From 5114bdd3a120a36b340a9f7437aed3900b51f8fc Mon Sep 17 00:00:00 2001 From: Julian Mills Date: Fri, 11 Oct 2024 10:16:35 +0200 Subject: [PATCH] refactor: cleanup codebase --- biome.json | 13 ++++++++++++- src/data/types/range.ts | 2 +- src/engines/abstract.ts | 9 +-------- src/engines/http.ts | 4 ++-- src/engines/ws.ts | 4 ++-- src/index.ts | 6 +++--- src/surreal.ts | 8 +++----- src/types.ts | 4 ++-- .../{getIncrementalID.ts => get-incremental-id.ts} | 0 src/util/{PreparedQuery.ts => prepared-query.ts} | 0 .../{processAuthVars.ts => process-auth-vars.ts} | 0 src/util/tagged-template.ts | 2 +- src/util/{versionCheck.ts => version-check.ts} | 0 tests/integration/tests/live.test.ts | 1 - tests/integration/tests/querying.test.ts | 2 -- .../{convertAuth.test.ts => convert-auth.test.ts} | 2 +- ...pported.test.ts => is-version-supported.test.ts} | 2 +- 17 files changed, 29 insertions(+), 30 deletions(-) rename src/util/{getIncrementalID.ts => get-incremental-id.ts} (100%) rename src/util/{PreparedQuery.ts => prepared-query.ts} (100%) rename src/util/{processAuthVars.ts => process-auth-vars.ts} (100%) rename src/util/{versionCheck.ts => version-check.ts} (100%) rename tests/unit/{convertAuth.test.ts => convert-auth.test.ts} (95%) rename tests/unit/{isVersionSupported.test.ts => is-version-supported.test.ts} (89%) diff --git a/biome.json b/biome.json index 15fcc306..c560e8e5 100644 --- a/biome.json +++ b/biome.json @@ -9,10 +9,21 @@ "recommended": true, "suspicious": { "noConsoleLog": "error" + }, + "correctness": { + "noUnusedImports": "error" + }, + "style": { + "useFilenamingConvention": { + "level": "error", + "options": { + "filenameCases": ["kebab-case"] + } + } } } }, "files": { - "ignore": ["dist/**"] + "ignore": ["dist/**", "npm/**"] } } diff --git a/src/data/types/range.ts b/src/data/types/range.ts index 69b90a55..725f05c3 100644 --- a/src/data/types/range.ts +++ b/src/data/types/range.ts @@ -1,7 +1,7 @@ import { Tagged } from "../../cbor"; import { SurrealDbError } from "../../errors"; import { toSurrealqlString } from "../../util/to-surrealql-string"; -import { TAG_BOUND_EXCLUDED, TAG_BOUND_INCLUDED, TAG_RANGE } from "../cbor"; +import { TAG_BOUND_EXCLUDED, TAG_BOUND_INCLUDED } from "../cbor"; import { type RecordIdValue, escape_id_part, diff --git a/src/engines/abstract.ts b/src/engines/abstract.ts index 948a60bb..1424d7c3 100644 --- a/src/engines/abstract.ts +++ b/src/engines/abstract.ts @@ -1,12 +1,5 @@ -import type { Encoded } from "../cbor"; import type { EngineDisconnected } from "../errors"; -import type { - LiveAction, - LiveHandlerArguments, - Patch, - RpcRequest, - RpcResponse, -} from "../types"; +import type { LiveHandlerArguments, RpcRequest, RpcResponse } from "../types"; import type { Emitter } from "../util/emitter"; export type Engine = new (context: EngineContext) => AbstractEngine; diff --git a/src/engines/http.ts b/src/engines/http.ts index d3aa54f5..ee23fbfe 100644 --- a/src/engines/http.ts +++ b/src/engines/http.ts @@ -4,8 +4,8 @@ import { MissingNamespaceDatabase, } from "../errors"; import type { RpcRequest, RpcResponse } from "../types"; -import { getIncrementalID } from "../util/getIncrementalID"; -import { retrieveRemoteVersion } from "../util/versionCheck"; +import { getIncrementalID } from "../util/get-incremental-id"; +import { retrieveRemoteVersion } from "../util/version-check"; import { AbstractEngine, ConnectionStatus, diff --git a/src/engines/ws.ts b/src/engines/ws.ts index 4cbd9d7d..7d516b00 100644 --- a/src/engines/ws.ts +++ b/src/engines/ws.ts @@ -7,8 +7,8 @@ import { UnexpectedServerResponse, } from "../errors"; import { type RpcRequest, type RpcResponse, isLiveResult } from "../types"; -import { getIncrementalID } from "../util/getIncrementalID"; -import { retrieveRemoteVersion } from "../util/versionCheck"; +import { getIncrementalID } from "../util/get-incremental-id"; +import { retrieveRemoteVersion } from "../util/version-check"; import { AbstractEngine, ConnectionStatus, diff --git a/src/index.ts b/src/index.ts index 2b6799cf..9af987d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ export { Emitter, type Listener, type UnknownEvents } from "./util/emitter.ts"; export { surql, surrealql } from "./util/tagged-template.ts"; -export { PreparedQuery } from "./util/PreparedQuery.ts"; +export { PreparedQuery } from "./util/prepared-query.ts"; export * as cbor from "./cbor"; export * from "./cbor/gap"; export * from "./cbor/error"; @@ -8,8 +8,8 @@ export * from "./data"; export * from "./errors.ts"; export * from "./types.ts"; export * from "./util/jsonify.ts"; -export * from "./util/versionCheck.ts"; -export * from "./util/getIncrementalID.ts"; +export * from "./util/version-check.ts"; +export * from "./util/get-incremental-id.ts"; export * from "./util/string-prefixes.ts"; export * from "./util/to-surrealql-string.ts"; export { diff --git a/src/surreal.ts b/src/surreal.ts index c566d1aa..d2a221f0 100644 --- a/src/surreal.ts +++ b/src/surreal.ts @@ -13,10 +13,10 @@ import { type EngineEvents, type Engines, } from "./engines/abstract.ts"; -import { PreparedQuery } from "./util/PreparedQuery.ts"; import { Emitter } from "./util/emitter.ts"; -import { processAuthVars } from "./util/processAuthVars.ts"; -import { versionCheck } from "./util/versionCheck.ts"; +import { PreparedQuery } from "./util/prepared-query.ts"; +import { processAuthVars } from "./util/process-auth-vars.ts"; +import { versionCheck } from "./util/version-check.ts"; import { type AccessRecordAuth, @@ -41,8 +41,6 @@ import { WebsocketEngine } from "./engines/ws.ts"; import { EngineDisconnected, NoActiveSocket, - NoDatabaseSpecified, - NoNamespaceSpecified, NoTokenReturned, ResponseError, SurrealDbError, diff --git a/src/types.ts b/src/types.ts index 5f2d5b20..71d95159 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ -import type { Encoded, Fill } from "./cbor"; +import type { Fill } from "./cbor"; import { type RecordId, Uuid } from "./data"; import { SurrealDbError } from "./errors"; -import type { PreparedQuery } from "./util/PreparedQuery"; +import type { PreparedQuery } from "./util/prepared-query"; export type ActionResult> = Prettify< T["id"] extends RecordId ? T : { id: RecordId } & T diff --git a/src/util/getIncrementalID.ts b/src/util/get-incremental-id.ts similarity index 100% rename from src/util/getIncrementalID.ts rename to src/util/get-incremental-id.ts diff --git a/src/util/PreparedQuery.ts b/src/util/prepared-query.ts similarity index 100% rename from src/util/PreparedQuery.ts rename to src/util/prepared-query.ts diff --git a/src/util/processAuthVars.ts b/src/util/process-auth-vars.ts similarity index 100% rename from src/util/processAuthVars.ts rename to src/util/process-auth-vars.ts diff --git a/src/util/tagged-template.ts b/src/util/tagged-template.ts index 97f90155..878d5de7 100644 --- a/src/util/tagged-template.ts +++ b/src/util/tagged-template.ts @@ -1,4 +1,4 @@ -import { PreparedQuery } from "./PreparedQuery.ts"; +import { PreparedQuery } from "./prepared-query.ts"; export function surrealql( query_raw: string[] | TemplateStringsArray, diff --git a/src/util/versionCheck.ts b/src/util/version-check.ts similarity index 100% rename from src/util/versionCheck.ts rename to src/util/version-check.ts diff --git a/tests/integration/tests/live.test.ts b/tests/integration/tests/live.test.ts index 042096b1..bf6a25f7 100644 --- a/tests/integration/tests/live.test.ts +++ b/tests/integration/tests/live.test.ts @@ -1,6 +1,5 @@ import { describe, expect, test } from "bun:test"; import { - type LiveAction, type LiveHandlerArguments, RecordId, ResponseError, diff --git a/tests/integration/tests/querying.test.ts b/tests/integration/tests/querying.test.ts index 86bc269c..16690270 100644 --- a/tests/integration/tests/querying.test.ts +++ b/tests/integration/tests/querying.test.ts @@ -11,8 +11,6 @@ import { StringRecordId, Table, Uuid, - decodeCbor, - encodeCbor, surql, } from "../../../src"; import { diff --git a/tests/unit/convertAuth.test.ts b/tests/unit/convert-auth.test.ts similarity index 95% rename from tests/unit/convertAuth.test.ts rename to tests/unit/convert-auth.test.ts index b53f41bb..88430894 100644 --- a/tests/unit/convertAuth.test.ts +++ b/tests/unit/convert-auth.test.ts @@ -1,5 +1,5 @@ import { expect, test } from "bun:test"; -import { type AnyAuth, convertAuth } from "../../src"; +import { convertAuth } from "../../src"; test("valid", () => { expect(convertAuth({ username: "root", password: "root" })).toStrictEqual({ diff --git a/tests/unit/isVersionSupported.test.ts b/tests/unit/is-version-supported.test.ts similarity index 89% rename from tests/unit/isVersionSupported.test.ts rename to tests/unit/is-version-supported.test.ts index 642236cc..695faa8f 100644 --- a/tests/unit/isVersionSupported.test.ts +++ b/tests/unit/is-version-supported.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test"; -import { isVersionSupported } from "../../src/util/versionCheck.ts"; +import { isVersionSupported } from "../../src/util/version-check.ts"; describe("isVersionSupported", () => { test("1.0.0 should be unsupported", () => {