bupkis 0.3.0 → 0.5.0

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 (206) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +26 -2
  3. package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
  4. package/dist/commonjs/assertion/assertion.js +74 -45
  5. package/dist/commonjs/assertion/assertion.js.map +1 -1
  6. package/dist/commonjs/assertion/impl/assertion-util.d.ts +189 -0
  7. package/dist/commonjs/assertion/impl/assertion-util.d.ts.map +1 -0
  8. package/dist/commonjs/assertion/impl/assertion-util.js +365 -0
  9. package/dist/commonjs/assertion/impl/assertion-util.js.map +1 -0
  10. package/dist/commonjs/assertion/impl/async-callback.d.ts +273 -0
  11. package/dist/commonjs/assertion/impl/async-callback.d.ts.map +1 -0
  12. package/dist/commonjs/assertion/impl/async-callback.js +427 -0
  13. package/dist/commonjs/assertion/impl/async-callback.js.map +1 -0
  14. package/dist/commonjs/assertion/impl/async-parametric.d.ts +250 -0
  15. package/dist/commonjs/assertion/impl/async-parametric.d.ts.map +1 -0
  16. package/dist/commonjs/assertion/impl/async-parametric.js +447 -0
  17. package/dist/commonjs/assertion/impl/async-parametric.js.map +1 -0
  18. package/dist/commonjs/assertion/impl/async.d.ts +93 -60
  19. package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
  20. package/dist/commonjs/assertion/impl/async.js +48 -271
  21. package/dist/commonjs/assertion/impl/async.js.map +1 -1
  22. package/dist/commonjs/assertion/impl/index.d.ts +19 -2
  23. package/dist/commonjs/assertion/impl/index.d.ts.map +1 -1
  24. package/dist/commonjs/assertion/impl/index.js +33 -5
  25. package/dist/commonjs/assertion/impl/index.js.map +1 -1
  26. package/dist/commonjs/assertion/impl/sync-basic.d.ts +518 -2
  27. package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -1
  28. package/dist/commonjs/assertion/impl/sync-basic.js +534 -60
  29. package/dist/commonjs/assertion/impl/sync-basic.js.map +1 -1
  30. package/dist/commonjs/assertion/impl/sync-callback.d.ts +281 -0
  31. package/dist/commonjs/assertion/impl/sync-callback.d.ts.map +1 -0
  32. package/dist/commonjs/assertion/impl/sync-callback.js +413 -0
  33. package/dist/commonjs/assertion/impl/sync-callback.js.map +1 -0
  34. package/dist/commonjs/assertion/impl/sync-collection.d.ts +484 -6
  35. package/dist/commonjs/assertion/impl/sync-collection.d.ts.map +1 -1
  36. package/dist/commonjs/assertion/impl/sync-collection.js +782 -52
  37. package/dist/commonjs/assertion/impl/sync-collection.js.map +1 -1
  38. package/dist/commonjs/assertion/impl/sync-esoteric.d.ts +143 -2
  39. package/dist/commonjs/assertion/impl/sync-esoteric.d.ts.map +1 -1
  40. package/dist/commonjs/assertion/impl/sync-esoteric.js +143 -8
  41. package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
  42. package/dist/commonjs/assertion/impl/sync-parametric.d.ts +489 -54
  43. package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
  44. package/dist/commonjs/assertion/impl/sync-parametric.js +747 -342
  45. package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
  46. package/dist/commonjs/assertion/impl/sync.d.ts +212 -66
  47. package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
  48. package/dist/commonjs/assertion/impl/sync.js +180 -12
  49. package/dist/commonjs/assertion/impl/sync.js.map +1 -1
  50. package/dist/commonjs/assertion/index.d.ts +2 -0
  51. package/dist/commonjs/assertion/index.d.ts.map +1 -1
  52. package/dist/commonjs/assertion/index.js +2 -0
  53. package/dist/commonjs/assertion/index.js.map +1 -1
  54. package/dist/commonjs/bootstrap.d.ts +45 -89
  55. package/dist/commonjs/bootstrap.d.ts.map +1 -1
  56. package/dist/commonjs/constant.d.ts +24 -1
  57. package/dist/commonjs/constant.d.ts.map +1 -1
  58. package/dist/commonjs/constant.js +31 -1
  59. package/dist/commonjs/constant.js.map +1 -1
  60. package/dist/commonjs/guards.d.ts +85 -1
  61. package/dist/commonjs/guards.d.ts.map +1 -1
  62. package/dist/commonjs/guards.js +92 -1
  63. package/dist/commonjs/guards.js.map +1 -1
  64. package/dist/commonjs/index.d.ts +47 -90
  65. package/dist/commonjs/index.d.ts.map +1 -1
  66. package/dist/commonjs/index.js +35 -1
  67. package/dist/commonjs/index.js.map +1 -1
  68. package/dist/commonjs/metadata.d.ts +3 -0
  69. package/dist/commonjs/metadata.d.ts.map +1 -1
  70. package/dist/commonjs/metadata.js +9 -6
  71. package/dist/commonjs/metadata.js.map +1 -1
  72. package/dist/commonjs/schema.d.ts +292 -83
  73. package/dist/commonjs/schema.d.ts.map +1 -1
  74. package/dist/commonjs/schema.js +320 -107
  75. package/dist/commonjs/schema.js.map +1 -1
  76. package/dist/commonjs/types.d.ts +144 -1
  77. package/dist/commonjs/types.d.ts.map +1 -1
  78. package/dist/commonjs/use.d.ts.map +1 -1
  79. package/dist/commonjs/use.js +15 -1
  80. package/dist/commonjs/use.js.map +1 -1
  81. package/dist/commonjs/util.d.ts +130 -26
  82. package/dist/commonjs/util.d.ts.map +1 -1
  83. package/dist/commonjs/util.js +227 -51
  84. package/dist/commonjs/util.js.map +1 -1
  85. package/dist/commonjs/value-to-schema.d.ts.map +1 -1
  86. package/dist/commonjs/value-to-schema.js +22 -2
  87. package/dist/commonjs/value-to-schema.js.map +1 -1
  88. package/dist/esm/assertion/assertion.d.ts.map +1 -1
  89. package/dist/esm/assertion/assertion.js +74 -45
  90. package/dist/esm/assertion/assertion.js.map +1 -1
  91. package/dist/esm/assertion/impl/assertion-util.d.ts +189 -0
  92. package/dist/esm/assertion/impl/assertion-util.d.ts.map +1 -0
  93. package/dist/esm/assertion/impl/assertion-util.js +348 -0
  94. package/dist/esm/assertion/impl/assertion-util.js.map +1 -0
  95. package/dist/esm/assertion/impl/async-callback.d.ts +273 -0
  96. package/dist/esm/assertion/impl/async-callback.d.ts.map +1 -0
  97. package/dist/esm/assertion/impl/async-callback.js +424 -0
  98. package/dist/esm/assertion/impl/async-callback.js.map +1 -0
  99. package/dist/esm/assertion/impl/async-parametric.d.ts +250 -0
  100. package/dist/esm/assertion/impl/async-parametric.d.ts.map +1 -0
  101. package/dist/esm/assertion/impl/async-parametric.js +444 -0
  102. package/dist/esm/assertion/impl/async-parametric.js.map +1 -0
  103. package/dist/esm/assertion/impl/async.d.ts +93 -60
  104. package/dist/esm/assertion/impl/async.d.ts.map +1 -1
  105. package/dist/esm/assertion/impl/async.js +47 -270
  106. package/dist/esm/assertion/impl/async.js.map +1 -1
  107. package/dist/esm/assertion/impl/index.d.ts +19 -2
  108. package/dist/esm/assertion/impl/index.d.ts.map +1 -1
  109. package/dist/esm/assertion/impl/index.js +19 -2
  110. package/dist/esm/assertion/impl/index.js.map +1 -1
  111. package/dist/esm/assertion/impl/sync-basic.d.ts +518 -2
  112. package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -1
  113. package/dist/esm/assertion/impl/sync-basic.js +534 -60
  114. package/dist/esm/assertion/impl/sync-basic.js.map +1 -1
  115. package/dist/esm/assertion/impl/sync-callback.d.ts +281 -0
  116. package/dist/esm/assertion/impl/sync-callback.d.ts.map +1 -0
  117. package/dist/esm/assertion/impl/sync-callback.js +410 -0
  118. package/dist/esm/assertion/impl/sync-callback.js.map +1 -0
  119. package/dist/esm/assertion/impl/sync-collection.d.ts +484 -6
  120. package/dist/esm/assertion/impl/sync-collection.d.ts.map +1 -1
  121. package/dist/esm/assertion/impl/sync-collection.js +780 -53
  122. package/dist/esm/assertion/impl/sync-collection.js.map +1 -1
  123. package/dist/esm/assertion/impl/sync-esoteric.d.ts +143 -2
  124. package/dist/esm/assertion/impl/sync-esoteric.d.ts.map +1 -1
  125. package/dist/esm/assertion/impl/sync-esoteric.js +142 -7
  126. package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
  127. package/dist/esm/assertion/impl/sync-parametric.d.ts +489 -54
  128. package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
  129. package/dist/esm/assertion/impl/sync-parametric.js +747 -342
  130. package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
  131. package/dist/esm/assertion/impl/sync.d.ts +212 -66
  132. package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
  133. package/dist/esm/assertion/impl/sync.js +166 -8
  134. package/dist/esm/assertion/impl/sync.js.map +1 -1
  135. package/dist/esm/assertion/index.d.ts +2 -0
  136. package/dist/esm/assertion/index.d.ts.map +1 -1
  137. package/dist/esm/assertion/index.js +2 -0
  138. package/dist/esm/assertion/index.js.map +1 -1
  139. package/dist/esm/bootstrap.d.ts +45 -89
  140. package/dist/esm/bootstrap.d.ts.map +1 -1
  141. package/dist/esm/constant.d.ts +24 -1
  142. package/dist/esm/constant.d.ts.map +1 -1
  143. package/dist/esm/constant.js +30 -0
  144. package/dist/esm/constant.js.map +1 -1
  145. package/dist/esm/guards.d.ts +85 -1
  146. package/dist/esm/guards.d.ts.map +1 -1
  147. package/dist/esm/guards.js +89 -0
  148. package/dist/esm/guards.js.map +1 -1
  149. package/dist/esm/index.d.ts +47 -90
  150. package/dist/esm/index.d.ts.map +1 -1
  151. package/dist/esm/index.js +1 -0
  152. package/dist/esm/index.js.map +1 -1
  153. package/dist/esm/metadata.d.ts +3 -0
  154. package/dist/esm/metadata.d.ts.map +1 -1
  155. package/dist/esm/metadata.js +9 -6
  156. package/dist/esm/metadata.js.map +1 -1
  157. package/dist/esm/schema.d.ts +292 -83
  158. package/dist/esm/schema.d.ts.map +1 -1
  159. package/dist/esm/schema.js +320 -107
  160. package/dist/esm/schema.js.map +1 -1
  161. package/dist/esm/types.d.ts +144 -1
  162. package/dist/esm/types.d.ts.map +1 -1
  163. package/dist/esm/use.d.ts.map +1 -1
  164. package/dist/esm/use.js +15 -1
  165. package/dist/esm/use.js.map +1 -1
  166. package/dist/esm/util.d.ts +130 -26
  167. package/dist/esm/util.d.ts.map +1 -1
  168. package/dist/esm/util.js +220 -48
  169. package/dist/esm/util.js.map +1 -1
  170. package/dist/esm/value-to-schema.d.ts.map +1 -1
  171. package/dist/esm/value-to-schema.js +24 -4
  172. package/dist/esm/value-to-schema.js.map +1 -1
  173. package/package.json +19 -6
  174. package/src/assertion/assertion.ts +82 -47
  175. package/src/assertion/impl/assertion-util.ts +409 -0
  176. package/src/assertion/impl/async-callback.ts +507 -0
  177. package/src/assertion/impl/async-parametric.ts +496 -0
  178. package/src/assertion/impl/async.ts +68 -311
  179. package/src/assertion/impl/index.ts +20 -2
  180. package/src/assertion/impl/shims.d.ts +62 -0
  181. package/src/assertion/impl/sync-basic.ts +671 -95
  182. package/src/assertion/impl/sync-callback.ts +483 -0
  183. package/src/assertion/impl/sync-collection.ts +909 -90
  184. package/src/assertion/impl/sync-esoteric.ts +162 -20
  185. package/src/assertion/impl/sync-parametric.ts +855 -428
  186. package/src/assertion/impl/sync.ts +289 -14
  187. package/src/assertion/index.ts +2 -0
  188. package/src/constant.ts +34 -0
  189. package/src/guards.ts +96 -1
  190. package/src/index.ts +3 -1
  191. package/src/metadata.ts +11 -7
  192. package/src/schema.ts +331 -114
  193. package/src/types.ts +184 -2
  194. package/src/use.ts +22 -0
  195. package/src/util.ts +259 -51
  196. package/src/value-to-schema.ts +28 -8
  197. package/dist/commonjs/assertion/impl/callback.d.ts +0 -104
  198. package/dist/commonjs/assertion/impl/callback.d.ts.map +0 -1
  199. package/dist/commonjs/assertion/impl/callback.js +0 -694
  200. package/dist/commonjs/assertion/impl/callback.js.map +0 -1
  201. package/dist/esm/assertion/impl/callback.d.ts +0 -104
  202. package/dist/esm/assertion/impl/callback.d.ts.map +0 -1
  203. package/dist/esm/assertion/impl/callback.js +0 -691
  204. package/dist/esm/assertion/impl/callback.js.map +0 -1
  205. package/src/assertion/impl/README.md +0 -13
  206. package/src/assertion/impl/callback.ts +0 -882
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0](https://github.com/boneskull/bupkis/compare/bupkis-v0.4.0...bupkis-v0.5.0) (2025-09-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * **assertions:** implement "to have key" and "to have exact key" ([8bb53cc](https://github.com/boneskull/bupkis/commit/8bb53cc6c6457b52f16f9057b1287005bc9a80df))
9
+ * more set/map assertions ([ec9e0f4](https://github.com/boneskull/bupkis/commit/ec9e0f46cd2ec0d0d097b54b3d0d9400fbb79c9d)), closes [#27](https://github.com/boneskull/bupkis/issues/27)
10
+ * **util:** implement `get` and `has` functions (like lodash's) supporting keypaths ([8bb53cc](https://github.com/boneskull/bupkis/commit/8bb53cc6c6457b52f16f9057b1287005bc9a80df))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * "to satisfy" now accepts any value for comparison ([ec9e0f4](https://github.com/boneskull/bupkis/commit/ec9e0f46cd2ec0d0d097b54b3d0d9400fbb79c9d))
16
+ * **assertions:** widen allowed subjects for "to have keys" assertion ([8bb53cc](https://github.com/boneskull/bupkis/commit/8bb53cc6c6457b52f16f9057b1287005bc9a80df))
17
+ * many edge cases ([ec9e0f4](https://github.com/boneskull/bupkis/commit/ec9e0f46cd2ec0d0d097b54b3d0d9400fbb79c9d))
18
+
19
+ ## [0.4.0](https://github.com/boneskull/bupkis/compare/bupkis-v0.3.0...bupkis-v0.4.0) (2025-09-15)
20
+
21
+
22
+ ### Features
23
+
24
+ * implement embeddable assertions ([3050d1c](https://github.com/boneskull/bupkis/commit/3050d1c0d57048a840449935fd0dfead370b0f11)), closes [#46](https://github.com/boneskull/bupkis/issues/46)
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * **schema:** rename ClassSchema to ConstructibleSchema ([#47](https://github.com/boneskull/bupkis/issues/47)) ([c497a24](https://github.com/boneskull/bupkis/commit/c497a249ad6428a8a2082aadfd7796c1e7f8b82f))
30
+
3
31
  ## [0.3.0](https://github.com/boneskull/bupkis/compare/bupkis-v0.2.0...bupkis-v0.3.0) (2025-09-14)
4
32
 
5
33
 
package/README.md CHANGED
@@ -111,9 +111,32 @@ To formalize the conventions at a high level:
111
111
  expect(subject, 'phrase', [parameter?, phrase?, parameter?, ...]);
112
112
  ```
113
113
 
114
- - One more convention worth mentioning is _negation_.
114
+ - If an assertion's phrase contains something like "to satisfy" or "satisfying", then the next parameter has special meaning. It is somewhat like Jest's `expect.objectContaining()`, but more powerful (prior art: [unexpected's `to satisfy` assertion](https://unexpected.js.org/assertions/any/to-satisfy/)).
115
115
 
116
- You can _negate_ just about any phrase by prepending it with `not` and a space. For example:
116
+ There are three (3) things to know about this parameter:
117
+ 1. It matches objects, but only verifies that the keys provided are present and the values match.
118
+ 2. If the value of any given property in an object is a _regular expression_, the real value will be coerced to a string and tested against the regular expression. This provides easy string matching within nested properties.
119
+ 3. _Any assertion_ (including custom assertions) can be embedded within them via the `expect.it()` function:
120
+
121
+ ```ts
122
+ expect(user, 'to satisfy', {
123
+ name: expect.it('to be a string'),
124
+ email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, // equivalent to "to match" below
125
+ age: expect.it('to be greater than', 18),
126
+ roles: [expect.it('to be a string')], // Each array element must be a string
127
+ metadata: {
128
+ lastLogin: expect.it('to match', /^\d{4}-\d{2}-\d{2}$/),
129
+ preferences: {
130
+ theme: expect.it('to be one of', ['light', 'dark']),
131
+ notifications: expect.it('to be a boolean'),
132
+ },
133
+ },
134
+ });
135
+ ```
136
+
137
+ > See [Embeddable Assertions][] for more a thorough explanation.
138
+
139
+ - You can _negate_ just about any phrase by prepending it with `not`. For example:
117
140
 
118
141
  ```js
119
142
  expect(actual, 'to be', expected);
@@ -224,3 +247,4 @@ Copyright © 2025 Christopher Hiller. Licensed under [BlueOak-1.0.0](https://blu
224
247
  [assertion-reference]: https://bupkis.zip/assertions
225
248
  [tshy]: https://github.com/isaacs/tshy
226
249
  [typedoc]: https://typedoc.org
250
+ [embeddable assertions]: https://bupkis.zip/documents/Basic_Usage#embeddable-assertions
@@ -1 +1 @@
1
- {"version":3,"file":"assertion.d.ts","sourceRoot":"","sources":["../../../src/assertion/assertion.ts"],"names":[],"mappings":"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C,mBAAmB,CAAC,IAAI,SAAS,WAAW,CAAC,KAAK,CAAC,EAC3D,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,OAAO,GACd,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC;IA4BhC;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,iBAAiB,CACzB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,QAAQ,EAAE,CAAC,CAAC,QAAQ,EACpB,GAAG,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,GAC7B,cAAc;IAIjB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,mBAAmB;CAW5B"}
@@ -22,12 +22,13 @@ const error_js_1 = require("../error.js");
22
22
  const metadata_js_1 = require("../metadata.js");
23
23
  const debug = (0, debug_1.default)('bupkis:assertion');
24
24
  /**
25
- * Modified charmap for {@link slug} to use underscores to replace hyphens (and
26
- * for hyphens to replace everything else that needs replacing).
25
+ * Modified charmap for {@link slug} to use underscores to replace hyphens (`-`;
26
+ * and for hyphens to replace everything else that needs replacing) and `<` with
27
+ * `_` (to distinguish type args)
27
28
  *
28
29
  * @see {@link BupkisAssertion.generateUniqueId} for usage
29
30
  */
30
- const SLUG_CHARMAP = { ...slug_1.default.charmap, '-': '_' };
31
+ const SLUG_CHARMAP = { ...slug_1.default.charmap, '-': '_', '<': '_', '>': '' };
31
32
  class BupkisAssertion {
32
33
  parts;
33
34
  slots;
@@ -51,54 +52,82 @@ class BupkisAssertion {
51
52
  * @returns String representation
52
53
  */
53
54
  toString() {
54
- const expand = (zodType) => {
55
+ const expand = (zodType, wrapCurlies = false) => {
55
56
  const def = 'def' in zodType ? zodType.def : zodType._zod.def;
56
- switch (def.type) {
57
- case 'custom': {
58
- const meta = metadata_js_1.BupkisRegistry.get(zodType);
59
- if (meta?.name) {
60
- // our name
61
- return `{${meta.name}}`;
62
- }
63
- else if ('Class' in zodType._zod.bag) {
57
+ let repr = '';
58
+ const meta = metadata_js_1.BupkisRegistry.get(zodType);
59
+ if (meta?.name) {
60
+ // our name
61
+ repr = meta.name;
62
+ }
63
+ else {
64
+ switch (def.type) {
65
+ case 'custom': {
64
66
  // internal Zod class name. will probably break.
65
- return `{${zodType._zod.bag.Class.name}}`;
67
+ try {
68
+ repr =
69
+ 'Class' in zodType._zod.bag
70
+ ? `${zodType._zod.bag.Class.name}`
71
+ : 'custom';
72
+ }
73
+ catch (err) {
74
+ debug(`Warning: Unable to extract custom class name from Zod type(did Zod's API change?): ${err}`);
75
+ repr = 'custom';
76
+ }
77
+ break;
66
78
  }
67
- return '{custom}';
79
+ case 'default':
80
+ repr = `{${expand(def.innerType)}}`;
81
+ break;
82
+ case 'enum':
83
+ repr = `${Object.keys(def.entries).join(' / ')}`;
84
+ break;
85
+ case 'intersection':
86
+ repr = `${expand(def.left)} & ${expand(def.right)}`;
87
+ break;
88
+ case 'literal':
89
+ repr = def.values
90
+ .map((value) => `'${value}'`)
91
+ .join(' / ');
92
+ break;
93
+ case 'map':
94
+ repr = `Map<${expand(def.keyType)}, ${expand(def.valueType)}>`;
95
+ break;
96
+ case 'nonoptional':
97
+ repr = `${expand(def.innerType)}!`;
98
+ break;
99
+ case 'nullable':
100
+ repr = `${expand(def.innerType)}? | null`;
101
+ break;
102
+ case 'optional':
103
+ repr = `${expand(def.innerType)}?`;
104
+ break;
105
+ case 'record':
106
+ repr = `Record<${expand(def.keyType)}, ${expand(def.valueType)}>`;
107
+ break;
108
+ case 'set':
109
+ repr = `Set<${expand(def.valueType)}>`;
110
+ break;
111
+ case 'tuple':
112
+ repr = `[${def.items.map((value) => expand(value)).join(', ')}]`;
113
+ break;
114
+ case 'union':
115
+ repr = def.options
116
+ .map((value) => expand(value))
117
+ .join(' | ');
118
+ break;
119
+ default:
120
+ repr = def.type;
121
+ break;
68
122
  }
69
- case 'default':
70
- return `{${expand(def.innerType)}}`;
71
- case 'enum':
72
- return `${Object.keys(def.entries).join(' / ')}`;
73
- case 'intersection':
74
- return `${expand(def.left)} & ${expand(def.right)}`;
75
- case 'literal':
76
- return def.values
77
- .map((value) => `'${value}'`)
78
- .join(' / ');
79
- case 'map':
80
- return `{Map<${expand(def.keyType)}, ${expand(def.valueType)}>`;
81
- case 'nonoptional':
82
- return `${expand(def.innerType)}!`;
83
- case 'nullable':
84
- return `${expand(def.innerType)}? | null`;
85
- case 'optional':
86
- return `${expand(def.innerType)}?`;
87
- case 'record':
88
- return `{Record<${expand(def.keyType)}, ${expand(def.valueType)}>`;
89
- case 'set':
90
- return `{Set<${expand(def.valueType)}>`;
91
- case 'tuple':
92
- return `[${def.items.map(expand).join(', ')}]`;
93
- case 'union':
94
- return def.options
95
- .map(expand)
96
- .join(' | ');
97
- default:
98
- return `{${def.type}}`;
99
123
  }
124
+ return wrapCurlies ? `{${repr}}` : repr;
100
125
  };
101
- return `"${this.slots.map(expand).join(' ')}"`;
126
+ return `"${this.slots
127
+ .map((slot) => Object.hasOwn(metadata_js_1.BupkisRegistry.get(slot) ?? {}, constant_js_1.kStringLiteral)
128
+ ? expand(slot)
129
+ : expand(slot, true))
130
+ .join(' ')}"`;
102
131
  }
103
132
  maybeParseValuesArgMismatch(args) {
104
133
  if (this.slots.length !== args.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"assertion.js","sourceRoot":"","sources":["../../../src/assertion/assertion.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,kDAA0B;AAC1B,gDAAwB;AAExB,+BAA+B;AAG/B,gDAAgD;AAChD,0CAA6C;AAC7C,gDAAgD;AAUhD,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,kBAAkB,CAAC,CAAC;AAExC;;;;;GAKG;AACH,MAAM,YAAY,GAAG,EAAE,GAAG,cAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEnD,MAAsB,eAAe;IASxB;IACA;IACA;IALF,EAAE,CAAS;IAEpB,YACW,KAAY,EACZ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,QAAQ,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;oBACnC,OAAO;wBACL,OAAO,EAAE,KAAK;qBACf,CAAC;gBACJ,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,oBAAoB;gBACpB,MAAM,IAAI,SAAS,CACjB,6BAA6B,SAAS,eAAe,IAAA,cAAO,EAAC,MAAM,CAAC,EAAE,CACvE,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,iBAAiB,CACzB,YAAqC,EACrC,QAAoB,EACpB,GAAG,MAA2B;QAE9B,OAAO,yBAAc,CAAC,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACK,mBAAmB;QACzB,MAAM,QAAQ,GAAG,IAAA,cAAI,EAAC,GAAG,IAAI,EAAE,EAAE;YAC/B,OAAO,EAAE,YAAY;SACtB,CAAC,CAAC;QAEH,qDAAqD;QACrD,2DAA2D;QAC3D,MAAM,SAAS,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAE/D,OAAO,GAAG,QAAQ,IAAI,SAAS,EAAE,CAAC;IACpC,CAAC;CACF;AArND,0CAqNC"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Utility functions for assertion implementations
3
+ *
4
+ * @internal
5
+ * @packageDocumentation
6
+ */
7
+ import { z } from 'zod/v4';
8
+ import { type ValueToSchemaOptions } from '../../value-to-schema.js';
9
+ /**
10
+ * Creates a standardized error object for when a callback or nodeback is not
11
+ * called.
12
+ *
13
+ * @param type - The type of callback ('callback' or 'nodeback')
14
+ * @returns Error object with consistent structure for sync assertions
15
+ */
16
+ export declare const createNotCalledError: (type: "callback" | "nodeback") => {
17
+ actual: string;
18
+ expected: string;
19
+ message: string;
20
+ };
21
+ /**
22
+ * Creates a standardized error object for when a callback or nodeback is not
23
+ * called in async contexts. Uses consistent field naming for async assertions.
24
+ *
25
+ * @param type - The type of callback ('callback' or 'nodeback')
26
+ * @returns Error object with consistent structure for async assertions
27
+ */
28
+ export declare const createAsyncNotCalledError: (type: "callback" | "nodeback") => {
29
+ actual: string;
30
+ expected: string;
31
+ message: string;
32
+ };
33
+ /**
34
+ * Creates error objects for nodeback error state mismatches in sync contexts.
35
+ * Handles cases where an error is expected but not present, or vice versa.
36
+ *
37
+ * @param hasError - Whether the nodeback was called with an error
38
+ * @param expectError - Whether an error was expected
39
+ * @param error - The actual error value (if any)
40
+ * @returns Error object if there's a mismatch, undefined if the state matches
41
+ * expectations
42
+ */
43
+ export declare const createErrorMismatchError: (hasError: boolean, expectError: boolean, error?: unknown) => {
44
+ actual: string;
45
+ expected: string;
46
+ message: string;
47
+ } | undefined;
48
+ /**
49
+ * Creates error objects for nodeback error state mismatches in async contexts.
50
+ * Handles cases where an error is expected but not present, or vice versa. Uses
51
+ * consistent field naming and messaging for async assertions.
52
+ *
53
+ * @param hasError - Whether the nodeback was called with an error
54
+ * @param expectError - Whether an error was expected
55
+ * @param error - The actual error value (if any)
56
+ * @returns Error object if there's a mismatch, undefined if the state matches
57
+ * expectations
58
+ */
59
+ export declare const createAsyncErrorMismatchError: (hasError: boolean, expectError: boolean, error?: unknown) => {
60
+ actual: string;
61
+ expected: string;
62
+ message: string;
63
+ } | undefined;
64
+ /**
65
+ * Creates a standardized error object for exact value comparison failures. Used
66
+ * when a callback/nodeback is called with a value that doesn't match the
67
+ * expected value using Object.is() strict equality.
68
+ *
69
+ * @param actual - The actual value the callback was called with
70
+ * @param expected - The expected value
71
+ * @param callbackType - The type of callback for error messaging
72
+ * @returns Error object with formatted comparison message
73
+ */
74
+ export declare const createValueMismatchError: (actual: unknown, expected: unknown, callbackType: "callback" | "nodeback") => {
75
+ actual: unknown;
76
+ expected: unknown;
77
+ message: string;
78
+ };
79
+ /**
80
+ * Creates a Zod schema for validating error parameters in callback assertions.
81
+ * Handles string literals, RegExp patterns, and object structures for error
82
+ * matching.
83
+ *
84
+ * @param param - The error parameter to create a schema for
85
+ * @returns Zod schema that can validate the error against the parameter
86
+ * @throws TypeError if the parameter type is not supported
87
+ */
88
+ export declare const createErrorSchema: (param: unknown) => z.ZodType;
89
+ /**
90
+ * Validates a value against a parameter using valueToSchema with specified
91
+ * options. Centralizes the common pattern of schema creation and validation
92
+ * used across many callback assertions.
93
+ *
94
+ * @param subject - The value to validate
95
+ * @param param - The parameter to validate against
96
+ * @param options - Options to pass to valueToSchema
97
+ * @returns Undefined if validation succeeds, ZodError if validation fails
98
+ */
99
+ export declare const validateValue: <T = unknown>(subject: T, param: unknown, options?: ValueToSchemaOptions) => z.ZodError<any> | undefined;
100
+ /**
101
+ * Traps the invocation of a single-parameter callback function for synchronous
102
+ * testing. Executes the provided function with a callback and captures whether
103
+ * it was called, what arguments it received, and any errors thrown during
104
+ * execution.
105
+ *
106
+ * @param fn - The function to execute that should call the provided callback
107
+ * @returns Object containing invocation details: args, called, error, and value
108
+ */
109
+ export declare const trapCallbackInvocation: (fn: (...args: unknown[]) => unknown) => {
110
+ args: unknown[];
111
+ called: boolean;
112
+ error: unknown;
113
+ value: unknown;
114
+ };
115
+ /**
116
+ * Traps the invocation of a nodeback (error-first callback) function for
117
+ * synchronous testing. Executes the provided function with a nodeback and
118
+ * captures whether it was called, what arguments it received, and any errors
119
+ * thrown during execution.
120
+ *
121
+ * @param fn - The function to execute that should call the provided nodeback
122
+ * @returns Object containing invocation details: args, called, error, and value
123
+ */
124
+ export declare const trapNodebackInvocation: (fn: (...args: unknown[]) => unknown) => {
125
+ args: unknown[];
126
+ called: boolean;
127
+ error: unknown;
128
+ value: unknown;
129
+ };
130
+ /**
131
+ * Traps the invocation of a single-parameter callback function for asynchronous
132
+ * testing. Returns a Promise that resolves with invocation details once the
133
+ * callback is called or an error occurs. Uses a Proxy to catch errors during
134
+ * function execution.
135
+ *
136
+ * @param fn - The function to execute that should call the provided callback
137
+ * @returns Promise resolving to object with invocation details: args, called,
138
+ * error, and value
139
+ */
140
+ export declare const trapAsyncCallbackInvocation: (fn: (...args: unknown[]) => unknown) => Promise<{
141
+ args: unknown[];
142
+ called: boolean;
143
+ error: unknown;
144
+ value: unknown;
145
+ }>;
146
+ /**
147
+ * Traps the invocation of a nodeback (error-first callback) function for
148
+ * asynchronous testing. Returns a Promise that resolves with invocation details
149
+ * once the nodeback is called or an error occurs. Uses a Proxy to catch errors
150
+ * during function execution. Always resolves (never rejects) to allow assertion
151
+ * logic to handle error conditions.
152
+ *
153
+ * @param fn - The function to execute that should call the provided nodeback
154
+ * @returns Promise resolving to object with invocation details: args, called,
155
+ * error, and value
156
+ */
157
+ export declare const trapAsyncNodebackInvocation: (fn: (...args: unknown[]) => unknown) => Promise<{
158
+ args: unknown[];
159
+ called: boolean;
160
+ error: unknown;
161
+ value: unknown;
162
+ }>;
163
+ /**
164
+ * Executes & traps a `Promise` rejected from an async function, capturing the
165
+ * error.
166
+ *
167
+ * @param fn The function to execute that may throw an error or return a
168
+ * `Promise`
169
+ * @returns Rejection
170
+ */
171
+ export declare const trapAsyncFnError: (fn: () => unknown) => Promise<unknown>;
172
+ /**
173
+ * Awaits & traps a Promise, capturing any rejection error.
174
+ *
175
+ * @param promise The `Promise` to trap
176
+ * @returns Rejection
177
+ */
178
+ export declare const trapPromiseError: (promise: PromiseLike<unknown>) => Promise<unknown>;
179
+ /**
180
+ * Executes & traps a synchronous function that may throw, capturing any thrown
181
+ * error and discarding the result.
182
+ *
183
+ * @remarks
184
+ * Avoids throwing `undefined` for some reason.
185
+ * @param fn Function to execute
186
+ * @returns Error
187
+ */
188
+ export declare const trapError: (fn: () => unknown) => unknown;
189
+ //# sourceMappingURL=assertion-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertion-util.d.ts","sourceRoot":"","sources":["../../../../src/assertion/impl/assertion-util.ts"],"names":[],"mappings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