unischema 1.0.1 → 1.2.0
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/README.md +780 -228
- package/dist/adapters/backend/index.d.mts +2 -1
- package/dist/adapters/backend/index.d.ts +2 -1
- package/dist/adapters/backend/index.js +17 -441
- package/dist/adapters/backend/index.mjs +9 -433
- package/dist/adapters/frontend/index.d.mts +2 -1
- package/dist/adapters/frontend/index.d.ts +2 -1
- package/dist/adapters/frontend/index.js +10 -421
- package/dist/adapters/frontend/index.mjs +8 -419
- package/dist/chunk-5A4ITJVD.mjs +124 -0
- package/dist/chunk-66RFUBVU.js +131 -0
- package/dist/chunk-75YSYC4K.mjs +85 -0
- package/dist/chunk-76BBWQDH.js +90 -0
- package/dist/chunk-7XES4A3M.mjs +237 -0
- package/dist/chunk-BVRXGZLS.js +17 -0
- package/dist/chunk-COMVAVFU.mjs +335 -0
- package/dist/chunk-DT2TQZU7.js +796 -0
- package/dist/chunk-FPCCH55A.js +103 -0
- package/dist/chunk-IUXRLMET.js +206 -0
- package/dist/chunk-JEW6U6CB.js +353 -0
- package/dist/chunk-KZCV5IW4.mjs +97 -0
- package/dist/chunk-KZZ7NVU3.mjs +41 -0
- package/dist/chunk-MFEBMQAU.mjs +779 -0
- package/dist/chunk-OIYG5D2I.js +50 -0
- package/dist/chunk-RW6HDA5H.mjs +194 -0
- package/dist/chunk-TTK77YBI.mjs +15 -0
- package/dist/chunk-TXT36BCE.js +248 -0
- package/dist/index-C17xs-fU.d.mts +140 -0
- package/dist/index-C17xs-fU.d.ts +140 -0
- package/dist/index.d.mts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +769 -499
- package/dist/index.mjs +695 -487
- package/dist/{schema-D9DGC9E_.d.ts → schema-DYE8Wz8X.d.mts} +264 -79
- package/dist/{schema-D9DGC9E_.d.mts → schema-Dtp-joeT.d.ts} +264 -79
- package/dist/validators/array.d.mts +15 -0
- package/dist/validators/array.d.ts +15 -0
- package/dist/validators/array.js +31 -0
- package/dist/validators/array.mjs +2 -0
- package/dist/validators/common.d.mts +13 -0
- package/dist/validators/common.d.ts +13 -0
- package/dist/validators/common.js +27 -0
- package/dist/validators/common.mjs +2 -0
- package/dist/validators/date.d.mts +23 -0
- package/dist/validators/date.d.ts +23 -0
- package/dist/validators/date.js +47 -0
- package/dist/validators/date.mjs +2 -0
- package/dist/validators/index.d.mts +46 -0
- package/dist/validators/index.d.ts +46 -0
- package/dist/validators/index.js +256 -0
- package/dist/validators/index.mjs +7 -0
- package/dist/validators/number.d.mts +25 -0
- package/dist/validators/number.d.ts +25 -0
- package/dist/validators/number.js +51 -0
- package/dist/validators/number.mjs +2 -0
- package/dist/validators/object.d.mts +11 -0
- package/dist/validators/object.d.ts +11 -0
- package/dist/validators/object.js +23 -0
- package/dist/validators/object.mjs +2 -0
- package/dist/validators/string.d.mts +37 -0
- package/dist/validators/string.d.ts +37 -0
- package/dist/validators/string.js +75 -0
- package/dist/validators/string.mjs +2 -0
- package/package.json +82 -5
- package/dist/adapters/backend/index.js.map +0 -1
- package/dist/adapters/backend/index.mjs.map +0 -1
- package/dist/adapters/frontend/index.js.map +0 -1
- package/dist/adapters/frontend/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the FormSchema validation engine
|
|
3
|
+
*/
|
|
4
|
+
type ValidationSeverity = 'hard' | 'soft';
|
|
5
|
+
interface ValidationError {
|
|
6
|
+
/** Field path (e.g., "email" or "address.city") */
|
|
7
|
+
field: string;
|
|
8
|
+
/** Path as array (e.g., ["address", "city"]) */
|
|
9
|
+
path?: string[];
|
|
10
|
+
/** Error code for programmatic handling */
|
|
11
|
+
code: string;
|
|
12
|
+
/** Human-readable error message */
|
|
13
|
+
message: string;
|
|
14
|
+
/** Severity level - hard errors block submission, soft are warnings */
|
|
15
|
+
severity: ValidationSeverity;
|
|
16
|
+
/** Value that was received (for context) */
|
|
17
|
+
received?: unknown;
|
|
18
|
+
/** Expected value or constraints (for context) */
|
|
19
|
+
expected?: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface ValidationResult {
|
|
22
|
+
/** True if no hard errors exist */
|
|
23
|
+
valid: boolean;
|
|
24
|
+
/** Errors that block form submission */
|
|
25
|
+
hardErrors: ValidationError[];
|
|
26
|
+
/** Warnings that don't block submission */
|
|
27
|
+
softErrors: ValidationError[];
|
|
28
|
+
/** Errors aggregated by field path */
|
|
29
|
+
errorsByField?: Record<string, ValidationError[]>;
|
|
30
|
+
}
|
|
31
|
+
/** Validation options */
|
|
32
|
+
interface ValidationOptions {
|
|
33
|
+
/** Custom error message formatter */
|
|
34
|
+
errorMap?: (error: ValidationError) => ValidationError | {
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
/** Stop validation on first error */
|
|
38
|
+
abortEarly?: boolean;
|
|
39
|
+
/** Aggregate errors by field */
|
|
40
|
+
aggregateByField?: boolean;
|
|
41
|
+
}
|
|
42
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
|
|
43
|
+
interface ValidationRule {
|
|
44
|
+
/** Rule type identifier */
|
|
45
|
+
type: string;
|
|
46
|
+
/** Rule parameters */
|
|
47
|
+
params?: Record<string, unknown>;
|
|
48
|
+
/** Custom error message */
|
|
49
|
+
message?: string;
|
|
50
|
+
/** Is this a soft validation (warning only)? */
|
|
51
|
+
soft?: boolean;
|
|
52
|
+
/** Is this an async validation? */
|
|
53
|
+
async?: boolean;
|
|
54
|
+
/** Debounce delay in ms for async validators */
|
|
55
|
+
debounce?: number;
|
|
56
|
+
/** Timeout in ms for async validators */
|
|
57
|
+
timeout?: number;
|
|
58
|
+
}
|
|
59
|
+
interface FieldDefinition<T = unknown> {
|
|
60
|
+
/** The base type of this field */
|
|
61
|
+
type: FieldType;
|
|
62
|
+
/** Validation rules to apply */
|
|
63
|
+
rules: ValidationRule[];
|
|
64
|
+
/** Is this field required? */
|
|
65
|
+
required: boolean;
|
|
66
|
+
/** Default value */
|
|
67
|
+
defaultValue?: T;
|
|
68
|
+
/** For nested schemas */
|
|
69
|
+
schema?: SchemaDefinition;
|
|
70
|
+
/** For array items */
|
|
71
|
+
items?: FieldDefinition;
|
|
72
|
+
/** Field metadata */
|
|
73
|
+
meta?: Record<string, unknown>;
|
|
74
|
+
/** Transform functions to apply to value */
|
|
75
|
+
transforms?: Array<(value: unknown) => unknown>;
|
|
76
|
+
/** Preprocess function to apply before validation */
|
|
77
|
+
preprocess?: (value: unknown) => unknown;
|
|
78
|
+
/** Allow null values */
|
|
79
|
+
nullable?: boolean;
|
|
80
|
+
/** Allow null or undefined values */
|
|
81
|
+
nullish?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface SchemaDefinition {
|
|
84
|
+
/** Field definitions keyed by field name */
|
|
85
|
+
fields: Record<string, FieldDefinition>;
|
|
86
|
+
/** Schema metadata */
|
|
87
|
+
meta?: Record<string, unknown>;
|
|
88
|
+
/** Allow unknown keys to pass through */
|
|
89
|
+
passthrough?: boolean;
|
|
90
|
+
/** Strict mode - reject unknown keys */
|
|
91
|
+
strict?: boolean;
|
|
92
|
+
/** Catchall field definition for unknown keys */
|
|
93
|
+
catchall?: FieldDefinition;
|
|
94
|
+
}
|
|
95
|
+
interface ValidatorContext {
|
|
96
|
+
/** Current field path */
|
|
97
|
+
path: string;
|
|
98
|
+
/** Full data object being validated */
|
|
99
|
+
root: unknown;
|
|
100
|
+
/** Parent object containing this field */
|
|
101
|
+
parent?: unknown;
|
|
102
|
+
}
|
|
103
|
+
type ValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => ValidationError | null;
|
|
104
|
+
type AsyncValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => Promise<ValidationError | null>;
|
|
105
|
+
/** Async refine function type - returns boolean or validation result object */
|
|
106
|
+
type AsyncRefineFn<T = unknown> = (value: T) => Promise<boolean | {
|
|
107
|
+
valid: boolean;
|
|
108
|
+
message?: string;
|
|
109
|
+
}>;
|
|
110
|
+
/** Options for async validation */
|
|
111
|
+
interface AsyncValidationOptions {
|
|
112
|
+
/** Custom error message */
|
|
113
|
+
message?: string;
|
|
114
|
+
/** Debounce delay in ms */
|
|
115
|
+
debounce?: number;
|
|
116
|
+
/** Timeout in ms (default: 5000) */
|
|
117
|
+
timeout?: number;
|
|
118
|
+
/** Is this a soft validation (warning only)? */
|
|
119
|
+
soft?: boolean;
|
|
120
|
+
/** Cache results (useful for expensive checks) */
|
|
121
|
+
cache?: boolean;
|
|
122
|
+
/** Cache TTL in seconds (default: 3600) */
|
|
123
|
+
cacheTTL?: number;
|
|
124
|
+
}
|
|
125
|
+
interface EnterpriseValidationResponse {
|
|
126
|
+
status: 'success' | 'validation_error';
|
|
127
|
+
data?: unknown;
|
|
128
|
+
errors: ValidationError[];
|
|
129
|
+
msg: string;
|
|
130
|
+
validation: {
|
|
131
|
+
hard_validations: ValidationError[];
|
|
132
|
+
soft_validations: ValidationError[];
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert ValidationResult to enterprise-compatible response format
|
|
137
|
+
*/
|
|
138
|
+
declare function toEnterpriseResponse(result: ValidationResult, data?: unknown): EnterpriseValidationResponse;
|
|
139
|
+
|
|
140
|
+
export { type AsyncRefineFn as A, type EnterpriseValidationResponse as E, type FieldDefinition as F, type SchemaDefinition as S, type ValidatorContext as V, type ValidationError as a, type ValidationResult as b, type ValidationRule as c, type AsyncValidationOptions as d, type ValidationOptions as e, type ValidatorFn as f, type ValidationSeverity as g, type FieldType as h, type AsyncValidatorFn as i, toEnterpriseResponse as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S as SchemaDefinition,
|
|
2
|
-
export { A as
|
|
1
|
+
import { S as SchemaDefinition, e as ValidationOptions, b as ValidationResult, f as ValidatorFn } from './index-C17xs-fU.mjs';
|
|
2
|
+
export { A as AsyncRefineFn, d as AsyncValidationOptions, i as AsyncValidatorFn, E as EnterpriseValidationResponse, F as FieldDefinition, h as FieldType, a as ValidationError, c as ValidationRule, g as ValidationSeverity, V as ValidatorContext, t as toEnterpriseResponse } from './index-C17xs-fU.mjs';
|
|
3
|
+
export { A as ArrayFieldBuilder, B as BaseFieldBuilder, l as BooleanFieldBuilder, n as DateFieldBuilder, D as DeepPartial, E as EnumFieldBuilder, I as InferInput, j as InferOutput, N as NumberFieldBuilder, O as ObjectFieldBuilder, S as SchemaBuilder, k as StringFieldBuilder, f as catchall, i as coerce, d as deepPartial, e as extend, h as field, m as merge, o as omit, g as optional, a as partial, b as passthrough, p as pick, r as required, s as schema, c as strict } from './schema-DYE8Wz8X.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Core validation engine - runs unchanged in browser and Node.js
|
|
@@ -8,19 +9,19 @@ export { A as ArrayFieldBuilder, B as BaseFieldBuilder, h as BooleanFieldBuilder
|
|
|
8
9
|
/**
|
|
9
10
|
* Validate data against a schema
|
|
10
11
|
*/
|
|
11
|
-
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): ValidationResult;
|
|
12
|
+
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown, options?: ValidationOptions): ValidationResult;
|
|
12
13
|
/**
|
|
13
14
|
* Main validation function
|
|
14
15
|
*/
|
|
15
|
-
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): ValidationResult;
|
|
16
|
+
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): ValidationResult;
|
|
16
17
|
/**
|
|
17
18
|
* Check if data is valid (no hard errors)
|
|
18
19
|
*/
|
|
19
|
-
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown
|
|
20
|
+
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown>, options?: ValidationOptions): boolean;
|
|
20
21
|
/**
|
|
21
22
|
* Validate and throw if invalid
|
|
22
23
|
*/
|
|
23
|
-
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): T;
|
|
24
|
+
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): T;
|
|
24
25
|
/**
|
|
25
26
|
* Merge multiple validation results
|
|
26
27
|
*/
|
|
@@ -34,6 +35,24 @@ declare function validResult(): ValidationResult;
|
|
|
34
35
|
*/
|
|
35
36
|
declare function errorResult(field: string, code: string, message: string, soft?: boolean): ValidationResult;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Async validation engine for handling asynchronous validators
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
declare function validateSchemaAsync(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): Promise<ValidationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Main async validation function
|
|
45
|
+
*/
|
|
46
|
+
declare function validateAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<ValidationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if data is valid async (no hard errors)
|
|
49
|
+
*/
|
|
50
|
+
declare function isValidAsync(schema: SchemaDefinition, data: Record<string, unknown>): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate async and throw if invalid
|
|
53
|
+
*/
|
|
54
|
+
declare function assertValidAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<T>;
|
|
55
|
+
|
|
37
56
|
/**
|
|
38
57
|
* Built-in validators for common validation rules
|
|
39
58
|
*/
|
|
@@ -53,4 +72,4 @@ declare function getValidator(name: string): ValidatorFn | undefined;
|
|
|
53
72
|
*/
|
|
54
73
|
declare function getTypeValidator(type: string): ValidatorFn | undefined;
|
|
55
74
|
|
|
56
|
-
export { SchemaDefinition, ValidationResult, ValidatorFn, assertValid, errorResult, getTypeValidator, getValidator, isValid, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateSchema };
|
|
75
|
+
export { SchemaDefinition, ValidationOptions, ValidationResult, ValidatorFn, assertValid, assertValidAsync, errorResult, getTypeValidator, getValidator, isValid, isValidAsync, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateAsync, validateSchema, validateSchemaAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S as SchemaDefinition,
|
|
2
|
-
export { A as
|
|
1
|
+
import { S as SchemaDefinition, e as ValidationOptions, b as ValidationResult, f as ValidatorFn } from './index-C17xs-fU.js';
|
|
2
|
+
export { A as AsyncRefineFn, d as AsyncValidationOptions, i as AsyncValidatorFn, E as EnterpriseValidationResponse, F as FieldDefinition, h as FieldType, a as ValidationError, c as ValidationRule, g as ValidationSeverity, V as ValidatorContext, t as toEnterpriseResponse } from './index-C17xs-fU.js';
|
|
3
|
+
export { A as ArrayFieldBuilder, B as BaseFieldBuilder, l as BooleanFieldBuilder, n as DateFieldBuilder, D as DeepPartial, E as EnumFieldBuilder, I as InferInput, j as InferOutput, N as NumberFieldBuilder, O as ObjectFieldBuilder, S as SchemaBuilder, k as StringFieldBuilder, f as catchall, i as coerce, d as deepPartial, e as extend, h as field, m as merge, o as omit, g as optional, a as partial, b as passthrough, p as pick, r as required, s as schema, c as strict } from './schema-Dtp-joeT.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Core validation engine - runs unchanged in browser and Node.js
|
|
@@ -8,19 +9,19 @@ export { A as ArrayFieldBuilder, B as BaseFieldBuilder, h as BooleanFieldBuilder
|
|
|
8
9
|
/**
|
|
9
10
|
* Validate data against a schema
|
|
10
11
|
*/
|
|
11
|
-
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): ValidationResult;
|
|
12
|
+
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown, options?: ValidationOptions): ValidationResult;
|
|
12
13
|
/**
|
|
13
14
|
* Main validation function
|
|
14
15
|
*/
|
|
15
|
-
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): ValidationResult;
|
|
16
|
+
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): ValidationResult;
|
|
16
17
|
/**
|
|
17
18
|
* Check if data is valid (no hard errors)
|
|
18
19
|
*/
|
|
19
|
-
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown
|
|
20
|
+
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown>, options?: ValidationOptions): boolean;
|
|
20
21
|
/**
|
|
21
22
|
* Validate and throw if invalid
|
|
22
23
|
*/
|
|
23
|
-
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): T;
|
|
24
|
+
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): T;
|
|
24
25
|
/**
|
|
25
26
|
* Merge multiple validation results
|
|
26
27
|
*/
|
|
@@ -34,6 +35,24 @@ declare function validResult(): ValidationResult;
|
|
|
34
35
|
*/
|
|
35
36
|
declare function errorResult(field: string, code: string, message: string, soft?: boolean): ValidationResult;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Async validation engine for handling asynchronous validators
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
declare function validateSchemaAsync(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): Promise<ValidationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Main async validation function
|
|
45
|
+
*/
|
|
46
|
+
declare function validateAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<ValidationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if data is valid async (no hard errors)
|
|
49
|
+
*/
|
|
50
|
+
declare function isValidAsync(schema: SchemaDefinition, data: Record<string, unknown>): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate async and throw if invalid
|
|
53
|
+
*/
|
|
54
|
+
declare function assertValidAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<T>;
|
|
55
|
+
|
|
37
56
|
/**
|
|
38
57
|
* Built-in validators for common validation rules
|
|
39
58
|
*/
|
|
@@ -53,4 +72,4 @@ declare function getValidator(name: string): ValidatorFn | undefined;
|
|
|
53
72
|
*/
|
|
54
73
|
declare function getTypeValidator(type: string): ValidatorFn | undefined;
|
|
55
74
|
|
|
56
|
-
export { SchemaDefinition, ValidationResult, ValidatorFn, assertValid, errorResult, getTypeValidator, getValidator, isValid, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateSchema };
|
|
75
|
+
export { SchemaDefinition, ValidationOptions, ValidationResult, ValidatorFn, assertValid, assertValidAsync, errorResult, getTypeValidator, getValidator, isValid, isValidAsync, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateAsync, validateSchema, validateSchemaAsync };
|