@osdk/maker 0.10.0-beta.16 → 0.10.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/build/browser/api/defineAction.js +248 -5
  3. package/build/browser/api/defineAction.js.map +1 -1
  4. package/build/browser/api/defineLink.js +1 -1
  5. package/build/browser/api/defineLink.js.map +1 -1
  6. package/build/browser/api/defineObject.js +2 -4
  7. package/build/browser/api/defineObject.js.map +1 -1
  8. package/build/browser/api/defineOntology.js +60 -21
  9. package/build/browser/api/defineOntology.js.map +1 -1
  10. package/build/browser/api/defineSpt.js.map +1 -1
  11. package/build/browser/api/overall.test.js +1064 -23
  12. package/build/browser/api/overall.test.js.map +1 -1
  13. package/build/browser/api/types.js.map +1 -1
  14. package/build/browser/cli/main.js +1 -1
  15. package/build/browser/index.js +1 -1
  16. package/build/browser/index.js.map +1 -1
  17. package/build/cjs/index.cjs +311 -32
  18. package/build/cjs/index.cjs.map +1 -1
  19. package/build/cjs/index.d.cts +23 -7
  20. package/build/esm/api/defineAction.js +248 -5
  21. package/build/esm/api/defineAction.js.map +1 -1
  22. package/build/esm/api/defineLink.js +1 -1
  23. package/build/esm/api/defineLink.js.map +1 -1
  24. package/build/esm/api/defineObject.js +2 -4
  25. package/build/esm/api/defineObject.js.map +1 -1
  26. package/build/esm/api/defineOntology.js +60 -21
  27. package/build/esm/api/defineOntology.js.map +1 -1
  28. package/build/esm/api/defineSpt.js.map +1 -1
  29. package/build/esm/api/overall.test.js +1064 -23
  30. package/build/esm/api/overall.test.js.map +1 -1
  31. package/build/esm/api/types.js.map +1 -1
  32. package/build/esm/cli/main.js +1 -1
  33. package/build/esm/index.js +1 -1
  34. package/build/esm/index.js.map +1 -1
  35. package/build/types/api/defineAction.d.ts +3 -1
  36. package/build/types/api/defineAction.d.ts.map +1 -1
  37. package/build/types/api/defineObject.d.ts.map +1 -1
  38. package/build/types/api/defineOntology.d.ts.map +1 -1
  39. package/build/types/api/defineSpt.d.ts +2 -1
  40. package/build/types/api/defineSpt.d.ts.map +1 -1
  41. package/build/types/api/types.d.ts +19 -6
  42. package/build/types/api/types.d.ts.map +1 -1
  43. package/build/types/index.d.ts +1 -1
  44. package/build/types/index.d.ts.map +1 -1
  45. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.10.0-beta.18
4
+
5
+ ### Minor Changes
6
+
7
+ - 489ea17: Wire through nullability to SPT
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [56aa502]
12
+ - @osdk/api@2.2.0-beta.18
13
+
14
+ ## 0.10.0-beta.17
15
+
16
+ ### Minor Changes
17
+
18
+ - 6eeb423: Simple create and modify actions for interfaces
19
+ - 38ad25b: Make properties nullable
20
+ - 5745d3e: Make Object PKs singular
21
+ - 791e655: Add support for geoshape and geohash action parameters.
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [c6bee50]
26
+ - Updated dependencies [abe4897]
27
+ - Updated dependencies [70b4464]
28
+ - Updated dependencies [791e655]
29
+ - @osdk/api@2.2.0-beta.17
30
+
3
31
  ## 0.10.0-beta.16
4
32
 
5
33
  ### Minor Changes
@@ -16,6 +16,114 @@
16
16
 
17
17
  import invariant from "tiny-invariant";
18
18
  import { namespace, ontologyDefinition } from "./defineOntology.js";
