schemas.cjs 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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.ZodMiniFile = exports.ZodMiniLiteral = exports.ZodMiniEnum = exports.ZodMiniSet = exports.ZodMiniMap = exports.ZodMiniRecord = exports.ZodMiniTuple = exports.ZodMiniIntersection = exports.ZodMiniDiscriminatedUnion = exports.ZodMiniXor = exports.ZodMiniUnion = exports.ZodMiniObject = exports.ZodMiniArray = exports.ZodMiniDate = exports.ZodMiniVoid = exports.ZodMiniNever = exports.ZodMiniUnknown = exports.ZodMiniAny = exports.ZodMiniNull = exports.ZodMiniUndefined = exports.ZodMiniSymbol = exports.ZodMiniBigIntFormat = exports.ZodMiniBigInt = exports.ZodMiniBoolean = exports.ZodMiniNumberFormat = exports.ZodMiniNumber = exports.ZodMiniCustomStringFormat = exports.ZodMiniJWT = exports.ZodMiniE164 = exports.ZodMiniBase64URL = exports.ZodMiniBase64 = exports.ZodMiniMAC = exports.ZodMiniCIDRv6 = exports.ZodMiniCIDRv4 = exports.ZodMiniIPv6 = exports.ZodMiniIPv4 = exports.ZodMiniKSUID = exports.ZodMiniXID = exports.ZodMiniULID = exports.ZodMiniCUID2 = exports.ZodMiniCUID = exports.ZodMiniNanoID = exports.ZodMiniEmoji = exports.ZodMiniURL = exports.ZodMiniUUID = exports.ZodMiniGUID = exports.ZodMiniEmail = exports.ZodMiniStringFormat = exports.ZodMiniString = exports.ZodMiniType = void 0;
  27. exports.ZodMiniFunction = exports.stringbool = exports.meta = exports.describe = exports.ZodMiniCustom = exports.ZodMiniPromise = exports.ZodMiniLazy = exports.ZodMiniTemplateLiteral = exports.ZodMiniReadonly = exports.ZodMiniCodec = exports.ZodMiniPipe = exports.ZodMiniNaN = exports.ZodMiniCatch = exports.ZodMiniSuccess = exports.ZodMiniNonOptional = exports.ZodMiniPrefault = exports.ZodMiniDefault = exports.ZodMiniNullable = exports.ZodMiniExactOptional = exports.ZodMiniOptional = exports.ZodMiniTransform = 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.httpUrl = httpUrl;
  37. exports.emoji = emoji;
  38. exports.nanoid = nanoid;
  39. exports.cuid = cuid;
  40. exports.cuid2 = cuid2;
  41. exports.ulid = ulid;
  42. exports.xid = xid;
  43. exports.ksuid = ksuid;
  44. exports.ipv4 = ipv4;
  45. exports.ipv6 = ipv6;
  46. exports.cidrv4 = cidrv4;
  47. exports.cidrv6 = cidrv6;
  48. exports.mac = mac;
  49. exports.base64 = base64;
  50. exports.base64url = base64url;
  51. exports.e164 = e164;
  52. exports.jwt = jwt;
  53. exports.stringFormat = stringFormat;
  54. exports.hostname = hostname;
  55. exports.hex = hex;
  56. exports.hash = hash;
  57. exports.number = number;
  58. exports.int = int;
  59. exports.float32 = float32;
  60. exports.float64 = float64;
  61. exports.int32 = int32;
  62. exports.uint32 = uint32;
  63. exports.boolean = boolean;
  64. exports.bigint = bigint;
  65. exports.int64 = int64;
  66. exports.uint64 = uint64;
  67. exports.symbol = symbol;
  68. exports.undefined = _undefined;
  69. exports.null = _null;
  70. exports.any = any;
  71. exports.unknown = unknown;
  72. exports.never = never;
  73. exports.void = _void;
  74. exports.date = date;
  75. exports.array = array;
  76. exports.keyof = keyof;
  77. exports.object = object;
  78. exports.strictObject = strictObject;
  79. exports.looseObject = looseObject;
  80. exports.extend = extend;
  81. exports.safeExtend = safeExtend;
  82. exports.merge = merge;
  83. exports.pick = pick;
  84. exports.omit = omit;
  85. exports.partial = partial;
  86. exports.required = required;
  87. exports.catchall = catchall;
  88. exports.union = union;
  89. exports.xor = xor;
  90. exports.discriminatedUnion = discriminatedUnion;
  91. exports.intersection = intersection;
  92. exports.tuple = tuple;
  93. exports.record = record;
  94. exports.partialRecord = partialRecord;
  95. exports.looseRecord = looseRecord;
  96. exports.map = map;
  97. exports.set = set;
  98. exports.enum = _enum;
  99. exports.nativeEnum = nativeEnum;
  100. exports.literal = literal;
  101. exports.file = file;
  102. exports.transform = transform;
  103. exports.optional = optional;
  104. exports.exactOptional = exactOptional;
  105. exports.nullable = nullable;
  106. exports.nullish = nullish;
  107. exports._default = _default;
  108. exports.prefault = prefault;
  109. exports.nonoptional = nonoptional;
  110. exports.success = success;
  111. exports.catch = _catch;
  112. exports.nan = nan;
  113. exports.pipe = pipe;
  114. exports.codec = codec;
  115. exports.readonly = readonly;
  116. exports.templateLiteral = templateLiteral;
  117. exports.lazy = _lazy;
  118. exports.promise = promise;
  119. exports.check = check;
  120. exports.custom = custom;
  121. exports.refine = refine;
  122. exports.superRefine = superRefine;
  123. exports.instanceof = _instanceof;
  124. exports.json = json;
  125. exports._function = _function;
  126. exports.function = _function;
  127. exports._function = _function;
  128. exports.function = _function;
  129. const core = __importStar(require("../core/index.cjs"));
  130. const util = __importStar(require("../core/util.cjs"));
  131. const parse = __importStar(require("./parse.cjs"));
  132. exports.ZodMiniType = core.$constructor("ZodMiniType", (inst, def) => {
  133. if (!inst._zod)
  134. throw new Error("Uninitialized schema in ZodMiniType.");
  135. core.$ZodType.init(inst, def);
  136. inst.def = def;
  137. inst.type = def.type;
  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.check = (...checks) => {
  143. return inst.clone({
  144. ...def,
  145. checks: [
  146. ...(def.checks ?? []),
  147. ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
  148. ],
  149. }, { parent: true });
  150. };
  151. inst.with = inst.check;
  152. inst.clone = (_def, params) => core.clone(inst, _def, params);
  153. inst.brand = () => inst;
  154. inst.register = ((reg, meta) => {
  155. reg.add(inst, meta);
  156. return inst;
  157. });
  158. inst.apply = (fn) => fn(inst);
  159. });
  160. exports.ZodMiniString = core.$constructor("ZodMiniString", (inst, def) => {
  161. core.$ZodString.init(inst, def);
  162. exports.ZodMiniType.init(inst, def);
  163. });
  164. // @__NO_SIDE_EFFECTS__
  165. function string(params) {
  166. return core._string(exports.ZodMiniString, params);
  167. }
  168. exports.ZodMiniStringFormat = core.$constructor("ZodMiniStringFormat", (inst, def) => {
  169. core.$ZodStringFormat.init(inst, def);
  170. exports.ZodMiniString.init(inst, def);
  171. });
  172. exports.ZodMiniEmail = core.$constructor("ZodMiniEmail", (inst, def) => {
  173. core.$ZodEmail.init(inst, def);
  174. exports.ZodMiniStringFormat.init(inst, def);
  175. });
  176. // @__NO_SIDE_EFFECTS__
  177. function email(params) {
  178. return core._email(exports.ZodMiniEmail, params);
  179. }
  180. exports.ZodMiniGUID = core.$constructor("ZodMiniGUID", (inst, def) => {
  181. core.$ZodGUID.init(inst, def);
  182. exports.ZodMiniStringFormat.init(inst, def);
  183. });
  184. // @__NO_SIDE_EFFECTS__
  185. function guid(params) {
  186. return core._guid(exports.ZodMiniGUID, params);
  187. }
  188. exports.ZodMiniUUID = core.$constructor("ZodMiniUUID", (inst, def) => {
  189. core.$ZodUUID.init(inst, def);
  190. exports.ZodMiniStringFormat.init(inst, def);
  191. });
  192. // @__NO_SIDE_EFFECTS__
  193. function uuid(params) {
  194. return core._uuid(exports.ZodMiniUUID, params);
  195. }
  196. // @__NO_SIDE_EFFECTS__
  197. function uuidv4(params) {
  198. return core._uuidv4(exports.ZodMiniUUID, params);
  199. }
  200. // ZodMiniUUIDv6
  201. // @__NO_SIDE_EFFECTS__
  202. function uuidv6(params) {
  203. return core._uuidv6(exports.ZodMiniUUID, params);
  204. }
  205. // ZodMiniUUIDv7
  206. // @__NO_SIDE_EFFECTS__
  207. function uuidv7(params) {
  208. return core._uuidv7(exports.ZodMiniUUID, params);
  209. }
  210. exports.ZodMiniURL = core.$constructor("ZodMiniURL", (inst, def) => {
  211. core.$ZodURL.init(inst, def);
  212. exports.ZodMiniStringFormat.init(inst, def);
  213. });
  214. // @__NO_SIDE_EFFECTS__
  215. function url(params) {
  216. return core._url(exports.ZodMiniURL, params);
  217. }
  218. // @__NO_SIDE_EFFECTS__
  219. function httpUrl(params) {
  220. return core._url(exports.ZodMiniURL, {
  221. protocol: /^https?$/,
  222. hostname: core.regexes.domain,
  223. ...util.normalizeParams(params),
  224. });
  225. }
  226. exports.ZodMiniEmoji = core.$constructor("ZodMiniEmoji", (inst, def) => {
  227. core.$ZodEmoji.init(inst, def);
  228. exports.ZodMiniStringFormat.init(inst, def);
  229. });
  230. // @__NO_SIDE_EFFECTS__
  231. function emoji(params) {
  232. return core._emoji(exports.ZodMiniEmoji, params);
  233. }
  234. exports.ZodMiniNanoID = core.$constructor("ZodMiniNanoID", (inst, def) => {
  235. core.$ZodNanoID.init(inst, def);
  236. exports.ZodMiniStringFormat.init(inst, def);
  237. });
  238. // @__NO_SIDE_EFFECTS__
  239. function nanoid(params) {
  240. return core._nanoid(exports.ZodMiniNanoID, params);
  241. }
  242. exports.ZodMiniCUID = core.$constructor("ZodMiniCUID", (inst, def) => {
  243. core.$ZodCUID.init(inst, def);
  244. exports.ZodMiniStringFormat.init(inst, def);
  245. });
  246. // @__NO_SIDE_EFFECTS__
  247. function cuid(params) {
  248. return core._cuid(exports.ZodMiniCUID, params);
  249. }
  250. exports.ZodMiniCUID2 = core.$constructor("ZodMiniCUID2", (inst, def) => {
  251. core.$ZodCUID2.init(inst, def);
  252. exports.ZodMiniStringFormat.init(inst, def);
  253. });
  254. // @__NO_SIDE_EFFECTS__
  255. function cuid2(params) {
  256. return core._cuid2(exports.ZodMiniCUID2, params);
  257. }
  258. exports.ZodMiniULID = core.$constructor("ZodMiniULID", (inst, def) => {
  259. core.$ZodULID.init(inst, def);
  260. exports.ZodMiniStringFormat.init(inst, def);
  261. });
  262. // @__NO_SIDE_EFFECTS__
  263. function ulid(params) {
  264. return core._ulid(exports.ZodMiniULID, params);
  265. }
  266. exports.ZodMiniXID = core.$constructor("ZodMiniXID", (inst, def) => {
  267. core.$ZodXID.init(inst, def);
  268. exports.ZodMiniStringFormat.init(inst, def);
  269. });
  270. // @__NO_SIDE_EFFECTS__
  271. function xid(params) {
  272. return core._xid(exports.ZodMiniXID, params);
  273. }
  274. exports.ZodMiniKSUID = core.$constructor("ZodMiniKSUID", (inst, def) => {
  275. core.$ZodKSUID.init(inst, def);
  276. exports.ZodMiniStringFormat.init(inst, def);
  277. });
  278. // @__NO_SIDE_EFFECTS__
  279. function ksuid(params) {
  280. return core._ksuid(exports.ZodMiniKSUID, params);
  281. }
  282. exports.ZodMiniIPv4 = core.$constructor("ZodMiniIPv4", (inst, def) => {
  283. core.$ZodIPv4.init(inst, def);
  284. exports.ZodMiniStringFormat.init(inst, def);
  285. });
  286. // @__NO_SIDE_EFFECTS__
  287. function ipv4(params) {
  288. return core._ipv4(exports.ZodMiniIPv4, params);
  289. }
  290. exports.ZodMiniIPv6 = core.$constructor("ZodMiniIPv6", (inst, def) => {
  291. core.$ZodIPv6.init(inst, def);
  292. exports.ZodMiniStringFormat.init(inst, def);
  293. });
  294. // @__NO_SIDE_EFFECTS__
  295. function ipv6(params) {
  296. return core._ipv6(exports.ZodMiniIPv6, params);
  297. }
  298. exports.ZodMiniCIDRv4 = core.$constructor("ZodMiniCIDRv4", (inst, def) => {
  299. core.$ZodCIDRv4.init(inst, def);
  300. exports.ZodMiniStringFormat.init(inst, def);
  301. });
  302. // @__NO_SIDE_EFFECTS__
  303. function cidrv4(params) {
  304. return core._cidrv4(exports.ZodMiniCIDRv4, params);
  305. }
  306. exports.ZodMiniCIDRv6 = core.$constructor("ZodMiniCIDRv6", (inst, def) => {
  307. core.$ZodCIDRv6.init(inst, def);
  308. exports.ZodMiniStringFormat.init(inst, def);
  309. });
  310. // @__NO_SIDE_EFFECTS__
  311. function cidrv6(params) {
  312. return core._cidrv6(exports.ZodMiniCIDRv6, params);
  313. }
  314. exports.ZodMiniMAC = core.$constructor("ZodMiniMAC", (inst, def) => {
  315. core.$ZodMAC.init(inst, def);
  316. exports.ZodMiniStringFormat.init(inst, def);
  317. });
  318. // @__NO_SIDE_EFFECTS__
  319. function mac(params) {
  320. return core._mac(exports.ZodMiniMAC, params);
  321. }
  322. exports.ZodMiniBase64 = core.$constructor("ZodMiniBase64", (inst, def) => {
  323. core.$ZodBase64.init(inst, def);
  324. exports.ZodMiniStringFormat.init(inst, def);
  325. });
  326. // @__NO_SIDE_EFFECTS__
  327. function base64(params) {
  328. return core._base64(exports.ZodMiniBase64, params);
  329. }
  330. exports.ZodMiniBase64URL = core.$constructor("ZodMiniBase64URL", (inst, def) => {
  331. core.$ZodBase64URL.init(inst, def);
  332. exports.ZodMiniStringFormat.init(inst, def);
  333. });
  334. // @__NO_SIDE_EFFECTS__
  335. function base64url(params) {
  336. return core._base64url(exports.ZodMiniBase64URL, params);
  337. }
  338. exports.ZodMiniE164 = core.$constructor("ZodMiniE164", (inst, def) => {
  339. core.$ZodE164.init(inst, def);
  340. exports.ZodMiniStringFormat.init(inst, def);
  341. });
  342. // @__NO_SIDE_EFFECTS__
  343. function e164(params) {
  344. return core._e164(exports.ZodMiniE164, params);
  345. }
  346. exports.ZodMiniJWT = core.$constructor("ZodMiniJWT", (inst, def) => {
  347. core.$ZodJWT.init(inst, def);
  348. exports.ZodMiniStringFormat.init(inst, def);
  349. });
  350. // @__NO_SIDE_EFFECTS__
  351. function jwt(params) {
  352. return core._jwt(exports.ZodMiniJWT, params);
  353. }
  354. exports.ZodMiniCustomStringFormat = core.$constructor("ZodMiniCustomStringFormat", (inst, def) => {
  355. core.$ZodCustomStringFormat.init(inst, def);
  356. exports.ZodMiniStringFormat.init(inst, def);
  357. });
  358. // @__NO_SIDE_EFFECTS__
  359. function stringFormat(format, fnOrRegex, _params = {}) {
  360. return core._stringFormat(exports.ZodMiniCustomStringFormat, format, fnOrRegex, _params);
  361. }
  362. // @__NO_SIDE_EFFECTS__
  363. function hostname(_params) {
  364. return core._stringFormat(exports.ZodMiniCustomStringFormat, "hostname", core.regexes.hostname, _params);
  365. }
  366. // @__NO_SIDE_EFFECTS__
  367. function hex(_params) {
  368. return core._stringFormat(exports.ZodMiniCustomStringFormat, "hex", core.regexes.hex, _params);
  369. }
  370. // @__NO_SIDE_EFFECTS__
  371. function hash(alg, params) {
  372. const enc = params?.enc ?? "hex";
  373. const format = `${alg}_${enc}`;
  374. const regex = core.regexes[format];
  375. // check for unrecognized format
  376. if (!regex)
  377. throw new Error(`Unrecognized hash format: ${format}`);
  378. return core._stringFormat(exports.ZodMiniCustomStringFormat, format, regex, params);
  379. }
  380. exports.ZodMiniNumber = core.$constructor("ZodMiniNumber", (inst, def) => {
  381. core.$ZodNumber.init(inst, def);
  382. exports.ZodMiniType.init(inst, def);
  383. });
  384. // @__NO_SIDE_EFFECTS__
  385. function number(params) {
  386. return core._number(exports.ZodMiniNumber, params);
  387. }
  388. exports.ZodMiniNumberFormat = core.$constructor("ZodMiniNumberFormat", (inst, def) => {
  389. core.$ZodNumberFormat.init(inst, def);
  390. exports.ZodMiniNumber.init(inst, def);
  391. });
  392. // int
  393. // @__NO_SIDE_EFFECTS__
  394. function int(params) {
  395. return core._int(exports.ZodMiniNumberFormat, params);
  396. }
  397. // float32
  398. // @__NO_SIDE_EFFECTS__
  399. function float32(params) {
  400. return core._float32(exports.ZodMiniNumberFormat, params);
  401. }
  402. // float64
  403. // @__NO_SIDE_EFFECTS__
  404. function float64(params) {
  405. return core._float64(exports.ZodMiniNumberFormat, params);
  406. }
  407. // int32
  408. // @__NO_SIDE_EFFECTS__
  409. function int32(params) {
  410. return core._int32(exports.ZodMiniNumberFormat, params);
  411. }
  412. // uint32
  413. // @__NO_SIDE_EFFECTS__
  414. function uint32(params) {
  415. return core._uint32(exports.ZodMiniNumberFormat, params);
  416. }
  417. exports.ZodMiniBoolean = core.$constructor("ZodMiniBoolean", (inst, def) => {
  418. core.$ZodBoolean.init(inst, def);
  419. exports.ZodMiniType.init(inst, def);
  420. });
  421. // @__NO_SIDE_EFFECTS__
  422. function boolean(params) {
  423. return core._boolean(exports.ZodMiniBoolean, params);
  424. }
  425. exports.ZodMiniBigInt = core.$constructor("ZodMiniBigInt", (inst, def) => {
  426. core.$ZodBigInt.init(inst, def);
  427. exports.ZodMiniType.init(inst, def);
  428. });
  429. // @__NO_SIDE_EFFECTS__
  430. function bigint(params) {
  431. return core._bigint(exports.ZodMiniBigInt, params);
  432. }
  433. exports.ZodMiniBigIntFormat = core.$constructor("ZodMiniBigIntFormat", (inst, def) => {
  434. core.$ZodBigIntFormat.init(inst, def);
  435. exports.ZodMiniBigInt.init(inst, def);
  436. });
  437. // int64
  438. // @__NO_SIDE_EFFECTS__
  439. function int64(params) {
  440. return core._int64(exports.ZodMiniBigIntFormat, params);
  441. }
  442. // uint64
  443. // @__NO_SIDE_EFFECTS__
  444. function uint64(params) {
  445. return core._uint64(exports.ZodMiniBigIntFormat, params);
  446. }
  447. exports.ZodMiniSymbol = core.$constructor("ZodMiniSymbol", (inst, def) => {
  448. core.$ZodSymbol.init(inst, def);
  449. exports.ZodMiniType.init(inst, def);
  450. });
  451. // @__NO_SIDE_EFFECTS__
  452. function symbol(params) {
  453. return core._symbol(exports.ZodMiniSymbol, params);
  454. }
  455. exports.ZodMiniUndefined = core.$constructor("ZodMiniUndefined", (inst, def) => {
  456. core.$ZodUndefined.init(inst, def);
  457. exports.ZodMiniType.init(inst, def);
  458. });
  459. // @__NO_SIDE_EFFECTS__
  460. function _undefined(params) {
  461. return core._undefined(exports.ZodMiniUndefined, params);
  462. }
  463. exports.ZodMiniNull = core.$constructor("ZodMiniNull", (inst, def) => {
  464. core.$ZodNull.init(inst, def);
  465. exports.ZodMiniType.init(inst, def);
  466. });
  467. // @__NO_SIDE_EFFECTS__
  468. function _null(params) {
  469. return core._null(exports.ZodMiniNull, params);
  470. }
  471. exports.ZodMiniAny = core.$constructor("ZodMiniAny", (inst, def) => {
  472. core.$ZodAny.init(inst, def);
  473. exports.ZodMiniType.init(inst, def);
  474. });
  475. // @__NO_SIDE_EFFECTS__
  476. function any() {
  477. return core._any(exports.ZodMiniAny);
  478. }
  479. exports.ZodMiniUnknown = core.$constructor("ZodMiniUnknown", (inst, def) => {
  480. core.$ZodUnknown.init(inst, def);
  481. exports.ZodMiniType.init(inst, def);
  482. });
  483. // @__NO_SIDE_EFFECTS__
  484. function unknown() {
  485. return core._unknown(exports.ZodMiniUnknown);
  486. }
  487. exports.ZodMiniNever = core.$constructor("ZodMiniNever", (inst, def) => {
  488. core.$ZodNever.init(inst, def);
  489. exports.ZodMiniType.init(inst, def);
  490. });
  491. // @__NO_SIDE_EFFECTS__
  492. function never(params) {
  493. return core._never(exports.ZodMiniNever, params);
  494. }
  495. exports.ZodMiniVoid = core.$constructor("ZodMiniVoid", (inst, def) => {
  496. core.$ZodVoid.init(inst, def);
  497. exports.ZodMiniType.init(inst, def);
  498. });
  499. // @__NO_SIDE_EFFECTS__
  500. function _void(params) {
  501. return core._void(exports.ZodMiniVoid, params);
  502. }
  503. exports.ZodMiniDate = core.$constructor("ZodMiniDate", (inst, def) => {
  504. core.$ZodDate.init(inst, def);
  505. exports.ZodMiniType.init(inst, def);
  506. });
  507. // @__NO_SIDE_EFFECTS__
  508. function date(params) {
  509. return core._date(exports.ZodMiniDate, params);
  510. }
  511. exports.ZodMiniArray = core.$constructor("ZodMiniArray", (inst, def) => {
  512. core.$ZodArray.init(inst, def);
  513. exports.ZodMiniType.init(inst, def);
  514. });
  515. // @__NO_SIDE_EFFECTS__
  516. function array(element, params) {
  517. return new exports.ZodMiniArray({
  518. type: "array",
  519. element: element,
  520. ...util.normalizeParams(params),
  521. });
  522. }
  523. // .keyof
  524. // @__NO_SIDE_EFFECTS__
  525. function keyof(schema) {
  526. const shape = schema._zod.def.shape;
  527. return _enum(Object.keys(shape));
  528. }
  529. exports.ZodMiniObject = core.$constructor("ZodMiniObject", (inst, def) => {
  530. core.$ZodObject.init(inst, def);
  531. exports.ZodMiniType.init(inst, def);
  532. util.defineLazy(inst, "shape", () => def.shape);
  533. });
  534. // @__NO_SIDE_EFFECTS__
  535. function object(shape, params) {
  536. const def = {
  537. type: "object",
  538. shape: shape ?? {},
  539. ...util.normalizeParams(params),
  540. };
  541. return new exports.ZodMiniObject(def);
  542. }
  543. // strictObject
  544. // @__NO_SIDE_EFFECTS__
  545. function strictObject(shape, params) {
  546. return new exports.ZodMiniObject({
  547. type: "object",
  548. shape,
  549. catchall: never(),
  550. ...util.normalizeParams(params),
  551. });
  552. }
  553. // looseObject
  554. // @__NO_SIDE_EFFECTS__
  555. function looseObject(shape, params) {
  556. return new exports.ZodMiniObject({
  557. type: "object",
  558. shape,
  559. catchall: unknown(),
  560. ...util.normalizeParams(params),
  561. });
  562. }
  563. // object methods
  564. // @__NO_SIDE_EFFECTS__
  565. function extend(schema, shape) {
  566. return util.extend(schema, shape);
  567. }
  568. // @__NO_SIDE_EFFECTS__
  569. function safeExtend(schema, shape) {
  570. return util.safeExtend(schema, shape);
  571. }
  572. // @__NO_SIDE_EFFECTS__
  573. function merge(schema, shape) {
  574. return util.extend(schema, shape);
  575. }
  576. // @__NO_SIDE_EFFECTS__
  577. function pick(schema, mask) {
  578. return util.pick(schema, mask);
  579. }
  580. // .omit
  581. // @__NO_SIDE_EFFECTS__
  582. function omit(schema, mask) {
  583. return util.omit(schema, mask);
  584. }
  585. // @__NO_SIDE_EFFECTS__
  586. function partial(schema, mask) {
  587. return util.partial(exports.ZodMiniOptional, schema, mask);
  588. }
  589. // @__NO_SIDE_EFFECTS__
  590. function required(schema, mask) {
  591. return util.required(exports.ZodMiniNonOptional, schema, mask);
  592. }
  593. // @__NO_SIDE_EFFECTS__
  594. function catchall(inst, catchall) {
  595. return inst.clone({ ...inst._zod.def, catchall: catchall });
  596. }
  597. exports.ZodMiniUnion = core.$constructor("ZodMiniUnion", (inst, def) => {
  598. core.$ZodUnion.init(inst, def);
  599. exports.ZodMiniType.init(inst, def);
  600. });
  601. // @__NO_SIDE_EFFECTS__
  602. function union(options, params) {
  603. return new exports.ZodMiniUnion({
  604. type: "union",
  605. options: options,
  606. ...util.normalizeParams(params),
  607. });
  608. }
  609. exports.ZodMiniXor = core.$constructor("ZodMiniXor", (inst, def) => {
  610. exports.ZodMiniUnion.init(inst, def);
  611. core.$ZodXor.init(inst, def);
  612. });
  613. /** Creates an exclusive union (XOR) where exactly one option must match.
  614. * Unlike regular unions that succeed when any option matches, xor fails if
  615. * zero or more than one option matches the input. */
  616. function xor(options, params) {
  617. return new exports.ZodMiniXor({
  618. type: "union",
  619. options: options,
  620. inclusive: false,
  621. ...util.normalizeParams(params),
  622. });
  623. }
  624. exports.ZodMiniDiscriminatedUnion = core.$constructor("ZodMiniDiscriminatedUnion", (inst, def) => {
  625. core.$ZodDiscriminatedUnion.init(inst, def);
  626. exports.ZodMiniType.init(inst, def);
  627. });
  628. // @__NO_SIDE_EFFECTS__
  629. function discriminatedUnion(discriminator, options, params) {
  630. return new exports.ZodMiniDiscriminatedUnion({
  631. type: "union",
  632. options,
  633. discriminator,
  634. ...util.normalizeParams(params),
  635. });
  636. }
  637. exports.ZodMiniIntersection = core.$constructor("ZodMiniIntersection", (inst, def) => {
  638. core.$ZodIntersection.init(inst, def);
  639. exports.ZodMiniType.init(inst, def);
  640. });
  641. // @__NO_SIDE_EFFECTS__
  642. function intersection(left, right) {
  643. return new exports.ZodMiniIntersection({
  644. type: "intersection",
  645. left: left,
  646. right: right,
  647. });
  648. }
  649. exports.ZodMiniTuple = core.$constructor("ZodMiniTuple", (inst, def) => {
  650. core.$ZodTuple.init(inst, def);
  651. exports.ZodMiniType.init(inst, def);
  652. });
  653. // @__NO_SIDE_EFFECTS__
  654. function tuple(items, _paramsOrRest, _params) {
  655. const hasRest = _paramsOrRest instanceof core.$ZodType;
  656. const params = hasRest ? _params : _paramsOrRest;
  657. const rest = hasRest ? _paramsOrRest : null;
  658. return new exports.ZodMiniTuple({
  659. type: "tuple",
  660. items: items,
  661. rest,
  662. ...util.normalizeParams(params),
  663. });
  664. }
  665. exports.ZodMiniRecord = core.$constructor("ZodMiniRecord", (inst, def) => {
  666. core.$ZodRecord.init(inst, def);
  667. exports.ZodMiniType.init(inst, def);
  668. });
  669. // @__NO_SIDE_EFFECTS__
  670. function record(keyType, valueType, params) {
  671. return new exports.ZodMiniRecord({
  672. type: "record",
  673. keyType,
  674. valueType: valueType,
  675. ...util.normalizeParams(params),
  676. });
  677. }
  678. // @__NO_SIDE_EFFECTS__
  679. function partialRecord(keyType, valueType, params) {
  680. const k = core.clone(keyType);
  681. k._zod.values = undefined;
  682. return new exports.ZodMiniRecord({
  683. type: "record",
  684. keyType: k,
  685. valueType: valueType,
  686. ...util.normalizeParams(params),
  687. });
  688. }
  689. function looseRecord(keyType, valueType, params) {
  690. return new exports.ZodMiniRecord({
  691. type: "record",
  692. keyType,
  693. valueType: valueType,
  694. mode: "loose",
  695. ...util.normalizeParams(params),
  696. });
  697. }
  698. exports.ZodMiniMap = core.$constructor("ZodMiniMap", (inst, def) => {
  699. core.$ZodMap.init(inst, def);
  700. exports.ZodMiniType.init(inst, def);
  701. });
  702. // @__NO_SIDE_EFFECTS__
  703. function map(keyType, valueType, params) {
  704. return new exports.ZodMiniMap({
  705. type: "map",
  706. keyType: keyType,
  707. valueType: valueType,
  708. ...util.normalizeParams(params),
  709. });
  710. }
  711. exports.ZodMiniSet = core.$constructor("ZodMiniSet", (inst, def) => {
  712. core.$ZodSet.init(inst, def);
  713. exports.ZodMiniType.init(inst, def);
  714. });
  715. // @__NO_SIDE_EFFECTS__
  716. function set(valueType, params) {
  717. return new exports.ZodMiniSet({
  718. type: "set",
  719. valueType: valueType,
  720. ...util.normalizeParams(params),
  721. });
  722. }
  723. exports.ZodMiniEnum = core.$constructor("ZodMiniEnum", (inst, def) => {
  724. core.$ZodEnum.init(inst, def);
  725. exports.ZodMiniType.init(inst, def);
  726. inst.options = Object.values(def.entries);
  727. });
  728. // @__NO_SIDE_EFFECTS__
  729. function _enum(values, params) {
  730. const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
  731. return new exports.ZodMiniEnum({
  732. type: "enum",
  733. entries,
  734. ...util.normalizeParams(params),
  735. });
  736. }
  737. // @__NO_SIDE_EFFECTS__
  738. /** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
  739. *
  740. * ```ts
  741. * enum Colors { red, green, blue }
  742. * z.enum(Colors);
  743. * ```
  744. */
  745. function nativeEnum(entries, params) {
  746. return new exports.ZodMiniEnum({
  747. type: "enum",
  748. entries,
  749. ...util.normalizeParams(params),
  750. });
  751. }
  752. exports.ZodMiniLiteral = core.$constructor("ZodMiniLiteral", (inst, def) => {
  753. core.$ZodLiteral.init(inst, def);
  754. exports.ZodMiniType.init(inst, def);
  755. });
  756. // @__NO_SIDE_EFFECTS__
  757. function literal(value, params) {
  758. return new exports.ZodMiniLiteral({
  759. type: "literal",
  760. values: Array.isArray(value) ? value : [value],
  761. ...util.normalizeParams(params),
  762. });
  763. }
  764. exports.ZodMiniFile = core.$constructor("ZodMiniFile", (inst, def) => {
  765. core.$ZodFile.init(inst, def);
  766. exports.ZodMiniType.init(inst, def);
  767. });
  768. // @__NO_SIDE_EFFECTS__
  769. function file(params) {
  770. return core._file(exports.ZodMiniFile, params);
  771. }
  772. exports.ZodMiniTransform = core.$constructor("ZodMiniTransform", (inst, def) => {
  773. core.$ZodTransform.init(inst, def);
  774. exports.ZodMiniType.init(inst, def);
  775. });
  776. // @__NO_SIDE_EFFECTS__
  777. function transform(fn) {
  778. return new exports.ZodMiniTransform({
  779. type: "transform",
  780. transform: fn,
  781. });
  782. }
  783. exports.ZodMiniOptional = core.$constructor("ZodMiniOptional", (inst, def) => {
  784. core.$ZodOptional.init(inst, def);
  785. exports.ZodMiniType.init(inst, def);
  786. });
  787. // @__NO_SIDE_EFFECTS__
  788. function optional(innerType) {
  789. return new exports.ZodMiniOptional({
  790. type: "optional",
  791. innerType: innerType,
  792. });
  793. }
  794. exports.ZodMiniExactOptional = core.$constructor("ZodMiniExactOptional", (inst, def) => {
  795. core.$ZodExactOptional.init(inst, def);
  796. exports.ZodMiniType.init(inst, def);
  797. });
  798. // @__NO_SIDE_EFFECTS__
  799. function exactOptional(innerType) {
  800. return new exports.ZodMiniExactOptional({
  801. type: "optional",
  802. innerType: innerType,
  803. });
  804. }
  805. exports.ZodMiniNullable = core.$constructor("ZodMiniNullable", (inst, def) => {
  806. core.$ZodNullable.init(inst, def);
  807. exports.ZodMiniType.init(inst, def);
  808. });
  809. // @__NO_SIDE_EFFECTS__
  810. function nullable(innerType) {
  811. return new exports.ZodMiniNullable({
  812. type: "nullable",
  813. innerType: innerType,
  814. });
  815. }
  816. // nullish
  817. // @__NO_SIDE_EFFECTS__
  818. function nullish(innerType) {
  819. return optional(nullable(innerType));
  820. }
  821. exports.ZodMiniDefault = core.$constructor("ZodMiniDefault", (inst, def) => {
  822. core.$ZodDefault.init(inst, def);
  823. exports.ZodMiniType.init(inst, def);
  824. });
  825. // @__NO_SIDE_EFFECTS__
  826. function _default(innerType, defaultValue) {
  827. return new exports.ZodMiniDefault({
  828. type: "default",
  829. innerType: innerType,
  830. get defaultValue() {
  831. return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
  832. },
  833. });
  834. }
  835. exports.ZodMiniPrefault = core.$constructor("ZodMiniPrefault", (inst, def) => {
  836. core.$ZodPrefault.init(inst, def);
  837. exports.ZodMiniType.init(inst, def);
  838. });
  839. // @__NO_SIDE_EFFECTS__
  840. function prefault(innerType, defaultValue) {
  841. return new exports.ZodMiniPrefault({
  842. type: "prefault",
  843. innerType: innerType,
  844. get defaultValue() {
  845. return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
  846. },
  847. });
  848. }
  849. exports.ZodMiniNonOptional = core.$constructor("ZodMiniNonOptional", (inst, def) => {
  850. core.$ZodNonOptional.init(inst, def);
  851. exports.ZodMiniType.init(inst, def);
  852. });
  853. // @__NO_SIDE_EFFECTS__
  854. function nonoptional(innerType, params) {
  855. return new exports.ZodMiniNonOptional({
  856. type: "nonoptional",
  857. innerType: innerType,
  858. ...util.normalizeParams(params),
  859. });
  860. }
  861. exports.ZodMiniSuccess = core.$constructor("ZodMiniSuccess", (inst, def) => {
  862. core.$ZodSuccess.init(inst, def);
  863. exports.ZodMiniType.init(inst, def);
  864. });
  865. // @__NO_SIDE_EFFECTS__
  866. function success(innerType) {
  867. return new exports.ZodMiniSuccess({
  868. type: "success",
  869. innerType: innerType,
  870. });
  871. }
  872. exports.ZodMiniCatch = core.$constructor("ZodMiniCatch", (inst, def) => {
  873. core.$ZodCatch.init(inst, def);
  874. exports.ZodMiniType.init(inst, def);
  875. });
  876. // @__NO_SIDE_EFFECTS__
  877. function _catch(innerType, catchValue) {
  878. return new exports.ZodMiniCatch({
  879. type: "catch",
  880. innerType: innerType,
  881. catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
  882. });
  883. }
  884. exports.ZodMiniNaN = core.$constructor("ZodMiniNaN", (inst, def) => {
  885. core.$ZodNaN.init(inst, def);
  886. exports.ZodMiniType.init(inst, def);
  887. });
  888. // @__NO_SIDE_EFFECTS__
  889. function nan(params) {
  890. return core._nan(exports.ZodMiniNaN, params);
  891. }
  892. exports.ZodMiniPipe = core.$constructor("ZodMiniPipe", (inst, def) => {
  893. core.$ZodPipe.init(inst, def);
  894. exports.ZodMiniType.init(inst, def);
  895. });
  896. // @__NO_SIDE_EFFECTS__
  897. function pipe(in_, out) {
  898. return new exports.ZodMiniPipe({
  899. type: "pipe",
  900. in: in_,
  901. out: out,
  902. });
  903. }
  904. exports.ZodMiniCodec = core.$constructor("ZodMiniCodec", (inst, def) => {
  905. exports.ZodMiniPipe.init(inst, def);
  906. core.$ZodCodec.init(inst, def);
  907. });
  908. // @__NO_SIDE_EFFECTS__
  909. function codec(in_, out, params) {
  910. return new exports.ZodMiniCodec({
  911. type: "pipe",
  912. in: in_,
  913. out: out,
  914. transform: params.decode,
  915. reverseTransform: params.encode,
  916. });
  917. }
  918. exports.ZodMiniReadonly = core.$constructor("ZodMiniReadonly", (inst, def) => {
  919. core.$ZodReadonly.init(inst, def);
  920. exports.ZodMiniType.init(inst, def);
  921. });
  922. // @__NO_SIDE_EFFECTS__
  923. function readonly(innerType) {
  924. return new exports.ZodMiniReadonly({
  925. type: "readonly",
  926. innerType: innerType,
  927. });
  928. }
  929. exports.ZodMiniTemplateLiteral = core.$constructor("ZodMiniTemplateLiteral", (inst, def) => {
  930. core.$ZodTemplateLiteral.init(inst, def);
  931. exports.ZodMiniType.init(inst, def);
  932. });
  933. // @__NO_SIDE_EFFECTS__
  934. function templateLiteral(parts, params) {
  935. return new exports.ZodMiniTemplateLiteral({
  936. type: "template_literal",
  937. parts,
  938. ...util.normalizeParams(params),
  939. });
  940. }
  941. exports.ZodMiniLazy = core.$constructor("ZodMiniLazy", (inst, def) => {
  942. core.$ZodLazy.init(inst, def);
  943. exports.ZodMiniType.init(inst, def);
  944. });
  945. // export function lazy<T extends object>(getter: () => T): T {
  946. // return util.createTransparentProxy<T>(getter);
  947. // }
  948. // @__NO_SIDE_EFFECTS__
  949. function _lazy(getter) {
  950. return new exports.ZodMiniLazy({
  951. type: "lazy",
  952. getter: getter,
  953. });
  954. }
  955. exports.ZodMiniPromise = core.$constructor("ZodMiniPromise", (inst, def) => {
  956. core.$ZodPromise.init(inst, def);
  957. exports.ZodMiniType.init(inst, def);
  958. });
  959. // @__NO_SIDE_EFFECTS__
  960. function promise(innerType) {
  961. return new exports.ZodMiniPromise({
  962. type: "promise",
  963. innerType: innerType,
  964. });
  965. }
  966. exports.ZodMiniCustom = core.$constructor("ZodMiniCustom", (inst, def) => {
  967. core.$ZodCustom.init(inst, def);
  968. exports.ZodMiniType.init(inst, def);
  969. });
  970. // custom checks
  971. // @__NO_SIDE_EFFECTS__
  972. function check(fn, params) {
  973. const ch = new core.$ZodCheck({
  974. check: "custom",
  975. ...util.normalizeParams(params),
  976. });
  977. ch._zod.check = fn;
  978. return ch;
  979. }
  980. // ZodCustom
  981. // custom schema
  982. // @__NO_SIDE_EFFECTS__
  983. function custom(fn, _params) {
  984. return core._custom(exports.ZodMiniCustom, fn ?? (() => true), _params);
  985. }
  986. // refine
  987. // @__NO_SIDE_EFFECTS__
  988. function refine(fn, _params = {}) {
  989. return core._refine(exports.ZodMiniCustom, fn, _params);
  990. }
  991. // superRefine
  992. // @__NO_SIDE_EFFECTS__
  993. function superRefine(fn) {
  994. return core._superRefine(fn);
  995. }
  996. // Re-export describe and meta from core
  997. exports.describe = core.describe;
  998. exports.meta = core.meta;
  999. // instanceof
  1000. class Class {
  1001. constructor(..._args) { }
  1002. }
  1003. // @__NO_SIDE_EFFECTS__
  1004. function _instanceof(cls, params = {}) {
  1005. const inst = custom((data) => data instanceof cls, params);
  1006. inst._zod.bag.Class = cls;
  1007. // Override check to emit invalid_type instead of custom
  1008. inst._zod.check = (payload) => {
  1009. if (!(payload.value instanceof cls)) {
  1010. payload.issues.push({
  1011. code: "invalid_type",
  1012. expected: cls.name,
  1013. input: payload.value,
  1014. inst,
  1015. path: [...(inst._zod.def.path ?? [])],
  1016. });
  1017. }
  1018. };
  1019. return inst;
  1020. }
  1021. // stringbool
  1022. const stringbool = (...args) => core._stringbool({
  1023. Codec: exports.ZodMiniCodec,
  1024. Boolean: exports.ZodMiniBoolean,
  1025. String: exports.ZodMiniString,
  1026. }, ...args);
  1027. exports.stringbool = stringbool;
  1028. // @__NO_SIDE_EFFECTS__
  1029. function json() {
  1030. const jsonSchema = _lazy(() => {
  1031. return union([string(), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
  1032. });
  1033. return jsonSchema;
  1034. }
  1035. exports.ZodMiniFunction = core.$constructor("ZodMiniFunction", (inst, def) => {
  1036. core.$ZodFunction.init(inst, def);
  1037. exports.ZodMiniType.init(inst, def);
  1038. });
  1039. // @__NO_SIDE_EFFECTS__
  1040. function _function(params) {
  1041. return new exports.ZodMiniFunction({
  1042. type: "function",
  1043. input: Array.isArray(params?.input) ? tuple(params?.input) : (params?.input ?? array(unknown())),
  1044. output: params?.output ?? unknown(),
  1045. });
  1046. }