@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
@@ -18,14 +18,16 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
18
18
  options: ctx.config,
19
19
  generator: (b) => b.append(fileContent),
20
20
  });
21
+ const exports = fileContent.values.filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x);
22
+ const isType = exports.find((x) => x.name === name) instanceof ast_1.ts.TypeAlias;
21
23
  return {
22
24
  component: name,
23
25
  filePath,
24
- imports: [{ kind: 'file', name, modulePath: filePath, type: 'import' }],
25
- additionalExports: fileContent.values
26
- .filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x)
26
+ imports: [{ kind: 'file', name, modulePath: filePath, type: 'type-import' }],
27
+ additionalExports: exports
27
28
  .filter((x) => x.name !== name)
28
- .map((x) => x.name),
29
+ .map((x) => ({ name: x.name, type: x instanceof ast_1.ts.TypeAlias ? 'type-export' : 'export' })),
30
+ kind: isType ? 'type' : 'interface',
29
31
  };
30
32
  }
31
33
  else {
@@ -33,7 +35,7 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
33
35
  builder.append(this.getType(ctx, ctx.schema));
34
36
  const imports = builder.imports.imports;
35
37
  builder.imports.clear();
36
- return { component: builder.toString(false), imports };
38
+ return { component: builder.toString(false), imports, kind: 'unknown' };
37
39
  }
38
40
  }
39
41
  getFileContent(ctx) {
@@ -158,13 +160,17 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
158
160
  return this.getAnyType(ctx);
159
161
  schema = (0, core_1.getSchemaReference)(schema, ['description']);
160
162
  if ((options === null || options === void 0 ? void 0 : options.useBaseType) && ctx.schema.inheritedSchemas.some((x) => x.id === schema.id)) {
161
- return ast_1.ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema));
163
+ return ast_1.ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema), {
164
+ importType: 'type-import',
165
+ });
162
166
  }
163
167
  if (!(options === null || options === void 0 ? void 0 : options.skipSchemas) && this.shouldGenerateTypeDeclaration(ctx, schema)) {
164
168
  if (schema.id === ctx.schema.id) {
165
169
  return null;
166
170
  }
167
- return ast_1.ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema));
171
+ return ast_1.ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema), {
172
+ importType: 'type-import',
173
+ });
168
174
  }
169
175
  if (schema.enum) {
170
176
  return ast_1.ts.unionType(schema.enum.map((x) => ast_1.ts.toNode(x)));
@@ -57,7 +57,10 @@ class TypeScriptModelsGenerator extends core_1.OpenApiSchemasGenerationProviderB
57
57
  const { filePath } = x;
58
58
  if (!filePath)
59
59
  return [];
60
- return [ast_1.ts.export(x.component, filePath), ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => ast_1.ts.export(e, filePath))) !== null && _b !== void 0 ? _b : [])];
60
+ return [
61
+ ast_1.ts.export(x.component, filePath, { kind: x.kind === 'type' ? 'type-export' : 'export' }),
62
+ ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => typeof e === 'string' ? ast_1.ts.export(e, filePath) : ast_1.ts.export(e.name, filePath, { kind: e.type }))) !== null && _b !== void 0 ? _b : []),
63
+ ];
61
64
  }));
62
65
  }
63
66
  }
@@ -187,7 +187,7 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
187
187
  var _a, _b, _c, _d;
188
188
  const hasParams = this.hasEndpointParams(ctx, endpoint);
