🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@sjsf-lab/ata-validator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sjsf-lab/ata-validator - npm Package Compare versions

Comparing version
3.1.1
to
3.2.0
+3
-2
dist/errors.d.ts

@@ -1,7 +0,8 @@

import { type Config, type FailureValidationResult, type FormValue, type UiSchemaRoot } from "@sjsf/form";
import { type Config, type FailureValidationResult, type FormValue, type Schema, type UiSchemaRoot } from "@sjsf/form";
import type { ValidationError } from "ata-validator";
export interface ErrorsTransformerOptions {
uiSchema?: UiSchemaRoot;
schema?: Schema;
}
export declare function createFormErrorsTransformer({ uiSchema, }: ErrorsTransformerOptions): (errors: ValidationError[], data: FormValue) => FailureValidationResult;
export declare function createFormErrorsTransformer({ uiSchema, schema, }: ErrorsTransformerOptions): (errors: ValidationError[], data: FormValue) => FailureValidationResult;
export declare function transformFieldErrors(config: Config, errors: ValidationError[]): string[];
+9
-3
import { encodePseudoElement, getRootUiSchemaTitleByPath, } from "@sjsf/form";
import { pathFromLocation } from "@sjsf/form/core";
import { PROPERTIES_KEY, pathFromLocation } from "@sjsf/form/core";
import { getValueByPath } from "@sjsf/form/lib/object";
function createInstancePath({ params: { missingProperty, propertyName } }, path) {

@@ -25,3 +26,3 @@ let id = path;

}
export function createFormErrorsTransformer({ uiSchema = {}, }) {
export function createFormErrorsTransformer({ uiSchema = {}, schema = {}, }) {
return (errors, data) => {

@@ -43,3 +44,8 @@ return {

}
return undefined;
const schemaPath = [];
for (const part of path) {
schemaPath.push(PROPERTIES_KEY, part);
}
schemaPath.push(PROPERTIES_KEY, missingProperty, "title");
return getValueByPath(schema, schemaPath);
}),

@@ -46,0 +52,0 @@ };

