@rivetkit/supabase 0.0.0-stack-chore-sync-engine-changes-from-enterprise-mszropyy.677d526 → 0.0.0-sync-sqlite.0ed739a

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 (3) hide show
  1. package/dist/mod.js +428 -66
  2. package/dist/mod.mjs +428 -66
  3. package/package.json +3 -3
package/dist/mod.js CHANGED
@@ -519,7 +519,7 @@ function unsupportedFeature(feature) {
519
519
  );
520
520
  }
521
521
 
522
- // ../rivetkit/dist/tsup/chunk-GPD77M3M.js
522
+ // ../rivetkit/dist/tsup/chunk-NNPIJLBE.js
523
523
  var import_pino = require("pino");
524
524
 
525
525
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
@@ -13192,7 +13192,7 @@ var classic_default = external_exports;
13192
13192
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
13193
13193
  var v4_default = classic_default;
13194
13194
 
13195
- // ../rivetkit/dist/tsup/chunk-GPD77M3M.js
13195
+ // ../rivetkit/dist/tsup/chunk-NNPIJLBE.js
13196
13196
  var cbor = __toESM(require("cbor-x"), 1);
13197
13197
  var import_invariant = __toESM(require_invariant(), 1);
13198
13198
  var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
@@ -13366,7 +13366,7 @@ function noopNext() {
13366
13366
  }
13367
13367
  var package_default = {
13368
13368
  name: "rivetkit",
13369
- version: "0.0.0-stack-chore-sync-engine-changes-from-enterprise-mszropyy.677d526",
13369
+ version: "0.0.0-sync-sqlite.0ed739a",
13370
13370
  description: "Lightweight libraries for building stateful actors on edge platforms",
13371
13371
  license: "Apache-2.0",
13372
13372
  keywords: [
@@ -14670,7 +14670,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
14670
14670
  };
14671
14671
  }
14672
14672
 
14673
- // ../rivetkit/dist/tsup/chunk-M4RSGECU.js
14673
+ // ../rivetkit/dist/tsup/chunk-EHAGZJ34.js
14674
14674
  var config2 = /* @__PURE__ */ Config({});
