@goast/typescript 0.9.0 → 0.9.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.
Files changed (143) hide show
  1. package/dist/src/assets.d.ts +18 -0
  2. package/dist/src/assets.js +18 -0
  3. package/dist/src/ast/common.d.ts +6 -0
  4. package/dist/src/ast/node.d.ts +15 -0
  5. package/dist/src/ast/node.js +15 -0
  6. package/dist/src/ast/nodes/argument.d.ts +31 -0
  7. package/dist/src/ast/nodes/argument.js +31 -0
  8. package/dist/src/ast/nodes/array-type.d.ts +32 -0
  9. package/dist/src/ast/nodes/array-type.js +32 -0
  10. package/dist/src/ast/nodes/arrow-function.d.ts +56 -0
  11. package/dist/src/ast/nodes/arrow-function.js +56 -0
  12. package/dist/src/ast/nodes/call.d.ts +34 -0
  13. package/dist/src/ast/nodes/call.js +34 -0
  14. package/dist/src/ast/nodes/class.d.ts +73 -0
  15. package/dist/src/ast/nodes/class.js +73 -0
  16. package/dist/src/ast/nodes/constructor-parameter.d.ts +37 -0
  17. package/dist/src/ast/nodes/constructor-parameter.js +37 -0
  18. package/dist/src/ast/nodes/constructor.d.ts +44 -0
  19. package/dist/src/ast/nodes/constructor.js +44 -0
  20. package/dist/src/ast/nodes/decorator.d.ts +35 -0
  21. package/dist/src/ast/nodes/decorator.js +35 -0
  22. package/dist/src/ast/nodes/doc-tag.d.ts +39 -0
  23. package/dist/src/ast/nodes/doc-tag.js +39 -0
  24. package/dist/src/ast/nodes/doc.d.ts +38 -0
  25. package/dist/src/ast/nodes/doc.js +38 -0
  26. package/dist/src/ast/nodes/enum-value.d.ts +37 -0
  27. package/dist/src/ast/nodes/enum-value.js +37 -0
  28. package/dist/src/ast/nodes/enum.d.ts +47 -0
  29. package/dist/src/ast/nodes/enum.js +47 -0
  30. package/dist/src/ast/nodes/export.d.ts +51 -0
  31. package/dist/src/ast/nodes/export.js +51 -0
  32. package/dist/src/ast/nodes/function-type.d.ts +35 -0
  33. package/dist/src/ast/nodes/function-type.js +35 -0
  34. package/dist/src/ast/nodes/function.d.ts +61 -0
  35. package/dist/src/ast/nodes/function.js +61 -0
  36. package/dist/src/ast/nodes/generic-parameter.d.ts +44 -0
  37. package/dist/src/ast/nodes/generic-parameter.js +44 -0
  38. package/dist/src/ast/nodes/indexer.d.ts +41 -0
  39. package/dist/src/ast/nodes/indexer.js +41 -0
  40. package/dist/src/ast/nodes/interface.d.ts +57 -0
  41. package/dist/src/ast/nodes/interface.js +57 -0
  42. package/dist/src/ast/nodes/intersection-type.d.ts +32 -0
  43. package/dist/src/ast/nodes/intersection-type.js +32 -0
  44. package/dist/src/ast/nodes/lookup-type.d.ts +34 -0
  45. package/dist/src/ast/nodes/lookup-type.js +34 -0
  46. package/dist/src/ast/nodes/method.d.ts +90 -0
  47. package/dist/src/ast/nodes/method.js +90 -0
  48. package/dist/src/ast/nodes/object-type.d.ts +34 -0
  49. package/dist/src/ast/nodes/object-type.js +34 -0
  50. package/dist/src/ast/nodes/object.d.ts +34 -0
  51. package/dist/src/ast/nodes/object.js +34 -0
  52. package/dist/src/ast/nodes/parameter.d.ts +51 -0
  53. package/dist/src/ast/nodes/parameter.js +51 -0
  54. package/dist/src/ast/nodes/property-accessor.d.ts +94 -0
  55. package/dist/src/ast/nodes/property-accessor.js +94 -0
  56. package/dist/src/ast/nodes/property.d.ts +113 -0
  57. package/dist/src/ast/nodes/property.js +113 -0
  58. package/dist/src/ast/nodes/reference.d.ts +90 -0
  59. package/dist/src/ast/nodes/reference.js +66 -0
  60. package/dist/src/ast/nodes/string.d.ts +35 -0
  61. package/dist/src/ast/nodes/string.js +35 -0
  62. package/dist/src/ast/nodes/tuple.d.ts +33 -0
  63. package/dist/src/ast/nodes/tuple.js +33 -0
  64. package/dist/src/ast/nodes/type-alias.d.ts +44 -0
  65. package/dist/src/ast/nodes/type-alias.js +44 -0
  66. package/dist/src/ast/nodes/typeof.d.ts +41 -0
  67. package/dist/src/ast/nodes/typeof.js +41 -0
  68. package/dist/src/ast/nodes/types.d.ts +12 -0
  69. package/dist/src/ast/nodes/union-type.d.ts +31 -0
  70. package/dist/src/ast/nodes/union-type.js +31 -0
  71. package/dist/src/ast/nodes/variable.d.ts +46 -0
  72. package/dist/src/ast/nodes/variable.js +46 -0
  73. package/dist/src/ast/references/angular.d.ts +7 -0
  74. package/dist/src/ast/references/angular.js +7 -0
  75. package/dist/src/ast/references/easy-network-stub.d.ts +4 -0
  76. package/dist/src/ast/references/easy-network-stub.js +4 -0
  77. package/dist/src/ast/references/k6.d.ts +3 -0
  78. package/dist/src/ast/references/k6.js +3 -0
  79. package/dist/src/ast/references/rxjs.d.ts +5 -0
  80. package/dist/src/ast/references/rxjs.js +5 -0
  81. package/dist/src/ast/references/typescript.d.ts +30 -0
  82. package/dist/src/ast/references/typescript.js +30 -0
  83. package/dist/src/ast/utils/get-type-script-builder-options.d.ts +8 -0
  84. package/dist/src/ast/utils/get-type-script-builder-options.js +8 -0
  85. package/dist/src/ast/utils/to-ts-node.d.ts +28 -0
  86. package/dist/src/ast/utils/write-ts-generic-parameters.d.ts +9 -0
  87. package/dist/src/ast/utils/write-ts-generic-parameters.js +9 -0
  88. package/dist/src/ast/utils/write-ts-members.d.ts +12 -0
  89. package/dist/src/ast/utils/write-ts-members.js +12 -0
  90. package/dist/src/ast/utils/write-ts-nodes.d.ts +16 -0
  91. package/dist/src/ast/utils/write-ts-nodes.js +16 -0
  92. package/dist/src/ast/utils/write-ts-parameters.d.ts +9 -0
  93. package/dist/src/ast/utils/write-ts-parameters.js +9 -0
  94. package/dist/src/common-results.d.ts +65 -0
  95. package/dist/src/config.d.ts +32 -0
  96. package/dist/src/config.js +5 -0
  97. package/dist/src/file-builder.d.ts +104 -0
  98. package/dist/src/file-builder.js +93 -0
  99. package/dist/src/generators/file-generator.d.ts +14 -0
  100. package/dist/src/generators/file-generator.js +9 -0
  101. package/dist/src/generators/models/model-generator.d.ts +24 -0
  102. package/dist/src/generators/models/model-generator.js +15 -0
  103. package/dist/src/generators/models/models-generator.d.ts +16 -0
  104. package/dist/src/generators/models/models-generator.js +16 -0
  105. package/dist/src/generators/models/models.d.ts +53 -0
  106. package/dist/src/generators/models/models.js +8 -0
  107. package/dist/src/generators/services/angular-services/angular-service-generator.d.ts +27 -0
  108. package/dist/src/generators/services/angular-services/angular-service-generator.js +17 -0
  109. package/dist/src/generators/services/angular-services/angular-services-generator.d.ts +21 -0
  110. package/dist/src/generators/services/angular-services/angular-services-generator.js +21 -0
  111. package/dist/src/generators/services/angular-services/models.d.ts +70 -1
  112. package/dist/src/generators/services/angular-services/models.js +5 -0
  113. package/dist/src/generators/services/angular-services/refs.d.ts +11 -0
  114. package/dist/src/generators/services/angular-services/refs.js +11 -0
  115. package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +22 -0
  116. package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.js +12 -0
  117. package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +16 -0
  118. package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -0
  119. package/dist/src/generators/services/easy-network-stub/models.d.ts +61 -0
  120. package/dist/src/generators/services/easy-network-stub/models.js +5 -0
  121. package/dist/src/generators/services/easy-network-stub/refs.d.ts +7 -0
  122. package/dist/src/generators/services/easy-network-stub/refs.js +7 -0
  123. package/dist/src/generators/services/fetch-clients/fetch-client-generator.d.ts +22 -0
  124. package/dist/src/generators/services/fetch-clients/fetch-client-generator.js +12 -0
  125. package/dist/src/generators/services/fetch-clients/fetch-clients-generator.d.ts +17 -0
  126. package/dist/src/generators/services/fetch-clients/fetch-clients-generator.js +17 -0
  127. package/dist/src/generators/services/fetch-clients/models.d.ts +64 -1
  128. package/dist/src/generators/services/fetch-clients/models.js +5 -0
  129. package/dist/src/generators/services/fetch-clients/refs.d.ts +7 -0
  130. package/dist/src/generators/services/fetch-clients/refs.js +7 -0
  131. package/dist/src/generators/services/k6-clients/k6-client-generator.d.ts +21 -0
  132. package/dist/src/generators/services/k6-clients/k6-client-generator.js +11 -0
  133. package/dist/src/generators/services/k6-clients/k6-clients-generator.d.ts +18 -0
  134. package/dist/src/generators/services/k6-clients/k6-clients-generator.js +18 -0
  135. package/dist/src/generators/services/k6-clients/models.d.ts +65 -1
  136. package/dist/src/generators/services/k6-clients/models.js +5 -0
  137. package/dist/src/generators/services/k6-clients/refs.d.ts +8 -0
  138. package/dist/src/generators/services/k6-clients/refs.js +8 -0
  139. package/dist/src/import-collection.d.ts +81 -0
  140. package/dist/src/import-collection.js +58 -0
  141. package/dist/src/utils.d.ts +62 -0
  142. package/dist/src/utils.js +47 -0
  143. package/package.json +2 -2
