zod 4.0.0-beta.20250503T014749 → 4.0.0-beta.20250504T215252
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/commonjs/schemas.d.ts +40 -154
- package/dist/commonjs/schemas.js +22 -133
- package/dist/esm/schemas.d.ts +40 -154
- package/dist/esm/schemas.js +20 -124
- package/package.json +2 -2
- package/src/schemas.ts +82 -478
package/dist/esm/schemas.d.ts
CHANGED
|
@@ -10,14 +10,12 @@ export interface ZodType<out Output = unknown, out Input = unknown> extends core
|
|
|
10
10
|
def: this["_zod"]["def"];
|
|
11
11
|
/** @deprecated Use `.def` instead. */
|
|
12
12
|
_def: this["_zod"]["def"];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_input: this["_zod"]["input"];
|
|
17
|
-
check(...checks: (core.CheckFn<this["_zod"]["output"]> | core.$ZodCheck<this["_zod"]["output"]>)[]): this;
|
|
13
|
+
_output: core.output<this>;
|
|
14
|
+
_input: core.input<this>;
|
|
15
|
+
check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
|
|
18
16
|
clone(def?: this["_zod"]["def"]): this;
|
|
19
17
|
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$ZodRegistry<R["_meta"], this>["_meta"]?] : [core.$ZodRegistry<R["_meta"], this>["_meta"]] : ["Incompatible schema"]): this;
|
|
20
|
-
brand<T extends PropertyKey = PropertyKey>(value?: T): this & Record<"_zod", Record<"output", this
|
|
18
|
+
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : this & Record<"_zod", Record<"~output", core.output<this> & core.$brand<T>>>;
|
|
21
19
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
22
20
|
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): parse.ZodSafeParseResult<core.output<this>>;
|
|
23
21
|
parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
|
|
@@ -387,78 +385,9 @@ export interface ZodArray<T extends core.$ZodType = core.$ZodType> extends ZodTy
|
|
|
387
385
|
}
|
|
388
386
|
export declare const ZodArray: core.$constructor<ZodArray>;
|
|
389
387
|
export declare function array<T extends core.$ZodType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T>;
|
|
390
|
-
export
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
export declare const ZodObjectLike: core.$constructor<ZodObjectLike>;
|
|
394
|
-
export declare function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["def"]["shape"]>;
|
|
395
|
-
export declare function keyof<T extends ZodInterface>(schema: T): ZodLiteral<keyof T["_zod"]["output"]>;
|
|
396
|
-
type ZodInterfacePartial<T extends ZodInterface, Keys extends keyof T["_zod"]["def"]["shape"] = keyof T["_zod"]["def"]["shape"]> = ZodInterface<util.Extend<T["_zod"]["def"]["shape"], {
|
|
397
|
-
[k in Keys]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
|
|
398
|
-
}>, {
|
|
399
|
-
optional: T["_zod"]["optional"] | (string & Keys);
|
|
400
|
-
defaulted: T["_zod"]["defaulted"];
|
|
401
|
-
extra: T["_zod"]["extra"];
|
|
402
|
-
}>;
|
|
403
|
-
type ZodInterfaceRequired<T extends ZodInterface, Keys extends keyof T["_zod"]["def"]["shape"] = keyof T["_zod"]["def"]["shape"]> = ZodInterface<util.Extend<T["_zod"]["def"]["shape"], {
|
|
404
|
-
[k in Keys]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
|
|
405
|
-
}>, {
|
|
406
|
-
optional: never;
|
|
407
|
-
defaulted: T["_zod"]["defaulted"];
|
|
408
|
-
extra: T["_zod"]["extra"];
|
|
409
|
-
}>;
|
|
410
|
-
export type MergeInterfaces<A extends ZodInterface, B extends ZodInterface> = ZodInterface<util.Extend<A["_zod"]["def"]["shape"], B["_zod"]["def"]["shape"]>, util.MergeInterfaceParams<A, B>>;
|
|
411
|
-
export interface ZodInterface<out Shape extends core.$ZodLooseShape = core.$ZodLooseShape, out Params extends core.$ZodInterfaceNamedParams = core.$ZodInterfaceNamedParams> extends ZodType {
|
|
412
|
-
_zod: core.$ZodInterfaceInternals<Shape, Params>;
|
|
413
|
-
keyof(): ZodEnum<util.ToEnum<util.InterfaceKeys<string & keyof Shape>>>;
|
|
414
|
-
catchall<T extends core.$ZodType>(schema: T): ZodInterface<Shape, {
|
|
415
|
-
optional: Params["optional"];
|
|
416
|
-
defaulted: Params["defaulted"];
|
|
417
|
-
extra: Record<string, T["_zod"]["output"]>;
|
|
418
|
-
}>;
|
|
419
|
-
/** Consider `z.strictObject({ ...A.shape })` instead. */
|
|
420
|
-
strict(): ZodInterface<Shape, {
|
|
421
|
-
optional: Params["optional"];
|
|
422
|
-
defaulted: Params["defaulted"];
|
|
423
|
-
extra: {};
|
|
424
|
-
}>;
|
|
425
|
-
loose(): ZodInterface<Shape, {
|
|
426
|
-
optional: Params["optional"];
|
|
427
|
-
defaulted: Params["defaulted"];
|
|
428
|
-
extra: Record<string, unknown>;
|
|
429
|
-
}>;
|
|
430
|
-
/** Use `z.looseObject({ ...A.shape })` instead. */
|
|
431
|
-
strip(): ZodInterface<Shape, {
|
|
432
|
-
optional: Params["optional"];
|
|
433
|
-
defaulted: Params["defaulted"];
|
|
434
|
-
extra: {};
|
|
435
|
-
}>;
|
|
436
|
-
extend<U extends ZodInterface>(int: U): MergeInterfaces<this, U>;
|
|
437
|
-
extend<U extends core.$ZodLooseShape>(shape: U): MergeInterfaces<this, ZodInterface<U, util.InitInterfaceParams<U, {}>>>;
|
|
438
|
-
/** @deprecated Use `A.extend(B)` */
|
|
439
|
-
merge<U extends ZodInterface>(incoming: U): MergeInterfaces<this, U>;
|
|
440
|
-
pick<const M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(mask: M): ZodInterface<util.Flatten<Pick<Shape, keyof Shape & keyof M>>, {
|
|
441
|
-
optional: Extract<Params["optional"], keyof M>;
|
|
442
|
-
defaulted: Extract<Params["defaulted"], keyof M>;
|
|
443
|
-
extra: Params["extra"];
|
|
444
|
-
}>;
|
|
445
|
-
omit<const M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(mask: M): ZodInterface<util.Flatten<Omit<Shape, keyof M>>, {
|
|
446
|
-
optional: Exclude<Params["optional"], keyof M>;
|
|
447
|
-
defaulted: Exclude<Params["defaulted"], keyof M>;
|
|
448
|
-
extra: Params["extra"];
|
|
449
|
-
}>;
|
|
450
|
-
partial(): ZodInterfacePartial<this>;
|
|
451
|
-
partial<M extends util.Mask<string & keyof Shape>>(mask: M): ZodInterfacePartial<this, string & keyof M>;
|
|
452
|
-
required(): ZodInterfaceRequired<this, string & keyof Shape>;
|
|
453
|
-
required<M extends util.Mask<string & keyof Shape>>(mask: M): ZodInterfaceRequired<this, string & keyof M>;
|
|
454
|
-
}
|
|
455
|
-
export declare const ZodInterface: core.$constructor<ZodInterface>;
|
|
456
|
-
declare function _interface<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodInterfaceParams, Class?: util.Constructor<ZodInterface>): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>>;
|
|
457
|
-
export { _interface as interface };
|
|
458
|
-
export declare function strictInterface<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodInterfaceParams): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>>;
|
|
459
|
-
export declare function looseInterface<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodInterfaceParams): ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, Record<string, unknown>>>;
|
|
460
|
-
export interface ZodObject<out Shape extends core.$ZodShape = core.$ZodShape, Extra extends Record<string, unknown> = Record<string, unknown>> extends ZodType {
|
|
461
|
-
_zod: core.$ZodObjectInternals<Shape, Extra>;
|
|
388
|
+
export declare function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"]["output"]>;
|
|
389
|
+
export interface ZodObject<out Shape extends core.$ZodShape = core.$ZodLooseShape, OutExtra extends Record<string, unknown> = Record<string, unknown>, InExtra extends Record<string, unknown> = Record<string, unknown>> extends ZodType {
|
|
390
|
+
_zod: core.$ZodObjectInternals<Shape, OutExtra, InExtra>;
|
|
462
391
|
shape: Shape;
|
|
463
392
|
keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
|
|
464
393
|
/** Define a schema to validate all unrecognized keys. This overrides the existing strict/loose behavior. */
|
|
@@ -471,95 +400,52 @@ export interface ZodObject<out Shape extends core.$ZodShape = core.$ZodShape, Ex
|
|
|
471
400
|
strict(): ZodObject<Shape, {}>;
|
|
472
401
|
/** This is the default behavior. This method call is likely unnecessary. */
|
|
473
402
|
strip(): ZodObject<Shape, {}>;
|
|
474
|
-
extend<
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
403
|
+
extend<U extends core.$ZodLooseShape>(shape: U): ZodObject<util.Extend<Shape, U>, OutExtra, InExtra>;
|
|
404
|
+
/**
|
|
405
|
+
* @deprecated Use destructuring to merge the shapes:
|
|
406
|
+
*
|
|
407
|
+
* ```ts
|
|
408
|
+
* z.object({
|
|
409
|
+
* ...A.shape,
|
|
410
|
+
* ...B.shape
|
|
411
|
+
* });
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
merge<U extends ZodObject>(other: U): ZodObject<util.Extend<Shape, U["shape"]>, U["_zod"]["outextra"], U["_zod"]["inextra"]>;
|
|
415
|
+
/**
|
|
416
|
+
* @deprecated Use destructuring to merge the shapes:
|
|
417
|
+
*
|
|
418
|
+
* ```ts
|
|
419
|
+
* z.object({
|
|
420
|
+
* ...A.shape,
|
|
421
|
+
* ...B.shape
|
|
422
|
+
* });
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
pick<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(mask: M): ZodObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, OutExtra, InExtra>;
|
|
426
|
+
omit<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(mask: M): ZodObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, OutExtra, InExtra>;
|
|
480
427
|
partial(): ZodObject<{
|
|
481
428
|
[k in keyof Shape]: ZodOptional<Shape[k]>;
|
|
482
|
-
},
|
|
429
|
+
}, OutExtra, InExtra>;
|
|
483
430
|
partial<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(mask: M): ZodObject<{
|
|
484
431
|
[k in keyof Shape]: k extends keyof M ? ZodOptional<Shape[k]> : Shape[k];
|
|
485
|
-
},
|
|
432
|
+
}, OutExtra, InExtra>;
|
|
486
433
|
required(): ZodObject<{
|
|
487
434
|
[k in keyof Shape]: ZodNonOptional<Shape[k]>;
|
|
488
|
-
},
|
|
435
|
+
}, OutExtra, InExtra>;
|
|
489
436
|
required<M extends util.Exactly<util.Mask<string & keyof Shape>, M>>(mask: M): ZodObject<{
|
|
490
437
|
[k in keyof Shape]: k extends keyof M ? ZodNonOptional<Shape[k]> : Shape[k];
|
|
491
|
-
},
|
|
438
|
+
}, OutExtra, InExtra>;
|
|
492
439
|
}
|
|
493
440
|
export declare const ZodObject: core.$constructor<ZodObject>;
|
|
494
|
-
export declare function object<T extends core.$
|
|
495
|
-
export declare function strictObject<T extends core.$
|
|
496
|
-
export declare function looseObject<T extends core.$
|
|
441
|
+
export declare function object<T extends core.$ZodLooseShape = Record<never, core.$ZodType>>(shape?: T, params?: string | core.$ZodObjectParams): ZodObject<util.Writeable<T> & {}, {}, {}>;
|
|
442
|
+
export declare function strictObject<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodObjectParams): ZodObject<T, {}, {}>;
|
|
443
|
+
export declare function looseObject<T extends core.$ZodLooseShape>(shape: T, params?: string | core.$ZodObjectParams): ZodObject<T, {
|
|
497
444
|
[k: string]: unknown;
|
|
498
|
-
}>;
|
|
499
|
-
export declare function extend<T extends ZodInterface, U extends ZodInterface>(a: T, b: U): ZodInterface<util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>, util.MergeInterfaceParams<T, U>>;
|
|
500
|
-
export declare function extend<T extends ZodObject, U extends ZodObject>(a: T, b: U): ZodObject<util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>, U["_zod"]["extra"] & T["_zod"]["extra"]>;
|
|
501
|
-
export declare function extend<T extends ZodObjectLike, U extends core.$ZodLooseShape>(schema: T, shape: U): T extends ZodInterface<infer TShape, infer TParams> ? ZodInterface<util.ExtendInterfaceShape<TShape, U>, util.ExtendInterfaceParams<ZodInterface<TShape, TParams>, U>> : ZodObject<util.Extend<T["_zod"]["def"]["shape"], U>, T["_zod"]["extra"]>;
|
|
502
|
-
export declare function merge<T extends ZodObjectLike, U extends core.$ZodLooseShape>(schema: T, shape: U): T["_zod"]["def"]["type"] extends "interface" ? ZodInterface<util.Extend<T["_zod"]["def"]["shape"], U["_zod"]["def"]["shape"]>, {
|
|
503
|
-
extra: T["_zod"]["extra"] & U["_zod"]["extra"];
|
|
504
|
-
optional: Exclude<T["_zod"]["optional"], keyof U["_zod"]["def"]["shape"]> | U["_zod"]["optional"];
|
|
505
|
-
defaulted: Exclude<T["_zod"]["defaulted"], keyof U["_zod"]["def"]["shape"]> | U["_zod"]["defaulted"];
|
|
506
|
-
}> : ZodObject<util.Extend<T["_zod"]["def"]["shape"], U>, T["_zod"]["extra"]>;
|
|
507
|
-
export declare function pick<T extends ZodObjectLike, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(schema: T, mask: M): T["_zod"]["def"]["type"] extends "interface" ? ZodInterface<util.Flatten<Pick<T["_zod"]["def"]["shape"], keyof T["_zod"]["def"]["shape"] & keyof M>>, {
|
|
508
|
-
optional: Extract<T["_zod"]["optional"], keyof M>;
|
|
509
|
-
defaulted: Extract<T["_zod"]["defaulted"], keyof M>;
|
|
510
|
-
extra: T["_zod"]["extra"];
|
|
511
|
-
}> : ZodObject<util.Flatten<Pick<T["_zod"]["def"]["shape"], keyof T["_zod"]["def"]["shape"] & keyof M>>, T["_zod"]["extra"]>;
|
|
512
|
-
export declare function omit<T extends ZodObjectLike, const M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(schema: T, mask: M): T["_zod"]["def"]["type"] extends "interface" ? ZodInterface<util.Flatten<Omit<T["_zod"]["def"]["shape"], keyof M>>, {
|
|
513
|
-
optional: Exclude<T["_zod"]["optional"], keyof M>;
|
|
514
|
-
defaulted: Exclude<T["_zod"]["defaulted"], keyof M>;
|
|
515
|
-
extra: T["_zod"]["extra"];
|
|
516
|
-
}> : ZodObject<util.Flatten<Omit<T["_zod"]["def"]["shape"], keyof M>>, T["_zod"]["extra"]>;
|
|
517
|
-
export declare function partial<T extends ZodObjectLike>(schema: T): T["_zod"]["def"]["type"] extends "interface" ? ZodInterface<{
|
|
518
|
-
[k in keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
|
|
519
445
|
}, {
|
|
520
|
-
|
|
521
|
-
defaulted: never;
|
|
522
|
-
extra: T["_zod"]["extra"];
|
|
523
|
-
}> : ZodObject<{
|
|
524
|
-
[k in keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
|
|
525
|
-
}, T["_zod"]["extra"]>;
|
|
526
|
-
export declare function partial<T extends ZodObjectLike, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(schema: T, mask: M): T["_zod"]["def"]["type"] extends "interface" ? ZodInterface<util.Extend<T["_zod"]["def"]["shape"], {
|
|
527
|
-
[k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodOptional<T["_zod"]["def"]["shape"][k]>;
|
|
528
|
-
}>, {
|
|
529
|
-
optional: string & (T["_zod"]["optional"] | keyof M);
|
|
530
|
-
defaulted: T["_zod"]["defaulted"];
|
|
531
|
-
extra: T["_zod"]["extra"];
|
|
532
|
-
}> : ZodObject<{
|
|
533
|
-
[k in keyof T["_zod"]["def"]["shape"]]: k extends keyof M ? ZodOptional<T["_zod"]["def"]["shape"][k]> : T["_zod"]["def"]["shape"][k];
|
|
534
|
-
}, T["_zod"]["extra"]>;
|
|
535
|
-
export declare function required<T extends {
|
|
536
|
-
_subtype: "object";
|
|
537
|
-
} & ZodObject>(schema: T): ZodObject<{
|
|
538
|
-
[k in keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
|
|
539
|
-
}>;
|
|
540
|
-
export declare function required<T extends {
|
|
541
|
-
_subtype: "object";
|
|
542
|
-
} & ZodObject, M extends util.Exactly<util.Mask<keyof T["_zod"]["def"]["shape"]>, M>>(schema: T, mask: M): ZodObject<util.Extend<T["_zod"]["def"]["shape"], {
|
|
543
|
-
[k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
|
|
544
|
-
}>>;
|
|
545
|
-
export declare function required<T extends {
|
|
546
|
-
_subtype: "interface";
|
|
547
|
-
} & ZodInterface>(schema: T): ZodInterface<{
|
|
548
|
-
[k in keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
|
|
549
|
-
}, {
|
|
550
|
-
optional: never;
|
|
551
|
-
defaulted: T["_zod"]["defaulted"];
|
|
552
|
-
extra: T["_zod"]["extra"];
|
|
553
|
-
}>;
|
|
554
|
-
export declare function required<T extends {
|
|
555
|
-
_subtype: "interface";
|
|
556
|
-
} & ZodInterface, M extends util.Mask<keyof T["_zod"]["output"]>>(schema: T, mask: M): ZodInterface<util.Extend<T["_zod"]["def"]["shape"], {
|
|
557
|
-
[k in keyof M & keyof T["_zod"]["def"]["shape"]]: ZodNonOptional<T["_zod"]["def"]["shape"][k]>;
|
|
558
|
-
}>, {
|
|
559
|
-
optional: Exclude<T["_zod"]["optional"], keyof M>;
|
|
560
|
-
defaulted: T["_zod"]["defaulted"];
|
|
561
|
-
extra: T["_zod"]["extra"];
|
|
446
|
+
[k: string]: unknown;
|
|
562
447
|
}>;
|
|
448
|
+
export declare function partial<T>(shape: T): Partial<T>;
|
|
563
449
|
export interface ZodUnion<T extends readonly core.$ZodType[] = readonly core.$ZodType[]> extends ZodType {
|
|
564
450
|
_zod: core.$ZodUnionInternals<T>;
|
|
565
451
|
options: T;
|
package/dist/esm/schemas.js
CHANGED
|
@@ -464,96 +464,17 @@ export const ZodArray = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def)
|
|
|
464
464
|
export function array(element, params) {
|
|
465
465
|
return core._array(ZodArray, element, params);
|
|
466
466
|
}
|
|
467
|
-
|
|
468
|
-
core.$ZodObjectLike.init(inst, def);
|
|
469
|
-
ZodType.init(inst, def);
|
|
470
|
-
});
|
|
467
|
+
// .keyof
|
|
471
468
|
export function keyof(schema) {
|
|
472
|
-
const shape = schema._zod.def.
|
|
473
|
-
? util.cleanInterfaceShape(schema._zod.def.shape).shape
|
|
474
|
-
: schema._zod.def.shape;
|
|
469
|
+
const shape = schema._zod.def.shape;
|
|
475
470
|
return literal(Object.keys(shape));
|
|
476
471
|
}
|
|
477
|
-
export const ZodInterface = /*@__PURE__*/ core.$constructor("ZodInterface", (inst, def) => {
|
|
478
|
-
core.$ZodInterface.init(inst, def);
|
|
479
|
-
ZodType.init(inst, def);
|
|
480
|
-
// util.defineLazy(inst._zod, "shape", () => def.shape);
|
|
481
|
-
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
482
|
-
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
483
|
-
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
484
|
-
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
485
|
-
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
|
|
486
|
-
inst.extend = (incoming) => {
|
|
487
|
-
if (incoming instanceof core.$ZodInterface)
|
|
488
|
-
return util.extendObjectLike(inst, incoming);
|
|
489
|
-
return util.extendObjectLike(inst, _interface(incoming));
|
|
490
|
-
};
|
|
491
|
-
inst.merge = (other) => util.mergeObjectLike(inst, other);
|
|
492
|
-
inst.pick = (mask) => util.pick(inst, mask);
|
|
493
|
-
inst.omit = (mask) => util.omit(inst, mask);
|
|
494
|
-
inst.partial = (...args) => util.partialObjectLike(ZodOptional, inst, args[0]);
|
|
495
|
-
inst.required = (...args) => util.requiredObjectLike(ZodNonOptional, inst, args[0]);
|
|
496
|
-
});
|
|
497
|
-
function _interface(shape, params, Class = ZodInterface) {
|
|
498
|
-
const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
|
|
499
|
-
const def = {
|
|
500
|
-
type: "interface",
|
|
501
|
-
get shape() {
|
|
502
|
-
// return cleaned.value.shape;
|
|
503
|
-
const _shape = cleaned.value.shape;
|
|
504
|
-
util.assignProp(this, "shape", _shape);
|
|
505
|
-
return _shape;
|
|
506
|
-
},
|
|
507
|
-
get optional() {
|
|
508
|
-
return cleaned.value.optional;
|
|
509
|
-
},
|
|
510
|
-
...util.normalizeParams(params),
|
|
511
|
-
};
|
|
512
|
-
return new Class(def);
|
|
513
|
-
}
|
|
514
|
-
export { _interface as interface };
|
|
515
|
-
// strictInterface
|
|
516
|
-
export function strictInterface(shape, params) {
|
|
517
|
-
const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
|
|
518
|
-
const def = {
|
|
519
|
-
type: "interface",
|
|
520
|
-
get shape() {
|
|
521
|
-
// return cleaned.value.shape;
|
|
522
|
-
const _shape = cleaned.value.shape;
|
|
523
|
-
util.assignProp(this, "shape", _shape);
|
|
524
|
-
return _shape;
|
|
525
|
-
},
|
|
526
|
-
get optional() {
|
|
527
|
-
return cleaned.value.optional;
|
|
528
|
-
},
|
|
529
|
-
catchall: never(),
|
|
530
|
-
...util.normalizeParams(params),
|
|
531
|
-
};
|
|
532
|
-
return new ZodInterface(def);
|
|
533
|
-
}
|
|
534
|
-
// looseInterface
|
|
535
|
-
export function looseInterface(shape, params) {
|
|
536
|
-
const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
|
|
537
|
-
const def = {
|
|
538
|
-
type: "interface",
|
|
539
|
-
get optional() {
|
|
540
|
-
return cleaned.value.optional;
|
|
541
|
-
},
|
|
542
|
-
get shape() {
|
|
543
|
-
// return cleaned.value.shape;
|
|
544
|
-
const _shape = cleaned.value.shape;
|
|
545
|
-
util.assignProp(this, "shape", _shape);
|
|
546
|
-
return _shape;
|
|
547
|
-
},
|
|
548
|
-
catchall: unknown(),
|
|
549
|
-
...util.normalizeParams(params),
|
|
550
|
-
};
|
|
551
|
-
return new ZodInterface(def);
|
|
552
|
-
}
|
|
553
472
|
export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
|
|
554
473
|
core.$ZodObject.init(inst, def);
|
|
555
474
|
ZodType.init(inst, def);
|
|
556
|
-
inst
|
|
475
|
+
util.defineLazy(inst, "shape", () => {
|
|
476
|
+
return Object.fromEntries(Object.entries(inst._zod.def.shape));
|
|
477
|
+
});
|
|
557
478
|
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
558
479
|
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
559
480
|
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
@@ -562,22 +483,20 @@ export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def
|
|
|
562
483
|
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
563
484
|
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
|
|
564
485
|
inst.extend = (incoming) => {
|
|
565
|
-
|
|
566
|
-
return util.extendObjectLike(inst, incoming);
|
|
567
|
-
return util.extendObjectLike(inst, object(incoming));
|
|
486
|
+
return util.extend(inst, incoming);
|
|
568
487
|
};
|
|
569
|
-
inst.merge = (other) => util.
|
|
488
|
+
inst.merge = (other) => util.merge(inst, other);
|
|
570
489
|
inst.pick = (mask) => util.pick(inst, mask);
|
|
571
490
|
inst.omit = (mask) => util.omit(inst, mask);
|
|
572
|
-
inst.partial = (...args) => util.
|
|
573
|
-
inst.required = (...args) => util.
|
|
491
|
+
inst.partial = (...args) => util.partial(ZodOptional, inst, args[0]);
|
|
492
|
+
inst.required = (...args) => util.required(ZodNonOptional, inst, args[0]);
|
|
574
493
|
});
|
|
575
494
|
export function object(shape, params) {
|
|
576
495
|
const def = {
|
|
577
496
|
type: "object",
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
return
|
|
497
|
+
get shape() {
|
|
498
|
+
util.assignProp(this, "shape", { ...shape });
|
|
499
|
+
return this.shape;
|
|
581
500
|
},
|
|
582
501
|
...util.normalizeParams(params),
|
|
583
502
|
};
|
|
@@ -587,9 +506,9 @@ export function object(shape, params) {
|
|
|
587
506
|
export function strictObject(shape, params) {
|
|
588
507
|
return new ZodObject({
|
|
589
508
|
type: "object",
|
|
590
|
-
shape
|
|
591
|
-
|
|
592
|
-
return
|
|
509
|
+
get shape() {
|
|
510
|
+
util.assignProp(this, "shape", { ...shape });
|
|
511
|
+
return this.shape;
|
|
593
512
|
},
|
|
594
513
|
catchall: never(),
|
|
595
514
|
...util.normalizeParams(params),
|
|
@@ -599,39 +518,16 @@ export function strictObject(shape, params) {
|
|
|
599
518
|
export function looseObject(shape, params) {
|
|
600
519
|
return new ZodObject({
|
|
601
520
|
type: "object",
|
|
602
|
-
shape
|
|
603
|
-
|
|
604
|
-
return
|
|
521
|
+
get shape() {
|
|
522
|
+
util.assignProp(this, "shape", { ...shape });
|
|
523
|
+
return this.shape;
|
|
605
524
|
},
|
|
606
525
|
catchall: unknown(),
|
|
607
526
|
...util.normalizeParams(params),
|
|
608
527
|
});
|
|
609
528
|
}
|
|
610
|
-
export function
|
|
611
|
-
|
|
612
|
-
return util.mergeObjectLike(schema, shape);
|
|
613
|
-
if (schema instanceof ZodInterface) {
|
|
614
|
-
return util.mergeObjectLike(schema, _interface(shape));
|
|
615
|
-
}
|
|
616
|
-
if (schema instanceof ZodObject)
|
|
617
|
-
return util.mergeObjectLike(schema, object(shape));
|
|
618
|
-
return util.extend(schema, shape);
|
|
619
|
-
}
|
|
620
|
-
export function merge(a, b) {
|
|
621
|
-
return util.mergeObjectLike(a, b);
|
|
622
|
-
}
|
|
623
|
-
export function pick(schema, mask) {
|
|
624
|
-
// const picked = util.pick(schema, mask);
|
|
625
|
-
return util.pick(schema, mask);
|
|
626
|
-
}
|
|
627
|
-
export function omit(schema, mask) {
|
|
628
|
-
return util.omit(schema, mask);
|
|
629
|
-
}
|
|
630
|
-
export function partial(schema, mask) {
|
|
631
|
-
return util.partialObjectLike(ZodOptional, schema, mask);
|
|
632
|
-
}
|
|
633
|
-
export function required(schema, mask) {
|
|
634
|
-
return util.requiredObjectLike(ZodNonOptional, schema, mask);
|
|
529
|
+
export function partial(shape) {
|
|
530
|
+
return shape;
|
|
635
531
|
}
|
|
636
532
|
export const ZodUnion = /*@__PURE__*/ core.$constructor("ZodUnion", (inst, def) => {
|
|
637
533
|
core.$ZodUnion.init(inst, def);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.20250504T215252",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Colin McDonnell <zod@colinhacks.com>",
|
|
6
6
|
"description": "TypeScript-first schema declaration and validation library with static type inference",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@zod/core": "0.
|
|
73
|
+
"@zod/core": "0.11.0"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"clean": "rm -rf dist",
|