@rxap/schematics-ts-morph 18.0.3-dev.0 → 18.0.3-dev.1
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 +4 -0
- package/package.json +8 -8
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -3
- package/src/index.js.map +1 -1
- package/src/lib/nest/coerce-autocomplete-options-operation.d.ts +2 -2
- package/src/lib/nest/coerce-autocomplete-options-operation.js.map +1 -1
- package/src/lib/nest/coerce-form-submit-operation.js +1 -1
- package/src/lib/nest/coerce-form-submit-operation.js.map +1 -1
- package/src/lib/nest/coerce-get-by-id-operation.d.ts +2 -2
- package/src/lib/nest/coerce-get-by-id-operation.js +7 -7
- package/src/lib/nest/coerce-get-by-id-operation.js.map +1 -1
- package/src/lib/nest/coerce-get-operation.d.ts +1 -1
- package/src/lib/nest/coerce-get-operation.js.map +1 -1
- package/src/lib/nest/coerce-get-page-operation.d.ts +4 -5
- package/src/lib/nest/coerce-get-page-operation.js +4 -3
- package/src/lib/nest/coerce-get-page-operation.js.map +1 -1
- package/src/lib/nest/coerce-get-root-operation.d.ts +2 -3
- package/src/lib/nest/coerce-get-root-operation.js +1 -1
- package/src/lib/nest/coerce-get-root-operation.js.map +1 -1
- package/src/lib/nest/coerce-operation.d.ts +3 -45
- package/src/lib/nest/coerce-operation.js +3 -201
- package/src/lib/nest/coerce-operation.js.map +1 -1
- package/src/lib/nest/coerce-options-operation.d.ts +3 -3
- package/src/lib/nest/coerce-options-operation.js.map +1 -1
- package/src/lib/nest/coerce-page-dto-class.d.ts +2 -2
- package/src/lib/nest/coerce-page-dto-class.js +2 -2
- package/src/lib/nest/coerce-page-dto-class.js.map +1 -1
- package/src/lib/nest/coerce-row-dto-class.d.ts +2 -2
- package/src/lib/nest/coerce-row-dto-class.js +2 -2
- package/src/lib/nest/coerce-row-dto-class.js.map +1 -1
- package/src/lib/nest/coerce-table-select-value-resolve-operation.d.ts +2 -2
- package/src/lib/nest/table-query-list.d.ts +1 -1
- package/src/lib/nest/add-operation-to-controller.d.ts +0 -41
- package/src/lib/nest/add-operation-to-controller.js +0 -238
- package/src/lib/nest/add-operation-to-controller.js.map +0 -1
- package/src/lib/nest/coerce-dto-class.d.ts +0 -16
- package/src/lib/nest/coerce-dto-class.js +0 -228
- package/src/lib/nest/coerce-dto-class.js.map +0 -1
- package/src/lib/nest/dto-class-property.d.ts +0 -11
- package/src/lib/nest/dto-class-property.js +0 -30
- package/src/lib/nest/dto-class-property.js.map +0 -1
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AddOperationToController = void 0;
|
|
4
|
-
const schematics_utilities_1 = require("@rxap/schematics-utilities");
|
|
5
|
-
const ts_morph_1 = require("@rxap/ts-morph");
|
|
6
|
-
const utilities_1 = require("@rxap/utilities");
|
|
7
|
-
const ts_morph_2 = require("ts-morph");
|
|
8
|
-
function buildMethodQueryParameters(queryList, sourceFile) {
|
|
9
|
-
if (queryList.length) {
|
|
10
|
-
return queryList.map(query => {
|
|
11
|
-
var _a, _b;
|
|
12
|
-
if (query.defaultValue ===
|
|
13
|
-
undefined) {
|
|
14
|
-
return query;
|
|
15
|
-
}
|
|
16
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
17
|
-
namedImports: ['DefaultValuePipe'],
|
|
18
|
-
moduleSpecifier: '@nestjs/common',
|
|
19
|
-
});
|
|
20
|
-
const pipeList = (_b = (_a = query.pipeList) === null || _a === void 0 ? void 0 : _a.slice()) !== null && _b !== void 0 ? _b : [];
|
|
21
|
-
pipeList.push(w => {
|
|
22
|
-
w.write('new DefaultValuePipe(');
|
|
23
|
-
if (typeof query.defaultValue === 'string') {
|
|
24
|
-
w.write(query.defaultValue);
|
|
25
|
-
}
|
|
26
|
-
else if (typeof query.defaultValue === 'function') {
|
|
27
|
-
query.defaultValue(w);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new Error('Invalid default value. Must be a string or a function');
|
|
31
|
-
}
|
|
32
|
-
w.write(')');
|
|
33
|
-
});
|
|
34
|
-
return Object.assign(Object.assign({}, query), { pipeList });
|
|
35
|
-
}).map(({ alias, name, type, hasQuestionToken, required, defaultValue, pipeList = [], isArray }) => ({
|
|
36
|
-
name: alias !== null && alias !== void 0 ? alias : name,
|
|
37
|
-
type: (0, ts_morph_1.WriteType)({ type: type !== null && type !== void 0 ? type : 'unknown', isArray: isArray }, sourceFile),
|
|
38
|
-
hasQuestionToken: hasQuestionToken !== null && hasQuestionToken !== void 0 ? hasQuestionToken : (!required && defaultValue === undefined),
|
|
39
|
-
decorators: [
|
|
40
|
-
{
|
|
41
|
-
name: 'Query',
|
|
42
|
-
arguments: [
|
|
43
|
-
w => w.quote(name),
|
|
44
|
-
...pipeList.map(pipe => {
|
|
45
|
-
if (typeof pipe === 'string') {
|
|
46
|
-
return pipe;
|
|
47
|
-
}
|
|
48
|
-
if (typeof pipe === 'function') {
|
|
49
|
-
return pipe;
|
|
50
|
-
}
|
|
51
|
-
return (0, ts_morph_1.WriteType)(pipe, sourceFile);
|
|
52
|
-
}),
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
function buildMethodParamParameters(paramList, sourceFile) {
|
|
61
|
-
if (paramList.length) {
|
|
62
|
-
return paramList.map(({ alias, name, type }) => ({
|
|
63
|
-
name: alias !== null && alias !== void 0 ? alias : name,
|
|
64
|
-
type: type ? (0, ts_morph_1.WriteType)({
|
|
65
|
-
type: type,
|
|
66
|
-
isArray: false
|
|
67
|
-
}, sourceFile) : undefined,
|
|
68
|
-
decorators: [
|
|
69
|
-
{
|
|
70
|
-
name: 'Param',
|
|
71
|
-
arguments: [w => w.quote(name)],
|
|
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 AddOperationToController(sourceFile, classDeclaration, name, options) {
|
|
96
|
-
var _a;
|
|
97
|
-
let { method, path, returnType, isAsync, paramList, queryList, body, statements, decorators, tsMorphTransform, } = options;
|
|
98
|
-
queryList !== null && queryList !== void 0 ? queryList : (queryList = []);
|
|
99
|
-
paramList !== null && paramList !== void 0 ? paramList : (paramList = []);
|
|
100
|
-
decorators !== null && decorators !== void 0 ? decorators : (decorators = []);
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
102
|
-
tsMorphTransform !== null && tsMorphTransform !== void 0 ? tsMorphTransform : (tsMorphTransform = () => { });
|
|
103
|
-
method !== null && method !== void 0 ? method : (method = 'get');
|
|
104
|
-
method = (0, schematics_utilities_1.capitalize)(method.toLowerCase());
|
|
105
|
-
queryList.forEach(query => {
|
|
106
|
-
var _a;
|
|
107
|
-
query.name = (0, schematics_utilities_1.camelize)(query.name);
|
|
108
|
-
if (query.alias) {
|
|
109
|
-
query.alias = (0, schematics_utilities_1.camelize)(query.alias);
|
|
110
|
-
}
|
|
111
|
-
(_a = query.type) !== null && _a !== void 0 ? _a : (query.type = 'string');
|
|
112
|
-
});
|
|
113
|
-
paramList.forEach(param => {
|
|
114
|
-
var _a;
|
|
115
|
-
param.name = (0, schematics_utilities_1.camelize)(param.name);
|
|
116
|
-
if (param.alias) {
|
|
117
|
-
param.alias = (0, schematics_utilities_1.camelize)(param.alias);
|
|
118
|
-
}
|
|
119
|
-
(_a = param.type) !== null && _a !== void 0 ? _a : (param.type = 'string');
|
|
120
|
-
});
|
|
121
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
122
|
-
namedImports: [method],
|
|
123
|
-
moduleSpecifier: '@nestjs/common',
|
|
124
|
-
});
|
|
125
|
-
if (queryList.length) {
|
|
126
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
127
|
-
namedImports: ['Query'],
|
|
128
|
-
moduleSpecifier: '@nestjs/common',
|
|
129
|
-
});
|
|
130
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
131
|
-
namedImports: ['ApiQuery'],
|
|
132
|
-
moduleSpecifier: '@nestjs/swagger',
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
if (paramList.length) {
|
|
136
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
137
|
-
namedImports: ['Param'],
|
|
138
|
-
moduleSpecifier: '@nestjs/common',
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if (body) {
|
|
142
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
143
|
-
namedImports: ['Body'],
|
|
144
|
-
moduleSpecifier: '@nestjs/common',
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
if (!path) {
|
|
148
|
-
if (paramList.filter(param => !param.fromParent).length) {
|
|
149
|
-
path = paramList.filter(param => !param.fromParent).map(param => `:${param.name}`).join('/');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
const match = path.match(/:(\w+)/g);
|
|
154
|
-
for (const param of match !== null && match !== void 0 ? match : []) {
|
|
155
|
-
if (!paramList.find(p => p.name === param.substr(1))) {
|
|
156
|
-
paramList.push({
|
|
157
|
-
name: param.substr(1),
|
|
158
|
-
type: 'string',
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// TODO : check that all defined param in the paramList are present in the path
|
|
164
|
-
returnType !== null && returnType !== void 0 ? returnType : (returnType = 'void');
|
|
165
|
-
const methodDeclaration = (0, ts_morph_1.CoerceClassMethod)(classDeclaration, (0, schematics_utilities_1.camelize)(name), {
|
|
166
|
-
scope: ts_morph_2.Scope.Public,
|
|
167
|
-
isAsync,
|
|
168
|
-
returnType: !isAsync ? returnType : returnType ? (w) => {
|
|
169
|
-
w.write('Promise<');
|
|
170
|
-
if (typeof returnType === 'string') {
|
|
171
|
-
w.write(returnType);
|
|
172
|
-
}
|
|
173
|
-
else if (typeof returnType === 'function') {
|
|
174
|
-
returnType(w);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
throw new Error('Invalid return type. Must be a string or a function');
|
|
178
|
-
}
|
|
179
|
-
w.write('>');
|
|
180
|
-
} : undefined,
|
|
181
|
-
});
|
|
182
|
-
const existingParameters = methodDeclaration.getParameters().map(p => p.getStructure());
|
|
183
|
-
(0, utilities_1.CoerceArrayItems)(existingParameters, [
|
|
184
|
-
...buildMethodQueryParameters(queryList, sourceFile),
|
|
185
|
-
...buildMethodParamParameters(paramList, sourceFile),
|
|
186
|
-
...buildMethodBodyParameters(body),
|
|
187
|
-
], (a, b) => a.name === b.name);
|
|
188
|
-
methodDeclaration.getParameters().forEach(p => p.remove());
|
|
189
|
-
for (const parameter of existingParameters.sort((a, b) => {
|
|
190
|
-
if (a.hasQuestionToken && b.hasQuestionToken) {
|
|
191
|
-
return 0;
|
|
192
|
-
}
|
|
193
|
-
return a.hasQuestionToken ? 1 : -1;
|
|
194
|
-
})) {
|
|
195
|
-
methodDeclaration.addParameter(parameter);
|
|
196
|
-
}
|
|
197
|
-
decorators.forEach(decorator => {
|
|
198
|
-
(0, ts_morph_1.CoerceDecorator)(methodDeclaration, decorator.name, decorator);
|
|
199
|
-
});
|
|
200
|
-
(0, ts_morph_1.CoerceDecorator)(methodDeclaration, method, { arguments: path ? [w => w.quote(path)] : [] });
|
|
201
|
-
coerceApiQueryDecorators(queryList, methodDeclaration);
|
|
202
|
-
if (!statements) {
|
|
203
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
204
|
-
namedImports: ['NotImplementedException'],
|
|
205
|
-
moduleSpecifier: '@nestjs/common',
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
(0, ts_morph_1.CoerceStatements)(methodDeclaration, statements !== null && statements !== void 0 ? statements : ['throw new NotImplementedException();'], Array.isArray(options.overwrite) ? options.overwrite.includes('statements') : (_a = options.overwrite) !== null && _a !== void 0 ? _a : false);
|
|
209
|
-
tsMorphTransform(sourceFile, classDeclaration, methodDeclaration, options);
|
|
210
|
-
}
|
|
211
|
-
exports.AddOperationToController = AddOperationToController;
|
|
212
|
-
function coerceApiQueryDecorators(queryList, methodDeclaration) {
|
|
213
|
-
for (const query of queryList) {
|
|
214
|
-
(0, ts_morph_1.CoerceDecorator)(methodDeclaration, 'ApiQuery', {
|
|
215
|
-
arguments: [
|
|
216
|
-
ts_morph_2.Writers.object({
|
|
217
|
-
name: w => w.quote(query.name),
|
|
218
|
-
required: query.required ? 'true' : 'false',
|
|
219
|
-
isArray: query.isArray ? 'true' : 'false',
|
|
220
|
-
}),
|
|
221
|
-
],
|
|
222
|
-
}, () => decorator => {
|
|
223
|
-
var _a;
|
|
224
|
-
if (decorator.getArguments().length) {
|
|
225
|
-
const [objectLiteralExpression] = decorator.getArguments();
|
|
226
|
-
if (objectLiteralExpression instanceof ts_morph_2.ObjectLiteralExpression) {
|
|
227
|
-
const namePropertyElement = objectLiteralExpression.getProperty('name');
|
|
228
|
-
if (namePropertyElement instanceof ts_morph_2.PropertyAssignment) {
|
|
229
|
-
const name = (_a = namePropertyElement.getInitializer()) === null || _a === void 0 ? void 0 : _a.getText().trim().replace(/^'/, '').replace(/'$/, '');
|
|
230
|
-
return name === query.name;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return false;
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
//# sourceMappingURL=add-operation-to-controller.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add-operation-to-controller.js","sourceRoot":"","sources":["../../../../../../../packages/schematic/ts-morph/src/lib/nest/add-operation-to-controller.ts"],"names":[],"mappings":";;;AAAA,qEAIoC;AACpC,6CAOwB;AACxB,+CAAmD;AACnD,uCAakB;AAiDlB,SAAS,0BAA0B,CACjC,SAA+B,EAC/B,UAAsB;IAEtB,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACrB,OAAO,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;;YAC3B,IAAI,KAAK,CAAC,YAAY;gBACpB,SAAS,EAAE,CAAC;gBACZ,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAA,wBAAa,EAAC,UAAU,EAAC;gBACvB,YAAY,EAAE,CAAE,kBAAkB,CAAE;gBACpC,eAAe,EAAE,gBAAgB;aAClC,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,KAAK,EAAE,mCAAI,EAAE,CAAC;YAC/C,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBAChB,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;gBACjC,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;oBAC3C,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;gBAC9B,CAAC;qBAAM,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;oBACpD,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;gBACxB,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;gBAC3E,CAAC;gBACD,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACf,CAAC,CAAC,CAAC;YACH,uCACK,KAAK,KACR,QAAQ,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I,KAAK,KAAK,CAAC,IAAI,CAAC;oBAC7B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CACF,CAAC;IAEJ,CAAC;AAEH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ClassDeclaration, Project, SourceFile } from 'ts-morph';
|
|
2
|
-
import { DtoClassProperty } from './dto-class-property';
|
|
3
|
-
import 'colors';
|
|
4
|
-
export interface CoerceDtoClassOutput {
|
|
5
|
-
className: string;
|
|
6
|
-
filePath: string;
|
|
7
|
-
sourceFile: SourceFile;
|
|
8
|
-
classDeclaration: ClassDeclaration;
|
|
9
|
-
}
|
|
10
|
-
export interface CoerceDtoClassOptions {
|
|
11
|
-
project: Project;
|
|
12
|
-
name: string;
|
|
13
|
-
propertyList?: DtoClassProperty[];
|
|
14
|
-
tsMorphTransform?: (project: Project, sourceFile: SourceFile, classDeclaration: ClassDeclaration) => void;
|
|
15
|
-
}
|
|
16
|
-
export declare function CoerceDtoClass(options: CoerceDtoClassOptions): CoerceDtoClassOutput;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CoerceDtoClass = void 0;
|
|
4
|
-
const schematics_utilities_1 = require("@rxap/schematics-utilities");
|
|
5
|
-
const ts_morph_1 = require("@rxap/ts-morph");
|
|
6
|
-
const utilities_1 = require("@rxap/utilities");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const ts_morph_2 = require("ts-morph");
|
|
9
|
-
const dto_class_property_1 = require("./dto-class-property");
|
|
10
|
-
require("colors");
|
|
11
|
-
function CoerceDtoClass(options) {
|
|
12
|
-
const { project, propertyList = [], tsMorphTransform = utilities_1.noop, } = options;
|
|
13
|
-
let { name, } = options;
|
|
14
|
-
name = (0, schematics_utilities_1.dasherize)(name);
|
|
15
|
-
const className = (0, schematics_utilities_1.CoerceSuffix)((0, schematics_utilities_1.classify)(name), 'Dto');
|
|
16
|
-
const fileName = (0, schematics_utilities_1.CoerceSuffix)(name, '.dto');
|
|
17
|
-
const sourceFile = (0, ts_morph_1.CoerceSourceFile)(project, (0, path_1.join)('dtos', fileName + '.ts'));
|
|
18
|
-
const classDeclaration = (0, ts_morph_1.CoerceClass)(sourceFile, className);
|
|
19
|
-
classDeclaration.setIsExported(true);
|
|
20
|
-
for (const property of propertyList.map(dto_class_property_1.NormalizeDataClassProperty)) {
|
|
21
|
-
// create a clone of the property type to avoid modifying the original type
|
|
22
|
-
// if the property type is a self reference we need to replace the self reference with the class name
|
|
23
|
-
// if the property type is a deferred reference we need to replace the deferred reference with the class name
|
|
24
|
-
const propertyType = Object.assign({}, property.type);
|
|
25
|
-
let subTypeOutput;
|
|
26
|
-
switch (propertyType.name) {
|
|
27
|
-
case ts_morph_1.TypeNames.Self:
|
|
28
|
-
propertyType.name = className;
|
|
29
|
-
propertyType.isTypeOnly = false;
|
|
30
|
-
propertyType.moduleSpecifier = null;
|
|
31
|
-
propertyType.namedImport = null;
|
|
32
|
-
propertyType.namespaceImport = null;
|
|
33
|
-
propertyType.defaultImport = null;
|
|
34
|
-
property.isType = true;
|
|
35
|
-
break;
|
|
36
|
-
case ts_morph_1.TypeNames.Deferred:
|
|
37
|
-
subTypeOutput = CoerceDtoClass({
|
|
38
|
-
project,
|
|
39
|
-
name: [name, (0, schematics_utilities_1.dasherize)(property.name)].join('-'),
|
|
40
|
-
propertyList: property.memberList,
|
|
41
|
-
});
|
|
42
|
-
propertyType.name = subTypeOutput.className;
|
|
43
|
-
propertyType.moduleSpecifier = './' + (0, schematics_utilities_1.dasherize)(subTypeOutput.className.replace(/Dto$/, '')) + '.dto';
|
|
44
|
-
propertyType.isTypeOnly = false;
|
|
45
|
-
propertyType.namedImport = null;
|
|
46
|
-
propertyType.namespaceImport = null;
|
|
47
|
-
propertyType.defaultImport = null;
|
|
48
|
-
property.isType = true;
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
let propertyName = (0, schematics_utilities_1.camelize)(property.name);
|
|
52
|
-
const prefixMatch = property.name.match(/^(_+)/);
|
|
53
|
-
if (prefixMatch) {
|
|
54
|
-
propertyName = (0, schematics_utilities_1.camelize)(property.name.replace(/^_+/, ''));
|
|
55
|
-
propertyName = prefixMatch[0] + propertyName;
|
|
56
|
-
}
|
|
57
|
-
const propertyDeclaration = (0, ts_morph_1.CoercePropertyDeclaration)(classDeclaration, propertyName).set({
|
|
58
|
-
type: (0, ts_morph_1.WriteType)({
|
|
59
|
-
isArray: property.isArray,
|
|
60
|
-
type: propertyType,
|
|
61
|
-
}, sourceFile),
|
|
62
|
-
hasQuestionToken: property.isOptional,
|
|
63
|
-
hasExclamationToken: !property.isOptional,
|
|
64
|
-
});
|
|
65
|
-
addExposeDecorator(propertyDeclaration);
|
|
66
|
-
if (property.isArray) {
|
|
67
|
-
addClassValidatorDecoratorForIsArray(propertyDeclaration);
|
|
68
|
-
}
|
|
69
|
-
if (property.isType) {
|
|
70
|
-
addClassValidatorDecoratorForNestedDto(propertyDeclaration, propertyType, property.isArray);
|
|
71
|
-
}
|
|
72
|
-
if (property.isOptional) {
|
|
73
|
-
addIsOptionalDecorator(propertyDeclaration);
|
|
74
|
-
}
|
|
75
|
-
addClassValidatorDecoratorForType(propertyDeclaration, propertyType);
|
|
76
|
-
if (propertyType.name !== 'unknown') {
|
|
77
|
-
cleanupUnknownApiPropertyDecorator(propertyDeclaration);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
tsMorphTransform(project, sourceFile, classDeclaration);
|
|
81
|
-
return {
|
|
82
|
-
className,
|
|
83
|
-
filePath: '.' + (0, path_1.join)(sourceFile.getDirectoryPath(), sourceFile.getBaseNameWithoutExtension()),
|
|
84
|
-
sourceFile,
|
|
85
|
-
classDeclaration,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
exports.CoerceDtoClass = CoerceDtoClass;
|
|
89
|
-
function addIsOptionalDecorator(propertyDeclaration) {
|
|
90
|
-
const sourceFile = propertyDeclaration.getSourceFile();
|
|
91
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsOptional', {
|
|
92
|
-
arguments: [],
|
|
93
|
-
});
|
|
94
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
95
|
-
namedImports: ['IsOptional'],
|
|
96
|
-
moduleSpecifier: 'class-validator',
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function addExposeDecorator(propertyDeclaration) {
|
|
100
|
-
const sourceFile = propertyDeclaration.getSourceFile();
|
|
101
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'Expose', {
|
|
102
|
-
arguments: [],
|
|
103
|
-
});
|
|
104
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
105
|
-
namedImports: ['Expose'],
|
|
106
|
-
moduleSpecifier: 'class-transformer',
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function addClassValidatorDecoratorForIsArray(propertyDeclaration) {
|
|
110
|
-
const sourceFile = propertyDeclaration.getSourceFile();
|
|
111
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsArray', {
|
|
112
|
-
arguments: [],
|
|
113
|
-
});
|
|
114
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
115
|
-
namedImports: ['IsArray'],
|
|
116
|
-
moduleSpecifier: 'class-validator',
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function addClassValidatorDecoratorForNestedDto(propertyDeclaration, propertyType, isArray) {
|
|
120
|
-
const sourceFile = propertyDeclaration.getSourceFile();
|
|
121
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'Type', {
|
|
122
|
-
arguments: [
|
|
123
|
-
w => {
|
|
124
|
-
w.write('() => ');
|
|
125
|
-
(0, ts_morph_1.WriteType)({
|
|
126
|
-
type: propertyType,
|
|
127
|
-
isArray: false,
|
|
128
|
-
}, sourceFile)(w);
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
133
|
-
namedImports: ['Type'],
|
|
134
|
-
moduleSpecifier: 'class-transformer',
|
|
135
|
-
});
|
|
136
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsInstance', {
|
|
137
|
-
arguments: [
|
|
138
|
-
(0, ts_morph_1.WriteType)({
|
|
139
|
-
type: propertyType,
|
|
140
|
-
isArray: false,
|
|
141
|
-
}, sourceFile),
|
|
142
|
-
w => {
|
|
143
|
-
if (isArray) {
|
|
144
|
-
ts_morph_2.Writers.object({ each: 'true' })(w);
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
});
|
|
149
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
150
|
-
namedImports: ['IsInstance'],
|
|
151
|
-
moduleSpecifier: 'class-validator',
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function addClassValidatorDecoratorForType(propertyDeclaration, propertyType) {
|
|
155
|
-
var _a;
|
|
156
|
-
const sourceFile = propertyDeclaration.getSourceFile();
|
|
157
|
-
switch (propertyType.name) {
|
|
158
|
-
case 'date':
|
|
159
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsDate', {
|
|
160
|
-
arguments: [],
|
|
161
|
-
});
|
|
162
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
163
|
-
namedImports: ['IsDate'],
|
|
164
|
-
moduleSpecifier: 'class-validator',
|
|
165
|
-
});
|
|
166
|
-
break;
|
|
167
|
-
case 'number':
|
|
168
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsNumber', {
|
|
169
|
-
arguments: [],
|
|
170
|
-
});
|
|
171
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
172
|
-
namedImports: ['IsNumber'],
|
|
173
|
-
moduleSpecifier: 'class-validator',
|
|
174
|
-
});
|
|
175
|
-
break;
|
|
176
|
-
case 'string':
|
|
177
|
-
if ((_a = propertyDeclaration.getName()) === null || _a === void 0 ? void 0 : _a.match(/^uuid|Uuid$/)) {
|
|
178
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
179
|
-
namedImports: ['IsUUID'],
|
|
180
|
-
moduleSpecifier: 'class-validator',
|
|
181
|
-
});
|
|
182
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsUUID', {
|
|
183
|
-
arguments: [],
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
188
|
-
namedImports: ['IsString'],
|
|
189
|
-
moduleSpecifier: 'class-validator',
|
|
190
|
-
});
|
|
191
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsString', {
|
|
192
|
-
arguments: [],
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
196
|
-
case 'boolean':
|
|
197
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'IsBoolean', {
|
|
198
|
-
arguments: [],
|
|
199
|
-
});
|
|
200
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
201
|
-
namedImports: ['IsBoolean'],
|
|
202
|
-
moduleSpecifier: 'class-validator',
|
|
203
|
-
});
|
|
204
|
-
break;
|
|
205
|
-
case 'unknown':
|
|
206
|
-
(0, ts_morph_1.CoerceDecorator)(propertyDeclaration, 'ApiProperty', {
|
|
207
|
-
arguments: [ts_morph_2.Writers.object({ type: w => w.quote('unknown') })],
|
|
208
|
-
});
|
|
209
|
-
(0, ts_morph_1.CoerceImports)(sourceFile, {
|
|
210
|
-
namedImports: ['ApiProperty'],
|
|
211
|
-
moduleSpecifier: '@nestjs/swagger',
|
|
212
|
-
});
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
function cleanupUnknownApiPropertyDecorator(propertyDeclaration) {
|
|
217
|
-
var _a;
|
|
218
|
-
const apiProperty = propertyDeclaration.getDecorators().find(d => d.getName() === 'ApiProperty');
|
|
219
|
-
if (apiProperty) {
|
|
220
|
-
const args = apiProperty.getArguments()[0];
|
|
221
|
-
if (args instanceof ts_morph_2.ObjectLiteralExpression) {
|
|
222
|
-
if ((_a = args.getProperty('type')) === null || _a === void 0 ? void 0 : _a.getText().includes('unknown')) {
|
|
223
|
-
apiProperty.remove();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=coerce-dto-class.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coerce-dto-class.js","sourceRoot":"","sources":["../../../../../../../packages/schematic/ts-morph/src/lib/nest/coerce-dto-class.ts"],"names":[],"mappings":";;;AAAA,qEAKoC;AACpC,6CASwB;AACxB,+CAAuC;AACvC,+BAA4B;AAC5B,uCAOkB;AAClB,6DAG8B;AAC9B,kBAAgB;AAgBhB,SAAgB,cAAc,CAAC,OAA8B;IAC3D,MAAM,EACJ,OAAO,EACP,YAAY,GAAG,EAAE,EACjB,gBAAgB,GAAG,gBAAI,GACxB,GAAG,OAAO,CAAC;IACZ,IAAI,EACF,IAAI,GACL,GAAG,OAAO,CAAC;IAEZ,IAAI,GAAG,IAAA,gCAAS,EAAC,IAAI,CAAC,CAAC;IAEvB,MAAM,SAAS,GAAG,IAAA,mCAAY,EAAC,IAAA,+BAAQ,EAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAA,mCAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAE5C,MAAM,UAAU,GAAG,IAAA,2BAAgB,EAAC,OAAO,EAAE,IAAA,WAAI,EAAC,MAAM,EAAE,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC;IAC7E,MAAM,gBAAgB,GAAG,IAAA,sBAAW,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC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,YAAY,EAAE,CAAE,WAAW,CAAE;gBAC7B,eAAe,EAAE,iBAAiB;aACnC,CAAC,CAAC;YACH,MAAM;QACR,KAAK,SAAS;YACZ,IAAA,0BAAe,EACb,mBAAmB,EACnB,aAAa,EACb;gBACE,SAAS,EAAE,CAAE,kBAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,CAAE;aACjE,CACF,CAAC;YACF,IAAA,wBAAa,EAAC,UAAU,EAAE;gBACxB,YAAY,EAAE,CAAE,aAAa,CAAE;gBAC/B,eAAe,EAAE,iBAAiB;aACnC,CAAC,CAAC;YACH,MAAM;IACV,CAAC;AAEH,CAAC;AAED,SAAS,kCAAkC,CAAC,mBAAwC;;IAClF,MAAM,WAAW,GAAG,mBAAmB,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,aAAa,CAAC,CAAC;IACjG,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3C,IAAI,IAAI,YAAY,kCAAuB,EAAE,CAAC;YAC5C,IAAI,MAAA,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,0CAAE,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5D,WAAW,CAAC,MAAM,EAAE,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DataProperty, NormalizedDataProperty } from '@rxap/ts-morph';
|
|
2
|
-
import { Normalized } from '@rxap/utilities';
|
|
3
|
-
export interface DtoClassProperty extends DataProperty {
|
|
4
|
-
/**
|
|
5
|
-
* indicates that the @Type decorator should be used as the type of the property is another dto class
|
|
6
|
-
*/
|
|
7
|
-
isType?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface NormalizedDtoClassProperty extends Normalized<Pick<DtoClassProperty, 'isType'>>, NormalizedDataProperty {
|
|
10
|
-
}
|
|
11
|
-
export declare function NormalizeDataClassProperty(property: DtoClassProperty): NormalizedDtoClassProperty;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NormalizeDataClassProperty = void 0;
|
|
4
|
-
const ts_morph_1 = require("@rxap/ts-morph");
|
|
5
|
-
function NormalizeDataClassProperty(property) {
|
|
6
|
-
var _a;
|
|
7
|
-
const { name, type, isArray, memberList, source, isOptional, } = (0, ts_morph_1.NormalizeDataProperty)(property);
|
|
8
|
-
let isType = (_a = property.isType) !== null && _a !== void 0 ? _a : false;
|
|
9
|
-
if ([ts_morph_1.TypeNames.Self, ts_morph_1.TypeNames.Deferred].includes(type.name)) {
|
|
10
|
-
isType = true;
|
|
11
|
-
}
|
|
12
|
-
switch (type.name) {
|
|
13
|
-
case 'IconConfig':
|
|
14
|
-
type.name = 'IconDto';
|
|
15
|
-
type.moduleSpecifier = '@rxap/nest-dto';
|
|
16
|
-
isType = true;
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
source,
|
|
21
|
-
memberList,
|
|
22
|
-
name,
|
|
23
|
-
type,
|
|
24
|
-
isArray,
|
|
25
|
-
isType,
|
|
26
|
-
isOptional,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
exports.NormalizeDataClassProperty = NormalizeDataClassProperty;
|
|
30
|
-
//# sourceMappingURL=dto-class-property.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dto-class-property.js","sourceRoot":"","sources":["../../../../../../../packages/schematic/ts-morph/src/lib/nest/dto-class-property.ts"],"names":[],"mappings":";;;AAAA,6CAKwB;AAcxB,SAAgB,0BAA0B,CAAC,QAA0B;;IACnE,MAAM,EACJ,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,UAAU,EACV,MAAM,EACN,UAAU,GACX,GAAG,IAAA,gCAAqB,EAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,MAAM,GAAG,MAAA,QAAQ,CAAC,MAAM,mCAAI,KAAK,CAAC;IACtC,IAAK,CAAE,oBAAS,CAAC,IAAI,EAAE,oBAAS,CAAC,QAAQ,CAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7E,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IACD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,YAAY;YACf,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;YACtB,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC;YACxC,MAAM,GAAG,IAAI,CAAC;YACd,MAAM;IACV,CAAC;IACD,OAAO;QACL,MAAM;QACN,UAAU;QACV,IAAI;QACJ,IAAI;QACJ,OAAO;QACP,MAAM;QACN,UAAU;KACX,CAAC;AACJ,CAAC;AA7BD,gEA6BC"}
|