@sjsf-lab/ata-validator
Advanced tools
| import type { FieldValueValidator, FormValueValidator, Validator } from "@sjsf/form"; | ||
| import type { ValidationResult as AtaValidationResult } from "ata-validator"; | ||
| import type { ValueCloner } from "../validator.svelte.js"; | ||
| import { type ErrorsTransformerOptions } from "../errors.js"; | ||
| export type CompiledValidator = (data: unknown) => AtaValidationResult | { | ||
| valid: true; | ||
| errors: ReadonlyArray<never>; | ||
| }; | ||
| export type ValidateFunctions = { | ||
| [key: string]: CompiledValidator; | ||
| }; | ||
| export interface ValidatorOptions extends ValueCloner { | ||
| validateFunctions: ValidateFunctions; | ||
| augmentSuffix?: string; | ||
| } | ||
| export declare function createValidator(options: ValidatorOptions): Validator; | ||
| export interface FormValueValidatorOptions extends ValidatorOptions, ErrorsTransformerOptions, ValueCloner { | ||
| } | ||
| export declare function createFormValueValidator<T>(options: FormValueValidatorOptions): FormValueValidator<T>; | ||
| export interface FieldValueValidatorOptions extends ValidatorOptions, ValueCloner { | ||
| } | ||
| export declare function createFieldValueValidator(options: FieldValueValidatorOptions): FieldValueValidator; | ||
| export interface FormValidatorOptions extends ValidatorOptions, FormValueValidatorOptions, FieldValueValidatorOptions { | ||
| } | ||
| export declare function createFormValidatorFactory<T>({ cloneValue, ...vOptions }: Omit<ValidatorOptions, keyof ValueCloner> & Partial<ValueCloner>): (options: Omit<FormValidatorOptions, keyof ValidatorOptions>) => Validator & FormValueValidator<T> & FieldValueValidator; |
| import { DEFAULT_AUGMENT_SUFFIX } from "@sjsf/form/validators/precompile"; | ||
| import { createFormErrorsTransformer, transformFieldErrors, } from "../errors.js"; | ||
| function getValidator({ validateFunctions, augmentSuffix = DEFAULT_AUGMENT_SUFFIX, }, { $id: id, allOf }) { | ||
| if (id === undefined) { | ||
| const firstAllOfItem = allOf?.[0]; | ||
| if (typeof firstAllOfItem === "object" && | ||
| firstAllOfItem.$id !== undefined) { | ||
| id = firstAllOfItem.$id + augmentSuffix; | ||
| } | ||
| else { | ||
| throw new Error("Schema id not found"); | ||
| } | ||
| } | ||
| const validator = validateFunctions[id]; | ||
| if (validator === undefined) { | ||
| throw new Error(`Validate function with id "${id}" not found`); | ||
| } | ||
| return validator; | ||
| } | ||
| export function createValidator(options) { | ||
| return { | ||
| isValid(schema, _, formValue) { | ||
| if (typeof schema === "boolean") { | ||
| return schema; | ||
| } | ||
| const validator = getValidator(options, schema); | ||
| return validator(options.cloneValue(formValue)).valid; | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValueValidator(options) { | ||
| const transformErrors = createFormErrorsTransformer(options); | ||
| return { | ||
| validateFormValue(rootSchema, formValue) { | ||
| const validator = getValidator(options, rootSchema); | ||
| const { valid, errors } = validator(options.cloneValue(formValue)); | ||
| if (valid) { | ||
| return { | ||
| value: formValue, | ||
| }; | ||
| } | ||
| return transformErrors(errors, formValue); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFieldValueValidator(options) { | ||
| return { | ||
| validateFieldValue(field, fieldValue) { | ||
| const validator = getValidator(options, field.schema); | ||
| const { valid, errors } = validator(options.cloneValue(fieldValue)); | ||
| if (valid) { | ||
| return []; | ||
| } | ||
| return transformFieldErrors(field, errors); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValidatorFactory({ cloneValue = (value) => $state.snapshot(value), ...vOptions }) { | ||
| return (options) => { | ||
| const full = { | ||
| cloneValue, | ||
| ...vOptions, | ||
| ...options, | ||
| }; | ||
| return Object.assign(createValidator(full), createFormValueValidator(full), createFieldValueValidator(full)); | ||
| }; | ||
| } |
| import type { Config, FieldValueValidator, FormValue, FormValueValidator, Schema, Validator } from "@sjsf/form"; | ||
| import { type MapLike } from "@sjsf/form/lib/memoize"; | ||
| import { Validator as AtaValidator } from "ata-validator"; | ||
| import { type ErrorsTransformerOptions } from "./errors.js"; | ||
| export interface ValueCloner { | ||
| cloneValue: (value: FormValue) => FormValue; | ||
| } | ||
| export type AtaValidatorFactory = (schema: Schema) => AtaValidator; | ||
| export declare const COLOR_FORMAT_REGEX: RegExp; | ||
| export declare const DATA_URL_FORMAT_REGEX: RegExp; | ||
| export declare const DEFAULT_VALIDATOR_OPTIONS: { | ||
| verbose: true; | ||
| formats: { | ||
| color: (str: string) => boolean; | ||
| "data-url": (str: string) => boolean; | ||
| }; | ||
| }; | ||
| export declare const defaultValidatorFactory: AtaValidatorFactory; | ||
| export type ValidatorsCache = MapLike<Schema, AtaValidator>; | ||
| export declare function createSchemaValidatorFactory(factory: AtaValidatorFactory, validatorsCache?: ValidatorsCache): (schema: Schema, rootSchema: Schema) => AtaValidator; | ||
| export declare function createFieldSchemaValidatorFactory(factory: AtaValidatorFactory, cache?: WeakMap<Schema, AtaValidator>): (config: Config) => AtaValidator; | ||
| export interface ValidatorOptions extends ValueCloner { | ||
| createSchemaValidator: (schema: Schema, rootSchema: Schema) => AtaValidator; | ||
| } | ||
| export declare function createValidator({ createSchemaValidator, cloneValue, }: ValidatorOptions): Validator; | ||
| export interface FormValueValidatorOptions extends ValidatorOptions, ErrorsTransformerOptions, ValueCloner { | ||
| } | ||
| export declare function createFormValueValidator<T>(options: FormValueValidatorOptions): FormValueValidator<T>; | ||
| export interface FieldValueValidatorOptions extends ValueCloner { | ||
| compileFieldSchema: (config: Config) => AtaValidator; | ||
| } | ||
| export declare function createFieldValueValidator({ compileFieldSchema, cloneValue, }: FieldValueValidatorOptions): FieldValueValidator; | ||
| export interface FormValidatorOptions extends ValidatorOptions, FormValueValidatorOptions, FieldValueValidatorOptions { | ||
| } | ||
| export declare function createFormValidator<T>({ factory, schemaValidatorsCache, fieldsValidatorsCache, createSchemaValidator, compileFieldSchema, cloneValue, ...rest }?: Partial<FormValidatorOptions> & { | ||
| factory?: AtaValidatorFactory; | ||
| schemaValidatorsCache?: ValidatorsCache; | ||
| fieldsValidatorsCache?: WeakMap<Schema, AtaValidator>; | ||
| }): Validator & FormValueValidator<T> & FieldValueValidator; |
| import { DATA_URL_FORMAT, ID_KEY, prefixSchemaRefs, ROOT_SCHEMA_PREFIX, } from "@sjsf/form/core"; | ||
| import { memoize, weakMemoize } from "@sjsf/form/lib/memoize"; | ||
| import { Validator as AtaValidator, } from "ata-validator"; | ||
| import { createFormErrorsTransformer, transformFieldErrors, } from "./errors.js"; | ||
| export const COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/; | ||
| export const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/; | ||
| export const DEFAULT_VALIDATOR_OPTIONS = { | ||
| verbose: true, | ||
| formats: { | ||
| color: (str) => COLOR_FORMAT_REGEX.test(str), | ||
| [DATA_URL_FORMAT]: (str) => DATA_URL_FORMAT_REGEX.test(str), | ||
| }, | ||
| }; | ||
| export const defaultValidatorFactory = (schema) => new AtaValidator(Object.assign({ $schema: "http://json-schema.org/draft-07/schema#" }, schema), DEFAULT_VALIDATOR_OPTIONS); | ||
| export function createSchemaValidatorFactory(factory, validatorsCache = new WeakMap()) { | ||
| let rootSchemaId = ""; | ||
| let usePrefixSchemaRefs = false; | ||
| let lastRootSchema = new WeakRef({}); | ||
| const makeValidator = memoize(validatorsCache, (schema) => { | ||
| return factory(usePrefixSchemaRefs ? prefixSchemaRefs(schema, rootSchemaId) : schema); | ||
| }); | ||
| return (schema, rootSchema) => { | ||
| rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX; | ||
| usePrefixSchemaRefs = schema !== rootSchema; | ||
| const validator = makeValidator(schema); | ||
| if (usePrefixSchemaRefs && lastRootSchema.deref() !== rootSchema) { | ||
| lastRootSchema = new WeakRef(rootSchema); | ||
| validator.addSchema(Object.assign({ [ID_KEY]: rootSchemaId }, rootSchema)); | ||
| } | ||
| return validator; | ||
| }; | ||
| } | ||
| export function createFieldSchemaValidatorFactory(factory, cache = new WeakMap()) { | ||
| const makeValidator = weakMemoize(cache, factory); | ||
| return (config) => makeValidator(config.schema); | ||
| } | ||
| export function createValidator({ createSchemaValidator, cloneValue, }) { | ||
| return { | ||
| isValid(schemaDef, rootSchema, formValue) { | ||
| if (typeof schemaDef === "boolean") { | ||
| return schemaDef; | ||
| } | ||
| const validator = createSchemaValidator(schemaDef, rootSchema); | ||
| return validator.isValidObject(cloneValue(formValue)); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValueValidator(options) { | ||
| const transformErrors = createFormErrorsTransformer(options); | ||
| return { | ||
| validateFormValue(rootSchema, formValue) { | ||
| const validator = options.createSchemaValidator(rootSchema, rootSchema); | ||
| const { valid, errors } = validator.validate(options.cloneValue(formValue)); | ||
| if (valid) { | ||
| return { | ||
| value: formValue, | ||
| }; | ||
| } | ||
| return transformErrors(errors, formValue); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFieldValueValidator({ compileFieldSchema, cloneValue, }) { | ||
| return { | ||
| validateFieldValue(field, fieldValue) { | ||
| const validator = compileFieldSchema(field); | ||
| const { valid, errors } = validator.validate(cloneValue(fieldValue)); | ||
| if (valid) { | ||
| return []; | ||
| } | ||
| return transformFieldErrors(field, errors); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValidator({ factory = defaultValidatorFactory, schemaValidatorsCache, fieldsValidatorsCache, createSchemaValidator = createSchemaValidatorFactory(factory, schemaValidatorsCache), compileFieldSchema = createFieldSchemaValidatorFactory(factory, fieldsValidatorsCache), cloneValue = (value) => $state.snapshot(value), ...rest } = {}) { | ||
| const options = { | ||
| ...rest, | ||
| cloneValue, | ||
| createSchemaValidator, | ||
| compileFieldSchema, | ||
| }; | ||
| return Object.assign(createValidator(options), createFormValueValidator(options), createFieldValueValidator(options)); | ||
| } |
+1
-1
@@ -1,1 +0,1 @@ | ||
| export * from "./validator.js"; | ||
| export * from "./validator.svelte.js"; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| export * from "./validator.js"; | ||
| export * from "./validator.svelte.js"; |
@@ -1,1 +0,1 @@ | ||
| export * from "./validator.js"; | ||
| export * from "./validator.svelte.js"; |
@@ -1,1 +0,1 @@ | ||
| export * from "./validator.js"; | ||
| export * from "./validator.svelte.js"; |
+1
-1
| { | ||
| "name": "@sjsf-lab/ata-validator", | ||
| "version": "3.1.0", | ||
| "version": "3.1.1", | ||
| "description": "The ata based validator for svelte-jsonschema-form", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
| import type { FieldValueValidator, FormValueValidator, Validator } from "@sjsf/form"; | ||
| import type { ValidationResult as AtaValidationResult } from "ata-validator"; | ||
| import type { ValueCloner } from "../validator.js"; | ||
| import { type ErrorsTransformerOptions } from "../errors.js"; | ||
| export type CompiledValidator = (data: unknown) => AtaValidationResult | { | ||
| valid: true; | ||
| errors: ReadonlyArray<never>; | ||
| }; | ||
| export type ValidateFunctions = { | ||
| [key: string]: CompiledValidator; | ||
| }; | ||
| export interface ValidatorOptions extends ValueCloner { | ||
| validateFunctions: ValidateFunctions; | ||
| augmentSuffix?: string; | ||
| } | ||
| export declare function createValidator(options: ValidatorOptions): Validator; | ||
| export interface FormValueValidatorOptions extends ValidatorOptions, ErrorsTransformerOptions, ValueCloner { | ||
| } | ||
| export declare function createFormValueValidator<T>(options: FormValueValidatorOptions): FormValueValidator<T>; | ||
| export interface FieldValueValidatorOptions extends ValidatorOptions, ValueCloner { | ||
| } | ||
| export declare function createFieldValueValidator(options: FieldValueValidatorOptions): FieldValueValidator; | ||
| export interface FormValidatorOptions extends ValidatorOptions, FormValueValidatorOptions, FieldValueValidatorOptions { | ||
| } | ||
| export declare function createFormValidatorFactory<T>({ cloneValue, ...vOptions }: Omit<ValidatorOptions, keyof ValueCloner> & Partial<ValueCloner>): (options: Omit<FormValidatorOptions, keyof ValidatorOptions>) => Validator & FormValueValidator<T> & FieldValueValidator; |
| import { DEFAULT_AUGMENT_SUFFIX } from "@sjsf/form/validators/precompile"; | ||
| import { createFormErrorsTransformer, transformFieldErrors, } from "../errors.js"; | ||
| function getValidator({ validateFunctions, augmentSuffix = DEFAULT_AUGMENT_SUFFIX, }, { $id: id, allOf }) { | ||
| if (id === undefined) { | ||
| const firstAllOfItem = allOf?.[0]; | ||
| if (typeof firstAllOfItem === "object" && | ||
| firstAllOfItem.$id !== undefined) { | ||
| id = firstAllOfItem.$id + augmentSuffix; | ||
| } | ||
| else { | ||
| throw new Error("Schema id not found"); | ||
| } | ||
| } | ||
| const validator = validateFunctions[id]; | ||
| if (validator === undefined) { | ||
| throw new Error(`Validate function with id "${id}" not found`); | ||
| } | ||
| return validator; | ||
| } | ||
| export function createValidator(options) { | ||
| return { | ||
| isValid(schema, _, formValue) { | ||
| if (typeof schema === "boolean") { | ||
| return schema; | ||
| } | ||
| const validator = getValidator(options, schema); | ||
| return validator(options.cloneValue(formValue)).valid; | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValueValidator(options) { | ||
| const transformErrors = createFormErrorsTransformer(options); | ||
| return { | ||
| validateFormValue(rootSchema, formValue) { | ||
| const validator = getValidator(options, rootSchema); | ||
| const { valid, errors } = validator(options.cloneValue(formValue)); | ||
| if (valid) { | ||
| return { | ||
| value: formValue, | ||
| }; | ||
| } | ||
| return transformErrors(errors, formValue); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFieldValueValidator(options) { | ||
| return { | ||
| validateFieldValue(field, fieldValue) { | ||
| const validator = getValidator(options, field.schema); | ||
| const { valid, errors } = validator(options.cloneValue(fieldValue)); | ||
| if (valid) { | ||
| return []; | ||
| } | ||
| return transformFieldErrors(field, errors); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValidatorFactory({ cloneValue = structuredClone, ...vOptions }) { | ||
| return (options) => { | ||
| const full = { | ||
| cloneValue, | ||
| ...vOptions, | ||
| ...options, | ||
| }; | ||
| return Object.assign(createValidator(full), createFormValueValidator(full), createFieldValueValidator(full)); | ||
| }; | ||
| } |
| import type { Config, FieldValueValidator, FormValue, FormValueValidator, Schema, Validator } from "@sjsf/form"; | ||
| import { type MapLike } from "@sjsf/form/lib/memoize"; | ||
| import { Validator as AtaValidator } from "ata-validator"; | ||
| import { type ErrorsTransformerOptions } from "./errors.js"; | ||
| export interface ValueCloner { | ||
| cloneValue: (value: FormValue) => FormValue; | ||
| } | ||
| export type AtaValidatorFactory = (schema: Schema) => AtaValidator; | ||
| export declare const COLOR_FORMAT_REGEX: RegExp; | ||
| export declare const DATA_URL_FORMAT_REGEX: RegExp; | ||
| export declare const DEFAULT_VALIDATOR_OPTIONS: { | ||
| verbose: true; | ||
| formats: { | ||
| color: (str: string) => boolean; | ||
| "data-url": (str: string) => boolean; | ||
| }; | ||
| }; | ||
| export declare const defaultValidatorFactory: AtaValidatorFactory; | ||
| export type ValidatorsCache = MapLike<Schema, AtaValidator>; | ||
| export declare function createSchemaValidatorFactory(factory: AtaValidatorFactory, validatorsCache?: ValidatorsCache): (schema: Schema, rootSchema: Schema) => AtaValidator; | ||
| export declare function createFieldSchemaValidatorFactory(factory: AtaValidatorFactory, cache?: WeakMap<Schema, AtaValidator>): (config: Config) => AtaValidator; | ||
| export interface ValidatorOptions extends ValueCloner { | ||
| createSchemaValidator: (schema: Schema, rootSchema: Schema) => AtaValidator; | ||
| } | ||
| export declare function createValidator({ createSchemaValidator, cloneValue, }: ValidatorOptions): Validator; | ||
| export interface FormValueValidatorOptions extends ValidatorOptions, ErrorsTransformerOptions, ValueCloner { | ||
| } | ||
| export declare function createFormValueValidator<T>(options: FormValueValidatorOptions): FormValueValidator<T>; | ||
| export interface FieldValueValidatorOptions extends ValueCloner { | ||
| compileFieldSchema: (config: Config) => AtaValidator; | ||
| } | ||
| export declare function createFieldValueValidator({ compileFieldSchema, cloneValue, }: FieldValueValidatorOptions): FieldValueValidator; | ||
| export interface FormValidatorOptions extends ValidatorOptions, FormValueValidatorOptions, FieldValueValidatorOptions { | ||
| } | ||
| export declare function createFormValidator<T>({ factory, schemaValidatorsCache, fieldsValidatorsCache, createSchemaValidator, compileFieldSchema, cloneValue, ...rest }?: Partial<FormValidatorOptions> & { | ||
| factory?: AtaValidatorFactory; | ||
| schemaValidatorsCache?: ValidatorsCache; | ||
| fieldsValidatorsCache?: WeakMap<Schema, AtaValidator>; | ||
| }): Validator & FormValueValidator<T> & FieldValueValidator; |
| import { DATA_URL_FORMAT, ID_KEY, prefixSchemaRefs, ROOT_SCHEMA_PREFIX, } from "@sjsf/form/core"; | ||
| import { memoize, weakMemoize } from "@sjsf/form/lib/memoize"; | ||
| import { Validator as AtaValidator, } from "ata-validator"; | ||
| import { createFormErrorsTransformer, transformFieldErrors, } from "./errors.js"; | ||
| export const COLOR_FORMAT_REGEX = /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/; | ||
| export const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/; | ||
| export const DEFAULT_VALIDATOR_OPTIONS = { | ||
| verbose: true, | ||
| formats: { | ||
| color: (str) => COLOR_FORMAT_REGEX.test(str), | ||
| [DATA_URL_FORMAT]: (str) => DATA_URL_FORMAT_REGEX.test(str), | ||
| }, | ||
| }; | ||
| export const defaultValidatorFactory = (schema) => new AtaValidator(Object.assign({ $schema: "http://json-schema.org/draft-07/schema#" }, schema), DEFAULT_VALIDATOR_OPTIONS); | ||
| export function createSchemaValidatorFactory(factory, validatorsCache = new WeakMap()) { | ||
| let rootSchemaId = ""; | ||
| let usePrefixSchemaRefs = false; | ||
| let lastRootSchema = new WeakRef({}); | ||
| const makeValidator = memoize(validatorsCache, (schema) => { | ||
| return factory(usePrefixSchemaRefs ? prefixSchemaRefs(schema, rootSchemaId) : schema); | ||
| }); | ||
| return (schema, rootSchema) => { | ||
| rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX; | ||
| usePrefixSchemaRefs = schema !== rootSchema; | ||
| const validator = makeValidator(schema); | ||
| if (usePrefixSchemaRefs && lastRootSchema.deref() !== rootSchema) { | ||
| lastRootSchema = new WeakRef(rootSchema); | ||
| validator.addSchema(Object.assign({ [ID_KEY]: rootSchemaId }, rootSchema)); | ||
| } | ||
| return validator; | ||
| }; | ||
| } | ||
| export function createFieldSchemaValidatorFactory(factory, cache = new WeakMap()) { | ||
| const makeValidator = weakMemoize(cache, factory); | ||
| return (config) => makeValidator(config.schema); | ||
| } | ||
| export function createValidator({ createSchemaValidator, cloneValue, }) { | ||
| return { | ||
| isValid(schemaDef, rootSchema, formValue) { | ||
| if (typeof schemaDef === "boolean") { | ||
| return schemaDef; | ||
| } | ||
| const validator = createSchemaValidator(schemaDef, rootSchema); | ||
| return validator.isValidObject(cloneValue(formValue)); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValueValidator(options) { | ||
| const transformErrors = createFormErrorsTransformer(options); | ||
| return { | ||
| validateFormValue(rootSchema, formValue) { | ||
| const validator = options.createSchemaValidator(rootSchema, rootSchema); | ||
| const { valid, errors } = validator.validate(options.cloneValue(formValue)); | ||
| if (valid) { | ||
| return { | ||
| value: formValue, | ||
| }; | ||
| } | ||
| return transformErrors(errors, formValue); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFieldValueValidator({ compileFieldSchema, cloneValue, }) { | ||
| return { | ||
| validateFieldValue(field, fieldValue) { | ||
| const validator = compileFieldSchema(field); | ||
| const { valid, errors } = validator.validate(cloneValue(fieldValue)); | ||
| if (valid) { | ||
| return []; | ||
| } | ||
| return transformFieldErrors(field, errors); | ||
| }, | ||
| }; | ||
| } | ||
| export function createFormValidator({ factory = defaultValidatorFactory, schemaValidatorsCache, fieldsValidatorsCache, createSchemaValidator = createSchemaValidatorFactory(factory, schemaValidatorsCache), compileFieldSchema = createFieldSchemaValidatorFactory(factory, fieldsValidatorsCache), cloneValue = structuredClone, ...rest } = {}) { | ||
| const options = { | ||
| ...rest, | ||
| cloneValue, | ||
| createSchemaValidator, | ||
| compileFieldSchema, | ||
| }; | ||
| return Object.assign(createValidator(options), createFormValueValidator(options), createFieldValueValidator(options)); | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
16592
0.43%1
Infinity%