@goast/typescript 0.9.0-beta.2 → 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
@@ -1,2 +1,20 @@
1
+ /**
2
+ * Gets the text content of an asset file that is shipped with the TypeScript generator package. The files are read
3
+ * from the `assets` directory of the package.
4
+ * @param relativePath The path of the asset file, relative to the `assets` directory, such as `client/angular/...`.
5
+ * @returns The text content of the asset file.
6
+ */
1
7
  export declare const getAssetFileContent: (relativePath: string) => Promise<string>;
8
+ /**
9
+ * Copies an asset file that is shipped with the TypeScript generator package into a directory. The file keeps its
10
+ * base name and replaces any existing file with that name.
11
+ * @param relativePath The path of the asset file, relative to the `assets` directory.
12
+ * @param destDir The directory to copy the file into.
13
+ * @param logName The name to show in the log message. Nothing is logged if omitted, and an empty string logs the path.
14
+ * @returns A promise that resolves when the file has been copied.
15
+ * @example
16
+ * ```ts
17
+ * await copyAssetFile('client/angular/request-builder.ts', targetDir, 'Request Builder');
18
+ * ```
19
+ */
2
20
  export declare const copyAssetFile: (relativePath: string, destDir: string, logName?: string) => Promise<void>;
@@ -1,5 +1,23 @@
1
1
  import { AssetManager } from '@goast/core';
2
2
  import { URL } from 'node:url';
3
3
  const manager = new AssetManager(new URL('../assets/', import.meta.url));
4
+ /**
5
+ * Gets the text content of an asset file that is shipped with the TypeScript generator package. The files are read
6
+ * from the `assets` directory of the package.
7
+ * @param relativePath The path of the asset file, relative to the `assets` directory, such as `client/angular/...`.
8
+ * @returns The text content of the asset file.
9
+ */
4
10
  export const getAssetFileContent = manager.getAssetFileContent.bind(manager);
11
+ /**
12
+ * Copies an asset file that is shipped with the TypeScript generator package into a directory. The file keeps its
13
+ * base name and replaces any existing file with that name.
14
+ * @param relativePath The path of the asset file, relative to the `assets` directory.
15
+ * @param destDir The directory to copy the file into.
16
+ * @param logName The name to show in the log message. Nothing is logged if omitted, and an empty string logs the path.
17
+ * @returns A promise that resolves when the file has been copied.
18
+ * @example
19
+ * ```ts
20
+ * await copyAssetFile('client/angular/request-builder.ts', targetDir, 'Request Builder');
21
+ * ```
22
+ */
5
23
  export const copyAssetFile = manager.copyAssetFile.bind(manager);
@@ -1 +1,7 @@
1
+ /**
2
+ * The access modifier of a class member, written before the member as `public`, `protected` or `private`.
3
+ * Members without an access modifier are written without a keyword.
4
+ * @see TsMethod
5
+ * @see TsProperty
6
+ */
1
7
  export type TsAccessModifier = 'public' | 'protected' | 'private';
@@ -1,4 +1,19 @@
1
1
  import { AstNode, type AstNodeOptions, type SourceBuilder } from '@goast/core';
2
+ /**
3
+ * Base class of the TypeScript AST nodes. It adds no output of its own: each subclass renders its code in `onWrite`,
4
+ * and the `write` method of `AstNode` wraps that output in the `before` and `after` injections.
5
+ *
6
+ * Besides `before` and `after`, a node accepts the injection points that its subclass declares through `TInjects`,
7
+ * such as `beforeName` or `afterBody`.
8
+ *
9
+ * @template TBuilder The type of the source builder the node is written to.
10
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
11
+ * @see AstNode
12
+ */
2
13
  export declare abstract class TsNode<TBuilder extends SourceBuilder, TInjects extends string = never> extends AstNode<TBuilder, TInjects> {
14
+ /**
15
+ * Initializes a new instance of the TsNode class.
16
+ * @param options The options to use for this instance. They are passed on to the `AstNode` base class.
17
+ */
3
18
  constructor(options: AstNodeOptions<typeof AstNode<TBuilder, TInjects>>);
4
19
  }
