@osdk/maker 0.12.0-beta.9 → 0.12.0
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 +172 -0
- package/README.md +1 -1
- package/build/browser/api/defineAction.js +373 -89
- package/build/browser/api/defineAction.js.map +1 -1
- package/build/browser/api/defineOntology.js +78 -33
- 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 +4289 -2577
- 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 +537 -131
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +78 -9
- package/build/esm/api/defineAction.js +373 -89
- package/build/esm/api/defineAction.js.map +1 -1
- package/build/esm/api/defineOntology.js +78 -33
- 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 +4289 -2577
- 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 +1 -0
- package/build/types/api/defineAction.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 +69 -7
- 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 +6 -6
|
@@ -18,8 +18,8 @@ import { consola } from "consola";
|
|
|
18
18
|
import invariant from "tiny-invariant";
|
|
19
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,
|
|
@@ -91,32 +91,18 @@ export function defineCreateInterfaceObjectAction(interfaceType, objectType, val
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
export function defineCreateObjectAction(def) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(def.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
type: extractActionParameterType(def.objectType.properties?.[id]),
|
|
105
|
-
validation: def.parameterLevelValidations?.[id] !== undefined ? {
|
|
106
|
-
...def.parameterLevelValidations?.[id],
|
|
107
|
-
allowedValues: def.parameterLevelValidations?.[id].allowedValues ?? extractAllowedValuesFromType(def.objectType.properties?.[id].type),
|
|
108
|
-
required: def.parameterLevelValidations?.[id].required ?? true
|
|
109
|
-
} : {
|
|
110
|
-
required: def.objectType.properties?.[id].array ?? false ? {
|
|
111
|
-
listLength: def.objectType.properties?.[id].nullability?.noEmptyCollections ? {
|
|
112
|
-
min: 1
|
|
113
|
-
} : {}
|
|
114
|
-
} : def.objectType.properties?.[id].nullability?.noNulls ?? true,
|
|
115
|
-
allowedValues: extractAllowedValuesFromType(def.objectType.properties?.[id].type)
|
|
116
|
-
}
|
|
117
|
-
}));
|
|
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);
|
|
101
|
+
}
|
|
102
|
+
const parameters = createParameters(def, parameterNames, true);
|
|
103
|
+
const mappings = Object.fromEntries(Object.entries(def.nonParameterMappings ?? {}).map(([id, value]) => [id, convertMappingValue(value)]));
|
|
118
104
|
return defineAction({
|
|
119
|
-
apiName:
|
|
105
|
+
apiName: actionApiName,
|
|
120
106
|
displayName: def.displayName ?? `Create ${def.objectType.displayName}`,
|
|
121
107
|
parameters: parameters,
|
|
122
108
|
status: def.status ?? "active",
|
|
@@ -130,16 +116,35 @@ export function defineCreateObjectAction(def) {
|
|
|
130
116
|
type: "addObjectRule",
|
|
131
117
|
addObjectRule: {
|
|
132
118
|
objectTypeId: def.objectType.apiName,
|
|
133
|
-
propertyValues:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
119
|
+
propertyValues: {
|
|
120
|
+
...Object.fromEntries(propertyParameters.map(p => [p, {
|
|
121
|
+
type: "parameterId",
|
|
122
|
+
parameterId: p
|
|
123
|
+
}])),
|
|
124
|
+
...mappings
|
|
125
|
+
},
|
|
137
126
|
structFieldValues: {}
|
|
138
127
|
}
|
|
139
128
|
}],
|
|
129
|
+
parameterOrdering: def.parameterOrdering ?? createDefaultParameterOrdering(def, parameters),
|
|
140
130
|
...(def.actionLevelValidation ? {
|
|
141
131
|
validation: [convertValidationRule(def.actionLevelValidation)]
|
|
142
|
-
} : {})
|
|
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
|
+
})
|
|
143
148
|
});
|
|
144
149
|
}
|
|
145
150
|
export function defineModifyInterfaceObjectAction(interfaceType, objectType, validation) {
|
|
@@ -185,7 +190,7 @@ export function defineModifyInterfaceObjectAction(interfaceType, objectType, val
|
|
|
185
190
|
required: prop.sharedPropertyType.array ?? false ? {
|
|
186
191
|
listLength: {}
|
|
187
192
|
} : prop.required,
|
|
188
|
-
allowedValues:
|
|
193
|
+
allowedValues: extractAllowedValuesFromPropertyType(prop.sharedPropertyType.type)
|
|
189
194
|
}
|
|
190
195
|
}))],
|
|
191
196
|
status: interfaceType.status.type !== "deprecated" ? interfaceType.status.type : interfaceType.status,
|
|
@@ -211,58 +216,47 @@ export function defineModifyInterfaceObjectAction(interfaceType, objectType, val
|
|
|
211
216
|
});
|
|
212
217
|
}
|
|
213
218
|
export function defineModifyObjectAction(def) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
(def.
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
displayName: def.objectType.properties?.[id].displayName ?? convertToDisplayName(id),
|
|
224
|
-
type: extractActionParameterType(def.objectType.properties?.[id]),
|
|
225
|
-
validation: def.parameterLevelValidations?.[id] !== undefined ? {
|
|
226
|
-
...def.parameterLevelValidations?.[id],
|
|
227
|
-
allowedValues: def.parameterLevelValidations?.[id].allowedValues ?? extractAllowedValuesFromType(def.objectType.properties?.[id].type),
|
|
228
|
-
required: def.parameterLevelValidations?.[id].required ?? false
|
|
229
|
-
} : {
|
|
230
|
-
required: def.objectType.properties?.[id].array ?? false ? {
|
|
231
|
-
listLength: def.objectType.properties?.[id].nullability?.noEmptyCollections ? {
|
|
232
|
-
min: 1
|
|
233
|
-
} : {}
|
|
234
|
-
} : def.objectType.properties?.[id].nullability?.noNulls ?? false,
|
|
235
|
-
allowedValues: extractAllowedValuesFromType(def.objectType.properties?.[id].type)
|
|
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];
|
|
236
228
|
}
|
|
237
|
-
|
|
229
|
+
validateParameterOrdering(def.parameterOrdering, parameterNames, actionApiName);
|
|
230
|
+
}
|
|
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
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
const mappings = Object.fromEntries(Object.entries(def.nonParameterMappings ?? {}).map(([id, value]) => [id, convertMappingValue(value)]));
|
|
238
244
|
return defineAction({
|
|
239
|
-
apiName:
|
|
245
|
+
apiName: actionApiName,
|
|
240
246
|
displayName: def.displayName ?? `Modify ${def.objectType.displayName}`,
|
|
241
|
-
parameters:
|
|
242
|
-
id: "objectToModifyParameter",
|
|
243
|
-
displayName: "Modify object",
|
|
244
|
-
type: {
|
|
245
|
-
type: "objectReference",
|
|
246
|
-
objectReference: {
|
|
247
|
-
objectTypeId: def.objectType.apiName
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
validation: {
|
|
251
|
-
allowedValues: {
|
|
252
|
-
type: "objectQuery"
|
|
253
|
-
},
|
|
254
|
-
required: true
|
|
255
|
-
}
|
|
256
|
-
}, ...parameters],
|
|
247
|
+
parameters: parameters,
|
|
257
248
|
status: def.status ?? "active",
|
|
258
249
|
rules: [{
|
|
259
250
|
type: "modifyObjectRule",
|
|
260
251
|
modifyObjectRule: {
|
|
261
|
-
objectToModify:
|
|
262
|
-
propertyValues:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
252
|
+
objectToModify: MODIFY_OBJECT_PARAMETER,
|
|
253
|
+
propertyValues: {
|
|
254
|
+
...Object.fromEntries(propertyParameters.map(p => [p, {
|
|
255
|
+
type: "parameterId",
|
|
256
|
+
parameterId: p
|
|
257
|
+
}])),
|
|
258
|
+
...mappings
|
|
259
|
+
},
|
|
266
260
|
structFieldValues: {}
|
|
267
261
|
}
|
|
268
262
|
}],
|
|
@@ -272,9 +266,25 @@ export function defineModifyObjectAction(def) {
|
|
|
272
266
|
affectedLinkTypes: [],
|
|
273
267
|
typeGroups: []
|
|
274
268
|
},
|
|
269
|
+
parameterOrdering: def.parameterOrdering ?? createDefaultParameterOrdering(def, parameters, MODIFY_OBJECT_PARAMETER),
|
|
275
270
|
...(def.actionLevelValidation ? {
|
|
276
271
|
validation: [convertValidationRule(def.actionLevelValidation)]
|
|
277
|
-
} : {})
|
|
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
|
+
})
|
|
278
288
|
});
|
|
279
289
|
}
|
|
280
290
|
export function defineDeleteObjectAction(def) {
|
|
@@ -315,6 +325,78 @@ export function defineDeleteObjectAction(def) {
|
|
|
315
325
|
} : {})
|
|
316
326
|
});
|
|
317
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",
|
|
359
|
+
rules: [{
|
|
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: {}
|
|
371
|
+
}
|
|
372
|
+
}],
|
|
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
|
+
})
|
|
398
|
+
});
|
|
399
|
+
}
|
|
318
400
|
export function defineAction(actionDef) {
|
|
319
401
|
const apiName = namespace + actionDef.apiName;
|
|
320
402
|
const parameterIds = (actionDef.parameters ?? []).map(p => p.id);
|
|
@@ -349,15 +431,90 @@ export function defineAction(actionDef) {
|
|
|
349
431
|
},
|
|
350
432
|
__type: OntologyEntityTypeEnum.ACTION_TYPE
|
|
351
433
|
};
|
|
352
|
-
|
|
434
|
+
validateActionConfiguration(fullAction);
|
|
353
435
|
updateOntology(fullAction);
|
|
354
436
|
return fullAction;
|
|
355
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
|
+
}
|
|
356
513
|
function referencedParameterIds(actionDef) {
|
|
357
514
|
const parameterIds = new Set();
|
|
358
515
|
|
|
359
516
|
// section definitions
|
|
360
|
-
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));
|
|
361
518
|
|
|
362
519
|
// form content ordering
|
|
363
520
|
(actionDef.formContentOrdering ?? []).forEach(item => {
|
|
@@ -416,7 +573,80 @@ function referencedParameterIds(actionDef) {
|
|
|
416
573
|
});
|
|
417
574
|
return parameterIds;
|
|
418
575
|
}
|
|
419
|
-
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) {
|
|
420
650
|
switch (type) {
|
|
421
651
|
case "boolean":
|
|
422
652
|
return {
|
|
@@ -499,6 +729,10 @@ function extractAllowedValuesFromType(type) {
|
|
|
499
729
|
} : {
|
|
500
730
|
type: "mandatoryMarking"
|
|
501
731
|
};
|
|
732
|
+
case "string":
|
|
733
|
+
return {
|
|
734
|
+
type: "text"
|
|
735
|
+
};
|
|
502
736
|
case "struct":
|
|
503
737
|
throw new Error("Structs are not supported yet");
|
|
504
738
|
default:
|
|
@@ -513,6 +747,8 @@ function extractActionParameterType(pt) {
|
|
|
513
747
|
switch (typeType.type) {
|
|
514
748
|
case "marking":
|
|
515
749
|
return maybeAddList("marking", pt);
|
|
750
|
+
case "string":
|
|
751
|
+
return maybeAddList("string", pt);
|
|
516
752
|
case "struct":
|
|
517
753
|
throw new Error("Structs are not supported yet");
|
|
518
754
|
default:
|
|
@@ -560,16 +796,22 @@ function convertValidationRule(actionValidation) {
|
|
|
560
796
|
}
|
|
561
797
|
};
|
|
562
798
|
}
|
|
563
|
-
function
|
|
799
|
+
function validateActionConfiguration(action) {
|
|
564
800
|
const seenParameterIds = new Set();
|
|
565
|
-
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 => {
|
|
566
807
|
param.validation.conditionalOverrides?.forEach(override => {
|
|
567
|
-
|
|
808
|
+
validateParameterCondition(override.condition, param.id, seenParameterIds, action.parameters);
|
|
568
809
|
});
|
|
810
|
+
validateParameterPrefill(param.id, seenParameterIds, action.parameters, param.defaultValue);
|
|
569
811
|
seenParameterIds.add(param.id);
|
|
570
812
|
});
|
|
571
813
|
}
|
|
572
|
-
function
|
|
814
|
+
function validateParameterCondition(condition, currentParameterId, seenParameterIds, parameters) {
|
|
573
815
|
switch (condition.type) {
|
|
574
816
|
case "parameter":
|
|
575
817
|
const overrideParamId = condition.parameterId;
|
|
@@ -580,12 +822,12 @@ function validateActionCondition(condition, currentParameterId, seenParameterIds
|
|
|
580
822
|
case "and":
|
|
581
823
|
// this will not catch the niche edge case where users use the full syntax for unions
|
|
582
824
|
if ("conditions" in condition) {
|
|
583
|
-
condition.conditions.forEach(c =>
|
|
825
|
+
condition.conditions.forEach(c => validateParameterCondition(c, currentParameterId, seenParameterIds, parameters));
|
|
584
826
|
}
|
|
585
827
|
break;
|
|
586
828
|
case "or":
|
|
587
829
|
if ("conditions" in condition) {
|
|
588
|
-
condition.conditions.forEach(c =>
|
|
830
|
+
condition.conditions.forEach(c => validateParameterCondition(c, currentParameterId, seenParameterIds, parameters));
|
|
589
831
|
}
|
|
590
832
|
break;
|
|
591
833
|
case "comparison":
|
|
@@ -600,4 +842,46 @@ function validateActionCondition(condition, currentParameterId, seenParameterIds
|
|
|
600
842
|
throw new Error(`Unknown condition type on parameter ${currentParameterId}`);
|
|
601
843
|
}
|
|
602
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
|
+
}
|
|
603
887
|
//# sourceMappingURL=defineAction.js.map
|