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