-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathschemas.ts
More file actions
2746 lines (2480 loc) · 95.9 KB
/
schemas.ts
File metadata and controls
2746 lines (2480 loc) · 95.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as core from "../core/index.js";
import { util } from "../core/index.js";
import * as processors from "../core/json-schema-processors.js";
import type { StandardSchemaWithJSONProps } from "../core/standard-schema.js";
import { createStandardJSONSchemaMethod, createToJSONSchemaMethod } from "../core/to-json-schema.js";
import * as checks from "./checks.js";
import * as parse from "./parse.js";
// Lazy-bind builder methods.
//
// Builder methods (`.optional`, `.array`, `.refine`, ...) live as
// non-enumerable getters on each concrete schema constructor's
// prototype. On first access from an instance the getter allocates
// `fn.bind(this)` and caches it as an own property on that instance,
// so detached usage (`const m = schema.optional; m()`) still works
// and the per-instance allocation only happens for methods actually
// touched.
//
// One install per (prototype, group), memoized by `_installedGroups`.
const _installedGroups = /* @__PURE__ */ new WeakMap<object, Set<string>>();
/**
* Methods of `T` reshaped so each body has `this: T` and matches the
* declared (args, return) of the corresponding interface method. Allows
* us to type-check inline method-shorthand bodies against the
* `ZodType` / `_ZodString` / etc. interface declarations.
*/
type _LazyMethodsOf<T> = Partial<{
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (this: T, ...args: A) => R : never;
}>;
function _installLazyMethods<T extends object>(inst: T, group: string, methods: _LazyMethodsOf<T>): void {
const proto = Object.getPrototypeOf(inst);
let installed = _installedGroups.get(proto);
if (!installed) {
installed = new Set();
_installedGroups.set(proto, installed);
}
if (installed.has(group)) return;
installed.add(group);
for (const key in methods) {
const fn = methods[key]!;
Object.defineProperty(proto, key, {
configurable: true,
enumerable: false,
get(this: any) {
const bound = fn.bind(this);
Object.defineProperty(this, key, {
configurable: true,
writable: true,
enumerable: true,
value: bound,
});
return bound;
},
set(this: any, v: unknown) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
enumerable: true,
value: v,
});
},
});
}
}
///////////////////////////////////////////
///////////////////////////////////////////
//////////// ////////////
//////////// ZodType ////////////
//////////// ////////////
///////////////////////////////////////////
///////////////////////////////////////////
export type ZodStandardSchemaWithJSON<T> = StandardSchemaWithJSONProps<core.input<T>, core.output<T>>;
export interface ZodType<
out Output = unknown,
out Input = unknown,
out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
> extends core.$ZodType<Output, Input, Internals> {
def: Internals["def"];
type: Internals["def"]["type"];
/** @deprecated Use `.def` instead. */
_def: Internals["def"];
/** @deprecated Use `z.output<typeof schema>` instead. */
_output: Internals["output"];
/** @deprecated Use `z.input<typeof schema>` instead. */
_input: Internals["input"];
"~standard": ZodStandardSchemaWithJSON<this>;
/** Converts this schema to a JSON Schema representation. */
toJSONSchema(params?: core.ToJSONSchemaParams): core.ZodStandardJSONSchemaPayload<this>;
// base methods
check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
with(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
clone(def?: Internals["def"], params?: { parent: boolean }): this;
register<R extends core.$ZodRegistry>(
registry: R,
...meta: this extends R["_schema"]
? undefined extends R["_meta"]
? [core.$replace<R["_meta"], this>?]
: [core.$replace<R["_meta"], this>]
: ["Incompatible schema"]
): this;
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(
value?: T
): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
// parsing
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): parse.ZodSafeParseResult<core.output<this>>;
parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
/** Sync when possible; Promise on async refinement. Sync `transform` / `refine` / checks before the first async step run twice on the async fallback — prefer `parseAsync` for non-idempotent steps. Once a schema has been observed as async, subsequent calls skip the sync attempt and return a Promise even for inputs that would resolve synchronously (matters for unions or preprocess-gated async branches). */
parseMaybeAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.util.MaybeAsync<core.output<this>>;
/** Safe variant of `parseMaybeAsync`. Same side-effect caveat. */
safeParseMaybeAsync(
data: unknown,
params?: core.ParseContext<core.$ZodIssue>
): core.util.MaybeAsync<parse.ZodSafeParseResult<core.output<this>>>;
safeParseAsync(
data: unknown,
params?: core.ParseContext<core.$ZodIssue>
): Promise<parse.ZodSafeParseResult<core.output<this>>>;
spa: (
data: unknown,
params?: core.ParseContext<core.$ZodIssue>
) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
// encoding/decoding
encode(data: core.output<this>, params?: core.ParseContext<core.$ZodIssue>): core.input<this>;
decode(data: core.input<this>, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
encodeAsync(data: core.output<this>, params?: core.ParseContext<core.$ZodIssue>): Promise<core.input<this>>;
decodeAsync(data: core.input<this>, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
safeEncode(
data: core.output<this>,
params?: core.ParseContext<core.$ZodIssue>
): parse.ZodSafeParseResult<core.input<this>>;
safeDecode(
data: core.input<this>,
params?: core.ParseContext<core.$ZodIssue>
): parse.ZodSafeParseResult<core.output<this>>;
safeEncodeAsync(
data: core.output<this>,
params?: core.ParseContext<core.$ZodIssue>
): Promise<parse.ZodSafeParseResult<core.input<this>>>;
safeDecodeAsync(
data: core.input<this>,
params?: core.ParseContext<core.$ZodIssue>
): Promise<parse.ZodSafeParseResult<core.output<this>>>;
// refinements
refine<Ch extends (arg: core.output<this>) => unknown | Promise<unknown>>(
check: Ch,
params?: string | core.$ZodCustomParams
): Ch extends (arg: any) => arg is infer R ? this & ZodType<R, core.input<this>> : this;
superRefine(
refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>,
params?: core.$ZodSuperRefineParams
): this;
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
// wrappers
optional(): ZodOptional<this>;
exactOptional(): ZodExactOptional<this>;
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
nullable(): ZodNullable<this>;
nullish(): ZodOptional<ZodNullable<this>>;
default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>;
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
prefault(def: () => core.input<this>): ZodPrefault<this>;
prefault(def: core.input<this>): ZodPrefault<this>;
array(): ZodArray<this>;
or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
transform<NewOut>(
transform: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>
): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
catch(def: core.output<this>): ZodCatch<this>;
catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
pipe<T extends core.$ZodType<any, core.output<this>>>(
target: T | core.$ZodType<any, core.output<this>>
): ZodPipe<this, T>;
readonly(): ZodReadonly<this>;
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
describe(description: string): this;
description?: string;
/** Returns the metadata associated with this instance in `z.globalRegistry` */
meta(): core.$replace<core.GlobalMeta, this> | undefined;
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
meta(data: core.$replace<core.GlobalMeta, this>): this;
// helpers
/** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
*
* ```ts
* const schema = z.string().optional();
* const isOptional = schema.safeParse(undefined).success; // true
* ```
*/
isOptional(): boolean;
/**
* @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
*
* ```ts
* const schema = z.string().nullable();
* const isNullable = schema.safeParse(null).success; // true
* ```
*/
isNullable(): boolean;
apply<T>(fn: (schema: this) => T): T;
}
export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$ZodTypeInternals>
extends ZodType<any, any, Internals> {}
export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
core.$ZodType.init(inst, def);
Object.assign(inst["~standard"], {
jsonSchema: {
input: createStandardJSONSchemaMethod(inst, "input"),
output: createStandardJSONSchemaMethod(inst, "output"),
},
});
inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
inst.def = def;
inst.type = def.type;
Object.defineProperty(inst, "_def", { value: def });
// Parse-family is intentionally kept as per-instance closures: these are
// the hot path AND the most-detached methods (`arr.map(schema.parse)`,
// `const { parse } = schema`, etc.). Eager closures here mean callers pay
// ~12 closure allocations per schema but get monomorphic call sites and
// detached usage that "just works".
inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
inst.parseMaybeAsync = (data, params) => parse.parseMaybeAsync(inst, data, params, { callee: inst.parseMaybeAsync });
inst.safeParseMaybeAsync = (data, params) => parse.safeParseMaybeAsync(inst, data, params);
inst.spa = inst.safeParseAsync;
inst.encode = (data, params) => parse.encode(inst, data, params);
inst.decode = (data, params) => parse.decode(inst, data, params);
inst.encodeAsync = async (data, params) => parse.encodeAsync(inst, data, params);
inst.decodeAsync = async (data, params) => parse.decodeAsync(inst, data, params);
inst.safeEncode = (data, params) => parse.safeEncode(inst, data, params);
inst.safeDecode = (data, params) => parse.safeDecode(inst, data, params);
inst.safeEncodeAsync = async (data, params) => parse.safeEncodeAsync(inst, data, params);
inst.safeDecodeAsync = async (data, params) => parse.safeDecodeAsync(inst, data, params);
// All builder methods are placed on the internal prototype as lazy-bind
// getters. On first access per-instance, a bound thunk is allocated and
// cached as an own property; subsequent accesses skip the getter. This
// means: no per-instance allocation for unused methods, full
// detachability preserved (`const m = schema.optional; m()` works), and
// shared underlying function references across all instances.
_installLazyMethods(inst, "ZodType", {
check(...chks) {
const def = this.def;
return this.clone(
util.mergeDefs(def, {
checks: [
...(def.checks ?? []),
...chks.map((ch) =>
typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
),
],
}),
{ parent: true }
);
},
with(...chks) {
return this.check(...chks);
},
clone(def, params) {
return core.clone(this, def, params);
},
brand() {
return this;
},
register(reg, meta) {
reg.add(this, meta);
return this;
},
refine(check, params) {
return this.check(refine(check, params));
},
superRefine(refinement, params) {
return this.check(superRefine(refinement, params));
},
overwrite(fn) {
return this.check(checks.overwrite(fn));
},
optional() {
return optional(this);
},
exactOptional() {
return exactOptional(this);
},
nullable() {
return nullable(this);
},
nullish() {
return optional(nullable(this));
},
nonoptional(params) {
return nonoptional(this, params);
},
array() {
return array(this);
},
or(arg) {
return union([this, arg]);
},
and(arg) {
return intersection(this, arg);
},
transform(tx) {
return pipe(this, transform(tx));
},
default(d) {
return _default(this, d);
},
prefault(d) {
return prefault(this, d);
},
catch(params) {
return _catch(this, params);
},
pipe(target) {
return pipe(this, target);
},
readonly() {
return readonly(this);
},
describe(description) {
const cl = this.clone();
core.globalRegistry.add(cl, { description });
return cl;
},
meta(...args: any[]): any {
// overloaded: meta() returns the registered metadata, meta(data)
// returns a clone with `data` registered. The mapped type picks
// up the second overload, so we accept variadic any-args and
// return `any` to satisfy both at runtime.
if (args.length === 0) return core.globalRegistry.get(this);
const cl = this.clone();
core.globalRegistry.add(cl, args[0]);
return cl;
},
isOptional() {
return this.safeParse(undefined).success;
},
isNullable() {
return this.safeParse(null).success;
},
apply(fn) {
return fn(this);
},
});
Object.defineProperty(inst, "description", {
get() {
return core.globalRegistry.get(inst)?.description;
},
configurable: true,
});
return inst;
});
// ZodString
export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$ZodStringInternals<unknown>>
extends _ZodType<T> {
format: string | null;
minLength: number | null;
maxLength: number | null;
// miscellaneous checks
regex(regex: RegExp, params?: string | core.$ZodCheckRegexParams): this;
includes(value: string, params?: string | core.$ZodCheckIncludesParams): this;
startsWith(value: string, params?: string | core.$ZodCheckStartsWithParams): this;
endsWith(value: string, params?: string | core.$ZodCheckEndsWithParams): this;
min(minLength: number, params?: string | core.$ZodCheckMinLengthParams): this;
max(maxLength: number, params?: string | core.$ZodCheckMaxLengthParams): this;
length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
nonempty(params?: string | core.$ZodCheckMinLengthParams): this;
lowercase(params?: string | core.$ZodCheckLowerCaseParams): this;
uppercase(params?: string | core.$ZodCheckUpperCaseParams): this;
// transforms
trim(): this;
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
toLowerCase(): this;
toUpperCase(): this;
slugify(): this;
}
/** @internal */
export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$constructor("_ZodString", (inst, def) => {
core.$ZodString.init(inst, def);
ZodType.init(inst, def);
inst._zod.processJSONSchema = (ctx, json, params) => processors.stringProcessor(inst, ctx, json, params);
const bag = inst._zod.bag;
inst.format = bag.format ?? null;
inst.minLength = bag.minimum ?? null;
inst.maxLength = bag.maximum ?? null;
_installLazyMethods(inst, "_ZodString", {
regex(...args) {
return this.check((checks.regex as any)(...args));
},
includes(...args) {
return this.check((checks.includes as any)(...args));
},
startsWith(...args) {
return this.check((checks.startsWith as any)(...args));
},
endsWith(...args) {
return this.check((checks.endsWith as any)(...args));
},
min(...args) {
return this.check((checks.minLength as any)(...args));
},
max(...args) {
return this.check((checks.maxLength as any)(...args));
},
length(...args) {
return this.check((checks.length as any)(...args));
},
nonempty(...args) {
return this.check((checks.minLength as any)(1, ...args));
},
lowercase(params) {
return this.check(checks.lowercase(params));
},
uppercase(params) {
return this.check(checks.uppercase(params));
},
trim() {
return this.check(checks.trim());
},
normalize(...args) {
return this.check(checks.normalize(...args));
},
toLowerCase() {
return this.check(checks.toLowerCase());
},
toUpperCase() {
return this.check(checks.toUpperCase());
},
slugify() {
return this.check(checks.slugify());
},
});
});
export interface ZodString extends _ZodString<core.$ZodStringInternals<string>> {
// string format checks
/** @deprecated Use `z.email()` instead. */
email(params?: string | core.$ZodCheckEmailParams): this;
/** @deprecated Use `z.url()` instead. */
url(params?: string | core.$ZodCheckURLParams): this;
/** @deprecated Use `z.jwt()` instead. */
jwt(params?: string | core.$ZodCheckJWTParams): this;
/** @deprecated Use `z.emoji()` instead. */
emoji(params?: string | core.$ZodCheckEmojiParams): this;
/** @deprecated Use `z.guid()` instead. */
guid(params?: string | core.$ZodCheckGUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuid(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv4(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv6(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.uuid()` instead. */
uuidv7(params?: string | core.$ZodCheckUUIDParams): this;
/** @deprecated Use `z.nanoid()` instead. */
nanoid(params?: string | core.$ZodCheckNanoIDParams): this;
/** @deprecated Use `z.guid()` instead. */
guid(params?: string | core.$ZodCheckGUIDParams): this;
/**
* @deprecated CUID v1 is deprecated by its authors due to information leakage
* (timestamps embedded in the id). Use `z.cuid2()` instead.
* See https://github.com/paralleldrive/cuid.
*/
cuid(params?: string | core.$ZodCheckCUIDParams): this;
/** @deprecated Use `z.cuid2()` instead. */
cuid2(params?: string | core.$ZodCheckCUID2Params): this;
/** @deprecated Use `z.ulid()` instead. */
ulid(params?: string | core.$ZodCheckULIDParams): this;
/** @deprecated Use `z.base64()` instead. */
base64(params?: string | core.$ZodCheckBase64Params): this;
/** @deprecated Use `z.base64url()` instead. */
base64url(params?: string | core.$ZodCheckBase64URLParams): this;
// /** @deprecated Use `z.jsonString()` instead. */
// jsonString(params?: string | core.$ZodCheckJSONStringParams): this;
/** @deprecated Use `z.xid()` instead. */
xid(params?: string | core.$ZodCheckXIDParams): this;
/** @deprecated Use `z.ksuid()` instead. */
ksuid(params?: string | core.$ZodCheckKSUIDParams): this;
// /** @deprecated Use `z.ipv4()` or `z.ipv6()` instead. */
// ip(params?: string | (core.$ZodCheckIPv4Params & { version?: "v4" | "v6" })): ZodUnion<[this, this]>;
/** @deprecated Use `z.ipv4()` instead. */
ipv4(params?: string | core.$ZodCheckIPv4Params): this;
/** @deprecated Use `z.ipv6()` instead. */
ipv6(params?: string | core.$ZodCheckIPv6Params): this;
/** @deprecated Use `z.cidrv4()` instead. */
cidrv4(params?: string | core.$ZodCheckCIDRv4Params): this;
/** @deprecated Use `z.cidrv6()` instead. */
cidrv6(params?: string | core.$ZodCheckCIDRv6Params): this;
/** @deprecated Use `z.e164()` instead. */
e164(params?: string | core.$ZodCheckE164Params): this;
// ISO 8601 checks
/** @deprecated Use `z.iso.datetime()` instead. */
datetime(params?: string | core.$ZodCheckISODateTimeParams): this;
/** @deprecated Use `z.iso.date()` instead. */
date(params?: string | core.$ZodCheckISODateParams): this;
/** @deprecated Use `z.iso.time()` instead. */
time(
params?:
| string
// | {
// message?: string | undefined;
// precision?: number | null;
// }
| core.$ZodCheckISOTimeParams
): this;
/** @deprecated Use `z.iso.duration()` instead. */
duration(params?: string | core.$ZodCheckISODurationParams): this;
}
export const ZodString: core.$constructor<ZodString> = /*@__PURE__*/ core.$constructor("ZodString", (inst, def) => {
core.$ZodString.init(inst, def);
_ZodString.init(inst, def);
inst.email = (params) => inst.check(core._email(ZodEmail, params));
inst.url = (params) => inst.check(core._url(ZodURL, params));
inst.jwt = (params) => inst.check(core._jwt(ZodJWT, params));
inst.emoji = (params) => inst.check(core._emoji(ZodEmoji, params));
inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
inst.uuid = (params) => inst.check(core._uuid(ZodUUID, params));
inst.uuidv4 = (params) => inst.check(core._uuidv4(ZodUUID, params));
inst.uuidv6 = (params) => inst.check(core._uuidv6(ZodUUID, params));
inst.uuidv7 = (params) => inst.check(core._uuidv7(ZodUUID, params));
inst.nanoid = (params) => inst.check(core._nanoid(ZodNanoID, params));
inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
inst.cuid = (params) => inst.check(core._cuid(ZodCUID, params));
inst.cuid2 = (params) => inst.check(core._cuid2(ZodCUID2, params));
inst.ulid = (params) => inst.check(core._ulid(ZodULID, params));
inst.base64 = (params) => inst.check(core._base64(ZodBase64, params));
inst.base64url = (params) => inst.check(core._base64url(ZodBase64URL, params));
inst.xid = (params) => inst.check(core._xid(ZodXID, params));
inst.ksuid = (params) => inst.check(core._ksuid(ZodKSUID, params));
inst.ipv4 = (params) => inst.check(core._ipv4(ZodIPv4, params));
inst.ipv6 = (params) => inst.check(core._ipv6(ZodIPv6, params));
inst.cidrv4 = (params) => inst.check(core._cidrv4(ZodCIDRv4, params));
inst.cidrv6 = (params) => inst.check(core._cidrv6(ZodCIDRv6, params));
inst.e164 = (params) => inst.check(core._e164(ZodE164, params));
// iso
inst.datetime = (params) => inst.check(core._isoDateTime(ZodISODateTime, params as any));
inst.date = (params) => inst.check(core._isoDate(ZodISODate, params as any));
inst.time = (params) => inst.check(core._isoTime(ZodISOTime, params as any));
inst.duration = (params) => inst.check(core._isoDuration(ZodISODuration, params as any));
});
export function string(params?: string | core.$ZodStringParams): ZodString;
export function string<T extends string>(params?: string | core.$ZodStringParams): core.$ZodType<T, T>;
export function string(params?: string | core.$ZodStringParams): ZodString {
return core._string(ZodString, params);
}
// ZodStringFormat
export interface ZodStringFormat<Format extends string = string>
extends _ZodString<core.$ZodStringFormatInternals<Format>> {}
export const ZodStringFormat: core.$constructor<ZodStringFormat> = /*@__PURE__*/ core.$constructor(
"ZodStringFormat",
(inst, def) => {
core.$ZodStringFormat.init(inst, def);
_ZodString.init(inst, def);
}
);
//////////////////////////////////////////////
//////////////////////////////////////////////
////////// //////////
////////// ZodISODateTime //////////
////////// //////////
//////////////////////////////////////////////
//////////////////////////////////////////////
export interface ZodISODateTime extends ZodStringFormat {
_zod: core.$ZodISODateTimeInternals;
}
export const ZodISODateTime: core.$constructor<ZodISODateTime> = /*@__PURE__*/ core.$constructor(
"ZodISODateTime",
(inst, def) => {
core.$ZodISODateTime.init(inst, def);
ZodStringFormat.init(inst, def);
}
);
//////////////////////////////////////////
//////////////////////////////////////////
////////// //////////
////////// ZodISODate //////////
////////// //////////
//////////////////////////////////////////
//////////////////////////////////////////
export interface ZodISODate extends ZodStringFormat {
_zod: core.$ZodISODateInternals;
}
export const ZodISODate: core.$constructor<ZodISODate> = /*@__PURE__*/ core.$constructor("ZodISODate", (inst, def) => {
core.$ZodISODate.init(inst, def);
ZodStringFormat.init(inst, def);
});
//////////////////////////////////////////
//////////////////////////////////////////
////////// //////////
////////// ZodISOTime //////////
////////// //////////
//////////////////////////////////////////
//////////////////////////////////////////
export interface ZodISOTime extends ZodStringFormat {
_zod: core.$ZodISOTimeInternals;
}
export const ZodISOTime: core.$constructor<ZodISOTime> = /*@__PURE__*/ core.$constructor("ZodISOTime", (inst, def) => {
core.$ZodISOTime.init(inst, def);
ZodStringFormat.init(inst, def);
});
//////////////////////////////////////////////
//////////////////////////////////////////////
////////// //////////
////////// ZodISODuration //////////
////////// //////////
//////////////////////////////////////////////
//////////////////////////////////////////////
export interface ZodISODuration extends ZodStringFormat {
_zod: core.$ZodISODurationInternals;
}
export const ZodISODuration: core.$constructor<ZodISODuration> = /*@__PURE__*/ core.$constructor(
"ZodISODuration",
(inst, def) => {
core.$ZodISODuration.init(inst, def);
ZodStringFormat.init(inst, def);
}
);
// ZodEmail
export interface ZodEmail extends ZodStringFormat<"email"> {
_zod: core.$ZodEmailInternals;
}
export const ZodEmail: core.$constructor<ZodEmail> = /*@__PURE__*/ core.$constructor("ZodEmail", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodEmail.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function email(params?: string | core.$ZodEmailParams): ZodEmail {
return core._email(ZodEmail, params);
}
// ZodGUID
export interface ZodGUID extends ZodStringFormat<"guid"> {
_zod: core.$ZodGUIDInternals;
}
export const ZodGUID: core.$constructor<ZodGUID> = /*@__PURE__*/ core.$constructor("ZodGUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodGUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function guid(params?: string | core.$ZodGUIDParams): ZodGUID {
return core._guid(ZodGUID, params);
}
// ZodUUID
export interface ZodUUID extends ZodStringFormat<"uuid"> {
_zod: core.$ZodUUIDInternals;
}
export const ZodUUID: core.$constructor<ZodUUID> = /*@__PURE__*/ core.$constructor("ZodUUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodUUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function uuid(params?: string | core.$ZodUUIDParams): ZodUUID {
return core._uuid(ZodUUID, params);
}
export function uuidv4(params?: string | core.$ZodUUIDv4Params): ZodUUID {
return core._uuidv4(ZodUUID, params);
}
// ZodUUIDv6
export function uuidv6(params?: string | core.$ZodUUIDv6Params): ZodUUID {
return core._uuidv6(ZodUUID, params);
}
// ZodUUIDv7
export function uuidv7(params?: string | core.$ZodUUIDv7Params): ZodUUID {
return core._uuidv7(ZodUUID, params);
}
// ZodURL
export interface ZodURL extends ZodStringFormat<"url"> {
_zod: core.$ZodURLInternals;
}
export const ZodURL: core.$constructor<ZodURL> = /*@__PURE__*/ core.$constructor("ZodURL", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodURL.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function url(params?: string | core.$ZodURLParams): ZodURL {
return core._url(ZodURL, params);
}
export function httpUrl(params?: string | Omit<core.$ZodURLParams, "protocol" | "hostname">): ZodURL {
return core._url(ZodURL, {
protocol: core.regexes.httpProtocol,
hostname: core.regexes.domain,
...util.normalizeParams(params),
});
}
// ZodEmoji
export interface ZodEmoji extends ZodStringFormat<"emoji"> {
_zod: core.$ZodEmojiInternals;
}
export const ZodEmoji: core.$constructor<ZodEmoji> = /*@__PURE__*/ core.$constructor("ZodEmoji", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodEmoji.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function emoji(params?: string | core.$ZodEmojiParams): ZodEmoji {
return core._emoji(ZodEmoji, params);
}
// ZodNanoID
export interface ZodNanoID extends ZodStringFormat<"nanoid"> {
_zod: core.$ZodNanoIDInternals;
}
export const ZodNanoID: core.$constructor<ZodNanoID> = /*@__PURE__*/ core.$constructor("ZodNanoID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodNanoID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function nanoid(params?: string | core.$ZodNanoIDParams): ZodNanoID {
return core._nanoid(ZodNanoID, params);
}
// ZodCUID
/**
* @deprecated CUID v1 is deprecated by its authors due to information leakage
* (timestamps embedded in the id). Use {@link ZodCUID2} instead.
* See https://github.com/paralleldrive/cuid.
*/
export interface ZodCUID extends ZodStringFormat<"cuid"> {
_zod: core.$ZodCUIDInternals;
}
/**
* @deprecated CUID v1 is deprecated by its authors due to information leakage
* (timestamps embedded in the id). Use {@link ZodCUID2} instead.
* See https://github.com/paralleldrive/cuid.
*/
export const ZodCUID: core.$constructor<ZodCUID> = /*@__PURE__*/ core.$constructor("ZodCUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
/**
* Validates a CUID v1 string.
*
* @deprecated CUID v1 is deprecated by its authors due to information leakage
* (timestamps embedded in the id). Use {@link cuid2 | `z.cuid2()`} instead.
* See https://github.com/paralleldrive/cuid.
*/
export function cuid(params?: string | core.$ZodCUIDParams): ZodCUID {
return core._cuid(ZodCUID, params);
}
// ZodCUID2
export interface ZodCUID2 extends ZodStringFormat<"cuid2"> {
_zod: core.$ZodCUID2Internals;
}
export const ZodCUID2: core.$constructor<ZodCUID2> = /*@__PURE__*/ core.$constructor("ZodCUID2", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodCUID2.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cuid2(params?: string | core.$ZodCUID2Params): ZodCUID2 {
return core._cuid2(ZodCUID2, params);
}
// ZodULID
export interface ZodULID extends ZodStringFormat<"ulid"> {
_zod: core.$ZodULIDInternals;
}
export const ZodULID: core.$constructor<ZodULID> = /*@__PURE__*/ core.$constructor("ZodULID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodULID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ulid(params?: string | core.$ZodULIDParams): ZodULID {
return core._ulid(ZodULID, params);
}
// ZodXID
export interface ZodXID extends ZodStringFormat<"xid"> {
_zod: core.$ZodXIDInternals;
}
export const ZodXID: core.$constructor<ZodXID> = /*@__PURE__*/ core.$constructor("ZodXID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodXID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function xid(params?: string | core.$ZodXIDParams): ZodXID {
return core._xid(ZodXID, params);
}
// ZodKSUID
export interface ZodKSUID extends ZodStringFormat<"ksuid"> {
_zod: core.$ZodKSUIDInternals;
}
export const ZodKSUID: core.$constructor<ZodKSUID> = /*@__PURE__*/ core.$constructor("ZodKSUID", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodKSUID.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ksuid(params?: string | core.$ZodKSUIDParams): ZodKSUID {
return core._ksuid(ZodKSUID, params);
}
// ZodIP
// export interface ZodIP extends ZodStringFormat<"ip"> {
// _zod: core.$ZodIPInternals;
// }
// export const ZodIP: core.$constructor<ZodIP> = /*@__PURE__*/ core.$constructor("ZodIP", (inst, def) => {
// // ZodStringFormat.init(inst, def);
// core.$ZodIP.init(inst, def);
// ZodStringFormat.init(inst, def);
// });
// export function ip(params?: string | core.$ZodIPParams): ZodIP {
// return core._ip(ZodIP, params);
// }
// ZodIPv4
export interface ZodIPv4 extends ZodStringFormat<"ipv4"> {
_zod: core.$ZodIPv4Internals;
}
export const ZodIPv4: core.$constructor<ZodIPv4> = /*@__PURE__*/ core.$constructor("ZodIPv4", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodIPv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ipv4(params?: string | core.$ZodIPv4Params): ZodIPv4 {
return core._ipv4(ZodIPv4, params);
}
// ZodMAC
export interface ZodMAC extends ZodStringFormat<"mac"> {
_zod: core.$ZodMACInternals;
}
export const ZodMAC: core.$constructor<ZodMAC> = /*@__PURE__*/ core.$constructor("ZodMAC", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodMAC.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function mac(params?: string | core.$ZodMACParams): ZodMAC {
return core._mac(ZodMAC, params);
}
// ZodIPv6
export interface ZodIPv6 extends ZodStringFormat<"ipv6"> {
_zod: core.$ZodIPv6Internals;
}
export const ZodIPv6: core.$constructor<ZodIPv6> = /*@__PURE__*/ core.$constructor("ZodIPv6", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodIPv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function ipv6(params?: string | core.$ZodIPv6Params): ZodIPv6 {
return core._ipv6(ZodIPv6, params);
}
// ZodCIDRv4
export interface ZodCIDRv4 extends ZodStringFormat<"cidrv4"> {
_zod: core.$ZodCIDRv4Internals;
}
export const ZodCIDRv4: core.$constructor<ZodCIDRv4> = /*@__PURE__*/ core.$constructor("ZodCIDRv4", (inst, def) => {
core.$ZodCIDRv4.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cidrv4(params?: string | core.$ZodCIDRv4Params): ZodCIDRv4 {
return core._cidrv4(ZodCIDRv4, params);
}
// ZodCIDRv6
export interface ZodCIDRv6 extends ZodStringFormat<"cidrv6"> {
_zod: core.$ZodCIDRv6Internals;
}
export const ZodCIDRv6: core.$constructor<ZodCIDRv6> = /*@__PURE__*/ core.$constructor("ZodCIDRv6", (inst, def) => {
core.$ZodCIDRv6.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function cidrv6(params?: string | core.$ZodCIDRv6Params): ZodCIDRv6 {
return core._cidrv6(ZodCIDRv6, params);
}
// ZodBase64
export interface ZodBase64 extends ZodStringFormat<"base64"> {
_zod: core.$ZodBase64Internals;
}
export const ZodBase64: core.$constructor<ZodBase64> = /*@__PURE__*/ core.$constructor("ZodBase64", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodBase64.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function base64(params?: string | core.$ZodBase64Params): ZodBase64 {
return core._base64(ZodBase64, params);
}
// ZodBase64URL
export interface ZodBase64URL extends ZodStringFormat<"base64url"> {
_zod: core.$ZodBase64URLInternals;
}
export const ZodBase64URL: core.$constructor<ZodBase64URL> = /*@__PURE__*/ core.$constructor(
"ZodBase64URL",
(inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodBase64URL.init(inst, def);
ZodStringFormat.init(inst, def);
}
);
export function base64url(params?: string | core.$ZodBase64URLParams): ZodBase64URL {
return core._base64url(ZodBase64URL, params);
}
// ZodE164
export interface ZodE164 extends ZodStringFormat<"e164"> {
_zod: core.$ZodE164Internals;
}
export const ZodE164: core.$constructor<ZodE164> = /*@__PURE__*/ core.$constructor("ZodE164", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodE164.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function e164(params?: string | core.$ZodE164Params): ZodE164 {
return core._e164(ZodE164, params);
}
// ZodJWT
export interface ZodJWT extends ZodStringFormat<"jwt"> {
_zod: core.$ZodJWTInternals;
}
export const ZodJWT: core.$constructor<ZodJWT> = /*@__PURE__*/ core.$constructor("ZodJWT", (inst, def) => {
// ZodStringFormat.init(inst, def);
core.$ZodJWT.init(inst, def);
ZodStringFormat.init(inst, def);
});
export function jwt(params?: string | core.$ZodJWTParams): ZodJWT {
return core._jwt(ZodJWT, params);
}
// ZodCustomStringFormat
export interface ZodCustomStringFormat<Format extends string = string>
extends ZodStringFormat<Format>,
core.$ZodCustomStringFormat<Format> {
_zod: core.$ZodCustomStringFormatInternals<Format>;
"~standard": ZodStandardSchemaWithJSON<this>;
}
export const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat> = /*@__PURE__*/ core.$constructor(
"ZodCustomStringFormat",
(inst, def) => {