bupkis 0.1.2 → 0.3.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 (198) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +16 -16
  3. package/dist/commonjs/assertion/assertion-async.d.ts +2 -1
  4. package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
  5. package/dist/commonjs/assertion/assertion-async.js +84 -2
  6. package/dist/commonjs/assertion/assertion-async.js.map +1 -1
  7. package/dist/commonjs/assertion/assertion-sync.d.ts +1 -1
  8. package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
  9. package/dist/commonjs/assertion/assertion-sync.js +5 -1
  10. package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
  11. package/dist/commonjs/assertion/assertion-types.d.ts +39 -84
  12. package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
  13. package/dist/commonjs/assertion/assertion.d.ts +1 -1
  14. package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
  15. package/dist/commonjs/assertion/assertion.js +1 -14
  16. package/dist/commonjs/assertion/assertion.js.map +1 -1
  17. package/dist/commonjs/assertion/create.d.ts +5 -33
  18. package/dist/commonjs/assertion/create.d.ts.map +1 -1
  19. package/dist/commonjs/assertion/create.js +17 -6
  20. package/dist/commonjs/assertion/create.js.map +1 -1
  21. package/dist/commonjs/assertion/impl/async.d.ts +122 -21
  22. package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
  23. package/dist/commonjs/assertion/impl/async.js +114 -90
  24. package/dist/commonjs/assertion/impl/async.js.map +1 -1
  25. package/dist/commonjs/assertion/impl/callback.d.ts +104 -0
  26. package/dist/commonjs/assertion/impl/callback.d.ts.map +1 -0
  27. package/dist/commonjs/assertion/impl/callback.js +694 -0
  28. package/dist/commonjs/assertion/impl/callback.js.map +1 -0
  29. package/dist/commonjs/assertion/impl/index.d.ts +1 -1
  30. package/dist/commonjs/assertion/impl/index.d.ts.map +1 -1
  31. package/dist/commonjs/assertion/impl/index.js.map +1 -1
  32. package/dist/commonjs/assertion/impl/sync-esoteric.js +1 -1
  33. package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
  34. package/dist/commonjs/assertion/impl/sync-parametric.d.ts +37 -34
  35. package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
  36. package/dist/commonjs/assertion/impl/sync-parametric.js +32 -47
  37. package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
  38. package/dist/commonjs/assertion/impl/sync.d.ts +105 -58
  39. package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
  40. package/dist/commonjs/assertion/impl/sync.js +4 -1
  41. package/dist/commonjs/assertion/impl/sync.js.map +1 -1
  42. package/dist/commonjs/bootstrap.d.ts +199 -85
  43. package/dist/commonjs/bootstrap.d.ts.map +1 -1
  44. package/dist/commonjs/bootstrap.js +19 -10
  45. package/dist/commonjs/bootstrap.js.map +1 -1
  46. package/dist/commonjs/constant.js +7 -1
  47. package/dist/commonjs/constant.js.map +1 -1
  48. package/dist/commonjs/error.d.ts +32 -5
  49. package/dist/commonjs/error.d.ts.map +1 -1
  50. package/dist/commonjs/error.js +60 -5
  51. package/dist/commonjs/error.js.map +1 -1
  52. package/dist/commonjs/expect.d.ts +130 -3
  53. package/dist/commonjs/expect.d.ts.map +1 -1
  54. package/dist/commonjs/expect.js +116 -1
  55. package/dist/commonjs/expect.js.map +1 -1
  56. package/dist/commonjs/guards.d.ts +45 -20
  57. package/dist/commonjs/guards.d.ts.map +1 -1
  58. package/dist/commonjs/guards.js +56 -40
  59. package/dist/commonjs/guards.js.map +1 -1
  60. package/dist/commonjs/index.d.ts +241 -86
  61. package/dist/commonjs/index.d.ts.map +1 -1
  62. package/dist/commonjs/index.js +44 -42
  63. package/dist/commonjs/index.js.map +1 -1
  64. package/dist/commonjs/metadata.d.ts +1 -27
  65. package/dist/commonjs/metadata.d.ts.map +1 -1
  66. package/dist/commonjs/metadata.js +16 -15
  67. package/dist/commonjs/metadata.js.map +1 -1
  68. package/dist/commonjs/schema.d.ts +76 -33
  69. package/dist/commonjs/schema.d.ts.map +1 -1
  70. package/dist/commonjs/schema.js +77 -34
  71. package/dist/commonjs/schema.js.map +1 -1
  72. package/dist/commonjs/types.d.ts +480 -39
  73. package/dist/commonjs/types.d.ts.map +1 -1
  74. package/dist/commonjs/types.js +12 -2
  75. package/dist/commonjs/types.js.map +1 -1
  76. package/dist/commonjs/util.d.ts +72 -49
  77. package/dist/commonjs/util.d.ts.map +1 -1
  78. package/dist/commonjs/util.js +175 -155
  79. package/dist/commonjs/util.js.map +1 -1
  80. package/dist/commonjs/value-to-schema.d.ts +122 -0
  81. package/dist/commonjs/value-to-schema.d.ts.map +1 -0
  82. package/dist/commonjs/value-to-schema.js +309 -0
  83. package/dist/commonjs/value-to-schema.js.map +1 -0
  84. package/dist/esm/assertion/assertion-async.d.ts +2 -1
  85. package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
  86. package/dist/esm/assertion/assertion-async.js +85 -3
  87. package/dist/esm/assertion/assertion-async.js.map +1 -1
  88. package/dist/esm/assertion/assertion-sync.d.ts +1 -1
  89. package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
  90. package/dist/esm/assertion/assertion-sync.js +6 -2
  91. package/dist/esm/assertion/assertion-sync.js.map +1 -1
  92. package/dist/esm/assertion/assertion-types.d.ts +39 -84
  93. package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
  94. package/dist/esm/assertion/assertion.d.ts +1 -1
  95. package/dist/esm/assertion/assertion.d.ts.map +1 -1
  96. package/dist/esm/assertion/assertion.js +1 -14
  97. package/dist/esm/assertion/assertion.js.map +1 -1
  98. package/dist/esm/assertion/create.d.ts +5 -33
  99. package/dist/esm/assertion/create.d.ts.map +1 -1
  100. package/dist/esm/assertion/create.js +14 -4
  101. package/dist/esm/assertion/create.js.map +1 -1
  102. package/dist/esm/assertion/impl/async.d.ts +122 -21
  103. package/dist/esm/assertion/impl/async.d.ts.map +1 -1
  104. package/dist/esm/assertion/impl/async.js +113 -89
  105. package/dist/esm/assertion/impl/async.js.map +1 -1
  106. package/dist/esm/assertion/impl/callback.d.ts +104 -0
  107. package/dist/esm/assertion/impl/callback.d.ts.map +1 -0
  108. package/dist/esm/assertion/impl/callback.js +691 -0
  109. package/dist/esm/assertion/impl/callback.js.map +1 -0
  110. package/dist/esm/assertion/impl/index.d.ts +1 -1
  111. package/dist/esm/assertion/impl/index.d.ts.map +1 -1
  112. package/dist/esm/assertion/impl/index.js +1 -1
  113. package/dist/esm/assertion/impl/index.js.map +1 -1
  114. package/dist/esm/assertion/impl/sync-esoteric.js +2 -2
  115. package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
  116. package/dist/esm/assertion/impl/sync-parametric.d.ts +37 -34
  117. package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
  118. package/dist/esm/assertion/impl/sync-parametric.js +32 -47
  119. package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
  120. package/dist/esm/assertion/impl/sync.d.ts +105 -58
  121. package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
  122. package/dist/esm/assertion/impl/sync.js +3 -1
  123. package/dist/esm/assertion/impl/sync.js.map +1 -1
  124. package/dist/esm/bootstrap.d.ts +199 -85
  125. package/dist/esm/bootstrap.d.ts.map +1 -1
  126. package/dist/esm/bootstrap.js +19 -10
  127. package/dist/esm/bootstrap.js.map +1 -1
  128. package/dist/esm/constant.js +6 -0
  129. package/dist/esm/constant.js.map +1 -1
  130. package/dist/esm/error.d.ts +32 -5
  131. package/dist/esm/error.d.ts.map +1 -1
  132. package/dist/esm/error.js +59 -5
  133. package/dist/esm/error.js.map +1 -1
  134. package/dist/esm/expect.d.ts +130 -3
  135. package/dist/esm/expect.d.ts.map +1 -1
  136. package/dist/esm/expect.js +117 -2
  137. package/dist/esm/expect.js.map +1 -1
  138. package/dist/esm/guards.d.ts +45 -20
  139. package/dist/esm/guards.d.ts.map +1 -1
  140. package/dist/esm/guards.js +48 -31
  141. package/dist/esm/guards.js.map +1 -1
  142. package/dist/esm/index.d.ts +241 -86
  143. package/dist/esm/index.d.ts.map +1 -1
  144. package/dist/esm/index.js +46 -7
  145. package/dist/esm/index.js.map +1 -1
  146. package/dist/esm/metadata.d.ts +1 -27
  147. package/dist/esm/metadata.d.ts.map +1 -1
  148. package/dist/esm/metadata.js +2 -1
  149. package/dist/esm/metadata.js.map +1 -1
  150. package/dist/esm/schema.d.ts +76 -33
  151. package/dist/esm/schema.d.ts.map +1 -1
  152. package/dist/esm/schema.js +77 -34
  153. package/dist/esm/schema.js.map +1 -1
  154. package/dist/esm/types.d.ts +480 -39
  155. package/dist/esm/types.d.ts.map +1 -1
  156. package/dist/esm/types.js +12 -2
  157. package/dist/esm/types.js.map +1 -1
  158. package/dist/esm/util.d.ts +72 -49
  159. package/dist/esm/util.d.ts.map +1 -1
  160. package/dist/esm/util.js +159 -153
  161. package/dist/esm/util.js.map +1 -1
  162. package/dist/esm/value-to-schema.d.ts +122 -0
  163. package/dist/esm/value-to-schema.d.ts.map +1 -0
  164. package/dist/esm/value-to-schema.js +305 -0
  165. package/dist/esm/value-to-schema.js.map +1 -0
  166. package/package.json +94 -17
  167. package/src/assertion/assertion-async.ts +113 -3
  168. package/src/assertion/assertion-sync.ts +5 -2
  169. package/src/assertion/assertion-types.ts +52 -45
  170. package/src/assertion/assertion.ts +2 -17
  171. package/src/assertion/create.ts +16 -65
  172. package/src/assertion/impl/async.ts +132 -92
  173. package/src/assertion/impl/callback.ts +882 -0
  174. package/src/assertion/impl/index.ts +1 -1
  175. package/src/assertion/impl/sync-esoteric.ts +2 -2
  176. package/src/assertion/impl/sync-parametric.ts +41 -49
  177. package/src/assertion/impl/sync.ts +3 -0
  178. package/src/bootstrap.ts +21 -11
  179. package/src/constant.ts +8 -0
  180. package/src/error.ts +75 -4
  181. package/src/expect.ts +275 -20
  182. package/src/guards.ts +74 -69
  183. package/src/index.ts +72 -11
  184. package/src/metadata.ts +3 -4
  185. package/src/schema.ts +80 -36
  186. package/src/types.ts +625 -72
  187. package/src/util.ts +174 -222
  188. package/src/value-to-schema.ts +464 -0
  189. package/dist/commonjs/api.d.ts +0 -93
  190. package/dist/commonjs/api.d.ts.map +0 -1
  191. package/dist/commonjs/api.js +0 -8
  192. package/dist/commonjs/api.js.map +0 -1
  193. package/dist/esm/api.d.ts +0 -93
  194. package/dist/esm/api.d.ts.map +0 -1
  195. package/dist/esm/api.js +0 -7
  196. package/dist/esm/api.js.map +0 -1
  197. package/src/api.ts +0 -149
  198. package/src/schema.md +0 -15
