@sprucelabs/schema 34.0.6 → 34.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.
- package/build/StaticSchemaEntityImpl.js +5 -1
- package/build/esm/StaticSchemaEntityImpl.js +5 -1
- package/build/esm/fields/AbstractField.d.ts +1 -0
- package/build/esm/fields/AbstractField.js +3 -0
- package/build/esm/fields/field.static.types.d.ts +2 -0
- package/build/fields/AbstractField.d.ts +1 -0
- package/build/fields/AbstractField.js +3 -0
- package/build/fields/field.static.types.d.ts +2 -0
- package/package.json +9 -9
|
@@ -129,9 +129,13 @@ class StaticSchemaEntityImpl extends AbstractEntity_1.default {
|
|
|
129
129
|
const isMissingRequiredOrMinValues = field.isRequired &&
|
|
130
130
|
field.isArray &&
|
|
131
131
|
(!value || valueAsArray.length < (field.minArrayLength ?? 1));
|
|
132
|
+
const hasMaxArrayLength = !!field.maxArrayLength &&
|
|
133
|
+
valueAsArray.length > field.maxArrayLength;
|
|
132
134
|
const isMissing = !value;
|
|
133
135
|
const shouldBeArrayButIsnt = !wasArray && !isMissing && field.isArray;
|
|
134
|
-
if (isMissingRequiredOrMinValues ||
|
|
136
|
+
if (isMissingRequiredOrMinValues ||
|
|
137
|
+
shouldBeArrayButIsnt ||
|
|
138
|
+
hasMaxArrayLength) {
|
|
135
139
|
const missingRequiredError = `${field.label ? `'${field.label}'` : 'This'} is required!`;
|
|
136
140
|
const missingMinValuesError = `${field.label ? `'${field.label}'` : 'You'} must ${field.label ? 'have' : 'select'} at least ${field.minArrayLength} value${field.minArrayLength === 1 ? '' : 's'}. I found ${valueAsArray.length}!`;
|
|
137
141
|
const mustBeArrayError = `${field.label ? `'${field.label}'` : 'This'} must be an array!`;
|
|
@@ -93,9 +93,13 @@ class StaticSchemaEntityImpl extends AbstractEntity {
|
|
|
93
93
|
const isMissingRequiredOrMinValues = field.isRequired &&
|
|
94
94
|
field.isArray &&
|
|
95
95
|
(!value || valueAsArray.length < ((_a = field.minArrayLength) !== null && _a !== void 0 ? _a : 1));
|
|
96
|
+
const hasMaxArrayLength = !!field.maxArrayLength &&
|
|
97
|
+
valueAsArray.length > field.maxArrayLength;
|
|
96
98
|
const isMissing = !value;
|
|
97
99
|
const shouldBeArrayButIsnt = !wasArray && !isMissing && field.isArray;
|
|
98
|
-
if (isMissingRequiredOrMinValues ||
|
|
100
|
+
if (isMissingRequiredOrMinValues ||
|
|
101
|
+
shouldBeArrayButIsnt ||
|
|
102
|
+
hasMaxArrayLength) {
|
|
99
103
|
const missingRequiredError = `${field.label ? `'${field.label}'` : 'This'} is required!`;
|
|
100
104
|
const missingMinValuesError = `${field.label ? `'${field.label}'` : 'You'} must ${field.label ? 'have' : 'select'} at least ${field.minArrayLength} value${field.minArrayLength === 1 ? '' : 's'}. I found ${valueAsArray.length}!`;
|
|
101
105
|
const mustBeArrayError = `${field.label ? `'${field.label}'` : 'This'} must be an array!`;
|
|
@@ -24,6 +24,7 @@ export default abstract class AbstractField<F extends FieldDefinitions> implemen
|
|
|
24
24
|
get label(): string | undefined;
|
|
25
25
|
get hint(): string | undefined;
|
|
26
26
|
get minArrayLength(): number;
|
|
27
|
+
get maxArrayLength(): number | undefined;
|
|
27
28
|
validate(value: any, _?: ValidateOptions<F>): FieldError[];
|
|
28
29
|
/** Transform any value to the value type of this field */
|
|
29
30
|
toValueType(value: any, _: any): any;
|
|
@@ -52,6 +52,9 @@ public static generateTemplateDetails(
|
|
|
52
52
|
var _b;
|
|
53
53
|
return (_b = this.definition.minArrayLength) !== null && _b !== void 0 ? _b : 1;
|
|
54
54
|
}
|
|
55
|
+
get maxArrayLength() {
|
|
56
|
+
return this.definition.maxArrayLength;
|
|
57
|
+
}
|
|
55
58
|
validate(value, _) {
|
|
56
59
|
const errors = [];
|
|
57
60
|
if (isUndefinedOrNull(value) && this.isRequired) {
|
|
@@ -34,6 +34,7 @@ export type FieldDefinition<Value = any, DefaultValue = Value, ArrayValue = Valu
|
|
|
34
34
|
hint?: string;
|
|
35
35
|
isRequired?: boolean;
|
|
36
36
|
minArrayLength?: number;
|
|
37
|
+
maxArrayLength?: number;
|
|
37
38
|
} & ({
|
|
38
39
|
isArray: true;
|
|
39
40
|
defaultValue?: DefaultArrayValue | null;
|
|
@@ -52,6 +53,7 @@ export interface Field<F extends FieldDefinitions> {
|
|
|
52
53
|
readonly isPrivate: F['isPrivate'];
|
|
53
54
|
readonly isArray: F['isArray'];
|
|
54
55
|
readonly minArrayLength: F['minArrayLength'];
|
|
56
|
+
readonly maxArrayLength: F['maxArrayLength'];
|
|
55
57
|
readonly label: F['label'];
|
|
56
58
|
readonly hint: F['hint'];
|
|
57
59
|
name: string;
|
|
@@ -24,6 +24,7 @@ export default abstract class AbstractField<F extends FieldDefinitions> implemen
|
|
|
24
24
|
get label(): string | undefined;
|
|
25
25
|
get hint(): string | undefined;
|
|
26
26
|
get minArrayLength(): number;
|
|
27
|
+
get maxArrayLength(): number | undefined;
|
|
27
28
|
validate(value: any, _?: ValidateOptions<F>): FieldError[];
|
|
28
29
|
/** Transform any value to the value type of this field */
|
|
29
30
|
toValueType(value: any, _: any): any;
|
|
@@ -56,6 +56,9 @@ public static generateTemplateDetails(
|
|
|
56
56
|
get minArrayLength() {
|
|
57
57
|
return this.definition.minArrayLength ?? 1;
|
|
58
58
|
}
|
|
59
|
+
get maxArrayLength() {
|
|
60
|
+
return this.definition.maxArrayLength;
|
|
61
|
+
}
|
|
59
62
|
validate(value, _) {
|
|
60
63
|
const errors = [];
|
|
61
64
|
if ((0, isUndefinedOrNull_1.default)(value) && this.isRequired) {
|
|
@@ -34,6 +34,7 @@ export type FieldDefinition<Value = any, DefaultValue = Value, ArrayValue = Valu
|
|
|
34
34
|
hint?: string;
|
|
35
35
|
isRequired?: boolean;
|
|
36
36
|
minArrayLength?: number;
|
|
37
|
+
maxArrayLength?: number;
|
|
37
38
|
} & ({
|
|
38
39
|
isArray: true;
|
|
39
40
|
defaultValue?: DefaultArrayValue | null;
|
|
@@ -52,6 +53,7 @@ export interface Field<F extends FieldDefinitions> {
|
|
|
52
53
|
readonly isPrivate: F['isPrivate'];
|
|
53
54
|
readonly isArray: F['isArray'];
|
|
54
55
|
readonly minArrayLength: F['minArrayLength'];
|
|
56
|
+
readonly maxArrayLength: F['maxArrayLength'];
|
|
55
57
|
readonly label: F['label'];
|
|
56
58
|
readonly hint: F['hint'];
|
|
57
59
|
name: string;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"!build/__tests__",
|
|
9
9
|
"esm"
|
|
10
10
|
],
|
|
11
|
-
"version": "34.0
|
|
11
|
+
"version": "34.1.0",
|
|
12
12
|
"main": "./build/index.js",
|
|
13
13
|
"types": "./build/index.d.ts",
|
|
14
14
|
"module": "./build/esm/index.js",
|
|
@@ -70,20 +70,20 @@
|
|
|
70
70
|
"build.copy-files": "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@sprucelabs/error": "^8.1.
|
|
74
|
-
"@sprucelabs/test-utils": "^7.2.
|
|
73
|
+
"@sprucelabs/error": "^8.1.16",
|
|
74
|
+
"@sprucelabs/test-utils": "^7.2.20",
|
|
75
75
|
"email-validator": "^2.0.4",
|
|
76
76
|
"just-safe-get": "^4.2.0",
|
|
77
77
|
"just-safe-set": "^4.2.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@sprucelabs/esm-postbuild": "^9.0.
|
|
81
|
-
"@sprucelabs/jest-json-reporter": "^10.0.
|
|
82
|
-
"@sprucelabs/resolve-path-aliases": "^4.0.
|
|
80
|
+
"@sprucelabs/esm-postbuild": "^9.0.25",
|
|
81
|
+
"@sprucelabs/jest-json-reporter": "^10.0.32",
|
|
82
|
+
"@sprucelabs/resolve-path-aliases": "^4.0.24",
|
|
83
83
|
"@sprucelabs/semantic-release": "^6.0.0",
|
|
84
|
-
"@sprucelabs/test": "^11.1.
|
|
84
|
+
"@sprucelabs/test": "^11.1.7",
|
|
85
85
|
"chokidar-cli": "^3.0.0",
|
|
86
|
-
"eslint": "^10.0
|
|
86
|
+
"eslint": "^10.2.0",
|
|
87
87
|
"eslint-config-spruce": "^11.2.35",
|
|
88
88
|
"jest": "^30.3.0",
|
|
89
89
|
"jest-circus": "^30.3.0",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"ts-node": "^10.9.2",
|
|
92
92
|
"tsc-watch": "^7.2.0",
|
|
93
93
|
"tsconfig-paths": "^4.2.0",
|
|
94
|
-
"typescript": "^
|
|
94
|
+
"typescript": "^6.0.2"
|
|
95
95
|
},
|
|
96
96
|
"jest": {
|
|
97
97
|
"testEnvironment": "node",
|