@rxap/ts-morph 0.1.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/GETSTARTED.md +0 -0
- package/GUIDES.md +0 -0
- package/LICENSE.md +621 -0
- package/README.md +21 -0
- package/package.json +47 -0
- package/src/index.d.ts +41 -0
- package/src/index.js +49 -0
- package/src/index.js.map +1 -0
- package/src/lib/coerce-class-constructor.d.ts +2 -0
- package/src/lib/coerce-class-constructor.js +14 -0
- package/src/lib/coerce-class-constructor.js.map +1 -0
- package/src/lib/coerce-class-method.d.ts +2 -0
- package/src/lib/coerce-class-method.js +13 -0
- package/src/lib/coerce-class-method.js.map +1 -0
- package/src/lib/coerce-class.d.ts +2 -0
- package/src/lib/coerce-class.js +12 -0
- package/src/lib/coerce-class.js.map +1 -0
- package/src/lib/coerce-decorator.d.ts +5 -0
- package/src/lib/coerce-decorator.js +14 -0
- package/src/lib/coerce-decorator.js.map +1 -0
- package/src/lib/coerce-dependency-injection.d.ts +14 -0
- package/src/lib/coerce-dependency-injection.js +57 -0
- package/src/lib/coerce-dependency-injection.js.map +1 -0
- package/src/lib/coerce-imports.d.ts +21 -0
- package/src/lib/coerce-imports.js +235 -0
- package/src/lib/coerce-imports.js.map +1 -0
- package/src/lib/coerce-source-file.d.ts +2 -0
- package/src/lib/coerce-source-file.js +12 -0
- package/src/lib/coerce-source-file.js.map +1 -0
- package/src/lib/coerce-statements.d.ts +2 -0
- package/src/lib/coerce-statements.js +11 -0
- package/src/lib/coerce-statements.js.map +1 -0
- package/src/lib/coerce-variable-declaration.d.ts +2 -0
- package/src/lib/coerce-variable-declaration.js +25 -0
- package/src/lib/coerce-variable-declaration.js.map +1 -0
- package/src/lib/find-function.d.ts +7 -0
- package/src/lib/find-function.js +8 -0
- package/src/lib/find-function.js.map +1 -0
- package/src/lib/get-class-decorator-arguments.d.ts +3 -0
- package/src/lib/get-class-decorator-arguments.js +16 -0
- package/src/lib/get-class-decorator-arguments.js.map +1 -0
- package/src/lib/get-class.d.ts +3 -0
- package/src/lib/get-class.js +26 -0
- package/src/lib/get-class.js.map +1 -0
- package/src/lib/get-coerce-array-literal-form-object-literal.d.ts +2 -0
- package/src/lib/get-coerce-array-literal-form-object-literal.js +26 -0
- package/src/lib/get-coerce-array-literal-form-object-literal.js.map +1 -0
- package/src/lib/nest/add-health-endpoint.d.ts +2 -0
- package/src/lib/nest/add-health-endpoint.js +57 -0
- package/src/lib/nest/add-health-endpoint.js.map +1 -0
- package/src/lib/nest/add-health-indicator.d.ts +2 -0
- package/src/lib/nest/add-health-indicator.js +48 -0
- package/src/lib/nest/add-health-indicator.js.map +1 -0
- package/src/lib/nest/add-to-global-health-endpoint.d.ts +2 -0
- package/src/lib/nest/add-to-global-health-endpoint.js +53 -0
- package/src/lib/nest/add-to-global-health-endpoint.js.map +1 -0
- package/src/lib/nest/coerce-app-guard-provider.d.ts +2 -0
- package/src/lib/nest/coerce-app-guard-provider.js +24 -0
- package/src/lib/nest/coerce-app-guard-provider.js.map +1 -0
- package/src/lib/nest/coerce-health-controller.d.ts +2 -0
- package/src/lib/nest/coerce-health-controller.js +23 -0
- package/src/lib/nest/coerce-health-controller.js.map +1 -0
- package/src/lib/nest/coerce-health-module.d.ts +2 -0
- package/src/lib/nest/coerce-health-module.js +36 -0
- package/src/lib/nest/coerce-health-module.js.map +1 -0
- package/src/lib/nest/coerce-nest-app-config.d.ts +11 -0
- package/src/lib/nest/coerce-nest-app-config.js +77 -0
- package/src/lib/nest/coerce-nest-app-config.js.map +1 -0
- package/src/lib/nest/coerce-nest-app-controller.d.ts +5 -0
- package/src/lib/nest/coerce-nest-app-controller.js +49 -0
- package/src/lib/nest/coerce-nest-app-controller.js.map +1 -0
- package/src/lib/nest/coerce-nest-app-module.d.ts +5 -0
- package/src/lib/nest/coerce-nest-app-module.js +13 -0
- package/src/lib/nest/coerce-nest-app-module.js.map +1 -0
- package/src/lib/nest/coerce-nest-config-module-import.d.ts +4 -0
- package/src/lib/nest/coerce-nest-config-module-import.js +26 -0
- package/src/lib/nest/coerce-nest-config-module-import.js.map +1 -0
- package/src/lib/nest/coerce-nest-controller.d.ts +6 -0
- package/src/lib/nest/coerce-nest-controller.js +26 -0
- package/src/lib/nest/coerce-nest-controller.js.map +1 -0
- package/src/lib/nest/coerce-nest-environment-provider.d.ts +2 -0
- package/src/lib/nest/coerce-nest-environment-provider.js +24 -0
- package/src/lib/nest/coerce-nest-environment-provider.js.map +1 -0
- package/src/lib/nest/coerce-nest-logger-provider.d.ts +2 -0
- package/src/lib/nest/coerce-nest-logger-provider.js +24 -0
- package/src/lib/nest/coerce-nest-logger-provider.js.map +1 -0
- package/src/lib/nest/coerce-nest-module-controller.d.ts +8 -0
- package/src/lib/nest/coerce-nest-module-controller.js +24 -0
- package/src/lib/nest/coerce-nest-module-controller.js.map +1 -0
- package/src/lib/nest/coerce-nest-module-import.d.ts +9 -0
- package/src/lib/nest/coerce-nest-module-import.js +29 -0
- package/src/lib/nest/coerce-nest-module-import.js.map +1 -0
- package/src/lib/nest/coerce-nest-module-provider.d.ts +9 -0
- package/src/lib/nest/coerce-nest-module-provider.js +24 -0
- package/src/lib/nest/coerce-nest-module-provider.js.map +1 -0
- package/src/lib/nest/coerce-nest-module.d.ts +6 -0
- package/src/lib/nest/coerce-nest-module.js +31 -0
- package/src/lib/nest/coerce-nest-module.js.map +1 -0
- package/src/lib/nest/coerce-nest-operation.d.ts +40 -0
- package/src/lib/nest/coerce-nest-operation.js +253 -0
- package/src/lib/nest/coerce-nest-operation.js.map +1 -0
- package/src/lib/nest/coerce-nest-provider-to-array.d.ts +3 -0
- package/src/lib/nest/coerce-nest-provider-to-array.js +42 -0
- package/src/lib/nest/coerce-nest-provider-to-array.js.map +1 -0
- package/src/lib/nest/coerce-nest-throttler-module-import.d.ts +4 -0
- package/src/lib/nest/coerce-nest-throttler-module-import.js +34 -0
- package/src/lib/nest/coerce-nest-throttler-module-import.js.map +1 -0
- package/src/lib/nest/find-nest-module-source-file.d.ts +2 -0
- package/src/lib/nest/find-nest-module-source-file.js +10 -0
- package/src/lib/nest/find-nest-module-source-file.js.map +1 -0
- package/src/lib/nest/get-controller-class.d.ts +2 -0
- package/src/lib/nest/get-controller-class.js +18 -0
- package/src/lib/nest/get-controller-class.js.map +1 -0
- package/src/lib/nest/get-nest-module-metadata.d.ts +2 -0
- package/src/lib/nest/get-nest-module-metadata.js +19 -0
- package/src/lib/nest/get-nest-module-metadata.js.map +1 -0
- package/src/lib/nest/has-nest-module-class.d.ts +2 -0
- package/src/lib/nest/has-nest-module-class.js +11 -0
- package/src/lib/nest/has-nest-module-class.js.map +1 -0
- package/src/lib/nest/is-nest-module-class.d.ts +2 -0
- package/src/lib/nest/is-nest-module-class.js +8 -0
- package/src/lib/nest/is-nest-module-class.js.map +1 -0
- package/src/lib/nest/nest-provider-object.d.ts +10 -0
- package/src/lib/nest/nest-provider-object.js +3 -0
- package/src/lib/nest/nest-provider-object.js.map +1 -0
- package/src/lib/nest/remove-nest-module-provider.d.ts +3 -0
- package/src/lib/nest/remove-nest-module-provider.js +13 -0
- package/src/lib/nest/remove-nest-module-provider.js.map +1 -0
- package/src/lib/nest/remove-nest-provider-to-array.d.ts +3 -0
- package/src/lib/nest/remove-nest-provider-to-array.js +29 -0
- package/src/lib/nest/remove-nest-provider-to-array.js.map +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestAppModule = void 0;
|
|
4
|
+
const coerce_nest_module_1 = require("./coerce-nest-module");
|
|
5
|
+
const remove_nest_module_provider_1 = require("./remove-nest-module-provider");
|
|
6
|
+
function CoerceNestAppModule(sourceFile, options = {}) {
|
|
7
|
+
var _a;
|
|
8
|
+
(0, coerce_nest_module_1.CoerceNestModule)(sourceFile, Object.assign(Object.assign({}, options), { name: 'app' }));
|
|
9
|
+
(_a = sourceFile.getImportDeclaration('./app.service')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
10
|
+
(0, remove_nest_module_provider_1.RemoveNestModuleProvider)(sourceFile, 'AppService');
|
|
11
|
+
}
|
|
12
|
+
exports.CoerceNestAppModule = CoerceNestAppModule;
|
|
13
|
+
//# sourceMappingURL=coerce-nest-app-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-app-module.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-app-module.ts"],"names":[],"mappings":";;;AACA,6DAG8B;AAC9B,+EAAyE;AAOzE,SAAgB,mBAAmB,CAAC,UAAsB,EAAE,UAAsC,EAAE;;IAClG,IAAA,qCAAgB,EAAC,UAAU,kCACtB,OAAO,KACV,IAAI,EAAE,KAAK,IACX,CAAC;IACH,MAAA,UAAU,CAAC,oBAAoB,CAAC,eAAe,CAAC,0CAAE,MAAM,EAAE,CAAC;IAC3D,IAAA,sDAAwB,EAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACrD,CAAC;AAPD,kDAOC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
import { CoerceNestModuleImportOptions } from './coerce-nest-module-import';
|
|
3
|
+
export type CoerceNestConfigModuleImportOptions = Omit<CoerceNestModuleImportOptions, 'moduleName'>;
|
|
4
|
+
export declare function CoerceNestConfigModuleImport(sourceFile: SourceFile, options: CoerceNestConfigModuleImportOptions): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestConfigModuleImport = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const coerce_nest_module_import_1 = require("./coerce-nest-module-import");
|
|
6
|
+
function CoerceNestConfigModuleImport(sourceFile, options) {
|
|
7
|
+
(0, coerce_nest_module_import_1.CoerceNestModuleImport)(sourceFile, Object.assign(Object.assign({}, options), { moduleName: 'ConfigModule', structures: [
|
|
8
|
+
{
|
|
9
|
+
moduleSpecifier: '@nestjs/config',
|
|
10
|
+
namedImports: ['ConfigModule'],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
moduleSpecifier: './app.config',
|
|
14
|
+
namedImports: ['VALIDATION_SCHEMA'],
|
|
15
|
+
},
|
|
16
|
+
], importWriter: w => {
|
|
17
|
+
w.writeLine('ConfigModule.forRoot(');
|
|
18
|
+
ts_morph_1.Writers.object({
|
|
19
|
+
isGlobal: 'true',
|
|
20
|
+
validationSchema: 'VALIDATION_SCHEMA',
|
|
21
|
+
})(w);
|
|
22
|
+
w.write(')');
|
|
23
|
+
} }));
|
|
24
|
+
}
|
|
25
|
+
exports.CoerceNestConfigModuleImport = CoerceNestConfigModuleImport;
|
|
26
|
+
//# sourceMappingURL=coerce-nest-config-module-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-config-module-import.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-config-module-import.ts"],"names":[],"mappings":";;;AAAA,uCAGkB;AAClB,2EAGqC;AAIrC,SAAgB,4BAA4B,CAAC,UAAsB,EAAE,OAA4C;IAC/G,IAAA,kDAAsB,EACpB,UAAU,kCACL,OAAO,KACV,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE;YACV;gBACE,eAAe,EAAE,gBAAgB;gBACjC,YAAY,EAAE,CAAE,cAAc,CAAE;aACjC;YACD;gBACE,eAAe,EAAE,cAAc;gBAC/B,YAAY,EAAE,CAAE,mBAAmB,CAAE;aACtC;SACF,EACD,YAAY,EAAE,CAAC,CAAC,EAAE;YAChB,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;YACrC,kBAAO,CAAC,MAAM,CAAC;gBACb,QAAQ,EAAE,MAAM;gBAChB,gBAAgB,EAAE,mBAAmB;aACtC,CAAC,CAAC,CAAC,CAAC,CAAC;YACN,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACf,CAAC,IAEJ,CAAC;AACJ,CAAC;AAzBD,oEAyBC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClassDeclaration, SourceFile } from 'ts-morph';
|
|
2
|
+
export interface CoerceNestControllerOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
path?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function CoerceNestController(sourceFile: SourceFile, options: CoerceNestControllerOptions): ClassDeclaration;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestController = void 0;
|
|
4
|
+
const utilities_1 = require("@rxap/utilities");
|
|
5
|
+
const coerce_class_1 = require("../coerce-class");
|
|
6
|
+
const coerce_imports_1 = require("../coerce-imports");
|
|
7
|
+
function CoerceNestController(sourceFile, options) {
|
|
8
|
+
const { name, path } = options;
|
|
9
|
+
const controllerClass = (0, utilities_1.CoerceSuffix)((0, utilities_1.classify)(name), 'Controller');
|
|
10
|
+
const classDeclaration = (0, coerce_class_1.CoerceClass)(sourceFile, controllerClass, {
|
|
11
|
+
isExported: true,
|
|
12
|
+
decorators: [
|
|
13
|
+
{
|
|
14
|
+
name: 'Controller',
|
|
15
|
+
arguments: [w => w.quote(path !== null && path !== void 0 ? path : (0, utilities_1.dasherize)(name))],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
(0, coerce_imports_1.CoerceImports)(sourceFile, {
|
|
20
|
+
namedImports: ['Controller'],
|
|
21
|
+
moduleSpecifier: '@nestjs/common',
|
|
22
|
+
});
|
|
23
|
+
return classDeclaration;
|
|
24
|
+
}
|
|
25
|
+
exports.CoerceNestController = CoerceNestController;
|
|
26
|
+
//# sourceMappingURL=coerce-nest-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-controller.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-controller.ts"],"names":[],"mappings":";;;AAAA,+CAIyB;AAKzB,kDAA8C;AAC9C,sDAAkD;AAOlD,SAAgB,oBAAoB,CAClC,UAAsB,EACtB,OAAoC;IAGpC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAG/B,MAAM,eAAe,GAAG,IAAA,wBAAY,EAAC,IAAA,oBAAQ,EAAC,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GAAG,IAAA,0BAAW,EAClC,UAAU,EACV,eAAe,EACf;QACE,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE;YACV;gBACE,IAAI,EAAE,YAAY;gBAClB,SAAS,EAAE,CAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAA,qBAAS,EAAC,IAAI,CAAC,CAAC,CAAE;aACrD;SACF;KACF,CACF,CAAC;IAEF,IAAA,8BAAa,EAAC,UAAU,EAAE;QACxB,YAAY,EAAE,CAAE,YAAY,CAAE;QAC9B,eAAe,EAAE,gBAAgB;KAClC,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAE1B,CAAC;AA/BD,oDA+BC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestEnvironmentProvider = void 0;
|
|
4
|
+
const coerce_nest_module_provider_1 = require("./coerce-nest-module-provider");
|
|
5
|
+
function CoerceNestEnvironmentProvider(sourceFile) {
|
|
6
|
+
(0, coerce_nest_module_provider_1.CoerceNestModuleProvider)(sourceFile, {
|
|
7
|
+
providerObject: {
|
|
8
|
+
provide: 'ENVIRONMENT',
|
|
9
|
+
useValue: 'environment',
|
|
10
|
+
},
|
|
11
|
+
structures: [
|
|
12
|
+
{
|
|
13
|
+
namedImports: ['ENVIRONMENT'],
|
|
14
|
+
moduleSpecifier: '@rxap/nest-utilities',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
namedImports: ['environment'],
|
|
18
|
+
moduleSpecifier: '../environments/environment',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.CoerceNestEnvironmentProvider = CoerceNestEnvironmentProvider;
|
|
24
|
+
//# sourceMappingURL=coerce-nest-environment-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-environment-provider.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-environment-provider.ts"],"names":[],"mappings":";;;AACA,+EAAyE;AAEzE,SAAgB,6BAA6B,CAAC,UAAsB;IAClE,IAAA,sDAAwB,EACtB,UAAU,EACV;QACE,cAAc,EACZ;YACE,OAAO,EAAE,aAAa;YACtB,QAAQ,EAAE,aAAa;SACxB;QACH,UAAU,EAAE;YACV;gBACE,YAAY,EAAE,CAAE,aAAa,CAAE;gBAC/B,eAAe,EAAE,sBAAsB;aACxC;YACD;gBACE,YAAY,EAAE,CAAE,aAAa,CAAE;gBAC/B,eAAe,EAAE,6BAA6B;aAC/C;SACF;KACF,CACF,CAAC;AACJ,CAAC;AArBD,sEAqBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestLoggerProvider = void 0;
|
|
4
|
+
const coerce_nest_module_provider_1 = require("./coerce-nest-module-provider");
|
|
5
|
+
function CoerceNestLoggerProvider(sourceFile) {
|
|
6
|
+
(0, coerce_nest_module_provider_1.CoerceNestModuleProvider)(sourceFile, {
|
|
7
|
+
providerObject: {
|
|
8
|
+
provide: 'ENVIRONMENT',
|
|
9
|
+
useValue: 'environment',
|
|
10
|
+
},
|
|
11
|
+
structures: [
|
|
12
|
+
{
|
|
13
|
+
namedImports: ['ENVIRONMENT'],
|
|
14
|
+
moduleSpecifier: '@rxap/nest-utilities',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
namedImports: ['environment'],
|
|
18
|
+
moduleSpecifier: '../environments/environment',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.CoerceNestLoggerProvider = CoerceNestLoggerProvider;
|
|
24
|
+
//# sourceMappingURL=coerce-nest-logger-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-logger-provider.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-logger-provider.ts"],"names":[],"mappings":";;;AACA,+EAAyE;AAEzE,SAAgB,wBAAwB,CAAC,UAAsB;IAC7D,IAAA,sDAAwB,EACtB,UAAU,EACV;QACE,cAAc,EACZ;YACE,OAAO,EAAE,aAAa;YACtB,QAAQ,EAAE,aAAa;SACxB;QACH,UAAU,EAAE;YACV;gBACE,YAAY,EAAE,CAAE,aAAa,CAAE;gBAC/B,eAAe,EAAE,sBAAsB;aACxC;YACD;gBACE,YAAY,EAAE,CAAE,aAAa,CAAE;gBAC/B,eAAe,EAAE,6BAA6B;aAC/C;SACF;KACF,CACF,CAAC;AACJ,CAAC;AArBD,4DAqBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ImportDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph';
|
|
2
|
+
export interface CoerceNestModuleControllerOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
structures?: Array<OptionalKind<ImportDeclarationStructure>>;
|
|
5
|
+
overwrite?: boolean;
|
|
6
|
+
moduleSpecifier?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function CoerceNestModuleController(sourceFile: SourceFile, options: CoerceNestModuleControllerOptions): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestModuleController = void 0;
|
|
4
|
+
const coerce_imports_1 = require("../coerce-imports");
|
|
5
|
+
const get_coerce_array_literal_form_object_literal_1 = require("../get-coerce-array-literal-form-object-literal");
|
|
6
|
+
const coerce_nest_provider_to_array_1 = require("./coerce-nest-provider-to-array");
|
|
7
|
+
const get_nest_module_metadata_1 = require("./get-nest-module-metadata");
|
|
8
|
+
function CoerceNestModuleController(sourceFile, options) {
|
|
9
|
+
const { name, overwrite, moduleSpecifier } = options;
|
|
10
|
+
let { structures } = options;
|
|
11
|
+
structures !== null && structures !== void 0 ? structures : (structures = []);
|
|
12
|
+
if (moduleSpecifier) {
|
|
13
|
+
structures.push({
|
|
14
|
+
moduleSpecifier,
|
|
15
|
+
namedImports: [name],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
(0, coerce_imports_1.CoerceImports)(sourceFile, structures);
|
|
19
|
+
const metadata = (0, get_nest_module_metadata_1.GetNestModuleMetadata)(sourceFile);
|
|
20
|
+
const providerArray = (0, get_coerce_array_literal_form_object_literal_1.GetCoerceArrayLiteralFromObjectLiteral)(metadata, 'controllers');
|
|
21
|
+
(0, coerce_nest_provider_to_array_1.CoerceNestProviderToArray)(name, providerArray, overwrite);
|
|
22
|
+
}
|
|
23
|
+
exports.CoerceNestModuleController = CoerceNestModuleController;
|
|
24
|
+
//# sourceMappingURL=coerce-nest-module-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-module-controller.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-module-controller.ts"],"names":[],"mappings":";;;AAKA,sDAAkD;AAClD,kHAAyG;AACzG,mFAA4E;AAC5E,yEAAmE;AASnE,SAAgB,0BAA0B,CACxC,UAAsB,EACtB,OAA0C;IAG1C,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACrD,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE7B,UAAU,aAAV,UAAU,cAAV,UAAU,IAAV,UAAU,GAAK,EAAE,EAAC;IAElB,IAAI,eAAe,EAAE;QACnB,UAAU,CAAC,IAAI,CAAC;YACd,eAAe;YACf,YAAY,EAAE,CAAE,IAAI,CAAE;SACvB,CAAC,CAAC;KACJ;IAED,IAAA,8BAAa,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAG,IAAA,gDAAqB,EAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,aAAa,GAAG,IAAA,qFAAsC,EAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAEtF,IAAA,yDAAyB,EAAC,IAAI,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AAE5D,CAAC;AAzBD,gEAyBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ImportDeclarationStructure, OptionalKind, SourceFile, WriterFunction } from 'ts-morph';
|
|
2
|
+
export interface CoerceNestModuleImportOptions {
|
|
3
|
+
moduleName: string;
|
|
4
|
+
structures?: Array<OptionalKind<ImportDeclarationStructure>>;
|
|
5
|
+
importWriter?: WriterFunction;
|
|
6
|
+
overwrite?: boolean;
|
|
7
|
+
moduleSpecifier?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function CoerceNestModuleImport(sourceFile: SourceFile, options: CoerceNestModuleImportOptions): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestModuleImport = void 0;
|
|
4
|
+
const coerce_imports_1 = require("../coerce-imports");
|
|
5
|
+
const get_coerce_array_literal_form_object_literal_1 = require("../get-coerce-array-literal-form-object-literal");
|
|
6
|
+
const get_nest_module_metadata_1 = require("./get-nest-module-metadata");
|
|
7
|
+
function CoerceNestModuleImport(sourceFile, options) {
|
|
8
|
+
const { moduleName, importWriter, overwrite, moduleSpecifier, } = options;
|
|
9
|
+
let { structures } = options;
|
|
10
|
+
structures !== null && structures !== void 0 ? structures : (structures = []);
|
|
11
|
+
if (moduleSpecifier) {
|
|
12
|
+
structures.push({
|
|
13
|
+
moduleSpecifier,
|
|
14
|
+
namedImports: [moduleName],
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
(0, coerce_imports_1.CoerceImports)(sourceFile, structures !== null && structures !== void 0 ? structures : []);
|
|
18
|
+
const metadata = (0, get_nest_module_metadata_1.GetNestModuleMetadata)(sourceFile);
|
|
19
|
+
const importsArray = (0, get_coerce_array_literal_form_object_literal_1.GetCoerceArrayLiteralFromObjectLiteral)(metadata, 'imports');
|
|
20
|
+
const index = importsArray.getElements().findIndex(element => element.getFullText().trim().startsWith(moduleName));
|
|
21
|
+
if (index === -1 || overwrite) {
|
|
22
|
+
if (index !== -1) {
|
|
23
|
+
importsArray.removeElement(index);
|
|
24
|
+
}
|
|
25
|
+
importsArray.addElement(importWriter !== null && importWriter !== void 0 ? importWriter : moduleName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CoerceNestModuleImport = CoerceNestModuleImport;
|
|
29
|
+
//# sourceMappingURL=coerce-nest-module-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-module-import.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-module-import.ts"],"names":[],"mappings":";;;AAMA,sDAAkD;AAClD,kHAAyG;AACzG,yEAAmE;AAUnE,SAAgB,sBAAsB,CACpC,UAAsB,EACtB,OAAsC;IAEtC,MAAM,EACJ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE7B,UAAU,aAAV,UAAU,cAAV,UAAU,IAAV,UAAU,GAAK,EAAE,EAAC;IAElB,IAAI,eAAe,EAAE;QACnB,UAAU,CAAC,IAAI,CAAC;YACd,eAAe;YACf,YAAY,EAAE,CAAE,UAAU,CAAE;SAC7B,CAAC,CAAC;KACJ;IAED,IAAA,8BAAa,EAAC,UAAU,EAAE,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,EAAE,CAAC,CAAC;IAE5C,MAAM,QAAQ,GAAG,IAAA,gDAAqB,EAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,YAAY,GAAG,IAAA,qFAAsC,EAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEjF,MAAM,KAAK,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IAEnH,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,SAAS,EAAE;QAE7B,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YAChB,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;SACnC;QAED,YAAY,CAAC,UAAU,CAAC,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,UAAU,CAAC,CAAC;KAErD;AAEH,CAAC;AAxCD,wDAwCC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ImportDeclarationStructure, OptionalKind, SourceFile } from 'ts-morph';
|
|
2
|
+
import { NestProviderObject } from './nest-provider-object';
|
|
3
|
+
export interface CoerceNestModuleProviderOptions {
|
|
4
|
+
providerObject: NestProviderObject | string;
|
|
5
|
+
moduleSpecifier?: string;
|
|
6
|
+
structures?: Array<OptionalKind<ImportDeclarationStructure>>;
|
|
7
|
+
overwrite?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function CoerceNestModuleProvider(sourceFile: SourceFile, options: CoerceNestModuleProviderOptions): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestModuleProvider = void 0;
|
|
4
|
+
const coerce_imports_1 = require("../coerce-imports");
|
|
5
|
+
const get_coerce_array_literal_form_object_literal_1 = require("../get-coerce-array-literal-form-object-literal");
|
|
6
|
+
const coerce_nest_provider_to_array_1 = require("./coerce-nest-provider-to-array");
|
|
7
|
+
const get_nest_module_metadata_1 = require("./get-nest-module-metadata");
|
|
8
|
+
function CoerceNestModuleProvider(sourceFile, options) {
|
|
9
|
+
const { providerObject, overwrite, moduleSpecifier, } = options;
|
|
10
|
+
let { structures } = options;
|
|
11
|
+
structures !== null && structures !== void 0 ? structures : (structures = []);
|
|
12
|
+
if (moduleSpecifier && typeof providerObject === 'string') {
|
|
13
|
+
structures.push({
|
|
14
|
+
moduleSpecifier,
|
|
15
|
+
namedImports: [providerObject],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
(0, coerce_imports_1.CoerceImports)(sourceFile, structures);
|
|
19
|
+
const metadata = (0, get_nest_module_metadata_1.GetNestModuleMetadata)(sourceFile);
|
|
20
|
+
const providerArray = (0, get_coerce_array_literal_form_object_literal_1.GetCoerceArrayLiteralFromObjectLiteral)(metadata, 'providers');
|
|
21
|
+
(0, coerce_nest_provider_to_array_1.CoerceNestProviderToArray)(providerObject, providerArray, overwrite);
|
|
22
|
+
}
|
|
23
|
+
exports.CoerceNestModuleProvider = CoerceNestModuleProvider;
|
|
24
|
+
//# sourceMappingURL=coerce-nest-module-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-module-provider.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-module-provider.ts"],"names":[],"mappings":";;;AAKA,sDAAkD;AAClD,kHAAyG;AACzG,mFAA4E;AAC5E,yEAAmE;AAUnE,SAAgB,wBAAwB,CACtC,UAAsB,EACtB,OAAwC;IAGxC,MAAM,EACJ,cAAc,EACd,SAAS,EACT,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE7B,UAAU,aAAV,UAAU,cAAV,UAAU,IAAV,UAAU,GAAK,EAAE,EAAC;IAClB,IAAI,eAAe,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACzD,UAAU,CAAC,IAAI,CAAC;YACd,eAAe;YACf,YAAY,EAAE,CAAE,cAAc,CAAE;SACjC,CAAC,CAAC;KACJ;IAED,IAAA,8BAAa,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAG,IAAA,gDAAqB,EAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,aAAa,GAAG,IAAA,qFAAsC,EAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAEpF,IAAA,yDAAyB,EAAC,cAAc,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AAEtE,CAAC;AA7BD,4DA6BC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClassDeclaration, SourceFile } from 'ts-morph';
|
|
2
|
+
export interface CoerceNestModuleOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
tsMorphTransform?: (sourceFile: SourceFile, classDeclaration: ClassDeclaration) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function CoerceNestModule(sourceFile: SourceFile, options: CoerceNestModuleOptions): ClassDeclaration;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestModule = void 0;
|
|
4
|
+
const utilities_1 = require("@rxap/utilities");
|
|
5
|
+
const coerce_class_1 = require("../coerce-class");
|
|
6
|
+
const coerce_imports_1 = require("../coerce-imports");
|
|
7
|
+
function CoerceNestModule(sourceFile, options) {
|
|
8
|
+
const { name } = options;
|
|
9
|
+
let { tsMorphTransform } = options;
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
11
|
+
tsMorphTransform !== null && tsMorphTransform !== void 0 ? tsMorphTransform : (tsMorphTransform = () => { });
|
|
12
|
+
const classDeclaration = (0, coerce_class_1.CoerceClass)(sourceFile, (0, utilities_1.classify)(name) + 'Module', {
|
|
13
|
+
isExported: true,
|
|
14
|
+
decorators: [
|
|
15
|
+
{
|
|
16
|
+
name: 'Module',
|
|
17
|
+
arguments: ['{}'],
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
(0, coerce_imports_1.CoerceImports)(sourceFile, [
|
|
22
|
+
{
|
|
23
|
+
namedImports: ['Module'],
|
|
24
|
+
moduleSpecifier: '@nestjs/common',
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
tsMorphTransform(sourceFile, classDeclaration);
|
|
28
|
+
return classDeclaration;
|
|
29
|
+
}
|
|
30
|
+
exports.CoerceNestModule = CoerceNestModule;
|
|
31
|
+
//# sourceMappingURL=coerce-nest-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-nest-module.js","sourceRoot":"","sources":["../../../../../../packages/ts-morph/src/lib/nest/coerce-nest-module.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAK3C,kDAA8C;AAC9C,sDAAkD;AAOlD,SAAgB,gBAAgB,CAC9B,UAAsB,EACtB,OAAgC;IAEhC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,IAAI,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IACnC,gEAAgE;IAChE,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,IAAhB,gBAAgB,GAAK,GAAG,EAAE,GAAE,CAAC,EAAC;IAE9B,MAAM,gBAAgB,GAAG,IAAA,0BAAW,EAAC,UAAU,EAAE,IAAA,oBAAQ,EAAC,IAAI,CAAC,GAAG,QAAQ,EAAE;QAC1E,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE;YACV;gBACE,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,CAAE,IAAI,CAAE;aACpB;SACF;KACF,CAAC,CAAC;IACH,IAAA,8BAAa,EAAC,UAAU,EAAE;QACxB;YACE,YAAY,EAAE,CAAE,QAAQ,CAAE;YAC1B,eAAe,EAAE,gBAAgB;SAClC;KACF,CAAC,CAAC;IAEH,gBAAiB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAEhD,OAAO,gBAAgB,CAAC;AAE1B,CAAC;AA7BD,4CA6BC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ClassDeclaration, DecoratorStructure, MethodDeclaration, OptionalKind, SourceFile, StatementStructures, WriterFunction } from 'ts-morph';
|
|
2
|
+
export interface OperationParameter {
|
|
3
|
+
name: string;
|
|
4
|
+
type?: string | WriterFunction;
|
|
5
|
+
pipeList?: Array<string | WriterFunction>;
|
|
6
|
+
defaultValue?: string | WriterFunction;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
isArray?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* (optional) the method parameter name. If not defined the name property will be used
|
|
11
|
+
*/
|
|
12
|
+
alias?: string;
|
|
13
|
+
/**
|
|
14
|
+
* true - the parameter is a parent parameter.
|
|
15
|
+
* Example
|
|
16
|
+
* @Controller('/user/:uuid')
|
|
17
|
+
* ...
|
|
18
|
+
* @Get('/profile')
|
|
19
|
+
*
|
|
20
|
+
* In this case the uuid parameter should not be added to the operation path.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
fromParent?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface CoerceOperationOptions {
|
|
26
|
+
controllerName?: string;
|
|
27
|
+
tsMorphTransform?: (sourceFile: SourceFile, classDeclaration: ClassDeclaration, methodDeclaration: MethodDeclaration, options: CoerceOperationOptions) => void;
|
|
28
|
+
paramList?: OperationParameter[];
|
|
29
|
+
queryList?: OperationParameter[];
|
|
30
|
+
operationName: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
returnType?: string | WriterFunction;
|
|
33
|
+
isAsync?: boolean;
|
|
34
|
+
method?: string;
|
|
35
|
+
body?: string | WriterFunction;
|
|
36
|
+
statements?: (string | WriterFunction | StatementStructures)[] | string | WriterFunction;
|
|
37
|
+
decorators?: OptionalKind<DecoratorStructure>[];
|
|
38
|
+
}
|
|
39
|
+
export declare function CoerceOperationParamList(paramList: OperationParameter[], classDeclaration: ClassDeclaration): void;
|
|
40
|
+
export declare function CoerceNestOperation(sourceFile: SourceFile, options: CoerceOperationOptions): MethodDeclaration;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoerceNestOperation = exports.CoerceOperationParamList = void 0;
|
|
4
|
+
const utilities_1 = require("@rxap/utilities");
|
|
5
|
+
const ts_morph_1 = require("ts-morph");
|
|
6
|
+
const coerce_class_method_1 = require("../coerce-class-method");
|
|
7
|
+
const coerce_decorator_1 = require("../coerce-decorator");
|
|
8
|
+
const coerce_imports_1 = require("../coerce-imports");
|
|
9
|
+
const coerce_statements_1 = require("../coerce-statements");
|
|
10
|
+
const get_controller_class_1 = require("./get-controller-class");
|
|
11
|
+
function buildMethodQueryParameters(queryList, importStructures) {
|
|
12
|
+
if (queryList.length) {
|
|
13
|
+
return queryList.map(query => {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
if (query.defaultValue ===
|
|
16
|
+
undefined) {
|
|
17
|
+
return query;
|
|
18
|
+
}
|
|
19
|
+
importStructures.push({
|
|
20
|
+
namedImports: ['DefaultValuePipe'],
|
|
21
|
+
moduleSpecifier: '@nestjs/common',
|
|
22
|
+
});
|
|
23
|
+
const pipeList = (_b = (_a = query.pipeList) === null || _a === void 0 ? void 0 : _a.slice()) !== null && _b !== void 0 ? _b : [];
|
|
24
|
+
pipeList.push(w => {
|
|
25
|
+
w.write('new DefaultValuePipe(');
|
|
26
|
+
if (typeof query.defaultValue === 'string') {
|
|
27
|
+
w.write(query.defaultValue);
|
|
28
|
+
}
|
|
29
|
+
else if (typeof query.defaultValue === 'function') {
|
|
30
|
+
query.defaultValue(w);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error('Invalid default value. Must be a string or a function');
|
|
34
|
+
}
|
|
35
|
+
w.write(')');
|
|
36
|
+
});
|
|
37
|
+
return Object.assign(Object.assign({}, query), { pipeList });
|
|
38
|
+
}).map(query => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
return ({
|
|
41
|
+
name: (_a = query.alias) !== null && _a !== void 0 ? _a : query.name,
|
|
42
|
+
type: query.type,
|
|
43
|
+
hasQuestionToken: !query.required &&
|
|
44
|
+
query.defaultValue ===
|
|
45
|
+
undefined,
|
|
46
|
+
decorators: [
|
|
47
|
+
{
|
|
48
|
+
name: 'Query',
|
|
49
|
+
arguments: [
|
|
50
|
+
w => w.quote(query.name),
|
|
51
|
+
...((_b = query.pipeList) !== null && _b !== void 0 ? _b : []),
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
function buildMethodParamParameters(paramList) {
|
|
61
|
+
if (paramList.length) {
|
|
62
|
+
return paramList.map(param => {
|
|
63
|
+
var _a;
|
|
64
|
+
return ({
|
|
65
|
+
name: (_a = param.alias) !== null && _a !== void 0 ? _a : param.name,
|
|
66
|
+
type: param.type,
|
|
67
|
+
decorators: [
|
|
68
|
+
{
|
|
69
|
+
name: 'Param',
|
|
70
|
+
arguments: [w => w.quote(param.name)],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
function buildMethodBodyParameters(body) {
|
|
79
|
+
if (body) {
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
name: 'body',
|
|
83
|
+
type: body,
|
|
84
|
+
decorators: [
|
|
85
|
+
{
|
|
86
|
+
name: 'Body',
|
|
87
|
+
arguments: [],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
function coerceApiQueryDecorators(queryList, methodDeclaration) {
|
|
96
|
+
for (const query of queryList) {
|
|
97
|
+
(0, coerce_decorator_1.CoerceDecorator)(methodDeclaration, 'ApiQuery', {
|
|
98
|
+
arguments: [
|
|
99
|
+
ts_morph_1.Writers.object({
|
|
100
|
+
name: w => w.quote(query.name),
|
|
101
|
+
required: query.required ? 'true' : 'false',
|
|
102
|
+
isArray: query.isArray ? 'true' : 'false',
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
}, () => decorator => {
|
|
106
|
+
var _a;
|
|
107
|
+
if (decorator.getArguments().length) {
|
|
108
|
+
const [objectLiteralExpression] = decorator.getArguments();
|
|
109
|
+
if (objectLiteralExpression instanceof ts_morph_1.ObjectLiteralExpression) {
|
|
110
|
+
const namePropertyElement = objectLiteralExpression.getProperty('name');
|
|
111
|
+
if (namePropertyElement instanceof ts_morph_1.PropertyAssignment) {
|
|
112
|
+
const name = (_a = namePropertyElement.getInitializer()) === null || _a === void 0 ? void 0 : _a.getText().trim().replace(/^'/, '').replace(/'$/, '');
|
|
113
|
+
return name === query.name;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function CoerceOperationParamList(paramList, classDeclaration) {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
const currentControllerPath = (_b = (_a = classDeclaration.getDecoratorOrThrow('Controller').getArguments()[0]) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _b !== void 0 ? _b : '';
|
|
124
|
+
const fragments = currentControllerPath.split('/');
|
|
125
|
+
const parameters = fragments.filter(fragment => fragment.startsWith(':'));
|
|
126
|
+
for (const parameter of parameters) {
|
|
127
|
+
if (!paramList.some(param => param.name === parameter.substr(1))) {
|
|
128
|
+
paramList.push({ name: parameter.substr(1) });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.CoerceOperationParamList = CoerceOperationParamList;
|
|
133
|
+
function CoerceNestOperation(sourceFile, options) {
|
|
134
|
+
const { operationName, queryList = [], paramList = [], tsMorphTransform = () => void 0, returnType = 'void', isAsync, body, decorators = [], } = options;
|
|
135
|
+
let { method = 'get', path, statements, } = options;
|
|
136
|
+
const classDeclaration = (0, get_controller_class_1.GetControllerClass)(sourceFile);
|
|
137
|
+
CoerceOperationParamList(paramList, classDeclaration);
|
|
138
|
+
method = (0, utilities_1.capitalize)(method.toLowerCase());
|
|
139
|
+
queryList.forEach(query => {
|
|
140
|
+
var _a;
|
|
141
|
+
query.name = (0, utilities_1.camelize)(query.name);
|
|
142
|
+
if (query.alias) {
|
|
143
|
+
query.alias = (0, utilities_1.camelize)(query.alias);
|
|
144
|
+
}
|
|
145
|
+
(_a = query.type) !== null && _a !== void 0 ? _a : (query.type = 'string');
|
|
146
|
+
});
|
|
147
|
+
paramList.forEach(param => {
|
|
148
|
+
var _a;
|
|
149
|
+
param.name = (0, utilities_1.camelize)(param.name);
|
|
150
|
+
if (param.alias) {
|
|
151
|
+
param.alias = (0, utilities_1.camelize)(param.alias);
|
|
152
|
+
}
|
|
153
|
+
(_a = param.type) !== null && _a !== void 0 ? _a : (param.type = 'string');
|
|
154
|
+
});
|
|
155
|
+
const importStructures = [
|
|
156
|
+
{
|
|
157
|
+
namedImports: [method],
|
|
158
|
+
moduleSpecifier: '@nestjs/common',
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
if (!statements) {
|
|
162
|
+
statements = ['throw new NotImplementedException();'];
|
|
163
|
+
importStructures.push({
|
|
164
|
+
namedImports: ['NotImplementedException'],
|
|
165
|
+
moduleSpecifier: '@nestjs/common',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (queryList.length) {
|
|
169
|
+
importStructures.push({
|
|
170
|
+
namedImports: ['Query'],
|
|
171
|
+
moduleSpecifier: '@nestjs/common',
|
|
172
|
+
});
|
|
173
|
+
importStructures.push({
|
|
174
|
+
namedImports: ['ApiQuery'],
|
|
175
|
+
moduleSpecifier: '@nestjs/swagger',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (paramList.length) {
|
|
179
|
+
importStructures.push({
|
|
180
|
+
namedImports: ['Param'],
|
|
181
|
+
moduleSpecifier: '@nestjs/common',
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (body) {
|
|
185
|
+
importStructures.push({
|
|
186
|
+
namedImports: ['Body'],
|
|
187
|
+
moduleSpecifier: '@nestjs/common',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (!path) {
|
|
191
|
+
if (paramList.filter(param => !param.fromParent).length) {
|
|
192
|
+
path = paramList.filter(param => !param.fromParent).map(param => `:${param.name}`).join('/');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const match = path.match(/:(\w+)/g);
|
|
197
|
+
for (const param of match !== null && match !== void 0 ? match : []) {
|
|
198
|
+
if (!paramList.find(p => p.name === param.substr(1))) {
|
|
199
|
+
paramList.push({
|
|
200
|
+
name: param.substr(1),
|
|
201
|
+
type: 'string',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// TODO : check that all defined param in the paramList are present in the path
|
|
207
|
+
const methodDeclaration = (0, coerce_class_method_1.CoerceClassMethod)(classDeclaration, (0, utilities_1.camelize)(operationName), {
|
|
208
|
+
scope: ts_morph_1.Scope.Public,
|
|
209
|
+
isAsync,
|
|
210
|
+
parameters: [
|
|
211
|
+
...buildMethodQueryParameters(queryList, importStructures),
|
|
212
|
+
...buildMethodParamParameters(paramList),
|
|
213
|
+
...buildMethodBodyParameters(body),
|
|
214
|
+
].sort((a, b) => {
|
|
215
|
+
if (a.hasQuestionToken && b.hasQuestionToken) {
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
return a.hasQuestionToken ? 1 : -1;
|
|
219
|
+
}),
|
|
220
|
+
});
|
|
221
|
+
if (returnType) {
|
|
222
|
+
if (isAsync) {
|
|
223
|
+
methodDeclaration.setReturnType(w => {
|
|
224
|
+
w.write('Promise<');
|
|
225
|
+
if (typeof returnType === 'string') {
|
|
226
|
+
w.write(returnType);
|
|
227
|
+
}
|
|
228
|
+
else if (typeof returnType === 'function') {
|
|
229
|
+
returnType(w);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
throw new Error('Invalid return type. Must be a string or a function');
|
|
233
|
+
}
|
|
234
|
+
w.write('>');
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
methodDeclaration.setReturnType(returnType);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
decorators.forEach(decorator => {
|
|
242
|
+
(0, coerce_decorator_1.CoerceDecorator)(methodDeclaration, decorator.name, decorator);
|
|
243
|
+
});
|
|
244
|
+
(0, coerce_decorator_1.CoerceDecorator)(methodDeclaration, method, { arguments: path ? [w => w.quote(path)] : [] })
|
|
245
|
+
.set({ arguments: path ? [w => w.quote(path)] : [] });
|
|
246
|
+
coerceApiQueryDecorators(queryList, methodDeclaration);
|
|
247
|
+
(0, coerce_statements_1.CoerceStatements)(methodDeclaration, statements);
|
|
248
|
+
(0, coerce_imports_1.CoerceImports)(sourceFile, importStructures);
|
|
249
|
+
tsMorphTransform(sourceFile, classDeclaration, methodDeclaration, options);
|
|
250
|
+
return methodDeclaration;
|
|
251
|
+
}
|
|
252
|
+
exports.CoerceNestOperation = CoerceNestOperation;
|
|
253
|
+
//# sourceMappingURL=coerce-nest-operation.js.map
|