thesimplevalidation 1.1.2 → 2.0.0

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 (123) hide show
  1. package/README.md +158 -140
  2. package/dist/Validation.d.ts +16 -0
  3. package/dist/Validation.js +99 -0
  4. package/dist/Validation.js.map +1 -0
  5. package/{src/validation-errors-model.ts → dist/ValidationErrorsModel.d.ts} +3 -3
  6. package/dist/ValidationErrorsModel.js +2 -0
  7. package/dist/ValidationErrorsModel.js.map +1 -0
  8. package/{src/validation-model.ts → dist/ValidationModel.d.ts} +3 -3
  9. package/dist/ValidationModel.js +2 -0
  10. package/dist/ValidationModel.js.map +1 -0
  11. package/dist/ValidationPropertyResult.d.ts +4 -0
  12. package/dist/ValidationPropertyResult.js +2 -0
  13. package/dist/ValidationPropertyResult.js.map +1 -0
  14. package/dist/ValidationResult.d.ts +8 -0
  15. package/dist/ValidationResult.js +2 -0
  16. package/dist/ValidationResult.js.map +1 -0
  17. package/dist/ValidationScope.d.ts +15 -0
  18. package/dist/ValidationScope.js +95 -0
  19. package/dist/ValidationScope.js.map +1 -0
  20. package/dist/Validator.d.ts +10 -0
  21. package/dist/Validator.js +28 -0
  22. package/dist/Validator.js.map +1 -0
  23. package/{src/validator-setup.ts → dist/ValidatorSetup.d.ts} +4 -4
  24. package/dist/ValidatorSetup.js +2 -0
  25. package/dist/ValidatorSetup.js.map +1 -0
  26. package/dist/index.d.ts +8 -1
  27. package/dist/index.js +5 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/validators/boolean/BooleanValidator.d.ts +7 -0
  30. package/dist/validators/boolean/BooleanValidator.js +18 -0
  31. package/dist/validators/boolean/BooleanValidator.js.map +1 -0
  32. package/dist/validators/boolean/BooleanValidatorSetup.d.ts +4 -0
  33. package/dist/validators/boolean/BooleanValidatorSetup.js +2 -0
  34. package/dist/validators/boolean/BooleanValidatorSetup.js.map +1 -0
  35. package/dist/validators/index.d.ts +9 -0
  36. package/dist/validators/index.js +6 -0
  37. package/dist/validators/index.js.map +1 -0
  38. package/dist/validators/max/MaxValidator.d.ts +7 -0
  39. package/dist/validators/max/MaxValidator.js +26 -0
  40. package/dist/validators/max/MaxValidator.js.map +1 -0
  41. package/dist/validators/max/MaxValidatorSetup.d.ts +4 -0
  42. package/dist/validators/max/MaxValidatorSetup.js +2 -0
  43. package/dist/validators/max/MaxValidatorSetup.js.map +1 -0
  44. package/dist/validators/min/MinValidator.d.ts +7 -0
  45. package/dist/validators/min/MinValidator.js +27 -0
  46. package/dist/validators/min/MinValidator.js.map +1 -0
  47. package/dist/validators/min/MinValidatorSetup.d.ts +4 -0
  48. package/dist/validators/min/MinValidatorSetup.js +2 -0
  49. package/dist/validators/min/MinValidatorSetup.js.map +1 -0
  50. package/dist/validators/required/RequiredValidator.d.ts +7 -0
  51. package/dist/validators/required/RequiredValidator.js +21 -0
  52. package/dist/validators/required/RequiredValidator.js.map +1 -0
  53. package/dist/validators/simple/SimpleValidator.d.ts +7 -0
  54. package/dist/validators/simple/SimpleValidator.js +14 -0
  55. package/dist/validators/simple/SimpleValidator.js.map +1 -0
  56. package/dist/validators/simple/SimpleValidatorSetup.d.ts +4 -0
  57. package/dist/validators/simple/SimpleValidatorSetup.js +2 -0
  58. package/dist/validators/simple/SimpleValidatorSetup.js.map +1 -0
  59. package/package.json +13 -16
  60. package/.editorconfig +0 -11
  61. package/.travis.yml +0 -7
  62. package/.yo-rc.json +0 -9
  63. package/dist/src/index.d.ts +0 -8
  64. package/dist/src/index.js +0 -11
  65. package/dist/src/index.js.map +0 -1
  66. package/dist/src/validation-errors-model.d.ts +0 -3
  67. package/dist/src/validation-errors-model.js +0 -3
  68. package/dist/src/validation-errors-model.js.map +0 -1
  69. package/dist/src/validation-model.d.ts +0 -3
  70. package/dist/src/validation-model.js +0 -3
  71. package/dist/src/validation-model.js.map +0 -1
  72. package/dist/src/validation-property-result.d.ts +0 -4
  73. package/dist/src/validation-property-result.js +0 -3
  74. package/dist/src/validation-property-result.js.map +0 -1
  75. package/dist/src/validation-result.d.ts +0 -8
  76. package/dist/src/validation-result.js +0 -3
  77. package/dist/src/validation-result.js.map +0 -1
  78. package/dist/src/validation-scope.d.ts +0 -19
  79. package/dist/src/validation-scope.js +0 -197
  80. package/dist/src/validation-scope.js.map +0 -1
  81. package/dist/src/validator-setup.d.ts +0 -4
  82. package/dist/src/validator-setup.js +0 -3
  83. package/dist/src/validator-setup.js.map +0 -1
  84. package/dist/src/validator.d.ts +0 -8
  85. package/dist/src/validator.js +0 -68
  86. package/dist/src/validator.js.map +0 -1
  87. package/dist/src/validators/boolean/index.d.ts +0 -10
  88. package/dist/src/validators/boolean/index.js +0 -77
  89. package/dist/src/validators/boolean/index.js.map +0 -1
  90. package/dist/src/validators/index.d.ts +0 -5
  91. package/dist/src/validators/index.js +0 -13
  92. package/dist/src/validators/index.js.map +0 -1
  93. package/dist/src/validators/max/index.d.ts +0 -11
  94. package/dist/src/validators/max/index.js +0 -86
  95. package/dist/src/validators/max/index.js.map +0 -1
  96. package/dist/src/validators/min/index.d.ts +0 -11
  97. package/dist/src/validators/min/index.js +0 -87
  98. package/dist/src/validators/min/index.js.map +0 -1
  99. package/dist/src/validators/required/index.d.ts +0 -7
  100. package/dist/src/validators/required/index.js +0 -81
  101. package/dist/src/validators/required/index.js.map +0 -1
  102. package/dist/src/validators/simple/index.d.ts +0 -10
  103. package/dist/src/validators/simple/index.js +0 -73
  104. package/dist/src/validators/simple/index.js.map +0 -1
  105. package/index.ts +0 -1
  106. package/jest.config.js +0 -192
  107. package/src/index.ts +0 -9
  108. package/src/validation-property-result.ts +0 -5
  109. package/src/validation-result.ts +0 -11
  110. package/src/validation-scope.ts +0 -118
  111. package/src/validator.ts +0 -25
  112. package/src/validators/boolean/index.ts +0 -27
  113. package/src/validators/index.ts +0 -5
  114. package/src/validators/max/__tests__/index.test.ts +0 -92
  115. package/src/validators/max/index.ts +0 -34
  116. package/src/validators/min/__tests__/index.test.ts +0 -92
  117. package/src/validators/min/index.ts +0 -35
  118. package/src/validators/required/__tests__/index.test.ts +0 -229
  119. package/src/validators/required/index.ts +0 -24
  120. package/src/validators/simple/index.ts +0 -22
  121. package/thesimplevalidation.code-workspace +0 -10
  122. package/tsconfig.json +0 -23
  123. package/tslint.json +0 -18
