rivetkit 3.1.1 → 3.1.2-rc.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.
Files changed (95) hide show
  1. package/dist/browser/client.d.ts +41 -0
  2. package/dist/browser/client.js +1 -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-JWREVWQL.js → chunk-5RE3IF3C.js} +2 -2
  7. package/dist/tsup/{chunk-HXFGYYOA.js → chunk-7PUO5YRK.js} +3 -3
  8. package/dist/tsup/{chunk-FBRWBUUV.js → chunk-DKVKYLXH.js} +4 -4
  9. package/dist/tsup/{chunk-62DUEJF5.cjs → chunk-GI3TPFCE.cjs} +2 -2
  10. package/dist/tsup/chunk-GI3TPFCE.cjs.map +1 -0
  11. package/dist/tsup/{chunk-C4U5WWM6.js → chunk-J5ZNIJT3.js} +2 -2
  12. package/dist/tsup/{chunk-KTZWFOBF.cjs → chunk-KOB3RR6D.cjs} +7 -7
  13. package/dist/tsup/{chunk-KTZWFOBF.cjs.map → chunk-KOB3RR6D.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-HPVDAB3Q.js → chunk-LNMODE5R.js} +2 -2
  15. package/dist/tsup/{chunk-ZZQFX3FC.cjs → chunk-MM6QYEV7.cjs} +146 -146
  16. package/dist/tsup/{chunk-ZZQFX3FC.cjs.map → chunk-MM6QYEV7.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-O4QOORVK.cjs → chunk-R2GD2TDD.cjs} +3 -3
  18. package/dist/tsup/{chunk-O4QOORVK.cjs.map → chunk-R2GD2TDD.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-RROV4JN4.js → chunk-SPLLB6BX.js} +2 -2
  20. package/dist/tsup/{chunk-2X7ZRXPW.cjs → chunk-TR5YB355.cjs} +3 -3
  21. package/dist/tsup/{chunk-2X7ZRXPW.cjs.map → chunk-TR5YB355.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-SPSBNPLC.cjs → chunk-TYNEZVC2.cjs} +3 -3
  23. package/dist/tsup/{chunk-SPSBNPLC.cjs.map → chunk-TYNEZVC2.cjs.map} +1 -1
  24. package/dist/tsup/{chunk-IROHORSE.cjs → chunk-VUFOIAKH.cjs} +10 -10
  25. package/dist/tsup/{chunk-IROHORSE.cjs.map → chunk-VUFOIAKH.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-CSYHVROJ.js → chunk-WD6L6OTX.js} +2 -2
  27. package/dist/tsup/chunk-WD6L6OTX.js.map +1 -0
  28. package/dist/tsup/{chunk-AGFOGGFH.cjs → chunk-YPJ3QEDL.cjs} +4 -4
  29. package/dist/tsup/{chunk-AGFOGGFH.cjs.map → chunk-YPJ3QEDL.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-IULKFTST.js → chunk-YT77YM32.js} +3 -3
  31. package/dist/tsup/client/mod.cjs +5 -5
  32. package/dist/tsup/client/mod.d.cts +3 -3
  33. package/dist/tsup/client/mod.d.ts +3 -3
  34. package/dist/tsup/client/mod.js +4 -4
  35. package/dist/tsup/common/log.cjs +2 -2
  36. package/dist/tsup/common/log.js +1 -1
  37. package/dist/tsup/common/websocket.cjs +3 -3
  38. package/dist/tsup/common/websocket.js +2 -2
  39. package/dist/tsup/{config-BDdeBoxX.d.cts → config-CTGjM4A5.d.cts} +16 -1
  40. package/dist/tsup/{config-Ch-SMJ-n.d.ts → config-DLXQ_TVP.d.ts} +16 -1
  41. package/dist/tsup/{config-CBTr4IhE.d.cts → config-Df5jOcde.d.cts} +26 -0
  42. package/dist/tsup/{config-CBTr4IhE.d.ts → config-Df5jOcde.d.ts} +26 -0
  43. package/dist/tsup/{context-B-wRuYrf.d.ts → context-Dmz9Hd6K.d.ts} +2 -2
  44. package/dist/tsup/{context-NzsxAAoN.d.cts → context-S-Y75hj1.d.cts} +2 -2
  45. package/dist/tsup/db/drizzle.cjs +2 -2
  46. package/dist/tsup/db/drizzle.d.cts +1 -1
  47. package/dist/tsup/db/drizzle.d.ts +1 -1
  48. package/dist/tsup/db/drizzle.js +1 -1
  49. package/dist/tsup/db/mod.cjs +3 -3
  50. package/dist/tsup/db/mod.d.cts +2 -2
  51. package/dist/tsup/db/mod.d.ts +2 -2
  52. package/dist/tsup/db/mod.js +2 -2
  53. package/dist/tsup/dynamic/mod.d.cts +2 -2
  54. package/dist/tsup/dynamic/mod.d.ts +2 -2
  55. package/dist/tsup/inspector/mod.cjs +5 -5
  56. package/dist/tsup/inspector/mod.js +4 -4
  57. package/dist/tsup/inspector/workflow.cjs +4 -4
  58. package/dist/tsup/inspector/workflow.js +3 -3
  59. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  60. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  61. package/dist/tsup/mod.cjs +380 -121
  62. package/dist/tsup/mod.cjs.map +1 -1
  63. package/dist/tsup/mod.d.cts +4 -4
  64. package/dist/tsup/mod.d.ts +4 -4
  65. package/dist/tsup/mod.js +300 -41
  66. package/dist/tsup/mod.js.map +1 -1
  67. package/dist/tsup/test/mod.cjs +6 -6
  68. package/dist/tsup/test/mod.d.cts +2 -2
  69. package/dist/tsup/test/mod.d.ts +2 -2
  70. package/dist/tsup/test/mod.js +4 -4
  71. package/dist/tsup/unstable/migrations.d.cts +1 -1
  72. package/dist/tsup/unstable/migrations.d.ts +1 -1
  73. package/dist/tsup/utils.cjs +2 -2
  74. package/dist/tsup/utils.js +1 -1
  75. package/dist/tsup/workflow/mod.cjs +7 -7
  76. package/dist/tsup/workflow/mod.cjs.map +1 -1
  77. package/dist/tsup/workflow/mod.d.cts +4 -4
  78. package/dist/tsup/workflow/mod.d.ts +4 -4
  79. package/dist/tsup/workflow/mod.js +4 -4
  80. package/package.json +9 -9
  81. package/src/common/database/config.ts +39 -0
  82. package/src/common/database/native-database.ts +230 -21
  83. package/src/registry/napi-runtime.ts +78 -0
  84. package/src/registry/native.ts +57 -17
  85. package/src/registry/runtime.ts +52 -0
  86. package/src/registry/wasm-runtime.ts +88 -0
  87. package/dist/tsup/chunk-62DUEJF5.cjs.map +0 -1
  88. package/dist/tsup/chunk-CSYHVROJ.js.map +0 -1
  89. /package/dist/tsup/{chunk-JWREVWQL.js.map → chunk-5RE3IF3C.js.map} +0 -0
  90. /package/dist/tsup/{chunk-HXFGYYOA.js.map → chunk-7PUO5YRK.js.map} +0 -0
  91. /package/dist/tsup/{chunk-FBRWBUUV.js.map → chunk-DKVKYLXH.js.map} +0 -0
  92. /package/dist/tsup/{chunk-C4U5WWM6.js.map → chunk-J5ZNIJT3.js.map} +0 -0
  93. /package/dist/tsup/{chunk-HPVDAB3Q.js.map → chunk-LNMODE5R.js.map} +0 -0
  94. /package/dist/tsup/{chunk-RROV4JN4.js.map → chunk-SPLLB6BX.js.map} +0 -0
  95. /package/dist/tsup/{chunk-IULKFTST.js.map → chunk-YT77YM32.js.map} +0 -0
