@forklaunch/validator 0.4.6 → 0.4.8

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.
@@ -1,5 +1,5 @@
1
1
  import { SchemaObject } from 'openapi3-ts/oas31';
2
- import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-CA4Aof4g.mjs';
2
+ import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-CoFRq_Vn.mjs';
3
3
  import '@forklaunch/common';
4
4
  import '@sinclair/typebox';
5
5
  import '@sinclair/typebox/compiler';
@@ -1,5 +1,5 @@
1
1
  import { SchemaObject } from 'openapi3-ts/oas31';
2
- import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-CA4Aof4g.js';
2
+ import { S as SchemaValidator, L as LiteralSchema, a as ParseResult } from '../../schema.types-CoFRq_Vn.js';
3
3
  import '@forklaunch/common';
4
4
  import '@sinclair/typebox';
5
5
  import '@sinclair/typebox/compiler';
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // tests/utils/mockSchemaValidator.ts
20
+ // __test__/utils/mockSchemaValidator.ts
21
21
  var mockSchemaValidator_exports = {};
22
22
  __export(mockSchemaValidator_exports, {
23
23
  MockSchemaValidator: () => MockSchemaValidator,
@@ -96,7 +96,9 @@ var MockSchemaValidator = class {
96
96
  };
97
97
  }
98
98
  openapi(_schema) {
99
- return {};
99
+ return {
100
+ type: "string"
101
+ };
100
102
  }
101
103
  };
102
104
  var mockSchemaValidator = new MockSchemaValidator();
@@ -1,4 +1,4 @@
1
- // tests/utils/mockSchemaValidator.ts
1
+ // __test__/utils/mockSchemaValidator.ts
2
2
  var MockSchemaValidator = class {
3
3
  _Type;
4
4
  _SchemaCatchall;
@@ -53,7 +53,9 @@ var MockSchemaValidator = class {
53
53
  };
54
54
  }
55
55
  openapi(_schema) {
56
- return {};
56
+ return {
57
+ type: "string"
58
+ };
57
59
  }
58
60
  };
59
61
  var mockSchemaValidator = new MockSchemaValidator();
package/lib/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as ParseError } from './schema.types-CA4Aof4g.mjs';
2
- export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-CA4Aof4g.mjs';
1
+ import { P as ParseError } from './schema.types-CoFRq_Vn.mjs';
2
+ export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-CoFRq_Vn.mjs';
3
3
  import '@forklaunch/common';
4
4
  import 'openapi3-ts/oas31';
5
5
  import '@sinclair/typebox';
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as ParseError } from './schema.types-CA4Aof4g.js';
2
- export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-CA4Aof4g.js';
1
+ import { P as ParseError } from './schema.types-CoFRq_Vn.js';
2
+ export { A as AnySchemaValidator, I as IdiomaticSchema, e as Increment, K as KeyTypes, L as LiteralSchema, a as ParseResult, d as Schema, b as SchemaResolve, c as SchemaTranslate, S as SchemaValidator, U as UnboxedObjectSchema } from './schema.types-CoFRq_Vn.js';
3
3
  import '@forklaunch/common';
4
4
  import 'openapi3-ts/oas31';
5
5
  import '@sinclair/typebox';
@@ -1,6 +1,6 @@
1
1
  import { Prettify } from '@forklaunch/common';
2
2
  import { SchemaObject } from 'openapi3-ts/oas31';
3
- import { TUnknown, TLiteral, TSchema, TKind, TProperties, TObject as TObject$1, TNever, StaticDecode } from '@sinclair/typebox';
3
+ import { TUnknown, TLiteral, TSchema, TKind, TProperties, TObject as TObject$1, TNever, StaticDecode, TArray } from '@sinclair/typebox';
4
4
  import { TypeCheck } from '@sinclair/typebox/compiler';
5
5
  import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion, ZodLiteral, ZodType, z, ZodUnknown, ZodNever, ZodTypeAny } from 'zod';
6
6
 
@@ -8,6 +8,12 @@ import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion,
8
8
  * Represents a catch-all schema type.
9
9
  */
10
10
  type TCatchall = TSchema;
11
+ /**
12
+ * Represents an outer array schema type. If the type T is an object shape, it will return an array schema of T. Otherwise, it returns TNever.
13
+ *
14
+ * @template T - The type to check and possibly convert to an array schema.
15
+ */
16
+ type TOuterArray<T> = T extends TObject<TObjectShape> ? TArray<T> : TNever;
11
17
  /**
12
18
  * Represents the shape of an object schema.
13
19
  */
@@ -50,7 +56,7 @@ type UnionTResolve<T extends TUnionContainer> = T extends (infer UnionTypes)[] ?
50
56
  * @template T - The schema type to resolve.
51
57
  * @template Depth - The current depth of the resolution.
52
58
  */
