@tanstack/form-core 1.23.1 → 1.23.3
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.
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function prefixSchemaToErrors(issues) {
|
|
3
|
+
function prefixSchemaToErrors(issues, formValue) {
|
|
4
4
|
const schema = /* @__PURE__ */ new Map();
|
|
5
5
|
for (const issue of issues) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const issuePath = issue.path ?? [];
|
|
7
|
+
let currentFormValue = formValue;
|
|
8
|
+
let path = "";
|
|
9
|
+
for (let i = 0; i < issuePath.length; i++) {
|
|
10
|
+
const pathSegment = issuePath[i];
|
|
11
|
+
if (pathSegment === void 0) continue;
|
|
12
|
+
const segment = typeof pathSegment === "object" ? pathSegment.key : pathSegment;
|
|
13
|
+
const segmentAsNumber = Number(segment);
|
|
14
|
+
if (Array.isArray(currentFormValue) && !Number.isNaN(segmentAsNumber)) {
|
|
15
|
+
path += `[${segmentAsNumber}]`;
|
|
16
|
+
} else {
|
|
17
|
+
path += (i > 0 ? "." : "") + String(segment);
|
|
18
|
+
}
|
|
19
|
+
if (typeof currentFormValue === "object" && currentFormValue !== null) {
|
|
20
|
+
currentFormValue = currentFormValue[segment];
|
|
21
|
+
} else {
|
|
22
|
+
currentFormValue = void 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
10
25
|
schema.set(path, (schema.get(path) ?? []).concat(issue));
|
|
11
26
|
}
|
|
12
27
|
return Object.fromEntries(schema);
|
|
13
28
|
}
|
|
14
|
-
const transformFormIssues = (issues) => {
|
|
15
|
-
const schemaErrors = prefixSchemaToErrors(issues);
|
|
29
|
+
const transformFormIssues = (issues, formValue) => {
|
|
30
|
+
const schemaErrors = prefixSchemaToErrors(issues, formValue);
|
|
16
31
|
return {
|
|
17
32
|
form: schemaErrors,
|
|
18
33
|
fields: schemaErrors
|
|
@@ -30,7 +45,7 @@ const standardSchemaValidators = {
|
|
|
30
45
|
if (!result.issues) return;
|
|
31
46
|
if (validationSource === "field")
|
|
32
47
|
return result.issues;
|
|
33
|
-
return transformFormIssues(result.issues);
|
|
48
|
+
return transformFormIssues(result.issues, value);
|
|
34
49
|
},
|
|
35
50
|
async validateAsync({
|
|
36
51
|
value,
|
|
@@ -40,7 +55,7 @@ const standardSchemaValidators = {
|
|
|
40
55
|
if (!result.issues) return;
|
|
41
56
|
if (validationSource === "field")
|
|
42
57
|
return result.issues;
|
|
43
|
-
return transformFormIssues(result.issues);
|
|
58
|
+
return transformFormIssues(result.issues, value);
|
|
44
59
|
}
|
|
45
60
|
};
|
|
46
61
|
const isStandardSchemaValidator = (validator) => !!validator && "~standard" in validator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardSchemaValidator.cjs","sources":["../../src/standardSchemaValidator.ts"],"sourcesContent":["import type { ValidationSource } from './types'\n\nexport type TStandardSchemaValidatorValue<\n TData,\n TSource extends ValidationSource = ValidationSource,\n> = {\n value: TData\n validationSource: TSource\n}\n\nexport type TStandardSchemaValidatorIssue<\n TSource extends ValidationSource = ValidationSource,\n> = TSource extends 'form'\n ? {\n form: Record<string, StandardSchemaV1Issue[]>\n fields: Record<string, StandardSchemaV1Issue[]>\n }\n : TSource extends 'field'\n ? StandardSchemaV1Issue[]\n : never\n\nfunction prefixSchemaToErrors(issues: readonly StandardSchemaV1Issue[]) {\n const schema = new Map<string, StandardSchemaV1Issue[]>()\n\n for (const issue of issues) {\n const
|
|
1
|
+
{"version":3,"file":"standardSchemaValidator.cjs","sources":["../../src/standardSchemaValidator.ts"],"sourcesContent":["import type { ValidationSource } from './types'\n\nexport type TStandardSchemaValidatorValue<\n TData,\n TSource extends ValidationSource = ValidationSource,\n> = {\n value: TData\n validationSource: TSource\n}\n\nexport type TStandardSchemaValidatorIssue<\n TSource extends ValidationSource = ValidationSource,\n> = TSource extends 'form'\n ? {\n form: Record<string, StandardSchemaV1Issue[]>\n fields: Record<string, StandardSchemaV1Issue[]>\n }\n : TSource extends 'field'\n ? StandardSchemaV1Issue[]\n : never\n\nfunction prefixSchemaToErrors(\n issues: readonly StandardSchemaV1Issue[],\n formValue: unknown,\n) {\n const schema = new Map<string, StandardSchemaV1Issue[]>()\n\n for (const issue of issues) {\n const issuePath = issue.path ?? []\n\n let currentFormValue = formValue\n let path = ''\n\n for (let i = 0; i < issuePath.length; i++) {\n const pathSegment = issuePath[i]\n if (pathSegment === undefined) continue\n\n const segment =\n typeof pathSegment === 'object' ? pathSegment.key : pathSegment\n\n // Standard Schema doesn't specify if paths should use numbers or stringified numbers for array access.\n // However, if we follow the path it provides and encounter an array, then we can assume it's intended for array access.\n const segmentAsNumber = Number(segment)\n if (Array.isArray(currentFormValue) && !Number.isNaN(segmentAsNumber)) {\n path += `[${segmentAsNumber}]`\n } else {\n path += (i > 0 ? '.' : '') + String(segment)\n }\n\n if (typeof currentFormValue === 'object' && currentFormValue !== null) {\n currentFormValue = currentFormValue[segment as never]\n } else {\n currentFormValue = undefined\n }\n }\n schema.set(path, (schema.get(path) ?? []).concat(issue))\n }\n\n return Object.fromEntries(schema)\n}\n\nconst transformFormIssues = <TSource extends ValidationSource>(\n issues: readonly StandardSchemaV1Issue[],\n formValue: unknown,\n): TStandardSchemaValidatorIssue<TSource> => {\n const schemaErrors = prefixSchemaToErrors(issues, formValue)\n return {\n form: schemaErrors,\n fields: schemaErrors,\n } as TStandardSchemaValidatorIssue<TSource>\n}\n\nexport const standardSchemaValidators = {\n validate<TSource extends ValidationSource = ValidationSource>(\n {\n value,\n validationSource,\n }: TStandardSchemaValidatorValue<unknown, TSource>,\n schema: StandardSchemaV1,\n ): TStandardSchemaValidatorIssue<TSource> | undefined {\n const result = schema['~standard'].validate(value)\n\n if (result instanceof Promise) {\n throw new Error('async function passed to sync validator')\n }\n\n if (!result.issues) return\n\n if (validationSource === 'field')\n return result.issues as TStandardSchemaValidatorIssue<TSource>\n return transformFormIssues<TSource>(result.issues, value)\n },\n async validateAsync<TSource extends ValidationSource>(\n {\n value,\n validationSource,\n }: TStandardSchemaValidatorValue<unknown, TSource>,\n schema: StandardSchemaV1,\n ): Promise<TStandardSchemaValidatorIssue<TSource> | undefined> {\n const result = await schema['~standard'].validate(value)\n\n if (!result.issues) return\n\n if (validationSource === 'field')\n return result.issues as TStandardSchemaValidatorIssue<TSource>\n return transformFormIssues<TSource>(result.issues, value)\n },\n}\n\nexport const isStandardSchemaValidator = (\n validator: unknown,\n): validator is StandardSchemaV1 =>\n !!validator && '~standard' in (validator as object)\n\n/**\n * The Standard Schema interface.\n */\nexport type StandardSchemaV1<Input = unknown, Output = Input> = {\n /**\n * The Standard Schema properties.\n */\n readonly '~standard': StandardSchemaV1Props<Input, Output>\n}\n\n/**\n * The Standard Schema properties interface.\n */\ninterface StandardSchemaV1Props<Input = unknown, Output = Input> {\n /**\n * The version number of the standard.\n */\n readonly version: 1\n /**\n * The vendor name of the schema library.\n */\n readonly vendor: string\n /**\n * Validates unknown input values.\n */\n readonly validate: (\n value: unknown,\n ) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>\n /**\n * Inferred types associated with the schema.\n */\n readonly types?: StandardSchemaV1Types<Input, Output> | undefined\n}\n/**\n * The result interface of the validate function.\n */\ntype StandardSchemaV1Result<Output> =\n | StandardSchemaV1SuccessResult<Output>\n | StandardSchemaV1FailureResult\n/**\n * The result interface if validation succeeds.\n */\ninterface StandardSchemaV1SuccessResult<Output> {\n /**\n * The typed output value.\n */\n readonly value: Output\n /**\n * The non-existent issues.\n */\n readonly issues?: undefined\n}\n/**\n * The result interface if validation fails.\n */\ninterface StandardSchemaV1FailureResult {\n /**\n * The issues of failed validation.\n */\n readonly issues: ReadonlyArray<StandardSchemaV1Issue>\n}\n/**\n * The issue interface of the failure output.\n */\nexport interface StandardSchemaV1Issue {\n /**\n * The error message of the issue.\n */\n readonly message: string\n /**\n * The path of the issue, if any.\n */\n readonly path?:\n | ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment>\n | undefined\n}\n/**\n * The path segment interface of the issue.\n */\ninterface StandardSchemaV1PathSegment {\n /**\n * The key representing a path segment.\n */\n readonly key: PropertyKey\n}\n/**\n * The Standard Schema types interface.\n */\ninterface StandardSchemaV1Types<Input = unknown, Output = Input> {\n /**\n * The input type of the schema.\n */\n readonly input: Input\n /**\n * The output type of the schema.\n */\n readonly output: Output\n}\n"],"names":[],"mappings":";;AAqBA,SAAS,qBACP,QACA,WACA;AACA,QAAM,6BAAa,IAAA;AAEnB,aAAW,SAAS,QAAQ;AAC1B,UAAM,YAAY,MAAM,QAAQ,CAAA;AAEhC,QAAI,mBAAmB;AACvB,QAAI,OAAO;AAEX,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,YAAM,cAAc,UAAU,CAAC;AAC/B,UAAI,gBAAgB,OAAW;AAE/B,YAAM,UACJ,OAAO,gBAAgB,WAAW,YAAY,MAAM;AAItD,YAAM,kBAAkB,OAAO,OAAO;AACtC,UAAI,MAAM,QAAQ,gBAAgB,KAAK,CAAC,OAAO,MAAM,eAAe,GAAG;AACrE,gBAAQ,IAAI,eAAe;AAAA,MAC7B,OAAO;AACL,iBAAS,IAAI,IAAI,MAAM,MAAM,OAAO,OAAO;AAAA,MAC7C;AAEA,UAAI,OAAO,qBAAqB,YAAY,qBAAqB,MAAM;AACrE,2BAAmB,iBAAiB,OAAgB;AAAA,MACtD,OAAO;AACL,2BAAmB;AAAA,MACrB;AAAA,IACF;AACA,WAAO,IAAI,OAAO,OAAO,IAAI,IAAI,KAAK,CAAA,GAAI,OAAO,KAAK,CAAC;AAAA,EACzD;AAEA,SAAO,OAAO,YAAY,MAAM;AAClC;AAEA,MAAM,sBAAsB,CAC1B,QACA,cAC2C;AAC3C,QAAM,eAAe,qBAAqB,QAAQ,SAAS;AAC3D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,EAAA;AAEZ;AAEO,MAAM,2BAA2B;AAAA,EACtC,SACE;AAAA,IACE;AAAA,IACA;AAAA,EAAA,GAEF,QACoD;AACpD,UAAM,SAAS,OAAO,WAAW,EAAE,SAAS,KAAK;AAEjD,QAAI,kBAAkB,SAAS;AAC7B,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AAEA,QAAI,CAAC,OAAO,OAAQ;AAEpB,QAAI,qBAAqB;AACvB,aAAO,OAAO;AAChB,WAAO,oBAA6B,OAAO,QAAQ,KAAK;AAAA,EAC1D;AAAA,EACA,MAAM,cACJ;AAAA,IACE;AAAA,IACA;AAAA,EAAA,GAEF,QAC6D;AAC7D,UAAM,SAAS,MAAM,OAAO,WAAW,EAAE,SAAS,KAAK;AAEvD,QAAI,CAAC,OAAO,OAAQ;AAEpB,QAAI,qBAAqB;AACvB,aAAO,OAAO;AAChB,WAAO,oBAA6B,OAAO,QAAQ,KAAK;AAAA,EAC1D;AACF;AAEO,MAAM,4BAA4B,CACvC,cAEA,CAAC,CAAC,aAAa,eAAgB;;;"}
|
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
function prefixSchemaToErrors(issues) {
|
|
1
|
+
function prefixSchemaToErrors(issues, formValue) {
|
|
2
2
|
const schema = /* @__PURE__ */ new Map();
|
|
3
3
|
for (const issue of issues) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const issuePath = issue.path ?? [];
|
|
5
|
+
let currentFormValue = formValue;
|
|
6
|
+
let path = "";
|
|
7
|
+
for (let i = 0; i < issuePath.length; i++) {
|
|
8
|
+
const pathSegment = issuePath[i];
|
|
9
|
+
if (pathSegment === void 0) continue;
|
|
10
|
+
const segment = typeof pathSegment === "object" ? pathSegment.key : pathSegment;
|
|
11
|
+
const segmentAsNumber = Number(segment);
|
|
12
|
+
if (Array.isArray(currentFormValue) && !Number.isNaN(segmentAsNumber)) {
|
|
13
|
+
path += `[${segmentAsNumber}]`;
|
|
14
|
+
} else {
|
|
15
|
+
path += (i > 0 ? "." : "") + String(segment);
|
|
16
|
+
}
|
|
17
|
+
if (typeof currentFormValue === "object" && currentFormValue !== null) {
|
|
18
|
+
currentFormValue = currentFormValue[segment];
|
|
19
|
+
} else {
|
|
20
|
+
currentFormValue = void 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
8
23
|
schema.set(path, (schema.get(path) ?? []).concat(issue));
|
|
9
24
|
}
|
|
10
25
|
return Object.fromEntries(schema);
|
|
11
26
|
}
|
|
12
|
-
const transformFormIssues = (issues) => {
|
|
13
|
-
const schemaErrors = prefixSchemaToErrors(issues);
|
|
27
|
+
const transformFormIssues = (issues, formValue) => {
|
|
28
|
+
const schemaErrors = prefixSchemaToErrors(issues, formValue);
|
|
14
29
|
return {
|
|
15
30
|
form: schemaErrors,
|
|
16
31
|
fields: schemaErrors
|
|
@@ -28,7 +43,7 @@ const standardSchemaValidators = {
|
|
|
28
43
|
if (!result.issues) return;
|
|
29
44
|
if (validationSource === "field")
|
|
30
45
|
return result.issues;
|
|
31
|
-
return transformFormIssues(result.issues);
|
|
46
|
+
return transformFormIssues(result.issues, value);
|
|
32
47
|
},
|
|
33
48
|
async validateAsync({
|
|
34
49
|
value,
|
|
@@ -38,7 +53,7 @@ const standardSchemaValidators = {
|
|
|
38
53
|
if (!result.issues) return;
|
|
39
54
|
if (validationSource === "field")
|
|
40
55
|
return result.issues;
|
|
41
|
-
return transformFormIssues(result.issues);
|
|
56
|
+
return transformFormIssues(result.issues, value);
|
|
42
57
|
}
|
|
43
58
|
};
|
|
44
59
|
const isStandardSchemaValidator = (validator) => !!validator && "~standard" in validator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardSchemaValidator.js","sources":["../../src/standardSchemaValidator.ts"],"sourcesContent":["import type { ValidationSource } from './types'\n\nexport type TStandardSchemaValidatorValue<\n TData,\n TSource extends ValidationSource = ValidationSource,\n> = {\n value: TData\n validationSource: TSource\n}\n\nexport type TStandardSchemaValidatorIssue<\n TSource extends ValidationSource = ValidationSource,\n> = TSource extends 'form'\n ? {\n form: Record<string, StandardSchemaV1Issue[]>\n fields: Record<string, StandardSchemaV1Issue[]>\n }\n : TSource extends 'field'\n ? StandardSchemaV1Issue[]\n : never\n\nfunction prefixSchemaToErrors(issues: readonly StandardSchemaV1Issue[]) {\n const schema = new Map<string, StandardSchemaV1Issue[]>()\n\n for (const issue of issues) {\n const
|
|
1
|
+
{"version":3,"file":"standardSchemaValidator.js","sources":["../../src/standardSchemaValidator.ts"],"sourcesContent":["import type { ValidationSource } from './types'\n\nexport type TStandardSchemaValidatorValue<\n TData,\n TSource extends ValidationSource = ValidationSource,\n> = {\n value: TData\n validationSource: TSource\n}\n\nexport type TStandardSchemaValidatorIssue<\n TSource extends ValidationSource = ValidationSource,\n> = TSource extends 'form'\n ? {\n form: Record<string, StandardSchemaV1Issue[]>\n fields: Record<string, StandardSchemaV1Issue[]>\n }\n : TSource extends 'field'\n ? StandardSchemaV1Issue[]\n : never\n\nfunction prefixSchemaToErrors(\n issues: readonly StandardSchemaV1Issue[],\n formValue: unknown,\n) {\n const schema = new Map<string, StandardSchemaV1Issue[]>()\n\n for (const issue of issues) {\n const issuePath = issue.path ?? []\n\n let currentFormValue = formValue\n let path = ''\n\n for (let i = 0; i < issuePath.length; i++) {\n const pathSegment = issuePath[i]\n if (pathSegment === undefined) continue\n\n const segment =\n typeof pathSegment === 'object' ? pathSegment.key : pathSegment\n\n // Standard Schema doesn't specify if paths should use numbers or stringified numbers for array access.\n // However, if we follow the path it provides and encounter an array, then we can assume it's intended for array access.\n const segmentAsNumber = Number(segment)\n if (Array.isArray(currentFormValue) && !Number.isNaN(segmentAsNumber)) {\n path += `[${segmentAsNumber}]`\n } else {\n path += (i > 0 ? '.' : '') + String(segment)\n }\n\n if (typeof currentFormValue === 'object' && currentFormValue !== null) {\n currentFormValue = currentFormValue[segment as never]\n } else {\n currentFormValue = undefined\n }\n }\n schema.set(path, (schema.get(path) ?? []).concat(issue))\n }\n\n return Object.fromEntries(schema)\n}\n\nconst transformFormIssues = <TSource extends ValidationSource>(\n issues: readonly StandardSchemaV1Issue[],\n formValue: unknown,\n): TStandardSchemaValidatorIssue<TSource> => {\n const schemaErrors = prefixSchemaToErrors(issues, formValue)\n return {\n form: schemaErrors,\n fields: schemaErrors,\n } as TStandardSchemaValidatorIssue<TSource>\n}\n\nexport const standardSchemaValidators = {\n validate<TSource extends ValidationSource = ValidationSource>(\n {\n value,\n validationSource,\n }: TStandardSchemaValidatorValue<unknown, TSource>,\n schema: StandardSchemaV1,\n ): TStandardSchemaValidatorIssue<TSource> | undefined {\n const result = schema['~standard'].validate(value)\n\n if (result instanceof Promise) {\n throw new Error('async function passed to sync validator')\n }\n\n if (!result.issues) return\n\n if (validationSource === 'field')\n return result.issues as TStandardSchemaValidatorIssue<TSource>\n return transformFormIssues<TSource>(result.issues, value)\n },\n async validateAsync<TSource extends ValidationSource>(\n {\n value,\n validationSource,\n }: TStandardSchemaValidatorValue<unknown, TSource>,\n schema: StandardSchemaV1,\n ): Promise<TStandardSchemaValidatorIssue<TSource> | undefined> {\n const result = await schema['~standard'].validate(value)\n\n if (!result.issues) return\n\n if (validationSource === 'field')\n return result.issues as TStandardSchemaValidatorIssue<TSource>\n return transformFormIssues<TSource>(result.issues, value)\n },\n}\n\nexport const isStandardSchemaValidator = (\n validator: unknown,\n): validator is StandardSchemaV1 =>\n !!validator && '~standard' in (validator as object)\n\n/**\n * The Standard Schema interface.\n */\nexport type StandardSchemaV1<Input = unknown, Output = Input> = {\n /**\n * The Standard Schema properties.\n */\n readonly '~standard': StandardSchemaV1Props<Input, Output>\n}\n\n/**\n * The Standard Schema properties interface.\n */\ninterface StandardSchemaV1Props<Input = unknown, Output = Input> {\n /**\n * The version number of the standard.\n */\n readonly version: 1\n /**\n * The vendor name of the schema library.\n */\n readonly vendor: string\n /**\n * Validates unknown input values.\n */\n readonly validate: (\n value: unknown,\n ) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>\n /**\n * Inferred types associated with the schema.\n */\n readonly types?: StandardSchemaV1Types<Input, Output> | undefined\n}\n/**\n * The result interface of the validate function.\n */\ntype StandardSchemaV1Result<Output> =\n | StandardSchemaV1SuccessResult<Output>\n | StandardSchemaV1FailureResult\n/**\n * The result interface if validation succeeds.\n */\ninterface StandardSchemaV1SuccessResult<Output> {\n /**\n * The typed output value.\n */\n readonly value: Output\n /**\n * The non-existent issues.\n */\n readonly issues?: undefined\n}\n/**\n * The result interface if validation fails.\n */\ninterface StandardSchemaV1FailureResult {\n /**\n * The issues of failed validation.\n */\n readonly issues: ReadonlyArray<StandardSchemaV1Issue>\n}\n/**\n * The issue interface of the failure output.\n */\nexport interface StandardSchemaV1Issue {\n /**\n * The error message of the issue.\n */\n readonly message: string\n /**\n * The path of the issue, if any.\n */\n readonly path?:\n | ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment>\n | undefined\n}\n/**\n * The path segment interface of the issue.\n */\ninterface StandardSchemaV1PathSegment {\n /**\n * The key representing a path segment.\n */\n readonly key: PropertyKey\n}\n/**\n * The Standard Schema types interface.\n */\ninterface StandardSchemaV1Types<Input = unknown, Output = Input> {\n /**\n * The input type of the schema.\n */\n readonly input: Input\n /**\n * The output type of the schema.\n */\n readonly output: Output\n}\n"],"names":[],"mappings":"AAqBA,SAAS,qBACP,QACA,WACA;AACA,QAAM,6BAAa,IAAA;AAEnB,aAAW,SAAS,QAAQ;AAC1B,UAAM,YAAY,MAAM,QAAQ,CAAA;AAEhC,QAAI,mBAAmB;AACvB,QAAI,OAAO;AAEX,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,YAAM,cAAc,UAAU,CAAC;AAC/B,UAAI,gBAAgB,OAAW;AAE/B,YAAM,UACJ,OAAO,gBAAgB,WAAW,YAAY,MAAM;AAItD,YAAM,kBAAkB,OAAO,OAAO;AACtC,UAAI,MAAM,QAAQ,gBAAgB,KAAK,CAAC,OAAO,MAAM,eAAe,GAAG;AACrE,gBAAQ,IAAI,eAAe;AAAA,MAC7B,OAAO;AACL,iBAAS,IAAI,IAAI,MAAM,MAAM,OAAO,OAAO;AAAA,MAC7C;AAEA,UAAI,OAAO,qBAAqB,YAAY,qBAAqB,MAAM;AACrE,2BAAmB,iBAAiB,OAAgB;AAAA,MACtD,OAAO;AACL,2BAAmB;AAAA,MACrB;AAAA,IACF;AACA,WAAO,IAAI,OAAO,OAAO,IAAI,IAAI,KAAK,CAAA,GAAI,OAAO,KAAK,CAAC;AAAA,EACzD;AAEA,SAAO,OAAO,YAAY,MAAM;AAClC;AAEA,MAAM,sBAAsB,CAC1B,QACA,cAC2C;AAC3C,QAAM,eAAe,qBAAqB,QAAQ,SAAS;AAC3D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,EAAA;AAEZ;AAEO,MAAM,2BAA2B;AAAA,EACtC,SACE;AAAA,IACE;AAAA,IACA;AAAA,EAAA,GAEF,QACoD;AACpD,UAAM,SAAS,OAAO,WAAW,EAAE,SAAS,KAAK;AAEjD,QAAI,kBAAkB,SAAS;AAC7B,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AAEA,QAAI,CAAC,OAAO,OAAQ;AAEpB,QAAI,qBAAqB;AACvB,aAAO,OAAO;AAChB,WAAO,oBAA6B,OAAO,QAAQ,KAAK;AAAA,EAC1D;AAAA,EACA,MAAM,cACJ;AAAA,IACE;AAAA,IACA;AAAA,EAAA,GAEF,QAC6D;AAC7D,UAAM,SAAS,MAAM,OAAO,WAAW,EAAE,SAAS,KAAK;AAEvD,QAAI,CAAC,OAAO,OAAQ;AAEpB,QAAI,qBAAqB;AACvB,aAAO,OAAO;AAChB,WAAO,oBAA6B,OAAO,QAAQ,KAAK;AAAA,EAC1D;AACF;AAEO,MAAM,4BAA4B,CACvC,cAEA,CAAC,CAAC,aAAa,eAAgB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/form-core",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.3",
|
|
4
4
|
"description": "Powerful, type-safe, framework agnostic forms.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"src"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tanstack/devtools-event-client": "^0.3.
|
|
40
|
+
"@tanstack/devtools-event-client": "^0.3.2",
|
|
41
41
|
"@tanstack/store": "^0.7.7",
|
|
42
42
|
"uuid": "^13.0.0"
|
|
43
43
|
},
|
|
@@ -19,21 +19,40 @@ export type TStandardSchemaValidatorIssue<
|
|
|
19
19
|
? StandardSchemaV1Issue[]
|
|
20
20
|
: never
|
|
21
21
|
|
|
22
|
-
function prefixSchemaToErrors(
|
|
22
|
+
function prefixSchemaToErrors(
|
|
23
|
+
issues: readonly StandardSchemaV1Issue[],
|
|
24
|
+
formValue: unknown,
|
|
25
|
+
) {
|
|
23
26
|
const schema = new Map<string, StandardSchemaV1Issue[]>()
|
|
24
27
|
|
|
25
28
|
for (const issue of issues) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
const issuePath = issue.path ?? []
|
|
30
|
+
|
|
31
|
+
let currentFormValue = formValue
|
|
32
|
+
let path = ''
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < issuePath.length; i++) {
|
|
35
|
+
const pathSegment = issuePath[i]
|
|
36
|
+
if (pathSegment === undefined) continue
|
|
37
|
+
|
|
38
|
+
const segment =
|
|
39
|
+
typeof pathSegment === 'object' ? pathSegment.key : pathSegment
|
|
40
|
+
|
|
41
|
+
// Standard Schema doesn't specify if paths should use numbers or stringified numbers for array access.
|
|
42
|
+
// However, if we follow the path it provides and encounter an array, then we can assume it's intended for array access.
|
|
43
|
+
const segmentAsNumber = Number(segment)
|
|
44
|
+
if (Array.isArray(currentFormValue) && !Number.isNaN(segmentAsNumber)) {
|
|
45
|
+
path += `[${segmentAsNumber}]`
|
|
46
|
+
} else {
|
|
47
|
+
path += (i > 0 ? '.' : '') + String(segment)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (typeof currentFormValue === 'object' && currentFormValue !== null) {
|
|
51
|
+
currentFormValue = currentFormValue[segment as never]
|
|
52
|
+
} else {
|
|
53
|
+
currentFormValue = undefined
|
|
54
|
+
}
|
|
55
|
+
}
|
|
37
56
|
schema.set(path, (schema.get(path) ?? []).concat(issue))
|
|
38
57
|
}
|
|
39
58
|
|
|
@@ -42,8 +61,9 @@ function prefixSchemaToErrors(issues: readonly StandardSchemaV1Issue[]) {
|
|
|
42
61
|
|
|
43
62
|
const transformFormIssues = <TSource extends ValidationSource>(
|
|
44
63
|
issues: readonly StandardSchemaV1Issue[],
|
|
64
|
+
formValue: unknown,
|
|
45
65
|
): TStandardSchemaValidatorIssue<TSource> => {
|
|
46
|
-
const schemaErrors = prefixSchemaToErrors(issues)
|
|
66
|
+
const schemaErrors = prefixSchemaToErrors(issues, formValue)
|
|
47
67
|
return {
|
|
48
68
|
form: schemaErrors,
|
|
49
69
|
fields: schemaErrors,
|
|
@@ -68,7 +88,7 @@ export const standardSchemaValidators = {
|
|
|
68
88
|
|
|
69
89
|
if (validationSource === 'field')
|
|
70
90
|
return result.issues as TStandardSchemaValidatorIssue<TSource>
|
|
71
|
-
return transformFormIssues<TSource>(result.issues)
|
|
91
|
+
return transformFormIssues<TSource>(result.issues, value)
|
|
72
92
|
},
|
|
73
93
|
async validateAsync<TSource extends ValidationSource>(
|
|
74
94
|
{
|
|
@@ -83,7 +103,7 @@ export const standardSchemaValidators = {
|
|
|
83
103
|
|
|
84
104
|
if (validationSource === 'field')
|
|
85
105
|
return result.issues as TStandardSchemaValidatorIssue<TSource>
|
|
86
|
-
return transformFormIssues<TSource>(result.issues)
|
|
106
|
+
return transformFormIssues<TSource>(result.issues, value)
|
|
87
107
|
},
|
|
88
108
|
}
|
|
89
109
|
|