@@ -133,7 +133,12 @@ export interface SqliteDatabase {
133
133
  sql: string,
134
134
  callback?: (row: unknown[], columns: string[]) => void,
135
135
  ): Promise<void>;
136
+ execSync?(
137
+ sql: string,
138
+ callback?: (row: unknown[], columns: string[]) => void,
139
+ ): void;
136
140
  execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
141
+ executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
137
142
  executeBatch(
138
143
  statements: SqliteBatchStatement[],
139
144
  ): Promise<SqliteExecuteResult[]>;
@@ -141,12 +146,31 @@ export interface SqliteDatabase {
141
146
  timeoutMs?: number,
142
147
  name?: string,
143
148
  ): Promise<SqliteTransactionDatabase>;
149
+ beginTransactionSync?(
150
+ timeoutMs?: number,
151
+ name?: string,
152
+ ): SynchronousSqliteTransactionDatabase;
144
153
  run(sql: string, params?: SqliteBindings): Promise<void>;
145
154
  query(sql: string, params?: SqliteBindings): Promise<SqliteQueryResult>;
146
155
  nativeMetrics?():
147
156
  | SqliteNativeMetrics
148
157
  | Promise<SqliteNativeMetrics | null>
149
158
  | null;
159
+ /**
160
+ * Returns the ticket of the latest local commit. Synchronous writes return before they are
161
+ * durable; pass the ticket to `whenDurable` before releasing output that depends on them.
162
+ */
163
+ commitTicket?(): number;
164
+ /**
165
+ * Resolves once the commit `ticket` names and every earlier commit are durable. Rejects with
166
+ * `sqlite.durability_failed` once the database broke and the actor is restarting.
167
+ */
168
+ whenDurable?(ticket: number): Promise<void>;
169
+ /**
170
+ * Restarts the owning actor from durable state. Every later write fails, including the final
171
+ * state save. For native database providers whose in-memory state can no longer be trusted.
172
+ */
173
+ abortGeneration?(reason: string): void;
150
174
  close(): Promise<void>;
