@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
@@ -5,16 +5,62 @@ import { writeTsNode, 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 a TypeScript class declaration.
10
+ *
11
+ * Written in this order: doc comment, decorators, modifiers, name, generics, heritage clauses, then the body.
12
+ *
13
+ * @template TBuilder The type of the source builder the class is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see tsClass
16
+ */
8
17
  export class TsClass extends TsNode {
18
+ /**
19
+ * The doc comment written above the class, or `null` to omit it.
20
+ * Descriptions of generic parameters are merged into it as `@template` tags.
21
+ */
9
22
  doc;
23
+ /**
24
+ * The decorators written above the class declaration, each on its own line.
25
+ */
10
26
  decorators;
27
+ /**
28
+ * Whether the class is written with the `export` keyword.
29
+ * @default false
30
+ */
11
31
  export;
32
+ /**
33
+ * Whether the class is written with the `abstract` modifier, placed after `export` when both are set.
34
+ * @default false
35
+ */
12
36
  abstract;
37
+ /**
38
+ * The class name, written verbatim after the `class` keyword.
39
+ */
13
40
  name;
41
+ /**
42
+ * The type parameters written in angle brackets after the name, such as `<T, U>`.
43
+ * Plain strings are written as-is; described parameters also add a `@template` tag to the doc comment.
44
+ */
14
45
  generics;
46
+ /**
47
+ * The base class written after `extends`, or `null` to omit the clause.
48
+ */
15
49
  extends;
50
+ /**
51
+ * The interfaces written after `implements` as a comma-separated list. The clause is omitted when empty.
52
+ */
16
53
  implements;
54
+ /**
55
+ * The members written in the class body, in the given order.
56
+ * Properties and bodyless methods without a doc comment or decorators are written without blank lines,
57
+ * other members are set off by blank lines.
58
+ */
17
59
  members;
60
+ /**
61
+ * Initializes a new instance of the TsClass class.
62
+ * @param options The options to use for this instance.
63
+ */
18
64
  constructor(options) {
19
65
  super(options);
20
66
  this.doc = options.doc ?? null;
@@ -69,6 +115,33 @@ export class TsClass extends TsNode {
69
115
  }
70
116
  }
71
117
  const createClass = (name, options) => new TsClass({ ...options, name });
118
+ /**
119
+ * Factory for creating class nodes. The `write` function writes one or more class nodes to a builder.
120
+ *
121
+ * @param name The name of the class.
122
+ * @param options The settings of the class. See `TsClass` for the available properties.
123
+ * @example
124
+ * ```ts
125
+ * tsClass('X', {
126
+ * decorators: [tsDecorator('decorator')],
127
+ * export: true,
128
+ * abstract: true,
129
+ * generics: ['T', 'U'],
130
+ * extends: tsReference('Y'),
131
+ * implements: [tsReference('Z')],
132
+ * members: [tsProperty('x'), tsConstructor(), tsMethod('y')],
133
+ * });
134
+ * // Emits:
135
+ * // @decorator
136
+ * // export abstract class X<T, U> extends Y implements Z {
137
+ * // x;
138
+ * //
139
+ * // constructor() {}
140
+ * //
141
+ * // y();
142
+ * // }
143
+ * ```
144
+ */
72
145
  export const tsClass = Object.assign(createClass, {
73
146
  write: writeTsNodes,
74
147
  });
@@ -7,13 +7,50 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
7
7
  accessModifier?: Nullable<TsAccessModifier>;
8
8
  readonly?: Nullable<boolean>;
9
9
  }>;
10
+ /**
11
+ * Represents a parameter of a constructor. Besides the properties of `TsParameter`, it can declare a class property by
12
+ * setting an access modifier and the `readonly` keyword.
13
+ *
14
+ * Written in this order: the decorators, the access modifier, the `readonly` keyword, the name, the optional marker,
15
+ * the type, then the default value. The description is not written on the parameter. The constructor adds it as a
16
+ * `@param` tag to its doc comment instead.
17
+ *
18
+ * @template TBuilder The type of the source builder the constructor parameter is written to.
19
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
20
+ * @see tsConstructorParameter
21
+ */
10
22
  export declare class TsConstructorParameter<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsParameter<TBuilder, TInjects | Injects> {
23
+ /**
24
+ * The access modifier written before the name, such as `public`. Setting one makes the parameter a class property.
25
+ * Nothing is written when `null`.
26
+ */
11
27
  accessModifier: TsAccessModifier | null;
28
+ /**
29
+ * Whether the parameter is written with the `readonly` keyword, placed after the access modifier.
30
+ * @default false
31
+ */
12
32
  readonly: boolean;
33
+ /**
34
+ * Initializes a new instance of the TsConstructorParameter class.
35
+ * @param options The options to use for this instance.
36
+ */
13
37
  constructor(options: Options<TBuilder, TInjects>);
14
38
  protected onWrite(builder: TBuilder): void;
15
39
  }
16
40
  declare const createConstructorParameter: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsConstructorParameter<TBuilder>;
41
+ /**
42
+ * Factory for creating constructor parameter nodes. The `write` function writes the parameters of a constructor to a
43
+ * builder, enclosed in parentheses.
44
+ *
45
+ * @param name The name of the parameter.
46
+ * @param options The settings of the parameter. See `TsConstructorParameter` for the available properties.
47
+ * @example
48
+ * ```ts
49
+ * tsConstructorParameter('name', { accessModifier: 'private', readonly: true, type: 'string' });
50
+ * // Emits:
51
+ * // private readonly name: string
52
+ * ```
53
+ */
17
54
  export declare const tsConstructorParameter: typeof createConstructorParameter & {
18
55
  write: typeof writeTsParameters;
19
56
  };
@@ -2,9 +2,33 @@ import { writeTsNode } from '../utils/write-ts-nodes.js';
2
2
  import { writeTsParameters } from '../utils/write-ts-parameters.js';
3
3
  import { tsDecorator } from './decorator.js';
4
4
  import { TsParameter } from './parameter.js';
5
+ /**
6
+ * Represents a parameter of a constructor. Besides the properties of `TsParameter`, it can declare a class property by
7
+ * setting an access modifier and the `readonly` keyword.
8
+ *
9
+ * Written in this order: the decorators, the access modifier, the `readonly` keyword, the name, the optional marker,
10
+ * the type, then the default value. The description is not written on the parameter. The constructor adds it as a
11
+ * `@param` tag to its doc comment instead.
12
+ *
13
+ * @template TBuilder The type of the source builder the constructor parameter is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see tsConstructorParameter
16
+ */
5
17
  export class TsConstructorParameter extends TsParameter {
18
+ /**
19
+ * The access modifier written before the name, such as `public`. Setting one makes the parameter a class property.
20
+ * Nothing is written when `null`.
21
+ */
6
22
  accessModifier;
23
+ /**
24
+ * Whether the parameter is written with the `readonly` keyword, placed after the access modifier.
25
+ * @default false
26
+ */
7
27
  readonly;
28
+ /**
29
+ * Initializes a new instance of the TsConstructorParameter class.
30
+ * @param options The options to use for this instance.
31
+ */
8
32
  constructor(options) {
9
33
  super(options);
10
34
  this.accessModifier = options.accessModifier ?? null;
@@ -38,6 +62,19 @@ export class TsConstructorParameter extends TsParameter {
38
62
  }
39
63
  }
40
64
  const createConstructorParameter = (name, options) => new TsConstructorParameter({ ...options, name });
65
+ /**
66
+ * Factory for creating constructor parameter nodes. The `write` function writes the parameters of a constructor to a
67
+ * builder, enclosed in parentheses.
68
+ *
69
+ * @param name The name of the parameter.
70
+ * @param options The settings of the parameter. See `TsConstructorParameter` for the available properties.
71
+ * @example
72
+ * ```ts
73
+ * tsConstructorParameter('name', { accessModifier: 'private', readonly: true, type: 'string' });
74
+ * // Emits:
75
+ * // private readonly name: string
76
+ * ```
77
+ */
41
78
  export const tsConstructorParameter = Object.assign(createConstructorParameter, {
42
79
  write: writeTsParameters,
43
80
  });
@@ -11,15 +11,59 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
11
11
  parameters?: Nullable<Nullable<TsConstructorParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
12
12
  body?: Nullable<AppendValue<TBuilder>>;
13
13
  }>;
14
+ /**
15
+ * Represents the constructor of a class.
16
+ *
17
+ * Written in this order: the doc comment, the decorators, the `constructor` keyword, the parameters in parentheses, a
18
+ * space, then the body in braces, followed by a line break.
19
+ *
20
+ * @template TBuilder The type of the source builder the constructor is written to.
21
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
22
+ * @see tsConstructor
23
+ */
14
24
  export declare class TsConstructor<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
25
+ /**
26
+ * The doc comment written above the constructor, or `null` to omit it. The descriptions of the parameters are added
27
+ * to it as `@param` tags, which also creates a doc comment when none is set.
28
+ */
15
29
  doc: TsDoc<TBuilder> | null;
30
+ /**
31
+ * The decorators written above the constructor, each on its own line.
32
+ */
16
33
  decorators: TsDecorator<TBuilder>[];
34
+ /**
35
+ * The parameters written in parentheses. They are written one per line when there are more than two, or when one of
36
+ * them has decorators.
37
+ */
17
38
  parameters: (TsConstructorParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
39
+ /**
40
+ * The statements written in the body, on their own indented lines, or `null` to write empty braces `{}`.
41
+ */
18
42
  body: AppendValue<TBuilder> | null;
43
+ /**
44
+ * Initializes a new instance of the TsConstructor class.
45
+ * @param options The options to use for this instance.
46
+ */
19
47
  constructor(options: Options<TBuilder, TInjects>);
20
48
  protected onWrite(builder: TBuilder): void;
21
49
  }
22
50
  declare const createConstructor: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsConstructor<TBuilder>;
51
+ /**
52
+ * Factory for creating constructor nodes. The `write` function writes one or more constructors to a builder.
53
+ *
54
+ * @param options The settings of the constructor. See `TsConstructor` for the available properties.
55
+ * @example
56
+ * ```ts
57
+ * tsConstructor({
58
+ * parameters: [tsConstructorParameter('x', { type: 'number' }), 'y'],
59
+ * body: 'this.x = x;',
60
+ * });
61
+ * // Emits:
62
+ * // constructor(x: number, y) {
63
+ * // this.x = x;
64
+ * // }
65
+ * ```
66
+ */
23
67
  export declare const tsConstructor: typeof createConstructor & {
24
68
  write: typeof writeTsNodes;
25
69
  };
@@ -4,11 +4,39 @@ import { writeTsNodes } from '../utils/write-ts-nodes.js';
4
4
  import { tsDecorator } from './decorator.js';
5
5
  import { tsDoc } from './doc.js';
6
6
  import { tsParameter } from './parameter.js';
7
+ /**
8
+ * Represents the constructor of a class.
9
+ *
10
+ * Written in this order: the doc comment, the decorators, the `constructor` keyword, the parameters in parentheses, a
11
+ * space, then the body in braces, followed by a line break.
12
+ *
13
+ * @template TBuilder The type of the source builder the constructor is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see tsConstructor
16
+ */
7
17
  export class TsConstructor extends TsNode {
18
+ /**
19
+ * The doc comment written above the constructor, or `null` to omit it. The descriptions of the parameters are added
20
+ * to it as `@param` tags, which also creates a doc comment when none is set.
21
+ */
8
22
  doc;
23
+ /**
24
+ * The decorators written above the constructor, each on its own line.
25
+ */
9
26
  decorators;
27
+ /**
28
+ * The parameters written in parentheses. They are written one per line when there are more than two, or when one of
29
+ * them has decorators.
30
+ */
10
31
  parameters;
32
+ /**
33
+ * The statements written in the body, on their own indented lines, or `null` to write empty braces `{}`.
34
+ */
11
35
  body;
36
+ /**
37
+ * Initializes a new instance of the TsConstructor class.
38
+ * @param options The options to use for this instance.
39
+ */
12
40
  constructor(options) {
13
41
  super(options);
14
42
  this.doc = options.doc ?? null;
@@ -35,6 +63,22 @@ export class TsConstructor extends TsNode {
35
63
  }
36
64
  }
37
65
  const createConstructor = (options) => new TsConstructor(options ?? {});
66
+ /**
67
+ * Factory for creating constructor nodes. The `write` function writes one or more constructors to a builder.
68
+ *
69
+ * @param options The settings of the constructor. See `TsConstructor` for the available properties.
70
+ * @example
71
+ * ```ts
72
+ * tsConstructor({
73
+ * parameters: [tsConstructorParameter('x', { type: 'number' }), 'y'],
74
+ * body: 'this.x = x;',
75
+ * });
76
+ * // Emits:
77
+ * // constructor(x: number, y) {
78
+ * // this.x = x;
79
+ * // }
80
+ * ```
81
+ */
38
82
  export const tsConstructor = Object.assign(createConstructor, {
39
83
  write: writeTsNodes,
40
84
  });
@@ -8,9 +8,30 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
8
8
  function: TsReference<TBuilder> | BasicAppendValue<TBuilder>;
9
9
  arguments?: Nullable<Nullable<TsArgument<TBuilder> | TsValue<TBuilder>>[]>;
10
10
  }>;
11
+ /**
12
+ * Represents a decorator, such as `@decorator` or `@decorator(arg1, arg2)`.
13
+ *
14
+ * Written in this order: the `@` sign, the function, then the arguments in parentheses when they are set.
15
+ *
16
+ * @template TBuilder The type of the source builder the decorator is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see tsDecorator
19
+ */
11
20
  export declare class TsDecorator<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
21
+ /**
22
+ * The function that is called as the decorator, such as `decorator` in `@decorator`. It is written right after the
23
+ * `@` sign, and nodes are written with their own output.
24
+ */
12
25
  function: TsReference<TBuilder> | BasicAppendValue<TBuilder>;
26
+ /**
27
+ * The arguments written in parentheses after the function, or `null` to write no parentheses. An empty array writes
28
+ * `()`, and more than two arguments are written one per line.
29
+ */
13
30
  arguments: (TsArgument<TBuilder> | TsValue<TBuilder>)[] | null;
31
+ /**
32
+ * Initializes a new instance of the TsDecorator class.
33
+ * @param options The options to use for this instance.
34
+ */
14
35
  constructor(options: Options<TBuilder, TInjects>);
15
36
  protected onWrite(builder: TBuilder): void;
16
37
  }
