@solidstarters/solid-code-builder 1.0.20 → 1.0.21
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/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.d.ts +4 -0
- package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.js +61 -2
- package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.js.map +1 -1
- package/package.json +5 -2
- package/publish.js +16 -0
- package/src/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.ts +71 -2
- package/dto_additional_fields_duplicate_fix.diff +0 -40
- package/src/code-builder/index.js +0 -178
- package/src/code-builder/index_spec.js +0 -46
- package/src/code-builder/lib/field/FieldManager.js +0 -236
- package/src/code-builder/lib/field/decorator-managers/dto/ArrayDecoratorManager.js +0 -107
- package/src/code-builder/lib/field/decorator-managers/dto/BigIntDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/BooleanDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/DateDecoratorManager.js +0 -106
- package/src/code-builder/lib/field/decorator-managers/dto/DecimalDecoratorManager.js +0 -112
- package/src/code-builder/lib/field/decorator-managers/dto/EmailDecoratorManager.js +0 -99
- package/src/code-builder/lib/field/decorator-managers/dto/IntDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/JsonDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/LengthDecoratorManager.js +0 -104
- package/src/code-builder/lib/field/decorator-managers/dto/MaxDecoratorManager.js +0 -103
- package/src/code-builder/lib/field/decorator-managers/dto/MaxLengthDecoratorManager.js +0 -103
- package/src/code-builder/lib/field/decorator-managers/dto/MinDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/MinLengthDecoratorManager.js +0 -103
- package/src/code-builder/lib/field/decorator-managers/dto/NumberDecoratorManager.js +0 -112
- package/src/code-builder/lib/field/decorator-managers/dto/OptionalDecoratorManager.js +0 -104
- package/src/code-builder/lib/field/decorator-managers/dto/RegexDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/RequiredDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/StringDecoratorManager.js +0 -99
- package/src/code-builder/lib/field/decorator-managers/dto/TransformDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/ValidateNestedDecoratorManager.js +0 -140
- package/src/code-builder/lib/field/decorator-managers/entity/ColumnDecoratorManager.js +0 -178
- package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +0 -79
- package/src/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js +0 -118
- package/src/code-builder/lib/field/decorator-managers/entity/ManyToManyDecoratorManager.js +0 -175
- package/src/code-builder/lib/field/decorator-managers/entity/ManyToOneDecoratorManager.js +0 -179
- package/src/code-builder/lib/field/decorator-managers/entity/OneToManyDecoratorManager.js +0 -155
- package/src/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js +0 -174
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +0 -345
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +0 -373
- package/src/code-builder/lib/field/field-managers/base/DeleteType.js +0 -11
- package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForDto.js +0 -81
- package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForEntity.js +0 -55
- package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForDto.js +0 -75
- package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForEntity.js +0 -51
- package/src/code-builder/lib/field/field-managers/computed/ComputedFieldHandler.js +0 -30
- package/src/code-builder/lib/field/field-managers/computed/ComputedFieldManagerForEntity.js +0 -33
- package/src/code-builder/lib/field/field-managers/date/DateFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForDto.js +0 -81
- package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForEntity.js +0 -59
- package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForDto.js +0 -77
- package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForEntity.js +0 -53
- package/src/code-builder/lib/field/field-managers/email/EmailFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForDto.js +0 -72
- package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForEntity.js +0 -44
- package/src/code-builder/lib/field/field-managers/int/IntFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForDto.js +0 -76
- package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForEntity.js +0 -52
- package/src/code-builder/lib/field/field-managers/json/JsonFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForDto.js +0 -57
- package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForEntity.js +0 -21
- package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForDto.js +0 -63
- package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForEntity.js +0 -34
- package/src/code-builder/lib/field/field-managers/media/MediaFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForDto.js +0 -72
- package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForEntity.js +0 -57
- package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldHandler.js +0 -27
- package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForDto.js +0 -75
- package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForEntity.js +0 -35
- package/src/code-builder/lib/field/field-managers/password/PasswordFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForDto.js +0 -121
- package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForEntity.js +0 -37
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +0 -366
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -158
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +0 -294
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +0 -177
- package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForDto.js +0 -63
- package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForEntity.js +0 -34
- package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForDto.js +0 -63
- package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForEntity.js +0 -37
- package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForDto.js +0 -15
- package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForEntity.js +0 -33
- package/src/code-builder/lib/model/helpers.js +0 -407
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IsBigInt = exports.safeInsertImport = exports.ManagerForDtoOptions = exports.DtoSourceType = exports.RelationType = exports.getClassExportKeywordNode = exports.getClassNode = exports.createSourceFile = exports.getFieldHandler = exports.ReplaceChangeSSS = exports.RemoveChangeSSS = exports.PartialAddFieldChange = exports.DeleteType = exports.DecoratorType = exports.UUID_REGEX = exports.MAX_EMAIL_LENGTH = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
9
|
-
const change_1 = require("@schematics/angular/utility/change");
|
|
10
|
-
const class_validator_1 = require("class-validator");
|
|
11
|
-
const BigIntFieldHandler_1 = require("./field-managers/bigint/BigIntFieldHandler");
|
|
12
|
-
const BooleanFieldHandler_1 = require("./field-managers/boolean/BooleanFieldHandler");
|
|
13
|
-
const ComputedFieldHandler_1 = require("./field-managers/computed/ComputedFieldHandler");
|
|
14
|
-
const DateFieldHandler_1 = require("./field-managers/date/DateFieldHandler");
|
|
15
|
-
const DecimalFieldHandler_1 = require("./field-managers/decimal/DecimalFieldHandler");
|
|
16
|
-
const EmailFieldHandler_1 = require("./field-managers/email/EmailFieldHandler");
|
|
17
|
-
const IntFieldHandler_1 = require("./field-managers/int/IntFieldHandler");
|
|
18
|
-
const JsonFieldHandler_1 = require("./field-managers/json/JsonFieldHandler");
|
|
19
|
-
const LongTextFieldHandler_1 = require("./field-managers/long-text/LongTextFieldHandler");
|
|
20
|
-
const NoOpsFieldHandler_1 = require("./field-managers/no-ops/NoOpsFieldHandler");
|
|
21
|
-
const PasswordFieldHandler_1 = require("./field-managers/password/PasswordFieldHandler");
|
|
22
|
-
const ManyToManyRelationFieldHandler_1 = require("./field-managers/relation/ManyToManyRelationFieldHandler");
|
|
23
|
-
const ManyToOneRelationFieldHandler_1 = require("./field-managers/relation/ManyToOneRelationFieldHandler");
|
|
24
|
-
const RichTextFieldHandler_1 = require("./field-managers/rich-text/RichTextFieldHandler");
|
|
25
|
-
const ShortTextFieldHandler_1 = require("./field-managers/short-text/ShortTextFieldHandler");
|
|
26
|
-
const UUIDFieldHandler_1 = require("./field-managers/uuid/UUIDFieldHandler");
|
|
27
|
-
exports.MAX_EMAIL_LENGTH = 254;
|
|
28
|
-
exports.UUID_REGEX = `^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`;
|
|
29
|
-
var SolidFieldType;
|
|
30
|
-
(function (SolidFieldType) {
|
|
31
|
-
// numeric types
|
|
32
|
-
SolidFieldType["int"] = "int";
|
|
33
|
-
SolidFieldType["bigint"] = "bigint";
|
|
34
|
-
// float = 'float',
|
|
35
|
-
// double = 'double',
|
|
36
|
-
SolidFieldType["decimal"] = "decimal";
|
|
37
|
-
// text types
|
|
38
|
-
SolidFieldType["shortText"] = "shortText";
|
|
39
|
-
SolidFieldType["longtext"] = "longText";
|
|
40
|
-
SolidFieldType["richText"] = "richText";
|
|
41
|
-
SolidFieldType["json"] = "json";
|
|
42
|
-
// boolean types
|
|
43
|
-
SolidFieldType["boolean"] = "boolean";
|
|
44
|
-
// date
|
|
45
|
-
SolidFieldType["date"] = "date";
|
|
46
|
-
SolidFieldType["datetime"] = "datetime";
|
|
47
|
-
SolidFieldType["time"] = "time";
|
|
48
|
-
// relation
|
|
49
|
-
SolidFieldType["relation"] = "relation";
|
|
50
|
-
// media
|
|
51
|
-
SolidFieldType["mediaSingle"] = "mediaSingle";
|
|
52
|
-
SolidFieldType["mediaMultiple"] = "mediaMultiple";
|
|
53
|
-
SolidFieldType["email"] = "email";
|
|
54
|
-
SolidFieldType["password"] = "password";
|
|
55
|
-
// selection
|
|
56
|
-
SolidFieldType["selectionStatic"] = "selectionStatic";
|
|
57
|
-
SolidFieldType["selectionDynamic"] = "selectionDynamic";
|
|
58
|
-
SolidFieldType["uuid"] = "uuid";
|
|
59
|
-
SolidFieldType["computed"] = "computed";
|
|
60
|
-
})(SolidFieldType || (SolidFieldType = {}));
|
|
61
|
-
var DecoratorType;
|
|
62
|
-
(function (DecoratorType) {
|
|
63
|
-
DecoratorType["Max"] = "max";
|
|
64
|
-
DecoratorType["Min"] = "min";
|
|
65
|
-
DecoratorType["Required"] = "required";
|
|
66
|
-
DecoratorType["Optional"] = "optional";
|
|
67
|
-
DecoratorType["Regex"] = "regex";
|
|
68
|
-
DecoratorType["Number"] = "number";
|
|
69
|
-
DecoratorType["String"] = "string";
|
|
70
|
-
DecoratorType["Int"] = "int";
|
|
71
|
-
DecoratorType["Decimal"] = "decimal";
|
|
72
|
-
DecoratorType["Date"] = "date";
|
|
73
|
-
DecoratorType["Boolean"] = "boolean";
|
|
74
|
-
DecoratorType["Json"] = "json";
|
|
75
|
-
DecoratorType["Transform"] = "transform";
|
|
76
|
-
DecoratorType["Array"] = "array";
|
|
77
|
-
DecoratorType["ValidateNested"] = "validateNested";
|
|
78
|
-
DecoratorType["BigInt"] = "bigint";
|
|
79
|
-
DecoratorType["MinLength"] = "minLength";
|
|
80
|
-
DecoratorType["MaxLength"] = "maxLength";
|
|
81
|
-
})(DecoratorType || (exports.DecoratorType = DecoratorType = {}));
|
|
82
|
-
var DeleteType;
|
|
83
|
-
(function (DeleteType) {
|
|
84
|
-
DeleteType["CASCADE"] = "CASCADE";
|
|
85
|
-
DeleteType["RESTRICT"] = "RESTRICT";
|
|
86
|
-
DeleteType["SET_NULL"] = "SET_NULL";
|
|
87
|
-
DeleteType["SET_DEFAULT"] = "SET_DEFAULT";
|
|
88
|
-
})(DeleteType || (exports.DeleteType = DeleteType = {}));
|
|
89
|
-
class PartialAddFieldChange {
|
|
90
|
-
constructor() {
|
|
91
|
-
this.changes = [];
|
|
92
|
-
this.fieldSourceLines = [];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.PartialAddFieldChange = PartialAddFieldChange;
|
|
96
|
-
// export class PartialUpdateFieldChange implements FieldChange {
|
|
97
|
-
// filePath: string;
|
|
98
|
-
// field: any;
|
|
99
|
-
// changes: Change[] = [];
|
|
100
|
-
// updatedPropertyNode: PropertyDeclaration;
|
|
101
|
-
// }
|
|
102
|
-
class RemoveChangeSSS extends change_1.RemoveChange {
|
|
103
|
-
constructor(path, pos, toRemove) {
|
|
104
|
-
super(path, pos, toRemove);
|
|
105
|
-
this.removePosition = pos;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.RemoveChangeSSS = RemoveChangeSSS;
|
|
109
|
-
class ReplaceChangeSSS extends change_1.ReplaceChange {
|
|
110
|
-
constructor(path, pos, oldText, newText) {
|
|
111
|
-
super(path, pos, oldText, newText);
|
|
112
|
-
this.replacePosition = pos;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.ReplaceChangeSSS = ReplaceChangeSSS;
|
|
116
|
-
function getFieldHandler(tree, moduleName, modelName, field) {
|
|
117
|
-
// console.log('field', field);
|
|
118
|
-
switch (field.type) {
|
|
119
|
-
case SolidFieldType.shortText:
|
|
120
|
-
case SolidFieldType.selectionStatic:
|
|
121
|
-
case SolidFieldType.selectionDynamic:
|
|
122
|
-
if (field.selectionValueType === "int") {
|
|
123
|
-
return new IntFieldHandler_1.IntFieldHandler(tree, moduleName, modelName, field);
|
|
124
|
-
}
|
|
125
|
-
return new ShortTextFieldHandler_1.ShortTextFieldHandler(tree, moduleName, modelName, field);
|
|
126
|
-
case SolidFieldType.longtext:
|
|
127
|
-
return new LongTextFieldHandler_1.LongTextFieldHandler(tree, moduleName, modelName, field);
|
|
128
|
-
case SolidFieldType.richText:
|
|
129
|
-
return new RichTextFieldHandler_1.RichTextFieldHandler(tree, moduleName, modelName, field);
|
|
130
|
-
case SolidFieldType.json:
|
|
131
|
-
return new JsonFieldHandler_1.JsonFieldHandler(tree, moduleName, modelName, field);
|
|
132
|
-
case SolidFieldType.int:
|
|
133
|
-
return new IntFieldHandler_1.IntFieldHandler(tree, moduleName, modelName, field);
|
|
134
|
-
case SolidFieldType.decimal:
|
|
135
|
-
return new DecimalFieldHandler_1.DecimalFieldHandler(tree, moduleName, modelName, field);
|
|
136
|
-
case SolidFieldType.bigint:
|
|
137
|
-
return new BigIntFieldHandler_1.BigIntFieldHandler(tree, moduleName, modelName, field);
|
|
138
|
-
case SolidFieldType.boolean:
|
|
139
|
-
return new BooleanFieldHandler_1.BooleanFieldHandler(tree, moduleName, modelName, field);
|
|
140
|
-
case SolidFieldType.email:
|
|
141
|
-
return new EmailFieldHandler_1.EmailFieldHandler(tree, moduleName, modelName, field);
|
|
142
|
-
case SolidFieldType.password:
|
|
143
|
-
return new PasswordFieldHandler_1.PasswordFieldHandler(tree, moduleName, modelName, field);
|
|
144
|
-
case SolidFieldType.date:
|
|
145
|
-
case SolidFieldType.datetime:
|
|
146
|
-
case SolidFieldType.time:
|
|
147
|
-
return new DateFieldHandler_1.DateFieldHandler(tree, moduleName, modelName, field);
|
|
148
|
-
case SolidFieldType.relation:
|
|
149
|
-
if (field.relationType === RelationType.ManyToMany) {
|
|
150
|
-
return new ManyToManyRelationFieldHandler_1.ManyToManyRelationFieldHandler(tree, moduleName, modelName, field);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return new ManyToOneRelationFieldHandler_1.ManyToOneRelationFieldHandler(tree, moduleName, modelName, field);
|
|
154
|
-
}
|
|
155
|
-
case SolidFieldType.mediaSingle:
|
|
156
|
-
case SolidFieldType.mediaMultiple:
|
|
157
|
-
return new NoOpsFieldHandler_1.NoOpsFieldHandler(tree, moduleName, modelName, field);
|
|
158
|
-
case SolidFieldType.uuid:
|
|
159
|
-
return new UUIDFieldHandler_1.UUIDFieldHandler(tree, moduleName, modelName, field);
|
|
160
|
-
case SolidFieldType.computed:
|
|
161
|
-
return new ComputedFieldHandler_1.ComputedFieldHandler(tree, moduleName, modelName, field);
|
|
162
|
-
default:
|
|
163
|
-
console.log(`Field ${field.name} of type ${field.type} not supported yet`);
|
|
164
|
-
return new NoOpsFieldHandler_1.NoOpsFieldHandler(tree, moduleName, modelName, field);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.getFieldHandler = getFieldHandler;
|
|
168
|
-
function createSourceFile(tree, filePath) {
|
|
169
|
-
return typescript_1.default.createSourceFile(filePath, tree.readText(filePath), typescript_1.default.ScriptTarget.Latest, true);
|
|
170
|
-
}
|
|
171
|
-
exports.createSourceFile = createSourceFile;
|
|
172
|
-
function getClassNode(className, source) {
|
|
173
|
-
const classNodes = (0, ast_utils_1.findNodes)(source, typescript_1.default.SyntaxKind.ClassDeclaration);
|
|
174
|
-
return classNodes.find(node => node.name && node.name.text === className);
|
|
175
|
-
}
|
|
176
|
-
exports.getClassNode = getClassNode;
|
|
177
|
-
function getClassExportKeywordNode(className, sourceFile) {
|
|
178
|
-
var _a;
|
|
179
|
-
const classNode = getClassNode(className, sourceFile);
|
|
180
|
-
if (!classNode) {
|
|
181
|
-
throw new Error(`Class "${className}" not found`);
|
|
182
|
-
}
|
|
183
|
-
// Find the `export` modifier
|
|
184
|
-
const exportModifier = (_a = classNode.modifiers) === null || _a === void 0 ? void 0 : _a.find((modifier) => modifier.kind === typescript_1.default.SyntaxKind.ExportKeyword
|
|
185
|
-
// (modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword
|
|
186
|
-
);
|
|
187
|
-
return exportModifier;
|
|
188
|
-
}
|
|
189
|
-
exports.getClassExportKeywordNode = getClassExportKeywordNode;
|
|
190
|
-
;
|
|
191
|
-
var RelationType;
|
|
192
|
-
(function (RelationType) {
|
|
193
|
-
RelationType["ManyToOne"] = "many-to-one";
|
|
194
|
-
RelationType["ManyToMany"] = "many-to-many";
|
|
195
|
-
})(RelationType || (exports.RelationType = RelationType = {}));
|
|
196
|
-
var DtoSourceType;
|
|
197
|
-
(function (DtoSourceType) {
|
|
198
|
-
DtoSourceType["Create"] = "create";
|
|
199
|
-
DtoSourceType["Update"] = "update";
|
|
200
|
-
})(DtoSourceType || (exports.DtoSourceType = DtoSourceType = {}));
|
|
201
|
-
class ManagerForDtoOptions {
|
|
202
|
-
constructor(sourceType) {
|
|
203
|
-
this.sourceType = sourceType;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.ManagerForDtoOptions = ManagerForDtoOptions;
|
|
207
|
-
// insertImport(this.source, this.source.fileName, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
|
|
208
|
-
function safeInsertImport(source, symbolName, importFileName) {
|
|
209
|
-
// Check if in current source, there exists a class with the same symbolName
|
|
210
|
-
if (!getClassNode(symbolName, source)) {
|
|
211
|
-
return (0, ast_utils_1.insertImport)(source, source.fileName, symbolName, importFileName);
|
|
212
|
-
}
|
|
213
|
-
return new change_1.NoopChange();
|
|
214
|
-
}
|
|
215
|
-
exports.safeInsertImport = safeInsertImport;
|
|
216
|
-
// Register a custom decorator
|
|
217
|
-
function IsBigInt(validationOptions) {
|
|
218
|
-
return function (object, propertyName) {
|
|
219
|
-
(0, class_validator_1.registerDecorator)({
|
|
220
|
-
name: 'isBigInt',
|
|
221
|
-
target: object.constructor,
|
|
222
|
-
propertyName: propertyName,
|
|
223
|
-
options: validationOptions,
|
|
224
|
-
validator: {
|
|
225
|
-
validate(value, _args) {
|
|
226
|
-
return typeof value === 'bigint';
|
|
227
|
-
},
|
|
228
|
-
defaultMessage(args) {
|
|
229
|
-
return `${args.property} must be a BigInt`;
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
exports.IsBigInt = IsBigInt;
|
|
236
|
-
//# sourceMappingURL=FieldManager.js.map
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ArrayDecoratorManager = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
9
|
-
class ArrayDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isArray;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
21
|
-
changes.push(...this.decoratorImports());
|
|
22
|
-
return {
|
|
23
|
-
filePath: this.options.source.fileName,
|
|
24
|
-
field: this.options.field,
|
|
25
|
-
changes: changes,
|
|
26
|
-
fieldSourceLines: fieldSourceLines,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
setFieldNode(fieldNode) {
|
|
30
|
-
this.fieldNode = fieldNode;
|
|
31
|
-
}
|
|
32
|
-
decoratorName() {
|
|
33
|
-
return 'IsArray';
|
|
34
|
-
}
|
|
35
|
-
decoratorImports() {
|
|
36
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
|
|
37
|
-
}
|
|
38
|
-
updateDecorator() {
|
|
39
|
-
if (!this.fieldNode)
|
|
40
|
-
throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
|
|
41
|
-
let newModifiers = [];
|
|
42
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
43
|
-
// Check if the field has an IsArray decorator.
|
|
44
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
45
|
-
//Remove the decorator if the decorator exists
|
|
46
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
47
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
48
|
-
//Add the decorator, if it is required
|
|
49
|
-
const changes = [];
|
|
50
|
-
if (this.isApplyDecorator()) {
|
|
51
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
52
|
-
changes.push(...this.decoratorImports());
|
|
53
|
-
}
|
|
54
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
55
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
56
|
-
return [updatedProperty, changes];
|
|
57
|
-
}
|
|
58
|
-
createDecorator(existingDecorator) {
|
|
59
|
-
// Capture the existing isArray decorator options
|
|
60
|
-
const validationOptions = this.existingValidationOptions(existingDecorator);
|
|
61
|
-
// Re-create the isArray decorator with the existing isArray decorator options
|
|
62
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
63
|
-
const argumentsArray = this.createDecoratorArguments(validationOptions);
|
|
64
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
65
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
66
|
-
}
|
|
67
|
-
createDecoratorArguments(validationOptions) {
|
|
68
|
-
const argumentsArray = [];
|
|
69
|
-
if (validationOptions.length > 0) {
|
|
70
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
71
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
72
|
-
}
|
|
73
|
-
return argumentsArray;
|
|
74
|
-
}
|
|
75
|
-
existingValidationOptions(existingDecorator) {
|
|
76
|
-
const validationOptions = [];
|
|
77
|
-
if (existingDecorator !== undefined) {
|
|
78
|
-
//Pre-set the isArray options from the existing IsArray decorator
|
|
79
|
-
const existingCallExpression = existingDecorator.expression;
|
|
80
|
-
// Check if call expression has at least 1 argument
|
|
81
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
82
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
83
|
-
throw new Error('IsArray decorator 1st argument must be an object literal containing the validation options');
|
|
84
|
-
}
|
|
85
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
86
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return validationOptions;
|
|
90
|
-
}
|
|
91
|
-
findDecorator(name, existingModifiers) {
|
|
92
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
93
|
-
}
|
|
94
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
95
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
96
|
-
}
|
|
97
|
-
filterNonDecorators(existingModifiers) {
|
|
98
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
99
|
-
}
|
|
100
|
-
containsIdentifierName(m, identifierName) {
|
|
101
|
-
const callExpression = m.expression;
|
|
102
|
-
const identifier = callExpression.expression;
|
|
103
|
-
return identifier.text === identifierName;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.ArrayDecoratorManager = ArrayDecoratorManager;
|
|
107
|
-
//# sourceMappingURL=ArrayDecoratorManager.js.map
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BigIntDecoratorManager = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
9
|
-
class BigIntDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isBigInt;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
21
|
-
changes.push(...this.decoratorImports());
|
|
22
|
-
return {
|
|
23
|
-
filePath: this.options.source.fileName,
|
|
24
|
-
field: this.options.field,
|
|
25
|
-
changes: changes,
|
|
26
|
-
fieldSourceLines: fieldSourceLines,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
setFieldNode(fieldNode) {
|
|
30
|
-
this.fieldNode = fieldNode;
|
|
31
|
-
}
|
|
32
|
-
decoratorName() {
|
|
33
|
-
return 'IsBigInt';
|
|
34
|
-
}
|
|
35
|
-
decoratorImports() {
|
|
36
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), '../../FieldManager')];
|
|
37
|
-
}
|
|
38
|
-
updateDecorator() {
|
|
39
|
-
if (!this.fieldNode)
|
|
40
|
-
throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
|
|
41
|
-
let newModifiers = [];
|
|
42
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
43
|
-
// Check if the field has an Length decorator.
|
|
44
|
-
//@ts-ignore
|
|
45
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
46
|
-
//Remove the column decorator if the column decorator exists
|
|
47
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
48
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
49
|
-
//Add the column decorator if column decorator is required
|
|
50
|
-
const changes = [];
|
|
51
|
-
if (this.isApplyDecorator()) {
|
|
52
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
53
|
-
changes.push(...this.decoratorImports());
|
|
54
|
-
}
|
|
55
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
56
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
57
|
-
return [updatedProperty, changes];
|
|
58
|
-
}
|
|
59
|
-
createDecorator(existingDecorator) {
|
|
60
|
-
// Capture the existing column decorator options
|
|
61
|
-
const validationOptions = [];
|
|
62
|
-
if (existingDecorator !== undefined) {
|
|
63
|
-
// Pre-set the column options from the existing column decorator
|
|
64
|
-
const existingCallExpression = existingDecorator.expression;
|
|
65
|
-
// Check if call expression has at least 1 arguments
|
|
66
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
67
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
68
|
-
throw new Error(`${this.decoratorName()} decorator 1rd argument must be an object literal containing the validation options`);
|
|
69
|
-
}
|
|
70
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
71
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Re-create the column decorator with the merged column decorator options
|
|
75
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
76
|
-
const argumentsArray = [];
|
|
77
|
-
if (validationOptions.length > 0) {
|
|
78
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
79
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
80
|
-
}
|
|
81
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
82
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
83
|
-
}
|
|
84
|
-
findDecorator(name, existingModifiers) {
|
|
85
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
86
|
-
}
|
|
87
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
88
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
89
|
-
}
|
|
90
|
-
filterNonDecorators(existingModifiers) {
|
|
91
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
92
|
-
}
|
|
93
|
-
containsIdentifierName(m, identifierName) {
|
|
94
|
-
const callExpression = m.expression;
|
|
95
|
-
const identifier = callExpression.expression;
|
|
96
|
-
return identifier.text === identifierName;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.BigIntDecoratorManager = BigIntDecoratorManager;
|
|
100
|
-
//# sourceMappingURL=BigIntDecoratorManager.js.map
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BooleanDecoratorManager = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
9
|
-
class BooleanDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isBoolean;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
21
|
-
changes.push(...this.decoratorImports());
|
|
22
|
-
return {
|
|
23
|
-
filePath: this.options.source.fileName,
|
|
24
|
-
field: this.options.field,
|
|
25
|
-
changes: changes,
|
|
26
|
-
fieldSourceLines: fieldSourceLines,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
setFieldNode(fieldNode) {
|
|
30
|
-
this.fieldNode = fieldNode;
|
|
31
|
-
}
|
|
32
|
-
decoratorName() {
|
|
33
|
-
return 'IsBoolean';
|
|
34
|
-
}
|
|
35
|
-
decoratorImports() {
|
|
36
|
-
return [
|
|
37
|
-
(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator'),
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
updateDecorator() {
|
|
41
|
-
if (!this.fieldNode)
|
|
42
|
-
throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
|
|
43
|
-
let newModifiers = [];
|
|
44
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
45
|
-
// Check if the field has an Length decorator.
|
|
46
|
-
//@ts-ignore
|
|
47
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
48
|
-
//Remove the column decorator if the column decorator exists
|
|
49
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
50
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
51
|
-
//Add the column decorator if column decorator is required
|
|
52
|
-
const changes = [];
|
|
53
|
-
if (this.isApplyDecorator()) {
|
|
54
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
55
|
-
changes.push(...this.decoratorImports());
|
|
56
|
-
}
|
|
57
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
58
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
59
|
-
return [updatedProperty, changes];
|
|
60
|
-
}
|
|
61
|
-
createDecorator(existingDecorator) {
|
|
62
|
-
// Capture the existing column decorator options
|
|
63
|
-
const validationOptions = [];
|
|
64
|
-
if (existingDecorator !== undefined) {
|
|
65
|
-
//Pre-set the column options from the existing column decorator
|
|
66
|
-
const existingCallExpression = existingDecorator.expression;
|
|
67
|
-
// Check if call expression has at least 1 arguments
|
|
68
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
69
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
70
|
-
throw new Error('Boolean decorator 1st argument must be an object literal containing the validation options');
|
|
71
|
-
}
|
|
72
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
73
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Re-create the column decorator with the merged column decorator options
|
|
77
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
78
|
-
const argumentsArray = [];
|
|
79
|
-
if (validationOptions.length > 0) {
|
|
80
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
81
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
82
|
-
}
|
|
83
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
84
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
85
|
-
}
|
|
86
|
-
findDecorator(name, existingModifiers) {
|
|
87
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
88
|
-
}
|
|
89
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
90
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
91
|
-
}
|
|
92
|
-
filterNonDecorators(existingModifiers) {
|
|
93
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
94
|
-
}
|
|
95
|
-
containsIdentifierName(m, identifierName) {
|
|
96
|
-
const callExpression = m.expression;
|
|
97
|
-
const identifier = callExpression.expression;
|
|
98
|
-
return identifier.text === identifierName;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.BooleanDecoratorManager = BooleanDecoratorManager;
|
|
102
|
-
//# sourceMappingURL=BooleanDecoratorManager.js.map
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DateDecoratorManager = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
9
|
-
class DateDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isDate;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
// fieldSourceLines.push(`@Type(() => Date)`);
|
|
21
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
22
|
-
changes.push(...this.decoratorImports());
|
|
23
|
-
return {
|
|
24
|
-
filePath: this.options.source.fileName,
|
|
25
|
-
field: this.options.field,
|
|
26
|
-
changes: changes,
|
|
27
|
-
fieldSourceLines: fieldSourceLines,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
setFieldNode(fieldNode) {
|
|
31
|
-
this.fieldNode = fieldNode;
|
|
32
|
-
}
|
|
33
|
-
decoratorName() {
|
|
34
|
-
return 'IsDate';
|
|
35
|
-
}
|
|
36
|
-
decoratorImports() {
|
|
37
|
-
return [
|
|
38
|
-
(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator'),
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
updateDecorator() {
|
|
42
|
-
if (!this.fieldNode)
|
|
43
|
-
throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
|
|
44
|
-
let newModifiers = [];
|
|
45
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
46
|
-
// Check if the field has an Length decorator.
|
|
47
|
-
//@ts-ignore
|
|
48
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
49
|
-
//Remove the column decorator if the column decorator exists
|
|
50
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
51
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
52
|
-
//Add the column decorator if column decorator is required
|
|
53
|
-
const changes = [];
|
|
54
|
-
if (this.isApplyDecorator()) {
|
|
55
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
56
|
-
changes.push(...this.decoratorImports());
|
|
57
|
-
}
|
|
58
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
59
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
60
|
-
return [updatedProperty, changes];
|
|
61
|
-
}
|
|
62
|
-
createDecorator(existingDecorator) {
|
|
63
|
-
// Capture the existing column decorator options
|
|
64
|
-
const validationOptions = [];
|
|
65
|
-
if (existingDecorator !== undefined) {
|
|
66
|
-
//Pre-set the column options from the existing column decorator
|
|
67
|
-
const existingCallExpression = existingDecorator.expression;
|
|
68
|
-
// Check if call expression has at least 1 arguments
|
|
69
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
70
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
71
|
-
throw new Error('Date decorator 1st argument must be an object literal containing the validation options');
|
|
72
|
-
}
|
|
73
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
74
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// Re-create the column decorator with the merged column decorator options
|
|
78
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier("IsDate");
|
|
79
|
-
const argumentsArray = [];
|
|
80
|
-
if (validationOptions.length > 0) {
|
|
81
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
82
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
83
|
-
}
|
|
84
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
85
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
86
|
-
}
|
|
87
|
-
findDecorator(name, existingModifiers) {
|
|
88
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
89
|
-
}
|
|
90
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
91
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
92
|
-
}
|
|
93
|
-
// private filterNonTransformerDecorators(existingDecorators: ts.Decorator[]): ts.Decorator[] {
|
|
94
|
-
// return existingDecorators ? existingDecorators.filter(m => !this.containsIdentifierName(m, 'Type')) : [];
|
|
95
|
-
// }
|
|
96
|
-
filterNonDecorators(existingModifiers) {
|
|
97
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
98
|
-
}
|
|
99
|
-
containsIdentifierName(m, identifierName) {
|
|
100
|
-
const callExpression = m.expression;
|
|
101
|
-
const identifier = callExpression.expression;
|
|
102
|
-
return identifier.text === identifierName;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.DateDecoratorManager = DateDecoratorManager;
|
|
106
|
-
//# sourceMappingURL=DateDecoratorManager.js.map
|