@teambit/semantics.entities.semantic-schema 0.0.8 → 0.0.9

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.
Files changed (70) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +9 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/schemas/constructor.d.ts +12 -4
  5. package/dist/schemas/constructor.js +5 -5
  6. package/dist/schemas/constructor.js.map +1 -1
  7. package/dist/schemas/function.d.ts +10 -16
  8. package/dist/schemas/function.js +6 -3
  9. package/dist/schemas/function.js.map +1 -1
  10. package/dist/schemas/get-accessor.d.ts +2 -6
  11. package/dist/schemas/get-accessor.js.map +1 -1
  12. package/dist/schemas/index-signature.d.ts +5 -9
  13. package/dist/schemas/index-signature.js +5 -5
  14. package/dist/schemas/index-signature.js.map +1 -1
  15. package/dist/schemas/index.d.ts +9 -1
  16. package/dist/schemas/index.js +17 -1
  17. package/dist/schemas/index.js.map +1 -1
  18. package/dist/schemas/inference-type.d.ts +13 -0
  19. package/dist/schemas/inference-type.js +22 -0
  20. package/dist/schemas/inference-type.js.map +1 -0
  21. package/dist/schemas/keyword-type.d.ts +13 -0
  22. package/dist/schemas/keyword-type.js +22 -0
  23. package/dist/schemas/keyword-type.js.map +1 -0
  24. package/dist/schemas/literal-type.d.ts +13 -0
  25. package/dist/schemas/literal-type.js +22 -0
  26. package/dist/schemas/literal-type.js.map +1 -0
  27. package/dist/schemas/parameter.d.ts +18 -0
  28. package/dist/schemas/parameter.js +25 -0
  29. package/dist/schemas/parameter.js.map +1 -0
  30. package/dist/schemas/set-accessor.d.ts +3 -3
  31. package/dist/schemas/set-accessor.js +1 -1
  32. package/dist/schemas/set-accessor.js.map +1 -1
  33. package/dist/schemas/tuple-type.d.ts +12 -0
  34. package/dist/schemas/tuple-type.js +19 -0
  35. package/dist/schemas/tuple-type.js.map +1 -0
  36. package/dist/schemas/type-array.d.ts +12 -0
  37. package/dist/schemas/type-array.js +19 -0
  38. package/dist/schemas/type-array.js.map +1 -0
  39. package/dist/schemas/type-operator.d.ts +14 -0
  40. package/dist/schemas/type-operator.js +21 -0
  41. package/dist/schemas/type-operator.js.map +1 -0
  42. package/dist/schemas/type-query.d.ts +16 -0
  43. package/dist/schemas/type-query.js +27 -0
  44. package/dist/schemas/type-query.js.map +1 -0
  45. package/dist/schemas/type-ref.d.ts +5 -3
  46. package/dist/schemas/type-ref.js +8 -3
  47. package/dist/schemas/type-ref.js.map +1 -1
  48. package/dist/schemas/variable.d.ts +2 -6
  49. package/dist/schemas/variable.js.map +1 -1
  50. package/index.ts +9 -1
  51. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.9.tgz +0 -0
  52. package/package.json +2 -2
  53. package/{preview-1652239597845.js → preview-1652498684867.js} +1 -1
  54. package/schemas/constructor.ts +5 -5
  55. package/schemas/function.ts +10 -12
  56. package/schemas/get-accessor.ts +1 -2
  57. package/schemas/index-signature.ts +5 -6
  58. package/schemas/index.ts +9 -1
  59. package/schemas/inference-type.ts +19 -0
  60. package/schemas/keyword-type.ts +19 -0
  61. package/schemas/literal-type.ts +19 -0
  62. package/schemas/parameter.ts +23 -0
  63. package/schemas/set-accessor.ts +3 -3
  64. package/schemas/tuple-type.ts +14 -0
  65. package/schemas/type-array.ts +14 -0
  66. package/schemas/type-operator.ts +15 -0
  67. package/schemas/type-query.ts +23 -0
  68. package/schemas/type-ref.ts +9 -6
  69. package/schemas/variable.ts +1 -2
  70. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.8.tgz +0 -0
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeOperatorSchema = void 0;
4
+ class TypeOperatorSchema {
5
+ constructor(operatorName, type) {
6
+ this.operatorName = operatorName;
7
+ this.type = type;
8
+ }
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ operatorName: this.operatorName,
13
+ type: this.type.toObject(),
14
+ };
15
+ }
16
+ toString() {
17
+ return `${this.operatorName} ${this.type.toString()}`;
18
+ }
19
+ }
20
+ exports.TypeOperatorSchema = TypeOperatorSchema;
21
+ //# sourceMappingURL=type-operator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-operator.js","sourceRoot":"","sources":["../../schemas/type-operator.ts"],"names":[],"mappings":";;;AAEA,MAAa,kBAAkB;IAC7B,YAAoB,YAAoB,EAAU,IAAgB;QAA9C,iBAAY,GAAZ,YAAY,CAAQ;QAAU,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IACtE,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;SAC3B,CAAC;IACJ,CAAC;IACD,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IACxD,CAAC;CACF;AAZD,gDAYC"}
@@ -0,0 +1,16 @@
1
+ import { SchemaNode } from '../schema-node';
2
+ /**
3
+ * e.g. `typeof Foo`
4
+ */
5
+ export declare class TypeQuerySchema implements SchemaNode {
6
+ private type;
7
+ private signature;
8
+ constructor(type: SchemaNode, signature: string);
9
+ getSignature(): string;
10
+ toObject(): {
11
+ constructorName: string;
12
+ type: SchemaNode;
13
+ signature: string;
14
+ };
15
+ toString(): string;
16
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeQuerySchema = void 0;
4
+ /**
5
+ * e.g. `typeof Foo`
6
+ */
7
+ class TypeQuerySchema {
8
+ constructor(type, signature) {
9
+ this.type = type;
10
+ this.signature = signature;
11
+ }
12
+ getSignature() {
13
+ return this.signature;
14
+ }
15
+ toObject() {
16
+ return {
17
+ constructorName: this.constructor.name,
18
+ type: this.type,
19
+ signature: this.signature,
20
+ };
21
+ }
22
+ toString() {
23
+ return `typeof ${this.type.toString()}`;
24
+ }
25
+ }
26
+ exports.TypeQuerySchema = TypeQuerySchema;
27
+ //# sourceMappingURL=type-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-query.js","sourceRoot":"","sources":["../../schemas/type-query.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,eAAe;IAC1B,YAAoB,IAAgB,EAAU,SAAiB;QAA3C,SAAI,GAAJ,IAAI,CAAY;QAAU,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IACnE,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,UAAU,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC1C,CAAC;CACF;AAjBD,0CAiBC"}
@@ -4,7 +4,6 @@ export declare type PlainTypeRefSchema = {
4
4
  name: string;
5
5
  componentId?: string;
6
6
  packageName?: string;
7
- node?: SchemaNode;
8
7
  };
9
8
  export declare class TypeRefSchema implements SchemaNode {
10
9
  /**
@@ -19,7 +18,6 @@ export declare class TypeRefSchema implements SchemaNode {
19
18
  * target package name. existing if type is defined in different package.
20
19
  */
21
20
  readonly packageName?: string;
22
- readonly node?: SchemaNode;
23
21
  constructor(
24
22
  /**
25
23
  * name of the reference to type.
@@ -32,7 +30,7 @@ export declare class TypeRefSchema implements SchemaNode {
32
30
  /**
33
31
  * target package name. existing if type is defined in different package.
34
32
  */
35
- packageName?: string, node?: SchemaNode);
33
+ packageName?: string);
36
34
  toObject(): {
37
35
  constructorName: string;
38
36
  name: string;
@@ -40,5 +38,9 @@ export declare class TypeRefSchema implements SchemaNode {
40
38
  packageName: string;
41
39
  };
42
40
  toString(): string;
41
+ /**
42
+ * whether this type was already exported in this component
43
+ */
44
+ isFromThisComponent(): boolean;
43
45
  static from(plainSchema: PlainTypeRefSchema): TypeRefSchema;
44
46
  }
@@ -19,11 +19,10 @@ class TypeRefSchema {
19
19
  /**
20
20
  * target package name. existing if type is defined in different package.
21
21
  */
22
- packageName, node) {
22
+ packageName) {
23
23
  this.name = name;
24
24
  this.componentId = componentId;
25
25
  this.packageName = packageName;
26
- this.node = node;
27
26
  }
28
27
  toObject() {
29
28
  return {
@@ -42,8 +41,14 @@ class TypeRefSchema {
42
41
  }
43
42
  return this.name;
44
43
  }
44
+ /**
45
+ * whether this type was already exported in this component
46
+ */
47
+ isFromThisComponent() {
48
+ return !this.componentId && !this.packageName;
49
+ }
45
50
  static from(plainSchema) {
46
- return new TypeRefSchema(plainSchema.name, plainSchema.componentId ? component_1.ComponentID.fromString(plainSchema.componentId) : undefined, plainSchema.packageName, plainSchema.node);
51
+ return new TypeRefSchema(plainSchema.name, plainSchema.componentId ? component_1.ComponentID.fromString(plainSchema.componentId) : undefined, plainSchema.packageName);
47
52
  }
48
53
  }
49
54
  exports.TypeRefSchema = TypeRefSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"type-ref.js","sourceRoot":"","sources":["../../schemas/type-ref.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAiD;AACjD,kDAA0B;AAU1B,MAAa,aAAa;IACxB;IACE;;OAEG;IACM,IAAY;IAErB;;OAEG;IACM,WAAyB;IAElC;;OAEG;IACM,WAAoB,EAEpB,IAAiB;QAZjB,SAAI,GAAJ,IAAI,CAAQ;QAKZ,gBAAW,GAAX,WAAW,CAAc;QAKzB,gBAAW,GAAX,WAAW,CAAS;QAEpB,SAAI,GAAJ,IAAI,CAAa;IACzB,CAAC;IAEJ,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,IAAI,EAAE,IAAI,CAAC,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CAAC;IAED,QAAQ;QACN,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SAC3C;QACD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,GAAG,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SACtD;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,WAA+B;QACzC,OAAO,IAAI,aAAa,CACtB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,uBAAW,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,EACrF,WAAW,CAAC,WAAW,CACxB,CAAC;IACJ,CAAC;CACF;AAnDD,sCAmDC"}
@@ -1,20 +1,16 @@
1
1
  import { SchemaNode } from '../schema-node';
2
- import { TypeRefSchema } from './type-ref';
3
2
  export declare class VariableSchema implements SchemaNode {
4
3
  readonly name: string;
5
4
  private signature;
6
5
  private type;
7
- constructor(name: string, signature: string, type: TypeRefSchema);
6
+ constructor(name: string, signature: string, type: SchemaNode);
8
7
  getSignature(): string;
9
8
  toObject(): {
10
9
  constructorName: string;
11
10
  name: string;
12
11
  signature: string;
13
- type: {
12
+ type: Record<string, any> & {
14
13
  constructorName: string;
15
- name: string;
16
- componentId: import("@teambit/component").ComponentID;
17
- packageName: string;
18
14
  };
19
15
  };
20
16
  toString(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"variable.js","sourceRoot":"","sources":["../../schemas/variable.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAI1B,MAAa,cAAc;IACzB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AC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,CAAC;CACF;AAlBD,wCAkBC"}
package/index.ts CHANGED
@@ -5,7 +5,7 @@ export {
5
5
  Module,
6
6
  StaticProperties,
7
7
  FunctionSchema,
8
- Parameter,
8
+ Modifier,
9
9
  TypeRefSchema,
10
10
  VariableSchema,
11
11
  ClassSchema,
@@ -18,5 +18,13 @@ export {
18
18
  InterfaceSchema,
19
19
  GetAccessorSchema,
20
20
  SetAccessorSchema,
21
+ TypeQuerySchema,
22
+ InferenceTypeSchema,
23
+ LiteralTypeSchema,
24
+ KeywordTypeSchema,
25
+ TypeArraySchema,
26
+ TypeOperatorSchema,
27
+ TupleTypeSchema,
28
+ ParameterSchema,
21
29
  } from './schemas';
22
30
  export type { JSONSchema, JSONSchemaObject } from './json-schema';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/semantics.entities.semantic-schema",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "homepage": "https://bit.dev/teambit/semantics/entities/semantic-schema",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.semantics",
8
8
  "name": "entities/semantic-schema",
9
- "version": "0.0.8"
9
+ "version": "0.0.9"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "4.1.2",
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_entities_semantic-schema@0.0.8/dist/semantic-schema.docs.md')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_entities_semantic-schema@0.0.9/dist/semantic-schema.docs.md')]
@@ -1,19 +1,19 @@
1
1
  import chalk from 'chalk';
2
2
  import { SchemaNode } from '../schema-node';
3
- import { Parameter } from './function';
3
+ import { ParameterSchema } from './parameter';
4
4
 
5
5
  export class ConstructorSchema implements SchemaNode {
6
- constructor(readonly args: Parameter[]) {}
6
+ constructor(readonly params: ParameterSchema[]) {}
7
7
 
8
8
  toString() {
9
- const argsStr = this.args.map((arg) => `${arg.name}: ${arg.type.toString()}`).join(', ');
10
- return `${chalk.bold('constructor')}(${argsStr})`;
9
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
10
+ return `${chalk.bold('constructor')}(${paramsStr})`;
11
11
  }
12
12
 
13
13
  toObject() {
14
14
  return {
15
15
  constructorName: this.constructor.name,
16
- args: this.args,
16
+ args: this.params.map((arg) => arg.toObject()),
17
17
  };
18
18
  }
19
19
  }
@@ -1,22 +1,18 @@
1
1
  import chalk from 'chalk';
2
2
  import { SchemaNode } from '../schema-node';
3
- import { TypeRefSchema } from './type-ref';
3
+ import { ParameterSchema } from './parameter';
4
4
 
5
- export type Parameter = {
6
- name: string;
7
- type: TypeRefSchema;
8
- defaultValue?: any;
9
- description?: string;
10
- };
5
+ export type Modifier = 'static' | 'public' | 'private' | 'protected' | 'readonly' | 'abstract' | 'async' | 'override';
11
6
 
12
7
  export class FunctionSchema implements SchemaNode {
13
8
  constructor(
14
9
  readonly name: string,
15
10
  // readonly doc: any,
16
- readonly params: Parameter[],
11
+ readonly params: ParameterSchema[],
17
12
 
18
- readonly returnType: TypeRefSchema,
19
- private signature: string
13
+ readonly returnType: SchemaNode,
14
+ readonly signature: string,
15
+ readonly modifiers: Modifier[] = []
20
16
  ) {}
21
17
 
22
18
  serialize() {}
@@ -34,11 +30,13 @@ export class FunctionSchema implements SchemaNode {
34
30
  params: this.params,
35
31
  returnType: this.returnType.toObject(),
36
32
  signature: this.signature,
33
+ modifiers: this.modifiers,
37
34
  };
38
35
  }
39
36
 
40
37
  toString() {
41
- const paramsStr = this.params.map((arg) => `${arg.name}: ${arg.type.toString()}`).join(', ');
42
- return `${chalk.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
38
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
39
+ const modifiersStr = this.modifiers.length ? `${this.modifiers.join(' ')} ` : '';
40
+ return `${modifiersStr}${chalk.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
43
41
  }
44
42
  }
@@ -1,9 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import { SchemaNode } from '../schema-node';
3
- import { TypeRefSchema } from './type-ref';
4
3
 
5
4
  export class GetAccessorSchema implements SchemaNode {
6
- constructor(private name: string, private type: TypeRefSchema, private signature: string) {}
5
+ constructor(private name: string, private type: SchemaNode, private signature: string) {}
7
6
  getSignature() {
8
7
  return this.signature;
9
8
  }
@@ -1,22 +1,21 @@
1
1
  import { SchemaNode } from '../schema-node';
2
- import { Parameter } from './function';
3
- import { TypeRefSchema } from './type-ref';
2
+ import { ParameterSchema } from './parameter';
4
3
 
5
4
  /**
6
5
  * e.g. `{ [key: string]: boolean };`
7
6
  * the "[key: string]" is the "parameter", and the "boolean" is the "type".
8
7
  */
9
8
  export class IndexSignatureSchema implements SchemaNode {
10
- constructor(private parameters: Parameter[], private type: TypeRefSchema) {}
9
+ constructor(private params: ParameterSchema[], private type: SchemaNode) {}
11
10
  toObject() {
12
11
  return {
13
12
  constructorName: this.constructor.name,
14
- parameters: this.parameters,
13
+ parameters: this.params,
15
14
  type: this.type.toObject(),
16
15
  };
17
16
  }
18
17
  toString() {
19
- const parameters = this.parameters.map((arg) => `${arg.name}: ${arg.type.toString()}`).join(', ');
20
- return `[${parameters}]: ${this.type.toString()}`;
18
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
19
+ return `[${paramsStr}]: ${this.type.toString()}`;
21
20
  }
22
21
  }
package/schemas/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Module } from './module';
2
2
  export { Export, StaticProperties } from './export';
3
- export { FunctionSchema, Parameter } from './function';
3
+ export { FunctionSchema, Modifier } from './function';
4
4
  export { TypeRefSchema } from './type-ref';
5
5
  export { VariableSchema } from './variable';
6
6
  export { ClassSchema } from './class';
@@ -13,3 +13,11 @@ export { IndexSignatureSchema } from './index-signature';
13
13
  export { InterfaceSchema } from './interface';
14
14
  export { GetAccessorSchema } from './get-accessor';
15
15
  export { SetAccessorSchema } from './set-accessor';
16
+ export { TypeQuerySchema } from './type-query';
17
+ export { InferenceTypeSchema } from './inference-type';
18
+ export { LiteralTypeSchema } from './literal-type';
19
+ export { KeywordTypeSchema } from './keyword-type';
20
+ export { TypeArraySchema } from './type-array';
21
+ export { TypeOperatorSchema } from './type-operator';
22
+ export { TupleTypeSchema } from './tuple-type';
23
+ export { ParameterSchema } from './parameter';
@@ -0,0 +1,19 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * where there is no explicit type, the type is taken from the "quickinfo" of tsserver
5
+ */
6
+ export class InferenceTypeSchema implements SchemaNode {
7
+ constructor(private type: string) {}
8
+
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ type: this.type,
13
+ };
14
+ }
15
+
16
+ toString() {
17
+ return this.type;
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. 'string', 'boolean', etc.
5
+ */
6
+ export class KeywordTypeSchema implements SchemaNode {
7
+ constructor(private name: string) {}
8
+
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ name: this.name,
13
+ };
14
+ }
15
+
16
+ toString() {
17
+ return this.name;
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. const a: 'a';
5
+ */
6
+ export class LiteralTypeSchema implements SchemaNode {
7
+ constructor(private name: string) {}
8
+
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ name: this.name,
13
+ };
14
+ }
15
+
16
+ toString() {
17
+ return this.name;
18
+ }
19
+ }
@@ -0,0 +1,23 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class ParameterSchema implements SchemaNode {
4
+ constructor(
5
+ readonly name: string,
6
+ readonly type: SchemaNode,
7
+ readonly defaultValue?: any,
8
+ readonly description?: string
9
+ ) {}
10
+
11
+ toObject() {
12
+ return {
13
+ constructorName: this.constructor.name,
14
+ name: this.name,
15
+ type: this.type.toObject(),
16
+ defaultValue: this.defaultValue,
17
+ description: this.description,
18
+ };
19
+ }
20
+ toString() {
21
+ return `${this.name}: ${this.type.toString()}`;
22
+ }
23
+ }
@@ -1,9 +1,9 @@
1
1
  import chalk from 'chalk';
2
- import { Parameter } from '.';
3
2
  import { SchemaNode } from '../schema-node';
3
+ import { ParameterSchema } from './parameter';
4
4
 
5
5
  export class SetAccessorSchema implements SchemaNode {
6
- constructor(private name: string, private param: Parameter, private signature: string) {}
6
+ constructor(private name: string, private param: ParameterSchema, private signature: string) {}
7
7
  getSignature() {
8
8
  return this.signature;
9
9
  }
@@ -18,6 +18,6 @@ export class SetAccessorSchema implements SchemaNode {
18
18
  }
19
19
 
20
20
  toString() {
21
- return `set ${chalk.bold(this.name)}(${this.param.name}: ${this.param.type})`;
21
+ return `set ${chalk.bold(this.name)}(${this.param.toString()})`;
22
22
  }
23
23
  }
@@ -0,0 +1,14 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TupleTypeSchema implements SchemaNode {
4
+ constructor(private elements: SchemaNode[]) {}
5
+ toObject() {
6
+ return {
7
+ constructorName: this.constructor.name,
8
+ elements: this.elements.map((elem) => elem.toObject()),
9
+ };
10
+ }
11
+ toString() {
12
+ return `[${this.elements.map((elem) => elem.toString()).join(', ')}]`;
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TypeArraySchema implements SchemaNode {
4
+ constructor(private type: SchemaNode) {}
5
+ toObject() {
6
+ return {
7
+ constructorName: this.constructor.name,
8
+ type: this.type.toObject(),
9
+ };
10
+ }
11
+ toString() {
12
+ return `${this.type.toString()}[]`;
13
+ }
14
+ }
@@ -0,0 +1,15 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TypeOperatorSchema implements SchemaNode {
4
+ constructor(private operatorName: string, private type: SchemaNode) {}
5
+ toObject() {
6
+ return {
7
+ constructorName: this.constructor.name,
8
+ operatorName: this.operatorName,
9
+ type: this.type.toObject(),
10
+ };
11
+ }
12
+ toString() {
13
+ return `${this.operatorName} ${this.type.toString()}`;
14
+ }
15
+ }
@@ -0,0 +1,23 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. `typeof Foo`
5
+ */
6
+ export class TypeQuerySchema implements SchemaNode {
7
+ constructor(private type: SchemaNode, private signature: string) {}
8
+ getSignature() {
9
+ return this.signature;
10
+ }
11
+
12
+ toObject() {
13
+ return {
14
+ constructorName: this.constructor.name,
15
+ type: this.type,
16
+ signature: this.signature,
17
+ };
18
+ }
19
+
20
+ toString() {
21
+ return `typeof ${this.type.toString()}`;
22
+ }
23
+ }
@@ -6,7 +6,6 @@ export type PlainTypeRefSchema = {
6
6
  name: string;
7
7
  componentId?: string;
8
8
  packageName?: string;
9
- node?: SchemaNode;
10
9
  };
11
10
 
12
11
  export class TypeRefSchema implements SchemaNode {
@@ -24,9 +23,7 @@ export class TypeRefSchema implements SchemaNode {
24
23
  /**
25
24
  * target package name. existing if type is defined in different package.
26
25
  */
27
- readonly packageName?: string,
28
-
29
- readonly node?: SchemaNode
26
+ readonly packageName?: string
30
27
  ) {}
31
28
 
32
29
  toObject() {
@@ -48,12 +45,18 @@ export class TypeRefSchema implements SchemaNode {
48
45
  return this.name;
49
46
  }
50
47
 
48
+ /**
49
+ * whether this type was already exported in this component
50
+ */
51
+ isFromThisComponent() {
52
+ return !this.componentId && !this.packageName;
53
+ }
54
+
51
55
  static from(plainSchema: PlainTypeRefSchema) {
52
56
  return new TypeRefSchema(
53
57
  plainSchema.name,
54
58
  plainSchema.componentId ? ComponentID.fromString(plainSchema.componentId) : undefined,
55
- plainSchema.packageName,
56
- plainSchema.node
59
+ plainSchema.packageName
57
60
  );
58
61
  }
59
62
  }
@@ -1,9 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import { SchemaNode } from '../schema-node';
3
- import { TypeRefSchema } from './type-ref';
4
3
 
5
4
  export class VariableSchema implements SchemaNode {
6
- constructor(readonly name: string, private signature: string, private type: TypeRefSchema) {}
5
+ constructor(readonly name: string, private signature: string, private type: SchemaNode) {}
7
6
  getSignature() {
8
7
  return this.signature;
9
8
  }