@forklaunch/validator 0.1.0 → 0.1.1

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 (40) hide show
  1. package/dist/index.d.ts +83 -0
  2. package/dist/index.js +6 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/interfaces/schemaDefinition.interfaces.d.ts +21 -0
  5. package/dist/interfaces/schemaDefinition.interfaces.js +3 -0
  6. package/dist/interfaces/schemaDefinition.interfaces.js.map +1 -0
  7. package/dist/tests/equality.test.d.ts +0 -0
  8. package/dist/tests/equality.test.js +2 -0
  9. package/dist/tests/equality.test.js.map +1 -0
  10. package/dist/tests/largeSchema.test.d.ts +0 -0
  11. package/dist/tests/largeSchema.test.js +2 -0
  12. package/dist/tests/largeSchema.test.js.map +1 -0
  13. package/dist/tests/typebox/equality.test.d.ts +1 -0
  14. package/dist/tests/typebox/equality.test.js +85 -0
  15. package/dist/tests/typebox/equality.test.js.map +1 -0
  16. package/dist/tests/typebox/largeSchema.test.d.ts +1 -0
  17. package/dist/tests/typebox/largeSchema.test.js +135 -0
  18. package/dist/tests/typebox/largeSchema.test.js.map +1 -0
  19. package/dist/tests/zod/equality.test.d.ts +1 -0
  20. package/dist/tests/zod/equality.test.js +85 -0
  21. package/dist/tests/zod/equality.test.js.map +1 -0
  22. package/dist/tests/zod/largeSchema.test.d.ts +1 -0
  23. package/dist/tests/zod/largeSchema.test.js +135 -0
  24. package/dist/tests/zod/largeSchema.test.js.map +1 -0
  25. package/dist/typebox.d.ts +145 -0
  26. package/dist/typebox.js +191 -0
  27. package/dist/typebox.js.map +1 -0
  28. package/dist/types/schema.types.d.ts +7 -0
  29. package/dist/types/schema.types.js +3 -0
  30. package/dist/types/schema.types.js.map +1 -0
  31. package/dist/types/typebox.schema.types.d.ts +22 -0
  32. package/dist/types/typebox.schema.types.js +3 -0
  33. package/dist/types/typebox.schema.types.js.map +1 -0
  34. package/dist/types/zod.schema.types.d.ts +24 -0
  35. package/dist/types/zod.schema.types.js +3 -0
  36. package/dist/types/zod.schema.types.js.map +1 -0
  37. package/dist/zod.d.ts +145 -0
  38. package/dist/zod.js +192 -0
  39. package/dist/zod.js.map +1 -0
  40. package/package.json +3 -6