14675
14675
  function readWorkflowCbor(bc) {
14676
14676
  return readData(bc);
@@ -15549,45 +15549,7 @@ function removePrefixFromKey(prefixedKey) {
15549
15549
  return prefixedKey.slice(KEYS.KV.length);
15550
15550
  }
15551
15551
 
15552
- // ../rivetkit/dist/tsup/chunk-L6DNN72S.js
15553
- function logger() {
15554
- return getLogger("actor-client");
15555
- }
15556
- var webSocketPromise = null;
15557
- async function importWebSocket() {
15558
- if (webSocketPromise !== null) {
15559
- return webSocketPromise;
15560
- }
15561
- webSocketPromise = (async () => {
15562
- let _WebSocket;
15563
- if (typeof WebSocket !== "undefined") {
15564
- _WebSocket = WebSocket;
15565
- } else {
15566
- try {
15567
- const moduleName = "ws";
15568
- const ws = await import(
15569
- /* webpackIgnore: true */
15570
- moduleName
15571
- );
15572
- _WebSocket = ws.default;
15573
- logger().debug("using websocket from npm");
15574
- } catch {
15575
- _WebSocket = class MockWebSocket {
15576
- constructor() {
15577
- throw new Error(
15578
- 'WebSocket support requires installing the "ws" peer dependency.'
15579
- );
15580
- }
15581
- };
15582
- logger().debug("using mock websocket");
15583
- }
15584
- }
15585
- return _WebSocket;
15586
- })();
15587
- return webSocketPromise;
15588
- }
15589
-
15590
- // ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
15552
+ // ../rivetkit/dist/tsup/chunk-WCEJTJHO.js
15591
15553
  var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
15592
15554
  function isManualTransactionControl(query) {
15593
15555
  return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
@@ -15607,6 +15569,38 @@ function validateTransactionName(name) {
15607
15569
  throw new Error("db.transaction() name must not be empty");
15608
15570
  }
15609
15571
  }
15572
+ function isPromiseLike(value) {
15573
+ return typeof value === "object" && value !== null || typeof value === "function" ? typeof value.then === "function" : false;
15574
+ }
15575
+ function runSqliteTransactionSync(database, callback, options) {
15576
+ validateTransactionTimeout(options == null ? void 0 : options.timeout);
15577
+ validateTransactionName(options == null ? void 0 : options.name);
15578
+ if (!database.beginTransactionSync) {
15579
+ throw new Error(
15580
+ "Synchronous SQLite transactions are only available in the Node.js native runtime."
15581
+ );
15582
+ }
15583
+ const transaction = database.beginTransactionSync(
15584
+ options == null ? void 0 : options.timeout,
15585
+ options == null ? void 0 : options.name
15586
+ );
15587
+ try {
15588
+ const result = callback(transaction);
15589
+ if (isPromiseLike(result)) {
15590
+ throw new Error(
15591
+ "db.transactionSync() callback must complete synchronously and must not return a promise."
15592
+ );
15593
+ }
15594
+ transaction.commitSync();
15595
+ return result;
15596
+ } catch (error46) {
15597
+ try {
15598
+ transaction.rollbackSync();
15599
+ } catch {
15600
+ }
15601
+ throw error46;
15602
+ }
15603
+ }
15610
15604
  function isSqliteBindingValue(value) {
15611
15605
  if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
15612
15606
  return true;
@@ -15670,7 +15664,45 @@ var AsyncMutex = class {
15670
15664
  }
15671
15665
  };
15672
15666
 
15673
- // ../rivetkit/dist/tsup/chunk-OWSXJF7Z.js
15667
+ // ../rivetkit/dist/tsup/chunk-SLAKWYOH.js
15668
+ function logger() {
15669
+ return getLogger("actor-client");
15670
+ }
15671
+ var webSocketPromise = null;
15672
+ async function importWebSocket() {
15673
+ if (webSocketPromise !== null) {
15674
+ return webSocketPromise;
15675
+ }
15676
+ webSocketPromise = (async () => {
15677
+ let _WebSocket;
15678
+ if (typeof WebSocket !== "undefined") {
15679
+ _WebSocket = WebSocket;
15680
+ } else {
15681
+ try {
15682
+ const moduleName = "ws";
15683
+ const ws = await import(
15684
+ /* webpackIgnore: true */
15685
+ moduleName
15686
+ );
15687
+ _WebSocket = ws.default;
15688
+ logger().debug("using websocket from npm");
15689
+ } catch {
15690
+ _WebSocket = class MockWebSocket {
15691
+ constructor() {
15692
+ throw new Error(
15693
+ 'WebSocket support requires installing the "ws" peer dependency.'
15694
+ );
15695
+ }
15696
+ };
15697
+ logger().debug("using mock websocket");
15698
+ }
15699
+ }
15700
+ return _WebSocket;
15701
+ })();
15702
+ return webSocketPromise;
15703
+ }
15704
+
15705
+ // ../rivetkit/dist/tsup/chunk-BERJKIW5.js
15674
15706
  var import_invariant2 = __toESM(require_invariant(), 1);
15675
15707
 
15676
15708
  // ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
@@ -15848,7 +15880,7 @@ function createVersionedDataHandler(config3) {
15848
15880
  return new VersionedDataHandler(config3);
15849
15881
  }
15850
15882
 
15851
- // ../rivetkit/dist/tsup/chunk-OWSXJF7Z.js
15883
+ // ../rivetkit/dist/tsup/chunk-BERJKIW5.js
15852
15884
  var import_invariant3 = __toESM(require_invariant(), 1);
15853
15885
  var import_invariant4 = __toESM(require_invariant(), 1);
15854
15886
  var PATH_CONNECT = "/connect";
@@ -18353,6 +18385,15 @@ function createQueueSender(senderOptions) {
18353
18385
  send
18354
18386
  };
18355
18387
  }
