agent-relay 6.0.6 → 6.0.8
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.cjs +129 -36
- package/dist/src/cli/commands/cloud.d.ts +1 -0
- package/dist/src/cli/commands/cloud.d.ts.map +1 -1
- package/dist/src/cli/commands/cloud.js +74 -3
- package/dist/src/cli/commands/cloud.js.map +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/README.md +0 -17
- package/node_modules/@relaycast/sdk/node_modules/zod/package.json +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/schemas.ts +25 -3
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/assignability.test.ts +6 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/catch.test.ts +52 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +3 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/partial.test.ts +20 -23
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +26 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +69 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +22 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/api.ts +6 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/json-schema-processors.ts +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/schemas.ts +45 -5
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/to-json-schema.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/schemas.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/index.test.ts +5 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.cjs +12 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.d.cts +8 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.d.ts +8 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.js +11 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.d.cts +6 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.d.ts +6 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/json-schema-processors.cjs +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/json-schema-processors.js +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.cjs +15 -6
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.d.cts +18 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.d.ts +18 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.js +14 -5
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/to-json-schema.cjs +2 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/to-json-schema.js +2 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.js +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.d.cts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.d.ts +1 -1
- package/package.json +10 -10
|
@@ -31,23 +31,6 @@
|
|
|
31
31
|
<br/>
|
|
32
32
|
<br/>
|
|
33
33
|
|
|
34
|
-
<h2 align="center">Featured sponsor: Jazz</h2>
|
|
35
|
-
|
|
36
|
-
<div align="center">
|
|
37
|
-
<a href="https://jazz.tools/?utm_source=zod">
|
|
38
|
-
<picture width="85%" >
|
|
39
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/garden-co/jazz/938f6767e46cdfded60e50d99bf3b533f4809c68/homepage/homepage/public/Zod%20sponsor%20message.png">
|
|
40
|
-
<img alt="jazz logo" src="https://raw.githubusercontent.com/garden-co/jazz/938f6767e46cdfded60e50d99bf3b533f4809c68/homepage/homepage/public/Zod%20sponsor%20message.png" width="85%">
|
|
41
|
-
</picture>
|
|
42
|
-
</a>
|
|
43
|
-
<br/>
|
|
44
|
-
<p><sub>Learn more about <a target="_blank" rel="noopener noreferrer" href="mailto:sponsorship@colinhacks.com">featured sponsorships</a></sub></p>
|
|
45
|
-
</div>
|
|
46
|
-
|
|
47
|
-
<br/>
|
|
48
|
-
<br/>
|
|
49
|
-
<br/>
|
|
50
|
-
|
|
51
34
|
### [Read the docs →](https://zod.dev/api)
|
|
52
35
|
|
|
53
36
|
<br/>
|
|
@@ -1617,7 +1617,7 @@ export const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion> = /
|
|
|
1617
1617
|
);
|
|
1618
1618
|
|
|
1619
1619
|
export function discriminatedUnion<
|
|
1620
|
-
Types extends readonly [core.$ZodTypeDiscriminable
|
|
1620
|
+
Types extends readonly [core.$ZodTypeDiscriminable<Disc>, ...core.$ZodTypeDiscriminable<Disc>[]],
|
|
1621
1621
|
Disc extends string,
|
|
1622
1622
|
>(
|
|
1623
1623
|
discriminator: Disc,
|
|
@@ -2034,10 +2034,12 @@ export const ZodTransform: core.$constructor<ZodTransform> = /*@__PURE__*/ core.
|
|
|
2034
2034
|
if (output instanceof Promise) {
|
|
2035
2035
|
return output.then((output) => {
|
|
2036
2036
|
payload.value = output;
|
|
2037
|
+
payload.fallback = true;
|
|
2037
2038
|
return payload;
|
|
2038
2039
|
});
|
|
2039
2040
|
}
|
|
2040
2041
|
payload.value = output;
|
|
2042
|
+
payload.fallback = true;
|
|
2041
2043
|
return payload;
|
|
2042
2044
|
};
|
|
2043
2045
|
}
|
|
@@ -2361,6 +2363,22 @@ export function invertCodec<A extends core.SomeType, B extends core.SomeType>(co
|
|
|
2361
2363
|
}) as any;
|
|
2362
2364
|
}
|
|
2363
2365
|
|
|
2366
|
+
// ZodPreprocess
|
|
2367
|
+
export interface ZodPreprocess<B extends core.SomeType = core.$ZodType>
|
|
2368
|
+
extends ZodPipe<core.$ZodTransform, B>,
|
|
2369
|
+
core.$ZodPreprocess<B> {
|
|
2370
|
+
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
2371
|
+
_zod: core.$ZodPreprocessInternals<B>;
|
|
2372
|
+
def: core.$ZodPreprocessDef<B>;
|
|
2373
|
+
}
|
|
2374
|
+
export const ZodPreprocess: core.$constructor<ZodPreprocess> = /*@__PURE__*/ core.$constructor(
|
|
2375
|
+
"ZodPreprocess",
|
|
2376
|
+
(inst, def) => {
|
|
2377
|
+
ZodPipe.init(inst, def);
|
|
2378
|
+
core.$ZodPreprocess.init(inst, def);
|
|
2379
|
+
}
|
|
2380
|
+
);
|
|
2381
|
+
|
|
2364
2382
|
// ZodReadonly
|
|
2365
2383
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType>
|
|
2366
2384
|
extends _ZodType<core.$ZodReadonlyInternals<T>>,
|
|
@@ -2645,6 +2663,10 @@ export function json(params?: string | core.$ZodCustomParams): ZodJSONSchema {
|
|
|
2645
2663
|
export function preprocess<A, U extends core.SomeType, B = unknown>(
|
|
2646
2664
|
fn: (arg: B, ctx: core.$RefinementCtx) => A,
|
|
2647
2665
|
schema: U
|
|
2648
|
-
):
|
|
2649
|
-
return
|
|
2666
|
+
): ZodPreprocess<U> {
|
|
2667
|
+
return new ZodPreprocess({
|
|
2668
|
+
type: "pipe",
|
|
2669
|
+
in: transform(fn as any) as any as core.$ZodTransform,
|
|
2670
|
+
out: schema as any as core.$ZodType,
|
|
2671
|
+
}) as any;
|
|
2650
2672
|
}
|
package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/assignability.test.ts
CHANGED
|
@@ -143,6 +143,12 @@ test("assignability", () => {
|
|
|
143
143
|
z.unknown().pipe(z.number()) satisfies z.core.$ZodPipe;
|
|
144
144
|
z.unknown().pipe(z.number()) satisfies z.ZodPipe;
|
|
145
145
|
|
|
146
|
+
// $ZodPreprocess
|
|
147
|
+
z.preprocess((v) => v, z.number()) satisfies z.core.$ZodPreprocess;
|
|
148
|
+
z.preprocess((v) => v, z.number()) satisfies z.ZodPreprocess;
|
|
149
|
+
z.preprocess((v) => v, z.number()) satisfies z.core.$ZodPipe<z.core.$ZodTransform, z.ZodNumber>;
|
|
150
|
+
z.preprocess((v) => v, z.number()) satisfies z.ZodPipe<z.core.$ZodTransform, z.ZodNumber>;
|
|
151
|
+
|
|
146
152
|
// $ZodSuccess
|
|
147
153
|
z.success(z.string()) satisfies z.core.$ZodSuccess;
|
|
148
154
|
z.success(z.string()) satisfies z.ZodSuccess;
|
|
@@ -128,8 +128,9 @@ test("native enum", () => {
|
|
|
128
128
|
fruit: z.nativeEnum(Fruits).catch(Fruits.apple),
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
expect(schema.
|
|
131
|
+
// Absent keys flow through to the catch handler.
|
|
132
|
+
expect(schema.parse({})).toEqual({ fruit: Fruits.apple });
|
|
133
|
+
expect(schema.parse({}, { jitless: true })).toEqual({ fruit: Fruits.apple });
|
|
133
134
|
expect(schema.parse({ fruit: 15 })).toEqual({ fruit: Fruits.apple });
|
|
134
135
|
});
|
|
135
136
|
|
|
@@ -138,8 +139,8 @@ test("enum", () => {
|
|
|
138
139
|
fruit: z.enum(["apple", "orange"]).catch("apple"),
|
|
139
140
|
});
|
|
140
141
|
|
|
141
|
-
expect(schema.
|
|
142
|
-
expect(schema.
|
|
142
|
+
expect(schema.parse({})).toEqual({ fruit: "apple" });
|
|
143
|
+
expect(schema.parse({}, { jitless: true })).toEqual({ fruit: "apple" });
|
|
143
144
|
expect(schema.parse({ fruit: true })).toEqual({ fruit: "apple" });
|
|
144
145
|
expect(schema.parse({ fruit: 15 })).toEqual({ fruit: "apple" });
|
|
145
146
|
});
|
|
@@ -276,3 +277,50 @@ test("direction-aware catch", () => {
|
|
|
276
277
|
// But valid values should still work in reverse
|
|
277
278
|
expect(z.encode(schema, "world")).toBe("world");
|
|
278
279
|
});
|
|
280
|
+
|
|
281
|
+
test("optional clobbers catch through pipe boundaries", () => {
|
|
282
|
+
expect(
|
|
283
|
+
z
|
|
284
|
+
.string()
|
|
285
|
+
.catch("X")
|
|
286
|
+
.transform((s) => s + "!")
|
|
287
|
+
.optional()
|
|
288
|
+
.parse(undefined)
|
|
289
|
+
).toBeUndefined();
|
|
290
|
+
expect(z.string().catch("X").pipe(z.string()).optional().parse(undefined)).toBeUndefined();
|
|
291
|
+
expect(
|
|
292
|
+
z
|
|
293
|
+
.string()
|
|
294
|
+
.catch("X")
|
|
295
|
+
.transform((s) => s + "!")
|
|
296
|
+
.transform((s) => s.toLowerCase())
|
|
297
|
+
.optional()
|
|
298
|
+
.parse(undefined)
|
|
299
|
+
).toBeUndefined();
|
|
300
|
+
expect(
|
|
301
|
+
z
|
|
302
|
+
.object({
|
|
303
|
+
a: z
|
|
304
|
+
.string()
|
|
305
|
+
.catch("X")
|
|
306
|
+
.transform((s) => s + "!")
|
|
307
|
+
.optional(),
|
|
308
|
+
})
|
|
309
|
+
.parse({})
|
|
310
|
+
).toEqual({});
|
|
311
|
+
|
|
312
|
+
expect(
|
|
313
|
+
z
|
|
314
|
+
.string()
|
|
315
|
+
.catch("X")
|
|
316
|
+
.transform((s) => s + "!")
|
|
317
|
+
.parse("hi")
|
|
318
|
+
).toBe("hi!");
|
|
319
|
+
expect(
|
|
320
|
+
z
|
|
321
|
+
.string()
|
|
322
|
+
.catch("X")
|
|
323
|
+
.transform((s) => s + "!")
|
|
324
|
+
.parse(123)
|
|
325
|
+
).toBe("X!");
|
|
326
|
+
});
|
|
@@ -264,6 +264,9 @@ test("valid discriminator value, invalid data", () => {
|
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
test("wrong schema - missing discriminator", () => {
|
|
267
|
+
// @ts-expect-error missing discriminator property
|
|
268
|
+
z.discriminatedUnion("type", [z.object({ value: z.string() })]);
|
|
269
|
+
|
|
267
270
|
try {
|
|
268
271
|
z.discriminatedUnion("type", [
|
|
269
272
|
z.object({ type: z.literal("a"), a: z.string() }),
|
|
@@ -156,30 +156,27 @@ test("catch/prefault/default", () => {
|
|
|
156
156
|
f: z.string().prefault("prefault value"),
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
159
|
+
// Catch (d) and default/prefault (b, c, e, f) handle absent keys gracefully.
|
|
160
|
+
// `a: catch().optional()` short-circuits to undefined when the original
|
|
161
|
+
// input was undefined, so the property is omitted from the output. All
|
|
162
|
+
// other catch/default/prefault keys produce their fallback values.
|
|
163
|
+
expect(mySchema.parse({})).toMatchInlineSnapshot(`
|
|
164
|
+
{
|
|
165
|
+
"b": "default value",
|
|
166
|
+
"c": "prefault value",
|
|
167
|
+
"d": "catch value",
|
|
168
|
+
"e": "default value",
|
|
169
|
+
"f": "prefault value",
|
|
170
|
+
}
|
|
170
171
|
`);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
"d",
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
]
|
|
172
|
+
expect(mySchema.parse({}, { jitless: true })).toMatchInlineSnapshot(`
|
|
173
|
+
{
|
|
174
|
+
"b": "default value",
|
|
175
|
+
"c": "prefault value",
|
|
176
|
+
"d": "catch value",
|
|
177
|
+
"e": "default value",
|
|
178
|
+
"f": "prefault value",
|
|
179
|
+
}
|
|
183
180
|
`);
|
|
184
181
|
|
|
185
182
|
expect(mySchema.parse({ d: undefined })).toMatchInlineSnapshot(`
|
package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import * as z from "zod/v4";
|
|
3
|
+
|
|
4
|
+
test("ZodPreprocess<B> assignable to ZodPipe<$ZodTransform, B>", () => {
|
|
5
|
+
const pre = z.preprocess((v) => v, z.string().optional());
|
|
6
|
+
const _asPipe: z.ZodPipe<z.core.$ZodTransform, z.ZodOptional<z.ZodString>> = pre;
|
|
7
|
+
const _asCorePipe: z.core.$ZodPipe<z.core.$ZodTransform, z.ZodOptional<z.ZodString>> = pre;
|
|
8
|
+
expectTypeOf(_asPipe).toMatchTypeOf<z.ZodPipe>();
|
|
9
|
+
expectTypeOf(_asCorePipe).toMatchTypeOf<z.core.$ZodPipe>();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("ZodPreprocess optin/optout defer to B", () => {
|
|
13
|
+
const optionalInside = z.preprocess((v) => v, z.string().optional());
|
|
14
|
+
expectTypeOf<(typeof optionalInside)["_zod"]["optin"]>().toEqualTypeOf<"optional">();
|
|
15
|
+
expectTypeOf<(typeof optionalInside)["_zod"]["optout"]>().toEqualTypeOf<"optional">();
|
|
16
|
+
|
|
17
|
+
const required = z.preprocess((v) => v, z.string());
|
|
18
|
+
expectTypeOf<(typeof required)["_zod"]["optin"]>().toEqualTypeOf<"optional" | undefined>();
|
|
19
|
+
expectTypeOf<(typeof required)["_zod"]["optout"]>().toEqualTypeOf<"optional" | undefined>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("ZodPreprocess input/output inference", () => {
|
|
23
|
+
const pre = z.preprocess((v) => v, z.number().optional());
|
|
24
|
+
expectTypeOf<z.output<typeof pre>>().toEqualTypeOf<number | undefined>();
|
|
25
|
+
expectTypeOf<z.input<typeof pre>>().toEqualTypeOf<unknown>();
|
|
26
|
+
});
|
package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/preprocess.test.ts
CHANGED
|
@@ -280,3 +280,72 @@ test("perform transform with non-fatal issues", () => {
|
|
|
280
280
|
]]
|
|
281
281
|
`);
|
|
282
282
|
});
|
|
283
|
+
|
|
284
|
+
test("preprocess accepts absent object keys (4.3 parity)", () => {
|
|
285
|
+
const schema = z.object({ a: z.preprocess((v) => v ?? "X", z.string()) });
|
|
286
|
+
expect(schema.parse({})).toEqual({ a: "X" });
|
|
287
|
+
expect(schema.parse({ a: "hi" })).toEqual({ a: "hi" });
|
|
288
|
+
expect(schema.parse({ a: undefined })).toEqual({ a: "X" });
|
|
289
|
+
|
|
290
|
+
// Outer optional clobbers preprocess output on undefined input
|
|
291
|
+
expect(
|
|
292
|
+
z
|
|
293
|
+
.preprocess((v) => v ?? "X", z.string())
|
|
294
|
+
.optional()
|
|
295
|
+
.parse(undefined)
|
|
296
|
+
).toBeUndefined();
|
|
297
|
+
expect(
|
|
298
|
+
z
|
|
299
|
+
.preprocess((v) => v ?? "X", z.string())
|
|
300
|
+
.optional()
|
|
301
|
+
.parse("hi")
|
|
302
|
+
).toBe("hi");
|
|
303
|
+
expect(z.object({ a: z.preprocess((v) => v ?? "X", z.string()).optional() }).parse({})).toEqual({});
|
|
304
|
+
|
|
305
|
+
// Top-level direct call unchanged
|
|
306
|
+
expect(z.preprocess((v) => v ?? "X", z.string()).parse(undefined)).toBe("X");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// https://github.com/colinhacks/zod/issues/5917
|
|
310
|
+
test("optional propagates through preprocess inside object", () => {
|
|
311
|
+
const outer = z.object({ x: z.preprocess((v) => v, z.number()).optional() });
|
|
312
|
+
const inner = z.object({ x: z.preprocess((v) => v, z.number().optional()) });
|
|
313
|
+
|
|
314
|
+
expect(outer.safeParse({}).success).toBe(true);
|
|
315
|
+
expect(inner.safeParse({}).success).toBe(true);
|
|
316
|
+
|
|
317
|
+
expect(outer.safeParse({ x: 1 })).toEqual({ success: true, data: { x: 1 } });
|
|
318
|
+
expect(inner.safeParse({ x: 1 })).toEqual({ success: true, data: { x: 1 } });
|
|
319
|
+
|
|
320
|
+
expect(inner._zod.def.shape.x._zod.optin).toBe("optional");
|
|
321
|
+
expect(inner._zod.def.shape.x._zod.optout).toBe("optional");
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("preprocess is a structural subtype of ZodPipe", () => {
|
|
325
|
+
const schema = z.preprocess((v) => v, z.string());
|
|
326
|
+
expect(schema).toBeInstanceOf(z.ZodPipe);
|
|
327
|
+
expect(schema).toBeInstanceOf(z.ZodPreprocess);
|
|
328
|
+
expect(schema._zod.def.type).toBe("pipe");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("preprocess does not propagate values/propValues from inner schema", () => {
|
|
332
|
+
const inner = z.preprocess((v) => v, z.literal("test"));
|
|
333
|
+
expect(inner._zod.values).toBeUndefined();
|
|
334
|
+
expect(inner._zod.propValues).toBeUndefined();
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("preprocess as discriminator throws at construction (no propValues to inherit)", () => {
|
|
338
|
+
const schema = z.discriminatedUnion("kind", [
|
|
339
|
+
z.object({ kind: z.preprocess((v: any) => String(v).toUpperCase(), z.literal("A")), a: z.string() }),
|
|
340
|
+
z.object({ kind: z.preprocess((v: any) => String(v).toUpperCase(), z.literal("B")), b: z.number() }),
|
|
341
|
+
]);
|
|
342
|
+
expect(() => schema.parse({ kind: "a", a: "x" })).toThrow(/Invalid discriminated union option/);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("preprocess as record key does not restrict accepted keys", () => {
|
|
346
|
+
const schema = z.record(
|
|
347
|
+
z.preprocess((v: any) => String(v).toLowerCase(), z.enum(["a", "b"])),
|
|
348
|
+
z.string()
|
|
349
|
+
);
|
|
350
|
+
expect(schema.safeParse({ A: "x", B: "y" })).toEqual({ success: true, data: { a: "x", b: "y" } });
|
|
351
|
+
});
|
package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts
CHANGED
|
@@ -2731,7 +2731,6 @@ test("input type", () => {
|
|
|
2731
2731
|
"required": [
|
|
2732
2732
|
"a",
|
|
2733
2733
|
"d",
|
|
2734
|
-
"f",
|
|
2735
2734
|
"g",
|
|
2736
2735
|
],
|
|
2737
2736
|
"type": "object",
|
|
@@ -2896,6 +2895,28 @@ test("use output type for preprocess", () => {
|
|
|
2896
2895
|
`);
|
|
2897
2896
|
});
|
|
2898
2897
|
|
|
2898
|
+
test("strip output-side examples from input JSON schema for codec", () => {
|
|
2899
|
+
const codec = z
|
|
2900
|
+
.codec(z.string(), z.number(), { decode: (s) => Number(s), encode: (n) => String(n) })
|
|
2901
|
+
.meta({ examples: [42] });
|
|
2902
|
+
|
|
2903
|
+
expect(z.toJSONSchema(codec, { io: "input" })).toMatchInlineSnapshot(`
|
|
2904
|
+
{
|
|
2905
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2906
|
+
"type": "string",
|
|
2907
|
+
}
|
|
2908
|
+
`);
|
|
2909
|
+
expect(z.toJSONSchema(codec, { io: "output" })).toMatchInlineSnapshot(`
|
|
2910
|
+
{
|
|
2911
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2912
|
+
"examples": [
|
|
2913
|
+
42,
|
|
2914
|
+
],
|
|
2915
|
+
"type": "number",
|
|
2916
|
+
}
|
|
2917
|
+
`);
|
|
2918
|
+
});
|
|
2919
|
+
|
|
2899
2920
|
// test("isTransforming", () => {
|
|
2900
2921
|
// const tx = z.core.isTransforming;
|
|
2901
2922
|
// expect(tx(z.string())).toEqual(false);
|
|
@@ -1207,17 +1207,19 @@ export function _xor<const T extends readonly schemas.$ZodObject[]>(
|
|
|
1207
1207
|
}
|
|
1208
1208
|
|
|
1209
1209
|
// ZodDiscriminatedUnion
|
|
1210
|
-
export interface $ZodTypeDiscriminableInternals extends
|
|
1210
|
+
export interface $ZodTypeDiscriminableInternals<Disc extends string = string>
|
|
1211
|
+
extends schemas.$ZodTypeInternals<unknown, { [K in Disc]?: unknown }> {
|
|
1211
1212
|
propValues: util.PropValues;
|
|
1212
1213
|
}
|
|
1213
1214
|
|
|
1214
|
-
export interface $ZodTypeDiscriminable extends schemas.$ZodType {
|
|
1215
|
-
_zod: $ZodTypeDiscriminableInternals
|
|
1215
|
+
export interface $ZodTypeDiscriminable<Disc extends string = string> extends schemas.$ZodType {
|
|
1216
|
+
_zod: $ZodTypeDiscriminableInternals<Disc>;
|
|
1216
1217
|
}
|
|
1218
|
+
|
|
1217
1219
|
export type $ZodDiscriminatedUnionParams = TypeParams<schemas.$ZodDiscriminatedUnion, "options" | "discriminator">;
|
|
1218
1220
|
// @__NO_SIDE_EFFECTS__
|
|
1219
1221
|
export function _discriminatedUnion<
|
|
1220
|
-
Types extends [$ZodTypeDiscriminable
|
|
1222
|
+
Types extends [$ZodTypeDiscriminable<Disc>, ...$ZodTypeDiscriminable<Disc>[]],
|
|
1221
1223
|
Disc extends string,
|
|
1222
1224
|
>(
|
|
1223
1225
|
Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>,
|
|
@@ -525,7 +525,8 @@ export const catchProcessor: Processor<schemas.$ZodCatch> = (schema, ctx, json,
|
|
|
525
525
|
|
|
526
526
|
export const pipeProcessor: Processor<schemas.$ZodPipe> = (schema, ctx, _json, params) => {
|
|
527
527
|
const def = schema._zod.def as schemas.$ZodPipeDef;
|
|
528
|
-
const
|
|
528
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
529
|
+
const innerType = ctx.io === "input" ? (inIsTransform ? def.out : def.in) : def.out;
|
|
529
530
|
process(innerType, ctx as any, params);
|
|
530
531
|
const seen = ctx.seen.get(schema)!;
|
|
531
532
|
seen.ref = innerType;
|
|
@@ -36,6 +36,11 @@ export interface ParsePayload<T = unknown> {
|
|
|
36
36
|
issues: errors.$ZodRawIssue[];
|
|
37
37
|
/** A way to mark a whole payload as aborted. Used in codecs/pipes. */
|
|
38
38
|
aborted?: boolean;
|
|
39
|
+
/** @internal Marks a value as a fallback that an outer wrapper (e.g.
|
|
40
|
+
* $ZodOptional) may override with its own interpretation when input was
|
|
41
|
+
* undefined. Set by $ZodCatch when catchValue substitutes and by every
|
|
42
|
+
* $ZodTransform invocation. */
|
|
43
|
+
fallback?: boolean | undefined;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
export type CheckFn<T> = (input: ParsePayload<T>) => util.MaybeAsync<void>;
|
|
@@ -3417,6 +3422,7 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
3417
3422
|
"$ZodTransform",
|
|
3418
3423
|
(inst, def) => {
|
|
3419
3424
|
$ZodType.init(inst, def);
|
|
3425
|
+
inst._zod.optin = "optional";
|
|
3420
3426
|
inst._zod.parse = (payload, ctx) => {
|
|
3421
3427
|
if (ctx.direction === "backward") {
|
|
3422
3428
|
throw new core.$ZodEncodeError(inst.constructor.name);
|
|
@@ -3427,6 +3433,7 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
3427
3433
|
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
3428
3434
|
return output.then((output) => {
|
|
3429
3435
|
payload.value = output;
|
|
3436
|
+
payload.fallback = true;
|
|
3430
3437
|
return payload;
|
|
3431
3438
|
});
|
|
3432
3439
|
}
|
|
@@ -3436,6 +3443,7 @@ export const $ZodTransform: core.$constructor<$ZodTransform> = /*@__PURE__*/ cor
|
|
|
3436
3443
|
}
|
|
3437
3444
|
|
|
3438
3445
|
payload.value = _out;
|
|
3446
|
+
payload.fallback = true;
|
|
3439
3447
|
return payload;
|
|
3440
3448
|
};
|
|
3441
3449
|
}
|
|
@@ -3468,7 +3476,7 @@ export interface $ZodOptional<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3468
3476
|
}
|
|
3469
3477
|
|
|
3470
3478
|
function handleOptionalResult(result: ParsePayload, input: unknown) {
|
|
3471
|
-
if (result.issues.length
|
|
3479
|
+
if (input === undefined && (result.issues.length || result.fallback)) {
|
|
3472
3480
|
return { issues: [], value: undefined };
|
|
3473
3481
|
}
|
|
3474
3482
|
return result;
|
|
@@ -3491,9 +3499,10 @@ export const $ZodOptional: core.$constructor<$ZodOptional> = /*@__PURE__*/ core.
|
|
|
3491
3499
|
|
|
3492
3500
|
inst._zod.parse = (payload, ctx) => {
|
|
3493
3501
|
if (def.innerType._zod.optin === "optional") {
|
|
3502
|
+
const input = payload.value;
|
|
3494
3503
|
const result = def.innerType._zod.run(payload, ctx);
|
|
3495
|
-
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r,
|
|
3496
|
-
return handleOptionalResult(result,
|
|
3504
|
+
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
|
|
3505
|
+
return handleOptionalResult(result, input);
|
|
3497
3506
|
}
|
|
3498
3507
|
if (payload.value === undefined) {
|
|
3499
3508
|
return payload;
|
|
@@ -3886,7 +3895,7 @@ export interface $ZodCatch<T extends SomeType = $ZodType> extends $ZodType {
|
|
|
3886
3895
|
|
|
3887
3896
|
export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
|
|
3888
3897
|
$ZodType.init(inst, def);
|
|
3889
|
-
|
|
3898
|
+
inst._zod.optin = "optional";
|
|
3890
3899
|
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
3891
3900
|
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
3892
3901
|
|
|
@@ -3909,6 +3918,7 @@ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$const
|
|
|
3909
3918
|
input: payload.value,
|
|
3910
3919
|
});
|
|
3911
3920
|
payload.issues = [];
|
|
3921
|
+
payload.fallback = true;
|
|
3912
3922
|
}
|
|
3913
3923
|
|
|
3914
3924
|
return payload;
|
|
@@ -3926,6 +3936,7 @@ export const $ZodCatch: core.$constructor<$ZodCatch> = /*@__PURE__*/ core.$const
|
|
|
3926
3936
|
});
|
|
3927
3937
|
|
|
3928
3938
|
payload.issues = [];
|
|
3939
|
+
payload.fallback = true;
|
|
3929
3940
|
}
|
|
3930
3941
|
|
|
3931
3942
|
return payload;
|
|
@@ -4030,7 +4041,7 @@ function handlePipeResult(left: ParsePayload, next: $ZodType, ctx: ParseContextI
|
|
|
4030
4041
|
left.aborted = true;
|
|
4031
4042
|
return left;
|
|
4032
4043
|
}
|
|
4033
|
-
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
|
4044
|
+
return next._zod.run({ value: left.value, issues: left.issues, fallback: left.fallback }, ctx);
|
|
4034
4045
|
}
|
|
4035
4046
|
|
|
4036
4047
|
////////////////////////////////////////////
|
|
@@ -4118,6 +4129,35 @@ function handleCodecTxResult(left: ParsePayload, value: any, nextSchema: SomeTyp
|
|
|
4118
4129
|
return nextSchema._zod.run({ value, issues: left.issues }, ctx);
|
|
4119
4130
|
}
|
|
4120
4131
|
|
|
4132
|
+
/////////////////////////////////////////////////
|
|
4133
|
+
/////////////////////////////////////////////////
|
|
4134
|
+
////////// //////////
|
|
4135
|
+
////////// $ZodPreprocess //////////
|
|
4136
|
+
////////// //////////
|
|
4137
|
+
/////////////////////////////////////////////////
|
|
4138
|
+
/////////////////////////////////////////////////
|
|
4139
|
+
export interface $ZodPreprocessDef<B extends SomeType = $ZodType> extends $ZodPipeDef<$ZodTransform, B> {
|
|
4140
|
+
in: $ZodTransform;
|
|
4141
|
+
out: B;
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
export interface $ZodPreprocessInternals<B extends SomeType = $ZodType> extends $ZodPipeInternals<$ZodTransform, B> {
|
|
4145
|
+
def: $ZodPreprocessDef<B>;
|
|
4146
|
+
optin: B["_zod"]["optin"];
|
|
4147
|
+
optout: B["_zod"]["optout"];
|
|
4148
|
+
}
|
|
4149
|
+
|
|
4150
|
+
export interface $ZodPreprocess<B extends SomeType = $ZodType> extends $ZodPipe<$ZodTransform, B> {
|
|
4151
|
+
_zod: $ZodPreprocessInternals<B>;
|
|
4152
|
+
}
|
|
4153
|
+
|
|
4154
|
+
export const $ZodPreprocess: core.$constructor<$ZodPreprocess> = /*@__PURE__*/ core.$constructor(
|
|
4155
|
+
"$ZodPreprocess",
|
|
4156
|
+
(inst, def) => {
|
|
4157
|
+
$ZodPipe.init(inst, def);
|
|
4158
|
+
}
|
|
4159
|
+
);
|
|
4160
|
+
|
|
4121
4161
|
////////////////////////////////////////////
|
|
4122
4162
|
////////////////////////////////////////////
|
|
4123
4163
|
////////// //////////
|
|
@@ -561,6 +561,7 @@ function isTransforming(
|
|
|
561
561
|
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
562
562
|
}
|
|
563
563
|
if (def.type === "pipe") {
|
|
564
|
+
if (_schema._zod.traits.has("$ZodCodec")) return true;
|
|
564
565
|
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
565
566
|
}
|
|
566
567
|
|
|
@@ -1083,7 +1083,7 @@ export const ZodMiniDiscriminatedUnion: core.$constructor<ZodMiniDiscriminatedUn
|
|
|
1083
1083
|
|
|
1084
1084
|
// @__NO_SIDE_EFFECTS__
|
|
1085
1085
|
export function discriminatedUnion<
|
|
1086
|
-
Types extends readonly [core.$ZodTypeDiscriminable
|
|
1086
|
+
Types extends readonly [core.$ZodTypeDiscriminable<Disc>, ...core.$ZodTypeDiscriminable<Disc>[]],
|
|
1087
1087
|
Disc extends string,
|
|
1088
1088
|
>(
|
|
1089
1089
|
discriminator: Disc,
|
|
@@ -247,6 +247,11 @@ test("z.union([]) / z.xor([]) / z.discriminatedUnion(_, []) construct and reject
|
|
|
247
247
|
}
|
|
248
248
|
});
|
|
249
249
|
|
|
250
|
+
test("z.discriminatedUnion rejects object options missing the discriminator at type level", () => {
|
|
251
|
+
// @ts-expect-error missing discriminator property
|
|
252
|
+
z.discriminatedUnion("type", [z.object({ value: z.string() })]);
|
|
253
|
+
});
|
|
254
|
+
|
|
250
255
|
test("z.intersection", () => {
|
|
251
256
|
const a = z.intersection(z.object({ a: z.string() }), z.object({ b: z.number() }));
|
|
252
257
|
expect(z.parse(a, { a: "hello", b: 123 })).toEqual({ a: "hello", b: 123 });
|
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodXor = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodCustomStringFormat = exports.ZodJWT = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodMAC = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = void 0;
|
|
27
|
-
exports.stringbool = exports.meta = exports.describe = exports.ZodCustom = exports.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodExactOptional = exports.ZodOptional = exports.ZodTransform = exports.ZodFile = void 0;
|
|
27
|
+
exports.stringbool = exports.meta = exports.describe = exports.ZodCustom = exports.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodPreprocess = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodExactOptional = exports.ZodOptional = exports.ZodTransform = exports.ZodFile = void 0;
|
|
28
28
|
exports.string = string;
|
|
29
29
|
exports.email = email;
|
|
30
30
|
exports.guid = guid;
|
|
@@ -1203,10 +1203,12 @@ exports.ZodTransform = core.$constructor("ZodTransform", (inst, def) => {
|
|
|
1203
1203
|
if (output instanceof Promise) {
|
|
1204
1204
|
return output.then((output) => {
|
|
1205
1205
|
payload.value = output;
|
|
1206
|
+
payload.fallback = true;
|
|
1206
1207
|
return payload;
|
|
1207
1208
|
});
|
|
1208
1209
|
}
|
|
1209
1210
|
payload.value = output;
|
|
1211
|
+
payload.fallback = true;
|
|
1210
1212
|
return payload;
|
|
1211
1213
|
};
|
|
1212
1214
|
});
|
|
@@ -1372,6 +1374,10 @@ function invertCodec(codec) {
|
|
|
1372
1374
|
reverseTransform: def.transform,
|
|
1373
1375
|
});
|
|
1374
1376
|
}
|
|
1377
|
+
exports.ZodPreprocess = core.$constructor("ZodPreprocess", (inst, def) => {
|
|
1378
|
+
exports.ZodPipe.init(inst, def);
|
|
1379
|
+
core.$ZodPreprocess.init(inst, def);
|
|
1380
|
+
});
|
|
1375
1381
|
exports.ZodReadonly = core.$constructor("ZodReadonly", (inst, def) => {
|
|
1376
1382
|
core.$ZodReadonly.init(inst, def);
|
|
1377
1383
|
exports.ZodType.init(inst, def);
|
|
@@ -1497,5 +1503,9 @@ function json(params) {
|
|
|
1497
1503
|
}
|
|
1498
1504
|
// preprocess
|
|
1499
1505
|
function preprocess(fn, schema) {
|
|
1500
|
-
return
|
|
1506
|
+
return new exports.ZodPreprocess({
|
|
1507
|
+
type: "pipe",
|
|
1508
|
+
in: transform(fn),
|
|
1509
|
+
out: schema,
|
|
1510
|
+
});
|
|
1501
1511
|
}
|