@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,345 +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.BaseFieldManagerForDto = void 0;
|
|
7
|
-
const strings_1 = require("@angular-devkit/core/src/utils/strings");
|
|
8
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
9
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
10
|
-
const change_1 = require("@schematics/angular/utility/change");
|
|
11
|
-
const FieldManager_1 = require("../../FieldManager");
|
|
12
|
-
const ArrayDecoratorManager_1 = require("../../decorator-managers/dto/ArrayDecoratorManager");
|
|
13
|
-
const BooleanDecoratorManager_1 = require("../../decorator-managers/dto/BooleanDecoratorManager");
|
|
14
|
-
const DateDecoratorManager_1 = require("../../decorator-managers/dto/DateDecoratorManager");
|
|
15
|
-
const DecimalDecoratorManager_1 = require("../../decorator-managers/dto/DecimalDecoratorManager");
|
|
16
|
-
const IntDecoratorManager_1 = require("../../decorator-managers/dto/IntDecoratorManager");
|
|
17
|
-
const JsonDecoratorManager_1 = require("../../decorator-managers/dto/JsonDecoratorManager");
|
|
18
|
-
const MaxDecoratorManager_1 = require("../../decorator-managers/dto/MaxDecoratorManager");
|
|
19
|
-
const MinDecoratorManager_1 = require("../../decorator-managers/dto/MinDecoratorManager");
|
|
20
|
-
const NumberDecoratorManager_1 = require("../../decorator-managers/dto/NumberDecoratorManager");
|
|
21
|
-
const OptionalDecoratorManager_1 = require("../../decorator-managers/dto/OptionalDecoratorManager");
|
|
22
|
-
const RegexDecoratorManager_1 = require("../../decorator-managers/dto/RegexDecoratorManager");
|
|
23
|
-
const RequiredDecoratorManager_1 = require("../../decorator-managers/dto/RequiredDecoratorManager");
|
|
24
|
-
const StringDecoratorManager_1 = require("../../decorator-managers/dto/StringDecoratorManager");
|
|
25
|
-
const TransformDecoratorManager_1 = require("../../decorator-managers/dto/TransformDecoratorManager");
|
|
26
|
-
const ValidateNestedDecoratorManager_1 = require("../../decorator-managers/dto/ValidateNestedDecoratorManager");
|
|
27
|
-
const BigIntDecoratorManager_1 = require("../../decorator-managers/dto/BigIntDecoratorManager");
|
|
28
|
-
const MaxLengthDecoratorManager_1 = require("../../decorator-managers/dto/MaxLengthDecoratorManager");
|
|
29
|
-
const MinLengthDecoratorManager_1 = require("../../decorator-managers/dto/MinLengthDecoratorManager");
|
|
30
|
-
// This class manages the field generation for the DTOs
|
|
31
|
-
// It adds validation decorators to the fields
|
|
32
|
-
// The validation decorators added use the class-validator library
|
|
33
|
-
class BaseFieldManagerForDto {
|
|
34
|
-
constructor(tree, moduleName, modelName, field, options) {
|
|
35
|
-
this.moduleName = moduleName;
|
|
36
|
-
this.modelName = modelName;
|
|
37
|
-
this.field = field;
|
|
38
|
-
this.options = options;
|
|
39
|
-
const sourceFileName = (options.sourceType === FieldManager_1.DtoSourceType.Create) ? `create-${(0, strings_1.dasherize)(modelName)}.dto.ts` : `update-${(0, strings_1.dasherize)(modelName)}.dto.ts`;
|
|
40
|
-
const sourcePath = `src/${(0, strings_1.dasherize)(moduleName)}/dtos/${sourceFileName}`;
|
|
41
|
-
this.source = (0, FieldManager_1.createSourceFile)(tree, sourcePath);
|
|
42
|
-
this.decoratorManagers = this.getFieldDecoratorManagers(this.field, this.source, FieldManager_1.DecoratorType.Max, FieldManager_1.DecoratorType.Min, FieldManager_1.DecoratorType.MinLength, FieldManager_1.DecoratorType.MaxLength, FieldManager_1.DecoratorType.Required, FieldManager_1.DecoratorType.Optional, FieldManager_1.DecoratorType.Regex, FieldManager_1.DecoratorType.Number, FieldManager_1.DecoratorType.Int, FieldManager_1.DecoratorType.Decimal, FieldManager_1.DecoratorType.String, FieldManager_1.DecoratorType.Date, FieldManager_1.DecoratorType.Boolean, FieldManager_1.DecoratorType.Json);
|
|
43
|
-
}
|
|
44
|
-
removeField() {
|
|
45
|
-
const fieldChanges = [];
|
|
46
|
-
console.log(`Dto removeField ${this.fieldName()} called ...`);
|
|
47
|
-
fieldChanges.push(this.removeFieldFor(this.fieldName(), this.source));
|
|
48
|
-
if (this.isAdditionalFieldRequired()) {
|
|
49
|
-
fieldChanges.push(...this.removeAdditionalField());
|
|
50
|
-
}
|
|
51
|
-
return fieldChanges;
|
|
52
|
-
}
|
|
53
|
-
fieldName() {
|
|
54
|
-
return this.field.name;
|
|
55
|
-
}
|
|
56
|
-
removeFieldFor(fieldName, fieldSource) {
|
|
57
|
-
const fieldIdentifierNode = this.getFieldIdentifierNode(fieldName, fieldSource);
|
|
58
|
-
if (fieldIdentifierNode == null) {
|
|
59
|
-
// throw new Error(`Could not remove field. Field: ${fieldName} is missing in entity ${classify(this.modelName)}.`);
|
|
60
|
-
return {
|
|
61
|
-
filePath: this.source.fileName,
|
|
62
|
-
field: this.field,
|
|
63
|
-
changes: [],
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const propertyDeclarationNode = fieldIdentifierNode.parent;
|
|
67
|
-
return {
|
|
68
|
-
filePath: fieldSource.fileName,
|
|
69
|
-
field: this.field,
|
|
70
|
-
changes: [
|
|
71
|
-
new FieldManager_1.RemoveChangeSSS(fieldSource.fileName, propertyDeclarationNode.pos, propertyDeclarationNode.getFullText()),
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
getFieldIdentifierNode(fieldName, fieldSource) {
|
|
76
|
-
return (0, ast_utils_1.findNodes)(fieldSource, typescript_1.default.SyntaxKind.Identifier)
|
|
77
|
-
.filter((node) => node.getText() === fieldName)
|
|
78
|
-
.filter((node) => (node === null || node === void 0 ? void 0 : node.parent) && typescript_1.default.isPropertyDeclaration(node === null || node === void 0 ? void 0 : node.parent))
|
|
79
|
-
.pop();
|
|
80
|
-
}
|
|
81
|
-
isFieldPresent(fieldName, fieldSource) {
|
|
82
|
-
return this.getFieldIdentifierNode(fieldName, fieldSource) != null;
|
|
83
|
-
}
|
|
84
|
-
addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source) {
|
|
85
|
-
//FIXME There might a case where the main field is not present, but additional field is present. Do we update the fields or throw an error. Needs to be discussed
|
|
86
|
-
// For now, we assume, that if primary field is not present, then additional field is also not present
|
|
87
|
-
if (this.isFieldPresent(fieldName, source)) {
|
|
88
|
-
return {
|
|
89
|
-
filePath: source.fileName,
|
|
90
|
-
field: field,
|
|
91
|
-
changes: [],
|
|
92
|
-
};
|
|
93
|
-
// throw new Error(
|
|
94
|
-
// `Field: ${fieldName} already exists in entity ${classify(modelName)}. Use the updateField() method to modify the field`
|
|
95
|
-
// );
|
|
96
|
-
}
|
|
97
|
-
const fieldSourceLines = [];
|
|
98
|
-
const changes = [];
|
|
99
|
-
//Add the dto field declaration
|
|
100
|
-
let dtoPropertyLine = this.buildPropertyLine(fieldName, fieldType, field.defaultValue);
|
|
101
|
-
fieldSourceLines.push(dtoPropertyLine);
|
|
102
|
-
//Add the decorators to the field declaration
|
|
103
|
-
const builderChanges = [];
|
|
104
|
-
builderChanges.push(...this.applyBuildDecoratorTransformations(...decoratorManagers.reverse()));
|
|
105
|
-
// Capture the changes and field source lines
|
|
106
|
-
builderChanges.forEach((builderChange) => {
|
|
107
|
-
changes.push(...builderChange.changes);
|
|
108
|
-
fieldSourceLines.push(...builderChange.fieldSourceLines);
|
|
109
|
-
});
|
|
110
|
-
// Create the field definition changes
|
|
111
|
-
// const classNode = findNodes(source, ts.SyntaxKind.ClassDeclaration)[0];
|
|
112
|
-
const className = (this.options.sourceType === FieldManager_1.DtoSourceType.Create) ? `Create${(0, strings_1.classify)(modelName)}Dto` : `Update${(0, strings_1.classify)(modelName)}Dto`;
|
|
113
|
-
const classNode = (0, FieldManager_1.getClassNode)(className, source);
|
|
114
|
-
if (!classNode) {
|
|
115
|
-
throw new Error(`Class ${className} not found in file ${source.fileName}`);
|
|
116
|
-
}
|
|
117
|
-
const fieldDefinition = `\n${fieldSourceLines.reverse().join('\n')}\n`;
|
|
118
|
-
changes.push(new change_1.InsertChange(source.fileName, classNode.end - 1, fieldDefinition));
|
|
119
|
-
return {
|
|
120
|
-
filePath: source.fileName,
|
|
121
|
-
field: field,
|
|
122
|
-
changes: changes,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
buildPropertyLine(fieldName, fieldType, defaultConfigValue) {
|
|
126
|
-
var _a, _b;
|
|
127
|
-
let entityPropertyLine = `${fieldName}: ${fieldType}`;
|
|
128
|
-
const defaultValue = (_b = (_a = this.defaultValueInitializer(defaultConfigValue)) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : null;
|
|
129
|
-
if (defaultValue) {
|
|
130
|
-
entityPropertyLine += ` = ${defaultValue}`;
|
|
131
|
-
}
|
|
132
|
-
entityPropertyLine += ';';
|
|
133
|
-
return entityPropertyLine;
|
|
134
|
-
}
|
|
135
|
-
addField() {
|
|
136
|
-
const fieldChanges = [];
|
|
137
|
-
const fieldName = this.fieldName();
|
|
138
|
-
const fieldType = this.fieldType().text;
|
|
139
|
-
const source = this.source;
|
|
140
|
-
const field = this.field;
|
|
141
|
-
const modelName = this.modelName;
|
|
142
|
-
const decoratorManagers = this.decoratorManagers;
|
|
143
|
-
fieldChanges.push(this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source));
|
|
144
|
-
if (this.isAdditionalFieldRequired()) {
|
|
145
|
-
// Get the related field property declaration node
|
|
146
|
-
fieldChanges.push(...this.addAdditionalField());
|
|
147
|
-
}
|
|
148
|
-
return fieldChanges;
|
|
149
|
-
}
|
|
150
|
-
updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source) {
|
|
151
|
-
var _a;
|
|
152
|
-
const changes = [];
|
|
153
|
-
// Get the field property declaration node
|
|
154
|
-
const fieldPropertyDeclarationNode = (_a = this.getFieldIdentifierNode(fieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
|
|
155
|
-
// FIXME Handle the imports related to the updated field type
|
|
156
|
-
// Update the entity property declaration type
|
|
157
|
-
let updatedPropertyDeclarationNode = this.updateFieldType(fieldPropertyDeclarationNode, fieldType);
|
|
158
|
-
// Apply the decorator transformations to the field property declaration node
|
|
159
|
-
const [updatedPropertyDeclarationNodeTransformed, decoratorChanges] = this.applyUpdateDecoratorTransformations(updatedPropertyDeclarationNode, ...decoratorManagers);
|
|
160
|
-
updatedPropertyDeclarationNode = updatedPropertyDeclarationNodeTransformed;
|
|
161
|
-
changes.push(...decoratorChanges);
|
|
162
|
-
changes.push(...this.calculateReplaceChanges(this.printNode(updatedPropertyDeclarationNode, source), fieldPropertyDeclarationNode, source));
|
|
163
|
-
return {
|
|
164
|
-
filePath: source.fileName,
|
|
165
|
-
field: field,
|
|
166
|
-
changes: changes,
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
updateField() {
|
|
170
|
-
const fieldChanges = [];
|
|
171
|
-
console.log(`\ncreate Dto updateField ${this.fieldName()} called ...`);
|
|
172
|
-
const fieldName = this.fieldName();
|
|
173
|
-
const fieldType = this.fieldType().node(this.field);
|
|
174
|
-
const source = this.source;
|
|
175
|
-
const field = this.field;
|
|
176
|
-
const decoratorManagers = this.decoratorManagers;
|
|
177
|
-
//Validate if field exists
|
|
178
|
-
if (!this.isFieldPresent(this.fieldName(), this.source)) {
|
|
179
|
-
return this.addField();
|
|
180
|
-
}
|
|
181
|
-
const fieldChange = this.updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source);
|
|
182
|
-
fieldChanges.push(fieldChange);
|
|
183
|
-
if (this.isAdditionalFieldRequired()) {
|
|
184
|
-
// Get the related field property declaration node
|
|
185
|
-
fieldChanges.push(...this.addOrUpdateAdditionalField()); // TODO This needs to be refactored and renamed to updateAdditionalField, since it is confusing
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
// fieldChanges.push(this.removeAdditionalField()); //FIXME temporary fix, to check update module command
|
|
189
|
-
}
|
|
190
|
-
return fieldChanges;
|
|
191
|
-
}
|
|
192
|
-
addAdditionalField() {
|
|
193
|
-
throw new Error(`addAdditionalField method not implemented for field ${this.fieldName()} of type ${this.field.type}`);
|
|
194
|
-
}
|
|
195
|
-
addOrUpdateAdditionalField() {
|
|
196
|
-
throw new Error(`addOrUpdateAdditionalField method not implemented for field ${this.fieldName()} of type ${this.field.type}`);
|
|
197
|
-
}
|
|
198
|
-
removeAdditionalField() {
|
|
199
|
-
return [{
|
|
200
|
-
filePath: this.source.fileName,
|
|
201
|
-
field: this.field,
|
|
202
|
-
changes: [],
|
|
203
|
-
}];
|
|
204
|
-
}
|
|
205
|
-
updateFieldType(fieldPropertyDeclarationNode, newTypeNode) {
|
|
206
|
-
// console.log(
|
|
207
|
-
// `\nEntity updateFieldType ${this.fieldName()} called ... with existing field type: ${fieldPropertyDeclarationNode.type?.getText()}`,
|
|
208
|
-
// );
|
|
209
|
-
// const newTypeNode: ts.TypeNode = this.fieldType().node(this.field);
|
|
210
|
-
const updatedPropertyDeclaration = typescript_1.default.factory.updatePropertyDeclaration(fieldPropertyDeclarationNode, fieldPropertyDeclarationNode.modifiers, fieldPropertyDeclarationNode.name, fieldPropertyDeclarationNode.questionToken, newTypeNode, // Replace with new type node
|
|
211
|
-
fieldPropertyDeclarationNode.initializer);
|
|
212
|
-
return updatedPropertyDeclaration;
|
|
213
|
-
}
|
|
214
|
-
isBigInt() {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
;
|
|
218
|
-
isApplyMinLength() {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
isApplyMaxLength() {
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
applyUpdateDecoratorTransformations(fieldPropertyDeclarationNode, ...transformers) {
|
|
225
|
-
let updatedPropertyDeclarationNode = fieldPropertyDeclarationNode;
|
|
226
|
-
const changes = [];
|
|
227
|
-
transformers.forEach(updateTransformation());
|
|
228
|
-
return [updatedPropertyDeclarationNode, changes];
|
|
229
|
-
function updateTransformation() {
|
|
230
|
-
return transformer => {
|
|
231
|
-
transformer.setFieldNode(updatedPropertyDeclarationNode);
|
|
232
|
-
try {
|
|
233
|
-
const [updatedPropertyDeclaration, updateChanges] = transformer.updateDecorator();
|
|
234
|
-
updatedPropertyDeclarationNode = updatedPropertyDeclaration;
|
|
235
|
-
changes.push(...updateChanges);
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
// console.log(`Error updating decorator for ${transformer.decoratorName()} with message: ${error.message}`);
|
|
239
|
-
throw error;
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
applyBuildDecoratorTransformations(...transformers) {
|
|
245
|
-
const partialFieldChanges = [];
|
|
246
|
-
transformers.forEach(buildTransformation());
|
|
247
|
-
return partialFieldChanges;
|
|
248
|
-
function buildTransformation() {
|
|
249
|
-
return transformer => {
|
|
250
|
-
if (!transformer.isApplyDecorator())
|
|
251
|
-
return;
|
|
252
|
-
try {
|
|
253
|
-
partialFieldChanges.push(transformer.buildDecorator());
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
// console.log(`Error building decorator for ${transformer.decoratorName()} with message: ${error.message}`);
|
|
257
|
-
throw error;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
calculateReplaceChanges(updatedPropertyDeclarationNodeText, fieldPropertyDeclarationNode, source) {
|
|
263
|
-
const changes = [];
|
|
264
|
-
if (updatedPropertyDeclarationNodeText.trim() !==
|
|
265
|
-
fieldPropertyDeclarationNode.getFullText().trim()) {
|
|
266
|
-
console.log(`Updated Code:\n${updatedPropertyDeclarationNodeText.trim()}\nwith length ${updatedPropertyDeclarationNodeText.trim().length}\n`);
|
|
267
|
-
console.log(`Old Code:\n${fieldPropertyDeclarationNode.getFullText().trim()}\nwith length ${fieldPropertyDeclarationNode.getFullText().trim().length}\n`);
|
|
268
|
-
const replaceChange = new FieldManager_1.ReplaceChangeSSS(source.fileName, fieldPropertyDeclarationNode.pos, fieldPropertyDeclarationNode.getFullText(), `\n\n${updatedPropertyDeclarationNodeText}`);
|
|
269
|
-
changes.push(replaceChange);
|
|
270
|
-
}
|
|
271
|
-
return changes;
|
|
272
|
-
}
|
|
273
|
-
printNode(updatedPropertyDeclarationNode, nodeSource) {
|
|
274
|
-
const printer = typescript_1.default.createPrinter({
|
|
275
|
-
newLine: typescript_1.default.NewLineKind.LineFeed,
|
|
276
|
-
removeComments: false,
|
|
277
|
-
omitTrailingSemicolon: false,
|
|
278
|
-
});
|
|
279
|
-
const updatedPropertyDeclarationNodeText = printer.printNode(typescript_1.default.EmitHint.Unspecified, updatedPropertyDeclarationNode, nodeSource);
|
|
280
|
-
return updatedPropertyDeclarationNodeText;
|
|
281
|
-
}
|
|
282
|
-
isAdditionalFieldRequired() {
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
//FIXME: This code is not useful, better initialize the decorators using the constructor, for now
|
|
286
|
-
getFieldDecoratorManagers(field, source, ...decoratorTypes) {
|
|
287
|
-
return decoratorTypes.map((decoratorType) => {
|
|
288
|
-
switch (decoratorType) {
|
|
289
|
-
case FieldManager_1.DecoratorType.Max:
|
|
290
|
-
return new MaxDecoratorManager_1.MaxDecoratorManager({ isApplyMax: this.isApplyMax(), max: field.max, source: source, field: field });
|
|
291
|
-
case FieldManager_1.DecoratorType.Min:
|
|
292
|
-
return new MinDecoratorManager_1.MinDecoratorManager({ isApplyMin: this.isApplyMin(), min: field.min, source: source, field: field });
|
|
293
|
-
case FieldManager_1.DecoratorType.MinLength:
|
|
294
|
-
return new MinLengthDecoratorManager_1.MinLengthDecoratorManager({ isApplyMinLength: this.isApplyMinLength(), length: field.min, source: source, field: field });
|
|
295
|
-
case FieldManager_1.DecoratorType.MaxLength:
|
|
296
|
-
return new MaxLengthDecoratorManager_1.MaxLengthDecoratorManager({ isApplyMaxLength: this.isApplyMaxLength(), length: field.max, source: source, field: field });
|
|
297
|
-
case FieldManager_1.DecoratorType.Required:
|
|
298
|
-
return new RequiredDecoratorManager_1.RequiredDecoratorManager({ isApplyRequired: true, required: field.required, source: source, field: field });
|
|
299
|
-
case FieldManager_1.DecoratorType.Optional:
|
|
300
|
-
return new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: (this.options.sourceType === FieldManager_1.DtoSourceType.Update || !field.required), source: source, field: field });
|
|
301
|
-
case FieldManager_1.DecoratorType.Regex:
|
|
302
|
-
return new RegexDecoratorManager_1.RegexDecoratorManager({ isApplyRegex: this.isApplyRegex(), regexPattern: field.regexPattern, source: source, field: field });
|
|
303
|
-
case FieldManager_1.DecoratorType.Number:
|
|
304
|
-
return new NumberDecoratorManager_1.NumberDecoratorManager({ isNumber: this.isNumber(), source: source, field: field });
|
|
305
|
-
case FieldManager_1.DecoratorType.String:
|
|
306
|
-
return new StringDecoratorManager_1.StringDecoratorManager({ isString: this.isString(), source: source, field: field });
|
|
307
|
-
case FieldManager_1.DecoratorType.Int:
|
|
308
|
-
return new IntDecoratorManager_1.IntDecoratorManager({ isInt: this.isInt(), source: source, field: field });
|
|
309
|
-
case FieldManager_1.DecoratorType.Decimal:
|
|
310
|
-
return new DecimalDecoratorManager_1.DecimalDecoratorManager({ isDecimal: this.isDecimal(), source: source, field: field });
|
|
311
|
-
case FieldManager_1.DecoratorType.BigInt:
|
|
312
|
-
return new BigIntDecoratorManager_1.BigIntDecoratorManager({ isBigInt: this.isBigInt(), source: source, field: field });
|
|
313
|
-
case FieldManager_1.DecoratorType.Date:
|
|
314
|
-
return new DateDecoratorManager_1.DateDecoratorManager({ isDate: this.isDate(), source: source, field: field });
|
|
315
|
-
case FieldManager_1.DecoratorType.Boolean:
|
|
316
|
-
return new BooleanDecoratorManager_1.BooleanDecoratorManager({ isBoolean: this.isBoolean(), source: source, field: field });
|
|
317
|
-
case FieldManager_1.DecoratorType.Json:
|
|
318
|
-
return new JsonDecoratorManager_1.JsonDecoratorManager({ isJson: this.isJson(), source: source, field: field });
|
|
319
|
-
case FieldManager_1.DecoratorType.Transform:
|
|
320
|
-
return new TransformDecoratorManager_1.TransformDecoratorManager({ isTransform: true, type: this.fieldType().text.replace("[]", ""), source: source, field: field });
|
|
321
|
-
case FieldManager_1.DecoratorType.Array:
|
|
322
|
-
return new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field });
|
|
323
|
-
case FieldManager_1.DecoratorType.ValidateNested:
|
|
324
|
-
return new ValidateNestedDecoratorManager_1.ValidateNestedDecoratorManager({ isValidateNested: true, source: source, field: field });
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
parseDefaultValue(defaultValueConfig) {
|
|
329
|
-
if (!defaultValueConfig)
|
|
330
|
-
return null;
|
|
331
|
-
return defaultValueConfig;
|
|
332
|
-
}
|
|
333
|
-
defaultValueInitializer(defaultValueConfig) {
|
|
334
|
-
const defaultValue = this.parseDefaultValue(defaultValueConfig);
|
|
335
|
-
if (!defaultValue)
|
|
336
|
-
return null;
|
|
337
|
-
return {
|
|
338
|
-
value: defaultValue,
|
|
339
|
-
text: `"${defaultValue.toString()}"`,
|
|
340
|
-
expression: typescript_1.default.factory.createStringLiteral(defaultValue.toString())
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
exports.BaseFieldManagerForDto = BaseFieldManagerForDto;
|
|
345
|
-
//# sourceMappingURL=BaseFieldManagerForDto.js.map
|