@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,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PasswordFieldHandler = void 0;
4
- const FieldManager_1 = require("../../FieldManager");
5
- const PasswordFieldManagerForDto_1 = require("./PasswordFieldManagerForDto");
6
- const PasswordFieldManagerForEntity_1 = require("./PasswordFieldManagerForEntity");
7
- class PasswordFieldHandler {
8
- constructor(tree, moduleName, modelName, field) {
9
- this.entityFieldManager = new PasswordFieldManagerForEntity_1.PasswordFieldManagerForEntity(tree, moduleName, modelName, field);
10
- this.createDtoFieldManager = new PasswordFieldManagerForDto_1.PasswordFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Create));
11
- this.updateDtoFieldManager = new PasswordFieldManagerForDto_1.PasswordFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Update));
12
- //Instantiate the entity and dto source files
13
- }
14
- updateEntityField() {
15
- return this.entityFieldManager.updateField();
16
- }
17
- updateDtoField() {
18
- return [...this.createDtoFieldManager.updateField(), ...this.updateDtoFieldManager.updateField()];
19
- }
20
- removeEntityField() {
21
- return this.entityFieldManager.removeField();
22
- }
23
- removeDtoField() {
24
- return [...this.createDtoFieldManager.removeField(), ...this.updateDtoFieldManager.removeField()];
25
- }
26
- addEntityField() {
27
- return this.entityFieldManager.addField();
28
- }
29
- addDtoField() {
30
- return [...this.createDtoFieldManager.addField(), ...this.updateDtoFieldManager.addField()];
31
- }
32
- }
33
- exports.PasswordFieldHandler = PasswordFieldHandler;
34
- //# sourceMappingURL=PasswordFieldHandler.js.map
@@ -1,121 +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.PasswordFieldManagerForDto = 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 PasswordFieldManagerForDto extends BaseFieldManagerForDto_1.BaseFieldManagerForDto {
10
- isJson() {
11
- return false;
12
- }
13
- isBoolean() {
14
- return false;
15
- }
16
- constructor(tree, moduleName, modelName, field, options) {
17
- var _a;
18
- super(tree, moduleName, modelName, Object.assign(Object.assign({}, field), { regexPattern: (_a = field.regexPattern) !== null && _a !== void 0 ? _a : String.raw `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).*$` }), options);
19
- }
20
- isString() {
21
- return true;
22
- }
23
- isNumber() {
24
- return false;
25
- }
26
- isInt() {
27
- return false;
28
- }
29
- isDecimal() {
30
- return false;
31
- }
32
- isApplyMinLength() {
33
- return true;
34
- }
35
- isApplyMaxLength() {
36
- return true;
37
- }
38
- isApplyRegex() {
39
- return true; //TEMPORARY FIX
40
- }
41
- isApplyRequired() {
42
- return true;
43
- }
44
- isApplyMin() {
45
- return false; //FIXME : override the min implementation for short text
46
- }
47
- isApplyMax() {
48
- return false; //FIXME : override the max implementation for short text
49
- }
50
- isDate() {
51
- return false;
52
- }
53
- isTransform() {
54
- return false;
55
- }
56
- addAdditionalField() {
57
- const fieldChanges = [];
58
- // Add the confirm field to the main entity
59
- fieldChanges.push(this.addAdditionalConfirmField());
60
- return fieldChanges;
61
- }
62
- addAdditionalConfirmField() {
63
- const fieldName = this.additionalFieldName();
64
- const fieldType = this.fieldType().text;
65
- const decoratorManagers = this.decoratorManagers;
66
- const source = this.source;
67
- const field = this.field;
68
- const modelName = this.modelName;
69
- return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
70
- }
71
- addOrUpdateAdditionalField() {
72
- const fieldChanges = [];
73
- // Add or update the ids field
74
- fieldChanges.push(this.updateAdditionalConfirmField());
75
- return fieldChanges;
76
- }
77
- updateAdditionalConfirmField() {
78
- var _a;
79
- const fieldName = this.additionalFieldName();
80
- const source = this.source;
81
- // Handle the main source additional fields
82
- // Add or update the confirm field
83
- const confirmField = (_a = this.getFieldIdentifierNode(fieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
84
- if (confirmField == null) {
85
- return this.addAdditionalConfirmField();
86
- }
87
- else {
88
- //Update the confirm field
89
- const fieldType = this.fieldType().node(this.field);
90
- const decoratorManagers = this.decoratorManagers;
91
- const field = this.field;
92
- return this.updateFieldInternal(fieldName, fieldType, decoratorManagers, field, source);
93
- }
94
- }
95
- isAdditionalFieldRequired() {
96
- return true;
97
- }
98
- additionalFieldName() {
99
- return `${this.field.name}Confirm`;
100
- }
101
- fieldType() {
102
- return {
103
- text: 'string',
104
- node: (_field) => typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword),
105
- };
106
- }
107
- removeAdditionalField() {
108
- const changes = [];
109
- if (this.isFieldPresent(this.additionalFieldName(), this.source)) {
110
- console.log(`\ncreate Dto removeField ${this.additionalFieldName()} called ...`);
111
- changes.push(...this.removeFieldFor(this.additionalFieldName(), this.source).changes);
112
- }
113
- return [{
114
- filePath: this.source.fileName,
115
- field: this.field,
116
- changes: changes,
117
- }];
118
- }
119
- }
120
- exports.PasswordFieldManagerForDto = PasswordFieldManagerForDto;
121
- //# sourceMappingURL=PasswordFieldManagerForDto.js.map
@@ -1,37 +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.PasswordFieldManagerForEntity = 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 PasswordFieldManagerForEntity extends BaseFieldManagerForEntity_1.BaseFieldManagerForEntity {
10
- constructor(tree, moduleName, modelName, field) {
11
- super(tree, moduleName, modelName, field);
12
- }
13
- fieldType() {
14
- return {
15
- text: 'string',
16
- node: (_field) => typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword),
17
- };
18
- }
19
- additionalColumnDecoratorOptions() {
20
- var _a, _b;
21
- const additionalOptions = new Map();
22
- if (this.field.max) {
23
- additionalOptions.set('length', this.field.max);
24
- }
25
- additionalOptions.set('default', (_b = (_a = this.defaultValueInitializer(this.field.defaultValue)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null);
26
- return additionalOptions;
27
- }
28
- additionalColumnDecoratorOptionExpressions() {
29
- var _a, _b;
30
- const additionalOptions = new Map();
31
- (this.field.max) ? additionalOptions.set('length', typescript_1.default.factory.createNumericLiteral(this.field.max)) : additionalOptions.set('length', null);
32
- additionalOptions.set('default', (_b = (_a = this.defaultValueInitializer(this.field.defaultValue)) === null || _a === void 0 ? void 0 : _a.expression) !== null && _b !== void 0 ? _b : null);
33
- return additionalOptions;
34
- }
35
- }
36
- exports.PasswordFieldManagerForEntity = PasswordFieldManagerForEntity;
37
- //# sourceMappingURL=PasswordFieldManagerForEntity.js.map
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ManyToManyRelationFieldHandler = void 0;
4
- const FieldManager_1 = require("../../FieldManager");
5
- const ManyToManyRelationFieldManagerForDto_1 = require("./ManyToManyRelationFieldManagerForDto");
6
- const ManyToManyRelationFieldManagerForEntity_1 = require("./ManyToManyRelationFieldManagerForEntity");
7
- class ManyToManyRelationFieldHandler {
8
- constructor(tree, moduleName, modelName, field) {
9
- this.entityFieldManager = new ManyToManyRelationFieldManagerForEntity_1.ManyToManyRelationFieldManagerForEntity(tree, moduleName, modelName, field);
10
- this.createDtoFieldManager = new ManyToManyRelationFieldManagerForDto_1.ManyToManyRelationFieldManagerForDto(tree, moduleName, modelName, field, new FieldManager_1.ManagerForDtoOptions(FieldManager_1.DtoSourceType.Create));
11
- this.updateDtoFieldManager = new ManyToManyRelationFieldManagerForDto_1.ManyToManyRelationFieldManagerForDto(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.ManyToManyRelationFieldHandler = ManyToManyRelationFieldHandler;
33
- //# sourceMappingURL=ManyToManyRelationFieldHandler.js.map
@@ -1,366 +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.ManyToManyRelationFieldManagerForDto = 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 ManyToManyRelationFieldManagerForDto 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
- this.decoratorManagers = [...this.decoratorManagers, ...this.getFieldDecoratorManagers(this.field, this.source, FieldManager_1.DecoratorType.Array, FieldManager_1.DecoratorType.ValidateNested)];
25
- this.decoratorManagers.push(new TransformDecoratorManager_1.TransformDecoratorManager({ isTransform: true, type: this.transformType(this.field.relationModelSingularName), source: this.source, field: field }));
26
- // TODO : inverse source file logic is required, but needs to be handled in a better way
27
- if (this.field.relationCreateInverse) {
28
- 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`;
29
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/dtos/${relatedEntityFileName}` : `src/${(0, strings_1.dasherize)(moduleName)}/dtos/${relatedEntityFileName}`;
30
- this.relationInverseSource = (0, FieldManager_1.createSourceFile)(tree, relatedEntityPath);
31
- this.relationInverseDecoratorManagers = this.getFieldDecoratorManagers(this.field, this.relationInverseSource, FieldManager_1.DecoratorType.Array, FieldManager_1.DecoratorType.ValidateNested);
32
- this.relationInverseDecoratorManagers.push(new TransformDecoratorManager_1.TransformDecoratorManager({ isTransform: true, type: this.transformType(this.modelName), source: this.relationInverseSource, field: field }));
33
- this.relationInverseDecoratorManagers.push(new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: this.relationInverseSource, field: field }));
34
- }
35
- }
36
- isString() {
37
- return false;
38
- }
39
- isNumber() {
40
- return false;
41
- }
42
- isInt() {
43
- return false;
44
- }
45
- isDecimal() {
46
- return false;
47
- }
48
- isApplyRegex() {
49
- return false;
50
- }
51
- isApplyRequired() {
52
- return false;
53
- }
54
- isApplyMin() {
55
- return false;
56
- }
57
- isApplyMax() {
58
- return false;
59
- }
60
- isDate() {
61
- return false;
62
- }
63
- isTransform() {
64
- return true;
65
- }
66
- // This is the field type of the owner in the m2m relation
67
- fieldType() {
68
- return this.manyToManyFieldType(this.field.relationModelSingularName);
69
- }
70
- // This field type is used in the case of one-to-many relation, when we generate the inverse field in the related entity
71
- additionalFieldType() {
72
- return this.manyToManyFieldType(this.modelName);
73
- }
74
- transformType(forModelName) {
75
- return `Update${(0, strings_1.classify)(forModelName)}Dto`;
76
- }
77
- manyToManyFieldType(forModelName) {
78
- // const type = `number`
79
- const type = this.transformType(forModelName);
80
- const text = `${type}[]`;
81
- return {
82
- text: text,
83
- node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
84
- };
85
- }
86
- addAdditionalField() {
87
- const fieldChanges = [];
88
- // Add the ids field to the main entity
89
- fieldChanges.push(this.addAdditionalIdsField());
90
- // Add the command field to the main entity
91
- fieldChanges.push(this.addAdditionalCommandField());
92
- // Add the inverse field to the related entity
93
- if (this.field.relationCreateInverse) {
94
- fieldChanges.push(this.addAdditionalInverseField());
95
- fieldChanges.push(this.addAdditionalInverseIdsField());
96
- fieldChanges.push(this.addAdditionalInverseCommandsField());
97
- }
98
- return fieldChanges;
99
- }
100
- addAdditionalInverseIdsField() {
101
- const fieldName = `${this.field.relationModelFieldName}Ids`;
102
- const fieldType = "number[]";
103
- const source = this.relationInverseSource;
104
- const field = this.field;
105
- const modelName = this.field.relationModelSingularName;
106
- const decoratorManagers = [
107
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
108
- new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
109
- ];
110
- return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
111
- }
112
- addAdditionalInverseCommandsField() {
113
- const fieldName = `${this.field.relationModelFieldName}Command`;
114
- const fieldType = "string";
115
- const source = this.relationInverseSource;
116
- const field = this.field;
117
- const modelName = this.field.relationModelSingularName;
118
- const decoratorManagers = [
119
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
120
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
121
- // TODO pending @IsEnum(RelationFieldsCommand)
122
- ];
123
- return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
124
- }
125
- addAdditionalIdsField() {
126
- const fieldName = `${this.field.name}Ids`;
127
- const fieldType = "number[]";
128
- const source = this.source;
129
- const field = this.field;
130
- const modelName = this.modelName;
131
- const decoratorManagers = [
132
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
133
- new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
134
- ];
135
- return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
136
- }
137
- addAdditionalCommandField() {
138
- const fieldName = `${this.field.name}Command`;
139
- const fieldType = "string";
140
- const source = this.source;
141
- const field = this.field;
142
- const modelName = this.modelName;
143
- const decoratorManagers = [
144
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
145
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
146
- // TODO pending @IsEnum(RelationFieldsCommand)
147
- ];
148
- return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
149
- }
150
- inverseFieldImport(modelName, moduleName, source) {
151
- const inverseEntityImportName = `update-${(0, strings_1.dasherize)(modelName)}.dto`;
152
- const inverseEntityPath = `src/${moduleName}/dtos/${inverseEntityImportName}`;
153
- return (0, FieldManager_1.safeInsertImport)(source, `Update${(0, strings_1.classify)(modelName)}Dto`, inverseEntityPath);
154
- }
155
- addAdditionalInverseField() {
156
- const fieldName = this.additionalFieldName();
157
- const fieldType = this.additionalFieldType().text;
158
- const source = this.relationInverseSource;
159
- const field = this.field;
160
- const modelName = this.field.relationModelSingularName;
161
- const decoratorManagers = this.relationInverseDecoratorManagers;
162
- const fieldChange = this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
163
- if (this.modelName !== this.field.relationModelSingularName) {
164
- const currentModelName = this.modelName;
165
- const currentModuleName = this.moduleName;
166
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
167
- }
168
- return fieldChange;
169
- }
170
- //TODO: Can be improved to avoid duplicate code
171
- addOrUpdateAdditionalField() {
172
- const fieldChanges = [];
173
- // Add or update the ids field
174
- fieldChanges.push(this.updateAdditionalIdsField());
175
- // Add or update the command field
176
- fieldChanges.push(this.updateAdditionalCommandField());
177
- if (this.field.relationCreateInverse) {
178
- fieldChanges.push(this.updateAdditionalInverseField());
179
- fieldChanges.push(this.updateAdditionalInverseIdsField());
180
- fieldChanges.push(this.updateAdditionalInverseCommandsField());
181
- }
182
- return fieldChanges;
183
- }
184
- updateAdditionalInverseField() {
185
- var _a;
186
- const inverseFieldName = this.field.relationModelFieldName;
187
- const inverseFieldType = this.manyToManyFieldType(this.modelName).node(this.field);
188
- const source = this.relationInverseSource;
189
- const field = this.field;
190
- const inverseDecoratorManagers = this.relationInverseDecoratorManagers;
191
- const inverseField = (_a = this.getFieldIdentifierNode(inverseFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
192
- if (inverseField == null) {
193
- return this.addAdditionalInverseField();
194
- }
195
- else {
196
- //Update the inverse field
197
- const fieldChange = this.updateFieldInternal(inverseFieldName, inverseFieldType, inverseDecoratorManagers, field, source);
198
- if (this.modelName !== this.field.relationModelSingularName) {
199
- const currentModelName = this.modelName;
200
- const currentModuleName = this.moduleName;
201
- fieldChange.changes.push(this.inverseFieldImport(currentModelName, currentModuleName, source));
202
- }
203
- return fieldChange;
204
- }
205
- }
206
- updateAdditionalInverseIdsField() {
207
- var _a;
208
- const idsFieldName = `${this.field.relationModelFieldName}Ids`;
209
- const idsFieldType = typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword));
210
- const source = this.relationInverseSource;
211
- const field = this.field;
212
- const decoratorManagers = [
213
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
214
- new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
215
- ];
216
- const idsField = (_a = this.getFieldIdentifierNode(idsFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
217
- if (idsField == null) {
218
- return this.addAdditionalInverseIdsField();
219
- }
220
- else {
221
- //Update the ids field
222
- return this.updateFieldInternal(idsFieldName, idsFieldType, decoratorManagers, field, source);
223
- }
224
- }
225
- updateAdditionalInverseCommandsField() {
226
- var _a;
227
- const commandFieldName = `${this.field.relationModelFieldName}Command`;
228
- const commandFieldType = typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
229
- const source = this.relationInverseSource;
230
- const field = this.field;
231
- const decoratorManagers = [
232
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
233
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
234
- // TODO pending @IsEnum(RelationFieldsCommand)
235
- ];
236
- const commandField = (_a = this.getFieldIdentifierNode(commandFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
237
- if (commandField == null) {
238
- return this.addAdditionalInverseCommandsField();
239
- }
240
- else {
241
- //Update the command field
242
- return this.updateFieldInternal(commandFieldName, commandFieldType, decoratorManagers, field, source);
243
- }
244
- }
245
- updateAdditionalIdsField() {
246
- var _a;
247
- const idsFieldName = `${this.field.name}Ids`;
248
- const source = this.source;
249
- const field = this.field;
250
- // Handle the main source additional fields
251
- // Add or update the ids field
252
- const idsField = (_a = this.getFieldIdentifierNode(idsFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
253
- if (idsField == null) {
254
- return this.addAdditionalIdsField();
255
- }
256
- else {
257
- //Update the ids field
258
- const fieldType = typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword));
259
- const decoratorManagers = [
260
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
261
- new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
262
- ];
263
- return this.updateFieldInternal(idsFieldName, fieldType, decoratorManagers, field, source);
264
- }
265
- }
266
- updateAdditionalCommandField() {
267
- var _a;
268
- const commandFieldName = `${this.field.name}Command`;
269
- const source = this.source;
270
- const field = this.field;
271
- // Handle the main source additional fields
272
- // Add or update the command field
273
- const commandField = (_a = this.getFieldIdentifierNode(commandFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
274
- if (commandField == null) {
275
- return this.addAdditionalCommandField();
276
- }
277
- else {
278
- //Update the command field
279
- const fieldType = typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
280
- const decoratorManagers = [
281
- new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
282
- new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
283
- // TODO pending @IsEnum(RelationFieldsCommand)
284
- ];
285
- return this.updateFieldInternal(commandFieldName, fieldType, decoratorManagers, field, source);
286
- }
287
- }
288
- removeAdditionalField() {
289
- const fieldChanges = [];
290
- // Add the ids field to the main entity
291
- fieldChanges.push(this.removeAdditionalIdsField());
292
- // Add the command field to the main entity
293
- fieldChanges.push(this.removeAdditionalCommandField());
294
- // Add the inverse field to the related entity
295
- if (this.field.relationCreateInverse) {
296
- fieldChanges.push(this.removeAdditionalInverseField());
297
- fieldChanges.push(this.removeAdditionalInverseIdsField());
298
- fieldChanges.push(this.removeAdditionalInverseCommandsField());
299
- }
300
- return fieldChanges;
301
- }
302
- removeAdditionalIdsField() {
303
- const fieldName = `${this.field.name}Ids`;
304
- const source = this.source;
305
- return this.removeFieldFor(fieldName, source);
306
- }
307
- removeAdditionalCommandField() {
308
- const fieldName = `${this.field.name}Command`;
309
- const source = this.source;
310
- return this.removeFieldFor(fieldName, source);
311
- }
312
- removeAdditionalInverseField() {
313
- const fieldName = this.additionalFieldName();
314
- const source = this.relationInverseSource;
315
- return this.removeFieldFor(fieldName, source);
316
- }
317
- removeAdditionalInverseIdsField() {
318
- const fieldName = `${this.field.relationModelFieldName}Ids`;
319
- const source = this.relationInverseSource;
320
- return this.removeFieldFor(fieldName, source);
321
- }
322
- removeAdditionalInverseCommandsField() {
323
- const fieldName = `${this.field.relationModelFieldName}Command`;
324
- const source = this.relationInverseSource;
325
- return this.removeFieldFor(fieldName, source);
326
- }
327
- //TODO: Need to revise the algorithm to generate multiple fields as part of single solid field type
328
- fieldName() {
329
- return `${this.field.name}`;
330
- }
331
- additionalFieldName() {
332
- return this.field.relationModelFieldName;
333
- }
334
- isAdditionalFieldRequired() {
335
- return true;
336
- // return this.field.relationCreateInverse;
337
- }
338
- addField() {
339
- const fieldChanges = super.addField();
340
- if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
341
- const mainField = fieldChanges[0];
342
- mainField.changes.push(this.relatedFieldImport());
343
- }
344
- return fieldChanges;
345
- }
346
- updateField() {
347
- const fieldChanges = super.updateField();
348
- //FIXME This might not be required, since addField might never be called from within updateField
349
- // const containsAddFieldChanges = fieldChanges.filter((change) => !(change instanceof InsertChange));
350
- // if (containsAddFieldChanges) return fieldChanges;
351
- //This line is required to add import changes in the update context
352
- // if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
353
- const mainField = fieldChanges[0];
354
- mainField.changes.push(this.relatedFieldImport());
355
- // }
356
- return fieldChanges;
357
- }
358
- relatedFieldImport() {
359
- const relatedEntityImportName = `update-${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.dto`;
360
- const relatedEntityPath = this.field.relationModelModuleName ? `src/${this.field.relationModelModuleName}/dtos/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
361
- return (0, FieldManager_1.safeInsertImport)(this.source, `Update${(0, strings_1.classify)(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
362
- // return insertImport(this.source, this.source.fileName, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
363
- } //Uncomment this method while implementing many-to-many relation changes
364
- }
365
- exports.ManyToManyRelationFieldManagerForDto = ManyToManyRelationFieldManagerForDto;
366
- //# sourceMappingURL=ManyToManyRelationFieldManagerForDto.js.map