@goast/typescript 0.5.1-k6.2 → 0.5.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/LICENSE +21 -21
- package/README.md +52 -52
- package/assets/client/angular/angular-service.utils.ts +82 -82
- package/assets/client/angular/request-builder.ts +377 -377
- package/assets/client/fetch/fetch-client.utils.ts +52 -52
- package/assets/client/k6/request-builder.js +419 -419
- package/assets/client/k6/request-builder.ts +341 -341
- package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +259 -259
- package/esm/src/generators/models/model-generator.d.ts +1 -1
- package/esm/src/generators/models/model-generator.d.ts.map +1 -1
- package/esm/src/generators/models/model-generator.js +2 -2
- package/esm/src/generators/models/models.d.ts +7 -0
- package/esm/src/generators/models/models.d.ts.map +1 -1
- package/esm/src/generators/models/models.js +2 -0
- package/esm/src/generators/services/angular-services/angular-service-generator.js +9 -9
- package/esm/src/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
- package/esm/src/generators/services/fetch-clients/fetch-client-generator.js +2 -2
- package/esm/src/generators/services/k6-clients/k6-client-generator.js +11 -11
- package/package.json +1 -1
- package/script/src/generators/models/model-generator.d.ts +1 -1
- package/script/src/generators/models/model-generator.d.ts.map +1 -1
- package/script/src/generators/models/model-generator.js +2 -2
- package/script/src/generators/models/models.d.ts +7 -0
- package/script/src/generators/models/models.d.ts.map +1 -1
- package/script/src/generators/models/models.js +2 -0
- package/script/src/generators/services/angular-services/angular-service-generator.js +9 -9
- package/script/src/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
- package/script/src/generators/services/fetch-clients/fetch-client-generator.js +2 -2
- package/script/src/generators/services/k6-clients/k6-client-generator.js +11 -11
- package/src/mod.ts +7 -0
- package/src/src/assets.ts +9 -0
- package/src/src/ast/_index.ts +54 -0
- package/src/src/ast/common.ts +1 -0
- package/src/src/ast/index.ts +1 -0
- package/src/src/ast/node.ts +10 -0
- package/src/src/ast/nodes/argument.ts +40 -0
- package/src/src/ast/nodes/array-type.ts +49 -0
- package/src/src/ast/nodes/arrow-function.ts +91 -0
- package/src/src/ast/nodes/call.ts +55 -0
- package/src/src/ast/nodes/class.ts +133 -0
- package/src/src/ast/nodes/constructor-parameter.ts +70 -0
- package/src/src/ast/nodes/constructor.ts +77 -0
- package/src/src/ast/nodes/decorator.ts +76 -0
- package/src/src/ast/nodes/doc-tag.ts +291 -0
- package/src/src/ast/nodes/doc.ts +102 -0
- package/src/src/ast/nodes/enum-value.ts +72 -0
- package/src/src/ast/nodes/enum.ts +77 -0
- package/src/src/ast/nodes/export.ts +54 -0
- package/src/src/ast/nodes/function-type.ts +60 -0
- package/src/src/ast/nodes/function.ts +107 -0
- package/src/src/ast/nodes/generic-parameter.ts +71 -0
- package/src/src/ast/nodes/indexer.ts +60 -0
- package/src/src/ast/nodes/interface.ts +117 -0
- package/src/src/ast/nodes/intersection-type.ts +67 -0
- package/src/src/ast/nodes/lookup-type.ts +53 -0
- package/src/src/ast/nodes/method.ts +138 -0
- package/src/src/ast/nodes/object-type.ts +52 -0
- package/src/src/ast/nodes/object.ts +48 -0
- package/src/src/ast/nodes/parameter.ts +85 -0
- package/src/src/ast/nodes/property-accessor.ts +173 -0
- package/src/src/ast/nodes/property.ts +192 -0
- package/src/src/ast/nodes/reference.ts +194 -0
- package/src/src/ast/nodes/string.ts +49 -0
- package/src/src/ast/nodes/tuple.ts +53 -0
- package/src/src/ast/nodes/type-alias.ts +75 -0
- package/src/src/ast/nodes/typeof.ts +42 -0
- package/src/src/ast/nodes/types.ts +40 -0
- package/src/src/ast/nodes/union-type.ts +62 -0
- package/src/src/ast/nodes/variable.ts +73 -0
- package/src/src/ast/references/angular.ts +24 -0
- package/src/src/ast/references/easy-network-stub.ts +21 -0
- package/src/src/ast/references/index.ts +5 -0
- package/src/src/ast/references/k6.ts +8 -0
- package/src/src/ast/references/rxjs.ts +7 -0
- package/src/src/ast/references/typescript.ts +35 -0
- package/src/src/ast/utils/get-type-script-builder-options.ts +19 -0
- package/src/src/ast/utils/to-ts-node.ts +27 -0
- package/src/src/ast/utils/write-ts-generic-parameters.ts +25 -0
- package/src/src/ast/utils/write-ts-members.ts +28 -0
- package/src/src/ast/utils/write-ts-nodes.ts +35 -0
- package/src/src/ast/utils/write-ts-parameters.ts +25 -0
- package/src/src/common-results.ts +26 -0
- package/src/src/config.ts +89 -0
- package/src/src/file-builder.ts +136 -0
- package/src/src/generators/file-generator.ts +15 -0
- package/src/src/generators/index.ts +6 -0
- package/src/src/generators/models/index.ts +3 -0
- package/src/src/generators/models/model-generator.ts +469 -0
- package/src/src/generators/models/models-generator.ts +108 -0
- package/src/src/generators/models/models.ts +121 -0
- package/src/src/generators/services/angular-services/angular-service-generator.ts +406 -0
- package/src/src/generators/services/angular-services/angular-services-generator.ts +295 -0
- package/src/src/generators/services/angular-services/index.ts +3 -0
- package/src/src/generators/services/angular-services/models.ts +277 -0
- package/src/src/generators/services/angular-services/refs.ts +54 -0
- package/src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts +242 -0
- package/src/src/generators/services/easy-network-stub/easy-network-stubs-generator.ts +211 -0
- package/src/src/generators/services/easy-network-stub/index.ts +3 -0
- package/src/src/generators/services/easy-network-stub/models.ts +124 -0
- package/src/src/generators/services/easy-network-stub/refs.ts +45 -0
- package/src/src/generators/services/fetch-clients/fetch-client-generator.ts +267 -0
- package/src/src/generators/services/fetch-clients/fetch-clients-generator.ts +163 -0
- package/src/src/generators/services/fetch-clients/index.ts +3 -0
- package/src/src/generators/services/fetch-clients/models.ts +130 -0
- package/src/src/generators/services/fetch-clients/refs.ts +21 -0
- package/src/src/generators/services/k6-clients/index.ts +3 -0
- package/src/src/generators/services/k6-clients/k6-client-generator.ts +465 -0
- package/src/src/generators/services/k6-clients/k6-clients-generator.ts +171 -0
- package/src/src/generators/services/k6-clients/models.ts +247 -0
- package/src/src/generators/services/k6-clients/refs.ts +16 -0
- package/src/src/import-collection.ts +236 -0
- package/src/src/utils.ts +72 -0
|
@@ -94,15 +94,15 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
|
|
|
94
94
|
],
|
|
95
95
|
returnType: 'this',
|
|
96
96
|
body: appendValueGroup([
|
|
97
|
-
s `this.stubWrapper.stub2<${requestType}>()(${s.indent `
|
|
98
|
-
${ts.string(endpoint.method.toUpperCase())},
|
|
99
|
-
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
100
|
-
async (request) => {${s.indent `
|
|
101
|
-
if (this.stubWrapper.options.rememberRequests) {${s.indent `
|
|
102
|
-
this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
|
|
103
|
-
}
|
|
104
|
-
throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
|
|
105
|
-
}`}
|
|
97
|
+
s `this.stubWrapper.stub2<${requestType}>()(${s.indent `
|
|
98
|
+
${ts.string(endpoint.method.toUpperCase())},
|
|
99
|
+
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
100
|
+
async (request) => {${s.indent `
|
|
101
|
+
if (this.stubWrapper.options.rememberRequests) {${s.indent `
|
|
102
|
+
this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
|
|
103
|
+
}
|
|
104
|
+
throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
|
|
105
|
+
}`}
|
|
106
106
|
);`,
|
|
107
107
|
'return this;',
|
|
108
108
|
], '\n'),
|
|
@@ -131,7 +131,7 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
|
|
|
131
131
|
const method = this.getInterfaceEndpointMethod(ctx, endpoint);
|
|
132
132
|
method.accessModifier = 'public';
|
|
133
133
|
method.body = appendValueGroup([
|
|
134
|
-
s `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${s.indent `
|
|
134
|
+
s `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${s.indent `
|
|
135
135
|
.withPath(${ts.string(endpoint.path)})${(b) => b.forEach(endpoint.parameters, (b, p) => {
|
|
136
136
|
switch (p.target) {
|
|
137
137
|
case 'path':
|
|
@@ -141,7 +141,7 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
|
|
|
141
141
|
b.append(s `\n.withQueryParam(${ts.string(p.name)}, params.${toCasing(p.name, ctx.config.paramNameCasing)})`);
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
|
-
})}
|
|
144
|
+
})}
|
|
145
145
|
.build();`}`,
|
|
146
146
|
s `const response = (this.options.fetch ?? fetch)(url, ${ts.object({
|
|
147
147
|
members: [
|
|
@@ -229,7 +229,7 @@ export class DefaultTypeScriptK6ClientGenerator extends TypeScriptFileGenerator
|
|
|
229
229
|
ts.constructorParameter('rootUrl', { type: isJs ? undefined : rootUrlType }),
|
|
230
230
|
ts.constructorParameter('defaultK6ParamsFactory', { type: isJs ? undefined : paramType, optional: true }),
|
|
231
231
|
],
|
|
232
|
-
body: s `this.rootUrl = rootUrl;
|
|
232
|
+
body: s `this.rootUrl = rootUrl;
|
|
233
233
|
this._defaultK6ParamsFactory = defaultK6ParamsFactory;`,
|
|
234
234
|
}),
|
|
235
235
|
...ctx.service.endpoints.map((e) => this.getEndpointMethod(ctx, e)),
|
|
@@ -291,17 +291,17 @@ export class DefaultTypeScriptK6ClientGenerator extends TypeScriptFileGenerator
|
|
|
291
291
|
: null,
|
|
292
292
|
'',
|
|
293
293
|
ctx.config.language === 'javascript'
|
|
294
|
-
? s `return /** @type {${returnType}} */ (${s.indent `
|
|
295
|
-
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${s.indent `
|
|
296
|
-
accept: ${ts.string(accept)},
|
|
297
|
-
params: this.getK6Params(k6Params),`}
|
|
298
|
-
})`}
|
|
294
|
+
? s `return /** @type {${returnType}} */ (${s.indent `
|
|
295
|
+
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${s.indent `
|
|
296
|
+
accept: ${ts.string(accept)},
|
|
297
|
+
params: this.getK6Params(k6Params),`}
|
|
298
|
+
})`}
|
|
299
299
|
);`
|
|
300
|
-
: s `return (${s.indent `
|
|
301
|
-
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${s.indent `
|
|
302
|
-
accept: ${ts.string(accept)},
|
|
303
|
-
params: this.getK6Params(k6Params),`}
|
|
304
|
-
})`}
|
|
300
|
+
: s `return (${s.indent `
|
|
301
|
+
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${s.indent `
|
|
302
|
+
accept: ${ts.string(accept)},
|
|
303
|
+
params: this.getK6Params(k6Params),`}
|
|
304
|
+
})`}
|
|
305
305
|
) as unknown as ${returnType};`,
|
|
306
306
|
], '\n'),
|
|
307
307
|
});
|
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@ export declare class DefaultTypeScriptModelGenerator extends TypeScriptFileGener
|
|
|
24
24
|
skipSchemas?: boolean;
|
|
25
25
|
useBaseType?: boolean;
|
|
26
26
|
}): ts.Type<Builder> | null;
|
|
27
|
-
protected getStringType(
|
|
27
|
+
protected getStringType(ctx: Context, schema: StringLikeApiSchema): ts.Type<Builder>;
|
|
28
28
|
protected getArrayType(ctx: Context, schema: ArrayLikeApiSchema): ts.Type<Builder>;
|
|
29
29
|
protected getObjectType(ctx: Context, schema: ObjectLikeApiSchema): ts.Type<Builder>;
|
|
30
30
|
protected getDiscriminatorType(ctx: Context, schema: ApiSchema): ts.Type<Builder>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-generator.d.ts","sourceRoot":"","sources":["../../../../src/src/generators/models/model-generator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,gBAAgB,EAErB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAE1B,KAAK,YAAY,EAEjB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EAExB,KAAK,mBAAmB,EAEzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,E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S,CAAC,QAAQ,CAAC,GAAG,SAAS;IAU/E,SAAS,CAAC,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM;IAIzE,SAAS,CAAC,gCAAgC,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM;IAInF,SAAS,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM;IAI3E,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM;IAIlE,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC,kBAAkB,CAAC;IAM7F,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM;CAO/D"}
|
|
@@ -222,9 +222,9 @@ class DefaultTypeScriptModelGenerator extends file_generator_js_1.TypeScriptFile
|
|
|
222
222
|
return this.getAnyType(ctx);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
getStringType(
|
|
225
|
+
getStringType(ctx, schema) {
|
|
226
226
|
if (schema.format === 'binary') {
|
|
227
|
-
return
|
|
227
|
+
return ctx.config.binarySchemaType();
|
|
228
228
|
}
|
|
229
229
|
return 'string';
|
|
230
230
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ApiSchema, DefaultGenerationProviderConfig, ExtendedStringCasing, Nullable, OpenApiSchemasGenerationProviderContext } from '@goast/core';
|
|
2
|
+
import { ts } from '../../ast/index.js';
|
|
2
3
|
import type { TypeScriptComponentOutput } from '../../common-results.js';
|
|
3
4
|
import { type TypeScriptGeneratorConfig } from '../../config.js';
|
|
5
|
+
import type { TypeScriptFileBuilder } from '../../file-builder.js';
|
|
4
6
|
export type TypeScriptModelGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
5
7
|
/**
|
|
6
8
|
* Determines how to generate enums.
|
|
@@ -41,6 +43,11 @@ export type TypeScriptModelGeneratorConfig = TypeScriptGeneratorConfig & {
|
|
|
41
43
|
* @default `_<SchemaName>Base`
|
|
42
44
|
*/
|
|
43
45
|
discriminatorBaseTypeCasing: ExtendedStringCasing;
|
|
46
|
+
/**
|
|
47
|
+
* The type to use for binary schemas.
|
|
48
|
+
* @default `ts.refs.blob`
|
|
49
|
+
*/
|
|
50
|
+
binarySchemaType: () => ts.Type<TypeScriptFileBuilder>;
|
|
44
51
|
};
|
|
45
52
|
export type TypeScriptModelsGeneratorConfig = TypeScriptModelGeneratorConfig & {
|
|
46
53
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/src/generators/models/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,+BAA+B,EAC/B,oBAAoB,EACpB,QAAQ,EACR,uCAAuC,EACxC,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAoC,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../src/src/generators/models/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,+BAA+B,EAC/B,oBAAoB,EACpB,QAAQ,EACR,uCAAuC,EACxC,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAoC,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,MAAM,8BAA8B,GAAG,yBAAyB,GAAG;IAC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AAS,CAAC;CACnB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultTypeScriptModelsGeneratorConfig = exports.defaultTypeScriptModelGeneratorConfig = void 0;
|
|
4
|
+
const index_js_1 = require("../../ast/index.js");
|
|
4
5
|
const config_js_1 = require("../../config.js");
|
|
5
6
|
exports.defaultTypeScriptModelGeneratorConfig = {
|
|
6
7
|
...config_js_1.defaultTypeScriptGeneratorConfig,
|
|
@@ -11,6 +12,7 @@ exports.defaultTypeScriptModelGeneratorConfig = {
|
|
|
11
12
|
modelFileNameCasing: undefined,
|
|
12
13
|
typeDeclaration: 'type',
|
|
13
14
|
discriminatorBaseTypeCasing: { casing: 'pascal', prefix: '_', suffix: 'Base' },
|
|
15
|
+
binarySchemaType: index_js_1.ts.refs.blob,
|
|
14
16
|
};
|
|
15
17
|
exports.defaultTypeScriptModelsGeneratorConfig = {
|
|
16
18
|
...exports.defaultTypeScriptModelGeneratorConfig,
|
|
@@ -232,13 +232,13 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_js_1.TypeS
|
|
|
232
232
|
], '\n'), { multiline: true })
|
|
233
233
|
: null,
|
|
234
234
|
'',
|
|
235
|
-
(0, core_1.builderTemplate) `return ${ctx.refs.waitForResponse([responseModelType])}(${core_1.builderTemplate.indent `
|
|
236
|
-
this.http.request(rb.build({${core_1.builderTemplate.indent `
|
|
237
|
-
responseType: ${index_js_1.ts.string(responseType)},
|
|
238
|
-
accept: ${index_js_1.ts.string(accept)},
|
|
239
|
-
context,`}
|
|
240
|
-
})),
|
|
241
|
-
{${core_1.builderTemplate.indent `
|
|
235
|
+
(0, core_1.builderTemplate) `return ${ctx.refs.waitForResponse([responseModelType])}(${core_1.builderTemplate.indent `
|
|
236
|
+
this.http.request(rb.build({${core_1.builderTemplate.indent `
|
|
237
|
+
responseType: ${index_js_1.ts.string(responseType)},
|
|
238
|
+
accept: ${index_js_1.ts.string(accept)},
|
|
239
|
+
context,`}
|
|
240
|
+
})),
|
|
241
|
+
{${core_1.builderTemplate.indent `
|
|
242
242
|
errorResponseTypes: ${index_js_1.ts.object({
|
|
243
243
|
members: [
|
|
244
244
|
...Object.entries(this.getEndpointStatusCodes(ctx, endpoint))
|
|
@@ -247,8 +247,8 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_js_1.TypeS
|
|
|
247
247
|
return index_js_1.ts.property(key, { value: index_js_1.ts.string(value.parser) });
|
|
248
248
|
}),
|
|
249
249
|
],
|
|
250
|
-
})}`}
|
|
251
|
-
}`}
|
|
250
|
+
})}`}
|
|
251
|
+
}`}
|
|
252
252
|
)`,
|
|
253
253
|
], '\n'),
|
|
254
254
|
});
|
|
@@ -97,15 +97,15 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_js_1.Type
|
|
|
97
97
|
],
|
|
98
98
|
returnType: 'this',
|
|
99
99
|
body: (0, core_1.appendValueGroup)([
|
|
100
|
-
(0, core_1.builderTemplate) `this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate.indent `
|
|
101
|
-
${index_js_1.ts.string(endpoint.method.toUpperCase())},
|
|
102
|
-
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
103
|
-
async (request) => {${core_1.builderTemplate.indent `
|
|
104
|
-
if (this.stubWrapper.options.rememberRequests) {${core_1.builderTemplate.indent `
|
|
105
|
-
this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
|
|
106
|
-
}
|
|
107
|
-
throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
|
|
108
|
-
}`}
|
|
100
|
+
(0, core_1.builderTemplate) `this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate.indent `
|
|
101
|
+
${index_js_1.ts.string(endpoint.method.toUpperCase())},
|
|
102
|
+
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
103
|
+
async (request) => {${core_1.builderTemplate.indent `
|
|
104
|
+
if (this.stubWrapper.options.rememberRequests) {${core_1.builderTemplate.indent `
|
|
105
|
+
this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
|
|
106
|
+
}
|
|
107
|
+
throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
|
|
108
|
+
}`}
|
|
109
109
|
);`,
|
|
110
110
|
'return this;',
|
|
111
111
|
], '\n'),
|
|
@@ -134,7 +134,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_js_1.TypeScri
|
|
|
134
134
|
const method = this.getInterfaceEndpointMethod(ctx, endpoint);
|
|
135
135
|
method.accessModifier = 'public';
|
|
136
136
|
method.body = (0, core_1.appendValueGroup)([
|
|
137
|
-
(0, core_1.builderTemplate) `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${core_1.builderTemplate.indent `
|
|
137
|
+
(0, core_1.builderTemplate) `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${core_1.builderTemplate.indent `
|
|
138
138
|
.withPath(${index_js_1.ts.string(endpoint.path)})${(b) => b.forEach(endpoint.parameters, (b, p) => {
|
|
139
139
|
switch (p.target) {
|
|
140
140
|
case 'path':
|
|
@@ -144,7 +144,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_js_1.TypeScri
|
|
|
144
144
|
b.append((0, core_1.builderTemplate) `\n.withQueryParam(${index_js_1.ts.string(p.name)}, params.${(0, core_1.toCasing)(p.name, ctx.config.paramNameCasing)})`);
|
|
145
145
|
break;
|
|
146
146
|
}
|
|
147
|
-
})}
|
|
147
|
+
})}
|
|
148
148
|
.build();`}`,
|
|
149
149
|
(0, core_1.builderTemplate) `const response = (this.options.fetch ?? fetch)(url, ${index_js_1.ts.object({
|
|
150
150
|
members: [
|
|
@@ -232,7 +232,7 @@ class DefaultTypeScriptK6ClientGenerator extends file_generator_js_1.TypeScriptF
|
|
|
232
232
|
index_js_1.ts.constructorParameter('rootUrl', { type: isJs ? undefined : rootUrlType }),
|
|
233
233
|
index_js_1.ts.constructorParameter('defaultK6ParamsFactory', { type: isJs ? undefined : paramType, optional: true }),
|
|
234
234
|
],
|
|
235
|
-
body: (0, core_1.builderTemplate) `this.rootUrl = rootUrl;
|
|
235
|
+
body: (0, core_1.builderTemplate) `this.rootUrl = rootUrl;
|
|
236
236
|
this._defaultK6ParamsFactory = defaultK6ParamsFactory;`,
|
|
237
237
|
}),
|
|
238
238
|
...ctx.service.endpoints.map((e) => this.getEndpointMethod(ctx, e)),
|
|
@@ -294,17 +294,17 @@ class DefaultTypeScriptK6ClientGenerator extends file_generator_js_1.TypeScriptF
|
|
|
294
294
|
: null,
|
|
295
295
|
'',
|
|
296
296
|
ctx.config.language === 'javascript'
|
|
297
|
-
? (0, core_1.builderTemplate) `return /** @type {${returnType}} */ (${core_1.builderTemplate.indent `
|
|
298
|
-
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${core_1.builderTemplate.indent `
|
|
299
|
-
accept: ${index_js_1.ts.string(accept)},
|
|
300
|
-
params: this.getK6Params(k6Params),`}
|
|
301
|
-
})`}
|
|
297
|
+
? (0, core_1.builderTemplate) `return /** @type {${returnType}} */ (${core_1.builderTemplate.indent `
|
|
298
|
+
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${core_1.builderTemplate.indent `
|
|
299
|
+
accept: ${index_js_1.ts.string(accept)},
|
|
300
|
+
params: this.getK6Params(k6Params),`}
|
|
301
|
+
})`}
|
|
302
302
|
);`
|
|
303
|
-
: (0, core_1.builderTemplate) `return (${core_1.builderTemplate.indent `
|
|
304
|
-
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${core_1.builderTemplate.indent `
|
|
305
|
-
accept: ${index_js_1.ts.string(accept)},
|
|
306
|
-
params: this.getK6Params(k6Params),`}
|
|
307
|
-
})`}
|
|
303
|
+
: (0, core_1.builderTemplate) `return (${core_1.builderTemplate.indent `
|
|
304
|
+
${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${core_1.builderTemplate.indent `
|
|
305
|
+
accept: ${index_js_1.ts.string(accept)},
|
|
306
|
+
params: this.getK6Params(k6Params),`}
|
|
307
|
+
})`}
|
|
308
308
|
) as unknown as ${returnType};`,
|
|
309
309
|
], '\n'),
|
|
310
310
|
});
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './src/ast/index.js';
|
|
2
|
+
export * from './src/common-results.js';
|
|
3
|
+
export * from './src/config.js';
|
|
4
|
+
export * from './src/file-builder.js';
|
|
5
|
+
export * from './src/generators/index.js';
|
|
6
|
+
export * from './src/import-collection.js';
|
|
7
|
+
export * from './src/utils.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AssetManager } from '@goast/core';
|
|
2
|
+
import { pathToFileURL, URL } from 'node:url';
|
|
3
|
+
|
|
4
|
+
declare const __filename: string | undefined;
|
|
5
|
+
const scriptUrl = typeof __filename === 'undefined' ? import.meta.url : pathToFileURL(__filename);
|
|
6
|
+
|
|
7
|
+
const manager = new AssetManager(new URL('../assets/', scriptUrl));
|
|
8
|
+
export const getAssetFileContent = manager.getAssetFileContent.bind(manager);
|
|
9
|
+
export const copyAssetFile = manager.copyAssetFile.bind(manager);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export { type TsAccessModifier as AccessModifier } from './common.js';
|
|
2
|
+
export { TsNode as Node } from './node.js';
|
|
3
|
+
export { TsArgument as Argument, tsArgument as argument } from './nodes/argument.js';
|
|
4
|
+
export { TsArrayType as ArrayType, tsArrayType as arrayType } from './nodes/array-type.js';
|
|
5
|
+
export { TsArrowFunction as ArrowFunction, tsArrowFunction as arrowFunction } from './nodes/arrow-function.js';
|
|
6
|
+
export { TsCall as Call, tsCall as call } from './nodes/call.js';
|
|
7
|
+
export { TsClass as Class, tsClass as class } from './nodes/class.js';
|
|
8
|
+
export {
|
|
9
|
+
TsConstructorParameter as ConstructorParameter,
|
|
10
|
+
tsConstructorParameter as constructorParameter,
|
|
11
|
+
} from './nodes/constructor-parameter.js';
|
|
12
|
+
export { TsConstructor as Constructor, tsConstructor as constructor } from './nodes/constructor.js';
|
|
13
|
+
export { TsDecorator as Decorator, tsDecorator as decorator } from './nodes/decorator.js';
|
|
14
|
+
export { TsDocTag as DocTag, tsDocTag as docTag } from './nodes/doc-tag.js';
|
|
15
|
+
export { TsDoc as Doc, tsDoc as doc } from './nodes/doc.js';
|
|
16
|
+
export { TsEnumValue as EnumValue, tsEnumValue as enumValue } from './nodes/enum-value.js';
|
|
17
|
+
export { TsEnum as Enum, tsEnum as enum } from './nodes/enum.js';
|
|
18
|
+
export { TsExport as Export, tsExport as export } from './nodes/export.js';
|
|
19
|
+
export { TsFunctionType as FunctionType, tsFunctionType as functionType } from './nodes/function-type.js';
|
|
20
|
+
export { TsFunction as Function, tsFunction as function } from './nodes/function.js';
|
|
21
|
+
export {
|
|
22
|
+
TsGenericParameter as GenericParameter,
|
|
23
|
+
tsGenericParameter as genericParameter,
|
|
24
|
+
} from './nodes/generic-parameter.js';
|
|
25
|
+
export { TsIndexer as Indexer, tsIndexer as indexer } from './nodes/indexer.js';
|
|
26
|
+
export { TsInterface as Interface, tsInterface as interface } from './nodes/interface.js';
|
|
27
|
+
export {
|
|
28
|
+
TsIntersectionType as IntersectionType,
|
|
29
|
+
tsIntersectionType as intersectionType,
|
|
30
|
+
} from './nodes/intersection-type.js';
|
|
31
|
+
export { TsLookupType as LookupType, tsLookupType as lookupType } from './nodes/lookup-type.js';
|
|
32
|
+
export { TsMethod as Method, tsMethod as method } from './nodes/method.js';
|
|
33
|
+
export { TsObjectType as ObjectType, tsObjectType as objectType } from './nodes/object-type.js';
|
|
34
|
+
export { TsObject as Object, tsObject as object } from './nodes/object.js';
|
|
35
|
+
export { TsParameter as Parameter, tsParameter as parameter } from './nodes/parameter.js';
|
|
36
|
+
export { TsProperty as Property, tsProperty as property } from './nodes/property.js';
|
|
37
|
+
export {
|
|
38
|
+
type TsGenericModuleReferenceFactory as GenericModuleReferenceFactory,
|
|
39
|
+
type TsGenericReferenceFactory as GenericReferenceFactory,
|
|
40
|
+
type TsModuleReferenceFactory as ModuleReferenceFactory,
|
|
41
|
+
TsReference as Reference,
|
|
42
|
+
tsReference as reference,
|
|
43
|
+
type TsReferenceFactory as ReferenceFactory,
|
|
44
|
+
} from './nodes/reference.js';
|
|
45
|
+
export { TsString as String, tsString as string } from './nodes/string.js';
|
|
46
|
+
export { TsTuple as Tuple, tsTuple as tuple } from './nodes/tuple.js';
|
|
47
|
+
export { TsTypeAlias as TypeAlias, tsTypeAlias as typeAlias } from './nodes/type-alias.js';
|
|
48
|
+
export { TsTypeof as Typeof, tsTypeof as typeof } from './nodes/typeof.js';
|
|
49
|
+
export { type TsType as Type, type TsValue as Value } from './nodes/types.js';
|
|
50
|
+
export { TsUnionType as UnionType, tsUnionType as unionType } from './nodes/union-type.js';
|
|
51
|
+
export { TsVariable as Variable, tsVariable as variable } from './nodes/variable.js';
|
|
52
|
+
export * as refs from './references/index.js';
|
|
53
|
+
export { getTypeScriptBuilderOptions as getBuilderOptions } from './utils/get-type-script-builder-options.js';
|
|
54
|
+
export { toTsNode as toNode } from './utils/to-ts-node.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TsAccessModifier = 'public' | 'protected' | 'private';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as ts from './_index.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AstNode, type AstNodeOptions, type SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
export abstract class TsNode<TBuilder extends SourceBuilder, TInjects extends string = never> extends AstNode<
|
|
4
|
+
TBuilder,
|
|
5
|
+
TInjects
|
|
6
|
+
> {
|
|
7
|
+
constructor(options: AstNodeOptions<typeof AstNode<TBuilder, TInjects>>) {
|
|
8
|
+
super(options);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AstNodeOptions, Prettify, SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { TsNode } from '../node.js';
|
|
4
|
+
import { writeTsNode } from '../utils/write-ts-nodes.js';
|
|
5
|
+
import { writeTsParameters } from '../utils/write-ts-parameters.js';
|
|
6
|
+
import type { TsValue } from './types.js';
|
|
7
|
+
|
|
8
|
+
type Injects = never;
|
|
9
|
+
|
|
10
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
11
|
+
typeof TsNode<TBuilder, TInjects | Injects>,
|
|
12
|
+
{
|
|
13
|
+
value: TsValue<TBuilder>;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export class TsArgument<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
|
|
18
|
+
TBuilder,
|
|
19
|
+
TInjects | Injects
|
|
20
|
+
> {
|
|
21
|
+
public value: TsValue<TBuilder>;
|
|
22
|
+
|
|
23
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
24
|
+
super(options);
|
|
25
|
+
this.value = options.value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected override onWrite(builder: TBuilder): void {
|
|
29
|
+
writeTsNode(builder, this.value);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const createArgument = <TBuilder extends SourceBuilder>(
|
|
34
|
+
value: Options<TBuilder>['value'],
|
|
35
|
+
options?: Prettify<Omit<Options<TBuilder>, 'value'>>,
|
|
36
|
+
): TsArgument<TBuilder> => new TsArgument<TBuilder>({ ...options, value });
|
|
37
|
+
|
|
38
|
+
export const tsArgument: typeof createArgument & { write: typeof writeTsParameters } = Object.assign(createArgument, {
|
|
39
|
+
write: writeTsParameters,
|
|
40
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AstNodeOptions, Nullable, Prettify, SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { TsNode } from '../node.js';
|
|
4
|
+
import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
5
|
+
import type { TsType } from './types.js';
|
|
6
|
+
|
|
7
|
+
type Injects = 'type';
|
|
8
|
+
|
|
9
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
10
|
+
typeof TsNode<TBuilder, TInjects | Injects>,
|
|
11
|
+
{
|
|
12
|
+
readonly?: Nullable<boolean>;
|
|
13
|
+
type: TsType<TBuilder>;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export class TsArrayType<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
|
|
18
|
+
TBuilder,
|
|
19
|
+
TInjects | Injects
|
|
20
|
+
> {
|
|
21
|
+
public readonly: boolean;
|
|
22
|
+
public type: TsType<TBuilder>;
|
|
23
|
+
|
|
24
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
25
|
+
super(options);
|
|
26
|
+
this.readonly = options.readonly ?? false;
|
|
27
|
+
this.type = options.type;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected override onWrite(builder: TBuilder): void {
|
|
31
|
+
if (this.readonly) builder.append('readonly ');
|
|
32
|
+
|
|
33
|
+
builder
|
|
34
|
+
.append(this.inject.beforeType)
|
|
35
|
+
.parenthesize('()', (b) => writeTsNode(b, this.type))
|
|
36
|
+
.append(this.inject.afterType);
|
|
37
|
+
|
|
38
|
+
builder.append('[]');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const createArrayType = <TBuilder extends SourceBuilder>(
|
|
43
|
+
type: Options<TBuilder>['type'],
|
|
44
|
+
options?: Prettify<Omit<Options<TBuilder>, 'type'>>,
|
|
45
|
+
): TsArrayType<TBuilder> => new TsArrayType<TBuilder>({ ...options, type });
|
|
46
|
+
|
|
47
|
+
export const tsArrayType: typeof createArrayType & { write: typeof writeTsNodes } = Object.assign(createArrayType, {
|
|
48
|
+
write: writeTsNodes,
|
|
49
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AppendValue,
|
|
3
|
+
type AstNodeOptions,
|
|
4
|
+
type BasicAppendValue,
|
|
5
|
+
notNullish,
|
|
6
|
+
type Nullable,
|
|
7
|
+
type SourceBuilder,
|
|
8
|
+
} from '@goast/core';
|
|
9
|
+
|
|
10
|
+
import { TsNode } from '../node.js';
|
|
11
|
+
import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
12
|
+
import { type TsGenericParameter, tsGenericParameter } from './generic-parameter.js';
|
|
13
|
+
import { type TsParameter, tsParameter } from './parameter.js';
|
|
14
|
+
import type { TsType } from './types.js';
|
|
15
|
+
|
|
16
|
+
type Injects = 'generics' | 'params' | 'returnType' | 'body';
|
|
17
|
+
|
|
18
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
19
|
+
typeof TsNode<TBuilder, TInjects | Injects>,
|
|
20
|
+
{
|
|
21
|
+
async?: Nullable<boolean>;
|
|
22
|
+
generics?: Nullable<Nullable<TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
|
|
23
|
+
parameters?: Nullable<Nullable<TsParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
|
|
24
|
+
returnType?: Nullable<TsType<TBuilder>>;
|
|
25
|
+
singleExpression?: Nullable<boolean>;
|
|
26
|
+
body?: Nullable<AppendValue<TBuilder>>;
|
|
27
|
+
}
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export class TsArrowFunction<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
|
|
31
|
+
TBuilder,
|
|
32
|
+
TInjects | Injects
|
|
33
|
+
> {
|
|
34
|
+
public async: boolean;
|
|
35
|
+
public generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
36
|
+
public parameters: (TsParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
37
|
+
public returnType: TsType<TBuilder> | null;
|
|
38
|
+
public singleExpression: boolean;
|
|
39
|
+
public body: AppendValue<TBuilder> | null;
|
|
40
|
+
|
|
41
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
42
|
+
super(options);
|
|
43
|
+
this.async = options.async ?? false;
|
|
44
|
+
this.generics = options.generics?.filter(notNullish) ?? [];
|
|
45
|
+
this.parameters = options.parameters?.filter(notNullish) ?? [];
|
|
46
|
+
this.returnType = options.returnType ?? null;
|
|
47
|
+
this.singleExpression = options.singleExpression ?? false;
|
|
48
|
+
this.body = options.body ?? null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected override onWrite(builder: TBuilder): void {
|
|
52
|
+
if (this.async) {
|
|
53
|
+
builder.append('async ');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
builder.append(this.inject.beforeGenerics);
|
|
57
|
+
tsGenericParameter.write(builder, this.generics);
|
|
58
|
+
builder.append(this.inject.afterGenerics);
|
|
59
|
+
|
|
60
|
+
builder.append(this.inject.beforeParams);
|
|
61
|
+
tsParameter.write(builder, this.parameters);
|
|
62
|
+
builder.append(this.inject.afterParams);
|
|
63
|
+
|
|
64
|
+
if (this.returnType) {
|
|
65
|
+
builder.append(': ');
|
|
66
|
+
builder.append(this.inject.beforeReturnType);
|
|
67
|
+
writeTsNode(builder, this.returnType);
|
|
68
|
+
builder.append(this.inject.afterReturnType);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
builder.append(' => ');
|
|
72
|
+
|
|
73
|
+
builder.append(this.inject.beforeBody);
|
|
74
|
+
if (this.singleExpression && this.body) {
|
|
75
|
+
builder.append(this.body);
|
|
76
|
+
} else {
|
|
77
|
+
builder.parenthesize('{}', this.body, { multiline: !!this.body });
|
|
78
|
+
}
|
|
79
|
+
builder.append(this.inject.afterBody);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const createArrowFunction = <TBuilder extends SourceBuilder>(options?: Options<TBuilder>): TsArrowFunction<TBuilder> =>
|
|
84
|
+
new TsArrowFunction<TBuilder>(options ?? {});
|
|
85
|
+
|
|
86
|
+
export const tsArrowFunction: typeof createArrowFunction & { write: typeof writeTsNodes } = Object.assign(
|
|
87
|
+
createArrowFunction,
|
|
88
|
+
{
|
|
89
|
+
write: writeTsNodes,
|
|
90
|
+
},
|
|
91
|
+
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ArrayItem,
|
|
3
|
+
type AstNodeOptions,
|
|
4
|
+
notNullish,
|
|
5
|
+
type Nullable,
|
|
6
|
+
type Prettify,
|
|
7
|
+
type SourceBuilder,
|
|
8
|
+
} from '@goast/core';
|
|
9
|
+
|
|
10
|
+
import { TsNode } from '../node.js';
|
|
11
|
+
import { writeTsNodes } from '../utils/write-ts-nodes.js';
|
|
12
|
+
import { type TsArgument, tsArgument } from './argument.js';
|
|
13
|
+
import type { TsType, TsValue } from './types.js';
|
|
14
|
+
|
|
15
|
+
type Injects = never;
|
|
16
|
+
|
|
17
|
+
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<
|
|
18
|
+
typeof TsNode<TBuilder, TInjects | Injects>,
|
|
19
|
+
{
|
|
20
|
+
path: Nullable<TsType<TBuilder> | TsValue<TBuilder>>[];
|
|
21
|
+
arguments?: Nullable<Nullable<TsArgument<TBuilder> | TsValue<TBuilder>>[]>;
|
|
22
|
+
}
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
export class TsCall<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<
|
|
26
|
+
TBuilder,
|
|
27
|
+
TInjects | Injects
|
|
28
|
+
> {
|
|
29
|
+
public path: (TsType<TBuilder> | TsValue<TBuilder>)[];
|
|
30
|
+
public arguments: (TsArgument<TBuilder> | TsValue<TBuilder>)[] | null;
|
|
31
|
+
|
|
32
|
+
constructor(options: Options<TBuilder, TInjects>) {
|
|
33
|
+
super(options);
|
|
34
|
+
this.path = options.path.filter(notNullish);
|
|
35
|
+
this.arguments = options.arguments?.filter(notNullish) ?? null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected override onWrite(builder: TBuilder): void {
|
|
39
|
+
writeTsNodes(builder, this.path, { separator: '.' });
|
|
40
|
+
|
|
41
|
+
if (this.arguments) {
|
|
42
|
+
tsArgument.write(builder, this.arguments);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const createCall = <TBuilder extends SourceBuilder>(
|
|
48
|
+
path: Options<TBuilder>['path'] | ArrayItem<Options<TBuilder>['path']>,
|
|
49
|
+
args?: Options<TBuilder>['arguments'],
|
|
50
|
+
options?: Prettify<Omit<Options<TBuilder>, 'path' | 'arguments'>>,
|
|
51
|
+
): TsCall<TBuilder> => new TsCall<TBuilder>({ ...options, path: Array.isArray(path) ? path : [path], arguments: args });
|
|
52
|
+
|
|
53
|
+
export const tsCall: typeof createCall & { write: typeof writeTsNodes } = Object.assign(createCall, {
|
|
54
|
+
write: writeTsNodes,
|
|
55
|
+
});
|