Skip to content

Commit

Permalink
[patch] convince TypeScript to stop inlining the guard methods in @au…
Browse files Browse the repository at this point in the history
…gment-vir/assert
  • Loading branch information
electrovir committed Sep 15, 2024
1 parent d8edd20 commit 1541c39
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 58 deletions.
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/mono-repo-root",
"version": "30.0.4",
"version": "30.0.5",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand Down
4 changes: 2 additions & 2 deletions packages/assert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/assert",
"version": "30.0.4",
"version": "30.0.5",
"description": "A collection of assertions for test and production code alike.",
"keywords": [
"augment",
Expand Down Expand Up @@ -41,7 +41,7 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/core": "^30.0.4",
"@augment-vir/core": "^30.0.5",
"@date-vir/duration": "^6.0.0",
"deep-eql": "^5.0.2",
"expect-type": "^0.20.0",
Expand Down
44 changes: 42 additions & 2 deletions packages/assert/src/assertions/extendable-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,26 @@ import {throwGuards} from './throws.js';
import {uuidGuards} from './uuid.js';
import {valueGuards} from './values.js';

export const extendableAssertions = {
export const extendableAssertions: typeof booleanGuards.assert &
typeof boundaryGuards.assert &
typeof entryEqualityGuards.assert &
typeof enumGuards.assert &
typeof instanceGuards.assert &
typeof jsonEqualityGuards.assert &
typeof keyGuards.assert &
typeof lengthGuards.assert &
typeof nullishGuards.assert &
typeof numericGuards.assert &
typeof primitiveGuards.assert &
typeof promiseGuards.assert &
typeof regexpGuards.assert &
typeof runtimeTypeGuards.assert &
typeof simpleEqualityGuards.assert &
typeof throwGuards.assert &
typeof uuidGuards.assert &
typeof valueGuards.assert &
typeof httpGuards.assert &
typeof outputGuards.assert = {
...booleanGuards.assert,
...boundaryGuards.assert,
...entryEqualityGuards.assert,
Expand Down Expand Up @@ -51,7 +70,28 @@ export const extendableAssertions = {
* maintain function type parameters when mapping such functions.
*/

export const guardOverrides = [
export const guardOverrides: [
typeof booleanGuards,
typeof boundaryGuards,
typeof entryEqualityGuards,
typeof enumGuards,
typeof instanceGuards,
typeof jsonEqualityGuards,
typeof keyGuards,
typeof lengthGuards,
typeof nullishGuards,
typeof numericGuards,
typeof primitiveGuards,
typeof promiseGuards,
typeof regexpGuards,
typeof runtimeTypeGuards,
typeof simpleEqualityGuards,
typeof throwGuards,
typeof uuidGuards,
typeof valueGuards,
typeof httpGuards,
typeof outputGuards,
] = [
booleanGuards,
boundaryGuards,
entryEqualityGuards,
Expand Down
5 changes: 3 additions & 2 deletions packages/assert/src/augments/guards/assert-wrap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {assertWrapOverrides, extendableAssertions} from '../../assertions/extendable-assertions.js';
import {createAssertWrapGroup} from '../../guard-types/assert-wrap-function.js';
import {AssertWrapGroup, createAssertWrapGroup} from '../../guard-types/assert-wrap-function.js';
import {AssertionError} from '../assertion.error.js';

const assertWrapGroup = createAssertWrapGroup(extendableAssertions, assertWrapOverrides);
const assertWrapGroup: AssertWrapGroup<typeof extendableAssertions, typeof assertWrapOverrides> =
createAssertWrapGroup(extendableAssertions, assertWrapOverrides);

/**
* A group of guard methods that do the following:
Expand Down
12 changes: 9 additions & 3 deletions packages/assert/src/augments/guards/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {tsTypeGuards} from '../../assertions/equality/ts-type-equality.js';
import {extendableAssertions} from '../../assertions/extendable-assertions.js';
import {AssertionError} from '../assertion.error.js';

const allAssertions = {
...tsTypeGuards.assert,
...extendableAssertions,
const extraAssertions = {
/**
* Immediately throw an assertion error.
*
Expand All @@ -23,6 +21,14 @@ const allAssertions = {
},
};

const allAssertions: typeof tsTypeGuards.assert &
typeof extendableAssertions &
typeof extraAssertions = {
...tsTypeGuards.assert,
...extendableAssertions,
...extraAssertions,
};

/**
* A group of guard methods that assert their conditions and do nothing else.
*
Expand Down
8 changes: 6 additions & 2 deletions packages/assert/src/augments/guards/check-wrap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {type AnyFunction} from '@augment-vir/core';
import {checkWrapOverrides, extendableAssertions} from '../../assertions/extendable-assertions.js';
import {createCheckWrapGroup} from '../../guard-types/check-wrap-wrapper-function.js';
import {
CheckWrapGroup,
createCheckWrapGroup,
} from '../../guard-types/check-wrap-wrapper-function.js';

const checkWrapGroup = createCheckWrapGroup(extendableAssertions, checkWrapOverrides);
const checkWrapGroup: CheckWrapGroup<typeof extendableAssertions, typeof checkWrapOverrides> =
createCheckWrapGroup(extendableAssertions, checkWrapOverrides);

/**
* A group of guard methods that do the following:
Expand Down
7 changes: 5 additions & 2 deletions packages/assert/src/augments/guards/check.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type {AnyFunction} from '@augment-vir/core';
import {checkOverrides, extendableAssertions} from '../../assertions/extendable-assertions.js';
import {createCheckGroup} from '../../guard-types/check-function.js';
import {CheckGroup, createCheckGroup} from '../../guard-types/check-function.js';

const checkGroup = createCheckGroup(extendableAssertions, checkOverrides);
const checkGroup: CheckGroup<typeof extendableAssertions, typeof checkOverrides> = createCheckGroup(
extendableAssertions,
checkOverrides,
);

/**
* A group of guard methods that return a boolean type guard rather than an assertion type guard.
Expand Down
4 changes: 3 additions & 1 deletion packages/assert/src/augments/guards/wait-until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {extendableAssertions, waitUntilOverrides} from '../../assertions/extenda
import {
createWaitUntilGroup,
executeWaitUntil,
type WaitUntilGroup,
type WaitUntilOptions,
} from '../../guard-types/wait-until-function.js';
import {AssertionError} from '../assertion.error.js';

const waitUntilGroup = createWaitUntilGroup(extendableAssertions, waitUntilOverrides);
const waitUntilGroup: WaitUntilGroup<typeof extendableAssertions, typeof waitUntilOverrides> =
createWaitUntilGroup(extendableAssertions, waitUntilOverrides);

/**
* A group of guard methods that run the given callback multiple times until its return value
Expand Down
2 changes: 1 addition & 1 deletion packages/assert/src/guard-types/wait-until-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type WaitUntilFunction<Assert extends AssertFunction<any>> =
) => Promise<NarrowToExpected<Input, Guard>>
: never;

type WaitUntilGroup<
export type WaitUntilGroup<
Asserts extends Readonly<Record<string, AssertFunction<any>>>,
WaitUntilOverrides extends WaitUntilOverridesBase,
> = Omit<
Expand Down
6 changes: 3 additions & 3 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/common",
"version": "30.0.4",
"version": "30.0.5",
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
"keywords": [
"augment",
Expand Down Expand Up @@ -39,8 +39,8 @@
"test:web": "virmator --no-deps test web"
},
"dependencies": {
"@augment-vir/assert": "^30.0.4",
"@augment-vir/core": "^30.0.4",
"@augment-vir/assert": "^30.0.5",
"@augment-vir/core": "^30.0.5",
"@date-vir/duration": "^6.0.0",
"ansi-styles": "^6.2.1",
"json5": "^2.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/core",
"version": "30.0.4",
"version": "30.0.5",
"description": "Core augment-vir augments. Use @augment-vir/common instead.",
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand Down
8 changes: 4 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/node",
"version": "30.0.4",
"version": "30.0.5",
"description": "A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.",
"keywords": [
"augment",
Expand Down Expand Up @@ -37,16 +37,16 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/assert": "^30.0.4",
"@augment-vir/common": "^30.0.4",
"@augment-vir/assert": "^30.0.5",
"@augment-vir/common": "^30.0.5",
"@date-vir/duration": "^6.0.0",
"ansi-styles": "^6.2.1",
"terminate": "^2.8.0",
"type-fest": "^4.26.1",
"typed-event-target": "^3.4.0"
},
"devDependencies": {
"@augment-vir/test": "^30.0.4",
"@augment-vir/test": "^30.0.5",
"@prisma/client": "^5.19.1",
"@types/node": "^22.5.5",
"@web/dev-server-esbuild": "^1.0.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/scripts",
"version": "30.0.4",
"version": "30.0.5",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand All @@ -24,14 +24,14 @@
"test:update": "npm test"
},
"dependencies": {
"@augment-vir/assert": "^30.0.4",
"@augment-vir/core": "^30.0.4",
"@augment-vir/assert": "^30.0.5",
"@augment-vir/core": "^30.0.5",
"@virmator/docs": "^13.3.12",
"jsdom": "^25.0.0",
"typedoc": "^0.26.7"
},
"devDependencies": {
"@augment-vir/test": "^30.0.4",
"@augment-vir/test": "^30.0.5",
"@types/jsdom": "^21.1.7",
"@types/node": "^22.5.5"
},
Expand Down
Loading

0 comments on commit 1541c39

Please sign in to comment.