@@ -18,6 +39,20 @@ declare const createDecorator: <TBuilder extends SourceBuilder>(fn: Options<TBui
18
39
  declare const writeDecorators: <TBuilder extends SourceBuilder>(builder: TBuilder, nodes: SingleOrMultiple<Nullable<TsDecorator<TBuilder> | AppendValue<TBuilder>>>, options?: {
19
40
  multiline?: boolean;
20
41
  }) => void;
42
+ /**
43
+ * Factory for creating decorator nodes. The `write` function writes one or more decorators to a builder. With
44
+ * `multiline` each decorator gets its own line, otherwise the decorators are separated by spaces.
45
+ *
46
+ * @param fn The decorator function, such as `Injectable`.
47
+ * @param args The arguments of the decorator. Omit them to write no parentheses.
48
+ * @param options The settings of the decorator. See `TsDecorator` for the available properties.
49
+ * @example
50
+ * ```ts
51
+ * tsDecorator('Injectable', ["'root'"]);
52
+ * // Emits:
53
+ * // @Injectable('root')
54
+ * ```
55
+ */
21
56
  export declare const tsDecorator: typeof createDecorator & {
22
57
  write: typeof writeDecorators;
23
58
  };
@@ -2,9 +2,30 @@ import { notNullish, toArray, } from '@goast/core';
2
2
  import { TsNode } from '../node.js';
3
3
  import { writeTsNode } from '../utils/write-ts-nodes.js';
4
4
  import { tsArgument } from './argument.js';
5
+ /**
6
+ * Represents a decorator, such as `@decorator` or `@decorator(arg1, arg2)`.
7
+ *
8
+ * Written in this order: the `@` sign, the function, then the arguments in parentheses when they are set.
9
+ *
10
+ * @template TBuilder The type of the source builder the decorator is written to.
11
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
12
+ * @see tsDecorator
13
+ */
5
14
  export class TsDecorator extends TsNode {
15
+ /**
16
+ * The function that is called as the decorator, such as `decorator` in `@decorator`. It is written right after the
17
+ * `@` sign, and nodes are written with their own output.
18
+ */
6
19
  function;
20
+ /**
21
+ * The arguments written in parentheses after the function, or `null` to write no parentheses. An empty array writes
22
+ * `()`, and more than two arguments are written one per line.
23
+ */
7
24
  arguments;
25
+ /**
26
+ * Initializes a new instance of the TsDecorator class.
27
+ * @param options The options to use for this instance.
28
+ */
8
29
  constructor(options) {
9
30
  super(options);
10
31
  this.function = options.function;
@@ -30,6 +51,20 @@ const writeDecorators = (builder, nodes, options) => {
30
51
  b.append(options?.multiline ? '\n' : ' ');
31
52
  });
32
53
  };
54
+ /**
55
+ * Factory for creating decorator nodes. The `write` function writes one or more decorators to a builder. With
56
+ * `multiline` each decorator gets its own line, otherwise the decorators are separated by spaces.
57
+ *
58
+ * @param fn The decorator function, such as `Injectable`.
59
+ * @param args The arguments of the decorator. Omit them to write no parentheses.
60
+ * @param options The settings of the decorator. See `TsDecorator` for the available properties.
61
+ * @example
62
+ * ```ts
63
+ * tsDecorator('Injectable', ["'root'"]);
64
+ * // Emits:
65
+ * // @Injectable('root')
66
+ * ```
67
+ */
33
68
  export const tsDecorator = Object.assign(createDecorator, {
34
69
  write: writeDecorators,
35
70
  });
@@ -8,10 +8,34 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
8
8
  type?: Nullable<TsType<TBuilder>>;
9
9
  text?: Nullable<BasicAppendValue<TBuilder>>;
10
10
  }>;