53
- 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<{
59
+ type TResolve<T, Depth extends number = 0> = Depth extends 10 ? TUnknown : T extends LiteralSchema ? TLiteral<T> : T extends TSchema ? T : T extends TKind ? T : T extends TObject<TObjectShape> ? T : T extends UnboxedTObjectSchema ? TObject<{
54
60
  [K in keyof T]: TResolve<T[K], Increment<Depth>>;
55
61
  }> : T extends TypeCheck<infer Type> ? TResolve<Type, Increment<Depth>> : TNever;
56
62
 
@@ -65,7 +71,11 @@ type TResolve<T, Depth extends number = 0> = Depth extends 12 ? TUnknown : T ext
65
71
  * Class representing a Zod schema definition.
66
72
  * @implements {StaticSchemaValidator}
67
73
  */
68
- declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<ZodResolve<T>>, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => ZodUnion<UnionZodResolve<[T, T, ...T[]]>>, (value: unknown) => value is ZodType, <T extends ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => SchemaObject> {
74
+ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<ZodResolve<T>>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => ZodUnion<[
75
+ {
76
+ [K in keyof T]: ZodLiteral<T[K]>;
77
+ }[keyof T]
78
+ ]>, (value: unknown) => value is ZodType, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => SchemaObject> {
69
79
  _Type: 'Zod';
70
80
  _SchemaCatchall: ZodType;
71
81
  _ValidSchemaObject: ZodObject$1<ZodRawShape> | ZodArray<ZodObject$1<ZodRawShape>>;
@@ -124,7 +134,11 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
124
134
  * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
125
135
  * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
126
136
  */
127
- enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): ZodUnion<UnionZodResolve<[T, T, ...T[]]>>;
137
+ enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): ZodUnion<[
138
+ {
139
+ [K in keyof T]: ZodLiteral<T[K]>;
140
+ }[keyof T]
141
+ ]>;
128
142
  /**
129
143
  * Checks if a value is a Zod schema.
130
144
  * @param {unknown} value - The value to check.
@@ -137,7 +151,7 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
137
151
  * @param {unknown} value - The value to validate.
138
152
  * @returns {boolean} True if valid, otherwise false.
139
153
  */
140
- validate<T extends ZodCatchall>(schema: T, value: unknown): boolean;
154
+ validate<T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown): boolean;
141
155
  /**
142
156
  * Parses a value to a schema validation.
143
157
  *
@@ -145,19 +159,25 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
145
159
  * @param {unknown} value - The value to validate.
146
160
  * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
147
161
  */
148
- parse<T extends ZodCatchall>(schema: T, value: unknown): ParseResult<ZodResolve<T>>;
162
+ parse<T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown): ParseResult<ZodResolve<T>>;
149
163
  /**
150
164
  * Convert a schema to an OpenAPI schema object.
151
165
  * @param {ZodIdiomaticSchema} schema - The schema to convert.
152
166
  * @returns {SchemaObject} The OpenAPI schema object.
153
167
  */
154
- openapi<T extends ZodIdiomaticSchema>(schema: T): SchemaObject;
168
+ openapi<T extends ZodIdiomaticSchema | ZodCatchall>(schema: T): SchemaObject;
155
169
  }
156
170
 
157
171
  /**
158
172
  * Represents a catch-all Zod schema type.
159
173
  */
160
174
  type ZodCatchall = ZodTypeAny;
175
+ /**
176
+ * Represents an outer array schema type for Zod. If the type T is a Zod object, it will return an array schema of T. Otherwise, it returns ZodNever.
177
+ *
178
+ * @template T - The type to check and possibly convert to an array schema.
179
+ */
180
+ type ZodOuterArray<T> = T extends ZodObject<ZodObjectShape> ? ZodArray<T> : ZodNever;
161
181
  /**
162
182
  * Represents the shape of a Zod object schema.
163
183
  */
@@ -177,7 +197,7 @@ type ZodSchemaTranslate<T> = T extends ZodCatchall ? z.infer<T> : ZodNever;
177
197
  /**
178
198
  * Represents an unboxed Zod object schema where each key can have an idiomatic schema.
179
199
  */
180
- type ZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
200
+ type UnboxedZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
181
201
  /**
182
202
  * Represents an idiomatic schema for Zod which can be an unboxed object schema or a literal schema.
183
203
  */
@@ -212,7 +232,7 @@ type UnionZodResolve<T extends ZodUnionContainer> = T extends [
212
232
  * @template T - The Zod schema type to resolve.
213
233
  * @template Depth - The current depth of the resolution.
214
234
  */
215
- type ZodResolve<T, Depth extends number = 0> = Depth extends 31 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends ZodObjectSchema ? ZodObject<{
235
+ type ZodResolve<T, Depth extends number = 0> = Depth extends 30 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends UnboxedZodObjectSchema ? ZodObject<{
216
236
  [K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
217
237
  }> : ZodNever;
218
238
 
@@ -473,4 +493,4 @@ type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends
473
493
  */
474
494
  type KeyTypes = string | number;
475
495
 
476
- export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, type TObject as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionContainer as h, type UnionTResolve as i, type ZodIdiomaticSchema as j, type ZodResolve as k, type ZodUnionContainer as l, type UnionZodResolve as m, type ZodCatchall as n };
496
+ export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, type TObject as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionContainer as h, type UnionTResolve as i, type TCatchall as j, type TOuterArray as k, type TObjectShape as l, type TSchemaTranslate as m, type UnboxedTObjectSchema as n, type ZodIdiomaticSchema as o, type ZodResolve as p, type ZodUnionContainer as q, type UnionZodResolve as r, type ZodCatchall as s, type ZodOuterArray as t, type ZodObjectShape as u, type ZodObject as v, type ZodSchemaTranslate as w, type UnboxedZodObjectSchema as x };
@@ -1,6 +1,6 @@
1
1
  import { Prettify } from '@forklaunch/common';
2
2
  import { SchemaObject } from 'openapi3-ts/oas31';
3
- import { TUnknown, TLiteral, TSchema, TKind, TProperties, TObject as TObject$1, TNever, StaticDecode } from '@sinclair/typebox';
3
+ import { TUnknown, TLiteral, TSchema, TKind, TProperties, TObject as TObject$1, TNever, StaticDecode, TArray } from '@sinclair/typebox';
4
4
  import { TypeCheck } from '@sinclair/typebox/compiler';
5
5
  import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion, ZodLiteral, ZodType, z, ZodUnknown, ZodNever, ZodTypeAny } from 'zod';