@@ -10,16 +10,60 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
10
10
  constraint?: Nullable<TsType<TBuilder>>;
11
11
  default?: Nullable<TsType<TBuilder>>;
12
12
  }>;
13
+ /**
14
+ * Represents a type parameter, such as `const T extends number = 4711`.
15
+ *
16
+ * Written in this order: the `const` modifier, the name, the constraint and the default type. The description is not
17
+ * written inline. Nodes with a doc comment, such as classes, functions and interfaces, add it as a `@template` tag.
18
+ *
19
+ * @template TBuilder The type of the source builder the type parameter is written to.
20
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
21
+ * @see tsGenericParameter
22
+ */
13
23
  export declare class TsGenericParameter<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
24
+ /**
25
+ * The description of the type parameter. It is not written inline. Enclosing nodes with a doc comment add it as a
26
+ * `@template` tag.
27
+ */
14
28
  description: BasicAppendValue<TBuilder> | null;
29
+ /**
30
+ * Whether the parameter is written with the `const` modifier, such as `const T`.
31
+ * @default false
32
+ */
15
33
  const: boolean;
34
+ /**
35
+ * The name of the type parameter, such as `T`.
36
+ */
16
37
  name: string;
38
+ /**
39
+ * The type that the parameter must extend, written as ` extends Type`, or `null` to omit it.
40
+ */
17
41
  constraint: TsType<TBuilder> | null;