@@ -1,27 +0,0 @@
1
- import { IValidationPropertyResult } from "../../validation-property-result";
2
- import { IValidatorSetup } from "../../validator-setup";
3
- import { Validator } from "../../validator";
4
-
5
- export interface IBooleanValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
6
- target: () => boolean;
7
- }
8
-
9
- export class BooleanValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IBooleanValidatorSetup<TModel, K>> {
10
- constructor(setup: IBooleanValidatorSetup<TModel, K>) {
11
- super(setup);
12
- }
13
-
14
- public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
15
- let isValid: boolean = true;
16
- const targetValue: boolean = this.setup.target();
17
-
18
- if (value != null && typeof value === "boolean") {
19
- isValid = targetValue === value;
20
- }
21
-
22
- return {
23
- isValid: isValid,
24
- errors: []
25
- };
26
- }
27
- }
@@ -1,5 +0,0 @@
1
- export { SimpleValidator, ISimpleValidatorSetup } from "./simple";
2
- export { BooleanValidator, IBooleanValidatorSetup } from "./boolean";
3
- export { RequiredValidator } from "./required";
4
- export { MinValidator, IMinValidatorSetup } from "./min";
5
- export { MaxValidator, IMaxValidatorSetup } from "./max";
@@ -1,92 +0,0 @@
1
- import { MaxValidator } from "..";
2
-
3
- describe("[validation].[MaxValidator] checking", () => {
4
- test("[validation].[MaxValidator]: null", async () => {
5
- const validator = new MaxValidator<{ value: string | null }, "value">({
6
- maxValue: () => 1,
7
- });
8
- const result = await validator.isValidInternal(null);
9
- expect(result.isValid).toEqual(true);
10
- });
11
-
12
- test("[validation].[MaxValidator]: function", async () => {
13
- const validator = new MaxValidator<{ value: () => void; }, "value">({
14
- maxValue: () => 1
15
- });
16
- const result = await validator.isValidInternal(() => { return; });
17
- expect(result.isValid).toEqual(true);
18
- });
19
-
20
- test("[validation].[MaxValidator]: Empty String. Max=1", async () => {
21
- const validator = new MaxValidator<{ value: string; }, "value">({
22
- maxValue: () => 1
23
- });
24
- const result = await validator.isValidInternal("");
25
- expect(result.isValid).toEqual(true);
26
- });
27
-
28
- test("[validation].[MaxValidator]: Empty String. Max=0", async () => {
29
- const validator = new MaxValidator<{ value: string; }, "value">({
30
- maxValue: () => 0
31
- });
32
- const result = await validator.isValidInternal("");
33
- expect(result.isValid).toEqual(true);
34
- });
35
-
36
- test("[validation].[MaxValidator]: Empty Array. Max=1", async () => {
37
- const validator = new MaxValidator<{ value: string[]; }, "value">({
38
- maxValue: () => 1
39
- });
40
- const result = await validator.isValidInternal([]);
41
- expect(result.isValid).toEqual(true);
42
- });
43
-
44
- test("[validation].[MaxValidator]: Empty Array. Max=0", async () => {
45
- const validator = new MaxValidator<{ value: string[]; }, "value">({
46
- maxValue: () => 0
47
- });
48
- const result = await validator.isValidInternal([]);
49
- expect(result.isValid).toEqual(true);
50
- });
51
-
52
- test("[validation].[MaxValidator]: 0. Max=0", async () => {
53
- const validator = new MaxValidator<{ value: number; }, "value">({
54
- maxValue: () => 0
55
- });
56
- const result = await validator.isValidInternal(0);
57
- expect(result.isValid).toEqual(true);
58
- });
59
-
60
- test("[validation].[MaxValidator]: 0. Max=1", async () => {
61
- const validator = new MaxValidator<{ value: number; }, "value">({
62
- maxValue: () => 1
63
- });
64
- const result = await validator.isValidInternal(0);
65
- expect(result.isValid).toEqual(true);
66
- });
67
-
68
- test("[validation].[MaxValidator]: 1. Max=1", async () => {
69
- const validator = new MaxValidator<{ value: number; }, "value">({
70
- maxValue: () => 1
71
- });
72
- const result = await validator.isValidInternal(0);
73
- expect(result.isValid).toEqual(true);
74
- });
75
-
76
- test("[validation].[MaxValidator]: 2. Max=1", async () => {
77
- const validator = new MaxValidator<{ value: number; }, "value">({
78
- maxValue: () => 1
79
- });
80
- const result = await validator.isValidInternal(2);
81
- expect(result.isValid).toEqual(false);
82
- });
83
-
84
- test("[validation].[MaxValidator]: Disabled", async () => {
85
- const validator = new MaxValidator<{ value: number; }, "value">({
86
- maxValue: () => 1,
87
- isDisabled: () => true
88
- });
89
- const result = await validator.isValid(2, { value: 2 }, "value");
90
- expect(result.isValid).toEqual(true);
91
- });
92
- });
@@ -1,34 +0,0 @@
1
- import { IValidatorSetup } from "../../validator-setup";
2
- import { IValidationPropertyResult } from "../../validation-property-result";
3
- import { Validator } from "../../validator";
4
-
5
- export interface IMaxValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
6
- maxValue: () => number;
7
- converter?: (val: TModel[K]) => unknown;
8
- }
9
-
10
- export class MaxValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMaxValidatorSetup<TModel, K>> {
11
- constructor(setup: IMaxValidatorSetup<TModel, K>) {
12
- super(setup);
13
- }
14
-
15
- public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
16
- let isValid: boolean = true;
17
- const val: unknown = this.setup.converter ? this.setup.converter(value) : value;
18
- if (val != null) {
19
- const maxValue: number = this.setup.maxValue();
20
- if (Array.isArray(val)) {
21
- isValid = val.length <= maxValue;
22
- } else if (typeof val === "string") {
23
- isValid = val.length <= maxValue;
24
- } else if (typeof val === "number") {
25
- isValid = val <= maxValue;
26
- }
27
- }
28
-
29
- return {
30
- isValid: isValid,
31
- errors: []
32
- };
33
- }
34
- }
@@ -1,92 +0,0 @@
1
- import { MinValidator } from "..";
2
-
3
- describe("[validation].[MinValidator] checking", () => {
4
- test("[validation].[MinValidator]: null", async () => {
5
- const validator = new MinValidator<{ value: string | null; }, "value">({
6
- minValue: () => 1
7
- });
8
- const result = await validator.isValidInternal(null);
9
- expect(result.isValid).toEqual(true);
10
- });
11
-
12
- test("[validation].[MinValidator]: function", async () => {
13
- const validator = new MinValidator<{ value: () => void; }, "value">({
14
- minValue: () => 1
15
- });
16
- const result = await validator.isValidInternal(() => { return; });
17
- expect(result.isValid).toEqual(true);
18
- });
19
-
20
- test("[validation].[MinValidator]: Empty String. Min=1", async () => {
21
- const validator = new MinValidator<{ value: string; }, "value">({
22
- minValue: () => 1
23
- });
24
- const result = await validator.isValidInternal("");
25
- expect(result.isValid).toEqual(false);
26
- });
27
-
28
- test("[validation].[MinValidator]: Empty String. Min=0", async () => {
29
- const validator = new MinValidator<{ value: string; }, "value">({
30
- minValue: () => 0
31
- });
32
- const result = await validator.isValidInternal("");
33
- expect(result.isValid).toEqual(true);
34
- });
35
-
36
- test("[validation].[MinValidator]: Empty Array. Min=1", async () => {
37
- const validator = new MinValidator<{ value: string[]; }, "value">({
38
- minValue: () => 1
39
- });
40
- const result = await validator.isValidInternal([]);
41
- expect(result.isValid).toEqual(false);
42
- });
43
-
44
- test("[validation].[MinValidator]: Empty Array. Min=0", async () => {
45
- const validator = new MinValidator<{ value: string[]; }, "value">({
46
- minValue: () => 0
47
- });
48
- const result = await validator.isValidInternal([]);
49
- expect(result.isValid).toEqual(true);
50
- });
51
-
52
- test("[validation].[MinValidator]: 0. Min=0", async () => {
53
- const validator = new MinValidator<{ value: number; }, "value">({
54
- minValue: () => 0
55
- });
56
- const result = await validator.isValidInternal(0);
57
- expect(result.isValid).toEqual(true);
58
- });
59
-
60
- test("[validation].[MinValidator]: 0. Min=1", async () => {
61
- const validator = new MinValidator<{ value: number; }, "value">({
62
- minValue: () => 1
63
- });
64
- const result = await validator.isValidInternal(0);
65
- expect(result.isValid).toEqual(false);
66
- });
67
-
68
- test("[validation].[MinValidator]: 1. Min=1", async () => {
69
- const validator = new MinValidator<{ value: number; }, "value">({
70
- minValue: () => 1
71
- });
72
- const result = await validator.isValidInternal(0);
73
- expect(result.isValid).toEqual(false);
74
- });
75
-
76
- test("[validation].[MinValidator]: 8. Min=9", async () => {
77
- const validator = new MinValidator<{ value: number; }, "value">({
78
- minValue: () => 9
79
- });
80
- const result = await validator.isValidInternal(8);
81
- expect(result.isValid).toEqual(false);
82
- });
83
-
84
- test("[validation].[MinValidator]: Disabled", async () => {
85
- const validator = new MinValidator<{ value: number; }, "value">({
86
- minValue: () => 9,
87
- isDisabled: () => true
88
- });
89
- const result = await validator.isValid(8, { value: 8 }, "value");
90
- expect(result.isValid).toEqual(true);
91
- });
92
- });
@@ -1,35 +0,0 @@
1
- import { IValidationPropertyResult } from "../../validation-property-result";
2
- import { IValidatorSetup } from "../../validator-setup";
3
- import { Validator } from "../../validator";
4
-
5
- export interface IMinValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
6
- minValue: () => number;
7
- converter?: (val: TModel[K]) => unknown;
8
- }
9
-
10
- export class MinValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMinValidatorSetup<TModel, K>> {
11
- constructor(setup: IMinValidatorSetup<TModel, K>) {
12
- super(setup);
13
- }
14
-
15
- public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
16
- let isValid: boolean = true;
17
- const val: unknown = this.setup.converter ? this.setup.converter(value) : value;
18
- if (val != null) {
19
- const minValue: number = this.setup.minValue();
20
- // tslint:disable-next-line:prefer-conditional-expression
21
- if (Array.isArray(val)) {
22
- isValid = val.length >= minValue;
23
- } else if (typeof val === "string") {
24
- isValid = val.length >= minValue;
25
- } else if (typeof val === "number") {
26
- isValid = val >= minValue;
27
- }
28
- }
29
-
30
- return {
31
- isValid: isValid,
32
- errors: []
33
- };
34
- }
35
- }
@@ -1,229 +0,0 @@
1
- import { Validator } from "../../../validator";
2
- import { RequiredValidator } from "..";
3
-
4
- // String check
5
- test("[validation].[RequiredValidator]: check null string", async () => {
6
- interface IModelType {
7
- val: string | null;
8
- }
9
-
10
- const model: IModelType = {
11
- val: null
12
- };
13
-
14
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
15
- getErrors: () => ["Error.Message"]
16
- });
17
- await expect(validator.isValid(model.val, model, "val"))
18
- .resolves
19
- .toEqual({ errors: ["Error.Message"], isValid: false });
20
- });
21
-
22
- test("[validation].[RequiredValidator]: check empty string", async () => {
23
- interface IModelType {
24
- val: string | null;
25
- }
26
-
27
- const model: IModelType = {
28
- val: ""
29
- };
30
-
31
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
32
- getErrors: () => ["Error.Message"]
33
- });
34
- await expect(validator.isValid(model.val, model, "val"))
35
- .resolves
36
- .toEqual({ errors: ["Error.Message"], isValid: false });
37
- });
38
-
39
- test("[validation].[RequiredValidator]: check non-empty string", async () => {
40
- interface IModelType {
41
- val: string | null;
42
- }
43
-
44
- const model: IModelType = {
45
- val: "HelloWorld"
46
- };
47
-
48
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
49
- getErrors: () => ["Error.Message"]
50
- });
51
- await expect(validator.isValid(model.val, model, "val"))
52
- .resolves
53
- .toEqual({ errors: [], isValid: true });
54
- });
55
-
56
- // Number check
57
- test("[validation].[RequiredValidator]: check null number", async () => {
58
- interface IModelType {
59
- val: number | null;
60
- }
61
-
62
- const model: IModelType = {
63
- val: null
64
- };
65
-
66
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
67
- getErrors: () => ["Error.Message"]
68
- });
69
- await expect(validator.isValid(model.val, model, "val"))
70
- .resolves
71
- .toEqual({ errors: ["Error.Message"], isValid: false });
72
- });
73
-
74
- test("[validation].[RequiredValidator]: check 0 number", async () => {
75
- interface IModelType {
76
- val: number | null;
77
- }
78
-
79
- const model: IModelType = {
80
- val: 0
81
- };
82
-
83
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
84
- getErrors: () => ["Error.Message"]
85
- });
86
- await expect(validator.isValid(model.val, model, "val"))
87
- .resolves
88
- .toEqual({ errors: ["Error.Message"], isValid: false });
89
- });
90
-
91
- test("[validation].[RequiredValidator]: check > 0 number", async () => {
92
- interface IModelType {
93
- val: number | null;
94
- }
95
-
96
- const model: IModelType = {
97
- val: 0.1
98
- };
99
-
100
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
101
- getErrors: () => ["Error.Message"]
102
- });
103
- await expect(validator.isValid(model.val, model, "val"))
104
- .resolves
105
- .toEqual({ errors: [], isValid: true });
106
- });
107
-
108
- test("[validation].[RequiredValidator]: check < 0 number", async () => {
109
- interface IModelType {
110
- val: number | null;
111
- }
112
-
113
- const model: IModelType = {
114
- val: -0.1
115
- };
116
-
117
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
118
- getErrors: () => ["Error.Message"]
119
- });
120
- await expect(validator.isValid(model.val, model, "val"))
121
- .resolves
122
- .toEqual({ errors: [], isValid: true });
123
- });
124
-
125
- // Array check
126
- test("[validation].[RequiredValidator]: check null array", async () => {
127
- interface IModelType {
128
- val: string[] | null;
129
- }
130
-
131
- const model: IModelType = {
132
- val: null
133
- };
134
-
135
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
136
- getErrors: () => ["Error.Message"]
137
- });
138
- await expect(validator.isValid(model.val, model, "val"))
139
- .resolves
140
- .toEqual({ errors: ["Error.Message"], isValid: false });
141
- });
142
-
143
- test("[validation].[RequiredValidator]: check empty array", async () => {
144
- interface IModelType {
145
- val: string[] | null;
146
- }
147
-
148
- const model: IModelType = {
149
- val: []
150
- };
151
-
152
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
153
- getErrors: () => ["Error.Message"]
154
- });
155
- await expect(validator.isValid(model.val, model, "val"))
156
- .resolves
157
- .toEqual({ errors: ["Error.Message"], isValid: false });
158
- });
159
-
160
- test("[validation].[RequiredValidator]: check non-empty array", async () => {
161
- interface IModelType {
162
- val: string[] | null;
163
- }
164
-
165
- const model: IModelType = {
166
- val: ["HelloWorld"]
167
- };
168
-
169
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
170
- getErrors: () => ["Error.Message"]
171
- });
172
- await expect(validator.isValid(model.val, model, "val"))
173
- .resolves
174
- .toEqual({ errors: [], isValid: true });
175
- });
176
-
177
- // Object check
178
- test("[validation].[RequiredValidator]: check null object", async () => {
179
- interface IModelType {
180
- val: {} | null;
181
- }
182
-
183
- const model: IModelType = {
184
- val: null
185
- };
186
-
187
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
188
- getErrors: () => ["Error.Message"]
189
- });
190
- await expect(validator.isValid(model.val, model, "val"))
191
- .resolves
192
- .toEqual({ errors: ["Error.Message"], isValid: false });
193
- });
194
-
195
- test("[validation].[RequiredValidator]: check non-null object", async () => {
196
- interface IModelType {
197
- val: {} | null;
198
- }
199
-
200
- const model: IModelType = {
201
- val: {}
202
- };
203
-
204
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
205
- getErrors: () => ["Error.Message"]
206
- });
207
- await expect(validator.isValid(model.val, model, "val"))
208
- .resolves
209
- .toEqual({ errors: [], isValid: true });
210
- });
211
-
212
- // Disabling
213
- test("[validation].[RequiredValidator]: disabling check", async () => {
214
- interface IModelType {
215
- val: {} | null;
216
- }
217
-
218
- const model: IModelType = {
219
- val: null
220
- };
221
-
222
- const validator: Validator<IModelType, "val"> = new RequiredValidator({
223
- getErrors: () => ["Error.Message"],
224
- isDisabled: () => true
225
- });
226
- await expect(validator.isValid(model.val, model, "val"))
227
- .resolves
228
- .toEqual({ errors: [], isValid: true });
229
- });
@@ -1,24 +0,0 @@
1
- import { IValidationPropertyResult } from "../../validation-property-result";
2
- import { IValidatorSetup } from "../../validator-setup";
3
- import { Validator } from "../../validator";
4
-
5
- export class RequiredValidator<TModel, K extends keyof TModel> extends Validator<TModel, K> {
6
- constructor(setup: IValidatorSetup<TModel, K> = {}) {
7
- super(setup);
8
- }
9
-
10
- public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
11
- let isValid: boolean = true;
12
- // tslint:disable-next-line:prefer-conditional-expression
13
- if (Array.isArray(value)) {
14
- isValid = value.length > 0;
15
- } else {
16
- isValid = !!value;
17
- }
18
-
19
- return {
20
- isValid: isValid,
21
- errors: []
22
- };
23
- }
24
- }
@@ -1,22 +0,0 @@
1
- import { IValidationPropertyResult } from "../../validation-property-result";
2
- import { IValidatorSetup } from "../../validator-setup";
3
- import { Validator } from "../../validator";
4
-
5
- export interface ISimpleValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
6
- getValidation: () => boolean;
7
- }
8
-
9
- export class SimpleValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, ISimpleValidatorSetup<TModel, K>> {
10
- constructor(setup: ISimpleValidatorSetup<TModel, K>) {
11
- super(setup);
12
- }
13
-
14
- public async isValidInternal(_value: TModel[K]): Promise<IValidationPropertyResult> {
15
- const isValid: boolean = this.setup.getValidation();
16
-
17
- return {
18
- isValid: isValid,
19
- errors: []
20
- };
21
- }
22
- }
@@ -1,10 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- }
6
- ],
7
- "settings": {
8
- "typescript.tsdk": "node_modules\\typescript\\lib"
9
- }
10
- }
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "sourceMap": true,
5
- "declaration": true,
6
- "noImplicitAny": true,
7
- "module": "commonjs",
8
- "moduleResolution": "node",
9
- "esModuleInterop": true,
10
- "noUnusedLocals": true,
11
- "noImplicitReturns": true,
12
- "traceResolution": false,
13
- "allowSyntheticDefaultImports": true,
14
- "target": "es5",
15
- "lib": [
16
- "dom",
17
- "es2015"
18
- ]
19
- },
20
- "include": [
21
- "./index.ts"
22
- ]
23
- }
package/tslint.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "defaultSeverity": "error",
3
- "extends": [
4
- "tslint:recommended"
5
- ],
6
- "jsRules": {},
7
- "rules": {
8
- "curly": [true, "ignore-same-line"],
9
- "object-literal-shorthand": [true, "never"],
10
- "trailing-comma": false,
11
- "object-literal-sort-keys": false,
12
- "max-line-length": false,
13
- "no-console": false,
14
- "arrow-parens": false,
15
- "ordered-imports": false
16
- },
17
- "rulesDirectory": []
18
- }