@goast/typescript 0.3.6 → 0.3.7
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/assets/client/angular/angular-service.utils.ts +3 -1
- package/assets/client/angular/request-builder.ts +3 -1
- package/assets/stubs/easy-network-stub/easy-network-stub.utils.ts +3 -1
- 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 +33 -6
- package/cjs/lib/generators/models/models-generator.js +6 -1
- package/cjs/lib/generators/services/angular-services/angular-service-generator.js +1 -1
- 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/refs.js +11 -5
- package/cjs/lib/generators/services/fetch-clients/refs.js +2 -2
- 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 +33 -6
- package/esm/lib/generators/models/models-generator.js +6 -1
- package/esm/lib/generators/services/angular-services/angular-service-generator.js +1 -1
- 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/refs.js +11 -5
- package/esm/lib/generators/services/fetch-clients/refs.js +2 -2
- package/esm/lib/import-collection.js +37 -14
- package/package.json +1 -1
- 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 +8 -2
- package/types/lib/file-builder.d.ts +2 -2
- package/types/lib/generators/models/model-generator.d.ts +2 -0
- package/types/lib/import-collection.d.ts +9 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { HttpErrorResponse,
|
|
1
|
+
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
|
|
2
2
|
import { Observable, Subscription, filter, take, map, catchError, EMPTY } from 'rxjs';
|
|
3
3
|
|
|
4
|
+
import type { HttpEvent } from '@angular/common/http';
|
|
5
|
+
|
|
4
6
|
export type AbortablePromise<T> = Omit<Promise<T>, 'then' | 'catch' | 'finally'> & {
|
|
5
7
|
abort(): void;
|
|
6
8
|
then<TResult1 = T, TResult2 = never>(
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { HttpRequest,
|
|
1
|
+
import { HttpRequest, HttpParams, HttpHeaders, HttpContext } from '@angular/common/http';
|
|
2
|
+
|
|
3
|
+
import type { HttpParameterCodec } from '@angular/common/http';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Custom parameter codec to correctly handle the plus sign in parameter
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { EasyNetworkStub
|
|
1
|
+
import { EasyNetworkStub } from 'easy-network-stub';
|
|
2
|
+
|
|
3
|
+
import type { HttpMethod, RouteResponseCallback, ErrorResponse } from 'easy-network-stub';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Options for the `EasyNetworkStubWrapper`.
|
|
@@ -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
|
}
|
|
@@ -18,14 +18,26 @@ 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 node = exports.find((x) => x.name === name);
|
|
21
23
|
return {
|
|
22
24
|
component: name,
|
|
23
25
|
filePath,
|
|
24
|
-
imports: [
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
imports: [
|
|
27
|
+
{
|
|
28
|
+
kind: 'file',
|
|
29
|
+
name,
|
|
30
|
+
modulePath: filePath,
|
|
31
|
+
type: node instanceof ast_1.ts.Interface || node instanceof ast_1.ts.TypeAlias ? 'type-import' : 'import',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
additionalExports: exports
|
|
27
35
|
.filter((x) => x.name !== name)
|
|
28
|
-
.map((x) =>
|
|
36
|
+
.map((x) => ({
|
|
37
|
+
name: x.name,
|
|
38
|
+
type: x instanceof ast_1.ts.TypeAlias || x instanceof ast_1.ts.Interface ? 'type-export' : 'export',
|
|
39
|
+
})),
|
|
40
|
+
kind: this.getNodeKind(node),
|
|
29
41
|
};
|
|
30
42
|
}
|
|
31
43
|
else {
|
|
@@ -36,6 +48,17 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
36
48
|
return { component: builder.toString(false), imports };
|
|
37
49
|
}
|
|
38
50
|
}
|
|
51
|
+
getNodeKind(node) {
|
|
52
|
+
if (node instanceof ast_1.ts.Interface)
|
|
53
|
+
return 'interface';
|
|
54
|
+
if (node instanceof ast_1.ts.TypeAlias)
|
|
55
|
+
return 'type';
|
|
56
|
+
if (node instanceof ast_1.ts.Enum)
|
|
57
|
+
return 'enum';
|
|
58
|
+
if (node instanceof ast_1.ts.Class)
|
|
59
|
+
return 'class';
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
39
62
|
getFileContent(ctx) {
|
|
40
63
|
var _a;
|
|
41
64
|
const content = (0, core_1.appendValueGroup)([], '\n');
|
|
@@ -158,13 +181,17 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
158
181
|
return this.getAnyType(ctx);
|
|
159
182
|
schema = (0, core_1.getSchemaReference)(schema, ['description']);
|
|
160
183
|
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)
|
|
184
|
+
return ast_1.ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema), {
|
|
185
|
+
importType: 'type-import',
|
|
186
|
+
});
|
|
162
187
|
}
|
|
163
188
|
if (!(options === null || options === void 0 ? void 0 : options.skipSchemas) && this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
164
189
|
if (schema.id === ctx.schema.id) {
|
|
165
190
|
return null;
|
|
166
191
|
}
|
|
167
|
-
return ast_1.ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema)
|
|
192
|
+
return ast_1.ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema), {
|
|
193
|
+
importType: 'type-import',
|
|
194
|
+
});
|
|
168
195
|
}
|
|
169
196
|
if (schema.enum) {
|
|
170
197
|
return ast_1.ts.unionType(schema.enum.map((x) => ast_1.ts.toNode(x)));
|
|
@@ -57,7 +57,12 @@ class TypeScriptModelsGenerator extends core_1.OpenApiSchemasGenerationProviderB
|
|
|
57
57
|
const { filePath } = x;
|
|
58
58
|
if (!filePath)
|
|
59
59
|
return [];
|
|
60
|
-
return [
|
|
60
|
+
return [
|
|
61
|
+
ast_1.ts.export(x.component, filePath, {
|
|
62
|
+
kind: x.kind === 'type' || x.kind === 'interface' ? 'type-export' : 'export',
|
|
63
|
+
}),
|
|
64
|
+
...((_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 : []),
|
|
65
|
+
];
|
|
61
66
|
}));
|
|
62
67
|
}
|
|
63
68
|
}
|
|
@@ -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);
|
|
@@ -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
|
};
|
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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(
|
|
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');
|
package/esm/lib/file-builder.js
CHANGED
|
@@ -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,26 @@ 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 node = exports.find((x) => x.name === name);
|
|
18
20
|
return {
|
|
19
21
|
component: name,
|
|
20
22
|
filePath,
|
|
21
|
-
imports: [
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
imports: [
|
|
24
|
+
{
|
|
25
|
+
kind: 'file',
|
|
26
|
+
name,
|
|
27
|
+
modulePath: filePath,
|
|
28
|
+
type: node instanceof ts.Interface || node instanceof ts.TypeAlias ? 'type-import' : 'import',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
additionalExports: exports
|
|
24
32
|
.filter((x) => x.name !== name)
|
|
25
|
-
.map((x) =>
|
|
33
|
+
.map((x) => ({
|
|
34
|
+
name: x.name,
|
|
35
|
+
type: x instanceof ts.TypeAlias || x instanceof ts.Interface ? 'type-export' : 'export',
|
|
36
|
+
})),
|
|
37
|
+
kind: this.getNodeKind(node),
|
|
26
38
|
};
|
|
27
39
|
}
|
|
28
40
|
else {
|
|
@@ -33,6 +45,17 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
|
|
|
33
45
|
return { component: builder.toString(false), imports };
|
|
34
46
|
}
|
|
35
47
|
}
|
|
48
|
+
getNodeKind(node) {
|
|
49
|
+
if (node instanceof ts.Interface)
|
|
50
|
+
return 'interface';
|
|
51
|
+
if (node instanceof ts.TypeAlias)
|
|
52
|
+
return 'type';
|
|
53
|
+
if (node instanceof ts.Enum)
|
|
54
|
+
return 'enum';
|
|
55
|
+
if (node instanceof ts.Class)
|
|
56
|
+
return 'class';
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
36
59
|
getFileContent(ctx) {
|
|
37
60
|
var _a;
|
|
38
61
|
const content = appendValueGroup([], '\n');
|
|
@@ -155,13 +178,17 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
|
|
|
155
178
|
return this.getAnyType(ctx);
|
|
156
179
|
schema = getSchemaReference(schema, ['description']);
|
|
157
180
|
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)
|
|
181
|
+
return ts.reference(this.getBaseTypeName(ctx, schema), this.getFilePath(ctx, schema), {
|
|
182
|
+
importType: 'type-import',
|
|
183
|
+
});
|
|
159
184
|
}
|
|
160
185
|
if (!(options === null || options === void 0 ? void 0 : options.skipSchemas) && this.shouldGenerateTypeDeclaration(ctx, schema)) {
|
|
161
186
|
if (schema.id === ctx.schema.id) {
|
|
162
187
|
return null;
|
|
163
188
|
}
|
|
164
|
-
return ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema)
|
|
189
|
+
return ts.reference(this.getDeclarationTypeName(ctx, schema), this.getFilePath(ctx, schema), {
|
|
190
|
+
importType: 'type-import',
|
|
191
|
+
});
|
|
165
192
|
}
|
|
166
193
|
if (schema.enum) {
|
|
167
194
|
return ts.unionType(schema.enum.map((x) => ts.toNode(x)));
|
|
@@ -54,7 +54,12 @@ export class TypeScriptModelsGenerator extends OpenApiSchemasGenerationProviderB
|
|
|
54
54
|
const { filePath } = x;
|
|
55
55
|
if (!filePath)
|
|
56
56
|
return [];
|
|
57
|
-
return [
|
|
57
|
+
return [
|
|
58
|
+
ts.export(x.component, filePath, {
|
|
59
|
+
kind: x.kind === 'type' || x.kind === 'interface' ? 'type-export' : 'export',
|
|
60
|
+
}),
|
|
61
|
+
...((_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 : []),
|
|
62
|
+
];
|
|
58
63
|
}));
|
|
59
64
|
}
|
|
60
65
|
}
|
|
@@ -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);
|
|
@@ -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
|
};
|
|
@@ -6,14 +6,20 @@ export function getReferenceFactories(options) {
|
|
|
6
6
|
const easyNetworkStubUtilsPath = join(utilsDirPath, 'easy-network-stub.utils.ts');
|
|
7
7
|
return {
|
|
8
8
|
// easy-network-stub.utils.ts
|
|
9
|
-
easyNetworkStubWrapperOptions: ts.reference.factory('EasyNetworkStubWrapperOptions', easyNetworkStubUtilsPath
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
easyNetworkStubWrapperOptions: ts.reference.factory('EasyNetworkStubWrapperOptions', easyNetworkStubUtilsPath, {
|
|
10
|
+
importType: 'type-import',
|
|
11
|
+
}),
|
|
12
|
+
stubRequestItem: ts.reference.factory('StubRequestItem', easyNetworkStubUtilsPath, { importType: 'type-import' }),
|
|
13
|
+
stubRequestInfo: ts.reference.genericFactory('StubRequestInfo', easyNetworkStubUtilsPath, {
|
|
14
|
+
importType: 'type-import',
|
|
15
|
+
}),
|
|
16
|
+
strictRouteResponseCallback: ts.reference.genericFactory('StrictRouteResponseCallback', easyNetworkStubUtilsPath, { importType: 'type-import' }),
|
|
13
17
|
getStubResponder: ts.reference.genericFactory('getStubResponder', easyNetworkStubUtilsPath),
|
|
14
18
|
easyNetworkStubWrapper: ts.reference.factory('EasyNetworkStubWrapper', easyNetworkStubUtilsPath),
|
|
15
19
|
easyNetworkStubBase: ts.reference.factory('EasyNetworkStubBase', easyNetworkStubUtilsPath),
|
|
16
|
-
easyNetworkStubGroup: ts.reference.genericFactory('EasyNetworkStubGroup', easyNetworkStubUtilsPath
|
|
20
|
+
easyNetworkStubGroup: ts.reference.genericFactory('EasyNetworkStubGroup', easyNetworkStubUtilsPath, {
|
|
21
|
+
importType: 'type-import',
|
|
22
|
+
}),
|
|
17
23
|
createEasyNetworkStubGroup: ts.reference.genericFactory('createEasyNetworkStubGroup', easyNetworkStubUtilsPath),
|
|
18
24
|
};
|
|
19
25
|
}
|
|
@@ -6,8 +6,8 @@ export function getReferenceFactories(options) {
|
|
|
6
6
|
const fetchClientUtilsPath = resolve(utilsDirPath, 'fetch-client.utils.ts');
|
|
7
7
|
return {
|
|
8
8
|
// fetch-client.utils.ts
|
|
9
|
-
typedResponse: ts.reference.genericFactory('TypedResponse', fetchClientUtilsPath),
|
|
10
|
-
fetchClientOptions: ts.reference.factory('FetchClientOptions', fetchClientUtilsPath),
|
|
9
|
+
typedResponse: ts.reference.genericFactory('TypedResponse', fetchClientUtilsPath, { importType: 'type-import' }),
|
|
10
|
+
fetchClientOptions: ts.reference.factory('FetchClientOptions', fetchClientUtilsPath, { importType: 'type-import' }),
|
|
11
11
|
urlBuilder: ts.reference.factory('UrlBuilder', fetchClientUtilsPath),
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -12,13 +12,14 @@ export class ImportExportCollection {
|
|
|
12
12
|
this._typeImports = new Map();
|
|
13
13
|
this._jsDocImports = new Map();
|
|
14
14
|
this._exports = new Map();
|
|
15
|
+
this._typeExports = new Map();
|
|
15
16
|
this._options = { ...defaultImportExportCollectionOptions, ...options };
|
|
16
17
|
}
|
|
17
18
|
get hasImports() {
|
|
18
19
|
return this._imports.size > 0 || this._typeImports.size > 0 || this._jsDocImports.size > 0;
|
|
19
20
|
}
|
|
20
21
|
get hasExports() {
|
|
21
|
-
return this._exports.size > 0;
|
|
22
|
+
return this._exports.size > 0 || this._typeExports.size > 0;
|
|
22
23
|
}
|
|
23
24
|
get imports() {
|
|
24
25
|
return [
|
|
@@ -48,28 +49,23 @@ export class ImportExportCollection {
|
|
|
48
49
|
map.set(fromModule, new Set([importName]));
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
case 'type-import':
|
|
56
|
-
return this._typeImports;
|
|
57
|
-
case 'js-doc':
|
|
58
|
-
return this._jsDocImports;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
addExport(exportName, fromModule) {
|
|
62
|
-
const existingExport = this._exports.get(fromModule);
|
|
52
|
+
addExport(exportName, fromModule, options) {
|
|
53
|
+
var _a;
|
|
54
|
+
const map = this.getExportMap((_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : 'export');
|
|
55
|
+
const existingExport = map.get(fromModule);
|
|
63
56
|
if (existingExport) {
|
|
64
57
|
existingExport.add(exportName);
|
|
65
58
|
}
|
|
66
59
|
else {
|
|
67
|
-
|
|
60
|
+
map.set(fromModule, new Set([exportName]));
|
|
68
61
|
}
|
|
69
62
|
}
|
|
70
63
|
clear() {
|
|
71
64
|
this._imports.clear();
|
|
65
|
+
this._typeImports.clear();
|
|
66
|
+
this._jsDocImports.clear();
|
|
72
67
|
this._exports.clear();
|
|
68
|
+
this._typeExports.clear();
|
|
73
69
|
}
|
|
74
70
|
toString(options) {
|
|
75
71
|
const builder = new StringBuilder(options);
|
|
@@ -108,6 +104,15 @@ export class ImportExportCollection {
|
|
|
108
104
|
}
|
|
109
105
|
const sortedExports = this.sortAndResolve(this._exports, filePath, importModuleTransformer);
|
|
110
106
|
this.writeImportsExports(builder, 'export', sortedExports, { useSingleQuotes });
|
|
107
|
+
hasPrevious = true;
|
|
108
|
+
}
|
|
109
|
+
if (this._typeExports.size > 0) {
|
|
110
|
+
if (hasPrevious) {
|
|
111
|
+
builder.appendLine();
|
|
112
|
+
}
|
|
113
|
+
const sortedExports = this.sortAndResolve(this._typeExports, filePath, importModuleTransformer);
|
|
114
|
+
this.writeImportsExports(builder, 'export type', sortedExports, { useSingleQuotes });
|
|
115
|
+
hasPrevious = true;
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
118
|
writeImportsExports(builder, keyword, data, options) {
|
|
@@ -150,4 +155,22 @@ export class ImportExportCollection {
|
|
|
150
155
|
kind,
|
|
151
156
|
];
|
|
152
157
|
}
|
|
158
|
+
getImportMap(type) {
|
|
159
|
+
switch (type) {
|
|
160
|
+
case 'import':
|
|
161
|
+
return this._imports;
|
|
162
|
+
case 'type-import':
|
|
163
|
+
return this._typeImports;
|
|
164
|
+
case 'js-doc':
|
|
165
|
+
return this._jsDocImports;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
getExportMap(type) {
|
|
169
|
+
switch (type) {
|
|
170
|
+
case 'export':
|
|
171
|
+
return this._exports;
|
|
172
|
+
case 'type-export':
|
|
173
|
+
return this._typeExports;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
153
176
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { AstNodeOptions, Prettify, SourceBuilder } from '@goast/core';
|
|
1
|
+
import { AstNodeOptions, Nullable, Prettify, SourceBuilder } from '@goast/core';
|
|
2
|
+
import { TypeScriptExportType } from '../../common-results';
|
|
2
3
|
import { TsNode } from '../node';
|
|
3
4
|
import { writeTsNodes } from '../utils/write-ts-nodes';
|
|
4
5
|
type Injects = never;
|
|
5
6
|
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<typeof TsNode<TBuilder, TInjects | Injects>, {
|
|
6
7
|
name: string;
|
|
7
8
|
filePath: string;
|
|
9
|
+
kind?: Nullable<TypeScriptExportType>;
|
|
8
10
|
}>;
|
|
9
11
|
export declare class TsExport<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
|
|
10
12
|
name: string;
|
|
11
13
|
filePath: string;
|
|
14
|
+
kind: TypeScriptExportType;
|
|
12
15
|
constructor(options: Options<TBuilder, TInjects>);
|
|
13
16
|
protected onWrite(builder: TBuilder): void;
|
|
14
17
|
}
|
|
@@ -27,23 +27,35 @@ export declare class TsReference<TBuilder extends SourceBuilder, TInjects extend
|
|
|
27
27
|
protected onWrite(builder: TBuilder): void;
|
|
28
28
|
static registerAddImportHandler<TBuilder extends SourceBuilder>(builderClass: _AddImportHandler<TBuilder>['builderClass'], handler: _AddImportHandler<TBuilder>['handler']): void;
|
|
29
29
|
}
|
|
30
|
-
declare function _createFactory(name: string, moduleNameOrfilePath?: Nullable<string
|
|
30
|
+
declare function _createFactory(name: string, moduleNameOrfilePath?: Nullable<string>, defaultOptions?: {
|
|
31
|
+
importType?: Nullable<TypeScriptImportType>;
|
|
32
|
+
}): (<TBuilder extends SourceBuilder>(options?: FactoryOptions<TBuilder>) => TsReference<TBuilder, never>) & {
|
|
31
33
|
refName: string;
|
|
32
34
|
moduleNameOrfilePath: Nullable<string>;
|
|
33
35
|
};
|
|
34
|
-
declare function createFactory(name: string, moduleNameOrfilePath: string
|
|
36
|
+
declare function createFactory(name: string, moduleNameOrfilePath: string, defaultOptions?: {
|
|
37
|
+
importType?: Nullable<TypeScriptImportType>;
|
|
38
|
+
}): ReturnType<typeof _createFactory> & {
|
|
35
39
|
moduleNameOrfilePath: string;
|
|
36
40
|
};
|
|
37
|
-
declare function createFactory(name: string, moduleNameOrfilePath?: Nullable<string
|
|
38
|
-
|
|
41
|
+
declare function createFactory(name: string, moduleNameOrfilePath?: Nullable<string>, defaultOptions?: {
|
|
42
|
+
importType?: Nullable<TypeScriptImportType>;
|
|
43
|
+
}): ReturnType<typeof _createFactory>;
|
|
44
|
+
declare function _createGenericFactory<TGenericCount extends number | number[]>(name: string, moduleNameOrfilePath?: Nullable<string>, defaultOptions?: {
|
|
45
|
+
importType?: Nullable<TypeScriptImportType>;
|
|
46
|
+
}): (<TBuilder extends SourceBuilder>(generics: TupleWithCount<TsType<TBuilder>, TGenericCount>, options?: FactoryOptions<TBuilder>) => TsReference<TBuilder, never>) & {
|
|
39
47
|
refName: string;
|
|
40
48
|
moduleNameOrfilePath: Nullable<string>;
|
|
41
49
|
infer: <TBuilder extends SourceBuilder>() => TsReference<TBuilder, never>;
|
|
42
50
|
};
|
|
43
|
-
declare function createGenericFactory<TGenericCount extends number | number[]>(name: string, moduleNameOrfilePath: string
|
|
51
|
+
declare function createGenericFactory<TGenericCount extends number | number[]>(name: string, moduleNameOrfilePath: string, defaultOptions?: {
|
|
52
|
+
importType?: Nullable<TypeScriptImportType>;
|
|
53
|
+
}): ReturnType<typeof _createGenericFactory<TGenericCount>> & {
|
|
44
54
|
moduleNameOrfilePath: string;
|
|
45
55
|
};
|
|
46
|
-
declare function createGenericFactory<TGenericCount extends number | number[]>(name: string, moduleNameOrfilePath?: Nullable<string
|
|
56
|
+
declare function createGenericFactory<TGenericCount extends number | number[]>(name: string, moduleNameOrfilePath?: Nullable<string>, defaultOptions?: {
|
|
57
|
+
importType?: Nullable<TypeScriptImportType>;
|
|
58
|
+
}): ReturnType<typeof _createGenericFactory<TGenericCount>>;
|
|
47
59
|
export declare const tsReference: (<TBuilder extends SourceBuilder>(name: Options<TBuilder>["name"], moduleNameOrfilePath?: Options<TBuilder>["moduleNameOrfilePath"], options?: Prettify<Omit<Options<TBuilder>, "name" | "moduleNameOrfilePath">>) => TsReference<TBuilder, never>) & {
|
|
48
60
|
factory: typeof createFactory;
|
|
49
61
|
genericFactory: typeof createGenericFactory;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
+
import { TypeScriptExportOptions } from './import-collection';
|
|
2
|
+
export type TypeScriptComponentOutputKind = 'interface' | 'type' | 'enum' | 'class' | 'function' | 'variable';
|
|
1
3
|
export type TypeScriptComponentOutput = {
|
|
2
4
|
component: string;
|
|
3
5
|
filePath?: string;
|
|
4
6
|
imports: TypeScriptImport[];
|
|
5
|
-
additionalExports?: string[]
|
|
7
|
+
additionalExports?: string[] | ({
|
|
8
|
+
name: string;
|
|
9
|
+
} & TypeScriptExportOptions)[];
|
|
10
|
+
kind?: TypeScriptComponentOutputKind;
|
|
6
11
|
};
|
|
7
12
|
export type TypeScriptExportOutput = {
|
|
8
13
|
component: string;
|
|
9
14
|
filePath: string;
|
|
10
|
-
};
|
|
15
|
+
} & TypeScriptExportOptions;
|
|
11
16
|
export type TypeScriptImportKind = 'module' | 'file';
|
|
12
17
|
export type TypeScriptImportType = 'import' | 'type-import' | 'js-doc';
|
|
18
|
+
export type TypeScriptExportType = 'export' | 'type-export';
|
|
13
19
|
export type TypeScriptImport = {
|
|
14
20
|
kind: TypeScriptImportKind;
|
|
15
21
|
type: TypeScriptImportType;
|
|
@@ -2,7 +2,7 @@ import { AppendParam, AppendValue, Nullable, SourceBuilder } from '@goast/core';
|
|
|
2
2
|
import { TsNode } from './ast/node';
|
|
3
3
|
import { TypeScriptGeneratorConfig } from './config';
|
|
4
4
|
import { TypeScriptModelGeneratorOutput } from './generators';
|
|
5
|
-
import { ImportExportCollection, TypeScriptImportOptions } from './import-collection';
|
|
5
|
+
import { ImportExportCollection, TypeScriptExportOptions, TypeScriptImportOptions } from './import-collection';
|
|
6
6
|
export type TypeScriptAppends<TAdditionalAppends> = TsNode<TypeScriptFileBuilder> | TAdditionalAppends;
|
|
7
7
|
export type TypeScriptAppendParam<TBuilder extends TypeScriptFileBuilder, TAdditionalAppends> = AppendParam<TBuilder, TypeScriptAppends<TAdditionalAppends>>;
|
|
8
8
|
export declare function isTypeScriptAppendValue<TBuilder extends TypeScriptFileBuilder = TypeScriptFileBuilder>(value: unknown): value is AppendValue<TBuilder>;
|
|
@@ -12,7 +12,7 @@ export declare class TypeScriptFileBuilder<TAdditionalAppends = never> extends S
|
|
|
12
12
|
get options(): TypeScriptGeneratorConfig;
|
|
13
13
|
constructor(filePath?: string, options?: TypeScriptGeneratorConfig);
|
|
14
14
|
addImport(name: string, moduleNameOrfilePath: string, options?: TypeScriptImportOptions): this;
|
|
15
|
-
addExport(name: string, filePath: string): this;
|
|
15
|
+
addExport(name: string, filePath: string, options?: TypeScriptExportOptions): this;
|
|
16
16
|
clear(): void;
|
|
17
17
|
toString(addPadding?: boolean): string;
|
|
18
18
|
protected appendSingle(value: TypeScriptAppendParam<this, TAdditionalAppends>): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ApiSchema, AppendValueGroup, ArrayLikeApiSchema, CombinedLikeApiSchema, Nullable, ObjectLikeApiSchema } from '@goast/core';
|
|
2
2
|
import { TypeScriptModelGeneratorContext, TypeScriptModelGeneratorOutput } from './models';
|
|
3
3
|
import { ts } from '../../ast';
|
|
4
|
+
import { TypeScriptComponentOutputKind } from '../../common-results';
|
|
4
5
|
import { TypeScriptFileBuilder } from '../../file-builder';
|
|
5
6
|
import { TypeScriptFileGenerator } from '../file-generator';
|
|
6
7
|
type Context = TypeScriptModelGeneratorContext;
|
|
@@ -11,6 +12,7 @@ export interface TypeScriptModelGenerator<TOutput extends Output = Output> {
|
|
|
11
12
|
}
|
|
12
13
|
export declare class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator<Context, Output> implements TypeScriptModelGenerator {
|
|
13
14
|
generate(ctx: Context): Output;
|
|
15
|
+
protected getNodeKind(node: unknown): TypeScriptComponentOutputKind | undefined;
|
|
14
16
|
protected getFileContent(ctx: Context): AppendValueGroup<Builder>;
|
|
15
17
|
protected getEnum(ctx: Context): ts.Enum<import("@goast/core").SourceBuilder<never>, never>;
|
|
16
18
|
protected getInterface(ctx: Context, schema: ObjectLikeApiSchema): ts.Interface<Builder, never>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SourceBuilderOptions, StringBuilder } from '@goast/core';
|
|
2
|
-
import { TypeScriptImport, TypeScriptImportKind, TypeScriptImportType } from './common-results';
|
|
2
|
+
import { TypeScriptExportType, TypeScriptImport, TypeScriptImportKind, TypeScriptImportType } from './common-results';
|
|
3
3
|
import { ImportModuleTransformer } from './utils';
|
|
4
4
|
export type ImportExportCollectionOptions = {
|
|
5
5
|
filePath?: string;
|
|
@@ -10,11 +10,15 @@ export declare const defaultImportExportCollectionOptions: ImportExportCollectio
|
|
|
10
10
|
export type TypeScriptImportOptions = {
|
|
11
11
|
type?: TypeScriptImportType;
|
|
12
12
|
};
|
|
13
|
+
export type TypeScriptExportOptions = {
|
|
14
|
+
type?: TypeScriptExportType;
|
|
15
|
+
};
|
|
13
16
|
export declare class ImportExportCollection {
|
|
14
17
|
private readonly _imports;
|
|
15
18
|
private readonly _typeImports;
|
|
16
19
|
private readonly _jsDocImports;
|
|
17
20
|
private readonly _exports;
|
|
21
|
+
private readonly _typeExports;
|
|
18
22
|
private readonly _options;
|
|
19
23
|
constructor(options?: Partial<ImportExportCollectionOptions>);
|
|
20
24
|
get hasImports(): boolean;
|
|
@@ -22,15 +26,16 @@ export declare class ImportExportCollection {
|
|
|
22
26
|
get imports(): TypeScriptImport[];
|
|
23
27
|
private toImport;
|
|
24
28
|
addImport(importName: string, fromModule: string, options?: TypeScriptImportOptions): void;
|
|
25
|
-
|
|
26
|
-
addExport(exportName: string, fromModule: string): void;
|
|
29
|
+
addExport(exportName: string, fromModule: string, options?: TypeScriptExportOptions): void;
|
|
27
30
|
clear(): void;
|
|
28
31
|
toString(options: Partial<SourceBuilderOptions>): string;
|
|
29
32
|
writeTo(builder: StringBuilder): void;
|
|
30
|
-
protected writeImportsExports(builder: StringBuilder, keyword: 'import' | 'export' | 'import type' | ' * @import', data: (readonly [string, TypeScriptImportKind, string[]])[], options: {
|
|
33
|
+
protected writeImportsExports(builder: StringBuilder, keyword: 'import' | 'export' | 'import type' | 'export type' | ' * @import', data: (readonly [string, TypeScriptImportKind, string[]])[], options: {
|
|
31
34
|
useSingleQuotes: boolean;
|
|
32
35
|
}): void;
|
|
33
36
|
protected sortAndResolve(data: Map<string, Set<string>>, filePath: string | undefined, importModuleTransformer: ImportModuleTransformer): (readonly [string, TypeScriptImportKind, string[]])[];
|
|
34
37
|
protected getImportKind(fromModule: string): TypeScriptImportKind;
|
|
35
38
|
protected resolveModulePath(fromModule: string, filePath: string | undefined, importModuleTransformer: ImportModuleTransformer): [string, TypeScriptImportKind];
|
|
39
|
+
protected getImportMap(type: TypeScriptImportType): Map<string, Set<string>>;
|
|
40
|
+
protected getExportMap(type: TypeScriptExportType): Map<string, Set<string>>;
|
|
36
41
|
}
|