6
6
 
@@ -8,6 +8,12 @@ import { ZodObject as ZodObject$1, ZodRawShape, ZodOptional, ZodArray, ZodUnion,
8
8
  * Represents a catch-all schema type.
9
9
  */
10
10
  type TCatchall = TSchema;
11
+ /**
12
+ * Represents an outer array schema type. If the type T is an object shape, it will return an array schema of T. Otherwise, it returns TNever.
13
+ *
14
+ * @template T - The type to check and possibly convert to an array schema.
15
+ */
16
+ type TOuterArray<T> = T extends TObject<TObjectShape> ? TArray<T> : TNever;
11
17
  /**
12
18
  * Represents the shape of an object schema.
13
19
  */
@@ -50,7 +56,7 @@ type UnionTResolve<T extends TUnionContainer> = T extends (infer UnionTypes)[] ?
50
56
  * @template T - The schema type to resolve.
51
57
  * @template Depth - The current depth of the resolution.
52
58
  */
53
- 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<{
59
+ type TResolve<T, Depth extends number = 0> = Depth extends 10 ? TUnknown : T extends LiteralSchema ? TLiteral<T> : T extends TSchema ? T : T extends TKind ? T : T extends TObject<TObjectShape> ? T : T extends UnboxedTObjectSchema ? TObject<{
54
60
  [K in keyof T]: TResolve<T[K], Increment<Depth>>;
55
61
  }> : T extends TypeCheck<infer Type> ? TResolve<Type, Increment<Depth>> : TNever;
56
62
 
@@ -65,7 +71,11 @@ type TResolve<T, Depth extends number = 0> = Depth extends 12 ? TUnknown : T ext
65
71
  * Class representing a Zod schema definition.
66
72
  * @implements {StaticSchemaValidator}
67
73
  */
68
- declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<ZodResolve<T>>, <T extends LiteralSchema>(schemaEnum: Record<string, T>) => ZodUnion<UnionZodResolve<[T, T, ...T[]]>>, (value: unknown) => value is ZodType, <T extends ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => SchemaObject> {
74
+ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObject$1<ZodRawShape>>(schema: T) => ZodResolve<T>), <T extends ZodIdiomaticSchema>(schema: T) => ZodResolve<T>, <T extends ZodIdiomaticSchema>(schema: T) => ZodOptional<ZodResolve<T>>, <T extends ZodIdiomaticSchema>(schema: T) => ZodArray<ZodResolve<T>>, <T extends ZodUnionContainer>(schemas: T) => ZodUnion<UnionZodResolve<T>>, <T extends LiteralSchema>(value: T) => ZodLiteral<ZodResolve<T>>, <T extends Record<string, LiteralSchema>>(schemaEnum: T) => ZodUnion<[
75
+ {
76
+ [K in keyof T]: ZodLiteral<T[K]>;
77
+ }[keyof T]
78
+ ]>, (value: unknown) => value is ZodType, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>, <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => SchemaObject> {
69
79
  _Type: 'Zod';
70
80
  _SchemaCatchall: ZodType;
71
81
  _ValidSchemaObject: ZodObject$1<ZodRawShape> | ZodArray<ZodObject$1<ZodRawShape>>;
@@ -124,7 +134,11 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
124
134
  * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
125
135
  * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
126
136
  */
127
- enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): ZodUnion<UnionZodResolve<[T, T, ...T[]]>>;
137
+ enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): ZodUnion<[
138
+ {
139
+ [K in keyof T]: ZodLiteral<T[K]>;
140
+ }[keyof T]
141
+ ]>;
128
142
  /**
129
143
  * Checks if a value is a Zod schema.
130
144
  * @param {unknown} value - The value to check.
@@ -137,7 +151,7 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
137
151
  * @param {unknown} value - The value to validate.
138
152
  * @returns {boolean} True if valid, otherwise false.
139
153
  */
140
- validate<T extends ZodCatchall>(schema: T, value: unknown): boolean;
154
+ validate<T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown): boolean;
141
155
  /**
142
156
  * Parses a value to a schema validation.
143
157
  *
@@ -145,19 +159,25 @@ declare class ZodSchemaValidator implements SchemaValidator<(<T extends ZodObjec
145
159
  * @param {unknown} value - The value to validate.
146
160
  * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
147
161
  */
148
- parse<T extends ZodCatchall>(schema: T, value: unknown): ParseResult<ZodResolve<T>>;
162
+ parse<T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown): ParseResult<ZodResolve<T>>;
149
163
  /**
150
164
  * Convert a schema to an OpenAPI schema object.
151
165
  * @param {ZodIdiomaticSchema} schema - The schema to convert.
152
166
  * @returns {SchemaObject} The OpenAPI schema object.
153
167
  */
154
- openapi<T extends ZodIdiomaticSchema>(schema: T): SchemaObject;
168
+ openapi<T extends ZodIdiomaticSchema | ZodCatchall>(schema: T): SchemaObject;
155
169
  }
156
170
 
157
171
  /**
158
172
  * Represents a catch-all Zod schema type.
159
173
  */
160
174
  type ZodCatchall = ZodTypeAny;
175
+ /**
176
+ * Represents an outer array schema type for Zod. If the type T is a Zod object, it will return an array schema of T. Otherwise, it returns ZodNever.
177
+ *
178
+ * @template T - The type to check and possibly convert to an array schema.
179
+ */
180
+ type ZodOuterArray<T> = T extends ZodObject<ZodObjectShape> ? ZodArray<T> : ZodNever;
161
181
  /**
162
182
  * Represents the shape of a Zod object schema.
163
183
  */
