@osdk/maker 0.16.0-beta.5 → 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.
Files changed (31) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -1
  3. package/build/browser/api/defineFunction.js +61 -0
  4. package/build/browser/api/defineFunction.js.map +1 -0
  5. package/build/browser/api/object/ObjectTypeDatasourceDefinition.js.map +1 -1
  6. package/build/browser/api/test/objects.test.js +11 -2
  7. package/build/browser/api/test/objects.test.js.map +1 -1
  8. package/build/browser/cli/main.js +145 -2
  9. package/build/browser/cli/main.js.map +1 -1
  10. package/build/browser/conversion/toMarketplace/convertDatasourceDefinition.js +7 -5
  11. package/build/browser/conversion/toMarketplace/convertDatasourceDefinition.js.map +1 -1
  12. package/build/cjs/defineFunction-7ORD7HD4.cjs +72 -0
  13. package/build/cjs/defineFunction-7ORD7HD4.cjs.map +1 -0
  14. package/build/cjs/index.cjs +144 -7
  15. package/build/cjs/index.cjs.map +1 -1
  16. package/build/cjs/index.d.cts +4 -2
  17. package/build/esm/api/defineFunction.js +61 -0
  18. package/build/esm/api/defineFunction.js.map +1 -0
  19. package/build/esm/api/object/ObjectTypeDatasourceDefinition.js.map +1 -1
  20. package/build/esm/api/test/objects.test.js +11 -2
  21. package/build/esm/api/test/objects.test.js.map +1 -1
  22. package/build/esm/cli/main.js +145 -2
  23. package/build/esm/cli/main.js.map +1 -1
  24. package/build/esm/conversion/toMarketplace/convertDatasourceDefinition.js +7 -5
  25. package/build/esm/conversion/toMarketplace/convertDatasourceDefinition.js.map +1 -1
  26. package/build/types/api/defineFunction.d.ts +19 -0
  27. package/build/types/api/defineFunction.d.ts.map +1 -0
  28. package/build/types/api/object/ObjectTypeDatasourceDefinition.d.ts +4 -2
  29. package/build/types/api/object/ObjectTypeDatasourceDefinition.d.ts.map +1 -1
  30. package/build/types/cli/main.d.ts.map +1 -1
  31. package/package.json +7 -5
@@ -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) {
@@ -1402,6 +1406,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
1402
1406
  },
1403
1407
  additionalMandatory: {
1404
1408
  markings: {},
1409
+ assumedMarkingsV2: {},
1405
1410
  assumedMarkings: []
1406
1411
  }
1407
1412
  }
@@ -1428,7 +1433,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
1428
1433
  rid: ds.objectSecurityPolicy?.name || "defaultObjectSecurityPolicy",
1429
1434
  security: {
1430
1435
  type: "granular",
1431
- granular: convertGranularPolicy(ds.objectSecurityPolicy?.granularPolicy, ds.objectSecurityPolicy?.additionalMandatoryMarkings)
1436
+ granular: convertGranularPolicy(ds.objectSecurityPolicy?.granularPolicy, ds.objectSecurityPolicy?.appliedMarkings, ds.objectSecurityPolicy?.assumedMarkings)
1432
1437
  },
1433
1438
  type: {
1434
1439
  type: "primaryKey",
@@ -1441,7 +1446,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
1441
1446
  rid: psg.name,
1442
1447
  security: {
1443
1448
  type: "granular",
1444
- granular: convertGranularPolicy(psg.granularPolicy, psg.additionalMandatoryMarkings)
1449
+ granular: convertGranularPolicy(psg.granularPolicy, psg.appliedMarkings, psg.assumedMarkings)
1445
1450
  },
1446
1451
  type: {
1447
1452
  type: "property",
@@ -1453,7 +1458,7 @@ function convertPropertySecurityGroups(ds, properties, primaryKeyPropertyApiName
1453
1458
  })) ?? []]
1454
1459
  };
1455
1460
  }
1456
- function convertGranularPolicy(granularPolicy, additionalMandatoryMarkings) {
1461
+ function convertGranularPolicy(granularPolicy, appliedMarkings, assumedMarkings) {
1457
1462
  return {
1458
1463
  viewPolicy: {
1459
1464
  granularPolicyCondition: granularPolicy ? convertSecurityCondition(granularPolicy) : {
@@ -1463,8 +1468,9 @@ function convertGranularPolicy(granularPolicy, additionalMandatoryMarkings) {
1463
1468
  }
1464
1469
  },
1465
1470
  additionalMandatory: {
1466
- markings: additionalMandatoryMarkings ?? {},
1467
- assumedMarkings: []
1471
+ markings: appliedMarkings ?? {},
1472
+ assumedMarkings: [],
1473
+ assumedMarkingsV2: assumedMarkings ?? {}
1468
1474
  }
1469
1475
  }
1470
1476
  };
@@ -2619,10 +2625,21 @@ function addNamespaceIfNone(apiName) {
2619
2625
  }
2620
2626
 
2621
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
+ }
2622
2639
  var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
2623
2640
  var uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
2624
2641
  async function main(args = process.argv) {
2625
- const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.16.0-beta.5").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
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({
2626
2643
  input: {
2627
2644
  alias: "i",
2628
2645
  describe: "Input file",
@@ -2686,6 +2703,41 @@ async function main(args = process.argv) {
2686
2703
  describe: "Value used to assure uniqueness of entities",
2687
2704
  type: "string",
2688
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
2689
2741
  }
2690
2742
  }).parseAsync();
2691
2743
  let apiNamespace = "";
@@ -2707,11 +2759,96 @@ async function main(args = process.argv) {
2707
2759
  if (ontologyIr.valueTypes.valueTypes.length > 0 || ontologyIr.importedValueTypes.valueTypes.length > 0) {
2708
2760
  await fs3__namespace.writeFile(commandLineOpts.valueTypesOutput, JSON.stringify(ontologyIr.valueTypes, null, 2));
2709
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
+ }
2710
2794
  }
2711
2795
  async function loadOntology(input, apiNamespace, outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey) {
2712
- const q = await defineOntology(apiNamespace, async () => await import(input), outputDir, dependencyFile, generateCodeSnippets, snippetPackageName, codeSnippetDir, randomnessKey);
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);
2713
2804
  return q;
2714
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
+ }
2715
2852
  var MAX_SEARCH_DEPTH = 5;
2716
2853
  function addDependency(namespaceNoDot, fileInPackage) {
2717
2854
  let dir = path3__namespace.dirname(fileInPackage);