42
+ /**
43
+ * The type used when no type argument is given, written as ` = Type`, or `null` to omit it.
44
+ */
18
45
  default: TsType<TBuilder> | null;
46
+ /**
47
+ * Initializes a new instance of the TsGenericParameter class.
48
+ * @param options The options to use for this instance.
49
+ */
19
50
  constructor(options: Options<TBuilder, TInjects>);
20
51
  protected onWrite(builder: TBuilder): void;
21
52
  }
22
53
  declare const createGenericParameter: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsGenericParameter<TBuilder>;
54
+ /**
55
+ * Factory for creating type parameter nodes. The `write` function writes the parameters in angle brackets, or nothing
56
+ * when there are none. More than two parameters are written one per line.
57
+ *
58
+ * @param name The name of the type parameter.
59
+ * @param options The settings of the type parameter. See `TsGenericParameter` for the available properties.
60
+ * @example
61
+ * ```ts
62
+ * tsGenericParameter('T', { constraint: 'number', default: '4711', const: true });
63
+ * // Emits:
64
+ * // const T extends number = 4711
65
+ * ```
66
+ */
23
67
  export declare const tsGenericParameter: typeof createGenericParameter & {
24
68
  write: typeof writeTsGenericParameters;
25
69
  };
@@ -1,12 +1,43 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { writeTsGenericParameters } from '../utils/write-ts-generic-parameters.js';
3
3
  import { writeTsNode } from '../utils/write-ts-nodes.js';
