@forklaunch/validator 0.3.1 → 0.3.3

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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/lib/eslint.config.d.mts +3 -0
  3. package/lib/eslint.config.d.mts.map +1 -0
  4. package/lib/eslint.config.mjs +10 -0
  5. package/lib/index.d.ts +2 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +1 -0
  8. package/lib/jest.config.d.ts +4 -0
  9. package/lib/jest.config.d.ts.map +1 -0
  10. package/lib/jest.config.js +19 -0
  11. package/{dist → lib/src/shared}/types/schema.types.d.ts +47 -7
  12. package/lib/src/shared/types/schema.types.d.ts.map +1 -0
  13. package/lib/src/typebox/index.d.ts +3 -0
  14. package/lib/src/typebox/index.d.ts.map +1 -0
  15. package/lib/src/typebox/index.js +1 -0
  16. package/lib/src/typebox/staticSchemaValidator.d.ts +93 -0
  17. package/lib/src/typebox/staticSchemaValidator.d.ts.map +1 -0
  18. package/lib/src/typebox/staticSchemaValidator.js +91 -0
  19. package/lib/src/typebox/typeboxSchemaValidator.d.ts +110 -0
  20. package/lib/src/typebox/typeboxSchemaValidator.d.ts.map +1 -0
  21. package/lib/src/typebox/typeboxSchemaValidator.js +343 -0
  22. package/{dist/typebox/types/typebox.schema.types.d.ts → lib/src/typebox/types/schema.types.d.ts} +9 -13
  23. package/lib/src/typebox/types/schema.types.d.ts.map +1 -0
  24. package/lib/src/zod/index.d.ts +3 -0
  25. package/lib/src/zod/index.d.ts.map +1 -0
  26. package/lib/src/zod/index.js +1 -0
  27. package/lib/src/zod/staticSchemaValidator.d.ts +93 -0
  28. package/lib/src/zod/staticSchemaValidator.d.ts.map +1 -0
  29. package/lib/src/zod/staticSchemaValidator.js +91 -0
  30. package/{dist/zod/types/zod.schema.types.d.ts → lib/src/zod/types/schema.types.d.ts} +3 -2
  31. package/lib/src/zod/types/schema.types.d.ts.map +1 -0
  32. package/lib/src/zod/types/schema.types.js +1 -0
  33. package/lib/src/zod/zodSchemaValidator.d.ts +98 -0
  34. package/lib/src/zod/zodSchemaValidator.d.ts.map +1 -0
  35. package/lib/src/zod/zodSchemaValidator.js +179 -0
  36. package/lib/tests/typebox/advancedParse.test.d.ts +2 -0
  37. package/lib/tests/typebox/advancedParse.test.d.ts.map +1 -0
  38. package/lib/tests/typebox/advancedParse.test.js +514 -0
  39. package/lib/tests/typebox/largeSchema.test.d.ts +2 -0
  40. package/lib/tests/typebox/largeSchema.test.d.ts.map +1 -0
  41. package/{dist → lib}/tests/typebox/largeSchema.test.js +46 -49
  42. package/lib/tests/typebox/schemaValidator.test.d.ts +2 -0
  43. package/lib/tests/typebox/schemaValidator.test.d.ts.map +1 -0
  44. package/lib/tests/typebox/schemaValidator.test.js +219 -0
  45. package/{dist/tests/typebox/equality.test.d.ts → lib/tests/typebox/typeEquality.test.d.ts} +1 -0
  46. package/lib/tests/typebox/typeEquality.test.d.ts.map +1 -0
  47. package/lib/tests/typebox/typeEquality.test.js +100 -0
  48. package/lib/tests/utils/compare.d.ts +2 -0
  49. package/lib/tests/utils/compare.d.ts.map +1 -0
  50. package/lib/tests/utils/compare.js +8 -0
  51. package/{dist/tests → lib/tests/utils}/mockSchemaValidator.d.ts +14 -8
  52. package/lib/tests/utils/mockSchemaValidator.d.ts.map +1 -0
  53. package/lib/tests/utils/mockSchemaValidator.js +72 -0
  54. package/lib/tests/zod/advancedParse.test.d.ts +2 -0
  55. package/lib/tests/zod/advancedParse.test.d.ts.map +1 -0
  56. package/lib/tests/zod/advancedParse.test.js +514 -0
  57. package/lib/tests/zod/largeSchema.test.d.ts +2 -0
  58. package/lib/tests/zod/largeSchema.test.d.ts.map +1 -0
  59. package/{dist → lib}/tests/zod/largeSchema.test.js +43 -46
  60. package/lib/tests/zod/schemaValidator.test.d.ts +2 -0
  61. package/lib/tests/zod/schemaValidator.test.d.ts.map +1 -0
  62. package/lib/tests/zod/schemaValidator.test.js +179 -0
  63. package/{dist/tests/zod/equality.test.d.ts → lib/tests/zod/typeEquality.test.d.ts} +1 -0
  64. package/lib/tests/zod/typeEquality.test.d.ts.map +1 -0
  65. package/lib/tests/zod/typeEquality.test.js +100 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -0
  67. package/lib/vitest.config.d.ts +3 -0
  68. package/lib/vitest.config.d.ts.map +1 -0
  69. package/lib/vitest.config.js +7 -0
  70. package/package.json +35 -39
  71. package/dist/index.d.ts +0 -1
  72. package/dist/index.js +0 -18
  73. package/dist/index.js.map +0 -1
  74. package/dist/jest.config.d.ts +0 -3
  75. package/dist/jest.config.js +0 -10
  76. package/dist/jest.config.js.map +0 -1
  77. package/dist/tests/mockSchemaValidator.js +0 -60
  78. package/dist/tests/mockSchemaValidator.js.map +0 -1
  79. package/dist/tests/typebox/equality.test.js +0 -234
  80. package/dist/tests/typebox/equality.test.js.map +0 -1
  81. package/dist/tests/typebox/largeSchema.test.js.map +0 -1
  82. package/dist/tests/zod/equality.test.js +0 -238
  83. package/dist/tests/zod/equality.test.js.map +0 -1
  84. package/dist/tests/zod/largeSchema.test.js.map +0 -1
  85. package/dist/typebox/index.d.ts +0 -1
  86. package/dist/typebox/index.js +0 -18
  87. package/dist/typebox/index.js.map +0 -1
  88. package/dist/typebox/typebox.schemaValidator.d.ts +0 -150
  89. package/dist/typebox/typebox.schemaValidator.js +0 -203
  90. package/dist/typebox/typebox.schemaValidator.js.map +0 -1
  91. package/dist/typebox/types/typebox.schema.types.js +0 -3
  92. package/dist/typebox/types/typebox.schema.types.js.map +0 -1
  93. package/dist/types/index.d.ts +0 -1
  94. package/dist/types/index.js +0 -18
  95. package/dist/types/index.js.map +0 -1
  96. package/dist/types/schema.types.js +0 -3
  97. package/dist/types/schema.types.js.map +0 -1
  98. package/dist/zod/index.d.ts +0 -1
  99. package/dist/zod/index.js +0 -18
  100. package/dist/zod/index.js.map +0 -1
  101. package/dist/zod/types/zod.schema.types.js +0 -3
  102. package/dist/zod/types/zod.schema.types.js.map +0 -1
  103. package/dist/zod/zod.schemaValidator.d.ts +0 -147
  104. package/dist/zod/zod.schemaValidator.js +0 -196
  105. package/dist/zod/zod.schemaValidator.js.map +0 -1
  106. /package/{dist/tests/typebox/largeSchema.test.d.ts → lib/src/shared/types/schema.types.js} +0 -0
  107. /package/{dist/tests/zod/largeSchema.test.d.ts → lib/src/typebox/types/schema.types.js} +0 -0