11
+ /**
12
+ * Represents a single tag of a doc comment, such as `@param x The x value.` or `@returns`.
13
+ *
14
+ * Written in this order: the `@` sign and the tag name, the type in curly braces when set, then the text. The parts are
15
+ * separated by spaces. The enclosing doc comment writes its tags one per line.
16
+ *
17
+ * @template TBuilder The type of the source builder the doc tag is written to.
18
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
19
+ * @see tsDocTag
20
+ */
11
21
  export declare class TsDocTag<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
22
+ /**
23
+ * The name of the tag, written after the `@` sign, such as `param`. Any name is written, so custom tags work too.
24
+ */
12
25
  tag: string;
26
+ /**
27
+ * The type written in curly braces after the tag name, such as `{number}`. Nothing is written when `null`.
28
+ */
13
29
  type: TsType<TBuilder> | null;
30
+ /**
31
+ * The text written after the tag name and the type, such as the description of a parameter. Nothing is written when
32
+ * `null`.
33
+ */
14
34
  text: BasicAppendValue<TBuilder> | null;
35
+ /**
36
+ * Initializes a new instance of the TsDocTag class.
37
+ * @param options The options to use for this instance.
38
+ */
15
39
  constructor(options: Options<TBuilder, TInjects>);
16
40
  protected onWrite(builder: TBuilder): void;
