@composio/json-schema-to-zod 0.3.4 → 0.4.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.
- package/README.md +31 -3
- package/dist/compile-pattern-D-zr7Yui.d.mts +206 -0
- package/dist/convert-Cte4lEaK.mjs +1768 -0
- package/dist/index.d.mts +4 -209
- package/dist/index.mjs +103 -1731
- package/dist/v4.d.mts +14 -0
- package/dist/v4.mjs +246 -0
- package/package.json +16 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,192 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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 JsonSchemaDefinitions = Record<string, JsonSchema>;
|
|
148
|
-
interface JsonSchemaObject extends Omit<JSONSchema7, '$defs' | 'items' | 'additionalItems' | 'contains' | 'properties' | 'patternProperties' | 'additionalProperties' | 'dependencies' | 'propertyNames' | 'if' | 'then' | 'else' | 'allOf' | 'anyOf' | 'oneOf' | 'not' | 'definitions'> {
|
|
149
|
-
min?: number;
|
|
150
|
-
max?: number;
|
|
151
|
-
example?: Serializable;
|
|
152
|
-
$defs?: JsonSchemaDefinitions;
|
|
153
|
-
definitions?: JsonSchemaDefinitions;
|
|
154
|
-
items?: JsonSchema | JsonSchema[];
|
|
155
|
-
additionalItems?: JsonSchema;
|
|
156
|
-
contains?: JsonSchema;
|
|
157
|
-
properties?: JsonSchemaDefinitions;
|
|
158
|
-
patternProperties?: JsonSchemaDefinitions;
|
|
159
|
-
additionalProperties?: JsonSchema;
|
|
160
|
-
dependencies?: Record<string, JsonSchema | string[]>;
|
|
161
|
-
propertyNames?: JsonSchema;
|
|
162
|
-
if?: JsonSchema;
|
|
163
|
-
then?: JsonSchema;
|
|
164
|
-
else?: JsonSchema;
|
|
165
|
-
allOf?: JsonSchema[];
|
|
166
|
-
anyOf?: JsonSchema[];
|
|
167
|
-
oneOf?: JsonSchema[];
|
|
168
|
-
not?: JsonSchema;
|
|
169
|
-
}
|
|
170
|
-
type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny;
|
|
171
|
-
type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny | undefined;
|
|
172
|
-
type JsonSchemaToZodOptions = {
|
|
173
|
-
withoutDefaults?: boolean;
|
|
174
|
-
withoutDescribes?: boolean;
|
|
175
|
-
parserOverride?: ParserOverride;
|
|
176
|
-
depth?: number;
|
|
177
|
-
};
|
|
178
|
-
type Refs = JsonSchemaToZodOptions & {
|
|
179
|
-
path: Array<string | number>;
|
|
180
|
-
seen: Map<object | boolean, {
|
|
181
|
-
n: number;
|
|
182
|
-
r: ZodTypeAny | undefined;
|
|
183
|
-
}>;
|
|
184
|
-
/** The document that local `$ref` pointers resolve against. */
|
|
185
|
-
root?: JsonSchema;
|
|
186
|
-
};
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region src/json-schema-to-zod.d.ts
|
|
189
|
-
export declare const jsonSchemaToZod: (schema: JsonSchema, options?: JsonSchemaToZodOptions) => z.ZodType;
|
|
1
|
+
import { a as JsonSchemaToZodOptions, c as Refs, i as JsonSchemaObject, l as Serializable, n as InvalidPatternReason, o as ParserOverride, r as JsonSchema, s as ParserSelector, t as InvalidPatternError } from "./compile-pattern-D-zr7Yui.mjs";
|
|
2
|
+
import { ZodType, ZodTypeAny } from "zod/v3";
|
|
3
|
+
export declare const jsonSchemaToZod: (schema: JsonSchema, options?: JsonSchemaToZodOptions) => ZodType;
|
|
190
4
|
/**
|
|
191
5
|
* A simplified type for Zod raw shapes that avoids deep type instantiation issues.
|
|
192
6
|
* This is compatible with ZodRawShape but uses a simpler type signature.
|
|
@@ -205,23 +19,4 @@ type SimpleZodRawShape = Record<string, ZodTypeAny>;
|
|
|
205
19
|
* @returns A Zod raw shape object with property keys mapped to Zod types
|
|
206
20
|
*/
|
|
207
21
|
export declare const jsonSchemaToZodShape: (schema: JsonSchema, options?: JsonSchemaToZodOptions) => SimpleZodRawShape;
|
|
208
|
-
|
|
209
|
-
//#region src/utils/compile-pattern.d.ts
|
|
210
|
-
type InvalidPatternReason = 'syntax' | 'too-long' | 'unsupported';
|
|
211
|
-
/**
|
|
212
|
-
* Raised at conversion time when a schema `pattern` cannot be turned into a
|
|
213
|
-
* `RegExp`. Conversion fails eagerly, in line with how this package and
|
|
214
|
-
* `@composio/json-schema-to-effect-schema` treat other schema defects: a broken
|
|
215
|
-
* schema is the tool author's bug, so it surfaces once at construction rather
|
|
216
|
-
* than on every validation as if the caller's input were wrong.
|
|
217
|
-
*/
|
|
218
|
-
export declare class InvalidPatternError extends Error {
|
|
219
|
-
readonly keyword: 'pattern' | 'patternProperties';
|
|
220
|
-
readonly pattern: string;
|
|
221
|
-
readonly path: ReadonlyArray<string | number>;
|
|
222
|
-
readonly reason: InvalidPatternReason;
|
|
223
|
-
readonly name = "InvalidPatternError";
|
|
224
|
-
constructor(keyword: 'pattern' | 'patternProperties', pattern: string, path: ReadonlyArray<string | number>, reason: InvalidPatternReason, detail: string, options?: ErrorOptions);
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
export type { InvalidPatternReason, JsonSchema, JsonSchemaObject, JsonSchemaToZodOptions, ParserOverride, ParserSelector, Refs, Serializable };
|
|
22
|
+
export { InvalidPatternError, type InvalidPatternReason, type JsonSchema, type JsonSchemaObject, type JsonSchemaToZodOptions, type ParserOverride, type ParserSelector, type Refs, type Serializable };
|