19
+ export function defineCreateAction(interfaceType, objectType) {
20
+ return defineAction({
21
+ apiName: `create-${kebab(interfaceType.apiName.split(".").pop() ?? interfaceType.apiName)}${objectType === undefined ? "" : `-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`}`,
22
+ displayName: `Create ${interfaceType.displayMetadata.displayName}`,
23
+ parameters: [{
24
+ id: "objectTypeParameter",
25
+ displayName: "Object type to create",
26
+ type: {
27
+ type: "objectTypeReference",
28
+ objectTypeReference: {
29
+ interfaceTypeRids: [interfaceType.apiName]
30
+ }
31
+ },
32
+ validation: {
33
+ required: true,
34
+ allowedValues: objectType === undefined ? {
35
+ type: "objectTypeReference",
36
+ interfaceTypes: [interfaceType.apiName]
37
+ } : {
38
+ type: "oneOf",
39
+ oneOf: [{
40
+ label: objectType.displayName,
41
+ value: {
42
+ type: "objectType",
43
+ objectType: {
44
+ objectTypeId: objectType.apiName
45
+ }
46
+ }
47
+ }]
48
+ }
49
+ }
50
+ }, ...Object.entries(interfaceType.propertiesV2).map(([id, prop]) => ({
51
+ id,
52
+ displayName: prop.sharedPropertyType.displayName ?? prop.sharedPropertyType.nonNameSpacedApiName,
53
+ type: extractActionParameterTypeFromSpt(prop.sharedPropertyType),
54
+ typeClasses: prop.sharedPropertyType.typeClasses ?? [],
55
+ validation: {
56
+ required: true,
57
+ allowedValues: extractAllowedValuesFromSpt(prop.sharedPropertyType)
58
+ }
59
+ }))],
60
+ status: interfaceType.status.type !== "deprecated" ? interfaceType.status.type : interfaceType.status,
61
+ rules: [{
62
+ type: "addInterfaceRule",
63
+ addInterfaceRule: {
64
+ interfaceApiName: interfaceType.apiName,
65
+ objectTypeParameter: "objectTypeParameter",
66
+ sharedPropertyValues: Object.fromEntries(Object.entries(interfaceType.propertiesV2).map(([id, prop]) => [id, {
67
+ type: "parameterId",
68
+ parameterId: id
69
+ }]))
70
+ }
71
+ }]
72
+ });
73
+ }
74
+ export function defineModifyAction(interfaceType, objectType) {
75
+ return defineAction({
76
+ apiName: `modify-${kebab(interfaceType.apiName.split(".").pop() ?? interfaceType.apiName)}${objectType === undefined ? "" : `-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`}`,
77
+ displayName: `Modify ${interfaceType.displayMetadata.displayName}`,
78
+ parameters: [{
79
+ id: "interfaceObjectToModifyParameter",
80
+ displayName: "Object type to modify",
81
+ type: {
82
+ type: "interfaceReference",
83
+ interfaceReference: {
84
+ interfaceTypeRid: interfaceType.apiName
85
+ }
86
+ },
87
+ validation: {
88
+ required: true,
89
+ allowedValues: objectType === undefined ? {
90
+ type: "interfaceObjectQuery"
91
+ } : {
92
+ type: "oneOf",
93
+ oneOf: [{
94
+ label: objectType.displayName,
95
+ value: {
96
+ type: "objectType",
97
+ objectType: {
98
+ objectTypeId: objectType.apiName
99
+ }
100
+ }
101
+ }]
102
+ }
103
+ }
104
+ }, ...Object.entries(interfaceType.propertiesV2).map(([id, prop]) => ({
105
+ id,
106
+ displayName: prop.sharedPropertyType.displayName ?? prop.sharedPropertyType.nonNameSpacedApiName,
107
+ type: extractActionParameterTypeFromSpt(prop.sharedPropertyType),
108
+ typeClasses: prop.sharedPropertyType.typeClasses ?? [],
109
+ validation: {
110
+ required: true,
111
+ allowedValues: extractAllowedValuesFromSpt(prop.sharedPropertyType)
112
+ }
113
+ }))],
114
+ status: interfaceType.status.type !== "deprecated" ? interfaceType.status.type : interfaceType.status,
115
+ rules: [{
116
+ type: "modifyInterfaceRule",
117
+ modifyInterfaceRule: {
118
+ interfaceObjectToModifyParameter: "interfaceObjectToModifyParameter",
119
+ sharedPropertyValues: Object.fromEntries(Object.entries(interfaceType.propertiesV2).map(([id, prop]) => [id, {
120
+ type: "parameterId",
121
+ parameterId: id
122
+ }]))
123
+ }
124
+ }]
125
+ });
126
+ }
19
127
  export function defineAction(actionDef) {
20
128
  const apiName = namespace + actionDef.apiName;
21
129
  const parameterIds = (actionDef.parameters ?? []).map(p => p.id);
@@ -26,7 +134,7 @@ export function defineAction(actionDef) {
26
134
  const parameterIdsSet = new Set(parameterIds);
27
135
  !(parameterIdsSet.size === parameterIds.length) ? process.env.NODE_ENV !== "production" ? invariant(false, `Parameter ids must be unique`) : invariant(false) : void 0;
28
136
  const parameterIdsNotFound = Array.from(referencedParameterIds(actionDef)).filter(p => !parameterIdsSet.has(p));
29
- !(parameterIdsNotFound.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `Parameters [${parameterIdsNotFound}] were referenced but not defined`) : invariant(false) : void 0;
137
+ !(parameterIdsNotFound.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `Parameters ${JSON.stringify(parameterIdsNotFound)} were referenced but not defined`) : invariant(false) : void 0;
30
138
  const definedSectionIds = new Set(Object.keys(actionDef.sections ?? []));
31
139
  const undefinedSectionsInOrdering = (actionDef.formContentOrdering ?? []).flatMap(s => s.type === "parameterId" ? [] : [s.sectionId]).filter(sId => !definedSectionIds.has(sId));
32
140
  !(undefinedSectionsInOrdering.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `Sections [${undefinedSectionsInOrdering}] were referenced in content ordering but not defined`) : invariant(false) : void 0;
@@ -53,25 +161,160 @@ function referencedParameterIds(actionDef) {
53
161
 
54
162
  // logic rules
55
163
  actionDef.rules.forEach(rule => {
164
+ // when visiting each rule, we also do drive-by namespace prefixing
56
165
  switch (rule.type) {
57
166
  case "addInterfaceRule":
58
- parameterIds.add(rule.addInterfaceRule.objectType);
59
- Object.values(rule.addInterfaceRule.sharedPropertyValues).forEach(v => {
167
+ rule.addInterfaceRule.interfaceApiName = sanitize(rule.addInterfaceRule.interfaceApiName);
168
+ parameterIds.add(rule.addInterfaceRule.objectTypeParameter);
169
+ Object.entries(rule.addInterfaceRule.sharedPropertyValues).forEach(([k, v]) => {
60
170
  if (v.type === "parameterId") {
61
171
  parameterIds.add(v.parameterId);
62
172
  }
173
+ rule.addInterfaceRule.sharedPropertyValues[sanitize(k)] = v;
174
+ delete rule.addInterfaceRule.sharedPropertyValues[k];
63
175
  });
64
176
  break;
65
177
  case "modifyInterfaceRule":
66
- parameterIds.add(rule.modifyInterfaceRule.interfaceObjectToModify);
67
- Object.values(rule.modifyInterfaceRule.sharedPropertyValues).forEach(v => {
178
+ parameterIds.add(rule.modifyInterfaceRule.interfaceObjectToModifyParameter);
179
+ Object.entries(rule.modifyInterfaceRule.sharedPropertyValues).forEach(([k, v]) => {
68
180
  if (v.type === "parameterId") {
69
181
  parameterIds.add(v.parameterId);
70
182
  }
183
+ rule.modifyInterfaceRule.sharedPropertyValues[sanitize(k)] = v;
184
+ delete rule.modifyInterfaceRule.sharedPropertyValues[k];
71
185
  });
72
186
  break;
73
187
  }
74
188
  });
75
189
  return parameterIds;
76
190
  }
191
+ function extractAllowedValuesFromSpt(spt) {
192
+ switch (spt.type) {
193
+ case "boolean":
194
+ return {
195
+ type: "boolean"
196
+ };
197
+ case "byte":
198
+ return {
199
+ type: "range",
200
+ min: {
201
+ type: "staticValue",
202
+ staticValue: {
203
+ type: "integer",
204
+ integer: 0
205
+ }
206
+ },
207
+ max: {
208
+ type: "staticValue",
209
+ staticValue: {
210
+ type: "integer",
211
+ integer: 255
212
+ }
213
+ }
214
+ };
215
+ case "timestamp":
216
+ case "date":
217
+ return {
218
+ type: "datetime"
219
+ };
220
+ case "decimal":
221
+ case "double":
222
+ case "float":
223
+ case "integer":
224
+ case "long":
225
+ return {
226
+ type: "range"
227
+ };
228
+ case "short":
229
+ return {
230
+ type: "range",
231
+ min: {
232
+ type: "staticValue",
233
+ staticValue: {
234
+ type: "integer",
235
+ integer: 0
236
+ }
237
+ },
238
+ max: {
239
+ type: "staticValue",
240
+ staticValue: {
241
+ type: "integer",
242
+ integer: 65535
243
+ }
244
+ }
245
+ };
246
+ case "string":
247
+ return {
248
+ type: "text"
249
+ };
250
+ case "geopoint":
251
+ case "geoshape":
252
+ return {
253
+ type: "geoshape"
254
+ };
255
+ case "mediaReference":
256
+ return {
257
+ type: "mediaReference"
258
+ };
259
+ case "geotimeSeries":
260
+ return {
261
+ type: "geotimeSeriesReference"
262
+ };
263
+ default:
264
+ switch (spt.type.type) {
265
+ case "marking":
266
+ return spt.type.markingType === "CBAC" ? {
267
+ type: "cbacMarking"
268
+ } : {
269
+ type: "mandatoryMarking"
270
+ };
271
+ case "struct":
272
+ throw new Error("Structs are not supported yet");
273
+ default:
274
+ throw new Error("Unknown type");
275
+ }
276
+ break;
277
+ }
278
+ }
279
+ function extractActionParameterTypeFromSpt(spt) {
280
+ const typeType = spt.type;
281
+ if (typeof typeType === "object") {
282
+ switch (typeType.type) {
283
+ case "marking":
284
+ break;
285
+ case "struct":
286
+ break;
287
+ default:
288
+ throw new Error(`Unknown type`);
289
+ }
290
+ }
291
+ if (typeof typeType === "string" && isActionParameterTypePrimitive(typeType)) {
292
+ return maybeAddList(typeType, spt);
293
+ }
294
+ switch (typeType) {
295
+ case "byte":
296
+ case "short":
297
+ return maybeAddList("integer", spt);
298
+ case "geopoint":
299
+ return maybeAddList("geoshape", spt);
300
+ case "float":
301
+ return maybeAddList("double", spt);
302
+ case "geotimeSeries":
303
+ return maybeAddList("geotimeSeriesReference", spt);
304
+ default:
305
+ throw new Error("Unknown type");
306
+ }
307
+ }
308
+ function maybeAddList(type, spt) {
309
+ return spt.array ?? false ? type + "List" : type;
310
+ }
311
+ function isActionParameterTypePrimitive(type) {
312
+ return ["boolean", "booleanList", "integer", "integerList", "long", "longList", "double", "doubleList", "string", "stringList", "decimal", "decimalList", "timestamp", "timestampList", "geohash", "geohashList", "geoshape", "geoshapeList", "timeSeriesReference", "date", "dateList", "objectTypeReference", "attachment", "attachmentList", "marking", "markingList", "mediaReference", "mediaReferenceList", "geotimeSeriesReference", "geotimeSeriesReferenceList"].includes(type);
313
+ }
314
+ function kebab(s) {
315
+ return s.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/\./g, "-").toLowerCase();
316
+ }
317
+ function sanitize(s) {
318
+ return s.includes(".") ? s : namespace + s;
319
+ }
77
320
  //# sourceMappingURL=defineAction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineAction.js","names":["invariant","namespace","ontologyDefinition","defineAction","actionDef","apiName","parameterIds","parameters","map","p","id","actionTypes","undefined","Error","test","process","env","NODE_ENV","parameterIdsSet","Set","size","length","parameterIdsNotFound","Array","from","referencedParameterIds","filter","has","definedSectionIds","Object","keys","sections","undefinedSectionsInOrdering","formContentOrdering","flatMap","s","type","sectionId","sId","rules","fullAction","values","forEach","pId","add","item","parameterId","rule","addInterfaceRule","objectType","sharedPropertyValues","v","modifyInterfaceRule","interfaceObjectToModify"],"sources":["defineAction.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 { ParameterId } from \"@osdk/client.unstable\";\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport type { ActionType } from \"./types.js\";\n\nexport function defineAction(actionDef: ActionType): ActionType {\n const apiName = namespace + actionDef.apiName;\n const parameterIds = (actionDef.parameters ?? []).map(p => p.id);\n\n if (ontologyDefinition.actionTypes[apiName] !== undefined) {\n throw new Error(\n `Action type with apiName ${actionDef.apiName} is already defined`,\n );\n }\n invariant(\n /^[a-z0-9]+(-[a-z0-9]+)*$/.test(actionDef.apiName),\n `Action type apiName \"${actionDef.apiName}\" must be alphanumeric, lowercase, and kebab-case`,\n );\n\n const parameterIdsSet = new Set(parameterIds);\n invariant(\n parameterIdsSet.size === parameterIds.length,\n `Parameter ids must be unique`,\n );\n\n const parameterIdsNotFound = Array.from(referencedParameterIds(actionDef))\n .filter(p => !parameterIdsSet.has(p));\n invariant(\n parameterIdsNotFound.length === 0,\n `Parameters [${parameterIdsNotFound}] were referenced but not defined`,\n );\n\n const definedSectionIds = new Set(Object.keys(actionDef.sections ?? []));\n const undefinedSectionsInOrdering = (actionDef.formContentOrdering ?? [])\n .flatMap(\n s => s.type === \"parameterId\" ? [] : [s.sectionId],\n ).filter(sId => !definedSectionIds.has(sId));\n invariant(\n undefinedSectionsInOrdering.length === 0,\n `Sections [${undefinedSectionsInOrdering}] were referenced in content ordering but not defined`,\n );\n\n invariant(\n actionDef.rules.length > 0,\n `Action type ${actionDef.apiName} must have at least one logic rule`,\n );\n\n const fullAction = { ...actionDef, apiName: apiName };\n ontologyDefinition.actionTypes[apiName] = fullAction;\n return fullAction;\n}\n\nfunction referencedParameterIds(actionDef: ActionType): Set<ParameterId> {\n const parameterIds: Set<ParameterId> = new Set();\n\n // section definitions\n Object.values(actionDef.sections ?? {})\n .flatMap(p => p).forEach(pId => parameterIds.add(pId));\n\n // form content ordering\n (actionDef.formContentOrdering ?? []).forEach(item => {\n if (item.type === \"parameterId\") {\n parameterIds.add(item.parameterId);\n }\n });\n\n // logic rules\n actionDef.rules.forEach(rule => {\n switch (rule.type) {\n case \"addInterfaceRule\":\n parameterIds.add(rule.addInterfaceRule.objectType);\n Object.values(rule.addInterfaceRule.sharedPropertyValues).forEach(v => {\n if (v.type === \"parameterId\") {\n parameterIds.add(v.parameterId);\n }\n });\n break;\n case \"modifyInterfaceRule\":\n parameterIds.add(rule.modifyInterfaceRule.interfaceObjectToModify);\n Object.values(rule.modifyInterfaceRule.sharedPropertyValues).forEach(\n v => {\n if (v.type === \"parameterId\") {\n parameterIds.add(v.parameterId);\n }\n },\n );\n break;\n }\n });\n return parameterIds;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AAGnE,OAAO,SAASC,YAAYA,CAACC,SAAqB,EAAc;EAC9D,MAAMC,OAAO,GAAGJ,SAAS,GAAGG,SAAS,CAACC,OAAO;EAC7C,MAAMC,YAAY,GAAG,CAACF,SAAS,CAACG,UAAU,IAAI,EAAE,EAAEC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,EAAE,CAAC;EAEhE,IAAIR,kBAAkB,CAACS,WAAW,CAACN,OAAO,CAAC,KAAKO,SAAS,EAAE;IACzD,MAAM,IA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K,aAAa,EAAE;YAC5B9B,YAAY,CAACsC,GAAG,CAACO,CAAC,CAACL,WAAW,CAAC;UACjC;QACF,CAAC,CAAC;QACF;MACF,KAAK,qBAAqB;QACxBxC,YAAY,CAACsC,GAAG,CAACG,IAAI,CAACK,mBAAmB,CAACC,uBAAuB,CAAC;QAClExB,MAAM,CAACY,MAAM,CAACM,IAAI,CAACK,mBAAmB,CAACF,oBAAoB,CAAC,CAACR,OAAO,CAClES,CAAC,IAAI;UACH,IAAIA,CAAC,CAACf,IAAI,KAAK,aAAa,EAAE;YAC5B9B,YAAY,CAACsC,GAAG,CAACO,CAAC,CAACL,WAAW,CAAC;UACjC;QACF,CACF,CAAC;QACD;IACJ;EACF,CAAC,CAAC;EACF,OAAOxC,YAAY;AACrB","ignoreList":[]}
1
+ {"version":3,"file":"defineAction.js","names":["invariant","namespace","ontologyDefinition","defineCreateAction","interfaceType","objectType","defineAction","apiName","kebab","split","pop","undefined","displayName","displayMetadata","parameters","id","type","objectTypeReference","interfaceTypeRids","validation","required","allowedValues","interfaceTypes","oneOf","label","value","objectTypeId","Object","entries","propertiesV2","map","prop","sharedPropertyType","nonNameSpacedApiName","extractActionParameterTypeFromSpt","typeClasses","extractAllowedValuesFromSpt","status","rules","addInterfaceRule","interfaceApiName","objectTypeParameter","sharedPropertyValues","fromEntries","parameterId","defineModifyAction","interfaceReference","interfaceTypeRid","modifyInterfaceRule","interfaceObjectToModifyParameter","actionDef","parameterIds","p","actionTypes","Error","test","process","env","NODE_ENV","parameterIdsSet","Set","size","length","parameterIdsNotFound","Array","from","referencedParameterIds","filter","has","JSON","stringify","definedSectionIds","keys","sections","undefinedSectionsInOrdering","formContentOrdering","flatMap","s","sectionId","sId","fullAction","values","forEach","pId","add","item","rule","sanitize","k","v","spt","min","staticValue","integer","max","markingType","typeType","isActionParameterTypePrimitive","maybeAddList","array","includes","replace","toLowerCase"],"sources":["defineAction.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 { ParameterId } from \"@osdk/client.unstable\";\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport type {\n ActionParameterAllowedValues,\n ActionParameterType,\n ActionParameterTypePrimitive,\n ActionType,\n InterfaceType,\n ObjectType,\n SharedPropertyType,\n} from \"./types.js\";\n\nexport function defineCreateAction(\n interfaceType: InterfaceType,\n objectType?: ObjectType,\n): ActionType {\n return defineAction({\n apiName: `create-${\n kebab(interfaceType.apiName.split(\".\").pop() ?? interfaceType.apiName)\n }${\n objectType === undefined\n ? \"\"\n : `-${kebab(objectType.apiName.split(\".\").pop() ?? objectType.apiName)}`\n }`,\n displayName: `Create ${interfaceType.displayMetadata.displayName}`,\n parameters: [\n {\n id: \"objectTypeParameter\",\n displayName: \"Object type to create\",\n type: {\n type: \"objectTypeReference\",\n objectTypeReference: { interfaceTypeRids: [interfaceType.apiName] },\n },\n validation: {\n required: true,\n allowedValues: objectType === undefined\n ? {\n type: \"objectTypeReference\",\n interfaceTypes: [interfaceType.apiName],\n }\n : {\n type: \"oneOf\",\n oneOf: [{\n label: objectType.displayName,\n value: {\n type: \"objectType\",\n objectType: { objectTypeId: objectType.apiName },\n },\n }],\n },\n },\n },\n ...Object.entries(interfaceType.propertiesV2).map((\n [id, prop],\n ) => ({\n id,\n displayName: prop.sharedPropertyType.displayName\n ?? prop.sharedPropertyType.nonNameSpacedApiName,\n type: extractActionParameterTypeFromSpt(prop.sharedPropertyType),\n typeClasses: prop.sharedPropertyType.typeClasses ?? [],\n validation: {\n required: true,\n allowedValues: extractAllowedValuesFromSpt(\n prop.sharedPropertyType,\n ),\n },\n })),\n ],\n status: interfaceType.status.type !== \"deprecated\"\n ? interfaceType.status.type\n : interfaceType.status,\n rules: [\n {\n type: \"addInterfaceRule\",\n addInterfaceRule: {\n interfaceApiName: interfaceType.apiName,\n objectTypeParameter: \"objectTypeParameter\",\n sharedPropertyValues: Object.fromEntries(\n Object.entries(interfaceType.propertiesV2).map((\n [id, prop],\n ) => [id, { type: \"parameterId\", parameterId: id }]),\n ),\n },\n },\n ],\n });\n}\n\nexport function defineModifyAction(\n interfaceType: InterfaceType,\n objectType?: ObjectType,\n): ActionType {\n return defineAction({\n apiName: `modify-${\n kebab(interfaceType.apiName.split(\".\").pop() ?? interfaceType.apiName)\n }${\n objectType === undefined\n ? \"\"\n : `-${kebab(objectType.apiName.split(\".\").pop() ?? objectType.apiName)}`\n }`,\n displayName: `Modify ${interfaceType.displayMetadata.displayName}`,\n parameters: [\n {\n id: \"interfaceObjectToModifyParameter\",\n displayName: \"Object type to modify\",\n type: {\n type: \"interfaceReference\",\n interfaceReference: { interfaceTypeRid: interfaceType.apiName },\n },\n validation: {\n required: true,\n allowedValues: objectType === undefined\n ? { type: \"interfaceObjectQuery\" }\n : {\n type: \"oneOf\",\n oneOf: [{\n label: objectType.displayName,\n value: {\n type: \"objectType\",\n objectType: { objectTypeId: objectType.apiName },\n },\n }],\n },\n },\n },\n ...Object.entries(interfaceType.propertiesV2).map((\n [id, prop],\n ) => ({\n id,\n displayName: prop.sharedPropertyType.displayName\n ?? prop.sharedPropertyType.nonNameSpacedApiName,\n type: extractActionParameterTypeFromSpt(prop.sharedPropertyType),\n typeClasses: prop.sharedPropertyType.typeClasses ?? [],\n validation: {\n required: true,\n allowedValues: extractAllowedValuesFromSpt(\n prop.sharedPropertyType,\n ),\n },\n })),\n ],\n status: interfaceType.status.type !== \"deprecated\"\n ? interfaceType.status.type\n : interfaceType.status,\n rules: [\n {\n type: \"modifyInterfaceRule\",\n modifyInterfaceRule: {\n interfaceObjectToModifyParameter: \"interfaceObjectToModifyParameter\",\n sharedPropertyValues: Object.fromEntries(\n Object.entries(interfaceType.propertiesV2).map((\n [id, prop],\n ) => [id, { type: \"parameterId\", parameterId: id }]),\n ),\n },\n },\n ],\n });\n}\n\nexport function defineAction(actionDef: ActionType): ActionType {\n const apiName = namespace + actionDef.apiName;\n const parameterIds = (actionDef.parameters ?? []).map(p => p.id);\n\n if (ontologyDefinition.actionTypes[apiName] !== undefined) {\n throw new Error(\n `Action type with apiName ${actionDef.apiName} is already defined`,\n );\n }\n invariant(\n /^[a-z0-9]+(-[a-z0-9]+)*$/.test(actionDef.apiName),\n `Action type apiName \"${actionDef.apiName}\" must be alphanumeric, lowercase, and kebab-case`,\n );\n\n const parameterIdsSet = new Set(parameterIds);\n invariant(\n parameterIdsSet.size === parameterIds.length,\n `Parameter ids must be unique`,\n );\n\n const parameterIdsNotFound = Array.from(referencedParameterIds(actionDef))\n .filter(p => !parameterIdsSet.has(p));\n invariant(\n parameterIdsNotFound.length === 0,\n `Parameters ${\n JSON.stringify(parameterIdsNotFound)\n } were referenced but not defined`,\n );\n\n const definedSectionIds = new Set(Object.keys(actionDef.sections ?? []));\n const undefinedSectionsInOrdering = (actionDef.formContentOrdering ?? [])\n .flatMap(\n s => s.type === \"parameterId\" ? [] : [s.sectionId],\n ).filter(sId => !definedSectionIds.has(sId));\n invariant(\n undefinedSectionsInOrdering.length === 0,\n `Sections [${undefinedSectionsInOrdering}] were referenced in content ordering but not defined`,\n );\n\n invariant(\n actionDef.rules.length > 0,\n `Action type ${actionDef.apiName} must have at least one logic rule`,\n );\n\n const fullAction = { ...actionDef, apiName: apiName };\n ontologyDefinition.actionTypes[apiName] = fullAction;\n return fullAction;\n}\n\nfunction referencedParameterIds(actionDef: ActionType): Set<ParameterId> {\n const parameterIds: Set<ParameterId> = new Set();\n\n // section definitions\n Object.values(actionDef.sections ?? {})\n .flatMap(p => p).forEach(pId => parameterIds.add(pId));\n\n // form content ordering\n (actionDef.formContentOrdering ?? []).forEach(item => {\n if (item.type === \"parameterId\") {\n parameterIds.add(item.parameterId);\n }\n });\n\n // logic rules\n actionDef.rules.forEach(rule => {\n // when visiting each rule, we also do drive-by namespace prefixing\n switch (rule.type) {\n case \"addInterfaceRule\":\n rule.addInterfaceRule.interfaceApiName = sanitize(\n rule.addInterfaceRule.interfaceApiName,\n );\n parameterIds.add(rule.addInterfaceRule.objectTypeParameter);\n Object.entries(rule.addInterfaceRule.sharedPropertyValues).forEach(\n ([k, v]) => {\n if (v.type === \"parameterId\") {\n parameterIds.add(v.parameterId);\n }\n rule.addInterfaceRule.sharedPropertyValues[sanitize(k)] = v;\n delete rule.addInterfaceRule.sharedPropertyValues[k];\n },\n );\n break;\n case \"modifyInterfaceRule\":\n parameterIds.add(\n rule.modifyInterfaceRule.interfaceObjectToModifyParameter,\n );\n Object.entries(rule.modifyInterfaceRule.sharedPropertyValues).forEach(\n ([k, v]) => {\n if (v.type === \"parameterId\") {\n parameterIds.add(v.parameterId);\n }\n rule.modifyInterfaceRule.sharedPropertyValues[sanitize(k)] = v;\n delete rule.modifyInterfaceRule.sharedPropertyValues[k];\n },\n );\n break;\n }\n });\n return parameterIds;\n}\n\nfunction extractAllowedValuesFromSpt(\n spt: SharedPropertyType,\n): ActionParameterAllowedValues {\n switch (spt.type) {\n case \"boolean\":\n return { type: \"boolean\" };\n case \"byte\":\n return {\n type: \"range\",\n min: {\n type: \"staticValue\",\n staticValue: { type: \"integer\", integer: 0 },\n },\n max: {\n type: \"staticValue\",\n staticValue: { type: \"integer\", integer: 255 },\n },\n };\n case \"timestamp\":\n case \"date\":\n return { type: \"datetime\" };\n case \"decimal\":\n case \"double\":\n case \"float\":\n case \"integer\":\n case \"long\":\n return { type: \"range\" };\n case \"short\":\n return {\n type: \"range\",\n min: {\n type: \"staticValue\",\n staticValue: { type: \"integer\", integer: 0 },\n },\n max: {\n type: \"staticValue\",\n staticValue: { type: \"integer\", integer: 65535 },\n },\n };\n case \"string\":\n return { type: \"text\" };\n case \"geopoint\":\n case \"geoshape\":\n return { type: \"geoshape\" };\n case \"mediaReference\":\n return { type: \"mediaReference\" };\n case \"geotimeSeries\":\n return { type: \"geotimeSeriesReference\" };\n default:\n switch (spt.type.type) {\n case \"marking\":\n return spt.type.markingType === \"CBAC\"\n ? { type: \"cbacMarking\" }\n : { type: \"mandatoryMarking\" };\n case \"struct\":\n throw new Error(\"Structs are not supported yet\");\n default:\n throw new Error(\"Unknown type\");\n }\n break;\n }\n}\n\nfunction extractActionParameterTypeFromSpt(\n spt: SharedPropertyType,\n): ActionParameterType {\n const typeType = spt.type;\n if (typeof typeType === \"object\") {\n switch (typeType.type) {\n case \"marking\":\n break;\n case \"struct\":\n break;\n default:\n throw new Error(`Unknown type`);\n }\n }\n if (\n typeof typeType === \"string\" && isActionParameterTypePrimitive(typeType)\n ) {\n return maybeAddList(typeType, spt);\n }\n switch (typeType) {\n case \"byte\":\n case \"short\":\n return maybeAddList(\"integer\", spt);\n case \"geopoint\":\n return maybeAddList(\"geoshape\", spt);\n case \"float\":\n return maybeAddList(\"double\", spt);\n case \"geotimeSeries\":\n return maybeAddList(\"geotimeSeriesReference\", spt);\n default:\n throw new Error(\"Unknown type\");\n }\n}\n\nfunction maybeAddList(\n type: ActionParameterTypePrimitive,\n spt: SharedPropertyType,\n): ActionParameterType {\n return ((spt.array ?? false) ? type + \"List\" : type) as ActionParameterType;\n}\n\nfunction isActionParameterTypePrimitive(\n type: string,\n): type is ActionParameterTypePrimitive {\n return [\n \"boolean\",\n \"booleanList\",\n \"integer\",\n \"integerList\",\n \"long\",\n \"longList\",\n \"double\",\n \"doubleList\",\n \"string\",\n \"stringList\",\n \"decimal\",\n \"decimalList\",\n \"timestamp\",\n \"timestampList\",\n \"geohash\",\n \"geohashList\",\n \"geoshape\",\n \"geoshapeList\",\n \"timeSeriesReference\",\n \"date\",\n \"dateList\",\n \"objectTypeReference\",\n \"attachment\",\n \"attachmentList\",\n \"marking\",\n \"markingList\",\n \"mediaReference\",\n \"mediaReferenceList\",\n \"geotimeSeriesReference\",\n \"geotimeSeriesReferenceList\",\n ].includes(type);\n}\n\nfunction kebab(s: string): string {\n return s\n .replace(/([a-z])([A-Z])/g, \"$1-$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1-$2\")\n .replace(/\\./g, \"-\")\n .toLowerCase();\n}\n\nfunction sanitize(s: string): string {\n return s.includes(\".\") ? s : namespace + s;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AAWnE,OAAO,SAASC,kBAAkBA,CAChCC,aAA4B,EAC5BC,UAAuB,EACX;EACZ,OAAOC,YAAY,CAAC;IAClBC,OAAO,EAAE,UACPC,KAAK,CAACJ,aAAa,CAACG,OAAO,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,IAAIN,aAAa,CAACG,OAAO,CAAC,GAEtEF,UAAU,KAAKM,SAAS,GACpB,EAAE,GACF,IAAIH,KAAK,CAACH,UAAU,CAACE,OAAO,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,IAAIL,UAAU,CAACE,OAAO,CAAC,EAAE,EAC1E;IACFK,WAAW,EAAE,UAAUR,aAAa,CAACS,eAAe,CAACD,WAAW,EAAE;IAClEE,UAAU,EAAE,CACV;MACEC,EAAE,EAAE,qBAAqB;MACzBH,WAAW,EAAE,uBAAuB;MACpCI,IAAI,EAAE;QACJA,IAAI,EAAE,qBAAqB;QAC3BC,mBAAmB,EAAE;UAAEC,iBAAiB,EAAE,CAACd,aAAa,CAACG,OAAO;QAAE;MACpE,CAAC;MACDY,UAAU,EAAE;QACVC,QAAQ,EAAE,IAAI;QACdC,aAAa,EAAEhB,UAAU,KAAKM,SAAS,GACnC;UACAK,I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AACrD;AAEA,SAASiF,8BAA8BA,CACrCjF,IAAY,EAC0B;EACtC,OAAO,CACL,SAAS,EACT,aAAa,EACb,SAAS,EACT,aAAa,EACb,MAAM,EACN,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,EACX,eAAe,EACf,SAAS,EACT,aAAa,EACb,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,MAAM,EACN,UAAU,EACV,qBAAqB,EACrB,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,4BAA4B,CAC7B,CAACoF,QAAQ,CAACpF,IAAI,CAAC;AAClB;AAEA,SAASR,KAAKA,CAACqE,CAAS,EAAU;EAChC,OAAOA,CAAC,CACLwB,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CACnCA,OAAO,CAAC,sBAAsB,EAAE,OAAO,CAAC,CACxCA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CACnBC,WAAW,CAAC,CAAC;AAClB;AAEA,SAASf,QAAQA,CAACV,CAAS,EAAU;EACnC,OAAOA,CAAC,CAACuB,QAAQ,CAAC,GAAG,CAAC,GAAGvB,CAAC,GAAG5E,SAAS,GAAG4E,CAAC;AAC5C","ignoreList":[]}
@@ -27,7 +27,7 @@ export function defineLink(linkDefinition) {
27
27
  if ("one" in linkDefinition) {
28
28
  const foreignKey = linkDefinition.toMany.object.properties?.find(prop => prop.apiName === linkDefinition.manyForeignKeyProperty);
29
29
  !(foreignKey !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Foreign key ${linkDefinition.manyForeignKeyProperty} on link ${linkDefinition.id} does not exist on object ${linkDefinition.toMany.object.apiName}}`) : invariant(false) : void 0;
30
- const typesMatch = foreignKey.type === linkDefinition.one.object.properties?.find(prop => prop.apiName === linkDefinition.one.object.primaryKeys[0])?.type;
30
+ const typesMatch = foreignKey.type === linkDefinition.one.object.properties?.find(prop => prop.apiName === linkDefinition.one.object.primaryKeyPropertyApiName)?.type;
31
31
  !typesMatch ? process.env.NODE_ENV !== "production" ? invariant(false, `Link ${linkDefinition.id} has type mismatch between the one side's primary key and the foreign key on the many side`) : invariant(false) : void 0;
32
32
  }
33
33
  ontologyDefinition.linkTypes[linkDefinition.id] = linkDefinition;
@@ -1 +1 @@
1
- {"version":3,"file":"defineLink.js","names":["invariant","ontologyDefinition","defaultTypeClasses","kind","name","defineLink","linkDefinition","foreignKey","toMany","object","properties","find","prop","apiName","manyForeignKeyProperty","undefined","process","env","NODE_ENV","id","typesMatch","type","one","primaryKeys","linkTypes"],"sources":["defineLink.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 invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nimport type { LinkTypeDefinition, SharedPropertyType } from \"./types.js\";\n\nconst defaultTypeClasses: SharedPropertyType[\"typeClasses\"] = [{\n kind: \"render_hint\",\n name: \"SELECTABLE\",\n}, { kind: \"render_hint\", name: \"SORTABLE\" }];\n\nexport function defineLink(\n linkDefinition: LinkTypeDefinition,\n): LinkTypeDefinition {\n if (\"one\" in linkDefinition) {\n const foreignKey = linkDefinition.toMany.object.properties?.find(prop =>\n prop.apiName === linkDefinition.manyForeignKeyProperty\n );\n invariant(\n foreignKey !== undefined,\n `Foreign key ${linkDefinition.manyForeignKeyProperty} on link ${linkDefinition.id} does not exist on object ${linkDefinition.toMany.object.apiName}}`,\n );\n\n const typesMatch =\n foreignKey.type === linkDefinition.one.object.properties?.find(prop =>\n prop.apiName === linkDefinition.one.object.primaryKeys[0]\n )?.type;\n invariant(\n typesMatch,\n `Link ${linkDefinition.id} has type mismatch between the one side's primary key and the foreign key on the many side`,\n );\n }\n ontologyDefinition.linkTypes[linkDefinition.id] = linkDefinition;\n return linkDefinition;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,kBAAkB,QAAQ,qBAAqB;AAGxD,MAAMC,kBAAqD,GAAG,CAAC;EAC7DC,IAAI,EAAE,aAAa;EACnBC,IAAI,EAAE;AACR,CAAC,EAAE;EAAED,IAAI,EAAE,aAAa;EAAEC,IAAI,EAAE;AAAW,CAAC,CAAC;AAE7C,OAAO,SAASC,UAAUA,CACxBC,cAAkC,EACd;EACpB,IAAI,KAAK,IAAIA,cAAc,EAAE;IAC3B,MAAMC,UAAU,GAAGD,cAAc,CAACE,MAAM,CAACC,MAAM,CAACC,UAAU,EAAEC,IAAI,CAACC,IAAI,IACnEA,IAAI,CAACC,OAAO,KAAKP,cAAc,CAACQ,sBAClC,CAAC;IACD,EACEP,UAAU,KAAKQ,SAAS,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1BlB,SAAS,QAEP,eAAeM,cAAc,CAACQ,sBAAsB,YAAYR,cAAc,CAACa,EAAE,6BAA6Bb,cAAc,CAACE,MAAM,CAACC,MAAM,CAACI,OAAO,GAAG,IAFvJb,SAAS;IAKT,MAAMoB,UAAU,GACdb,UAAU,CAACc,IAAI,KAAKf,cAAc,CAACgB,GAAG,CAACb,MAAM,CAACC,UAAU,EAAEC,IAAI,CAACC,IAAI,IACjEA,IAAI,CAACC,OAAO,KAAKP,cAAc,CAACgB,GAAG,CAACb,MAAM,CAACc,WAAW,CAAC,CAAC,CAC1D,CAAC,EAAEF,IAAI;IACT,CACED,UAAU,GAAAJ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADZlB,SAAS,QAEP,QAAQM,cAAc,CAACa,EAAE,4FAA4F,IAFvHnB,SAAS;EAIX;EACAC,kBAAkB,CAACuB,SAAS,CAAClB,cAAc,CAACa,EAAE,CAAC,GAAGb,cAAc;EAChE,OAAOA,cAAc;AACvB","ignoreList":[]}
1
+ {"version":3,"file":"defineLink.js","names":["invariant","ontologyDefinition","defaultTypeClasses","kind","name","defineLink","linkDefinition","foreignKey","toMany","object","properties","find","prop","apiName","manyForeignKeyProperty","undefined","process","env","NODE_ENV","id","typesMatch","type","one","primaryKeyPropertyApiName","linkTypes"],"sources":["defineLink.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 invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nimport type { LinkTypeDefinition, SharedPropertyType } from \"./types.js\";\n\nconst defaultTypeClasses: SharedPropertyType[\"typeClasses\"] = [{\n kind: \"render_hint\",\n name: \"SELECTABLE\",\n}, { kind: \"render_hint\", name: \"SORTABLE\" }];\n\nexport function defineLink(\n linkDefinition: LinkTypeDefinition,\n): LinkTypeDefinition {\n if (\"one\" in linkDefinition) {\n const foreignKey = linkDefinition.toMany.object.properties?.find(prop =>\n prop.apiName === linkDefinition.manyForeignKeyProperty\n );\n invariant(\n foreignKey !== undefined,\n `Foreign key ${linkDefinition.manyForeignKeyProperty} on link ${linkDefinition.id} does not exist on object ${linkDefinition.toMany.object.apiName}}`,\n );\n\n const typesMatch =\n foreignKey.type === linkDefinition.one.object.properties?.find(prop =>\n prop.apiName === linkDefinition.one.object.primaryKeyPropertyApiName\n )?.type;\n invariant(\n typesMatch,\n `Link ${linkDefinition.id} has type mismatch between the one side's primary key and the foreign key on the many side`,\n );\n }\n ontologyDefinition.linkTypes[linkDefinition.id] = linkDefinition;\n return linkDefinition;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,kBAAkB,QAAQ,qBAAqB;AAGxD,MAAMC,kBAAqD,GAAG,CAAC;EAC7DC,IAAI,EAAE,aAAa;EACnBC,IAAI,EAAE;AACR,CAAC,EAAE;EAAED,IAAI,EAAE,aAAa;EAAEC,IAAI,EAAE;AAAW,CAAC,CAAC;AAE7C,OAAO,SAASC,UAAUA,CACxBC,cAAkC,EACd;EACpB,IAAI,KAAK,IAAIA,cAAc,EAAE;IAC3B,MAAMC,UAAU,GAAGD,cAAc,CAACE,MAAM,CAACC,MAAM,CAACC,UAAU,EAAEC,IAAI,CAACC,IAAI,IACnEA,IAAI,CAACC,OAAO,KAAKP,cAAc,CAACQ,sBAClC,CAAC;IACD,EACEP,UAAU,KAAKQ,SAAS,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1BlB,SAAS,QAEP,eAAeM,cAAc,CAACQ,sBAAsB,YAAYR,cAAc,CAACa,EAAE,6BAA6Bb,cAAc,CAACE,MAAM,CAACC,MAAM,CAACI,OAAO,GAAG,IAFvJb,SAAS;IAKT,MAAMoB,UAAU,GACdb,UAAU,CAACc,IAAI,KAAKf,cAAc,CAACgB,GAAG,CAACb,MAAM,CAACC,UAAU,EAAEC,IAAI,CAACC,IAAI,IACjEA,IAAI,CAACC,OAAO,KAAKP,cAAc,CAACgB,GAAG,CAACb,MAAM,CAACc,yBAC7C,CAAC,EAAEF,IAAI;IACT,CACED,UAAU,GAAAJ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADZlB,SAAS,QAEP,QAAQM,cAAc,CAACa,EAAE,4FAA4F,IAFvHnB,SAAS;EAIX;EACAC,kBAAkB,CAACuB,SAAS,CAAClB,cAAc,CAACa,EAAE,CAAC,GAAGb,cAAc;EAChE,OAAOA,cAAc;AACvB","ignoreList":[]}
@@ -25,13 +25,11 @@ export function defineObject(objectDef) {
25
25
  throw new Error(`Object type with apiName ${objectDef.apiName} is already defined`);
26
26
  }
27
27
  !propertyApiNames.includes(objectDef.titlePropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`) : invariant(false) : void 0;
28
- !(objectDef.primaryKeys.length !== 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `${objectDef.apiName} does not have any primary keys, objects must have at least one primary key`) : invariant(false) : void 0;
29
- const nonExistentPrimaryKeys = objectDef.primaryKeys.filter(primaryKey => !objectDef.properties?.map(val => val.apiName).includes(primaryKey));
30
- !(nonExistentPrimaryKeys.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key properties ${nonExistentPrimaryKeys} do not exist on object ${objectDef.apiName}`) : invariant(false) : void 0;
28
+ !propertyApiNames.includes(objectDef.primaryKeyPropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`) : invariant(false) : void 0;
31
29
  const retentionPeriod = objectDef.datasource?.retentionPeriod;
32
30
  !(retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Retention period "${retentionPeriod}" on object "${objectDef.apiName}" is not a valid ISO 8601 duration string`) : invariant(false) : void 0;
33
31
  !(objectDef.properties ?? []).filter(p => p.apiName === objectDef.titlePropertyApiName).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Title property ${objectDef.titlePropertyApiName} must be a primitive type`) : invariant(false) : void 0;
34
- !(objectDef.properties ?? []).filter(p => objectDef.primaryKeys.includes(p.apiName)).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key properties ${objectDef.primaryKeys} can only be primitive types`) : invariant(false) : void 0;
32
+ !(objectDef.properties ?? []).filter(p => p.apiName === objectDef.primaryKeyPropertyApiName).every(p => !isExotic(p.type)) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`) : invariant(false) : void 0;
35
33
  objectDef.implementsInterfaces?.forEach(interfaceImpl => {
36
34
  const nonExistentInterfaceProperties = interfaceImpl.propertyMapping.map(val => val.interfaceProperty).filter(interfaceProperty => interfaceImpl.implements.propertiesV2[interfaceProperty] === undefined).map(interfaceProp => ({
37
35
  type: "invalid",
@@ -1 +1 @@
1
- {"version":3,"file":"defineObject.js","names":["invariant","namespace","ontologyDefinition","ISO_8601_DURATION","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","objectTypes","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeys","length","nonExistentPrimaryKeys","filter","primaryKey","retentionPeriod","datasource","test","p","every","isExotic","type","implementsInterfaces","forEach","interfaceImpl","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","implements","propertiesV2","interfaceProp","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","nonNameSpacedApiName","validateInterfaceImplProperty","baseValidations","entries","extendsValidations","extendsInterfaces","flatMap","interfaceApiName","interfaceTypes","allFailedValidations","concat","formatValidationErrors","join","error","spt","mappedObjectProp","object","objProp","find","prop"],"sources":["defineObject.ts"],"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\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport type {\n InterfacePropertyType,\n ObjectType,\n PropertyTypeType,\n PropertyTypeTypeExotic,\n SharedPropertyType,\n} from \"./types.js\";\n\n// From https://stackoverflow.com/a/79288714\nconst ISO_8601_DURATION =\n /^P(?!$)(?:(?:((?:\\d+Y)|(?:\\d+(?:\\.|,)\\d+Y$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+D)|(?:\\d+(?:\\.|,)\\d+D$))?(T((?:\\d+H)|(?:\\d+(?:\\.|,)\\d+H$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+S)|(?:\\d+(?:\\.|,)\\d+S$))?)?)|(?:\\d+(?:(?:\\.|,)\\d+)?W))$/;\n\nexport function defineObject(objectDef: ObjectType): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (ontologyDefinition.objectTypes[apiName] !== undefined) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n objectDef.primaryKeys.length !== 0,\n `${objectDef.apiName} does not have any primary keys, objects must have at least one primary key`,\n );\n const nonExistentPrimaryKeys = objectDef.primaryKeys.filter(primaryKey =>\n !objectDef.properties?.map(val => val.apiName).includes(primaryKey)\n );\n invariant(\n nonExistentPrimaryKeys.length === 0,\n `Primary key properties ${nonExistentPrimaryKeys} do not exist on object ${objectDef.apiName}`,\n );\n const retentionPeriod = (objectDef.datasource as any)?.retentionPeriod;\n invariant(\n retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod),\n `Retention period \"${retentionPeriod}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 duration string`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.titlePropertyApiName\n ).every(p => !isExotic(p.type)),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n objectDef.primaryKeys.includes(p.apiName)\n ).every(p => !isExotic(p.type)),\n `Primary key properties ${objectDef.primaryKeys} can only be primitive types`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n interfaceImpl.implements.propertiesV2[interfaceProperty]\n === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [mapping.interfaceProperty, mapping.mapsTo],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, InterfacePropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1].sharedPropertyType,\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${interfaceImpl.implements.apiName}.${\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const baseValidations = Object.entries(\n interfaceImpl.implements.propertiesV2,\n )\n .map<ValidationResult>(validateProperty);\n const extendsValidations = interfaceImpl.implements.extendsInterfaces\n .flatMap(interfaceApiName =>\n Object.entries(\n ontologyDefinition.interfaceTypes[interfaceApiName].propertiesV2,\n ).map(validateProperty)\n );\n\n const allFailedValidations = baseValidations.concat(\n extendsValidations,\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n });\n\n ontologyDefinition.objectTypes[apiName] = { ...objectDef, apiName: apiName };\n return { ...objectDef, apiName: apiName };\n}\n\nexport function isExotic(\n type: PropertyTypeType,\n): type is PropertyTypeTypeExotic {\n if (typeof type === \"string\") {\n return [\"geopoint\", \"geoshape\", \"mediaReference\", \"geotimeSeries\"].includes(\n type,\n );\n } else if (typeof type === \"object\" && type != null) {\n return type.type === \"marking\" || type.type === \"struct\";\n }\n return false;\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectType,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (spt.type !== objProp?.type) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AASnE;AACA,MAAMC,iBAAiB,GACrB,+OAA+O;AAEjP,OAAO,SAASC,YAAYA,CAACC,SAAqB,EAAc;EAC9D,MAAMC,OAAO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B,OAAO;MACLA,IAAI,EAAE,SAAS;MACfU,MAAM,EACJ,mGAAmGsB,GAAG,CAACxD,OAAO,qBAAqByD,gBAAgB;IACvJ,CAAC;EACH;EAEA,OAAO;IAAEjC,IAAI,EAAE;EAAQ,CAAC;AAC1B","ignoreList":[]}
1
+ {"version":3,"file":"defineObject.js","names":["invariant","namespace","ontologyDefinition","ISO_8601_DURATION","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","objectTypes","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeyPropertyApiName","retentionPeriod","datasource","test","filter","p","every","isExotic","type","implementsInterfaces","forEach","interfaceImpl","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","implements","propertiesV2","interfaceProp","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","sharedPropertyType","nonNameSpacedApiName","validateInterfaceImplProperty","baseValidations","entries","extendsValidations","extendsInterfaces","flatMap","interfaceApiName","interfaceTypes","allFailedValidations","concat","length","formatValidationErrors","join","error","spt","mappedObjectProp","object","objProp","find","prop"],"sources":["defineObject.ts"],"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\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport type {\n InterfacePropertyType,\n ObjectType,\n PropertyTypeType,\n PropertyTypeTypeExotic,\n SharedPropertyType,\n} from \"./types.js\";\n\n// From https://stackoverflow.com/a/79288714\nconst ISO_8601_DURATION =\n /^P(?!$)(?:(?:((?:\\d+Y)|(?:\\d+(?:\\.|,)\\d+Y$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+D)|(?:\\d+(?:\\.|,)\\d+D$))?(T((?:\\d+H)|(?:\\d+(?:\\.|,)\\d+H$))?((?:\\d+M)|(?:\\d+(?:\\.|,)\\d+M$))?((?:\\d+S)|(?:\\d+(?:\\.|,)\\d+S$))?)?)|(?:\\d+(?:(?:\\.|,)\\d+)?W))$/;\n\nexport function defineObject(objectDef: ObjectType): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (ontologyDefinition.objectTypes[apiName] !== undefined) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n propertyApiNames.includes(objectDef.primaryKeyPropertyApiName),\n `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`,\n );\n const retentionPeriod = (objectDef.datasource as any)?.retentionPeriod;\n invariant(\n retentionPeriod === undefined || ISO_8601_DURATION.test(retentionPeriod),\n `Retention period \"${retentionPeriod}\" on object \"${objectDef.apiName}\" is not a valid ISO 8601 duration string`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.titlePropertyApiName\n ).every(p => !isExotic(p.type)),\n `Title property ${objectDef.titlePropertyApiName} must be a primitive type`,\n );\n invariant(\n (objectDef.properties ?? []).filter(p =>\n p.apiName === objectDef.primaryKeyPropertyApiName\n ).every(p => !isExotic(p.type)),\n `Primary key properties ${objectDef.primaryKeyPropertyApiName} can only be primitive types`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n interfaceImpl.implements.propertiesV2[interfaceProperty]\n === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [mapping.interfaceProperty, mapping.mapsTo],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, InterfacePropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1].sharedPropertyType,\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${interfaceImpl.implements.apiName}.${\n interfaceProp[1].sharedPropertyType.nonNameSpacedApiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const baseValidations = Object.entries(\n interfaceImpl.implements.propertiesV2,\n )\n .map<ValidationResult>(validateProperty);\n const extendsValidations = interfaceImpl.implements.extendsInterfaces\n .flatMap(interfaceApiName =>\n Object.entries(\n ontologyDefinition.interfaceTypes[interfaceApiName].propertiesV2,\n ).map(validateProperty)\n );\n\n const allFailedValidations = baseValidations.concat(\n extendsValidations,\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n });\n\n ontologyDefinition.objectTypes[apiName] = { ...objectDef, apiName: apiName };\n return { ...objectDef, apiName: apiName };\n}\n\nexport function isExotic(\n type: PropertyTypeType,\n): type is PropertyTypeTypeExotic {\n if (typeof type === \"string\") {\n return [\"geopoint\", \"geoshape\", \"mediaReference\", \"geotimeSeries\"].includes(\n type,\n );\n } else if (typeof type === \"object\" && type != null) {\n return type.type === \"marking\" || type.type === \"struct\";\n }\n return false;\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectType,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (spt.type !== objProp?.type) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AASnE;AACA,MAAMC,iBAAiB,GACrB,+OAA+O;AAEjP,OAAO,SAASC,YAAYA,CAACC,SAAqB,EAAc;EAC9D,MAAMC,OAAO,GAAGL,SAAS,GAAGI,SAAS,CAACC,OAAO;EAC7C,MAAMC,gBAAgB,GAAG,CAACF,SAAS,CAACG,UAAU,IAAI,EAAE,EAAEC,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACJ,OAAO,CAAC;EAC7E,IAAIJ,kBAAkB,CAACS,WAAW,CAACL,OAAO,CAAC,KAAKM,SAAS,EAAE;IACzD,MAAM,IAAIC,KAAK,CACb,4BAA4BR,SAAS,CAACC,OAAO,qBAC/C,CAAC;EACH;EACA,CACEC,gBAAgB,CAACO,QAAQ,CAACT,SAAS,CAACU,oBAAoB,CAAC,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD3DlB,SAAS,QAEP,kBAAkBK,SAAS,CAACU,oBAAoB,6BAA6BV,SAAS,CAACC,OAAO,EAA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