feat: add async SQLite on Node 24 and improve messaging diagnostics (#520)
Move database work off the main thread on Node.js 24 and improve message handling and runtime diagnostics. Preserve migration, restart, and concurrency coverage with the async SQLite driver.
This commit is contained in:
1 parent
20f48d11ec
commit
c7428363cb
170 files changed
+7748
-3913
No files matched your search
@@ -86,5 +86,8 @@
|
||||
"@zxcvbn-ts/core": "^4.1.2",
|
||||
"@zxcvbn-ts/language-common": "^4.1.3",
|
||||
"@zxcvbn-ts/language-en": "^4.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { isObject } from './coerce';
|
||||
|
||||
export interface RuntimeConfig {
|
||||
webuiPort?: number;
|
||||
@@ -395,10 +396,6 @@ function parseBoolValue(raw: unknown): boolean | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isObject(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function isErrnoCode(error: unknown, code: string): boolean {
|
||||
return error instanceof Error && 'code' in error && error.code === code;
|
||||
}
|
||||
@@ -71,18 +71,17 @@ export class SingleFlightCache<K, V> {
|
||||
}
|
||||
|
||||
const task = (async () => {
|
||||
try {
|
||||
const value = await this.load(key);
|
||||
const value = await this.load(key);
|
||||
|
||||
if (this.shouldCache(value)) {
|
||||
this.fresh.set(key, { at: this.now(), value });
|
||||
}
|
||||
|
||||
return value;
|
||||
} finally {
|
||||
this.inflight.delete(key);
|
||||
if (this.shouldCache(value)) {
|
||||
this.fresh.set(key, { at: this.now(), value });
|
||||
}
|
||||
})();
|
||||
|
||||
return value;
|
||||
})().finally(() => {
|
||||
// Run after registration even when load throws synchronously.
|
||||
this.inflight.delete(key);
|
||||
});
|
||||
this.inflight.set(key, task);
|
||||
return task;
|
||||
}
|
||||
|
||||
@@ -147,4 +147,18 @@ describe('SingleFlightCache', () => {
|
||||
await cache.get('b');
|
||||
expect(load).toHaveBeenCalledTimes(5);
|
||||
});
|
||||
|
||||
it('allows retry when a loader throws before returning its promise', async () => {
|
||||
const load = vi
|
||||
.fn<() => Promise<string>>()
|
||||
.mockImplementationOnce(() => {
|
||||
throw new Error('failed before request');
|
||||
})
|
||||
.mockResolvedValue('recovered');
|
||||
const cache = createSingleFlightCache({ ttlMs: 1000, load });
|
||||
|
||||
await expect(cache.get('key')).rejects.toThrow('failed before request');
|
||||
await expect(cache.get('key')).resolves.toBe('recovered');
|
||||
expect(load).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user