@rivetkit/supabase 2.3.25 → 2.3.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.js +321 -321
- package/dist/mod.mjs +321 -321
- package/package.json +3 -3
package/dist/mod.js
CHANGED
|
@@ -538,7 +538,7 @@ function unsupportedFeature(feature) {
|
|
|
538
538
|
);
|
|
539
539
|
}
|
|
540
540
|
|
|
541
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
541
|
+
// ../rivetkit/dist/tsup/chunk-TCZ2DONE.js
|
|
542
542
|
var import_pino = require("pino");
|
|
543
543
|
|
|
544
544
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
@@ -13211,7 +13211,7 @@ var classic_default = external_exports;
|
|
|
13211
13211
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
13212
13212
|
var v4_default = classic_default;
|
|
13213
13213
|
|
|
13214
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
13214
|
+
// ../rivetkit/dist/tsup/chunk-TCZ2DONE.js
|
|
13215
13215
|
var cbor = __toESM(require("cbor-x"), 1);
|
|
13216
13216
|
var import_invariant = __toESM(require_invariant(), 1);
|
|
13217
13217
|
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
@@ -13382,7 +13382,7 @@ function noopNext() {
|
|
|
13382
13382
|
}
|
|
13383
13383
|
var package_default = {
|
|
13384
13384
|
name: "rivetkit",
|
|
13385
|
-
version: "2.3.
|
|
13385
|
+
version: "2.3.27",
|
|
13386
13386
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13387
13387
|
license: "Apache-2.0",
|
|
13388
13388
|
keywords: [
|
|
@@ -13593,7 +13593,7 @@ var package_default = {
|
|
|
13593
13593
|
"@hono/zod-openapi": "^1.1.5",
|
|
13594
13594
|
"@opentelemetry/api": "^1.1.0",
|
|
13595
13595
|
"@rivet-dev/agent-os-core": "^0.1.1",
|
|
13596
|
-
"@rivet-dev/services": "^0.
|
|
13596
|
+
"@rivet-dev/services": "^0.2.0",
|
|
13597
13597
|
"@rivetkit/bare-ts": "^0.6.2",
|
|
13598
13598
|
"@rivetkit/engine-api-full": "workspace:*",
|
|
13599
13599
|
"@rivetkit/engine-cli": "workspace:*",
|
|
@@ -14689,7 +14689,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
14689
14689
|
};
|
|
14690
14690
|
}
|
|
14691
14691
|
|
|
14692
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14692
|
+
// ../rivetkit/dist/tsup/chunk-PIRTTV4D.js
|
|
14693
14693
|
var config2 = /* @__PURE__ */ Config({});
|
|
14694
14694
|
function readWorkflowCbor(bc) {
|
|
14695
14695
|
return readData(bc);
|
|
@@ -14987,7 +14987,7 @@ function decodeWorkflowHistoryTransport(data) {
|
|
|
14987
14987
|
return decodeWorkflowHistory(toUint8Array(data));
|
|
14988
14988
|
}
|
|
14989
14989
|
|
|
14990
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14990
|
+
// ../rivetkit/dist/tsup/chunk-6FEYCVZC.js
|
|
14991
14991
|
function flattenActionHandlers(actions) {
|
|
14992
14992
|
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14993
14993
|
for (const { name, handler } of collectActionEntries(actions)) {
|
|
@@ -15258,9 +15258,9 @@ var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
|
15258
15258
|
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15259
15259
|
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15260
15260
|
/**
|
|
15261
|
-
* Can hibernate WebSockets for
|
|
15262
|
-
*
|
|
15263
|
-
*
|
|
15261
|
+
* Can hibernate WebSockets, both client connections for actions and
|
|
15262
|
+
* events and WebSockets for onWebSocket. A WebSocket that does not
|
|
15263
|
+
* hibernate closes when the actor sleeps, and the client reconnects.
|
|
15264
15264
|
*
|
|
15265
15265
|
* @experimental
|
|
15266
15266
|
**/
|
|
@@ -15407,7 +15407,7 @@ var DocActorOptionsSchema = external_exports.object({
|
|
|
15407
15407
|
"Maximum size of each queue message in bytes. Default: 65536"
|
|
15408
15408
|
),
|
|
15409
15409
|
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
15410
|
-
"Whether WebSockets
|
|
15410
|
+
"Whether WebSockets can be hibernated, both client connections for actions and events and WebSockets using onWebSocket. A WebSocket that does not hibernate closes when the actor sleeps. Default: false"
|
|
15411
15411
|
)
|
|
15412
15412
|
}).describe("Actor options for timeouts and behavior configuration.");
|
|
15413
15413
|
var DocActorConfigSchema = external_exports.object({
|
|
@@ -15482,314 +15482,6 @@ var DocActorConfigSchema = external_exports.object({
|
|
|
15482
15482
|
options: DocActorOptionsSchema.optional()
|
|
15483
15483
|
}).describe("Actor configuration passed to the actor() function.");
|
|
15484
15484
|
|
|
15485
|
-
// ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
|
|
15486
|
-
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
15487
|
-
function isManualTransactionControl(query) {
|
|
15488
|
-
return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
|
|
15489
|
-
}
|
|
15490
|
-
function validateTransactionTimeout(timeout) {
|
|
15491
|
-
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0)) {
|
|
15492
|
-
throw new Error(
|
|
15493
|
-
"db.transaction() timeout must be a positive finite number of milliseconds"
|
|
15494
|
-
);
|
|
15495
|
-
}
|
|
15496
|
-
}
|
|
15497
|
-
function validateTransactionName(name) {
|
|
15498
|
-
if (name === void 0) {
|
|
15499
|
-
return;
|
|
15500
|
-
}
|
|
15501
|
-
if (name.length === 0) {
|
|
15502
|
-
throw new Error("db.transaction() name must not be empty");
|
|
15503
|
-
}
|
|
15504
|
-
}
|
|
15505
|
-
function isSqliteBindingValue(value) {
|
|
15506
|
-
if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
|
|
15507
|
-
return true;
|
|
15508
|
-
}
|
|
15509
|
-
if (Array.isArray(value)) {
|
|
15510
|
-
return value.every((item) => typeof item === "number");
|
|
15511
|
-
}
|
|
15512
|
-
return false;
|
|
15513
|
-
}
|
|
15514
|
-
function isPlainObject3(value) {
|
|
15515
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
15516
|
-
return false;
|
|
15517
|
-
}
|
|
15518
|
-
return Object.getPrototypeOf(value) === Object.prototype;
|
|
15519
|
-
}
|
|
15520
|
-
function isSqliteBindingObject(value) {
|
|
15521
|
-
if (!isPlainObject3(value)) {
|
|
15522
|
-
return false;
|
|
15523
|
-
}
|
|
15524
|
-
return Object.values(value).every((entry) => isSqliteBindingValue(entry));
|
|
15525
|
-
}
|
|
15526
|
-
function toSqliteBindings(input) {
|
|
15527
|
-
if (Array.isArray(input)) {
|
|
15528
|
-
for (const value of input) {
|
|
15529
|
-
if (!isSqliteBindingValue(value)) {
|
|
15530
|
-
throw new Error(
|
|
15531
|
-
`unsupported sqlite binding type: ${typeof value}`
|
|
15532
|
-
);
|
|
15533
|
-
}
|
|
15534
|
-
}
|
|
15535
|
-
return input;
|
|
15536
|
-
}
|
|
15537
|
-
if (isSqliteBindingObject(input)) {
|
|
15538
|
-
return input;
|
|
15539
|
-
}
|
|
15540
|
-
throw new Error("unsupported sqlite binding collection");
|
|
15541
|
-
}
|
|
15542
|
-
var AsyncMutex = class {
|
|
15543
|
-
#locked = false;
|
|
15544
|
-
#waiting = [];
|
|
15545
|
-
async acquire() {
|
|
15546
|
-
while (this.#locked) {
|
|
15547
|
-
await new Promise((resolve) => this.#waiting.push(resolve));
|
|
15548
|
-
}
|
|
15549
|
-
this.#locked = true;
|
|
15550
|
-
}
|
|
15551
|
-
release() {
|
|
15552
|
-
this.#locked = false;
|
|
15553
|
-
const next = this.#waiting.shift();
|
|
15554
|
-
if (next) {
|
|
15555
|
-
next();
|
|
15556
|
-
}
|
|
15557
|
-
}
|
|
15558
|
-
async run(fn) {
|
|
15559
|
-
await this.acquire();
|
|
15560
|
-
try {
|
|
15561
|
-
return await fn();
|
|
15562
|
-
} finally {
|
|
15563
|
-
this.release();
|
|
15564
|
-
}
|
|
15565
|
-
}
|
|
15566
|
-
};
|
|
15567
|
-
|
|
15568
|
-
// ../rivetkit/dist/tsup/chunk-BRYK7XVR.js
|
|
15569
|
-
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
15570
|
-
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
15571
|
-
function registerNativeStateTransactionOpener(provider, opener) {
|
|
15572
|
-
nativeStateTransactionOpeners.set(provider, opener);
|
|
15573
|
-
return provider;
|
|
15574
|
-
}
|
|
15575
|
-
function bindNativeStateTransactionContext(client, context2) {
|
|
15576
|
-
if ((typeof client !== "object" || client === null) && typeof client !== "function") {
|
|
15577
|
-
return client;
|
|
15578
|
-
}
|
|
15579
|
-
const bind = nativeStateTransactionClientBinders.get(client);
|
|
15580
|
-
return (bind == null ? void 0 : bind(context2)) ?? client;
|
|
15581
|
-
}
|
|
15582
|
-
function hasMultipleStatements(query) {
|
|
15583
|
-
const trimmed = query.trim().replace(/;+$/, "").trimEnd();
|
|
15584
|
-
return trimmed.includes(";");
|
|
15585
|
-
}
|
|
15586
|
-
function db({
|
|
15587
|
-
onMigrate,
|
|
15588
|
-
warnOnManualTransactions = true,
|
|
15589
|
-
profiling
|
|
15590
|
-
} = {}) {
|
|
15591
|
-
const provider = {
|
|
15592
|
-
sqliteProfiling: profiling,
|
|
15593
|
-
createClient: async (ctx) => {
|
|
15594
|
-
const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
|
|
15595
|
-
if (!nativeDatabaseProvider) {
|
|
15596
|
-
throw new Error(
|
|
15597
|
-
"native SQLite is required, but the current runtime did not provide a native database provider"
|
|
15598
|
-
);
|
|
15599
|
-
}
|
|
15600
|
-
const db2 = await nativeDatabaseProvider.open(ctx.actorId);
|
|
15601
|
-
let closed = false;
|
|
15602
|
-
let manualTransactionWarned = false;
|
|
15603
|
-
const ensureOpen = () => {
|
|
15604
|
-
if (closed) {
|
|
15605
|
-
throw new Error(
|
|
15606
|
-
"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."
|
|
15607
|
-
);
|
|
15608
|
-
}
|
|
15609
|
-
};
|
|
15610
|
-
const createClient = (target, transactionScoped = false, stateTransactionContext) => {
|
|
15611
|
-
const client2 = {
|
|
15612
|
-
execute: async (query, ...args) => {
|
|
15613
|
-
var _a2, _b, _c, _d;
|
|
15614
|
-
ensureOpen();
|
|
15615
|
-
if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
|
|
15616
|
-
manualTransactionWarned = true;
|
|
15617
|
-
getLogger("database").warn(
|
|
15618
|
-
{ actorId: ctx.actorId },
|
|
15619
|
-
"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."
|
|
15620
|
-
);
|
|
15621
|
-
}
|
|
15622
|
-
const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
|
|
15623
|
-
const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
|
|
15624
|
-
const start = performance.now();
|
|
15625
|
-
try {
|
|
15626
|
-
if (args.length > 0) {
|
|
15627
|
-
const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
|
|
15628
|
-
const { rows, columns } = await target.execute(
|
|
15629
|
-
query,
|
|
15630
|
-
bindings
|
|
15631
|
-
);
|
|
15632
|
-
return rows.map(
|
|
15633
|
-
(row) => rowToObject(row, columns)
|
|
15634
|
-
);
|
|
15635
|
-
}
|
|
15636
|
-
if (!hasMultipleStatements(query)) {
|
|
15637
|
-
const { rows, columns } = await target.execute(
|
|
15638
|
-
query,
|
|
15639
|
-
void 0
|
|
15640
|
-
);
|
|
15641
|
-
return rows.map(
|
|
15642
|
-
(row) => rowToObject(row, columns)
|
|
15643
|
-
);
|
|
15644
|
-
}
|
|
15645
|
-
return await execMultiStatement(
|
|
15646
|
-
target,
|
|
15647
|
-
query
|
|
15648
|
-
);
|
|
15649
|
-
} finally {
|
|
15650
|
-
const durationMs = performance.now() - start;
|
|
15651
|
-
(_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
|
|
15652
|
-
if (ctx.metrics) {
|
|
15653
|
-
const kvReads = ctx.metrics.totalKvReads - kvReadsBefore;
|
|
15654
|
-
const kvWrites = ctx.metrics.totalKvWrites - kvWritesBefore;
|
|
15655
|
-
(_d = ctx.log) == null ? void 0 : _d.debug({
|
|
15656
|
-
msg: "sql query",
|
|
15657
|
-
query: query.slice(0, 120),
|
|
15658
|
-
durationMs,
|
|
15659
|
-
kvReads,
|
|
15660
|
-
kvWrites
|
|
15661
|
-
});
|
|
15662
|
-
}
|
|
15663
|
-
}
|
|
15664
|
-
},
|
|
15665
|
-
transaction: async (callback, options) => {
|
|
15666
|
-
var _a2, _b;
|
|
15667
|
-
validateTransactionTimeout(options == null ? void 0 : options.timeout);
|
|
15668
|
-
validateTransactionName(options == null ? void 0 : options.name);
|
|
15669
|
-
if (transactionScoped && ((_a2 = options == null ? void 0 : options.experimental) == null ? void 0 : _a2.includeState)) {
|
|
15670
|
-
throw new Error(
|
|
15671
|
-
"experimental.includeState is not supported for nested transactions"
|
|
15672
|
-
);
|
|
15673
|
-
}
|
|
15674
|
-
const includeState = ((_b = options == null ? void 0 : options.experimental) == null ? void 0 : _b.includeState) === true;
|
|
15675
|
-
const stateScope = includeState && stateTransactionContext ? await stateTransactionContext.enter() : void 0;
|
|
15676
|
-
try {
|
|
15677
|
-
const transaction = includeState ? await (() => {
|
|
15678
|
-
const beginStateTransaction = ctx.nativeDatabaseProvider && nativeStateTransactionOpeners.get(
|
|
15679
|
-
ctx.nativeDatabaseProvider
|
|
15680
|
-
);
|
|
15681
|
-
if (!beginStateTransaction) {
|
|
15682
|
-
throw new Error(
|
|
15683
|
-
"experimental.includeState is only supported by RivetKit's embedded database provider"
|
|
15684
|
-
);
|
|
15685
|
-
}
|
|
15686
|
-
return beginStateTransaction(
|
|
15687
|
-
options == null ? void 0 : options.timeout,
|
|
15688
|
-
stateScope
|
|
15689
|
-
);
|
|
15690
|
-
})() : await db2.beginTransaction(
|
|
15691
|
-
options == null ? void 0 : options.timeout,
|
|
15692
|
-
options == null ? void 0 : options.name
|
|
15693
|
-
);
|
|
15694
|
-
const tx = createClient(transaction, true);
|
|
15695
|
-
try {
|
|
15696
|
-
const result = await callback(tx);
|
|
15697
|
-
await transaction.commit();
|
|
15698
|
-
return result;
|
|
15699
|
-
} catch (error46) {
|
|
15700
|
-
try {
|
|
15701
|
-
await transaction.rollback();
|
|
15702
|
-
} catch {
|
|
15703
|
-
}
|
|
15704
|
-
throw error46;
|
|
15705
|
-
}
|
|
15706
|
-
} finally {
|
|
15707
|
-
if (stateScope !== void 0) {
|
|
15708
|
-
stateTransactionContext == null ? void 0 : stateTransactionContext.exit(stateScope);
|
|
15709
|
-
}
|
|
15710
|
-
}
|
|
15711
|
-
},
|
|
15712
|
-
close: async () => {
|
|
15713
|
-
if (!closed) {
|
|
15714
|
-
closed = true;
|
|
15715
|
-
await db2.close();
|
|
15716
|
-
}
|
|
15717
|
-
},
|
|
15718
|
-
nativeMetrics: () => {
|
|
15719
|
-
var _a2;
|
|
15720
|
-
return ((_a2 = db2.nativeMetrics) == null ? void 0 : _a2.call(db2)) ?? null;
|
|
15721
|
-
}
|
|
15722
|
-
};
|
|
15723
|
-
if (!transactionScoped) {
|
|
15724
|
-
nativeStateTransactionClientBinders.set(
|
|
15725
|
-
client2,
|
|
15726
|
-
(context2) => createClient(target, false, context2)
|
|
15727
|
-
);
|
|
15728
|
-
}
|
|
15729
|
-
return client2;
|
|
15730
|
-
};
|
|
15731
|
-
const client = createClient(db2);
|
|
15732
|
-
return client;
|
|
15733
|
-
},
|
|
15734
|
-
onMigrate: async (client) => {
|
|
15735
|
-
if (onMigrate) {
|
|
15736
|
-
await withMigrationSavepoint(
|
|
15737
|
-
client,
|
|
15738
|
-
(leased) => onMigrate(leased)
|
|
15739
|
-
);
|
|
15740
|
-
}
|
|
15741
|
-
}
|
|
15742
|
-
};
|
|
15743
|
-
return provider;
|
|
15744
|
-
}
|
|
15745
|
-
function rowToObject(row, columns) {
|
|
15746
|
-
const rowObj = {};
|
|
15747
|
-
for (let i = 0; i < columns.length; i++) {
|
|
15748
|
-
rowObj[columns[i]] = row[i];
|
|
15749
|
-
}
|
|
15750
|
-
return rowObj;
|
|
15751
|
-
}
|
|
15752
|
-
async function execMultiStatement(db2, query) {
|
|
15753
|
-
const results = [];
|
|
15754
|
-
let columnNames = null;
|
|
15755
|
-
await db2.exec(query, (row, columns) => {
|
|
15756
|
-
if (!columnNames) {
|
|
15757
|
-
columnNames = columns;
|
|
15758
|
-
}
|
|
15759
|
-
results.push(rowToObject(row, columnNames));
|
|
15760
|
-
});
|
|
15761
|
-
return results;
|
|
15762
|
-
}
|
|
15763
|
-
async function withMigrationSavepoint(client, callback) {
|
|
15764
|
-
return await client.transaction(
|
|
15765
|
-
async (transaction) => {
|
|
15766
|
-
await transaction.execute("SAVEPOINT __rivet_on_migrate");
|
|
15767
|
-
try {
|
|
15768
|
-
const result = await callback(transaction);
|
|
15769
|
-
await transaction.execute(
|
|
15770
|
-
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
15771
|
-
);
|
|
15772
|
-
return result;
|
|
15773
|
-
} catch (error46) {
|
|
15774
|
-
try {
|
|
15775
|
-
await transaction.execute(
|
|
15776
|
-
"ROLLBACK TO SAVEPOINT __rivet_on_migrate"
|
|
15777
|
-
);
|
|
15778
|
-
} finally {
|
|
15779
|
-
await transaction.execute(
|
|
15780
|
-
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
15781
|
-
);
|
|
15782
|
-
}
|
|
15783
|
-
throw error46;
|
|
15784
|
-
}
|
|
15785
|
-
},
|
|
15786
|
-
{
|
|
15787
|
-
name: "rivetkit-migration",
|
|
15788
|
-
timeout: MIGRATION_TRANSACTION_TIMEOUT_MS
|
|
15789
|
-
}
|
|
15790
|
-
);
|
|
15791
|
-
}
|
|
15792
|
-
|
|
15793
15485
|
// ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
|
|
15794
15486
|
var EMPTY_KEY = "/";
|
|
15795
15487
|
var KEY_SEPARATOR = "/";
|
|
@@ -15907,7 +15599,7 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15907
15599
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15908
15600
|
}
|
|
15909
15601
|
|
|
15910
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15602
|
+
// ../rivetkit/dist/tsup/chunk-SREEDRMF.js
|
|
15911
15603
|
function logger() {
|
|
15912
15604
|
return getLogger("actor-client");
|
|
15913
15605
|
}
|
|
@@ -15945,7 +15637,90 @@ async function importWebSocket() {
|
|
|
15945
15637
|
return webSocketPromise;
|
|
15946
15638
|
}
|
|
15947
15639
|
|
|
15948
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15640
|
+
// ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
|
|
15641
|
+
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
15642
|
+
function isManualTransactionControl(query) {
|
|
15643
|
+
return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
|
|
15644
|
+
}
|
|
15645
|
+
function validateTransactionTimeout(timeout) {
|
|
15646
|
+
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0)) {
|
|
15647
|
+
throw new Error(
|
|
15648
|
+
"db.transaction() timeout must be a positive finite number of milliseconds"
|
|
15649
|
+
);
|
|
15650
|
+
}
|
|
15651
|
+
}
|
|
15652
|
+
function validateTransactionName(name) {
|
|
15653
|
+
if (name === void 0) {
|
|
15654
|
+
return;
|
|
15655
|
+
}
|
|
15656
|
+
if (name.length === 0) {
|
|
15657
|
+
throw new Error("db.transaction() name must not be empty");
|
|
15658
|
+
}
|
|
15659
|
+
}
|
|
15660
|
+
function isSqliteBindingValue(value) {
|
|
15661
|
+
if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
|
|
15662
|
+
return true;
|
|
15663
|
+
}
|
|
15664
|
+
if (Array.isArray(value)) {
|
|
15665
|
+
return value.every((item) => typeof item === "number");
|
|
15666
|
+
}
|
|
15667
|
+
return false;
|
|
15668
|
+
}
|
|
15669
|
+
function isPlainObject3(value) {
|
|
15670
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
15671
|
+
return false;
|
|
15672
|
+
}
|
|
15673
|
+
return Object.getPrototypeOf(value) === Object.prototype;
|
|
15674
|
+
}
|
|
15675
|
+
function isSqliteBindingObject(value) {
|
|
15676
|
+
if (!isPlainObject3(value)) {
|
|
15677
|
+
return false;
|
|
15678
|
+
}
|
|
15679
|
+
return Object.values(value).every((entry) => isSqliteBindingValue(entry));
|
|
15680
|
+
}
|
|
15681
|
+
function toSqliteBindings(input) {
|
|
15682
|
+
if (Array.isArray(input)) {
|
|
15683
|
+
for (const value of input) {
|
|
15684
|
+
if (!isSqliteBindingValue(value)) {
|
|
15685
|
+
throw new Error(
|
|
15686
|
+
`unsupported sqlite binding type: ${typeof value}`
|
|
15687
|
+
);
|
|
15688
|
+
}
|
|
15689
|
+
}
|
|
15690
|
+
return input;
|
|
15691
|
+
}
|
|
15692
|
+
if (isSqliteBindingObject(input)) {
|
|
15693
|
+
return input;
|
|
15694
|
+
}
|
|
15695
|
+
throw new Error("unsupported sqlite binding collection");
|
|
15696
|
+
}
|
|
15697
|
+
var AsyncMutex = class {
|
|
15698
|
+
#locked = false;
|
|
15699
|
+
#waiting = [];
|
|
15700
|
+
async acquire() {
|
|
15701
|
+
while (this.#locked) {
|
|
15702
|
+
await new Promise((resolve) => this.#waiting.push(resolve));
|
|
15703
|
+
}
|
|
15704
|
+
this.#locked = true;
|
|
15705
|
+
}
|
|
15706
|
+
release() {
|
|
15707
|
+
this.#locked = false;
|
|
15708
|
+
const next = this.#waiting.shift();
|
|
15709
|
+
if (next) {
|
|
15710
|
+
next();
|
|
15711
|
+
}
|
|
15712
|
+
}
|
|
15713
|
+
async run(fn) {
|
|
15714
|
+
await this.acquire();
|
|
15715
|
+
try {
|
|
15716
|
+
return await fn();
|
|
15717
|
+
} finally {
|
|
15718
|
+
this.release();
|
|
15719
|
+
}
|
|
15720
|
+
}
|
|
15721
|
+
};
|
|
15722
|
+
|
|
15723
|
+
// ../rivetkit/dist/tsup/chunk-DIIXK2AW.js
|
|
15949
15724
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15950
15725
|
|
|
15951
15726
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -17160,7 +16935,7 @@ var TraceAPI = (
|
|
|
17160
16935
|
// ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
17161
16936
|
var trace = TraceAPI.getInstance();
|
|
17162
16937
|
|
|
17163
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
16938
|
+
// ../rivetkit/dist/tsup/chunk-DIIXK2AW.js
|
|
17164
16939
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
17165
16940
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
17166
16941
|
var PATH_CONNECT = "/connect";
|
|
@@ -23356,6 +23131,231 @@ function apiActorToOutput(actor2) {
|
|
|
23356
23131
|
};
|
|
23357
23132
|
}
|
|
23358
23133
|
|
|
23134
|
+
// ../rivetkit/dist/tsup/chunk-V43A2WB2.js
|
|
23135
|
+
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
23136
|
+
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
23137
|
+
function registerNativeStateTransactionOpener(provider, opener) {
|
|
23138
|
+
nativeStateTransactionOpeners.set(provider, opener);
|
|
23139
|
+
return provider;
|
|
23140
|
+
}
|
|
23141
|
+
function bindNativeStateTransactionContext(client, context2) {
|
|
23142
|
+
if ((typeof client !== "object" || client === null) && typeof client !== "function") {
|
|
23143
|
+
return client;
|
|
23144
|
+
}
|
|
23145
|
+
const bind = nativeStateTransactionClientBinders.get(client);
|
|
23146
|
+
return (bind == null ? void 0 : bind(context2)) ?? client;
|
|
23147
|
+
}
|
|
23148
|
+
function hasMultipleStatements(query) {
|
|
23149
|
+
const trimmed = query.trim().replace(/;+$/, "").trimEnd();
|
|
23150
|
+
return trimmed.includes(";");
|
|
23151
|
+
}
|
|
23152
|
+
function db({
|
|
23153
|
+
onMigrate,
|
|
23154
|
+
warnOnManualTransactions = true,
|
|
23155
|
+
profiling
|
|
23156
|
+
} = {}) {
|
|
23157
|
+
const provider = {
|
|
23158
|
+
sqliteProfiling: profiling,
|
|
23159
|
+
createClient: async (ctx) => {
|
|
23160
|
+
const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
|
|
23161
|
+
if (!nativeDatabaseProvider) {
|
|
23162
|
+
throw new Error(
|
|
23163
|
+
"native SQLite is required, but the current runtime did not provide a native database provider"
|
|
23164
|
+
);
|
|
23165
|
+
}
|
|
23166
|
+
const db2 = await nativeDatabaseProvider.open(ctx.actorId);
|
|
23167
|
+
let closed = false;
|
|
23168
|
+
let manualTransactionWarned = false;
|
|
23169
|
+
const ensureOpen = () => {
|
|
23170
|
+
if (closed) {
|
|
23171
|
+
throw new Error(
|
|
23172
|
+
"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."
|
|
23173
|
+
);
|
|
23174
|
+
}
|
|
23175
|
+
};
|
|
23176
|
+
const createClient = (target, transactionScoped = false, stateTransactionContext) => {
|
|
23177
|
+
const client2 = {
|
|
23178
|
+
execute: async (query, ...args) => {
|
|
23179
|
+
var _a2, _b, _c, _d;
|
|
23180
|
+
ensureOpen();
|
|
23181
|
+
if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
|
|
23182
|
+
manualTransactionWarned = true;
|
|
23183
|
+
getLogger("database").warn(
|
|
23184
|
+
{ actorId: ctx.actorId },
|
|
23185
|
+
"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."
|
|
23186
|
+
);
|
|
23187
|
+
}
|
|
23188
|
+
const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
|
|
23189
|
+
const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
|
|
23190
|
+
const start = performance.now();
|
|
23191
|
+
try {
|
|
23192
|
+
if (args.length > 0) {
|
|
23193
|
+
const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
|
|
23194
|
+
const { rows, columns } = await target.execute(
|
|
23195
|
+
query,
|
|
23196
|
+
bindings
|
|
23197
|
+
);
|
|
23198
|
+
return rows.map(
|
|
23199
|
+
(row) => rowToObject(row, columns)
|
|
23200
|
+
);
|
|
23201
|
+
}
|
|
23202
|
+
if (!hasMultipleStatements(query)) {
|
|
23203
|
+
const { rows, columns } = await target.execute(
|
|
23204
|
+
query,
|
|
23205
|
+
void 0
|
|
23206
|
+
);
|
|
23207
|
+
return rows.map(
|
|
23208
|
+
(row) => rowToObject(row, columns)
|
|
23209
|
+
);
|
|
23210
|
+
}
|
|
23211
|
+
return await execMultiStatement(
|
|
23212
|
+
target,
|
|
23213
|
+
query
|
|
23214
|
+
);
|
|
23215
|
+
} finally {
|
|
23216
|
+
const durationMs = performance.now() - start;
|
|
23217
|
+
(_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
|
|
23218
|
+
if (ctx.metrics) {
|
|
23219
|
+
const kvReads = ctx.metrics.totalKvReads - kvReadsBefore;
|
|
23220
|
+
const kvWrites = ctx.metrics.totalKvWrites - kvWritesBefore;
|
|
23221
|
+
(_d = ctx.log) == null ? void 0 : _d.debug({
|
|
23222
|
+
msg: "sql query",
|
|
23223
|
+
query: query.slice(0, 120),
|
|
23224
|
+
durationMs,
|
|
23225
|
+
kvReads,
|
|
23226
|
+
kvWrites
|
|
23227
|
+
});
|
|
23228
|
+
}
|
|
23229
|
+
}
|
|
23230
|
+
},
|
|
23231
|
+
transaction: async (callback, options) => {
|
|
23232
|
+
var _a2, _b;
|
|
23233
|
+
validateTransactionTimeout(options == null ? void 0 : options.timeout);
|
|
23234
|
+
validateTransactionName(options == null ? void 0 : options.name);
|
|
23235
|
+
if (transactionScoped && ((_a2 = options == null ? void 0 : options.experimental) == null ? void 0 : _a2.includeState)) {
|
|
23236
|
+
throw new Error(
|
|
23237
|
+
"experimental.includeState is not supported for nested transactions"
|
|
23238
|
+
);
|
|
23239
|
+
}
|
|
23240
|
+
const includeState = ((_b = options == null ? void 0 : options.experimental) == null ? void 0 : _b.includeState) === true;
|
|
23241
|
+
const stateScope = includeState && stateTransactionContext ? await stateTransactionContext.enter() : void 0;
|
|
23242
|
+
try {
|
|
23243
|
+
const transaction = includeState ? await (() => {
|
|
23244
|
+
const beginStateTransaction = ctx.nativeDatabaseProvider && nativeStateTransactionOpeners.get(
|
|
23245
|
+
ctx.nativeDatabaseProvider
|
|
23246
|
+
);
|
|
23247
|
+
if (!beginStateTransaction) {
|
|
23248
|
+
throw new Error(
|
|
23249
|
+
"experimental.includeState is only supported by RivetKit's embedded database provider"
|
|
23250
|
+
);
|
|
23251
|
+
}
|
|
23252
|
+
return beginStateTransaction(
|
|
23253
|
+
options == null ? void 0 : options.timeout,
|
|
23254
|
+
stateScope
|
|
23255
|
+
);
|
|
23256
|
+
})() : await db2.beginTransaction(
|
|
23257
|
+
options == null ? void 0 : options.timeout,
|
|
23258
|
+
options == null ? void 0 : options.name
|
|
23259
|
+
);
|
|
23260
|
+
const tx = createClient(transaction, true);
|
|
23261
|
+
try {
|
|
23262
|
+
const result = await callback(tx);
|
|
23263
|
+
await transaction.commit();
|
|
23264
|
+
return result;
|
|
23265
|
+
} catch (error46) {
|
|
23266
|
+
try {
|
|
23267
|
+
await transaction.rollback();
|
|
23268
|
+
} catch {
|
|
23269
|
+
}
|
|
23270
|
+
throw error46;
|
|
23271
|
+
}
|
|
23272
|
+
} finally {
|
|
23273
|
+
if (stateScope !== void 0) {
|
|
23274
|
+
stateTransactionContext == null ? void 0 : stateTransactionContext.exit(stateScope);
|
|
23275
|
+
}
|
|
23276
|
+
}
|
|
23277
|
+
},
|
|
23278
|
+
close: async () => {
|
|
23279
|
+
if (!closed) {
|
|
23280
|
+
closed = true;
|
|
23281
|
+
await db2.close();
|
|
23282
|
+
}
|
|
23283
|
+
},
|
|
23284
|
+
nativeMetrics: () => {
|
|
23285
|
+
var _a2;
|
|
23286
|
+
return ((_a2 = db2.nativeMetrics) == null ? void 0 : _a2.call(db2)) ?? null;
|
|
23287
|
+
}
|
|
23288
|
+
};
|
|
23289
|
+
if (!transactionScoped) {
|
|
23290
|
+
nativeStateTransactionClientBinders.set(
|
|
23291
|
+
client2,
|
|
23292
|
+
(context2) => createClient(target, false, context2)
|
|
23293
|
+
);
|
|
23294
|
+
}
|
|
23295
|
+
return client2;
|
|
23296
|
+
};
|
|
23297
|
+
const client = createClient(db2);
|
|
23298
|
+
return client;
|
|
23299
|
+
},
|
|
23300
|
+
onMigrate: async (client) => {
|
|
23301
|
+
if (onMigrate) {
|
|
23302
|
+
await withMigrationSavepoint(
|
|
23303
|
+
client,
|
|
23304
|
+
(leased) => onMigrate(leased)
|
|
23305
|
+
);
|
|
23306
|
+
}
|
|
23307
|
+
}
|
|
23308
|
+
};
|
|
23309
|
+
return provider;
|
|
23310
|
+
}
|
|
23311
|
+
function rowToObject(row, columns) {
|
|
23312
|
+
const rowObj = {};
|
|
23313
|
+
for (let i = 0; i < columns.length; i++) {
|
|
23314
|
+
rowObj[columns[i]] = row[i];
|
|
23315
|
+
}
|
|
23316
|
+
return rowObj;
|
|
23317
|
+
}
|
|
23318
|
+
async function execMultiStatement(db2, query) {
|
|
23319
|
+
const results = [];
|
|
23320
|
+
let columnNames = null;
|
|
23321
|
+
await db2.exec(query, (row, columns) => {
|
|
23322
|
+
if (!columnNames) {
|
|
23323
|
+
columnNames = columns;
|
|
23324
|
+
}
|
|
23325
|
+
results.push(rowToObject(row, columnNames));
|
|
23326
|
+
});
|
|
23327
|
+
return results;
|
|
23328
|
+
}
|
|
23329
|
+
async function withMigrationSavepoint(client, callback) {
|
|
23330
|
+
return await client.transaction(
|
|
23331
|
+
async (transaction) => {
|
|
23332
|
+
await transaction.execute("SAVEPOINT __rivet_on_migrate");
|
|
23333
|
+
try {
|
|
23334
|
+
const result = await callback(transaction);
|
|
23335
|
+
await transaction.execute(
|
|
23336
|
+
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
23337
|
+
);
|
|
23338
|
+
return result;
|
|
23339
|
+
} catch (error46) {
|
|
23340
|
+
try {
|
|
23341
|
+
await transaction.execute(
|
|
23342
|
+
"ROLLBACK TO SAVEPOINT __rivet_on_migrate"
|
|
23343
|
+
);
|
|
23344
|
+
} finally {
|
|
23345
|
+
await transaction.execute(
|
|
23346
|
+
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
23347
|
+
);
|
|
23348
|
+
}
|
|
23349
|
+
throw error46;
|
|
23350
|
+
}
|
|
23351
|
+
},
|
|
23352
|
+
{
|
|
23353
|
+
name: "rivetkit-migration",
|
|
23354
|
+
timeout: MIGRATION_TRANSACTION_TIMEOUT_MS
|
|
23355
|
+
}
|
|
23356
|
+
);
|
|
23357
|
+
}
|
|
23358
|
+
|
|
23359
23359
|
// ../../../shared/typescript/virtual-websocket/dist/mod.js
|
|
23360
23360
|
var VirtualWebSocket = class {
|
|
23361
23361
|
static CONNECTING = 0;
|