@hedystia/validations 1.10.1 → 1.10.2
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/dist/index.cjs +15 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/types.cjs +562 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +244 -0
- package/dist/types.d.mts +244 -0
- package/dist/types.mjs +550 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +15 -7
- package/readme.md +46 -128
- package/dist/index.d.ts +0 -311
- package/dist/index.js +0 -1
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./node_modules/@standard-schema/spec/dist/index.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type SchemaPrimitive = "string" | "number" | "boolean" | "any";
|
|
5
|
+
interface SchemaLike {
|
|
6
|
+
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
7
|
+
}
|
|
8
|
+
type Simplify<T> = T extends any ? { [K in keyof T]: T[K] } : never;
|
|
9
|
+
type RequiredKeys<S> = { [K in keyof S]: S[K] extends OptionalSchema<any, any> ? never : K }[keyof S];
|
|
10
|
+
type OptionalKeys<S> = { [K in keyof S]: S[K] extends OptionalSchema<any, any> ? K : never }[keyof S];
|
|
11
|
+
type SchemaPrimitiveMap = {
|
|
12
|
+
string: string;
|
|
13
|
+
number: number;
|
|
14
|
+
boolean: boolean;
|
|
15
|
+
any: unknown;
|
|
16
|
+
};
|
|
17
|
+
type SchemaType<S> = S extends BaseSchema<any, infer O> ? O : S extends keyof SchemaPrimitiveMap ? SchemaPrimitiveMap[S] : S extends Record<string, any> ? InferSchema<S> : unknown;
|
|
18
|
+
type InferObject<S extends SchemaDefinition> = Simplify<{ [K in RequiredKeys<S>]: SchemaType<S[K]> } & { [K in OptionalKeys<S>]?: SchemaType<S[K]> }>;
|
|
19
|
+
type InferSchema<S> = S extends BaseSchema<any, infer O> ? O : S extends "string" ? string : S extends "number" ? number : S extends "boolean" ? boolean : S extends {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
} ? { [K in keyof S as undefined extends InferSchema<S[K]> ? K : never]?: InferSchema<S[K]> } & { [K in keyof S as undefined extends InferSchema<S[K]> ? never : K]: InferSchema<S[K]> } : unknown;
|
|
22
|
+
type SchemaDefinition = SchemaLike;
|
|
23
|
+
interface Schema<I, O> extends StandardSchemaV1<I, O> {
|
|
24
|
+
optional(): OptionalSchema<I, O | undefined>;
|
|
25
|
+
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
26
|
+
array(): ArraySchema<I, O[]>;
|
|
27
|
+
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
28
|
+
jsonSchema: any;
|
|
29
|
+
readonly inferred: O;
|
|
30
|
+
schema: Schema<I, O>;
|
|
31
|
+
}
|
|
32
|
+
declare abstract class BaseSchema<I, O> implements Schema<I, O> {
|
|
33
|
+
abstract readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
34
|
+
jsonSchema: any;
|
|
35
|
+
get inferred(): O;
|
|
36
|
+
schema: Schema<I, O>;
|
|
37
|
+
protected _coerce: boolean;
|
|
38
|
+
coerce(): this;
|
|
39
|
+
optional(): OptionalSchema<I, O | undefined>;
|
|
40
|
+
null(): UnionSchema<I, O | null>;
|
|
41
|
+
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
42
|
+
array(): ArraySchema<I, O[]>;
|
|
43
|
+
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
44
|
+
}
|
|
45
|
+
declare class StringSchemaType extends BaseSchema<unknown, string> {
|
|
46
|
+
readonly type: SchemaPrimitive;
|
|
47
|
+
private _validateDate;
|
|
48
|
+
private _validateUUID;
|
|
49
|
+
private _validateRegex;
|
|
50
|
+
private _validateEmail;
|
|
51
|
+
private _validatePhone;
|
|
52
|
+
private _validateDomain;
|
|
53
|
+
private _requireHttpOrHttps;
|
|
54
|
+
private _minLength?;
|
|
55
|
+
private _maxLength?;
|
|
56
|
+
constructor();
|
|
57
|
+
primitive(): SchemaPrimitive;
|
|
58
|
+
minLength(n: number): StringSchemaType;
|
|
59
|
+
maxLength(n: number): StringSchemaType;
|
|
60
|
+
date(): StringSchemaType;
|
|
61
|
+
uuid(): StringSchemaType;
|
|
62
|
+
regex(regex: RegExp): StringSchemaType;
|
|
63
|
+
email(): StringSchemaType;
|
|
64
|
+
phone(): StringSchemaType;
|
|
65
|
+
domain(requireHttpOrHttps?: boolean): StringSchemaType;
|
|
66
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, string>;
|
|
67
|
+
private _isValidDate;
|
|
68
|
+
private _isValidUUID;
|
|
69
|
+
private _isValidRegex;
|
|
70
|
+
private _isValidEmail;
|
|
71
|
+
private _isValidPhone;
|
|
72
|
+
private _isValidDomain;
|
|
73
|
+
}
|
|
74
|
+
declare class NumberSchemaType extends BaseSchema<unknown, number> {
|
|
75
|
+
readonly type: SchemaPrimitive;
|
|
76
|
+
private _min?;
|
|
77
|
+
private _max?;
|
|
78
|
+
constructor();
|
|
79
|
+
primitive(): SchemaPrimitive;
|
|
80
|
+
min(n: number): NumberSchemaType;
|
|
81
|
+
max(n: number): NumberSchemaType;
|
|
82
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, number>;
|
|
83
|
+
}
|
|
84
|
+
declare class BooleanSchemaType extends BaseSchema<unknown, boolean> {
|
|
85
|
+
readonly type: SchemaPrimitive;
|
|
86
|
+
constructor();
|
|
87
|
+
primitive(): SchemaPrimitive;
|
|
88
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, boolean>;
|
|
89
|
+
}
|
|
90
|
+
declare class AnySchemaType extends BaseSchema<unknown, any> {
|
|
91
|
+
readonly type: SchemaPrimitive;
|
|
92
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, any>;
|
|
93
|
+
}
|
|
94
|
+
declare class LiteralSchema<I, T extends string | number | boolean> extends BaseSchema<I, T> {
|
|
95
|
+
private readonly value;
|
|
96
|
+
constructor(value: T);
|
|
97
|
+
readonly "~standard": StandardSchemaV1.Props<I, T>;
|
|
98
|
+
}
|
|
99
|
+
declare class OptionalSchema<I, O> extends BaseSchema<I, O | undefined> {
|
|
100
|
+
private readonly innerSchema;
|
|
101
|
+
constructor(schema: Schema<I, O>);
|
|
102
|
+
readonly "~standard": StandardSchemaV1.Props<I, O | undefined>;
|
|
103
|
+
}
|
|
104
|
+
declare class NullSchemaType extends BaseSchema<unknown, null> {
|
|
105
|
+
readonly type = "null";
|
|
106
|
+
constructor();
|
|
107
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, null>;
|
|
108
|
+
}
|
|
109
|
+
declare class UnionSchema<I, O> extends BaseSchema<I, O> {
|
|
110
|
+
private readonly schemas;
|
|
111
|
+
constructor(...schemas: Schema<I, any>[]);
|
|
112
|
+
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
113
|
+
}
|
|
114
|
+
declare class ArraySchema<I, O extends any[]> extends BaseSchema<I, O> {
|
|
115
|
+
private readonly innerSchema;
|
|
116
|
+
constructor(schema: Schema<I, O[number]>);
|
|
117
|
+
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
118
|
+
}
|
|
119
|
+
declare class InstanceOfSchema<I, O> extends BaseSchema<I, O> {
|
|
120
|
+
private readonly innerSchema;
|
|
121
|
+
private readonly classConstructor;
|
|
122
|
+
constructor(schema: Schema<I, any>, classConstructor: new (...args: any[]) => any);
|
|
123
|
+
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
124
|
+
}
|
|
125
|
+
declare class ObjectSchemaType<T extends Record<string, unknown>> extends BaseSchema<unknown, T> {
|
|
126
|
+
readonly definition: SchemaDefinition;
|
|
127
|
+
constructor(definition: SchemaDefinition);
|
|
128
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, T>;
|
|
129
|
+
}
|
|
130
|
+
type AnySchema = SchemaPrimitive | BaseSchema<any, any> | SchemaDefinition;
|
|
131
|
+
declare function toStandard<T>(schema: AnySchema): Schema<unknown, T>;
|
|
132
|
+
/**
|
|
133
|
+
* Create standard schema types
|
|
134
|
+
* @returns {typeof h} Standard schema types
|
|
135
|
+
*/
|
|
136
|
+
declare const h: {
|
|
137
|
+
/**
|
|
138
|
+
* Create string schema type
|
|
139
|
+
* @returns {StringSchemaType} String schema type
|
|
140
|
+
*/
|
|
141
|
+
string: () => StringSchemaType;
|
|
142
|
+
/**
|
|
143
|
+
* Create number schema type
|
|
144
|
+
* @returns {NumberSchemaType} Number schema type
|
|
145
|
+
*/
|
|
146
|
+
number: () => NumberSchemaType;
|
|
147
|
+
/**
|
|
148
|
+
* Create boolean schema type
|
|
149
|
+
* @returns {BooleanSchemaType} Boolean schema type
|
|
150
|
+
*/
|
|
151
|
+
boolean: () => BooleanSchemaType;
|
|
152
|
+
/**
|
|
153
|
+
* Create null schema type
|
|
154
|
+
* @returns {NullSchemaType} Null schema type
|
|
155
|
+
*/
|
|
156
|
+
null: () => NullSchemaType;
|
|
157
|
+
/**
|
|
158
|
+
* Create any schema type
|
|
159
|
+
* @returns {AnySchemaType} Any schema type
|
|
160
|
+
*/
|
|
161
|
+
any: () => AnySchemaType;
|
|
162
|
+
/**
|
|
163
|
+
* Create literal schema type
|
|
164
|
+
* @param {T} value - Literal value
|
|
165
|
+
* @returns {LiteralSchema<unknown, T>} Literal schema type
|
|
166
|
+
*/
|
|
167
|
+
literal: <T extends string | number | boolean>(value: T) => LiteralSchema<unknown, T>;
|
|
168
|
+
/**
|
|
169
|
+
* Create object schema type
|
|
170
|
+
* @param {S} [schemaDef] - Schema definition
|
|
171
|
+
* @returns {ObjectSchemaType<InferObject<S>>} Object schema type
|
|
172
|
+
*/
|
|
173
|
+
object: <S extends SchemaDefinition>(schemaDef?: S) => ObjectSchemaType<InferObject<S>>;
|
|
174
|
+
/**
|
|
175
|
+
* Create array schema type
|
|
176
|
+
* @param {S} schema - Schema
|
|
177
|
+
* @returns {ArraySchema<unknown, InferSchema<S>[]>} Array schema type
|
|
178
|
+
*/
|
|
179
|
+
array: <S extends AnySchema>(schema: S) => ArraySchema<unknown, SchemaType<S>[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Create enum schema type from a list of string, number or boolean values.
|
|
182
|
+
* @param {Values} values - An array of literal values.
|
|
183
|
+
* @returns {UnionSchema<unknown, Values[number]>} A schema that validates against one of the provided literal values.
|
|
184
|
+
*/
|
|
185
|
+
enum: <T extends string | number | boolean, Values extends readonly [T, ...T[]]>(values: Values) => UnionSchema<unknown, Values[number]>;
|
|
186
|
+
/**
|
|
187
|
+
* Create optional schema type
|
|
188
|
+
* @param {S} schema - Schema
|
|
189
|
+
* @returns {OptionalSchema<unknown, InferSchema<S> | undefined>} Optional schema type
|
|
190
|
+
*/
|
|
191
|
+
optional: <S extends AnySchema>(schema: S) => OptionalSchema<unknown, InferSchema<S> | undefined>;
|
|
192
|
+
/**
|
|
193
|
+
* Create options schema type
|
|
194
|
+
* @param {S} schemas - Schemas
|
|
195
|
+
* @returns {UnionSchema<unknown, InferSchema<S[number]>>} Options schema type
|
|
196
|
+
*/
|
|
197
|
+
options: <S extends AnySchema[]>(...schemas: S) => UnionSchema<unknown, InferSchema<S[number]>>;
|
|
198
|
+
/**
|
|
199
|
+
* Create instance of schema type
|
|
200
|
+
* @param {C} constructor - Constructor function
|
|
201
|
+
* @returns {InstanceOfSchema<unknown, InstanceType<C>>} Instance of schema type
|
|
202
|
+
*/
|
|
203
|
+
instanceOf: <C extends new (...args: any[]) => any>(constructor: C) => InstanceOfSchema<unknown, InstanceType<C>>;
|
|
204
|
+
/**
|
|
205
|
+
* Create date schema type
|
|
206
|
+
* @returns {StringSchemaType} Date schema type
|
|
207
|
+
*/
|
|
208
|
+
date: () => StringSchemaType;
|
|
209
|
+
/**
|
|
210
|
+
* Create UUID schema type
|
|
211
|
+
* @returns {StringSchemaType} UUID schema type
|
|
212
|
+
*/
|
|
213
|
+
uuid: () => StringSchemaType;
|
|
214
|
+
/**
|
|
215
|
+
* Create regex schema type
|
|
216
|
+
* @param {RegExp} regex - Regex
|
|
217
|
+
* @returns {StringSchemaType} Regex schema type
|
|
218
|
+
*/
|
|
219
|
+
regex: (regex: RegExp) => StringSchemaType;
|
|
220
|
+
/**
|
|
221
|
+
* Create email schema type
|
|
222
|
+
* @returns {StringSchemaType} Email schema type
|
|
223
|
+
*/
|
|
224
|
+
email: () => StringSchemaType;
|
|
225
|
+
/**
|
|
226
|
+
* Create phone schema type
|
|
227
|
+
* @returns {StringSchemaType} Phone schema type
|
|
228
|
+
*/
|
|
229
|
+
phone: () => StringSchemaType;
|
|
230
|
+
/** Create domain schema type
|
|
231
|
+
* @param {boolean} requireHttpOrHttps - Require http or https
|
|
232
|
+
* @returns {StringSchemaType} Domain schema type
|
|
233
|
+
*/
|
|
234
|
+
domain: (requireHttpOrHttps?: boolean) => StringSchemaType;
|
|
235
|
+
/**
|
|
236
|
+
* Convert schema to standard schema
|
|
237
|
+
* @param {AnySchema} schema - Schema
|
|
238
|
+
* @returns {Schema<unknown, any>} Standard schema
|
|
239
|
+
*/
|
|
240
|
+
toStandard: typeof toStandard;
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { AnySchema, AnySchemaType, ArraySchema, BaseSchema, BooleanSchemaType, InstanceOfSchema, LiteralSchema, NullSchemaType, NumberSchemaType, ObjectSchemaType, OptionalSchema, StringSchemaType, UnionSchema, h };
|
|
244
|
+
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./node_modules/@standard-schema/spec/dist/index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type SchemaPrimitive = "string" | "number" | "boolean" | "any";
|
|
5
|
+
interface SchemaLike {
|
|
6
|
+
[key: string]: SchemaPrimitive | SchemaLike | BaseSchema<any, any>;
|
|
7
|
+
}
|
|
8
|
+
type Simplify<T> = T extends any ? { [K in keyof T]: T[K] } : never;
|
|
9
|
+
type RequiredKeys<S> = { [K in keyof S]: S[K] extends OptionalSchema<any, any> ? never : K }[keyof S];
|
|
10
|
+
type OptionalKeys<S> = { [K in keyof S]: S[K] extends OptionalSchema<any, any> ? K : never }[keyof S];
|
|
11
|
+
type SchemaPrimitiveMap = {
|
|
12
|
+
string: string;
|
|
13
|
+
number: number;
|
|
14
|
+
boolean: boolean;
|
|
15
|
+
any: unknown;
|
|
16
|
+
};
|
|
17
|
+
type SchemaType<S> = S extends BaseSchema<any, infer O> ? O : S extends keyof SchemaPrimitiveMap ? SchemaPrimitiveMap[S] : S extends Record<string, any> ? InferSchema<S> : unknown;
|
|
18
|
+
type InferObject<S extends SchemaDefinition> = Simplify<{ [K in RequiredKeys<S>]: SchemaType<S[K]> } & { [K in OptionalKeys<S>]?: SchemaType<S[K]> }>;
|
|
19
|
+
type InferSchema<S> = S extends BaseSchema<any, infer O> ? O : S extends "string" ? string : S extends "number" ? number : S extends "boolean" ? boolean : S extends {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
} ? { [K in keyof S as undefined extends InferSchema<S[K]> ? K : never]?: InferSchema<S[K]> } & { [K in keyof S as undefined extends InferSchema<S[K]> ? never : K]: InferSchema<S[K]> } : unknown;
|
|
22
|
+
type SchemaDefinition = SchemaLike;
|
|
23
|
+
interface Schema<I, O> extends StandardSchemaV1<I, O> {
|
|
24
|
+
optional(): OptionalSchema<I, O | undefined>;
|
|
25
|
+
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
26
|
+
array(): ArraySchema<I, O[]>;
|
|
27
|
+
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
28
|
+
jsonSchema: any;
|
|
29
|
+
readonly inferred: O;
|
|
30
|
+
schema: Schema<I, O>;
|
|
31
|
+
}
|
|
32
|
+
declare abstract class BaseSchema<I, O> implements Schema<I, O> {
|
|
33
|
+
abstract readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
34
|
+
jsonSchema: any;
|
|
35
|
+
get inferred(): O;
|
|
36
|
+
schema: Schema<I, O>;
|
|
37
|
+
protected _coerce: boolean;
|
|
38
|
+
coerce(): this;
|
|
39
|
+
optional(): OptionalSchema<I, O | undefined>;
|
|
40
|
+
null(): UnionSchema<I, O | null>;
|
|
41
|
+
enum<V extends O & (string | number | boolean), Values extends readonly [V, ...V[]]>(values: Values): UnionSchema<I, Values[number]>;
|
|
42
|
+
array(): ArraySchema<I, O[]>;
|
|
43
|
+
instanceOf<C extends new (...args: any[]) => any>(constructor: C): InstanceOfSchema<I, InstanceType<C>>;
|
|
44
|
+
}
|
|
45
|
+
declare class StringSchemaType extends BaseSchema<unknown, string> {
|
|
46
|
+
readonly type: SchemaPrimitive;
|
|
47
|
+
private _validateDate;
|
|
48
|
+
private _validateUUID;
|
|
49
|
+
private _validateRegex;
|
|
50
|
+
private _validateEmail;
|
|
51
|
+
private _validatePhone;
|
|
52
|
+
private _validateDomain;
|
|
53
|
+
private _requireHttpOrHttps;
|
|
54
|
+
private _minLength?;
|
|
55
|
+
private _maxLength?;
|
|
56
|
+
constructor();
|
|
57
|
+
primitive(): SchemaPrimitive;
|
|
58
|
+
minLength(n: number): StringSchemaType;
|
|
59
|
+
maxLength(n: number): StringSchemaType;
|
|
60
|
+
date(): StringSchemaType;
|
|
61
|
+
uuid(): StringSchemaType;
|
|
62
|
+
regex(regex: RegExp): StringSchemaType;
|
|
63
|
+
email(): StringSchemaType;
|
|
64
|
+
phone(): StringSchemaType;
|
|
65
|
+
domain(requireHttpOrHttps?: boolean): StringSchemaType;
|
|
66
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, string>;
|
|
67
|
+
private _isValidDate;
|
|
68
|
+
private _isValidUUID;
|
|
69
|
+
private _isValidRegex;
|
|
70
|
+
private _isValidEmail;
|
|
71
|
+
private _isValidPhone;
|
|
72
|
+
private _isValidDomain;
|
|
73
|
+
}
|
|
74
|
+
declare class NumberSchemaType extends BaseSchema<unknown, number> {
|
|
75
|
+
readonly type: SchemaPrimitive;
|
|
76
|
+
private _min?;
|
|
77
|
+
private _max?;
|
|
78
|
+
constructor();
|
|
79
|
+
primitive(): SchemaPrimitive;
|
|
80
|
+
min(n: number): NumberSchemaType;
|
|
81
|
+
max(n: number): NumberSchemaType;
|
|
82
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, number>;
|
|
83
|
+
}
|
|
84
|
+
declare class BooleanSchemaType extends BaseSchema<unknown, boolean> {
|
|
85
|
+
readonly type: SchemaPrimitive;
|
|
86
|
+
constructor();
|
|
87
|
+
primitive(): SchemaPrimitive;
|
|
88
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, boolean>;
|
|
89
|
+
}
|
|
90
|
+
declare class AnySchemaType extends BaseSchema<unknown, any> {
|
|
91
|
+
readonly type: SchemaPrimitive;
|
|
92
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, any>;
|
|
93
|
+
}
|
|
94
|
+
declare class LiteralSchema<I, T extends string | number | boolean> extends BaseSchema<I, T> {
|
|
95
|
+
private readonly value;
|
|
96
|
+
constructor(value: T);
|
|
97
|
+
readonly "~standard": StandardSchemaV1.Props<I, T>;
|
|
98
|
+
}
|
|
99
|
+
declare class OptionalSchema<I, O> extends BaseSchema<I, O | undefined> {
|
|
100
|
+
private readonly innerSchema;
|
|
101
|
+
constructor(schema: Schema<I, O>);
|
|
102
|
+
readonly "~standard": StandardSchemaV1.Props<I, O | undefined>;
|
|
103
|
+
}
|
|
104
|
+
declare class NullSchemaType extends BaseSchema<unknown, null> {
|
|
105
|
+
readonly type = "null";
|
|
106
|
+
constructor();
|
|
107
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, null>;
|
|
108
|
+
}
|
|
109
|
+
declare class UnionSchema<I, O> extends BaseSchema<I, O> {
|
|
110
|
+
private readonly schemas;
|
|
111
|
+
constructor(...schemas: Schema<I, any>[]);
|
|
112
|
+
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
113
|
+
}
|
|
114
|
+
declare class ArraySchema<I, O extends any[]> extends BaseSchema<I, O> {
|
|
115
|
+
private readonly innerSchema;
|
|
116
|
+
constructor(schema: Schema<I, O[number]>);
|
|
117
|
+
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
118
|
+
}
|
|
119
|
+
declare class InstanceOfSchema<I, O> extends BaseSchema<I, O> {
|
|
120
|
+
private readonly innerSchema;
|
|
121
|
+
private readonly classConstructor;
|
|
122
|
+
constructor(schema: Schema<I, any>, classConstructor: new (...args: any[]) => any);
|
|
123
|
+
readonly "~standard": StandardSchemaV1.Props<I, O>;
|
|
124
|
+
}
|
|
125
|
+
declare class ObjectSchemaType<T extends Record<string, unknown>> extends BaseSchema<unknown, T> {
|
|
126
|
+
readonly definition: SchemaDefinition;
|
|
127
|
+
constructor(definition: SchemaDefinition);
|
|
128
|
+
readonly "~standard": StandardSchemaV1.Props<unknown, T>;
|
|
129
|
+
}
|
|
130
|
+
type AnySchema = SchemaPrimitive | BaseSchema<any, any> | SchemaDefinition;
|
|
131
|
+
declare function toStandard<T>(schema: AnySchema): Schema<unknown, T>;
|
|
132
|
+
/**
|
|
133
|
+
* Create standard schema types
|
|
134
|
+
* @returns {typeof h} Standard schema types
|
|
135
|
+
*/
|
|
136
|
+
declare const h: {
|
|
137
|
+
/**
|
|
138
|
+
* Create string schema type
|
|
139
|
+
* @returns {StringSchemaType} String schema type
|
|
140
|
+
*/
|
|
141
|
+
string: () => StringSchemaType;
|
|
142
|
+
/**
|
|
143
|
+
* Create number schema type
|
|
144
|
+
* @returns {NumberSchemaType} Number schema type
|
|
145
|
+
*/
|
|
146
|
+
number: () => NumberSchemaType;
|
|
147
|
+
/**
|
|
148
|
+
* Create boolean schema type
|
|
149
|
+
* @returns {BooleanSchemaType} Boolean schema type
|
|
150
|
+
*/
|
|
151
|
+
boolean: () => BooleanSchemaType;
|
|
152
|
+
/**
|
|
153
|
+
* Create null schema type
|
|
154
|
+
* @returns {NullSchemaType} Null schema type
|
|
155
|
+
*/
|
|
156
|
+
null: () => NullSchemaType;
|
|
157
|
+
/**
|
|
158
|
+
* Create any schema type
|
|
159
|
+
* @returns {AnySchemaType} Any schema type
|
|
160
|
+
*/
|
|
161
|
+
any: () => AnySchemaType;
|
|
162
|
+
/**
|
|
163
|
+
* Create literal schema type
|
|
164
|
+
* @param {T} value - Literal value
|
|
165
|
+
* @returns {LiteralSchema<unknown, T>} Literal schema type
|
|
166
|
+
*/
|
|
167
|
+
literal: <T extends string | number | boolean>(value: T) => LiteralSchema<unknown, T>;
|
|
168
|
+
/**
|
|
169
|
+
* Create object schema type
|
|
170
|
+
* @param {S} [schemaDef] - Schema definition
|
|
171
|
+
* @returns {ObjectSchemaType<InferObject<S>>} Object schema type
|
|
172
|
+
*/
|
|
173
|
+
object: <S extends SchemaDefinition>(schemaDef?: S) => ObjectSchemaType<InferObject<S>>;
|
|
174
|
+
/**
|
|
175
|
+
* Create array schema type
|
|
176
|
+
* @param {S} schema - Schema
|
|
177
|
+
* @returns {ArraySchema<unknown, InferSchema<S>[]>} Array schema type
|
|
178
|
+
*/
|
|
179
|
+
array: <S extends AnySchema>(schema: S) => ArraySchema<unknown, SchemaType<S>[]>;
|
|
180
|
+
/**
|
|
181
|
+
* Create enum schema type from a list of string, number or boolean values.
|
|
182
|
+
* @param {Values} values - An array of literal values.
|
|
183
|
+
* @returns {UnionSchema<unknown, Values[number]>} A schema that validates against one of the provided literal values.
|
|
184
|
+
*/
|
|
185
|
+
enum: <T extends string | number | boolean, Values extends readonly [T, ...T[]]>(values: Values) => UnionSchema<unknown, Values[number]>;
|
|
186
|
+
/**
|
|
187
|
+
* Create optional schema type
|
|
188
|
+
* @param {S} schema - Schema
|
|
189
|
+
* @returns {OptionalSchema<unknown, InferSchema<S> | undefined>} Optional schema type
|
|
190
|
+
*/
|
|
191
|
+
optional: <S extends AnySchema>(schema: S) => OptionalSchema<unknown, InferSchema<S> | undefined>;
|
|
192
|
+
/**
|
|
193
|
+
* Create options schema type
|
|
194
|
+
* @param {S} schemas - Schemas
|
|
195
|
+
* @returns {UnionSchema<unknown, InferSchema<S[number]>>} Options schema type
|
|
196
|
+
*/
|
|
197
|
+
options: <S extends AnySchema[]>(...schemas: S) => UnionSchema<unknown, InferSchema<S[number]>>;
|
|
198
|
+
/**
|
|
199
|
+
* Create instance of schema type
|
|
200
|
+
* @param {C} constructor - Constructor function
|
|
201
|
+
* @returns {InstanceOfSchema<unknown, InstanceType<C>>} Instance of schema type
|
|
202
|
+
*/
|
|
203
|
+
instanceOf: <C extends new (...args: any[]) => any>(constructor: C) => InstanceOfSchema<unknown, InstanceType<C>>;
|
|
204
|
+
/**
|
|
205
|
+
* Create date schema type
|
|
206
|
+
* @returns {StringSchemaType} Date schema type
|
|
207
|
+
*/
|
|
208
|
+
date: () => StringSchemaType;
|
|
209
|
+
/**
|
|
210
|
+
* Create UUID schema type
|
|
211
|
+
* @returns {StringSchemaType} UUID schema type
|
|
212
|
+
*/
|
|
213
|
+
uuid: () => StringSchemaType;
|
|
214
|
+
/**
|
|
215
|
+
* Create regex schema type
|
|
216
|
+
* @param {RegExp} regex - Regex
|
|
217
|
+
* @returns {StringSchemaType} Regex schema type
|
|
218
|
+
*/
|
|
219
|
+
regex: (regex: RegExp) => StringSchemaType;
|
|
220
|
+
/**
|
|
221
|
+
* Create email schema type
|
|
222
|
+
* @returns {StringSchemaType} Email schema type
|
|
223
|
+
*/
|
|
224
|
+
email: () => StringSchemaType;
|
|
225
|
+
/**
|
|
226
|
+
* Create phone schema type
|
|
227
|
+
* @returns {StringSchemaType} Phone schema type
|
|
228
|
+
*/
|
|
229
|
+
phone: () => StringSchemaType;
|
|
230
|
+
/** Create domain schema type
|
|
231
|
+
* @param {boolean} requireHttpOrHttps - Require http or https
|
|
232
|
+
* @returns {StringSchemaType} Domain schema type
|
|
233
|
+
*/
|
|
234
|
+
domain: (requireHttpOrHttps?: boolean) => StringSchemaType;
|
|
235
|
+
/**
|
|
236
|
+
* Convert schema to standard schema
|
|
237
|
+
* @param {AnySchema} schema - Schema
|
|
238
|
+
* @returns {Schema<unknown, any>} Standard schema
|
|
239
|
+
*/
|
|
240
|
+
toStandard: typeof toStandard;
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { AnySchema, AnySchemaType, ArraySchema, BaseSchema, BooleanSchemaType, InstanceOfSchema, LiteralSchema, NullSchemaType, NumberSchemaType, ObjectSchemaType, OptionalSchema, StringSchemaType, UnionSchema, h };
|
|
244
|
+
//# sourceMappingURL=types.d.mts.map
|