agent-relay 6.0.7 → 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 +50 -19
- 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 +9 -9
|
@@ -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
|
}
|
|
@@ -511,7 +511,7 @@ export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[]
|
|
|
511
511
|
def: core.$ZodDiscriminatedUnionDef<Options, Disc>;
|
|
512
512
|
}
|
|
513
513
|
export declare const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion>;
|
|
514
|
-
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable
|
|
514
|
+
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable<Disc>, ...core.$ZodTypeDiscriminable<Disc>[]], Disc extends string>(discriminator: Disc, options: Types, params?: string | core.$ZodDiscriminatedUnionParams): ZodDiscriminatedUnion<Types, Disc>;
|
|
515
515
|
export interface ZodIntersection<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodIntersectionInternals<A, B>>, core.$ZodIntersection<A, B> {
|
|
516
516
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
517
517
|
}
|
|
@@ -674,6 +674,12 @@ export declare function codec<const A extends core.SomeType, B extends core.Some
|
|
|
674
674
|
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
675
675
|
}): ZodCodec<A, B>;
|
|
676
676
|
export declare function invertCodec<A extends core.SomeType, B extends core.SomeType>(codec: ZodCodec<A, B>): ZodCodec<B, A>;
|
|
677
|
+
export interface ZodPreprocess<B extends core.SomeType = core.$ZodType> extends ZodPipe<core.$ZodTransform, B>, core.$ZodPreprocess<B> {
|
|
678
|
+
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
679
|
+
_zod: core.$ZodPreprocessInternals<B>;
|
|
680
|
+
def: core.$ZodPreprocessDef<B>;
|
|
681
|
+
}
|
|
682
|
+
export declare const ZodPreprocess: core.$constructor<ZodPreprocess>;
|
|
677
683
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
|
|
678
684
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
679
685
|
unwrap(): T;
|
|
@@ -758,4 +764,4 @@ export interface ZodJSONSchema extends _ZodJSONSchema {
|
|
|
758
764
|
_zod: ZodJSONSchemaInternals;
|
|
759
765
|
}
|
|
760
766
|
export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
|
|
761
|
-
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U):
|
|
767
|
+
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U): ZodPreprocess<U>;
|
|
@@ -511,7 +511,7 @@ export interface ZodDiscriminatedUnion<Options extends readonly core.SomeType[]
|
|
|
511
511
|
def: core.$ZodDiscriminatedUnionDef<Options, Disc>;
|
|
512
512
|
}
|
|
513
513
|
export declare const ZodDiscriminatedUnion: core.$constructor<ZodDiscriminatedUnion>;
|
|
514
|
-
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable
|
|
514
|
+
export declare function discriminatedUnion<Types extends readonly [core.$ZodTypeDiscriminable<Disc>, ...core.$ZodTypeDiscriminable<Disc>[]], Disc extends string>(discriminator: Disc, options: Types, params?: string | core.$ZodDiscriminatedUnionParams): ZodDiscriminatedUnion<Types, Disc>;
|
|
515
515
|
export interface ZodIntersection<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodIntersectionInternals<A, B>>, core.$ZodIntersection<A, B> {
|
|
516
516
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
517
517
|
}
|
|
@@ -674,6 +674,12 @@ export declare function codec<const A extends core.SomeType, B extends core.Some
|
|
|
674
674
|
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
675
675
|
}): ZodCodec<A, B>;
|
|
676
676
|
export declare function invertCodec<A extends core.SomeType, B extends core.SomeType>(codec: ZodCodec<A, B>): ZodCodec<B, A>;
|
|
677
|
+
export interface ZodPreprocess<B extends core.SomeType = core.$ZodType> extends ZodPipe<core.$ZodTransform, B>, core.$ZodPreprocess<B> {
|
|
678
|
+
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
679
|
+
_zod: core.$ZodPreprocessInternals<B>;
|
|
680
|
+
def: core.$ZodPreprocessDef<B>;
|
|
681
|
+
}
|
|
682
|
+
export declare const ZodPreprocess: core.$constructor<ZodPreprocess>;
|
|
677
683
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
|
|
678
684
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
679
685
|
unwrap(): T;
|
|
@@ -758,4 +764,4 @@ export interface ZodJSONSchema extends _ZodJSONSchema {
|
|
|
758
764
|
_zod: ZodJSONSchemaInternals;
|
|
759
765
|
}
|
|
760
766
|
export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
|
|
761
|
-
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U):
|
|
767
|
+
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U): ZodPreprocess<U>;
|
|
@@ -1085,10 +1085,12 @@ export const ZodTransform = /*@__PURE__*/ core.$constructor("ZodTransform", (ins
|
|
|
1085
1085
|
if (output instanceof Promise) {
|
|
1086
1086
|
return output.then((output) => {
|
|
1087
1087
|
payload.value = output;
|
|
1088
|
+
payload.fallback = true;
|
|
1088
1089
|
return payload;
|
|
1089
1090
|
});
|
|
1090
1091
|
}
|
|
1091
1092
|
payload.value = output;
|
|
1093
|
+
payload.fallback = true;
|
|
1092
1094
|
return payload;
|
|
1093
1095
|
};
|
|
1094
1096
|
});
|
|
@@ -1255,6 +1257,10 @@ export function invertCodec(codec) {
|
|
|
1255
1257
|
reverseTransform: def.transform,
|
|
1256
1258
|
});
|
|
1257
1259
|
}
|
|
1260
|
+
export const ZodPreprocess = /*@__PURE__*/ core.$constructor("ZodPreprocess", (inst, def) => {
|
|
1261
|
+
ZodPipe.init(inst, def);
|
|
1262
|
+
core.$ZodPreprocess.init(inst, def);
|
|
1263
|
+
});
|
|
1258
1264
|
export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, def) => {
|
|
1259
1265
|
core.$ZodReadonly.init(inst, def);
|
|
1260
1266
|
ZodType.init(inst, def);
|
|
@@ -1381,5 +1387,9 @@ export function json(params) {
|
|
|
1381
1387
|
}
|
|
1382
1388
|
// preprocess
|
|
1383
1389
|
export function preprocess(fn, schema) {
|
|
1384
|
-
return
|
|
1390
|
+
return new ZodPreprocess({
|
|
1391
|
+
type: "pipe",
|
|
1392
|
+
in: transform(fn),
|
|
1393
|
+
out: schema,
|
|
1394
|
+
});
|
|
1385
1395
|
}
|
|
@@ -225,14 +225,16 @@ export type $ZodUnionParams = TypeParams<schemas.$ZodUnion, "options">;
|
|
|
225
225
|
export declare function _union<const T extends readonly schemas.$ZodObject[]>(Class: util.SchemaClass<schemas.$ZodUnion>, options: T, params?: string | $ZodUnionParams): schemas.$ZodUnion<T>;
|
|
226
226
|
export type $ZodXorParams = TypeParams<schemas.$ZodXor, "options">;
|
|
227
227
|
export declare function _xor<const T extends readonly schemas.$ZodObject[]>(Class: util.SchemaClass<schemas.$ZodXor>, options: T, params?: string | $ZodXorParams): schemas.$ZodXor<T>;
|
|
228
|
-
export interface $ZodTypeDiscriminableInternals extends schemas.$ZodTypeInternals {
|
|
228
|
+
export interface $ZodTypeDiscriminableInternals<Disc extends string = string> extends schemas.$ZodTypeInternals<unknown, {
|
|
229
|
+
[K in Disc]?: unknown;
|
|
230
|
+
}> {
|
|
229
231
|
propValues: util.PropValues;
|
|
230
232
|
}
|
|
231
|
-
export interface $ZodTypeDiscriminable extends schemas.$ZodType {
|
|
232
|
-
_zod: $ZodTypeDiscriminableInternals
|
|
233
|
+
export interface $ZodTypeDiscriminable<Disc extends string = string> extends schemas.$ZodType {
|
|
234
|
+
_zod: $ZodTypeDiscriminableInternals<Disc>;
|
|
233
235
|
}
|
|
234
236
|
export type $ZodDiscriminatedUnionParams = TypeParams<schemas.$ZodDiscriminatedUnion, "options" | "discriminator">;
|
|
235
|
-
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable
|
|
237
|
+
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable<Disc>, ...$ZodTypeDiscriminable<Disc>[]], Disc extends string>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: Disc, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types, Disc>;
|
|
236
238
|
export type $ZodIntersectionParams = TypeParams<schemas.$ZodIntersection, "left" | "right">;
|
|
237
239
|
export declare function _intersection<T extends schemas.$ZodObject, U extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodIntersection>, left: T, right: U): schemas.$ZodIntersection<T, U>;
|
|
238
240
|
export type $ZodTupleParams = TypeParams<schemas.$ZodTuple, "items" | "rest">;
|
|
@@ -225,14 +225,16 @@ export type $ZodUnionParams = TypeParams<schemas.$ZodUnion, "options">;
|
|
|
225
225
|
export declare function _union<const T extends readonly schemas.$ZodObject[]>(Class: util.SchemaClass<schemas.$ZodUnion>, options: T, params?: string | $ZodUnionParams): schemas.$ZodUnion<T>;
|
|
226
226
|
export type $ZodXorParams = TypeParams<schemas.$ZodXor, "options">;
|
|
227
227
|
export declare function _xor<const T extends readonly schemas.$ZodObject[]>(Class: util.SchemaClass<schemas.$ZodXor>, options: T, params?: string | $ZodXorParams): schemas.$ZodXor<T>;
|
|
228
|
-
export interface $ZodTypeDiscriminableInternals extends schemas.$ZodTypeInternals {
|
|
228
|
+
export interface $ZodTypeDiscriminableInternals<Disc extends string = string> extends schemas.$ZodTypeInternals<unknown, {
|
|
229
|
+
[K in Disc]?: unknown;
|
|
230
|
+
}> {
|
|
229
231
|
propValues: util.PropValues;
|
|
230
232
|
}
|
|
231
|
-
export interface $ZodTypeDiscriminable extends schemas.$ZodType {
|
|
232
|
-
_zod: $ZodTypeDiscriminableInternals
|
|
233
|
+
export interface $ZodTypeDiscriminable<Disc extends string = string> extends schemas.$ZodType {
|
|
234
|
+
_zod: $ZodTypeDiscriminableInternals<Disc>;
|
|
233
235
|
}
|
|
234
236
|
export type $ZodDiscriminatedUnionParams = TypeParams<schemas.$ZodDiscriminatedUnion, "options" | "discriminator">;
|
|
235
|
-
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable
|
|
237
|
+
export declare function _discriminatedUnion<Types extends [$ZodTypeDiscriminable<Disc>, ...$ZodTypeDiscriminable<Disc>[]], Disc extends string>(Class: util.SchemaClass<schemas.$ZodDiscriminatedUnion>, discriminator: Disc, options: Types, params?: string | $ZodDiscriminatedUnionParams): schemas.$ZodDiscriminatedUnion<Types, Disc>;
|
|
236
238
|
export type $ZodIntersectionParams = TypeParams<schemas.$ZodIntersection, "left" | "right">;
|
|
237
239
|
export declare function _intersection<T extends schemas.$ZodObject, U extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodIntersection>, left: T, right: U): schemas.$ZodIntersection<T, U>;
|
|
238
240
|
export type $ZodTupleParams = TypeParams<schemas.$ZodTuple, "items" | "rest">;
|
|
@@ -525,7 +525,8 @@ const catchProcessor = (schema, ctx, json, params) => {
|
|
|
525
525
|
exports.catchProcessor = catchProcessor;
|
|
526
526
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
527
527
|
const def = schema._zod.def;
|
|
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
|
(0, to_json_schema_js_1.process)(innerType, ctx, params);
|
|
530
531
|
const seen = ctx.seen.get(schema);
|
|
531
532
|
seen.ref = innerType;
|
|
@@ -487,7 +487,8 @@ export const catchProcessor = (schema, ctx, json, params) => {
|
|
|
487
487
|
};
|
|
488
488
|
export const pipeProcessor = (schema, ctx, _json, params) => {
|
|
489
489
|
const def = schema._zod.def;
|
|
490
|
-
const
|
|
490
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
491
|
+
const innerType = ctx.io === "input" ? (inIsTransform ? def.out : def.in) : def.out;
|
|
491
492
|
process(innerType, ctx, params);
|
|
492
493
|
const seen = ctx.seen.get(schema);
|
|
493
494
|
seen.ref = innerType;
|