@goast/typescript 0.6.3-beta.1 → 0.7.0
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/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +9 -7
- package/esm/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +3 -0
- package/esm/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts.map +1 -1
- package/esm/src/generators/services/easy-network-stub/easy-network-stub-generator.js +28 -1
- package/esm/src/generators/services/easy-network-stub/refs.d.ts +1 -0
- package/esm/src/generators/services/easy-network-stub/refs.d.ts.map +1 -1
- package/esm/src/generators/services/easy-network-stub/refs.js +1 -0
- package/package.json +2 -2
- package/script/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +3 -0
- package/script/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts.map +1 -1
- package/script/src/generators/services/easy-network-stub/easy-network-stub-generator.js +28 -1
- package/script/src/generators/services/easy-network-stub/refs.d.ts +1 -0
- package/script/src/generators/services/easy-network-stub/refs.d.ts.map +1 -1
- package/script/src/generators/services/easy-network-stub/refs.js +1 -0
- 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 +137 -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 +481 -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 +414 -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 +289 -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 +47 -0
- package/src/src/generators/services/fetch-clients/fetch-client-generator.ts +285 -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 +474 -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
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Marc Schmidt
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Marc Schmidt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EasyNetworkStub, ErrorResponse, HttpMethod, RouteResponseCallback } from 'easy-network-stub';
|
|
1
|
+
import type { EasyNetworkStub, ErrorResponse, HttpMethod, RouteResponseCallback, StubHandle } from 'easy-network-stub';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Options for the `EasyNetworkStubWrapper`.
|
|
@@ -128,8 +128,8 @@ export class EasyNetworkStubWrapper {
|
|
|
128
128
|
method: HttpMethod,
|
|
129
129
|
route: Route,
|
|
130
130
|
response: RouteResponseCallback<Route, unknown>,
|
|
131
|
-
):
|
|
132
|
-
this.wrappedStub.stub<Route>(method, route, async (request) => {
|
|
131
|
+
): StubHandle {
|
|
132
|
+
return this.wrappedStub.stub<Route>(method, route, async (request) => {
|
|
133
133
|
if (this.options.delay > 0) await sleep(this.options.delay);
|
|
134
134
|
return await this.runRequest(method, route, response, request);
|
|
135
135
|
});
|
|
@@ -152,9 +152,9 @@ export class EasyNetworkStubWrapper {
|
|
|
152
152
|
method: HttpMethod,
|
|
153
153
|
route: Route,
|
|
154
154
|
response: RouteResponseCallback<Route, T>,
|
|
155
|
-
) =>
|
|
155
|
+
) => StubHandle {
|
|
156
156
|
return <Route extends string>(method: HttpMethod, route: Route, response: RouteResponseCallback<Route, T>) => {
|
|
157
|
-
this.wrappedStub.stub2<T>()<Route>(method, route, async (request) => {
|
|
157
|
+
return this.wrappedStub.stub2<T>()<Route>(method, route, async (request) => {
|
|
158
158
|
if (this.options.delay > 0) await sleep(this.options.delay);
|
|
159
159
|
return await this.runRequest(method, route, response, request);
|
|
160
160
|
});
|
|
@@ -166,7 +166,7 @@ export class EasyNetworkStubWrapper {
|
|
|
166
166
|
*/
|
|
167
167
|
public reset(): void {
|
|
168
168
|
this._requests = [];
|
|
169
|
-
this.wrappedStub
|
|
169
|
+
this.wrappedStub.reset();
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
private async runRequest<Route extends string, T>(
|
|
@@ -219,7 +219,9 @@ export class EasyNetworkStubBase {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
public reset() {
|
|
222
|
-
this.
|
|
222
|
+
if (this.ownsStubWrapper) {
|
|
223
|
+
this.stubWrapper.reset();
|
|
224
|
+
}
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
|
|
@@ -23,8 +23,11 @@ export declare class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScrip
|
|
|
23
23
|
protected getStubClassName(ctx: Context): string;
|
|
24
24
|
protected getEndpointPathPropertyName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
25
25
|
protected getEndpointRequestsFieldName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
26
|
+
protected getEndpointStubHandleFieldName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
26
27
|
protected getEndpointRequestsPropertyName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
27
28
|
protected getEndpointStubMethodName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
29
|
+
protected getEndpointUnregisterMethodName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
30
|
+
protected getEndpointUnregisterMethod(ctx: Context, endpoint: ApiEndpoint): ts.Method<Builder>;
|
|
28
31
|
protected getStubRoute(ctx: Context, endpoint: ApiEndpoint): string;
|
|
29
32
|
protected getEndpointStatusCodes(ctx: Context, endpoint: ApiEndpoint): Record<number, ts.Type<Builder>>;
|
|
30
33
|
protected getSchemaType(ctx: Context, schema: ApiSchema | undefined, fallback?: ts.Type<Builder>): ts.Type<Builder>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easy-network-stub-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EAIrB,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,yCAAyC,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AAEvH,KAAK,OAAO,GAAG,yCAAyC,CAAC;AACzD,KAAK,MAAM,GAAG,wCAAwC,CAAC;AACvD,KAAK,OAAO,GAAG,qBAAqB,CAAC;AAErC,MAAM,WAAW,kCAAkC,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACjF,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;CAC/C;AAED,qBAAa,yCAA0C,SAAQ,uBAAuB,CAAC,OAAO,EAAE,MAAM,CACpG,YAAW,kCAAkC;IACtC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC;IAwBnD,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAOrE,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;IAgBzF,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"easy-network-stub-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts"],"names":[],"mappings":"AAE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AS,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;CAKpH"}
|
|
@@ -55,6 +55,11 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
|
|
|
55
55
|
value: ts.tuple([]),
|
|
56
56
|
})),
|
|
57
57
|
'\n',
|
|
58
|
+
...ctx.service.endpoints.map((endpoint) => ts.property(this.getEndpointStubHandleFieldName(ctx, endpoint), {
|
|
59
|
+
accessModifier: 'private',
|
|
60
|
+
type: s `${ctx.refs.stubHandle()} | undefined`,
|
|
61
|
+
})),
|
|
62
|
+
'\n',
|
|
58
63
|
...ctx.service.endpoints.map((endpoint) => ts.property(this.getEndpointRequestsPropertyName(ctx, endpoint), {
|
|
59
64
|
readonly: true,
|
|
60
65
|
accessModifier: 'public',
|
|
@@ -64,11 +69,13 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
|
|
|
64
69
|
}),
|
|
65
70
|
})),
|
|
66
71
|
...ctx.service.endpoints.map((endpoint) => this.getEndpointStubMethod(ctx, endpoint)),
|
|
72
|
+
...ctx.service.endpoints.map((endpoint) => this.getEndpointUnregisterMethod(ctx, endpoint)),
|
|
67
73
|
ts.method('reset', {
|
|
68
74
|
accessModifier: 'public',
|
|
69
75
|
override: true,
|
|
70
76
|
returnType: ts.refs.void_(),
|
|
71
77
|
body: appendValueGroup([
|
|
78
|
+
...ctx.service.endpoints.map((endpoint) => `this.${this.getEndpointStubHandleFieldName(ctx, endpoint)} = undefined;`),
|
|
72
79
|
...ctx.service.endpoints.map((endpoint) => `this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.length = 0;`),
|
|
73
80
|
'super.reset();',
|
|
74
81
|
], '\n'),
|
|
@@ -99,7 +106,11 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
|
|
|
99
106
|
],
|
|
100
107
|
returnType: 'this',
|
|
101
108
|
body: appendValueGroup([
|
|
102
|
-
s `this.
|
|
109
|
+
s `if (this.${this.getEndpointStubHandleFieldName(ctx, endpoint)}) {${s.indent `
|
|
110
|
+
throw new Error('${this.getEndpointStubMethodName(ctx, endpoint)} has already been called. Call ${this.getEndpointUnregisterMethodName(ctx, endpoint)}() or reset() before stubbing again.');`}
|
|
111
|
+
}`,
|
|
112
|
+
s `this.${this.getEndpointStubHandleFieldName(ctx, endpoint)} = this.stubWrapper.stub2<${requestType}>()(${s
|
|
113
|
+
.indent `
|
|
103
114
|
${ts.string(endpoint.method.toUpperCase())},
|
|
104
115
|
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
105
116
|
async (request) => {${s.indent `
|
|
@@ -129,12 +140,28 @@ export class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScriptFileGen
|
|
|
129
140
|
getEndpointRequestsFieldName(ctx, endpoint) {
|
|
130
141
|
return toCasing(endpoint.name + '_Requests', adjustCasing(ctx.config.propertyNameCasing, { prefix: '_' }));
|
|
131
142
|
}
|
|
143
|
+
getEndpointStubHandleFieldName(ctx, endpoint) {
|
|
144
|
+
return toCasing('stub_' + endpoint.name + '_Handle', adjustCasing(ctx.config.propertyNameCasing, { prefix: '_' }));
|
|
145
|
+
}
|
|
132
146
|
getEndpointRequestsPropertyName(ctx, endpoint) {
|
|
133
147
|
return toCasing(endpoint.name + '_Requests', ctx.config.propertyNameCasing);
|
|
134
148
|
}
|
|
135
149
|
getEndpointStubMethodName(ctx, endpoint) {
|
|
136
150
|
return toCasing('stub_' + endpoint.name, ctx.config.functionNameCasing);
|
|
137
151
|
}
|
|
152
|
+
getEndpointUnregisterMethodName(ctx, endpoint) {
|
|
153
|
+
return toCasing('unregister_stub_' + endpoint.name, ctx.config.functionNameCasing);
|
|
154
|
+
}
|
|
155
|
+
getEndpointUnregisterMethod(ctx, endpoint) {
|
|
156
|
+
return ts.method(this.getEndpointUnregisterMethodName(ctx, endpoint), {
|
|
157
|
+
accessModifier: 'public',
|
|
158
|
+
returnType: ts.refs.void_(),
|
|
159
|
+
body: appendValueGroup([
|
|
160
|
+
`this.${this.getEndpointStubHandleFieldName(ctx, endpoint)}?.unregister();`,
|
|
161
|
+
`this.${this.getEndpointStubHandleFieldName(ctx, endpoint)} = undefined;`,
|
|
162
|
+
], '\n'),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
138
165
|
getStubRoute(ctx, endpoint) {
|
|
139
166
|
var _a, _b;
|
|
140
167
|
let path = endpoint.path;
|
|
@@ -10,5 +10,6 @@ export declare function getReferenceFactories(options: TypeScriptEasyNetworkStub
|
|
|
10
10
|
easyNetworkStubBase: ts.ModuleReferenceFactory;
|
|
11
11
|
easyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
|
|
12
12
|
createEasyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
|
|
13
|
+
stubHandle: ts.ModuleReferenceFactory;
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=refs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAChE,UAAU,EAAE,EAAE,CAAC,sBAAsB,CAAC;CACvC,CA6BA"}
|
|
@@ -23,5 +23,6 @@ export function getReferenceFactories(options) {
|
|
|
23
23
|
importType: 'type-import',
|
|
24
24
|
}),
|
|
25
25
|
createEasyNetworkStubGroup: ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
|
|
26
|
+
stubHandle: ts.reference.factory('StubHandle', 'easy-network-stub', { importType: 'type-import' }),
|
|
26
27
|
};
|
|
27
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/typescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Provides gOAst generators for generating TypeScript code from OpenAPI specifications.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Marc Schmidt (MaSch0212)",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"tslib": "^2.6.2",
|
|
27
27
|
"fs-extra": "^11.3.3",
|
|
28
|
-
"@goast/core": "0.5.0
|
|
28
|
+
"@goast/core": "0.5.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.9.0",
|
|
@@ -23,8 +23,11 @@ export declare class DefaultTypeScriptEasyNetworkStubGenerator extends TypeScrip
|
|
|
23
23
|
protected getStubClassName(ctx: Context): string;
|
|
24
24
|
protected getEndpointPathPropertyName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
25
25
|
protected getEndpointRequestsFieldName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
26
|
+
protected getEndpointStubHandleFieldName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
26
27
|
protected getEndpointRequestsPropertyName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
27
28
|
protected getEndpointStubMethodName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
29
|
+
protected getEndpointUnregisterMethodName(ctx: Context, endpoint: ApiEndpoint): string;
|
|
30
|
+
protected getEndpointUnregisterMethod(ctx: Context, endpoint: ApiEndpoint): ts.Method<Builder>;
|
|
28
31
|
protected getStubRoute(ctx: Context, endpoint: ApiEndpoint): string;
|
|
29
32
|
protected getEndpointStatusCodes(ctx: Context, endpoint: ApiEndpoint): Record<number, ts.Type<Builder>>;
|
|
30
33
|
protected getSchemaType(ctx: Context, schema: ApiSchema | undefined, fallback?: ts.Type<Builder>): ts.Type<Builder>;
|
package/script/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easy-network-stub-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EAIrB,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,yCAAyC,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AAEvH,KAAK,OAAO,GAAG,yCAAyC,CAAC;AACzD,KAAK,MAAM,GAAG,wCAAwC,CAAC;AACvD,KAAK,OAAO,GAAG,qBAAqB,CAAC;AAErC,MAAM,WAAW,kCAAkC,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACjF,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;CAC/C;AAED,qBAAa,yCAA0C,SAAQ,uBAAuB,CAAC,OAAO,EAAE,MAAM,CACpG,YAAW,kCAAkC;IACtC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC;IAwBnD,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAOrE,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;IAgBzF,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"easy-network-stub-generator.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/easy-network-stub-generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EAIrB,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,yCAAyC,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AAEvH,KAAK,OAAO,GAAG,yCAAyC,CAAC;AACzD,KAAK,MAAM,GAAG,wCAAwC,CAAC;AACvD,KAAK,OAAO,GAAG,qBAAqB,CAAC;AAErC,MAAM,WAAW,kCAAkC,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM;IACjF,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;CAC/C;AAED,qBAAa,yCAA0C,SAAQ,uBAAuB,CAAC,OAAO,EAAE,MAAM,CACpG,YAAW,kCAAkC;IACtC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC;IAwBnD,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAOrE,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;IAgBzF,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,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AAS,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,MAAM;IAyBnE,SAAS,CAAC,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAYvG,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;CAKpH"}
|
|
@@ -58,6 +58,11 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_js_1.Type
|
|
|
58
58
|
value: index_js_1.ts.tuple([]),
|
|
59
59
|
})),
|
|
60
60
|
'\n',
|
|
61
|
+
...ctx.service.endpoints.map((endpoint) => index_js_1.ts.property(this.getEndpointStubHandleFieldName(ctx, endpoint), {
|
|
62
|
+
accessModifier: 'private',
|
|
63
|
+
type: (0, core_1.builderTemplate) `${ctx.refs.stubHandle()} | undefined`,
|
|
64
|
+
})),
|
|
65
|
+
'\n',
|
|
61
66
|
...ctx.service.endpoints.map((endpoint) => index_js_1.ts.property(this.getEndpointRequestsPropertyName(ctx, endpoint), {
|
|
62
67
|
readonly: true,
|
|
63
68
|
accessModifier: 'public',
|
|
@@ -67,11 +72,13 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_js_1.Type
|
|
|
67
72
|
}),
|
|
68
73
|
})),
|
|
69
74
|
...ctx.service.endpoints.map((endpoint) => this.getEndpointStubMethod(ctx, endpoint)),
|
|
75
|
+
...ctx.service.endpoints.map((endpoint) => this.getEndpointUnregisterMethod(ctx, endpoint)),
|
|
70
76
|
index_js_1.ts.method('reset', {
|
|
71
77
|
accessModifier: 'public',
|
|
72
78
|
override: true,
|
|
73
79
|
returnType: index_js_1.ts.refs.void_(),
|
|
74
80
|
body: (0, core_1.appendValueGroup)([
|
|
81
|
+
...ctx.service.endpoints.map((endpoint) => `this.${this.getEndpointStubHandleFieldName(ctx, endpoint)} = undefined;`),
|
|
75
82
|
...ctx.service.endpoints.map((endpoint) => `this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.length = 0;`),
|
|
76
83
|
'super.reset();',
|
|
77
84
|
], '\n'),
|
|
@@ -102,7 +109,11 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_js_1.Type
|
|
|
102
109
|
],
|
|
103
110
|
returnType: 'this',
|
|
104
111
|
body: (0, core_1.appendValueGroup)([
|
|
105
|
-
(0, core_1.builderTemplate) `this.
|
|
112
|
+
(0, core_1.builderTemplate) `if (this.${this.getEndpointStubHandleFieldName(ctx, endpoint)}) {${core_1.builderTemplate.indent `
|
|
113
|
+
throw new Error('${this.getEndpointStubMethodName(ctx, endpoint)} has already been called. Call ${this.getEndpointUnregisterMethodName(ctx, endpoint)}() or reset() before stubbing again.');`}
|
|
114
|
+
}`,
|
|
115
|
+
(0, core_1.builderTemplate) `this.${this.getEndpointStubHandleFieldName(ctx, endpoint)} = this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate
|
|
116
|
+
.indent `
|
|
106
117
|
${index_js_1.ts.string(endpoint.method.toUpperCase())},
|
|
107
118
|
${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
|
|
108
119
|
async (request) => {${core_1.builderTemplate.indent `
|
|
@@ -132,12 +143,28 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_js_1.Type
|
|
|
132
143
|
getEndpointRequestsFieldName(ctx, endpoint) {
|
|
133
144
|
return (0, core_1.toCasing)(endpoint.name + '_Requests', (0, core_1.adjustCasing)(ctx.config.propertyNameCasing, { prefix: '_' }));
|
|
134
145
|
}
|
|
146
|
+
getEndpointStubHandleFieldName(ctx, endpoint) {
|
|
147
|
+
return (0, core_1.toCasing)('stub_' + endpoint.name + '_Handle', (0, core_1.adjustCasing)(ctx.config.propertyNameCasing, { prefix: '_' }));
|
|
148
|
+
}
|
|
135
149
|
getEndpointRequestsPropertyName(ctx, endpoint) {
|
|
136
150
|
return (0, core_1.toCasing)(endpoint.name + '_Requests', ctx.config.propertyNameCasing);
|
|
137
151
|
}
|
|
138
152
|
getEndpointStubMethodName(ctx, endpoint) {
|
|
139
153
|
return (0, core_1.toCasing)('stub_' + endpoint.name, ctx.config.functionNameCasing);
|
|
140
154
|
}
|
|
155
|
+
getEndpointUnregisterMethodName(ctx, endpoint) {
|
|
156
|
+
return (0, core_1.toCasing)('unregister_stub_' + endpoint.name, ctx.config.functionNameCasing);
|
|
157
|
+
}
|
|
158
|
+
getEndpointUnregisterMethod(ctx, endpoint) {
|
|
159
|
+
return index_js_1.ts.method(this.getEndpointUnregisterMethodName(ctx, endpoint), {
|
|
160
|
+
accessModifier: 'public',
|
|
161
|
+
returnType: index_js_1.ts.refs.void_(),
|
|
162
|
+
body: (0, core_1.appendValueGroup)([
|
|
163
|
+
`this.${this.getEndpointStubHandleFieldName(ctx, endpoint)}?.unregister();`,
|
|
164
|
+
`this.${this.getEndpointStubHandleFieldName(ctx, endpoint)} = undefined;`,
|
|
165
|
+
], '\n'),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
141
168
|
getStubRoute(ctx, endpoint) {
|
|
142
169
|
var _a, _b;
|
|
143
170
|
let path = endpoint.path;
|
|
@@ -10,5 +10,6 @@ export declare function getReferenceFactories(options: TypeScriptEasyNetworkStub
|
|
|
10
10
|
easyNetworkStubBase: ts.ModuleReferenceFactory;
|
|
11
11
|
easyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
|
|
12
12
|
createEasyNetworkStubGroup: ts.GenericModuleReferenceFactory<2>;
|
|
13
|
+
stubHandle: ts.ModuleReferenceFactory;
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=refs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../../../../src/src/generators/services/easy-network-stub/refs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,KAAK,EAAE,yCAAyC,EAAE,MAAM,aAAa,CAAC;AAG7E,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,yCAAyC,GAAG;IACzF,6BAA6B,EAAE,EAAE,CAAC,sBAAsB,CAAC;IACzD,eAAe,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC3C,eAAe,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACrD,2BAA2B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACjE,gBAAgB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IACtD,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAClD,mBAAmB,EAAE,EAAE,CAAC,sBAAsB,CAAC;IAC/C,oBAAoB,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAC1D,0BAA0B,EAAE,EAAE,CAAC,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAChE,UAAU,EAAE,EAAE,CAAC,sBAAsB,CAAC;CACvC,CA6BA"}
|
|
@@ -26,5 +26,6 @@ function getReferenceFactories(options) {
|
|
|
26
26
|
importType: 'type-import',
|
|
27
27
|
}),
|
|
28
28
|
createEasyNetworkStubGroup: index_js_1.ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
|
|
29
|
+
stubHandle: index_js_1.ts.reference.factory('StubHandle', 'easy-network-stub', { importType: 'type-import' }),
|
|
29
30
|
};
|
|
30
31
|
}
|
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
|
+
);
|