bupkis 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (377) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -4
  3. package/src/assertion/assertion-types.ts +4 -4
  4. package/src/assertion/impl/async-parametric.ts +4 -21
  5. package/src/assertion/impl/sync-parametric.ts +5 -17
  6. package/src/expect.ts +0 -4
  7. package/src/guards.ts +24 -24
  8. package/src/internal-schema.ts +16 -32
  9. package/src/value-to-schema.ts +1 -1
  10. package/dist/assertion/assertion-async.cjs +0 -268
  11. package/dist/assertion/assertion-async.cjs.map +0 -1
  12. package/dist/assertion/assertion-async.d.cts +0 -40
  13. package/dist/assertion/assertion-async.d.cts.map +0 -1
  14. package/dist/assertion/assertion-async.d.ts +0 -40
  15. package/dist/assertion/assertion-async.d.ts.map +0 -1
  16. package/dist/assertion/assertion-async.js +0 -259
  17. package/dist/assertion/assertion-async.js.map +0 -1
  18. package/dist/assertion/assertion-standard-schema-async.cjs +0 -132
  19. package/dist/assertion/assertion-standard-schema-async.cjs.map +0 -1
  20. package/dist/assertion/assertion-standard-schema-async.d.cts +0 -52
  21. package/dist/assertion/assertion-standard-schema-async.d.cts.map +0 -1
  22. package/dist/assertion/assertion-standard-schema-async.d.ts +0 -52
  23. package/dist/assertion/assertion-standard-schema-async.d.ts.map +0 -1
  24. package/dist/assertion/assertion-standard-schema-async.js +0 -128
  25. package/dist/assertion/assertion-standard-schema-async.js.map +0 -1
  26. package/dist/assertion/assertion-standard-schema-sync.cjs +0 -141
  27. package/dist/assertion/assertion-standard-schema-sync.cjs.map +0 -1
  28. package/dist/assertion/assertion-standard-schema-sync.d.cts +0 -52
  29. package/dist/assertion/assertion-standard-schema-sync.d.cts.map +0 -1
  30. package/dist/assertion/assertion-standard-schema-sync.d.ts +0 -52
  31. package/dist/assertion/assertion-standard-schema-sync.d.ts.map +0 -1
  32. package/dist/assertion/assertion-standard-schema-sync.js +0 -137
  33. package/dist/assertion/assertion-standard-schema-sync.js.map +0 -1
  34. package/dist/assertion/assertion-sync.cjs +0 -284
  35. package/dist/assertion/assertion-sync.cjs.map +0 -1
  36. package/dist/assertion/assertion-sync.d.cts +0 -60
  37. package/dist/assertion/assertion-sync.d.cts.map +0 -1
  38. package/dist/assertion/assertion-sync.d.ts +0 -60
  39. package/dist/assertion/assertion-sync.d.ts.map +0 -1
  40. package/dist/assertion/assertion-sync.js +0 -275
  41. package/dist/assertion/assertion-sync.js.map +0 -1
  42. package/dist/assertion/assertion-types.cjs +0 -20
  43. package/dist/assertion/assertion-types.cjs.map +0 -1
  44. package/dist/assertion/assertion-types.d.cts +0 -1086
  45. package/dist/assertion/assertion-types.d.cts.map +0 -1
  46. package/dist/assertion/assertion-types.d.ts +0 -1086
  47. package/dist/assertion/assertion-types.d.ts.map +0 -1
  48. package/dist/assertion/assertion-types.js +0 -19
  49. package/dist/assertion/assertion-types.js.map +0 -1
  50. package/dist/assertion/assertion.cjs +0 -382
  51. package/dist/assertion/assertion.cjs.map +0 -1
  52. package/dist/assertion/assertion.d.cts +0 -109
  53. package/dist/assertion/assertion.d.cts.map +0 -1
  54. package/dist/assertion/assertion.d.ts +0 -109
  55. package/dist/assertion/assertion.d.ts.map +0 -1
  56. package/dist/assertion/assertion.js +0 -375
  57. package/dist/assertion/assertion.js.map +0 -1
  58. package/dist/assertion/create.cjs +0 -148
  59. package/dist/assertion/create.cjs.map +0 -1
  60. package/dist/assertion/create.d.cts +0 -85
  61. package/dist/assertion/create.d.cts.map +0 -1
  62. package/dist/assertion/create.d.ts +0 -85
  63. package/dist/assertion/create.d.ts.map +0 -1
  64. package/dist/assertion/create.js +0 -143
  65. package/dist/assertion/create.js.map +0 -1
  66. package/dist/assertion/format-assertion-failure.cjs +0 -63
  67. package/dist/assertion/format-assertion-failure.cjs.map +0 -1
  68. package/dist/assertion/format-assertion-failure.d.cts +0 -21
  69. package/dist/assertion/format-assertion-failure.d.cts.map +0 -1
  70. package/dist/assertion/format-assertion-failure.d.ts +0 -21
  71. package/dist/assertion/format-assertion-failure.d.ts.map +0 -1
  72. package/dist/assertion/format-assertion-failure.js +0 -59
  73. package/dist/assertion/format-assertion-failure.js.map +0 -1
  74. package/dist/assertion/impl/assertion-util.cjs +0 -68
  75. package/dist/assertion/impl/assertion-util.cjs.map +0 -1
  76. package/dist/assertion/impl/assertion-util.d.cts +0 -36
  77. package/dist/assertion/impl/assertion-util.d.cts.map +0 -1
  78. package/dist/assertion/impl/assertion-util.d.ts +0 -36
  79. package/dist/assertion/impl/assertion-util.d.ts.map +0 -1
  80. package/dist/assertion/impl/assertion-util.js +0 -62
  81. package/dist/assertion/impl/assertion-util.js.map +0 -1
  82. package/dist/assertion/impl/async-iterable.cjs +0 -627
  83. package/dist/assertion/impl/async-iterable.cjs.map +0 -1
  84. package/dist/assertion/impl/async-iterable.d.cts +0 -406
  85. package/dist/assertion/impl/async-iterable.d.cts.map +0 -1
  86. package/dist/assertion/impl/async-iterable.d.ts +0 -406
  87. package/dist/assertion/impl/async-iterable.d.ts.map +0 -1
  88. package/dist/assertion/impl/async-iterable.js +0 -624
  89. package/dist/assertion/impl/async-iterable.js.map +0 -1
  90. package/dist/assertion/impl/async-parametric.cjs +0 -423
  91. package/dist/assertion/impl/async-parametric.cjs.map +0 -1
  92. package/dist/assertion/impl/async-parametric.d.cts +0 -278
  93. package/dist/assertion/impl/async-parametric.d.cts.map +0 -1
  94. package/dist/assertion/impl/async-parametric.d.ts +0 -278
  95. package/dist/assertion/impl/async-parametric.d.ts.map +0 -1
  96. package/dist/assertion/impl/async-parametric.js +0 -420
  97. package/dist/assertion/impl/async-parametric.js.map +0 -1
  98. package/dist/assertion/impl/async.cjs +0 -56
  99. package/dist/assertion/impl/async.cjs.map +0 -1
  100. package/dist/assertion/impl/async.d.cts +0 -179
  101. package/dist/assertion/impl/async.d.cts.map +0 -1
  102. package/dist/assertion/impl/async.d.ts +0 -179
  103. package/dist/assertion/impl/async.d.ts.map +0 -1
  104. package/dist/assertion/impl/async.js +0 -39
  105. package/dist/assertion/impl/async.js.map +0 -1
  106. package/dist/assertion/impl/index.cjs +0 -37
  107. package/dist/assertion/impl/index.cjs.map +0 -1
  108. package/dist/assertion/impl/index.d.cts +0 -21
  109. package/dist/assertion/impl/index.d.cts.map +0 -1
  110. package/dist/assertion/impl/index.d.ts +0 -21
  111. package/dist/assertion/impl/index.d.ts.map +0 -1
  112. package/dist/assertion/impl/index.js +0 -21
  113. package/dist/assertion/impl/index.js.map +0 -1
  114. package/dist/assertion/impl/iteration-util.cjs +0 -297
  115. package/dist/assertion/impl/iteration-util.cjs.map +0 -1
  116. package/dist/assertion/impl/iteration-util.d.cts +0 -12
  117. package/dist/assertion/impl/iteration-util.d.cts.map +0 -1
  118. package/dist/assertion/impl/iteration-util.d.ts +0 -12
  119. package/dist/assertion/impl/iteration-util.d.ts.map +0 -1
  120. package/dist/assertion/impl/iteration-util.js +0 -282
  121. package/dist/assertion/impl/iteration-util.js.map +0 -1
  122. package/dist/assertion/impl/snapshot.cjs +0 -276
  123. package/dist/assertion/impl/snapshot.cjs.map +0 -1
  124. package/dist/assertion/impl/snapshot.d.cts +0 -278
  125. package/dist/assertion/impl/snapshot.d.cts.map +0 -1
  126. package/dist/assertion/impl/snapshot.d.ts +0 -278
  127. package/dist/assertion/impl/snapshot.d.ts.map +0 -1
  128. package/dist/assertion/impl/snapshot.js +0 -273
  129. package/dist/assertion/impl/snapshot.js.map +0 -1
  130. package/dist/assertion/impl/sync-basic.cjs +0 -553
  131. package/dist/assertion/impl/sync-basic.cjs.map +0 -1
  132. package/dist/assertion/impl/sync-basic.d.cts +0 -528
  133. package/dist/assertion/impl/sync-basic.d.cts.map +0 -1
  134. package/dist/assertion/impl/sync-basic.d.ts +0 -528
  135. package/dist/assertion/impl/sync-basic.d.ts.map +0 -1
  136. package/dist/assertion/impl/sync-basic.js +0 -550
  137. package/dist/assertion/impl/sync-basic.js.map +0 -1
  138. package/dist/assertion/impl/sync-collection.cjs +0 -856
  139. package/dist/assertion/impl/sync-collection.cjs.map +0 -1
  140. package/dist/assertion/impl/sync-collection.d.cts +0 -607
  141. package/dist/assertion/impl/sync-collection.d.cts.map +0 -1
  142. package/dist/assertion/impl/sync-collection.d.ts +0 -607
  143. package/dist/assertion/impl/sync-collection.d.ts.map +0 -1
  144. package/dist/assertion/impl/sync-collection.js +0 -850
  145. package/dist/assertion/impl/sync-collection.js.map +0 -1
  146. package/dist/assertion/impl/sync-date.cjs +0 -341
  147. package/dist/assertion/impl/sync-date.cjs.map +0 -1
  148. package/dist/assertion/impl/sync-date.d.cts +0 -209
  149. package/dist/assertion/impl/sync-date.d.cts.map +0 -1
  150. package/dist/assertion/impl/sync-date.d.ts +0 -209
  151. package/dist/assertion/impl/sync-date.d.ts.map +0 -1
  152. package/dist/assertion/impl/sync-date.js +0 -338
  153. package/dist/assertion/impl/sync-date.js.map +0 -1
  154. package/dist/assertion/impl/sync-esoteric.cjs +0 -214
  155. package/dist/assertion/impl/sync-esoteric.cjs.map +0 -1
  156. package/dist/assertion/impl/sync-esoteric.d.cts +0 -191
  157. package/dist/assertion/impl/sync-esoteric.d.cts.map +0 -1
  158. package/dist/assertion/impl/sync-esoteric.d.ts +0 -191
  159. package/dist/assertion/impl/sync-esoteric.d.ts.map +0 -1
  160. package/dist/assertion/impl/sync-esoteric.js +0 -211
  161. package/dist/assertion/impl/sync-esoteric.js.map +0 -1
  162. package/dist/assertion/impl/sync-iterable.cjs +0 -512
  163. package/dist/assertion/impl/sync-iterable.cjs.map +0 -1
  164. package/dist/assertion/impl/sync-iterable.d.cts +0 -334
  165. package/dist/assertion/impl/sync-iterable.d.cts.map +0 -1
  166. package/dist/assertion/impl/sync-iterable.d.ts +0 -334
  167. package/dist/assertion/impl/sync-iterable.d.ts.map +0 -1
  168. package/dist/assertion/impl/sync-iterable.js +0 -509
  169. package/dist/assertion/impl/sync-iterable.js.map +0 -1
  170. package/dist/assertion/impl/sync-parametric.cjs +0 -812
  171. package/dist/assertion/impl/sync-parametric.cjs.map +0 -1
  172. package/dist/assertion/impl/sync-parametric.d.cts +0 -560
  173. package/dist/assertion/impl/sync-parametric.d.cts.map +0 -1
  174. package/dist/assertion/impl/sync-parametric.d.ts +0 -560
  175. package/dist/assertion/impl/sync-parametric.d.ts.map +0 -1
  176. package/dist/assertion/impl/sync-parametric.js +0 -809
  177. package/dist/assertion/impl/sync-parametric.js.map +0 -1
  178. package/dist/assertion/impl/sync.cjs +0 -214
  179. package/dist/assertion/impl/sync.cjs.map +0 -1
  180. package/dist/assertion/impl/sync.d.cts +0 -512
  181. package/dist/assertion/impl/sync.d.cts.map +0 -1
  182. package/dist/assertion/impl/sync.d.ts +0 -512
  183. package/dist/assertion/impl/sync.d.ts.map +0 -1
  184. package/dist/assertion/impl/sync.js +0 -197
  185. package/dist/assertion/impl/sync.js.map +0 -1
  186. package/dist/assertion/index.cjs +0 -38
  187. package/dist/assertion/index.cjs.map +0 -1
  188. package/dist/assertion/index.d.cts +0 -18
  189. package/dist/assertion/index.d.cts.map +0 -1
  190. package/dist/assertion/index.d.ts +0 -18
  191. package/dist/assertion/index.d.ts.map +0 -1
  192. package/dist/assertion/index.js +0 -17
  193. package/dist/assertion/index.js.map +0 -1
  194. package/dist/assertion/slotify.cjs +0 -165
  195. package/dist/assertion/slotify.cjs.map +0 -1
  196. package/dist/assertion/slotify.d.cts +0 -11
  197. package/dist/assertion/slotify.d.cts.map +0 -1
  198. package/dist/assertion/slotify.d.ts +0 -11
  199. package/dist/assertion/slotify.d.ts.map +0 -1
  200. package/dist/assertion/slotify.js +0 -161
  201. package/dist/assertion/slotify.js.map +0 -1
  202. package/dist/bootstrap.cjs +0 -43
  203. package/dist/bootstrap.cjs.map +0 -1
  204. package/dist/bootstrap.d.cts +0 -27
  205. package/dist/bootstrap.d.cts.map +0 -1
  206. package/dist/bootstrap.d.ts +0 -27
  207. package/dist/bootstrap.d.ts.map +0 -1
  208. package/dist/bootstrap.js +0 -40
  209. package/dist/bootstrap.js.map +0 -1
  210. package/dist/constant.cjs +0 -82
  211. package/dist/constant.cjs.map +0 -1
  212. package/dist/constant.d.cts +0 -69
  213. package/dist/constant.d.cts.map +0 -1
  214. package/dist/constant.d.ts +0 -69
  215. package/dist/constant.d.ts.map +0 -1
  216. package/dist/constant.js +0 -79
  217. package/dist/constant.js.map +0 -1
  218. package/dist/diff.cjs +0 -340
  219. package/dist/diff.cjs.map +0 -1
  220. package/dist/diff.d.cts +0 -51
  221. package/dist/diff.d.cts.map +0 -1
  222. package/dist/diff.d.ts +0 -51
  223. package/dist/diff.d.ts.map +0 -1
  224. package/dist/diff.js +0 -334
  225. package/dist/diff.js.map +0 -1
  226. package/dist/error.cjs +0 -204
  227. package/dist/error.cjs.map +0 -1
  228. package/dist/error.d.cts +0 -212
  229. package/dist/error.d.cts.map +0 -1
  230. package/dist/error.d.ts +0 -212
  231. package/dist/error.d.ts.map +0 -1
  232. package/dist/error.js +0 -191
  233. package/dist/error.js.map +0 -1
  234. package/dist/expect.cjs +0 -590
  235. package/dist/expect.cjs.map +0 -1
  236. package/dist/expect.d.cts +0 -138
  237. package/dist/expect.d.cts.map +0 -1
  238. package/dist/expect.d.ts +0 -138
  239. package/dist/expect.d.ts.map +0 -1
  240. package/dist/expect.js +0 -582
  241. package/dist/expect.js.map +0 -1
  242. package/dist/guards.cjs +0 -297
  243. package/dist/guards.cjs.map +0 -1
  244. package/dist/guards.d.cts +0 -231
  245. package/dist/guards.d.cts.map +0 -1
  246. package/dist/guards.d.ts +0 -231
  247. package/dist/guards.d.ts.map +0 -1
  248. package/dist/guards.js +0 -277
  249. package/dist/guards.js.map +0 -1
  250. package/dist/index.cjs +0 -111
  251. package/dist/index.cjs.map +0 -1
  252. package/dist/index.d.cts +0 -448
  253. package/dist/index.d.cts.map +0 -1
  254. package/dist/index.d.ts +0 -448
  255. package/dist/index.d.ts.map +0 -1
  256. package/dist/index.js +0 -71
  257. package/dist/index.js.map +0 -1
  258. package/dist/internal-schema.cjs +0 -253
  259. package/dist/internal-schema.cjs.map +0 -1
  260. package/dist/internal-schema.d.cts +0 -8
  261. package/dist/internal-schema.d.cts.map +0 -1
  262. package/dist/internal-schema.d.ts +0 -8
  263. package/dist/internal-schema.d.ts.map +0 -1
  264. package/dist/internal-schema.js +0 -248
  265. package/dist/internal-schema.js.map +0 -1
  266. package/dist/metadata.cjs +0 -57
  267. package/dist/metadata.cjs.map +0 -1
  268. package/dist/metadata.d.cts +0 -27
  269. package/dist/metadata.d.cts.map +0 -1
  270. package/dist/metadata.d.ts +0 -27
  271. package/dist/metadata.d.ts.map +0 -1
  272. package/dist/metadata.js +0 -54
  273. package/dist/metadata.js.map +0 -1
  274. package/dist/schema.cjs +0 -1522
  275. package/dist/schema.cjs.map +0 -1
  276. package/dist/schema.d.cts +0 -1196
  277. package/dist/schema.d.cts.map +0 -1
  278. package/dist/schema.d.ts +0 -1196
  279. package/dist/schema.d.ts.map +0 -1
  280. package/dist/schema.js +0 -1516
  281. package/dist/schema.js.map +0 -1
  282. package/dist/snapshot/adapter.cjs +0 -31
  283. package/dist/snapshot/adapter.cjs.map +0 -1
  284. package/dist/snapshot/adapter.d.cts +0 -258
  285. package/dist/snapshot/adapter.d.cts.map +0 -1
  286. package/dist/snapshot/adapter.d.ts +0 -258
  287. package/dist/snapshot/adapter.d.ts.map +0 -1
  288. package/dist/snapshot/adapter.js +0 -27
  289. package/dist/snapshot/adapter.js.map +0 -1
  290. package/dist/snapshot/adapters/fallback.cjs +0 -453
  291. package/dist/snapshot/adapters/fallback.cjs.map +0 -1
  292. package/dist/snapshot/adapters/fallback.d.cts +0 -185
  293. package/dist/snapshot/adapters/fallback.d.cts.map +0 -1
  294. package/dist/snapshot/adapters/fallback.d.ts +0 -185
  295. package/dist/snapshot/adapters/fallback.d.ts.map +0 -1
  296. package/dist/snapshot/adapters/fallback.js +0 -446
  297. package/dist/snapshot/adapters/fallback.js.map +0 -1
  298. package/dist/snapshot/adapters/node-test.cjs +0 -301
  299. package/dist/snapshot/adapters/node-test.cjs.map +0 -1
  300. package/dist/snapshot/adapters/node-test.d.cts +0 -131
  301. package/dist/snapshot/adapters/node-test.d.cts.map +0 -1
  302. package/dist/snapshot/adapters/node-test.d.ts +0 -131
  303. package/dist/snapshot/adapters/node-test.d.ts.map +0 -1
  304. package/dist/snapshot/adapters/node-test.js +0 -297
  305. package/dist/snapshot/adapters/node-test.js.map +0 -1
  306. package/dist/snapshot/index.cjs +0 -61
  307. package/dist/snapshot/index.cjs.map +0 -1
  308. package/dist/snapshot/index.d.cts +0 -40
  309. package/dist/snapshot/index.d.cts.map +0 -1
  310. package/dist/snapshot/index.d.ts +0 -40
  311. package/dist/snapshot/index.d.ts.map +0 -1
  312. package/dist/snapshot/index.js +0 -44
  313. package/dist/snapshot/index.js.map +0 -1
  314. package/dist/snapshot/node-version.cjs +0 -49
  315. package/dist/snapshot/node-version.cjs.map +0 -1
  316. package/dist/snapshot/node-version.d.cts +0 -34
  317. package/dist/snapshot/node-version.d.cts.map +0 -1
  318. package/dist/snapshot/node-version.d.ts +0 -34
  319. package/dist/snapshot/node-version.d.ts.map +0 -1
  320. package/dist/snapshot/node-version.js +0 -44
  321. package/dist/snapshot/node-version.js.map +0 -1
  322. package/dist/snapshot/select-adapter.cjs +0 -170
  323. package/dist/snapshot/select-adapter.cjs.map +0 -1
  324. package/dist/snapshot/select-adapter.d.cts +0 -128
  325. package/dist/snapshot/select-adapter.d.cts.map +0 -1
  326. package/dist/snapshot/select-adapter.d.ts +0 -128
  327. package/dist/snapshot/select-adapter.d.ts.map +0 -1
  328. package/dist/snapshot/select-adapter.js +0 -164
  329. package/dist/snapshot/select-adapter.js.map +0 -1
  330. package/dist/snapshot/serializer.cjs +0 -246
  331. package/dist/snapshot/serializer.cjs.map +0 -1
  332. package/dist/snapshot/serializer.d.cts +0 -126
  333. package/dist/snapshot/serializer.d.cts.map +0 -1
  334. package/dist/snapshot/serializer.d.ts +0 -126
  335. package/dist/snapshot/serializer.d.ts.map +0 -1
  336. package/dist/snapshot/serializer.js +0 -238
  337. package/dist/snapshot/serializer.js.map +0 -1
  338. package/dist/standard-schema.cjs +0 -13
  339. package/dist/standard-schema.cjs.map +0 -1
  340. package/dist/standard-schema.d.cts +0 -192
  341. package/dist/standard-schema.d.cts.map +0 -1
  342. package/dist/standard-schema.d.ts +0 -192
  343. package/dist/standard-schema.d.ts.map +0 -1
  344. package/dist/standard-schema.js +0 -12
  345. package/dist/standard-schema.js.map +0 -1
  346. package/dist/types.cjs +0 -22
  347. package/dist/types.cjs.map +0 -1
  348. package/dist/types.d.cts +0 -905
  349. package/dist/types.d.cts.map +0 -1
  350. package/dist/types.d.ts +0 -905
  351. package/dist/types.d.ts.map +0 -1
  352. package/dist/types.js +0 -21
  353. package/dist/types.js.map +0 -1
  354. package/dist/use.cjs +0 -240
  355. package/dist/use.cjs.map +0 -1
  356. package/dist/use.d.cts +0 -8
  357. package/dist/use.d.cts.map +0 -1
  358. package/dist/use.d.ts +0 -8
  359. package/dist/use.d.ts.map +0 -1
  360. package/dist/use.js +0 -236
  361. package/dist/use.js.map +0 -1
  362. package/dist/util.cjs +0 -255
  363. package/dist/util.cjs.map +0 -1
  364. package/dist/util.d.cts +0 -141
  365. package/dist/util.d.cts.map +0 -1
  366. package/dist/util.d.ts +0 -141
  367. package/dist/util.d.ts.map +0 -1
  368. package/dist/util.js +0 -234
  369. package/dist/util.js.map +0 -1
  370. package/dist/value-to-schema.cjs +0 -537
  371. package/dist/value-to-schema.cjs.map +0 -1
  372. package/dist/value-to-schema.d.cts +0 -144
  373. package/dist/value-to-schema.d.cts.map +0 -1
  374. package/dist/value-to-schema.d.ts +0 -144
  375. package/dist/value-to-schema.d.ts.map +0 -1
  376. package/dist/value-to-schema.js +0 -533
  377. package/dist/value-to-schema.js.map +0 -1