17
41
  }
@@ -67,6 +91,21 @@ type _TsDocTagArgsMap<TBuilder extends SourceBuilder> = {
67
91
  };
68
92
  type _TsDocTagArgs<TTagName extends StringSuggestions<keyof _TsDocTagArgsMap<TBuilder>>, TBuilder extends SourceBuilder> = TTagName extends keyof _TsDocTagArgsMap<TBuilder> ? _TsDocTagArgsMap<TBuilder>[TTagName] extends (...args: any[]) => any ? ParametersWithOverloads<_TsDocTagArgsMap<TBuilder>[TTagName]> : never : [options?: _TsDocTagOpt<TBuilder>];
69
93
  declare function createDocTag<TTagName extends StringSuggestions<keyof _TsDocTagArgsMap<TBuilder>>, TBuilder extends SourceBuilder>(tag: TTagName, ...args: _TsDocTagArgs<TTagName, TBuilder>): TsDocTag<TBuilder>;
94
+ /**
95
+ * Factory for creating doc tag nodes. The arguments depend on the tag. For example, `param` takes a name and a
96
+ * description, and `author` takes a name and an optional email address, which it writes in angle brackets. Tags such as
97
+ * `returns` take a single description. Any tag accepts an optional last argument with the `type`, `text` or `inject`
98
+ * settings. The `write` function writes one or more tags to a builder.
99
+ *
100
+ * @param tag The name of the tag, written after the `@` sign.
101
+ * @param args The arguments of the tag. See the overloads of `tsDocTag` for the arguments that each tag takes.
102
+ * @example
103
+ * ```ts
104
+ * tsDocTag('param', 'x', 'The x coordinate.', { type: 'number' });
105
+ * // Emits:
106
+ * // @param {number} x The x coordinate.
107
+ * ```
108
+ */
70
109
  export declare const tsDocTag: typeof createDocTag & {
71
110
  write: typeof writeTsNodes;
72
111
  };
