@osdk/maker 0.12.0-beta.8 → 0.12.0-rc.23
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 +138 -0
- package/README.md +88 -62
- package/build/browser/api/defineAction.js +403 -106
- package/build/browser/api/defineAction.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.js +6 -2
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.js +80 -35
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/defineSpt.js.map +1 -1
- package/build/browser/api/ontologyUtils.js +80 -0
- package/build/browser/api/ontologyUtils.js.map +1 -1
- package/build/browser/api/overall.test.js +4741 -2358
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/types.js +2 -0
- package/build/browser/api/types.js.map +1 -1
- package/build/browser/cli/main.js +2 -10
- package/build/browser/cli/main.js.map +1 -1
- package/build/browser/index.js +5 -4
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +575 -153
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +98 -20
- package/build/esm/api/defineAction.js +403 -106
- package/build/esm/api/defineAction.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.js +6 -2
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.js +80 -35
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/defineSpt.js.map +1 -1
- package/build/esm/api/ontologyUtils.js +80 -0
- package/build/esm/api/ontologyUtils.js.map +1 -1
- package/build/esm/api/overall.test.js +4741 -2358
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/types.js +2 -0
- package/build/esm/api/types.js.map +1 -1
- package/build/esm/cli/main.js +2 -10
- package/build/esm/cli/main.js.map +1 -1
- package/build/esm/index.js +5 -4
- package/build/esm/index.js.map +1 -1
- package/build/types/api/defineAction.d.ts +7 -6
- package/build/types/api/defineAction.d.ts.map +1 -1
- package/build/types/api/defineObject.d.ts +2 -2
- package/build/types/api/defineObject.d.ts.map +1 -1
- package/build/types/api/defineOntology.d.ts +3 -2
- package/build/types/api/defineOntology.d.ts.map +1 -1
- package/build/types/api/defineSpt.d.ts +2 -2
- package/build/types/api/defineSpt.d.ts.map +1 -1
- package/build/types/api/ontologyUtils.d.ts +5 -2
- package/build/types/api/ontologyUtils.d.ts.map +1 -1
- package/build/types/api/types.d.ts +83 -12
- package/build/types/api/types.d.ts.map +1 -1
- package/build/types/cli/main.d.ts.map +1 -1
- package/build/types/index.d.ts +6 -5
- package/build/types/index.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
|
|
17
17
|
import { consola } from "consola";
|
|
18
18
|
import invariant from "tiny-invariant";
|
|
19
|
-
import { getAllInterfaceProperties } from "./defineObject.js";
|
|
19
|
+
import { convertToDisplayName, getAllInterfaceProperties } from "./defineObject.js";
|
|
20
20
|
import { namespace, ontologyDefinition, updateOntology } from "./defineOntology.js";
|
|
21
|
-
import { convertConditionDefinition } from "./ontologyUtils.js";
|
|
22
|
-
import { OntologyEntityTypeEnum } from "./types.js";
|
|
21
|
+
import { convertConditionDefinition, convertMappingValue } from "./ontologyUtils.js";
|
|
22
|
+
import { CREATE_OR_MODIFY_OBJECT_PARAMETER, MODIFY_OBJECT_PARAMETER, OntologyEntityTypeEnum } from "./types.js";
|
|
23
23
|
export function defineCreateInterfaceObjectAction(interfaceType, objectType, validation) {
|
|
24
24
|
const allProperties = Object.entries(getAllInterfaceProperties(interfaceType)).filter(([_, prop]) => !isStruct(prop.sharedPropertyType.type));
|
|
25
25
|
if (allProperties.length !== Object.entries(getAllInterfaceProperties(interfaceType)).length) {
|
|
@@ -64,7 +64,7 @@ export function defineCreateInterfaceObjectAction(interfaceType, objectType, val
|
|
|
64
64
|
required: prop.sharedPropertyType.array ?? false ? {
|
|
65
65
|
listLength: {}
|
|
66
66
|
} : prop.required,
|
|
67
|
-
allowedValues:
|
|
67
|
+
allowedValues: extractAllowedValuesFromPropertyType(prop.sharedPropertyType.type)
|
|
68
68
|
}
|
|
69
69
|
}))],
|
|
70
70
|
status: interfaceType.status.type !== "deprecated" ? interfaceType.status.type : interfaceType.status,
|
|
@@ -90,49 +90,61 @@ export function defineCreateInterfaceObjectAction(interfaceType, objectType, val
|
|
|
90
90
|
} : {})
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
export function defineCreateObjectAction(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
export function defineCreateObjectAction(def) {
|
|
94
|
+
validateActionParameters(def);
|
|
95
|
+
const propertyParameters = Object.keys(def.objectType.properties ?? {}).filter(id => !Object.keys(def.nonParameterMappings ?? {}).includes(id) && !def.excludedProperties?.includes(id) && !isStruct(def.objectType.properties?.[id].type));
|
|
96
|
+
const parameterNames = new Set(propertyParameters);
|
|
97
|
+
Object.keys(def.parameterConfiguration ?? {}).forEach(param => parameterNames.add(param));
|
|
98
|
+
const actionApiName = def.apiName ?? `create-object-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`;
|
|
99
|
+
if (def.parameterOrdering) {
|
|
100
|
+
validateParameterOrdering(def.parameterOrdering, parameterNames, actionApiName);
|
|
97
101
|
}
|
|
102
|
+
const parameters = createParameters(def, parameterNames, true);
|
|
103
|
+
const mappings = Object.fromEntries(Object.entries(def.nonParameterMappings ?? {}).map(([id, value]) => [id, convertMappingValue(value)]));
|
|
98
104
|
return defineAction({
|
|
99
|
-
apiName:
|
|
100
|
-
displayName: `Create ${objectType.displayName}`,
|
|
101
|
-
parameters:
|
|
102
|
-
|
|
103
|
-
displayName: prop.displayName,
|
|
104
|
-
type: extractActionParameterType(prop),
|
|
105
|
-
typeClasses: prop.typeClasses ?? [],
|
|
106
|
-
validation: {
|
|
107
|
-
required: prop.array ?? false ? {
|
|
108
|
-
listLength: prop.nullability?.noEmptyCollections ? {
|
|
109
|
-
min: 1
|
|
110
|
-
} : {}
|
|
111
|
-
} : prop.nullability?.noNulls ?? true,
|
|
112
|
-
allowedValues: extractAllowedValuesFromType(prop.type)
|
|
113
|
-
}
|
|
114
|
-
}))],
|
|
115
|
-
status: "active",
|
|
105
|
+
apiName: actionApiName,
|
|
106
|
+
displayName: def.displayName ?? `Create ${def.objectType.displayName}`,
|
|
107
|
+
parameters: parameters,
|
|
108
|
+
status: def.status ?? "active",
|
|
116
109
|
entities: {
|
|
117
110
|
affectedInterfaceTypes: [],
|
|
118
|
-
affectedObjectTypes: [objectType.apiName],
|
|
111
|
+
affectedObjectTypes: [def.objectType.apiName],
|
|
119
112
|
affectedLinkTypes: [],
|
|
120
113
|
typeGroups: []
|
|
121
114
|
},
|
|
122
115
|
rules: [{
|
|
123
116
|
type: "addObjectRule",
|
|
124
117
|
addObjectRule: {
|
|
125
|
-
objectTypeId: objectType.apiName,
|
|
126
|
-
propertyValues:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
objectTypeId: def.objectType.apiName,
|
|
119
|
+
propertyValues: {
|
|
120
|
+
...Object.fromEntries(propertyParameters.map(p => [p, {
|
|
121
|
+
type: "parameterId",
|
|
122
|
+
parameterId: p
|
|
123
|
+
}])),
|
|
124
|
+
...mappings
|
|
125
|
+
},
|
|
130
126
|
structFieldValues: {}
|
|
131
127
|
}
|
|
132
128
|
}],
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
parameterOrdering: def.parameterOrdering ?? createDefaultParameterOrdering(def, parameters),
|
|
130
|
+
...(def.actionLevelValidation ? {
|
|
131
|
+
validation: [convertValidationRule(def.actionLevelValidation)]
|
|
132
|
+
} : {}),
|
|
133
|
+
...(def.defaultFormat && {
|
|
134
|
+
defaultFormat: def.defaultFormat
|
|
135
|
+
}),
|
|
136
|
+
...(def.enableLayoutSwitch && {
|
|
137
|
+
enableLayoutSwitch: def.enableLayoutSwitch
|
|
138
|
+
}),
|
|
139
|
+
...(def.displayAndFormat && {
|
|
140
|
+
displayAndFormat: def.displayAndFormat
|
|
141
|
+
}),
|
|
142
|
+
...(def.sections && {
|
|
143
|
+
sections: Object.fromEntries(def.sections.map(section => [section.id, section]))
|
|
144
|
+
}),
|
|
145
|
+
...(def.submissionMetadata && {
|
|
146
|
+
submissionMetadata: def.submissionMetadata
|
|
147
|
+
})
|
|
136
148
|
});
|
|
137
149
|
}
|
|
138
150
|
export function defineModifyInterfaceObjectAction(interfaceType, objectType, validation) {
|
|
@@ -178,7 +190,7 @@ export function defineModifyInterfaceObjectAction(interfaceType, objectType, val
|
|
|
178
190
|
required: prop.sharedPropertyType.array ?? false ? {
|
|
179
191
|
listLength: {}
|
|
180
192
|
} : prop.required,
|
|
181
|
-
allowedValues:
|
|
193
|
+
allowedValues: extractAllowedValuesFromPropertyType(prop.sharedPropertyType.type)
|
|
182
194
|
}
|
|
183
195
|
}))],
|
|
184
196
|
status: interfaceType.status.type !== "deprecated" ? interfaceType.status.type : interfaceType.status,
|
|
@@ -203,78 +215,89 @@ export function defineModifyInterfaceObjectAction(interfaceType, objectType, val
|
|
|
203
215
|
} : {})
|
|
204
216
|
});
|
|
205
217
|
}
|
|
206
|
-
export function defineModifyObjectAction(
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
218
|
+
export function defineModifyObjectAction(def) {
|
|
219
|
+
validateActionParameters(def);
|
|
220
|
+
const propertyParameters = Object.keys(def.objectType.properties ?? {}).filter(id => !Object.keys(def.nonParameterMappings ?? {}).includes(id) && !def.excludedProperties?.includes(id) && !isStruct(def.objectType.properties?.[id].type) && id !== def.objectType.primaryKeyPropertyApiName);
|
|
221
|
+
const parameterNames = new Set(propertyParameters);
|
|
222
|
+
Object.keys(def.parameterConfiguration ?? {}).forEach(param => parameterNames.add(param));
|
|
223
|
+
parameterNames.add(MODIFY_OBJECT_PARAMETER);
|
|
224
|
+
const actionApiName = def.apiName ?? `modify-object-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`;
|
|
225
|
+
if (def.parameterOrdering) {
|
|
226
|
+
if (!def.parameterOrdering.includes(MODIFY_OBJECT_PARAMETER)) {
|
|
227
|
+
def.parameterOrdering = [MODIFY_OBJECT_PARAMETER, ...def.parameterOrdering];
|
|
228
|
+
}
|
|
229
|
+
validateParameterOrdering(def.parameterOrdering, parameterNames, actionApiName);
|
|
211
230
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
objectReference: {
|
|
221
|
-
objectTypeId: objectType.apiName
|
|
231
|
+
const parameters = createParameters(def, parameterNames, false);
|
|
232
|
+
parameters.forEach(p => {
|
|
233
|
+
if (p.id !== MODIFY_OBJECT_PARAMETER && p.defaultValue === undefined) {
|
|
234
|
+
p.defaultValue = {
|
|
235
|
+
type: "objectParameterPropertyValue",
|
|
236
|
+
objectParameterPropertyValue: {
|
|
237
|
+
parameterId: MODIFY_OBJECT_PARAMETER,
|
|
238
|
+
propertyTypeId: p.id
|
|
222
239
|
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
const mappings = Object.fromEntries(Object.entries(def.nonParameterMappings ?? {}).map(([id, value]) => [id, convertMappingValue(value)]));
|
|
244
|
+
return defineAction({
|
|
245
|
+
apiName: actionApiName,
|
|
246
|
+
displayName: def.displayName ?? `Modify ${def.objectType.displayName}`,
|
|
247
|
+
parameters: parameters,
|
|
248
|
+
status: def.status ?? "active",
|
|
249
|
+
rules: [{
|
|
250
|
+
type: "modifyObjectRule",
|
|
251
|
+
modifyObjectRule: {
|
|
252
|
+
objectToModify: MODIFY_OBJECT_PARAMETER,
|
|
253
|
+
propertyValues: {
|
|
254
|
+
...Object.fromEntries(propertyParameters.map(p => [p, {
|
|
255
|
+
type: "parameterId",
|
|
256
|
+
parameterId: p
|
|
257
|
+
}])),
|
|
258
|
+
...mappings
|
|
227
259
|
},
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
}, ...filteredProperties.map(prop => ({
|
|
231
|
-
id: prop.apiName,
|
|
232
|
-
displayName: prop.displayName,
|
|
233
|
-
type: extractActionParameterType(prop),
|
|
234
|
-
typeClasses: prop.typeClasses ?? [],
|
|
235
|
-
validation: {
|
|
236
|
-
required: prop.array ?? false ? {
|
|
237
|
-
listLength: prop.nullability?.noEmptyCollections ? {
|
|
238
|
-
min: 1
|
|
239
|
-
} : {}
|
|
240
|
-
} : prop.nullability?.noNulls ?? false,
|
|
241
|
-
allowedValues: extractAllowedValuesFromType(prop.type)
|
|
260
|
+
structFieldValues: {}
|
|
242
261
|
}
|
|
243
|
-
}
|
|
244
|
-
status: "active",
|
|
262
|
+
}],
|
|
245
263
|
entities: {
|
|
246
264
|
affectedInterfaceTypes: [],
|
|
247
|
-
affectedObjectTypes: [objectType.apiName],
|
|
265
|
+
affectedObjectTypes: [def.objectType.apiName],
|
|
248
266
|
affectedLinkTypes: [],
|
|
249
267
|
typeGroups: []
|
|
250
268
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
269
|
+
parameterOrdering: def.parameterOrdering ?? createDefaultParameterOrdering(def, parameters, MODIFY_OBJECT_PARAMETER),
|
|
270
|
+
...(def.actionLevelValidation ? {
|
|
271
|
+
validation: [convertValidationRule(def.actionLevelValidation)]
|
|
272
|
+
} : {}),
|
|
273
|
+
...(def.defaultFormat && {
|
|
274
|
+
defaultFormat: def.defaultFormat
|
|
275
|
+
}),
|
|
276
|
+
...(def.enableLayoutSwitch && {
|
|
277
|
+
enableLayoutSwitch: def.enableLayoutSwitch
|
|
278
|
+
}),
|
|
279
|
+
...(def.displayAndFormat && {
|
|
280
|
+
displayAndFormat: def.displayAndFormat
|
|
281
|
+
}),
|
|
282
|
+
...(def.sections && {
|
|
283
|
+
sections: Object.fromEntries(def.sections.map(section => [section.id, section]))
|
|
284
|
+
}),
|
|
285
|
+
...(def.submissionMetadata && {
|
|
286
|
+
submissionMetadata: def.submissionMetadata
|
|
287
|
+
})
|
|
265
288
|
});
|
|
266
289
|
}
|
|
267
|
-
export function defineDeleteObjectAction(
|
|
290
|
+
export function defineDeleteObjectAction(def) {
|
|
268
291
|
return defineAction({
|
|
269
|
-
apiName: `delete-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
|
|
270
|
-
displayName: `Delete ${objectType.displayName}`,
|
|
292
|
+
apiName: def.apiName ?? `delete-object-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`,
|
|
293
|
+
displayName: def.displayName ?? `Delete ${def.objectType.displayName}`,
|
|
271
294
|
parameters: [{
|
|
272
295
|
id: "objectToDeleteParameter",
|
|
273
296
|
displayName: "Delete object",
|
|
274
297
|
type: {
|
|
275
298
|
type: "objectReference",
|
|
276
299
|
objectReference: {
|
|
277
|
-
objectTypeId: objectType.apiName
|
|
300
|
+
objectTypeId: def.objectType.apiName
|
|
278
301
|
}
|
|
279
302
|
},
|
|
280
303
|
validation: {
|
|
@@ -284,22 +307,94 @@ export function defineDeleteObjectAction(objectType, validation) {
|
|
|
284
307
|
}
|
|
285
308
|
}
|
|
286
309
|
}],
|
|
287
|
-
status: "active",
|
|
310
|
+
status: def.status ?? "active",
|
|
311
|
+
rules: [{
|
|
312
|
+
type: "deleteObjectRule",
|
|
313
|
+
deleteObjectRule: {
|
|
314
|
+
objectToDelete: "objectToDeleteParameter"
|
|
315
|
+
}
|
|
316
|
+
}],
|
|
288
317
|
entities: {
|
|
289
318
|
affectedInterfaceTypes: [],
|
|
290
|
-
affectedObjectTypes: [objectType.apiName],
|
|
319
|
+
affectedObjectTypes: [def.objectType.apiName],
|
|
291
320
|
affectedLinkTypes: [],
|
|
292
321
|
typeGroups: []
|
|
293
322
|
},
|
|
323
|
+
...(def.actionLevelValidation ? {
|
|
324
|
+
validation: [convertValidationRule(def.actionLevelValidation)]
|
|
325
|
+
} : {})
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
export function defineCreateOrModifyObjectAction(def) {
|
|
329
|
+
validateActionParameters(def);
|
|
330
|
+
const propertyParameters = Object.keys(def.objectType.properties ?? {}).filter(id => !Object.keys(def.nonParameterMappings ?? {}).includes(id) && !def.excludedProperties?.includes(id) && !isStruct(def.objectType.properties?.[id].type) && id !== def.objectType.primaryKeyPropertyApiName);
|
|
331
|
+
const parameterNames = new Set(propertyParameters);
|
|
332
|
+
Object.keys(def.parameterConfiguration ?? {}).forEach(param => parameterNames.add(param));
|
|
333
|
+
parameterNames.add(CREATE_OR_MODIFY_OBJECT_PARAMETER);
|
|
334
|
+
const actionApiName = def.apiName ?? `create-or-modify-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`;
|
|
335
|
+
if (def.parameterOrdering) {
|
|
336
|
+
if (!def.parameterOrdering.includes(CREATE_OR_MODIFY_OBJECT_PARAMETER)) {
|
|
337
|
+
def.parameterOrdering = [CREATE_OR_MODIFY_OBJECT_PARAMETER, ...def.parameterOrdering];
|
|
338
|
+
}
|
|
339
|
+
validateParameterOrdering(def.parameterOrdering, parameterNames, actionApiName);
|
|
340
|
+
}
|
|
341
|
+
const parameters = createParameters(def, parameterNames, false);
|
|
342
|
+
parameters.forEach(p => {
|
|
343
|
+
if (p.id !== CREATE_OR_MODIFY_OBJECT_PARAMETER && p.defaultValue === undefined) {
|
|
344
|
+
p.defaultValue = {
|
|
345
|
+
type: "objectParameterPropertyValue",
|
|
346
|
+
objectParameterPropertyValue: {
|
|
347
|
+
parameterId: CREATE_OR_MODIFY_OBJECT_PARAMETER,
|
|
348
|
+
propertyTypeId: p.id
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
const mappings = Object.fromEntries(Object.entries(def.nonParameterMappings ?? {}).map(([id, value]) => [id, convertMappingValue(value)]));
|
|
354
|
+
return defineAction({
|
|
355
|
+
apiName: actionApiName,
|
|
356
|
+
displayName: def.displayName ?? `Create or Modify ${def.objectType.displayName}`,
|
|
357
|
+
parameters: parameters,
|
|
358
|
+
status: def.status ?? "active",
|
|
294
359
|
rules: [{
|
|
295
|
-
type: "
|
|
296
|
-
|
|
297
|
-
|
|
360
|
+
type: "addOrModifyObjectRuleV2",
|
|
361
|
+
addOrModifyObjectRuleV2: {
|
|
362
|
+
objectToModify: CREATE_OR_MODIFY_OBJECT_PARAMETER,
|
|
363
|
+
propertyValues: {
|
|
364
|
+
...Object.fromEntries(propertyParameters.map(p => [p, {
|
|
365
|
+
type: "parameterId",
|
|
366
|
+
parameterId: p
|
|
367
|
+
}])),
|
|
368
|
+
...mappings
|
|
369
|
+
},
|
|
370
|
+
structFieldValues: {}
|
|
298
371
|
}
|
|
299
372
|
}],
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
373
|
+
entities: {
|
|
374
|
+
affectedInterfaceTypes: [],
|
|
375
|
+
affectedObjectTypes: [def.objectType.apiName],
|
|
376
|
+
affectedLinkTypes: [],
|
|
377
|
+
typeGroups: []
|
|
378
|
+
},
|
|
379
|
+
parameterOrdering: def.parameterOrdering ?? createDefaultParameterOrdering(def, parameters, CREATE_OR_MODIFY_OBJECT_PARAMETER),
|
|
380
|
+
...(def.actionLevelValidation ? {
|
|
381
|
+
validation: [convertValidationRule(def.actionLevelValidation)]
|
|
382
|
+
} : {}),
|
|
383
|
+
...(def.defaultFormat && {
|
|
384
|
+
defaultFormat: def.defaultFormat
|
|
385
|
+
}),
|
|
386
|
+
...(def.enableLayoutSwitch && {
|
|
387
|
+
enableLayoutSwitch: def.enableLayoutSwitch
|
|
388
|
+
}),
|
|
389
|
+
...(def.displayAndFormat && {
|
|
390
|
+
displayAndFormat: def.displayAndFormat
|
|
391
|
+
}),
|
|
392
|
+
...(def.sections && {
|
|
393
|
+
sections: Object.fromEntries(def.sections.map(section => [section.id, section]))
|
|
394
|
+
}),
|
|
395
|
+
...(def.submissionMetadata && {
|
|
396
|
+
submissionMetadata: def.submissionMetadata
|
|
397
|
+
})
|
|
303
398
|
});
|
|
304
399
|
}
|
|
305
400
|
export function defineAction(actionDef) {
|
|
@@ -336,15 +431,90 @@ export function defineAction(actionDef) {
|
|
|
336
431
|
},
|
|
337
432
|
__type: OntologyEntityTypeEnum.ACTION_TYPE
|
|
338
433
|
};
|
|
339
|
-
|
|
434
|
+
validateActionConfiguration(fullAction);
|
|
340
435
|
updateOntology(fullAction);
|
|
341
436
|
return fullAction;
|
|
342
437
|
}
|
|
438
|
+
function createParameters(def, parameterSet, defaultRequired) {
|
|
439
|
+
const targetParam = [];
|
|
440
|
+
parameterSet.forEach(name => {
|
|
441
|
+
if (name === MODIFY_OBJECT_PARAMETER) {
|
|
442
|
+
targetParam.push({
|
|
443
|
+
id: MODIFY_OBJECT_PARAMETER,
|
|
444
|
+
displayName: def.parameterConfiguration?.[name]?.displayName ?? "Modify object",
|
|
445
|
+
type: {
|
|
446
|
+
type: "objectReference",
|
|
447
|
+
objectReference: {
|
|
448
|
+
objectTypeId: def.objectType.apiName
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
validation: {
|
|
452
|
+
...def.parameterConfiguration?.[name],
|
|
453
|
+
allowedValues: {
|
|
454
|
+
type: "objectQuery"
|
|
455
|
+
},
|
|
456
|
+
required: def.parameterConfiguration?.[name]?.required ?? true
|
|
457
|
+
},
|
|
458
|
+
defaultValue: def.parameterConfiguration?.[name]?.defaultValue,
|
|
459
|
+
description: def.parameterConfiguration?.[name]?.description
|
|
460
|
+
});
|
|
461
|
+
parameterSet.delete(MODIFY_OBJECT_PARAMETER);
|
|
462
|
+
}
|
|
463
|
+
if (name === CREATE_OR_MODIFY_OBJECT_PARAMETER) {
|
|
464
|
+
targetParam.push({
|
|
465
|
+
id: CREATE_OR_MODIFY_OBJECT_PARAMETER,
|
|
466
|
+
displayName: def.parameterConfiguration?.[name]?.displayName ?? "Create or modify object",
|
|
467
|
+
type: {
|
|
468
|
+
type: "objectReference",
|
|
469
|
+
objectReference: {
|
|
470
|
+
objectTypeId: def.objectType.apiName,
|
|
471
|
+
maybeCreateObjectOption: !def.primaryKeyOption || def.primaryKeyOption === "autoGenerated" ? {
|
|
472
|
+
type: "autoGenerated",
|
|
473
|
+
autoGenerated: {}
|
|
474
|
+
} : {
|
|
475
|
+
type: "userInput",
|
|
476
|
+
userInput: {}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
validation: {
|
|
481
|
+
...def.parameterConfiguration?.[name],
|
|
482
|
+
allowedValues: {
|
|
483
|
+
type: "objectQuery"
|
|
484
|
+
},
|
|
485
|
+
required: def.parameterConfiguration?.[name]?.required ?? true
|
|
486
|
+
},
|
|
487
|
+
defaultValue: def.parameterConfiguration?.[name]?.defaultValue,
|
|
488
|
+
description: def.parameterConfiguration?.[name]?.description
|
|
489
|
+
});
|
|
490
|
+
parameterSet.delete(CREATE_OR_MODIFY_OBJECT_PARAMETER);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
return [...targetParam, ...Array.from(parameterSet).map(id => ({
|
|
494
|
+
id,
|
|
495
|
+
displayName: def.parameterConfiguration?.[id]?.displayName ?? def.objectType.properties?.[id]?.displayName ?? convertToDisplayName(id),
|
|
496
|
+
type: def.parameterConfiguration?.[id]?.customParameterType ?? extractActionParameterType(def.objectType.properties?.[id]),
|
|
497
|
+
validation: def.parameterConfiguration?.[id] !== undefined ? {
|
|
498
|
+
...def.parameterConfiguration?.[id],
|
|
499
|
+
allowedValues: def.parameterConfiguration?.[id].allowedValues ?? (def.parameterConfiguration?.[id].customParameterType ? extractAllowedValuesFromActionParameterType(def.parameterConfiguration?.[id].customParameterType) : extractAllowedValuesFromPropertyType(def.objectType.properties?.[id].type)),
|
|
500
|
+
required: def.parameterConfiguration?.[id].required ?? defaultRequired
|
|
501
|
+
} : {
|
|
502
|
+
required: def.objectType.properties?.[id].array ?? false ? {
|
|
503
|
+
listLength: def.objectType.properties?.[id].nullability?.noEmptyCollections ? {
|
|
504
|
+
min: 1
|
|
505
|
+
} : {}
|
|
506
|
+
} : def.objectType.properties?.[id].nullability?.noNulls ?? defaultRequired,
|
|
507
|
+
allowedValues: extractAllowedValuesFromPropertyType(def.objectType.properties?.[id].type)
|
|
508
|
+
},
|
|
509
|
+
defaultValue: def.parameterConfiguration?.[id]?.defaultValue,
|
|
510
|
+
description: def.parameterConfiguration?.[id]?.description
|
|
511
|
+
}))];
|
|
512
|
+
}
|
|
343
513
|
function referencedParameterIds(actionDef) {
|
|
344
514
|
const parameterIds = new Set();
|
|
345
515
|
|
|
346
516
|
// section definitions
|
|
347
|
-
Object.values(actionDef.sections ?? {}).flatMap(p => p).forEach(pId => parameterIds.add(pId));
|
|
517
|
+
Object.values(actionDef.sections ?? {}).flatMap(p => p.parameters).forEach(pId => parameterIds.add(pId));
|
|
348
518
|
|
|
349
519
|
// form content ordering
|
|
350
520
|
(actionDef.formContentOrdering ?? []).forEach(item => {
|
|
@@ -403,7 +573,80 @@ function referencedParameterIds(actionDef) {
|
|
|
403
573
|
});
|
|
404
574
|
return parameterIds;
|
|
405
575
|
}
|
|
406
|
-
function
|
|
576
|
+
function extractAllowedValuesFromActionParameterType(type) {
|
|
577
|
+
if (typeof type === "object") {
|
|
578
|
+
switch (type.type) {
|
|
579
|
+
case "objectReference":
|
|
580
|
+
case "objectReferenceList":
|
|
581
|
+
return {
|
|
582
|
+
type: "objectQuery"
|
|
583
|
+
};
|
|
584
|
+
case "struct":
|
|
585
|
+
case "structList":
|
|
586
|
+
throw new Error("Structs are not supported yet");
|
|
587
|
+
default:
|
|
588
|
+
throw new Error(`Inferred allowed values for ${type.type} not yet supported. Please explicitly provide allowed values.`);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
switch (type) {
|
|
592
|
+
case "boolean":
|
|
593
|
+
case "booleanList":
|
|
594
|
+
return {
|
|
595
|
+
type: "boolean"
|
|
596
|
+
};
|
|
597
|
+
case "integer":
|
|
598
|
+
case "integerList":
|
|
599
|
+
case "decimal":
|
|
600
|
+
case "decimalList":
|
|
601
|
+
case "double":
|
|
602
|
+
case "doubleList":
|
|
603
|
+
case "long":
|
|
604
|
+
case "longList":
|
|
605
|
+
return {
|
|
606
|
+
type: "range"
|
|
607
|
+
};
|
|
608
|
+
case "timestamp":
|
|
609
|
+
case "timestampList":
|
|
610
|
+
case "date":
|
|
611
|
+
case "dateList":
|
|
612
|
+
return {
|
|
613
|
+
type: "datetime"
|
|
614
|
+
};
|
|
615
|
+
case "string":
|
|
616
|
+
case "stringList":
|
|
617
|
+
return {
|
|
618
|
+
type: "text"
|
|
619
|
+
};
|
|
620
|
+
case "geohash":
|
|
621
|
+
case "geohashList":
|
|
622
|
+
return {
|
|
623
|
+
type: "geohash"
|
|
624
|
+
};
|
|
625
|
+
case "geoshape":
|
|
626
|
+
case "geoshapeList":
|
|
627
|
+
return {
|
|
628
|
+
type: "geoshape"
|
|
629
|
+
};
|
|
630
|
+
case "mediaReference":
|
|
631
|
+
case "mediaReferenceList":
|
|
632
|
+
return {
|
|
633
|
+
type: "mediaReference"
|
|
634
|
+
};
|
|
635
|
+
case "geotimeSeriesReference":
|
|
636
|
+
case "geotimeSeriesReferenceList":
|
|
637
|
+
return {
|
|
638
|
+
type: "geotimeSeriesReference"
|
|
639
|
+
};
|
|
640
|
+
case "attachment":
|
|
641
|
+
case "attachmentList":
|
|
642
|
+
return {
|
|
643
|
+
type: "attachment"
|
|
644
|
+
};
|
|
645
|
+
default:
|
|
646
|
+
throw new Error(`Inferred allowed values for ${type} not yet supported. Please explicitly provide allowed values.`);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function extractAllowedValuesFromPropertyType(type) {
|
|
407
650
|
switch (type) {
|
|
408
651
|
case "boolean":
|
|
409
652
|
return {
|
|
@@ -486,6 +729,10 @@ function extractAllowedValuesFromType(type) {
|
|
|
486
729
|
} : {
|
|
487
730
|
type: "mandatoryMarking"
|
|
488
731
|
};
|
|
732
|
+
case "string":
|
|
733
|
+
return {
|
|
734
|
+
type: "text"
|
|
735
|
+
};
|
|
489
736
|
case "struct":
|
|
490
737
|
throw new Error("Structs are not supported yet");
|
|
491
738
|
default:
|
|
@@ -500,6 +747,8 @@ function extractActionParameterType(pt) {
|
|
|
500
747
|
switch (typeType.type) {
|
|
501
748
|
case "marking":
|
|
502
749
|
return maybeAddList("marking", pt);
|
|
750
|
+
case "string":
|
|
751
|
+
return maybeAddList("string", pt);
|
|
503
752
|
case "struct":
|
|
504
753
|
throw new Error("Structs are not supported yet");
|
|
505
754
|
default:
|
|
@@ -547,16 +796,22 @@ function convertValidationRule(actionValidation) {
|
|
|
547
796
|
}
|
|
548
797
|
};
|
|
549
798
|
}
|
|
550
|
-
function
|
|
799
|
+
function validateActionConfiguration(action) {
|
|
551
800
|
const seenParameterIds = new Set();
|
|
552
|
-
action.parameters?.
|
|
801
|
+
const parameterMap = action.parameters?.reduce((acc, param) => {
|
|
802
|
+
acc[param.id] = param;
|
|
803
|
+
return acc;
|
|
804
|
+
}, {}) ?? {};
|
|
805
|
+
const orderedParameters = action.parameterOrdering?.map(id => parameterMap[id]) ?? action.parameters;
|
|
806
|
+
orderedParameters?.forEach(param => {
|
|
553
807
|
param.validation.conditionalOverrides?.forEach(override => {
|
|
554
|
-
|
|
808
|
+
validateParameterCondition(override.condition, param.id, seenParameterIds, action.parameters);
|
|
555
809
|
});
|
|
810
|
+
validateParameterPrefill(param.id, seenParameterIds, action.parameters, param.defaultValue);
|
|
556
811
|
seenParameterIds.add(param.id);
|
|
557
812
|
});
|
|
558
813
|
}
|
|
559
|
-
function
|
|
814
|
+
function validateParameterCondition(condition, currentParameterId, seenParameterIds, parameters) {
|
|
560
815
|
switch (condition.type) {
|
|
561
816
|
case "parameter":
|
|
562
817
|
const overrideParamId = condition.parameterId;
|
|
@@ -567,12 +822,12 @@ function validateActionCondition(condition, currentParameterId, seenParameterIds
|
|
|
567
822
|
case "and":
|
|
568
823
|
// this will not catch the niche edge case where users use the full syntax for unions
|
|
569
824
|
if ("conditions" in condition) {
|
|
570
|
-
condition.conditions.forEach(c =>
|
|
825
|
+
condition.conditions.forEach(c => validateParameterCondition(c, currentParameterId, seenParameterIds, parameters));
|
|
571
826
|
}
|
|
572
827
|
break;
|
|
573
828
|
case "or":
|
|
574
829
|
if ("conditions" in condition) {
|
|
575
|
-
condition.conditions.forEach(c =>
|
|
830
|
+
condition.conditions.forEach(c => validateParameterCondition(c, currentParameterId, seenParameterIds, parameters));
|
|
576
831
|
}
|
|
577
832
|
break;
|
|
578
833
|
case "comparison":
|
|
@@ -587,4 +842,46 @@ function validateActionCondition(condition, currentParameterId, seenParameterIds
|
|
|
587
842
|
throw new Error(`Unknown condition type on parameter ${currentParameterId}`);
|
|
588
843
|
}
|
|
589
844
|
}
|
|
845
|
+
function validateParameterPrefill(currentParameterId, seenParameterIds, parameters, defaultValue) {
|
|
846
|
+
if (!defaultValue) return;
|
|
847
|
+
switch (defaultValue.type) {
|
|
848
|
+
case "objectParameterPropertyValue":
|
|
849
|
+
!parameters?.some(p => p.id === defaultValue.objectParameterPropertyValue.parameterId) ? process.env.NODE_ENV !== "production" ? invariant(false, `Default value for parameter ${currentParameterId} is referencing unknown parameter ${defaultValue.objectParameterPropertyValue.parameterId}`) : invariant(false) : void 0;
|
|
850
|
+
!seenParameterIds.has(defaultValue.objectParameterPropertyValue.parameterId) ? process.env.NODE_ENV !== "production" ? invariant(false, `Default value for parameter ${currentParameterId} is referencing later parameter ${defaultValue.objectParameterPropertyValue.parameterId}`) : invariant(false) : void 0;
|
|
851
|
+
break;
|
|
852
|
+
case "staticValue":
|
|
853
|
+
!(defaultValue.staticValue.type === parameters?.find(p => p.id === currentParameterId)?.type) ? process.env.NODE_ENV !== "production" ? invariant(false, `Default static value for parameter ${currentParameterId} does not match type`) : invariant(false) : void 0;
|
|
854
|
+
break;
|
|
855
|
+
case "staticObject":
|
|
856
|
+
case "interfaceParameterPropertyValue":
|
|
857
|
+
case "objectQueryPrefill":
|
|
858
|
+
case "objectQueryPropertyValue":
|
|
859
|
+
case "objectSetRidPrefill":
|
|
860
|
+
case "redacted":
|
|
861
|
+
break;
|
|
862
|
+
default:
|
|
863
|
+
throw new Error(`Unknown default value type for parameter ${currentParameterId}`);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function validateActionParameters(def) {
|
|
867
|
+
// validates that parameters either exist as object properties or have a type defined
|
|
868
|
+
[...Object.keys(def.parameterConfiguration ?? {})].forEach(id => {
|
|
869
|
+
!(def.objectType.properties?.[id] !== undefined || def.parameterConfiguration?.[id].customParameterType !== undefined || id === MODIFY_OBJECT_PARAMETER || id === CREATE_OR_MODIFY_OBJECT_PARAMETER) ? process.env.NODE_ENV !== "production" ? invariant(false, `Parameter ${id} does not exist as a property on ${def.objectType.apiName} and its type is not explicitly defined`) : invariant(false) : void 0;
|
|
870
|
+
});
|
|
871
|
+
[...Object.keys(def.nonParameterMappings ?? {}), ...(def.excludedProperties ?? [])].forEach(id => {
|
|
872
|
+
!(def.objectType.properties?.[id] !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Property ${id} does not exist as a property on ${def.objectType.apiName}`) : invariant(false) : void 0;
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Parameters with configurations will be ordered first in the order they were defined
|
|
877
|
+
// followed by the rest of the parameters in the order they were defined on the object type
|
|
878
|
+
function createDefaultParameterOrdering(def, parameters, priorityId) {
|
|
879
|
+
return [...(priorityId ? [priorityId] : []), ...Object.keys(def.parameterConfiguration ?? {}), ...Object.keys(def.objectType.properties ?? {}).filter(id => !def.parameterConfiguration?.[id] && parameters.some(p => p.id === id))];
|
|
880
|
+
}
|
|
881
|
+
function validateParameterOrdering(parameterOrdering, parameterSet, actionApiName) {
|
|
882
|
+
const orderingSet = new Set(parameterOrdering);
|
|
883
|
+
const missingParameters = [...parameterSet].filter(param => !orderingSet.has(param));
|
|
884
|
+
const extraneousParameters = parameterOrdering.filter(param => !parameterSet.has(param));
|
|
885
|
+
!(extraneousParameters.length === 0 && missingParameters.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `Action parameter ordering for ${actionApiName} does not match expected parameters. Extraneous parameters in ordering: {${extraneousParameters}}, Missing parameters in ordering: {${missingParameters}}`) : invariant(false) : void 0;
|
|
886
|
+
}
|
|
590
887
|
//# sourceMappingURL=defineAction.js.map
|