@osdk/maker-import 0.1.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/bin/maker-import.mjs +6 -0
- package/build/browser/cli/main.js +47 -0
- package/build/browser/cli/main.js.map +1 -0
- package/build/browser/generate/convertActionType.js +63 -0
- package/build/browser/generate/convertActionType.js.map +1 -0
- package/build/browser/generate/convertInterfaceType.js +74 -0
- package/build/browser/generate/convertInterfaceType.js.map +1 -0
- package/build/browser/generate/convertObjectType.js +64 -0
- package/build/browser/generate/convertObjectType.js.map +1 -0
- package/build/browser/generate/convertSharedPropertyType.js +37 -0
- package/build/browser/generate/convertSharedPropertyType.js.map +1 -0
- package/build/browser/generate/mapActionParameterType.js +211 -0
- package/build/browser/generate/mapActionParameterType.js.map +1 -0
- package/build/browser/generate/mapPropertyType.js +117 -0
- package/build/browser/generate/mapPropertyType.js.map +1 -0
- package/build/browser/generate/utils.js +52 -0
- package/build/browser/generate/utils.js.map +1 -0
- package/build/browser/generate/writeImportedOntology.js +169 -0
- package/build/browser/generate/writeImportedOntology.js.map +1 -0
- package/build/browser/index.js +19 -0
- package/build/browser/index.js.map +1 -0
- package/build/cjs/index.cjs +601 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +88 -0
- package/build/esm/cli/main.js +47 -0
- package/build/esm/cli/main.js.map +1 -0
- package/build/esm/generate/convertActionType.js +63 -0
- package/build/esm/generate/convertActionType.js.map +1 -0
- package/build/esm/generate/convertInterfaceType.js +74 -0
- package/build/esm/generate/convertInterfaceType.js.map +1 -0
- package/build/esm/generate/convertObjectType.js +64 -0
- package/build/esm/generate/convertObjectType.js.map +1 -0
- package/build/esm/generate/convertSharedPropertyType.js +37 -0
- package/build/esm/generate/convertSharedPropertyType.js.map +1 -0
- package/build/esm/generate/mapActionParameterType.js +211 -0
- package/build/esm/generate/mapActionParameterType.js.map +1 -0
- package/build/esm/generate/mapPropertyType.js +117 -0
- package/build/esm/generate/mapPropertyType.js.map +1 -0
- package/build/esm/generate/utils.js +52 -0
- package/build/esm/generate/utils.js.map +1 -0
- package/build/esm/generate/writeImportedOntology.js +169 -0
- package/build/esm/generate/writeImportedOntology.js.map +1 -0
- package/build/esm/index.js +19 -0
- package/build/esm/index.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var consola = require('consola');
|
|
6
|
+
var fs2 = require('fs/promises');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var yargs = require('yargs');
|
|
9
|
+
var helpers = require('yargs/helpers');
|
|
10
|
+
var maker = require('@osdk/maker');
|
|
11
|
+
var fs = require('fs');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
function _interopNamespace(e) {
|
|
16
|
+
if (e && e.__esModule) return e;
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n.default = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
|
|
34
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
35
|
+
var yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
36
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
37
|
+
|
|
38
|
+
// src/cli/main.ts
|
|
39
|
+
var SIMPLE_PARAM_TYPES = {
|
|
40
|
+
string: "string",
|
|
41
|
+
integer: "integer",
|
|
42
|
+
boolean: "boolean",
|
|
43
|
+
double: "double",
|
|
44
|
+
long: "long",
|
|
45
|
+
date: "date",
|
|
46
|
+
timestamp: "timestamp",
|
|
47
|
+
attachment: "attachment",
|
|
48
|
+
marking: "marking",
|
|
49
|
+
geohash: "geohash",
|
|
50
|
+
geoshape: "geoshape",
|
|
51
|
+
mediaReference: "mediaReference",
|
|
52
|
+
decimal: "decimal"
|
|
53
|
+
};
|
|
54
|
+
var LIST_VARIANT_MAP = {
|
|
55
|
+
string: "stringList",
|
|
56
|
+
integer: "integerList",
|
|
57
|
+
boolean: "booleanList",
|
|
58
|
+
double: "doubleList",
|
|
59
|
+
long: "longList",
|
|
60
|
+
date: "dateList",
|
|
61
|
+
timestamp: "timestampList",
|
|
62
|
+
attachment: "attachmentList",
|
|
63
|
+
marking: "markingList",
|
|
64
|
+
geohash: "geohashList",
|
|
65
|
+
geoshape: "geoshapeList",
|
|
66
|
+
mediaReference: "mediaReferenceList",
|
|
67
|
+
decimal: "decimalList"
|
|
68
|
+
};
|
|
69
|
+
var STRUCT_FIELD_IR_TYPES = {
|
|
70
|
+
boolean: "boolean",
|
|
71
|
+
integer: "integer",
|
|
72
|
+
long: "long",
|
|
73
|
+
double: "double",
|
|
74
|
+
string: "string",
|
|
75
|
+
geohash: "geohash",
|
|
76
|
+
geoshape: "geoshape",
|
|
77
|
+
timestamp: "timestamp",
|
|
78
|
+
date: "date"
|
|
79
|
+
};
|
|
80
|
+
function mapGatewayStructFieldsToIr(dataType) {
|
|
81
|
+
const fields = dataType.structFieldTypes;
|
|
82
|
+
if (!fields) {
|
|
83
|
+
consola.consola.warn("Struct parameter type missing structFieldTypes, skipping");
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const structFieldTypes = {};
|
|
87
|
+
for (const field of fields) {
|
|
88
|
+
const fieldType = field.dataType.type;
|
|
89
|
+
const irType = STRUCT_FIELD_IR_TYPES[fieldType];
|
|
90
|
+
if (irType) {
|
|
91
|
+
structFieldTypes[field.apiName] = {
|
|
92
|
+
type: irType,
|
|
93
|
+
[irType]: {}
|
|
94
|
+
};
|
|
95
|
+
} else if (fieldType === "object") {
|
|
96
|
+
const objectTypeApiName = field.dataType.objectTypeApiName ?? "";
|
|
97
|
+
structFieldTypes[field.apiName] = {
|
|
98
|
+
type: "objectReference",
|
|
99
|
+
objectReference: {
|
|
100
|
+
objectTypeId: objectTypeApiName
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
consola.consola.warn(`Skipping struct param field "${field.apiName}": unsupported type "${fieldType}"`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return structFieldTypes;
|
|
108
|
+
}
|
|
109
|
+
function mapActionParameterType(dataType) {
|
|
110
|
+
const simpleType = SIMPLE_PARAM_TYPES[dataType.type];
|
|
111
|
+
if (simpleType !== void 0) {
|
|
112
|
+
return simpleType;
|
|
113
|
+
}
|
|
114
|
+
switch (dataType.type) {
|
|
115
|
+
case "object": {
|
|
116
|
+
const objectTypeApiName = dataType.objectTypeApiName ?? "";
|
|
117
|
+
return {
|
|
118
|
+
type: "objectReference",
|
|
119
|
+
objectReference: {
|
|
120
|
+
objectTypeId: objectTypeApiName
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
case "objectSet": {
|
|
125
|
+
const objectTypeApiName = dataType.objectTypeApiName ?? "";
|
|
126
|
+
return {
|
|
127
|
+
type: "objectSetRid",
|
|
128
|
+
objectSetRid: {
|
|
129
|
+
objectTypeId: objectTypeApiName
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
case "interfaceObject": {
|
|
134
|
+
const interfaceApiName = dataType.interfaceApiName ?? "";
|
|
135
|
+
return {
|
|
136
|
+
type: "interfaceReference",
|
|
137
|
+
interfaceReference: {
|
|
138
|
+
interfaceTypeRid: interfaceApiName
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
case "array": {
|
|
143
|
+
const subType = dataType.subType;
|
|
144
|
+
if (!subType) {
|
|
145
|
+
consola.consola.warn("Array parameter type missing subType, skipping");
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
const listVariant = LIST_VARIANT_MAP[subType.type];
|
|
149
|
+
if (listVariant !== void 0) {
|
|
150
|
+
return listVariant;
|
|
151
|
+
}
|
|
152
|
+
if (subType.type === "object") {
|
|
153
|
+
const objectTypeApiName = subType.objectTypeApiName ?? "";
|
|
154
|
+
return {
|
|
155
|
+
type: "objectReferenceList",
|
|
156
|
+
objectReferenceList: {
|
|
157
|
+
objectTypeId: objectTypeApiName
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (subType.type === "interfaceObject") {
|
|
162
|
+
const interfaceApiName = subType.interfaceApiName ?? "";
|
|
163
|
+
return {
|
|
164
|
+
type: "interfaceReferenceList",
|
|
165
|
+
interfaceReferenceList: {
|
|
166
|
+
interfaceTypeRid: interfaceApiName
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (subType.type === "struct") {
|
|
171
|
+
const structFields = mapGatewayStructFieldsToIr(subType);
|
|
172
|
+
if (!structFields) return void 0;
|
|
173
|
+
return {
|
|
174
|
+
type: "structList",
|
|
175
|
+
structList: {
|
|
176
|
+
structFieldTypes: structFields
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
consola.consola.warn(`Skipping array parameter with unsupported subType: ${subType.type}`);
|
|
181
|
+
return void 0;
|
|
182
|
+
}
|
|
183
|
+
case "struct": {
|
|
184
|
+
const structFields = mapGatewayStructFieldsToIr(dataType);
|
|
185
|
+
if (!structFields) return void 0;
|
|
186
|
+
return {
|
|
187
|
+
type: "struct",
|
|
188
|
+
struct: {
|
|
189
|
+
structFieldTypes: structFields
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
case "vector":
|
|
194
|
+
consola.consola.warn("Skipping vector parameter type: no maker equivalent");
|
|
195
|
+
return void 0;
|
|
196
|
+
case "objectType":
|
|
197
|
+
return "objectTypeReference";
|
|
198
|
+
default:
|
|
199
|
+
consola.consola.warn(`Skipping unknown parameter type: ${dataType.type}`);
|
|
200
|
+
return void 0;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/generate/utils.ts
|
|
205
|
+
function withoutNamespace(apiName) {
|
|
206
|
+
const lastDot = apiName.lastIndexOf(".");
|
|
207
|
+
if (lastDot === -1) {
|
|
208
|
+
return apiName;
|
|
209
|
+
}
|
|
210
|
+
return apiName.substring(lastDot + 1);
|
|
211
|
+
}
|
|
212
|
+
function fullCamel(apiName) {
|
|
213
|
+
return camel(apiName.replace(/\./g, "-"));
|
|
214
|
+
}
|
|
215
|
+
function camel(str) {
|
|
216
|
+
if (!str) {
|
|
217
|
+
return str;
|
|
218
|
+
}
|
|
219
|
+
let result = str.replace(/[-_]+(.)?/g, (_, c) => c ? c.toUpperCase() : "");
|
|
220
|
+
result = result.charAt(0).toLowerCase() + result.slice(1);
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/generate/convertActionType.ts
|
|
225
|
+
function convertActionType(action) {
|
|
226
|
+
const parameters = [];
|
|
227
|
+
for (const [paramId, paramV2] of Object.entries(action.parameters)) {
|
|
228
|
+
const mappedType = mapActionParameterType(paramV2.dataType);
|
|
229
|
+
if (!mappedType) {
|
|
230
|
+
consola.consola.warn(`Skipping parameter "${paramId}" on action "${action.apiName}": unsupported type "${paramV2.dataType.type}"`);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
parameters.push({
|
|
234
|
+
id: paramId,
|
|
235
|
+
displayName: paramV2.displayName ?? paramId,
|
|
236
|
+
type: mappedType,
|
|
237
|
+
validation: {
|
|
238
|
+
required: paramV2.required
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const shortName = withoutNamespace(action.apiName);
|
|
243
|
+
return {
|
|
244
|
+
__type: maker.OntologyEntityTypeEnum.ACTION_TYPE,
|
|
245
|
+
apiName: action.apiName,
|
|
246
|
+
displayName: action.displayName ?? shortName,
|
|
247
|
+
status: mapActionStatus(action.status),
|
|
248
|
+
rules: [],
|
|
249
|
+
parameters
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function mapActionStatus(status) {
|
|
253
|
+
switch (status) {
|
|
254
|
+
case "ACTIVE":
|
|
255
|
+
return "active";
|
|
256
|
+
case "EXPERIMENTAL":
|
|
257
|
+
return "experimental";
|
|
258
|
+
default:
|
|
259
|
+
return "active";
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function mapPropertyType(dataType) {
|
|
263
|
+
switch (dataType.type) {
|
|
264
|
+
case "string":
|
|
265
|
+
return {
|
|
266
|
+
type: "string"
|
|
267
|
+
};
|
|
268
|
+
case "integer":
|
|
269
|
+
return {
|
|
270
|
+
type: "integer"
|
|
271
|
+
};
|
|
272
|
+
case "boolean":
|
|
273
|
+
return {
|
|
274
|
+
type: "boolean"
|
|
275
|
+
};
|
|
276
|
+
case "double":
|
|
277
|
+
return {
|
|
278
|
+
type: "double"
|
|
279
|
+
};
|
|
280
|
+
case "float":
|
|
281
|
+
return {
|
|
282
|
+
type: "float"
|
|
283
|
+
};
|
|
284
|
+
case "long":
|
|
285
|
+
return {
|
|
286
|
+
type: "long"
|
|
287
|
+
};
|
|
288
|
+
case "short":
|
|
289
|
+
return {
|
|
290
|
+
type: "short"
|
|
291
|
+
};
|
|
292
|
+
case "byte":
|
|
293
|
+
return {
|
|
294
|
+
type: "byte"
|
|
295
|
+
};
|
|
296
|
+
case "date":
|
|
297
|
+
return {
|
|
298
|
+
type: "date"
|
|
299
|
+
};
|
|
300
|
+
case "timestamp":
|
|
301
|
+
return {
|
|
302
|
+
type: "timestamp"
|
|
303
|
+
};
|
|
304
|
+
case "decimal":
|
|
305
|
+
return {
|
|
306
|
+
type: "decimal"
|
|
307
|
+
};
|
|
308
|
+
case "attachment":
|
|
309
|
+
return {
|
|
310
|
+
type: "attachment"
|
|
311
|
+
};
|
|
312
|
+
case "geopoint":
|
|
313
|
+
return {
|
|
314
|
+
type: "geopoint"
|
|
315
|
+
};
|
|
316
|
+
case "geoshape":
|
|
317
|
+
return {
|
|
318
|
+
type: "geoshape"
|
|
319
|
+
};
|
|
320
|
+
case "mediaReference":
|
|
321
|
+
return {
|
|
322
|
+
type: "mediaReference"
|
|
323
|
+
};
|
|
324
|
+
case "geotimeSeriesReference":
|
|
325
|
+
return {
|
|
326
|
+
type: "geotimeSeries"
|
|
327
|
+
};
|
|
328
|
+
case "array": {
|
|
329
|
+
const subType = dataType.subType;
|
|
330
|
+
if (!subType) {
|
|
331
|
+
consola.consola.warn("Array type missing subType, skipping");
|
|
332
|
+
return void 0;
|
|
333
|
+
}
|
|
334
|
+
const inner = mapPropertyType(subType);
|
|
335
|
+
if (!inner) {
|
|
336
|
+
return void 0;
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
type: inner.type,
|
|
340
|
+
array: true
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
// We don't support structs or markings here. It should have no influence on importing functionality
|
|
344
|
+
default:
|
|
345
|
+
return void 0;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/generate/convertSharedPropertyType.ts
|
|
350
|
+
function convertSharedPropertyType(spt) {
|
|
351
|
+
const mapped = mapPropertyType(spt.dataType);
|
|
352
|
+
if (!mapped) {
|
|
353
|
+
consola.consola.warn(`Skipping shared property type "${spt.apiName}": unsupported type "${spt.dataType.type}"`);
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
__type: maker.OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE,
|
|
358
|
+
apiName: spt.apiName,
|
|
359
|
+
nonNameSpacedApiName: withoutNamespace(spt.apiName),
|
|
360
|
+
displayName: spt.displayName ?? withoutNamespace(spt.apiName),
|
|
361
|
+
type: mapped.type,
|
|
362
|
+
array: mapped.array,
|
|
363
|
+
description: spt.description
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/generate/convertInterfaceType.ts
|
|
368
|
+
function convertInterfaceType(iface, allInterfaces) {
|
|
369
|
+
const shortName = withoutNamespace(iface.apiName);
|
|
370
|
+
const propertiesV2 = {};
|
|
371
|
+
const propertiesV3 = {};
|
|
372
|
+
for (const [sptApiName, sptDef] of Object.entries(iface.properties)) {
|
|
373
|
+
const converted = convertSharedPropertyType({
|
|
374
|
+
apiName: sptApiName,
|
|
375
|
+
displayName: sptDef.displayName,
|
|
376
|
+
description: sptDef.description,
|
|
377
|
+
dataType: sptDef.dataType
|
|
378
|
+
});
|
|
379
|
+
if (converted) {
|
|
380
|
+
const entry = {
|
|
381
|
+
sharedPropertyType: converted,
|
|
382
|
+
required: true
|
|
383
|
+
};
|
|
384
|
+
propertiesV2[sptApiName] = entry;
|
|
385
|
+
propertiesV3[withoutNamespace(sptApiName)] = entry;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const extendsInterfaces = [];
|
|
389
|
+
for (const extApiName of iface.extendsInterfaces) {
|
|
390
|
+
const extIface = allInterfaces[extApiName];
|
|
391
|
+
if (extIface) {
|
|
392
|
+
extendsInterfaces.push(convertInterfaceType(extIface, allInterfaces));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
__type: maker.OntologyEntityTypeEnum.INTERFACE_TYPE,
|
|
397
|
+
apiName: iface.apiName,
|
|
398
|
+
displayMetadata: {
|
|
399
|
+
displayName: iface.displayName ?? shortName,
|
|
400
|
+
description: iface.description ?? shortName
|
|
401
|
+
},
|
|
402
|
+
extendsInterfaces,
|
|
403
|
+
links: [],
|
|
404
|
+
status: {
|
|
405
|
+
type: "active",
|
|
406
|
+
active: {}
|
|
407
|
+
},
|
|
408
|
+
propertiesV2,
|
|
409
|
+
propertiesV3,
|
|
410
|
+
searchable: true
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function convertObjectType(fullMetadata) {
|
|
414
|
+
const obj = fullMetadata.objectType;
|
|
415
|
+
const properties = [];
|
|
416
|
+
for (const [propApiName, propV2] of Object.entries(obj.properties)) {
|
|
417
|
+
const mapped = mapPropertyType(propV2.dataType);
|
|
418
|
+
if (!mapped) {
|
|
419
|
+
consola.consola.warn(`Skipping property "${propApiName}" on object "${obj.apiName}": unsupported type "${propV2.dataType.type}"`);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const prop = {
|
|
423
|
+
apiName: propApiName,
|
|
424
|
+
displayName: propV2.displayName ?? propApiName,
|
|
425
|
+
type: mapped.type
|
|
426
|
+
};
|
|
427
|
+
if (mapped.array) {
|
|
428
|
+
prop.array = true;
|
|
429
|
+
}
|
|
430
|
+
properties.push(prop);
|
|
431
|
+
}
|
|
432
|
+
const shortName = withoutNamespace(obj.apiName);
|
|
433
|
+
return {
|
|
434
|
+
__type: maker.OntologyEntityTypeEnum.OBJECT_TYPE,
|
|
435
|
+
apiName: obj.apiName,
|
|
436
|
+
displayName: obj.displayName ?? shortName,
|
|
437
|
+
pluralDisplayName: (obj.displayName ?? shortName) + "s",
|
|
438
|
+
primaryKeyPropertyApiName: obj.primaryKey,
|
|
439
|
+
titlePropertyApiName: obj.titleProperty,
|
|
440
|
+
properties,
|
|
441
|
+
description: obj.description,
|
|
442
|
+
visibility: obj.visibility,
|
|
443
|
+
status: mapObjectStatus(obj.status)
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function mapObjectStatus(status) {
|
|
447
|
+
switch (status) {
|
|
448
|
+
case "ACTIVE":
|
|
449
|
+
return "active";
|
|
450
|
+
case "EXPERIMENTAL":
|
|
451
|
+
return "experimental";
|
|
452
|
+
default:
|
|
453
|
+
return "active";
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/generate/writeImportedOntology.ts
|
|
458
|
+
var TYPE_NAME_MAP = {
|
|
459
|
+
[maker.OntologyEntityTypeEnum.OBJECT_TYPE]: "ObjectType",
|
|
460
|
+
[maker.OntologyEntityTypeEnum.ACTION_TYPE]: "ActionType",
|
|
461
|
+
[maker.OntologyEntityTypeEnum.INTERFACE_TYPE]: "InterfaceType",
|
|
462
|
+
[maker.OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE]: "SharedPropertyType"
|
|
463
|
+
};
|
|
464
|
+
var DIR_NAME_MAP = {
|
|
465
|
+
[maker.OntologyEntityTypeEnum.OBJECT_TYPE]: "object-types",
|
|
466
|
+
[maker.OntologyEntityTypeEnum.ACTION_TYPE]: "action-types",
|
|
467
|
+
[maker.OntologyEntityTypeEnum.INTERFACE_TYPE]: "interface-types",
|
|
468
|
+
[maker.OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE]: "shared-property-types"
|
|
469
|
+
};
|
|
470
|
+
function resolveVarNames(apiNames) {
|
|
471
|
+
const shortNames = apiNames.map((n) => camel(withoutNamespace(n)));
|
|
472
|
+
const counts = /* @__PURE__ */ new Map();
|
|
473
|
+
for (const name of shortNames) {
|
|
474
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
475
|
+
}
|
|
476
|
+
const resolved = apiNames.map((apiName, i) => {
|
|
477
|
+
if (counts.get(shortNames[i]) > 1) {
|
|
478
|
+
return fullCamel(apiName);
|
|
479
|
+
}
|
|
480
|
+
return shortNames[i];
|
|
481
|
+
});
|
|
482
|
+
const finalNames = [];
|
|
483
|
+
const used = /* @__PURE__ */ new Map();
|
|
484
|
+
for (const name of resolved) {
|
|
485
|
+
const count = used.get(name) ?? 0;
|
|
486
|
+
finalNames.push(count === 0 ? name : `${name}${count}`);
|
|
487
|
+
used.set(name, count + 1);
|
|
488
|
+
}
|
|
489
|
+
return finalNames;
|
|
490
|
+
}
|
|
491
|
+
function writeImportedOntology(metadata, outputDir) {
|
|
492
|
+
const codegenDir = path__namespace.resolve(outputDir, "codegen");
|
|
493
|
+
for (const dirName of Object.values(DIR_NAME_MAP)) {
|
|
494
|
+
const dirPath = path__namespace.join(codegenDir, dirName);
|
|
495
|
+
if (fs__namespace.existsSync(dirPath)) {
|
|
496
|
+
fs__namespace.rmSync(dirPath, {
|
|
497
|
+
recursive: true,
|
|
498
|
+
force: true
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
fs__namespace.mkdirSync(dirPath, {
|
|
502
|
+
recursive: true
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const entries = [];
|
|
506
|
+
for (const [_apiName, spt] of Object.entries(metadata.sharedPropertyTypes)) {
|
|
507
|
+
const converted = convertSharedPropertyType(spt);
|
|
508
|
+
if (converted) {
|
|
509
|
+
entries.push({
|
|
510
|
+
apiName: converted.apiName,
|
|
511
|
+
entityType: maker.OntologyEntityTypeEnum.SHARED_PROPERTY_TYPE,
|
|
512
|
+
entity: converted
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
for (const [_apiName, iface] of Object.entries(metadata.interfaceTypes)) {
|
|
517
|
+
const converted = convertInterfaceType(iface, metadata.interfaceTypes);
|
|
518
|
+
entries.push({
|
|
519
|
+
apiName: converted.apiName,
|
|
520
|
+
entityType: maker.OntologyEntityTypeEnum.INTERFACE_TYPE,
|
|
521
|
+
entity: converted
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
for (const [_apiName, objFull] of Object.entries(metadata.objectTypes)) {
|
|
525
|
+
const converted = convertObjectType(objFull);
|
|
526
|
+
entries.push({
|
|
527
|
+
apiName: converted.apiName,
|
|
528
|
+
entityType: maker.OntologyEntityTypeEnum.OBJECT_TYPE,
|
|
529
|
+
entity: converted
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
for (const [_apiName, action] of Object.entries(metadata.actionTypes)) {
|
|
533
|
+
const converted = convertActionType(action);
|
|
534
|
+
entries.push({
|
|
535
|
+
apiName: converted.apiName,
|
|
536
|
+
entityType: maker.OntologyEntityTypeEnum.ACTION_TYPE,
|
|
537
|
+
entity: converted
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
const varNames = resolveVarNames(entries.map((e) => e.apiName));
|
|
541
|
+
const topLevelExports = [];
|
|
542
|
+
for (let i = 0; i < entries.length; i++) {
|
|
543
|
+
writeEntityFile(codegenDir, entries[i].entityType, entries[i].entity, varNames[i], topLevelExports);
|
|
544
|
+
}
|
|
545
|
+
if (topLevelExports.length > 0) {
|
|
546
|
+
const indexContent = topLevelExports.join("\n") + "\n";
|
|
547
|
+
const indexPath = path__namespace.join(outputDir, "index.ts");
|
|
548
|
+
fs__namespace.writeFileSync(indexPath, indexContent, {
|
|
549
|
+
flag: "w"
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function writeEntityFile(codegenDir, entityType, entity, varName, topLevelExports) {
|
|
554
|
+
const typeName = TYPE_NAME_MAP[entityType];
|
|
555
|
+
const dirName = DIR_NAME_MAP[entityType];
|
|
556
|
+
const entityJSON = JSON.stringify(entity, null, 2).replace(/("__type"\s*:\s*)"([^"]*)"/g, (_, prefix, value) => `${prefix}OntologyEntityTypeEnum.${value}`);
|
|
557
|
+
const content = `import { wrapWithProxy, OntologyEntityTypeEnum } from '@osdk/maker';
|
|
558
|
+
import type { ${typeName} } from '@osdk/maker';
|
|
559
|
+
|
|
560
|
+
/** @type {import('@osdk/maker').${typeName}} */
|
|
561
|
+
const ${varName}_base: ${typeName} = ${entityJSON} as unknown as ${typeName};
|
|
562
|
+
|
|
563
|
+
export const ${varName}: ${typeName} = wrapWithProxy(${varName}_base);
|
|
564
|
+
`;
|
|
565
|
+
const filePath = path__namespace.join(codegenDir, dirName, `${varName}.ts`);
|
|
566
|
+
fs__namespace.writeFileSync(filePath, content, {
|
|
567
|
+
flag: "w"
|
|
568
|
+
});
|
|
569
|
+
topLevelExports.push(`export { ${varName} } from "./codegen/${dirName}/${varName}.js";`);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/cli/main.ts
|
|
573
|
+
async function main(args = process.argv) {
|
|
574
|
+
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.1.0").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
575
|
+
input: {
|
|
576
|
+
alias: "i",
|
|
577
|
+
describe: "Path to OntologyFullMetadata JSON file",
|
|
578
|
+
type: "string",
|
|
579
|
+
demandOption: true,
|
|
580
|
+
coerce: path__namespace.resolve
|
|
581
|
+
},
|
|
582
|
+
output: {
|
|
583
|
+
alias: "o",
|
|
584
|
+
describe: "Output directory for generated TypeScript files",
|
|
585
|
+
type: "string",
|
|
586
|
+
default: "./generated-imports",
|
|
587
|
+
coerce: path__namespace.resolve
|
|
588
|
+
}
|
|
589
|
+
}).parseAsync();
|
|
590
|
+
consola.consola.info(`Reading OntologyFullMetadata from ${commandLineOpts.input}`);
|
|
591
|
+
const jsonContent = await fs2__namespace.readFile(commandLineOpts.input, "utf-8");
|
|
592
|
+
const metadata = JSON.parse(jsonContent);
|
|
593
|
+
consola.consola.info(`Writing generated imports to ${commandLineOpts.output}`);
|
|
594
|
+
writeImportedOntology(metadata, commandLineOpts.output);
|
|
595
|
+
consola.consola.success(`Generated import files in ${commandLineOpts.output}`);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
exports.default = main;
|
|
599
|
+
exports.writeImportedOntology = writeImportedOntology;
|
|
600
|
+
//# sourceMappingURL=index.cjs.map
|
|
601
|
+
//# sourceMappingURL=index.cjs.map
|