@solidstarters/solid-code-builder 1.0.11 → 1.0.12

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 (52) hide show
  1. package/dist/code-builder/lib/field/FieldManager.d.ts +2 -1
  2. package/dist/code-builder/lib/field/FieldManager.js +18 -5
  3. package/dist/code-builder/lib/field/FieldManager.js.map +1 -1
  4. package/dist/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +1 -1
  5. package/dist/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js.map +1 -1
  6. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.d.ts +3 -0
  7. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +15 -3
  8. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js.map +1 -1
  9. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.d.ts +13 -0
  10. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.js +33 -0
  11. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.js.map +1 -0
  12. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.d.ts +4 -0
  13. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.js +9 -0
  14. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.js.map +1 -0
  15. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.d.ts +4 -0
  16. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.js +8 -0
  17. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.js.map +1 -0
  18. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.d.ts +1 -16
  19. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +15 -156
  20. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js.map +1 -1
  21. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.d.ts +1 -20
  22. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -109
  23. package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js.map +1 -1
  24. package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.d.ts +2 -17
  25. package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +4 -175
  26. package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js.map +1 -1
  27. package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.d.ts +1 -22
  28. package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +1 -133
  29. package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js.map +1 -1
  30. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.d.ts +13 -0
  31. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.js +33 -0
  32. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.js.map +1 -0
  33. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.d.ts +34 -0
  34. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.js +202 -0
  35. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.js.map +1 -0
  36. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.d.ts +9 -0
  37. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.js +43 -0
  38. package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.js.map +1 -0
  39. package/package.json +1 -1
  40. package/src/code-builder/lib/field/FieldManager.ts +19 -6
  41. package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.ts +1 -1
  42. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.ts +19 -3
  43. package/src/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.ts +52 -0
  44. package/src/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.ts +8 -0
  45. package/src/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.ts +8 -0
  46. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.ts +16 -189
  47. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.ts +2 -147
  48. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.ts +6 -215
  49. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.ts +3 -174
  50. package/src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.ts +52 -0
  51. package/src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.ts +247 -0
  52. package/src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.ts +51 -0