189
189
  const paramsOptional = !endpoint.parameters.some((p) => p.required) && !((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.required);
190
- const responseModelType = ast_1.ts.reference(this.getResponseModelName(ctx, endpoint), this.getResponseModelFilePath(ctx));
190
+ const responseModelType = ast_1.ts.reference(this.getResponseModelName(ctx, endpoint), this.getResponseModelFilePath(ctx), { importType: 'type-import' });
191
191
  const returnType = ctx.refs.abortablePromise([responseModelType]);
192
192
  const accept = (_d = (_c = (_b = this.getEndpointSuccessResponse(ctx, endpoint)) === null || _b === void 0 ? void 0 : _b.contentOptions[0]) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : '*/*';
193
193
  const responseType = this.contentTypeToResponseType(accept);
@@ -231,13 +231,13 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
231
231
  }
232
232
  : null,
233
233
  '',
234
- (0, core_1.builderTemplate) `return ${ctx.refs.waitForResponse([responseModelType])}(${core_1.builderTemplate.indent `
235
- this.http.request(rb.build({${core_1.builderTemplate.indent `
236
- responseType: ${ast_1.ts.string(responseType)},
237
- accept: ${ast_1.ts.string(accept)},
238
- context,`}
239
- })),
240
- {${core_1.builderTemplate.indent `
234
+ (0, core_1.builderTemplate) `return ${ctx.refs.waitForResponse([responseModelType])}(${core_1.builderTemplate.indent `
235
+ this.http.request(rb.build({${core_1.builderTemplate.indent `
236
+ responseType: ${ast_1.ts.string(responseType)},
237
+ accept: ${ast_1.ts.string(accept)},
238
+ context,`}
239
+ })),
240
+ {${core_1.builderTemplate.indent `
241
241
  errorResponseTypes: ${ast_1.ts.object({
242
242
  members: [
243
243
  ...Object.entries(this.getEndpointStatusCodes(ctx, endpoint))
@@ -246,8 +246,8 @@ class DefaultTypeScriptAngularServiceGenerator extends file_generator_1.TypeScri
246
246
  return ast_1.ts.property(key, { value: ast_1.ts.string(value.parser) });
247
247
  }),
248
248
  ],
249
- })}`}
250
- }`}
249
+ })}`}
250
+ }`}
251
251
  )`,
252
252
  ], '\n'),
253
253
  });
@@ -199,7 +199,7 @@ class TypeScriptAngularServicesGenerator extends core_1.OpenApiServicesGeneratio
199
199
  getResponseModelsIndexFileContent(ctx) {
200
200
  return (0, core_1.appendValueGroup)(Object.values(ctx.output.typescript.services)
201
201
  .flatMap((x) => Object.values(x.responseModels))
202
- .map((x) => ast_1.ts.export(x.component, x.filePath)));
202
+ .map((x) => ast_1.ts.export(x.component, x.filePath, { kind: 'type-export' })));
203
203
  }
204
204
  getServicesIndexFilePath(ctx) {
205
205
  return ctx.config.servicesIndexFile ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.servicesIndexFile) : null;
@@ -10,7 +10,7 @@ function getReferenceFactories(options) {
10
10
  const utilsDirPath = (0, path_1.resolve)(options.outputDir, options.utilsDir);
11
11
  return {
12
12
  // angular-service.utils.ts
13
- abortablePromise: ast_1.ts.reference.genericFactory('AbortablePromise', (0, path_1.join)(utilsDirPath, 'angular-service.utils.ts')),
13
+ abortablePromise: ast_1.ts.reference.genericFactory('AbortablePromise', (0, path_1.join)(utilsDirPath, 'angular-service.utils.ts'), { importType: 'type-import' }),
14
14
  waitForResponse: ast_1.ts.reference.genericFactory('waitForResponse', (0, path_1.join)(utilsDirPath, 'angular-service.utils.ts')),
15
15
  // request-builder.ts
16
16
  requestBuilder: ast_1.ts.reference.factory('RequestBuilder', (0, path_1.join)(utilsDirPath, 'request-builder.ts')),
@@ -19,7 +19,9 @@ function getReferenceFactories(options) {
19
19
  // api-base-service.ts - generated in angular-service-generator.ts
20
20
  apiBaseService: ast_1.ts.reference.factory('ApiBaseService', (0, path_1.join)(utilsDirPath, 'api-base-service.ts')),
21
21
  // http-status-code.ts - generated in angular-services-generator.ts
22
- httpStatusCode: ast_1.ts.reference.factory('HttpStatusCode', (0, path_1.join)(utilsDirPath, 'http-status-code.ts')),
22
+ httpStatusCode: ast_1.ts.reference.factory('HttpStatusCode', (0, path_1.join)(utilsDirPath, 'http-status-code.ts'), {
23
+ importType: 'type-import',
24
+ }),
23
25
  // provide.ts - generated in angular-services-generator.ts
24
26
  provide: ast_1.ts.reference.factory((0, core_1.toCasing)(`provide_${(_b = options.domainName) !== null && _b !== void 0 ? _b : ''}_Api`, options.functionNameCasing), (0, path_1.join)(utilsDirPath, 'provide.ts')),
25
27
  };
@@ -97,15 +97,15 @@ class DefaultTypeScriptEasyNetworkStubGenerator extends file_generator_1.TypeScr
97
97
  ],
98
98
  returnType: 'this',
99
99
  body: (0, core_1.appendValueGroup)([
100
- (0, core_1.builderTemplate) `this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate.indent `
101
- ${ast_1.ts.string(endpoint.method.toUpperCase())},
102
- ${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
103
- async (request) => {${core_1.builderTemplate.indent `
104
- if (this.stubWrapper.options.rememberRequests) {${core_1.builderTemplate.indent `
105
- this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
106
- }
107
- throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
108
- }`}
100
+ (0, core_1.builderTemplate) `this.stubWrapper.stub2<${requestType}>()(${core_1.builderTemplate.indent `
101
+ ${ast_1.ts.string(endpoint.method.toUpperCase())},
102
+ ${this.getStubClassName(ctx)}.${this.getEndpointPathPropertyName(ctx, endpoint)},
103
+ async (request) => {${core_1.builderTemplate.indent `
104
+ if (this.stubWrapper.options.rememberRequests) {${core_1.builderTemplate.indent `
105
+ this.${this.getEndpointRequestsFieldName(ctx, endpoint)}.push(request);`}
106
+ }
107
+ throw await response(${this.getResponderVariableName(ctx, endpoint)}, request);`}
108
+ }`}
109
109
  );`,
110
110
  'return this;',
111
111
  ], '\n'),
