use-zod-default 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/v4.js +44 -17
- package/package.json +6 -5
package/dist/v4.js
CHANGED
|
@@ -23,24 +23,18 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
23
23
|
if (schema instanceof z.ZodArray) {
|
|
24
24
|
return [];
|
|
25
25
|
}
|
|
26
|
+
if (schema instanceof z.ZodBigInt) {
|
|
27
|
+
if (schema._zod.bag?.minimum && schema._zod.bag?.minimum > 0) {
|
|
28
|
+
return BigInt(schema._zod.bag?.minimum);
|
|
29
|
+
}
|
|
30
|
+
return BigInt(0);
|
|
31
|
+
}
|
|
26
32
|
if (schema instanceof z.ZodBoolean) {
|
|
27
33
|
return false;
|
|
28
34
|
}
|
|
29
35
|
if (schema instanceof z.ZodDate) {
|
|
30
36
|
return null;
|
|
31
37
|
}
|
|
32
|
-
if (schema instanceof z.ZodISODate) {
|
|
33
|
-
return new Date().toISOString().split('T')[0];
|
|
34
|
-
}
|
|
35
|
-
if (schema instanceof z.ZodISODateTime) {
|
|
36
|
-
return new Date().toISOString();
|
|
37
|
-
}
|
|
38
|
-
if (schema instanceof z.ZodISODuration) {
|
|
39
|
-
return 'P0D';
|
|
40
|
-
}
|
|
41
|
-
if (schema instanceof z.ZodISOTime) {
|
|
42
|
-
return new Date().toISOString().split('T')[1];
|
|
43
|
-
}
|
|
44
38
|
if (schema instanceof z.ZodDiscriminatedUnion) {
|
|
45
39
|
const firstOption = schema._zod.def.options[0];
|
|
46
40
|
return defaultInstance(cast(firstOption));
|
|
@@ -69,8 +63,11 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
69
63
|
if (schema instanceof z.ZodNullable) {
|
|
70
64
|
return null;
|
|
71
65
|
}
|
|
72
|
-
if (schema instanceof z.ZodNumber
|
|
73
|
-
|
|
66
|
+
if (schema instanceof z.ZodNumber) {
|
|
67
|
+
if (schema._zod.bag?.minimum && schema._zod.bag?.minimum > 0) {
|
|
68
|
+
return schema._zod.bag?.minimum;
|
|
69
|
+
}
|
|
70
|
+
return 0;
|
|
74
71
|
}
|
|
75
72
|
if (schema instanceof z.ZodObject) {
|
|
76
73
|
return defaultInstance(schema, {});
|
|
@@ -80,7 +77,7 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
80
77
|
const defaultInValue = getDefaultValue(cast(schema._zod.def.in));
|
|
81
78
|
return getDefaultValue(cast(schema._zod.def.out), defaultInValue);
|
|
82
79
|
}
|
|
83
|
-
return getDefaultValue(cast(schema._zod.def.
|
|
80
|
+
return getDefaultValue(cast(schema._zod.def.out));
|
|
84
81
|
}
|
|
85
82
|
if (schema instanceof z.ZodPromise) {
|
|
86
83
|
return Promise.resolve(getDefaultValue(cast(schema._zod.def.innerType)));
|
|
@@ -91,7 +88,31 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
91
88
|
if (schema instanceof z.ZodSet) {
|
|
92
89
|
return new Set();
|
|
93
90
|
}
|
|
94
|
-
if (schema instanceof z.
|
|
91
|
+
if (schema instanceof z.ZodBase64 ||
|
|
92
|
+
schema instanceof z.ZodBase64URL ||
|
|
93
|
+
schema instanceof z.ZodCIDRv4 ||
|
|
94
|
+
schema instanceof z.ZodCIDRv6 ||
|
|
95
|
+
schema instanceof z.ZodCUID ||
|
|
96
|
+
schema instanceof z.ZodCUID2 ||
|
|
97
|
+
schema instanceof z.ZodCustomStringFormat ||
|
|
98
|
+
schema instanceof z.ZodE164 ||
|
|
99
|
+
schema instanceof z.ZodEmail ||
|
|
100
|
+
schema instanceof z.ZodEmoji ||
|
|
101
|
+
schema instanceof z.ZodGUID ||
|
|
102
|
+
schema instanceof z.ZodIPv4 ||
|
|
103
|
+
schema instanceof z.ZodIPv6 ||
|
|
104
|
+
schema instanceof z.ZodISODate ||
|
|
105
|
+
schema instanceof z.ZodISODateTime ||
|
|
106
|
+
schema instanceof z.ZodISODuration ||
|
|
107
|
+
schema instanceof z.ZodISOTime ||
|
|
108
|
+
schema instanceof z.ZodJWT ||
|
|
109
|
+
schema instanceof z.ZodKSUID ||
|
|
110
|
+
schema instanceof z.ZodNanoID ||
|
|
111
|
+
schema instanceof z.ZodString ||
|
|
112
|
+
schema instanceof z.ZodULID ||
|
|
113
|
+
schema instanceof z.ZodURL ||
|
|
114
|
+
schema instanceof z.ZodUUID ||
|
|
115
|
+
schema instanceof z.ZodXID) {
|
|
95
116
|
return '';
|
|
96
117
|
}
|
|
97
118
|
if (schema instanceof z.ZodSymbol) {
|
|
@@ -162,6 +183,12 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
162
183
|
if (schema instanceof z.ZodArray) {
|
|
163
184
|
return processArray(schema, value);
|
|
164
185
|
}
|
|
186
|
+
if (schema instanceof z.ZodBigInt) {
|
|
187
|
+
if (typeof value === 'bigint') {
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
return typeof value === 'number' ? BigInt(value) : BigInt(0);
|
|
191
|
+
}
|
|
165
192
|
if (schema instanceof z.ZodBoolean) {
|
|
166
193
|
return isBoolean(value) ? value : false;
|
|
167
194
|
}
|
|
@@ -189,7 +216,7 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
189
216
|
if (schema instanceof z.ZodNullable) {
|
|
190
217
|
return isNil(value) ? null : processValue(schema._zod.def.innerType, value);
|
|
191
218
|
}
|
|
192
|
-
if (schema instanceof z.ZodNumber
|
|
219
|
+
if (schema instanceof z.ZodNumber) {
|
|
193
220
|
return isNumber(value) ? value : (schema._zod.bag?.minimum ?? 0);
|
|
194
221
|
}
|
|
195
222
|
if (schema instanceof z.ZodObject) {
|
package/package.json
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
"devDependencies": {
|
|
3
3
|
"@types/lodash": "^4.17.12",
|
|
4
4
|
"@types/node": "^22.7.7",
|
|
5
|
-
"@vitest/coverage-v8": "^3.
|
|
5
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
6
6
|
"eslint": "^9.26.0",
|
|
7
7
|
"lodash": "^4.17.21",
|
|
8
8
|
"prettier": "^3.3.3",
|
|
9
9
|
"tsx": "^4.20.3",
|
|
10
10
|
"typescript": "^5.6.3",
|
|
11
11
|
"typescript-eslint": "^8.32.1",
|
|
12
|
-
"vitest": "^2.
|
|
12
|
+
"vitest": "^3.2.4",
|
|
13
13
|
"zod": "^4.0.17"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "rm -rf dist && yarn lint && tsc -p tsconfig.json",
|
|
36
36
|
"lint": "prettier --write . && eslint . && yarn tsc",
|
|
37
|
-
"npm:publish": "yarn test
|
|
38
|
-
"test": "vitest",
|
|
37
|
+
"npm:publish": "yarn test && yarn build && yarn version --patch --no-git-tag-version && yarn publish --non-interactive",
|
|
38
|
+
"test": "vitest --run",
|
|
39
|
+
"test:watch": "vitest",
|
|
39
40
|
"test:coverage": "rm -rf coverage && vitest --run --coverage"
|
|
40
41
|
},
|
|
41
|
-
"version": "1.0.
|
|
42
|
+
"version": "1.0.21"
|
|
42
43
|
}
|