@atom8n/json-schema-to-zod 1.6.8 → 1.7.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 (76) hide show
  1. package/.turbo/turbo-build.log +2 -8
  2. package/dist/cjs/index.js +5 -0
  3. package/dist/cjs/json-schema-to-zod.js +12 -0
  4. package/dist/cjs/package.json +1 -0
  5. package/dist/cjs/parsers/parse-all-of.js +37 -0
  6. package/dist/cjs/parsers/parse-any-of.js +16 -0
  7. package/dist/cjs/parsers/parse-array.js +18 -0
  8. package/dist/cjs/parsers/parse-boolean.js +8 -0
  9. package/dist/cjs/parsers/parse-const.js +8 -0
  10. package/dist/cjs/parsers/parse-default.js +8 -0
  11. package/dist/cjs/parsers/parse-enum.js +18 -0
  12. package/dist/cjs/parsers/parse-if-then-else.js +23 -0
  13. package/dist/cjs/parsers/parse-multiple-type.js +9 -0
  14. package/dist/cjs/parsers/parse-not.js +12 -0
  15. package/dist/cjs/parsers/parse-null.js +8 -0
  16. package/dist/cjs/parsers/parse-nullable.js +12 -0
  17. package/dist/cjs/parsers/parse-number.js +49 -0
  18. package/dist/cjs/parsers/parse-object.js +206 -0
  19. package/dist/cjs/parsers/parse-one-of.js +32 -0
  20. package/dist/cjs/parsers/parse-schema.js +159 -0
  21. package/dist/cjs/parsers/parse-string.js +42 -0
  22. package/dist/cjs/types.js +2 -0
  23. package/dist/cjs/utils/extend-schema.js +11 -0
  24. package/dist/cjs/utils/half.js +7 -0
  25. package/dist/cjs/utils/its.js +23 -0
  26. package/dist/cjs/utils/omit.js +10 -0
  27. package/dist/esm/index.js +1 -0
  28. package/dist/esm/json-schema-to-zod.js +8 -0
  29. package/dist/esm/package.json +1 -0
  30. package/dist/esm/parsers/parse-all-of.js +34 -0
  31. package/dist/esm/parsers/parse-any-of.js +12 -0
  32. package/dist/esm/parsers/parse-array.js +14 -0
  33. package/dist/esm/parsers/parse-boolean.js +4 -0
  34. package/dist/esm/parsers/parse-const.js +4 -0
  35. package/dist/esm/parsers/parse-default.js +4 -0
  36. package/dist/esm/parsers/parse-enum.js +14 -0
  37. package/dist/esm/parsers/parse-if-then-else.js +19 -0
  38. package/dist/esm/parsers/parse-multiple-type.js +5 -0
  39. package/dist/esm/parsers/parse-not.js +8 -0
  40. package/dist/esm/parsers/parse-null.js +4 -0
  41. package/dist/esm/parsers/parse-nullable.js +8 -0
  42. package/dist/esm/parsers/parse-number.js +45 -0
  43. package/dist/esm/parsers/parse-object.js +170 -0
  44. package/dist/esm/parsers/parse-one-of.js +28 -0
  45. package/dist/esm/parsers/parse-schema.js +122 -0
  46. package/dist/esm/parsers/parse-string.js +38 -0
  47. package/dist/esm/types.js +1 -0
  48. package/dist/esm/utils/extend-schema.js +8 -0
  49. package/dist/esm/utils/half.js +3 -0
  50. package/dist/esm/utils/its.js +20 -0
  51. package/dist/esm/utils/omit.js +6 -0
  52. package/dist/types/index.d.ts +2 -0
  53. package/dist/types/json-schema-to-zod.d.ts +3 -0
  54. package/dist/types/parsers/parse-all-of.d.ts +5 -0
  55. package/dist/types/parsers/parse-any-of.d.ts +5 -0
  56. package/dist/types/parsers/parse-array.d.ts +5 -0
  57. package/dist/types/parsers/parse-boolean.d.ts +5 -0
  58. package/dist/types/parsers/parse-const.d.ts +5 -0
  59. package/dist/types/parsers/parse-default.d.ts +3 -0
  60. package/dist/types/parsers/parse-enum.d.ts +5 -0
  61. package/dist/types/parsers/parse-if-then-else.d.ts +7 -0
  62. package/dist/types/parsers/parse-multiple-type.d.ts +5 -0
  63. package/dist/types/parsers/parse-not.d.ts +5 -0
  64. package/dist/types/parsers/parse-null.d.ts +5 -0
  65. package/dist/types/parsers/parse-nullable.d.ts +7 -0
  66. package/dist/types/parsers/parse-number.d.ts +5 -0
  67. package/dist/types/parsers/parse-object.d.ts +5 -0
  68. package/dist/types/parsers/parse-one-of.d.ts +5 -0
  69. package/dist/types/parsers/parse-schema.d.ts +3 -0
  70. package/dist/types/parsers/parse-string.d.ts +5 -0
  71. package/dist/types/types.d.ts +66 -0
  72. package/dist/types/utils/extend-schema.d.ts +3 -0
  73. package/dist/types/utils/half.d.ts +1 -0
  74. package/dist/types/utils/its.d.ts +45 -0
  75. package/dist/types/utils/omit.d.ts +1 -0
  76. package/package.json +3 -3
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { parseSchema } from './parse-schema';
3
+ export const parseOneOf = (jsonSchema, refs) => {
4
+ if (!jsonSchema.oneOf.length) {
5
+ return z.any();
6
+ }
7
+ if (jsonSchema.oneOf.length === 1) {
8
+ return parseSchema(jsonSchema.oneOf[0], {
9
+ ...refs,
10
+ path: [...refs.path, 'oneOf', 0],
11
+ });
12
+ }
13
+ return z.any().superRefine((x, ctx) => {
14
+ const schemas = jsonSchema.oneOf.map((schema, i) => parseSchema(schema, {
15
+ ...refs,
16
+ path: [...refs.path, 'oneOf', i],
17
+ }));
18
+ const unionErrors = schemas.reduce((errors, schema) => ((result) => (result.error ? [...errors, result.error] : errors))(schema.safeParse(x)), []);
19
+ if (schemas.length - unionErrors.length !== 1) {
20
+ ctx.addIssue({
21
+ path: ctx.path,
22
+ code: 'invalid_union',
23
+ unionErrors,
24
+ message: 'Invalid input: Should pass single schema',
25
+ });
26
+ }
27
+ });
28
+ };
@@ -0,0 +1,122 @@
1
+ import * as z from 'zod';
2
+ import { parseAllOf } from './parse-all-of';
3
+ import { parseAnyOf } from './parse-any-of';
4
+ import { parseArray } from './parse-array';
5
+ import { parseBoolean } from './parse-boolean';
6
+ import { parseConst } from './parse-const';
7
+ import { parseDefault } from './parse-default';
8
+ import { parseEnum } from './parse-enum';
9
+ import { parseIfThenElse } from './parse-if-then-else';
10
+ import { parseMultipleType } from './parse-multiple-type';
11
+ import { parseNot } from './parse-not';
12
+ import { parseNull } from './parse-null';
13
+ import { parseNullable } from './parse-nullable';
14
+ import { parseNumber } from './parse-number';
15
+ import { parseObject } from './parse-object';
16
+ import { parseOneOf } from './parse-one-of';
17
+ import { parseString } from './parse-string';
18
+ import { its } from '../utils/its';
19
+ const addDescribes = (jsonSchema, zodSchema) => {
20
+ if (jsonSchema.description) {
21
+ zodSchema = zodSchema.describe(jsonSchema.description);
22
+ }
23
+ return zodSchema;
24
+ };
25
+ const addDefaults = (jsonSchema, zodSchema) => {
26
+ if (jsonSchema.default !== undefined) {
27
+ zodSchema = zodSchema.default(jsonSchema.default);
28
+ }
29
+ return zodSchema;
30
+ };
31
+ const addAnnotations = (jsonSchema, zodSchema) => {
32
+ if (jsonSchema.readOnly) {
33
+ zodSchema = zodSchema.readonly();
34
+ }
35
+ return zodSchema;
36
+ };
37
+ const selectParser = (schema, refs) => {
38
+ if (its.a.nullable(schema)) {
39
+ return parseNullable(schema, refs);
40
+ }
41
+ else if (its.an.object(schema)) {
42
+ return parseObject(schema, refs);
43
+ }
44
+ else if (its.an.array(schema)) {
45
+ return parseArray(schema, refs);
46
+ }
47
+ else if (its.an.anyOf(schema)) {
48
+ return parseAnyOf(schema, refs);
49
+ }
50
+ else if (its.an.allOf(schema)) {
51
+ return parseAllOf(schema, refs);
52
+ }
53
+ else if (its.a.oneOf(schema)) {
54
+ return parseOneOf(schema, refs);
55
+ }
56
+ else if (its.a.not(schema)) {
57
+ return parseNot(schema, refs);
58
+ }
59
+ else if (its.an.enum(schema)) {
60
+ return parseEnum(schema); //<-- needs to come before primitives
61
+ }
62
+ else if (its.a.const(schema)) {
63
+ return parseConst(schema);
64
+ }
65
+ else if (its.a.multipleType(schema)) {
66
+ return parseMultipleType(schema, refs);
67
+ }
68
+ else if (its.a.primitive(schema, 'string')) {
69
+ return parseString(schema);
70
+ }
71
+ else if (its.a.primitive(schema, 'number') || its.a.primitive(schema, 'integer')) {
72
+ return parseNumber(schema);
73
+ }
74
+ else if (its.a.primitive(schema, 'boolean')) {
75
+ return parseBoolean(schema);
76
+ }
77
+ else if (its.a.primitive(schema, 'null')) {
78
+ return parseNull(schema);
79
+ }
80
+ else if (its.a.conditional(schema)) {
81
+ return parseIfThenElse(schema, refs);
82
+ }
83
+ else {
84
+ return parseDefault(schema);
85
+ }
86
+ };
87
+ export const parseSchema = (jsonSchema, refs = { seen: new Map(), path: [] }, blockMeta) => {
88
+ if (typeof jsonSchema !== 'object')
89
+ return jsonSchema ? z.any() : z.never();
90
+ if (refs.parserOverride) {
91
+ const custom = refs.parserOverride(jsonSchema, refs);
92
+ if (custom instanceof z.ZodType) {
93
+ return custom;
94
+ }
95
+ }
96
+ let seen = refs.seen.get(jsonSchema);
97
+ if (seen) {
98
+ if (seen.r !== undefined) {
99
+ return seen.r;
100
+ }
101
+ if (refs.depth === undefined || seen.n >= refs.depth) {
102
+ return z.any();
103
+ }
104
+ seen.n += 1;
105
+ }
106
+ else {
107
+ seen = { r: undefined, n: 0 };
108
+ refs.seen.set(jsonSchema, seen);
109
+ }
110
+ let parsedZodSchema = selectParser(jsonSchema, refs);
111
+ if (!blockMeta) {
112
+ if (!refs.withoutDescribes) {
113
+ parsedZodSchema = addDescribes(jsonSchema, parsedZodSchema);
114
+ }
115
+ if (!refs.withoutDefaults) {
116
+ parsedZodSchema = addDefaults(jsonSchema, parsedZodSchema);
117
+ }
118
+ parsedZodSchema = addAnnotations(jsonSchema, parsedZodSchema);
119
+ }
120
+ seen.r = parsedZodSchema;
121
+ return parsedZodSchema;
122
+ };
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+ import { extendSchemaWithMessage } from '../utils/extend-schema';
3
+ export const parseString = (jsonSchema) => {
4
+ let zodSchema = z.string();
5
+ zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'format', (zs, format, errorMsg) => {
6
+ switch (format) {
7
+ case 'email':
8
+ return zs.email(errorMsg);
9
+ case 'ip':
10
+ return zs.ip(errorMsg);
11
+ case 'ipv4':
12
+ return zs.ip({ version: 'v4', message: errorMsg });
13
+ case 'ipv6':
14
+ return zs.ip({ version: 'v6', message: errorMsg });
15
+ case 'uri':
16
+ return zs.url(errorMsg);
17
+ case 'uuid':
18
+ return zs.uuid(errorMsg);
19
+ case 'date-time':
20
+ return zs.datetime({ offset: true, message: errorMsg });
21
+ case 'time':
22
+ return zs.time(errorMsg);
23
+ case 'date':
24
+ return zs.date(errorMsg);
25
+ case 'binary':
26
+ return zs.base64(errorMsg);
27
+ case 'duration':
28
+ return zs.duration(errorMsg);
29
+ default:
30
+ return zs;
31
+ }
32
+ });
33
+ zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'contentEncoding', (zs, _, errorMsg) => zs.base64(errorMsg));
34
+ zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'pattern', (zs, pattern, errorMsg) => zs.regex(new RegExp(pattern), errorMsg));
35
+ zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'minLength', (zs, minLength, errorMsg) => zs.min(minLength, errorMsg));
36
+ zodSchema = extendSchemaWithMessage(zodSchema, jsonSchema, 'maxLength', (zs, maxLength, errorMsg) => zs.max(maxLength, errorMsg));
37
+ return zodSchema;
38
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export function extendSchemaWithMessage(zodSchema, jsonSchema, key, extend) {
2
+ const value = jsonSchema[key];
3
+ if (value !== undefined) {
4
+ const errorMessage = jsonSchema.errorMessage?.[key];
5
+ return extend(zodSchema, value, errorMessage);
6
+ }
7
+ return zodSchema;
8
+ }
@@ -0,0 +1,3 @@
1
+ export const half = (arr) => {
2
+ return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
3
+ };
@@ -0,0 +1,20 @@
1
+ export const its = {
2
+ an: {
3
+ object: (x) => x.type === 'object',
4
+ array: (x) => x.type === 'array',
5
+ anyOf: (x) => x.anyOf !== undefined,
6
+ allOf: (x) => x.allOf !== undefined,
7
+ enum: (x) => x.enum !== undefined,
8
+ },
9
+ a: {
10
+ nullable: (x) =>
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
12
+ x.nullable === true,
13
+ multipleType: (x) => Array.isArray(x.type),
14
+ not: (x) => x.not !== undefined,
15
+ const: (x) => x.const !== undefined,
16
+ primitive: (x, p) => x.type === p,
17
+ conditional: (x) => Boolean('if' in x && x.if && 'then' in x && 'else' in x && x.then && x.else),
18
+ oneOf: (x) => x.oneOf !== undefined,
19
+ },
20
+ };
@@ -0,0 +1,6 @@
1
+ export const omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
2
+ if (!keys.includes(key)) {
3
+ acc[key] = obj[key];
4
+ }
5
+ return acc;
6
+ }, {});
@@ -0,0 +1,2 @@
1
+ export type * from './types';
2
+ export { jsonSchemaToZod } from './json-schema-to-zod';
@@ -0,0 +1,3 @@
1
+ import type { z } from 'zod';
2
+ import type { JsonSchemaToZodOptions, JsonSchema } from './types';
3
+ export declare const jsonSchemaToZod: <T extends z.ZodTypeAny = z.ZodTypeAny>(schema: JsonSchema, options?: JsonSchemaToZodOptions) => T;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, JsonSchema, Refs } from '../types';
3
+ export declare function parseAllOf(jsonSchema: JsonSchemaObject & {
4
+ allOf: JsonSchema[];
5
+ }, refs: Refs): z.ZodTypeAny;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, JsonSchema, Refs } from '../types';
3
+ export declare const parseAnyOf: (jsonSchema: JsonSchemaObject & {
4
+ anyOf: JsonSchema[];
5
+ }, refs: Refs) => z.ZodTypeAny;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, Refs } from '../types';
3
+ export declare const parseArray: (jsonSchema: JsonSchemaObject & {
4
+ type: "array";
5
+ }, refs: Refs) => z.ZodArray<z.ZodTypeAny, "many"> | z.ZodTuple<[z.ZodTypeAny], null>;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject } from '../types';
3
+ export declare const parseBoolean: (_jsonSchema: JsonSchemaObject & {
4
+ type: "boolean";
5
+ }) => z.ZodBoolean;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, Serializable } from '../types';
3
+ export declare const parseConst: (jsonSchema: JsonSchemaObject & {
4
+ const: Serializable;
5
+ }) => z.ZodLiteral<z.Primitive>;
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject } from '../types';
3
+ export declare const parseDefault: (_jsonSchema: JsonSchemaObject) => z.ZodAny;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, Serializable } from '../types';
3
+ export declare const parseEnum: (jsonSchema: JsonSchemaObject & {
4
+ enum: Serializable[];
5
+ }) => z.ZodNever | z.ZodUnion<[z.ZodTypeAny, z.ZodTypeAny]> | z.ZodLiteral<z.Primitive> | z.ZodEnum<[string]>;
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, JsonSchema, Refs } from '../types';
3
+ export declare const parseIfThenElse: (jsonSchema: JsonSchemaObject & {
4
+ if: JsonSchema;
5
+ then: JsonSchema;
6
+ else: JsonSchema;
7
+ }, refs: Refs) => z.ZodEffects<z.ZodUnion<[z.ZodTypeAny, z.ZodTypeAny]>, any, any>;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, Refs } from '../types';
3
+ export declare const parseMultipleType: (jsonSchema: JsonSchemaObject & {
4
+ type: string[];
5
+ }, refs: Refs) => z.ZodUnion<[z.ZodTypeAny, z.ZodTypeAny]>;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, JsonSchema, Refs } from '../types';
3
+ export declare const parseNot: (jsonSchema: JsonSchemaObject & {
4
+ not: JsonSchema;
5
+ }, refs: Refs) => z.ZodEffects<z.ZodAny, any, any>;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject } from '../types';
3
+ export declare const parseNull: (_jsonSchema: JsonSchemaObject & {
4
+ type: "null";
5
+ }) => z.ZodNull;
@@ -0,0 +1,7 @@
1
+ import type { JsonSchemaObject, Refs } from '../types';
2
+ /**
3
+ * For compatibility with open api 3.0 nullable
4
+ */
5
+ export declare const parseNullable: (jsonSchema: JsonSchemaObject & {
6
+ nullable: true;
7
+ }, refs: Refs) => import("zod").ZodNullable<import("zod").ZodTypeAny>;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject } from '../types';
3
+ export declare const parseNumber: (jsonSchema: JsonSchemaObject & {
4
+ type: "number" | "integer";
5
+ }) => z.ZodNumber;
@@ -0,0 +1,5 @@
1
+ import * as z from 'zod';
2
+ import type { JsonSchemaObject, Refs } from '../types';
3
+ export declare function parseObject(objectSchema: JsonSchemaObject & {
4
+ type: 'object';
5
+ }, refs: Refs): z.ZodTypeAny;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject, JsonSchema, Refs } from '../types';
3
+ export declare const parseOneOf: (jsonSchema: JsonSchemaObject & {
4
+ oneOf: JsonSchema[];
5
+ }, refs: Refs) => z.ZodTypeAny;
@@ -0,0 +1,3 @@
1
+ import * as z from 'zod';
2
+ import type { Refs, JsonSchema } from '../types';
3
+ export declare const parseSchema: (jsonSchema: JsonSchema, refs?: Refs, blockMeta?: boolean) => z.ZodTypeAny;
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ import type { JsonSchemaObject } from '../types';
3
+ export declare const parseString: (jsonSchema: JsonSchemaObject & {
4
+ type: "string";
5
+ }) => z.ZodString;
@@ -0,0 +1,66 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ export type Serializable = {
3
+ [key: string]: Serializable;
4
+ } | Serializable[] | string | number | boolean | null;
5
+ export type JsonSchema = JsonSchemaObject | boolean;
6
+ export type JsonSchemaObject = {
7
+ type?: string | string[];
8
+ properties?: {
9
+ [key: string]: JsonSchema;
10
+ };
11
+ additionalProperties?: JsonSchema;
12
+ unevaluatedProperties?: JsonSchema;
13
+ patternProperties?: {
14
+ [key: string]: JsonSchema;
15
+ };
16
+ minProperties?: number;
17
+ maxProperties?: number;
18
+ required?: string[] | boolean;
19
+ propertyNames?: JsonSchema;
20
+ items?: JsonSchema | JsonSchema[];
21
+ additionalItems?: JsonSchema;
22
+ minItems?: number;
23
+ maxItems?: number;
24
+ uniqueItems?: boolean;
25
+ minLength?: number;
26
+ maxLength?: number;
27
+ pattern?: string;
28
+ format?: string;
29
+ minimum?: number;
30
+ maximum?: number;
31
+ exclusiveMinimum?: number | boolean;
32
+ exclusiveMaximum?: number | boolean;
33
+ multipleOf?: number;
34
+ anyOf?: JsonSchema[];
35
+ allOf?: JsonSchema[];
36
+ oneOf?: JsonSchema[];
37
+ if?: JsonSchema;
38
+ then?: JsonSchema;
39
+ else?: JsonSchema;
40
+ const?: Serializable;
41
+ enum?: Serializable[];
42
+ errorMessage?: {
43
+ [key: string]: string | undefined;
44
+ };
45
+ description?: string;
46
+ default?: Serializable;
47
+ readOnly?: boolean;
48
+ not?: JsonSchema;
49
+ contentEncoding?: string;
50
+ nullable?: boolean;
51
+ };
52
+ export type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny;
53
+ export type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny | undefined;
54
+ export type JsonSchemaToZodOptions = {
55
+ withoutDefaults?: boolean;
56
+ withoutDescribes?: boolean;
57
+ parserOverride?: ParserOverride;
58
+ depth?: number;
59
+ };
60
+ export type Refs = JsonSchemaToZodOptions & {
61
+ path: Array<string | number>;
62
+ seen: Map<object | boolean, {
63
+ n: number;
64
+ r: ZodTypeAny | undefined;
65
+ }>;
66
+ };
@@ -0,0 +1,3 @@
1
+ import type { z } from 'zod';
2
+ import type { JsonSchemaObject } from '../types';
3
+ export declare function extendSchemaWithMessage<TZod extends z.ZodTypeAny, TJson extends JsonSchemaObject, TKey extends keyof TJson>(zodSchema: TZod, jsonSchema: TJson, key: TKey, extend: (zodSchema: TZod, value: NonNullable<TJson[TKey]>, errorMessage?: string) => TZod): TZod;
@@ -0,0 +1 @@
1
+ export declare const half: <T>(arr: T[]) => [T[], T[]];
@@ -0,0 +1,45 @@
1
+ import type { JsonSchema, JsonSchemaObject, Serializable } from '../types';
2
+ export declare const its: {
3
+ an: {
4
+ object: (x: JsonSchemaObject) => x is JsonSchemaObject & {
5
+ type: "object";
6
+ };
7
+ array: (x: JsonSchemaObject) => x is JsonSchemaObject & {
8
+ type: "array";
9
+ };
10
+ anyOf: (x: JsonSchemaObject) => x is JsonSchemaObject & {
11
+ anyOf: JsonSchema[];
12
+ };
13
+ allOf: (x: JsonSchemaObject) => x is JsonSchemaObject & {
14
+ allOf: JsonSchema[];
15
+ };
16
+ enum: (x: JsonSchemaObject) => x is JsonSchemaObject & {
17
+ enum: Serializable | Serializable[];
18
+ };
19
+ };
20
+ a: {
21
+ nullable: (x: JsonSchemaObject) => x is JsonSchemaObject & {
22
+ nullable: true;
23
+ };
24
+ multipleType: (x: JsonSchemaObject) => x is JsonSchemaObject & {
25
+ type: string[];
26
+ };
27
+ not: (x: JsonSchemaObject) => x is JsonSchemaObject & {
28
+ not: JsonSchema;
29
+ };
30
+ const: (x: JsonSchemaObject) => x is JsonSchemaObject & {
31
+ const: Serializable;
32
+ };
33
+ primitive: <T extends "string" | "number" | "integer" | "boolean" | "null">(x: JsonSchemaObject, p: T) => x is JsonSchemaObject & {
34
+ type: T;
35
+ };
36
+ conditional: (x: JsonSchemaObject) => x is JsonSchemaObject & {
37
+ if: JsonSchema;
38
+ then: JsonSchema;
39
+ else: JsonSchema;
40
+ };
41
+ oneOf: (x: JsonSchemaObject) => x is JsonSchemaObject & {
42
+ oneOf: JsonSchema[];
43
+ };
44
+ };
45
+ };
@@ -0,0 +1 @@
1
+ export declare const omit: <T extends object, K extends keyof T>(obj: T, ...keys: K[]) => Omit<T, K>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atom8n/json-schema-to-zod",
3
- "version": "1.6.8",
3
+ "version": "1.7.0",
4
4
  "description": "Converts JSON schema objects into Zod schemas",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "main": "./dist/cjs/index.js",
@@ -26,7 +26,7 @@
26
26
  "build:types": "tsc -p tsconfig.types.json",
27
27
  "build:cjs": "tsc -p tsconfig.cjs.json && node postcjs.cjs",
28
28
  "build:esm": "tsc -p tsconfig.esm.json && node postesm.cjs",
29
- "build": "rimraf ./dist && pnpm run build:types && pnpm run build:cjs && pnpm run build:esm",
29
+ "build": "rimraf ./dist && tsc -p tsconfig.types.json && sleep 2 && tsc -p tsconfig.cjs.json && node postcjs.cjs && sleep 2 && tsc -p tsconfig.esm.json && node postesm.cjs",
30
30
  "dry": "pnpm run build && pnpm pub --dry-run",
31
31
  "test": "jest",
32
32
  "test:unit": "jest",
@@ -63,7 +63,7 @@
63
63
  "zod": "^3.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@n8n/typescript-config": "npm:@atom8n/typescript-config@1.3.8",
66
+ "@n8n/typescript-config": "npm:@atom8n/typescript-config@1.4.0",
67
67
  "@types/json-schema": "^7.0.15",
68
68
  "zod": "3.25.67"
69
69
  }