@@ -82,13 +82,15 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
82
82
  ...Object.entries(ctx.output.typescript.stubs).map(([id, x]) => ast_1.ts.property((0, core_1.toCasing)(serviceNames[id], fieldCasing), {
83
83
  accessModifier: 'private',
84
84
  optional: true,
85
- type: ctx.refs.easyNetworkStubGroup([ast_1.ts.reference(x.component, x.filePath), 'this']),
85
+ type: ctx.refs.easyNetworkStubGroup([ast_1.ts.reference(x.component, x.filePath), 'this'], {
86
+ importType: 'type-import',
87
+ }),
86
88
  })),
87
89
  ast_1.ts.constructor({
88
90
  parameters: [
89
91
  ast_1.ts.constructorParameter('stub', { type: ast_1.ts.refs.easyNetworkStub.easyNetworkStub() }),
90
92
  ast_1.ts.constructorParameter('options', {
91
- type: ast_1.ts.refs.partial([ctx.refs.easyNetworkStubWrapperOptions()]),
93
+ type: ast_1.ts.refs.partial([ctx.refs.easyNetworkStubWrapperOptions()], { importType: 'type-import' }),
92
94
  optional: true,
93
95
  }),
94
96
  ],
@@ -96,14 +98,16 @@ class TypeScriptEasyNetworkStubsGenerator extends core_1.OpenApiServicesGenerati
96
98
  }),
97
99
  ast_1.ts.property('requests', {
98
100
  accessModifier: 'public',
99
- type: ast_1.ts.arrayType(ctx.refs.stubRequestItem(), { readonly: true }),
101
+ type: ast_1.ts.arrayType(ctx.refs.stubRequestItem({ importType: 'type-import' }), { readonly: true }),
100
102
  get: ast_1.ts.property.getter({
101
103
  body: (0, core_1.appendValueGroup)(['return this._stubWrapper.requests;'], '\n'),
102
104
  }),
103
105
  }),
