@osdk/maker 0.16.0-beta.8 → 0.16.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.16.0-beta.9
4
+
5
+ ### Minor Changes
6
+
7
+ - 7fa6de3: Revert breaking change
8
+
3
9
  ## 0.16.0-beta.8
4
10
 
5
11
  ### Minor Changes
@@ -14,33 +14,17 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { OntologyIrToFullMetadataConverter } from "@osdk/generator-converters.ontologyir";
18
17
  import { consola } from "consola";
19
- import { execa } from "execa";
20
- import { createJiti } from "jiti";
21
18
  import * as fs from "node:fs/promises";
22
19
  import * as path from "node:path";
23
20
  import invariant from "tiny-invariant";
24
21
  import yargs from "yargs";
25
22
  import { hideBin } from "yargs/helpers";
26
23
  import { defineOntology } from "../api/defineOntology.js";
27
-
28
- // Dynamic imports for optional function discovery dependencies
29
- let generateFunctionsIr;
30
- async function loadFunctionDiscoveryDeps() {
31
- try {
32
- const defineFunctionModule = await import("../api/defineFunction.js");
33
- generateFunctionsIr = defineFunctionModule.generateFunctionsIr;
34
- return true;
35
- } catch (e) {
36
- consola.warn("Failed to load function discovery dependencies:", e instanceof Error ? e.message : e);
37
- return false;
38
- }
39
- }
40
24
  const apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
41
25
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
42
26
  export default async function main(args = process.argv) {
43
- const commandLineOpts = await yargs(hideBin(args)).version("0.16.0-beta.8" ?? "").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
27
+ const commandLineOpts = await yargs(hideBin(args)).version("0.16.0-beta.9" ?? "").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
44
28
  input: {
45
29
  alias: "i",
46
30
  describe: "Input file",
@@ -104,41 +88,6 @@ export default async function main(args = process.argv) {
104
88
  describe: "Value used to assure uniqueness of entities",
105
89
  type: "string",
106
90
  coerce: path.resolve
107
- },
108
- generateFunctionsOsdk: {
109
- describe: "Output folder for generated OSDK for functions",
110
- type: "string",
111
- coerce: path.resolve
112
- },
113
- functionsRootDir: {
114
- describe: "Root folder containing function definitions",
115
- type: "string",
116
- coerce: path.resolve
117
- },
118
- functionsOutput: {
119
- describe: "Output folder for function IR",
120
- type: "string",
121
- coerce: path.resolve
122
- },
123
- configPath: {
124
- describe: "Path to the TypeScript config file",
125
- type: "string",
126
- coerce: path.resolve
127
- },
128
- pythonFunctionsDir: {
129
- describe: "Path to Python functions source directory (enables Python function discovery)",
130
- type: "string",
131
- coerce: path.resolve
132
- },
133
- pythonBinary: {
134
- describe: "Path to Python binary (required when using --pythonFunctionsDir)",
135
- type: "string",
136
- coerce: path.resolve
137
- },
138
- pythonRootProjectDir: {
139
- describe: "Root project directory for Python functions (defaults to parent of pythonFunctionsDir)",
140
- type: "string",
141
- coerce: path.resolve
142
91
  }
143
92
  }).parseAsync();
144
93
  let apiNamespace = "";
@@ -161,101 +110,9 @@ export default async function main(args = process.argv) {
161
110
  if (ontologyIr.valueTypes.valueTypes.length > 0 || ontologyIr.importedValueTypes.valueTypes.length > 0) {
162
111
  await fs.writeFile(commandLineOpts.valueTypesOutput, JSON.stringify(ontologyIr.valueTypes, null, 2));
163
112
  }
164
- if (commandLineOpts.pythonFunctionsDir && !commandLineOpts.pythonBinary) {
165
- consola.error("--pythonBinary is required when using --pythonFunctionsDir");
166
- return;
167
- }
168
-
169
- // Function discovery feature (requires optional dependencies)
170
- if (commandLineOpts.functionsOutput !== undefined && commandLineOpts.functionsRootDir !== undefined) {
171
- const hasFunctionDeps = await loadFunctionDiscoveryDeps();
172
- if (!hasFunctionDeps || !generateFunctionsIr) {
173
- consola.error("Function discovery requires optional dependencies. Install @foundry/functions-typescript-* packages.");
174
- return;
175
- }
176
- consola.info(`Loading function IR`);
177
- const functionsIr = await generateFunctionsIr(commandLineOpts.functionsRootDir, commandLineOpts.configPath, createEntityMappings(ontologyIr));
178
- await fs.writeFile(commandLineOpts.functionsOutput, JSON.stringify(functionsIr, null, 2));
179
- return;
180
- }
181
- if (commandLineOpts.generateFunctionsOsdk !== undefined) {
182
- // Generate full ontology metadata for functions OSDK
183
- const fullMetadata = OntologyIrToFullMetadataConverter.getFullMetadataFromIr(ontologyIr.ontology);
184
-
185
- // Discover Python functions and merge into ontology metadata
186
- if (commandLineOpts.pythonFunctionsDir) {
187
- const effectivePythonRootDir = commandLineOpts.pythonRootProjectDir ?? path.dirname(commandLineOpts.pythonFunctionsDir);
188
- const queryTypes = await OntologyIrToFullMetadataConverter.getOsdkQueryTypes(commandLineOpts.pythonBinary, undefined, undefined, commandLineOpts.pythonFunctionsDir, effectivePythonRootDir);
189
- const functionNames = Object.keys(queryTypes);
190
- if (functionNames.length > 0) {
191
- fullMetadata.queryTypes = queryTypes;
192
- consola.info(`Discovered ${functionNames.length} Python function(s): ${functionNames.join(", ")}`);
193
- } else {
194
- consola.info("No Python functions discovered.");
195
- }
196
- }
197
- consola.info(`Saving full ontology metadata to ${commandLineOpts.generateFunctionsOsdk}`);
198
- await fs.writeFile(path.join(commandLineOpts.generateFunctionsOsdk, ".ontology.json"), JSON.stringify(fullMetadata, null, 2));
199
- await fullMetadataToOsdk(commandLineOpts.generateFunctionsOsdk);
200
- }
201
113
  }
