@tanstack/form-core
Advanced tools
Comparing version 0.40.1 to 0.40.2
import { Store } from '@tanstack/store'; | ||
import { StandardSchemaV1 } from './standardSchemaValidator.js'; | ||
import { FieldInfo, FieldsErrorMapFromValidator, FormApi } from './FormApi.js'; | ||
@@ -6,3 +7,2 @@ import { UpdateMetaOptions, ValidationCause, ValidationError, ValidationErrorMap, ValidationSource, Validator } from './types.js'; | ||
import { DeepKeys, DeepValue, NoInfer } from './util-types.js'; | ||
import { StandardSchemaV1 } from '@standard-schema/spec'; | ||
/** | ||
@@ -18,3 +18,3 @@ * @private | ||
*/ | ||
export type FieldValidateOrFn<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = TFieldValidator extends Validator<TData, infer TFN> ? TFN | FieldValidateFn<TParentData, TName, TFieldValidator, TFormValidator, TData> : TFormValidator extends Validator<TParentData, infer FFN> ? FFN | FieldValidateFn<TParentData, TName, TFieldValidator, TFormValidator, TData> : FieldValidateFn<TParentData, TName, TFieldValidator, TFormValidator, TData> | StandardSchemaV1; | ||
export type FieldValidateOrFn<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = (TFieldValidator extends Validator<TData, infer TFN> ? TFN : never) | (TFormValidator extends Validator<TParentData, infer FFN> ? FFN : never) | FieldValidateFn<TParentData, TName, TFieldValidator, TFormValidator, TData> | StandardSchemaV1<TData, unknown>; | ||
/** | ||
@@ -31,3 +31,3 @@ * @private | ||
*/ | ||
export type FieldAsyncValidateOrFn<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = TFieldValidator extends Validator<TData, infer TFN> ? TFN | FieldValidateAsyncFn<TParentData, TName, TFieldValidator, TFormValidator, TData> : TFormValidator extends Validator<TParentData, infer FFN> ? FFN | FieldValidateAsyncFn<TParentData, TName, TFieldValidator, TFormValidator, TData> : FieldValidateAsyncFn<TParentData, TName, TFieldValidator, TFormValidator, TData> | StandardSchemaV1<TData, unknown>; | ||
export type FieldAsyncValidateOrFn<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = (TFieldValidator extends Validator<TData, infer TFN> ? TFN : never) | (TFormValidator extends Validator<TParentData, infer FFN> ? FFN : never) | FieldValidateAsyncFn<TParentData, TName, TFieldValidator, TFormValidator, TData> | StandardSchemaV1<TData, unknown>; | ||
/** | ||
@@ -34,0 +34,0 @@ * @private |
import { Store } from '@tanstack/store'; | ||
import { StandardSchemaV1 } from './standardSchemaValidator.js'; | ||
import { FieldApi, FieldMeta } from './FieldApi.js'; | ||
@@ -6,3 +7,2 @@ import { FormValidationError, FormValidationErrorMap, UpdateMetaOptions, ValidationCause, ValidationError, ValidationErrorMap, ValidationErrorMapKeys, ValidationSource, Validator } from './types.js'; | ||
import { Updater } from './utils.js'; | ||
import { StandardSchemaV1 } from '@standard-schema/spec'; | ||
export type FieldsErrorMapFromValidator<TFormData> = Partial<Record<DeepKeys<TFormData>, ValidationErrorMap>>; | ||
@@ -9,0 +9,0 @@ export type FormValidateFn<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = (props: { |
import { Validator, ValidatorAdapterParams } from './types.js'; | ||
import { StandardSchemaV1 } from '@standard-schema/spec'; | ||
type Params = ValidatorAdapterParams<StandardSchemaV1.Issue>; | ||
export declare const standardSchemaValidator: (params?: Params) => Validator<unknown, StandardSchemaV1>; | ||
type Params = ValidatorAdapterParams<StandardSchemaV1Issue>; | ||
export declare const standardSchemaValidator: (params?: Params) => Validator<unknown, StandardSchemaV1<any>>; | ||
export declare const isStandardSchemaValidator: (validator: unknown) => validator is StandardSchemaV1; | ||
/** | ||
* The Standard Schema interface. | ||
*/ | ||
export type StandardSchemaV1<Input = unknown, Output = Input> = { | ||
/** | ||
* The Standard Schema properties. | ||
*/ | ||
readonly '~standard': StandardSchemaV1Props<Input, Output>; | ||
}; | ||
/** | ||
* The Standard Schema properties interface. | ||
*/ | ||
interface StandardSchemaV1Props<Input = unknown, Output = Input> { | ||
/** | ||
* The version number of the standard. | ||
*/ | ||
readonly version: 1; | ||
/** | ||
* The vendor name of the schema library. | ||
*/ | ||
readonly vendor: string; | ||
/** | ||
* Validates unknown input values. | ||
*/ | ||
readonly validate: (value: unknown) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>; | ||
/** | ||
* Inferred types associated with the schema. | ||
*/ | ||
readonly types?: StandardSchemaV1Types<Input, Output> | undefined; | ||
} | ||
/** | ||
* The result interface of the validate function. | ||
*/ | ||
type StandardSchemaV1Result<Output> = StandardSchemaV1SuccessResult<Output> | StandardSchemaV1FailureResult; | ||
/** | ||
* The result interface if validation succeeds. | ||
*/ | ||
interface StandardSchemaV1SuccessResult<Output> { | ||
/** | ||
* The typed output value. | ||
*/ | ||
readonly value: Output; | ||
/** | ||
* The non-existent issues. | ||
*/ | ||
readonly issues?: undefined; | ||
} | ||
/** | ||
* The result interface if validation fails. | ||
*/ | ||
interface StandardSchemaV1FailureResult { | ||
/** | ||
* The issues of failed validation. | ||
*/ | ||
readonly issues: ReadonlyArray<StandardSchemaV1Issue>; | ||
} | ||
/** | ||
* The issue interface of the failure output. | ||
*/ | ||
interface StandardSchemaV1Issue { | ||
/** | ||
* The error message of the issue. | ||
*/ | ||
readonly message: string; | ||
/** | ||
* The path of the issue, if any. | ||
*/ | ||
readonly path?: ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> | undefined; | ||
} | ||
/** | ||
* The path segment interface of the issue. | ||
*/ | ||
interface StandardSchemaV1PathSegment { | ||
/** | ||
* The key representing a path segment. | ||
*/ | ||
readonly key: PropertyKey; | ||
} | ||
/** | ||
* The Standard Schema types interface. | ||
*/ | ||
interface StandardSchemaV1Types<Input = unknown, Output = Input> { | ||
/** | ||
* The input type of the schema. | ||
*/ | ||
readonly input: Input; | ||
/** | ||
* The output type of the schema. | ||
*/ | ||
readonly output: Output; | ||
} | ||
export {}; |
{ | ||
"name": "@tanstack/form-core", | ||
"version": "0.40.1", | ||
"version": "0.40.2", | ||
"description": "Powerful, type-safe, framework agnostic forms.", | ||
@@ -43,3 +43,2 @@ "author": "tannerlinsley", | ||
"devDependencies": { | ||
"@standard-schema/spec": "1.0.0-beta.4", | ||
"arktype": "2.0.0-rc.23", | ||
@@ -46,0 +45,0 @@ "valibot": "^1.0.0-beta.9", |
@@ -7,2 +7,3 @@ import { Store } from '@tanstack/store' | ||
} from './standardSchemaValidator' | ||
import type { StandardSchemaV1 } from './standardSchemaValidator' | ||
import type { FieldInfo, FieldsErrorMapFromValidator, FormApi } from './FormApi' | ||
@@ -19,3 +20,2 @@ import type { | ||
import type { DeepKeys, DeepValue, NoInfer } from './util-types' | ||
import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
@@ -54,31 +54,6 @@ /** | ||
> = | ||
TFieldValidator extends Validator<TData, infer TFN> | ||
? | ||
| TFN | ||
| FieldValidateFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
: TFormValidator extends Validator<TParentData, infer FFN> | ||
? | ||
| FFN | ||
| FieldValidateFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
: | ||
| FieldValidateFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
| StandardSchemaV1 | ||
| (TFieldValidator extends Validator<TData, infer TFN> ? TFN : never) | ||
| (TFormValidator extends Validator<TParentData, infer FFN> ? FFN : never) | ||
| FieldValidateFn<TParentData, TName, TFieldValidator, TFormValidator, TData> | ||
| StandardSchemaV1<TData, unknown> | ||
@@ -118,31 +93,12 @@ /** | ||
> = | ||
TFieldValidator extends Validator<TData, infer TFN> | ||
? | ||
| TFN | ||
| FieldValidateAsyncFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
: TFormValidator extends Validator<TParentData, infer FFN> | ||
? | ||
| FFN | ||
| FieldValidateAsyncFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
: | ||
| FieldValidateAsyncFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
| StandardSchemaV1<TData, unknown> | ||
| (TFieldValidator extends Validator<TData, infer TFN> ? TFN : never) | ||
| (TFormValidator extends Validator<TParentData, infer FFN> ? FFN : never) | ||
| FieldValidateAsyncFn< | ||
TParentData, | ||
TName, | ||
TFieldValidator, | ||
TFormValidator, | ||
TData | ||
> | ||
| StandardSchemaV1<TData, unknown> | ||
@@ -149,0 +105,0 @@ /** |
@@ -15,2 +15,3 @@ import { Store } from '@tanstack/store' | ||
} from './standardSchemaValidator' | ||
import type { StandardSchemaV1 } from './standardSchemaValidator' | ||
import type { FieldApi, FieldMeta } from './FieldApi' | ||
@@ -30,3 +31,2 @@ import type { | ||
import type { Updater } from './utils' | ||
import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
@@ -33,0 +33,0 @@ export type FieldsErrorMapFromValidator<TFormData> = Partial< |
@@ -6,12 +6,11 @@ import type { | ||
} from './types' | ||
import type { StandardSchemaV1 } from '@standard-schema/spec' | ||
type Params = ValidatorAdapterParams<StandardSchemaV1.Issue> | ||
type Params = ValidatorAdapterParams<StandardSchemaV1Issue> | ||
type TransformFn = NonNullable<Params['transformErrors']> | ||
function prefixSchemaToErrors( | ||
issues: readonly StandardSchemaV1.Issue[], | ||
issues: readonly StandardSchemaV1Issue[], | ||
transformErrors: TransformFn, | ||
) { | ||
const schema = new Map<string, StandardSchemaV1.Issue[]>() | ||
const schema = new Map<string, StandardSchemaV1Issue[]>() | ||
@@ -43,4 +42,4 @@ for (const issue of issues) { | ||
function defaultFormTransformer(transformErrors: TransformFn) { | ||
return (issues: readonly StandardSchemaV1.Issue[]) => ({ | ||
form: transformErrors(issues as StandardSchemaV1.Issue[]), | ||
return (issues: readonly StandardSchemaV1Issue[]) => ({ | ||
form: transformErrors(issues as StandardSchemaV1Issue[]), | ||
fields: prefixSchemaToErrors(issues, transformErrors), | ||
@@ -51,7 +50,7 @@ }) | ||
export const standardSchemaValidator = | ||
(params: Params = {}): Validator<unknown, StandardSchemaV1> => | ||
(params: Params = {}): Validator<unknown, StandardSchemaV1<any>> => | ||
() => { | ||
const transformFieldErrors = | ||
params.transformErrors ?? | ||
((issues: StandardSchemaV1.Issue[]) => | ||
((issues: StandardSchemaV1Issue[]) => | ||
issues.map((issue) => issue.message).join(', ')) | ||
@@ -76,3 +75,3 @@ | ||
return transformer(result.issues as StandardSchemaV1.Issue[]) | ||
return transformer(result.issues as StandardSchemaV1Issue[]) | ||
}, | ||
@@ -86,3 +85,3 @@ async validateAsync({ value, validationSource }, fn) { | ||
return transformer(result.issues as StandardSchemaV1.Issue[]) | ||
return transformer(result.issues as StandardSchemaV1Issue[]) | ||
}, | ||
@@ -96,1 +95,100 @@ } | ||
!!validator && '~standard' in (validator as object) | ||
/** | ||
* The Standard Schema interface. | ||
*/ | ||
export type StandardSchemaV1<Input = unknown, Output = Input> = { | ||
/** | ||
* The Standard Schema properties. | ||
*/ | ||
readonly '~standard': StandardSchemaV1Props<Input, Output> | ||
} | ||
/** | ||
* The Standard Schema properties interface. | ||
*/ | ||
interface StandardSchemaV1Props<Input = unknown, Output = Input> { | ||
/** | ||
* The version number of the standard. | ||
*/ | ||
readonly version: 1 | ||
/** | ||
* The vendor name of the schema library. | ||
*/ | ||
readonly vendor: string | ||
/** | ||
* Validates unknown input values. | ||
*/ | ||
readonly validate: ( | ||
value: unknown, | ||
) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>> | ||
/** | ||
* Inferred types associated with the schema. | ||
*/ | ||
readonly types?: StandardSchemaV1Types<Input, Output> | undefined | ||
} | ||
/** | ||
* The result interface of the validate function. | ||
*/ | ||
type StandardSchemaV1Result<Output> = | ||
| StandardSchemaV1SuccessResult<Output> | ||
| StandardSchemaV1FailureResult | ||
/** | ||
* The result interface if validation succeeds. | ||
*/ | ||
interface StandardSchemaV1SuccessResult<Output> { | ||
/** | ||
* The typed output value. | ||
*/ | ||
readonly value: Output | ||
/** | ||
* The non-existent issues. | ||
*/ | ||
readonly issues?: undefined | ||
} | ||
/** | ||
* The result interface if validation fails. | ||
*/ | ||
interface StandardSchemaV1FailureResult { | ||
/** | ||
* The issues of failed validation. | ||
*/ | ||
readonly issues: ReadonlyArray<StandardSchemaV1Issue> | ||
} | ||
/** | ||
* The issue interface of the failure output. | ||
*/ | ||
interface StandardSchemaV1Issue { | ||
/** | ||
* The error message of the issue. | ||
*/ | ||
readonly message: string | ||
/** | ||
* The path of the issue, if any. | ||
*/ | ||
readonly path?: | ||
| ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> | ||
| undefined | ||
} | ||
/** | ||
* The path segment interface of the issue. | ||
*/ | ||
interface StandardSchemaV1PathSegment { | ||
/** | ||
* The key representing a path segment. | ||
*/ | ||
readonly key: PropertyKey | ||
} | ||
/** | ||
* The Standard Schema types interface. | ||
*/ | ||
interface StandardSchemaV1Types<Input = unknown, Output = Input> { | ||
/** | ||
* The input type of the schema. | ||
*/ | ||
readonly input: Input | ||
/** | ||
* The output type of the schema. | ||
*/ | ||
readonly output: Output | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
516319
3
6791