@forklaunch/validator 0.3.12 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/lib/index-V6qNDTlr.d.mts +476 -0
  2. package/lib/index-V6qNDTlr.d.ts +476 -0
  3. package/lib/index.d.mts +6 -0
  4. package/lib/index.d.ts +6 -2
  5. package/lib/index.js +18 -1
  6. package/lib/index.mjs +0 -0
  7. package/lib/src/typebox/index.d.mts +220 -0
  8. package/lib/src/typebox/index.d.ts +220 -3
  9. package/lib/src/typebox/index.js +448 -1
  10. package/lib/src/typebox/index.mjs +406 -0
  11. package/lib/src/zod/index.d.mts +106 -0
  12. package/lib/src/zod/index.d.ts +106 -3
  13. package/lib/src/zod/index.js +291 -1
  14. package/lib/src/zod/index.mjs +244 -0
  15. package/lib/tests/utils/mockSchemaValidator.d.mts +69 -0
  16. package/lib/tests/utils/mockSchemaValidator.d.ts +29 -25
  17. package/lib/tests/utils/mockSchemaValidator.js +143 -79
  18. package/lib/tests/utils/mockSchemaValidator.mjs +99 -0
  19. package/package.json +21 -8
  20. package/lib/index.d.ts.map +0 -1
  21. package/lib/src/shared/types/schema.types.d.ts +0 -255
  22. package/lib/src/shared/types/schema.types.d.ts.map +0 -1
  23. package/lib/src/shared/types/schema.types.js +0 -1
  24. package/lib/src/typebox/index.d.ts.map +0 -1
  25. package/lib/src/typebox/staticSchemaValidator.d.ts +0 -99
  26. package/lib/src/typebox/staticSchemaValidator.d.ts.map +0 -1
  27. package/lib/src/typebox/staticSchemaValidator.js +0 -99
  28. package/lib/src/typebox/typeboxSchemaValidator.d.ts +0 -122
  29. package/lib/src/typebox/typeboxSchemaValidator.d.ts.map +0 -1
  30. package/lib/src/typebox/typeboxSchemaValidator.js +0 -362
  31. package/lib/src/typebox/types/schema.types.d.ts +0 -59
  32. package/lib/src/typebox/types/schema.types.d.ts.map +0 -1
  33. package/lib/src/typebox/types/schema.types.js +0 -1
  34. package/lib/src/zod/index.d.ts.map +0 -1
  35. package/lib/src/zod/staticSchemaValidator.d.ts +0 -99
  36. package/lib/src/zod/staticSchemaValidator.d.ts.map +0 -1
  37. package/lib/src/zod/staticSchemaValidator.js +0 -99
  38. package/lib/src/zod/types/schema.types.d.ts +0 -71
  39. package/lib/src/zod/types/schema.types.d.ts.map +0 -1
  40. package/lib/src/zod/types/schema.types.js +0 -1
  41. package/lib/src/zod/zodSchemaValidator.d.ts +0 -110
  42. package/lib/src/zod/zodSchemaValidator.d.ts.map +0 -1
  43. package/lib/src/zod/zodSchemaValidator.js +0 -192
  44. package/lib/tests/typebox/advancedParse.test.d.ts +0 -2
  45. package/lib/tests/typebox/advancedParse.test.d.ts.map +0 -1
  46. package/lib/tests/typebox/advancedParse.test.js +0 -514
  47. package/lib/tests/typebox/largeSchema.test.d.ts +0 -2
  48. package/lib/tests/typebox/largeSchema.test.d.ts.map +0 -1
  49. package/lib/tests/typebox/largeSchema.test.js +0 -150
  50. package/lib/tests/typebox/schemaValidator.test.d.ts +0 -2
  51. package/lib/tests/typebox/schemaValidator.test.d.ts.map +0 -1
  52. package/lib/tests/typebox/schemaValidator.test.js +0 -253
  53. package/lib/tests/typebox/typeEquality.test.d.ts +0 -2
  54. package/lib/tests/typebox/typeEquality.test.d.ts.map +0 -1
  55. package/lib/tests/typebox/typeEquality.test.js +0 -100
  56. package/lib/tests/utils/compare.d.ts +0 -2
  57. package/lib/tests/utils/compare.d.ts.map +0 -1
  58. package/lib/tests/utils/compare.js +0 -8
  59. package/lib/tests/utils/mockSchemaValidator.d.ts.map +0 -1
  60. package/lib/tests/zod/advancedParse.test.d.ts +0 -2
  61. package/lib/tests/zod/advancedParse.test.d.ts.map +0 -1
  62. package/lib/tests/zod/advancedParse.test.js +0 -514
  63. package/lib/tests/zod/largeSchema.test.d.ts +0 -2
  64. package/lib/tests/zod/largeSchema.test.d.ts.map +0 -1
  65. package/lib/tests/zod/largeSchema.test.js +0 -150
  66. package/lib/tests/zod/schemaValidator.test.d.ts +0 -2
  67. package/lib/tests/zod/schemaValidator.test.d.ts.map +0 -1
  68. package/lib/tests/zod/schemaValidator.test.js +0 -205
  69. package/lib/tests/zod/typeEquality.test.d.ts +0 -2
  70. package/lib/tests/zod/typeEquality.test.d.ts.map +0 -1
  71. package/lib/tests/zod/typeEquality.test.js +0 -100
  72. package/lib/tsconfig.tsbuildinfo +0 -1
  73. package/lib/vitest.config.d.ts +0 -3
  74. package/lib/vitest.config.d.ts.map +0 -1
  75. package/lib/vitest.config.js +0 -7
