@osdk/generator 2.4.2 → 2.5.0-beta.10
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 +85 -38
- package/build/browser/util/test/TodoWireOntology.js +53 -4
- package/build/browser/util/test/TodoWireOntology.js.map +1 -1
- package/build/browser/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.js +2 -2
- package/build/browser/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.js.map +1 -1
- package/build/browser/v2.0/generateClientSdkVersionTwoPointZero.test.js +35 -5
- package/build/browser/v2.0/generateClientSdkVersionTwoPointZero.test.js.map +1 -1
- package/build/browser/v2.0/generateMetadata.js +4 -1
- package/build/browser/v2.0/generateMetadata.js.map +1 -1
- package/build/browser/v2.0/wireObjectTypeV2ToSdkObjectConstV2.js +51 -9
- package/build/browser/v2.0/wireObjectTypeV2ToSdkObjectConstV2.js.map +1 -1
- package/build/cjs/index.cjs +55 -11
- package/build/cjs/index.cjs.map +1 -1
- package/build/esm/util/test/TodoWireOntology.js +53 -4
- package/build/esm/util/test/TodoWireOntology.js.map +1 -1
- package/build/esm/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.js +2 -2
- package/build/esm/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.js.map +1 -1
- package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.test.js +35 -5
- package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.test.js.map +1 -1
- package/build/esm/v2.0/generateMetadata.js +4 -1
- package/build/esm/v2.0/generateMetadata.js.map +1 -1
- package/build/esm/v2.0/wireObjectTypeV2ToSdkObjectConstV2.js +51 -9
- package/build/esm/v2.0/wireObjectTypeV2ToSdkObjectConstV2.js.map +1 -1
- package/build/types/v2.0/wireObjectTypeV2ToSdkObjectConstV2.d.ts +3 -2
- package/build/types/v2.0/wireObjectTypeV2ToSdkObjectConstV2.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -18,7 +18,7 @@ import path from "path";
|
|
|
18
18
|
import { formatTs } from "../util/test/formatTs.js";
|
|
19
19
|
|
|
20
20
|
// BEGIN: THIS IS GENERATED CODE. DO NOT EDIT.
|
|
21
|
-
const ExpectedOsdkVersion = "2.
|
|
21
|
+
const ExpectedOsdkVersion = "2.5.0";
|
|
22
22
|
// END: THIS IS GENERATED CODE. DO NOT EDIT.
|
|
23
23
|
|
|
24
24
|
export async function generateOntologyMetadataFile({
|
|
@@ -33,6 +33,9 @@ export async function generateOntologyMetadataFile({
|
|
|
33
33
|
${ontologyApiNamespace == null ? `
|
|
34
34
|
export const $ontologyRid = "${ontology.ontology.rid}";
|
|
35
35
|
` : ""}
|
|
36
|
+
${ontology.raw.branch != null ? `
|
|
37
|
+
export const $branch = "${ontology.raw.branch.rid}";
|
|
38
|
+
` : ""}
|
|
36
39
|
`));
|
|
37
40
|
}
|
|
38
41
|
//# sourceMappingURL=generateMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateMetadata.js","names":["path","formatTs","ExpectedOsdkVersion","generateOntologyMetadataFile","fs","outDir","ontology","ontologyApiNamespace","userAgent","writeFile","join","rid"],"sources":["generateMetadata.ts"],"sourcesContent":["/*\n * Copyright 2023 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 path from \"path\";\nimport type { GenerateContext } from \"../GenerateContext/GenerateContext.js\";\nimport { formatTs } from \"../util/test/formatTs.js\";\n\n// BEGIN: THIS IS GENERATED CODE. DO NOT EDIT.\nconst ExpectedOsdkVersion = \"2.
|
|
1
|
+
{"version":3,"file":"generateMetadata.js","names":["path","formatTs","ExpectedOsdkVersion","generateOntologyMetadataFile","fs","outDir","ontology","ontologyApiNamespace","userAgent","writeFile","join","rid","raw","branch"],"sources":["generateMetadata.ts"],"sourcesContent":["/*\n * Copyright 2023 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 path from \"path\";\nimport type { GenerateContext } from \"../GenerateContext/GenerateContext.js\";\nimport { formatTs } from \"../util/test/formatTs.js\";\n\n// BEGIN: THIS IS GENERATED CODE. DO NOT EDIT.\nconst ExpectedOsdkVersion = \"2.5.0\";\n// END: THIS IS GENERATED CODE. DO NOT EDIT.\n\nexport async function generateOntologyMetadataFile(\n { fs, outDir, ontology, ontologyApiNamespace }: GenerateContext,\n userAgent: string,\n): Promise<void> {\n await fs.writeFile(\n path.join(outDir, \"OntologyMetadata.ts\"),\n await formatTs(\n `\n export type $ExpectedClientVersion = \"${ExpectedOsdkVersion}\";\n export const $osdkMetadata = { extraUserAgent: \"${userAgent}\" };\n ${\n ontologyApiNamespace == null\n ? `\n export const $ontologyRid = \"${ontology.ontology.rid}\";\n `\n : \"\"\n }\n ${\n ontology.raw.branch != null\n ? `\n export const $branch = \"${ontology.raw.branch.rid}\";\n `\n : \"\"\n }\n `,\n ),\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AAEvB,SAASC,QAAQ,QAAQ,0BAA0B;;AAEnD;AACA,MAAMC,mBAAmB,GAAG,OAAO;AACnC;;AAEA,OAAO,eAAeC,4BAA4BA,CAChD;EAAEC,EAAE;EAAEC,MAAM;EAAEC,QAAQ;EAAEC;AAAsC,CAAC,EAC/DC,SAAiB,EACF;EACf,MAAMJ,EAAE,CAACK,SAAS,CAChBT,IAAI,CAACU,IAAI,CAACL,MAAM,EAAE,qBAAqB,CAAC,EACxC,MAAMJ,QAAQ,CACZ;AACN,8CAA8CC,mBAAmB;AACjE,wDAAwDM,SAAS;AACjE,QACQD,oBAAoB,IAAI,IAAI,GACxB;AACZ,uCAAuCD,QAAQ,CAACA,QAAQ,CAACK,GAAG;AAC5D,SAAS,GACG,EAAE;AACd,SAEQL,QAAQ,CAACM,GAAG,CAACC,MAAM,IAAI,IAAI,GACvB;AACZ,kCAAkCP,QAAQ,CAACM,GAAG,CAACC,MAAM,CAACF,GAAG;AACzD,SAAS,GACG,EAAE;AACd,OAEI,CACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
import { wireObjectTypeFullMetadataToSdkObjectMetadata } from "@osdk/generator-converters";
|
|
18
18
|
import consola from "consola";
|
|
19
|
+
import { EnhancedInterfaceType } from "../GenerateContext/EnhancedInterfaceType.js";
|
|
19
20
|
import { EnhancedObjectType } from "../GenerateContext/EnhancedObjectType.js";
|
|
20
21
|
import { ForeignType } from "../GenerateContext/ForeignType.js";
|
|
21
22
|
import { getObjectImports } from "../shared/getObjectImports.js";
|
|
22
23
|
import { propertyJsdoc } from "../shared/propertyJsdoc.js";
|
|
23
24
|
import { stringify } from "../util/stringify.js";
|
|
24
|
-
|
|
25
25
|
/** @internal */
|
|
26
26
|
export function wireObjectTypeV2ToSdkObjectConstV2(wireObject, {
|
|
27
27
|
ontology,
|
|
@@ -73,8 +73,8 @@ export function wireObjectTypeV2ToSdkObjectConstV2(wireObject, {
|
|
|
73
73
|
|
|
74
74
|
${createLinks(ontology, object, "Links")}
|
|
75
75
|
|
|
76
|
-
${createProps(object, "Props", false)}
|
|
77
|
-
${createProps(object, "StrictProps", true)}
|
|
76
|
+
${createProps(object, "Props", false, ontology.raw.valueTypes)}
|
|
77
|
+
${createProps(object, "StrictProps", true, ontology.raw.valueTypes)}
|
|
78
78
|
|
|
79
79
|
${createObjectSet(object, identifiers)}
|
|
80
80
|
|
|
@@ -145,18 +145,19 @@ function maybeStripNamespace(type, q) {
|
|
|
145
145
|
return q;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
export function createProps(type, identifier, strict) {
|
|
148
|
+
export function createProps(type, identifier, strict, valueTypeMetadata) {
|
|
149
149
|
if (identifier === "StrictProps") {
|
|
150
150
|
return `export type StrictProps = Props`;
|
|
151
151
|
}
|
|
152
152
|
const definition = type.getCleanedUpDefinition(true);
|
|
153
|
-
const propertyMetadata = type instanceof EnhancedObjectType ? type.raw.objectType.properties : undefined;
|
|
153
|
+
const propertyMetadata = type instanceof EnhancedObjectType ? type.raw.objectType.properties : type instanceof EnhancedInterfaceType ? type.raw.properties : undefined;
|
|
154
154
|
return `export interface ${identifier} {
|
|
155
155
|
${stringify(definition.properties, {
|
|
156
156
|
"*": (propertyDefinition, _, apiName) => {
|
|
157
|
-
|
|
157
|
+
const metadata = propertyMetadata ? propertyMetadata[apiName] : undefined;
|
|
158
|
+
return [`${propertyJsdoc(propertyDefinition, metadata, {
|
|
158
159
|
apiName
|
|
159
|
-
})}readonly "${maybeStripNamespace(type, apiName)}"`, (typeof propertyDefinition.type === "object" ? remapStructType(propertyDefinition.type) :
|
|
160
|
+
})}readonly "${maybeStripNamespace(type, apiName)}"`, (typeof propertyDefinition.type === "object" ? remapStructType(propertyDefinition.type) : getPropTypeOrValueTypeEnum(propertyDefinition, valueTypeMetadata)) + `${propertyDefinition.multiplicity ? "[]" : ""}${propertyDefinition.nullable || !strict && !(definition.type === "object" && definition.primaryKeyApiName === apiName) ? `| undefined` : ""}`];
|
|
160
161
|
}
|
|
161
162
|
})}
|
|
162
163
|
}`;
|
|
@@ -169,7 +170,7 @@ export function createDefinition(object, ontology, identifier, {
|
|
|
169
170
|
osdkObjectLinksIdentifier
|
|
170
171
|
}) {
|
|
171
172
|
const definition = object.getCleanedUpDefinition(true);
|
|
172
|
-
const propertyMetadata = object instanceof EnhancedObjectType ? object.raw.objectType.properties : undefined;
|
|
173
|
+
const propertyMetadata = object instanceof EnhancedObjectType ? object.raw.objectType.properties : object instanceof EnhancedInterfaceType ? object.raw.properties : undefined;
|
|
173
174
|
return `
|
|
174
175
|
export interface ${identifier} extends ${object instanceof EnhancedObjectType ? `$ObjectTypeDefinition` : `$InterfaceDefinition`} {
|
|
175
176
|
osdkMetadata: typeof $osdkMetadata;
|
|
@@ -190,7 +191,7 @@ export function createDefinition(object, ontology, identifier, {
|
|
|
190
191
|
}`,
|
|
191
192
|
properties: () => `{
|
|
192
193
|
${stringify(definition.properties, {
|
|
193
|
-
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, propertyMetadata
|
|
194
|
+
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, propertyMetadata[apiName], {
|
|
194
195
|
apiName
|
|
195
196
|
})}"${maybeStripNamespace(object, apiName)}"`, `$PropertyDef<${JSON.stringify(propertyDefinition.type)}, "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`]
|
|
196
197
|
})}
|
|
@@ -225,4 +226,45 @@ function remapStructType(structType) {
|
|
|
225
226
|
output += "}";
|
|
226
227
|
return output;
|
|
227
228
|
}
|
|
229
|
+
function getPropTypeOrValueTypeEnum(propertyDefinition, valueTypeMetadata) {
|
|
230
|
+
const defaultPropString = `$PropType[${JSON.stringify(propertyDefinition.type)}]`;
|
|
231
|
+
if (!(propertyDefinition.type === "string" || propertyDefinition.type === "boolean") || !propertyDefinition.valueTypeApiName || valueTypeMetadata[propertyDefinition.valueTypeApiName] == null) {
|
|
232
|
+
return defaultPropString;
|
|
233
|
+
}
|
|
234
|
+
const valueType = valueTypeMetadata[propertyDefinition.valueTypeApiName];
|
|
235
|
+
if (valueType.constraints.length !== 1) {
|
|
236
|
+
throw new Error(`Expected exactly one constraint for value type ${propertyDefinition.valueTypeApiName} but got ${valueType.constraints.length}`);
|
|
237
|
+
}
|
|
238
|
+
let shouldWrapWithParentheses = false;
|
|
239
|
+
let constraint = valueType.constraints[0];
|
|
240
|
+
if (constraint.type === "array" && constraint.valueConstraint) {
|
|
241
|
+
constraint = constraint.valueConstraint;
|
|
242
|
+
shouldWrapWithParentheses = true;
|
|
243
|
+
}
|
|
244
|
+
const maybeEnumString = maybeGetEnumString(propertyDefinition, constraint);
|
|
245
|
+
return maybeEnumString ? shouldWrapWithParentheses ? `(${maybeEnumString})` : maybeEnumString : defaultPropString;
|
|
246
|
+
}
|
|
247
|
+
function maybeGetEnumString(propertyDefinition, constraint) {
|
|
248
|
+
if (constraint.type !== "enum" || constraint.options.length === 0) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
if (propertyDefinition.type === "string") {
|
|
252
|
+
return constraint.options.map(x => `"${x}"`).join(" | ");
|
|
253
|
+
}
|
|
254
|
+
if (propertyDefinition.type === "boolean") {
|
|
255
|
+
return constraint.options.map(value => {
|
|
256
|
+
if (value === true) {
|
|
257
|
+
return true;
|
|
258
|
+
} else if (value === false) {
|
|
259
|
+
return false;
|
|
260
|
+
} else if (value == null) {
|
|
261
|
+
// Always infer nullability from the property definition
|
|
262
|
+
return undefined;
|
|
263
|
+
} else {
|
|
264
|
+
consola.warn(`Unexpected boolean value in enum: ${value}. Ignoring.`);
|
|
265
|
+
}
|
|
266
|
+
}).filter(value => value != null).join(" | ");
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
228
270
|
//# sourceMappingURL=wireObjectTypeV2ToSdkObjectConstV2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wireObjectTypeV2ToSdkObjectConstV2.js","names":["wireObjectTypeFullMetadataToSdkObjectMetadata","consola","EnhancedObjectType","ForeignType","getObjectImports","propertyJsdoc","stringify","wireObjectTypeV2ToSdkObjectConstV2","wireObject","ontology","forInternalUse","currentFilePath","object","requireObjectType","objectType","apiName","Error","uniqueLinkTargetTypes","Set","linkTypes","map","a","objectTypeApiName","definition","raw","objectDefIdentifier","getDefinitionIdentifier","objectSetIdentifier","shortApiName","propertyKeysIdentifier","osdkObjectPropsIdentifier","osdkObjectStrictPropsIdentifier","osdkObjectLinksIdentifier","osdkObjectIdentifier","identifiers","imports","createPropertyKeys","createLinks","createProps","createObjectSet","createOsdkObject","createDefinition","fullApiName","identifier","getCleanedUpDefinition","maybeStripNamespace","type","q","apiNamespace","startsWith","slice","length","strict","propertyMetadata","properties","undefined","*","propertyDefinition","_","remapStructType","JSON","multiplicity","nullable","primaryKeyApiName","links","linkDefinition","targetType","requireInterfaceType","targetTypeApiName","getImportedDefinitionIdentifier","Object","keys","key","linkTarget","join","structType","output","entries","value"],"sources":["wireObjectTypeV2ToSdkObjectConstV2.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { ObjectTypeFullMetadata } from \"@osdk/foundry.ontologies\";\nimport { wireObjectTypeFullMetadataToSdkObjectMetadata } from \"@osdk/generator-converters\";\nimport consola from \"consola\";\nimport type { EnhancedInterfaceType } from \"../GenerateContext/EnhancedInterfaceType.js\";\nimport { EnhancedObjectType } from \"../GenerateContext/EnhancedObjectType.js\";\nimport type { EnhancedOntologyDefinition } from \"../GenerateContext/EnhancedOntologyDefinition.js\";\nimport { ForeignType } from \"../GenerateContext/ForeignType.js\";\nimport type { GenerateContext } from \"../GenerateContext/GenerateContext.js\";\nimport { getObjectImports } from \"../shared/getObjectImports.js\";\nimport { propertyJsdoc } from \"../shared/propertyJsdoc.js\";\nimport { stringify } from \"../util/stringify.js\";\n\n/** @internal */\nexport function wireObjectTypeV2ToSdkObjectConstV2(\n wireObject: ObjectTypeFullMetadata,\n { ontology, forInternalUse }: Pick<\n GenerateContext,\n \"ontology\" | \"forInternalUse\"\n >,\n currentFilePath: string,\n) {\n const object = ontology.requireObjectType(\n wireObject.objectType.apiName,\n true,\n );\n if (object instanceof ForeignType) {\n throw new Error(\"Should not be generating types for an external type\");\n }\n const uniqueLinkTargetTypes = new Set(\n wireObject.linkTypes.map(a =>\n ontology.requireObjectType(a.objectTypeApiName, false)\n ),\n );\n\n const definition = wireObjectTypeFullMetadataToSdkObjectMetadata(\n object.raw,\n true,\n consola,\n );\n\n const objectDefIdentifier = object.getDefinitionIdentifier(true);\n\n const objectSetIdentifier = `${object.shortApiName}.ObjectSet`;\n const propertyKeysIdentifier = `${object.shortApiName}.PropertyKeys`;\n // const osdkObjectPropsIdentifier = `OsdkObjectProps$${objectDefIdentifier}`;\n const osdkObjectPropsIdentifier = `${object.shortApiName}.Props`;\n const osdkObjectStrictPropsIdentifier = `${object.shortApiName}.StrictProps`;\n const osdkObjectLinksIdentifier = `${object.shortApiName}.Links`;\n const osdkObjectIdentifier = `${object.shortApiName}.OsdkObject`;\n\n const identifiers: Identifiers = {\n objectDefIdentifier: object.shortApiName,\n osdkObjectLinksIdentifier,\n osdkObjectPropsIdentifier,\n osdkObjectStrictPropsIdentifier,\n objectSetIdentifier,\n osdkObjectIdentifier,\n propertyKeysIdentifier,\n };\n\n function getV2Types(\n object: EnhancedObjectType,\n forInternalUse: boolean = false,\n ) {\n return `import type {\n PropertyKeys as $PropertyKeys, \n ObjectTypeDefinition as $ObjectTypeDefinition,\n ObjectMetadata as $ObjectMetadata,\n } from \"${forInternalUse ? \"@osdk/api\" : \"@osdk/client\"}\";\n import type {\n ObjectSet as $ObjectSet, \n Osdk as $Osdk,\n OsdkObject as $OsdkObject,\n PropertyValueWireToClient as $PropType,\n SingleLinkAccessor as $SingleLinkAccessor,\n } from \"${forInternalUse ? \"@osdk/api\" : \"@osdk/client\"}\";\n\n\n export namespace ${object.shortApiName} {\n\n ${createPropertyKeys(object)}\n\n\n ${createLinks(ontology, object, \"Links\")}\n\n ${createProps(object, \"Props\", false)}\n ${createProps(object, \"StrictProps\", true)}\n\n ${createObjectSet(object, identifiers)}\n \n ${createOsdkObject(object, \"OsdkInstance\", identifiers)}\n } \n\n\n\n ${createDefinition(object, ontology, object.shortApiName, identifiers)}\n `;\n }\n\n const imports = getObjectImports(\n uniqueLinkTargetTypes,\n definition.apiName,\n currentFilePath,\n true,\n );\n\n return `${imports}${getV2Types(object, forInternalUse)}\n\n export const ${object.shortApiName}: ${objectDefIdentifier}\n = {\n type: \"${object instanceof EnhancedObjectType ? \"object\" : \"interface\"}\",\n apiName: \"${object.fullApiName}\",\n osdkMetadata: $osdkMetadata, \n };`;\n}\n\nexport interface Identifiers extends\n Record<\n | \"osdkObjectIdentifier\"\n | \"propertyKeysIdentifier\"\n | \"osdkObjectPropsIdentifier\"\n | \"objectDefIdentifier\"\n | \"osdkObjectLinksIdentifier\"\n | \"osdkObjectStrictPropsIdentifier\"\n | \"objectSetIdentifier\",\n string\n >\n{}\n\nexport function createOsdkObject(\n object: EnhancedObjectType | EnhancedInterfaceType,\n identifier: string,\n {\n osdkObjectPropsIdentifier,\n objectDefIdentifier,\n osdkObjectStrictPropsIdentifier,\n osdkObjectLinksIdentifier,\n }: Identifiers,\n) {\n const definition = object.getCleanedUpDefinition(true);\n return `\n export type ${identifier}<\n OPTIONS extends never | \"$rid\" = never,\n K extends keyof ${osdkObjectPropsIdentifier}= keyof ${osdkObjectPropsIdentifier},\n > \n = $Osdk.Instance<\n ${objectDefIdentifier}, \n OPTIONS,\n K\n >;\n \n\n /** @deprecated use ${identifier} */\n export type OsdkObject<\n OPTIONS extends never | \"$rid\" = never,\n K extends keyof ${osdkObjectPropsIdentifier}= keyof ${osdkObjectPropsIdentifier},\n > = ${identifier}<OPTIONS, K>;\n ;\n `;\n}\n\nexport function createObjectSet(\n object: EnhancedObjectType | EnhancedInterfaceType,\n {\n objectDefIdentifier,\n objectSetIdentifier,\n propertyKeysIdentifier,\n osdkObjectIdentifier,\n }: Identifiers,\n) {\n return `\nexport interface ObjectSet extends \n$ObjectSet<${objectDefIdentifier},\n\n${objectSetIdentifier}\n>\n{\n\n}\n`;\n}\n\nfunction maybeStripNamespace(\n type: EnhancedInterfaceType | EnhancedObjectType,\n q: string,\n) {\n if (\n type.apiNamespace && q.startsWith(`${type.apiNamespace}.`)\n ) {\n return q.slice(type.apiNamespace.length + 1);\n } else {\n return q;\n }\n}\n\nexport function createProps(\n type: EnhancedInterfaceType | EnhancedObjectType,\n identifier: string,\n strict: boolean,\n): string {\n if (identifier === \"StrictProps\") {\n return `export type StrictProps = Props`;\n }\n const definition = type.getCleanedUpDefinition(true);\n const propertyMetadata = type instanceof EnhancedObjectType\n ? type.raw.objectType.properties\n : undefined;\n return `export interface ${identifier} {\n${\n stringify(definition.properties, {\n \"*\": (propertyDefinition, _, apiName) => {\n return [\n `${\n propertyJsdoc(propertyDefinition, propertyMetadata?.[apiName], {\n apiName,\n })\n }readonly \"${maybeStripNamespace(type, apiName)}\"`,\n (typeof propertyDefinition.type === \"object\"\n ? remapStructType(propertyDefinition.type)\n : `$PropType[${JSON.stringify(propertyDefinition.type)}]`)\n + `${propertyDefinition.multiplicity ? \"[]\" : \"\"}${\n propertyDefinition.nullable\n || (!strict\n && !(definition.type === \"object\"\n && definition.primaryKeyApiName === apiName))\n ? `| undefined`\n : \"\"\n }`,\n ] as [string, string];\n },\n })\n }\n }`;\n}\n\nexport function createDefinition(\n object: EnhancedObjectType | EnhancedInterfaceType,\n ontology: EnhancedOntologyDefinition,\n identifier: string,\n {\n objectDefIdentifier,\n objectSetIdentifier,\n osdkObjectPropsIdentifier,\n osdkObjectStrictPropsIdentifier,\n osdkObjectLinksIdentifier,\n }: Identifiers,\n) {\n const definition = object.getCleanedUpDefinition(true);\n const propertyMetadata = object instanceof EnhancedObjectType\n ? object.raw.objectType.properties\n : undefined;\n return `\n export interface ${identifier} extends ${\n object instanceof EnhancedObjectType\n ? `$ObjectTypeDefinition`\n : `$InterfaceDefinition`\n } {\n osdkMetadata: typeof $osdkMetadata;\n type: \"${object instanceof EnhancedObjectType ? \"object\" : \"interface\"}\";\n apiName: \"${object.fullApiName}\";\n __DefinitionMetadata?: {\n objectSet: ${objectSetIdentifier};\n props: ${osdkObjectPropsIdentifier};\n linksType: ${osdkObjectLinksIdentifier};\n strictProps: ${osdkObjectStrictPropsIdentifier};\n ${\n stringify(definition, {\n links: (_value) =>\n `{\n ${\n definition.type === \"interface\"\n ? stringify(definition.links, {\n \"*\": (linkDefinition) =>\n `$InterfaceMetadata.Link<${\n linkDefinition.targetType === \"interface\"\n ? ontology.requireInterfaceType(\n linkDefinition.targetTypeApiName,\n )\n .getImportedDefinitionIdentifier(true)\n : ontology.requireObjectType(\n linkDefinition.targetTypeApiName,\n ).getImportedDefinitionIdentifier(true)\n }, ${linkDefinition.multiplicity}>`,\n })\n : stringify(definition.links, {\n \"*\": (linkDefinition) =>\n `$ObjectMetadata.Link<${\n ontology.requireObjectType(linkDefinition.targetType)\n .getImportedDefinitionIdentifier(true)\n }, ${linkDefinition.multiplicity}>`,\n })\n }\n }`,\n properties: (_value) => (`{\n ${\n stringify(definition.properties, {\n \"*\": (propertyDefinition, _, apiName) =>\n [\n `${\n propertyJsdoc(propertyDefinition, propertyMetadata?.[apiName], {\n apiName,\n })\n }\"${maybeStripNamespace(object, apiName)}\"`,\n `$PropertyDef<${JSON.stringify(propertyDefinition.type)}, \"${\n propertyDefinition.nullable ? \"nullable\" : \"non-nullable\"\n }\", \"${propertyDefinition.multiplicity ? \"array\" : \"single\"}\">`,\n ] as [string, string],\n })\n }\n }`),\n })\n }\n } \n}\n `;\n}\n\nexport function createLinks(\n ontology: EnhancedOntologyDefinition,\n object: EnhancedObjectType | EnhancedInterfaceType,\n identifier: string,\n) {\n const definition = object.getCleanedUpDefinition(true);\n\n return `\n ${\n Object.keys(definition.links).length === 0\n ? `export type ${identifier} = {};`\n : `\n export interface ${identifier} {\n${\n stringify(definition.links, {\n \"*\": (definition, _, key) => {\n const linkTarget = ontology.requireObjectType(\n definition.targetType,\n )\n .getImportedDefinitionIdentifier(true);\n\n return [\n `readonly ${key}`,\n `${\n definition.multiplicity\n ? `${linkTarget}.ObjectSet`\n : `$SingleLinkAccessor<${linkTarget}>`\n }\n `,\n ];\n },\n })\n }\n }\n `\n }`;\n}\n\nexport function createPropertyKeys(\n type: EnhancedObjectType | EnhancedInterfaceType,\n) {\n const properties = Object.keys(type.getCleanedUpDefinition(true).properties);\n return `export type PropertyKeys = ${\n properties.length === 0\n ? \"never\"\n : properties.map(\n (a) => maybeStripNamespace(type, a),\n ).map(a => `\"${a}\"`).join(\"|\")\n };`;\n}\n\nfunction remapStructType(structType: Record<string, any>): string {\n let output = `{`;\n Object.entries(structType).map(([key, value]) =>\n output += `${key}:$PropType[${JSON.stringify(value)}]|undefined;`\n );\n output += \"}\";\n return output;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,6CAA6C,QAAQ,4BAA4B;AAC1F,OAAOC,OAAO,MAAM,SAAS;AAE7B,SAASC,kBAAkB,QAAQ,0CAA0C;AAE7E,SAASC,WAAW,QAAQ,mCAAmC;AAE/D,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;;AAEhD;AACA,OAAO,SAASC,kCAAkCA,CAChDC,UAAkC,EAClC;EAAEC,QAAQ;EAAEC;AAGZ,C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AAU,CAAC,CAACvD,GAAG,CAAC,CAAC,CAACoD,GAAG,EAAEM,KAAK,CAAC,KAC1CF,MAAM,IAAI,GAAGJ,GAAG,cAAcZ,IAAI,CAACtD,SAAS,CAACwE,KAAK,CAAC,cACrD,CAAC;EACDF,MAAM,IAAI,GAAG;EACb,OAAOA,MAAM;AACf","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"wireObjectTypeV2ToSdkObjectConstV2.js","names":["wireObjectTypeFullMetadataToSdkObjectMetadata","consola","EnhancedInterfaceType","EnhancedObjectType","ForeignType","getObjectImports","propertyJsdoc","stringify","wireObjectTypeV2ToSdkObjectConstV2","wireObject","ontology","forInternalUse","currentFilePath","object","requireObjectType","objectType","apiName","Error","uniqueLinkTargetTypes","Set","linkTypes","map","a","objectTypeApiName","definition","raw","objectDefIdentifier","getDefinitionIdentifier","objectSetIdentifier","shortApiName","propertyKeysIdentifier","osdkObjectPropsIdentifier","osdkObjectStrictPropsIdentifier","osdkObjectLinksIdentifier","osdkObjectIdentifier","identifiers","imports","createPropertyKeys","createLinks","createProps","valueTypes","createObjectSet","createOsdkObject","createDefinition","fullApiName","identifier","getCleanedUpDefinition","maybeStripNamespace","type","q","apiNamespace","startsWith","slice","length","strict","valueTypeMetadata","propertyMetadata","properties","undefined","*","propertyDefinition","_","metadata","remapStructType","getPropTypeOrValueTypeEnum","multiplicity","nullable","primaryKeyApiName","links","linkDefinition","targetType","requireInterfaceType","targetTypeApiName","getImportedDefinitionIdentifier","JSON","Object","keys","key","linkTarget","join","structType","output","entries","value","defaultPropString","valueTypeApiName","valueType","constraints","shouldWrapWithParentheses","constraint","valueConstraint","maybeEnumString","maybeGetEnumString","options","x","warn","filter"],"sources":["wireObjectTypeV2ToSdkObjectConstV2.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { ObjectMetadata } from \"@osdk/api\";\nimport type {\n ObjectTypeFullMetadata,\n OntologyValueType,\n PropertyApiName,\n SharedPropertyTypeApiName,\n ValueTypeApiName,\n ValueTypeConstraint,\n} from \"@osdk/foundry.ontologies\";\nimport { wireObjectTypeFullMetadataToSdkObjectMetadata } from \"@osdk/generator-converters\";\nimport consola from \"consola\";\nimport { EnhancedInterfaceType } from \"../GenerateContext/EnhancedInterfaceType.js\";\nimport { EnhancedObjectType } from \"../GenerateContext/EnhancedObjectType.js\";\nimport type { EnhancedOntologyDefinition } from \"../GenerateContext/EnhancedOntologyDefinition.js\";\nimport { ForeignType } from \"../GenerateContext/ForeignType.js\";\nimport type { GenerateContext } from \"../GenerateContext/GenerateContext.js\";\nimport { getObjectImports } from \"../shared/getObjectImports.js\";\nimport { propertyJsdoc } from \"../shared/propertyJsdoc.js\";\nimport { stringify } from \"../util/stringify.js\";\n\ntype PropertyApiNameUnion = PropertyApiName | SharedPropertyTypeApiName;\n\n/** @internal */\nexport function wireObjectTypeV2ToSdkObjectConstV2(\n wireObject: ObjectTypeFullMetadata,\n { ontology, forInternalUse }: Pick<\n GenerateContext,\n \"ontology\" | \"forInternalUse\"\n >,\n currentFilePath: string,\n) {\n const object = ontology.requireObjectType(\n wireObject.objectType.apiName,\n true,\n );\n if (object instanceof ForeignType) {\n throw new Error(\"Should not be generating types for an external type\");\n }\n const uniqueLinkTargetTypes = new Set(\n wireObject.linkTypes.map(a =>\n ontology.requireObjectType(a.objectTypeApiName, false)\n ),\n );\n\n const definition = wireObjectTypeFullMetadataToSdkObjectMetadata(\n object.raw,\n true,\n consola,\n );\n\n const objectDefIdentifier = object.getDefinitionIdentifier(true);\n\n const objectSetIdentifier = `${object.shortApiName}.ObjectSet`;\n const propertyKeysIdentifier = `${object.shortApiName}.PropertyKeys`;\n // const osdkObjectPropsIdentifier = `OsdkObjectProps$${objectDefIdentifier}`;\n const osdkObjectPropsIdentifier = `${object.shortApiName}.Props`;\n const osdkObjectStrictPropsIdentifier = `${object.shortApiName}.StrictProps`;\n const osdkObjectLinksIdentifier = `${object.shortApiName}.Links`;\n const osdkObjectIdentifier = `${object.shortApiName}.OsdkObject`;\n\n const identifiers: Identifiers = {\n objectDefIdentifier: object.shortApiName,\n osdkObjectLinksIdentifier,\n osdkObjectPropsIdentifier,\n osdkObjectStrictPropsIdentifier,\n objectSetIdentifier,\n osdkObjectIdentifier,\n propertyKeysIdentifier,\n };\n\n function getV2Types(\n object: EnhancedObjectType,\n forInternalUse: boolean = false,\n ) {\n return `import type {\n PropertyKeys as $PropertyKeys, \n ObjectTypeDefinition as $ObjectTypeDefinition,\n ObjectMetadata as $ObjectMetadata,\n } from \"${forInternalUse ? \"@osdk/api\" : \"@osdk/client\"}\";\n import type {\n ObjectSet as $ObjectSet, \n Osdk as $Osdk,\n OsdkObject as $OsdkObject,\n PropertyValueWireToClient as $PropType,\n SingleLinkAccessor as $SingleLinkAccessor,\n } from \"${forInternalUse ? \"@osdk/api\" : \"@osdk/client\"}\";\n\n\n export namespace ${object.shortApiName} {\n\n ${createPropertyKeys(object)}\n\n\n ${createLinks(ontology, object, \"Links\")}\n\n ${createProps(object, \"Props\", false, ontology.raw.valueTypes)}\n ${createProps(object, \"StrictProps\", true, ontology.raw.valueTypes)}\n\n ${createObjectSet(object, identifiers)}\n \n ${createOsdkObject(object, \"OsdkInstance\", identifiers)}\n } \n\n\n\n ${createDefinition(object, ontology, object.shortApiName, identifiers)}\n `;\n }\n\n const imports = getObjectImports(\n uniqueLinkTargetTypes,\n definition.apiName,\n currentFilePath,\n true,\n );\n\n return `${imports}${getV2Types(object, forInternalUse)}\n\n export const ${object.shortApiName}: ${objectDefIdentifier}\n = {\n type: \"${object instanceof EnhancedObjectType ? \"object\" : \"interface\"}\",\n apiName: \"${object.fullApiName}\",\n osdkMetadata: $osdkMetadata, \n };`;\n}\n\nexport interface Identifiers extends\n Record<\n | \"osdkObjectIdentifier\"\n | \"propertyKeysIdentifier\"\n | \"osdkObjectPropsIdentifier\"\n | \"objectDefIdentifier\"\n | \"osdkObjectLinksIdentifier\"\n | \"osdkObjectStrictPropsIdentifier\"\n | \"objectSetIdentifier\",\n string\n >\n{}\n\nexport function createOsdkObject(\n object: EnhancedObjectType | EnhancedInterfaceType,\n identifier: string,\n {\n osdkObjectPropsIdentifier,\n objectDefIdentifier,\n osdkObjectStrictPropsIdentifier,\n osdkObjectLinksIdentifier,\n }: Identifiers,\n) {\n const definition = object.getCleanedUpDefinition(true);\n return `\n export type ${identifier}<\n OPTIONS extends never | \"$rid\" = never,\n K extends keyof ${osdkObjectPropsIdentifier}= keyof ${osdkObjectPropsIdentifier},\n > \n = $Osdk.Instance<\n ${objectDefIdentifier}, \n OPTIONS,\n K\n >;\n \n\n /** @deprecated use ${identifier} */\n export type OsdkObject<\n OPTIONS extends never | \"$rid\" = never,\n K extends keyof ${osdkObjectPropsIdentifier}= keyof ${osdkObjectPropsIdentifier},\n > = ${identifier}<OPTIONS, K>;\n ;\n `;\n}\n\nexport function createObjectSet(\n object: EnhancedObjectType | EnhancedInterfaceType,\n {\n objectDefIdentifier,\n objectSetIdentifier,\n propertyKeysIdentifier,\n osdkObjectIdentifier,\n }: Identifiers,\n) {\n return `\nexport interface ObjectSet extends \n$ObjectSet<${objectDefIdentifier},\n\n${objectSetIdentifier}\n>\n{\n\n}\n`;\n}\n\nfunction maybeStripNamespace(\n type: EnhancedInterfaceType | EnhancedObjectType,\n q: string,\n) {\n if (\n type.apiNamespace && q.startsWith(`${type.apiNamespace}.`)\n ) {\n return q.slice(type.apiNamespace.length + 1);\n } else {\n return q;\n }\n}\n\nexport function createProps(\n type: EnhancedInterfaceType | EnhancedObjectType,\n identifier: string,\n strict: boolean,\n valueTypeMetadata: Record<ValueTypeApiName, OntologyValueType>,\n): string {\n if (identifier === \"StrictProps\") {\n return `export type StrictProps = Props`;\n }\n const definition = type.getCleanedUpDefinition(true);\n const propertyMetadata = type instanceof EnhancedObjectType\n ? type.raw.objectType.properties\n : type instanceof EnhancedInterfaceType\n ? type.raw.properties\n : undefined;\n return `export interface ${identifier} {\n${\n stringify(definition.properties, {\n \"*\": (propertyDefinition, _, apiName) => {\n const metadata = propertyMetadata\n ? (propertyMetadata as Record<PropertyApiNameUnion, any>)[apiName]\n : undefined;\n return [\n `${\n propertyJsdoc(propertyDefinition, metadata, {\n apiName,\n })\n }readonly \"${maybeStripNamespace(type, apiName)}\"`,\n (typeof propertyDefinition.type === \"object\"\n ? remapStructType(propertyDefinition.type)\n : getPropTypeOrValueTypeEnum(\n propertyDefinition,\n valueTypeMetadata,\n ))\n + `${propertyDefinition.multiplicity ? \"[]\" : \"\"}${\n propertyDefinition.nullable\n || (!strict\n && !(definition.type === \"object\"\n && definition.primaryKeyApiName === apiName))\n ? `| undefined`\n : \"\"\n }`,\n ] as [string, string];\n },\n })\n }\n }`;\n}\n\nexport function createDefinition(\n object: EnhancedObjectType | EnhancedInterfaceType,\n ontology: EnhancedOntologyDefinition,\n identifier: string,\n {\n objectDefIdentifier,\n objectSetIdentifier,\n osdkObjectPropsIdentifier,\n osdkObjectStrictPropsIdentifier,\n osdkObjectLinksIdentifier,\n }: Identifiers,\n) {\n const definition = object.getCleanedUpDefinition(true);\n const propertyMetadata = object instanceof EnhancedObjectType\n ? object.raw.objectType.properties\n : object instanceof EnhancedInterfaceType\n ? object.raw.properties\n : undefined;\n return `\n export interface ${identifier} extends ${\n object instanceof EnhancedObjectType\n ? `$ObjectTypeDefinition`\n : `$InterfaceDefinition`\n } {\n osdkMetadata: typeof $osdkMetadata;\n type: \"${object instanceof EnhancedObjectType ? \"object\" : \"interface\"}\";\n apiName: \"${object.fullApiName}\";\n __DefinitionMetadata?: {\n objectSet: ${objectSetIdentifier};\n props: ${osdkObjectPropsIdentifier};\n linksType: ${osdkObjectLinksIdentifier};\n strictProps: ${osdkObjectStrictPropsIdentifier};\n ${\n stringify(definition, {\n links: (_value) =>\n `{\n ${\n definition.type === \"interface\"\n ? stringify(definition.links, {\n \"*\": (linkDefinition) =>\n `$InterfaceMetadata.Link<${\n linkDefinition.targetType === \"interface\"\n ? ontology.requireInterfaceType(\n linkDefinition.targetTypeApiName,\n )\n .getImportedDefinitionIdentifier(true)\n : ontology.requireObjectType(\n linkDefinition.targetTypeApiName,\n ).getImportedDefinitionIdentifier(true)\n }, ${linkDefinition.multiplicity}>`,\n })\n : stringify(definition.links, {\n \"*\": (linkDefinition) =>\n `$ObjectMetadata.Link<${\n ontology.requireObjectType(linkDefinition.targetType)\n .getImportedDefinitionIdentifier(true)\n }, ${linkDefinition.multiplicity}>`,\n })\n }\n }`,\n properties: (_value) => (`{\n ${\n stringify(definition.properties, {\n \"*\": (propertyDefinition, _, apiName) =>\n [\n `${\n propertyJsdoc(\n propertyDefinition,\n (propertyMetadata as Record<PropertyApiNameUnion, any>)[\n apiName\n ],\n {\n apiName,\n },\n )\n }\"${maybeStripNamespace(object, apiName)}\"`,\n `$PropertyDef<${JSON.stringify(propertyDefinition.type)}, \"${\n propertyDefinition.nullable ? \"nullable\" : \"non-nullable\"\n }\", \"${propertyDefinition.multiplicity ? \"array\" : \"single\"}\">`,\n ] as [string, string],\n })\n }\n }`),\n })\n }\n } \n}\n `;\n}\n\nexport function createLinks(\n ontology: EnhancedOntologyDefinition,\n object: EnhancedObjectType | EnhancedInterfaceType,\n identifier: string,\n) {\n const definition = object.getCleanedUpDefinition(true);\n\n return `\n ${\n Object.keys(definition.links).length === 0\n ? `export type ${identifier} = {};`\n : `\n export interface ${identifier} {\n${\n stringify(definition.links, {\n \"*\": (definition, _, key) => {\n const linkTarget = ontology.requireObjectType(\n definition.targetType,\n )\n .getImportedDefinitionIdentifier(true);\n\n return [\n `readonly ${key}`,\n `${\n definition.multiplicity\n ? `${linkTarget}.ObjectSet`\n : `$SingleLinkAccessor<${linkTarget}>`\n }\n `,\n ];\n },\n })\n }\n }\n `\n }`;\n}\n\nexport function createPropertyKeys(\n type: EnhancedObjectType | EnhancedInterfaceType,\n) {\n const properties = Object.keys(type.getCleanedUpDefinition(true).properties);\n return `export type PropertyKeys = ${\n properties.length === 0\n ? \"never\"\n : properties.map(\n (a) => maybeStripNamespace(type, a),\n ).map(a => `\"${a}\"`).join(\"|\")\n };`;\n}\n\nfunction remapStructType(structType: Record<string, any>): string {\n let output = `{`;\n Object.entries(structType).map(([key, value]) =>\n output += `${key}:$PropType[${JSON.stringify(value)}]|undefined;`\n );\n output += \"}\";\n return output;\n}\n\nfunction getPropTypeOrValueTypeEnum(\n propertyDefinition: ObjectMetadata.Property,\n valueTypeMetadata: Record<ValueTypeApiName, OntologyValueType>,\n): string {\n const defaultPropString = `$PropType[${\n JSON.stringify(propertyDefinition.type)\n }]`;\n if (\n !(propertyDefinition.type === \"string\"\n || propertyDefinition.type === \"boolean\")\n || !propertyDefinition.valueTypeApiName\n || valueTypeMetadata[propertyDefinition.valueTypeApiName] == null\n ) {\n return defaultPropString;\n }\n const valueType = valueTypeMetadata[propertyDefinition.valueTypeApiName];\n if (valueType.constraints.length !== 1) {\n throw new Error(\n `Expected exactly one constraint for value type ${propertyDefinition.valueTypeApiName} but got ${valueType.constraints.length}`,\n );\n }\n\n let shouldWrapWithParentheses = false;\n let constraint = valueType.constraints[0];\n if (constraint.type === \"array\" && constraint.valueConstraint) {\n constraint = constraint.valueConstraint;\n shouldWrapWithParentheses = true;\n }\n\n const maybeEnumString = maybeGetEnumString(\n propertyDefinition,\n constraint,\n );\n\n return maybeEnumString\n ? (\n shouldWrapWithParentheses ? `(${maybeEnumString})` : maybeEnumString\n )\n : defaultPropString;\n}\n\nfunction maybeGetEnumString(\n propertyDefinition: ObjectMetadata.Property,\n constraint: ValueTypeConstraint,\n) {\n if (constraint.type !== \"enum\" || constraint.options.length === 0) {\n return undefined;\n }\n if (propertyDefinition.type === \"string\") {\n return constraint.options.map(x => `\"${x}\"`).join(\n \" | \",\n );\n }\n if (propertyDefinition.type === \"boolean\") {\n return constraint.options.map(value => {\n if (value === true) {\n return true;\n } else if (value === false) {\n return false;\n } else if (value == null) {\n // Always infer nullability from the property definition\n return undefined;\n } else {\n consola.warn(`Unexpected boolean value in enum: ${value}. Ignoring.`);\n }\n }).filter(value => value != null).join(\n \" | \",\n );\n }\n return undefined;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SAASA,6CAA6C,QAAQ,4BAA4B;AAC1F,OAAOC,OAAO,MAAM,SAAS;AAC7B,SAASC,qBAAqB,QAAQ,6CAA6C;AACnF,SAASC,kBAAkB,QAAQ,0CAA0C;AAE7E,SAASC,WAAW,QAAQ,mCAAmC;AAE/D,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAIhD;AACA,OAAO,SAASC,kCAAkCA,CAChDC,UAAkC,EAClC;EAAEC,QAAQ;EAAEC;AAGZ,CAAC,EACDC,eAAuB,EACvB;EACA,MAAMC,MAAM,GAAGH,QAAQ,CAACI,iBAAiB,CACvCL,UAAU,CAACM,UAAU,CAACC,OAAO,EAC7B,IACF,CAAC;EACD,IAAIH,MAAM,YAAYT,WAAW,EAAE;IACjC,MAAM,IAAIa,KAAK,CAAC,qDAAqD,CAAC;EACxE;EACA,MAAMC,qBAAqB,GAAG,IAAIC,GAAG,CACnCV,UAAU,CAACW,SAAS,CAACC,GAAG,CAACC,CAAC,IACxBZ,QAAQ,CAACI,iBAAiB,CAACQ,CAAC,CAACC,iBAAiB,EAAE,KAAK,CACvD,CACF,CAAC;EAED,MAAMC,UAAU,GAAGxB,6CAA6C,CAC9Da,MAAM,CAACY,GAAG,EACV,IAAI,EACJxB,OACF,CAAC;EAED,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ACjE,OAAOK,SAAS;EAClB;EACA,IAAIE,kBAAkB,CAACZ,IAAI,KAAK,QAAQ,EAAE;IACxC,OAAOyC,UAAU,CAACI,OAAO,CAACxE,GAAG,CAACyE,CAAC,IAAI,IAAIA,CAAC,GAAG,CAAC,CAACf,IAAI,CAC/C,KACF,CAAC;EACH;EACA,IAAInB,kBAAkB,CAACZ,IAAI,KAAK,SAAS,EAAE;IACzC,OAAOyC,UAAU,CAACI,OAAO,CAACxE,GAAG,CAAC8D,KAAK,IAAI;MACrC,IAAIA,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,IAAI;MACb,CAAC,MAAM,IAAIA,KAAK,KAAK,KAAK,EAAE;QAC1B,OAAO,KAAK;MACd,CAAC,MAAM,IAAIA,KAAK,IAAI,IAAI,EAAE;QACxB;QACA,OAAOzB,SAAS;MAClB,CAAC,MAAM;QACLzD,OAAO,CAAC8F,IAAI,CAAC,qCAAqCZ,KAAK,aAAa,CAAC;MACvE;IACF,CAAC,CAAC,CAACa,MAAM,CAACb,KAAK,IAAIA,KAAK,IAAI,IAAI,CAAC,CAACJ,IAAI,CACpC,KACF,CAAC;EACH;EACA,OAAOrB,SAAS;AAClB","ignoreList":[]}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -287,7 +287,7 @@ function formatTs(contents) {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
// src/v2.0/generateMetadata.ts
|
|
290
|
-
var ExpectedOsdkVersion = "2.
|
|
290
|
+
var ExpectedOsdkVersion = "2.5.0";
|
|
291
291
|
async function generateOntologyMetadataFile({
|
|
292
292
|
fs: fs2,
|
|
293
293
|
outDir,
|
|
@@ -300,6 +300,9 @@ async function generateOntologyMetadataFile({
|
|
|
300
300
|
${ontologyApiNamespace == null ? `
|
|
301
301
|
export const $ontologyRid = "${ontology.ontology.rid}";
|
|
302
302
|
` : ""}
|
|
303
|
+
${ontology.raw.branch != null ? `
|
|
304
|
+
export const $branch = "${ontology.raw.branch.rid}";
|
|
305
|
+
` : ""}
|
|
303
306
|
`));
|
|
304
307
|
}
|
|
305
308
|
|
|
@@ -703,8 +706,8 @@ function wireObjectTypeV2ToSdkObjectConstV2(wireObject, {
|
|
|
703
706
|
|
|
704
707
|
${createLinks(ontology, object2, "Links")}
|
|
705
708
|
|
|
706
|
-
${createProps(object2, "Props", false)}
|
|
707
|
-
${createProps(object2, "StrictProps", true)}
|
|
709
|
+
${createProps(object2, "Props", false, ontology.raw.valueTypes)}
|
|
710
|
+
${createProps(object2, "StrictProps", true, ontology.raw.valueTypes)}
|
|
708
711
|
|
|
709
712
|
${createObjectSet(object2, identifiers)}
|
|
710
713
|
|
|
@@ -777,18 +780,19 @@ function maybeStripNamespace(type, q) {
|
|
|
777
780
|
return q;
|
|
778
781
|
}
|
|
779
782
|
}
|
|
780
|
-
function createProps(type, identifier, strict) {
|
|
783
|
+
function createProps(type, identifier, strict, valueTypeMetadata) {
|
|
781
784
|
if (identifier === "StrictProps") {
|
|
782
785
|
return `export type StrictProps = Props`;
|
|
783
786
|
}
|
|
784
787
|
const definition = type.getCleanedUpDefinition(true);
|
|
785
|
-
const propertyMetadata = type instanceof EnhancedObjectType ? type.raw.objectType.properties : void 0;
|
|
788
|
+
const propertyMetadata = type instanceof EnhancedObjectType ? type.raw.objectType.properties : type instanceof EnhancedInterfaceType ? type.raw.properties : void 0;
|
|
786
789
|
return `export interface ${identifier} {
|
|
787
790
|
${stringify(definition.properties, {
|
|
788
791
|
"*": (propertyDefinition, _, apiName) => {
|
|
789
|
-
|
|
792
|
+
const metadata = propertyMetadata ? propertyMetadata[apiName] : void 0;
|
|
793
|
+
return [`${propertyJsdoc(propertyDefinition, metadata, {
|
|
790
794
|
apiName
|
|
791
|
-
})}readonly "${maybeStripNamespace(type, apiName)}"`, (typeof propertyDefinition.type === "object" ? remapStructType(propertyDefinition.type) :
|
|
795
|
+
})}readonly "${maybeStripNamespace(type, apiName)}"`, (typeof propertyDefinition.type === "object" ? remapStructType(propertyDefinition.type) : getPropTypeOrValueTypeEnum(propertyDefinition, valueTypeMetadata)) + `${propertyDefinition.multiplicity ? "[]" : ""}${propertyDefinition.nullable || !strict && !(definition.type === "object" && definition.primaryKeyApiName === apiName) ? `| undefined` : ""}`];
|
|
792
796
|
}
|
|
793
797
|
})}
|
|
794
798
|
}`;
|
|
@@ -801,7 +805,7 @@ function createDefinition(object, ontology, identifier, {
|
|
|
801
805
|
osdkObjectLinksIdentifier
|
|
802
806
|
}) {
|
|
803
807
|
const definition = object.getCleanedUpDefinition(true);
|
|
804
|
-
const propertyMetadata = object instanceof EnhancedObjectType ? object.raw.objectType.properties : void 0;
|
|
808
|
+
const propertyMetadata = object instanceof EnhancedObjectType ? object.raw.objectType.properties : object instanceof EnhancedInterfaceType ? object.raw.properties : void 0;
|
|
805
809
|
return `
|
|
806
810
|
export interface ${identifier} extends ${object instanceof EnhancedObjectType ? `$ObjectTypeDefinition` : `$InterfaceDefinition`} {
|
|
807
811
|
osdkMetadata: typeof $osdkMetadata;
|
|
@@ -822,7 +826,7 @@ function createDefinition(object, ontology, identifier, {
|
|
|
822
826
|
}`,
|
|
823
827
|
properties: (_value) => `{
|
|
824
828
|
${stringify(definition.properties, {
|
|
825
|
-
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, propertyMetadata
|
|
829
|
+
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, propertyMetadata[apiName], {
|
|
826
830
|
apiName
|
|
827
831
|
})}"${maybeStripNamespace(object, apiName)}"`, `$PropertyDef<${JSON.stringify(propertyDefinition.type)}, "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`]
|
|
828
832
|
})}
|
|
@@ -857,6 +861,46 @@ function remapStructType(structType) {
|
|
|
857
861
|
output += "}";
|
|
858
862
|
return output;
|
|
859
863
|
}
|
|
864
|
+
function getPropTypeOrValueTypeEnum(propertyDefinition, valueTypeMetadata) {
|
|
865
|
+
const defaultPropString = `$PropType[${JSON.stringify(propertyDefinition.type)}]`;
|
|
866
|
+
if (!(propertyDefinition.type === "string" || propertyDefinition.type === "boolean") || !propertyDefinition.valueTypeApiName || valueTypeMetadata[propertyDefinition.valueTypeApiName] == null) {
|
|
867
|
+
return defaultPropString;
|
|
868
|
+
}
|
|
869
|
+
const valueType = valueTypeMetadata[propertyDefinition.valueTypeApiName];
|
|
870
|
+
if (valueType.constraints.length !== 1) {
|
|
871
|
+
throw new Error(`Expected exactly one constraint for value type ${propertyDefinition.valueTypeApiName} but got ${valueType.constraints.length}`);
|
|
872
|
+
}
|
|
873
|
+
let shouldWrapWithParentheses = false;
|
|
874
|
+
let constraint = valueType.constraints[0];
|
|
875
|
+
if (constraint.type === "array" && constraint.valueConstraint) {
|
|
876
|
+
constraint = constraint.valueConstraint;
|
|
877
|
+
shouldWrapWithParentheses = true;
|
|
878
|
+
}
|
|
879
|
+
const maybeEnumString = maybeGetEnumString(propertyDefinition, constraint);
|
|
880
|
+
return maybeEnumString ? shouldWrapWithParentheses ? `(${maybeEnumString})` : maybeEnumString : defaultPropString;
|
|
881
|
+
}
|
|
882
|
+
function maybeGetEnumString(propertyDefinition, constraint) {
|
|
883
|
+
if (constraint.type !== "enum" || constraint.options.length === 0) {
|
|
884
|
+
return void 0;
|
|
885
|
+
}
|
|
886
|
+
if (propertyDefinition.type === "string") {
|
|
887
|
+
return constraint.options.map((x) => `"${x}"`).join(" | ");
|
|
888
|
+
}
|
|
889
|
+
if (propertyDefinition.type === "boolean") {
|
|
890
|
+
return constraint.options.map((value) => {
|
|
891
|
+
if (value === true) {
|
|
892
|
+
return true;
|
|
893
|
+
} else if (value === false) {
|
|
894
|
+
return false;
|
|
895
|
+
} else if (value == null) {
|
|
896
|
+
return void 0;
|
|
897
|
+
} else {
|
|
898
|
+
consola__default.default.warn(`Unexpected boolean value in enum: ${value}. Ignoring.`);
|
|
899
|
+
}
|
|
900
|
+
}).filter((value) => value != null).join(" | ");
|
|
901
|
+
}
|
|
902
|
+
return void 0;
|
|
903
|
+
}
|
|
860
904
|
|
|
861
905
|
// src/v2.0/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.ts
|
|
862
906
|
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, ontology, v2 = false, forInternalUse = false, currentFilePath = "") {
|
|
@@ -934,8 +978,8 @@ ${stringify(definition.links, {
|
|
|
934
978
|
${createPropertyKeys(interfaceDef)}
|
|
935
979
|
|
|
936
980
|
|
|
937
|
-
${createProps(interfaceDef, "Props", false)}
|
|
938
|
-
${createProps(interfaceDef, "StrictProps", true)}
|
|
981
|
+
${createProps(interfaceDef, "Props", false, ontology.raw.valueTypes)}
|
|
982
|
+
${createProps(interfaceDef, "StrictProps", true, ontology.raw.valueTypes)}
|
|
939
983
|
|
|
940
984
|
|
|
941
985
|
${createObjectSet(interfaceDef, ids)}
|