@solidstarters/solid-code-builder 1.0.19 → 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 (98) 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/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.d.ts +1 -0
  5. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +13 -2
  6. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js.map +1 -1
  7. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +1 -1
  8. package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js.map +1 -1
  9. package/package.json +5 -2
  10. package/publish.js +16 -0
  11. package/src/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.ts +71 -2
  12. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.ts +21 -1
  13. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.ts +1 -1
  14. package/dto_additional_fields_duplicate_fix.diff +0 -40
  15. package/src/code-builder/index.js +0 -178
  16. package/src/code-builder/index_spec.js +0 -46
  17. package/src/code-builder/lib/field/FieldManager.js +0 -236
  18. package/src/code-builder/lib/field/decorator-managers/dto/ArrayDecoratorManager.js +0 -107
  19. package/src/code-builder/lib/field/decorator-managers/dto/BigIntDecoratorManager.js +0 -100
  20. package/src/code-builder/lib/field/decorator-managers/dto/BooleanDecoratorManager.js +0 -102
  21. package/src/code-builder/lib/field/decorator-managers/dto/DateDecoratorManager.js +0 -106
  22. package/src/code-builder/lib/field/decorator-managers/dto/DecimalDecoratorManager.js +0 -112
  23. package/src/code-builder/lib/field/decorator-managers/dto/EmailDecoratorManager.js +0 -99
  24. package/src/code-builder/lib/field/decorator-managers/dto/IntDecoratorManager.js +0 -100
  25. package/src/code-builder/lib/field/decorator-managers/dto/JsonDecoratorManager.js +0 -100
  26. package/src/code-builder/lib/field/decorator-managers/dto/LengthDecoratorManager.js +0 -104
  27. package/src/code-builder/lib/field/decorator-managers/dto/MaxDecoratorManager.js +0 -103
  28. package/src/code-builder/lib/field/decorator-managers/dto/MaxLengthDecoratorManager.js +0 -103
  29. package/src/code-builder/lib/field/decorator-managers/dto/MinDecoratorManager.js +0 -102
  30. package/src/code-builder/lib/field/decorator-managers/dto/MinLengthDecoratorManager.js +0 -103
  31. package/src/code-builder/lib/field/decorator-managers/dto/NumberDecoratorManager.js +0 -112
  32. package/src/code-builder/lib/field/decorator-managers/dto/OptionalDecoratorManager.js +0 -104
  33. package/src/code-builder/lib/field/decorator-managers/dto/RegexDecoratorManager.js +0 -102
  34. package/src/code-builder/lib/field/decorator-managers/dto/RequiredDecoratorManager.js +0 -100
  35. package/src/code-builder/lib/field/decorator-managers/dto/StringDecoratorManager.js +0 -99
  36. package/src/code-builder/lib/field/decorator-managers/dto/TransformDecoratorManager.js +0 -102
  37. package/src/code-builder/lib/field/decorator-managers/dto/ValidateNestedDecoratorManager.js +0 -140
  38. package/src/code-builder/lib/field/decorator-managers/entity/ColumnDecoratorManager.js +0 -178
  39. package/src/code-builder/lib/field/decorator-managers/entity/IndexDecoratorManager.js +0 -79
  40. package/src/code-builder/lib/field/decorator-managers/entity/JoinTableDecoratorManager.js +0 -118
  41. package/src/code-builder/lib/field/decorator-managers/entity/ManyToManyDecoratorManager.js +0 -175
  42. package/src/code-builder/lib/field/decorator-managers/entity/ManyToOneDecoratorManager.js +0 -179
  43. package/src/code-builder/lib/field/decorator-managers/entity/OneToManyDecoratorManager.js +0 -155
  44. package/src/code-builder/lib/field/decorator-managers/entity/UniqueIndexDecoratorManager.js +0 -174
  45. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +0 -345
  46. package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +0 -373
  47. package/src/code-builder/lib/field/field-managers/base/DeleteType.js +0 -11
  48. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldHandler.js +0 -33
  49. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForDto.js +0 -81
  50. package/src/code-builder/lib/field/field-managers/bigint/BigIntFieldManagerForEntity.js +0 -55
  51. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldHandler.js +0 -33
  52. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForDto.js +0 -75
  53. package/src/code-builder/lib/field/field-managers/boolean/BooleanFieldManagerForEntity.js +0 -51
  54. package/src/code-builder/lib/field/field-managers/computed/ComputedFieldHandler.js +0 -30
  55. package/src/code-builder/lib/field/field-managers/computed/ComputedFieldManagerForEntity.js +0 -33
  56. package/src/code-builder/lib/field/field-managers/date/DateFieldHandler.js +0 -33
  57. package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForDto.js +0 -81
  58. package/src/code-builder/lib/field/field-managers/date/DateFieldManagerForEntity.js +0 -59
  59. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldHandler.js +0 -33
  60. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForDto.js +0 -77
  61. package/src/code-builder/lib/field/field-managers/decimal/DecimalFieldManagerForEntity.js +0 -53
  62. package/src/code-builder/lib/field/field-managers/email/EmailFieldHandler.js +0 -34
  63. package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForDto.js +0 -72
  64. package/src/code-builder/lib/field/field-managers/email/EmailFieldManagerForEntity.js +0 -44
  65. package/src/code-builder/lib/field/field-managers/int/IntFieldHandler.js +0 -33
  66. package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForDto.js +0 -76
  67. package/src/code-builder/lib/field/field-managers/int/IntFieldManagerForEntity.js +0 -52
  68. package/src/code-builder/lib/field/field-managers/json/JsonFieldHandler.js +0 -34
  69. package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForDto.js +0 -57
  70. package/src/code-builder/lib/field/field-managers/json/JsonFieldManagerForEntity.js +0 -21
  71. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldHandler.js +0 -34
  72. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForDto.js +0 -63
  73. package/src/code-builder/lib/field/field-managers/long-text/LongTextFieldManagerForEntity.js +0 -34
  74. package/src/code-builder/lib/field/field-managers/media/MediaFieldHandler.js +0 -33
  75. package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForDto.js +0 -72
  76. package/src/code-builder/lib/field/field-managers/media/MediaFieldManagerForEntity.js +0 -57
  77. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldHandler.js +0 -27
  78. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForDto.js +0 -75
  79. package/src/code-builder/lib/field/field-managers/no-ops/NoOpsFieldManagerForEntity.js +0 -35
  80. package/src/code-builder/lib/field/field-managers/password/PasswordFieldHandler.js +0 -34
  81. package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForDto.js +0 -121
  82. package/src/code-builder/lib/field/field-managers/password/PasswordFieldManagerForEntity.js +0 -37
  83. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldHandler.js +0 -33
  84. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForDto.js +0 -366
  85. package/src/code-builder/lib/field/field-managers/relation/ManyToManyRelationFieldManagerForEntity.js +0 -158
  86. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldHandler.js +0 -33
  87. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForDto.js +0 -294
  88. package/src/code-builder/lib/field/field-managers/relation/ManyToOneRelationFieldManagerForEntity.js +0 -177
  89. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldHandler.js +0 -34
  90. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForDto.js +0 -63
  91. package/src/code-builder/lib/field/field-managers/rich-text/RichTextFieldManagerForEntity.js +0 -34
  92. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldHandler.js +0 -34
  93. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForDto.js +0 -63
  94. package/src/code-builder/lib/field/field-managers/short-text/ShortTextFieldManagerForEntity.js +0 -37
  95. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldHandler.js +0 -34
  96. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForDto.js +0 -15
  97. package/src/code-builder/lib/field/field-managers/uuid/UUIDFieldManagerForEntity.js +0 -33
  98. package/src/code-builder/lib/model/helpers.js +0 -407
