Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(db): pass the chunk size and the abort options through the NUL-free connection

Mauricedd98469a02c2
diff --git a/server/src/db/nul-free.ts b/server/src/db/nul-free.ts
index 8f7384866..32f1a770c 100644
--- a/server/src/db/nul-free.ts
+++ b/server/src/db/nul-free.ts
@@ -1,4 +1,4 @@
-import type { CompiledQuery, DatabaseConnection, Dialect, Driver } from 'kysely';
+import type { AbortableOperationOptions, CompiledQuery, DatabaseConnection, Dialect, Driver } from 'kysely';
/**
* TREK stores no U+0000 (NUL) in text, on either engine.
@@ -87,9 +87,10 @@ function nulFreeDriver(driver: Driver): Driver {
let proxy = wrapped.get(connection);
if (!proxy) {
proxy = overriding(connection, {
- executeQuery: <R>(query: CompiledQuery) => connection.executeQuery<R>(nulFreeQuery(query)),
- streamQuery: <R>(query: CompiledQuery, chunkSize?: number) =>
- connection.streamQuery<R>(nulFreeQuery(query), chunkSize),
+ executeQuery: <R>(query: CompiledQuery, options?: AbortableOperationOptions) =>
+ connection.executeQuery<R>(nulFreeQuery(query), options),
+ streamQuery: <R>(query: CompiledQuery, chunkSize: number, options?: AbortableOperationOptions) =>
+ connection.streamQuery<R>(nulFreeQuery(query), chunkSize, options),
});
wrapped.set(connection, proxy);
}
diff --git a/server/tests/unit/db/nul-free.test.ts b/server/tests/unit/db/nul-free.test.ts
index 56655ebe4..311a99293 100644
--- a/server/tests/unit/db/nul-free.test.ts
+++ b/server/tests/unit/db/nul-free.test.ts
@@ -9,6 +9,7 @@ import { TrekPostgreSqlPlatform } from '../../../src/db/engine/postgres/postgres
import { nulFreeJson, nulFreeParameter, stripNul, withNulFreeParameters } from '../../../src/db/nul-free';
import {
+ type AbortableOperationOptions,
CompiledQuery,
type DatabaseConnection,
type Dialect,
@@ -25,17 +26,25 @@ const RELEASE = Symbol('release');
/** A connection that records what it was sent and keeps a private release, like Kysely's Postgres one. */
class RecordingConnection implements DatabaseConnection {
readonly sent: CompiledQuery[] = [];
+ /** What came with each query besides itself: the chunk size of a stream, the abort options. */
+ readonly extras: unknown[][] = [];
released = false;
#open = true;
- async executeQuery<R>(query: CompiledQuery): Promise<QueryResult<R>> {
+ async executeQuery<R>(query: CompiledQuery, options?: AbortableOperationOptions): Promise<QueryResult<R>> {
if (!this.#open) throw new Error('closed');
this.sent.push(query);
+ this.extras.push([options]);
return { rows: [] };
}
- async *streamQuery<R>(query: CompiledQuery): AsyncIterableIterator<QueryResult<R>> {
+ async *streamQuery<R>(
+ query: CompiledQuery,
+ chunkSize: number,
+ options?: AbortableOperationOptions,
+ ): AsyncIterableIterator<QueryResult<R>> {
this.sent.push(query);
+ this.extras.push([chunkSize, options]);
yield { rows: [] };
}
@@ -120,6 +129,20 @@ describe('NUL-free values', () => {
expect(connection.released).toBe(true);
});
+ it('NULFREE-005: the chunk size of a stream and the abort options reach the connection as they were given', async () => {
+ const connection = new RecordingConnection();
+ const acquired = await withNulFreeParameters(recordingDialect(connection)).createDriver().acquireConnection();
+ const options: AbortableOperationOptions = { signal: new AbortController().signal };
+
+ await acquired.executeQuery(CompiledQuery.raw('select ?', ['a\u0000']), options);
+ for await (const chunk of acquired.streamQuery(CompiledQuery.raw('select 1'), 25, options)) {
+ expect(chunk.rows).toEqual([]);
+ }
+ expect(connection.extras).toEqual([[options], [25, options]]);
+ expect(connection.extras[0][0]).toBe(options);
+ expect(connection.extras[1][1]).toBe(options);
+ });
+
it('NULFREE-004: the Postgres platform inlines strings and serializes JSON without NUL', () => {
const platform = new TrekPostgreSqlPlatform();
expect(platform.escape("o\u0000'k")).toBe("'o''k'");