@@ -1,5 +1,20 @@
1
1
  import { AstNode } from '@goast/core';
2
+ /**
3
+ * Base class of the TypeScript AST nodes. It adds no output of its own: each subclass renders its code in `onWrite`,
4
+ * and the `write` method of `AstNode` wraps that output in the `before` and `after` injections.
5
+ *
6
+ * Besides `before` and `after`, a node accepts the injection points that its subclass declares through `TInjects`,
7
+ * such as `beforeName` or `afterBody`.
8
+ *
9
+ * @template TBuilder The type of the source builder the node is written to.
10
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
11
+ * @see AstNode
12
+ */
2
13
  export class TsNode extends AstNode {
14
+ /**
15
+ * Initializes a new instance of the TsNode class.
16
+ * @param options The options to use for this instance. They are passed on to the `AstNode` base class.
17
+ */
3
18
  constructor(options) {
4
19
  super(options);
5
20
  }
@@ -6,12 +6,43 @@ type Injects = never;
6
6
  type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<typeof TsNode<TBuilder, TInjects | Injects>, {
7
7
  value: TsValue<TBuilder>;
8
8
  }>;
9
+ /**
10
+ * Represents a single argument of a call or a decorator. The node itself writes only the value.
11
+ *
12
+ * The parentheses around the arguments and the separators between them are written by the `write` function. It writes
13
+ * the parentheses even when there are no arguments, and puts one argument per line when there are more than two.
14
+ *
15
+ * @template TBuilder The type of the source builder the argument is written to.
16
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
17
+ * @see tsArgument
18
+ */
9
19
  export declare class TsArgument<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
20
+ /**
21
+ * The value written as the argument, such as `42` or an expression. Nodes are written with their own output, and
22
+ * other values are appended as they are.
23
+ */
10
24
  value: TsValue<TBuilder>;
25
+ /**
26
+ * Initializes a new instance of the TsArgument class.
27
+ * @param options The options to use for this instance.
28
+ */
11
29
  constructor(options: Options<TBuilder, TInjects>);
12
30
  protected onWrite(builder: TBuilder): void;
13
31
  }
14
32
  declare const createArgument: <TBuilder extends SourceBuilder>(value: Options<TBuilder>['value'], options?: Prettify<Omit<Options<TBuilder>, 'value'>>) => TsArgument<TBuilder>;
33
+ /**
34
+ * Factory for creating argument nodes. The `write` function writes one or more arguments to a builder, enclosed in
35
+ * parentheses.
36
+ *
37
+ * @param value The value of the argument.
38
+ * @param options The settings of the argument. See `TsArgument` for the available properties.
39
+ * @example
40
+ * ```ts
41
+ * tsArgument('42');
42
+ * // Emits:
43
+ * // 42
44
+ * ```
45
+ */
15
46
  export declare const tsArgument: typeof createArgument & {
16
47
  write: typeof writeTsParameters;
17
48
  };
@@ -1,8 +1,26 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { writeTsNode } from '../utils/write-ts-nodes.js';
3
3
  import { writeTsParameters } from '../utils/write-ts-parameters.js';
