@player-tools/xlr-converters 0.1.0 → 0.2.0-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 CHANGED
@@ -323,6 +323,7 @@ class TsConverter {
323
323
  handleHeritageClauses(clauses, baseObject, typeChecker) {
324
324
  let newProperties = {};
325
325
  let newAdditionalProperties = false;
326
+ let extendsType;
326
327
  clauses.forEach((heritageClause) => {
327
328
  var _a;
328
329
  const parent = heritageClause.types[0];
@@ -334,22 +335,26 @@ class TsConverter {
334
335
  parentInterface = parentInterface.parent;
335
336
  }
336
337
  if (parentInterface && xlrUtils.isTopLevelNode(parentInterface)) {
337
- const parentInterfaceType = this.convertDeclaration(parentInterface);
338
- if (parentInterface.typeParameters && parent.typeArguments) {
339
- const filledInInterface = this.solveGenerics(parentInterfaceType, parentInterface.typeParameters, parent.typeArguments);
340
- newProperties = filledInInterface.properties;
341
- newAdditionalProperties = filledInInterface.additionalProperties;
338
+ if (this.context.customPrimitives.includes(parentInterface.name.text)) {
339
+ extendsType = this.makeBasicRefNode(parent);
342
340
  } else {
343
- if (xlrUtils.isGenericNodeType(baseObject)) {
344
- baseObject.genericTokens.push(...(_a = parentInterfaceType.genericTokens) != null ? _a : []);
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;
346
+ } else {
347
+ if (xlrUtils.isGenericNodeType(baseObject)) {
348
+ baseObject.genericTokens.push(...(_a = parentInterfaceType.genericTokens) != null ? _a : []);
349
+ }
350
+ newProperties = parentInterfaceType.properties;
351
+ newAdditionalProperties = parentInterfaceType.additionalProperties;
345
352
  }
346
- newProperties = parentInterfaceType.properties;
347
- newAdditionalProperties = parentInterfaceType.additionalProperties;
348
353
  }
349
354
  }
350
355
  });
351
356
  newAdditionalProperties = baseObject.additionalProperties === false ? newAdditionalProperties : false;
352
- return __spreadProps(__spreadValues$1({}, baseObject), {
357
+ return __spreadProps(__spreadValues$1(__spreadValues$1({}, baseObject), extendsType ? { extends: extendsType } : {}), {
353
358
  properties: __spreadValues$1(__spreadValues$1({}, newProperties), baseObject.properties),
354
359
  additionalProperties: newAdditionalProperties
355
360
  });
@@ -455,9 +460,9 @@ class TsConverter {
455
460
  if (typeInfo) {
456
461
  const genericType = this.convertDeclaration(typeInfo.declaration);
457
462
  const genericParams = typeInfo.declaration.typeParameters;
458
- const genericArgs2 = node.typeArguments;
459
- if (genericType && genericParams && genericArgs2) {
460
- return this.solveGenerics(genericType, genericParams, genericArgs2);
463
+ const genericArgs = node.typeArguments;
464
+ if (genericType && genericParams && genericArgs) {
465
+ return this.solveGenerics(genericType, genericParams, genericArgs);
461
466
  }
462
467
  if (genericType) {
463
468
  return genericType;
@@ -465,6 +470,9 @@ class TsConverter {
465
470
  }
466
471
  this.context.throwError(`Can't find referenced type ${refName}, is it available in the current package or node_modules?`);
467
472
  }
473
+ return this.makeBasicRefNode(node);
474
+ }
475
+ makeBasicRefNode(node) {
468
476
  const genericArgs = [];
469
477
  if (node.typeArguments) {
470
478
  node.typeArguments.forEach((typeArg) => {
@@ -477,7 +485,7 @@ class TsConverter {
477
485
  if (convertedNode) {
478
486
  genericArgs.push(convertedNode);
479
487
  } else {
480
- this.context.throwError(`Conversion Error: Couldn't convert type argument in type ${refName}`);
488
+ this.context.throwError(`Conversion Error: Couldn't convert type argument in type ${node.getText()}`);
481
489
  }
482
490
  });
483
491
  }
package/dist/index.d.ts CHANGED
@@ -40,6 +40,7 @@ declare class TsConverter {
40
40
  private solveGenerics;
41
41
  private generateGenerics;
42
42
  private resolveRefNode;
43
+ private makeBasicRefNode;
43
44
  }
44
45
 
45
46
  interface ConvertedType {
package/dist/index.esm.js CHANGED
@@ -315,6 +315,7 @@ class TsConverter {
315
315
  handleHeritageClauses(clauses, baseObject, typeChecker) {
316
316
  let newProperties = {};
317
317
  let newAdditionalProperties = false;
318
+ let extendsType;
318
319
  clauses.forEach((heritageClause) => {
319
320
  var _a;
320
321
  const parent = heritageClause.types[0];
@@ -326,22 +327,26 @@ class TsConverter {
326
327
  parentInterface = parentInterface.parent;
327
328
  }
328
329
  if (parentInterface && isTopLevelNode(parentInterface)) {
329
- const parentInterfaceType = this.convertDeclaration(parentInterface);
330
- if (parentInterface.typeParameters && parent.typeArguments) {
331
- const filledInInterface = this.solveGenerics(parentInterfaceType, parentInterface.typeParameters, parent.typeArguments);
332
- newProperties = filledInInterface.properties;
333
- newAdditionalProperties = filledInInterface.additionalProperties;
330
+ if (this.context.customPrimitives.includes(parentInterface.name.text)) {
331
+ extendsType = this.makeBasicRefNode(parent);
334
332
  } else {
335
- if (isGenericNodeType(baseObject)) {
336
- baseObject.genericTokens.push(...(_a = parentInterfaceType.genericTokens) != null ? _a : []);
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;
338
+ } else {
339
+ if (isGenericNodeType(baseObject)) {
340
+ baseObject.genericTokens.push(...(_a = parentInterfaceType.genericTokens) != null ? _a : []);
341
+ }
342
+ newProperties = parentInterfaceType.properties;
343
+ newAdditionalProperties = parentInterfaceType.additionalProperties;
337
344
  }
338
- newProperties = parentInterfaceType.properties;
339
- newAdditionalProperties = parentInterfaceType.additionalProperties;
340
345
  }
341
346
  }
342
347
  });
343
348
  newAdditionalProperties = baseObject.additionalProperties === false ? newAdditionalProperties : false;
344
- return __spreadProps(__spreadValues$1({}, baseObject), {
349
+ return __spreadProps(__spreadValues$1(__spreadValues$1({}, baseObject), extendsType ? { extends: extendsType } : {}), {
345
350
  properties: __spreadValues$1(__spreadValues$1({}, newProperties), baseObject.properties),
346
351
  additionalProperties: newAdditionalProperties
347
352
  });
@@ -447,9 +452,9 @@ class TsConverter {
447
452
  if (typeInfo) {
448
453
  const genericType = this.convertDeclaration(typeInfo.declaration);
449
454
  const genericParams = typeInfo.declaration.typeParameters;
450
- const genericArgs2 = node.typeArguments;
451
- if (genericType && genericParams && genericArgs2) {
452
- return this.solveGenerics(genericType, genericParams, genericArgs2);
455
+ const genericArgs = node.typeArguments;
456
+ if (genericType && genericParams && genericArgs) {
457
+ return this.solveGenerics(genericType, genericParams, genericArgs);
453
458
  }
454
459
  if (genericType) {
455
460
  return genericType;
@@ -457,6 +462,9 @@ class TsConverter {
457
462
  }
458
463
  this.context.throwError(`Can't find referenced type ${refName}, is it available in the current package or node_modules?`);
459
464
  }
465
+ return this.makeBasicRefNode(node);
466
+ }
467
+ makeBasicRefNode(node) {
460
468
  const genericArgs = [];
461
469
  if (node.typeArguments) {
462
470
  node.typeArguments.forEach((typeArg) => {
@@ -469,7 +477,7 @@ class TsConverter {
469
477
  if (convertedNode) {
470
478
  genericArgs.push(convertedNode);
471
479
  } else {
472
- this.context.throwError(`Conversion Error: Couldn't convert type argument in type ${refName}`);
480
+ this.context.throwError(`Conversion Error: Couldn't convert type argument in type ${node.getText()}`);
473
481
  }
474
482
  });
475
483
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-tools/xlr-converters",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-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.1.0",
13
- "@player-tools/xlr-utils": "0.1.0",
12
+ "@player-tools/xlr": "0.2.0-next.0",
13
+ "@player-tools/xlr-utils": "0.2.0-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
@@ -11,6 +11,7 @@ import type {
11
11
  AnyType,
12
12
  ParamTypeNode,
13
13
  ConditionalType,
14
+ RefType,
14
15
  } from '@player-tools/xlr';
15
16
  import type { TopLevelDeclaration } from '@player-tools/xlr-utils';
16
17
  import {
@@ -481,6 +482,7 @@ export class TsConverter {
481
482
  ): ObjectType {
482
483
  let newProperties: { [x: string]: ObjectProperty } = {};
483
484
  let newAdditionalProperties: NodeType | false = false;
485
+ let extendsType: RefType | undefined;
484
486
 
485
487
  clauses.forEach((heritageClause) => {
486
488
  const parent = heritageClause.types[0];
@@ -499,25 +501,29 @@ export class TsConverter {
499
501
  }
500
502
 
501
503
  if (parentInterface && isTopLevelNode(parentInterface)) {
502
- const parentInterfaceType = this.convertDeclaration(parentInterface);
503
- if (parentInterface.typeParameters && parent.typeArguments) {
504
- const filledInInterface = this.solveGenerics(
505
- parentInterfaceType as NodeTypeWithGenerics,
506
- parentInterface.typeParameters,
507
- parent.typeArguments
508
- ) as NamedType<ObjectType>;
509
- newProperties = filledInInterface.properties;
510
- newAdditionalProperties = filledInInterface.additionalProperties;
504
+ if (this.context.customPrimitives.includes(parentInterface.name.text)) {
505
+ extendsType = this.makeBasicRefNode(parent);
511
506
  } else {
512
- if (isGenericNodeType(baseObject)) {
513
- baseObject.genericTokens.push(
514
- ...((parentInterfaceType as NodeTypeWithGenerics).genericTokens ??
515
- [])
516
- );
507
+ const parentInterfaceType = this.convertDeclaration(parentInterface);
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;
516
+ } else {
517
+ if (isGenericNodeType(baseObject)) {
518
+ baseObject.genericTokens.push(
519
+ ...((parentInterfaceType as NodeTypeWithGenerics)
520
+ .genericTokens ?? [])
521
+ );
522
+ }
523
+
524
+ newProperties = parentInterfaceType.properties;
525
+ newAdditionalProperties = parentInterfaceType.additionalProperties;
517
526
  }
518
-
519
- newProperties = parentInterfaceType.properties;
520
- newAdditionalProperties = parentInterfaceType.additionalProperties;
521
527
  }
522
528
  }
523
529
  });
@@ -527,6 +533,7 @@ export class TsConverter {
527
533
  : false;
528
534
  return {
529
535
  ...baseObject,
536
+ ...(extendsType ? { extends: extendsType } : {}),
530
537
  properties: { ...newProperties, ...baseObject.properties },
531
538
  additionalProperties: newAdditionalProperties,
532
539
  };
@@ -695,6 +702,10 @@ export class TsConverter {
695
702
  );
696
703
  }
697
704
 
705
+ return this.makeBasicRefNode(node);
706
+ }
707
+
708
+ private makeBasicRefNode(node: ts.NodeWithTypeArguments): RefType {
698
709
  const genericArgs: Array<NodeType | NamedType<ObjectType>> = [];
699
710
  if (node.typeArguments) {
700
711
  node.typeArguments.forEach((typeArg) => {
@@ -709,7 +720,7 @@ export class TsConverter {
709
720
  genericArgs.push(convertedNode);
710
721
  } else {
711
722
  this.context.throwError(
712
- `Conversion Error: Couldn't convert type argument in type ${refName}`
723
+ `Conversion Error: Couldn't convert type argument in type ${node.getText()}`
713
724
  );
714
725
  }
715
726
  });