thesimplevalidation 1.2.0 → 2.1.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/dist/ValidationErrorsModel.js +2 -0
  6. package/dist/ValidationErrorsModel.js.map +1 -0
  7. package/dist/ValidationModel.js +2 -0
  8. package/dist/ValidationModel.js.map +1 -0
  9. package/dist/ValidationPropertyResult.d.ts +4 -0
  10. package/dist/ValidationPropertyResult.js +2 -0
  11. package/dist/ValidationPropertyResult.js.map +1 -0
  12. package/dist/ValidationResult.d.ts +8 -0
  13. package/dist/ValidationResult.js +2 -0
  14. package/dist/ValidationResult.js.map +1 -0
  15. package/dist/ValidationScope.d.ts +15 -0
  16. package/dist/ValidationScope.js +95 -0
  17. package/dist/ValidationScope.js.map +1 -0
  18. package/dist/Validator.d.ts +10 -0
  19. package/dist/Validator.js +28 -0
  20. package/dist/Validator.js.map +1 -0
  21. package/dist/{src/validator-setup.d.ts → ValidatorSetup.d.ts} +2 -2
  22. package/dist/ValidatorSetup.js +2 -0
  23. package/dist/ValidatorSetup.js.map +1 -0
  24. package/dist/index.d.ts +8 -1
  25. package/dist/index.js +5 -17
  26. package/dist/index.js.map +1 -1
  27. package/dist/validators/boolean/BooleanValidator.d.ts +7 -0
  28. package/dist/validators/boolean/BooleanValidator.js +18 -0
  29. package/dist/validators/boolean/BooleanValidator.js.map +1 -0
  30. package/dist/validators/boolean/BooleanValidatorSetup.d.ts +4 -0
  31. package/dist/validators/boolean/BooleanValidatorSetup.js +2 -0
  32. package/dist/validators/boolean/BooleanValidatorSetup.js.map +1 -0
  33. package/dist/validators/index.d.ts +9 -0
  34. package/dist/validators/index.js +6 -0
  35. package/dist/validators/index.js.map +1 -0
  36. package/dist/validators/max/MaxValidator.d.ts +7 -0
  37. package/dist/validators/max/MaxValidator.js +26 -0
  38. package/dist/validators/max/MaxValidator.js.map +1 -0
  39. package/dist/validators/max/MaxValidatorSetup.d.ts +4 -0
  40. package/dist/validators/max/MaxValidatorSetup.js +2 -0
  41. package/dist/validators/max/MaxValidatorSetup.js.map +1 -0
  42. package/dist/validators/min/MinValidator.d.ts +7 -0
  43. package/dist/validators/min/MinValidator.js +27 -0
  44. package/dist/validators/min/MinValidator.js.map +1 -0
  45. package/dist/validators/min/MinValidatorSetup.d.ts +4 -0
  46. package/dist/validators/min/MinValidatorSetup.js +2 -0
  47. package/dist/validators/min/MinValidatorSetup.js.map +1 -0
  48. package/dist/validators/required/RequiredValidator.d.ts +7 -0
  49. package/dist/validators/required/RequiredValidator.js +21 -0
  50. package/dist/validators/required/RequiredValidator.js.map +1 -0
  51. package/dist/validators/simple/SimpleValidator.d.ts +7 -0
  52. package/dist/validators/simple/SimpleValidator.js +14 -0
  53. package/dist/validators/simple/SimpleValidator.js.map +1 -0
  54. package/dist/validators/simple/SimpleValidatorSetup.d.ts +4 -0
  55. package/dist/validators/simple/SimpleValidatorSetup.js +2 -0
  56. package/dist/validators/simple/SimpleValidatorSetup.js.map +1 -0
  57. package/package.json +12 -12
  58. package/.editorconfig +0 -11
  59. package/.travis.yml +0 -7
  60. package/.yo-rc.json +0 -9
  61. package/dist/src/index.d.ts +0 -8
  62. package/dist/src/index.js +0 -23
  63. package/dist/src/index.js.map +0 -1
  64. package/dist/src/validation-errors-model.js +0 -3
  65. package/dist/src/validation-errors-model.js.map +0 -1
  66. package/dist/src/validation-model.js +0 -3
  67. package/dist/src/validation-model.js.map +0 -1
  68. package/dist/src/validation-property-result.d.ts +0 -4
  69. package/dist/src/validation-property-result.js +0 -3
  70. package/dist/src/validation-property-result.js.map +0 -1
  71. package/dist/src/validation-result.d.ts +0 -8
  72. package/dist/src/validation-result.js +0 -3
  73. package/dist/src/validation-result.js.map +0 -1
  74. package/dist/src/validation-scope.d.ts +0 -19
  75. package/dist/src/validation-scope.js +0 -200
  76. package/dist/src/validation-scope.js.map +0 -1
  77. package/dist/src/validator-setup.js +0 -3
  78. package/dist/src/validator-setup.js.map +0 -1
  79. package/dist/src/validator.d.ts +0 -8
  80. package/dist/src/validator.js +0 -69
  81. package/dist/src/validator.js.map +0 -1
  82. package/dist/src/validators/boolean/index.d.ts +0 -10
  83. package/dist/src/validators/boolean/index.js +0 -80
  84. package/dist/src/validators/boolean/index.js.map +0 -1
  85. package/dist/src/validators/index.d.ts +0 -5
  86. package/dist/src/validators/index.js +0 -14
  87. package/dist/src/validators/index.js.map +0 -1
  88. package/dist/src/validators/max/index.d.ts +0 -10
  89. package/dist/src/validators/max/index.js +0 -88
  90. package/dist/src/validators/max/index.js.map +0 -1
  91. package/dist/src/validators/min/index.d.ts +0 -10
  92. package/dist/src/validators/min/index.js +0 -89
  93. package/dist/src/validators/min/index.js.map +0 -1
  94. package/dist/src/validators/required/index.d.ts +0 -7
  95. package/dist/src/validators/required/index.js +0 -84
  96. package/dist/src/validators/required/index.js.map +0 -1
  97. package/dist/src/validators/simple/index.d.ts +0 -10
  98. package/dist/src/validators/simple/index.js +0 -76
  99. package/dist/src/validators/simple/index.js.map +0 -1
  100. package/index.ts +0 -1
  101. package/jest.config.js +0 -192
  102. package/src/index.ts +0 -9
  103. package/src/validation-errors-model.ts +0 -3
  104. package/src/validation-model.ts +0 -3
  105. package/src/validation-property-result.ts +0 -5
  106. package/src/validation-result.ts +0 -11
  107. package/src/validation-scope.ts +0 -119
  108. package/src/validator-setup.ts +0 -4
  109. package/src/validator.ts +0 -25
  110. package/src/validators/boolean/index.ts +0 -27
  111. package/src/validators/index.ts +0 -5
  112. package/src/validators/max/__tests__/index.test.ts +0 -92
  113. package/src/validators/max/index.ts +0 -32
  114. package/src/validators/min/__tests__/index.test.ts +0 -92
  115. package/src/validators/min/index.ts +0 -33
  116. package/src/validators/required/__tests__/index.test.ts +0 -229
  117. package/src/validators/required/index.ts +0 -24
  118. package/src/validators/simple/index.ts +0 -22
  119. package/thesimplevalidation.code-workspace +0 -10
  120. package/tsconfig.json +0 -23
  121. package/tslint.json +0 -18
  122. /package/dist/{src/validation-errors-model.d.ts → ValidationErrorsModel.d.ts} +0 -0
  123. /package/dist/{src/validation-model.d.ts → ValidationModel.d.ts} +0 -0