@@ -2,10 +2,34 @@ import { basicAppendValueGroup, notNullish, } from '@goast/core';
2
2
  import { isTypeScriptAppendValue } from '../../file-builder.js';
3
3
  import { TsNode } from '../node.js';
4
4
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
5
+ /**
6
+ * Represents a single tag of a doc comment, such as `@param x The x value.` or `@returns`.
7
+ *
8
+ * Written in this order: the `@` sign and the tag name, the type in curly braces when set, then the text. The parts are
9
+ * separated by spaces. The enclosing doc comment writes its tags one per line.
10
+ *
11
+ * @template TBuilder The type of the source builder the doc tag is written to.
12
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
13
+ * @see tsDocTag
14
+ */
5
15
  export class TsDocTag extends TsNode {
16
+ /**
17
+ * The name of the tag, written after the `@` sign, such as `param`. Any name is written, so custom tags work too.
18
+ */
6
19
  tag;
20
+ /**
21
+ * The type written in curly braces after the tag name, such as `{number}`. Nothing is written when `null`.
22
+ */
7
23
  type;
24
+ /**
25
+ * The text written after the tag name and the type, such as the description of a parameter. Nothing is written when
26
+ * `null`.
27
+ */
8
28
  text;
29
+ /**
30
+ * Initializes a new instance of the TsDocTag class.
31
+ * @param options The options to use for this instance.
32
+ */
9
33
  constructor(options) {
10
34
  super(options);
11
35
  this.tag = options.tag;
@@ -57,6 +81,21 @@ function createDocTag(tag, ...args) {
57
81
  inject: opt.inject,
58
82
  });
59
83
  }