@@ -0,0 +1,343 @@
1
+ /**
2
+ * This module provides a TypeScript-based schema definition using the TypeBox library.
3
+ * It includes various types, schema creation, validation, and OpenAPI integration.
4
+ *
5
+ * @module TypeboxSchemaValidator
6
+ */
7
+ import { Kind, KindGuard, Type } from '@sinclair/typebox';
8
+ import { TypeCheck, TypeCompiler } from '@sinclair/typebox/compiler';
9
+ import { DefaultErrorFunction, SetErrorFunction, ValueErrorType } from '@sinclair/typebox/errors';
10
+ import { Value } from '@sinclair/typebox/value';
11
+ /**
12
+ * Typebox custom error function
13
+ */
14
+ SetErrorFunction((params) => {
15
+ switch (params.errorType) {
16
+ case ValueErrorType.Union:
17
+ case ValueErrorType.Array:
18
+ case ValueErrorType.String:
19
+ case ValueErrorType.Number:
20
+ return params.schema.errorType
21
+ ? `Expected ${params.schema.errorType} value${params.schema.errorSuffix ? 's' : ''}`
22
+ : DefaultErrorFunction(params);
23
+ default:
24
+ return DefaultErrorFunction(params);
25
+ }
26
+ });
27
+ /**
28
+ * Class representing a TypeBox schema definition.
29
+ * @implements {SchemaValidator}
30
+ */
31
+ export class TypeboxSchemaValidator {
32
+ _Type;
33
+ _SchemaCatchall;
34
+ _ValidSchemaObject;
35
+ string = Type.String();
36
+ // uuid = Type.String({ format: 'uuid' });
37
+ uuid = Type.String({
38
+ pattern: '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$',
39
+ errorType: 'uuid'
40
+ });
41
+ uri = Type.String({
42
+ pattern: '^[a-zA-Z][a-zA-Z\\d+-.]*:[^\\s]*$',
43
+ errorType: 'uri'
44
+ });
45
+ email = Type.String({
46
+ pattern: '(?:[a-z0-9!#$%&\'*+/=?^_{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)])',
47
+ errorType: 'email'
48
+ });
49
+ number = Type.Transform(Type.Union([
50
+ Type.Number(),
51
+ Type.String({ pattern: '^[0-9]+$' }),
52
+ Type.Boolean(),
53
+ Type.Null(),
54
+ Type.Date(),
55
+ Type.BigInt()
56
+ ], {
57
+ errorType: 'number-like',
58
+ openapiType: Type.Number()
59
+ }))
60
+ .Decode((value) => {
61
+ if (typeof value !== 'number') {
62
+ const num = Number(value);
63
+ if (isNaN(num)) {
64
+ throw new Error('Invalid number');
65
+ }
66
+ else {
67
+ return num;
68
+ }
69
+ }
70
+ return value;
71
+ })
72
+ .Encode(Number);
73
+ bigint = Type.Transform(Type.Union([
74
+ Type.BigInt(),
75
+ Type.Number(),
76
+ Type.String({ pattern: '^[0-9]+$' }),
77
+ Type.Boolean(),
78
+ Type.Date()
79
+ ], {
80
+ errorType: 'BigInt-like',
81
+ openapiType: Type.BigInt()
82
+ }))
83
+ .Decode((value) => {
84
+ if (typeof value !== 'bigint') {
85
+ try {
86
+ return BigInt(value instanceof Date ? value.getTime() : value);
87
+ }
88
+ catch (error) {
89
+ throw new Error('Invalid bigint');
90
+ }
91
+ }
92
+ return value;
93
+ })
94
+ .Encode(BigInt);
95
+ boolean = Type.Transform(Type.Union([
96
+ Type.Boolean(),
97
+ Type.String({
98
+ pattern: '^(t|T)(r|R)(u|U)(e|E)$|^(f|F)(a|A)(l|L)(s|S)(e|E)$'
99
+ })
100
+ ], {
101
+ errorType: 'boolean-like',
102
+ openapiType: Type.Boolean()
103
+ }))
104
+ .Decode((value) => {
105
+ if (typeof value === 'string') {
106
+ if (value.toLowerCase() === 'true')
107
+ return true;
108
+ if (value.toLowerCase() === 'false')
109
+ return false;
110
+ }
111
+ else {
112
+ return value;
113
+ }
114
+ })
115
+ .Encode(Boolean);
116
+ date = Type.Transform(Type.Union([
117
+ Type.Date(),
118
+ Type.Number(),
119
+ Type.String({
120
+ pattern: '^\\d{4}(-\\d{2}){0,2}(T\\d{2}:\\d{2}(:\\d{2}(\\.\\d{1,3})?)?(Z|([+-]\\d{2}:\\d{2}))?)?$|^\\d{1,2}\\/\\d{1,2}\\/\\d{4}$|^\\d{4}\\/\\d{1,2}\\/\\d{1,2}$|^\\d+$'
121
+ }),
122
+ Type.Boolean(),
123
+ Type.Null()
124
+ ], {
125
+ errorType: 'date',
126
+ openapiType: Type.Date()
127
+ }))
128
+ .Decode((value) => {
129
+ if (!(value instanceof Date)) {
130
+ if (value === null || typeof value === 'boolean') {
131
+ return new Date(value ? 1 : 0);
132
+ }
133
+ return new Date(value);
134
+ }
135
+ return value;
136
+ })
137
+ .Encode((value) => new Date(value));
138
+ symbol = Type.Symbol();
139
+ nullish = Type.Union([Type.Void(), Type.Null(), Type.Undefined()], {
140
+ errorType: 'nullish'
141
+ });
142
+ any = Type.Any();
143
+ unknown = Type.Unknown();
144
+ never = Type.Never();
145
+ /**
146
+ * Extracts the error type of a schema for error messages.
147
+ *
148
+ * @param {TCatchall} schema - A schema that contains some type information.
149
+ * @returns The type of the schema for error messages.
150
+ */
151
+ errorType(schema) {
152
+ if (Object.hasOwn(schema, 'errorType')) {
153
+ return schema.errorType;
154
+ }
155
+ return schema[Kind].toLowerCase();
156
+ }
157
+ /**
158
+ * Pretty print TypeBox errors.
159
+ *
160
+ * @param {ValueError[]} errors
161
+ * @returns
162
+ */
163
+ prettyPrintTypeBoxErrors(errors) {
164
+ if (!errors || errors.length === 0)
165
+ return;
166
+ const errorMessages = errors.map((err, index) => {
167
+ const path = err.path.length > 0 ? err.path.split('/').slice(1).join(' > ') : 'root';
168
+ return `${index + 1}. Path: ${path}\n Message: ${err.message}`;
169
+ });
170
+ return `Validation failed with the following errors:\n${errorMessages.join('\n\n')}`;
171
+ }
172
+ /**
173
+ * Compiles schema if this exists, for optimal performance.
174
+ *
175
+ * @param {TObject<TProperties>} schema - The schema to compile.
176
+ * @returns {TypeCheck<T>} - The compiled schema.
177
+ */
178
+ compile(schema) {
179
+ return TypeCompiler.Compile(schema);
180
+ }
181
+ /**
182
+ * Convert a schema to a TypeBox schema.
183
+ * @param {TIdiomaticSchema} schema - The schema to convert.
184
+ * @returns {TResolve<T>} The resolved schema.
185
+ */
186
+ schemify(schema) {
187
+ if (typeof schema === 'string' ||
188
+ typeof schema === 'number' ||
189
+ typeof schema === 'boolean') {
190
+ return Type.Literal(schema);
191
+ }
192
+ if (KindGuard.IsSchema(schema) || schema instanceof TypeCheck) {
193
+ return schema;
194
+ }
195
+ const newSchema = {};
196
+ Object.getOwnPropertyNames(schema).forEach((key) => {
197
+ if (KindGuard.IsSchema(schema[key])) {
198
+ newSchema[key] = schema[key];
199
+ }
200
+ else {
201
+ const schemified = this.schemify(schema[key]);
202
+ newSchema[key] = schemified;
203
+ }
204
+ });
205
+ return Type.Object(newSchema);
206
+ }
207
+ /**
208
+ * Make a schema optional.
209
+ * @param {TIdiomaticSchema} schema - The schema to make optional.
210
+ * @returns {TOptional<TResolve<T>>} The optional schema.
211
+ */
212
+ optional(schema) {
213
+ const schemified = KindGuard.IsSchema(schema)
214
+ ? schema
215
+ : this.schemify(schema);
216
+ return Type.Optional(schemified);
217
+ }
218
+ /**
219
+ * Create an array schema.
220
+ * @param {TIdiomaticSchema} schema - The schema to use for array items.
221
+ * @returns {TArray<TResolve<T>>} The array schema.
222
+ */
223
+ array(schema) {
224
+ const schemified = KindGuard.IsSchema(schema)
225
+ ? schema
226
+ : this.schemify(schema);
227
+ return Type.Array(schemified, {
228
+ errorType: `array of ${this.errorType(schemified)}`
229
+ });
230
+ }
231
+ /**
232
+ * Create a union schema.
233
+ * @param {TUnionContainer} schemas - The schemas to union.
234
+ * @returns {TUnion<UnionTResolve<T>>} The union schema.
235
+ *
236
+ * WARNING: If "nullish" or TUndefined is included in the union, the key will still be expected.
237
+ * This is a limitation of TypeBox. Consider using "optional" instead.
238
+ */
239
+ union(schemas) {
240
+ const unionTypes = schemas.map((schema) => {
241
+ return KindGuard.IsSchema(schema) ? schema : this.schemify(schema);
242
+ });
243
+ return Type.Union(unionTypes, {
244
+ errorType: `any of ${unionTypes
245
+ .map((s) => this.errorType(s))
246
+ .join(', ')}`,
247
+ errorSuffix: true
248
+ });
249
+ }
250
+ /**
251
+ * Create a literal schema.
252
+ * @param {LiteralSchema} value - The literal value.
253
+ * @returns {TLiteral<T>} The literal schema.
254
+ */
255
+ literal(value) {
256
+ return Type.Literal(value, {
257
+ errorType: `literal "${value}"`
258
+ });
259
+ }
260
+ /**
261
+ * Validate a value against a schema.
262
+ *
263
+ * @param {TSchema} schema - The schema to validate against.
264
+ * @param {unknown} value - The value to validate.
265
+ * @returns {boolean} True if valid, otherwise false.
266
+ */
267
+ validate(schema, value) {
268
+ if (schema instanceof TypeCheck) {
269
+ return schema.Check(value);
270
+ }
271
+ else {
272
+ const schemified = KindGuard.IsSchema(schema)
273
+ ? schema
274
+ : this.schemify(schema);
275
+ return Value.Check(schemified, value);
276
+ }
277
+ }
278
+ /**
279
+ * Parse a value against a schema.
280
+ *
281
+ * @param {TSchema} schema - The schema to validate against.
282
+ * @param {unknown} value - The value to validate.
283
+ * @returns {ParseResult<TResolve<T>>} The parsing result.
284
+ */
285
+ parse(schema, value) {
286
+ let errors = [];
287
+ let conversion;
288
+ if (schema instanceof TypeCheck) {
289
+ if (schema.Check(value)) {
290
+ conversion = schema.Decode(value);
291
+ }
292
+ else {
293
+ errors = Array.from(schema.Errors(value));
294
+ }
295
+ }
296
+ else {
297
+ const schemified = KindGuard.IsSchema(schema)
298
+ ? schema
299
+ : this.schemify(schema);
300
+ if (Value.Check(schemified, value)) {
301
+ conversion = Value.Decode(schemified, value);
302
+ }
303
+ else {
304
+ errors = Array.from(Value.Errors(schemified, value));
305
+ }
306
+ }
307
+ return errors != null && errors.length === 0
308
+ ? {
309
+ ok: true,
310
+ value: conversion
311
+ }
312
+ : {
313
+ ok: false,
314
+ error: this.prettyPrintTypeBoxErrors(errors)
315
+ };
316
+ }
317
+ /**
318
+ * Convert a schema to an OpenAPI schema object.
319
+ * @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
320
+ * @returns {SchemaObject} The OpenAPI schema object.
321
+ */
322
+ openapi(schema) {
323
+ const schemified = KindGuard.IsSchema(schema)
324
+ ? schema
325
+ : this.schemify(schema);
326
+ if (Object.hasOwn(schemified, 'openapiType') ||
327
+ KindGuard.IsLiteral(schemified)) {
328
+ return schemified.openapiType;
329
+ }
330
+ const newSchema = Object.assign({}, schemified);
331
+ if (Object.hasOwn(newSchema, 'properties')) {
332
+ newSchema.properties = { ...schemified.properties };
333
+ if (newSchema.properties) {
334
+ Object.entries(newSchema.properties).forEach(([key, value]) => {
335
+ if (KindGuard.IsSchema(value) && newSchema.properties) {
336
+ newSchema.properties[key] = this.openapi(value);
337
+ }
338
+ });
339
+ }
340
+ }
341
+ return newSchema;
342
+ }
343
+ }
@@ -1,5 +1,6 @@
1
- import { TObject as OriginalTObject, Static, TArray, TKind, TLiteral, TNever, TProperties, TSchema, TUnknown } from '@sinclair/typebox';
2
- import { Increment, KeyTypes, LiteralSchema } from '../../types/schema.types';
1
+ import { TObject as OriginalTObject, StaticDecode, TArray, TKind, TLiteral, TNever, TProperties, TSchema, TUnknown } from '@sinclair/typebox';
2
+ import { TypeCheck } from '@sinclair/typebox/compiler';
3
+ import { Increment, KeyTypes, LiteralSchema } from '../../shared/types/schema.types';
3
4
  /**
4
5
  * Represents a catch-all schema type.
5
6
  */