4
+ /**
5
+ * Represents a type parameter, such as `const T extends number = 4711`.
6
+ *
7
+ * Written in this order: the `const` modifier, the name, the constraint and the default type. The description is not
8
+ * written inline. Nodes with a doc comment, such as classes, functions and interfaces, add it as a `@template` tag.
9
+ *
10
+ * @template TBuilder The type of the source builder the type parameter is written to.
11
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
12
+ * @see tsGenericParameter
13
+ */
4
14
  export class TsGenericParameter extends TsNode {
15
+ /**
16
+ * The description of the type parameter. It is not written inline. Enclosing nodes with a doc comment add it as a
17
+ * `@template` tag.
18
+ */
5
19
  description;
20
+ /**
21
+ * Whether the parameter is written with the `const` modifier, such as `const T`.
22
+ * @default false
23
+ */
6
24
  const;
25
+ /**
26
+ * The name of the type parameter, such as `T`.
27
+ */
7
28
  name;
29
+ /**
30
+ * The type that the parameter must extend, written as ` extends Type`, or `null` to omit it.
31
+ */
8
32
  constraint;
33
+ /**
34
+ * The type used when no type argument is given, written as ` = Type`, or `null` to omit it.
35
+ */
9
36
  default;
37
+ /**
38
+ * Initializes a new instance of the TsGenericParameter class.
39
+ * @param options The options to use for this instance.
40
+ */
10
41
  constructor(options) {
11
42
  super(options);
12
43
  this.description = options.description ?? null;
@@ -35,6 +66,19 @@ export class TsGenericParameter extends TsNode {
35
66
  }
36
67
  }
37
68
  const createGenericParameter = (name, options) => new TsGenericParameter({ ...options, name });
69
+ /**
70
+ * Factory for creating type parameter nodes. The `write` function writes the parameters in angle brackets, or nothing
71
+ * when there are none. More than two parameters are written one per line.
72
+ *
73
+ * @param name The name of the type parameter.
74
+ * @param options The settings of the type parameter. See `TsGenericParameter` for the available properties.
75
+ * @example
76
+ * ```ts
77
+ * tsGenericParameter('T', { constraint: 'number', default: '4711', const: true });
78
+ * // Emits:
79
+ * // const T extends number = 4711
80
+ * ```
81
+ */
38
82
  export const tsGenericParameter = Object.assign(createGenericParameter, {
39
83
  write: writeTsGenericParameters,
40
84
  });
@@ -9,15 +9,56 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
9
9
  valueType: TsType<TBuilder>;
10
10
  readonly?: Nullable<boolean>;
11
11
  }>;
12
+ /**
13
+ * Represents an index signature, such as `readonly [key: string]: number;`.
14
+ *
15
+ * Written in this order: the `readonly` keyword when set, the key in square brackets as `name: keyType`, then
16
+ * `: valueType;`. The signature is followed by a line break. It is used as a member of an interface or a class.
17
+ *
18
+ * @template TBuilder The type of the source builder the index signature is written to.
19
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
20
+ * @see tsIndexer
21
+ */
12
22
  export declare class TsIndexer<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
23
+ /**
24
+ * The name of the key parameter, written before the key type, such as `id` in `[id: string]`.
25
+ * @default 'key'
26
+ */
13
27
  keyName: string;
28
+ /**
29
+ * The type of the keys, written after the key name in square brackets, such as `string`.
30
+ */
14
31
  keyType: TsType<TBuilder>;
32
+ /**
33
+ * The type of the values, written after the closing bracket, such as `number` in `: number;`.
34
+ */
15
35
  valueType: TsType<TBuilder>;
36
+ /**
37
+ * Whether the signature is written with the `readonly` keyword in front of it.
38
+ * @default false
39
+ */
16
40
  readonly: boolean;
41
+ /**
42
+ * Initializes a new instance of the TsIndexer class.
43
+ * @param options The options to use for this instance.
44
+ */
17
45
  constructor(options: Options<TBuilder, TInjects>);
18
46
  protected onWrite(builder: TBuilder): void;
19
47
  }
20
48
  declare const createIndexer: <TBuilder extends SourceBuilder>(keyType: Options<TBuilder>['keyType'], valueType: Options<TBuilder>['valueType'], options?: Prettify<Omit<Options<TBuilder>, 'keyType' | 'valueType'>>) => TsIndexer<TBuilder>;
