@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,155 +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.OneToManyDecoratorManager = 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 OneToManyDecoratorManager {
11
- constructor(options, fieldNode) {
12
- this.options = options;
13
- this.fieldNode = fieldNode;
14
- }
15
- isApplyDecorator() {
16
- return this.options.isOneToMany;
17
- }
18
- decoratorName() {
19
- return 'OneToMany';
20
- }
21
- buildDecorator() {
22
- const changes = [];
23
- const fieldSourceLines = [];
24
- // Add the one-to-many import
25
- // const oneToManyImport = insertImport(
26
- // this.options.source,
27
- // this.options.source.fileName,
28
- // this.decoratorName(),
29
- // 'typeorm',
30
- // );
31
- // if (oneToManyImport) {
32
- // changes.push(oneToManyImport);
33
- // }
34
- fieldSourceLines.push(`@${this.decoratorName()}(() => ${(0, strings_1.classify)(this.options.modelName)}, ${(0, strings_1.camelize)(this.options.modelName)} => ${(0, strings_1.camelize)(this.options.modelName)}.${this.options.fieldName}, ${this.buildRelationOptionsCode()})`);
35
- changes.push(...this.decoratorImports());
36
- return {
37
- filePath: this.options.source.fileName,
38
- field: this.options.field,
39
- changes: changes,
40
- fieldSourceLines: fieldSourceLines,
41
- };
42
- }
43
- setFieldNode(fieldNode) {
44
- this.fieldNode = fieldNode;
45
- }
46
- decoratorImports() {
47
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'typeorm')];
48
- }
49
- updateDecorator() {
50
- // Check if the field property declaration exists, if not throw an error
51
- if (!this.fieldNode)
52
- throw new Error('Field node is required for updating the one to many decorator');
53
- let newModifiers = [];
54
- let existingModifiers = this.fieldNode.modifiers;
55
- // Check if field has an existing one-to-many relation decorator
56
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
57
- //Remove the many-to-one decorator if it exists
58
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
59
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
60
- //Add the one-to-many decorator if it is required
61
- const changes = [];
62
- if (this.isApplyDecorator()) {
63
- newModifiers = [...newModifiers, this.createRelationDecorator(existingDecorator)];
64
- changes.push(...this.decoratorImports());
65
- }
66
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
67
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
68
- return [updatedProperty, changes];
69
- }
70
- buildRelationOptionsCode() {
71
- return `{ cascade: true }`;
72
- }
73
- createRelationDecorator(existingRelationDecorator) {
74
- // Capture the existing relation decorator options
75
- let existingRelationDecoratorPropertyAssignments = this.existingDecoratorOptions(existingRelationDecorator);
76
- // Create the new relation decorator options
77
- const decoratorOptions = this.createRelationDecoratorOptions();
78
- const newPropertyAssignments = Array.from(decoratorOptions.values()).filter(p => p !== null);
79
- // console.log('newPropertyAssignments', newPropertyAssignments.map(p => JSON.stringify(p.name)).join(', '));
80
- // Add the other unhandled column decorator options
81
- const handledDecoratorOptions = Array.from(decoratorOptions.keys());
82
- //@ts-ignore
83
- const otherPropertyAssignments = existingRelationDecoratorPropertyAssignments.filter(ps => { var _a; return !handledDecoratorOptions.includes((_a = ps.name) === null || _a === void 0 ? void 0 : _a.escapedText); });
84
- newPropertyAssignments.push(...otherPropertyAssignments);
85
- // Re-create the relation decorator with the merged relation decorator options
86
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
87
- const argumentsArray = this.createDecoratorArguments(newPropertyAssignments);
88
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
89
- return typescript_1.default.factory.createDecorator(call);
90
- }
91
- createDecoratorArguments(newPropertyAssignments) {
92
- const argumentsArray = [];
93
- // 1st Argument: Target
94
- 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.modelName)));
95
- argumentsArray.push(typeFunctionOrTarget);
96
- // 2nd Argument: Inverse side
97
- 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.modelName)), 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.modelName)), typescript_1.default.factory.createIdentifier(this.options.fieldName)));
98
- argumentsArray.push(inverseSide);
99
- // 3rd Argument: Options. This argument is optional
100
- if (newPropertyAssignments.length > 0) {
101
- const decoratorOptions = typescript_1.default.factory.createObjectLiteralExpression(newPropertyAssignments);
102
- argumentsArray.push(decoratorOptions);
103
- }
104
- return argumentsArray;
105
- }
106
- existingDecoratorOptions(existingRelationDecorator) {
107
- let existingRelationDecoratorPropertyAssignments = [];
108
- if (existingRelationDecorator !== undefined) {
109
- //Pre-set the relation options from the existing relation decorator
110
- const existingCallExpression = existingRelationDecorator.expression;
111
- // Check if call expression has at least 1 arguments
112
- if (existingCallExpression.arguments.length > 2) { //Because we are interested in the 2nd argument, we check for length > 1
113
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[2])) {
114
- throw new Error('OneToMany decorator 3rd argument must be an object literal containing the relation options');
115
- }
116
- const existingObjectLiteralExpression = existingCallExpression.arguments[2];
117
- existingRelationDecoratorPropertyAssignments.push(...existingObjectLiteralExpression.properties);
118
- }
119
- }
120
- return existingRelationDecoratorPropertyAssignments;
121
- }
122
- createRelationDecoratorOptions() {
123
- const options = new Map();
124
- options.set('cascade', typescript_1.default.factory.createTrue());
125
- return this.optionsToPropertyAssignmentsOrNull(options);
126
- }
127
- optionsToPropertyAssignmentsOrNull(options) {
128
- const decoratorOptions = new Map();
129
- options.forEach((value, key) => {
130
- if (value !== null) {
131
- decoratorOptions.set(key, typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), value));
132
- }
133
- else {
134
- decoratorOptions.set(key, null);
135
- }
136
- });
137
- return decoratorOptions;
138
- }
139
- findDecorator(name, existingModifiers) {
140
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
141
- }
142
- filterOtherDecorators(name, existingModifiers) {
143
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
144
- }
145
- filterNonDecorators(existingModifiers) {
146
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
147
- }
148
- containsIdentifierName(m, identifierName) {
149
- const callExpression = m.expression;
150
- const identifier = callExpression.expression;
151
- return identifier.text === identifierName;
152
- }
153
- }
154
- exports.OneToManyDecoratorManager = OneToManyDecoratorManager;
155
- //# sourceMappingURL=OneToManyDecoratorManager.js.map
@@ -1,174 +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.UniqueIndexDecoratorManager = 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 UniqueIndexDecoratorManager {
10
- constructor(options, classNode, fieldNode) {
11
- this.options = options;
12
- this.classNode = classNode;
13
- this.fieldNode = fieldNode;
14
- }
15
- isApplyDecorator() {
16
- return this.options.unique;
17
- }
18
- decoratorName() {
19
- return 'Index';
20
- }
21
- setFieldNode(fieldNode) {
22
- this.fieldNode = fieldNode;
23
- }
24
- buildDecorator() {
25
- const fieldSourceLines = [];
26
- const changes = [];
27
- const indexDecoratorLine = `@Index(["${this.options.fieldName}", "deletedTracker"], { unique: true })`;
28
- fieldSourceLines.push(indexDecoratorLine);
29
- changes.push(...this.decoratorImports());
30
- return {
31
- filePath: this.options.source.fileName,
32
- field: this.options.field,
33
- changes: changes,
34
- fieldSourceLines: fieldSourceLines,
35
- };
36
- }
37
- decoratorImports() {
38
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'typeorm')];
39
- }
40
- //Updates the index decorator for the fieldNode based on the options provided
41
- // @returns the updated property declaration
42
- updateDecorator() {
43
- if (!this.classNode)
44
- throw new Error('Class node is required for updating the unique index decorator');
45
- let newModifiers = [];
46
- let existingModifiers = this.classNode.modifiers;
47
- // Get the existing unique index decorator if it exists
48
- const existingUniqueIndexDecorator = this.findUniqueIndexDecorator(existingModifiers);
49
- //Remove the Index decorator if the Index decorator exists
50
- newModifiers = [...this.filterOtherDecorators(this.decoratorName(), existingModifiers), ...this.filterOtherIndexDecorators(this.decoratorName(), this.options, existingModifiers), ...this.filterNonDecorators(existingModifiers)];
51
- //Add the column decorator if column decorator is required
52
- const changes = [];
53
- if (this.isApplyDecorator()) {
54
- newModifiers = [...newModifiers, this.createUniqueIndexDecorator(existingUniqueIndexDecorator)];
55
- changes.push(...this.decoratorImports());
56
- }
57
- // If field node is provided, replace the class members with the updated field node
58
- const newMembers = this.classNode.members.filter((member) => {
59
- // Check if the member is a PropertyDeclaration
60
- if (typescript_1.default.isPropertyDeclaration(member)) {
61
- // Compare the name of the property with the field name
62
- const memberName = member.name.getText();
63
- return memberName !== this.options.fieldName; // Exclude members with the matching field name
64
- }
65
- return true; // Keep non-PropertyDeclaration members
66
- });
67
- if (this.fieldNode) {
68
- newMembers.push(this.fieldNode);
69
- }
70
- // Update the class node with the new modifiers
71
- const updatedClass = typescript_1.default.factory.updateClassDeclaration(this.classNode, newModifiers, this.classNode.name, this.classNode.typeParameters, this.classNode.heritageClauses, newMembers);
72
- return [updatedClass, changes];
73
- }
74
- findUniqueIndexDecorator(existingModifiers) {
75
- return existingModifiers ? existingModifiers
76
- .filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator))
77
- .map(m => m)
78
- .filter(m => this.containsIdentifierName(m, this.decoratorName()))
79
- .filter(m => this.containsIndexForField(m, this.options.fieldName))
80
- .pop()
81
- : undefined;
82
- }
83
- createUniqueIndexDecorator(existingDecorator) {
84
- // Capture the existing column decorator options
85
- let existingUniqueIndexDecoratorPropertyAssignments = [];
86
- if (existingDecorator !== undefined) {
87
- //Pre-set the column options from the existing column decorator
88
- const existingCallExpression = existingDecorator.expression;
89
- // Check if call expression has at least 2 arguments
90
- if (existingCallExpression.arguments.length > 1) {
91
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
92
- throw new Error('Column decorator 1st arguments must be an object literal containing the column options');
93
- }
94
- const existingObjectLiteralExpression = existingCallExpression.arguments[1];
95
- existingUniqueIndexDecoratorPropertyAssignments.push(...existingObjectLiteralExpression.properties);
96
- }
97
- }
98
- // Create the new unique index decorator options as property assignments,
99
- const uniqueIndexDecoratorOptions = this.createUniqueIndexDecoratorOptions();
100
- const newPropertyAssignments = Array.from(uniqueIndexDecoratorOptions.values()).filter(p => p !== null);
101
- // Add the other unhandled column decorator options
102
- const handledColumnDecoratorOptions = Array.from(uniqueIndexDecoratorOptions.keys());
103
- //@ts-ignore
104
- const otherPropertyAssignments = existingUniqueIndexDecoratorPropertyAssignments.filter(ps => { var _a; return !handledColumnDecoratorOptions.includes((_a = ps.name) === null || _a === void 0 ? void 0 : _a.escapedText); });
105
- newPropertyAssignments.push(...otherPropertyAssignments);
106
- // Re-create the column decorator with the merged column decorator options
107
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
108
- const fieldsArray = typescript_1.default.factory.createArrayLiteralExpression([
109
- typescript_1.default.factory.createStringLiteral(this.options.fieldName),
110
- typescript_1.default.factory.createStringLiteral("deletedTracker")
111
- ], false);
112
- const decoratorOptions = typescript_1.default.factory.createObjectLiteralExpression(newPropertyAssignments);
113
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, [fieldsArray, decoratorOptions]);
114
- return typescript_1.default.factory.createDecorator(call);
115
- }
116
- createUniqueIndexDecoratorOptions() {
117
- const options = new Map();
118
- options.set('unique', typescript_1.default.factory.createTrue());
119
- return this.optionsToPropertyAssignmentsOrNull(options);
120
- }
121
- optionsToPropertyAssignmentsOrNull(options) {
122
- const decoratorOptions = new Map();
123
- options.forEach((value, key) => {
124
- if (value !== null) {
125
- decoratorOptions.set(key, typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), value));
126
- }
127
- else {
128
- decoratorOptions.set(key, null);
129
- }
130
- });
131
- return decoratorOptions;
132
- }
133
- filterOtherDecorators(name, existingModifiers) {
134
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
135
- }
136
- filterOtherIndexDecorators(name, decoratorOptions, existingModifiers) {
137
- return existingModifiers
138
- ? existingModifiers
139
- .filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator))
140
- .map(m => m)
141
- .filter(m => this.containsIdentifierName(m, name))
142
- .filter(m => !this.containsIndexForField(m, decoratorOptions.fieldName))
143
- : [];
144
- }
145
- filterNonDecorators(existingModifiers) {
146
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
147
- }
148
- containsIdentifierName(m, identifierName) {
149
- const callExpression = m.expression;
150
- const identifier = callExpression.expression;
151
- return identifier.text === identifierName;
152
- }
153
- containsIndexForField(m, fieldName) {
154
- // Check if the Index decorator contains the field name
155
- const callExpression = m.expression;
156
- const args = callExpression.arguments;
157
- if (args.length === 0)
158
- return false;
159
- let indexAlreadyPresent = false;
160
- const fields = args[0];
161
- if (typescript_1.default.isArrayLiteralExpression(fields)) {
162
- const fieldNames = fields.elements.map(e => e.getText().replace(/^["']|["']$/g, ""));
163
- // Check if fieldNames only contains the field name and deletedTracker
164
- indexAlreadyPresent = fieldNames.includes(fieldName) && fieldNames.includes('deletedTracker') && fieldNames.length === 2;
165
- console.log('fieldNames', fieldNames);
166
- console;
167
- }
168
- if (!indexAlreadyPresent)
169
- return false;
170
- return true;
171
- }
172
- }
173
- exports.UniqueIndexDecoratorManager = UniqueIndexDecoratorManager;
174
- //# sourceMappingURL=UniqueIndexDecoratorManager.js.map