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
@@ -1,850 +0,0 @@
1
- // do not remove; otherwise zshy will not resolve the .d.ts file; it must be referenced directly
2
- // eslint-disable-next-line @typescript-eslint/triple-slash-reference
3
- /// <reference path="./shims.d.ts" />
4
- /**
5
- * Collection-based assertions for arrays, objects, Maps, and Sets.
6
- *
7
- * These assertions handle operations like containment, size checking, and
8
- * set-theoretic operations for various collection types including native
9
- * JavaScript collections and WeakMap/WeakSet.
10
- *
11
- * @packageDocumentation
12
- * @groupDescription Collection Assertions
13
- * Assertions for arrays, objects, Maps, Sets, and collection operations.
14
- *
15
- * @showGroup
16
- */
17
- import setDifference from 'set.prototype.difference';
18
- import setIntersection from 'set.prototype.intersection';
19
- import isDisjointFrom from 'set.prototype.isdisjointfrom';
20
- import isSubsetOf from 'set.prototype.issubsetof';
21
- import isSupersetOf from 'set.prototype.issupersetof';
22
- import symmetricDifference from 'set.prototype.symmetricdifference';
23
- import setUnion from 'set.prototype.union';
24
- import { z } from 'zod';
25
- import { isWeakKey } from "../../guards.js";
26
- import { AnyMapSchema, AnySetSchema, KeypathSchema, MapSchema, NonCollectionObjectSchema, NonNegativeIntegerSchema, PropertyKeySchema, SetSchema, UnknownArraySchema, UnknownRecordSchema, UnknownSchema, } from "../../schema.js";
27
- import { has } from "../../util.js";
28
- import { valueToSchema, valueToSchemaOptionsForSatisfies, } from "../../value-to-schema.js";
29
- import { createAssertion } from "../create.js";
30
- const { hasOwn, keys } = Object;
31
- /**
32
- * Asserts that a Map or WeakMap contains a specific key. For WeakMap, the key
33
- * must be an object.
34
- *
35
- * @example
36
- *
37
- * ```ts
38
- * const map = new Map([['key', 'value']]);
39
- * expect(map, 'to contain', 'key'); // passes
40
- *
41
- * const obj = {};
42
- * const weakMap = new WeakMap([[obj, 'value']]);
43
- * expect(weakMap, 'to contain', obj); // passes
44
- * expect(weakMap, 'to contain', 'string'); // fails (not an object)
45
- * ```
46
- *
47
- * @group Collection Assertions
48
- * @bupkisAnchor map-to-contain-any
49
- * @bupkisAssertionCategory collections
50
- */
51
- export const mapContainsAssertion = createAssertion([AnyMapSchema, ['to contain', 'to include'], UnknownSchema], (subject, key) => {
52
- // WeakMap.has only works with object or symbol keys
53
- let hasKey;
54
- if (subject instanceof WeakMap) {
55
- if (!isWeakKey(key)) {
56
- return {
57
- message: `WeakMap keys must be objects or symbols, got ${typeof key}`,
58
- };
59
- }
60
- hasKey = subject.has(key);
61
- }
62
- else {
63
- hasKey = subject.has(key);
64
- }
65
- if (!hasKey) {
66
- return {
67
- actual: key,
68
- expected: `key to exist in ${subject.constructor.name}`,
69
- message: `Expected ${subject.constructor.name} to contain key`,
70
- };
71
- }
72
- });
73
- /**
74
- * Asserts that a Map has a specific size.
75
- *
76
- * @example
77
- *
78
- * ```ts
79
- * const map = new Map([
80
- * ['a', 1],
81
- * ['b', 2],
82
- * ]);
83
- * expect(map, 'to have size', 2); // passes
84
- * expect(map, 'to have size', 3); // fails
85
- * ```
86
- *
87
- * @group Collection Assertions
88
- * @bupkisAnchor map-to-have-size-nonnegative-integer
89
- * @bupkisAssertionCategory collections
90
- */
91
- export const mapSizeAssertion = createAssertion([MapSchema, 'to have size', NonNegativeIntegerSchema], (_subject, expectedSize) => z.map(z.unknown(), z.unknown()).refine((map) => map.size === expectedSize, {
92
- error: `Expected Map to have size ${expectedSize}`,
93
- }));
94
- /**
95
- * Asserts that a Map is empty.
96
- *
97
- * @example
98
- *
99
- * ```ts
100
- * expect(new Map(), 'to be empty'); // passes
101
- * expect(new Map([['key', 'value']]), 'to be empty'); // fails
102
- * ```
103
- *
104
- * @group Collection Assertions
105
- * @bupkisAnchor map-to-be-empty
106
- * @bupkisAssertionCategory collections
107
- */
108
- export const emptyMapAssertion = createAssertion([MapSchema, 'to be empty'], MapSchema.refine((map) => map.size === 0, {
109
- error: 'Expected Map to be empty',
110
- }));
111
- /**
112
- * Asserts that a Set or WeakSet contains a specific value. For WeakSet, the
113
- * value must be an object.
114
- *
115
- * @example
116
- *
117
- * ```ts
118
- * const set = new Set(['a', 'b']);
119
- * expect(set, 'to contain', 'a'); // passes
120
- *
121
- * const obj = {};
122
- * const weakSet = new WeakSet([obj]);
123
- * expect(weakSet, 'to contain', obj); // passes
124
- * expect(weakSet, 'to contain', 'string'); // fails (not an object)
125
- * ```
126
- *
127
- * @group Collection Assertions
128
- * @bupkisAnchor set-to-contain-any
129
- * @bupkisAssertionCategory collections
130
- */
131
- export const setContainsAssertion = createAssertion([AnySetSchema, ['to contain', 'to include'], UnknownSchema], (subject, value) => {
132
- // WeakSet.has only works with object or symbol values
133
- if (subject instanceof WeakSet && !isWeakKey(value)) {
134
- return {
135
- message: `WeakSet values must be objects or symbols, got ${typeof value}`,
136
- };
137
- }
138
- // At this point, if it's a WeakSet, we know value is a WeakKey
139
- const hasValue = subject instanceof WeakSet
140
- ? subject.has(value)
141
- : subject.has(value);
142
- if (!hasValue) {
143
- return {
144
- actual: value,
145
- expected: `value to exist in ${subject.constructor.name}`,
146
- message: `Expected ${subject.constructor.name} to contain value`,
147
- };
148
- }
149
- });
150
- /**
151
- * Asserts that a Set has a specific size.
152
- *
153
- * @example
154
- *
155
- * ```ts
156
- * const set = new Set(['a', 'b']);
157
- * expect(set, 'to have size', 2); // passes
158
- * expect(set, 'to have size', 3); // fails
159
- * ```
160
- *
161
- * @group Collection Assertions
162
- * @bupkisAnchor set-to-have-size-nonnegative-integer
163
- * @bupkisAssertionCategory collections
164
- */
165
- export const setSizeAssertion = createAssertion([SetSchema, 'to have size', NonNegativeIntegerSchema], (_subject, expectedSize) => z
166
- .set(z.unknown())
167
- .min(expectedSize, { error: `Expected Set to have size ${expectedSize}` })
168
- .max(expectedSize, {
169
- error: `Expected Set to have size ${expectedSize}`,
170
- }));
171
- /**
172
- * Asserts that a Set is empty.
173
- *
174
- * @example
175
- *
176
- * ```ts
177
- * expect(new Set(), 'to be empty'); // passes
178
- * expect(new Set(['value']), 'to be empty'); // fails
179
- * ```
180
- *
181
- * @group Collection Assertions
182
- * @bupkisAnchor set-to-be-empty
183
- * @bupkisAssertionCategory collections
184
- */
185
- export const emptySetAssertion = createAssertion([SetSchema, 'to be empty'], SetSchema.refine(({ size }) => size === 0, {
186
- error: 'Expected Set to be empty',
187
- }));
188
- /**
189
- * Asserts that an array contains a specific value.
190
- *
191
- * @example
192
- *
193
- * ```ts
194
- * expect([1, 2, 3], 'to contain', 2); // passes
195
- * expect([1, 2, 3], 'to contain', 4); // fails
196
- * ```
197
- *
198
- * @group Collection Assertions
199
- * @bupkisAnchor array-to-contain-any
200
- * @bupkisAssertionCategory collections
201
- */
202
- export const arrayContainsAssertion = createAssertion([UnknownArraySchema, ['to contain', 'to include'], UnknownSchema], (subject, value) => {
203
- if (!subject.includes(value)) {
204
- return {
205
- message: `Expected array to contain value`,
206
- };
207
- }
208
- });
209
- /**
210
- * Asserts that an array contains an item that satisfies a given shape or
211
- * pattern. Uses partial matching semantics - the item only needs to match the
212
- * specified properties.
213
- *
214
- * @example
215
- *
216
- * ```ts
217
- * expect([{ a: 1, b: 2 }, { c: 3 }], 'to have item satisfying', { a: 1 }); // passes
218
- * expect([{ a: 1 }, { b: 2 }], 'to have an item satisfying', { c: 3 }); // fails
219
- * expect([1, 2, 3], 'to contain item satisfying', 2); // passes (exact match)
220
- * ```
221
- *
222
- * @group Collection Assertions
223
- * @bupkisAnchor array-to-have-item-satisfying
224
- * @bupkisAssertionCategory collections
225
- */
226
- export const arrayItemSatisfiesAssertion = createAssertion([
227
- UnknownArraySchema,
228
- [
229
- 'to have item satisfying',
230
- 'to have an item satisfying',
231
- 'to contain item satisfying',
232
- ],
233
- UnknownSchema,
234
- ], (subject, shape) => {
235
- const schema = valueToSchema(shape, valueToSchemaOptionsForSatisfies);
236
- for (const item of subject) {
237
- const result = schema.safeParse(item);
238
- if (result.success) {
239
- return;
240
- }
241
- }
242
- return {
243
- message: `Expected array to contain an item satisfying the given shape`,
244
- };
245
- });
246
- /**
247
- * Asserts that an array has a specific size.
248
- *
249
- * @example
250
- *
251
- * ```ts
252
- * expect([1, 2, 3], 'to have length', 3); // passes
253
- * expect([1, 2, 3], 'to have size', 2); // fails
254
- * ```
255
- *
256
- * @group Collection Assertions
257
- * @bupkisAnchor array-to-have-size-nonnegative-integer
258
- * @bupkisAssertionCategory collections
259
- */
260
- export const arraySizeAssertion = createAssertion([
261
- UnknownArraySchema,
262
- ['to have length', 'to have size'],
263
- NonNegativeIntegerSchema,
264
- ], (_subject, expectedSize) => UnknownArraySchema.min(expectedSize, {
265
- error: `Expected array to have size ${expectedSize}}`,
266
- }).max(expectedSize, {
267
- error: `Expected array to have size ${expectedSize}}`,
268
- }));
269
- /**
270
- * Asserts that an array is non-empty.
271
- *
272
- * @example
273
- *
274
- * ```ts
275
- * expect([1, 2, 3], 'to be non-empty'); // passes
276
- * expect([], 'to be non-empty'); // fails
277
- * ```
278
- *
279
- * @group Collection Assertions
280
- * @bupkisAnchor array-not-to-be-empty
281
- * @bupkisAssertionCategory collections
282
- */
283
- export const nonEmptyArrayAssertion = createAssertion([UnknownArraySchema, 'to be non-empty'], UnknownArraySchema.min(1, { error: 'Expected array to be non-empty' }));
284
- /**
285
- * Asserts that an object has specific keys/properties.
286
- *
287
- * @example
288
- *
289
- * ```ts
290
- * expect({ a: 1, b: 2 }, 'to have keys', 'a', 'b'); // passes
291
- * expect({ a: 1 }, 'to have keys', 'a', 'b'); // fails
292
- * ```
293
- *
294
- * @group Collection Assertions
295
- * @bupkisAnchor object-to-have-keys-array
296
- * @bupkisAssertionCategory object
297
- */
298
- // TODO support keypaths, maybe.
299
- // TODO support `undefined` values (will require moving away from Zod schema)
300
- export const objectKeysAssertion = createAssertion([
301
- NonCollectionObjectSchema,
302
- [
303
- 'to have keys',
304
- 'to have properties',
305
- 'to have props',
306
- 'to contain keys',
307
- 'to contain properties',
308
- 'to contain props',
309
- 'to include keys',
310
- 'to include properties',
311
- 'to include props',
312
- ],
313
- z.array(PropertyKeySchema).nonempty(),
314
- ], (_subject, keys) => NonCollectionObjectSchema.superRefine((subject, ctx) => {
315
- // iterate thru keys and add an issue for each missing
316
- for (const k of keys) {
317
- if (!hasOwn(subject, k)) {
318
- ctx.addIssue({
319
- code: 'custom',
320
- input: subject,
321
- message: `Expected object to contain key "${String(k)}"`,
322
- params: { bupkisType: 'missing_key' },
323
- });
324
- }
325
- }
326
- }));
327
- /**
328
- * Asserts that an object has a property at the specified keypath using dot or
329
- * bracket notation. Uses the `has()` function to traverse nested properties and
330
- * supports complex keypaths like 'foo.bar[0]["baz"]'.
331
- *
332
- * This assertion supports:
333
- *
334
- * - Dot notation: 'prop.nested'
335
- * - Bracket notation with numbers: 'arr[0]'
336
- * - Bracket notation with quoted strings: 'obj["key"]' or "obj['key']"
337
- * - Mixed notation: 'data.items[1].name'
338
- *
339
- * @example
340
- *
341
- * ```ts
342
- * const obj = {
343
- * foo: { bar: [{ baz: 'value' }] },
344
- * 'kebab-case': 'works',
345
- * };
346
- *
347
- * expect(obj, 'to have key', 'foo.bar'); // passes
348
- * expect(obj, 'to have property', 'foo.bar[0].baz'); // passes
349
- * expect(obj, 'to have prop', 'foo["kebab-case"]'); // passes
350
- * expect(obj, 'to have key', 'nonexistent.path'); // fails
351
- * ```
352
- *
353
- * @group Collection Assertions
354
- * @bupkisAnchor object-to-have-key-string-number-symbol
355
- * @bupkisAssertionCategory object
356
- */
357
- export const objectKeyAssertion = createAssertion([
358
- NonCollectionObjectSchema,
359
- [
360
- 'to have key',
361
- 'to have property',
362
- 'to have prop',
363
- 'to contain key',
364
- 'to contain property',
365
- 'to contain prop',
366
- 'to include key',
367
- 'to include property',
368
- 'to include prop',
369
- ],
370
- KeypathSchema,
371
- ], (subject, keypath) => {
372
- const result = has(subject, keypath);
373
- if (!result) {
374
- return {
375
- actual: 'no such keypath',
376
- expect: `to have keypath ${keypath}`,
377
- message: `Expected object to contain keypath ${keypath}`,
378
- };
379
- }
380
- });
381
- /**
382
- * Asserts that an object has an exact property key without keypath traversal.
383
- * This assertion checks for direct properties on the object and supports
384
- * symbols and keys that would conflict with bracket/dot notation.
385
- *
386
- * Unlike `objectKeyAssertion`, this does not use the `has()` function and
387
- * therefore:
388
- *
389
- * - Does not support keypath traversal (no dots or brackets)
390
- * - Can check for symbol keys
391
- * - Can check for keys containing dots, brackets, or other special characters
392
- * - Only checks direct properties (no nested access)
393
- *
394
- * @example
395
- *
396
- * ```ts
397
- * const sym = Symbol('test');
398
- * const obj = {
399
- * simple: 'value',
400
- * 'key.with.dots': 'direct property',
401
- * 'key[with]brackets': 'another direct property',
402
- * [sym]: 'symbol value',
403
- * };
404
- *
405
- * expect(obj, 'to have exact key', 'simple'); // passes
406
- * expect(obj, 'to have exact property', 'key.with.dots'); // passes (literal key)
407
- * expect(obj, 'to have exact prop', 'key[with]brackets'); // passes (literal key)
408
- * expect(obj, 'to have exact key', sym); // passes (symbol key)
409
- *
410
- * // These would fail because they're not direct properties:
411
- * expect(obj, 'to have exact key', 'nested.path'); // fails (no keypath traversal)
412
- * ```
413
- *
414
- * @group Collection Assertions
415
- * @bupkisAnchor object-to-have-only-keys-array
416
- * @bupkisAssertionCategory object
417
- */
418
- export const objectExactKeyAssertion = createAssertion([
419
- NonCollectionObjectSchema,
420
- ['to have exact key', 'to have exact property', 'to have exact prop'],
421
- PropertyKeySchema,
422
- ], (_, key) => NonCollectionObjectSchema.transform((v) => ({ ...v })).refine((value) => hasOwn(value, key), { error: `Expected object to have own exact key "${String(key)}"` }));
423
- /**
424
- * Asserts that an object has a specific number of keys.
425
- *
426
- * @example
427
- *
428
- * ```ts
429
- * expect({ a: 1, b: 2 }, 'to have size', 2); // passes
430
- * expect({ a: 1 }, 'to have size', 2); // fails
431
- * ```
432
- *
433
- * @group Collection Assertions
434
- * @bupkisAnchor unknown-to-be-an-object
435
- * @bupkisAssertionCategory object
436
- */
437
- export const objectSizeAssertion = createAssertion([UnknownRecordSchema, 'to have size', NonNegativeIntegerSchema], (subject, expectedSize) => {
438
- const actual = keys(subject).length;
439
- if (actual !== expectedSize) {
440
- return {
441
- actual,
442
- expected: expectedSize,
443
- message: `Expected object to have ${expectedSize} keys, but it has ${actual} keys`,
444
- };
445
- }
446
- });
447
- /**
448
- * Asserts that two Sets are equal (same elements, order-independent).
449
- *
450
- * @example
451
- *
452
- * ```ts
453
- * expect(new Set([1, 2]), 'to equal', new Set([2, 1])); // passes
454
- * expect(new Set([1, 2]), 'to equal', new Set([1, 3])); // fails
455
- * ```
456
- *
457
- * @group Collection Assertions
458
- * @bupkisAnchor set-to-equal-set
459
- * @bupkisAssertionCategory collections
460
- */
461
- export const setEqualityAssertion = createAssertion([SetSchema, 'to equal', SetSchema], (actual, expected) => {
462
- return actual.size === expected.size && isSubsetOf(actual, expected);
463
- });
464
- /**
465
- * Asserts that one Set is a subset of another.
466
- *
467
- * @example
468
- *
469
- * ```ts
470
- * expect(new Set([1, 2]), 'to be a subset of', new Set([1, 2, 3])); // passes
471
- * expect(new Set([1, 4]), 'to be a subset of', new Set([1, 2, 3])); // fails
472
- * ```
473
- *
474
- * @group Collection Assertions
475
- * @bupkisAnchor set-to-be-a-subset-of-set
476
- * @bupkisAssertionCategory collections
477
- */
478
- export const setSubsetAssertion = createAssertion([SetSchema, 'to be a subset of', SetSchema], (subset, superset) => isSubsetOf(subset, superset));
479
- /**
480
- * Asserts that one Set is a superset of another.
481
- *
482
- * @example
483
- *
484
- * ```ts
485
- * expect(new Set([1, 2, 3]), 'to be a superset of', new Set([1, 2])); // passes
486
- * expect(new Set([1, 2]), 'to be a superset of', new Set([1, 2, 3])); // fails
487
- * ```
488
- *
489
- * @group Collection Assertions
490
- * @bupkisAnchor set-to-be-a-superset-of-set
491
- * @bupkisAssertionCategory collections
492
- */
493
- export const setSupersetAssertion = createAssertion([SetSchema, 'to be a superset of', SetSchema], (superset, subset) => isSupersetOf(superset, subset));
494
- /**
495
- * Asserts that two Sets intersect (have common elements).
496
- *
497
- * @example
498
- *
499
- * ```ts
500
- * expect(new Set([1, 2]), 'to intersect with', new Set([2, 3])); // passes
501
- * expect(new Set([1, 2]), 'to intersect with', new Set([3, 4])); // fails
502
- * ```
503
- *
504
- * @group Collection Assertions
505
- * @bupkisAnchor set-to-have-intersection-with-set-satisfying-any
506
- * @bupkisAssertionCategory collections
507
- */
508
- export const setIntersectionAssertion = createAssertion([SetSchema, 'to intersect with', SetSchema], (setA, setB) => !isDisjointFrom(setA, setB));
509
- /**
510
- * Asserts that two Sets are disjoint (have no common elements).
511
- *
512
- * @example
513
- *
514
- * ```ts
515
- * expect(new Set([1, 2]), 'to be disjoint from', new Set([3, 4])); // passes
516
- * expect(new Set([1, 2]), 'to be disjoint from', new Set([2, 3])); // fails
517
- * ```
518
- *
519
- * @group Collection Assertions
520
- * @bupkisAnchor set-to-be-disjoint-from-set
521
- * @bupkisAssertionCategory collections
522
- */
523
- export const setDisjointAssertion = createAssertion([SetSchema, 'to be disjoint from', SetSchema], (setA, setB) => isDisjointFrom(setA, setB));
524
- /**
525
- * Asserts that the union of two Sets equals a third Set.
526
- *
527
- * @example
528
- *
529
- * ```ts
530
- * expect(
531
- * new Set([1, 2]),
532
- * 'to have union',
533
- * new Set([3]),
534
- * 'equal to',
535
- * new Set([1, 2, 3]),
536
- * ); // passes
537
- * ```
538
- *
539
- * @group Collection Assertions
540
- * @bupkisAnchor set-union-with-set-to-equal-set
541
- * @bupkisAssertionCategory collections
542
- */
543
- export const setUnionEqualityAssertion = createAssertion([SetSchema, 'to have union', SetSchema, 'equal to', SetSchema], (setA, setB, expected) => {
544
- const result = setUnion(setA, setB);
545
- return (result.size === expected.size &&
546
- isSubsetOf(result, expected) &&
547
- isSubsetOf(expected, result));
548
- });
549
- /**
550
- * Asserts that the intersection of two Sets equals a third Set.
551
- *
552
- * @example
553
- *
554
- * ```ts
555
- * expect(
556
- * new Set([1, 2, 3]),
557
- * 'to have intersection',
558
- * new Set([2, 3, 4]),
559
- * 'equal to',
560
- * new Set([2, 3]),
561
- * ); // passes
562
- * ```
563
- *
564
- * @group Collection Assertions
565
- * @bupkisAnchor set-intersection-with-set-to-equal-set
566
- * @bupkisAssertionCategory collections
567
- */
568
- export const setIntersectionEqualityAssertion = createAssertion([SetSchema, 'to have intersection', SetSchema, 'equal to', SetSchema], (setA, setB, expected) => {
569
- const result = setIntersection(setA, setB);
570
- return (result.size === expected.size &&
571
- isSubsetOf(result, expected) &&
572
- isSubsetOf(expected, result));
573
- });
574
- /**
575
- * Asserts that the difference between two Sets equals a third Set.
576
- *
577
- * @example
578
- *
579
- * ```ts
580
- * expect(
581
- * new Set([1, 2, 3]),
582
- * 'to have difference',
583
- * new Set([2, 4]),
584
- * 'equal to',
585
- * new Set([1, 3]),
586
- * ); // passes
587
- * ```
588
- *
589
- * @group Collection Assertions
590
- * @bupkisAnchor set-difference-with-set-to-equal-set
591
- * @bupkisAssertionCategory collections
592
- */
593
- export const setDifferenceEqualityAssertion = createAssertion([SetSchema, 'to have difference', SetSchema, 'equal to', SetSchema], (setA, setB, expected) => {
594
- const result = setDifference(setA, setB);
595
- return (result.size === expected.size &&
596
- isSubsetOf(result, expected) &&
597
- isSubsetOf(expected, result));
598
- });
599
- /**
600
- * Asserts that the symmetric difference between two Sets equals a third Set.
601
- *
602
- * @example
603
- *
604
- * ```ts
605
- * expect(
606
- * new Set([1, 2]),
607
- * 'to have symmetric difference',
608
- * new Set([2, 3]),
609
- * 'equal to',
610
- * new Set([1, 3]),
611
- * ); // passes
612
- * ```
613
- *
614
- * @group Collection Assertions
615
- * @bupkisAnchor set-symmetric-difference-with-set-to-equal-set
616
- * @bupkisAssertionCategory collections
617
- */
618
- export const setSymmetricDifferenceEqualityAssertion = createAssertion([SetSchema, 'to have symmetric difference', SetSchema, 'equal to', SetSchema], (setA, setB, expected) => {
619
- const result = symmetricDifference(setA, setB);
620
- return (result.size === expected.size &&
621
- isSubsetOf(result, expected) &&
622
- isSubsetOf(expected, result));
623
- });
624
- /**
625
- * Asserts that a Map has a specific key.
626
- *
627
- * @example
628
- *
629
- * ```ts
630
- * const map = new Map([['key', 'value']]);
631
- * expect(map, 'to have key', 'key'); // passes
632
- * expect(map, 'to have key', 'missing'); // fails
633
- * ```
634
- *
635
- * @group Collection Assertions
636
- * @bupkisAnchor map-to-have-key-any
637
- * @bupkisAssertionCategory collections
638
- */
639
- export const mapKeyAssertion = createAssertion([MapSchema, 'to have key', UnknownSchema], (map, key) => {
640
- if (!map.has(key)) {
641
- return {
642
- actual: [...map.keys()],
643
- expected: [...map.keys(), key],
644
- message: 'Expected Map to have key',
645
- };
646
- }
647
- });
648
- /**
649
- * Asserts that a Map contains a specific value.
650
- *
651
- * @example
652
- *
653
- * ```ts
654
- * const map = new Map([['key', 'value']]);
655
- * expect(map, 'to have value', 'value'); // passes
656
- * expect(map, 'to have value', 'missing'); // fails
657
- * ```
658
- *
659
- * @group Collection Assertions
660
- * @bupkisAnchor map-to-have-value-any
661
- * @bupkisAssertionCategory collections
662
- */
663
- export const mapValueAssertion = createAssertion([
664
- MapSchema,
665
- ['to have value', 'to contain value', 'to include value'],
666
- UnknownSchema,
667
- ], (map, value) => {
668
- for (const mapValue of map.values()) {
669
- if (mapValue === value) {
670
- return;
671
- }
672
- }
673
- return {
674
- actual: [...map.values()],
675
- expected: value,
676
- message: `Expected Map to have value`,
677
- };
678
- });
679
- /**
680
- * Asserts that a Map has a specific key-value entry.
681
- *
682
- * @example
683
- *
684
- * ```ts
685
- * const map = new Map([['key', 'value']]);
686
- * expect(map, 'to have entry', ['key', 'value']); // passes
687
- * expect(map, 'to have entry', ['key', 'wrong']); // fails
688
- * ```
689
- *
690
- * @group Collection Assertions
691
- * @bupkisAnchor map-to-have-entry-any-any
692
- * @bupkisAssertionCategory collections
693
- */
694
- export const mapEntryAssertion = createAssertion([
695
- AnyMapSchema,
696
- [
697
- 'to have entry',
698
- 'to have key/value pair',
699
- 'to contain entry',
700
- 'to contain key/value pair',
701
- 'to include entry',
702
- 'to include key/value pair',
703
- ],
704
- z.tuple([UnknownSchema, UnknownSchema]),
705
- ], (map, [key, value]) => {
706
- // WeakMap operations only work with object or symbol keys
707
- if (map instanceof WeakMap && !isWeakKey(key)) {
708
- return {
709
- message: `WeakMap keys must be objects or symbols, got ${typeof key}`,
710
- };
711
- }
712
- // At this point, if it's a WeakMap, we know key is a WeakKey
713
- const actualValue = map instanceof WeakMap ? map.get(key) : map.get(key);
714
- if (actualValue === value) {
715
- return;
716
- }
717
- const hasKey = map instanceof WeakMap ? map.has(key) : map.has(key);
718
- return {
719
- actual: hasKey ? [key, actualValue] : undefined,
720
- expected: [key, value],
721
- message: hasKey
722
- ? `Expected ${map.constructor.name} entry [${String(key)}, ${String(actualValue)}] to equal [${String(key)}, ${String(value)}]`
723
- : `Expected ${map.constructor.name} to have key ${String(key)}`,
724
- };
725
- });
726
- /**
727
- * Asserts that two Maps are equal (same key-value pairs, order-independent).
728
- *
729
- * @example
730
- *
731
- * ```ts
732
- * const map1 = new Map([
733
- * ['a', 1],
734
- * ['b', 2],
735
- * ]);
736
- * const map2 = new Map([
737
- * ['b', 2],
738
- * ['a', 1],
739
- * ]);
740
- * expect(map1, 'to equal', map2); // passes
741
- * ```
742
- *
743
- * @group Collection Assertions
744
- * @bupkisAnchor map-to-equal-map
745
- * @bupkisAssertionCategory collections
746
- */
747
- export const mapEqualityAssertion = createAssertion([MapSchema, 'to equal', MapSchema], (mapA, mapB) => {
748
- if (mapA.size !== mapB.size) {
749
- return {
750
- actual: mapA.size,
751
- expected: mapB.size,
752
- message: `Expected Maps to have equal sizes, got ${mapA.size} and ${mapB.size}`,
753
- };
754
- }
755
- for (const [key, value] of mapA) {
756
- if (!mapB.has(key)) {
757
- return {
758
- message: `Expected second Map to contain key ${String(key)}`,
759
- };
760
- }
761
- if (mapB.get(key) !== value) {
762
- return {
763
- actual: [key, mapB.get(key)],
764
- expected: [key, value],
765
- message: `Expected Maps to have equal value for key ${String(key)}`,
766
- };
767
- }
768
- }
769
- });
770
- /**
771
- * Asserts that a collection (Map or Set) has a size greater than a threshold.
772
- *
773
- * @example
774
- *
775
- * ```ts
776
- * expect(new Set([1, 2, 3]), 'to have size greater than', 2); // passes
777
- * expect(new Set([1]), 'to have size greater than', 2); // fails
778
- * ```
779
- *
780
- * @group Collection Assertions
781
- * @bupkisAnchor collection-to-have-size-greater-than-nonnegative-integer
782
- * @bupkisAssertionCategory collections
783
- */
784
- export const collectionSizeGreaterThanAssertion = createAssertion([
785
- z.union([MapSchema, SetSchema]),
786
- 'to have size greater than',
787
- NonNegativeIntegerSchema,
788
- ], (collection, minSize) => {
789
- if (collection.size <= minSize) {
790
- return {
791
- actual: collection.size,
792
- expected: minSize,
793
- message: `Expected ${collection.constructor.name} to have size greater than ${minSize}, got ${collection.size}`,
794
- };
795
- }
796
- });
797
- /**
798
- * Asserts that a collection (Map or Set) has a size less than a threshold.
799
- *
800
- * @example
801
- *
802
- * ```ts
803
- * expect(new Set([1]), 'to have size less than', 2); // passes
804
- * expect(new Set([1, 2, 3]), 'to have size less than', 2); // fails
805
- * ```
806
- *
807
- * @group Collection Assertions
808
- * @bupkisAnchor collection-to-have-size-less-than-nonnegative-integer
809
- * @bupkisAssertionCategory collections
810
- */
811
- export const collectionSizeLessThanAssertion = createAssertion([
812
- z.union([MapSchema, SetSchema]),
813
- 'to have size less than',
814
- NonNegativeIntegerSchema,
815
- ], (collection, maxSize) => {
816
- if (collection.size >= maxSize) {
817
- return {
818
- actual: collection.size,
819
- expected: maxSize,
820
- message: `Expected ${collection.constructor.name} to have size less than ${maxSize}, got ${collection.size}`,
821
- };
822
- }
823
- });
824
- /**
825
- * Asserts that a collection (Map or Set) has a size within a specific range.
826
- *
827
- * @example
828
- *
829
- * ```ts
830
- * expect(new Set([1, 2]), 'to have size between', [1, 3]); // passes
831
- * expect(new Set([1, 2, 3, 4]), 'to have size between', [1, 3]); // fails
832
- * ```
833
- *
834
- * @group Collection Assertions
835
- * @bupkisAnchor collection-to-have-size-between-nonnegative-integer-and-nonnegative-integer
836
- * @bupkisAssertionCategory collections
837
- */
838
- export const collectionSizeBetweenAssertion = createAssertion([
839
- z.union([MapSchema, SetSchema]),
840
- 'to have size between',
841
- z.tuple([NonNegativeIntegerSchema, NonNegativeIntegerSchema]),
842
- ], (collection, [min, max]) => {
843
- const size = collection.size;
844
- if (!(size >= min && size <= max)) {
845
- return {
846
- message: `Expected ${collection.constructor.name} to have size between ${min} and ${max}, got ${size}`,
847
- };
848
- }
849
- });
850
- //# sourceMappingURL=sync-collection.js.map