@osdk/maker 0.10.1 → 0.11.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -85
- package/README.md +748 -0
- package/build/browser/api/addDependency.js +40 -0
- package/build/browser/api/addDependency.js.map +1 -0
- package/build/browser/api/defineAction.js +74 -12
- package/build/browser/api/defineAction.js.map +1 -1
- package/build/browser/api/defineImportSpt.js +9 -9
- package/build/browser/api/defineImportSpt.js.map +1 -1
- package/build/browser/api/defineInterface.js +2 -13
- package/build/browser/api/defineInterface.js.map +1 -1
- package/build/browser/api/defineLink.js +38 -8
- package/build/browser/api/defineLink.js.map +1 -1
- package/build/browser/api/defineObject.js +10 -1
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.js +91 -176
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/defineSpt.js +3 -16
- package/build/browser/api/defineSpt.js.map +1 -1
- package/build/browser/api/overall.test.js +4454 -2559
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/propertyConversionUtils.js +271 -0
- package/build/browser/api/propertyConversionUtils.js.map +1 -0
- package/build/browser/api/types.js.map +1 -1
- package/build/browser/cli/main.js +23 -5
- package/build/browser/cli/main.js.map +1 -1
- package/build/browser/index.js +1 -0
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +515 -237
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +52 -13
- package/build/esm/api/addDependency.js +40 -0
- package/build/esm/api/addDependency.js.map +1 -0
- package/build/esm/api/defineAction.js +74 -12
- package/build/esm/api/defineAction.js.map +1 -1
- package/build/esm/api/defineImportSpt.js +9 -9
- package/build/esm/api/defineImportSpt.js.map +1 -1
- package/build/esm/api/defineInterface.js +2 -13
- package/build/esm/api/defineInterface.js.map +1 -1
- package/build/esm/api/defineLink.js +38 -8
- package/build/esm/api/defineLink.js.map +1 -1
- package/build/esm/api/defineObject.js +10 -1
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.js +91 -176
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/defineSpt.js +3 -16
- package/build/esm/api/defineSpt.js.map +1 -1
- package/build/esm/api/overall.test.js +4454 -2559
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/propertyConversionUtils.js +271 -0
- package/build/esm/api/propertyConversionUtils.js.map +1 -0
- package/build/esm/api/types.js.map +1 -1
- package/build/esm/cli/main.js +23 -5
- package/build/esm/cli/main.js.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/types/api/addDependency.d.ts +1 -0
- package/build/types/api/addDependency.d.ts.map +1 -0
- package/build/types/api/defineAction.d.ts +6 -6
- package/build/types/api/defineAction.d.ts.map +1 -1
- package/build/types/api/defineImportSpt.d.ts +1 -0
- package/build/types/api/defineImportSpt.d.ts.map +1 -1
- package/build/types/api/defineInterface.d.ts +1 -1
- package/build/types/api/defineLink.d.ts.map +1 -1
- package/build/types/api/defineObject.d.ts +2 -0
- package/build/types/api/defineObject.d.ts.map +1 -1
- package/build/types/api/defineOntology.d.ts +1 -1
- package/build/types/api/defineOntology.d.ts.map +1 -1
- package/build/types/api/defineSpt.d.ts.map +1 -1
- package/build/types/api/propertyConversionUtils.d.ts +24 -0
- package/build/types/api/propertyConversionUtils.d.ts.map +1 -0
- package/build/types/api/types.d.ts +43 -6
- 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 +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/package.json +7 -6
package/build/cjs/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var consola = require('consola');
|
|
6
|
+
var jiti = require('jiti');
|
|
6
7
|
var fs2 = require('fs/promises');
|
|
7
8
|
var path2 = require('path');
|
|
8
9
|
var invariant = require('tiny-invariant');
|
|
@@ -10,6 +11,7 @@ var yargs = require('yargs');
|
|
|
10
11
|
var helpers = require('yargs/helpers');
|
|
11
12
|
var fs = require('fs');
|
|
12
13
|
|
|
14
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
16
|
|
|
15
17
|
function _interopNamespace(e) {
|
|
@@ -60,6 +62,7 @@ function defineObject(objectDef) {
|
|
|
60
62
|
}
|
|
61
63
|
!propertyApiNames.includes(objectDef.titlePropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`) : invariant__default.default(false) : void 0;
|
|
62
64
|
!propertyApiNames.includes(objectDef.primaryKeyPropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Primary key property ${objectDef.primaryKeyPropertyApiName} does not exist on object ${objectDef.apiName}`) : invariant__default.default(false) : void 0;
|
|
65
|
+
!(objectDef.properties ?? []).filter((p) => p.apiName === objectDef.primaryKeyPropertyApiName).every((p) => !p.editOnly) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Primary key property ${objectDef.primaryKeyPropertyApiName} on object ${objectDef.apiName} cannot be edit-only`) : invariant__default.default(false) : void 0;
|
|
63
66
|
const retentionPeriod = objectDef.datasource?.retentionPeriod;
|
|
64
67
|
!(retentionPeriod === void 0 || ISO_8601_DURATION.test(retentionPeriod)) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Retention period "${retentionPeriod}" on object "${objectDef.apiName}" is not a valid ISO 8601 duration string`) : invariant__default.default(false) : void 0;
|
|
65
68
|
if (objectDef.status === "experimental") {
|
|
@@ -88,7 +91,7 @@ function defineObject(objectDef) {
|
|
|
88
91
|
};
|
|
89
92
|
};
|
|
90
93
|
const baseValidations = Object.entries(interfaceImpl.implements.propertiesV2).map(validateProperty);
|
|
91
|
-
const extendsValidations = interfaceImpl.implements.extendsInterfaces.flatMap((
|
|
94
|
+
const extendsValidations = interfaceImpl.implements.extendsInterfaces.flatMap((interfaceType) => Object.entries(interfaceType.propertiesV2).map(validateProperty));
|
|
92
95
|
const allFailedValidations = baseValidations.concat(extendsValidations, nonExistentInterfaceProperties).filter((val) => val.type === "invalid");
|
|
93
96
|
!(allFailedValidations.length === 0) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "\n" + allFailedValidations.map(formatValidationErrors).join("\n")) : invariant__default.default(false) : void 0;
|
|
94
97
|
interfaceImpl.propertyMapping = interfaceImpl.propertyMapping.map((mapping) => ({
|
|
@@ -134,10 +137,259 @@ function validateInterfaceImplProperty(spt, mappedObjectProp, object) {
|
|
|
134
137
|
type: "valid"
|
|
135
138
|
};
|
|
136
139
|
}
|
|
140
|
+
function convertToDisplayName(s) {
|
|
141
|
+
return s === void 0 || s == null ? "" : s.charAt(0).toUpperCase() + s.slice(1);
|
|
142
|
+
}
|
|
143
|
+
function convertToPluralDisplayName(s) {
|
|
144
|
+
return s === void 0 || s == null ? "" : s.endsWith("s") ? convertToDisplayName(s) : convertToDisplayName(s) + "s";
|
|
145
|
+
}
|
|
146
|
+
var defaultTypeClasses = [{
|
|
147
|
+
kind: "render_hint",
|
|
148
|
+
name: "SELECTABLE"
|
|
149
|
+
}, {
|
|
150
|
+
kind: "render_hint",
|
|
151
|
+
name: "SORTABLE"
|
|
152
|
+
}];
|
|
153
|
+
function shouldNotHaveRenderHints(type) {
|
|
154
|
+
return ["struct", "mediaReference", "geotimeSeries"].includes(getPropertyTypeName(type));
|
|
155
|
+
}
|
|
156
|
+
function hasRenderHints(typeClasses) {
|
|
157
|
+
return (typeClasses ?? []).some((tc) => tc.kind.toLowerCase() === "render_hint");
|
|
158
|
+
}
|
|
159
|
+
function getPropertyTypeName(type) {
|
|
160
|
+
return typeof type === "object" ? type.type : type;
|
|
161
|
+
}
|
|
162
|
+
function convertValueType(valueType) {
|
|
163
|
+
return {
|
|
164
|
+
apiName: valueType.apiName,
|
|
165
|
+
version: valueType.version
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function convertValueTypeDataConstraints(dataConstraints) {
|
|
169
|
+
if (dataConstraints.length === 0) {
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
const propertyTypeConstraints = dataConstraints.map((constraint) => ({
|
|
173
|
+
constraints: dataConstraintToPropertyTypeDataConstraint(constraint.constraint.constraint),
|
|
174
|
+
failureMessage: constraint.constraint.failureMessage
|
|
175
|
+
}));
|
|
176
|
+
return {
|
|
177
|
+
propertyTypeConstraints
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function dataConstraintToPropertyTypeDataConstraint(dc) {
|
|
181
|
+
switch (dc.type) {
|
|
182
|
+
case "array":
|
|
183
|
+
return {
|
|
184
|
+
...dc
|
|
185
|
+
};
|
|
186
|
+
case "boolean":
|
|
187
|
+
return {
|
|
188
|
+
...dc
|
|
189
|
+
};
|
|
190
|
+
case "binary":
|
|
191
|
+
throw new Error("Binary type constraints are not supported");
|
|
192
|
+
case "date":
|
|
193
|
+
return {
|
|
194
|
+
...dc
|
|
195
|
+
};
|
|
196
|
+
case "decimal":
|
|
197
|
+
return {
|
|
198
|
+
...dc
|
|
199
|
+
};
|
|
200
|
+
case "double":
|
|
201
|
+
return {
|
|
202
|
+
...dc
|
|
203
|
+
};
|
|
204
|
+
case "float":
|
|
205
|
+
return {
|
|
206
|
+
...dc
|
|
207
|
+
};
|
|
208
|
+
case "integer":
|
|
209
|
+
return {
|
|
210
|
+
...dc
|
|
211
|
+
};
|
|
212
|
+
case "long":
|
|
213
|
+
return {
|
|
214
|
+
...dc
|
|
215
|
+
};
|
|
216
|
+
case "map":
|
|
217
|
+
throw new Error("Map type constraints are not supported");
|
|
218
|
+
case "nullable":
|
|
219
|
+
throw new Error("Nullable constraints are not supported");
|
|
220
|
+
case "short":
|
|
221
|
+
return {
|
|
222
|
+
...dc
|
|
223
|
+
};
|
|
224
|
+
case "string":
|
|
225
|
+
return {
|
|
226
|
+
...dc
|
|
227
|
+
};
|
|
228
|
+
case "struct":
|
|
229
|
+
return {
|
|
230
|
+
type: "struct",
|
|
231
|
+
struct: {
|
|
232
|
+
elementConstraints: Object.fromEntries(Object.entries(dc.struct.elementConstraints).map(([field, constraint]) => [field, convertDataConstraintToDataConstraints(constraint)]))
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
case "structV2":
|
|
236
|
+
throw new Error("StructV2 constraints are not supported");
|
|
237
|
+
case "timestamp":
|
|
238
|
+
return {
|
|
239
|
+
...dc
|
|
240
|
+
};
|
|
241
|
+
default:
|
|
242
|
+
throw new Error(`Unknown DataConstraint type: ${dc.type}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function convertDataConstraintToDataConstraints(dc) {
|
|
246
|
+
return {
|
|
247
|
+
propertyTypeConstraints: [{
|
|
248
|
+
constraints: dataConstraintToPropertyTypeDataConstraint(dc)
|
|
249
|
+
// known limitation: structs don't carry field-level data constraint failure messages
|
|
250
|
+
}]
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function convertNullabilityToDataConstraint(prop) {
|
|
254
|
+
if (typeof prop.type === "object" && prop.type.type === "marking") {
|
|
255
|
+
if (prop.nullability === void 0) {
|
|
256
|
+
return {
|
|
257
|
+
propertyTypeConstraints: [],
|
|
258
|
+
nullability: void 0,
|
|
259
|
+
nullabilityV2: {
|
|
260
|
+
noEmptyCollections: true,
|
|
261
|
+
noNulls: true
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
!prop.nullability?.noNulls ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Marking property type has noNulls set to false, marking properties must not be nullable") : invariant__default.default(false) : void 0;
|
|
266
|
+
return {
|
|
267
|
+
propertyTypeConstraints: [],
|
|
268
|
+
nullability: void 0,
|
|
269
|
+
nullabilityV2: prop.nullability
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return prop.nullability === void 0 ? void 0 : {
|
|
273
|
+
propertyTypeConstraints: [],
|
|
274
|
+
nullability: void 0,
|
|
275
|
+
nullabilityV2: prop.nullability
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function convertType(type) {
|
|
279
|
+
switch (true) {
|
|
280
|
+
case (typeof type === "object" && "markingType" in type):
|
|
281
|
+
return {
|
|
282
|
+
"type": "marking",
|
|
283
|
+
marking: {
|
|
284
|
+
markingType: type.markingType
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
case (typeof type === "object" && "structDefinition" in type):
|
|
288
|
+
const structFields = new Array();
|
|
289
|
+
for (const key in type.structDefinition) {
|
|
290
|
+
const fieldTypeDefinition = type.structDefinition[key];
|
|
291
|
+
let field;
|
|
292
|
+
if (typeof fieldTypeDefinition === "string") {
|
|
293
|
+
field = {
|
|
294
|
+
apiName: key,
|
|
295
|
+
displayMetadata: {
|
|
296
|
+
displayName: key,
|
|
297
|
+
description: void 0
|
|
298
|
+
},
|
|
299
|
+
typeClasses: [],
|
|
300
|
+
aliases: [],
|
|
301
|
+
fieldType: convertType(fieldTypeDefinition)
|
|
302
|
+
};
|
|
303
|
+
} else {
|
|
304
|
+
if ("fieldType" in fieldTypeDefinition) {
|
|
305
|
+
field = {
|
|
306
|
+
...fieldTypeDefinition,
|
|
307
|
+
apiName: key,
|
|
308
|
+
fieldType: convertType(fieldTypeDefinition.fieldType),
|
|
309
|
+
typeClasses: fieldTypeDefinition.typeClasses ?? [],
|
|
310
|
+
aliases: fieldTypeDefinition.aliases ?? []
|
|
311
|
+
};
|
|
312
|
+
} else {
|
|
313
|
+
field = {
|
|
314
|
+
apiName: key,
|
|
315
|
+
displayMetadata: {
|
|
316
|
+
displayName: key,
|
|
317
|
+
description: void 0
|
|
318
|
+
},
|
|
319
|
+
typeClasses: [],
|
|
320
|
+
aliases: [],
|
|
321
|
+
fieldType: convertType(fieldTypeDefinition)
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
structFields.push(field);
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
type: "struct",
|
|
329
|
+
struct: {
|
|
330
|
+
structFields
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
case (typeof type === "object" && "isLongText" in type):
|
|
334
|
+
return {
|
|
335
|
+
"type": "string",
|
|
336
|
+
"string": {
|
|
337
|
+
analyzerOverride: void 0,
|
|
338
|
+
enableAsciiFolding: void 0,
|
|
339
|
+
isLongText: type.isLongText,
|
|
340
|
+
supportsEfficientLeadingWildcard: type.supportsEfficientLeadingWildcard,
|
|
341
|
+
supportsExactMatching: type.supportsExactMatching
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
case type === "geopoint":
|
|
345
|
+
return {
|
|
346
|
+
type: "geohash",
|
|
347
|
+
geohash: {}
|
|
348
|
+
};
|
|
349
|
+
case type === "decimal":
|
|
350
|
+
return {
|
|
351
|
+
type,
|
|
352
|
+
[type]: {
|
|
353
|
+
precision: void 0,
|
|
354
|
+
scale: void 0
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
case type === "string":
|
|
358
|
+
return {
|
|
359
|
+
type,
|
|
360
|
+
[type]: {
|
|
361
|
+
analyzerOverride: void 0,
|
|
362
|
+
enableAsciiFolding: void 0,
|
|
363
|
+
isLongText: false,
|
|
364
|
+
supportsEfficientLeadingWildcard: false,
|
|
365
|
+
supportsExactMatching: true
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
case type === "mediaReference":
|
|
369
|
+
return {
|
|
370
|
+
type,
|
|
371
|
+
mediaReference: {}
|
|
372
|
+
};
|
|
373
|
+
case type === "geotimeSeries":
|
|
374
|
+
return {
|
|
375
|
+
type: "geotimeSeriesReference",
|
|
376
|
+
geotimeSeriesReference: {}
|
|
377
|
+
};
|
|
378
|
+
default:
|
|
379
|
+
return distributeTypeHelper(type);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function distributeTypeHelper(type) {
|
|
383
|
+
return {
|
|
384
|
+
type,
|
|
385
|
+
[type]: {}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
137
388
|
|
|
138
389
|
// src/api/defineOntology.ts
|
|
139
390
|
var ontologyDefinition;
|
|
140
391
|
var importedTypes;
|
|
392
|
+
var dependencies;
|
|
141
393
|
var namespace;
|
|
142
394
|
function updateOntology(entity) {
|
|
143
395
|
if (entity.__type !== OntologyEntityTypeEnum.VALUE_TYPE) {
|
|
@@ -149,8 +401,9 @@ function updateOntology(entity) {
|
|
|
149
401
|
}
|
|
150
402
|
ontologyDefinition[OntologyEntityTypeEnum.VALUE_TYPE][entity.apiName].push(entity);
|
|
151
403
|
}
|
|
152
|
-
async function defineOntology(ns, body, outputDir) {
|
|
404
|
+
async function defineOntology(ns, body, outputDir, dependencyFile) {
|
|
153
405
|
namespace = ns;
|
|
406
|
+
dependencies = {};
|
|
154
407
|
ontologyDefinition = {
|
|
155
408
|
OBJECT_TYPE: {},
|
|
156
409
|
ACTION_TYPE: {},
|
|
@@ -173,7 +426,12 @@ async function defineOntology(ns, body, outputDir) {
|
|
|
173
426
|
console.error("Unexpected error while processing the body of the ontology", e);
|
|
174
427
|
throw e;
|
|
175
428
|
}
|
|
176
|
-
|
|
429
|
+
if (outputDir) {
|
|
430
|
+
writeStaticObjects(outputDir);
|
|
431
|
+
}
|
|
432
|
+
if (dependencyFile) {
|
|
433
|
+
writeDependencyFile(dependencyFile);
|
|
434
|
+
}
|
|
177
435
|
return {
|
|
178
436
|
ontology: convertToWireOntologyIr(ontologyDefinition),
|
|
179
437
|
valueType: convertOntologyToValueTypeIr(ontologyDefinition)
|
|
@@ -230,11 +488,11 @@ export const ${entityFileNameBase}: ${entityTypeName} = wrapWithProxy(${entityFi
|
|
|
230
488
|
entityModuleNames.push(entityFileNameBase);
|
|
231
489
|
});
|
|
232
490
|
for (const entityModuleName of entityModuleNames) {
|
|
233
|
-
topLevelExportStatements.push(`export { ${entityModuleName} } from
|
|
491
|
+
topLevelExportStatements.push(`export { ${entityModuleName} } from "./codegen/${typeDirName}/${entityModuleName}.js";`);
|
|
234
492
|
}
|
|
235
493
|
});
|
|
236
494
|
if (topLevelExportStatements.length > 0) {
|
|
237
|
-
const mainIndexContent = topLevelExportStatements.join("\n") + "\n";
|
|
495
|
+
const mainIndexContent = dependencyInjectionString() + topLevelExportStatements.join("\n") + "\n";
|
|
238
496
|
const mainIndexFilePath = path2__namespace.join(outputDir, "index.ts");
|
|
239
497
|
fs__namespace.writeFileSync(mainIndexFilePath, mainIndexContent, {
|
|
240
498
|
flag: "w"
|
|
@@ -366,7 +624,15 @@ function convertToWireBlockData(ontology) {
|
|
|
366
624
|
return [apiName, convertAction(action)];
|
|
367
625
|
})),
|
|
368
626
|
blockPermissionInformation: {
|
|
369
|
-
actionTypes: {
|
|
627
|
+
actionTypes: Object.fromEntries(Object.entries(ontology[OntologyEntityTypeEnum.ACTION_TYPE]).filter(([apiName, action]) => action.validation).map(([apiName, action]) => {
|
|
628
|
+
return [apiName, {
|
|
629
|
+
restrictionStatus: {
|
|
630
|
+
hasRolesApplied: true,
|
|
631
|
+
ontologyPackageRid: null,
|
|
632
|
+
publicProject: false
|
|
633
|
+
}
|
|
634
|
+
}];
|
|
635
|
+
})),
|
|
370
636
|
linkTypes: {},
|
|
371
637
|
objectTypes: {}
|
|
372
638
|
}
|
|
@@ -474,39 +740,54 @@ function convertDatasourceDefinition(objectType, properties) {
|
|
|
474
740
|
propertySecurityGroups: void 0
|
|
475
741
|
}
|
|
476
742
|
};
|
|
743
|
+
case "restrictedView":
|
|
744
|
+
return {
|
|
745
|
+
type: "restrictedViewV2",
|
|
746
|
+
restrictedViewV2: {
|
|
747
|
+
restrictedViewRid: objectType.apiName,
|
|
748
|
+
propertyMapping: buildPropertyMapping(properties)
|
|
749
|
+
}
|
|
750
|
+
};
|
|
477
751
|
case "dataset":
|
|
478
752
|
default:
|
|
479
|
-
const datasetPropertyMapping = Object.fromEntries(properties.map((prop) => {
|
|
480
|
-
prop.type;
|
|
481
|
-
if (typeof prop.type === "object" && prop.type?.type === "struct") {
|
|
482
|
-
const structMapping = {
|
|
483
|
-
type: "struct",
|
|
484
|
-
struct: {
|
|
485
|
-
column: prop.apiName,
|
|
486
|
-
mapping: Object.fromEntries(Object.entries(prop.type.structDefinition).map(([fieldName, _fieldType]) => [fieldName, {
|
|
487
|
-
apiName: fieldName,
|
|
488
|
-
mappings: {}
|
|
489
|
-
}]))
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
return [prop.apiName, structMapping];
|
|
493
|
-
} else {
|
|
494
|
-
return [prop.apiName, {
|
|
495
|
-
type: "column",
|
|
496
|
-
column: prop.apiName
|
|
497
|
-
}];
|
|
498
|
-
}
|
|
499
|
-
}));
|
|
500
753
|
return {
|
|
501
754
|
type: "datasetV2",
|
|
502
755
|
datasetV2: {
|
|
503
756
|
datasetRid: objectType.apiName,
|
|
504
|
-
propertyMapping:
|
|
757
|
+
propertyMapping: buildPropertyMapping(properties)
|
|
505
758
|
}
|
|
506
759
|
};
|
|
507
760
|
}
|
|
508
761
|
}
|
|
762
|
+
function buildPropertyMapping(properties) {
|
|
763
|
+
return Object.fromEntries(properties.map((prop) => {
|
|
764
|
+
prop.type;
|
|
765
|
+
if (typeof prop.type === "object" && prop.type?.type === "struct") {
|
|
766
|
+
const structMapping = {
|
|
767
|
+
type: "struct",
|
|
768
|
+
struct: {
|
|
769
|
+
column: prop.apiName,
|
|
770
|
+
mapping: Object.fromEntries(Object.entries(prop.type.structDefinition).map(([fieldName, _fieldType]) => [fieldName, {
|
|
771
|
+
apiName: fieldName,
|
|
772
|
+
mappings: {}
|
|
773
|
+
}]))
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
return [prop.apiName, structMapping];
|
|
777
|
+
} else {
|
|
778
|
+
return [prop.apiName, prop.editOnly ? {
|
|
779
|
+
type: "editOnly",
|
|
780
|
+
editOnly: {}
|
|
781
|
+
} : {
|
|
782
|
+
type: "column",
|
|
783
|
+
column: prop.apiName
|
|
784
|
+
}];
|
|
785
|
+
}
|
|
786
|
+
}));
|
|
787
|
+
}
|
|
509
788
|
function convertProperty(property) {
|
|
789
|
+
const apiName = namespace + property.apiName;
|
|
790
|
+
!(!shouldNotHaveRenderHints(property.type) || !hasRenderHints(property.typeClasses)) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Property type ${apiName} of type '${getPropertyTypeName(property.type)}' should not have render hints`) : invariant__default.default(false) : void 0;
|
|
510
791
|
const output = {
|
|
511
792
|
apiName: property.apiName,
|
|
512
793
|
sharedPropertyTypeApiName: property.sharedPropertyType?.apiName,
|
|
@@ -519,12 +800,12 @@ function convertProperty(property) {
|
|
|
519
800
|
ruleSetBinding: void 0,
|
|
520
801
|
baseFormatter: property.baseFormatter,
|
|
521
802
|
type: convertType(property.type),
|
|
522
|
-
typeClasses: property.typeClasses ?? [],
|
|
803
|
+
typeClasses: property.typeClasses ?? (shouldNotHaveRenderHints(property.type) ? [] : defaultTypeClasses),
|
|
523
804
|
status: convertObjectStatus(property.status),
|
|
524
805
|
inlineAction: void 0,
|
|
525
|
-
dataConstraints: convertNullabilityToDataConstraint(property),
|
|
806
|
+
dataConstraints: property.valueType ? convertValueTypeDataConstraints(property.valueType.constraints) : convertNullabilityToDataConstraint(property),
|
|
526
807
|
sharedPropertyTypeRid: property.sharedPropertyType?.apiName,
|
|
527
|
-
valueType: void 0
|
|
808
|
+
valueType: property.valueType ? convertValueType(property.valueType) : void 0
|
|
528
809
|
};
|
|
529
810
|
return output;
|
|
530
811
|
}
|
|
@@ -535,7 +816,7 @@ function convertLink(linkType) {
|
|
|
535
816
|
definition = {
|
|
536
817
|
type: "oneToMany",
|
|
537
818
|
oneToMany: {
|
|
538
|
-
cardinalityHint: "
|
|
819
|
+
cardinalityHint: "ONE_TO_MANY",
|
|
539
820
|
manyToOneLinkMetadata: linkType.toMany.metadata,
|
|
540
821
|
objectTypeRidManySide: linkType.toMany.object.apiName,
|
|
541
822
|
objectTypeRidOneSide: linkType.one.object.apiName,
|
|
@@ -615,7 +896,7 @@ function convertLink(linkType) {
|
|
|
615
896
|
return {
|
|
616
897
|
linkType: {
|
|
617
898
|
definition,
|
|
618
|
-
id: linkType.apiName,
|
|
899
|
+
id: cleanAndValidateLinkTypeId(linkType.apiName),
|
|
619
900
|
status: linkType.status ?? {
|
|
620
901
|
type: "active",
|
|
621
902
|
active: {}
|
|
@@ -628,6 +909,15 @@ function convertLink(linkType) {
|
|
|
628
909
|
}
|
|
629
910
|
};
|
|
630
911
|
}
|
|
912
|
+
function cleanAndValidateLinkTypeId(apiName) {
|
|
913
|
+
const step1 = apiName.replace(/([a-z0-9])([A-Z])/g, "$1-$2");
|
|
914
|
+
const linkTypeId = step1.replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
915
|
+
const VALIDATION_PATTERN = /^([a-z][a-z0-9\-]*)$/;
|
|
916
|
+
if (!VALIDATION_PATTERN.test(linkTypeId)) {
|
|
917
|
+
throw new Error(`LinkType id '${linkTypeId}' must be lower case with dashes.`);
|
|
918
|
+
}
|
|
919
|
+
return linkTypeId;
|
|
920
|
+
}
|
|
631
921
|
function convertInterface(interfaceType) {
|
|
632
922
|
const {
|
|
633
923
|
__type,
|
|
@@ -639,6 +929,7 @@ function convertInterface(interfaceType) {
|
|
|
639
929
|
required: spt.required,
|
|
640
930
|
sharedPropertyType: convertSpt(spt.sharedPropertyType)
|
|
641
931
|
}])),
|
|
932
|
+
extendsInterfaces: interfaceType.extendsInterfaces.map((i) => i.apiName),
|
|
642
933
|
// these are omitted from our internal types but we need to re-add them for the final json
|
|
643
934
|
allExtendsInterfaces: [],
|
|
644
935
|
allLinks: [],
|
|
@@ -685,110 +976,6 @@ function convertSpt({
|
|
|
685
976
|
valueType
|
|
686
977
|
};
|
|
687
978
|
}
|
|
688
|
-
function convertType(type) {
|
|
689
|
-
switch (true) {
|
|
690
|
-
case (typeof type === "object" && "markingType" in type):
|
|
691
|
-
return {
|
|
692
|
-
"type": "marking",
|
|
693
|
-
marking: {
|
|
694
|
-
markingType: type.markingType
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
case (typeof type === "object" && "structDefinition" in type):
|
|
698
|
-
const structFields = new Array();
|
|
699
|
-
for (const key in type.structDefinition) {
|
|
700
|
-
const fieldTypeDefinition = type.structDefinition[key];
|
|
701
|
-
let field;
|
|
702
|
-
if (typeof fieldTypeDefinition === "string") {
|
|
703
|
-
field = {
|
|
704
|
-
apiName: key,
|
|
705
|
-
displayMetadata: {
|
|
706
|
-
displayName: key,
|
|
707
|
-
description: void 0
|
|
708
|
-
},
|
|
709
|
-
typeClasses: [],
|
|
710
|
-
aliases: [],
|
|
711
|
-
fieldType: convertType(fieldTypeDefinition)
|
|
712
|
-
};
|
|
713
|
-
} else {
|
|
714
|
-
if ("fieldType" in fieldTypeDefinition) {
|
|
715
|
-
field = {
|
|
716
|
-
...fieldTypeDefinition,
|
|
717
|
-
apiName: key,
|
|
718
|
-
fieldType: convertType(fieldTypeDefinition.fieldType),
|
|
719
|
-
typeClasses: fieldTypeDefinition.typeClasses ?? [],
|
|
720
|
-
aliases: fieldTypeDefinition.aliases ?? []
|
|
721
|
-
};
|
|
722
|
-
} else {
|
|
723
|
-
field = {
|
|
724
|
-
apiName: key,
|
|
725
|
-
displayMetadata: {
|
|
726
|
-
displayName: key,
|
|
727
|
-
description: void 0
|
|
728
|
-
},
|
|
729
|
-
typeClasses: [],
|
|
730
|
-
aliases: [],
|
|
731
|
-
fieldType: convertType(fieldTypeDefinition)
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
structFields.push(field);
|
|
736
|
-
}
|
|
737
|
-
return {
|
|
738
|
-
type: "struct",
|
|
739
|
-
struct: {
|
|
740
|
-
structFields
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
case (typeof type === "object" && "isLongText" in type):
|
|
744
|
-
return {
|
|
745
|
-
"type": "string",
|
|
746
|
-
"string": {
|
|
747
|
-
analyzerOverride: void 0,
|
|
748
|
-
enableAsciiFolding: void 0,
|
|
749
|
-
isLongText: type.isLongText,
|
|
750
|
-
supportsEfficientLeadingWildcard: type.supportsEfficientLeadingWildcard,
|
|
751
|
-
supportsExactMatching: type.supportsExactMatching
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
case type === "geopoint":
|
|
755
|
-
return {
|
|
756
|
-
type: "geohash",
|
|
757
|
-
geohash: {}
|
|
758
|
-
};
|
|
759
|
-
case type === "decimal":
|
|
760
|
-
return {
|
|
761
|
-
type,
|
|
762
|
-
[type]: {
|
|
763
|
-
precision: void 0,
|
|
764
|
-
scale: void 0
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
case type === "string":
|
|
768
|
-
return {
|
|
769
|
-
type,
|
|
770
|
-
[type]: {
|
|
771
|
-
analyzerOverride: void 0,
|
|
772
|
-
enableAsciiFolding: void 0,
|
|
773
|
-
isLongText: false,
|
|
774
|
-
supportsEfficientLeadingWildcard: false,
|
|
775
|
-
supportsExactMatching: true
|
|
776
|
-
}
|
|
777
|
-
};
|
|
778
|
-
case type === "mediaReference":
|
|
779
|
-
return {
|
|
780
|
-
type,
|
|
781
|
-
mediaReference: {}
|
|
782
|
-
};
|
|
783
|
-
case type === "geotimeSeries":
|
|
784
|
-
return {
|
|
785
|
-
type: "geotimeSeriesReference",
|
|
786
|
-
geotimeSeriesReference: {}
|
|
787
|
-
};
|
|
788
|
-
default:
|
|
789
|
-
return distributeTypeHelper(type);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
979
|
function convertObjectStatus(status) {
|
|
793
980
|
if (status === void 0) {
|
|
794
981
|
return {
|
|
@@ -1154,37 +1341,6 @@ function convertParameterRequirementConstraint(required) {
|
|
|
1154
1341
|
}
|
|
1155
1342
|
};
|
|
1156
1343
|
}
|
|
1157
|
-
function convertNullabilityToDataConstraint(prop) {
|
|
1158
|
-
if (typeof prop.type === "object" && prop.type.type === "marking") {
|
|
1159
|
-
if (prop.nullability === void 0) {
|
|
1160
|
-
return {
|
|
1161
|
-
propertyTypeConstraints: [],
|
|
1162
|
-
nullability: void 0,
|
|
1163
|
-
nullabilityV2: {
|
|
1164
|
-
noEmptyCollections: true,
|
|
1165
|
-
noNulls: true
|
|
1166
|
-
}
|
|
1167
|
-
};
|
|
1168
|
-
}
|
|
1169
|
-
!prop.nullability?.noNulls ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Marking property type has noNulls set to false, marking properties must not be nullable") : invariant__default.default(false) : void 0;
|
|
1170
|
-
return {
|
|
1171
|
-
propertyTypeConstraints: [],
|
|
1172
|
-
nullability: void 0,
|
|
1173
|
-
nullabilityV2: prop.nullability
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
return prop.nullability === void 0 ? void 0 : {
|
|
1177
|
-
propertyTypeConstraints: [],
|
|
1178
|
-
nullability: void 0,
|
|
1179
|
-
nullabilityV2: prop.nullability
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
function distributeTypeHelper(type) {
|
|
1183
|
-
return {
|
|
1184
|
-
type,
|
|
1185
|
-
[type]: {}
|
|
1186
|
-
};
|
|
1187
|
-
}
|
|
1188
1344
|
function sanitize(namespace2, s) {
|
|
1189
1345
|
return s.includes(".") ? s : namespace2 + s;
|
|
1190
1346
|
}
|
|
@@ -1216,11 +1372,23 @@ function getEntityTypeName(type) {
|
|
|
1216
1372
|
[OntologyEntityTypeEnum.VALUE_TYPE]: "ValueTypeDefinitionVersion"
|
|
1217
1373
|
}[type];
|
|
1218
1374
|
}
|
|
1375
|
+
function writeDependencyFile(dependencyFile) {
|
|
1376
|
+
fs__namespace.writeFileSync(dependencyFile, JSON.stringify(dependencies, null, 2));
|
|
1377
|
+
}
|
|
1378
|
+
function dependencyInjectionString() {
|
|
1379
|
+
const namespaceNoDot = namespace.endsWith(".") ? namespace.slice(0, -1) : namespace;
|
|
1380
|
+
return `
|
|
1381
|
+
import { fileURLToPath } from "url";
|
|
1382
|
+
import { addDependency } from '@osdk/maker';
|
|
1383
|
+
|
|
1384
|
+
addDependency("${namespaceNoDot}", fileURLToPath(import.meta.url));
|
|
1385
|
+
`;
|
|
1386
|
+
}
|
|
1219
1387
|
|
|
1220
1388
|
// src/cli/main.ts
|
|
1221
1389
|
var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
|
|
1222
1390
|
async function main(args = process.argv) {
|
|
1223
|
-
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.10
|
|
1391
|
+
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.11.0-beta.10").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
1224
1392
|
input: {
|
|
1225
1393
|
alias: "i",
|
|
1226
1394
|
describe: "Input file",
|
|
@@ -1247,11 +1415,22 @@ async function main(args = process.argv) {
|
|
|
1247
1415
|
default: "snapshots",
|
|
1248
1416
|
coerce: path2__namespace.resolve
|
|
1249
1417
|
},
|
|
1418
|
+
outputDir: {
|
|
1419
|
+
alias: "d",
|
|
1420
|
+
describe: "Directory for generated ontology entities",
|
|
1421
|
+
type: "string",
|
|
1422
|
+
coerce: path2__namespace.resolve
|
|
1423
|
+
},
|
|
1250
1424
|
valueTypesOutput: {
|
|
1251
1425
|
describe: "Value Type Output File",
|
|
1252
1426
|
type: "string",
|
|
1253
1427
|
default: "value-types.json",
|
|
1254
1428
|
coerce: path2__namespace.resolve
|
|
1429
|
+
},
|
|
1430
|
+
dependencies: {
|
|
1431
|
+
describe: "File to write dependencies to",
|
|
1432
|
+
type: "string",
|
|
1433
|
+
coerce: path2__namespace.resolve
|
|
1255
1434
|
}
|
|
1256
1435
|
}).parseAsync();
|
|
1257
1436
|
let apiNamespace = "";
|
|
@@ -1261,23 +1440,45 @@ async function main(args = process.argv) {
|
|
|
1261
1440
|
!apiNamespaceRegex.test(apiNamespace) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(.[a-z0-9-]+)*.$") : invariant__default.default(false) : void 0;
|
|
1262
1441
|
}
|
|
1263
1442
|
consola.consola.info(`Loading ontology from ${commandLineOpts.input}`);
|
|
1264
|
-
const ontology = await loadOntology(
|
|
1265
|
-
commandLineOpts.input,
|
|
1266
|
-
apiNamespace,
|
|
1267
|
-
path2__namespace.dirname(path2__namespace.dirname(commandLineOpts.input))
|
|
1268
|
-
// "src" in "src/ontology/ontology.mjs"
|
|
1269
|
-
);
|
|
1443
|
+
const ontology = await loadOntology(commandLineOpts.input, apiNamespace, commandLineOpts.outputDir, commandLineOpts.dependencies);
|
|
1270
1444
|
consola.consola.info(`Saving ontology to ${commandLineOpts.output}`);
|
|
1271
1445
|
await fs2__namespace.writeFile(commandLineOpts.output, JSON.stringify(ontology.ontology, null, 2));
|
|
1272
1446
|
if (ontology.valueType.valueTypes.length > 0) {
|
|
1273
1447
|
await fs2__namespace.writeFile(commandLineOpts.valueTypesOutput, JSON.stringify(ontology.valueType, null, 2));
|
|
1274
1448
|
}
|
|
1275
1449
|
}
|
|
1276
|
-
async function loadOntology(input, apiNamespace, outputDir) {
|
|
1277
|
-
const q = await defineOntology(apiNamespace, async () =>
|
|
1450
|
+
async function loadOntology(input, apiNamespace, outputDir, dependencyFile) {
|
|
1451
|
+
const q = await defineOntology(apiNamespace, async () => {
|
|
1452
|
+
const jiti$1 = jiti.createJiti(undefined, {
|
|
1453
|
+
moduleCache: false,
|
|
1454
|
+
debug: false,
|
|
1455
|
+
importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) })
|
|
1456
|
+
});
|
|
1457
|
+
const module = await jiti$1.import(input);
|
|
1458
|
+
}, outputDir, dependencyFile);
|
|
1278
1459
|
return q;
|
|
1279
1460
|
}
|
|
1280
|
-
|
|
1461
|
+
var MAX_SEARCH_DEPTH = 5;
|
|
1462
|
+
function addDependency(namespace2, fileInPackage) {
|
|
1463
|
+
let dir = path2__namespace.dirname(fileInPackage);
|
|
1464
|
+
let packageJsonPath = null;
|
|
1465
|
+
for (let i = 0; i < MAX_SEARCH_DEPTH; i++) {
|
|
1466
|
+
const candidate = path2__namespace.join(dir, "package.json");
|
|
1467
|
+
if (fs__namespace.existsSync(candidate)) {
|
|
1468
|
+
packageJsonPath = candidate;
|
|
1469
|
+
break;
|
|
1470
|
+
}
|
|
1471
|
+
const parentDir = path2__namespace.dirname(dir);
|
|
1472
|
+
if (parentDir === dir) break;
|
|
1473
|
+
dir = parentDir;
|
|
1474
|
+
}
|
|
1475
|
+
if (!packageJsonPath) {
|
|
1476
|
+
throw new Error(`Could not find a package.json within ${MAX_SEARCH_DEPTH} parent directories of ${fileInPackage}`);
|
|
1477
|
+
}
|
|
1478
|
+
const packageJson = JSON.parse(fs__namespace.readFileSync(packageJsonPath, "utf-8"));
|
|
1479
|
+
dependencies[namespace2] = packageJson.version ?? "";
|
|
1480
|
+
}
|
|
1481
|
+
function defineCreateInterfaceObjectAction(interfaceType, objectType, validation) {
|
|
1281
1482
|
return defineAction({
|
|
1282
1483
|
apiName: `create-${kebab(interfaceType.apiName.split(".").pop() ?? interfaceType.apiName)}${objectType === void 0 ? "" : `-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`}`,
|
|
1283
1484
|
displayName: `Create ${interfaceType.displayMetadata.displayName}`,
|
|
@@ -1331,10 +1532,13 @@ function defineCreateInterfaceObjectAction(interfaceType, objectType) {
|
|
|
1331
1532
|
parameterId: id
|
|
1332
1533
|
}]))
|
|
1333
1534
|
}
|
|
1334
|
-
}]
|
|
1535
|
+
}],
|
|
1536
|
+
...validation ? {
|
|
1537
|
+
validation: [createValidationRule(validation)]
|
|
1538
|
+
} : {}
|
|
1335
1539
|
});
|
|
1336
1540
|
}
|
|
1337
|
-
function defineCreateObjectAction(objectType) {
|
|
1541
|
+
function defineCreateObjectAction(objectType, validation) {
|
|
1338
1542
|
return defineAction({
|
|
1339
1543
|
apiName: `create-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
|
|
1340
1544
|
displayName: `Create ${objectType.displayName}`,
|
|
@@ -1358,10 +1562,13 @@ function defineCreateObjectAction(objectType) {
|
|
|
1358
1562
|
}])) : {},
|
|
1359
1563
|
structFieldValues: {}
|
|
1360
1564
|
}
|
|
1361
|
-
}]
|
|
1565
|
+
}],
|
|
1566
|
+
...validation ? {
|
|
1567
|
+
validation: [createValidationRule(validation)]
|
|
1568
|
+
} : {}
|
|
1362
1569
|
});
|
|
1363
1570
|
}
|
|
1364
|
-
function defineModifyInterfaceObjectAction(interfaceType, objectType) {
|
|
1571
|
+
function defineModifyInterfaceObjectAction(interfaceType, objectType, validation) {
|
|
1365
1572
|
return defineAction({
|
|
1366
1573
|
apiName: `modify-${kebab(interfaceType.apiName.split(".").pop() ?? interfaceType.apiName)}${objectType === void 0 ? "" : `-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`}`,
|
|
1367
1574
|
displayName: `Modify ${interfaceType.displayMetadata.displayName}`,
|
|
@@ -1413,10 +1620,13 @@ function defineModifyInterfaceObjectAction(interfaceType, objectType) {
|
|
|
1413
1620
|
parameterId: id
|
|
1414
1621
|
}]))
|
|
1415
1622
|
}
|
|
1416
|
-
}]
|
|
1623
|
+
}],
|
|
1624
|
+
...validation ? {
|
|
1625
|
+
validation: [createValidationRule(validation)]
|
|
1626
|
+
} : {}
|
|
1417
1627
|
});
|
|
1418
1628
|
}
|
|
1419
|
-
function defineModifyObjectAction(objectType) {
|
|
1629
|
+
function defineModifyObjectAction(objectType, validation) {
|
|
1420
1630
|
return defineAction({
|
|
1421
1631
|
apiName: `modify-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
|
|
1422
1632
|
displayName: `Modify ${objectType.displayName}`,
|
|
@@ -1440,7 +1650,7 @@ function defineModifyObjectAction(objectType) {
|
|
|
1440
1650
|
displayName: prop.displayName,
|
|
1441
1651
|
type: extractActionParameterType(prop),
|
|
1442
1652
|
validation: {
|
|
1443
|
-
required:
|
|
1653
|
+
required: false,
|
|
1444
1654
|
allowedValues: extractAllowedValuesFromType(prop.type)
|
|
1445
1655
|
}
|
|
1446
1656
|
})) ?? []],
|
|
@@ -1455,10 +1665,13 @@ function defineModifyObjectAction(objectType) {
|
|
|
1455
1665
|
}])) : {},
|
|
1456
1666
|
structFieldValues: {}
|
|
1457
1667
|
}
|
|
1458
|
-
}]
|
|
1668
|
+
}],
|
|
1669
|
+
...validation ? {
|
|
1670
|
+
validation: [createValidationRule(validation)]
|
|
1671
|
+
} : {}
|
|
1459
1672
|
});
|
|
1460
1673
|
}
|
|
1461
|
-
function defineDeleteObjectAction(objectType) {
|
|
1674
|
+
function defineDeleteObjectAction(objectType, validation) {
|
|
1462
1675
|
return defineAction({
|
|
1463
1676
|
apiName: `delete-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
|
|
1464
1677
|
displayName: `Delete ${objectType.displayName}`,
|
|
@@ -1484,7 +1697,10 @@ function defineDeleteObjectAction(objectType) {
|
|
|
1484
1697
|
deleteObjectRule: {
|
|
1485
1698
|
objectToDelete: "objectToDeleteParameter"
|
|
1486
1699
|
}
|
|
1487
|
-
}]
|
|
1700
|
+
}],
|
|
1701
|
+
...validation ? {
|
|
1702
|
+
validation: [createValidationRule(validation)]
|
|
1703
|
+
} : {}
|
|
1488
1704
|
});
|
|
1489
1705
|
}
|
|
1490
1706
|
function defineAction(actionDef) {
|
|
@@ -1634,6 +1850,9 @@ function extractAllowedValuesFromType(type) {
|
|
|
1634
1850
|
type: "text"
|
|
1635
1851
|
};
|
|
1636
1852
|
case "geopoint":
|
|
1853
|
+
return {
|
|
1854
|
+
type: "geohash"
|
|
1855
|
+
};
|
|
1637
1856
|
case "geoshape":
|
|
1638
1857
|
return {
|
|
1639
1858
|
type: "geoshape"
|
|
@@ -1681,7 +1900,7 @@ function extractActionParameterType(pt) {
|
|
|
1681
1900
|
case "short":
|
|
1682
1901
|
return maybeAddList("integer", pt);
|
|
1683
1902
|
case "geopoint":
|
|
1684
|
-
return maybeAddList("
|
|
1903
|
+
return maybeAddList("geohash", pt);
|
|
1685
1904
|
case "float":
|
|
1686
1905
|
return maybeAddList("double", pt);
|
|
1687
1906
|
case "geotimeSeries":
|
|
@@ -1702,57 +1921,102 @@ function kebab(s) {
|
|
|
1702
1921
|
function sanitize2(s) {
|
|
1703
1922
|
return s.includes(".") ? s : namespace + s;
|
|
1704
1923
|
}
|
|
1924
|
+
function createValidationRule(actionValidation) {
|
|
1925
|
+
if (!("type" in actionValidation)) {
|
|
1926
|
+
return actionValidation;
|
|
1927
|
+
}
|
|
1928
|
+
switch (actionValidation.type) {
|
|
1929
|
+
case "group":
|
|
1930
|
+
return {
|
|
1931
|
+
condition: {
|
|
1932
|
+
type: "comparison",
|
|
1933
|
+
comparison: {
|
|
1934
|
+
operator: "EQUALS",
|
|
1935
|
+
left: {
|
|
1936
|
+
type: "userProperty",
|
|
1937
|
+
userProperty: {
|
|
1938
|
+
userId: {
|
|
1939
|
+
type: "currentUser",
|
|
1940
|
+
currentUser: {}
|
|
1941
|
+
},
|
|
1942
|
+
propertyValue: {
|
|
1943
|
+
type: "groupIds",
|
|
1944
|
+
groupIds: {}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
},
|
|
1948
|
+
right: {
|
|
1949
|
+
type: "staticValue",
|
|
1950
|
+
staticValue: {
|
|
1951
|
+
type: "stringList",
|
|
1952
|
+
stringList: {
|
|
1953
|
+
strings: [actionValidation.name]
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
},
|
|
1959
|
+
displayMetadata: {
|
|
1960
|
+
failureMessage: "Insufficient permissions. Missing organization membership required to submit action",
|
|
1961
|
+
typeClasses: []
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
default:
|
|
1965
|
+
throw new Error(`Unknown action validation type: ${actionValidation.type}`);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// src/api/importOntologyEntity.ts
|
|
1970
|
+
function importOntologyEntity(e) {
|
|
1971
|
+
if (e.__type !== OntologyEntityTypeEnum.VALUE_TYPE) {
|
|
1972
|
+
importedTypes[e.__type][e.apiName] = e;
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1975
|
+
if (importedTypes[OntologyEntityTypeEnum.VALUE_TYPE][e.apiName] === void 0) {
|
|
1976
|
+
importedTypes[OntologyEntityTypeEnum.VALUE_TYPE][e.apiName] = [];
|
|
1977
|
+
}
|
|
1978
|
+
importedTypes[OntologyEntityTypeEnum.VALUE_TYPE][e.apiName].push(e);
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
// src/api/defineImportSpt.ts
|
|
1705
1982
|
function importSharedPropertyType(opts) {
|
|
1706
1983
|
const {
|
|
1707
1984
|
apiName,
|
|
1708
1985
|
packageName,
|
|
1709
|
-
typeHint
|
|
1986
|
+
typeHint,
|
|
1987
|
+
array
|
|
1710
1988
|
} = opts;
|
|
1989
|
+
const fullApiName = packageName === void 0 ? apiName : `${packageName}.${apiName}`;
|
|
1711
1990
|
if (packageName !== void 0) {
|
|
1712
1991
|
!!packageName.endsWith(".") ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Package name format invalid ends with period") : invariant__default.default(false) : void 0;
|
|
1713
1992
|
!(packageName.match("[A-Z]") == null) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Package name includes upper case characters") : invariant__default.default(false) : void 0;
|
|
1714
|
-
return {
|
|
1715
|
-
apiName: packageName + "." + apiName,
|
|
1716
|
-
type: typeHint,
|
|
1717
|
-
nonNameSpacedApiName: apiName,
|
|
1718
|
-
__type: OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE
|
|
1719
|
-
};
|
|
1720
1993
|
}
|
|
1721
|
-
|
|
1722
|
-
apiName,
|
|
1994
|
+
const spt = {
|
|
1995
|
+
apiName: fullApiName,
|
|
1723
1996
|
type: typeHint,
|
|
1724
1997
|
nonNameSpacedApiName: apiName,
|
|
1998
|
+
array: array ?? false,
|
|
1725
1999
|
__type: OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE
|
|
1726
2000
|
};
|
|
2001
|
+
importOntologyEntity(spt);
|
|
2002
|
+
return spt;
|
|
1727
2003
|
}
|
|
1728
|
-
var defaultTypeClasses = [{
|
|
1729
|
-
kind: "render_hint",
|
|
1730
|
-
name: "SELECTABLE"
|
|
1731
|
-
}, {
|
|
1732
|
-
kind: "render_hint",
|
|
1733
|
-
name: "SORTABLE"
|
|
1734
|
-
}];
|
|
1735
2004
|
function defineSharedPropertyType(sptDef) {
|
|
1736
2005
|
const apiName = namespace + sptDef.apiName;
|
|
1737
2006
|
!(ontologyDefinition[OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE][apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Shared property type ${apiName} already exists`) : invariant__default.default(false) : void 0;
|
|
1738
|
-
|
|
1739
|
-
const hasRenderHints = (sptDef.typeClasses ?? []).some((tc) => tc.kind.toLowerCase() === "render_hint");
|
|
1740
|
-
!(!shouldNotHaveRenderHints || !hasRenderHints) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Shared property type ${apiName} of type '${getPropertyTypeName(sptDef.type)}' should not have render hints`) : invariant__default.default(false) : void 0;
|
|
2007
|
+
!(!shouldNotHaveRenderHints(sptDef.type) || !hasRenderHints(sptDef.typeClasses)) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Shared property type ${apiName} of type '${getPropertyTypeName(sptDef.type)}' should not have render hints`) : invariant__default.default(false) : void 0;
|
|
1741
2008
|
const fullSpt = {
|
|
1742
2009
|
...sptDef,
|
|
1743
2010
|
apiName,
|
|
1744
2011
|
nonNameSpacedApiName: sptDef.apiName,
|
|
1745
2012
|
displayName: sptDef.displayName ?? sptDef.apiName,
|
|
1746
2013
|
// This way the non-namespaced api name is the display name (maybe not ideal)
|
|
1747
|
-
typeClasses: sptDef.typeClasses ?? (shouldNotHaveRenderHints ? [] : defaultTypeClasses),
|
|
2014
|
+
typeClasses: sptDef.typeClasses ?? (shouldNotHaveRenderHints(sptDef.type) ? [] : defaultTypeClasses),
|
|
1748
2015
|
__type: OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE
|
|
1749
2016
|
};
|
|
1750
2017
|
updateOntology(fullSpt);
|
|
1751
2018
|
return fullSpt;
|
|
1752
2019
|
}
|
|
1753
|
-
function getPropertyTypeName(type) {
|
|
1754
|
-
return typeof type === "object" ? type.type : type;
|
|
1755
|
-
}
|
|
1756
2020
|
|
|
1757
2021
|
// src/api/defineInterface.ts
|
|
1758
2022
|
function defineInterface(interfaceDef) {
|
|
@@ -1770,18 +2034,7 @@ function defineInterface(interfaceDef) {
|
|
|
1770
2034
|
sharedPropertyType: unifyBasePropertyDefinition(namespace, apiName2, type)
|
|
1771
2035
|
}];
|
|
1772
2036
|
}));
|
|
1773
|
-
|
|
1774
|
-
if (interfaceDef.extends) {
|
|
1775
|
-
if (typeof interfaceDef.extends === "string") {
|
|
1776
|
-
extendsInterfaces = [interfaceDef.extends];
|
|
1777
|
-
} else if (Array.isArray(interfaceDef.extends) && interfaceDef.extends.every((item) => typeof item === "string")) {
|
|
1778
|
-
extendsInterfaces = interfaceDef.extends;
|
|
1779
|
-
} else if (interfaceDef.extends.apiName !== void 0) {
|
|
1780
|
-
extendsInterfaces = [interfaceDef.extends.apiName];
|
|
1781
|
-
} else {
|
|
1782
|
-
extendsInterfaces = interfaceDef.extends.map((item) => item.apiName);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
2037
|
+
const extendsInterfaces = interfaceDef.extends ? Array.isArray(interfaceDef.extends) ? interfaceDef.extends : [interfaceDef.extends] : [];
|
|
1785
2038
|
const status = mapSimplifiedStatusToInterfaceTypeStatus(interfaceDef.status ?? {
|
|
1786
2039
|
type: "active"
|
|
1787
2040
|
});
|
|
@@ -1885,20 +2138,56 @@ function getLinkMeta(meta) {
|
|
|
1885
2138
|
description: description ?? displayName ?? apiNameWithoutNamespace
|
|
1886
2139
|
};
|
|
1887
2140
|
}
|
|
2141
|
+
var typeIdPattern = /([a-z][a-z0-9\\-]*)/;
|
|
1888
2142
|
function defineLink(linkDefinition) {
|
|
1889
2143
|
if ("one" in linkDefinition) {
|
|
1890
2144
|
const foreignKey = linkDefinition.toMany.object.properties?.find((prop) => prop.apiName === linkDefinition.manyForeignKeyProperty);
|
|
1891
2145
|
!(foreignKey !== void 0) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Foreign key ${linkDefinition.manyForeignKeyProperty} on link ${linkDefinition.apiName} does not exist on object ${linkDefinition.toMany.object.apiName}}`) : invariant__default.default(false) : void 0;
|
|
2146
|
+
!typeIdPattern.test(linkDefinition.apiName) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Top level link api names are expected to match the regex pattern ([a-z][a-z0-9\\-]*) ${linkDefinition.apiName} does not match`) : invariant__default.default(false) : void 0;
|
|
1892
2147
|
const typesMatch = foreignKey.type === linkDefinition.one.object.properties?.find((prop) => prop.apiName === linkDefinition.one.object.primaryKeyPropertyApiName)?.type;
|
|
1893
2148
|
!typesMatch ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Link ${linkDefinition.apiName} has type mismatch between the one side's primary key and the foreign key on the many side`) : invariant__default.default(false) : void 0;
|
|
1894
2149
|
}
|
|
1895
|
-
const
|
|
2150
|
+
const fullLinkDefinition = "one" in linkDefinition ? {
|
|
1896
2151
|
...linkDefinition,
|
|
2152
|
+
one: convertUserOneToManyLinkDefinition(linkDefinition.one),
|
|
2153
|
+
toMany: convertUserOneToManyLinkDefinition(linkDefinition.toMany)
|
|
2154
|
+
} : {
|
|
2155
|
+
...linkDefinition,
|
|
2156
|
+
many: convertUserManyToManyLinkDefinition(linkDefinition.many),
|
|
2157
|
+
toMany: convertUserManyToManyLinkDefinition(linkDefinition.toMany)
|
|
2158
|
+
};
|
|
2159
|
+
const linkType = {
|
|
2160
|
+
cardinality: "one" in linkDefinition ? "OneToMany" : void 0,
|
|
2161
|
+
...fullLinkDefinition,
|
|
1897
2162
|
__type: OntologyEntityTypeEnum.LINK_TYPE
|
|
1898
2163
|
};
|
|
1899
2164
|
updateOntology(linkType);
|
|
1900
2165
|
return linkType;
|
|
1901
2166
|
}
|
|
2167
|
+
function convertUserOneToManyLinkDefinition(oneToMany) {
|
|
2168
|
+
return {
|
|
2169
|
+
...oneToMany,
|
|
2170
|
+
metadata: convertLinkTypeMetadata(oneToMany.metadata)
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
function convertUserManyToManyLinkDefinition(manyToMany) {
|
|
2174
|
+
return {
|
|
2175
|
+
...manyToMany,
|
|
2176
|
+
metadata: convertLinkTypeMetadata(manyToMany.metadata)
|
|
2177
|
+
};
|
|
2178
|
+
}
|
|
2179
|
+
function convertLinkTypeMetadata(metadata) {
|
|
2180
|
+
return {
|
|
2181
|
+
apiName: metadata.apiName,
|
|
2182
|
+
displayMetadata: {
|
|
2183
|
+
displayName: metadata.displayName ?? convertToDisplayName(metadata.apiName),
|
|
2184
|
+
pluralDisplayName: metadata.pluralDisplayName ?? convertToPluralDisplayName(metadata.apiName),
|
|
2185
|
+
visibility: metadata.visibility ?? "NORMAL",
|
|
2186
|
+
groupDisplayName: metadata.groupDisplayName ?? ""
|
|
2187
|
+
},
|
|
2188
|
+
typeClasses: []
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
1902
2191
|
function convertValueTypeTypeToBaseType(valueType) {
|
|
1903
2192
|
switch (true) {
|
|
1904
2193
|
case (typeof valueType === "object" && valueType.type === "array"):
|
|
@@ -1986,18 +2275,6 @@ function defineValueType(valueTypeDef) {
|
|
|
1986
2275
|
return vt;
|
|
1987
2276
|
}
|
|
1988
2277
|
|
|
1989
|
-
// src/api/importOntologyEntity.ts
|
|
1990
|
-
function importOntologyEntity(e) {
|
|
1991
|
-
if (e.__type !== OntologyEntityTypeEnum.VALUE_TYPE) {
|
|
1992
|
-
importedTypes[e.__type][e.apiName] = e;
|
|
1993
|
-
return;
|
|
1994
|
-
}
|
|
1995
|
-
if (importedTypes[OntologyEntityTypeEnum.VALUE_TYPE][e.apiName] === void 0) {
|
|
1996
|
-
importedTypes[OntologyEntityTypeEnum.VALUE_TYPE][e.apiName] = [];
|
|
1997
|
-
}
|
|
1998
|
-
importedTypes[OntologyEntityTypeEnum.VALUE_TYPE][e.apiName].push(e);
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
2278
|
// src/api/wrapWithProxy.ts
|
|
2002
2279
|
function wrapWithProxy(entity) {
|
|
2003
2280
|
return new Proxy(entity, {
|
|
@@ -2009,6 +2286,7 @@ function wrapWithProxy(entity) {
|
|
|
2009
2286
|
}
|
|
2010
2287
|
|
|
2011
2288
|
exports.OntologyEntityTypeEnum = OntologyEntityTypeEnum;
|
|
2289
|
+
exports.addDependency = addDependency;
|
|
2012
2290
|
exports.default = main;
|
|
2013
2291
|
exports.defineAction = defineAction;
|
|
2014
2292
|
exports.defineCreateInterfaceObjectAction = defineCreateInterfaceObjectAction;
|