From fee51a3ec6d129b8d74eafcd7ca535701e2cc076 Mon Sep 17 00:00:00 2001 From: ssanjay1 <67482244+ssanjay1@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:10:24 -0400 Subject: [PATCH] Add interface support for foundry-sdk-generator (#484) * Speed up build, fix dts generation for all, primitive --beta * Add empty changeset * more beta work, packagejson needs revision * package json work * small refactor * add changesets * spell check fix --------- Co-authored-by: Eric Anderson --- .changeset/funny-days-sneeze.md | 5 ++ packages/foundry-sdk-generator/package.json | 1 + .../src/__e2e_tests__/testSetup.ts | 6 ++ .../src/generate/GeneratePackageCommand.ts | 12 ++++ .../generate/betaClient/generatePackage.ts | 26 ++++++-- .../betaClient/generatePackageJson.ts | 62 ++++++++++++------- .../ontologyMetadataResolver.ts | 17 ++++- .../monorepo.cspell/dict.normal-dev-words.txt | 3 +- pnpm-lock.yaml | 3 + 9 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 .changeset/funny-days-sneeze.md diff --git a/.changeset/funny-days-sneeze.md b/.changeset/funny-days-sneeze.md new file mode 100644 index 000000000..443838e54 --- /dev/null +++ b/.changeset/funny-days-sneeze.md @@ -0,0 +1,5 @@ +--- +"@osdk/foundry-sdk-generator": minor +--- + +Add interface support diff --git a/packages/foundry-sdk-generator/package.json b/packages/foundry-sdk-generator/package.json index ab18957dc..9500c09a0 100644 --- a/packages/foundry-sdk-generator/package.json +++ b/packages/foundry-sdk-generator/package.json @@ -33,6 +33,7 @@ "dependencies": { "@osdk/api": "workspace:~", "@osdk/client": "workspace:~", + "@osdk/client.api": "workspace:~", "@osdk/gateway": "workspace:~", "@osdk/generator": "workspace:~", "@osdk/legacy-client": "workspace:~", diff --git a/packages/foundry-sdk-generator/src/__e2e_tests__/testSetup.ts b/packages/foundry-sdk-generator/src/__e2e_tests__/testSetup.ts index c9cbc124b..f81a88c16 100755 --- a/packages/foundry-sdk-generator/src/__e2e_tests__/testSetup.ts +++ b/packages/foundry-sdk-generator/src/__e2e_tests__/testSetup.ts @@ -60,6 +60,9 @@ export async function setup() { "twoDimensionalAggregationFunction", "threeDimensionalAggregationFunction", ], + interfaceTypes: [ + "FooInterface", + ], linkTypes: ["employee.peeps", "employee.lead", "employee.officeLink"], palantirOnlyTest: true, _: [], @@ -95,6 +98,9 @@ export async function setup() { "twoDimensionalAggregationFunction", "threeDimensionalAggregationFunction", ], + interfaceTypes: [ + "FooInterface", + ], beta: true, linkTypes: ["employee.peeps", "employee.lead", "employee.officeLink"], palantirOnlyTest: true, diff --git a/packages/foundry-sdk-generator/src/generate/GeneratePackageCommand.ts b/packages/foundry-sdk-generator/src/generate/GeneratePackageCommand.ts index a47ff9836..e7543b3ea 100644 --- a/packages/foundry-sdk-generator/src/generate/GeneratePackageCommand.ts +++ b/packages/foundry-sdk-generator/src/generate/GeneratePackageCommand.ts @@ -29,6 +29,7 @@ export interface generatePackageCommandArgs { actionTypes?: string[]; queryTypes?: string[]; linkTypes?: string[]; + interfaceTypes?: string[]; experimentalFeatures?: string[]; packageName: string; packageVersion: string; @@ -118,6 +119,16 @@ export class GeneratePackageCommand defaultDescription: `By default, no arguments will not load any query type.`, }) + .options("interfaceTypes", { + array: true, + string: true, + demandOption: false, + description: + `The API Names of the interface types to generate. Example Usage: --interfaceTypes Geolocatable`, + default: undefined, + defaultDescription: + `By default, no arguments will not load any interface type.`, + }) .options("experimentalFeatures", { array: true, string: true, @@ -164,6 +175,7 @@ export class GeneratePackageCommand objectTypesApiNamesToLoad: transformArrayArg(args.objectTypes), actionTypesApiNamesToLoad: transformArrayArg(args.actionTypes), queryTypesApiNamesToLoad: transformArrayArg(args.queryTypes), + interfaceTypesApiNamesToLoad: transformArrayArg(args.interfaceTypes), linkTypesApiNamesToLoad: transformArrayArg(args.linkTypes), }); diff --git a/packages/foundry-sdk-generator/src/generate/betaClient/generatePackage.ts b/packages/foundry-sdk-generator/src/generate/betaClient/generatePackage.ts index 10ffca6ce..e7ca20735 100644 --- a/packages/foundry-sdk-generator/src/generate/betaClient/generatePackage.ts +++ b/packages/foundry-sdk-generator/src/generate/betaClient/generatePackage.ts @@ -28,12 +28,23 @@ import { compileInMemory } from "./compileInMemory.js"; import { generatePackageJson } from "./generatePackageJson.js"; declare const __OSDK_LEGACY_CLIENT_VERSION__: string | undefined; +declare const __OSDK_CLIENT_API_VERSION__: string | undefined; +declare const __OSDK_API_VERSION__: string | undefined; const dependencies: { [key: string]: string | undefined } = { "@osdk/legacy-client": typeof __OSDK_LEGACY_CLIENT_VERSION__ !== "undefined" ? __OSDK_LEGACY_CLIENT_VERSION__ : undefined, }; +const betaDependencies: { [key: string]: string | undefined } = { + "@osdk/client.api": typeof __OSDK_CLIENT_API_VERSION__ !== "undefined" + ? __OSDK_CLIENT_API_VERSION__ + : undefined, + "@osdk/api": typeof __OSDK_API_VERSION__ !== "undefined" + ? __OSDK_API_VERSION__ + : undefined, +}; + export async function generatePackage( ontology: WireOntologyDefinition, options: { @@ -47,12 +58,14 @@ export async function generatePackage( const packagePath = join(options.outputDir, options.packageName); const resolvedDependencies = await Promise.all( - Object.keys(dependencies).map(async dependency => { - return { - dependencyName: dependency, - dependencyVersion: await getDependencyVersion(dependency), - }; - }), + Object.keys(options.beta ? betaDependencies : dependencies).map( + async dependency => { + return { + dependencyName: dependency, + dependencyVersion: await getDependencyVersion(dependency), + }; + }, + ), ); await mkdir(packagePath, { recursive: true }); @@ -139,6 +152,7 @@ export async function generatePackage( packagePath, packageVersion: options.packageVersion, dependencies: resolvedDependencies, + beta: options.beta, }), ]); diff --git a/packages/foundry-sdk-generator/src/generate/betaClient/generatePackageJson.ts b/packages/foundry-sdk-generator/src/generate/betaClient/generatePackageJson.ts index f9a7d23d8..227de3653 100644 --- a/packages/foundry-sdk-generator/src/generate/betaClient/generatePackageJson.ts +++ b/packages/foundry-sdk-generator/src/generate/betaClient/generatePackageJson.ts @@ -22,32 +22,52 @@ export async function generatePackageJson(options: { packageVersion: string; packagePath: string; dependencies?: Array<{ dependencyName: string; dependencyVersion: string }>; + beta: boolean; }) { + const packageDeps = options.dependencies?.reduce((acc, value) => { + acc[value.dependencyName] = value.dependencyVersion; + return acc; + }, {} as { [dependencyName: string]: string }); + // Note that any "default" conditions _must_ be last in their block otherwise it will crash at runtime - const packageJson = { - name: options.packageName, - version: options.packageVersion, - main: "./index.js", - types: "./index.d.ts", - exports: { - ".": { - types: "./index.d.ts", - script: { - types: "./dist/bundle/index.d.ts", - default: "./dist/bundle/index.esm.js", + const packageJson = options.beta + ? { + name: options.packageName, + version: options.packageVersion, + main: "./index.js", + types: "./index.d.ts", + exports: { + ".": { + types: "./index.d.ts", + script: { + default: "./dist/bundle/index.esm.js", + }, + default: "./index.js", }, - default: "./index.js", }, - "./ontology/objects": { - types: "./ontology/objects/index.d.ts", - default: "./ontology/objects/index.js", + dependencies: packageDeps, + } + : { + name: options.packageName, + version: options.packageVersion, + main: "./index.js", + types: "./index.d.ts", + exports: { + ".": { + types: "./index.d.ts", + script: { + types: "./dist/bundle/index.d.ts", + default: "./dist/bundle/index.esm.js", + }, + default: "./index.js", + }, + "./ontology/objects": { + types: "./ontology/objects/index.d.ts", + default: "./ontology/objects/index.js", + }, }, - }, - dependencies: options.dependencies?.reduce((acc, value) => { - acc[value.dependencyName] = value.dependencyVersion; - return acc; - }, {} as { [dependencyName: string]: string }), - }; + dependencies: packageDeps, + }; await writeFile( join(options.packagePath, "package.json"), diff --git a/packages/foundry-sdk-generator/src/ontologyMetadata/ontologyMetadataResolver.ts b/packages/foundry-sdk-generator/src/ontologyMetadata/ontologyMetadataResolver.ts index 5e60159f5..6307f27a0 100644 --- a/packages/foundry-sdk-generator/src/ontologyMetadata/ontologyMetadataResolver.ts +++ b/packages/foundry-sdk-generator/src/ontologyMetadata/ontologyMetadataResolver.ts @@ -43,6 +43,7 @@ export class OntologyMetadataResolver { objectTypes: Set; queryTypes: Set; actionTypes: Set; + interfaceTypes: Set; }, ): components.OntologyFullMetadata { const filteredObjectTypes = Object.fromEntries( @@ -51,6 +52,12 @@ export class OntologyMetadataResolver { ) => expectedEntities.objectTypes.has(objectTypeApiName.toLowerCase())), ); + const filteredInterfaceTypes = Object.fromEntries( + Object.entries(ontologyFullMetadata.interfaceTypes).filter(( + [interfaceApiName], + ) => expectedEntities.interfaceTypes.has(interfaceApiName.toLowerCase())), + ); + Object.values(filteredObjectTypes).forEach(objectType => { const linkTypesToKeep = expectedEntities.linkTypes.get( objectType.objectType.apiName.toLowerCase(), @@ -91,7 +98,7 @@ export class OntologyMetadataResolver { objectTypes: filteredObjectTypes, actionTypes: filteredActionTypes, queryTypes: filteredQueryTypes, - interfaceTypes: {}, + interfaceTypes: filteredInterfaceTypes, sharedPropertyTypes: {}, }; } @@ -102,6 +109,7 @@ export class OntologyMetadataResolver { actionTypesApiNamesToLoad?: string[]; objectTypesApiNamesToLoad?: string[]; queryTypesApiNamesToLoad?: string[]; + interfaceTypesApiNamesToLoad?: string[]; linkTypesApiNamesToLoad?: string[]; }, ): Promise> { @@ -147,6 +155,12 @@ export class OntologyMetadataResolver { ), ); + const interfaceTypes = new Set( + entities.interfaceTypesApiNamesToLoad?.map(interfaceName => + interfaceName.toLowerCase() + ), + ); + for (const linkType of entities.linkTypesApiNamesToLoad ?? []) { const [objectTypeApiName, linkTypeApiName] = linkType.toLowerCase().split( ".", @@ -162,6 +176,7 @@ export class OntologyMetadataResolver { linkTypes, actionTypes, queryTypes, + interfaceTypes, }); const validData: Result<{}, string[]> = this.validateLoadedOntologyMetadata( diff --git a/packages/monorepo.cspell/dict.normal-dev-words.txt b/packages/monorepo.cspell/dict.normal-dev-words.txt index dd0d4225c..db100f438 100644 --- a/packages/monorepo.cspell/dict.normal-dev-words.txt +++ b/packages/monorepo.cspell/dict.normal-dev-words.txt @@ -12,4 +12,5 @@ typesafety uncapitalize unevaluable unioned -webapi \ No newline at end of file +webapi +Geolocatable \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c3b06c0c1..531d0ab82 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1428,6 +1428,9 @@ importers: '@osdk/client': specifier: workspace:~ version: link:../client + '@osdk/client.api': + specifier: workspace:~ + version: link:../client.api '@osdk/gateway': specifier: workspace:~ version: link:../gateway