49
+ /**
50
+ * Factory for creating index signature nodes. The `write` function writes one or more index signatures to a builder.
51
+ *
52
+ * @param keyType The type of the keys.
53
+ * @param valueType The type of the values.
54
+ * @param options The settings of the index signature. See `TsIndexer` for the available properties.
55
+ * @example
56
+ * ```ts
57
+ * tsIndexer('string', 'number', { keyName: 'id', readonly: true });
58
+ * // Emits:
59
+ * // readonly [id: string]: number;
60
+ * ```
61
+ */
21
62
  export declare const tsIndexer: typeof createIndexer & {
22
63
  write: typeof writeTsNodes;
23
64
  };
@@ -1,10 +1,38 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
3
+ /**
4
+ * Represents an index signature, such as `readonly [key: string]: number;`.
5
+ *
6
+ * Written in this order: the `readonly` keyword when set, the key in square brackets as `name: keyType`, then
7
+ * `: valueType;`. The signature is followed by a line break. It is used as a member of an interface or a class.
8
+ *
9
+ * @template TBuilder The type of the source builder the index signature is written to.
10
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
11
+ * @see tsIndexer
12
+ */
3
13
  export class TsIndexer extends TsNode {
14
+ /**
15
+ * The name of the key parameter, written before the key type, such as `id` in `[id: string]`.
16
+ * @default 'key'
17
+ */
4
18
  keyName;
19
+ /**
20
+ * The type of the keys, written after the key name in square brackets, such as `string`.
21
+ */
5
22
  keyType;
23
+ /**
24
+ * The type of the values, written after the closing bracket, such as `number` in `: number;`.
25
+ */
6
26
  valueType;
27
+ /**
28
+ * Whether the signature is written with the `readonly` keyword in front of it.
29
+ * @default false
30
+ */
7
31
  readonly;
32
+ /**
33
+ * Initializes a new instance of the TsIndexer class.
34
+ * @param options The options to use for this instance.
35
+ */
8
36
  constructor(options) {
9
37
  super(options);
10
38
  this.keyName = options.keyName ?? 'key';
@@ -26,6 +54,19 @@ export class TsIndexer extends TsNode {
26
54
  }
27
55
  }
28
56
  const createIndexer = (keyType, valueType, options) => new TsIndexer({ ...options, keyType, valueType });
57
+ /**
58
+ * Factory for creating index signature nodes. The `write` function writes one or more index signatures to a builder.
59
+ *
60
+ * @param keyType The type of the keys.
61
+ * @param valueType The type of the values.
62
+ * @param options The settings of the index signature. See `TsIndexer` for the available properties.
63
+ * @example
64
+ * ```ts
65
+ * tsIndexer('string', 'number', { keyName: 'id', readonly: true });
66
+ * // Emits:
67
+ * // readonly [id: string]: number;
68
+ * ```
69
+ */
29
70
  export const tsIndexer = Object.assign(createIndexer, {
30
71
  write: writeTsNodes,
31
72
  });
@@ -19,18 +19,75 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
19
19
  members?: Nullable<Nullable<Member<TBuilder>>[]>;
20
20
  }>;
21
21
  type Member<TBuilder extends SourceBuilder> = TsIndexer<TBuilder> | TsProperty<TBuilder> | TsMethod<TBuilder> | BasicAppendValue<TBuilder>;
22
+ /**
23
+ * Represents an interface declaration.
24
+ *
25
+ * Written in this order: the doc comment, the decorators, the `export` keyword, the name, the generics, the `extends`
26
+ * list, then the members in braces, followed by a line break.
27
+ *
28
+ * @template TBuilder The type of the source builder the interface is written to.
29
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
30
+ * @see tsInterface
31
+ */
22
32
  export declare class TsInterface<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
33
+ /**
34
+ * The doc comment written above the interface, or `null` to omit it. Descriptions of generic parameters are merged
35
+ * into it as `@template` tags.
36
+ */
23
37
  doc: TsDoc<TBuilder> | null;
38
+ /**
39
+ * The decorators written above the interface, each on its own line.
40
+ */
24
41
  decorators: TsDecorator<TBuilder>[];
42
+ /**
43
+ * Whether the interface is written with the `export` keyword.
44
+ * @default false
45
+ */
25
46
  export: boolean;
47
+ /**
48
+ * The name of the interface, written after the `interface` keyword.
49
+ */
26
50
  name: string;
51
+ /**
52
+ * The type parameters written in angle brackets after the name, such as `<T, U>`. Nothing is written when empty.
53
+ */
27
54
  generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
