From 6eb0e20147e09c1a912a54094ba51cf210813187 Mon Sep 17 00:00:00 2001 From: Saurav Date: Wed, 20 Mar 2024 09:39:25 -0400 Subject: [PATCH 1/5] fix bug --- examples-extra/docs_example/ontology.json | 6 +++--- .../ontology/actions/completeTodo.ts | 4 ++-- .../generator/src/v1.1/generatePerActionDataFiles.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples-extra/docs_example/ontology.json b/examples-extra/docs_example/ontology.json index 0add65abb..633827688 100644 --- a/examples-extra/docs_example/ontology.json +++ b/examples-extra/docs_example/ontology.json @@ -39,9 +39,9 @@ "Todo": { "description": "A todo Object", "dataType": { - "type": "object", - "objectApiName": "Todo", - "objectTypeApiName": "Todo" + "type": "array", + + "subType": { "type": "object", "objectApiName": "Todo", "objectTypeApiName": "Todo" } }, "required": true }, diff --git a/examples-extra/docs_example/src/generatedNoCheck/ontology/actions/completeTodo.ts b/examples-extra/docs_example/src/generatedNoCheck/ontology/actions/completeTodo.ts index 9751e2415..202c10209 100644 --- a/examples-extra/docs_example/src/generatedNoCheck/ontology/actions/completeTodo.ts +++ b/examples-extra/docs_example/src/generatedNoCheck/ontology/actions/completeTodo.ts @@ -11,7 +11,7 @@ export type ActionDef$completeTodo$Params = { }; Todo: { description: 'A todo Object'; - multiplicity: false; + multiplicity: true; nullable: false; type: ObjectActionDataType<'Todo', Todo>; }; @@ -42,7 +42,7 @@ export const completeTodo: ActionDef$completeTodo = { apiName: 'completeTodo', parameters: { Todo: { - multiplicity: false, + multiplicity: true, type: { type: 'object', object: 'Todo', diff --git a/packages/generator/src/v1.1/generatePerActionDataFiles.ts b/packages/generator/src/v1.1/generatePerActionDataFiles.ts index 597e9f2d1..0eb113deb 100644 --- a/packages/generator/src/v1.1/generatePerActionDataFiles.ts +++ b/packages/generator/src/v1.1/generatePerActionDataFiles.ts @@ -147,6 +147,18 @@ export async function generatePerActionDataFiles( getObjectDefIdentifier(p.dataType.objectTypeApiName!, v2), ); } + if ( + p.dataType.type === "array" + && (p.dataType.subType.type === "object" + || p.dataType.subType.type === "objectSet") + ) { + referencedObjectDefs.add( + getObjectDefIdentifier(p.dataType.subType.objectApiName!, v2), + ); + referencedObjectDefs.add( + getObjectDefIdentifier(p.dataType.subType.objectTypeApiName!, v2), + ); + } } const importObjects = referencedObjectDefs.size > 0 From e510085dfddb886b992291f9053d4bb252f2b32a Mon Sep 17 00:00:00 2001 From: Saurav Date: Wed, 20 Mar 2024 10:25:05 -0400 Subject: [PATCH 2/5] add unit tests --- .../src/util/test/TodoWireOntology.ts | 25 +++++++++++++++++++ .../src/v1.1/generateActions.test.ts | 11 ++++++++ .../src/v1.1/generateBulkActions.test.ts | 12 ++++++++- .../src/v1.1/generateMetadataFile.test.ts | 5 +++- .../v1.1/generatePerActionDataFiles.test.ts | 17 +++++++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/packages/generator/src/util/test/TodoWireOntology.ts b/packages/generator/src/util/test/TodoWireOntology.ts index 6a5a84b94..61a17c73a 100644 --- a/packages/generator/src/util/test/TodoWireOntology.ts +++ b/packages/generator/src/util/test/TodoWireOntology.ts @@ -45,6 +45,31 @@ export const TodoWireOntology = { }], status: "ACTIVE", }, + "deleteTodos": { + apiName: "deleteTodos", + description: "An action which takes in an array of objects", + parameters: { + object: { + description: "Todo(s) to be deleted", + "dataType": { + "type": "array", + + "subType": { + "type": "object", + "objectApiName": "Todo", + "objectTypeApiName": "Todo", + }, + }, + required: false, + }, + }, + rid: "ri.ontology.main.action-type.8f94017d-cf17-4fa8-84c3-8e01e5d594f2", + operations: [{ + type: "deleteObject", + objectTypeApiName: "Todo", + }], + status: "ACTIVE", + }, }, objectTypes: { Todo: { diff --git a/packages/generator/src/v1.1/generateActions.test.ts b/packages/generator/src/v1.1/generateActions.test.ts index 7a00556e8..946b2e73e 100644 --- a/packages/generator/src/v1.1/generateActions.test.ts +++ b/packages/generator/src/v1.1/generateActions.test.ts @@ -53,6 +53,17 @@ describe(generateActions, () => { }, options?: O, ): Promise>, ActionError>>; + + /** + * An action which takes in an array of objects + * @param {Array} params.object + */ + deleteTodos( + params: { + object?: Array; + }, + options?: O, + ): Promise>, ActionError>>; } " `); diff --git a/packages/generator/src/v1.1/generateBulkActions.test.ts b/packages/generator/src/v1.1/generateBulkActions.test.ts index 462aab706..f1b814e68 100644 --- a/packages/generator/src/v1.1/generateBulkActions.test.ts +++ b/packages/generator/src/v1.1/generateBulkActions.test.ts @@ -31,7 +31,6 @@ describe(generateBulkActions, () => { ); expect(helper.minimalFiles.writeFile).toBeCalled(); - expect(helper.getFiles()[`${BASE_PATH}/BulkActions.ts`]) .toMatchInlineSnapshot(` "import type { @@ -53,6 +52,17 @@ describe(generateBulkActions, () => { }[], options?: O, ): Promise>, ActionError>>; + + /** + * An action which takes in an array of objects + * @param {Array} params.object + */ + deleteTodos( + params: { + object?: Array; + }[], + options?: O, + ): Promise>, ActionError>>; } " `); diff --git a/packages/generator/src/v1.1/generateMetadataFile.test.ts b/packages/generator/src/v1.1/generateMetadataFile.test.ts index 27545954f..8b77c3869 100644 --- a/packages/generator/src/v1.1/generateMetadataFile.test.ts +++ b/packages/generator/src/v1.1/generateMetadataFile.test.ts @@ -40,6 +40,7 @@ describe(generateMetadataFile, () => { import type { Ontology as ClientOntology } from '@osdk/legacy-client'; import type { Actions } from './ontology/actions/Actions'; import type { BulkActions } from './ontology/actions/BulkActions'; + import { deleteTodos } from './ontology/actions/deleteTodos'; import { markTodoCompleted } from './ontology/actions/markTodoCompleted'; import type { Objects } from './ontology/objects/Objects'; import { Person } from './ontology/objects/Person'; @@ -59,6 +60,7 @@ describe(generateMetadataFile, () => { }; actions: { markTodoCompleted: typeof markTodoCompleted; + deleteTodos: typeof deleteTodos; }; queries: { getCount: typeof getCount; @@ -75,11 +77,12 @@ describe(generateMetadataFile, () => { }, actions: { markTodoCompleted, + deleteTodos, }, queries: { getCount, }, - } satisfies OntologyDefinition<'Todo' | 'Person', 'markTodoCompleted', 'getCount'>; + } satisfies OntologyDefinition<'Todo' | 'Person', 'markTodoCompleted' | 'deleteTodos', 'getCount'>; export interface Ontology extends ClientOntology { objects: Objects; diff --git a/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts b/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts index ab7b0f81d..4751be51d 100644 --- a/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts +++ b/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts @@ -51,4 +51,21 @@ describe(generatePerActionDataFiles, () => { ); expect(helper.getFiles()[`${BASE_PATH}/index.ts`]).toEqual("export {};\n"); }); + + it("imports object types correctly with array params in actions", async () => { + const helper = createMockMinimalFiles(); + const BASE_PATH = "/foo/actions"; + await generatePerActionDataFiles( + TodoWireOntology, + helper.minimalFiles, + BASE_PATH, + "", + true, + ); + console.error("OH NO"); + console.error(helper.getFiles()[`${BASE_PATH}/deleteTodos.ts`]); + expect(helper.getFiles()[`${BASE_PATH}/deleteTodos.ts`]).toContain( + "import type { Todo } from '../objects';\n", + ); + }); }); From e31706d3370441f8611c47e45f0333193fc3c1f2 Mon Sep 17 00:00:00 2001 From: Saurav Date: Wed, 20 Mar 2024 10:26:15 -0400 Subject: [PATCH 3/5] Remove console statements --- packages/generator/src/v1.1/generatePerActionDataFiles.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts b/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts index 4751be51d..a7c3b9f46 100644 --- a/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts +++ b/packages/generator/src/v1.1/generatePerActionDataFiles.test.ts @@ -62,8 +62,7 @@ describe(generatePerActionDataFiles, () => { "", true, ); - console.error("OH NO"); - console.error(helper.getFiles()[`${BASE_PATH}/deleteTodos.ts`]); + expect(helper.getFiles()[`${BASE_PATH}/deleteTodos.ts`]).toContain( "import type { Todo } from '../objects';\n", ); From b5eceb8c48a8756b8aebf203ddb6e0f5266f874b Mon Sep 17 00:00:00 2001 From: Saurav Date: Wed, 20 Mar 2024 10:32:20 -0400 Subject: [PATCH 4/5] add back new line --- packages/generator/src/v1.1/generateBulkActions.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/generator/src/v1.1/generateBulkActions.test.ts b/packages/generator/src/v1.1/generateBulkActions.test.ts index f1b814e68..ee585ad87 100644 --- a/packages/generator/src/v1.1/generateBulkActions.test.ts +++ b/packages/generator/src/v1.1/generateBulkActions.test.ts @@ -31,6 +31,7 @@ describe(generateBulkActions, () => { ); expect(helper.minimalFiles.writeFile).toBeCalled(); + expect(helper.getFiles()[`${BASE_PATH}/BulkActions.ts`]) .toMatchInlineSnapshot(` "import type { From 0298f3b562ed0a2724e41049411291fe1c6e8ba0 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 20 Mar 2024 17:07:59 +0000 Subject: [PATCH 5/5] Add generated changelog entries --- packages/generator/changelog/@unreleased/pr-138.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/generator/changelog/@unreleased/pr-138.v2.yml diff --git a/packages/generator/changelog/@unreleased/pr-138.v2.yml b/packages/generator/changelog/@unreleased/pr-138.v2.yml new file mode 100644 index 000000000..c6137f757 --- /dev/null +++ b/packages/generator/changelog/@unreleased/pr-138.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Fix action params + links: + - https://github.com/palantir/osdk-ts/pull/138