Skip to content

Commit

Permalink
feat: replace programIDs with diagramID (CV3-364)
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusdacal committed Sep 15, 2023
1 parent 9058e8f commit e9bb4f5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
25 changes: 25 additions & 0 deletions packages/api-sdk/src/resources/version/diagram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Fetch from '@api-sdk/fetch';
import { BaseModels } from '@voiceflow/base-types';

import CrudNestedResource from '../crudNested';

const ENDPOINT = 'diagrams';

export type ModelKey = 'diagramID';

class DiagramResource extends CrudNestedResource<string, BaseModels.Diagram.Model, ModelKey, DiagramResource> {
constructor(fetch: Fetch, { parentEndpoint }: { parentEndpoint: string }) {
super({
fetch,
clazz: DiagramResource,
endpoint: ENDPOINT,
clazzOptions: { parentEndpoint },
});
}

public async get(versionID: string, diagramID: string): Promise<BaseModels.Diagram.Model> {
return this._getByID<BaseModels.Diagram.Model>(versionID, diagramID);
}
}

export default DiagramResource;
12 changes: 12 additions & 0 deletions packages/api-sdk/src/resources/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { AnyRecord } from '@voiceflow/common';
import { Fields } from '../base';
import CrudResource from '../crud';
import CanvasTemplate from './canvasTemplate';
import Diagram from './diagram';
import Domain from './domain';
import Program from './program';
import PrototypeProgram from './prototypeProgram';

export const ENDPOINT = 'versions';

Expand All @@ -16,6 +19,12 @@ class VersionResource extends CrudResource<BaseModels.Version.Model<BaseModels.V

public canvasTemplate: CanvasTemplate;

public diagram: Diagram;

public program: Program;

public prototypeProgram: PrototypeProgram;

constructor(fetch: Fetch) {
super({
fetch,
Expand All @@ -25,6 +34,9 @@ class VersionResource extends CrudResource<BaseModels.Version.Model<BaseModels.V

this.domain = new Domain(fetch, { parentEndpoint: ENDPOINT });
this.canvasTemplate = new CanvasTemplate(fetch, { parentEndpoint: ENDPOINT });
this.diagram = new Diagram(fetch, { parentEndpoint: ENDPOINT });
this.program = new Program(fetch, { parentEndpoint: ENDPOINT });
this.prototypeProgram = new PrototypeProgram(fetch, { parentEndpoint: ENDPOINT });
}

public async get<T extends Partial<BaseModels.Version.Model<BaseModels.Version.PlatformData>>>(id: string, fields: Fields): Promise<T>;
Expand Down
25 changes: 25 additions & 0 deletions packages/api-sdk/src/resources/version/program.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Fetch from '@api-sdk/fetch';
import { BaseModels } from '@voiceflow/base-types';

import CrudNestedResource from '../crudNested';

const ENDPOINT = 'programs';

export type ModelKey = 'diagramID';

class ProgramResource extends CrudNestedResource<string, BaseModels.Program.Model, ModelKey, ProgramResource> {
constructor(fetch: Fetch, { parentEndpoint }: { parentEndpoint: string }) {
super({
fetch,
clazz: ProgramResource,
endpoint: ENDPOINT,
clazzOptions: { parentEndpoint },
});
}

public async get(versionID: string, diagramID: string): Promise<BaseModels.Program.Model> {
return this._getByID<BaseModels.Program.Model>(versionID, diagramID);
}
}

export default ProgramResource;
25 changes: 25 additions & 0 deletions packages/api-sdk/src/resources/version/prototypeProgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Fetch from '@api-sdk/fetch';
import { BaseModels } from '@voiceflow/base-types';

import CrudNestedResource from '../crudNested';

const ENDPOINT = 'prototype-programs';

export type ModelKey = 'diagramID';

class PrototypeProgramResource extends CrudNestedResource<string, BaseModels.Program.Model, ModelKey, PrototypeProgramResource> {
constructor(fetch: Fetch, { parentEndpoint }: { parentEndpoint: string }) {
super({
fetch,
clazz: PrototypeProgramResource,
endpoint: ENDPOINT,
clazzOptions: { parentEndpoint },
});
}

public async get(versionID: string, diagramID: string): Promise<BaseModels.Program.Model> {
return this._getByID<BaseModels.Program.Model>(versionID, diagramID);
}
}

export default PrototypeProgramResource;
2 changes: 1 addition & 1 deletion packages/base-types/src/models/version/prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseCommand, Intent, PrototypeModel, Slot } from '../base';

export interface PrototypeStackFrame<Command extends BaseCommand = BaseCommand> {
nodeID?: Nullable<string>;
programID: string;
diagramID: string;

storage?: AnyRecord;
commands?: Command[];
Expand Down
2 changes: 1 addition & 1 deletion packages/base-types/src/runtimeLogs/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface PathReference {
/** A reference to a flow (frame) on the canvas. */
export interface FlowReference {
name: string | null;
programID: string;
diagramID: string;
}

/** A common interface for representing a before & after change of a value. */
Expand Down

0 comments on commit e9bb4f5

Please sign in to comment.