| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222 |
- "use strict";
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- var desc = Object.getOwnPropertyDescriptor(m, k);
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
- desc = { enumerable: true, get: function() { return m[k]; } };
- }
- Object.defineProperty(o, k2, desc);
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.TimePrecision = void 0;
- exports._string = _string;
- exports._coercedString = _coercedString;
- exports._email = _email;
- exports._guid = _guid;
- exports._uuid = _uuid;
- exports._uuidv4 = _uuidv4;
- exports._uuidv6 = _uuidv6;
- exports._uuidv7 = _uuidv7;
- exports._url = _url;
- exports._emoji = _emoji;
- exports._nanoid = _nanoid;
- exports._cuid = _cuid;
- exports._cuid2 = _cuid2;
- exports._ulid = _ulid;
- exports._xid = _xid;
- exports._ksuid = _ksuid;
- exports._ipv4 = _ipv4;
- exports._ipv6 = _ipv6;
- exports._mac = _mac;
- exports._cidrv4 = _cidrv4;
- exports._cidrv6 = _cidrv6;
- exports._base64 = _base64;
- exports._base64url = _base64url;
- exports._e164 = _e164;
- exports._jwt = _jwt;
- exports._isoDateTime = _isoDateTime;
- exports._isoDate = _isoDate;
- exports._isoTime = _isoTime;
- exports._isoDuration = _isoDuration;
- exports._number = _number;
- exports._coercedNumber = _coercedNumber;
- exports._int = _int;
- exports._float32 = _float32;
- exports._float64 = _float64;
- exports._int32 = _int32;
- exports._uint32 = _uint32;
- exports._boolean = _boolean;
- exports._coercedBoolean = _coercedBoolean;
- exports._bigint = _bigint;
- exports._coercedBigint = _coercedBigint;
- exports._int64 = _int64;
- exports._uint64 = _uint64;
- exports._symbol = _symbol;
- exports._undefined = _undefined;
- exports._null = _null;
- exports._any = _any;
- exports._unknown = _unknown;
- exports._never = _never;
- exports._void = _void;
- exports._date = _date;
- exports._coercedDate = _coercedDate;
- exports._nan = _nan;
- exports._lt = _lt;
- exports._lte = _lte;
- exports._max = _lte;
- exports._lte = _lte;
- exports._max = _lte;
- exports._gt = _gt;
- exports._gte = _gte;
- exports._min = _gte;
- exports._gte = _gte;
- exports._min = _gte;
- exports._positive = _positive;
- exports._negative = _negative;
- exports._nonpositive = _nonpositive;
- exports._nonnegative = _nonnegative;
- exports._multipleOf = _multipleOf;
- exports._maxSize = _maxSize;
- exports._minSize = _minSize;
- exports._size = _size;
- exports._maxLength = _maxLength;
- exports._minLength = _minLength;
- exports._length = _length;
- exports._regex = _regex;
- exports._lowercase = _lowercase;
- exports._uppercase = _uppercase;
- exports._includes = _includes;
- exports._startsWith = _startsWith;
- exports._endsWith = _endsWith;
- exports._property = _property;
- exports._mime = _mime;
- exports._overwrite = _overwrite;
- exports._normalize = _normalize;
- exports._trim = _trim;
- exports._toLowerCase = _toLowerCase;
- exports._toUpperCase = _toUpperCase;
- exports._slugify = _slugify;
- exports._array = _array;
- exports._union = _union;
- exports._xor = _xor;
- exports._discriminatedUnion = _discriminatedUnion;
- exports._intersection = _intersection;
- exports._tuple = _tuple;
- exports._record = _record;
- exports._map = _map;
- exports._set = _set;
- exports._enum = _enum;
- exports._nativeEnum = _nativeEnum;
- exports._literal = _literal;
- exports._file = _file;
- exports._transform = _transform;
- exports._optional = _optional;
- exports._nullable = _nullable;
- exports._default = _default;
- exports._nonoptional = _nonoptional;
- exports._success = _success;
- exports._catch = _catch;
- exports._pipe = _pipe;
- exports._readonly = _readonly;
- exports._templateLiteral = _templateLiteral;
- exports._lazy = _lazy;
- exports._promise = _promise;
- exports._custom = _custom;
- exports._refine = _refine;
- exports._superRefine = _superRefine;
- exports._check = _check;
- exports.describe = describe;
- exports.meta = meta;
- exports._stringbool = _stringbool;
- exports._stringFormat = _stringFormat;
- const checks = __importStar(require("./checks.cjs"));
- const registries = __importStar(require("./registries.cjs"));
- const schemas = __importStar(require("./schemas.cjs"));
- const util = __importStar(require("./util.cjs"));
- // @__NO_SIDE_EFFECTS__
- function _string(Class, params) {
- return new Class({
- type: "string",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _coercedString(Class, params) {
- return new Class({
- type: "string",
- coerce: true,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _email(Class, params) {
- return new Class({
- type: "string",
- format: "email",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _guid(Class, params) {
- return new Class({
- type: "string",
- format: "guid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uuid(Class, params) {
- return new Class({
- type: "string",
- format: "uuid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uuidv4(Class, params) {
- return new Class({
- type: "string",
- format: "uuid",
- check: "string_format",
- abort: false,
- version: "v4",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uuidv6(Class, params) {
- return new Class({
- type: "string",
- format: "uuid",
- check: "string_format",
- abort: false,
- version: "v6",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uuidv7(Class, params) {
- return new Class({
- type: "string",
- format: "uuid",
- check: "string_format",
- abort: false,
- version: "v7",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _url(Class, params) {
- return new Class({
- type: "string",
- format: "url",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _emoji(Class, params) {
- return new Class({
- type: "string",
- format: "emoji",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _nanoid(Class, params) {
- return new Class({
- type: "string",
- format: "nanoid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _cuid(Class, params) {
- return new Class({
- type: "string",
- format: "cuid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _cuid2(Class, params) {
- return new Class({
- type: "string",
- format: "cuid2",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _ulid(Class, params) {
- return new Class({
- type: "string",
- format: "ulid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _xid(Class, params) {
- return new Class({
- type: "string",
- format: "xid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _ksuid(Class, params) {
- return new Class({
- type: "string",
- format: "ksuid",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _ipv4(Class, params) {
- return new Class({
- type: "string",
- format: "ipv4",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _ipv6(Class, params) {
- return new Class({
- type: "string",
- format: "ipv6",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _mac(Class, params) {
- return new Class({
- type: "string",
- format: "mac",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _cidrv4(Class, params) {
- return new Class({
- type: "string",
- format: "cidrv4",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _cidrv6(Class, params) {
- return new Class({
- type: "string",
- format: "cidrv6",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _base64(Class, params) {
- return new Class({
- type: "string",
- format: "base64",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _base64url(Class, params) {
- return new Class({
- type: "string",
- format: "base64url",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _e164(Class, params) {
- return new Class({
- type: "string",
- format: "e164",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _jwt(Class, params) {
- return new Class({
- type: "string",
- format: "jwt",
- check: "string_format",
- abort: false,
- ...util.normalizeParams(params),
- });
- }
- exports.TimePrecision = {
- Any: null,
- Minute: -1,
- Second: 0,
- Millisecond: 3,
- Microsecond: 6,
- };
- // @__NO_SIDE_EFFECTS__
- function _isoDateTime(Class, params) {
- return new Class({
- type: "string",
- format: "datetime",
- check: "string_format",
- offset: false,
- local: false,
- precision: null,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _isoDate(Class, params) {
- return new Class({
- type: "string",
- format: "date",
- check: "string_format",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _isoTime(Class, params) {
- return new Class({
- type: "string",
- format: "time",
- check: "string_format",
- precision: null,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _isoDuration(Class, params) {
- return new Class({
- type: "string",
- format: "duration",
- check: "string_format",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _number(Class, params) {
- return new Class({
- type: "number",
- checks: [],
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _coercedNumber(Class, params) {
- return new Class({
- type: "number",
- coerce: true,
- checks: [],
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _int(Class, params) {
- return new Class({
- type: "number",
- check: "number_format",
- abort: false,
- format: "safeint",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _float32(Class, params) {
- return new Class({
- type: "number",
- check: "number_format",
- abort: false,
- format: "float32",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _float64(Class, params) {
- return new Class({
- type: "number",
- check: "number_format",
- abort: false,
- format: "float64",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _int32(Class, params) {
- return new Class({
- type: "number",
- check: "number_format",
- abort: false,
- format: "int32",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uint32(Class, params) {
- return new Class({
- type: "number",
- check: "number_format",
- abort: false,
- format: "uint32",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _boolean(Class, params) {
- return new Class({
- type: "boolean",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _coercedBoolean(Class, params) {
- return new Class({
- type: "boolean",
- coerce: true,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _bigint(Class, params) {
- return new Class({
- type: "bigint",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _coercedBigint(Class, params) {
- return new Class({
- type: "bigint",
- coerce: true,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _int64(Class, params) {
- return new Class({
- type: "bigint",
- check: "bigint_format",
- abort: false,
- format: "int64",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uint64(Class, params) {
- return new Class({
- type: "bigint",
- check: "bigint_format",
- abort: false,
- format: "uint64",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _symbol(Class, params) {
- return new Class({
- type: "symbol",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _undefined(Class, params) {
- return new Class({
- type: "undefined",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _null(Class, params) {
- return new Class({
- type: "null",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _any(Class) {
- return new Class({
- type: "any",
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _unknown(Class) {
- return new Class({
- type: "unknown",
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _never(Class, params) {
- return new Class({
- type: "never",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _void(Class, params) {
- return new Class({
- type: "void",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _date(Class, params) {
- return new Class({
- type: "date",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _coercedDate(Class, params) {
- return new Class({
- type: "date",
- coerce: true,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _nan(Class, params) {
- return new Class({
- type: "nan",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _lt(value, params) {
- return new checks.$ZodCheckLessThan({
- check: "less_than",
- ...util.normalizeParams(params),
- value,
- inclusive: false,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _lte(value, params) {
- return new checks.$ZodCheckLessThan({
- check: "less_than",
- ...util.normalizeParams(params),
- value,
- inclusive: true,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _gt(value, params) {
- return new checks.$ZodCheckGreaterThan({
- check: "greater_than",
- ...util.normalizeParams(params),
- value,
- inclusive: false,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _gte(value, params) {
- return new checks.$ZodCheckGreaterThan({
- check: "greater_than",
- ...util.normalizeParams(params),
- value,
- inclusive: true,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _positive(params) {
- return _gt(0, params);
- }
- // negative
- // @__NO_SIDE_EFFECTS__
- function _negative(params) {
- return _lt(0, params);
- }
- // nonpositive
- // @__NO_SIDE_EFFECTS__
- function _nonpositive(params) {
- return _lte(0, params);
- }
- // nonnegative
- // @__NO_SIDE_EFFECTS__
- function _nonnegative(params) {
- return _gte(0, params);
- }
- // @__NO_SIDE_EFFECTS__
- function _multipleOf(value, params) {
- return new checks.$ZodCheckMultipleOf({
- check: "multiple_of",
- ...util.normalizeParams(params),
- value,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _maxSize(maximum, params) {
- return new checks.$ZodCheckMaxSize({
- check: "max_size",
- ...util.normalizeParams(params),
- maximum,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _minSize(minimum, params) {
- return new checks.$ZodCheckMinSize({
- check: "min_size",
- ...util.normalizeParams(params),
- minimum,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _size(size, params) {
- return new checks.$ZodCheckSizeEquals({
- check: "size_equals",
- ...util.normalizeParams(params),
- size,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _maxLength(maximum, params) {
- const ch = new checks.$ZodCheckMaxLength({
- check: "max_length",
- ...util.normalizeParams(params),
- maximum,
- });
- return ch;
- }
- // @__NO_SIDE_EFFECTS__
- function _minLength(minimum, params) {
- return new checks.$ZodCheckMinLength({
- check: "min_length",
- ...util.normalizeParams(params),
- minimum,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _length(length, params) {
- return new checks.$ZodCheckLengthEquals({
- check: "length_equals",
- ...util.normalizeParams(params),
- length,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _regex(pattern, params) {
- return new checks.$ZodCheckRegex({
- check: "string_format",
- format: "regex",
- ...util.normalizeParams(params),
- pattern,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _lowercase(params) {
- return new checks.$ZodCheckLowerCase({
- check: "string_format",
- format: "lowercase",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _uppercase(params) {
- return new checks.$ZodCheckUpperCase({
- check: "string_format",
- format: "uppercase",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _includes(includes, params) {
- return new checks.$ZodCheckIncludes({
- check: "string_format",
- format: "includes",
- ...util.normalizeParams(params),
- includes,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _startsWith(prefix, params) {
- return new checks.$ZodCheckStartsWith({
- check: "string_format",
- format: "starts_with",
- ...util.normalizeParams(params),
- prefix,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _endsWith(suffix, params) {
- return new checks.$ZodCheckEndsWith({
- check: "string_format",
- format: "ends_with",
- ...util.normalizeParams(params),
- suffix,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _property(property, schema, params) {
- return new checks.$ZodCheckProperty({
- check: "property",
- property,
- schema,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _mime(types, params) {
- return new checks.$ZodCheckMimeType({
- check: "mime_type",
- mime: types,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _overwrite(tx) {
- return new checks.$ZodCheckOverwrite({
- check: "overwrite",
- tx,
- });
- }
- // normalize
- // @__NO_SIDE_EFFECTS__
- function _normalize(form) {
- return _overwrite((input) => input.normalize(form));
- }
- // trim
- // @__NO_SIDE_EFFECTS__
- function _trim() {
- return _overwrite((input) => input.trim());
- }
- // toLowerCase
- // @__NO_SIDE_EFFECTS__
- function _toLowerCase() {
- return _overwrite((input) => input.toLowerCase());
- }
- // toUpperCase
- // @__NO_SIDE_EFFECTS__
- function _toUpperCase() {
- return _overwrite((input) => input.toUpperCase());
- }
- // slugify
- // @__NO_SIDE_EFFECTS__
- function _slugify() {
- return _overwrite((input) => util.slugify(input));
- }
- // @__NO_SIDE_EFFECTS__
- function _array(Class, element, params) {
- return new Class({
- type: "array",
- element,
- // get element() {
- // return element;
- // },
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _union(Class, options, params) {
- return new Class({
- type: "union",
- options,
- ...util.normalizeParams(params),
- });
- }
- function _xor(Class, options, params) {
- return new Class({
- type: "union",
- options,
- inclusive: false,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _discriminatedUnion(Class, discriminator, options, params) {
- return new Class({
- type: "union",
- options,
- discriminator,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _intersection(Class, left, right) {
- return new Class({
- type: "intersection",
- left,
- right,
- });
- }
- // export function _tuple(
- // Class: util.SchemaClass<schemas.$ZodTuple>,
- // items: [],
- // params?: string | $ZodTupleParams
- // ): schemas.$ZodTuple<[], null>;
- // @__NO_SIDE_EFFECTS__
- function _tuple(Class, items, _paramsOrRest, _params) {
- const hasRest = _paramsOrRest instanceof schemas.$ZodType;
- const params = hasRest ? _params : _paramsOrRest;
- const rest = hasRest ? _paramsOrRest : null;
- return new Class({
- type: "tuple",
- items,
- rest,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _record(Class, keyType, valueType, params) {
- return new Class({
- type: "record",
- keyType,
- valueType,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _map(Class, keyType, valueType, params) {
- return new Class({
- type: "map",
- keyType,
- valueType,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _set(Class, valueType, params) {
- return new Class({
- type: "set",
- valueType,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _enum(Class, values, params) {
- const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
- // if (Array.isArray(values)) {
- // for (const value of values) {
- // entries[value] = value;
- // }
- // } else {
- // Object.assign(entries, values);
- // }
- // const entries: util.EnumLike = {};
- // for (const val of values) {
- // entries[val] = val;
- // }
- return new Class({
- type: "enum",
- entries,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- /** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
- *
- * ```ts
- * enum Colors { red, green, blue }
- * z.enum(Colors);
- * ```
- */
- function _nativeEnum(Class, entries, params) {
- return new Class({
- type: "enum",
- entries,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _literal(Class, value, params) {
- return new Class({
- type: "literal",
- values: Array.isArray(value) ? value : [value],
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _file(Class, params) {
- return new Class({
- type: "file",
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _transform(Class, fn) {
- return new Class({
- type: "transform",
- transform: fn,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _optional(Class, innerType) {
- return new Class({
- type: "optional",
- innerType,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _nullable(Class, innerType) {
- return new Class({
- type: "nullable",
- innerType,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _default(Class, innerType, defaultValue) {
- return new Class({
- type: "default",
- innerType,
- get defaultValue() {
- return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
- },
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _nonoptional(Class, innerType, params) {
- return new Class({
- type: "nonoptional",
- innerType,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _success(Class, innerType) {
- return new Class({
- type: "success",
- innerType,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _catch(Class, innerType, catchValue) {
- return new Class({
- type: "catch",
- innerType,
- catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _pipe(Class, in_, out) {
- return new Class({
- type: "pipe",
- in: in_,
- out,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _readonly(Class, innerType) {
- return new Class({
- type: "readonly",
- innerType,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _templateLiteral(Class, parts, params) {
- return new Class({
- type: "template_literal",
- parts,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _lazy(Class, getter) {
- return new Class({
- type: "lazy",
- getter,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _promise(Class, innerType) {
- return new Class({
- type: "promise",
- innerType,
- });
- }
- // @__NO_SIDE_EFFECTS__
- function _custom(Class, fn, _params) {
- const norm = util.normalizeParams(_params);
- norm.abort ?? (norm.abort = true); // default to abort:false
- const schema = new Class({
- type: "custom",
- check: "custom",
- fn: fn,
- ...norm,
- });
- return schema;
- }
- // same as _custom but defaults to abort:false
- // @__NO_SIDE_EFFECTS__
- function _refine(Class, fn, _params) {
- const schema = new Class({
- type: "custom",
- check: "custom",
- fn: fn,
- ...util.normalizeParams(_params),
- });
- return schema;
- }
- // @__NO_SIDE_EFFECTS__
- function _superRefine(fn) {
- const ch = _check((payload) => {
- payload.addIssue = (issue) => {
- if (typeof issue === "string") {
- payload.issues.push(util.issue(issue, payload.value, ch._zod.def));
- }
- else {
- // for Zod 3 backwards compatibility
- const _issue = issue;
- if (_issue.fatal)
- _issue.continue = false;
- _issue.code ?? (_issue.code = "custom");
- _issue.input ?? (_issue.input = payload.value);
- _issue.inst ?? (_issue.inst = ch);
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
- payload.issues.push(util.issue(_issue));
- }
- };
- return fn(payload.value, payload);
- });
- return ch;
- }
- // @__NO_SIDE_EFFECTS__
- function _check(fn, params) {
- const ch = new checks.$ZodCheck({
- check: "custom",
- ...util.normalizeParams(params),
- });
- ch._zod.check = fn;
- return ch;
- }
- // @__NO_SIDE_EFFECTS__
- function describe(description) {
- const ch = new checks.$ZodCheck({ check: "describe" });
- ch._zod.onattach = [
- (inst) => {
- const existing = registries.globalRegistry.get(inst) ?? {};
- registries.globalRegistry.add(inst, { ...existing, description });
- },
- ];
- ch._zod.check = () => { }; // no-op check
- return ch;
- }
- // @__NO_SIDE_EFFECTS__
- function meta(metadata) {
- const ch = new checks.$ZodCheck({ check: "meta" });
- ch._zod.onattach = [
- (inst) => {
- const existing = registries.globalRegistry.get(inst) ?? {};
- registries.globalRegistry.add(inst, { ...existing, ...metadata });
- },
- ];
- ch._zod.check = () => { }; // no-op check
- return ch;
- }
- // @__NO_SIDE_EFFECTS__
- function _stringbool(Classes, _params) {
- const params = util.normalizeParams(_params);
- let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
- let falsyArray = params.falsy ?? ["false", "0", "no", "off", "n", "disabled"];
- if (params.case !== "sensitive") {
- truthyArray = truthyArray.map((v) => (typeof v === "string" ? v.toLowerCase() : v));
- falsyArray = falsyArray.map((v) => (typeof v === "string" ? v.toLowerCase() : v));
- }
- const truthySet = new Set(truthyArray);
- const falsySet = new Set(falsyArray);
- const _Codec = Classes.Codec ?? schemas.$ZodCodec;
- const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
- const _String = Classes.String ?? schemas.$ZodString;
- const stringSchema = new _String({ type: "string", error: params.error });
- const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
- const codec = new _Codec({
- type: "pipe",
- in: stringSchema,
- out: booleanSchema,
- transform: ((input, payload) => {
- let data = input;
- if (params.case !== "sensitive")
- data = data.toLowerCase();
- if (truthySet.has(data)) {
- return true;
- }
- else if (falsySet.has(data)) {
- return false;
- }
- else {
- payload.issues.push({
- code: "invalid_value",
- expected: "stringbool",
- values: [...truthySet, ...falsySet],
- input: payload.value,
- inst: codec,
- continue: false,
- });
- return {};
- }
- }),
- reverseTransform: ((input, _payload) => {
- if (input === true) {
- return truthyArray[0] || "true";
- }
- else {
- return falsyArray[0] || "false";
- }
- }),
- error: params.error,
- });
- return codec;
- }
- // @__NO_SIDE_EFFECTS__
- function _stringFormat(Class, format, fnOrRegex, _params = {}) {
- const params = util.normalizeParams(_params);
- const def = {
- ...util.normalizeParams(_params),
- check: "string_format",
- type: "string",
- format,
- fn: typeof fnOrRegex === "function" ? fnOrRegex : (val) => fnOrRegex.test(val),
- ...params,
- };
- if (fnOrRegex instanceof RegExp) {
- def.pattern = fnOrRegex;
- }
- const inst = new Class(def);
- return inst;
- }
|