bupkis 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/commonjs/api.d.ts +93 -0
- package/dist/commonjs/api.d.ts.map +1 -0
- package/dist/commonjs/api.js +8 -0
- package/dist/commonjs/api.js.map +1 -0
- package/dist/commonjs/assertion/assertion-async.d.ts +45 -0
- package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -0
- package/dist/commonjs/assertion/assertion-async.js +154 -0
- package/dist/commonjs/assertion/assertion-async.js.map +1 -0
- package/dist/commonjs/assertion/assertion-sync.d.ts +66 -0
- package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -0
- package/dist/commonjs/assertion/assertion-sync.js +244 -0
- package/dist/commonjs/assertion/assertion-sync.js.map +1 -0
- package/dist/commonjs/assertion/assertion-types.d.ts +801 -0
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -0
- package/dist/commonjs/assertion/assertion-types.js +13 -0
- package/dist/commonjs/assertion/assertion-types.js.map +1 -0
- package/dist/commonjs/assertion/assertion.d.ts +74 -0
- package/dist/commonjs/assertion/assertion.d.ts.map +1 -0
- package/dist/commonjs/assertion/assertion.js +201 -0
- package/dist/commonjs/assertion/assertion.js.map +1 -0
- package/dist/commonjs/assertion/create.d.ts +109 -0
- package/dist/commonjs/assertion/create.d.ts.map +1 -0
- package/dist/commonjs/assertion/create.js +129 -0
- package/dist/commonjs/assertion/create.js.map +1 -0
- package/dist/commonjs/assertion/impl/async.d.ts +45 -0
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/async.js +257 -0
- package/dist/commonjs/assertion/impl/async.js.map +1 -0
- package/dist/commonjs/assertion/impl/index.d.ts +3 -0
- package/dist/commonjs/assertion/impl/index.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/index.js +8 -0
- package/dist/commonjs/assertion/impl/index.js.map +1 -0
- package/dist/commonjs/assertion/impl/sync-basic.d.ts +6 -0
- package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/sync-basic.js +68 -0
- package/dist/commonjs/assertion/impl/sync-basic.js.map +1 -0
- package/dist/commonjs/assertion/impl/sync-collection.d.ts +17 -0
- package/dist/commonjs/assertion/impl/sync-collection.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/sync-collection.js +66 -0
- package/dist/commonjs/assertion/impl/sync-collection.js.map +1 -0
- package/dist/commonjs/assertion/impl/sync-esoteric.d.ts +5 -0
- package/dist/commonjs/assertion/impl/sync-esoteric.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/sync-esoteric.js +14 -0
- package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -0
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +115 -0
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/sync-parametric.js +390 -0
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -0
- package/dist/commonjs/assertion/impl/sync.d.ts +144 -0
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -0
- package/dist/commonjs/assertion/impl/sync.js +28 -0
- package/dist/commonjs/assertion/impl/sync.js.map +1 -0
- package/dist/commonjs/assertion/index.d.ts +15 -0
- package/dist/commonjs/assertion/index.d.ts.map +1 -0
- package/dist/commonjs/assertion/index.js +34 -0
- package/dist/commonjs/assertion/index.js.map +1 -0
- package/dist/commonjs/assertion/slotify.d.ts +23 -0
- package/dist/commonjs/assertion/slotify.d.ts.map +1 -0
- package/dist/commonjs/assertion/slotify.js +67 -0
- package/dist/commonjs/assertion/slotify.js.map +1 -0
- package/dist/commonjs/bootstrap.d.ts +175 -0
- package/dist/commonjs/bootstrap.d.ts.map +1 -0
- package/dist/commonjs/bootstrap.js +34 -0
- package/dist/commonjs/bootstrap.js.map +1 -0
- package/dist/commonjs/constant.d.ts +12 -0
- package/dist/commonjs/constant.d.ts.map +1 -0
- package/dist/commonjs/constant.js +33 -0
- package/dist/commonjs/constant.js.map +1 -0
- package/dist/commonjs/error.d.ts +20 -0
- package/dist/commonjs/error.d.ts.map +1 -0
- package/dist/commonjs/error.js +40 -0
- package/dist/commonjs/error.js.map +1 -0
- package/dist/commonjs/expect.d.ts +9 -0
- package/dist/commonjs/expect.d.ts.map +1 -0
- package/dist/commonjs/expect.js +218 -0
- package/dist/commonjs/expect.js.map +1 -0
- package/dist/commonjs/guards.d.ts +93 -0
- package/dist/commonjs/guards.d.ts.map +1 -0
- package/dist/commonjs/guards.js +163 -0
- package/dist/commonjs/guards.js.map +1 -0
- package/dist/commonjs/index.d.ts +181 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +62 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/metadata.d.ts +53 -0
- package/dist/commonjs/metadata.d.ts.map +1 -0
- package/dist/commonjs/metadata.js +51 -0
- package/dist/commonjs/metadata.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/schema.d.ts +373 -0
- package/dist/commonjs/schema.d.ts.map +1 -0
- package/dist/commonjs/schema.js +437 -0
- package/dist/commonjs/schema.js.map +1 -0
- package/dist/commonjs/types.d.ts +79 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +9 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/use.d.ts +4 -0
- package/dist/commonjs/use.d.ts.map +1 -0
- package/dist/commonjs/use.js +35 -0
- package/dist/commonjs/use.js.map +1 -0
- package/dist/commonjs/util.d.ts +67 -0
- package/dist/commonjs/util.d.ts.map +1 -0
- package/dist/commonjs/util.js +187 -0
- package/dist/commonjs/util.js.map +1 -0
- package/dist/esm/api.d.ts +93 -0
- package/dist/esm/api.d.ts.map +1 -0
- package/dist/esm/api.js +7 -0
- package/dist/esm/api.js.map +1 -0
- package/dist/esm/assertion/assertion-async.d.ts +45 -0
- package/dist/esm/assertion/assertion-async.d.ts.map +1 -0
- package/dist/esm/assertion/assertion-async.js +145 -0
- package/dist/esm/assertion/assertion-async.js.map +1 -0
- package/dist/esm/assertion/assertion-sync.d.ts +66 -0
- package/dist/esm/assertion/assertion-sync.d.ts.map +1 -0
- package/dist/esm/assertion/assertion-sync.js +235 -0
- package/dist/esm/assertion/assertion-sync.js.map +1 -0
- package/dist/esm/assertion/assertion-types.d.ts +801 -0
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -0
- package/dist/esm/assertion/assertion-types.js +12 -0
- package/dist/esm/assertion/assertion-types.js.map +1 -0
- package/dist/esm/assertion/assertion.d.ts +74 -0
- package/dist/esm/assertion/assertion.d.ts.map +1 -0
- package/dist/esm/assertion/assertion.js +194 -0
- package/dist/esm/assertion/assertion.js.map +1 -0
- package/dist/esm/assertion/create.d.ts +109 -0
- package/dist/esm/assertion/create.d.ts.map +1 -0
- package/dist/esm/assertion/create.js +125 -0
- package/dist/esm/assertion/create.js.map +1 -0
- package/dist/esm/assertion/impl/async.d.ts +45 -0
- package/dist/esm/assertion/impl/async.d.ts.map +1 -0
- package/dist/esm/assertion/impl/async.js +254 -0
- package/dist/esm/assertion/impl/async.js.map +1 -0
- package/dist/esm/assertion/impl/index.d.ts +3 -0
- package/dist/esm/assertion/impl/index.d.ts.map +1 -0
- package/dist/esm/assertion/impl/index.js +3 -0
- package/dist/esm/assertion/impl/index.js.map +1 -0
- package/dist/esm/assertion/impl/sync-basic.d.ts +6 -0
- package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -0
- package/dist/esm/assertion/impl/sync-basic.js +65 -0
- package/dist/esm/assertion/impl/sync-basic.js.map +1 -0
- package/dist/esm/assertion/impl/sync-collection.d.ts +17 -0
- package/dist/esm/assertion/impl/sync-collection.d.ts.map +1 -0
- package/dist/esm/assertion/impl/sync-collection.js +63 -0
- package/dist/esm/assertion/impl/sync-collection.js.map +1 -0
- package/dist/esm/assertion/impl/sync-esoteric.d.ts +5 -0
- package/dist/esm/assertion/impl/sync-esoteric.d.ts.map +1 -0
- package/dist/esm/assertion/impl/sync-esoteric.js +11 -0
- package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -0
- package/dist/esm/assertion/impl/sync-parametric.d.ts +115 -0
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -0
- package/dist/esm/assertion/impl/sync-parametric.js +387 -0
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -0
- package/dist/esm/assertion/impl/sync.d.ts +144 -0
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -0
- package/dist/esm/assertion/impl/sync.js +22 -0
- package/dist/esm/assertion/impl/sync.js.map +1 -0
- package/dist/esm/assertion/index.d.ts +15 -0
- package/dist/esm/assertion/index.d.ts.map +1 -0
- package/dist/esm/assertion/index.js +14 -0
- package/dist/esm/assertion/index.js.map +1 -0
- package/dist/esm/assertion/slotify.d.ts +23 -0
- package/dist/esm/assertion/slotify.d.ts.map +1 -0
- package/dist/esm/assertion/slotify.js +63 -0
- package/dist/esm/assertion/slotify.js.map +1 -0
- package/dist/esm/bootstrap.d.ts +175 -0
- package/dist/esm/bootstrap.d.ts.map +1 -0
- package/dist/esm/bootstrap.js +30 -0
- package/dist/esm/bootstrap.js.map +1 -0
- package/dist/esm/constant.d.ts +12 -0
- package/dist/esm/constant.d.ts.map +1 -0
- package/dist/esm/constant.js +30 -0
- package/dist/esm/constant.js.map +1 -0
- package/dist/esm/error.d.ts +20 -0
- package/dist/esm/error.d.ts.map +1 -0
- package/dist/esm/error.js +35 -0
- package/dist/esm/error.js.map +1 -0
- package/dist/esm/expect.d.ts +9 -0
- package/dist/esm/expect.d.ts.map +1 -0
- package/dist/esm/expect.js +210 -0
- package/dist/esm/expect.js.map +1 -0
- package/dist/esm/guards.d.ts +93 -0
- package/dist/esm/guards.d.ts.map +1 -0
- package/dist/esm/guards.js +144 -0
- package/dist/esm/guards.js.map +1 -0
- package/dist/esm/index.d.ts +181 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/metadata.d.ts +53 -0
- package/dist/esm/metadata.d.ts.map +1 -0
- package/dist/esm/metadata.js +48 -0
- package/dist/esm/metadata.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/schema.d.ts +373 -0
- package/dist/esm/schema.d.ts.map +1 -0
- package/dist/esm/schema.js +434 -0
- package/dist/esm/schema.js.map +1 -0
- package/dist/esm/types.d.ts +79 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +8 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/use.d.ts +4 -0
- package/dist/esm/use.d.ts.map +1 -0
- package/dist/esm/use.js +32 -0
- package/dist/esm/use.js.map +1 -0
- package/dist/esm/util.d.ts +67 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +182 -0
- package/dist/esm/util.js.map +1 -0
- package/package.json +17 -6
- package/src/assertion/impl/sync-parametric.ts +5 -2
- package/src/bootstrap.ts +5 -18
- package/src/guards.ts +5 -2
- package/src/use.ts +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.2](https://github.com/boneskull/bupkis/compare/bupkis-v0.1.1...bupkis-v0.1.2) (2025-09-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **util:** isConstructable handles Symbol and BigInt properly ([c13747a](https://github.com/boneskull/bupkis/commit/c13747aa57b5806c38389c1d8347a2966cb17f22))
|
|
9
|
+
|
|
10
|
+
## [0.1.1](https://github.com/boneskull/bupkis/compare/bupkis-v0.1.0...bupkis-v0.1.1) (2025-09-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* actually build before publish ([996c28e](https://github.com/boneskull/bupkis/commit/996c28e223ce488d07ea0b7633829ff25d510be3))
|
|
16
|
+
|
|
3
17
|
## [0.1.0](https://github.com/boneskull/bupkis/compare/bupkis-v0.0.2...bupkis-v0.1.0) (2025-09-08)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains the main API types
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import type { TupleToUnion, UnionToIntersection } from 'type-fest';
|
|
7
|
+
import type { AnyAsyncAssertion, AnyAsyncAssertions, AnySyncAssertion, AnySyncAssertions, BuiltinAsyncAssertions, BuiltinSyncAssertions } from './assertion/assertion-types.js';
|
|
8
|
+
import type { createAssertion, createAsyncAssertion } from './assertion/create.js';
|
|
9
|
+
import { type InferredExpectSlots, type MutableOrReadonly, type UseFn } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Base set of properties included in both {@link Expect} and {@link ExpectAsync}.
|
|
12
|
+
*/
|
|
13
|
+
export interface BaseExpect {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new synchronous assertion.
|
|
16
|
+
*/
|
|
17
|
+
createAssertion: typeof createAssertion;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new asynchronous assertion.
|
|
20
|
+
*/
|
|
21
|
+
createAsyncAssertion: typeof createAsyncAssertion;
|
|
22
|
+
/**
|
|
23
|
+
* Fails immediately with optional `reason`.
|
|
24
|
+
*
|
|
25
|
+
* @param reason Reason for failure
|
|
26
|
+
* @throws {AssertionError}
|
|
27
|
+
*/
|
|
28
|
+
fail(this: void, reason?: string): never;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The main synchronous assertion function.
|
|
32
|
+
*
|
|
33
|
+
* Contains properties in {@link ExpectSyncProps}.
|
|
34
|
+
*
|
|
35
|
+
* @template T All synchronous assertions available
|
|
36
|
+
* @template U All asynchronous assertions available; for use in
|
|
37
|
+
* {@link ExpectSyncProps.use}
|
|
38
|
+
* @useDeclaredType
|
|
39
|
+
* @see {@link expect}
|
|
40
|
+
*/
|
|
41
|
+
export type Expect<T extends AnySyncAssertions = BuiltinSyncAssertions, U extends AnyAsyncAssertions = BuiltinAsyncAssertions> = ExpectFunction<T> & ExpectSyncProps<T, U>;
|
|
42
|
+
/**
|
|
43
|
+
* The main asynchronous assertion function.
|
|
44
|
+
*
|
|
45
|
+
* Contains properties in {@link ExpectSyncProps}.
|
|
46
|
+
*
|
|
47
|
+
* @useDeclaredType
|
|
48
|
+
* @see {@link expectAsync}
|
|
49
|
+
*/
|
|
50
|
+
export type ExpectAsync<T extends AnyAsyncAssertions = BuiltinAsyncAssertions, U extends AnySyncAssertions = BuiltinSyncAssertions> = ExpectAsyncFunction<T> & ExpectAsyncProps<T, U>;
|
|
51
|
+
/**
|
|
52
|
+
* All function overloads for `expectAsync()`; part of {@link ExpectAsync}.
|
|
53
|
+
*/
|
|
54
|
+
export type ExpectAsyncFunction<T extends AnyAsyncAssertions = BuiltinAsyncAssertions> = UnionToIntersection<TupleToUnion<{
|
|
55
|
+
[K in keyof T]: T[K] extends AnyAsyncAssertion ? (...args: MutableOrReadonly<InferredExpectSlots<T[K]['parts']>>) => Promise<void> : never;
|
|
56
|
+
}>>;
|
|
57
|
+
/**
|
|
58
|
+
* Properties available on `expectAsync()`; part of {@link ExpectAsync}.
|
|
59
|
+
*/
|
|
60
|
+
export interface ExpectAsyncProps<T extends AnyAsyncAssertions, U extends AnySyncAssertions> extends BaseExpect {
|
|
61
|
+
/**
|
|
62
|
+
* Tuple of all assertions available in this `expect()`.
|
|
63
|
+
*/
|
|
64
|
+
assertions: T;
|
|
65
|
+
/**
|
|
66
|
+
* Function to add more assertions to this `expect()`, returning a new
|
|
67
|
+
* `expect()` and `expectAsync()` pair with the combined assertions.
|
|
68
|
+
*/
|
|
69
|
+
use: UseFn<U, T>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* All function overloads for `expect()`; part of {@link Expect}.
|
|
73
|
+
*
|
|
74
|
+
* @useDeclaredType
|
|
75
|
+
*/
|
|
76
|
+
export type ExpectFunction<T extends AnySyncAssertions = BuiltinSyncAssertions> = UnionToIntersection<TupleToUnion<{
|
|
77
|
+
[K in keyof T]: T[K] extends AnySyncAssertion ? (...args: MutableOrReadonly<InferredExpectSlots<T[K]['parts']>>) => void : never;
|
|
78
|
+
}>>;
|
|
79
|
+
/**
|
|
80
|
+
* Properties for `expect()`; part of {@link Expect}.
|
|
81
|
+
*/
|
|
82
|
+
export interface ExpectSyncProps<T extends AnySyncAssertions, U extends AnyAsyncAssertions> extends BaseExpect {
|
|
83
|
+
/**
|
|
84
|
+
* Tuple of all assertions available in this `expect()`.
|
|
85
|
+
*/
|
|
86
|
+
assertions: T;
|
|
87
|
+
/**
|
|
88
|
+
* Function to add more assertions to this `expect()`, returning a new
|
|
89
|
+
* `expect()` and `expectAsync()` pair with the combined assertions.
|
|
90
|
+
*/
|
|
91
|
+
use: UseFn<T, U>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,KAAK,EACX,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,eAAe,EAAE,OAAO,eAAe,CAAC;IACxC;;OAEG;IACH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BAAqB,IACjD,mBAAmB,CACrB,YAAY,CAAC;KACV,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,gBAAgB,GACzC,CAAC,GAAG,IAAI,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,GACxE,KAAK;CACV,CAAC,CACH,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,iBAAiB,EAC3B,CAAC,SAAS,kBAAkB,CAC5B,SAAQ,UAAU;IAClB;;OAEG;IACH,UAAU,EAAE,CAAC,CAAC;IAEd;;;OAGG;IACH,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type AssertionAsync, type AssertionFunctionAsync, type AssertionImplAsync, type AssertionImplFnAsync, type AssertionImplSchemaAsync, type AssertionParts, type AssertionSchemaAsync, type AssertionSlots, type ParsedResult, type ParsedValues } from './assertion-types.js';
|
|
2
|
+
import { BupkisAssertion } from './assertion.js';
|
|
3
|
+
export declare abstract class BupkisAssertionAsync<Parts extends AssertionParts, Impl extends AssertionImplAsync<Parts>, Slots extends AssertionSlots<Parts>> extends BupkisAssertion<Parts, Impl, Slots> implements AssertionAsync<Parts, Impl, Slots> {
|
|
4
|
+
abstract executeAsync(parsedValues: ParsedValues<Parts>, args: unknown[], stackStartFn: (...args: any[]) => any, parseResult?: ParsedResult<Parts>): Promise<void>;
|
|
5
|
+
parseValuesAsync<Args extends readonly unknown[]>(args: Args): Promise<ParsedResult<Parts>>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* An assertion implemented as a Zod schema.
|
|
9
|
+
*
|
|
10
|
+
* Async schemas are supported via {@link expectAsync}.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Optimized schema assertion that performs subject validation during
|
|
14
|
+
* parseValues() to eliminate double parsing for simple schema-based
|
|
15
|
+
* assertions.
|
|
16
|
+
*
|
|
17
|
+
* This class implements Option 2 from the z.function() analysis - it caches the
|
|
18
|
+
* subject validation result during argument parsing and reuses it during
|
|
19
|
+
* execution, eliminating the double parsing overhead.
|
|
20
|
+
*/
|
|
21
|
+
export declare class BupkisAssertionFunctionAsync<Parts extends AssertionParts, Impl extends AssertionImplFnAsync<Parts>, Slots extends AssertionSlots<Parts>> extends BupkisAssertionAsync<Parts, Impl, Slots> implements AssertionFunctionAsync<Parts, Impl, Slots> {
|
|
22
|
+
executeAsync(parsedValues: ParsedValues<Parts>, args: unknown[], stackStartFn: (...args: any[]) => any, _parseResult?: ParsedResult<Parts>): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A class representing an assertion implemented as a function.
|
|
26
|
+
*
|
|
27
|
+
* This function may:
|
|
28
|
+
*
|
|
29
|
+
* 1. Return a `boolean` indicating pass/fail.
|
|
30
|
+
* 2. Return a `ZodType` which will be used to validate the subject.
|
|
31
|
+
* 3. Return a `Promise` resolving to either of the above (when called via
|
|
32
|
+
* {@link expectAsync})
|
|
33
|
+
* 4. Throw a {@link AssertionError}; when called via {@link expectAsync}, reject
|
|
34
|
+
* with an {@link AssertionError}
|
|
35
|
+
*/
|
|
36
|
+
export declare class BupkisAssertionSchemaAsync<Parts extends AssertionParts, Impl extends AssertionImplSchemaAsync<Parts>, Slots extends AssertionSlots<Parts>> extends BupkisAssertionAsync<Parts, Impl, Slots> implements AssertionSchemaAsync<Parts, Impl, Slots> {
|
|
37
|
+
executeAsync(parsedValues: ParsedValues<Parts>, _args: unknown[], stackStartFn: (...args: any[]) => any, _parseResult?: ParsedResult<Parts>): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Determines if this assertion can be optimized (simple single-subject
|
|
40
|
+
* schema). Only simple assertions like ['to be a string'] with z.string()
|
|
41
|
+
* qualify.
|
|
42
|
+
*/
|
|
43
|
+
private isSimpleSchemaAssertion;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=assertion-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertion-async.d.ts","sourceRoot":"","sources":["../../../src/assertion/assertion-async.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,8BAAsB,oBAAoB,CACtC,KAAK,SAAS,cAAc,EAC5B,IAAI,SAAS,kBAAkB,CAAC,KAAK,CAAC,EACtC,KAAK,SAAS,cAAc,CAAC,KAAK,CAAC,CAErC,SAAQ,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAC1C,YAAW,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAE7C,QAAQ,CAAC,YAAY,CACnB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,IAAI,EAAE,OAAO,EAAE,EACf,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,WAAW,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAEV,gBAAgB,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EACpD,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CA0ChC;AACD;;;;GAIG;AACH;;;;;;;;GAQG;AAEH,qBAAa,4BAA4B,CACrC,KAAK,SAAS,cAAc,EAC5B,IAAI,SAAS,oBAAoB,CAAC,KAAK,CAAC,EACxC,KAAK,SAAS,cAAc,CAAC,KAAK,CAAC,CAErC,SAAQ,oBAAoB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAC/C,YAAW,sBAAsB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAEtC,YAAY,CACzB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,IAAI,EAAE,OAAO,EAAE,EACf,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC;CA8BjB;AAED;;;;;;;;;;;GAWG;AAEH,qBAAa,0BAA0B,CACnC,KAAK,SAAS,cAAc,EAC5B,IAAI,SAAS,wBAAwB,CAAC,KAAK,CAAC,EAC5C,KAAK,SAAS,cAAc,CAAC,KAAK,CAAC,CAErC,SAAQ,oBAAoB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAC/C,YAAW,oBAAoB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAEpC,YAAY,CACzB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,KAAK,EAAE,OAAO,EAAE,EAChB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC;IAahB;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAehC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BupkisAssertionSchemaAsync = exports.BupkisAssertionFunctionAsync = exports.BupkisAssertionAsync = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const v4_1 = __importDefault(require("zod/v4"));
|
|
10
|
+
const constant_js_1 = require("../constant.js");
|
|
11
|
+
const error_js_1 = require("../error.js");
|
|
12
|
+
const guards_js_1 = require("../guards.js");
|
|
13
|
+
const metadata_js_1 = require("../metadata.js");
|
|
14
|
+
const assertion_js_1 = require("./assertion.js");
|
|
15
|
+
const debug = (0, debug_1.default)('bupkis:assertion:async');
|
|
16
|
+
class BupkisAssertionAsync extends assertion_js_1.BupkisAssertion {
|
|
17
|
+
async parseValuesAsync(args) {
|
|
18
|
+
const { slots } = this;
|
|
19
|
+
const parsedValues = [];
|
|
20
|
+
if (slots.length !== args.length) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let exactMatch = true;
|
|
26
|
+
for (let i = 0; i < slots.length; i++) {
|
|
27
|
+
const slot = slots[i];
|
|
28
|
+
const arg = args[i];
|
|
29
|
+
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
30
|
+
if (parsedLiteralResult === true) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
else if (parsedLiteralResult !== false) {
|
|
34
|
+
return parsedLiteralResult;
|
|
35
|
+
}
|
|
36
|
+
// unknown/any accept anything
|
|
37
|
+
// IMPORTANT: do not use a type guard here; it will break inference
|
|
38
|
+
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
39
|
+
debug('Skipping unknown/any slot validation for arg', arg);
|
|
40
|
+
parsedValues.push(arg);
|
|
41
|
+
exactMatch = false;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const result = await slot.safeParseAsync(arg);
|
|
45
|
+
if (!result.success) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
parsedValues.push(result.data);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
exactMatch,
|
|
54
|
+
parsedValues: parsedValues,
|
|
55
|
+
success: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.BupkisAssertionAsync = BupkisAssertionAsync;
|
|
60
|
+
/**
|
|
61
|
+
* An assertion implemented as a Zod schema.
|
|
62
|
+
*
|
|
63
|
+
* Async schemas are supported via {@link expectAsync}.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Optimized schema assertion that performs subject validation during
|
|
67
|
+
* parseValues() to eliminate double parsing for simple schema-based
|
|
68
|
+
* assertions.
|
|
69
|
+
*
|
|
70
|
+
* This class implements Option 2 from the z.function() analysis - it caches the
|
|
71
|
+
* subject validation result during argument parsing and reuses it during
|
|
72
|
+
* execution, eliminating the double parsing overhead.
|
|
73
|
+
*/
|
|
74
|
+
class BupkisAssertionFunctionAsync extends BupkisAssertionAsync {
|
|
75
|
+
async executeAsync(parsedValues, args, stackStartFn, _parseResult) {
|
|
76
|
+
const { impl } = this;
|
|
77
|
+
const result = await impl(...parsedValues);
|
|
78
|
+
if ((0, guards_js_1.isZodType)(result)) {
|
|
79
|
+
try {
|
|
80
|
+
await result.parseAsync(parsedValues[0]);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if ((0, guards_js_1.isA)(error, v4_1.default.ZodError)) {
|
|
84
|
+
throw this.translateZodError(stackStartFn, error, ...parsedValues);
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if ((0, guards_js_1.isBoolean)(result)) {
|
|
90
|
+
if (!result) {
|
|
91
|
+
throw new error_js_1.AssertionError({
|
|
92
|
+
message: `Assertion ${this} failed for arguments: ${(0, util_1.inspect)(args)}`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if ((0, guards_js_1.isAssertionFailure)(result)) {
|
|
97
|
+
throw new error_js_1.AssertionError({
|
|
98
|
+
actual: result.actual,
|
|
99
|
+
expected: result.expected,
|
|
100
|
+
message: result.message ?? `Assertion ${this} failed`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (result) {
|
|
104
|
+
throw new TypeError(`Invalid return type from assertion ${this}; expected boolean, ZodType, or AssertionFailure`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.BupkisAssertionFunctionAsync = BupkisAssertionFunctionAsync;
|
|
109
|
+
/**
|
|
110
|
+
* A class representing an assertion implemented as a function.
|
|
111
|
+
*
|
|
112
|
+
* This function may:
|
|
113
|
+
*
|
|
114
|
+
* 1. Return a `boolean` indicating pass/fail.
|
|
115
|
+
* 2. Return a `ZodType` which will be used to validate the subject.
|
|
116
|
+
* 3. Return a `Promise` resolving to either of the above (when called via
|
|
117
|
+
* {@link expectAsync})
|
|
118
|
+
* 4. Throw a {@link AssertionError}; when called via {@link expectAsync}, reject
|
|
119
|
+
* with an {@link AssertionError}
|
|
120
|
+
*/
|
|
121
|
+
class BupkisAssertionSchemaAsync extends BupkisAssertionAsync {
|
|
122
|
+
async executeAsync(parsedValues, _args, stackStartFn, _parseResult) {
|
|
123
|
+
// For async, fall back to standard implementation for now
|
|
124
|
+
const [subject] = parsedValues;
|
|
125
|
+
try {
|
|
126
|
+
await this.impl.parseAsync(subject);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if ((0, guards_js_1.isA)(error, v4_1.default.ZodError)) {
|
|
130
|
+
throw this.translateZodError(stackStartFn, error, ...parsedValues);
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Determines if this assertion can be optimized (simple single-subject
|
|
137
|
+
* schema). Only simple assertions like ['to be a string'] with z.string()
|
|
138
|
+
* qualify.
|
|
139
|
+
*/
|
|
140
|
+
isSimpleSchemaAssertion() {
|
|
141
|
+
// Only optimize if we have exactly one subject slot + string literal slots
|
|
142
|
+
// and no complex argument processing
|
|
143
|
+
const hasSubjectSlot = this.slots.length > 0 &&
|
|
144
|
+
(this.slots[0]?.def.type === 'unknown' ||
|
|
145
|
+
this.slots[0]?.def.type === 'any');
|
|
146
|
+
const allOtherSlotsAreLiterals = this.slots.slice(1).every((slot) => {
|
|
147
|
+
const meta = metadata_js_1.BupkisRegistry.get(slot) ?? {};
|
|
148
|
+
return constant_js_1.kStringLiteral in meta;
|
|
149
|
+
});
|
|
150
|
+
return hasSubjectSlot && allOtherSlotsAreLiterals;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.BupkisAssertionSchemaAsync = BupkisAssertionSchemaAsync;
|
|
154
|
+
//# sourceMappingURL=assertion-async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertion-async.js","sourceRoot":"","sources":["../../../src/assertion/assertion-async.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+BAA+B;AAC/B,gDAAuB;AAEvB,gDAAgD;AAChD,0CAA6C;AAC7C,4CAA6E;AAC7E,gDAAgD;AAahD,iDAAiD;AACjD,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,wBAAwB,CAAC,CAAC;AAE9C,MAAsB,oBAKpB,SAAQ,8BAAmC;IAU3C,KAAK,CAAC,gBAAgB,CACpB,IAAU;QAEV,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QACvB,MAAM,YAAY,GAAU,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO;gBACL,OAAO,EAAE,KAAK;aACf,CAAC;QACJ,CAAC;QACD,IAAI,UAAU,GAAG,IAAI,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,C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
* @packageDocumentation
|
|
5
|
+
* @see {@link AssertionFunctionSync} for function-based assertions
|
|
6
|
+
* @see {@link AssertionSchemaSync} for schema-based assertions
|
|
7
|
+
*/
|
|
8
|
+
import { type AssertionFunctionSync, type AssertionImplFnSync, type AssertionImplSchemaSync, type AssertionImplSync, type AssertionParts, type AssertionSchemaSync, type AssertionSlots, type AssertionSync, type ParsedResult, type ParsedValues } from './assertion-types.js';
|
|
9
|
+
import { BupkisAssertion } from './assertion.js';
|
|
10
|
+
/**
|
|
11
|
+
* Abstract class for synchronous assertions.
|
|
12
|
+
*
|
|
13
|
+
* Child classes are expected to implement {@link execute}.
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class BupkisAssertionSync<Parts extends AssertionParts, Impl extends AssertionImplSync<Parts>, Slots extends AssertionSlots<Parts>> extends BupkisAssertion<Parts, Impl, Slots> implements AssertionSync<Parts, Impl, Slots> {
|
|
16
|
+
/**
|
|
17
|
+
* Parses raw arguments synchronously against this `Assertion`'s Slots to
|
|
18
|
+
* determine if they match this `Assertion`.
|
|
19
|
+
*
|
|
20
|
+
* @param args Raw arguments provided to `expect()`
|
|
21
|
+
* @returns Result of parsing attempt
|
|
22
|
+
*/
|
|
23
|
+
abstract execute(parsedValues: ParsedValues<Parts>, args: unknown[], stackStartFn: (...args: any[]) => any, parseResult?: ParsedResult<Parts>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Parses raw arguments against the slots of this assertion to determine if
|
|
26
|
+
* this assertion should be executed against those arguments.
|
|
27
|
+
*
|
|
28
|
+
* For example, if an assertion wants the subject to be a `z.string()`, then
|
|
29
|
+
* this will validate that the first raw arg parses as a string. It will also
|
|
30
|
+
* validate Phrase Literals as well, such as "to be a string". If all slots
|
|
31
|
+
* match and none of the slots are "unknown" or "any", then `exactMatch` will
|
|
32
|
+
* be true.
|
|
33
|
+
*
|
|
34
|
+
* If any slot does not match, this returns `success: false`.
|
|
35
|
+
*
|
|
36
|
+
* @param args Raw arguments
|
|
37
|
+
* @returns Result of parsing attempt
|
|
38
|
+
*/
|
|
39
|
+
parseValues<Args extends readonly unknown[]>(args: Args): ParsedResult<Parts>;
|
|
40
|
+
}
|
|
41
|
+
export declare class BupkisAssertionFunctionSync<Parts extends AssertionParts, Impl extends AssertionImplFnSync<Parts>, Slots extends AssertionSlots<Parts>> extends BupkisAssertionSync<Parts, Impl, Slots> implements AssertionFunctionSync<Parts, Impl, Slots> {
|
|
42
|
+
execute(parsedValues: ParsedValues<Parts>, args: unknown[], stackStartFn: (...args: any[]) => any, _parseResult?: ParsedResult<Parts>): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A class representing an assertion implemented as a function.
|
|
46
|
+
*
|
|
47
|
+
* This function may:
|
|
48
|
+
*
|
|
49
|
+
* 1. Return a `boolean` indicating pass/fail.
|
|
50
|
+
* 2. Return a `ZodType` which will be used to validate the subject.
|
|
51
|
+
* 3. Return a `Promise` resolving to either of the above (when called via
|
|
52
|
+
* {@link expectAsync})
|
|
53
|
+
* 4. Throw a {@link AssertionError}; when called via {@link expectAsync}, reject
|
|
54
|
+
* with an {@link AssertionError}
|
|
55
|
+
*/
|
|
56
|
+
export declare class BupkisAssertionSchemaSync<Parts extends AssertionParts, Impl extends AssertionImplSchemaSync<Parts>, Slots extends AssertionSlots<Parts>> extends BupkisAssertionSync<Parts, Impl, Slots> implements AssertionSchemaSync<Parts, Impl, Slots> {
|
|
57
|
+
execute(parsedValues: ParsedValues<Parts>, args: unknown[], stackStartFn: (...args: any[]) => any, parseResult?: ParsedResult<Parts>): void;
|
|
58
|
+
parseValues<Args extends readonly unknown[]>(args: Args): ParsedResult<Parts>;
|
|
59
|
+
/**
|
|
60
|
+
* Determines if this assertion can be optimized (simple single-subject
|
|
61
|
+
* schema). Only simple assertions like ['to be a string'] with z.string()
|
|
62
|
+
* qualify.
|
|
63
|
+
*/
|
|
64
|
+
private isSimpleSchemaAssertion;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=assertion-sync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KAAK,EAAE,IAAI,EAAE,KAAK,CAC9C,YAAW,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAE3C,OAAO,CACd,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,IAAI,EAAE,OAAO,EAAE,EACf,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GACjC,IAAI;CA2CR;AAED;;;;;;;;;;;GAWG;AAEH,qBAAa,yBAAyB,CAClC,KAAK,SAAS,cAAc,EAC5B,IAAI,SAAS,uBAAuB,CAAC,KAAK,CAAC,EAC3C,KAAK,SAAS,cAAc,CAAC,KAAK,CAAC,CAErC,SAAQ,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAC9C,YAAW,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAEzC,OAAO,CACd,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,IAAI,EAAE,OAAO,EAAE,EACf,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,WAAW,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GAChC,IAAI;IA+BE,WAAW,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EAClD,IAAI,EAAE,IAAI,GACT,YAAY,CAAC,KAAK,CAAC;IA8EtB;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAehC"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Synchronous assertion subclasses.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @see {@link AssertionFunctionSync} for function-based assertions
|
|
7
|
+
* @see {@link AssertionSchemaSync} for schema-based assertions
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.BupkisAssertionSchemaSync = exports.BupkisAssertionFunctionSync = exports.BupkisAssertionSync = void 0;
|
|
14
|
+
const debug_1 = __importDefault(require("debug"));
|
|
15
|
+
const util_1 = require("util");
|
|
16
|
+
const constant_js_1 = require("../constant.js");
|
|
17
|
+
const error_js_1 = require("../error.js");
|
|
18
|
+
const guards_js_1 = require("../guards.js");
|
|
19
|
+
const metadata_js_1 = require("../metadata.js");
|
|
20
|
+
const assertion_js_1 = require("./assertion.js");
|
|
21
|
+
const debug = (0, debug_1.default)('bupkis:assertion:sync');
|
|
22
|
+
/**
|
|
23
|
+
* Abstract class for synchronous assertions.
|
|
24
|
+
*
|
|
25
|
+
* Child classes are expected to implement {@link execute}.
|
|
26
|
+
*/
|
|
27
|
+
class BupkisAssertionSync extends assertion_js_1.BupkisAssertion {
|
|
28
|
+
/**
|
|
29
|
+
* Parses raw arguments against the slots of this assertion to determine if
|
|
30
|
+
* this assertion should be executed against those arguments.
|
|
31
|
+
*
|
|
32
|
+
* For example, if an assertion wants the subject to be a `z.string()`, then
|
|
33
|
+
* this will validate that the first raw arg parses as a string. It will also
|
|
34
|
+
* validate Phrase Literals as well, such as "to be a string". If all slots
|
|
35
|
+
* match and none of the slots are "unknown" or "any", then `exactMatch` will
|
|
36
|
+
* be true.
|
|
37
|
+
*
|
|
38
|
+
* If any slot does not match, this returns `success: false`.
|
|
39
|
+
*
|
|
40
|
+
* @param args Raw arguments
|
|
41
|
+
* @returns Result of parsing attempt
|
|
42
|
+
*/
|
|
43
|
+
parseValues(args) {
|
|
44
|
+
const { slots } = this;
|
|
45
|
+
const parsedValues = [];
|
|
46
|
+
const mismatch = this.maybeParseValuesArgMismatch(args);
|
|
47
|
+
if (mismatch) {
|
|
48
|
+
return mismatch;
|
|
49
|
+
}
|
|
50
|
+
let exactMatch = true;
|
|
51
|
+
for (let i = 0; i < slots.length; i++) {
|
|
52
|
+
const slot = slots[i];
|
|
53
|
+
const arg = args[i];
|
|
54
|
+
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
55
|
+
if (parsedLiteralResult === true) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
else if (parsedLiteralResult !== false) {
|
|
59
|
+
return parsedLiteralResult;
|
|
60
|
+
}
|
|
61
|
+
// unknown/any accept anything
|
|
62
|
+
// IMPORTANT: do not use a type guard here
|
|
63
|
+
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
64
|
+
// debug('Skipping unknown/any slot validation for arg', arg);
|
|
65
|
+
parsedValues.push(arg);
|
|
66
|
+
exactMatch = false;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
// low-effort check
|
|
70
|
+
if ((0, guards_js_1.isZodPromise)(slot)) {
|
|
71
|
+
throw new TypeError(`${this} expects a Promise for slot ${i}; use expectAsync() instead of expect()`);
|
|
72
|
+
}
|
|
73
|
+
const result = slot.safeParse(arg);
|
|
74
|
+
if (!result.success) {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
parsedValues.push(arg);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
exactMatch,
|
|
83
|
+
parsedValues: parsedValues,
|
|
84
|
+
success: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.BupkisAssertionSync = BupkisAssertionSync;
|
|
89
|
+
class BupkisAssertionFunctionSync extends BupkisAssertionSync {
|
|
90
|
+
execute(parsedValues, args, stackStartFn, _parseResult) {
|
|
91
|
+
const result = this.impl.call(null,
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
93
|
+
...parsedValues);
|
|
94
|
+
if ((0, guards_js_1.isPromiseLike)(result)) {
|
|
95
|
+
// Avoid unhandled promise rejection
|
|
96
|
+
Promise.resolve(result).catch((err) => {
|
|
97
|
+
debug(`Ate unhandled rejection from assertion %s: %O`, this, err);
|
|
98
|
+
});
|
|
99
|
+
throw new TypeError(`Assertion ${this} returned a Promise; use expectAsync() instead of expect()`);
|
|
100
|
+
}
|
|
101
|
+
if ((0, guards_js_1.isZodType)(result)) {
|
|
102
|
+
const zodResult = result.safeParse(parsedValues[0]);
|
|
103
|
+
if (!zodResult.success) {
|
|
104
|
+
throw this.translateZodError(stackStartFn, zodResult.error, ...parsedValues);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else if ((0, guards_js_1.isBoolean)(result)) {
|
|
108
|
+
if (!result) {
|
|
109
|
+
throw new error_js_1.AssertionError({
|
|
110
|
+
message: `Assertion ${this} failed for arguments: ${(0, util_1.inspect)(args)}`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if ((0, guards_js_1.isAssertionFailure)(result)) {
|
|
115
|
+
throw new error_js_1.AssertionError({
|
|
116
|
+
actual: result.actual,
|
|
117
|
+
expected: result.expected,
|
|
118
|
+
message: result.message ?? `Assertion ${this} failed`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else if (result) {
|
|
122
|
+
throw new TypeError(`Invalid return type from assertion ${this}; expected boolean, ZodType, or AssertionFailure`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.BupkisAssertionFunctionSync = BupkisAssertionFunctionSync;
|
|
127
|
+
/**
|
|
128
|
+
* A class representing an assertion implemented as a function.
|
|
129
|
+
*
|
|
130
|
+
* This function may:
|
|
131
|
+
*
|
|
132
|
+
* 1. Return a `boolean` indicating pass/fail.
|
|
133
|
+
* 2. Return a `ZodType` which will be used to validate the subject.
|
|
134
|
+
* 3. Return a `Promise` resolving to either of the above (when called via
|
|
135
|
+
* {@link expectAsync})
|
|
136
|
+
* 4. Throw a {@link AssertionError}; when called via {@link expectAsync}, reject
|
|
137
|
+
* with an {@link AssertionError}
|
|
138
|
+
*/
|
|
139
|
+
class BupkisAssertionSchemaSync extends BupkisAssertionSync {
|
|
140
|
+
execute(parsedValues, args, stackStartFn, parseResult) {
|
|
141
|
+
// Check if we have cached validation result from parseValues
|
|
142
|
+
const cachedValidation = parseResult?.success
|
|
143
|
+
? parseResult.subjectValidationResult
|
|
144
|
+
: undefined;
|
|
145
|
+
if (cachedValidation) {
|
|
146
|
+
debug('Using cached subject validation result from parseValues for %s', this);
|
|
147
|
+
if (!cachedValidation.success) {
|
|
148
|
+
// Subject validation failed during parseValues, throw the cached error
|
|
149
|
+
throw this.translateZodError(stackStartFn, cachedValidation.error, ...parsedValues);
|
|
150
|
+
}
|
|
151
|
+
// Subject validation passed, nothing more to do
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// Fall back to standard validation if no cached result
|
|
155
|
+
const [subject] = parsedValues;
|
|
156
|
+
const result = this.impl.safeParse(subject);
|
|
157
|
+
if (!result.success) {
|
|
158
|
+
throw this.translateZodError(stackStartFn, result.error, ...parsedValues);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
parseValues(args) {
|
|
162
|
+
const { slots } = this;
|
|
163
|
+
const parsedValues = [];
|
|
164
|
+
const mismatch = this.maybeParseValuesArgMismatch(args);
|
|
165
|
+
if (mismatch) {
|
|
166
|
+
return mismatch;
|
|
167
|
+
}
|
|
168
|
+
let exactMatch = true;
|
|
169
|
+
let subjectValidationResult;
|
|
170
|
+
for (let i = 0; i < slots.length; i++) {
|
|
171
|
+
const slot = slots[i];
|
|
172
|
+
const arg = args[i];
|
|
173
|
+
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
174
|
+
if (parsedLiteralResult === true) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
else if (parsedLiteralResult !== false) {
|
|
178
|
+
return parsedLiteralResult;
|
|
179
|
+
}
|
|
180
|
+
// For the subject slot (first slot if it's unknown/any), try optimized validation
|
|
181
|
+
if (i === 0 &&
|
|
182
|
+
(slot.def.type === 'unknown' || slot.def.type === 'any') &&
|
|
183
|
+
this.isSimpleSchemaAssertion()) {
|
|
184
|
+
const result = this.impl.safeParse(arg);
|
|
185
|
+
if (result.success) {
|
|
186
|
+
subjectValidationResult = { data: result.data, success: true };
|
|
187
|
+
parsedValues.push(result.data); // Use validated data
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
subjectValidationResult = { error: result.error, success: false };
|
|
191
|
+
parsedValues.push(arg); // Keep original for error reporting
|
|
192
|
+
}
|
|
193
|
+
exactMatch = false; // Subject was validated, so we know the exact type
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
// Standard slot processing for non-optimized cases
|
|
197
|
+
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
198
|
+
debug('Skipping unknown/any slot validation for arg', arg);
|
|
199
|
+
parsedValues.push(arg);
|
|
200
|
+
exactMatch = false;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if ((0, guards_js_1.isZodPromise)(slot)) {
|
|
204
|
+
throw new TypeError(`${this} expects a Promise for slot ${i}; use expectAsync() instead of expect()`);
|
|
205
|
+
}
|
|
206
|
+
const result = slot.safeParse(arg);
|
|
207
|
+
if (!result.success) {
|
|
208
|
+
return {
|
|
209
|
+
success: false,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
parsedValues.push(arg);
|
|
213
|
+
}
|
|
214
|
+
const result = {
|
|
215
|
+
exactMatch,
|
|
216
|
+
parsedValues: parsedValues,
|
|
217
|
+
success: true,
|
|
218
|
+
};
|
|
219
|
+
// Add cached validation result if we performed optimization
|
|
220
|
+
if (subjectValidationResult) {
|
|
221
|
+
result.subjectValidationResult = subjectValidationResult;
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Determines if this assertion can be optimized (simple single-subject
|
|
227
|
+
* schema). Only simple assertions like ['to be a string'] with z.string()
|
|
228
|
+
* qualify.
|
|
229
|
+
*/
|
|
230
|
+
isSimpleSchemaAssertion() {
|
|
231
|
+
// Only optimize if we have exactly one subject slot + string literal slots
|
|
232
|
+
// and no complex argument processing
|
|
233
|
+
const hasSubjectSlot = this.slots.length > 0 &&
|
|
234
|
+
(this.slots[0]?.def.type === 'unknown' ||
|
|
235
|
+
this.slots[0]?.def.type === 'any');
|
|
236
|
+
const allOtherSlotsAreLiterals = this.slots.slice(1).every((slot) => {
|
|
237
|
+
const meta = metadata_js_1.BupkisRegistry.get(slot) ?? {};
|
|
238
|
+
return constant_js_1.kStringLiteral in meta;
|
|
239
|
+
});
|
|
240
|
+
return hasSubjectSlot && allOtherSlotsAreLiterals;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.BupkisAssertionSchemaSync = BupkisAssertionSchemaSync;
|
|
244
|
+
//# sourceMappingURL=assertion-sync.js.map
|