202
114
  async function loadOntology(input, apiNamespace, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey) {
203
- const q = await defineOntology(apiNamespace, async () => {
204
- const jiti = createJiti(import.meta.filename, {
205
- moduleCache: true,
206
- debug: false,
207
- importMeta: import.meta
208
- });
209
- await jiti.import(input);
210
- }, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey);
115
+ const q = await defineOntology(apiNamespace, async () => await import(input), outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey);
211
116
  return q;
212
117
  }
213
- async function fullMetadataToOsdk(workDir) {
214
- // First create a clean temporary directory to generate the SDK into
215
- const functionOsdkDir = path.join(workDir, "generated");
216
- await fs.rm(functionOsdkDir, {
217
- recursive: true,
218
- force: true
219
- });
220
- await fs.mkdir(functionOsdkDir, {
221
- recursive: true
222
- });
223
- try {
224
- // Generate the source code for the osdk
225
- await execa("pnpm", ["exec", "osdk", "unstable", "typescript", "generate", "--outDir", functionOsdkDir, "--ontologyPath", path.join(workDir, ".ontology.json"), "--beta", "true", "--packageType", "module", "--version", "dev"]);
226
- } catch (error) {
227
- await fs.rm(functionOsdkDir, {
228
- recursive: true,
229
- force: true
230
- });
231
- throw error;
232
- }
233
- }
234
- function createEntityMappings(ontologyIr) {
235
- const entityMappings = {
236
- ontologies: {}
237
- };
238
- const ontologyRid = "ontology";
239
- entityMappings.ontologies[ontologyRid] = {
240
- objectTypes: {},
241
- interfaceTypes: {}
242
- };
243
- for (const [apiName, blockData] of Object.entries(ontologyIr.ontology.objectTypes)) {
244
- const propertyTypesMap = {};
245
- Object.keys(blockData.objectType.propertyTypes).forEach(propertyName => {
246
- propertyTypesMap[propertyName] = {
247
- propertyId: propertyName
248
- };
249
- });
250
- entityMappings.ontologies[ontologyRid].objectTypes[apiName] = {
251
- objectTypeId: apiName,
252
- primaryKey: {
253
- propertyId: blockData.objectType.primaryKeys[0]
254
- },
255
- propertyTypes: propertyTypesMap,
256
- linkTypes: {}
257
- };
258
- }
259
- return entityMappings;
260
- }
261
118
  //# sourceMappingURL=main.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","names":["OntologyIrToFullMetadataConverter","consola","execa","createJiti","fs","path","invariant","yargs","hideBin","defineOntology","generateFunctionsIr","loadFunctionDiscoveryDeps","defineFunctionModule","e","warn","Error","message","apiNamespaceRegex","uuidRegex","main","args","process","argv","commandLineOpts","version","wrap","Math","min","terminalWidth","strict","help","options","input","alias","describe","type","default","coerce","resolve","output","apiNamespace","snapshotDir","outputDir","valueTypesOutput","dependencies","generateCodeSnippets","codeSnippetPackageName","codeSnippetDir","randomnessKey","generateFunctionsOsdk","functionsRootDir","functionsOutput","configPath","pythonFunctionsDir","pythonBinary","pythonRootProjectDir","parseAsync","length","slice","env","NODE_ENV","test","info","undefined","ontologyIr","loadOntology","writeFile","JSON","stringify","valueTypes","importedValueTypes","error","hasFunctionDeps","functionsIr","createEntityMappings","fullMetadata","getFullMetadataFromIr","ontology","effectivePythonRootDir","dirname","queryTypes","getOsdkQueryTypes","functionNames","Object","keys","join","fullMetadataToOsdk","dependencyFile","snippetPackageName","q","jiti","import","meta","filename","moduleCache","debug","importMeta","workDir","functionOsdkDir","rm","recursive","force","mkdir","entityMappings","ontologies","ontologyRid","objectTypes","interfaceTypes","apiName","blockData","entries","propertyTypesMap","objectType","propertyTypes","forEach","propertyName","propertyId","objectTypeId","primaryKey","primaryKeys","linkTypes"],"sources":["main.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { OntologyIr } from \"@osdk/client.unstable\";\nimport { OntologyIrToFullMetadataConverter } from \"@osdk/generator-converters.ontologyir\";\nimport { consola } from \"consola\";\nimport { execa } from \"execa\";\nimport { createJiti } from \"jiti\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport type { IEntityMetadataMapping } from \"../api/defineFunction.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\n\n// Dynamic imports for optional function discovery dependencies\nlet generateFunctionsIr:\n | ((\n rootDir: string,\n configPath: string | undefined,\n entityMappings: IEntityMetadataMapping,\n ) => Promise<unknown>)\n | undefined;\n\nasync function loadFunctionDiscoveryDeps(): Promise<boolean> {\n try {\n const defineFunctionModule = await import(\"../api/defineFunction.js\");\n generateFunctionsIr = defineFunctionModule.generateFunctionsIr;\n return true;\n } catch (e: unknown) {\n consola.warn(\n \"Failed to load function discovery dependencies:\",\n e instanceof Error ? e.message : e,\n );\n return false;\n }\n}\n\nconst apiNamespaceRegex = /^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$/;\nconst uuidRegex =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;\n\nexport default async function main(\n args: string[] = process.argv,\n): Promise<void> {\n const commandLineOpts: {\n input: string;\n output: string;\n apiNamespace: string;\n snapshotDir: string;\n valueTypesOutput: string;\n outputDir?: string;\n dependencies?: string;\n generateCodeSnippets: boolean;\n codeSnippetPackageName: string;\n codeSnippetDir: string;\n randomnessKey?: string;\n generateFunctionsOsdk?: string;\n functionsRootDir?: string;\n functionsOutput?: string;\n configPath?: string;\n pythonFunctionsDir?: string;\n pythonBinary?: string;\n pythonRootProjectDir?: string;\n } = await yargs(hideBin(args))\n .version(process.env.PACKAGE_VERSION ?? \"\")\n .wrap(Math.min(150, yargs().terminalWidth()))\n .strict()\n .help()\n .options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve,\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve,\n },\n apiNamespace: {\n describe: \"Api name prefix for namespaced ontology types\",\n type: \"string\",\n default: \"\",\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve,\n },\n outputDir: {\n alias: \"d\",\n describe: \"Directory for generated ontology entities\",\n type: \"string\",\n coerce: path.resolve,\n },\n valueTypesOutput: {\n describe: \"Value Type Output File\",\n type: \"string\",\n default: \"value-types.json\",\n coerce: path.resolve,\n },\n dependencies: {\n describe: \"File to write dependencies to\",\n type: \"string\",\n coerce: path.resolve,\n },\n generateCodeSnippets: {\n describe: \"Enable code snippet files creation\",\n type: \"boolean\",\n default: false,\n },\n codeSnippetPackageName: {\n describe:\n \"The package name that will be displayed in the code snippets\",\n default: \"\",\n type: \"string\",\n },\n codeSnippetDir: {\n describe: \"Directory for generated code snippet files\",\n type: \"string\",\n default: \"./\",\n coerce: path.resolve,\n },\n randomnessKey: {\n describe: \"Value used to assure uniqueness of entities\",\n type: \"string\",\n coerce: path.resolve,\n },\n generateFunctionsOsdk: {\n describe: \"Output folder for generated OSDK for functions\",\n type: \"string\",\n coerce: path.resolve,\n },\n functionsRootDir: {\n describe: \"Root folder containing function definitions\",\n type: \"string\",\n coerce: path.resolve,\n },\n functionsOutput: {\n describe: \"Output folder for function IR\",\n type: \"string\",\n coerce: path.resolve,\n },\n configPath: {\n describe: \"Path to the TypeScript config file\",\n type: \"string\",\n coerce: path.resolve,\n },\n pythonFunctionsDir: {\n describe:\n \"Path to Python functions source directory (enables Python function discovery)\",\n type: \"string\",\n coerce: path.resolve,\n },\n pythonBinary: {\n describe:\n \"Path to Python binary (required when using --pythonFunctionsDir)\",\n type: \"string\",\n coerce: path.resolve,\n },\n pythonRootProjectDir: {\n describe:\n \"Root project directory for Python functions (defaults to parent of pythonFunctionsDir)\",\n type: \"string\",\n coerce: path.resolve,\n },\n })\n .parseAsync();\n let apiNamespace = \"\";\n if (commandLineOpts.apiNamespace.length !== 0) {\n apiNamespace = (commandLineOpts.apiNamespace.slice(-1) !== \".\")\n ? commandLineOpts.apiNamespace + \".\"\n : commandLineOpts.apiNamespace;\n invariant(apiNamespace.length < 1024, \"API namespace is too long.\");\n invariant(\n apiNamespaceRegex.test(apiNamespace),\n \"API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$\",\n );\n }\n\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n\n if (\n !commandLineOpts.generateCodeSnippets\n && (commandLineOpts.codeSnippetPackageName !== \"\"\n || commandLineOpts.codeSnippetDir !== path.resolve(\"./\"))\n ) {\n consola.info(\n \"Package name and/or directory supplied for code snippets, but code snippet generation is false.\",\n );\n }\n\n if (commandLineOpts.randomnessKey !== undefined) {\n invariant(\n uuidRegex.test(commandLineOpts.randomnessKey),\n \"Supplied randomness key is not a uuid and shouldn't be used as a uniqueness guarantee\",\n );\n }\n\n const ontologyIr = await loadOntology(\n commandLineOpts.input,\n apiNamespace,\n commandLineOpts.outputDir,\n commandLineOpts.dependencies,\n commandLineOpts.generateCodeSnippets,\n commandLineOpts.codeSnippetPackageName,\n commandLineOpts.codeSnippetDir,\n commandLineOpts.randomnessKey,\n );\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(\n commandLineOpts.output,\n JSON.stringify(\n ontologyIr,\n null,\n 2,\n ),\n );\n // No point in generating block if there aren't any value types\n if (\n ontologyIr.valueTypes.valueTypes.length > 0\n || ontologyIr.importedValueTypes.valueTypes.length > 0\n ) {\n await fs.writeFile(\n commandLineOpts.valueTypesOutput,\n JSON.stringify(\n ontologyIr.valueTypes,\n null,\n 2,\n ),\n );\n }\n\n if (commandLineOpts.pythonFunctionsDir && !commandLineOpts.pythonBinary) {\n consola.error(\n \"--pythonBinary is required when using --pythonFunctionsDir\",\n );\n return;\n }\n\n // Function discovery feature (requires optional dependencies)\n if (\n commandLineOpts.functionsOutput !== undefined\n && commandLineOpts.functionsRootDir !== undefined\n ) {\n const hasFunctionDeps = await loadFunctionDiscoveryDeps();\n if (!hasFunctionDeps || !generateFunctionsIr) {\n consola.error(\n \"Function discovery requires optional dependencies. Install @foundry/functions-typescript-* packages.\",\n );\n return;\n }\n consola.info(`Loading function IR`);\n const functionsIr = await generateFunctionsIr(\n commandLineOpts.functionsRootDir,\n commandLineOpts.configPath,\n createEntityMappings(ontologyIr),\n );\n await fs.writeFile(\n commandLineOpts.functionsOutput,\n JSON.stringify(functionsIr, null, 2),\n );\n return;\n }\n\n if (commandLineOpts.generateFunctionsOsdk !== undefined) {\n // Generate full ontology metadata for functions OSDK\n const fullMetadata = OntologyIrToFullMetadataConverter\n .getFullMetadataFromIr(ontologyIr.ontology);\n\n // Discover Python functions and merge into ontology metadata\n if (commandLineOpts.pythonFunctionsDir) {\n const effectivePythonRootDir = commandLineOpts.pythonRootProjectDir\n ?? path.dirname(commandLineOpts.pythonFunctionsDir);\n\n const queryTypes = await OntologyIrToFullMetadataConverter\n .getOsdkQueryTypes(\n commandLineOpts.pythonBinary,\n undefined,\n undefined,\n commandLineOpts.pythonFunctionsDir,\n effectivePythonRootDir,\n );\n\n const functionNames = Object.keys(queryTypes);\n if (functionNames.length > 0) {\n fullMetadata.queryTypes = queryTypes;\n consola.info(\n `Discovered ${functionNames.length} Python function(s): ${\n functionNames.join(\", \")\n }`,\n );\n } else {\n consola.info(\"No Python functions discovered.\");\n }\n }\n\n consola.info(\n `Saving full ontology metadata to ${commandLineOpts.generateFunctionsOsdk}`,\n );\n\n await fs.writeFile(\n path.join(commandLineOpts.generateFunctionsOsdk, \".ontology.json\"),\n JSON.stringify(fullMetadata, null, 2),\n );\n\n await fullMetadataToOsdk(commandLineOpts.generateFunctionsOsdk);\n }\n}\n\nasync function loadOntology(\n input: string,\n apiNamespace: string,\n outputDir: string | undefined,\n dependencyFile: string | undefined,\n generateCodeSnippets: boolean,\n snippetPackageName: string,\n codeSnippetDir: string,\n randomnessKey?: string,\n) {\n const q = await defineOntology(\n apiNamespace,\n async () => {\n const jiti = createJiti(import.meta.filename, {\n moduleCache: true,\n debug: false,\n importMeta: import.meta,\n });\n await jiti.import(input);\n },\n outputDir,\n dependencyFile,\n generateCodeSnippets,\n snippetPackageName,\n codeSnippetDir,\n randomnessKey,\n );\n return q;\n}\n\nasync function fullMetadataToOsdk(\n workDir: string,\n): Promise<void> {\n // First create a clean temporary directory to generate the SDK into\n const functionOsdkDir = path.join(\n workDir,\n \"generated\",\n );\n await fs.rm(functionOsdkDir, { recursive: true, force: true });\n await fs.mkdir(functionOsdkDir, { recursive: true });\n\n try {\n // Generate the source code for the osdk\n await execa(\"pnpm\", [\n \"exec\",\n \"osdk\",\n \"unstable\",\n \"typescript\",\n \"generate\",\n \"--outDir\",\n functionOsdkDir,\n \"--ontologyPath\",\n path.join(workDir, \".ontology.json\"),\n \"--beta\",\n \"true\",\n \"--packageType\",\n \"module\",\n \"--version\",\n \"dev\",\n ]);\n } catch (error) {\n await fs.rm(functionOsdkDir, { recursive: true, force: true });\n throw error;\n }\n}\n\nfunction createEntityMappings(ontologyIr: OntologyIr): IEntityMetadataMapping {\n const entityMappings: IEntityMetadataMapping = {\n ontologies: {},\n };\n\n const ontologyRid = \"ontology\";\n entityMappings.ontologies[ontologyRid] = {\n objectTypes: {},\n interfaceTypes: {},\n };\n\n for (\n const [apiName, blockData] of Object.entries(\n ontologyIr.ontology.objectTypes,\n )\n ) {\n const propertyTypesMap: Record<string, { propertyId: string }> = {};\n\n Object.keys(blockData.objectType.propertyTypes).forEach((propertyName) => {\n propertyTypesMap[propertyName] = { propertyId: propertyName };\n });\n\n entityMappings.ontologies[ontologyRid].objectTypes[apiName] = {\n objectTypeId: apiName,\n primaryKey: {\n propertyId: blockData.objectType.primaryKeys[0],\n },\n propertyTypes: propertyTypesMap,\n linkTypes: {},\n };\n }\n\n return entityMappings;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,iCAAiC,QAAQ,uCAAuC;AACzF,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,KAAK,QAAQ,OAAO;AAC7B,SAASC,UAAU,QAAQ,MAAM;AACjC,OAAO,KAAKC,E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,GAAG;IACvCC,WAAW,EAAE,CAAC,CAAC;IACfC,cAAc,EAAE,CAAC;EACnB,CAAC;EAED,KACE,MAAM,CAACC,OAAO,EAAEC,SAAS,CAAC,IAAI1B,MAAM,CAAC2B,OAAO,CAC1C9C,UAAU,CAACa,QAAQ,CAAC6B,WACtB,CAAC,EACD;IACA,MAAMK,gBAAwD,GAAG,CAAC,CAAC;IAEnE5B,MAAM,CAACC,IAAI,CAACyB,SAAS,CAACG,UAAU,CAACC,aAAa,CAAC,CAACC,OAAO,CAAEC,YAAY,IAAK;MACxEJ,gBAAgB,CAACI,YAAY,CAAC,GAAG;QAAEC,UAAU,EAAED;MAAa,CAAC;IAC/D,CAAC,CAAC;IAEFZ,cAAc,CAACC,UAAU,CAACC,WAAW,CAAC,CAACC,WAAW,CAACE,OAAO,CAAC,GAAG;MAC5DS,YAAY,EAAET,OAAO;MACrBU,UAAU,EAAE;QACVF,UAAU,EAAEP,SAAS,CAACG,UAAU,CAACO,WAAW,CAAC,CAAC;MAChD,CAAC;MACDN,aAAa,EAAEF,gBAAgB;MAC/BS,SAAS,EAAE,CAAC;IACd,CAAC;EACH;EAEA,OAAOjB,cAAc;AACvB","ignoreList":[]}