@@ -25,7 +26,7 @@ export type TObject<T> = T extends TObjectShape ? OriginalTObject<T> : TNever;
25
26
  *
26
27
  * @template T - The schema type to translate.
27
28
  */
28
- export type TSchemaTranslate<T> = T extends TCatchall ? Static<T> : TNever;
29
+ export type TSchemaTranslate<T> = T extends TCatchall ? StaticDecode<T> : TNever;
29
30
  /**
30
31
  * Represents an unboxed object schema where each key can have an idiomatic schema.
31
32
  */
@@ -45,19 +46,14 @@ export type TUnionContainer = [...TIdiomaticSchema[]];
45
46
  *
46
47
  * @template T - The union container to resolve.
47
48
  */
48
- export type UnionTResolve<T extends TUnionContainer> = T extends [
49
- ...infer A extends TIdiomaticSchema[]
50
- ] ? [
51
- ...{
52
- [K in keyof A]: TResolve<A[K]>;
53
- }
54
- ] : [];
49
+ export type UnionTResolve<T extends TUnionContainer> = T extends (infer UnionTypes)[] ? [TResolve<UnionTypes>] : TNever;
55
50
  /**
56
- * Resolves a schema type T to its resolved type. The depth is limited to 22 to prevent infinite recursion.
51
+ * Resolves a schema type T to its resolved type. The depth is limited to 12 to prevent infinite recursion, due to StaticDecode limitations.
57
52
  *
58
53
  * @template T - The schema type to resolve.
59
54
  * @template Depth - The current depth of the resolution.
60
55
  */
