@osdk/generator-converters.preview 0.1.0-beta.1 → 0.1.0-beta.3
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 +27 -0
- package/build/browser/ActionLogicRuleConverter.js +24 -2
- package/build/browser/ActionLogicRuleConverter.js.map +1 -1
- package/build/browser/PreviewOntologyIrConverter.js +15 -28
- package/build/browser/PreviewOntologyIrConverter.js.map +1 -1
- package/build/browser/cli/generate-sdk.js +249 -31
- package/build/browser/cli/generate-sdk.js.map +1 -1
- package/build/browser/ridUtils.js +10 -5
- package/build/browser/ridUtils.js.map +1 -1
- package/build/cjs/index.cjs +26 -31
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +2 -2
- package/build/esm/ActionLogicRuleConverter.js +24 -2
- package/build/esm/ActionLogicRuleConverter.js.map +1 -1
- package/build/esm/PreviewOntologyIrConverter.js +15 -28
- package/build/esm/PreviewOntologyIrConverter.js.map +1 -1
- package/build/esm/cli/generate-sdk.js +249 -31
- package/build/esm/cli/generate-sdk.js.map +1 -1
- package/build/esm/ridUtils.js +10 -5
- package/build/esm/ridUtils.js.map +1 -1
- package/build/types/ActionLogicRuleConverter.d.ts +7 -1
- package/build/types/ActionLogicRuleConverter.d.ts.map +1 -1
- package/build/types/PreviewOntologyIrConverter.d.ts +2 -2
- package/build/types/PreviewOntologyIrConverter.d.ts.map +1 -1
- package/build/types/ridUtils.d.ts +3 -2
- package/build/types/ridUtils.d.ts.map +1 -1
- package/package.json +11 -8
- package/build/browser/ridUtils.test.js +0 -43
- package/build/browser/ridUtils.test.js.map +0 -1
- package/build/esm/ridUtils.test.js +0 -43
- package/build/esm/ridUtils.test.js.map +0 -1
- package/build/types/ridUtils.test.d.ts +0 -1
- package/build/types/ridUtils.test.d.ts.map +0 -1
|
@@ -15,51 +15,202 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { generateClientSdkVersionTwoPointZero } from "@osdk/generator";
|
|
18
|
+
import { OntologyIrToFullMetadataConverter } from "@osdk/generator-converters.ontologyir";
|
|
19
|
+
import { consola } from "consola";
|
|
20
|
+
import { spawnSync } from "node:child_process";
|
|
21
|
+
import * as fsSync from "node:fs";
|
|
18
22
|
import * as fs from "node:fs/promises";
|
|
23
|
+
import * as os from "node:os";
|
|
19
24
|
import * as path from "node:path";
|
|
25
|
+
import yargs from "yargs";
|
|
26
|
+
import { hideBin } from "yargs/helpers";
|
|
20
27
|
import { PreviewOntologyIrConverter } from "../PreviewOntologyIrConverter.js";
|
|
21
|
-
const
|
|
28
|
+
const PYTHON_SDK_PACKAGE_NAME = "ontology_sdk";
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Generates the Python SDK package into the conda environment's site-packages
|
|
32
|
+
* so that Python function discovery can resolve ontology type imports.
|
|
33
|
+
*/
|
|
34
|
+
function generatePythonSdk(previewMetadata, pythonBinary) {
|
|
35
|
+
// Build the Python-compatible metadata: unwrap actionTypes and add globalFunctions
|
|
36
|
+
const pythonMetadata = {
|
|
37
|
+
...previewMetadata,
|
|
38
|
+
actionTypes: Object.fromEntries(Object.entries(previewMetadata.actionTypes).map(([key, fullMeta]) => [key, fullMeta.actionType])),
|
|
39
|
+
globalFunctions: {
|
|
40
|
+
queryTypes: {},
|
|
41
|
+
valueTypes: {}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const objectTypes = Object.keys(previewMetadata.objectTypes ?? {});
|
|
45
|
+
if (objectTypes.length === 0) {
|
|
46
|
+
consola.info("No object types found, skipping Python SDK generation.");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const ontologyApiName = previewMetadata.ontology?.apiName ?? "ontology";
|
|
50
|
+
|
|
51
|
+
// Discover site-packages from the conda environment
|
|
52
|
+
const siteResult = spawnSync(pythonBinary, ["-c", "import site; print(site.getsitepackages()[0])"], {
|
|
53
|
+
encoding: "utf-8"
|
|
54
|
+
});
|
|
55
|
+
if (siteResult.status !== 0 || !siteResult.stdout?.trim()) {
|
|
56
|
+
consola.warn(`Could not discover Python site-packages: ${siteResult.stderr || siteResult.error}`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const sitePackages = siteResult.stdout.trim();
|
|
60
|
+
consola.info(`Python site-packages: ${sitePackages}`);
|
|
61
|
+
|
|
62
|
+
// Write metadata to a temp file for the generator
|
|
63
|
+
const tmpDir = fsSync.mkdtempSync(path.join(os.tmpdir(), "python-sdk-"));
|
|
64
|
+
const tmpMetadata = path.join(tmpDir, "metadata.json");
|
|
65
|
+
fsSync.writeFileSync(tmpMetadata, JSON.stringify(pythonMetadata, null, 2), "utf-8");
|
|
66
|
+
|
|
67
|
+
// Run the Python SDK generator into the temp directory.
|
|
68
|
+
// The generator creates <output-dir>/ontology_sdk/ which is a project
|
|
69
|
+
// directory containing ontology_sdk/ (the actual Python package), setup.py, etc.
|
|
70
|
+
consola.info("Generating Python SDK...");
|
|
71
|
+
const packageName = PYTHON_SDK_PACKAGE_NAME;
|
|
72
|
+
const genResult = spawnSync(pythonBinary, ["-m", "foundry_sdk_generator", "generate_package", "--output-dir", tmpDir, "--package-name", packageName, "--package-version", "0.0.0", "--ontology", ontologyApiName, "--object-types", objectTypes.join(","), "--cache-path", tmpMetadata, "--force"], {
|
|
73
|
+
encoding: "utf-8",
|
|
74
|
+
stdio: "pipe"
|
|
75
|
+
});
|
|
76
|
+
if (genResult.status !== 0) {
|
|
77
|
+
consola.warn(`Python SDK generation failed (non-fatal): ${genResult.stderr || genResult.stdout}`);
|
|
78
|
+
fsSync.rmSync(tmpDir, {
|
|
79
|
+
recursive: true,
|
|
80
|
+
force: true
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
34
83
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
84
|
+
|
|
85
|
+
// The generator creates <tmpDir>/ontology_sdk/ontology_sdk/ (the importable
|
|
86
|
+
// package). Copy just the inner package into site-packages so Python can
|
|
87
|
+
// resolve `import ontology_sdk`.
|
|
88
|
+
const generatedPackage = path.join(tmpDir, packageName, packageName);
|
|
89
|
+
const destPackage = path.join(sitePackages, packageName);
|
|
90
|
+
|
|
91
|
+
// Remove any previous version
|
|
92
|
+
fsSync.rmSync(destPackage, {
|
|
93
|
+
recursive: true,
|
|
94
|
+
force: true
|
|
95
|
+
});
|
|
96
|
+
fsSync.cpSync(generatedPackage, destPackage, {
|
|
97
|
+
recursive: true
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Clean up temp directory
|
|
101
|
+
fsSync.rmSync(tmpDir, {
|
|
102
|
+
recursive: true,
|
|
103
|
+
force: true
|
|
104
|
+
});
|
|
105
|
+
consola.info(`Python SDK installed to ${destPackage}`);
|
|
106
|
+
}
|
|
107
|
+
async function main() {
|
|
108
|
+
const argv = await yargs(hideBin(process.argv)).strict().help().version(false) // so that we can use --version argument for the package version
|
|
109
|
+
.usage("$0 --input <path> --package-name <name> --version <ver> --output-dir <dir>").options({
|
|
110
|
+
"input": {
|
|
111
|
+
describe: "Path to the OntologyIR JSON file",
|
|
112
|
+
type: "string",
|
|
113
|
+
demandOption: true,
|
|
114
|
+
coerce: path.resolve
|
|
115
|
+
},
|
|
116
|
+
"package-name": {
|
|
117
|
+
describe: "Name for the generated SDK package",
|
|
118
|
+
type: "string",
|
|
119
|
+
demandOption: true
|
|
120
|
+
},
|
|
121
|
+
"version": {
|
|
122
|
+
describe: "Version string for the generated SDK",
|
|
123
|
+
type: "string",
|
|
124
|
+
demandOption: true
|
|
125
|
+
},
|
|
126
|
+
"output-dir": {
|
|
127
|
+
describe: "Directory where the SDK will be generated",
|
|
128
|
+
type: "string",
|
|
129
|
+
demandOption: true,
|
|
130
|
+
coerce: path.resolve
|
|
131
|
+
},
|
|
132
|
+
"functions-dir": {
|
|
133
|
+
describe: "Path to TypeScript functions source directory (enables TS function discovery)",
|
|
134
|
+
type: "string",
|
|
135
|
+
coerce: path.resolve
|
|
136
|
+
},
|
|
137
|
+
"node-modules-path": {
|
|
138
|
+
describe: "Path to node_modules containing @foundry packages (for TS function discovery)",
|
|
139
|
+
type: "string",
|
|
140
|
+
coerce: path.resolve
|
|
141
|
+
},
|
|
142
|
+
"python-functions-dir": {
|
|
143
|
+
describe: "Path to Python functions source directory (enables Python function discovery)",
|
|
144
|
+
type: "string",
|
|
145
|
+
coerce: path.resolve
|
|
146
|
+
},
|
|
147
|
+
"python-root-project-dir": {
|
|
148
|
+
describe: "Root project directory for Python functions (defaults to parent of python-functions-dir)",
|
|
149
|
+
type: "string",
|
|
150
|
+
coerce: path.resolve
|
|
151
|
+
},
|
|
152
|
+
"python-binary": {
|
|
153
|
+
describe: "Path to Python binary (required when using --python-functions-dir)",
|
|
154
|
+
type: "string",
|
|
155
|
+
coerce: path.resolve
|
|
156
|
+
}
|
|
157
|
+
}).parse();
|
|
158
|
+
const inputFile = argv.input;
|
|
159
|
+
const packageName = argv.packageName;
|
|
160
|
+
const packageVersion = argv.version;
|
|
161
|
+
const outputDir = argv.outputDir;
|
|
38
162
|
|
|
39
163
|
// Validate input file exists
|
|
40
164
|
try {
|
|
41
165
|
await fs.access(inputFile);
|
|
42
166
|
} catch {
|
|
43
|
-
|
|
44
|
-
console.error(`Error: Input file does not exist: ${inputFile}`);
|
|
167
|
+
consola.error(`Input file does not exist: ${inputFile}`);
|
|
45
168
|
process.exit(1);
|
|
46
169
|
}
|
|
47
|
-
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.log(`Converting ${inputFile}...`);
|
|
170
|
+
consola.info(`Converting ${inputFile}...`);
|
|
50
171
|
const fileContent = await fs.readFile(inputFile, "utf-8");
|
|
51
172
|
let irJson;
|
|
52
173
|
try {
|
|
53
174
|
const parsed = JSON.parse(fileContent);
|
|
54
175
|
// Handle both wrapped (ontology.objectTypes) and unwrapped (objectTypes) formats
|
|
55
176
|
irJson = parsed.ontology ?? parsed;
|
|
56
|
-
} catch
|
|
57
|
-
|
|
58
|
-
|
|
177
|
+
} catch {
|
|
178
|
+
consola.error(`Failed to parse JSON from ${inputFile}`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Basic structural validation before passing to converter
|
|
183
|
+
const ir = irJson;
|
|
184
|
+
if (!ir || typeof ir !== "object" || !("objectTypes" in ir) || !("actionTypes" in ir)) {
|
|
185
|
+
consola.error(`Invalid OntologyIR structure in ${inputFile}. Expected objectTypes and actionTypes fields.`);
|
|
59
186
|
process.exit(1);
|
|
60
187
|
}
|
|
61
188
|
const previewMetadata = PreviewOntologyIrConverter.getPreviewFullMetadataFromIr(irJson);
|
|
62
189
|
|
|
190
|
+
// Generate the Python SDK before function discovery so that Python functions
|
|
191
|
+
// that import ontology types (e.g. `from ontology_sdk.ontology.objects import X`)
|
|
192
|
+
// can be successfully parsed during discovery.
|
|
193
|
+
if (argv.pythonBinary && argv.pythonFunctionsDir) {
|
|
194
|
+
generatePythonSdk(previewMetadata, argv.pythonBinary);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Function discovery is optional - only run if at least one functions flag is provided
|
|
198
|
+
if (argv.functionsDir || argv.pythonFunctionsDir) {
|
|
199
|
+
if (argv.pythonFunctionsDir && !argv.pythonBinary) {
|
|
200
|
+
consola.error("--python-binary is required when using --python-functions-dir");
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
const effectivePythonRootDir = argv.pythonRootProjectDir ?? (argv.pythonFunctionsDir ? path.dirname(argv.pythonFunctionsDir) : undefined);
|
|
204
|
+
const queryTypes = await OntologyIrToFullMetadataConverter.getOsdkQueryTypes(argv.pythonBinary, argv.functionsDir, argv.nodeModulesPath, argv.pythonFunctionsDir, effectivePythonRootDir, previewMetadata);
|
|
205
|
+
const functionNames = Object.keys(queryTypes);
|
|
206
|
+
if (functionNames.length > 0) {
|
|
207
|
+
previewMetadata.queryTypes = queryTypes;
|
|
208
|
+
consola.info(`Discovered ${functionNames.length} function(s): ${functionNames.join(", ")}`);
|
|
209
|
+
} else {
|
|
210
|
+
consola.info("No functions discovered.");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
63
214
|
// Convert ActionTypeFullMetadata to ActionTypeV2 for generator compatibility
|
|
64
215
|
const metadata = {
|
|
65
216
|
...previewMetadata,
|
|
@@ -69,8 +220,18 @@ async function main() {
|
|
|
69
220
|
await fs.mkdir(fullOutputDir, {
|
|
70
221
|
recursive: true
|
|
71
222
|
});
|
|
72
|
-
|
|
73
|
-
|
|
223
|
+
|
|
224
|
+
// Clean the output directory before generation. The generator's verifyOutDir
|
|
225
|
+
// requires an empty directory, but a previous SDK build may exist from
|
|
226
|
+
// function discovery (so TypeScript functions can resolve @ontology/sdk imports).
|
|
227
|
+
const existingEntries = await fs.readdir(fullOutputDir);
|
|
228
|
+
for (const entry of existingEntries) {
|
|
229
|
+
await fs.rm(path.join(fullOutputDir, entry), {
|
|
230
|
+
recursive: true,
|
|
231
|
+
force: true
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
consola.info(`Generating SDK to ${fullOutputDir}...`);
|
|
74
235
|
await generateClientSdkVersionTwoPointZero(metadata, `osdk-generator/${packageVersion} (from-ir)`, {
|
|
75
236
|
async writeFile(filePath, contents) {
|
|
76
237
|
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(fullOutputDir, filePath);
|
|
@@ -91,15 +252,72 @@ async function main() {
|
|
|
91
252
|
}, fullOutputDir, "module", new Map(), new Map(), new Map(), false, []);
|
|
92
253
|
const metadataPath = path.join(fullOutputDir, "ontology-metadata.json");
|
|
93
254
|
await fs.writeFile(metadataPath, JSON.stringify(previewMetadata, null, 2), "utf-8");
|
|
255
|
+
consola.info(`Wrote ${metadataPath}`);
|
|
256
|
+
|
|
257
|
+
// Write Python-compatible metadata that the foundry-sdk-generator expects.
|
|
258
|
+
// This uses the unwrapped actionTypes (ActionTypeV2 instead of
|
|
259
|
+
// ActionTypeFullMetadata) and adds the globalFunctions key.
|
|
260
|
+
if (argv.pythonFunctionsDir) {
|
|
261
|
+
const pythonMetadataPath = path.join(fullOutputDir, "python-ontology-metadata.json");
|
|
262
|
+
await fs.writeFile(pythonMetadataPath, JSON.stringify({
|
|
263
|
+
...metadata,
|
|
264
|
+
globalFunctions: {
|
|
265
|
+
queryTypes: {},
|
|
266
|
+
valueTypes: {}
|
|
267
|
+
}
|
|
268
|
+
}, null, 2), "utf-8");
|
|
269
|
+
consola.info(`Wrote ${pythonMetadataPath}`);
|
|
270
|
+
}
|
|
94
271
|
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
|
|
272
|
+
// Write runtime metadata.json for the TypeScript functions runtime.
|
|
273
|
+
// The runtime needs entity metadata to resolve ontology types during
|
|
274
|
+
// function discovery. Without this, functions using Client/Osdk.Instance
|
|
275
|
+
// produce diagnostics that block ALL function discovery.
|
|
276
|
+
if (argv.functionsDir) {
|
|
277
|
+
const functionsProjectRoot = path.resolve(argv.functionsDir, "..", "..");
|
|
278
|
+
const runtimeMetadataDir = path.join(functionsProjectRoot, ".dev-server", "var", "conf");
|
|
279
|
+
const runtimeMetadataPath = path.join(runtimeMetadataDir, "metadata.json");
|
|
280
|
+
const ontologyRid = previewMetadata.ontology.rid;
|
|
281
|
+
const objectTypeMetadata = {};
|
|
282
|
+
if (previewMetadata.objectTypes) {
|
|
283
|
+
for (const [apiName, objData] of Object.entries(previewMetadata.objectTypes)) {
|
|
284
|
+
const objType = objData.objectType;
|
|
285
|
+
const propertyTypeMetadata = {};
|
|
286
|
+
if (objType.properties) {
|
|
287
|
+
for (const [propApiName, propDef] of Object.entries(objType.properties)) {
|
|
288
|
+
propertyTypeMetadata[propApiName] = {
|
|
289
|
+
propertyTypeApiName: propApiName,
|
|
290
|
+
type: propDef.dataType
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
objectTypeMetadata[apiName] = {
|
|
295
|
+
objectTypeApiName: apiName,
|
|
296
|
+
primaryKeyPropertyTypeId: objType.primaryKey,
|
|
297
|
+
propertyTypeMetadata,
|
|
298
|
+
linkTypeMetadata: {}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
await fs.mkdir(runtimeMetadataDir, {
|
|
304
|
+
recursive: true
|
|
305
|
+
});
|
|
306
|
+
await fs.writeFile(runtimeMetadataPath, JSON.stringify({
|
|
307
|
+
ontologyRid,
|
|
308
|
+
objectTypeMetadata,
|
|
309
|
+
interfaceTypeMetadata: {},
|
|
310
|
+
magritteSourceMetadata: {}
|
|
311
|
+
}), "utf-8");
|
|
312
|
+
consola.info(`Wrote runtime metadata to ${runtimeMetadataPath}`);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
consola.warn(`Could not write runtime metadata: ${e}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
consola.success("Done!");
|
|
99
318
|
}
|
|
100
319
|
main().catch(err => {
|
|
101
|
-
|
|
102
|
-
console.error("Error:", err instanceof Error ? err.message : err);
|
|
320
|
+
consola.error(err instanceof Error ? err.message : err);
|
|
103
321
|
process.exit(1);
|
|
104
322
|
});
|
|
105
323
|
//# sourceMappingURL=generate-sdk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-sdk.js","names":["generateClientSdkVersionTwoPointZero","fs","path","PreviewOntologyIrConverter","USAGE","main","args","process","argv","slice","length","console","error","exit","inputArg","packageName","packageVersion","outputArg","inputFile","resolve","outputDir","access","log","fileContent","readFile","irJson","parsed","JSON","parse","ontology","e","previewMetadata","getPreviewFullMetadataFromIr","metadata","actionTypes","Object","fromEntries","entries","map","key","fullMeta","actionType","fullOutputDir","join","mkdir","recursive","writeFile","filePath","contents","fullPath","isAbsolute","dirname","dirPath","readdir","Map","metadataPath","stringify","catch","err","Error","message"],"sources":["generate-sdk.ts"],"sourcesContent":["#!/usr/bin/env node\n/*\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 { generateClientSdkVersionTwoPointZero } from \"@osdk/generator\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { PreviewOntologyIrConverter } from \"../PreviewOntologyIrConverter.js\";\n\nconst USAGE =\n `Usage: generate-sdk <input-ontology-ir.json> <package-name> <package-version> <output-dir>\n\nArguments:\n input-ontology-ir.json Path to the OntologyIR JSON file\n package-name Name for the generated SDK package\n package-version Version string for the generated SDK\n output-dir Directory where the SDK will be generated`;\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n\n if (args.length < 4) {\n // eslint-disable-next-line no-console\n console.error(USAGE);\n process.exit(1);\n }\n\n const [inputArg, packageName, packageVersion, outputArg] = args;\n const inputFile = path.resolve(inputArg);\n const outputDir = path.resolve(outputArg);\n\n // Validate input file exists\n try {\n await fs.access(inputFile);\n } catch {\n // eslint-disable-next-line no-console\n console.error(`Error: Input file does not exist: ${inputFile}`);\n process.exit(1);\n }\n\n // eslint-disable-next-line no-console\n console.log(`Converting ${inputFile}...`);\n\n const fileContent = await fs.readFile(inputFile, \"utf-8\");\n let irJson: unknown;\n try {\n const parsed = JSON.parse(fileContent);\n // Handle both wrapped (ontology.objectTypes) and unwrapped (objectTypes) formats\n irJson = parsed.ontology ?? parsed;\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(`Error: Failed to parse JSON from ${inputFile}`);\n process.exit(1);\n }\n\n const previewMetadata = PreviewOntologyIrConverter\n .getPreviewFullMetadataFromIr(\n irJson as Parameters<\n typeof PreviewOntologyIrConverter.getPreviewFullMetadataFromIr\n >[0],\n );\n\n // Convert ActionTypeFullMetadata to ActionTypeV2 for generator compatibility\n const metadata = {\n ...previewMetadata,\n actionTypes: Object.fromEntries(\n Object.entries(previewMetadata.actionTypes).map(([key, fullMeta]) => [\n key,\n fullMeta.actionType,\n ]),\n ),\n };\n\n const fullOutputDir = path.join(outputDir, packageName);\n await fs.mkdir(fullOutputDir, { recursive: true });\n\n const hostFs = {\n async writeFile(filePath: string, contents: string): Promise<void> {\n const fullPath = path.isAbsolute(filePath)\n ? filePath\n : path.join(fullOutputDir, filePath);\n await fs.mkdir(path.dirname(fullPath), { recursive: true });\n await fs.writeFile(fullPath, contents, \"utf-8\");\n },\n async mkdir(dirPath: string): Promise<void> {\n const fullPath = path.isAbsolute(dirPath)\n ? dirPath\n : path.join(fullOutputDir, dirPath);\n await fs.mkdir(fullPath, { recursive: true });\n },\n async readdir(dirPath: string): Promise<string[]> {\n return fs.readdir(dirPath);\n },\n };\n\n // eslint-disable-next-line no-console\n console.log(`Generating SDK to ${fullOutputDir}...`);\n\n await generateClientSdkVersionTwoPointZero(\n metadata,\n `osdk-generator/${packageVersion} (from-ir)`,\n hostFs,\n fullOutputDir,\n \"module\",\n new Map(),\n new Map(),\n new Map(),\n false,\n [],\n );\n\n const metadataPath = path.join(fullOutputDir, \"ontology-metadata.json\");\n await fs.writeFile(\n metadataPath,\n JSON.stringify(previewMetadata, null, 2),\n \"utf-8\",\n );\n\n // eslint-disable-next-line no-console\n console.log(`Wrote ${metadataPath}`);\n // eslint-disable-next-line no-console\n console.log(\"Done!\");\n}\n\nmain().catch((err: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Error:\", err instanceof Error ? err.message : err);\n process.exit(1);\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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,OAAe,EAAiB;MAC1C,MAAMH,QAAQ,GAAG/C,IAAI,CAACgD,UAAU,CAACE,OAAO,CAAC,GACrCA,OAAO,GACPlD,IAAI,CAACyC,IAAI,CAACD,aAAa,EAAEU,OAAO,CAAC;MACrC,MAAMnD,EAAE,CAAC2C,KAAK,CAACK,QAAQ,EAAE;QAAEJ,SAAS,EAAE;MAAK,CAAC,CAAC;IAC/C,CAAC;IACD,MAAMQ,OAAOA,CAACD,OAAe,EAAqB;MAChD,OAAOnD,EAAE,CAACoD,OAAO,CAACD,OAAO,CAAC;IAC5B;EACF,CAAC,EASCV,aAAa,EACb,QAAQ,EACR,IAAIY,GAAG,CAAC,CAAC,EACT,IAAIA,GAAG,CAAC,CAAC,EACT,IAAIA,GAAG,CAAC,CAAC,EACT,KAAK,EACL,EACF,CAAC;EAED,MAAMC,YAAY,GAAGrD,IAAI,CAACyC,IAAI,CAACD,aAAa,EAAE,wBAAwB,CAAC;EACvE,MAAMzC,EAAE,CAAC6C,SAAS,CAChBS,YAAY,EACZ5B,IAAI,CAAC6B,SAAS,CAACzB,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,EACxC,OACF,CAAC;;EAED;EACApB,OAAO,CAACW,GAAG,CAAC,SAASiC,YAAY,EAAE,CAAC;EACpC;EACA5C,OAAO,CAACW,GAAG,CAAC,OAAO,CAAC;AACtB;AAEAjB,IAAI,CAAC,CAAC,CAACoD,KAAK,CAAEC,GAAY,IAAK;EAC7B;EACA/C,OAAO,CAACC,KAAK,CAAC,QAAQ,EAAE8C,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGF,GAAG,CAAC;EACjEnD,OAAO,CAACM,IAAI,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"generate-sdk.js","names":["generateClientSdkVersionTwoPointZero","OntologyIrToFullMetadataConverter","consola","spawnSync","fsSync","fs","os","path","yargs","hideBin","PreviewOntologyIrConverter","PYTHON_SDK_PACKAGE_NAME","generatePythonSdk","previewMetadata","pythonBinary","pythonMetadata","actionTypes","Object","fromEntries","entries","map","key","fullMeta","actionType","globalFunctions","queryTypes","valueTypes","objectTypes","keys","length","info","ontologyApiName","ontology","apiName","siteResult","encoding","status","stdout","trim","warn","stderr","error","sitePackages","tmpDir","mkdtempSync","join","tmpdir","tmpMetadata","writeFileSync","JSON","stringify","packageName","genResult","stdio","rmSync","recursive","force","generatedPackage","destPackage","cpSync","main","argv","process","strict","help","version","usage","options","describe","type","demandOption","coerce","resolve","parse","inputFile","input","packageVersion","outputDir","access","exit","fileContent","readFile","irJson","parsed","ir","getPreviewFullMetadataFromIr","pythonFunctionsDir","functionsDir","effectivePythonRootDir","pythonRootProjectDir","dirname","undefined","getOsdkQueryTypes","nodeModulesPath","functionNames","metadata","fullOutputDir","mkdir","existingEntries","readdir","entry","rm","writeFile","filePath","contents","fullPath","isAbsolute","dirPath","Map","metadataPath","pythonMetadataPath","functionsProjectRoot","runtimeMetadataDir","runtimeMetadataPath","ontologyRid","rid","objectTypeMetadata","objData","objType","objectType","propertyTypeMetadata","properties","propApiName","propDef","propertyTypeApiName","dataType","objectTypeApiName","primaryKeyPropertyTypeId","primaryKey","linkTypeMetadata","interfaceTypeMetadata","magritteSourceMetadata","e","success","catch","err","Error","message"],"sources":["generate-sdk.ts"],"sourcesContent":["#!/usr/bin/env node\n/*\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 { generateClientSdkVersionTwoPointZero } from \"@osdk/generator\";\nimport { OntologyIrToFullMetadataConverter } from \"@osdk/generator-converters.ontologyir\";\nimport { consola } from \"consola\";\nimport { spawnSync } from \"node:child_process\";\nimport * as fsSync from \"node:fs\";\nimport * as fs from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { PreviewOntologyIrConverter } from \"../PreviewOntologyIrConverter.js\";\n\nconst PYTHON_SDK_PACKAGE_NAME = \"ontology_sdk\";\n\n/**\n * Generates the Python SDK package into the conda environment's site-packages\n * so that Python function discovery can resolve ontology type imports.\n */\nfunction generatePythonSdk(\n previewMetadata: ReturnType<\n typeof PreviewOntologyIrConverter.getPreviewFullMetadataFromIr\n >,\n pythonBinary: string,\n): void {\n // Build the Python-compatible metadata: unwrap actionTypes and add globalFunctions\n const pythonMetadata = {\n ...previewMetadata,\n actionTypes: Object.fromEntries(\n Object.entries(previewMetadata.actionTypes).map(([key, fullMeta]) => [\n key,\n fullMeta.actionType,\n ]),\n ),\n globalFunctions: { queryTypes: {}, valueTypes: {} },\n };\n\n const objectTypes = Object.keys(previewMetadata.objectTypes ?? {});\n if (objectTypes.length === 0) {\n consola.info(\"No object types found, skipping Python SDK generation.\");\n return;\n }\n\n const ontologyApiName = previewMetadata.ontology?.apiName ?? \"ontology\";\n\n // Discover site-packages from the conda environment\n const siteResult = spawnSync(\n pythonBinary,\n [\"-c\", \"import site; print(site.getsitepackages()[0])\"],\n { encoding: \"utf-8\" },\n );\n if (siteResult.status !== 0 || !siteResult.stdout?.trim()) {\n consola.warn(\n `Could not discover Python site-packages: ${\n siteResult.stderr || siteResult.error\n }`,\n );\n return;\n }\n const sitePackages = siteResult.stdout.trim();\n consola.info(`Python site-packages: ${sitePackages}`);\n\n // Write metadata to a temp file for the generator\n const tmpDir = fsSync.mkdtempSync(path.join(os.tmpdir(), \"python-sdk-\"));\n const tmpMetadata = path.join(tmpDir, \"metadata.json\");\n fsSync.writeFileSync(\n tmpMetadata,\n JSON.stringify(pythonMetadata, null, 2),\n \"utf-8\",\n );\n\n // Run the Python SDK generator into the temp directory.\n // The generator creates <output-dir>/ontology_sdk/ which is a project\n // directory containing ontology_sdk/ (the actual Python package), setup.py, etc.\n consola.info(\"Generating Python SDK...\");\n const packageName = PYTHON_SDK_PACKAGE_NAME;\n const genResult = spawnSync(\n pythonBinary,\n [\n \"-m\",\n \"foundry_sdk_generator\",\n \"generate_package\",\n \"--output-dir\",\n tmpDir,\n \"--package-name\",\n packageName,\n \"--package-version\",\n \"0.0.0\",\n \"--ontology\",\n ontologyApiName,\n \"--object-types\",\n objectTypes.join(\",\"),\n \"--cache-path\",\n tmpMetadata,\n \"--force\",\n ],\n { encoding: \"utf-8\", stdio: \"pipe\" },\n );\n\n if (genResult.status !== 0) {\n consola.warn(\n `Python SDK generation failed (non-fatal): ${\n genResult.stderr || genResult.stdout\n }`,\n );\n fsSync.rmSync(tmpDir, { recursive: true, force: true });\n return;\n }\n\n // The generator creates <tmpDir>/ontology_sdk/ontology_sdk/ (the importable\n // package). Copy just the inner package into site-packages so Python can\n // resolve `import ontology_sdk`.\n const generatedPackage = path.join(tmpDir, packageName, packageName);\n const destPackage = path.join(sitePackages, packageName);\n\n // Remove any previous version\n fsSync.rmSync(destPackage, { recursive: true, force: true });\n fsSync.cpSync(generatedPackage, destPackage, { recursive: true });\n\n // Clean up temp directory\n fsSync.rmSync(tmpDir, { recursive: true, force: true });\n\n consola.info(`Python SDK installed to ${destPackage}`);\n}\n\nasync function main(): Promise<void> {\n const argv = await yargs(hideBin(process.argv))\n .strict()\n .help()\n .version(false) // so that we can use --version argument for the package version\n .usage(\n \"$0 --input <path> --package-name <name> --version <ver> --output-dir <dir>\",\n )\n .options({\n \"input\": {\n describe: \"Path to the OntologyIR JSON file\",\n type: \"string\",\n demandOption: true,\n coerce: path.resolve,\n },\n \"package-name\": {\n describe: \"Name for the generated SDK package\",\n type: \"string\",\n demandOption: true,\n },\n \"version\": {\n describe: \"Version string for the generated SDK\",\n type: \"string\",\n demandOption: true,\n },\n \"output-dir\": {\n describe: \"Directory where the SDK will be generated\",\n type: \"string\",\n demandOption: true,\n coerce: path.resolve,\n },\n \"functions-dir\": {\n describe:\n \"Path to TypeScript functions source directory (enables TS function discovery)\",\n type: \"string\",\n coerce: path.resolve,\n },\n \"node-modules-path\": {\n describe:\n \"Path to node_modules containing @foundry packages (for TS function discovery)\",\n type: \"string\",\n coerce: path.resolve,\n },\n \"python-functions-dir\": {\n describe:\n \"Path to Python functions source directory (enables Python function discovery)\",\n type: \"string\",\n coerce: path.resolve,\n },\n \"python-root-project-dir\": {\n describe:\n \"Root project directory for Python functions (defaults to parent of python-functions-dir)\",\n type: \"string\",\n coerce: path.resolve,\n },\n \"python-binary\": {\n describe:\n \"Path to Python binary (required when using --python-functions-dir)\",\n type: \"string\",\n coerce: path.resolve,\n },\n })\n .parse();\n\n const inputFile = argv.input;\n const packageName = argv.packageName;\n const packageVersion = argv.version;\n const outputDir = argv.outputDir;\n\n // Validate input file exists\n try {\n await fs.access(inputFile);\n } catch {\n consola.error(`Input file does not exist: ${inputFile}`);\n process.exit(1);\n }\n\n consola.info(`Converting ${inputFile}...`);\n\n const fileContent = await fs.readFile(inputFile, \"utf-8\");\n let irJson: unknown;\n try {\n const parsed = JSON.parse(fileContent);\n // Handle both wrapped (ontology.objectTypes) and unwrapped (objectTypes) formats\n irJson = parsed.ontology ?? parsed;\n } catch {\n consola.error(`Failed to parse JSON from ${inputFile}`);\n process.exit(1);\n }\n\n // Basic structural validation before passing to converter\n const ir = irJson as Record<string, unknown>;\n if (\n !ir\n || typeof ir !== \"object\"\n || !(\"objectTypes\" in ir)\n || !(\"actionTypes\" in ir)\n ) {\n consola.error(\n `Invalid OntologyIR structure in ${inputFile}. Expected objectTypes and actionTypes fields.`,\n );\n process.exit(1);\n }\n\n const previewMetadata = PreviewOntologyIrConverter\n .getPreviewFullMetadataFromIr(\n irJson as Parameters<\n typeof PreviewOntologyIrConverter.getPreviewFullMetadataFromIr\n >[0],\n );\n\n // Generate the Python SDK before function discovery so that Python functions\n // that import ontology types (e.g. `from ontology_sdk.ontology.objects import X`)\n // can be successfully parsed during discovery.\n if (argv.pythonBinary && argv.pythonFunctionsDir) {\n generatePythonSdk(\n previewMetadata,\n argv.pythonBinary,\n );\n }\n\n // Function discovery is optional - only run if at least one functions flag is provided\n if (argv.functionsDir || argv.pythonFunctionsDir) {\n if (argv.pythonFunctionsDir && !argv.pythonBinary) {\n consola.error(\n \"--python-binary is required when using --python-functions-dir\",\n );\n process.exit(1);\n }\n\n const effectivePythonRootDir = argv.pythonRootProjectDir\n ?? (argv.pythonFunctionsDir\n ? path.dirname(argv.pythonFunctionsDir)\n : undefined);\n\n const queryTypes = await OntologyIrToFullMetadataConverter\n .getOsdkQueryTypes(\n argv.pythonBinary,\n argv.functionsDir,\n argv.nodeModulesPath,\n argv.pythonFunctionsDir,\n effectivePythonRootDir,\n previewMetadata,\n );\n\n const functionNames = Object.keys(queryTypes);\n if (functionNames.length > 0) {\n previewMetadata.queryTypes = queryTypes;\n consola.info(\n `Discovered ${functionNames.length} function(s): ${\n functionNames.join(\", \")\n }`,\n );\n } else {\n consola.info(\"No functions discovered.\");\n }\n }\n\n // Convert ActionTypeFullMetadata to ActionTypeV2 for generator compatibility\n const metadata = {\n ...previewMetadata,\n actionTypes: Object.fromEntries(\n Object.entries(previewMetadata.actionTypes).map(([key, fullMeta]) => [\n key,\n fullMeta.actionType,\n ]),\n ),\n };\n\n const fullOutputDir = path.join(outputDir, packageName);\n await fs.mkdir(fullOutputDir, { recursive: true });\n\n // Clean the output directory before generation. The generator's verifyOutDir\n // requires an empty directory, but a previous SDK build may exist from\n // function discovery (so TypeScript functions can resolve @ontology/sdk imports).\n const existingEntries = await fs.readdir(fullOutputDir);\n for (const entry of existingEntries) {\n await fs.rm(path.join(fullOutputDir, entry), {\n recursive: true,\n force: true,\n });\n }\n\n const hostFs = {\n async writeFile(filePath: string, contents: string): Promise<void> {\n const fullPath = path.isAbsolute(filePath)\n ? filePath\n : path.join(fullOutputDir, filePath);\n await fs.mkdir(path.dirname(fullPath), { recursive: true });\n await fs.writeFile(fullPath, contents, \"utf-8\");\n },\n async mkdir(dirPath: string): Promise<void> {\n const fullPath = path.isAbsolute(dirPath)\n ? dirPath\n : path.join(fullOutputDir, dirPath);\n await fs.mkdir(fullPath, { recursive: true });\n },\n async readdir(dirPath: string): Promise<string[]> {\n return fs.readdir(dirPath);\n },\n };\n\n consola.info(`Generating SDK to ${fullOutputDir}...`);\n\n await generateClientSdkVersionTwoPointZero(\n metadata,\n `osdk-generator/${packageVersion} (from-ir)`,\n hostFs,\n fullOutputDir,\n \"module\",\n new Map(),\n new Map(),\n new Map(),\n false,\n [],\n );\n\n const metadataPath = path.join(fullOutputDir, \"ontology-metadata.json\");\n await fs.writeFile(\n metadataPath,\n JSON.stringify(previewMetadata, null, 2),\n \"utf-8\",\n );\n\n consola.info(`Wrote ${metadataPath}`);\n\n // Write Python-compatible metadata that the foundry-sdk-generator expects.\n // This uses the unwrapped actionTypes (ActionTypeV2 instead of\n // ActionTypeFullMetadata) and adds the globalFunctions key.\n if (argv.pythonFunctionsDir) {\n const pythonMetadataPath = path.join(\n fullOutputDir,\n \"python-ontology-metadata.json\",\n );\n await fs.writeFile(\n pythonMetadataPath,\n JSON.stringify(\n { ...metadata, globalFunctions: { queryTypes: {}, valueTypes: {} } },\n null,\n 2,\n ),\n \"utf-8\",\n );\n consola.info(`Wrote ${pythonMetadataPath}`);\n }\n\n // Write runtime metadata.json for the TypeScript functions runtime.\n // The runtime needs entity metadata to resolve ontology types during\n // function discovery. Without this, functions using Client/Osdk.Instance\n // produce diagnostics that block ALL function discovery.\n if (argv.functionsDir) {\n const functionsProjectRoot = path.resolve(argv.functionsDir, \"..\", \"..\");\n const runtimeMetadataDir = path.join(\n functionsProjectRoot,\n \".dev-server\",\n \"var\",\n \"conf\",\n );\n const runtimeMetadataPath = path.join(runtimeMetadataDir, \"metadata.json\");\n\n const ontologyRid = previewMetadata.ontology.rid;\n\n const objectTypeMetadata: Record<string, unknown> = {};\n if (previewMetadata.objectTypes) {\n for (\n const [apiName, objData] of Object.entries(previewMetadata.objectTypes)\n ) {\n const objType = objData.objectType;\n const propertyTypeMetadata: Record<\n string,\n { propertyTypeApiName: string; type?: unknown }\n > = {};\n if (objType.properties) {\n for (\n const [propApiName, propDef] of Object.entries(objType.properties)\n ) {\n propertyTypeMetadata[propApiName] = {\n propertyTypeApiName: propApiName,\n type: propDef.dataType,\n };\n }\n }\n objectTypeMetadata[apiName] = {\n objectTypeApiName: apiName,\n primaryKeyPropertyTypeId: objType.primaryKey,\n propertyTypeMetadata,\n linkTypeMetadata: {},\n };\n }\n }\n\n const runtimeMetadata = {\n ontologyRid,\n objectTypeMetadata,\n interfaceTypeMetadata: {},\n magritteSourceMetadata: {},\n };\n\n try {\n await fs.mkdir(runtimeMetadataDir, { recursive: true });\n await fs.writeFile(\n runtimeMetadataPath,\n JSON.stringify(runtimeMetadata),\n \"utf-8\",\n );\n consola.info(`Wrote runtime metadata to ${runtimeMetadataPath}`);\n } catch (e) {\n consola.warn(`Could not write runtime metadata: ${e}`);\n }\n }\n\n consola.success(\"Done!\");\n}\n\nmain().catch((err: unknown) => {\n consola.error(err instanceof Error ? err.message : err);\n process.exit(1);\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oCAAoC,QAAQ,iBAAiB;AACtE,SAASC,iCAAiC,QAAQ,uCAAuC;AACzF,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,OAAO,KAAKC,MAAM,MAAM,SAAS;AACjC,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AACtC,OAAO,KAAKC,EAAE,MAAM,SAAS;AAC7B,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,OAAO,QAAQ,eAAe;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AC,CAAC","ignoreList":[]}
|
package/build/esm/ridUtils.js
CHANGED
|
@@ -17,12 +17,17 @@
|
|
|
17
17
|
import { createHash } from "node:crypto";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Generate a deterministic UUID from a string.
|
|
21
|
-
* Uses SHA-256 hash truncated to UUID format
|
|
20
|
+
* Generate a deterministic UUID v5-like identifier from a string.
|
|
21
|
+
* Uses SHA-256 hash truncated to UUID format with version (5) and
|
|
22
|
+
* variant (RFC 4122) bits set for spec compliance.
|
|
22
23
|
*/
|
|
23
24
|
export function toUuid(str) {
|
|
24
|
-
const
|
|
25
|
-
//
|
|
26
|
-
|
|
25
|
+
const hashBytes = createHash("sha256").update(str).digest();
|
|
26
|
+
// Set version to 5 (name-based SHA) in byte 6: clear top nibble, set to 0101
|
|
27
|
+
hashBytes[6] = hashBytes[6] & 0x0f | 0x50;
|
|
28
|
+
// Set variant to RFC 4122 in byte 8: clear top 2 bits, set to 10
|
|
29
|
+
hashBytes[8] = hashBytes[8] & 0x3f | 0x80;
|
|
30
|
+
const hex = hashBytes.subarray(0, 16).toString("hex");
|
|
31
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=ridUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ridUtils.js","names":["createHash","toUuid","str","
|
|
1
|
+
{"version":3,"file":"ridUtils.js","names":["createHash","toUuid","str","hashBytes","update","digest","hex","subarray","toString","slice"],"sources":["ridUtils.ts"],"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 { createHash } from \"node:crypto\";\n\n/**\n * Generate a deterministic UUID v5-like identifier from a string.\n * Uses SHA-256 hash truncated to UUID format with version (5) and\n * variant (RFC 4122) bits set for spec compliance.\n */\nexport function toUuid(str: string): string {\n const hashBytes = createHash(\"sha256\").update(str).digest();\n // Set version to 5 (name-based SHA) in byte 6: clear top nibble, set to 0101\n hashBytes[6] = (hashBytes[6] & 0x0f) | 0x50;\n // Set variant to RFC 4122 in byte 8: clear top 2 bits, set to 10\n hashBytes[8] = (hashBytes[8] & 0x3f) | 0x80;\n\n const hex = hashBytes.subarray(0, 16).toString(\"hex\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${\n hex.slice(16, 20)\n }-${hex.slice(20, 32)}`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,QAAQ,aAAa;;AAExC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,MAAMA,CAACC,GAAW,EAAU;EAC1C,MAAMC,SAAS,GAAGH,UAAU,CAAC,QAAQ,CAAC,CAACI,MAAM,CAACF,GAAG,CAAC,CAACG,MAAM,CAAC,CAAC;EAC3D;EACAF,SAAS,CAAC,CAAC,CAAC,GAAIA,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAI,IAAI;EAC3C;EACAA,SAAS,CAAC,CAAC,CAAC,GAAIA,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAI,IAAI;EAE3C,MAAMG,GAAG,GAAGH,SAAS,CAACI,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAACC,QAAQ,CAAC,KAAK,CAAC;EACrD,OAAO,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAIH,GAAG,CAACG,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAIH,GAAG,CAACG,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAChEH,GAAG,CAACG,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IACfH,GAAG,CAACG,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;AACzB","ignoreList":[]}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { OntologyIrActionTypeBlockDataV2, OntologyIrLogicRule, OntologyIrOntologyBlockDataV2 } from "@osdk/client.unstable";
|
|
2
2
|
import type * as Ontologies from "@osdk/foundry.ontologies";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Build lookups once and convert all logic rules for an action.
|
|
5
|
+
* Avoids rebuilding lookup Maps on every rule.
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertIrLogicRulesToActionLogicRules(rules: OntologyIrLogicRule[], action: OntologyIrActionTypeBlockDataV2, ir?: OntologyIrOntologyBlockDataV2): Ontologies.ActionLogicRule[];
|
|
8
|
+
/**
|
|
9
|
+
* Convert a single OntologyIrLogicRule to ActionLogicRule.
|
|
10
|
+
* Kept as a public API for callers that only need a single rule conversion.
|
|
5
11
|
*/
|
|
6
12
|
export declare function convertIrLogicRuleToActionLogicRule(irRule: OntologyIrLogicRule, action: OntologyIrActionTypeBlockDataV2, ir?: OntologyIrOntologyBlockDataV2): Ontologies.ActionLogicRule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,cACE,iCACA,qBACA,qCACK,uBAAwB;AAC/B,iBAAiB,gBAAgB,0BAA2B
|
|
1
|
+
{"mappings":"AAgBA,cACE,iCACA,qBACA,qCACK,uBAAwB;AAC/B,iBAAiB,gBAAgB,0BAA2B;;;;;AA+D5D,OAAO,iBAAS,sCACdA,OAAO,uBACPC,QAAQ,iCACRC,KAAK,gCACJ,WAAW;;;;;AAad,OAAO,iBAAS,oCACdC,QAAQ,qBACRF,QAAQ,iCACRC,KAAK,gCACJ,WAAW","names":["rules: OntologyIrLogicRule[]","action: OntologyIrActionTypeBlockDataV2","ir?: OntologyIrOntologyBlockDataV2","irRule: OntologyIrLogicRule"],"sources":["../../src/ActionLogicRuleConverter.ts"],"version":3,"file":"ActionLogicRuleConverter.d.ts"}
|
|
@@ -22,8 +22,8 @@ export declare class PreviewOntologyIrConverter {
|
|
|
22
22
|
private static convertObjectTypesWithUuidRids;
|
|
23
23
|
/**
|
|
24
24
|
* Convert IR action types to ActionTypeFullMetadata format.
|
|
25
|
-
*
|
|
25
|
+
* Reuses base converter for action type conversion, then process
|
|
26
|
+
* RIDs to use UUID-based format and adds fullLogicRules.
|
|
26
27
|
*/
|
|
27
28
|
private static convertActionTypesWithFullLogicRules;
|
|
28
|
-
private static convertActionTypeStatus;
|
|
29
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,
|
|
1
|
+
{"mappings":"AAgBA,cAEE,qCACK,uBAAwB;AAC/B,iBAAiB,gBAAgB,0BAA2B;;;;AAQ5D,iBAAiB,oCACP,KAAK,WAAW,sBAAsB,eAChD;CACE,aAAa,eAAe,WAAW;AACxC;;;;;AAMD,OAAO,cAAM,2BAA2B;;;;;CAKtC,OAAO,6BACLA,IAAI,gCACH;;;;CA8BH,eAAe;;;;;;CAkCf,eAAe;AA8BhB","names":["ir: OntologyIrOntologyBlockDataV2"],"sources":["../../src/PreviewOntologyIrConverter.ts"],"version":3,"file":"PreviewOntologyIrConverter.d.ts"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generate a deterministic UUID from a string.
|
|
3
|
-
* Uses SHA-256 hash truncated to UUID format
|
|
2
|
+
* Generate a deterministic UUID v5-like identifier from a string.
|
|
3
|
+
* Uses SHA-256 hash truncated to UUID format with version (5) and
|
|
4
|
+
* variant (RFC 4122) bits set for spec compliance.
|
|
4
5
|
*/
|
|
5
6
|
export declare function toUuid(str: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAuBA,OAAO,iBAAS,OAAOA","names":["str: string"],"sources":["../../src/ridUtils.ts"],"version":3,"file":"ridUtils.d.ts"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@osdk/generator-converters.preview",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-beta.3",
|
|
4
|
+
"description": "OSDK generator with support for Python and TSv2 discovered functions",
|
|
5
5
|
"access": "public",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -29,18 +29,21 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@osdk/foundry.ontologies": "2.
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"@osdk/
|
|
32
|
+
"@osdk/foundry.ontologies": "2.50.0",
|
|
33
|
+
"consola": "^3.4.2",
|
|
34
|
+
"yargs": "17.7.2",
|
|
35
|
+
"@osdk/client.unstable": "~2.8.0-beta.16",
|
|
36
|
+
"@osdk/generator-converters.ontologyir": "~2.8.0-beta.16",
|
|
37
|
+
"@osdk/generator": "~2.8.0-beta.16"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"@types/node": "^24.3.1",
|
|
41
|
+
"@types/yargs": "^17.0.33",
|
|
39
42
|
"ts-expect": "^1.3.0",
|
|
40
43
|
"typescript": "~5.5.4",
|
|
41
44
|
"vitest": "^3.2.4",
|
|
42
|
-
"@osdk/monorepo.
|
|
43
|
-
"@osdk/monorepo.
|
|
45
|
+
"@osdk/monorepo.api-extractor": "~0.7.0-beta.1",
|
|
46
|
+
"@osdk/monorepo.tsconfig": "~0.7.0-beta.1"
|
|
44
47
|
},
|
|
45
48
|
"publishConfig": {
|
|
46
49
|
"access": "public"
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { describe, expect, it } from "vitest";
|
|
18
|
-
import { toUuid } from "./ridUtils.js";
|
|
19
|
-
describe("ridUtils", () => {
|
|
20
|
-
describe("toUuid", () => {
|
|
21
|
-
it("returns a valid UUID format", () => {
|
|
22
|
-
const result = toUuid("test-string");
|
|
23
|
-
// UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
24
|
-
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
25
|
-
});
|
|
26
|
-
it("is deterministic - same input produces same output", () => {
|
|
27
|
-
const input = "my-deterministic-input";
|
|
28
|
-
const result1 = toUuid(input);
|
|
29
|
-
const result2 = toUuid(input);
|
|
30
|
-
expect(result1).toBe(result2);
|
|
31
|
-
});
|
|
32
|
-
it("produces different outputs for different inputs", () => {
|
|
33
|
-
const result1 = toUuid("input-1");
|
|
34
|
-
const result2 = toUuid("input-2");
|
|
35
|
-
expect(result1).not.toBe(result2);
|
|
36
|
-
});
|
|
37
|
-
it("handles empty string", () => {
|
|
38
|
-
const result = toUuid("");
|
|
39
|
-
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
//# sourceMappingURL=ridUtils.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ridUtils.test.js","names":["describe","expect","it","toUuid","result","toMatch","input","result1","result2","toBe","not"],"sources":["ridUtils.test.ts"],"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 { describe, expect, it } from \"vitest\";\nimport { toUuid } from \"./ridUtils.js\";\n\ndescribe(\"ridUtils\", () => {\n describe(\"toUuid\", () => {\n it(\"returns a valid UUID format\", () => {\n const result = toUuid(\"test-string\");\n // UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n expect(result).toMatch(\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,\n );\n });\n\n it(\"is deterministic - same input produces same output\", () => {\n const input = \"my-deterministic-input\";\n const result1 = toUuid(input);\n const result2 = toUuid(input);\n expect(result1).toBe(result2);\n });\n\n it(\"produces different outputs for different inputs\", () => {\n const result1 = toUuid(\"input-1\");\n const result2 = toUuid(\"input-2\");\n expect(result1).not.toBe(result2);\n });\n\n it(\"handles empty string\", () => {\n const result = toUuid(\"\");\n expect(result).toMatch(\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,\n );\n });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