104
106
  ...Object.entries(ctx.output.typescript.stubs).map(([id, x]) => ast_1.ts.property((0, core_1.toCasing)(serviceNames[id], ctx.config.propertyNameCasing), {
105
107
  accessModifier: 'public',
106
- type: ctx.refs.easyNetworkStubGroup([ast_1.ts.reference(x.component, x.filePath), 'this']),
108
+ type: ctx.refs.easyNetworkStubGroup([ast_1.ts.reference(x.component, x.filePath), 'this'], {
109
+ importType: 'type-import',
110
+ }),
107
111
  get: ast_1.ts.property.getter({
108
112
  body: (0, core_1.appendValueGroup)([
109
113
  (0, core_1.builderTemplate) `return this.${(0, core_1.toCasing)(serviceNames[id], fieldCasing)} ??= ${ctx.refs.createEasyNetworkStubGroup.infer()}(this, this._stubWrapper, ${ast_1.ts.reference(x.component, x.filePath)});`,
@@ -9,14 +9,20 @@ function getReferenceFactories(options) {
9
9
  const easyNetworkStubUtilsPath = (0, path_1.join)(utilsDirPath, 'easy-network-stub.utils.ts');
10
10
  return {
11
11
  // easy-network-stub.utils.ts
12
- easyNetworkStubWrapperOptions: ast_1.ts.reference.factory('EasyNetworkStubWrapperOptions', easyNetworkStubUtilsPath),
13
- stubRequestItem: ast_1.ts.reference.factory('StubRequestItem', easyNetworkStubUtilsPath),
14
- stubRequestInfo: ast_1.ts.reference.genericFactory('StubRequestInfo', easyNetworkStubUtilsPath),
15
- strictRouteResponseCallback: ast_1.ts.reference.genericFactory('StrictRouteResponseCallback', easyNetworkStubUtilsPath),
12
+ easyNetworkStubWrapperOptions: ast_1.ts.reference.factory('EasyNetworkStubWrapperOptions', easyNetworkStubUtilsPath, {
13
+ importType: 'type-import',
14
+ }),
15
+ stubRequestItem: ast_1.ts.reference.factory('StubRequestItem', easyNetworkStubUtilsPath, { importType: 'type-import' }),
16
+ stubRequestInfo: ast_1.ts.reference.genericFactory('StubRequestInfo', easyNetworkStubUtilsPath, {
17
+ importType: 'type-import',
18
+ }),
19
+ strictRouteResponseCallback: ast_1.ts.reference.genericFactory('StrictRouteResponseCallback', easyNetworkStubUtilsPath, { importType: 'type-import' }),
16
20
  getStubResponder: ast_1.ts.reference.genericFactory('getStubResponder', easyNetworkStubUtilsPath),
17
21
  easyNetworkStubWrapper: ast_1.ts.reference.factory('EasyNetworkStubWrapper', easyNetworkStubUtilsPath),
18
22
  easyNetworkStubBase: ast_1.ts.reference.factory('EasyNetworkStubBase', easyNetworkStubUtilsPath),
19
- easyNetworkStubGroup: ast_1.ts.reference.genericFactory('EasyNetworkStubGroup', easyNetworkStubUtilsPath),
23
+ easyNetworkStubGroup: ast_1.ts.reference.genericFactory('EasyNetworkStubGroup', easyNetworkStubUtilsPath, {
24
+ importType: 'type-import',
25
+ }),
20
26
  createEasyNetworkStubGroup: ast_1.ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
21
27
  };
22
28
  }
@@ -136,7 +136,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
136
136
  const method = this.getInterfaceEndpointMethod(ctx, endpoint);
137
137
  method.accessModifier = 'public';
138
138
  method.body = (0, core_1.appendValueGroup)([
139
- (0, core_1.builderTemplate) `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${core_1.builderTemplate.indent `
139
+ (0, core_1.builderTemplate) `const url = new ${ctx.refs.urlBuilder()}(this.options.baseUrl)${core_1.builderTemplate.indent `
140
140
  .withPath(${ast_1.ts.string(endpoint.path)})${(b) => b.forEach(endpoint.parameters, (b, p) => {
141
141
  switch (p.target) {
142
142
  case 'path':
@@ -146,7 +146,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
146
146
  b.append((0, core_1.builderTemplate) `\n.withQueryParam(${ast_1.ts.string(p.name)}, params.${(0, core_1.toCasing)(p.name, ctx.config.paramNameCasing)})`);
147
147
  break;
148
148
  }
149
- })}
149
+ })}
150
150
  .build();`}`,
151
151
  (0, core_1.builderTemplate) `const response = (this.options.fetch ?? fetch)(url, ${ast_1.ts.object({
152
152
  members: [
@@ -9,8 +9,8 @@ function getReferenceFactories(options) {
9
9
  const fetchClientUtilsPath = (0, path_1.resolve)(utilsDirPath, 'fetch-client.utils.ts');
10
10
  return {
11
11
  // fetch-client.utils.ts
12
- typedResponse: ast_1.ts.reference.genericFactory('TypedResponse', fetchClientUtilsPath),
13
- fetchClientOptions: ast_1.ts.reference.factory('FetchClientOptions', fetchClientUtilsPath),
12
+ typedResponse: ast_1.ts.reference.genericFactory('TypedResponse', fetchClientUtilsPath, { importType: 'type-import' }),
13
+ fetchClientOptions: ast_1.ts.reference.factory('FetchClientOptions', fetchClientUtilsPath, { importType: 'type-import' }),
14
14
  urlBuilder: ast_1.ts.reference.factory('UrlBuilder', fetchClientUtilsPath),
15
15
  };
16
16
  }
@@ -189,7 +189,7 @@ class DefaultTypeScriptK6ClientGenerator extends file_generator_1.TypeScriptFile
189
189
  ],
190
190
  }),
191
191
  parameters: [ast_1.ts.constructorParameter('rootUrl'), ast_1.ts.constructorParameter('defaultK6ParamsFactory')],
192
- body: (0, core_1.builderTemplate) `this.rootUrl = rootUrl;
192
+ body: (0, core_1.builderTemplate) `this.rootUrl = rootUrl;
193
193
  this._defaultK6ParamsFactory = defaultK6ParamsFactory;`,
194
194
  }),
195
195
  ...ctx.service.endpoints.map((e) => this.getEndpointMethod(ctx, e)),
@@ -248,11 +248,11 @@ class DefaultTypeScriptK6ClientGenerator extends file_generator_1.TypeScriptFile
248
248
  }
249
249
  : null,
250
250
  '',
251
- (0, core_1.builderTemplate) `return /** @type {${returnType}} */ (${core_1.builderTemplate.indent `
252
- ${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${core_1.builderTemplate.indent `
253
- accept: ${ast_1.ts.string(accept)},
254
- params: this.getK6Params(k6Params),`}
255
- })`}
251
+ (0, core_1.builderTemplate) `return /** @type {${returnType}} */ (${core_1.builderTemplate.indent `
252
+ ${ctx.config.async ? 'await rb.buildAsync' : 'rb.build'}({${core_1.builderTemplate.indent `
253
+ accept: ${ast_1.ts.string(accept)},
254
+ params: this.getK6Params(k6Params),`}
255
+ })`}
256
256
  );`,
257
257
  ], '\n'),
258
258
  });
@@ -15,13 +15,14 @@ class ImportExportCollection {
15
15
  this._typeImports = new Map();
16
16
  this._jsDocImports = new Map();
17
17
  this._exports = new Map();
18
+ this._typeExports = new Map();
18
19
  this._options = { ...exports.defaultImportExportCollectionOptions, ...options };
19
20
  }
20
21
  get hasImports() {
21
22
  return this._imports.size > 0 || this._typeImports.size > 0 || this._jsDocImports.size > 0;
22
23
  }
23
24
  get hasExports() {
24
- return this._exports.size > 0;
25
+ return this._exports.size > 0 || this._typeExports.size > 0;
25
26
  }
26
27
  get imports() {
27
28
  return [
@@ -51,28 +52,23 @@ class ImportExportCollection {
51
52
  map.set(fromModule, new Set([importName]));
52
53
  }
53
54
  }
54
- getImportMap(type) {
55
- switch (type) {
56
- case 'import':
57
- return this._imports;
58
- case 'type-import':
59
- return this._typeImports;
60
- case 'js-doc':
61
- return this._jsDocImports;
62
- }
63
- }
64
- addExport(exportName, fromModule) {
65
- const existingExport = this._exports.get(fromModule);
55
+ addExport(exportName, fromModule, options) {
56
+ var _a;
57
+ const map = this.getExportMap((_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : 'export');
58
+ const existingExport = map.get(fromModule);
66
59
  if (existingExport) {
67
60
  existingExport.add(exportName);
68
61
  }
69
62
  else {
70
- this._exports.set(fromModule, new Set([exportName]));
63
+ map.set(fromModule, new Set([exportName]));
71
64
  }
72
65
  }
73
66
  clear() {
74
67
  this._imports.clear();
68
+ this._typeImports.clear();
69
+ this._jsDocImports.clear();
75
70
  this._exports.clear();
71
+ this._typeExports.clear();
76
72
  }
77
73
  toString(options) {
78
74
  const builder = new core_1.StringBuilder(options);
@@ -111,6 +107,15 @@ class ImportExportCollection {
111
107
  }
112
108
  const sortedExports = this.sortAndResolve(this._exports, filePath, importModuleTransformer);
113
109
  this.writeImportsExports(builder, 'export', sortedExports, { useSingleQuotes });
110
+ hasPrevious = true;
111
+ }
112
+ if (this._typeExports.size > 0) {
113
+ if (hasPrevious) {
114
+ builder.appendLine();
115
+ }
116
+ const sortedExports = this.sortAndResolve(this._typeExports, filePath, importModuleTransformer);
117
+ this.writeImportsExports(builder, 'export type', sortedExports, { useSingleQuotes });
118
+ hasPrevious = true;
114
119
  }
115
120
  }
116
121
  writeImportsExports(builder, keyword, data, options) {
@@ -153,5 +158,23 @@ class ImportExportCollection {
153
158
  kind,
154
159
  ];
155
160
  }
161
+ getImportMap(type) {
162
+ switch (type) {
163
+ case 'import':
164
+ return this._imports;
165
+ case 'type-import':
166
+ return this._typeImports;
167
+ case 'js-doc':
168
+ return this._jsDocImports;
169
+ }
170
+ }
171
+ getExportMap(type) {
172
+ switch (type) {
173
+ case 'export':
174
+ return this._exports;
175
+ case 'type-export':
176
+ return this._typeExports;
177
+ }
178
+ }
156
179
  }
157
180
  exports.ImportExportCollection = ImportExportCollection;
@@ -3,16 +3,18 @@ import { TsNode } from '../node';
3
3
  import { writeTsNodes } from '../utils/write-ts-nodes';
4
4
  export class TsExport extends TsNode {
5
5
  constructor(options) {
6
+ var _a;
6
7
  super(options);
7
8
  this.name = options.name;
8
9
  this.filePath = options.filePath;
10
+ this.kind = (_a = options.kind) !== null && _a !== void 0 ? _a : 'export';
9
11
  }
10
12
  onWrite(builder) {
11
13
  if (builder instanceof TypeScriptFileBuilder) {
12
- builder.addExport(this.name, this.filePath);
14
+ builder.addExport(this.name, this.filePath, { type: this.kind });
13
15
  }
14
16
  else {
15
- builder.appendLine(`export { ${this.name} } from '${this.filePath}';`);
17
+ builder.appendLine(this.kind === 'type-export' ? 'export type' : 'export', ` { ${this.name} } from '${this.filePath}';`);
16
18
  }
17
19
  }
18
20
  }
@@ -38,24 +38,24 @@ TsReference.addImportHandlers = [
38
38
  },
39
39
  ];
40
40
  const createReference = (name, moduleNameOrfilePath, options) => new TsReference({ ...options, name, moduleNameOrfilePath });
41
- function _createFactory(name, moduleNameOrfilePath) {
42
- return Object.assign((options) => createReference(name, moduleNameOrfilePath, options), {
41
+ function _createFactory(name, moduleNameOrfilePath, defaultOptions) {
42
+ return Object.assign((options) => createReference(name, moduleNameOrfilePath, { ...defaultOptions, ...options }), {
43
43
  refName: name,
44
44
  moduleNameOrfilePath,
45
45
  });
46
46
  }
47
- function createFactory(name, moduleNameOrfilePath) {
48
- return _createFactory(name, moduleNameOrfilePath);
47
+ function createFactory(name, moduleNameOrfilePath, defaultOptions) {
48
+ return _createFactory(name, moduleNameOrfilePath, defaultOptions);
49
49
  }
50
- function _createGenericFactory(name, moduleNameOrfilePath) {
51
- return Object.assign((generics, options) => createReference(name, moduleNameOrfilePath, { ...options, generics }), {
50
+ function _createGenericFactory(name, moduleNameOrfilePath, defaultOptions) {
51
+ return Object.assign((generics, options) => createReference(name, moduleNameOrfilePath, { ...defaultOptions, ...options, generics }), {
52
52
  refName: name,
53
53
  moduleNameOrfilePath,
54
54
  infer: () => createReference(name, moduleNameOrfilePath),
55
55
  });
56
56
  }
57
- function createGenericFactory(name, moduleNameOrfilePath) {
58
- return _createGenericFactory(name, moduleNameOrfilePath);
57
+ function createGenericFactory(name, moduleNameOrfilePath, defaultOptions) {
58
+ return _createGenericFactory(name, moduleNameOrfilePath, defaultOptions);
59
59
  }
60
60
  export const tsReference = Object.assign(createReference, {
61
61
  factory: createFactory,
@@ -2,7 +2,7 @@ import { tsReference } from '../nodes/reference';
2
2
  // @angular/core
3
3
  export const inject = tsReference.factory('inject', '@angular/core');
4
4
  export const injectable = tsReference.factory('Injectable', '@angular/core');
5
- export const provider = tsReference.factory('Provider', '@angular/core');
5
+ export const provider = tsReference.factory('Provider', '@angular/core', { importType: 'type-import' });
6
6
  // @angular/common/http
7
7
  export const httpClient = tsReference.factory('HttpClient', '@angular/common/http');
8
8
  export const httpContext = tsReference.factory('HttpContext', '@angular/common/http');
@@ -1,5 +1,7 @@
1
1
  import { tsReference } from '../nodes/reference';
2
2
  export const easyNetworkStub = tsReference.factory('EasyNetworkStub', 'easy-network-stub');
3
- export const httpMethod = tsReference.factory('HttpMethod', 'easy-network-stub');
4
- export const routeResponseCallback = tsReference.genericFactory('RouteResponseCallback', 'easy-network-stub');
3
+ export const httpMethod = tsReference.factory('HttpMethod', 'easy-network-stub', { importType: 'type-import' });
4
+ export const routeResponseCallback = tsReference.genericFactory('RouteResponseCallback', 'easy-network-stub', {
5
+ importType: 'type-import',
6
+ });
5
7
  export const errorResponse = tsReference.genericFactory('ErrorResponse', 'easy-network-stub');
@@ -24,8 +24,8 @@ export class TypeScriptFileBuilder extends SourceBuilder {
24
24
  this.imports.addImport(name, moduleNameOrfilePath, options);
25
25
  return this;
26
26
  }
27
- addExport(name, filePath) {
28
- this.imports.addExport(name, filePath);
27
+ addExport(name, filePath, options) {
28
+ this.imports.addExport(name, filePath, options);
29
29
  return this;
30
30
  }
31
31
  clear() {
@@ -59,7 +59,7 @@ export class TypeScriptFileBuilder extends SourceBuilder {
59
59
  appendModelUsage(type, options) {
60
60
  this.append(type.component);
61
61
  for (const i of type.imports) {
62
- this.addImport(i.name, i.modulePath, options);
62
+ this.addImport(i.name, i.modulePath, { ...i, ...options });
63
63
  }
64
64
  return this;
65
65
  }
@@ -15,14 +15,16 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
15
15
  options: ctx.config,
16
16
  generator: (b) => b.append(fileContent),
17
17
  });
18
+ const exports = fileContent.values.filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x);
19
+ const isType = exports.find((x) => x.name === name) instanceof ts.TypeAlias;
18
20
  return {
19
21
  component: name,
20
22
  filePath,
21
- imports: [{ kind: 'file', name, modulePath: filePath, type: 'import' }],
22
- additionalExports: fileContent.values
23
- .filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x)
23
+ imports: [{ kind: 'file', name, modulePath: filePath, type: 'type-import' }],
24
+ additionalExports: exports
24
25
  .filter((x) => x.name !== name)
25
- .map((x) => x.name),
26
+ .map((x) => ({ name: x.name, type: x instanceof ts.TypeAlias ? 'type-export' : 'export' })),
27
+ kind: isType ? 'type' : 'interface',
26
28
  };
27
29
  }
28
30
  else {
@@ -30,7 +32,7 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
30
32
  builder.append(this.getType(ctx, ctx.schema));
31
33
  const imports = builder.imports.imports;
32
34
  builder.imports.clear();
33
- return { component: builder.toString(false), imports };
35
+ return { component: builder.toString(false), imports, kind: 'unknown' };
34
36
  }
35
37
  }
36
38
  getFileContent(ctx) {
@@ -155,13 +157,17 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
155
157
  return this.getAnyType(ctx);
156
158
  schema = getSchemaReference(schema, ['description']);
157
159
  if ((options === null || options === void 0 ? void 0 : options.useBaseType) && ctx.schema.inheritedSchemas.some((x) => x.id === schema.id)) {
158
- return ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema));
160
+ return ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema), {
161
+ importType: 'type-import',
162
+ });
159
163
  }
160
164
  if (!(options === null || options === void 0 ? void 0 : options.skipSchemas) && this.shouldGenerateTypeDeclaration(ctx, schema)) {
161
165
  if (schema.id === ctx.schema.id) {
162
166
  return null;
163
167
  }
164
- return ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema));
168
+ return ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema), {
169
+ importType: 'type-import',
170
+ });
165
171
  }
166
172
  if (schema.enum) {
167
173
  return ts.unionType(schema.enum.map((x) => ts.toNode(x)));
@@ -54,7 +54,10 @@ export class TypeScriptModelsGenerator extends OpenApiSchemasGenerationProviderB
54
54
  const { filePath } = x;
55
55
  if (!filePath)
56
56
  return [];
57
- return [ts.export(x.component, filePath), ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => ts.export(e, filePath))) !== null && _b !== void 0 ? _b : [])];
57
+ return [
58
+ ts.export(x.component, filePath, { kind: x.kind === 'type' ? 'type-export' : 'export' }),
59
+ ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => typeof e === 'string' ? ts.export(e, filePath) : ts.export(e.name, filePath, { kind: e.type }))) !== null && _b !== void 0 ? _b : []),
60
+ ];
58
61
  }));
59
62
  }
60
63
  }
@@ -184,7 +184,7 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
184
184
  var _a, _b, _c, _d;
185
185
  const hasParams = this.hasEndpointParams(ctx, endpoint);
186
186
  const paramsOptional = !endpoint.parameters.some((p) => p.required) && !((_a = endpoint.requestBody) === null || _a === void 0 ? void 0 : _a.required);
187
- const responseModelType = ts.reference(this.getResponseModelName(ctx, endpoint), this.getResponseModelFilePath(ctx));
187
+ const responseModelType = ts.reference(this.getResponseModelName(ctx, endpoint), this.getResponseModelFilePath(ctx), { importType: 'type-import' });
188
188
  const returnType = ctx.refs.abortablePromise([responseModelType]);
189
189
  const accept = (_d = (_c = (_b = this.getEndpointSuccessResponse(ctx, endpoint)) === null || _b === void 0 ? void 0 : _b.contentOptions[0]) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : '*/*';
190
190
  const responseType = this.contentTypeToResponseType(accept);
@@ -228,13 +228,13 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
228
228
  }
229
229
  : null,
230
230
  '',
231
- s `return ${ctx.refs.waitForResponse([responseModelType])}(${s.indent `
232
- this.http.request(rb.build({${s.indent `
233
- responseType: ${ts.string(responseType)},
234
- accept: ${ts.string(accept)},
235
- context,`}
236
- })),
237
- {${s.indent `
231
+ s `return ${ctx.refs.waitForResponse([responseModelType])}(${s.indent `
232
+ this.http.request(rb.build({${s.indent `
233
+ responseType: ${ts.string(responseType)},
234
+ accept: ${ts.string(accept)},
235
+ context,`}
236
+ })),
237
+ {${s.indent `
238
238
  errorResponseTypes: ${ts.object({
239
239
  members: [
240
240
  ...Object.entries(this.getEndpointStatusCodes(ctx, endpoint))
@@ -243,8 +243,8 @@ export class DefaultTypeScriptAngularServiceGenerator extends TypeScriptFileGene
243
243
  return ts.property(key, { value: ts.string(value.parser) });
244
244
  }),
245
245
  ],
246
- })}`}
247
- }`}
246
+ })}`}
247
+ }`}
248
248
  )`,
249
249
  ], '\n'),
