@osdk/generator-converters.preview 0.1.0-beta.1 → 0.1.0-beta.2
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 +14 -0
- package/build/browser/ActionLogicRuleConverter.js +19 -1
- 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 +90 -33
- 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/browser/ridUtils.test.js +5 -4
- package/build/browser/ridUtils.test.js.map +1 -1
- package/build/cjs/index.cjs +21 -30
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +2 -2
- package/build/esm/ActionLogicRuleConverter.js +19 -1
- 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 +90 -33
- 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/esm/ridUtils.test.js +5 -4
- package/build/esm/ridUtils.test.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @osdk/generator-converters.preview
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a29ed88: Add functions support
|
|
8
|
+
- 35f2f1a: Add Media inputs/outputs for Queries
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [35f2f1a]
|
|
13
|
+
- @osdk/client.unstable@2.8.0-beta.14
|
|
14
|
+
- @osdk/generator@2.8.0-beta.14
|
|
15
|
+
- @osdk/generator-converters.ontologyir@2.8.0-beta.14
|
|
16
|
+
|
|
3
17
|
## 0.1.0-beta.1
|
|
4
18
|
|
|
5
19
|
### 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,6 +114,7 @@ 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);
|
|
101
119
|
const result = {
|
|
102
120
|
type: "modifyObject",
|
|
@@ -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,EAA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C;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","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 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,CAAC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AAoB,EAAED,gBAAgB;UACtC7C,UAAU,EAAE6C,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;UACFjB,IAAI,EAAE,iBAAiB;UACvBgC,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,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,EAC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CAAE;MAC7CI,MAAM,CAACJ,OAAO,CAAC,GAAG;QAChBkB,UAAU,EAAE;UACV,GAAGE,cAAc;UACjBnB,GAAG,EAAE,gCAAgCd,MAAM,CAACa,OAAO,CAAC;QACtD,CAAC;QACDuB,cAAc,EAAErC,qCAAqC,CACnDmC,MAAM,CAACH,UAAU,CAACM,eAAe,CAACC,KAAK,CAACC,KAAK,EAC7CL,MAAM,EACN/B,EACF;MACF,CAAC;IACH;IAEA,OAAOc,MAAM;EACf;AACF","ignoreList":[]}
|
|
@@ -15,51 +15,113 @@
|
|
|
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";
|
|
18
20
|
import * as fs from "node:fs/promises";
|
|
19
21
|
import * as path from "node:path";
|
|
22
|
+
import yargs from "yargs";
|
|
23
|
+
import { hideBin } from "yargs/helpers";
|
|
20
24
|
import { PreviewOntologyIrConverter } from "../PreviewOntologyIrConverter.js";
|
|
21
|
-
const USAGE = `Usage: generate-sdk <input-ontology-ir.json> <package-name> <package-version> <output-dir>
|
|
22
|
-
|
|
23
|
-
Arguments:
|
|
24
|
-
input-ontology-ir.json Path to the OntologyIR JSON file
|
|
25
|
-
package-name Name for the generated SDK package
|
|
26
|
-
package-version Version string for the generated SDK
|
|
27
|
-
output-dir Directory where the SDK will be generated`;
|
|
28
25
|
async function main() {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const argv = await yargs(hideBin(process.argv)).strict().help().version(false) // so that we can use --version argument for the package version
|
|
27
|
+
.usage("$0 --input <path> --package-name <name> --version <ver> --output-dir <dir>").options({
|
|
28
|
+
"input": {
|
|
29
|
+
describe: "Path to the OntologyIR JSON file",
|
|
30
|
+
type: "string",
|
|
31
|
+
demandOption: true,
|
|
32
|
+
coerce: path.resolve
|
|
33
|
+
},
|
|
34
|
+
"package-name": {
|
|
35
|
+
describe: "Name for the generated SDK package",
|
|
36
|
+
type: "string",
|
|
37
|
+
demandOption: true
|
|
38
|
+
},
|
|
39
|
+
"version": {
|
|
40
|
+
describe: "Version string for the generated SDK",
|
|
41
|
+
type: "string",
|
|
42
|
+
demandOption: true
|
|
43
|
+
},
|
|
44
|
+
"output-dir": {
|
|
45
|
+
describe: "Directory where the SDK will be generated",
|
|
46
|
+
type: "string",
|
|
47
|
+
demandOption: true,
|
|
48
|
+
coerce: path.resolve
|
|
49
|
+
},
|
|
50
|
+
"functions-dir": {
|
|
51
|
+
describe: "Path to TypeScript functions source directory (enables TS function discovery)",
|
|
52
|
+
type: "string",
|
|
53
|
+
coerce: path.resolve
|
|
54
|
+
},
|
|
55
|
+
"node-modules-path": {
|
|
56
|
+
describe: "Path to node_modules containing @foundry packages (for TS function discovery)",
|
|
57
|
+
type: "string",
|
|
58
|
+
coerce: path.resolve
|
|
59
|
+
},
|
|
60
|
+
"python-functions-dir": {
|
|
61
|
+
describe: "Path to Python functions source directory (enables Python function discovery)",
|
|
62
|
+
type: "string",
|
|
63
|
+
coerce: path.resolve
|
|
64
|
+
},
|
|
65
|
+
"python-root-project-dir": {
|
|
66
|
+
describe: "Root project directory for Python functions (defaults to parent of python-functions-dir)",
|
|
67
|
+
type: "string",
|
|
68
|
+
coerce: path.resolve
|
|
69
|
+
},
|
|
70
|
+
"python-binary": {
|
|
71
|
+
describe: "Path to Python binary (required when using --python-functions-dir)",
|
|
72
|
+
type: "string",
|
|
73
|
+
coerce: path.resolve
|
|
74
|
+
}
|
|
75
|
+
}).parse();
|
|
76
|
+
const inputFile = argv.input;
|
|
77
|
+
const packageName = argv.packageName;
|
|
78
|
+
const packageVersion = argv.version;
|
|
79
|
+
const outputDir = argv.outputDir;
|
|
38
80
|
|
|
39
81
|
// Validate input file exists
|
|
40
82
|
try {
|
|
41
83
|
await fs.access(inputFile);
|
|
42
84
|
} catch {
|
|
43
|
-
|
|
44
|
-
console.error(`Error: Input file does not exist: ${inputFile}`);
|
|
85
|
+
consola.error(`Input file does not exist: ${inputFile}`);
|
|
45
86
|
process.exit(1);
|
|
46
87
|
}
|
|
47
|
-
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.log(`Converting ${inputFile}...`);
|
|
88
|
+
consola.info(`Converting ${inputFile}...`);
|
|
50
89
|
const fileContent = await fs.readFile(inputFile, "utf-8");
|
|
51
90
|
let irJson;
|
|
52
91
|
try {
|
|
53
92
|
const parsed = JSON.parse(fileContent);
|
|
54
93
|
// Handle both wrapped (ontology.objectTypes) and unwrapped (objectTypes) formats
|
|
55
94
|
irJson = parsed.ontology ?? parsed;
|
|
56
|
-
} catch
|
|
57
|
-
|
|
58
|
-
|
|
95
|
+
} catch {
|
|
96
|
+
consola.error(`Failed to parse JSON from ${inputFile}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Basic structural validation before passing to converter
|
|
101
|
+
const ir = irJson;
|
|
102
|
+
if (!ir || typeof ir !== "object" || !("objectTypes" in ir) || !("actionTypes" in ir)) {
|
|
103
|
+
consola.error(`Invalid OntologyIR structure in ${inputFile}. Expected objectTypes and actionTypes fields.`);
|
|
59
104
|
process.exit(1);
|
|
60
105
|
}
|
|
61
106
|
const previewMetadata = PreviewOntologyIrConverter.getPreviewFullMetadataFromIr(irJson);
|
|
62
107
|
|
|
108
|
+
// Function discovery is optional - only run if at least one functions flag is provided
|
|
109
|
+
if (argv.functionsDir || argv.pythonFunctionsDir) {
|
|
110
|
+
if (argv.pythonFunctionsDir && !argv.pythonBinary) {
|
|
111
|
+
consola.error("--python-binary is required when using --python-functions-dir");
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
const effectivePythonRootDir = argv.pythonRootProjectDir ?? (argv.pythonFunctionsDir ? path.dirname(argv.pythonFunctionsDir) : undefined);
|
|
115
|
+
const queryTypes = await OntologyIrToFullMetadataConverter.getOsdkQueryTypes(argv.pythonBinary, argv.functionsDir, argv.nodeModulesPath, argv.pythonFunctionsDir, effectivePythonRootDir);
|
|
116
|
+
const functionNames = Object.keys(queryTypes);
|
|
117
|
+
if (functionNames.length > 0) {
|
|
118
|
+
previewMetadata.queryTypes = queryTypes;
|
|
119
|
+
consola.info(`Discovered ${functionNames.length} function(s): ${functionNames.join(", ")}`);
|
|
120
|
+
} else {
|
|
121
|
+
consola.info("No functions discovered.");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
63
125
|
// Convert ActionTypeFullMetadata to ActionTypeV2 for generator compatibility
|
|
64
126
|
const metadata = {
|
|
65
127
|
...previewMetadata,
|
|
@@ -69,8 +131,7 @@ async function main() {
|
|
|
69
131
|
await fs.mkdir(fullOutputDir, {
|
|
70
132
|
recursive: true
|
|
71
133
|
});
|
|
72
|
-
|
|
73
|
-
console.log(`Generating SDK to ${fullOutputDir}...`);
|
|
134
|
+
consola.info(`Generating SDK to ${fullOutputDir}...`);
|
|
74
135
|
await generateClientSdkVersionTwoPointZero(metadata, `osdk-generator/${packageVersion} (from-ir)`, {
|
|
75
136
|
async writeFile(filePath, contents) {
|
|
76
137
|
const fullPath = path.isAbsolute(filePath) ? filePath : path.join(fullOutputDir, filePath);
|
|
@@ -91,15 +152,11 @@ async function main() {
|
|
|
91
152
|
}, fullOutputDir, "module", new Map(), new Map(), new Map(), false, []);
|
|
92
153
|
const metadataPath = path.join(fullOutputDir, "ontology-metadata.json");
|
|
93
154
|
await fs.writeFile(metadataPath, JSON.stringify(previewMetadata, null, 2), "utf-8");
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
console.log(`Wrote ${metadataPath}`);
|
|
97
|
-
// eslint-disable-next-line no-console
|
|
98
|
-
console.log("Done!");
|
|
155
|
+
consola.info(`Wrote ${metadataPath}`);
|
|
156
|
+
consola.success("Done!");
|
|
99
157
|
}
|
|
100
158
|
main().catch(err => {
|
|
101
|
-
|
|
102
|
-
console.error("Error:", err instanceof Error ? err.message : err);
|
|
159
|
+
consola.error(err instanceof Error ? err.message : err);
|
|
103
160
|
process.exit(1);
|
|
104
161
|
});
|
|
105
162
|
//# 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;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oCAAoC,QAAQ,iBAAiB;AACtE,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AACtC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,SAASC,0BAA0B,QAAQ,kCAAkC;AAE7E,MAAMC,KAAK,GACT;AACF;AACA;AACA;AACA;AACA;AACA,oEAAoE;AAEpE,eAAeC,IAAIA,CAAA,EAAkB;EACnC,MAAMC,IAAI,GAAGC,OAAO,CAACC,IAAI,CAACC,KAAK,CAAC,CAAC,CAAC;EAElC,IAAIH,IAAI,CAACI,MAAM,GAAG,CAAC,EAAE;IACnB;IACAC,OAAO,CAACC,KAAK,CAACR,KAAK,CAAC;IACpBG,OAAO,CAACM,IAAI,CAAC,CAAC,CAAC;EACjB;EAEA,MAAM,CAACC,QAAQ,EAAEC,WAAW,EAAEC,cAAc,EAAEC,SAAS,CAAC,GAAGX,IAAI;EAC/D,MAAMY,SAAS,GAAGhB,IAAI,CAACiB,OAAO,CAACL,QAAQ,CAAC;EACxC,MAAMM,SAAS,GAAGlB,IAAI,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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","fs","path","yargs","hideBin","PreviewOntologyIrConverter","main","argv","process","strict","help","version","usage","options","describe","type","demandOption","coerce","resolve","parse","inputFile","input","packageName","packageVersion","outputDir","access","error","exit","info","fileContent","readFile","irJson","parsed","JSON","ontology","ir","previewMetadata","getPreviewFullMetadataFromIr","functionsDir","pythonFunctionsDir","pythonBinary","effectivePythonRootDir","pythonRootProjectDir","dirname","undefined","queryTypes","getOsdkQueryTypes","nodeModulesPath","functionNames","Object","keys","length","join","metadata","actionTypes","fromEntries","entries","map","key","fullMeta","actionType","fullOutputDir","mkdir","recursive","writeFile","filePath","contents","fullPath","isAbsolute","dirPath","readdir","Map","metadataPath","stringify","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 * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { PreviewOntologyIrConverter } from \"../PreviewOntologyIrConverter.js\";\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 // 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 );\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 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 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,OAAO,KAAKC,EAAE,MAAM,kBAAkB;AACtC,OAAO,KAAKC,IAAI,MAAM,WAAW;AACjC,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,OAAO,QAAQ,eAAe;AACvC,S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AAC,EAQCR,aAAa,EACb,QAAQ,EACR,IAAIU,GAAG,CAAC,CAAC,EACT,IAAIA,GAAG,CAAC,CAAC,EACT,IAAIA,GAAG,CAAC,CAAC,EACT,KAAK,EACL,EACF,CAAC;EAED,MAAMC,YAAY,GAAGtE,IAAI,CAACkD,IAAI,CAACS,aAAa,EAAE,wBAAwB,CAAC;EACvE,MAAM5D,EAAE,CAAC+D,SAAS,CAChBQ,YAAY,EACZvC,IAAI,CAACwC,SAAS,CAACrC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,EACxC,OACF,CAAC;EAEDpC,OAAO,CAAC4B,IAAI,CAAC,SAAS4C,YAAY,EAAE,CAAC;EACrCxE,OAAO,CAAC0E,OAAO,CAAC,OAAO,CAAC;AAC1B;AAEApE,IAAI,CAAC,CAAC,CAACqE,KAAK,CAAEC,GAAY,IAAK;EAC7B5E,OAAO,CAAC0B,KAAK,CAACkD,GAAG,YAAYC,KAAK,GAAGD,GAAG,CAACE,OAAO,GAAGF,GAAG,CAAC;EACvDpE,OAAO,CAACmB,IAAI,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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":[]}
|
|
@@ -18,10 +18,11 @@ import { describe, expect, it } from "vitest";
|
|
|
18
18
|
import { toUuid } from "./ridUtils.js";
|
|
19
19
|
describe("ridUtils", () => {
|
|
20
20
|
describe("toUuid", () => {
|
|
21
|
-
it("returns a valid UUID format", () => {
|
|
21
|
+
it("returns a valid UUID format with correct version and variant bits", () => {
|
|
22
22
|
const result = toUuid("test-string");
|
|
23
|
-
// UUID format: xxxxxxxx-xxxx-
|
|
24
|
-
|
|
23
|
+
// UUID format: xxxxxxxx-xxxx-Vxxx-Nxxx-xxxxxxxxxxxx // cspell:disable-line
|
|
24
|
+
// V = version (5), N = variant (8, 9, a, or b for RFC 4122)
|
|
25
|
+
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
25
26
|
});
|
|
26
27
|
it("is deterministic - same input produces same output", () => {
|
|
27
28
|
const input = "my-deterministic-input";
|
|
@@ -36,7 +37,7 @@ describe("ridUtils", () => {
|
|
|
36
37
|
});
|
|
37
38
|
it("handles empty string", () => {
|
|
38
39
|
const result = toUuid("");
|
|
39
|
-
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{
|
|
40
|
+
expect(result).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
40
41
|
});
|
|
41
42
|
});
|
|
42
43
|
});
|
|
@@ -1 +1 @@
|
|
|
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-
|
|
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 with correct version and variant bits\", () => {\n const result = toUuid(\"test-string\");\n // UUID format: xxxxxxxx-xxxx-Vxxx-Nxxx-xxxxxxxxxxxx // cspell:disable-line\n // V = version (5), N = variant (8, 9, a, or b for RFC 4122)\n expect(result).toMatch(\n /^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[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}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,\n );\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,E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