@@ -177,7 +197,7 @@ type ZodSchemaTranslate<T> = T extends ZodCatchall ? z.infer<T> : ZodNever;
177
197
  /**
178
198
  * Represents an unboxed Zod object schema where each key can have an idiomatic schema.
179
199
  */
180
- type ZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
200
+ type UnboxedZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
181
201
  /**
182
202
  * Represents an idiomatic schema for Zod which can be an unboxed object schema or a literal schema.
183
203
  */
@@ -212,7 +232,7 @@ type UnionZodResolve<T extends ZodUnionContainer> = T extends [
212
232
  * @template T - The Zod schema type to resolve.
213
233
  * @template Depth - The current depth of the resolution.
214
234
  */
215
- type ZodResolve<T, Depth extends number = 0> = Depth extends 31 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends ZodObjectSchema ? ZodObject<{
235
+ type ZodResolve<T, Depth extends number = 0> = Depth extends 30 ? ZodUnknown : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType ? T : T extends UnboxedZodObjectSchema ? ZodObject<{
216
236
  [K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
217
237
  }> : ZodNever;
218
238
 
@@ -473,4 +493,4 @@ type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends
473
493
  */
474
494
  type KeyTypes = string | number;
475
495
 
476
- export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, type TObject as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionContainer as h, type UnionTResolve as i, type ZodIdiomaticSchema as j, type ZodResolve as k, type ZodUnionContainer as l, type UnionZodResolve as m, type ZodCatchall as n };
496
+ export { type AnySchemaValidator as A, type IdiomaticSchema as I, type KeyTypes as K, type LiteralSchema as L, type ParseError as P, type SchemaValidator as S, type TObject as T, type UnboxedObjectSchema as U, ZodSchemaValidator as Z, type ParseResult as a, type SchemaResolve as b, type SchemaTranslate as c, type Schema as d, type Increment as e, type TIdiomaticSchema as f, type TResolve as g, type TUnionContainer as h, type UnionTResolve as i, type TCatchall as j, type TOuterArray as k, type TObjectShape as l, type TSchemaTranslate as m, type UnboxedTObjectSchema as n, type ZodIdiomaticSchema as o, type ZodResolve as p, type ZodUnionContainer as q, type UnionZodResolve as r, type ZodCatchall as s, type ZodOuterArray as t, type ZodObjectShape as u, type ZodObject as v, type ZodSchemaTranslate as w, type UnboxedZodObjectSchema as x };
@@ -2,9 +2,10 @@ import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import { SchemaObject } from 'openapi3-ts/oas31';
3
3
  import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
4
4
  import { TypeCheck } from '@sinclair/typebox/compiler';
5
- import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, a as ParseResult } from '../../schema.types-CA4Aof4g.mjs';
5
+ import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult } from '../../schema.types-CoFRq_Vn.mjs';
6
+ export { l as TObjectShape, k as TOuterArray, m as TSchemaTranslate, n as UnboxedTObjectSchema } from '../../schema.types-CoFRq_Vn.mjs';
6
7
  import * as _sinclair_typebox from '@sinclair/typebox';
7
- import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TKind } from '@sinclair/typebox';
8
+ import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema } from '@sinclair/typebox';
8
9
  import '@forklaunch/common';
9
10
  import 'zod';
10
11
 
@@ -12,9 +13,13 @@ import 'zod';
12
13
  * Class representing a TypeBox schema definition.
13
14
  * @implements {SchemaValidator}
14
15
  */
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
+ 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 Record<string, LiteralSchema>>(schemaEnum: T) => TUnion<[
17
+ {
18
+ [K in keyof T]: TLiteral<T[K]>;
19
+ }[keyof T]
20
+ ]>, (value: unknown) => value is TSchema, <T extends TIdiomaticSchema | TCatchall>(schema: T, value: unknown) => boolean, <T extends TIdiomaticSchema | TCatchall>(schema: T, value: unknown) => ParseResult<TResolve<T>>, <T extends TIdiomaticSchema | TCatchall>(schema: T) => SchemaObject> {
16
21
  _Type: 'TypeBox';
17
- _SchemaCatchall: TKind;
22
+ _SchemaCatchall: TSchema;
18
23
  _ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
19
24
  string: _sinclair_typebox.TString;
20
25
  uuid: _sinclair_typebox.TString;
@@ -81,7 +86,11 @@ declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TO
81
86
  * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
82
87
  * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
83
88
  */
84
- enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): TUnion<UnionTResolve<T[]>>;
89
+ enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): TUnion<[
90
+ {
91
+ [K in keyof T]: TLiteral<T[K]>;
92
+ }[keyof T]
93
+ ]>;
85
94
  /**
86
95
  * Check if a value is a TypeBox object schema.
87
96
  * @param {unknown} value - The value to check.
@@ -192,7 +201,7 @@ declare const literal: <T extends LiteralSchema>(value: T) => _sinclair_typebox.
192
201
  /**
193
202
  * Defines an enum for a valid schema.
194
203
  */
195
- declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => _sinclair_typebox.TUnion<UnionTResolve<T[]>>;
204
+ declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => _sinclair_typebox.TUnion<[{ [K in keyof T]: _sinclair_typebox.TLiteral<T[K]>; }[keyof T]]>;
196
205
  /**
197
206
  * Checks if a value is a TypeBox schema.
198
207
  */
