schemas.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.ZodFile = exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodJWT = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = exports.coerce = exports.iso = void 0;
  27. exports.stringbool = exports.ZodCustom = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransform = void 0;
  28. exports.string = string;
  29. exports.email = email;
  30. exports.guid = guid;
  31. exports.uuid = uuid;
  32. exports.uuidv4 = uuidv4;
  33. exports.uuidv6 = uuidv6;
  34. exports.uuidv7 = uuidv7;
  35. exports.url = url;
  36. exports.emoji = emoji;
  37. exports.nanoid = nanoid;
  38. exports.cuid = cuid;
  39. exports.cuid2 = cuid2;
  40. exports.ulid = ulid;
  41. exports.xid = xid;
  42. exports.ksuid = ksuid;
  43. exports.ipv4 = ipv4;
  44. exports.ipv6 = ipv6;
  45. exports.cidrv4 = cidrv4;
  46. exports.cidrv6 = cidrv6;
  47. exports.base64 = base64;
  48. exports.base64url = base64url;
  49. exports.e164 = e164;
  50. exports.jwt = jwt;
  51. exports.number = number;
  52. exports.int = int;
  53. exports.float32 = float32;
  54. exports.float64 = float64;
  55. exports.int32 = int32;
  56. exports.uint32 = uint32;
  57. exports.boolean = boolean;
  58. exports.bigint = bigint;
  59. exports.int64 = int64;
  60. exports.uint64 = uint64;
  61. exports.symbol = symbol;
  62. exports.undefined = _undefined;
  63. exports.null = _null;
  64. exports.any = any;
  65. exports.unknown = unknown;
  66. exports.never = never;
  67. exports.void = _void;
  68. exports.date = date;
  69. exports.array = array;
  70. exports.keyof = keyof;
  71. exports.object = object;
  72. exports.strictObject = strictObject;
  73. exports.looseObject = looseObject;
  74. exports.union = union;
  75. exports.discriminatedUnion = discriminatedUnion;
  76. exports.intersection = intersection;
  77. exports.tuple = tuple;
  78. exports.record = record;
  79. exports.partialRecord = partialRecord;
  80. exports.map = map;
  81. exports.set = set;
  82. exports.enum = _enum;
  83. exports.nativeEnum = nativeEnum;
  84. exports.literal = literal;
  85. exports.file = file;
  86. exports.transform = transform;
  87. exports.optional = optional;
  88. exports.nullable = nullable;
  89. exports.nullish = nullish;
  90. exports._default = _default;
  91. exports.prefault = prefault;
  92. exports.nonoptional = nonoptional;
  93. exports.success = success;
  94. exports.catch = _catch;
  95. exports.nan = nan;
  96. exports.pipe = pipe;
  97. exports.readonly = readonly;
  98. exports.templateLiteral = templateLiteral;
  99. exports.lazy = lazy;
  100. exports.promise = promise;
  101. exports.check = check;
  102. exports.custom = custom;
  103. exports.refine = refine;
  104. exports.superRefine = superRefine;
  105. exports.instanceof = _instanceof;
  106. exports.json = json;
  107. exports.preprocess = preprocess;
  108. const core = __importStar(require("zod/v4/core"));
  109. const core_1 = require("zod/v4/core");
  110. const checks = __importStar(require("./checks.js"));
  111. const iso = __importStar(require("./iso.js"));
  112. const parse = __importStar(require("./parse.js"));
  113. exports.iso = __importStar(require("./iso.js"));
  114. exports.coerce = __importStar(require("./coerce.js"));
  115. exports.ZodType = core.$constructor("ZodType", (inst, def) => {
  116. core.$ZodType.init(inst, def);
  117. inst.def = def;
  118. Object.defineProperty(inst, "_def", { value: def });
  119. // base methods
  120. inst.check = (...checks) => {
  121. return inst.clone({
  122. ...def,
  123. checks: [
  124. ...(def.checks ?? []),
  125. ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
  126. ],
  127. }
  128. // { parent: true }
  129. );
  130. };
  131. inst.clone = (def, params) => core.clone(inst, def, params);
  132. inst.brand = () => inst;
  133. inst.register = ((reg, meta) => {
  134. reg.add(inst, meta);
  135. return inst;
  136. });
  137. // parsing
  138. inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
  139. inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
  140. inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
  141. inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
  142. inst.spa = inst.safeParseAsync;
  143. // refinements
  144. inst.refine = (check, params) => inst.check(refine(check, params));
  145. inst.superRefine = (refinement) => inst.check(superRefine(refinement));
  146. inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
  147. // wrappers
  148. inst.optional = () => optional(inst);
  149. inst.nullable = () => nullable(inst);
  150. inst.nullish = () => optional(nullable(inst));
  151. inst.nonoptional = (params) => nonoptional(inst, params);
  152. inst.array = () => array(inst);
  153. inst.or = (arg) => union([inst, arg]);
  154. inst.and = (arg) => intersection(inst, arg);
  155. inst.transform = (tx) => pipe(inst, transform(tx));
  156. inst.default = (def) => _default(inst, def);
  157. inst.prefault = (def) => prefault(inst, def);
  158. // inst.coalesce = (def, params) => coalesce(inst, def, params);
  159. inst.catch = (params) => _catch(inst, params);
  160. inst.pipe = (target) => pipe(inst, target);
  161. inst.readonly = () => readonly(inst);
  162. // meta
  163. inst.describe = (description) => {
  164. const cl = inst.clone();
  165. core.globalRegistry.add(cl, { description });
  166. return cl;
  167. };
  168. Object.defineProperty(inst, "description", {
  169. get() {
  170. return core.globalRegistry.get(inst)?.description;
  171. },
  172. configurable: true,
  173. });
  174. inst.meta = (...args) => {
  175. if (args.length === 0) {
  176. return core.globalRegistry.get(inst);
  177. }
  178. const cl = inst.clone();
  179. core.globalRegistry.add(cl, args[0]);
  180. return cl;
  181. };
  182. // helpers
  183. inst.isOptional = () => inst.safeParse(undefined).success;
  184. inst.isNullable = () => inst.safeParse(null).success;
  185. return inst;
  186. });
  187. /** @internal */
  188. exports._ZodString = core.$constructor("_ZodString", (inst, def) => {
  189. core.$ZodString.init(inst, def);
  190. exports.ZodType.init(inst, def);
  191. const bag = inst._zod.bag;
  192. inst.format = bag.format ?? null;
  193. inst.minLength = bag.minimum ?? null;
  194. inst.maxLength = bag.maximum ?? null;
  195. // validations
  196. inst.regex = (...args) => inst.check(checks.regex(...args));
  197. inst.includes = (...args) => inst.check(checks.includes(...args));
  198. inst.startsWith = (...args) => inst.check(checks.startsWith(...args));
  199. inst.endsWith = (...args) => inst.check(checks.endsWith(...args));
  200. inst.min = (...args) => inst.check(checks.minLength(...args));
  201. inst.max = (...args) => inst.check(checks.maxLength(...args));
  202. inst.length = (...args) => inst.check(checks.length(...args));
  203. inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args));
  204. inst.lowercase = (params) => inst.check(checks.lowercase(params));
  205. inst.uppercase = (params) => inst.check(checks.uppercase(params));
  206. // transforms
  207. inst.trim = () => inst.check(checks.trim());
  208. inst.normalize = (...args) => inst.check(checks.normalize(...args));
  209. inst.toLowerCase = () => inst.check(checks.toLowerCase());
  210. inst.toUpperCase = () => inst.check(checks.toUpperCase());
  211. });
  212. exports.ZodString = core.$constructor("ZodString", (inst, def) => {
  213. core.$ZodString.init(inst, def);
  214. exports._ZodString.init(inst, def);
  215. inst.email = (params) => inst.check(core._email(exports.ZodEmail, params));
  216. inst.url = (params) => inst.check(core._url(exports.ZodURL, params));
  217. inst.jwt = (params) => inst.check(core._jwt(exports.ZodJWT, params));
  218. inst.emoji = (params) => inst.check(core._emoji(exports.ZodEmoji, params));
  219. inst.guid = (params) => inst.check(core._guid(exports.ZodGUID, params));
  220. inst.uuid = (params) => inst.check(core._uuid(exports.ZodUUID, params));
  221. inst.uuidv4 = (params) => inst.check(core._uuidv4(exports.ZodUUID, params));
  222. inst.uuidv6 = (params) => inst.check(core._uuidv6(exports.ZodUUID, params));
  223. inst.uuidv7 = (params) => inst.check(core._uuidv7(exports.ZodUUID, params));
  224. inst.nanoid = (params) => inst.check(core._nanoid(exports.ZodNanoID, params));
  225. inst.guid = (params) => inst.check(core._guid(exports.ZodGUID, params));
  226. inst.cuid = (params) => inst.check(core._cuid(exports.ZodCUID, params));
  227. inst.cuid2 = (params) => inst.check(core._cuid2(exports.ZodCUID2, params));
  228. inst.ulid = (params) => inst.check(core._ulid(exports.ZodULID, params));
  229. inst.base64 = (params) => inst.check(core._base64(exports.ZodBase64, params));
  230. inst.base64url = (params) => inst.check(core._base64url(exports.ZodBase64URL, params));
  231. inst.xid = (params) => inst.check(core._xid(exports.ZodXID, params));
  232. inst.ksuid = (params) => inst.check(core._ksuid(exports.ZodKSUID, params));
  233. inst.ipv4 = (params) => inst.check(core._ipv4(exports.ZodIPv4, params));
  234. inst.ipv6 = (params) => inst.check(core._ipv6(exports.ZodIPv6, params));
  235. inst.cidrv4 = (params) => inst.check(core._cidrv4(exports.ZodCIDRv4, params));
  236. inst.cidrv6 = (params) => inst.check(core._cidrv6(exports.ZodCIDRv6, params));
  237. inst.e164 = (params) => inst.check(core._e164(exports.ZodE164, params));
  238. // iso
  239. inst.datetime = (params) => inst.check(iso.datetime(params));
  240. inst.date = (params) => inst.check(iso.date(params));
  241. inst.time = (params) => inst.check(iso.time(params));
  242. inst.duration = (params) => inst.check(iso.duration(params));
  243. });
  244. function string(params) {
  245. return core._string(exports.ZodString, params);
  246. }
  247. exports.ZodStringFormat = core.$constructor("ZodStringFormat", (inst, def) => {
  248. core.$ZodStringFormat.init(inst, def);
  249. exports._ZodString.init(inst, def);
  250. });
  251. exports.ZodEmail = core.$constructor("ZodEmail", (inst, def) => {
  252. // ZodStringFormat.init(inst, def);
  253. core.$ZodEmail.init(inst, def);
  254. exports.ZodStringFormat.init(inst, def);
  255. });
  256. function email(params) {
  257. return core._email(exports.ZodEmail, params);
  258. }
  259. exports.ZodGUID = core.$constructor("ZodGUID", (inst, def) => {
  260. // ZodStringFormat.init(inst, def);
  261. core.$ZodGUID.init(inst, def);
  262. exports.ZodStringFormat.init(inst, def);
  263. });
  264. function guid(params) {
  265. return core._guid(exports.ZodGUID, params);
  266. }
  267. exports.ZodUUID = core.$constructor("ZodUUID", (inst, def) => {
  268. // ZodStringFormat.init(inst, def);
  269. core.$ZodUUID.init(inst, def);
  270. exports.ZodStringFormat.init(inst, def);
  271. });
  272. function uuid(params) {
  273. return core._uuid(exports.ZodUUID, params);
  274. }
  275. function uuidv4(params) {
  276. return core._uuidv4(exports.ZodUUID, params);
  277. }
  278. // ZodUUIDv6
  279. function uuidv6(params) {
  280. return core._uuidv6(exports.ZodUUID, params);
  281. }
  282. // ZodUUIDv7
  283. function uuidv7(params) {
  284. return core._uuidv7(exports.ZodUUID, params);
  285. }
  286. exports.ZodURL = core.$constructor("ZodURL", (inst, def) => {
  287. // ZodStringFormat.init(inst, def);
  288. core.$ZodURL.init(inst, def);
  289. exports.ZodStringFormat.init(inst, def);
  290. });
  291. function url(params) {
  292. return core._url(exports.ZodURL, params);
  293. }
  294. exports.ZodEmoji = core.$constructor("ZodEmoji", (inst, def) => {
  295. // ZodStringFormat.init(inst, def);
  296. core.$ZodEmoji.init(inst, def);
  297. exports.ZodStringFormat.init(inst, def);
  298. });
  299. function emoji(params) {
  300. return core._emoji(exports.ZodEmoji, params);
  301. }
  302. exports.ZodNanoID = core.$constructor("ZodNanoID", (inst, def) => {
  303. // ZodStringFormat.init(inst, def);
  304. core.$ZodNanoID.init(inst, def);
  305. exports.ZodStringFormat.init(inst, def);
  306. });
  307. function nanoid(params) {
  308. return core._nanoid(exports.ZodNanoID, params);
  309. }
  310. exports.ZodCUID = core.$constructor("ZodCUID", (inst, def) => {
  311. // ZodStringFormat.init(inst, def);
  312. core.$ZodCUID.init(inst, def);
  313. exports.ZodStringFormat.init(inst, def);
  314. });
  315. function cuid(params) {
  316. return core._cuid(exports.ZodCUID, params);
  317. }
  318. exports.ZodCUID2 = core.$constructor("ZodCUID2", (inst, def) => {
  319. // ZodStringFormat.init(inst, def);
  320. core.$ZodCUID2.init(inst, def);
  321. exports.ZodStringFormat.init(inst, def);
  322. });
  323. function cuid2(params) {
  324. return core._cuid2(exports.ZodCUID2, params);
  325. }
  326. exports.ZodULID = core.$constructor("ZodULID", (inst, def) => {
  327. // ZodStringFormat.init(inst, def);
  328. core.$ZodULID.init(inst, def);
  329. exports.ZodStringFormat.init(inst, def);
  330. });
  331. function ulid(params) {
  332. return core._ulid(exports.ZodULID, params);
  333. }
  334. exports.ZodXID = core.$constructor("ZodXID", (inst, def) => {
  335. // ZodStringFormat.init(inst, def);
  336. core.$ZodXID.init(inst, def);
  337. exports.ZodStringFormat.init(inst, def);
  338. });
  339. function xid(params) {
  340. return core._xid(exports.ZodXID, params);
  341. }
  342. exports.ZodKSUID = core.$constructor("ZodKSUID", (inst, def) => {
  343. // ZodStringFormat.init(inst, def);
  344. core.$ZodKSUID.init(inst, def);
  345. exports.ZodStringFormat.init(inst, def);
  346. });
  347. function ksuid(params) {
  348. return core._ksuid(exports.ZodKSUID, params);
  349. }
  350. exports.ZodIPv4 = core.$constructor("ZodIPv4", (inst, def) => {
  351. // ZodStringFormat.init(inst, def);
  352. core.$ZodIPv4.init(inst, def);
  353. exports.ZodStringFormat.init(inst, def);
  354. });
  355. function ipv4(params) {
  356. return core._ipv4(exports.ZodIPv4, params);
  357. }
  358. exports.ZodIPv6 = core.$constructor("ZodIPv6", (inst, def) => {
  359. // ZodStringFormat.init(inst, def);
  360. core.$ZodIPv6.init(inst, def);
  361. exports.ZodStringFormat.init(inst, def);
  362. });
  363. function ipv6(params) {
  364. return core._ipv6(exports.ZodIPv6, params);
  365. }
  366. exports.ZodCIDRv4 = core.$constructor("ZodCIDRv4", (inst, def) => {
  367. core.$ZodCIDRv4.init(inst, def);
  368. exports.ZodStringFormat.init(inst, def);
  369. });
  370. function cidrv4(params) {
  371. return core._cidrv4(exports.ZodCIDRv4, params);
  372. }
  373. exports.ZodCIDRv6 = core.$constructor("ZodCIDRv6", (inst, def) => {
  374. core.$ZodCIDRv6.init(inst, def);
  375. exports.ZodStringFormat.init(inst, def);
  376. });
  377. function cidrv6(params) {
  378. return core._cidrv6(exports.ZodCIDRv6, params);
  379. }
  380. exports.ZodBase64 = core.$constructor("ZodBase64", (inst, def) => {
  381. // ZodStringFormat.init(inst, def);
  382. core.$ZodBase64.init(inst, def);
  383. exports.ZodStringFormat.init(inst, def);
  384. });
  385. function base64(params) {
  386. return core._base64(exports.ZodBase64, params);
  387. }
  388. exports.ZodBase64URL = core.$constructor("ZodBase64URL", (inst, def) => {
  389. // ZodStringFormat.init(inst, def);
  390. core.$ZodBase64URL.init(inst, def);
  391. exports.ZodStringFormat.init(inst, def);
  392. });
  393. function base64url(params) {
  394. return core._base64url(exports.ZodBase64URL, params);
  395. }
  396. exports.ZodE164 = core.$constructor("ZodE164", (inst, def) => {
  397. // ZodStringFormat.init(inst, def);
  398. core.$ZodE164.init(inst, def);
  399. exports.ZodStringFormat.init(inst, def);
  400. });
  401. function e164(params) {
  402. return core._e164(exports.ZodE164, params);
  403. }
  404. exports.ZodJWT = core.$constructor("ZodJWT", (inst, def) => {
  405. // ZodStringFormat.init(inst, def);
  406. core.$ZodJWT.init(inst, def);
  407. exports.ZodStringFormat.init(inst, def);
  408. });
  409. function jwt(params) {
  410. return core._jwt(exports.ZodJWT, params);
  411. }
  412. exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => {
  413. core.$ZodNumber.init(inst, def);
  414. exports.ZodType.init(inst, def);
  415. inst.gt = (value, params) => inst.check(checks.gt(value, params));
  416. inst.gte = (value, params) => inst.check(checks.gte(value, params));
  417. inst.min = (value, params) => inst.check(checks.gte(value, params));
  418. inst.lt = (value, params) => inst.check(checks.lt(value, params));
  419. inst.lte = (value, params) => inst.check(checks.lte(value, params));
  420. inst.max = (value, params) => inst.check(checks.lte(value, params));
  421. inst.int = (params) => inst.check(int(params));
  422. inst.safe = (params) => inst.check(int(params));
  423. inst.positive = (params) => inst.check(checks.gt(0, params));
  424. inst.nonnegative = (params) => inst.check(checks.gte(0, params));
  425. inst.negative = (params) => inst.check(checks.lt(0, params));
  426. inst.nonpositive = (params) => inst.check(checks.lte(0, params));
  427. inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
  428. inst.step = (value, params) => inst.check(checks.multipleOf(value, params));
  429. // inst.finite = (params) => inst.check(core.finite(params));
  430. inst.finite = () => inst;
  431. const bag = inst._zod.bag;
  432. inst.minValue =
  433. Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
  434. inst.maxValue =
  435. Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
  436. inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
  437. inst.isFinite = true;
  438. inst.format = bag.format ?? null;
  439. });
  440. function number(params) {
  441. return core._number(exports.ZodNumber, params);
  442. }
  443. exports.ZodNumberFormat = core.$constructor("ZodNumberFormat", (inst, def) => {
  444. core.$ZodNumberFormat.init(inst, def);
  445. exports.ZodNumber.init(inst, def);
  446. });
  447. function int(params) {
  448. return core._int(exports.ZodNumberFormat, params);
  449. }
  450. function float32(params) {
  451. return core._float32(exports.ZodNumberFormat, params);
  452. }
  453. function float64(params) {
  454. return core._float64(exports.ZodNumberFormat, params);
  455. }
  456. function int32(params) {
  457. return core._int32(exports.ZodNumberFormat, params);
  458. }
  459. function uint32(params) {
  460. return core._uint32(exports.ZodNumberFormat, params);
  461. }
  462. exports.ZodBoolean = core.$constructor("ZodBoolean", (inst, def) => {
  463. core.$ZodBoolean.init(inst, def);
  464. exports.ZodType.init(inst, def);
  465. });
  466. function boolean(params) {
  467. return core._boolean(exports.ZodBoolean, params);
  468. }
  469. exports.ZodBigInt = core.$constructor("ZodBigInt", (inst, def) => {
  470. core.$ZodBigInt.init(inst, def);
  471. exports.ZodType.init(inst, def);
  472. inst.gte = (value, params) => inst.check(checks.gte(value, params));
  473. inst.min = (value, params) => inst.check(checks.gte(value, params));
  474. inst.gt = (value, params) => inst.check(checks.gt(value, params));
  475. inst.gte = (value, params) => inst.check(checks.gte(value, params));
  476. inst.min = (value, params) => inst.check(checks.gte(value, params));
  477. inst.lt = (value, params) => inst.check(checks.lt(value, params));
  478. inst.lte = (value, params) => inst.check(checks.lte(value, params));
  479. inst.max = (value, params) => inst.check(checks.lte(value, params));
  480. inst.positive = (params) => inst.check(checks.gt(BigInt(0), params));
  481. inst.negative = (params) => inst.check(checks.lt(BigInt(0), params));
  482. inst.nonpositive = (params) => inst.check(checks.lte(BigInt(0), params));
  483. inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params));
  484. inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
  485. const bag = inst._zod.bag;
  486. inst.minValue = bag.minimum ?? null;
  487. inst.maxValue = bag.maximum ?? null;
  488. inst.format = bag.format ?? null;
  489. });
  490. function bigint(params) {
  491. return core._bigint(exports.ZodBigInt, params);
  492. }
  493. exports.ZodBigIntFormat = core.$constructor("ZodBigIntFormat", (inst, def) => {
  494. core.$ZodBigIntFormat.init(inst, def);
  495. exports.ZodBigInt.init(inst, def);
  496. });
  497. // int64
  498. function int64(params) {
  499. return core._int64(exports.ZodBigIntFormat, params);
  500. }
  501. // uint64
  502. function uint64(params) {
  503. return core._uint64(exports.ZodBigIntFormat, params);
  504. }
  505. exports.ZodSymbol = core.$constructor("ZodSymbol", (inst, def) => {
  506. core.$ZodSymbol.init(inst, def);
  507. exports.ZodType.init(inst, def);
  508. });
  509. function symbol(params) {
  510. return core._symbol(exports.ZodSymbol, params);
  511. }
  512. exports.ZodUndefined = core.$constructor("ZodUndefined", (inst, def) => {
  513. core.$ZodUndefined.init(inst, def);
  514. exports.ZodType.init(inst, def);
  515. });
  516. function _undefined(params) {
  517. return core._undefined(exports.ZodUndefined, params);
  518. }
  519. exports.ZodNull = core.$constructor("ZodNull", (inst, def) => {
  520. core.$ZodNull.init(inst, def);
  521. exports.ZodType.init(inst, def);
  522. });
  523. function _null(params) {
  524. return core._null(exports.ZodNull, params);
  525. }
  526. exports.ZodAny = core.$constructor("ZodAny", (inst, def) => {
  527. core.$ZodAny.init(inst, def);
  528. exports.ZodType.init(inst, def);
  529. });
  530. function any() {
  531. return core._any(exports.ZodAny);
  532. }
  533. exports.ZodUnknown = core.$constructor("ZodUnknown", (inst, def) => {
  534. core.$ZodUnknown.init(inst, def);
  535. exports.ZodType.init(inst, def);
  536. });
  537. function unknown() {
  538. return core._unknown(exports.ZodUnknown);
  539. }
  540. exports.ZodNever = core.$constructor("ZodNever", (inst, def) => {
  541. core.$ZodNever.init(inst, def);
  542. exports.ZodType.init(inst, def);
  543. });
  544. function never(params) {
  545. return core._never(exports.ZodNever, params);
  546. }
  547. exports.ZodVoid = core.$constructor("ZodVoid", (inst, def) => {
  548. core.$ZodVoid.init(inst, def);
  549. exports.ZodType.init(inst, def);
  550. });
  551. function _void(params) {
  552. return core._void(exports.ZodVoid, params);
  553. }
  554. exports.ZodDate = core.$constructor("ZodDate", (inst, def) => {
  555. core.$ZodDate.init(inst, def);
  556. exports.ZodType.init(inst, def);
  557. inst.min = (value, params) => inst.check(checks.gte(value, params));
  558. inst.max = (value, params) => inst.check(checks.lte(value, params));
  559. const c = inst._zod.bag;
  560. inst.minDate = c.minimum ? new Date(c.minimum) : null;
  561. inst.maxDate = c.maximum ? new Date(c.maximum) : null;
  562. });
  563. function date(params) {
  564. return core._date(exports.ZodDate, params);
  565. }
  566. exports.ZodArray = core.$constructor("ZodArray", (inst, def) => {
  567. core.$ZodArray.init(inst, def);
  568. exports.ZodType.init(inst, def);
  569. inst.element = def.element;
  570. inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params));
  571. inst.nonempty = (params) => inst.check(checks.minLength(1, params));
  572. inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
  573. inst.length = (len, params) => inst.check(checks.length(len, params));
  574. inst.unwrap = () => inst.element;
  575. });
  576. function array(element, params) {
  577. return core._array(exports.ZodArray, element, params);
  578. }
  579. // .keyof
  580. function keyof(schema) {
  581. const shape = schema._zod.def.shape;
  582. return literal(Object.keys(shape));
  583. }
  584. exports.ZodObject = core.$constructor("ZodObject", (inst, def) => {
  585. core.$ZodObject.init(inst, def);
  586. exports.ZodType.init(inst, def);
  587. core_1.util.defineLazy(inst, "shape", () => {
  588. return Object.fromEntries(Object.entries(inst._zod.def.shape));
  589. });
  590. inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
  591. inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
  592. inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
  593. // inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
  594. inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
  595. inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
  596. inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
  597. inst.extend = (incoming) => {
  598. return core_1.util.extend(inst, incoming);
  599. };
  600. inst.merge = (other) => core_1.util.merge(inst, other);
  601. inst.pick = (mask) => core_1.util.pick(inst, mask);
  602. inst.omit = (mask) => core_1.util.omit(inst, mask);
  603. inst.partial = (...args) => core_1.util.partial(exports.ZodOptional, inst, args[0]);
  604. inst.required = (...args) => core_1.util.required(exports.ZodNonOptional, inst, args[0]);
  605. });
  606. function object(shape, params) {
  607. const def = {
  608. type: "object",
  609. get shape() {
  610. core_1.util.assignProp(this, "shape", { ...shape });
  611. return this.shape;
  612. },
  613. ...core_1.util.normalizeParams(params),
  614. };
  615. return new exports.ZodObject(def);
  616. }
  617. // strictObject
  618. function strictObject(shape, params) {
  619. return new exports.ZodObject({
  620. type: "object",
  621. get shape() {
  622. core_1.util.assignProp(this, "shape", { ...shape });
  623. return this.shape;
  624. },
  625. catchall: never(),
  626. ...core_1.util.normalizeParams(params),
  627. });
  628. }
  629. // looseObject
  630. function looseObject(shape, params) {
  631. return new exports.ZodObject({
  632. type: "object",
  633. get shape() {
  634. core_1.util.assignProp(this, "shape", { ...shape });
  635. return this.shape;
  636. },
  637. catchall: unknown(),
  638. ...core_1.util.normalizeParams(params),
  639. });
  640. }
  641. exports.ZodUnion = core.$constructor("ZodUnion", (inst, def) => {
  642. core.$ZodUnion.init(inst, def);
  643. exports.ZodType.init(inst, def);
  644. inst.options = def.options;
  645. });
  646. function union(options, params) {
  647. return new exports.ZodUnion({
  648. type: "union",
  649. options,
  650. ...core_1.util.normalizeParams(params),
  651. });
  652. }
  653. exports.ZodDiscriminatedUnion = core.$constructor("ZodDiscriminatedUnion", (inst, def) => {
  654. exports.ZodUnion.init(inst, def);
  655. core.$ZodDiscriminatedUnion.init(inst, def);
  656. });
  657. function discriminatedUnion(discriminator, options, params) {
  658. // const [options, params] = args;
  659. return new exports.ZodDiscriminatedUnion({
  660. type: "union",
  661. options,
  662. discriminator,
  663. ...core_1.util.normalizeParams(params),
  664. });
  665. }
  666. exports.ZodIntersection = core.$constructor("ZodIntersection", (inst, def) => {
  667. core.$ZodIntersection.init(inst, def);
  668. exports.ZodType.init(inst, def);
  669. });
  670. function intersection(left, right) {
  671. return new exports.ZodIntersection({
  672. type: "intersection",
  673. left,
  674. right,
  675. });
  676. }
  677. exports.ZodTuple = core.$constructor("ZodTuple", (inst, def) => {
  678. core.$ZodTuple.init(inst, def);
  679. exports.ZodType.init(inst, def);
  680. inst.rest = (rest) => inst.clone({
  681. ...inst._zod.def,
  682. rest,
  683. });
  684. });
  685. function tuple(items, _paramsOrRest, _params) {
  686. const hasRest = _paramsOrRest instanceof core.$ZodType;
  687. const params = hasRest ? _params : _paramsOrRest;
  688. const rest = hasRest ? _paramsOrRest : null;
  689. return new exports.ZodTuple({
  690. type: "tuple",
  691. items,
  692. rest,
  693. ...core_1.util.normalizeParams(params),
  694. });
  695. }
  696. exports.ZodRecord = core.$constructor("ZodRecord", (inst, def) => {
  697. core.$ZodRecord.init(inst, def);
  698. exports.ZodType.init(inst, def);
  699. inst.keyType = def.keyType;
  700. inst.valueType = def.valueType;
  701. });
  702. function record(keyType, valueType, params) {
  703. return new exports.ZodRecord({
  704. type: "record",
  705. keyType,
  706. valueType,
  707. ...core_1.util.normalizeParams(params),
  708. });
  709. }
  710. function partialRecord(keyType, valueType, params) {
  711. return new exports.ZodRecord({
  712. type: "record",
  713. keyType: union([keyType, never()]),
  714. valueType,
  715. ...core_1.util.normalizeParams(params),
  716. });
  717. }
  718. exports.ZodMap = core.$constructor("ZodMap", (inst, def) => {
  719. core.$ZodMap.init(inst, def);
  720. exports.ZodType.init(inst, def);
  721. inst.keyType = def.keyType;
  722. inst.valueType = def.valueType;
  723. });
  724. function map(keyType, valueType, params) {
  725. return new exports.ZodMap({
  726. type: "map",
  727. keyType,
  728. valueType,
  729. ...core_1.util.normalizeParams(params),
  730. });
  731. }
  732. exports.ZodSet = core.$constructor("ZodSet", (inst, def) => {
  733. core.$ZodSet.init(inst, def);
  734. exports.ZodType.init(inst, def);
  735. inst.min = (...args) => inst.check(core._minSize(...args));
  736. inst.nonempty = (params) => inst.check(core._minSize(1, params));
  737. inst.max = (...args) => inst.check(core._maxSize(...args));
  738. inst.size = (...args) => inst.check(core._size(...args));
  739. });
  740. function set(valueType, params) {
  741. return new exports.ZodSet({
  742. type: "set",
  743. valueType,
  744. ...core_1.util.normalizeParams(params),
  745. });
  746. }
  747. exports.ZodEnum = core.$constructor("ZodEnum", (inst, def) => {
  748. core.$ZodEnum.init(inst, def);
  749. exports.ZodType.init(inst, def);
  750. inst.enum = def.entries;
  751. inst.options = Object.values(def.entries);
  752. const keys = new Set(Object.keys(def.entries));
  753. inst.extract = (values, params) => {
  754. const newEntries = {};
  755. for (const value of values) {
  756. if (keys.has(value)) {
  757. newEntries[value] = def.entries[value];
  758. }
  759. else
  760. throw new Error(`Key ${value} not found in enum`);
  761. }
  762. return new exports.ZodEnum({
  763. ...def,
  764. checks: [],
  765. ...core_1.util.normalizeParams(params),
  766. entries: newEntries,
  767. });
  768. };
  769. inst.exclude = (values, params) => {
  770. const newEntries = { ...def.entries };
  771. for (const value of values) {
  772. if (keys.has(value)) {
  773. delete newEntries[value];
  774. }
  775. else
  776. throw new Error(`Key ${value} not found in enum`);
  777. }
  778. return new exports.ZodEnum({
  779. ...def,
  780. checks: [],
  781. ...core_1.util.normalizeParams(params),
  782. entries: newEntries,
  783. });
  784. };
  785. });
  786. function _enum(values, params) {
  787. const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
  788. return new exports.ZodEnum({
  789. type: "enum",
  790. entries,
  791. ...core_1.util.normalizeParams(params),
  792. });
  793. }
  794. /** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
  795. *
  796. * ```ts
  797. * enum Colors { red, green, blue }
  798. * z.enum(Colors);
  799. * ```
  800. */
  801. function nativeEnum(entries, params) {
  802. return new exports.ZodEnum({
  803. type: "enum",
  804. entries,
  805. ...core_1.util.normalizeParams(params),
  806. });
  807. }
  808. exports.ZodLiteral = core.$constructor("ZodLiteral", (inst, def) => {
  809. core.$ZodLiteral.init(inst, def);
  810. exports.ZodType.init(inst, def);
  811. inst.values = new Set(def.values);
  812. Object.defineProperty(inst, "value", {
  813. get() {
  814. if (def.values.length > 1) {
  815. throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
  816. }
  817. return def.values[0];
  818. },
  819. });
  820. });
  821. function literal(value, params) {
  822. return new exports.ZodLiteral({
  823. type: "literal",
  824. values: Array.isArray(value) ? value : [value],
  825. ...core_1.util.normalizeParams(params),
  826. });
  827. }
  828. exports.ZodFile = core.$constructor("ZodFile", (inst, def) => {
  829. core.$ZodFile.init(inst, def);
  830. exports.ZodType.init(inst, def);
  831. inst.min = (size, params) => inst.check(core._minSize(size, params));
  832. inst.max = (size, params) => inst.check(core._maxSize(size, params));
  833. inst.mime = (types, params) => inst.check(core._mime(types, params));
  834. });
  835. function file(params) {
  836. return core._file(exports.ZodFile, params);
  837. }
  838. exports.ZodTransform = core.$constructor("ZodTransform", (inst, def) => {
  839. core.$ZodTransform.init(inst, def);
  840. exports.ZodType.init(inst, def);
  841. inst._zod.parse = (payload, _ctx) => {
  842. payload.addIssue = (issue) => {
  843. if (typeof issue === "string") {
  844. payload.issues.push(core_1.util.issue(issue, payload.value, def));
  845. }
  846. else {
  847. // for Zod 3 backwards compatibility
  848. const _issue = issue;
  849. if (_issue.fatal)
  850. _issue.continue = false;
  851. _issue.code ?? (_issue.code = "custom");
  852. _issue.input ?? (_issue.input = payload.value);
  853. _issue.inst ?? (_issue.inst = inst);
  854. _issue.continue ?? (_issue.continue = true);
  855. payload.issues.push(core_1.util.issue(_issue));
  856. }
  857. };
  858. const output = def.transform(payload.value, payload);
  859. if (output instanceof Promise) {
  860. return output.then((output) => {
  861. payload.value = output;
  862. return payload;
  863. });
  864. }
  865. payload.value = output;
  866. return payload;
  867. };
  868. });
  869. function transform(fn) {
  870. return new exports.ZodTransform({
  871. type: "transform",
  872. transform: fn,
  873. });
  874. }
  875. exports.ZodOptional = core.$constructor("ZodOptional", (inst, def) => {
  876. core.$ZodOptional.init(inst, def);
  877. exports.ZodType.init(inst, def);
  878. inst.unwrap = () => inst._zod.def.innerType;
  879. });
  880. function optional(innerType) {
  881. return new exports.ZodOptional({
  882. type: "optional",
  883. innerType,
  884. });
  885. }
  886. exports.ZodNullable = core.$constructor("ZodNullable", (inst, def) => {
  887. core.$ZodNullable.init(inst, def);
  888. exports.ZodType.init(inst, def);
  889. inst.unwrap = () => inst._zod.def.innerType;
  890. });
  891. function nullable(innerType) {
  892. return new exports.ZodNullable({
  893. type: "nullable",
  894. innerType,
  895. });
  896. }
  897. // nullish
  898. function nullish(innerType) {
  899. return optional(nullable(innerType));
  900. }
  901. exports.ZodDefault = core.$constructor("ZodDefault", (inst, def) => {
  902. core.$ZodDefault.init(inst, def);
  903. exports.ZodType.init(inst, def);
  904. inst.unwrap = () => inst._zod.def.innerType;
  905. inst.removeDefault = inst.unwrap;
  906. });
  907. function _default(innerType, defaultValue) {
  908. return new exports.ZodDefault({
  909. type: "default",
  910. innerType,
  911. get defaultValue() {
  912. return typeof defaultValue === "function" ? defaultValue() : defaultValue;
  913. },
  914. });
  915. }
  916. exports.ZodPrefault = core.$constructor("ZodPrefault", (inst, def) => {
  917. core.$ZodPrefault.init(inst, def);
  918. exports.ZodType.init(inst, def);
  919. inst.unwrap = () => inst._zod.def.innerType;
  920. });
  921. function prefault(innerType, defaultValue) {
  922. return new exports.ZodPrefault({
  923. type: "prefault",
  924. innerType,
  925. get defaultValue() {
  926. return typeof defaultValue === "function" ? defaultValue() : defaultValue;
  927. },
  928. });
  929. }
  930. exports.ZodNonOptional = core.$constructor("ZodNonOptional", (inst, def) => {
  931. core.$ZodNonOptional.init(inst, def);
  932. exports.ZodType.init(inst, def);
  933. inst.unwrap = () => inst._zod.def.innerType;
  934. });
  935. function nonoptional(innerType, params) {
  936. return new exports.ZodNonOptional({
  937. type: "nonoptional",
  938. innerType,
  939. ...core_1.util.normalizeParams(params),
  940. });
  941. }
  942. exports.ZodSuccess = core.$constructor("ZodSuccess", (inst, def) => {
  943. core.$ZodSuccess.init(inst, def);
  944. exports.ZodType.init(inst, def);
  945. inst.unwrap = () => inst._zod.def.innerType;
  946. });
  947. function success(innerType) {
  948. return new exports.ZodSuccess({
  949. type: "success",
  950. innerType,
  951. });
  952. }
  953. exports.ZodCatch = core.$constructor("ZodCatch", (inst, def) => {
  954. core.$ZodCatch.init(inst, def);
  955. exports.ZodType.init(inst, def);
  956. inst.unwrap = () => inst._zod.def.innerType;
  957. inst.removeCatch = inst.unwrap;
  958. });
  959. function _catch(innerType, catchValue) {
  960. return new exports.ZodCatch({
  961. type: "catch",
  962. innerType,
  963. catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
  964. });
  965. }
  966. exports.ZodNaN = core.$constructor("ZodNaN", (inst, def) => {
  967. core.$ZodNaN.init(inst, def);
  968. exports.ZodType.init(inst, def);
  969. });
  970. function nan(params) {
  971. return core._nan(exports.ZodNaN, params);
  972. }
  973. exports.ZodPipe = core.$constructor("ZodPipe", (inst, def) => {
  974. core.$ZodPipe.init(inst, def);
  975. exports.ZodType.init(inst, def);
  976. inst.in = def.in;
  977. inst.out = def.out;
  978. });
  979. function pipe(in_, out) {
  980. return new exports.ZodPipe({
  981. type: "pipe",
  982. in: in_,
  983. out,
  984. // ...util.normalizeParams(params),
  985. });
  986. }
  987. exports.ZodReadonly = core.$constructor("ZodReadonly", (inst, def) => {
  988. core.$ZodReadonly.init(inst, def);
  989. exports.ZodType.init(inst, def);
  990. });
  991. function readonly(innerType) {
  992. return new exports.ZodReadonly({
  993. type: "readonly",
  994. innerType,
  995. });
  996. }
  997. exports.ZodTemplateLiteral = core.$constructor("ZodTemplateLiteral", (inst, def) => {
  998. core.$ZodTemplateLiteral.init(inst, def);
  999. exports.ZodType.init(inst, def);
  1000. });
  1001. function templateLiteral(parts, params) {
  1002. return new exports.ZodTemplateLiteral({
  1003. type: "template_literal",
  1004. parts,
  1005. ...core_1.util.normalizeParams(params),
  1006. });
  1007. }
  1008. exports.ZodLazy = core.$constructor("ZodLazy", (inst, def) => {
  1009. core.$ZodLazy.init(inst, def);
  1010. exports.ZodType.init(inst, def);
  1011. inst.unwrap = () => inst._zod.def.getter();
  1012. });
  1013. function lazy(getter) {
  1014. return new exports.ZodLazy({
  1015. type: "lazy",
  1016. getter,
  1017. });
  1018. }
  1019. exports.ZodPromise = core.$constructor("ZodPromise", (inst, def) => {
  1020. core.$ZodPromise.init(inst, def);
  1021. exports.ZodType.init(inst, def);
  1022. inst.unwrap = () => inst._zod.def.innerType;
  1023. });
  1024. function promise(innerType) {
  1025. return new exports.ZodPromise({
  1026. type: "promise",
  1027. innerType,
  1028. });
  1029. }
  1030. exports.ZodCustom = core.$constructor("ZodCustom", (inst, def) => {
  1031. core.$ZodCustom.init(inst, def);
  1032. exports.ZodType.init(inst, def);
  1033. });
  1034. // custom checks
  1035. function check(fn, params) {
  1036. const ch = new core.$ZodCheck({
  1037. check: "custom",
  1038. ...core_1.util.normalizeParams(params),
  1039. });
  1040. ch._zod.check = fn;
  1041. return ch;
  1042. }
  1043. function custom(fn, _params) {
  1044. return core._custom(exports.ZodCustom, fn ?? (() => true), _params);
  1045. }
  1046. function refine(fn, _params = {}) {
  1047. return core._custom(exports.ZodCustom, fn, _params);
  1048. }
  1049. // superRefine
  1050. function superRefine(fn, params) {
  1051. const ch = check((payload) => {
  1052. payload.addIssue = (issue) => {
  1053. if (typeof issue === "string") {
  1054. payload.issues.push(core_1.util.issue(issue, payload.value, ch._zod.def));
  1055. }
  1056. else {
  1057. // for Zod 3 backwards compatibility
  1058. const _issue = issue;
  1059. if (_issue.fatal)
  1060. _issue.continue = false;
  1061. _issue.code ?? (_issue.code = "custom");
  1062. _issue.input ?? (_issue.input = payload.value);
  1063. _issue.inst ?? (_issue.inst = ch);
  1064. _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
  1065. payload.issues.push(core_1.util.issue(_issue));
  1066. }
  1067. };
  1068. return fn(payload.value, payload);
  1069. }, params);
  1070. return ch;
  1071. }
  1072. function _instanceof(cls, params = {
  1073. error: `Input not instance of ${cls.name}`,
  1074. }) {
  1075. const inst = new exports.ZodCustom({
  1076. type: "custom",
  1077. check: "custom",
  1078. fn: (data) => data instanceof cls,
  1079. abort: true,
  1080. ...core_1.util.normalizeParams(params),
  1081. });
  1082. inst._zod.bag.Class = cls;
  1083. return inst;
  1084. }
  1085. // stringbool
  1086. exports.stringbool =
  1087. /*@__PURE__*/ core._stringbool.bind(null, {
  1088. Pipe: exports.ZodPipe,
  1089. Boolean: exports.ZodBoolean,
  1090. Unknown: exports.ZodUnknown,
  1091. });
  1092. function json(params) {
  1093. const jsonSchema = lazy(() => {
  1094. return union([string(params), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
  1095. });
  1096. return jsonSchema;
  1097. }
  1098. // preprocess
  1099. // /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
  1100. function preprocess(fn, schema) {
  1101. return pipe(transform(fn), schema);
  1102. }