1
+ {"version":3,"file":"main.js","names":["consola","fs","path","invariant","yargs","hideBin","defineOntology","apiNamespaceRegex","uuidRegex","main","args","process","argv","commandLineOpts","version","wrap","Math","min","terminalWidth","strict","help","options","input","alias","describe","type","default","coerce","resolve","output","apiNamespace","snapshotDir","outputDir","valueTypesOutput","dependencies","generateCodeSnippets","codeSnippetPackageName","codeSnippetDir","randomnessKey","parseAsync","length","slice","env","NODE_ENV","test","info","undefined","ontologyIr","loadOntology","writeFile","JSON","stringify","valueTypes","importedValueTypes","dependencyFile","snippetPackageName","q"],"sources":["main.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineOntology } from \"../api/defineOntology.js\";\n\nconst apiNamespaceRegex = /^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$/;\nconst uuidRegex =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;\n\nexport default async function main(\n args: string[] = process.argv,\n): Promise<void> {\n const commandLineOpts: {\n input: string;\n output: string;\n apiNamespace: string;\n snapshotDir: string;\n valueTypesOutput: string;\n outputDir?: string;\n dependencies?: string;\n generateCodeSnippets: boolean;\n codeSnippetPackageName: string;\n codeSnippetDir: string;\n randomnessKey?: string;\n } = await yargs(hideBin(args))\n .version(process.env.PACKAGE_VERSION ?? \"\")\n .wrap(Math.min(150, yargs().terminalWidth()))\n .strict()\n .help()\n .options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve,\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve,\n },\n apiNamespace: {\n describe: \"Api name prefix for namespaced ontology types\",\n type: \"string\",\n default: \"\",\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve,\n },\n outputDir: {\n alias: \"d\",\n describe: \"Directory for generated ontology entities\",\n type: \"string\",\n coerce: path.resolve,\n },\n valueTypesOutput: {\n describe: \"Value Type Output File\",\n type: \"string\",\n default: \"value-types.json\",\n coerce: path.resolve,\n },\n dependencies: {\n describe: \"File to write dependencies to\",\n type: \"string\",\n coerce: path.resolve,\n },\n generateCodeSnippets: {\n describe: \"Enable code snippet files creation\",\n type: \"boolean\",\n default: false,\n },\n codeSnippetPackageName: {\n describe:\n \"The package name that will be displayed in the code snippets\",\n default: \"\",\n type: \"string\",\n },\n codeSnippetDir: {\n describe: \"Directory for generated code snippet files\",\n type: \"string\",\n default: \"./\",\n coerce: path.resolve,\n },\n randomnessKey: {\n describe: \"Value used to assure uniqueness of entities\",\n type: \"string\",\n coerce: path.resolve,\n },\n })\n .parseAsync();\n let apiNamespace = \"\";\n if (commandLineOpts.apiNamespace.length !== 0) {\n apiNamespace = (commandLineOpts.apiNamespace.slice(-1) !== \".\")\n ? commandLineOpts.apiNamespace + \".\"\n : commandLineOpts.apiNamespace;\n invariant(apiNamespace.length < 1024, \"API namespace is too long.\");\n invariant(\n apiNamespaceRegex.test(apiNamespace),\n \"API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$\",\n );\n }\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n\n if (\n !commandLineOpts.generateCodeSnippets\n && (commandLineOpts.codeSnippetPackageName !== \"\"\n || commandLineOpts.codeSnippetDir !== path.resolve(\"./\"))\n ) {\n consola.info(\n \"Package name and/or directory supplied for code snippets, but code snippet generation is false.\",\n );\n }\n\n if (commandLineOpts.randomnessKey !== undefined) {\n invariant(\n uuidRegex.test(commandLineOpts.randomnessKey),\n \"Supplied randomness key is not a uuid and shouldn't be used as a uniqueness guarantee\",\n );\n }\n\n const ontologyIr = await loadOntology(\n commandLineOpts.input,\n apiNamespace,\n commandLineOpts.outputDir,\n commandLineOpts.dependencies,\n commandLineOpts.generateCodeSnippets,\n commandLineOpts.codeSnippetPackageName,\n commandLineOpts.codeSnippetDir,\n commandLineOpts.randomnessKey,\n );\n\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(\n commandLineOpts.output,\n JSON.stringify(\n ontologyIr,\n null,\n 2,\n ),\n );\n // No point in generating block if there aren't any value types\n if (\n ontologyIr.valueTypes.valueTypes.length > 0\n || ontologyIr.importedValueTypes.valueTypes.length > 0\n ) {\n await fs.writeFile(\n commandLineOpts.valueTypesOutput,\n JSON.stringify(\n ontologyIr.valueTypes,\n null,\n 2,\n ),\n );\n }\n}\n\nasync function loadOntology(\n input: string,\n apiNamespace: string,\n outputDir: string | undefined,\n dependencyFile: string | undefined,\n generateCodeSnippets: boolean,\n snippetPackageName: string,\n codeSnippetDir: string,\n randomnessKey?: string,\n) {\n const q = await defineOntology(\n apiNamespace,\n async () => await import(input),\n outputDir,\n dependencyFile,\n generateCodeSnippets,\n snippetPackageName,\n codeSnippetDir,\n randomnessKey,\n );\n return q;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,SAAS;AACjC,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AACtC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAOC,SAAS,MAAM,gBAAgB;AACtC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,OAAO,QAAQ,eAAe;AACvC,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,MAAMC,iBAAiB,GAAG,+BAA+B;AACzD,MAAMC,SAAS,GACb,gEAAgE;AAElE,eAAe,eAAeC,IAAIA,CAChCC,IAAc,GAAGC,OAAO,CAACC,IAAI,EACd;EACf,MAAMC,eAYL,GAAG,MAAMT,KAAK,CAACC,OAAO,CAACK,IAAI,CAAC,CAAC,CAC3BI,OAAO,CAAC,mBAA+B,EAAE,CAAC,CAC1CC,IAAI,CAACC,IAAI,CAACC,GAAG,CAAC,GAAG,EAAEb,KAAK,CAAC,CAAC,CAACc,aAAa,CAAC,CAAC,CAAC,CAAC,CAC5CC,MAAM,CAAC,CAAC,CACRC,IAAI,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D,OAAOkB,CAAC;AACV","ignoreList":[]}
@@ -2,10 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var generatorConverters_ontologyir = require('@osdk/generator-converters.ontologyir');
6
5
  var consola = require('consola');
7
- var execa = require('execa');
8
- var jiti = require('jiti');
9
6
  var fs3 = require('fs/promises');
10
7
  var path3 = require('path');
11
8
  var invariant9 = require('tiny-invariant');
@@ -16,7 +13,6 @@ var typescriptSdkDocs = require('@osdk/typescript-sdk-docs');
16
13
  var Mustache = require('mustache');
17
14
  var crypto = require('crypto');
18
15
 
19
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
20
16
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
21
17
 
22
18
  function _interopNamespace(e) {
@@ -2657,21 +2653,10 @@ function getNamespace() {
2657
2653
  }
2658
2654
 
2659
2655
  // src/cli/main.ts
2660
- var generateFunctionsIr;
2661
- async function loadFunctionDiscoveryDeps() {
2662
- try {
2663
- const defineFunctionModule = await import('./defineFunction-7ORD7HD4.cjs');
2664
- generateFunctionsIr = defineFunctionModule.generateFunctionsIr;
2665
- return true;
2666
- } catch (e) {
2667
- consola.consola.warn("Failed to load function discovery dependencies:", e instanceof Error ? e.message : e);
2668
- return false;
2669
- }
2670
- }
2671
2656
  var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
2672
2657
  var uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
2673
2658
  async function main(args = process.argv) {
2674
- const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.16.0-beta.8").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
2659
+ const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.16.0-beta.9").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
2675
2660
  input: {
2676
2661
  alias: "i",
2677
2662
  describe: "Input file",
@@ -2735,41 +2720,6 @@ async function main(args = process.argv) {
2735
2720
  describe: "Value used to assure uniqueness of entities",
2736
2721
  type: "string",
2737
2722
  coerce: path3__namespace.resolve
2738
- },
2739
- generateFunctionsOsdk: {
2740
- describe: "Output folder for generated OSDK for functions",
2741
- type: "string",
2742
- coerce: path3__namespace.resolve
2743
- },
2744
- functionsRootDir: {
2745
- describe: "Root folder containing function definitions",
2746
- type: "string",
2747
- coerce: path3__namespace.resolve
2748
- },
2749
- functionsOutput: {
2750
- describe: "Output folder for function IR",
2751
- type: "string",
2752
- coerce: path3__namespace.resolve
2753
- },
2754
- configPath: {
2755
- describe: "Path to the TypeScript config file",
2756
- type: "string",
2757
- coerce: path3__namespace.resolve
2758
- },
2759
- pythonFunctionsDir: {
2760
- describe: "Path to Python functions source directory (enables Python function discovery)",
2761
- type: "string",
2762
- coerce: path3__namespace.resolve
2763
- },
2764
- pythonBinary: {
2765
- describe: "Path to Python binary (required when using --pythonFunctionsDir)",
2766
- type: "string",
2767
- coerce: path3__namespace.resolve
2768
- },
2769
- pythonRootProjectDir: {
2770
- describe: "Root project directory for Python functions (defaults to parent of pythonFunctionsDir)",
2771
- type: "string",
2772
- coerce: path3__namespace.resolve
2773
2723
  }
2774
2724
  }).parseAsync();
2775
2725
  let apiNamespace = "";
@@ -2791,96 +2741,11 @@ async function main(args = process.argv) {
2791
2741
  if (ontologyIr.valueTypes.valueTypes.length > 0 || ontologyIr.importedValueTypes.valueTypes.length > 0) {
2792
2742
  await fs3__namespace.writeFile(commandLineOpts.valueTypesOutput, JSON.stringify(ontologyIr.valueTypes, null, 2));
2793
2743
  }
2794
- if (commandLineOpts.pythonFunctionsDir && !commandLineOpts.pythonBinary) {
2795
- consola.consola.error("--pythonBinary is required when using --pythonFunctionsDir");
2796
- return;
2797
- }
2798
- if (commandLineOpts.functionsOutput !== void 0 && commandLineOpts.functionsRootDir !== void 0) {
2799
- const hasFunctionDeps = await loadFunctionDiscoveryDeps();
2800
- if (!hasFunctionDeps || !generateFunctionsIr) {
2801
- consola.consola.error("Function discovery requires optional dependencies. Install @foundry/functions-typescript-* packages.");
2802
- return;
2803
- }
2804
- consola.consola.info(`Loading function IR`);
2805
- const functionsIr = await generateFunctionsIr(commandLineOpts.functionsRootDir, commandLineOpts.configPath, createEntityMappings(ontologyIr));
2806
- await fs3__namespace.writeFile(commandLineOpts.functionsOutput, JSON.stringify(functionsIr, null, 2));
2807
- return;
2808
- }
2809
- if (commandLineOpts.generateFunctionsOsdk !== void 0) {
2810
- const fullMetadata = generatorConverters_ontologyir.OntologyIrToFullMetadataConverter.getFullMetadataFromIr(ontologyIr.ontology);
2811
- if (commandLineOpts.pythonFunctionsDir) {
2812
- const effectivePythonRootDir = commandLineOpts.pythonRootProjectDir ?? path3__namespace.dirname(commandLineOpts.pythonFunctionsDir);
2813
- const queryTypes = await generatorConverters_ontologyir.OntologyIrToFullMetadataConverter.getOsdkQueryTypes(commandLineOpts.pythonBinary, void 0, void 0, commandLineOpts.pythonFunctionsDir, effectivePythonRootDir);
2814
- const functionNames = Object.keys(queryTypes);
2815
- if (functionNames.length > 0) {
2816
- fullMetadata.queryTypes = queryTypes;
2817
- consola.consola.info(`Discovered ${functionNames.length} Python function(s): ${functionNames.join(", ")}`);
2818
- } else {
2819
- consola.consola.info("No Python functions discovered.");
2820
- }
2821
- }
2822
- consola.consola.info(`Saving full ontology metadata to ${commandLineOpts.generateFunctionsOsdk}`);
2823
- await fs3__namespace.writeFile(path3__namespace.join(commandLineOpts.generateFunctionsOsdk, ".ontology.json"), JSON.stringify(fullMetadata, null, 2));
2824
- await fullMetadataToOsdk(commandLineOpts.generateFunctionsOsdk);
2825
- }
2826
2744
  }
2827
2745
  async function loadOntology(input, apiNamespace, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey) {
2828
- const q = await defineOntology(apiNamespace, async () => {
2829
- const jiti$1 = jiti.createJiti(undefined, {
2830
- moduleCache: true,
2831
- debug: false,
2832
- importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) })
2833
- });
2834
- await jiti$1.import(input);
2835
- }, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey);
2746
+ const q = await defineOntology(apiNamespace, async () => await import(input), outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey);
2836
2747
  return q;