@@ -210,4 +219,4 @@ declare const parse: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(sc
210
219
  */
211
220
  declare const openapi: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
212
221
 
213
- 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 };
222
+ export { SchemaValidator, TCatchall, TIdiomaticSchema, TObject, TResolve, TUnionContainer, TypeboxSchemaValidator, UnionTResolve, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
@@ -2,9 +2,10 @@ import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
2
  import { SchemaObject } from 'openapi3-ts/oas31';
3
3
  import * as _sinclair_typebox_compiler from '@sinclair/typebox/compiler';
4
4
  import { TypeCheck } from '@sinclair/typebox/compiler';
5
- import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, a as ParseResult } from '../../schema.types-CA4Aof4g.js';
5
+ import { S as SchemaValidator$1, T as TObject, f as TIdiomaticSchema, g as TResolve, h as TUnionContainer, i as UnionTResolve, L as LiteralSchema, j as TCatchall, a as ParseResult } from '../../schema.types-CoFRq_Vn.js';
6
+ export { l as TObjectShape, k as TOuterArray, m as TSchemaTranslate, n as UnboxedTObjectSchema } from '../../schema.types-CoFRq_Vn.js';
6
7
  import * as _sinclair_typebox from '@sinclair/typebox';
7
- import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema, TKind } from '@sinclair/typebox';
8
+ import { TProperties, TOptional, TArray, TUnion, TLiteral, TSchema } from '@sinclair/typebox';
8
9
  import '@forklaunch/common';
9
10
  import 'zod';
10
11
 
@@ -12,9 +13,13 @@ import 'zod';
12
13
  * Class representing a TypeBox schema definition.
13
14
  * @implements {SchemaValidator}
