@forklaunch/validator 0.3.13 → 0.4.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/lib/index-V6qNDTlr.d.mts +476 -0
- package/lib/index-V6qNDTlr.d.ts +476 -0
- package/lib/index.d.mts +6 -0
- package/lib/index.d.ts +6 -2
- package/lib/index.js +18 -1
- package/lib/index.mjs +0 -0
- package/lib/src/typebox/index.d.mts +220 -0
- package/lib/src/typebox/index.d.ts +220 -3
- package/lib/src/typebox/index.js +448 -1
- package/lib/src/typebox/index.mjs +406 -0
- package/lib/src/zod/index.d.mts +106 -0
- package/lib/src/zod/index.d.ts +106 -3
- package/lib/src/zod/index.js +291 -1
- package/lib/src/zod/index.mjs +244 -0
- package/lib/tests/utils/mockSchemaValidator.d.mts +69 -0
- package/lib/tests/utils/mockSchemaValidator.d.ts +29 -25
- package/lib/tests/utils/mockSchemaValidator.js +143 -79
- package/lib/tests/utils/mockSchemaValidator.mjs +99 -0
- package/package.json +21 -8
- package/lib/index.d.ts.map +0 -1
- package/lib/src/shared/types/schema.types.d.ts +0 -255
- package/lib/src/shared/types/schema.types.d.ts.map +0 -1
- package/lib/src/shared/types/schema.types.js +0 -1
- package/lib/src/typebox/index.d.ts.map +0 -1
- package/lib/src/typebox/staticSchemaValidator.d.ts +0 -99
- package/lib/src/typebox/staticSchemaValidator.d.ts.map +0 -1
- package/lib/src/typebox/staticSchemaValidator.js +0 -99
- package/lib/src/typebox/typeboxSchemaValidator.d.ts +0 -122
- package/lib/src/typebox/typeboxSchemaValidator.d.ts.map +0 -1
- package/lib/src/typebox/typeboxSchemaValidator.js +0 -362
- package/lib/src/typebox/types/schema.types.d.ts +0 -59
- package/lib/src/typebox/types/schema.types.d.ts.map +0 -1
- package/lib/src/typebox/types/schema.types.js +0 -1
- package/lib/src/zod/index.d.ts.map +0 -1
- package/lib/src/zod/staticSchemaValidator.d.ts +0 -99
- package/lib/src/zod/staticSchemaValidator.d.ts.map +0 -1
- package/lib/src/zod/staticSchemaValidator.js +0 -99
- package/lib/src/zod/types/schema.types.d.ts +0 -71
- package/lib/src/zod/types/schema.types.d.ts.map +0 -1
- package/lib/src/zod/types/schema.types.js +0 -1
- package/lib/src/zod/zodSchemaValidator.d.ts +0 -110
- package/lib/src/zod/zodSchemaValidator.d.ts.map +0 -1
- package/lib/src/zod/zodSchemaValidator.js +0 -192
- package/lib/tests/typebox/advancedParse.test.d.ts +0 -2
- package/lib/tests/typebox/advancedParse.test.d.ts.map +0 -1
- package/lib/tests/typebox/advancedParse.test.js +0 -514
- package/lib/tests/typebox/largeSchema.test.d.ts +0 -2
- package/lib/tests/typebox/largeSchema.test.d.ts.map +0 -1
- package/lib/tests/typebox/largeSchema.test.js +0 -150
- package/lib/tests/typebox/schemaValidator.test.d.ts +0 -2
- package/lib/tests/typebox/schemaValidator.test.d.ts.map +0 -1
- package/lib/tests/typebox/schemaValidator.test.js +0 -253
- package/lib/tests/typebox/typeEquality.test.d.ts +0 -2
- package/lib/tests/typebox/typeEquality.test.d.ts.map +0 -1
- package/lib/tests/typebox/typeEquality.test.js +0 -100
- package/lib/tests/utils/compare.d.ts +0 -2
- package/lib/tests/utils/compare.d.ts.map +0 -1
- package/lib/tests/utils/compare.js +0 -8
- package/lib/tests/utils/mockSchemaValidator.d.ts.map +0 -1
- package/lib/tests/zod/advancedParse.test.d.ts +0 -2
- package/lib/tests/zod/advancedParse.test.d.ts.map +0 -1
- package/lib/tests/zod/advancedParse.test.js +0 -514
- package/lib/tests/zod/largeSchema.test.d.ts +0 -2
- package/lib/tests/zod/largeSchema.test.d.ts.map +0 -1
- package/lib/tests/zod/largeSchema.test.js +0 -150
- package/lib/tests/zod/schemaValidator.test.d.ts +0 -2
- package/lib/tests/zod/schemaValidator.test.d.ts.map +0 -1
- package/lib/tests/zod/schemaValidator.test.js +0 -205
- package/lib/tests/zod/typeEquality.test.d.ts +0 -2
- package/lib/tests/zod/typeEquality.test.d.ts.map +0 -1
- package/lib/tests/zod/typeEquality.test.js +0 -100
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
|
+
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
3
|
+
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
4
|
+
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
5
|
+
import { S as SchemaValidator$1, T as TObject, e as TIdiomaticSchema, f as TResolve, g as TUnionContainer, h as UnionTResolve, L as LiteralSchema, P as ParseResult } from '../../index-V6qNDTlr.mjs';
|
|
6
|
+
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
7
|
+
import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TKind } from '@sinclair/typebox';
|
|
8
|
+
import '@forklaunch/common';
|
|
9
|
+
import 'zod';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a TypeBox schema definition.
|
|
13
|
+
* @implements {SchemaValidator}
|
|
14
|
+
*/
|
|
15
|
+
declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TObject<TProperties>>(schema: T) => TypeCheck<T>), <T extends TIdiomaticSchema>(schema: T) => TResolve<T>, <T extends TIdiomaticSchema>(schema: T) => TOptional<TResolve<T>>, <T extends TIdiomaticSchema>(schema: T) => TArray<TResolve<T>>, <T extends TUnionContainer>(schemas: [...T]) => TUnion<UnionTResolve<T>>, <T extends LiteralSchema>(value: T) => TLiteral<T>, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => TUnion<UnionTResolve<T[]>>, (value: unknown) => value is TSchema, <T extends TIdiomaticSchema>(schema: T, value: unknown) => boolean, <T extends TIdiomaticSchema>(schema: T, value: unknown) => ParseResult<TResolve<T>>, <T extends TIdiomaticSchema>(schema: T) => SchemaObject> {
|
|
16
|
+
_Type: 'TypeBox';
|
|
17
|
+
_SchemaCatchall: TKind;
|
|
18
|
+
_ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
|
|
19
|
+
string: _sinclair_typebox.TString;
|
|
20
|
+
uuid: _sinclair_typebox.TString;
|
|
21
|
+
uri: _sinclair_typebox.TString;
|
|
22
|
+
email: _sinclair_typebox.TString;
|
|
23
|
+
number: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TDate, _sinclair_typebox.TBigInt]>, number>;
|
|
24
|
+
bigint: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TBigInt, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TDate]>, bigint>;
|
|
25
|
+
boolean: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TBoolean, _sinclair_typebox.TString]>, boolean | undefined>;
|
|
26
|
+
date: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
|
|
27
|
+
symbol: _sinclair_typebox.TSymbol;
|
|
28
|
+
nullish: TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
|
|
29
|
+
any: _sinclair_typebox.TAny;
|
|
30
|
+
unknown: _sinclair_typebox.TUnknown;
|
|
31
|
+
never: _sinclair_typebox.TNever;
|
|
32
|
+
/**
|
|
33
|
+
* Extracts the error type of a schema for error messages.
|
|
34
|
+
*
|
|
35
|
+
* @param {TCatchall} schema - A schema that contains some type information.
|
|
36
|
+
* @returns The type of the schema for error messages.
|
|
37
|
+
*/
|
|
38
|
+
private errorType;
|
|
39
|
+
/**
|
|
40
|
+
* Pretty print TypeBox errors.
|
|
41
|
+
*
|
|
42
|
+
* @param {ValueError[]} errors
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
private prettyPrintTypeBoxErrors;
|
|
46
|
+
/**
|
|
47
|
+
* Compiles schema if this exists, for optimal performance.
|
|
48
|
+
*
|
|
49
|
+
* @param {TObject<TProperties>} schema - The schema to compile.
|
|
50
|
+
* @returns {TypeCheck<T>} - The compiled schema.
|
|
51
|
+
*/
|
|
52
|
+
compile<T extends TObject<TProperties>>(schema: T): TypeCheck<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Convert a schema to a TypeBox schema.
|
|
55
|
+
* @param {TIdiomaticSchema} schema - The schema to convert.
|
|
56
|
+
* @returns {TResolve<T>} The resolved schema.
|
|
57
|
+
*/
|
|
58
|
+
schemify<T extends TIdiomaticSchema>(schema: T): TResolve<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Make a schema optional.
|
|
61
|
+
* @param {TIdiomaticSchema} schema - The schema to make optional.
|
|
62
|
+
* @returns {TOptional<TResolve<T>>} The optional schema.
|
|
63
|
+
*/
|
|
64
|
+
optional<T extends TIdiomaticSchema>(schema: T): TOptional<TResolve<T>>;
|
|
65
|
+
/**
|
|
66
|
+
* Create an array schema.
|
|
67
|
+
* @param {TIdiomaticSchema} schema - The schema to use for array items.
|
|
68
|
+
* @returns {TArray<TResolve<T>>} The array schema.
|
|
69
|
+
*/
|
|
70
|
+
array<T extends TIdiomaticSchema>(schema: T): TArray<TResolve<T>>;
|
|
71
|
+
/**
|
|
72
|
+
* Create a union schema.
|
|
73
|
+
* @param {TUnionContainer} schemas - The schemas to union.
|
|
74
|
+
* @returns {TUnion<UnionTResolve<T>>} The union schema.
|
|
75
|
+
*
|
|
76
|
+
* WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
|
|
77
|
+
* This is a limitation of TypeBox. Consider using "optional" instead.
|
|
78
|
+
*/
|
|
79
|
+
union<T extends TUnionContainer>(schemas: [...T]): TUnion<UnionTResolve<T>>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a literal schema.
|
|
82
|
+
* @param {LiteralSchema} value - The literal value.
|
|
83
|
+
* @returns {TLiteral<T>} The literal schema.
|
|
84
|
+
*/
|
|
85
|
+
literal<T extends LiteralSchema>(value: T): TLiteral<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Create an enum schema.
|
|
88
|
+
* @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
|
|
89
|
+
* @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
|
|
90
|
+
*/
|
|
91
|
+
enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): TUnion<UnionTResolve<T[]>>;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a value is a TypeBox object schema.
|
|
94
|
+
* @param {unknown} value - The value to check.
|
|
95
|
+
* @returns {boolean} True if the value is a TypeBox object schema.
|
|
96
|
+
*/
|
|
97
|
+
isSchema(value: unknown): value is TSchema;
|
|
98
|
+
/**
|
|
99
|
+
* Validate a value against a schema.
|
|
100
|
+
*
|
|
101
|
+
* @param {TSchema} schema - The schema to validate against.
|
|
102
|
+
* @param {unknown} value - The value to validate.
|
|
103
|
+
* @returns {boolean} True if valid, otherwise false.
|
|
104
|
+
*/
|
|
105
|
+
validate<T extends TIdiomaticSchema | TSchema>(schema: T | TypeCheck<TResolve<T>>, value: unknown): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Parse a value against a schema.
|
|
108
|
+
*
|
|
109
|
+
* @param {TSchema} schema - The schema to validate against.
|
|
110
|
+
* @param {unknown} value - The value to validate.
|
|
111
|
+
* @returns {ParseResult<TResolve<T>>} The parsing result.
|
|
112
|
+
*/
|
|
113
|
+
parse<T extends TIdiomaticSchema | TSchema>(schema: T | TypeCheck<TResolve<T>>, value: unknown): ParseResult<TResolve<T>>;
|
|
114
|
+
/**
|
|
115
|
+
* Convert a schema to an OpenAPI schema object.
|
|
116
|
+
* @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
|
|
117
|
+
* @returns {SchemaObject} The OpenAPI schema object.
|
|
118
|
+
*/
|
|
119
|
+
openapi<T extends TIdiomaticSchema | TSchema>(schema: T): SchemaObject;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Factory function for creating a TypeboxSchemaValidator instance.
|
|
124
|
+
* @returns {TypeboxSchemaValidator} The TypeboxSchemaValidator instance.
|
|
125
|
+
*/
|
|
126
|
+
declare const SchemaValidator: () => TypeboxSchemaValidator;
|
|
127
|
+
/**
|
|
128
|
+
* TypeBox schema definition for string type.
|
|
129
|
+
*/
|
|
130
|
+
declare const string: _sinclair_typebox.TString;
|
|
131
|
+
/**
|
|
132
|
+
* TypeBox schema definition for UUID type.
|
|
133
|
+
*/
|
|
134
|
+
declare const uuid: _sinclair_typebox.TString;
|
|
135
|
+
/**
|
|
136
|
+
* TypeBox schema definition for URI type.
|
|
137
|
+
*/
|
|
138
|
+
declare const uri: _sinclair_typebox.TString;
|
|
139
|
+
/**
|
|
140
|
+
* TypeBox schema definition for email type.
|
|
141
|
+
*/
|
|
142
|
+
declare const email: _sinclair_typebox.TString;
|
|
143
|
+
/**
|
|
144
|
+
* TypeBox schema definition for number type.
|
|
145
|
+
*/
|
|
146
|
+
declare const number: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TDate, _sinclair_typebox.TBigInt]>, number>;
|
|
147
|
+
/**
|
|
148
|
+
* TypeBox schema definition for bigint type.
|
|
149
|
+
*/
|
|
150
|
+
declare const bigint: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TBigInt, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TDate]>, bigint>;
|
|
151
|
+
/**
|
|
152
|
+
* TypeBox schema definition for boolean type.
|
|
153
|
+
*/
|
|
154
|
+
declare const boolean: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TBoolean, _sinclair_typebox.TString]>, boolean | undefined>;
|
|
155
|
+
/**
|
|
156
|
+
* TypeBox schema definition for date type.
|
|
157
|
+
*/
|
|
158
|
+
declare const date: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
|
|
159
|
+
/**
|
|
160
|
+
* TypeBox schema definition for symbol type.
|
|
161
|
+
*/
|
|
162
|
+
declare const symbol: _sinclair_typebox.TSymbol;
|
|
163
|
+
/**
|
|
164
|
+
* TypeBox schema definition for undefined, null, void types.
|
|
165
|
+
*/
|
|
166
|
+
declare const nullish: _sinclair_typebox.TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
|
|
167
|
+
/**
|
|
168
|
+
* TypeBox schema definition for any type.
|
|
169
|
+
*/
|
|
170
|
+
declare const any: _sinclair_typebox.TAny;
|
|
171
|
+
/**
|
|
172
|
+
* TypeBox schema definition for unknown type.
|
|
173
|
+
*/
|
|
174
|
+
declare const unknown: _sinclair_typebox.TUnknown;
|
|
175
|
+
/**
|
|
176
|
+
* TypeBox schema definition for never type.
|
|
177
|
+
*/
|
|
178
|
+
declare const never: _sinclair_typebox.TNever;
|
|
179
|
+
/**
|
|
180
|
+
* Transforms valid schema into TypeBox schema.
|
|
181
|
+
*/
|
|
182
|
+
declare const schemify: <T extends TIdiomaticSchema>(schema: T) => TResolve<T>;
|
|
183
|
+
/**
|
|
184
|
+
* Makes a valid schema optional.
|
|
185
|
+
*/
|
|
186
|
+
declare const optional: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebox.TOptional<TResolve<T>>;
|
|
187
|
+
/**
|
|
188
|
+
* Defines an array for a valid schema.
|
|
189
|
+
*/
|
|
190
|
+
declare const array: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebox.TArray<TResolve<T>>;
|
|
191
|
+
/**
|
|
192
|
+
* Defines a union for a valid schema.
|
|
193
|
+
*/
|
|
194
|
+
declare const union: <T extends TUnionContainer>(schemas: [...T]) => _sinclair_typebox.TUnion<UnionTResolve<T>>;
|
|
195
|
+
/**
|
|
196
|
+
* Defines a literal for a valid schema.
|
|
197
|
+
*/
|
|
198
|
+
declare const literal: <T extends LiteralSchema>(value: T) => _sinclair_typebox.TLiteral<T>;
|
|
199
|
+
/**
|
|
200
|
+
* Defines an enum for a valid schema.
|
|
201
|
+
*/
|
|
202
|
+
declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => _sinclair_typebox.TUnion<UnionTResolve<T[]>>;
|
|
203
|
+
/**
|
|
204
|
+
* Checks if a value is a TypeBox schema.
|
|
205
|
+
*/
|
|
206
|
+
declare const isSchema: (value: unknown) => value is _sinclair_typebox.TSchema;
|
|
207
|
+
/**
|
|
208
|
+
* Validates a value against a valid schema.
|
|
209
|
+
*/
|
|
210
|
+
declare const validate: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Parses a value against a valid schema.
|
|
213
|
+
*/
|
|
214
|
+
declare const parse: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TResolve<T>>;
|
|
215
|
+
/**
|
|
216
|
+
* Generates an OpenAPI schema object from a valid schema.
|
|
217
|
+
*/
|
|
218
|
+
declare const openapi: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
|
|
219
|
+
|
|
220
|
+
export { SchemaValidator, TypeboxSchemaValidator, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
|
|
@@ -1,3 +1,220 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
|
+
import { SchemaObject } from 'openapi3-ts/oas31';
|
|
3
|
+
import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
|
|
4
|
+
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
5
|
+
import { S as SchemaValidator$1, T as TObject, e as TIdiomaticSchema, f as TResolve, g as TUnionContainer, h as UnionTResolve, L as LiteralSchema, P as ParseResult } from '../../index-V6qNDTlr.js';
|
|
6
|
+
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
7
|
+
import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TKind } from '@sinclair/typebox';
|
|
8
|
+
import '@forklaunch/common';
|
|
9
|
+
import 'zod';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a TypeBox schema definition.
|
|
13
|
+
* @implements {SchemaValidator}
|
|
14
|
+
*/
|
|
15
|
+
declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TObject<TProperties>>(schema: T) => TypeCheck<T>), <T extends TIdiomaticSchema>(schema: T) => TResolve<T>, <T extends TIdiomaticSchema>(schema: T) => TOptional<TResolve<T>>, <T extends TIdiomaticSchema>(schema: T) => TArray<TResolve<T>>, <T extends TUnionContainer>(schemas: [...T]) => TUnion<UnionTResolve<T>>, <T extends LiteralSchema>(value: T) => TLiteral<T>, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => TUnion<UnionTResolve<T[]>>, (value: unknown) => value is TSchema, <T extends TIdiomaticSchema>(schema: T, value: unknown) => boolean, <T extends TIdiomaticSchema>(schema: T, value: unknown) => ParseResult<TResolve<T>>, <T extends TIdiomaticSchema>(schema: T) => SchemaObject> {
|
|
16
|
+
_Type: 'TypeBox';
|
|
17
|
+
_SchemaCatchall: TKind;
|
|
18
|
+
_ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
|
|
19
|
+
string: _sinclair_typebox.TString;
|
|
20
|
+
uuid: _sinclair_typebox.TString;
|
|
21
|
+
uri: _sinclair_typebox.TString;
|
|
22
|
+
email: _sinclair_typebox.TString;
|
|
23
|
+
number: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TDate, _sinclair_typebox.TBigInt]>, number>;
|
|
24
|
+
bigint: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TBigInt, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TDate]>, bigint>;
|
|
25
|
+
boolean: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TBoolean, _sinclair_typebox.TString]>, boolean | undefined>;
|
|
26
|
+
date: _sinclair_typebox.TTransform<TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
|
|
27
|
+
symbol: _sinclair_typebox.TSymbol;
|
|
28
|
+
nullish: TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
|
|
29
|
+
any: _sinclair_typebox.TAny;
|
|
30
|
+
unknown: _sinclair_typebox.TUnknown;
|
|
31
|
+
never: _sinclair_typebox.TNever;
|
|
32
|
+
/**
|
|
33
|
+
* Extracts the error type of a schema for error messages.
|
|
34
|
+
*
|
|
35
|
+
* @param {TCatchall} schema - A schema that contains some type information.
|
|
36
|
+
* @returns The type of the schema for error messages.
|
|
37
|
+
*/
|
|
38
|
+
private errorType;
|
|
39
|
+
/**
|
|
40
|
+
* Pretty print TypeBox errors.
|
|
41
|
+
*
|
|
42
|
+
* @param {ValueError[]} errors
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
private prettyPrintTypeBoxErrors;
|
|
46
|
+
/**
|
|
47
|
+
* Compiles schema if this exists, for optimal performance.
|
|
48
|
+
*
|
|
49
|
+
* @param {TObject<TProperties>} schema - The schema to compile.
|
|
50
|
+
* @returns {TypeCheck<T>} - The compiled schema.
|
|
51
|
+
*/
|
|
52
|
+
compile<T extends TObject<TProperties>>(schema: T): TypeCheck<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Convert a schema to a TypeBox schema.
|
|
55
|
+
* @param {TIdiomaticSchema} schema - The schema to convert.
|
|
56
|
+
* @returns {TResolve<T>} The resolved schema.
|
|
57
|
+
*/
|
|
58
|
+
schemify<T extends TIdiomaticSchema>(schema: T): TResolve<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Make a schema optional.
|
|
61
|
+
* @param {TIdiomaticSchema} schema - The schema to make optional.
|
|
62
|
+
* @returns {TOptional<TResolve<T>>} The optional schema.
|
|
63
|
+
*/
|
|
64
|
+
optional<T extends TIdiomaticSchema>(schema: T): TOptional<TResolve<T>>;
|
|
65
|
+
/**
|
|
66
|
+
* Create an array schema.
|
|
67
|
+
* @param {TIdiomaticSchema} schema - The schema to use for array items.
|
|
68
|
+
* @returns {TArray<TResolve<T>>} The array schema.
|
|
69
|
+
*/
|
|
70
|
+
array<T extends TIdiomaticSchema>(schema: T): TArray<TResolve<T>>;
|
|
71
|
+
/**
|
|
72
|
+
* Create a union schema.
|
|
73
|
+
* @param {TUnionContainer} schemas - The schemas to union.
|
|
74
|
+
* @returns {TUnion<UnionTResolve<T>>} The union schema.
|
|
75
|
+
*
|
|
76
|
+
* WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
|
|
77
|
+
* This is a limitation of TypeBox. Consider using "optional" instead.
|
|
78
|
+
*/
|
|
79
|
+
union<T extends TUnionContainer>(schemas: [...T]): TUnion<UnionTResolve<T>>;
|
|
80
|
+
/**
|
|
81
|
+
* Create a literal schema.
|
|
82
|
+
* @param {LiteralSchema} value - The literal value.
|
|
83
|
+
* @returns {TLiteral<T>} The literal schema.
|
|
84
|
+
*/
|
|
85
|
+
literal<T extends LiteralSchema>(value: T): TLiteral<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Create an enum schema.
|
|
88
|
+
* @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
|
|
89
|
+
* @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
|
|
90
|
+
*/
|
|
91
|
+
enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): TUnion<UnionTResolve<T[]>>;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a value is a TypeBox object schema.
|
|
94
|
+
* @param {unknown} value - The value to check.
|
|
95
|
+
* @returns {boolean} True if the value is a TypeBox object schema.
|
|
96
|
+
*/
|
|
97
|
+
isSchema(value: unknown): value is TSchema;
|
|
98
|
+
/**
|
|
99
|
+
* Validate a value against a schema.
|
|
100
|
+
*
|
|
101
|
+
* @param {TSchema} schema - The schema to validate against.
|
|
102
|
+
* @param {unknown} value - The value to validate.
|
|
103
|
+
* @returns {boolean} True if valid, otherwise false.
|
|
104
|
+
*/
|
|
105
|
+
validate<T extends TIdiomaticSchema | TSchema>(schema: T | TypeCheck<TResolve<T>>, value: unknown): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Parse a value against a schema.
|
|
108
|
+
*
|
|
109
|
+
* @param {TSchema} schema - The schema to validate against.
|
|
110
|
+
* @param {unknown} value - The value to validate.
|
|
111
|
+
* @returns {ParseResult<TResolve<T>>} The parsing result.
|
|
112
|
+
*/
|
|
113
|
+
parse<T extends TIdiomaticSchema | TSchema>(schema: T | TypeCheck<TResolve<T>>, value: unknown): ParseResult<TResolve<T>>;
|
|
114
|
+
/**
|
|
115
|
+
* Convert a schema to an OpenAPI schema object.
|
|
116
|
+
* @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
|
|
117
|
+
* @returns {SchemaObject} The OpenAPI schema object.
|
|
118
|
+
*/
|
|
119
|
+
openapi<T extends TIdiomaticSchema | TSchema>(schema: T): SchemaObject;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Factory function for creating a TypeboxSchemaValidator instance.
|
|
124
|
+
* @returns {TypeboxSchemaValidator} The TypeboxSchemaValidator instance.
|
|
125
|
+
*/
|
|
126
|
+
declare const SchemaValidator: () => TypeboxSchemaValidator;
|
|
127
|
+
/**
|
|
128
|
+
* TypeBox schema definition for string type.
|
|
129
|
+
*/
|
|
130
|
+
declare const string: _sinclair_typebox.TString;
|
|
131
|
+
/**
|
|
132
|
+
* TypeBox schema definition for UUID type.
|
|
133
|
+
*/
|
|
134
|
+
declare const uuid: _sinclair_typebox.TString;
|
|
135
|
+
/**
|
|
136
|
+
* TypeBox schema definition for URI type.
|
|
137
|
+
*/
|
|
138
|
+
declare const uri: _sinclair_typebox.TString;
|
|
139
|
+
/**
|
|
140
|
+
* TypeBox schema definition for email type.
|
|
141
|
+
*/
|
|
142
|
+
declare const email: _sinclair_typebox.TString;
|
|
143
|
+
/**
|
|
144
|
+
* TypeBox schema definition for number type.
|
|
145
|
+
*/
|
|
146
|
+
declare const number: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull, _sinclair_typebox.TDate, _sinclair_typebox.TBigInt]>, number>;
|
|
147
|
+
/**
|
|
148
|
+
* TypeBox schema definition for bigint type.
|
|
149
|
+
*/
|
|
150
|
+
declare const bigint: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TBigInt, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TDate]>, bigint>;
|
|
151
|
+
/**
|
|
152
|
+
* TypeBox schema definition for boolean type.
|
|
153
|
+
*/
|
|
154
|
+
declare const boolean: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TBoolean, _sinclair_typebox.TString]>, boolean | undefined>;
|
|
155
|
+
/**
|
|
156
|
+
* TypeBox schema definition for date type.
|
|
157
|
+
*/
|
|
158
|
+
declare const date: _sinclair_typebox.TTransform<_sinclair_typebox.TUnion<[_sinclair_typebox.TDate, _sinclair_typebox.TNumber, _sinclair_typebox.TString, _sinclair_typebox.TBoolean, _sinclair_typebox.TNull]>, Date>;
|
|
159
|
+
/**
|
|
160
|
+
* TypeBox schema definition for symbol type.
|
|
161
|
+
*/
|
|
162
|
+
declare const symbol: _sinclair_typebox.TSymbol;
|
|
163
|
+
/**
|
|
164
|
+
* TypeBox schema definition for undefined, null, void types.
|
|
165
|
+
*/
|
|
166
|
+
declare const nullish: _sinclair_typebox.TUnion<[_sinclair_typebox.TVoid, _sinclair_typebox.TNull, _sinclair_typebox.TUndefined]>;
|
|
167
|
+
/**
|
|
168
|
+
* TypeBox schema definition for any type.
|
|
169
|
+
*/
|
|
170
|
+
declare const any: _sinclair_typebox.TAny;
|
|
171
|
+
/**
|
|
172
|
+
* TypeBox schema definition for unknown type.
|
|
173
|
+
*/
|
|
174
|
+
declare const unknown: _sinclair_typebox.TUnknown;
|
|
175
|
+
/**
|
|
176
|
+
* TypeBox schema definition for never type.
|
|
177
|
+
*/
|
|
178
|
+
declare const never: _sinclair_typebox.TNever;
|
|
179
|
+
/**
|
|
180
|
+
* Transforms valid schema into TypeBox schema.
|
|
181
|
+
*/
|
|
182
|
+
declare const schemify: <T extends TIdiomaticSchema>(schema: T) => TResolve<T>;
|
|
183
|
+
/**
|
|
184
|
+
* Makes a valid schema optional.
|
|
185
|
+
*/
|
|
186
|
+
declare const optional: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebox.TOptional<TResolve<T>>;
|
|
187
|
+
/**
|
|
188
|
+
* Defines an array for a valid schema.
|
|
189
|
+
*/
|
|
190
|
+
declare const array: <T extends TIdiomaticSchema>(schema: T) => _sinclair_typebox.TArray<TResolve<T>>;
|
|
191
|
+
/**
|
|
192
|
+
* Defines a union for a valid schema.
|
|
193
|
+
*/
|
|
194
|
+
declare const union: <T extends TUnionContainer>(schemas: [...T]) => _sinclair_typebox.TUnion<UnionTResolve<T>>;
|
|
195
|
+
/**
|
|
196
|
+
* Defines a literal for a valid schema.
|
|
197
|
+
*/
|
|
198
|
+
declare const literal: <T extends LiteralSchema>(value: T) => _sinclair_typebox.TLiteral<T>;
|
|
199
|
+
/**
|
|
200
|
+
* Defines an enum for a valid schema.
|
|
201
|
+
*/
|
|
202
|
+
declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => _sinclair_typebox.TUnion<UnionTResolve<T[]>>;
|
|
203
|
+
/**
|
|
204
|
+
* Checks if a value is a TypeBox schema.
|
|
205
|
+
*/
|
|
206
|
+
declare const isSchema: (value: unknown) => value is _sinclair_typebox.TSchema;
|
|
207
|
+
/**
|
|
208
|
+
* Validates a value against a valid schema.
|
|
209
|
+
*/
|
|
210
|
+
declare const validate: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Parses a value against a valid schema.
|
|
213
|
+
*/
|
|
214
|
+
declare const parse: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T | _sinclair_typebox_compiler.TypeCheck<TResolve<T>>, value: unknown) => ParseResult<TResolve<T>>;
|
|
215
|
+
/**
|
|
216
|
+
* Generates an OpenAPI schema object from a valid schema.
|
|
217
|
+
*/
|
|
218
|
+
declare const openapi: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
|
|
219
|
+
|
|
220
|
+
export { SchemaValidator, TypeboxSchemaValidator, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
|