@augment-vir/assert 31.0.0 → 31.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assertions/boolean.d.ts +20 -26
- package/dist/assertions/boolean.js +185 -41
- package/dist/assertions/boundary.d.ts +40 -256
- package/dist/assertions/boundary.js +265 -229
- package/dist/assertions/enum.d.ts +12 -13
- package/dist/assertions/enum.js +98 -20
- package/dist/assertions/equality/entry-equality.d.ts +11 -15
- package/dist/assertions/equality/entry-equality.js +210 -43
- package/dist/assertions/equality/json-equality.d.ts +11 -15
- package/dist/assertions/equality/json-equality.js +144 -43
- package/dist/assertions/equality/simple-equality.d.ts +39 -46
- package/dist/assertions/equality/simple-equality.js +316 -61
- package/dist/assertions/extendable-assertions.d.ts +0 -12
- package/dist/assertions/extendable-assertions.js +0 -12
- package/dist/assertions/http.d.ts +10 -14
- package/dist/assertions/http.js +96 -28
- package/dist/assertions/instance.d.ts +10 -18
- package/dist/assertions/instance.js +92 -26
- package/dist/assertions/keys.d.ts +59 -138
- package/dist/assertions/keys.js +279 -162
- package/dist/assertions/length.d.ts +30 -212
- package/dist/assertions/length.js +117 -175
- package/dist/assertions/nullish.d.ts +8 -20
- package/dist/assertions/nullish.js +85 -27
- package/dist/assertions/numeric.d.ts +67 -81
- package/dist/assertions/numeric.js +564 -133
- package/dist/assertions/output.d.ts +2 -3
- package/dist/assertions/output.js +1 -7
- package/dist/assertions/primitive.d.ts +33 -40
- package/dist/assertions/primitive.js +232 -66
- package/dist/assertions/promise.d.ts +20 -30
- package/dist/assertions/promise.js +244 -53
- package/dist/assertions/regexp.d.ts +12 -14
- package/dist/assertions/regexp.js +84 -21
- package/dist/assertions/runtime-type.d.ts +99 -150
- package/dist/assertions/runtime-type.js +805 -229
- package/dist/assertions/throws.d.ts +24 -25
- package/dist/assertions/throws.js +43 -5
- package/dist/assertions/uuid.d.ts +11 -16
- package/dist/assertions/uuid.js +91 -22
- package/dist/assertions/values.d.ts +81 -210
- package/dist/assertions/values.js +627 -234
- package/dist/augments/guards/assert-wrap.d.ts +7 -4
- package/dist/augments/guards/assert-wrap.js +5 -4
- package/dist/augments/guards/check-wrap.d.ts +7 -5
- package/dist/augments/guards/check-wrap.js +5 -4
- package/dist/augments/guards/check.d.ts +5 -5
- package/dist/augments/guards/check.js +5 -4
- package/dist/augments/guards/wait-until.d.ts +8 -4
- package/dist/augments/guards/wait-until.js +7 -8
- package/dist/guard-types/guard-group.d.ts +5 -2
- package/dist/guard-types/wait-until-function.d.ts +2 -10
- package/dist/guard-types/wait-until-function.js +1 -9
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/guard-types/assert-wrap-function.d.ts +0 -12
- package/dist/guard-types/assert-wrap-function.js +0 -14
- package/dist/guard-types/check-function.d.ts +0 -14
- package/dist/guard-types/check-function.js +0 -22
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
- package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
- package/dist/guard-types/guard-override.d.ts +0 -4
- package/dist/guard-types/guard-override.js +0 -10
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ArrayElement } from '@augment-vir/core';
|
|
2
|
+
import { UnionToIntersection } from 'type-fest';
|
|
3
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
4
|
+
declare const assertWrapMethods: UnionToIntersection<Extract<ArrayElement<typeof guardOverrides>, {
|
|
5
|
+
assertWrap: any;
|
|
6
|
+
}>['assertWrap']>;
|
|
4
7
|
/**
|
|
5
8
|
* A group of guard methods that do the following:
|
|
6
9
|
*
|
|
@@ -34,5 +37,5 @@ declare const assertWrapGroup: AssertWrapGroup<typeof extendableAssertions, type
|
|
|
34
37
|
* @throws {@link AssertionError} When the assertion fails.
|
|
35
38
|
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
36
39
|
*/
|
|
37
|
-
export declare const assertWrap: (<T>(input: T, failureMessage?: string | undefined) => T) & typeof
|
|
40
|
+
export declare const assertWrap: (<T>(input: T, failureMessage?: string | undefined) => T) & typeof assertWrapMethods;
|
|
38
41
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createAssertWrapGroup } from '../../guard-types/assert-wrap-function.js';
|
|
1
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
3
2
|
import { AssertionError } from '../assertion.error.js';
|
|
4
|
-
const
|
|
3
|
+
const assertWrapMethods = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
4
|
+
return entry.assertWrap;
|
|
5
|
+
}));
|
|
5
6
|
/**
|
|
6
7
|
* A group of guard methods that do the following:
|
|
7
8
|
*
|
|
@@ -40,4 +41,4 @@ export const assertWrap = Object.assign(function assertWrap(input, failureMessag
|
|
|
40
41
|
throw new AssertionError('Assertion failed.', failureMessage);
|
|
41
42
|
}
|
|
42
43
|
return input;
|
|
43
|
-
},
|
|
44
|
+
}, assertWrapMethods);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
declare const
|
|
1
|
+
import { AnyFunction, ArrayElement } from '@augment-vir/core';
|
|
2
|
+
import { UnionToIntersection } from 'type-fest';
|
|
3
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
4
|
+
declare const checkWrapMethods: UnionToIntersection<Extract<ArrayElement<typeof guardOverrides>, {
|
|
5
|
+
checkWrap: any;
|
|
6
|
+
}>['checkWrap']>;
|
|
5
7
|
/**
|
|
6
8
|
* A group of guard methods that do the following:
|
|
7
9
|
*
|
|
@@ -35,5 +37,5 @@ declare const checkWrapGroup: CheckWrapGroup<typeof extendableAssertions, typeof
|
|
|
35
37
|
* `undefined`.
|
|
36
38
|
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
37
39
|
*/
|
|
38
|
-
export declare const checkWrap: (<T>(input: T) => undefined | T) & typeof
|
|
40
|
+
export declare const checkWrap: (<T>(input: T) => undefined | T) & typeof checkWrapMethods & Record<keyof AnyFunction, never>;
|
|
39
41
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
2
|
+
const checkWrapMethods = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
3
|
+
return entry.checkWrap;
|
|
4
|
+
}));
|
|
4
5
|
/**
|
|
5
6
|
* A group of guard methods that do the following:
|
|
6
7
|
*
|
|
@@ -39,4 +40,4 @@ export const checkWrap = Object.assign(function checkWrap(input) {
|
|
|
39
40
|
return undefined;
|
|
40
41
|
}
|
|
41
42
|
return input;
|
|
42
|
-
},
|
|
43
|
+
}, checkWrapMethods);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
declare const
|
|
1
|
+
import { AnyFunction, ArrayElement } from '@augment-vir/core';
|
|
2
|
+
import { UnionToIntersection } from 'type-fest';
|
|
3
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
4
|
+
declare const checkMethods: UnionToIntersection<ArrayElement<typeof guardOverrides>['check']>;
|
|
5
5
|
/**
|
|
6
6
|
* A group of guard methods that return a boolean type guard rather than an assertion type guard.
|
|
7
7
|
*
|
|
@@ -24,5 +24,5 @@ declare const checkGroup: CheckGroup<typeof extendableAssertions, typeof checkOv
|
|
|
24
24
|
* @returns A boolean (as a type guard when possible).
|
|
25
25
|
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
26
26
|
*/
|
|
27
|
-
export declare const check: ((input: unknown) => boolean) & typeof
|
|
27
|
+
export declare const check: ((input: unknown) => boolean) & typeof checkMethods & Record<keyof AnyFunction, never>;
|
|
28
28
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
2
|
+
const checkMethods = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
3
|
+
return entry.check;
|
|
4
|
+
}));
|
|
4
5
|
/**
|
|
5
6
|
* A group of guard methods that return a boolean type guard rather than an assertion type guard.
|
|
6
7
|
*
|
|
@@ -25,4 +26,4 @@ const checkGroup = createCheckGroup(extendableAssertions, checkOverrides);
|
|
|
25
26
|
*/
|
|
26
27
|
export const check = Object.assign(function check(input) {
|
|
27
28
|
return !!input;
|
|
28
|
-
},
|
|
29
|
+
}, checkMethods);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ArrayElement } from '@augment-vir/core';
|
|
2
|
+
import { UnionToIntersection } from 'type-fest';
|
|
3
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
4
|
+
import { type WaitUntilOptions } from '../../guard-types/wait-until-function.js';
|
|
5
|
+
declare const waitUntilMethods: UnionToIntersection<Extract<ArrayElement<typeof guardOverrides>, {
|
|
6
|
+
waitUntil: any;
|
|
7
|
+
}>['waitUntil']>;
|
|
4
8
|
/**
|
|
5
9
|
* A group of guard methods that run the given callback multiple times until its return value
|
|
6
10
|
* matches expectations. Callback interval and timeout can be customized with
|
|
@@ -36,5 +40,5 @@ declare const waitUntilGroup: WaitUntilGroup<typeof extendableAssertions, typeof
|
|
|
36
40
|
* @throws {@link AssertionError} When the assertion fails.
|
|
37
41
|
* @package [`@augment-vir/assert`](https://www.npmjs.com/package/@augment-vir/assert)
|
|
38
42
|
*/
|
|
39
|
-
export declare const waitUntil: (<T>(callback: () => T, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<T>) & typeof
|
|
43
|
+
export declare const waitUntil: (<T>(callback: () => T, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<T>) & typeof waitUntilMethods;
|
|
40
44
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { guardOverrides } from '../../assertions/extendable-assertions.js';
|
|
2
|
+
import { executeWaitUntil } from '../../guard-types/wait-until-function.js';
|
|
3
3
|
import { AssertionError } from '../assertion.error.js';
|
|
4
|
-
const
|
|
4
|
+
const waitUntilMethods = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
5
|
+
return entry.waitUntil;
|
|
6
|
+
}));
|
|
5
7
|
/**
|
|
6
8
|
* A group of guard methods that run the given callback multiple times until its return value
|
|
7
9
|
* matches expectations. Callback interval and timeout can be customized with
|
|
@@ -42,8 +44,5 @@ export const waitUntil = Object.assign(function waitUntil(input, failureMessage)
|
|
|
42
44
|
if (!input) {
|
|
43
45
|
throw new AssertionError('Assertion failed.', failureMessage);
|
|
44
46
|
}
|
|
45
|
-
}, [
|
|
46
|
-
|
|
47
|
-
failureMessage,
|
|
48
|
-
], false);
|
|
49
|
-
}, waitUntilGroup);
|
|
47
|
+
}, [input, failureMessage], false);
|
|
48
|
+
}, waitUntilMethods);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/** C8 fails in type-only files. */
|
|
2
|
+
import { AnyFunction, MaybePromise } from '@augment-vir/core';
|
|
2
3
|
import type { AssertFunction } from './assert-function.js';
|
|
3
|
-
import type { AssertWrapOverridesBase } from './assert-wrap-function.js';
|
|
4
|
-
import type { CheckOverridesBase } from './check-function.js';
|
|
5
4
|
import type { WaitUntilOverridesBase } from './wait-until-function.js';
|
|
5
|
+
export type AssertWrapOverridesBase<Keys extends PropertyKey = string> = Partial<Readonly<Record<Keys, AnyFunction | undefined>>>;
|
|
6
|
+
export type CheckFunction<Output> = (input: any, ...extraInputs: any[]) => input is Output;
|
|
7
|
+
export type GenericCheckFunction = (input: any, ...extraInputs: any[]) => MaybePromise<boolean> | never;
|
|
8
|
+
export type CheckOverridesBase<Keys extends PropertyKey = string> = Partial<Readonly<Record<Keys, CheckFunction<any> | GenericCheckFunction | undefined>>>;
|
|
6
9
|
export type GuardGroup<Assertions extends Record<string, AssertFunction<any>>> = {
|
|
7
10
|
assert: Assertions;
|
|
8
11
|
check: CheckOverridesBase<keyof Assertions>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { AnyFunction, MaybePromise, NarrowToExpected, PartialWithUndefined, RemoveFirstTupleEntry, RemoveLastTupleEntry, RequiredAndNotNull } from '@augment-vir/core';
|
|
2
|
-
import { type ExtractKeysWithMatchingValues, type Overwrite } from '@augment-vir/core';
|
|
3
2
|
import { type AnyDuration } from '@date-vir/duration';
|
|
4
3
|
import type { AssertFunction } from './assert-function.js';
|
|
5
|
-
import { autoGuardSymbol } from './guard-override.js';
|
|
6
4
|
/**
|
|
7
5
|
* Options for configuring the timing of `waitUntil`.
|
|
8
6
|
*
|
|
@@ -27,22 +25,16 @@ export type WaitUntilOptions = PartialWithUndefined<{
|
|
|
27
25
|
}>;
|
|
28
26
|
export declare const defaultWaitUntilOptions: RequiredAndNotNull<WaitUntilOptions>;
|
|
29
27
|
export declare function executeWaitUntil<const Assert extends AssertFunction<any>>(this: void, assert: AssertFunction<any>, rawArgs: unknown[], requireSynchronousResult: boolean): Promise<ReturnType<WaitUntilFunction<Assert>>>;
|
|
30
|
-
export type WaitUntilOverridesBase<Keys extends PropertyKey = string> = Readonly<Record<Keys, AnyFunction |
|
|
28
|
+
export type WaitUntilOverridesBase<Keys extends PropertyKey = string> = Readonly<Partial<Record<Keys, AnyFunction | undefined>>>;
|
|
31
29
|
export type WaitUntilFunctionParameters<Assert extends AssertFunction<any>, Input> = [
|
|
32
30
|
...RemoveFirstTupleEntry<RemoveLastTupleEntry<Parameters<Assert>>>,
|
|
33
31
|
() => MaybePromise<Input>
|
|
34
32
|
];
|
|
35
|
-
export type WaitUntilFunction<Assert extends AssertFunction<any>> = Assert extends AssertFunction<infer Guard> ? <Input extends Parameters<Assert>[0]>(...params: [
|
|
33
|
+
export type WaitUntilFunction<Assert extends AssertFunction<any>> = Assert extends AssertFunction<infer Guard> ? <Input extends Parameters<Assert>[0]>(this: void, ...params: [
|
|
36
34
|
...WaitUntilFunctionParameters<Assert, Input>,
|
|
37
35
|
options?: WaitUntilOptions | undefined,
|
|
38
36
|
failureMessage?: string | undefined
|
|
39
37
|
]) => Promise<NarrowToExpected<Input, Guard>> : never;
|
|
40
|
-
export type WaitUntilGroup<Asserts extends Readonly<Record<string, AssertFunction<any>>>, WaitUntilOverrides extends WaitUntilOverridesBase> = Omit<Overwrite<{
|
|
41
|
-
[Name in keyof Asserts as Asserts[Name] extends AssertFunction<any> ? Name : never]: WaitUntilFunction<Asserts[Name]>;
|
|
42
|
-
}, {
|
|
43
|
-
[Name in keyof WaitUntilOverrides]: WaitUntilOverrides[Name] extends typeof autoGuardSymbol ? Name extends keyof Asserts ? Asserts[Name] extends AssertFunction<any> ? WaitUntilFunction<Asserts[Name]> : never : never : WaitUntilOverrides[Name];
|
|
44
|
-
}>, ExtractKeysWithMatchingValues<WaitUntilOverrides, undefined>>;
|
|
45
|
-
export declare function createWaitUntilGroup<const Asserts extends Readonly<Record<string, AssertFunction<any>>>, const WaitUntilOverrides extends WaitUntilOverridesBase>(asserts: Asserts, waitUntilOverrides: WaitUntilOverrides): WaitUntilGroup<Asserts, WaitUntilOverrides>;
|
|
46
38
|
export declare function createWaitUntil<const Assert extends AssertFunction<any>>(assert: Assert, requireSynchronousResult?: boolean): WaitUntilFunction<Assert>;
|
|
47
39
|
export declare function parseWaitUntilArgs(rawArgs: unknown[]): {
|
|
48
40
|
callback: AnyFunction;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ensureError, ensureErrorAndPrependMessage, wait
|
|
1
|
+
import { ensureError, ensureErrorAndPrependMessage, wait } from '@augment-vir/core';
|
|
2
2
|
import { convertDuration } from '@date-vir/duration';
|
|
3
|
-
import { pickOverride } from './guard-override.js';
|
|
4
3
|
export const defaultWaitUntilOptions = {
|
|
5
4
|
interval: {
|
|
6
5
|
milliseconds: 100,
|
|
@@ -38,13 +37,6 @@ export async function executeWaitUntil(assert, rawArgs, requireSynchronousResult
|
|
|
38
37
|
}
|
|
39
38
|
return lastCallbackOutput;
|
|
40
39
|
}
|
|
41
|
-
export function createWaitUntilGroup(asserts, waitUntilOverrides) {
|
|
42
|
-
const waitUntilGroup = Object.entries(asserts).reduce((accum, [name, assert,]) => {
|
|
43
|
-
accum[name] = pickOverride(waitUntilOverrides, name, () => createWaitUntil(assert));
|
|
44
|
-
return accum;
|
|
45
|
-
}, {});
|
|
46
|
-
return waitUntilGroup;
|
|
47
|
-
}
|
|
48
40
|
export function createWaitUntil(assert, requireSynchronousResult = false) {
|
|
49
41
|
return ((...rawArgs) => {
|
|
50
42
|
return executeWaitUntil(assert, rawArgs, requireSynchronousResult);
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/assert",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.1.0",
|
|
4
4
|
"description": "A collection of assertions for test and production code alike.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"test:update": "npm test"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
44
|
+
"@augment-vir/core": "^31.1.0",
|
|
45
45
|
"@date-vir/duration": "^7.0.1",
|
|
46
46
|
"deep-eql": "^5.0.2",
|
|
47
47
|
"expect-type": "^1.1.0",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type AnyFunction, type ExtractKeysWithMatchingValues, type NarrowToExpected, type Overwrite } from '@augment-vir/core';
|
|
2
|
-
import { type AssertFunction } from './assert-function.js';
|
|
3
|
-
import { autoGuardSymbol } from './guard-override.js';
|
|
4
|
-
export type AssertWrapFunction<Output> = <Input>(input: Input, ...extraInputs: any[]) => NarrowToExpected<Input, Output>;
|
|
5
|
-
export type AssertWrapOverridesBase<Keys extends PropertyKey = string> = Readonly<Record<Keys, AnyFunction | undefined | typeof autoGuardSymbol>>;
|
|
6
|
-
export type AssertWrapGroup<Asserts extends Readonly<Record<string, AssertFunction<any>>>, AssertWrapOverrides extends AssertWrapOverridesBase> = Omit<Overwrite<{
|
|
7
|
-
[Name in keyof Asserts as Asserts[Name] extends AssertFunction<any> ? Name : never]: Asserts[Name] extends AssertFunction<infer Output> ? AssertWrapFunction<Output> : never;
|
|
8
|
-
}, {
|
|
9
|
-
[Name in keyof AssertWrapOverrides]: AssertWrapOverrides[Name] extends typeof autoGuardSymbol ? Name extends keyof Asserts ? Asserts[Name] extends AssertFunction<infer Output> ? AssertWrapFunction<Output> : never : never : AssertWrapOverrides[Name];
|
|
10
|
-
}>, ExtractKeysWithMatchingValues<AssertWrapOverrides, undefined>>;
|
|
11
|
-
export declare function createAssertWrapGroup<const Asserts extends Readonly<Record<string, AssertFunction<any>>>, const AssertWrapOverrides extends AssertWrapOverridesBase>(asserts: Asserts, assertWrapOverrides: AssertWrapOverrides): AssertWrapGroup<Asserts, AssertWrapOverrides>;
|
|
12
|
-
export declare function createAssertWrap<const Output>(assert: AssertFunction<Output>): AssertWrapFunction<Output>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { pickOverride } from './guard-override.js';
|
|
2
|
-
export function createAssertWrapGroup(asserts, assertWrapOverrides) {
|
|
3
|
-
const checks = Object.entries(asserts).reduce((accum, [name, assert,]) => {
|
|
4
|
-
accum[name] = pickOverride(assertWrapOverrides, name, () => createAssertWrap(assert));
|
|
5
|
-
return accum;
|
|
6
|
-
}, {});
|
|
7
|
-
return checks;
|
|
8
|
-
}
|
|
9
|
-
export function createAssertWrap(assert) {
|
|
10
|
-
return ((...inputs) => {
|
|
11
|
-
assert(...inputs);
|
|
12
|
-
return inputs[0];
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ExtractKeysWithMatchingValues, MaybePromise, Overwrite, RemoveFirstTupleEntry, RemoveLastTupleEntry } from '@augment-vir/core';
|
|
2
|
-
import { type AssertFunction } from './assert-function.js';
|
|
3
|
-
import { type autoGuardSymbol } from './guard-override.js';
|
|
4
|
-
export type CheckFunction<Output> = (input: any, ...extraInputs: any[]) => input is Output;
|
|
5
|
-
export type GenericCheckFunction = (input: any, ...extraInputs: any[]) => MaybePromise<boolean> | never;
|
|
6
|
-
export type CheckOverridesBase<Keys extends PropertyKey = string> = Readonly<Record<Keys, CheckFunction<any> | GenericCheckFunction | undefined | typeof autoGuardSymbol>>;
|
|
7
|
-
export type CheckGroup<Asserts extends Readonly<Record<string, AssertFunction<any>>>, CheckOverrides extends CheckOverridesBase> = Omit<Overwrite<{
|
|
8
|
-
[Name in keyof Asserts as Asserts[Name] extends AssertFunction<any> ? Name : never]: Asserts[Name] extends AssertFunction<infer Output> ? (input: Parameters<Asserts[Name]>[0], ...params: RemoveLastTupleEntry<RemoveFirstTupleEntry<Parameters<Asserts[Name]>>>) => input is Output : never;
|
|
9
|
-
}, {
|
|
10
|
-
[Name in keyof CheckOverrides]: CheckOverrides[Name] extends typeof autoGuardSymbol ? Name extends keyof Asserts ? Asserts[Name] extends AssertFunction<infer Output> ? (input: Parameters<Asserts[Name]>[0], ...params: RemoveLastTupleEntry<RemoveFirstTupleEntry<Parameters<Asserts[Name]>>>) => input is Output : never : never : CheckOverrides[Name];
|
|
11
|
-
}>, ExtractKeysWithMatchingValues<CheckOverrides, undefined>>;
|
|
12
|
-
export declare function createCheckGroup<const Asserts extends Readonly<Record<string, AssertFunction<any>>>, const CheckOverrides extends CheckOverridesBase>(asserts: Asserts, checkOverrides: CheckOverrides): CheckGroup<Asserts, CheckOverrides>;
|
|
13
|
-
export declare function createCheck<const Output>(assert: AssertFunction<Output>): CheckFunction<Output>;
|
|
14
|
-
export declare function runAssertCheck<const Output, const Assert extends AssertFunction<Output>>(assert: Assert, input: Parameters<Assert>[0], ...inputs: RemoveFirstTupleEntry<RemoveLastTupleEntry<Parameters<Assert>>>): input is Output;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { pickOverride } from './guard-override.js';
|
|
2
|
-
export function createCheckGroup(asserts, checkOverrides) {
|
|
3
|
-
const checks = Object.entries(asserts).reduce((accum, [name, assert,]) => {
|
|
4
|
-
accum[name] = pickOverride(checkOverrides, name, () => createCheck(assert));
|
|
5
|
-
return accum;
|
|
6
|
-
}, {});
|
|
7
|
-
return checks;
|
|
8
|
-
}
|
|
9
|
-
export function createCheck(assert) {
|
|
10
|
-
return ((...inputs) => {
|
|
11
|
-
return runAssertCheck(assert, ...inputs);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export function runAssertCheck(assert, input, ...inputs) {
|
|
15
|
-
try {
|
|
16
|
-
assert(input, ...inputs);
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ExtractKeysWithMatchingValues, NarrowToActual, Overwrite } from '@augment-vir/core';
|
|
2
|
-
import { type AssertFunction } from './assert-function.js';
|
|
3
|
-
import { type AssertWrapOverridesBase } from './assert-wrap-function.js';
|
|
4
|
-
import { autoGuardSymbol } from './guard-override.js';
|
|
5
|
-
export type CheckWrapFunction<Output> = <Input>(input: Input, ...extraInputs: any[]) => NarrowToActual<Input, Output> | undefined;
|
|
6
|
-
export type CheckWrapGroup<Asserts extends Readonly<Record<string, AssertFunction<any>>>, CheckWrapOverrides extends AssertWrapOverridesBase> = Omit<Overwrite<{
|
|
7
|
-
[Name in keyof Asserts as Asserts[Name] extends AssertFunction<any> ? Name : never]: Asserts[Name] extends AssertFunction<infer Output> ? CheckWrapFunction<Output> : never;
|
|
8
|
-
}, {
|
|
9
|
-
[Name in keyof CheckWrapOverrides]: CheckWrapOverrides[Name] extends typeof autoGuardSymbol ? Name extends keyof Asserts ? Asserts[Name] extends AssertFunction<infer Output> ? CheckWrapFunction<Output> : never : never : CheckWrapOverrides[Name];
|
|
10
|
-
}>, ExtractKeysWithMatchingValues<CheckWrapOverrides, undefined>>;
|
|
11
|
-
export declare function createCheckWrapGroup<const Asserts extends Readonly<Record<string, AssertFunction<any>>>, const CheckWrapOverrides extends AssertWrapOverridesBase>(asserts: Asserts, checkWrapOverrides: CheckWrapOverrides): CheckWrapGroup<Asserts, CheckWrapOverrides>;
|
|
12
|
-
export declare function createCheckWrap<const Output>(assert: AssertFunction<Output>): CheckWrapFunction<Output>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { pickOverride } from './guard-override.js';
|
|
2
|
-
export function createCheckWrapGroup(asserts, checkWrapOverrides) {
|
|
3
|
-
const checks = Object.entries(asserts).reduce((accum, [name, assert,]) => {
|
|
4
|
-
accum[name] = pickOverride(checkWrapOverrides, name, () => createCheckWrap(assert));
|
|
5
|
-
return accum;
|
|
6
|
-
}, {});
|
|
7
|
-
return checks;
|
|
8
|
-
}
|
|
9
|
-
export function createCheckWrap(assert) {
|
|
10
|
-
return ((...inputs) => {
|
|
11
|
-
try {
|
|
12
|
-
assert(...inputs);
|
|
13
|
-
return inputs[0];
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AnyObject, Values } from '@augment-vir/core';
|
|
2
|
-
export declare const autoGuardSymbol: unique symbol;
|
|
3
|
-
export declare function autoGuard<T>(): T;
|
|
4
|
-
export declare function pickOverride<Overrides extends AnyObject, Created>(overrides: Overrides, name: string, create: () => Created): Values<Overrides> | Created;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const autoGuardSymbol = Symbol('auto guard');
|
|
2
|
-
export function autoGuard() {
|
|
3
|
-
return autoGuardSymbol;
|
|
4
|
-
}
|
|
5
|
-
export function pickOverride(overrides, name, create) {
|
|
6
|
-
if (name in overrides && overrides[name] !== autoGuardSymbol) {
|
|
7
|
-
return overrides[name];
|
|
8
|
-
}
|
|
9
|
-
return create();
|
|
10
|
-
}
|