@@ -8,13 +8,14 @@
8
8
 
9
9
  import Debug from 'debug';
10
10
  import { inspect } from 'util';
11
- import { type z } from 'zod/v4';
11
+ import { z } from 'zod/v4';
12
12
 
13
13
  import { kStringLiteral } from '../constant.js';
14
14
  import { AssertionError } from '../error.js';
15
15
  import {
16
16
  isAssertionFailure,
17
17
  isBoolean,
18
+ isError,
18
19
  isPromiseLike,
19
20
  isZodPromise,
20
21
  isZodType,
@@ -183,6 +184,8 @@ export class BupkisAssertionFunctionSync<
183
184
  expected: result.expected,
184
185
  message: result.message ?? `Assertion ${this} failed`,
185
186
  });
187
+ } else if (isError(result) && result instanceof z.ZodError) {
188
+ throw this.translateZodError(stackStartFn, result, ...parsedValues);
186
189
  } else if (result as unknown) {
187
190
  throw new TypeError(
188
191
  `Invalid return type from assertion ${this}; expected boolean, ZodType, or AssertionFailure`,
@@ -214,7 +217,7 @@ export class BupkisAssertionSchemaSync<
214
217
  {
215
218
  override execute(
216
219
  parsedValues: ParsedValues<Parts>,
217
- args: unknown[],
220
+ _args: unknown[],
218
221
  stackStartFn: (...args: any[]) => any,
219
222
  parseResult?: ParsedResult<Parts>,
220
223
  ): void {
@@ -12,7 +12,6 @@
12
12
  import { type ArrayValues, type NonEmptyTuple } from 'type-fest';
13
13
  import { type z } from 'zod/v4';
14
14
 
15
- import type { createAssertion as _createAssertion } from './create.js';
16
15
  import type { AsyncAssertions, SyncAssertions } from './impl/index.js';
17
16
 
18
17
  /**
@@ -46,8 +45,8 @@ export type AnyAssertions = NonEmptyTuple<AnyAssertion>;
46
45
  * @see {@link AssertionSchemaAsync} for schema-based async assertions
47
46
  */
48
47
  export type AnyAsyncAssertion =
49
- // | AssertionAsync<any, any, any>
50
- AssertionFunctionAsync<any, any, any> | AssertionSchemaAsync<any, any, any>;
48
+ | AssertionFunctionAsync<any, any, any>
49
+ | AssertionSchemaAsync<any, any, any>;
51
50
 
52
51
  /**
53
52
  * Non-empty tuple type containing any asynchronous assertions.
@@ -71,7 +70,6 @@ export type AnyAsyncAssertions = NonEmptyTuple<AnyAsyncAssertion>;
71
70
  export type AnySyncAssertion =
72
71
  | AssertionFunctionSync<any, any, any>
73
72
  | AssertionSchemaSync<any, any, any>;
74
- // | AssertionSync<any, any, any>;
75
73
 
76
74
  /**
77
75
  * Non-empty tuple type containing any synchronous assertions.
@@ -203,7 +201,7 @@ export type AssertionImpl<Parts extends AssertionParts> =
203
201
  * asynchronous assertions, providing a type-safe way to handle async assertion
204
202
  * logic.
205
203
  *
206
- * @typeParam Parts - The assertion parts defining the structure
204
+ * @template Parts - The assertion parts defining the structure
207
205
  * @see {@link AssertionImplFnAsync} for function-based async implementations
208
206
  * @see {@link AssertionImplSchemaAsync} for schema-based async implementations
209
207
  */
@@ -219,7 +217,7 @@ export type AssertionImplAsync<Parts extends AssertionParts> =
219
217
  * parsed values from the assertion parts and can return various types
220
218
  * indicating validation success or failure.
221
219
  *
222
- * @typeParam Parts - The assertion parts defining the structure
220
+ * @template Parts - The assertion parts defining the structure
223
221
  * @param values - The parsed values corresponding to assertion parts
224
222
  * @returns Promise resolving to boolean indicating pass/fail, void for success,
225
223
  * ZodType for dynamic validation, or AssertionFailure object for detailed
@@ -229,9 +227,19 @@ export type AssertionImplAsync<Parts extends AssertionParts> =
229
227
  */
230
228
  export type AssertionImplFnAsync<Parts extends AssertionParts> = (
231
229
  ...values: ParsedValues<Parts>
232
- ) => Promise<
233
- AssertionFailure | boolean | void | z.ZodType<ParsedSubject<Parts>>
234
- >;
230
+ ) =>
231
+ | AssertionImplFnReturnType<Parts>
232
+ | Promise<AssertionImplFnReturnType<Parts>>;
233
+
234
+ /**
235
+ * The return type of an assertion implementation function.
236
+ */
237
+ export type AssertionImplFnReturnType<Parts extends AssertionParts> =
238
+ | AssertionFailure
239
+ | boolean
240
+ | void
241
+ | z.ZodError
242
+ | z.ZodType<ParsedSubject<Parts>>;
235
243
 
236
244
  /**
237
245
  * The implementation of an assertion as a sync function.
@@ -241,7 +249,7 @@ export type AssertionImplFnAsync<Parts extends AssertionParts> = (
241
249
  * assertion parts and can return various types indicating validation success or
242
250
  * failure.
243
251
  *
244
- * @typeParam Parts - The assertion parts defining the structure
252
+ * @template Parts - The assertion parts defining the structure
245
253
  * @param values - The parsed values corresponding to assertion parts
246
254
  * @returns Boolean indicating pass/fail, void for success, ZodType for dynamic
247
255
  * validation, or AssertionFailure object for detailed error information
@@ -250,14 +258,12 @@ export type AssertionImplFnAsync<Parts extends AssertionParts> = (
250
258
  */
251
259
  export type AssertionImplFnSync<Parts extends AssertionParts> = (
252
260
  ...values: ParsedValues<Parts>
253
- ) => AssertionFailure | boolean | void | z.ZodType<ParsedSubject<Parts>>;
261
+ ) => AssertionImplFnReturnType<Parts>;
254
262
 
255
263
  /**
256
264
  * Maps an {@link AssertionPart} to a parameter to an {@link AssertionImpl}.
257
265
  *
258
266
  * This omits {@link Phrase} parts, which are not received by the implementation.
259
- *
260
- * @knipignore
261
267
  */
262
268
  export type AssertionImplPart<Part extends AssertionPart> = Part extends
263
269
  | PhraseLiteral
@@ -269,8 +275,6 @@ export type AssertionImplPart<Part extends AssertionPart> = Part extends
269
275
 
270
276
  /**
271
277
  * Maps {@link AssertionParts} to their corresponding {@link AssertionImplPart}.
272
- *
273
- * @knipignore
274
278
  */
275
279
  export type AssertionImplParts<Parts extends readonly AssertionPart[]> =
276
280
  Parts extends readonly [
@@ -292,7 +296,7 @@ export type AssertionImplParts<Parts extends readonly AssertionPart[]> =
292
296
  * the assertion parts and is branded with 'async-schema' for compile-time type
293
297
  * safety.
294
298
  *
295
- * @typeParam Parts - The assertion parts tuple defining the assertion structure
299
+ * @template Parts - The assertion parts tuple defining the assertion structure
296
300
  * @see {@link AssertionImplSchemaSync} for synchronous schema implementations
297
301
  * @see {@link AssertionImplFnAsync} for function-based async implementations
298
302
  * @see {@link ParsedSubject} for subject type derivation
@@ -308,7 +312,7 @@ export type AssertionImplSchemaAsync<Parts extends AssertionParts> =
308
312
  * assertion parts and is branded with 'sync-schema' for compile-time type
309
313
  * safety.
310
314
  *
311
- * @typeParam Parts - The assertion parts tuple defining the assertion structure
315
+ * @template Parts - The assertion parts tuple defining the assertion structure
312
316
  * @see {@link AssertionImplSchemaAsync} for asynchronous schema implementations
313
317
  * @see {@link AssertionImplFnSync} for function-based sync implementations
314
318
  * @see {@link ParsedSubject} for subject type derivation
@@ -323,7 +327,7 @@ export type AssertionImplSchemaSync<Parts extends AssertionParts> =
323
327
  * synchronous assertions. Function implementations provide custom validation
324
328
  * logic, while schema implementations use Zod schemas for validation.
325
329
  *
326
- * @typeParam Parts - The assertion parts tuple defining the assertion structure
330
+ * @template Parts - The assertion parts tuple defining the assertion structure
327
331
  * @see {@link AssertionImplFnSync} for function-based implementations
328
332
  * @see {@link AssertionImplSchemaSync} for schema-based implementations
329
333
  * @see {@link AssertionImplAsync} for async implementation unions
@@ -335,7 +339,7 @@ export type AssertionImplSchemaSync<Parts extends AssertionParts> =
335
339
  * synchronous assertions. Function implementations provide custom validation
336
340
  * logic, while schema implementations use Zod schemas for validation.
337
341
  *
338
- * @typeParam Parts - The assertion parts tuple defining the assertion structure
342
+ * @template Parts - The assertion parts tuple defining the assertion structure
339
343
  * @see {@link AssertionImplFnSync} for function-based implementations
340
344
  * @see {@link AssertionImplSchemaSync} for schema-based implementations
341
345
  * @see {@link AssertionImplAsync} for async implementation unions
@@ -391,11 +395,10 @@ export type AssertionPart = Phrase | z.ZodType;
391
395
  * type ChoiceAssertion = [z.any(), ['to be', 'to equal'], z.any()];
392
396
  * ```
393
397
  *
394
- * @typeParam Parts - Extends the base AssertionPart array with tuple
395
- * constraints
398
+ * @template Parts - Extends the base AssertionPart array with tuple constraints
396
399
  * @see {@link AssertionPart} for individual part types
397
400
  * @see {@link AssertionSlots} for compiled slot representation
398
- * @see {@link _createAssertion} for assertion creation from parts
401
+ * @see {@link createAssertion} for assertion creation from parts
399
402
  */
400
403
  export type AssertionParts = NonEmptyTuple<AssertionPart>;
401
404
 
@@ -418,7 +421,7 @@ export type AssertionParts = NonEmptyTuple<AssertionPart>;
418
421
  * type Slots = [PhraseLiteralSlot<'to be a string'>, z.ZodNumber];
419
422
  * ```
420
423
  *
421
- * @typeParam Parts - The readonly array of assertion parts to process
424
+ * @template Parts - The readonly array of assertion parts to process
422
425
  * @see {@link AssertionSlot} for individual slot type mapping
423
426
  * @see {@link AssertionSlots} for filtered and properly typed slot tuples
424
427
  * @see {@link NoNeverTuple} for filtering never entries
@@ -472,7 +475,7 @@ export interface AssertionSchemaSync<
472
475
  * type Slot3 = AssertionSlot<z.ZodString>; // z.ZodString
473
476
  * ```
474
477
  *
475
- * @typeParam Part - The assertion part to convert to a slot
478
+ * @template Part - The assertion part to convert to a slot
476
479
  * @see {@link PhraseLiteralSlot} for string literal slots
477
480
  * @see {@link PhraseLiteralChoiceSlot} for choice-based slots
478
481
  * @see {@link AssertionSlots} for complete slot tuples
@@ -496,8 +499,12 @@ export type AssertionSlot<Part extends AssertionPart> = Part extends string
496
499
  * The resulting tuple:
497
500
  *
498
501
  * 1. Has `never` entries filtered out to maintain proper tuple structure
499
- * 2. May include an implicit subject slot for phrase-first assertions
500
- * 3. Contains branded slots for phrase literals to enable phrase matching
502
+ * 2. Will include an implicit subject slot {@link AssertionParts} with a
503
+ * {@link PhraseLiteral}/{@link PhraseLiteralChoice} in the first position.
504
+ * 3. Contains branded slots for
505
+ * {@link PhraseLiteral PhraseLiterals}/{@link PhraseLiteralChoice PhraseLiteralChoices}
506
+ * to enable phrase matching; differentiates from a user-created
507
+ * {@link z.ZodLiteral ZodLiteral}.
501
508
  *
502
509
  * @example
503
510
  *
@@ -511,7 +518,7 @@ export type AssertionSlot<Part extends AssertionPart> = Part extends string
511
518
  * // Result: [z.ZodString, PhraseLiteralSlot<'to match'>, z.ZodRegExp]
512
519
  * ```
513
520
  *
514
- * @typeParam Parts - The assertion parts to convert to slots
521
+ * @template Parts - The assertion parts to convert to slots
515
522
  * @see {@link AssertionSlot} for individual slot mapping
516
523
  * @see {@link AssertionPartsToSlots} for the underlying mapping logic
517
524
  * @see {@link NoNeverTuple} for never filtering
@@ -558,8 +565,6 @@ export interface AssertionSync<
558
565
 
559
566
  /**
560
567
  * The base structure for parsed assertion results.
561
- *
562
- * @knipignore
563
568
  */
564
569
  export interface BaseParsedResult<Parts extends AssertionParts> {
565
570
  /**
@@ -570,13 +575,13 @@ export interface BaseParsedResult<Parts extends AssertionParts> {
570
575
 
571
576
  /**
572
577
  * Present only if `success` is `true`. The parsed values mapped to the slots
573
- * of {@link assertion}.
578
+ * of an {@link Assertion}.
574
579
  */
575
580
  parsedValues?: ParsedValues<Parts>;
576
581
 
577
582
  /**
578
- * Whether the args were successfully parsed against the slots of
579
- * {@link assertion}.
583
+ * Whether the args were successfully parsed against the slots of an
584
+ * {@link Assertion}.
580
585
  */
581
586
  success: boolean;
582
587
  }
@@ -587,6 +592,7 @@ export interface BaseParsedResult<Parts extends AssertionParts> {
587
592
  * This type extracts the element types from the builtin async assertions array,
588
593
  * providing a union of all available async assertion types in the framework.
589
594
  *
595
+ * @internal
590
596
  * @see {@link BuiltinAsyncAssertions} for the full array type
591
597
  * @see {@link AsyncAssertions} for the actual assertion implementations
592
598
  */
@@ -599,6 +605,7 @@ export type BuiltinAsyncAssertion = ArrayValues<BuiltinAsyncAssertions>;
599
605
  * providing type information for all async assertion implementations included
600
606
  * in the framework by default.
601
607
  *
608
+ * @internal
602
609
  * @see {@link AsyncAssertions} for the actual assertion implementations
603
610
  * @see {@link BuiltinAsyncAssertion} for individual assertion types
604
611
  */
@@ -611,6 +618,7 @@ export type BuiltinAsyncAssertions = typeof AsyncAssertions;
611
618
  * providing a union of all available synchronous assertion types in the
612
619
  * framework.
613
620
  *
621
+ * @internal
614
622
  * @see {@link BuiltinSyncAssertions} for the full array type
615
623
  * @see {@link SyncAssertions} for the actual assertion implementations
616
624
  */
@@ -623,6 +631,7 @@ export type BuiltinSyncAssertion = ArrayValues<BuiltinSyncAssertions>;
623
631
  * providing type information for all synchronous assertion implementations
624
632
  * included in the framework by default.
625
633
  *
634
+ * @internal
626
635
  * @see {@link SyncAssertions} for the actual assertion implementations
627
636
  * @see {@link BuiltinSyncAssertion} for individual assertion types
628
637
  */
@@ -636,7 +645,7 @@ export type BuiltinSyncAssertions = typeof SyncAssertions;
636
645
  * tuple). It uses `NoNeverTuple` to filter out `never` types that may arise
637
646
  * during the recursive processing.
638
647
  *
639
- * @typeParam Parts - The assertion parts to process
648
+ * @template Parts - The assertion parts to process
640
649
  * @see {@link ParsedValues} for the standard parsed values type
641
650
  * @see {@link NoNeverTuple} for never-type filtering
642
651
  */
@@ -674,7 +683,7 @@ export type MaybeEmptyParsedValues<Parts extends readonly AssertionPart[]> =
674
683
  * type Mixed = NoNeverTuple<readonly [boolean, never, string]>; // readonly [boolean, string]
675
684
  * ```
676
685
  *
677
- * @typeParam T - The readonly tuple type to filter
686
+ * @template T - The readonly tuple type to filter
678
687
  * @see {@link AssertionPartsToSlots} for usage in slot processing
679
688
  * @see {@link AssertionSlots} for filtered slot tuples
680
689
  */
@@ -710,7 +719,7 @@ export type NoNeverTuple<T extends readonly unknown[]> = T extends readonly [
710
719
  * };
711
720
  * ```
712
721
  *
713
- * @typeParam Parts - The assertion parts tuple defining expected structure
722
+ * @template Parts - The assertion parts tuple defining expected structure
714
723
  * @see {@link ParsedResultSuccess} for successful parse results
715
724
  * @see {@link ParsedResultFailure} for failed parse results
716
725
  * @see {@link AssertionSync.parseValues} and {@link AssertionAsync.parseValuesAsync} for usage context
@@ -743,7 +752,7 @@ export interface ParsedResultFailure extends BaseParsedResult<never> {
743
752
  * interface contains the validated arguments and metadata about the match
744
753
  * quality. The assertion can be executed using the `parsedValues`.
745
754
  *
746
- * @typeParam Parts - The assertion parts tuple defining the expected structure
755
+ * @template Parts - The assertion parts tuple defining the expected structure
747
756
  * @see {@link ParsedResultFailure} for failed parsing results
748
757
  * @see {@link BaseParsedResult} for shared result properties
749
758
  */
@@ -785,7 +794,7 @@ export interface ParsedResultSuccess<Parts extends AssertionParts>
785
794
  * type NumericSubject = ParsedSubject<NumericParts>; // number
786
795
  * ```
787
796
  *
788
- * @typeParam Parts - The assertion parts tuple defining the assertion structure
797
+ * @template Parts - The assertion parts tuple defining the assertion structure
789
798
  * @see {@link ParsedValues} for the complete parsed values tuple
790
799
  * @see {@link AssertionImpl} for how subjects are used in implementations
791
800
  */
@@ -812,7 +821,7 @@ export type ParsedSubject<Parts extends AssertionParts> =
812
821
  * // ParsedValues = [typeof obj, typeof shape]
813
822
  * ```
814
823
  *
815
- * @typeParam Parts - The assertion parts tuple defining the expected structure
824
+ * @template Parts - The assertion parts tuple defining the expected structure
816
825
  * @see {@link ParsedSubject} for extracting just the subject
817
826
  * @see {@link MaybeEmptyParsedValues} for the underlying value processing
818
827
  * @see {@link AssertionImpl} for how these values are consumed
@@ -915,7 +924,7 @@ export type PhraseLiteralChoice = NonEmptyTuple<string>;
915
924
  * The `__values` property might be redundant since values should be derivable
916
925
  * from the ZodLiteral metadata, but it provides type-level access to the
917
926
  * choices.
918
- * @typeParam H - The readonly tuple of string choices
927
+ * @template H - The readonly tuple of string choices
919
928
  * @see {@link PhraseLiteralChoice} for the source type
920
929
  * @see {@link PhraseLiteralSlot} for single phrase slots
921
930
  * @see {@link AssertionSlot} for slot type mapping
@@ -935,7 +944,7 @@ export type PhraseLiteralChoiceSlot<H extends readonly [string, ...string[]]> =
935
944
  * This type might be redundant since the value should be derivable from the
936
945
  * ZodLiteral's value property, but it provides type-level access to the
937
946
  * literal.
938
- * @typeParam T - The string literal type
947
+ * @template T - The string literal type
939
948
  * @see {@link PhraseLiteral} for the source type
940
949
  * @see {@link PhraseLiteralChoiceSlot} for choice phrase slots
941
950
  * @see {@link AssertionSlot} for slot type mapping
@@ -943,10 +952,7 @@ export type PhraseLiteralChoiceSlot<H extends readonly [string, ...string[]]> =
943
952
  export type PhraseLiteralSlot<T extends string> = z.core.$ZodBranded<
944
953
  z.ZodLiteral<T>,
945
954
  'string-literal'
946
- >; /**
947
- * Object which can returned by assertion implementation functions to provide
948
- * contextual information to an `AssertionError`
949
- */
955
+ >;
950
956
 
951
957
  /**
952
958
  * Type for a raw (unbranded) synchronous schema assertion implementation.
@@ -956,7 +962,8 @@ export type PhraseLiteralSlot<T extends string> = z.core.$ZodBranded<
956
962
  * type is not branded and represents the underlying schema before it is
957
963
  * processed by the assertion creation system.
958
964
  *
959
- * @typeParam Parts - The assertion parts tuple defining the assertion structure
965
+ * @template Parts The tuple defining the assertion structure
966
+ * @useDeclaredType
960
967
  * @see {@link AssertionImplSchemaSync} for the branded version
961
968
  * @see {@link ParsedSubject} for subject type derivation
962
969
  */
@@ -13,7 +13,7 @@ import Debug from 'debug';
13
13
  import slug from 'slug';
14
14
  import { type ArrayValues } from 'type-fest';
15
15
  import { inspect } from 'util';
16
- import { z } from 'zod/v4';
16
+ import { type z } from 'zod/v4';
17
17
 
18
18
  import { kStringLiteral } from '../constant.js';
19
19
  import { AssertionError } from '../error.js';
@@ -186,22 +186,7 @@ export abstract class BupkisAssertion<
186
186
  zodError: z.ZodError,
187
187
  ...values: ParsedValues<Parts>
188
188
  ): AssertionError {
189
- const flat = z.flattenError(zodError);
190
-
191
- let pretty = flat.formErrors.join('; ');
192
- for (const [keypath, errors] of Object.entries(flat.fieldErrors)) {
193
- pretty += `; ${keypath}: ${(errors as unknown[]).join('; ')}`;
194
- }
195
-
196
- const [actual, ...expected] = values as unknown as [unknown, ...unknown[]];
197
-
198
- return new AssertionError({
199
- actual,
200
- expected: expected.length === 1 ? expected[0] : expected,
201
- message: `Assertion ${this} failed: ${pretty}`,
202
- operator: `${this}`,
203
- stackStartFn,
204
- });
189
+ return AssertionError.fromZodError(zodError, stackStartFn, values);
205
190
  }
206
191
 
207
192
  /**
@@ -69,22 +69,16 @@
69
69
  import { z } from 'zod/v4';
70
70
 
71
71
  import type {
72
- AssertionFunctionAsync,
73
- AssertionFunctionSync,
74
72
  AssertionImplAsync,
75
- AssertionImplFnAsync,
76
- AssertionImplFnSync,
77
- AssertionImplSchemaAsync,
78
- AssertionImplSchemaSync,
79
73
  AssertionImplSync,
80
74
  AssertionParts,
81
- AssertionSchemaAsync,
82
- AssertionSchemaSync,
83
- AssertionSlots,
84
- RawAssertionImplSchemaSync,
85
75
  } from './assertion-types.js';
86
76
 
87
77
  import { isFunction, isString, isZodType } from '../guards.js';
78
+ import {
79
+ type CreateAssertionFn,
80
+ type CreateAsyncAssertionFn,
81
+ } from '../types.js';
88
82
  import {
89
83
  BupkisAssertionFunctionAsync,
90
84
  BupkisAssertionSchemaAsync,
@@ -96,40 +90,17 @@ import {
96
90
  import { slotify } from './slotify.js';
97
91
 
98
92
  /**
99
- * Create a synchronous `Assertion` from {@link AssertionParts parts} and a
100
- * {@link z.ZodType Zod schema}.
93
+ * {@inheritDoc CreateAssertionFn}
101
94
  *
102
- * @param parts Assertion parts defining the shape of the assertion
103
- * @param impl Implementation as a Zod schema
104
- * @returns New `SchemaAssertion` instance
105
95
  * @throws {TypeError} Invalid assertion implementation type
106
96
  */
107
- export function createAssertion<
97
+ export const createAssertion: CreateAssertionFn = <
98
+ Impl extends AssertionImplSync<Parts>,
108
99
  const Parts extends AssertionParts,
109
- Impl extends RawAssertionImplSchemaSync<Parts>,
110
- Slots extends AssertionSlots<Parts>,
111
100
  >(
112
101
  parts: Parts,
113
102
  impl: Impl,
114
- ): AssertionSchemaSync<Parts, AssertionImplSchemaSync<Parts>, Slots>;
115
- /**
116
- * Create a synchronous `Assertion` from {@link AssertionParts parts} and an
117
- * implementation function.
118
- *
119
- * @param parts Assertion parts defining the shape of the assertion
120
- * @param impl Implementation as a function
121
- * @returns New `FunctionAssertion` instance
122
- * @throws {TypeError} Invalid assertion implementation type
123
- */
124
- export function createAssertion<
125
- const Parts extends AssertionParts,
126
- Impl extends AssertionImplFnSync<Parts>,
127
- Slots extends AssertionSlots<Parts>,
128
- >(parts: Parts, impl: Impl): AssertionFunctionSync<Parts, Impl, Slots>;
129
- export function createAssertion<
130
- Impl extends AssertionImplSync<Parts>,
131
- const Parts extends AssertionParts,
132
- >(parts: Parts, impl: Impl) {
103
+ ) => {
133
104
  if (!Array.isArray(parts)) {
134
105
  throw new TypeError('First parameter must be an array');
135
106
  }
@@ -163,40 +134,20 @@ export function createAssertion<
163
134
  throw new TypeError(
164
135
  'Assertion implementation must be a function, Zod schema or Zod schema factory',
165
136
  );
166
- }
167
- /**
168
- * Create an async `Assertion` from {@link AssertionParts parts} and an async
169
- * {@link z.ZodType Zod schema}.
170
- *
171
- * @param parts Assertion parts defining the shape of the assertion
172
- * @param impl Implementation as a Zod schema (potentially async)
173
- * @returns New `BupkisAssertionSchemaAsync` instance
174
- * @throws {TypeError} Invalid assertion implementation type
175
- */
176
- export function createAsyncAssertion<
177
- const Parts extends AssertionParts,
178
- Impl extends AssertionImplSchemaAsync<Parts>,
179
- Slots extends AssertionSlots<Parts>,
180
- >(parts: Parts, impl: Impl): AssertionSchemaAsync<Parts, Impl, Slots>;
137
+ };
181
138
 
182
139
  /**
183
- * Create an async `Assertion` from {@link AssertionParts parts} and an
184
- * implementation function.
140
+ * {@inheritDoc CreateAsyncAssertionFn}
185
141
  *
186
- * @param parts Assertion parts defining the shape of the assertion
187
- * @param impl Implementation as a function (potentially async)
188
- * @returns New `FunctionAssertion` instance
189
142
  * @throws {TypeError} Invalid assertion implementation type
190
143
  */
191
- export function createAsyncAssertion<
192
- const Parts extends AssertionParts,
193
- Impl extends AssertionImplFnAsync<Parts>,
194
- Slots extends AssertionSlots<Parts>,
195
- >(parts: Parts, impl: Impl): AssertionFunctionAsync<Parts, Impl, Slots>;
196
- export function createAsyncAssertion<
144
+ export const createAsyncAssertion: CreateAsyncAssertionFn = <
197
145
  const Parts extends AssertionParts,
198
146
  Impl extends AssertionImplAsync<Parts>,
199
- >(parts: Parts, impl: Impl) {
147
+ >(
148
+ parts: Parts,
149
+ impl: Impl,
150
+ ) => {
200
151
  if (!Array.isArray(parts)) {
201
152
  throw new TypeError('First parameter must be an array');
202
153
  }
@@ -223,4 +174,4 @@ export function createAsyncAssertion<
223
174
  throw new TypeError(
224
175
  'Assertion implementation must be a function, Zod schema or Zod schema factory',
225
176
  );
226
- }
177
+ };