@@ -1,6 +0,17 @@

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 { FieldValueValidator, FormValueValidator, Schema, Validator } from "@sjsf/form";
import type { ValidationError } from "ata-validator";
import { type ErrorsTransformerOptions } from "../errors.js";
export type CompiledValidator = (data: unknown) => AtaValidationResult | {
import { type ValueCloner } from "../validator.svelte.js";
export declare const DEFAULT_PRECOMPILED_VALIDATOR_OPTIONS: {
format: "esm";
formats: {
color: (value: unknown) => boolean;
"data-url": (value: unknown) => boolean;
};
verbose: true;
};
export type CompiledValidator = (data: unknown) => {
valid: boolean;
errors: ValidationError[];
} | {
valid: true;

@@ -12,15 +23,21 @@ errors: ReadonlyArray<never>;

};
export interface ValidatorOptions extends ValueCloner {
interface LegacyValidatorOptions {
/** @deprecated use `validatorRetriever` instead */
validateFunctions: ValidateFunctions;
/** @deprecated use `validatorRetriever` instead */
augmentSuffix?: string;
validatorRetriever?: (schema: Schema) => CompiledValidator;
}
interface ModernValidatorOptions {
validatorRetriever: (schema: Schema) => CompiledValidator;
}
type CoreValidatorOptions = LegacyValidatorOptions | ModernValidatorOptions;
export type ValidatorOptions = ValueCloner & CoreValidatorOptions;
export declare function createValidator(options: ValidatorOptions): Validator;
export interface FormValueValidatorOptions extends ValidatorOptions, ErrorsTransformerOptions, ValueCloner {
}
export type FormValueValidatorOptions = ValidatorOptions & ErrorsTransformerOptions & ValueCloner;
export declare function createFormValueValidator<T>(options: FormValueValidatorOptions): FormValueValidator<T>;
export interface FieldValueValidatorOptions extends ValidatorOptions, ValueCloner {
}
export type FieldValueValidatorOptions = 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;
export type FormValidatorOptions = ValidatorOptions & FormValueValidatorOptions & FieldValueValidatorOptions;
export declare function createFormValidatorFactory<T>(vOptions: CoreValidatorOptions & Partial<ValueCloner>): (options: Omit<FormValidatorOptions, keyof ValidatorOptions>) => Validator & FormValueValidator<T> & FieldValueValidator;
export {};

@@ -1,21 +0,31 @@

import { DEFAULT_AUGMENT_SUFFIX } from "@sjsf/form/validators/precompile";
import { DATA_URL_FORMAT } from "@sjsf/form/core";
import { fromValidators } 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;
import { COLOR_FORMAT_REGEX, DATA_URL_FORMAT_REGEX, DEFAULT_VALIDATOR_OPTIONS, } from "../validator.svelte.js";
function createFormatPredicate(regExp) {
return new Function("value", `return ${regExp}.test(value)`);
}
export const DEFAULT_PRECOMPILED_VALIDATOR_OPTIONS = {
...DEFAULT_VALIDATOR_OPTIONS,
format: "esm",
formats: {
color: createFormatPredicate(COLOR_FORMAT_REGEX),
[DATA_URL_FORMAT]: createFormatPredicate(DATA_URL_FORMAT_REGEX),
},
};
// TODO: Remove in v4
function createRetriever(options) {
return "validateFunctions" in options
? (options.validatorRetriever ??
fromValidators(options.validateFunctions, options.augmentSuffix
? {
idAugmentations: {
combination: (id) => id + options.augmentSuffix,
},
}
: undefined))
: options.validatorRetriever;
}
export function createValidator(options) {
const getValidator = createRetriever(options);
return {

@@ -26,3 +36,3 @@ isValid(schema, _, formValue) {

}
const validator = getValidator(options, schema);
const validator = getValidator(schema);
return validator(options.cloneValue(formValue)).valid;

@@ -33,6 +43,7 @@ },

export function createFormValueValidator(options) {
const getValidator = createRetriever(options);
const transformErrors = createFormErrorsTransformer(options);
return {
validateFormValue(rootSchema, formValue) {
const validator = getValidator(options, rootSchema);
const validator = getValidator(rootSchema);
const { valid, errors } = validator(options.cloneValue(formValue));

@@ -49,5 +60,6 @@ if (valid) {

export function createFieldValueValidator(options) {
const getValidator = createRetriever(options);
return {
validateFieldValue(field, fieldValue) {
const validator = getValidator(options, field.schema);
const validator = getValidator(field.schema);
const { valid, errors } = validator(options.cloneValue(fieldValue));

@@ -61,8 +73,9 @@ if (valid) {

}
export function createFormValidatorFactory({ cloneValue = (value) => $state.snapshot(value), ...vOptions }) {
export function createFormValidatorFactory(vOptions) {
return (options) => {
const full = {
cloneValue,
...options,
...vOptions,
...options,
validatorRetriever: vOptions.validatorRetriever ?? createRetriever(vOptions),
cloneValue: vOptions.cloneValue ?? ((value) => $state.snapshot(value)),
};

@@ -69,0 +82,0 @@ return Object.assign(createValidator(full), createFormValueValidator(full), createFieldValueValidator(full));

@@ -20,4 +20,4 @@ import type { Config, FieldValueValidator, FormValue, FormValueValidator, Schema, Validator } from "@sjsf/form";

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 declare function createSchemaValidatorFactory(factory: AtaValidatorFactory, validatorsCache?: ValidatorsCache): (schema: Schema, rootSchema: Schema) => AtaValidator<unknown>;
export declare function createFieldSchemaValidatorFactory(factory: AtaValidatorFactory, cache?: WeakMap<Schema, AtaValidator<unknown>>): (config: Config) => AtaValidator<unknown>;
export interface ValidatorOptions extends ValueCloner {

@@ -24,0 +24,0 @@ createSchemaValidator: (schema: Schema, rootSchema: Schema) => AtaValidator;

{
"name": "@sjsf-lab/ata-validator",
"version": "3.1.1",
"version": "3.2.0",
"description": "The ata based validator for svelte-jsonschema-form",
"license": "MIT",
"keywords": [
"validator",
"ata",
"jsonschema",
"ata"
"validator"
],
"type": "module",
"homepage": "https://x0k.github.io/svelte-jsonschema-form/",
"bugs": "https://github.com/x0k/svelte-jsonschema-form/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/x0k/svelte-jsonschema-form.git",
"directory": "lab/ata-validator"
},
"files": [

@@ -17,14 +23,5 @@ "dist",

],
"publishConfig": {
"provenance": true
},
"repository": {
"type": "git",
"url": "git+https://github.com/x0k/svelte-jsonschema-form.git",
"directory": "lab/ata-validator"
},
"bugs": "https://github.com/x0k/svelte-jsonschema-form/issues",
"homepage": "https://x0k.github.io/svelte-jsonschema-form/",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"exports": {

@@ -43,17 +40,22 @@ "./package.json": "./package.json",

},
"publishConfig": {
"provenance": true
},
"devDependencies": {
"ata-validator": "^0.21.0",
"svelte": "^5.56.4",
"@sjsf/form": "3.7.0",
"validator-testing": "1.0.28"
},
"peerDependencies": {
"@sjsf/form": "^3.5.0",
"ata-validator": "^0.13.1"
"ata-validator": "^0.21.0"
},
"devDependencies": {
"ata-validator": "^0.13.2",
"svelte": "^5.55.5",
"@sjsf/form": "3.6.0",
"validator-testing": "1.0.27"
},
"scripts": {
"test": "vitest run",
"build": "tsc && publint",
"dev": "tsc --watch"
"dev": "tsc --watch",
"format": "oxfmt .",
"format:check": "oxfmt --check ."
}
}