84
+ /**
85
+ * Factory for creating doc tag nodes. The arguments depend on the tag. For example, `param` takes a name and a
86
+ * description, and `author` takes a name and an optional email address, which it writes in angle brackets. Tags such as
87
+ * `returns` take a single description. Any tag accepts an optional last argument with the `type`, `text` or `inject`
88
+ * settings. The `write` function writes one or more tags to a builder.
89
+ *
90
+ * @param tag The name of the tag, written after the `@` sign.
91
+ * @param args The arguments of the tag. See the overloads of `tsDocTag` for the arguments that each tag takes.
92
+ * @example
93
+ * ```ts
94
+ * tsDocTag('param', 'x', 'The x coordinate.', { type: 'number' });
95
+ * // Emits:
96
+ * // @param {number} x The x coordinate.
97
+ * ```
98
+ */
60
99
  export const tsDocTag = Object.assign(createDocTag, {
61
100
  write: writeTsNodes,
62
101
  });
@@ -9,9 +9,32 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
9
9
  description?: Nullable<BasicAppendValue<TBuilder>>;
10
10
  tags?: Nullable<Nullable<TsDocTag<TBuilder>>[]>;
11
11
  }>;
12
+ /**
13
+ * Represents a doc comment, which is written above the node that it documents. Nothing is written when the doc has
14
+ * neither a description nor tags.
15
+ *
16
+ * Written in this order: the description, an empty line when both a description and tags are set, then the tags, one
17
+ * per line. The comment starts on its own line and is followed by a line break.
18
+ *
19
+ * @template TBuilder The type of the source builder the doc comment is written to.
20
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
21
+ * @see tsDoc
22
+ */
12
23
  export declare class TsDoc<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
24
+ /**
25
+ * The text at the top of the doc comment. Each line of the text is prefixed with an asterisk. Nothing is written when
26
+ * `null`.
27
+ */
13
28
  description: BasicAppendValue<TBuilder> | null;
29
+ /**
30
+ * The tags written below the description, one per line, such as `@param` or `@returns`. An empty line separates them
31
+ * from the description.
32
+ */
14
33
  tags: TsDocTag<TBuilder>[];
