rivetkit 3.1.2-rc.1 → 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.
Files changed (103) hide show
  1. package/dist/browser/client.d.ts +3 -43
  2. package/dist/browser/client.js +9 -1
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +1 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/{chunk-SPLLB6BX.js → chunk-2BXN54R4.js} +2 -2
  7. package/dist/tsup/{chunk-YT77YM32.js → chunk-3ALVCHXR.js} +3 -3
  8. package/dist/tsup/{chunk-R2GD2TDD.cjs → chunk-6ANYUVLS.cjs} +3 -3
  9. package/dist/tsup/{chunk-R2GD2TDD.cjs.map → chunk-6ANYUVLS.cjs.map} +1 -1
  10. package/dist/tsup/{chunk-5RE3IF3C.js → chunk-6S73EWWS.js} +2 -2
  11. package/dist/tsup/{chunk-MM6QYEV7.cjs → chunk-6YDPLY6F.cjs} +155 -147
  12. package/dist/tsup/chunk-6YDPLY6F.cjs.map +1 -0
  13. package/dist/tsup/{chunk-KOB3RR6D.cjs → chunk-C2I4CPLD.cjs} +7 -7
  14. package/dist/tsup/{chunk-KOB3RR6D.cjs.map → chunk-C2I4CPLD.cjs.map} +1 -1
  15. package/dist/tsup/{chunk-YPJ3QEDL.cjs → chunk-JK62DI4K.cjs} +4 -4
  16. package/dist/tsup/{chunk-YPJ3QEDL.cjs.map → chunk-JK62DI4K.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-TYNEZVC2.cjs → chunk-MJCM3IZN.cjs} +3 -3
  18. package/dist/tsup/{chunk-TYNEZVC2.cjs.map → chunk-MJCM3IZN.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-GI3TPFCE.cjs → chunk-MJWDZ4CU.cjs} +2 -2
  20. package/dist/tsup/{chunk-GI3TPFCE.cjs.map → chunk-MJWDZ4CU.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-TR5YB355.cjs → chunk-P57K5DTD.cjs} +5 -4
  22. package/dist/tsup/chunk-P57K5DTD.cjs.map +1 -0
  23. package/dist/tsup/{chunk-WD6L6OTX.js → chunk-POKN6RC5.js} +2 -2
  24. package/dist/tsup/{chunk-WD6L6OTX.js.map → chunk-POKN6RC5.js.map} +1 -1
  25. package/dist/tsup/{chunk-7PUO5YRK.js → chunk-WCVT6UXF.js} +14 -6
  26. package/dist/tsup/chunk-WCVT6UXF.js.map +1 -0
  27. package/dist/tsup/{chunk-DKVKYLXH.js → chunk-WJSHEWTP.js} +4 -4
  28. package/dist/tsup/{chunk-VUFOIAKH.cjs → chunk-X4HPTBGP.cjs} +10 -10
  29. package/dist/tsup/{chunk-VUFOIAKH.cjs.map → chunk-X4HPTBGP.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-LNMODE5R.js → chunk-YXBMGSYD.js} +4 -3
  31. package/dist/tsup/chunk-YXBMGSYD.js.map +1 -0
  32. package/dist/tsup/{chunk-J5ZNIJT3.js → chunk-ZWLSBELO.js} +2 -2
  33. package/dist/tsup/client/mod.cjs +5 -5
  34. package/dist/tsup/client/mod.d.cts +3 -3
  35. package/dist/tsup/client/mod.d.ts +3 -3
  36. package/dist/tsup/client/mod.js +4 -4
  37. package/dist/tsup/common/log.cjs +2 -2
  38. package/dist/tsup/common/log.js +1 -1
  39. package/dist/tsup/common/websocket.cjs +3 -3
  40. package/dist/tsup/common/websocket.js +2 -2
  41. package/dist/tsup/{config-CTGjM4A5.d.cts → config-BbRMYCV8.d.cts} +4 -18
  42. package/dist/tsup/{config-Df5jOcde.d.ts → config-CBTr4IhE.d.cts} +0 -26
  43. package/dist/tsup/{config-Df5jOcde.d.cts → config-CBTr4IhE.d.ts} +0 -26
  44. package/dist/tsup/{config-DLXQ_TVP.d.ts → config-CW3AWqHa.d.ts} +4 -18
  45. package/dist/tsup/{context-Dmz9Hd6K.d.ts → context-Cp64yaMW.d.ts} +2 -2
  46. package/dist/tsup/{context-S-Y75hj1.d.cts → context-NuwP8HjQ.d.cts} +2 -2
  47. package/dist/tsup/db/drizzle.cjs +2 -2
  48. package/dist/tsup/db/drizzle.d.cts +1 -1
  49. package/dist/tsup/db/drizzle.d.ts +1 -1
  50. package/dist/tsup/db/drizzle.js +1 -1
  51. package/dist/tsup/db/mod.cjs +3 -3
  52. package/dist/tsup/db/mod.d.cts +2 -2
  53. package/dist/tsup/db/mod.d.ts +2 -2
  54. package/dist/tsup/db/mod.js +2 -2
  55. package/dist/tsup/dynamic/mod.d.cts +2 -2
  56. package/dist/tsup/dynamic/mod.d.ts +2 -2
  57. package/dist/tsup/inspector/mod.cjs +5 -5
  58. package/dist/tsup/inspector/mod.js +4 -4
  59. package/dist/tsup/inspector/workflow.cjs +4 -4
  60. package/dist/tsup/inspector/workflow.js +3 -3
  61. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  62. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  63. package/dist/tsup/mod.cjs +151 -401
  64. package/dist/tsup/mod.cjs.map +1 -1
  65. package/dist/tsup/mod.d.cts +4 -4
  66. package/dist/tsup/mod.d.ts +4 -4
  67. package/dist/tsup/mod.js +70 -320
  68. package/dist/tsup/mod.js.map +1 -1
  69. package/dist/tsup/test/mod.cjs +6 -6
  70. package/dist/tsup/test/mod.d.cts +2 -2
  71. package/dist/tsup/test/mod.d.ts +2 -2
  72. package/dist/tsup/test/mod.js +4 -4
  73. package/dist/tsup/unstable/migrations.d.cts +1 -1
  74. package/dist/tsup/unstable/migrations.d.ts +1 -1
  75. package/dist/tsup/utils.cjs +2 -2
  76. package/dist/tsup/utils.js +1 -1
  77. package/dist/tsup/workflow/mod.cjs +35 -27
  78. package/dist/tsup/workflow/mod.cjs.map +1 -1
  79. package/dist/tsup/workflow/mod.d.cts +4 -4
  80. package/dist/tsup/workflow/mod.d.ts +4 -4
  81. package/dist/tsup/workflow/mod.js +32 -24
  82. package/dist/tsup/workflow/mod.js.map +1 -1
  83. package/package.json +9 -9
  84. package/src/client/lifecycle-errors.ts +15 -0
  85. package/src/common/database/config.ts +0 -39
  86. package/src/common/database/mod.ts +3 -0
  87. package/src/common/database/native-database.ts +32 -231
  88. package/src/registry/config/index.ts +3 -1
  89. package/src/registry/index.ts +15 -14
  90. package/src/registry/napi-runtime.ts +4 -81
  91. package/src/registry/native.ts +21 -60
  92. package/src/registry/runtime.ts +3 -53
  93. package/src/registry/wasm-runtime.ts +3 -89
  94. package/src/workflow/driver.ts +29 -20
  95. package/dist/tsup/chunk-7PUO5YRK.js.map +0 -1
  96. package/dist/tsup/chunk-LNMODE5R.js.map +0 -1
  97. package/dist/tsup/chunk-MM6QYEV7.cjs.map +0 -1
  98. package/dist/tsup/chunk-TR5YB355.cjs.map +0 -1
  99. /package/dist/tsup/{chunk-SPLLB6BX.js.map → chunk-2BXN54R4.js.map} +0 -0
  100. /package/dist/tsup/{chunk-YT77YM32.js.map → chunk-3ALVCHXR.js.map} +0 -0
  101. /package/dist/tsup/{chunk-5RE3IF3C.js.map → chunk-6S73EWWS.js.map} +0 -0
  102. /package/dist/tsup/{chunk-DKVKYLXH.js.map → chunk-WJSHEWTP.js.map} +0 -0
  103. /package/dist/tsup/{chunk-J5ZNIJT3.js.map → chunk-ZWLSBELO.js.map} +0 -0
