@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.
Files changed (91) 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/package.json +5 -2
  5. package/publish.js +16 -0
  6. package/src/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.ts +71 -2
  7. package/dto_additional_fields_duplicate_fix.diff +0 -40
  8. package/src/code-builder/index.js +0 -178
  9. package/src/code-builder/index_spec.js +0 -46
  10. package/src/code-builder/lib/field/FieldManager.js +0 -236
  11. package/src/code-builder/lib/field/decorator-managers/dto/ArrayDecoratorManager.js +0 -107
  12. package/src/code-builder/lib/field/decorator-managers/dto/BigIntDecoratorManager.js +0 -100
  13. package/src/code-builder/lib/field/decorator-managers/dto/BooleanDecoratorManager.js +0 -102
  14. package/src/code-builder/lib/field/decorator-managers/dto/DateDecoratorManager.js +0 -106
  15. package/src/code-builder/lib/field/decorator-managers/dto/DecimalDecoratorManager.js +0 -112
  16. package/src/code-builder/lib/field/decorator-managers/dto/EmailDecoratorManager.js +0 -99
  17. package/src/code-builder/lib/field/decorator-managers/dto/IntDecoratorManager.js +0 -100
  18. package/src/code-builder/lib/field/decorator-managers/dto/JsonDecoratorManager.js +0 -100
  19. package/src/code-builder/lib/field/decorator-managers/dto/LengthDecoratorManager.js +0 -104
  20. package/src/code-builder/lib/field/decorator-managers/dto/MaxDecoratorManager.js +0 -103
  21. package/src/code-builder/lib/field/decorator-managers/dto/MaxLengthDecoratorManager.js +0 -103
  22. package/src/code-builder/lib/field/decorator-managers/dto/MinDecoratorManager.js +0 -102
  23. package/src/code-builder/lib/field/decorator-managers/dto/MinLengthDecoratorManager.js +0 -103
  24. package/src/code-builder/lib/field/decorator-managers/dto/NumberDecoratorManager.js +0 -112
  25. package/src/code-builder/lib/field/decorator-managers/dto/OptionalDecoratorManager.js +0 -104
  26. package/src/code-builder/lib/field/decorator-managers/dto/RegexDecoratorManager.js +0 -102
  27. package/src/code-builder/lib/field/decorator-managers/dto/RequiredDecoratorManager.js +0 -100
  28. package/src/code-builder/lib/field/decorator-managers/dto/StringDecoratorManager.js +0 -99
  29. package/src/code-builder/lib/field/decorator-managers/dto/TransformDecoratorManager.js +0 -102
  30. package/src/code-builder/lib/field/decorator-managers/dto/ValidateNestedDecoratorManager.js +0 -140
  31. package/src/code-builder/lib/field/decorator-managers/entity/ColumnDecoratorManager.js +0 -178
  32. package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +0 -79
  33. package/src/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js +0 -118
  34. package/src/code-builder/lib/field/decorator-managers/entity/ManyToManyDecoratorManager.js +0 -175
  35. package/src/code-builder/lib/field/decorator-managers/entity/ManyToOneDecoratorManager.js +0 -179
  36. package/src/code-builder/lib/field/decorator-managers/entity/OneToManyDecoratorManager.js +0 -155
  37. package/src/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js +0 -174
  38. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +0 -345
  39. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +0 -373
  40. package/src/code-builder/lib/field/field-managers/base/DeleteType.js +0 -11
  41. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldHandler.js +0 -33
  42. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForDto.js +0 -81
  43. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForEntity.js +0 -55
  44. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldHandler.js +0 -33
  45. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForDto.js +0 -75
  46. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForEntity.js +0 -51
  47. package/src/code-builder/lib/field/field-managers/computed/ComputedFieldHandler.js +0 -30
  48. package/src/code-builder/lib/field/field-managers/computed/ComputedFieldManagerForEntity.js +0 -33
  49. package/src/code-builder/lib/field/field-managers/date/DateFieldHandler.js +0 -33
  50. package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForDto.js +0 -81
  51. package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForEntity.js +0 -59
  52. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldHandler.js +0 -33
  53. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForDto.js +0 -77
  54. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForEntity.js +0 -53
  55. package/src/code-builder/lib/field/field-managers/email/EmailFieldHandler.js +0 -34
  56. package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForDto.js +0 -72
  57. package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForEntity.js +0 -44
  58. package/src/code-builder/lib/field/field-managers/int/IntFieldHandler.js +0 -33
  59. package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForDto.js +0 -76
  60. package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForEntity.js +0 -52
  61. package/src/code-builder/lib/field/field-managers/json/JsonFieldHandler.js +0 -34
  62. package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForDto.js +0 -57
  63. package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForEntity.js +0 -21
  64. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldHandler.js +0 -34
  65. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForDto.js +0 -63
  66. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForEntity.js +0 -34
  67. package/src/code-builder/lib/field/field-managers/media/MediaFieldHandler.js +0 -33
  68. package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForDto.js +0 -72
  69. package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForEntity.js +0 -57
  70. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldHandler.js +0 -27
  71. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForDto.js +0 -75
  72. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForEntity.js +0 -35
  73. package/src/code-builder/lib/field/field-managers/password/PasswordFieldHandler.js +0 -34
  74. package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForDto.js +0 -121
  75. package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForEntity.js +0 -37
  76. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldHandler.js +0 -33
  77. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +0 -366
  78. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -158
  79. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldHandler.js +0 -33
  80. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +0 -294
  81. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +0 -177
  82. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldHandler.js +0 -34
  83. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForDto.js +0 -63
  84. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForEntity.js +0 -34
  85. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldHandler.js +0 -34
  86. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForDto.js +0 -63
  87. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForEntity.js +0 -37
  88. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldHandler.js +0 -34
  89. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForDto.js +0 -15
  90. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForEntity.js +0 -33
  91. package/src/code-builder/lib/model/helpers.js +0 -407