4
+ /**
5
+ * Represents a single argument of a call or a decorator. The node itself writes only the value.
6
+ *
7
+ * The parentheses around the arguments and the separators between them are written by the `write` function. It writes
8
+ * the parentheses even when there are no arguments, and puts one argument per line when there are more than two.
9
+ *
10
+ * @template TBuilder The type of the source builder the argument is written to.
11
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
12
+ * @see tsArgument
13
+ */
4
14
  export class TsArgument extends TsNode {
15
+ /**
16
+ * The value written as the argument, such as `42` or an expression. Nodes are written with their own output, and
17
+ * other values are appended as they are.
18
+ */
5
19
  value;
20
+ /**
21
+ * Initializes a new instance of the TsArgument class.
22
+ * @param options The options to use for this instance.
23
+ */
6
24
  constructor(options) {
7
25
  super(options);
8
26
  this.value = options.value;
@@ -12,6 +30,19 @@ export class TsArgument extends TsNode {
12
30
  }
13
31
  }
14
32
  const createArgument = (value, options) => new TsArgument({ ...options, value });
33
+ /**
34
+ * Factory for creating argument nodes. The `write` function writes one or more arguments to a builder, enclosed in
35
+ * parentheses.
36
+ *
37
+ * @param value The value of the argument.
38
+ * @param options The settings of the argument. See `TsArgument` for the available properties.
39
+ * @example
40
+ * ```ts
41
+ * tsArgument('42');
42
+ * // Emits:
43
+ * // 42
44
+ * ```
45
+ */
15
46
  export const tsArgument = Object.assign(createArgument, {
16
47
  write: writeTsParameters,
17
48
  });
@@ -7,13 +7,45 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
7
7
  readonly?: Nullable<boolean>;
8
8
  type: TsType<TBuilder>;
9
9
  }>;
10
+ /**
11
+ * Represents an array type, such as `readonly (number)[]`. The element type is always wrapped in parentheses.
12
+ *
13
+ * Written in this order: the `readonly` keyword when set, the element type in parentheses, then `[]`.
14
+ *
15
+ * @template TBuilder The type of the source builder the array type is written to.
16
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
17
+ * @see tsArrayType
18
+ */
10
19
  export declare class TsArrayType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
20
+ /**
21
+ * Whether the array is written with the `readonly` keyword in front of it.
22
+ * @default false
23
+ */
11
24
  readonly: boolean;
25
+ /**
26
+ * The element type of the array. It is always wrapped in parentheses, so `number` is written as `(number)[]`.
27
+ */
12
28
  type: TsType<TBuilder>;
29
+ /**
30
+ * Initializes a new instance of the TsArrayType class.
31
+ * @param options The options to use for this instance.
32
+ */
13
33
  constructor(options: Options<TBuilder, TInjects>);
14
34
  protected onWrite(builder: TBuilder): void;
15
35
  }
16
36
  declare const createArrayType: <TBuilder extends SourceBuilder>(type: Options<TBuilder>['type'], options?: Prettify<Omit<Options<TBuilder>, 'type'>>) => TsArrayType<TBuilder>;
37
+ /**
38
+ * Factory for creating array type nodes. The `write` function writes one or more array types to a builder.
39
+ *
40
+ * @param type The element type of the array.
41
+ * @param options The settings of the array type. See `TsArrayType` for the available properties.
42
+ * @example
43
+ * ```ts
44
+ * tsArrayType('number', { readonly: true });
45
+ * // Emits:
46
+ * // readonly (number)[]
47
+ * ```
48
+ */
17
49
  export declare const tsArrayType: typeof createArrayType & {
18
50
  write: typeof writeTsNodes;
19
51
  };
