@forklaunch/validator 0.2.6 → 0.2.7

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/package.json +2 -1
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -18
  4. package/dist/index.js.map +0 -1
  5. package/dist/jest.config.d.ts +0 -3
  6. package/dist/jest.config.js +0 -10
  7. package/dist/jest.config.js.map +0 -1
  8. package/dist/tests/mockSchemaValidator.d.ts +0 -24
  9. package/dist/tests/mockSchemaValidator.js +0 -41
  10. package/dist/tests/mockSchemaValidator.js.map +0 -1
  11. package/dist/tests/typebox/equality.test.d.ts +0 -1
  12. package/dist/tests/typebox/equality.test.js +0 -234
  13. package/dist/tests/typebox/equality.test.js.map +0 -1
  14. package/dist/tests/typebox/largeSchema.test.d.ts +0 -1
  15. package/dist/tests/typebox/largeSchema.test.js +0 -153
  16. package/dist/tests/typebox/largeSchema.test.js.map +0 -1
  17. package/dist/tests/zod/equality.test.d.ts +0 -1
  18. package/dist/tests/zod/equality.test.js +0 -238
  19. package/dist/tests/zod/equality.test.js.map +0 -1
  20. package/dist/tests/zod/largeSchema.test.d.ts +0 -1
  21. package/dist/tests/zod/largeSchema.test.js +0 -153
  22. package/dist/tests/zod/largeSchema.test.js.map +0 -1
  23. package/dist/typebox/index.d.ts +0 -150
  24. package/dist/typebox/index.js +0 -203
  25. package/dist/typebox/index.js.map +0 -1
  26. package/dist/typebox/types/typebox.schema.types.d.ts +0 -63
  27. package/dist/typebox/types/typebox.schema.types.js +0 -3
  28. package/dist/typebox/types/typebox.schema.types.js.map +0 -1
  29. package/dist/types/index.d.ts +0 -1
  30. package/dist/types/index.js +0 -18
  31. package/dist/types/index.js.map +0 -1
  32. package/dist/types/schema.types.d.ts +0 -153
  33. package/dist/types/schema.types.js +0 -3
  34. package/dist/types/schema.types.js.map +0 -1
  35. package/dist/zod/index.d.ts +0 -147
  36. package/dist/zod/index.js +0 -196
  37. package/dist/zod/index.js.map +0 -1
  38. package/dist/zod/types/zod.schema.types.d.ts +0 -70
  39. package/dist/zod/types/zod.schema.types.js +0 -3
  40. package/dist/zod/types/zod.schema.types.js.map +0 -1