151
175
  }
152
176
 
@@ -155,11 +179,26 @@ export interface SqliteTransactionDatabase {
155
179
  sql: string,
156
180
  callback?: (row: unknown[], columns: string[]) => void,
157
181
  ): Promise<void>;
182
+ execSync?(
183
+ sql: string,
184
+ callback?: (row: unknown[], columns: string[]) => void,
185
+ ): void;
158
186
  execute(sql: string, params?: SqliteBindings): Promise<SqliteExecuteResult>;
187
+ executeSync?(sql: string, params?: SqliteBindings): SqliteExecuteResult;
159
188
  commit(): Promise<void>;
160
189
  rollback(): Promise<void>;
161
190
  }
162
191
 
192
+ export type SynchronousSqliteTransactionDatabase = SqliteTransactionDatabase & {
193
+ execSync(
194
+ sql: string,
195
+ callback?: (row: unknown[], columns: string[]) => void,
196
+ ): void;
197
+ executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult;
198
+ commitSync(): void;
199
+ rollbackSync(): void;
200
+ };
201
+
163
202
  /**
164
203
  * Provider for opening native databases from the active runtime.
165
204
  */
@@ -6,6 +6,7 @@ import type {
6
6
  SqliteExecuteResult,
7
7
  SqliteNativeMetrics,
8
8
  SqliteTransactionDatabase,
9
+ SynchronousSqliteTransactionDatabase,
9
10
  } from "./config";
10
11
 