@@ -1,8 +1,28 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
3
+ /**
4
+ * Represents an array type, such as `readonly (number)[]`. The element type is always wrapped in parentheses.
5
+ *
6
+ * Written in this order: the `readonly` keyword when set, the element type in parentheses, then `[]`.
7
+ *
8
+ * @template TBuilder The type of the source builder the array type is written to.
9
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
10
+ * @see tsArrayType
11
+ */
3
12
  export class TsArrayType extends TsNode {
13
+ /**
14
+ * Whether the array is written with the `readonly` keyword in front of it.
15
+ * @default false
16
+ */
4
17
  readonly;
18
+ /**
19
+ * The element type of the array. It is always wrapped in parentheses, so `number` is written as `(number)[]`.
20
+ */
5
21
  type;
22
+ /**
23
+ * Initializes a new instance of the TsArrayType class.
24
+ * @param options The options to use for this instance.
25
+ */
6
26
  constructor(options) {
7
27
  super(options);
8
28
  this.readonly = options.readonly ?? false;
@@ -19,6 +39,18 @@ export class TsArrayType extends TsNode {
19
39
  }
20
40
  }
21
41
  const createArrayType = (type, options) => new TsArrayType({ ...options, type });
42
+ /**
43
+ * Factory for creating array type nodes. The `write` function writes one or more array types to a builder.
44
+ *
45
+ * @param type The element type of the array.
46
+ * @param options The settings of the array type. See `TsArrayType` for the available properties.
47
+ * @example
48
+ * ```ts
49
+ * tsArrayType('number', { readonly: true });
50
+ * // Emits:
51
+ * // readonly (number)[]
52
+ * ```
53
+ */
22
54
  export const tsArrayType = Object.assign(createArrayType, {
23
55
  write: writeTsNodes,
24
56
  });
@@ -13,17 +13,73 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
13
13
  singleExpression?: Nullable<boolean>;
14
14
  body?: Nullable<AppendValue<TBuilder>>;
15
15
  }>;
16
+ /**
17
+ * Represents an arrow function, such as `(x, y): number => { ... }`.
18
+ *
19
+ * Written in this order: the `async` keyword when set, the generics, the parameters, the return type, ` => `, then the
20
+ * body. The function has no doc comment and no decorators.
21
+ *
22
+ * @template TBuilder The type of the source builder the arrow function is written to.
23
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
24
+ * @see tsArrowFunction
25
+ */
16
26
  export declare class TsArrowFunction<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
27
+ /**
28
+ * Whether the function is written with the `async` keyword in front of it.
29
+ * @default false
30
+ */
17
31
  async: boolean;
32
+ /**
33
+ * The type parameters written in angle brackets before the parameters, such as `<T, U>`. Nothing is written when
34
+ * there are none.
35
+ */
18
36
  generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
37
+ /**
38
+ * The parameters written in parentheses, such as `(x, y)`. The parentheses are always written, and more than two
39
+ * parameters are written one per line.
40
+ */
19
41
  parameters: (TsParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
42
+ /**
43
+ * The return type written after the parameters as `: Type`, or `null` to omit it.
44
+ */
20
45
  returnType: TsType<TBuilder> | null;
46
+ /**
47
+ * Whether the body is written directly after ` => ` without braces, such as `(x) => x * 2`. Without a body, empty
48
+ * braces are written instead.
49
+ * @default false
50
+ */
21
51
  singleExpression: boolean;
52
+ /**
53
+ * The body of the function, or `null` to write empty braces `{}`. A block body is written in braces on its own
54
+ * indented lines. With `singleExpression` the body is written without braces.
55
+ */
22
56
  body: AppendValue<TBuilder> | null;
57
+ /**
58
+ * Initializes a new instance of the TsArrowFunction class.
59
+ * @param options The options to use for this instance.
60
+ */
23
61
  constructor(options: Options<TBuilder, TInjects>);
24
62
  protected onWrite(builder: TBuilder): void;
25
63
  }
26
64
  declare const createArrowFunction: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => TsArrowFunction<TBuilder>;
65
+ /**
66
+ * Factory for creating arrow function nodes. The `write` function writes one or more arrow functions to a builder.
67
+ *
68
+ * @param options The settings of the arrow function. See `TsArrowFunction` for the available properties.
69
+ * @example
70
+ * ```ts
71
+ * tsArrowFunction({
72
+ * generics: ['T', 'U'],
73
+ * parameters: ['x', 'y'],
74
+ * returnType: 'number',
75
+ * body: 'return 42;',
76
+ * });
77
+ * // Emits:
78
+ * // <T, U>(x, y): number => {
79
+ * // return 42;
80
+ * // }
81
+ * ```
82
+ */
27
83
  export declare const tsArrowFunction: typeof createArrowFunction & {
28
84
  write: typeof writeTsNodes;
29
85
  };