61
- export type TResolve<T, Depth extends number = 0> = Depth extends 22 ? TUnknown : T extends LiteralSchema ? TLiteral<T> : T extends TKind ? T : T extends TObject<TObjectShape> ? T : T extends UnboxedTObjectSchema ? TObject<{
56
+ export type TResolve<T, Depth extends number = 0> = Depth extends 12 ? TUnknown : T extends LiteralSchema ? TLiteral<T> : T extends TSchema ? T : T extends TKind ? T : T extends TObject<TObjectShape> ? T : T extends UnboxedTObjectSchema ? TObject<{
62
57
  [K in keyof T]: TResolve<T[K], Increment<Depth>>;
63
- }> : TNever;
58
+ }> : T extends TypeCheck<infer Type> ? TResolve<Type, Increment<Depth>> : TNever;
59
+ //# sourceMappingURL=schema.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.types.d.ts","sourceRoot":"","sources":["../../../../src/typebox/types/schema.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,eAAe,EAC1B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,QAAQ,EACR,MAAM,EACN,WAAW,EACX,OAAO,EACP,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EACL,SAAS,EACT,QAAQ,EACR,aAAa,EACd,MAAM,iCAAiC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAEhC;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IACvB,CAAC,SAAS,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAE9E;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,YAAY,CAAC,CAAC,CAAC,GACf,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,CAAC,GAAG,EAAE,QAAQ,GAAG,gBAAgB,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,aAAa,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,gBAAgB,EAAE,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,eAAe,IACjD,CAAC,SAAS,CAAC,MAAM,UAAU,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,GAChE,QAAQ,GACR,CAAC,SAAS,aAAa,GACrB,QAAQ,CAAC,CAAC,CAAC,GACX,CAAC,SAAS,OAAO,GACf,CAAC,GACD,CAAC,SAAS,KAAK,GACb,CAAC,GACD,CAAC,SAAS,OAAO,CAAC,YAAY,CAAC,GAC7B,CAAC,GACD,CAAC,SAAS,oBAAoB,GAC5B,OAAO,CAAC;KACL,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;CACjD,CAAC,GACF,CAAC,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,GAC7B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,GAChC,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './staticSchemaValidator';
2
+ export type { ZodSchemaValidator } from './zodSchemaValidator';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/zod/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './staticSchemaValidator';
@@ -0,0 +1,93 @@
1
+ import { ZodSchemaValidator } from './zodSchemaValidator';
2
+ /**
3
+ * Factory function for creating a ZodSchemaValidator instance.
4
+ * @returns {ZodSchemaValidator} The ZodSchemaValidator instance.
5
+ */
6
+ export declare const SchemaValidator: () => ZodSchemaValidator;
7
+ declare const StaticSchemaValidator: ZodSchemaValidator;
8
+ /**
9
+ * Zod schema definition for string type.
10
+ */
11
+ export declare const string: typeof StaticSchemaValidator.string;
12
+ /**
13
+ * Zod schema definition for UUID type.
14
+ */
15
+ export declare const uuid: typeof StaticSchemaValidator.uuid;
16
+ /**
17
+ * Zod schema definition for email type.
18
+ */
19
+ export declare const email: typeof StaticSchemaValidator.email;
20
+ /**
21
+ * Zod schema definition for URI type.
22
+ */
23
+ export declare const uri: typeof StaticSchemaValidator.uri;
24
+ /**
25
+ * Zod schema definition for number type.
26
+ */
27
+ export declare const number: typeof StaticSchemaValidator.number;
28
+ /**
29
+ * Zod schema definition for bigint type.
30
+ */
31
+ export declare const bigint: typeof StaticSchemaValidator.bigint;
32
+ /**
33
+ * Zod schema definition for boolean type.
34
+ */
35
+ export declare const boolean: typeof StaticSchemaValidator.boolean;
36
+ /**
37
+ * Zod schema definition for date type.
38
+ */
39
+ export declare const date: typeof StaticSchemaValidator.date;
40
+ /**
41
+ * Zod schema definition for symbol type.
42
+ */
43
+ export declare const symbol: typeof StaticSchemaValidator.symbol;
44
+ /**
45
+ * Zod schema definition for undefined, null, void types.
46
+ */
47
+ export declare const nullish: typeof StaticSchemaValidator.nullish;
48
+ /**
49
+ * Zod schema definition for any type.
50
+ */
51
+ export declare const any: typeof StaticSchemaValidator.any;
52
+ /**
53
+ * Zod schema definition for unknown type.
54
+ */
55
+ export declare const unknown: typeof StaticSchemaValidator.unknown;
56
+ /**
57
+ * Zod schema definition for never type.
58
+ */
59
+ export declare const never: typeof StaticSchemaValidator.never;
60
+ /**
61
+ * Transforms valid schema into Zod schema.
62
+ */
63
+ export declare const schemify: typeof StaticSchemaValidator.schemify;
64
+ /**
65
+ * Makes a valid schema optional.
66
+ */
67
+ export declare const optional: typeof StaticSchemaValidator.optional;
68
+ /**
69
+ * Defines an array for a valid schema.
70
+ */
71
+ export declare const array: typeof StaticSchemaValidator.array;
72
+ /**
73
+ * Defines a union for a valid schema.
74
+ */
75
+ export declare const union: typeof StaticSchemaValidator.union;
76
+ /**
77
+ * Defines a literal for a valid schema.
78
+ */
79
+ export declare const literal: typeof StaticSchemaValidator.literal;
80
+ /**
81
+ * Validates a value against a valid schema.
82
+ */
83
+ export declare const validate: typeof StaticSchemaValidator.validate;
84
+ /**
85
+ * Parses a value to be conformant to a particular schema.
86
+ */
87
+ export declare const parse: typeof StaticSchemaValidator.parse;
88
+ /**
89
+ * Generates an OpenAPI schema object from a valid schema.
90
+ */
91
+ export declare const openapi: typeof StaticSchemaValidator.openapi;
92
+ export {};
93
+ //# sourceMappingURL=staticSchemaValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staticSchemaValidator.d.ts","sourceRoot":"","sources":["../../../src/zod/staticSchemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,eAAe,0BAAiC,CAAC;AAE9D,QAAA,MAAM,qBAAqB,oBAAoB,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,qBAAqB,CAAC,MACpB,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,OAAO,qBAAqB,CAAC,IACpB,CAAC;AAE7B;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,OAAO,qBAAqB,CAAC,KACpB,CAAC;AAE9B;;GAEG;AACH,eAAO,MAAM,GAAG,EAAE,OAAO,qBAAqB,CAAC,GAA+B,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,qBAAqB,CAAC,MACpB,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,qBAAqB,CAAC,MACpB,CAAC;AAE/B;;GAEG;AACH,eAA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SchemaValidator} The ZodSchemaValidator instance.
5
+ */
6
+ export const SchemaValidator = () => new ZodSchemaValidator();
7
+ const StaticSchemaValidator = SchemaValidator();
8
+ /**
9
+ * Zod schema definition for string type.
10
+ */
11
+ export const string = StaticSchemaValidator.string;
12
+ /**
13
+ * Zod schema definition for UUID type.
14
+ */
15
+ export const uuid = StaticSchemaValidator.uuid;
16
+ /**
17
+ * Zod schema definition for email type.
18
+ */
19
+ export const email = StaticSchemaValidator.email;
20
+ /**
21
+ * Zod schema definition for URI type.
22
+ */
23
+ export const uri = StaticSchemaValidator.uri;
24
+ /**
25
+ * Zod schema definition for number type.
26
+ */
27
+ export const number = StaticSchemaValidator.number;
28
+ /**
29
+ * Zod schema definition for bigint type.
30
+ */
31
+ export const bigint = StaticSchemaValidator.bigint;
32
+ /**
33
+ * Zod schema definition for boolean type.
34
+ */
35
+ export const boolean = StaticSchemaValidator.boolean;
36
+ /**
37
+ * Zod schema definition for date type.
38
+ */
39
+ export const date = StaticSchemaValidator.date;
40
+ /**
41
+ * Zod schema definition for symbol type.
42
+ */
43
+ export const symbol = StaticSchemaValidator.symbol;
44
+ /**
45
+ * Zod schema definition for undefined, null, void types.
46
+ */
47
+ export const nullish = StaticSchemaValidator.nullish;
48
+ /**
49
+ * Zod schema definition for any type.
50
+ */
51
+ export const any = StaticSchemaValidator.any;
52
+ /**
53
+ * Zod schema definition for unknown type.
54
+ */
55
+ export const unknown = StaticSchemaValidator.unknown;
56
+ /**
57
+ * Zod schema definition for never type.
58
+ */
59
+ export const never = StaticSchemaValidator.never;
60
+ /**
61
+ * Transforms valid schema into Zod schema.
62
+ */
63
+ export const schemify = StaticSchemaValidator.schemify.bind(StaticSchemaValidator);
64
+ /**
65
+ * Makes a valid schema optional.
66
+ */
67
+ export const optional = StaticSchemaValidator.optional.bind(StaticSchemaValidator);
68
+ /**
69
+ * Defines an array for a valid schema.
70
+ */
71
+ export const array = StaticSchemaValidator.array.bind(StaticSchemaValidator);
72
+ /**
73
+ * Defines a union for a valid schema.
74
+ */
75
+ export const union = StaticSchemaValidator.union.bind(StaticSchemaValidator);
76
+ /**
77
+ * Defines a literal for a valid schema.
78
+ */
79
+ export const literal = StaticSchemaValidator.literal.bind(StaticSchemaValidator);
80
+ /**
81
+ * Validates a value against a valid schema.
82
+ */
83
+ export const validate = StaticSchemaValidator.validate.bind(StaticSchemaValidator);
84
+ /**
85
+ * Parses a value to be conformant to a particular schema.
86
+ */
87
+ export const parse = StaticSchemaValidator.parse.bind(StaticSchemaValidator);
88
+ /**
89
+ * Generates an OpenAPI schema object from a valid schema.
90
+ */
91
+ export const openapi = StaticSchemaValidator.openapi.bind(StaticSchemaValidator);
@@ -1,6 +1,6 @@
1
1
  import { ZodObject as OriginalZodObject, ZodArray, ZodLiteral, ZodNever, ZodRawShape, ZodType, ZodTypeAny, ZodUnknown, z } from 'zod';
2
- import { ZodSchemaValidator } from '..';
3
- import { IdiomaticSchema, Increment, LiteralSchema, UnboxedObjectSchema } from '../../types/schema.types';
2
+ import { IdiomaticSchema, Increment, LiteralSchema, UnboxedObjectSchema } from '../../shared/types/schema.types';
3
+ import { ZodSchemaValidator } from '../zodSchemaValidator';
4
4
  /**
5
5
  * Represents a catch-all Zod schema type.
6
6
  */
@@ -68,3 +68,4 @@ export type UnionZodResolve<T extends ZodUnionContainer> = T extends [
68
68
  export type ZodResolve<T, Depth extends number = 0> = Depth extends 31 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends ZodObjectSchema ? ZodObject<{
69
69
  [K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
70
70
  }> : ZodNever;
71
+ //# sourceMappingURL=schema.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.types.d.ts","sourceRoot":"","sources":["../../../../src/zod/types/schema.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,iBAAiB,EAC9B,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,WAAW,EACX,OAAO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