rivetkit 3.1.2-rc.2 → 3.1.2-rc.3
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/browser/client.d.ts +2 -16
- package/dist/browser/client.js +9 -1
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-MRWI2HTU.js → chunk-2BXN54R4.js} +2 -2
- package/dist/tsup/{chunk-N2SQDK2F.js → chunk-3ALVCHXR.js} +3 -3
- package/dist/tsup/{chunk-LBYX466L.cjs → chunk-6ANYUVLS.cjs} +3 -3
- package/dist/tsup/{chunk-LBYX466L.cjs.map → chunk-6ANYUVLS.cjs.map} +1 -1
- package/dist/tsup/{chunk-I6P2AHO6.js → chunk-6S73EWWS.js} +2 -2
- package/dist/tsup/{chunk-L2XH4EXJ.cjs → chunk-6YDPLY6F.cjs} +155 -147
- package/dist/tsup/chunk-6YDPLY6F.cjs.map +1 -0
- package/dist/tsup/{chunk-QJ7MIAFD.cjs → chunk-C2I4CPLD.cjs} +7 -7
- package/dist/tsup/{chunk-QJ7MIAFD.cjs.map → chunk-C2I4CPLD.cjs.map} +1 -1
- package/dist/tsup/{chunk-YAGP66QF.cjs → chunk-JK62DI4K.cjs} +4 -4
- package/dist/tsup/{chunk-YAGP66QF.cjs.map → chunk-JK62DI4K.cjs.map} +1 -1
- package/dist/tsup/{chunk-6BGQCMIF.cjs → chunk-MJCM3IZN.cjs} +3 -3
- package/dist/tsup/{chunk-6BGQCMIF.cjs.map → chunk-MJCM3IZN.cjs.map} +1 -1
- package/dist/tsup/{chunk-DDF35AIK.cjs → chunk-MJWDZ4CU.cjs} +2 -2
- package/dist/tsup/{chunk-DDF35AIK.cjs.map → chunk-MJWDZ4CU.cjs.map} +1 -1
- package/dist/tsup/{chunk-TAK6KRMJ.cjs → chunk-P57K5DTD.cjs} +3 -3
- package/dist/tsup/{chunk-TAK6KRMJ.cjs.map → chunk-P57K5DTD.cjs.map} +1 -1
- package/dist/tsup/{chunk-MVOIZGVC.js → chunk-POKN6RC5.js} +2 -2
- package/dist/tsup/{chunk-MVOIZGVC.js.map → chunk-POKN6RC5.js.map} +1 -1
- package/dist/tsup/{chunk-JGMXY4GD.js → chunk-WCVT6UXF.js} +14 -6
- package/dist/tsup/chunk-WCVT6UXF.js.map +1 -0
- package/dist/tsup/{chunk-6MJSWO33.js → chunk-WJSHEWTP.js} +4 -4
- package/dist/tsup/{chunk-A3N3LJC6.cjs → chunk-X4HPTBGP.cjs} +10 -10
- package/dist/tsup/{chunk-A3N3LJC6.cjs.map → chunk-X4HPTBGP.cjs.map} +1 -1
- package/dist/tsup/{chunk-D2CCGHEJ.js → chunk-YXBMGSYD.js} +2 -2
- package/dist/tsup/{chunk-6NHRZU52.js → chunk-ZWLSBELO.js} +2 -2
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +4 -4
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-BMGUEKMZ.d.cts → config-BbRMYCV8.d.cts} +2 -16
- package/dist/tsup/{config-iBpXyITj.d.ts → config-CW3AWqHa.d.ts} +2 -16
- package/dist/tsup/{context-hyVakgnU.d.ts → context-Cp64yaMW.d.ts} +1 -1
- package/dist/tsup/{context-qfvLuF0P.d.cts → context-NuwP8HjQ.d.cts} +1 -1
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +1 -1
- package/dist/tsup/dynamic/mod.d.ts +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +2 -2
- package/dist/tsup/inspector-tab/mod.d.ts +2 -2
- package/dist/tsup/mod.cjs +127 -391
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +3 -3
- package/dist/tsup/mod.d.ts +3 -3
- package/dist/tsup/mod.js +46 -310
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +4 -4
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +7 -7
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +9 -9
- package/src/client/lifecycle-errors.ts +15 -0
- package/src/common/database/config.ts +0 -52
- package/src/common/database/native-database.ts +18 -229
- package/src/registry/config/index.ts +3 -1
- package/src/registry/index.ts +15 -14
- package/src/registry/napi-runtime.ts +2 -81
- package/src/registry/native.ts +17 -66
- package/src/registry/runtime.ts +2 -53
- package/src/registry/wasm-runtime.ts +0 -88
- package/dist/tsup/chunk-JGMXY4GD.js.map +0 -1
- package/dist/tsup/chunk-L2XH4EXJ.cjs.map +0 -1
- /package/dist/tsup/{chunk-MRWI2HTU.js.map → chunk-2BXN54R4.js.map} +0 -0
- /package/dist/tsup/{chunk-N2SQDK2F.js.map → chunk-3ALVCHXR.js.map} +0 -0
- /package/dist/tsup/{chunk-I6P2AHO6.js.map → chunk-6S73EWWS.js.map} +0 -0
- /package/dist/tsup/{chunk-6MJSWO33.js.map → chunk-WJSHEWTP.js.map} +0 -0
- /package/dist/tsup/{chunk-D2CCGHEJ.js.map → chunk-YXBMGSYD.js.map} +0 -0
- /package/dist/tsup/{chunk-6NHRZU52.js.map → chunk-ZWLSBELO.js.map} +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { decodeBridgeRivetError } from "@/actor/errors";
|
|
2
2
|
import type {
|
|
3
|
-
DeferredSqliteDatabase,
|
|
4
3
|
SqliteBatchStatement,
|
|
5
4
|
SqliteBindings,
|
|
5
|
+
SqliteDatabase,
|
|
6
6
|
SqliteExecuteResult,
|
|
7
7
|
SqliteNativeMetrics,
|
|
8
8
|
SqliteTransactionDatabase,
|
|
9
|
-
SynchronousSqliteTransactionDatabase,
|
|
10
9
|
} from "./config";
|
|
11
10
|
|
|
12
11
|
// Matches the name core uses for the transaction behind a native executeBatch call.
|
|
@@ -78,15 +77,10 @@ interface NativeBatchStatement {
|
|
|
78
77
|
|
|
79
78
|
export interface JsNativeDatabaseLike {
|
|
80
79
|
exec(sql: string): Promise<NativeExecResult>;
|
|
81
|
-
execSync(sql: string): NativeExecResult;
|
|
82
80
|
execute(
|
|
83
81
|
sql: string,
|
|
84
82
|
params?: NativeBindParam[] | null,
|
|
85
83
|
): Promise<NativeExecuteResult>;
|
|
86
|
-
executeSync(
|
|
87
|
-
sql: string,
|
|
88
|
-
params?: NativeBindParam[] | null,
|
|
89
|
-
): NativeExecuteResult;
|
|
90
84
|
executeBatch?(
|
|
91
85
|
statements: NativeBatchStatement[],
|
|
92
86
|
): Promise<NativeExecuteResult[]>;
|
|
@@ -99,10 +93,6 @@ export interface JsNativeDatabaseLike {
|
|
|
99
93
|
timeoutMs?: number,
|
|
100
94
|
name?: string,
|
|
101
95
|
): Promise<JsNativeTransactionLike>;
|
|
102
|
-
beginTransactionSync(
|
|
103
|
-
timeoutMs?: number,
|
|
104
|
-
name?: string,
|
|
105
|
-
): JsNativeSynchronousTransactionLike;
|
|
106
96
|
query(
|
|
107
97
|
sql: string,
|
|
108
98
|
params?: NativeBindParam[] | null,
|
|
@@ -113,14 +103,9 @@ export interface JsNativeDatabaseLike {
|
|
|
113
103
|
): Promise<NativeRunResult>;
|
|
114
104
|
metrics?(): SqliteNativeMetrics | null;
|
|
115
105
|
takeLastKvError?(): string | null;
|
|
116
|
-
open(): Promise<void>;
|
|
117
|
-
commitTicket(): number;
|
|
118
|
-
whenDurable(ticket: number): Promise<void>;
|
|
119
|
-
abortGeneration(reason: string): void;
|
|
120
106
|
close(): Promise<void>;
|
|
121
107
|
}
|
|
122
|
-
export type StateAwareSqliteDatabase =
|
|
123
|
-
open(): Promise<void>;
|
|
108
|
+
export type StateAwareSqliteDatabase = SqliteDatabase & {
|
|
124
109
|
beginStateTransaction(
|
|
125
110
|
timeoutMs?: number,
|
|
126
111
|
context?: unknown,
|
|
@@ -143,28 +128,6 @@ export interface JsNativeTransactionLike {
|
|
|
143
128
|
rollback(): Promise<void>;
|
|
144
129
|
}
|
|
145
130
|
|
|
146
|
-
export interface JsNativeSynchronousTransactionLike
|
|
147
|
-
extends JsNativeTransactionLike {
|
|
148
|
-
execSync(sql: string): NativeExecResult;
|
|
149
|
-
executeSync(
|
|
150
|
-
sql: string,
|
|
151
|
-
params?: NativeBindParam[] | null,
|
|
152
|
-
): NativeExecuteResult;
|
|
153
|
-
commitSync(): void;
|
|
154
|
-
rollbackSync(): void;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function isSynchronousTransaction(
|
|
158
|
-
transaction: JsNativeTransactionLike,
|
|
159
|
-
): transaction is JsNativeSynchronousTransactionLike {
|
|
160
|
-
const candidate =
|
|
161
|
-
transaction as Partial<JsNativeSynchronousTransactionLike>;
|
|
162
|
-
return (
|
|
163
|
-
typeof candidate.commitSync === "function" &&
|
|
164
|
-
typeof candidate.rollbackSync === "function"
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
131
|
function shouldAttachNativeKvError(message: string): boolean {
|
|
169
132
|
return /i\/o error|unable to open database file/i.test(message);
|
|
170
133
|
}
|
|
@@ -204,16 +167,6 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
204
167
|
return { kind: "null" };
|
|
205
168
|
}
|
|
206
169
|
if (typeof arg === "bigint") {
|
|
207
|
-
// Integers cross to native code as JavaScript numbers, which round a bigint past the
|
|
208
|
-
// safe range. Refuse instead of writing a different value.
|
|
209
|
-
if (
|
|
210
|
-
arg > BigInt(Number.MAX_SAFE_INTEGER) ||
|
|
211
|
-
arg < BigInt(Number.MIN_SAFE_INTEGER)
|
|
212
|
-
) {
|
|
213
|
-
throw new RangeError(
|
|
214
|
-
"SQLite bigint bindings must be within the JavaScript safe integer range.",
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
170
|
return { kind: "int", intValue: Number(arg) };
|
|
218
171
|
}
|
|
219
172
|
if (typeof arg === "number") {
|
|
@@ -237,13 +190,9 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
237
190
|
function extractNamedSqliteParameters(sql: string): string[] {
|
|
238
191
|
const orderedNames: string[] = [];
|
|
239
192
|
const seen = new Set<string>();
|
|
240
|
-
|
|
241
|
-
// whole identifiers so their suffixes cannot be mistaken for parameters.
|
|
242
|
-
const pattern =
|
|
243
|
-
/'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|([:@$][\w$\u0080-\u{10FFFF}]+(?:::[\w$\u0080-\u{10FFFF}]+)*(?:\([^)]*\))?)|[A-Za-z_\u0080-\u{10FFFF}][\w$\u0080-\u{10FFFF}]*/gu;
|
|
193
|
+
const pattern = /([:@$][A-Za-z_][A-Za-z0-9_]*)/g;
|
|
244
194
|
for (const match of sql.matchAll(pattern)) {
|
|
245
195
|
const name = match[1];
|
|
246
|
-
if (!name) continue;
|
|
247
196
|
if (seen.has(name)) {
|
|
248
197
|
continue;
|
|
249
198
|
}
|
|
@@ -397,49 +346,21 @@ export function wrapJsNativeDatabase(
|
|
|
397
346
|
sql: string,
|
|
398
347
|
params?: SqliteBindings,
|
|
399
348
|
): Promise<SqliteExecuteResult> => {
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
lastInsertRowId,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const nativeParams = toNativeBindings(sql, params);
|
|
413
|
-
const result = await database.execute(sql, nativeParams);
|
|
414
|
-
if (result.lastInsertRowId != null) {
|
|
415
|
-
lastInsertRowId = result.lastInsertRowId;
|
|
416
|
-
}
|
|
417
|
-
return result;
|
|
418
|
-
} catch (error) {
|
|
419
|
-
enrichNativeDatabaseError(database, error);
|
|
420
|
-
} finally {
|
|
421
|
-
release();
|
|
349
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
350
|
+
if (lastInsertRowIdColumn) {
|
|
351
|
+
return {
|
|
352
|
+
columns: [lastInsertRowIdColumn],
|
|
353
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
354
|
+
changes: 0,
|
|
355
|
+
lastInsertRowId,
|
|
356
|
+
};
|
|
422
357
|
}
|
|
423
|
-
|
|
424
|
-
const executeNativeSync = (
|
|
425
|
-
sql: string,
|
|
426
|
-
params?: SqliteBindings,
|
|
427
|
-
): SqliteExecuteResult => {
|
|
358
|
+
|
|
428
359
|
const release = gate.enter();
|
|
429
360
|
try {
|
|
430
361
|
const nativeParams = toNativeBindings(sql, params);
|
|
431
|
-
const result = database.
|
|
432
|
-
|
|
433
|
-
const rowIdColumn = lastInsertRowIdColumnName(sql);
|
|
434
|
-
if (rowIdColumn) {
|
|
435
|
-
return {
|
|
436
|
-
columns: [rowIdColumn],
|
|
437
|
-
rows: [[lastInsertRowId ?? 0]],
|
|
438
|
-
changes: 0,
|
|
439
|
-
lastInsertRowId,
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
if (result.lastInsertRowId != null) {
|
|
362
|
+
const result = await database.execute(sql, nativeParams);
|
|
363
|
+
if (result.lastInsertRowId !== undefined) {
|
|
443
364
|
lastInsertRowId = result.lastInsertRowId;
|
|
444
365
|
}
|
|
445
366
|
return result;
|
|
@@ -471,34 +392,12 @@ export function wrapJsNativeDatabase(
|
|
|
471
392
|
callback(row, result.columns);
|
|
472
393
|
}
|
|
473
394
|
},
|
|
474
|
-
execSync(
|
|
475
|
-
sql: string,
|
|
476
|
-
callback?: (row: unknown[], columns: string[]) => void,
|
|
477
|
-
): void {
|
|
478
|
-
const release = gate.enter();
|
|
479
|
-
let result: NativeExecResult;
|
|
480
|
-
try {
|
|
481
|
-
result = database.execSync(sql);
|
|
482
|
-
} catch (error) {
|
|
483
|
-
enrichNativeDatabaseError(database, error);
|
|
484
|
-
} finally {
|
|
485
|
-
release();
|
|
486
|
-
}
|
|
487
|
-
if (callback) {
|
|
488
|
-
for (const row of result.rows) {
|
|
489
|
-
callback(row, result.columns);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
},
|
|
493
395
|
async execute(
|
|
494
396
|
sql: string,
|
|
495
397
|
params?: SqliteBindings,
|
|
496
398
|
): Promise<SqliteExecuteResult> {
|
|
497
399
|
return await executeNative(sql, params);
|
|
498
400
|
},
|
|
499
|
-
executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult {
|
|
500
|
-
return executeNativeSync(sql, params);
|
|
501
|
-
},
|
|
502
401
|
async executeBatch(
|
|
503
402
|
statements: SqliteBatchStatement[],
|
|
504
403
|
): Promise<SqliteExecuteResult[]> {
|
|
@@ -528,7 +427,7 @@ export function wrapJsNativeDatabase(
|
|
|
528
427
|
return transactionResults;
|
|
529
428
|
})();
|
|
530
429
|
for (const result of results) {
|
|
531
|
-
if (result.lastInsertRowId
|
|
430
|
+
if (result.lastInsertRowId !== undefined) {
|
|
532
431
|
lastInsertRowId = result.lastInsertRowId;
|
|
533
432
|
}
|
|
534
433
|
}
|
|
@@ -560,26 +459,7 @@ export function wrapJsNativeDatabase(
|
|
|
560
459
|
release();
|
|
561
460
|
}
|
|
562
461
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
563
|
-
if (result.lastInsertRowId
|
|
564
|
-
lastInsertRowId = result.lastInsertRowId;
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
},
|
|
568
|
-
beginTransactionSync(
|
|
569
|
-
timeoutMs?: number,
|
|
570
|
-
name?: string,
|
|
571
|
-
): SynchronousSqliteTransactionDatabase {
|
|
572
|
-
const release = gate.enter();
|
|
573
|
-
let transaction: JsNativeSynchronousTransactionLike;
|
|
574
|
-
try {
|
|
575
|
-
transaction = database.beginTransactionSync(timeoutMs, name);
|
|
576
|
-
} catch (error) {
|
|
577
|
-
enrichNativeDatabaseError(database, error);
|
|
578
|
-
} finally {
|
|
579
|
-
release();
|
|
580
|
-
}
|
|
581
|
-
return wrapTransaction(database, transaction, gate, (result) => {
|
|
582
|
-
if (result.lastInsertRowId != null) {
|
|
462
|
+
if (result.lastInsertRowId !== undefined) {
|
|
583
463
|
lastInsertRowId = result.lastInsertRowId;
|
|
584
464
|
}
|
|
585
465
|
});
|
|
@@ -606,7 +486,7 @@ export function wrapJsNativeDatabase(
|
|
|
606
486
|
release();
|
|
607
487
|
}
|
|
608
488
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
609
|
-
if (result.lastInsertRowId
|
|
489
|
+
if (result.lastInsertRowId !== undefined) {
|
|
610
490
|
lastInsertRowId = result.lastInsertRowId;
|
|
611
491
|
}
|
|
612
492
|
});
|
|
@@ -621,25 +501,6 @@ export function wrapJsNativeDatabase(
|
|
|
621
501
|
nativeMetrics(): SqliteNativeMetrics | null {
|
|
622
502
|
return normalizeNativeMetrics(database.metrics?.());
|
|
623
503
|
},
|
|
624
|
-
async open(): Promise<void> {
|
|
625
|
-
const release = gate.enter();
|
|
626
|
-
try {
|
|
627
|
-
await database.open();
|
|
628
|
-
} catch (error) {
|
|
629
|
-
enrichNativeDatabaseError(database, error);
|
|
630
|
-
} finally {
|
|
631
|
-
release();
|
|
632
|
-
}
|
|
633
|
-
},
|
|
634
|
-
commitTicket(): number {
|
|
635
|
-
return database.commitTicket();
|
|
636
|
-
},
|
|
637
|
-
async whenDurable(ticket: number): Promise<void> {
|
|
638
|
-
await database.whenDurable(ticket);
|
|
639
|
-
},
|
|
640
|
-
abortGeneration(reason: string): void {
|
|
641
|
-
database.abortGeneration(reason);
|
|
642
|
-
},
|
|
643
504
|
async close(): Promise<void> {
|
|
644
505
|
terminalPromise ??= gate.close(() => database.close());
|
|
645
506
|
await terminalPromise;
|
|
@@ -651,25 +512,13 @@ export function wrapJsNativeDatabase(
|
|
|
651
512
|
};
|
|
652
513
|
}
|
|
653
514
|
|
|
654
|
-
function wrapTransaction(
|
|
655
|
-
database: JsNativeDatabaseLike,
|
|
656
|
-
transaction: JsNativeSynchronousTransactionLike,
|
|
657
|
-
gate: NativeCloseGate,
|
|
658
|
-
onExecute: (result: NativeExecuteResult) => void,
|
|
659
|
-
): SynchronousSqliteTransactionDatabase;
|
|
660
|
-
function wrapTransaction(
|
|
661
|
-
database: JsNativeDatabaseLike,
|
|
662
|
-
transaction: JsNativeTransactionLike,
|
|
663
|
-
gate: NativeCloseGate,
|
|
664
|
-
onExecute: (result: NativeExecuteResult) => void,
|
|
665
|
-
): SqliteTransactionDatabase;
|
|
666
515
|
function wrapTransaction(
|
|
667
516
|
database: JsNativeDatabaseLike,
|
|
668
517
|
transaction: JsNativeTransactionLike,
|
|
669
518
|
gate: NativeCloseGate,
|
|
670
519
|
onExecute: (result: NativeExecuteResult) => void,
|
|
671
520
|
): SqliteTransactionDatabase {
|
|
672
|
-
|
|
521
|
+
return {
|
|
673
522
|
async exec(sql, callback) {
|
|
674
523
|
const release = gate.enter();
|
|
675
524
|
let result: NativeExecResult;
|
|
@@ -720,66 +569,6 @@ function wrapTransaction(
|
|
|
720
569
|
}
|
|
721
570
|
},
|
|
722
571
|
};
|
|
723
|
-
|
|
724
|
-
if (isSynchronousTransaction(transaction)) {
|
|
725
|
-
return Object.assign(wrapped, {
|
|
726
|
-
execSync(
|
|
727
|
-
sql: string,
|
|
728
|
-
callback?: (row: unknown[], columns: string[]) => void,
|
|
729
|
-
) {
|
|
730
|
-
const release = gate.enter();
|
|
731
|
-
let result: NativeExecResult;
|
|
732
|
-
try {
|
|
733
|
-
result = transaction.execSync(sql);
|
|
734
|
-
} catch (error) {
|
|
735
|
-
enrichNativeDatabaseError(database, error);
|
|
736
|
-
} finally {
|
|
737
|
-
release();
|
|
738
|
-
}
|
|
739
|
-
if (callback) {
|
|
740
|
-
for (const row of result.rows)
|
|
741
|
-
callback(row, result.columns);
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
executeSync(sql: string, params?: SqliteBindings) {
|
|
745
|
-
const release = gate.enter();
|
|
746
|
-
try {
|
|
747
|
-
const result = transaction.executeSync(
|
|
748
|
-
sql,
|
|
749
|
-
toNativeBindings(sql, params),
|
|
750
|
-
);
|
|
751
|
-
onExecute(result);
|
|
752
|
-
return result;
|
|
753
|
-
} catch (error) {
|
|
754
|
-
enrichNativeDatabaseError(database, error);
|
|
755
|
-
} finally {
|
|
756
|
-
release();
|
|
757
|
-
}
|
|
758
|
-
},
|
|
759
|
-
commitSync() {
|
|
760
|
-
const release = gate.enter();
|
|
761
|
-
try {
|
|
762
|
-
transaction.commitSync();
|
|
763
|
-
} catch (error) {
|
|
764
|
-
enrichNativeDatabaseError(database, error);
|
|
765
|
-
} finally {
|
|
766
|
-
release();
|
|
767
|
-
}
|
|
768
|
-
},
|
|
769
|
-
rollbackSync() {
|
|
770
|
-
const release = gate.enter();
|
|
771
|
-
try {
|
|
772
|
-
transaction.rollbackSync();
|
|
773
|
-
} catch (error) {
|
|
774
|
-
enrichNativeDatabaseError(database, error);
|
|
775
|
-
} finally {
|
|
776
|
-
release();
|
|
777
|
-
}
|
|
778
|
-
},
|
|
779
|
-
}) as SynchronousSqliteTransactionDatabase;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
return wrapped;
|
|
783
572
|
}
|
|
784
573
|
|
|
785
574
|
function lastInsertRowIdColumnName(sql: string): string | undefined {
|
|
@@ -289,7 +289,9 @@ export const RegistryConfigSchema = z
|
|
|
289
289
|
/**
|
|
290
290
|
* Wait this many milliseconds for the serve promise to resolve
|
|
291
291
|
* after calling `CoreRegistry::shutdown()`. Defaults to the
|
|
292
|
-
* engine
|
|
292
|
+
* engine's shutdown budget once the node connects: the pool's
|
|
293
|
+
* eviction delay and period, over which it stops the node's actors,
|
|
294
|
+
* plus the time each actor is given to stop. A
|
|
293
295
|
* signal-driven shutdown of a managed local development engine waits
|
|
294
296
|
* four seconds by default so actors can acknowledge stopping before
|
|
295
297
|
* a file watcher restarts the process.
|
package/src/registry/index.ts
CHANGED
|
@@ -39,9 +39,10 @@ const LOCAL_ENGINE_READY_TIMEOUT_MS = 60_000;
|
|
|
39
39
|
// reports. Leave time to close the node connection after that, while staying
|
|
40
40
|
// below the five-second force-kill ceiling used by tsx watch.
|
|
41
41
|
const LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS = 4_000;
|
|
42
|
-
// Matches the engine's default
|
|
43
|
-
//
|
|
44
|
-
|
|
42
|
+
// Matches the engine's default shutdown budget: a pool without an eviction delay or period,
|
|
43
|
+
// plus the default `pegboard.actor_stop_threshold`. Used only when the node has not received
|
|
44
|
+
// the engine's advertised budget before shutdown begins.
|
|
45
|
+
const DEFAULT_SHUTDOWN_BUDGET_MS = 30_000;
|
|
45
46
|
|
|
46
47
|
// Serverless is disabled for v3; keep the implementation for a later release.
|
|
47
48
|
function rejectServerless(): void {
|
|
@@ -823,13 +824,14 @@ export class Registry<A extends RegistryActors> {
|
|
|
823
824
|
if (gracePeriodMs === undefined) {
|
|
824
825
|
gracePeriodMs = localDevSignal
|
|
825
826
|
? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS
|
|
826
|
-
: ((await this.#
|
|
827
|
+
: ((await this.#shutdownBudgetMs(
|
|
827
828
|
modeAPromise ?? modeBPromise,
|
|
828
|
-
)) ??
|
|
829
|
+
)) ?? DEFAULT_SHUTDOWN_BUDGET_MS);
|
|
829
830
|
}
|
|
830
831
|
// Race the entire drain sequence (both modes + serve promise) against
|
|
831
832
|
// a single grace ceiling. Local dev signal shutdowns allow the watcher
|
|
832
|
-
// to restart promptly; other shutdowns use the engine's
|
|
833
|
+
// to restart promptly; other shutdowns use the engine's shutdown budget, its drain
|
|
834
|
+
// period plus its actor stop threshold.
|
|
833
835
|
const drain = async () => {
|
|
834
836
|
// Shut down every live `CoreRegistry` we know about. Mode A
|
|
835
837
|
// (`start()`) and Mode B (`handler()`) each build a separate
|
|
@@ -892,7 +894,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
892
894
|
);
|
|
893
895
|
}
|
|
894
896
|
|
|
895
|
-
async #
|
|
897
|
+
async #shutdownBudgetMs(
|
|
896
898
|
configuredRegistryPromise:
|
|
897
899
|
| ReturnType<typeof buildConfiguredRegistry>
|
|
898
900
|
| undefined,
|
|
@@ -900,19 +902,18 @@ export class Registry<A extends RegistryActors> {
|
|
|
900
902
|
if (configuredRegistryPromise === undefined) return undefined;
|
|
901
903
|
try {
|
|
902
904
|
const { runtime, registry } = await configuredRegistryPromise;
|
|
903
|
-
const
|
|
904
|
-
await runtime.registryActorStopThresholdMs?.(registry);
|
|
905
|
+
const budgetMs = await runtime.registryShutdownBudgetMs?.(registry);
|
|
905
906
|
if (
|
|
906
|
-
|
|
907
|
-
Number.isFinite(
|
|
908
|
-
|
|
907
|
+
budgetMs !== undefined &&
|
|
908
|
+
Number.isFinite(budgetMs) &&
|
|
909
|
+
budgetMs > 0
|
|
909
910
|
) {
|
|
910
|
-
return
|
|
911
|
+
return budgetMs;
|
|
911
912
|
}
|
|
912
913
|
} catch (err) {
|
|
913
914
|
logger().warn(
|
|
914
915
|
{ err },
|
|
915
|
-
"failed to read
|
|
916
|
+
"failed to read the shutdown budget for shutdown grace",
|
|
916
917
|
);
|
|
917
918
|
}
|
|
918
919
|
return undefined;
|
|
@@ -345,12 +345,11 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
345
345
|
await this.#bindings.shutdownTelemetry();
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
async
|
|
348
|
+
async registryShutdownBudgetMs(
|
|
349
349
|
registry: RegistryHandle,
|
|
350
350
|
): Promise<number | undefined> {
|
|
351
351
|
return (
|
|
352
|
-
(await asNativeRegistry(registry).
|
|
353
|
-
undefined
|
|
352
|
+
(await asNativeRegistry(registry).shutdownBudgetMs()) ?? undefined
|
|
354
353
|
);
|
|
355
354
|
}
|
|
356
355
|
|
|
@@ -883,13 +882,6 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
883
882
|
return await this.#actorSql(ctx).exec(sql);
|
|
884
883
|
}
|
|
885
884
|
|
|
886
|
-
actorSqlExecSync(
|
|
887
|
-
ctx: ActorContextHandle,
|
|
888
|
-
sql: string,
|
|
889
|
-
): RuntimeSqlExecResult {
|
|
890
|
-
return this.#actorSql(ctx).execSync(sql);
|
|
891
|
-
}
|
|
892
|
-
|
|
893
885
|
async actorSqlExecute(
|
|
894
886
|
ctx: ActorContextHandle,
|
|
895
887
|
sql: string,
|
|
@@ -902,18 +894,6 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
902
894
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
903
895
|
}
|
|
904
896
|
|
|
905
|
-
actorSqlExecuteSync(
|
|
906
|
-
ctx: ActorContextHandle,
|
|
907
|
-
sql: string,
|
|
908
|
-
params?: RuntimeSqlBindParams,
|
|
909
|
-
): RuntimeSqlExecuteResult {
|
|
910
|
-
const result = this.#actorSql(ctx).executeSync(
|
|
911
|
-
sql,
|
|
912
|
-
toNapiSqlBindParams(params),
|
|
913
|
-
);
|
|
914
|
-
return normalizeRuntimeSqlExecuteResult(result);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
897
|
async actorSqlExecuteBatch(
|
|
918
898
|
ctx: ActorContextHandle,
|
|
919
899
|
statements: RuntimeSqlBatchStatement[],
|
|
@@ -935,17 +915,6 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
935
915
|
)) as unknown as SqliteTransactionHandle;
|
|
936
916
|
}
|
|
937
917
|
|
|
938
|
-
actorSqlBeginTransactionSync(
|
|
939
|
-
ctx: ActorContextHandle,
|
|
940
|
-
timeoutMs?: number,
|
|
941
|
-
name?: string,
|
|
942
|
-
): SqliteTransactionHandle {
|
|
943
|
-
return this.#actorSql(ctx).beginTransactionSync(
|
|
944
|
-
timeoutMs,
|
|
945
|
-
name,
|
|
946
|
-
) as unknown as SqliteTransactionHandle;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
918
|
async actorSqlTransactionExec(
|
|
950
919
|
transaction: SqliteTransactionHandle,
|
|
951
920
|
sql: string,
|
|
@@ -953,13 +922,6 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
953
922
|
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
954
923
|
}
|
|
955
924
|
|
|
956
|
-
actorSqlTransactionExecSync(
|
|
957
|
-
transaction: SqliteTransactionHandle,
|
|
958
|
-
sql: string,
|
|
959
|
-
): RuntimeSqlExecResult {
|
|
960
|
-
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
961
|
-
}
|
|
962
|
-
|
|
963
925
|
async actorSqlTransactionExecute(
|
|
964
926
|
transaction: SqliteTransactionHandle,
|
|
965
927
|
sql: string,
|
|
@@ -972,39 +934,17 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
972
934
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
973
935
|
}
|
|
974
936
|
|
|
975
|
-
actorSqlTransactionExecuteSync(
|
|
976
|
-
transaction: SqliteTransactionHandle,
|
|
977
|
-
sql: string,
|
|
978
|
-
params?: RuntimeSqlBindParams,
|
|
979
|
-
): RuntimeSqlExecuteResult {
|
|
980
|
-
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
981
|
-
sql,
|
|
982
|
-
toNapiSqlBindParams(params),
|
|
983
|
-
);
|
|
984
|
-
return normalizeRuntimeSqlExecuteResult(result);
|
|
985
|
-
}
|
|
986
|
-
|
|
987
937
|
async actorSqlTransactionCommit(
|
|
988
938
|
transaction: SqliteTransactionHandle,
|
|
989
939
|
): Promise<void> {
|
|
990
940
|
await asNativeSqlTransaction(transaction).commit();
|
|
991
941
|
}
|
|
992
942
|
|
|
993
|
-
actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
|
|
994
|
-
asNativeSqlTransaction(transaction).commitSync();
|
|
995
|
-
}
|
|
996
|
-
|
|
997
943
|
async actorSqlTransactionRollback(
|
|
998
944
|
transaction: SqliteTransactionHandle,
|
|
999
945
|
): Promise<void> {
|
|
1000
946
|
await asNativeSqlTransaction(transaction).rollback();
|
|
1001
947
|
}
|
|
1002
|
-
|
|
1003
|
-
actorSqlTransactionRollbackSync(
|
|
1004
|
-
transaction: SqliteTransactionHandle,
|
|
1005
|
-
): void {
|
|
1006
|
-
asNativeSqlTransaction(transaction).rollbackSync();
|
|
1007
|
-
}
|
|
1008
948
|
async actorBeginStateTransaction(
|
|
1009
949
|
ctx: ActorContextHandle,
|
|
1010
950
|
timeoutMs?: number,
|
|
@@ -1070,25 +1010,6 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1070
1010
|
return this.#actorSql(ctx).takeLastKvError?.() ?? null;
|
|
1071
1011
|
}
|
|
1072
1012
|
|
|
1073
|
-
async actorSqlOpen(ctx: ActorContextHandle): Promise<void> {
|
|
1074
|
-
await this.#actorSql(ctx).open();
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
actorSqlCommitTicket(ctx: ActorContextHandle): number {
|
|
1078
|
-
return this.#actorSql(ctx).commitTicket();
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void {
|
|
1082
|
-
this.#actorSql(ctx).abortGeneration(reason);
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
async actorSqlWhenDurable(
|
|
1086
|
-
ctx: ActorContextHandle,
|
|
1087
|
-
ticket: number,
|
|
1088
|
-
): Promise<void> {
|
|
1089
|
-
await this.#actorSql(ctx).whenDurable(ticket);
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
1013
|
async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
|
|
1093
1014
|
const nativeCtx = asNativeActorContext(ctx);
|
|
1094
1015
|
if (!this.#sqlOpened.delete(nativeCtx)) {
|