@@ -3,13 +3,51 @@ import { TsNode } from '../node.js';
3
3
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
4
4
  import { tsGenericParameter } from './generic-parameter.js';
5
5
  import { tsParameter } from './parameter.js';
6
+ /**
7
+ * Represents an arrow function, such as `(x, y): number => { ... }`.
8
+ *
9
+ * Written in this order: the `async` keyword when set, the generics, the parameters, the return type, ` => `, then the
10
+ * body. The function has no doc comment and no decorators.
11
+ *
12
+ * @template TBuilder The type of the source builder the arrow function is written to.
13
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
14
+ * @see tsArrowFunction
15
+ */
6
16
  export class TsArrowFunction extends TsNode {
17
+ /**
18
+ * Whether the function is written with the `async` keyword in front of it.
19
+ * @default false
20
+ */
7
21
  async;
22
+ /**
23
+ * The type parameters written in angle brackets before the parameters, such as `<T, U>`. Nothing is written when
24
+ * there are none.
25
+ */
8
26
  generics;
27
+ /**
28
+ * The parameters written in parentheses, such as `(x, y)`. The parentheses are always written, and more than two
29
+ * parameters are written one per line.
30
+ */
9
31
  parameters;
32
+ /**
33
+ * The return type written after the parameters as `: Type`, or `null` to omit it.
34
+ */
10
35
  returnType;
36
+ /**
37
+ * Whether the body is written directly after ` => ` without braces, such as `(x) => x * 2`. Without a body, empty
38
+ * braces are written instead.
39
+ * @default false
40
+ */
11
41
  singleExpression;
42
+ /**
43
+ * The body of the function, or `null` to write empty braces `{}`. A block body is written in braces on its own
44
+ * indented lines. With `singleExpression` the body is written without braces.
45
+ */
12
46
  body;
47
+ /**
48
+ * Initializes a new instance of the TsArrowFunction class.
49
+ * @param options The options to use for this instance.
50
+ */
13
51
  constructor(options) {
14
52
  super(options);
15
53
  this.async = options.async ?? false;
@@ -47,6 +85,24 @@ export class TsArrowFunction extends TsNode {
47
85
  }
48
86
  }
49
87
  const createArrowFunction = (options) => new TsArrowFunction(options ?? {});
88
+ /**
89
+ * Factory for creating arrow function nodes. The `write` function writes one or more arrow functions to a builder.
90
+ *
91
+ * @param options The settings of the arrow function. See `TsArrowFunction` for the available properties.
92
+ * @example
93
+ * ```ts
94
+ * tsArrowFunction({
95
+ * generics: ['T', 'U'],
96
+ * parameters: ['x', 'y'],
97
+ * returnType: 'number',
98
+ * body: 'return 42;',
99
+ * });
100
+ * // Emits:
101
+ * // <T, U>(x, y): number => {
102
+ * // return 42;
103
+ * // }
104
+ * ```
105
+ */
50
106
  export const tsArrowFunction = Object.assign(createArrowFunction, {
51
107
  write: writeTsNodes,
52
108
  });
@@ -8,13 +8,47 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
8
8
  path: Nullable<TsType<TBuilder> | TsValue<TBuilder>>[];
9
9
  arguments?: Nullable<Nullable<TsArgument<TBuilder> | TsValue<TBuilder>>[]>;
10
10
  }>;
11
+ /**
12
+ * Represents a call, such as `console.log('x', 42)`.
13
+ *
14
+ * Written in this order: the path, with its segments joined by dots, then the arguments in parentheses when they are
15
+ * set.
16
+ *
17
+ * @template TBuilder The type of the source builder the call is written to.
18
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
19
+ * @see tsCall
20
+ */
11
21
  export declare class TsCall<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
