@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 +6 -0
- package/build/browser/cli/main.js +2 -145
- package/build/browser/cli/main.js.map +1 -1
- package/build/cjs/index.cjs +2 -137
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/cli/main.js +2 -145
- package/build/esm/cli/main.js.map +1 -1
- package/build/types/cli/main.d.ts.map +1 -1
- package/package.json +5 -6
- package/build/cjs/defineFunction-7ORD7HD4.cjs +0 -72
- package/build/cjs/defineFunction-7ORD7HD4.cjs.map +0 -1
package/build/esm/cli/main.js
CHANGED
|
@@ -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.
|
|
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.primaryK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AC+F,EAAE,CAACD,eAAe,EAAE;MAAEE,SAAS,EAAE,IAAI;MAAEC,KAAK,EAAE;IAAK,CAAC,CAAC;IAC9D,MAAM9B,KAAK;EACb;AACF;AAEA,SAASG,oBAAoBA,CAACV,UAAsB,EAA0B;EAC5E,MAAMuC,cAAsC,GAAG;IAC7CC,UAAU,EAAE,CAAC;EACf,CAAC;EAED,MAAMC,WAAW,GAAG,UAAU;EAC9BF,cAAc,CAACC,UAAU,CAACC,WAAW,CAAC,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,IA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Aa,EACbQ,YAAoB,EACpBE,SAA6B,EAC7BsB,cAAkC,EAClCnB,oBAA6B,EAC7BoB,kBAA0B,EAC1BlB,cAAsB,EACtBC,aAAsB,EACtB;EACA,MAAMkB,CAAC,GAAG,MAAMlD,cAAc,CAC5BwB,YAAY,EACZ,YAAY,MAAM,MAAM,CAACR,KAAK,CAAC,EAC/BU,SAAS,EACTsB,cAAc,EACdnB,oBAAoB,EACpBoB,kBAAkB,EAClBlB,cAAc,EACdC,aACF,CAAC;EACD,OAAOkB,CAAC;AACV","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"eA4Be,SAAe,KAC5BA,kBACC","names":["args: string[]"],"sources":["../../../src/cli/main.ts"],"version":3,"file":"main.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/maker",
|
|
3
|
-
"version": "0.16.0-beta.
|
|
3
|
+
"version": "0.16.0-beta.9",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,15 +29,14 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@osdk/typescript-sdk-docs": "^0.2.0",
|
|
31
31
|
"consola": "^3.4.2",
|
|
32
|
-
"execa": "^9.6.0",
|
|
33
32
|
"jiti": "^2.5.1",
|
|
34
33
|
"mustache": "^4.2.0",
|
|
35
34
|
"semver-ts": "^1.0.3",
|
|
36
35
|
"tiny-invariant": "^1.3.3",
|
|
37
36
|
"ts-node": "^10.9.2",
|
|
38
37
|
"yargs": "^17.7.2",
|
|
39
|
-
"@osdk/
|
|
40
|
-
"@osdk/
|
|
38
|
+
"@osdk/generator-converters.ontologyir": "~2.8.0-beta.15",
|
|
39
|
+
"@osdk/api": "~2.8.0-beta.15"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@types/mustache": "^4.2.6",
|
|
@@ -46,8 +45,8 @@
|
|
|
46
45
|
"typescript": "~5.5.4",
|
|
47
46
|
"vitest": "^3.2.4",
|
|
48
47
|
"@osdk/monorepo.api-extractor": "~0.7.0-beta.1",
|
|
49
|
-
"@osdk/
|
|
50
|
-
"@osdk/
|
|
48
|
+
"@osdk/client.unstable": "~2.8.0-beta.15",
|
|
49
|
+
"@osdk/monorepo.tsconfig": "~0.7.0-beta.1"
|
|
51
50
|
},
|
|
52
51
|
"publishConfig": {
|
|
53
52
|
"access": "public"
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var generatorConverters_ontologyir = require('@osdk/generator-converters.ontologyir');
|
|
4
|
-
var consola = require('consola');
|
|
5
|
-
var path = require('path');
|
|
6
|
-
|
|
7
|
-
function _interopNamespace(e) {
|
|
8
|
-
if (e && e.__esModule) return e;
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
26
|
-
|
|
27
|
-
// src/api/defineFunction.ts
|
|
28
|
-
var cachedFunctionDiscoverer = null;
|
|
29
|
-
async function loadFunctionDiscoverer() {
|
|
30
|
-
if (cachedFunctionDiscoverer != null) {
|
|
31
|
-
return cachedFunctionDiscoverer;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const modulePath = "@foundry/functions-typescript-osdk-discovery";
|
|
35
|
-
const module = await import(
|
|
36
|
-
/* @vite-ignore */
|
|
37
|
-
modulePath
|
|
38
|
-
);
|
|
39
|
-
cachedFunctionDiscoverer = module.FunctionDiscoverer;
|
|
40
|
-
return cachedFunctionDiscoverer;
|
|
41
|
-
} catch (e) {
|
|
42
|
-
consola.consola.warn("Failed to load @foundry/functions-typescript-osdk-discovery:", e instanceof Error ? e.message : e);
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function extractFunctionEntries(discoveredFunctions) {
|
|
47
|
-
return discoveredFunctions.map((fn) => {
|
|
48
|
-
if (fn.locator.type !== "typescriptOsdk") {
|
|
49
|
-
throw new Error(`OAC functions must be TypeScript, got type: ${fn.locator.type}`);
|
|
50
|
-
}
|
|
51
|
-
const locator = fn.locator;
|
|
52
|
-
return [locator.typescriptOsdk.functionName, fn];
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async function generateFunctionsIr(rootDir, configPath, entityMappings) {
|
|
56
|
-
const functionsDiscoverer = await loadFunctionDiscoverer();
|
|
57
|
-
if (!functionsDiscoverer) {
|
|
58
|
-
throw new Error("Function discovery requires @foundry/functions-typescript-osdk-discovery to be installed");
|
|
59
|
-
}
|
|
60
|
-
const tsConfigPath = configPath ?? path__namespace.join(rootDir, "tsconfig.json");
|
|
61
|
-
const program = generatorConverters_ontologyir.OntologyIrToFullMetadataConverter.createProgram(tsConfigPath, rootDir);
|
|
62
|
-
const functionsDir = path__namespace.join(rootDir, "functions");
|
|
63
|
-
const fd = new functionsDiscoverer(program, rootDir, functionsDir, entityMappings);
|
|
64
|
-
const functions = fd.discover();
|
|
65
|
-
return {
|
|
66
|
-
functionsBlockDataV1: Object.fromEntries(extractFunctionEntries(functions.discoveredFunctions))
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
exports.generateFunctionsIr = generateFunctionsIr;
|
|
71
|
-
//# sourceMappingURL=defineFunction-7ORD7HD4.cjs.map
|
|
72
|
-
//# sourceMappingURL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AI,MAAM,0FAA0F,CAAA;AAAA;AAE5G,EAAA,MAAM,YAAe,GAAA,UAAA,IAAmBC,eAAK,CAAA,IAAA,CAAA,OAAA,EAAS,eAAe,CAAA;AACrE,EAAA,MAAM,OAAU,GAAAC,gEAAA,CAAkC,aAAc,CAAA,YAAA,EAAc,OAAO,CAAA;AACrF,EAAM,MAAA,YAAA,GAAoBD,eAAK,CAAA,IAAA,CAAA,OAAA,EAAS,WAAW,CAAA;AACnD,EAAA,MAAM,KAAK,IAAI,mBAAA,CAAoB,OAAS,EAAA,OAAA,EAAS,cAAc,cAAc,CAAA;AACjF,EAAM,MAAA,SAAA,GAAY,GAAG,QAAS,EAAA;AAC9B,EAAO,OAAA;AAAA,IACL,sBAAsB,MAAO,CAAA,WAAA,CAAY,sBAAuB,CAAA,SAAA,CAAU,mBAAmB,CAAC;AAAA,GAChG;AACF","file":"defineFunction-7ORD7HD4.cjs","sourcesContent":["/*\n * Copyright 2025 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 { OntologyIrToFullMetadataConverter } from \"@osdk/generator-converters.ontologyir\";\nimport { consola } from \"consola\";\nimport * as path from \"node:path\";\n\n// Type definitions for optional function discovery dependencies\n\n// Lazy-loaded function discovery module\nlet cachedFunctionDiscoverer = null;\nasync function loadFunctionDiscoverer() {\n if (cachedFunctionDiscoverer != null) {\n return cachedFunctionDiscoverer;\n }\n try {\n const modulePath = \"@foundry/functions-typescript-osdk-discovery\";\n const module = await import(/* @vite-ignore */modulePath);\n cachedFunctionDiscoverer = module.FunctionDiscoverer;\n return cachedFunctionDiscoverer;\n } catch (e) {\n consola.warn(\"Failed to load @foundry/functions-typescript-osdk-discovery:\", e instanceof Error ? e.message : e);\n return null;\n }\n}\nfunction extractFunctionEntries(discoveredFunctions) {\n return discoveredFunctions.map(fn => {\n if (fn.locator.type !== \"typescriptOsdk\") {\n throw new Error(`OAC functions must be TypeScript, got type: ${fn.locator.type}`);\n }\n const locator = fn.locator;\n return [locator.typescriptOsdk.functionName, fn];\n });\n}\nexport async function generateFunctionsIr(rootDir, configPath, entityMappings) {\n const functionsDiscoverer = await loadFunctionDiscoverer();\n if (!functionsDiscoverer) {\n throw new Error(\"Function discovery requires @foundry/functions-typescript-osdk-discovery to be installed\");\n }\n const tsConfigPath = configPath ?? path.join(rootDir, \"tsconfig.json\");\n const program = OntologyIrToFullMetadataConverter.createProgram(tsConfigPath, rootDir);\n const functionsDir = path.join(rootDir, \"functions\");\n const fd = new functionsDiscoverer(program, rootDir, functionsDir, entityMappings);\n const functions = fd.discover();\n return {\n functionsBlockDataV1: Object.fromEntries(extractFunctionEntries(functions.discoveredFunctions))\n };\n}"]}
|