@@ -1,71 +0,0 @@
1
- import { ZodObject as OriginalZodObject, ZodArray, ZodLiteral, ZodNever, ZodRawShape, ZodType, ZodTypeAny, ZodUnknown, z } from 'zod';
2
- import { IdiomaticSchema, Increment, LiteralSchema, UnboxedObjectSchema } from '../../shared/types/schema.types';
3
- import { ZodSchemaValidator } from '../zodSchemaValidator';
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;
71
- //# sourceMappingURL=schema.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.types.d.ts","sourceRoot":"","sources":["../../../../src/zod/types/schema.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,iBAAiB,EAC9B,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,CAAC,EACF,MAAM,KAAK,CAAC;AACb,OAAO,EACL,eAAe,EAC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AC,CAAC,CAAC,CAAC;KACjC;CACF,GACD,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,GAClE,UAAU,GACV,CAAC,SAAS,aAAa,GACrB,UAAU,CAAC,CAAC,CAAC,GACb,CAAC,SAAS,OAAO,GACf,CAAC,GACD,CAAC,SAAS,eAAe,GACvB,SAAS,CAAC;KACP,CAAC,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;CACnD,CAAC,GACF,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,110 +0,0 @@
1
- /**
2
- * This module provides a Zod-based schema definition.
3
- * It includes various types, schema creation, validation, and OpenAPI integration.
4
- *
5
- * @module ZodSchemaValidator
6
- */
7
- import { SchemaObject } from 'openapi3-ts/oas31';
8
- import { ZodArray, ZodLiteral, ZodObject, ZodOptional, ZodRawShape, ZodType, ZodUnion, z } from 'zod';
9
- import { LiteralSchema, ParseResult, SchemaValidator as SV } from '../shared/types/schema.types';
10
- import { UnionZodResolve, ZodCatchall, ZodIdiomaticSchema, ZodResolve, ZodUnionContainer } from './types/schema.types';
11
- /**
12
- * Class representing a Zod schema definition.
13
- * @implements {StaticSchemaValidator}
14
- */
15
- export declare class ZodSchemaValidator implements SV<(<T extends ZodObject<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> {
16
- _Type: 'Zod';
17
- _SchemaCatchall: ZodType;
18
- _ValidSchemaObject: ZodObject<ZodRawShape> | ZodArray<ZodObject<ZodRawShape>>;
19
- string: z.ZodString;
20
- uuid: z.ZodString;
21
- email: z.ZodString;
22
- uri: z.ZodString;
23
- number: z.ZodNumber;
24
- bigint: z.ZodBigInt;
25
- boolean: z.ZodEffects<z.ZodBoolean, boolean, unknown>;
26
- date: z.ZodDate;
27
- symbol: z.ZodSymbol;
28
- nullish: ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodUndefined]>;
29
- any: z.ZodAny;
30
- unknown: z.ZodUnknown;
31
- never: z.ZodNever;
32
- /**
33
- * Pretty print Zod errors.
34
- *
35
- * @param {ZodError} error - The Zod error to pretty print.
36
- * @returns
37
- */
38
- private prettyPrintZodErrors;
39
- /**
40
- * Compiles schema if this exists, for optimal performance.
41
- *
42
- * @param {ZodObject<ZodRawShape>} schema - The schema to compile.
43
- * @returns {ZodResolve<T>} - The compiled schema.
44
- */
45
- compile<T extends ZodObject<ZodRawShape>>(schema: T): ZodResolve<T>;
46
- /**
47
- * Convert a schema to a Zod schema.
48
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
49
- * @returns {ZodResolve<T>} The resolved schema.
50
- */
51
- schemify<T extends ZodIdiomaticSchema>(schema: T): ZodResolve<T>;
52
- /**
53
- * Make a schema optional.
54
- * @param {ZodIdiomaticSchema} schema - The schema to make optional.
55
- * @returns {ZodOptional<ZodResolve<T>>} The optional schema.
56
- */
57
- optional<T extends ZodIdiomaticSchema>(schema: T): ZodOptional<ZodResolve<T>>;
58
- /**
59
- * Create an array schema.
60
- * @param {ZodIdiomaticSchema} schema - The schema to use for array items.
61
- * @returns {ZodArray<ZodResolve<T>>} The array schema.
62
- */
63
- array<T extends ZodIdiomaticSchema>(schema: T): ZodArray<ZodResolve<T>>;
64
- /**
65
- * Create a union schema.
66
- * @param {ZodUnionContainer} schemas - The schemas to union.
67
- * @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
68
- */
69
- union<T extends ZodUnionContainer>(schemas: T): ZodUnion<UnionZodResolve<T>>;
70
- /**
71
- * Create a literal schema.
72
- * @param {LiteralSchema} value - The literal value.
73
- * @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
74
- */
75
- literal<T extends LiteralSchema>(value: T): ZodLiteral<ZodResolve<T>>;
76
- /**
77
- * Create an enum schema.
78
- * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
79
- * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
80
- */
81
- enum_<T extends LiteralSchema>(schemaEnum: Record<string, T>): ZodUnion<UnionZodResolve<[T, T, ...T[]]>>;
82
- /**
83
- * Checks if a value is a Zod schema.
84
- * @param {unknown} value - The value to check.
85
- * @returns {boolean} True if the value is a Zod schema.
86
- */
87
- isSchema(value: unknown): value is ZodType;
88
- /**
89
- * Validate a value against a schema.
90
- * @param {ZodCatchall} schema - The schema to validate against.
91
- * @param {unknown} value - The value to validate.
92
- * @returns {boolean} True if valid, otherwise false.
93
- */
94
- validate<T extends ZodCatchall>(schema: T, value: unknown): boolean;
95
- /**
96
- * Parses a value to a schema validation.
97
- *
98
- * @param {ZodCatchall} schema - The schema to validate against.
99
- * @param {unknown} value - The value to validate.
100
- * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
101
- */
102
- parse<T extends ZodCatchall>(schema: T, value: unknown): ParseResult<ZodResolve<T>>;
103
- /**
104
- * Convert a schema to an OpenAPI schema object.
105
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
106
- * @returns {SchemaObject} The OpenAPI schema object.
107
- */
108
- openapi<T extends ZodIdiomaticSchema>(schema: T): SchemaObject;
109
- }
110
- //# sourceMappingURL=zodSchemaValidator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zodSchemaValidator.d.ts","sourceRoot":"","sources":["../../../src/zod/zodSchemaValidator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,QAAQ,EAER,UAAU,EACV,SAAS,EACT,WAAW,EACX,WAAW,EACX,OAAO,EACP,QAAQ,EACR,CAAC,EACF,MAAM,KAAK,CAAC;AACb,OAAO,EACL,aAAa,EACb,WAAW,EACX,eAAe,IAAI,EAAE,EACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B;;;GAGG;AACH,qBAAa,kBACX,YACE,EAAE,EACA,CAAC,CAAC,SAAS,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAC9D,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAC1D,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,KAAK,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACvE,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACpE,CAAC,CAAC,SAAS,iBAAiB,EAAE,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EACzE,CAAC,CAAC,SAAS,aAAa,EAAE,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAChE,CAAC,CAAC,SAAS,aAAa,EACtB,UAAU,EAA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AM,EAAE,CAAC,GACR,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAQ7B;;;;OAIG;IACH,KAAK,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAQvE;;;;OAIG;IACH,KAAK,CAAC,CAAC,SAAS,iBAAiB,EAAE,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAa5E;;;;OAIG;IACH,OAAO,CAAC,CAAC,SAAS,aAAa,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAIrE;;;;OAIG;IACH,KAAK,CAAC,CAAC,SAAS,aAAa,EAC3B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAC5B,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO;IAI1C;;;;;OAKG;IACH,QAAQ,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO;IAInE;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,SAAS,WAAW,EACzB,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,GACb,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAiB7B;;;;OAIG;IACH,OAAO,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,YAAY;CAG/D"}
@@ -1,192 +0,0 @@
1
- /**
2
- * This module provides a Zod-based schema definition.
3
- * It includes various types, schema creation, validation, and OpenAPI integration.
4
- *
5
- * @module ZodSchemaValidator
6
- */
7
- import { generateSchema } from '@anatine/zod-openapi';
8
- import { ZodType, z } from 'zod';
9
- /**
10
- * Class representing a Zod schema definition.
11
- * @implements {StaticSchemaValidator}
12
- */
13
- export class ZodSchemaValidator {
14
- _Type;
15
- _SchemaCatchall;
16
- _ValidSchemaObject;
17
- string = z.string();
18
- uuid = z.coerce.string().uuid();
19
- email = z.coerce.string().email();
20
- uri = z.coerce.string().url();
21
- number = z.coerce.number();
22
- bigint = z.coerce.bigint();
23
- boolean = z.preprocess((val) => {
24
- if (typeof val === 'string') {
25
- if (val.toLowerCase() === 'true')
26
- return true;
27
- if (val.toLowerCase() === 'false')
28
- return false;
29
- }
30
- return val;
31
- }, z.boolean());
32
- date = z.coerce.date();
33
- symbol = z.symbol();
34
- nullish = z.union([z.void(), z.null(), z.undefined()]);
35
- any = z.any();
36
- unknown = z.unknown();
37
- never = z.never();
38
- /**
39
- * Pretty print Zod errors.
40
- *
41
- * @param {ZodError} error - The Zod error to pretty print.
42
- * @returns
43
- */
44
- prettyPrintZodErrors(error) {
45
- if (!error)
46
- return;
47
- const errorMessages = error.errors.map((err, index) => {
48
- const path = err.path.length > 0 ? err.path.join(' > ') : 'root';
49
- return `${index + 1}. Path: ${path}\n Message: ${err.message}`;
50
- });
51
- return `Validation failed with the following errors:\n${errorMessages.join('\n\n')}`;
52
- }
53
- /**
54
- * Compiles schema if this exists, for optimal performance.
55
- *
56
- * @param {ZodObject<ZodRawShape>} schema - The schema to compile.
57
- * @returns {ZodResolve<T>} - The compiled schema.
58
- */
59
- compile(schema) {
60
- return schema;
61
- }
62
- /**
63
- * Convert a schema to a Zod schema.
64
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
65
- * @returns {ZodResolve<T>} The resolved schema.
66
- */
67
- schemify(schema) {
68
- if (typeof schema === 'string' ||
69
- typeof schema === 'number' ||
70
- typeof schema === 'boolean') {
71
- return z.literal(schema);
72
- }
73
- if (schema instanceof ZodType) {
74
- return schema;
75
- }
76
- const newSchema = {};
77
- Object.getOwnPropertyNames(schema).forEach((key) => {
78
- if (schema[key] instanceof ZodType) {
79
- newSchema[key] = schema[key];
80
- }
81
- else {
82
- newSchema[key] = this.schemify(schema[key]);
83
- }
84
- });
85
- return z.object(newSchema);
86
- }
87
- /**
88
- * Make a schema optional.
89
- * @param {ZodIdiomaticSchema} schema - The schema to make optional.
90
- * @returns {ZodOptional<ZodResolve<T>>} The optional schema.
91
- */
92
- optional(schema) {
93
- if (schema instanceof ZodType) {
94
- return schema.optional();
95
- }
96
- else {
97
- return this.schemify(schema).optional();
98
- }
99
- }
100
- /**
101
- * Create an array schema.
102
- * @param {ZodIdiomaticSchema} schema - The schema to use for array items.
103
- * @returns {ZodArray<ZodResolve<T>>} The array schema.
104
- */
105
- array(schema) {
106
- if (schema instanceof ZodType) {
107
- return schema.array();
108
- }
109
- else {
110
- return this.schemify(schema).array();
111
- }
112
- }
113
- /**
114
- * Create a union schema.
115
- * @param {ZodUnionContainer} schemas - The schemas to union.
116
- * @returns {ZodUnion<UnionZodResolve<T>>} The union schema.
117
- */
118
- union(schemas) {
119
- const resolvedSchemas = schemas.map((schema) => {
120
- if (schema instanceof ZodType) {
121
- return schema;
122
- }
123
- return this.schemify(schema);
124
- });
125
- return z.union(resolvedSchemas);
126
- }
127
- /**
128
- * Create a literal schema.
129
- * @param {LiteralSchema} value - The literal value.
130
- * @returns {ZodLiteral<ZodResolve<T>>} The literal schema.
131
- */
132
- literal(value) {
133
- return z.literal(value);
134
- }
135
- /**
136
- * Create an enum schema.
137
- * @param {Record<string, LiteralSchema>} schemaEnum - The enum schema.
138
- * @returns {ZodUnion<UnionZodResolve<[T, T, ...T[]]>>} The enum schema.
139
- */
140
- enum_(schemaEnum) {
141
- return this.union(Object.values(schemaEnum));
142
- }
143
- /**
144
- * Checks if a value is a Zod schema.
145
- * @param {unknown} value - The value to check.
146
- * @returns {boolean} True if the value is a Zod schema.
147
- */
148
- isSchema(value) {
149
- return value instanceof ZodType;
150
- }
151
- /**
152
- * Validate a value against a schema.
153
- * @param {ZodCatchall} schema - The schema to validate against.
154
- * @param {unknown} value - The value to validate.
155
- * @returns {boolean} True if valid, otherwise false.
156
- */
157
- validate(schema, value) {
158
- return schema.safeParse(value).success;
159
- }
160
- /**
161
- * Parses a value to a schema validation.
162
- *
163
- * @param {ZodCatchall} schema - The schema to validate against.
164
- * @param {unknown} value - The value to validate.
165
- * @returns {ParseResult} - The discrimintated parsed value if successful, the error if unsuccessful.
166
- */
167
- parse(schema, value) {
168
- try {
169
- const result = schema.safeParse(value);
170
- return result.success
171
- ? { ok: true, value: result.data }
172
- : {
173
- ok: false,
174
- error: this.prettyPrintZodErrors(result.error)
175
- };
176
- }
177
- catch (error) {
178
- return {
179
- ok: false,
180
- error: `Unexpected zod safeParse error: ${error.message}`
181
- };
182
- }
183
- }
184
- /**
185
- * Convert a schema to an OpenAPI schema object.
186
- * @param {ZodIdiomaticSchema} schema - The schema to convert.
187
- * @returns {SchemaObject} The OpenAPI schema object.
188
- */
189
- openapi(schema) {
190
- return generateSchema(this.schemify(schema));
191
- }
192
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=advancedParse.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"advancedParse.test.d.ts","sourceRoot":"","sources":["../../../tests/typebox/advancedParse.test.ts"],"names":[],"mappings":""}