2837
2748
  }
2838
- async function fullMetadataToOsdk(workDir) {
2839
- const functionOsdkDir = path3__namespace.join(workDir, "generated");
2840
- await fs3__namespace.rm(functionOsdkDir, {
2841
- recursive: true,
2842
- force: true
2843
- });
2844
- await fs3__namespace.mkdir(functionOsdkDir, {
2845
- recursive: true
2846
- });
2847
- try {
2848
- await execa.execa("pnpm", ["exec", "osdk", "unstable", "typescript", "generate", "--outDir", functionOsdkDir, "--ontologyPath", path3__namespace.join(workDir, ".ontology.json"), "--beta", "true", "--packageType", "module", "--version", "dev"]);
2849
- } catch (error) {
2850
- await fs3__namespace.rm(functionOsdkDir, {
2851
- recursive: true,
2852
- force: true
2853
- });
2854
- throw error;
2855
- }
2856
- }
2857
- function createEntityMappings(ontologyIr) {
2858
- const entityMappings = {
2859
- ontologies: {}
2860
- };
2861
- const ontologyRid = "ontology";
2862
- entityMappings.ontologies[ontologyRid] = {
2863
- objectTypes: {},
2864
- interfaceTypes: {}
2865
- };
2866
- for (const [apiName, blockData] of Object.entries(ontologyIr.ontology.objectTypes)) {
2867
- const propertyTypesMap = {};
2868
- Object.keys(blockData.objectType.propertyTypes).forEach((propertyName) => {
2869
- propertyTypesMap[propertyName] = {
2870
- propertyId: propertyName
2871
- };
2872
- });
2873
- entityMappings.ontologies[ontologyRid].objectTypes[apiName] = {
2874
- objectTypeId: apiName,
2875
- primaryKey: {
2876
- propertyId: blockData.objectType.primaryKeys[0]
2877
- },
2878
- propertyTypes: propertyTypesMap,
2879
- linkTypes: {}
2880
- };
2881
- }
2882
- return entityMappings;
2883
- }
2884
2749
  var MAX_SEARCH_DEPTH = 5;
2885
2750
  function addDependency(namespaceNoDot, fileInPackage) {
2886
2751
  let dir = path3__namespace.dirname(fileInPackage);