@@ -1,158 +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.ManyToManyRelationFieldManagerForEntity = 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 ManyToManyDecoratorManager_1 = require("../../decorator-managers/entity/ManyToManyDecoratorManager");
11
- const FieldManager_1 = require("../../FieldManager");
12
- const BaseFieldManagerForEntity_1 = require("../base/BaseFieldManagerForEntity");
13
- class ManyToManyRelationFieldManagerForEntity extends BaseFieldManagerForEntity_1.BaseFieldManagerForEntity {
14
- constructor(tree, moduleName, modelName, field) {
15
- super(tree, moduleName, modelName, field);
16
- if (this.isAdditionalFieldRequired()) {
17
- const relatedEntityFileName = `${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.entity.ts`;
18
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/entities/${relatedEntityFileName}` : `src/${(0, strings_1.dasherize)(moduleName)}/entities/${relatedEntityFileName}`;
19
- this.relationInverseSource = (0, FieldManager_1.createSourceFile)(//TODO "src/iam/dtos/create-user.dto.ts" does not exist. If an entity is used in a many-to-one relation, the create-entity.dto.ts file should be exist.
20
- tree, relatedEntityPath);
21
- this.inverseManyToManyDecoratorManager = new ManyToManyDecoratorManager_1.ManyToManyDecoratorManager({
22
- isManyToMany: this.isInverseManyToMany(),
23
- relationModelName: this.modelName,
24
- relationInverseFieldName: this.fieldName(),
25
- relationCascade: this.field.relationCascade,
26
- owner: false,
27
- source: this.relationInverseSource,
28
- field: this.field,
29
- fieldName: this.fieldName(),
30
- modelName: this.modelName,
31
- });
32
- }
33
- }
34
- fieldName() {
35
- return `${this.field.name}`;
36
- }
37
- fieldType() {
38
- return this.manyToManyFieldType();
39
- }
40
- manyToManyFieldType() {
41
- const type = `${(0, strings_1.classify)(this.field.relationModelSingularName)}`;
42
- const text = `${type}[]`;
43
- return {
44
- text: text,
45
- node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
46
- };
47
- }
48
- addField() {
49
- const fieldChanges = super.addField();
50
- if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
51
- const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
52
- mainField.changes.push(this.relatedFieldImport());
53
- }
54
- return fieldChanges;
55
- }
56
- updateField() {
57
- const fieldChanges = super.updateField();
58
- if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
59
- const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
60
- mainField.changes.push(this.relatedFieldImport());
61
- }
62
- return fieldChanges;
63
- }
64
- relatedFieldImport() {
65
- const relatedEntityImportName = `${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.entity`;
66
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/entities/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
67
- return (0, ast_utils_1.insertImport)(this.source, this.source.fileName, (0, strings_1.classify)(this.field.relationModelSingularName), relatedEntityPath);
68
- }
69
- removeAdditionalField() {
70
- const changes = [];
71
- if (this.isFieldPresent(this.additionalFieldName(), this.relationInverseSource)) {
72
- console.log(`\nEntity removeField ${this.additionalFieldName()} called ...`);
73
- changes.push(...this.removeFieldFor(this.additionalFieldName(), this.relationInverseSource).changes);
74
- }
75
- return {
76
- filePath: this.relationInverseSource.fileName,
77
- field: this.field,
78
- changes: changes,
79
- };
80
- }
81
- isAdditionalFieldRequired() {
82
- return (this.field.type === 'relation' && this.field.relationCreateInverse);
83
- }
84
- addAdditionalField() {
85
- const fieldChanges = [];
86
- if (this.field.relationCreateInverse) {
87
- fieldChanges.push(this.addAdditionalInverseField());
88
- }
89
- return fieldChanges;
90
- }
91
- addAdditionalInverseField() {
92
- const fieldName = this.additionalFieldName();
93
- const fieldType = this.additionalFieldType().text;
94
- const source = this.relationInverseSource;
95
- const field = this.field;
96
- const modelName = this.field.relationModelSingularName;
97
- const decoratorManagers = this.additionalDecoratorManagers();
98
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
99
- if (this.modelName !== this.field.relationModelSingularName) {
100
- const currentModelName = this.modelName;
101
- const currentModuleName = this.moduleName;
102
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
103
- }
104
- return fieldChange;
105
- }
106
- inverseFieldImport(modelName, moduleName, source) {
107
- const inverseEntityImportName = `${(0, strings_1.dasherize)(modelName)}.entity`;
108
- const inverseEntityPath = `src/${moduleName}/entities/${inverseEntityImportName}`;
109
- return (0, FieldManager_1.safeInsertImport)(source, `${(0, strings_1.classify)(modelName)}`, inverseEntityPath);
110
- }
111
- addOrUpdateAdditionalField() {
112
- const fieldChanges = [];
113
- if (this.field.relationCreateInverse) {
114
- fieldChanges.push(this.updateAdditionalInverseField());
115
- }
116
- return fieldChanges;
117
- }
118
- updateAdditionalInverseField() {
119
- var _a;
120
- const fieldName = this.additionalFieldName();
121
- const fieldType = this.additionalFieldType().node(this.field);
122
- const source = this.relationInverseSource;
123
- const field = this.field;
124
- const decoratorManagers = this.additionalDecoratorManagers();
125
- const inverseField = (_a = this.getFieldIdentifierNode(fieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
126
- if (inverseField == null) {
127
- return this.addAdditionalInverseField();
128
- }
129
- else {
130
- const fieldChange = this.updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source);
131
- if (this.modelName !== this.field.relationModelSingularName) {
132
- const currentModelName = this.modelName;
133
- const currentModuleName = this.moduleName;
134
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
135
- }
136
- return fieldChange;
137
- }
138
- }
139
- additionalFieldType() {
140
- const type = `${(0, strings_1.classify)(this.modelName)}`;
141
- const text = `${type}[]`;
142
- return {
143
- text: text,
144
- node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
145
- };
146
- }
147
- additionalFieldName() {
148
- return this.field.relationModelFieldName;
149
- }
150
- additionalDecoratorManagers() {
151
- return [this.inverseManyToManyDecoratorManager];
152
- }
153
- isInverseManyToMany() {
154
- return (this.isManyToMany() && this.field.relationCreateInverse);
155
- }
156
- }
157
- exports.ManyToManyRelationFieldManagerForEntity = ManyToManyRelationFieldManagerForEntity;
158
- //# sourceMappingURL=ManyToManyRelationFieldManagerForEntity.js.map
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ManyToOneRelationFieldHandler = void 0;
4
- const FieldManager_1 = require("../../FieldManager");
5
- const ManyToOneRelationFieldManagerForDto_1 = require("./ManyToOneRelationFieldManagerForDto");
6
- const ManyToOneRelationFieldManagerForEntity_1 = require("./ManyToOneRelationFieldManagerForEntity");
7
- class ManyToOneRelationFieldHandler {
8
- constructor(tree, moduleName, modelName, field) {
9
- this.entityFieldManager = new ManyToOneRelationFieldManagerForEntity_1.ManyToOneRelationFieldManagerForEntity(tree, moduleName, modelName, field);
10
- this.createDtoFieldManager = new ManyToOneRelationFieldManagerForDto_1.ManyToOneRelationFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Create));
11
- this.updateDtoFieldManager = new ManyToOneRelationFieldManagerForDto_1.ManyToOneRelationFieldManagerForDto(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.ManyToOneRelationFieldHandler = ManyToOneRelationFieldHandler;
33
- //# sourceMappingURL=ManyToOneRelationFieldHandler.js.map
@@ -1,294 +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.ManyToOneRelationFieldManagerForDto = 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 ArrayDecoratorManager_1 = require("../../decorator-managers/dto/ArrayDecoratorManager");
10
- const OptionalDecoratorManager_1 = require("../../decorator-managers/dto/OptionalDecoratorManager");
11
- const TransformDecoratorManager_1 = require("../../decorator-managers/dto/TransformDecoratorManager");
12
- const FieldManager_1 = require("../../FieldManager");
13
- const BaseFieldManagerForDto_1 = require("../base/BaseFieldManagerForDto");
14
- const StringDecoratorManager_1 = require("../../decorator-managers/dto/StringDecoratorManager");
15
- class ManyToOneRelationFieldManagerForDto extends BaseFieldManagerForDto_1.BaseFieldManagerForDto {
16
- isJson() {
17
- return false;
18
- }
19
- isBoolean() {
20
- return false;
21
- }
22
- constructor(tree, moduleName, modelName, field, options) {
23
- super(tree, moduleName, modelName, Object.assign(Object.assign({}, field), { required: false }), options);
24
- if (this.field.relationCreateInverse) {
25
- const relatedEntityFileName = (this.options.sourceType === FieldManager_1.DtoSourceType.Create) ? `create-${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.dto.ts` : `update-${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.dto.ts`;
26
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/dtos/${relatedEntityFileName}` : `src/${(0, strings_1.dasherize)(moduleName)}/dtos/${relatedEntityFileName}`;
27
- this.relationInverseSource = (0, FieldManager_1.createSourceFile)(tree, relatedEntityPath);
28
- this.relationInverseDecoratorManagers = this.getFieldDecoratorManagers(this.field, this.relationInverseSource, FieldManager_1.DecoratorType.Array, FieldManager_1.DecoratorType.ValidateNested);
29
- //HACK: This is a hack to add the transform decorator to the inverse field
30
- this.relationInverseDecoratorManagers.push(new TransformDecoratorManager_1.TransformDecoratorManager({ isTransform: true, type: this.transformType(), source: this.relationInverseSource, field: field }));
31
- //HACK: This is a hack to replace the optional decorator to the inverse field
32
- this.relationInverseDecoratorManagers.push(new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: this.relationInverseSource, field: field }));
33
- }
34
- }
35
- isString() {
36
- return false;
37
- }
38
- isNumber() {
39
- return false;
40
- }
41
- isInt() {
42
- return true;
43
- }
44
- isDecimal() {
45
- return false;
46
- }
47
- isApplyRegex() {
48
- return false;
49
- }
50
- isApplyRequired() {
51
- return true;
52
- }
53
- isApplyMin() {
54
- return false;
55
- }
56
- isApplyMax() {
57
- return false;
58
- }
59
- isDate() {
60
- return false;
61
- }
62
- isTransform() {
63
- return false;
64
- }
65
- fieldType() {
66
- return this.manyToOneFieldType();
67
- }
68
- manyToOneFieldType() {
69
- return {
70
- text: 'number',
71
- node: (_field) => typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword),
72
- };
73
- }
74
- // This field type is used in the case of one-to-many relation, when we generate the inverse field in the related entity
75
- additionalFieldType() {
76
- const type = this.transformType(); //TODO Discuss if this needs to be Create Or Update DTO
77
- const text = `${type}[]`;
78
- return {
79
- text: text,
80
- node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
81
- };
82
- }
83
- transformType() {
84
- return `Update${(0, strings_1.classify)(this.modelName)}Dto`;
85
- }
86
- addAdditionalField() {
87
- const fieldChanges = [];
88
- // Add the userKey field to the main entity
89
- fieldChanges.push(this.addAdditionalUserKeyField());
90
- if (this.field.relationCreateInverse) {
91
- fieldChanges.push(this.addAdditionalInverseField());
92
- fieldChanges.push(this.addAdditionalInverseIdsField());
93
- fieldChanges.push(this.addAdditionalInverseCommandsField());
94
- }
95
- return fieldChanges;
96
- }
97
- addAdditionalUserKeyField() {
98
- const fieldName = `${this.field.name}UserKey`;
99
- const fieldType = "string";
100
- const source = this.source;
101
- const field = this.field;
102
- const modelName = this.modelName;
103
- const decoratorManagers = [
104
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
105
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
106
- ];
107
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
108
- return fieldChange;
109
- }
110
- addAdditionalInverseCommandsField() {
111
- var _a;
112
- const fieldName = `${(_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : this.modelName}Command`;
113
- const fieldType = "string";
114
- const source = this.relationInverseSource;
115
- const field = this.field;
116
- const modelName = this.field.relationModelSingularName;
117
- const decoratorManagers = [
118
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
119
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
120
- // TODO pending @IsEnum(RelationFieldsCommand)
121
- ];
122
- //console.log(`\ncreate Dto addAdditionalInverseCommandsField ${fieldName} called ...`);
123
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
124
- return fieldChange;
125
- }
126
- addAdditionalInverseIdsField() {
127
- var _a;
128
- const fieldName = `${(_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : this.modelName}Ids`;
129
- const fieldType = "number[]";
130
- const source = this.relationInverseSource;
131
- const field = this.field;
132
- const modelName = this.field.relationModelSingularName;
133
- const decoratorManagers = [
134
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
135
- new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
136
- ];
137
- //console.log(`\ncreate Dto addAdditionalInverseIdsField ${fieldName} called ...`);
138
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
139
- return fieldChange;
140
- }
141
- addAdditionalInverseField() {
142
- const fieldName = this.additionalFieldName();
143
- const fieldType = this.additionalFieldType().text;
144
- const source = this.relationInverseSource;
145
- const field = this.field;
146
- const modelName = this.field.relationModelSingularName;
147
- const decoratorManagers = this.relationInverseDecoratorManagers;
148
- //console.log(`\ncreate Dto addAdditionalInverseField ${fieldName} called ...`);
149
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
150
- if (this.modelName !== this.field.relationModelSingularName) {
151
- const currentModelName = this.modelName;
152
- const currentModuleName = this.moduleName;
153
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
154
- }
155
- return fieldChange;
156
- }
157
- addOrUpdateAdditionalField() {
158
- const fieldChanges = [];
159
- // Add the userKey field to the main entity
160
- fieldChanges.push(this.updateAdditionalUserKeyField());
161
- if (this.field.relationCreateInverse) {
162
- fieldChanges.push(this.updateAdditionalInverseField());
163
- fieldChanges.push(this.updateAdditionalInverseIdsField());
164
- fieldChanges.push(this.updateAdditionalInverseCommandsField());
165
- }
166
- return fieldChanges;
167
- }
168
- updateAdditionalUserKeyField() {
169
- var _a;
170
- const userKeyFieldName = `${this.field.name}UserKey`;
171
- const userKeyFieldType = typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
172
- const source = this.source;
173
- const field = this.field;
174
- const decoratorManagers = [
175
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
176
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
177
- // TODO pending @IsEnum(RelationFieldsCommand)
178
- ];
179
- const userKeyField = (_a = this.getFieldIdentifierNode(userKeyFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
180
- //console.log(`\ncreate Dto updateAdditionalInverseCommandsField ${userKeyFieldName} called ...`);
181
- if (userKeyField == null) {
182
- return this.addAdditionalUserKeyField();
183
- }
184
- else {
185
- //Update the command field
186
- return this.updateFieldInternal(userKeyFieldName, userKeyFieldType, decoratorManagers, field, source);
187
- }
188
- }
189
- updateAdditionalInverseCommandsField() {
190
- var _a, _b;
191
- const commandFieldName = `${(_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : this.modelName}Command`;
192
- const commandFieldType = typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
193
- const source = this.relationInverseSource;
194
- const field = this.field;
195
- const decoratorManagers = [
196
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
197
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
198
- // TODO pending @IsEnum(RelationFieldsCommand)
199
- ];
200
- const commandField = (_b = this.getFieldIdentifierNode(commandFieldName, source)) === null || _b === void 0 ? void 0 : _b.parent;
201
- //console.log(`\ncreate Dto updateAdditionalInverseCommandsField ${commandFieldName} called ...`);
202
- if (commandField == null) {
203
- return this.addAdditionalInverseCommandsField();
204
- }
205
- else {
206
- //Update the command field
207
- return this.updateFieldInternal(commandFieldName, commandFieldType, decoratorManagers, field, source);
208
- }
209
- }
210
- updateAdditionalInverseIdsField() {
211
- var _a, _b;
212
- const idsFieldName = `${(_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : this.modelName}Ids`;
213
- const idsFieldType = typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword));
214
- const source = this.relationInverseSource;
215
- const field = this.field;
216
- const decoratorManagers = [
217
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
218
- new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
219
- ];
220
- const idsField = (_b = this.getFieldIdentifierNode(idsFieldName, source)) === null || _b === void 0 ? void 0 : _b.parent;
221
- //console.log(`\ncreate Dto updateAdditionalInverseIdsField ${idsFieldName} called ...`);
222
- if (idsField == null) {
223
- return this.addAdditionalInverseIdsField();
224
- }
225
- else {
226
- //Update the ids field
227
- return this.updateFieldInternal(idsFieldName, idsFieldType, decoratorManagers, field, source);
228
- }
229
- }
230
- updateAdditionalInverseField() {
231
- var _a;
232
- const fieldName = this.additionalFieldName();
233
- const fieldType = this.additionalFieldType().node(this.field);
234
- const source = this.relationInverseSource;
235
- const field = this.field;
236
- const decoratorManagers = this.relationInverseDecoratorManagers;
237
- const inverseField = (_a = this.getFieldIdentifierNode(fieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
238
- if (inverseField == null) {
239
- return this.addAdditionalInverseField();
240
- }
241
- else {
242
- const fieldChange = this.updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source);
243
- if (this.modelName !== this.field.relationModelSingularName) {
244
- const currentModelName = this.modelName;
245
- const currentModuleName = this.moduleName;
246
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
247
- }
248
- return fieldChange;
249
- }
250
- }
251
- inverseFieldImport(modelName, moduleName, source) {
252
- const inverseEntityImportName = `update-${(0, strings_1.dasherize)(modelName)}.dto`;
253
- const inverseEntityPath = `src/${moduleName}/dtos/${inverseEntityImportName}`;
254
- return (0, FieldManager_1.safeInsertImport)(source, `Update${(0, strings_1.classify)(modelName)}Dto`, inverseEntityPath);
255
- }
256
- removeAdditionalField() {
257
- const fieldChanges = [];
258
- if (this.field.relationCreateInverse) {
259
- fieldChanges.push(this.removeAdditionalInverseField());
260
- fieldChanges.push(this.removeAdditionalInverseIdsField());
261
- fieldChanges.push(this.removeAdditionalInverseCommandsField());
262
- }
263
- return fieldChanges;
264
- }
265
- removeAdditionalInverseField() {
266
- const fieldName = this.additionalFieldName();
267
- const source = this.relationInverseSource;
268
- return this.removeFieldFor(fieldName, source);
269
- }
270
- removeAdditionalInverseIdsField() {
271
- var _a;
272
- const fieldName = `${(_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : this.modelName}Ids`;
273
- const source = this.relationInverseSource;
274
- return this.removeFieldFor(fieldName, source);
275
- }
276
- removeAdditionalInverseCommandsField() {
277
- var _a;
278
- const fieldName = `${(_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : this.modelName}Command`;
279
- const source = this.relationInverseSource;
280
- return this.removeFieldFor(fieldName, source);
281
- }
282
- fieldName() {
283
- return `${this.field.name}Id`;
284
- }
285
- additionalFieldName() {
286
- var _a;
287
- return (_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : `${this.modelName}s`;
288
- }
289
- isAdditionalFieldRequired() {
290
- return true;
291
- }
292
- }
293
- exports.ManyToOneRelationFieldManagerForDto = ManyToOneRelationFieldManagerForDto;
294
- //# sourceMappingURL=ManyToOneRelationFieldManagerForDto.js.map
@@ -1,177 +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.ManyToOneRelationFieldManagerForEntity = 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 OneToManyDecoratorManager_1 = require("../../decorator-managers/entity/OneToManyDecoratorManager");
11
- const FieldManager_1 = require("../../FieldManager");
12
- const BaseFieldManagerForEntity_1 = require("../base/BaseFieldManagerForEntity");
13
- class ManyToOneRelationFieldManagerForEntity extends BaseFieldManagerForEntity_1.BaseFieldManagerForEntity {
14
- constructor(tree, moduleName, modelName, field) {
15
- super(tree, moduleName, modelName, field);
16
- if (this.isAdditionalFieldRequired()) {
17
- const relatedEntityFileName = `${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.entity.ts`;
18
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/entities/${relatedEntityFileName}` : `src/${(0, strings_1.dasherize)(moduleName)}/entities/${relatedEntityFileName}`;
19
- this.relationInverseSource = (0, FieldManager_1.createSourceFile)(//TODO "src/iam/dtos/create-user.dto.ts" does not exist. If an entity is used in a many-to-one relation, the create-entity.dto.ts file should be exist.
20
- tree, relatedEntityPath);
21
- // this.relationInverseSource = createSourceFile(tree, `src/${dasherize(this.field.relationModelSingularName)}/entities/${dasherize(this.field.relationModelSingularName)}.entity.ts`)
22
- this.oneToManyDecoratorManager = new OneToManyDecoratorManager_1.OneToManyDecoratorManager({
23
- isOneToMany: this.isOneToMany(),
24
- relationCascade: this.field.relationCascade,
25
- source: this.relationInverseSource,
26
- field: this.field,
27
- fieldName: this.fieldName(),
28
- modelName: this.modelName,
29
- });
30
- }
31
- }
32
- fieldName() {
33
- switch (this.field.relationType) {
34
- case FieldManager_1.RelationType.ManyToOne:
35
- return super.fieldName();
36
- case FieldManager_1.RelationType.ManyToMany:
37
- return `${this.field.name}s`;
38
- default:
39
- throw new Error(`Unsupported relation type: ${this.field.relationType}`);
40
- }
41
- }
42
- fieldType() {
43
- switch (this.field.relationType) {
44
- case FieldManager_1.RelationType.ManyToOne:
45
- return this.manyToOneFieldType();
46
- case FieldManager_1.RelationType.ManyToMany:
47
- return this.manyToManyFieldType();
48
- default:
49
- throw new Error(`Unsupported relation type: ${this.field.relationType}`);
50
- }
51
- }
52
- manyToOneFieldType() {
53
- return {
54
- text: (0, strings_1.classify)(this.field.relationModelSingularName),
55
- node: (field) => typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier((0, strings_1.classify)(field.relationModelSingularName)), undefined),
56
- };
57
- }
58
- manyToManyFieldType() {
59
- const type = `${(0, strings_1.classify)(this.field.relationModelSingularName)}`;
60
- const text = `${type}[]`;
61
- return {
62
- text: text,
63
- node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
64
- };
65
- }
66
- addField() {
67
- const fieldChanges = super.addField();
68
- if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
69
- const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
70
- mainField.changes.push(this.relatedFieldImport());
71
- }
72
- return fieldChanges;
73
- }
74
- updateField() {
75
- const fieldChanges = super.updateField();
76
- if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
77
- const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
78
- mainField.changes.push(this.relatedFieldImport());
79
- }
80
- return fieldChanges;
81
- }
82
- relatedFieldImport() {
83
- const relatedEntityImportName = `${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.entity`;
84
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/entities/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
85
- return (0, ast_utils_1.insertImport)(this.source, this.source.fileName, (0, strings_1.classify)(this.field.relationModelSingularName), relatedEntityPath);
86
- }
87
- isOneToMany() {
88
- return (this.field.type === 'relation' && this.field.relationType === FieldManager_1.RelationType.ManyToOne && this.field.relationCreateInverse);
89
- }
90
- removeAdditionalField() {
91
- const changes = [];
92
- if (this.isFieldPresent(this.additionalFieldName(), this.relationInverseSource)) {
93
- console.log(`\nEntity removeField ${this.additionalFieldName()} called ...`);
94
- changes.push(...this.removeFieldFor(this.additionalFieldName(), this.relationInverseSource).changes);
95
- }
96
- return {
97
- filePath: this.relationInverseSource.fileName,
98
- field: this.field,
99
- changes: changes,
100
- };
101
- }
102
- isAdditionalFieldRequired() {
103
- return (this.field.type === 'relation' && this.field.relationCreateInverse);
104
- }
105
- addAdditionalField() {
106
- const fieldChanges = [];
107
- if (this.field.relationCreateInverse) {
108
- fieldChanges.push(this.addAdditionalInverseField());
109
- }
110
- return fieldChanges;
111
- }
112
- addAdditionalInverseField() {
113
- const fieldName = this.additionalFieldName();
114
- const fieldType = this.additionalFieldType().text;
115
- const source = this.relationInverseSource;
116
- const field = this.field;
117
- const modelName = this.field.relationModelSingularName;
118
- const decoratorManagers = this.additionalDecoratorManagers();
119
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
120
- if (this.modelName !== this.field.relationModelSingularName) {
121
- const currentModelName = this.modelName;
122
- const currentModuleName = this.moduleName;
123
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
124
- }
125
- return fieldChange;
126
- }
127
- inverseFieldImport(modelName, moduleName, source) {
128
- const inverseEntityImportName = `${(0, strings_1.dasherize)(modelName)}.entity`;
129
- const inverseEntityPath = `src/${moduleName}/entities/${inverseEntityImportName}`;
130
- return (0, FieldManager_1.safeInsertImport)(source, (0, strings_1.classify)(modelName), inverseEntityPath);
131
- }
132
- addOrUpdateAdditionalField() {
133
- const fieldChanges = [];
134
- if (this.field.relationCreateInverse) {
135
- fieldChanges.push(this.updateAdditionalInverseField());
136
- }
137
- return fieldChanges;
138
- }
139
- updateAdditionalInverseField() {
140
- var _a;
141
- const fieldName = this.additionalFieldName();
142
- const fieldType = this.additionalFieldType().node(this.field);
143
- const source = this.relationInverseSource;
144
- const field = this.field;
145
- const decoratorManagers = this.additionalDecoratorManagers();
146
- const inverseField = (_a = this.getFieldIdentifierNode(fieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
147
- if (inverseField == null) {
148
- return this.addAdditionalInverseField();
149
- }
150
- else {
151
- const fieldChange = this.updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source);
152
- if (this.modelName !== this.field.relationModelSingularName) {
153
- const currentModelName = this.modelName;
154
- const currentModuleName = this.moduleName;
155
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
156
- }
157
- return fieldChange;
158
- }
159
- }
160
- additionalFieldName() {
161
- var _a;
162
- return (_a = this.field.relationModelFieldName) !== null && _a !== void 0 ? _a : `${this.modelName}s`;
163
- }
164
- additionalFieldType() {
165
- const type = `${(0, strings_1.classify)(this.modelName)}`;
166
- const text = `${type}[]`;
167
- return {
168
- text: text,
169
- node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
170
- };
171
- }
172
- additionalDecoratorManagers() {
173
- return [this.oneToManyDecoratorManager];
174
- }
175
- }
176
- exports.ManyToOneRelationFieldManagerForEntity = ManyToOneRelationFieldManagerForEntity;
177
- //# sourceMappingURL=ManyToOneRelationFieldManagerForEntity.js.map