From a28c6ddeb8eb0f50beff560915daf98e2a5eb158 Mon Sep 17 00:00:00 2001 From: Abdou TOP Date: Fri, 9 Jan 2026 12:14:58 +0000 Subject: [PATCH] fix: resolve circular dependency between api and db by moving Sql type to types package --- api/dev.ts | 2 +- api/router.ts | 2 +- db/mod.ts | 15 +-------------- deno.lock | 5 +++++ types/db.d.ts | 15 +++++++++++++++ types/deno.json | 7 +++++-- 6 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 types/db.d.ts diff --git a/api/dev.ts b/api/dev.ts index 1e200f0..cb7beb0 100644 --- a/api/dev.ts +++ b/api/dev.ts @@ -3,7 +3,7 @@ import { respond } from '@01edu/api/response' import type { RequestContext } from '@01edu/types/context' import { route } from '@01edu/api/router' import { ARR, OBJ, optional, STR } from '@01edu/api/validator' -import type { Sql } from '@01edu/db' +import type { Sql } from '@01edu/types/db' /** * Authorizes access to developer routes. diff --git a/api/router.ts b/api/router.ts index 779313d..583f4b2 100644 --- a/api/router.ts +++ b/api/router.ts @@ -22,7 +22,7 @@ import type { } from '@01edu/types/router' import type { Log } from './log.ts' import { respond, ResponseError } from './response.ts' -import type { Sql } from '@01edu/db' +import type { Sql } from '@01edu/types/db' import { createSqlDevRoute } from './dev.ts' import { createDocRoute } from './doc.ts' diff --git a/db/mod.ts b/db/mod.ts index 60332a8..903402c 100644 --- a/db/mod.ts +++ b/db/mod.ts @@ -14,6 +14,7 @@ import { type RestBindParameters, } from '@db/sqlite' import type { Expand, MatchKeys, UnionToIntersection } from '@01edu/types' +import type { Sql } from '@01edu/types/db' import { respond } from '@01edu/api/response' import { APP_ENV, ENV } from '@01edu/api/env' @@ -403,20 +404,6 @@ export const createTable = ( } } -/** - * Type definition for the `sql` template tag function. - * It allows executing SQL queries with parameter binding and retrieving results in various formats. - */ -export type Sql = < - T extends { [k in string]: unknown } | undefined, - P extends BindValue | BindParameters | undefined, ->(sqlArr: TemplateStringsArray, ...vars: unknown[]) => { - get: (params?: P) => T | undefined - all: (params?: P) => T[] - run: (params?: P) => void - value: (params?: P) => T[keyof T][] | undefined -} - /** * A template literal tag for executing arbitrary SQL queries. * diff --git a/deno.lock b/deno.lock index 012722d..09ac5ed 100644 --- a/deno.lock +++ b/deno.lock @@ -1081,6 +1081,11 @@ "npm:@preact/signals@^2.5.1", "npm:preact@^10.27.2" ] + }, + "types": { + "dependencies": [ + "jsr:@db/sqlite@0.13" + ] } } } diff --git a/types/db.d.ts b/types/db.d.ts new file mode 100644 index 0000000..f66183a --- /dev/null +++ b/types/db.d.ts @@ -0,0 +1,15 @@ +import type { BindParameters, BindValue } from '@db/sqlite' + +/** + * Type definition for the `sql` template tag function. + * It allows executing SQL queries with parameter binding and retrieving results in various formats. + */ +export type Sql = < + T extends { [k in string]: unknown } | undefined, + P extends BindValue | BindParameters | undefined, +>(sqlArr: TemplateStringsArray, ...vars: unknown[]) => { + get: (params?: P) => T | undefined + all: (params?: P) => T[] + run: (params?: P) => void + value: (params?: P) => T[keyof T][] | undefined +} diff --git a/types/deno.json b/types/deno.json index 3d5e77d..5dbbd20 100644 --- a/types/deno.json +++ b/types/deno.json @@ -1,11 +1,14 @@ { - "imports": {}, + "imports": { + "@db/sqlite": "jsr:@db/sqlite@^0.13.0" + }, "name": "@01edu/types", - "version": "0.1.3", + "version": "0.1.4", "license": "MIT", "exports": { ".": "./mod.d.ts", "./context": "./context.d.ts", + "./db": "./db.d.ts", "./router": "./router.d.ts", "./validator": "./validator.d.ts" }