@@ -1,104 +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.LengthDecoratorManager = 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 LengthDecoratorManager {
10
- constructor(options, fieldNode) {
11
- this.options = options;
12
- this.fieldNode = fieldNode;
13
- }
14
- isApplyDecorator() {
15
- return (this.options.isApplyLength && this.options.length > 0);
16
- }
17
- setFieldNode(fieldNode) {
18
- this.fieldNode = fieldNode;
19
- }
20
- buildDecorator() {
21
- const fieldSourceLines = [];
22
- const changes = [];
23
- fieldSourceLines.push(`@Length(1, ${this.options.length})`);
24
- changes.push(...this.decoratorImports());
25
- return {
26
- filePath: this.options.source.fileName,
27
- field: this.options.field,
28
- changes: changes,
29
- fieldSourceLines: fieldSourceLines,
30
- };
31
- }
32
- decoratorName() {
33
- return 'Length';
34
- }
35
- decoratorImports() {
36
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
37
- }
38
- updateDecorator() {
39
- if (!this.fieldNode)
40
- throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
41
- let newModifiers = [];
42
- let existingModifiers = this.fieldNode.modifiers;
43
- // Check if the field has an Length decorator.
44
- //@ts-ignore
45
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
46
- //Remove the column decorator if the column decorator exists
47
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
48
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
49
- //Add the column decorator if column decorator is required
50
- // console.log('this.options.isApplyLength', this.options.isApplyLength, this.options.length)
51
- const changes = [];
52
- if (this.isApplyDecorator()) {
53
- newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
54
- changes.push(...this.decoratorImports());
55
- }
56
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
57
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
58
- return [updatedProperty, changes];
59
- }
60
- createDecorator(existingDecorator) {
61
- // Capture the existing validation options
62
- let validationOptions = [];
63
- if (existingDecorator !== undefined) {
64
- //Pre-set the column options from the existing column decorator
65
- const existingCallExpression = existingDecorator.expression;
66
- // Check if call expression has at least 1 arguments
67
- if (existingCallExpression.arguments.length > 2) {
68
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[2])) {
69
- throw new Error('Length decorator 3rd argument must be an object literal containing the validation options');
70
- }
71
- const existingObjectLiteralExpression = existingCallExpression.arguments[2];
72
- validationOptions.push(...existingObjectLiteralExpression.properties);
73
- }
74
- }
75
- // Re-create the column decorator with the merged column decorator options
76
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier("Length");
77
- const argumentsArray = [];
78
- const min = typescript_1.default.factory.createNumericLiteral(1);
79
- const max = typescript_1.default.factory.createNumericLiteral(this.options.length);
80
- argumentsArray.push(min, max);
81
- if (validationOptions.length > 0) {
82
- const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
83
- argumentsArray.push(validationOptionsObjectLiteral);
84
- }
85
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
86
- return typescript_1.default.factory.createDecorator(call);
87
- }
88
- findDecorator(name, existingModifiers) {
89
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
90
- }
91
- filterOtherDecorators(name, existingModifiers) {
92
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
93
- }
94
- filterNonDecorators(existingModifiers) {
95
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
96
- }
97
- containsIdentifierName(m, identifierName) {
98
- const callExpression = m.expression;
99
- const identifier = callExpression.expression;
100
- return identifier.text === identifierName;
101
- }
102
- }
103
- exports.LengthDecoratorManager = LengthDecoratorManager;
104
- //# sourceMappingURL=LengthDecoratorManager.js.map
@@ -1,103 +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.MaxDecoratorManager = void 0;
7
- const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
8
- const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
9
- class MaxDecoratorManager {
10
- constructor(options, fieldNode) {
11
- this.options = options;
12
- this.fieldNode = fieldNode;
13
- }
14
- isApplyDecorator() {
15
- return this.options.isApplyMax && this.options.max > 0;
16
- }
17
- buildDecorator() {
18
- const fieldSourceLines = [];
19
- const changes = [];
20
- fieldSourceLines.push(`@Max(${this.options.max})`);
21
- changes.push(...this.decoratorImports());
22
- return {
23
- filePath: this.options.source.fileName,
24
- field: this.options.field,
25
- changes: changes,
26
- fieldSourceLines: fieldSourceLines,
27
- };
28
- }
29
- setFieldNode(fieldNode) {
30
- this.fieldNode = fieldNode;
31
- }
32
- decoratorName() {
33
- return 'Max';
34
- }
35
- decoratorImports() {
36
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
37
- }
38
- updateDecorator() {
39
- if (!this.fieldNode)
40
- throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
41
- let newModifiers = [];
42
- let existingModifiers = this.fieldNode.modifiers;
43
- // Check if the field has an Length decorator.
44
- //@ts-ignore
45
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
46
- //Remove the column decorator if the column decorator exists
47
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
48
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
49
- //Add the column decorator if column decorator is required
50
- // console.log('this.options.isApplyMax', this.options.isApplyMax, this.options.max)
51
- const changes = [];
52
- if (this.isApplyDecorator()) {
53
- newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
54
- changes.push(...this.decoratorImports());
55
- }
56
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
57
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
58
- return [updatedProperty, changes];
59
- }
60
- createDecorator(existingDecorator) {
61
- // Capture the existing column decorator options
62
- let validationOptions = [];
63
- if (existingDecorator !== undefined) {
64
- //Pre-set the column options from the existing column decorator
65
- const existingCallExpression = existingDecorator.expression;
66
- // Check if call expression has at least 1 arguments
67
- if (existingCallExpression.arguments.length > 1) {
68
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
69
- throw new Error('Max decorator 2nd argument must be an object literal containing the validation options');
70
- }
71
- const existingObjectLiteralExpression = existingCallExpression.arguments[1];
72
- validationOptions.push(...existingObjectLiteralExpression.properties);
73
- }
74
- }
75
- // Re-create the column decorator with the merged column decorator options
76
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier("Max");
77
- const argumentsArray = [];
78
- const max = typescript_1.default.factory.createNumericLiteral(this.options.max);
79
- argumentsArray.push(max);
80
- if (validationOptions.length > 0) {
81
- const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
82
- argumentsArray.push(validationOptionsObjectLiteral);
83
- }
84
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
85
- return typescript_1.default.factory.createDecorator(call);
86
- }
87
- findDecorator(name, existingModifiers) {
88
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
89
- }
90
- filterOtherDecorators(name, existingModifiers) {
91
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
92
- }
93
- filterNonDecorators(existingModifiers) {
94
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
95
- }
96
- containsIdentifierName(m, identifierName) {
97
- const callExpression = m.expression;
98
- const identifier = callExpression.expression;
99
- return identifier.text === identifierName;
100
- }
101
- }
102
- exports.MaxDecoratorManager = MaxDecoratorManager;
103
- //# sourceMappingURL=MaxDecoratorManager.js.map
@@ -1,103 +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.MaxLengthDecoratorManager = 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 MaxLengthDecoratorManager {
10
- constructor(options, fieldNode) {
11
- this.options = options;
12
- this.fieldNode = fieldNode;
13
- }
14
- isApplyDecorator() {
15
- return (this.options.isApplyMaxLength && this.options.length > 0);
16
- }
17
- setFieldNode(fieldNode) {
18
- this.fieldNode = fieldNode;
19
- }
20
- buildDecorator() {
21
- const fieldSourceLines = [];
22
- const changes = [];
23
- fieldSourceLines.push(`@${this.decoratorName()}(${this.options.length})`);
24
- changes.push(...this.decoratorImports());
25
- return {
26
- filePath: this.options.source.fileName,
27
- field: this.options.field,
28
- changes: changes,
29
- fieldSourceLines: fieldSourceLines,
30
- };
31
- }
32
- decoratorName() {
33
- return 'MaxLength';
34
- }
35
- decoratorImports() {
36
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
37
- }
38
- updateDecorator() {
39
- if (!this.fieldNode)
40
- throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
41
- let newModifiers = [];
42
- let existingModifiers = this.fieldNode.modifiers;
43
- // Check if the field has an Length decorator.
44
- //@ts-ignore
45
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
46
- //Remove the column decorator if the column decorator exists
47
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
48
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
49
- //Add the column decorator if column decorator is required
50
- // console.log('this.options.isApplyLength', this.options.isApplyLength, this.options.length)
51
- const changes = [];
52
- if (this.isApplyDecorator()) {
53
- newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
54
- changes.push(...this.decoratorImports());
55
- }
56
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
57
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
58
- return [updatedProperty, changes];
59
- }
60
- createDecorator(existingDecorator) {
61
- // Capture the existing validation options
62
- let validationOptions = [];
63
- if (existingDecorator !== undefined) {
64
- //Pre-set the column options from the existing column decorator
65
- const existingCallExpression = existingDecorator.expression;
66
- // Check if call expression has at least 1 arguments
67
- if (existingCallExpression.arguments.length > 1) {
68
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
69
- throw new Error(`${this.decoratorName()} decorator 2nd argument must be an object literal containing the validation options`);
70
- }
71
- const existingObjectLiteralExpression = existingCallExpression.arguments[1];
72
- validationOptions.push(...existingObjectLiteralExpression.properties);
73
- }
74
- }
75
- // Re-create the column decorator with the merged column decorator options
76
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
77
- const argumentsArray = [];
78
- const length = typescript_1.default.factory.createNumericLiteral(this.options.length);
79
- argumentsArray.push(length);
80
- if (validationOptions.length > 0) {
81
- const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
82
- argumentsArray.push(validationOptionsObjectLiteral);
83
- }
84
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
85
- return typescript_1.default.factory.createDecorator(call);
86
- }
87
- findDecorator(name, existingModifiers) {
88
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
89
- }
90
- filterOtherDecorators(name, existingModifiers) {
91
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
92
- }
93
- filterNonDecorators(existingModifiers) {
94
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
95
- }
96
- containsIdentifierName(m, identifierName) {
97
- const callExpression = m.expression;
98
- const identifier = callExpression.expression;
99
- return identifier.text === identifierName;
100
- }
101
- }
102
- exports.MaxLengthDecoratorManager = MaxLengthDecoratorManager;
103
- //# sourceMappingURL=MaxLengthDecoratorManager.js.map
@@ -1,102 +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.MinDecoratorManager = void 0;
7
- const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
8
- const typescript_1 = __importDefault(require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"));
9
- class MinDecoratorManager {
10
- constructor(options, fieldNode) {
11
- this.options = options;
12
- this.fieldNode = fieldNode;
13
- }
14
- isApplyDecorator() {
15
- return this.options.isApplyMin && this.options.min > 0;
16
- }
17
- buildDecorator() {
18
- const fieldSourceLines = [];
19
- const changes = [];
20
- fieldSourceLines.push(`@Min(${this.options.min})`);
21
- changes.push(...this.decoratorImports());
22
- return {
23
- filePath: this.options.source.fileName,
24
- field: this.options.field,
25
- changes: changes,
26
- fieldSourceLines: fieldSourceLines,
27
- };
28
- }
29
- setFieldNode(fieldNode) {
30
- this.fieldNode = fieldNode;
31
- }
32
- decoratorName() {
33
- return 'Min';
34
- }
35
- decoratorImports() {
36
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
37
- }
38
- updateDecorator() {
39
- if (!this.fieldNode)
40
- throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
41
- let newModifiers = [];
42
- let existingModifiers = this.fieldNode.modifiers;
43
- // Check if the field has an Length decorator.
44
- //@ts-ignore
45
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
46
- //Remove the column decorator if the column decorator exists
47
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
48
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
49
- //Add the column decorator if column decorator is required
50
- const changes = [];
51
- if (this.isApplyDecorator()) {
52
- newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
53
- changes.push(...this.decoratorImports());
54
- }
55
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
56
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
57
- return [updatedProperty, changes];
58
- }
59
- createDecorator(existingDecorator) {
60
- // Capture the existing column decorator options
61
- let validationOptions = [];
62
- if (existingDecorator !== undefined) {
63
- //Pre-set the column options from the existing column decorator
64
- const existingCallExpression = existingDecorator.expression;
65
- // Check if call expression has at least 1 arguments
66
- if (existingCallExpression.arguments.length > 1) {
67
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
68
- throw new Error('Min decorator 2nd argument must be an object literal containing the validation options');
69
- }
70
- const existingObjectLiteralExpression = existingCallExpression.arguments[1];
71
- validationOptions.push(...existingObjectLiteralExpression.properties);
72
- }
73
- }
74
- // Re-create the column decorator with the merged column decorator options
75
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier("Max");
76
- const argumentsArray = [];
77
- const min = typescript_1.default.factory.createNumericLiteral(this.options.min);
78
- argumentsArray.push(min);
79
- if (validationOptions.length > 0) {
80
- const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
81
- argumentsArray.push(validationOptionsObjectLiteral);
82
- }
83
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
84
- return typescript_1.default.factory.createDecorator(call);
85
- }
86
- findDecorator(name, existingModifiers) {
87
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
88
- }
89
- filterOtherDecorators(name, existingModifiers) {
90
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
91
- }
92
- filterNonDecorators(existingModifiers) {
93
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
94
- }
95
- containsIdentifierName(m, identifierName) {
96
- const callExpression = m.expression;
97
- const identifier = callExpression.expression;
98
- return identifier.text === identifierName;
99
- }
100
- }
101
- exports.MinDecoratorManager = MinDecoratorManager;
102
- //# sourceMappingURL=MinDecoratorManager.js.map
@@ -1,103 +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.MinLengthDecoratorManager = 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 MinLengthDecoratorManager {
10
- constructor(options, fieldNode) {
11
- this.options = options;
12
- this.fieldNode = fieldNode;
13
- }
14
- isApplyDecorator() {
15
- return (this.options.isApplyMinLength && this.options.length > 0);
16
- }
17
- setFieldNode(fieldNode) {
18
- this.fieldNode = fieldNode;
19
- }
20
- buildDecorator() {
21
- const fieldSourceLines = [];
22
- const changes = [];
23
- fieldSourceLines.push(`@${this.decoratorName()}(${this.options.length})`);
24
- changes.push(...this.decoratorImports());
25
- return {
26
- filePath: this.options.source.fileName,
27
- field: this.options.field,
28
- changes: changes,
29
- fieldSourceLines: fieldSourceLines,
30
- };
31
- }
32
- decoratorName() {
33
- return 'MinLength';
34
- }
35
- decoratorImports() {
36
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
37
- }
38
- updateDecorator() {
39
- if (!this.fieldNode)
40
- throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
41
- let newModifiers = [];
42
- let existingModifiers = this.fieldNode.modifiers;
43
- // Check if the field has an Length decorator.
44
- //@ts-ignore
45
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
46
- //Remove the column decorator if the column decorator exists
47
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
48
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
49
- //Add the column decorator if column decorator is required
50
- // console.log('this.options.isApplyLength', this.options.isApplyLength, this.options.length)
51
- const changes = [];
52
- if (this.isApplyDecorator()) {
53
- newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
54
- changes.push(...this.decoratorImports());
55
- }
56
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
57
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
58
- return [updatedProperty, changes];
59
- }
60
- createDecorator(existingDecorator) {
61
- // Capture the existing validation options
62
- let validationOptions = [];
63
- if (existingDecorator !== undefined) {
64
- //Pre-set the column options from the existing column decorator
65
- const existingCallExpression = existingDecorator.expression;
66
- // Check if call expression has at least 1 arguments
67
- if (existingCallExpression.arguments.length > 1) {
68
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
69
- throw new Error(`${this.decoratorName()} decorator 2nd argument must be an object literal containing the validation options`);
70
- }
71
- const existingObjectLiteralExpression = existingCallExpression.arguments[1];
72
- validationOptions.push(...existingObjectLiteralExpression.properties);
73
- }
74
- }
75
- // Re-create the column decorator with the merged column decorator options
76
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
77
- const argumentsArray = [];
78
- const length = typescript_1.default.factory.createNumericLiteral(this.options.length);
79
- argumentsArray.push(length);
80
- if (validationOptions.length > 0) {
81
- const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
82
- argumentsArray.push(validationOptionsObjectLiteral);
83
- }
84
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
85
- return typescript_1.default.factory.createDecorator(call);
86
- }
87
- findDecorator(name, existingModifiers) {
88
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
89
- }
90
- filterOtherDecorators(name, existingModifiers) {
91
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
92
- }
93
- filterNonDecorators(existingModifiers) {
94
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
95
- }
96
- containsIdentifierName(m, identifierName) {
97
- const callExpression = m.expression;
98
- const identifier = callExpression.expression;
99
- return identifier.text === identifierName;
100
- }
101
- }
102
- exports.MinLengthDecoratorManager = MinLengthDecoratorManager;
103
- //# sourceMappingURL=MinLengthDecoratorManager.js.map
@@ -1,112 +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.NumberDecoratorManager = 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 NumberDecoratorManager {
10
- constructor(options, fieldNode) {
11
- this.options = options;
12
- this.fieldNode = fieldNode;
13
- }
14
- isApplyDecorator() {
15
- return this.options.isNumber;
16
- }
17
- buildDecorator() {
18
- const fieldSourceLines = [];
19
- const changes = [];
20
- fieldSourceLines.push(`@IsNumber()`);
21
- changes.push(...this.decoratorImports());
22
- return {
23
- filePath: this.options.source.fileName,
24
- field: this.options.field,
25
- changes: changes,
26
- fieldSourceLines: fieldSourceLines,
27
- };
28
- }
29
- setFieldNode(fieldNode) {
30
- this.fieldNode = fieldNode;
31
- }
32
- decoratorName() {
33
- return 'IsNumber';
34
- }
35
- decoratorImports() {
36
- return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
37
- }
38
- updateDecorator() {
39
- if (!this.fieldNode)
40
- throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
41
- let newModifiers = [];
42
- let existingModifiers = this.fieldNode.modifiers;
43
- // Check if the field has an Length decorator.
44
- //@ts-ignore
45
- const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
46
- //Remove the column decorator if the column decorator exists
47
- //TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
48
- newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
49
- //Add the column decorator if column decorator is required
50
- const changes = [];
51
- if (this.isApplyDecorator()) {
52
- newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
53
- changes.push(...this.decoratorImports());
54
- }
55
- const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
56
- this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
57
- return [updatedProperty, changes];
58
- }
59
- createDecorator(existingDecorator) {
60
- // Capture the existing column decorator options
61
- const numberOptions = [];
62
- const validationOptions = [];
63
- if (existingDecorator !== undefined) {
64
- //Pre-set the column options from the existing column decorator
65
- const existingCallExpression = existingDecorator.expression;
66
- // Check if call expression has at least 1 arguments
67
- if (existingCallExpression.arguments.length > 0) {
68
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
69
- throw new Error('Number decorator 2nd argument must be an object literal containing the validation options');
70
- }
71
- const existingObjectLiteralExpression = existingCallExpression.arguments[0];
72
- numberOptions.push(...existingObjectLiteralExpression.properties);
73
- if (existingCallExpression.arguments.length > 1) {
74
- if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
75
- throw new Error('Number decorator 3rd argument must be an object literal containing the validation options');
76
- }
77
- const existingObjectLiteralExpression = existingCallExpression.arguments[1];
78
- validationOptions.push(...existingObjectLiteralExpression.properties);
79
- }
80
- }
81
- }
82
- // Re-create the column decorator with the merged column decorator options
83
- const decoratorIdentifier = typescript_1.default.factory.createIdentifier("IsNumber");
84
- const argumentsArray = [];
85
- if (numberOptions.length > 0) {
86
- const numberOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(numberOptions);
87
- argumentsArray.push(numberOptionsObjectLiteral);
88
- }
89
- if (validationOptions.length > 0) {
90
- const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
91
- argumentsArray.push(validationOptionsObjectLiteral);
92
- }
93
- const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
94
- return typescript_1.default.factory.createDecorator(call);
95
- }
96
- findDecorator(name, existingModifiers) {
97
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
98
- }
99
- filterOtherDecorators(name, existingModifiers) {
100
- return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
101
- }
102
- filterNonDecorators(existingModifiers) {
103
- return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
104
- }
105
- containsIdentifierName(m, identifierName) {
106
- const callExpression = m.expression;
107
- const identifier = callExpression.expression;
108
- return identifier.text === identifierName;
109
- }
110
- }
111
- exports.NumberDecoratorManager = NumberDecoratorManager;
112
- //# sourceMappingURL=NumberDecoratorManager.js.map