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.
- package/CHANGELOG.md +28 -0
- package/README.md +16 -16
- package/dist/commonjs/assertion/assertion-async.d.ts +2 -1
- package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-async.js +84 -2
- package/dist/commonjs/assertion/assertion-async.js.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.js +5 -1
- package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
- package/dist/commonjs/assertion/assertion-types.d.ts +39 -84
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.d.ts +1 -1
- package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.js +1 -14
- package/dist/commonjs/assertion/assertion.js.map +1 -1
- package/dist/commonjs/assertion/create.d.ts +5 -33
- package/dist/commonjs/assertion/create.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.js +17 -6
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +122 -21
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +114 -90
- package/dist/commonjs/assertion/impl/async.js.map +1 -1
- package/dist/commonjs/assertion/impl/callback.d.ts +104 -0
- package/dist/commonjs/assertion/impl/callback.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/callback.js +694 -0
- package/dist/commonjs/assertion/impl/callback.js.map +1 -0
- package/dist/commonjs/assertion/impl/index.d.ts +1 -1
- package/dist/commonjs/assertion/impl/index.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/index.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +37 -34
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +32 -47
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +105 -58
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync.js +4 -1
- package/dist/commonjs/assertion/impl/sync.js.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +199 -85
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +19 -10
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/constant.js +7 -1
- package/dist/commonjs/constant.js.map +1 -1
- package/dist/commonjs/error.d.ts +32 -5
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +60 -5
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts +130 -3
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +116 -1
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +45 -20
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +56 -40
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +241 -86
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +44 -42
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/metadata.d.ts +1 -27
- package/dist/commonjs/metadata.d.ts.map +1 -1
- package/dist/commonjs/metadata.js +16 -15
- package/dist/commonjs/metadata.js.map +1 -1
- package/dist/commonjs/schema.d.ts +76 -33
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +77 -34
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/types.d.ts +480 -39
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +12 -2
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/util.d.ts +72 -49
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +175 -155
- package/dist/commonjs/util.js.map +1 -1
- package/dist/commonjs/value-to-schema.d.ts +122 -0
- package/dist/commonjs/value-to-schema.d.ts.map +1 -0
- package/dist/commonjs/value-to-schema.js +309 -0
- package/dist/commonjs/value-to-schema.js.map +1 -0
- package/dist/esm/assertion/assertion-async.d.ts +2 -1
- package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-async.js +85 -3
- package/dist/esm/assertion/assertion-async.js.map +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-sync.js +6 -2
- package/dist/esm/assertion/assertion-sync.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +39 -84
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.d.ts +1 -1
- package/dist/esm/assertion/assertion.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.js +1 -14
- package/dist/esm/assertion/assertion.js.map +1 -1
- package/dist/esm/assertion/create.d.ts +5 -33
- package/dist/esm/assertion/create.d.ts.map +1 -1
- package/dist/esm/assertion/create.js +14 -4
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +122 -21
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +113 -89
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/callback.d.ts +104 -0
- package/dist/esm/assertion/impl/callback.d.ts.map +1 -0
- package/dist/esm/assertion/impl/callback.js +691 -0
- package/dist/esm/assertion/impl/callback.js.map +1 -0
- package/dist/esm/assertion/impl/index.d.ts +1 -1
- package/dist/esm/assertion/impl/index.d.ts.map +1 -1
- package/dist/esm/assertion/impl/index.js +1 -1
- package/dist/esm/assertion/impl/index.js.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.js +2 -2
- package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +37 -34
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +32 -47
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +105 -58
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync.js +3 -1
- package/dist/esm/assertion/impl/sync.js.map +1 -1
- package/dist/esm/bootstrap.d.ts +199 -85
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +19 -10
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/constant.js +6 -0
- package/dist/esm/constant.js.map +1 -1
- package/dist/esm/error.d.ts +32 -5
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +59 -5
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts +130 -3
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +117 -2
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +45 -20
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +48 -31
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +241 -86
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +46 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metadata.d.ts +1 -27
- package/dist/esm/metadata.d.ts.map +1 -1
- package/dist/esm/metadata.js +2 -1
- package/dist/esm/metadata.js.map +1 -1
- package/dist/esm/schema.d.ts +76 -33
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +77 -34
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/types.d.ts +480 -39
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +12 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/util.d.ts +72 -49
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +159 -153
- package/dist/esm/util.js.map +1 -1
- package/dist/esm/value-to-schema.d.ts +122 -0
- package/dist/esm/value-to-schema.d.ts.map +1 -0
- package/dist/esm/value-to-schema.js +305 -0
- package/dist/esm/value-to-schema.js.map +1 -0
- package/package.json +94 -17
- package/src/assertion/assertion-async.ts +113 -3
- package/src/assertion/assertion-sync.ts +5 -2
- package/src/assertion/assertion-types.ts +52 -45
- package/src/assertion/assertion.ts +2 -17
- package/src/assertion/create.ts +16 -65
- package/src/assertion/impl/async.ts +132 -92
- package/src/assertion/impl/callback.ts +882 -0
- package/src/assertion/impl/index.ts +1 -1
- package/src/assertion/impl/sync-esoteric.ts +2 -2
- package/src/assertion/impl/sync-parametric.ts +41 -49
- package/src/assertion/impl/sync.ts +3 -0
- package/src/bootstrap.ts +21 -11
- package/src/constant.ts +8 -0
- package/src/error.ts +75 -4
- package/src/expect.ts +275 -20
- package/src/guards.ts +74 -69
- package/src/index.ts +72 -11
- package/src/metadata.ts +3 -4
- package/src/schema.ts +80 -36
- package/src/types.ts +625 -72
- package/src/util.ts +174 -222
- package/src/value-to-schema.ts +464 -0
- package/dist/commonjs/api.d.ts +0 -93
- package/dist/commonjs/api.d.ts.map +0 -1
- package/dist/commonjs/api.js +0 -8
- package/dist/commonjs/api.js.map +0 -1
- package/dist/esm/api.d.ts +0 -93
- package/dist/esm/api.d.ts.map +0 -1
- package/dist/esm/api.js +0 -7
- package/dist/esm/api.js.map +0 -1
- package/src/api.ts +0 -149
- 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 {
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
) =>
|
|
233
|
-
|
|
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
|
-
* @
|
|
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
|
-
) =>
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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.
|
|
500
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
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
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
|
|
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
|
/**
|
package/src/assertion/create.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
|
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
|
-
)
|
|
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
|
-
*
|
|
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
|
|
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
|
-
>(
|
|
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
|
+
};
|