@solidstarters/solid-code-builder 1.0.20 → 1.0.22

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.
Files changed (93) hide show
  1. package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.d.ts +4 -0
  2. package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.js +61 -2
  3. package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.js.map +1 -1
  4. package/dist/files/generate-model/services/__model@dasherize__.service.ts +4 -4
  5. package/files/generate-model/services/__model@dasherize__.service.ts +4 -4
  6. package/package.json +5 -2
  7. package/publish.js +16 -0
  8. package/src/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.ts +71 -2
  9. package/dto_additional_fields_duplicate_fix.diff +0 -40
  10. package/src/code-builder/index.js +0 -178
  11. package/src/code-builder/index_spec.js +0 -46
  12. package/src/code-builder/lib/field/FieldManager.js +0 -236
  13. package/src/code-builder/lib/field/decorator-managers/dto/ArrayDecoratorManager.js +0 -107
  14. package/src/code-builder/lib/field/decorator-managers/dto/BigIntDecoratorManager.js +0 -100
  15. package/src/code-builder/lib/field/decorator-managers/dto/BooleanDecoratorManager.js +0 -102
  16. package/src/code-builder/lib/field/decorator-managers/dto/DateDecoratorManager.js +0 -106
  17. package/src/code-builder/lib/field/decorator-managers/dto/DecimalDecoratorManager.js +0 -112
  18. package/src/code-builder/lib/field/decorator-managers/dto/EmailDecoratorManager.js +0 -99
  19. package/src/code-builder/lib/field/decorator-managers/dto/IntDecoratorManager.js +0 -100
  20. package/src/code-builder/lib/field/decorator-managers/dto/JsonDecoratorManager.js +0 -100
  21. package/src/code-builder/lib/field/decorator-managers/dto/LengthDecoratorManager.js +0 -104
  22. package/src/code-builder/lib/field/decorator-managers/dto/MaxDecoratorManager.js +0 -103
  23. package/src/code-builder/lib/field/decorator-managers/dto/MaxLengthDecoratorManager.js +0 -103
  24. package/src/code-builder/lib/field/decorator-managers/dto/MinDecoratorManager.js +0 -102
  25. package/src/code-builder/lib/field/decorator-managers/dto/MinLengthDecoratorManager.js +0 -103
  26. package/src/code-builder/lib/field/decorator-managers/dto/NumberDecoratorManager.js +0 -112
  27. package/src/code-builder/lib/field/decorator-managers/dto/OptionalDecoratorManager.js +0 -104
  28. package/src/code-builder/lib/field/decorator-managers/dto/RegexDecoratorManager.js +0 -102
  29. package/src/code-builder/lib/field/decorator-managers/dto/RequiredDecoratorManager.js +0 -100
  30. package/src/code-builder/lib/field/decorator-managers/dto/StringDecoratorManager.js +0 -99
  31. package/src/code-builder/lib/field/decorator-managers/dto/TransformDecoratorManager.js +0 -102
  32. package/src/code-builder/lib/field/decorator-managers/dto/ValidateNestedDecoratorManager.js +0 -140
  33. package/src/code-builder/lib/field/decorator-managers/entity/ColumnDecoratorManager.js +0 -178
  34. package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +0 -79
  35. package/src/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js +0 -118
  36. package/src/code-builder/lib/field/decorator-managers/entity/ManyToManyDecoratorManager.js +0 -175
  37. package/src/code-builder/lib/field/decorator-managers/entity/ManyToOneDecoratorManager.js +0 -179
  38. package/src/code-builder/lib/field/decorator-managers/entity/OneToManyDecoratorManager.js +0 -155
  39. package/src/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js +0 -174
  40. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +0 -345
  41. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +0 -373
  42. package/src/code-builder/lib/field/field-managers/base/DeleteType.js +0 -11
  43. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldHandler.js +0 -33
  44. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForDto.js +0 -81
  45. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForEntity.js +0 -55
  46. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldHandler.js +0 -33
  47. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForDto.js +0 -75
  48. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForEntity.js +0 -51
  49. package/src/code-builder/lib/field/field-managers/computed/ComputedFieldHandler.js +0 -30
  50. package/src/code-builder/lib/field/field-managers/computed/ComputedFieldManagerForEntity.js +0 -33
  51. package/src/code-builder/lib/field/field-managers/date/DateFieldHandler.js +0 -33
  52. package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForDto.js +0 -81
  53. package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForEntity.js +0 -59
  54. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldHandler.js +0 -33
  55. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForDto.js +0 -77
  56. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForEntity.js +0 -53
  57. package/src/code-builder/lib/field/field-managers/email/EmailFieldHandler.js +0 -34
  58. package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForDto.js +0 -72
  59. package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForEntity.js +0 -44
  60. package/src/code-builder/lib/field/field-managers/int/IntFieldHandler.js +0 -33
  61. package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForDto.js +0 -76
  62. package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForEntity.js +0 -52
  63. package/src/code-builder/lib/field/field-managers/json/JsonFieldHandler.js +0 -34
  64. package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForDto.js +0 -57
  65. package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForEntity.js +0 -21
  66. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldHandler.js +0 -34
  67. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForDto.js +0 -63
  68. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForEntity.js +0 -34
  69. package/src/code-builder/lib/field/field-managers/media/MediaFieldHandler.js +0 -33
  70. package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForDto.js +0 -72
  71. package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForEntity.js +0 -57
  72. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldHandler.js +0 -27
  73. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForDto.js +0 -75
  74. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForEntity.js +0 -35
  75. package/src/code-builder/lib/field/field-managers/password/PasswordFieldHandler.js +0 -34
  76. package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForDto.js +0 -121
  77. package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForEntity.js +0 -37
  78. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldHandler.js +0 -33
  79. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +0 -366
  80. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -158
  81. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldHandler.js +0 -33
  82. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +0 -294
  83. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +0 -177
  84. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldHandler.js +0 -34
  85. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForDto.js +0 -63
  86. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForEntity.js +0 -34
  87. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldHandler.js +0 -34
  88. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForDto.js +0 -63
  89. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForEntity.js +0 -37
  90. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldHandler.js +0 -34
  91. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForDto.js +0 -15
  92. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForEntity.js +0 -33
  93. package/src/code-builder/lib/model/helpers.js +0 -407
