@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.
- package/dist/src/assets.d.ts +18 -0
- package/dist/src/assets.js +18 -0
- package/dist/src/ast/common.d.ts +6 -0
- package/dist/src/ast/node.d.ts +15 -0
- package/dist/src/ast/node.js +15 -0
- package/dist/src/ast/nodes/argument.d.ts +31 -0
- package/dist/src/ast/nodes/argument.js +31 -0
- package/dist/src/ast/nodes/array-type.d.ts +32 -0
- package/dist/src/ast/nodes/array-type.js +32 -0
- package/dist/src/ast/nodes/arrow-function.d.ts +56 -0
- package/dist/src/ast/nodes/arrow-function.js +56 -0
- package/dist/src/ast/nodes/call.d.ts +34 -0
- package/dist/src/ast/nodes/call.js +34 -0
- package/dist/src/ast/nodes/class.d.ts +73 -0
- package/dist/src/ast/nodes/class.js +73 -0
- package/dist/src/ast/nodes/constructor-parameter.d.ts +37 -0
- package/dist/src/ast/nodes/constructor-parameter.js +37 -0
- package/dist/src/ast/nodes/constructor.d.ts +44 -0
- package/dist/src/ast/nodes/constructor.js +44 -0
- package/dist/src/ast/nodes/decorator.d.ts +35 -0
- package/dist/src/ast/nodes/decorator.js +35 -0
- package/dist/src/ast/nodes/doc-tag.d.ts +39 -0
- package/dist/src/ast/nodes/doc-tag.js +39 -0
- package/dist/src/ast/nodes/doc.d.ts +38 -0
- package/dist/src/ast/nodes/doc.js +38 -0
- package/dist/src/ast/nodes/enum-value.d.ts +37 -0
- package/dist/src/ast/nodes/enum-value.js +37 -0
- package/dist/src/ast/nodes/enum.d.ts +47 -0
- package/dist/src/ast/nodes/enum.js +47 -0
- package/dist/src/ast/nodes/export.d.ts +51 -0
- package/dist/src/ast/nodes/export.js +51 -0
- package/dist/src/ast/nodes/function-type.d.ts +35 -0
- package/dist/src/ast/nodes/function-type.js +35 -0
- package/dist/src/ast/nodes/function.d.ts +61 -0
- package/dist/src/ast/nodes/function.js +61 -0
- package/dist/src/ast/nodes/generic-parameter.d.ts +44 -0
- package/dist/src/ast/nodes/generic-parameter.js +44 -0
- package/dist/src/ast/nodes/indexer.d.ts +41 -0
- package/dist/src/ast/nodes/indexer.js +41 -0
- package/dist/src/ast/nodes/interface.d.ts +57 -0
- package/dist/src/ast/nodes/interface.js +57 -0
- package/dist/src/ast/nodes/intersection-type.d.ts +32 -0
- package/dist/src/ast/nodes/intersection-type.js +32 -0
- package/dist/src/ast/nodes/lookup-type.d.ts +34 -0
- package/dist/src/ast/nodes/lookup-type.js +34 -0
- package/dist/src/ast/nodes/method.d.ts +90 -0
- package/dist/src/ast/nodes/method.js +90 -0
- package/dist/src/ast/nodes/object-type.d.ts +34 -0
- package/dist/src/ast/nodes/object-type.js +34 -0
- package/dist/src/ast/nodes/object.d.ts +34 -0
- package/dist/src/ast/nodes/object.js +34 -0
- package/dist/src/ast/nodes/parameter.d.ts +51 -0
- package/dist/src/ast/nodes/parameter.js +51 -0
- package/dist/src/ast/nodes/property-accessor.d.ts +94 -0
- package/dist/src/ast/nodes/property-accessor.js +94 -0
- package/dist/src/ast/nodes/property.d.ts +113 -0
- package/dist/src/ast/nodes/property.js +113 -0
- package/dist/src/ast/nodes/reference.d.ts +90 -0
- package/dist/src/ast/nodes/reference.js +66 -0
- package/dist/src/ast/nodes/string.d.ts +35 -0
- package/dist/src/ast/nodes/string.js +35 -0
- package/dist/src/ast/nodes/tuple.d.ts +33 -0
- package/dist/src/ast/nodes/tuple.js +33 -0
- package/dist/src/ast/nodes/type-alias.d.ts +44 -0
- package/dist/src/ast/nodes/type-alias.js +44 -0
- package/dist/src/ast/nodes/typeof.d.ts +41 -0
- package/dist/src/ast/nodes/typeof.js +41 -0
- package/dist/src/ast/nodes/types.d.ts +12 -0
- package/dist/src/ast/nodes/union-type.d.ts +31 -0
- package/dist/src/ast/nodes/union-type.js +31 -0
- package/dist/src/ast/nodes/variable.d.ts +46 -0
- package/dist/src/ast/nodes/variable.js +46 -0
- package/dist/src/ast/references/angular.d.ts +7 -0
- package/dist/src/ast/references/angular.js +7 -0
- package/dist/src/ast/references/easy-network-stub.d.ts +4 -0
- package/dist/src/ast/references/easy-network-stub.js +4 -0
- package/dist/src/ast/references/k6.d.ts +3 -0
- package/dist/src/ast/references/k6.js +3 -0
- package/dist/src/ast/references/rxjs.d.ts +5 -0
- package/dist/src/ast/references/rxjs.js +5 -0
- package/dist/src/ast/references/typescript.d.ts +30 -0
- package/dist/src/ast/references/typescript.js +30 -0
- package/dist/src/ast/utils/get-type-script-builder-options.d.ts +8 -0
- package/dist/src/ast/utils/get-type-script-builder-options.js +8 -0
- package/dist/src/ast/utils/to-ts-node.d.ts +28 -0
- package/dist/src/ast/utils/write-ts-generic-parameters.d.ts +9 -0
- package/dist/src/ast/utils/write-ts-generic-parameters.js +9 -0
- package/dist/src/ast/utils/write-ts-members.d.ts +12 -0
- package/dist/src/ast/utils/write-ts-members.js +12 -0
- package/dist/src/ast/utils/write-ts-nodes.d.ts +16 -0
- package/dist/src/ast/utils/write-ts-nodes.js +16 -0
- package/dist/src/ast/utils/write-ts-parameters.d.ts +9 -0
- package/dist/src/ast/utils/write-ts-parameters.js +9 -0
- package/dist/src/common-results.d.ts +65 -0
- package/dist/src/config.d.ts +32 -0
- package/dist/src/config.js +5 -0
- package/dist/src/file-builder.d.ts +104 -0
- package/dist/src/file-builder.js +93 -0
- package/dist/src/generators/file-generator.d.ts +14 -0
- package/dist/src/generators/file-generator.js +9 -0
- package/dist/src/generators/models/model-generator.d.ts +24 -0
- package/dist/src/generators/models/model-generator.js +15 -0
- package/dist/src/generators/models/models-generator.d.ts +16 -0
- package/dist/src/generators/models/models-generator.js +16 -0
- package/dist/src/generators/models/models.d.ts +53 -0
- package/dist/src/generators/models/models.js +8 -0
- package/dist/src/generators/services/angular-services/angular-service-generator.d.ts +27 -0
- package/dist/src/generators/services/angular-services/angular-service-generator.js +17 -0
- package/dist/src/generators/services/angular-services/angular-services-generator.d.ts +21 -0
- package/dist/src/generators/services/angular-services/angular-services-generator.js +21 -0
- package/dist/src/generators/services/angular-services/models.d.ts +70 -1
- package/dist/src/generators/services/angular-services/models.js +5 -0
- package/dist/src/generators/services/angular-services/refs.d.ts +11 -0
- package/dist/src/generators/services/angular-services/refs.js +11 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +22 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.js +12 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +16 -0
- package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -0
- package/dist/src/generators/services/easy-network-stub/models.d.ts +61 -0
- package/dist/src/generators/services/easy-network-stub/models.js +5 -0
- package/dist/src/generators/services/easy-network-stub/refs.d.ts +7 -0
- package/dist/src/generators/services/easy-network-stub/refs.js +7 -0
- package/dist/src/generators/services/fetch-clients/fetch-client-generator.d.ts +22 -0
- package/dist/src/generators/services/fetch-clients/fetch-client-generator.js +12 -0
- package/dist/src/generators/services/fetch-clients/fetch-clients-generator.d.ts +17 -0
- package/dist/src/generators/services/fetch-clients/fetch-clients-generator.js +17 -0
- package/dist/src/generators/services/fetch-clients/models.d.ts +64 -1
- package/dist/src/generators/services/fetch-clients/models.js +5 -0
- package/dist/src/generators/services/fetch-clients/refs.d.ts +7 -0
- package/dist/src/generators/services/fetch-clients/refs.js +7 -0
- package/dist/src/generators/services/k6-clients/k6-client-generator.d.ts +21 -0
- package/dist/src/generators/services/k6-clients/k6-client-generator.js +11 -0
- package/dist/src/generators/services/k6-clients/k6-clients-generator.d.ts +18 -0
- package/dist/src/generators/services/k6-clients/k6-clients-generator.js +18 -0
- package/dist/src/generators/services/k6-clients/models.d.ts +65 -1
- package/dist/src/generators/services/k6-clients/models.js +5 -0
- package/dist/src/generators/services/k6-clients/refs.d.ts +8 -0
- package/dist/src/generators/services/k6-clients/refs.js +8 -0
- package/dist/src/import-collection.d.ts +81 -0
- package/dist/src/import-collection.js +58 -0
- package/dist/src/utils.d.ts +62 -0
- package/dist/src/utils.js +47 -0
- package/package.json +2 -2
|
@@ -6,10 +6,32 @@ import type { TypeScriptFetchClientGeneratorContext, TypeScriptFetchClientGenera
|
|
|
6
6
|
type Context = TypeScriptFetchClientGeneratorContext;
|
|
7
7
|
type Output = TypeScriptFetchClientGeneratorOutput;
|
|
8
8
|
type Builder = TypeScriptFileBuilder;
|
|
9
|
+
/**
|
|
10
|
+
* Generates the client class and/or the client interface of one API service.
|
|
11
|
+
* @template TOutput The type of the output returned for the service.
|
|
12
|
+
* @see DefaultTypeScriptFetchClientGenerator
|
|
13
|
+
*/
|
|
9
14
|
export interface TypeScriptFetchClientGenerator<TOutput extends Output = Output> {
|
|
15
|
+
/**
|
|
16
|
+
* Generates the files of the service in the context and returns the exports that were written.
|
|
17
|
+
* @param ctx The context of the service to generate.
|
|
18
|
+
* @returns The output for the service, or a promise that resolves to it.
|
|
19
|
+
*/
|
|
10
20
|
generate(ctx: Context): MaybePromise<TOutput>;
|
|
11
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* The default implementation of `TypeScriptFetchClientGenerator`. It writes the client interface to
|
|
24
|
+
* `{outputDir}/{clientInterfaceDir}/{service}.ts` and the client class to
|
|
25
|
+
* `{outputDir}/{clientDir}/{service}-client.ts`, as selected by `clientFileKind`, where `{service}` is the kebab-cased
|
|
26
|
+
* service name. Extend it to customize the output.
|
|
27
|
+
* @see TypeScriptFetchClientsGenerator
|
|
28
|
+
*/
|
|
12
29
|
export declare class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerator<Context, Output> implements TypeScriptFetchClientGenerator {
|
|
30
|
+
/**
|
|
31
|
+
* Generates the client interface and/or the client class of the service.
|
|
32
|
+
* @param ctx The context of the service to generate.
|
|
33
|
+
* @returns The `clientInterface` and `client` exports that were written, depending on `clientFileKind`.
|
|
34
|
+
*/
|
|
13
35
|
generate(ctx: Context): MaybePromise<Output>;
|
|
14
36
|
protected getInterfaceFileContent(ctx: Context): AppendValueGroup<Builder>;
|
|
15
37
|
protected getInterface(ctx: Context): ts.Interface<Builder>;
|
|
@@ -4,7 +4,19 @@ import { ts } from '../../../ast/index.js';
|
|
|
4
4
|
import { TypeScriptFileBuilder } from '../../../file-builder.js';
|
|
5
5
|
import { getSourceDocLine } from '../../../utils.js';
|
|
6
6
|
import { TypeScriptFileGenerator } from '../../file-generator.js';
|
|
7
|
+
/**
|
|
8
|
+
* The default implementation of `TypeScriptFetchClientGenerator`. It writes the client interface to
|
|
9
|
+
* `{outputDir}/{clientInterfaceDir}/{service}.ts` and the client class to
|
|
10
|
+
* `{outputDir}/{clientDir}/{service}-client.ts`, as selected by `clientFileKind`, where `{service}` is the kebab-cased
|
|
11
|
+
* service name. Extend it to customize the output.
|
|
12
|
+
* @see TypeScriptFetchClientsGenerator
|
|
13
|
+
*/
|
|
7
14
|
export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerator {
|
|
15
|
+
/**
|
|
16
|
+
* Generates the client interface and/or the client class of the service.
|
|
17
|
+
* @param ctx The context of the service to generate.
|
|
18
|
+
* @returns The `clientInterface` and `client` exports that were written, depending on `clientFileKind`.
|
|
19
|
+
*/
|
|
8
20
|
generate(ctx) {
|
|
9
21
|
const result = {};
|
|
10
22
|
if (this.shouldGenerateInterface(ctx)) {
|
|
@@ -7,8 +7,25 @@ type Output = TypeScriptFetchClientsGeneratorOutput;
|
|
|
7
7
|
type Config = TypeScriptFetchClientsGeneratorConfig;
|
|
8
8
|
type ServiceOutput = TypeScriptFetchClientGeneratorOutput;
|
|
9
9
|
type Context = TypeScriptFetchClientsGeneratorContext;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a fetch client class and/or client interface for each API service (tag).
|
|
12
|
+
*
|
|
13
|
+
* Each service produces `{outputDir}/{clientDir}/{service}-client.ts` (the class) and/or
|
|
14
|
+
* `{outputDir}/{clientInterfaceDir}/{service}.ts` (the interface), depending on `clientFileKind`, where `{service}` is
|
|
15
|
+
* the kebab-cased service name. The utilities are copied to `{outputDir}/{utilsDir}`. The index files
|
|
16
|
+
* `{outputDir}/{clientsIndexFile}` and `{outputDir}/{clientInterfacesIndexFile}` are written when they are configured.
|
|
17
|
+
*
|
|
18
|
+
* It publishes `typescript.clients[serviceId]` with the `client` and `clientInterface` exports of each service, and
|
|
19
|
+
* `typescript.indexFiles.clients` and `typescript.indexFiles.clientInterfaces` for subsequent generators.
|
|
20
|
+
* @see TypeScriptFetchClientGenerator
|
|
21
|
+
*/
|
|
10
22
|
export declare class TypeScriptFetchClientsGenerator extends OpenApiServicesGenerationProviderBase<Input, Output, Config, ServiceOutput, Context> {
|
|
11
23
|
private readonly _clientGeneratorFactory;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes a new instance of the TypeScriptFetchClientsGenerator class.
|
|
26
|
+
* @param clientGeneratorFactory The factory that creates the generator for each service. Defaults to a
|
|
27
|
+
* `DefaultTypeScriptFetchClientGenerator`.
|
|
28
|
+
*/
|
|
12
29
|
constructor(clientGeneratorFactory?: Factory<TypeScriptFetchClientGenerator, []>);
|
|
13
30
|
protected initResult(): Output;
|
|
14
31
|
protected buildContext(context: OpenApiGeneratorContext<Input>, config?: Partial<Config> | undefined): Context;
|
|
@@ -7,8 +7,25 @@ import { TypeScriptFileBuilder } from '../../../file-builder.js';
|
|
|
7
7
|
import { DefaultTypeScriptFetchClientGenerator, } from './fetch-client-generator.js';
|
|
8
8
|
import { defaultTypeScriptFetchClientsGeneratorConfig, } from './models.js';
|
|
9
9
|
import { getReferenceFactories } from './refs.js';
|
|
10
|
+
/**
|
|
11
|
+
* Generates a fetch client class and/or client interface for each API service (tag).
|
|
12
|
+
*
|
|
13
|
+
* Each service produces `{outputDir}/{clientDir}/{service}-client.ts` (the class) and/or
|
|
14
|
+
* `{outputDir}/{clientInterfaceDir}/{service}.ts` (the interface), depending on `clientFileKind`, where `{service}` is
|
|
15
|
+
* the kebab-cased service name. The utilities are copied to `{outputDir}/{utilsDir}`. The index files
|
|
16
|
+
* `{outputDir}/{clientsIndexFile}` and `{outputDir}/{clientInterfacesIndexFile}` are written when they are configured.
|
|
17
|
+
*
|
|
18
|
+
* It publishes `typescript.clients[serviceId]` with the `client` and `clientInterface` exports of each service, and
|
|
19
|
+
* `typescript.indexFiles.clients` and `typescript.indexFiles.clientInterfaces` for subsequent generators.
|
|
20
|
+
* @see TypeScriptFetchClientGenerator
|
|
21
|
+
*/
|
|
10
22
|
export class TypeScriptFetchClientsGenerator extends OpenApiServicesGenerationProviderBase {
|
|
11
23
|
_clientGeneratorFactory;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes a new instance of the TypeScriptFetchClientsGenerator class.
|
|
26
|
+
* @param clientGeneratorFactory The factory that creates the generator for each service. Defaults to a
|
|
27
|
+
* `DefaultTypeScriptFetchClientGenerator`.
|
|
28
|
+
*/
|
|
12
29
|
constructor(clientGeneratorFactory) {
|
|
13
30
|
super();
|
|
14
31
|
this._clientGeneratorFactory =
|
|
@@ -3,6 +3,11 @@ import type { TypeScriptExportOutput } from '../../../common-results.ts';
|
|
|
3
3
|
import { type TypeScriptGeneratorConfig } from '../../../config.ts';
|
|
4
4
|
import type { TypeScriptModelsGeneratorOutput } from '../../models/models.ts';
|
|
5
5
|
import type { getReferenceFactories } from './refs.ts';
|
|
6
|
+
/**
|
|
7
|
+
* The configuration of the `TypeScriptFetchClientsGenerator`. It extends the common TypeScript generator configuration
|
|
8
|
+
* with the naming, directory and index file settings of the generated clients and client interfaces.
|
|
9
|
+
* @see TypeScriptFetchClientsGenerator
|
|
10
|
+
*/
|
|
6
11
|
export type TypeScriptFetchClientsGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
7
12
|
/**
|
|
8
13
|
* The casing of the client file names. If nullish, the `fileNameCasing` is used.
|
|
@@ -11,7 +16,7 @@ export type TypeScriptFetchClientsGeneratorConfig = TypeScriptGeneratorConfig &
|
|
|
11
16
|
clientFileNameCasing: Nullable<ExtendedStringCasing>;
|
|
12
17
|
/**
|
|
13
18
|
* The casing of the client interface file names. If nullish, the `fileNameCasing` is used.
|
|
14
|
-
* @default
|
|
19
|
+
* @default undefined
|
|
15
20
|
*/
|
|
16
21
|
clientInterfaceFileNameCasing: Nullable<ExtendedStringCasing>;
|
|
17
22
|
/**
|
|
@@ -58,26 +63,84 @@ export type TypeScriptFetchClientsGeneratorConfig = TypeScriptGeneratorConfig &
|
|
|
58
63
|
*/
|
|
59
64
|
utilsDir: string;
|
|
60
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* The default configuration of the `TypeScriptFetchClientsGenerator`. The provider uses these values for every option
|
|
68
|
+
* that is not set in its configuration.
|
|
69
|
+
* @see TypeScriptFetchClientsGeneratorConfig
|
|
70
|
+
*/
|
|
61
71
|
export declare const defaultTypeScriptFetchClientsGeneratorConfig: DefaultGenerationProviderConfig<TypeScriptFetchClientsGeneratorConfig>;
|
|
72
|
+
/**
|
|
73
|
+
* The input of the `TypeScriptFetchClientsGenerator`. It is the output of the models generator, which the generated
|
|
74
|
+
* clients use to reference the request and response model types.
|
|
75
|
+
* @see TypeScriptModelsGeneratorOutput
|
|
76
|
+
*/
|
|
62
77
|
export type TypeScriptFetchClientsGeneratorInput = TypeScriptModelsGeneratorOutput;
|
|
78
|
+
/**
|
|
79
|
+
* The output of the `TypeScriptFetchClientsGenerator`. It is published under the `typescript` key for subsequent
|
|
80
|
+
* generators.
|
|
81
|
+
* @see TypeScriptFetchClientGeneratorOutput
|
|
82
|
+
*/
|
|
63
83
|
export type TypeScriptFetchClientsGeneratorOutput = {
|
|
84
|
+
/**
|
|
85
|
+
* The TypeScript-specific results of the fetch clients generator.
|
|
86
|
+
*/
|
|
64
87
|
typescript: {
|
|
88
|
+
/**
|
|
89
|
+
* The clients, keyed by the ID of their service (`ApiService['id']`).
|
|
90
|
+
*/
|
|
65
91
|
clients: {
|
|
92
|
+
/**
|
|
93
|
+
* The client and client interface that were generated for one service.
|
|
94
|
+
*/
|
|
66
95
|
[serviceId: string]: TypeScriptFetchClientGeneratorOutput;
|
|
67
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* The paths of the index files. A value is `null` when its index file is disabled by the configuration.
|
|
99
|
+
*/
|
|
68
100
|
indexFiles: {
|
|
101
|
+
/**
|
|
102
|
+
* The path to the index file that exports the client classes.
|
|
103
|
+
*/
|
|
69
104
|
clients: Nullable<string>;
|
|
105
|
+
/**
|
|
106
|
+
* The path to the index file that exports the client interfaces.
|
|
107
|
+
*/
|
|
70
108
|
clientInterfaces: Nullable<string>;
|
|
71
109
|
};
|
|
72
110
|
};
|
|
73
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* The output of the `TypeScriptFetchClientGenerator` for one service. A property is only set when `clientFileKind`
|
|
114
|
+
* generates its kind of file.
|
|
115
|
+
*/
|
|
74
116
|
export type TypeScriptFetchClientGeneratorOutput = {
|
|
117
|
+
/**
|
|
118
|
+
* The exported client class and the file it was written to. Set when `clientFileKind` generates the class.
|
|
119
|
+
*/
|
|
75
120
|
client?: TypeScriptExportOutput;
|
|
121
|
+
/**
|
|
122
|
+
* The exported client interface and the file it was written to. Set when `clientFileKind` generates the interface.
|
|
123
|
+
*/
|
|
76
124
|
clientInterface?: TypeScriptExportOutput;
|
|
77
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* The context passed to the `TypeScriptFetchClientsGenerator` methods. It extends the services generator context with
|
|
128
|
+
* the reference factories of the generated clients.
|
|
129
|
+
* @see TypeScriptFetchClientGeneratorContext
|
|
130
|
+
*/
|
|
78
131
|
export type TypeScriptFetchClientsGeneratorContext = OpenApiServicesGenerationProviderContext<TypeScriptFetchClientsGeneratorInput, TypeScriptFetchClientsGeneratorOutput, TypeScriptFetchClientsGeneratorConfig, TypeScriptFetchClientGeneratorOutput> & {
|
|
132
|
+
/**
|
|
133
|
+
* The factories that create references to the utilities, as returned by `getReferenceFactories`.
|
|
134
|
+
*/
|
|
79
135
|
refs: ReturnType<typeof getReferenceFactories>;
|
|
80
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* The context passed to `TypeScriptFetchClientGenerator.generate` for a single service.
|
|
139
|
+
* @see TypeScriptFetchClientsGeneratorContext
|
|
140
|
+
*/
|
|
81
141
|
export type TypeScriptFetchClientGeneratorContext = TypeScriptFetchClientsGeneratorContext & {
|
|
142
|
+
/**
|
|
143
|
+
* The API service whose client is generated.
|
|
144
|
+
*/
|
|
82
145
|
readonly service: ApiService;
|
|
83
146
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { defaultTypeScriptGeneratorConfig } from '../../../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default configuration of the `TypeScriptFetchClientsGenerator`. The provider uses these values for every option
|
|
4
|
+
* that is not set in its configuration.
|
|
5
|
+
* @see TypeScriptFetchClientsGeneratorConfig
|
|
6
|
+
*/
|
|
2
7
|
export const defaultTypeScriptFetchClientsGeneratorConfig = {
|
|
3
8
|
...defaultTypeScriptGeneratorConfig,
|
|
4
9
|
clientFileNameCasing: { casing: 'kebab', suffix: '-client' },
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ts } from '../../../ast/index.ts';
|
|
2
2
|
import type { TypeScriptFetchClientsGeneratorConfig } from './models.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the references to the utilities that the generated fetch clients import from the `utils` directory.
|
|
5
|
+
* `TypeScriptFetchClientsGenerator` copies these utilities to `{outputDir}/{utilsDir}`.
|
|
6
|
+
* @param options The configuration of the fetch clients generator, which provides `outputDir` and `utilsDir`.
|
|
7
|
+
* @returns The reference factories for `TypedResponse`, `FetchClientOptions` and `UrlBuilder`, all imported from
|
|
8
|
+
* `fetch-client.utils.ts`.
|
|
9
|
+
*/
|
|
3
10
|
export declare function getReferenceFactories(options: TypeScriptFetchClientsGeneratorConfig): {
|
|
4
11
|
typedResponse: ts.GenericModuleReferenceFactory<1>;
|
|
5
12
|
fetchClientOptions: ts.ModuleReferenceFactory;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { ts } from '../../../ast/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the references to the utilities that the generated fetch clients import from the `utils` directory.
|
|
5
|
+
* `TypeScriptFetchClientsGenerator` copies these utilities to `{outputDir}/{utilsDir}`.
|
|
6
|
+
* @param options The configuration of the fetch clients generator, which provides `outputDir` and `utilsDir`.
|
|
7
|
+
* @returns The reference factories for `TypedResponse`, `FetchClientOptions` and `UrlBuilder`, all imported from
|
|
8
|
+
* `fetch-client.utils.ts`.
|
|
9
|
+
*/
|
|
3
10
|
// See packages/typescript/assets/client/fetch for reference
|
|
4
11
|
export function getReferenceFactories(options) {
|
|
5
12
|
const utilsDirPath = resolve(options.outputDir, options.utilsDir);
|
|
@@ -8,10 +8,31 @@ import type { TypeScriptK6ClientGeneratorContext, TypeScriptK6ClientGeneratorOut
|
|
|
8
8
|
type Context = TypeScriptK6ClientGeneratorContext;
|
|
9
9
|
type Output = TypeScriptK6ClientGeneratorOutput;
|
|
10
10
|
type Builder = TypeScriptFileBuilder;
|
|
11
|
+
/**
|
|
12
|
+
* Generates the k6 client class and the response models of one API service.
|
|
13
|
+
* @template TOutput The type of the output returned for the service.
|
|
14
|
+
* @see DefaultTypeScriptK6ClientGenerator
|
|
15
|
+
*/
|
|
11
16
|
export interface TypeScriptK6ClientGenerator<TOutput extends Output = Output> {
|
|
17
|
+
/**
|
|
18
|
+
* Generates the files of the service in the context and returns the exports that were written.
|
|
19
|
+
* @param context The context of the service to generate.
|
|
20
|
+
* @returns The output for the service, or a promise that resolves to it.
|
|
21
|
+
*/
|
|
12
22
|
generate(context: Context): MaybePromise<TOutput>;
|
|
13
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The default implementation of `TypeScriptK6ClientGenerator`. It writes the client to
|
|
26
|
+
* `{outputDir}/{clientDir}/{service}-client.js` (or `.ts`, depending on `language`), and the response models of each
|
|
27
|
+
* endpoint to `{outputDir}/{responseModelsDir}/{service}-responses.ts`. Extend it to customize the output.
|
|
28
|
+
* @see TypeScriptK6ClientsGenerator
|
|
29
|
+
*/
|
|
14
30
|
export declare class DefaultTypeScriptK6ClientGenerator extends TypeScriptFileGenerator<Context, Output> implements TypeScriptK6ClientGenerator {
|
|
31
|
+
/**
|
|
32
|
+
* Generates the response models and the client file of the service and returns their exports.
|
|
33
|
+
* @param ctx The context of the service to generate.
|
|
34
|
+
* @returns The client `component` and `filePath`, and the `responseModels` keyed by endpoint ID.
|
|
35
|
+
*/
|
|
15
36
|
generate(ctx: TypeScriptK6ClientGeneratorContext): MaybePromise<TypeScriptK6ClientGeneratorOutput>;
|
|
16
37
|
protected generateResponseModels(ctx: Context): Record<string, TypeScriptExportOutput>;
|
|
17
38
|
protected getResponseModelFileContent(ctx: Context, endpoint: ApiEndpoint): AppendValueGroup<Builder>;
|
|
@@ -4,7 +4,18 @@ import { ts } from '../../../ast/index.js';
|
|
|
4
4
|
import { TypeScriptFileBuilder } from '../../../file-builder.js';
|
|
5
5
|
import { getSourceDocLine } from '../../../utils.js';
|
|
6
6
|
import { TypeScriptFileGenerator } from '../../file-generator.js';
|
|
7
|
+
/**
|
|
8
|
+
* The default implementation of `TypeScriptK6ClientGenerator`. It writes the client to
|
|
9
|
+
* `{outputDir}/{clientDir}/{service}-client.js` (or `.ts`, depending on `language`), and the response models of each
|
|
10
|
+
* endpoint to `{outputDir}/{responseModelsDir}/{service}-responses.ts`. Extend it to customize the output.
|
|
11
|
+
* @see TypeScriptK6ClientsGenerator
|
|
12
|
+
*/
|
|
7
13
|
export class DefaultTypeScriptK6ClientGenerator extends TypeScriptFileGenerator {
|
|
14
|
+
/**
|
|
15
|
+
* Generates the response models and the client file of the service and returns their exports.
|
|
16
|
+
* @param ctx The context of the service to generate.
|
|
17
|
+
* @returns The client `component` and `filePath`, and the `responseModels` keyed by endpoint ID.
|
|
18
|
+
*/
|
|
8
19
|
generate(ctx) {
|
|
9
20
|
const responseModels = this.generateResponseModels(ctx);
|
|
10
21
|
const filePath = this.getFilePath(ctx);
|
|
@@ -7,8 +7,26 @@ type Output = TypeScriptK6ClientsGeneratorOutput;
|
|
|
7
7
|
type Config = TypeScriptK6ClientsGeneratorConfig;
|
|
8
8
|
type ServiceOutput = TypeScriptK6ClientGeneratorOutput;
|
|
9
9
|
type Context = TypeScriptK6ClientsGeneratorContext;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a k6 client class for each API service (tag), plus index files for the clients and the response models.
|
|
12
|
+
*
|
|
13
|
+
* Each service produces `{outputDir}/{clientDir}/{service}-client.js` (or `.ts`, depending on `language`) and its
|
|
14
|
+
* response models in `{outputDir}/{responseModelsDir}/{service}-responses.ts`, where `{service}` is the kebab-cased
|
|
15
|
+
* service name. The request builder is copied to `{outputDir}/{utilsDir}`, and `http-status-code.ts` is generated there
|
|
16
|
+
* when `strictResponseTypes` is disabled. The index files `{outputDir}/{clientsIndexFile}` and
|
|
17
|
+
* `{outputDir}/{responseModelsIndexFile}` are written when they are configured.
|
|
18
|
+
*
|
|
19
|
+
* It publishes `typescript.k6Clients[serviceId]` with the client `component` and `filePath` and the `responseModels`
|
|
20
|
+
* of each service, and `typescript.indexFiles.k6Clients` and `typescript.indexFiles.k6ResponseModels`.
|
|
21
|
+
* @see TypeScriptK6ClientGenerator
|
|
22
|
+
*/
|
|
10
23
|
export declare class TypeScriptK6ClientsGenerator extends OpenApiServicesGenerationProviderBase<Input, Output, Config, ServiceOutput, Context> {
|
|
11
24
|
private readonly _clientGeneratorFactory;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a new instance of the TypeScriptK6ClientsGenerator class.
|
|
27
|
+
* @param clientGeneratorFactory The factory that creates the generator for each service. Defaults to a
|
|
28
|
+
* `DefaultTypeScriptK6ClientGenerator`.
|
|
29
|
+
*/
|
|
12
30
|
constructor(clientGeneratorFactory?: Factory<TypeScriptK6ClientGenerator, []>);
|
|
13
31
|
protected initResult(): Output;
|
|
14
32
|
protected buildContext(context: OpenApiGeneratorContext<Input>, config?: Partial<Config> | undefined): Context;
|
|
@@ -7,8 +7,26 @@ import { TypeScriptFileBuilder } from '../../../file-builder.js';
|
|
|
7
7
|
import { DefaultTypeScriptK6ClientGenerator } from './k6-client-generator.js';
|
|
8
8
|
import { defaultTypeScriptK6ClientsGeneratorConfig, } from './models.js';
|
|
9
9
|
import { getReferenceFactories } from './refs.js';
|
|
10
|
+
/**
|
|
11
|
+
* Generates a k6 client class for each API service (tag), plus index files for the clients and the response models.
|
|
12
|
+
*
|
|
13
|
+
* Each service produces `{outputDir}/{clientDir}/{service}-client.js` (or `.ts`, depending on `language`) and its
|
|
14
|
+
* response models in `{outputDir}/{responseModelsDir}/{service}-responses.ts`, where `{service}` is the kebab-cased
|
|
15
|
+
* service name. The request builder is copied to `{outputDir}/{utilsDir}`, and `http-status-code.ts` is generated there
|
|
16
|
+
* when `strictResponseTypes` is disabled. The index files `{outputDir}/{clientsIndexFile}` and
|
|
17
|
+
* `{outputDir}/{responseModelsIndexFile}` are written when they are configured.
|
|
18
|
+
*
|
|
19
|
+
* It publishes `typescript.k6Clients[serviceId]` with the client `component` and `filePath` and the `responseModels`
|
|
20
|
+
* of each service, and `typescript.indexFiles.k6Clients` and `typescript.indexFiles.k6ResponseModels`.
|
|
21
|
+
* @see TypeScriptK6ClientGenerator
|
|
22
|
+
*/
|
|
10
23
|
export class TypeScriptK6ClientsGenerator extends OpenApiServicesGenerationProviderBase {
|
|
11
24
|
_clientGeneratorFactory;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a new instance of the TypeScriptK6ClientsGenerator class.
|
|
27
|
+
* @param clientGeneratorFactory The factory that creates the generator for each service. Defaults to a
|
|
28
|
+
* `DefaultTypeScriptK6ClientGenerator`.
|
|
29
|
+
*/
|
|
12
30
|
constructor(clientGeneratorFactory) {
|
|
13
31
|
super();
|
|
14
32
|
this._clientGeneratorFactory =
|
|
@@ -5,6 +5,11 @@ import { type TypeScriptGeneratorConfig } from '../../../config.ts';
|
|
|
5
5
|
import type { TypeScriptFileBuilder } from '../../../file-builder.ts';
|
|
6
6
|
import type { TypeScriptModelsGeneratorOutput } from '../../models/index.ts';
|
|
7
7
|
import type { getReferenceFactories } from './refs.ts';
|
|
8
|
+
/**
|
|
9
|
+
* The configuration of the `TypeScriptK6ClientsGenerator`. It extends the common TypeScript generator configuration
|
|
10
|
+
* with the language, response type, naming, directory and index file settings of the generated k6 clients.
|
|
11
|
+
* @see TypeScriptK6ClientsGenerator
|
|
12
|
+
*/
|
|
8
13
|
export type TypeScriptK6ClientsGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
9
14
|
/**
|
|
10
15
|
* The language of the generated clients.
|
|
@@ -78,7 +83,7 @@ export type TypeScriptK6ClientsGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
|
78
83
|
responseModelsDir: string;
|
|
79
84
|
/**
|
|
80
85
|
* The index file where all clients should be exported. The path is relative to the output directory. If nullish, no index file will be generated.
|
|
81
|
-
* @default 'clients.
|
|
86
|
+
* @default 'clients.js'
|
|
82
87
|
*/
|
|
83
88
|
clientsIndexFile: Nullable<string>;
|
|
84
89
|
/**
|
|
@@ -97,27 +102,86 @@ export type TypeScriptK6ClientsGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
|
97
102
|
*/
|
|
98
103
|
async: boolean;
|
|
99
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* The default configuration of the `TypeScriptK6ClientsGenerator`. The provider uses these values for every option that
|
|
107
|
+
* is not set in its configuration.
|
|
108
|
+
* @see TypeScriptK6ClientsGeneratorConfig
|
|
109
|
+
*/
|
|
100
110
|
export declare const defaultTypeScriptK6ClientsGeneratorConfig: DefaultGenerationProviderConfig<TypeScriptK6ClientsGeneratorConfig>;
|
|
111
|
+
/**
|
|
112
|
+
* The input of the `TypeScriptK6ClientsGenerator`. It is the output of the models generator, which the clients use to
|
|
113
|
+
* reference the request and response model types.
|
|
114
|
+
* @see TypeScriptModelsGeneratorOutput
|
|
115
|
+
*/
|
|
101
116
|
export type TypeScriptK6ClientsGeneratorInput = TypeScriptModelsGeneratorOutput;
|
|
117
|
+
/**
|
|
118
|
+
* The output of the `TypeScriptK6ClientsGenerator`. It is published under the `typescript` key for subsequent
|
|
119
|
+
* generators.
|
|
120
|
+
* @see TypeScriptK6ClientGeneratorOutput
|
|
121
|
+
*/
|
|
102
122
|
export type TypeScriptK6ClientsGeneratorOutput = {
|
|
123
|
+
/**
|
|
124
|
+
* The TypeScript-specific results of the k6 clients generator.
|
|
125
|
+
*/
|
|
103
126
|
typescript: {
|
|
127
|
+
/**
|
|
128
|
+
* The clients, keyed by the ID of their service (`ApiService['id']`).
|
|
129
|
+
*/
|
|
104
130
|
k6Clients: {
|
|
131
|
+
/**
|
|
132
|
+
* The client and response models that were generated for one service.
|
|
133
|
+
*/
|
|
105
134
|
[serviceId: string]: TypeScriptK6ClientGeneratorOutput;
|
|
106
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* The paths of the index files. A value is `null` when its index file is disabled by the configuration.
|
|
138
|
+
*/
|
|
107
139
|
indexFiles: {
|
|
140
|
+
/**
|
|
141
|
+
* The path to the index file that exports the client classes.
|
|
142
|
+
*/
|
|
108
143
|
k6Clients: Nullable<string>;
|
|
144
|
+
/**
|
|
145
|
+
* The path to the index file that exports the response model types.
|
|
146
|
+
*/
|
|
109
147
|
k6ResponseModels: Nullable<string>;
|
|
110
148
|
};
|
|
111
149
|
};
|
|
112
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* The output of the `TypeScriptK6ClientGenerator` for one service: the exported client class and its file, plus the
|
|
153
|
+
* response model types of its endpoints.
|
|
154
|
+
* @see TypeScriptExportOutput
|
|
155
|
+
*/
|
|
113
156
|
export type TypeScriptK6ClientGeneratorOutput = TypeScriptExportOutput & {
|
|
157
|
+
/**
|
|
158
|
+
* The response model types of the service, keyed by the ID of their endpoint (`ApiEndpoint['id']`).
|
|
159
|
+
*/
|
|
114
160
|
responseModels: {
|
|
161
|
+
/**
|
|
162
|
+
* The exported response model type and the file it was written to.
|
|
163
|
+
*/
|
|
115
164
|
[operationId: string]: TypeScriptExportOutput;
|
|
116
165
|
};
|
|
117
166
|
};
|
|
167
|
+
/**
|
|
168
|
+
* The context passed to the `TypeScriptK6ClientsGenerator` methods. It extends the services generator context with the
|
|
169
|
+
* reference factories of the generated clients.
|
|
170
|
+
* @see TypeScriptK6ClientGeneratorContext
|
|
171
|
+
*/
|
|
118
172
|
export type TypeScriptK6ClientsGeneratorContext = OpenApiServicesGenerationProviderContext<TypeScriptK6ClientsGeneratorInput, TypeScriptK6ClientsGeneratorOutput, TypeScriptK6ClientsGeneratorConfig, TypeScriptK6ClientGeneratorOutput> & {
|
|
173
|
+
/**
|
|
174
|
+
* The factories that create references to the utilities, as returned by `getReferenceFactories`.
|
|
175
|
+
*/
|
|
119
176
|
refs: ReturnType<typeof getReferenceFactories>;
|
|
120
177
|
};
|
|
178
|
+
/**
|
|
179
|
+
* The context passed to `TypeScriptK6ClientGenerator.generate` for a single service.
|
|
180
|
+
* @see TypeScriptK6ClientsGeneratorContext
|
|
181
|
+
*/
|
|
121
182
|
export type TypeScriptK6ClientGeneratorContext = TypeScriptK6ClientsGeneratorContext & {
|
|
183
|
+
/**
|
|
184
|
+
* The API service whose client is generated.
|
|
185
|
+
*/
|
|
122
186
|
readonly service: ApiService;
|
|
123
187
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { defaultTypeScriptGeneratorConfig } from '../../../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default configuration of the `TypeScriptK6ClientsGenerator`. The provider uses these values for every option that
|
|
4
|
+
* is not set in its configuration.
|
|
5
|
+
* @see TypeScriptK6ClientsGeneratorConfig
|
|
6
|
+
*/
|
|
2
7
|
export const defaultTypeScriptK6ClientsGeneratorConfig = {
|
|
3
8
|
...defaultTypeScriptGeneratorConfig,
|
|
4
9
|
language: 'javascript',
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ts } from '../../../ast/index.ts';
|
|
2
2
|
import type { TypeScriptK6ClientsGeneratorConfig } from './models.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the references to the utilities that the generated k6 clients import from the `utils` directory.
|
|
5
|
+
* `TypeScriptK6ClientsGenerator` copies the request builder there, and generates `http-status-code.ts` when
|
|
6
|
+
* `strictResponseTypes` is disabled.
|
|
7
|
+
* @param options The configuration of the k6 clients generator, which provides `outputDir`, `utilsDir` and `language`.
|
|
8
|
+
* @returns The reference factories for `RequestBuilder` (`request-builder.js` or `.ts`, depending on `language`) and
|
|
9
|
+
* for `HttpStatusCode` (`http-status-code.ts`).
|
|
10
|
+
*/
|
|
3
11
|
export declare function getReferenceFactories(options: TypeScriptK6ClientsGeneratorConfig): {
|
|
4
12
|
requestBuilder: ts.ModuleReferenceFactory;
|
|
5
13
|
httpStatusCode: ts.ModuleReferenceFactory;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { join, resolve } from 'node:path';
|
|
2
2
|
import { ts } from '../../../ast/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the references to the utilities that the generated k6 clients import from the `utils` directory.
|
|
5
|
+
* `TypeScriptK6ClientsGenerator` copies the request builder there, and generates `http-status-code.ts` when
|
|
6
|
+
* `strictResponseTypes` is disabled.
|
|
7
|
+
* @param options The configuration of the k6 clients generator, which provides `outputDir`, `utilsDir` and `language`.
|
|
8
|
+
* @returns The reference factories for `RequestBuilder` (`request-builder.js` or `.ts`, depending on `language`) and
|
|
9
|
+
* for `HttpStatusCode` (`http-status-code.ts`).
|
|
10
|
+
*/
|
|
3
11
|
export function getReferenceFactories(options) {
|
|
4
12
|
const utilsDirPath = resolve(options.outputDir, options.utilsDir);
|
|
5
13
|
const ext = options.language === 'javascript' ? '.js' : '.ts';
|
|
@@ -1,18 +1,60 @@
|
|
|
1
1
|
import { type SourceBuilderOptions, StringBuilder } from '@goast/core';
|
|
2
2
|
import type { TypeScriptExportType, TypeScriptImport, TypeScriptImportKind, TypeScriptImportType } from './common-results.ts';
|
|
3
3
|
import { type ImportModuleTransformer } from './utils.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The options of an `ImportExportCollection`.
|
|
6
|
+
*/
|
|
4
7
|
export type ImportExportCollectionOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* The path of the file that the statements are written to. Paths of project files are made relative to it. If it is
|
|
10
|
+
* omitted, file paths are written as they are.
|
|
11
|
+
*/
|
|
5
12
|
filePath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The transformer that writes the relative module paths of project files.
|
|
15
|
+
* @default 'omit-extension'
|
|
16
|
+
*/
|
|
6
17
|
importModuleTransformer: ImportModuleTransformer;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the module paths are quoted with single quotes instead of double quotes.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
7
22
|
useSingleQuotes: boolean;
|
|
8
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* The default options of an `ImportExportCollection`. The transformer and the quote style are taken from
|
|
26
|
+
* `defaultTypeScriptGeneratorConfig`.
|
|
27
|
+
*/
|
|
9
28
|
export declare const defaultImportExportCollectionOptions: ImportExportCollectionOptions;
|
|
29
|
+
/**
|
|
30
|
+
* The options of an import that is added with `addImport`. Its `type` property sets the form of the import statement,
|
|
31
|
+
* see `TypeScriptImportType`, and defaults to `'import'`.
|
|
32
|
+
*/
|
|
10
33
|
export type TypeScriptImportOptions = {
|
|
11
34
|
type?: TypeScriptImportType;
|
|
12
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The options of an export that is added with `addExport`. Its `type` property sets the form of the export statement,
|
|
38
|
+
* see `TypeScriptExportType`, and defaults to `'export'`.
|
|
39
|
+
*/
|
|
13
40
|
export type TypeScriptExportOptions = {
|
|
14
41
|
type?: TypeScriptExportType;
|
|
15
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Collects the imports and re-exports of a file, and writes them as import and export statements.
|
|
45
|
+
*
|
|
46
|
+
* Names are stored per module path, in one map for each form: `import`, `import type` and `@import` names, and the same
|
|
47
|
+
* for re-exports. Adding a name that is already present has no effect, so each name is written once per module.
|
|
48
|
+
*
|
|
49
|
+
* When the statements are written, a project file (a path ending in `.ts`, `.js` or `.json`) is turned into a relative
|
|
50
|
+
* path from the file that the statements are written to, and transformed with `importModuleTransformer`. A package
|
|
51
|
+
* name, such as `rxjs`, is written as it is. The statements are written in this order: value imports, type imports, the
|
|
52
|
+
* `@import` block, value re-exports and type re-exports. Module imports come before file imports, separated by a blank
|
|
53
|
+
* line.
|
|
54
|
+
*
|
|
55
|
+
* `TypeScriptFileBuilder` owns one of these collections. It adds the imports of every `TsReference` node that has a
|
|
56
|
+
* module or file path, and it passes its own `filePath` and options to the collection.
|
|
57
|
+
*/
|
|
16
58
|
export declare class ImportExportCollection {
|
|
17
59
|
private readonly _imports;
|
|
18
60
|
private readonly _typeImports;
|
|
@@ -20,15 +62,54 @@ export declare class ImportExportCollection {
|
|
|
20
62
|
private readonly _exports;
|
|
21
63
|
private readonly _typeExports;
|
|
22
64
|
private readonly _options;
|
|
65
|
+
/**
|
|
66
|
+
* Initializes a new instance of the ImportExportCollection class.
|
|
67
|
+
* @param options The options of the collection. Options that are not given use the defaults.
|
|
68
|
+
*/
|
|
23
69
|
constructor(options?: Partial<ImportExportCollectionOptions>);
|
|
70
|
+
/**
|
|
71
|
+
* Gets a value indicating whether at least one import of any form has been added.
|
|
72
|
+
*/
|
|
24
73
|
get hasImports(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Gets a value indicating whether at least one re-export of any form has been added.
|
|
76
|
+
*/
|
|
25
77
|
get hasExports(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Gets all collected imports as a flat list. The module paths are the unresolved ones, as they were passed to
|
|
80
|
+
* `addImport`, so they are not yet relative to the file.
|
|
81
|
+
*/
|
|
26
82
|
get imports(): TypeScriptImport[];
|
|
27
83
|
private toImport;
|
|
84
|
+
/**
|
|
85
|
+
* Adds a named import from a module or a file. Adding the same name from the same module again has no effect.
|
|
86
|
+
* @param importName The name to import.
|
|
87
|
+
* @param fromModule The module name, such as `rxjs`, or the path of the file that exports the name.
|
|
88
|
+
* @param options The options of the import, such as the import type. Defaults to a value import.
|
|
89
|
+
*/
|
|
28
90
|
addImport(importName: string, fromModule: string, options?: TypeScriptImportOptions): void;
|
|
91
|
+
/**
|
|
92
|
+
* Adds a named re-export from a module or a file. Adding the same name from the same module again has no effect.
|
|
93
|
+
* @param exportName The name to re-export.
|
|
94
|
+
* @param fromModule The module name, or the path of the file that exports the name.
|
|
95
|
+
* @param options The options of the export, such as the export type. Defaults to a value export.
|
|
96
|
+
*/
|
|
29
97
|
addExport(exportName: string, fromModule: string, options?: TypeScriptExportOptions): void;
|
|
98
|
+
/**
|
|
99
|
+
* Removes all collected imports and re-exports.
|
|
100
|
+
*/
|
|
30
101
|
clear(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Renders the import and export statements as a string.
|
|
104
|
+
* @param options The options of the builder that the statements are written with.
|
|
105
|
+
* @returns The import and export statements.
|
|
106
|
+
*/
|
|
31
107
|
toString(options: Partial<SourceBuilderOptions>): string;
|
|
108
|
+
/**
|
|
109
|
+
* Writes the import and export statements to a builder. The statements are written in the order described for the
|
|
110
|
+
* class, and the groups are separated by a blank line.
|
|
111
|
+
* @param builder The builder to write the statements to.
|
|
112
|
+
*/
|
|
32
113
|
writeTo(builder: StringBuilder): void;
|
|
33
114
|
protected writeImportsExports(builder: StringBuilder, keyword: 'import' | 'export' | 'import type' | 'export type' | ' * @import', data: (readonly [string, TypeScriptImportKind, string[]])[], options: {
|
|
34
115
|
useSingleQuotes: boolean;
|