@@ -0,0 +1,247 @@
1
+ import { classify, dasherize } from '@angular-devkit/core/src/utils/strings';
2
+ import { Tree } from '@angular-devkit/schematics';
3
+ import ts, { PropertyDeclaration } from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
4
+ import { Change } from '@schematics/angular/utility/change';
5
+ import { ArrayDecoratorManager } from '../../decorator-managers/dto/ArrayDecoratorManager';
6
+ import { OptionalDecoratorManager } from '../../decorator-managers/dto/OptionalDecoratorManager';
7
+ import { StringDecoratorManager } from '../../decorator-managers/dto/StringDecoratorManager';
8
+ import { TransformDecoratorManager } from '../../decorator-managers/dto/TransformDecoratorManager';
9
+ import { DecoratorType, FieldChange, FieldManager, FieldType, ManagerForDtoOptions, safeInsertImport } from '../../FieldManager';
10
+ import { BaseFieldManagerForDto } from '../base/BaseFieldManagerForDto';
11
+
12
+ export class OneToManyRelationFieldManagerForDto
13
+ extends BaseFieldManagerForDto
14
+ implements FieldManager {
15
+ isJson(): boolean {
16
+ return false;
17
+ }
18
+ isBoolean(): boolean {
19
+ return false;
20
+ }
21
+
22
+ constructor(tree: Tree, moduleName: string, modelName: string, field: any, options: ManagerForDtoOptions) {
23
+ super(tree, moduleName, modelName, { ...field, required: false }, options);
24
+ this.decoratorManagers = [...this.decoratorManagers, ...this.getFieldDecoratorManagers(
25
+ this.field,
26
+ this.source,
27
+ DecoratorType.Array,
28
+ DecoratorType.ValidateNested,
29
+ )];
30
+ this.decoratorManagers.push(
31
+ new TransformDecoratorManager({ isTransform: true, type: this.transformType(), source: this.source, field: field })
32
+ );
33
+ }
34
+
35
+ isString(): boolean {
36
+ return false;
37
+ }
38
+ isNumber(): boolean {
39
+ return false;
40
+ }
41
+ isInt(): boolean {
42
+ return false;
43
+ }
44
+ isDecimal(): boolean {
45
+ return false;
46
+ }
47
+ isApplyRegex(): boolean {
48
+ return false;
49
+ }
50
+ isApplyRequired(): boolean {
51
+ return false;
52
+ }
53
+ isApplyMin(): boolean {
54
+ return false;
55
+ }
56
+ isApplyMax(): boolean {
57
+ return false;
58
+ }
59
+ isDate(): boolean {
60
+ return false;
61
+ }
62
+ isTransform(): boolean {
63
+ return false;
64
+ }
65
+
66
+ // This field type is used in the case of one-to-many relation, when we generate the inverse field in the related entity
67
+ fieldType(): FieldType {
68
+ const type = this.transformType() //TODO Discuss if this needs to be Create Or Update DTO
69
+ const text = `${type}[]`
70
+ return {
71
+ text: text,
72
+ node: (_field: any) =>
73
+ ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(
74
+ ts.factory.createIdentifier(type),
75
+ undefined
76
+ )),
77
+ };
78
+ }
79
+
80
+ private transformType(): string {
81
+ return `Update${classify(this.field.relationModelSingularName)}Dto`;
82
+ }
83
+
84
+ override addField(): FieldChange[] {
85
+ const fieldChanges: FieldChange[] = super.addField();
86
+ if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
87
+ const mainField = fieldChanges[0];
88
+ mainField.changes.push(this.relatedFieldImport());
89
+ }
90
+ return fieldChanges;
91
+ }
92
+
93
+ override addAdditionalField(): FieldChange[] {
94
+ const fieldChanges: FieldChange[] = [];
95
+
96
+ // Add the ids field to the main entity
97
+ fieldChanges.push(this.addAdditionalIdsField());
98
+ // Add the command field to the main entity
99
+ fieldChanges.push(this.addAdditionalCommandField());
100
+
101
+ return fieldChanges;
102
+ }
103
+
104
+ private addAdditionalIdsField(): FieldChange {
105
+ const fieldName = `${this.field.name}Ids`;
106
+ const fieldType = "number[]";
107
+ const source = this.source
108
+ const field = this.field
109
+ const modelName = this.modelName
110
+ const decoratorManagers = [
111
+ new OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
112
+ new ArrayDecoratorManager({ isArray: true, source: source, field: field })
113
+ ]
114
+
115
+ return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
116
+ }
117
+
118
+ private addAdditionalCommandField(): FieldChange {
119
+ const fieldName = `${this.field.name}Command`;
120
+ const fieldType = "string";
121
+ const source = this.source
122
+ const field = this.field
123
+ const modelName = this.modelName
124
+ const decoratorManagers = [
125
+ new StringDecoratorManager({ isString: true, source: source, field: field }),
126
+ new OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
127
+ // TODO pending @IsEnum(RelationFieldsCommand)
128
+ ]
129
+
130
+ return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
131
+
132
+ }
133
+
134
+
135
+ override updateField(): FieldChange[] {
136
+ const fieldChanges: FieldChange[] = super.updateField();
137
+
138
+ //FIXME This might not be required, since addField might never be called from within updateField
139
+ // const containsAddFieldChanges = fieldChanges.filter((change) => !(change instanceof InsertChange));
140
+ // if (containsAddFieldChanges) return fieldChanges;
141
+
142
+ //This line is required to add import changes in the update context
143
+ // if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
144
+ const mainField = fieldChanges[0];
145
+ mainField.changes.push(this.relatedFieldImport());
146
+ // }
147
+ return fieldChanges
148
+ }
149
+
150
+ override addOrUpdateAdditionalField(): FieldChange[] {
151
+ const fieldChanges: FieldChange[] = [];
152
+
153
+ // Add or update the ids field
154
+ fieldChanges.push(this.updateAdditionalIdsField());
155
+ // Add or update the command field
156
+ fieldChanges.push(this.updateAdditionalCommandField());
157
+
158
+ return fieldChanges;
159
+ }
160
+
161
+ private updateAdditionalIdsField(): FieldChange {
162
+ const idsFieldName = `${this.field.name}Ids`
163
+ const source = this.source
164
+ const field = this.field
165
+
166
+ // Handle the main source additional fields
167
+ // Add or update the ids field
168
+ const idsField = this.getFieldIdentifierNode(
169
+ idsFieldName,
170
+ source
171
+ )?.parent as PropertyDeclaration;
172
+ if (idsField == null) {
173
+ return this.addAdditionalIdsField();
174
+ }
175
+ else {
176
+ //Update the ids field
177
+ const fieldType = ts.factory.createArrayTypeNode(ts.factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword));
178
+ const decoratorManagers = [
179
+ new OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
180
+ new ArrayDecoratorManager({ isArray: true, source: source, field: field })
181
+ ];
182
+ return this.updateFieldInternal(idsFieldName, fieldType, decoratorManagers, field, source);
183
+ }
184
+
185
+ }
186
+
187
+ updateAdditionalCommandField(): FieldChange {
188
+ const commandFieldName = `${this.field.name}Command`
189
+ const source = this.source
190
+ const field = this.field
191
+
192
+ // Handle the main source additional fields
193
+ // Add or update the command field
194
+ const commandField = this.getFieldIdentifierNode(
195
+ commandFieldName,
196
+ source
197
+ )?.parent as PropertyDeclaration;
198
+ if (commandField == null) {
199
+ return this.addAdditionalCommandField();
200
+ }
201
+ else {
202
+ //Update the command field
203
+ const fieldType = ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword);
204
+ const decoratorManagers = [
205
+ new StringDecoratorManager({ isString: true, source: source, field: field }),
206
+ new OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
207
+ // TODO pending @IsEnum(RelationFieldsCommand)
208
+ ];
209
+ return this.updateFieldInternal(commandFieldName, fieldType, decoratorManagers, field, source);
210
+ }
211
+ }
212
+
213
+
214
+ override removeAdditionalField(): FieldChange[] {
215
+ const fieldChanges: FieldChange[] = [];
216
+
217
+ // Add the ids field to the main entity
218
+ fieldChanges.push(this.removeAdditionalIdsField());
219
+ // Add the command field to the main entity
220
+ fieldChanges.push(this.removeAdditionalCommandField());
221
+
222
+ return fieldChanges;
223
+ }
224
+
225
+ removeAdditionalIdsField(): FieldChange {
226
+ const fieldName = `${this.field.name}Ids`;
227
+ const source = this.source;
228
+ return this.removeFieldFor(fieldName, source);
229
+ }
230
+ removeAdditionalCommandField(): FieldChange {
231
+ const fieldName = `${this.field.name}Command`;
232
+ const source = this.source;
233
+ return this.removeFieldFor(fieldName, source);
234
+ }
235
+
236
+ protected isAdditionalFieldRequired(): boolean {
237
+ return true;
238
+ }
239
+
240
+ relatedFieldImport(): Change {
241
+ const relatedEntityImportName = `update-${dasherize(this.field.relationModelSingularName)}.dto`;
242
+ const relatedEntityPath = this.field.relationModelModuleName ? `src/${this.field.relationModelModuleName}/dtos/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
243
+ return safeInsertImport(this.source, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath, this.moduleName);
244
+ // return insertImport(this.source, this.source.fileName, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
245
+ } //Uncomment this method while implementing many-to-many relation changes
246
+
247
+ }
@@ -0,0 +1,51 @@
1
+ import { classify, dasherize } from '@angular-devkit/core/src/utils/strings';
2
+ import ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
3
+ import { Change } from '@schematics/angular/utility/change';
4
+ import { FieldChange, FieldManager, FieldType, safeInsertImport } from '../../FieldManager';
5
+ import {
6
+ BaseFieldManagerForEntity,
7
+ } from '../base/BaseFieldManagerForEntity';
8
+
9
+ export class OneToManyRelationFieldManagerForEntity
10
+ extends BaseFieldManagerForEntity
11
+ implements FieldManager {
12
+
13
+ override addField(): FieldChange[] {
14
+ const fieldChanges = super.addField();
15
+ if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
16
+ const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
17
+ mainField.changes.push(this.relatedFieldImport());
18
+ }
19
+ return fieldChanges
20
+ }
21
+
22
+ override updateField(): FieldChange[] {
23
+ const fieldChanges = super.updateField();
24
+ if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
25
+ const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
26
+ mainField.changes.push(this.relatedFieldImport());
27
+ }
28
+ return fieldChanges
29
+ }
30
+
31
+ relatedFieldImport(): Change {
32
+ const relatedEntityImportName = `${dasherize(this.field.relationModelSingularName)}.entity`;
33
+ const relatedEntityPath = this.field.relationModelModuleName ? `src/${dasherize(this.field.relationModelModuleName)}/entities/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
34
+ return safeInsertImport(this.source, classify(this.field.relationModelSingularName), relatedEntityPath, this.moduleName);
35
+ }
36
+
37
+
38
+ fieldType(): FieldType { // The inverse field type will remain the same for both one-to-many and many-to-many relations
39
+ const type = `${classify(this.field.relationModelSingularName)}`
40
+ const text = `${type}[]`
41
+ return {
42
+ text: text,
43
+ node: (_field: any) =>
44
+ ts.factory.createArrayTypeNode(ts.factory.createTypeReferenceNode(
45
+ ts.factory.createIdentifier(type),
46
+ undefined
47
+ )),
48
+ };
49
+ }
50
+
51
+ }