@tanstack/form-core 0.40.0 → 0.40.1
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/cjs/FieldApi.cjs.map +1 -1
- package/dist/cjs/FieldApi.d.cts +3 -2
- package/dist/cjs/FormApi.cjs.map +1 -1
- package/dist/cjs/FormApi.d.cts +3 -3
- package/dist/cjs/standardSchemaValidator.cjs.map +1 -1
- package/dist/cjs/standardSchemaValidator.d.cts +4 -4
- package/dist/esm/FieldApi.d.ts +3 -2
- package/dist/esm/FieldApi.js.map +1 -1
- package/dist/esm/FormApi.d.ts +3 -3
- package/dist/esm/FormApi.js.map +1 -1
- package/dist/esm/standardSchemaValidator.d.ts +4 -4
- package/dist/esm/standardSchemaValidator.js.map +1 -1
- package/package.json +2 -2
- package/src/FieldApi.ts +19 -14
- package/src/FormApi.ts +3 -3
- package/src/standardSchemaValidator.ts +11 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/form-core",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.1",
|
|
4
4
|
"description": "Powerful, type-safe, framework agnostic forms.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@tanstack/store": "^0.6.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@standard-schema/spec": "1.0.0-beta.
|
|
43
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
44
44
|
"arktype": "2.0.0-rc.23",
|
|
45
45
|
"valibot": "^1.0.0-beta.9",
|
|
46
46
|
"zod": "^3.24.0"
|
package/src/FieldApi.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
} from './types'
|
|
16
16
|
import type { AsyncValidator, SyncValidator, Updater } from './utils'
|
|
17
17
|
import type { DeepKeys, DeepValue, NoInfer } from './util-types'
|
|
18
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @private
|
|
@@ -68,13 +69,15 @@ export type FieldValidateOrFn<
|
|
|
68
69
|
TFormValidator,
|
|
69
70
|
TData
|
|
70
71
|
>
|
|
71
|
-
:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
:
|
|
73
|
+
| FieldValidateFn<
|
|
74
|
+
TParentData,
|
|
75
|
+
TName,
|
|
76
|
+
TFieldValidator,
|
|
77
|
+
TFormValidator,
|
|
78
|
+
TData
|
|
79
|
+
>
|
|
80
|
+
| StandardSchemaV1
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
83
|
* @private
|
|
@@ -129,13 +132,15 @@ export type FieldAsyncValidateOrFn<
|
|
|
129
132
|
TFormValidator,
|
|
130
133
|
TData
|
|
131
134
|
>
|
|
132
|
-
:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
:
|
|
136
|
+
| FieldValidateAsyncFn<
|
|
137
|
+
TParentData,
|
|
138
|
+
TName,
|
|
139
|
+
TFieldValidator,
|
|
140
|
+
TFormValidator,
|
|
141
|
+
TData
|
|
142
|
+
>
|
|
143
|
+
| StandardSchemaV1<TData, unknown>
|
|
139
144
|
|
|
140
145
|
/**
|
|
141
146
|
* @private
|
package/src/FormApi.ts
CHANGED
|
@@ -26,7 +26,7 @@ import type {
|
|
|
26
26
|
} from './types'
|
|
27
27
|
import type { DeepKeys, DeepValue } from './util-types'
|
|
28
28
|
import type { Updater } from './utils'
|
|
29
|
-
import type {
|
|
29
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
30
30
|
|
|
31
31
|
export type FieldsErrorMapFromValidator<TFormData> = Partial<
|
|
32
32
|
Record<DeepKeys<TFormData>, ValidationErrorMap>
|
|
@@ -51,7 +51,7 @@ export type FormValidateOrFn<
|
|
|
51
51
|
? TFN | FormValidateFn<TFormData, TFormValidator>
|
|
52
52
|
:
|
|
53
53
|
| FormValidateFn<TFormData, TFormValidator>
|
|
54
|
-
|
|
|
54
|
+
| StandardSchemaV1<TFormData, unknown>
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @private
|
|
@@ -91,7 +91,7 @@ export type FormAsyncValidateOrFn<
|
|
|
91
91
|
? FFN | FormValidateAsyncFn<TFormData, TFormValidator>
|
|
92
92
|
:
|
|
93
93
|
| FormValidateAsyncFn<TFormData, TFormValidator>
|
|
94
|
-
|
|
|
94
|
+
| StandardSchemaV1<TFormData, unknown>
|
|
95
95
|
|
|
96
96
|
export interface FormValidators<
|
|
97
97
|
TFormData,
|
|
@@ -3,16 +3,16 @@ import type {
|
|
|
3
3
|
Validator,
|
|
4
4
|
ValidatorAdapterParams,
|
|
5
5
|
} from './types'
|
|
6
|
-
import type {
|
|
6
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
7
7
|
|
|
8
|
-
type Params = ValidatorAdapterParams<
|
|
8
|
+
type Params = ValidatorAdapterParams<StandardSchemaV1.Issue>
|
|
9
9
|
type TransformFn = NonNullable<Params['transformErrors']>
|
|
10
10
|
|
|
11
11
|
function prefixSchemaToErrors(
|
|
12
|
-
issues: readonly
|
|
12
|
+
issues: readonly StandardSchemaV1.Issue[],
|
|
13
13
|
transformErrors: TransformFn,
|
|
14
14
|
) {
|
|
15
|
-
const schema = new Map<string,
|
|
15
|
+
const schema = new Map<string, StandardSchemaV1.Issue[]>()
|
|
16
16
|
|
|
17
17
|
for (const issue of issues) {
|
|
18
18
|
const path = [...(issue.path ?? [])]
|
|
@@ -39,18 +39,18 @@ function prefixSchemaToErrors(
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function defaultFormTransformer(transformErrors: TransformFn) {
|
|
42
|
-
return (issues: readonly
|
|
43
|
-
form: transformErrors(issues as
|
|
42
|
+
return (issues: readonly StandardSchemaV1.Issue[]) => ({
|
|
43
|
+
form: transformErrors(issues as StandardSchemaV1.Issue[]),
|
|
44
44
|
fields: prefixSchemaToErrors(issues, transformErrors),
|
|
45
45
|
})
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export const standardSchemaValidator =
|
|
49
|
-
(params: Params = {}): Validator<unknown,
|
|
49
|
+
(params: Params = {}): Validator<unknown, StandardSchemaV1> =>
|
|
50
50
|
() => {
|
|
51
51
|
const transformFieldErrors =
|
|
52
52
|
params.transformErrors ??
|
|
53
|
-
((issues:
|
|
53
|
+
((issues: StandardSchemaV1.Issue[]) =>
|
|
54
54
|
issues.map((issue) => issue.message).join(', '))
|
|
55
55
|
|
|
56
56
|
const getTransformStrategy = (validationSource: 'form' | 'field') =>
|
|
@@ -70,7 +70,7 @@ export const standardSchemaValidator =
|
|
|
70
70
|
|
|
71
71
|
const transformer = getTransformStrategy(validationSource)
|
|
72
72
|
|
|
73
|
-
return transformer(result.issues as
|
|
73
|
+
return transformer(result.issues as StandardSchemaV1.Issue[])
|
|
74
74
|
},
|
|
75
75
|
async validateAsync({ value, validationSource }, fn) {
|
|
76
76
|
const result = await fn['~standard'].validate(value)
|
|
@@ -79,12 +79,12 @@ export const standardSchemaValidator =
|
|
|
79
79
|
|
|
80
80
|
const transformer = getTransformStrategy(validationSource)
|
|
81
81
|
|
|
82
|
-
return transformer(result.issues as
|
|
82
|
+
return transformer(result.issues as StandardSchemaV1.Issue[])
|
|
83
83
|
},
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export const isStandardSchemaValidator = (
|
|
88
88
|
validator: unknown,
|
|
89
|
-
): validator is
|
|
89
|
+
): validator is StandardSchemaV1 =>
|
|
90
90
|
!!validator && '~standard' in (validator as object)
|