@osdk/maker 0.16.0-beta.4 → 0.16.0-beta.6
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 +22 -0
- package/README.md +4 -1
- package/build/browser/api/defineFunction.js +61 -0
- package/build/browser/api/defineFunction.js.map +1 -0
- package/build/browser/api/object/ObjectTypeDatasourceDefinition.js.map +1 -1
- package/build/browser/api/test/objects.test.js +11 -2
- package/build/browser/api/test/objects.test.js.map +1 -1
- package/build/browser/cli/main.js +145 -2
- package/build/browser/cli/main.js.map +1 -1
- package/build/browser/conversion/toMarketplace/convertDatasourceDefinition.js +17 -6
- package/build/browser/conversion/toMarketplace/convertDatasourceDefinition.js.map +1 -1
- package/build/cjs/defineFunction-7ORD7HD4.cjs +72 -0
- package/build/cjs/defineFunction-7ORD7HD4.cjs.map +1 -0
- package/build/cjs/index.cjs +154 -8
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +10 -3
- package/build/esm/api/defineFunction.js +61 -0
- package/build/esm/api/defineFunction.js.map +1 -0
- package/build/esm/api/object/ObjectTypeDatasourceDefinition.js.map +1 -1
- package/build/esm/api/test/objects.test.js +11 -2
- package/build/esm/api/test/objects.test.js.map +1 -1
- package/build/esm/cli/main.js +145 -2
- package/build/esm/cli/main.js.map +1 -1
- package/build/esm/conversion/toMarketplace/convertDatasourceDefinition.js +17 -6
- package/build/esm/conversion/toMarketplace/convertDatasourceDefinition.js.map +1 -1
- package/build/types/api/defineFunction.d.ts +19 -0
- package/build/types/api/defineFunction.d.ts.map +1 -0
- package/build/types/api/object/ObjectTypeDatasourceDefinition.d.ts +10 -3
- package/build/types/api/object/ObjectTypeDatasourceDefinition.d.ts.map +1 -1
- package/build/types/cli/main.d.ts.map +1 -1
- package/build/types/conversion/toMarketplace/convertDatasourceDefinition.d.ts.map +1 -1
- package/package.json +7 -5
package/build/cjs/index.cjs
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var generatorConverters_ontologyir = require('@osdk/generator-converters.ontologyir');
|
|
5
6
|
var consola = require('consola');
|
|
7
|
+
var execa = require('execa');
|
|
8
|
+
var jiti = require('jiti');
|
|
6
9
|
var fs3 = require('fs/promises');
|
|
7
10
|
var path3 = require('path');
|
|
8
11
|
var invariant9 = require('tiny-invariant');
|
|
@@ -13,6 +16,7 @@ var typescriptSdkDocs = require('@osdk/typescript-sdk-docs');
|
|
|
13
16
|
var Mustache = require('mustache');
|
|
14
17
|
var crypto = require('crypto');
|
|
15
18
|
|
|
19
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
21
|
|
|
18
22
|
function _interopNamespace(e) {
|
|
@@ -1314,7 +1318,7 @@ function convertInterface(interfaceType) {
|
|
|
1314
1318
|
};
|
|
1315
1319
|
}
|
|
1316
1320
|
function convertDatasourceDefinition(objectType, properties) {
|
|
1317
|
-
const baseDatasource = objectType.datasources?.find((ds) => ["dataset", "stream", "restrictedView"].includes(ds.type));
|
|
1321
|
+
const baseDatasource = objectType.datasources?.find((ds) => ["dataset", "stream", "restrictedView", "direct"].includes(ds.type));
|
|
1318
1322
|
switch (baseDatasource?.type) {
|
|
1319
1323
|
case "stream":
|
|
1320
1324
|
const window = baseDatasource.retentionPeriod;
|
|
@@ -1353,6 +1357,15 @@ function convertDatasourceDefinition(objectType, properties) {
|
|
|
1353
1357
|
propertyMapping: buildPropertyMapping(properties)
|
|
1354
1358
|
}
|
|
1355
1359
|
};
|
|
1360
|
+
case "direct":
|
|
1361
|
+
return {
|
|
1362
|
+
type: "direct",
|
|
1363
|
+
direct: {
|
|
1364
|
+
directSourceRid: objectType.apiName,
|
|
1365
|
+
propertyMapping: buildPropertyMapping(properties),
|
|
1366
|
+
propertySecurityGroups: convertPropertySecurityGroups(baseDatasource, properties, objectType.primaryKeyPropertyApiName)
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1356
1369
|
case "dataset":
|
|
1357
1370
|
default:
|
|
1358
1371
|
if (objectType.properties?.some((prop) => typeof prop.type === "object" && prop.type.type === "marking") || baseDatasource?.objectSecurityPolicy || baseDatasource?.propertySecurityGroups) {
|
|
@@ -1393,6 +1406,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
|
|
|
1393
1406
|
},
|
|
1394
1407
|
additionalMandatory: {
|
|
1395
1408
|
markings: {},
|
|
1409
|
+
assumedMarkingsV2: {},
|
|
1396
1410
|
assumedMarkings: []
|
|
1397
1411
|
}
|
|
1398
1412
|
}
|
|
@@ -1419,7 +1433,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
|
|
|
1419
1433
|
rid: ds.objectSecurityPolicy?.name || "defaultObjectSecurityPolicy",
|
|
1420
1434
|
security: {
|
|
1421
1435
|
type: "granular",
|
|
1422
|
-
granular: convertGranularPolicy(ds.objectSecurityPolicy?.granularPolicy, ds.objectSecurityPolicy?.
|
|
1436
|
+
granular: convertGranularPolicy(ds.objectSecurityPolicy?.granularPolicy, ds.objectSecurityPolicy?.appliedMarkings, ds.objectSecurityPolicy?.assumedMarkings)
|
|
1423
1437
|
},
|
|
1424
1438
|
type: {
|
|
1425
1439
|
type: "primaryKey",
|
|
@@ -1432,7 +1446,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
|
|
|
1432
1446
|
rid: psg.name,
|
|
1433
1447
|
security: {
|
|
1434
1448
|
type: "granular",
|
|
1435
|
-
granular: convertGranularPolicy(psg.granularPolicy, psg.
|
|
1449
|
+
granular: convertGranularPolicy(psg.granularPolicy, psg.appliedMarkings, psg.assumedMarkings)
|
|
1436
1450
|
},
|
|
1437
1451
|
type: {
|
|
1438
1452
|
type: "property",
|
|
@@ -1444,7 +1458,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
|
|
|
1444
1458
|
})) ?? []]
|
|
1445
1459
|
};
|
|
1446
1460
|
}
|
|
1447
|
-
function convertGranularPolicy(granularPolicy,
|
|
1461
|
+
function convertGranularPolicy(granularPolicy, appliedMarkings, assumedMarkings) {
|
|
1448
1462
|
return {
|
|
1449
1463
|
viewPolicy: {
|
|
1450
1464
|
granularPolicyCondition: granularPolicy ? convertSecurityCondition(granularPolicy) : {
|
|
@@ -1454,8 +1468,9 @@ function convertGranularPolicy(granularPolicy, additionalMandatoryMarkings) {
|
|
|
1454
1468
|
}
|
|
1455
1469
|
},
|
|
1456
1470
|
additionalMandatory: {
|
|
1457
|
-
markings:
|
|
1458
|
-
assumedMarkings: []
|
|
1471
|
+
markings: appliedMarkings ?? {},
|
|
1472
|
+
assumedMarkings: [],
|
|
1473
|
+
assumedMarkingsV2: assumedMarkings ?? {}
|
|
1459
1474
|
}
|
|
1460
1475
|
}
|
|
1461
1476
|
};
|
|
@@ -2610,10 +2625,21 @@ function addNamespaceIfNone(apiName) {
|
|
|
2610
2625
|
}
|
|
2611
2626
|
|
|
2612
2627
|
// src/cli/main.ts
|
|
2628
|
+
var generateFunctionsIr;
|
|
2629
|
+
async function loadFunctionDiscoveryDeps() {
|
|
2630
|
+
try {
|
|
2631
|
+
const defineFunctionModule = await import('./defineFunction-7ORD7HD4.cjs');
|
|
2632
|
+
generateFunctionsIr = defineFunctionModule.generateFunctionsIr;
|
|
2633
|
+
return true;
|
|
2634
|
+
} catch (e) {
|
|
2635
|
+
consola.consola.warn("Failed to load function discovery dependencies:", e instanceof Error ? e.message : e);
|
|
2636
|
+
return false;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2613
2639
|
var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
|
|
2614
2640
|
var uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
2615
2641
|
async function main(args = process.argv) {
|
|
2616
|
-
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.16.0-beta.
|
|
2642
|
+
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.16.0-beta.6").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
2617
2643
|
input: {
|
|
2618
2644
|
alias: "i",
|
|
2619
2645
|
describe: "Input file",
|
|
@@ -2677,6 +2703,41 @@ async function main(args = process.argv) {
|
|
|
2677
2703
|
describe: "Value used to assure uniqueness of entities",
|
|
2678
2704
|
type: "string",
|
|
2679
2705
|
coerce: path3__namespace.resolve
|
|
2706
|
+
},
|
|
2707
|
+
generateFunctionsOsdk: {
|
|
2708
|
+
describe: "Output folder for generated OSDK for functions",
|
|
2709
|
+
type: "string",
|
|
2710
|
+
coerce: path3__namespace.resolve
|
|
2711
|
+
},
|
|
2712
|
+
functionsRootDir: {
|
|
2713
|
+
describe: "Root folder containing function definitions",
|
|
2714
|
+
type: "string",
|
|
2715
|
+
coerce: path3__namespace.resolve
|
|
2716
|
+
},
|
|
2717
|
+
functionsOutput: {
|
|
2718
|
+
describe: "Output folder for function IR",
|
|
2719
|
+
type: "string",
|
|
2720
|
+
coerce: path3__namespace.resolve
|
|
2721
|
+
},
|
|
2722
|
+
configPath: {
|
|
2723
|
+
describe: "Path to the TypeScript config file",
|
|
2724
|
+
type: "string",
|
|
2725
|
+
coerce: path3__namespace.resolve
|
|
2726
|
+
},
|
|
2727
|
+
pythonFunctionsDir: {
|
|
2728
|
+
describe: "Path to Python functions source directory (enables Python function discovery)",
|
|
2729
|
+
type: "string",
|
|
2730
|
+
coerce: path3__namespace.resolve
|
|
2731
|
+
},
|
|
2732
|
+
pythonBinary: {
|
|
2733
|
+
describe: "Path to Python binary (required when using --pythonFunctionsDir)",
|
|
2734
|
+
type: "string",
|
|
2735
|
+
coerce: path3__namespace.resolve
|
|
2736
|
+
},
|
|
2737
|
+
pythonRootProjectDir: {
|
|
2738
|
+
describe: "Root project directory for Python functions (defaults to parent of pythonFunctionsDir)",
|
|
2739
|
+
type: "string",
|
|
2740
|
+
coerce: path3__namespace.resolve
|
|
2680
2741
|
}
|
|
2681
2742
|
}).parseAsync();
|
|
2682
2743
|
let apiNamespace = "";
|
|
@@ -2698,11 +2759,96 @@ async function main(args = process.argv) {
|
|
|
2698
2759
|
if (ontologyIr.valueTypes.valueTypes.length > 0 || ontologyIr.importedValueTypes.valueTypes.length > 0) {
|
|
2699
2760
|
await fs3__namespace.writeFile(commandLineOpts.valueTypesOutput, JSON.stringify(ontologyIr.valueTypes, null, 2));
|
|
2700
2761
|
}
|
|
2762
|
+
if (commandLineOpts.pythonFunctionsDir && !commandLineOpts.pythonBinary) {
|
|
2763
|
+
consola.consola.error("--pythonBinary is required when using --pythonFunctionsDir");
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2766
|
+
if (commandLineOpts.functionsOutput !== void 0 && commandLineOpts.functionsRootDir !== void 0) {
|
|
2767
|
+
const hasFunctionDeps = await loadFunctionDiscoveryDeps();
|
|
2768
|
+
if (!hasFunctionDeps || !generateFunctionsIr) {
|
|
2769
|
+
consola.consola.error("Function discovery requires optional dependencies. Install @foundry/functions-typescript-* packages.");
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2772
|
+
consola.consola.info(`Loading function IR`);
|
|
2773
|
+
const functionsIr = await generateFunctionsIr(commandLineOpts.functionsRootDir, commandLineOpts.configPath, createEntityMappings(ontologyIr));
|
|
2774
|
+
await fs3__namespace.writeFile(commandLineOpts.functionsOutput, JSON.stringify(functionsIr, null, 2));
|
|
2775
|
+
return;
|
|
2776
|
+
}
|
|
2777
|
+
if (commandLineOpts.generateFunctionsOsdk !== void 0) {
|
|
2778
|
+
const fullMetadata = generatorConverters_ontologyir.OntologyIrToFullMetadataConverter.getFullMetadataFromIr(ontologyIr.ontology);
|
|
2779
|
+
if (commandLineOpts.pythonFunctionsDir) {
|
|
2780
|
+
const effectivePythonRootDir = commandLineOpts.pythonRootProjectDir ?? path3__namespace.dirname(commandLineOpts.pythonFunctionsDir);
|
|
2781
|
+
const queryTypes = await generatorConverters_ontologyir.OntologyIrToFullMetadataConverter.getOsdkQueryTypes(commandLineOpts.pythonBinary, void 0, void 0, commandLineOpts.pythonFunctionsDir, effectivePythonRootDir);
|
|
2782
|
+
const functionNames = Object.keys(queryTypes);
|
|
2783
|
+
if (functionNames.length > 0) {
|
|
2784
|
+
fullMetadata.queryTypes = queryTypes;
|
|
2785
|
+
consola.consola.info(`Discovered ${functionNames.length} Python function(s): ${functionNames.join(", ")}`);
|
|
2786
|
+
} else {
|
|
2787
|
+
consola.consola.info("No Python functions discovered.");
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
consola.consola.info(`Saving full ontology metadata to ${commandLineOpts.generateFunctionsOsdk}`);
|
|
2791
|
+
await fs3__namespace.writeFile(path3__namespace.join(commandLineOpts.generateFunctionsOsdk, ".ontology.json"), JSON.stringify(fullMetadata, null, 2));
|
|
2792
|
+
await fullMetadataToOsdk(commandLineOpts.generateFunctionsOsdk);
|
|
2793
|
+
}
|
|
2701
2794
|
}
|
|
2702
2795
|
async function loadOntology(input, apiNamespace, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey) {
|
|
2703
|
-
const q = await defineOntology(apiNamespace, async () =>
|
|
2796
|
+
const q = await defineOntology(apiNamespace, async () => {
|
|
2797
|
+
const jiti$1 = jiti.createJiti(undefined, {
|
|
2798
|
+
moduleCache: true,
|
|
2799
|
+
debug: false,
|
|
2800
|
+
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)) })
|
|
2801
|
+
});
|
|
2802
|
+
await jiti$1.import(input);
|
|
2803
|
+
}, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey);
|
|
2704
2804
|
return q;
|
|
2705
2805
|
}
|
|
2806
|
+
async function fullMetadataToOsdk(workDir) {
|
|
2807
|
+
const functionOsdkDir = path3__namespace.join(workDir, "generated");
|
|
2808
|
+
await fs3__namespace.rm(functionOsdkDir, {
|
|
2809
|
+
recursive: true,
|
|
2810
|
+
force: true
|
|
2811
|
+
});
|
|
2812
|
+
await fs3__namespace.mkdir(functionOsdkDir, {
|
|
2813
|
+
recursive: true
|
|
2814
|
+
});
|
|
2815
|
+
try {
|
|
2816
|
+
await execa.execa("pnpm", ["exec", "osdk", "unstable", "typescript", "generate", "--outDir", functionOsdkDir, "--ontologyPath", path3__namespace.join(workDir, ".ontology.json"), "--beta", "true", "--packageType", "module", "--version", "dev"]);
|
|
2817
|
+
} catch (error) {
|
|
2818
|
+
await fs3__namespace.rm(functionOsdkDir, {
|
|
2819
|
+
recursive: true,
|
|
2820
|
+
force: true
|
|
2821
|
+
});
|
|
2822
|
+
throw error;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
function createEntityMappings(ontologyIr) {
|
|
2826
|
+
const entityMappings = {
|
|
2827
|
+
ontologies: {}
|
|
2828
|
+
};
|
|
2829
|
+
const ontologyRid = "ontology";
|
|
2830
|
+
entityMappings.ontologies[ontologyRid] = {
|
|
2831
|
+
objectTypes: {},
|
|
2832
|
+
interfaceTypes: {}
|
|
2833
|
+
};
|
|
2834
|
+
for (const [apiName, blockData] of Object.entries(ontologyIr.ontology.objectTypes)) {
|
|
2835
|
+
const propertyTypesMap = {};
|
|
2836
|
+
Object.keys(blockData.objectType.propertyTypes).forEach((propertyName) => {
|
|
2837
|
+
propertyTypesMap[propertyName] = {
|
|
2838
|
+
propertyId: propertyName
|
|
2839
|
+
};
|
|
2840
|
+
});
|
|
2841
|
+
entityMappings.ontologies[ontologyRid].objectTypes[apiName] = {
|
|
2842
|
+
objectTypeId: apiName,
|
|
2843
|
+
primaryKey: {
|
|
2844
|
+
propertyId: blockData.objectType.primaryKeys[0]
|
|
2845
|
+
},
|
|
2846
|
+
propertyTypes: propertyTypesMap,
|
|
2847
|
+
linkTypes: {}
|
|
2848
|
+
};
|
|
2849
|
+
}
|
|
2850
|
+
return entityMappings;
|
|
2851
|
+
}
|
|
2706
2852
|
var MAX_SEARCH_DEPTH = 5;
|
|
2707
2853
|
function addDependency(namespaceNoDot, fileInPackage) {
|
|
2708
2854
|
let dir = path3__namespace.dirname(fileInPackage);
|