@tambo-ai/react 0.66.1 → 0.67.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/context-helpers/current-interactables-context-helper.d.ts +2 -2
- package/dist/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/dist/context-helpers/current-interactables-context-helper.js +17 -23
- package/dist/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/dist/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/dist/hoc/with-tambo-interactable.js +0 -1
- package/dist/hoc/with-tambo-interactable.js.map +1 -1
- package/dist/hooks/use-component-state.d.ts +16 -1
- package/dist/hooks/use-component-state.d.ts.map +1 -1
- package/dist/hooks/use-component-state.js +72 -12
- package/dist/hooks/use-component-state.js.map +1 -1
- package/dist/hooks/use-component-state.test.js +42 -0
- package/dist/hooks/use-component-state.test.js.map +1 -1
- package/dist/hooks/use-current-message.d.ts +3 -0
- package/dist/hooks/use-current-message.d.ts.map +1 -1
- package/dist/hooks/use-current-message.js +6 -5
- package/dist/hooks/use-current-message.js.map +1 -1
- package/dist/hooks/use-current-message.test.js +5 -0
- package/dist/hooks/use-current-message.test.js.map +1 -1
- package/dist/model/component-metadata.d.ts +2 -2
- package/dist/model/component-metadata.d.ts.map +1 -1
- package/dist/model/component-metadata.js.map +1 -1
- package/dist/model/tambo-interactable.d.ts +6 -0
- package/dist/model/tambo-interactable.d.ts.map +1 -1
- package/dist/model/tambo-interactable.js.map +1 -1
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js +87 -87
- package/dist/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.d.ts +1 -0
- package/dist/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/dist/providers/tambo-interactable-provider.js +83 -47
- package/dist/providers/tambo-interactable-provider.js.map +1 -1
- package/dist/providers/tambo-interactable-provider.test.d.ts +2 -0
- package/dist/providers/tambo-interactable-provider.test.d.ts.map +1 -0
- package/dist/providers/tambo-interactable-provider.test.js +62 -0
- package/dist/providers/tambo-interactable-provider.test.js.map +1 -0
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js +8 -8
- package/dist/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/dist/providers/tambo-interactables-additional-context.test.js +10 -10
- package/dist/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/dist/providers/tambo-registry-provider.test.js +28 -18
- package/dist/providers/tambo-registry-provider.test.js.map +1 -1
- package/dist/providers/tambo-registry-schema-compat.test.js +57 -28
- package/dist/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/dist/providers/tambo-thread-provider.test.js +21 -19
- package/dist/providers/tambo-thread-provider.test.js.map +1 -1
- package/dist/schema/alias.d.ts +3 -0
- package/dist/schema/alias.d.ts.map +1 -0
- package/dist/schema/alias.js +6 -0
- package/dist/schema/alias.js.map +1 -0
- package/dist/schema/json-schema.js +29 -29
- package/dist/schema/json-schema.js.map +1 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +20 -9
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/schema.test.js +291 -3
- package/dist/schema/schema.test.js.map +1 -1
- package/dist/schema/standard-schema.js +8 -8
- package/dist/schema/standard-schema.js.map +1 -1
- package/dist/schema/validate.test.js +31 -31
- package/dist/schema/validate.test.js.map +1 -1
- package/dist/schema/zod.d.ts +1 -1
- package/dist/schema/zod.d.ts.map +1 -1
- package/dist/schema/zod.js +27 -26
- package/dist/schema/zod.js.map +1 -1
- package/dist/schema/zod.test.d.ts +2 -0
- package/dist/schema/zod.test.d.ts.map +1 -0
- package/dist/schema/zod.test.js +551 -0
- package/dist/schema/zod.test.js.map +1 -0
- package/dist/util/registry-validators.d.ts.map +1 -1
- package/dist/util/registry-validators.js +40 -0
- package/dist/util/registry-validators.js.map +1 -1
- package/dist/util/registry-validators.test.js +69 -0
- package/dist/util/registry-validators.test.js.map +1 -1
- package/dist/util/registry.d.ts +1 -5
- package/dist/util/registry.d.ts.map +1 -1
- package/dist/util/registry.js +1 -5
- package/dist/util/registry.js.map +1 -1
- package/dist/util/registry.test.js +80 -67
- package/dist/util/registry.test.js.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.d.ts +2 -2
- package/esm/context-helpers/current-interactables-context-helper.d.ts.map +1 -1
- package/esm/context-helpers/current-interactables-context-helper.js +17 -23
- package/esm/context-helpers/current-interactables-context-helper.js.map +1 -1
- package/esm/hoc/with-tambo-interactable.d.ts.map +1 -1
- package/esm/hoc/with-tambo-interactable.js +0 -1
- package/esm/hoc/with-tambo-interactable.js.map +1 -1
- package/esm/hooks/use-component-state.d.ts +16 -1
- package/esm/hooks/use-component-state.d.ts.map +1 -1
- package/esm/hooks/use-component-state.js +74 -14
- package/esm/hooks/use-component-state.js.map +1 -1
- package/esm/hooks/use-component-state.test.js +40 -1
- package/esm/hooks/use-component-state.test.js.map +1 -1
- package/esm/hooks/use-current-message.d.ts +3 -0
- package/esm/hooks/use-current-message.d.ts.map +1 -1
- package/esm/hooks/use-current-message.js +2 -1
- package/esm/hooks/use-current-message.js.map +1 -1
- package/esm/hooks/use-current-message.test.js +5 -0
- package/esm/hooks/use-current-message.test.js.map +1 -1
- package/esm/model/component-metadata.d.ts +2 -2
- package/esm/model/component-metadata.d.ts.map +1 -1
- package/esm/model/component-metadata.js.map +1 -1
- package/esm/model/tambo-interactable.d.ts +6 -0
- package/esm/model/tambo-interactable.d.ts.map +1 -1
- package/esm/model/tambo-interactable.js.map +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js +1 -1
- package/esm/providers/tambo-interactable-provider-partial-updates.test.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.d.ts +1 -0
- package/esm/providers/tambo-interactable-provider.d.ts.map +1 -1
- package/esm/providers/tambo-interactable-provider.js +55 -19
- package/esm/providers/tambo-interactable-provider.js.map +1 -1
- package/esm/providers/tambo-interactable-provider.test.d.ts +2 -0
- package/esm/providers/tambo-interactable-provider.test.d.ts.map +1 -0
- package/esm/providers/tambo-interactable-provider.test.js +57 -0
- package/esm/providers/tambo-interactable-provider.test.js.map +1 -0
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js +1 -1
- package/esm/providers/tambo-interactables-additional-context-edge-cases.test.js.map +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js +1 -1
- package/esm/providers/tambo-interactables-additional-context.test.js.map +1 -1
- package/esm/providers/tambo-registry-provider.test.js +16 -6
- package/esm/providers/tambo-registry-provider.test.js.map +1 -1
- package/esm/providers/tambo-registry-schema-compat.test.js +57 -28
- package/esm/providers/tambo-registry-schema-compat.test.js.map +1 -1
- package/esm/providers/tambo-thread-provider.test.js +8 -6
- package/esm/providers/tambo-thread-provider.test.js.map +1 -1
- package/esm/schema/alias.d.ts +3 -0
- package/esm/schema/alias.d.ts.map +1 -0
- package/esm/schema/alias.js +13 -0
- package/esm/schema/alias.js.map +1 -0
- package/esm/schema/json-schema.js +1 -1
- package/esm/schema/json-schema.js.map +1 -1
- package/esm/schema/schema.d.ts.map +1 -1
- package/esm/schema/schema.js +20 -9
- package/esm/schema/schema.js.map +1 -1
- package/esm/schema/schema.test.js +258 -3
- package/esm/schema/schema.test.js.map +1 -1
- package/esm/schema/standard-schema.js +1 -1
- package/esm/schema/standard-schema.js.map +1 -1
- package/esm/schema/validate.test.js +1 -1
- package/esm/schema/validate.test.js.map +1 -1
- package/esm/schema/zod.d.ts +1 -1
- package/esm/schema/zod.d.ts.map +1 -1
- package/esm/schema/zod.js +27 -26
- package/esm/schema/zod.js.map +1 -1
- package/esm/schema/zod.test.d.ts +2 -0
- package/esm/schema/zod.test.d.ts.map +1 -0
- package/esm/schema/zod.test.js +516 -0
- package/esm/schema/zod.test.js.map +1 -0
- package/esm/util/registry-validators.d.ts.map +1 -1
- package/esm/util/registry-validators.js +40 -0
- package/esm/util/registry-validators.js.map +1 -1
- package/esm/util/registry-validators.test.js +69 -0
- package/esm/util/registry-validators.test.js.map +1 -1
- package/esm/util/registry.d.ts +1 -5
- package/esm/util/registry.d.ts.map +1 -1
- package/esm/util/registry.js +1 -5
- package/esm/util/registry.js.map +1 -1
- package/esm/util/registry.test.js +80 -67
- package/esm/util/registry.test.js.map +1 -1
- package/package.json +2 -3
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const z3 = __importStar(require("zod/v3"));
|
|
37
|
+
const z4 = __importStar(require("zod/v4"));
|
|
38
|
+
const zod_1 = require("./zod");
|
|
39
|
+
// Test helper: assumes `value` is JSON-serializable (plain objects/arrays/primitives).
|
|
40
|
+
// Conservative helper: returns true if any object in the tree has an own `key`
|
|
41
|
+
// property at any depth. This lets us assert against JSON Schema `$ref` keys
|
|
42
|
+
// structurally (not via incidental substrings in string values).
|
|
43
|
+
function hasKeyDeep(value, key) {
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
function isPlainObject(v) {
|
|
46
|
+
if (!v || typeof v !== "object" || Array.isArray(v))
|
|
47
|
+
return false;
|
|
48
|
+
const proto = Object.getPrototypeOf(v);
|
|
49
|
+
return proto === Object.prototype || proto === null;
|
|
50
|
+
}
|
|
51
|
+
function visit(node) {
|
|
52
|
+
if (!node || typeof node !== "object")
|
|
53
|
+
return false;
|
|
54
|
+
if (seen.has(node))
|
|
55
|
+
return false;
|
|
56
|
+
seen.add(node);
|
|
57
|
+
if (Array.isArray(node)) {
|
|
58
|
+
return node.some(visit);
|
|
59
|
+
}
|
|
60
|
+
if (!isPlainObject(node))
|
|
61
|
+
return false;
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(node, key))
|
|
63
|
+
return true;
|
|
64
|
+
return Object.values(node).some(visit);
|
|
65
|
+
}
|
|
66
|
+
return visit(value);
|
|
67
|
+
}
|
|
68
|
+
function resolveJsonPointer(doc, pointer) {
|
|
69
|
+
if (!pointer.startsWith("#"))
|
|
70
|
+
return undefined;
|
|
71
|
+
if (pointer === "#")
|
|
72
|
+
return doc;
|
|
73
|
+
if (!pointer.startsWith("#/"))
|
|
74
|
+
return undefined;
|
|
75
|
+
return pointer
|
|
76
|
+
.slice(2)
|
|
77
|
+
.split("/")
|
|
78
|
+
.map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"))
|
|
79
|
+
.reduce((current, segment) => {
|
|
80
|
+
if (!current || typeof current !== "object")
|
|
81
|
+
return undefined;
|
|
82
|
+
if (Array.isArray(current)) {
|
|
83
|
+
const index = Number(segment);
|
|
84
|
+
if (!Number.isInteger(index))
|
|
85
|
+
return undefined;
|
|
86
|
+
return current[index];
|
|
87
|
+
}
|
|
88
|
+
return current[segment];
|
|
89
|
+
}, doc);
|
|
90
|
+
}
|
|
91
|
+
function createRecursiveZod4NodeSchema() {
|
|
92
|
+
// Placeholder schema so we can self-reference via `z4.lazy` without
|
|
93
|
+
// fighting ESLint `prefer-const`.
|
|
94
|
+
let nodeSchema = z4.any();
|
|
95
|
+
nodeSchema = z4.object({ next: z4.lazy(() => nodeSchema).optional() });
|
|
96
|
+
return nodeSchema;
|
|
97
|
+
}
|
|
98
|
+
describe("zod schema utilities", () => {
|
|
99
|
+
describe("isZod3Schema", () => {
|
|
100
|
+
it("returns true for Zod 3 schemas", () => {
|
|
101
|
+
const schema = z3.object({ name: z3.string() });
|
|
102
|
+
expect((0, zod_1.isZod3Schema)(schema)).toBe(true);
|
|
103
|
+
expect((0, zod_1.isZod4Schema)(schema)).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
it("returns true for Zod 4 schemas (they also have _def)", () => {
|
|
106
|
+
// Note: Zod 4 schemas have both _def and _zod, so isZod3Schema returns true.
|
|
107
|
+
// This is fine because handleZodSchemaToJson checks isZod4Schema first.
|
|
108
|
+
const schema = z4.object({ name: z4.string() });
|
|
109
|
+
expect((0, zod_1.isZod4Schema)(schema)).toBe(true);
|
|
110
|
+
expect((0, zod_1.isZod3Schema)(schema)).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
it("returns false for non-Zod values", () => {
|
|
113
|
+
expect((0, zod_1.isZod3Schema)({})).toBe(false);
|
|
114
|
+
expect((0, zod_1.isZod3Schema)(null)).toBe(false);
|
|
115
|
+
expect((0, zod_1.isZod3Schema)("string")).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("isZod4Schema", () => {
|
|
119
|
+
it("returns true for Zod 4 schemas", () => {
|
|
120
|
+
const schema = z4.object({ name: z4.string() });
|
|
121
|
+
expect((0, zod_1.isZod4Schema)(schema)).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
it("returns false for Zod 3 schemas", () => {
|
|
124
|
+
const schema = z3.object({ name: z3.string() });
|
|
125
|
+
expect((0, zod_1.isZod4Schema)(schema)).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
it("returns false for non-Zod values", () => {
|
|
128
|
+
expect((0, zod_1.isZod4Schema)({})).toBe(false);
|
|
129
|
+
expect((0, zod_1.isZod4Schema)(null)).toBe(false);
|
|
130
|
+
expect((0, zod_1.isZod4Schema)("string")).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe("handleZodSchemaToJson", () => {
|
|
134
|
+
describe("basic conversion", () => {
|
|
135
|
+
it("converts Zod 3 schema to JSON Schema", () => {
|
|
136
|
+
const schema = z3.object({
|
|
137
|
+
name: z3.string(),
|
|
138
|
+
age: z3.number(),
|
|
139
|
+
});
|
|
140
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
141
|
+
expect(result).toMatchObject({
|
|
142
|
+
type: "object",
|
|
143
|
+
properties: {
|
|
144
|
+
name: { type: "string" },
|
|
145
|
+
age: { type: "number" },
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
it("converts Zod 4 schema to JSON Schema", () => {
|
|
150
|
+
const schema = z4.object({
|
|
151
|
+
name: z4.string(),
|
|
152
|
+
age: z4.number(),
|
|
153
|
+
});
|
|
154
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
155
|
+
expect(result).toMatchObject({
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
name: { type: "string" },
|
|
159
|
+
age: { type: "number" },
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe("reused schemas - no $ref references", () => {
|
|
165
|
+
it("inlines reused Zod 3 schemas without any $ref in output", () => {
|
|
166
|
+
// Define a shared schema that will be reused
|
|
167
|
+
const dataSchema = z3.object({
|
|
168
|
+
name: z3.string(),
|
|
169
|
+
value: z3.number(),
|
|
170
|
+
});
|
|
171
|
+
// Use the same schema in multiple places
|
|
172
|
+
const props = z3.object({
|
|
173
|
+
data: z3.array(dataSchema),
|
|
174
|
+
historicalData: z3.array(dataSchema),
|
|
175
|
+
});
|
|
176
|
+
const result = (0, zod_1.handleZodSchemaToJson)(props);
|
|
177
|
+
// Ensure there are no JSON Schema `$ref` keys anywhere in the produced schema.
|
|
178
|
+
expect(hasKeyDeep(result, "$ref")).toBe(false);
|
|
179
|
+
// Both arrays should have the full schema inline
|
|
180
|
+
expect(result).toMatchObject({
|
|
181
|
+
type: "object",
|
|
182
|
+
properties: {
|
|
183
|
+
data: {
|
|
184
|
+
type: "array",
|
|
185
|
+
items: {
|
|
186
|
+
type: "object",
|
|
187
|
+
properties: {
|
|
188
|
+
name: { type: "string" },
|
|
189
|
+
value: { type: "number" },
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
historicalData: {
|
|
194
|
+
type: "array",
|
|
195
|
+
items: {
|
|
196
|
+
type: "object",
|
|
197
|
+
properties: {
|
|
198
|
+
name: { type: "string" },
|
|
199
|
+
value: { type: "number" },
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
it("inlines reused Zod 4 schemas without any $ref in output", () => {
|
|
207
|
+
// Define a shared schema that will be reused
|
|
208
|
+
const dataSchema = z4.object({
|
|
209
|
+
name: z4.string(),
|
|
210
|
+
value: z4.number(),
|
|
211
|
+
});
|
|
212
|
+
// Use the same schema in multiple places
|
|
213
|
+
const props = z4.object({
|
|
214
|
+
data: z4.array(dataSchema),
|
|
215
|
+
historicalData: z4.array(dataSchema),
|
|
216
|
+
});
|
|
217
|
+
const result = (0, zod_1.handleZodSchemaToJson)(props);
|
|
218
|
+
expect(hasKeyDeep(result, "$ref")).toBe(false);
|
|
219
|
+
// Both arrays should have the full schema inline
|
|
220
|
+
expect(result).toMatchObject({
|
|
221
|
+
type: "object",
|
|
222
|
+
properties: {
|
|
223
|
+
data: {
|
|
224
|
+
type: "array",
|
|
225
|
+
items: {
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: {
|
|
228
|
+
name: { type: "string" },
|
|
229
|
+
value: { type: "number" },
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
historicalData: {
|
|
234
|
+
type: "array",
|
|
235
|
+
items: {
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {
|
|
238
|
+
name: { type: "string" },
|
|
239
|
+
value: { type: "number" },
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
it("handles deeply nested reused Zod 3 schemas without any $ref", () => {
|
|
247
|
+
const addressSchema = z3.object({
|
|
248
|
+
street: z3.string(),
|
|
249
|
+
city: z3.string(),
|
|
250
|
+
});
|
|
251
|
+
const personSchema = z3.object({
|
|
252
|
+
name: z3.string(),
|
|
253
|
+
homeAddress: addressSchema,
|
|
254
|
+
workAddress: addressSchema,
|
|
255
|
+
});
|
|
256
|
+
const result = (0, zod_1.handleZodSchemaToJson)(personSchema);
|
|
257
|
+
expect(hasKeyDeep(result, "$ref")).toBe(false);
|
|
258
|
+
expect(result).toMatchObject({
|
|
259
|
+
type: "object",
|
|
260
|
+
properties: {
|
|
261
|
+
name: { type: "string" },
|
|
262
|
+
homeAddress: {
|
|
263
|
+
type: "object",
|
|
264
|
+
properties: {
|
|
265
|
+
street: { type: "string" },
|
|
266
|
+
city: { type: "string" },
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
workAddress: {
|
|
270
|
+
type: "object",
|
|
271
|
+
properties: {
|
|
272
|
+
street: { type: "string" },
|
|
273
|
+
city: { type: "string" },
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
it("handles deeply nested reused Zod 4 schemas without any $ref", () => {
|
|
280
|
+
const addressSchema = z4.object({
|
|
281
|
+
street: z4.string(),
|
|
282
|
+
city: z4.string(),
|
|
283
|
+
});
|
|
284
|
+
const personSchema = z4.object({
|
|
285
|
+
name: z4.string(),
|
|
286
|
+
homeAddress: addressSchema,
|
|
287
|
+
workAddress: addressSchema,
|
|
288
|
+
});
|
|
289
|
+
const result = (0, zod_1.handleZodSchemaToJson)(personSchema);
|
|
290
|
+
expect(hasKeyDeep(result, "$ref")).toBe(false);
|
|
291
|
+
expect(result).toMatchObject({
|
|
292
|
+
type: "object",
|
|
293
|
+
properties: {
|
|
294
|
+
name: { type: "string" },
|
|
295
|
+
homeAddress: {
|
|
296
|
+
type: "object",
|
|
297
|
+
properties: {
|
|
298
|
+
street: { type: "string" },
|
|
299
|
+
city: { type: "string" },
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
workAddress: {
|
|
303
|
+
type: "object",
|
|
304
|
+
properties: {
|
|
305
|
+
street: { type: "string" },
|
|
306
|
+
city: { type: "string" },
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
it("handles triple-nested reused Zod 4 schemas without any $ref", () => {
|
|
313
|
+
const pointSchema = z4.object({
|
|
314
|
+
x: z4.number(),
|
|
315
|
+
y: z4.number(),
|
|
316
|
+
});
|
|
317
|
+
const lineSchema = z4.object({
|
|
318
|
+
start: pointSchema,
|
|
319
|
+
end: pointSchema,
|
|
320
|
+
});
|
|
321
|
+
const shapeSchema = z4.object({
|
|
322
|
+
outline: z4.array(lineSchema),
|
|
323
|
+
boundingBox: z4.object({
|
|
324
|
+
topLeft: pointSchema,
|
|
325
|
+
bottomRight: pointSchema,
|
|
326
|
+
}),
|
|
327
|
+
});
|
|
328
|
+
const result = (0, zod_1.handleZodSchemaToJson)(shapeSchema);
|
|
329
|
+
expect(result).toMatchInlineSnapshot(`
|
|
330
|
+
{
|
|
331
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
332
|
+
"additionalProperties": false,
|
|
333
|
+
"properties": {
|
|
334
|
+
"boundingBox": {
|
|
335
|
+
"additionalProperties": false,
|
|
336
|
+
"properties": {
|
|
337
|
+
"bottomRight": {
|
|
338
|
+
"additionalProperties": false,
|
|
339
|
+
"properties": {
|
|
340
|
+
"x": {
|
|
341
|
+
"type": "number",
|
|
342
|
+
},
|
|
343
|
+
"y": {
|
|
344
|
+
"type": "number",
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
"required": [
|
|
348
|
+
"x",
|
|
349
|
+
"y",
|
|
350
|
+
],
|
|
351
|
+
"type": "object",
|
|
352
|
+
},
|
|
353
|
+
"topLeft": {
|
|
354
|
+
"additionalProperties": false,
|
|
355
|
+
"properties": {
|
|
356
|
+
"x": {
|
|
357
|
+
"type": "number",
|
|
358
|
+
},
|
|
359
|
+
"y": {
|
|
360
|
+
"type": "number",
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
"required": [
|
|
364
|
+
"x",
|
|
365
|
+
"y",
|
|
366
|
+
],
|
|
367
|
+
"type": "object",
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
"required": [
|
|
371
|
+
"topLeft",
|
|
372
|
+
"bottomRight",
|
|
373
|
+
],
|
|
374
|
+
"type": "object",
|
|
375
|
+
},
|
|
376
|
+
"outline": {
|
|
377
|
+
"items": {
|
|
378
|
+
"additionalProperties": false,
|
|
379
|
+
"properties": {
|
|
380
|
+
"end": {
|
|
381
|
+
"additionalProperties": false,
|
|
382
|
+
"properties": {
|
|
383
|
+
"x": {
|
|
384
|
+
"type": "number",
|
|
385
|
+
},
|
|
386
|
+
"y": {
|
|
387
|
+
"type": "number",
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
"required": [
|
|
391
|
+
"x",
|
|
392
|
+
"y",
|
|
393
|
+
],
|
|
394
|
+
"type": "object",
|
|
395
|
+
},
|
|
396
|
+
"start": {
|
|
397
|
+
"additionalProperties": false,
|
|
398
|
+
"properties": {
|
|
399
|
+
"x": {
|
|
400
|
+
"type": "number",
|
|
401
|
+
},
|
|
402
|
+
"y": {
|
|
403
|
+
"type": "number",
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
"required": [
|
|
407
|
+
"x",
|
|
408
|
+
"y",
|
|
409
|
+
],
|
|
410
|
+
"type": "object",
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
"required": [
|
|
414
|
+
"start",
|
|
415
|
+
"end",
|
|
416
|
+
],
|
|
417
|
+
"type": "object",
|
|
418
|
+
},
|
|
419
|
+
"type": "array",
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
"required": [
|
|
423
|
+
"outline",
|
|
424
|
+
"boundingBox",
|
|
425
|
+
],
|
|
426
|
+
"type": "object",
|
|
427
|
+
}
|
|
428
|
+
`);
|
|
429
|
+
expect(hasKeyDeep(result, "$ref")).toBe(false);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
describe("recursive schemas", () => {
|
|
433
|
+
it("represents Zod 4 recursive schemas using $ref", () => {
|
|
434
|
+
const nodeSchema = createRecursiveZod4NodeSchema();
|
|
435
|
+
const result = (0, zod_1.handleZodSchemaToJson)(nodeSchema);
|
|
436
|
+
const schema = result;
|
|
437
|
+
const properties = schema.properties;
|
|
438
|
+
const next = properties?.next;
|
|
439
|
+
const ref = next?.$ref;
|
|
440
|
+
expect(hasKeyDeep(result, "$ref")).toBe(true);
|
|
441
|
+
expect(result).toMatchObject({
|
|
442
|
+
type: "object",
|
|
443
|
+
properties: {
|
|
444
|
+
next: {
|
|
445
|
+
$ref: expect.stringMatching(/^#(\/.*)?$/),
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
expect(ref).toEqual(expect.stringMatching(/^#(\/.*)?$/));
|
|
450
|
+
const resolved = typeof ref === "string" ? resolveJsonPointer(result, ref) : undefined;
|
|
451
|
+
expect(resolved).toBe(result);
|
|
452
|
+
expect(resolved).toMatchObject({
|
|
453
|
+
type: "object",
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
describe("complex schemas", () => {
|
|
458
|
+
it("handles optional fields in Zod 3", () => {
|
|
459
|
+
const schema = z3.object({
|
|
460
|
+
required: z3.string(),
|
|
461
|
+
optional: z3.string().optional(),
|
|
462
|
+
});
|
|
463
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
464
|
+
expect(result).toMatchObject({
|
|
465
|
+
type: "object",
|
|
466
|
+
properties: {
|
|
467
|
+
required: { type: "string" },
|
|
468
|
+
optional: { type: "string" },
|
|
469
|
+
},
|
|
470
|
+
required: ["required"],
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
it("handles optional fields in Zod 4", () => {
|
|
474
|
+
const schema = z4.object({
|
|
475
|
+
required: z4.string(),
|
|
476
|
+
optional: z4.string().optional(),
|
|
477
|
+
});
|
|
478
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
479
|
+
expect(result).toMatchObject({
|
|
480
|
+
type: "object",
|
|
481
|
+
properties: {
|
|
482
|
+
required: { type: "string" },
|
|
483
|
+
optional: { type: "string" },
|
|
484
|
+
},
|
|
485
|
+
required: ["required"],
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
it("handles enums in Zod 3", () => {
|
|
489
|
+
const schema = z3.object({
|
|
490
|
+
status: z3.enum(["active", "inactive", "pending"]),
|
|
491
|
+
});
|
|
492
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
493
|
+
expect(result).toMatchObject({
|
|
494
|
+
type: "object",
|
|
495
|
+
properties: {
|
|
496
|
+
status: {
|
|
497
|
+
type: "string",
|
|
498
|
+
enum: ["active", "inactive", "pending"],
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
it("handles enums in Zod 4", () => {
|
|
504
|
+
const schema = z4.object({
|
|
505
|
+
status: z4.enum(["active", "inactive", "pending"]),
|
|
506
|
+
});
|
|
507
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
508
|
+
expect(result).toMatchObject({
|
|
509
|
+
type: "object",
|
|
510
|
+
properties: {
|
|
511
|
+
status: {
|
|
512
|
+
type: "string",
|
|
513
|
+
enum: ["active", "inactive", "pending"],
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
it("handles descriptions in Zod 3", () => {
|
|
519
|
+
const schema = z3.object({
|
|
520
|
+
name: z3.string().describe("The user name"),
|
|
521
|
+
});
|
|
522
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
523
|
+
expect(result).toMatchObject({
|
|
524
|
+
type: "object",
|
|
525
|
+
properties: {
|
|
526
|
+
name: {
|
|
527
|
+
type: "string",
|
|
528
|
+
description: "The user name",
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
it("handles descriptions in Zod 4", () => {
|
|
534
|
+
const schema = z4.object({
|
|
535
|
+
name: z4.string().describe("The user name"),
|
|
536
|
+
});
|
|
537
|
+
const result = (0, zod_1.handleZodSchemaToJson)(schema);
|
|
538
|
+
expect(result).toMatchObject({
|
|
539
|
+
type: "object",
|
|
540
|
+
properties: {
|
|
541
|
+
name: {
|
|
542
|
+
type: "string",
|
|
543
|
+
description: "The user name",
|
|
544
|
+
},
|
|
545
|
+
},
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
//# sourceMappingURL=zod.test.js.map
|
|
@@ -0,0 +1 @@
|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,GAAG,EAAE;gBACvC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;oBACvB,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;iBAC5C,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,IAAA,2BAAqB,EAAC,MAAM,CAAC,CAAC;gBAE7C,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;oBAC3B,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,IAAI,EAAE;4BACJ,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,eAAe;yBAC7B;qBACF;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;gBACvC,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;oBACvB,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;iBAC5C,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,IAAA,2BAAqB,EAAC,MAAM,CAAC,CAAC;gBAE7C,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;oBAC3B,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,IAAI,EAAE;4BACJ,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,eAAe;yBAC7B;qBACF;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4\";\nimport { handleZodSchemaToJson, isZod3Schema, isZod4Schema } from \"./zod\";\n\n// Test helper: assumes `value` is JSON-serializable (plain objects/arrays/primitives).\n// Conservative helper: returns true if any object in the tree has an own `key`\n// property at any depth. This lets us assert against JSON Schema `$ref` keys\n// structurally (not via incidental substrings in string values).\nfunction hasKeyDeep(value: unknown, key: string): boolean {\n const seen = new Set<object>();\n\n function isPlainObject(v: unknown): v is Record<string, unknown> {\n if (!v || typeof v !== \"object\" || Array.isArray(v)) return false;\n const proto = Object.getPrototypeOf(v);\n return proto === Object.prototype || proto === null;\n }\n\n function visit(node: unknown): boolean {\n if (!node || typeof node !== \"object\") return false;\n if (seen.has(node)) return false;\n seen.add(node);\n\n if (Array.isArray(node)) {\n return node.some(visit);\n }\n\n if (!isPlainObject(node)) return false;\n\n if (Object.prototype.hasOwnProperty.call(node, key)) return true;\n return Object.values(node).some(visit);\n }\n\n return visit(value);\n}\n\nfunction resolveJsonPointer(doc: unknown, pointer: string): unknown {\n if (!pointer.startsWith(\"#\")) return undefined;\n if (pointer === \"#\") return doc;\n if (!pointer.startsWith(\"#/\")) return undefined;\n\n return pointer\n .slice(2)\n .split(\"/\")\n .map((segment) => segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"))\n .reduce<unknown>((current, segment) => {\n if (!current || typeof current !== \"object\") return undefined;\n\n if (Array.isArray(current)) {\n const index = Number(segment);\n if (!Number.isInteger(index)) return undefined;\n return current[index];\n }\n\n return (current as Record<string, unknown>)[segment];\n }, doc);\n}\n\nfunction createRecursiveZod4NodeSchema(): z4.ZodTypeAny {\n // Placeholder schema so we can self-reference via `z4.lazy` without\n // fighting ESLint `prefer-const`.\n let nodeSchema: z4.ZodTypeAny = z4.any();\n nodeSchema = z4.object({ next: z4.lazy(() => nodeSchema).optional() });\n return nodeSchema;\n}\n\ndescribe(\"zod schema utilities\", () => {\n describe(\"isZod3Schema\", () => {\n it(\"returns true for Zod 3 schemas\", () => {\n const schema = z3.object({ name: z3.string() });\n expect(isZod3Schema(schema)).toBe(true);\n expect(isZod4Schema(schema)).toBe(false);\n });\n\n it(\"returns true for Zod 4 schemas (they also have _def)\", () => {\n // Note: Zod 4 schemas have both _def and _zod, so isZod3Schema returns true.\n // This is fine because handleZodSchemaToJson checks isZod4Schema first.\n const schema = z4.object({ name: z4.string() });\n expect(isZod4Schema(schema)).toBe(true);\n expect(isZod3Schema(schema)).toBe(false);\n });\n\n it(\"returns false for non-Zod values\", () => {\n expect(isZod3Schema({})).toBe(false);\n expect(isZod3Schema(null)).toBe(false);\n expect(isZod3Schema(\"string\")).toBe(false);\n });\n });\n\n describe(\"isZod4Schema\", () => {\n it(\"returns true for Zod 4 schemas\", () => {\n const schema = z4.object({ name: z4.string() });\n expect(isZod4Schema(schema)).toBe(true);\n });\n\n it(\"returns false for Zod 3 schemas\", () => {\n const schema = z3.object({ name: z3.string() });\n expect(isZod4Schema(schema)).toBe(false);\n });\n\n it(\"returns false for non-Zod values\", () => {\n expect(isZod4Schema({})).toBe(false);\n expect(isZod4Schema(null)).toBe(false);\n expect(isZod4Schema(\"string\")).toBe(false);\n });\n });\n\n describe(\"handleZodSchemaToJson\", () => {\n describe(\"basic conversion\", () => {\n it(\"converts Zod 3 schema to JSON Schema\", () => {\n const schema = z3.object({\n name: z3.string(),\n age: z3.number(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n });\n });\n\n it(\"converts Zod 4 schema to JSON Schema\", () => {\n const schema = z4.object({\n name: z4.string(),\n age: z4.number(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n age: { type: \"number\" },\n },\n });\n });\n });\n\n describe(\"reused schemas - no $ref references\", () => {\n it(\"inlines reused Zod 3 schemas without any $ref in output\", () => {\n // Define a shared schema that will be reused\n const dataSchema = z3.object({\n name: z3.string(),\n value: z3.number(),\n });\n\n // Use the same schema in multiple places\n const props = z3.object({\n data: z3.array(dataSchema),\n historicalData: z3.array(dataSchema),\n });\n\n const result = handleZodSchemaToJson(props);\n\n // Ensure there are no JSON Schema `$ref` keys anywhere in the produced schema.\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n\n // Both arrays should have the full schema inline\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n data: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n historicalData: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n },\n });\n });\n\n it(\"inlines reused Zod 4 schemas without any $ref in output\", () => {\n // Define a shared schema that will be reused\n const dataSchema = z4.object({\n name: z4.string(),\n value: z4.number(),\n });\n\n // Use the same schema in multiple places\n const props = z4.object({\n data: z4.array(dataSchema),\n historicalData: z4.array(dataSchema),\n });\n\n const result = handleZodSchemaToJson(props);\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n\n // Both arrays should have the full schema inline\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n data: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n historicalData: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n value: { type: \"number\" },\n },\n },\n },\n },\n });\n });\n\n it(\"handles deeply nested reused Zod 3 schemas without any $ref\", () => {\n const addressSchema = z3.object({\n street: z3.string(),\n city: z3.string(),\n });\n\n const personSchema = z3.object({\n name: z3.string(),\n homeAddress: addressSchema,\n workAddress: addressSchema,\n });\n\n const result = handleZodSchemaToJson(personSchema);\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n homeAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n workAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n },\n });\n });\n\n it(\"handles deeply nested reused Zod 4 schemas without any $ref\", () => {\n const addressSchema = z4.object({\n street: z4.string(),\n city: z4.string(),\n });\n\n const personSchema = z4.object({\n name: z4.string(),\n homeAddress: addressSchema,\n workAddress: addressSchema,\n });\n\n const result = handleZodSchemaToJson(personSchema);\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n homeAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n workAddress: {\n type: \"object\",\n properties: {\n street: { type: \"string\" },\n city: { type: \"string\" },\n },\n },\n },\n });\n });\n\n it(\"handles triple-nested reused Zod 4 schemas without any $ref\", () => {\n const pointSchema = z4.object({\n x: z4.number(),\n y: z4.number(),\n });\n\n const lineSchema = z4.object({\n start: pointSchema,\n end: pointSchema,\n });\n\n const shapeSchema = z4.object({\n outline: z4.array(lineSchema),\n boundingBox: z4.object({\n topLeft: pointSchema,\n bottomRight: pointSchema,\n }),\n });\n\n const result = handleZodSchemaToJson(shapeSchema);\n\n expect(result).toMatchInlineSnapshot(`\n {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"boundingBox\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"bottomRight\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n \"topLeft\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n },\n \"required\": [\n \"topLeft\",\n \"bottomRight\",\n ],\n \"type\": \"object\",\n },\n \"outline\": {\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"end\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n \"start\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"x\": {\n \"type\": \"number\",\n },\n \"y\": {\n \"type\": \"number\",\n },\n },\n \"required\": [\n \"x\",\n \"y\",\n ],\n \"type\": \"object\",\n },\n },\n \"required\": [\n \"start\",\n \"end\",\n ],\n \"type\": \"object\",\n },\n \"type\": \"array\",\n },\n },\n \"required\": [\n \"outline\",\n \"boundingBox\",\n ],\n \"type\": \"object\",\n }\n `);\n expect(hasKeyDeep(result, \"$ref\")).toBe(false);\n });\n });\n\n describe(\"recursive schemas\", () => {\n it(\"represents Zod 4 recursive schemas using $ref\", () => {\n const nodeSchema = createRecursiveZod4NodeSchema();\n const result = handleZodSchemaToJson(nodeSchema);\n const schema = result as Record<string, unknown>;\n const properties = schema.properties as\n | Record<string, unknown>\n | undefined;\n const next = properties?.next as Record<string, unknown> | undefined;\n const ref = next?.$ref;\n\n expect(hasKeyDeep(result, \"$ref\")).toBe(true);\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n next: {\n $ref: expect.stringMatching(/^#(\\/.*)?$/),\n },\n },\n });\n expect(ref).toEqual(expect.stringMatching(/^#(\\/.*)?$/));\n\n const resolved =\n typeof ref === \"string\" ? resolveJsonPointer(result, ref) : undefined;\n expect(resolved).toBe(result);\n expect(resolved).toMatchObject({\n type: \"object\",\n });\n });\n });\n\n describe(\"complex schemas\", () => {\n it(\"handles optional fields in Zod 3\", () => {\n const schema = z3.object({\n required: z3.string(),\n optional: z3.string().optional(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n required: { type: \"string\" },\n optional: { type: \"string\" },\n },\n required: [\"required\"],\n });\n });\n\n it(\"handles optional fields in Zod 4\", () => {\n const schema = z4.object({\n required: z4.string(),\n optional: z4.string().optional(),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n required: { type: \"string\" },\n optional: { type: \"string\" },\n },\n required: [\"required\"],\n });\n });\n\n it(\"handles enums in Zod 3\", () => {\n const schema = z3.object({\n status: z3.enum([\"active\", \"inactive\", \"pending\"]),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n status: {\n type: \"string\",\n enum: [\"active\", \"inactive\", \"pending\"],\n },\n },\n });\n });\n\n it(\"handles enums in Zod 4\", () => {\n const schema = z4.object({\n status: z4.enum([\"active\", \"inactive\", \"pending\"]),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n status: {\n type: \"string\",\n enum: [\"active\", \"inactive\", \"pending\"],\n },\n },\n });\n });\n\n it(\"handles descriptions in Zod 3\", () => {\n const schema = z3.object({\n name: z3.string().describe(\"The user name\"),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description: \"The user name\",\n },\n },\n });\n });\n\n it(\"handles descriptions in Zod 4\", () => {\n const schema = z4.object({\n name: z4.string().describe(\"The user name\"),\n });\n\n const result = handleZodSchemaToJson(schema);\n\n expect(result).toMatchObject({\n type: \"object\",\n properties: {\n name: {\n type: \"string\",\n description: \"The user name\",\n },\n },\n });\n });\n });\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry-validators.d.ts","sourceRoot":"","sources":["../../src/util/registry-validators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAoDrC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,uBAAuB,GAAG,IAAI,CAuB5E;AA0CD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,cAAc,GAAG;IACtE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CA6BA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,OAAO,EACxB,UAAU,EAAE,OAAO,GAClB,IAAI,CAWN"}
|