@cleverbrush/schema 4.0.0 → 4.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 +21 -0
- package/dist/builders/AnySchemaBuilder.js +1 -1
- package/dist/builders/ArraySchemaBuilder.js +1 -1
- package/dist/builders/BooleanSchemaBuilder.js +1 -1
- package/dist/builders/DateSchemaBuilder.js +1 -1
- package/dist/builders/ExternSchemaBuilder.js +1 -1
- package/dist/builders/FunctionSchemaBuilder.js +1 -1
- package/dist/builders/IntersectionSchemaBuilder.d.ts +124 -0
- package/dist/builders/NumberSchemaBuilder.js +1 -1
- package/dist/builders/ObjectSchemaBuilder.js +1 -1
- package/dist/builders/ParseStringSchemaBuilder.js +1 -1
- package/dist/builders/PromiseSchemaBuilder.js +1 -1
- package/dist/builders/RecordSchemaBuilder.js +1 -1
- package/dist/builders/StringSchemaBuilder.js +1 -1
- package/dist/builders/TupleSchemaBuilder.js +1 -1
- package/dist/builders/UnionSchemaBuilder.js +1 -1
- package/dist/{chunk-ZC2HTRZF.js → chunk-54RHS4F4.js} +2 -2
- package/dist/{chunk-4RMOR7SV.js → chunk-6LSN7NXQ.js} +2 -2
- package/dist/{chunk-EBGC6ZBF.js → chunk-C6YQOKWB.js} +2 -2
- package/dist/{chunk-PUWIYD4T.js → chunk-ELPPAHNO.js} +2 -2
- package/dist/{chunk-VRRKXJ2H.js → chunk-G424M7GI.js} +2 -2
- package/dist/{chunk-FTA66XZT.js → chunk-JUFZ7PLO.js} +2 -2
- package/dist/{chunk-OJJHAZZ4.js → chunk-K4ZLXLE2.js} +2 -2
- package/dist/{chunk-3K7MOEPS.js → chunk-KC45JEFL.js} +2 -2
- package/dist/{chunk-YYE5HQCL.js → chunk-NF4CRFMN.js} +2 -2
- package/dist/{chunk-QG254RGI.js → chunk-ORV2G6ZL.js} +2 -2
- package/dist/{chunk-ETJPB3TR.js → chunk-PQINUGZW.js} +2 -2
- package/dist/chunk-REYZ7G7J.js +2 -0
- package/dist/chunk-REYZ7G7J.js.map +1 -0
- package/dist/chunk-VSU5GILY.js +2 -0
- package/dist/chunk-VSU5GILY.js.map +1 -0
- package/dist/{chunk-SY5EYKF2.js → chunk-XHSBY2QK.js} +2 -2
- package/dist/{chunk-57AZDIBB.js → chunk-XL723XFL.js} +2 -2
- package/dist/{chunk-ZHBJ46HB.js → chunk-XPLTW5DI.js} +2 -2
- package/dist/{chunk-QWYVMYJ2.js → chunk-YAOZEA2R.js} +2 -2
- package/dist/core.d.ts +2 -0
- package/dist/core.js +1 -1
- package/dist/extension.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-C4LSLV6T.js +0 -2
- package/dist/chunk-C4LSLV6T.js.map +0 -1
- package/dist/chunk-G6HTNXRO.js +0 -2
- package/dist/chunk-G6HTNXRO.js.map +0 -1
- /package/dist/{chunk-ZC2HTRZF.js.map → chunk-54RHS4F4.js.map} +0 -0
- /package/dist/{chunk-4RMOR7SV.js.map → chunk-6LSN7NXQ.js.map} +0 -0
- /package/dist/{chunk-EBGC6ZBF.js.map → chunk-C6YQOKWB.js.map} +0 -0
- /package/dist/{chunk-PUWIYD4T.js.map → chunk-ELPPAHNO.js.map} +0 -0
- /package/dist/{chunk-VRRKXJ2H.js.map → chunk-G424M7GI.js.map} +0 -0
- /package/dist/{chunk-FTA66XZT.js.map → chunk-JUFZ7PLO.js.map} +0 -0
- /package/dist/{chunk-OJJHAZZ4.js.map → chunk-K4ZLXLE2.js.map} +0 -0
- /package/dist/{chunk-3K7MOEPS.js.map → chunk-KC45JEFL.js.map} +0 -0
- /package/dist/{chunk-YYE5HQCL.js.map → chunk-NF4CRFMN.js.map} +0 -0
- /package/dist/{chunk-QG254RGI.js.map → chunk-ORV2G6ZL.js.map} +0 -0
- /package/dist/{chunk-ETJPB3TR.js.map → chunk-PQINUGZW.js.map} +0 -0
- /package/dist/{chunk-SY5EYKF2.js.map → chunk-XHSBY2QK.js.map} +0 -0
- /package/dist/{chunk-57AZDIBB.js.map → chunk-XL723XFL.js.map} +0 -0
- /package/dist/{chunk-ZHBJ46HB.js.map → chunk-XPLTW5DI.js.map} +0 -0
- /package/dist/{chunk-QWYVMYJ2.js.map → chunk-YAOZEA2R.js.map} +0 -0
package/README.md
CHANGED
|
@@ -137,6 +137,7 @@ The following builder functions are available:
|
|
|
137
137
|
| `tuple([...schemas])` | Fixed-length array with per-position types. Each index validated against its own schema — mirrors TypeScript tuple types. | `.rest(schema)`, `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)` |
|
|
138
138
|
| `record(keySchema, valSchema)` | Object with dynamic string keys. Every key must satisfy `keySchema` (a string schema) and every value must satisfy `valSchema` — mirrors TypeScript's `Record<K, V>`. | `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)`, `.addValidator(fn)` |
|
|
139
139
|
| `union(schema)` | Union of schemas — e.g. `string \| number`. | `.or(schema)`, `.validate(data)`, `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)` |
|
|
140
|
+
| `intersection(left, right)` | Intersection of two schemas — both must pass. Merges validated outputs. Use `.acceptUnknownProps()` on object schemas. | `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)`, `.addValidator(fn)` |
|
|
140
141
|
| `enumOf(...values)` | String enum — sugar for `string().oneOf(...)`. | `.optional()`, `.nullable()`, `.notNullable()`, `.default(value)` |
|
|
141
142
|
| `lazy(getter)` | Recursive/self-referential schema. The getter is called once and its result is cached. Enables tree structures, linked lists, and other recursive types. | `.resolve()`, `.optional()`, `.addValidator(fn)`, `.default(value)` |
|
|
142
143
|
| `generic(fn)` | Parameterized schema template. Call `.apply(...schemas)` with concrete schemas to obtain a fully typed concrete schema builder. TypeScript infers the result type from the template function's own generic signature. Optionally pass a `defaults` array as the first argument to enable direct validation without calling `.apply()`. | `.apply(...schemas)`, `.optional()`, `.nullable()`, `.default(value)` |
|
|
@@ -199,6 +200,16 @@ const TeamSchema = object({
|
|
|
199
200
|
const IdOrEmail = union(string().minLength(1)).or(
|
|
200
201
|
string().matches(/^[^@]+@[^@]+$/)
|
|
201
202
|
);
|
|
203
|
+
|
|
204
|
+
// Intersection types — combine two schemas into one (both must pass)
|
|
205
|
+
import { intersection } from '@cleverbrush/schema';
|
|
206
|
+
|
|
207
|
+
const NameAndAge = intersection(
|
|
208
|
+
object({ name: string() }).acceptUnknownProps(),
|
|
209
|
+
object({ age: number() }).acceptUnknownProps()
|
|
210
|
+
);
|
|
211
|
+
const person = NameAndAge.parse({ name: 'Alice', age: 30 });
|
|
212
|
+
// typeof person === { name: string } & { age: number }
|
|
202
213
|
```
|
|
203
214
|
|
|
204
215
|
## Generic Schemas
|
|
@@ -1766,6 +1777,16 @@ const UserSchema = object({
|
|
|
1766
1777
|
const standardSchema = UserSchema['~standard'];
|
|
1767
1778
|
```
|
|
1768
1779
|
|
|
1780
|
+
The `['~standard'].validate()` method returns a `Promise`, supporting both sync
|
|
1781
|
+
and async preprocessors, validators, and error message providers:
|
|
1782
|
+
|
|
1783
|
+
```ts
|
|
1784
|
+
const result = await UserSchema['~standard'].validate(input);
|
|
1785
|
+
if ('issues' in result) {
|
|
1786
|
+
console.error(result.issues[0].message);
|
|
1787
|
+
}
|
|
1788
|
+
```
|
|
1789
|
+
|
|
1769
1790
|
Confirmed integrations: **tRPC**, **TanStack Form**, **React Hook Form**, **T3 Env**, **Hono**, **Elysia**, **next-safe-action**, and 50+ others listed on [standardschema.dev](https://standardschema.dev/).
|
|
1770
1791
|
|
|
1771
1792
|
## Code Quality
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-XPLTW5DI.js";import"../chunk-REYZ7G7J.js";export{a as AnySchemaBuilder,b as any};
|
|
2
2
|
//# sourceMappingURL=AnySchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-KC45JEFL.js";import"../chunk-REYZ7G7J.js";export{a as ArraySchemaBuilder,b as array};
|
|
2
2
|
//# sourceMappingURL=ArraySchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-PQINUGZW.js";import"../chunk-REYZ7G7J.js";export{a as BooleanSchemaBuilder,b as boolean};
|
|
2
2
|
//# sourceMappingURL=BooleanSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-NF4CRFMN.js";import"../chunk-REYZ7G7J.js";export{a as DateSchemaBuilder,b as date};
|
|
2
2
|
//# sourceMappingURL=DateSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-YAOZEA2R.js";import"../chunk-REYZ7G7J.js";export{a as ExternSchemaBuilder,b as extern};
|
|
2
2
|
//# sourceMappingURL=ExternSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-K4ZLXLE2.js";import"../chunk-REYZ7G7J.js";export{a as FunctionSchemaBuilder,b as func};
|
|
2
2
|
//# sourceMappingURL=FunctionSchemaBuilder.js.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type BRAND, type InferType, SchemaBuilder, type ValidationContext, type ValidationResult } from './SchemaBuilder.js';
|
|
2
|
+
type IntersectionSchemaBuilderCreateProps<TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>, R extends boolean = true> = Partial<ReturnType<IntersectionSchemaBuilder<TLeft, TRight, R>['introspect']>>;
|
|
3
|
+
type SchemaIntersection<TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>> = InferType<TLeft> & InferType<TRight>;
|
|
4
|
+
export type IntersectionSchemaValidationResult<T> = ValidationResult<T>;
|
|
5
|
+
export declare class IntersectionSchemaBuilder<TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}> extends SchemaBuilder<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, TRequired, TNullable, THasDefault, TExtensions> {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
static create(props: IntersectionSchemaBuilderCreateProps<any, any>): IntersectionSchemaBuilder<any, any, true, false, undefined, false, {}>;
|
|
11
|
+
protected constructor(props: IntersectionSchemaBuilderCreateProps<TLeft, TRight, TRequired>);
|
|
12
|
+
introspect(): {
|
|
13
|
+
left: TLeft;
|
|
14
|
+
right: TRight;
|
|
15
|
+
type: string;
|
|
16
|
+
isRequired: boolean;
|
|
17
|
+
isNullable: boolean;
|
|
18
|
+
isReadonly: boolean;
|
|
19
|
+
preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>[];
|
|
20
|
+
validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>[];
|
|
21
|
+
requiredValidationErrorMessageProvider: import("./SchemaBuilder.js").ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
|
|
22
|
+
extensions: {
|
|
23
|
+
[x: string]: unknown;
|
|
24
|
+
};
|
|
25
|
+
hasDefault: boolean;
|
|
26
|
+
defaultValue: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | undefined;
|
|
27
|
+
description: string | undefined;
|
|
28
|
+
schemaName: string | undefined;
|
|
29
|
+
hasCatch: boolean;
|
|
30
|
+
catchValue: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | undefined;
|
|
31
|
+
example: unknown;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @override
|
|
35
|
+
*/
|
|
36
|
+
protected get isNullRequiredViolation(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* @inheritdoc
|
|
39
|
+
*/
|
|
40
|
+
hasType<T>(_notUsed?: T): IntersectionSchemaBuilder<TLeft, TRight, true, TNullable, T, THasDefault, TExtensions> & TExtensions;
|
|
41
|
+
/**
|
|
42
|
+
* @inheritdoc
|
|
43
|
+
*/
|
|
44
|
+
clearHasType(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
45
|
+
/**
|
|
46
|
+
* @inheritdoc
|
|
47
|
+
*/
|
|
48
|
+
validate(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>;
|
|
49
|
+
/**
|
|
50
|
+
* @inheritdoc
|
|
51
|
+
*/
|
|
52
|
+
validateAsync(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): Promise<IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>>;
|
|
53
|
+
/**
|
|
54
|
+
* Performs synchronous validation.
|
|
55
|
+
* Validates left schema first, then right schema.
|
|
56
|
+
* Both must pass for the intersection to be valid.
|
|
57
|
+
*/
|
|
58
|
+
protected _validate(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>;
|
|
59
|
+
/**
|
|
60
|
+
* Performs async validation.
|
|
61
|
+
*/
|
|
62
|
+
protected _validateAsync(object: TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType, context?: ValidationContext): Promise<IntersectionSchemaValidationResult<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>>;
|
|
63
|
+
protected createFromProps<TL extends SchemaBuilder<any, any, any, any, any>, TR extends SchemaBuilder<any, any, any, any, any>, TReq extends boolean>(props: IntersectionSchemaBuilderCreateProps<TL, TR, TReq>): this;
|
|
64
|
+
/**
|
|
65
|
+
* @hidden
|
|
66
|
+
*/
|
|
67
|
+
required(errorMessage?: any): IntersectionSchemaBuilder<TLeft, TRight, true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
68
|
+
/**
|
|
69
|
+
* @hidden
|
|
70
|
+
*/
|
|
71
|
+
optional(): IntersectionSchemaBuilder<TLeft, TRight, false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
72
|
+
/**
|
|
73
|
+
* @hidden
|
|
74
|
+
*/
|
|
75
|
+
default(value: (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) | (() => TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType)): IntersectionSchemaBuilder<TLeft, TRight, true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
|
|
76
|
+
/**
|
|
77
|
+
* @hidden
|
|
78
|
+
*/
|
|
79
|
+
clearDefault(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
|
|
80
|
+
/**
|
|
81
|
+
* @hidden
|
|
82
|
+
*/
|
|
83
|
+
brand<TBrand extends string | symbol>(_name?: TBrand): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, (TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType) & {
|
|
84
|
+
readonly [K in BRAND]: TBrand;
|
|
85
|
+
}, THasDefault, TExtensions> & TExtensions;
|
|
86
|
+
/**
|
|
87
|
+
* @hidden
|
|
88
|
+
*/
|
|
89
|
+
readonly(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, TNullable, Readonly<TExplicitType extends undefined ? SchemaIntersection<TLeft, TRight> : TExplicitType>, THasDefault, TExtensions> & TExtensions;
|
|
90
|
+
/**
|
|
91
|
+
* @hidden
|
|
92
|
+
*/
|
|
93
|
+
nullable(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, true, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
94
|
+
/**
|
|
95
|
+
* @hidden
|
|
96
|
+
*/
|
|
97
|
+
notNullable(): IntersectionSchemaBuilder<TLeft, TRight, TRequired, false, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the left side of this intersection.
|
|
100
|
+
*/
|
|
101
|
+
get leftSchema(): TLeft;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the right side of this intersection.
|
|
104
|
+
*/
|
|
105
|
+
get rightSchema(): TRight;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates an intersection schema.
|
|
109
|
+
* The resulting schema validates that the input satisfies both `left` and `right` schemas.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const schema = intersection(
|
|
114
|
+
* object({ name: string() }),
|
|
115
|
+
* object({ age: number() })
|
|
116
|
+
* );
|
|
117
|
+
* // InferType<typeof schema> === { name: string } & { age: number }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @param left - first schema
|
|
121
|
+
* @param right - second schema
|
|
122
|
+
*/
|
|
123
|
+
export declare const intersection: <TLeft extends SchemaBuilder<any, any, any, any, any>, TRight extends SchemaBuilder<any, any, any, any, any>>(left: TLeft, right: TRight) => IntersectionSchemaBuilder<TLeft, TRight>;
|
|
124
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-ELPPAHNO.js";import"../chunk-REYZ7G7J.js";export{a as NumberSchemaBuilder,b as number};
|
|
2
2
|
//# sourceMappingURL=NumberSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-6LSN7NXQ.js";import"../chunk-REYZ7G7J.js";export{a as ObjectSchemaBuilder,b as object};
|
|
2
2
|
//# sourceMappingURL=ObjectSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-XHSBY2QK.js";import"../chunk-6LSN7NXQ.js";import"../chunk-REYZ7G7J.js";export{a as ParseStringSchemaBuilder,b as parseString};
|
|
2
2
|
//# sourceMappingURL=ParseStringSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-JUFZ7PLO.js";import"../chunk-REYZ7G7J.js";export{a as PromiseSchemaBuilder,b as promise};
|
|
2
2
|
//# sourceMappingURL=PromiseSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-XL723XFL.js";import"../chunk-REYZ7G7J.js";export{a as RecordSchemaBuilder,b as record};
|
|
2
2
|
//# sourceMappingURL=RecordSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-ORV2G6ZL.js";import"../chunk-REYZ7G7J.js";export{a as StringSchemaBuilder,b as string};
|
|
2
2
|
//# sourceMappingURL=StringSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-G424M7GI.js";import"../chunk-REYZ7G7J.js";export{a as TupleSchemaBuilder,b as tuple};
|
|
2
2
|
//# sourceMappingURL=TupleSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-C6YQOKWB.js";import"../chunk-REYZ7G7J.js";export{a as UnionSchemaBuilder,b as union};
|
|
2
2
|
//# sourceMappingURL=UnionSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as P,b as w}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as P,b as w}from"./chunk-C6YQOKWB.js";import{a as B,b as R}from"./chunk-K4ZLXLE2.js";import{a as S,b}from"./chunk-ELPPAHNO.js";import{a as g,b as F}from"./chunk-6LSN7NXQ.js";import{a as M,b as A}from"./chunk-JUFZ7PLO.js";import{a as N,b as D}from"./chunk-XL723XFL.js";import{a as _,b as v}from"./chunk-ORV2G6ZL.js";import{a as V,b as C}from"./chunk-G424M7GI.js";import{a as c,b as T}from"./chunk-XPLTW5DI.js";import{a as x,b as p}from"./chunk-KC45JEFL.js";import{a as m,b as E}from"./chunk-PQINUGZW.js";import{a as h,b as f}from"./chunk-NF4CRFMN.js";import{f as u}from"./chunk-REYZ7G7J.js";var d=class o extends u{#e;#n;#t;static create(e){return new o({type:"generic",...e})}constructor(e){super(e),this.#e=e.templateFn,this.#n=e.defaults,this.apply=(...n)=>{if(!this.#e)throw new Error("GenericSchemaBuilder: no template function defined");return this.#e(...n)}}introspect(){return{...super.introspect(),templateFn:this.#e,defaults:this.#n}}#a(){if(!(!this.#e||!this.#n))return this.#t||(this.#t=this.#e(...this.#n)),this.#t}#r(e,n){let{valid:r,transaction:s,errors:i}=e;if(!r)return{valid:r,errors:i};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{valid:!0,object:a};let t=this.#a();return t?t.validate(a,n):{valid:!1,errors:[{message:"This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic()."}]}}async#s(e,n){let{valid:r,transaction:s,errors:i}=e;if(!r)return{valid:r,errors:i};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{valid:!0,object:a};let t=this.#a();return t?await t.validateAsync(a,n):{valid:!1,errors:[{message:"This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic()."}]}}validate(e,n){return super.validate(e,n)}async validateAsync(e,n){return super.validateAsync(e,n)}_validate(e,n){return this.#r(this.preValidateSync(e,n),n)}async _validateAsync(e,n){return this.#s(await super.preValidateAsync(e,n),n)}createFromProps(e){return o.create(e)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}required(e){return super.required(e)}optional(){return super.optional()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}};function j(o,e){let n=e!==void 0?e:o,r=e!==void 0?o:void 0;return d.create({isRequired:!0,templateFn:n,defaults:r})}var y={string:_,number:S,boolean:m,date:h,object:g,array:x,tuple:V,record:N,union:P,func:B,any:c,promise:M,generic:d},q={string:v,number:b,boolean:E,date:f,object:F,array:p,tuple:C,record:D,union:w,func:R,any:T,promise:A,generic:j},ee="__cleverbrush_method_literal_brand__";var ne="__cleverbrush_extra_type_brand__";var G=new Set(["validate","validateAsync","parse","parseAsync","safeParse","safeParseAsync","introspect","optional","required","addPreprocessor","clearPreprocessors","addValidator","clearValidators","hasType","clearHasType","createFromProps","preValidate","preValidateSync","preValidateAsync","getValidationErrorMessage","getValidationErrorMessageSync","assureValidationErrorMessageProvider","withExtension","getExtension"]);function te(o){let e={};for(let n of Object.keys(o)){if(!(n in y))throw new Error(`Unknown builder type "${n}". Valid types: ${Object.keys(y).join(", ")}`);let r=o[n];if(!r||typeof r!="object")throw new Error(`Extension config for "${n}" must be an object of methods`);e[n]={};for(let s of Object.keys(r)){if(G.has(s))throw new Error(`Cannot override reserved method "${s}" on "${n}"`);let i=r[s];if(typeof i!="function")throw new Error(`Extension method "${n}.${s}" must be a function`);e[n][s]=function(...a){let t=i.apply(this,a);return t&&typeof t=="object"&&typeof t.withExtension=="function"&&(typeof t.getExtension!="function"||t.getExtension(s)===void 0)?t.withExtension(s,a.length===1?a[0]:a.length===0?!0:a):t}}}return{config:e}}function ae(...o){let e=new Map;for(let r of o)for(let s of Object.keys(r.config)){e.has(s)||e.set(s,new Map);let i=e.get(s),a=r.config[s];for(let t of Object.keys(a)){if(i.has(t))throw new Error(`Extension method collision: "${t}" is defined by multiple extensions for "${s}"`);i.set(t,a[t])}}let n={};for(let r of Object.keys(y)){let s=e.get(r);if(!s||s.size===0){n[r]=q[r];continue}let i=y[r],a=class extends i{constructor(...t){super(...t)}static create(t){return new a({...t})}createFromProps(t){return a.create(t)}};for(let[t,l]of s)Object.defineProperty(a.prototype,t,{value:l,writable:!0,configurable:!0,enumerable:!1});n[r]=(...t)=>{let l=q[r](...t);return Object.setPrototypeOf(l,a.prototype),l}}return n}export{d as a,j as b,ee as c,ne as d,te as e,ae as f};
|
|
2
|
+
//# sourceMappingURL=chunk-54RHS4F4.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as f,d as k,f as S}from"./chunk-G6HTNXRO.js";var O=class{#e;#t;#n=[];#a=[];get seenValue(){let e=this.#e[f].getValue(this.#t);return e.success?e.value:void 0}get errors(){return this.#n}get isValid(){return this.#n.length===0&&this.getChildErrors().length===0}getChildErrors(){return this.#a}get descriptor(){return this.#e[f]}constructor(e,r,t){if(!b.isValidPropertyDescriptor(e))throw new Error("Invalid property descriptor");this.#e=e,this.#n=Array.isArray(t)?[...t]:[],this.#t=r}addError(e){this.#n.push(e)}addChildError(e){this.#a.push(e)}toJSON(){return{isValid:this.isValid,errors:this.errors}}};var V="must be an object",b=class p extends S{#e={};#t=!1;#n=[];#a=[];[k]=!0;#s=new WeakMap;static create(e){return new p({type:"object",...e})}createFromProps(e){return p.create(e)}constructor(e){super(e),typeof e.properties=="object"&&e.properties&&(this.#e=e.properties,this.#n=Object.keys(e.properties)),typeof e.acceptUnknownProps=="boolean"&&(this.#t=e.acceptUnknownProps),Array.isArray(e.constructorSchemas)&&(this.#a=e.constructorSchemas.filter(r=>r instanceof S))}introspect(){return{...super.introspect(),properties:{...this.#e},acceptUnknownProps:this.#t,constructorSchemas:[...this.#a]}}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}#i(e){p.isValidPropertyDescriptor(e?.context?.rootPropertyDescriptor)||(e.context.rootPropertyDescriptor=p.getPropertiesFor(this)),p.isValidPropertyDescriptor(e.context.currentPropertyDescriptor)||(e.context.currentPropertyDescriptor=e.context.rootPropertyDescriptor),!e.context.rootValidationObject&&e.transaction?.object?.validatedObject&&(e.context.rootValidationObject=e.transaction.object.validatedObject)}preValidateSync(e,r){let t=super.preValidateSync(e,r);return this.#i(t),t}async preValidateAsync(e,r){let t=await super.preValidateAsync(e,r);return this.#i(t),t}#o(e){let{valid:r,context:t,transaction:n,errors:a}=e,s=new WeakMap,y=new Set,{doNotStopOnFirstError:o,rootValidationObject:i}=t,l=t.rootPropertyDescriptor,u=t.currentPropertyDescriptor,P=(h,m,R)=>{if(!p.isValidPropertyDescriptor(h))throw new Error("invalid property descriptor");let g=s.has(h)?s.get(h):null;if(g||(g=new O(h,i),s.set(h,g)),g.addError(m),y.add(g),R&&p.isValidPropertyDescriptor(R)){let j=s.has(R)?s.get(R):null;j||(j=new O(R,i),s.set(R,j)),j.addChildError(g)}},d=(h=>{let m=typeof h=="function"?h(u):u;if(!p.isValidPropertyDescriptor(m))throw new Error("invalid property descriptor");return s.has(m)||s.set(m,new O(m,i)),s.get(m)}),c=()=>[...y].filter(h=>h.errors.length>0),T=e.errors||[],E=h=>{if(typeof h.property=="function"&&p.isValidPropertyDescriptor(u)){let m=h.property(u);if(p.isValidPropertyDescriptor(m)){P(m,h.message,u);return}}p.isValidPropertyDescriptor(u)&&P(u,h.message)};if(!r&&!o&&a){for(let h of a)E(h);return{earlyReturn:!0,result:{valid:r,errors:a,getErrorsFor:d,getInvalidProperties:c}}}if(o&&a)for(let h of a)E(h);let{object:{validatedObject:x}}=n;if(typeof x>"u"&&!this.isRequired||x===null&&(!this.isRequired||this.isNullable))return{earlyReturn:!0,result:{valid:!0,object:n.commit().validatedObject,getErrorsFor:d,getInvalidProperties:c}};if(typeof x!="object"||x===null)return T.length===0&&(T.push({message:V}),P(u,V)),n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}};let w=this.#n,D=Object.keys(x);if(w.length===0){if(D.length===0)return o&&T.length>0?{earlyReturn:!0,result:{valid:!1,errors:T,getErrorsFor:d,getInvalidProperties:c}}:(n&&n.commit().validatedObject,{earlyReturn:!0,result:{valid:!0,object:{},getErrorsFor:d,getInvalidProperties:c}});if(!this.#t){for(let h=0;h<D.length;h++){let m=`unknown property '${D[h]}'`;if(T.push({message:m}),!o)break}return n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}}}return n&&n.commit(),{earlyReturn:!0,result:{valid:!0,object:{...x},getErrorsFor:d,getInvalidProperties:c}}}return{earlyReturn:!1,errors:T,objToValidate:x,propKeys:w,objKeys:D,addErrorFor:P,getErrorsFor:d,getInvalidProperties:c,doNotStopOnFirstError:!!o,rootPropertyDescriptor:l,currentPropertyDescriptor:u,validationTransaction:n}}#p(e,r){let{objToValidate:t,objKeys:n,addErrorFor:a,getErrorsFor:s,getInvalidProperties:y,doNotStopOnFirstError:o,currentPropertyDescriptor:i,validationTransaction:l}=e,u=e.errors,P=!1;for(let{result:d}of r)if(!d.valid&&(P=!0,Array.isArray(d.errors)))for(let c of d.errors)u.push(c);for(let d=0;d<n.length;d++){let c=n[d];if(!(c in this.#e)&&!this.#t){let T=`unknown property '${c}'`;if(u.push({message:T}),a(i,T),!o)return l&&l.rollback(),{valid:!1,errors:[u[0]],getErrorsFor:s,getInvalidProperties:y}}}if(!P&&u.length===0){let d={};for(let{key:c,result:T}of r)d[c]=T.object;if(this.#t)for(let c of n)c in this.#e||(d[c]=t[c]);return{valid:!0,object:d,getErrorsFor:s,getInvalidProperties:y}}for(let{key:d,result:c}of r)if(!c.valid){let T=i[d];if(typeof c.getErrorsFor=="function"&&p.isValidPropertyDescriptor(T)){if(p.#c(c,T,a),Array.isArray(c.__externErrorPropertyNames)&&Array.isArray(c.errors))for(let E of c.errors)a(T,E.message,i)}else if(Array.isArray(c.errors)&&p.isValidPropertyDescriptor(T))for(let E of c.errors)a(T,E.message)}return l.rollback(),{valid:!1,errors:o?u:u[0]?[u[0]]:[],getErrorsFor:s,getInvalidProperties:y}}addValidator(e,r){return super.addValidator(e,r)}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation&&!r?.doNotStopOnFirstError&&!r?.rootPropertyDescriptor){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let t=this;return{valid:!0,object:e,getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else{let t=this;return{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}],getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else if(typeof e=="object"){let t=this.#n;if(!this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)if(!(s[y]in this.#e)){let o=this;return{valid:!1,errors:[{message:`unknown property '${s[y]}'`}],getErrorsFor(i){return o.#r(e,r).getErrorsFor(i)},getInvalidProperties(){return o.#r(e,r).getInvalidProperties()}}}}let n={};for(let s=0;s<t.length;s++){let y=t[s],o=this.#e[y].validate(e[y]);if(!o.valid){let i=this;return{valid:!1,errors:o.errors&&o.errors.length>0?[o.errors[0]]:[],getErrorsFor(l){return i.#r(e,r).getErrorsFor(l)},getInvalidProperties(){return i.#r(e,r).getInvalidProperties()}}}n[y]=o.object}if(this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)s[y]in this.#e||(n[s[y]]=e[s[y]])}let a=this;return{valid:!0,object:n,getErrorsFor(s){return a.#r(e,r).getErrorsFor(s)},getInvalidProperties(){return a.#r(e,r).getInvalidProperties()}}}}return this.#r(e,r)}#r(e,r){let t=this.#o(this.preValidateSync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];for(let l of n){let u=this.#e[l].validate(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid&&!s)break}return this.#p(t,i)}async _validateAsync(e,r){let t=this.#o(await this.preValidateAsync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];if(s){let l=await Promise.all(n.map(async u=>{let P=await this.#e[u].validateAsync(a[u],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[u]});return{key:u,result:P}}));i.push(...l)}else for(let l of n){let u=await this.#e[l].validateAsync(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid)break}return this.#p(t,i)}acceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!0})}notAcceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!1})}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}addConstructor(e){if(!(e instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),constructorSchemas:[...this.#a,e]})}clearConstructors(){return this.createFromProps({...this.introspect(),constructorSchemas:[]})}addProp(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(e in this.#e)throw new Error(`Property ${e} already exists`);if(!(r instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),properties:{...this.introspect().properties,[e]:r}})}optimize(){return this.createFromProps({...this.introspect()})}addProps(e){if(e instanceof p)return this.addProps(e.introspect().properties);if(typeof e!="object")throw new Error("props should be an object");if(e===null)throw new Error("props should not be null");let r={...this.#e};for(let t in e){if(t in this.#e)throw new Error(`property '${t}' already exists`);if(!(e[t]instanceof S))throw new Error(`${t} is not a SchemaBuilder`);r[t]=e[t]}return this.createFromProps({...this.introspect(),properties:r})}omit(e){if(typeof e=="string"){let r=e;if(!r||!(r in this.#e))throw new Error(`property ${r.toString()} does not exists in the schema`);return this.createFromProps({...this.introspect(),properties:(()=>{let t={...this.#e};return delete t[r],t})()})}else if(Array.isArray(e)){let r=e,t=new Map;if(r.forEach(a=>{if(typeof a!="string"||!a)throw new Error("property name must be a string");if(!(a in this.#e))throw new Error(`property ${a.toString()} does not exists in the schema`);t.set(a.toString(),!0)}),t.size===0)throw new Error("please provide at least one property to omit");let n={...this.introspect()};for(let a of t.keys())delete n.properties[a];return this.createFromProps(n)}else if(e instanceof p){let r={...e.introspect().properties},t={...this.introspect()};for(let n in r)n in t.properties&&delete t.properties[n];return this.createFromProps(t)}throw new Error("this parameter type is not supported")}intersect(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");let r=e.introspect().properties,t=this.introspect(),n=Object.keys(t.properties).reduce((a,s)=>(a[s]=s in r?r[s]:t.properties[s],a),{});return this.createFromProps({...this.introspect(),properties:n})}partial(e){if(typeof e>"u"||e===null)return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((r,t)=>(r[t]=this.#e[t].optional(),r),{})});if(Array.isArray(e)){let r=e;if(r.length===0)throw new Error("properties cannot be empty");let t={...this.introspect()};return r.forEach(n=>{if(typeof n!="string")throw new Error("each propery in property list must be as string value");if(!(n in t.properties))throw new Error(`property ${n} does not exists`);t.properties[n]=t.properties[n].optional()}),this.createFromProps(t)}if(typeof e=="string")return this.modifyPropSchema(e,r=>r.optional());throw new Error("expecting string or string[] parameter")}deepPartial(){let e={};for(let r of Object.keys(this.#e)){let t=this.#e[r];t instanceof p?e[r]=t.deepPartial().optional():e[r]=t.optional()}return this.createFromProps({...this.introspect(),properties:e})}pick(e){if(typeof e=="string"){let r=e;if(!r)throw new Error("property cannot be empty");if(!(r in this.#e))throw new Error(`property ${r} does not exists`);return this.createFromProps({...this.introspect(),properties:{[r]:this.#e[r]}})}if(Array.isArray(e)){if(e.length===0)throw new Error("properties must be a non empty erray");let r=e.reduce((t,n)=>{if(typeof n!="string"||!n)throw new Error("each property name must be a non empty string");if(!(n in this.#e))throw new Error(`property ${n} does not exists`);return t[n]=this.#e[n],t},{});return this.createFromProps({...this.introspect(),properties:r})}if(e instanceof p){let t=Object.keys(e.introspect().properties).filter(n=>typeof this.#e[n]<"u");if(t.length===0)throw new Error("there are no common properties in provided schemas");return this.pick(t)}throw new Error("string, array or ObjectSchemaBuilder is expected")}modifyPropSchema(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(!(e in this.#e))throw new Error(`property ${e} does not exists in the schema`);if(typeof r!="function")throw new Error("callback must be a function");let t=r(this.#e[e]);if(!(t instanceof S))throw new Error("callback must return a SchemaBuilder object");let n={...this.introspect()};return n.properties={...n.properties,[e]:t},this.createFromProps(n)}makePropOptional(e){return this.modifyPropSchema(e,r=>r.optional())}makePropRequired(e){return this.modifyPropSchema(e,r=>r.required())}makeAllPropsOptional(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].optional(),e),{})})}makeAllPropsRequired(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].required(),e),{})})}static#y(e,r,t,n,a){let s=e.introspect();if(!s.properties)return{};let y=Object.keys(s.properties);if(y.length===0)return{};typeof r!="function"&&(r=i=>i);let o=B((i,l)=>(t||r)(i,l),n,e,a);for(let i of y){let l=s.properties[i];if(l instanceof p){let u=l.introspect().properties;u&&typeof u=="object"&&Object.keys(u).length>0?o[i]=p.#y(l,(P,d)=>{let c=r(P,d);return c?(d&&!c[i]&&(c[i]={}),c[i]):null},r,i,o[f]):o[i]=B(r,i,l,o[f])}else if(l[k]===!0){let u=B(r,i,l,o[f]),P=(d,c)=>{let T=r(d,c);return T?(c&&!T[i]&&(T[i]={}),T[i]):null};o[i]=q(u,P)}else o[i]=B(r,i,l,o[f])}return o}static getPropertiesFor(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");if(e.#s.has(e))return e.#s.get(e);let r=p.#y(e);return e.#s.set(e,r),r}static isValidPropertyDescriptor(e){return typeof e=="object"&&e!==null&&typeof e[f]=="object"}static#c(e,r,t){let a=p.#l(r).introspect().properties,s;if(a)s=Object.keys(a);else if(Array.isArray(e.__externErrorPropertyNames))s=e.__externErrorPropertyNames;else return;for(let y of s){let o=r[y];if(!p.isValidPropertyDescriptor(o))continue;let i=e.getErrorsFor(()=>o);if(!i.isValid)for(let l of i.errors)t(o,l,r);if(a){let l=a[y];(l instanceof p||l[k]===!0)&&typeof e.getErrorsFor=="function"&&p.isValidPropertyDescriptor(o)&&p.#c(e,o,t)}}}static#l(e){if(!p.isValidPropertyDescriptor(e))throw new Error("descriptor is not a valid property descriptor");return e[f].getSchema()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},v=(p=>b.create({isRequired:!0,properties:p})),B=(p,e,r,t)=>({[f]:{setValue:(n,a,s)=>{let y=p(n,!!s?.createMissingStructure);return y?(typeof e=="string"&&(y[e]=a),!0):!1},getValue:n=>{let a=p(n,!1);return a?typeof e!="string"?{success:!0,value:a}:Object.hasOwn(a,e)?{success:!0,value:a[e]}:{success:!1}:{success:!1}},getSchema:()=>r,parent:t,propertyName:e,toJsonPointer:()=>{let n=[];typeof e=="string"&&n.push(e.replace(/~/g,"~0").replace(/\//g,"~1"));let a=t;for(;a;)typeof a.propertyName=="string"&&n.push(a.propertyName.replace(/~/g,"~0").replace(/\//g,"~1")),a=a.parent;return n.reverse(),n.length>0?"/"+n.join("/"):""}}}),q=(p,e)=>new Proxy(p,{get(r,t,n){if(t===f)return r[f];if(typeof t=="string"&&!(t in r)){let a=B(e,t,void 0,r[f]),s=(y,o)=>{let i=e(y,o);return i!=null&&typeof i=="object"?(o&&!(t in i)&&(i[t]={}),i[t]):null};r[t]=q(a,s)}return Reflect.get(r,t,n)}});v.getPropertiesFor=p=>b.getPropertiesFor(p);v.isValidPropertyDescriptor=b.isValidPropertyDescriptor;export{b as a,v as b};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as f,d as k,f as S}from"./chunk-REYZ7G7J.js";var O=class{#e;#t;#n=[];#a=[];get seenValue(){let e=this.#e[f].getValue(this.#t);return e.success?e.value:void 0}get errors(){return this.#n}get isValid(){return this.#n.length===0&&this.getChildErrors().length===0}getChildErrors(){return this.#a}get descriptor(){return this.#e[f]}constructor(e,r,t){if(!b.isValidPropertyDescriptor(e))throw new Error("Invalid property descriptor");this.#e=e,this.#n=Array.isArray(t)?[...t]:[],this.#t=r}addError(e){this.#n.push(e)}addChildError(e){this.#a.push(e)}toJSON(){return{isValid:this.isValid,errors:this.errors}}};var V="must be an object",b=class p extends S{#e={};#t=!1;#n=[];#a=[];[k]=!0;#s=new WeakMap;static create(e){return new p({type:"object",...e})}createFromProps(e){return p.create(e)}constructor(e){super(e),typeof e.properties=="object"&&e.properties&&(this.#e=e.properties,this.#n=Object.keys(e.properties)),typeof e.acceptUnknownProps=="boolean"&&(this.#t=e.acceptUnknownProps),Array.isArray(e.constructorSchemas)&&(this.#a=e.constructorSchemas.filter(r=>r instanceof S))}introspect(){return{...super.introspect(),properties:{...this.#e},acceptUnknownProps:this.#t,constructorSchemas:[...this.#a]}}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}#i(e){p.isValidPropertyDescriptor(e?.context?.rootPropertyDescriptor)||(e.context.rootPropertyDescriptor=p.getPropertiesFor(this)),p.isValidPropertyDescriptor(e.context.currentPropertyDescriptor)||(e.context.currentPropertyDescriptor=e.context.rootPropertyDescriptor),!e.context.rootValidationObject&&e.transaction?.object?.validatedObject&&(e.context.rootValidationObject=e.transaction.object.validatedObject)}preValidateSync(e,r){let t=super.preValidateSync(e,r);return this.#i(t),t}async preValidateAsync(e,r){let t=await super.preValidateAsync(e,r);return this.#i(t),t}#o(e){let{valid:r,context:t,transaction:n,errors:a}=e,s=new WeakMap,y=new Set,{doNotStopOnFirstError:o,rootValidationObject:i}=t,l=t.rootPropertyDescriptor,u=t.currentPropertyDescriptor,P=(h,m,R)=>{if(!p.isValidPropertyDescriptor(h))throw new Error("invalid property descriptor");let g=s.has(h)?s.get(h):null;if(g||(g=new O(h,i),s.set(h,g)),g.addError(m),y.add(g),R&&p.isValidPropertyDescriptor(R)){let j=s.has(R)?s.get(R):null;j||(j=new O(R,i),s.set(R,j)),j.addChildError(g)}},d=(h=>{let m=typeof h=="function"?h(u):u;if(!p.isValidPropertyDescriptor(m))throw new Error("invalid property descriptor");return s.has(m)||s.set(m,new O(m,i)),s.get(m)}),c=()=>[...y].filter(h=>h.errors.length>0),T=e.errors||[],E=h=>{if(typeof h.property=="function"&&p.isValidPropertyDescriptor(u)){let m=h.property(u);if(p.isValidPropertyDescriptor(m)){P(m,h.message,u);return}}p.isValidPropertyDescriptor(u)&&P(u,h.message)};if(!r&&!o&&a){for(let h of a)E(h);return{earlyReturn:!0,result:{valid:r,errors:a,getErrorsFor:d,getInvalidProperties:c}}}if(o&&a)for(let h of a)E(h);let{object:{validatedObject:x}}=n;if(typeof x>"u"&&!this.isRequired||x===null&&(!this.isRequired||this.isNullable))return{earlyReturn:!0,result:{valid:!0,object:n.commit().validatedObject,getErrorsFor:d,getInvalidProperties:c}};if(typeof x!="object"||x===null)return T.length===0&&(T.push({message:V}),P(u,V)),n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}};let w=this.#n,D=Object.keys(x);if(w.length===0){if(D.length===0)return o&&T.length>0?{earlyReturn:!0,result:{valid:!1,errors:T,getErrorsFor:d,getInvalidProperties:c}}:(n&&n.commit().validatedObject,{earlyReturn:!0,result:{valid:!0,object:{},getErrorsFor:d,getInvalidProperties:c}});if(!this.#t){for(let h=0;h<D.length;h++){let m=`unknown property '${D[h]}'`;if(T.push({message:m}),!o)break}return n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}}}return n&&n.commit(),{earlyReturn:!0,result:{valid:!0,object:{...x},getErrorsFor:d,getInvalidProperties:c}}}return{earlyReturn:!1,errors:T,objToValidate:x,propKeys:w,objKeys:D,addErrorFor:P,getErrorsFor:d,getInvalidProperties:c,doNotStopOnFirstError:!!o,rootPropertyDescriptor:l,currentPropertyDescriptor:u,validationTransaction:n}}#p(e,r){let{objToValidate:t,objKeys:n,addErrorFor:a,getErrorsFor:s,getInvalidProperties:y,doNotStopOnFirstError:o,currentPropertyDescriptor:i,validationTransaction:l}=e,u=e.errors,P=!1;for(let{result:d}of r)if(!d.valid&&(P=!0,Array.isArray(d.errors)))for(let c of d.errors)u.push(c);for(let d=0;d<n.length;d++){let c=n[d];if(!(c in this.#e)&&!this.#t){let T=`unknown property '${c}'`;if(u.push({message:T}),a(i,T),!o)return l&&l.rollback(),{valid:!1,errors:[u[0]],getErrorsFor:s,getInvalidProperties:y}}}if(!P&&u.length===0){let d={};for(let{key:c,result:T}of r)d[c]=T.object;if(this.#t)for(let c of n)c in this.#e||(d[c]=t[c]);return{valid:!0,object:d,getErrorsFor:s,getInvalidProperties:y}}for(let{key:d,result:c}of r)if(!c.valid){let T=i[d];if(typeof c.getErrorsFor=="function"&&p.isValidPropertyDescriptor(T)){if(p.#c(c,T,a),Array.isArray(c.__externErrorPropertyNames)&&Array.isArray(c.errors))for(let E of c.errors)a(T,E.message,i)}else if(Array.isArray(c.errors)&&p.isValidPropertyDescriptor(T))for(let E of c.errors)a(T,E.message)}return l.rollback(),{valid:!1,errors:o?u:u[0]?[u[0]]:[],getErrorsFor:s,getInvalidProperties:y}}addValidator(e,r){return super.addValidator(e,r)}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation&&!r?.doNotStopOnFirstError&&!r?.rootPropertyDescriptor){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let t=this;return{valid:!0,object:e,getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else{let t=this;return{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}],getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else if(typeof e=="object"){let t=this.#n;if(!this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)if(!(s[y]in this.#e)){let o=this;return{valid:!1,errors:[{message:`unknown property '${s[y]}'`}],getErrorsFor(i){return o.#r(e,r).getErrorsFor(i)},getInvalidProperties(){return o.#r(e,r).getInvalidProperties()}}}}let n={};for(let s=0;s<t.length;s++){let y=t[s],o=this.#e[y].validate(e[y]);if(!o.valid){let i=this;return{valid:!1,errors:o.errors&&o.errors.length>0?[o.errors[0]]:[],getErrorsFor(l){return i.#r(e,r).getErrorsFor(l)},getInvalidProperties(){return i.#r(e,r).getInvalidProperties()}}}n[y]=o.object}if(this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)s[y]in this.#e||(n[s[y]]=e[s[y]])}let a=this;return{valid:!0,object:n,getErrorsFor(s){return a.#r(e,r).getErrorsFor(s)},getInvalidProperties(){return a.#r(e,r).getInvalidProperties()}}}}return this.#r(e,r)}#r(e,r){let t=this.#o(this.preValidateSync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];for(let l of n){let u=this.#e[l].validate(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid&&!s)break}return this.#p(t,i)}async _validateAsync(e,r){let t=this.#o(await this.preValidateAsync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];if(s){let l=await Promise.all(n.map(async u=>{let P=await this.#e[u].validateAsync(a[u],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[u]});return{key:u,result:P}}));i.push(...l)}else for(let l of n){let u=await this.#e[l].validateAsync(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid)break}return this.#p(t,i)}acceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!0})}notAcceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!1})}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}addConstructor(e){if(!(e instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),constructorSchemas:[...this.#a,e]})}clearConstructors(){return this.createFromProps({...this.introspect(),constructorSchemas:[]})}addProp(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(e in this.#e)throw new Error(`Property ${e} already exists`);if(!(r instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),properties:{...this.introspect().properties,[e]:r}})}optimize(){return this.createFromProps({...this.introspect()})}addProps(e){if(e instanceof p)return this.addProps(e.introspect().properties);if(typeof e!="object")throw new Error("props should be an object");if(e===null)throw new Error("props should not be null");let r={...this.#e};for(let t in e){if(t in this.#e)throw new Error(`property '${t}' already exists`);if(!(e[t]instanceof S))throw new Error(`${t} is not a SchemaBuilder`);r[t]=e[t]}return this.createFromProps({...this.introspect(),properties:r})}omit(e){if(typeof e=="string"){let r=e;if(!r||!(r in this.#e))throw new Error(`property ${r.toString()} does not exists in the schema`);return this.createFromProps({...this.introspect(),properties:(()=>{let t={...this.#e};return delete t[r],t})()})}else if(Array.isArray(e)){let r=e,t=new Map;if(r.forEach(a=>{if(typeof a!="string"||!a)throw new Error("property name must be a string");if(!(a in this.#e))throw new Error(`property ${a.toString()} does not exists in the schema`);t.set(a.toString(),!0)}),t.size===0)throw new Error("please provide at least one property to omit");let n={...this.introspect()};for(let a of t.keys())delete n.properties[a];return this.createFromProps(n)}else if(e instanceof p){let r={...e.introspect().properties},t={...this.introspect()};for(let n in r)n in t.properties&&delete t.properties[n];return this.createFromProps(t)}throw new Error("this parameter type is not supported")}intersect(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");let r=e.introspect().properties,t=this.introspect(),n=Object.keys(t.properties).reduce((a,s)=>(a[s]=s in r?r[s]:t.properties[s],a),{});return this.createFromProps({...this.introspect(),properties:n})}partial(e){if(typeof e>"u"||e===null)return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((r,t)=>(r[t]=this.#e[t].optional(),r),{})});if(Array.isArray(e)){let r=e;if(r.length===0)throw new Error("properties cannot be empty");let t={...this.introspect()};return r.forEach(n=>{if(typeof n!="string")throw new Error("each propery in property list must be as string value");if(!(n in t.properties))throw new Error(`property ${n} does not exists`);t.properties[n]=t.properties[n].optional()}),this.createFromProps(t)}if(typeof e=="string")return this.modifyPropSchema(e,r=>r.optional());throw new Error("expecting string or string[] parameter")}deepPartial(){let e={};for(let r of Object.keys(this.#e)){let t=this.#e[r];t instanceof p?e[r]=t.deepPartial().optional():e[r]=t.optional()}return this.createFromProps({...this.introspect(),properties:e})}pick(e){if(typeof e=="string"){let r=e;if(!r)throw new Error("property cannot be empty");if(!(r in this.#e))throw new Error(`property ${r} does not exists`);return this.createFromProps({...this.introspect(),properties:{[r]:this.#e[r]}})}if(Array.isArray(e)){if(e.length===0)throw new Error("properties must be a non empty erray");let r=e.reduce((t,n)=>{if(typeof n!="string"||!n)throw new Error("each property name must be a non empty string");if(!(n in this.#e))throw new Error(`property ${n} does not exists`);return t[n]=this.#e[n],t},{});return this.createFromProps({...this.introspect(),properties:r})}if(e instanceof p){let t=Object.keys(e.introspect().properties).filter(n=>typeof this.#e[n]<"u");if(t.length===0)throw new Error("there are no common properties in provided schemas");return this.pick(t)}throw new Error("string, array or ObjectSchemaBuilder is expected")}modifyPropSchema(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(!(e in this.#e))throw new Error(`property ${e} does not exists in the schema`);if(typeof r!="function")throw new Error("callback must be a function");let t=r(this.#e[e]);if(!(t instanceof S))throw new Error("callback must return a SchemaBuilder object");let n={...this.introspect()};return n.properties={...n.properties,[e]:t},this.createFromProps(n)}makePropOptional(e){return this.modifyPropSchema(e,r=>r.optional())}makePropRequired(e){return this.modifyPropSchema(e,r=>r.required())}makeAllPropsOptional(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].optional(),e),{})})}makeAllPropsRequired(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].required(),e),{})})}static#y(e,r,t,n,a){let s=e.introspect();if(!s.properties)return{};let y=Object.keys(s.properties);if(y.length===0)return{};typeof r!="function"&&(r=i=>i);let o=B((i,l)=>(t||r)(i,l),n,e,a);for(let i of y){let l=s.properties[i];if(l instanceof p){let u=l.introspect().properties;u&&typeof u=="object"&&Object.keys(u).length>0?o[i]=p.#y(l,(P,d)=>{let c=r(P,d);return c?(d&&!c[i]&&(c[i]={}),c[i]):null},r,i,o[f]):o[i]=B(r,i,l,o[f])}else if(l[k]===!0){let u=B(r,i,l,o[f]),P=(d,c)=>{let T=r(d,c);return T?(c&&!T[i]&&(T[i]={}),T[i]):null};o[i]=q(u,P)}else o[i]=B(r,i,l,o[f])}return o}static getPropertiesFor(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");if(e.#s.has(e))return e.#s.get(e);let r=p.#y(e);return e.#s.set(e,r),r}static isValidPropertyDescriptor(e){return typeof e=="object"&&e!==null&&typeof e[f]=="object"}static#c(e,r,t){let a=p.#l(r).introspect().properties,s;if(a)s=Object.keys(a);else if(Array.isArray(e.__externErrorPropertyNames))s=e.__externErrorPropertyNames;else return;for(let y of s){let o=r[y];if(!p.isValidPropertyDescriptor(o))continue;let i=e.getErrorsFor(()=>o);if(!i.isValid)for(let l of i.errors)t(o,l,r);if(a){let l=a[y];(l instanceof p||l[k]===!0)&&typeof e.getErrorsFor=="function"&&p.isValidPropertyDescriptor(o)&&p.#c(e,o,t)}}}static#l(e){if(!p.isValidPropertyDescriptor(e))throw new Error("descriptor is not a valid property descriptor");return e[f].getSchema()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},v=(p=>b.create({isRequired:!0,properties:p})),B=(p,e,r,t)=>({[f]:{setValue:(n,a,s)=>{let y=p(n,!!s?.createMissingStructure);return y?(typeof e=="string"&&(y[e]=a),!0):!1},getValue:n=>{let a=p(n,!1);return a?typeof e!="string"?{success:!0,value:a}:Object.hasOwn(a,e)?{success:!0,value:a[e]}:{success:!1}:{success:!1}},getSchema:()=>r,parent:t,propertyName:e,toJsonPointer:()=>{let n=[];typeof e=="string"&&n.push(e.replace(/~/g,"~0").replace(/\//g,"~1"));let a=t;for(;a;)typeof a.propertyName=="string"&&n.push(a.propertyName.replace(/~/g,"~0").replace(/\//g,"~1")),a=a.parent;return n.reverse(),n.length>0?"/"+n.join("/"):""}}}),q=(p,e)=>new Proxy(p,{get(r,t,n){if(t===f)return r[f];if(typeof t=="string"&&!(t in r)){let a=B(e,t,void 0,r[f]),s=(y,o)=>{let i=e(y,o);return i!=null&&typeof i=="object"?(o&&!(t in i)&&(i[t]={}),i[t]):null};r[t]=q(a,s)}return Reflect.get(r,t,n)}});v.getPropertiesFor=p=>b.getPropertiesFor(p);v.isValidPropertyDescriptor=b.isValidPropertyDescriptor;export{b as a,v as b};
|
|
2
|
+
//# sourceMappingURL=chunk-6LSN7NXQ.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as h,e as m,f as c}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as h,e as m,f as c}from"./chunk-REYZ7G7J.js";var f=class T extends c{#e;#n=null;#t=null;static create(e){return new T({type:"union",...e})}constructor(e){super(e),Array.isArray(e.options)&&(this.#e=e.options,this.#o())}#o(){let e=this.#e;if(!e||e.length<2)return;let n=[];for(let s of e){let t=s.introspect();if(t.type!=="object")return;n.push(t)}let i=n[0].properties;if(i)for(let s of Object.keys(i)){let t=new Map,a=!0;for(let o=0;o<n.length;o++){let d=n[o].properties;if(!d||!(s in d)){a=!1;break}let r=d[s].introspect();if(r.isRequired!==!0){a=!1;break}let l=r.equalsTo;if(l==null){a=!1;break}if(typeof l!="string"&&typeof l!="number"){a=!1;break}if(t.has(l)){a=!1;break}t.set(l,e[o])}if(a&&t.size===e.length){this.#n=s,this.#t=t;return}}}introspect(){return{...super.introspect(),options:this.#e,discriminatorPropertyName:this.#n??void 0}}get isNullRequiredViolation(){return!1}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#r(e,n){let{valid:i,transaction:s,context:t,errors:a}=n,o={[h]:{setValue:()=>!1,getValue:u=>({success:!0,value:u}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},d=[],y=m([],()=>e,()=>d,()=>o[h]),r=(()=>y);if(!i)return d.push(...(a||[]).map(u=>u.message||String(u))),{needsOptionValidation:!1,result:{valid:i,errors:a,getNestedErrors:r}};let{object:{validatedObject:l}}=s;return typeof l>"u"&&!this.isRequired||l===null&&(!this.isRequired||this.isNullable)?{needsOptionValidation:!1,result:{valid:!0,object:l,getNestedErrors:r}}:{needsOptionValidation:!0,objToValidate:l,prevalidationContext:t,preValidationTransaction:s,getNestedErrors:r,optionResults:y,rootErrors:d}}#s(e,n,i,s,t,a){if(i[n]=e,e.valid)return{valid:!0,object:e.object,getNestedErrors:a};let o=e.errors;return Array.isArray(o)&&o.length>0&&o.length<t.minErrorsCount&&(t.resultingErrors=o,t.minErrorsCount=o.length),t.objToValidate=s.rollback().validatedObject,null}validate(e,n){return super.validate(e,n)}async validateAsync(e,n){return super.validateAsync(e,n)}_validate(e,n){if(this.canSkipPreValidation&&!n?.doNotStopOnFirstError&&!n?.rootPropertyDescriptor){if(typeof e>"u")if(this.hasDefault)e=this.resolveDefaultValue();else return this.isRequired?this.#i(!1,void 0,[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}],e,n):this.#i(!0,e,void 0,e,n);else if(e===null&&(!this.isRequired||this.isNullable))return this.#i(!0,e,void 0,e,n);if(this.#n&&this.#t&&typeof e=="object"&&e!==null){let i=e[this.#n],s=this.#t.get(i);if(s){let t=s.validate(e);return this.#i(t.valid,t.valid?t.object:void 0,t.valid?void 0:t.errors,e,n)}return this.#i(!1,void 0,[{message:"value doesn't match any option in union schema"}],e,n)}if(!this.#n){let i=this.#e,s=Number.MAX_SAFE_INTEGER,t=[];for(let a=0;a<i.length;a++){let o=i[a].validate(e);if(o.valid)return this.#i(!0,o.object,void 0,e,n);let d=o.errors;Array.isArray(d)&&d.length>0&&d.length<s&&(t=d,s=d.length)}return this.#i(!1,void 0,t,e,n)}}return this.#a(e,n)}#i(e,n,i,s,t){let a=this;return e?{valid:!0,object:n,getNestedErrors(){return a.#a(s,t).getNestedErrors()}}:{valid:!1,errors:i,getNestedErrors(){return a.#a(s,t).getNestedErrors()}}}#a(e,n){let i=this.#r(e,this.preValidateSync(e,n));if(!i.needsOptionValidation)return i.result;let{prevalidationContext:s,preValidationTransaction:t,getNestedErrors:a,optionResults:o,rootErrors:d}=i;if(this.#n&&this.#t){let r=i.objToValidate;if(typeof r=="object"&&r!==null){let l=r[this.#n],u=this.#t.get(l);if(u){let p=u.validate(r,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0});if(p.valid)return{valid:!0,object:p.object,getNestedErrors:a}}}}let y={objToValidate:i.objToValidate,minErrorsCount:Number.MAX_SAFE_INTEGER,resultingErrors:[]};for(let r=0;r<this.#e.length;r++){let l=this.#e[r].validate(y.objToValidate,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0}),u=this.#s(l,r,o,t,y,a);if(u)return u}return d.push("value doesn't match any option in union schema"),{valid:!1,errors:y.resultingErrors,getNestedErrors:a}}async _validateAsync(e,n){let i=this.#r(e,await super.preValidateAsync(e,n));if(!i.needsOptionValidation)return i.result;let{prevalidationContext:s,preValidationTransaction:t,getNestedErrors:a,optionResults:o,rootErrors:d}=i;if(this.#n&&this.#t){let r=i.objToValidate;if(typeof r=="object"&&r!==null){let l=r[this.#n],u=this.#t.get(l);if(u){let p=await u.validateAsync(r,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0});if(p.valid)return{valid:!0,object:p.object,getNestedErrors:a}}}}let y={objToValidate:i.objToValidate,minErrorsCount:Number.MAX_SAFE_INTEGER,resultingErrors:[]};for(let r=0;r<this.#e.length;r++){let l=await this.#e[r].validateAsync(y.objToValidate,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0}),u=this.#s(l,r,o,t,y,a);if(u)return u}return d.push("value doesn't match any option in union schema"),{valid:!1,errors:y.resultingErrors,getNestedErrors:a}}createFromProps(e){return T.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}or(e){if(!(e instanceof c))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),options:[...this.#e,e]})}removeOption(e){if(typeof e!="number"||e<0||e>this.#e.length)throw new Error("index must be >= 0 and <= count of the options");return this.createFromProps({...this.introspect(),options:this.#e.filter((n,i)=>i!==e)})}removeFirstOption(){return this.removeOption(0)}reset(e){if(!(e instanceof c))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),options:[e]})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},E=T=>f.create({isRequired:!0,options:[T]});export{f as a,E as b};
|
|
2
|
+
//# sourceMappingURL=chunk-C6YQOKWB.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as l}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as l}from"./chunk-REYZ7G7J.js";var n=class i extends l{#e;#b=function(){return`expected to be at least ${this.#e}`};#a=this.#b;#r;#N=function(){return`expected to be no more than or equal to ${this.#r}`};#u=this.#N;#s;#E=function(){return`expected to be equal to ${this.#s}`};#n=this.#E;#t=!0;#l=function(){return"is not expected to be NaN"};#o=this.#l;#d=!0;#T=function(){return"is expected to be a finite number"};#m=this.#T;#h=!0;#i=function(){return"is expected to be an integer"};#c=this.#i;static create(e){return new i({type:"number",...e})}constructor(e){super(e),typeof e.min=="number"&&(this.#e=e.min),this.#a=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#b),typeof e.max=="number"&&(this.#r=e.max),this.#u=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#N),typeof e.ensureNotNaN=="boolean"&&(this.#t=e.ensureNotNaN),this.#o=this.assureValidationErrorMessageProvider(e.ensureNotNaNErrorMessageProvider,this.#l),typeof e.ensureIsFinite=="boolean"&&(this.#d=e.ensureIsFinite),this.#m=this.assureValidationErrorMessageProvider(e.ensureIsFiniteErrorMessageProvider,this.#T),typeof e.isInteger=="boolean"&&(this.#h=e.isInteger),this.#c=this.assureValidationErrorMessageProvider(e.ensureIsIntegerErrorMessageProvider,this.#i),(typeof e.equalsTo=="number"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#n=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#E)}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#a,max:this.#r,maxValidationErrorMessageProvider:this.#u,ensureNotNaN:this.#t,ensureNotNaNErrorMessageProvider:this.#o,ensureIsFinite:this.#d,ensureIsFiniteErrorMessageProvider:this.#m,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#n,isInteger:this.#h,ensureIsIntegerErrorMessageProvider:this.#c,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#f(e){return typeof e!="number"?{message:`expected type number, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#n}:this.#t&&Number.isNaN(e)?{provider:this.#o}:this.#d&&!Number.isFinite(e)&&this.#t&&!Number.isNaN(e)?{provider:this.#m}:this.#h&&!Number.isNaN(e)&&Number.isFinite(e)&&!Number.isInteger(e)?{provider:this.#c}:typeof this.#e<"u"&&e<this.#e?{provider:this.#a}:typeof this.#r<"u"&&e>this.#r?{provider:this.#u}:null}#R(e){let{valid:r,transaction:s,errors:t}=e;if(!r)return{done:!0,result:{valid:r,errors:t}};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:a}};let u=this.#f(a);return u?"message"in u?{done:!0,result:{valid:!1,errors:[{message:u.message}]}}:{done:!1,provider:u.provider,objToValidate:a}:{done:!0,result:{valid:!0,object:s.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let t=this.#f(e);return t?"message"in t?{valid:!1,errors:[{message:t.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,e)}]}:{valid:!0,object:e}}let s=this.#R(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#R(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return i.create(e)}equals(e,r){if(typeof e!="number")throw new Error("number expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}isFloat(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}clearIsInteger(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}isInteger(e){return this.createFromProps({...this.introspect(),isInteger:!0,ensureIsIntegerErrorMessageProvider:e})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}notNaN(e){return this.createFromProps({...this.introspect(),ensureNotNaN:!0,ensureNotNaNErrorMessageProvider:e})}canBeNaN(){return this.createFromProps({...this.introspect(),ensureNotNaN:!1,ensureNotNaNErrorMessageProvider:this.#l})}isFinite(e){return this.createFromProps({...this.introspect(),ensureIsFinite:!0,ensureIsFiniteErrorMessageProvider:e})}canBeInfinite(){return this.createFromProps({...this.introspect(),ensureIsFinite:!1,ensureIsFiniteErrorMessageProvider:this.#T})}coerce(){return this.addPreprocessor((e=>typeof e=="string"?Number(e):e),{mutates:!0})}min(e,r){if(typeof e!="number")throw new Error("minValue must be a number");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(typeof e!="number")throw new Error("maxValue must be a number");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}};function d(i){return typeof i=="number"?n.create({isRequired:!0,equalsTo:i}):n.create({isRequired:!0})}export{n as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-ELPPAHNO.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as p,e as f,f as T}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as p,e as f,f as T}from"./chunk-REYZ7G7J.js";var m=class h extends T{#e;#t;static create(e){return new h({type:"tuple",...e})}constructor(e){super(e),Array.isArray(e.elements)?this.#e=e.elements:this.#e=[],e.restSchema instanceof T&&(this.#t=e.restSchema)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#a(e){if(e.length<this.#e.length){let l=this.#e.length;return`expected a tuple with at least ${l} element${l===1?"":"s"}, got ${e.length}`}if(!(this.#t instanceof T)&&e.length!==this.#e.length){let l=this.#e.length;return`expected a tuple of exactly ${l} element${l===1?"":"s"}, got ${e.length}`}return null}#n(e,l){let{valid:o,context:r,errors:a,transaction:n}=l,i={[p]:{setValue:()=>!1,getValue:t=>({success:!0,value:t}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},d=[],y=f([],()=>e,()=>d,()=>i[p]),c=(()=>y);if(!o)return d.push(...(a||[]).map(t=>t.message||String(t))),{needsElementValidation:!1,result:{valid:o,errors:a,getNestedErrors:c}};let{object:{validatedObject:u}}=n;return typeof u>"u"&&!this.isRequired||u===null&&(!this.isRequired||this.isNullable)?{needsElementValidation:!1,result:{valid:!0,object:u,getNestedErrors:c}}:Array.isArray(u)?{needsElementValidation:!0,objToValidate:u,prevalidationContext:r,getNestedErrors:c,elementResults:y,rootErrors:d}:(d.push("array expected"),{needsElementValidation:!1,result:{valid:!1,errors:[{message:"array expected"}],getNestedErrors:c}})}#r(e,l,o){let r=!0;for(let a=0;a<e.length;a++)e[a]?.valid||(r=!1),l[a]=e[a];return Object.assign({valid:r,getNestedErrors:o},r?{}:{errors:e.map(a=>a?.errors).filter(a=>a).flatMap(a=>a?.map(n=>({...n})))},r?{object:e.map(a=>a?.object)}:{})}validate(e,l){return super.validate(e,l)}async validateAsync(e,l){return super.validateAsync(e,l)}_validate(e,l){if(this.canSkipPreValidation&&!l?.doNotStopOnFirstError){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let n=this;return{valid:!0,object:e,getNestedErrors(){return n.#s(e,l).getNestedErrors()}}}else return this.#s(e,l);if(!Array.isArray(e))return this.#s(e,l);let o=this.#a(e);if(o){let n=this;return{valid:!1,errors:[{message:o}],getNestedErrors(){return n.#s(e,l).getNestedErrors()}}}let r=new Array(e.length);for(let n=0;n<this.#e.length;n++){let i=this.#e[n].validate(e[n]);if(!i.valid){let d=this;return{valid:!1,errors:i.errors&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors(){return d.#s(e,l).getNestedErrors()}}}r[n]=i.object}if(this.#t instanceof T)for(let n=this.#e.length;n<e.length;n++){let i=this.#t.validate(e[n]);if(!i.valid){let d=this;return{valid:!1,errors:i.errors&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors(){return d.#s(e,l).getNestedErrors()}}}r[n]=i.object}let a=this;return{valid:!0,object:r,getNestedErrors(){return a.#s(e,l).getNestedErrors()}}}return this.#s(e,l)}#s(e,l){let o=this.#n(e,this.preValidateSync(e,l));if(!o.needsElementValidation)return o.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:n,elementResults:i,rootErrors:d}=o,y=this.#a(r);if(y)return d.push(y),{valid:!1,errors:[{message:y}],getNestedErrors:n};let c=this.#t instanceof T?r.length:this.#e.length;if(a.doNotStopOnFirstError){let u=new Array(c);for(let t=0;t<this.#e.length;t++)u[t]=this.#e[t].validate(r[t],{...a});if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++)u[t]=this.#t.validate(r[t],{...a});return this.#r(u,i,n)}else{let u=new Array(c);for(let t=0;t<this.#e.length;t++){let s=this.#e[t].validate(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++){let s=this.#t.validate(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}return{valid:!0,object:u,getNestedErrors:n}}}async _validateAsync(e,l){let o=this.#n(e,await super.preValidateAsync(e,l));if(!o.needsElementValidation)return o.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:n,elementResults:i,rootErrors:d}=o,y=this.#a(r);if(y)return d.push(y),{valid:!1,errors:[{message:y}],getNestedErrors:n};let c=this.#t instanceof T?r.length:this.#e.length;if(a.doNotStopOnFirstError){let u=new Array(c);for(let s=0;s<this.#e.length;s++)u[s]=this.#e[s].validateAsync(r[s],{...a});if(this.#t instanceof T)for(let s=this.#e.length;s<r.length;s++)u[s]=this.#t.validateAsync(r[s],{...a});let t=await Promise.all(u);return this.#r(t,i,n)}else{let u=new Array(c);for(let t=0;t<this.#e.length;t++){let s=await this.#e[t].validateAsync(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++){let s=await this.#t.validateAsync(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}return{valid:!0,object:u,getNestedErrors:n}}}createFromProps(e){return h.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}introspect(){return{...super.introspect(),elements:this.#e,restSchema:this.#t}}rest(e){return h.create({...this.introspect(),restSchema:e})}clearRest(){return h.create({...this.introspect(),restSchema:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},R=h=>m.create({isRequired:!0,elements:h});export{m as a,R as b};
|
|
2
|
+
//# sourceMappingURL=chunk-G424M7GI.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as i}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as i}from"./chunk-REYZ7G7J.js";var r=class s extends i{#e;static create(e){return new s({type:"promise",...e})}constructor(e){super(e),e.resolvedType instanceof i&&(this.#e=e.resolvedType)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}introspect(){return{...super.introspect(),resolvedType:this.#e}}#a(e){let{valid:a,transaction:n,errors:l}=e;if(!a)return{valid:a,errors:l};let{object:{validatedObject:t}}=n;return typeof t>"u"&&!this.isRequired||t===null&&(!this.isRequired||this.isNullable)?{valid:!0,object:t}:t==null||typeof t.then!="function"?{valid:!1,errors:[{message:`expected a Promise, but saw ${t===null?"null":typeof t}`}]}:{valid:!0,object:t}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){return this.#a(this.preValidateSync(e,a))}async _validateAsync(e,a){return this.#a(await super.preValidateAsync(e,a))}createFromProps(e){return s.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}hasResolvedType(e){return this.createFromProps({...this.introspect(),resolvedType:e})}};function o(s){return r.create({isRequired:!0,resolvedType:s})}export{r as a,o as b};
|
|
2
|
+
//# sourceMappingURL=chunk-JUFZ7PLO.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as n}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as n}from"./chunk-REYZ7G7J.js";var r=class s extends n{#e=[];#a;static create(e){return new s({type:"function",...e})}constructor(e){super(e),Array.isArray(e.parameters)&&(this.#e=e.parameters.filter(a=>a instanceof n)),e.returnType instanceof n&&(this.#a=e.returnType)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}introspect(){return{...super.introspect(),parameters:[...this.#e],returnType:this.#a}}#t(e){let{valid:a,transaction:i,errors:u}=e;if(!a)return{valid:a,errors:u};let{object:{validatedObject:t}}=i;return typeof t>"u"&&!this.isRequired||t===null&&(!this.isRequired||this.isNullable)?{valid:!0,object:t}:typeof t!="function"?{valid:!1,errors:[{message:`expected type function, but saw ${typeof t}`}]}:{valid:!0,object:t}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){return this.#t(this.preValidateSync(e,a))}async _validateAsync(e,a){return this.#t(await super.preValidateAsync(e,a))}createFromProps(e){return s.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}nullable(){return super.nullable()}addParameter(e){return this.createFromProps({...this.introspect(),parameters:[...this.#e,e]})}hasReturnType(e){return this.createFromProps({...this.introspect(),returnType:e})}notNullable(){return super.notNullable()}},T=()=>r.create({isRequired:!0});export{r as a,T as b};
|
|
2
|
+
//# sourceMappingURL=chunk-K4ZLXLE2.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as T,e as p,f as h}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as T,e as p,f as h}from"./chunk-REYZ7G7J.js";var y=class m extends h{#r;#l=function(){return`is expected to have no less than ${this.#r} elements`};#n=this.#l;#t;#u=function(){return`is expected to have no more than ${this.#t} elements`};#s=this.#u;#e;static create(e){return new m({type:"array",...e})}constructor(e){super(e),typeof e.minLength=="number"&&(this.#r=e.minLength),this.#n=this.assureValidationErrorMessageProvider(e.minLengthValidationErrorMessageProvider,this.#l),typeof e.maxLength=="number"&&(this.#t=e.maxLength),this.#s=this.assureValidationErrorMessageProvider(e.maxLengthValidationErrorMessageProvider,this.#u),e.elementSchema instanceof h&&(this.#e=e.elementSchema)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#o(e,t){let{valid:u,context:r,errors:a,transaction:l}=t,d={[T]:{setValue:()=>!1,getValue:i=>({success:!0,value:i}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},o=[],c=p([],()=>e,()=>o,()=>d[T]),s=(()=>c);if(!u)return o.push(...(a||[]).map(i=>i.message||String(i))),{needsElementValidation:!1,result:{valid:u,errors:a,getNestedErrors:s}};let{object:{validatedObject:n}}=l;return typeof n>"u"&&!this.isRequired||n===null&&(!this.isRequired||this.isNullable)?{needsElementValidation:!1,result:{valid:!0,object:n,getNestedErrors:s}}:Array.isArray(n)?{needsElementValidation:!0,objToValidate:n,prevalidationContext:r,getNestedErrors:s,elementResults:c,rootErrors:o}:(o.push("array expected"),{needsElementValidation:!1,result:{valid:!1,errors:[{message:"array expected"}],getNestedErrors:s}})}#i(e){return typeof this.#t=="number"&&e.length>this.#t?{provider:this.#s}:typeof this.#r=="number"&&e.length<this.#r?{provider:this.#n}:null}#d(e,t,u){let r=!0;for(let a=0;a<e.length;a++)e[a]?.valid||(r=!1),t[a]=e[a];return Object.assign({valid:r,getNestedErrors:u},r?{}:{errors:e.map(a=>a?.errors).filter(a=>a).flatMap(a=>a?.map(l=>({...l})))},r?{object:e.map(a=>a?.object)}:{})}validate(e,t){return super.validate(e,t)}async validateAsync(e,t){return super.validateAsync(e,t)}_validate(e,t){if(this.canSkipPreValidation&&!t?.doNotStopOnFirstError&&this.#e instanceof h){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let a=this;return{valid:!0,object:e,getNestedErrors(){return a.#a(e,t).getNestedErrors()}}}else return this.#a(e,t);if(!Array.isArray(e))return this.#a(e,t);if(this.#i(e))return this.#a(e,t);let u=e.length;if(u>0){let a=new Array(u);for(let d=0;d<u;d++){let o=this.#e.validate(e[d]);if(!o.valid){let c=this;return{valid:!1,errors:o.errors&&o.errors.length>0?[o.errors[0]]:[],getNestedErrors(){return c.#a(e,t).getNestedErrors()}}}a[d]=o.object}let l=this;return{valid:!0,object:a,getNestedErrors(){return l.#a(e,t).getNestedErrors()}}}let r=this;return{valid:!0,object:e,getNestedErrors(){return r.#a(e,t).getNestedErrors()}}}return this.#a(e,t)}#a(e,t){let u=this.#o(e,this.preValidateSync(e,t));if(!u.needsElementValidation)return u.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:l,elementResults:d,rootErrors:o}=u,c=this.#i(r);if(c){let s=this.getValidationErrorMessageSync(c.provider,r);return o.push(s),{valid:!1,errors:[{message:s}],getNestedErrors:l}}if(r.length>0&&this.#e instanceof h)if(a.doNotStopOnFirstError){let s=[];for(let n=0;n<r.length;n++)s.push(this.#e.validate(r[n],{...a}));return this.#d(s,d,l)}else{let s=new Array(r.length);for(let n=0;n<r.length;n++){let i=this.#e.validate(r[n],{...a});if(d[n]=i,i.valid)s[n]=i.object;else return{valid:!1,errors:Array.isArray(i.errors)&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors:l}}return{valid:!0,object:s,getNestedErrors:l}}return{valid:!0,object:r,getNestedErrors:l}}async _validateAsync(e,t){let u=this.#o(e,await super.preValidateAsync(e,t));if(!u.needsElementValidation)return u.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:l,elementResults:d,rootErrors:o}=u,c=this.#i(r);if(c){let s=await this.getValidationErrorMessage(c.provider,r);return o.push(s),{valid:!1,errors:[{message:s}],getNestedErrors:l}}if(r.length>0&&this.#e instanceof h)if(a.doNotStopOnFirstError){let s=await Promise.all(r.map(n=>this.#e?.validateAsync(n,a)));return this.#d(s,d,l)}else{let s=new Array(r.length);for(let n=0;n<r.length;n++){let i=await this.#e.validateAsync(r[n],{...a});if(d[n]=i,i.valid)s[n]=i.object;else return{valid:!1,errors:Array.isArray(i.errors)&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors:l}}return{valid:!0,object:s,getNestedErrors:l}}return{valid:!0,object:r,getNestedErrors:l}}createFromProps(e){return m.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}introspect(){return{...super.introspect(),elementSchema:this.#e,minLength:this.#r,minLengthValidationErrorMessageProvider:this.#n,maxLength:this.#t,maxLengthValidationErrorMessageProvider:this.#s}}of(e){return m.create({...this.introspect(),elementSchema:e})}clearOf(){return m.create({...this.introspect(),elementSchema:void 0})}minLength(e,t){if(typeof e!="number"||e<0)throw new Error("length is expected to be a number which is >= 0");return m.create({...this.introspect(),minLength:e,minLengthValidationErrorMessageProvider:t})}clearMinLength(){let e=this.introspect();return delete e.minLength,this.createFromProps({...e})}maxLength(e,t){if(typeof e!="number"||e<0)throw new Error("length is expected to be a number which is >= 0");return m.create({...this.introspect(),maxLength:e,maxLengthValidationErrorMessageProvider:t})}clearMaxLength(){let e=this.introspect();return delete e.maxLength,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},S=m=>y.create({isRequired:!0,elementSchema:m});export{y as a,S as b};
|
|
2
|
+
//# sourceMappingURL=chunk-KC45JEFL.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as u,f as l}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as u,f as l}from"./chunk-REYZ7G7J.js";var d=t=>{if(typeof t>"u")return t;if(typeof t=="string"){let e=Date.parse(t);return Number.isNaN(e)?t:new Date(e)}return t},T=t=>{if(typeof t>"u")return t;if(typeof t=="number"){let e=new Date(t);return Number.isNaN(e.getTime())?t:e}return t},o=class t extends l{#e;#c=function(){return`is expected to be after ${this.#e} (${this.#e?.getTime()})`};#i=this.#c;#r;#h=function(){return`is expected to be before ${this.#r} (${this.#r?.getTime()})`};#n=this.#h;#t;#m=function(){return`is expected to be equal ${this.#t} (${this.#t?.getTime()})`};#u=this.#m;#o=!1;#f=function(){return"is expected to be in future"};#l=this.#f;#d=!1;#p=function(){return"is expected to be in past"};#T=this.#p;#s=!1;#a=!1;#E=!0;static create(e){return new t({type:"date",...e})}constructor(e){super(e),e.min instanceof Date&&(this.#e=e.min),this.#i=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#c),e.max instanceof Date&&(this.#r=e.max),this.#n=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#h),typeof e.ensureIsInFuture=="boolean"&&(this.#o=e.ensureIsInFuture),this.#l=this.assureValidationErrorMessageProvider(e.ensureIsInFutureValidationErrorMessageProvider,this.#f),typeof e.ensureIsInPast=="boolean"&&(this.#d=e.ensureIsInPast),this.#T=this.assureValidationErrorMessageProvider(e.ensureIsInPastValidationErrorMessageProvider,this.#p),typeof e.parseFromJson=="boolean"&&(this.#s=e.parseFromJson),typeof e.parseFromEpoch=="boolean"&&(this.#a=e.parseFromEpoch),(e.equalsTo instanceof Date||typeof e.equalsTo>"u")&&(this.#t=e.equalsTo),this.#u=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#m),this.#E=this.canSkipPreValidation&&!this.#s&&!this.#a}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#i,max:this.#r,maxValidationErrorMessageProvider:this.#n,ensureIsInFuture:this.#o,ensureIsInFutureValidationErrorMessageProvider:this.#l,ensureIsInPast:this.#d,ensureIsInPastValidationErrorMessageProvider:this.#T,equalsTo:this.#t,equalsToValidationErrorMessageProvider:this.#u,parseFromEpoch:this.#a,parseFromJson:this.#s,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#R(e){return e instanceof Date?typeof this.#t<"u"&&e.getTime()!==this.#t.getTime()?{provider:this.#u}:this.#o&&e<=new Date?{provider:this.#l}:this.#d&&e>=new Date?{provider:this.#T}:typeof this.#e<"u"&&e<this.#e?{provider:this.#i}:typeof this.#r<"u"&&e>this.#r?{provider:this.#n}:null:{message:`expected instance of Date, but saw ${typeof e}`}}#D(e){let{valid:r,errors:s}=e;if(!r)return{done:!0,result:{valid:r,errors:s}};let{transaction:a}=e,{object:{validatedObject:i}}=a;if(typeof i>"u"&&!this.isRequired||i===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:i}};this.#s&&(a=u({validatedObject:d(i)}),i=a.object.validatedObject),this.#a&&(a=u({validatedObject:T(i)}),i=a.object.validatedObject);let n=this.#R(i);return n?"message"in n?{done:!0,result:{valid:!1,errors:[{message:n.message}]}}:{done:!1,provider:n.provider,objToValidate:i}:{done:!0,result:{valid:!0,object:a.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.#E){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let a=this.#R(e);return a?"message"in a?{valid:!1,errors:[{message:a.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(a.provider,e)}]}:{valid:!0,object:e}}let s=this.#D(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#D(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return t.create(e)}equals(e,r){if(!(e instanceof Date))throw new Error("Date expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}isInFuture(e){return this.createFromProps({...this.introspect(),ensureIsInFuture:!0,ensureIsInFutureValidationErrorMessageProvider:e})}clearIsInFuture(){return this.createFromProps({...this.introspect(),ensureIsInFuture:!1})}isInPast(e){return this.createFromProps({...this.introspect(),ensureIsInPast:!0,ensureIsInPastValidationErrorMessageProvider:e})}clearIsInPast(){return this.createFromProps({...this.introspect(),ensureIsInPast:!1})}min(e,r){if(!(e instanceof Date))throw new Error("minValue must be a Date");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(!(e instanceof Date))throw new Error("maxValue must be a Date");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}coerce(){return this.addPreprocessor((e=>{if(typeof e=="string"){let r=new Date(e);return Number.isNaN(r.getTime())?e:r}return e}),{mutates:!0})}acceptJsonString(){return this.createFromProps({...this.introspect(),parseFromJson:!0})}doNotAcceptJsonString(){return this.createFromProps({...this.introspect(),parseFromJson:!1})}acceptEpoch(){return this.createFromProps({...this.introspect(),parseFromEpoch:!0})}doNotAcceptEpoch(){return this.createFromProps({...this.introspect(),parseFromEpoch:!1})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},m=()=>o.create({isRequired:!0});export{o as a,m as b};
|
|
2
|
+
//# sourceMappingURL=chunk-NF4CRFMN.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as o}from"./chunk-REYZ7G7J.js";var l=class a extends o{#t;#T=function(){return`is expected to have a length of at least ${this.#t} characters`};#n=this.#T;#i;#g=function(){return`is expected to have a length of no more than ${this.#i} characters`};#l=this.#g;#s;#c=function(e){return`is expected to be equal to "${this.#s}" but saw "${e}"`};#o=this.#c;#e;#m=function(){return`is expected to start with "${this.#e}"`};#u=this.#m;#r;#E=function(){return`is expected to end with "${this.#r}"`};#d=this.#E;#a;#f=function(){return`is expected to match the pattern ${this.#a}`};#h=this.#f;static create(e){return new a({type:"string",...e})}constructor(e){super(e),typeof e.minLength=="number"&&(this.#t=e.minLength),this.#n=this.assureValidationErrorMessageProvider(e.minLengthValidationErrorMessageProvider,this.#T),typeof e.maxLength=="number"&&(this.#i=e.maxLength),this.#l=this.assureValidationErrorMessageProvider(e.maxLengthValidationErrorMessageProvider,this.#g),(typeof e.equalsTo=="string"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#o=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#c),typeof e.startsWith=="string"&&e.startsWith.length>0&&(this.#e=e.startsWith),this.#u=this.assureValidationErrorMessageProvider(e.startsWithValidationErrorMessageProvider,this.#m),typeof e.endsWith=="string"&&e.endsWith.length>0&&(this.#r=e.endsWith),this.#d=this.assureValidationErrorMessageProvider(e.endsWithValidationErrorMessageProvider,this.#E),e.matches instanceof RegExp&&(this.#a=e.matches),this.#h=this.assureValidationErrorMessageProvider(e.matchesValidationErrorMessageProvider,this.#f)}introspect(){return{...super.introspect(),minLength:this.#t,minLengthValidationErrorMessageProvider:this.#n,maxLength:this.#i,maxLengthValidationErrorMessageProvider:this.#l,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#o,startsWith:this.#e,startsWithValidationErrorMessageProvider:this.#u,endsWith:this.#r,endsWithValidationErrorMessageProvider:this.#d,matches:this.#a,matchesValidationErrorMessageProvider:this.#h,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#R(e){return typeof e!="string"?{message:`expected type string, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#o}:typeof this.#e=="string"&&this.#e.length>0&&!e.startsWith(this.#e)?{provider:this.#u}:typeof this.#r=="string"&&this.#r.length>0&&!e.endsWith(this.#r)?{provider:this.#d}:typeof this.#t<"u"&&e.length<this.#t?{provider:this.#n}:typeof this.#i<"u"&&e.length>this.#i?{provider:this.#l}:this.#a instanceof RegExp&&!this.#a.test(e)?{provider:this.#h}:null}#p(e){let{valid:r,transaction:t,errors:i}=e;if(!r)return{done:!0,result:{valid:r,errors:i}};let{object:{validatedObject:s}}=t;if(typeof s>"u"&&!this.isRequired||s===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:s}};let n=this.#R(s);return n?"message"in n?{done:!0,result:{valid:!1,errors:[{message:n.message}]}}:{done:!1,provider:n.provider,objToValidate:s}:{done:!0,result:{valid:!0,object:s}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let i=this.#R(e);return i?"message"in i?{valid:!1,errors:[{message:i.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(i.provider,e)}]}:{valid:!0,object:e}}let t=this.#p(this.preValidateSync(e,r));return t.done?t.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,t.objToValidate)}]}}async _validateAsync(e,r){let t=this.#p(await super.preValidateAsync(e,r));return t.done?t.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(t.provider,t.objToValidate)}]}}createFromProps(e){return a.create(e)}equals(e,r){if(typeof e!="string")throw new Error("string expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}minLength(e,r){if(typeof e!="number")throw new Error("length must be a number");return this.createFromProps({...this.introspect(),minLength:e,minLengthValidationErrorMessageProvider:r})}clearMinLength(){let e=this.introspect();return delete e.minLength,this.createFromProps({...e})}maxLength(e,r){if(typeof e!="number")throw new Error("length must be a number");return this.createFromProps({...this.introspect(),maxLength:e,maxLengthValidationErrorMessageProvider:r})}clearMaxLength(){let e=this.introspect();return delete e.maxLength,this.createFromProps({...e})}startsWith(e,r){if(typeof e!="string"||!e)throw new Error("non empty string expected");return this.createFromProps({...this.introspect(),startsWith:e,startsWithValidationErrorMessageProvider:r})}clearStartsWith(){let e=this.introspect();return delete e.startsWith,this.createFromProps({...e})}endsWith(e,r){if(typeof e!="string"||!e)throw new Error("non empty string expected");return this.createFromProps({...this.introspect(),endsWith:e,endsWithValidationErrorMessageProvider:r})}clearEndsWith(){let e=this.introspect();return delete e.endsWith,this.createFromProps({...e})}matches(e,r){if(!(e instanceof RegExp))throw new Error("regexp expected");return this.createFromProps({...this.introspect(),matches:e,matchesValidationErrorMessageProvider:r})}clearMatches(){let e=this.introspect();return delete e.matches,this.createFromProps({...e})}};function d(a,e){return typeof a=="string"?l.create({isRequired:!0,equalsTo:a,equalsToValidationErrorMessageProvider:e}):l.create({isRequired:!0})}export{l as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-ORV2G6ZL.js.map
|