package/src/validator.ts DELETED
@@ -1,25 +0,0 @@
1
- import { IValidationPropertyResult } from "./validation-property-result";
2
- import { IValidatorSetup } from "./validator-setup";
3
-
4
- export abstract class Validator<TModel, K extends keyof TModel, TSetup extends IValidatorSetup<TModel, K> = IValidatorSetup<TModel, K>> {
5
-
6
- constructor(protected setup: TSetup) { }
7
-
8
- public isValid = async (value: TModel[K], model: TModel, field: K): Promise<IValidationPropertyResult> => {
9
- if (this.setup.isDisabled != null && this.setup.isDisabled(value)) {
10
- return {
11
- isValid: true,
12
- errors: []
13
- };
14
- }
15
-
16
- const result: IValidationPropertyResult = await this.isValidInternal(value, model, field);
17
- if (result.isValid !== true && this.setup.getErrors != null) {
18
- result.errors = this.setup.getErrors(value);
19
- }
20
-
21
- return result;
22
- }
23
-
24
- protected abstract isValidInternal(value: TModel[K], model: TModel, field: K): Promise<IValidationPropertyResult>;
25
- }
@@ -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,32 +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
- }
8
-
9
- export class MaxValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMaxValidatorSetup<TModel, K>> {
10
- constructor(setup: IMaxValidatorSetup<TModel, K>) {
11
- super(setup);
12
- }
13
-
14
- public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
15
- let isValid: boolean = true;
16
- if (value != null) {
17
- const maxValue: number = this.setup.maxValue();
18
- if (Array.isArray(value)) {
19
- isValid = value.length <= maxValue;
20
- } else if (typeof value === "string") {
21
- isValid = value.length <= maxValue;
22
- } else if (typeof value === "number") {
23
- isValid = value <= maxValue;
24
- }
25
- }
26
-
27
- return {
28
- isValid: isValid,
29
- errors: []
30
- };
31
- }
32
- }
@@ -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,33 +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
- }
8
-
9
- export class MinValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMinValidatorSetup<TModel, K>> {
10
- constructor(setup: IMinValidatorSetup<TModel, K>) {
11
- super(setup);
12
- }
13
-
14
- public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
15
- let isValid: boolean = true;
16
- if (value != null) {
17
- const minValue: number = this.setup.minValue();
18
- // tslint:disable-next-line:prefer-conditional-expression
19
- if (Array.isArray(value)) {
20
- isValid = value.length >= minValue;
21
- } else if (typeof value === "string") {
22
- isValid = value.length >= minValue;
23
- } else if (typeof value === "number") {
24
- isValid = value >= minValue;
25
- }
26
- }
27
-
28
- return {
29
- isValid: isValid,
30
- errors: []
31
- };
32
- }
33
- }
@@ -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
- }