@@ -1,373 +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.BaseFieldManagerForEntity = 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 ColumnDecoratorManager_1 = require("../../decorator-managers/entity/ColumnDecoratorManager");
13
- const IndexDecoratorManager_1 = require("../../decorator-managers/entity/IndexDecoratorManager");
14
- const ManyToOneDecoratorManager_1 = require("../../decorator-managers/entity/ManyToOneDecoratorManager");
15
- const ManyToManyDecoratorManager_1 = require("../../decorator-managers/entity/ManyToManyDecoratorManager");
16
- const JoinTableDecoratorManager_1 = require("../../decorator-managers/entity/JoinTableDecoratorManager");
17
- const FieldManager_2 = require("../../FieldManager");
18
- const UniqueIndexDecoratorManager_1 = require("../../decorator-managers/entity/UniqueIndexDecoratorManager");
19
- class BaseFieldManagerForEntity {
20
- constructor(tree, moduleName, modelName, field) {
21
- var _a;
22
- this.moduleName = moduleName;
23
- this.modelName = modelName;
24
- this.field = field;
25
- // TODO: Note that the source file instance is created during construction
26
- // So every operation should use a new instance of the field manager, so updated tree/source is used before each operation
27
- this.source = (0, FieldManager_1.createSourceFile)(tree, `src/${(0, strings_1.dasherize)(moduleName)}/entities/${(0, strings_1.dasherize)(modelName)}.entity.ts`);
28
- // this.relationInverseSource = createSourceFile(tree, `src/${dasherize(this.field.relationModelSingularName)}/dtos/create-${dasherize(this.field.relationModelSingularName)}.dto.ts`)
29
- const fieldPropertyDeclarationNode = (_a = this.getFieldIdentifierNode(this.fieldName(), this.source)) === null || _a === void 0 ? void 0 : _a.parent;
30
- this.indexDecoratorManager = new IndexDecoratorManager_1.IndexDecoratorManager({ index: this.field.index, source: this.source, field: this.field }, fieldPropertyDeclarationNode);
31
- this.columnDecoratorManager = new ColumnDecoratorManager_1.ColumnDecoratorManager({
32
- isColumn: this.isColumn(),
33
- columnName: this.field.columnName,
34
- type: this.field.ormType,
35
- required: this.field.required,
36
- otherOptions: this.additionalColumnDecoratorOptions(),
37
- otherOptionExpressions: this.additionalColumnDecoratorOptionExpressions(),
38
- source: this.source,
39
- field: this.field,
40
- }, fieldPropertyDeclarationNode);
41
- this.manyToOneDecoratorManager = new ManyToOneDecoratorManager_1.ManyToOneDecoratorManager({
42
- isManyToOne: this.isManyToOne(),
43
- relationModelSingularName: this.field.relationModelSingularName,
44
- relationCascade: this.field.relationCascade,
45
- required: this.field.required,
46
- source: this.source,
47
- field: this.field,
48
- fieldName: this.fieldName(),
49
- modelName: this.modelName,
50
- }, fieldPropertyDeclarationNode);
51
- this.manyToManyDecoratorManager = new ManyToManyDecoratorManager_1.ManyToManyDecoratorManager({
52
- isManyToMany: this.isManyToMany(),
53
- relationModelName: this.field.relationModelSingularName,
54
- relationInverseFieldName: this.field.relationModelFieldName,
55
- relationCascade: this.field.relationCascade,
56
- owner: true,
57
- source: this.source,
58
- field: this.field,
59
- fieldName: this.fieldName(),
60
- modelName: this.modelName,
61
- });
62
- this.joinTableDecoratorManager = new JoinTableDecoratorManager_1.JoinTableDecoratorManager({
63
- isManyToManyRelationOwner: this.field.relationType === FieldManager_2.RelationType.ManyToMany,
64
- source: this.source,
65
- field: this.field,
66
- fieldName: this.fieldName(),
67
- modelName: this.modelName,
68
- });
69
- this.uniqueIndexDecoratorManager = new UniqueIndexDecoratorManager_1.UniqueIndexDecoratorManager({ unique: this.field.unique, fieldName: this.fieldName(), source: this.source, field: this.field }, this.getClassNode(this.modelName, this.source));
70
- }
71
- addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source) {
72
- //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
73
- // For now, we assume, that if primary field is not present, then additional field is also not present
74
- if (this.isFieldPresent(fieldName, source)) {
75
- return {
76
- filePath: source.fileName,
77
- field: field,
78
- changes: [],
79
- };
80
- // throw new Error(
81
- // `Field: ${fieldName} already exists in entity ${classify(modelName)}. Use the updateField() method to modify the field`
82
- // );
83
- }
84
- const fieldSourceLines = [];
85
- const changes = [];
86
- //Add the entity field declaration
87
- let entityPropertyLine = this.buildPropertyLine(fieldName, fieldType, field.defaultValue);
88
- fieldSourceLines.push(entityPropertyLine);
89
- //Add the decorators to the field declaration
90
- const builderChanges = [];
91
- builderChanges.push(...this.applyBuildDecoratorTransformations(...decoratorManagers.reverse()));
92
- // Capture the changes and field source lines
93
- builderChanges.forEach((builderChange) => {
94
- changes.push(...builderChange.changes);
95
- fieldSourceLines.push(...builderChange.fieldSourceLines);
96
- });
97
- // Create the field definition changes
98
- // const classNode = findNodes(source, ts.SyntaxKind.ClassDeclaration)[0];
99
- const classNode = this.getClassNode(modelName, source);
100
- const fieldDefinition = `\n${fieldSourceLines.reverse().join('\n')}\n`;
101
- changes.push(new change_1.InsertChange(source.fileName, classNode.end - 1, fieldDefinition));
102
- // Apply the unique index decorator changes at the class node level
103
- const uniqueIndexDecoratorChanges = this.uniqueIndexDecoratorManager.buildDecorator();
104
- changes.push(...uniqueIndexDecoratorChanges.changes);
105
- const classDecoratorLines = `${uniqueIndexDecoratorChanges.fieldSourceLines.reverse().join('\n')}\n`;
106
- const classExportKeywordNode = (0, FieldManager_1.getClassExportKeywordNode)((0, strings_1.classify)(modelName), source);
107
- if (!classExportKeywordNode) {
108
- throw new Error(`Export keyword not found for class ${modelName} in file ${source.fileName}`);
109
- }
110
- const classExportKeywordStartPosition = classExportKeywordNode.getStart(source);
111
- changes.push(new change_1.InsertChange(source.fileName, classExportKeywordStartPosition, classDecoratorLines));
112
- return {
113
- filePath: source.fileName,
114
- field: field,
115
- changes: changes,
116
- };
117
- }
118
- uniqueIndexDecoratorChanges() {
119
- const changes = [];
120
- const [updatedClassNode, indexDecoratorChanges] = this.uniqueIndexDecoratorManager.updateDecorator();
121
- changes.push(...indexDecoratorChanges);
122
- return [updatedClassNode, changes];
123
- // changes.push(...this.calculateReplaceChanges(this.printNode(updatedClassNode, source), classNode, source));
124
- }
125
- getClassNode(modelName, source) {
126
- const className = (0, strings_1.classify)(modelName);
127
- const classNode = (0, FieldManager_1.getClassNode)(className, source);
128
- if (!classNode) {
129
- throw new Error(`Class ${className} not found in file ${source.fileName}`);
130
- }
131
- return classNode;
132
- }
133
- buildPropertyLine(fieldName, fieldType, defaultConfigValue) {
134
- var _a, _b;
135
- let entityPropertyLine = `${fieldName}: ${fieldType}`;
136
- const defaultValue = (_b = (_a = this.defaultValueInitializer(defaultConfigValue)) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : null;
137
- if (defaultValue) {
138
- entityPropertyLine += ` = ${defaultValue}`;
139
- }
140
- entityPropertyLine += ';';
141
- return entityPropertyLine;
142
- }
143
- addField() {
144
- const fieldChanges = [];
145
- const fieldName = this.fieldName();
146
- const fieldType = this.fieldType().text;
147
- const source = this.source;
148
- const field = this.field;
149
- const modelName = this.modelName;
150
- const decoratorManagers = this.decoratorManagers();
151
- fieldChanges.push(this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source));
152
- if (this.isAdditionalFieldRequired()) {
153
- // Get the related field property declaration node
154
- fieldChanges.push(...this.addAdditionalField());
155
- }
156
- return fieldChanges;
157
- }
158
- updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source) {
159
- var _a, _b;
160
- const changes = [];
161
- // Get the field property declaration node
162
- const fieldPropertyDeclarationNode = (_a = this.getFieldIdentifierNode(fieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
163
- // FIXME Handle the imports related to the updated field type
164
- // Update the entity property declaration type
165
- let updatedPropertyDeclarationNode = this.updateFieldType(fieldPropertyDeclarationNode, fieldType);
166
- updatedPropertyDeclarationNode =
167
- this.updateFieldInitializer(fieldPropertyDeclarationNode, (_b = this.defaultValueInitializer(field.defaultValue)) === null || _b === void 0 ? void 0 : _b.expression);
168
- // Apply the decorator transformations to the field property declaration node
169
- const [updatedPropertyDeclarationNodeTransformed, decoratorChanges] = this.applyUpdateDecoratorTransformations(updatedPropertyDeclarationNode, ...decoratorManagers);
170
- updatedPropertyDeclarationNode = updatedPropertyDeclarationNodeTransformed;
171
- changes.push(...decoratorChanges);
172
- // Update the property declaration node in the class hierarchy with the updated property declaration node
173
- // Then calculate the replace changes
174
- // changes.push(...this.calculateReplaceChanges(this.printNode(updatedPropertyDeclarationNode, source), fieldPropertyDeclarationNode, source));
175
- this.uniqueIndexDecoratorManager.setFieldNode(updatedPropertyDeclarationNode);
176
- // Apply the unique index decorator changes at the class node level
177
- const [updatedClassNode, uniqueIndexDecoratorChanges] = this.uniqueIndexDecoratorChanges();
178
- changes.push(...uniqueIndexDecoratorChanges);
179
- changes.push(...this.calculateReplaceChanges(this.printNode(updatedClassNode, source), this.getClassNode(this.modelName, source), source)); //FIXME: this.modelName to passed in for avoiding statefullness
180
- // this.uniqueIndexDecoratorChanges(changes, source, this.getClassNode(this.modelName, source));
181
- return {
182
- filePath: source.fileName,
183
- field: field,
184
- changes: changes,
185
- };
186
- }
187
- updateField() {
188
- const fieldChanges = [];
189
- console.log(`\nentity updateField ${this.fieldName()} called ...`);
190
- const fieldName = this.fieldName();
191
- const fieldType = this.fieldType().node(this.field);
192
- const source = this.source;
193
- const field = this.field;
194
- const decoratorManagers = this.decoratorManagers();
195
- //Validate if field exists
196
- if (!this.isFieldPresent(this.fieldName(), this.source)) {
197
- return this.addField();
198
- }
199
- const fieldChange = this.updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source);
200
- fieldChanges.push(fieldChange);
201
- if (this.isAdditionalFieldRequired()) {
202
- // Get the related field property declaration node
203
- fieldChanges.push(...this.addOrUpdateAdditionalField()); // TODO This needs to be refactored and renamed to updateAdditionalField, since it is confusing
204
- }
205
- else {
206
- // fieldChanges.push(this.removeAdditionalField()); //FIXME temporary fix, to check update module command
207
- }
208
- return fieldChanges;
209
- }
210
- //TODO how to handle scenarios, wherein fieldname() implementation has changed later, after add field code was autogenerated
211
- removeField() {
212
- const fieldChanges = [];
213
- console.log(`Entity removeField ${this.fieldName()} called ...`);
214
- fieldChanges.push(this.removeFieldFor(this.fieldName(), this.source));
215
- if (this.isAdditionalFieldRequired()) {
216
- fieldChanges.push(this.removeAdditionalField());
217
- }
218
- return fieldChanges;
219
- }
220
- removeFieldFor(fieldName, fieldSource) {
221
- const fieldIdentifierNode = this.getFieldIdentifierNode(fieldName, fieldSource);
222
- if (fieldIdentifierNode == null) {
223
- return {
224
- filePath: fieldSource.fileName,
225
- field: this.field,
226
- changes: [],
227
- };
228
- }
229
- const propertyDeclarationNode = fieldIdentifierNode.parent;
230
- return {
231
- filePath: fieldSource.fileName,
232
- field: this.field,
233
- changes: [
234
- new FieldManager_1.RemoveChangeSSS(fieldSource.fileName, propertyDeclarationNode.pos, propertyDeclarationNode.getFullText()),
235
- ],
236
- };
237
- }
238
- calculateReplaceChanges(updateNodeText, sourceNode, source) {
239
- const changes = [];
240
- if (updateNodeText.trim() !==
241
- sourceNode.getFullText().trim()) {
242
- console.log(`Updated Code:\n${updateNodeText.trim()}\nwith length ${updateNodeText.trim().length}\n`);
243
- console.log(`Old Code:\n${sourceNode.getFullText().trim()}\nwith length ${sourceNode.getFullText().trim().length}\n`);
244
- const replaceChange = new FieldManager_1.ReplaceChangeSSS(source.fileName, sourceNode.pos, sourceNode.getFullText(), `\n\n${updateNodeText}`);
245
- changes.push(replaceChange);
246
- }
247
- return changes;
248
- }
249
- printNode(updatedPropertyDeclarationNode, nodeSource) {
250
- const printer = typescript_1.default.createPrinter({
251
- newLine: typescript_1.default.NewLineKind.LineFeed,
252
- removeComments: false,
253
- omitTrailingSemicolon: false,
254
- });
255
- const updatedPropertyDeclarationNodeText = printer.printNode(typescript_1.default.EmitHint.Unspecified, updatedPropertyDeclarationNode, nodeSource);
256
- return updatedPropertyDeclarationNodeText;
257
- }
258
- getFieldIdentifierNode(fieldName, fieldSource) {
259
- return (0, ast_utils_1.findNodes)(fieldSource, typescript_1.default.SyntaxKind.Identifier)
260
- .filter((node) => node.getText() === fieldName)
261
- .filter((node) => (node === null || node === void 0 ? void 0 : node.parent) && typescript_1.default.isPropertyDeclaration(node === null || node === void 0 ? void 0 : node.parent))
262
- .pop();
263
- }
264
- isFieldPresent(fieldName, fieldSource) {
265
- return this.getFieldIdentifierNode(fieldName, fieldSource) != null;
266
- }
267
- fieldName() {
268
- return this.field.name;
269
- }
270
- additionalColumnDecoratorOptions() {
271
- return new Map();
272
- }
273
- additionalColumnDecoratorOptionExpressions() {
274
- return new Map();
275
- }
276
- updateFieldType(fieldPropertyDeclarationNode, newTypeNode) {
277
- if (!newTypeNode)
278
- return fieldPropertyDeclarationNode;
279
- const updatedPropertyDeclaration = typescript_1.default.factory.updatePropertyDeclaration(fieldPropertyDeclarationNode, fieldPropertyDeclarationNode.modifiers, fieldPropertyDeclarationNode.name, fieldPropertyDeclarationNode.questionToken, newTypeNode, // Replace with new type node
280
- fieldPropertyDeclarationNode.initializer);
281
- return updatedPropertyDeclaration;
282
- }
283
- updateFieldInitializer(fieldPropertyDeclarationNode, initializer) {
284
- if (!initializer)
285
- return fieldPropertyDeclarationNode;
286
- const updatedPropertyDeclaration = typescript_1.default.factory.updatePropertyDeclaration(fieldPropertyDeclarationNode, fieldPropertyDeclarationNode.modifiers, fieldPropertyDeclarationNode.name, fieldPropertyDeclarationNode.questionToken, fieldPropertyDeclarationNode.type, initializer // Replace with new initializer
287
- );
288
- return updatedPropertyDeclaration;
289
- }
290
- inverseRelationFieldName() {
291
- return `${this.field.relationModelSingularName}s`;
292
- }
293
- isManyToOne() {
294
- return (this.field.type === 'relation' && this.field.relationType === FieldManager_2.RelationType.ManyToOne);
295
- }
296
- isAdditionalFieldRequired() {
297
- return false;
298
- }
299
- isManyToMany() {
300
- return (this.field.type === 'relation' && this.field.relationType === FieldManager_2.RelationType.ManyToMany);
301
- }
302
- isColumn() {
303
- return this.field.type !== 'relation';
304
- }
305
- applyUpdateDecoratorTransformations(fieldPropertyDeclarationNode, ...transformers) {
306
- let updatedPropertyDeclarationNode = fieldPropertyDeclarationNode;
307
- const changes = [];
308
- transformers.forEach(updateTransformation());
309
- return [updatedPropertyDeclarationNode, changes];
310
- function updateTransformation() {
311
- return transformer => {
312
- transformer.setFieldNode(updatedPropertyDeclarationNode);
313
- try {
314
- const [updatedPropertyDeclaration, updateChanges] = transformer.updateDecorator();
315
- updatedPropertyDeclarationNode = updatedPropertyDeclaration;
316
- changes.push(...updateChanges);
317
- }
318
- catch (error) {
319
- // console.log(`Error updating decorator for ${transformer.decoratorName()} with message: ${error.message}`);
320
- throw error;
321
- }
322
- };
323
- }
324
- }
325
- applyBuildDecoratorTransformations(...transformers) {
326
- const partialFieldChanges = [];
327
- transformers.forEach(buildTransformation());
328
- return partialFieldChanges;
329
- function buildTransformation() {
330
- return transformer => {
331
- if (!transformer.isApplyDecorator())
332
- return;
333
- partialFieldChanges.push(transformer.buildDecorator());
334
- };
335
- }
336
- }
337
- decoratorManagers() {
338
- return [this.indexDecoratorManager, this.columnDecoratorManager, this.manyToOneDecoratorManager, this.manyToManyDecoratorManager, this.joinTableDecoratorManager];
339
- }
340
- addAdditionalField() {
341
- throw new Error(`addAdditionalField method not implemented for field ${this.fieldName()} of type ${this.field.type}`);
342
- }
343
- addOrUpdateAdditionalField() {
344
- throw new Error(`addOrUpdateAdditionalField method not implemented for field ${this.fieldName()} of type ${this.field.type}`);
345
- }
346
- removeAdditionalField() {
347
- return {
348
- filePath: this.source.fileName,
349
- field: this.field,
350
- changes: [],
351
- };
352
- }
353
- additionalFieldName() {
354
- throw new Error(`additionalFieldName method not implemented for field ${this.fieldName()} of type ${this.field.type}`);
355
- }
356
- parseDefaultValue(defaultValueConfig) {
357
- if (!defaultValueConfig)
358
- return null;
359
- return defaultValueConfig;
360
- }
361
- defaultValueInitializer(defaultValueConfig) {
362
- const defaultValue = this.parseDefaultValue(defaultValueConfig);
363
- if (!defaultValue)
364
- return null;
365
- return {
366
- value: defaultValue,
367
- text: `"${defaultValue.toString()}"`,
368
- expression: typescript_1.default.factory.createStringLiteral(defaultValue.toString())
369
- };
370
- }
371
- }
372
- exports.BaseFieldManagerForEntity = BaseFieldManagerForEntity;
373
- //# sourceMappingURL=BaseFieldManagerForEntity.js.map
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeleteType = void 0;
4
- var DeleteType;
5
- (function (DeleteType) {
6
- DeleteType["CASCADE"] = "CASCADE";
7
- DeleteType["RESTRICT"] = "RESTRICT";
8
- DeleteType["SET_NULL"] = "SET_NULL";
9
- DeleteType["SET_DEFAULT"] = "SET_DEFAULT";
10
- })(DeleteType || (exports.DeleteType = DeleteType = {}));
11
- //# sourceMappingURL=DeleteType.js.map
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BigIntFieldHandler = void 0;
4
- const FieldManager_1 = require("../../FieldManager");
5
- const BigIntFieldManagerForDto_1 = require("./BigIntFieldManagerForDto");
6
- const BigIntFieldManagerForEntity_1 = require("./BigIntFieldManagerForEntity");
7
- class BigIntFieldHandler {
8
- constructor(tree, moduleName, modelName, field) {
9
- this.entityFieldManager = new BigIntFieldManagerForEntity_1.BigIntFieldManagerForEntity(tree, moduleName, modelName, field);
10
- this.createDtoFieldManager = new BigIntFieldManagerForDto_1.BigIntFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Create));
11
- this.updateDtoFieldManager = new BigIntFieldManagerForDto_1.BigIntFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Update));
12
- }
13
- updateEntityField() {
14
- return this.entityFieldManager.updateField();
15
- }
16
- updateDtoField() {
17
- return [...this.createDtoFieldManager.updateField(), ...this.updateDtoFieldManager.updateField()];
18
- }
19
- removeEntityField() {
20
- return this.entityFieldManager.removeField();
21
- }
22
- removeDtoField() {
23
- return [...this.createDtoFieldManager.removeField(), ...this.updateDtoFieldManager.removeField()];
24
- }
25
- addEntityField() {
26
- return this.entityFieldManager.addField();
27
- }
28
- addDtoField() {
29
- return [...this.createDtoFieldManager.addField(), ...this.updateDtoFieldManager.addField()];
30
- }
31
- }
32
- exports.BigIntFieldHandler = BigIntFieldHandler;
33
- //# sourceMappingURL=BigIntFieldHandler.js.map
@@ -1,81 +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.BigIntFieldManagerForDto = void 0;
7
- const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
8
- const BaseFieldManagerForDto_1 = require("../base/BaseFieldManagerForDto");
9
- class BigIntFieldManagerForDto extends BaseFieldManagerForDto_1.BaseFieldManagerForDto {
10
- isJson() {
11
- return false;
12
- }
13
- isBoolean() {
14
- return false;
15
- }
16
- constructor(tree, moduleName, modelName, field, options) {
17
- super(tree, moduleName, modelName, field, options);
18
- }
19
- isString() {
20
- return false;
21
- }
22
- isNumber() {
23
- return false;
24
- }
25
- isInt() {
26
- return false;
27
- }
28
- isDecimal() {
29
- return false;
30
- }
31
- isBigInt() {
32
- return true;
33
- }
34
- isApplyRegex() {
35
- return false;
36
- }
37
- isApplyRequired() {
38
- return true;
39
- }
40
- isApplyMin() {
41
- return true;
42
- }
43
- isApplyMax() {
44
- return true;
45
- }
46
- isDate() {
47
- return false;
48
- }
49
- isTransform() {
50
- return false;
51
- }
52
- fieldType() {
53
- return {
54
- text: 'bigint',
55
- node: (_field) => typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BigIntKeyword),
56
- };
57
- }
58
- parseDefaultValue(defaultValue) {
59
- if (!defaultValue)
60
- return null;
61
- try {
62
- return BigInt(defaultValue);
63
- }
64
- catch (e) {
65
- // console.log(`Could not set default value ${defaultValue} for field ${this.field.name} in model ${this.modelName}`);
66
- return null;
67
- }
68
- }
69
- defaultValueInitializer(defaultValueConfig) {
70
- const defaultValue = this.parseDefaultValue(defaultValueConfig);
71
- if (!defaultValue)
72
- return null;
73
- return {
74
- value: defaultValue,
75
- text: `${defaultValue.toString()}n`,
76
- expression: typescript_1.default.factory.createBigIntLiteral(defaultValue.toString())
77
- };
78
- }
79
- }
80
- exports.BigIntFieldManagerForDto = BigIntFieldManagerForDto;
81
- //# sourceMappingURL=BigIntFieldManagerForDto.js.map
@@ -1,55 +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.BigIntFieldManagerForEntity = void 0;
7
- const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
8
- const BaseFieldManagerForEntity_1 = require("../base/BaseFieldManagerForEntity");
9
- class BigIntFieldManagerForEntity extends BaseFieldManagerForEntity_1.BaseFieldManagerForEntity {
10
- constructor(tree, moduleName, modelName, field) {
11
- super(tree, moduleName, modelName, field);
12
- }
13
- fieldType() {
14
- return {
15
- text: 'bigint',
16
- node: (_field) => typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BigIntKeyword),
17
- };
18
- }
19
- additionalColumnDecoratorOptions() {
20
- var _a, _b;
21
- // Parse the default value from the field & set it to the column options
22
- const options = new Map();
23
- options.set('default', (_b = (_a = this.defaultValueInitializer(this.field.defaultValue)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null);
24
- return options;
25
- }
26
- additionalColumnDecoratorOptionExpressions() {
27
- var _a, _b;
28
- const options = new Map();
29
- options.set('default', (_b = (_a = this.defaultValueInitializer(this.field.defaultValue)) === null || _a === void 0 ? void 0 : _a.expression) !== null && _b !== void 0 ? _b : null);
30
- return options;
31
- }
32
- parseDefaultValue(defaultValue) {
33
- if (!defaultValue)
34
- return null;
35
- try {
36
- return BigInt(defaultValue);
37
- }
38
- catch (e) {
39
- // console.log(`Could not set default value ${defaultValue} for field ${this.field.name} in model ${this.modelName}`);
40
- return null;
41
- }
42
- }
43
- defaultValueInitializer(defaultValueConfig) {
44
- const defaultValue = this.parseDefaultValue(defaultValueConfig);
45
- if (!defaultValue)
46
- return null;
47
- return {
48
- value: defaultValue,
49
- text: `${defaultValue.toString()}n`,
50
- expression: typescript_1.default.factory.createBigIntLiteral(defaultValue.toString())
51
- };
52
- }
53
- }
54
- exports.BigIntFieldManagerForEntity = BigIntFieldManagerForEntity;
55
- //# sourceMappingURL=BigIntFieldManagerForEntity.js.map
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BooleanFieldHandler = void 0;
4
- const FieldManager_1 = require("../../FieldManager");
5
- const BooleanFieldManagerForDto_1 = require("./BooleanFieldManagerForDto");
6
- const BooleanFieldManagerForEntity_1 = require("./BooleanFieldManagerForEntity");
7
- class BooleanFieldHandler {
8
- constructor(tree, moduleName, modelName, field) {
9
- this.entityFieldManager = new BooleanFieldManagerForEntity_1.BooleanFieldManagerForEntity(tree, moduleName, modelName, field);
10
- this.createDtoFieldManager = new BooleanFieldManagerForDto_1.BooleanFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Create));
11
- this.updateDtoFieldManager = new BooleanFieldManagerForDto_1.BooleanFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Update));
12
- }
13
- updateEntityField() {
14
- return this.entityFieldManager.updateField();
15
- }
16
- updateDtoField() {
17
- return [...this.createDtoFieldManager.updateField(), ...this.updateDtoFieldManager.updateField()];
18
- }
19
- removeEntityField() {
20
- return this.entityFieldManager.removeField();
21
- }
22
- removeDtoField() {
23
- return [...this.createDtoFieldManager.removeField(), ...this.updateDtoFieldManager.removeField()];
24
- }
25
- addEntityField() {
26
- return this.entityFieldManager.addField();
27
- }
28
- addDtoField() {
29
- return [...this.createDtoFieldManager.addField(), ...this.updateDtoFieldManager.addField()];
30
- }
31
- }
32
- exports.BooleanFieldHandler = BooleanFieldHandler;
33
- //# sourceMappingURL=BooleanFieldHandler.js.map
@@ -1,75 +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.BooleanFieldManagerForDto = void 0;
7
- const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
8
- const BaseFieldManagerForDto_1 = require("../base/BaseFieldManagerForDto");
9
- class BooleanFieldManagerForDto extends BaseFieldManagerForDto_1.BaseFieldManagerForDto {
10
- isJson() {
11
- return false;
12
- }
13
- isBoolean() {
14
- return true;
15
- }
16
- constructor(tree, moduleName, modelName, field, options) {
17
- super(tree, moduleName, modelName, field, options);
18
- }
19
- isString() {
20
- return false;
21
- }
22
- isNumber() {
23
- return false;
24
- }
25
- isInt() {
26
- return false;
27
- }
28
- isDecimal() {
29
- return false;
30
- }
31
- isApplyRegex() {
32
- return false;
33
- }
34
- isApplyRequired() {
35
- return true;
36
- }
37
- isApplyMin() {
38
- return false;
39
- }
40
- isApplyMax() {
41
- return false;
42
- }
43
- isDate() {
44
- return false;
45
- }
46
- isTransform() {
47
- return false;
48
- }
49
- fieldType() {
50
- return {
51
- text: 'boolean',
52
- node: (_field) => typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.BooleanKeyword),
53
- };
54
- }
55
- parseDefaultValue(defaultValue) {
56
- try {
57
- return Boolean(defaultValue);
58
- }
59
- catch (e) {
60
- // console.log(`Could not set default value ${defaultValue} for field ${this.field.name} in model ${this.modelName}`);
61
- }
62
- return null;
63
- }
64
- defaultValueInitializer(defaultValueConfig) {
65
- var _a;
66
- const defaultValue = (_a = this.parseDefaultValue(defaultValueConfig)) !== null && _a !== void 0 ? _a : false;
67
- return {
68
- value: defaultValue,
69
- text: defaultValue.toString(),
70
- expression: defaultValue ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse()
71
- };
72
- }
73
- }
74
- exports.BooleanFieldManagerForDto = BooleanFieldManagerForDto;
75
- //# sourceMappingURL=BooleanFieldManagerForDto.js.map