cursedbelt-server 4.65.0 → 4.65.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server/d1/remote.js
CHANGED
|
@@ -112,12 +112,21 @@ class RemoteStatement {
|
|
|
112
112
|
return new RemoteStatement(this.stmt.bind(...wire), this.sql, this.timing);
|
|
113
113
|
}
|
|
114
114
|
async first(column) {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// Through `all()`: D1's own `first()` answers the row and drops `meta`, so a `first()` was reported on wall time
|
|
116
|
+
// alone and a stall in the queue read as a heavy statement (photos' 0.1 ms `sqlite_master` look at 5.8 s wall,
|
|
117
|
+
// forge task 4686). D1's `first()` is row 0 of this same answer — it never adds a LIMIT — so nothing more is read.
|
|
118
|
+
const res = await timed(this.timing, this.sql, () => this.stmt.all(), (r) => [r.meta]);
|
|
119
|
+
assertSucceeded(res, this.sql);
|
|
120
|
+
const row = (res.results ?? [])[0];
|
|
121
|
+
if (row === undefined || row === null)
|
|
117
122
|
return null;
|
|
118
|
-
if (column
|
|
119
|
-
return
|
|
120
|
-
|
|
123
|
+
if (column === undefined)
|
|
124
|
+
return normalizeRows([row])[0] ?? null;
|
|
125
|
+
// D1's own refusal for a column the row does not have, kept: a typo stays loud.
|
|
126
|
+
if (!(column in row))
|
|
127
|
+
throw new Error(`D1_COLUMN_NOTFOUND: Column not found (${column})`);
|
|
128
|
+
const value = row[column];
|
|
129
|
+
return value === null || value === undefined ? null : normalizeValue(value);
|
|
121
130
|
}
|
|
122
131
|
async all() {
|
|
123
132
|
const res = await timed(this.timing, this.sql, () => this.stmt.all(), (r) => [r.meta]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedbelt-server",
|
|
3
|
-
"version": "4.65.
|
|
3
|
+
"version": "4.65.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The app-facing Bun/Hono server tier of the cursedbelt split — storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
|
|
@@ -429,7 +429,7 @@
|
|
|
429
429
|
"@node-rs/argon2": "^2.0.2",
|
|
430
430
|
"@types/bun": "^1.3.14",
|
|
431
431
|
"@types/node": "^24",
|
|
432
|
-
"cursedbelt": "^5.122.
|
|
432
|
+
"cursedbelt": "^5.122.2",
|
|
433
433
|
"hono": "4.12.28",
|
|
434
434
|
"kysely": "^0.28.17",
|
|
435
435
|
"kysely-bun-sqlite": "^0.4.0",
|
package/src/server/d1/remote.ts
CHANGED
|
@@ -185,10 +185,18 @@ class RemoteStatement implements D1LikeStatement {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
async first<T = D1LikeRow>(column?: string): Promise<T | null> {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
// Through `all()`: D1's own `first()` answers the row and drops `meta`, so a `first()` was reported on wall time
|
|
189
|
+
// alone and a stall in the queue read as a heavy statement (photos' 0.1 ms `sqlite_master` look at 5.8 s wall,
|
|
190
|
+
// forge task 4686). D1's `first()` is row 0 of this same answer — it never adds a LIMIT — so nothing more is read.
|
|
191
|
+
const res = await timed(this.timing, this.sql, () => this.stmt.all(), (r) => [r.meta]);
|
|
192
|
+
assertSucceeded(res, this.sql);
|
|
193
|
+
const row = (res.results ?? [])[0] as Record<string, unknown> | undefined;
|
|
194
|
+
if (row === undefined || row === null) return null;
|
|
195
|
+
if (column === undefined) return normalizeRows<T>([row])[0] ?? null;
|
|
196
|
+
// D1's own refusal for a column the row does not have, kept: a typo stays loud.
|
|
197
|
+
if (!(column in row)) throw new Error(`D1_COLUMN_NOTFOUND: Column not found (${column})`);
|
|
198
|
+
const value = row[column];
|
|
199
|
+
return value === null || value === undefined ? null : (normalizeValue(value) as T);
|
|
192
200
|
}
|
|
193
201
|
|
|
194
202
|
async all<T = D1LikeRow>(): Promise<D1LikeResult<T>> {
|
|
@@ -66,6 +66,16 @@ describe('the remote driver reports a slow or D1-failed statement', () => {
|
|
|
66
66
|
expect(reports.map((r) => [r.event, r.durationMs])).toEqual([['d1.slow', 2500]]);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
it("🔴 a first() carries D1's own time, so a stall on the way is told apart from a heavy statement (forge task 4686)", async () => {
|
|
70
|
+
// photos' `SELECT sql FROM sqlite_master …` read 5769 ms wall with no D1 time, and was filed as a statement about to reset the database.
|
|
71
|
+
const { db, reports } = slowBinding({ ms: 5800, duration: 0.1 });
|
|
72
|
+
expect(await db.prepare('SELECT v FROM t WHERE id = ?').bind(1).first<{ v: string }>()).toEqual({ v: 'a' });
|
|
73
|
+
expect(await db.prepare('SELECT v FROM t WHERE id = ?').bind(2).first<string>('v')).toBe('b');
|
|
74
|
+
expect(await db.prepare('SELECT v FROM t WHERE id = ?').bind(9).first()).toBeNull();
|
|
75
|
+
expect(reports.map((r) => [r.ms, r.durationMs])).toEqual([[5800, 0.1], [5800, 0.1], [5800, 0.1]]);
|
|
76
|
+
await expect(db.prepare('SELECT v FROM t').first('nope')).rejects.toThrow('D1_COLUMN_NOTFOUND');
|
|
77
|
+
});
|
|
78
|
+
|
|
69
79
|
it('a statement D1 reset for CPU is reported as failed, and the error still reaches the caller', async () => {
|
|
70
80
|
const fail = 'D1_ERROR: D1 DB exceeded its CPU time limit and was reset.';
|
|
71
81
|
const { db, reports } = slowBinding({ ms: 34_000, fail });
|