sveltekit-superforms
Version:
Making SvelteKit forms a pleasure to use!
43 lines (42 loc) • 2.09 kB
TypeScript
import type { JSONSchema } from '../jsonSchema/index.js';
import { type SchemaShape } from '../jsonSchema/schemaShape.js';
import type { InputConstraints } from '../jsonSchema/constraints.js';
import type { Schema, ValidationResult, Infer as InferSchema, InferIn as InferInSchema, Registry } from './typeSchema.js';
export type { Schema, ValidationIssue, ValidationResult } from './typeSchema.js';
export type Infer<T extends Schema, K extends keyof Registry = keyof Registry> = NonNullable<InferSchema<T, K>>;
export type InferIn<T extends Schema, K extends keyof Registry = keyof Registry> = NonNullable<InferInSchema<T, K>>;
export type ValidationLibrary = 'arktype' | 'classvalidator' | 'custom' | 'joi' | 'superform' | 'typebox' | 'valibot' | 'yup' | 'zod' | 'zod4' | 'vine' | 'schemasafe' | 'superstruct' | 'effect';
export type AdapterOptions<T> = {
jsonSchema?: JSONSchema;
defaults?: T;
};
export type RequiredDefaultsOptions<T> = {
defaults: T;
jsonSchema?: JSONSchema;
};
export type ClientValidationAdapter<Out, In = Out> = {
superFormValidationLibrary: ValidationLibrary;
validate: (data: unknown) => Promise<ValidationResult<Out>>;
shape?: SchemaShape;
};
type BaseValidationAdapter<Out, In = Out> = ClientValidationAdapter<Out, In> & {
jsonSchema: JSONSchema;
defaults?: Out;
constraints?: InputConstraints<Out>;
};
export type ValidationAdapter<Out, In = Out> = BaseValidationAdapter<Out, In> & {
defaults: Out;
constraints: InputConstraints<Out>;
shape: SchemaShape;
id: string;
};
/**
* If the adapter options doesn't have a "defaults" or "jsonSchema" fields,
* this is a convenient function for creating a JSON schema.
* If no transformer exist for the adapter, use RequiredDefaultsOptions.
* @see {AdapterOptions}
* @see {RequiredDefaultsOptions}
* @__NO_SIDE_EFFECTS__
*/
export declare function createJsonSchema(options: object, transformer?: () => JSONSchema): {};
export declare function createAdapter<Out, In>(adapter: BaseValidationAdapter<Out, In>, jsonSchema?: JSONSchema): ValidationAdapter<Out, In>;