@nyrra/prismantix-cli 0.0.4-next.23 → 0.0.4-next.24
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/foundry-import/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/foundry-import/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EAYpB,eAAe,EACf,MAAM,YAAY,CAAC;AAOpB,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,oBAAoB,EAAE,GACjC,eAAe,CAkBjB"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { arrayField, isRecord } from "./utils.js";
|
|
2
|
+
const baseTypeFields = ["baseType", "dataType", "type"];
|
|
3
|
+
const dataTypeFields = ["dataType", "type"];
|
|
4
|
+
const interfaceTypeFields = ["type", "dataType", "fieldType"];
|
|
2
5
|
export function parseFoundryV2Export(input, diagnostics) {
|
|
3
6
|
if (!isRecord(input)) {
|
|
4
7
|
throw new Error("Expected a JSON object.");
|
|
5
8
|
}
|
|
9
|
+
if (isFoundryFullMetadataExport(input)) {
|
|
10
|
+
return parseFoundryFullMetadataExport(input, diagnostics);
|
|
11
|
+
}
|
|
6
12
|
const version = typeof input.version === "number" ? input.version : 0;
|
|
7
13
|
addVersionDiagnostic(version, input.version, diagnostics);
|
|
8
14
|
return {
|
|
@@ -15,6 +21,445 @@ export function parseFoundryV2Export(input, diagnostics) {
|
|
|
15
21
|
version,
|
|
16
22
|
};
|
|
17
23
|
}
|
|
24
|
+
function isFoundryFullMetadataExport(input) {
|
|
25
|
+
const objectTypes = input.objectTypes;
|
|
26
|
+
return (isRecord(objectTypes) &&
|
|
27
|
+
Object.values(objectTypes).some((value) => isRecord(value) && isRecord(value.objectType)));
|
|
28
|
+
}
|
|
29
|
+
function parseFoundryFullMetadataExport(input, diagnostics) {
|
|
30
|
+
const objectTypes = recordField(input, "objectTypes");
|
|
31
|
+
return {
|
|
32
|
+
actionTypes: recordValues(input, "actionTypes").map(fullMetadataActionType),
|
|
33
|
+
interfaces: recordValues(input, "interfaceTypes").map(fullMetadataInterface),
|
|
34
|
+
objectTypes: Object.values(objectTypes).map(fullMetadataObjectType),
|
|
35
|
+
relations: fullMetadataRelations(objectTypes, diagnostics),
|
|
36
|
+
sharedProperties: recordValues(input, "sharedPropertyTypes").map(fullMetadataSharedProperty),
|
|
37
|
+
typeGroups: arrayField(input, "typeGroups"),
|
|
38
|
+
version: 2,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function fullMetadataObjectType(value) {
|
|
42
|
+
const wrapper = isRecord(value) ? value : {};
|
|
43
|
+
const objectType = isRecord(wrapper.objectType)
|
|
44
|
+
? wrapper.objectType
|
|
45
|
+
: wrapper;
|
|
46
|
+
return {
|
|
47
|
+
aliases: stringArray(objectType.aliases),
|
|
48
|
+
apiName: stringField(objectType, "apiName"),
|
|
49
|
+
datasources: arrayField(objectType, "datasources"),
|
|
50
|
+
displayMetadata: fullMetadataDisplayMetadata(objectType),
|
|
51
|
+
interfaces: fullMetadataObjectInterfaces(wrapper),
|
|
52
|
+
primaryKeys: fullMetadataPrimaryKeys(objectType),
|
|
53
|
+
properties: recordEntries(objectType, "properties").map(([key, property]) => fullMetadataProperty(key, property)),
|
|
54
|
+
rid: stringField(objectType, "rid"),
|
|
55
|
+
status: fullMetadataStatus(objectType.status),
|
|
56
|
+
titlePropertyId: fullMetadataTitleProperty(objectType),
|
|
57
|
+
typeGroups: stringArray(objectType.typeGroups),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function fullMetadataPrimaryKeys(objectType) {
|
|
61
|
+
const primaryKey = stringField(objectType, "primaryKey");
|
|
62
|
+
return primaryKey ? [primaryKey] : stringArray(objectType.primaryKeys);
|
|
63
|
+
}
|
|
64
|
+
function fullMetadataTitleProperty(objectType) {
|
|
65
|
+
return firstStringField(objectType, ["titleProperty", "titlePropertyId"]);
|
|
66
|
+
}
|
|
67
|
+
function fullMetadataObjectInterfaces(wrapper) {
|
|
68
|
+
const implementsInterfaces = stringArray(wrapper.implementsInterfaces);
|
|
69
|
+
if (implementsInterfaces.length > 0) {
|
|
70
|
+
return implementsInterfaces;
|
|
71
|
+
}
|
|
72
|
+
const implementsInterfaces2 = wrapper.implementsInterfaces2;
|
|
73
|
+
return isRecord(implementsInterfaces2)
|
|
74
|
+
? Object.keys(implementsInterfaces2)
|
|
75
|
+
: [];
|
|
76
|
+
}
|
|
77
|
+
function fullMetadataProperty(apiName, value) {
|
|
78
|
+
const property = isRecord(value) ? value : {};
|
|
79
|
+
return {
|
|
80
|
+
apiName: stringFieldWithFallback(property, "apiName", apiName),
|
|
81
|
+
baseFormatter: property.baseFormatter,
|
|
82
|
+
baseType: fullMetadataBaseType(firstPresentValue(property, baseTypeFields)),
|
|
83
|
+
dataConstraints: dataConstraints(property),
|
|
84
|
+
displayMetadata: fullMetadataDisplayMetadata(property),
|
|
85
|
+
id: stringFieldWithFallback(property, "id", apiName),
|
|
86
|
+
indexedForSearch: booleanField(property, "indexedForSearch"),
|
|
87
|
+
renderHints: renderHints(property),
|
|
88
|
+
rid: stringField(property, "rid"),
|
|
89
|
+
source: recordOrUndefined(property.source),
|
|
90
|
+
status: fullMetadataStatus(property.status),
|
|
91
|
+
typeClasses: arrayField(property, "typeClasses"),
|
|
92
|
+
valueType: fullMetadataValueType(property),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function fullMetadataActionType(value) {
|
|
96
|
+
const action = isRecord(value) ? value : {};
|
|
97
|
+
return {
|
|
98
|
+
actionTypeLogic: {
|
|
99
|
+
logic: {
|
|
100
|
+
rules: arrayField(action, "operations").map((operation) => ({ type: operation.type })),
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
metadata: {
|
|
104
|
+
apiName: stringField(action, "apiName"),
|
|
105
|
+
displayMetadata: fullMetadataDisplayMetadata(action),
|
|
106
|
+
formContentInOrder: recordEntries(action, "parameters").map(([id, parameter]) => ({
|
|
107
|
+
parameter: fullMetadataActionParameter(id, parameter),
|
|
108
|
+
type: "parameter",
|
|
109
|
+
})),
|
|
110
|
+
rid: stringField(action, "rid"),
|
|
111
|
+
status: fullMetadataStatus(action.status),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function fullMetadataActionParameter(id, value) {
|
|
116
|
+
const parameter = isRecord(value) ? value : {};
|
|
117
|
+
return {
|
|
118
|
+
displayMetadata: fullMetadataDisplayMetadata(parameter),
|
|
119
|
+
id,
|
|
120
|
+
type: fullMetadataBaseType(firstPresentValue(parameter, dataTypeFields)),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function fullMetadataInterface(value) {
|
|
124
|
+
const interfaceType = isRecord(value) ? value : {};
|
|
125
|
+
return {
|
|
126
|
+
apiName: stringField(interfaceType, "apiName"),
|
|
127
|
+
displayMetadata: fullMetadataDisplayMetadata(interfaceType),
|
|
128
|
+
extendsInterfaces: stringArray(interfaceType.extendsInterfaces),
|
|
129
|
+
links: recordOrArrayValues(interfaceType.links),
|
|
130
|
+
properties: recordOrArrayValues(interfaceType.properties).map(fullMetadataInterfaceProperty),
|
|
131
|
+
rid: stringField(interfaceType, "rid"),
|
|
132
|
+
searchable: booleanField(interfaceType, "searchable"),
|
|
133
|
+
status: fullMetadataStatus(interfaceType.status),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function fullMetadataInterfaceProperty(value) {
|
|
137
|
+
const property = isRecord(value) ? value : {};
|
|
138
|
+
return {
|
|
139
|
+
displayName: stringField(property, "displayName"),
|
|
140
|
+
isSharedProperty: booleanField(property, "isSharedProperty"),
|
|
141
|
+
required: firstBooleanField(property, [
|
|
142
|
+
"required",
|
|
143
|
+
"requireImplementation",
|
|
144
|
+
]),
|
|
145
|
+
sharedPropertyRid: stringField(property, "sharedPropertyRid"),
|
|
146
|
+
type: fullMetadataBaseType(firstPresentValue(property, interfaceTypeFields)),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function fullMetadataSharedProperty(value) {
|
|
150
|
+
const property = isRecord(value) ? value : {};
|
|
151
|
+
return {
|
|
152
|
+
aliases: stringArray(property.aliases),
|
|
153
|
+
apiName: stringField(property, "apiName"),
|
|
154
|
+
baseType: fullMetadataBaseType(firstPresentValue(property, baseTypeFields)),
|
|
155
|
+
dataConstraints: dataConstraints(property),
|
|
156
|
+
displayMetadata: fullMetadataDisplayMetadata(property),
|
|
157
|
+
indexedForSearch: booleanField(property, "indexedForSearch"),
|
|
158
|
+
renderHints: renderHints(property),
|
|
159
|
+
rid: stringField(property, "rid"),
|
|
160
|
+
valueType: fullMetadataValueType(property),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function fullMetadataRelations(objectTypes, diagnostics) {
|
|
164
|
+
const groups = fullMetadataLinkGroups(objectTypes);
|
|
165
|
+
return [...groups.entries()].flatMap(([relationRid, links], relationIndex) => fullMetadataRelation(relationRid, links, relationIndex, diagnostics));
|
|
166
|
+
}
|
|
167
|
+
function fullMetadataLinkGroups(objectTypes) {
|
|
168
|
+
const groups = new Map();
|
|
169
|
+
for (const value of Object.values(objectTypes)) {
|
|
170
|
+
addFullMetadataObjectLinks(groups, value);
|
|
171
|
+
}
|
|
172
|
+
return groups;
|
|
173
|
+
}
|
|
174
|
+
function addFullMetadataObjectLinks(groups, value) {
|
|
175
|
+
const wrapper = isRecord(value) ? value : {};
|
|
176
|
+
const context = fullMetadataLinkContext(wrapper);
|
|
177
|
+
if (!context) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
for (const link of arrayField(wrapper, "linkTypes")) {
|
|
181
|
+
addFullMetadataLink(groups, context, link);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function addFullMetadataLink(groups, context, value) {
|
|
185
|
+
const linkRecord = isRecord(value) ? value : {};
|
|
186
|
+
const relationRid = fullMetadataRelationRid(context.sourceApiName, linkRecord);
|
|
187
|
+
const group = groups.get(relationRid) ?? [];
|
|
188
|
+
group.push({ link: linkRecord, ...context });
|
|
189
|
+
groups.set(relationRid, group);
|
|
190
|
+
}
|
|
191
|
+
function fullMetadataLinkContext(wrapper) {
|
|
192
|
+
const objectType = fullMetadataWrappedObjectType(wrapper);
|
|
193
|
+
const sourceApiName = stringField(objectType, "apiName");
|
|
194
|
+
const sourceRid = stringField(objectType, "rid");
|
|
195
|
+
return sourceApiName && sourceRid ? { sourceApiName, sourceRid } : undefined;
|
|
196
|
+
}
|
|
197
|
+
function fullMetadataRelationRid(sourceApiName, link) {
|
|
198
|
+
return (stringField(link, "linkTypeRid") ??
|
|
199
|
+
`${sourceApiName}:${stringFieldWithFallback(link, "apiName", "link")}`);
|
|
200
|
+
}
|
|
201
|
+
function fullMetadataRelation(relationRid, links, relationIndex, diagnostics) {
|
|
202
|
+
if (links.length !== 2) {
|
|
203
|
+
diagnostics.push({
|
|
204
|
+
code: "skipped.fullMetadataLinkGroup",
|
|
205
|
+
message: `Foundry full-metadata link group ${relationRid} has ${links.length} sides; expected 2.`,
|
|
206
|
+
path: `$.objectTypes.*.linkTypes[${relationIndex}]`,
|
|
207
|
+
severity: "warning",
|
|
208
|
+
});
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
const foreignKeySide = links.find((link) => Boolean(stringField(link.link, "foreignKeyPropertyApiName")));
|
|
212
|
+
if (foreignKeySide) {
|
|
213
|
+
return fullMetadataOneToManyRelation(relationRid, links, foreignKeySide);
|
|
214
|
+
}
|
|
215
|
+
return [fullMetadataManyToManyRelation(relationRid, linkPair(links))];
|
|
216
|
+
}
|
|
217
|
+
function fullMetadataManyToManyRelation(relationRid, [a, b]) {
|
|
218
|
+
return {
|
|
219
|
+
definition: {
|
|
220
|
+
manyToMany: {
|
|
221
|
+
objectTypeAToBLinkMetadata: fullMetadataLinkMetadata(a.link),
|
|
222
|
+
objectTypeBToALinkMetadata: fullMetadataLinkMetadata(b.link),
|
|
223
|
+
objectTypeRidA: a.sourceRid,
|
|
224
|
+
objectTypeRidB: b.sourceRid,
|
|
225
|
+
},
|
|
226
|
+
type: "manyToMany",
|
|
227
|
+
},
|
|
228
|
+
id: relationRid,
|
|
229
|
+
rid: relationRid,
|
|
230
|
+
status: fullMetadataStatus(firstPresentValueFromList([a.link, b.link], "status")),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function fullMetadataOneToManyRelation(relationRid, links, foreignKeySide) {
|
|
234
|
+
const oneSide = links.find((link) => link !== foreignKeySide);
|
|
235
|
+
if (!oneSide) {
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
return [
|
|
239
|
+
{
|
|
240
|
+
definition: {
|
|
241
|
+
oneToMany: {
|
|
242
|
+
cardinalityHint: stringField(oneSide.link, "cardinality") === "ONE"
|
|
243
|
+
? "ONE_TO_ONE"
|
|
244
|
+
: "ONE_TO_MANY",
|
|
245
|
+
manySideForeignKeyPropertyId: stringField(foreignKeySide.link, "foreignKeyPropertyApiName"),
|
|
246
|
+
manyToOneLinkMetadata: fullMetadataLinkMetadata(foreignKeySide.link),
|
|
247
|
+
objectTypeRidManySide: foreignKeySide.sourceRid,
|
|
248
|
+
objectTypeRidOneSide: oneSide.sourceRid,
|
|
249
|
+
oneToManyLinkMetadata: fullMetadataLinkMetadata(oneSide.link),
|
|
250
|
+
},
|
|
251
|
+
type: "oneToMany",
|
|
252
|
+
},
|
|
253
|
+
id: relationRid,
|
|
254
|
+
rid: relationRid,
|
|
255
|
+
status: fullMetadataStatus(foreignKeySide.link.status ?? oneSide.link.status),
|
|
256
|
+
},
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
function fullMetadataLinkMetadata(link) {
|
|
260
|
+
return {
|
|
261
|
+
apiName: stringField(link, "apiName"),
|
|
262
|
+
displayMetadata: fullMetadataDisplayMetadata(link),
|
|
263
|
+
typeClasses: arrayField(link, "typeClasses"),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function fullMetadataWrappedObjectType(value) {
|
|
267
|
+
const wrapper = isRecord(value) ? value : {};
|
|
268
|
+
return isRecord(wrapper.objectType) ? wrapper.objectType : wrapper;
|
|
269
|
+
}
|
|
270
|
+
function fullMetadataBaseType(value) {
|
|
271
|
+
const record = recordOrUndefined(value);
|
|
272
|
+
return record ? fullMetadataBaseTypeFromRecord(record) : undefined;
|
|
273
|
+
}
|
|
274
|
+
function fullMetadataBaseTypeFromRecord(value) {
|
|
275
|
+
const type = stringField(value, "type");
|
|
276
|
+
return type
|
|
277
|
+
? typedFullMetadataBaseType(value, type)
|
|
278
|
+
: value;
|
|
279
|
+
}
|
|
280
|
+
function typedFullMetadataBaseType(value, type) {
|
|
281
|
+
const normalizedType = normalizeFullMetadataType(type);
|
|
282
|
+
return {
|
|
283
|
+
...value,
|
|
284
|
+
...fullMetadataBaseTypeExtras(value, normalizedType),
|
|
285
|
+
type: normalizedType,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function fullMetadataBaseTypeExtras(value, type) {
|
|
289
|
+
const extras = {
|
|
290
|
+
ARRAY: () => ({ subType: fullMetadataBaseType(value.subType) }),
|
|
291
|
+
STRUCT: () => ({
|
|
292
|
+
structFields: recordOrArrayValues(value.fields).map((field) => fullMetadataStructField(field)),
|
|
293
|
+
}),
|
|
294
|
+
};
|
|
295
|
+
return extras[type]?.() ?? {};
|
|
296
|
+
}
|
|
297
|
+
function fullMetadataStructField(value) {
|
|
298
|
+
const field = isRecord(value) ? value : {};
|
|
299
|
+
return {
|
|
300
|
+
apiName: stringField(field, "apiName") ?? stringField(field, "name"),
|
|
301
|
+
displayMetadata: fullMetadataDisplayMetadata(field),
|
|
302
|
+
fieldType: fullMetadataBaseType(field.fieldType ?? field.dataType),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function normalizeFullMetadataType(type) {
|
|
306
|
+
const typeMap = {
|
|
307
|
+
array: "ARRAY",
|
|
308
|
+
attachment: "ATTACHMENT",
|
|
309
|
+
boolean: "BOOLEAN",
|
|
310
|
+
date: "DATE",
|
|
311
|
+
double: "DOUBLE",
|
|
312
|
+
geohash: "GEOHASH",
|
|
313
|
+
geopoint: "GEOHASH",
|
|
314
|
+
geoshape: "GEOSHAPE",
|
|
315
|
+
integer: "INTEGER",
|
|
316
|
+
long: "LONG",
|
|
317
|
+
marking: "MARKING",
|
|
318
|
+
mediaReference: "MEDIA_REFERENCE",
|
|
319
|
+
string: "STRING",
|
|
320
|
+
struct: "STRUCT",
|
|
321
|
+
timestamp: "TIMESTAMP",
|
|
322
|
+
vector: "VECTOR",
|
|
323
|
+
};
|
|
324
|
+
return typeMap[type] ?? type;
|
|
325
|
+
}
|
|
326
|
+
function fullMetadataStatus(value) {
|
|
327
|
+
const type = fullMetadataStatusType(value);
|
|
328
|
+
return type
|
|
329
|
+
? { ...fullMetadataStatusRecord(value), type: type.toLowerCase() }
|
|
330
|
+
: undefined;
|
|
331
|
+
}
|
|
332
|
+
function fullMetadataStatusRecord(value) {
|
|
333
|
+
return isRecord(value) ? value : {};
|
|
334
|
+
}
|
|
335
|
+
function fullMetadataStatusType(value) {
|
|
336
|
+
return typeof value === "string"
|
|
337
|
+
? nonEmptyString(value)
|
|
338
|
+
: stringField(fullMetadataStatusRecord(value), "type");
|
|
339
|
+
}
|
|
340
|
+
function fullMetadataDisplayMetadata(record) {
|
|
341
|
+
const nested = recordOrUndefined(record.displayMetadata);
|
|
342
|
+
return nested ? nested : displayMetadataFromTopLevelFields(record);
|
|
343
|
+
}
|
|
344
|
+
function displayMetadataFromTopLevelFields(record) {
|
|
345
|
+
const displayMetadata = {
|
|
346
|
+
description: nullableStringField(record, "description"),
|
|
347
|
+
displayName: nullableStringField(record, "displayName"),
|
|
348
|
+
groupDisplayName: nullableStringField(record, "groupDisplayName"),
|
|
349
|
+
icon: definedValue(record.icon),
|
|
350
|
+
pluralDisplayName: nullableStringField(record, "pluralDisplayName"),
|
|
351
|
+
visibility: nullableStringField(record, "visibility"),
|
|
352
|
+
};
|
|
353
|
+
const compact = compactRecord(displayMetadata);
|
|
354
|
+
return Object.keys(compact).length > 0
|
|
355
|
+
? compact
|
|
356
|
+
: undefined;
|
|
357
|
+
}
|
|
358
|
+
function linkPair(links) {
|
|
359
|
+
return [links[0], links[1]];
|
|
360
|
+
}
|
|
361
|
+
function fullMetadataValueType(record) {
|
|
362
|
+
const explicit = record.valueType;
|
|
363
|
+
return explicit === undefined ? valueTypeReference(record) : explicit;
|
|
364
|
+
}
|
|
365
|
+
function firstPresentValue(record, keys) {
|
|
366
|
+
for (const key of keys) {
|
|
367
|
+
const value = record[key];
|
|
368
|
+
if (value !== undefined) {
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
function firstPresentValueFromList(records, key) {
|
|
375
|
+
for (const record of records) {
|
|
376
|
+
const value = record[key];
|
|
377
|
+
if (value !== undefined) {
|
|
378
|
+
return value;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return undefined;
|
|
382
|
+
}
|
|
383
|
+
function firstStringField(record, keys) {
|
|
384
|
+
for (const key of keys) {
|
|
385
|
+
const value = stringField(record, key);
|
|
386
|
+
if (value) {
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
function firstBooleanField(record, keys) {
|
|
393
|
+
for (const key of keys) {
|
|
394
|
+
const value = booleanField(record, key);
|
|
395
|
+
if (value !== undefined) {
|
|
396
|
+
return value;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
function stringFieldWithFallback(record, key, fallback) {
|
|
402
|
+
return stringField(record, key) ?? fallback;
|
|
403
|
+
}
|
|
404
|
+
function recordOrUndefined(value) {
|
|
405
|
+
return isRecord(value) ? value : undefined;
|
|
406
|
+
}
|
|
407
|
+
function nonEmptyString(value) {
|
|
408
|
+
return value === "" ? undefined : value;
|
|
409
|
+
}
|
|
410
|
+
function nullableStringField(record, key) {
|
|
411
|
+
const value = record[key];
|
|
412
|
+
return typeof value === "string" || value === null ? value : undefined;
|
|
413
|
+
}
|
|
414
|
+
function definedValue(value) {
|
|
415
|
+
return value === undefined ? undefined : value;
|
|
416
|
+
}
|
|
417
|
+
function compactRecord(record) {
|
|
418
|
+
return Object.fromEntries(Object.entries(record).filter((entry) => entry[1] !== undefined));
|
|
419
|
+
}
|
|
420
|
+
function dataConstraints(record) {
|
|
421
|
+
return isRecord(record.dataConstraints) ? record.dataConstraints : undefined;
|
|
422
|
+
}
|
|
423
|
+
function valueTypeReference(record) {
|
|
424
|
+
const valueTypeApiName = stringField(record, "valueTypeApiName");
|
|
425
|
+
return valueTypeApiName ? { apiName: valueTypeApiName } : undefined;
|
|
426
|
+
}
|
|
427
|
+
function renderHints(record) {
|
|
428
|
+
const explicit = stringArray(record.renderHints);
|
|
429
|
+
if (explicit.length > 0) {
|
|
430
|
+
return explicit;
|
|
431
|
+
}
|
|
432
|
+
return arrayField(record, "typeClasses").flatMap((typeClass) => typeClass.kind === "render_hint" && typeClass.name ? [typeClass.name] : []);
|
|
433
|
+
}
|
|
434
|
+
function recordField(record, key) {
|
|
435
|
+
const value = record[key];
|
|
436
|
+
return isRecord(value) ? value : {};
|
|
437
|
+
}
|
|
438
|
+
function recordValues(record, key) {
|
|
439
|
+
return Object.values(recordField(record, key));
|
|
440
|
+
}
|
|
441
|
+
function recordEntries(record, key) {
|
|
442
|
+
return Object.entries(recordField(record, key));
|
|
443
|
+
}
|
|
444
|
+
function recordOrArrayValues(value) {
|
|
445
|
+
if (Array.isArray(value)) {
|
|
446
|
+
return value;
|
|
447
|
+
}
|
|
448
|
+
return isRecord(value) ? Object.values(value) : [];
|
|
449
|
+
}
|
|
450
|
+
function stringField(record, key) {
|
|
451
|
+
const value = record[key];
|
|
452
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
453
|
+
}
|
|
454
|
+
function booleanField(record, key) {
|
|
455
|
+
const value = record[key];
|
|
456
|
+
return typeof value === "boolean" ? value : undefined;
|
|
457
|
+
}
|
|
458
|
+
function stringArray(value) {
|
|
459
|
+
return Array.isArray(value)
|
|
460
|
+
? value.filter((item) => typeof item === "string")
|
|
461
|
+
: [];
|
|
462
|
+
}
|
|
18
463
|
function addVersionDiagnostic(version, rawVersion, diagnostics) {
|
|
19
464
|
if (version === 2) {
|
|
20
465
|
return;
|
package/oclif.manifest.json
CHANGED