@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @osdk/generator-converters.preview
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6af21a5: Support python OSDK generation and edit functions discovery
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [6941b4f]
|
|
12
|
+
- @osdk/client.unstable@2.8.0-beta.16
|
|
13
|
+
- @osdk/generator-converters.ontologyir@2.8.0-beta.16
|
|
14
|
+
- @osdk/generator@2.8.0-beta.16
|
|
15
|
+
|
|
16
|
+
## 0.1.0-beta.2
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- a29ed88: Add functions support
|
|
21
|
+
- 35f2f1a: Add Media inputs/outputs for Queries
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [35f2f1a]
|
|
26
|
+
- @osdk/client.unstable@2.8.0-beta.14
|
|
27
|
+
- @osdk/generator@2.8.0-beta.14
|
|
28
|
+
- @osdk/generator-converters.ontologyir@2.8.0-beta.14
|
|
29
|
+
|
|
3
30
|
## 0.1.0-beta.1
|
|
4
31
|
|
|
5
32
|
### Minor Changes
|
|
@@ -61,11 +61,25 @@ function getObjectReferenceType(action, paramKey) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Build lookups once and convert all logic rules for an action.
|
|
65
|
+
* Avoids rebuilding lookup Maps on every rule.
|
|
66
|
+
*/
|
|
67
|
+
export function convertIrLogicRulesToActionLogicRules(rules, action, ir) {
|
|
68
|
+
const objectLookup = buildObjectTypeLookup(ir);
|
|
69
|
+
const interfaceLookup = buildInterfaceTypeLookup(ir);
|
|
70
|
+
return rules.map(irRule => convertSingleRule(irRule, action, objectLookup, interfaceLookup));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Convert a single OntologyIrLogicRule to ActionLogicRule.
|
|
75
|
+
* Kept as a public API for callers that only need a single rule conversion.
|
|
65
76
|
*/
|
|
66
77
|
export function convertIrLogicRuleToActionLogicRule(irRule, action, ir) {
|
|
67
78
|
const objectLookup = buildObjectTypeLookup(ir);
|
|
68
79
|
const interfaceLookup = buildInterfaceTypeLookup(ir);
|
|
80
|
+
return convertSingleRule(irRule, action, objectLookup, interfaceLookup);
|
|
81
|
+
}
|
|
82
|
+
function convertSingleRule(irRule, action, objectLookup, interfaceLookup) {
|
|
69
83
|
switch (irRule.type) {
|
|
70
84
|
case "addObjectRule":
|
|
71
85
|
{
|
|
@@ -86,6 +100,9 @@ export function convertIrLogicRuleToActionLogicRule(irRule, action, ir) {
|
|
|
86
100
|
{
|
|
87
101
|
const r = irRule.addOrModifyObjectRuleV2;
|
|
88
102
|
const objRef = getObjectReferenceType(action, r.objectToModify);
|
|
103
|
+
// propertyArguments left empty: the downstream generator resolves
|
|
104
|
+
// property mappings from the action parameter configuration rather
|
|
105
|
+
// than from the logic rule itself for createOrModify rules.
|
|
89
106
|
const result = {
|
|
90
107
|
type: "createOrModifyObject",
|
|
91
108
|
objectTypeApiName: resolveApiName(objRef.objectTypeId, objectLookup),
|
|
@@ -97,11 +114,16 @@ export function convertIrLogicRuleToActionLogicRule(irRule, action, ir) {
|
|
|
97
114
|
case "modifyObjectRule":
|
|
98
115
|
{
|
|
99
116
|
const r = irRule.modifyObjectRule;
|
|
117
|
+
// Validate that the parameter is an objectReference (throws if not)
|
|
100
118
|
getObjectReferenceType(action, r.objectToModify);
|
|
119
|
+
const modifyPropertyArguments = {};
|
|
120
|
+
for (const [k, v] of Object.entries(r.propertyValues)) {
|
|
121
|
+
modifyPropertyArguments[k] = v;
|
|
122
|
+
}
|
|
101
123
|
const result = {
|
|
102
124
|
type: "modifyObject",
|
|
103
125
|
objectToModify: r.objectToModify,
|
|
104
|
-
propertyArguments:
|
|
126
|
+
propertyArguments: modifyPropertyArguments,
|
|
105
127
|
structPropertyArguments: {}
|
|
106
128
|
};
|
|
107
129
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionLogicRuleConverter.js","names":["buildObjectTypeLookup","ir","objectTypes","undefined","byId","Map","byHyphenated","key","value","Object","entries","apiName","objectType","set","replace","buildInterfaceTypeLookup","interfaceTypes","interfaceType","resolveApiName","id","lookup","get","getObjectReferenceType","action","paramKey","param","actionType","metadata","parameters","type","Error","objectReference","convertIrLogicRuleToActionLogicRule","irRule","objectLookup","interfaceLookup","r","addObjectRule","propertyArguments","k","v","propertyValues","result","objectTypeApiName","objectTypeId","structPropertyArguments","addOrModifyObjectRuleV2","objRef","objectToModify","modifyObjectRule","deleteObjectRule","objectToDelete","addInterfaceRule","interfaceApiName","interfaceTypeApiName","sharedPropertyArguments","modifyInterfaceRule","interfaceObjectToModify","interfaceObjectToModifyParameter"],"sources":["ActionLogicRuleConverter.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 type {\n OntologyIrActionTypeBlockDataV2,\n OntologyIrLogicRule,\n OntologyIrOntologyBlockDataV2,\n} from \"@osdk/client.unstable\";\nimport type * as Ontologies from \"@osdk/foundry.ontologies\";\n\ninterface ApiNameLookup {\n byId: Map<string, string>;\n byHyphenated: Map<string, string>;\n}\n\nfunction buildObjectTypeLookup(\n ir: OntologyIrOntologyBlockDataV2 | undefined,\n): ApiNameLookup | undefined {\n if (!ir?.objectTypes) {\n return undefined;\n }\n const byId = new Map<string, string>();\n const byHyphenated = new Map<string, string>();\n for (const [key, value] of Object.entries(ir.objectTypes)) {\n const apiName = value.objectType.apiName;\n byId.set(key, apiName);\n byHyphenated.set(apiName.replace(/\\./g, \"-\"), apiName);\n }\n return { byId, byHyphenated };\n}\n\nfunction buildInterfaceTypeLookup(\n ir: OntologyIrOntologyBlockDataV2 | undefined,\n): ApiNameLookup | undefined {\n if (!ir?.interfaceTypes) {\n return undefined;\n }\n const byId = new Map<string, string>();\n const byHyphenated = new Map<string, string>();\n for (const [key, value] of Object.entries(ir.interfaceTypes)) {\n const apiName = value.interfaceType.apiName;\n byId.set(key, apiName);\n byHyphenated.set(apiName.replace(/\\./g, \"-\"), apiName);\n }\n return { byId, byHyphenated };\n}\n\nfunction resolveApiName(id: string, lookup: ApiNameLookup | undefined): string {\n if (!lookup) {\n return id;\n }\n return lookup.byId.get(id) ?? lookup.byHyphenated.get(id) ?? id;\n}\n\nfunction getObjectReferenceType(\n action: OntologyIrActionTypeBlockDataV2,\n paramKey: string,\n): { objectTypeId: string } {\n const param = action.actionType.metadata.parameters[paramKey];\n if (!param || param.type.type !== \"objectReference\") {\n throw new Error(\n `Parameter '${paramKey}' must be an objectReference type`,\n );\n }\n return param.type.objectReference;\n}\n\n/**\n * Convert OntologyIrLogicRule to ActionLogicRule for use in ActionTypeFullMetadata.\n */\nexport function convertIrLogicRuleToActionLogicRule(\n irRule: OntologyIrLogicRule,\n action: OntologyIrActionTypeBlockDataV2,\n ir?: OntologyIrOntologyBlockDataV2,\n): Ontologies.ActionLogicRule {\n const objectLookup = buildObjectTypeLookup(ir);\n const interfaceLookup = buildInterfaceTypeLookup(ir);\n\n switch (irRule.type) {\n case \"addObjectRule\": {\n const r = irRule.addObjectRule;\n const propertyArguments: Record<\n Ontologies.PropertyApiName,\n Ontologies.LogicRuleArgument\n > = {};\n for (const [k, v] of Object.entries(r.propertyValues)) {\n propertyArguments[k] = v as Ontologies.LogicRuleArgument;\n }\n const result: Ontologies.CreateObjectLogicRule & {\n type: \"createObject\";\n } = {\n type: \"createObject\",\n objectTypeApiName: resolveApiName(r.objectTypeId, objectLookup),\n propertyArguments,\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"addOrModifyObjectRuleV2\": {\n const r = irRule.addOrModifyObjectRuleV2;\n const objRef = getObjectReferenceType(action, r.objectToModify);\n const result: Ontologies.CreateOrModifyObjectLogicRule & {\n type: \"createOrModifyObject\";\n } = {\n type: \"createOrModifyObject\",\n objectTypeApiName: resolveApiName(objRef.objectTypeId, objectLookup),\n propertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"modifyObjectRule\": {\n const r = irRule.modifyObjectRule;\n getObjectReferenceType(action, r.objectToModify);\n const result: Ontologies.ModifyObjectLogicRule & {\n type: \"modifyObject\";\n } = {\n type: \"modifyObject\",\n objectToModify: r.objectToModify,\n propertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"deleteObjectRule\": {\n const r = irRule.deleteObjectRule;\n const result: Ontologies.DeleteObjectLogicRule & {\n type: \"deleteObject\";\n } = {\n type: \"deleteObject\",\n objectToDelete: r.objectToDelete,\n };\n return result;\n }\n\n case \"addInterfaceRule\": {\n const r = irRule.addInterfaceRule;\n const interfaceApiName = resolveApiName(\n r.interfaceApiName,\n interfaceLookup,\n );\n const result: Ontologies.CreateInterfaceLogicRule & {\n type: \"createInterface\";\n } = {\n type: \"createInterface\",\n interfaceTypeApiName: interfaceApiName,\n objectType: interfaceApiName,\n sharedPropertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"modifyInterfaceRule\": {\n const r = irRule.modifyInterfaceRule;\n const result: Ontologies.ModifyInterfaceLogicRule & {\n type: \"modifyInterface\";\n } = {\n type: \"modifyInterface\",\n interfaceObjectToModify: r.interfaceObjectToModifyParameter,\n sharedPropertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"addLinkRule\":\n throw new Error(\"addLinkRule is not supported for ActionLogicRule\");\n\n case \"deleteLinkRule\":\n throw new Error(\"deleteLinkRule is not supported for ActionLogicRule\");\n\n default:\n throw new Error(\n `Unsupported logic rule type: ${(irRule as { type: string }).type}`,\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,SAASA,qBAAqBA,CAC5BC,EAA6C,EAClB;EAC3B,IAAI,CAACA,EAAE,EAAEC,WAAW,EAAE;IACpB,OAAOC,SAAS;EAClB;EACA,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACtC,MAAMC,YAAY,GAAG,IAAID,GAAG,CAAiB,CAAC;EAC9C,KAAK,MAAM,CAACE,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,EAAE,CAACC,WAAW,CAAC,EAAE;IACzD,MAAMS,OAAO,GAAGH,KAAK,CAACI,UAAU,CAACD,OAAO;IACxCP,IAAI,CAACS,GAAG,CAACN,GAAG,EAAEI,OAAO,CAAC;IACtBL,YAAY,CAACO,GAAG,CAACF,OAAO,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAEH,OAAO,CAAC;EACxD;EACA,OAAO;IAAEP,IAAI;IAAEE;EAAa,CAAC;AAC/B;AAEA,SAASS,wBAAwBA,CAC/Bd,EAA6C,EAClB;EAC3B,IAAI,CAACA,EAAE,EAAEe,cAAc,EAAE;IACvB,OAAOb,SAAS;EAClB;EACA,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACtC,MAAMC,YAAY,GAAG,IAAID,GAAG,CAAiB,CAAC;EAC9C,KAAK,MAAM,CAACE,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,EAAE,CAACe,cAAc,CAAC,EAAE;IAC5D,MAAML,OAAO,GAAGH,KAAK,CAACS,aAAa,CAACN,OAAO;IAC3CP,IAAI,CAACS,GAAG,CAACN,GAAG,EAAEI,OAAO,CAAC;IACtBL,YAAY,CAACO,GAAG,CAACF,OAAO,CAACG,OAAO,CAAC,KAAK,E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API;UACFN,IAAI,EAAE,iBAAiB;UACvByB,oBAAoB,EAAED,gBAAgB;UACtCzC,UAAU,EAAEyC,gBAAgB;UAC5BE,uBAAuB,EAAE,CAAC,CAAC;UAC3BV,uBAAuB,EAAE,CAAC;QAC5B,CAAC;MAEH;IAEA,KAAK,qBAAqB;MAAE;QAC1B,MAAMT,CAAC,GAAGH,MAAM,CAACuB,mBAAmB;QACpC,MAAMd,MAEL,GAAG;UACFb,IAAI,EAAE,iBAAiB;UACvB4B,uBAAuB,EAAErB,CAAC,CAACsB,gCAAgC;UAC3DH,uBAAuB,EAAE,CAAC,CAAC;UAC3BV,uBAAuB,EAAE,CAAC;QAC5B,CAAC;QACD,OAAOH,MAAM;MACf;IAEA,KAAK,aAAa;MAChB,MAAM,IAAIZ,KAAK,CAAC,kDAAkD,CAAC;IAErE,KAAK,gBAAgB;MACnB,MAAM,IAAIA,KAAK,CAAC,qDAAqD,CAAC;IAExE;MACE,MAAM,IAAIA,KAAK,CACb,gCAAiCG,MAAM,CAAsBJ,IAAI,EACnE,CAAC;EACL;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ActionLogicRuleConverter.js","names":["buildObjectTypeLookup","ir","objectTypes","undefined","byId","Map","byHyphenated","key","value","Object","entries","apiName","objectType","set","replace","buildInterfaceTypeLookup","interfaceTypes","interfaceType","resolveApiName","id","lookup","get","getObjectReferenceType","action","paramKey","param","actionType","metadata","parameters","type","Error","objectReference","convertIrLogicRulesToActionLogicRules","rules","objectLookup","interfaceLookup","map","irRule","convertSingleRule","convertIrLogicRuleToActionLogicRule","r","addObjectRule","propertyArguments","k","v","propertyValues","result","objectTypeApiName","objectTypeId","structPropertyArguments","addOrModifyObjectRuleV2","objRef","objectToModify","modifyObjectRule","modifyPropertyArguments","deleteObjectRule","objectToDelete","addInterfaceRule","interfaceApiName","interfaceTypeApiName","sharedPropertyArguments","modifyInterfaceRule","interfaceObjectToModify","interfaceObjectToModifyParameter"],"sources":["ActionLogicRuleConverter.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 type {\n OntologyIrActionTypeBlockDataV2,\n OntologyIrLogicRule,\n OntologyIrOntologyBlockDataV2,\n} from \"@osdk/client.unstable\";\nimport type * as Ontologies from \"@osdk/foundry.ontologies\";\n\ninterface ApiNameLookup {\n byId: Map<string, string>;\n byHyphenated: Map<string, string>;\n}\n\nfunction buildObjectTypeLookup(\n ir: OntologyIrOntologyBlockDataV2 | undefined,\n): ApiNameLookup | undefined {\n if (!ir?.objectTypes) {\n return undefined;\n }\n const byId = new Map<string, string>();\n const byHyphenated = new Map<string, string>();\n for (const [key, value] of Object.entries(ir.objectTypes)) {\n const apiName = value.objectType.apiName;\n byId.set(key, apiName);\n byHyphenated.set(apiName.replace(/\\./g, \"-\"), apiName);\n }\n return { byId, byHyphenated };\n}\n\nfunction buildInterfaceTypeLookup(\n ir: OntologyIrOntologyBlockDataV2 | undefined,\n): ApiNameLookup | undefined {\n if (!ir?.interfaceTypes) {\n return undefined;\n }\n const byId = new Map<string, string>();\n const byHyphenated = new Map<string, string>();\n for (const [key, value] of Object.entries(ir.interfaceTypes)) {\n const apiName = value.interfaceType.apiName;\n byId.set(key, apiName);\n byHyphenated.set(apiName.replace(/\\./g, \"-\"), apiName);\n }\n return { byId, byHyphenated };\n}\n\nfunction resolveApiName(id: string, lookup: ApiNameLookup | undefined): string {\n if (!lookup) {\n return id;\n }\n return lookup.byId.get(id) ?? lookup.byHyphenated.get(id) ?? id;\n}\n\nfunction getObjectReferenceType(\n action: OntologyIrActionTypeBlockDataV2,\n paramKey: string,\n): { objectTypeId: string } {\n const param = action.actionType.metadata.parameters[paramKey];\n if (!param || param.type.type !== \"objectReference\") {\n throw new Error(\n `Parameter '${paramKey}' must be an objectReference type`,\n );\n }\n return param.type.objectReference;\n}\n\n/**\n * Build lookups once and convert all logic rules for an action.\n * Avoids rebuilding lookup Maps on every rule.\n */\nexport function convertIrLogicRulesToActionLogicRules(\n rules: OntologyIrLogicRule[],\n action: OntologyIrActionTypeBlockDataV2,\n ir?: OntologyIrOntologyBlockDataV2,\n): Ontologies.ActionLogicRule[] {\n const objectLookup = buildObjectTypeLookup(ir);\n const interfaceLookup = buildInterfaceTypeLookup(ir);\n\n return rules.map(irRule =>\n convertSingleRule(irRule, action, objectLookup, interfaceLookup)\n );\n}\n\n/**\n * Convert a single OntologyIrLogicRule to ActionLogicRule.\n * Kept as a public API for callers that only need a single rule conversion.\n */\nexport function convertIrLogicRuleToActionLogicRule(\n irRule: OntologyIrLogicRule,\n action: OntologyIrActionTypeBlockDataV2,\n ir?: OntologyIrOntologyBlockDataV2,\n): Ontologies.ActionLogicRule {\n const objectLookup = buildObjectTypeLookup(ir);\n const interfaceLookup = buildInterfaceTypeLookup(ir);\n return convertSingleRule(irRule, action, objectLookup, interfaceLookup);\n}\n\nfunction convertSingleRule(\n irRule: OntologyIrLogicRule,\n action: OntologyIrActionTypeBlockDataV2,\n objectLookup: ApiNameLookup | undefined,\n interfaceLookup: ApiNameLookup | undefined,\n): Ontologies.ActionLogicRule {\n switch (irRule.type) {\n case \"addObjectRule\": {\n const r = irRule.addObjectRule;\n const propertyArguments: Record<\n Ontologies.PropertyApiName,\n Ontologies.LogicRuleArgument\n > = {};\n for (const [k, v] of Object.entries(r.propertyValues)) {\n propertyArguments[k] = v as Ontologies.LogicRuleArgument;\n }\n const result: Ontologies.CreateObjectLogicRule & {\n type: \"createObject\";\n } = {\n type: \"createObject\",\n objectTypeApiName: resolveApiName(r.objectTypeId, objectLookup),\n propertyArguments,\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"addOrModifyObjectRuleV2\": {\n const r = irRule.addOrModifyObjectRuleV2;\n const objRef = getObjectReferenceType(action, r.objectToModify);\n // propertyArguments left empty: the downstream generator resolves\n // property mappings from the action parameter configuration rather\n // than from the logic rule itself for createOrModify rules.\n const result: Ontologies.CreateOrModifyObjectLogicRule & {\n type: \"createOrModifyObject\";\n } = {\n type: \"createOrModifyObject\",\n objectTypeApiName: resolveApiName(objRef.objectTypeId, objectLookup),\n propertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"modifyObjectRule\": {\n const r = irRule.modifyObjectRule;\n // Validate that the parameter is an objectReference (throws if not)\n getObjectReferenceType(action, r.objectToModify);\n const modifyPropertyArguments: Record<\n Ontologies.PropertyApiName,\n Ontologies.LogicRuleArgument\n > = {};\n for (const [k, v] of Object.entries(r.propertyValues)) {\n modifyPropertyArguments[k] = v as Ontologies.LogicRuleArgument;\n }\n const result: Ontologies.ModifyObjectLogicRule & {\n type: \"modifyObject\";\n } = {\n type: \"modifyObject\",\n objectToModify: r.objectToModify,\n propertyArguments: modifyPropertyArguments,\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"deleteObjectRule\": {\n const r = irRule.deleteObjectRule;\n const result: Ontologies.DeleteObjectLogicRule & {\n type: \"deleteObject\";\n } = {\n type: \"deleteObject\",\n objectToDelete: r.objectToDelete,\n };\n return result;\n }\n\n case \"addInterfaceRule\": {\n const r = irRule.addInterfaceRule;\n const interfaceApiName = resolveApiName(\n r.interfaceApiName,\n interfaceLookup,\n );\n const result: Ontologies.CreateInterfaceLogicRule & {\n type: \"createInterface\";\n } = {\n type: \"createInterface\",\n interfaceTypeApiName: interfaceApiName,\n objectType: interfaceApiName,\n sharedPropertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"modifyInterfaceRule\": {\n const r = irRule.modifyInterfaceRule;\n const result: Ontologies.ModifyInterfaceLogicRule & {\n type: \"modifyInterface\";\n } = {\n type: \"modifyInterface\",\n interfaceObjectToModify: r.interfaceObjectToModifyParameter,\n sharedPropertyArguments: {},\n structPropertyArguments: {},\n };\n return result;\n }\n\n case \"addLinkRule\":\n throw new Error(\"addLinkRule is not supported for ActionLogicRule\");\n\n case \"deleteLinkRule\":\n throw new Error(\"deleteLinkRule is not supported for ActionLogicRule\");\n\n default:\n throw new Error(\n `Unsupported logic rule type: ${(irRule as { type: string }).type}`,\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,SAASA,qBAAqBA,CAC5BC,EAA6C,EAClB;EAC3B,IAAI,CAACA,EAAE,EAAEC,WAAW,EAAE;IACpB,OAAOC,SAAS;EAClB;EACA,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACtC,MAAMC,YAAY,GAAG,IAAID,GAAG,CAAiB,CAAC;EAC9C,KAAK,MAAM,CAACE,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,EAAE,CAACC,WAAW,CAAC,EAAE;IACzD,MAAMS,OAAO,GAAGH,KAAK,CAACI,UAAU,CAACD,OAAO;IACxCP,IAAI,CAACS,GAAG,CAACN,GAAG,EAAEI,OAAO,CAAC;IACtBL,YAAY,CAACO,GAAG,CAACF,OAAO,CAACG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAEH,OAAO,CAAC;EACxD;EACA,OAAO;IAAEP,IAAI;IAAEE;EAAa,CAAC;AAC/B;AAEA,SAASS,wBAAwBA,CAC/Bd,EAA6C,EAClB;EAC3B,IAAI,CAACA,EAAE,EAAEe,cAAc,EAAE;IACvB,OAAOb,SAAS;EAClB;EACA,MAAMC,IAAI,GAAG,IAAIC,GAAG,CAAiB,CAAC;EACtC,MAAMC,YAAY,GAAG,IAAID,GAAG,CAAiB,CAAC;EAC9C,KAAK,MAAM,CAACE,GAAG,EAAEC,KAAK,CAAC,IAA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AmB;QACpC,MAAMf,MAEL,GAAG;UACFjB,IAAI,EAAE,iBAAiB;UACvBiC,uBAAuB,EAAEtB,CAAC,CAACuB,gCAAgC;UAC3DH,uBAAuB,EAAE,CAAC,CAAC;UAC3BX,uBAAuB,EAAE,CAAC;QAC5B,CAAC;QACD,OAAOH,MAAM;MACf;IAEA,KAAK,aAAa;MAChB,MAAM,IAAIhB,KAAK,CAAC,kDAAkD,CAAC;IAErE,KAAK,gBAAgB;MACnB,MAAM,IAAIA,KAAK,CAAC,qDAAqD,CAAC;IAExE;MACE,MAAM,IAAIA,KAAK,CACb,gCAAiCO,MAAM,CAAsBR,IAAI,EACnE,CAAC;EACL;AACF","ignoreList":[]}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { OntologyIrToFullMetadataConverter } from "@osdk/generator-converters.ontologyir";
|
|
18
|
-
import {
|
|
18
|
+
import { convertIrLogicRulesToActionLogicRules } from "./ActionLogicRuleConverter.js";
|
|
19
19
|
import { toUuid } from "./ridUtils.js";
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -78,39 +78,26 @@ export class PreviewOntologyIrConverter {
|
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* Convert IR action types to ActionTypeFullMetadata format.
|
|
81
|
-
*
|
|
81
|
+
* Reuses base converter for action type conversion, then process
|
|
82
|
+
* RIDs to use UUID-based format and adds fullLogicRules.
|
|
82
83
|
*/
|
|
83
84
|
static convertActionTypesWithFullLogicRules(actions, ir) {
|
|
85
|
+
const baseActionTypes = OntologyIrToFullMetadataConverter.getOsdkActionTypes(actions);
|
|
86
|
+
|
|
87
|
+
// Build a lookup from apiName to the original IR action for logic rules
|
|
88
|
+
const actionsByApiName = new Map(actions.map(a => [a.actionType.metadata.apiName, a]));
|
|
84
89
|
const result = {};
|
|
85
|
-
for (const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
operations: OntologyIrToFullMetadataConverter.getOsdkActionOperations(action),
|
|
94
|
-
status: this.convertActionTypeStatus(metadata.status)
|
|
95
|
-
};
|
|
96
|
-
result[actionType.apiName] = {
|
|
97
|
-
actionType,
|
|
98
|
-
fullLogicRules: action.actionType.actionTypeLogic.logic.rules.map(rule => convertIrLogicRuleToActionLogicRule(rule, action, ir))
|
|
90
|
+
for (const [apiName, baseActionType] of Object.entries(baseActionTypes)) {
|
|
91
|
+
const action = actionsByApiName.get(apiName);
|
|
92
|
+
result[apiName] = {
|
|
93
|
+
actionType: {
|
|
94
|
+
...baseActionType,
|
|
95
|
+
rid: `ri.ontology.main.action-type.${toUuid(apiName)}`
|
|
96
|
+
},
|
|
97
|
+
fullLogicRules: convertIrLogicRulesToActionLogicRules(action.actionType.actionTypeLogic.logic.rules, action, ir)
|
|
99
98
|
};
|
|
100
99
|
}
|
|
101
100
|
return result;
|
|
102
101
|
}
|
|
103
|
-
static convertActionTypeStatus(status) {
|
|
104
|
-
switch (status.type) {
|
|
105
|
-
case "active":
|
|
106
|
-
return "ACTIVE";
|
|
107
|
-
case "deprecated":
|
|
108
|
-
return "DEPRECATED";
|
|
109
|
-
case "experimental":
|
|
110
|
-
return "EXPERIMENTAL";
|
|
111
|
-
case "example":
|
|
112
|
-
throw new Error("Example status cannot be mapped to ActionTypeStatus");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
102
|
}
|
|
116
103
|
//# sourceMappingURL=PreviewOntologyIrConverter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewOntologyIrConverter.js","names":["OntologyIrToFullMetadataConverter","
|
|
1
|
+
{"version":3,"file":"PreviewOntologyIrConverter.js","names":["OntologyIrToFullMetadataConverter","convertIrLogicRulesToActionLogicRules","toUuid","PreviewOntologyIrConverter","getPreviewFullMetadataFromIr","ir","baseMetadata","getFullMetadataFromIr","actionTypes","convertActionTypesWithFullLogicRules","Object","values","objectTypes","convertObjectTypesWithUuidRids","ontology","apiName","rid","displayName","description","result","fullMetadata","entries","objectType","properties","propKey","prop","actions","baseActionTypes","getOsdkActionTypes","actionsByApiName","Map","map","a","actionType","metadata","baseActionType","action","get","fullLogicRules","actionTypeLogic","logic","rules"],"sources":["PreviewOntologyIrConverter.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 type {\n OntologyIrActionTypeBlockDataV2,\n OntologyIrOntologyBlockDataV2,\n} from \"@osdk/client.unstable\";\nimport type * as Ontologies from \"@osdk/foundry.ontologies\";\nimport { OntologyIrToFullMetadataConverter } from \"@osdk/generator-converters.ontologyir\";\nimport { convertIrLogicRulesToActionLogicRules } from \"./ActionLogicRuleConverter.js\";\nimport { toUuid } from \"./ridUtils.js\";\n\n/**\n * Extended return type that uses ActionTypeFullMetadata instead of ActionTypeV2.\n */\nexport interface PreviewOntologyFullMetadata\n extends Omit<Ontologies.OntologyFullMetadata, \"actionTypes\">\n{\n actionTypes: Record<string, Ontologies.ActionTypeFullMetadata>;\n}\n\n/**\n * Preview converter that extends the base OntologyIrToFullMetadataConverter\n * to return ActionTypeFullMetadata with fullLogicRules instead of ActionTypeV2.\n */\nexport class PreviewOntologyIrConverter {\n /**\n * Main entry point - converts IR to full metadata with enhanced action types.\n * Returns ActionTypeFullMetadata which includes fullLogicRules.\n */\n static getPreviewFullMetadataFromIr(\n ir: OntologyIrOntologyBlockDataV2,\n ): PreviewOntologyFullMetadata {\n const baseMetadata = OntologyIrToFullMetadataConverter\n .getFullMetadataFromIr(ir);\n\n const actionTypes = this.convertActionTypesWithFullLogicRules(\n Object.values(ir.actionTypes),\n ir,\n );\n\n // Post-process object types to use UUID-based RIDs\n const objectTypes = this.convertObjectTypesWithUuidRids(\n baseMetadata.objectTypes,\n );\n\n return {\n ...baseMetadata,\n objectTypes,\n actionTypes,\n ontology: {\n apiName: \"ontology\",\n rid: \"ri.ontology.main.ontology.0\",\n displayName: \"ontology\",\n description: \"local ontology\",\n },\n };\n }\n\n /**\n * Post-process object types to use UUID-based RIDs for properties.\n */\n private static convertObjectTypesWithUuidRids(\n objectTypes: Record<string, Ontologies.ObjectTypeFullMetadata>,\n ): Record<string, Ontologies.ObjectTypeFullMetadata> {\n const result: Record<string, Ontologies.ObjectTypeFullMetadata> = {};\n\n for (const [apiName, fullMetadata] of Object.entries(objectTypes)) {\n const objectType = fullMetadata.objectType;\n const properties: Record<string, Ontologies.PropertyV2> = {};\n\n for (const [propKey, prop] of Object.entries(objectType.properties)) {\n properties[propKey] = {\n ...prop,\n rid: `ri.ontology.main.property.${toUuid(apiName + \".\" + propKey)}`,\n };\n }\n\n result[apiName] = {\n ...fullMetadata,\n objectType: {\n ...objectType,\n rid: `ri.ontology.main.object-type.${toUuid(apiName)}`,\n properties,\n },\n };\n }\n\n return result;\n }\n\n /**\n * Convert IR action types to ActionTypeFullMetadata format.\n * Reuses base converter for action type conversion, then process\n * RIDs to use UUID-based format and adds fullLogicRules.\n */\n private static convertActionTypesWithFullLogicRules(\n actions: OntologyIrActionTypeBlockDataV2[],\n ir: OntologyIrOntologyBlockDataV2,\n ): Record<string, Ontologies.ActionTypeFullMetadata> {\n const baseActionTypes = OntologyIrToFullMetadataConverter\n .getOsdkActionTypes(actions);\n\n // Build a lookup from apiName to the original IR action for logic rules\n const actionsByApiName = new Map(\n actions.map(a => [a.actionType.metadata.apiName, a]),\n );\n\n const result: Record<string, Ontologies.ActionTypeFullMetadata> = {};\n for (const [apiName, baseActionType] of Object.entries(baseActionTypes)) {\n const action = actionsByApiName.get(apiName)!;\n result[apiName] = {\n actionType: {\n ...baseActionType,\n rid: `ri.ontology.main.action-type.${toUuid(apiName)}`,\n },\n fullLogicRules: convertIrLogicRulesToActionLogicRules(\n action.actionType.actionTypeLogic.logic.rules,\n action,\n ir,\n ),\n };\n }\n\n return result;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,iCAAiC,QAAQ,uCAAuC;AACzF,SAASC,qCAAqC,QAAQ,+BAA+B;AACrF,SAASC,MAAM,QAAQ,eAAe;;AAEtC;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA,OAAO,MAAMC,0BAA0B,CAAC;EACtC;AACF;AACA;AACA;EACE,OAAOC,4BAA4BA,CACjCC,EAAiC,EACJ;IAC7B,MAAMC,YAAY,GAAGN,iCAAiC,CACnDO,qBAAqB,CAACF,EAAE,CAAC;IAE5B,MAAMG,WAAW,GAAG,IAAI,CAACC,oCAAoC,CAC3DC,MAAM,CAACC,MAAM,CAACN,EAAE,CAACG,WAAW,CAAC,EAC7BH,EACF,CAAC;;IAED;IACA,MAAMO,WAAW,GAAG,IAAI,CAACC,8BAA8B,CACrDP,YAAY,CAACM,WACf,CAAC;IAED,OAAO;MACL,GAAGN,YAAY;MACfM,WAAW;MACXJ,WAAW;MACXM,QAAQ,EAAE;QACRC,OAAO,EAAE,UAAU;QACnBC,GAAG,EAAE,6BAA6B;QAClCC,WAAW,EAAE,UAAU;QACvBC,WAAW,EAAE;MACf;IACF,CAAC;EACH;;EAEA;AACF;AACA;EACE,OAAeL,8BAA8BA,CAC3CD,WAA8D,EACX;IACnD,MAAMO,MAAyD,GAAG,CAAC,CAAC;IAEpE,KAAK,MAAM,CAACJ,OAAO,EAAEK,YAAY,CAAC,IAAIV,MAAM,CAACW,OAAO,CAACT,WAAW,CAAC,EAAE;MACjE,MAAMU,UAAU,GAAGF,YAAY,CAACE,UAAU;MAC1C,MAAMC,UAA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,CAACM,eAAe,CAACC,KAAK,CAACC,KAAK,EAC7CL,MAAM,EACN/B,EACF;MACF,CAAC;IACH;IAEA,OAAOc,MAAM;EACf;AACF","ignoreList":[]}
|
|
@@ -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
|