@rivetkit/supabase 2.3.24 → 2.3.25

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 +346 -346
  2. package/dist/mod.mjs +346 -346
  3. package/package.json +3 -3
package/dist/mod.mjs CHANGED
@@ -500,7 +500,7 @@ function unsupportedFeature(feature) {
500
500
  );
501
501
  }
502
502
 
503
- // ../rivetkit/dist/tsup/chunk-YH2CAWLD.js
503
+ // ../rivetkit/dist/tsup/chunk-BSQWFYSP.js
504
504
  import {
505
505
  pino,
506
506
  stdTimeFunctions
@@ -13176,7 +13176,7 @@ var classic_default = external_exports;
13176
13176
  // ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
13177
13177
  var v4_default = classic_default;
13178
13178
 
13179
- // ../rivetkit/dist/tsup/chunk-YH2CAWLD.js
13179
+ // ../rivetkit/dist/tsup/chunk-BSQWFYSP.js
13180
13180
  var import_invariant = __toESM(require_invariant(), 1);
13181
13181
  import * as cbor from "cbor-x";
13182
13182
  var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
@@ -13347,7 +13347,7 @@ function noopNext() {
13347
13347
  }
13348
13348
  var package_default = {
13349
13349
  name: "rivetkit",
13350
- version: "2.3.24",
13350
+ version: "2.3.25",
13351
13351
  description: "Lightweight libraries for building stateful actors on edge platforms",
13352
13352
  license: "Apache-2.0",
13353
13353
  keywords: [
@@ -14654,7 +14654,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
14654
14654
  };
14655
14655
  }
14656
14656
 
14657
- // ../rivetkit/dist/tsup/chunk-QMR2J7PT.js
14657
+ // ../rivetkit/dist/tsup/chunk-FHRRLHJE.js
14658
14658
  var config2 = /* @__PURE__ */ Config({});
14659
14659
  function readWorkflowCbor(bc) {
14660
14660
  return readData(bc);
@@ -15447,6 +15447,314 @@ var DocActorConfigSchema = external_exports.object({
15447
15447
  options: DocActorOptionsSchema.optional()
15448
15448
  }).describe("Actor configuration passed to the actor() function.");
15449
15449
 
15450
+ // ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
15451
+ var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
15452
+ function isManualTransactionControl(query) {
15453
+ return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
15454
+ }
15455
+ function validateTransactionTimeout(timeout) {
15456
+ if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0)) {
15457
+ throw new Error(
15458
+ "db.transaction() timeout must be a positive finite number of milliseconds"
15459
+ );
15460
+ }
15461
+ }
15462
+ function validateTransactionName(name) {
15463
+ if (name === void 0) {
15464
+ return;
15465
+ }
15466
+ if (name.length === 0) {
15467
+ throw new Error("db.transaction() name must not be empty");
15468
+ }
15469
+ }
15470
+ function isSqliteBindingValue(value) {
15471
+ if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
15472
+ return true;
15473
+ }
15474
+ if (Array.isArray(value)) {
15475
+ return value.every((item) => typeof item === "number");
15476
+ }
15477
+ return false;
15478
+ }
15479
+ function isPlainObject3(value) {
15480
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
15481
+ return false;
15482
+ }
15483
+ return Object.getPrototypeOf(value) === Object.prototype;
15484
+ }
15485
+ function isSqliteBindingObject(value) {
15486
+ if (!isPlainObject3(value)) {
15487
+ return false;
15488
+ }
15489
+ return Object.values(value).every((entry) => isSqliteBindingValue(entry));
15490
+ }
15491
+ function toSqliteBindings(input) {
15492
+ if (Array.isArray(input)) {
15493
+ for (const value of input) {
15494
+ if (!isSqliteBindingValue(value)) {
15495
+ throw new Error(
15496
+ `unsupported sqlite binding type: ${typeof value}`
15497
+ );
15498
+ }
15499
+ }
15500
+ return input;
15501
+ }
15502
+ if (isSqliteBindingObject(input)) {
15503
+ return input;
15504
+ }
15505
+ throw new Error("unsupported sqlite binding collection");
15506
+ }
15507
+ var AsyncMutex = class {
15508
+ #locked = false;
15509
+ #waiting = [];
15510
+ async acquire() {
15511
+ while (this.#locked) {
15512
+ await new Promise((resolve) => this.#waiting.push(resolve));
15513
+ }
15514
+ this.#locked = true;
15515
+ }
15516
+ release() {
15517
+ this.#locked = false;
15518
+ const next = this.#waiting.shift();
15519
+ if (next) {
15520
+ next();
15521
+ }
15522
+ }
15523
+ async run(fn) {
15524
+ await this.acquire();
15525
+ try {
15526
+ return await fn();
15527
+ } finally {
15528
+ this.release();
15529
+ }
15530
+ }
15531
+ };
15532
+
15533
+ // ../rivetkit/dist/tsup/chunk-BRYK7XVR.js
15534
+ var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
15535
+ var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
15536
+ function registerNativeStateTransactionOpener(provider, opener) {
15537
+ nativeStateTransactionOpeners.set(provider, opener);
15538
+ return provider;
15539
+ }
15540
+ function bindNativeStateTransactionContext(client, context2) {
15541
+ if ((typeof client !== "object" || client === null) && typeof client !== "function") {
15542
+ return client;
15543
+ }
15544
+ const bind = nativeStateTransactionClientBinders.get(client);
15545
+ return (bind == null ? void 0 : bind(context2)) ?? client;
15546
+ }
15547
+ function hasMultipleStatements(query) {
15548
+ const trimmed = query.trim().replace(/;+$/, "").trimEnd();
15549
+ return trimmed.includes(";");
15550
+ }
15551
+ function db({
15552
+ onMigrate,
15553
+ warnOnManualTransactions = true,
15554
+ profiling
15555
+ } = {}) {
15556
+ const provider = {
15557
+ sqliteProfiling: profiling,
15558
+ createClient: async (ctx) => {
15559
+ const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
15560
+ if (!nativeDatabaseProvider) {
15561
+ throw new Error(
15562
+ "native SQLite is required, but the current runtime did not provide a native database provider"
15563
+ );
15564
+ }
15565
+ const db2 = await nativeDatabaseProvider.open(ctx.actorId);
15566
+ let closed = false;
15567
+ let manualTransactionWarned = false;
15568
+ const ensureOpen = () => {
15569
+ if (closed) {
15570
+ throw new Error(
15571
+ "Database is closed. This usually means a background timer (setInterval, setTimeout) or a stray promise is still running after the actor stopped. Use c.abortSignal to clean up timers before the actor shuts down."
15572
+ );
15573
+ }
15574
+ };
15575
+ const createClient = (target, transactionScoped = false, stateTransactionContext) => {
15576
+ const client2 = {
15577
+ execute: async (query, ...args) => {
15578
+ var _a2, _b, _c, _d;
15579
+ ensureOpen();
15580
+ if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
15581
+ manualTransactionWarned = true;
15582
+ getLogger("database").warn(
15583
+ { actorId: ctx.actorId },
15584
+ "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."
15585
+ );
15586
+ }
15587
+ const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
15588
+ const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
15589
+ const start = performance.now();
15590
+ try {
15591
+ if (args.length > 0) {
15592
+ const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
15593
+ const { rows, columns } = await target.execute(
15594
+ query,
15595
+ bindings
15596
+ );
15597
+ return rows.map(
15598
+ (row) => rowToObject(row, columns)
15599
+ );
15600
+ }
15601
+ if (!hasMultipleStatements(query)) {
15602
+ const { rows, columns } = await target.execute(
15603
+ query,
15604
+ void 0
15605
+ );
15606
+ return rows.map(
15607
+ (row) => rowToObject(row, columns)
15608
+ );
15609
+ }
15610
+ return await execMultiStatement(
15611
+ target,
15612
+ query
15613
+ );
15614
+ } finally {
15615
+ const durationMs = performance.now() - start;
15616
+ (_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
15617
+ if (ctx.metrics) {
15618
+ const kvReads = ctx.metrics.totalKvReads - kvReadsBefore;
15619
+ const kvWrites = ctx.metrics.totalKvWrites - kvWritesBefore;
15620
+ (_d = ctx.log) == null ? void 0 : _d.debug({
15621
+ msg: "sql query",
15622
+ query: query.slice(0, 120),
15623
+ durationMs,
15624
+ kvReads,
15625
+ kvWrites
15626
+ });
15627
+ }
15628
+ }
15629
+ },
15630
+ transaction: async (callback, options) => {
15631
+ var _a2, _b;
15632
+ validateTransactionTimeout(options == null ? void 0 : options.timeout);
15633
+ validateTransactionName(options == null ? void 0 : options.name);
15634
+ if (transactionScoped && ((_a2 = options == null ? void 0 : options.experimental) == null ? void 0 : _a2.includeState)) {
15635
+ throw new Error(
15636
+ "experimental.includeState is not supported for nested transactions"
15637
+ );
15638
+ }
15639
+ const includeState = ((_b = options == null ? void 0 : options.experimental) == null ? void 0 : _b.includeState) === true;
15640
+ const stateScope = includeState && stateTransactionContext ? await stateTransactionContext.enter() : void 0;
15641
+ try {
15642
+ const transaction = includeState ? await (() => {
15643
+ const beginStateTransaction = ctx.nativeDatabaseProvider && nativeStateTransactionOpeners.get(
15644
+ ctx.nativeDatabaseProvider
15645
+ );
15646
+ if (!beginStateTransaction) {
15647
+ throw new Error(
15648
+ "experimental.includeState is only supported by RivetKit's embedded database provider"
15649
+ );
15650
+ }
15651
+ return beginStateTransaction(
15652
+ options == null ? void 0 : options.timeout,
15653
+ stateScope
15654
+ );
15655
+ })() : await db2.beginTransaction(
15656
+ options == null ? void 0 : options.timeout,
15657
+ options == null ? void 0 : options.name
15658
+ );
15659
+ const tx = createClient(transaction, true);
15660
+ try {
15661
+ const result = await callback(tx);
15662
+ await transaction.commit();
15663
+ return result;
15664
+ } catch (error46) {
15665
+ try {
15666
+ await transaction.rollback();
15667
+ } catch {
15668
+ }
15669
+ throw error46;
15670
+ }
15671
+ } finally {
15672
+ if (stateScope !== void 0) {
15673
+ stateTransactionContext == null ? void 0 : stateTransactionContext.exit(stateScope);
15674
+ }
15675
+ }
15676
+ },
15677
+ close: async () => {
15678
+ if (!closed) {
15679
+ closed = true;
15680
+ await db2.close();
15681
+ }
15682
+ },
15683
+ nativeMetrics: () => {
15684
+ var _a2;
15685
+ return ((_a2 = db2.nativeMetrics) == null ? void 0 : _a2.call(db2)) ?? null;
15686
+ }
15687
+ };
15688
+ if (!transactionScoped) {
15689
+ nativeStateTransactionClientBinders.set(
15690
+ client2,
15691
+ (context2) => createClient(target, false, context2)
15692
+ );
15693
+ }
15694
+ return client2;
15695
+ };
15696
+ const client = createClient(db2);
15697
+ return client;
15698
+ },
15699
+ onMigrate: async (client) => {
15700
+ if (onMigrate) {
15701
+ await withMigrationSavepoint(
15702
+ client,
15703
+ (leased) => onMigrate(leased)
15704
+ );
15705
+ }
15706
+ }
15707
+ };
15708
+ return provider;
15709
+ }
15710
+ function rowToObject(row, columns) {
15711
+ const rowObj = {};
15712
+ for (let i = 0; i < columns.length; i++) {
15713
+ rowObj[columns[i]] = row[i];
15714
+ }
15715
+ return rowObj;
15716
+ }
15717
+ async function execMultiStatement(db2, query) {
15718
+ const results = [];
15719
+ let columnNames = null;
15720
+ await db2.exec(query, (row, columns) => {
15721
+ if (!columnNames) {
15722
+ columnNames = columns;
15723
+ }
15724
+ results.push(rowToObject(row, columnNames));
15725
+ });
15726
+ return results;
15727
+ }
15728
+ async function withMigrationSavepoint(client, callback) {
15729
+ return await client.transaction(
15730
+ async (transaction) => {
15731
+ await transaction.execute("SAVEPOINT __rivet_on_migrate");
15732
+ try {
15733
+ const result = await callback(transaction);
15734
+ await transaction.execute(
15735
+ "RELEASE SAVEPOINT __rivet_on_migrate"
15736
+ );
15737
+ return result;
15738
+ } catch (error46) {
15739
+ try {
15740
+ await transaction.execute(
15741
+ "ROLLBACK TO SAVEPOINT __rivet_on_migrate"
15742
+ );
15743
+ } finally {
15744
+ await transaction.execute(
15745
+ "RELEASE SAVEPOINT __rivet_on_migrate"
15746
+ );
15747
+ }
15748
+ throw error46;
15749
+ }
15750
+ },
15751
+ {
15752
+ name: "rivetkit-migration",
15753
+ timeout: MIGRATION_TRANSACTION_TIMEOUT_MS
15754
+ }
15755
+ );
15756
+ }
15757
+
15450
15758
  // ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
15451
15759
  var EMPTY_KEY = "/";
15452
15760
  var KEY_SEPARATOR = "/";
@@ -15564,128 +15872,45 @@ function removePrefixFromKey(prefixedKey) {
15564
15872
  return prefixedKey.slice(KEYS.KV.length);
15565
15873
  }
15566
15874
 
15567
- // ../rivetkit/dist/tsup/chunk-NSNBWLCG.js
15875
+ // ../rivetkit/dist/tsup/chunk-3KHT4UQA.js
15568
15876
  function logger() {
15569
15877
  return getLogger("actor-client");
15570
15878
  }
15571
15879
  var webSocketPromise = null;
15572
- async function importWebSocket() {
15573
- if (webSocketPromise !== null) {
15574
- return webSocketPromise;
15575
- }
15576
- webSocketPromise = (async () => {
15577
- let _WebSocket;
15578
- if (typeof WebSocket !== "undefined") {
15579
- _WebSocket = WebSocket;
15580
- } else {
15581
- try {
15582
- const moduleName = "ws";
15583
- const ws = await import(
15584
- /* webpackIgnore: true */
15585
- moduleName
15586
- );
15587
- _WebSocket = ws.default;
15588
- logger().debug("using websocket from npm");
15589
- } catch {
15590
- _WebSocket = class MockWebSocket {
15591
- constructor() {
15592
- throw new Error(
15593
- 'WebSocket support requires installing the "ws" peer dependency.'
15594
- );
15595
- }
15596
- };
15597
- logger().debug("using mock websocket");
15598
- }
15599
- }
15600
- return _WebSocket;
15601
- })();
15602
- return webSocketPromise;
15603
- }
15604
-
15605
- // ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
15606
- var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
15607
- function isManualTransactionControl(query) {
15608
- return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
15609
- }
15610
- function validateTransactionTimeout(timeout) {
15611
- if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0)) {
15612
- throw new Error(
15613
- "db.transaction() timeout must be a positive finite number of milliseconds"
15614
- );
15615
- }
15616
- }
15617
- function validateTransactionName(name) {
15618
- if (name === void 0) {
15619
- return;
15620
- }
15621
- if (name.length === 0) {
15622
- throw new Error("db.transaction() name must not be empty");
15623
- }
15624
- }
15625
- function isSqliteBindingValue(value) {
15626
- if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
15627
- return true;
15628
- }
15629
- if (Array.isArray(value)) {
15630
- return value.every((item) => typeof item === "number");
15631
- }
15632
- return false;
15633
- }
15634
- function isPlainObject3(value) {
15635
- if (!value || typeof value !== "object" || Array.isArray(value)) {
15636
- return false;
15637
- }
15638
- return Object.getPrototypeOf(value) === Object.prototype;
15639
- }
15640
- function isSqliteBindingObject(value) {
15641
- if (!isPlainObject3(value)) {
15642
- return false;
15643
- }
15644
- return Object.values(value).every((entry) => isSqliteBindingValue(entry));
15645
- }
15646
- function toSqliteBindings(input) {
15647
- if (Array.isArray(input)) {
15648
- for (const value of input) {
15649
- if (!isSqliteBindingValue(value)) {
15650
- throw new Error(
15651
- `unsupported sqlite binding type: ${typeof value}`
15652
- );
15653
- }
15654
- }
15655
- return input;
15656
- }
15657
- if (isSqliteBindingObject(input)) {
15658
- return input;
15659
- }
15660
- throw new Error("unsupported sqlite binding collection");
15661
- }
15662
- var AsyncMutex = class {
15663
- #locked = false;
15664
- #waiting = [];
15665
- async acquire() {
15666
- while (this.#locked) {
15667
- await new Promise((resolve) => this.#waiting.push(resolve));
15668
- }
15669
- this.#locked = true;
15670
- }
15671
- release() {
15672
- this.#locked = false;
15673
- const next = this.#waiting.shift();
15674
- if (next) {
15675
- next();
15676
- }
15677
- }
15678
- async run(fn) {
15679
- await this.acquire();
15680
- try {
15681
- return await fn();
15682
- } finally {
15683
- this.release();
15684
- }
15880
+ async function importWebSocket() {
15881
+ if (webSocketPromise !== null) {
15882
+ return webSocketPromise;
15685
15883
  }
15686
- };
15884
+ webSocketPromise = (async () => {
15885
+ let _WebSocket;
15886
+ if (typeof WebSocket !== "undefined") {
15887
+ _WebSocket = WebSocket;
15888
+ } else {
15889
+ try {
15890
+ const moduleName = "ws";
15891
+ const ws = await import(
15892
+ /* webpackIgnore: true */
15893
+ moduleName
15894
+ );
15895
+ _WebSocket = ws.default;
15896
+ logger().debug("using websocket from npm");
15897
+ } catch {
15898
+ _WebSocket = class MockWebSocket {
15899
+ constructor() {
15900
+ throw new Error(
15901
+ 'WebSocket support requires installing the "ws" peer dependency.'
15902
+ );
15903
+ }
15904
+ };
15905
+ logger().debug("using mock websocket");
15906
+ }
15907
+ }
15908
+ return _WebSocket;
15909
+ })();
15910
+ return webSocketPromise;
15911
+ }
15687
15912
 
15688
- // ../rivetkit/dist/tsup/chunk-SW22GCYF.js
15913
+ // ../rivetkit/dist/tsup/chunk-FV63WBQ5.js
15689
15914
  var import_invariant2 = __toESM(require_invariant(), 1);
15690
15915
 
15691
15916
  // ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
@@ -16900,7 +17125,7 @@ var TraceAPI = (
16900
17125
  // ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
16901
17126
  var trace = TraceAPI.getInstance();
16902
17127
 
16903
- // ../rivetkit/dist/tsup/chunk-SW22GCYF.js
17128
+ // ../rivetkit/dist/tsup/chunk-FV63WBQ5.js
16904
17129
  var import_invariant3 = __toESM(require_invariant(), 1);
16905
17130
  var import_invariant4 = __toESM(require_invariant(), 1);
16906
17131
  var PATH_CONNECT = "/connect";
@@ -23096,231 +23321,6 @@ function apiActorToOutput(actor2) {
23096
23321
  };
23097
23322
  }
23098
23323
 
23099
- // ../rivetkit/dist/tsup/chunk-QZQE75U2.js
23100
- var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
23101
- var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
23102
- function registerNativeStateTransactionOpener(provider, opener) {
23103
- nativeStateTransactionOpeners.set(provider, opener);
23104
- return provider;
23105
- }
23106
- function bindNativeStateTransactionContext(client, context2) {
23107
- if ((typeof client !== "object" || client === null) && typeof client !== "function") {
23108
- return client;
23109
- }
23110
- const bind = nativeStateTransactionClientBinders.get(client);
23111
- return (bind == null ? void 0 : bind(context2)) ?? client;
23112
- }
23113
- function hasMultipleStatements(query) {
23114
- const trimmed = query.trim().replace(/;+$/, "").trimEnd();
23115
- return trimmed.includes(";");
23116
- }
23117
- function db({
23118
- onMigrate,
23119
- warnOnManualTransactions = true,
23120
- profiling
23121
- } = {}) {
23122
- const provider = {
23123
- sqliteProfiling: profiling,
23124
- createClient: async (ctx) => {
23125
- const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
23126
- if (!nativeDatabaseProvider) {
23127
- throw new Error(
23128
- "native SQLite is required, but the current runtime did not provide a native database provider"
23129
- );
23130
- }
23131
- const db2 = await nativeDatabaseProvider.open(ctx.actorId);
23132
- let closed = false;
23133
- let manualTransactionWarned = false;
23134
- const ensureOpen = () => {
23135
- if (closed) {
23136
- throw new Error(
23137
- "Database is closed. This usually means a background timer (setInterval, setTimeout) or a stray promise is still running after the actor stopped. Use c.abortSignal to clean up timers before the actor shuts down."
23138
- );
23139
- }
23140
- };
23141
- const createClient = (target, transactionScoped = false, stateTransactionContext) => {
23142
- const client2 = {
23143
- execute: async (query, ...args) => {
23144
- var _a2, _b, _c, _d;
23145
- ensureOpen();
23146
- if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
23147
- manualTransactionWarned = true;
23148
- getLogger("database").warn(
23149
- { actorId: ctx.actorId },
23150
- "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."
23151
- );
23152
- }
23153
- const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
23154
- const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
23155
- const start = performance.now();
23156
- try {
23157
- if (args.length > 0) {
23158
- const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
23159
- const { rows, columns } = await target.execute(
23160
- query,
23161
- bindings
23162
- );
23163
- return rows.map(
23164
- (row) => rowToObject(row, columns)
23165
- );
23166
- }
23167
- if (!hasMultipleStatements(query)) {
23168
- const { rows, columns } = await target.execute(
23169
- query,
23170
- void 0
23171
- );
23172
- return rows.map(
23173
- (row) => rowToObject(row, columns)
23174
- );
23175
- }
23176
- return await execMultiStatement(
23177
- target,
23178
- query
23179
- );
23180
- } finally {
23181
- const durationMs = performance.now() - start;
23182
- (_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
23183
- if (ctx.metrics) {
23184
- const kvReads = ctx.metrics.totalKvReads - kvReadsBefore;
23185
- const kvWrites = ctx.metrics.totalKvWrites - kvWritesBefore;
23186
- (_d = ctx.log) == null ? void 0 : _d.debug({
23187
- msg: "sql query",
23188
- query: query.slice(0, 120),
23189
- durationMs,
23190
- kvReads,
23191
- kvWrites
23192
- });
23193
- }
23194
- }
23195
- },
23196
- transaction: async (callback, options) => {
23197
- var _a2, _b;
23198
- validateTransactionTimeout(options == null ? void 0 : options.timeout);
23199
- validateTransactionName(options == null ? void 0 : options.name);
23200
- if (transactionScoped && ((_a2 = options == null ? void 0 : options.experimental) == null ? void 0 : _a2.includeState)) {
23201
- throw new Error(
23202
- "experimental.includeState is not supported for nested transactions"
23203
- );
23204
- }
23205
- const includeState = ((_b = options == null ? void 0 : options.experimental) == null ? void 0 : _b.includeState) === true;
23206
- const stateScope = includeState && stateTransactionContext ? await stateTransactionContext.enter() : void 0;
23207
- try {
23208
- const transaction = includeState ? await (() => {
23209
- const beginStateTransaction = ctx.nativeDatabaseProvider && nativeStateTransactionOpeners.get(
23210
- ctx.nativeDatabaseProvider
23211
- );
23212
- if (!beginStateTransaction) {
23213
- throw new Error(
23214
- "experimental.includeState is only supported by RivetKit's embedded database provider"
23215
- );
23216
- }
23217
- return beginStateTransaction(
23218
- options == null ? void 0 : options.timeout,
23219
- stateScope
23220
- );
23221
- })() : await db2.beginTransaction(
23222
- options == null ? void 0 : options.timeout,
23223
- options == null ? void 0 : options.name
23224
- );
23225
- const tx = createClient(transaction, true);
23226
- try {
23227
- const result = await callback(tx);
23228
- await transaction.commit();
23229
- return result;
23230
- } catch (error46) {
23231
- try {
23232
- await transaction.rollback();
23233
- } catch {
23234
- }
23235
- throw error46;
23236
- }
23237
- } finally {
23238
- if (stateScope !== void 0) {
23239
- stateTransactionContext == null ? void 0 : stateTransactionContext.exit(stateScope);
23240
- }
23241
- }
23242
- },
23243
- close: async () => {
23244
- if (!closed) {
23245
- closed = true;
23246
- await db2.close();
23247
- }
23248
- },
23249
- nativeMetrics: () => {
23250
- var _a2;
23251
- return ((_a2 = db2.nativeMetrics) == null ? void 0 : _a2.call(db2)) ?? null;
23252
- }
23253
- };
23254
- if (!transactionScoped) {
23255
- nativeStateTransactionClientBinders.set(
23256
- client2,
23257
- (context2) => createClient(target, false, context2)
23258
- );
23259
- }
23260
- return client2;
23261
- };
23262
- const client = createClient(db2);
23263
- return client;
23264
- },
23265
- onMigrate: async (client) => {
23266
- if (onMigrate) {
23267
- await withMigrationSavepoint(
23268
- client,
23269
- (leased) => onMigrate(leased)
23270
- );
23271
- }
23272
- }
23273
- };
23274
- return provider;
23275
- }
23276
- function rowToObject(row, columns) {
23277
- const rowObj = {};
23278
- for (let i = 0; i < columns.length; i++) {
23279
- rowObj[columns[i]] = row[i];
23280
- }
23281
- return rowObj;
23282
- }
23283
- async function execMultiStatement(db2, query) {
23284
- const results = [];
23285
- let columnNames = null;
23286
- await db2.exec(query, (row, columns) => {
23287
- if (!columnNames) {
23288
- columnNames = columns;
23289
- }
23290
- results.push(rowToObject(row, columnNames));
23291
- });
23292
- return results;
23293
- }
23294
- async function withMigrationSavepoint(client, callback) {
23295
- return await client.transaction(
23296
- async (transaction) => {
23297
- await transaction.execute("SAVEPOINT __rivet_on_migrate");
23298
- try {
23299
- const result = await callback(transaction);
23300
- await transaction.execute(
23301
- "RELEASE SAVEPOINT __rivet_on_migrate"
23302
- );
23303
- return result;
23304
- } catch (error46) {
23305
- try {
23306
- await transaction.execute(
23307
- "ROLLBACK TO SAVEPOINT __rivet_on_migrate"
23308
- );
23309
- } finally {
23310
- await transaction.execute(
23311
- "RELEASE SAVEPOINT __rivet_on_migrate"
23312
- );
23313
- }
23314
- throw error46;
23315
- }
23316
- },
23317
- {
23318
- name: "rivetkit-migration",
23319
- timeout: MIGRATION_TRANSACTION_TIMEOUT_MS
23320
- }
23321
- );
23322
- }
23323
-
23324
23324
  // ../../../shared/typescript/virtual-websocket/dist/mod.js
23325
23325
  var VirtualWebSocket = class {
23326
23326
  static CONNECTING = 0;