22
+ /**
23
+ * The segments of the called expression, joined with dots, such as `a.b.c`. Nullish segments are left out.
24
+ */
12
25
  path: (TsType<TBuilder> | TsValue<TBuilder>)[];
26
+ /**
27
+ * The arguments written in parentheses after the path, or `null` to write no parentheses at all. An empty array
28
+ * writes `()`.
29
+ */
13
30
  arguments: (TsArgument<TBuilder> | TsValue<TBuilder>)[] | null;
31
+ /**
32
+ * Initializes a new instance of the TsCall 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
  }
17
38
  declare const createCall: <TBuilder extends SourceBuilder>(path: Options<TBuilder>['path'] | ArrayItem<Options<TBuilder>['path']>, args?: Options<TBuilder>['arguments'], options?: Prettify<Omit<Options<TBuilder>, 'path' | 'arguments'>>) => TsCall<TBuilder>;
39
+ /**
40
+ * Factory for creating call nodes. The `write` function writes one or more calls to a builder.
41
+ *
42
+ * @param path The segments of the called expression. A single segment can be passed without an array.
43
+ * @param args The arguments of the call. Omit them to write no parentheses.
44
+ * @param options The settings of the call. See `TsCall` for the available properties.
45
+ * @example
46
+ * ```ts
47
+ * tsCall(['console', 'log'], ["'Hello'", '42']);
48
+ * // Emits:
49
+ * // console.log('Hello', 42)
50
+ * ```
51
+ */
18
52
  export declare const tsCall: typeof createCall & {
19
53
  write: typeof writeTsNodes;
20
54
  };
@@ -2,9 +2,30 @@ import { notNullish, } from '@goast/core';
2
2
  import { TsNode } from '../node.js';
3
3
  import { writeTsNodes } from '../utils/write-ts-nodes.js';
4
4
  import { tsArgument } from './argument.js';
5
+ /**
6
+ * Represents a call, such as `console.log('x', 42)`.
7
+ *
8
+ * Written in this order: the path, with its segments joined by dots, then the arguments in parentheses when they are
9
+ * set.
10
+ *
11
+ * @template TBuilder The type of the source builder the call is written to.
12
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
13
+ * @see tsCall
14
+ */
5
15
  export class TsCall extends TsNode {
16
+ /**
17
+ * The segments of the called expression, joined with dots, such as `a.b.c`. Nullish segments are left out.
18
+ */
6
19
  path;
20
+ /**
21
+ * The arguments written in parentheses after the path, or `null` to write no parentheses at all. An empty array
22
+ * writes `()`.
23
+ */
7
24
  arguments;
25
+ /**
26
+ * Initializes a new instance of the TsCall class.
27
+ * @param options The options to use for this instance.
28
+ */
8
29
  constructor(options) {
9
30
  super(options);
10
31
  this.path = options.path.filter(notNullish);
@@ -18,6 +39,19 @@ export class TsCall extends TsNode {
18
39
  }
19
40
  }
20
41
  const createCall = (path, args, options) => new TsCall({ ...options, path: Array.isArray(path) ? path : [path], arguments: args });
42
+ /**
43
+ * Factory for creating call nodes. The `write` function writes one or more calls to a builder.
44
+ *
45
+ * @param path The segments of the called expression. A single segment can be passed without an array.
46
+ * @param args The arguments of the call. Omit them to write no parentheses.
47
+ * @param options The settings of the call. See `TsCall` for the available properties.
48
+ * @example
49
+ * ```ts
50
+ * tsCall(['console', 'log'], ["'Hello'", '42']);
51
+ * // Emits:
52
+ * // console.log('Hello', 42)
53
+ * ```
54
+ */
21
55
  export const tsCall = Object.assign(createCall, {
22
56
  write: writeTsNodes,
23
57
  });
@@ -22,20 +22,93 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
22
22
  members?: Nullable<Nullable<Member<TBuilder>>[]>;
23
23
  }>;