34
+ /**
35
+ * Initializes a new instance of the TsDoc class.
36
+ * @param options The options to use for this instance.
37
+ */
15
38
  constructor(options: Options<TBuilder, TInjects>);
16
39
  protected onWrite(builder: TBuilder): void;
17
40
  }
@@ -21,6 +44,21 @@ declare function getDoc<TBuilder extends SourceBuilder>(baseDoc: TsDoc<TBuilder>
21
44
  generics?: Nullable<Nullable<TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
22
45
  }): TsDoc<TBuilder> | null;
23
46
  declare function isDocEmpty(doc: Nullable<TsDoc<SourceBuilder>>): boolean;
47
+ /**
48
+ * Factory for creating doc comment nodes. The `write` function writes a doc comment to a builder. The `get` function
49
+ * returns a doc with `@template` tags for the described generics and `@param` tags for the described parameters, placed
50
+ * before the existing tags. The `isEmpty` function tells whether a doc has nothing to write.
51
+ *
52
+ * @param options The settings of the doc comment. See `TsDoc` for the available properties.
53
+ * @example
54
+ * ```ts
55
+ * tsDoc({ description: 'Creates a user.', tags: [tsDocTag('returns', 'The new user.')] });
56
+ * // Emits the lines of the doc comment. The opening and closing delimiters are left out here:
57
+ * // Creates a user.
58
+ * //
59
+ * // @returns The new user.
60
+ * ```
61
+ */
24
62
  export declare const tsDoc: typeof createDoc & {
25
63
  write: typeof writeTsNodes;
26
64
  get: typeof getDoc;
@@ -4,9 +4,32 @@ import { writeTsNodes } from '../utils/write-ts-nodes.js';
4
4
  import { tsDocTag } from './doc-tag.js';
5
5
  import { TsGenericParameter } from './generic-parameter.js';
6
6
  import { TsParameter } from './parameter.js';
7
+ /**
8
+ * Represents a doc comment, which is written above the node that it documents. Nothing is written when the doc has
9
+ * neither a description nor tags.
10
+ *
11
+ * Written in this order: the description, an empty line when both a description and tags are set, then the tags, one
12
+ * per line. The comment starts on its own line and is followed by a line break.
13
+ *
14
+ * @template TBuilder The type of the source builder the doc comment is written to.
15
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
16
+ * @see tsDoc
17
+ */
7
18
  export class TsDoc extends TsNode {
19
+ /**
20
+ * The text at the top of the doc comment. Each line of the text is prefixed with an asterisk. Nothing is written when
21
+ * `null`.
22
+ */
8
23
  description;
24
+ /**
25
+ * The tags written below the description, one per line, such as `@param` or `@returns`. An empty line separates them
26
+ * from the description.
27
+ */
9
28
  tags;
29
+ /**
30
+ * Initializes a new instance of the TsDoc class.
31
+ * @param options The options to use for this instance.
32
+ */
10
33
  constructor(options) {
11
34
  super(options);
12
35
  this.description = options.description ?? null;
@@ -50,6 +73,21 @@ function getDoc(baseDoc, options) {
50
73
  function isDocEmpty(doc) {
51
74
  return !doc || (!doc.description && doc.tags.length === 0);
52
75
  }
76
+ /**
77
+ * Factory for creating doc comment nodes. The `write` function writes a doc comment to a builder. The `get` function
78
+ * returns a doc with `@template` tags for the described generics and `@param` tags for the described parameters, placed
79
+ * before the existing tags. The `isEmpty` function tells whether a doc has nothing to write.
80
+ *
81
+ * @param options The settings of the doc comment. See `TsDoc` for the available properties.
82
+ * @example
83
+ * ```ts
84
+ * tsDoc({ description: 'Creates a user.', tags: [tsDocTag('returns', 'The new user.')] });
85
+ * // Emits the lines of the doc comment. The opening and closing delimiters are left out here:
86
+ * // Creates a user.
87
+ * //
88
+ * // @returns The new user.
89
+ * ```
90
+ */
53
91
  export const tsDoc = Object.assign(createDoc, {
54
92
  write: writeTsNodes,
55
93
  get: getDoc,