55
+ /**
56
+ * The interfaces written after `extends` as a comma-separated list. The clause is omitted when empty.
57
+ */
28
58
  extends: (TsReference<TBuilder> | BasicAppendValue<TBuilder>)[];
59
+ /**
60
+ * The members written in the body, in the given order. Properties and bodyless methods without a doc comment or
61
+ * decorators are written without blank lines, other members are set off by blank lines.
62
+ */
29
63
  members: Member<TBuilder>[];
64
+ /**
65
+ * Initializes a new instance of the TsInterface class.
66
+ * @param options The options to use for this instance.
67
+ */
30
68
  constructor(options: Options<TBuilder, TInjects>);
31
69
  protected onWrite(builder: TBuilder): void;
32
70
  }
33
71
  declare const createInterface: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsInterface<TBuilder>;
72
+ /**
73
+ * Factory for creating interface nodes. The `write` function writes one or more interfaces to a builder.
74
+ *
75
+ * @param name The name of the interface.
76
+ * @param options The settings of the interface. See `TsInterface` for the available properties.
77
+ * @example
78
+ * ```ts
79
+ * tsInterface('User', {
80
+ * export: true,
81
+ * extends: [tsReference('Entity')],
82
+ * members: [tsProperty('name', { type: 'string' }), tsMethod('save')],
83
+ * });
84
+ * // Emits:
85
+ * // export interface User extends Entity {
86
+ * // name: string;
87
+ * // save();
88
+ * // }
89
+ * ```
90
+ */
34
91
  export declare const tsInterface: typeof createInterface & {
35
92
  write: typeof writeTsNodes;
36
93
  };
@@ -5,14 +5,52 @@ import { writeTsNodes } from '../utils/write-ts-nodes.js';
5
5
  import { tsDecorator } from './decorator.js';
6
6
  import { tsDoc } from './doc.js';
7
7
  import { tsGenericParameter } from './generic-parameter.js';
8
+ /**
9
+ * Represents an interface declaration.
10
+ *
11
+ * Written in this order: the doc comment, the decorators, the `export` keyword, the name, the generics, the `extends`
12
+ * list, then the members in braces, followed by a line break.
13
+ *
14
+ * @template TBuilder The type of the source builder the interface is written to.
15
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
16
+ * @see tsInterface
17
+ */
8
18
  export class TsInterface extends TsNode {
19
+ /**
20
+ * The doc comment written above the interface, or `null` to omit it. Descriptions of generic parameters are merged
21
+ * into it as `@template` tags.
22
+ */
9
23
  doc;
24
+ /**
25
+ * The decorators written above the interface, each on its own line.
26
+ */
10
27
  decorators;
28
+ /**
29
+ * Whether the interface is written with the `export` keyword.
30
+ * @default false
31
+ */
11
32
  export;
33
+ /**
34
+ * The name of the interface, written after the `interface` keyword.
35
+ */
12
36
  name;
37
+ /**
38
+ * The type parameters written in angle brackets after the name, such as `<T, U>`. Nothing is written when empty.
39
+ */
13
40
  generics;
41
+ /**
42
+ * The interfaces written after `extends` as a comma-separated list. The clause is omitted when empty.
43
+ */
14
44
  extends;
45
+ /**
46
+ * The members written in the body, in the given order. Properties and bodyless methods without a doc comment or
47
+ * decorators are written without blank lines, other members are set off by blank lines.
48
+ */
15
49
  members;
50
+ /**
51
+ * Initializes a new instance of the TsInterface class.
52
+ * @param options The options to use for this instance.
53
+ */
16
54
  constructor(options) {
17
55
  super(options);
18
56
  this.doc = options.doc ?? null;
@@ -57,6 +95,25 @@ export class TsInterface extends TsNode {
57
95
  }
58
96
  }
59
97
  const createInterface = (name, options) => new TsInterface({ ...options, name });
98
+ /**
99
+ * Factory for creating interface nodes. The `write` function writes one or more interfaces to a builder.
100
+ *
101
+ * @param name The name of the interface.
102
+ * @param options The settings of the interface. See `TsInterface` for the available properties.
103
+ * @example
104
+ * ```ts
105
+ * tsInterface('User', {
106
+ * export: true,
107
+ * extends: [tsReference('Entity')],
108
+ * members: [tsProperty('name', { type: 'string' }), tsMethod('save')],
109
+ * });
110
+ * // Emits:
111
+ * // export interface User extends Entity {
112
+ * // name: string;
113
+ * // save();
114
+ * // }
115
+ * ```
116
+ */
60
117
  export const tsInterface = Object.assign(createInterface, {
61
118
  write: writeTsNodes,
62
119
  });
@@ -6,12 +6,44 @@ type Injects = never;
6
6
  type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<typeof TsNode<TBuilder, TInjects | Injects>, {
7
7
  types: Nullable<TsType<TBuilder>>[];
8
8
  }>;
9
+ /**
10
+ * Represents an intersection type, which combines several types with `&`, such as `(string) & (number)`.
11
+ *
12
+ * Each type is wrapped in parentheses. Nested intersection types are flattened into the same list. An intersection
13
+ * without types is written as `unknown`, and one with a single type is written as that type without parentheses.
14
+ * Intersections of more than three types are written with one type per line, and each line starts with `&`.
15
+ *
16
+ * @template TBuilder The type of the source builder the intersection type is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see tsIntersectionType
19
+ */
9
20
  export declare class TsIntersectionType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
21
+ /**
22
+ * The types that are combined, in the given order. Null entries are skipped. Nested intersection types are
23
+ * flattened into this list when the node is written, so they add no nested parentheses.
24
+ */
10
25
  types: TsType<TBuilder>[];
26
+ /**
27
+ * Initializes a new instance of the TsIntersectionType class.
28
+ * @param options The options to use for this instance.
29
+ */
11
30
  constructor(options: Options<TBuilder, TInjects>);
12
31
  protected onWrite(builder: TBuilder): void;
13
32
  }
