@solidstarters/solid-code-builder 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-builder/lib/field/FieldManager.d.ts +2 -1
- package/dist/code-builder/lib/field/FieldManager.js +18 -5
- package/dist/code-builder/lib/field/FieldManager.js.map +1 -1
- package/dist/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +1 -1
- package/dist/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.d.ts +6 -3
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +50 -15
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.d.ts +3 -0
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +15 -3
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.d.ts +13 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.js +33 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.js.map +1 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.d.ts +4 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.js +9 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.js.map +1 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.d.ts +4 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.js +8 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.js.map +1 -0
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.d.ts +1 -16
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +15 -156
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.d.ts +1 -20
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -109
- package/dist/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.d.ts +2 -17
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +4 -175
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.d.ts +1 -22
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +1 -133
- package/dist/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.d.ts +13 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.js +33 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.js.map +1 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.d.ts +34 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.js +202 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.js.map +1 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.d.ts +9 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.js +43 -0
- package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.js.map +1 -0
- package/dist/files/generate-model/controllers/__model@dasherize__.controller.ts +6 -2
- package/files/generate-model/controllers/__model@dasherize__.controller.ts +6 -2
- package/package.json +1 -1
- package/src/code-builder/lib/field/FieldManager.ts +19 -6
- package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.ts +1 -1
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.ts +74 -26
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.ts +19 -3
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldHandler.ts +52 -0
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForDto.ts +8 -0
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyInverseRelationFieldManagerForEntity.ts +8 -0
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.ts +16 -189
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.ts +2 -147
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.ts +6 -215
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.ts +3 -174
- package/src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldHandler.ts +52 -0
- package/src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.ts +247 -0
- package/src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.ts +51 -0
package/dist/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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.OneToManyRelationFieldManagerForDto = 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 StringDecoratorManager_1 = require("../../decorator-managers/dto/StringDecoratorManager");
|
|
12
|
+
const TransformDecoratorManager_1 = require("../../decorator-managers/dto/TransformDecoratorManager");
|
|
13
|
+
const FieldManager_1 = require("../../FieldManager");
|
|
14
|
+
const BaseFieldManagerForDto_1 = require("../base/BaseFieldManagerForDto");
|
|
15
|
+
class OneToManyRelationFieldManagerForDto 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(), source: this.source, field: field }));
|
|
26
|
+
}
|
|
27
|
+
isString() {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
isNumber() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
isInt() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
isDecimal() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
isApplyRegex() {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
isApplyRequired() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
isApplyMin() {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
isApplyMax() {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
isDate() {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
isTransform() {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// This field type is used in the case of one-to-many relation, when we generate the inverse field in the related entity
|
|
58
|
+
fieldType() {
|
|
59
|
+
const type = this.transformType(); //TODO Discuss if this needs to be Create Or Update DTO
|
|
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
|
+
transformType() {
|
|
67
|
+
return `Update${(0, strings_1.classify)(this.field.relationModelSingularName)}Dto`;
|
|
68
|
+
}
|
|
69
|
+
addField() {
|
|
70
|
+
const fieldChanges = super.addField();
|
|
71
|
+
if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
|
|
72
|
+
const mainField = fieldChanges[0];
|
|
73
|
+
mainField.changes.push(this.relatedFieldImport());
|
|
74
|
+
}
|
|
75
|
+
return fieldChanges;
|
|
76
|
+
}
|
|
77
|
+
addAdditionalField() {
|
|
78
|
+
const fieldChanges = [];
|
|
79
|
+
// Add the ids field to the main entity
|
|
80
|
+
fieldChanges.push(this.addAdditionalIdsField());
|
|
81
|
+
// Add the command field to the main entity
|
|
82
|
+
fieldChanges.push(this.addAdditionalCommandField());
|
|
83
|
+
return fieldChanges;
|
|
84
|
+
}
|
|
85
|
+
addAdditionalIdsField() {
|
|
86
|
+
const fieldName = `${this.field.name}Ids`;
|
|
87
|
+
const fieldType = "number[]";
|
|
88
|
+
const source = this.source;
|
|
89
|
+
const field = this.field;
|
|
90
|
+
const modelName = this.modelName;
|
|
91
|
+
const decoratorManagers = [
|
|
92
|
+
new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
|
|
93
|
+
new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
|
|
94
|
+
];
|
|
95
|
+
return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
|
|
96
|
+
}
|
|
97
|
+
addAdditionalCommandField() {
|
|
98
|
+
const fieldName = `${this.field.name}Command`;
|
|
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
|
+
// TODO pending @IsEnum(RelationFieldsCommand)
|
|
107
|
+
];
|
|
108
|
+
return this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source);
|
|
109
|
+
}
|
|
110
|
+
updateField() {
|
|
111
|
+
const fieldChanges = super.updateField();
|
|
112
|
+
//FIXME This might not be required, since addField might never be called from within updateField
|
|
113
|
+
// const containsAddFieldChanges = fieldChanges.filter((change) => !(change instanceof InsertChange));
|
|
114
|
+
// if (containsAddFieldChanges) return fieldChanges;
|
|
115
|
+
//This line is required to add import changes in the update context
|
|
116
|
+
// if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
|
|
117
|
+
const mainField = fieldChanges[0];
|
|
118
|
+
mainField.changes.push(this.relatedFieldImport());
|
|
119
|
+
// }
|
|
120
|
+
return fieldChanges;
|
|
121
|
+
}
|
|
122
|
+
addOrUpdateAdditionalField() {
|
|
123
|
+
const fieldChanges = [];
|
|
124
|
+
// Add or update the ids field
|
|
125
|
+
fieldChanges.push(this.updateAdditionalIdsField());
|
|
126
|
+
// Add or update the command field
|
|
127
|
+
fieldChanges.push(this.updateAdditionalCommandField());
|
|
128
|
+
return fieldChanges;
|
|
129
|
+
}
|
|
130
|
+
updateAdditionalIdsField() {
|
|
131
|
+
var _a;
|
|
132
|
+
const idsFieldName = `${this.field.name}Ids`;
|
|
133
|
+
const source = this.source;
|
|
134
|
+
const field = this.field;
|
|
135
|
+
// Handle the main source additional fields
|
|
136
|
+
// Add or update the ids field
|
|
137
|
+
const idsField = (_a = this.getFieldIdentifierNode(idsFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
|
|
138
|
+
if (idsField == null) {
|
|
139
|
+
return this.addAdditionalIdsField();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
//Update the ids field
|
|
143
|
+
const fieldType = typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword));
|
|
144
|
+
const decoratorManagers = [
|
|
145
|
+
new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
|
|
146
|
+
new ArrayDecoratorManager_1.ArrayDecoratorManager({ isArray: true, source: source, field: field })
|
|
147
|
+
];
|
|
148
|
+
return this.updateFieldInternal(idsFieldName, fieldType, decoratorManagers, field, source);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
updateAdditionalCommandField() {
|
|
152
|
+
var _a;
|
|
153
|
+
const commandFieldName = `${this.field.name}Command`;
|
|
154
|
+
const source = this.source;
|
|
155
|
+
const field = this.field;
|
|
156
|
+
// Handle the main source additional fields
|
|
157
|
+
// Add or update the command field
|
|
158
|
+
const commandField = (_a = this.getFieldIdentifierNode(commandFieldName, source)) === null || _a === void 0 ? void 0 : _a.parent;
|
|
159
|
+
if (commandField == null) {
|
|
160
|
+
return this.addAdditionalCommandField();
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
//Update the command field
|
|
164
|
+
const fieldType = typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword);
|
|
165
|
+
const decoratorManagers = [
|
|
166
|
+
new StringDecoratorManager_1.StringDecoratorManager({ isString: true, source: source, field: field }),
|
|
167
|
+
new OptionalDecoratorManager_1.OptionalDecoratorManager({ isApplyOptional: true, optional: true, source: source, field: field }),
|
|
168
|
+
// TODO pending @IsEnum(RelationFieldsCommand)
|
|
169
|
+
];
|
|
170
|
+
return this.updateFieldInternal(commandFieldName, fieldType, decoratorManagers, field, source);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
removeAdditionalField() {
|
|
174
|
+
const fieldChanges = [];
|
|
175
|
+
// Add the ids field to the main entity
|
|
176
|
+
fieldChanges.push(this.removeAdditionalIdsField());
|
|
177
|
+
// Add the command field to the main entity
|
|
178
|
+
fieldChanges.push(this.removeAdditionalCommandField());
|
|
179
|
+
return fieldChanges;
|
|
180
|
+
}
|
|
181
|
+
removeAdditionalIdsField() {
|
|
182
|
+
const fieldName = `${this.field.name}Ids`;
|
|
183
|
+
const source = this.source;
|
|
184
|
+
return this.removeFieldFor(fieldName, source);
|
|
185
|
+
}
|
|
186
|
+
removeAdditionalCommandField() {
|
|
187
|
+
const fieldName = `${this.field.name}Command`;
|
|
188
|
+
const source = this.source;
|
|
189
|
+
return this.removeFieldFor(fieldName, source);
|
|
190
|
+
}
|
|
191
|
+
isAdditionalFieldRequired() {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
relatedFieldImport() {
|
|
195
|
+
const relatedEntityImportName = `update-${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.dto`;
|
|
196
|
+
const relatedEntityPath = this.field.relationModelModuleName ? `src/${this.field.relationModelModuleName}/dtos/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
|
|
197
|
+
return (0, FieldManager_1.safeInsertImport)(this.source, `Update${(0, strings_1.classify)(this.field.relationModelSingularName)}Dto`, relatedEntityPath, this.moduleName);
|
|
198
|
+
// return insertImport(this.source, this.source.fileName, `Update${classify(this.field.relationModelSingularName)}Dto`, relatedEntityPath);
|
|
199
|
+
} //Uncomment this method while implementing many-to-many relation changes
|
|
200
|
+
}
|
|
201
|
+
exports.OneToManyRelationFieldManagerForDto = OneToManyRelationFieldManagerForDto;
|
|
202
|
+
//# sourceMappingURL=OneToManyRelationFieldManagerForDto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneToManyRelationFieldManagerForDto.js","sourceRoot":"","sources":["../../../../../../src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForDto.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA6E;AAE7E,gIAAyH;AAEzH,8FAA2F;AAC3F,oGAAiG;AACjG,gGAA6F;AAC7F,sGAAmG;AACnG,qDAAiI;AACjI,2EAAwE;AAExE,MAAa,mCACX,SAAQ,+CAAsB;IAE9B,MAAM;QACJ,OAAO,KAAK,CAAC;IACf,CAAC;IACD,SAAS;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IAED,YAAY,IAAU,EAAE,UAAkB,EAAE,SAAiB,EAAE,KAAU,EAAE,OAA6B;QACtG,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,kCAAO,KAAK,KAAE,QAAQ,EAAE,KAAK,KAAI,OAAO,CAAC,CAAC;QAC3E,IAAI,CAAC,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAC,iBAAiB,EAAE,GAAG,IAAI,CAAC,yBAAyB,CACpF,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,EACX,4BAAa,CAAC,KAAK,EACnB,4BAAa,CAAC,cAAc,CAC7B,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,CAAC,IAAI,CACzB,IAAI,qDAAyB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAA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AAC,KAAK,CAAC,IAAI,SAAS,CAAC;QAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAES,yBAAyB;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB;QAChB,MAAM,uBAAuB,GAAG,UAAU,IAAA,mBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,MAAM,CAAC;QAChG,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,uBAAuB,SAAS,uBAAuB,EAAE,CAAC,CAAC,CAAC,KAAK,uBAAuB,EAAE,CAAC;QAC5K,OAAO,IAAA,+BAAgB,EAAC,IAAI,CAAC,MAAM,EAAE,SAAS,IAAA,kBAAQ,EAAC,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,KAAK,EAAE,iBAAiB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACvI,2IAA2I;IAC7I,CAAC,CAAC,wEAAwE;CAE3E;AA3OD,kFA2OC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Change } from '@schematics/angular/utility/change';
|
|
2
|
+
import { FieldChange, FieldManager, FieldType } from '../../FieldManager';
|
|
3
|
+
import { BaseFieldManagerForEntity } from '../base/BaseFieldManagerForEntity';
|
|
4
|
+
export declare class OneToManyRelationFieldManagerForEntity extends BaseFieldManagerForEntity implements FieldManager {
|
|
5
|
+
addField(): FieldChange[];
|
|
6
|
+
updateField(): FieldChange[];
|
|
7
|
+
relatedFieldImport(): Change;
|
|
8
|
+
fieldType(): FieldType;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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.OneToManyRelationFieldManagerForEntity = 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 FieldManager_1 = require("../../FieldManager");
|
|
10
|
+
const BaseFieldManagerForEntity_1 = require("../base/BaseFieldManagerForEntity");
|
|
11
|
+
class OneToManyRelationFieldManagerForEntity extends BaseFieldManagerForEntity_1.BaseFieldManagerForEntity {
|
|
12
|
+
addField() {
|
|
13
|
+
const fieldChanges = super.addField();
|
|
14
|
+
if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
|
|
15
|
+
const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
|
|
16
|
+
mainField.changes.push(this.relatedFieldImport());
|
|
17
|
+
}
|
|
18
|
+
return fieldChanges;
|
|
19
|
+
}
|
|
20
|
+
updateField() {
|
|
21
|
+
const fieldChanges = super.updateField();
|
|
22
|
+
if (fieldChanges.length > 0 && this.modelName !== this.field.relationModelSingularName) {
|
|
23
|
+
const mainField = fieldChanges[0]; // The 1st field change is the main field change, related to the entity source file
|
|
24
|
+
mainField.changes.push(this.relatedFieldImport());
|
|
25
|
+
}
|
|
26
|
+
return fieldChanges;
|
|
27
|
+
}
|
|
28
|
+
relatedFieldImport() {
|
|
29
|
+
const relatedEntityImportName = `${(0, strings_1.dasherize)(this.field.relationModelSingularName)}.entity`;
|
|
30
|
+
const relatedEntityPath = this.field.relationModelModuleName ? `src/${(0, strings_1.dasherize)(this.field.relationModelModuleName)}/entities/${relatedEntityImportName}` : `./${relatedEntityImportName}`;
|
|
31
|
+
return (0, FieldManager_1.safeInsertImport)(this.source, (0, strings_1.classify)(this.field.relationModelSingularName), relatedEntityPath, this.moduleName);
|
|
32
|
+
}
|
|
33
|
+
fieldType() {
|
|
34
|
+
const type = `${(0, strings_1.classify)(this.field.relationModelSingularName)}`;
|
|
35
|
+
const text = `${type}[]`;
|
|
36
|
+
return {
|
|
37
|
+
text: text,
|
|
38
|
+
node: (_field) => typescript_1.default.factory.createArrayTypeNode(typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createIdentifier(type), undefined)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.OneToManyRelationFieldManagerForEntity = OneToManyRelationFieldManagerForEntity;
|
|
43
|
+
//# sourceMappingURL=OneToManyRelationFieldManagerForEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OneToManyRelationFieldManagerForEntity.js","sourceRoot":"","sources":["../../../../../../src/code-builder/lib/field/field-managers/relation/OneToManyRelationFieldManagerForEntity.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA6E;AAC7E,gIAAgG;AAEhG,qDAA4F;AAC5F,iFAE2C;AAE3C,MAAa,sCACX,SAAQ,qDAAyB;IAGxB,QAAQ;QACf,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QACtC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC;YACvF,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,mFAAmF;YACtH,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,YAAY,CAAA;IACrB,CAAC;IAEQ,WAAW;QAClB,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC;YACvF,MAAM,SAAS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create-<%= dasherize(model) %>.dto';
|
|
6
6
|
import { Update<%= classify(model) %>Dto } from '../dtos/update-<%= dasherize(model) %>.dto';
|
|
7
7
|
|
|
8
|
+
enum ShowSoftDeleted {
|
|
9
|
+
INCLUSIVE = "inclusive",
|
|
10
|
+
EXCLUSIVE = "exclusive",
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
@ApiTags('<%= unSnakeCase(moduleDisplayName) %>')
|
|
9
14
|
@Controller('<%= dasherize(model) %>')
|
|
10
15
|
export class <%= classify(model) %>Controller {
|
|
@@ -52,8 +57,7 @@ export class <%= classify(model) %>Controller {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
@ApiBearerAuth("jwt")
|
|
55
|
-
@ApiQuery({ name: 'showSoftDeleted', required: false,
|
|
56
|
-
@ApiQuery({ name: 'showOnlySoftDeleted', required: false, type: Boolean })
|
|
60
|
+
@ApiQuery({ name: 'showSoftDeleted', required: false, enum: ShowSoftDeleted })
|
|
57
61
|
@ApiQuery({ name: 'limit', required: false, type: Number })
|
|
58
62
|
@ApiQuery({ name: 'offset', required: false, type: Number })
|
|
59
63
|
@ApiQuery({ name: 'fields', required: false, type: Array })
|
|
@@ -5,6 +5,11 @@ import { <%= classify(model) %>Service } from '../services/<%= dasherize(model)
|
|
|
5
5
|
import { Create<%= classify(model) %>Dto } from '../dtos/create-<%= dasherize(model) %>.dto';
|
|
6
6
|
import { Update<%= classify(model) %>Dto } from '../dtos/update-<%= dasherize(model) %>.dto';
|
|
7
7
|
|
|
8
|
+
enum ShowSoftDeleted {
|
|
9
|
+
INCLUSIVE = "inclusive",
|
|
10
|
+
EXCLUSIVE = "exclusive",
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
@ApiTags('<%= unSnakeCase(moduleDisplayName) %>')
|
|
9
14
|
@Controller('<%= dasherize(model) %>')
|
|
10
15
|
export class <%= classify(model) %>Controller {
|
|
@@ -52,8 +57,7 @@ export class <%= classify(model) %>Controller {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
@ApiBearerAuth("jwt")
|
|
55
|
-
@ApiQuery({ name: 'showSoftDeleted', required: false,
|
|
56
|
-
@ApiQuery({ name: 'showOnlySoftDeleted', required: false, type: Boolean })
|
|
60
|
+
@ApiQuery({ name: 'showSoftDeleted', required: false, enum: ShowSoftDeleted })
|
|
57
61
|
@ApiQuery({ name: 'limit', required: false, type: Number })
|
|
58
62
|
@ApiQuery({ name: 'offset', required: false, type: Number })
|
|
59
63
|
@ApiQuery({ name: 'fields', required: false, type: Array })
|
package/package.json
CHANGED
|
@@ -20,6 +20,8 @@ import { RichTextFieldHandler } from './field-managers/rich-text/RichTextFieldHa
|
|
|
20
20
|
import { ShortTextFieldHandler } from './field-managers/short-text/ShortTextFieldHandler';
|
|
21
21
|
import { UUIDFieldHandler } from './field-managers/uuid/UUIDFieldHandler';
|
|
22
22
|
import { SOLID_CORE_MODULE_NAME, SOLID_CORE_MODULE_NPM_PACKAGE_NAME } from '../model/helpers';
|
|
23
|
+
import { OneToManyRelationFieldHandler } from './field-managers/relation/OneToManyRelationFieldHandler';
|
|
24
|
+
import { ManyToManyInverseRelationFieldHandler } from './field-managers/relation/ManyToManyInverseRelationFieldHandler';
|
|
23
25
|
|
|
24
26
|
export const MAX_EMAIL_LENGTH = 254;
|
|
25
27
|
export const UUID_REGEX = `^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`;
|
|
@@ -212,13 +214,23 @@ export function getFieldHandler(
|
|
|
212
214
|
case SolidFieldType.datetime:
|
|
213
215
|
case SolidFieldType.time:
|
|
214
216
|
return new DateFieldHandler(tree, moduleName, modelName, field);
|
|
215
|
-
case SolidFieldType.relation:
|
|
216
|
-
if (field.relationType === RelationType.
|
|
217
|
-
return new ManyToManyRelationFieldHandler(tree, moduleName, modelName, field);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
217
|
+
case SolidFieldType.relation: {
|
|
218
|
+
if (field.relationType === RelationType.ManyToOne) {
|
|
220
219
|
return new ManyToOneRelationFieldHandler(tree, moduleName, modelName, field);
|
|
221
220
|
}
|
|
221
|
+
else if (field.relationType === RelationType.OneToMany) {
|
|
222
|
+
return new OneToManyRelationFieldHandler(tree, moduleName, modelName, field);
|
|
223
|
+
}
|
|
224
|
+
else if (field.relationType === RelationType.ManyToMany) {
|
|
225
|
+
if (field.isRelationManyToManyOwner) {
|
|
226
|
+
return new ManyToManyRelationFieldHandler(tree, moduleName, modelName, field);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return new ManyToManyInverseRelationFieldHandler(tree, moduleName, modelName, field);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return new NoOpsFieldHandler(tree, moduleName, modelName, field);
|
|
233
|
+
}
|
|
222
234
|
case SolidFieldType.mediaSingle:
|
|
223
235
|
case SolidFieldType.mediaMultiple:
|
|
224
236
|
return new NoOpsFieldHandler(tree, moduleName, modelName, field);
|
|
@@ -269,7 +281,8 @@ export function getClassExportKeywordNode (className: string, sourceFile: ts.Sou
|
|
|
269
281
|
|
|
270
282
|
export enum RelationType {
|
|
271
283
|
ManyToOne = 'many-to-one',
|
|
272
|
-
ManyToMany = 'many-to-many'
|
|
284
|
+
ManyToMany = 'many-to-many',
|
|
285
|
+
OneToMany = "one-to-many"
|
|
273
286
|
}
|
|
274
287
|
|
|
275
288
|
export enum DtoSourceType {
|
|
@@ -13,7 +13,7 @@ export class IndexDecoratorManager implements DecoratorManager {
|
|
|
13
13
|
|
|
14
14
|
constructor(public options: IndexDecoratorOptions, public fieldNode?: PropertyDeclaration) { }
|
|
15
15
|
isApplyDecorator(): boolean {
|
|
16
|
-
return this.options.index && this.options.field.relationType !== RelationType.ManyToMany;
|
|
16
|
+
return this.options.index && this.options.field.relationType !== RelationType.ManyToMany && this.options.field.relationType !== RelationType.OneToMany;
|
|
17
17
|
}
|
|
18
18
|
decoratorName(): string {
|
|
19
19
|
return 'Index';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { classify, dasherize } from '@angular-devkit/core/src/utils/strings';
|
|
2
2
|
import { Tree } from '@angular-devkit/schematics';
|
|
3
3
|
import ts, {
|
|
4
|
+
ClassDeclaration,
|
|
4
5
|
PropertyDeclaration,
|
|
5
6
|
SourceFile,
|
|
6
7
|
} from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
@@ -48,6 +49,7 @@ import { ApiPropertyDecoratorManager } from '../../decorator-managers/dto/ApiPro
|
|
|
48
49
|
// The validation decorators added use the class-validator library
|
|
49
50
|
export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
50
51
|
source: SourceFile;
|
|
52
|
+
updatedSourceClassNode?: ts.ClassDeclaration;
|
|
51
53
|
decoratorManagers: DecoratorManager[];
|
|
52
54
|
|
|
53
55
|
constructor(
|
|
@@ -137,7 +139,7 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
137
139
|
protected addFieldInternal(fieldName: string, fieldType: string, decoratorManagers: DecoratorManager[], field: any, modelName: any, source: ts.SourceFile): FieldChange {
|
|
138
140
|
//FIXME There might a case where the main field is not present, but additional field is present. Do we update the fields or throw an error. Needs to be discussed
|
|
139
141
|
// For now, we assume, that if primary field is not present, then additional field is also not present
|
|
140
|
-
if (this.isFieldPresent(fieldName, source)) {
|
|
142
|
+
if (this.isFieldPresent(fieldName, source)) {
|
|
141
143
|
return {
|
|
142
144
|
filePath: source.fileName,
|
|
143
145
|
field: field,
|
|
@@ -166,14 +168,8 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
166
168
|
fieldSourceLines.push(...builderChange.fieldSourceLines);
|
|
167
169
|
});
|
|
168
170
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const className = (this.options.sourceType === DtoSourceType.Create) ? `Create${classify(modelName)}Dto` : `Update${classify(modelName)}Dto`;
|
|
172
|
-
const classNode = getClassNode(className,source);
|
|
173
|
-
if (!classNode) {
|
|
174
|
-
throw new Error(`Class ${className} not found in file ${source.fileName}`);
|
|
175
|
-
}
|
|
176
|
-
|
|
171
|
+
const classNode = this.getClassNode(modelName, this.options, source);
|
|
172
|
+
|
|
177
173
|
const fieldDefinition = `\n${fieldSourceLines.reverse().join('\n')}\n`;
|
|
178
174
|
changes.push(
|
|
179
175
|
new InsertChange(
|
|
@@ -208,9 +204,9 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
208
204
|
|
|
209
205
|
const fieldName = this.fieldName();
|
|
210
206
|
const fieldType = this.fieldType().text;
|
|
211
|
-
const source= this.source
|
|
207
|
+
const source = this.source
|
|
212
208
|
const field = this.field
|
|
213
|
-
const modelName = this.modelName
|
|
209
|
+
const modelName = this.modelName
|
|
214
210
|
const decoratorManagers = this.decoratorManagers;
|
|
215
211
|
|
|
216
212
|
fieldChanges.push(this.addFieldInternal(fieldName, fieldType, decoratorManagers, field, modelName, source));
|
|
@@ -241,7 +237,20 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
241
237
|
updatedPropertyDeclarationNode = updatedPropertyDeclarationNodeTransformed;
|
|
242
238
|
changes.push(...decoratorChanges);
|
|
243
239
|
|
|
244
|
-
changes.push(...this.calculateReplaceChanges(this.printNode(updatedPropertyDeclarationNode, source), fieldPropertyDeclarationNode, source));
|
|
240
|
+
// changes.push(...this.calculateReplaceChanges(this.printNode(updatedPropertyDeclarationNode, source), fieldPropertyDeclarationNode, source));
|
|
241
|
+
|
|
242
|
+
// if (!this.isAdditionalFieldRequired()) {
|
|
243
|
+
// Get the source class node i.e CreateDto or UpdateDto
|
|
244
|
+
const sourceClassNode = this.getClassNode(this.modelName, this.options, source); // FIXME Avoid this.model to avoid stateful behaviour
|
|
245
|
+
const classNode = this.updatedSourceClassNode ?? sourceClassNode;
|
|
246
|
+
// Set the updated property declaration node to the source class node
|
|
247
|
+
const updatedClassNode = this.updateClassNode(classNode, updatedPropertyDeclarationNode, fieldName);
|
|
248
|
+
this.updatedSourceClassNode = updatedClassNode; // Set the updated class node to the source class node, so it can be used for additional operations e.g for additional field updates
|
|
249
|
+
changes.push(...this.calculateReplaceChanges(this.printNode(updatedClassNode, source), sourceClassNode, source.fileName));
|
|
250
|
+
// }
|
|
251
|
+
// else {
|
|
252
|
+
// changes.push(...this.calculateReplaceChanges(this.printNode(updatedPropertyDeclarationNode, source), fieldPropertyDeclarationNode, source.fileName));
|
|
253
|
+
// }
|
|
245
254
|
|
|
246
255
|
return {
|
|
247
256
|
filePath: source.fileName,
|
|
@@ -250,6 +259,32 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
250
259
|
};
|
|
251
260
|
}
|
|
252
261
|
|
|
262
|
+
updateClassNode(sourceClassNode: ts.ClassDeclaration, updatedFieldNode: ts.PropertyDeclaration, fieldName: string): ClassDeclaration {
|
|
263
|
+
// Replace the class memeber matching the field name with the updated field node
|
|
264
|
+
const newMembers = sourceClassNode.members.map((member) => {
|
|
265
|
+
// Check if the member is a PropertyDeclaration
|
|
266
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
267
|
+
// Compare the name of the property with the field name
|
|
268
|
+
const memberName = member.name.getText();
|
|
269
|
+
if (memberName === fieldName) {
|
|
270
|
+
return updatedFieldNode!;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return member;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Update the class node with the new modifiers
|
|
277
|
+
const updatedClass = ts.factory.updateClassDeclaration(
|
|
278
|
+
sourceClassNode,
|
|
279
|
+
sourceClassNode.modifiers,
|
|
280
|
+
sourceClassNode.name,
|
|
281
|
+
sourceClassNode.typeParameters,
|
|
282
|
+
sourceClassNode.heritageClauses,
|
|
283
|
+
newMembers,
|
|
284
|
+
);
|
|
285
|
+
return updatedClass;
|
|
286
|
+
}
|
|
287
|
+
|
|
253
288
|
updateField(): FieldChange[] {
|
|
254
289
|
const fieldChanges: FieldChange[] = [];
|
|
255
290
|
|
|
@@ -257,7 +292,7 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
257
292
|
|
|
258
293
|
const fieldName = this.fieldName();
|
|
259
294
|
const fieldType = this.fieldType().node(this.field);
|
|
260
|
-
const source= this.source
|
|
295
|
+
const source = this.source
|
|
261
296
|
const field = this.field
|
|
262
297
|
const decoratorManagers = this.decoratorManagers;
|
|
263
298
|
|
|
@@ -365,7 +400,7 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
365
400
|
}
|
|
366
401
|
}
|
|
367
402
|
}
|
|
368
|
-
}
|
|
403
|
+
}
|
|
369
404
|
|
|
370
405
|
protected applyBuildDecoratorTransformations(...transformers: DecoratorManager[]): PartialAddFieldChange[] {
|
|
371
406
|
const partialFieldChanges: PartialAddFieldChange[] = [];
|
|
@@ -385,24 +420,24 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
385
420
|
}
|
|
386
421
|
}
|
|
387
422
|
|
|
388
|
-
protected calculateReplaceChanges(
|
|
423
|
+
protected calculateReplaceChanges(updatedSourceNodeText: string, sourceNode:ts.Node, sourceFileName: string): Change[] {
|
|
389
424
|
const changes: Change[] = [];
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
console.log(`Updated Code:\n${
|
|
393
|
-
console.log(`Old Code:\n${
|
|
425
|
+
if (updatedSourceNodeText.trim() !==
|
|
426
|
+
sourceNode.getFullText().trim()) {
|
|
427
|
+
console.log(`Updated Code:\n${updatedSourceNodeText.trim()}\nwith length ${updatedSourceNodeText.trim().length}\n`);
|
|
428
|
+
console.log(`Old Code:\n${sourceNode.getFullText().trim()}\nwith length ${sourceNode.getFullText().trim().length}\n`);
|
|
394
429
|
const replaceChange = new ReplaceChangeSSS(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
`\n\n${
|
|
430
|
+
sourceFileName,
|
|
431
|
+
sourceNode.pos,
|
|
432
|
+
sourceNode.getFullText(),
|
|
433
|
+
`\n\n${updatedSourceNodeText}`
|
|
399
434
|
);
|
|
400
435
|
changes.push(replaceChange);
|
|
401
436
|
}
|
|
402
437
|
return changes;
|
|
403
438
|
}
|
|
404
439
|
|
|
405
|
-
protected printNode(updatedPropertyDeclarationNode: ts.
|
|
440
|
+
protected printNode(updatedPropertyDeclarationNode: ts.Node, nodeSource: SourceFile): string {
|
|
406
441
|
const printer = ts.createPrinter({
|
|
407
442
|
newLine: ts.NewLineKind.LineFeed,
|
|
408
443
|
removeComments: false,
|
|
@@ -432,7 +467,7 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
432
467
|
case DecoratorType.MinLength:
|
|
433
468
|
return new MinLengthDecoratorManager({ isApplyMinLength: this.isApplyMinLength(), length: field.min, source: source, field: field });
|
|
434
469
|
case DecoratorType.MaxLength:
|
|
435
|
-
return new MaxLengthDecoratorManager({ isApplyMaxLength: this.isApplyMaxLength(), length: field.max, source: source, field: field });
|
|
470
|
+
return new MaxLengthDecoratorManager({ isApplyMaxLength: this.isApplyMaxLength(), length: field.max, source: source, field: field });
|
|
436
471
|
case DecoratorType.Required:
|
|
437
472
|
return new RequiredDecoratorManager({ isApplyRequired: true, required: field.required, source: source, field: field });
|
|
438
473
|
case DecoratorType.Optional:
|
|
@@ -447,7 +482,7 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
447
482
|
return new IntDecoratorManager({ isInt: this.isInt(), source: source, field: field });
|
|
448
483
|
case DecoratorType.Decimal:
|
|
449
484
|
return new DecimalDecoratorManager({ isDecimal: this.isDecimal(), source: source, field: field });
|
|
450
|
-
case DecoratorType.BigInt:
|
|
485
|
+
case DecoratorType.BigInt:
|
|
451
486
|
return new BigIntDecoratorManager({ isBigInt: this.isBigInt(), source: source, field: field });
|
|
452
487
|
case DecoratorType.Date:
|
|
453
488
|
return new DateDecoratorManager({ isDate: this.isDate(), source: source, field: field });
|
|
@@ -482,4 +517,17 @@ export abstract class BaseFieldManagerForDto implements FieldManager {
|
|
|
482
517
|
}
|
|
483
518
|
}
|
|
484
519
|
|
|
520
|
+
private getClassNode(modelName: any, options: ManagerForDtoOptions, source: ts.SourceFile) {
|
|
521
|
+
// if (this.updatedSourceClassNode) {
|
|
522
|
+
// return this.updatedSourceClassNode;
|
|
523
|
+
// }
|
|
524
|
+
const classifiedModelName = classify(modelName);
|
|
525
|
+
const sourceClassName = (options.sourceType === DtoSourceType.Create) ? `Create${classifiedModelName}Dto` : `Update${classifiedModelName}Dto`;
|
|
526
|
+
const classNode = getClassNode(sourceClassName, source);
|
|
527
|
+
if (!classNode) {
|
|
528
|
+
throw new Error(`Class ${sourceClassName} not found in file ${source.fileName}`);
|
|
529
|
+
}
|
|
530
|
+
return classNode;
|
|
531
|
+
}
|
|
532
|
+
|
|
485
533
|
}
|
|
@@ -28,6 +28,7 @@ import { JoinTableDecoratorManager } from '../../decorator-managers/entity/JoinT
|
|
|
28
28
|
import { RelationType } from "../../FieldManager";
|
|
29
29
|
import { UniqueIndexDecoratorManager } from '../../decorator-managers/entity/UniqueIndexDecoratorManager';
|
|
30
30
|
import { JoinColumnDecoratorManager } from '../../decorator-managers/entity/JoinColumnDecoratorManager';
|
|
31
|
+
import { OneToManyDecoratorManager } from '../../decorator-managers/entity/OneToManyDecoratorManager';
|
|
31
32
|
|
|
32
33
|
export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
33
34
|
source: SourceFile;
|
|
@@ -38,6 +39,7 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
38
39
|
manyToManyDecoratorManager: DecoratorManager;
|
|
39
40
|
joinTableDecoratorManager: DecoratorManager;
|
|
40
41
|
uniqueIndexDecoratorManager: UniqueIndexDecoratorManager;
|
|
42
|
+
oneToManyDecoratorManager: OneToManyDecoratorManager;
|
|
41
43
|
constructor(
|
|
42
44
|
tree: Tree,
|
|
43
45
|
protected readonly moduleName: string,
|
|
@@ -88,7 +90,7 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
88
90
|
);
|
|
89
91
|
this.joinColumnDecoratorManager = new JoinColumnDecoratorManager(
|
|
90
92
|
{
|
|
91
|
-
isManyToOneRelationOwner: this.
|
|
93
|
+
isManyToOneRelationOwner: this.isManyToOne(),
|
|
92
94
|
source: this.source,
|
|
93
95
|
field: this.field,
|
|
94
96
|
fieldName: this.fieldName(),
|
|
@@ -101,7 +103,7 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
101
103
|
relationModelName: this.field.relationModelSingularName,
|
|
102
104
|
relationInverseFieldName: this.field.relationModelFieldName,
|
|
103
105
|
relationCascade: this.field.relationCascade,
|
|
104
|
-
owner:
|
|
106
|
+
owner: this.field.isRelationManyToManyOwner,
|
|
105
107
|
source: this.source,
|
|
106
108
|
field: this.field,
|
|
107
109
|
fieldName: this.fieldName(),
|
|
@@ -110,7 +112,7 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
110
112
|
);
|
|
111
113
|
this.joinTableDecoratorManager = new JoinTableDecoratorManager(
|
|
112
114
|
{
|
|
113
|
-
isManyToManyRelationOwner: this.
|
|
115
|
+
isManyToManyRelationOwner: this.isManyToMany() && this.field.isRelationManyToManyOwner,
|
|
114
116
|
source: this.source,
|
|
115
117
|
field: this.field,
|
|
116
118
|
fieldName: this.fieldName(),
|
|
@@ -124,6 +126,17 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
124
126
|
{ unique: this.field.unique, fieldName: this.fieldName(), source: this.source, field: this.field },
|
|
125
127
|
this.getClassNode(this.modelName, this.source)
|
|
126
128
|
);
|
|
129
|
+
this.oneToManyDecoratorManager = new OneToManyDecoratorManager(
|
|
130
|
+
{
|
|
131
|
+
isOneToMany: this.isOneToMany(),
|
|
132
|
+
relationCascade: this.field.relationCascade,
|
|
133
|
+
source: this.source,
|
|
134
|
+
field: this.field,
|
|
135
|
+
fieldName: this.fieldName(),
|
|
136
|
+
modelName: this.modelName,
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
|
|
127
140
|
}
|
|
128
141
|
|
|
129
142
|
protected addFieldInternal(fieldName: string, fieldType: string, decoratorManagers: DecoratorManager[], field: any, modelName: any, source: ts.SourceFile): FieldChange {
|
|
@@ -452,6 +465,9 @@ export abstract class BaseFieldManagerForEntity implements FieldManager {
|
|
|
452
465
|
return (this.field.type === 'relation' && this.field.relationType === RelationType.ManyToOne);
|
|
453
466
|
}
|
|
454
467
|
|
|
468
|
+
private isOneToMany(): boolean {
|
|
469
|
+
return (this.field.type === 'relation' && this.field.relationType === RelationType.OneToMany);
|
|
470
|
+
}
|
|
455
471
|
|
|
456
472
|
|
|
457
473
|
protected isAdditionalFieldRequired(): boolean {
|