From 1541c39912c7485cc3575ff968b7d0c1dd78ccda Mon Sep 17 00:00:00 2001 From: electrovir Date: Sun, 15 Sep 2024 16:26:07 +0000 Subject: [PATCH] [patch] convince TypeScript to stop inlining the guard methods in @augment-vir/assert --- package-lock.json | 46 +++++++++---------- package.json | 2 +- packages/assert/package.json | 4 +- .../src/assertions/extendable-assertions.ts | 44 +++++++++++++++++- .../assert/src/augments/guards/assert-wrap.ts | 5 +- packages/assert/src/augments/guards/assert.ts | 12 +++-- .../assert/src/augments/guards/check-wrap.ts | 8 +++- packages/assert/src/augments/guards/check.ts | 7 ++- .../assert/src/augments/guards/wait-until.ts | 4 +- .../src/guard-types/wait-until-function.ts | 2 +- packages/common/package.json | 6 +-- packages/core/package.json | 2 +- packages/node/package.json | 8 ++-- packages/scripts/package.json | 8 ++-- packages/test/package.json | 6 +-- packages/web/package.json | 8 ++-- 16 files changed, 114 insertions(+), 58 deletions(-) diff --git a/package-lock.json b/package-lock.json index f3d909af..333eb6dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@augment-vir/mono-repo-root", - "version": "30.0.4", + "version": "30.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@augment-vir/mono-repo-root", - "version": "30.0.4", + "version": "30.0.5", "hasInstallScript": true, "license": "(MIT or CC0 1.0)", "workspaces": [ @@ -18832,10 +18832,10 @@ }, "packages/assert": { "name": "@augment-vir/assert", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "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", @@ -18867,11 +18867,11 @@ }, "packages/common": { "name": "@augment-vir/common", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "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", @@ -18965,7 +18965,7 @@ }, "packages/core": { "name": "@augment-vir/core", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "dependencies": { "@date-vir/duration": "^6.0.0", @@ -18984,11 +18984,11 @@ }, "packages/node": { "name": "@augment-vir/node", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "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", @@ -18996,7 +18996,7 @@ "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", @@ -19087,17 +19087,17 @@ }, "packages/scripts": { "name": "@augment-vir/scripts", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "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" }, @@ -19107,11 +19107,11 @@ }, "packages/test": { "name": "@augment-vir/test", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "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", "@open-wc/testing-helpers": "^3.0.1", "type-fest": "^4.26.1" }, @@ -19204,17 +19204,17 @@ }, "packages/web": { "name": "@augment-vir/web", - "version": "30.0.4", + "version": "30.0.5", "license": "(MIT or CC0 1.0)", "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", "html-spec-tags": "^2.2.0", "type-fest": "^4.26.1" }, "devDependencies": { - "@augment-vir/test": "^30.0.4", + "@augment-vir/test": "^30.0.5", "bowser": "^2.11.0", "typescript": "^5.6.2" }, diff --git a/package.json b/package.json index 1e144b34..9d27da4c 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/packages/assert/package.json b/packages/assert/package.json index a289ccd8..d823d042 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -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", @@ -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", diff --git a/packages/assert/src/assertions/extendable-assertions.ts b/packages/assert/src/assertions/extendable-assertions.ts index 7b67466a..fdd4a600 100644 --- a/packages/assert/src/assertions/extendable-assertions.ts +++ b/packages/assert/src/assertions/extendable-assertions.ts @@ -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, @@ -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, diff --git a/packages/assert/src/augments/guards/assert-wrap.ts b/packages/assert/src/augments/guards/assert-wrap.ts index ededc9bc..57687003 100644 --- a/packages/assert/src/augments/guards/assert-wrap.ts +++ b/packages/assert/src/augments/guards/assert-wrap.ts @@ -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 = + createAssertWrapGroup(extendableAssertions, assertWrapOverrides); /** * A group of guard methods that do the following: diff --git a/packages/assert/src/augments/guards/assert.ts b/packages/assert/src/augments/guards/assert.ts index ba006323..e92b0c68 100644 --- a/packages/assert/src/augments/guards/assert.ts +++ b/packages/assert/src/augments/guards/assert.ts @@ -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. * @@ -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. * diff --git a/packages/assert/src/augments/guards/check-wrap.ts b/packages/assert/src/augments/guards/check-wrap.ts index e9a9bcf4..8a06a844 100644 --- a/packages/assert/src/augments/guards/check-wrap.ts +++ b/packages/assert/src/augments/guards/check-wrap.ts @@ -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 = + createCheckWrapGroup(extendableAssertions, checkWrapOverrides); /** * A group of guard methods that do the following: diff --git a/packages/assert/src/augments/guards/check.ts b/packages/assert/src/augments/guards/check.ts index 75b0134a..16c38e0f 100644 --- a/packages/assert/src/augments/guards/check.ts +++ b/packages/assert/src/augments/guards/check.ts @@ -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 = createCheckGroup( + extendableAssertions, + checkOverrides, +); /** * A group of guard methods that return a boolean type guard rather than an assertion type guard. diff --git a/packages/assert/src/augments/guards/wait-until.ts b/packages/assert/src/augments/guards/wait-until.ts index 3c391f81..7b3dc4db 100644 --- a/packages/assert/src/augments/guards/wait-until.ts +++ b/packages/assert/src/augments/guards/wait-until.ts @@ -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 = + createWaitUntilGroup(extendableAssertions, waitUntilOverrides); /** * A group of guard methods that run the given callback multiple times until its return value diff --git a/packages/assert/src/guard-types/wait-until-function.ts b/packages/assert/src/guard-types/wait-until-function.ts index 1e896570..5309610f 100644 --- a/packages/assert/src/guard-types/wait-until-function.ts +++ b/packages/assert/src/guard-types/wait-until-function.ts @@ -113,7 +113,7 @@ export type WaitUntilFunction> = ) => Promise> : never; -type WaitUntilGroup< +export type WaitUntilGroup< Asserts extends Readonly>>, WaitUntilOverrides extends WaitUntilOverridesBase, > = Omit< diff --git a/packages/common/package.json b/packages/common/package.json index 68640a73..6ce05ed3 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -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", @@ -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", diff --git a/packages/core/package.json b/packages/core/package.json index a6109fca..d984ac39 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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": { diff --git a/packages/node/package.json b/packages/node/package.json index 29a8d8f6..231dc4f6 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -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", @@ -37,8 +37,8 @@ "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", @@ -46,7 +46,7 @@ "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", diff --git a/packages/scripts/package.json b/packages/scripts/package.json index fdd3f989..33268c76 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -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": { @@ -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" }, diff --git a/packages/test/package.json b/packages/test/package.json index ef900d84..25f71f84 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/test", - "version": "30.0.4", + "version": "30.0.5", "description": "A universal testing suite that works with Mocha style test runners _and_ Node.js's built-in test runner.", "keywords": [ "test", @@ -42,8 +42,8 @@ "test:web": "virmator test --no-deps web 'src/test-web/**/*.test.ts'" }, "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", "@open-wc/testing-helpers": "^3.0.1", "type-fest": "^4.26.1" }, diff --git a/packages/web/package.json b/packages/web/package.json index be45b131..f4e9f784 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,6 +1,6 @@ { "name": "@augment-vir/web", - "version": "30.0.4", + "version": "30.0.5", "description": "A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.", "keywords": [ "augment", @@ -35,14 +35,14 @@ "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", "html-spec-tags": "^2.2.0", "type-fest": "^4.26.1" }, "devDependencies": { - "@augment-vir/test": "^30.0.4", + "@augment-vir/test": "^30.0.5", "bowser": "^2.11.0", "typescript": "^5.6.2" },