package/dist/schema.cjs DELETED
@@ -1,1522 +0,0 @@
1
- "use strict";
2
- /**
3
- * Arguably-useful Zod schemas for common types and validation patterns.
4
- *
5
- * This module provides reusable Zod schemas for validating constructors,
6
- * functions, property keys, promises, and other common JavaScript types used
7
- * throughout the assertion system. These tend to work around the impedance
8
- * mismatch between **BUPKIS** and Zod.
9
- *
10
- * These are used internally, but consumers may also find them useful.
11
- *
12
- * For example, we have {@link FunctionSchema} which accepts any
13
- * function—regardless of its signature. We need this because Zod v4's
14
- * `z.function()` no longer returns a `ZodType` (ref:
15
- * {@link https://zod.dev/v4/changelog | Zod v4 Migration Guide}) and so behaves
16
- * differently. `FunctionSchema` allows us to work with functions as _values_
17
- * instead of something to be implemented.
18
- *
19
- * Similarly—but not a new development—`z.promise()` does not parse a
20
- * {@link Promise} object; it parses the _fulfilled value_. This is not what we
21
- * want for "is a Promise" assertions, but it _can_ be useful for making sense
22
- * of the fulfilled value. To solve this, we have
23
- * {@link WrappedPromiseLikeSchema} (which explicitly supports
24
- * {@link PromiseLike}/"thenable" objects).
25
- *
26
- * @module schema
27
- * @category API
28
- * @example
29
- *
30
- * ```ts
31
- * import * as schema from 'bupkis/schema';
32
- * ```
33
- *
34
- * @groupDescription Schema
35
- * Schemas for common types and validation patterns.
36
- */
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.SyncIteratorSchema = exports.SyncIterableSchema = exports.SnapshotOptionsSchema = exports.createErrorMessageRegexSchema = exports.createErrorMessageSchema = exports.AnyObjectSchema = exports.WeakRefSchema = exports.WeakSetSchema = exports.UndefinedSchema = exports.NullSchema = exports.RegexpSchema = exports.ErrorSchema = exports.UnknownRecordSchema = exports.DateSchema = exports.UnknownArraySchema = exports.UnknownSchema = exports.SymbolSchema = exports.BigintSchema = exports.NegativeNumberSchema = exports.PositiveNumberSchema = exports.BooleanSchema = exports.NegativeInfinitySchema = exports.InfinitySchema = exports.NumberSchema = exports.StringSchema = exports.AnyMapSchema = exports.WeakMapSchema = exports.MapSchema = exports.AnySetSchema = exports.SetSchema = exports.DurationSchema = exports.DurationFormatSchema = exports.DateLikeFormatSchema = exports.ISODateFormatSchema = exports.TimestampFormatSchema = exports.NonNegativeIntegerSchema = exports.RegExpSchema = exports.ArrayLikeSchema = exports.PrimitiveSchema = exports.FalsySchema = exports.TruthySchema = exports.AsyncFunctionSchema = exports.NullProtoObjectSchema = exports.DictionarySchema = exports.WrappedPromiseLikeSchema = exports.KeypathSchema = exports.PropertyKeySchema = exports.NonCollectionObjectSchema = exports.FunctionSchema = exports.ConstructibleSchema = void 0;
39
- exports.AsyncIterableOrIteratorSchema = exports.AsyncIteratorSchema = exports.AsyncIterableSchema = exports.SyncIterableOrIteratorSchema = void 0;
40
- const zod_1 = require("zod");
41
- const constant_js_1 = require("./constant.cjs");
42
- const guards_js_1 = require("./guards.cjs");
43
- const metadata_js_1 = require("./metadata.cjs");
44
- const { getPrototypeOf, prototype: objectPrototype } = Object;
45
- const { asyncIterator: asyncIteratorSymbol, iterator: symbolIterator } = Symbol;
46
- const { isInteger } = Number;
47
- /**
48
- * A Zod schema that validates JavaScript constructible functions.
49
- *
50
- * This schema validates values that can be used as constructors, including ES6
51
- * classes, traditional constructor functions, and built-in constructors. It
52
- * uses the {@link isConstructible} guard function to determine if a value can be
53
- * invoked with the `new` operator to create object instances.
54
- *
55
- * @privateRemarks
56
- * The schema is registered in the {@link BupkisRegistry} with the name
57
- * `ConstructibleSchema` for later reference and type checking purposes.
58
- * @example Direct Usage
59
- *
60
- * ```typescript
61
- * class MyClass {}
62
- * function MyConstructor() {}
63
- *
64
- * ConstructibleSchema.parse(MyClass); // ✓ Valid
65
- * ConstructibleSchema.parse(MyConstructor); // ✓ Valid
66
- * ConstructibleSchema.parse(Array); // ✓ Valid
67
- * ConstructibleSchema.parse(Date); // ✓ Valid
68
- * ConstructibleSchema.parse(() => {}); // ✗ Throws validation error
69
- * ConstructibleSchema.parse({}); // ✗ Throws validation error
70
- * ```
71
- *
72
- * @example Assertion Creation
73
- *
74
- * ```ts
75
- * import { createAssertion, use } from 'bupkis';
76
- * import { ConstructibleSchema } from 'bupkis/schema';
77
- *
78
- * const classAssertion = createAssertion(
79
- * [ConstructibleSchema, 'to be a subclass of Error'],
80
- * ConstructibleSchema.refine(
81
- * (subject) => subject.prototype instanceof Error,
82
- * ),
83
- * );
84
- *
85
- * const { expect } = use([classAssertion]);
86
- * expect(class MyError extends Error {}, 'to be a subclass of Error');
87
- * ```
88
- *
89
- * @group Schema
90
- */
91
- exports.ConstructibleSchema = zod_1.z
92
- .custom(guards_js_1.isConstructible)
93
- .register(metadata_js_1.BupkisRegistry, { name: 'constructible' })
94
- .meta({ description: 'Constructible Function' });
95
- /**
96
- * A Zod schema that validates any JavaScript function.
97
- *
98
- * This schema accepts a function having any signature and avoids Zod's parsing
99
- * overhead.
100
- *
101
- * @remarks
102
- * Zod v~4.0.0 changed how {@link z.function z.function()} worked, which made it
103
- * unsuitable for validation. This was reverted in Zod v4.1.0.
104
- * @privateRemarks
105
- * The schema is registered in the {@link BupkisRegistry} with the name
106
- * `FunctionSchema` for later reference and type checking purposes.
107
- * @example Direct Usage
108
- *
109
- * ```typescript
110
- * FunctionSchema.parse(function () {}); // ✓ Valid
111
- * FunctionSchema.parse(() => {}); // ✓ Valid
112
- * FunctionSchema.parse(async () => {}); // ✓ Valid
113
- * FunctionSchema.parse(function* () {}); // ✓ Valid
114
- * FunctionSchema.parse(Math.max); // ✓ Valid
115
- * FunctionSchema.parse('not a function'); // ✗ Throws validation error
116
- * FunctionSchema.parse({}); // ✗ Throws validation error
117
- * ```
118
- *
119
- * @example Assertion Creation
120
- *
121
- * ```ts
122
- * import { createAssertion, use } from 'bupkis';
123
- * import { FunctionSchema } from 'bupkis/schema';
124
- *
125
- * const fnAssertion = createAssertion(
126
- * [FunctionSchema, 'to be a function with arity 2'],
127
- * FunctionSchema.refine((subject) => subject.length === 2),
128
- * );
129
- * const { expect } = use([fnAssertion]);
130
- * function add(a: number, b: number) {
131
- * return a + b;
132
- * }
133
- * expect(add, 'to be a function with arity 2');
134
- * ```
135
- *
136
- * @group Schema
137
- */
138
- exports.FunctionSchema = zod_1.z
139
- .custom(guards_js_1.isFunction)
140
- .register(metadata_js_1.BupkisRegistry, {
141
- name: 'function',
142
- })
143
- .meta({ description: 'Any function' });
144
- /**
145
- * A Zod schema that validates non-collection objects and functions.
146
- *
147
- * Accepts plain objects, functions, arrays, dates, etc. but rejects collection
148
- * types like `Map`, `Set`, `WeakMap`, and `WeakSet`.
149
- *
150
- * @example Direct Usage
151
- *
152
- * ```typescript
153
- * NonCollectionObjectSchema.parse({}); // ✓ Valid
154
- * NonCollectionObjectSchema.parse({ key: 'value' }); // ✓ Valid
155
- * NonCollectionObjectSchema.parse(function () {}); // ✓ Valid
156
- * NonCollectionObjectSchema.parse(() => {}); // ✓ Valid
157
- * NonCollectionObjectSchema.parse(new Map()); // ✗ Throws validation error
158
- * NonCollectionObjectSchema.parse(new Set()); // ✗ Throws validation error
159
- * NonCollectionObjectSchema.parse(null); // ✗ Throws validation error
160
- * NonCollectionObjectSchema.parse(42); // ✗ Throws validation error
161
- * ```
162
- *
163
- * @example Assertion Creation
164
- *
165
- * ```ts
166
- * import { createAssertion, use } from 'bupkis';
167
- * import { NonCollectionObjectSchema } from 'bupkis/schema';
168
- *
169
- * const nonCollectionAssertion = createAssertion(
170
- * [NonCollectionObjectSchema, 'to be a non-collection object'],
171
- * NonCollectionObjectSchema,
172
- * );
173
- * const { expect } = use([nonCollectionAssertion]);
174
- * expect({ key: 'value' }, 'to be a non-collection object');
175
- * ```
176
- *
177
- * @group Schema
178
- */
179
- exports.NonCollectionObjectSchema = zod_1.z
180
- .custom((v) => ((0, guards_js_1.isNonNullObject)(v) || (0, guards_js_1.isFunction)(v)) &&
181
- !(v instanceof Map) &&
182
- !(v instanceof Set) &&
183
- !(v instanceof WeakMap) &&
184
- !(v instanceof WeakSet))
185
- .register(metadata_js_1.BupkisRegistry, { name: 'non-collection-object' })
186
- .meta({ description: 'Non-collection object or function' });
187
- /**
188
- * A Zod schema that validates JavaScript property keys.
189
- *
190
- * This schema validates values that can be used as object property keys in
191
- * JavaScript, which includes strings, numbers, and symbols. These are the three
192
- * types that JavaScript automatically converts to property keys when used in
193
- * object access or assignment operations.
194
- *
195
- * @privateRemarks
196
- * The schema is registered in the `BupkisRegistry` with the name
197
- * `PropertyKeySchema` for later reference and type checking purposes.
198
- * @example Direct Usage
199
- *
200
- * ```typescript
201
- * PropertyKeySchema.parse('stringKey'); // ✓ Valid
202
- * PropertyKeySchema.parse(42); // ✓ Valid
203
- * PropertyKeySchema.parse(Symbol('symbolKey')); // ✓ Valid
204
- * PropertyKeySchema.parse({}); // ✗ Throws validation error
205
- * PropertyKeySchema.parse(null); // ✗ Throws validation error
206
- * ```
207
- *
208
- * @example Assertion Creation
209
- *
210
- * ```ts
211
- * import { createAssertion, use } from 'bupkis';
212
- * import { PropertyKeySchema } from 'bupkis/schema';
213
- * const unknownRecordAssertion = createAssertion(
214
- * ['to be a record of anything'],
215
- * z.record(PropertyKeySchema, z.unknown()),
216
- * );
217
- *
218
- * const { expect } = use([unknownRecordAssertion]);
219
- * expect(
220
- * { 42: pants, shirts: 'foo', [Symbol('baz')]: null },
221
- * 'to be a record of anything',
222
- * );
223
- * ```
224
- *
225
- * @group Schema
226
- */
227
- exports.PropertyKeySchema = zod_1.z
228
- .union([zod_1.z.string(), zod_1.z.number(), zod_1.z.symbol()])
229
- .register(metadata_js_1.BupkisRegistry, { name: 'property-key' })
230
- .meta({ description: 'Any valid object property name' });
231
- /**
232
- * A Zod schema that validates a keypath, which is a string featuring dot
233
- * notation or bracket notation, used to access nested object properties.
234
- *
235
- * Bare numbers must be wrapped in a string.
236
- *
237
- * @example Direct Usage
238
- *
239
- * ```typescript
240
- * KeypathSchema.parse('foo.bar'); // ✓ Valid
241
- * KeypathSchema.parse('arr[0].item'); // ✓ Valid
242
- * KeypathSchema.parse('obj["key"].prop'); // ✓ Valid
243
- * KeypathSchema.parse("obj['key'].prop"); // ✓ Valid
244
- * KeypathSchema.parse('simpleKey'); // ✓ Valid
245
- * KeypathSchema.parse('42'); // ✓ Valid
246
- * KeypathSchema.parse('invalid keypath!'); // ✗ Throws validation error
247
- * KeypathSchema.parse('foo..bar'); // ✗ Throws validation error
248
- * KeypathSchema.parse('foo[bar]'); // ✗ Throws validation error
249
- * KeypathSchema.parse(42); // ✗ Throws validation error
250
- * ```
251
- *
252
- * @example Assertion Creation
253
- *
254
- * ```ts
255
- * import { createAssertion, use } from 'bupkis';
256
- * import { KeypathSchema } from 'bupkis/schema';
257
- *
258
- * const hasKeypathAssertion = createAssertion(
259
- * [KeypathSchema, 'to be a keypath'],
260
- * KeypathSchema,
261
- * );
262
- *
263
- * const { expect } = use([hasKeypathAssertion]);
264
- * expect('foo.bar[0]["baz"]', 'to be a keypath');
265
- * ```
266
- *
267
- * @group Schema
268
- */
269
- exports.KeypathSchema = zod_1.z
270
- .string()
271
- .regex(constant_js_1.KEYPATH_REGEX)
272
- .register(metadata_js_1.BupkisRegistry, { name: 'keypath' })
273
- .meta({ description: 'A keypath supporting dot and bracket notation' });
274
- /**
275
- * A Zod schema that validates "thenable" objects with a `.then()` method.
276
- *
277
- * This schema validates objects that implement the PromiseLike interface by
278
- * having a `.then()` method, which includes Promises and other thenable
279
- * objects.
280
- *
281
- * Unlike Zod's built-in `z.promise()`, this schema does not unwrap the resolved
282
- * value, meaning the result of parsing remains a Promise or thenable object.
283
- *
284
- * @privateRemarks
285
- * The schema is registered in the `BupkisRegistry` with the name
286
- * `WrappedPromiseLikeSchema` for later reference and type checking purposes.
287
- * This is useful when you need to validate that something is thenable without
288
- * automatically resolving it.
289
- * @example Direct Usage
290
- *
291
- * ```typescript
292
- * WrappedPromiseLikeSchema.parse(Promise.resolve(42)); // ✓ Valid (returns Promise)
293
- * WrappedPromiseLikeSchema.parse({ then: () => {} }); // ✓ Valid (thenable)
294
- * WrappedPromiseLikeSchema.parse(42); // ✗ Throws validation error
295
- * WrappedPromiseLikeSchema.parse({}); // ✗ Throws validation error
296
- * ```
297
- *
298
- * @example Assertion Creation
299
- *
300
- * ```ts
301
- * import { createAssertion, use } from 'bupkis';
302
- * import { WrappedPromiseLikeSchema } from 'bupkis/schema';
303
- *
304
- * const thenableAssertion = createAssertion(
305
- * [WrappedPromiseLikeSchema, 'to be a thenable'],
306
- * WrappedPromiseLikeSchema,
307
- * );
308
- *
309
- * const { expect } = use([thenableAssertion]);
310
- * // does nothing with 'pants'; await it elsewhere
311
- * expect({ then: () => Promise.resolve('pants') }, 'to be a thenable');
312
- * ```
313
- *
314
- * @group Schema
315
- */
316
- exports.WrappedPromiseLikeSchema = zod_1.z
317
- .custom((value) => (0, guards_js_1.isPromiseLike)(value))
318
- .register(metadata_js_1.BupkisRegistry, { name: 'promiselike' })
319
- .meta({
320
- description: 'PromiseLike; unlike z.promise(), does not unwrap the resolved value',
321
- });
322
- /**
323
- * A Zod schema that validates plain objects with null prototypes.
324
- *
325
- * > Aliases: {@link NullProtoObjectSchema}, {@link DictionarySchema}
326
- *
327
- * This schema validates objects that have been created with
328
- * `Object.create(null)` or otherwise have their prototype set to `null`. Such
329
- * objects are "plain" objects without any inherited properties or methods from
330
- * `Object.prototype`, making them useful as pure data containers or
331
- * dictionaries.
332
- *
333
- * @privateRemarks
334
- * The schema is registered in the `BupkisRegistry` with the name
335
- * `ObjectWithNullPrototype` for later reference and type checking purposes.
336
- *
337
- * Changing this to be a `ZodRecord` would be nice, but that would end up
338
- * blasting away the original object's prototype.
339
- * @example Direct Usage
340
- *
341
- * ```typescript
342
- * const nullProtoObj = Object.create(null);
343
- * nullProtoObj.key = 'value';
344
- * NullProtoObjectSchema.parse(nullProtoObj); // ✓ Valid
345
- *
346
- * const regularObj = { key: 'value' };
347
- * NullProtoObjectSchema.parse(regularObj); // ✗ Throws validation error
348
- *
349
- * const emptyObj = {};
350
- * NullProtoObjectSchema.parse(emptyObj); // ✗ Throws validation error
351
- * ```
352
- *
353
- * @example Assertion Creation
354
- *
355
- * ```ts
356
- * import { createAssertion, use } from 'bupkis';
357
- * import { DictionarySchema } from 'bupkis/schema';
358
- *
359
- * const dictAssertion = createAssertion(
360
- * [DictionarySchema, 'to be a dictionary of numbers'],
361
- * DictionarySchema.pipe(z.record(z.number())),
362
- * );
363
- *
364
- * const { expect } = use([dictAssertion]);
365
- *
366
- * expect(Object.create(null, { pants: { value: 42, enumerable: true } }),
367
- * ```
368
- *
369
- * @group Schema
370
- */
371
- exports.DictionarySchema = zod_1.z
372
- .custom((value) => (0, guards_js_1.isNonNullObject)(value) && getPrototypeOf(value) === null)
373
- .register(metadata_js_1.BupkisRegistry, { name: 'dictionary' })
374
- .meta({ description: 'Object with null prototype' });
375
- /**
376
- * {@inheritDoc DictionarySchema}
377
- *
378
- * @group Schema
379
- */
380
- exports.NullProtoObjectSchema = exports.DictionarySchema;
381
- /**
382
- * A Zod schema that validates functions declared with the `async` keyword.
383
- *
384
- * This schema validates functions that are explicitly declared as asynchronous
385
- * using the `async` keyword. It uses runtime introspection to check the
386
- * function's internal `[[ToString]]` representation to distinguish async
387
- * functions from regular functions that might return Promises.
388
- *
389
- * @remarks
390
- * **This schema _cannot_ match a function that returns a {@link Promise} but was
391
- * not declared via `async`.** Determining if a function returns a `Promise` is
392
- * only possible by execution of said function (which <span
393
- * class="bupkis">BUPKIS</span> avoids, naturally). This is a limitation of
394
- * JavaScript itself.
395
- * @example Direct Usage
396
- *
397
- * ```typescript
398
- * async function asyncFn() {
399
- * return 42;
400
- * }
401
- * AsyncFunctionSchema.parse(asyncFn); // ✓ Valid
402
- *
403
- * const asyncArrow = async () => 42;
404
- * AsyncFunctionSchema.parse(asyncArrow); // ✓ Valid
405
- *
406
- * function syncFn() {
407
- * return Promise.resolve(42);
408
- * }
409
- * AsyncFunctionSchema.parse(syncFn); // ✗ Throws validation error
410
- *
411
- * const regularFn = () => 42;
412
- * AsyncFunctionSchema.parse(regularFn); // ✗ Throws validation error
413
- * ```
414
- *
415
- * @example Assertion Creation
416
- *
417
- * ```ts
418
- * import { createAssertion, use } from 'bupkis';
419
- * import { AsyncFunctionSchema } from 'bupkis/schema';
420
- *
421
- * const asyncFnAssertion = createAssertion(
422
- * [AsyncFunctionSchema, 'to be an async function'],
423
- * AsyncFunctionSchema,
424
- * );
425
- *
426
- * const { expect } = use([asyncFnAssertion]);
427
- * expect(async () => {}, 'to be an async function');
428
- * ```
429
- *
430
- * @group Schema
431
- */
432
- exports.AsyncFunctionSchema = exports.FunctionSchema.refine((value) => objectPrototype.toString.call(value) === '[object AsyncFunction]')
433
- .describe('Function declared with the `async` keyword')
434
- .register(metadata_js_1.BupkisRegistry, { name: 'async-function' });
435
- /**
436
- * A Zod schema that validates truthy JavaScript values.
437
- *
438
- * This schema accepts any input value but only validates successfully if the
439
- * value is truthy according to JavaScript's truthiness rules. A value is truthy
440
- * if it converts to `true` when evaluated in a boolean context - essentially
441
- * any value that is not one of the eight falsy values.
442
- *
443
- * @privateRemarks
444
- * The schema is registered in the `BupkisRegistry` with the name `Truthy` and
445
- * indicates that it accepts anything as valid input for evaluation.
446
- * @example Direct Usage
447
- *
448
- * ```typescript
449
- * TruthySchema.parse(true); // ✓ Valid
450
- * TruthySchema.parse(1); // ✓ Valid
451
- * TruthySchema.parse('hello'); // ✓ Valid
452
- * TruthySchema.parse([]); // ✓ Valid (arrays are truthy)
453
- * TruthySchema.parse({}); // ✓ Valid (objects are truthy)
454
- * TruthySchema.parse(false); // ✗ Throws validation error
455
- * TruthySchema.parse(0); // ✗ Throws validation error
456
- * TruthySchema.parse(''); // ✗ Throws validation error
457
- * TruthySchema.parse(null); // ✗ Throws validation error
458
- * ```
459
- *
460
- * @example Assertion Creation
461
- *
462
- * ```ts
463
- * import { createAssertion, use } from 'bupkis';
464
- * import { TruthySchema } from 'bupkis/schema';
465
- *
466
- * const somethingAssertion = createAssertion(
467
- * ['to be something'],
468
- * TruthySchema,
469
- * );
470
- *
471
- * const { expect } = use([somethingAssertion]);
472
- *
473
- * expect('pants', 'to be something');
474
- * ```
475
- *
476
- * @group Schema
477
- * @see {@link FalsySchema}
478
- */
479
- exports.TruthySchema = zod_1.z
480
- .any()
481
- .nonoptional()
482
- .refine((value) => !!value)
483
- .register(metadata_js_1.BupkisRegistry, {
484
- name: 'truthy',
485
- })
486
- .meta({ description: 'Truthy value' });
487
- /**
488
- * A Zod schema that validates falsy JavaScript values.
489
- *
490
- * This schema accepts any input value but only validates successfully if the
491
- * value is falsy according to JavaScript's truthiness rules. The falsy values
492
- * in JavaScript are: `false`, `0`, `-0`, `0n`, `""` (empty string), `null`,
493
- * `undefined`, and `NaN`.
494
- *
495
- * @privateRemarks
496
- * The schema is registered in the `BupkisRegistry` with the name `Falsy` and
497
- * indicates that it accepts anything as valid input for evaluation.
498
- * @example Direct Usage
499
- *
500
- * ```typescript
501
- * FalsySchema.parse(false); // ✓ Valid
502
- * FalsySchema.parse(0); // ✓ Valid
503
- * FalsySchema.parse(-0); // ✓ Valid
504
- * FalsySchema.parse(0n); // ✓ Valid (BigInt zero)
505
- * FalsySchema.parse(''); // ✓ Valid (empty string)
506
- * FalsySchema.parse(null); // ✓ Valid
507
- * FalsySchema.parse(undefined); // ✓ Valid
508
- * FalsySchema.parse(NaN); // ✓ Valid
509
- * FalsySchema.parse(true); // ✗ Throws validation error
510
- * FalsySchema.parse(1); // ✗ Throws validation error
511
- * FalsySchema.parse('hello'); // ✗ Throws validation error
512
- * FalsySchema.parse({}); // ✗ Throws validation error
513
- * ```
514
- *
515
- * @example Assertion Creation
516
- *
517
- * ```ts
518
- * import { createAssertion, use } from 'bupkis';
519
- * import { FalsySchema } from 'bupkis/schema';
520
- *
521
- * const falsyAssertion = createAssertion(['to be nothing'], FalsySchema);
522
- *
523
- * const { expect } = use([falsyAssertion]);
524
- *
525
- * expect('', 'to be nothing');
526
- * ```
527
- *
528
- * @group Schema
529
- * @see {@link TruthySchema}
530
- */
531
- exports.FalsySchema = zod_1.z
532
- .any()
533
- .nullable()
534
- .refine((value) => !value)
535
- .register(metadata_js_1.BupkisRegistry, { name: 'falsy' })
536
- .meta({ description: 'Falsy value' });
537
- /**
538
- * A Zod schema that validates primitive JavaScript values.
539
- *
540
- * This schema validates any of the seven primitive data types in JavaScript:
541
- * string, number, boolean, bigint, symbol, null, and undefined. Primitive
542
- * values are immutable and are passed by value rather than by reference,
543
- * distinguishing them from objects and functions which are non-primitive
544
- * reference types.
545
- *
546
- * @privateRemarks
547
- * The schema is registered in the `BupkisRegistry` with the name `Primitive`
548
- * and indicates that it accepts primitive values as valid input.
549
- * @example Direct Usage
550
- *
551
- * ```typescript
552
- * PrimitiveSchema.parse('hello'); // ✓ Valid (string)
553
- * PrimitiveSchema.parse(42); // ✓ Valid (number)
554
- * PrimitiveSchema.parse(true); // ✓ Valid (boolean)
555
- * PrimitiveSchema.parse(BigInt(123)); // ✓ Valid (bigint)
556
- * PrimitiveSchema.parse(Symbol('test')); // ✓ Valid (symbol)
557
- * PrimitiveSchema.parse(null); // ✓ Valid (null)
558
- * PrimitiveSchema.parse(undefined); // ✓ Valid (undefined)
559
- * PrimitiveSchema.parse({}); // ✗ Throws validation error (object)
560
- * PrimitiveSchema.parse([]); // ✗ Throws validation error (array)
561
- * PrimitiveSchema.parse(() => {}); // ✗ Throws validation error (function)
562
- * ```
563
- *
564
- * @example Assertion Creation
565
- *
566
- * ```ts
567
- * import { createAssertion, use } from 'bupkis';
568
- * import { PrimitiveSchema } from 'bupkis/schema';
569
- *
570
- * const primitiveAssertion = createAssertion(
571
- * ['to be a primitive, Date, or RegExp'],
572
- * PrimitiveSchema.or(z.instanceof(Date)).or(z.instanceof(RegExp)),
573
- * );
574
- *
575
- * const { expect } = use([primitiveAssertion]);
576
- *
577
- * expect('pants', 'to be a primitive, Date, or RegExp');
578
- * ```
579
- *
580
- * @group Schema
581
- */
582
- exports.PrimitiveSchema = zod_1.z
583
- .union([
584
- zod_1.z.string(),
585
- zod_1.z.number(),
586
- zod_1.z.boolean(),
587
- zod_1.z.bigint(),
588
- zod_1.z.symbol(),
589
- zod_1.z.null(),
590
- zod_1.z.undefined(),
591
- ])
592
- .register(metadata_js_1.BupkisRegistry, { name: 'primitive' })
593
- .meta({ description: 'Primitive value' });
594
- /**
595
- * A Zod schema that validates array-like structures including mutable and
596
- * readonly variants.
597
- *
598
- * This schema validates values that behave like arrays, including standard
599
- * arrays, tuples with rest elements, and their readonly counterparts. It
600
- * accepts any array-like structure that can hold elements of any type, making
601
- * it useful for validating collections where the specific array mutability or
602
- * tuple structure is not critical.
603
- *
604
- * @privateRemarks
605
- * The schema is registered in the {@link BupkisRegistry} with the name
606
- * `ArrayLike` for later reference and type checking purposes. This schema is
607
- * particularly useful when you need to accept various forms of array-like data
608
- * without being restrictive about mutability or exact tuple structure.
609
- * @example Direct Usage
610
- *
611
- * ```typescript
612
- * ArrayLikeSchema.parse([1, 2, 3]); // ✓ Valid (mutable array)
613
- * ArrayLikeSchema.parse(['a', 'b'] as const); // ✓ Valid (readonly array)
614
- * ArrayLikeSchema.parse([]); // ✓ Valid (empty array)
615
- * ArrayLikeSchema.parse([42, 'mixed', true]); // ✓ Valid (mixed types)
616
- * ArrayLikeSchema.parse('not an array'); // ✗ Throws validation error
617
- * ArrayLikeSchema.parse({}); // ✗ Throws validation error
618
- * ArrayLikeSchema.parse(null); // ✗ Throws validation error
619
- * ```
620
- *
621
- * @example Assertion Creation
622
- *
623
- * ```ts
624
- * import { createAssertion, use } from 'bupkis';
625
- * import { ArrayLikeSchema } from 'bupkis/schema';
626
- *
627
- * const argsAssertion = createAssertion(
628
- * [ArrayLikeSchema, 'to be a non-array arraylike object'],
629
- * ArrayLikeSchema.refine((subject) => !Array.isArray(subject)),
630
- * );
631
- *
632
- * const { expect } = use([argsAssertion]);
633
- * expect(
634
- * (function () {
635
- * return arguments;
636
- * })(),
637
- * 'to be a non-array arraylike object',
638
- * );
639
- * ```
640
- *
641
- * @group Schema
642
- */
643
- exports.ArrayLikeSchema = zod_1.z
644
- .custom((value) => value != null &&
645
- typeof value !== 'string' &&
646
- typeof value === 'object' &&
647
- symbolIterator in value &&
648
- 'length' in value &&
649
- typeof value.length === 'number' &&
650
- isInteger(value.length) &&
651
- value.length >= 0)
652
- .register(metadata_js_1.BupkisRegistry, {
653
- name: 'arraylike',
654
- })
655
- .meta({ description: 'Array-like value' });
656
- /**
657
- * A Zod schema that validates RegExp instances.
658
- *
659
- * This schema validates values that are instances of the RegExp class,
660
- * including regular expressions created with both literal syntax
661
- * (`/pattern/flags`) and the RegExp constructor (`new RegExp(pattern, flags)`).
662
- * It ensures the validated value is a proper regular expression object with all
663
- * associated methods and properties.
664
- *
665
- * @privateRemarks
666
- * The schema is registered in the `BupkisRegistry` with the name `RegExp` for
667
- * later reference and type checking purposes.
668
- * @example Direct Usage
669
- *
670
- * ```typescript
671
- * RegExpSchema.parse(/abc/gi); // ✓ Valid (literal syntax)
672
- * RegExpSchema.parse(new RegExp('abc', 'gi')); // ✓ Valid (constructor)
673
- * RegExpSchema.parse(/test/); // ✓ Valid (no flags)
674
- * RegExpSchema.parse(new RegExp('')); // ✓ Valid (empty pattern)
675
- * RegExpSchema.parse('abc'); // ✗ Throws validation error (string)
676
- * RegExpSchema.parse(/abc/.source); // ✗ Throws validation error (string pattern)
677
- * RegExpSchema.parse({}); // ✗ Throws validation error (object)
678
- * ```
679
- *
680
- * @example Assertion Creation
681
- *
682
- * ```ts
683
- * import { createAssertion, use } from 'bupkis';
684
- * import { RegExpSchema } from 'bupkis/schema';
685
- *
686
- * const globalRegexAssertion = createAssertion(
687
- * [RegExpSchema, 'to be a RegExp with the global flag'],
688
- * RegExpSchema.refine((subject) => subject.flags.includes('g')),
689
- * );
690
- *
691
- * const { expect } = use([globalRegexAssertion]);
692
- *
693
- * expect(/pants/g, 'to be a RegExp with the global flag');
694
- * ```
695
- *
696
- * @group Schema
697
- */
698
- exports.RegExpSchema = zod_1.z
699
- .instanceof(RegExp)
700
- .register(metadata_js_1.BupkisRegistry, { name: 'regexp' })
701
- .meta({ description: 'A RegExp instance' });
702
- /**
703
- * A Zod schema that validates non-negative integer values.
704
- *
705
- * This schema validates numbers that are both integers (whole numbers without
706
- * decimal parts) and non-negative (greater than or equal to zero). It combines
707
- * Zod's integer validation with non-negative validation to ensure the value is
708
- * a valid count, index, or other non-negative discrete quantity.
709
- *
710
- * @privateRemarks
711
- * The schema is registered in the {@link BupkisRegistry} with the name
712
- * `nonnegative-integer` for later reference and type checking purposes.
713
- * @example Direct Usage
714
- *
715
- * ```typescript
716
- * NonNegativeIntegerSchema.parse(0); // ✓ Valid (zero)
717
- * NonNegativeIntegerSchema.parse(42); // ✓ Valid (positive integer)
718
- * NonNegativeIntegerSchema.parse(1000); // ✓ Valid (large positive integer)
719
- * NonNegativeIntegerSchema.parse(-1); // ✗ Throws validation error (negative)
720
- * NonNegativeIntegerSchema.parse(3.14); // ✗ Throws validation error (not integer)
721
- * NonNegativeIntegerSchema.parse(-3.14); // ✗ Throws validation error (negative and not integer)
722
- * NonNegativeIntegerSchema.parse('42'); // ✗ Throws validation error (string)
723
- * ```
724
- *
725
- * @example Assertion Creation
726
- *
727
- * ```ts
728
- * import { createAssertion, use } from 'bupkis';
729
- * import { NonNegativeIntegerSchema } from 'bupkis/schema';
730
- *
731
- * const arrayIndexAssertion = createAssertion(
732
- * [NonNegativeIntegerSchema, 'to be a valid array index'],
733
- * NonNegativeIntegerSchema,
734
- * );
735
- *
736
- * const { expect } = use([arrayIndexAssertion]);
737
- * expect(0, 'to be a valid array index'); // Valid array index
738
- * expect(5, 'to be a valid array index'); // Valid array index
739
- * ```
740
- *
741
- * @group Schema
742
- */
743
- exports.NonNegativeIntegerSchema = zod_1.z
744
- .int()
745
- .nonnegative()
746
- .register(metadata_js_1.BupkisRegistry, { name: 'nonnegative-integer' })
747
- .meta({ description: 'A non-negative integer' });
748
- const MIN_TIMESTAMP = -8640000000000000;
749
- const MAX_TIMESTAMP = 8640000000000000;
750
- /**
751
- * A Zod schema that validates numeric timestamps.
752
- *
753
- * This schema validates JavaScript timestamp values (milliseconds since Unix
754
- * epoch) within the valid range for JavaScript Date objects. It ensures the
755
- * timestamp is an integer between -8,640,000,000,000,000 and
756
- * 8,640,000,000,000,000 milliseconds, which corresponds to the range of dates
757
- * that can be represented by JavaScript's Date object (approximately April 20,
758
- * 271821 BCE to September 13, 275760 CE).
759
- *
760
- * @example
761
- *
762
- * ```typescript
763
- * TimestampFormatSchema.parse(Date.now()); // ✓ Valid current timestamp
764
- * TimestampFormatSchema.parse(0); // ✓ Valid Unix epoch
765
- * TimestampFormatSchema.parse(-62135596800000); // ✓ Valid timestamp (year 1 CE)
766
- * TimestampFormatSchema.parse(1.5); // ✗ Throws - not an integer
767
- * TimestampFormatSchema.parse(9e15); // ✗ Throws - exceeds maximum timestamp
768
- * TimestampFormatSchema.parse('1234567890000'); // ✗ Throws - string not number
769
- * ```
770
- *
771
- * @group Schema
772
- */
773
- exports.TimestampFormatSchema = zod_1.z
774
- .int()
775
- .min(MIN_TIMESTAMP)
776
- .max(MAX_TIMESTAMP);
777
- /**
778
- * A Zod schema that validates ISO date strings.
779
- *
780
- * This schema validates ISO 8601 date and datetime strings in various formats.
781
- * It accepts both date-only formats (YYYY-MM-DD) and full datetime formats with
782
- * optional timezone information. The schema supports local datetime strings and
783
- * those with timezone offsets.
784
- *
785
- * @example
786
- *
787
- * ```typescript
788
- * ISODateFormatSchema.parse('2025-01-01'); // ✓ Valid ISO date
789
- * ISODateFormatSchema.parse('2025-01-01T10:30:00'); // ✓ Valid local datetime
790
- * ISODateFormatSchema.parse('2025-01-01T10:30:00Z'); // ✓ Valid UTC datetime
791
- * ISODateFormatSchema.parse('2025-01-01T10:30:00+05:30'); // ✓ Valid with offset
792
- * ISODateFormatSchema.parse('2025-01-01T10:30:00.123Z'); // ✓ Valid with milliseconds
793
- * ISODateFormatSchema.parse('01/01/2025'); // ✗ Throws - not ISO format
794
- * ISODateFormatSchema.parse('2025-13-01'); // ✗ Throws - invalid month
795
- * ISODateFormatSchema.parse('not-a-date'); // ✗ Throws - invalid format
796
- * ```
797
- *
798
- * @group Schema
799
- */
800
- exports.ISODateFormatSchema = zod_1.z.union([
801
- zod_1.z.iso.datetime({ local: true, offset: true }),
802
- zod_1.z.iso.date(),
803
- ]);
804
- /**
805
- * A Zod schema that validates date-like values.
806
- *
807
- * This schema accepts any value that can represent a date: native JavaScript
808
- * Date objects, ISO 8601 date strings, or numeric timestamps. It provides a
809
- * unified validation approach for date inputs across different assertion types.
810
- * The schema is registered in the BupkisRegistry for use in assertion
811
- * creation.
812
- *
813
- * @privateRemarks
814
- * This schema is registered with the name 'date-like' in the BupkisRegistry and
815
- * is commonly used in temporal assertions throughout the library.
816
- * @example
817
- *
818
- * ```typescript
819
- * DateLikeFormatSchema.parse(new Date()); // ✓ Valid Date object
820
- * DateLikeFormatSchema.parse('2025-01-01'); // ✓ Valid ISO date string
821
- * DateLikeFormatSchema.parse('2025-01-01T10:30:00Z'); // ✓ Valid ISO datetime
822
- * DateLikeFormatSchema.parse(Date.now()); // ✓ Valid timestamp
823
- * DateLikeFormatSchema.parse(0); // ✓ Valid Unix epoch
824
- * DateLikeFormatSchema.parse('invalid-date'); // ✗ Throws - invalid format
825
- * DateLikeFormatSchema.parse({}); // ✗ Throws - not date-like
826
- * DateLikeFormatSchema.parse(null); // ✗ Throws - null not accepted
827
- * ```
828
- *
829
- * @group Schema
830
- */
831
- exports.DateLikeFormatSchema = zod_1.z
832
- .union([zod_1.z.date(), exports.ISODateFormatSchema, exports.TimestampFormatSchema])
833
- .register(metadata_js_1.BupkisRegistry, { name: 'date-like' })
834
- .meta({ description: 'Date, ISO string, or timestamp' });
835
- const DURATION_REGEX = /^(\d+)\s*(milliseconds?|ms|seconds?|s|minutes?|m|hours?|h|days?|d|weeks?|w|months?|months?|years?|y)$/i;
836
- /**
837
- * A Zod schema that validates duration string formats.
838
- *
839
- * This schema validates human-readable duration strings using a flexible format
840
- * that supports various time units with both full names and abbreviations. The
841
- * format is "{amount} {unit}" where amount is a positive integer and unit can
842
- * be any supported time unit. Extra whitespace is automatically trimmed.
843
- *
844
- * Supported units (case-insensitive):
845
- *
846
- * - Milliseconds: `millisecond`, `milliseconds`, `ms`
847
- * - Seconds: `second`, `seconds`, `s`
848
- * - Minutes: `minute`, `minutes`, `m`
849
- * - Hours: `hour`, `hours`, `h`
850
- * - Days: `day`, `days`, `d`
851
- * - Weeks: `week`, `weeks`, `w`
852
- * - Months: `month`, `months` (approximate: 30 days)
853
- * - Years: `year`, `years`, `y` (approximate: 365 days)
854
- *
855
- * @privateRemarks
856
- * This schema only validates the format; it does not perform any
857
- * transformations. For converting to milliseconds, use {@link DurationSchema}
858
- * instead. The schema is registered with the name 'duration' in the
859
- * BupkisRegistry.
860
- * @example
861
- *
862
- * ```typescript
863
- * DurationFormatSchema.parse('1 hour'); // ✓ Valid
864
- * DurationFormatSchema.parse('30 minutes'); // ✓ Valid
865
- * DurationFormatSchema.parse('2 days'); // ✓ Valid
866
- * DurationFormatSchema.parse(' 5 seconds '); // ✓ Valid (whitespace trimmed)
867
- * DurationFormatSchema.parse('1h'); // ✓ Valid abbreviation
868
- * DurationFormatSchema.parse('10 ms'); // ✓ Valid milliseconds
869
- * DurationFormatSchema.parse('-5 minutes'); // ✗ Throws - negative not allowed
870
- * DurationFormatSchema.parse('1.5 hours'); // ✗ Throws - decimal not allowed
871
- * DurationFormatSchema.parse('5'); // ✗ Throws - missing unit
872
- * DurationFormatSchema.parse('five minutes'); // ✗ Throws - non-numeric amount
873
- * ```
874
- *
875
- * @group Schema
876
- */
877
- exports.DurationFormatSchema = zod_1.z
878
- .stringFormat('duration', (val) => DURATION_REGEX.test(val.trim()))
879
- .register(metadata_js_1.BupkisRegistry, { name: 'duration' })
880
- .meta({
881
- description: 'Duration string format like "1 hour", "30 minutes", "2 days"',
882
- });
883
- /**
884
- * A Zod schema that validates and transforms duration strings to milliseconds.
885
- *
886
- * This schema extends {@link DurationFormatSchema} by adding a transformation
887
- * step that converts valid duration strings into their equivalent values in
888
- * milliseconds. It supports the same flexible duration format but returns a
889
- * numeric value representing the total duration in milliseconds.
890
- *
891
- * The transformation handles all supported time units with accurate
892
- * conversions, except for months and years which use approximate values (30
893
- * days per month, 365 days per year) due to the variability of these units.
894
- *
895
- * Conversion rates:
896
- *
897
- * - 1 millisecond = 1 ms
898
- * - 1 second = 1,000 ms
899
- * - 1 minute = 60,000 ms
900
- * - 1 hour = 3,600,000 ms
901
- * - 1 day = 86,400,000 ms
902
- * - 1 week = 604,800,000 ms
903
- * - 1 month ≈ 2,592,000,000 ms (30 days)
904
- * - 1 year ≈ 31,536,000,000 ms (365 days)
905
- *
906
- * @privateRemarks
907
- * The transformation function includes comprehensive error handling, though
908
- * errors should never occur in practice due to the format validation step. The
909
- * schema is registered with the name 'duration' in the BupkisRegistry.
910
- * @example
911
- *
912
- * ```typescript
913
- * DurationSchema.parse('1 hour'); // → 3600000
914
- * DurationSchema.parse('30 minutes'); // → 1800000
915
- * DurationSchema.parse('2 days'); // → 172800000
916
- * DurationSchema.parse('500 ms'); // → 500
917
- * DurationSchema.parse('1 week'); // → 604800000
918
- * DurationSchema.parse('1 year'); // → 31536000000 (approximate)
919
- * DurationSchema.parse('invalid'); // ✗ Throws - invalid format
920
- * ```
921
- *
922
- * @group Schema
923
- */
924
- /**
925
- * Duration unit multipliers in milliseconds. Units are stored lowercase for
926
- * case-insensitive matching.
927
- */
928
- const DURATION_MULTIPLIERS = {
929
- d: 24 * 60 * 60 * 1000,
930
- day: 24 * 60 * 60 * 1000,
931
- days: 24 * 60 * 60 * 1000,
932
- h: 60 * 60 * 1000,
933
- hour: 60 * 60 * 1000,
934
- hours: 60 * 60 * 1000,
935
- m: 60 * 1000,
936
- millisecond: 1,
937
- milliseconds: 1,
938
- minute: 60 * 1000,
939
- minutes: 60 * 1000,
940
- month: 30 * 24 * 60 * 60 * 1000, // Approximate
941
- months: 30 * 24 * 60 * 60 * 1000, // Approximate
942
- ms: 1,
943
- s: 1000,
944
- second: 1000,
945
- seconds: 1000,
946
- w: 7 * 24 * 60 * 60 * 1000,
947
- week: 7 * 24 * 60 * 60 * 1000,
948
- weeks: 7 * 24 * 60 * 60 * 1000,
949
- y: 365 * 24 * 60 * 60 * 1000, // Approximate
950
- year: 365 * 24 * 60 * 60 * 1000, // Approximate
951
- years: 365 * 24 * 60 * 60 * 1000, // Approximate
952
- };
953
- exports.DurationSchema = exports.DurationFormatSchema.transform((duration) => {
954
- const match = duration.trim().match(DURATION_REGEX);
955
- if (!match) {
956
- throw new Error('Invalid duration format'); // Should never happen due to format validation
957
- }
958
- const [, amountStr, unit] = match;
959
- const amount = parseInt(amountStr, 10);
960
- const multiplier = DURATION_MULTIPLIERS[unit.toLowerCase()];
961
- if (multiplier === undefined) {
962
- throw new Error(`Unrecognized duration unit: ${unit}`); // Should never happen
963
- }
964
- return amount * multiplier;
965
- })
966
- .register(metadata_js_1.BupkisRegistry, { name: 'duration' })
967
- .describe('Duration string like "1 hour", "30 minutes", "2 days" (transforms to milliseconds)');
968
- /**
969
- * Schema that matches any `Set` instance, including those with any element
970
- * types.
971
- *
972
- * This schema is designed for runtime type checking and assertion matching
973
- * rather than parsing or validation of Set contents. It uses `instanceof`
974
- * checking to verify that a value is a Set, regardless of what elements it
975
- * contains.
976
- *
977
- * **Usage in Assertions:**
978
- *
979
- * - Collection size validation: `expect(mySet, 'to have size', 3)`
980
- * - Set operations: `expect(setA, 'to be a subset of', setB)`
981
- * - Emptiness checks: `expect(mySet, 'to be empty')`
982
- * - Element containment: `expect(mySet, 'to contain', value)`
983
- *
984
- * **Why `instanceof` Instead of Zod's `z.set()`:**
985
- *
986
- * - `z.set()` requires knowing the element schema at compile time
987
- * - This schema works with Sets containing any element types
988
- * - Focuses on the Set structure rather than element validation
989
- * - Better performance for assertion matching scenarios
990
- *
991
- * @example
992
- *
993
- * ```ts
994
- * // Matches any Set regardless of element types
995
- * SetSchema.parse(new Set([1, 2, 3])); // ✓ passes
996
- * SetSchema.parse(new Set(['a', 'b'])); // ✓ passes
997
- * SetSchema.parse(new Set()); // ✓ passes (empty Set)
998
- * SetSchema.parse([]); // ✗ fails (not a Set)
999
- * SetSchema.parse(new WeakSet()); // ✗ fails (use AnySetSchema)
1000
- * ```
1001
- *
1002
- * @group Schema
1003
- */
1004
- exports.SetSchema = zod_1.z
1005
- .instanceof(Set)
1006
- .register(metadata_js_1.BupkisRegistry, { name: 'set' })
1007
- .meta({ description: 'A Set instance' });
1008
- /**
1009
- * Schema that matches either `Set` or `WeakSet` instances.
1010
- *
1011
- * This unified schema handles both strong and weak Set types, making it useful
1012
- * for assertions that should work with either variant. The distinction between
1013
- * Set and WeakSet is important for garbage collection behavior but often
1014
- * irrelevant for structural assertions.
1015
- *
1016
- * **Key Differences Between Set and WeakSet:**
1017
- *
1018
- * - **Set**: Holds strong references, prevents GC, iterable, any value types
1019
- * - **WeakSet**: Holds weak references, allows GC, not iterable, object keys only
1020
- *
1021
- * **Usage Scenarios:**
1022
- *
1023
- * - Generic containment checks that work with both types
1024
- * - Polymorphic collection handling in assertion libraries
1025
- * - APIs that accept either Set variant for flexibility
1026
- *
1027
- * **WeakSet Limitations:**
1028
- *
1029
- * - Only accepts object or symbol values (primitives will cause runtime errors)
1030
- * - Cannot be iterated or have size checked
1031
- * - Some Set-specific assertions may not work with WeakSet
1032
- *
1033
- * @example
1034
- *
1035
- * ```ts
1036
- * // Accepts both Set and WeakSet
1037
- * AnySetSchema.parse(new Set([1, 2, 3])); // ✓ passes
1038
- * AnySetSchema.parse(new WeakSet([obj1, obj2])); // ✓ passes
1039
- * AnySetSchema.parse(new Map()); // ✗ fails (wrong collection type)
1040
- *
1041
- * // Usage in assertions
1042
- * expect(myWeakSet, 'to contain', someObject); // Works with WeakSet
1043
- * expect(mySet, 'to contain', 'string'); // Works with Set
1044
- * ```
1045
- *
1046
- * @group Schema
1047
- */
1048
- exports.AnySetSchema = exports.SetSchema.or(zod_1.z.instanceof(WeakSet))
1049
- .register(metadata_js_1.BupkisRegistry, { name: 'set-or-weakset' })
1050
- .describe('A Set or WeakSet instance');
1051
- /**
1052
- * Schema that matches any `Map` instance, including those with any key-value
1053
- * types.
1054
- *
1055
- * This schema provides runtime type checking for Map instances without
1056
- * requiring compile-time knowledge of key or value schemas. It uses
1057
- * `instanceof` checking to verify Map structure while being agnostic about the
1058
- * contained data types.
1059
- *
1060
- * **Usage in Assertions:**
1061
- *
1062
- * - Size validation: `expect(myMap, 'to have size', 5)`
1063
- * - Key presence: `expect(myMap, 'to have key', 'someKey')`
1064
- * - Value containment: `expect(myMap, 'to have value', expectedValue)`
1065
- * - Entry validation: `expect(myMap, 'to have entry', [key, value])`
1066
- * - Map equality: `expect(mapA, 'to equal', mapB)`
1067
- *
1068
- * **Advantages Over `z.map()`:**
1069
- *
1070
- * - Works with Maps having heterogeneous key/value types
1071
- * - No need to specify key and value schemas upfront
1072
- * - Optimized for structural validation rather than content parsing
1073
- * - Better error messages for type mismatches in assertions
1074
- *
1075
- * @example
1076
- *
1077
- * ```ts
1078
- * // Matches any Map regardless of key/value types
1079
- * MapSchema.parse(new Map([['key', 'value']])); // ✓ passes
1080
- * MapSchema.parse(
1081
- * new Map([
1082
- * [1, 'one'],
1083
- * [2, 'two'],
1084
- * ]),
1085
- * ); // ✓ passes
1086
- * MapSchema.parse(new Map()); // ✓ passes (empty Map)
1087
- * MapSchema.parse({}); // ✗ fails (plain object)
1088
- * MapSchema.parse(new WeakMap()); // ✗ fails (use AnyMapSchema)
1089
- * ```
1090
- *
1091
- * @group Schema
1092
- */
1093
- exports.MapSchema = zod_1.z
1094
- .instanceof(Map)
1095
- .register(metadata_js_1.BupkisRegistry, { name: 'map' })
1096
- .meta({ description: 'A Map instance' });
1097
- exports.WeakMapSchema = zod_1.z
1098
- .instanceof(WeakMap)
1099
- .register(metadata_js_1.BupkisRegistry, { name: 'weakmap' })
1100
- .meta({ description: 'A WeakMap instance' });
1101
- /**
1102
- * Schema that matches either `Map` or `WeakMap` instances.
1103
- *
1104
- * This union schema accommodates both strong and weak Map variants, enabling
1105
- * assertions to work polymorphically across both collection types. The choice
1106
- * between Map and WeakMap affects memory management and iteration capabilities
1107
- * but often doesn't impact structural validation logic.
1108
- *
1109
- * **Key Differences Between Map and WeakMap:**
1110
- *
1111
- * - **Map**: Strong references, enumerable, iterable, any key types, has `.size`
1112
- * - **WeakMap**: Weak references, not enumerable, not iterable, object keys only,
1113
- * no `.size`
1114
- *
1115
- * **Usage Considerations:**
1116
- *
1117
- * - Use for assertions that need to work with either Map type
1118
- * - Particularly useful in library code that accepts either variant
1119
- * - Some Map-specific operations (iteration, size) won't work with WeakMap
1120
- * - WeakMap key restrictions (objects/symbols only) should be considered
1121
- *
1122
- * **Memory Management Implications:**
1123
- *
1124
- * - Map entries prevent garbage collection of keys
1125
- * - WeakMap entries allow garbage collection when keys become unreachable
1126
- * - This affects long-lived caches and memory-sensitive applications
1127
- *
1128
- * @example
1129
- *
1130
- * ```ts
1131
- * // Accepts both Map and WeakMap
1132
- * AnyMapSchema.parse(new Map([['key', 'value']])); // ✓ passes
1133
- * AnyMapSchema.parse(new WeakMap([[obj, 'value']])); // ✓ passes
1134
- * AnyMapSchema.parse(new Set()); // ✗ fails (wrong collection type)
1135
- *
1136
- * // Usage in assertions
1137
- * expect(myWeakMap, 'to have key', someObject); // Works with WeakMap
1138
- * expect(myMap, 'to have key', 'stringKey'); // Works with Map
1139
- * expect(myWeakMap, 'to have size', 3); // ✗ Fails - WeakMap has no size
1140
- * ```
1141
- *
1142
- * @group Schema
1143
- */
1144
- exports.AnyMapSchema = exports.MapSchema.or(exports.WeakMapSchema)
1145
- .register(metadata_js_1.BupkisRegistry, { name: 'map-or-weakmap' })
1146
- .describe('A Map or WeakMap instance');
1147
- exports.StringSchema = zod_1.z
1148
- .string()
1149
- .register(metadata_js_1.BupkisRegistry, { name: 'string' })
1150
- .meta({ description: 'A string' });
1151
- exports.NumberSchema = zod_1.z
1152
- .number()
1153
- .register(metadata_js_1.BupkisRegistry, { name: 'number' })
1154
- .meta({ description: 'A number' });
1155
- exports.InfinitySchema = zod_1.z
1156
- .literal(Infinity)
1157
- .register(metadata_js_1.BupkisRegistry, { name: 'infinity' })
1158
- .meta({ description: 'The number Infinity' });
1159
- exports.NegativeInfinitySchema = zod_1.z
1160
- .literal(-Infinity)
1161
- .register(metadata_js_1.BupkisRegistry, { name: 'negative-infinity' })
1162
- .meta({ description: 'The number -Infinity' });
1163
- exports.BooleanSchema = zod_1.z
1164
- .boolean()
1165
- .register(metadata_js_1.BupkisRegistry, { name: 'boolean' })
1166
- .meta({ description: 'A boolean' });
1167
- exports.PositiveNumberSchema = zod_1.z
1168
- .number()
1169
- .positive()
1170
- .register(metadata_js_1.BupkisRegistry, { name: 'positive-number' })
1171
- .meta({ description: 'A positive number' });
1172
- exports.NegativeNumberSchema = zod_1.z
1173
- .number()
1174
- .negative()
1175
- .register(metadata_js_1.BupkisRegistry, { name: 'negative-number' })
1176
- .meta({ description: 'A negative number' });
1177
- exports.BigintSchema = zod_1.z
1178
- .bigint()
1179
- .register(metadata_js_1.BupkisRegistry, { name: 'bigint' })
1180
- .meta({ description: 'A bigint' });
1181
- exports.SymbolSchema = zod_1.z
1182
- .symbol()
1183
- .register(metadata_js_1.BupkisRegistry, { name: 'symbol' })
1184
- .meta({ description: 'A symbol' });
1185
- exports.UnknownSchema = zod_1.z
1186
- .unknown()
1187
- .register(metadata_js_1.BupkisRegistry, { name: 'unknown' })
1188
- .meta({ description: 'Unknown value' });
1189
- exports.UnknownArraySchema = zod_1.z
1190
- .array(exports.UnknownSchema)
1191
- .register(metadata_js_1.BupkisRegistry, { name: 'unknown-array' })
1192
- .meta({ description: 'An array of unknown values' });
1193
- exports.DateSchema = zod_1.z
1194
- .date()
1195
- .register(metadata_js_1.BupkisRegistry, { name: 'date' })
1196
- .meta({ description: 'A Date' });
1197
- exports.UnknownRecordSchema = zod_1.z
1198
- .record(exports.PropertyKeySchema, exports.UnknownSchema)
1199
- .register(metadata_js_1.BupkisRegistry, { name: 'record' })
1200
- .meta({ description: 'A record with unknown values and property keys' });
1201
- exports.ErrorSchema = zod_1.z
1202
- .instanceof(Error)
1203
- .register(metadata_js_1.BupkisRegistry, { name: 'error' })
1204
- .meta({ description: 'An Error instance' });
1205
- exports.RegexpSchema = zod_1.z
1206
- .instanceof(RegExp)
1207
- .register(metadata_js_1.BupkisRegistry, { name: 'regexp' })
1208
- .meta({ description: 'A RegExp instance' });
1209
- exports.NullSchema = zod_1.z
1210
- .null()
1211
- .register(metadata_js_1.BupkisRegistry, { name: 'null' })
1212
- .meta({ description: 'Null' });
1213
- exports.UndefinedSchema = zod_1.z
1214
- .undefined()
1215
- .register(metadata_js_1.BupkisRegistry, { name: 'undefined' })
1216
- .meta({ description: 'Undefined' });
1217
- exports.WeakSetSchema = zod_1.z
1218
- .instanceof(WeakSet)
1219
- .register(metadata_js_1.BupkisRegistry, { name: 'weakset' })
1220
- .meta({ description: 'A WeakSet instance' });
1221
- exports.WeakRefSchema = zod_1.z
1222
- .instanceof(WeakRef)
1223
- .register(metadata_js_1.BupkisRegistry, { name: 'weakref' })
1224
- .meta({ description: 'A WeakRef instance' });
1225
- exports.AnyObjectSchema = zod_1.z
1226
- .looseObject({})
1227
- .register(metadata_js_1.BupkisRegistry, { name: 'object' })
1228
- .meta({ description: 'An object with unknown properties' });
1229
- /**
1230
- * Memoizes {@link createErrorMessageSchema}
1231
- */
1232
- const errorMessageSchemaCache = new Map();
1233
- /**
1234
- * Memoizes {@link createErrorMessageRegexSchema}
1235
- */
1236
- const errorMessageRegexSchemaCache = new WeakMap();
1237
- /**
1238
- * @function
1239
- * @internal
1240
- */
1241
- const createErrorMessageSchema = (param) => {
1242
- const cached = errorMessageSchemaCache.get(param);
1243
- if (cached) {
1244
- return cached;
1245
- }
1246
- const schema = zod_1.z
1247
- .looseObject({
1248
- message: zod_1.z.coerce.string().pipe(zod_1.z.literal(param)),
1249
- })
1250
- .or(zod_1.z.coerce.string().pipe(zod_1.z.literal(param)));
1251
- errorMessageSchemaCache.set(param, schema);
1252
- return schema;
1253
- };
1254
- exports.createErrorMessageSchema = createErrorMessageSchema;
1255
- /**
1256
- * @function
1257
- * @internal
1258
- */
1259
- const createErrorMessageRegexSchema = (param) => {
1260
- const cached = errorMessageRegexSchemaCache.get(param);
1261
- if (cached) {
1262
- return cached;
1263
- }
1264
- const schema = zod_1.z
1265
- .looseObject({
1266
- message: zod_1.z.coerce.string().regex(param),
1267
- })
1268
- .or(zod_1.z.coerce.string().regex(param));
1269
- errorMessageRegexSchemaCache.set(param, schema);
1270
- return schema;
1271
- };
1272
- exports.createErrorMessageRegexSchema = createErrorMessageRegexSchema;
1273
- /**
1274
- * Schema for snapshot options.
1275
- */
1276
- exports.SnapshotOptionsSchema = zod_1.z.object({
1277
- hint: zod_1.z.string().optional(),
1278
- serializer: zod_1.z.any().optional(),
1279
- });
1280
- /**
1281
- * Schema matching any synchronous iterable (has `Symbol.iterator` method).
1282
- *
1283
- * This schema validates values that implement the synchronous iteration
1284
- * protocol, meaning they have a `Symbol.iterator` method that returns an
1285
- * iterator. This includes arrays, strings, Sets, Maps, generators, and custom
1286
- * iterable objects.
1287
- *
1288
- * @example Direct Usage
1289
- *
1290
- * ```typescript
1291
- * SyncIterableSchema.parse([1, 2, 3]); // ✓ Valid (array)
1292
- * SyncIterableSchema.parse('hello'); // ✓ Valid (string)
1293
- * SyncIterableSchema.parse(new Set()); // ✓ Valid (Set)
1294
- * SyncIterableSchema.parse(new Map()); // ✓ Valid (Map)
1295
- * SyncIterableSchema.parse(
1296
- * (function* () {
1297
- * yield 1;
1298
- * })(),
1299
- * ); // ✓ Valid (generator)
1300
- * SyncIterableSchema.parse(42); // ✗ Throws validation error
1301
- * SyncIterableSchema.parse({}); // ✗ Throws validation error (plain objects are not iterable)
1302
- * ```
1303
- *
1304
- * @example Assertion Creation
1305
- *
1306
- * ```ts
1307
- * import { createAssertion, use } from 'bupkis';
1308
- * import { SyncIterableSchema } from 'bupkis/schema';
1309
- *
1310
- * const iterableAssertion = createAssertion(
1311
- * [SyncIterableSchema, 'to be iterable'],
1312
- * SyncIterableSchema,
1313
- * );
1314
- *
1315
- * const { expect } = use([iterableAssertion]);
1316
- * expect([1, 2, 3], 'to be iterable');
1317
- * ```
1318
- *
1319
- * @group Schema
1320
- */
1321
- exports.SyncIterableSchema = zod_1.z
1322
- .custom((val) => val != null &&
1323
- typeof val[symbolIterator] === 'function', { error: 'Expected a synchronous iterable' })
1324
- .register(metadata_js_1.BupkisRegistry, { name: 'sync-iterable' })
1325
- .meta({ description: 'A synchronous iterable (has Symbol.iterator)' });
1326
- /**
1327
- * Schema matching any synchronous iterator (has `next()` method).
1328
- *
1329
- * This schema validates values that implement the iterator protocol, meaning
1330
- * they have a `next()` method that returns `{ value, done }` objects. This
1331
- * includes iterator objects returned from calling `Symbol.iterator` on
1332
- * iterables, generator objects, and custom iterator implementations.
1333
- *
1334
- * @remarks
1335
- * Note that most iterators are also iterable (they have `Symbol.iterator`
1336
- * returning `this`), but this schema specifically checks for the `next()`
1337
- * method which is the core iterator requirement.
1338
- * @example Direct Usage
1339
- *
1340
- * ```typescript
1341
- * const arr = [1, 2, 3];
1342
- * SyncIteratorSchema.parse(arr[Symbol.iterator]()); // ✓ Valid
1343
- * SyncIteratorSchema.parse(
1344
- * (function* () {
1345
- * yield 1;
1346
- * })(),
1347
- * ); // ✓ Valid (generators are iterators)
1348
- * SyncIteratorSchema.parse({
1349
- * next: () => ({ done: true, value: undefined }),
1350
- * }); // ✓ Valid
1351
- * SyncIteratorSchema.parse([1, 2, 3]); // ✗ Throws (array is iterable, not iterator)
1352
- * SyncIteratorSchema.parse({}); // ✗ Throws validation error
1353
- * ```
1354
- *
1355
- * @example Assertion Creation
1356
- *
1357
- * ```ts
1358
- * import { createAssertion, use } from 'bupkis';
1359
- * import { SyncIteratorSchema } from 'bupkis/schema';
1360
- *
1361
- * const iteratorAssertion = createAssertion(
1362
- * [SyncIteratorSchema, 'to be an iterator'],
1363
- * SyncIteratorSchema,
1364
- * );
1365
- *
1366
- * const { expect } = use([iteratorAssertion]);
1367
- * expect([1, 2, 3][Symbol.iterator](), 'to be an iterator');
1368
- * ```
1369
- *
1370
- * @group Schema
1371
- */
1372
- exports.SyncIteratorSchema = zod_1.z
1373
- .custom((val) => val != null &&
1374
- typeof val.next === 'function', { error: 'Expected a synchronous iterator' })
1375
- .register(metadata_js_1.BupkisRegistry, { name: 'sync-iterator' })
1376
- .meta({ description: 'A synchronous iterator (has next() method)' });
1377
- /**
1378
- * Schema matching either a sync iterable or sync iterator.
1379
- *
1380
- * This union schema accepts values that implement either the iterable protocol
1381
- * (has `Symbol.iterator`) or the iterator protocol (has `next()` method). This
1382
- * is useful for assertions that can work with either form, allowing users to
1383
- * pass arrays, generators, or raw iterators interchangeably.
1384
- *
1385
- * @example Direct Usage
1386
- *
1387
- * ```typescript
1388
- * SyncIterableOrIteratorSchema.parse([1, 2, 3]); // ✓ Valid (iterable)
1389
- * SyncIterableOrIteratorSchema.parse([1, 2, 3][Symbol.iterator]()); // ✓ Valid (iterator)
1390
- * SyncIterableOrIteratorSchema.parse(
1391
- * (function* () {
1392
- * yield 1;
1393
- * })(),
1394
- * ); // ✓ Valid (both)
1395
- * SyncIterableOrIteratorSchema.parse(42); // ✗ Throws validation error
1396
- * ```
1397
- *
1398
- * @group Schema
1399
- */
1400
- exports.SyncIterableOrIteratorSchema = zod_1.z
1401
- .union([exports.SyncIterableSchema, exports.SyncIteratorSchema])
1402
- .register(metadata_js_1.BupkisRegistry, { name: 'sync-iterable-or-iterator' })
1403
- .meta({ description: 'A synchronous iterable or iterator' });
1404
- /**
1405
- * Schema matching any asynchronous iterable (has `Symbol.asyncIterator`
1406
- * method).
1407
- *
1408
- * This schema validates values that implement the asynchronous iteration
1409
- * protocol, meaning they have a `Symbol.asyncIterator` method that returns an
1410
- * async iterator. This includes async generators, Node.js Readable streams
1411
- * (v10+), and Web ReadableStreams (in modern browsers and Node.js v22+).
1412
- *
1413
- * @example Direct Usage
1414
- *
1415
- * ```typescript
1416
- * AsyncIterableSchema.parse(
1417
- * (async function* () {
1418
- * yield 1;
1419
- * })(),
1420
- * ); // ✓ Valid (async generator)
1421
- * AsyncIterableSchema.parse(Readable.from([1, 2, 3])); // ✓ Valid (Node stream)
1422
- * AsyncIterableSchema.parse(new ReadableStream()); // ✓ Valid (Web stream, Node 22+)
1423
- * AsyncIterableSchema.parse([1, 2, 3]); // ✗ Throws (sync iterable, not async)
1424
- * AsyncIterableSchema.parse(Promise.resolve(1)); // ✗ Throws (Promise is not iterable)
1425
- * ```
1426
- *
1427
- * @example Assertion Creation
1428
- *
1429
- * ```ts
1430
- * import { createAssertion, use } from 'bupkis';
1431
- * import { AsyncIterableSchema } from 'bupkis/schema';
1432
- *
1433
- * const asyncIterableAssertion = createAssertion(
1434
- * [AsyncIterableSchema, 'to be an async iterable'],
1435
- * AsyncIterableSchema,
1436
- * );
1437
- *
1438
- * const { expect } = use([asyncIterableAssertion]);
1439
- * expect(
1440
- * (async function* () {
1441
- * yield 1;
1442
- * })(),
1443
- * 'to be an async iterable',
1444
- * );
1445
- * ```
1446
- *
1447
- * @group Schema
1448
- */
1449
- exports.AsyncIterableSchema = zod_1.z
1450
- .custom((val) => val != null &&
1451
- typeof val[asyncIteratorSymbol] ===
1452
- 'function', { error: 'Expected an asynchronous iterable' })
1453
- .register(metadata_js_1.BupkisRegistry, { name: 'async-iterable' })
1454
- .meta({ description: 'An asynchronous iterable (has Symbol.asyncIterator)' });
1455
- /**
1456
- * Schema matching any asynchronous iterator (has async `next()` method).
1457
- *
1458
- * This schema validates values that implement the async iterator protocol,
1459
- * meaning they have a `next()` method that returns a Promise of `{ value, done
1460
- * }`. This includes async iterator objects and custom async iterator
1461
- * implementations.
1462
- *
1463
- * @remarks
1464
- * This schema checks for the presence of a `next()` method but cannot verify at
1465
- * parse time that it returns a Promise. The async behavior is validated at
1466
- * iteration time.
1467
- * @example Direct Usage
1468
- *
1469
- * ```typescript
1470
- * const asyncGen = (async function* () {
1471
- * yield 1;
1472
- * })();
1473
- * AsyncIteratorSchema.parse(asyncGen); // ✓ Valid (async generator is also iterator)
1474
- * AsyncIteratorSchema.parse({
1475
- * next: async () => ({ done: true, value: undefined }),
1476
- * }); // ✓ Valid
1477
- * AsyncIteratorSchema.parse([1, 2, 3][Symbol.iterator]()); // ✓ Valid (has next())
1478
- * AsyncIteratorSchema.parse({}); // ✗ Throws validation error
1479
- * ```
1480
- *
1481
- * @group Schema
1482
- */
1483
- exports.AsyncIteratorSchema = zod_1.z
1484
- .custom((val) => val != null &&
1485
- typeof val.next === 'function', { error: 'Expected an asynchronous iterator' })
1486
- .register(metadata_js_1.BupkisRegistry, { name: 'async-iterator' })
1487
- .meta({ description: 'An asynchronous iterator (has next() method)' });
1488
- /**
1489
- * Schema matching either an async iterable or async iterator. Also accepts sync
1490
- * iterables (can be consumed async).
1491
- *
1492
- * This permissive union schema accepts values that can be iterated
1493
- * asynchronously, including:
1494
- *
1495
- * - Async iterables (has `Symbol.asyncIterator`)
1496
- * - Async iterators (has async `next()`)
1497
- * - Sync iterables (has `Symbol.iterator`) - these can be consumed via async
1498
- * iteration
1499
- *
1500
- * This flexibility allows async assertions to work uniformly with various
1501
- * iterable types.
1502
- *
1503
- * @example Direct Usage
1504
- *
1505
- * ```typescript
1506
- * AsyncIterableOrIteratorSchema.parse(
1507
- * (async function* () {
1508
- * yield 1;
1509
- * })(),
1510
- * ); // ✓ Valid
1511
- * AsyncIterableOrIteratorSchema.parse([1, 2, 3]); // ✓ Valid (sync iterable works)
1512
- * AsyncIterableOrIteratorSchema.parse(Readable.from([1, 2, 3])); // ✓ Valid
1513
- * AsyncIterableOrIteratorSchema.parse(42); // ✗ Throws validation error
1514
- * ```
1515
- *
1516
- * @group Schema
1517
- */
1518
- exports.AsyncIterableOrIteratorSchema = zod_1.z
1519
- .union([exports.AsyncIterableSchema, exports.AsyncIteratorSchema, exports.SyncIterableSchema])
1520
- .register(metadata_js_1.BupkisRegistry, { name: 'async-iterable-or-iterator' })
1521
- .meta({ description: 'An async iterable, async iterator, or sync iterable' });
1522
- //# sourceMappingURL=schema.js.map