schemas.js 23 KB

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