@@ -0,0 +1,145 @@
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 TypeboxSchemaDefinition
6
+ */
7
+ import { TSchema, TArray, TOptional, TUnion, TLiteral } from '@sinclair/typebox';
8
+ import { LiteralSchema } from './types/schema.types';
9
+ import { SchemaDefinition } from './interfaces/schemaDefinition.interfaces';
10
+ import { SchemaObject } from 'openapi3-ts/oas31';
11
+ import { TUnionContainer, TIdiomaticSchema, TResolve, UnionTResolve } from './types/typebox.schema.types';
12
+ /**
13
+ * Class representing a TypeBox schema definition.
14
+ * @implements {SchemaDefinition}
15
+ */
16
+ export declare class TypeboxSchemaDefinition implements SchemaDefinition<TUnionContainer, TIdiomaticSchema, TSchema> {
17
+ string: import("@sinclair/typebox").TString;
18
+ number: import("@sinclair/typebox").TNumber;
19
+ bigint: import("@sinclair/typebox").TBigInt;
20
+ boolean: import("@sinclair/typebox").TBoolean;
21
+ date: import("@sinclair/typebox").TDate;
22
+ symbol: import("@sinclair/typebox").TSymbol;
23
+ empty: TUnion<[import("@sinclair/typebox").TVoid, import("@sinclair/typebox").TNull, import("@sinclair/typebox").TUndefined]>;
24
+ any: import("@sinclair/typebox").TAny;
25
+ unknown: import("@sinclair/typebox").TUnknown;
26
+ never: import("@sinclair/typebox").TNever;
27
+ /**
28
+ * Convert a schema to a TypeBox schema.
29
+ * @param {TIdiomaticSchema} schema - The schema to convert.
30
+ * @returns {TResolve<T>} The resolved schema.
31
+ */
32
+ schemify<T extends TIdiomaticSchema>(schema: T): TResolve<T>;
33
+ /**
34
+ * Make a schema optional.
35
+ * @param {TIdiomaticSchema} schema - The schema to make optional.
36
+ * @returns {TOptional<TResolve<T>>} The optional schema.
37
+ */
38
+ optional<T extends TIdiomaticSchema>(schema: T): TOptional<TResolve<T>>;
39
+ /**
40
+ * Create an array schema.
41
+ * @param {TIdiomaticSchema} schema - The schema to use for array items.
42
+ * @returns {TArray<TResolve<T>>} The array schema.
43
+ */
44
+ array<T extends TIdiomaticSchema>(schema: T): TArray<TResolve<T>>;
45
+ /**
46
+ * Create a union schema.
47
+ * @param {TUnionContainer} schemas - The schemas to union.
48
+ * @returns {TUnion<UnionTResolve<T>>} The union schema.
49
+ */
50
+ union<T extends TUnionContainer>(schemas: T): TUnion<UnionTResolve<T>>;
51
+ /**
52
+ * Create a literal schema.
53
+ * @param {LiteralSchema} value - The literal value.
54
+ * @returns {TLiteral<T>} The literal schema.
55
+ */
56
+ literal<T extends LiteralSchema>(value: T): TLiteral<T>;
57
+ /**
58
+ * Validate a value against a schema.
59
+ * @param {TSchema} schema - The schema to validate against.
60
+ * @param {unknown} value - The value to validate.
61
+ * @returns {boolean} True if valid, otherwise false.
62
+ */
63
+ validate<T extends TSchema>(schema: T, value: unknown): boolean;
64
+ /**
65
+ * Convert a schema to an OpenAPI schema object.
66
+ * @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
67
+ * @returns {SchemaObject} The OpenAPI schema object.
68
+ */
69
+ openapi<T extends TIdiomaticSchema | TSchema>(schema: T): SchemaObject;
70
+ }
71
+ /**
72
+ * Factory function for creating a TypeboxSchemaDefinition instance.
73
+ * @returns {TypeboxSchemaDefinition} The TypeboxSchemaDefinition instance.
74
+ */
75
+ export declare const TypeboxSchema: () => TypeboxSchemaDefinition;
76
+ declare const schemaDefinition: TypeboxSchemaDefinition;
77
+ /**
78
+ * TypeBox schema definition for string type.
79
+ */
80
+ export declare const string: typeof schemaDefinition.string;
81
+ /**
82
+ * TypeBox schema definition for number type.
83
+ */
84
+ export declare const number: typeof schemaDefinition.number;
85
+ /**
86
+ * TypeBox schema definition for bigint type.
87
+ */
88
+ export declare const bigint: typeof schemaDefinition.bigint;
89
+ /**
90
+ * TypeBox schema definition for boolean type.
91
+ */
92
+ export declare const boolean: typeof schemaDefinition.boolean;
93
+ /**
94
+ * TypeBox schema definition for date type.
95
+ */
96
+ export declare const date: typeof schemaDefinition.date;
97
+ /**
98
+ * TypeBox schema definition for symbol type.
99
+ */
100
+ export declare const symbol: typeof schemaDefinition.symbol;
101
+ /**
102
+ * TypeBox schema definition for undefined, null, void types.
103
+ */
104
+ export declare const empty: typeof schemaDefinition.empty;
105
+ /**
106
+ * TypeBox schema definition for any type.
107
+ */
108
+ export declare const any: typeof schemaDefinition.any;
109
+ /**
110
+ * TypeBox schema definition for unknown type.
111
+ */
112
+ export declare const unknown: typeof schemaDefinition.unknown;
113
+ /**
114
+ * TypeBox schema definition for never type.
115
+ */
116
+ export declare const never: typeof schemaDefinition.never;
117
+ /**
118
+ * Transforms valid schema into TypeBox schema.
119
+ */
120
+ export declare const schemify: typeof schemaDefinition.schemify;
121
+ /**
122
+ * Makes a valid schema optional.
123
+ */
124
+ export declare const optional: typeof schemaDefinition.optional;
125
+ /**
126
+ * Defines an array for a valid schema.
127
+ */
128
+ export declare const array: typeof schemaDefinition.array;
129
+ /**
130
+ * Defines a union for a valid schema.
131
+ */
132
+ export declare const union: typeof schemaDefinition.union;
133
+ /**
134
+ * Defines a literal for a valid schema.
135
+ */
136
+ export declare const literal: typeof schemaDefinition.literal;
137
+ /**
138
+ * Validates a value against a valid schema.
139
+ */
140
+ export declare const validate: typeof schemaDefinition.validate;
141
+ /**
142
+ * Generates an OpenAPI schema object from a valid schema.
143
+ */
144
+ export declare const openapi: typeof schemaDefinition.openapi;
145
+ export {};
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ /**
3
+ * This module provides a TypeScript-based schema definition using the TypeBox library.
4
+ * It includes various types, schema creation, validation, and OpenAPI integration.
5
+ *
6
+ * @module TypeboxSchemaDefinition
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.openapi = exports.validate = exports.literal = exports.union = exports.array = exports.optional = exports.schemify = exports.never = exports.unknown = exports.any = exports.empty = exports.symbol = exports.date = exports.boolean = exports.bigint = exports.number = exports.string = exports.TypeboxSchema = exports.TypeboxSchemaDefinition = void 0;
10
+ const typebox_1 = require("@sinclair/typebox");
11
+ const value_1 = require("@sinclair/typebox/value");
12
+ /**
13
+ * Class representing a TypeBox schema definition.
14
+ * @implements {SchemaDefinition}
15
+ */
16
+ class TypeboxSchemaDefinition {
17
+ string = typebox_1.Type.String();
18
+ number = typebox_1.Type.Number();
19
+ bigint = typebox_1.Type.BigInt();
20
+ boolean = typebox_1.Type.Boolean();
21
+ date = typebox_1.Type.Date();
22
+ symbol = typebox_1.Type.Symbol();
23
+ empty = typebox_1.Type.Union([typebox_1.Type.Void(), typebox_1.Type.Null(), typebox_1.Type.Undefined()]);
24
+ any = typebox_1.Type.Any();
25
+ unknown = typebox_1.Type.Unknown();
26
+ never = typebox_1.Type.Never();
27
+ /**
28
+ * Convert a schema to a TypeBox schema.
29
+ * @param {TIdiomaticSchema} schema - The schema to convert.
30
+ * @returns {TResolve<T>} The resolved schema.
31
+ */
32
+ schemify(schema) {
33
+ if (typeof schema === 'string' || typeof schema === 'number' || typeof schema === 'boolean') {
34
+ return typebox_1.Type.Literal(schema);
35
+ }
36
+ if (typebox_1.Kind in schema) {
37
+ return schema;
38
+ }
39
+ const newSchema = {};
40
+ Object.getOwnPropertyNames(schema).forEach((key) => {
41
+ if (typeof schema[key] === 'object' && typebox_1.Kind in schema[key]) {
42
+ newSchema[key] = schema[key];
43
+ }
44
+ else {
45
+ const scheme = this.schemify(schema[key]);
46
+ newSchema[key] = scheme;
47
+ }
48
+ });
49
+ return typebox_1.Type.Object(newSchema);
50
+ }
51
+ /**
52
+ * Make a schema optional.
53
+ * @param {TIdiomaticSchema} schema - The schema to make optional.
54
+ * @returns {TOptional<TResolve<T>>} The optional schema.
55
+ */
56
+ optional(schema) {
57
+ if (typebox_1.Kind in schema) {
58
+ return typebox_1.Type.Optional(schema);
59
+ }
60
+ const scheme = this.schemify(schema);
61
+ return typebox_1.Type.Optional(scheme);
62
+ }
63
+ /**
64
+ * Create an array schema.
65
+ * @param {TIdiomaticSchema} schema - The schema to use for array items.
66
+ * @returns {TArray<TResolve<T>>} The array schema.
67
+ */
68
+ array(schema) {
69
+ if (typebox_1.Kind in schema) {
70
+ return typebox_1.Type.Array(schema);
71
+ }
72
+ const scheme = this.schemify(schema);
73
+ return typebox_1.Type.Array(scheme);
74
+ }
75
+ /**
76
+ * Create a union schema.
77
+ * @param {TUnionContainer} schemas - The schemas to union.
78
+ * @returns {TUnion<UnionTResolve<T>>} The union schema.
79
+ */
80
+ union(schemas) {
81
+ const unionTypes = schemas.map((schema) => {
82
+ if (typebox_1.Kind in schema) {
83
+ return schema;
84
+ }
85
+ return this.schemify(schema);
86
+ });
87
+ return typebox_1.Type.Union(unionTypes);
88
+ }
89
+ /**
90
+ * Create a literal schema.
91
+ * @param {LiteralSchema} value - The literal value.
92
+ * @returns {TLiteral<T>} The literal schema.
93
+ */
94
+ literal(value) {
95
+ return typebox_1.Type.Literal(value);
96
+ }
97
+ /**
98
+ * Validate a value against a schema.
99
+ * @param {TSchema} schema - The schema to validate against.
100
+ * @param {unknown} value - The value to validate.
101
+ * @returns {boolean} True if valid, otherwise false.
102
+ */
103
+ validate(schema, value) {
104
+ return value_1.Value.Check(schema, value);
105
+ }
106
+ /**
107
+ * Convert a schema to an OpenAPI schema object.
108
+ * @param {TIdiomaticSchema | TSchema} schema - The schema to convert.
109
+ * @returns {SchemaObject} The OpenAPI schema object.
110
+ */
111
+ openapi(schema) {
112
+ return this.schemify(schema);
113
+ }
114
+ }
115
+ exports.TypeboxSchemaDefinition = TypeboxSchemaDefinition;
116
+ /**
117
+ * Factory function for creating a TypeboxSchemaDefinition instance.
118
+ * @returns {TypeboxSchemaDefinition} The TypeboxSchemaDefinition instance.
119
+ */
120
+ const TypeboxSchema = () => new TypeboxSchemaDefinition();
121
+ exports.TypeboxSchema = TypeboxSchema;
122
+ const schemaDefinition = (0, exports.TypeboxSchema)();
123
+ /**
124
+ * TypeBox schema definition for string type.
125
+ */
126
+ exports.string = schemaDefinition.string;
127
+ /**
128
+ * TypeBox schema definition for number type.
129
+ */
130
+ exports.number = schemaDefinition.number;
131
+ /**
132
+ * TypeBox schema definition for bigint type.
133
+ */
134
+ exports.bigint = schemaDefinition.bigint;
135
+ /**
136
+ * TypeBox schema definition for boolean type.
137
+ */
138
+ exports.boolean = schemaDefinition.boolean;
139
+ /**
140
+ * TypeBox schema definition for date type.
141
+ */
142
+ exports.date = schemaDefinition.date;
143
+ /**
144
+ * TypeBox schema definition for symbol type.
145
+ */
146
+ exports.symbol = schemaDefinition.symbol;
147
+ /**
148
+ * TypeBox schema definition for undefined, null, void types.
149
+ */
150
+ exports.empty = schemaDefinition.empty;
151
+ /**
152
+ * TypeBox schema definition for any type.
153
+ */
154
+ exports.any = schemaDefinition.any;
155
+ /**
156
+ * TypeBox schema definition for unknown type.
157
+ */
158
+ exports.unknown = schemaDefinition.unknown;
159
+ /**
160
+ * TypeBox schema definition for never type.
161
+ */
162
+ exports.never = schemaDefinition.never;
163
+ /**
164
+ * Transforms valid schema into TypeBox schema.
165
+ */
166
+ exports.schemify = schemaDefinition.schemify.bind(schemaDefinition);
167
+ /**
168
+ * Makes a valid schema optional.
169
+ */
170
+ exports.optional = schemaDefinition.optional.bind(schemaDefinition);
171
+ /**
172
+ * Defines an array for a valid schema.
173
+ */
174
+ exports.array = schemaDefinition.array.bind(schemaDefinition);
175
+ /**
176
+ * Defines a union for a valid schema.
177
+ */
178
+ exports.union = schemaDefinition.union.bind(schemaDefinition);
179
+ /**
180
+ * Defines a literal for a valid schema.
181
+ */
182
+ exports.literal = schemaDefinition.literal.bind(schemaDefinition);
183
+ /**
184
+ * Validates a value against a valid schema.
185
+ */
186
+ exports.validate = schemaDefinition.validate.bind(schemaDefinition);
187
+ /**
188
+ * Generates an OpenAPI schema object from a valid schema.
189
+ */
190
+ exports.openapi = schemaDefinition.openapi.bind(schemaDefinition);
191
+ //# sourceMappingURL=typebox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typebox.js","sourceRoot":"","sources":["../typebox.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+CAA6F;AAC7F,mDAAgD;AAMhD;;;GAGG;AACH,MAAa,uBAAuB;IAKhC,MAAM,GAAG,cAAI,CAAC,MAAM,EAAE,CAAC;IACvB,MAAM,GAAG,cAAI,CAAC,MAAM,EAAE,CAAC;IACvB,MAAM,GAAG,cAAI,CAAC,MAAM,EAAE,CAAC;IACvB,OAAO,GAAG,cAAI,CAAC,OAAO,EAAE,CAAC;IACzB,IAAI,GAAG,cAAI,CAAC,IAAI,EAAE,CAAC;IACnB,MAAM,GAAG,cAAI,CAAC,MAAM,EAAE,CAAC;IACvB,KAAK,GAAG,cAAI,CAAC,KAAK,CAAC,CAAC,cAAI,CAAC,IAAI,EAAE,EAAE,cAAI,CAAC,IAAI,EAAE,EAAE,cAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IACjE,GAAG,GAAG,cAAI,CAAC,GAAG,EAAE,CAAC;IACjB,OAAO,GAAG,cAAI,CAAC,OAAO,EAAE,CAAC;IACzB,KAAK,GAAG,cAAI,CAAC,KAAK,EAAE,CAAC;IAErB;;;;OAIG;IACH,QAAQ,CAA6B,MAAS;QAC1C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,SAAS,EAAE;YACzF,OAAO,cAAI,CAAC,OAAO,CAAC,MAAM,CAAgB,CAAC;SAC9C;QAED,IAAI,cAAI,IAAK,MAAkB,EAAE;YAC7B,OAAO,MAAqB,CAAC;SAChC;QAED,MAAM,SAAS,GAEX,EAAE,CAAC;QACP,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/C,IAAI,OAAO,MAAM,CAAC,GA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AA,QAAQ,GAAqC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAE3G;;GAEG;AACU,QAAA,QAAQ,GAAqC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAE3G;;GAEG;AACU,QAAA,KAAK,GAAkC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAElG;;GAEG;AACU,QAAA,KAAK,GAAkC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAElG;;GAEG;AACU,QAAA,OAAO,GAAoC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAExG;;GAEG;AACU,QAAA,QAAQ,GAAqC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAE3G;;GAEG;AACU,QAAA,OAAO,GAAoC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type UnboxedObjectSchema<Catchall> = {
2
+ [key: KeyTypes]: IdiomaticSchema<Catchall>;
3
+ };
4
+ export type LiteralSchema = string | number | boolean;
5
+ export type IdiomaticSchema<Catchall> = UnboxedObjectSchema<Catchall> | LiteralSchema | Catchall;
6
+ export type Increment<T extends number> = T extends 0 ? 1 : T extends 1 ? 2 : T extends 2 ? 3 : T extends 3 ? 4 : T extends 4 ? 5 : T extends 5 ? 6 : T extends 6 ? 7 : T extends 7 ? 8 : T extends 8 ? 9 : T extends 9 ? 10 : T extends 10 ? 11 : T extends 11 ? 12 : T extends 12 ? 13 : T extends 13 ? 14 : T extends 14 ? 15 : T extends 15 ? 16 : T extends 16 ? 17 : T extends 17 ? 18 : T extends 18 ? 19 : T extends 19 ? 20 : T extends 20 ? 21 : T extends 21 ? 22 : T extends 22 ? 23 : T extends 23 ? 24 : T extends 24 ? 25 : T extends 25 ? 26 : T extends 26 ? 27 : T extends 27 ? 28 : T extends 28 ? 29 : T extends 29 ? 30 : T extends 30 ? 31 : T extends 31 ? 32 : T extends 32 ? 33 : T extends 33 ? 34 : T extends 34 ? 35 : T extends 35 ? 36 : T extends 36 ? 37 : T extends 37 ? 38 : T extends 38 ? 39 : T extends 39 ? 40 : T extends 40 ? 41 : T extends 41 ? 42 : T extends 42 ? 43 : T extends 43 ? 44 : T extends 44 ? 45 : T extends 45 ? 46 : T extends 46 ? 47 : T extends 47 ? 48 : T extends 48 ? 49 : T extends 49 ? 50 : 50;
7
+ export type KeyTypes = string | number;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=schema.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.types.js","sourceRoot":"","sources":["../../types/schema.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import { TSchema, TObject as OriginalTObject, TArray, TLiteral, TNever, Static, TProperties, TKind, TAny } from '@sinclair/typebox';
2
+ import { Increment, KeyTypes, LiteralSchema } from './schema.types';
3
+ export type TCatchall = TSchema;
4
+ export type TOuterArray<T> = T extends TObject<TObjectShape> ? TArray<T> : TNever;
5
+ export type TObjectShape = TProperties;
6
+ export type TObject<T> = T extends TObjectShape ? OriginalTObject<T> : TNever;
7
+ export type TSchemaTranslate<T> = T extends TCatchall ? Static<T> : TNever;
8
+ export type UnboxedTObjectSchema = {
9
+ [key: KeyTypes]: TIdiomaticSchema;
10
+ };
11
+ export type TIdiomaticSchema = UnboxedTObjectSchema | LiteralSchema;
12
+ export type TUnionContainer = [...TIdiomaticSchema[]];
13
+ export type UnionTResolve<T extends TUnionContainer> = T extends [
14
+ ...infer A extends TIdiomaticSchema[]
15
+ ] ? [
16
+ ...{
17
+ [K in keyof A]: TResolve<A[K]>;
18
+ }
19
+ ] : [];
20
+ export type TResolve<T, Depth extends number = 0> = Depth extends 22 ? TAny : T extends TKind ? T : T extends LiteralSchema ? TLiteral<T> : T extends UnboxedTObjectSchema ? TObject<{
21
+ [K in keyof T]: TResolve<T[K], Increment<Depth>>;
22
+ }> : TNever;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=typebox.schema.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typebox.schema.types.js","sourceRoot":"","sources":["../../types/typebox.schema.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { ZodArray, ZodObject as OriginalZodObject, ZodRawShape, ZodType, ZodTypeAny, z, ZodLiteral, ZodNever, ZodAny } from "zod";
2
+ import { IdiomaticSchema, UnboxedObjectSchema, LiteralSchema, Increment } from "./schema.types";
3
+ export type ZodCatchall = ZodTypeAny;
4
+ export type ZodOuterArray<T> = T extends ZodObject<ZodObjectShape> ? ZodArray<T> : ZodNever;
5
+ export type ZodObjectShape = ZodRawShape;
6
+ export type ZodObject<T> = T extends ZodObjectShape ? OriginalZodObject<T> : ZodNever;
7
+ export type ZodSchemaTranslate<T> = T extends ZodCatchall ? z.infer<T> : ZodNever;
8
+ export type ZodObjectSchema = UnboxedObjectSchema<ZodCatchall>;
9
+ export type ZodIdiomaticSchema = IdiomaticSchema<ZodCatchall>;
10
+ export type ZodUnionContainer = readonly [ZodIdiomaticSchema, ZodIdiomaticSchema, ...ZodIdiomaticSchema[]];
11
+ export type UnionZodResolve<T extends ZodUnionContainer> = T extends [
12
+ infer A extends ZodIdiomaticSchema,
13
+ infer B extends ZodIdiomaticSchema,
14
+ ...infer C extends ZodIdiomaticSchema[]
15
+ ] ? [
16
+ ZodResolve<A>,
17
+ ZodResolve<B>,
18
+ ...{
19
+ [K in keyof C]: ZodResolve<C[K]>;
20
+ }
21
+ ] : [ZodNever, ZodNever];
22
+ export type ZodResolve<T, Depth extends number = 0> = Depth extends 22 ? ZodAny : T extends LiteralSchema ? ZodLiteral<T> : T extends ZodType | ZodObject<any> ? T : T extends ZodObjectSchema ? ZodObject<{
23
+ [K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
24
+ }> : ZodNever;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=zod.schema.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.schema.types.js","sourceRoot":"","sources":["../../types/zod.schema.types.ts"],"names":[],"mappings":""}
package/dist/zod.d.ts ADDED
@@ -0,0 +1,145 @@
1
+ /**
2
+ * This module provides a Zod-based schema definition.
3
+ * It includes various types, schema creation, validation, and OpenAPI integration.
4
+ *
5
+ * @module ZodSchemaDefinition
6
+ */
7
+ import { ZodArray, ZodOptional, ZodUnion, z, ZodLiteral } from "zod";
8
+ import { LiteralSchema } from "./types/schema.types";
9
+ import { SchemaDefinition } from "./interfaces/schemaDefinition.interfaces";
10
+ import { SchemaObject } from 'openapi3-ts/oas31';
11
+ import { ZodUnionContainer, ZodIdiomaticSchema, ZodCatchall, ZodResolve, UnionZodResolve } from "./types/zod.schema.types";
12
+ /**
13
+ * Class representing a Zod schema definition.
14
+ * @implements {SchemaDefinition}
15
+ */
16
+ export declare class ZodSchemaDefinition implements SchemaDefinition<ZodUnionContainer, ZodIdiomaticSchema, ZodCatchall> {
17
+ string: z.ZodString;
18
+ number: z.ZodNumber;
19
+ bigint: z.ZodBigInt;
20
+ boolean: z.ZodBoolean;
21
+ date: z.ZodDate;
22
+ symbol: z.ZodSymbol;
23
+ empty: ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
24
+ any: z.ZodAny;
25
+ unknown: z.ZodUnknown;
26
+ never: z.ZodNever;
27
+ /**
28
+ * Convert a schema to a Zod schema.
29
+ * @param {ZodIdiomaticSchema} schema - The schema to convert.
30
+ * @returns {ZodResolve<T>} The resolved schema.
31
+ */
32
+ schemify<T extends ZodIdiomaticSchema>(schema: T): ZodResolve<T>;
33
+ /**
34
+ * Make a schema optional.
35
+ * @param {ZodIdiomaticSchema} schema - The schema to make optional.
36
+ * @returns {ZodOptional<ZodResolve<T>>} The optional schema.
37
+ */
38
+ optional<T extends ZodIdiomaticSchema>(schema: T): ZodOptional<ZodResolve<T>>;
39
+ /**
40
+ * Create an array schema.
41
+ * @param {ZodIdiomaticSchema} schema - The schema to use for array items.
42
+ * @returns {ZodArray<ZodResolve<T>>} The array schema.
43
+ */
44
+ array<T extends ZodIdiomaticSchema>(schema: T): ZodArray<ZodResolve<T>>;
45
+ /**
46
+ * Create a union schema.
47
+ * @param {ZodUnionContainer} schemas - The schemas to union.
48
+ * @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
49
+ */
50
+ union<T extends ZodUnionContainer>(schemas: T): ZodUnion<UnionZodResolve<T>>;
51
+ /**
52
+ * Create a literal schema.
53
+ * @param {LiteralSchema} value - The literal value.
54
+ * @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
55
+ */
56
+ literal<T extends LiteralSchema>(value: T): ZodLiteral<ZodResolve<T>>;
57
+ /**
58
+ * Validate a value against a schema.
59
+ * @param {ZodCatchall} schema - The schema to validate against.
60
+ * @param {unknown} value - The value to validate.
61
+ * @returns {boolean} True if valid, otherwise false.
62
+ */
63
+ validate<T extends ZodCatchall>(schema: T, value: unknown): boolean;
64
+ /**
65
+ * Convert a schema to an OpenAPI schema object.
66
+ * @param {ZodIdiomaticSchema} schema - The schema to convert.
67
+ * @returns {SchemaObject} The OpenAPI schema object.
68
+ */
69
+ openapi<T extends ZodIdiomaticSchema>(schema: T): SchemaObject;
70
+ }
71
+ /**
72
+ * Factory function for creating a ZodSchemaDefinition instance.
73
+ * @returns {ZodSchemaDefinition} The ZodSchemaDefinition instance.
74
+ */
75
+ export declare const ZodSchema: () => ZodSchemaDefinition;
76
+ declare const schemaDefinition: ZodSchemaDefinition;
77
+ /**
78
+ * Zod schema definition for string type.
79
+ */
80
+ export declare const string: typeof schemaDefinition.string;
81
+ /**
82
+ * Zod schema definition for number type.
83
+ */
84
+ export declare const number: typeof schemaDefinition.number;
85
+ /**
86
+ * Zod schema definition for bigint type.
87
+ */
88
+ export declare const bigint: typeof schemaDefinition.bigint;
89
+ /**
90
+ * Zod schema definition for boolean type.
91
+ */
92
+ export declare const boolean: typeof schemaDefinition.boolean;
93
+ /**
94
+ * Zod schema definition for date type.
95
+ */
96
+ export declare const date: typeof schemaDefinition.date;
97
+ /**
98
+ * Zod schema definition for symbol type.
99
+ */
100
+ export declare const symbol: typeof schemaDefinition.symbol;
101
+ /**
102
+ * Zod schema definition for undefined, null, void types.
103
+ */
104
+ export declare const empty: typeof schemaDefinition.empty;
105
+ /**
106
+ * Zod schema definition for any type.
107
+ */
108
+ export declare const any: typeof schemaDefinition.any;
109
+ /**
110
+ * Zod schema definition for unknown type.
111
+ */
112
+ export declare const unknown: typeof schemaDefinition.unknown;
113
+ /**
114
+ * Zod schema definition for never type.
115
+ */
116
+ export declare const never: typeof schemaDefinition.never;
117
+ /**
118
+ * Transforms valid schema into Zod schema.
119
+ */
120
+ export declare const schemify: typeof schemaDefinition.schemify;
121
+ /**
122
+ * Makes a valid schema optional.
123
+ */
124
+ export declare const optional: typeof schemaDefinition.optional;
125
+ /**
126
+ * Defines an array for a valid schema.
127
+ */
128
+ export declare const array: typeof schemaDefinition.array;
129
+ /**
130
+ * Defines a union for a valid schema.
131
+ */
132
+ export declare const union: typeof schemaDefinition.union;
133
+ /**
134
+ * Defines a literal for a valid schema.
135
+ */
136
+ export declare const literal: typeof schemaDefinition.literal;
137
+ /**
138
+ * Validates a value against a valid schema.
139
+ */
140
+ export declare const validate: typeof schemaDefinition.validate;
141
+ /**
142
+ * Generates an OpenAPI schema object from a valid schema.
143
+ */
144
+ export declare const openapi: typeof schemaDefinition.openapi;
145
+ export {};