@@ -6,9 +6,11 @@ import type {
6
6
  SqliteExecuteResult,
7
7
  SqliteNativeMetrics,
8
8
  SqliteTransactionDatabase,
9
- SynchronousSqliteTransactionDatabase,
10
9
  } from "./config";
11
10
 
11
+ // Matches the name core uses for the transaction behind a native executeBatch call.
12
+ const EXECUTE_BATCH_TRANSACTION_NAME = "rivetkit-execute-batch";
13
+
12
14
  type NativeBindNoValues = {
13
15
  intValue?: never;
14
16
  floatValue?: never;
@@ -75,30 +77,22 @@ interface NativeBatchStatement {
75
77
 
76
78
  export interface JsNativeDatabaseLike {
77
79
  exec(sql: string): Promise<NativeExecResult>;
78
- execSync(sql: string): NativeExecResult;
79
80
  execute(
80
81
  sql: string,
81
82
  params?: NativeBindParam[] | null,
82
83
  ): Promise<NativeExecuteResult>;
83
- executeSync(
84
- sql: string,
85
- params?: NativeBindParam[] | null,
86
- ): NativeExecuteResult;
87
84
  executeBatch?(
88
85
  statements: NativeBatchStatement[],
89
86
  ): Promise<NativeExecuteResult[]>;
90
87
  beginStateTransaction?(
91
88
  timeoutMs?: number,
92
89
  context?: unknown,
90
+ name?: string,
93
91
  ): Promise<JsNativeTransactionLike>;
94
92
  beginTransaction(
95
93
  timeoutMs?: number,
96
94
  name?: string,
97
95
  ): Promise<JsNativeTransactionLike>;
98
- beginTransactionSync(
99
- timeoutMs?: number,
100
- name?: string,
101
- ): JsNativeSynchronousTransactionLike;
102
96
  query(
103
97
  sql: string,
104
98
  params?: NativeBindParam[] | null,
@@ -109,19 +103,13 @@ export interface JsNativeDatabaseLike {
109
103
  ): Promise<NativeRunResult>;
110
104
  metrics?(): SqliteNativeMetrics | null;
111
105
  takeLastKvError?(): string | null;
112
- open(): Promise<void>;
113
- commitTicket(): number;
114
- whenDurable(ticket: number): Promise<void>;
115
- abortGeneration(reason: string): void;
116
106
  close(): Promise<void>;
117
107
  }
118
108
  export type StateAwareSqliteDatabase = SqliteDatabase & {
119
- open(): Promise<void>;
120
- commitTicket(): number;
121
- whenDurable(ticket: number): Promise<void>;
122
109
  beginStateTransaction(
123
110
  timeoutMs?: number,
124
111
  context?: unknown,
112
+ name?: string,
125
113
  ): Promise<SqliteTransactionDatabase>;
126
114
  };
127
115
 
@@ -140,28 +128,6 @@ export interface JsNativeTransactionLike {
140
128
  rollback(): Promise<void>;
141
129
  }
142
130
 
143
- export interface JsNativeSynchronousTransactionLike
144
- extends JsNativeTransactionLike {
145
- execSync(sql: string): NativeExecResult;
146
- executeSync(
147
- sql: string,
148
- params?: NativeBindParam[] | null,
149
- ): NativeExecuteResult;
150
- commitSync(): void;
151
- rollbackSync(): void;
152
- }
153
-
154
- function isSynchronousTransaction(
155
- transaction: JsNativeTransactionLike,
156
- ): transaction is JsNativeSynchronousTransactionLike {
157
- const candidate =
158
- transaction as Partial<JsNativeSynchronousTransactionLike>;
159
- return (
160
- typeof candidate.commitSync === "function" &&
161
- typeof candidate.rollbackSync === "function"
162
- );
163
- }
164
-
165
131
  function shouldAttachNativeKvError(message: string): boolean {
166
132
  return /i\/o error|unable to open database file/i.test(message);
167
133
  }
@@ -200,19 +166,13 @@ function toNativeBinding(arg: unknown): NativeBindParam {
200
166
  if (arg === null || arg === undefined) {
201
167
  return { kind: "null" };
202
168
  }
203
- if (
204
- typeof arg === "bigint" ||
205
- (typeof arg === "number" && Number.isInteger(arg))
206
- ) {
207
- const value = Number(arg);
208
- if (!Number.isSafeInteger(value)) {
209
- throw new RangeError(
210
- "SQLite integer bindings must be within the JavaScript safe integer range.",
211
- );
212
- }
213
- return { kind: "int", intValue: value };
169
+ if (typeof arg === "bigint") {
170
+ return { kind: "int", intValue: Number(arg) };
214
171
  }
215
172
  if (typeof arg === "number") {
173
+ if (Number.isInteger(arg)) {
174
+ return { kind: "int", intValue: arg };
175
+ }
216
176
  return { kind: "float", floatValue: arg };
217
177
  }
218
178
  if (typeof arg === "string") {
@@ -230,13 +190,9 @@ function toNativeBinding(arg: unknown): NativeBindParam {
230
190
  function extractNamedSqliteParameters(sql: string): string[] {
231
191
  const orderedNames: string[] = [];
232
192
  const seen = new Set<string>();
233
- // SQLite identifiers may contain "$" and any non-ASCII character. Consume
234
- // whole identifiers so their suffixes cannot be mistaken for parameters.
235
- const pattern =
236
- /'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\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;
237
194
  for (const match of sql.matchAll(pattern)) {
238
195
  const name = match[1];
239
- if (!name) continue;
240
196
  if (seen.has(name)) {
241
197
  continue;
242
198
  }
@@ -390,49 +346,21 @@ export function wrapJsNativeDatabase(
390
346
  sql: string,
391
347
  params?: SqliteBindings,
392
348
  ): Promise<SqliteExecuteResult> => {
393
- const release = gate.enter();
394
- try {
395
- const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
396
- if (lastInsertRowIdColumn) {
397
- return {
398
- columns: [lastInsertRowIdColumn],
399
- rows: [[lastInsertRowId ?? 0]],
400
- changes: 0,
401
- lastInsertRowId,
402
- };
403
- }
404
-
405
- const nativeParams = toNativeBindings(sql, params);
406
- const result = await database.execute(sql, nativeParams);
407
- if (result.lastInsertRowId != null) {
408
- lastInsertRowId = result.lastInsertRowId;
409
- }
410
- return result;
411
- } catch (error) {
412
- enrichNativeDatabaseError(database, error);
413
- } finally {
414
- release();
349
+ const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
350
+ if (lastInsertRowIdColumn) {
351
+ return {
352
+ columns: [lastInsertRowIdColumn],
353
+ rows: [[lastInsertRowId ?? 0]],
354
+ changes: 0,
355
+ lastInsertRowId,
356
+ };
415
357
  }
416
- };
417
- const executeNativeSync = (
418
- sql: string,
419
- params?: SqliteBindings,
420
- ): SqliteExecuteResult => {
358
+
421
359
  const release = gate.enter();
422
360
  try {
423
361
  const nativeParams = toNativeBindings(sql, params);
424
- const result = database.executeSync(sql, nativeParams);
425
- // Execute first so runtime availability and transaction admission are enforced.
426
- const rowIdColumn = lastInsertRowIdColumnName(sql);
427
- if (rowIdColumn) {
428
- return {
429
- columns: [rowIdColumn],
430
- rows: [[lastInsertRowId ?? 0]],
431
- changes: 0,
432
- lastInsertRowId,
433
- };
434
- }
435
- if (result.lastInsertRowId != null) {
362
+ const result = await database.execute(sql, nativeParams);
363
+ if (result.lastInsertRowId !== undefined) {
436
364
  lastInsertRowId = result.lastInsertRowId;
437
365
  }
438
366
  return result;
@@ -464,34 +392,12 @@ export function wrapJsNativeDatabase(
464
392
  callback(row, result.columns);
465
393
  }
466
394
  },
467
- execSync(
468
- sql: string,
469
- callback?: (row: unknown[], columns: string[]) => void,
470
- ): void {
471
- const release = gate.enter();
472
- let result: NativeExecResult;
473
- try {
474
- result = database.execSync(sql);
475
- } catch (error) {
476
- enrichNativeDatabaseError(database, error);
477
- } finally {
478
- release();
479
- }
480
- if (callback) {
481
- for (const row of result.rows) {
482
- callback(row, result.columns);
483
- }
484
- }
485
- },
486
395
  async execute(
487
396
  sql: string,
488
397
  params?: SqliteBindings,
489
398
  ): Promise<SqliteExecuteResult> {
490
399
  return await executeNative(sql, params);
491
400
  },
492
- executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult {
493
- return executeNativeSync(sql, params);
494
- },
495
401
  async executeBatch(
496
402
  statements: SqliteBatchStatement[],
497
403
  ): Promise<SqliteExecuteResult[]> {
@@ -502,7 +408,10 @@ export function wrapJsNativeDatabase(
502
408
  const results = database.executeBatch
503
409
  ? await database.executeBatch(nativeStatements)
504
410
  : await (async () => {
505
- transaction = await database.beginTransaction();
411
+ transaction = await database.beginTransaction(
412
+ undefined,
413
+ EXECUTE_BATCH_TRANSACTION_NAME,
414
+ );
506
415
  const transactionResults: NativeExecuteResult[] =
507
416
  [];
508
417
  for (const statement of nativeStatements) {
@@ -518,7 +427,7 @@ export function wrapJsNativeDatabase(
518
427
  return transactionResults;
519
428
  })();
520
429
  for (const result of results) {
521
- if (result.lastInsertRowId != null) {
430
+ if (result.lastInsertRowId !== undefined) {
522
431
  lastInsertRowId = result.lastInsertRowId;
523
432
  }
524
433
  }
@@ -550,26 +459,7 @@ export function wrapJsNativeDatabase(
550
459
  release();
551
460
  }
552
461
  return wrapTransaction(database, transaction, gate, (result) => {
553
- if (result.lastInsertRowId != null) {
554
- lastInsertRowId = result.lastInsertRowId;
555
- }
556
- });
557
- },
558
- beginTransactionSync(
559
- timeoutMs?: number,
560
- name?: string,
561
- ): SynchronousSqliteTransactionDatabase {
562
- const release = gate.enter();
563
- let transaction: JsNativeSynchronousTransactionLike;
564
- try {
565
- transaction = database.beginTransactionSync(timeoutMs, name);
566
- } catch (error) {
567
- enrichNativeDatabaseError(database, error);
568
- } finally {
569
- release();
570
- }
571
- return wrapTransaction(database, transaction, gate, (result) => {
572
- if (result.lastInsertRowId != null) {
462
+ if (result.lastInsertRowId !== undefined) {
573
463
  lastInsertRowId = result.lastInsertRowId;
574
464
  }
575
465
  });
@@ -577,6 +467,7 @@ export function wrapJsNativeDatabase(
577
467
  async beginStateTransaction(
578
468
  timeoutMs?: number,
579
469
  context?: unknown,
470
+ name?: string,
580
471
  ): Promise<SqliteTransactionDatabase> {
581
472
  if (!database.beginStateTransaction) {
582
473
  throw new Error("actor state transactions are not configured");
@@ -587,6 +478,7 @@ export function wrapJsNativeDatabase(
587
478
  transaction = await database.beginStateTransaction(
588
479
  timeoutMs,
589
480
  context,
481
+ name,
590
482
  );
591
483
  } catch (error) {
592
484
  enrichNativeDatabaseError(database, error);
@@ -594,7 +486,7 @@ export function wrapJsNativeDatabase(
594
486
  release();
595
487
  }
596
488
  return wrapTransaction(database, transaction, gate, (result) => {
597
- if (result.lastInsertRowId != null) {
489
+ if (result.lastInsertRowId !== undefined) {
598
490
  lastInsertRowId = result.lastInsertRowId;
599
491
  }
600
492
  });
@@ -609,25 +501,6 @@ export function wrapJsNativeDatabase(
609
501
  nativeMetrics(): SqliteNativeMetrics | null {
610
502
  return normalizeNativeMetrics(database.metrics?.());
611
503
  },
612
- async open(): Promise<void> {
613
- const release = gate.enter();
614
- try {
615
- await database.open();
616
- } catch (error) {
617
- enrichNativeDatabaseError(database, error);
618
- } finally {
619
- release();
620
- }
621
- },
622
- commitTicket(): number {
623
- return database.commitTicket();
624
- },
625
- async whenDurable(ticket: number): Promise<void> {
626
- await database.whenDurable(ticket);
627
- },
628
- abortGeneration(reason: string): void {
629
- database.abortGeneration(reason);
630
- },
631
504
  async close(): Promise<void> {
632
505
  terminalPromise ??= gate.close(() => database.close());
633
506
  await terminalPromise;
@@ -639,25 +512,13 @@ export function wrapJsNativeDatabase(
639
512
  };
640
513
  }
641
514
 
642
- function wrapTransaction(
643
- database: JsNativeDatabaseLike,
644
- transaction: JsNativeSynchronousTransactionLike,
645
- gate: NativeCloseGate,
646
- onExecute: (result: NativeExecuteResult) => void,
647
- ): SynchronousSqliteTransactionDatabase;
648
- function wrapTransaction(
649
- database: JsNativeDatabaseLike,
650
- transaction: JsNativeTransactionLike,
651
- gate: NativeCloseGate,
652
- onExecute: (result: NativeExecuteResult) => void,
653
- ): SqliteTransactionDatabase;
654
515
  function wrapTransaction(
655
516
  database: JsNativeDatabaseLike,
656
517
  transaction: JsNativeTransactionLike,
657
518
  gate: NativeCloseGate,
658
519
  onExecute: (result: NativeExecuteResult) => void,
659
520
  ): SqliteTransactionDatabase {
660
- const wrapped: SqliteTransactionDatabase = {
521
+ return {
661
522
  async exec(sql, callback) {
662
523
  const release = gate.enter();
663
524
  let result: NativeExecResult;
@@ -708,66 +569,6 @@ function wrapTransaction(
708
569
  }
709
570
  },
710
571
  };
711
-
712
- if (isSynchronousTransaction(transaction)) {
713
- return Object.assign(wrapped, {
714
- execSync(
715
- sql: string,
716
- callback?: (row: unknown[], columns: string[]) => void,
717
- ) {
718
- const release = gate.enter();
719
- let result: NativeExecResult;
720
- try {
721
- result = transaction.execSync(sql);
722
- } catch (error) {
723
- enrichNativeDatabaseError(database, error);
724
- } finally {
725
- release();
726
- }
727
- if (callback) {
728
- for (const row of result.rows)
729
- callback(row, result.columns);
730
- }
731
- },
732
- executeSync(sql: string, params?: SqliteBindings) {
733
- const release = gate.enter();
734
- try {
735
- const result = transaction.executeSync(
736
- sql,
737
- toNativeBindings(sql, params),
738
- );
739
- onExecute(result);
740
- return result;
741
- } catch (error) {
742
- enrichNativeDatabaseError(database, error);
743
- } finally {
744
- release();
745
- }
746
- },
747
- commitSync() {
748
- const release = gate.enter();
749
- try {
750
- transaction.commitSync();
751
- } catch (error) {
752
- enrichNativeDatabaseError(database, error);
753
- } finally {
754
- release();
755
- }
756
- },
757
- rollbackSync() {
758
- const release = gate.enter();
759
- try {
760
- transaction.rollbackSync();
761
- } catch (error) {
762
- enrichNativeDatabaseError(database, error);
763
- } finally {
764
- release();
765
- }
766
- },
767
- }) as SynchronousSqliteTransactionDatabase;
768
- }
769
-
770
- return wrapped;
771
572
  }
772
573
 
773
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-provided actor stop threshold once the node connects. A
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.
@@ -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 `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;
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.#actorStopThresholdMs(
827
+ : ((await this.#shutdownBudgetMs(
827
828
  modeAPromise ?? modeBPromise,
828
- )) ?? DEFAULT_ACTOR_STOP_THRESHOLD_MS);
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 actor stop threshold.
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 #actorStopThresholdMs(
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 thresholdMs =
904
- await runtime.registryActorStopThresholdMs?.(registry);
905
+ const budgetMs = await runtime.registryShutdownBudgetMs?.(registry);
905
906
  if (
906
- thresholdMs !== undefined &&
907
- Number.isFinite(thresholdMs) &&
908
- thresholdMs > 0
907
+ budgetMs !== undefined &&
908
+ Number.isFinite(budgetMs) &&
909
+ budgetMs > 0
909
910
  ) {
910
- return thresholdMs;
911
+ return budgetMs;
911
912
  }
912
913
  } catch (err) {
913
914
  logger().warn(
914
915
  { err },
915
- "failed to read actor stop threshold for shutdown grace",
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 registryActorStopThresholdMs(
348
+ async registryShutdownBudgetMs(
349
349
  registry: RegistryHandle,
350
350
  ): Promise<number | undefined> {
351
351
  return (
352
- (await asNativeRegistry(registry).actorStopThresholdMs()) ??
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,45 +934,25 @@ 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,
951
+ name?: string,
1011
952
  ): Promise<ActorStateTransactionHandle> {
1012
953
  return (await this.#actorContextForOperation(ctx).beginStateTransaction(
1013
954
  timeoutMs,
955
+ name,
1014
956
  )) as unknown as ActorStateTransactionHandle;
1015
957
  }
1016
958
 
@@ -1068,25 +1010,6 @@ export class NapiCoreRuntime implements CoreRuntime {
1068
1010
  return this.#actorSql(ctx).takeLastKvError?.() ?? null;
1069
1011
  }
1070
1012
 
1071
- async actorSqlOpen(ctx: ActorContextHandle): Promise<void> {
1072
- await this.#actorSql(ctx).open();
1073
- }
1074
-
1075
- actorSqlCommitTicket(ctx: ActorContextHandle): number {
1076
- return this.#actorSql(ctx).commitTicket();
1077
- }
1078
-
1079
- actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void {
1080
- this.#actorSql(ctx).abortGeneration(reason);
1081
- }
1082
-
1083
- async actorSqlWhenDurable(
1084
- ctx: ActorContextHandle,
1085
- ticket: number,
1086
- ): Promise<void> {
1087
- await this.#actorSql(ctx).whenDurable(ticket);
1088
- }
1089
-
1090
1013
  async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
1091
1014
  const nativeCtx = asNativeActorContext(ctx);
1092
1015
  if (!this.#sqlOpened.delete(nativeCtx)) {