@cleverbrush/schema 0.0.0-beta-20260410073748
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 +1409 -0
- package/dist/builders/AnySchemaBuilder.d.ts +116 -0
- package/dist/builders/AnySchemaBuilder.js +2 -0
- package/dist/builders/AnySchemaBuilder.js.map +1 -0
- package/dist/builders/ArraySchemaBuilder.d.ts +214 -0
- package/dist/builders/ArraySchemaBuilder.js +2 -0
- package/dist/builders/ArraySchemaBuilder.js.map +1 -0
- package/dist/builders/BooleanSchemaBuilder.d.ts +146 -0
- package/dist/builders/BooleanSchemaBuilder.js +2 -0
- package/dist/builders/BooleanSchemaBuilder.js.map +1 -0
- package/dist/builders/DateSchemaBuilder.d.ts +277 -0
- package/dist/builders/DateSchemaBuilder.js +2 -0
- package/dist/builders/DateSchemaBuilder.js.map +1 -0
- package/dist/builders/ExternSchemaBuilder.d.ts +200 -0
- package/dist/builders/ExternSchemaBuilder.js +2 -0
- package/dist/builders/ExternSchemaBuilder.js.map +1 -0
- package/dist/builders/FunctionSchemaBuilder.d.ts +246 -0
- package/dist/builders/FunctionSchemaBuilder.js +2 -0
- package/dist/builders/FunctionSchemaBuilder.js.map +1 -0
- package/dist/builders/LazySchemaBuilder.d.ts +167 -0
- package/dist/builders/NullSchemaBuilder.d.ts +162 -0
- package/dist/builders/NumberSchemaBuilder.d.ts +273 -0
- package/dist/builders/NumberSchemaBuilder.js +2 -0
- package/dist/builders/NumberSchemaBuilder.js.map +1 -0
- package/dist/builders/ObjectSchemaBuilder.d.ts +517 -0
- package/dist/builders/ObjectSchemaBuilder.js +2 -0
- package/dist/builders/ObjectSchemaBuilder.js.map +1 -0
- package/dist/builders/PropertyValidationResult.d.ts +68 -0
- package/dist/builders/RecordSchemaBuilder.d.ts +341 -0
- package/dist/builders/RecordSchemaBuilder.js +2 -0
- package/dist/builders/RecordSchemaBuilder.js.map +1 -0
- package/dist/builders/SchemaBuilder.d.ts +947 -0
- package/dist/builders/StringSchemaBuilder.d.ts +291 -0
- package/dist/builders/StringSchemaBuilder.js +2 -0
- package/dist/builders/StringSchemaBuilder.js.map +1 -0
- package/dist/builders/TupleSchemaBuilder.d.ts +248 -0
- package/dist/builders/TupleSchemaBuilder.js +2 -0
- package/dist/builders/TupleSchemaBuilder.js.map +1 -0
- package/dist/builders/UnionSchemaBuilder.d.ts +227 -0
- package/dist/builders/UnionSchemaBuilder.js +2 -0
- package/dist/builders/UnionSchemaBuilder.js.map +1 -0
- package/dist/chunk-CTP4RHDG.js +2 -0
- package/dist/chunk-CTP4RHDG.js.map +1 -0
- package/dist/chunk-FWUEUW2N.js +2 -0
- package/dist/chunk-FWUEUW2N.js.map +1 -0
- package/dist/chunk-IJ6FO37G.js +2 -0
- package/dist/chunk-IJ6FO37G.js.map +1 -0
- package/dist/chunk-KESLT5EE.js +2 -0
- package/dist/chunk-KESLT5EE.js.map +1 -0
- package/dist/chunk-KFTO7TMB.js +2 -0
- package/dist/chunk-KFTO7TMB.js.map +1 -0
- package/dist/chunk-MKAYFPAR.js +2 -0
- package/dist/chunk-MKAYFPAR.js.map +1 -0
- package/dist/chunk-NXPH3ZUW.js +2 -0
- package/dist/chunk-NXPH3ZUW.js.map +1 -0
- package/dist/chunk-OOPF7RXS.js +2 -0
- package/dist/chunk-OOPF7RXS.js.map +1 -0
- package/dist/chunk-S5TC6NSU.js +2 -0
- package/dist/chunk-S5TC6NSU.js.map +1 -0
- package/dist/chunk-YWBNVHR6.js +2 -0
- package/dist/chunk-YWBNVHR6.js.map +1 -0
- package/dist/chunk-Z72HXYKX.js +2 -0
- package/dist/chunk-Z72HXYKX.js.map +1 -0
- package/dist/chunk-Z7QZ7IXT.js +2 -0
- package/dist/chunk-Z7QZ7IXT.js.map +1 -0
- package/dist/chunk-ZAN4ZHCJ.js +2 -0
- package/dist/chunk-ZAN4ZHCJ.js.map +1 -0
- package/dist/chunk-ZUPYV5TI.js +2 -0
- package/dist/chunk-ZUPYV5TI.js.map +1 -0
- package/dist/core.d.ts +23 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/extension.d.ts +413 -0
- package/dist/extensions/array.d.ts +112 -0
- package/dist/extensions/enum.d.ts +190 -0
- package/dist/extensions/index.d.ts +108 -0
- package/dist/extensions/nullable.d.ts +26 -0
- package/dist/extensions/number.d.ts +228 -0
- package/dist/extensions/string.d.ts +332 -0
- package/dist/extensions/util.d.ts +45 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/transaction.d.ts +69 -0
- package/package.json +104 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type BRAND, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
|
|
2
|
+
type AnySchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnType<AnySchemaBuilder<R>['introspect']>>;
|
|
3
|
+
/**
|
|
4
|
+
* Any schema builder class. Similar to the `any` type
|
|
5
|
+
* in TypeScript. Allows to define a schema for `any` value.
|
|
6
|
+
* Use it when you don't know the type of the value.
|
|
7
|
+
*
|
|
8
|
+
* **NOTE** this class is exported only to give opportunity to extend it
|
|
9
|
+
* by inheriting. It is not recommended to create an instance of this class
|
|
10
|
+
* directly. Use `any()` function instead.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const schema = any();
|
|
15
|
+
* const result = schema.validate(123);
|
|
16
|
+
* // result.valid === true
|
|
17
|
+
* // result.object === 123
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class AnySchemaBuilder<TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResult = TExplicitType extends undefined ? any : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
static create(props: AnySchemaBuilderCreateProps<any>): AnySchemaBuilder<true, false, undefined, false, {}, any>;
|
|
26
|
+
protected constructor(props: AnySchemaBuilderCreateProps<TRequired>);
|
|
27
|
+
/**
|
|
28
|
+
* @inheritdoc
|
|
29
|
+
*/
|
|
30
|
+
hasType<T>(_notUsed?: T): AnySchemaBuilder<true, TNullable, T, THasDefault, TExtensions> & TExtensions;
|
|
31
|
+
/**
|
|
32
|
+
* @inheritdoc
|
|
33
|
+
*/
|
|
34
|
+
clearHasType(): AnySchemaBuilder<TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
35
|
+
/** {@inheritDoc SchemaBuilder.validate} */
|
|
36
|
+
validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
37
|
+
/** {@inheritDoc SchemaBuilder.validateAsync} */
|
|
38
|
+
validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
39
|
+
/**
|
|
40
|
+
* Performs synchronous validation of the schema over `object`.
|
|
41
|
+
* Throws if any preprocessor, validator, or error message provider returns a Promise.
|
|
42
|
+
* @param context Optional `ValidationContext` settings.
|
|
43
|
+
*/
|
|
44
|
+
protected _validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Performs async validation of the schema over `object`.
|
|
47
|
+
* Supports async preprocessors, validators, and error message providers.
|
|
48
|
+
* @param context Optional `ValidationContext` settings.
|
|
49
|
+
*/
|
|
50
|
+
protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
51
|
+
protected createFromProps<TReq extends boolean>(props: AnySchemaBuilderCreateProps<TReq>): this;
|
|
52
|
+
/**
|
|
53
|
+
* @hidden
|
|
54
|
+
*/
|
|
55
|
+
required(errorMessage?: ValidationErrorMessageProvider): AnySchemaBuilder<true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
56
|
+
/**
|
|
57
|
+
* @hidden
|
|
58
|
+
*/
|
|
59
|
+
optional(): AnySchemaBuilder<false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
60
|
+
/**
|
|
61
|
+
* @hidden
|
|
62
|
+
*/
|
|
63
|
+
default(value: TResult | (() => TResult)): AnySchemaBuilder<true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
|
|
64
|
+
/**
|
|
65
|
+
* @hidden
|
|
66
|
+
*/
|
|
67
|
+
clearDefault(): AnySchemaBuilder<TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
|
|
68
|
+
/**
|
|
69
|
+
* @hidden
|
|
70
|
+
*/
|
|
71
|
+
brand<TBrand extends string | symbol>(_name?: TBrand): AnySchemaBuilder<TRequired, TNullable, TResult & {
|
|
72
|
+
readonly [K in BRAND]: TBrand;
|
|
73
|
+
}, THasDefault, TExtensions> & TExtensions;
|
|
74
|
+
/**
|
|
75
|
+
* Marks the inferred type as `Readonly<T>`. Sets the `isReadonly`
|
|
76
|
+
* introspection flag for tooling consistency.
|
|
77
|
+
*
|
|
78
|
+
* @see {@link SchemaBuilder.readonly}
|
|
79
|
+
*/
|
|
80
|
+
readonly(): AnySchemaBuilder<TRequired, TNullable, Readonly<TResult>, THasDefault, TExtensions> & TExtensions;
|
|
81
|
+
/**
|
|
82
|
+
* @hidden
|
|
83
|
+
*/
|
|
84
|
+
nullable(): AnySchemaBuilder<TRequired, true, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
85
|
+
/**
|
|
86
|
+
* @hidden
|
|
87
|
+
*/
|
|
88
|
+
notNullable(): AnySchemaBuilder<TRequired, false, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a `any` schema.
|
|
92
|
+
* @example
|
|
93
|
+
* ```
|
|
94
|
+
* const anyObject = any();
|
|
95
|
+
*
|
|
96
|
+
* // null - invalid
|
|
97
|
+
* // undefined - invalid
|
|
98
|
+
* // string - valid
|
|
99
|
+
* // {} - valid
|
|
100
|
+
* // Date -valid
|
|
101
|
+
* // { someProp: 123 } - valid
|
|
102
|
+
* // etc
|
|
103
|
+
* ```
|
|
104
|
+
* @example
|
|
105
|
+
* ```
|
|
106
|
+
* const anyObject = any().optional();
|
|
107
|
+
* // null - valid
|
|
108
|
+
* // undefined - valid
|
|
109
|
+
* // string - valid
|
|
110
|
+
* // {} - valid
|
|
111
|
+
* // Date -valid
|
|
112
|
+
* // { someProp: 123 } - valid
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare const any: () => AnySchemaBuilder<true>;
|
|
116
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { ObjectSchemaBuilder, ObjectSchemaValidationResult } from './ObjectSchemaBuilder.js';
|
|
2
|
+
import { type BRAND, type InferType, type NestedValidationResult, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
|
|
3
|
+
import type { UnionSchemaBuilder, UnionSchemaValidationResult } from './UnionSchemaBuilder.js';
|
|
4
|
+
/**
|
|
5
|
+
* Maps an element schema type to the appropriate validation result type.
|
|
6
|
+
* Union schema elements get `UnionSchemaValidationResult`,
|
|
7
|
+
* Object schema elements get `ObjectSchemaValidationResult`,
|
|
8
|
+
* other types get `ValidationResult`.
|
|
9
|
+
*/
|
|
10
|
+
export type ElementValidationResult<TElementSchema extends SchemaBuilder<any, any, any, any, any>> = TElementSchema extends UnionSchemaBuilder<infer UOptions extends readonly SchemaBuilder<any, any, any, any, any>[], any, any> ? UnionSchemaValidationResult<InferType<TElementSchema>, UOptions> : TElementSchema extends ObjectSchemaBuilder<any, any, any, any, any> ? ObjectSchemaValidationResult<InferType<TElementSchema>, TElementSchema> : ValidationResult<InferType<TElementSchema>>;
|
|
11
|
+
/**
|
|
12
|
+
* Validation result type returned by `ArraySchemaBuilder.validate()`.
|
|
13
|
+
* Extends `ValidationResult` with `getNestedErrors` for root-level array
|
|
14
|
+
* errors and per-element validation results.
|
|
15
|
+
*/
|
|
16
|
+
export type ArraySchemaValidationResult<TResult, TElementSchema extends SchemaBuilder<any, any, any, any, any>> = ValidationResult<TResult> & {
|
|
17
|
+
/**
|
|
18
|
+
* Returns root-level array validation errors combined with
|
|
19
|
+
* per-element validation results.
|
|
20
|
+
* The returned value has both `NestedValidationResult` properties
|
|
21
|
+
* (`errors`, `isValid`, `descriptor`, `seenValue`) and indexed
|
|
22
|
+
* element results (`[0]`, `[1]`, etc.).
|
|
23
|
+
*/
|
|
24
|
+
getNestedErrors(): Array<ElementValidationResult<TElementSchema>> & NestedValidationResult<any, any, any>;
|
|
25
|
+
};
|
|
26
|
+
type ArraySchemaBuilderCreateProps<TElementSchema extends SchemaBuilder<any, any, any, any, any>, R extends boolean = true> = Partial<ReturnType<ArraySchemaBuilder<TElementSchema, R>['introspect']>>;
|
|
27
|
+
/**
|
|
28
|
+
* Similar to the `Array` type in TypeScript. It can be used to validate arrays of any type.
|
|
29
|
+
* It can also be used to validate arrays of specific type.
|
|
30
|
+
* For example, if you want to validate an array of numbers,
|
|
31
|
+
* you can use `array(number())` to create a schema builder.
|
|
32
|
+
* If you want to validate an array of users, you can use
|
|
33
|
+
* `array().of(object({ name: string(), age: number() }))` to create a schema builder.
|
|
34
|
+
* If you want to validate an array of numbers or strings,
|
|
35
|
+
* you can use `array(union(number()).or(string()))`.
|
|
36
|
+
*
|
|
37
|
+
* Also you can limit the length of the array by using `minLength`
|
|
38
|
+
* and `maxLength` methods.
|
|
39
|
+
*
|
|
40
|
+
* **NOTE** this class is exported only to give opportunity to extend it
|
|
41
|
+
* by inheriting. It is not recommended to create an instance of this class
|
|
42
|
+
* directly. Use {@link array | array()} function instead.
|
|
43
|
+
* @see {@link array}
|
|
44
|
+
*/
|
|
45
|
+
export declare class ArraySchemaBuilder<TElementSchema extends SchemaBuilder<any, any, any, any, any>, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TResult = TExplicitType extends undefined ? TElementSchema extends undefined ? Array<any> : TElementSchema extends SchemaBuilder<infer T1, infer T2> ? Array<InferType<SchemaBuilder<T1, T2>>> : never : TExplicitType> extends SchemaBuilder<TResult, TRequired, TNullable, THasDefault, TExtensions> {
|
|
46
|
+
#private;
|
|
47
|
+
/**
|
|
48
|
+
* @hidden
|
|
49
|
+
*/
|
|
50
|
+
static create(props: ArraySchemaBuilderCreateProps<any, any>): ArraySchemaBuilder<SchemaBuilder<any, any, any, any, any>, true, false, undefined, false, {}, any[]>;
|
|
51
|
+
protected constructor(props: ArraySchemaBuilderCreateProps<TElementSchema, TRequired>);
|
|
52
|
+
/**
|
|
53
|
+
* @inheritdoc
|
|
54
|
+
*/
|
|
55
|
+
hasType<T>(_notUsed?: T): ArraySchemaBuilder<TElementSchema, true, TNullable, T, THasDefault, TExtensions> & TExtensions;
|
|
56
|
+
/**
|
|
57
|
+
* @inheritdoc
|
|
58
|
+
*/
|
|
59
|
+
clearHasType(): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
60
|
+
/**
|
|
61
|
+
* Performs synchronous validation of the schema over `object`. {@inheritDoc SchemaBuilder.validate}
|
|
62
|
+
*/
|
|
63
|
+
validate(object: TResult, context?: ValidationContext): ArraySchemaValidationResult<TResult, TElementSchema>;
|
|
64
|
+
/**
|
|
65
|
+
* Performs asynchronous validation of the schema over `object`. {@inheritDoc SchemaBuilder.validateAsync}
|
|
66
|
+
*/
|
|
67
|
+
validateAsync(object: TResult, context?: ValidationContext): Promise<ArraySchemaValidationResult<TResult, TElementSchema>>;
|
|
68
|
+
/**
|
|
69
|
+
* Performs synchronous validation of the schema over `object`.
|
|
70
|
+
* Throws if any preprocessor, validator, or error message provider returns a Promise.
|
|
71
|
+
* @param context Optional `ValidationContext` settings.
|
|
72
|
+
*/
|
|
73
|
+
protected _validate(object: TResult, context?: ValidationContext): ArraySchemaValidationResult<TResult, TElementSchema>;
|
|
74
|
+
/**
|
|
75
|
+
* Performs async validation of the schema over `object`.
|
|
76
|
+
* Supports async preprocessors, validators, and error message providers.
|
|
77
|
+
* @param context Optional `ValidationContext` settings.
|
|
78
|
+
*/
|
|
79
|
+
protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ArraySchemaValidationResult<TResult, TElementSchema>>;
|
|
80
|
+
/**
|
|
81
|
+
* @hidden
|
|
82
|
+
*/
|
|
83
|
+
protected createFromProps<TReq extends boolean>(props: ArraySchemaBuilderCreateProps<TElementSchema, TReq>): this;
|
|
84
|
+
/**
|
|
85
|
+
* @hidden
|
|
86
|
+
*/
|
|
87
|
+
required(errorMessage?: ValidationErrorMessageProvider): ArraySchemaBuilder<TElementSchema, true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
88
|
+
/**
|
|
89
|
+
* @hidden
|
|
90
|
+
*/
|
|
91
|
+
optional(): ArraySchemaBuilder<TElementSchema, false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
92
|
+
/**
|
|
93
|
+
* @hidden
|
|
94
|
+
*/
|
|
95
|
+
default(value: TResult | (() => TResult)): ArraySchemaBuilder<TElementSchema, true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
|
|
96
|
+
/**
|
|
97
|
+
* @hidden
|
|
98
|
+
*/
|
|
99
|
+
clearDefault(): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
|
|
100
|
+
/**
|
|
101
|
+
* @hidden
|
|
102
|
+
*/
|
|
103
|
+
brand<TBrand extends string | symbol>(_name?: TBrand): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TResult & {
|
|
104
|
+
readonly [K in BRAND]: TBrand;
|
|
105
|
+
}, THasDefault, TExtensions> & TExtensions;
|
|
106
|
+
/**
|
|
107
|
+
* Marks the inferred type as `ReadonlyArray<T>` — disables `push`,
|
|
108
|
+
* `pop`, and other mutating methods at the type level. Validation
|
|
109
|
+
* behaviour is unchanged.
|
|
110
|
+
*
|
|
111
|
+
* @see {@link SchemaBuilder.readonly}
|
|
112
|
+
*/
|
|
113
|
+
readonly(): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, ReadonlyArray<TElementSchema extends SchemaBuilder<infer T1, infer T2> ? InferType<SchemaBuilder<T1, T2>> : any>, THasDefault, TExtensions> & TExtensions;
|
|
114
|
+
introspect(): {
|
|
115
|
+
/**
|
|
116
|
+
* Schema of array item (if defined)
|
|
117
|
+
*/
|
|
118
|
+
elementSchema: TElementSchema | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Min length of a valid array
|
|
121
|
+
*/
|
|
122
|
+
minLength: number | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Min length validation error message provider.
|
|
125
|
+
* If not provided, default error message provider is used.
|
|
126
|
+
*/
|
|
127
|
+
minLengthValidationErrorMessageProvider: ValidationErrorMessageProvider<ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, false, {}, TExplicitType extends undefined ? TElementSchema extends undefined ? any[] : TElementSchema extends SchemaBuilder<infer T1, infer T2 extends boolean, false, false, {}> ? (T2 extends true ? T1 : T1 | undefined)[] : never : TExplicitType>>;
|
|
128
|
+
/**
|
|
129
|
+
* Max length of a valid array
|
|
130
|
+
*/
|
|
131
|
+
maxLength: number | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Max length validation error message provider.
|
|
134
|
+
* If not provided, default error message provider is used.
|
|
135
|
+
*/
|
|
136
|
+
maxLengthValidationErrorMessageProvider: ValidationErrorMessageProvider<ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, false, {}, TExplicitType extends undefined ? TElementSchema extends undefined ? any[] : TElementSchema extends SchemaBuilder<infer T1, infer T2 extends boolean, false, false, {}> ? (T2 extends true ? T1 : T1 | undefined)[] : never : TExplicitType>>;
|
|
137
|
+
type: string;
|
|
138
|
+
isRequired: boolean;
|
|
139
|
+
isNullable: boolean;
|
|
140
|
+
isReadonly: boolean;
|
|
141
|
+
preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TResult>[];
|
|
142
|
+
validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TResult>[];
|
|
143
|
+
requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
|
|
144
|
+
extensions: {
|
|
145
|
+
[x: string]: unknown;
|
|
146
|
+
};
|
|
147
|
+
hasDefault: boolean;
|
|
148
|
+
defaultValue: TResult | (() => TResult) | undefined;
|
|
149
|
+
description: string | undefined;
|
|
150
|
+
hasCatch: boolean;
|
|
151
|
+
catchValue: TResult | (() => TResult) | undefined;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Set a schema that every array item has to satisfy. If it is not set,
|
|
155
|
+
* Item of any type is allowed.
|
|
156
|
+
* @param schema Schema that every array item has to satisfy
|
|
157
|
+
*/
|
|
158
|
+
of<TSchema extends SchemaBuilder<any, any, any, any, any>>(schema: TSchema): ArraySchemaBuilder<TSchema, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
159
|
+
/**
|
|
160
|
+
* Clears the element schema set by `of()`. After this call,
|
|
161
|
+
* array items of any type will be accepted.
|
|
162
|
+
*/
|
|
163
|
+
clearOf(): ArraySchemaBuilder<any, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
164
|
+
/**
|
|
165
|
+
* Set minimal length of the valid array value for schema.
|
|
166
|
+
*/
|
|
167
|
+
minLength<T extends number>(length: T,
|
|
168
|
+
/**
|
|
169
|
+
* Custom error message provider.
|
|
170
|
+
*/
|
|
171
|
+
errorMessage?: ValidationErrorMessageProvider<ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType>>): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
172
|
+
/**
|
|
173
|
+
* Clear minimal length of the valid array value for schema.
|
|
174
|
+
*/
|
|
175
|
+
clearMinLength(): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
176
|
+
/**
|
|
177
|
+
* Set max length of the valid array value for schema.
|
|
178
|
+
*/
|
|
179
|
+
maxLength<T extends number>(length: T,
|
|
180
|
+
/**
|
|
181
|
+
* Custom error message provider.
|
|
182
|
+
*/
|
|
183
|
+
errorMessage?: ValidationErrorMessageProvider<ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType>>): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
184
|
+
/**
|
|
185
|
+
* Clear max length of the valid array value for schema.
|
|
186
|
+
*/
|
|
187
|
+
clearMaxLength(): ArraySchemaBuilder<TElementSchema, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
188
|
+
/**
|
|
189
|
+
* @hidden
|
|
190
|
+
*/
|
|
191
|
+
nullable(): ArraySchemaBuilder<TElementSchema, TRequired, true, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
192
|
+
/**
|
|
193
|
+
* @hidden
|
|
194
|
+
*/
|
|
195
|
+
notNullable(): ArraySchemaBuilder<TElementSchema, TRequired, false, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Creates a `Array` schema.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const schema = array().minLength(2).maxLength(5).of(string());
|
|
203
|
+
* // [] - invalid
|
|
204
|
+
* // ['a', 'b'] - valid
|
|
205
|
+
* // ['a', 'b', 'c', 'd', 'e', 'f'] - invalid
|
|
206
|
+
* // ['a', 'b', 'c', 'd', 'e'] - valid
|
|
207
|
+
* // ['a', 'b', 'c', 'd', 1] - invalid
|
|
208
|
+
* // ['a', 'b', null] - invalid
|
|
209
|
+
* // null - invalid
|
|
210
|
+
* // undefined - invalid
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export declare const array: <TElementSchema extends SchemaBuilder<any, any, any, any, any>>(elementSchema?: TElementSchema) => ArraySchemaBuilder<TElementSchema, true>;
|
|
214
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type BRAND, SchemaBuilder, type ValidationContext, type ValidationErrorMessageProvider, type ValidationResult } from './SchemaBuilder.js';
|
|
2
|
+
type BooleanSchemaBuilderCreateProps<R extends boolean = true> = Partial<ReturnType<BooleanSchemaBuilder<R>['introspect']>>;
|
|
3
|
+
/**
|
|
4
|
+
* Similar to `boolean` type in TypeScript.
|
|
5
|
+
* Allows to define a schema for a boolean value. It can be required or optional.
|
|
6
|
+
* It can be restricted to be equal to a certain value.
|
|
7
|
+
*
|
|
8
|
+
* **NOTE** this class is exported only to give opportunity to extend it
|
|
9
|
+
* by inheriting. It is not recommended to create an instance of this class
|
|
10
|
+
* directly. Use {@link boolean | boolean()} function instead.
|
|
11
|
+
*
|
|
12
|
+
* @example ```ts
|
|
13
|
+
* const schema = boolean().equals(true);
|
|
14
|
+
* const result = schema.validate(true);
|
|
15
|
+
* // result.valid === true
|
|
16
|
+
* // result.object === true
|
|
17
|
+
* ```
|
|
18
|
+
* @example ```ts
|
|
19
|
+
* const schema = boolean().equals(false);
|
|
20
|
+
* const result = schema.validate(true);
|
|
21
|
+
* // result.valid === false
|
|
22
|
+
* // result.errors[0].message === 'is expected to be equal to 'false''
|
|
23
|
+
* ```
|
|
24
|
+
* @example ```ts
|
|
25
|
+
* const schema = boolean().equals(true).optional();
|
|
26
|
+
* const result = schema.validate(undefined);
|
|
27
|
+
* // result.valid === true
|
|
28
|
+
* // result.object === undefined
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @see {@link boolean}
|
|
32
|
+
*/
|
|
33
|
+
export declare class BooleanSchemaBuilder<TResult = boolean, TRequired extends boolean = true, TNullable extends boolean = false, TExplicitType = undefined, THasDefault extends boolean = false, TExtensions = {}, TFinalResult = TExplicitType extends undefined ? TResult : TExplicitType> extends SchemaBuilder<TFinalResult, TRequired, TNullable, THasDefault, TExtensions> {
|
|
34
|
+
#private;
|
|
35
|
+
/**
|
|
36
|
+
* @hidden
|
|
37
|
+
*/
|
|
38
|
+
static create(props: BooleanSchemaBuilderCreateProps<any>): BooleanSchemaBuilder<boolean, any, false, undefined, false, {}, boolean>;
|
|
39
|
+
protected constructor(props: BooleanSchemaBuilderCreateProps<TRequired>);
|
|
40
|
+
introspect(): {
|
|
41
|
+
/**
|
|
42
|
+
* If set, restrict object to be equal to a certain value.
|
|
43
|
+
*/
|
|
44
|
+
equalsTo: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Equals to validation error message provider.
|
|
47
|
+
* If not provided, default error message will be used.
|
|
48
|
+
*/
|
|
49
|
+
equalsToValidationErrorMessageProvider: ValidationErrorMessageProvider<BooleanSchemaBuilder<TResult, TRequired, false, undefined, false, {}, TResult>>;
|
|
50
|
+
type: string;
|
|
51
|
+
isRequired: boolean;
|
|
52
|
+
isNullable: boolean;
|
|
53
|
+
isReadonly: boolean;
|
|
54
|
+
preprocessors: readonly import("./SchemaBuilder.js").PreprocessorEntry<TFinalResult>[];
|
|
55
|
+
validators: readonly import("./SchemaBuilder.js").ValidatorEntry<TFinalResult>[];
|
|
56
|
+
requiredValidationErrorMessageProvider: ValidationErrorMessageProvider<SchemaBuilder<any, any, any, any, any>>;
|
|
57
|
+
extensions: {
|
|
58
|
+
[x: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
hasDefault: boolean;
|
|
61
|
+
defaultValue: TFinalResult | (() => TFinalResult) | undefined;
|
|
62
|
+
description: string | undefined;
|
|
63
|
+
hasCatch: boolean;
|
|
64
|
+
catchValue: TFinalResult | (() => TFinalResult) | undefined;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* @inheritdoc
|
|
68
|
+
*/
|
|
69
|
+
hasType<T>(_notUsed?: T): BooleanSchemaBuilder<TResult, true, TNullable, T, THasDefault, TExtensions> & TExtensions;
|
|
70
|
+
/**
|
|
71
|
+
* @inheritdoc
|
|
72
|
+
*/
|
|
73
|
+
clearHasType(): BooleanSchemaBuilder<TResult, TRequired, TNullable, undefined, THasDefault, TExtensions> & TExtensions;
|
|
74
|
+
/** {@inheritDoc SchemaBuilder.validate} */
|
|
75
|
+
validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
76
|
+
/** {@inheritDoc SchemaBuilder.validateAsync} */
|
|
77
|
+
validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
78
|
+
/**
|
|
79
|
+
* Performs synchronous validation of the schema over `object`.
|
|
80
|
+
* Throws if any preprocessor, validator, or error message provider returns a Promise.
|
|
81
|
+
* @param context Optional `ValidationContext` settings.
|
|
82
|
+
*/
|
|
83
|
+
protected _validate(object: TResult, context?: ValidationContext): ValidationResult<TResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Performs async validation of the schema over `object`.
|
|
86
|
+
* Supports async preprocessors, validators, and error message providers.
|
|
87
|
+
* @param context Optional `ValidationContext` settings.
|
|
88
|
+
*/
|
|
89
|
+
protected _validateAsync(object: TResult, context?: ValidationContext): Promise<ValidationResult<TResult>>;
|
|
90
|
+
protected createFromProps<TReq extends boolean>(props: BooleanSchemaBuilderCreateProps<TReq>): this;
|
|
91
|
+
/**
|
|
92
|
+
* @hidden
|
|
93
|
+
*/
|
|
94
|
+
required(errorMessage?: ValidationErrorMessageProvider): BooleanSchemaBuilder<TResult, true, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
95
|
+
/**
|
|
96
|
+
* @hidden
|
|
97
|
+
*/
|
|
98
|
+
optional(): BooleanSchemaBuilder<TResult, false, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
99
|
+
/**
|
|
100
|
+
* @hidden
|
|
101
|
+
*/
|
|
102
|
+
default(value: TFinalResult | (() => TFinalResult)): BooleanSchemaBuilder<TResult, true, TNullable, TExplicitType, true, TExtensions> & TExtensions;
|
|
103
|
+
/**
|
|
104
|
+
* @hidden
|
|
105
|
+
*/
|
|
106
|
+
clearDefault(): BooleanSchemaBuilder<TResult, TRequired, TNullable, TExplicitType, false, TExtensions> & TExtensions;
|
|
107
|
+
/**
|
|
108
|
+
* @hidden
|
|
109
|
+
*/
|
|
110
|
+
brand<TBrand extends string | symbol>(_name?: TBrand): BooleanSchemaBuilder<TResult, TRequired, TNullable, TFinalResult & {
|
|
111
|
+
readonly [K in BRAND]: TBrand;
|
|
112
|
+
}, THasDefault, TExtensions> & TExtensions;
|
|
113
|
+
/**
|
|
114
|
+
* Marks the inferred type as `Readonly<boolean>`. Since booleans are
|
|
115
|
+
* already immutable this is an identity operation, but it sets the
|
|
116
|
+
* `isReadonly` introspection flag for tooling consistency.
|
|
117
|
+
*
|
|
118
|
+
* @see {@link SchemaBuilder.readonly}
|
|
119
|
+
*/
|
|
120
|
+
readonly(): BooleanSchemaBuilder<TResult, TRequired, TNullable, Readonly<TFinalResult>, THasDefault, TExtensions> & TExtensions;
|
|
121
|
+
/**
|
|
122
|
+
* Restricts object to be equal to `value`.
|
|
123
|
+
*/
|
|
124
|
+
equals<T extends boolean>(value: T,
|
|
125
|
+
/**
|
|
126
|
+
* Custom error message provider.
|
|
127
|
+
*/
|
|
128
|
+
errorMessage?: ValidationErrorMessageProvider<BooleanSchemaBuilder<TResult, TRequired>>): BooleanSchemaBuilder<T, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
129
|
+
/**
|
|
130
|
+
* Removes a `value` defined by `equals()` call.
|
|
131
|
+
*/
|
|
132
|
+
clearEquals(): BooleanSchemaBuilder<boolean, TRequired, TNullable, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
133
|
+
/**
|
|
134
|
+
* @hidden
|
|
135
|
+
*/
|
|
136
|
+
nullable(): BooleanSchemaBuilder<TResult, TRequired, true, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
137
|
+
/**
|
|
138
|
+
* @hidden
|
|
139
|
+
*/
|
|
140
|
+
notNullable(): BooleanSchemaBuilder<TResult, TRequired, false, TExplicitType, THasDefault, TExtensions> & TExtensions;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates a `boolean` schema.
|
|
144
|
+
*/
|
|
145
|
+
export declare const boolean: () => BooleanSchemaBuilder<boolean, true>;
|
|
146
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|