From bfbb1075c168af8e80df46c2259263b277e5502d Mon Sep 17 00:00:00 2001 From: Lukas Obermann Date: Sun, 6 Oct 2024 12:43:26 +0200 Subject: [PATCH] feat: use @optolith/helpers package --- package-lock.json | 12 ++++++++++++ package.json | 1 + src/parser/resolvetypeargs.ts | 4 ++-- src/renderers/jsonSchema.ts | 2 +- src/renderers/markdown.ts | 4 ++-- src/utils/assertExhaustive.ts | 6 ------ src/utils/nullable.ts | 2 -- 7 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 src/utils/assertExhaustive.ts delete mode 100644 src/utils/nullable.ts diff --git a/package-lock.json b/package-lock.json index 6e1b093..0431c97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.10.7", "license": "MPL-2.0", "dependencies": { + "@optolith/helpers": "^0.2.1", "typescript": "^5.2.2" }, "bin": { @@ -513,6 +514,12 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/@optolith/helpers": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@optolith/helpers/-/helpers-0.2.1.tgz", + "integrity": "sha512-i2mg5ro2XaY0sFT3vwW+BBuMYVuJpHRMt27X9/sBfXmgY6L16aKG3UXEcP5jjX+/gjH2AM7Uiz6xgtV31/rFLw==", + "license": "MPL-2.0" + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -3218,6 +3225,11 @@ } } }, + "@optolith/helpers": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@optolith/helpers/-/helpers-0.2.1.tgz", + "integrity": "sha512-i2mg5ro2XaY0sFT3vwW+BBuMYVuJpHRMt27X9/sBfXmgY6L16aKG3UXEcP5jjX+/gjH2AM7Uiz6xgtV31/rFLw==" + }, "@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", diff --git a/package.json b/package.json index 6afc2e9..fc68dd0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "author": "Lukas Obermann", "license": "MPL-2.0", "dependencies": { + "@optolith/helpers": "^0.2.1", "typescript": "^5.2.2" }, "devDependencies": { diff --git a/src/parser/resolvetypeargs.ts b/src/parser/resolvetypeargs.ts index f68497a..5906d1e 100644 --- a/src/parser/resolvetypeargs.ts +++ b/src/parser/resolvetypeargs.ts @@ -1,3 +1,5 @@ +import { isNotNullish } from "@optolith/helpers/nullable" +import { assertExhaustive } from "@optolith/helpers/typeSafety" import { ContentNode, EnumerationNode, @@ -10,8 +12,6 @@ import { TypeDefinitionNode, isExportAssignmentNode, } from "../ast.js" -import { assertExhaustive } from "../utils/assertExhaustive.js" -import { isNotNullish } from "../utils/nullable.js" enum ScopeTypeKind { Default, diff --git a/src/renderers/jsonSchema.ts b/src/renderers/jsonSchema.ts index 7573654..b876e0e 100644 --- a/src/renderers/jsonSchema.ts +++ b/src/renderers/jsonSchema.ts @@ -1,3 +1,4 @@ +import { assertExhaustive } from "@optolith/helpers/typeSafety" import { EOL } from "node:os" import { sep } from "node:path" import { @@ -12,7 +13,6 @@ import { isReferenceNode, } from "../ast.js" import { AstTransformer, Renderer } from "../main.js" -import { assertExhaustive } from "../utils/assertExhaustive.js" import { getAliasedImportName, getFullyQualifiedNameAsPath, diff --git a/src/renderers/markdown.ts b/src/renderers/markdown.ts index 1e87389..8bd2f72 100644 --- a/src/renderers/markdown.ts +++ b/src/renderers/markdown.ts @@ -1,3 +1,5 @@ +import { isNotNullish } from "@optolith/helpers/nullable" +import { assertExhaustive } from "@optolith/helpers/typeSafety" import { EOL } from "node:os" import { ArrayNode, @@ -20,8 +22,6 @@ import { isTokenNode, } from "../ast.js" import { AstTransformer, Renderer } from "../main.js" -import { assertExhaustive } from "../utils/assertExhaustive.js" -import { isNotNullish } from "../utils/nullable.js" import { getRightmostQualifiedNameSegment, qualifiedNameToArray, diff --git a/src/utils/assertExhaustive.ts b/src/utils/assertExhaustive.ts deleted file mode 100644 index 313202c..0000000 --- a/src/utils/assertExhaustive.ts +++ /dev/null @@ -1,6 +0,0 @@ -export function assertExhaustive( - _x: never, - msg: string = "The switch is not exhaustive." -): never { - throw new Error(msg) -} diff --git a/src/utils/nullable.ts b/src/utils/nullable.ts deleted file mode 100644 index fca8fdc..0000000 --- a/src/utils/nullable.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const isNotNullish = (value: T): value is NonNullable => - value !== null && value !== undefined