rivetkit 3.1.2-rc.5 → 3.1.2-rc.6
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 +16 -2
- package/dist/browser/client.js +18 -48
- 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-3T3EMLZW.js → chunk-2OEJM5K3.js} +2 -2
- package/dist/tsup/{chunk-3T3EMLZW.js.map → chunk-2OEJM5K3.js.map} +1 -1
- package/dist/tsup/{chunk-URACKJQW.js → chunk-4GCDILHQ.js} +2 -2
- package/dist/tsup/{chunk-W7R5OF2Y.cjs → chunk-7EDYE6RS.cjs} +164 -194
- package/dist/tsup/chunk-7EDYE6RS.cjs.map +1 -0
- package/dist/tsup/{chunk-2BOGDAXY.cjs → chunk-AKADRXK5.cjs} +3 -3
- package/dist/tsup/{chunk-2BOGDAXY.cjs.map → chunk-AKADRXK5.cjs.map} +1 -1
- package/dist/tsup/{chunk-2PPPGFWJ.js → chunk-AUC22H3Q.js} +4 -4
- package/dist/tsup/{chunk-J7FZTBPN.js → chunk-GPNKYTKX.js} +2 -2
- package/dist/tsup/{chunk-4M2YYW5C.js → chunk-HEWH252Y.js} +2 -2
- package/dist/tsup/{chunk-CKNOZ3G3.cjs → chunk-JHBRUK2G.cjs} +2 -2
- package/dist/tsup/{chunk-CKNOZ3G3.cjs.map → chunk-JHBRUK2G.cjs.map} +1 -1
- package/dist/tsup/{chunk-6JRISJJK.cjs → chunk-KCL4AISR.cjs} +4 -4
- package/dist/tsup/{chunk-6JRISJJK.cjs.map → chunk-KCL4AISR.cjs.map} +1 -1
- package/dist/tsup/{chunk-KRUDOIRE.js → chunk-LFGYDRKK.js} +2 -2
- package/dist/tsup/{chunk-GSS3YRUD.cjs → chunk-NHTD4LYE.cjs} +3 -3
- package/dist/tsup/{chunk-GSS3YRUD.cjs.map → chunk-NHTD4LYE.cjs.map} +1 -1
- package/dist/tsup/{chunk-6KETXN6K.js → chunk-O6BVKXY4.js} +23 -53
- package/dist/tsup/chunk-O6BVKXY4.js.map +1 -0
- package/dist/tsup/{chunk-62HCCSWY.cjs → chunk-V32FXQ3Y.cjs} +3 -3
- package/dist/tsup/{chunk-62HCCSWY.cjs.map → chunk-V32FXQ3Y.cjs.map} +1 -1
- package/dist/tsup/{chunk-ITW5YHD2.cjs → chunk-X3EPJHTD.cjs} +7 -7
- package/dist/tsup/{chunk-ITW5YHD2.cjs.map → chunk-X3EPJHTD.cjs.map} +1 -1
- package/dist/tsup/{chunk-MFJDJ2X6.cjs → chunk-X7HD5E4N.cjs} +10 -10
- package/dist/tsup/{chunk-MFJDJ2X6.cjs.map → chunk-X7HD5E4N.cjs.map} +1 -1
- package/dist/tsup/{chunk-OLOQ3NAM.js → chunk-Y5RH2IT6.js} +3 -3
- 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-BbRMYCV8.d.cts → config-BMGUEKMZ.d.cts} +16 -2
- package/dist/tsup/{config-CW3AWqHa.d.ts → config-iBpXyITj.d.ts} +16 -2
- package/dist/tsup/{context-Cp64yaMW.d.ts → context-hyVakgnU.d.ts} +1 -1
- package/dist/tsup/{context-NuwP8HjQ.d.cts → context-qfvLuF0P.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 +391 -127
- 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 +310 -46
- 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/actor-handle.ts +0 -1
- package/src/client/client.ts +1 -4
- package/src/client/lifecycle-errors.ts +0 -37
- package/src/client/resolve-gateway-target.ts +15 -34
- package/src/common/database/config.ts +52 -0
- package/src/common/database/native-database.ts +229 -18
- package/src/registry/config/index.ts +1 -3
- package/src/registry/index.ts +14 -15
- package/src/registry/napi-runtime.ts +81 -2
- package/src/registry/native.ts +66 -17
- package/src/registry/runtime.ts +53 -2
- package/src/registry/wasm-runtime.ts +88 -0
- package/dist/tsup/chunk-6KETXN6K.js.map +0 -1
- package/dist/tsup/chunk-W7R5OF2Y.cjs.map +0 -1
- /package/dist/tsup/{chunk-URACKJQW.js.map → chunk-4GCDILHQ.js.map} +0 -0
- /package/dist/tsup/{chunk-2PPPGFWJ.js.map → chunk-AUC22H3Q.js.map} +0 -0
- /package/dist/tsup/{chunk-J7FZTBPN.js.map → chunk-GPNKYTKX.js.map} +0 -0
- /package/dist/tsup/{chunk-4M2YYW5C.js.map → chunk-HEWH252Y.js.map} +0 -0
- /package/dist/tsup/{chunk-KRUDOIRE.js.map → chunk-LFGYDRKK.js.map} +0 -0
- /package/dist/tsup/{chunk-OLOQ3NAM.js.map → chunk-Y5RH2IT6.js.map} +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { decodeBridgeRivetError } from "@/actor/errors";
|
|
2
2
|
import type {
|
|
3
|
+
DeferredSqliteDatabase,
|
|
3
4
|
SqliteBatchStatement,
|
|
4
5
|
SqliteBindings,
|
|
5
|
-
SqliteDatabase,
|
|
6
6
|
SqliteExecuteResult,
|
|
7
7
|
SqliteNativeMetrics,
|
|
8
8
|
SqliteTransactionDatabase,
|
|
9
|
+
SynchronousSqliteTransactionDatabase,
|
|
9
10
|
} from "./config";
|
|
10
11
|
|
|
11
12
|
// Matches the name core uses for the transaction behind a native executeBatch call.
|
|
@@ -77,10 +78,15 @@ interface NativeBatchStatement {
|
|
|
77
78
|
|
|
78
79
|
export interface JsNativeDatabaseLike {
|
|
79
80
|
exec(sql: string): Promise<NativeExecResult>;
|
|
81
|
+
execSync(sql: string): NativeExecResult;
|
|
80
82
|
execute(
|
|
81
83
|
sql: string,
|
|
82
84
|
params?: NativeBindParam[] | null,
|
|
83
85
|
): Promise<NativeExecuteResult>;
|
|
86
|
+
executeSync(
|
|
87
|
+
sql: string,
|
|
88
|
+
params?: NativeBindParam[] | null,
|
|
89
|
+
): NativeExecuteResult;
|
|
84
90
|
executeBatch?(
|
|
85
91
|
statements: NativeBatchStatement[],
|
|
86
92
|
): Promise<NativeExecuteResult[]>;
|
|
@@ -93,6 +99,10 @@ export interface JsNativeDatabaseLike {
|
|
|
93
99
|
timeoutMs?: number,
|
|
94
100
|
name?: string,
|
|
95
101
|
): Promise<JsNativeTransactionLike>;
|
|
102
|
+
beginTransactionSync(
|
|
103
|
+
timeoutMs?: number,
|
|
104
|
+
name?: string,
|
|
105
|
+
): JsNativeSynchronousTransactionLike;
|
|
96
106
|
query(
|
|
97
107
|
sql: string,
|
|
98
108
|
params?: NativeBindParam[] | null,
|
|
@@ -103,9 +113,14 @@ export interface JsNativeDatabaseLike {
|
|
|
103
113
|
): Promise<NativeRunResult>;
|
|
104
114
|
metrics?(): SqliteNativeMetrics | null;
|
|
105
115
|
takeLastKvError?(): string | null;
|
|
116
|
+
open(): Promise<void>;
|
|
117
|
+
commitTicket(): number;
|
|
118
|
+
whenDurable(ticket: number): Promise<void>;
|
|
119
|
+
abortGeneration(reason: string): void;
|
|
106
120
|
close(): Promise<void>;
|
|
107
121
|
}
|
|
108
|
-
export type StateAwareSqliteDatabase =
|
|
122
|
+
export type StateAwareSqliteDatabase = DeferredSqliteDatabase & {
|
|
123
|
+
open(): Promise<void>;
|
|
109
124
|
beginStateTransaction(
|
|
110
125
|
timeoutMs?: number,
|
|
111
126
|
context?: unknown,
|
|
@@ -128,6 +143,28 @@ export interface JsNativeTransactionLike {
|
|
|
128
143
|
rollback(): Promise<void>;
|
|
129
144
|
}
|
|
130
145
|
|
|
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
|
+
|
|
131
168
|
function shouldAttachNativeKvError(message: string): boolean {
|
|
132
169
|
return /i\/o error|unable to open database file/i.test(message);
|
|
133
170
|
}
|
|
@@ -167,6 +204,16 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
167
204
|
return { kind: "null" };
|
|
168
205
|
}
|
|
169
206
|
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
|
+
}
|
|
170
217
|
return { kind: "int", intValue: Number(arg) };
|
|
171
218
|
}
|
|
172
219
|
if (typeof arg === "number") {
|
|
@@ -190,9 +237,13 @@ function toNativeBinding(arg: unknown): NativeBindParam {
|
|
|
190
237
|
function extractNamedSqliteParameters(sql: string): string[] {
|
|
191
238
|
const orderedNames: string[] = [];
|
|
192
239
|
const seen = new Set<string>();
|
|
193
|
-
|
|
240
|
+
// SQLite identifiers may contain "$" and any non-ASCII character. Consume
|
|
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;
|
|
194
244
|
for (const match of sql.matchAll(pattern)) {
|
|
195
245
|
const name = match[1];
|
|
246
|
+
if (!name) continue;
|
|
196
247
|
if (seen.has(name)) {
|
|
197
248
|
continue;
|
|
198
249
|
}
|
|
@@ -346,21 +397,49 @@ export function wrapJsNativeDatabase(
|
|
|
346
397
|
sql: string,
|
|
347
398
|
params?: SqliteBindings,
|
|
348
399
|
): Promise<SqliteExecuteResult> => {
|
|
349
|
-
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
350
|
-
if (lastInsertRowIdColumn) {
|
|
351
|
-
return {
|
|
352
|
-
columns: [lastInsertRowIdColumn],
|
|
353
|
-
rows: [[lastInsertRowId ?? 0]],
|
|
354
|
-
changes: 0,
|
|
355
|
-
lastInsertRowId,
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
|
|
359
400
|
const release = gate.enter();
|
|
360
401
|
try {
|
|
402
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
403
|
+
if (lastInsertRowIdColumn) {
|
|
404
|
+
return {
|
|
405
|
+
columns: [lastInsertRowIdColumn],
|
|
406
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
407
|
+
changes: 0,
|
|
408
|
+
lastInsertRowId,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
361
412
|
const nativeParams = toNativeBindings(sql, params);
|
|
362
413
|
const result = await database.execute(sql, nativeParams);
|
|
363
|
-
if (result.lastInsertRowId
|
|
414
|
+
if (result.lastInsertRowId != null) {
|
|
415
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
} catch (error) {
|
|
419
|
+
enrichNativeDatabaseError(database, error);
|
|
420
|
+
} finally {
|
|
421
|
+
release();
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const executeNativeSync = (
|
|
425
|
+
sql: string,
|
|
426
|
+
params?: SqliteBindings,
|
|
427
|
+
): SqliteExecuteResult => {
|
|
428
|
+
const release = gate.enter();
|
|
429
|
+
try {
|
|
430
|
+
const nativeParams = toNativeBindings(sql, params);
|
|
431
|
+
const result = database.executeSync(sql, nativeParams);
|
|
432
|
+
// Execute first so runtime availability and transaction admission are enforced.
|
|
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) {
|
|
364
443
|
lastInsertRowId = result.lastInsertRowId;
|
|
365
444
|
}
|
|
366
445
|
return result;
|
|
@@ -392,12 +471,34 @@ export function wrapJsNativeDatabase(
|
|
|
392
471
|
callback(row, result.columns);
|
|
393
472
|
}
|
|
394
473
|
},
|
|
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
|
+
},
|
|
395
493
|
async execute(
|
|
396
494
|
sql: string,
|
|
397
495
|
params?: SqliteBindings,
|
|
398
496
|
): Promise<SqliteExecuteResult> {
|
|
399
497
|
return await executeNative(sql, params);
|
|
400
498
|
},
|
|
499
|
+
executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult {
|
|
500
|
+
return executeNativeSync(sql, params);
|
|
501
|
+
},
|
|
401
502
|
async executeBatch(
|
|
402
503
|
statements: SqliteBatchStatement[],
|
|
403
504
|
): Promise<SqliteExecuteResult[]> {
|
|
@@ -427,7 +528,7 @@ export function wrapJsNativeDatabase(
|
|
|
427
528
|
return transactionResults;
|
|
428
529
|
})();
|
|
429
530
|
for (const result of results) {
|
|
430
|
-
if (result.lastInsertRowId
|
|
531
|
+
if (result.lastInsertRowId != null) {
|
|
431
532
|
lastInsertRowId = result.lastInsertRowId;
|
|
432
533
|
}
|
|
433
534
|
}
|
|
@@ -459,7 +560,26 @@ export function wrapJsNativeDatabase(
|
|
|
459
560
|
release();
|
|
460
561
|
}
|
|
461
562
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
462
|
-
if (result.lastInsertRowId
|
|
563
|
+
if (result.lastInsertRowId != null) {
|
|
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) {
|
|
463
583
|
lastInsertRowId = result.lastInsertRowId;
|
|
464
584
|
}
|
|
465
585
|
});
|
|
@@ -486,7 +606,7 @@ export function wrapJsNativeDatabase(
|
|
|
486
606
|
release();
|
|
487
607
|
}
|
|
488
608
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
489
|
-
if (result.lastInsertRowId
|
|
609
|
+
if (result.lastInsertRowId != null) {
|
|
490
610
|
lastInsertRowId = result.lastInsertRowId;
|
|
491
611
|
}
|
|
492
612
|
});
|
|
@@ -501,6 +621,25 @@ export function wrapJsNativeDatabase(
|
|
|
501
621
|
nativeMetrics(): SqliteNativeMetrics | null {
|
|
502
622
|
return normalizeNativeMetrics(database.metrics?.());
|
|
503
623
|
},
|
|
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
|
+
},
|
|
504
643
|
async close(): Promise<void> {
|
|
505
644
|
terminalPromise ??= gate.close(() => database.close());
|
|
506
645
|
await terminalPromise;
|
|
@@ -512,13 +651,25 @@ export function wrapJsNativeDatabase(
|
|
|
512
651
|
};
|
|
513
652
|
}
|
|
514
653
|
|
|
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;
|
|
515
666
|
function wrapTransaction(
|
|
516
667
|
database: JsNativeDatabaseLike,
|
|
517
668
|
transaction: JsNativeTransactionLike,
|
|
518
669
|
gate: NativeCloseGate,
|
|
519
670
|
onExecute: (result: NativeExecuteResult) => void,
|
|
520
671
|
): SqliteTransactionDatabase {
|
|
521
|
-
|
|
672
|
+
const wrapped: SqliteTransactionDatabase = {
|
|
522
673
|
async exec(sql, callback) {
|
|
523
674
|
const release = gate.enter();
|
|
524
675
|
let result: NativeExecResult;
|
|
@@ -569,6 +720,66 @@ function wrapTransaction(
|
|
|
569
720
|
}
|
|
570
721
|
},
|
|
571
722
|
};
|
|
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;
|
|
572
783
|
}
|
|
573
784
|
|
|
574
785
|
function lastInsertRowIdColumnName(sql: string): string | undefined {
|
|
@@ -289,9 +289,7 @@ 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
|
|
293
|
-
* eviction delay and period, over which it stops the node's actors,
|
|
294
|
-
* plus the time each actor is given to stop. A
|
|
292
|
+
* engine-provided actor stop threshold once the node connects. A
|
|
295
293
|
* signal-driven shutdown of a managed local development engine waits
|
|
296
294
|
* four seconds by default so actors can acknowledge stopping before
|
|
297
295
|
* a file watcher restarts the process.
|
package/src/registry/index.ts
CHANGED
|
@@ -39,10 +39,9 @@ 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
|
-
|
|
45
|
-
const DEFAULT_SHUTDOWN_BUDGET_MS = 30_000;
|
|
42
|
+
// Matches the engine's default `pegboard.actor_stop_threshold`. Used only when the
|
|
43
|
+
// node has not received the engine's advertised threshold before shutdown begins.
|
|
44
|
+
const DEFAULT_ACTOR_STOP_THRESHOLD_MS = 30_000;
|
|
46
45
|
|
|
47
46
|
// Serverless is disabled for v3; keep the implementation for a later release.
|
|
48
47
|
function rejectServerless(): void {
|
|
@@ -824,14 +823,13 @@ export class Registry<A extends RegistryActors> {
|
|
|
824
823
|
if (gracePeriodMs === undefined) {
|
|
825
824
|
gracePeriodMs = localDevSignal
|
|
826
825
|
? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS
|
|
827
|
-
: ((await this.#
|
|
826
|
+
: ((await this.#actorStopThresholdMs(
|
|
828
827
|
modeAPromise ?? modeBPromise,
|
|
829
|
-
)) ??
|
|
828
|
+
)) ?? DEFAULT_ACTOR_STOP_THRESHOLD_MS);
|
|
830
829
|
}
|
|
831
830
|
// Race the entire drain sequence (both modes + serve promise) against
|
|
832
831
|
// a single grace ceiling. Local dev signal shutdowns allow the watcher
|
|
833
|
-
// to restart promptly; other shutdowns use the engine's
|
|
834
|
-
// period plus its actor stop threshold.
|
|
832
|
+
// to restart promptly; other shutdowns use the engine's actor stop threshold.
|
|
835
833
|
const drain = async () => {
|
|
836
834
|
// Shut down every live `CoreRegistry` we know about. Mode A
|
|
837
835
|
// (`start()`) and Mode B (`handler()`) each build a separate
|
|
@@ -894,7 +892,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
894
892
|
);
|
|
895
893
|
}
|
|
896
894
|
|
|
897
|
-
async #
|
|
895
|
+
async #actorStopThresholdMs(
|
|
898
896
|
configuredRegistryPromise:
|
|
899
897
|
| ReturnType<typeof buildConfiguredRegistry>
|
|
900
898
|
| undefined,
|
|
@@ -902,18 +900,19 @@ export class Registry<A extends RegistryActors> {
|
|
|
902
900
|
if (configuredRegistryPromise === undefined) return undefined;
|
|
903
901
|
try {
|
|
904
902
|
const { runtime, registry } = await configuredRegistryPromise;
|
|
905
|
-
const
|
|
903
|
+
const thresholdMs =
|
|
904
|
+
await runtime.registryActorStopThresholdMs?.(registry);
|
|
906
905
|
if (
|
|
907
|
-
|
|
908
|
-
Number.isFinite(
|
|
909
|
-
|
|
906
|
+
thresholdMs !== undefined &&
|
|
907
|
+
Number.isFinite(thresholdMs) &&
|
|
908
|
+
thresholdMs > 0
|
|
910
909
|
) {
|
|
911
|
-
return
|
|
910
|
+
return thresholdMs;
|
|
912
911
|
}
|
|
913
912
|
} catch (err) {
|
|
914
913
|
logger().warn(
|
|
915
914
|
{ err },
|
|
916
|
-
"failed to read
|
|
915
|
+
"failed to read actor stop threshold for shutdown grace",
|
|
917
916
|
);
|
|
918
917
|
}
|
|
919
918
|
return undefined;
|
|
@@ -345,11 +345,12 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
345
345
|
await this.#bindings.shutdownTelemetry();
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
async
|
|
348
|
+
async registryActorStopThresholdMs(
|
|
349
349
|
registry: RegistryHandle,
|
|
350
350
|
): Promise<number | undefined> {
|
|
351
351
|
return (
|
|
352
|
-
(await asNativeRegistry(registry).
|
|
352
|
+
(await asNativeRegistry(registry).actorStopThresholdMs()) ??
|
|
353
|
+
undefined
|
|
353
354
|
);
|
|
354
355
|
}
|
|
355
356
|
|
|
@@ -882,6 +883,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
882
883
|
return await this.#actorSql(ctx).exec(sql);
|
|
883
884
|
}
|
|
884
885
|
|
|
886
|
+
actorSqlExecSync(
|
|
887
|
+
ctx: ActorContextHandle,
|
|
888
|
+
sql: string,
|
|
889
|
+
): RuntimeSqlExecResult {
|
|
890
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
891
|
+
}
|
|
892
|
+
|
|
885
893
|
async actorSqlExecute(
|
|
886
894
|
ctx: ActorContextHandle,
|
|
887
895
|
sql: string,
|
|
@@ -894,6 +902,18 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
894
902
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
895
903
|
}
|
|
896
904
|
|
|
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
|
+
|
|
897
917
|
async actorSqlExecuteBatch(
|
|
898
918
|
ctx: ActorContextHandle,
|
|
899
919
|
statements: RuntimeSqlBatchStatement[],
|
|
@@ -915,6 +935,17 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
915
935
|
)) as unknown as SqliteTransactionHandle;
|
|
916
936
|
}
|
|
917
937
|
|
|
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
|
+
|
|
918
949
|
async actorSqlTransactionExec(
|
|
919
950
|
transaction: SqliteTransactionHandle,
|
|
920
951
|
sql: string,
|
|
@@ -922,6 +953,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
922
953
|
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
923
954
|
}
|
|
924
955
|
|
|
956
|
+
actorSqlTransactionExecSync(
|
|
957
|
+
transaction: SqliteTransactionHandle,
|
|
958
|
+
sql: string,
|
|
959
|
+
): RuntimeSqlExecResult {
|
|
960
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
961
|
+
}
|
|
962
|
+
|
|
925
963
|
async actorSqlTransactionExecute(
|
|
926
964
|
transaction: SqliteTransactionHandle,
|
|
927
965
|
sql: string,
|
|
@@ -934,17 +972,39 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
934
972
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
935
973
|
}
|
|
936
974
|
|
|
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
|
+
|
|
937
987
|
async actorSqlTransactionCommit(
|
|
938
988
|
transaction: SqliteTransactionHandle,
|
|
939
989
|
): Promise<void> {
|
|
940
990
|
await asNativeSqlTransaction(transaction).commit();
|
|
941
991
|
}
|
|
942
992
|
|
|
993
|
+
actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
|
|
994
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
995
|
+
}
|
|
996
|
+
|
|
943
997
|
async actorSqlTransactionRollback(
|
|
944
998
|
transaction: SqliteTransactionHandle,
|
|
945
999
|
): Promise<void> {
|
|
946
1000
|
await asNativeSqlTransaction(transaction).rollback();
|
|
947
1001
|
}
|
|
1002
|
+
|
|
1003
|
+
actorSqlTransactionRollbackSync(
|
|
1004
|
+
transaction: SqliteTransactionHandle,
|
|
1005
|
+
): void {
|
|
1006
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
1007
|
+
}
|
|
948
1008
|
async actorBeginStateTransaction(
|
|
949
1009
|
ctx: ActorContextHandle,
|
|
950
1010
|
timeoutMs?: number,
|
|
@@ -1010,6 +1070,25 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
1010
1070
|
return this.#actorSql(ctx).takeLastKvError?.() ?? null;
|
|
1011
1071
|
}
|
|
1012
1072
|
|
|
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
|
+
|
|
1013
1092
|
async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
|
|
1014
1093
|
const nativeCtx = asNativeActorContext(ctx);
|
|
1015
1094
|
if (!this.#sqlOpened.delete(nativeCtx)) {
|