@solidstarters/solid-code-builder 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.d.ts +4 -0
- package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.js +61 -2
- package/dist/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.js.map +1 -1
- package/dist/files/generate-model/services/__model@dasherize__.service.ts +4 -4
- package/files/generate-model/services/__model@dasherize__.service.ts +4 -4
- package/package.json +5 -2
- package/publish.js +16 -0
- package/src/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.ts +71 -2
- package/dto_additional_fields_duplicate_fix.diff +0 -40
- package/src/code-builder/index.js +0 -178
- package/src/code-builder/index_spec.js +0 -46
- package/src/code-builder/lib/field/FieldManager.js +0 -236
- package/src/code-builder/lib/field/decorator-managers/dto/ArrayDecoratorManager.js +0 -107
- package/src/code-builder/lib/field/decorator-managers/dto/BigIntDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/BooleanDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/DateDecoratorManager.js +0 -106
- package/src/code-builder/lib/field/decorator-managers/dto/DecimalDecoratorManager.js +0 -112
- package/src/code-builder/lib/field/decorator-managers/dto/EmailDecoratorManager.js +0 -99
- package/src/code-builder/lib/field/decorator-managers/dto/IntDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/JsonDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/LengthDecoratorManager.js +0 -104
- package/src/code-builder/lib/field/decorator-managers/dto/MaxDecoratorManager.js +0 -103
- package/src/code-builder/lib/field/decorator-managers/dto/MaxLengthDecoratorManager.js +0 -103
- package/src/code-builder/lib/field/decorator-managers/dto/MinDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/MinLengthDecoratorManager.js +0 -103
- package/src/code-builder/lib/field/decorator-managers/dto/NumberDecoratorManager.js +0 -112
- package/src/code-builder/lib/field/decorator-managers/dto/OptionalDecoratorManager.js +0 -104
- package/src/code-builder/lib/field/decorator-managers/dto/RegexDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/RequiredDecoratorManager.js +0 -100
- package/src/code-builder/lib/field/decorator-managers/dto/StringDecoratorManager.js +0 -99
- package/src/code-builder/lib/field/decorator-managers/dto/TransformDecoratorManager.js +0 -102
- package/src/code-builder/lib/field/decorator-managers/dto/ValidateNestedDecoratorManager.js +0 -140
- package/src/code-builder/lib/field/decorator-managers/entity/ColumnDecoratorManager.js +0 -178
- package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +0 -79
- package/src/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js +0 -118
- package/src/code-builder/lib/field/decorator-managers/entity/ManyToManyDecoratorManager.js +0 -175
- package/src/code-builder/lib/field/decorator-managers/entity/ManyToOneDecoratorManager.js +0 -179
- package/src/code-builder/lib/field/decorator-managers/entity/OneToManyDecoratorManager.js +0 -155
- package/src/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js +0 -174
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +0 -345
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +0 -373
- package/src/code-builder/lib/field/field-managers/base/DeleteType.js +0 -11
- package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForDto.js +0 -81
- package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForEntity.js +0 -55
- package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForDto.js +0 -75
- package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForEntity.js +0 -51
- package/src/code-builder/lib/field/field-managers/computed/ComputedFieldHandler.js +0 -30
- package/src/code-builder/lib/field/field-managers/computed/ComputedFieldManagerForEntity.js +0 -33
- package/src/code-builder/lib/field/field-managers/date/DateFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForDto.js +0 -81
- package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForEntity.js +0 -59
- package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForDto.js +0 -77
- package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForEntity.js +0 -53
- package/src/code-builder/lib/field/field-managers/email/EmailFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForDto.js +0 -72
- package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForEntity.js +0 -44
- package/src/code-builder/lib/field/field-managers/int/IntFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForDto.js +0 -76
- package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForEntity.js +0 -52
- package/src/code-builder/lib/field/field-managers/json/JsonFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForDto.js +0 -57
- package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForEntity.js +0 -21
- package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForDto.js +0 -63
- package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForEntity.js +0 -34
- package/src/code-builder/lib/field/field-managers/media/MediaFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForDto.js +0 -72
- package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForEntity.js +0 -57
- package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldHandler.js +0 -27
- package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForDto.js +0 -75
- package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForEntity.js +0 -35
- package/src/code-builder/lib/field/field-managers/password/PasswordFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForDto.js +0 -121
- package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForEntity.js +0 -37
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +0 -366
- package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -158
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldHandler.js +0 -33
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +0 -294
- package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +0 -177
- package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForDto.js +0 -63
- package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForEntity.js +0 -34
- package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForDto.js +0 -63
- package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForEntity.js +0 -37
- package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldHandler.js +0 -34
- package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForDto.js +0 -15
- package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForEntity.js +0 -33
- package/src/code-builder/lib/model/helpers.js +0 -407
|
@@ -1,79 +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.IndexDecoratorManager = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const FieldManager_1 = require("../../FieldManager");
|
|
9
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
10
|
-
class IndexDecoratorManager {
|
|
11
|
-
constructor(options, fieldNode) {
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.fieldNode = fieldNode;
|
|
14
|
-
}
|
|
15
|
-
isApplyDecorator() {
|
|
16
|
-
return this.options.index && this.options.field.relationType !== FieldManager_1.RelationType.ManyToMany;
|
|
17
|
-
}
|
|
18
|
-
decoratorName() {
|
|
19
|
-
return 'Index';
|
|
20
|
-
}
|
|
21
|
-
setFieldNode(fieldNode) {
|
|
22
|
-
this.fieldNode = fieldNode;
|
|
23
|
-
}
|
|
24
|
-
buildDecorator() {
|
|
25
|
-
const fieldSourceLines = [];
|
|
26
|
-
const changes = [];
|
|
27
|
-
// if (this.field.index) {
|
|
28
|
-
const indexDecoratorLine = `@Index()`;
|
|
29
|
-
fieldSourceLines.push(indexDecoratorLine);
|
|
30
|
-
changes.push(...this.decoratorImports());
|
|
31
|
-
// }
|
|
32
|
-
return {
|
|
33
|
-
filePath: this.options.source.fileName,
|
|
34
|
-
field: this.options.field,
|
|
35
|
-
changes: changes,
|
|
36
|
-
fieldSourceLines: fieldSourceLines,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
decoratorImports() {
|
|
40
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'typeorm')];
|
|
41
|
-
}
|
|
42
|
-
//Updates the index decorator for the fieldNode based on the options provided
|
|
43
|
-
// @returns the updated property declaration
|
|
44
|
-
updateDecorator() {
|
|
45
|
-
if (!this.fieldNode)
|
|
46
|
-
throw new Error('Field node is required for updating the index decorator');
|
|
47
|
-
let newModifiers = [];
|
|
48
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
49
|
-
//Remove the Index decorator if the Index decorator exists
|
|
50
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
51
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
52
|
-
//Add the column decorator if column decorator is required
|
|
53
|
-
const changes = [];
|
|
54
|
-
if (this.isApplyDecorator()) {
|
|
55
|
-
newModifiers = [...newModifiers, this.createIndexDecorator()];
|
|
56
|
-
changes.push(...this.decoratorImports());
|
|
57
|
-
}
|
|
58
|
-
//If index decorator is present & index is required, no need to update the index decorator
|
|
59
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //newModifiers contains the updated index decorator
|
|
60
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
61
|
-
return [updatedProperty, changes];
|
|
62
|
-
}
|
|
63
|
-
createIndexDecorator() {
|
|
64
|
-
return typescript_1.default.factory.createDecorator(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier('Index'), undefined, []));
|
|
65
|
-
}
|
|
66
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
67
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
68
|
-
}
|
|
69
|
-
filterNonDecorators(existingModifiers) {
|
|
70
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
71
|
-
}
|
|
72
|
-
containsIdentifierName(m, identifierName) {
|
|
73
|
-
const callExpression = m.expression;
|
|
74
|
-
const identifier = callExpression.expression;
|
|
75
|
-
return identifier.text === identifierName;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.IndexDecoratorManager = IndexDecoratorManager;
|
|
79
|
-
//# sourceMappingURL=IndexDecoratorManager.js.map
|
|
@@ -1,118 +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.JoinTableDecoratorManager = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
8
|
-
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
9
|
-
class JoinTableDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isManyToManyRelationOwner;
|
|
16
|
-
}
|
|
17
|
-
decoratorName() {
|
|
18
|
-
return 'JoinTable';
|
|
19
|
-
}
|
|
20
|
-
buildDecorator() {
|
|
21
|
-
const changes = [];
|
|
22
|
-
const fieldSourceLines = [];
|
|
23
|
-
// Add the many-to-many import
|
|
24
|
-
// const decoratorImport = insertImport(
|
|
25
|
-
// this.options.source,
|
|
26
|
-
// this.options.source.fileName,
|
|
27
|
-
// this.decoratorName(),
|
|
28
|
-
// 'typeorm',
|
|
29
|
-
// );
|
|
30
|
-
// if (decoratorImport) {
|
|
31
|
-
// changes.push(decoratorImport);
|
|
32
|
-
// }
|
|
33
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
34
|
-
changes.push(...this.decoratorImports());
|
|
35
|
-
return {
|
|
36
|
-
filePath: this.options.source.fileName,
|
|
37
|
-
field: this.options.field,
|
|
38
|
-
changes: changes,
|
|
39
|
-
fieldSourceLines: fieldSourceLines,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
decoratorImports() {
|
|
43
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'typeorm')];
|
|
44
|
-
}
|
|
45
|
-
setFieldNode(fieldNode) {
|
|
46
|
-
this.fieldNode = fieldNode;
|
|
47
|
-
}
|
|
48
|
-
updateDecorator() {
|
|
49
|
-
// Check if the field property declaration exists, if not throw an error
|
|
50
|
-
if (!this.fieldNode)
|
|
51
|
-
throw new Error('Field node is required for updating the one to many decorator');
|
|
52
|
-
let newModifiers = [];
|
|
53
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
54
|
-
// Check if field has an existing one-to-many relation decorator
|
|
55
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
56
|
-
//Remove the many-to-one decorator if it exists
|
|
57
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
58
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
59
|
-
//Add the one-to-many decorator if it is required
|
|
60
|
-
const changes = [];
|
|
61
|
-
if (this.isApplyDecorator()) {
|
|
62
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
63
|
-
changes.push(...this.decoratorImports());
|
|
64
|
-
}
|
|
65
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
66
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
67
|
-
return [updatedProperty, changes];
|
|
68
|
-
}
|
|
69
|
-
createDecorator(existingDecorator) {
|
|
70
|
-
let existingRelationOptions = this.existingDecoratorOptions(existingDecorator);
|
|
71
|
-
// const mergedRelationOptions: ObjectLiteralElementLike[] = this.mergeNewAndExistingDecoratorOptions(existingRelationOptions);
|
|
72
|
-
// Re-create the decorator with the merged decorator options
|
|
73
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
74
|
-
const argumentsArray = this.createDecoratorArguments(existingRelationOptions);
|
|
75
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
76
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
77
|
-
}
|
|
78
|
-
createDecoratorArguments(joinTableOptions) {
|
|
79
|
-
const argumentsArray = [];
|
|
80
|
-
if (joinTableOptions.length > 0) {
|
|
81
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(joinTableOptions);
|
|
82
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
83
|
-
}
|
|
84
|
-
return argumentsArray;
|
|
85
|
-
}
|
|
86
|
-
existingDecoratorOptions(existingDecorator) {
|
|
87
|
-
let existingDecoratorPropertyAssignments = [];
|
|
88
|
-
if (existingDecorator !== undefined) {
|
|
89
|
-
//Pre-set the relation options from the existing relation decorator
|
|
90
|
-
const existingCallExpression = existingDecorator.expression;
|
|
91
|
-
// Check if call expression has at least 1 arguments
|
|
92
|
-
if (existingCallExpression.arguments.length > 0) { //Because we are interested in the 1st argument, we check for length > 0
|
|
93
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
94
|
-
throw new Error('JoinTable decorator 1st argument must be an object literal containing the joinTable options');
|
|
95
|
-
}
|
|
96
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
97
|
-
existingDecoratorPropertyAssignments.push(...existingObjectLiteralExpression.properties);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return existingDecoratorPropertyAssignments;
|
|
101
|
-
}
|
|
102
|
-
findDecorator(name, existingModifiers) {
|
|
103
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
104
|
-
}
|
|
105
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
106
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
107
|
-
}
|
|
108
|
-
filterNonDecorators(existingModifiers) {
|
|
109
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
110
|
-
}
|
|
111
|
-
containsIdentifierName(m, identifierName) {
|
|
112
|
-
const callExpression = m.expression;
|
|
113
|
-
const identifier = callExpression.expression;
|
|
114
|
-
return identifier.text === identifierName;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.JoinTableDecoratorManager = JoinTableDecoratorManager;
|
|
118
|
-
//# sourceMappingURL=JoinTableDecoratorManager.js.map
|
|
@@ -1,175 +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.ManyToManyDecoratorManager = 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
|
-
class ManyToManyDecoratorManager {
|
|
11
|
-
constructor(options, fieldNode) {
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.fieldNode = fieldNode;
|
|
14
|
-
}
|
|
15
|
-
isApplyDecorator() {
|
|
16
|
-
return this.options.isManyToMany;
|
|
17
|
-
}
|
|
18
|
-
decoratorName() {
|
|
19
|
-
return 'ManyToMany';
|
|
20
|
-
}
|
|
21
|
-
buildDecorator() {
|
|
22
|
-
const changes = [];
|
|
23
|
-
const fieldSourceLines = [];
|
|
24
|
-
// Add the many-to-many import
|
|
25
|
-
// const decoratorImport = insertImport(
|
|
26
|
-
// this.options.source,
|
|
27
|
-
// this.options.source.fileName,
|
|
28
|
-
// this.decoratorName(),
|
|
29
|
-
// 'typeorm',
|
|
30
|
-
// );
|
|
31
|
-
changes.push(...this.decoratorImports());
|
|
32
|
-
// if (decoratorImport) {
|
|
33
|
-
// changes.push(decoratorImport);
|
|
34
|
-
// }
|
|
35
|
-
const fieldSourceLineComponents = [];
|
|
36
|
-
fieldSourceLineComponents.push(`() => ${(0, strings_1.classify)(this.options.relationModelName)}`);
|
|
37
|
-
this.options.relationInverseFieldName ? fieldSourceLineComponents.push(`${(0, strings_1.camelize)(this.options.relationModelName)} => ${(0, strings_1.camelize)(this.options.relationModelName)}.${this.options.relationInverseFieldName}`) : "no-ops";
|
|
38
|
-
fieldSourceLineComponents.push(`${this.buildRelationOptionsCode()}`);
|
|
39
|
-
fieldSourceLines.push(`@${this.decoratorName()}(${fieldSourceLineComponents.join(', ')})`);
|
|
40
|
-
return {
|
|
41
|
-
filePath: this.options.source.fileName,
|
|
42
|
-
field: this.options.field,
|
|
43
|
-
changes: changes,
|
|
44
|
-
fieldSourceLines: fieldSourceLines,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
setFieldNode(fieldNode) {
|
|
48
|
-
this.fieldNode = fieldNode;
|
|
49
|
-
}
|
|
50
|
-
decoratorImports() {
|
|
51
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'typeorm')];
|
|
52
|
-
}
|
|
53
|
-
updateDecorator() {
|
|
54
|
-
// Check if the field property declaration exists, if not throw an error
|
|
55
|
-
if (!this.fieldNode)
|
|
56
|
-
throw new Error('Field node is required for updating the one to many decorator');
|
|
57
|
-
let newModifiers = [];
|
|
58
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
59
|
-
// Check if field has an existing one-to-many relation decorator
|
|
60
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
61
|
-
//Remove the many-to-one decorator if it exists
|
|
62
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
63
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
64
|
-
//Add the one-to-many decorator if it is required
|
|
65
|
-
const changes = [];
|
|
66
|
-
if (this.isApplyDecorator()) {
|
|
67
|
-
newModifiers = [...newModifiers, this.createRelationDecorator(existingDecorator)];
|
|
68
|
-
changes.push(...this.decoratorImports());
|
|
69
|
-
}
|
|
70
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
71
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
72
|
-
return [updatedProperty, changes];
|
|
73
|
-
}
|
|
74
|
-
buildRelationOptionsCode() {
|
|
75
|
-
const relationOptions = new Map();
|
|
76
|
-
// this.options.owner ? relationOptions.set('cascade', true): "no-ops";
|
|
77
|
-
this.options.owner ? relationOptions.set('cascade', true) : relationOptions.set('cascade', ['insert', 'update']);
|
|
78
|
-
const decoratorArgs = Array.from(relationOptions)
|
|
79
|
-
.map(([key, value]) => {
|
|
80
|
-
if (Array.isArray(value)) {
|
|
81
|
-
return `${key}: [${value.map(v => `'${v}'`).join(', ')}]`;
|
|
82
|
-
}
|
|
83
|
-
return `${key}: ${value}`;
|
|
84
|
-
})
|
|
85
|
-
.join(', ');
|
|
86
|
-
// Convert the map to a string
|
|
87
|
-
return `{ ${decoratorArgs} }`;
|
|
88
|
-
}
|
|
89
|
-
createRelationDecorator(existingRelationDecorator) {
|
|
90
|
-
let existingRelationOptions = this.existingDecoratorOptions(existingRelationDecorator);
|
|
91
|
-
const mergedRelationOptions = this.mergeNewAndExistingDecoratorOptions(existingRelationOptions);
|
|
92
|
-
// Re-create the decorator with the merged decorator options
|
|
93
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
94
|
-
const argumentsArray = this.createDecoratorArguments(mergedRelationOptions);
|
|
95
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
96
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
97
|
-
}
|
|
98
|
-
mergeNewAndExistingDecoratorOptions(existingRelationOptions) {
|
|
99
|
-
const decoratorOptions = this.createRelationDecoratorOptions();
|
|
100
|
-
const newPropertyAssignments = Array.from(decoratorOptions.values()).filter(p => p !== null);
|
|
101
|
-
// console.log('newPropertyAssignments', newPropertyAssignments.map(p => JSON.stringify(p.name)).join(', '));
|
|
102
|
-
// Add the other unhandled column decorator options
|
|
103
|
-
const handledDecoratorOptions = Array.from(decoratorOptions.keys());
|
|
104
|
-
//@ts-ignore
|
|
105
|
-
const otherPropertyAssignments = existingRelationOptions.filter(ps => { var _a; return !handledDecoratorOptions.includes((_a = ps.name) === null || _a === void 0 ? void 0 : _a.escapedText); });
|
|
106
|
-
newPropertyAssignments.push(...otherPropertyAssignments);
|
|
107
|
-
return newPropertyAssignments;
|
|
108
|
-
}
|
|
109
|
-
createDecoratorArguments(newPropertyAssignments) {
|
|
110
|
-
const argumentsArray = [];
|
|
111
|
-
// 1st Argument: Target
|
|
112
|
-
const typeFunctionOrTarget = typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createIdentifier((0, strings_1.classify)(this.options.relationModelName)));
|
|
113
|
-
argumentsArray.push(typeFunctionOrTarget);
|
|
114
|
-
if (this.options.relationInverseFieldName) {
|
|
115
|
-
// 2nd Argument: Inverse side
|
|
116
|
-
const inverseSide = typescript_1.default.factory.createArrowFunction(undefined, undefined, [typescript_1.default.factory.createParameterDeclaration(undefined, undefined, typescript_1.default.factory.createIdentifier((0, strings_1.camelize)(this.options.relationModelName)), undefined, undefined, undefined)], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier((0, strings_1.camelize)(this.options.relationModelName)), typescript_1.default.factory.createIdentifier(this.options.relationInverseFieldName)));
|
|
117
|
-
argumentsArray.push(inverseSide);
|
|
118
|
-
}
|
|
119
|
-
// 3rd Argument: Options. This argument is optional
|
|
120
|
-
if (newPropertyAssignments.length > 0) {
|
|
121
|
-
const decoratorOptions = typescript_1.default.factory.createObjectLiteralExpression(newPropertyAssignments);
|
|
122
|
-
argumentsArray.push(decoratorOptions);
|
|
123
|
-
}
|
|
124
|
-
return argumentsArray;
|
|
125
|
-
}
|
|
126
|
-
existingDecoratorOptions(existingRelationDecorator) {
|
|
127
|
-
let existingRelationDecoratorPropertyAssignments = [];
|
|
128
|
-
if (existingRelationDecorator !== undefined) {
|
|
129
|
-
//Pre-set the relation options from the existing relation decorator
|
|
130
|
-
const existingCallExpression = existingRelationDecorator.expression;
|
|
131
|
-
// Check if call expression has at least 1 arguments
|
|
132
|
-
if (existingCallExpression.arguments.length > 2) { //Because we are interested in the 2nd argument, we check for length > 1
|
|
133
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[2])) {
|
|
134
|
-
throw new Error('Many-to-Many decorator 3rd argument must be an object literal containing the relation options');
|
|
135
|
-
}
|
|
136
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[2];
|
|
137
|
-
existingRelationDecoratorPropertyAssignments.push(...existingObjectLiteralExpression.properties);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return existingRelationDecoratorPropertyAssignments;
|
|
141
|
-
}
|
|
142
|
-
createRelationDecoratorOptions() {
|
|
143
|
-
const relationOptions = new Map();
|
|
144
|
-
this.options.owner ? relationOptions.set('cascade', typescript_1.default.factory.createTrue()) : "no-ops";
|
|
145
|
-
return this.optionsToPropertyAssignmentsOrNull(relationOptions);
|
|
146
|
-
}
|
|
147
|
-
optionsToPropertyAssignmentsOrNull(options) {
|
|
148
|
-
const decoratorOptions = new Map();
|
|
149
|
-
options.forEach((value, key) => {
|
|
150
|
-
if (value !== null) {
|
|
151
|
-
decoratorOptions.set(key, typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), value));
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
decoratorOptions.set(key, null);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
return decoratorOptions;
|
|
158
|
-
}
|
|
159
|
-
findDecorator(name, existingModifiers) {
|
|
160
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
161
|
-
}
|
|
162
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
163
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
164
|
-
}
|
|
165
|
-
filterNonDecorators(existingModifiers) {
|
|
166
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
167
|
-
}
|
|
168
|
-
containsIdentifierName(m, identifierName) {
|
|
169
|
-
const callExpression = m.expression;
|
|
170
|
-
const identifier = callExpression.expression;
|
|
171
|
-
return identifier.text === identifierName;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
exports.ManyToManyDecoratorManager = ManyToManyDecoratorManager;
|
|
175
|
-
//# sourceMappingURL=ManyToManyDecoratorManager.js.map
|
|
@@ -1,179 +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.ManyToOneDecoratorManager = 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 lodash_1 = __importDefault(require("lodash"));
|
|
11
|
-
class ManyToOneDecoratorManager {
|
|
12
|
-
constructor(options, fieldNode) {
|
|
13
|
-
this.options = options;
|
|
14
|
-
this.fieldNode = fieldNode;
|
|
15
|
-
}
|
|
16
|
-
isApplyDecorator() {
|
|
17
|
-
return this.options.isManyToOne;
|
|
18
|
-
}
|
|
19
|
-
decoratorName() {
|
|
20
|
-
return 'ManyToOne';
|
|
21
|
-
}
|
|
22
|
-
buildDecorator() {
|
|
23
|
-
const changes = [];
|
|
24
|
-
const fieldSourceLines = [];
|
|
25
|
-
// Add the ManyToOne import
|
|
26
|
-
// const relationImports = insertImport(
|
|
27
|
-
// this.options.source,
|
|
28
|
-
// this.options.source.fileName,
|
|
29
|
-
// this.decoratorName(),
|
|
30
|
-
// 'typeorm',
|
|
31
|
-
// );
|
|
32
|
-
// if (relationImports) {
|
|
33
|
-
// changes.push(relationImports);
|
|
34
|
-
// }
|
|
35
|
-
// Add the relation decorator
|
|
36
|
-
fieldSourceLines.push(`@${this.decoratorName()}(() => ${(0, strings_1.classify)(this.options.relationModelSingularName)}, ${this.buildRelationOptionsCode()})`);
|
|
37
|
-
changes.push(...this.decoratorImports());
|
|
38
|
-
return {
|
|
39
|
-
filePath: this.options.source.fileName,
|
|
40
|
-
field: this.options.field,
|
|
41
|
-
changes: changes,
|
|
42
|
-
fieldSourceLines: fieldSourceLines,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
setFieldNode(fieldNode) {
|
|
46
|
-
this.fieldNode = fieldNode;
|
|
47
|
-
}
|
|
48
|
-
decoratorImports() {
|
|
49
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'typeorm')];
|
|
50
|
-
}
|
|
51
|
-
updateDecorator() {
|
|
52
|
-
// Check if the field property declaration exists, if not throw an error
|
|
53
|
-
if (!this.fieldNode)
|
|
54
|
-
throw new Error('Field node is required for updating the index decorator');
|
|
55
|
-
let newModifiers = [];
|
|
56
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
57
|
-
// Check if field has an existing many-to-one relation decorator
|
|
58
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
59
|
-
//Remove the many-to-one decorator if it exists
|
|
60
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
61
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
62
|
-
//Add the many-to-one decorator if it is required
|
|
63
|
-
const changes = [];
|
|
64
|
-
if (this.isApplyDecorator()) {
|
|
65
|
-
newModifiers = [...newModifiers, this.createRelationDecorator(existingDecorator)];
|
|
66
|
-
changes.push(...this.decoratorImports());
|
|
67
|
-
}
|
|
68
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
69
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
70
|
-
return [updatedProperty, changes];
|
|
71
|
-
}
|
|
72
|
-
buildRelationOptionsCode() {
|
|
73
|
-
const options = this.buildRelationDecoratorOptions();
|
|
74
|
-
const keys = Array.from(options.keys());
|
|
75
|
-
const optionsString = keys
|
|
76
|
-
.filter((key) => options.get(key) !== null)
|
|
77
|
-
.map((key) => {
|
|
78
|
-
if (typeof options.get(key) === 'string') {
|
|
79
|
-
return `${key}: "${options.get(key)}"`;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return `${key}: ${options.get(key)}`;
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
.join(', ');
|
|
86
|
-
return `{ ${optionsString} }`;
|
|
87
|
-
}
|
|
88
|
-
buildRelationDecoratorOptions() {
|
|
89
|
-
const options = new Map();
|
|
90
|
-
//Set common options
|
|
91
|
-
// onDelete option
|
|
92
|
-
if (!lodash_1.default.isEmpty(this.options.relationCascade)) {
|
|
93
|
-
const cascade = this.options.relationCascade.toUpperCase();
|
|
94
|
-
const onDeleteType = cascade;
|
|
95
|
-
options.set('onDelete', onDeleteType);
|
|
96
|
-
}
|
|
97
|
-
// nullable option
|
|
98
|
-
if (!this.options.required) {
|
|
99
|
-
options.set('nullable', true);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
options.set('nullable', false);
|
|
103
|
-
}
|
|
104
|
-
return options;
|
|
105
|
-
}
|
|
106
|
-
createRelationDecorator(existingRelationDecorator) {
|
|
107
|
-
// console.log('createRelationDecorator called with ....', existingRelationDecorator?.getText());
|
|
108
|
-
// Capture the existing relation decorator options
|
|
109
|
-
let existingRelationDecoratorPropertyAssignments = [];
|
|
110
|
-
if (existingRelationDecorator !== undefined) {
|
|
111
|
-
//Pre-set the relation options from the existing relation decorator
|
|
112
|
-
const existingCallExpression = existingRelationDecorator.expression;
|
|
113
|
-
// Check if call expression has at least 1 arguments
|
|
114
|
-
if (existingCallExpression.arguments.length > 1) { //Because we are interested in the 2nd argument, we check for length > 1
|
|
115
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
|
|
116
|
-
throw new Error('ManyToOne decorator 2nd arguments must be an object literal containing the relation options');
|
|
117
|
-
}
|
|
118
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[1];
|
|
119
|
-
existingRelationDecoratorPropertyAssignments.push(...existingObjectLiteralExpression.properties);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// Create the new relation decorator options
|
|
123
|
-
const decoratorOptions = this.createRelationDecoratorOptions();
|
|
124
|
-
const newPropertyAssignments = Array.from(decoratorOptions.values()).filter(p => p !== null);
|
|
125
|
-
// console.log('newPropertyAssignments', newPropertyAssignments.map(p => JSON.stringify(p.name)).join(', '));
|
|
126
|
-
// Add the other unhandled column decorator options
|
|
127
|
-
const handledDecoratorOptions = Array.from(decoratorOptions.keys());
|
|
128
|
-
//@ts-ignore
|
|
129
|
-
const otherPropertyAssignments = existingRelationDecoratorPropertyAssignments.filter(ps => { var _a; return !handledDecoratorOptions.includes((_a = ps.name) === null || _a === void 0 ? void 0 : _a.escapedText); });
|
|
130
|
-
newPropertyAssignments.push(...otherPropertyAssignments);
|
|
131
|
-
// Re-create the relation decorator with the merged relation decorator options
|
|
132
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
133
|
-
const typeFunctionOrTarget = typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createIdentifier((0, strings_1.classify)(this.options.relationModelSingularName)));
|
|
134
|
-
const decoratorOptionsExpression = typescript_1.default.factory.createObjectLiteralExpression(newPropertyAssignments);
|
|
135
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, [typeFunctionOrTarget, decoratorOptionsExpression]);
|
|
136
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
137
|
-
}
|
|
138
|
-
createRelationDecoratorOptions() {
|
|
139
|
-
const options = new Map();
|
|
140
|
-
const cascade = this.options.relationCascade.toUpperCase();
|
|
141
|
-
const onDeleteType = cascade;
|
|
142
|
-
options.set('onDelete', typescript_1.default.factory.createStringLiteral(onDeleteType));
|
|
143
|
-
if (!this.options.required) {
|
|
144
|
-
options.set('nullable', typescript_1.default.factory.createTrue());
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
options.set('nullable', typescript_1.default.factory.createFalse());
|
|
148
|
-
}
|
|
149
|
-
return this.optionsToPropertyAssignmentsOrNull(options);
|
|
150
|
-
}
|
|
151
|
-
optionsToPropertyAssignmentsOrNull(options) {
|
|
152
|
-
const decoratorOptions = new Map();
|
|
153
|
-
options.forEach((value, key) => {
|
|
154
|
-
if (value !== null) {
|
|
155
|
-
decoratorOptions.set(key, typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), value));
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
decoratorOptions.set(key, null);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
return decoratorOptions;
|
|
162
|
-
}
|
|
163
|
-
findDecorator(name, existingModifiers) {
|
|
164
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
165
|
-
}
|
|
166
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
167
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
168
|
-
}
|
|
169
|
-
filterNonDecorators(existingModifiers) {
|
|
170
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
171
|
-
}
|
|
172
|
-
containsIdentifierName(m, identifierName) {
|
|
173
|
-
const callExpression = m.expression;
|
|
174
|
-
const identifier = callExpression.expression;
|
|
175
|
-
return identifier.text === identifierName;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.ManyToOneDecoratorManager = ManyToOneDecoratorManager;
|
|
179
|
-
//# sourceMappingURL=ManyToOneDecoratorManager.js.map
|