@conform-to/zod
Advanced tools
Comparing version 0.7.0-pre.1 to 0.7.0-pre.2
62
index.js
@@ -30,14 +30,2 @@ 'use strict'; | ||
function getFieldsetConstraint(source) { | ||
function getSchemaShape(schema) { | ||
if (schema instanceof z__namespace.ZodObject) { | ||
return schema.shape; | ||
} else if (schema instanceof z__namespace.ZodEffects) { | ||
return getSchemaShape(schema.innerType()); | ||
} else if (schema instanceof z__namespace.ZodOptional) { | ||
return getSchemaShape(schema.unwrap()); | ||
} else if (schema instanceof z__namespace.ZodIntersection) { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getSchemaShape(schema._def.left)), getSchemaShape(schema._def.right)); | ||
} | ||
return null; | ||
} | ||
function inferConstraint(schema) { | ||
@@ -104,11 +92,47 @@ var constraint = {}; | ||
} | ||
var shape = getSchemaShape(source); | ||
var result = {}; | ||
if (shape) { | ||
for (var [key, def] of Object.entries(shape)) { | ||
// @ts-expect-error | ||
result[key] = inferConstraint(def); | ||
var keys = ['required', 'minLength', 'maxLength', 'min', 'max', 'step', 'multiple', 'pattern']; | ||
function resolveFieldsetConstarint(schema) { | ||
if (schema instanceof z__namespace.ZodObject) { | ||
var result = {}; | ||
for (var [key, def] of Object.entries(schema.shape)) { | ||
// @ts-expect-error | ||
result[key] = inferConstraint(def); | ||
} | ||
return result; | ||
} | ||
if (schema instanceof z__namespace.ZodEffects) { | ||
return resolveFieldsetConstarint(schema.innerType()); | ||
} else if (schema instanceof z__namespace.ZodOptional) { | ||
return resolveFieldsetConstarint(schema.unwrap()); | ||
} else if (schema instanceof z__namespace.ZodIntersection) { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, resolveFieldsetConstarint(schema._def.left)), resolveFieldsetConstarint(schema._def.right)); | ||
} else if (schema instanceof z__namespace.ZodUnion || schema instanceof z__namespace.ZodDiscriminatedUnion) { | ||
var options = schema.options; | ||
return options.map(resolveFieldsetConstarint).reduce((prev, next) => { | ||
var list = new Set([...Object.keys(prev), ...Object.keys(next)]); | ||
var result = {}; | ||
for (var name of list) { | ||
// @ts-expect-error | ||
var prevConstraint = prev[name]; | ||
// @ts-expect-error | ||
var nextConstraint = next[name]; | ||
if (prevConstraint && nextConstraint) { | ||
result[name] = {}; | ||
for (var _key of keys) { | ||
if (typeof prevConstraint[_key] !== 'undefined' && typeof nextConstraint[_key] !== 'undefined' && prevConstraint[_key] === nextConstraint[_key]) { | ||
result[name][_key] = prevConstraint[_key]; | ||
} | ||
} | ||
} else { | ||
result[name] = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, prevConstraint), nextConstraint), {}, { | ||
required: false | ||
}); | ||
} | ||
} | ||
return result; | ||
}); | ||
} | ||
return {}; | ||
} | ||
return result; | ||
return resolveFieldsetConstarint(source); | ||
} | ||
@@ -115,0 +139,0 @@ function parse(payload, config) { |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.7.0-pre.1", | ||
"version": "0.7.0-pre.2", | ||
"main": "index.js", | ||
@@ -29,3 +29,3 @@ "module": "index.mjs", | ||
"peerDependencies": { | ||
"@conform-to/dom": "0.7.0-pre.1", | ||
"@conform-to/dom": "0.7.0-pre.2", | ||
"zod": "^3.21.0" | ||
@@ -32,0 +32,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21541
457
0