@goast/typescript 0.3.5 → 0.3.7-beta1
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/README.md +43 -43
- package/assets/client/angular/angular-service.utils.ts +82 -80
- package/assets/client/angular/request-builder.ts +374 -372
- package/assets/client/fetch/fetch-client.utils.ts +52 -52
- package/assets/client/k6/request-builder.js +411 -411
- package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +260 -258
- package/cjs/lib/ast/nodes/export.js +4 -2
- package/cjs/lib/ast/nodes/reference.js +8 -8
- package/cjs/lib/ast/references/angular.js +1 -1
- package/cjs/lib/ast/references/easy-network-stub.js +4 -2
- package/cjs/lib/file-builder.js +3 -3
- package/cjs/lib/generators/models/model-generator.js +13 -7
- package/cjs/lib/generators/models/models-generator.js +4 -1
- package/cjs/lib/generators/services/angular-services/angular-service-generator.js +10 -10
- package/cjs/lib/generators/services/angular-services/angular-services-generator.js +1 -1
- package/cjs/lib/generators/services/angular-services/refs.js +4 -2
- package/cjs/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
- package/cjs/lib/generators/services/easy-network-stub/easy-network-stubs-generator.js +8 -4
- package/cjs/lib/generators/services/easy-network-stub/refs.js +11 -5
- package/cjs/lib/generators/services/fetch-clients/fetch-client-generator.js +2 -2
- package/cjs/lib/generators/services/fetch-clients/refs.js +2 -2
- package/cjs/lib/generators/services/k6-clients/k6-client-generator.js +6 -6
- package/cjs/lib/import-collection.js +37 -14
- package/esm/lib/ast/nodes/export.js +4 -2
- package/esm/lib/ast/nodes/reference.js +8 -8
- package/esm/lib/ast/references/angular.js +1 -1
- package/esm/lib/ast/references/easy-network-stub.js +4 -2
- package/esm/lib/file-builder.js +3 -3
- package/esm/lib/generators/models/model-generator.js +13 -7
- package/esm/lib/generators/models/models-generator.js +4 -1
- package/esm/lib/generators/services/angular-services/angular-service-generator.js +10 -10
- package/esm/lib/generators/services/angular-services/angular-services-generator.js +1 -1
- package/esm/lib/generators/services/angular-services/refs.js +4 -2
- package/esm/lib/generators/services/easy-network-stub/easy-network-stub-generator.js +9 -9
- package/esm/lib/generators/services/easy-network-stub/easy-network-stubs-generator.js +8 -4
- package/esm/lib/generators/services/easy-network-stub/refs.js +11 -5
- package/esm/lib/generators/services/fetch-clients/fetch-client-generator.js +2 -2
- package/esm/lib/generators/services/fetch-clients/refs.js +2 -2
- package/esm/lib/generators/services/k6-clients/k6-client-generator.js +6 -6
- package/esm/lib/import-collection.js +37 -14
- package/package.json +3 -4
- package/types/lib/ast/nodes/export.d.ts +4 -1
- package/types/lib/ast/nodes/reference.d.ts +18 -6
- package/types/lib/common-results.d.ts +7 -2
- package/types/lib/file-builder.d.ts +2 -2
- package/types/lib/import-collection.d.ts +9 -4
|
@@ -1,258 +1,260 @@
|
|
|
1
|
-
import { EasyNetworkStub
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
* @param
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* })
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
1
|
+
import { EasyNetworkStub } from 'easy-network-stub';
|
|
2
|
+
|
|
3
|
+
import type { HttpMethod, RouteResponseCallback, ErrorResponse } from 'easy-network-stub';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Options for the `EasyNetworkStubWrapper`.
|
|
7
|
+
*/
|
|
8
|
+
export type EasyNetworkStubWrapperOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Delay in milliseconds before responding.
|
|
11
|
+
* @default 0
|
|
12
|
+
*/
|
|
13
|
+
delay: number;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to log requests to the console.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
logRequests: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to log responses to the console.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
logResponses: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to remember requests. Remebered requests can be accessed via the `requests` property.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
rememberRequests: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Function to call when a response is sent.
|
|
31
|
+
* @param response The response that was sent.
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
responseCallback?: (response: unknown) => void;
|
|
35
|
+
/**
|
|
36
|
+
* A prefix to add to the URL in log messages.
|
|
37
|
+
* @default /api/
|
|
38
|
+
*/
|
|
39
|
+
logUrlPrefix: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Represents a request intercepted by the `EasyNetworkStubWrapper`.
|
|
44
|
+
*/
|
|
45
|
+
export type StubRequestItem = {
|
|
46
|
+
/**
|
|
47
|
+
* The HTTP method of the request.
|
|
48
|
+
*/
|
|
49
|
+
method: HttpMethod;
|
|
50
|
+
/**
|
|
51
|
+
* The route of the request.
|
|
52
|
+
*/
|
|
53
|
+
route: string;
|
|
54
|
+
/**
|
|
55
|
+
* The request information provided by `easy-network-stub`.
|
|
56
|
+
*/
|
|
57
|
+
request: StubRequestInfo;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Represents the request information provided by `easy-network-stub`.
|
|
62
|
+
*/
|
|
63
|
+
export type StubRequestInfo<TRoute extends string = string, TBody = unknown> = Parameters<
|
|
64
|
+
RouteResponseCallback<TRoute, TBody>
|
|
65
|
+
>[0];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A strict version of `RouteResponseCallback` that allows for a responder to be passed as the first argument.
|
|
69
|
+
*/
|
|
70
|
+
export type StrictRouteResponseCallback<T, P extends string, R> = (
|
|
71
|
+
respondWith: R,
|
|
72
|
+
...args: Parameters<RouteResponseCallback<P, T>>
|
|
73
|
+
) => ErrorResponse<any> | Promise<ErrorResponse<any>>;
|
|
74
|
+
|
|
75
|
+
type _UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
76
|
+
type __StubResponder<T extends Record<number, unknown>, S> = S extends number
|
|
77
|
+
? [T[S]] extends [never]
|
|
78
|
+
? (statusCode: S) => ErrorResponse<T[S]>
|
|
79
|
+
: (statusCode: S, content: T[S]) => ErrorResponse<T[S]>
|
|
80
|
+
: never;
|
|
81
|
+
type _StubResponder<T extends Record<number, unknown>> = _UnionToIntersection<__StubResponder<T, keyof T>>;
|
|
82
|
+
const untypedResponder = (statusCode: number, content?: unknown) => ({ statusCode, content });
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Gets the responder function typed to a specific set of status codes.
|
|
86
|
+
* @returns The responder function.
|
|
87
|
+
*/
|
|
88
|
+
export function getStubResponder<T extends Record<number, unknown>>(): _StubResponder<T> {
|
|
89
|
+
return untypedResponder as _StubResponder<T>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Wrapper for `EasyNetworkStub` that adds additional functionality.
|
|
94
|
+
*/
|
|
95
|
+
export class EasyNetworkStubWrapper {
|
|
96
|
+
private _requests: StubRequestItem[] = [];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The options for the wrapper.
|
|
100
|
+
*/
|
|
101
|
+
public readonly options: Readonly<EasyNetworkStubWrapperOptions>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The requests that have been intercepted by the wrapper.
|
|
105
|
+
*/
|
|
106
|
+
public get requests(): ReadonlyArray<StubRequestItem> {
|
|
107
|
+
return this._requests;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
constructor(
|
|
111
|
+
public readonly wrappedStub: EasyNetworkStub,
|
|
112
|
+
options?: Partial<EasyNetworkStubWrapperOptions>,
|
|
113
|
+
) {
|
|
114
|
+
this.options = {
|
|
115
|
+
delay: options?.delay ?? 0,
|
|
116
|
+
logRequests: options?.logRequests ?? false,
|
|
117
|
+
logResponses: options?.logResponses ?? false,
|
|
118
|
+
rememberRequests: options?.rememberRequests ?? false,
|
|
119
|
+
responseCallback: options?.responseCallback,
|
|
120
|
+
logUrlPrefix: options?.logUrlPrefix ?? '/api/',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Add a single api stub to your intercepted routes.
|
|
126
|
+
* @param method The http method that should be stubbed
|
|
127
|
+
* @param route The route that should be stubbed. Supports parameters in the form of {name:type}.
|
|
128
|
+
* @param response The callback in which you can process the request and reply with the stub. When a Promise is returned, the stub response will be delayed until it is resolved.
|
|
129
|
+
*/
|
|
130
|
+
public stub<Route extends string>(
|
|
131
|
+
method: HttpMethod,
|
|
132
|
+
route: Route,
|
|
133
|
+
response: RouteResponseCallback<Route, unknown>,
|
|
134
|
+
): void {
|
|
135
|
+
this.wrappedStub.stub<Route>(method, route, async (request) => {
|
|
136
|
+
if (this.options.delay > 0) await sleep(this.options.delay);
|
|
137
|
+
return await this.runRequest(method, route, response, request);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The stub2 method provides a way to set the type of the body that is sent.
|
|
143
|
+
* Due to restrictions in TypeScript (https://github.com/microsoft/TypeScript/issues/10571, https://github.com/Microsoft/TypeScript/pull/26349),
|
|
144
|
+
* We have to hacke a bit here. Calling stub2<T>() will return the stub method with a body of type T.
|
|
145
|
+
*
|
|
146
|
+
* Usage:
|
|
147
|
+
* ```
|
|
148
|
+
* .stub2<MyRequest>()('GET', '/api/test', ({ body }) => {
|
|
149
|
+
* // body is of type MyRequest
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
* @returns The stub method with a body of type T.
|
|
153
|
+
*/
|
|
154
|
+
public stub2<T>(): <Route extends string>(
|
|
155
|
+
method: HttpMethod,
|
|
156
|
+
route: Route,
|
|
157
|
+
response: RouteResponseCallback<Route, T>,
|
|
158
|
+
) => void {
|
|
159
|
+
return <Route extends string>(method: HttpMethod, route: Route, response: RouteResponseCallback<Route, T>) => {
|
|
160
|
+
this.wrappedStub.stub2<T>()<Route>(method, route, async (request) => {
|
|
161
|
+
if (this.options.delay > 0) await sleep(this.options.delay);
|
|
162
|
+
return await this.runRequest(method, route, response, request);
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Reset the stubs and requests.
|
|
169
|
+
*/
|
|
170
|
+
public reset(): void {
|
|
171
|
+
this._requests = [];
|
|
172
|
+
this.wrappedStub['_config'].stubs = [];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private async runRequest<Route extends string, T>(
|
|
176
|
+
method: HttpMethod,
|
|
177
|
+
route: Route,
|
|
178
|
+
response: RouteResponseCallback<Route, T>,
|
|
179
|
+
request: StubRequestInfo<Route, T>,
|
|
180
|
+
): Promise<unknown> {
|
|
181
|
+
if (this.options.rememberRequests) {
|
|
182
|
+
this._requests.push({ method, route, request });
|
|
183
|
+
}
|
|
184
|
+
this.log('request', method, route, request, '#7FFFFF');
|
|
185
|
+
try {
|
|
186
|
+
const r = await response(request);
|
|
187
|
+
this.options.responseCallback?.(r);
|
|
188
|
+
this.log('response', method, route, r, '#7FFF8E');
|
|
189
|
+
return r;
|
|
190
|
+
} catch (error: unknown) {
|
|
191
|
+
this.options.responseCallback?.(error);
|
|
192
|
+
if (isHttpResponse(error) && error.statusCode >= 200 && error.statusCode < 300) {
|
|
193
|
+
this.log('response', method, route, error.content, '#7FFF8E');
|
|
194
|
+
throw error;
|
|
195
|
+
} else {
|
|
196
|
+
const isError = isHttpResponse(error) && error.statusCode >= 400 && error.statusCode < 600;
|
|
197
|
+
this.log('response', method, route, error, isError ? '#FF7F7F' : '7F7F7F');
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private log(type: 'request' | 'response', method: HttpMethod, route: string, data: unknown, color: string) {
|
|
204
|
+
if (type === 'request' && !this.options.logRequests) return;
|
|
205
|
+
if (type === 'response' && !this.options.logResponses) return;
|
|
206
|
+
const typeDisplay = type === 'request' ? ' [req]' : '[resp]';
|
|
207
|
+
const strippedRoute = route.match(/[^?]*(?=\?)?/)?.[0];
|
|
208
|
+
console.log(`%c${typeDisplay} ${method}: ${this.options.logUrlPrefix}${strippedRoute}`, `color:${color};`, data);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Base class for generated easy network stubs.
|
|
214
|
+
*/
|
|
215
|
+
export class EasyNetworkStubBase {
|
|
216
|
+
protected readonly stubWrapper: EasyNetworkStubWrapper;
|
|
217
|
+
protected readonly ownsStubWrapper: boolean;
|
|
218
|
+
|
|
219
|
+
constructor(stub: EasyNetworkStub | EasyNetworkStubWrapper, options?: EasyNetworkStubWrapperOptions) {
|
|
220
|
+
this.stubWrapper = stub instanceof EasyNetworkStubWrapper ? stub : new EasyNetworkStubWrapper(stub, options);
|
|
221
|
+
this.ownsStubWrapper = !(stub instanceof EasyNetworkStubWrapper);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public reset() {
|
|
225
|
+
if (this.ownsStubWrapper) {
|
|
226
|
+
this.stubWrapper.reset();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type EasyNetworkStubGroup<Group, GroupContainer> = Group & {
|
|
232
|
+
(stubActions: (stubs: Group) => void): GroupContainer;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
236
|
+
declare interface GroupType<T> extends Function {
|
|
237
|
+
new (stubWrapper: EasyNetworkStubWrapper): T;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function createEasyNetworkStubGroup<GroupContainer, Group>(
|
|
241
|
+
container: GroupContainer,
|
|
242
|
+
stubWrapper: EasyNetworkStubWrapper,
|
|
243
|
+
groupType: GroupType<Group>,
|
|
244
|
+
): EasyNetworkStubGroup<Group, GroupContainer> {
|
|
245
|
+
const group = new groupType(stubWrapper);
|
|
246
|
+
const groupFn = (stubActions: (stubs: Group) => void) => {
|
|
247
|
+
stubActions(group);
|
|
248
|
+
return container;
|
|
249
|
+
};
|
|
250
|
+
Object.setPrototypeOf(groupFn, groupType.prototype);
|
|
251
|
+
return Object.assign(groupFn, group);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function sleep(ms: number): Promise<void> {
|
|
255
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function isHttpResponse(value: unknown): value is ErrorResponse<unknown> {
|
|
259
|
+
return typeof value === 'object' && value !== null && 'statusCode' in value;
|
|
260
|
+
}
|
|
@@ -6,16 +6,18 @@ const node_1 = require("../node");
|
|
|
6
6
|
const write_ts_nodes_1 = require("../utils/write-ts-nodes");
|
|
7
7
|
class TsExport extends node_1.TsNode {
|
|
8
8
|
constructor(options) {
|
|
9
|
+
var _a;
|
|
9
10
|
super(options);
|
|
10
11
|
this.name = options.name;
|
|
11
12
|
this.filePath = options.filePath;
|
|
13
|
+
this.kind = (_a = options.kind) !== null && _a !== void 0 ? _a : 'export';
|
|
12
14
|
}
|
|
13
15
|
onWrite(builder) {
|
|
14
16
|
if (builder instanceof file_builder_1.TypeScriptFileBuilder) {
|
|
15
|
-
builder.addExport(this.name, this.filePath);
|
|
17
|
+
builder.addExport(this.name, this.filePath, { type: this.kind });
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
|
-
builder.appendLine(
|
|
20
|
+
builder.appendLine(this.kind === 'type-export' ? 'export type' : 'export', ` { ${this.name} } from '${this.filePath}';`);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -42,24 +42,24 @@ TsReference.addImportHandlers = [
|
|
|
42
42
|
},
|
|
43
43
|
];
|
|
44
44
|
const createReference = (name, moduleNameOrfilePath, options) => new TsReference({ ...options, name, moduleNameOrfilePath });
|
|
45
|
-
function _createFactory(name, moduleNameOrfilePath) {
|
|
46
|
-
return Object.assign((options) => createReference(name, moduleNameOrfilePath, options), {
|
|
45
|
+
function _createFactory(name, moduleNameOrfilePath, defaultOptions) {
|
|
46
|
+
return Object.assign((options) => createReference(name, moduleNameOrfilePath, { ...defaultOptions, ...options }), {
|
|
47
47
|
refName: name,
|
|
48
48
|
moduleNameOrfilePath,
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
function createFactory(name, moduleNameOrfilePath) {
|
|
52
|
-
return _createFactory(name, moduleNameOrfilePath);
|
|
51
|
+
function createFactory(name, moduleNameOrfilePath, defaultOptions) {
|
|
52
|
+
return _createFactory(name, moduleNameOrfilePath, defaultOptions);
|
|
53
53
|
}
|
|
54
|
-
function _createGenericFactory(name, moduleNameOrfilePath) {
|
|
55
|
-
return Object.assign((generics, options) => createReference(name, moduleNameOrfilePath, { ...options, generics }), {
|
|
54
|
+
function _createGenericFactory(name, moduleNameOrfilePath, defaultOptions) {
|
|
55
|
+
return Object.assign((generics, options) => createReference(name, moduleNameOrfilePath, { ...defaultOptions, ...options, generics }), {
|
|
56
56
|
refName: name,
|
|
57
57
|
moduleNameOrfilePath,
|
|
58
58
|
infer: () => createReference(name, moduleNameOrfilePath),
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
function createGenericFactory(name, moduleNameOrfilePath) {
|
|
62
|
-
return _createGenericFactory(name, moduleNameOrfilePath);
|
|
61
|
+
function createGenericFactory(name, moduleNameOrfilePath, defaultOptions) {
|
|
62
|
+
return _createGenericFactory(name, moduleNameOrfilePath, defaultOptions);
|
|
63
63
|
}
|
|
64
64
|
exports.tsReference = Object.assign(createReference, {
|
|
65
65
|
factory: createFactory,
|
|
@@ -5,7 +5,7 @@ const reference_1 = require("../nodes/reference");
|
|
|
5
5
|
// @angular/core
|
|
6
6
|
exports.inject = reference_1.tsReference.factory('inject', '@angular/core');
|
|
7
7
|
exports.injectable = reference_1.tsReference.factory('Injectable', '@angular/core');
|
|
8
|
-
exports.provider = reference_1.tsReference.factory('Provider', '@angular/core');
|
|
8
|
+
exports.provider = reference_1.tsReference.factory('Provider', '@angular/core', { importType: 'type-import' });
|
|
9
9
|
// @angular/common/http
|
|
10
10
|
exports.httpClient = reference_1.tsReference.factory('HttpClient', '@angular/common/http');
|
|
11
11
|
exports.httpContext = reference_1.tsReference.factory('HttpContext', '@angular/common/http');
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.errorResponse = exports.routeResponseCallback = exports.httpMethod = exports.easyNetworkStub = void 0;
|
|
4
4
|
const reference_1 = require("../nodes/reference");
|
|
5
5
|
exports.easyNetworkStub = reference_1.tsReference.factory('EasyNetworkStub', 'easy-network-stub');
|
|
6
|
-
exports.httpMethod = reference_1.tsReference.factory('HttpMethod', 'easy-network-stub');
|
|
7
|
-
exports.routeResponseCallback = reference_1.tsReference.genericFactory('RouteResponseCallback', 'easy-network-stub'
|
|
6
|
+
exports.httpMethod = reference_1.tsReference.factory('HttpMethod', 'easy-network-stub', { importType: 'type-import' });
|
|
7
|
+
exports.routeResponseCallback = reference_1.tsReference.genericFactory('RouteResponseCallback', 'easy-network-stub', {
|
|
8
|
+
importType: 'type-import',
|
|
9
|
+
});
|
|
8
10
|
exports.errorResponse = reference_1.tsReference.genericFactory('ErrorResponse', 'easy-network-stub');
|
package/cjs/lib/file-builder.js
CHANGED
|
@@ -28,8 +28,8 @@ class TypeScriptFileBuilder extends core_1.SourceBuilder {
|
|
|
28
28
|
this.imports.addImport(name, moduleNameOrfilePath, options);
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
|
-
addExport(name, filePath) {
|
|
32
|
-
this.imports.addExport(name, filePath);
|
|
31
|
+
addExport(name, filePath, options) {
|
|
32
|
+
this.imports.addExport(name, filePath, options);
|
|
33
33
|
return this;
|
|
34
34
|
}
|
|
35
35
|
clear() {
|
|
@@ -63,7 +63,7 @@ class TypeScriptFileBuilder extends core_1.SourceBuilder {
|
|
|
63
63
|
appendModelUsage(type, options) {
|
|
64
64
|
this.append(type.component);
|
|
65
65
|
for (const i of type.imports) {
|
|
66
|
-
this.addImport(i.name, i.modulePath, options);
|
|
66
|
+
this.addImport(i.name, i.modulePath, { ...i, ...options });
|
|
67
67
|
}
|
|
68
68
|
return this;
|
|
69
69
|
}
|