18388
+ async function prepareRetryableInit(init) {
18389
+ if (init.body instanceof ReadableStream) {
18390
+ return {
18391
+ ...init,
18392
+ body: new Uint8Array(await new Response(init.body).arrayBuffer())
18393
+ };
18394
+ }
18395
+ return init;
18396
+ }
18356
18397
  async function rawHttpFetch(driver, target, params, input, init, options = {}) {
18357
18398
  let path2;
18358
18399
  let originalUrl;
@@ -18887,9 +18928,10 @@ var ActorHandleRaw = class {
18887
18928
  return this.#fetchWithResolvedActor(input, init);
18888
18929
  }
18889
18930
  async #fetchWithResolvedActor(input, init) {
18890
- const { skipReadyWait, ...requestInit } = init ?? {};
18891
- const hasBody = requestInit.body !== void 0 ? requestInit.body !== null : isRequestLike(input) && input.body !== null;
18892
- const maxAttempts = hasBody ? 1 : this.#getDynamicQueryMaxAttempts();
18931
+ const { skipReadyWait, ...restInit } = init ?? {};
18932
+ const maxAttempts = this.#getDynamicQueryMaxAttempts();
18933
+ const requestInit = maxAttempts > 1 ? await prepareRetryableInit(restInit) : restInit;
18934
+ const clonesInputBody = requestInit.body === void 0 && isRequestLike(input) && input.body !== null;
18893
18935
  let useQueryTarget = isDynamicActorQuery(this.#actorResolutionState);
18894
18936
  const gatewayOptions = resolveActorGatewayOptions(
18895
18937
  this.#gatewayOptions,
@@ -18909,7 +18951,9 @@ var ActorHandleRaw = class {
18909
18951
  this.#driver,
18910
18952
  target,
18911
18953
  this.#params,
18912
- input,
18954
+ // Clone a body-bearing Request so retries don't reuse a consumed stream.
18955
+ // NOTE: This holds the body in memory until GC (unavoidable).
18956
+ clonesInputBody ? input.clone() : input,
18913
18957
  requestInit,
18914
18958
  gatewayOptions
18915
18959
  );
@@ -21620,7 +21664,7 @@ function apiActorToOutput(actor2) {
21620
21664
  };
21621
21665
  }
21622
21666
 
21623
- // ../rivetkit/dist/tsup/chunk-LHT3TRDM.js
21667
+ // ../rivetkit/dist/tsup/chunk-J7WM3KL5.js
21624
21668
  var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
21625
21669
  var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
21626
21670
  function registerNativeStateTransactionOpener(provider, opener) {
@@ -21655,6 +21699,7 @@ function db({
21655
21699
  const db2 = await nativeDatabaseProvider.open(ctx.actorId);
21656
21700
  let closed = false;
21657
21701
  let manualTransactionWarned = false;
21702
+ let synchronousTransactionActive = false;
21658
21703
  const ensureOpen = () => {
21659
21704
  if (closed) {
21660
21705
  throw new Error(
@@ -21662,16 +21707,24 @@ function db({
21662
21707
  );
21663
21708
  }
21664
21709
  };
21710
+ const ensureSynchronousTransactionClient = (transactionScoped) => {
21711
+ if (!transactionScoped && synchronousTransactionActive) {
21712
+ throw new Error(
21713
+ "Use the transaction callback's tx value for queries inside db.transactionSync()."
21714
+ );
21715
+ }
21716
+ };
21665
21717
  const createClient = (target, transactionScoped = false, stateTransactionContext) => {
21666
21718
  const client2 = {
21667
21719
  execute: async (query, ...args) => {
21668
21720
  var _a2, _b, _c, _d;
21669
21721
  ensureOpen();
21722
+ ensureSynchronousTransactionClient(transactionScoped);
21670
21723
  if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
21671
21724
  manualTransactionWarned = true;
21672
21725
  getLogger("database").warn(
21673
21726
  { actorId: ctx.actorId },
21674
- "Manual cross-call SQLite transactions can interleave with other actor work. Use db.transaction() for coordinated transactions. Set warnOnManualTransactions: false in your db(...) configuration to disable this warning."
21727
+ "Manual cross-call SQLite transactions can interleave with other actor work. Use db.transaction() or db.transactionSync() for coordinated transactions. Set warnOnManualTransactions: false in your db(...) configuration to disable this warning."
21675
21728
  );
21676
21729
  }
21677
21730
  const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
@@ -21717,8 +21770,66 @@ function db({
21717
21770
  }
21718
21771
  }
21719
21772
  },
21773
+ executeSync: (query, ...args) => {
21774
+ var _a2, _b, _c, _d;
21775
+ ensureOpen();
21776
+ ensureSynchronousTransactionClient(transactionScoped);
21777
+ if (!target.executeSync) {
21778
+ throw new Error(
21779
+ "Synchronous SQLite queries are only available in the Node.js native runtime."
21780
+ );
21781
+ }
21782
+ if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
21783
+ manualTransactionWarned = true;
21784
+ getLogger("database").warn(
21785
+ { actorId: ctx.actorId },
21786
+ "Manual cross-call SQLite transactions can interleave with other actor work. Use db.transaction() or db.transactionSync() for coordinated transactions. Set warnOnManualTransactions: false in your db(...) configuration to disable this warning."
21787
+ );
21788
+ }
21789
+ const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
21790
+ const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
21791
+ const start = performance.now();
21792
+ try {
21793
+ if (args.length > 0) {
21794
+ const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
21795
+ const { rows, columns } = target.executeSync(
21796
+ query,
21797
+ bindings
21798
+ );
21799
+ return rows.map(
21800
+ (row) => rowToObject(row, columns)
21801
+ );
21802
+ }
21803
+ if (!hasMultipleStatements(query)) {
21804
+ const { rows, columns } = target.executeSync(
21805
+ query,
21806
+ void 0
21807
+ );
21808
+ return rows.map(
21809
+ (row) => rowToObject(row, columns)
21810
+ );
21811
+ }
21812
+ return execMultiStatementSync(target, query);
21813
+ } finally {
21814
+ const durationMs = performance.now() - start;
21815
+ (_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
21816
+ if (ctx.metrics) {
21817
+ const kvReads = ctx.metrics.totalKvReads - kvReadsBefore;
21818
+ const kvWrites = ctx.metrics.totalKvWrites - kvWritesBefore;
21819
+ (_d = ctx.log) == null ? void 0 : _d.debug({
21820
+ msg: "sql query",
21821
+ query: query.slice(0, 120),
21822
+ durationMs,
21823
+ kvReads,
21824
+ kvWrites
21825
+ });
21826
+ }
21827
+ }
21828
+ },
21720
21829
  transaction: async (callback, options) => {
21721
21830
  var _a2, _b;
21831
+ ensureOpen();
21832
+ ensureSynchronousTransactionClient(transactionScoped);
21722
21833
  validateTransactionTimeout(options == null ? void 0 : options.timeout);
21723
21834
  validateTransactionName(options == null ? void 0 : options.name);
21724
21835
  if (transactionScoped && ((_a2 = options == null ? void 0 : options.experimental) == null ? void 0 : _a2.includeState)) {
@@ -21764,6 +21875,33 @@ function db({
21764
21875
  }
21765
21876
  }
21766
21877
  },
21878
+ transactionSync: (callback, options) => {
21879
+ ensureOpen();
21880
+ if (transactionScoped || synchronousTransactionActive) {
21881
+ throw new Error(
21882
+ "Nested synchronous SQLite transactions are not supported."
21883
+ );
21884
+ }
21885
+ return runSqliteTransactionSync(
21886
+ db2,
21887
+ (transaction) => {
21888
+ const transactionClient = createClient(
21889
+ transaction,
21890
+ true
21891
+ );
21892
+ const tx = {
21893
+ executeSync: transactionClient.executeSync
21894
+ };
21895
+ synchronousTransactionActive = true;
21896
+ try {
21897
+ return callback(tx);
21898
+ } finally {
21899
+ synchronousTransactionActive = false;
21900
+ }
21901
+ },
21902
+ options
21903
+ );
21904
+ },
21767
21905
  close: async () => {
21768
21906
  if (!closed) {
21769
21907
  closed = true;
@@ -21815,6 +21953,22 @@ async function execMultiStatement(db2, query) {
21815
21953
  });
21816
21954
  return results;
21817
21955
  }
21956
+ function execMultiStatementSync(db2, query) {
21957
+ if (!db2.execSync) {
21958
+ throw new Error(
21959
+ "Synchronous SQLite queries are only available in the Node.js native runtime."
21960
+ );
21961
+ }
21962
+ const results = [];
21963
+ let columnNames = null;
21964
+ db2.execSync(query, (row, columns) => {
21965
+ if (!columnNames) {
21966
+ columnNames = columns;
21967
+ }
21968
+ results.push(rowToObject(row, columnNames));
21969
+ });
21970
+ return results;
21971
+ }
21818
21972
  async function withMigrationSavepoint(client, callback) {
21819
21973
  return await client.transaction(
21820
21974
  async (transaction) => {
@@ -23187,7 +23341,7 @@ function getValidationSchema(schema) {
23187
23341
  }
23188
23342
  return schema;
23189
23343
  }
23190
- function isPromiseLike(value) {
23344
+ function isPromiseLike2(value) {
23191
23345
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
23192
23346
  }
23193
23347
  function validateSchemaSync(schemas, key, data) {
@@ -23197,7 +23351,7 @@ function validateSchemaSync(schemas, key, data) {
23197
23351
  }
23198
23352
  if (isStandardSchema(schema)) {
23199
23353
  const result = schema["~standard"].validate(data);
23200
- if (isPromiseLike(result)) {
23354
+ if (isPromiseLike2(result)) {
23201
23355
  throw unsupportedFeature("async schema validation");
23202
23356
  }
23203
23357
  if (result.issues) {
@@ -23929,6 +24083,10 @@ var DocRegistryConfigSchema = external_exports.object({
23929
24083
  serverless: DocServerlessConfigSchema.optional(),
23930
24084
  envoy: DocEnvoyConfigSchema.optional()
23931
24085
  }).describe("RivetKit registry configuration.");
24086
+ function isSynchronousTransaction(transaction) {
24087
+ const candidate = transaction;
24088
+ return typeof candidate.commitSync === "function" && typeof candidate.rollbackSync === "function";
24089
+ }
23932
24090
  function shouldAttachNativeKvError(message) {
23933
24091
  return /i\/o error|unable to open database file/i.test(message);
23934
24092
  }
@@ -24116,6 +24274,30 @@ function wrapJsNativeDatabase(database) {
24116
24274
  release();
24117
24275
  }
24118
24276
  };
24277
+ const executeNativeSync = (sql, params) => {
24278
+ const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
24279
+ if (lastInsertRowIdColumn) {
24280
+ return {
24281
+ columns: [lastInsertRowIdColumn],
24282
+ rows: [[lastInsertRowId ?? 0]],
24283
+ changes: 0,
24284
+ lastInsertRowId
24285
+ };
24286
+ }
24287
+ const release = gate.enter();
24288
+ try {
24289
+ const nativeParams = toNativeBindings(sql, params);
24290
+ const result = database.executeSync(sql, nativeParams);
24291
+ if (result.lastInsertRowId !== void 0) {
24292
+ lastInsertRowId = result.lastInsertRowId;
24293
+ }
24294
+ return result;
24295
+ } catch (error46) {
24296
+ enrichNativeDatabaseError(database, error46);
24297
+ } finally {
24298
+ release();
24299
+ }
24300
+ };
24119
24301
  return {
24120
24302
  async exec(sql, callback) {
24121
24303
  const release = gate.enter();
@@ -24134,9 +24316,28 @@ function wrapJsNativeDatabase(database) {
24134
24316
  callback(row, result.columns);
24135
24317
  }
24136
24318
  },
24319
+ execSync(sql, callback) {
24320
+ const release = gate.enter();
24321
+ let result;
24322
+ try {
24323
+ result = database.execSync(sql);
24324
+ } catch (error46) {
24325
+ enrichNativeDatabaseError(database, error46);
24326
+ } finally {
24327
+ release();
24328
+ }
24329
+ if (callback) {
24330
+ for (const row of result.rows) {
24331
+ callback(row, result.columns);
24332
+ }
24333
+ }
24334
+ },
24137
24335
  async execute(sql, params) {
24138
24336
  return await executeNative(sql, params);
24139
24337
  },
24338
+ executeSync(sql, params) {
24339
+ return executeNativeSync(sql, params);
24340
+ },
24140
24341
  async executeBatch(statements) {
24141
24342
  const nativeStatements = statements.map(toNativeBatchStatement);
24142
24343
  const release = gate.enter();
@@ -24191,6 +24392,22 @@ function wrapJsNativeDatabase(database) {
24191
24392
  }
24192
24393
  });
24193
24394
  },
24395
+ beginTransactionSync(timeoutMs, name) {
24396
+ const release = gate.enter();
24397
+ let transaction;
24398
+ try {
24399
+ transaction = database.beginTransactionSync(timeoutMs, name);
24400
+ } catch (error46) {
24401
+ enrichNativeDatabaseError(database, error46);
24402
+ } finally {
24403
+ release();
24404
+ }
24405
+ return wrapTransaction(database, transaction, gate, (result) => {
24406
+ if (result.lastInsertRowId !== void 0) {
24407
+ lastInsertRowId = result.lastInsertRowId;
24408
+ }
24409
+ });
24410
+ },
24194
24411
  async beginStateTransaction(timeoutMs, context) {
24195
24412
  if (!database.beginStateTransaction) {
24196
24413
  throw new Error("actor state transactions are not configured");
@@ -24231,7 +24448,7 @@ function wrapJsNativeDatabase(database) {
24231
24448
  };
24232
24449
  }
24233
24450
  function wrapTransaction(database, transaction, gate, onExecute) {
24234
- return {
24451
+ const wrapped = {
24235
24452
  async exec(sql, callback) {
24236
24453
  const release = gate.enter();
24237
24454
  let result;
@@ -24246,6 +24463,20 @@ function wrapTransaction(database, transaction, gate, onExecute) {
24246
24463
  for (const row of result.rows) callback(row, result.columns);
24247
24464
  }
24248
24465
  },
24466
+ execSync(sql, callback) {
24467
+ const release = gate.enter();
24468
+ let result;
24469
+ try {
24470
+ result = transaction.execSync(sql);
24471
+ } catch (error46) {
24472
+ enrichNativeDatabaseError(database, error46);
24473
+ } finally {
24474
+ release();
24475
+ }
24476
+ if (callback) {
24477
+ for (const row of result.rows) callback(row, result.columns);
24478
+ }
24479
+ },
24249
24480
  async execute(sql, params) {
24250
24481
  const release = gate.enter();
24251
24482
  try {
@@ -24261,6 +24492,21 @@ function wrapTransaction(database, transaction, gate, onExecute) {
24261
24492
  release();
24262
24493
  }
24263
24494
  },
24495
+ executeSync(sql, params) {
24496
+ const release = gate.enter();
24497
+ try {
24498
+ const result = transaction.executeSync(
24499
+ sql,
24500
+ toNativeBindings(sql, params)
24501
+ );
24502
+ onExecute(result);
24503
+ return result;
24504
+ } catch (error46) {
24505
+ enrichNativeDatabaseError(database, error46);
24506
+ } finally {
24507
+ release();
24508
+ }
24509
+ },
24264
24510
  async commit() {
24265
24511
  const release = gate.enter();
24266
24512
  try {
@@ -24282,6 +24528,31 @@ function wrapTransaction(database, transaction, gate, onExecute) {
24282
24528
  }
24283
24529
  }
24284
24530
  };
24531
+ if (isSynchronousTransaction(transaction)) {
24532
+ return Object.assign(wrapped, {
24533
+ commitSync() {
24534
+ const release = gate.enter();
24535
+ try {
24536
+ transaction.commitSync();
24537
+ } catch (error46) {
24538
+ enrichNativeDatabaseError(database, error46);
24539
+ } finally {
24540
+ release();
24541
+ }
24542
+ },
24543
+ rollbackSync() {
24544
+ const release = gate.enter();
24545
+ try {
24546
+ transaction.rollbackSync();
24547
+ } catch (error46) {
24548
+ enrichNativeDatabaseError(database, error46);
24549
+ } finally {
24550
+ release();
24551
+ }
24552
+ }
24553
+ });
24554
+ }
24555
+ return wrapped;
24285
24556
  }
24286
24557
  function lastInsertRowIdColumnName(sql) {
24287
24558
  const match = sql.match(
@@ -24775,6 +25046,9 @@ var NapiCoreRuntime = class {
24775
25046
  async actorSqlExec(ctx, sql) {
24776
25047
  return await this.#actorSql(ctx).exec(sql);
24777
25048
  }
25049
+ actorSqlExecSync(ctx, sql) {
25050
+ return this.#actorSql(ctx).execSync(sql);
25051
+ }
24778
25052
  async actorSqlExecute(ctx, sql, params) {
24779
25053
  const result = await this.#actorSql(ctx).execute(
24780
25054
  sql,
@@ -24782,6 +25056,13 @@ var NapiCoreRuntime = class {
24782
25056
  );
24783
25057
  return normalizeRuntimeSqlExecuteResult(result);
24784
25058
  }
25059
+ actorSqlExecuteSync(ctx, sql, params) {
25060
+ const result = this.#actorSql(ctx).executeSync(
25061
+ sql,
25062
+ toNapiSqlBindParams(params)
25063
+ );
25064
+ return normalizeRuntimeSqlExecuteResult(result);
25065
+ }
24785
25066
  async actorSqlExecuteBatch(ctx, statements) {
24786
25067
  const results = await this.#actorSql(ctx).executeBatch(
24787
25068
  statements.map(toNapiSqlBatchStatement)
@@ -24794,9 +25075,18 @@ var NapiCoreRuntime = class {
24794
25075
  name
24795
25076
  );
24796
25077
  }
25078
+ actorSqlBeginTransactionSync(ctx, timeoutMs, name) {
25079
+ return this.#actorSql(ctx).beginTransactionSync(
25080
+ timeoutMs,
25081
+ name
25082
+ );
25083
+ }
24797
25084
  async actorSqlTransactionExec(transaction, sql) {
24798
25085
  return await asNativeSqlTransaction(transaction).exec(sql);
24799
25086
  }
25087
+ actorSqlTransactionExecSync(transaction, sql) {
25088
+ return asNativeSqlTransaction(transaction).execSync(sql);
25089
+ }
24800
25090
  async actorSqlTransactionExecute(transaction, sql, params) {
24801
25091
  const result = await asNativeSqlTransaction(transaction).execute(
24802
25092
  sql,
@@ -24804,12 +25094,25 @@ var NapiCoreRuntime = class {
24804
25094
  );
24805
25095
  return normalizeRuntimeSqlExecuteResult(result);
24806
25096
  }
25097
+ actorSqlTransactionExecuteSync(transaction, sql, params) {
25098
+ const result = asNativeSqlTransaction(transaction).executeSync(
25099
+ sql,
25100
+ toNapiSqlBindParams(params)
25101
+ );
25102
+ return normalizeRuntimeSqlExecuteResult(result);
25103
+ }
24807
25104
  async actorSqlTransactionCommit(transaction) {
24808
25105
  await asNativeSqlTransaction(transaction).commit();
24809
25106
  }
25107
+ actorSqlTransactionCommitSync(transaction) {
25108
+ asNativeSqlTransaction(transaction).commitSync();
25109
+ }
24810
25110
  async actorSqlTransactionRollback(transaction) {
24811
25111
  await asNativeSqlTransaction(transaction).rollback();
24812
25112
  }
25113
+ actorSqlTransactionRollbackSync(transaction) {
25114
+ asNativeSqlTransaction(transaction).rollbackSync();
25115
+ }
24813
25116
  async actorBeginStateTransaction(ctx, timeoutMs) {
24814
25117
  return await asNativeActorContext(ctx).beginStateTransaction(
24815
25118
  timeoutMs
@@ -24822,6 +25125,13 @@ var NapiCoreRuntime = class {
24822
25125
  );
24823
25126
  return normalizeRuntimeSqlExecuteResult(result);
24824
25127
  }
25128
+ actorStateTransactionExecuteSync(transaction, sql, params) {
25129
+ const result = asNativeActorStateTransaction(transaction).executeSync(
25130
+ sql,
25131
+ toNapiSqlBindParams(params)
25132
+ );
25133
+ return normalizeRuntimeSqlExecuteResult(result);
25134
+ }
24825
25135
  async actorStateTransactionCommit(transaction, payload) {
24826
25136
  await asNativeActorStateTransaction(transaction).commit(
24827
25137
  toNapiStateDeltaPayload(payload)
@@ -25421,6 +25731,11 @@ function optionalWasmNumber(value) {
25421
25731
  function wasmNumber(value) {
25422
25732
  return typeof value === "bigint" ? Number(value) : value;
25423
25733
  }
25734
+ function synchronousSqliteUnavailable() {
25735
+ throw new Error(
25736
+ "Synchronous SQLite operations are only available in the Node.js native runtime."
25737
+ );
25738
+ }
25424
25739
  function normalizeKvEntry(entry) {
25425
25740
  return {
25426
25741
  key: toBytes(entry.key),
@@ -25824,12 +26139,18 @@ var WasmCoreRuntime = class {
25824
26139
  async actorSqlExec(ctx, sql) {
25825
26140
  return await callWasm(() => this.#actorSql(ctx).exec(sql));
25826
26141
  }
26142
+ actorSqlExecSync(_ctx, _sql) {
26143
+ return synchronousSqliteUnavailable();
26144
+ }
25827
26145
  async actorSqlExecute(ctx, sql, params) {
25828
26146
  const result = await callWasm(
25829
26147
  () => this.#actorSql(ctx).execute(sql, params)
25830
26148
  );
25831
26149
  return normalizeRuntimeSqlExecuteResult(result);
25832
26150
  }
26151
+ actorSqlExecuteSync(_ctx, _sql, _params) {
26152
+ return synchronousSqliteUnavailable();
26153
+ }
25833
26154
  async actorSqlExecuteBatch(ctx, statements) {
25834
26155
  const results = await callWasm(
25835
26156
  () => this.#actorSql(ctx).executeBatch(statements)
@@ -25841,27 +26162,42 @@ var WasmCoreRuntime = class {
25841
26162
  () => this.#actorSql(ctx).beginTransaction(timeoutMs, name)
25842
26163
  );
25843
26164
  }
26165
+ actorSqlBeginTransactionSync(_ctx, _timeoutMs, _name) {
26166
+ return synchronousSqliteUnavailable();
26167
+ }
25844
26168
  async actorSqlTransactionExec(transaction, sql) {
25845
26169
  return await callWasm(
25846
26170
  () => transaction.exec(sql)
25847
26171
  );
25848
26172
  }
26173
+ actorSqlTransactionExecSync(_transaction, _sql) {
26174
+ return synchronousSqliteUnavailable();
26175
+ }
25849
26176
  async actorSqlTransactionExecute(transaction, sql, params) {
25850
26177
  const result = await callWasm(
25851
26178
  () => transaction.execute(sql, params)
25852
26179
  );
25853
26180
  return normalizeRuntimeSqlExecuteResult(result);
25854
26181
  }
26182
+ actorSqlTransactionExecuteSync(_transaction, _sql, _params) {
26183
+ return synchronousSqliteUnavailable();
26184
+ }
25855
26185
  async actorSqlTransactionCommit(transaction) {
25856
26186
  await callWasm(
25857
26187
  () => transaction.commit()
25858
26188
  );
25859
26189
  }
26190
+ actorSqlTransactionCommitSync(_transaction) {
26191
+ synchronousSqliteUnavailable();
26192
+ }
25860
26193
  async actorSqlTransactionRollback(transaction) {
25861
26194
  await callWasm(
25862
26195
  () => transaction.rollback()
25863
26196
  );
25864
26197
  }
26198
+ actorSqlTransactionRollbackSync(_transaction) {
26199
+ synchronousSqliteUnavailable();
26200
+ }
25865
26201
  async actorBeginStateTransaction(ctx, timeoutMs) {
25866
26202
  return await callWasm(
25867
26203
  () => asWasmActorContext(ctx).beginStateTransaction(timeoutMs)
@@ -25873,6 +26209,9 @@ var WasmCoreRuntime = class {
25873
26209
  );
25874
26210
  return normalizeRuntimeSqlExecuteResult(result);
25875
26211
  }
26212
+ actorStateTransactionExecuteSync(_transaction, _sql, _params) {
26213
+ return synchronousSqliteUnavailable();
26214
+ }
25876
26215
  async actorStateTransactionCommit(transaction, payload) {
25877
26216
  await callWasm(
25878
26217
  () => transaction.commit(payload)
@@ -26361,7 +26700,7 @@ function getNativePersistState(runtime, ctx) {
26361
26700
  }
26362
26701
  return persistState;
26363
26702
  }
26364
- function isPromiseLike2(value) {
26703
+ function isPromiseLike22(value) {
26365
26704
  return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
26366
26705
  }
26367
26706
  function getNativeConnPersistState(runtime, ctx, conn) {
@@ -26507,6 +26846,18 @@ async function closeNativeDatabaseClient(runtime, ctx) {
26507
26846
  await entry.client.close();
26508
26847
  }
26509
26848
  }
26849
+ function createNativeSqlTransaction(runtime, transaction) {
26850
+ return {
26851
+ exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
26852
+ execSync: (sql) => runtime.actorSqlTransactionExecSync(transaction, sql),
26853
+ execute: (sql, params) => runtime.actorSqlTransactionExecute(transaction, sql, params),
26854
+ executeSync: (sql, params) => runtime.actorSqlTransactionExecuteSync(transaction, sql, params),
26855
+ commit: () => runtime.actorSqlTransactionCommit(transaction),
26856
+ commitSync: () => runtime.actorSqlTransactionCommitSync(transaction),
26857
+ rollback: () => runtime.actorSqlTransactionRollback(transaction),
26858
+ rollbackSync: () => runtime.actorSqlTransactionRollbackSync(transaction)
26859
+ };
26860
+ }
26510
26861
  function getOrCreateNativeSqlDatabase(runtime, ctx) {
26511
26862
  const runtimeState = getNativeRuntimeState(runtime, ctx);
26512
26863
  const cachedDatabase = runtimeState.sql;
@@ -26515,7 +26866,9 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
26515
26866
  }
26516
26867
  const database = wrapJsNativeDatabase({
26517
26868
  exec: (sql) => runtime.actorSqlExec(ctx, sql),
26869
+ execSync: (sql) => runtime.actorSqlExecSync(ctx, sql),
26518
26870
  execute: (sql, params) => runtime.actorSqlExecute(ctx, sql, params),
26871
+ executeSync: (sql, params) => runtime.actorSqlExecuteSync(ctx, sql, params),
26519
26872
  executeBatch: (statements) => runtime.actorSqlExecuteBatch(ctx, statements),
26520
26873
  beginTransaction: async (timeoutMs, name) => {
26521
26874
  const transaction = await runtime.actorSqlBeginTransaction(
@@ -26523,16 +26876,15 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
26523
26876
  timeoutMs,
26524
26877
  name
26525
26878
  );
26526
- return {
26527
- exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
26528
- execute: (sql, params) => runtime.actorSqlTransactionExecute(
26529
- transaction,
26530
- sql,
26531
- params
26532
- ),
26533
- commit: () => runtime.actorSqlTransactionCommit(transaction),
26534
- rollback: () => runtime.actorSqlTransactionRollback(transaction)
26535
- };
26879
+ return createNativeSqlTransaction(runtime, transaction);
26880
+ },
26881
+ beginTransactionSync: (timeoutMs, name) => {
26882
+ const transaction = runtime.actorSqlBeginTransactionSync(
26883
+ ctx,
26884
+ timeoutMs,
26885
+ name
26886
+ );
26887
+ return createNativeSqlTransaction(runtime, transaction);
26536
26888
  },
26537
26889
  beginStateTransaction: async (timeoutMs, context) => {
26538
26890
  const scope = context;
@@ -26551,11 +26903,21 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
26551
26903
  "actor state transactions only support single-statement execute calls"
26552
26904
  );
26553
26905
  },
26906
+ execSync: () => {
26907
+ throw new Error(
26908
+ "actor state transactions only support single-statement execute calls"
26909
+ );
26910
+ },
26554
26911
  execute: (sql, params) => runtime.actorStateTransactionExecute(
26555
26912
  transaction,
26556
26913
  sql,
26557
26914
  params
26558
26915
  ),
26916
+ executeSync: (sql, params) => runtime.actorStateTransactionExecuteSync(
26917
+ transaction,
26918
+ sql,
26919
+ params
26920
+ ),
26559
26921
  commit: async () => {
26560
26922
  await runtime.actorStateTransactionCommit(
26561
26923
  transaction,
@@ -28683,7 +29045,7 @@ var ActorContextHandleAdapter = class {
28683
29045
  this,
28684
29046
  actorState.state
28685
29047
  );
28686
- if (isPromiseLike2(result)) {
29048
+ if (isPromiseLike22(result)) {
28687
29049
  shouldFinish = false;
28688
29050
  void Promise.resolve(result).catch((error46) => {
28689
29051
  logger22().error({