@osdk/maker 0.9.0-beta.2 → 0.9.0-beta.20
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 +174 -0
- package/build/browser/api/defineImportSpt.d.ts +10 -0
- package/build/browser/api/defineImportSpt.d.ts.map +1 -0
- package/build/browser/api/defineImportSpt.js +44 -0
- package/build/browser/api/defineImportSpt.js.map +1 -0
- package/build/browser/api/defineInterface.d.ts +11 -0
- package/build/browser/api/defineInterface.d.ts.map +1 -1
- package/build/browser/api/defineInterface.js +38 -11
- package/build/browser/api/defineInterface.js.map +1 -1
- package/build/browser/api/defineInterfaceLinkConstraint.d.ts +2 -0
- package/build/browser/api/defineInterfaceLinkConstraint.d.ts.map +1 -1
- package/build/browser/api/defineInterfaceLinkConstraint.js +2 -2
- package/build/browser/api/defineInterfaceLinkConstraint.js.map +1 -1
- package/build/browser/api/defineLink.js +2 -2
- package/build/browser/api/defineLink.js.map +1 -1
- package/build/browser/api/defineObject.d.ts.map +1 -1
- package/build/browser/api/defineObject.js +19 -2
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.d.ts +3 -3
- package/build/browser/api/defineOntology.d.ts.map +1 -1
- package/build/browser/api/defineOntology.js +85 -24
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/defineSpt.js +1 -1
- package/build/browser/api/defineSpt.js.map +1 -1
- package/build/browser/api/defineValueType.d.ts +8 -17
- package/build/browser/api/defineValueType.d.ts.map +1 -1
- package/build/browser/api/defineValueType.js +57 -11
- package/build/browser/api/defineValueType.js.map +1 -1
- package/build/browser/api/overall.test.js +351 -60
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/types.d.ts +196 -3
- package/build/browser/api/types.d.ts.map +1 -1
- package/build/browser/cli/main.js +3 -3
- package/build/browser/cli/main.js.map +1 -1
- package/build/browser/index.d.ts +1 -0
- package/build/browser/index.d.ts.map +1 -1
- package/build/browser/index.js +1 -0
- package/build/browser/index.js.map +1 -1
- package/build/esm/api/defineImportSpt.d.ts +10 -0
- package/build/esm/api/defineImportSpt.d.ts.map +1 -0
- package/build/esm/api/defineImportSpt.js +44 -0
- package/build/esm/api/defineImportSpt.js.map +1 -0
- package/build/esm/api/defineInterface.d.ts +11 -0
- package/build/esm/api/defineInterface.d.ts.map +1 -1
- package/build/esm/api/defineInterface.js +38 -11
- package/build/esm/api/defineInterface.js.map +1 -1
- package/build/esm/api/defineInterfaceLinkConstraint.d.ts +2 -0
- package/build/esm/api/defineInterfaceLinkConstraint.d.ts.map +1 -1
- package/build/esm/api/defineInterfaceLinkConstraint.js +2 -2
- package/build/esm/api/defineInterfaceLinkConstraint.js.map +1 -1
- package/build/esm/api/defineLink.js +2 -2
- package/build/esm/api/defineLink.js.map +1 -1
- package/build/esm/api/defineObject.d.ts.map +1 -1
- package/build/esm/api/defineObject.js +19 -2
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.d.ts +3 -3
- package/build/esm/api/defineOntology.d.ts.map +1 -1
- package/build/esm/api/defineOntology.js +85 -24
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/defineSpt.js +1 -1
- package/build/esm/api/defineSpt.js.map +1 -1
- package/build/esm/api/defineValueType.d.ts +8 -17
- package/build/esm/api/defineValueType.d.ts.map +1 -1
- package/build/esm/api/defineValueType.js +57 -11
- package/build/esm/api/defineValueType.js.map +1 -1
- package/build/esm/api/overall.test.js +351 -60
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/types.d.ts +196 -3
- package/build/esm/api/types.d.ts.map +1 -1
- package/build/esm/cli/main.js +3 -3
- package/build/esm/cli/main.js.map +1 -1
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/package.json +10 -8
|
@@ -25,7 +25,10 @@ export async function defineOntology(ns, body) {
|
|
|
25
25
|
queryTypes: {},
|
|
26
26
|
interfaceTypes: {},
|
|
27
27
|
sharedPropertyTypes: {},
|
|
28
|
-
valueTypes: {}
|
|
28
|
+
valueTypes: {},
|
|
29
|
+
importedTypes: {
|
|
30
|
+
sharedPropertyTypes: []
|
|
31
|
+
}
|
|
29
32
|
};
|
|
30
33
|
try {
|
|
31
34
|
await body();
|
|
@@ -58,19 +61,22 @@ function convertOntologyToValueTypeIr(ontology) {
|
|
|
58
61
|
}
|
|
59
62
|
function convertToWireOntologyIr(ontology) {
|
|
60
63
|
return {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
blockData: {
|
|
65
|
+
sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {
|
|
66
|
+
sharedPropertyType: convertSpt(spt)
|
|
67
|
+
}])),
|
|
68
|
+
interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {
|
|
69
|
+
return [apiName, {
|
|
70
|
+
interfaceType: convertInterface(interfaceType)
|
|
71
|
+
}];
|
|
72
|
+
})),
|
|
73
|
+
blockPermissionInformation: {
|
|
74
|
+
actionTypes: {},
|
|
75
|
+
linkTypes: {},
|
|
76
|
+
objectTypes: {}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
importedTypes: ontology.importedTypes
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
function convertInterface(interfaceType) {
|
|
@@ -99,6 +105,14 @@ function convertSpt({
|
|
|
99
105
|
typeClasses,
|
|
100
106
|
valueType
|
|
101
107
|
}) {
|
|
108
|
+
const dataConstraint = typeof type === "object" && type.type === "marking" ? {
|
|
109
|
+
propertyTypeConstraints: [],
|
|
110
|
+
nullability: "NO_EXPLICIT_NULLS",
|
|
111
|
+
nullabilityV2: {
|
|
112
|
+
noEmptyCollections: true,
|
|
113
|
+
noNulls: true
|
|
114
|
+
}
|
|
115
|
+
} : undefined;
|
|
102
116
|
return {
|
|
103
117
|
apiName,
|
|
104
118
|
displayMetadata: {
|
|
@@ -114,7 +128,7 @@ function convertSpt({
|
|
|
114
128
|
} : convertType(type),
|
|
115
129
|
aliases: [],
|
|
116
130
|
baseFormatter: undefined,
|
|
117
|
-
dataConstraints:
|
|
131
|
+
dataConstraints: dataConstraint,
|
|
118
132
|
gothamMapping: gothamMapping,
|
|
119
133
|
indexedForSearch: true,
|
|
120
134
|
provenance: undefined,
|
|
@@ -123,20 +137,67 @@ function convertSpt({
|
|
|
123
137
|
};
|
|
124
138
|
}
|
|
125
139
|
function convertType(type) {
|
|
126
|
-
switch (
|
|
127
|
-
case "
|
|
140
|
+
switch (true) {
|
|
141
|
+
case typeof type === "object" && "markingType" in type:
|
|
128
142
|
return {
|
|
129
|
-
type,
|
|
130
|
-
|
|
131
|
-
markingType:
|
|
143
|
+
"type": "marking",
|
|
144
|
+
marking: {
|
|
145
|
+
markingType: type.markingType
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
case typeof type === "object" && "structDefinition" in type:
|
|
149
|
+
const structFields = new Array();
|
|
150
|
+
for (const key in type.structDefinition) {
|
|
151
|
+
const fieldTypeDefinition = type.structDefinition[key];
|
|
152
|
+
var field;
|
|
153
|
+
if (typeof fieldTypeDefinition === "string") {
|
|
154
|
+
field = {
|
|
155
|
+
apiName: key,
|
|
156
|
+
displayMetadata: {
|
|
157
|
+
displayName: key,
|
|
158
|
+
description: undefined
|
|
159
|
+
},
|
|
160
|
+
typeClasses: [],
|
|
161
|
+
aliases: [],
|
|
162
|
+
fieldType: convertType(fieldTypeDefinition)
|
|
163
|
+
};
|
|
164
|
+
} else {
|
|
165
|
+
// If it is a full form type definition then process it as such
|
|
166
|
+
if ("fieldType" in fieldTypeDefinition) {
|
|
167
|
+
field = {
|
|
168
|
+
...fieldTypeDefinition,
|
|
169
|
+
apiName: key,
|
|
170
|
+
fieldType: convertType(fieldTypeDefinition.fieldType),
|
|
171
|
+
typeClasses: fieldTypeDefinition.typeClasses ?? [],
|
|
172
|
+
aliases: fieldTypeDefinition.aliases ?? []
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
field = {
|
|
176
|
+
apiName: key,
|
|
177
|
+
displayMetadata: {
|
|
178
|
+
displayName: key,
|
|
179
|
+
description: undefined
|
|
180
|
+
},
|
|
181
|
+
typeClasses: [],
|
|
182
|
+
aliases: [],
|
|
183
|
+
fieldType: convertType(fieldTypeDefinition)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
structFields.push(field);
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
type: "struct",
|
|
191
|
+
struct: {
|
|
192
|
+
structFields
|
|
132
193
|
}
|
|
133
194
|
};
|
|
134
|
-
case "geopoint":
|
|
195
|
+
case type === "geopoint":
|
|
135
196
|
return {
|
|
136
197
|
type: "geohash",
|
|
137
198
|
geohash: {}
|
|
138
199
|
};
|
|
139
|
-
case "decimal":
|
|
200
|
+
case type === "decimal":
|
|
140
201
|
return {
|
|
141
202
|
type,
|
|
142
203
|
[type]: {
|
|
@@ -144,7 +205,7 @@ function convertType(type) {
|
|
|
144
205
|
scale: undefined
|
|
145
206
|
}
|
|
146
207
|
};
|
|
147
|
-
case "string":
|
|
208
|
+
case type === "string":
|
|
148
209
|
return {
|
|
149
210
|
type,
|
|
150
211
|
[type]: {
|
|
@@ -154,7 +215,7 @@ function convertType(type) {
|
|
|
154
215
|
supportsExactMatching: true
|
|
155
216
|
}
|
|
156
217
|
};
|
|
157
|
-
case "mediaReference":
|
|
218
|
+
case type === "mediaReference":
|
|
158
219
|
return {
|
|
159
220
|
type: type,
|
|
160
221
|
mediaReference: {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineOntology.js","names":["ontologyDefinition","namespace","defineOntology","ns","body","actionTypes","objectTypes","queryTypes","interfaceTypes","sharedPropertyTypes","valueTypes","e","console","error","ontology","convertToWireOntologyIr","valueType","convertOntologyToValueTypeIr","Object","values","map","definitions","metadata","apiName","displayMetadata","status","versions","definition","version","baseType","constraints","exampleValues","fromEntries","entries","spt","sharedPropertyType","convertSpt","interfaceType","convertInterface","blockPermissionInformation","linkTypes","properties","allExtendsInterfaces","allLinks","allProperties","dumpOntologyFullMetadata","dumpValueTypeWireType","type","array","description","displayName","gothamMapping","typeClasses","visibility","subtype","convertType","aliases","baseFormatter","undefined","dataConstraints","indexedForSearch","provenance","markingType","geohash","precision","scale","analyzerOverride","enableAsciiFolding","isLongText","supportsExactMatching","mediaReference","distributeTypeHelper"],"sources":["defineOntology.js"],"sourcesContent":["/*\n * Copyright 2024 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/** @internal */\nexport let ontologyDefinition;\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {},\n valueTypes: {},\n };\n try {\n await body();\n }\n catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return {\n ontology: convertToWireOntologyIr(ontologyDefinition),\n valueType: convertOntologyToValueTypeIr(ontologyDefinition),\n };\n}\nfunction convertOntologyToValueTypeIr(ontology) {\n return {\n valueTypes: Object.values(ontology.valueTypes).map(definitions => ({\n metadata: {\n apiName: definitions[0].apiName,\n displayMetadata: definitions[0].displayMetadata,\n status: definitions[0].status,\n },\n versions: definitions.map(definition => ({\n version: definition.version,\n baseType: definition.baseType,\n constraints: definition.constraints,\n exampleValues: definition.exampleValues,\n })),\n })),\n };\n}\nfunction convertToWireOntologyIr(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes)\n .map(([apiName, spt]) => [apiName, { sharedPropertyType: convertSpt(spt) }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes)\n .map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType),\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {},\n },\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties)\n .map((spt) => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: [],\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntologyIr(ontologyDefinition);\n}\nexport function dumpValueTypeWireType() {\n return convertOntologyToValueTypeIr(ontologyDefinition);\n}\nfunction convertSpt({ type, array, description, apiName, displayName, gothamMapping, typeClasses, valueType, }) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description,\n },\n type: array\n ? {\n type: \"array\",\n array: {\n subtype: convertType(type),\n },\n }\n : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: gothamMapping,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: typeClasses ?? [],\n valueType: valueType,\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return { type, [type]: { markingType: \"MANDATORY\" } };\n case \"geopoint\":\n return { type: \"geohash\", geohash: {} };\n case \"decimal\":\n return { type, [type]: { precision: undefined, scale: undefined } };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true,\n },\n };\n case \"mediaReference\":\n return {\n type: type,\n mediaReference: {},\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return { type, [type]: {} }; // any cast to match conditional return type\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAIA,kBAAkB;AAC7B;AACA,OAAO,IAAIC,SAAS;AACpB,OAAO,eAAeC,cAAcA,CAACC,EAAE,EAAEC,IAAI,EAAE;EAC3CH,SAAS,GAAGE,EAAE;EACdH,kBAAkB,GAAG;IACjBK,WAAW,EAAE,CAAC,CAAC;IACfC,WAAW,EAAE,CAAC,CAAC;IACfC,UAAU,EAAE,CAAC,CAAC;IACdC,cAAc,EAAE,CAAC,CAAC;IAClBC,mBAAmB,EAAE,CAAC,CAAC;IACvBC,UAAU,EAAE,CAAC;EACjB,CAAC;EACD,IAAI;IACA,MAAMN,IAAI,CAAC,CAAC;EAChB,CAAC,CACD,OAAOO,CAAC,EAAE;IACN;IACAC,OAAO,CAACC,KAAK,CAAC,4DAA4D,EAAEF,CAAC,CAAC;IAC9E,MAAMA,CAAC;EACX;EACA,OAAO;IACHG,QAAQ,EAAEC,uBAAuB,CAACf,kBAAkB,CAAC;IACrDgB,SAAS,EAAEC,4BAA4B,CAACjB,kBAAkB;EAC9D,CAAC;AACL;AACA,SAASiB,4BAA4BA,CAACH,QAAQ,EAAE;EAC5C,OAAO;IACHJ,UAAU,EAAEQ,MAAM,CAACC,MAAM,CAACL,QAAQ,CAACJ,UAAU,CAAC,CAACU,GAAG,CAACC,WAAW,KAAK;MAC/DC,QAAQ,EAAE;QACNC,OAAO,EAAEF,WAAW,CAAC,CAAC,CAAC,CAAC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S;QAAEgB,OAAO,EAAE,CAAC;MAAE,CAAC;IAC3C,KAAK,SAAS;MACV,OAAO;QAAEhB,IAAI;QAAE,CAACA,IAAI,GAAG;UAAEiB,SAAS,EAAEN,SAAS;UAAEO,KAAK,EAAEP;QAAU;MAAE,CAAC;IACvE,KAAK,QAAQ;MACT,OAAO;QACHX,IAAI;QACJ,CAACA,IAAI,GAAG;UACJmB,gBAAgB,EAAER,SAAS;UAC3BS,kBAAkB,EAAET,SAAS;UAC7BU,UAAU,EAAE,KAAK;UACjBC,qBAAqB,EAAE;QAC3B;MACJ,CAAC;IACL,KAAK,gBAAgB;MACjB,OAAO;QACHtB,IAAI,EAAEA,IAAI;QACVuB,cAAc,EAAE,CAAC;MACrB,CAAC;IACL;MACI;MACA,OAAOC,oBAAoB,CAACxB,IAAI,CAAC;EACzC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASwB,oBAAoBA,CAACxB,IAAI,EAAE;EAChC,OAAO;IAAEA,IAAI;IAAE,CAACA,IAAI,GAAG,CAAC;EAAE,CAAC,CAAC,CAAC;AACjC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"defineOntology.js","names":["ontologyDefinition","namespace","defineOntology","ns","body","actionTypes","objectTypes","queryTypes","interfaceTypes","sharedPropertyTypes","valueTypes","importedTypes","e","console","error","ontology","convertToWireOntologyIr","valueType","convertOntologyToValueTypeIr","Object","values","map","definitions","metadata","apiName","displayMetadata","status","versions","definition","version","baseType","constraints","exampleValues","blockData","fromEntries","entries","spt","sharedPropertyType","convertSpt","interfaceType","convertInterface","blockPermissionInformation","linkTypes","properties","allExtendsInterfaces","allLinks","allProperties","dumpOntologyFullMetadata","dumpValueTypeWireType","type","array","description","displayName","gothamMapping","typeClasses","dataConstraint","propertyTypeConstraints","nullability","nullabilityV2","noEmptyCollections","noNulls","undefined","visibility","subtype","convertType","aliases","baseFormatter","dataConstraints","indexedForSearch","provenance","marking","markingType","structFields","Array","key","structDefinition","fieldTypeDefinition","field","fieldType","push","struct","geohash","precision","scale","analyzerOverride","enableAsciiFolding","isLongText","supportsExactMatching","mediaReference","distributeTypeHelper"],"sources":["defineOntology.js"],"sourcesContent":["/*\n * Copyright 2024 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/** @internal */\nexport let ontologyDefinition;\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {},\n valueTypes: {},\n importedTypes: {\n sharedPropertyTypes: [],\n },\n };\n try {\n await body();\n }\n catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return {\n ontology: convertToWireOntologyIr(ontologyDefinition),\n valueType: convertOntologyToValueTypeIr(ontologyDefinition),\n };\n}\nfunction convertOntologyToValueTypeIr(ontology) {\n return {\n valueTypes: Object.values(ontology.valueTypes).map(definitions => ({\n metadata: {\n apiName: definitions[0].apiName,\n displayMetadata: definitions[0].displayMetadata,\n status: definitions[0].status,\n },\n versions: definitions.map(definition => ({\n version: definition.version,\n baseType: definition.baseType,\n constraints: definition.constraints,\n exampleValues: definition.exampleValues,\n })),\n })),\n };\n}\nfunction convertToWireOntologyIr(ontology) {\n return {\n blockData: {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes)\n .map(([apiName, spt]) => [apiName, { sharedPropertyType: convertSpt(spt) }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes)\n .map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType),\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {},\n },\n },\n importedTypes: ontology.importedTypes,\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties)\n .map((spt) => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: [],\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntologyIr(ontologyDefinition);\n}\nexport function dumpValueTypeWireType() {\n return convertOntologyToValueTypeIr(ontologyDefinition);\n}\nfunction convertSpt({ type, array, description, apiName, displayName, gothamMapping, typeClasses, valueType, }) {\n const dataConstraint = (typeof type === \"object\" && type.type === \"marking\")\n ? {\n propertyTypeConstraints: [],\n nullability: \"NO_EXPLICIT_NULLS\",\n nullabilityV2: { noEmptyCollections: true, noNulls: true },\n }\n : undefined;\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description,\n },\n type: array\n ? {\n type: \"array\",\n array: {\n subtype: convertType(type),\n },\n }\n : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: dataConstraint,\n gothamMapping: gothamMapping,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: typeClasses ?? [],\n valueType: valueType,\n };\n}\nfunction convertType(type) {\n switch (true) {\n case (typeof type === \"object\" && \"markingType\" in type):\n return {\n \"type\": \"marking\",\n marking: { markingType: type.markingType },\n };\n case (typeof type === \"object\" && \"structDefinition\" in type):\n const structFields = new Array();\n for (const key in type.structDefinition) {\n const fieldTypeDefinition = type.structDefinition[key];\n var field;\n if (typeof fieldTypeDefinition === \"string\") {\n field = {\n apiName: key,\n displayMetadata: { displayName: key, description: undefined },\n typeClasses: [],\n aliases: [],\n fieldType: convertType(fieldTypeDefinition),\n };\n }\n else {\n // If it is a full form type definition then process it as such\n if (\"fieldType\" in fieldTypeDefinition) {\n field = {\n ...fieldTypeDefinition,\n apiName: key,\n fieldType: convertType(fieldTypeDefinition.fieldType),\n typeClasses: fieldTypeDefinition.typeClasses ?? [],\n aliases: fieldTypeDefinition.aliases ?? [],\n };\n }\n else {\n field = {\n apiName: key,\n displayMetadata: { displayName: key, description: undefined },\n typeClasses: [],\n aliases: [],\n fieldType: convertType(fieldTypeDefinition),\n };\n }\n }\n structFields.push(field);\n }\n return {\n type: \"struct\",\n struct: { structFields },\n };\n case (type === \"geopoint\"):\n return { type: \"geohash\", geohash: {} };\n case (type === \"decimal\"):\n return { type, [type]: { precision: undefined, scale: undefined } };\n case (type === \"string\"):\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true,\n },\n };\n case (type === \"mediaReference\"):\n return {\n type: type,\n mediaReference: {},\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return { type, [type]: {} }; // any cast to match conditional return type\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAIA,kBAAkB;AAC7B;AACA,OAAO,IAAIC,SAAS;AACpB,OAAO,eAAeC,cAAcA,CAACC,EAAE,EAAEC,IAAI,EAAE;EAC3CH,SAAS,GAAGE,EAAE;EACdH,kBAAkB,GAAG;IACjBK,WAAW,EAAE,CAAC,CAAC;IACfC,WAAW,EAAE,CAAC,CAAC;IACfC,UAAU,EAAE,CAAC,CAAC;IACdC,cAAc,EAAE,CAAC,CAAC;IAClBC,mBAAmB,EAAE,CAAC,CAAC;IACvBC,UAAU,EAAE,CAAC,CAAC;IACdC,aAAa,EAAE;MACXF,mBAAmB,EAAE;IACzB;EACJ,CAAC;EACD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3BwB,kBAAkB,EAAExB,SAAS;UAC7ByB,UAAU,EAAE,KAAK;UACjBC,qBAAqB,EAAE;QAC3B;MACJ,CAAC;IACL,KAAMtC,IAAI,KAAK,gBAAgB;MAC3B,OAAO;QACHA,IAAI,EAAEA,IAAI;QACVuC,cAAc,EAAE,CAAC;MACrB,CAAC;IACL;MACI;MACA,OAAOC,oBAAoB,CAACxC,IAAI,CAAC;EACzC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASwC,oBAAoBA,CAACxC,IAAI,EAAE;EAChC,OAAO;IAAEA,IAAI;IAAE,CAACA,IAAI,GAAG,CAAC;EAAE,CAAC,CAAC,CAAC;AACjC","ignoreList":[]}
|
|
@@ -24,7 +24,7 @@ const defaultTypeClasses = [{
|
|
|
24
24
|
}];
|
|
25
25
|
export function defineSharedPropertyType(opts) {
|
|
26
26
|
const apiName = namespace + opts.apiName;
|
|
27
|
-
!(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? invariant(false, `Shared property type ${apiName} already exists`) : void 0;
|
|
27
|
+
!(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;
|
|
28
28
|
return ontologyDefinition.sharedPropertyTypes[apiName] = {
|
|
29
29
|
...opts,
|
|
30
30
|
apiName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineSpt.js","names":["invariant","namespace","ontologyDefinition","defaultTypeClasses","kind","name","defineSharedPropertyType","opts","apiName","sharedPropertyTypes","undefined","displayName","typeClasses"],"sources":["defineSpt.js"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nconst defaultTypeClasses = [{\n kind: \"render_hint\",\n name: \"SELECTABLE\",\n }, { kind: \"render_hint\", name: \"SORTABLE\" }];\nexport function defineSharedPropertyType(opts) {\n const apiName = namespace + opts.apiName;\n invariant(ontologyDefinition.sharedPropertyTypes[apiName] === undefined, `Shared property type ${apiName} already exists`);\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts,\n apiName,\n displayName: opts.displayName ?? opts.apiName, // This way the non-namespaced api name is the display name (maybe not ideal)\n typeClasses: opts.typeClasses ?? defaultTypeClasses,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AACnE,MAAMC,kBAAkB,GAAG,CAAC;EACpBC,IAAI,EAAE,aAAa;EACnBC,IAAI,EAAE;AACV,CAAC,EAAE;EAAED,IAAI,EAAE,aAAa;EAAEC,IAAI,EAAE;AAAW,CAAC,CAAC;AACjD,OAAO,SAASC,wBAAwBA,CAACC,IAAI,EAAE;EAC3C,MAAMC,OAAO,GAAGP,SAAS,GAAGM,IAAI,CAACC,OAAO;EACxC,EAAUN,kBAAkB,CAACO,mBAAmB,CAACD,OAAO,CAAC,KAAKE,SAAS,
|
|
1
|
+
{"version":3,"file":"defineSpt.js","names":["invariant","namespace","ontologyDefinition","defaultTypeClasses","kind","name","defineSharedPropertyType","opts","apiName","sharedPropertyTypes","undefined","process","env","NODE_ENV","displayName","typeClasses"],"sources":["defineSpt.js"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nconst defaultTypeClasses = [{\n kind: \"render_hint\",\n name: \"SELECTABLE\",\n }, { kind: \"render_hint\", name: \"SORTABLE\" }];\nexport function defineSharedPropertyType(opts) {\n const apiName = namespace + opts.apiName;\n invariant(ontologyDefinition.sharedPropertyTypes[apiName] === undefined, `Shared property type ${apiName} already exists`);\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts,\n apiName,\n displayName: opts.displayName ?? opts.apiName, // This way the non-namespaced api name is the display name (maybe not ideal)\n typeClasses: opts.typeClasses ?? defaultTypeClasses,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AACnE,MAAMC,kBAAkB,GAAG,CAAC;EACpBC,IAAI,EAAE,aAAa;EACnBC,IAAI,EAAE;AACV,CAAC,EAAE;EAAED,IAAI,EAAE,aAAa;EAAEC,IAAI,EAAE;AAAW,CAAC,CAAC;AACjD,OAAO,SAASC,wBAAwBA,CAACC,IAAI,EAAE;EAC3C,MAAMC,OAAO,GAAGP,SAAS,GAAGM,IAAI,CAACC,OAAO;EACxC,EAAUN,kBAAkB,CAACO,mBAAmB,CAACD,OAAO,CAAC,KAAKE,SAAS,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAvEb,SAAS,QAAgE,wBAAwBQ,OAAO,iBAAiB,IAAzHR,SAAS;EACT,OAAOE,kBAAkB,CAACO,mBAAmB,CAACD,OAAO,CAAC,GAAG;IACrD,GAAGD,IAAI;IACPC,OAAO;IACPM,WAAW,EAAEP,IAAI,CAACO,WAAW,IAAIP,IAAI,CAACC,OAAO;IAAE;IAC/CO,WAAW,EAAER,IAAI,CAACQ,WAAW,IAAIZ;EACrC,CAAC;AACL","ignoreList":[]}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
baseType: Omit<Base, "type">;
|
|
8
|
-
constraints?: Constraint extends {
|
|
9
|
-
type: PropertyType;
|
|
10
|
-
} ? {
|
|
11
|
-
constraint: Omit<Constraint, "type">;
|
|
12
|
-
failureMessage?: FailureMessage;
|
|
13
|
-
}[] : undefined;
|
|
14
|
-
} : never;
|
|
1
|
+
import type { ValueTypeDefinitionVersion, ValueTypeType } from "./types.js";
|
|
2
|
+
type NewValueTypeDefinitionBacking = {
|
|
3
|
+
[Type in ValueTypeType as Type["type"]]: {
|
|
4
|
+
type: Type["value"];
|
|
5
|
+
constraints?: Type["constraints"];
|
|
6
|
+
};
|
|
15
7
|
};
|
|
16
|
-
type
|
|
17
|
-
type TypeAndConstraints = MappedZip[keyof MappedZip];
|
|
8
|
+
type NewValueTypeDefinition = NewValueTypeDefinitionBacking[keyof NewValueTypeDefinitionBacking];
|
|
18
9
|
export declare function defineValueType(opts: {
|
|
19
10
|
apiName: string;
|
|
20
11
|
displayName: string;
|
|
21
12
|
description?: string;
|
|
22
|
-
|
|
13
|
+
type: NewValueTypeDefinition;
|
|
23
14
|
version: string;
|
|
24
15
|
}): ValueTypeDefinitionVersion;
|
|
25
16
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineValueType.d.ts","sourceRoot":"","sources":["../../../src/api/defineValueType.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defineValueType.d.ts","sourceRoot":"","sources":["../../../src/api/defineValueType.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiC5E,KAAK,6BAA6B,GAAG;KAClC,IAAI,IAAI,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG;QACvC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,WAAW,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;KACnC;CACF,CAAC;AACF,KAAK,sBAAsB,GACzB,6BAA6B,CAAC,MAAM,6BAA6B,CAAC,CAAC;AA+CrE,wBAAgB,eAAe,CAC7B,IAAI,EAAE;IACJ,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;CACjB,GACA,0BAA0B,CAyC5B"}
|
|
@@ -15,28 +15,74 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import invariant from "tiny-invariant";
|
|
17
17
|
import { ontologyDefinition } from "./defineOntology.js";
|
|
18
|
+
function convertValueTypeTypeToBaseType(valueType) {
|
|
19
|
+
if (typeof valueType === "string") {}
|
|
20
|
+
switch (true) {
|
|
21
|
+
case typeof valueType === "object" && valueType.type === "array":
|
|
22
|
+
return {
|
|
23
|
+
type: "array",
|
|
24
|
+
array: {
|
|
25
|
+
elementType: convertValueTypeTypeToBaseType(valueType.elementType)
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
case typeof valueType === "object" && valueType.type === "struct":
|
|
29
|
+
return {
|
|
30
|
+
type: "structV2",
|
|
31
|
+
structV2: {
|
|
32
|
+
fields: valueType.fields.map(field => ({
|
|
33
|
+
identifier: field.identifier,
|
|
34
|
+
baseType: convertValueTypeTypeToBaseType(field.baseType)
|
|
35
|
+
}))
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
case typeof valueType === "object" && valueType.type === "map":
|
|
39
|
+
return {
|
|
40
|
+
type: "map",
|
|
41
|
+
map: {
|
|
42
|
+
keyType: convertValueTypeTypeToBaseType(valueType.keyType),
|
|
43
|
+
valueType: convertValueTypeTypeToBaseType(valueType.valueType)
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
case typeof valueType === "object" && valueType.type === "optional":
|
|
47
|
+
return {
|
|
48
|
+
type: "optional",
|
|
49
|
+
optional: {
|
|
50
|
+
wrappedType: convertValueTypeTypeToBaseType(valueType.wrappedType)
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
case typeof valueType === "string":
|
|
54
|
+
return {
|
|
55
|
+
type: valueType,
|
|
56
|
+
[valueType]: {}
|
|
57
|
+
};
|
|
58
|
+
default:
|
|
59
|
+
throw new Error("Invalid ValueTypeType");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
18
62
|
export function defineValueType(opts) {
|
|
19
63
|
const {
|
|
20
64
|
apiName,
|
|
21
65
|
displayName,
|
|
22
66
|
description,
|
|
23
|
-
|
|
67
|
+
type,
|
|
24
68
|
version
|
|
25
69
|
} = opts;
|
|
26
|
-
!/^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/.test(version) ? invariant(false, "Version is not a valid semver") : void 0;
|
|
70
|
+
!/^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/.test(version) ? process.env.NODE_ENV !== "production" ? invariant(false, "Version is not a valid semver") : invariant(false) : void 0;
|
|
71
|
+
const typeName = typeof type.type === "string" ? type.type : type.type.type === "struct" ? "structV2" : type.type.type;
|
|
27
72
|
// These suck but TS doesn't understand the relationship from the key of the base type to the type string
|
|
28
|
-
const constraints =
|
|
29
|
-
|
|
73
|
+
const constraints = type.constraints ? type.constraints.map(constraint => {
|
|
74
|
+
const output = {
|
|
30
75
|
constraint: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
76
|
+
type: typeName,
|
|
77
|
+
[typeName]: constraint.constraint
|
|
78
|
+
},
|
|
79
|
+
failureMessage: constraint.failureMessage
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
constraint: output
|
|
34
83
|
};
|
|
35
84
|
}) : [];
|
|
36
|
-
const baseType =
|
|
37
|
-
[Object.keys(typeAndConstraints.baseType)[0]]: Object.keys(typeAndConstraints.baseType)[0],
|
|
38
|
-
...typeAndConstraints.baseType
|
|
39
|
-
};
|
|
85
|
+
const baseType = convertValueTypeTypeToBaseType(type.type);
|
|
40
86
|
const vt = {
|
|
41
87
|
apiName,
|
|
42
88
|
displayMetadata: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineValueType.js","names":["invariant","ontologyDefinition","defineValueType","opts","apiName","displayName","description","
|
|
1
|
+
{"version":3,"file":"defineValueType.js","names":["invariant","ontologyDefinition","convertValueTypeTypeToBaseType","valueType","type","array","elementType","structV2","fields","map","field","identifier","baseType","keyType","optional","wrappedType","Error","defineValueType","opts","apiName","displayName","description","version","test","process","env","NODE_ENV","typeName","constraints","constraint","output","failureMessage","vt","displayMetadata","status","active","exampleValues","valueTypes","undefined","push"],"sources":["defineValueType.js"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nfunction convertValueTypeTypeToBaseType(valueType) {\n if (typeof valueType === \"string\") {\n }\n switch (true) {\n case (typeof valueType === \"object\" && valueType.type === \"array\"):\n return {\n type: \"array\",\n array: {\n elementType: convertValueTypeTypeToBaseType(valueType.elementType),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"struct\"):\n return {\n type: \"structV2\",\n structV2: {\n fields: valueType.fields.map(field => ({\n identifier: field.identifier,\n baseType: convertValueTypeTypeToBaseType(field.baseType),\n })),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"map\"):\n return {\n type: \"map\",\n map: {\n keyType: convertValueTypeTypeToBaseType(valueType.keyType),\n valueType: convertValueTypeTypeToBaseType(valueType.valueType),\n },\n };\n case (typeof valueType === \"object\" && valueType.type === \"optional\"):\n return {\n type: \"optional\",\n optional: {\n wrappedType: convertValueTypeTypeToBaseType(valueType.wrappedType),\n },\n };\n case (typeof valueType === \"string\"):\n return { type: valueType, [valueType]: {} };\n default:\n throw new Error(\"Invalid ValueTypeType\");\n }\n}\nexport function defineValueType(opts) {\n const { apiName, displayName, description, type, version } = opts;\n const semverValidation = /^((([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)$/;\n invariant(semverValidation.test(version), \"Version is not a valid semver\");\n const typeName = typeof type.type === \"string\"\n ? type.type\n : type.type.type === \"struct\"\n ? \"structV2\"\n : type.type.type;\n // These suck but TS doesn't understand the relationship from the key of the base type to the type string\n const constraints = type.constraints\n ? type.constraints.map(constraint => {\n const output = {\n constraint: { type: typeName, [typeName]: constraint.constraint },\n failureMessage: constraint.failureMessage,\n };\n return { constraint: output };\n })\n : [];\n const baseType = convertValueTypeTypeToBaseType(type.type);\n const vt = {\n apiName,\n displayMetadata: {\n displayName: displayName,\n description: description ?? \"\",\n },\n status: { type: \"active\", active: {} },\n version: version,\n baseType: baseType,\n constraints: constraints,\n exampleValues: [],\n };\n if (ontologyDefinition.valueTypes[apiName] === undefined) {\n ontologyDefinition.valueTypes[apiName] = [];\n }\n ontologyDefinition.valueTypes[apiName].push(vt);\n return vt;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,kBAAkB,QAAQ,qBAAqB;AACxD,SAASC,8BAA8BA,CAACC,SAAS,EAAE;EAC/C,IAAI,OAAOA,SAAS,KAAK,QAAQ,EAAE,CACnC;EACA,QAAQ,IAAI;IACR,KAAM,OAAOA,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,OAAO;MAC7D,OAAO;QACHA,IAAI,EAAE,OAAO;QACbC,KAAK,EAAE;UACHC,WAAW,EAAEJ,8BAA8B,CAACC,SAAS,CAACG,WAAW;QACrE;MACJ,CAAC;IACL,KAAM,OAAOH,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,QAAQ;MAC9D,OAAO;QACHA,IAAI,EAAE,UAAU;QAChBG,QAAQ,EAAE;UACNC,MAAM,EAAEL,SAAS,CAACK,MAAM,CAACC,GAAG,CAACC,KAAK,KAAK;YACnCC,UAAU,EAAED,KAAK,CAACC,UAAU;YAC5BC,QAAQ,EAAEV,8BAA8B,CAACQ,KAAK,CAACE,QAAQ;UAC3D,CAAC,CAAC;QACN;MACJ,CAAC;IACL,KAAM,OAAOT,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAACC,IAAI,KAAK,KAAK;MAC3D,OAAO;QACHA,IAAI,EAAE,KAAK;QACXK,GAAG,EAAE;UACDI,OAAO,EAAEX,8BAA8B,CAACC,SAAS,CAACU,OAAO,CAAC;UAC1DV,SAAS,EAAED,8BAA8B,CAACC,SAAS,CAACA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