14
15
  */
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
+ 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 Record<string, LiteralSchema>>(schemaEnum: T) => TUnion<[
17
+ {
18
+ [K in keyof T]: TLiteral<T[K]>;
19
+ }[keyof T]
20
+ ]>, (value: unknown) => value is TSchema, <T extends TIdiomaticSchema | TCatchall>(schema: T, value: unknown) => boolean, <T extends TIdiomaticSchema | TCatchall>(schema: T, value: unknown) => ParseResult<TResolve<T>>, <T extends TIdiomaticSchema | TCatchall>(schema: T) => SchemaObject> {
16
21
  _Type: 'TypeBox';
17
- _SchemaCatchall: TKind;
22
+ _SchemaCatchall: TSchema;
18
23
  _ValidSchemaObject: TObject<TProperties> | TArray<TObject<TProperties>>;
19
24
  string: _sinclair_typebox.TString;
20
25
  uuid: _sinclair_typebox.TString;
@@ -81,7 +86,11 @@ declare class TypeboxSchemaValidator implements SchemaValidator$1<(<T extends TO
81
86
  * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
82
87
  * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
83
88
  */
84
- enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): TUnion<UnionTResolve<T[]>>;
89
+ enum_<T extends Record<string, LiteralSchema>>(schemaEnum: T): TUnion<[
90
+ {
91
+ [K in keyof T]: TLiteral<T[K]>;
92
+ }[keyof T]
93
+ ]>;
85
94
  /**
86
95
  * Check if a value is a TypeBox object schema.
87
96
  * @param {unknown} value - The value to check.
@@ -192,7 +201,7 @@ declare const literal: <T extends LiteralSchema>(value: T) => _sinclair_typebox.
192
201
  /**
193
202
  * Defines an enum for a valid schema.
194
203
  */
195
- declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => _sinclair_typebox.TUnion<UnionTResolve<T[]>>;
204
+ declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => _sinclair_typebox.TUnion<[{ [K in keyof T]: _sinclair_typebox.TLiteral<T[K]>; }[keyof T]]>;
196
205
  /**
197
206
  * Checks if a value is a TypeBox schema.
198
207
  */
@@ -210,4 +219,4 @@ declare const parse: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(sc
210
219
  */
211
220
  declare const openapi: <T extends TIdiomaticSchema | _sinclair_typebox.TSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
212
221
 
213
- 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 };
222
+ export { SchemaValidator, TCatchall, TIdiomaticSchema, TObject, TResolve, TUnionContainer, TypeboxSchemaValidator, UnionTResolve, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
@@ -283,7 +283,9 @@ var TypeboxSchemaValidator = class {
283
283
  * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
284
284
  */
285
285
  enum_(schemaEnum) {
286
- return this.union(Object.values(schemaEnum));
286
+ return this.union(
287
+ Object.values(schemaEnum).map((value) => this.literal(value))
288
+ );
287
289
  }
288
290
  /**
289
291
  * Check if a value is a TypeBox object schema.
@@ -332,15 +334,42 @@ var TypeboxSchemaValidator = class {
332
334
  errors = Array.from(import_value.Value.Errors(schemified, value));
333
335
  }
334
336
  }
337
+ errors.forEach((error) => {
338
+ if (error.type === import_errors.ValueErrorType.Union && error.schema.errorType === "any of") {
339
+ error.errors.forEach((e, idx) => {
340
+ console.log({
341
+ p: [`Union Schema Variant ${idx}`, error.path],
342
+ message: Array.from(e)
343
+ });
344
+ });
345
+ }
346
+ });
335
347
  return errors != null && errors.length === 0 ? {
336
348
  ok: true,
337
349
  value: conversion
338
350
  } : {
339
351
  ok: false,
340
- errors: errors.map((error) => ({
341
- path: error.path.split("/").slice(1),
342
- message: error.message
343
- }))
352
+ errors: errors.flatMap((error) => {
353
+ if (error.type === import_errors.ValueErrorType.Union && error.schema.errorType.includes("any of")) {
354
+ return error.errors.flatMap(
355
+ (e, idx) => Array.from(e).map((e2) => ({
356
+ path: [
357
+ `Union Schema Variant ${idx}`,
358
+ ...error.path.split("/").slice(1),
359
+ ...e2.path.split("/").slice(1)
360
+ ],
361
+ message: e2.message
362
+ }))
363
+ );
364
+ } else {
365
+ return [
366
+ {
367
+ path: error.path.split("/").slice(1),
368
+ message: error.message
369
+ }
370
+ ];
371
+ }
372
+ })
344
373
  };
345
374
  }
346
375
  /**
@@ -242,7 +242,9 @@ var TypeboxSchemaValidator = class {
242
242
  * @returns {TUnion<UnionTResolve<T[]>>} The enum schema.
243
243
  */
244
244
  enum_(schemaEnum) {
245
- return this.union(Object.values(schemaEnum));
245
+ return this.union(
246
+ Object.values(schemaEnum).map((value) => this.literal(value))
247
+ );
246
248
  }
247
249
  /**
248
250
  * Check if a value is a TypeBox object schema.
@@ -291,15 +293,42 @@ var TypeboxSchemaValidator = class {
291
293
  errors = Array.from(Value.Errors(schemified, value));
292
294
  }
293
295
  }
296
+ errors.forEach((error) => {
297
+ if (error.type === ValueErrorType.Union && error.schema.errorType === "any of") {
298
+ error.errors.forEach((e, idx) => {
299
+ console.log({
300
+ p: [`Union Schema Variant ${idx}`, error.path],
301
+ message: Array.from(e)
302
+ });
303
+ });
304
+ }
305
+ });
294
306
  return errors != null && errors.length === 0 ? {
295
307
  ok: true,
296
308
  value: conversion
297
309
  } : {
298
310
  ok: false,
299
- errors: errors.map((error) => ({
300
- path: error.path.split("/").slice(1),
301
- message: error.message
302
- }))
311
+ errors: errors.flatMap((error) => {
312
+ if (error.type === ValueErrorType.Union && error.schema.errorType.includes("any of")) {
313
+ return error.errors.flatMap(
314
+ (e, idx) => Array.from(e).map((e2) => ({
315
+ path: [
316
+ `Union Schema Variant ${idx}`,
317
+ ...error.path.split("/").slice(1),
318
+ ...e2.path.split("/").slice(1)
319
+ ],
320
+ message: e2.message
321
+ }))
322
+ );
323
+ } else {
324
+ return [
325
+ {
326
+ path: error.path.split("/").slice(1),
327
+ message: error.message
328
+ }
329
+ ];
330
+ }
331
+ })
303
332
  };
304
333
  }
305
334
  /**
@@ -1,5 +1,6 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
- import { Z as ZodSchemaValidator, j as ZodIdiomaticSchema, k as ZodResolve, l as ZodUnionContainer, m as UnionZodResolve, L as LiteralSchema, n as ZodCatchall, a as ParseResult } from '../../schema.types-CA4Aof4g.mjs';
2
+ import { Z as ZodSchemaValidator, o as ZodIdiomaticSchema, p as ZodResolve, q as ZodUnionContainer, r as UnionZodResolve, L as LiteralSchema, s as ZodCatchall, a as ParseResult } from '../../schema.types-CoFRq_Vn.mjs';
3
+ export { x as UnboxedZodObjectSchema, v as ZodObject, u as ZodObjectShape, t as ZodOuterArray, w as ZodSchemaTranslate } from '../../schema.types-CoFRq_Vn.mjs';
3
4
  import * as zod from 'zod';
4
5
  import '@forklaunch/common';
5
6
  import '@sinclair/typebox';
@@ -85,7 +86,7 @@ declare const literal: <T extends LiteralSchema>(value: T) => zod.ZodLiteral<Zod
85
86
  /**
86
87
  * Defines an enum for a valid schema.
87
88
  */
88
- declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => zod.ZodUnion<UnionZodResolve<[T, T, ...T[]]>>;
89
+ declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => zod.ZodUnion<[{ [K in keyof T]: zod.ZodLiteral<T[K]>; }[keyof T]]>;
89
90
  /**
90
91
  * Checks if a value is a Zod schema.
91
92
  */
@@ -93,14 +94,14 @@ declare const isSchema: (value: unknown) => value is zod.ZodSchema;
93
94
  /**
94
95
  * Validates a value against a valid schema.
95
96
  */
96
- declare const validate: <T extends ZodCatchall>(schema: T, value: unknown) => boolean;
97
+ declare const validate: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean;
97
98
  /**
98
99
  * Parses a value to be conformant to a particular schema.
99
100
  */
100
- declare const parse: <T extends ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>;
101
+ declare const parse: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>;
101
102
  /**
102
103
  * Generates an OpenAPI schema object from a valid schema.
103
104
  */
104
- declare const openapi: <T extends ZodIdiomaticSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
105
+ declare const openapi: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
105
106
 
106
- export { SchemaValidator, ZodSchemaValidator, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
107
+ export { SchemaValidator, UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodResolve, ZodSchemaValidator, ZodUnionContainer, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
@@ -1,5 +1,6 @@
1
1
  import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
2
- import { Z as ZodSchemaValidator, j as ZodIdiomaticSchema, k as ZodResolve, l as ZodUnionContainer, m as UnionZodResolve, L as LiteralSchema, n as ZodCatchall, a as ParseResult } from '../../schema.types-CA4Aof4g.js';
2
+ import { Z as ZodSchemaValidator, o as ZodIdiomaticSchema, p as ZodResolve, q as ZodUnionContainer, r as UnionZodResolve, L as LiteralSchema, s as ZodCatchall, a as ParseResult } from '../../schema.types-CoFRq_Vn.js';
3
+ export { x as UnboxedZodObjectSchema, v as ZodObject, u as ZodObjectShape, t as ZodOuterArray, w as ZodSchemaTranslate } from '../../schema.types-CoFRq_Vn.js';
3
4
  import * as zod from 'zod';
4
5
  import '@forklaunch/common';
5
6
  import '@sinclair/typebox';
@@ -85,7 +86,7 @@ declare const literal: <T extends LiteralSchema>(value: T) => zod.ZodLiteral<Zod
85
86
  /**
86
87
  * Defines an enum for a valid schema.
87
88
  */
88
- declare const enum_: <T extends LiteralSchema>(schemaEnum: Record<string, T>) => zod.ZodUnion<UnionZodResolve<[T, T, ...T[]]>>;
89
+ declare const enum_: <T extends Record<string, LiteralSchema>>(schemaEnum: T) => zod.ZodUnion<[{ [K in keyof T]: zod.ZodLiteral<T[K]>; }[keyof T]]>;
89
90
  /**
90
91
  * Checks if a value is a Zod schema.
91
92
  */
@@ -93,14 +94,14 @@ declare const isSchema: (value: unknown) => value is zod.ZodSchema;
93
94
  /**
94
95
  * Validates a value against a valid schema.
95
96
  */
96
- declare const validate: <T extends ZodCatchall>(schema: T, value: unknown) => boolean;
97
+ declare const validate: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => boolean;
97
98
  /**
98
99
  * Parses a value to be conformant to a particular schema.
99
100
  */
100
- declare const parse: <T extends ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>;
101
+ declare const parse: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T, value: unknown) => ParseResult<ZodResolve<T>>;
101
102
  /**
102
103
  * Generates an OpenAPI schema object from a valid schema.
103
104
  */
104
- declare const openapi: <T extends ZodIdiomaticSchema>(schema: T) => openapi3_ts_oas31.SchemaObject;
105
+ declare const openapi: <T extends ZodIdiomaticSchema | ZodCatchall>(schema: T) => openapi3_ts_oas31.SchemaObject;
105
106
 
106
- export { SchemaValidator, ZodSchemaValidator, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
107
+ export { SchemaValidator, UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodResolve, ZodSchemaValidator, ZodUnionContainer, any, array, bigint, boolean, date, email, enum_, isSchema, literal, never, nullish, number, openapi, optional, parse, schemify, string, symbol, union, unknown, uri, uuid, validate };
@@ -75,7 +75,7 @@ var ZodSchemaValidator = class {
75
75
  boolean = import_zod.z.preprocess((val) => {
76
76
  if (typeof val === "string") {
77
77
  if (val.toLowerCase() === "true") return true;
78
- return false;
78
+ if (val.toLowerCase() === "false") return false;
79
79
  }
80
80
  return val;
81
81
  }, import_zod.z.boolean());
@@ -176,7 +176,9 @@ var ZodSchemaValidator = class {
176
176
  * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
177
177
  */
178
178
  enum_(schemaEnum) {
179
- return this.union(Object.values(schemaEnum));
179
+ return this.union(
180
+ Object.values(schemaEnum)
181
+ );
180
182
  }
181
183
  /**
182
184
  * Checks if a value is a Zod schema.
@@ -193,7 +195,8 @@ var ZodSchemaValidator = class {
193
195
  * @returns {boolean} True if valid, otherwise false.
194
196
  */
195
197
  validate(schema, value) {
196
- return schema.safeParse(value).success;
198
+ const resolvedSchema = schema instanceof import_zod.ZodType ? schema : this.schemify(schema);
199
+ return resolvedSchema.safeParse(value).success;
197
200
  }
198
201
  /**
199
202
  * Parses a value to a schema validation.
@@ -203,13 +206,32 @@ var ZodSchemaValidator = class {
203
206
  * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
204
207
  */
205
208
  parse(schema, value) {
206
- const result = schema.safeParse(value);
209
+ const resolvedSchema = schema instanceof import_zod.ZodType ? schema : this.schemify(schema);
210
+ const result = resolvedSchema.safeParse(value);
207
211
  return result.success ? { ok: true, value: result.data } : {
208
212
  ok: false,
209
- errors: result.error.errors.map((error) => ({
210
- path: error.path.map((p) => p.toString()),
211
- message: error.message
212
- }))
213
+ errors: result.error.errors.flatMap((error) => {
214
+ switch (error.code) {
215
+ case "invalid_union":
216
+ return error.unionErrors.flatMap(
217
+ (unionError, idx) => unionError.errors.map((e) => ({
218
+ path: [
219
+ `Union Schema Variant ${idx}`,
220
+ ...error.path.map((p) => p.toString()),
221
+ ...e.path.map((p) => p.toString())
222
+ ],
223
+ message: e.message
224
+ }))
225
+ );
226
+ default:
227
+ return [
228
+ {
229
+ path: error.path.map((p) => p.toString()),
230
+ message: error.message
231
+ }
232
+ ];
233
+ }
234
+ })
213
235
  };
214
236
  }
215
237
  /**
@@ -218,7 +240,9 @@ var ZodSchemaValidator = class {
218
240
  * @returns {SchemaObject} The OpenAPI schema object.
219
241
  */
220
242
  openapi(schema) {
221
- return (0, import_zod_openapi.generateSchema)(this.schemify(schema));
243
+ return (0, import_zod_openapi.generateSchema)(
244
+ schema instanceof import_zod.ZodType ? schema : this.schemify(schema)
245
+ );
222
246
  }
223
247
  };
224
248
 
@@ -29,7 +29,7 @@ var ZodSchemaValidator = class {
29
29
  boolean = z.preprocess((val) => {
30
30
  if (typeof val === "string") {
31
31
  if (val.toLowerCase() === "true") return true;
32
- return false;
32
+ if (val.toLowerCase() === "false") return false;
33
33
  }
34
34
  return val;
35
35
  }, z.boolean());
@@ -130,7 +130,9 @@ var ZodSchemaValidator = class {
130
130
  * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
131
131
  */
132
132
  enum_(schemaEnum) {
133
- return this.union(Object.values(schemaEnum));
133
+ return this.union(
134
+ Object.values(schemaEnum)
135
+ );
134
136
  }
135
137
  /**
136
138
  * Checks if a value is a Zod schema.
@@ -147,7 +149,8 @@ var ZodSchemaValidator = class {
147
149
  * @returns {boolean} True if valid, otherwise false.
148
150
  */
149
151
  validate(schema, value) {
150
- return schema.safeParse(value).success;
152
+ const resolvedSchema = schema instanceof ZodType ? schema : this.schemify(schema);
153
+ return resolvedSchema.safeParse(value).success;
151
154
  }
152
155
  /**
153
156
  * Parses a value to a schema validation.
@@ -157,13 +160,32 @@ var ZodSchemaValidator = class {
157
160
  * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
158
161
  */
159
162
  parse(schema, value) {
160
- const result = schema.safeParse(value);
163
+ const resolvedSchema = schema instanceof ZodType ? schema : this.schemify(schema);
164
+ const result = resolvedSchema.safeParse(value);
161
165
  return result.success ? { ok: true, value: result.data } : {
162
166
  ok: false,
163
- errors: result.error.errors.map((error) => ({
164
- path: error.path.map((p) => p.toString()),
165
- message: error.message
166
- }))
167
+ errors: result.error.errors.flatMap((error) => {
168
+ switch (error.code) {
169
+ case "invalid_union":
170
+ return error.unionErrors.flatMap(
171
+ (unionError, idx) => unionError.errors.map((e) => ({
172
+ path: [
173
+ `Union Schema Variant ${idx}`,
174
+ ...error.path.map((p) => p.toString()),
175
+ ...e.path.map((p) => p.toString())
176
+ ],
177
+ message: e.message
178
+ }))
179
+ );
180
+ default:
181
+ return [
182
+ {
183
+ path: error.path.map((p) => p.toString()),
184
+ message: error.message
185
+ }
186
+ ];
187
+ }
188
+ })
167
189
  };
168
190
  }
169
191
  /**
@@ -172,7 +194,9 @@ var ZodSchemaValidator = class {
172
194
  * @returns {SchemaObject} The OpenAPI schema object.
173
195
  */
174
196
  openapi(schema) {
175
- return generateSchema(this.schemify(schema));
197
+ return generateSchema(
198
+ schema instanceof ZodType ? schema : this.schemify(schema)
199
+ );
176
200
  }
177
201
  };
178
202
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/validator",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "Schema validator for ForkLaunch components.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -44,41 +44,42 @@
44
44
  "default": "./lib/src/zod/types/schema.types.js"
45
45
  },
46
46
  "./tests/mockSchemaValidator": {
47
- "types": "./lib/tests/utils/mockSchemaValidator.d.ts",
48
- "import": "./lib/tests/utils/mockSchemaValidator.mjs",
49
- "require": "./lib/tests/utils/mockSchemaValidator.js",
50
- "default": "./lib/tests/utils/mockSchemaValidator.js"
47
+ "types": "./lib/__test__/utils/mockSchemaValidator.d.ts",
48
+ "import": "./lib/__test__/utils/mockSchemaValidator.mjs",
49
+ "require": "./lib/__test__/utils/mockSchemaValidator.js",
50
+ "default": "./lib/__test__/utils/mockSchemaValidator.js"
51
51
  }
52
52
  },
53
53
  "types": "lib/index.d.ts",
54
54
  "directories": {
55
- "test": "tests"
55
+ "test": "__test__"
56
56
  },
57
57
  "files": [
58
58
  "lib"
59
59
  ],
60
60
  "dependencies": {
61
61
  "@anatine/zod-openapi": "^2.2.7",
62
- "@sinclair/typebox": "^0.34.28",
62
+ "@sinclair/typebox": "^0.34.33",
63
63
  "zod": "^3.24.2",
64
- "@forklaunch/common": "0.2.3"
64
+ "@forklaunch/common": "0.2.5"
65
65
  },
66
66
  "devDependencies": {
67
- "@eslint/js": "^9.22.0",
67
+ "@eslint/js": "^9.23.0",
68
68
  "@types/jest": "^29.5.14",
69
- "@vitest/coverage-v8": "^3.0.8",
69
+ "@vitest/coverage-v8": "^3.1.1",
70
70
  "eslint-config-prettier": "^10.1.1",
71
- "eslint-plugin-prettier": "^5.2.3",
71
+ "eslint-plugin-prettier": "^5.2.6",
72
72
  "globals": "^16.0.0",
73
73
  "jest": "^29.7.0",
74
74
  "openapi3-ts": "^4.4.0",
75
- "ts-jest": "^29.2.6",
75
+ "ts-jest": "^29.3.1",
76
76
  "ts-node": "^10.9.2",
77
77
  "tsup": "^8.4.0",
78
- "typescript-eslint": "^8.26.0"
78
+ "typedoc": "^0.28.1",
79
+ "typescript-eslint": "^8.29.0"
79
80
  },
80
81
  "scripts": {
81
- "build": "tsc --noEmit && tsup index.ts src/typebox/index.ts src/zod/index.ts tests/utils/mockSchemaValidator.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",
82
+ "build": "tsc --noEmit && tsup index.ts src/typebox/index.ts src/zod/index.ts __test__/utils/mockSchemaValidator.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",
82
83
  "check": "depcheck",
83
84
  "clean": "rm -rf lib pnpm.lock.yaml node_modules",
84
85
  "docs": "typedoc --out docs *",