14
33
  declare const createIntersectionType: <TBuilder extends SourceBuilder>(types: Options<TBuilder>['types'], options?: Prettify<Omit<Options<TBuilder>, 'types'>>) => TsIntersectionType<TBuilder>;
34
+ /**
35
+ * Factory for creating intersection type nodes. The `write` function writes one or more intersection type nodes to a
36
+ * builder.
37
+ *
38
+ * @param types The types to combine. See `TsIntersectionType.types` for how they are written.
39
+ * @param options The settings of the intersection type. See `TsIntersectionType` for the available properties.
40
+ * @example
41
+ * ```ts
42
+ * tsIntersectionType(['string', 'number']);
43
+ * // Emits:
44
+ * // (string) & (number)
45
+ * ```
46
+ */
15
47
  export declare const tsIntersectionType: typeof createIntersectionType & {
16
48
  write: typeof writeTsNodes;
17
49
  };
@@ -1,8 +1,27 @@
1
1
  import { notNullish } from '@goast/core';
2
2
  import { TsNode } from '../node.js';
3
3
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
4
+ /**
5
+ * Represents an intersection type, which combines several types with `&`, such as `(string) & (number)`.
6
+ *
7
+ * Each type is wrapped in parentheses. Nested intersection types are flattened into the same list. An intersection
8
+ * without types is written as `unknown`, and one with a single type is written as that type without parentheses.
9
+ * Intersections of more than three types are written with one type per line, and each line starts with `&`.
10
+ *
11
+ * @template TBuilder The type of the source builder the intersection type is written to.
12
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
13
+ * @see tsIntersectionType
14
+ */
4
15
  export class TsIntersectionType extends TsNode {
16
+ /**
17
+ * The types that are combined, in the given order. Null entries are skipped. Nested intersection types are
18
+ * flattened into this list when the node is written, so they add no nested parentheses.
19
+ */
5
20
  types;
21
+ /**
22
+ * Initializes a new instance of the TsIntersectionType class.
23
+ * @param options The options to use for this instance.
24
+ */
6
25
  constructor(options) {
7
26
  super(options);
8
27
  this.types = options.types.filter(notNullish);
@@ -24,6 +43,19 @@ export class TsIntersectionType extends TsNode {
24
43
  }
25
44
  }
26
45
  const createIntersectionType = (types, options) => new TsIntersectionType({ ...options, types });
46
+ /**
47
+ * Factory for creating intersection type nodes. The `write` function writes one or more intersection type nodes to a
48
+ * builder.
49
+ *
50
+ * @param types The types to combine. See `TsIntersectionType.types` for how they are written.
51
+ * @param options The settings of the intersection type. See `TsIntersectionType` for the available properties.
52
+ * @example
53
+ * ```ts
54
+ * tsIntersectionType(['string', 'number']);
55
+ * // Emits:
56
+ * // (string) & (number)
57
+ * ```
58
+ */
27
59
  export const tsIntersectionType = Object.assign(createIntersectionType, {
28
60
  write: writeTsNodes,
29
61
  });
@@ -7,13 +7,47 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
7
7
  type: TsType<TBuilder>;
8
8
  index: TsType<TBuilder>;
9
9
  }>;
