bupkis 0.18.1 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -4
- package/src/assertion/assertion-types.ts +4 -4
- package/src/assertion/impl/sync-parametric.ts +1 -1
- package/src/expect.ts +0 -4
- package/src/guards.ts +24 -24
- package/src/internal-schema.ts +16 -32
- package/src/value-to-schema.ts +1 -1
- package/dist/assertion/assertion-async.cjs +0 -268
- package/dist/assertion/assertion-async.cjs.map +0 -1
- package/dist/assertion/assertion-async.d.cts +0 -40
- package/dist/assertion/assertion-async.d.cts.map +0 -1
- package/dist/assertion/assertion-async.d.ts +0 -40
- package/dist/assertion/assertion-async.d.ts.map +0 -1
- package/dist/assertion/assertion-async.js +0 -259
- package/dist/assertion/assertion-async.js.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.cjs +0 -132
- package/dist/assertion/assertion-standard-schema-async.cjs.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.d.cts +0 -52
- package/dist/assertion/assertion-standard-schema-async.d.cts.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.d.ts +0 -52
- package/dist/assertion/assertion-standard-schema-async.d.ts.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.js +0 -128
- package/dist/assertion/assertion-standard-schema-async.js.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.cjs +0 -141
- package/dist/assertion/assertion-standard-schema-sync.cjs.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.d.cts +0 -52
- package/dist/assertion/assertion-standard-schema-sync.d.cts.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.d.ts +0 -52
- package/dist/assertion/assertion-standard-schema-sync.d.ts.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.js +0 -137
- package/dist/assertion/assertion-standard-schema-sync.js.map +0 -1
- package/dist/assertion/assertion-sync.cjs +0 -284
- package/dist/assertion/assertion-sync.cjs.map +0 -1
- package/dist/assertion/assertion-sync.d.cts +0 -60
- package/dist/assertion/assertion-sync.d.cts.map +0 -1
- package/dist/assertion/assertion-sync.d.ts +0 -60
- package/dist/assertion/assertion-sync.d.ts.map +0 -1
- package/dist/assertion/assertion-sync.js +0 -275
- package/dist/assertion/assertion-sync.js.map +0 -1
- package/dist/assertion/assertion-types.cjs +0 -20
- package/dist/assertion/assertion-types.cjs.map +0 -1
- package/dist/assertion/assertion-types.d.cts +0 -1086
- package/dist/assertion/assertion-types.d.cts.map +0 -1
- package/dist/assertion/assertion-types.d.ts +0 -1086
- package/dist/assertion/assertion-types.d.ts.map +0 -1
- package/dist/assertion/assertion-types.js +0 -19
- package/dist/assertion/assertion-types.js.map +0 -1
- package/dist/assertion/assertion.cjs +0 -382
- package/dist/assertion/assertion.cjs.map +0 -1
- package/dist/assertion/assertion.d.cts +0 -109
- package/dist/assertion/assertion.d.cts.map +0 -1
- package/dist/assertion/assertion.d.ts +0 -109
- package/dist/assertion/assertion.d.ts.map +0 -1
- package/dist/assertion/assertion.js +0 -375
- package/dist/assertion/assertion.js.map +0 -1
- package/dist/assertion/create.cjs +0 -148
- package/dist/assertion/create.cjs.map +0 -1
- package/dist/assertion/create.d.cts +0 -85
- package/dist/assertion/create.d.cts.map +0 -1
- package/dist/assertion/create.d.ts +0 -85
- package/dist/assertion/create.d.ts.map +0 -1
- package/dist/assertion/create.js +0 -143
- package/dist/assertion/create.js.map +0 -1
- package/dist/assertion/format-assertion-failure.cjs +0 -63
- package/dist/assertion/format-assertion-failure.cjs.map +0 -1
- package/dist/assertion/format-assertion-failure.d.cts +0 -21
- package/dist/assertion/format-assertion-failure.d.cts.map +0 -1
- package/dist/assertion/format-assertion-failure.d.ts +0 -21
- package/dist/assertion/format-assertion-failure.d.ts.map +0 -1
- package/dist/assertion/format-assertion-failure.js +0 -59
- package/dist/assertion/format-assertion-failure.js.map +0 -1
- package/dist/assertion/impl/assertion-util.cjs +0 -68
- package/dist/assertion/impl/assertion-util.cjs.map +0 -1
- package/dist/assertion/impl/assertion-util.d.cts +0 -36
- package/dist/assertion/impl/assertion-util.d.cts.map +0 -1
- package/dist/assertion/impl/assertion-util.d.ts +0 -36
- package/dist/assertion/impl/assertion-util.d.ts.map +0 -1
- package/dist/assertion/impl/assertion-util.js +0 -62
- package/dist/assertion/impl/assertion-util.js.map +0 -1
- package/dist/assertion/impl/async-iterable.cjs +0 -627
- package/dist/assertion/impl/async-iterable.cjs.map +0 -1
- package/dist/assertion/impl/async-iterable.d.cts +0 -406
- package/dist/assertion/impl/async-iterable.d.cts.map +0 -1
- package/dist/assertion/impl/async-iterable.d.ts +0 -406
- package/dist/assertion/impl/async-iterable.d.ts.map +0 -1
- package/dist/assertion/impl/async-iterable.js +0 -624
- package/dist/assertion/impl/async-iterable.js.map +0 -1
- package/dist/assertion/impl/async-parametric.cjs +0 -412
- package/dist/assertion/impl/async-parametric.cjs.map +0 -1
- package/dist/assertion/impl/async-parametric.d.cts +0 -278
- package/dist/assertion/impl/async-parametric.d.cts.map +0 -1
- package/dist/assertion/impl/async-parametric.d.ts +0 -278
- package/dist/assertion/impl/async-parametric.d.ts.map +0 -1
- package/dist/assertion/impl/async-parametric.js +0 -409
- package/dist/assertion/impl/async-parametric.js.map +0 -1
- package/dist/assertion/impl/async.cjs +0 -56
- package/dist/assertion/impl/async.cjs.map +0 -1
- package/dist/assertion/impl/async.d.cts +0 -179
- package/dist/assertion/impl/async.d.cts.map +0 -1
- package/dist/assertion/impl/async.d.ts +0 -179
- package/dist/assertion/impl/async.d.ts.map +0 -1
- package/dist/assertion/impl/async.js +0 -39
- package/dist/assertion/impl/async.js.map +0 -1
- package/dist/assertion/impl/index.cjs +0 -37
- package/dist/assertion/impl/index.cjs.map +0 -1
- package/dist/assertion/impl/index.d.cts +0 -21
- package/dist/assertion/impl/index.d.cts.map +0 -1
- package/dist/assertion/impl/index.d.ts +0 -21
- package/dist/assertion/impl/index.d.ts.map +0 -1
- package/dist/assertion/impl/index.js +0 -21
- package/dist/assertion/impl/index.js.map +0 -1
- package/dist/assertion/impl/iteration-util.cjs +0 -297
- package/dist/assertion/impl/iteration-util.cjs.map +0 -1
- package/dist/assertion/impl/iteration-util.d.cts +0 -12
- package/dist/assertion/impl/iteration-util.d.cts.map +0 -1
- package/dist/assertion/impl/iteration-util.d.ts +0 -12
- package/dist/assertion/impl/iteration-util.d.ts.map +0 -1
- package/dist/assertion/impl/iteration-util.js +0 -282
- package/dist/assertion/impl/iteration-util.js.map +0 -1
- package/dist/assertion/impl/snapshot.cjs +0 -276
- package/dist/assertion/impl/snapshot.cjs.map +0 -1
- package/dist/assertion/impl/snapshot.d.cts +0 -278
- package/dist/assertion/impl/snapshot.d.cts.map +0 -1
- package/dist/assertion/impl/snapshot.d.ts +0 -278
- package/dist/assertion/impl/snapshot.d.ts.map +0 -1
- package/dist/assertion/impl/snapshot.js +0 -273
- package/dist/assertion/impl/snapshot.js.map +0 -1
- package/dist/assertion/impl/sync-basic.cjs +0 -553
- package/dist/assertion/impl/sync-basic.cjs.map +0 -1
- package/dist/assertion/impl/sync-basic.d.cts +0 -528
- package/dist/assertion/impl/sync-basic.d.cts.map +0 -1
- package/dist/assertion/impl/sync-basic.d.ts +0 -528
- package/dist/assertion/impl/sync-basic.d.ts.map +0 -1
- package/dist/assertion/impl/sync-basic.js +0 -550
- package/dist/assertion/impl/sync-basic.js.map +0 -1
- package/dist/assertion/impl/sync-collection.cjs +0 -856
- package/dist/assertion/impl/sync-collection.cjs.map +0 -1
- package/dist/assertion/impl/sync-collection.d.cts +0 -607
- package/dist/assertion/impl/sync-collection.d.cts.map +0 -1
- package/dist/assertion/impl/sync-collection.d.ts +0 -607
- package/dist/assertion/impl/sync-collection.d.ts.map +0 -1
- package/dist/assertion/impl/sync-collection.js +0 -850
- package/dist/assertion/impl/sync-collection.js.map +0 -1
- package/dist/assertion/impl/sync-date.cjs +0 -341
- package/dist/assertion/impl/sync-date.cjs.map +0 -1
- package/dist/assertion/impl/sync-date.d.cts +0 -209
- package/dist/assertion/impl/sync-date.d.cts.map +0 -1
- package/dist/assertion/impl/sync-date.d.ts +0 -209
- package/dist/assertion/impl/sync-date.d.ts.map +0 -1
- package/dist/assertion/impl/sync-date.js +0 -338
- package/dist/assertion/impl/sync-date.js.map +0 -1
- package/dist/assertion/impl/sync-esoteric.cjs +0 -214
- package/dist/assertion/impl/sync-esoteric.cjs.map +0 -1
- package/dist/assertion/impl/sync-esoteric.d.cts +0 -191
- package/dist/assertion/impl/sync-esoteric.d.cts.map +0 -1
- package/dist/assertion/impl/sync-esoteric.d.ts +0 -191
- package/dist/assertion/impl/sync-esoteric.d.ts.map +0 -1
- package/dist/assertion/impl/sync-esoteric.js +0 -211
- package/dist/assertion/impl/sync-esoteric.js.map +0 -1
- package/dist/assertion/impl/sync-iterable.cjs +0 -512
- package/dist/assertion/impl/sync-iterable.cjs.map +0 -1
- package/dist/assertion/impl/sync-iterable.d.cts +0 -334
- package/dist/assertion/impl/sync-iterable.d.cts.map +0 -1
- package/dist/assertion/impl/sync-iterable.d.ts +0 -334
- package/dist/assertion/impl/sync-iterable.d.ts.map +0 -1
- package/dist/assertion/impl/sync-iterable.js +0 -509
- package/dist/assertion/impl/sync-iterable.js.map +0 -1
- package/dist/assertion/impl/sync-parametric.cjs +0 -805
- package/dist/assertion/impl/sync-parametric.cjs.map +0 -1
- package/dist/assertion/impl/sync-parametric.d.cts +0 -560
- package/dist/assertion/impl/sync-parametric.d.cts.map +0 -1
- package/dist/assertion/impl/sync-parametric.d.ts +0 -560
- package/dist/assertion/impl/sync-parametric.d.ts.map +0 -1
- package/dist/assertion/impl/sync-parametric.js +0 -802
- package/dist/assertion/impl/sync-parametric.js.map +0 -1
- package/dist/assertion/impl/sync.cjs +0 -214
- package/dist/assertion/impl/sync.cjs.map +0 -1
- package/dist/assertion/impl/sync.d.cts +0 -512
- package/dist/assertion/impl/sync.d.cts.map +0 -1
- package/dist/assertion/impl/sync.d.ts +0 -512
- package/dist/assertion/impl/sync.d.ts.map +0 -1
- package/dist/assertion/impl/sync.js +0 -197
- package/dist/assertion/impl/sync.js.map +0 -1
- package/dist/assertion/index.cjs +0 -38
- package/dist/assertion/index.cjs.map +0 -1
- package/dist/assertion/index.d.cts +0 -18
- package/dist/assertion/index.d.cts.map +0 -1
- package/dist/assertion/index.d.ts +0 -18
- package/dist/assertion/index.d.ts.map +0 -1
- package/dist/assertion/index.js +0 -17
- package/dist/assertion/index.js.map +0 -1
- package/dist/assertion/slotify.cjs +0 -165
- package/dist/assertion/slotify.cjs.map +0 -1
- package/dist/assertion/slotify.d.cts +0 -11
- package/dist/assertion/slotify.d.cts.map +0 -1
- package/dist/assertion/slotify.d.ts +0 -11
- package/dist/assertion/slotify.d.ts.map +0 -1
- package/dist/assertion/slotify.js +0 -161
- package/dist/assertion/slotify.js.map +0 -1
- package/dist/bootstrap.cjs +0 -43
- package/dist/bootstrap.cjs.map +0 -1
- package/dist/bootstrap.d.cts +0 -27
- package/dist/bootstrap.d.cts.map +0 -1
- package/dist/bootstrap.d.ts +0 -27
- package/dist/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap.js +0 -40
- package/dist/bootstrap.js.map +0 -1
- package/dist/constant.cjs +0 -82
- package/dist/constant.cjs.map +0 -1
- package/dist/constant.d.cts +0 -69
- package/dist/constant.d.cts.map +0 -1
- package/dist/constant.d.ts +0 -69
- package/dist/constant.d.ts.map +0 -1
- package/dist/constant.js +0 -79
- package/dist/constant.js.map +0 -1
- package/dist/diff.cjs +0 -340
- package/dist/diff.cjs.map +0 -1
- package/dist/diff.d.cts +0 -51
- package/dist/diff.d.cts.map +0 -1
- package/dist/diff.d.ts +0 -51
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js +0 -334
- package/dist/diff.js.map +0 -1
- package/dist/error.cjs +0 -204
- package/dist/error.cjs.map +0 -1
- package/dist/error.d.cts +0 -212
- package/dist/error.d.cts.map +0 -1
- package/dist/error.d.ts +0 -212
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -191
- package/dist/error.js.map +0 -1
- package/dist/expect.cjs +0 -590
- package/dist/expect.cjs.map +0 -1
- package/dist/expect.d.cts +0 -138
- package/dist/expect.d.cts.map +0 -1
- package/dist/expect.d.ts +0 -138
- package/dist/expect.d.ts.map +0 -1
- package/dist/expect.js +0 -582
- package/dist/expect.js.map +0 -1
- package/dist/guards.cjs +0 -297
- package/dist/guards.cjs.map +0 -1
- package/dist/guards.d.cts +0 -231
- package/dist/guards.d.cts.map +0 -1
- package/dist/guards.d.ts +0 -231
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -277
- package/dist/guards.js.map +0 -1
- package/dist/index.cjs +0 -111
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -448
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts +0 -448
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -71
- package/dist/index.js.map +0 -1
- package/dist/internal-schema.cjs +0 -253
- package/dist/internal-schema.cjs.map +0 -1
- package/dist/internal-schema.d.cts +0 -8
- package/dist/internal-schema.d.cts.map +0 -1
- package/dist/internal-schema.d.ts +0 -8
- package/dist/internal-schema.d.ts.map +0 -1
- package/dist/internal-schema.js +0 -248
- package/dist/internal-schema.js.map +0 -1
- package/dist/metadata.cjs +0 -57
- package/dist/metadata.cjs.map +0 -1
- package/dist/metadata.d.cts +0 -27
- package/dist/metadata.d.cts.map +0 -1
- package/dist/metadata.d.ts +0 -27
- package/dist/metadata.d.ts.map +0 -1
- package/dist/metadata.js +0 -54
- package/dist/metadata.js.map +0 -1
- package/dist/schema.cjs +0 -1522
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.cts +0 -1196
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.ts +0 -1196
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -1516
- package/dist/schema.js.map +0 -1
- package/dist/snapshot/adapter.cjs +0 -31
- package/dist/snapshot/adapter.cjs.map +0 -1
- package/dist/snapshot/adapter.d.cts +0 -258
- package/dist/snapshot/adapter.d.cts.map +0 -1
- package/dist/snapshot/adapter.d.ts +0 -258
- package/dist/snapshot/adapter.d.ts.map +0 -1
- package/dist/snapshot/adapter.js +0 -27
- package/dist/snapshot/adapter.js.map +0 -1
- package/dist/snapshot/adapters/fallback.cjs +0 -453
- package/dist/snapshot/adapters/fallback.cjs.map +0 -1
- package/dist/snapshot/adapters/fallback.d.cts +0 -185
- package/dist/snapshot/adapters/fallback.d.cts.map +0 -1
- package/dist/snapshot/adapters/fallback.d.ts +0 -185
- package/dist/snapshot/adapters/fallback.d.ts.map +0 -1
- package/dist/snapshot/adapters/fallback.js +0 -446
- package/dist/snapshot/adapters/fallback.js.map +0 -1
- package/dist/snapshot/adapters/node-test.cjs +0 -301
- package/dist/snapshot/adapters/node-test.cjs.map +0 -1
- package/dist/snapshot/adapters/node-test.d.cts +0 -131
- package/dist/snapshot/adapters/node-test.d.cts.map +0 -1
- package/dist/snapshot/adapters/node-test.d.ts +0 -131
- package/dist/snapshot/adapters/node-test.d.ts.map +0 -1
- package/dist/snapshot/adapters/node-test.js +0 -297
- package/dist/snapshot/adapters/node-test.js.map +0 -1
- package/dist/snapshot/index.cjs +0 -61
- package/dist/snapshot/index.cjs.map +0 -1
- package/dist/snapshot/index.d.cts +0 -40
- package/dist/snapshot/index.d.cts.map +0 -1
- package/dist/snapshot/index.d.ts +0 -40
- package/dist/snapshot/index.d.ts.map +0 -1
- package/dist/snapshot/index.js +0 -44
- package/dist/snapshot/index.js.map +0 -1
- package/dist/snapshot/node-version.cjs +0 -49
- package/dist/snapshot/node-version.cjs.map +0 -1
- package/dist/snapshot/node-version.d.cts +0 -34
- package/dist/snapshot/node-version.d.cts.map +0 -1
- package/dist/snapshot/node-version.d.ts +0 -34
- package/dist/snapshot/node-version.d.ts.map +0 -1
- package/dist/snapshot/node-version.js +0 -44
- package/dist/snapshot/node-version.js.map +0 -1
- package/dist/snapshot/select-adapter.cjs +0 -170
- package/dist/snapshot/select-adapter.cjs.map +0 -1
- package/dist/snapshot/select-adapter.d.cts +0 -128
- package/dist/snapshot/select-adapter.d.cts.map +0 -1
- package/dist/snapshot/select-adapter.d.ts +0 -128
- package/dist/snapshot/select-adapter.d.ts.map +0 -1
- package/dist/snapshot/select-adapter.js +0 -164
- package/dist/snapshot/select-adapter.js.map +0 -1
- package/dist/snapshot/serializer.cjs +0 -246
- package/dist/snapshot/serializer.cjs.map +0 -1
- package/dist/snapshot/serializer.d.cts +0 -126
- package/dist/snapshot/serializer.d.cts.map +0 -1
- package/dist/snapshot/serializer.d.ts +0 -126
- package/dist/snapshot/serializer.d.ts.map +0 -1
- package/dist/snapshot/serializer.js +0 -238
- package/dist/snapshot/serializer.js.map +0 -1
- package/dist/standard-schema.cjs +0 -13
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.d.cts +0 -192
- package/dist/standard-schema.d.cts.map +0 -1
- package/dist/standard-schema.d.ts +0 -192
- package/dist/standard-schema.d.ts.map +0 -1
- package/dist/standard-schema.js +0 -12
- package/dist/standard-schema.js.map +0 -1
- package/dist/types.cjs +0 -22
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -905
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -905
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -21
- package/dist/types.js.map +0 -1
- package/dist/use.cjs +0 -240
- package/dist/use.cjs.map +0 -1
- package/dist/use.d.cts +0 -8
- package/dist/use.d.cts.map +0 -1
- package/dist/use.d.ts +0 -8
- package/dist/use.d.ts.map +0 -1
- package/dist/use.js +0 -236
- package/dist/use.js.map +0 -1
- package/dist/util.cjs +0 -255
- package/dist/util.cjs.map +0 -1
- package/dist/util.d.cts +0 -141
- package/dist/util.d.cts.map +0 -1
- package/dist/util.d.ts +0 -141
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -234
- package/dist/util.js.map +0 -1
- package/dist/value-to-schema.cjs +0 -537
- package/dist/value-to-schema.cjs.map +0 -1
- package/dist/value-to-schema.d.cts +0 -144
- package/dist/value-to-schema.d.cts.map +0 -1
- package/dist/value-to-schema.d.ts +0 -144
- package/dist/value-to-schema.d.ts.map +0 -1
- package/dist/value-to-schema.js +0 -533
- package/dist/value-to-schema.js.map +0 -1
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { inspect } from 'util';
|
|
2
|
-
import z from 'zod';
|
|
3
|
-
import { AssertionError, AssertionImplementationError } from "../error.js";
|
|
4
|
-
import { isA, isBoolean, isError, isStandardSchema, isZodType, } from "../guards.js";
|
|
5
|
-
import { isAssertionFailure, isAssertionParseRequest, } from "../internal-schema.js";
|
|
6
|
-
import { BupkisAssertion } from "./assertion.js";
|
|
7
|
-
import { formatAssertionFailure } from "./format-assertion-failure.js";
|
|
8
|
-
export class BupkisAssertionAsync extends BupkisAssertion {
|
|
9
|
-
async parseValuesAsync(args) {
|
|
10
|
-
const { slots } = this;
|
|
11
|
-
const parsedValues = [];
|
|
12
|
-
if (slots.length !== args.length) {
|
|
13
|
-
return {
|
|
14
|
-
success: false,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
let exactMatch = true;
|
|
18
|
-
for (let i = 0; i < slots.length; i++) {
|
|
19
|
-
const slot = slots[i];
|
|
20
|
-
const arg = args[i];
|
|
21
|
-
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
22
|
-
if (parsedLiteralResult === true) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
else if (parsedLiteralResult !== false) {
|
|
26
|
-
return parsedLiteralResult;
|
|
27
|
-
}
|
|
28
|
-
// unknown/any accept anything
|
|
29
|
-
// IMPORTANT: do not use a type guard here; it will break inference
|
|
30
|
-
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
31
|
-
parsedValues.push(arg);
|
|
32
|
-
exactMatch = false;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
const result = await slot.safeParseAsync(arg);
|
|
36
|
-
if (!result.success) {
|
|
37
|
-
return {
|
|
38
|
-
success: false,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
parsedValues.push(result.data);
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
exactMatch,
|
|
45
|
-
parsedValues: parsedValues,
|
|
46
|
-
success: true,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* An assertion implemented as a Zod schema.
|
|
52
|
-
*
|
|
53
|
-
* Async schemas are supported via {@link expectAsync}.
|
|
54
|
-
*/
|
|
55
|
-
/**
|
|
56
|
-
* Optimized schema assertion that performs subject validation during
|
|
57
|
-
* parseValues() to eliminate double parsing for simple schema-based
|
|
58
|
-
* assertions.
|
|
59
|
-
*
|
|
60
|
-
* This class implements Option 2 from the z.function() analysis - it caches the
|
|
61
|
-
* subject validation result during argument parsing and reuses it during
|
|
62
|
-
* execution, eliminating the double parsing overhead.
|
|
63
|
-
*/
|
|
64
|
-
export class BupkisAssertionFunctionAsync extends BupkisAssertionAsync {
|
|
65
|
-
async executeAsync(parsedValues, args, stackStartFn, _parseResult) {
|
|
66
|
-
let result;
|
|
67
|
-
try {
|
|
68
|
-
result = await this.impl.call(null,
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
70
|
-
...parsedValues);
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
if (AssertionError.isAssertionError(err)) {
|
|
74
|
-
throw err;
|
|
75
|
-
}
|
|
76
|
-
if (isError(err) && err instanceof z.ZodError) {
|
|
77
|
-
throw this.fromZodError(err, stackStartFn, parsedValues);
|
|
78
|
-
}
|
|
79
|
-
throw new AssertionImplementationError(`Unexpected error thrown from assertion ${this}: ${err}`, { cause: err });
|
|
80
|
-
}
|
|
81
|
-
if (isZodType(result)) {
|
|
82
|
-
try {
|
|
83
|
-
await result.parseAsync(parsedValues[0]);
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
if (isA(error, z.ZodError)) {
|
|
87
|
-
throw this.fromZodError(error, stackStartFn, parsedValues);
|
|
88
|
-
}
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if (isStandardSchema(result)) {
|
|
93
|
-
const validationResult = result['~standard'].validate(parsedValues[0]);
|
|
94
|
-
const finalResult = validationResult instanceof Promise
|
|
95
|
-
? await validationResult
|
|
96
|
-
: validationResult;
|
|
97
|
-
if (finalResult.issues) {
|
|
98
|
-
throw this.fromStandardSchemaIssues(finalResult.issues, stackStartFn, parsedValues);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (isBoolean(result)) {
|
|
102
|
-
if (!result) {
|
|
103
|
-
throw new AssertionError({
|
|
104
|
-
id: this.id,
|
|
105
|
-
message: `Assertion ${this} failed for arguments: ${inspect(args)}`,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (isError(result) && result instanceof z.ZodError) {
|
|
110
|
-
throw this.fromZodError(result, stackStartFn, parsedValues);
|
|
111
|
-
}
|
|
112
|
-
else if (isAssertionParseRequest(result)) {
|
|
113
|
-
const { asyncSchema, schema, subject } = result;
|
|
114
|
-
const schemaToUse = schema ?? asyncSchema;
|
|
115
|
-
if (isZodType(schemaToUse)) {
|
|
116
|
-
let zodResult;
|
|
117
|
-
if (schema) {
|
|
118
|
-
zodResult = schemaToUse.safeParse(subject);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
zodResult = await schemaToUse.safeParseAsync(subject);
|
|
122
|
-
}
|
|
123
|
-
if (!zodResult.success) {
|
|
124
|
-
throw this.fromZodError(zodResult.error, stackStartFn, subject);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else if (isStandardSchema(schemaToUse)) {
|
|
128
|
-
const validationResult = schemaToUse['~standard'].validate(subject);
|
|
129
|
-
const finalResult = validationResult instanceof Promise
|
|
130
|
-
? await validationResult
|
|
131
|
-
: validationResult;
|
|
132
|
-
if (finalResult.issues) {
|
|
133
|
-
throw this.fromStandardSchemaIssues(finalResult.issues, stackStartFn, subject);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else if (isAssertionFailure(result)) {
|
|
138
|
-
const diffOutput = formatAssertionFailure(result);
|
|
139
|
-
const baseMessage = result.message ??
|
|
140
|
-
`Assertion ${this} failed for arguments: ${inspect(args)}`;
|
|
141
|
-
const message = diffOutput
|
|
142
|
-
? `${baseMessage}\n${diffOutput}`
|
|
143
|
-
: baseMessage;
|
|
144
|
-
throw new AssertionError({
|
|
145
|
-
actual: result.actual,
|
|
146
|
-
expected: result.expected,
|
|
147
|
-
id: this.id,
|
|
148
|
-
message,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
else if (result) {
|
|
152
|
-
throw new AssertionImplementationError(`Invalid return type from assertion ${this}; expected boolean, ZodType, or AssertionFailure`, { result });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* A class representing an assertion implemented as a function.
|
|
158
|
-
*
|
|
159
|
-
* This function may:
|
|
160
|
-
*
|
|
161
|
-
* 1. Return a `boolean` indicating pass/fail.
|
|
162
|
-
* 2. Return a `ZodType` which will be used to validate the subject.
|
|
163
|
-
* 3. Return a `Promise` resolving to either of the above (when called via
|
|
164
|
-
* {@link expectAsync})
|
|
165
|
-
* 4. Throw a {@link AssertionError}; when called via {@link expectAsync}, reject
|
|
166
|
-
* with an {@link AssertionError}
|
|
167
|
-
*/
|
|
168
|
-
export class BupkisAssertionSchemaAsync extends BupkisAssertionAsync {
|
|
169
|
-
async executeAsync(parsedValues, _args, stackStartFn, parseResult) {
|
|
170
|
-
// Check if we have cached validation result from parseValuesAsync
|
|
171
|
-
const cachedValidation = parseResult?.success
|
|
172
|
-
? parseResult.subjectValidationResult
|
|
173
|
-
: undefined;
|
|
174
|
-
if (cachedValidation && !cachedValidation.success) {
|
|
175
|
-
// Subject validation failed during parseValuesAsync, throw the cached error
|
|
176
|
-
if ('error' in cachedValidation) {
|
|
177
|
-
throw this.fromZodError(cachedValidation.error, stackStartFn, parsedValues);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// Fall back to standard validation if no cached result
|
|
181
|
-
const [subject] = parsedValues;
|
|
182
|
-
try {
|
|
183
|
-
await this.impl.parseAsync(subject);
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
if (isA(error, z.ZodError)) {
|
|
187
|
-
throw this.fromZodError(error, stackStartFn, parsedValues);
|
|
188
|
-
}
|
|
189
|
-
/* c8 ignore next */
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async parseValuesAsync(args) {
|
|
194
|
-
const { slots } = this;
|
|
195
|
-
const parsedValues = [];
|
|
196
|
-
const mismatch = this.maybeParseValuesArgMismatch(args);
|
|
197
|
-
if (mismatch) {
|
|
198
|
-
return mismatch;
|
|
199
|
-
}
|
|
200
|
-
let exactMatch = true;
|
|
201
|
-
let subjectValidationResult;
|
|
202
|
-
for (let i = 0; i < slots.length; i++) {
|
|
203
|
-
const slot = slots[i];
|
|
204
|
-
const arg = args[i];
|
|
205
|
-
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
206
|
-
if (parsedLiteralResult === true) {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
else if (parsedLiteralResult !== false) {
|
|
210
|
-
return parsedLiteralResult;
|
|
211
|
-
}
|
|
212
|
-
// For the subject slot (first slot if it's unknown/any), try optimized validation
|
|
213
|
-
if (i === 0 &&
|
|
214
|
-
(slot.def.type === 'unknown' || slot.def.type === 'any') &&
|
|
215
|
-
this.isSimpleSchemaAssertion()) {
|
|
216
|
-
try {
|
|
217
|
-
const result = await this.impl.parseAsync(arg);
|
|
218
|
-
subjectValidationResult = { data: result, success: true };
|
|
219
|
-
parsedValues.push(result); // Use validated data
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
if (isA(error, z.ZodError)) {
|
|
223
|
-
subjectValidationResult = { error, success: false };
|
|
224
|
-
parsedValues.push(arg); // Keep original for error reporting
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
throw error; // Re-throw non-Zod errors
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
exactMatch = false; // Subject was validated, so we know the exact type
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
// Standard slot processing for non-optimized cases
|
|
234
|
-
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
235
|
-
parsedValues.push(arg);
|
|
236
|
-
exactMatch = false;
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
const result = await slot.safeParseAsync(arg);
|
|
240
|
-
if (!result.success) {
|
|
241
|
-
return {
|
|
242
|
-
success: false,
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
parsedValues.push(result.data);
|
|
246
|
-
}
|
|
247
|
-
const result = {
|
|
248
|
-
exactMatch,
|
|
249
|
-
parsedValues: parsedValues,
|
|
250
|
-
success: true,
|
|
251
|
-
};
|
|
252
|
-
// Add cached validation result if we performed optimization
|
|
253
|
-
if (subjectValidationResult) {
|
|
254
|
-
result.subjectValidationResult = subjectValidationResult;
|
|
255
|
-
}
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
//# sourceMappingURL=assertion-async.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertion-async.js","sourceRoot":"","sources":["../../src/assertion/assertion-async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,4BAA4B,EAAE,oBAAoB;AAC3E,OAAO,EACL,GAAG,EACH,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,SAAS,GACV,qBAAqB;AACtB,O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ion implementation.
|
|
4
|
-
*
|
|
5
|
-
* This module provides the `BupkisAssertionStandardSchemaAsync` class for
|
|
6
|
-
* assertions implemented using Standard Schema v1 compliant validators that may
|
|
7
|
-
* perform asynchronous validation.
|
|
8
|
-
*
|
|
9
|
-
* @packageDocumentation
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.BupkisAssertionStandardSchemaAsync = void 0;
|
|
13
|
-
const assertion_js_1 = require("./assertion.cjs");
|
|
14
|
-
/**
|
|
15
|
-
* An asynchronous assertion implemented using a Standard Schema v1 validator.
|
|
16
|
-
*
|
|
17
|
-
* This class handles async schema-based assertions where the implementation is
|
|
18
|
-
* any Standard Schema compliant validator that may perform asynchronous
|
|
19
|
-
* validation. It optimizes validation by caching the subject validation result
|
|
20
|
-
* during `parseValuesAsync()` to avoid double parsing.
|
|
21
|
-
*
|
|
22
|
-
* @template Parts - The assertion parts tuple defining structure
|
|
23
|
-
* @template Impl - The Standard Schema implementation
|
|
24
|
-
* @template Slots - The derived validation slots
|
|
25
|
-
*/
|
|
26
|
-
class BupkisAssertionStandardSchemaAsync extends assertion_js_1.BupkisAssertion {
|
|
27
|
-
/**
|
|
28
|
-
* Executes the assertion asynchronously against validated values.
|
|
29
|
-
*
|
|
30
|
-
* If validation was already performed during `parseValuesAsync()` and cached,
|
|
31
|
-
* reuses that result. Otherwise, performs validation using the Standard
|
|
32
|
-
* Schema's validate() method (which may return a Promise).
|
|
33
|
-
*
|
|
34
|
-
* @param parsedValues - The parsed and validated values
|
|
35
|
-
* @param _args - Original raw arguments (unused)
|
|
36
|
-
* @param stackStartFn - Function to use as stack trace start point
|
|
37
|
-
* @param parseResult - Optional cached parse result from `parseValuesAsync()`
|
|
38
|
-
* @throws {AssertionError} If validation fails
|
|
39
|
-
*/
|
|
40
|
-
async executeAsync(parsedValues, _args, stackStartFn, parseResult) {
|
|
41
|
-
const cachedValidation = parseResult?.success
|
|
42
|
-
? parseResult.subjectValidationResult
|
|
43
|
-
: undefined;
|
|
44
|
-
if (cachedValidation && !cachedValidation.success) {
|
|
45
|
-
if ('issues' in cachedValidation) {
|
|
46
|
-
throw this.fromStandardSchemaIssues(cachedValidation.issues, stackStartFn, parsedValues);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const [subject] = parsedValues;
|
|
50
|
-
const result = this.impl['~standard'].validate(subject);
|
|
51
|
-
const validationResult = result instanceof Promise ? await result : result;
|
|
52
|
-
if (validationResult.issues) {
|
|
53
|
-
throw this.fromStandardSchemaIssues(validationResult.issues, stackStartFn, parsedValues);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Parses raw arguments asynchronously against slots with optimized caching.
|
|
58
|
-
*
|
|
59
|
-
* For simple schema assertions (subject + phrase literals only), this method
|
|
60
|
-
* validates the subject during parsing and caches the result to avoid double
|
|
61
|
-
* validation in `executeAsync()`.
|
|
62
|
-
*
|
|
63
|
-
* @param args - Raw arguments provided to `expectAsync()`
|
|
64
|
-
* @returns Promise resolving to parse result with cached validation
|
|
65
|
-
*/
|
|
66
|
-
async parseValuesAsync(args) {
|
|
67
|
-
const { slots } = this;
|
|
68
|
-
const parsedValues = [];
|
|
69
|
-
const mismatch = this.maybeParseValuesArgMismatch(args);
|
|
70
|
-
if (mismatch) {
|
|
71
|
-
return mismatch;
|
|
72
|
-
}
|
|
73
|
-
let exactMatch = true;
|
|
74
|
-
let subjectValidationResult;
|
|
75
|
-
for (let i = 0; i < slots.length; i++) {
|
|
76
|
-
const slot = slots[i];
|
|
77
|
-
const arg = args[i];
|
|
78
|
-
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
79
|
-
if (parsedLiteralResult === true) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
else if (parsedLiteralResult !== false) {
|
|
83
|
-
return parsedLiteralResult;
|
|
84
|
-
}
|
|
85
|
-
if (i === 0 &&
|
|
86
|
-
(slot.def.type === 'unknown' || slot.def.type === 'any') &&
|
|
87
|
-
this.isSimpleSchemaAssertion()) {
|
|
88
|
-
const result = this.impl['~standard'].validate(arg);
|
|
89
|
-
const validationResult = result instanceof Promise ? await result : result;
|
|
90
|
-
if (validationResult.issues) {
|
|
91
|
-
subjectValidationResult = {
|
|
92
|
-
issues: validationResult.issues,
|
|
93
|
-
success: false,
|
|
94
|
-
};
|
|
95
|
-
parsedValues.push(arg);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
subjectValidationResult = {
|
|
99
|
-
data: validationResult.value,
|
|
100
|
-
success: true,
|
|
101
|
-
};
|
|
102
|
-
parsedValues.push(validationResult.value);
|
|
103
|
-
}
|
|
104
|
-
exactMatch = false;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
108
|
-
parsedValues.push(arg);
|
|
109
|
-
exactMatch = false;
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const result = await slot.safeParseAsync(arg);
|
|
113
|
-
if (!result.success) {
|
|
114
|
-
return {
|
|
115
|
-
success: false,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
parsedValues.push(result.data);
|
|
119
|
-
}
|
|
120
|
-
const result = {
|
|
121
|
-
exactMatch,
|
|
122
|
-
parsedValues: parsedValues,
|
|
123
|
-
success: true,
|
|
124
|
-
};
|
|
125
|
-
if (subjectValidationResult) {
|
|
126
|
-
result.subjectValidationResult = subjectValidationResult;
|
|
127
|
-
}
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.BupkisAssertionStandardSchemaAsync = BupkisAssertionStandardSchemaAsync;
|
|
132
|
-
//# sourceMappingURL=assertion-standard-schema-async.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertion-standard-schema-async.js","sourceRoot":"","sources":["../../src/assertion/assertion-standard-schema-async.ts"],"names":[],"mappings":";AAAA;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F,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;gBAC5C,CAAC;gBACD,UAAU,GAAG,KAAK,CAAC;gBACnB,SAAS;YACX,CAAC;YAED,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBAC3D,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACvB,UAAU,GAAG,KAAK,CAAC;gBACnB,SAAS;YACX,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO;oBACL,OAAO,EAAE,KAAK;iBACf,CAAC;YACJ,CAAC;YACD,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,MAAM,GAA+B;YACzC,UAAU;YACV,YAAY,EAAE,YAA8C;YAC5D,OAAO,EAAE,IAAI;SACd,CAAC;QAEF,IAAI,uBAAuB,EAAE,CAAC;YAC5B,MAAM,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QAC3D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5ID,gFA4IC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asynchronous Standard Schema assertion implementation.
|
|
3
|
-
*
|
|
4
|
-
* This module provides the `BupkisAssertionStandardSchemaAsync` class for
|
|
5
|
-
* assertions implemented using Standard Schema v1 compliant validators that may
|
|
6
|
-
* perform asynchronous validation.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import type { StandardSchemaV1 } from "../standard-schema.cjs";
|
|
11
|
-
import type { AssertionParts, AssertionSlots, AssertionStandardSchemaAsync, ParsedResult, ParsedValues } from "./assertion-types.cjs";
|
|
12
|
-
import { BupkisAssertion } from "./assertion.cjs";
|
|
13
|
-
/**
|
|
14
|
-
* An asynchronous assertion implemented using a Standard Schema v1 validator.
|
|
15
|
-
*
|
|
16
|
-
* This class handles async schema-based assertions where the implementation is
|
|
17
|
-
* any Standard Schema compliant validator that may perform asynchronous
|
|
18
|
-
* validation. It optimizes validation by caching the subject validation result
|
|
19
|
-
* during `parseValuesAsync()` to avoid double parsing.
|
|
20
|
-
*
|
|
21
|
-
* @template Parts - The assertion parts tuple defining structure
|
|
22
|
-
* @template Impl - The Standard Schema implementation
|
|
23
|
-
* @template Slots - The derived validation slots
|
|
24
|
-
*/
|
|
25
|
-
export declare class BupkisAssertionStandardSchemaAsync<Parts extends AssertionParts, Impl extends StandardSchemaV1, Slots extends AssertionSlots<Parts>> extends BupkisAssertion<Parts, Impl, Slots> implements AssertionStandardSchemaAsync<Parts, Impl, Slots> {
|
|
26
|
-
/**
|
|
27
|
-
* Executes the assertion asynchronously against validated values.
|
|
28
|
-
*
|
|
29
|
-
* If validation was already performed during `parseValuesAsync()` and cached,
|
|
30
|
-
* reuses that result. Otherwise, performs validation using the Standard
|
|
31
|
-
* Schema's validate() method (which may return a Promise).
|
|
32
|
-
*
|
|
33
|
-
* @param parsedValues - The parsed and validated values
|
|
34
|
-
* @param _args - Original raw arguments (unused)
|
|
35
|
-
* @param stackStartFn - Function to use as stack trace start point
|
|
36
|
-
* @param parseResult - Optional cached parse result from `parseValuesAsync()`
|
|
37
|
-
* @throws {AssertionError} If validation fails
|
|
38
|
-
*/
|
|
39
|
-
executeAsync(parsedValues: ParsedValues<Parts>, _args: unknown[], stackStartFn: (...args: any[]) => any, parseResult?: ParsedResult<Parts>): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Parses raw arguments asynchronously against slots with optimized caching.
|
|
42
|
-
*
|
|
43
|
-
* For simple schema assertions (subject + phrase literals only), this method
|
|
44
|
-
* validates the subject during parsing and caches the result to avoid double
|
|
45
|
-
* validation in `executeAsync()`.
|
|
46
|
-
*
|
|
47
|
-
* @param args - Raw arguments provided to `expectAsync()`
|
|
48
|
-
* @returns Promise resolving to parse result with cached validation
|
|
49
|
-
*/
|
|
50
|
-
parseValuesAsync<Args extends readonly unknown[]>(args: Args): Promise<ParsedResult<Parts>>;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=assertion-standard-schema-async.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertion-standard-schema-async.d.ts","sourceRoot":"","sources":["../../src/assertion/assertion-standard-schema-async.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA8B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,YAAY,EAEZ,YAAY,EACb,8BAA6B;AAE9B,OAAO,EAAE,eAAe,EAAE,wBAAuB;AAEjD;;;;;;;;;;;GAWG;AACH,qBAAa,kCAAkC,CAC7C,KAAK,SAAS,cAAc,EAC5B,IAAI,SAAS,gBAAgB,EAC7B,KAAK,SAAS,cAAc,CAAC,KAAK,CAAC,CAEnC,SAAQ,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAC1C,YAAW,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAE3D;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,KAAK,EAAE,OAAO,EAAE,EAChB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,WAAW,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IA4BhB;;;;;;;;;OASG;IACG,gBAAgB,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EACpD,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CA0EhC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asynchronous Standard Schema assertion implementation.
|
|
3
|
-
*
|
|
4
|
-
* This module provides the `BupkisAssertionStandardSchemaAsync` class for
|
|
5
|
-
* assertions implemented using Standard Schema v1 compliant validators that may
|
|
6
|
-
* perform asynchronous validation.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import type { StandardSchemaV1 } from "../standard-schema.js";
|
|
11
|
-
import type { AssertionParts, AssertionSlots, AssertionStandardSchemaAsync, ParsedResult, ParsedValues } from "./assertion-types.js";
|
|
12
|
-
import { BupkisAssertion } from "./assertion.js";
|
|
13
|
-
/**
|
|
14
|
-
* An asynchronous assertion implemented using a Standard Schema v1 validator.
|
|
15
|
-
*
|
|
16
|
-
* This class handles async schema-based assertions where the implementation is
|
|
17
|
-
* any Standard Schema compliant validator that may perform asynchronous
|
|
18
|
-
* validation. It optimizes validation by caching the subject validation result
|
|
19
|
-
* during `parseValuesAsync()` to avoid double parsing.
|
|
20
|
-
*
|
|
21
|
-
* @template Parts - The assertion parts tuple defining structure
|
|
22
|
-
* @template Impl - The Standard Schema implementation
|
|
23
|
-
* @template Slots - The derived validation slots
|
|
24
|
-
*/
|
|
25
|
-
export declare class BupkisAssertionStandardSchemaAsync<Parts extends AssertionParts, Impl extends StandardSchemaV1, Slots extends AssertionSlots<Parts>> extends BupkisAssertion<Parts, Impl, Slots> implements AssertionStandardSchemaAsync<Parts, Impl, Slots> {
|
|
26
|
-
/**
|
|
27
|
-
* Executes the assertion asynchronously against validated values.
|
|
28
|
-
*
|
|
29
|
-
* If validation was already performed during `parseValuesAsync()` and cached,
|
|
30
|
-
* reuses that result. Otherwise, performs validation using the Standard
|
|
31
|
-
* Schema's validate() method (which may return a Promise).
|
|
32
|
-
*
|
|
33
|
-
* @param parsedValues - The parsed and validated values
|
|
34
|
-
* @param _args - Original raw arguments (unused)
|
|
35
|
-
* @param stackStartFn - Function to use as stack trace start point
|
|
36
|
-
* @param parseResult - Optional cached parse result from `parseValuesAsync()`
|
|
37
|
-
* @throws {AssertionError} If validation fails
|
|
38
|
-
*/
|
|
39
|
-
executeAsync(parsedValues: ParsedValues<Parts>, _args: unknown[], stackStartFn: (...args: any[]) => any, parseResult?: ParsedResult<Parts>): Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Parses raw arguments asynchronously against slots with optimized caching.
|
|
42
|
-
*
|
|
43
|
-
* For simple schema assertions (subject + phrase literals only), this method
|
|
44
|
-
* validates the subject during parsing and caches the result to avoid double
|
|
45
|
-
* validation in `executeAsync()`.
|
|
46
|
-
*
|
|
47
|
-
* @param args - Raw arguments provided to `expectAsync()`
|
|
48
|
-
* @returns Promise resolving to parse result with cached validation
|
|
49
|
-
*/
|
|
50
|
-
parseValuesAsync<Args extends readonly unknown[]>(args: Args): Promise<ParsedResult<Parts>>;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=assertion-standard-schema-async.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertion-standard-schema-async.d.ts","sourceRoot":"","sources":["../../src/assertion/assertion-standard-schema-async.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,8BAA8B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,YAAY,EAEZ,YAAY,EACb,6BAA6B;AAE9B,OAAO,EAAE,eAAe,EAAE,uBAAuB;AAEjD;;;;;;;;;;;GAWG;AACH,qBAAa,kCAAkC,CAC7C,KAAK,SAAS,cAAc,EAC5B,IAAI,SAAS,gBAAgB,EAC7B,KAAK,SAAS,cAAc,CAAC,KAAK,CAAC,CAEnC,SAAQ,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAC1C,YAAW,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;IAE3D;;;;;;;;;;;;OAYG;IACG,YAAY,CAChB,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,EACjC,KAAK,EAAE,OAAO,EAAE,EAChB,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrC,WAAW,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IA4BhB;;;;;;;;;OASG;IACG,gBAAgB,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EACpD,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CA0EhC"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asynchronous Standard Schema assertion implementation.
|
|
3
|
-
*
|
|
4
|
-
* This module provides the `BupkisAssertionStandardSchemaAsync` class for
|
|
5
|
-
* assertions implemented using Standard Schema v1 compliant validators that may
|
|
6
|
-
* perform asynchronous validation.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
import { BupkisAssertion } from "./assertion.js";
|
|
11
|
-
/**
|
|
12
|
-
* An asynchronous assertion implemented using a Standard Schema v1 validator.
|
|
13
|
-
*
|
|
14
|
-
* This class handles async schema-based assertions where the implementation is
|
|
15
|
-
* any Standard Schema compliant validator that may perform asynchronous
|
|
16
|
-
* validation. It optimizes validation by caching the subject validation result
|
|
17
|
-
* during `parseValuesAsync()` to avoid double parsing.
|
|
18
|
-
*
|
|
19
|
-
* @template Parts - The assertion parts tuple defining structure
|
|
20
|
-
* @template Impl - The Standard Schema implementation
|
|
21
|
-
* @template Slots - The derived validation slots
|
|
22
|
-
*/
|
|
23
|
-
export class BupkisAssertionStandardSchemaAsync extends BupkisAssertion {
|
|
24
|
-
/**
|
|
25
|
-
* Executes the assertion asynchronously against validated values.
|
|
26
|
-
*
|
|
27
|
-
* If validation was already performed during `parseValuesAsync()` and cached,
|
|
28
|
-
* reuses that result. Otherwise, performs validation using the Standard
|
|
29
|
-
* Schema's validate() method (which may return a Promise).
|
|
30
|
-
*
|
|
31
|
-
* @param parsedValues - The parsed and validated values
|
|
32
|
-
* @param _args - Original raw arguments (unused)
|
|
33
|
-
* @param stackStartFn - Function to use as stack trace start point
|
|
34
|
-
* @param parseResult - Optional cached parse result from `parseValuesAsync()`
|
|
35
|
-
* @throws {AssertionError} If validation fails
|
|
36
|
-
*/
|
|
37
|
-
async executeAsync(parsedValues, _args, stackStartFn, parseResult) {
|
|
38
|
-
const cachedValidation = parseResult?.success
|
|
39
|
-
? parseResult.subjectValidationResult
|
|
40
|
-
: undefined;
|
|
41
|
-
if (cachedValidation && !cachedValidation.success) {
|
|
42
|
-
if ('issues' in cachedValidation) {
|
|
43
|
-
throw this.fromStandardSchemaIssues(cachedValidation.issues, stackStartFn, parsedValues);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const [subject] = parsedValues;
|
|
47
|
-
const result = this.impl['~standard'].validate(subject);
|
|
48
|
-
const validationResult = result instanceof Promise ? await result : result;
|
|
49
|
-
if (validationResult.issues) {
|
|
50
|
-
throw this.fromStandardSchemaIssues(validationResult.issues, stackStartFn, parsedValues);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Parses raw arguments asynchronously against slots with optimized caching.
|
|
55
|
-
*
|
|
56
|
-
* For simple schema assertions (subject + phrase literals only), this method
|
|
57
|
-
* validates the subject during parsing and caches the result to avoid double
|
|
58
|
-
* validation in `executeAsync()`.
|
|
59
|
-
*
|
|
60
|
-
* @param args - Raw arguments provided to `expectAsync()`
|
|
61
|
-
* @returns Promise resolving to parse result with cached validation
|
|
62
|
-
*/
|
|
63
|
-
async parseValuesAsync(args) {
|
|
64
|
-
const { slots } = this;
|
|
65
|
-
const parsedValues = [];
|
|
66
|
-
const mismatch = this.maybeParseValuesArgMismatch(args);
|
|
67
|
-
if (mismatch) {
|
|
68
|
-
return mismatch;
|
|
69
|
-
}
|
|
70
|
-
let exactMatch = true;
|
|
71
|
-
let subjectValidationResult;
|
|
72
|
-
for (let i = 0; i < slots.length; i++) {
|
|
73
|
-
const slot = slots[i];
|
|
74
|
-
const arg = args[i];
|
|
75
|
-
const parsedLiteralResult = this.parseSlotForLiteral(slot, i, arg);
|
|
76
|
-
if (parsedLiteralResult === true) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
else if (parsedLiteralResult !== false) {
|
|
80
|
-
return parsedLiteralResult;
|
|
81
|
-
}
|
|
82
|
-
if (i === 0 &&
|
|
83
|
-
(slot.def.type === 'unknown' || slot.def.type === 'any') &&
|
|
84
|
-
this.isSimpleSchemaAssertion()) {
|
|
85
|
-
const result = this.impl['~standard'].validate(arg);
|
|
86
|
-
const validationResult = result instanceof Promise ? await result : result;
|
|
87
|
-
if (validationResult.issues) {
|
|
88
|
-
subjectValidationResult = {
|
|
89
|
-
issues: validationResult.issues,
|
|
90
|
-
success: false,
|
|
91
|
-
};
|
|
92
|
-
parsedValues.push(arg);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
subjectValidationResult = {
|
|
96
|
-
data: validationResult.value,
|
|
97
|
-
success: true,
|
|
98
|
-
};
|
|
99
|
-
parsedValues.push(validationResult.value);
|
|
100
|
-
}
|
|
101
|
-
exactMatch = false;
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (slot.def.type === 'unknown' || slot.def.type === 'any') {
|
|
105
|
-
parsedValues.push(arg);
|
|
106
|
-
exactMatch = false;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
const result = await slot.safeParseAsync(arg);
|
|
110
|
-
if (!result.success) {
|
|
111
|
-
return {
|
|
112
|
-
success: false,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
parsedValues.push(result.data);
|
|
116
|
-
}
|
|
117
|
-
const result = {
|
|
118
|
-
exactMatch,
|
|
119
|
-
parsedValues: parsedValues,
|
|
120
|
-
success: true,
|
|
121
|
-
};
|
|
122
|
-
if (subjectValidationResult) {
|
|
123
|
-
result.subjectValidationResult = subjectValidationResult;
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=assertion-standard-schema-async.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertion-standard-schema-async.js","sourceRoot":"","sources":["../../src/assertion/assertion-standard-schema-async.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,OAAO,EAAE,eAAe,EAAE,uBAAuB;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,kCAKX,SAAQ,eAAmC;IAG3C;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,YAAY,CAChB,YAAiC,EACjC,KAAgB,EAChB,YAAqC,EACrC,WAAiC;QAEjC,MAAM,gBAAgB,GAAG,WAAW,EAAE,OAAO;YAC3C,CAAC,CAAC,WAAW,CAAC,uBAAuB;YACrC,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,gBAAgB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAClD,IAAI,QAAQ,IAAI,gBAAgB,EAAE,CAAC;gBACjC,MAAM,IAAI,CAAC,wBAAwB,CACjC,gBAAgB,CAAC,MAAM,EACvB,YAAY,EACZ,YAAY,CACb,CAAC;YACJ,CAAC;QACH,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,gBAAgB,GAAG,MAAM,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QAE3E,IAAI,gBAAgB,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,wBAAwB,CACjC,gBAAgB,C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