schemas.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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.ZodMiniTransform = exports.ZodMiniFile = exports.ZodMiniLiteral = exports.ZodMiniEnum = exports.ZodMiniSet = exports.ZodMiniMap = exports.ZodMiniRecord = exports.ZodMiniTuple = exports.ZodMiniIntersection = exports.ZodMiniDiscriminatedUnion = 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.ZodMiniJWT = exports.ZodMiniE164 = exports.ZodMiniBase64URL = exports.ZodMiniBase64 = 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 = exports.iso = exports.coerce = void 0;
  27. exports.stringbool = exports.ZodMiniCustom = exports.ZodMiniPromise = exports.ZodMiniLazy = exports.ZodMiniTemplateLiteral = exports.ZodMiniReadonly = exports.ZodMiniPipe = exports.ZodMiniNaN = exports.ZodMiniCatch = exports.ZodMiniSuccess = exports.ZodMiniNonOptional = exports.ZodMiniPrefault = exports.ZodMiniDefault = exports.ZodMiniNullable = exports.ZodMiniOptional = 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.extend = extend;
  75. exports.merge = merge;
  76. exports.pick = pick;
  77. exports.omit = omit;
  78. exports.partial = partial;
  79. exports.required = required;
  80. exports.union = union;
  81. exports.discriminatedUnion = discriminatedUnion;
  82. exports.intersection = intersection;
  83. exports.tuple = tuple;
  84. exports.record = record;
  85. exports.partialRecord = partialRecord;
  86. exports.map = map;
  87. exports.set = set;
  88. exports.enum = _enum;
  89. exports.nativeEnum = nativeEnum;
  90. exports.literal = literal;
  91. exports.file = file;
  92. exports.transform = transform;
  93. exports.optional = optional;
  94. exports.nullable = nullable;
  95. exports.nullish = nullish;
  96. exports._default = _default;
  97. exports.prefault = prefault;
  98. exports.nonoptional = nonoptional;
  99. exports.success = success;
  100. exports.catch = _catch;
  101. exports.nan = nan;
  102. exports.pipe = pipe;
  103. exports.readonly = readonly;
  104. exports.templateLiteral = templateLiteral;
  105. exports.lazy = _lazy;
  106. exports.promise = promise;
  107. exports.check = check;
  108. exports.refine = refine;
  109. exports.custom = custom;
  110. exports.instanceof = _instanceof;
  111. exports.json = json;
  112. const core = __importStar(require("zod/v4/core"));
  113. const core_1 = require("zod/v4/core");
  114. const parse = __importStar(require("./parse.js"));
  115. exports.coerce = __importStar(require("./coerce.js"));
  116. exports.iso = __importStar(require("./iso.js"));
  117. exports.ZodMiniType = core.$constructor("ZodMiniType", (inst, def) => {
  118. if (!inst._zod)
  119. throw new Error("Uninitialized schema in mixin ZodMiniType.");
  120. core.$ZodType.init(inst, def);
  121. inst.def = def;
  122. inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
  123. inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
  124. inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
  125. inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
  126. inst.check = (...checks) => {
  127. return inst.clone({
  128. ...def,
  129. checks: [
  130. ...(def.checks ?? []),
  131. ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
  132. ],
  133. }
  134. // { parent: true }
  135. );
  136. };
  137. inst.clone = (_def, params) => core.clone(inst, _def, params);
  138. inst.brand = () => inst;
  139. inst.register = ((reg, meta) => {
  140. reg.add(inst, meta);
  141. return inst;
  142. });
  143. });
  144. exports.ZodMiniString = core.$constructor("ZodMiniString", (inst, def) => {
  145. core.$ZodString.init(inst, def);
  146. exports.ZodMiniType.init(inst, def);
  147. });
  148. function string(params) {
  149. return core._string(exports.ZodMiniString, params);
  150. }
  151. exports.ZodMiniStringFormat = core.$constructor("ZodMiniStringFormat", (inst, def) => {
  152. core.$ZodStringFormat.init(inst, def);
  153. exports.ZodMiniString.init(inst, def);
  154. });
  155. exports.ZodMiniEmail = core.$constructor("ZodMiniEmail", (inst, def) => {
  156. core.$ZodEmail.init(inst, def);
  157. exports.ZodMiniStringFormat.init(inst, def);
  158. });
  159. function email(params) {
  160. return core._email(exports.ZodMiniEmail, params);
  161. }
  162. exports.ZodMiniGUID = core.$constructor("ZodMiniGUID", (inst, def) => {
  163. core.$ZodGUID.init(inst, def);
  164. exports.ZodMiniStringFormat.init(inst, def);
  165. });
  166. function guid(params) {
  167. return core._guid(exports.ZodMiniGUID, params);
  168. }
  169. exports.ZodMiniUUID = core.$constructor("ZodMiniUUID", (inst, def) => {
  170. core.$ZodUUID.init(inst, def);
  171. exports.ZodMiniStringFormat.init(inst, def);
  172. });
  173. function uuid(params) {
  174. return core._uuid(exports.ZodMiniUUID, params);
  175. }
  176. function uuidv4(params) {
  177. return core._uuidv4(exports.ZodMiniUUID, params);
  178. }
  179. // ZodMiniUUIDv6
  180. function uuidv6(params) {
  181. return core._uuidv6(exports.ZodMiniUUID, params);
  182. }
  183. // ZodMiniUUIDv7
  184. function uuidv7(params) {
  185. return core._uuidv7(exports.ZodMiniUUID, params);
  186. }
  187. exports.ZodMiniURL = core.$constructor("ZodMiniURL", (inst, def) => {
  188. core.$ZodURL.init(inst, def);
  189. exports.ZodMiniStringFormat.init(inst, def);
  190. });
  191. function url(params) {
  192. return core._url(exports.ZodMiniURL, params);
  193. }
  194. exports.ZodMiniEmoji = core.$constructor("ZodMiniEmoji", (inst, def) => {
  195. core.$ZodEmoji.init(inst, def);
  196. exports.ZodMiniStringFormat.init(inst, def);
  197. });
  198. function emoji(params) {
  199. return core._emoji(exports.ZodMiniEmoji, params);
  200. }
  201. exports.ZodMiniNanoID = core.$constructor("ZodMiniNanoID", (inst, def) => {
  202. core.$ZodNanoID.init(inst, def);
  203. exports.ZodMiniStringFormat.init(inst, def);
  204. });
  205. function nanoid(params) {
  206. return core._nanoid(exports.ZodMiniNanoID, params);
  207. }
  208. exports.ZodMiniCUID = core.$constructor("ZodMiniCUID", (inst, def) => {
  209. core.$ZodCUID.init(inst, def);
  210. exports.ZodMiniStringFormat.init(inst, def);
  211. });
  212. function cuid(params) {
  213. return core._cuid(exports.ZodMiniCUID, params);
  214. }
  215. exports.ZodMiniCUID2 = core.$constructor("ZodMiniCUID2", (inst, def) => {
  216. core.$ZodCUID2.init(inst, def);
  217. exports.ZodMiniStringFormat.init(inst, def);
  218. });
  219. function cuid2(params) {
  220. return core._cuid2(exports.ZodMiniCUID2, params);
  221. }
  222. exports.ZodMiniULID = core.$constructor("ZodMiniULID", (inst, def) => {
  223. core.$ZodULID.init(inst, def);
  224. exports.ZodMiniStringFormat.init(inst, def);
  225. });
  226. function ulid(params) {
  227. return core._ulid(exports.ZodMiniULID, params);
  228. }
  229. exports.ZodMiniXID = core.$constructor("ZodMiniXID", (inst, def) => {
  230. core.$ZodXID.init(inst, def);
  231. exports.ZodMiniStringFormat.init(inst, def);
  232. });
  233. function xid(params) {
  234. return core._xid(exports.ZodMiniXID, params);
  235. }
  236. exports.ZodMiniKSUID = core.$constructor("ZodMiniKSUID", (inst, def) => {
  237. core.$ZodKSUID.init(inst, def);
  238. exports.ZodMiniStringFormat.init(inst, def);
  239. });
  240. function ksuid(params) {
  241. return core._ksuid(exports.ZodMiniKSUID, params);
  242. }
  243. exports.ZodMiniIPv4 = core.$constructor("ZodMiniIPv4", (inst, def) => {
  244. core.$ZodIPv4.init(inst, def);
  245. exports.ZodMiniStringFormat.init(inst, def);
  246. });
  247. function ipv4(params) {
  248. return core._ipv4(exports.ZodMiniIPv4, params);
  249. }
  250. exports.ZodMiniIPv6 = core.$constructor("ZodMiniIPv6", (inst, def) => {
  251. core.$ZodIPv6.init(inst, def);
  252. exports.ZodMiniStringFormat.init(inst, def);
  253. });
  254. function ipv6(params) {
  255. return core._ipv6(exports.ZodMiniIPv6, params);
  256. }
  257. exports.ZodMiniCIDRv4 = core.$constructor("ZodMiniCIDRv4", (inst, def) => {
  258. core.$ZodCIDRv4.init(inst, def);
  259. exports.ZodMiniStringFormat.init(inst, def);
  260. });
  261. function cidrv4(params) {
  262. return core._cidrv4(exports.ZodMiniCIDRv4, params);
  263. }
  264. exports.ZodMiniCIDRv6 = core.$constructor("ZodMiniCIDRv6", (inst, def) => {
  265. core.$ZodCIDRv6.init(inst, def);
  266. exports.ZodMiniStringFormat.init(inst, def);
  267. });
  268. function cidrv6(params) {
  269. return core._cidrv6(exports.ZodMiniCIDRv6, params);
  270. }
  271. exports.ZodMiniBase64 = core.$constructor("ZodMiniBase64", (inst, def) => {
  272. core.$ZodBase64.init(inst, def);
  273. exports.ZodMiniStringFormat.init(inst, def);
  274. });
  275. function base64(params) {
  276. return core._base64(exports.ZodMiniBase64, params);
  277. }
  278. exports.ZodMiniBase64URL = core.$constructor("ZodMiniBase64URL", (inst, def) => {
  279. core.$ZodBase64URL.init(inst, def);
  280. exports.ZodMiniStringFormat.init(inst, def);
  281. });
  282. function base64url(params) {
  283. return core._base64url(exports.ZodMiniBase64URL, params);
  284. }
  285. exports.ZodMiniE164 = core.$constructor("ZodMiniE164", (inst, def) => {
  286. core.$ZodE164.init(inst, def);
  287. exports.ZodMiniStringFormat.init(inst, def);
  288. });
  289. function e164(params) {
  290. return core._e164(exports.ZodMiniE164, params);
  291. }
  292. exports.ZodMiniJWT = core.$constructor("ZodMiniJWT", (inst, def) => {
  293. core.$ZodJWT.init(inst, def);
  294. exports.ZodMiniStringFormat.init(inst, def);
  295. });
  296. function jwt(params) {
  297. return core._jwt(exports.ZodMiniJWT, params);
  298. }
  299. exports.ZodMiniNumber = core.$constructor("ZodMiniNumber", (inst, def) => {
  300. core.$ZodNumber.init(inst, def);
  301. exports.ZodMiniType.init(inst, def);
  302. });
  303. function number(params) {
  304. return core._number(exports.ZodMiniNumber, params);
  305. }
  306. exports.ZodMiniNumberFormat = core.$constructor("ZodMiniNumberFormat", (inst, def) => {
  307. core.$ZodNumberFormat.init(inst, def);
  308. exports.ZodMiniNumber.init(inst, def);
  309. });
  310. // int
  311. function int(params) {
  312. return core._int(exports.ZodMiniNumberFormat, params);
  313. }
  314. // float32
  315. function float32(params) {
  316. return core._float32(exports.ZodMiniNumberFormat, params);
  317. }
  318. // float64
  319. function float64(params) {
  320. return core._float64(exports.ZodMiniNumberFormat, params);
  321. }
  322. // int32
  323. function int32(params) {
  324. return core._int32(exports.ZodMiniNumberFormat, params);
  325. }
  326. // uint32
  327. function uint32(params) {
  328. return core._uint32(exports.ZodMiniNumberFormat, params);
  329. }
  330. exports.ZodMiniBoolean = core.$constructor("ZodMiniBoolean", (inst, def) => {
  331. core.$ZodBoolean.init(inst, def);
  332. exports.ZodMiniType.init(inst, def);
  333. });
  334. function boolean(params) {
  335. return core._boolean(exports.ZodMiniBoolean, params);
  336. }
  337. exports.ZodMiniBigInt = core.$constructor("ZodMiniBigInt", (inst, def) => {
  338. core.$ZodBigInt.init(inst, def);
  339. exports.ZodMiniType.init(inst, def);
  340. });
  341. function bigint(params) {
  342. return core._bigint(exports.ZodMiniBigInt, params);
  343. }
  344. exports.ZodMiniBigIntFormat = core.$constructor("ZodMiniBigIntFormat", (inst, def) => {
  345. core.$ZodBigIntFormat.init(inst, def);
  346. exports.ZodMiniBigInt.init(inst, def);
  347. });
  348. // int64
  349. function int64(params) {
  350. return core._int64(exports.ZodMiniBigIntFormat, params);
  351. }
  352. // uint64
  353. function uint64(params) {
  354. return core._uint64(exports.ZodMiniBigIntFormat, params);
  355. }
  356. exports.ZodMiniSymbol = core.$constructor("ZodMiniSymbol", (inst, def) => {
  357. core.$ZodSymbol.init(inst, def);
  358. exports.ZodMiniType.init(inst, def);
  359. });
  360. function symbol(params) {
  361. return core._symbol(exports.ZodMiniSymbol, params);
  362. }
  363. exports.ZodMiniUndefined = core.$constructor("ZodMiniUndefined", (inst, def) => {
  364. core.$ZodUndefined.init(inst, def);
  365. exports.ZodMiniType.init(inst, def);
  366. });
  367. function _undefined(params) {
  368. return core._undefined(exports.ZodMiniUndefined, params);
  369. }
  370. exports.ZodMiniNull = core.$constructor("ZodMiniNull", (inst, def) => {
  371. core.$ZodNull.init(inst, def);
  372. exports.ZodMiniType.init(inst, def);
  373. });
  374. function _null(params) {
  375. return core._null(exports.ZodMiniNull, params);
  376. }
  377. exports.ZodMiniAny = core.$constructor("ZodMiniAny", (inst, def) => {
  378. core.$ZodAny.init(inst, def);
  379. exports.ZodMiniType.init(inst, def);
  380. });
  381. function any() {
  382. return core._any(exports.ZodMiniAny);
  383. }
  384. exports.ZodMiniUnknown = core.$constructor("ZodMiniUnknown", (inst, def) => {
  385. core.$ZodUnknown.init(inst, def);
  386. exports.ZodMiniType.init(inst, def);
  387. });
  388. function unknown() {
  389. return core._unknown(exports.ZodMiniUnknown);
  390. }
  391. exports.ZodMiniNever = core.$constructor("ZodMiniNever", (inst, def) => {
  392. core.$ZodNever.init(inst, def);
  393. exports.ZodMiniType.init(inst, def);
  394. });
  395. function never(params) {
  396. return core._never(exports.ZodMiniNever, params);
  397. }
  398. exports.ZodMiniVoid = core.$constructor("ZodMiniVoid", (inst, def) => {
  399. core.$ZodVoid.init(inst, def);
  400. exports.ZodMiniType.init(inst, def);
  401. });
  402. function _void(params) {
  403. return core._void(exports.ZodMiniVoid, params);
  404. }
  405. exports.ZodMiniDate = core.$constructor("ZodMiniDate", (inst, def) => {
  406. core.$ZodDate.init(inst, def);
  407. exports.ZodMiniType.init(inst, def);
  408. });
  409. function date(params) {
  410. return core._date(exports.ZodMiniDate, params);
  411. }
  412. exports.ZodMiniArray = core.$constructor("ZodMiniArray", (inst, def) => {
  413. core.$ZodArray.init(inst, def);
  414. exports.ZodMiniType.init(inst, def);
  415. });
  416. function array(element, params) {
  417. return new exports.ZodMiniArray({
  418. type: "array",
  419. element,
  420. // get element() {
  421. // return element;
  422. // },
  423. ...core_1.util.normalizeParams(params),
  424. });
  425. }
  426. // .keyof
  427. function keyof(schema) {
  428. const shape = schema._zod.def.shape;
  429. return literal(Object.keys(shape));
  430. }
  431. exports.ZodMiniObject = core.$constructor("ZodMiniObject", (inst, def) => {
  432. core.$ZodObject.init(inst, def);
  433. exports.ZodMiniType.init(inst, def);
  434. });
  435. function object(shape, params) {
  436. const def = {
  437. type: "object",
  438. get shape() {
  439. core_1.util.assignProp(this, "shape", { ...shape });
  440. return this.shape;
  441. },
  442. ...core_1.util.normalizeParams(params),
  443. };
  444. return new exports.ZodMiniObject(def);
  445. }
  446. // strictObject
  447. function strictObject(shape, params) {
  448. return new exports.ZodMiniObject({
  449. type: "object",
  450. // shape: shape as core.$ZodLooseShape,
  451. get shape() {
  452. core_1.util.assignProp(this, "shape", { ...shape });
  453. return this.shape;
  454. },
  455. // get optional() {
  456. // return util.optionalKeys(shape);
  457. // },
  458. catchall: never(),
  459. ...core_1.util.normalizeParams(params),
  460. });
  461. }
  462. // looseObject
  463. function looseObject(shape, params) {
  464. return new exports.ZodMiniObject({
  465. type: "object",
  466. // shape: shape as core.$ZodLooseShape,
  467. get shape() {
  468. core_1.util.assignProp(this, "shape", { ...shape });
  469. return this.shape;
  470. },
  471. // get optional() {
  472. // return util.optionalKeys(shape);
  473. // },
  474. catchall: unknown(),
  475. ...core_1.util.normalizeParams(params),
  476. });
  477. }
  478. // object methods
  479. function extend(schema, shape) {
  480. return core_1.util.extend(schema, shape);
  481. }
  482. function merge(schema, shape) {
  483. return core_1.util.extend(schema, shape);
  484. }
  485. function pick(schema, mask) {
  486. return core_1.util.pick(schema, mask);
  487. }
  488. // .omit
  489. function omit(schema, mask) {
  490. return core_1.util.omit(schema, mask);
  491. }
  492. function partial(schema, mask) {
  493. return core_1.util.partial(exports.ZodMiniOptional, schema, mask);
  494. }
  495. function required(schema, mask) {
  496. return core_1.util.required(exports.ZodMiniNonOptional, schema, mask);
  497. }
  498. exports.ZodMiniUnion = core.$constructor("ZodMiniUnion", (inst, def) => {
  499. core.$ZodUnion.init(inst, def);
  500. exports.ZodMiniType.init(inst, def);
  501. });
  502. function union(options, params) {
  503. return new exports.ZodMiniUnion({
  504. type: "union",
  505. options,
  506. ...core_1.util.normalizeParams(params),
  507. });
  508. }
  509. exports.ZodMiniDiscriminatedUnion = core.$constructor("ZodMiniDiscriminatedUnion", (inst, def) => {
  510. core.$ZodDiscriminatedUnion.init(inst, def);
  511. exports.ZodMiniType.init(inst, def);
  512. });
  513. function discriminatedUnion(discriminator, options, params) {
  514. return new exports.ZodMiniDiscriminatedUnion({
  515. type: "union",
  516. options,
  517. discriminator,
  518. ...core_1.util.normalizeParams(params),
  519. });
  520. }
  521. exports.ZodMiniIntersection = core.$constructor("ZodMiniIntersection", (inst, def) => {
  522. core.$ZodIntersection.init(inst, def);
  523. exports.ZodMiniType.init(inst, def);
  524. });
  525. function intersection(left, right) {
  526. return new exports.ZodMiniIntersection({
  527. type: "intersection",
  528. left,
  529. right,
  530. });
  531. }
  532. exports.ZodMiniTuple = core.$constructor("ZodMiniTuple", (inst, def) => {
  533. core.$ZodTuple.init(inst, def);
  534. exports.ZodMiniType.init(inst, def);
  535. });
  536. function tuple(items, _paramsOrRest, _params) {
  537. const hasRest = _paramsOrRest instanceof core.$ZodType;
  538. const params = hasRest ? _params : _paramsOrRest;
  539. const rest = hasRest ? _paramsOrRest : null;
  540. return new exports.ZodMiniTuple({
  541. type: "tuple",
  542. items,
  543. rest,
  544. ...core_1.util.normalizeParams(params),
  545. });
  546. }
  547. exports.ZodMiniRecord = core.$constructor("ZodMiniRecord", (inst, def) => {
  548. core.$ZodRecord.init(inst, def);
  549. exports.ZodMiniType.init(inst, def);
  550. });
  551. function record(keyType, valueType, params) {
  552. return new exports.ZodMiniRecord({
  553. type: "record",
  554. keyType,
  555. valueType,
  556. ...core_1.util.normalizeParams(params),
  557. });
  558. }
  559. function partialRecord(keyType, valueType, params) {
  560. return new exports.ZodMiniRecord({
  561. type: "record",
  562. keyType: union([keyType, never()]),
  563. valueType,
  564. ...core_1.util.normalizeParams(params),
  565. });
  566. }
  567. exports.ZodMiniMap = core.$constructor("ZodMiniMap", (inst, def) => {
  568. core.$ZodMap.init(inst, def);
  569. exports.ZodMiniType.init(inst, def);
  570. });
  571. function map(keyType, valueType, params) {
  572. return new exports.ZodMiniMap({
  573. type: "map",
  574. keyType,
  575. valueType,
  576. ...core_1.util.normalizeParams(params),
  577. });
  578. }
  579. exports.ZodMiniSet = core.$constructor("ZodMiniSet", (inst, def) => {
  580. core.$ZodSet.init(inst, def);
  581. exports.ZodMiniType.init(inst, def);
  582. });
  583. function set(valueType, params) {
  584. return new exports.ZodMiniSet({
  585. type: "set",
  586. valueType,
  587. ...core_1.util.normalizeParams(params),
  588. });
  589. }
  590. exports.ZodMiniEnum = core.$constructor("ZodMiniEnum", (inst, def) => {
  591. core.$ZodEnum.init(inst, def);
  592. exports.ZodMiniType.init(inst, def);
  593. });
  594. function _enum(values, params) {
  595. const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
  596. return new exports.ZodMiniEnum({
  597. type: "enum",
  598. entries,
  599. ...core_1.util.normalizeParams(params),
  600. });
  601. }
  602. /** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
  603. *
  604. * ```ts
  605. * enum Colors { red, green, blue }
  606. * z.enum(Colors);
  607. * ```
  608. */
  609. function nativeEnum(entries, params) {
  610. return new exports.ZodMiniEnum({
  611. type: "enum",
  612. entries,
  613. ...core_1.util.normalizeParams(params),
  614. });
  615. }
  616. exports.ZodMiniLiteral = core.$constructor("ZodMiniLiteral", (inst, def) => {
  617. core.$ZodLiteral.init(inst, def);
  618. exports.ZodMiniType.init(inst, def);
  619. });
  620. function literal(value, params) {
  621. return new exports.ZodMiniLiteral({
  622. type: "literal",
  623. values: Array.isArray(value) ? value : [value],
  624. ...core_1.util.normalizeParams(params),
  625. });
  626. }
  627. exports.ZodMiniFile = core.$constructor("ZodMiniFile", (inst, def) => {
  628. core.$ZodFile.init(inst, def);
  629. exports.ZodMiniType.init(inst, def);
  630. });
  631. function file(params) {
  632. return core._file(exports.ZodMiniFile, params);
  633. }
  634. exports.ZodMiniTransform = core.$constructor("ZodMiniTransform", (inst, def) => {
  635. core.$ZodTransform.init(inst, def);
  636. exports.ZodMiniType.init(inst, def);
  637. });
  638. function transform(fn) {
  639. return new exports.ZodMiniTransform({
  640. type: "transform",
  641. transform: fn,
  642. });
  643. }
  644. exports.ZodMiniOptional = core.$constructor("ZodMiniOptional", (inst, def) => {
  645. core.$ZodOptional.init(inst, def);
  646. exports.ZodMiniType.init(inst, def);
  647. });
  648. function optional(innerType) {
  649. return new exports.ZodMiniOptional({
  650. type: "optional",
  651. innerType,
  652. });
  653. }
  654. exports.ZodMiniNullable = core.$constructor("ZodMiniNullable", (inst, def) => {
  655. core.$ZodNullable.init(inst, def);
  656. exports.ZodMiniType.init(inst, def);
  657. });
  658. function nullable(innerType) {
  659. return new exports.ZodMiniNullable({
  660. type: "nullable",
  661. innerType,
  662. });
  663. }
  664. // nullish
  665. function nullish(innerType) {
  666. return optional(nullable(innerType));
  667. }
  668. exports.ZodMiniDefault = core.$constructor("ZodMiniDefault", (inst, def) => {
  669. core.$ZodDefault.init(inst, def);
  670. exports.ZodMiniType.init(inst, def);
  671. });
  672. function _default(innerType, defaultValue) {
  673. return new exports.ZodMiniDefault({
  674. type: "default",
  675. innerType,
  676. get defaultValue() {
  677. return typeof defaultValue === "function" ? defaultValue() : defaultValue;
  678. },
  679. });
  680. }
  681. exports.ZodMiniPrefault = core.$constructor("ZodMiniPrefault", (inst, def) => {
  682. core.$ZodPrefault.init(inst, def);
  683. exports.ZodMiniType.init(inst, def);
  684. });
  685. function prefault(innerType, defaultValue) {
  686. return new exports.ZodMiniPrefault({
  687. type: "prefault",
  688. innerType,
  689. get defaultValue() {
  690. return typeof defaultValue === "function" ? defaultValue() : defaultValue;
  691. },
  692. });
  693. }
  694. exports.ZodMiniNonOptional = core.$constructor("ZodMiniNonOptional", (inst, def) => {
  695. core.$ZodNonOptional.init(inst, def);
  696. exports.ZodMiniType.init(inst, def);
  697. });
  698. function nonoptional(innerType, params) {
  699. return new exports.ZodMiniNonOptional({
  700. type: "nonoptional",
  701. innerType,
  702. ...core_1.util.normalizeParams(params),
  703. });
  704. }
  705. exports.ZodMiniSuccess = core.$constructor("ZodMiniSuccess", (inst, def) => {
  706. core.$ZodSuccess.init(inst, def);
  707. exports.ZodMiniType.init(inst, def);
  708. });
  709. function success(innerType) {
  710. return new exports.ZodMiniSuccess({
  711. type: "success",
  712. innerType,
  713. });
  714. }
  715. exports.ZodMiniCatch = core.$constructor("ZodMiniCatch", (inst, def) => {
  716. core.$ZodCatch.init(inst, def);
  717. exports.ZodMiniType.init(inst, def);
  718. });
  719. function _catch(innerType, catchValue) {
  720. return new exports.ZodMiniCatch({
  721. type: "catch",
  722. innerType,
  723. catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
  724. });
  725. }
  726. exports.ZodMiniNaN = core.$constructor("ZodMiniNaN", (inst, def) => {
  727. core.$ZodNaN.init(inst, def);
  728. exports.ZodMiniType.init(inst, def);
  729. });
  730. function nan(params) {
  731. return core._nan(exports.ZodMiniNaN, params);
  732. }
  733. exports.ZodMiniPipe = core.$constructor("ZodMiniPipe", (inst, def) => {
  734. core.$ZodPipe.init(inst, def);
  735. exports.ZodMiniType.init(inst, def);
  736. });
  737. function pipe(in_, out) {
  738. return new exports.ZodMiniPipe({
  739. type: "pipe",
  740. in: in_,
  741. out,
  742. });
  743. }
  744. exports.ZodMiniReadonly = core.$constructor("ZodMiniReadonly", (inst, def) => {
  745. core.$ZodReadonly.init(inst, def);
  746. exports.ZodMiniType.init(inst, def);
  747. });
  748. function readonly(innerType) {
  749. return new exports.ZodMiniReadonly({
  750. type: "readonly",
  751. innerType,
  752. });
  753. }
  754. exports.ZodMiniTemplateLiteral = core.$constructor("ZodMiniTemplateLiteral", (inst, def) => {
  755. core.$ZodTemplateLiteral.init(inst, def);
  756. exports.ZodMiniType.init(inst, def);
  757. });
  758. function templateLiteral(parts, params) {
  759. return new exports.ZodMiniTemplateLiteral({
  760. type: "template_literal",
  761. parts,
  762. ...core_1.util.normalizeParams(params),
  763. });
  764. }
  765. exports.ZodMiniLazy = core.$constructor("ZodMiniLazy", (inst, def) => {
  766. core.$ZodLazy.init(inst, def);
  767. exports.ZodMiniType.init(inst, def);
  768. });
  769. // export function lazy<T extends object>(getter: () => T): T {
  770. // return util.createTransparentProxy<T>(getter);
  771. // }
  772. function _lazy(getter) {
  773. return new exports.ZodMiniLazy({
  774. type: "lazy",
  775. getter,
  776. });
  777. }
  778. exports.ZodMiniPromise = core.$constructor("ZodMiniPromise", (inst, def) => {
  779. core.$ZodPromise.init(inst, def);
  780. exports.ZodMiniType.init(inst, def);
  781. });
  782. function promise(innerType) {
  783. return new exports.ZodMiniPromise({
  784. type: "promise",
  785. innerType,
  786. });
  787. }
  788. exports.ZodMiniCustom = core.$constructor("ZodMiniCustom", (inst, def) => {
  789. core.$ZodCustom.init(inst, def);
  790. exports.ZodMiniType.init(inst, def);
  791. });
  792. // custom checks
  793. function check(fn, params) {
  794. const ch = new core.$ZodCheck({
  795. check: "custom",
  796. ...core_1.util.normalizeParams(params),
  797. });
  798. ch._zod.check = fn;
  799. return ch;
  800. }
  801. // ZodCustom
  802. function _custom(fn, _params, Class) {
  803. const params = core_1.util.normalizeParams(_params);
  804. const schema = new Class({
  805. type: "custom",
  806. check: "custom",
  807. fn: fn,
  808. ...params,
  809. });
  810. return schema;
  811. }
  812. // refine
  813. function refine(fn, _params = {}) {
  814. return _custom(fn, _params, exports.ZodMiniCustom);
  815. }
  816. // custom schema
  817. function custom(fn, _params) {
  818. return _custom(fn ?? (() => true), _params, exports.ZodMiniCustom);
  819. }
  820. // instanceof
  821. class Class {
  822. constructor(..._args) { }
  823. }
  824. function _instanceof(cls, params = {
  825. error: `Input not instance of ${cls.name}`,
  826. }) {
  827. const inst = custom((data) => data instanceof cls, params);
  828. inst._zod.bag.Class = cls;
  829. return inst;
  830. }
  831. // stringbool
  832. exports.stringbool = core._stringbool.bind(null, {
  833. Pipe: exports.ZodMiniPipe,
  834. Boolean: exports.ZodMiniBoolean,
  835. Unknown: exports.ZodMiniUnknown,
  836. });
  837. function json() {
  838. const jsonSchema = _lazy(() => {
  839. return union([string(), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
  840. });
  841. return jsonSchema;
  842. }