@player-tools/xlr-sdk 0.2.1-next.4 → 0.2.1
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/dist/index.cjs.js +236 -162
- package/dist/index.d.ts +66 -6
- package/dist/index.esm.js +237 -145
- package/package.json +4 -4
- package/src/registry/basic-registry.ts +0 -1
- package/src/sdk.ts +152 -27
- package/src/utils.ts +104 -43
- package/src/validator.ts +53 -76
package/dist/index.esm.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { isPrimitiveTypeNode, resolveConditional, makePropertyMap,
|
|
1
|
+
import { isPrimitiveTypeNode, resolveConditional, makePropertyMap, computeEffectiveObject, resolveReferenceNode, fillInGenerics } from '@player-tools/xlr-utils';
|
|
2
2
|
import { TSWriter } from '@player-tools/xlr-converters';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import ts from 'typescript';
|
|
6
6
|
|
|
7
|
-
var __defProp$
|
|
8
|
-
var __getOwnPropSymbols$
|
|
9
|
-
var __hasOwnProp$
|
|
10
|
-
var __propIsEnum$
|
|
11
|
-
var __defNormalProp$
|
|
12
|
-
var __spreadValues$
|
|
7
|
+
var __defProp$3 = Object.defineProperty;
|
|
8
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
9
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues$3 = (a, b) => {
|
|
13
13
|
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp$
|
|
15
|
-
__defNormalProp$
|
|
16
|
-
if (__getOwnPropSymbols$
|
|
17
|
-
for (var prop of __getOwnPropSymbols$
|
|
18
|
-
if (__propIsEnum$
|
|
19
|
-
__defNormalProp$
|
|
14
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
15
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols$3)
|
|
17
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
18
|
+
if (__propIsEnum$3.call(b, prop))
|
|
19
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
20
20
|
}
|
|
21
21
|
return a;
|
|
22
22
|
};
|
|
@@ -28,7 +28,7 @@ class BasicXLRRegistry {
|
|
|
28
28
|
}
|
|
29
29
|
get(id) {
|
|
30
30
|
const value = this.typeMap.get(id);
|
|
31
|
-
return value ? __spreadValues$
|
|
31
|
+
return value ? __spreadValues$3({}, value) : void 0;
|
|
32
32
|
}
|
|
33
33
|
add(type, plugin, capability) {
|
|
34
34
|
this.typeMap.set(type.name, type);
|
|
@@ -68,28 +68,28 @@ class BasicXLRRegistry {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
var __defProp = Object.defineProperty;
|
|
72
|
-
var __defProps = Object.defineProperties;
|
|
73
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
74
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
75
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
76
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
77
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
78
|
-
var __spreadValues = (a, b) => {
|
|
71
|
+
var __defProp$2 = Object.defineProperty;
|
|
72
|
+
var __defProps$2 = Object.defineProperties;
|
|
73
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
74
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
75
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
76
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
77
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
78
|
+
var __spreadValues$2 = (a, b) => {
|
|
79
79
|
for (var prop in b || (b = {}))
|
|
80
|
-
if (__hasOwnProp.call(b, prop))
|
|
81
|
-
__defNormalProp(a, prop, b[prop]);
|
|
82
|
-
if (__getOwnPropSymbols)
|
|
83
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
84
|
-
if (__propIsEnum.call(b, prop))
|
|
85
|
-
__defNormalProp(a, prop, b[prop]);
|
|
80
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
81
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
82
|
+
if (__getOwnPropSymbols$2)
|
|
83
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
84
|
+
if (__propIsEnum$2.call(b, prop))
|
|
85
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
86
86
|
}
|
|
87
87
|
return a;
|
|
88
88
|
};
|
|
89
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
89
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
90
90
|
class XLRValidator {
|
|
91
|
-
constructor(
|
|
92
|
-
this.
|
|
91
|
+
constructor(resolveType) {
|
|
92
|
+
this.resolveType = resolveType;
|
|
93
93
|
this.regexCache = new Map();
|
|
94
94
|
}
|
|
95
95
|
validateType(rootNode, xlrNode) {
|
|
@@ -130,7 +130,7 @@ class XLRValidator {
|
|
|
130
130
|
message: `Does not match any of the expected types for type: '${xlrNode.name}'`
|
|
131
131
|
});
|
|
132
132
|
} else if (xlrNode.type === "and") {
|
|
133
|
-
const effectiveType = this.computeIntersectionType(xlrNode.and);
|
|
133
|
+
const effectiveType = __spreadValues$2(__spreadValues$2({}, this.computeIntersectionType(xlrNode.and)), xlrNode.name ? { name: xlrNode.name } : {});
|
|
134
134
|
validationIssues.push(...this.validateType(rootNode, effectiveType));
|
|
135
135
|
} else if (xlrNode.type === "record") {
|
|
136
136
|
(_a = rootNode.children) == null ? void 0 : _a.forEach((child) => {
|
|
@@ -166,11 +166,24 @@ class XLRValidator {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
} else if (xlrNode.type === "conditional") {
|
|
169
|
-
|
|
170
|
-
if (
|
|
169
|
+
let { right, left } = xlrNode.check;
|
|
170
|
+
if (right.type === "ref") {
|
|
171
|
+
right = this.getRefType(right);
|
|
172
|
+
}
|
|
173
|
+
if (left.type === "ref") {
|
|
174
|
+
left = this.getRefType(left);
|
|
175
|
+
}
|
|
176
|
+
const resolvedXLRNode = __spreadProps$2(__spreadValues$2({}, xlrNode), {
|
|
177
|
+
check: {
|
|
178
|
+
left,
|
|
179
|
+
right
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const resolvedConditional = resolveConditional(resolvedXLRNode);
|
|
183
|
+
if (resolvedConditional === resolvedXLRNode) {
|
|
171
184
|
throw Error(`Unable to resolve conditional type at runtime: ${xlrNode.name}`);
|
|
172
185
|
}
|
|
173
|
-
validationIssues.push(...this.validateType(rootNode,
|
|
186
|
+
validationIssues.push(...this.validateType(rootNode, resolvedConditional));
|
|
174
187
|
} else {
|
|
175
188
|
throw Error(`Unknown type ${xlrNode.type}`);
|
|
176
189
|
}
|
|
@@ -206,7 +219,7 @@ class XLRValidator {
|
|
|
206
219
|
let effectiveXLRNode = xlrNode;
|
|
207
220
|
if (xlrNode.extends) {
|
|
208
221
|
const extendedNode = this.getRefType(xlrNode.extends);
|
|
209
|
-
effectiveXLRNode =
|
|
222
|
+
effectiveXLRNode = computeEffectiveObject(extendedNode, xlrNode);
|
|
210
223
|
}
|
|
211
224
|
for (const prop in effectiveXLRNode.properties) {
|
|
212
225
|
const expectedType = effectiveXLRNode.properties[prop];
|
|
@@ -267,19 +280,14 @@ class XLRValidator {
|
|
|
267
280
|
}
|
|
268
281
|
getRefType(ref) {
|
|
269
282
|
let refName = ref.ref;
|
|
270
|
-
const { genericArguments } = ref;
|
|
271
283
|
if (refName.indexOf("<") > 0) {
|
|
272
284
|
[refName] = refName.split("<");
|
|
273
285
|
}
|
|
274
|
-
const actualType = this.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
actualType.genericTokens.forEach((token, index) => {
|
|
278
|
-
var _a, _b;
|
|
279
|
-
genericMap.set(token.symbol, (_b = (_a = genericArguments[index]) != null ? _a : token.default) != null ? _b : token.constraints);
|
|
280
|
-
});
|
|
286
|
+
const actualType = this.resolveType(refName);
|
|
287
|
+
if (!actualType) {
|
|
288
|
+
throw new Error(`Error: can't resolve type reference ${refName}`);
|
|
281
289
|
}
|
|
282
|
-
return
|
|
290
|
+
return resolveReferenceNode(ref, actualType);
|
|
283
291
|
}
|
|
284
292
|
getRegex(expString) {
|
|
285
293
|
if (this.regexCache.has(expString)) {
|
|
@@ -297,6 +305,12 @@ class XLRValidator {
|
|
|
297
305
|
}
|
|
298
306
|
if (firstElement.type === "and") {
|
|
299
307
|
effectiveType = this.computeIntersectionType(firstElement.and);
|
|
308
|
+
} else if (firstElement.type === "record") {
|
|
309
|
+
effectiveType = {
|
|
310
|
+
type: "object",
|
|
311
|
+
properties: {},
|
|
312
|
+
additionalProperties: firstElement.valueType
|
|
313
|
+
};
|
|
300
314
|
} else if (firstElement.type !== "or" && firstElement.type !== "object") {
|
|
301
315
|
throw new Error(`Can't compute a union with a non-object type ${firstElement.type} (${firstElement.name})`);
|
|
302
316
|
} else {
|
|
@@ -304,6 +318,13 @@ class XLRValidator {
|
|
|
304
318
|
}
|
|
305
319
|
types.slice(1).forEach((type) => {
|
|
306
320
|
let typeToApply = type;
|
|
321
|
+
if (typeToApply.type === "record") {
|
|
322
|
+
typeToApply = {
|
|
323
|
+
type: "object",
|
|
324
|
+
properties: {},
|
|
325
|
+
additionalProperties: typeToApply.valueType
|
|
326
|
+
};
|
|
327
|
+
}
|
|
307
328
|
if (type.type === "ref") {
|
|
308
329
|
typeToApply = this.getRefType(type);
|
|
309
330
|
}
|
|
@@ -312,15 +333,15 @@ class XLRValidator {
|
|
|
312
333
|
}
|
|
313
334
|
if (typeToApply.type === "object") {
|
|
314
335
|
if (effectiveType.type === "object") {
|
|
315
|
-
effectiveType =
|
|
336
|
+
effectiveType = computeEffectiveObject(effectiveType, typeToApply);
|
|
316
337
|
} else {
|
|
317
|
-
effectiveType = __spreadProps(__spreadValues({}, effectiveType), {
|
|
338
|
+
effectiveType = __spreadProps$2(__spreadValues$2({}, effectiveType), {
|
|
318
339
|
or: effectiveType.or.map((y) => this.computeIntersectionType([y, typeToApply]))
|
|
319
340
|
});
|
|
320
341
|
}
|
|
321
342
|
} else if (typeToApply.type === "or") {
|
|
322
343
|
if (effectiveType.type === "object") {
|
|
323
|
-
effectiveType = __spreadProps(__spreadValues({}, typeToApply), {
|
|
344
|
+
effectiveType = __spreadProps$2(__spreadValues$2({}, typeToApply), {
|
|
324
345
|
or: typeToApply.or.map((y) => this.computeIntersectionType([y, effectiveType]))
|
|
325
346
|
});
|
|
326
347
|
} else {
|
|
@@ -332,32 +353,130 @@ class XLRValidator {
|
|
|
332
353
|
});
|
|
333
354
|
return effectiveType;
|
|
334
355
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
var __defProp$1 = Object.defineProperty;
|
|
359
|
+
var __defProps$1 = Object.defineProperties;
|
|
360
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
361
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
362
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
363
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
364
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
365
|
+
var __spreadValues$1 = (a, b) => {
|
|
366
|
+
for (var prop in b || (b = {}))
|
|
367
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
368
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
369
|
+
if (__getOwnPropSymbols$1)
|
|
370
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
371
|
+
if (__propIsEnum$1.call(b, prop))
|
|
372
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
348
373
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
374
|
+
return a;
|
|
375
|
+
};
|
|
376
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
377
|
+
function simpleTransformGenerator(typeToTransform, capabilityToTransform, functionToRun) {
|
|
378
|
+
const walker = (n, capability) => {
|
|
379
|
+
var _a;
|
|
380
|
+
if (capability === capabilityToTransform) {
|
|
381
|
+
let node = __spreadValues$1({}, n);
|
|
382
|
+
if (node.type === typeToTransform) {
|
|
383
|
+
node = functionToRun(node);
|
|
384
|
+
}
|
|
385
|
+
if (node.type === "object") {
|
|
386
|
+
const newObjectProperties = {};
|
|
387
|
+
for (const key in node.properties) {
|
|
388
|
+
const value = node.properties[key];
|
|
389
|
+
newObjectProperties[key] = {
|
|
390
|
+
required: value.required,
|
|
391
|
+
node: walker(value.node, capability)
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
395
|
+
properties: __spreadValues$1({}, newObjectProperties),
|
|
396
|
+
extends: node.extends ? walker(node.extends, capability) : void 0,
|
|
397
|
+
additionalProperties: node.additionalProperties ? walker(node.additionalProperties, capability) : false
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
if (node.type === "array") {
|
|
401
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
402
|
+
elementType: walker(node.elementType, capability)
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (node.type === "and") {
|
|
406
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
407
|
+
and: node.and.map((element) => walker(element, capability))
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (node.type === "or") {
|
|
411
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
412
|
+
or: node.or.map((element) => walker(element, capability))
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (node.type === "ref") {
|
|
416
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
417
|
+
genericArguments: (_a = node.genericArguments) == null ? void 0 : _a.map((arg) => walker(arg, capability))
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (node.type === "tuple") {
|
|
421
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
422
|
+
elementTypes: node.elementTypes.map((type) => walker(type, capability)),
|
|
423
|
+
additionalItems: node.additionalItems ? walker(node.additionalItems, capability) : false
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (node.type === "function") {
|
|
427
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
428
|
+
parameters: node.parameters.map((param) => {
|
|
429
|
+
return __spreadProps$1(__spreadValues$1({}, param), {
|
|
430
|
+
type: walker(param.type, capability),
|
|
431
|
+
default: param.default ? walker(param.default, capability) : void 0
|
|
432
|
+
});
|
|
433
|
+
}),
|
|
434
|
+
returnType: node.returnType ? walker(node.returnType, capability) : void 0
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
if (node.type === "record") {
|
|
438
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
439
|
+
keyType: walker(node.keyType, capability),
|
|
440
|
+
valueType: walker(node.valueType, capability)
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
if (node.type === "conditional") {
|
|
444
|
+
return __spreadProps$1(__spreadValues$1({}, node), {
|
|
445
|
+
check: {
|
|
446
|
+
left: walker(node.check.left, capability),
|
|
447
|
+
right: walker(node.check.left, capability)
|
|
448
|
+
},
|
|
449
|
+
value: {
|
|
450
|
+
true: walker(node.value.true, capability),
|
|
451
|
+
false: walker(node.value.false, capability)
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
356
455
|
}
|
|
357
|
-
return
|
|
358
|
-
}
|
|
456
|
+
return n;
|
|
457
|
+
};
|
|
458
|
+
return walker;
|
|
359
459
|
}
|
|
360
460
|
|
|
461
|
+
var __defProp = Object.defineProperty;
|
|
462
|
+
var __defProps = Object.defineProperties;
|
|
463
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
464
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
465
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
466
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
467
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
468
|
+
var __spreadValues = (a, b) => {
|
|
469
|
+
for (var prop in b || (b = {}))
|
|
470
|
+
if (__hasOwnProp.call(b, prop))
|
|
471
|
+
__defNormalProp(a, prop, b[prop]);
|
|
472
|
+
if (__getOwnPropSymbols)
|
|
473
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
474
|
+
if (__propIsEnum.call(b, prop))
|
|
475
|
+
__defNormalProp(a, prop, b[prop]);
|
|
476
|
+
}
|
|
477
|
+
return a;
|
|
478
|
+
};
|
|
479
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
361
480
|
var __async = (__this, __arguments, generator) => {
|
|
362
481
|
return new Promise((resolve, reject) => {
|
|
363
482
|
var fulfilled = (value) => {
|
|
@@ -381,7 +500,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
381
500
|
class XLRSDK {
|
|
382
501
|
constructor(customRegistry) {
|
|
383
502
|
this.registry = customRegistry != null ? customRegistry : new BasicXLRRegistry();
|
|
384
|
-
this.validator = new XLRValidator(this.
|
|
503
|
+
this.validator = new XLRValidator(this.getType.bind(this));
|
|
385
504
|
this.tsWriter = new TSWriter();
|
|
386
505
|
}
|
|
387
506
|
loadDefinitionsFromDisk(inputPath, filters, transforms) {
|
|
@@ -398,36 +517,39 @@ class XLRSDK {
|
|
|
398
517
|
if ((filters == null ? void 0 : filters.capabilityFilter) && capabilityName.match(filters == null ? void 0 : filters.capabilityFilter))
|
|
399
518
|
return;
|
|
400
519
|
capabilityList.forEach((extensionName) => {
|
|
520
|
+
var _a2;
|
|
401
521
|
if (!(filters == null ? void 0 : filters.typeFilter) || !extensionName.match(filters == null ? void 0 : filters.typeFilter)) {
|
|
402
522
|
const cType = JSON.parse(fs.readFileSync(path.join(inputPath, "xlr", `${extensionName}.json`)).toString());
|
|
403
|
-
transforms == null ? void 0 : transforms.
|
|
404
|
-
|
|
405
|
-
this.registry.add(resolvedType, manifest.pluginName, capabilityName);
|
|
523
|
+
const effectiveType = (_a2 = transforms == null ? void 0 : transforms.reduce((typeAccumulator, transformFn) => transformFn(typeAccumulator, capabilityName), cType)) != null ? _a2 : cType;
|
|
524
|
+
this.registry.add(effectiveType, manifest.pluginName, capabilityName);
|
|
406
525
|
}
|
|
407
526
|
});
|
|
408
527
|
});
|
|
409
528
|
}
|
|
410
|
-
loadDefinitionsFromModule(
|
|
529
|
+
loadDefinitionsFromModule(manifest, filters, transforms) {
|
|
411
530
|
return __async(this, null, function* () {
|
|
412
531
|
var _a;
|
|
413
|
-
const importManifest = yield import(path.join(inputPath, "xlr", "manifest.js"));
|
|
414
|
-
const manifest = importManifest.default;
|
|
415
532
|
(_a = Object.keys(manifest.capabilities)) == null ? void 0 : _a.forEach((capabilityName) => {
|
|
416
533
|
if ((filters == null ? void 0 : filters.capabilityFilter) && capabilityName.match(filters == null ? void 0 : filters.capabilityFilter))
|
|
417
534
|
return;
|
|
418
535
|
const capabilityList = manifest.capabilities[capabilityName];
|
|
419
536
|
capabilityList.forEach((extension) => {
|
|
537
|
+
var _a2;
|
|
420
538
|
if (!(filters == null ? void 0 : filters.typeFilter) || !extension.name.match(filters == null ? void 0 : filters.typeFilter)) {
|
|
421
|
-
transforms == null ? void 0 : transforms.
|
|
422
|
-
|
|
423
|
-
this.registry.add(resolvedType, manifest.pluginName, extension.name);
|
|
539
|
+
const effectiveType = (_a2 = transforms == null ? void 0 : transforms.reduce((typeAccumulator, transformFn) => transformFn(typeAccumulator, capabilityName), extension)) != null ? _a2 : extension;
|
|
540
|
+
this.registry.add(effectiveType, manifest.pluginName, capabilityName);
|
|
424
541
|
}
|
|
425
542
|
});
|
|
426
543
|
});
|
|
427
544
|
});
|
|
428
545
|
}
|
|
429
|
-
getType(id) {
|
|
430
|
-
|
|
546
|
+
getType(id, options) {
|
|
547
|
+
let type = this.registry.get(id);
|
|
548
|
+
if ((options == null ? void 0 : options.getRawType) === true || !type) {
|
|
549
|
+
return type;
|
|
550
|
+
}
|
|
551
|
+
type = this.resolveType(type);
|
|
552
|
+
return fillInGenerics(type);
|
|
431
553
|
}
|
|
432
554
|
hasType(id) {
|
|
433
555
|
return this.registry.has(id);
|
|
@@ -435,20 +557,28 @@ class XLRSDK {
|
|
|
435
557
|
listTypes(filters) {
|
|
436
558
|
return this.registry.list(filters);
|
|
437
559
|
}
|
|
438
|
-
|
|
439
|
-
|
|
560
|
+
getTypeInfo(id) {
|
|
561
|
+
return this.registry.info(id);
|
|
562
|
+
}
|
|
563
|
+
validateByName(typeName, rootNode) {
|
|
564
|
+
const xlr = this.getType(typeName, { getRawType: true });
|
|
440
565
|
if (!xlr) {
|
|
441
566
|
throw new Error(`Type ${typeName} does not exist in registry, can't validate`);
|
|
442
567
|
}
|
|
443
568
|
return this.validator.validateType(rootNode, xlr);
|
|
444
569
|
}
|
|
570
|
+
validateByType(type, rootNode) {
|
|
571
|
+
return this.validator.validateType(rootNode, type);
|
|
572
|
+
}
|
|
445
573
|
exportRegistry(exportType, importMap, filters, transforms) {
|
|
446
574
|
const typesToExport = this.registry.list(filters).map((type) => {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
575
|
+
var _a;
|
|
576
|
+
const resolvedType = this.resolveType(type);
|
|
577
|
+
const effectiveType = (_a = transforms == null ? void 0 : transforms.reduce((typeAccumulator, transformFn) => {
|
|
578
|
+
var _a2;
|
|
579
|
+
return transformFn(typeAccumulator, (_a2 = this.registry.info(type.name)) == null ? void 0 : _a2.capability);
|
|
580
|
+
}, resolvedType)) != null ? _a : resolvedType;
|
|
581
|
+
return effectiveType;
|
|
452
582
|
});
|
|
453
583
|
if (exportType === "TypeScript") {
|
|
454
584
|
const outputString = this.exportToTypeScript(typesToExport, importMap);
|
|
@@ -456,6 +586,23 @@ class XLRSDK {
|
|
|
456
586
|
}
|
|
457
587
|
throw new Error(`Unknown export format ${exportType}`);
|
|
458
588
|
}
|
|
589
|
+
resolveType(type) {
|
|
590
|
+
return simpleTransformGenerator("object", "any", (objectNode) => {
|
|
591
|
+
if (objectNode.extends) {
|
|
592
|
+
const refName = objectNode.extends.ref.split("<")[0];
|
|
593
|
+
let extendedType = this.getType(refName, { getRawType: true });
|
|
594
|
+
if (!extendedType) {
|
|
595
|
+
throw new Error(`Error resolving ${objectNode.name}: can't find extended type ${refName}`);
|
|
596
|
+
}
|
|
597
|
+
extendedType = resolveReferenceNode(objectNode.extends, extendedType);
|
|
598
|
+
return __spreadProps(__spreadValues({}, computeEffectiveObject(extendedType, objectNode, false)), {
|
|
599
|
+
name: objectNode.name,
|
|
600
|
+
description: objectNode.description
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
return objectNode;
|
|
604
|
+
})(type, "any");
|
|
605
|
+
}
|
|
459
606
|
exportToTypeScript(typesToExport, importMap) {
|
|
460
607
|
const referencedImports = new Set();
|
|
461
608
|
const exportedTypes = new Map();
|
|
@@ -472,7 +619,7 @@ class XLRSDK {
|
|
|
472
619
|
importMap.forEach((imports, packageName) => {
|
|
473
620
|
const applicableImports = imports.filter((i) => referencedImports.has(i));
|
|
474
621
|
resultFile = ts.factory.updateSourceFile(resultFile, [
|
|
475
|
-
ts.factory.createImportDeclaration(void 0,
|
|
622
|
+
ts.factory.createImportDeclaration(void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports(applicableImports.map((i) => ts.factory.createImportSpecifier(false, void 0, ts.factory.createIdentifier(i))))), ts.factory.createStringLiteral(packageName)),
|
|
476
623
|
...resultFile.statements
|
|
477
624
|
]);
|
|
478
625
|
});
|
|
@@ -483,60 +630,5 @@ ${nodeText}`;
|
|
|
483
630
|
}
|
|
484
631
|
}
|
|
485
632
|
|
|
486
|
-
function simpleTransformGenerator(typeToTransform, capabilityToTransform, functionToRun) {
|
|
487
|
-
const walker = (node, capability) => {
|
|
488
|
-
var _a;
|
|
489
|
-
if (capability === capabilityToTransform) {
|
|
490
|
-
if (node.type === typeToTransform) {
|
|
491
|
-
functionToRun(node);
|
|
492
|
-
}
|
|
493
|
-
if (node.type === "object") {
|
|
494
|
-
if (node.extends) {
|
|
495
|
-
walker(node, capability);
|
|
496
|
-
}
|
|
497
|
-
for (const key in node.properties) {
|
|
498
|
-
const value = node.properties[key];
|
|
499
|
-
walker(value.node, capability);
|
|
500
|
-
}
|
|
501
|
-
if (node.additionalProperties) {
|
|
502
|
-
walker(node.additionalProperties, capability);
|
|
503
|
-
}
|
|
504
|
-
} else if (node.type === "array") {
|
|
505
|
-
walker(node.elementType, capability);
|
|
506
|
-
} else if (node.type === "and") {
|
|
507
|
-
node.and.forEach((element) => walker(element, capability));
|
|
508
|
-
} else if (node.type === "or") {
|
|
509
|
-
node.or.forEach((element) => walker(element, capability));
|
|
510
|
-
} else if (node.type === "ref") {
|
|
511
|
-
(_a = node.genericArguments) == null ? void 0 : _a.forEach((element) => walker(element, capability));
|
|
512
|
-
} else if (node.type === "tuple") {
|
|
513
|
-
if (node.additionalItems) {
|
|
514
|
-
walker(node.additionalItems, capability);
|
|
515
|
-
}
|
|
516
|
-
node.elementTypes.forEach((element) => walker(element, capability));
|
|
517
|
-
} else if (node.type === "function") {
|
|
518
|
-
node.parameters.forEach((param) => {
|
|
519
|
-
walker(param.type, capability);
|
|
520
|
-
if (param.default) {
|
|
521
|
-
walker(param.default, capability);
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
if (node.returnType) {
|
|
525
|
-
walker(node.returnType, capability);
|
|
526
|
-
}
|
|
527
|
-
} else if (node.type === "record") {
|
|
528
|
-
walker(node.keyType, capability);
|
|
529
|
-
walker(node.valueType, capability);
|
|
530
|
-
} else if (node.type === "conditional") {
|
|
531
|
-
walker(node.check.left, capability);
|
|
532
|
-
walker(node.check.right, capability);
|
|
533
|
-
walker(node.value.true, capability);
|
|
534
|
-
walker(node.value.false, capability);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
return walker;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
633
|
export { BasicXLRRegistry, XLRSDK, simpleTransformGenerator };
|
|
542
634
|
//# sourceMappingURL=index.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-tools/xlr-sdk",
|
|
3
|
-
"version": "0.2.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"typescript": "4.8.4"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-tools/xlr": "0.2.1
|
|
13
|
-
"@player-tools/xlr-utils": "0.2.1
|
|
14
|
-
"@player-tools/xlr-converters": "0.2.1
|
|
12
|
+
"@player-tools/xlr": "0.2.1",
|
|
13
|
+
"@player-tools/xlr-utils": "0.2.1",
|
|
14
|
+
"@player-tools/xlr-converters": "0.2.1",
|
|
15
15
|
"jsonc-parser": "^2.3.1",
|
|
16
16
|
"@types/node": "^16.11.12",
|
|
17
17
|
"@types/fs-extra": "^9.0.13",
|