10
+ /**
11
+ * Represents an indexed access type, which looks up the type of one member of another type, such as `(Foo)['bar']`.
12
+ *
13
+ * Both parts are wrapped in parentheses. The `type` is written first, followed by the `index` in square brackets. The
14
+ * injection points `beforeType` and `afterType` wrap the type, and `beforeIndex` and `afterIndex` wrap the index.
15
+ *
16
+ * @template TBuilder The type of the source builder the indexed access type is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see tsLookupType
19
+ */
10
20
  export declare class TsLookupType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
21
+ /**
22
+ * The type whose member is looked up. It is written in parentheses before the index, such as `(Foo)`.
23
+ */
11
24
  type: TsType<TBuilder>;
25
+ /**
26
+ * The index type or key that selects the member. It is written in square brackets after the type, such as `['bar']`.
27
+ * A plain string is written as it is, so the quotes of a string literal have to be part of the string.
28
+ */
12
29
  index: TsType<TBuilder>;
30
+ /**
31
+ * Initializes a new instance of the TsLookupType class.
32
+ * @param options The options to use for this instance.
33
+ */
13
34
  constructor(options: Options<TBuilder, TInjects>);
14
35
  protected onWrite(builder: TBuilder): void;
15
36
  }
16
37
  declare const createLookupType: <TBuilder extends SourceBuilder>(type: Options<TBuilder>['type'], index: Options<TBuilder>['index'], options?: Omit<Options<TBuilder>, 'type' | 'index'>) => TsLookupType<TBuilder>;
38
+ /**
39
+ * Factory for creating indexed access type nodes. The `write` function writes one or more of them to a builder.
40
+ *
41
+ * @param type The type whose member is looked up. See `TsLookupType.type`.
42
+ * @param index The index type or key. See `TsLookupType.index`.
43
+ * @param options The settings of the indexed access type. See `TsLookupType` for the available properties.
44
+ * @example
45
+ * ```ts
46
+ * tsLookupType('Foo', "'bar'");
47
+ * // Emits:
48
+ * // (Foo)['bar']
49
+ * ```
50
+ */
17
51
  export declare const tsLookupType: typeof createLookupType & {
18
52
  write: typeof writeTsNodes;
19
53
  };
@@ -1,8 +1,29 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
3
+ /**
4
+ * Represents an indexed access type, which looks up the type of one member of another type, such as `(Foo)['bar']`.
5
+ *
6
+ * Both parts are wrapped in parentheses. The `type` is written first, followed by the `index` in square brackets. The
7
+ * injection points `beforeType` and `afterType` wrap the type, and `beforeIndex` and `afterIndex` wrap the index.
8
+ *
9
+ * @template TBuilder The type of the source builder the indexed access type is written to.
10
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
11
+ * @see tsLookupType
12
+ */
3
13
  export class TsLookupType extends TsNode {
14
+ /**
15
+ * The type whose member is looked up. It is written in parentheses before the index, such as `(Foo)`.
16
+ */
4
17
  type;
18
+ /**
19
+ * The index type or key that selects the member. It is written in square brackets after the type, such as `['bar']`.
20
+ * A plain string is written as it is, so the quotes of a string literal have to be part of the string.
21
+ */
5
22
  index;
23
+ /**
24
+ * Initializes a new instance of the TsLookupType class.
25
+ * @param options The options to use for this instance.
26
+ */
6
27
  constructor(options) {
7
28
  super(options);
8
29
  this.type = options.type;
@@ -23,6 +44,19 @@ export class TsLookupType extends TsNode {
23
44
  }
24
45
  }
25
46
  const createLookupType = (type, index, options) => new TsLookupType({ ...options, type, index });
47
+ /**
48
+ * Factory for creating indexed access type nodes. The `write` function writes one or more of them to a builder.
49
+ *
50
+ * @param type The type whose member is looked up. See `TsLookupType.type`.
51
+ * @param index The index type or key. See `TsLookupType.index`.
52
+ * @param options The settings of the indexed access type. See `TsLookupType` for the available properties.
53
+ * @example
54
+ * ```ts
55
+ * tsLookupType('Foo', "'bar'");
56
+ * // Emits:
57
+ * // (Foo)['bar']
58
+ * ```
59
+ */
26
60
  export const tsLookupType = Object.assign(createLookupType, {
27
61
  write: writeTsNodes,
28
62
  });