From 77ac62f22a8198608ea6d15b48547cfe2df150fe Mon Sep 17 00:00:00 2001 From: Christian Klotz Date: Wed, 30 Sep 2026 20:10:39 +0100 Subject: [PATCH] refactor(durable): simplify Node SQLite queue and bindings --- packages/durable/src/storage/sqlite/node.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/durable/src/storage/sqlite/node.ts b/packages/durable/src/storage/sqlite/node.ts index 558c1dcfc..74c3cdb1e 100644 --- a/packages/durable/src/storage/sqlite/node.ts +++ b/packages/durable/src/storage/sqlite/node.ts @@ -1,7 +1,7 @@ import { AsyncLocalStorage } from "node:async_hooks"; import { mkdir } from "node:fs/promises"; import { dirname } from "node:path"; -import type { SQLInputValue, StatementSync } from "node:sqlite"; +import type { StatementSync } from "node:sqlite"; import { DatabaseSync } from "node:sqlite"; import type { SqliteDatabase, SqliteExecutor, SqliteValue } from "./database.ts"; import { SqliteStorage } from "./storage.ts"; @@ -24,15 +24,13 @@ class SerialOperationQueue { async run(operation: () => T | Promise): Promise { const previous = this.tail; - let release: () => void; - this.tail = new Promise((resolve) => { - release = resolve; - }); + const { promise, resolve: release } = Promise.withResolvers(); + this.tail = promise; await previous; try { return await operation(); } finally { - release!(); + release(); } } } @@ -58,16 +56,16 @@ abstract class NodeSqliteExecutor implements SqliteExecutor { run(sql: string, ...params: SqliteValue[]): Promise { return this.runOperation(() => { - this.statement(sql).run(...(params as SQLInputValue[])); + this.statement(sql).run(...params); }); } get(sql: string, ...params: SqliteValue[]): Promise { - return this.runOperation(() => this.statement(sql).get(...(params as SQLInputValue[])) as T | undefined); + return this.runOperation(() => this.statement(sql).get(...params) as T | undefined); } all(sql: string, ...params: SqliteValue[]): Promise { - return this.runOperation(() => this.statement(sql).all(...(params as SQLInputValue[])) as T[]); + return this.runOperation(() => this.statement(sql).all(...params) as T[]); } protected abstract runOperation(operation: () => T): Promise;