@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.
- 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/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.d.ts +1 -0
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js +13 -2
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.js.map +1 -1
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js +1 -1
- package/dist/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.js.map +1 -1
- package/package.json +5 -2
- package/publish.js +16 -0
- package/src/code-builder/lib/field/decorator-managers/dto/ApiPropertyDecoratorManager.ts +71 -2
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForDto.ts +21 -1
- package/src/code-builder/lib/field/field-managers/base/BaseFieldManagerForEntity.ts +1 -1
- 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,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.OptionalDecoratorManager = 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 OptionalDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isApplyOptional && this.options.optional;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
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 'IsOptional';
|
|
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 existingValidationOptions = this.existingDecoratorOptions(existingDecorator);
|
|
62
|
-
// Re-create the decorator with the existing decorator options
|
|
63
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
64
|
-
const argumentsArray = [];
|
|
65
|
-
if (existingValidationOptions.length > 0) {
|
|
66
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(existingValidationOptions);
|
|
67
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
68
|
-
}
|
|
69
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
70
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
71
|
-
}
|
|
72
|
-
existingDecoratorOptions(existingDecorator) {
|
|
73
|
-
let validationOptions = [];
|
|
74
|
-
if (existingDecorator !== undefined) {
|
|
75
|
-
//Pre-set the column options from the existing column decorator
|
|
76
|
-
const existingCallExpression = existingDecorator.expression;
|
|
77
|
-
// Check if call expression has at least 1 arguments
|
|
78
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
79
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
80
|
-
throw new Error('IsOptional decorator 1st argument must be an object literal containing the validation options');
|
|
81
|
-
}
|
|
82
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
83
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return validationOptions;
|
|
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.OptionalDecoratorManager = OptionalDecoratorManager;
|
|
104
|
-
//# sourceMappingURL=OptionalDecoratorManager.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.RegexDecoratorManager = 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 RegexDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isApplyRegex && this.options.regexPattern !== null && this.options.regexPattern !== undefined && this.options.regexPattern.trim().length > 0;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@Matches(/${this.options.regexPattern}/)`);
|
|
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 'Matches';
|
|
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('Regex 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("Matches");
|
|
76
|
-
const argumentsArray = [];
|
|
77
|
-
const regexPattern = typescript_1.default.factory.createRegularExpressionLiteral(`/${this.options.regexPattern}/`);
|
|
78
|
-
argumentsArray.push(regexPattern);
|
|
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.RegexDecoratorManager = RegexDecoratorManager;
|
|
102
|
-
//# sourceMappingURL=RegexDecoratorManager.js.map
|
|
@@ -1,100 +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.RequiredDecoratorManager = 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 RequiredDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isApplyRequired && this.options.required;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
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 'IsNotEmpty';
|
|
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 > 0) {
|
|
67
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
68
|
-
throw new Error('IsNotEmpty decorator 1st argument must be an object literal containing the validation options');
|
|
69
|
-
}
|
|
70
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
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(this.decoratorName());
|
|
76
|
-
const argumentsArray = [];
|
|
77
|
-
if (validationOptions.length > 0) {
|
|
78
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
79
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
80
|
-
}
|
|
81
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
82
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
83
|
-
}
|
|
84
|
-
findDecorator(name, existingModifiers) {
|
|
85
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
86
|
-
}
|
|
87
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
88
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
89
|
-
}
|
|
90
|
-
filterNonDecorators(existingModifiers) {
|
|
91
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
92
|
-
}
|
|
93
|
-
containsIdentifierName(m, identifierName) {
|
|
94
|
-
const callExpression = m.expression;
|
|
95
|
-
const identifier = callExpression.expression;
|
|
96
|
-
return identifier.text === identifierName;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.RequiredDecoratorManager = RequiredDecoratorManager;
|
|
100
|
-
//# sourceMappingURL=RequiredDecoratorManager.js.map
|
|
@@ -1,99 +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.StringDecoratorManager = 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 StringDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isString;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}()`);
|
|
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 'IsString';
|
|
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
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
45
|
-
//Remove the column decorator if the column decorator exists
|
|
46
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
47
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
48
|
-
//Add the column decorator if column decorator is required
|
|
49
|
-
const changes = [];
|
|
50
|
-
if (this.isApplyDecorator()) {
|
|
51
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
52
|
-
changes.push(...this.decoratorImports());
|
|
53
|
-
}
|
|
54
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
55
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
56
|
-
return [updatedProperty, changes];
|
|
57
|
-
}
|
|
58
|
-
createDecorator(existingDecorator) {
|
|
59
|
-
// Capture the existing column decorator options
|
|
60
|
-
let validationOptions = [];
|
|
61
|
-
if (existingDecorator !== undefined) {
|
|
62
|
-
//Pre-set the column options from the existing column decorator
|
|
63
|
-
const existingCallExpression = existingDecorator.expression;
|
|
64
|
-
// Check if call expression has at least 1 arguments
|
|
65
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
66
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
67
|
-
throw new Error(`${this.decoratorName()} decorator 1st argument must be an object literal containing the validation options`);
|
|
68
|
-
}
|
|
69
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
70
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Re-create the column decorator with the merged column decorator options
|
|
74
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
75
|
-
const argumentsArray = [];
|
|
76
|
-
if (validationOptions.length > 0) {
|
|
77
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
78
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
79
|
-
}
|
|
80
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
81
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
82
|
-
}
|
|
83
|
-
findDecorator(name, existingModifiers) {
|
|
84
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
85
|
-
}
|
|
86
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
87
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
88
|
-
}
|
|
89
|
-
filterNonDecorators(existingModifiers) {
|
|
90
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
91
|
-
}
|
|
92
|
-
containsIdentifierName(m, identifierName) {
|
|
93
|
-
const callExpression = m.expression;
|
|
94
|
-
const identifier = callExpression.expression;
|
|
95
|
-
return identifier.text === identifierName;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.StringDecoratorManager = StringDecoratorManager;
|
|
99
|
-
//# sourceMappingURL=StringDecoratorManager.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.TransformDecoratorManager = 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 TransformDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isTransform;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}(() => ${this.options.type})`);
|
|
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 'Type';
|
|
34
|
-
}
|
|
35
|
-
decoratorImports() {
|
|
36
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-transformer')];
|
|
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 Transform decorator.
|
|
44
|
-
//@ts-ignore
|
|
45
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
46
|
-
//Remove the decorator if the 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 decorator, if it 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 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 2 arguments
|
|
66
|
-
if (existingCallExpression.arguments.length > 1) {
|
|
67
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[1])) {
|
|
68
|
-
throw new Error('Transform decorator 1st 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(this.decoratorName());
|
|
76
|
-
const argumentsArray = [];
|
|
77
|
-
const transformFunction = typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createIdentifier(this.options.type));
|
|
78
|
-
argumentsArray.push(transformFunction);
|
|
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.TransformDecoratorManager = TransformDecoratorManager;
|
|
102
|
-
//# sourceMappingURL=TransformDecoratorManager.js.map
|
|
@@ -1,140 +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.ValidateNestedDecoratorManager = 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 ValidateNestedDecoratorManager {
|
|
10
|
-
constructor(options, fieldNode) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.fieldNode = fieldNode;
|
|
13
|
-
}
|
|
14
|
-
isApplyDecorator() {
|
|
15
|
-
return this.options.isValidateNested;
|
|
16
|
-
}
|
|
17
|
-
buildDecorator() {
|
|
18
|
-
const fieldSourceLines = [];
|
|
19
|
-
const changes = [];
|
|
20
|
-
fieldSourceLines.push(`@${this.decoratorName()}(${this.buildValidationOptionsCode()})`);
|
|
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 'ValidateNested';
|
|
34
|
-
}
|
|
35
|
-
decoratorImports() {
|
|
36
|
-
return [(0, ast_utils_1.insertImport)(this.options.source, this.options.source.fileName, this.decoratorName(), 'class-validator')];
|
|
37
|
-
}
|
|
38
|
-
buildValidationOptionsCode() {
|
|
39
|
-
return `{ each : true }`;
|
|
40
|
-
}
|
|
41
|
-
updateDecorator() {
|
|
42
|
-
if (!this.fieldNode)
|
|
43
|
-
throw new Error(`Field node is required for updating the ${this.decoratorName()} decorator`);
|
|
44
|
-
let newModifiers = [];
|
|
45
|
-
let existingModifiers = this.fieldNode.modifiers;
|
|
46
|
-
// Check if the field has an IsArray decorator.
|
|
47
|
-
const existingDecorator = this.findDecorator(this.decoratorName(), existingModifiers);
|
|
48
|
-
//Remove the decorator if the decorator exists
|
|
49
|
-
//TODO probably this too can be done in a lesser intrusive way i.e update everything instead of removing and adding
|
|
50
|
-
newModifiers = [...this.filterNonDecorators(existingModifiers), ...this.filterOtherDecorators(this.decoratorName(), existingModifiers)];
|
|
51
|
-
//Add the decorator, if it is required
|
|
52
|
-
const changes = [];
|
|
53
|
-
if (this.isApplyDecorator()) {
|
|
54
|
-
newModifiers = [...newModifiers, this.createDecorator(existingDecorator)];
|
|
55
|
-
changes.push(...this.decoratorImports());
|
|
56
|
-
}
|
|
57
|
-
const updatedProperty = typescript_1.default.factory.updatePropertyDeclaration(this.fieldNode, newModifiers, //Replace with new modifiers
|
|
58
|
-
this.fieldNode.name, this.fieldNode.questionToken, this.fieldNode.type, this.fieldNode.initializer);
|
|
59
|
-
return [updatedProperty, changes];
|
|
60
|
-
}
|
|
61
|
-
createDecorator(existingDecorator) {
|
|
62
|
-
// Capture the existing isArray decorator options
|
|
63
|
-
const validationOptions = this.existingValidationOptions(existingDecorator);
|
|
64
|
-
//Merge the options with the existing options
|
|
65
|
-
const mergedValidationOptions = this.mergeExistingAndNewValidationOptions(validationOptions);
|
|
66
|
-
// Re-create the isArray decorator with the existing isArray decorator options
|
|
67
|
-
const decoratorIdentifier = typescript_1.default.factory.createIdentifier(this.decoratorName());
|
|
68
|
-
const argumentsArray = this.createDecoratorArguments(mergedValidationOptions);
|
|
69
|
-
const call = typescript_1.default.factory.createCallExpression(decoratorIdentifier, undefined, argumentsArray);
|
|
70
|
-
return typescript_1.default.factory.createDecorator(call);
|
|
71
|
-
}
|
|
72
|
-
mergeExistingAndNewValidationOptions(validationOptions) {
|
|
73
|
-
const decoratorOptions = this.createValidationDecoratorOptions();
|
|
74
|
-
const mergedValidationOptions = Array.from(decoratorOptions.values()).filter(p => p !== null);
|
|
75
|
-
// console.log('mergedValidationOptions', mergedValidationOptions.map(p => JSON.stringify(p.name)).join(', '));
|
|
76
|
-
// Add the other unhandled column decorator options
|
|
77
|
-
const handledDecoratorOptions = Array.from(decoratorOptions.keys());
|
|
78
|
-
//@ts-ignore
|
|
79
|
-
const otherPropertyAssignments = validationOptions.filter(ps => { var _a; return !handledDecoratorOptions.includes((_a = ps.name) === null || _a === void 0 ? void 0 : _a.escapedText); });
|
|
80
|
-
mergedValidationOptions.push(...otherPropertyAssignments);
|
|
81
|
-
return mergedValidationOptions;
|
|
82
|
-
}
|
|
83
|
-
createValidationDecoratorOptions() {
|
|
84
|
-
const options = new Map();
|
|
85
|
-
options.set('each', typescript_1.default.factory.createTrue());
|
|
86
|
-
return this.optionsToPropertyAssignmentsOrNull(options);
|
|
87
|
-
}
|
|
88
|
-
optionsToPropertyAssignmentsOrNull(options) {
|
|
89
|
-
const decoratorOptions = new Map();
|
|
90
|
-
options.forEach((value, key) => {
|
|
91
|
-
if (value !== null) {
|
|
92
|
-
decoratorOptions.set(key, typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(key), value));
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
decoratorOptions.set(key, null);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return decoratorOptions;
|
|
99
|
-
}
|
|
100
|
-
createDecoratorArguments(validationOptions) {
|
|
101
|
-
const argumentsArray = [];
|
|
102
|
-
if (validationOptions.length > 0) {
|
|
103
|
-
const validationOptionsObjectLiteral = typescript_1.default.factory.createObjectLiteralExpression(validationOptions);
|
|
104
|
-
argumentsArray.push(validationOptionsObjectLiteral);
|
|
105
|
-
}
|
|
106
|
-
return argumentsArray;
|
|
107
|
-
}
|
|
108
|
-
existingValidationOptions(existingDecorator) {
|
|
109
|
-
const validationOptions = [];
|
|
110
|
-
if (existingDecorator !== undefined) {
|
|
111
|
-
//Pre-set the isArray options from the existing IsArray decorator
|
|
112
|
-
const existingCallExpression = existingDecorator.expression;
|
|
113
|
-
// Check if call expression has at least 1 argument
|
|
114
|
-
if (existingCallExpression.arguments.length > 0) {
|
|
115
|
-
if (!typescript_1.default.isObjectLiteralExpression(existingCallExpression.arguments[0])) {
|
|
116
|
-
throw new Error('ValidateNested decorator 1st argument must be an object literal containing the validation options');
|
|
117
|
-
}
|
|
118
|
-
const existingObjectLiteralExpression = existingCallExpression.arguments[0];
|
|
119
|
-
validationOptions.push(...existingObjectLiteralExpression.properties);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return validationOptions;
|
|
123
|
-
}
|
|
124
|
-
findDecorator(name, existingModifiers) {
|
|
125
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => this.containsIdentifierName(m, name)).pop() : undefined;
|
|
126
|
-
}
|
|
127
|
-
filterOtherDecorators(name, existingModifiers) {
|
|
128
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind === typescript_1.default.SyntaxKind.Decorator)).map(m => m).filter(m => !this.containsIdentifierName(m, name)) : [];
|
|
129
|
-
}
|
|
130
|
-
filterNonDecorators(existingModifiers) {
|
|
131
|
-
return existingModifiers ? existingModifiers.filter((m) => (m.kind !== typescript_1.default.SyntaxKind.Decorator)).map(m => m) : [];
|
|
132
|
-
}
|
|
133
|
-
containsIdentifierName(m, identifierName) {
|
|
134
|
-
const callExpression = m.expression;
|
|
135
|
-
const identifier = callExpression.expression;
|
|
136
|
-
return identifier.text === identifierName;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.ValidateNestedDecoratorManager = ValidateNestedDecoratorManager;
|
|
140
|
-
//# sourceMappingURL=ValidateNestedDecoratorManager.js.map
|