@platecms/delta-validation 0.13.0 → 1.2.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.
- package/package.json +4 -4
- package/src/lib/helpers/rule-to-schema.spec.ts +4 -4
- package/src/lib/helpers/validate-with-function.spec.ts +3 -3
- package/src/lib/schemas/array.schema.spec.ts +1 -1
- package/src/lib/schemas/content-value.schema.spec.ts +5 -5
- package/src/lib/schemas/date.schema.spec.ts +1 -1
- package/src/lib/schemas/string.schema.spec.ts +1 -1
- package/src/lib/validation-rules/allowed-values.validation-rule.spec.ts +5 -5
- package/src/lib/validation-rules/count.validation-rule.spec.ts +1 -1
- package/src/lib/validation-rules/date-between.validation-rule.spec.ts +1 -1
- package/src/lib/validation-rules/date-between.validation-rule.ts +4 -4
- package/src/lib/validation-rules/decimal-count.validation-rule.spec.ts +1 -1
- package/src/lib/validation-rules/number-between.validation-rule.spec.ts +1 -1
- package/src/lib/validation-rules/relatable-content-types.validation-rule.spec.ts +5 -5
- package/src/lib/validation-rules/string-format.validation-rule.spec.ts +1 -1
- package/src/lib/validation-rules/value-type.validation-rule.spec.ts +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-validation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "This package contains the validation system for Plate.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"src/**/*"
|
|
18
18
|
],
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@platecms/delta-cast": "
|
|
21
|
-
"@platecms/delta-plate-resource-notation": "
|
|
22
|
-
"@platecms/delta-types": "
|
|
20
|
+
"@platecms/delta-cast": "1.2.0",
|
|
21
|
+
"@platecms/delta-plate-resource-notation": "1.2.0",
|
|
22
|
+
"@platecms/delta-types": "1.2.0",
|
|
23
23
|
"class-transformer": "0.5.1",
|
|
24
24
|
"reflect-metadata": "0.2.2",
|
|
25
25
|
"tslib": "2.8.1"
|
|
@@ -5,14 +5,14 @@ import { ArrayValidationSchema } from "../schemas/array.schema";
|
|
|
5
5
|
import { ruleToSchema } from "./rule-to-schema";
|
|
6
6
|
|
|
7
7
|
describe("ruleToSchema", () => {
|
|
8
|
-
const mockPrn = PRN.fromString("prn:plate:-1:
|
|
8
|
+
const mockPrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
9
9
|
|
|
10
10
|
describe("ALLOWED_VALUES rule", () => {
|
|
11
11
|
it("converts ALLOWED_VALUES rule to array schema with inner content-value schema", () => {
|
|
12
12
|
const rule = {
|
|
13
13
|
ruleType: RuleType.ALLOWED_VALUES,
|
|
14
14
|
settings: { allowedValues: ["option1", "option2", "option3"] },
|
|
15
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
15
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const schema = ruleToSchema(rule);
|
|
@@ -68,7 +68,7 @@ describe("ruleToSchema", () => {
|
|
|
68
68
|
const rule = {
|
|
69
69
|
ruleType: RuleType.STRING_FORMAT,
|
|
70
70
|
settings: { allowedFormat: ".*@.*\\..*" },
|
|
71
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
71
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
const schema = ruleToSchema(rule);
|
|
@@ -241,7 +241,7 @@ describe("ruleToSchema", () => {
|
|
|
241
241
|
const rule = {
|
|
242
242
|
ruleType: RuleType.RELATABLE_CONTENT_TYPES,
|
|
243
243
|
settings: { allowedTypes: [ContentValueTypeNames.STRING, ContentValueTypeNames.NUMBER] },
|
|
244
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
244
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
245
245
|
};
|
|
246
246
|
|
|
247
247
|
const schema = ruleToSchema(rule);
|
|
@@ -6,7 +6,7 @@ import { RuleType } from "../enums/rule-types.enum";
|
|
|
6
6
|
import { validateWithFunction } from "./validate-with-function";
|
|
7
7
|
|
|
8
8
|
describe("validate-with-function", () => {
|
|
9
|
-
const mockRulePrn = PRN.fromString("prn:plate:-1:
|
|
9
|
+
const mockRulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
10
10
|
const mockPath = ["content-type-prn", "content-field-prn"];
|
|
11
11
|
const fallbackErrorMessage = "Validation failed";
|
|
12
12
|
|
|
@@ -182,7 +182,7 @@ describe("validate-with-function", () => {
|
|
|
182
182
|
|
|
183
183
|
// Test with PRN
|
|
184
184
|
const prnResult = validateWithFunction(
|
|
185
|
-
PRN.fromString("prn:plate:-1:
|
|
185
|
+
PRN.fromString("prn:plate:-1:cms:content-item:1"),
|
|
186
186
|
mockRule,
|
|
187
187
|
mockPath,
|
|
188
188
|
fallbackErrorMessage,
|
|
@@ -229,7 +229,7 @@ describe("validate-with-function", () => {
|
|
|
229
229
|
42,
|
|
230
230
|
true,
|
|
231
231
|
new Date("2023-01-01"),
|
|
232
|
-
PRN.fromString("prn:plate:-1:
|
|
232
|
+
PRN.fromString("prn:plate:-1:cms:content-item:1"),
|
|
233
233
|
{ type: "root", children: [] },
|
|
234
234
|
];
|
|
235
235
|
|
|
@@ -105,7 +105,7 @@ describe("ArrayValidationSchema", () => {
|
|
|
105
105
|
ruleType: RuleType.COUNT,
|
|
106
106
|
settings: { min: 2, max: 4 },
|
|
107
107
|
id: "count-rule",
|
|
108
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
108
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
const schemaWithRule = new ArrayValidationSchema<ContentValueType>(mockRule);
|
|
@@ -37,7 +37,7 @@ describe("ContentValueValidationSchema", () => {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it("passes validation when value is a PRN", () => {
|
|
40
|
-
const prn = PRN.fromString("prn:plate:-1:
|
|
40
|
+
const prn = PRN.fromString("prn:plate:-1:cms:content-item:1");
|
|
41
41
|
const result = schema.validate(prn, { path: ["test"] });
|
|
42
42
|
expect(result.isValid).toBe(true);
|
|
43
43
|
expect(result.errors).toHaveLength(0);
|
|
@@ -92,10 +92,10 @@ describe("ContentValueValidationSchema", () => {
|
|
|
92
92
|
|
|
93
93
|
describe("allowed content types validation", () => {
|
|
94
94
|
it("passes validation when PRN content type is in allowed types", () => {
|
|
95
|
-
const allowedTypes = [PRN.fromString("prn:plate:-1:
|
|
95
|
+
const allowedTypes = [PRN.fromString("prn:plate:-1:cms:content-item:1")];
|
|
96
96
|
schema.allowedContentTypes(allowedTypes);
|
|
97
97
|
|
|
98
|
-
const prn = PRN.fromString("prn:plate:-1:
|
|
98
|
+
const prn = PRN.fromString("prn:plate:-1:cms:content-item:1");
|
|
99
99
|
const result = schema.validate(prn, { path: ["test"] });
|
|
100
100
|
expect(result.isValid).toBe(true);
|
|
101
101
|
expect(result.errors).toHaveLength(0);
|
|
@@ -106,7 +106,7 @@ describe("ContentValueValidationSchema", () => {
|
|
|
106
106
|
const mockRule = {
|
|
107
107
|
ruleType: RuleType.VALUE_TYPE,
|
|
108
108
|
settings: { allowedTypes: allowedValueTypes },
|
|
109
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
109
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
const schemaWithRule = new ContentValueValidationSchema(mockRule).allowedValueTypes(allowedValueTypes);
|
|
@@ -119,7 +119,7 @@ describe("ContentValueValidationSchema", () => {
|
|
|
119
119
|
describe("method chaining", () => {
|
|
120
120
|
it("supports method chaining", () => {
|
|
121
121
|
const allowedValueTypes = [ContentValueTypeNames.STRING, ContentValueTypeNames.NUMBER];
|
|
122
|
-
const allowedContentTypes = [PRN.fromString("prn:plate:-1:
|
|
122
|
+
const allowedContentTypes = [PRN.fromString("prn:plate:-1:cms:content-item:1")];
|
|
123
123
|
|
|
124
124
|
const result = schema
|
|
125
125
|
.allowedValueTypes(allowedValueTypes)
|
|
@@ -88,7 +88,7 @@ describe("DateValidationSchema", () => {
|
|
|
88
88
|
const mockRule = {
|
|
89
89
|
ruleType: RuleType.DATE_BETWEEN,
|
|
90
90
|
settings: { start: startDate, end: endDate },
|
|
91
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
91
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
schema = new DateValidationSchema(mockRule).start(startDate).end(endDate);
|
|
@@ -88,7 +88,7 @@ describe("StringValidationSchema", () => {
|
|
|
88
88
|
const mockRule = {
|
|
89
89
|
ruleType: RuleType.STRING_FORMAT,
|
|
90
90
|
settings: { allowedFormat: ".*@.*\\..*" },
|
|
91
|
-
prn: PRN.fromString("prn:plate:-1:
|
|
91
|
+
prn: PRN.fromString("prn:plate:-1:cms:validation-rule:1"),
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
const schemaWithRule = new StringValidationSchema(mockRule);
|
|
@@ -6,7 +6,7 @@ describe("AllowedValuesValidationRule", () => {
|
|
|
6
6
|
let rulePrn: PRN;
|
|
7
7
|
|
|
8
8
|
beforeEach(() => {
|
|
9
|
-
rulePrn = PRN.fromString("prn:plate:-1:
|
|
9
|
+
rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
describe("validate", () => {
|
|
@@ -14,7 +14,7 @@ describe("AllowedValuesValidationRule", () => {
|
|
|
14
14
|
let rule: AllowedValuesValidationRule;
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
17
|
-
const allowedValues = [1, "2", true, new Date("2020-01-01"), PRN.fromString("prn:plate:-1:
|
|
17
|
+
const allowedValues = [1, "2", true, new Date("2020-01-01"), PRN.fromString("prn:plate:-1:cms:content-item:1")];
|
|
18
18
|
rule = new AllowedValuesValidationRule(rulePrn, { allowedValues });
|
|
19
19
|
});
|
|
20
20
|
|
|
@@ -28,8 +28,8 @@ describe("AllowedValuesValidationRule", () => {
|
|
|
28
28
|
false,
|
|
29
29
|
new Date("2020-01-01"),
|
|
30
30
|
new Date("2020-01-02"),
|
|
31
|
-
PRN.fromString("prn:plate:-1:
|
|
32
|
-
PRN.fromString("prn:plate:-1:
|
|
31
|
+
PRN.fromString("prn:plate:-1:cms:content-item:1"),
|
|
32
|
+
PRN.fromString("prn:plate:-1:cms:content-item:2"),
|
|
33
33
|
]);
|
|
34
34
|
expect(result).toBeContentValidationResult([true, false, true, false, true, false, true, false, true, false]);
|
|
35
35
|
});
|
|
@@ -48,7 +48,7 @@ describe("AllowedValuesValidationRule", () => {
|
|
|
48
48
|
[1, false],
|
|
49
49
|
[true, false],
|
|
50
50
|
[new Date("2020-01-01"), false],
|
|
51
|
-
[PRN.fromString("prn:plate:-1:
|
|
51
|
+
[PRN.fromString("prn:plate:-1:cms:content-item:1"), false],
|
|
52
52
|
])("returns false if the value is %s", (value, expected) => {
|
|
53
53
|
expect(rule.validate([value])).toBeContentValidationResult([expected]);
|
|
54
54
|
});
|
|
@@ -3,7 +3,7 @@ import { InvalidValidationRuleSettingsError } from "../errors/invalid-validation
|
|
|
3
3
|
import { CountValidationRule } from "./count.validation-rule";
|
|
4
4
|
|
|
5
5
|
describe("CountValidationRule", () => {
|
|
6
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
6
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
7
7
|
|
|
8
8
|
describe("constructor", () => {
|
|
9
9
|
it("throws an error if neither min nor max are provided", () => {
|
|
@@ -3,7 +3,7 @@ import { InvalidValidationRuleSettingsError } from "../errors/invalid-validation
|
|
|
3
3
|
import { DateBetweenValidationRule } from "./date-between.validation-rule";
|
|
4
4
|
|
|
5
5
|
describe("DateBetweenValidationRule", () => {
|
|
6
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
6
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
7
7
|
|
|
8
8
|
describe("constructor", () => {
|
|
9
9
|
it("throws an error if min and max are not provided", () => {
|
|
@@ -15,15 +15,15 @@ export function validateValueDateBetween(
|
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
if (ruleInstance.settings.start != null && value < ruleInstance.settings.start) {
|
|
18
|
+
if (ruleInstance.settings.start != null && value < new Date(ruleInstance.settings.start as unknown as Date)) {
|
|
19
19
|
return new ValidationErrorDetails(
|
|
20
|
-
`The date must be greater than or equal ${ruleInstance.settings.start.toDateString()}`,
|
|
20
|
+
`The date must be greater than or equal ${new Date(ruleInstance.settings.start).toDateString()}`,
|
|
21
21
|
ruleInstance,
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
|
-
if (ruleInstance.settings.end != null && value > ruleInstance.settings.end) {
|
|
24
|
+
if (ruleInstance.settings.end != null && value > new Date(ruleInstance.settings.end)) {
|
|
25
25
|
return new ValidationErrorDetails(
|
|
26
|
-
`The date must be lower than or equal ${ruleInstance.settings.end.toDateString()}`,
|
|
26
|
+
`The date must be lower than or equal ${new Date(ruleInstance.settings.end).toDateString()}`,
|
|
27
27
|
ruleInstance,
|
|
28
28
|
);
|
|
29
29
|
}
|
|
@@ -2,7 +2,7 @@ import { PRN } from "@platecms/delta-plate-resource-notation";
|
|
|
2
2
|
import { DecimalCountValidationRule } from "./decimal-count.validation-rule";
|
|
3
3
|
|
|
4
4
|
describe("DecimalCountValidationRule", () => {
|
|
5
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
5
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:decimal-count");
|
|
6
6
|
|
|
7
7
|
describe("validate", () => {
|
|
8
8
|
describe("with max of 0", () => {
|
|
@@ -3,7 +3,7 @@ import { InvalidValidationRuleSettingsError } from "../errors/invalid-validation
|
|
|
3
3
|
import { NumberBetweenValidationRule } from "./number-between.validation-rule";
|
|
4
4
|
|
|
5
5
|
describe("NumberBetweenValidationRule", () => {
|
|
6
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
6
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
7
7
|
|
|
8
8
|
describe("constructor", () => {
|
|
9
9
|
it("throws an error if min and max are not provided", () => {
|
|
@@ -3,15 +3,15 @@ import { InvalidValidationArgumentsError } from "../errors/invalid-validation-ar
|
|
|
3
3
|
import { RelatableContentTypesValidationRule } from "./relatable-content-types.validation-rule";
|
|
4
4
|
|
|
5
5
|
describe("RelatableContentTypesValidationRule", () => {
|
|
6
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
7
|
-
const contentItemPrn = PRN.fromString("prn:plate:-1:
|
|
6
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:1");
|
|
7
|
+
const contentItemPrn = PRN.fromString("prn:plate:-1:cms:content-item:1");
|
|
8
8
|
|
|
9
9
|
const allowedContentTypes = [
|
|
10
|
-
PRN.fromString("prn:plate:-1:
|
|
11
|
-
PRN.fromString("prn:plate:-1:
|
|
10
|
+
PRN.fromString("prn:plate:-1:cms:content-type:1"),
|
|
11
|
+
PRN.fromString("prn:plate:-1:cms:content-type:2"),
|
|
12
12
|
];
|
|
13
13
|
|
|
14
|
-
const disallowedContentType = PRN.fromString("prn:plate:-1:
|
|
14
|
+
const disallowedContentType = PRN.fromString("prn:plate:-1:cms:content-type:3");
|
|
15
15
|
|
|
16
16
|
let rule: RelatableContentTypesValidationRule;
|
|
17
17
|
|
|
@@ -2,7 +2,7 @@ import { PRN } from "@platecms/delta-plate-resource-notation";
|
|
|
2
2
|
import { StringFormatValidationRule } from "./string-format.validation-rule";
|
|
3
3
|
|
|
4
4
|
describe("StringFormatValidationRule", () => {
|
|
5
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
5
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:string-format");
|
|
6
6
|
|
|
7
7
|
describe("with an email regex", () => {
|
|
8
8
|
let rule: StringFormatValidationRule;
|
|
@@ -3,7 +3,7 @@ import { ContentValueType, ContentValueTypeNames } from "@platecms/delta-types";
|
|
|
3
3
|
import { ValueTypeValidationRule, ValueTypeValidationRuleSettings } from "./value-type.validation-rule";
|
|
4
4
|
|
|
5
5
|
describe("ValueTypeValidationRule", () => {
|
|
6
|
-
const rulePrn = PRN.fromString("prn:plate:-1:
|
|
6
|
+
const rulePrn = PRN.fromString("prn:plate:-1:cms:validation-rule:value-type");
|
|
7
7
|
|
|
8
8
|
describe.each([
|
|
9
9
|
[
|
|
@@ -42,7 +42,7 @@ describe("ValueTypeValidationRule", () => {
|
|
|
42
42
|
"with allowed content item type",
|
|
43
43
|
{ allowedTypes: [ContentValueTypeNames.CONTENT_ITEM] },
|
|
44
44
|
[
|
|
45
|
-
[PRN.fromString("prn:plate:-1:
|
|
45
|
+
[PRN.fromString("prn:plate:-1:cms:content-item:1"), true],
|
|
46
46
|
["foo", false],
|
|
47
47
|
],
|
|
48
48
|
],
|
|
@@ -50,7 +50,7 @@ describe("ValueTypeValidationRule", () => {
|
|
|
50
50
|
"with allowed asset type",
|
|
51
51
|
{ allowedTypes: [ContentValueTypeNames.ASSET] },
|
|
52
52
|
[
|
|
53
|
-
[PRN.fromString("prn:plate:-1:
|
|
53
|
+
[PRN.fromString("prn:plate:-1:ps:asset:1"), true],
|
|
54
54
|
["foo", false],
|
|
55
55
|
],
|
|
56
56
|
],
|
|
@@ -58,7 +58,7 @@ describe("ValueTypeValidationRule", () => {
|
|
|
58
58
|
"with allowed path part type",
|
|
59
59
|
{ allowedTypes: [ContentValueTypeNames.PATH_PART] },
|
|
60
60
|
[
|
|
61
|
-
[PRN.fromString("prn:plate:-1:
|
|
61
|
+
[PRN.fromString("prn:plate:-1:cms:path-part:1"), true],
|
|
62
62
|
["foo", false],
|
|
63
63
|
],
|
|
64
64
|
],
|
|
@@ -66,7 +66,7 @@ describe("ValueTypeValidationRule", () => {
|
|
|
66
66
|
"with allowed grid placement type",
|
|
67
67
|
{ allowedTypes: [ContentValueTypeNames.GRID_PLACEMENT] },
|
|
68
68
|
[
|
|
69
|
-
[PRN.fromString("prn:plate:-1:
|
|
69
|
+
[PRN.fromString("prn:plate:-1:cms:grid-placement:1"), true],
|
|
70
70
|
["foo", false],
|
|
71
71
|
],
|
|
72
72
|
],
|
|
@@ -75,13 +75,13 @@ describe("ValueTypeValidationRule", () => {
|
|
|
75
75
|
{ allowedTypes: [ContentValueTypeNames.SMART_TEXT] },
|
|
76
76
|
[
|
|
77
77
|
[{ type: "root", children: [] }, true],
|
|
78
|
-
[PRN.fromString("prn:plate:-1:
|
|
78
|
+
[PRN.fromString("prn:plate:-1:cms:grid-placement:1"), false],
|
|
79
79
|
],
|
|
80
80
|
],
|
|
81
81
|
[
|
|
82
82
|
"with incorrect prn",
|
|
83
83
|
{ allowedTypes: [ContentValueTypeNames.CONTENT_ITEM] },
|
|
84
|
-
[[PRN.fromString("prn:plate:-1:
|
|
84
|
+
[[PRN.fromString("prn:plate:-1:ps:asset:1"), false]],
|
|
85
85
|
],
|
|
86
86
|
[
|
|
87
87
|
"with multiple types",
|
|
@@ -90,7 +90,7 @@ describe("ValueTypeValidationRule", () => {
|
|
|
90
90
|
},
|
|
91
91
|
[
|
|
92
92
|
["foo", true],
|
|
93
|
-
[PRN.fromString("prn:plate:-1:
|
|
93
|
+
[PRN.fromString("prn:plate:-1:cms:content-item:1"), true],
|
|
94
94
|
[new Date(), false],
|
|
95
95
|
],
|
|
96
96
|
],
|