react-f0rm 0.6.0 → 0.7.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/README.md +22 -0
- package/dist/devtools/index.cjs.js +1 -743
- package/dist/devtools/index.cjs.js.map +1 -1
- package/dist/devtools/index.mjs +1 -723
- package/dist/devtools/index.mjs.map +1 -1
- package/dist/form-CGRvih_c.cjs.js +2 -0
- package/dist/form-CGRvih_c.cjs.js.map +1 -0
- package/dist/form-CfBBPz6p.mjs +2 -0
- package/dist/form-CfBBPz6p.mjs.map +1 -0
- package/dist/{form-D9COEt0-.d.ts → form-DHKns6j_.d.ts} +41 -1
- package/dist/index.cjs.js +1 -1812
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +1 -1719
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +27 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +2 -2
- package/dist/index.umd.min.js.map +1 -1
- package/dist/resolvers/standard-schema.cjs.js +1 -89
- package/dist/resolvers/standard-schema.cjs.js.map +1 -1
- package/dist/resolvers/standard-schema.mjs +1 -85
- package/dist/resolvers/standard-schema.mjs.map +1 -1
- package/dist/resolvers/yup.cjs.js +1 -22
- package/dist/resolvers/yup.cjs.js.map +1 -1
- package/dist/resolvers/yup.d.ts +1 -1
- package/dist/resolvers/yup.mjs +1 -20
- package/dist/resolvers/yup.mjs.map +1 -1
- package/dist/resolvers/zod.cjs.js +1 -22
- package/dist/resolvers/zod.cjs.js.map +1 -1
- package/dist/resolvers/zod.d.ts +1 -1
- package/dist/resolvers/zod.mjs +1 -20
- package/dist/resolvers/zod.mjs.map +1 -1
- package/dist/{validate-Cu43SqhV.d.ts → validate-BoNZhOMY.d.ts} +1 -1
- package/package.json +6 -1
- package/dist/form-CXF5HwQG.mjs +0 -349
- package/dist/form-CXF5HwQG.mjs.map +0 -1
- package/dist/form-DbnzAKSM.cjs.js +0 -358
- package/dist/form-DbnzAKSM.cjs.js.map +0 -1
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var form = require('../form-DbnzAKSM.cjs.js');
|
|
4
|
-
|
|
5
|
-
function hasStandardProps(schema) {
|
|
6
|
-
return !!schema && typeof schema === "object" && typeof schema["~standard"]?.validate === "function";
|
|
7
|
-
}
|
|
8
|
-
function toFieldError(issue) {
|
|
9
|
-
return { type: "standard", message: issue?.message || "Validation failed" };
|
|
10
|
-
}
|
|
11
|
-
function standardSchemaResolver(schema) {
|
|
12
|
-
return async (value) => {
|
|
13
|
-
const result = await schema["~standard"].validate(value);
|
|
14
|
-
if (!result.issues?.length) return void 0;
|
|
15
|
-
return result.issues.map(toFieldError);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function standardSchemaFormValidator(schema) {
|
|
19
|
-
return async (values) => {
|
|
20
|
-
const result = await schema["~standard"].validate(values);
|
|
21
|
-
const { issues } = result;
|
|
22
|
-
if (!issues?.length) {
|
|
23
|
-
return {
|
|
24
|
-
[form.VALIDATION_OUTCOME]: true,
|
|
25
|
-
values: "value" in result ? result.value : void 0
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const errors = {};
|
|
29
|
-
for (const issue of issues) {
|
|
30
|
-
const segments = toPathSegments(issue);
|
|
31
|
-
if (segments.length) {
|
|
32
|
-
assignAtPath(errors, segments, toFieldError(issue));
|
|
33
|
-
} else {
|
|
34
|
-
const slot = errors._form ??= [];
|
|
35
|
-
if (Array.isArray(slot)) slot.push(toFieldError(issue));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return { [form.VALIDATION_OUTCOME]: true, errors: pruneEmpty(errors) || {} };
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function toPathSegments(issue) {
|
|
42
|
-
const path = issue.path || [];
|
|
43
|
-
const segments = [];
|
|
44
|
-
for (const segment of path) {
|
|
45
|
-
const key = typeof segment === "object" && segment !== null ? segment.key : segment;
|
|
46
|
-
segments.push(String(key));
|
|
47
|
-
}
|
|
48
|
-
return segments;
|
|
49
|
-
}
|
|
50
|
-
function assignAtPath(root, segments, error) {
|
|
51
|
-
let node = root;
|
|
52
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
53
|
-
const segment = segments[i];
|
|
54
|
-
let next = node[segment];
|
|
55
|
-
if (next === void 0) {
|
|
56
|
-
next = node[segment] = {};
|
|
57
|
-
}
|
|
58
|
-
if (!isBranch(next)) return;
|
|
59
|
-
node = next;
|
|
60
|
-
}
|
|
61
|
-
const leaf = segments[segments.length - 1];
|
|
62
|
-
const slot = node[leaf];
|
|
63
|
-
if (slot === void 0) node[leaf] = [error];
|
|
64
|
-
else if (Array.isArray(slot)) slot.push(error);
|
|
65
|
-
}
|
|
66
|
-
function isBranch(value) {
|
|
67
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
68
|
-
}
|
|
69
|
-
function pruneEmpty(node) {
|
|
70
|
-
let hasLeaf = false;
|
|
71
|
-
const result = {};
|
|
72
|
-
Object.entries(node).forEach(([key, value]) => {
|
|
73
|
-
if (isBranch(value)) {
|
|
74
|
-
const pruned = pruneEmpty(value);
|
|
75
|
-
if (pruned) {
|
|
76
|
-
result[key] = pruned;
|
|
77
|
-
hasLeaf = true;
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
result[key] = value;
|
|
81
|
-
hasLeaf = true;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return hasLeaf ? result : void 0;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
exports.hasStandardProps = hasStandardProps;
|
|
88
|
-
exports.standardSchemaFormValidator = standardSchemaFormValidator;
|
|
89
|
-
exports.standardSchemaResolver = standardSchemaResolver;
|
|
1
|
+
"use strict";var t=require("../form-CGRvih_c.cjs.js");function r(t){return{type:"standard",message:t?.message||"Validation failed"}}function e(t){const r=t.path||[],e=[];for(const t of r){const r="object"==typeof t&&null!==t?t.key:t;e.push(String(r))}return e}function n(t,r,e){let n=t;for(let t=0;t<r.length-1;t++){const e=r[t];let o=n[e];if(void 0===o&&(o=n[e]={}),!s(o))return;n=o}const o=r[r.length-1],a=n[o];void 0===a?n[o]=[e]:Array.isArray(a)&&a.push(e)}function s(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function o(t){let r=!1;const e={};return Object.entries(t).forEach(([t,n])=>{if(s(n)){const s=o(n);s&&(e[t]=s,r=!0)}else e[t]=n,r=!0}),r?e:void 0}exports.hasStandardProps=function(t){return!!t&&"object"==typeof t&&"function"==typeof t["~standard"]?.validate},exports.standardSchemaFormValidator=function(s){return async a=>{const i=await s["~standard"].validate(a),{issues:c}=i;if(!c?.length)return{[t.VALIDATION_OUTCOME]:!0,values:"value"in i?i.value:void 0};const u={};for(const t of c){const s=e(t);if(s.length)n(u,s,r(t));else{const e=u._form??=[];Array.isArray(e)&&e.push(r(t))}}return{[t.VALIDATION_OUTCOME]:!0,errors:o(u)||{}}}},exports.standardSchemaResolver=function(t){return async e=>{const n=await t["~standard"].validate(e);if(n.issues?.length)return n.issues.map(r)}};
|
|
90
2
|
//# sourceMappingURL=standard-schema.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.cjs.js","sources":["../../src/resolvers/standard-schema.ts"],"sourcesContent":["import {VALIDATION_OUTCOME} from '../form';\nimport type {FieldError, ValidationOutcome} from '../form';\nimport type {Validator} from '../hooks/validate';\n\n/**\n * Minimal copy of the Standard Schema v1 interfaces\n * (https://standardschema.dev) so this module has zero runtime and type\n * dependencies on any schema library. Implemented by zod v3.24+/v4,\n * valibot v1, arktype and others.\n */\nexport interface StandardSchemaIssue {\n readonly message: string;\n readonly path?:\n ReadonlyArray<PropertyKey | {readonly key: PropertyKey}> | undefined;\n}\n\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n readonly validate: (\n value: Input\n ) =>\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n | Promise<\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n >;\n };\n}\n\n/**\n * Does the schema implement the Standard Schema v1 props?\n */\nexport function hasStandardProps(schema: any): schema is StandardSchemaV1 {\n return (\n !!schema &&\n typeof schema === 'object' &&\n typeof schema['~standard']?.validate === 'function'\n );\n}\n\nfunction toFieldError(issue: StandardSchemaIssue | undefined): FieldError {\n return {type: 'standard', message: issue?.message || 'Validation failed'};\n}\n\n/**\n * Field-level Standard Schema adapter: validate a single value with any\n * schema implementing '~standard' and map every issue to a FieldError,\n * so a value breaking several rules surfaces all of them (setErrorByPath\n * stores the array; error/errorObject readers still see the first).\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return field validator compatible with useField's validate option\n */\nexport function standardSchemaResolver(schema: StandardSchemaV1): Validator {\n return async (value: any) => {\n const result = await schema['~standard'].validate(value);\n if (!result.issues?.length) return undefined;\n return result.issues.map(toFieldError);\n };\n}\n\n/**\n * Form-level Standard Schema adapter: validate the whole values object with\n * any schema implementing '~standard' and return a ValidationOutcome. On\n * failure `errors` carries the nested shape Options.validate expects\n * ({a: {b: FieldError[]}}; ensureValidate flattens it back to per-field\n * errors, keeping every issue of a path). Issues without a path are\n * form-level errors and land on the '_form' key. On success `values`\n * carries the schema's parsed output (coerce/transform results included),\n * which the form stores as its parsedValues baseline — the layer getValues\n * reads above initialValues, mirroring how react-hook-form's zodResolver\n * and TanStack's standardSchemaValidators use the parsed value.\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return form-level validator for createForm({validate: ...})\n */\nexport function standardSchemaFormValidator<T extends Record<string, any>>(\n schema: StandardSchemaV1<T, any>\n): (values: T) => Promise<ValidationOutcome<T>> {\n return async (values: T) => {\n const result = await schema['~standard'].validate(values);\n const {issues} = result;\n if (!issues?.length) {\n // Success: expose the schema's parsed output. `in` keeps the union\n // narrowed (the success variant is the one carrying `value`).\n return {\n [VALIDATION_OUTCOME]: true,\n values: 'value' in result ? result.value : undefined\n };\n }\n const errors: Record<string, any> = {};\n for (const issue of issues) {\n const segments = toPathSegments(issue);\n if (segments.length) {\n assignAtPath(errors, segments, toFieldError(issue));\n } else {\n // Pathless issues are all form-level: they accumulate on '_form'\n // instead of the first shadowing the rest. (A nested path literally\n // named '_form' would have made the slot a branch — skip then.)\n const slot = (errors._form ??= []);\n if (Array.isArray(slot)) slot.push(toFieldError(issue));\n }\n }\n return {[VALIDATION_OUTCOME]: true, errors: pruneEmpty(errors) || {}};\n };\n}\n\n/**\n * Stringify an issue path: PropertyKey or {key} path segments → strings.\n */\nfunction toPathSegments(issue: StandardSchemaIssue): string[] {\n const path = issue.path || [];\n const segments: string[] = [];\n for (const segment of path) {\n const key =\n typeof segment === 'object' && segment !== null\n ? (segment as {key: PropertyKey}).key\n : segment;\n segments.push(String(key));\n }\n return segments;\n}\n\n/**\n * Append the error at a nested path. Leaves are FieldError[] arrays, so\n * several issues on one field accumulate in issue order; an issue whose\n * path conflicts with an existing leaf or crosses it is skipped.\n */\nfunction assignAtPath(\n root: Record<string, any>,\n segments: string[],\n error: FieldError\n): void {\n let node = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i];\n let next = node[segment];\n if (next === undefined) {\n next = node[segment] = {};\n }\n if (!isBranch(next)) return;\n node = next;\n }\n const leaf = segments[segments.length - 1];\n const slot = node[leaf];\n if (slot === undefined) node[leaf] = [error];\n else if (Array.isArray(slot)) slot.push(error);\n}\n\n/**\n * A branch is a plain container built while nesting; the leaves it carries\n * are the FieldError[] arrays assignAtPath appends.\n */\nfunction isBranch(value: any): value is Record<string, any> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Drop empty branch objects left behind by conflicting issue paths.\n */\nfunction pruneEmpty(\n node: Record<string, any>\n): Record<string, any> | undefined {\n let hasLeaf = false;\n const result: Record<string, any> = {};\n Object.entries(node).forEach(([key, value]) => {\n if (isBranch(value)) {\n const pruned = pruneEmpty(value);\n if (pruned) {\n result[key] = pruned;\n hasLeaf = true;\n }\n } else {\n result[key] = value;\n hasLeaf = true;\n }\n });\n return hasLeaf ? result : undefined;\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"standard-schema.cjs.js","sources":["../../src/resolvers/standard-schema.ts"],"sourcesContent":["import {VALIDATION_OUTCOME} from '../form';\nimport type {FieldError, ValidationOutcome} from '../form';\nimport type {Validator} from '../hooks/validate';\n\n/**\n * Minimal copy of the Standard Schema v1 interfaces\n * (https://standardschema.dev) so this module has zero runtime and type\n * dependencies on any schema library. Implemented by zod v3.24+/v4,\n * valibot v1, arktype and others.\n */\nexport interface StandardSchemaIssue {\n readonly message: string;\n readonly path?:\n ReadonlyArray<PropertyKey | {readonly key: PropertyKey}> | undefined;\n}\n\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n readonly validate: (\n value: Input\n ) =>\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n | Promise<\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n >;\n };\n}\n\n/**\n * Does the schema implement the Standard Schema v1 props?\n */\nexport function hasStandardProps(schema: any): schema is StandardSchemaV1 {\n return (\n !!schema &&\n typeof schema === 'object' &&\n typeof schema['~standard']?.validate === 'function'\n );\n}\n\nfunction toFieldError(issue: StandardSchemaIssue | undefined): FieldError {\n return {type: 'standard', message: issue?.message || 'Validation failed'};\n}\n\n/**\n * Field-level Standard Schema adapter: validate a single value with any\n * schema implementing '~standard' and map every issue to a FieldError,\n * so a value breaking several rules surfaces all of them (setErrorByPath\n * stores the array; error/errorObject readers still see the first).\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return field validator compatible with useField's validate option\n */\nexport function standardSchemaResolver(schema: StandardSchemaV1): Validator {\n return async (value: any) => {\n const result = await schema['~standard'].validate(value);\n if (!result.issues?.length) return undefined;\n return result.issues.map(toFieldError);\n };\n}\n\n/**\n * Form-level Standard Schema adapter: validate the whole values object with\n * any schema implementing '~standard' and return a ValidationOutcome. On\n * failure `errors` carries the nested shape Options.validate expects\n * ({a: {b: FieldError[]}}; ensureValidate flattens it back to per-field\n * errors, keeping every issue of a path). Issues without a path are\n * form-level errors and land on the '_form' key. On success `values`\n * carries the schema's parsed output (coerce/transform results included),\n * which the form stores as its parsedValues baseline — the layer getValues\n * reads above initialValues, mirroring how react-hook-form's zodResolver\n * and TanStack's standardSchemaValidators use the parsed value.\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return form-level validator for createForm({validate: ...})\n */\nexport function standardSchemaFormValidator<T extends Record<string, any>>(\n schema: StandardSchemaV1<T, any>\n): (values: T) => Promise<ValidationOutcome<T>> {\n return async (values: T) => {\n const result = await schema['~standard'].validate(values);\n const {issues} = result;\n if (!issues?.length) {\n // Success: expose the schema's parsed output. `in` keeps the union\n // narrowed (the success variant is the one carrying `value`).\n return {\n [VALIDATION_OUTCOME]: true,\n values: 'value' in result ? result.value : undefined\n };\n }\n const errors: Record<string, any> = {};\n for (const issue of issues) {\n const segments = toPathSegments(issue);\n if (segments.length) {\n assignAtPath(errors, segments, toFieldError(issue));\n } else {\n // Pathless issues are all form-level: they accumulate on '_form'\n // instead of the first shadowing the rest. (A nested path literally\n // named '_form' would have made the slot a branch — skip then.)\n const slot = (errors._form ??= []);\n if (Array.isArray(slot)) slot.push(toFieldError(issue));\n }\n }\n return {[VALIDATION_OUTCOME]: true, errors: pruneEmpty(errors) || {}};\n };\n}\n\n/**\n * Stringify an issue path: PropertyKey or {key} path segments → strings.\n */\nfunction toPathSegments(issue: StandardSchemaIssue): string[] {\n const path = issue.path || [];\n const segments: string[] = [];\n for (const segment of path) {\n const key =\n typeof segment === 'object' && segment !== null\n ? (segment as {key: PropertyKey}).key\n : segment;\n segments.push(String(key));\n }\n return segments;\n}\n\n/**\n * Append the error at a nested path. Leaves are FieldError[] arrays, so\n * several issues on one field accumulate in issue order; an issue whose\n * path conflicts with an existing leaf or crosses it is skipped.\n */\nfunction assignAtPath(\n root: Record<string, any>,\n segments: string[],\n error: FieldError\n): void {\n let node = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i];\n let next = node[segment];\n if (next === undefined) {\n next = node[segment] = {};\n }\n if (!isBranch(next)) return;\n node = next;\n }\n const leaf = segments[segments.length - 1];\n const slot = node[leaf];\n if (slot === undefined) node[leaf] = [error];\n else if (Array.isArray(slot)) slot.push(error);\n}\n\n/**\n * A branch is a plain container built while nesting; the leaves it carries\n * are the FieldError[] arrays assignAtPath appends.\n */\nfunction isBranch(value: any): value is Record<string, any> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Drop empty branch objects left behind by conflicting issue paths.\n */\nfunction pruneEmpty(\n node: Record<string, any>\n): Record<string, any> | undefined {\n let hasLeaf = false;\n const result: Record<string, any> = {};\n Object.entries(node).forEach(([key, value]) => {\n if (isBranch(value)) {\n const pruned = pruneEmpty(value);\n if (pruned) {\n result[key] = pruned;\n hasLeaf = true;\n }\n } else {\n result[key] = value;\n hasLeaf = true;\n }\n });\n return hasLeaf ? result : undefined;\n}\n"],"names":["toFieldError","issue","type","message","toPathSegments","path","segments","segment","key","push","String","assignAtPath","root","error","node","i","length","next","isBranch","leaf","slot","Array","isArray","value","pruneEmpty","hasLeaf","result","Object","entries","forEach","pruned","schema","validate","async","values","issues","VALIDATION_OUTCOME","errors","_form","map"],"mappings":"sDA2CA,SAASA,EAAaC,GACpB,MAAO,CAACC,KAAM,WAAYC,QAASF,GAAOE,SAAW,oBACvD,CAoEA,SAASC,EAAeH,GACtB,MAAMI,EAAOJ,EAAMI,MAAQ,GACrBC,EAAqB,GAC3B,IAAA,MAAWC,KAAWF,EAAM,CAC1B,MAAMG,EACe,iBAAZD,GAAoC,OAAZA,EAC1BA,EAA+BC,IAChCD,EACND,EAASG,KAAKC,OAAOF,GACvB,CACA,OAAOF,CACT,CAOA,SAASK,EACPC,EACAN,EACAO,GAEA,IAAIC,EAAOF,EACX,IAAA,IAASG,EAAI,EAAGA,EAAIT,EAASU,OAAS,EAAGD,IAAK,CAC5C,MAAMR,EAAUD,EAASS,GACzB,IAAIE,EAAOH,EAAKP,GAIhB,QAHa,IAATU,IACFA,EAAOH,EAAKP,GAAW,CAAA,IAEpBW,EAASD,GAAO,OACrBH,EAAOG,CACT,CACA,MAAME,EAAOb,EAASA,EAASU,OAAS,GAClCI,EAAON,EAAKK,QACL,IAATC,EAAoBN,EAAKK,GAAQ,CAACN,GAC7BQ,MAAMC,QAAQF,IAAOA,EAAKX,KAAKI,EAC1C,CAMA,SAASK,EAASK,GAChB,QAASA,GAA0B,iBAAVA,IAAuBF,MAAMC,QAAQC,EAChE,CAKA,SAASC,EACPV,GAEA,IAAIW,GAAU,EACd,MAAMC,EAA8B,CAAA,EAapC,OAZAC,OAAOC,QAAQd,GAAMe,QAAQ,EAAErB,EAAKe,MAClC,GAAIL,EAASK,GAAQ,CACnB,MAAMO,EAASN,EAAWD,GACtBO,IACFJ,EAAOlB,GAAOsB,EACdL,GAAU,EAEd,MACEC,EAAOlB,GAAOe,EACdE,GAAU,IAGPA,EAAUC,OAAS,CAC5B,0BAlJO,SAA0BK,GAC/B,QACIA,GACgB,iBAAXA,GACkC,mBAAlCA,EAAO,cAAcC,QAEhC,sCAsCO,SACLD,GAEA,OAAOE,MAAOC,IACZ,MAAMR,QAAeK,EAAO,aAAaC,SAASE,IAC5CC,OAACA,GAAUT,EACjB,IAAKS,GAAQnB,OAGX,MAAO,CACL,CAACoB,EAAAA,qBAAqB,EACtBF,OAAQ,UAAWR,EAASA,EAAOH,WAAQ,GAG/C,MAAMc,EAA8B,CAAA,EACpC,IAAA,MAAWpC,KAASkC,EAAQ,CAC1B,MAAM7B,EAAWF,EAAeH,GAChC,GAAIK,EAASU,OACXL,EAAa0B,EAAQ/B,EAAUN,EAAaC,QACvC,CAIL,MAAMmB,EAAQiB,EAAOC,QAAU,GAC3BjB,MAAMC,QAAQF,MAAYX,KAAKT,EAAaC,GAClD,CACF,CACA,MAAO,CAAC,CAACmC,EAAAA,qBAAqB,EAAMC,OAAQb,EAAWa,IAAW,IAEtE,iCApDO,SAAgCN,GACrC,OAAOE,MAAOV,IACZ,MAAMG,QAAeK,EAAO,aAAaC,SAAST,GAClD,GAAKG,EAAOS,QAAQnB,OACpB,OAAOU,EAAOS,OAAOI,IAAIvC,GAE7B"}
|
|
@@ -1,86 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function hasStandardProps(schema) {
|
|
4
|
-
return !!schema && typeof schema === "object" && typeof schema["~standard"]?.validate === "function";
|
|
5
|
-
}
|
|
6
|
-
function toFieldError(issue) {
|
|
7
|
-
return { type: "standard", message: issue?.message || "Validation failed" };
|
|
8
|
-
}
|
|
9
|
-
function standardSchemaResolver(schema) {
|
|
10
|
-
return async (value) => {
|
|
11
|
-
const result = await schema["~standard"].validate(value);
|
|
12
|
-
if (!result.issues?.length) return void 0;
|
|
13
|
-
return result.issues.map(toFieldError);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function standardSchemaFormValidator(schema) {
|
|
17
|
-
return async (values) => {
|
|
18
|
-
const result = await schema["~standard"].validate(values);
|
|
19
|
-
const { issues } = result;
|
|
20
|
-
if (!issues?.length) {
|
|
21
|
-
return {
|
|
22
|
-
[VALIDATION_OUTCOME]: true,
|
|
23
|
-
values: "value" in result ? result.value : void 0
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const errors = {};
|
|
27
|
-
for (const issue of issues) {
|
|
28
|
-
const segments = toPathSegments(issue);
|
|
29
|
-
if (segments.length) {
|
|
30
|
-
assignAtPath(errors, segments, toFieldError(issue));
|
|
31
|
-
} else {
|
|
32
|
-
const slot = errors._form ??= [];
|
|
33
|
-
if (Array.isArray(slot)) slot.push(toFieldError(issue));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return { [VALIDATION_OUTCOME]: true, errors: pruneEmpty(errors) || {} };
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function toPathSegments(issue) {
|
|
40
|
-
const path = issue.path || [];
|
|
41
|
-
const segments = [];
|
|
42
|
-
for (const segment of path) {
|
|
43
|
-
const key = typeof segment === "object" && segment !== null ? segment.key : segment;
|
|
44
|
-
segments.push(String(key));
|
|
45
|
-
}
|
|
46
|
-
return segments;
|
|
47
|
-
}
|
|
48
|
-
function assignAtPath(root, segments, error) {
|
|
49
|
-
let node = root;
|
|
50
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
51
|
-
const segment = segments[i];
|
|
52
|
-
let next = node[segment];
|
|
53
|
-
if (next === void 0) {
|
|
54
|
-
next = node[segment] = {};
|
|
55
|
-
}
|
|
56
|
-
if (!isBranch(next)) return;
|
|
57
|
-
node = next;
|
|
58
|
-
}
|
|
59
|
-
const leaf = segments[segments.length - 1];
|
|
60
|
-
const slot = node[leaf];
|
|
61
|
-
if (slot === void 0) node[leaf] = [error];
|
|
62
|
-
else if (Array.isArray(slot)) slot.push(error);
|
|
63
|
-
}
|
|
64
|
-
function isBranch(value) {
|
|
65
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
66
|
-
}
|
|
67
|
-
function pruneEmpty(node) {
|
|
68
|
-
let hasLeaf = false;
|
|
69
|
-
const result = {};
|
|
70
|
-
Object.entries(node).forEach(([key, value]) => {
|
|
71
|
-
if (isBranch(value)) {
|
|
72
|
-
const pruned = pruneEmpty(value);
|
|
73
|
-
if (pruned) {
|
|
74
|
-
result[key] = pruned;
|
|
75
|
-
hasLeaf = true;
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
result[key] = value;
|
|
79
|
-
hasLeaf = true;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return hasLeaf ? result : void 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { hasStandardProps, standardSchemaFormValidator, standardSchemaResolver };
|
|
1
|
+
import{V as t}from"../form-CfBBPz6p.mjs";function n(t){return!!t&&"object"==typeof t&&"function"==typeof t["~standard"]?.validate}function e(t){return{type:"standard",message:t?.message||"Validation failed"}}function r(t){return async n=>{const r=await t["~standard"].validate(n);if(r.issues?.length)return r.issues.map(e)}}function o(n){return async r=>{const o=await n["~standard"].validate(r),{issues:i}=o;if(!i?.length)return{[t]:!0,values:"value"in o?o.value:void 0};const c={};for(const t of i){const n=s(t);if(n.length)a(c,n,e(t));else{const n=c._form??=[];Array.isArray(n)&&n.push(e(t))}}return{[t]:!0,errors:u(c)||{}}}}function s(t){const n=t.path||[],e=[];for(const t of n){const n="object"==typeof t&&null!==t?t.key:t;e.push(String(n))}return e}function a(t,n,e){let r=t;for(let t=0;t<n.length-1;t++){const e=n[t];let o=r[e];if(void 0===o&&(o=r[e]={}),!i(o))return;r=o}const o=n[n.length-1],s=r[o];void 0===s?r[o]=[e]:Array.isArray(s)&&s.push(e)}function i(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}function u(t){let n=!1;const e={};return Object.entries(t).forEach(([t,r])=>{if(i(r)){const o=u(r);o&&(e[t]=o,n=!0)}else e[t]=r,n=!0}),n?e:void 0}export{n as hasStandardProps,o as standardSchemaFormValidator,r as standardSchemaResolver};
|
|
86
2
|
//# sourceMappingURL=standard-schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-schema.mjs","sources":["../../src/resolvers/standard-schema.ts"],"sourcesContent":["import {VALIDATION_OUTCOME} from '../form';\nimport type {FieldError, ValidationOutcome} from '../form';\nimport type {Validator} from '../hooks/validate';\n\n/**\n * Minimal copy of the Standard Schema v1 interfaces\n * (https://standardschema.dev) so this module has zero runtime and type\n * dependencies on any schema library. Implemented by zod v3.24+/v4,\n * valibot v1, arktype and others.\n */\nexport interface StandardSchemaIssue {\n readonly message: string;\n readonly path?:\n ReadonlyArray<PropertyKey | {readonly key: PropertyKey}> | undefined;\n}\n\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n readonly validate: (\n value: Input\n ) =>\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n | Promise<\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n >;\n };\n}\n\n/**\n * Does the schema implement the Standard Schema v1 props?\n */\nexport function hasStandardProps(schema: any): schema is StandardSchemaV1 {\n return (\n !!schema &&\n typeof schema === 'object' &&\n typeof schema['~standard']?.validate === 'function'\n );\n}\n\nfunction toFieldError(issue: StandardSchemaIssue | undefined): FieldError {\n return {type: 'standard', message: issue?.message || 'Validation failed'};\n}\n\n/**\n * Field-level Standard Schema adapter: validate a single value with any\n * schema implementing '~standard' and map every issue to a FieldError,\n * so a value breaking several rules surfaces all of them (setErrorByPath\n * stores the array; error/errorObject readers still see the first).\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return field validator compatible with useField's validate option\n */\nexport function standardSchemaResolver(schema: StandardSchemaV1): Validator {\n return async (value: any) => {\n const result = await schema['~standard'].validate(value);\n if (!result.issues?.length) return undefined;\n return result.issues.map(toFieldError);\n };\n}\n\n/**\n * Form-level Standard Schema adapter: validate the whole values object with\n * any schema implementing '~standard' and return a ValidationOutcome. On\n * failure `errors` carries the nested shape Options.validate expects\n * ({a: {b: FieldError[]}}; ensureValidate flattens it back to per-field\n * errors, keeping every issue of a path). Issues without a path are\n * form-level errors and land on the '_form' key. On success `values`\n * carries the schema's parsed output (coerce/transform results included),\n * which the form stores as its parsedValues baseline — the layer getValues\n * reads above initialValues, mirroring how react-hook-form's zodResolver\n * and TanStack's standardSchemaValidators use the parsed value.\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return form-level validator for createForm({validate: ...})\n */\nexport function standardSchemaFormValidator<T extends Record<string, any>>(\n schema: StandardSchemaV1<T, any>\n): (values: T) => Promise<ValidationOutcome<T>> {\n return async (values: T) => {\n const result = await schema['~standard'].validate(values);\n const {issues} = result;\n if (!issues?.length) {\n // Success: expose the schema's parsed output. `in` keeps the union\n // narrowed (the success variant is the one carrying `value`).\n return {\n [VALIDATION_OUTCOME]: true,\n values: 'value' in result ? result.value : undefined\n };\n }\n const errors: Record<string, any> = {};\n for (const issue of issues) {\n const segments = toPathSegments(issue);\n if (segments.length) {\n assignAtPath(errors, segments, toFieldError(issue));\n } else {\n // Pathless issues are all form-level: they accumulate on '_form'\n // instead of the first shadowing the rest. (A nested path literally\n // named '_form' would have made the slot a branch — skip then.)\n const slot = (errors._form ??= []);\n if (Array.isArray(slot)) slot.push(toFieldError(issue));\n }\n }\n return {[VALIDATION_OUTCOME]: true, errors: pruneEmpty(errors) || {}};\n };\n}\n\n/**\n * Stringify an issue path: PropertyKey or {key} path segments → strings.\n */\nfunction toPathSegments(issue: StandardSchemaIssue): string[] {\n const path = issue.path || [];\n const segments: string[] = [];\n for (const segment of path) {\n const key =\n typeof segment === 'object' && segment !== null\n ? (segment as {key: PropertyKey}).key\n : segment;\n segments.push(String(key));\n }\n return segments;\n}\n\n/**\n * Append the error at a nested path. Leaves are FieldError[] arrays, so\n * several issues on one field accumulate in issue order; an issue whose\n * path conflicts with an existing leaf or crosses it is skipped.\n */\nfunction assignAtPath(\n root: Record<string, any>,\n segments: string[],\n error: FieldError\n): void {\n let node = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i];\n let next = node[segment];\n if (next === undefined) {\n next = node[segment] = {};\n }\n if (!isBranch(next)) return;\n node = next;\n }\n const leaf = segments[segments.length - 1];\n const slot = node[leaf];\n if (slot === undefined) node[leaf] = [error];\n else if (Array.isArray(slot)) slot.push(error);\n}\n\n/**\n * A branch is a plain container built while nesting; the leaves it carries\n * are the FieldError[] arrays assignAtPath appends.\n */\nfunction isBranch(value: any): value is Record<string, any> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Drop empty branch objects left behind by conflicting issue paths.\n */\nfunction pruneEmpty(\n node: Record<string, any>\n): Record<string, any> | undefined {\n let hasLeaf = false;\n const result: Record<string, any> = {};\n Object.entries(node).forEach(([key, value]) => {\n if (isBranch(value)) {\n const pruned = pruneEmpty(value);\n if (pruned) {\n result[key] = pruned;\n hasLeaf = true;\n }\n } else {\n result[key] = value;\n hasLeaf = true;\n }\n });\n return hasLeaf ? result : undefined;\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"standard-schema.mjs","sources":["../../src/resolvers/standard-schema.ts"],"sourcesContent":["import {VALIDATION_OUTCOME} from '../form';\nimport type {FieldError, ValidationOutcome} from '../form';\nimport type {Validator} from '../hooks/validate';\n\n/**\n * Minimal copy of the Standard Schema v1 interfaces\n * (https://standardschema.dev) so this module has zero runtime and type\n * dependencies on any schema library. Implemented by zod v3.24+/v4,\n * valibot v1, arktype and others.\n */\nexport interface StandardSchemaIssue {\n readonly message: string;\n readonly path?:\n ReadonlyArray<PropertyKey | {readonly key: PropertyKey}> | undefined;\n}\n\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n readonly validate: (\n value: Input\n ) =>\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n | Promise<\n | {readonly value: Output; readonly issues?: undefined}\n | {readonly issues: ReadonlyArray<StandardSchemaIssue>}\n >;\n };\n}\n\n/**\n * Does the schema implement the Standard Schema v1 props?\n */\nexport function hasStandardProps(schema: any): schema is StandardSchemaV1 {\n return (\n !!schema &&\n typeof schema === 'object' &&\n typeof schema['~standard']?.validate === 'function'\n );\n}\n\nfunction toFieldError(issue: StandardSchemaIssue | undefined): FieldError {\n return {type: 'standard', message: issue?.message || 'Validation failed'};\n}\n\n/**\n * Field-level Standard Schema adapter: validate a single value with any\n * schema implementing '~standard' and map every issue to a FieldError,\n * so a value breaking several rules surfaces all of them (setErrorByPath\n * stores the array; error/errorObject readers still see the first).\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return field validator compatible with useField's validate option\n */\nexport function standardSchemaResolver(schema: StandardSchemaV1): Validator {\n return async (value: any) => {\n const result = await schema['~standard'].validate(value);\n if (!result.issues?.length) return undefined;\n return result.issues.map(toFieldError);\n };\n}\n\n/**\n * Form-level Standard Schema adapter: validate the whole values object with\n * any schema implementing '~standard' and return a ValidationOutcome. On\n * failure `errors` carries the nested shape Options.validate expects\n * ({a: {b: FieldError[]}}; ensureValidate flattens it back to per-field\n * errors, keeping every issue of a path). Issues without a path are\n * form-level errors and land on the '_form' key. On success `values`\n * carries the schema's parsed output (coerce/transform results included),\n * which the form stores as its parsedValues baseline — the layer getValues\n * reads above initialValues, mirroring how react-hook-form's zodResolver\n * and TanStack's standardSchemaValidators use the parsed value.\n *\n * @param schema a Standard Schema v1 (zod v3.24+/v4, valibot v1, arktype...)\n * @return form-level validator for createForm({validate: ...})\n */\nexport function standardSchemaFormValidator<T extends Record<string, any>>(\n schema: StandardSchemaV1<T, any>\n): (values: T) => Promise<ValidationOutcome<T>> {\n return async (values: T) => {\n const result = await schema['~standard'].validate(values);\n const {issues} = result;\n if (!issues?.length) {\n // Success: expose the schema's parsed output. `in` keeps the union\n // narrowed (the success variant is the one carrying `value`).\n return {\n [VALIDATION_OUTCOME]: true,\n values: 'value' in result ? result.value : undefined\n };\n }\n const errors: Record<string, any> = {};\n for (const issue of issues) {\n const segments = toPathSegments(issue);\n if (segments.length) {\n assignAtPath(errors, segments, toFieldError(issue));\n } else {\n // Pathless issues are all form-level: they accumulate on '_form'\n // instead of the first shadowing the rest. (A nested path literally\n // named '_form' would have made the slot a branch — skip then.)\n const slot = (errors._form ??= []);\n if (Array.isArray(slot)) slot.push(toFieldError(issue));\n }\n }\n return {[VALIDATION_OUTCOME]: true, errors: pruneEmpty(errors) || {}};\n };\n}\n\n/**\n * Stringify an issue path: PropertyKey or {key} path segments → strings.\n */\nfunction toPathSegments(issue: StandardSchemaIssue): string[] {\n const path = issue.path || [];\n const segments: string[] = [];\n for (const segment of path) {\n const key =\n typeof segment === 'object' && segment !== null\n ? (segment as {key: PropertyKey}).key\n : segment;\n segments.push(String(key));\n }\n return segments;\n}\n\n/**\n * Append the error at a nested path. Leaves are FieldError[] arrays, so\n * several issues on one field accumulate in issue order; an issue whose\n * path conflicts with an existing leaf or crosses it is skipped.\n */\nfunction assignAtPath(\n root: Record<string, any>,\n segments: string[],\n error: FieldError\n): void {\n let node = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i];\n let next = node[segment];\n if (next === undefined) {\n next = node[segment] = {};\n }\n if (!isBranch(next)) return;\n node = next;\n }\n const leaf = segments[segments.length - 1];\n const slot = node[leaf];\n if (slot === undefined) node[leaf] = [error];\n else if (Array.isArray(slot)) slot.push(error);\n}\n\n/**\n * A branch is a plain container built while nesting; the leaves it carries\n * are the FieldError[] arrays assignAtPath appends.\n */\nfunction isBranch(value: any): value is Record<string, any> {\n return !!value && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Drop empty branch objects left behind by conflicting issue paths.\n */\nfunction pruneEmpty(\n node: Record<string, any>\n): Record<string, any> | undefined {\n let hasLeaf = false;\n const result: Record<string, any> = {};\n Object.entries(node).forEach(([key, value]) => {\n if (isBranch(value)) {\n const pruned = pruneEmpty(value);\n if (pruned) {\n result[key] = pruned;\n hasLeaf = true;\n }\n } else {\n result[key] = value;\n hasLeaf = true;\n }\n });\n return hasLeaf ? result : undefined;\n}\n"],"names":["hasStandardProps","schema","validate","toFieldError","issue","type","message","standardSchemaResolver","async","value","result","issues","length","map","standardSchemaFormValidator","values","VALIDATION_OUTCOME","errors","segments","toPathSegments","assignAtPath","slot","_form","Array","isArray","push","pruneEmpty","path","segment","key","String","root","error","node","i","next","isBranch","leaf","hasLeaf","Object","entries","forEach","pruned"],"mappings":"yCAmCO,SAASA,EAAiBC,GAC/B,QACIA,GACgB,iBAAXA,GACkC,mBAAlCA,EAAO,cAAcC,QAEhC,CAEA,SAASC,EAAaC,GACpB,MAAO,CAACC,KAAM,WAAYC,QAASF,GAAOE,SAAW,oBACvD,CAWO,SAASC,EAAuBN,GACrC,OAAOO,MAAOC,IACZ,MAAMC,QAAeT,EAAO,aAAaC,SAASO,GAClD,GAAKC,EAAOC,QAAQC,OACpB,OAAOF,EAAOC,OAAOE,IAAIV,GAE7B,CAiBO,SAASW,EACdb,GAEA,OAAOO,MAAOO,IACZ,MAAML,QAAeT,EAAO,aAAaC,SAASa,IAC5CJ,OAACA,GAAUD,EACjB,IAAKC,GAAQC,OAGX,MAAO,CACLI,CAACA,IAAqB,EACtBD,OAAQ,UAAWL,EAASA,EAAOD,WAAQ,GAG/C,MAAMQ,EAA8B,CAAA,EACpC,IAAA,MAAWb,KAASO,EAAQ,CAC1B,MAAMO,EAAWC,EAAef,GAChC,GAAIc,EAASN,OACXQ,EAAaH,EAAQC,EAAUf,EAAaC,QACvC,CAIL,MAAMiB,EAAQJ,EAAOK,QAAU,GAC3BC,MAAMC,QAAQH,MAAYI,KAAKtB,EAAaC,GAClD,CACF,CACA,MAAO,CAACY,CAACA,IAAqB,EAAMC,OAAQS,EAAWT,IAAW,IAEtE,CAKA,SAASE,EAAef,GACtB,MAAMuB,EAAOvB,EAAMuB,MAAQ,GACrBT,EAAqB,GAC3B,IAAA,MAAWU,KAAWD,EAAM,CAC1B,MAAME,EACe,iBAAZD,GAAoC,OAAZA,EAC1BA,EAA+BC,IAChCD,EACNV,EAASO,KAAKK,OAAOD,GACvB,CACA,OAAOX,CACT,CAOA,SAASE,EACPW,EACAb,EACAc,GAEA,IAAIC,EAAOF,EACX,IAAA,IAASG,EAAI,EAAGA,EAAIhB,EAASN,OAAS,EAAGsB,IAAK,CAC5C,MAAMN,EAAUV,EAASgB,GACzB,IAAIC,EAAOF,EAAKL,GAIhB,QAHa,IAATO,IACFA,EAAOF,EAAKL,GAAW,CAAA,IAEpBQ,EAASD,GAAO,OACrBF,EAAOE,CACT,CACA,MAAME,EAAOnB,EAASA,EAASN,OAAS,GAClCS,EAAOY,EAAKI,QACL,IAAThB,EAAoBY,EAAKI,GAAQ,CAACL,GAC7BT,MAAMC,QAAQH,IAAOA,EAAKI,KAAKO,EAC1C,CAMA,SAASI,EAAS3B,GAChB,QAASA,GAA0B,iBAAVA,IAAuBc,MAAMC,QAAQf,EAChE,CAKA,SAASiB,EACPO,GAEA,IAAIK,GAAU,EACd,MAAM5B,EAA8B,CAAA,EAapC,OAZA6B,OAAOC,QAAQP,GAAMQ,QAAQ,EAAEZ,EAAKpB,MAClC,GAAI2B,EAAS3B,GAAQ,CACnB,MAAMiC,EAAShB,EAAWjB,GACtBiC,IACFhC,EAAOmB,GAAOa,EACdJ,GAAU,EAEd,MACE5B,EAAOmB,GAAOpB,EACd6B,GAAU,IAGPA,EAAU5B,OAAS,CAC5B"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var resolvers_standardSchema = require('./standard-schema.cjs.js');
|
|
4
|
-
require('../form-DbnzAKSM.cjs.js');
|
|
5
|
-
|
|
6
|
-
function yupResolver(schema) {
|
|
7
|
-
if (resolvers_standardSchema.hasStandardProps(schema)) return resolvers_standardSchema.standardSchemaResolver(schema);
|
|
8
|
-
return async (value) => {
|
|
9
|
-
try {
|
|
10
|
-
await schema.validate(value, { abortEarly: false });
|
|
11
|
-
return void 0;
|
|
12
|
-
} catch (err) {
|
|
13
|
-
const issues = Array.isArray(err?.inner) && err.inner.length ? err.inner : [err];
|
|
14
|
-
return issues.map((issue) => ({
|
|
15
|
-
type: issue?.type || "custom",
|
|
16
|
-
message: issue?.message || "Validation failed"
|
|
17
|
-
}));
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
exports.yupResolver = yupResolver;
|
|
1
|
+
"use strict";var r=require("./standard-schema.cjs.js");require("../form-CGRvih_c.cjs.js"),exports.yupResolver=function(e){return r.hasStandardProps(e)?r.standardSchemaResolver(e):async r=>{try{return void await e.validate(r,{abortEarly:!1})}catch(r){return(Array.isArray(r?.inner)&&r.inner.length?r.inner:[r]).map(r=>({type:r?.type||"custom",message:r?.message||"Validation failed"}))}}};
|
|
23
2
|
//# sourceMappingURL=yup.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.cjs.js","sources":["../../src/resolvers/yup.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function yupResolver(schema: any): Validator {\n // Recent yup versions implement the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older yup: fall back to the throw-based validate API. abortEarly:false\n // makes yup aggregate every failure into err.inner instead of throwing\n // on the first, so all of a field's errors reach the form.\n return async (value: any) => {\n try {\n await schema.validate(value, {abortEarly: false});\n return undefined;\n } catch (err: any) {\n const issues =\n Array.isArray(err?.inner) && err.inner.length ? err.inner : [err];\n return issues.map((issue: any): FieldError => ({\n type: issue?.type || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n }\n };\n}\n"],"names":["hasStandardProps","standardSchemaResolver"
|
|
1
|
+
{"version":3,"file":"yup.cjs.js","sources":["../../src/resolvers/yup.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function yupResolver(schema: any): Validator {\n // Recent yup versions implement the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older yup: fall back to the throw-based validate API. abortEarly:false\n // makes yup aggregate every failure into err.inner instead of throwing\n // on the first, so all of a field's errors reach the form.\n return async (value: any) => {\n try {\n await schema.validate(value, {abortEarly: false});\n return undefined;\n } catch (err: any) {\n const issues =\n Array.isArray(err?.inner) && err.inner.length ? err.inner : [err];\n return issues.map((issue: any): FieldError => ({\n type: issue?.type || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n }\n };\n}\n"],"names":["schema","hasStandardProps","standardSchemaResolver","async","value","validate","abortEarly","err","Array","isArray","inner","length","map","issue","type","message"],"mappings":"8GAIO,SAAqBA,GAE1B,OAAIC,EAAAA,iBAAiBD,GAAgBE,EAAAA,uBAAuBF,GAIrDG,MAAOC,IACZ,IAEE,kBADMJ,EAAOK,SAASD,EAAO,CAACE,YAAY,GAE5C,OAASC,GAGP,OADEC,MAAMC,QAAQF,GAAKG,QAAUH,EAAIG,MAAMC,OAASJ,EAAIG,MAAQ,CAACH,IACjDK,IAAKC,IAAA,CACjBC,KAAMD,GAAOC,MAAQ,SACrBC,QAASF,GAAOE,SAAW,sBAE/B,EAEJ"}
|
package/dist/resolvers/yup.d.ts
CHANGED
package/dist/resolvers/yup.mjs
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '../form-CXF5HwQG.mjs';
|
|
3
|
-
|
|
4
|
-
function yupResolver(schema) {
|
|
5
|
-
if (hasStandardProps(schema)) return standardSchemaResolver(schema);
|
|
6
|
-
return async (value) => {
|
|
7
|
-
try {
|
|
8
|
-
await schema.validate(value, { abortEarly: false });
|
|
9
|
-
return void 0;
|
|
10
|
-
} catch (err) {
|
|
11
|
-
const issues = Array.isArray(err?.inner) && err.inner.length ? err.inner : [err];
|
|
12
|
-
return issues.map((issue) => ({
|
|
13
|
-
type: issue?.type || "custom",
|
|
14
|
-
message: issue?.message || "Validation failed"
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { yupResolver };
|
|
1
|
+
import{hasStandardProps as r,standardSchemaResolver as a}from"./standard-schema.mjs";import"../form-CfBBPz6p.mjs";function t(t){return r(t)?a(t):async r=>{try{return void await t.validate(r,{abortEarly:!1})}catch(r){return(Array.isArray(r?.inner)&&r.inner.length?r.inner:[r]).map(r=>({type:r?.type||"custom",message:r?.message||"Validation failed"}))}}}export{t as yupResolver};
|
|
21
2
|
//# sourceMappingURL=yup.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.mjs","sources":["../../src/resolvers/yup.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function yupResolver(schema: any): Validator {\n // Recent yup versions implement the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older yup: fall back to the throw-based validate API. abortEarly:false\n // makes yup aggregate every failure into err.inner instead of throwing\n // on the first, so all of a field's errors reach the form.\n return async (value: any) => {\n try {\n await schema.validate(value, {abortEarly: false});\n return undefined;\n } catch (err: any) {\n const issues =\n Array.isArray(err?.inner) && err.inner.length ? err.inner : [err];\n return issues.map((issue: any): FieldError => ({\n type: issue?.type || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n }\n };\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"yup.mjs","sources":["../../src/resolvers/yup.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function yupResolver(schema: any): Validator {\n // Recent yup versions implement the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older yup: fall back to the throw-based validate API. abortEarly:false\n // makes yup aggregate every failure into err.inner instead of throwing\n // on the first, so all of a field's errors reach the form.\n return async (value: any) => {\n try {\n await schema.validate(value, {abortEarly: false});\n return undefined;\n } catch (err: any) {\n const issues =\n Array.isArray(err?.inner) && err.inner.length ? err.inner : [err];\n return issues.map((issue: any): FieldError => ({\n type: issue?.type || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n }\n };\n}\n"],"names":["yupResolver","schema","hasStandardProps","standardSchemaResolver","async","value","validate","abortEarly","err","Array","isArray","inner","length","map","issue","type","message"],"mappings":"kHAIO,SAASA,EAAYC,GAE1B,OAAIC,EAAiBD,GAAgBE,EAAuBF,GAIrDG,MAAOC,IACZ,IAEE,kBADMJ,EAAOK,SAASD,EAAO,CAACE,YAAY,GAE5C,OAASC,GAGP,OADEC,MAAMC,QAAQF,GAAKG,QAAUH,EAAIG,MAAMC,OAASJ,EAAIG,MAAQ,CAACH,IACjDK,IAAKC,IAAA,CACjBC,KAAMD,GAAOC,MAAQ,SACrBC,QAASF,GAAOE,SAAW,sBAE/B,EAEJ"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var resolvers_standardSchema = require('./standard-schema.cjs.js');
|
|
4
|
-
require('../form-DbnzAKSM.cjs.js');
|
|
5
|
-
|
|
6
|
-
function zodResolver(schema) {
|
|
7
|
-
if (resolvers_standardSchema.hasStandardProps(schema)) return resolvers_standardSchema.standardSchemaResolver(schema);
|
|
8
|
-
return async (value) => {
|
|
9
|
-
const result = await schema.safeParseAsync(value);
|
|
10
|
-
if (result.success) return void 0;
|
|
11
|
-
const { issues } = result.error;
|
|
12
|
-
if (!issues?.length) {
|
|
13
|
-
return [{ type: "custom", message: "Validation failed" }];
|
|
14
|
-
}
|
|
15
|
-
return issues.map((issue) => ({
|
|
16
|
-
type: issue?.code || "custom",
|
|
17
|
-
message: issue?.message || "Validation failed"
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
exports.zodResolver = zodResolver;
|
|
1
|
+
"use strict";var s=require("./standard-schema.cjs.js");require("../form-CGRvih_c.cjs.js"),exports.zodResolver=function(e){return s.hasStandardProps(e)?s.standardSchemaResolver(e):async s=>{const a=await e.safeParseAsync(s);if(a.success)return;const{issues:r}=a.error;return r?.length?r.map(s=>({type:s?.code||"custom",message:s?.message||"Validation failed"})):[{type:"custom",message:"Validation failed"}]}};
|
|
23
2
|
//# sourceMappingURL=zod.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.cjs.js","sources":["../../src/resolvers/zod.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function zodResolver(schema: any): Validator {\n // zod v3.24+/v4 schemas carry the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older zod: fall back to the legacy safeParseAsync API. It aggregates\n // every issue (no abortEarly), so map them all — a value breaking\n // several rules surfaces all of its errors.\n return async (value: any) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return undefined;\n const {issues} = result.error;\n if (!issues?.length) {\n return [{type: 'custom', message: 'Validation failed'}];\n }\n return issues.map((issue: any): FieldError => ({\n type: issue?.code || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n };\n}\n"],"names":["hasStandardProps","standardSchemaResolver"
|
|
1
|
+
{"version":3,"file":"zod.cjs.js","sources":["../../src/resolvers/zod.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function zodResolver(schema: any): Validator {\n // zod v3.24+/v4 schemas carry the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older zod: fall back to the legacy safeParseAsync API. It aggregates\n // every issue (no abortEarly), so map them all — a value breaking\n // several rules surfaces all of its errors.\n return async (value: any) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return undefined;\n const {issues} = result.error;\n if (!issues?.length) {\n return [{type: 'custom', message: 'Validation failed'}];\n }\n return issues.map((issue: any): FieldError => ({\n type: issue?.code || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n };\n}\n"],"names":["schema","hasStandardProps","standardSchemaResolver","async","value","result","safeParseAsync","success","issues","error","length","map","issue","type","code","message"],"mappings":"8GAIO,SAAqBA,GAE1B,OAAIC,EAAAA,iBAAiBD,GAAgBE,EAAAA,uBAAuBF,GAIrDG,MAAOC,IACZ,MAAMC,QAAeL,EAAOM,eAAeF,GAC3C,GAAIC,EAAOE,QAAS,OACpB,MAAMC,OAACA,GAAUH,EAAOI,MACxB,OAAKD,GAAQE,OAGNF,EAAOG,IAAKC,IAAA,CACjBC,KAAMD,GAAOE,MAAQ,SACrBC,QAASH,GAAOG,SAAW,uBAJpB,CAAC,CAACF,KAAM,SAAUE,QAAS,sBAOxC"}
|
package/dist/resolvers/zod.d.ts
CHANGED
package/dist/resolvers/zod.mjs
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '../form-CXF5HwQG.mjs';
|
|
3
|
-
|
|
4
|
-
function zodResolver(schema) {
|
|
5
|
-
if (hasStandardProps(schema)) return standardSchemaResolver(schema);
|
|
6
|
-
return async (value) => {
|
|
7
|
-
const result = await schema.safeParseAsync(value);
|
|
8
|
-
if (result.success) return void 0;
|
|
9
|
-
const { issues } = result.error;
|
|
10
|
-
if (!issues?.length) {
|
|
11
|
-
return [{ type: "custom", message: "Validation failed" }];
|
|
12
|
-
}
|
|
13
|
-
return issues.map((issue) => ({
|
|
14
|
-
type: issue?.code || "custom",
|
|
15
|
-
message: issue?.message || "Validation failed"
|
|
16
|
-
}));
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { zodResolver };
|
|
1
|
+
import{hasStandardProps as s,standardSchemaResolver as e}from"./standard-schema.mjs";import"../form-CfBBPz6p.mjs";function a(a){return s(a)?e(a):async s=>{const e=await a.safeParseAsync(s);if(e.success)return;const{issues:t}=e.error;return t?.length?t.map(s=>({type:s?.code||"custom",message:s?.message||"Validation failed"})):[{type:"custom",message:"Validation failed"}]}}export{a as zodResolver};
|
|
21
2
|
//# sourceMappingURL=zod.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.mjs","sources":["../../src/resolvers/zod.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function zodResolver(schema: any): Validator {\n // zod v3.24+/v4 schemas carry the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older zod: fall back to the legacy safeParseAsync API. It aggregates\n // every issue (no abortEarly), so map them all — a value breaking\n // several rules surfaces all of its errors.\n return async (value: any) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return undefined;\n const {issues} = result.error;\n if (!issues?.length) {\n return [{type: 'custom', message: 'Validation failed'}];\n }\n return issues.map((issue: any): FieldError => ({\n type: issue?.code || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n };\n}\n"],"names":[
|
|
1
|
+
{"version":3,"file":"zod.mjs","sources":["../../src/resolvers/zod.ts"],"sourcesContent":["import type {FieldError} from '../form';\nimport type {Validator} from '../hooks/validate';\nimport {hasStandardProps, standardSchemaResolver} from './standard-schema';\n\nexport function zodResolver(schema: any): Validator {\n // zod v3.24+/v4 schemas carry the Standard Schema props — prefer them.\n if (hasStandardProps(schema)) return standardSchemaResolver(schema);\n // Older zod: fall back to the legacy safeParseAsync API. It aggregates\n // every issue (no abortEarly), so map them all — a value breaking\n // several rules surfaces all of its errors.\n return async (value: any) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return undefined;\n const {issues} = result.error;\n if (!issues?.length) {\n return [{type: 'custom', message: 'Validation failed'}];\n }\n return issues.map((issue: any): FieldError => ({\n type: issue?.code || 'custom',\n message: issue?.message || 'Validation failed'\n }));\n };\n}\n"],"names":["zodResolver","schema","hasStandardProps","standardSchemaResolver","async","value","result","safeParseAsync","success","issues","error","length","map","issue","type","code","message"],"mappings":"kHAIO,SAASA,EAAYC,GAE1B,OAAIC,EAAiBD,GAAgBE,EAAuBF,GAIrDG,MAAOC,IACZ,MAAMC,QAAeL,EAAOM,eAAeF,GAC3C,GAAIC,EAAOE,QAAS,OACpB,MAAMC,OAACA,GAAUH,EAAOI,MACxB,OAAKD,GAAQE,OAGNF,EAAOG,IAAKC,IAAA,CACjBC,KAAMD,GAAOE,MAAQ,SACrBC,QAASH,GAAOG,SAAW,uBAJpB,CAAC,CAACF,KAAM,SAAUE,QAAS,sBAOxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-f0rm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"packageManager": "pnpm@11.4.0",
|
|
5
5
|
"description": "react form",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -153,6 +153,11 @@
|
|
|
153
153
|
{
|
|
154
154
|
"path": "dist/index.mjs",
|
|
155
155
|
"limit": "10 KB"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"path": "dist/index.mjs",
|
|
159
|
+
"limit": "10 KB",
|
|
160
|
+
"gzip": true
|
|
156
161
|
}
|
|
157
162
|
]
|
|
158
163
|
}
|