package/dist/zod/index.js DELETED
@@ -1,196 +0,0 @@
1
- "use strict";
2
- /**
3
- * This module provides a Zod-based schema definition.
4
- * It includes various types, schema creation, validation, and OpenAPI integration.
5
- *
6
- * @module ZodSchemaValidator
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.ZodSchema = exports.ZodSchemaValidator = void 0;
10
- const zod_openapi_1 = require("@anatine/zod-openapi");
11
- const zod_1 = require("zod");
12
- /**
13
- * Class representing a Zod schema definition.
14
- * @implements {SchemaValidator}
15
- */
16
- class ZodSchemaValidator {
17
- _Type;
18
- _SchemaCatchall;
19
- _ValidSchemaObject;
20
- string = zod_1.z.string();
21
- number = zod_1.z.number();
22
- bigint = zod_1.z.bigint();
23
- boolean = zod_1.z.boolean();
24
- date = zod_1.z.date();
25
- symbol = zod_1.z.symbol();
26
- empty = zod_1.z.union([zod_1.z.void(), zod_1.z.null(), zod_1.z.undefined()]);
27
- any = zod_1.z.any();
28
- unknown = zod_1.z.unknown();
29
- never = zod_1.z.never();
30
- /**
31
- * Convert a schema to a Zod schema.
32
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
33
- * @returns {ZodResolve<T>} The resolved schema.
34
- */
35
- schemify(schema) {
36
- if (typeof schema === 'string' ||
37
- typeof schema === 'number' ||
38
- typeof schema === 'boolean') {
39
- return zod_1.z.literal(schema);
40
- }
41
- if (schema instanceof zod_1.ZodType) {
42
- return schema;
43
- }
44
- const newSchema = {};
45
- Object.getOwnPropertyNames(schema).forEach((key) => {
46
- if (schema[key] instanceof zod_1.ZodType) {
47
- newSchema[key] = schema[key];
48
- }
49
- else {
50
- newSchema[key] = this.schemify(schema[key]);
51
- }
52
- });
53
- return zod_1.z.object(newSchema);
54
- }
55
- /**
56
- * Make a schema optional.
57
- * @param {ZodIdiomaticSchema} schema - The schema to make optional.
58
- * @returns {ZodOptional<ZodResolve<T>>} The optional schema.
59
- */
60
- optional(schema) {
61
- if (schema instanceof zod_1.ZodType) {
62
- return schema.optional();
63
- }
64
- return this.schemify(schema).optional();
65
- }
66
- /**
67
- * Create an array schema.
68
- * @param {ZodIdiomaticSchema} schema - The schema to use for array items.
69
- * @returns {ZodArray<ZodResolve<T>>} The array schema.
70
- */
71
- array(schema) {
72
- if (schema instanceof zod_1.ZodType) {
73
- return schema.array();
74
- }
75
- return this.schemify(schema).array();
76
- }
77
- /**
78
- * Create a union schema.
79
- * @param {ZodUnionContainer} schemas - The schemas to union.
80
- * @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
81
- */
82
- union(schemas) {
83
- if (schemas.length < 2) {
84
- throw new Error('Union must have at least two schemas');
85
- }
86
- const unionTypes = schemas.map((schema) => {
87
- if (schema instanceof zod_1.ZodType) {
88
- return schema;
89
- }
90
- return this.schemify(schema);
91
- });
92
- return zod_1.z.union(unionTypes);
93
- }
94
- /**
95
- * Create a literal schema.
96
- * @param {LiteralSchema} value - The literal value.
97
- * @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
98
- */
99
- literal(value) {
100
- return zod_1.z.literal(value);
101
- }
102
- /**
103
- * Validate a value against a schema.
104
- * @param {ZodCatchall} schema - The schema to validate against.
105
- * @param {unknown} value - The value to validate.
106
- * @returns {boolean} True if valid, otherwise false.
107
- */
108
- validate(schema, value) {
109
- return schema.safeParse(value).success;
110
- }
111
- /**
112
- * Convert a schema to an OpenAPI schema object.
113
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
114
- * @returns {SchemaObject} The OpenAPI schema object.
115
- */
116
- openapi(schema) {
117
- return (0, zod_openapi_1.generateSchema)(this.schemify(schema));
118
- }
119
- }
120
- exports.ZodSchemaValidator = ZodSchemaValidator;
121
- /**
122
- * Factory function for creating a ZodSchemaValidator instance.
123
- * @returns {ZodSchemaValidator} The ZodSchemaValidator instance.
124
- */
125
- const ZodSchema = () => new ZodSchemaValidator();
126
- exports.ZodSchema = ZodSchema;
127
- const SchemaValidator = (0, exports.ZodSchema)();
128
- /**
129
- * Zod schema definition for string type.
130
- */
131
- exports.string = SchemaValidator.string;
132
- /**
133
- * Zod schema definition for number type.
134
- */
135
- exports.number = SchemaValidator.number;
136
- /**
137
- * Zod schema definition for bigint type.
138
- */
139
- exports.bigint = SchemaValidator.bigint;
140
- /**
141
- * Zod schema definition for boolean type.
142
- */
143
- exports.boolean = SchemaValidator.boolean;
144
- /**
145
- * Zod schema definition for date type.
146
- */
147
- exports.date = SchemaValidator.date;
148
- /**
149
- * Zod schema definition for symbol type.
150
- */
151
- exports.symbol = SchemaValidator.symbol;
152
- /**
153
- * Zod schema definition for undefined, null, void types.
154
- */
155
- exports.empty = SchemaValidator.empty;
156
- /**
157
- * Zod schema definition for any type.
158
- */
159
- exports.any = SchemaValidator.any;
160
- /**
161
- * Zod schema definition for unknown type.
162
- */
163
- exports.unknown = SchemaValidator.unknown;
164
- /**
165
- * Zod schema definition for never type.
166
- */
167
- exports.never = SchemaValidator.never;
168
- /**
169
- * Transforms valid schema into Zod schema.
170
- */
171
- exports.schemify = SchemaValidator.schemify.bind(SchemaValidator);
172
- /**
173
- * Makes a valid schema optional.
174
- */
175
- exports.optional = SchemaValidator.optional.bind(SchemaValidator);
176
- /**
177
- * Defines an array for a valid schema.
178
- */
179
- exports.array = SchemaValidator.array.bind(SchemaValidator);
180
- /**
181
- * Defines a union for a valid schema.
182
- */
183
- exports.union = SchemaValidator.union.bind(SchemaValidator);
184
- /**
185
- * Defines a literal for a valid schema.
186
- */
187
- exports.literal = SchemaValidator.literal.bind(SchemaValidator);
188
- /**
189
- * Validates a value against a valid schema.
190
- */
191
- exports.validate = SchemaValidator.validate.bind(SchemaValidator);
192
- /**
193
- * Generates an OpenAPI schema object from a valid schema.
194
- */
195
- exports.openapi = SchemaValidator.openapi.bind(SchemaValidator);
196
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../zod/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,sDAAsD;AAEtD,6BASa;AAUb;;;GAGG;AACH,MAAa,kBAAkB;IAY7B,KAAK,CAAS;IACd,eAAe,CAAW;IAC1B,kBAAkB,CAEmB;IAErC,MAAM,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;IACpB,MAAM,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;IACpB,MAAM,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;IACpB,OAAO,GAAG,OAAC,CAAC,OAAO,EAAE,CAAC;IACtB,IAAI,GAAG,OAAC,CAAC,IAAI,EAAE,CAAC;IAChB,MAAM,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;IACpB,KAAK,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,IAAI,EAAE,EAAE,OAAC,CAAC,IAAI,EAAE,EAAE,OAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IACrD,GAAG,GAAG,OAAC,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,GAAG,OAAC,CAAC,OAAO,EAAE,CAAC;IACtB,KAAK,GAAG,OAAC,CAAC,KAAK,EAAE,CAAC;IAElB;;;;OAIG;IACH,QAAQ,CAA+B,MAAS;QAC9C,IACE,OAAO,MAAM,KAAK,QAAQ;YAC1B,OAAO,MAAM,KAAK,QAAQ;YAC1B,OAAO,MAAM,KAAK,SAAS,EAC3B,CAAC;YACD,OAAO,OAAC,CAAC,OAAO,CAAC,MAAM,CAAkB,CAAC;QAC5C,CAAC;QAED,IAAI,MAAM,YAAY,aAAO,EAAE,CAAC;YAC9B,OAAO,MAAuB,CAAC;QACjC,CAAC;QAED,MAAM,SAAS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,OAAO,CAAC;AAE/E;;GAEG;AACU,QAAA,KAAK,GAAiC,eAAe,CAAC,KAAK,CAAC;AAEzE;;GAEG;AACU,QAAA,QAAQ,GACnB,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAEjD;;GAEG;AACU,QAAA,QAAQ,GACnB,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAEjD;;GAEG;AACU,QAAA,KAAK,GAChB,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAE9C;;GAEG;AACU,QAAA,KAAK,GAChB,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAE9C;;GAEG;AACU,QAAA,OAAO,GAClB,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAEhD;;GAEG;AACU,QAAA,QAAQ,GACnB,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAEjD;;GAEG;AACU,QAAA,OAAO,GAClB,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC"}
@@ -1,70 +0,0 @@
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';
4
- /**
5
- * Represents a catch-all Zod schema type.
6
- */
7
- export type ZodCatchall = ZodTypeAny;
8
- /**
9
- * 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.
10
- *
11
- * @template T - The type to check and possibly convert to an array schema.
12
- */
13
- export type ZodOuterArray<T> = T extends ZodObject<ZodObjectShape> ? ZodArray<T> : ZodNever;
14
- /**
15
- * Represents the shape of a Zod object schema.
16
- */
17
- export type ZodObjectShape = ZodRawShape;
18
- /**
19
- * Represents a Zod object schema type. If the type T is a Zod object shape, it will return the original ZodObject type of T. Otherwise, it returns ZodNever.
20
- *
21
- * @template T - The type to check and possibly convert to a Zod object schema.
22
- */
23
- export type ZodObject<T> = T extends ZodObjectShape ? OriginalZodObject<T> : ZodNever;
24
- /**
25
- * Translates a Zod schema type T to its static type if T extends ZodCatchall. Otherwise, it returns ZodNever.
26
- *
27
- * @template T - The Zod schema type to translate.
28
- */
29
- export type ZodSchemaTranslate<T> = T extends ZodCatchall ? z.infer<T> : ZodNever;
30
- /**
31
- * Represents an unboxed Zod object schema where each key can have an idiomatic schema.
32
- */
33
- export type ZodObjectSchema = UnboxedObjectSchema<ZodSchemaValidator>;
34
- /**
35
- * Represents an idiomatic schema for Zod which can be an unboxed object schema or a literal schema.
36
- */
37
- export type ZodIdiomaticSchema = IdiomaticSchema<ZodSchemaValidator>;
38
- /**
39
- * Represents a container for a union of Zod idiomatic schemas.
40
- */
41
- export type ZodUnionContainer = readonly [
42
- ZodIdiomaticSchema,
43
- ZodIdiomaticSchema,
44
- ...ZodIdiomaticSchema[]
45
- ];
46
- /**
47
- * Resolves a union container to a tuple of resolved Zod idiomatic schemas.
48
- *
49
- * @template T - The union container to resolve.
50
- */
51
- export type UnionZodResolve<T extends ZodUnionContainer> = T extends [
52
- infer A extends ZodIdiomaticSchema,
53
- infer B extends ZodIdiomaticSchema,
54
- ...infer C extends ZodIdiomaticSchema[]
55
- ] ? [
56
- ZodResolve<A>,
57
- ZodResolve<B>,
58
- ...{
59
- [K in keyof C]: ZodResolve<C[K]>;
60
- }
61
- ] : [ZodNever, ZodNever];
62
- /**
63
- * Resolves a Zod schema type T to its resolved type. The depth is limited to 31 to prevent infinite recursion.
64
- *
65
- * @template T - The Zod schema type to resolve.
66
- * @template Depth - The current depth of the resolution.
67
- */
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
- [K in keyof T]: ZodResolve<T[K], Increment<Depth>>;
70
- }> : ZodNever;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=zod.schema.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod.schema.types.js","sourceRoot":"","sources":["../../../zod/types/zod.schema.types.ts"],"names":[],"mappings":""}