use-zod-default 1.0.22 → 1.0.24
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/v3.js +8 -2
- package/dist/v4.js +11 -2
- package/package.json +2 -2
package/dist/v3.js
CHANGED
|
@@ -190,10 +190,16 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
190
190
|
// Process defined schema properties
|
|
191
191
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
192
192
|
if (key in source) {
|
|
193
|
-
|
|
193
|
+
const v = processValue(fieldSchema, source[key]);
|
|
194
|
+
if (v !== undefined) {
|
|
195
|
+
result[key] = v;
|
|
196
|
+
}
|
|
194
197
|
}
|
|
195
198
|
else {
|
|
196
|
-
|
|
199
|
+
const v = getDefaultValue(fieldSchema);
|
|
200
|
+
if (v !== undefined) {
|
|
201
|
+
result[key] = v;
|
|
202
|
+
}
|
|
197
203
|
}
|
|
198
204
|
}
|
|
199
205
|
// Handle passthrough - preserve additional properties not in schema
|
package/dist/v4.js
CHANGED
|
@@ -231,6 +231,9 @@ const defaultInstance = (schema, source) => {
|
|
|
231
231
|
if (schema instanceof z.ZodObject) {
|
|
232
232
|
return processObject(schema, value);
|
|
233
233
|
}
|
|
234
|
+
if (schema instanceof z.ZodOptional) {
|
|
235
|
+
return isNil(value) ? undefined : processValue(schema._zod.def.innerType, value);
|
|
236
|
+
}
|
|
234
237
|
if (schema instanceof z.ZodPipe) {
|
|
235
238
|
if (schema._zod.def.out instanceof z.ZodTransform) {
|
|
236
239
|
return processTransform(schema._zod.def.out, value);
|
|
@@ -273,10 +276,16 @@ const defaultInstance = (schema, source) => {
|
|
|
273
276
|
// Create a proper ZodType from the field schema
|
|
274
277
|
const zodFieldSchema = cast(fieldSchema);
|
|
275
278
|
if (source && key in source) {
|
|
276
|
-
|
|
279
|
+
const v = processValue(zodFieldSchema, source[key]);
|
|
280
|
+
if (v !== undefined) {
|
|
281
|
+
result[key] = v;
|
|
282
|
+
}
|
|
277
283
|
}
|
|
278
284
|
else {
|
|
279
|
-
|
|
285
|
+
const v = getDefaultValue(zodFieldSchema);
|
|
286
|
+
if (v !== undefined) {
|
|
287
|
+
result[key] = v;
|
|
288
|
+
}
|
|
280
289
|
}
|
|
281
290
|
}
|
|
282
291
|
// Handle catchall - preserve additional properties not in schema
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"typescript": "^5.6.3",
|
|
11
11
|
"typescript-eslint": "^8.32.1",
|
|
12
12
|
"vitest": "^3.2.4",
|
|
13
|
-
"zod": "^4.2.
|
|
13
|
+
"zod": "^4.2.1"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"lodash": "^4.17.21",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"test:watch": "vitest",
|
|
40
40
|
"test:coverage": "rm -rf coverage && vitest --run --coverage"
|
|
41
41
|
},
|
|
42
|
-
"version": "1.0.
|
|
42
|
+
"version": "1.0.24"
|
|
43
43
|
}
|