@composio/json-schema-to-zod 0.1.19 → 0.2.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.
- package/dist/index.d.mts +185 -0
- package/dist/index.mjs +628 -0
- package/package.json +29 -15
- package/dist/index.cjs +0 -830
- package/dist/index.d.cts +0 -27
- package/dist/index.d.ts +0 -27
- package/dist/index.js +0 -793
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ZodTypeAny, z } from "zod/v3";
|
|
2
|
+
|
|
3
|
+
//#region ../../../node_modules/.pnpm/@types+json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts
|
|
4
|
+
// ==================================================================================================
|
|
5
|
+
// JSON Schema Draft 07
|
|
6
|
+
// ==================================================================================================
|
|
7
|
+
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
8
|
+
// --------------------------------------------------------------------------------------------------
|
|
9
|
+
/**
|
|
10
|
+
* Primitive type
|
|
11
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
12
|
+
*/
|
|
13
|
+
type JSONSchema7TypeName = "string" //
|
|
14
|
+
| "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
15
|
+
/**
|
|
16
|
+
* Primitive type
|
|
17
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
|
18
|
+
*/
|
|
19
|
+
type JSONSchema7Type = string //
|
|
20
|
+
| number | boolean | JSONSchema7Object | JSONSchema7Array | null;
|
|
21
|
+
// Workaround for infinite type recursion
|
|
22
|
+
interface JSONSchema7Object {
|
|
23
|
+
[key: string]: JSONSchema7Type;
|
|
24
|
+
}
|
|
25
|
+
// Workaround for infinite type recursion
|
|
26
|
+
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
|
27
|
+
interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
|
28
|
+
/**
|
|
29
|
+
* Meta schema
|
|
30
|
+
*
|
|
31
|
+
* Recommended values:
|
|
32
|
+
* - 'http://json-schema.org/schema#'
|
|
33
|
+
* - 'http://json-schema.org/hyper-schema#'
|
|
34
|
+
* - 'http://json-schema.org/draft-07/schema#'
|
|
35
|
+
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
|
36
|
+
*
|
|
37
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
|
38
|
+
*/
|
|
39
|
+
type JSONSchema7Version = string;
|
|
40
|
+
/**
|
|
41
|
+
* JSON Schema v7
|
|
42
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
|
43
|
+
*/
|
|
44
|
+
type JSONSchema7Definition = JSONSchema7 | boolean;
|
|
45
|
+
interface JSONSchema7 {
|
|
46
|
+
$id?: string | undefined;
|
|
47
|
+
$ref?: string | undefined;
|
|
48
|
+
$schema?: JSONSchema7Version | undefined;
|
|
49
|
+
$comment?: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
|
52
|
+
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
|
53
|
+
*/
|
|
54
|
+
$defs?: {
|
|
55
|
+
[key: string]: JSONSchema7Definition;
|
|
56
|
+
} | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
|
59
|
+
*/
|
|
60
|
+
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
|
61
|
+
enum?: JSONSchema7Type[] | undefined;
|
|
62
|
+
const?: JSONSchema7Type | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
|
65
|
+
*/
|
|
66
|
+
multipleOf?: number | undefined;
|
|
67
|
+
maximum?: number | undefined;
|
|
68
|
+
exclusiveMaximum?: number | undefined;
|
|
69
|
+
minimum?: number | undefined;
|
|
70
|
+
exclusiveMinimum?: number | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
|
73
|
+
*/
|
|
74
|
+
maxLength?: number | undefined;
|
|
75
|
+
minLength?: number | undefined;
|
|
76
|
+
pattern?: string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
|
79
|
+
*/
|
|
80
|
+
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
|
81
|
+
additionalItems?: JSONSchema7Definition | undefined;
|
|
82
|
+
maxItems?: number | undefined;
|
|
83
|
+
minItems?: number | undefined;
|
|
84
|
+
uniqueItems?: boolean | undefined;
|
|
85
|
+
contains?: JSONSchema7Definition | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
|
88
|
+
*/
|
|
89
|
+
maxProperties?: number | undefined;
|
|
90
|
+
minProperties?: number | undefined;
|
|
91
|
+
required?: string[] | undefined;
|
|
92
|
+
properties?: {
|
|
93
|
+
[key: string]: JSONSchema7Definition;
|
|
94
|
+
} | undefined;
|
|
95
|
+
patternProperties?: {
|
|
96
|
+
[key: string]: JSONSchema7Definition;
|
|
97
|
+
} | undefined;
|
|
98
|
+
additionalProperties?: JSONSchema7Definition | undefined;
|
|
99
|
+
dependencies?: {
|
|
100
|
+
[key: string]: JSONSchema7Definition | string[];
|
|
101
|
+
} | undefined;
|
|
102
|
+
propertyNames?: JSONSchema7Definition | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
|
105
|
+
*/
|
|
106
|
+
if?: JSONSchema7Definition | undefined;
|
|
107
|
+
then?: JSONSchema7Definition | undefined;
|
|
108
|
+
else?: JSONSchema7Definition | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
|
111
|
+
*/
|
|
112
|
+
allOf?: JSONSchema7Definition[] | undefined;
|
|
113
|
+
anyOf?: JSONSchema7Definition[] | undefined;
|
|
114
|
+
oneOf?: JSONSchema7Definition[] | undefined;
|
|
115
|
+
not?: JSONSchema7Definition | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
|
118
|
+
*/
|
|
119
|
+
format?: string | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
|
122
|
+
*/
|
|
123
|
+
contentMediaType?: string | undefined;
|
|
124
|
+
contentEncoding?: string | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
|
127
|
+
*/
|
|
128
|
+
definitions?: {
|
|
129
|
+
[key: string]: JSONSchema7Definition;
|
|
130
|
+
} | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
|
133
|
+
*/
|
|
134
|
+
title?: string | undefined;
|
|
135
|
+
description?: string | undefined;
|
|
136
|
+
default?: JSONSchema7Type | undefined;
|
|
137
|
+
readOnly?: boolean | undefined;
|
|
138
|
+
writeOnly?: boolean | undefined;
|
|
139
|
+
examples?: JSONSchema7Type | undefined;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/types.d.ts
|
|
143
|
+
type Serializable = {
|
|
144
|
+
[key: string]: Serializable;
|
|
145
|
+
} | Serializable[] | string | number | boolean | null;
|
|
146
|
+
type JsonSchema = JsonSchemaObject | boolean;
|
|
147
|
+
type JsonSchemaObject = JSONSchema7;
|
|
148
|
+
type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny;
|
|
149
|
+
type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny | undefined;
|
|
150
|
+
type JsonSchemaToZodOptions = {
|
|
151
|
+
withoutDefaults?: boolean;
|
|
152
|
+
withoutDescribes?: boolean;
|
|
153
|
+
parserOverride?: ParserOverride;
|
|
154
|
+
depth?: number;
|
|
155
|
+
};
|
|
156
|
+
type Refs = JsonSchemaToZodOptions & {
|
|
157
|
+
path: Array<string | number>;
|
|
158
|
+
seen: Map<object | boolean, {
|
|
159
|
+
n: number;
|
|
160
|
+
r: ZodTypeAny | undefined;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/json-schema-to-zod.d.ts
|
|
165
|
+
declare const jsonSchemaToZod: (schema: JsonSchema, options?: JsonSchemaToZodOptions) => z.ZodType;
|
|
166
|
+
/**
|
|
167
|
+
* A simplified type for Zod raw shapes that avoids deep type instantiation issues.
|
|
168
|
+
* This is compatible with ZodRawShape but uses a simpler type signature.
|
|
169
|
+
*/
|
|
170
|
+
type SimpleZodRawShape = Record<string, ZodTypeAny>;
|
|
171
|
+
/**
|
|
172
|
+
* Converts a JSON Schema object to a Zod raw shape.
|
|
173
|
+
* This is useful when you need the shape object (e.g., `{ name: z.string(), age: z.number() }`)
|
|
174
|
+
* rather than a complete ZodObject schema.
|
|
175
|
+
*
|
|
176
|
+
* This is particularly useful for APIs that expect ZodRawShape instead of ZodType,
|
|
177
|
+
* such as the Claude Agent SDK's `tool()` function.
|
|
178
|
+
*
|
|
179
|
+
* @param schema - The JSON Schema to convert (must be an object schema)
|
|
180
|
+
* @param options - Optional configuration for the conversion
|
|
181
|
+
* @returns A Zod raw shape object with property keys mapped to Zod types
|
|
182
|
+
*/
|
|
183
|
+
declare const jsonSchemaToZodShape: (schema: JsonSchema, options?: JsonSchemaToZodOptions) => SimpleZodRawShape;
|
|
184
|
+
//#endregion
|
|
185
|
+
export { type JsonSchema, type JsonSchemaObject, type JsonSchemaToZodOptions, type ParserOverride, type ParserSelector, type Refs, type Serializable, jsonSchemaToZod, jsonSchemaToZodShape };
|