11
12
  type NativeBindNoValues = {
@@ -74,10 +75,15 @@ interface NativeBatchStatement {
74
75
 
75
76
  export interface JsNativeDatabaseLike {
76
77
  exec(sql: string): Promise<NativeExecResult>;
78
+ execSync(sql: string): NativeExecResult;
77
79
  execute(
78
80
  sql: string,
79
81
  params?: NativeBindParam[] | null,
80
82
  ): Promise<NativeExecuteResult>;
83
+ executeSync(
84
+ sql: string,
85
+ params?: NativeBindParam[] | null,
86
+ ): NativeExecuteResult;
81
87
  executeBatch?(
82
88
  statements: NativeBatchStatement[],
83
89
  ): Promise<NativeExecuteResult[]>;
@@ -89,6 +95,10 @@ export interface JsNativeDatabaseLike {
89
95
  timeoutMs?: number,
90
96
  name?: string,
91
97
  ): Promise<JsNativeTransactionLike>;
98
+ beginTransactionSync(
99
+ timeoutMs?: number,
100
+ name?: string,
101
+ ): JsNativeSynchronousTransactionLike;
92
102
  query(
93
103
  sql: string,
94
104
  params?: NativeBindParam[] | null,
@@ -99,9 +109,16 @@ export interface JsNativeDatabaseLike {
99
109
  ): Promise<NativeRunResult>;
100
110
  metrics?(): SqliteNativeMetrics | null;
101
111
  takeLastKvError?(): string | null;
112
+ open(): Promise<void>;
113
+ commitTicket(): number;
114
+ whenDurable(ticket: number): Promise<void>;
115
+ abortGeneration(reason: string): void;
102
116
  close(): Promise<void>;
103
117
  }
104
118
  export type StateAwareSqliteDatabase = SqliteDatabase & {
119
+ open(): Promise<void>;
120
+ commitTicket(): number;
121
+ whenDurable(ticket: number): Promise<void>;
105
122
  beginStateTransaction(
106
123
  timeoutMs?: number,
107
124
  context?: unknown,
@@ -123,6 +140,28 @@ export interface JsNativeTransactionLike {
123
140
  rollback(): Promise<void>;
124
141
  }
125
142
 
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
+
126
165
  function shouldAttachNativeKvError(message: string): boolean {
127
166
  return /i\/o error|unable to open database file/i.test(message);
128
167
  }
@@ -161,13 +200,19 @@ function toNativeBinding(arg: unknown): NativeBindParam {
161
200
  if (arg === null || arg === undefined) {
162
201
  return { kind: "null" };
163
202
  }
164
- if (typeof arg === "bigint") {
165
- return { kind: "int", intValue: Number(arg) };
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 };
166
214
  }
167
215
  if (typeof arg === "number") {
168
- if (Number.isInteger(arg)) {
169
- return { kind: "int", intValue: arg };
170
- }
171
216
  return { kind: "float", floatValue: arg };
172
217
  }
173
218
  if (typeof arg === "string") {
@@ -185,9 +230,13 @@ function toNativeBinding(arg: unknown): NativeBindParam {
185
230
  function extractNamedSqliteParameters(sql: string): string[] {
186
231
  const orderedNames: string[] = [];
187
232
  const seen = new Set<string>();
188
- const pattern = /([:@$][A-Za-z_][A-Za-z0-9_]*)/g;
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;
189
237
  for (const match of sql.matchAll(pattern)) {
190
238
  const name = match[1];
239
+ if (!name) continue;
191
240
  if (seen.has(name)) {
192
241
  continue;
193
242
  }
@@ -341,21 +390,49 @@ export function wrapJsNativeDatabase(
341
390
  sql: string,
342
391
  params?: SqliteBindings,
343
392
  ): Promise<SqliteExecuteResult> => {
344
- const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
345
- if (lastInsertRowIdColumn) {
346
- return {
347
- columns: [lastInsertRowIdColumn],
348
- rows: [[lastInsertRowId ?? 0]],
349
- changes: 0,
350
- lastInsertRowId,
351
- };
352
- }
353
-
354
393
  const release = gate.enter();
355
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
+
356
405
  const nativeParams = toNativeBindings(sql, params);
357
406
  const result = await database.execute(sql, nativeParams);
358
- if (result.lastInsertRowId !== undefined) {
407
+ if (result.lastInsertRowId != null) {
408
+ lastInsertRowId = result.lastInsertRowId;
409
+ }
410
+ return result;
411
+ } catch (error) {
412
+ enrichNativeDatabaseError(database, error);
413
+ } finally {
414
+ release();
415
+ }
416
+ };
417
+ const executeNativeSync = (
418
+ sql: string,
419
+ params?: SqliteBindings,
420
+ ): SqliteExecuteResult => {
421
+ const release = gate.enter();
422
+ try {
423
+ 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) {
359
436
  lastInsertRowId = result.lastInsertRowId;
360
437
  }
361
438
  return result;
@@ -387,12 +464,34 @@ export function wrapJsNativeDatabase(
387
464
  callback(row, result.columns);
388
465
  }
389
466
  },
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
+ },
390
486
  async execute(
391
487
  sql: string,
392
488
  params?: SqliteBindings,
393
489
  ): Promise<SqliteExecuteResult> {
394
490
  return await executeNative(sql, params);
395
491
  },
492
+ executeSync(sql: string, params?: SqliteBindings): SqliteExecuteResult {
493
+ return executeNativeSync(sql, params);
494
+ },
396
495
  async executeBatch(
397
496
  statements: SqliteBatchStatement[],
398
497
  ): Promise<SqliteExecuteResult[]> {
@@ -419,7 +518,7 @@ export function wrapJsNativeDatabase(
419
518
  return transactionResults;
420
519
  })();
421
520
  for (const result of results) {
422
- if (result.lastInsertRowId !== undefined) {
521
+ if (result.lastInsertRowId != null) {
423
522
  lastInsertRowId = result.lastInsertRowId;
424
523
  }
425
524
  }
@@ -451,7 +550,26 @@ export function wrapJsNativeDatabase(
451
550
  release();
452
551
  }
453
552
  return wrapTransaction(database, transaction, gate, (result) => {
454
- if (result.lastInsertRowId !== undefined) {
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) {
455
573
  lastInsertRowId = result.lastInsertRowId;
456
574
  }
457
575
  });
@@ -476,7 +594,7 @@ export function wrapJsNativeDatabase(
476
594
  release();
477
595
  }
478
596
  return wrapTransaction(database, transaction, gate, (result) => {
479
- if (result.lastInsertRowId !== undefined) {
597
+ if (result.lastInsertRowId != null) {
480
598
  lastInsertRowId = result.lastInsertRowId;
481
599
  }
482
600
  });
@@ -491,6 +609,25 @@ export function wrapJsNativeDatabase(
491
609
  nativeMetrics(): SqliteNativeMetrics | null {
492
610
  return normalizeNativeMetrics(database.metrics?.());
493
611
  },
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
+ },
494
631
  async close(): Promise<void> {
495
632
  terminalPromise ??= gate.close(() => database.close());
496
633
  await terminalPromise;
@@ -502,13 +639,25 @@ export function wrapJsNativeDatabase(
502
639
  };
503
640
  }
504
641
 
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;
505
654
  function wrapTransaction(
506
655
  database: JsNativeDatabaseLike,
507
656
  transaction: JsNativeTransactionLike,
508
657
  gate: NativeCloseGate,
509
658
  onExecute: (result: NativeExecuteResult) => void,
510
659
  ): SqliteTransactionDatabase {
511
- return {
660
+ const wrapped: SqliteTransactionDatabase = {
512
661
  async exec(sql, callback) {
513
662
  const release = gate.enter();
514
663
  let result: NativeExecResult;
@@ -559,6 +708,66 @@ function wrapTransaction(
559
708
  }
560
709
  },
561
710
  };
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;
562
771
  }
563
772
 
564
773
  function lastInsertRowIdColumnName(sql: string): string | undefined {
@@ -883,6 +883,13 @@ export class NapiCoreRuntime implements CoreRuntime {
883
883
  return await this.#actorSql(ctx).exec(sql);
884
884
  }
885
885
 
886
+ actorSqlExecSync(
887
+ ctx: ActorContextHandle,
888
+ sql: string,
889
+ ): RuntimeSqlExecResult {
890
+ return this.#actorSql(ctx).execSync(sql);
891
+ }
892
+
886
893
  async actorSqlExecute(
887
894
  ctx: ActorContextHandle,
888
895
  sql: string,
@@ -895,6 +902,18 @@ export class NapiCoreRuntime implements CoreRuntime {
895
902
  return normalizeRuntimeSqlExecuteResult(result);
896
903
  }
897
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
+
898
917
  async actorSqlExecuteBatch(
899
918
  ctx: ActorContextHandle,
900
919
  statements: RuntimeSqlBatchStatement[],
@@ -916,6 +935,17 @@ export class NapiCoreRuntime implements CoreRuntime {
916
935
  )) as unknown as SqliteTransactionHandle;
917
936
  }
918
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
+
919
949
  async actorSqlTransactionExec(
920
950
  transaction: SqliteTransactionHandle,
921
951
  sql: string,
@@ -923,6 +953,13 @@ export class NapiCoreRuntime implements CoreRuntime {
923
953
  return await asNativeSqlTransaction(transaction).exec(sql);
924
954
  }
925
955
 
956
+ actorSqlTransactionExecSync(
957
+ transaction: SqliteTransactionHandle,
958
+ sql: string,
959
+ ): RuntimeSqlExecResult {
960
+ return asNativeSqlTransaction(transaction).execSync(sql);
961
+ }
962
+
926
963
  async actorSqlTransactionExecute(
927
964
  transaction: SqliteTransactionHandle,
928
965
  sql: string,
@@ -935,17 +972,39 @@ export class NapiCoreRuntime implements CoreRuntime {
935
972
  return normalizeRuntimeSqlExecuteResult(result);
936
973
  }
937
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
+
938
987
  async actorSqlTransactionCommit(
939
988
  transaction: SqliteTransactionHandle,
940
989
  ): Promise<void> {
941
990
  await asNativeSqlTransaction(transaction).commit();
942
991
  }
943
992
 
993
+ actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
994
+ asNativeSqlTransaction(transaction).commitSync();
995
+ }
996
+
944
997
  async actorSqlTransactionRollback(
945
998
  transaction: SqliteTransactionHandle,
946
999
  ): Promise<void> {
947
1000
  await asNativeSqlTransaction(transaction).rollback();
948
1001
  }
1002
+
1003
+ actorSqlTransactionRollbackSync(
1004
+ transaction: SqliteTransactionHandle,
1005
+ ): void {
1006
+ asNativeSqlTransaction(transaction).rollbackSync();
1007
+ }
949
1008
  async actorBeginStateTransaction(
950
1009
  ctx: ActorContextHandle,
951
1010
  timeoutMs?: number,
@@ -1009,6 +1068,25 @@ export class NapiCoreRuntime implements CoreRuntime {
1009
1068
  return this.#actorSql(ctx).takeLastKvError?.() ?? null;
1010
1069
  }
1011
1070
 
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
+
1012
1090
  async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
1013
1091
  const nativeCtx = asNativeActorContext(ctx);
1014
1092
  if (!this.#sqlOpened.delete(nativeCtx)) {