@player-tools/xlr-converters 0.2.0-next.0 → 0.2.1-next.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/dist/index.cjs.js +41 -26
- package/dist/index.esm.js +41 -26
- package/package.json +3 -3
- package/src/ts-to-xlr.ts +69 -42
package/dist/index.cjs.js
CHANGED
|
@@ -322,41 +322,56 @@ class TsConverter {
|
|
|
322
322
|
}
|
|
323
323
|
handleHeritageClauses(clauses, baseObject, typeChecker) {
|
|
324
324
|
let newProperties = {};
|
|
325
|
-
|
|
325
|
+
const additionalPropertiesCollector = [];
|
|
326
326
|
let extendsType;
|
|
327
327
|
clauses.forEach((heritageClause) => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
} else {
|
|
341
|
-
const parentInterfaceType = this.convertDeclaration(parentInterface);
|
|
342
|
-
if (parentInterface.typeParameters && parent.typeArguments) {
|
|
343
|
-
const filledInInterface = this.solveGenerics(parentInterfaceType, parentInterface.typeParameters, parent.typeArguments);
|
|
344
|
-
newProperties = filledInInterface.properties;
|
|
345
|
-
newAdditionalProperties = filledInInterface.additionalProperties;
|
|
328
|
+
heritageClause.types.forEach((parent) => {
|
|
329
|
+
var _a;
|
|
330
|
+
const parentType = typeChecker.getTypeAtLocation(parent);
|
|
331
|
+
const parentSymbol = parentType.symbol;
|
|
332
|
+
const parentDeclarations = parentSymbol == null ? void 0 : parentSymbol.declarations;
|
|
333
|
+
let parentInterface = parentDeclarations == null ? void 0 : parentDeclarations[0];
|
|
334
|
+
if (parentInterface && ts__default["default"].isTypeLiteralNode(parentInterface) && ts__default["default"].isTypeAliasDeclaration(parentInterface.parent)) {
|
|
335
|
+
parentInterface = parentInterface.parent;
|
|
336
|
+
}
|
|
337
|
+
if (parentInterface && xlrUtils.isTopLevelNode(parentInterface)) {
|
|
338
|
+
if (this.context.customPrimitives.includes(parentInterface.name.text)) {
|
|
339
|
+
extendsType = this.makeBasicRefNode(parent);
|
|
346
340
|
} else {
|
|
347
|
-
|
|
348
|
-
|
|
341
|
+
const parentInterfaceType = this.convertDeclaration(parentInterface);
|
|
342
|
+
if (parentInterface.typeParameters && parent.typeArguments) {
|
|
343
|
+
const filledInInterface = this.solveGenerics(parentInterfaceType, parentInterface.typeParameters, parent.typeArguments);
|
|
344
|
+
newProperties = __spreadValues$1(__spreadValues$1({}, newProperties), filledInInterface.properties);
|
|
345
|
+
if (filledInInterface.additionalProperties) {
|
|
346
|
+
additionalPropertiesCollector.push(filledInInterface.additionalProperties);
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
if (xlrUtils.isGenericNodeType(baseObject)) {
|
|
350
|
+
baseObject.genericTokens.push(...(_a = parentInterfaceType.genericTokens) != null ? _a : []);
|
|
351
|
+
}
|
|
352
|
+
newProperties = __spreadValues$1(__spreadValues$1({}, newProperties), parentInterfaceType.properties);
|
|
353
|
+
if (parentInterfaceType.additionalProperties) {
|
|
354
|
+
additionalPropertiesCollector.push(parentInterfaceType.additionalProperties);
|
|
355
|
+
}
|
|
349
356
|
}
|
|
350
|
-
newProperties = parentInterfaceType.properties;
|
|
351
|
-
newAdditionalProperties = parentInterfaceType.additionalProperties;
|
|
352
357
|
}
|
|
353
358
|
}
|
|
354
|
-
}
|
|
359
|
+
});
|
|
355
360
|
});
|
|
356
|
-
|
|
361
|
+
let additionalProperties = false;
|
|
362
|
+
if (baseObject.additionalProperties === false) {
|
|
363
|
+
if (additionalPropertiesCollector.length === 1) {
|
|
364
|
+
additionalProperties = additionalPropertiesCollector[0];
|
|
365
|
+
} else if (additionalPropertiesCollector.length >= 1) {
|
|
366
|
+
additionalProperties = {
|
|
367
|
+
type: "or",
|
|
368
|
+
or: additionalPropertiesCollector
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
357
372
|
return __spreadProps(__spreadValues$1(__spreadValues$1({}, baseObject), extendsType ? { extends: extendsType } : {}), {
|
|
358
373
|
properties: __spreadValues$1(__spreadValues$1({}, newProperties), baseObject.properties),
|
|
359
|
-
additionalProperties
|
|
374
|
+
additionalProperties
|
|
360
375
|
});
|
|
361
376
|
}
|
|
362
377
|
solveGenerics(baseInterface, typeParameters, typeArguments) {
|
package/dist/index.esm.js
CHANGED
|
@@ -314,41 +314,56 @@ class TsConverter {
|
|
|
314
314
|
}
|
|
315
315
|
handleHeritageClauses(clauses, baseObject, typeChecker) {
|
|
316
316
|
let newProperties = {};
|
|
317
|
-
|
|
317
|
+
const additionalPropertiesCollector = [];
|
|
318
318
|
let extendsType;
|
|
319
319
|
clauses.forEach((heritageClause) => {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
} else {
|
|
333
|
-
const parentInterfaceType = this.convertDeclaration(parentInterface);
|
|
334
|
-
if (parentInterface.typeParameters && parent.typeArguments) {
|
|
335
|
-
const filledInInterface = this.solveGenerics(parentInterfaceType, parentInterface.typeParameters, parent.typeArguments);
|
|
336
|
-
newProperties = filledInInterface.properties;
|
|
337
|
-
newAdditionalProperties = filledInInterface.additionalProperties;
|
|
320
|
+
heritageClause.types.forEach((parent) => {
|
|
321
|
+
var _a;
|
|
322
|
+
const parentType = typeChecker.getTypeAtLocation(parent);
|
|
323
|
+
const parentSymbol = parentType.symbol;
|
|
324
|
+
const parentDeclarations = parentSymbol == null ? void 0 : parentSymbol.declarations;
|
|
325
|
+
let parentInterface = parentDeclarations == null ? void 0 : parentDeclarations[0];
|
|
326
|
+
if (parentInterface && ts.isTypeLiteralNode(parentInterface) && ts.isTypeAliasDeclaration(parentInterface.parent)) {
|
|
327
|
+
parentInterface = parentInterface.parent;
|
|
328
|
+
}
|
|
329
|
+
if (parentInterface && isTopLevelNode(parentInterface)) {
|
|
330
|
+
if (this.context.customPrimitives.includes(parentInterface.name.text)) {
|
|
331
|
+
extendsType = this.makeBasicRefNode(parent);
|
|
338
332
|
} else {
|
|
339
|
-
|
|
340
|
-
|
|
333
|
+
const parentInterfaceType = this.convertDeclaration(parentInterface);
|
|
334
|
+
if (parentInterface.typeParameters && parent.typeArguments) {
|
|
335
|
+
const filledInInterface = this.solveGenerics(parentInterfaceType, parentInterface.typeParameters, parent.typeArguments);
|
|
336
|
+
newProperties = __spreadValues$1(__spreadValues$1({}, newProperties), filledInInterface.properties);
|
|
337
|
+
if (filledInInterface.additionalProperties) {
|
|
338
|
+
additionalPropertiesCollector.push(filledInInterface.additionalProperties);
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
if (isGenericNodeType(baseObject)) {
|
|
342
|
+
baseObject.genericTokens.push(...(_a = parentInterfaceType.genericTokens) != null ? _a : []);
|
|
343
|
+
}
|
|
344
|
+
newProperties = __spreadValues$1(__spreadValues$1({}, newProperties), parentInterfaceType.properties);
|
|
345
|
+
if (parentInterfaceType.additionalProperties) {
|
|
346
|
+
additionalPropertiesCollector.push(parentInterfaceType.additionalProperties);
|
|
347
|
+
}
|
|
341
348
|
}
|
|
342
|
-
newProperties = parentInterfaceType.properties;
|
|
343
|
-
newAdditionalProperties = parentInterfaceType.additionalProperties;
|
|
344
349
|
}
|
|
345
350
|
}
|
|
346
|
-
}
|
|
351
|
+
});
|
|
347
352
|
});
|
|
348
|
-
|
|
353
|
+
let additionalProperties = false;
|
|
354
|
+
if (baseObject.additionalProperties === false) {
|
|
355
|
+
if (additionalPropertiesCollector.length === 1) {
|
|
356
|
+
additionalProperties = additionalPropertiesCollector[0];
|
|
357
|
+
} else if (additionalPropertiesCollector.length >= 1) {
|
|
358
|
+
additionalProperties = {
|
|
359
|
+
type: "or",
|
|
360
|
+
or: additionalPropertiesCollector
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
349
364
|
return __spreadProps(__spreadValues$1(__spreadValues$1({}, baseObject), extendsType ? { extends: extendsType } : {}), {
|
|
350
365
|
properties: __spreadValues$1(__spreadValues$1({}, newProperties), baseObject.properties),
|
|
351
|
-
additionalProperties
|
|
366
|
+
additionalProperties
|
|
352
367
|
});
|
|
353
368
|
}
|
|
354
369
|
solveGenerics(baseInterface, typeParameters, typeArguments) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-tools/xlr-converters",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-next.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"typescript": "4.4.4"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-tools/xlr": "0.2.
|
|
13
|
-
"@player-tools/xlr-utils": "0.2.
|
|
12
|
+
"@player-tools/xlr": "0.2.1-next.0",
|
|
13
|
+
"@player-tools/xlr-utils": "0.2.1-next.0",
|
|
14
14
|
"@babel/runtime": "7.15.4"
|
|
15
15
|
},
|
|
16
16
|
"main": "dist/index.cjs.js",
|
package/src/ts-to-xlr.ts
CHANGED
|
@@ -481,61 +481,88 @@ export class TsConverter {
|
|
|
481
481
|
typeChecker: ts.TypeChecker
|
|
482
482
|
): ObjectType {
|
|
483
483
|
let newProperties: { [x: string]: ObjectProperty } = {};
|
|
484
|
-
|
|
484
|
+
const additionalPropertiesCollector: Array<NodeType> = [];
|
|
485
485
|
let extendsType: RefType | undefined;
|
|
486
486
|
|
|
487
487
|
clauses.forEach((heritageClause) => {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
488
|
+
heritageClause.types.forEach((parent) => {
|
|
489
|
+
const parentType = typeChecker.getTypeAtLocation(parent);
|
|
490
|
+
const parentSymbol = parentType.symbol;
|
|
491
|
+
const parentDeclarations = parentSymbol?.declarations;
|
|
492
|
+
let parentInterface = parentDeclarations?.[0];
|
|
493
|
+
|
|
494
|
+
if (
|
|
495
|
+
parentInterface &&
|
|
496
|
+
ts.isTypeLiteralNode(parentInterface) &&
|
|
497
|
+
ts.isTypeAliasDeclaration(parentInterface.parent)
|
|
498
|
+
) {
|
|
499
|
+
// check for if the node is a type to get the actual type declaration
|
|
500
|
+
parentInterface = parentInterface.parent;
|
|
501
|
+
}
|
|
502
502
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (parentInterface.typeParameters && parent.typeArguments) {
|
|
509
|
-
const filledInInterface = this.solveGenerics(
|
|
510
|
-
parentInterfaceType as NodeTypeWithGenerics,
|
|
511
|
-
parentInterface.typeParameters,
|
|
512
|
-
parent.typeArguments
|
|
513
|
-
) as NamedType<ObjectType>;
|
|
514
|
-
newProperties = filledInInterface.properties;
|
|
515
|
-
newAdditionalProperties = filledInInterface.additionalProperties;
|
|
503
|
+
if (parentInterface && isTopLevelNode(parentInterface)) {
|
|
504
|
+
if (
|
|
505
|
+
this.context.customPrimitives.includes(parentInterface.name.text)
|
|
506
|
+
) {
|
|
507
|
+
extendsType = this.makeBasicRefNode(parent);
|
|
516
508
|
} else {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
509
|
+
const parentInterfaceType =
|
|
510
|
+
this.convertDeclaration(parentInterface);
|
|
511
|
+
if (parentInterface.typeParameters && parent.typeArguments) {
|
|
512
|
+
const filledInInterface = this.solveGenerics(
|
|
513
|
+
parentInterfaceType as NodeTypeWithGenerics,
|
|
514
|
+
parentInterface.typeParameters,
|
|
515
|
+
parent.typeArguments
|
|
516
|
+
) as NamedType<ObjectType>;
|
|
517
|
+
newProperties = {
|
|
518
|
+
...newProperties,
|
|
519
|
+
...filledInInterface.properties,
|
|
520
|
+
};
|
|
521
|
+
if (filledInInterface.additionalProperties) {
|
|
522
|
+
additionalPropertiesCollector.push(
|
|
523
|
+
filledInInterface.additionalProperties
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
} else {
|
|
527
|
+
if (isGenericNodeType(baseObject)) {
|
|
528
|
+
baseObject.genericTokens.push(
|
|
529
|
+
...((parentInterfaceType as NodeTypeWithGenerics)
|
|
530
|
+
.genericTokens ?? [])
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
newProperties = {
|
|
535
|
+
...newProperties,
|
|
536
|
+
...parentInterfaceType.properties,
|
|
537
|
+
};
|
|
538
|
+
if (parentInterfaceType.additionalProperties) {
|
|
539
|
+
additionalPropertiesCollector.push(
|
|
540
|
+
parentInterfaceType.additionalProperties
|
|
541
|
+
);
|
|
542
|
+
}
|
|
522
543
|
}
|
|
523
|
-
|
|
524
|
-
newProperties = parentInterfaceType.properties;
|
|
525
|
-
newAdditionalProperties = parentInterfaceType.additionalProperties;
|
|
526
544
|
}
|
|
527
545
|
}
|
|
528
|
-
}
|
|
546
|
+
});
|
|
529
547
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
548
|
+
|
|
549
|
+
let additionalProperties: NodeType | false = false;
|
|
550
|
+
if (baseObject.additionalProperties === false) {
|
|
551
|
+
if (additionalPropertiesCollector.length === 1) {
|
|
552
|
+
additionalProperties = additionalPropertiesCollector[0];
|
|
553
|
+
} else if (additionalPropertiesCollector.length >= 1) {
|
|
554
|
+
additionalProperties = {
|
|
555
|
+
type: 'or',
|
|
556
|
+
or: additionalPropertiesCollector,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
534
561
|
return {
|
|
535
562
|
...baseObject,
|
|
536
563
|
...(extendsType ? { extends: extendsType } : {}),
|
|
537
564
|
properties: { ...newProperties, ...baseObject.properties },
|
|
538
|
-
additionalProperties
|
|
565
|
+
additionalProperties,
|
|
539
566
|
};
|
|
540
567
|
}
|
|
541
568
|
|