250
250
  });
@@ -196,7 +196,7 @@ export class TypeScriptAngularServicesGenerator extends OpenApiServicesGeneratio
196
196
  getResponseModelsIndexFileContent(ctx) {
197
197
  return appendValueGroup(Object.values(ctx.output.typescript.services)
198
198
  .flatMap((x) => Object.values(x.responseModels))
199
- .map((x) => ts.export(x.component, x.filePath)));
199
+ .map((x) => ts.export(x.component, x.filePath, { kind: 'type-export' })));
200
200
  }
201
201
  getServicesIndexFilePath(ctx) {
202
202
  return ctx.config.servicesIndexFile ? resolve(ctx.config.outputDir, ctx.config.servicesIndexFile) : null;
@@ -7,7 +7,7 @@ export function getReferenceFactories(options) {
7
7
  const utilsDirPath = resolve(options.outputDir, options.utilsDir);
8
8
  return {
9
9
  // angular-service.utils.ts
10
- abortablePromise: ts.reference.genericFactory('AbortablePromise', join(utilsDirPath, 'angular-service.utils.ts')),
10
+ abortablePromise: ts.reference.genericFactory('AbortablePromise', join(utilsDirPath, 'angular-service.utils.ts'), { importType: 'type-import' }),
11
11
  waitForResponse: ts.reference.genericFactory('waitForResponse', join(utilsDirPath, 'angular-service.utils.ts')),
12
12
  // request-builder.ts
13
13
  requestBuilder: ts.reference.factory('RequestBuilder', join(utilsDirPath, 'request-builder.ts')),
@@ -16,7 +16,9 @@ export function getReferenceFactories(options) {
16
16
  // api-base-service.ts - generated in angular-service-generator.ts
17
17
  apiBaseService: ts.reference.factory('ApiBaseService', join(utilsDirPath, 'api-base-service.ts')),
18
18
  // http-status-code.ts - generated in angular-services-generator.ts
19
- httpStatusCode: ts.reference.factory('HttpStatusCode', join(utilsDirPath, 'http-status-code.ts')),
19
+ httpStatusCode: ts.reference.factory('HttpStatusCode', join(utilsDirPath, 'http-status-code.ts'), {
20
+ importType: 'type-import',
21
+ }),
20
22
  // provide.ts - generated in angular-services-generator.ts
21
23
  provide: ts.reference.factory(toCasing(`provide_${(_b = options.domainName) !== null && _b !== void 0 ? _b : ''}_Api`, options.functionNameCasing), join(utilsDirPath, 'provide.ts')),
22
24
  };