use-zod-default 1.0.12 → 1.0.14
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/index.js +12 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -144,6 +144,9 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
144
144
|
if (schema instanceof z.ZodEffects) {
|
|
145
145
|
return processEffect(schema, value);
|
|
146
146
|
}
|
|
147
|
+
if (schema instanceof z.ZodDefault) {
|
|
148
|
+
return processValue(schema._def.innerType, value);
|
|
149
|
+
}
|
|
147
150
|
if (schema instanceof z.ZodMap) {
|
|
148
151
|
return processMap(schema, value);
|
|
149
152
|
}
|
|
@@ -184,6 +187,7 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
184
187
|
const processObject = (schema, source) => {
|
|
185
188
|
const result = {};
|
|
186
189
|
const shape = schema.shape;
|
|
190
|
+
// Process defined schema properties
|
|
187
191
|
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
188
192
|
if (key in source) {
|
|
189
193
|
result[key] = processValue(fieldSchema, source[key]);
|
|
@@ -192,6 +196,14 @@ const defaultInstance = (schema, source = {}) => {
|
|
|
192
196
|
result[key] = getDefaultValue(fieldSchema);
|
|
193
197
|
}
|
|
194
198
|
}
|
|
199
|
+
// Handle passthrough - preserve additional properties not in schema
|
|
200
|
+
if (schema._def.unknownKeys === 'passthrough' && isPlainObject(source)) {
|
|
201
|
+
for (const key in source) {
|
|
202
|
+
if (!(key in shape)) {
|
|
203
|
+
result[key] = source[key];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
195
207
|
return result;
|
|
196
208
|
};
|
|
197
209
|
const processRecord = (schema, source) => {
|
package/package.json
CHANGED