@osdk/maker 0.9.0-beta.3 → 0.9.0-beta.30
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 +258 -0
- package/build/browser/api/defineImportSpt.js +47 -0
- package/build/browser/api/defineImportSpt.js.map +1 -0
- package/build/browser/api/defineInterface.js +39 -11
- package/build/browser/api/defineInterface.js.map +1 -1
- package/build/browser/api/defineInterfaceLinkConstraint.js +3 -2
- package/build/browser/api/defineInterfaceLinkConstraint.js.map +1 -1
- package/build/browser/api/defineObject.js +57 -62
- package/build/browser/api/defineObject.js.map +1 -1
- package/build/browser/api/defineOntology.js +194 -23
- package/build/browser/api/defineOntology.js.map +1 -1
- package/build/browser/api/defineSpt.js +3 -1
- package/build/browser/api/defineSpt.js.map +1 -1
- package/build/browser/api/defineValueType.js +58 -11
- package/build/browser/api/defineValueType.js.map +1 -1
- package/build/browser/api/iconNames.js +0 -15
- package/build/browser/api/iconNames.js.map +1 -1
- package/build/browser/api/overall.test.js +704 -63
- package/build/browser/api/overall.test.js.map +1 -1
- package/build/browser/api/types.js +0 -15
- package/build/browser/api/types.js.map +1 -1
- package/build/browser/cli/main.js +5 -6
- package/build/browser/cli/main.js.map +1 -1
- package/build/browser/index.js +3 -0
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +716 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +343 -0
- package/build/esm/api/defineImportSpt.js +47 -0
- package/build/esm/api/defineImportSpt.js.map +1 -0
- package/build/esm/api/defineInterface.js +39 -11
- package/build/esm/api/defineInterface.js.map +1 -1
- package/build/esm/api/defineInterfaceLinkConstraint.js +3 -2
- package/build/esm/api/defineInterfaceLinkConstraint.js.map +1 -1
- package/build/esm/api/defineObject.js +57 -62
- package/build/esm/api/defineObject.js.map +1 -1
- package/build/esm/api/defineOntology.js +194 -23
- package/build/esm/api/defineOntology.js.map +1 -1
- package/build/esm/api/defineSpt.js +3 -1
- package/build/esm/api/defineSpt.js.map +1 -1
- package/build/esm/api/defineValueType.js +58 -11
- package/build/esm/api/defineValueType.js.map +1 -1
- package/build/esm/api/iconNames.js +0 -15
- package/build/esm/api/iconNames.js.map +1 -1
- package/build/esm/api/overall.test.js +704 -63
- package/build/esm/api/overall.test.js.map +1 -1
- package/build/esm/api/types.js +0 -15
- package/build/esm/api/types.js.map +1 -1
- package/build/esm/cli/main.js +5 -6
- package/build/esm/cli/main.js.map +1 -1
- package/build/esm/index.js +3 -0
- package/build/esm/index.js.map +1 -1
- package/package.json +28 -13
- package/build/browser/api/defineInterface.d.ts +0 -14
- package/build/browser/api/defineInterface.d.ts.map +0 -1
- package/build/browser/api/defineInterfaceLinkConstraint.d.ts +0 -21
- package/build/browser/api/defineInterfaceLinkConstraint.d.ts.map +0 -1
- package/build/browser/api/defineLink.d.ts +0 -18
- package/build/browser/api/defineLink.d.ts.map +0 -1
- package/build/browser/api/defineLink.js +0 -37
- package/build/browser/api/defineLink.js.map +0 -1
- package/build/browser/api/defineObject.d.ts +0 -15
- package/build/browser/api/defineObject.d.ts.map +0 -1
- package/build/browser/api/defineOntology.d.ts +0 -10
- package/build/browser/api/defineOntology.d.ts.map +0 -1
- package/build/browser/api/defineSpt.d.ts +0 -13
- package/build/browser/api/defineSpt.d.ts.map +0 -1
- package/build/browser/api/defineValueType.d.ts +0 -26
- package/build/browser/api/defineValueType.d.ts.map +0 -1
- package/build/browser/api/iconNames.d.ts +0 -3
- package/build/browser/api/iconNames.d.ts.map +0 -1
- package/build/browser/api/overall.test.d.ts +0 -2
- package/build/browser/api/overall.test.d.ts.map +0 -1
- package/build/browser/api/types.d.ts +0 -38
- package/build/browser/api/types.d.ts.map +0 -1
- package/build/browser/cli/main.d.ts +0 -2
- package/build/browser/cli/main.d.ts.map +0 -1
- package/build/browser/index.d.ts +0 -6
- package/build/browser/index.d.ts.map +0 -1
- package/build/esm/api/defineInterface.d.ts +0 -14
- package/build/esm/api/defineInterface.d.ts.map +0 -1
- package/build/esm/api/defineInterfaceLinkConstraint.d.ts +0 -21
- package/build/esm/api/defineInterfaceLinkConstraint.d.ts.map +0 -1
- package/build/esm/api/defineLink.d.ts +0 -18
- package/build/esm/api/defineLink.d.ts.map +0 -1
- package/build/esm/api/defineLink.js +0 -37
- package/build/esm/api/defineLink.js.map +0 -1
- package/build/esm/api/defineObject.d.ts +0 -15
- package/build/esm/api/defineObject.d.ts.map +0 -1
- package/build/esm/api/defineOntology.d.ts +0 -10
- package/build/esm/api/defineOntology.d.ts.map +0 -1
- package/build/esm/api/defineSpt.d.ts +0 -13
- package/build/esm/api/defineSpt.d.ts.map +0 -1
- package/build/esm/api/defineValueType.d.ts +0 -26
- package/build/esm/api/defineValueType.d.ts.map +0 -1
- package/build/esm/api/iconNames.d.ts +0 -3
- package/build/esm/api/iconNames.d.ts.map +0 -1
- package/build/esm/api/overall.test.d.ts +0 -2
- package/build/esm/api/overall.test.d.ts.map +0 -1
- package/build/esm/api/types.d.ts +0 -38
- package/build/esm/api/types.d.ts.map +0 -1
- package/build/esm/cli/main.d.ts +0 -2
- package/build/esm/cli/main.d.ts.map +0 -1
- package/build/esm/index.d.ts +0 -6
- package/build/esm/index.d.ts.map +0 -1
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var consola = require('consola');
|
|
6
|
+
var fs = require('fs/promises');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var invariant2 = require('tiny-invariant');
|
|
9
|
+
var yargs = require('yargs');
|
|
10
|
+
var helpers = require('yargs/helpers');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
33
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
34
|
+
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
35
|
+
var yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
36
|
+
|
|
37
|
+
// src/cli/main.ts
|
|
38
|
+
|
|
39
|
+
// src/api/defineOntology.ts
|
|
40
|
+
var ontologyDefinition;
|
|
41
|
+
var namespace;
|
|
42
|
+
async function defineOntology(ns, body) {
|
|
43
|
+
namespace = ns;
|
|
44
|
+
ontologyDefinition = {
|
|
45
|
+
actionTypes: {},
|
|
46
|
+
objectTypes: {},
|
|
47
|
+
queryTypes: {},
|
|
48
|
+
interfaceTypes: {},
|
|
49
|
+
sharedPropertyTypes: {},
|
|
50
|
+
valueTypes: {},
|
|
51
|
+
importedTypes: {
|
|
52
|
+
sharedPropertyTypes: []
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
await body();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error("Unexpected error while processing the body of the ontology", e);
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
ontology: convertToWireOntologyIr(ontologyDefinition),
|
|
63
|
+
valueType: convertOntologyToValueTypeIr(ontologyDefinition)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function convertOntologyToValueTypeIr(ontology) {
|
|
67
|
+
return {
|
|
68
|
+
valueTypes: Object.values(ontology.valueTypes).map((definitions) => ({
|
|
69
|
+
metadata: {
|
|
70
|
+
apiName: definitions[0].apiName,
|
|
71
|
+
displayMetadata: definitions[0].displayMetadata,
|
|
72
|
+
status: definitions[0].status
|
|
73
|
+
},
|
|
74
|
+
versions: definitions.map((definition) => ({
|
|
75
|
+
version: definition.version,
|
|
76
|
+
baseType: definition.baseType,
|
|
77
|
+
constraints: definition.constraints,
|
|
78
|
+
exampleValues: definition.exampleValues
|
|
79
|
+
}))
|
|
80
|
+
}))
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function convertToWireOntologyIr(ontology) {
|
|
84
|
+
return {
|
|
85
|
+
blockData: {
|
|
86
|
+
objectTypes: Object.fromEntries(Object.entries(ontology.objectTypes).map(([apiName, objectType]) => {
|
|
87
|
+
return [apiName, convertObject(objectType)];
|
|
88
|
+
})),
|
|
89
|
+
sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {
|
|
90
|
+
sharedPropertyType: convertSpt(spt)
|
|
91
|
+
}])),
|
|
92
|
+
interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {
|
|
93
|
+
return [apiName, {
|
|
94
|
+
interfaceType: convertInterface(interfaceType)
|
|
95
|
+
}];
|
|
96
|
+
})),
|
|
97
|
+
blockPermissionInformation: {
|
|
98
|
+
actionTypes: {},
|
|
99
|
+
linkTypes: {},
|
|
100
|
+
objectTypes: {}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
importedTypes: ontology.importedTypes
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function convertObject(objectType) {
|
|
107
|
+
const propertyDatasource = {};
|
|
108
|
+
(objectType.properties ?? []).forEach((property) => {
|
|
109
|
+
propertyDatasource[property.apiName] = {
|
|
110
|
+
type: "column",
|
|
111
|
+
column: property.apiName
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
const datasource = {
|
|
115
|
+
rid: "ri.ontology.main.datasource.".concat(objectType.apiName),
|
|
116
|
+
datasource: {
|
|
117
|
+
type: "datasetV2",
|
|
118
|
+
datasetV2: {
|
|
119
|
+
datasetRid: objectType.apiName,
|
|
120
|
+
propertyMapping: propertyDatasource
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
editsConfiguration: {
|
|
124
|
+
onlyAllowPrivilegedEdits: false
|
|
125
|
+
},
|
|
126
|
+
redacted: false
|
|
127
|
+
};
|
|
128
|
+
const implementations = objectType.implementsInterfaces ?? [];
|
|
129
|
+
return {
|
|
130
|
+
objectType: {
|
|
131
|
+
displayMetadata: {
|
|
132
|
+
description: objectType.description,
|
|
133
|
+
displayName: objectType.displayName,
|
|
134
|
+
groupDisplayName: undefined,
|
|
135
|
+
icon: {
|
|
136
|
+
type: "blueprint",
|
|
137
|
+
blueprint: objectType.icon ?? {
|
|
138
|
+
locator: "cube",
|
|
139
|
+
color: "#2D72D2"
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
pluralDisplayName: objectType.pluralDisplayName,
|
|
143
|
+
visibility: objectType.visibility ?? "NORMAL"
|
|
144
|
+
},
|
|
145
|
+
primaryKeys: objectType.primaryKeys,
|
|
146
|
+
propertyTypes: Object.fromEntries(objectType.properties?.map((val) => [val.apiName, convertProperty(val)]) ?? []),
|
|
147
|
+
titlePropertyTypeRid: objectType.titlePropertyApiName,
|
|
148
|
+
apiName: objectType.apiName,
|
|
149
|
+
status: objectType.status ?? {
|
|
150
|
+
type: "active",
|
|
151
|
+
active: {}
|
|
152
|
+
},
|
|
153
|
+
redacted: false,
|
|
154
|
+
implementsInterfaces2: implementations.map((impl) => ({
|
|
155
|
+
interfaceTypeApiName: impl.implements.apiName,
|
|
156
|
+
properties: Object.fromEntries(impl.propertyMapping.map((mapping) => [namespace + mapping.interfaceProperty, {
|
|
157
|
+
propertyTypeRid: mapping.mapsTo
|
|
158
|
+
}]))
|
|
159
|
+
})),
|
|
160
|
+
allImplementsInterfaces: {}
|
|
161
|
+
},
|
|
162
|
+
datasources: [datasource],
|
|
163
|
+
entityMetadata: {
|
|
164
|
+
arePatchesEnabled: objectType.editsEnabled ?? false
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function convertProperty(property) {
|
|
169
|
+
const output = {
|
|
170
|
+
apiName: property.apiName,
|
|
171
|
+
sharedPropertyTypeApiName: property.sharedPropertyType?.apiName,
|
|
172
|
+
displayMetadata: {
|
|
173
|
+
displayName: property.displayName,
|
|
174
|
+
description: property.description,
|
|
175
|
+
visibility: property.visibility ?? "NORMAL"
|
|
176
|
+
},
|
|
177
|
+
indexedForSearch: property.indexedForSearch ?? true,
|
|
178
|
+
ruleSetBinding: undefined,
|
|
179
|
+
baseFormatter: property.baseFormatter,
|
|
180
|
+
type: convertType(property.type),
|
|
181
|
+
typeClasses: property.typeClasses ?? [],
|
|
182
|
+
status: property.status ?? {
|
|
183
|
+
type: "active",
|
|
184
|
+
active: {}
|
|
185
|
+
},
|
|
186
|
+
inlineAction: undefined,
|
|
187
|
+
dataConstraints: property.dataConstraints,
|
|
188
|
+
sharedPropertyTypeRid: property.sharedPropertyType?.apiName,
|
|
189
|
+
valueType: undefined
|
|
190
|
+
};
|
|
191
|
+
return output;
|
|
192
|
+
}
|
|
193
|
+
function convertInterface(interfaceType) {
|
|
194
|
+
return {
|
|
195
|
+
...interfaceType,
|
|
196
|
+
properties: Object.values(interfaceType.properties).map((spt) => convertSpt(spt)),
|
|
197
|
+
// these are omitted from our internal types but we need to re-add them for the final json
|
|
198
|
+
allExtendsInterfaces: [],
|
|
199
|
+
allLinks: [],
|
|
200
|
+
allProperties: []
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function convertSpt({
|
|
204
|
+
type,
|
|
205
|
+
array,
|
|
206
|
+
description,
|
|
207
|
+
apiName,
|
|
208
|
+
displayName,
|
|
209
|
+
gothamMapping,
|
|
210
|
+
typeClasses,
|
|
211
|
+
valueType
|
|
212
|
+
}) {
|
|
213
|
+
const dataConstraint = typeof type === "object" && type.type === "marking" ? {
|
|
214
|
+
propertyTypeConstraints: [],
|
|
215
|
+
nullability: undefined,
|
|
216
|
+
nullabilityV2: {
|
|
217
|
+
noEmptyCollections: true,
|
|
218
|
+
noNulls: true
|
|
219
|
+
}
|
|
220
|
+
} : undefined;
|
|
221
|
+
return {
|
|
222
|
+
apiName,
|
|
223
|
+
displayMetadata: {
|
|
224
|
+
displayName: displayName ?? apiName,
|
|
225
|
+
visibility: "NORMAL",
|
|
226
|
+
description
|
|
227
|
+
},
|
|
228
|
+
type: array ? {
|
|
229
|
+
type: "array",
|
|
230
|
+
array: {
|
|
231
|
+
subtype: convertType(type)
|
|
232
|
+
}
|
|
233
|
+
} : convertType(type),
|
|
234
|
+
aliases: [],
|
|
235
|
+
baseFormatter: undefined,
|
|
236
|
+
dataConstraints: dataConstraint,
|
|
237
|
+
gothamMapping,
|
|
238
|
+
indexedForSearch: true,
|
|
239
|
+
provenance: undefined,
|
|
240
|
+
typeClasses: typeClasses ?? [],
|
|
241
|
+
valueType
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function convertType(type) {
|
|
245
|
+
switch (true) {
|
|
246
|
+
case (typeof type === "object" && "markingType" in type):
|
|
247
|
+
return {
|
|
248
|
+
"type": "marking",
|
|
249
|
+
marking: {
|
|
250
|
+
markingType: type.markingType
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
case (typeof type === "object" && "structDefinition" in type):
|
|
254
|
+
const structFields = new Array();
|
|
255
|
+
for (const key in type.structDefinition) {
|
|
256
|
+
const fieldTypeDefinition = type.structDefinition[key];
|
|
257
|
+
let field;
|
|
258
|
+
if (typeof fieldTypeDefinition === "string") {
|
|
259
|
+
field = {
|
|
260
|
+
apiName: key,
|
|
261
|
+
displayMetadata: {
|
|
262
|
+
displayName: key,
|
|
263
|
+
description: undefined
|
|
264
|
+
},
|
|
265
|
+
typeClasses: [],
|
|
266
|
+
aliases: [],
|
|
267
|
+
fieldType: convertType(fieldTypeDefinition)
|
|
268
|
+
};
|
|
269
|
+
} else {
|
|
270
|
+
if ("fieldType" in fieldTypeDefinition) {
|
|
271
|
+
field = {
|
|
272
|
+
...fieldTypeDefinition,
|
|
273
|
+
apiName: key,
|
|
274
|
+
fieldType: convertType(fieldTypeDefinition.fieldType),
|
|
275
|
+
typeClasses: fieldTypeDefinition.typeClasses ?? [],
|
|
276
|
+
aliases: fieldTypeDefinition.aliases ?? []
|
|
277
|
+
};
|
|
278
|
+
} else {
|
|
279
|
+
field = {
|
|
280
|
+
apiName: key,
|
|
281
|
+
displayMetadata: {
|
|
282
|
+
displayName: key,
|
|
283
|
+
description: undefined
|
|
284
|
+
},
|
|
285
|
+
typeClasses: [],
|
|
286
|
+
aliases: [],
|
|
287
|
+
fieldType: convertType(fieldTypeDefinition)
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
structFields.push(field);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
type: "struct",
|
|
295
|
+
struct: {
|
|
296
|
+
structFields
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
case type === "geopoint":
|
|
300
|
+
return {
|
|
301
|
+
type: "geohash",
|
|
302
|
+
geohash: {}
|
|
303
|
+
};
|
|
304
|
+
case type === "decimal":
|
|
305
|
+
return {
|
|
306
|
+
type,
|
|
307
|
+
[type]: {
|
|
308
|
+
precision: undefined,
|
|
309
|
+
scale: undefined
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
case type === "string":
|
|
313
|
+
return {
|
|
314
|
+
type,
|
|
315
|
+
[type]: {
|
|
316
|
+
analyzerOverride: undefined,
|
|
317
|
+
enableAsciiFolding: undefined,
|
|
318
|
+
isLongText: false,
|
|
319
|
+
supportsEfficientLeadingWildcard: false,
|
|
320
|
+
supportsExactMatching: true
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
case type === "mediaReference":
|
|
324
|
+
return {
|
|
325
|
+
type,
|
|
326
|
+
mediaReference: {}
|
|
327
|
+
};
|
|
328
|
+
default:
|
|
329
|
+
return distributeTypeHelper(type);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function distributeTypeHelper(type) {
|
|
333
|
+
return {
|
|
334
|
+
type,
|
|
335
|
+
[type]: {}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
var defaultTypeClasses = [{
|
|
339
|
+
kind: "render_hint",
|
|
340
|
+
name: "SELECTABLE"
|
|
341
|
+
}, {
|
|
342
|
+
kind: "render_hint",
|
|
343
|
+
name: "SORTABLE"
|
|
344
|
+
}];
|
|
345
|
+
function defineSharedPropertyType(opts) {
|
|
346
|
+
const apiName = namespace + opts.apiName;
|
|
347
|
+
!(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Shared property type ${apiName} already exists`) : invariant2__default.default(false) : undefined;
|
|
348
|
+
return ontologyDefinition.sharedPropertyTypes[apiName] = {
|
|
349
|
+
...opts,
|
|
350
|
+
apiName,
|
|
351
|
+
nonNameSpacedApiName: opts.apiName,
|
|
352
|
+
displayName: opts.displayName ?? opts.apiName,
|
|
353
|
+
// This way the non-namespaced api name is the display name (maybe not ideal)
|
|
354
|
+
typeClasses: opts.typeClasses ?? defaultTypeClasses
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/api/defineInterface.ts
|
|
359
|
+
function defineInterface(opts) {
|
|
360
|
+
const apiName = namespace + opts.apiName;
|
|
361
|
+
!(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Interface ${apiName} already exists`) : invariant2__default.default(false) : undefined;
|
|
362
|
+
const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
|
|
363
|
+
if (typeof type === "string" || typeof type === "object" && !("apiName" in type)) {
|
|
364
|
+
!isPropertyTypeType(type) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Invalid data type ${JSON.stringify(type)} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant2__default.default(false) : undefined;
|
|
365
|
+
const spt = defineSharedPropertyType({
|
|
366
|
+
apiName: apiName2,
|
|
367
|
+
displayName: apiName2,
|
|
368
|
+
type,
|
|
369
|
+
array: false
|
|
370
|
+
});
|
|
371
|
+
return [apiName2, spt];
|
|
372
|
+
} else {
|
|
373
|
+
const unNamespacedTypeApiName = type.apiName.slice(type.apiName.lastIndexOf(".") + 1);
|
|
374
|
+
!(namespace + apiName2 === type.apiName || apiName2 === unNamespacedTypeApiName) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `property key and it's apiName must be identical. ${JSON.stringify({
|
|
375
|
+
key: apiName2,
|
|
376
|
+
apiName: type.apiName
|
|
377
|
+
})}`) : invariant2__default.default(false) : undefined;
|
|
378
|
+
return [apiName2, type];
|
|
379
|
+
}
|
|
380
|
+
}));
|
|
381
|
+
let extendsInterfaces = [];
|
|
382
|
+
if (opts.extends) {
|
|
383
|
+
if (typeof opts.extends === "string") {
|
|
384
|
+
extendsInterfaces = [opts.extends];
|
|
385
|
+
} else if (Array.isArray(opts.extends) && opts.extends.every((item) => typeof item === "string")) {
|
|
386
|
+
extendsInterfaces = opts.extends;
|
|
387
|
+
} else if (opts.extends.apiName !== undefined) {
|
|
388
|
+
extendsInterfaces = [opts.extends.apiName];
|
|
389
|
+
} else {
|
|
390
|
+
extendsInterfaces = opts.extends.map((item) => item.apiName);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const status = mapSimplifiedStatusToInterfaceTypeStatus(opts.status ?? {
|
|
394
|
+
type: "active"
|
|
395
|
+
});
|
|
396
|
+
!(status.type !== "deprecated" || status.deprecated.message && status.deprecated.deadline) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Deprecated status must include message and deadline properties.`) : invariant2__default.default(false) : undefined;
|
|
397
|
+
const a = {
|
|
398
|
+
apiName,
|
|
399
|
+
displayMetadata: {
|
|
400
|
+
displayName: opts.displayName ?? opts.apiName,
|
|
401
|
+
description: opts.description ?? opts.displayName ?? opts.apiName,
|
|
402
|
+
icon: opts.icon !== undefined ? {
|
|
403
|
+
type: "blueprint",
|
|
404
|
+
blueprint: {
|
|
405
|
+
color: opts.icon.color,
|
|
406
|
+
locator: opts.icon.locator
|
|
407
|
+
}
|
|
408
|
+
} : undefined
|
|
409
|
+
},
|
|
410
|
+
extendsInterfaces,
|
|
411
|
+
links: [],
|
|
412
|
+
properties,
|
|
413
|
+
status
|
|
414
|
+
};
|
|
415
|
+
return ontologyDefinition.interfaceTypes[apiName] = a;
|
|
416
|
+
}
|
|
417
|
+
function isPropertyTypeType(v) {
|
|
418
|
+
return v === "boolean" || v === "byte" || v === "date" || v === "decimal" || v === "double" || v === "float" || v === "geopoint" || v === "geoshape" || v === "integer" || v === "long" || typeof v === "object" && v.type === "marking" || v === "short" || v === "string" || v === "timestamp";
|
|
419
|
+
}
|
|
420
|
+
function mapSimplifiedStatusToInterfaceTypeStatus(status) {
|
|
421
|
+
switch (status.type) {
|
|
422
|
+
case "deprecated":
|
|
423
|
+
return {
|
|
424
|
+
type: "deprecated",
|
|
425
|
+
deprecated: {
|
|
426
|
+
message: status.message,
|
|
427
|
+
deadline: status.deadline,
|
|
428
|
+
replacedBy: undefined
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
case "active":
|
|
432
|
+
return {
|
|
433
|
+
type: "active",
|
|
434
|
+
active: {}
|
|
435
|
+
};
|
|
436
|
+
case "experimental":
|
|
437
|
+
return {
|
|
438
|
+
type: "experimental",
|
|
439
|
+
experimental: {}
|
|
440
|
+
};
|
|
441
|
+
default:
|
|
442
|
+
throw new Error(`Invalid status type: ${status.type}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function defineObject(objectDef) {
|
|
446
|
+
const apiName = namespace + objectDef.apiName;
|
|
447
|
+
const propertyApiNames = (objectDef.properties ?? []).map((val) => val.apiName);
|
|
448
|
+
if (ontologyDefinition.objectTypes[apiName] !== undefined) {
|
|
449
|
+
throw new Error(`Object type with apiName ${objectDef.apiName} is already defined`);
|
|
450
|
+
}
|
|
451
|
+
!propertyApiNames.includes(objectDef.titlePropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`) : invariant2__default.default(false) : undefined;
|
|
452
|
+
!(objectDef.primaryKeys.length !== 0) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `${objectDef.apiName} does not have any primary keys, objects must have at least one primary key`) : invariant2__default.default(false) : undefined;
|
|
453
|
+
const nonExistentPrimaryKeys = objectDef.primaryKeys.filter((primaryKey) => !objectDef.properties?.map((val) => val.apiName).includes(primaryKey));
|
|
454
|
+
!(nonExistentPrimaryKeys.length === 0) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Primary key properties ${nonExistentPrimaryKeys} do not exist on object ${objectDef.apiName}`) : invariant2__default.default(false) : undefined;
|
|
455
|
+
objectDef.implementsInterfaces?.forEach((interfaceImpl) => {
|
|
456
|
+
const nonExistentInterfaceProperties = interfaceImpl.propertyMapping.map((val) => val.interfaceProperty).filter((interfaceProperty) => interfaceImpl.implements.properties[interfaceProperty] === undefined).map((interfaceProp) => ({
|
|
457
|
+
type: "invalid",
|
|
458
|
+
reason: `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`
|
|
459
|
+
}));
|
|
460
|
+
const interfaceToObjectProperties = Object.fromEntries(interfaceImpl.propertyMapping.map((mapping) => [mapping.interfaceProperty, mapping.mapsTo]));
|
|
461
|
+
const validateProperty = (interfaceProp) => {
|
|
462
|
+
if (interfaceProp[1].nonNameSpacedApiName in interfaceToObjectProperties) {
|
|
463
|
+
return validateInterfaceImplProperty(interfaceProp[1], interfaceToObjectProperties[interfaceProp[0]], objectDef);
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
type: "invalid",
|
|
467
|
+
reason: `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp[1].nonNameSpacedApiName} not implemented by ${objectDef.apiName} object definition`
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
const baseValidations = Object.entries(interfaceImpl.implements.properties).map(validateProperty);
|
|
471
|
+
const extendsValidations = interfaceImpl.implements.extendsInterfaces.flatMap((interfaceApiName) => Object.entries(ontologyDefinition.interfaceTypes[interfaceApiName].properties).map(validateProperty));
|
|
472
|
+
const allFailedValidations = baseValidations.concat(extendsValidations, nonExistentInterfaceProperties).filter((val) => val.type === "invalid");
|
|
473
|
+
!(allFailedValidations.length === 0) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "\n" + allFailedValidations.map(formatValidationErrors).join("\n")) : invariant2__default.default(false) : undefined;
|
|
474
|
+
});
|
|
475
|
+
ontologyDefinition.objectTypes[apiName] = {
|
|
476
|
+
...objectDef,
|
|
477
|
+
apiName
|
|
478
|
+
};
|
|
479
|
+
return {
|
|
480
|
+
...objectDef,
|
|
481
|
+
apiName
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function formatValidationErrors(error) {
|
|
485
|
+
return `Ontology Definition Error: ${error.reason}
|
|
486
|
+
`;
|
|
487
|
+
}
|
|
488
|
+
function validateInterfaceImplProperty(spt, mappedObjectProp, object) {
|
|
489
|
+
const objProp = object.properties?.find((prop) => prop.apiName === mappedObjectProp);
|
|
490
|
+
if (objProp === undefined) {
|
|
491
|
+
return {
|
|
492
|
+
type: "invalid",
|
|
493
|
+
reason: `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (spt.type !== objProp?.type) {
|
|
497
|
+
return {
|
|
498
|
+
type: "invalid",
|
|
499
|
+
reason: `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
type: "valid"
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/cli/main.ts
|
|
508
|
+
var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
|
|
509
|
+
async function main(args = process.argv) {
|
|
510
|
+
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.9.0-beta.30").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
511
|
+
input: {
|
|
512
|
+
alias: "i",
|
|
513
|
+
describe: "Input file",
|
|
514
|
+
type: "string",
|
|
515
|
+
default: ".ontology/ontology.ts",
|
|
516
|
+
coerce: path__namespace.resolve
|
|
517
|
+
},
|
|
518
|
+
output: {
|
|
519
|
+
alias: "o",
|
|
520
|
+
describe: "Output file",
|
|
521
|
+
type: "string",
|
|
522
|
+
default: "ontology.json",
|
|
523
|
+
coerce: path__namespace.resolve
|
|
524
|
+
},
|
|
525
|
+
apiNamespace: {
|
|
526
|
+
describe: "Api name prefix for namespaced ontology types",
|
|
527
|
+
type: "string",
|
|
528
|
+
default: ""
|
|
529
|
+
},
|
|
530
|
+
snapshotDir: {
|
|
531
|
+
alias: "s",
|
|
532
|
+
describe: "Snapshot directory",
|
|
533
|
+
type: "string",
|
|
534
|
+
default: "snapshots",
|
|
535
|
+
coerce: path__namespace.resolve
|
|
536
|
+
},
|
|
537
|
+
valueTypesOutput: {
|
|
538
|
+
describe: "Value Type Output File",
|
|
539
|
+
type: "string",
|
|
540
|
+
default: "value-types.json",
|
|
541
|
+
coerce: path__namespace.resolve
|
|
542
|
+
}
|
|
543
|
+
}).parseAsync();
|
|
544
|
+
let apiNamespace = "";
|
|
545
|
+
if (commandLineOpts.apiNamespace.length !== 0) {
|
|
546
|
+
apiNamespace = commandLineOpts.apiNamespace.slice(-1) !== "." ? commandLineOpts.apiNamespace + "." : commandLineOpts.apiNamespace;
|
|
547
|
+
!(apiNamespace.length < 1024) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "API namespace is too long.") : invariant2__default.default(false) : undefined;
|
|
548
|
+
!apiNamespaceRegex.test(apiNamespace) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(.[a-z0-9-]+)*.$") : invariant2__default.default(false) : undefined;
|
|
549
|
+
}
|
|
550
|
+
consola.consola.info(`Loading ontology from ${commandLineOpts.input}`);
|
|
551
|
+
const ontology = await loadOntology(commandLineOpts.input, apiNamespace);
|
|
552
|
+
consola.consola.info(`Saving ontology to ${commandLineOpts.output}`);
|
|
553
|
+
await fs__namespace.writeFile(commandLineOpts.output, JSON.stringify(ontology.ontology, null, 2));
|
|
554
|
+
if (ontology.valueType.valueTypes.length > 0) {
|
|
555
|
+
await fs__namespace.writeFile(commandLineOpts.valueTypesOutput, JSON.stringify(ontology.valueType, null, 2));
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
async function loadOntology(input, apiNamespace) {
|
|
559
|
+
const q = await defineOntology(apiNamespace, async () => await import(input));
|
|
560
|
+
return q;
|
|
561
|
+
}
|
|
562
|
+
function importSharedPropertyType(opts) {
|
|
563
|
+
const {
|
|
564
|
+
apiName,
|
|
565
|
+
packageName,
|
|
566
|
+
typeHint
|
|
567
|
+
} = opts;
|
|
568
|
+
if (packageName !== undefined) {
|
|
569
|
+
ontologyDefinition.importedTypes.sharedPropertyTypes.push({
|
|
570
|
+
apiName,
|
|
571
|
+
packageName
|
|
572
|
+
});
|
|
573
|
+
!!packageName.endsWith(".") ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "Package name format invalid ends with period") : invariant2__default.default(false) : undefined;
|
|
574
|
+
!(packageName.match("[A-Z]") == null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "Package name includes upper case characters") : invariant2__default.default(false) : undefined;
|
|
575
|
+
return {
|
|
576
|
+
apiName: packageName + "." + apiName,
|
|
577
|
+
type: typeHint,
|
|
578
|
+
nonNameSpacedApiName: apiName
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
apiName,
|
|
583
|
+
type: typeHint,
|
|
584
|
+
nonNameSpacedApiName: apiName
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function defineInterfaceLinkConstraint(linkDef) {
|
|
588
|
+
const fromLinkMeta = getLinkMeta(linkDef);
|
|
589
|
+
!(linkDef.from.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`) : invariant2__default.default(false) : undefined;
|
|
590
|
+
linkDef.from.links.push({
|
|
591
|
+
cardinality: linkDef.toMany ? "MANY" : "SINGLE",
|
|
592
|
+
linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),
|
|
593
|
+
metadata: fromLinkMeta,
|
|
594
|
+
required: linkDef.required ?? true
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
function getLinkedType(t) {
|
|
598
|
+
return {
|
|
599
|
+
type: "interfaceType",
|
|
600
|
+
interfaceType: typeof t === "string" ? t : t.apiName
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function getLinkMeta(meta) {
|
|
604
|
+
return typeof meta === "string" ? withDefaults({
|
|
605
|
+
apiName: namespace + meta
|
|
606
|
+
}) : withDefaults(meta);
|
|
607
|
+
}
|
|
608
|
+
function withDefaults({
|
|
609
|
+
apiName,
|
|
610
|
+
description,
|
|
611
|
+
displayName
|
|
612
|
+
}) {
|
|
613
|
+
return {
|
|
614
|
+
apiName: namespace + apiName,
|
|
615
|
+
displayName: displayName ?? apiName,
|
|
616
|
+
description: description ?? displayName ?? apiName
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function convertValueTypeTypeToBaseType(valueType) {
|
|
620
|
+
switch (true) {
|
|
621
|
+
case (typeof valueType === "object" && valueType.type === "array"):
|
|
622
|
+
return {
|
|
623
|
+
type: "array",
|
|
624
|
+
array: {
|
|
625
|
+
elementType: convertValueTypeTypeToBaseType(valueType.elementType)
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
case (typeof valueType === "object" && valueType.type === "struct"):
|
|
629
|
+
return {
|
|
630
|
+
type: "structV2",
|
|
631
|
+
structV2: {
|
|
632
|
+
fields: valueType.fields.map((field) => ({
|
|
633
|
+
identifier: field.identifier,
|
|
634
|
+
baseType: convertValueTypeTypeToBaseType(field.baseType)
|
|
635
|
+
}))
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
case (typeof valueType === "object" && valueType.type === "map"):
|
|
639
|
+
return {
|
|
640
|
+
type: "map",
|
|
641
|
+
map: {
|
|
642
|
+
keyType: convertValueTypeTypeToBaseType(valueType.keyType),
|
|
643
|
+
valueType: convertValueTypeTypeToBaseType(valueType.valueType)
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
case (typeof valueType === "object" && valueType.type === "optional"):
|
|
647
|
+
return {
|
|
648
|
+
type: "optional",
|
|
649
|
+
optional: {
|
|
650
|
+
wrappedType: convertValueTypeTypeToBaseType(valueType.wrappedType)
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
case typeof valueType === "string":
|
|
654
|
+
return {
|
|
655
|
+
type: valueType,
|
|
656
|
+
[valueType]: {}
|
|
657
|
+
};
|
|
658
|
+
default:
|
|
659
|
+
throw new Error("Invalid ValueTypeType");
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function defineValueType(opts) {
|
|
663
|
+
const {
|
|
664
|
+
apiName,
|
|
665
|
+
displayName,
|
|
666
|
+
description,
|
|
667
|
+
type,
|
|
668
|
+
version
|
|
669
|
+
} = opts;
|
|
670
|
+
const semverValidation = /^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/;
|
|
671
|
+
!semverValidation.test(version) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "Version is not a valid semver") : invariant2__default.default(false) : undefined;
|
|
672
|
+
const typeName = typeof type.type === "string" ? type.type : type.type.type === "struct" ? "structV2" : type.type.type;
|
|
673
|
+
const constraints = type.constraints ? type.constraints.map((constraint) => {
|
|
674
|
+
const output = {
|
|
675
|
+
constraint: {
|
|
676
|
+
type: typeName,
|
|
677
|
+
[typeName]: constraint.constraint
|
|
678
|
+
},
|
|
679
|
+
failureMessage: constraint.failureMessage
|
|
680
|
+
};
|
|
681
|
+
return {
|
|
682
|
+
constraint: output
|
|
683
|
+
};
|
|
684
|
+
}) : [];
|
|
685
|
+
const baseType = convertValueTypeTypeToBaseType(type.type);
|
|
686
|
+
const vt = {
|
|
687
|
+
apiName,
|
|
688
|
+
displayMetadata: {
|
|
689
|
+
displayName,
|
|
690
|
+
description: description ?? ""
|
|
691
|
+
},
|
|
692
|
+
status: {
|
|
693
|
+
type: "active",
|
|
694
|
+
active: {}
|
|
695
|
+
},
|
|
696
|
+
version,
|
|
697
|
+
baseType,
|
|
698
|
+
constraints,
|
|
699
|
+
exampleValues: []
|
|
700
|
+
};
|
|
701
|
+
if (ontologyDefinition.valueTypes[apiName] === undefined) {
|
|
702
|
+
ontologyDefinition.valueTypes[apiName] = [];
|
|
703
|
+
}
|
|
704
|
+
ontologyDefinition.valueTypes[apiName].push(vt);
|
|
705
|
+
return vt;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
exports.default = main;
|
|
709
|
+
exports.defineInterface = defineInterface;
|
|
710
|
+
exports.defineInterfaceLinkConstraint = defineInterfaceLinkConstraint;
|
|
711
|
+
exports.defineObject = defineObject;
|
|
712
|
+
exports.defineSharedPropertyType = defineSharedPropertyType;
|
|
713
|
+
exports.defineValueType = defineValueType;
|
|
714
|
+
exports.importSharedPropertyType = importSharedPropertyType;
|
|
715
|
+
//# sourceMappingURL=index.cjs.map
|
|
716
|
+
//# sourceMappingURL=index.cjs.map
|