24
24
  type Member<TBuilder extends SourceBuilder> = TsProperty<TBuilder> | TsMethod<TBuilder> | TsIndexer<TBuilder> | TsConstructor<TBuilder> | BasicAppendValue<TBuilder>;
25
+ /**
26
+ * Represents a TypeScript class declaration.
27
+ *
28
+ * Written in this order: doc comment, decorators, modifiers, name, generics, heritage clauses, then the body.
29
+ *
30
+ * @template TBuilder The type of the source builder the class is written to.
31
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
32
+ * @see tsClass
33
+ */
25
34
  export declare class TsClass<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
35
+ /**
36
+ * The doc comment written above the class, or `null` to omit it.
37
+ * Descriptions of generic parameters are merged into it as `@template` tags.
38
+ */
26
39
  doc: TsDoc<TBuilder> | null;
40
+ /**
41
+ * The decorators written above the class declaration, each on its own line.
42
+ */
27
43
  decorators: TsDecorator<TBuilder>[];
44
+ /**
45
+ * Whether the class is written with the `export` keyword.
46
+ * @default false
47
+ */
28
48
  export: boolean;
49
+ /**
50
+ * Whether the class is written with the `abstract` modifier, placed after `export` when both are set.
51
+ * @default false
52
+ */
29
53
  abstract: boolean;
54
+ /**
55
+ * The class name, written verbatim after the `class` keyword.
56
+ */
30
57
  name: string;
58
+ /**
59
+ * The type parameters written in angle brackets after the name, such as `<T, U>`.
60
+ * Plain strings are written as-is; described parameters also add a `@template` tag to the doc comment.
61
+ */
31
62
  generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
63
+ /**
64
+ * The base class written after `extends`, or `null` to omit the clause.
65
+ */
32
66
  extends: TsReference<TBuilder> | BasicAppendValue<TBuilder> | null;
67
+ /**
68
+ * The interfaces written after `implements` as a comma-separated list. The clause is omitted when empty.
69
+ */
33
70
  implements: (TsReference<TBuilder> | BasicAppendValue<TBuilder>)[];
71
+ /**
72
+ * The members written in the class body, in the given order.
73
+ * Properties and bodyless methods without a doc comment or decorators are written without blank lines,
74
+ * other members are set off by blank lines.
75
+ */
34
76
  members: Member<TBuilder>[];
77
+ /**
78
+ * Initializes a new instance of the TsClass class.
79
+ * @param options The options to use for this instance.
80
+ */
35
81
  constructor(options: Options<TBuilder, TInjects>);
36
82
  protected onWrite(builder: TBuilder): void;
37
83
  }
38
84
  declare const createClass: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => TsClass<TBuilder>;
85
+ /**
86
+ * Factory for creating class nodes. The `write` function writes one or more class nodes to a builder.
87
+ *
88
+ * @param name The name of the class.
89
+ * @param options The settings of the class. See `TsClass` for the available properties.
90
+ * @example
91
+ * ```ts
92
+ * tsClass('X', {
93
+ * decorators: [tsDecorator('decorator')],
94
+ * export: true,
95
+ * abstract: true,
96
+ * generics: ['T', 'U'],
97
+ * extends: tsReference('Y'),
98
+ * implements: [tsReference('Z')],
99
+ * members: [tsProperty('x'), tsConstructor(), tsMethod('y')],
100
+ * });
101
+ * // Emits:
102
+ * // @decorator
103
+ * // export abstract class X<T, U> extends Y implements Z {
104
+ * // x;
105
+ * //
106
+ * // constructor() {}
107
+ * //
108
+ * // y();
109
+ * // }
110
+ * ```
111
+ */
39
112
  export declare const tsClass: typeof createClass & {
40
113
  write: typeof writeTsNodes;
41
114
  };