@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
|
@@ -3,6 +3,10 @@ import { ts } from '../../ast/index.ts';
|
|
|
3
3
|
import type { TypeScriptComponentOutput } from '../../common-results.ts';
|
|
4
4
|
import { type TypeScriptGeneratorConfig } from '../../config.ts';
|
|
5
5
|
import type { TypeScriptFileBuilder } from '../../file-builder.ts';
|
|
6
|
+
/**
|
|
7
|
+
* The options of a single model. They control how the `TypeScriptModelGenerator` writes the model of each schema.
|
|
8
|
+
* They extend the common TypeScript generator options.
|
|
9
|
+
*/
|
|
6
10
|
export type TypeScriptModelGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
7
11
|
/**
|
|
8
12
|
* Determines how to generate enums.
|
|
@@ -49,6 +53,10 @@ export type TypeScriptModelGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
|
49
53
|
*/
|
|
50
54
|
binarySchemaType: () => ts.Type<TypeScriptFileBuilder>;
|
|
51
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* The options of the `TypeScriptModelsGenerator`. They extend the model options with the location of the index file
|
|
58
|
+
* that re-exports all generated models.
|
|
59
|
+
*/
|
|
52
60
|
export type TypeScriptModelsGeneratorConfig = TypeScriptModelGeneratorConfig & {
|
|
53
61
|
/**
|
|
54
62
|
* The path to the index file where all models should be exported. If nullish, no index file will be generated.
|
|
@@ -56,21 +64,66 @@ export type TypeScriptModelsGeneratorConfig = TypeScriptModelGeneratorConfig & {
|
|
|
56
64
|
*/
|
|
57
65
|
modelsIndexFile: Nullable<string>;
|
|
58
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* The default values of the `TypeScriptModelGeneratorConfig` options. Options that are not set take these values.
|
|
69
|
+
* @see TypeScriptModelGeneratorConfig
|
|
70
|
+
*/
|
|
59
71
|
export declare const defaultTypeScriptModelGeneratorConfig: DefaultGenerationProviderConfig<TypeScriptModelGeneratorConfig>;
|
|
72
|
+
/**
|
|
73
|
+
* The default values of the `TypeScriptModelsGeneratorConfig` options. Options that are not set take these values.
|
|
74
|
+
* @see TypeScriptModelsGeneratorConfig
|
|
75
|
+
*/
|
|
60
76
|
export declare const defaultTypeScriptModelsGeneratorConfig: DefaultGenerationProviderConfig<TypeScriptModelsGeneratorConfig>;
|
|
77
|
+
/**
|
|
78
|
+
* The input of the `TypeScriptModelsGenerator`. It is empty because the generator only reads the schemas of the
|
|
79
|
+
* OpenAPI documents from the context.
|
|
80
|
+
*/
|
|
61
81
|
export type TypeScriptModelsGeneratorInput = {};
|
|
82
|
+
/**
|
|
83
|
+
* The output of the `TypeScriptModelsGenerator`. Later generators read the generated models and index file from it.
|
|
84
|
+
*/
|
|
62
85
|
export type TypeScriptModelsGeneratorOutput = {
|
|
86
|
+
/**
|
|
87
|
+
* The TypeScript results of the models generator.
|
|
88
|
+
*/
|
|
63
89
|
typescript: {
|
|
90
|
+
/**
|
|
91
|
+
* The generated models, keyed by the ID of their schema (`ApiSchema['id']`).
|
|
92
|
+
*/
|
|
64
93
|
models: {
|
|
94
|
+
/**
|
|
95
|
+
* The result for the schema with the given ID.
|
|
96
|
+
*/
|
|
65
97
|
[schemaId: string]: TypeScriptModelGeneratorOutput;
|
|
66
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* The index files that were generated.
|
|
101
|
+
*/
|
|
67
102
|
indexFiles: {
|
|
103
|
+
/**
|
|
104
|
+
* The path to the models index file, or `null` if no index file was generated (`modelsIndexFile` is nullish).
|
|
105
|
+
*/
|
|
68
106
|
models: Nullable<string>;
|
|
69
107
|
};
|
|
70
108
|
};
|
|
71
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* The result of generating a single model. For a schema that is written to its own file, `component` is the declared
|
|
112
|
+
* type name and `filePath` is set. For an inline schema, `component` is the type expression and no file is written.
|
|
113
|
+
*/
|
|
72
114
|
export type TypeScriptModelGeneratorOutput = TypeScriptComponentOutput;
|
|
115
|
+
/**
|
|
116
|
+
* The context of the `TypeScriptModelsGenerator`. It is passed to the models generator for all schemas.
|
|
117
|
+
* @see TypeScriptModelGeneratorContext
|
|
118
|
+
*/
|
|
73
119
|
export type TypeScriptModelsGeneratorContext = OpenApiSchemasGenerationProviderContext<TypeScriptModelsGeneratorInput, TypeScriptModelsGeneratorOutput, TypeScriptModelsGeneratorConfig, TypeScriptModelGeneratorOutput>;
|
|
120
|
+
/**
|
|
121
|
+
* The context of the `TypeScriptModelGenerator` for a single schema.
|
|
122
|
+
* @see TypeScriptModelsGeneratorContext
|
|
123
|
+
*/
|
|
74
124
|
export type TypeScriptModelGeneratorContext = TypeScriptModelsGeneratorContext & {
|
|
125
|
+
/**
|
|
126
|
+
* The schema to generate the model for.
|
|
127
|
+
*/
|
|
75
128
|
schema: ApiSchema;
|
|
76
129
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ts } from '../../ast/index.js';
|
|
2
2
|
import { defaultTypeScriptGeneratorConfig } from '../../config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default values of the `TypeScriptModelGeneratorConfig` options. Options that are not set take these values.
|
|
5
|
+
* @see TypeScriptModelGeneratorConfig
|
|
6
|
+
*/
|
|
3
7
|
export const defaultTypeScriptModelGeneratorConfig = {
|
|
4
8
|
...defaultTypeScriptGeneratorConfig,
|
|
5
9
|
enumGeneration: 'union',
|
|
@@ -11,6 +15,10 @@ export const defaultTypeScriptModelGeneratorConfig = {
|
|
|
11
15
|
discriminatorBaseTypeCasing: { casing: 'pascal', prefix: '_', suffix: 'Base' },
|
|
12
16
|
binarySchemaType: ts.refs.blob,
|
|
13
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* The default values of the `TypeScriptModelsGeneratorConfig` options. Options that are not set take these values.
|
|
20
|
+
* @see TypeScriptModelsGeneratorConfig
|
|
21
|
+
*/
|
|
14
22
|
export const defaultTypeScriptModelsGeneratorConfig = {
|
|
15
23
|
...defaultTypeScriptModelGeneratorConfig,
|
|
16
24
|
modelsIndexFile: 'models.ts',
|
|
@@ -7,10 +7,37 @@ import type { TypeScriptAngularServiceGeneratorContext, TypeScriptAngularService
|
|
|
7
7
|
type Context = TypeScriptAngularServiceGeneratorContext;
|
|
8
8
|
type Output = TypeScriptAngularServiceGeneratorOutput;
|
|
9
9
|
type Builder = TypeScriptFileBuilder;
|
|
10
|
+
/**
|
|
11
|
+
* Generates the Angular service class and the response models of a single OpenAPI service. Implement it to replace the
|
|
12
|
+
* default service generation.
|
|
13
|
+
* @template TOutput The type of the result that is returned for the service.
|
|
14
|
+
*/
|
|
10
15
|
export interface TypeScriptAngularServiceGenerator<TOutput extends Output = Output> {
|
|
16
|
+
/**
|
|
17
|
+
* Generates the response models and the service class of the service in the context.
|
|
18
|
+
* @param ctx The context of the service to generate, including its configuration and the generated models.
|
|
19
|
+
* @returns The result of the service, or a promise that resolves to it.
|
|
20
|
+
*/
|
|
11
21
|
generate(ctx: Context): MaybePromise<TOutput>;
|
|
12
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The default Angular service generator. It writes the response models of an OpenAPI service and the Angular service
|
|
25
|
+
* class with one method per endpoint.
|
|
26
|
+
*
|
|
27
|
+
* The response models are written to `{outputDir}/{responseModelsDir}`, one file per service. Each endpoint gets a
|
|
28
|
+
* `{Method}ApiResponse` type that lists its possible responses. The service class is written to
|
|
29
|
+
* `{outputDir}/{servicesDir}`, one file per service, together with a `{Method}_Params` type for each endpoint that has
|
|
30
|
+
* parameters or a request body.
|
|
31
|
+
*
|
|
32
|
+
* The result contains the file path and class name of the service, and the response models keyed by endpoint ID. The
|
|
33
|
+
* services generator publishes it as `typescript.services[serviceId]`.
|
|
34
|
+
*/
|
|
13
35
|
export declare class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGenerator<Context, Output> implements TypeScriptAngularServiceGenerator {
|
|
36
|
+
/**
|
|
37
|
+
* Generates the response models and the service class of the service in the context.
|
|
38
|
+
* @param ctx The context of the service to generate, including its configuration and the generated models.
|
|
39
|
+
* @returns The result of the service, including its file path, class name and response models.
|
|
40
|
+
*/
|
|
14
41
|
generate(ctx: Context): MaybePromise<Output>;
|
|
15
42
|
protected generateResponseModels(ctx: Context): Record<string, TypeScriptExportOutput>;
|
|
16
43
|
protected getResponseModelFileContent(ctx: Context, endpoint: ApiEndpoint): AppendValueGroup<Builder>;
|
|
@@ -4,7 +4,24 @@ 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 Angular service generator. It writes the response models of an OpenAPI service and the Angular service
|
|
9
|
+
* class with one method per endpoint.
|
|
10
|
+
*
|
|
11
|
+
* The response models are written to `{outputDir}/{responseModelsDir}`, one file per service. Each endpoint gets a
|
|
12
|
+
* `{Method}ApiResponse` type that lists its possible responses. The service class is written to
|
|
13
|
+
* `{outputDir}/{servicesDir}`, one file per service, together with a `{Method}_Params` type for each endpoint that has
|
|
14
|
+
* parameters or a request body.
|
|
15
|
+
*
|
|
16
|
+
* The result contains the file path and class name of the service, and the response models keyed by endpoint ID. The
|
|
17
|
+
* services generator publishes it as `typescript.services[serviceId]`.
|
|
18
|
+
*/
|
|
7
19
|
export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGenerator {
|
|
20
|
+
/**
|
|
21
|
+
* Generates the response models and the service class of the service in the context.
|
|
22
|
+
* @param ctx The context of the service to generate, including its configuration and the generated models.
|
|
23
|
+
* @returns The result of the service, including its file path, class name and response models.
|
|
24
|
+
*/
|
|
8
25
|
generate(ctx) {
|
|
9
26
|
const responseModels = this.generateResponseModels(ctx);
|
|
10
27
|
const filePath = this.getServiceFilePath(ctx);
|
|
@@ -7,8 +7,29 @@ type Output = TypeScriptAngularServicesGeneratorOutput;
|
|
|
7
7
|
type Config = TypeScriptAngularServicesGeneratorConfig;
|
|
8
8
|
type ServiceOutput = TypeScriptAngularServiceGeneratorOutput;
|
|
9
9
|
type Context = TypeScriptAngularServicesGeneratorContext;
|
|
10
|
+
/**
|
|
11
|
+
* Generates the Angular services for all OpenAPI services, together with the shared utility and index files.
|
|
12
|
+
*
|
|
13
|
+
* The utility files are written to `{outputDir}/{utilsDir}`: `request-builder.ts` and `angular-service.utils.ts`,
|
|
14
|
+
* which are copied from the assets, `api-configuration.ts`, `api-base-service.ts`, `http-status-code.ts` (only if
|
|
15
|
+
* `strictResponseTypes` is `false`) and `provide.ts` (only if `provideKind` is `'provide-fn'`). Each service is
|
|
16
|
+
* generated by a `TypeScriptAngularServiceGenerator` into `{outputDir}/{servicesDir}`, and its response models into
|
|
17
|
+
* `{outputDir}/{responseModelsDir}`. The index files are written to `{outputDir}/{servicesIndexFile}` and
|
|
18
|
+
* `{outputDir}/{responseModelsIndexFile}`.
|
|
19
|
+
*
|
|
20
|
+
* It publishes the following data for later generators:
|
|
21
|
+
* - `typescript.services`: The result of each service, keyed by the service ID (`ApiService['id']`).
|
|
22
|
+
* - `typescript.indexFiles.services`: The path of the services index file, or `null` if none was generated.
|
|
23
|
+
* - `typescript.indexFiles.responseModels`: The path of the response models index file, or `null` if none
|
|
24
|
+
* was generated.
|
|
25
|
+
*/
|
|
10
26
|
export declare class TypeScriptAngularServicesGenerator extends OpenApiServicesGenerationProviderBase<Input, Output, Config, ServiceOutput, Context> {
|
|
11
27
|
private readonly _clientGeneratorFactory;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes a new instance of the TypeScriptAngularServicesGenerator class.
|
|
30
|
+
* @param clientGeneratorFactory The factory that creates the service generator used for each service. If omitted, a
|
|
31
|
+
* `DefaultTypeScriptAngularServiceGenerator` is used.
|
|
32
|
+
*/
|
|
12
33
|
constructor(clientGeneratorFactory?: Factory<TypeScriptAngularServiceGenerator, []>);
|
|
13
34
|
protected initResult(): Output;
|
|
14
35
|
protected buildContext(context: OpenApiGeneratorContext<Input>, config?: Partial<Config> | undefined): Context;
|
|
@@ -8,8 +8,29 @@ import { modifyString } from '../../../utils.js';
|
|
|
8
8
|
import { DefaultTypeScriptAngularServiceGenerator, } from './angular-service-generator.js';
|
|
9
9
|
import { defaultTypeScriptAngularServicesGeneratorConfig, } from './models.js';
|
|
10
10
|
import { getReferenceFactories } from './refs.js';
|
|
11
|
+
/**
|
|
12
|
+
* Generates the Angular services for all OpenAPI services, together with the shared utility and index files.
|
|
13
|
+
*
|
|
14
|
+
* The utility files are written to `{outputDir}/{utilsDir}`: `request-builder.ts` and `angular-service.utils.ts`,
|
|
15
|
+
* which are copied from the assets, `api-configuration.ts`, `api-base-service.ts`, `http-status-code.ts` (only if
|
|
16
|
+
* `strictResponseTypes` is `false`) and `provide.ts` (only if `provideKind` is `'provide-fn'`). Each service is
|
|
17
|
+
* generated by a `TypeScriptAngularServiceGenerator` into `{outputDir}/{servicesDir}`, and its response models into
|
|
18
|
+
* `{outputDir}/{responseModelsDir}`. The index files are written to `{outputDir}/{servicesIndexFile}` and
|
|
19
|
+
* `{outputDir}/{responseModelsIndexFile}`.
|
|
20
|
+
*
|
|
21
|
+
* It publishes the following data for later generators:
|
|
22
|
+
* - `typescript.services`: The result of each service, keyed by the service ID (`ApiService['id']`).
|
|
23
|
+
* - `typescript.indexFiles.services`: The path of the services index file, or `null` if none was generated.
|
|
24
|
+
* - `typescript.indexFiles.responseModels`: The path of the response models index file, or `null` if none
|
|
25
|
+
* was generated.
|
|
26
|
+
*/
|
|
11
27
|
export class TypeScriptAngularServicesGenerator extends OpenApiServicesGenerationProviderBase {
|
|
12
28
|
_clientGeneratorFactory;
|
|
29
|
+
/**
|
|
30
|
+
* Initializes a new instance of the TypeScriptAngularServicesGenerator class.
|
|
31
|
+
* @param clientGeneratorFactory The factory that creates the service generator used for each service. If omitted, a
|
|
32
|
+
* `DefaultTypeScriptAngularServiceGenerator` is used.
|
|
33
|
+
*/
|
|
13
34
|
constructor(clientGeneratorFactory) {
|
|
14
35
|
super();
|
|
15
36
|
this._clientGeneratorFactory =
|
|
@@ -5,12 +5,16 @@ import { type TypeScriptGeneratorConfig } from '../../../config.ts';
|
|
|
5
5
|
import type { TypeScriptFileBuilder } from '../../../file-builder.ts';
|
|
6
6
|
import type { TypeScriptModelGeneratorOutput } from '../../models/index.ts';
|
|
7
7
|
import type { getReferenceFactories } from './refs.ts';
|
|
8
|
+
/**
|
|
9
|
+
* The options of the `TypeScriptAngularServicesGenerator`. They extend the common TypeScript generator options with
|
|
10
|
+
* the settings for the services, their response models and the utility files.
|
|
11
|
+
*/
|
|
8
12
|
export type TypeScriptAngularServicesGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
9
13
|
/**
|
|
10
14
|
* How the services should be provided in the Angular application.
|
|
11
15
|
* - `root` - provides all the services using `Injectable({ providedIn: 'root' })`
|
|
12
16
|
* - `provide-fn` - generates a function `provideApiClients` that provides the services
|
|
13
|
-
* @default '
|
|
17
|
+
* @default 'provide-fn'
|
|
14
18
|
*/
|
|
15
19
|
provideKind: 'root' | 'provide-fn';
|
|
16
20
|
/**
|
|
@@ -114,33 +118,98 @@ export type TypeScriptAngularServicesGeneratorConfig = TypeScriptGeneratorConfig
|
|
|
114
118
|
*/
|
|
115
119
|
utilsDir: string;
|
|
116
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* The default values of the `TypeScriptAngularServicesGeneratorConfig` options. Options that are not set take these
|
|
123
|
+
* values.
|
|
124
|
+
* @see TypeScriptAngularServicesGeneratorConfig
|
|
125
|
+
*/
|
|
117
126
|
export declare const defaultTypeScriptAngularServicesGeneratorConfig: DefaultGenerationProviderConfig<TypeScriptAngularServicesGeneratorConfig>;
|
|
127
|
+
/**
|
|
128
|
+
* The input of the `TypeScriptAngularServicesGenerator`. It contains the models generated before, which the services
|
|
129
|
+
* use for their parameter and response types.
|
|
130
|
+
*/
|
|
118
131
|
export type TypeScriptAngularServicesGeneratorInput = {
|
|
132
|
+
/**
|
|
133
|
+
* The TypeScript results of the models generator.
|
|
134
|
+
*/
|
|
119
135
|
typescript: {
|
|
136
|
+
/**
|
|
137
|
+
* The generated models, keyed by the ID of their schema (`ApiSchema['id']`).
|
|
138
|
+
*/
|
|
120
139
|
models: {
|
|
140
|
+
/**
|
|
141
|
+
* The result of the model for the schema with the given ID.
|
|
142
|
+
*/
|
|
121
143
|
[schemaId: string]: TypeScriptModelGeneratorOutput;
|
|
122
144
|
};
|
|
123
145
|
};
|
|
124
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* The output of the `TypeScriptAngularServicesGenerator`. Later generators read the generated services and index files
|
|
149
|
+
* from it.
|
|
150
|
+
*/
|
|
125
151
|
export type TypeScriptAngularServicesGeneratorOutput = {
|
|
152
|
+
/**
|
|
153
|
+
* The TypeScript results of the services generator.
|
|
154
|
+
*/
|
|
126
155
|
typescript: {
|
|
156
|
+
/**
|
|
157
|
+
* The generated services, keyed by the ID of their service (`ApiService['id']`).
|
|
158
|
+
*/
|
|
127
159
|
services: {
|
|
160
|
+
/**
|
|
161
|
+
* The result of the service with the given ID.
|
|
162
|
+
*/
|
|
128
163
|
[serviceId: string]: TypeScriptAngularServiceGeneratorOutput;
|
|
129
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* The index files that were generated.
|
|
167
|
+
*/
|
|
130
168
|
indexFiles: {
|
|
169
|
+
/**
|
|
170
|
+
* The path to the services index file, or `null` if `servicesIndexFile` is nullish.
|
|
171
|
+
*/
|
|
131
172
|
services: Nullable<string>;
|
|
173
|
+
/**
|
|
174
|
+
* The path to the response models index file, or `null` if `responseModelsIndexFile` is nullish.
|
|
175
|
+
*/
|
|
132
176
|
responseModels: Nullable<string>;
|
|
133
177
|
};
|
|
134
178
|
};
|
|
135
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* The result of generating a single Angular service. `component` is the name of the service class, and `filePath` is
|
|
182
|
+
* the file it is written to.
|
|
183
|
+
*/
|
|
136
184
|
export type TypeScriptAngularServiceGeneratorOutput = TypeScriptExportOutput & {
|
|
185
|
+
/**
|
|
186
|
+
* The response models of the service, keyed by the ID of their endpoint (`ApiEndpoint['id']`).
|
|
187
|
+
*/
|
|
137
188
|
responseModels: {
|
|
189
|
+
/**
|
|
190
|
+
* The export of the response model for the endpoint with the given ID.
|
|
191
|
+
*/
|
|
138
192
|
[operationId: string]: TypeScriptExportOutput;
|
|
139
193
|
};
|
|
140
194
|
};
|
|
195
|
+
/**
|
|
196
|
+
* The context of the `TypeScriptAngularServicesGenerator`. It is passed to the services generator, and each service
|
|
197
|
+
* generator receives it together with its `service`.
|
|
198
|
+
*/
|
|
141
199
|
export type TypeScriptAngularServicesGeneratorContext = OpenApiServicesGenerationProviderContext<TypeScriptAngularServicesGeneratorInput, TypeScriptAngularServicesGeneratorOutput, TypeScriptAngularServicesGeneratorConfig, TypeScriptAngularServiceGeneratorOutput> & {
|
|
200
|
+
/**
|
|
201
|
+
* The factories for the references to the utility files and the generated API infrastructure.
|
|
202
|
+
* See `getReferenceFactories`.
|
|
203
|
+
*/
|
|
142
204
|
refs: ReturnType<typeof getReferenceFactories>;
|
|
143
205
|
};
|
|
206
|
+
/**
|
|
207
|
+
* The context of the `TypeScriptAngularServiceGenerator` for a single service.
|
|
208
|
+
* @see TypeScriptAngularServicesGeneratorContext
|
|
209
|
+
*/
|
|
144
210
|
export type TypeScriptAngularServiceGeneratorContext = TypeScriptAngularServicesGeneratorContext & {
|
|
211
|
+
/**
|
|
212
|
+
* The service to generate the Angular service class for.
|
|
213
|
+
*/
|
|
145
214
|
readonly service: ApiService;
|
|
146
215
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { defaultTypeScriptGeneratorConfig } from '../../../config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The default values of the `TypeScriptAngularServicesGeneratorConfig` options. Options that are not set take these
|
|
4
|
+
* values.
|
|
5
|
+
* @see TypeScriptAngularServicesGeneratorConfig
|
|
6
|
+
*/
|
|
2
7
|
export const defaultTypeScriptAngularServicesGeneratorConfig = {
|
|
3
8
|
...defaultTypeScriptGeneratorConfig,
|
|
4
9
|
provideKind: 'provide-fn',
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { ts } from '../../../ast/index.ts';
|
|
2
2
|
import type { TypeScriptAngularServicesGeneratorConfig } from './models.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the factories for the references to the Angular utility files and the generated API infrastructure.
|
|
5
|
+
*
|
|
6
|
+
* The references point into `{outputDir}/{utilsDir}`. `abortablePromise` and `waitForResponse` are exported by
|
|
7
|
+
* `angular-service.utils.ts`, `requestBuilder` by `request-builder.ts`, and `apiConfiguration`, `apiBaseService`,
|
|
8
|
+
* `httpStatusCode` and `provide` by the files that the services generator writes.
|
|
9
|
+
*
|
|
10
|
+
* @param options The services generator configuration. It determines the names and the location of the references.
|
|
11
|
+
* @returns The reference factories, keyed by the name of the referenced component.
|
|
12
|
+
* @see TypeScriptAngularServicesGeneratorConfig
|
|
13
|
+
*/
|
|
3
14
|
export declare function getReferenceFactories(options: TypeScriptAngularServicesGeneratorConfig): {
|
|
4
15
|
abortablePromise: ts.GenericModuleReferenceFactory<1>;
|
|
5
16
|
waitForResponse: ts.GenericModuleReferenceFactory<1>;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { join, resolve } from 'node:path';
|
|
2
2
|
import { toCasing } from '@goast/core';
|
|
3
3
|
import { ts } from '../../../ast/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates the factories for the references to the Angular utility files and the generated API infrastructure.
|
|
6
|
+
*
|
|
7
|
+
* The references point into `{outputDir}/{utilsDir}`. `abortablePromise` and `waitForResponse` are exported by
|
|
8
|
+
* `angular-service.utils.ts`, `requestBuilder` by `request-builder.ts`, and `apiConfiguration`, `apiBaseService`,
|
|
9
|
+
* `httpStatusCode` and `provide` by the files that the services generator writes.
|
|
10
|
+
*
|
|
11
|
+
* @param options The services generator configuration. It determines the names and the location of the references.
|
|
12
|
+
* @returns The reference factories, keyed by the name of the referenced component.
|
|
13
|
+
* @see TypeScriptAngularServicesGeneratorConfig
|
|
14
|
+
*/
|
|
4
15
|
// See packages/typescript/assets/client/angular for reference
|
|
5
16
|
export function getReferenceFactories(options) {
|
|
6
17
|
const utilsDirPath = resolve(options.outputDir, options.utilsDir);
|
|
@@ -6,10 +6,32 @@ import type { TypeScriptEasyNetworkStubGeneratorContext, TypeScriptEasyNetworkSt
|
|
|
6
6
|
type Context = TypeScriptEasyNetworkStubGeneratorContext;
|
|
7
7
|
type Output = TypeScriptEasyNetworkStubGeneratorOutput;
|
|
8
8
|
type Builder = TypeScriptFileBuilder;
|
|
9
|
+
/**
|
|
10
|
+
* Generates the stub class of one API service.
|
|
11
|
+
* @template TOutput The type of the output returned for the service.
|
|
12
|
+
* @see DefaultTypeScriptEasyNetworkStubGenerator
|
|
13
|
+
*/
|
|
9
14
|
export interface TypeScriptEasyNetworkStubGenerator<TOutput extends Output = Output> {
|
|
15
|
+
/**
|
|
16
|
+
* Generates the stub file of the service in the context and returns the export that was 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 `TypeScriptEasyNetworkStubGenerator`. It writes the stub class of one service to
|
|
24
|
+
* `{outputDir}/{stubsDir}/{service}.stubs.ts`, where `{service}` is the kebab-cased service name. The class extends
|
|
25
|
+
* `EasyNetworkStubBase` and has a responder, a request list and a `stub_*` method for each endpoint.
|
|
26
|
+
* Extend it to customize the output.
|
|
27
|
+
* @see TypeScriptEasyNetworkStubsGenerator
|
|
28
|
+
*/
|
|
12
29
|
export declare class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGenerator<Context, Output> implements TypeScriptEasyNetworkStubGenerator {
|
|
30
|
+
/**
|
|
31
|
+
* Generates the stub file of the service and returns the export that was written.
|
|
32
|
+
* @param ctx The context of the service to generate.
|
|
33
|
+
* @returns The `component` (the stub class name) and `filePath` of the generated stub class.
|
|
34
|
+
*/
|
|
13
35
|
generate(ctx: Context): MaybePromise<Output>;
|
|
14
36
|
protected getStubFileContent(ctx: Context): AppendValueGroup<Builder>;
|
|
15
37
|
protected getResponderVariable(ctx: Context, endpoint: ApiEndpoint): ts.Variable<Builder>;
|
|
@@ -3,7 +3,19 @@ import { adjustCasing, appendValueGroup, builderTemplate as s, getSourceDisplayN
|
|
|
3
3
|
import { ts } from '../../../ast/index.js';
|
|
4
4
|
import { TypeScriptFileBuilder } from '../../../file-builder.js';
|
|
5
5
|
import { TypeScriptFileGenerator } from '../../file-generator.js';
|
|
6
|
+
/**
|
|
7
|
+
* The default implementation of `TypeScriptEasyNetworkStubGenerator`. It writes the stub class of one service to
|
|
8
|
+
* `{outputDir}/{stubsDir}/{service}.stubs.ts`, where `{service}` is the kebab-cased service name. The class extends
|
|
9
|
+
* `EasyNetworkStubBase` and has a responder, a request list and a `stub_*` method for each endpoint.
|
|
10
|
+
* Extend it to customize the output.
|
|
11
|
+
* @see TypeScriptEasyNetworkStubsGenerator
|
|
12
|
+
*/
|
|
6
13
|
export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGenerator {
|
|
14
|
+
/**
|
|
15
|
+
* Generates the stub file of the service and returns the export that was written.
|
|
16
|
+
* @param ctx The context of the service to generate.
|
|
17
|
+
* @returns The `component` (the stub class name) and `filePath` of the generated stub class.
|
|
18
|
+
*/
|
|
7
19
|
generate(ctx) {
|
|
8
20
|
const filePath = this.getStubFilePath(ctx);
|
|
9
21
|
const name = this.getStubClassName(ctx);
|
|
@@ -9,8 +9,24 @@ type Output = TypeScriptEasyNetworkStubsGeneratorOutput;
|
|
|
9
9
|
type Config = TypeScriptEasyNetworkStubsGeneratorConfig;
|
|
10
10
|
type ServiceOutput = TypeScriptEasyNetworkStubGeneratorOutput;
|
|
11
11
|
type Context = TypeScriptEasyNetworkStubsGeneratorContext;
|
|
12
|
+
/**
|
|
13
|
+
* Generates an easy-network-stub stub class for each API service (tag), and an index file that combines them.
|
|
14
|
+
*
|
|
15
|
+
* Each service produces `{outputDir}/{stubsDir}/{service}.stubs.ts`, where `{service}` is the kebab-cased service name.
|
|
16
|
+
* The utilities are copied to `{outputDir}/{utilsDir}`. The index file `{outputDir}/{stubsIndexFile}` exports all stub
|
|
17
|
+
* classes and an aggregate `{domainName}_ApiStubs` class (named by `typeNameCasing`) with one group per service.
|
|
18
|
+
*
|
|
19
|
+
* It publishes `typescript.stubs[serviceId]` with the `component` and `filePath` of each stub class, and
|
|
20
|
+
* `typescript.indexFiles.stubs` with the path of the index file, for subsequent generators.
|
|
21
|
+
* @see TypeScriptEasyNetworkStubGenerator
|
|
22
|
+
*/
|
|
12
23
|
export declare class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerationProviderBase<Input, Output, Config, ServiceOutput, Context> {
|
|
13
24
|
private readonly _generatorFactory;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a new instance of the TypeScriptEasyNetworkStubsGenerator class.
|
|
27
|
+
* @param generatorFactory The factory that creates the generator for each service. Defaults to a
|
|
28
|
+
* `DefaultTypeScriptEasyNetworkStubGenerator`.
|
|
29
|
+
*/
|
|
14
30
|
constructor(generatorFactory?: Factory<TypeScriptEasyNetworkStubGenerator, []>);
|
|
15
31
|
protected initResult(): Output;
|
|
16
32
|
protected buildContext(context: OpenApiGeneratorContext<Input>, config?: Partial<Config> | undefined): Context;
|
|
@@ -7,8 +7,24 @@ import { TypeScriptFileBuilder } from '../../../file-builder.js';
|
|
|
7
7
|
import { DefaultTypeScriptEasyNetworkStubGenerator, } from './easy-network-stub-generator.js';
|
|
8
8
|
import { defaultTypeScriptEasyNetworkStubsGeneratorConfig, } from './models.js';
|
|
9
9
|
import { getReferenceFactories } from './refs.js';
|
|
10
|
+
/**
|
|
11
|
+
* Generates an easy-network-stub stub class for each API service (tag), and an index file that combines them.
|
|
12
|
+
*
|
|
13
|
+
* Each service produces `{outputDir}/{stubsDir}/{service}.stubs.ts`, where `{service}` is the kebab-cased service name.
|
|
14
|
+
* The utilities are copied to `{outputDir}/{utilsDir}`. The index file `{outputDir}/{stubsIndexFile}` exports all stub
|
|
15
|
+
* classes and an aggregate `{domainName}_ApiStubs` class (named by `typeNameCasing`) with one group per service.
|
|
16
|
+
*
|
|
17
|
+
* It publishes `typescript.stubs[serviceId]` with the `component` and `filePath` of each stub class, and
|
|
18
|
+
* `typescript.indexFiles.stubs` with the path of the index file, for subsequent generators.
|
|
19
|
+
* @see TypeScriptEasyNetworkStubGenerator
|
|
20
|
+
*/
|
|
10
21
|
export class TypeScriptEasyNetworkStubsGenerator extends OpenApiServicesGenerationProviderBase {
|
|
11
22
|
_generatorFactory;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes a new instance of the TypeScriptEasyNetworkStubsGenerator class.
|
|
25
|
+
* @param generatorFactory The factory that creates the generator for each service. Defaults to a
|
|
26
|
+
* `DefaultTypeScriptEasyNetworkStubGenerator`.
|
|
27
|
+
*/
|
|
12
28
|
constructor(generatorFactory) {
|
|
13
29
|
super();
|
|
14
30
|
this._generatorFactory = generatorFactory ?? Factory.fromValue(new DefaultTypeScriptEasyNetworkStubGenerator());
|
|
@@ -5,6 +5,11 @@ import { type TypeScriptGeneratorConfig } from '../../../config.ts';
|
|
|
5
5
|
import type { TypeScriptFileBuilder } from '../../../file-builder.ts';
|
|
6
6
|
import type { TypeScriptModelGeneratorOutput } from '../../models/index.ts';
|
|
7
7
|
import type { getReferenceFactories } from './refs.ts';
|
|
8
|
+
/**
|
|
9
|
+
* The configuration of the `TypeScriptEasyNetworkStubsGenerator`. It extends the common TypeScript generator
|
|
10
|
+
* configuration with the naming, directory and index file settings of the generated stubs.
|
|
11
|
+
* @see TypeScriptEasyNetworkStubsGenerator
|
|
12
|
+
*/
|
|
8
13
|
export type TypeScriptEasyNetworkStubsGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
9
14
|
/**
|
|
10
15
|
* The domain name of the API. Used as a prefix for exported components (e.g. `ApiStubs`).
|
|
@@ -50,28 +55,84 @@ export type TypeScriptEasyNetworkStubsGeneratorConfig = TypeScriptGeneratorConfi
|
|
|
50
55
|
*/
|
|
51
56
|
utilsDir: string;
|
|
52
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* The default configuration of the `TypeScriptEasyNetworkStubsGenerator`. The provider uses these values for every
|
|
60
|
+
* option that is not set in its configuration.
|
|
61
|
+
* @see TypeScriptEasyNetworkStubsGeneratorConfig
|
|
62
|
+
*/
|
|
53
63
|
export declare const defaultTypeScriptEasyNetworkStubsGeneratorConfig: DefaultGenerationProviderConfig<TypeScriptEasyNetworkStubsGeneratorConfig>;
|
|
64
|
+
/**
|
|
65
|
+
* The input of the `TypeScriptEasyNetworkStubsGenerator`. It is the output of the models generator, which the stubs use
|
|
66
|
+
* to reference the request and response model types.
|
|
67
|
+
*/
|
|
54
68
|
export type TypeScriptEasyNetworkStubsGeneratorInput = {
|
|
69
|
+
/**
|
|
70
|
+
* The TypeScript-specific results of the models generator.
|
|
71
|
+
*/
|
|
55
72
|
typescript: {
|
|
73
|
+
/**
|
|
74
|
+
* The generated models, keyed by the ID of their schema (`ApiSchema['id']`).
|
|
75
|
+
*/
|
|
56
76
|
models: {
|
|
77
|
+
/**
|
|
78
|
+
* The model output of one schema.
|
|
79
|
+
*/
|
|
57
80
|
[schemaId: string]: TypeScriptModelGeneratorOutput;
|
|
58
81
|
};
|
|
59
82
|
};
|
|
60
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* The output of the `TypeScriptEasyNetworkStubsGenerator`. It is published under the `typescript` key for subsequent
|
|
86
|
+
* generators.
|
|
87
|
+
*/
|
|
61
88
|
export type TypeScriptEasyNetworkStubsGeneratorOutput = {
|
|
89
|
+
/**
|
|
90
|
+
* The TypeScript-specific results of the stubs generator.
|
|
91
|
+
*/
|
|
62
92
|
typescript: {
|
|
93
|
+
/**
|
|
94
|
+
* The stub classes, keyed by the ID of their service (`ApiService['id']`).
|
|
95
|
+
*/
|
|
63
96
|
stubs: {
|
|
97
|
+
/**
|
|
98
|
+
* The stub class that was generated for one service.
|
|
99
|
+
*/
|
|
64
100
|
[serviceId: string]: TypeScriptEasyNetworkStubGeneratorOutput;
|
|
65
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* The paths of the index files.
|
|
104
|
+
*/
|
|
66
105
|
indexFiles: {
|
|
106
|
+
/**
|
|
107
|
+
* The path to the index file that exports the stub classes. `null` when `stubsIndexFile` is disabled.
|
|
108
|
+
*/
|
|
67
109
|
stubs: Nullable<string>;
|
|
68
110
|
};
|
|
69
111
|
};
|
|
70
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* The output of the `TypeScriptEasyNetworkStubGenerator` for one service: the exported stub class and its file.
|
|
115
|
+
* @see TypeScriptExportOutput
|
|
116
|
+
*/
|
|
71
117
|
export type TypeScriptEasyNetworkStubGeneratorOutput = TypeScriptExportOutput;
|
|
118
|
+
/**
|
|
119
|
+
* The context passed to the `TypeScriptEasyNetworkStubsGenerator` methods. It extends the services generator context
|
|
120
|
+
* with the reference factories of the stubs.
|
|
121
|
+
* @see TypeScriptEasyNetworkStubGeneratorContext
|
|
122
|
+
*/
|
|
72
123
|
export type TypeScriptEasyNetworkStubsGeneratorContext = OpenApiServicesGenerationProviderContext<TypeScriptEasyNetworkStubsGeneratorInput, TypeScriptEasyNetworkStubsGeneratorOutput, TypeScriptEasyNetworkStubsGeneratorConfig, TypeScriptEasyNetworkStubGeneratorOutput> & {
|
|
124
|
+
/**
|
|
125
|
+
* The factories that create references to the utilities, as returned by `getReferenceFactories`.
|
|
126
|
+
*/
|
|
73
127
|
refs: ReturnType<typeof getReferenceFactories>;
|
|
74
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* The context passed to `TypeScriptEasyNetworkStubGenerator.generate` for a single service.
|
|
131
|
+
* @see TypeScriptEasyNetworkStubsGeneratorContext
|
|
132
|
+
*/
|
|
75
133
|
export type TypeScriptEasyNetworkStubGeneratorContext = TypeScriptEasyNetworkStubsGeneratorContext & {
|
|
134
|
+
/**
|
|
135
|
+
* The API service whose stubs are generated.
|
|
136
|
+
*/
|
|
76
137
|
readonly service: ApiService;
|
|
77
138
|
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ts } from '../../../ast/index.js';
|
|
2
2
|
import { defaultTypeScriptGeneratorConfig } from '../../../config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The default configuration of the `TypeScriptEasyNetworkStubsGenerator`. The provider uses these values for every
|
|
5
|
+
* option that is not set in its configuration.
|
|
6
|
+
* @see TypeScriptEasyNetworkStubsGeneratorConfig
|
|
7
|
+
*/
|
|
3
8
|
export const defaultTypeScriptEasyNetworkStubsGeneratorConfig = {
|
|
4
9
|
...defaultTypeScriptGeneratorConfig,
|
|
5
10
|
domainName: undefined,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ts } from '../../../ast/index.ts';
|
|
2
2
|
import type { TypeScriptEasyNetworkStubsGeneratorConfig } from './models.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the references to the utilities that the generated stubs import from the `utils` directory.
|
|
5
|
+
* `TypeScriptEasyNetworkStubsGenerator` copies these utilities to `{outputDir}/{utilsDir}`.
|
|
6
|
+
* @param options The configuration of the stubs generator, which provides `outputDir` and `utilsDir`.
|
|
7
|
+
* @returns The reference factories for the members of `easy-network-stub.utils.ts`, and for `StubHandle`, which is
|
|
8
|
+
* imported from the `easy-network-stub` module.
|
|
9
|
+
*/
|
|
3
10
|
export declare function getReferenceFactories(options: TypeScriptEasyNetworkStubsGeneratorConfig): {
|
|
4
11
|
easyNetworkStubWrapperOptions: ts.ModuleReferenceFactory;
|
|
5
12
|
stubRequestItem: ts.ModuleReferenceFactory;
|
|
@@ -1,5 +1,12 @@
|
|
|
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 stubs import from the `utils` directory.
|
|
5
|
+
* `TypeScriptEasyNetworkStubsGenerator` copies these utilities to `{outputDir}/{utilsDir}`.
|
|
6
|
+
* @param options The configuration of the stubs generator, which provides `outputDir` and `utilsDir`.
|
|
7
|
+
* @returns The reference factories for the members of `easy-network-stub.utils.ts`, and for `StubHandle`, which is
|
|
8
|
+
* imported from the `easy-network-stub` module.
|
|
9
|
+
*/
|
|
3
10
|
// See packages/typescript/assets/stubs/easy-network-stub for reference
|
|
4
11
|
export function getReferenceFactories(options) {
|
|
5
12
|
const utilsDirPath = resolve(options.outputDir, options.utilsDir);
|