@rivetkit/supabase 2.3.24-rc.1 → 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.
- package/dist/mod.js +499 -708
- package/dist/mod.mjs +499 -708
- 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-
|
|
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-
|
|
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.
|
|
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-
|
|
14657
|
+
// ../rivetkit/dist/tsup/chunk-FHRRLHJE.js
|
|
14658
14658
|
var config2 = /* @__PURE__ */ Config({});
|
|
14659
14659
|
function readWorkflowCbor(bc) {
|
|
14660
14660
|
return readData(bc);
|
|
@@ -14952,7 +14952,7 @@ function decodeWorkflowHistoryTransport(data) {
|
|
|
14952
14952
|
return decodeWorkflowHistory(toUint8Array(data));
|
|
14953
14953
|
}
|
|
14954
14954
|
|
|
14955
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14955
|
+
// ../rivetkit/dist/tsup/chunk-CSOHAAZK.js
|
|
14956
14956
|
function flattenActionHandlers(actions) {
|
|
14957
14957
|
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14958
14958
|
for (const { name, handler } of collectActionEntries(actions)) {
|
|
@@ -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 = "/";
|
|
@@ -15561,93 +15869,10 @@ function makePrefixedKey(key) {
|
|
|
15561
15869
|
return prefixed;
|
|
15562
15870
|
}
|
|
15563
15871
|
function removePrefixFromKey(prefixedKey) {
|
|
15564
|
-
return prefixedKey.slice(KEYS.KV.length);
|
|
15565
|
-
}
|
|
15566
|
-
|
|
15567
|
-
// ../rivetkit/dist/tsup/chunk-JTHHCZCZ.js
|
|
15568
|
-
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
15569
|
-
function isManualTransactionControl(query) {
|
|
15570
|
-
return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
|
|
15571
|
-
}
|
|
15572
|
-
function validateTransactionTimeout(timeout) {
|
|
15573
|
-
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0)) {
|
|
15574
|
-
throw new Error(
|
|
15575
|
-
"db.transaction() timeout must be a positive finite number of milliseconds"
|
|
15576
|
-
);
|
|
15577
|
-
}
|
|
15578
|
-
}
|
|
15579
|
-
function validateTransactionName(name) {
|
|
15580
|
-
if (name === void 0) {
|
|
15581
|
-
return;
|
|
15582
|
-
}
|
|
15583
|
-
if (name.length === 0) {
|
|
15584
|
-
throw new Error("db.transaction() name must not be empty");
|
|
15585
|
-
}
|
|
15586
|
-
}
|
|
15587
|
-
function isSqliteBindingValue(value) {
|
|
15588
|
-
if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
|
|
15589
|
-
return true;
|
|
15590
|
-
}
|
|
15591
|
-
if (Array.isArray(value)) {
|
|
15592
|
-
return value.every((item) => typeof item === "number");
|
|
15593
|
-
}
|
|
15594
|
-
return false;
|
|
15595
|
-
}
|
|
15596
|
-
function isPlainObject3(value) {
|
|
15597
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
15598
|
-
return false;
|
|
15599
|
-
}
|
|
15600
|
-
return Object.getPrototypeOf(value) === Object.prototype;
|
|
15601
|
-
}
|
|
15602
|
-
function isSqliteBindingObject(value) {
|
|
15603
|
-
if (!isPlainObject3(value)) {
|
|
15604
|
-
return false;
|
|
15605
|
-
}
|
|
15606
|
-
return Object.values(value).every((entry) => isSqliteBindingValue(entry));
|
|
15607
|
-
}
|
|
15608
|
-
function toSqliteBindings(input) {
|
|
15609
|
-
if (Array.isArray(input)) {
|
|
15610
|
-
for (const value of input) {
|
|
15611
|
-
if (!isSqliteBindingValue(value)) {
|
|
15612
|
-
throw new Error(
|
|
15613
|
-
`unsupported sqlite binding type: ${typeof value}`
|
|
15614
|
-
);
|
|
15615
|
-
}
|
|
15616
|
-
}
|
|
15617
|
-
return input;
|
|
15618
|
-
}
|
|
15619
|
-
if (isSqliteBindingObject(input)) {
|
|
15620
|
-
return input;
|
|
15621
|
-
}
|
|
15622
|
-
throw new Error("unsupported sqlite binding collection");
|
|
15623
|
-
}
|
|
15624
|
-
var AsyncMutex = class {
|
|
15625
|
-
#locked = false;
|
|
15626
|
-
#waiting = [];
|
|
15627
|
-
async acquire() {
|
|
15628
|
-
while (this.#locked) {
|
|
15629
|
-
await new Promise((resolve) => this.#waiting.push(resolve));
|
|
15630
|
-
}
|
|
15631
|
-
this.#locked = true;
|
|
15632
|
-
}
|
|
15633
|
-
release() {
|
|
15634
|
-
this.#locked = false;
|
|
15635
|
-
const next = this.#waiting.shift();
|
|
15636
|
-
if (next) {
|
|
15637
|
-
next();
|
|
15638
|
-
}
|
|
15639
|
-
}
|
|
15640
|
-
async run(fn) {
|
|
15641
|
-
await this.acquire();
|
|
15642
|
-
try {
|
|
15643
|
-
return await fn();
|
|
15644
|
-
} finally {
|
|
15645
|
-
this.release();
|
|
15646
|
-
}
|
|
15647
|
-
}
|
|
15648
|
-
};
|
|
15872
|
+
return prefixedKey.slice(KEYS.KV.length);
|
|
15873
|
+
}
|
|
15649
15874
|
|
|
15650
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15875
|
+
// ../rivetkit/dist/tsup/chunk-3KHT4UQA.js
|
|
15651
15876
|
function logger() {
|
|
15652
15877
|
return getLogger("actor-client");
|
|
15653
15878
|
}
|
|
@@ -15685,7 +15910,7 @@ async function importWebSocket() {
|
|
|
15685
15910
|
return webSocketPromise;
|
|
15686
15911
|
}
|
|
15687
15912
|
|
|
15688
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
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-
|
|
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";
|
|
@@ -18983,6 +19208,14 @@ function isResponseLike(value) {
|
|
|
18983
19208
|
function isHeadersLike(value) {
|
|
18984
19209
|
return typeof value === "object" && value !== null && typeof value.entries === "function";
|
|
18985
19210
|
}
|
|
19211
|
+
function readRequestBody(request) {
|
|
19212
|
+
if (!request.body) return request.arrayBuffer();
|
|
19213
|
+
return new Response(
|
|
19214
|
+
request.body.pipeThrough(new TransformStream(), {
|
|
19215
|
+
signal: request.signal
|
|
19216
|
+
})
|
|
19217
|
+
).arrayBuffer();
|
|
19218
|
+
}
|
|
18986
19219
|
function* walkErrorChain(error46, maxDepth = 8) {
|
|
18987
19220
|
let current = error46;
|
|
18988
19221
|
let depth = 0;
|
|
@@ -19511,9 +19744,10 @@ async function rawHttpFetch(driver, target, params, input, init, options = {}, t
|
|
|
19511
19744
|
initHeaders.forEach((value, key) => {
|
|
19512
19745
|
mergedHeaders.set(key, value);
|
|
19513
19746
|
});
|
|
19747
|
+
const readsInputBody = (init == null ? void 0 : init.body) === void 0 && input.method !== "GET" && input.method !== "HEAD";
|
|
19514
19748
|
mergedInit = {
|
|
19515
19749
|
method: input.method,
|
|
19516
|
-
body: input
|
|
19750
|
+
body: readsInputBody ? await readRequestBody(input) : void 0,
|
|
19517
19751
|
mode: input.mode,
|
|
19518
19752
|
credentials: input.credentials,
|
|
19519
19753
|
redirect: input.redirect,
|
|
@@ -21932,6 +22166,8 @@ var ClientConfigSchemaBase = v4_default.object({
|
|
|
21932
22166
|
// This is required in the client config in order to support
|
|
21933
22167
|
// `proxyWebSocket`
|
|
21934
22168
|
getUpgradeWebSocket: v4_default.custom().optional(),
|
|
22169
|
+
/** Replaces global fetch for actor HTTP gateway requests. */
|
|
22170
|
+
fetch: v4_default.custom().optional(),
|
|
21935
22171
|
/** Whether to automatically perform health checks when the client is created. */
|
|
21936
22172
|
disableMetadataLookup: v4_default.boolean().optional().default(false),
|
|
21937
22173
|
/**
|
|
@@ -21993,18 +22229,26 @@ async function sendHttpRequestToGateway(runConfig, gatewayUrl, actorRequest, opt
|
|
|
21993
22229
|
if (actorRequest.bodyUsed) {
|
|
21994
22230
|
throw new Error("Request body has already been consumed");
|
|
21995
22231
|
}
|
|
21996
|
-
|
|
21997
|
-
|
|
22232
|
+
const bytes = await readRequestBody(actorRequest);
|
|
22233
|
+
if (bytes.byteLength > 0) {
|
|
22234
|
+
bodyToSend = bytes;
|
|
21998
22235
|
guardHeaders.delete("transfer-encoding");
|
|
21999
22236
|
guardHeaders.delete("content-length");
|
|
22000
22237
|
}
|
|
22001
22238
|
}
|
|
22002
|
-
|
|
22239
|
+
const fetchImpl = runConfig.fetch ?? fetch;
|
|
22240
|
+
return fetchImpl(gatewayUrl, {
|
|
22003
22241
|
method: actorRequest.method,
|
|
22004
22242
|
headers: guardHeaders,
|
|
22005
22243
|
body: bodyToSend,
|
|
22006
22244
|
signal: actorRequest.signal,
|
|
22007
|
-
|
|
22245
|
+
mode: actorRequest.mode,
|
|
22246
|
+
credentials: actorRequest.credentials,
|
|
22247
|
+
redirect: actorRequest.redirect,
|
|
22248
|
+
referrer: actorRequest.referrer,
|
|
22249
|
+
referrerPolicy: actorRequest.referrerPolicy,
|
|
22250
|
+
integrity: actorRequest.integrity,
|
|
22251
|
+
keepalive: actorRequest.keepalive
|
|
22008
22252
|
});
|
|
22009
22253
|
}
|
|
22010
22254
|
function buildGuardHeaders(runConfig, actorRequest, options) {
|
|
@@ -22997,309 +23241,84 @@ var RemoteEngineControlClient = class {
|
|
|
22997
23241
|
}
|
|
22998
23242
|
setGetUpgradeWebSocket(getUpgradeWebSocket) {
|
|
22999
23243
|
this.#config.getUpgradeWebSocket = getUpgradeWebSocket;
|
|
23000
|
-
}
|
|
23001
|
-
#buildGatewayUrlForTarget(config3, target, path2, options = {}) {
|
|
23002
|
-
const endpoint = getEndpoint(config3);
|
|
23003
|
-
if (shouldSkipReadyWait(options) && directActorIdFromTarget(target) && canUseDirectSkipReadyWaitPath(path2)) {
|
|
23004
|
-
return combineUrlPath(endpoint, path2);
|
|
23005
|
-
}
|
|
23006
|
-
if ("directId" in target) {
|
|
23007
|
-
return buildActorGatewayUrl(
|
|
23008
|
-
endpoint,
|
|
23009
|
-
target.directId,
|
|
23010
|
-
config3.token,
|
|
23011
|
-
path2
|
|
23012
|
-
);
|
|
23013
|
-
}
|
|
23014
|
-
if ("getForId" in target) {
|
|
23015
|
-
return buildActorGatewayUrl(
|
|
23016
|
-
endpoint,
|
|
23017
|
-
target.getForId.actorId,
|
|
23018
|
-
config3.token,
|
|
23019
|
-
path2
|
|
23020
|
-
);
|
|
23021
|
-
}
|
|
23022
|
-
if ("getForKey" in target || "getOrCreateForKey" in target) {
|
|
23023
|
-
return buildActorQueryGatewayUrl(
|
|
23024
|
-
endpoint,
|
|
23025
|
-
config3.namespace,
|
|
23026
|
-
target,
|
|
23027
|
-
config3.token,
|
|
23028
|
-
path2,
|
|
23029
|
-
config3.maxInputSize,
|
|
23030
|
-
void 0,
|
|
23031
|
-
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ?? config3.poolName : void 0,
|
|
23032
|
-
options
|
|
23033
|
-
);
|
|
23034
|
-
}
|
|
23035
|
-
if ("create" in target) {
|
|
23036
|
-
throw new Error(
|
|
23037
|
-
"Gateway URLs only support direct actor IDs, get, and getOrCreate targets."
|
|
23038
|
-
);
|
|
23039
|
-
}
|
|
23040
|
-
throw new Error("unreachable: unknown gateway target type");
|
|
23041
|
-
}
|
|
23042
|
-
};
|
|
23043
|
-
function canUseDirectSkipReadyWaitPath(path2) {
|
|
23044
|
-
return isActorHttpRequestPath(path2) || isPathOrQuery(path2, PATH_CONNECT) || isPathOrQuery(path2, PATH_WEBSOCKET_BASE) || path2.startsWith(PATH_WEBSOCKET_PREFIX);
|
|
23045
|
-
}
|
|
23046
|
-
function isPathOrQuery(path2, basePath) {
|
|
23047
|
-
return path2 === basePath || path2.startsWith(`${basePath}?`);
|
|
23048
|
-
}
|
|
23049
|
-
function isActorHttpRequestPath(path2) {
|
|
23050
|
-
const stripped = path2.slice("/request".length);
|
|
23051
|
-
return path2.startsWith("/request") && (stripped.length === 0 || stripped.startsWith("/") || stripped.startsWith("?"));
|
|
23052
|
-
}
|
|
23053
|
-
function directActorIdFromTarget(target) {
|
|
23054
|
-
if ("directId" in target) {
|
|
23055
|
-
return target.directId;
|
|
23056
|
-
}
|
|
23057
|
-
if ("getForId" in target) {
|
|
23058
|
-
return target.getForId.actorId;
|
|
23059
|
-
}
|
|
23060
|
-
return void 0;
|
|
23061
|
-
}
|
|
23062
|
-
function requestPath(req) {
|
|
23063
|
-
const url2 = new URL(req.url);
|
|
23064
|
-
return `${url2.pathname}${url2.search}`;
|
|
23065
|
-
}
|
|
23066
|
-
function apiActorToOutput(actor2) {
|
|
23067
|
-
return {
|
|
23068
|
-
actorId: actor2.actor_id,
|
|
23069
|
-
name: actor2.name,
|
|
23070
|
-
key: deserializeActorKey(actor2.key),
|
|
23071
|
-
createTs: actor2.create_ts,
|
|
23072
|
-
startTs: actor2.start_ts ?? null,
|
|
23073
|
-
connectableTs: actor2.connectable_ts ?? null,
|
|
23074
|
-
sleepTs: actor2.sleep_ts ?? null,
|
|
23075
|
-
destroyTs: actor2.destroy_ts ?? null,
|
|
23076
|
-
error: actor2.error ?? void 0
|
|
23077
|
-
};
|
|
23078
|
-
}
|
|
23079
|
-
|
|
23080
|
-
// ../rivetkit/dist/tsup/chunk-QQ454DVR.js
|
|
23081
|
-
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
23082
|
-
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
23083
|
-
function registerNativeStateTransactionOpener(provider, opener) {
|
|
23084
|
-
nativeStateTransactionOpeners.set(provider, opener);
|
|
23085
|
-
return provider;
|
|
23086
|
-
}
|
|
23087
|
-
function bindNativeStateTransactionContext(client, context2) {
|
|
23088
|
-
if ((typeof client !== "object" || client === null) && typeof client !== "function") {
|
|
23089
|
-
return client;
|
|
23090
|
-
}
|
|
23091
|
-
const bind = nativeStateTransactionClientBinders.get(client);
|
|
23092
|
-
return (bind == null ? void 0 : bind(context2)) ?? client;
|
|
23093
|
-
}
|
|
23094
|
-
function hasMultipleStatements(query) {
|
|
23095
|
-
const trimmed = query.trim().replace(/;+$/, "").trimEnd();
|
|
23096
|
-
return trimmed.includes(";");
|
|
23097
|
-
}
|
|
23098
|
-
function db({
|
|
23099
|
-
onMigrate,
|
|
23100
|
-
warnOnManualTransactions = true,
|
|
23101
|
-
profiling
|
|
23102
|
-
} = {}) {
|
|
23103
|
-
const provider = {
|
|
23104
|
-
sqliteProfiling: profiling,
|
|
23105
|
-
createClient: async (ctx) => {
|
|
23106
|
-
const nativeDatabaseProvider = ctx.nativeDatabaseProvider;
|
|
23107
|
-
if (!nativeDatabaseProvider) {
|
|
23108
|
-
throw new Error(
|
|
23109
|
-
"native SQLite is required, but the current runtime did not provide a native database provider"
|
|
23110
|
-
);
|
|
23111
|
-
}
|
|
23112
|
-
const db2 = await nativeDatabaseProvider.open(ctx.actorId);
|
|
23113
|
-
let closed = false;
|
|
23114
|
-
let manualTransactionWarned = false;
|
|
23115
|
-
const ensureOpen = () => {
|
|
23116
|
-
if (closed) {
|
|
23117
|
-
throw new Error(
|
|
23118
|
-
"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."
|
|
23119
|
-
);
|
|
23120
|
-
}
|
|
23121
|
-
};
|
|
23122
|
-
const createClient = (target, transactionScoped = false, stateTransactionContext) => {
|
|
23123
|
-
const client2 = {
|
|
23124
|
-
execute: async (query, ...args) => {
|
|
23125
|
-
var _a2, _b, _c, _d;
|
|
23126
|
-
ensureOpen();
|
|
23127
|
-
if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
|
|
23128
|
-
manualTransactionWarned = true;
|
|
23129
|
-
getLogger("database").warn(
|
|
23130
|
-
{ actorId: ctx.actorId },
|
|
23131
|
-
"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."
|
|
23132
|
-
);
|
|
23133
|
-
}
|
|
23134
|
-
const kvReadsBefore = ((_a2 = ctx.metrics) == null ? void 0 : _a2.totalKvReads) ?? 0;
|
|
23135
|
-
const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
|
|
23136
|
-
const start = performance.now();
|
|
23137
|
-
try {
|
|
23138
|
-
if (args.length > 0) {
|
|
23139
|
-
const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
|
|
23140
|
-
const { rows, columns } = await target.execute(
|
|
23141
|
-
query,
|
|
23142
|
-
bindings
|
|
23143
|
-
);
|
|
23144
|
-
return rows.map(
|
|
23145
|
-
(row) => rowToObject(row, columns)
|
|
23146
|
-
);
|
|
23147
|
-
}
|
|
23148
|
-
if (!hasMultipleStatements(query)) {
|
|
23149
|
-
const { rows, columns } = await target.execute(
|
|
23150
|
-
query,
|
|
23151
|
-
void 0
|
|
23152
|
-
);
|
|
23153
|
-
return rows.map(
|
|
23154
|
-
(row) => rowToObject(row, columns)
|
|
23155
|
-
);
|
|
23156
|
-
}
|
|
23157
|
-
return await execMultiStatement(
|
|
23158
|
-
target,
|
|
23159
|
-
query
|
|
23160
|
-
);
|
|
23161
|
-
} finally {
|
|
23162
|
-
const durationMs = performance.now() - start;
|
|
23163
|
-
(_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
|
|
23164
|
-
if (ctx.metrics) {
|
|
23165
|
-
const kvReads = ctx.metrics.totalKvReads - kvReadsBefore;
|
|
23166
|
-
const kvWrites = ctx.metrics.totalKvWrites - kvWritesBefore;
|
|
23167
|
-
(_d = ctx.log) == null ? void 0 : _d.debug({
|
|
23168
|
-
msg: "sql query",
|
|
23169
|
-
query: query.slice(0, 120),
|
|
23170
|
-
durationMs,
|
|
23171
|
-
kvReads,
|
|
23172
|
-
kvWrites
|
|
23173
|
-
});
|
|
23174
|
-
}
|
|
23175
|
-
}
|
|
23176
|
-
},
|
|
23177
|
-
transaction: async (callback, options) => {
|
|
23178
|
-
var _a2, _b;
|
|
23179
|
-
validateTransactionTimeout(options == null ? void 0 : options.timeout);
|
|
23180
|
-
validateTransactionName(options == null ? void 0 : options.name);
|
|
23181
|
-
if (transactionScoped && ((_a2 = options == null ? void 0 : options.experimental) == null ? void 0 : _a2.includeState)) {
|
|
23182
|
-
throw new Error(
|
|
23183
|
-
"experimental.includeState is not supported for nested transactions"
|
|
23184
|
-
);
|
|
23185
|
-
}
|
|
23186
|
-
const includeState = ((_b = options == null ? void 0 : options.experimental) == null ? void 0 : _b.includeState) === true;
|
|
23187
|
-
const stateScope = includeState && stateTransactionContext ? await stateTransactionContext.enter() : void 0;
|
|
23188
|
-
try {
|
|
23189
|
-
const transaction = includeState ? await (() => {
|
|
23190
|
-
const beginStateTransaction = ctx.nativeDatabaseProvider && nativeStateTransactionOpeners.get(
|
|
23191
|
-
ctx.nativeDatabaseProvider
|
|
23192
|
-
);
|
|
23193
|
-
if (!beginStateTransaction) {
|
|
23194
|
-
throw new Error(
|
|
23195
|
-
"experimental.includeState is only supported by RivetKit's embedded database provider"
|
|
23196
|
-
);
|
|
23197
|
-
}
|
|
23198
|
-
return beginStateTransaction(
|
|
23199
|
-
options == null ? void 0 : options.timeout,
|
|
23200
|
-
stateScope
|
|
23201
|
-
);
|
|
23202
|
-
})() : await db2.beginTransaction(
|
|
23203
|
-
options == null ? void 0 : options.timeout,
|
|
23204
|
-
options == null ? void 0 : options.name
|
|
23205
|
-
);
|
|
23206
|
-
const tx = createClient(transaction, true);
|
|
23207
|
-
try {
|
|
23208
|
-
const result = await callback(tx);
|
|
23209
|
-
await transaction.commit();
|
|
23210
|
-
return result;
|
|
23211
|
-
} catch (error46) {
|
|
23212
|
-
try {
|
|
23213
|
-
await transaction.rollback();
|
|
23214
|
-
} catch {
|
|
23215
|
-
}
|
|
23216
|
-
throw error46;
|
|
23217
|
-
}
|
|
23218
|
-
} finally {
|
|
23219
|
-
if (stateScope !== void 0) {
|
|
23220
|
-
stateTransactionContext == null ? void 0 : stateTransactionContext.exit(stateScope);
|
|
23221
|
-
}
|
|
23222
|
-
}
|
|
23223
|
-
},
|
|
23224
|
-
close: async () => {
|
|
23225
|
-
if (!closed) {
|
|
23226
|
-
closed = true;
|
|
23227
|
-
await db2.close();
|
|
23228
|
-
}
|
|
23229
|
-
},
|
|
23230
|
-
nativeMetrics: () => {
|
|
23231
|
-
var _a2;
|
|
23232
|
-
return ((_a2 = db2.nativeMetrics) == null ? void 0 : _a2.call(db2)) ?? null;
|
|
23233
|
-
}
|
|
23234
|
-
};
|
|
23235
|
-
if (!transactionScoped) {
|
|
23236
|
-
nativeStateTransactionClientBinders.set(
|
|
23237
|
-
client2,
|
|
23238
|
-
(context2) => createClient(target, false, context2)
|
|
23239
|
-
);
|
|
23240
|
-
}
|
|
23241
|
-
return client2;
|
|
23242
|
-
};
|
|
23243
|
-
const client = createClient(db2);
|
|
23244
|
-
return client;
|
|
23245
|
-
},
|
|
23246
|
-
onMigrate: async (client) => {
|
|
23247
|
-
if (onMigrate) {
|
|
23248
|
-
await withMigrationSavepoint(
|
|
23249
|
-
client,
|
|
23250
|
-
(leased) => onMigrate(leased)
|
|
23251
|
-
);
|
|
23252
|
-
}
|
|
23244
|
+
}
|
|
23245
|
+
#buildGatewayUrlForTarget(config3, target, path2, options = {}) {
|
|
23246
|
+
const endpoint = getEndpoint(config3);
|
|
23247
|
+
if (shouldSkipReadyWait(options) && directActorIdFromTarget(target) && canUseDirectSkipReadyWaitPath(path2)) {
|
|
23248
|
+
return combineUrlPath(endpoint, path2);
|
|
23253
23249
|
}
|
|
23254
|
-
|
|
23255
|
-
|
|
23250
|
+
if ("directId" in target) {
|
|
23251
|
+
return buildActorGatewayUrl(
|
|
23252
|
+
endpoint,
|
|
23253
|
+
target.directId,
|
|
23254
|
+
config3.token,
|
|
23255
|
+
path2
|
|
23256
|
+
);
|
|
23257
|
+
}
|
|
23258
|
+
if ("getForId" in target) {
|
|
23259
|
+
return buildActorGatewayUrl(
|
|
23260
|
+
endpoint,
|
|
23261
|
+
target.getForId.actorId,
|
|
23262
|
+
config3.token,
|
|
23263
|
+
path2
|
|
23264
|
+
);
|
|
23265
|
+
}
|
|
23266
|
+
if ("getForKey" in target || "getOrCreateForKey" in target) {
|
|
23267
|
+
return buildActorQueryGatewayUrl(
|
|
23268
|
+
endpoint,
|
|
23269
|
+
config3.namespace,
|
|
23270
|
+
target,
|
|
23271
|
+
config3.token,
|
|
23272
|
+
path2,
|
|
23273
|
+
config3.maxInputSize,
|
|
23274
|
+
void 0,
|
|
23275
|
+
"getOrCreateForKey" in target ? target.getOrCreateForKey.poolName ?? config3.poolName : void 0,
|
|
23276
|
+
options
|
|
23277
|
+
);
|
|
23278
|
+
}
|
|
23279
|
+
if ("create" in target) {
|
|
23280
|
+
throw new Error(
|
|
23281
|
+
"Gateway URLs only support direct actor IDs, get, and getOrCreate targets."
|
|
23282
|
+
);
|
|
23283
|
+
}
|
|
23284
|
+
throw new Error("unreachable: unknown gateway target type");
|
|
23285
|
+
}
|
|
23286
|
+
};
|
|
23287
|
+
function canUseDirectSkipReadyWaitPath(path2) {
|
|
23288
|
+
return isActorHttpRequestPath(path2) || isPathOrQuery(path2, PATH_CONNECT) || isPathOrQuery(path2, PATH_WEBSOCKET_BASE) || path2.startsWith(PATH_WEBSOCKET_PREFIX);
|
|
23256
23289
|
}
|
|
23257
|
-
function
|
|
23258
|
-
|
|
23259
|
-
|
|
23260
|
-
|
|
23290
|
+
function isPathOrQuery(path2, basePath) {
|
|
23291
|
+
return path2 === basePath || path2.startsWith(`${basePath}?`);
|
|
23292
|
+
}
|
|
23293
|
+
function isActorHttpRequestPath(path2) {
|
|
23294
|
+
const stripped = path2.slice("/request".length);
|
|
23295
|
+
return path2.startsWith("/request") && (stripped.length === 0 || stripped.startsWith("/") || stripped.startsWith("?"));
|
|
23296
|
+
}
|
|
23297
|
+
function directActorIdFromTarget(target) {
|
|
23298
|
+
if ("directId" in target) {
|
|
23299
|
+
return target.directId;
|
|
23261
23300
|
}
|
|
23262
|
-
|
|
23301
|
+
if ("getForId" in target) {
|
|
23302
|
+
return target.getForId.actorId;
|
|
23303
|
+
}
|
|
23304
|
+
return void 0;
|
|
23263
23305
|
}
|
|
23264
|
-
|
|
23265
|
-
const
|
|
23266
|
-
|
|
23267
|
-
await db2.exec(query, (row, columns) => {
|
|
23268
|
-
if (!columnNames) {
|
|
23269
|
-
columnNames = columns;
|
|
23270
|
-
}
|
|
23271
|
-
results.push(rowToObject(row, columnNames));
|
|
23272
|
-
});
|
|
23273
|
-
return results;
|
|
23306
|
+
function requestPath(req) {
|
|
23307
|
+
const url2 = new URL(req.url);
|
|
23308
|
+
return `${url2.pathname}${url2.search}`;
|
|
23274
23309
|
}
|
|
23275
|
-
|
|
23276
|
-
return
|
|
23277
|
-
|
|
23278
|
-
|
|
23279
|
-
|
|
23280
|
-
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
await transaction.execute(
|
|
23288
|
-
"ROLLBACK TO SAVEPOINT __rivet_on_migrate"
|
|
23289
|
-
);
|
|
23290
|
-
} finally {
|
|
23291
|
-
await transaction.execute(
|
|
23292
|
-
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
23293
|
-
);
|
|
23294
|
-
}
|
|
23295
|
-
throw error46;
|
|
23296
|
-
}
|
|
23297
|
-
},
|
|
23298
|
-
{
|
|
23299
|
-
name: "rivetkit-migration",
|
|
23300
|
-
timeout: MIGRATION_TRANSACTION_TIMEOUT_MS
|
|
23301
|
-
}
|
|
23302
|
-
);
|
|
23310
|
+
function apiActorToOutput(actor2) {
|
|
23311
|
+
return {
|
|
23312
|
+
actorId: actor2.actor_id,
|
|
23313
|
+
name: actor2.name,
|
|
23314
|
+
key: deserializeActorKey(actor2.key),
|
|
23315
|
+
createTs: actor2.create_ts,
|
|
23316
|
+
startTs: actor2.start_ts ?? null,
|
|
23317
|
+
connectableTs: actor2.connectable_ts ?? null,
|
|
23318
|
+
sleepTs: actor2.sleep_ts ?? null,
|
|
23319
|
+
destroyTs: actor2.destroy_ts ?? null,
|
|
23320
|
+
error: actor2.error ?? void 0
|
|
23321
|
+
};
|
|
23303
23322
|
}
|
|
23304
23323
|
|
|
23305
23324
|
// ../../../shared/typescript/virtual-websocket/dist/mod.js
|
|
@@ -26136,12 +26155,6 @@ var NapiCoreRuntime = class {
|
|
|
26136
26155
|
actorId(ctx) {
|
|
26137
26156
|
return asNativeActorContext(ctx).actorId();
|
|
26138
26157
|
}
|
|
26139
|
-
actorGeneration(ctx) {
|
|
26140
|
-
return asNativeActorContext(ctx).generation() ?? void 0;
|
|
26141
|
-
}
|
|
26142
|
-
actorIsLost(ctx) {
|
|
26143
|
-
return asNativeActorContext(ctx).isLost();
|
|
26144
|
-
}
|
|
26145
26158
|
runWithActorInvocationContext(ctx, run) {
|
|
26146
26159
|
return this.#runAs(asNativeActorContext(ctx), run);
|
|
26147
26160
|
}
|
|
@@ -26755,27 +26768,6 @@ function notifyStateChanged(state) {
|
|
|
26755
26768
|
waiter();
|
|
26756
26769
|
}
|
|
26757
26770
|
}
|
|
26758
|
-
function createRunState(actorGeneration) {
|
|
26759
|
-
return {
|
|
26760
|
-
actorGeneration,
|
|
26761
|
-
active: false,
|
|
26762
|
-
closed: false,
|
|
26763
|
-
exclusive: false,
|
|
26764
|
-
exclusiveGeneration: 0,
|
|
26765
|
-
inspectorInitialized: false,
|
|
26766
|
-
queued: 0,
|
|
26767
|
-
waiters: /* @__PURE__ */ new Set()
|
|
26768
|
-
};
|
|
26769
|
-
}
|
|
26770
|
-
function closeRunState(state, disposeInspector = true) {
|
|
26771
|
-
var _a2, _b;
|
|
26772
|
-
state.closed = true;
|
|
26773
|
-
if (disposeInspector) {
|
|
26774
|
-
(_b = (_a2 = state.inspector) == null ? void 0 : _a2.dispose) == null ? void 0 : _b.call(_a2);
|
|
26775
|
-
}
|
|
26776
|
-
state.inspector = void 0;
|
|
26777
|
-
notifyStateChanged(state);
|
|
26778
|
-
}
|
|
26779
26771
|
function waitForStateChange(state) {
|
|
26780
26772
|
return new Promise((resolve) => {
|
|
26781
26773
|
state.waiters.add(resolve);
|
|
@@ -26790,11 +26782,8 @@ var RunHandlerCoordinator = class {
|
|
|
26790
26782
|
get inspectorKind() {
|
|
26791
26783
|
return getRunInspectorKind(this.#run);
|
|
26792
26784
|
}
|
|
26793
|
-
async run(actorId, restart, callback
|
|
26794
|
-
const state = this.#getOrCreate(actorId
|
|
26795
|
-
if (state.closed) {
|
|
26796
|
-
return "closed";
|
|
26797
|
-
}
|
|
26785
|
+
async run(actorId, restart, callback) {
|
|
26786
|
+
const state = this.#getOrCreate(actorId);
|
|
26798
26787
|
state.restart = restart;
|
|
26799
26788
|
this.#initializeInspector(actorId, state);
|
|
26800
26789
|
state.queued += 1;
|
|
@@ -26821,27 +26810,21 @@ var RunHandlerCoordinator = class {
|
|
|
26821
26810
|
notifyStateChanged(state);
|
|
26822
26811
|
}
|
|
26823
26812
|
}
|
|
26824
|
-
getInspector(actorId, restart
|
|
26813
|
+
getInspector(actorId, restart) {
|
|
26825
26814
|
var _a2;
|
|
26826
|
-
const state = this.#getOrCreate(actorId
|
|
26827
|
-
if (state.closed) {
|
|
26828
|
-
return void 0;
|
|
26829
|
-
}
|
|
26815
|
+
const state = this.#getOrCreate(actorId);
|
|
26830
26816
|
state.restart = restart;
|
|
26831
26817
|
this.#initializeInspector(actorId, state);
|
|
26832
26818
|
return (_a2 = state.inspector) == null ? void 0 : _a2.inspector;
|
|
26833
26819
|
}
|
|
26834
|
-
|
|
26835
|
-
|
|
26836
|
-
* generation is closed, so an older generation's late cleanup cannot close a newer one.
|
|
26837
|
-
*/
|
|
26838
|
-
destroy(actorId, actorGeneration, options = {}) {
|
|
26820
|
+
destroy(actorId) {
|
|
26821
|
+
var _a2, _b;
|
|
26839
26822
|
const state = this.#states.get(actorId);
|
|
26840
26823
|
if (!state) return;
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
|
|
26824
|
+
state.closed = true;
|
|
26825
|
+
(_b = (_a2 = state.inspector) == null ? void 0 : _a2.dispose) == null ? void 0 : _b.call(_a2);
|
|
26826
|
+
state.inspector = void 0;
|
|
26827
|
+
notifyStateChanged(state);
|
|
26845
26828
|
this.#states.delete(actorId);
|
|
26846
26829
|
}
|
|
26847
26830
|
#control(actorId, state) {
|
|
@@ -26887,20 +26870,18 @@ var RunHandlerCoordinator = class {
|
|
|
26887
26870
|
}
|
|
26888
26871
|
};
|
|
26889
26872
|
}
|
|
26890
|
-
#getOrCreate(actorId
|
|
26873
|
+
#getOrCreate(actorId) {
|
|
26891
26874
|
let state = this.#states.get(actorId);
|
|
26892
|
-
if (state && actorGeneration !== void 0 && state.actorGeneration !== void 0 && state.actorGeneration !== actorGeneration) {
|
|
26893
|
-
if (actorGeneration < state.actorGeneration) {
|
|
26894
|
-
const detached = createRunState(actorGeneration);
|
|
26895
|
-
detached.closed = true;
|
|
26896
|
-
return detached;
|
|
26897
|
-
}
|
|
26898
|
-
closeRunState(state, false);
|
|
26899
|
-
this.#states.delete(actorId);
|
|
26900
|
-
state = void 0;
|
|
26901
|
-
}
|
|
26902
26875
|
if (!state) {
|
|
26903
|
-
state =
|
|
26876
|
+
state = {
|
|
26877
|
+
active: false,
|
|
26878
|
+
closed: false,
|
|
26879
|
+
exclusive: false,
|
|
26880
|
+
exclusiveGeneration: 0,
|
|
26881
|
+
inspectorInitialized: false,
|
|
26882
|
+
queued: 0,
|
|
26883
|
+
waiters: /* @__PURE__ */ new Set()
|
|
26884
|
+
};
|
|
26904
26885
|
this.#states.set(actorId, state);
|
|
26905
26886
|
}
|
|
26906
26887
|
return state;
|
|
@@ -26909,7 +26890,6 @@ var RunHandlerCoordinator = class {
|
|
|
26909
26890
|
if (state.inspectorInitialized) return;
|
|
26910
26891
|
const inspector = createRunInspector(this.#run, {
|
|
26911
26892
|
actorId,
|
|
26912
|
-
actorGeneration: state.actorGeneration,
|
|
26913
26893
|
control: this.#control(actorId, state)
|
|
26914
26894
|
});
|
|
26915
26895
|
if (this.inspectorKind === "workflow") {
|
|
@@ -27235,12 +27215,6 @@ var WasmCoreRuntime = class {
|
|
|
27235
27215
|
actorId(ctx) {
|
|
27236
27216
|
return callHandle(asWasmActorContext(ctx), "actorId");
|
|
27237
27217
|
}
|
|
27238
|
-
actorGeneration(ctx) {
|
|
27239
|
-
return callHandle(asWasmActorContext(ctx), "generation") ?? void 0;
|
|
27240
|
-
}
|
|
27241
|
-
actorIsLost(ctx) {
|
|
27242
|
-
return callHandle(asWasmActorContext(ctx), "isLost");
|
|
27243
|
-
}
|
|
27244
27218
|
runWithActorInvocationContext(_ctx, run) {
|
|
27245
27219
|
return run();
|
|
27246
27220
|
}
|
|
@@ -28067,11 +28041,8 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
|
|
|
28067
28041
|
await closeNativeDatabaseClient(runtime, ctx);
|
|
28068
28042
|
await closeNativeSqlDatabase(runtime, ctx);
|
|
28069
28043
|
void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
|
|
28070
|
-
|
|
28071
|
-
|
|
28072
|
-
} finally {
|
|
28073
|
-
clearNativeRuntimeState(runtime, ctx);
|
|
28074
|
-
}
|
|
28044
|
+
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
28045
|
+
clearNativeRuntimeState(runtime, ctx);
|
|
28075
28046
|
}).catch((error46) => {
|
|
28076
28047
|
logger22().warn({
|
|
28077
28048
|
msg: "deferred native sleep cleanup failed",
|
|
@@ -28080,24 +28051,10 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
|
|
|
28080
28051
|
});
|
|
28081
28052
|
return;
|
|
28082
28053
|
}
|
|
28083
|
-
|
|
28084
|
-
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
28085
|
-
} finally {
|
|
28086
|
-
try {
|
|
28087
|
-
await closeNativeDatabaseClient(runtime, ctx);
|
|
28088
|
-
await closeNativeSqlDatabase(runtime, ctx);
|
|
28089
|
-
} finally {
|
|
28090
|
-
clearNativeRuntimeState(runtime, ctx);
|
|
28091
|
-
}
|
|
28092
|
-
}
|
|
28093
|
-
}
|
|
28094
|
-
async function cleanupNativeLostRuntimeState(runtime, ctx) {
|
|
28054
|
+
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
28095
28055
|
await closeNativeDatabaseClient(runtime, ctx);
|
|
28096
|
-
|
|
28097
|
-
|
|
28098
|
-
} finally {
|
|
28099
|
-
clearNativeRuntimeState(runtime, ctx);
|
|
28100
|
-
}
|
|
28056
|
+
await closeNativeSqlDatabase(runtime, ctx);
|
|
28057
|
+
clearNativeRuntimeState(runtime, ctx);
|
|
28101
28058
|
}
|
|
28102
28059
|
function closeNativeSqlDatabase(runtime, ctx) {
|
|
28103
28060
|
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
@@ -28115,9 +28072,6 @@ async function closeNativeDatabaseClient(runtime, ctx) {
|
|
|
28115
28072
|
return;
|
|
28116
28073
|
}
|
|
28117
28074
|
runtimeState.databaseClient = void 0;
|
|
28118
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
28119
|
-
return;
|
|
28120
|
-
}
|
|
28121
28075
|
if (entry.client && typeof entry.client === "object" && "close" in entry.client && typeof entry.client.close === "function") {
|
|
28122
28076
|
await entry.client.close();
|
|
28123
28077
|
}
|
|
@@ -28543,49 +28497,6 @@ function wrapNativeCallback(callback) {
|
|
|
28543
28497
|
}
|
|
28544
28498
|
};
|
|
28545
28499
|
}
|
|
28546
|
-
var LOST_GENERATION_CLEANUP_CALLBACKS = /* @__PURE__ */ new Set(["onSleep", "onDestroy"]);
|
|
28547
|
-
function throwIfActorLost(runtime, ctx) {
|
|
28548
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
28549
|
-
throw actorGenerationLostError();
|
|
28550
|
-
}
|
|
28551
|
-
}
|
|
28552
|
-
function actorGenerationLostError() {
|
|
28553
|
-
return new RivetError(
|
|
28554
|
-
"actor",
|
|
28555
|
-
"stopping",
|
|
28556
|
-
"Actor generation was declared lost; it starts no new user callbacks."
|
|
28557
|
-
);
|
|
28558
|
-
}
|
|
28559
|
-
function refuseCallbacksAfterLost(runtime, callbacks) {
|
|
28560
|
-
const guard = (callback) => {
|
|
28561
|
-
return async (...args) => {
|
|
28562
|
-
var _a2;
|
|
28563
|
-
const ctx = (_a2 = args[1]) == null ? void 0 : _a2.ctx;
|
|
28564
|
-
if (ctx !== void 0 && callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
28565
|
-
throw encodeNativeCallbackError(actorGenerationLostError());
|
|
28566
|
-
}
|
|
28567
|
-
return await callback(...args);
|
|
28568
|
-
};
|
|
28569
|
-
};
|
|
28570
|
-
const guarded = {};
|
|
28571
|
-
for (const [name, value] of Object.entries(callbacks)) {
|
|
28572
|
-
if (LOST_GENERATION_CLEANUP_CALLBACKS.has(name)) {
|
|
28573
|
-
guarded[name] = value;
|
|
28574
|
-
} else if (typeof value === "function") {
|
|
28575
|
-
guarded[name] = guard(value);
|
|
28576
|
-
} else if (name === "actions" && value !== null && typeof value === "object") {
|
|
28577
|
-
guarded[name] = Object.fromEntries(
|
|
28578
|
-
Object.entries(value).map(([actionName, handler]) => [
|
|
28579
|
-
actionName,
|
|
28580
|
-
guard(handler)
|
|
28581
|
-
])
|
|
28582
|
-
);
|
|
28583
|
-
} else {
|
|
28584
|
-
guarded[name] = value;
|
|
28585
|
-
}
|
|
28586
|
-
}
|
|
28587
|
-
return guarded;
|
|
28588
|
-
}
|
|
28589
28500
|
function decodeArgs(value) {
|
|
28590
28501
|
const decoded = decodeValue(value);
|
|
28591
28502
|
return normalizeArgs(decoded);
|
|
@@ -29023,30 +28934,17 @@ var NativeQueueAdapter = class {
|
|
|
29023
28934
|
this.#ctx = ctx;
|
|
29024
28935
|
this.#schemas = schemas;
|
|
29025
28936
|
}
|
|
29026
|
-
// Queue results arrive after awaits, and their schema validation is user code, so each
|
|
29027
|
-
// validation checks that the generation was not lost first.
|
|
29028
|
-
#validateBody(name, body) {
|
|
29029
|
-
throwIfActorLost(this.#runtime, this.#ctx);
|
|
29030
|
-
return validateQueueBody(this.#schemas, name, body);
|
|
29031
|
-
}
|
|
29032
|
-
#validateComplete(name, response) {
|
|
29033
|
-
throwIfActorLost(this.#runtime, this.#ctx);
|
|
29034
|
-
return validateQueueComplete(this.#schemas, name, response);
|
|
29035
|
-
}
|
|
29036
|
-
#wrap(message) {
|
|
29037
|
-
throwIfActorLost(this.#runtime, this.#ctx);
|
|
29038
|
-
return wrapQueueMessage(message, this.#schemas);
|
|
29039
|
-
}
|
|
29040
28937
|
async send(name, body) {
|
|
29041
|
-
const validatedBody = this.#
|
|
29042
|
-
return
|
|
28938
|
+
const validatedBody = validateQueueBody(this.#schemas, name, body);
|
|
28939
|
+
return wrapQueueMessage(
|
|
29043
28940
|
await callNative(
|
|
29044
28941
|
() => this.#runtime.actorQueueSend(
|
|
29045
28942
|
this.#ctx,
|
|
29046
28943
|
name,
|
|
29047
28944
|
encodeValue(validatedBody)
|
|
29048
28945
|
)
|
|
29049
|
-
)
|
|
28946
|
+
),
|
|
28947
|
+
this.#schemas
|
|
29050
28948
|
);
|
|
29051
28949
|
}
|
|
29052
28950
|
async next(options) {
|
|
@@ -29089,7 +28987,9 @@ var NativeQueueAdapter = class {
|
|
|
29089
28987
|
token
|
|
29090
28988
|
)
|
|
29091
28989
|
);
|
|
29092
|
-
const wrapped = messages.map(
|
|
28990
|
+
const wrapped = messages.map(
|
|
28991
|
+
(message) => wrapQueueMessage(message, this.#schemas)
|
|
28992
|
+
);
|
|
29093
28993
|
return completable ? wrapped.map(
|
|
29094
28994
|
(message) => this.#makeCompletableMessage(message)
|
|
29095
28995
|
) : wrapped;
|
|
@@ -29103,7 +29003,7 @@ var NativeQueueAdapter = class {
|
|
|
29103
29003
|
options == null ? void 0 : options.signal
|
|
29104
29004
|
);
|
|
29105
29005
|
try {
|
|
29106
|
-
return
|
|
29006
|
+
return wrapQueueMessage(
|
|
29107
29007
|
await callNative(
|
|
29108
29008
|
() => this.#runtime.actorQueueWaitForNames(
|
|
29109
29009
|
this.#ctx,
|
|
@@ -29114,7 +29014,8 @@ var NativeQueueAdapter = class {
|
|
|
29114
29014
|
},
|
|
29115
29015
|
token
|
|
29116
29016
|
)
|
|
29117
|
-
)
|
|
29017
|
+
),
|
|
29018
|
+
this.#schemas
|
|
29118
29019
|
);
|
|
29119
29020
|
} finally {
|
|
29120
29021
|
cleanup == null ? void 0 : cleanup();
|
|
@@ -29144,7 +29045,8 @@ var NativeQueueAdapter = class {
|
|
|
29144
29045
|
await this.waitForNamesAvailable(names ?? [], options);
|
|
29145
29046
|
}
|
|
29146
29047
|
async complete(message, response) {
|
|
29147
|
-
const validatedResponse =
|
|
29048
|
+
const validatedResponse = validateQueueComplete(
|
|
29049
|
+
this.#schemas,
|
|
29148
29050
|
message.name,
|
|
29149
29051
|
response
|
|
29150
29052
|
);
|
|
@@ -29159,7 +29061,7 @@ var NativeQueueAdapter = class {
|
|
|
29159
29061
|
this.#pendingCompletableMessageIds.delete(message.id.toString());
|
|
29160
29062
|
}
|
|
29161
29063
|
async enqueueAndWait(name, body, options) {
|
|
29162
|
-
const validatedBody = this.#
|
|
29064
|
+
const validatedBody = validateQueueBody(this.#schemas, name, body);
|
|
29163
29065
|
const { token, cleanup } = await createCancellationTokenHandle(
|
|
29164
29066
|
this.#runtime,
|
|
29165
29067
|
options == null ? void 0 : options.signal
|
|
@@ -29176,7 +29078,11 @@ var NativeQueueAdapter = class {
|
|
|
29176
29078
|
token
|
|
29177
29079
|
)
|
|
29178
29080
|
);
|
|
29179
|
-
return response === void 0 || response === null ? void 0 :
|
|
29081
|
+
return response === void 0 || response === null ? void 0 : validateQueueComplete(
|
|
29082
|
+
this.#schemas,
|
|
29083
|
+
name,
|
|
29084
|
+
decodeValue(response)
|
|
29085
|
+
);
|
|
29180
29086
|
} finally {
|
|
29181
29087
|
cleanup == null ? void 0 : cleanup();
|
|
29182
29088
|
}
|
|
@@ -29557,9 +29463,6 @@ var TrackedWebSocketHandleAdapter = class {
|
|
|
29557
29463
|
}
|
|
29558
29464
|
}
|
|
29559
29465
|
#callHandler(type, handler, event2) {
|
|
29560
|
-
if ((type === "message" || type === "open") && this.#ctx.isLost) {
|
|
29561
|
-
return;
|
|
29562
|
-
}
|
|
29563
29466
|
try {
|
|
29564
29467
|
const result = handler(event2);
|
|
29565
29468
|
if (!this.#isPromiseLike(result)) {
|
|
@@ -29842,13 +29745,6 @@ var ActorContextHandleAdapter = class {
|
|
|
29842
29745
|
get actorId() {
|
|
29843
29746
|
return callNativeSync(() => this.#runtime.actorId(this.#ctx));
|
|
29844
29747
|
}
|
|
29845
|
-
get actorGeneration() {
|
|
29846
|
-
return callNativeSync(() => this.#runtime.actorGeneration(this.#ctx));
|
|
29847
|
-
}
|
|
29848
|
-
/** Whether this generation was declared lost. A lost generation starts no new user code. */
|
|
29849
|
-
get isLost() {
|
|
29850
|
-
return callNativeSync(() => this.#runtime.actorIsLost(this.#ctx));
|
|
29851
|
-
}
|
|
29852
29748
|
get name() {
|
|
29853
29749
|
return callNativeSync(() => this.#runtime.actorName(this.#ctx));
|
|
29854
29750
|
}
|
|
@@ -29963,9 +29859,6 @@ var ActorContextHandleAdapter = class {
|
|
|
29963
29859
|
return this.#db;
|
|
29964
29860
|
}
|
|
29965
29861
|
const actorId = this.actorId;
|
|
29966
|
-
if (this.isLost) {
|
|
29967
|
-
throw actorGenerationLostError();
|
|
29968
|
-
}
|
|
29969
29862
|
const createdClient = await this.#databaseProvider.createClient({
|
|
29970
29863
|
actorId,
|
|
29971
29864
|
kv: {
|
|
@@ -30118,11 +30011,9 @@ var ActorContextHandleAdapter = class {
|
|
|
30118
30011
|
if (!this.#databaseProvider) {
|
|
30119
30012
|
return;
|
|
30120
30013
|
}
|
|
30121
|
-
|
|
30122
|
-
|
|
30123
|
-
|
|
30124
|
-
}
|
|
30125
|
-
await this.#databaseProvider.onMigrate(client);
|
|
30014
|
+
await this.#databaseProvider.onMigrate(
|
|
30015
|
+
await this.ensureDatabaseClient()
|
|
30016
|
+
);
|
|
30126
30017
|
}
|
|
30127
30018
|
async closeDatabase() {
|
|
30128
30019
|
this.#db = void 0;
|
|
@@ -30394,7 +30285,7 @@ var ActorContextHandleAdapter = class {
|
|
|
30394
30285
|
callNativeSync(
|
|
30395
30286
|
() => this.#runtime.actorRequestSave(this.#ctx, { immediate: false })
|
|
30396
30287
|
);
|
|
30397
|
-
if (!this.#onStateChange
|
|
30288
|
+
if (!this.#onStateChange) {
|
|
30398
30289
|
return;
|
|
30399
30290
|
}
|
|
30400
30291
|
actorState.isInOnStateChange = true;
|
|
@@ -30434,12 +30325,6 @@ var NativeWorkflowRuntimeAdapter = class {
|
|
|
30434
30325
|
#onMessagesReceived;
|
|
30435
30326
|
#completions = /* @__PURE__ */ new Map();
|
|
30436
30327
|
id;
|
|
30437
|
-
/** Actor generation, used to keep workflow registrations of different generations apart. */
|
|
30438
|
-
generation;
|
|
30439
|
-
/** Whether this generation was declared lost. Workflow code checks it before each user callback. */
|
|
30440
|
-
get isLost() {
|
|
30441
|
-
return this.#ctx.isLost;
|
|
30442
|
-
}
|
|
30443
30328
|
driver;
|
|
30444
30329
|
queueManager;
|
|
30445
30330
|
stateManager;
|
|
@@ -30447,7 +30332,6 @@ var NativeWorkflowRuntimeAdapter = class {
|
|
|
30447
30332
|
this.#ctx = ctx;
|
|
30448
30333
|
this.#onMessagesReceived = onMessagesReceived;
|
|
30449
30334
|
this.id = ctx.actorId;
|
|
30450
|
-
this.generation = ctx.actorGeneration;
|
|
30451
30335
|
this.driver = {
|
|
30452
30336
|
kvBatchGet: async (actorId, keys) => {
|
|
30453
30337
|
this.#assertActorId(actorId);
|
|
@@ -30730,23 +30614,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30730
30614
|
const runHandlerCoordinator = getRunInspectorKind(config3.run) === "workflow" ? new RunHandlerCoordinator(config3.run) : void 0;
|
|
30731
30615
|
const getNativeWorkflowInspector = (ctx) => {
|
|
30732
30616
|
var _a22, _b;
|
|
30733
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
30734
|
-
return void 0;
|
|
30735
|
-
}
|
|
30736
30617
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
30737
30618
|
const restart = () => callNativeSync(() => runtime.actorRestartRunHandler(ctx));
|
|
30738
|
-
|
|
30739
|
-
() => runtime.actorGeneration(ctx)
|
|
30740
|
-
);
|
|
30741
|
-
const inspector = ((_a22 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(
|
|
30742
|
-
actorId,
|
|
30743
|
-
restart,
|
|
30744
|
-
actorGeneration
|
|
30745
|
-
)) == null ? void 0 : _a22.workflow) ?? ((_b = getRunInspectorConfig(config3.run, actorId)) == null ? void 0 : _b.workflow);
|
|
30746
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
30747
|
-
return void 0;
|
|
30748
|
-
}
|
|
30749
|
-
return inspector;
|
|
30619
|
+
return ((_a22 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(actorId, restart)) == null ? void 0 : _a22.workflow) ?? ((_b = getRunInspectorConfig(config3.run, actorId)) == null ? void 0 : _b.workflow);
|
|
30750
30620
|
};
|
|
30751
30621
|
const onStateChange = typeof config3.onStateChange === "function" ? (actorCtx, nextState) => {
|
|
30752
30622
|
config3.onStateChange(actorCtx, nextState);
|
|
@@ -30823,10 +30693,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30823
30693
|
return errorResponse(error46, 401);
|
|
30824
30694
|
}
|
|
30825
30695
|
}
|
|
30826
|
-
const inspectorConnParams = (conn) => {
|
|
30827
|
-
throwIfActorLost(runtime, ctx);
|
|
30828
|
-
return conn.params;
|
|
30829
|
-
};
|
|
30830
30696
|
const workflowHistory = () => {
|
|
30831
30697
|
var _a3;
|
|
30832
30698
|
return serializeWorkflowHistoryForJson(
|
|
@@ -30860,7 +30726,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30860
30726
|
id: conn.id,
|
|
30861
30727
|
details: {
|
|
30862
30728
|
type: null,
|
|
30863
|
-
params:
|
|
30729
|
+
params: conn.params,
|
|
30864
30730
|
stateEnabled: true,
|
|
30865
30731
|
state: conn.state,
|
|
30866
30732
|
subscriptions: 0,
|
|
@@ -31064,7 +30930,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31064
30930
|
id: conn.id,
|
|
31065
30931
|
details: {
|
|
31066
30932
|
type: null,
|
|
31067
|
-
params:
|
|
30933
|
+
params: conn.params,
|
|
31068
30934
|
stateEnabled: true,
|
|
31069
30935
|
state: conn.state,
|
|
31070
30936
|
subscriptions: 0,
|
|
@@ -31111,20 +30977,15 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31111
30977
|
);
|
|
31112
30978
|
}
|
|
31113
30979
|
const args = body.properties !== void 0 ? [body.properties] : normalizeArgs(body.args);
|
|
31114
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
31115
|
-
return jsonResponse(
|
|
31116
|
-
{ error: "actor generation was declared lost" },
|
|
31117
|
-
{ status: 503 }
|
|
31118
|
-
);
|
|
31119
|
-
}
|
|
31120
30980
|
try {
|
|
31121
|
-
const
|
|
31122
|
-
|
|
31123
|
-
|
|
31124
|
-
|
|
30981
|
+
const output = await action(
|
|
30982
|
+
actorCtx,
|
|
30983
|
+
...validateActionArgs(
|
|
30984
|
+
schemaConfig.actionInputSchemas,
|
|
30985
|
+
actionName,
|
|
30986
|
+
args
|
|
30987
|
+
)
|
|
31125
30988
|
);
|
|
31126
|
-
throwIfActorLost(runtime, ctx);
|
|
31127
|
-
const output = await action(actorCtx, ...validatedArgs);
|
|
31128
30989
|
return jsonResponse({ output });
|
|
31129
30990
|
} catch (error46) {
|
|
31130
30991
|
logger22().error({
|
|
@@ -31228,9 +31089,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31228
31089
|
await actorCtx.closeDatabase();
|
|
31229
31090
|
}
|
|
31230
31091
|
await actorCtx.runDatabaseMigrations();
|
|
31231
|
-
if (typeof config3.onMigrate === "function"
|
|
31232
|
-
() => runtime.actorIsLost(ctx)
|
|
31233
|
-
)) {
|
|
31092
|
+
if (typeof config3.onMigrate === "function") {
|
|
31234
31093
|
await config3.onMigrate(actorCtx, isNew);
|
|
31235
31094
|
}
|
|
31236
31095
|
} catch (error210) {
|
|
@@ -31273,29 +31132,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31273
31132
|
const { ctx } = unwrapTsfnPayload(error46, payload);
|
|
31274
31133
|
const actorCtx = makeActorCtx(ctx);
|
|
31275
31134
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
31276
|
-
const actorGeneration = callNativeSync(
|
|
31277
|
-
() => runtime.actorGeneration(ctx)
|
|
31278
|
-
);
|
|
31279
|
-
const isLost = () => callNativeSync(() => runtime.actorIsLost(ctx));
|
|
31280
|
-
if (isLost()) {
|
|
31281
|
-
try {
|
|
31282
|
-
await cleanupNativeLostRuntimeState(runtime, ctx);
|
|
31283
|
-
} finally {
|
|
31284
|
-
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
|
|
31285
|
-
actorId,
|
|
31286
|
-
actorGeneration,
|
|
31287
|
-
{
|
|
31288
|
-
disposeInspector: false
|
|
31289
|
-
}
|
|
31290
|
-
);
|
|
31291
|
-
await actorCtx.dispose();
|
|
31292
|
-
}
|
|
31293
|
-
return;
|
|
31294
|
-
}
|
|
31295
31135
|
const saveActorState = async () => {
|
|
31296
|
-
if (isLost()) {
|
|
31297
|
-
return;
|
|
31298
|
-
}
|
|
31299
31136
|
if (runtime.kind === "wasm") {
|
|
31300
31137
|
await runtime.actorSaveState(
|
|
31301
31138
|
ctx,
|
|
@@ -31314,26 +31151,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31314
31151
|
await saveActorState();
|
|
31315
31152
|
} finally {
|
|
31316
31153
|
try {
|
|
31317
|
-
|
|
31318
|
-
|
|
31319
|
-
|
|
31320
|
-
|
|
31321
|
-
runtime,
|
|
31322
|
-
ctx,
|
|
31323
|
-
saveActorState
|
|
31324
|
-
);
|
|
31325
|
-
}
|
|
31326
|
-
} finally {
|
|
31327
|
-
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
|
|
31328
|
-
actorId,
|
|
31329
|
-
actorGeneration,
|
|
31330
|
-
{
|
|
31331
|
-
disposeInspector: !isLost()
|
|
31332
|
-
}
|
|
31154
|
+
await cleanupNativeSleepRuntimeState(
|
|
31155
|
+
runtime,
|
|
31156
|
+
ctx,
|
|
31157
|
+
saveActorState
|
|
31333
31158
|
);
|
|
31334
|
-
|
|
31335
|
-
|
|
31336
|
-
|
|
31159
|
+
} finally {
|
|
31160
|
+
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(actorId);
|
|
31161
|
+
disposeRunInspector(config3.run, actorId);
|
|
31337
31162
|
await actorCtx.dispose();
|
|
31338
31163
|
}
|
|
31339
31164
|
}
|
|
@@ -31344,17 +31169,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31344
31169
|
const { ctx } = unwrapTsfnPayload(error46, payload);
|
|
31345
31170
|
const actorCtx = makeActorCtx(ctx);
|
|
31346
31171
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
31347
|
-
|
|
31348
|
-
|
|
31349
|
-
actorId,
|
|
31350
|
-
callNativeSync(() => runtime.actorGeneration(ctx)),
|
|
31351
|
-
{ disposeInspector: !isLost() }
|
|
31352
|
-
);
|
|
31353
|
-
if (!isLost()) {
|
|
31354
|
-
disposeRunInspector(config3.run, actorId);
|
|
31355
|
-
}
|
|
31172
|
+
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(actorId);
|
|
31173
|
+
disposeRunInspector(config3.run, actorId);
|
|
31356
31174
|
try {
|
|
31357
|
-
if (typeof config3.onDestroy === "function"
|
|
31175
|
+
if (typeof config3.onDestroy === "function") {
|
|
31358
31176
|
await config3.onDestroy(actorCtx);
|
|
31359
31177
|
}
|
|
31360
31178
|
} finally {
|
|
@@ -31376,14 +31194,12 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31376
31194
|
request ? buildNativeHttpRequest(request) : void 0
|
|
31377
31195
|
);
|
|
31378
31196
|
try {
|
|
31379
|
-
const validatedParams = validateConnParams(
|
|
31380
|
-
schemaConfig.connParamsSchema,
|
|
31381
|
-
decodeValue(params)
|
|
31382
|
-
);
|
|
31383
|
-
throwIfActorLost(runtime, ctx);
|
|
31384
31197
|
await config3.onBeforeConnect(
|
|
31385
31198
|
actorCtx,
|
|
31386
|
-
|
|
31199
|
+
validateConnParams(
|
|
31200
|
+
schemaConfig.connParamsSchema,
|
|
31201
|
+
decodeValue(params)
|
|
31202
|
+
)
|
|
31387
31203
|
);
|
|
31388
31204
|
} finally {
|
|
31389
31205
|
await actorCtx.dispose();
|
|
@@ -31411,22 +31227,13 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31411
31227
|
() => actorCtx.assertCanMutateState()
|
|
31412
31228
|
);
|
|
31413
31229
|
try {
|
|
31414
|
-
|
|
31415
|
-
|
|
31416
|
-
|
|
31417
|
-
config3.connState
|
|
31418
|
-
);
|
|
31419
|
-
} else {
|
|
31420
|
-
const validatedParams = validateConnParams(
|
|
31230
|
+
const nextConnState = hasStaticConnState ? structuredClone(config3.connState) : await config3.createConnState(
|
|
31231
|
+
actorCtx,
|
|
31232
|
+
validateConnParams(
|
|
31421
31233
|
schemaConfig.connParamsSchema,
|
|
31422
31234
|
decodeValue(params)
|
|
31423
|
-
)
|
|
31424
|
-
|
|
31425
|
-
nextConnState = await config3.createConnState(
|
|
31426
|
-
actorCtx,
|
|
31427
|
-
validatedParams
|
|
31428
|
-
);
|
|
31429
|
-
}
|
|
31235
|
+
)
|
|
31236
|
+
);
|
|
31430
31237
|
connAdapter.initializeState(nextConnState);
|
|
31431
31238
|
return encodeValue(nextConnState);
|
|
31432
31239
|
} finally {
|
|
@@ -31531,9 +31338,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31531
31338
|
onBeforeActionResponse: typeof config3.onBeforeActionResponse === "function" ? wrapNativeCallback(
|
|
31532
31339
|
async (error46, payload) => {
|
|
31533
31340
|
const { ctx, name, args, output } = unwrapTsfnPayload(error46, payload);
|
|
31534
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
31535
|
-
return output;
|
|
31536
|
-
}
|
|
31537
31341
|
const actorCtx = makeActorCtx(ctx);
|
|
31538
31342
|
try {
|
|
31539
31343
|
return encodeValue(
|
|
@@ -31602,7 +31406,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31602
31406
|
}
|
|
31603
31407
|
};
|
|
31604
31408
|
try {
|
|
31605
|
-
throwIfActorLost(runtime, ctx);
|
|
31606
31409
|
const connParams = validateConnParams(
|
|
31607
31410
|
schemaConfig.connParamsSchema,
|
|
31608
31411
|
rawConnParams ? JSON.parse(rawConnParams) : void 0
|
|
@@ -31637,11 +31440,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31637
31440
|
abortRequest
|
|
31638
31441
|
);
|
|
31639
31442
|
}
|
|
31640
|
-
if (callNativeSync(
|
|
31641
|
-
() => runtime.actorIsLost(ctx)
|
|
31642
|
-
)) {
|
|
31643
|
-
throw actorGenerationLostError();
|
|
31644
|
-
}
|
|
31645
31443
|
const response = await config3.onRequest(
|
|
31646
31444
|
requestCtx,
|
|
31647
31445
|
handlerRequest
|
|
@@ -31714,9 +31512,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31714
31512
|
const { ctx } = unwrapTsfnPayload(error46, payload);
|
|
31715
31513
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
31716
31514
|
const executeRun = async () => {
|
|
31717
|
-
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
31718
|
-
return;
|
|
31719
|
-
}
|
|
31720
31515
|
const actorCtx = makeActorCtx(ctx);
|
|
31721
31516
|
try {
|
|
31722
31517
|
await run(actorCtx);
|
|
@@ -31730,8 +31525,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31730
31525
|
() => callNativeSync(
|
|
31731
31526
|
() => runtime.actorRestartRunHandler(ctx)
|
|
31732
31527
|
),
|
|
31733
|
-
executeRun
|
|
31734
|
-
callNativeSync(() => runtime.actorGeneration(ctx))
|
|
31528
|
+
executeRun
|
|
31735
31529
|
);
|
|
31736
31530
|
return outcome !== "suppressed";
|
|
31737
31531
|
}
|
|
@@ -31771,16 +31565,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31771
31565
|
const actorCtx = conn != null ? makeConnCtx(ctx, conn, void 0, cancelToken) : makeActorCtx(ctx, void 0, cancelToken);
|
|
31772
31566
|
const runAction = async () => {
|
|
31773
31567
|
try {
|
|
31774
|
-
const validatedArgs = validateActionArgs(
|
|
31775
|
-
schemaConfig.actionInputSchemas,
|
|
31776
|
-
name,
|
|
31777
|
-
decodeArgs(args)
|
|
31778
|
-
);
|
|
31779
|
-
throwIfActorLost(runtime, ctx);
|
|
31780
31568
|
return encodeValue(
|
|
31781
31569
|
await handler(
|
|
31782
31570
|
actorCtx,
|
|
31783
|
-
...
|
|
31571
|
+
...validateActionArgs(
|
|
31572
|
+
schemaConfig.actionInputSchemas,
|
|
31573
|
+
name,
|
|
31574
|
+
decodeArgs(args)
|
|
31575
|
+
),
|
|
31784
31576
|
...scheduledFire ? [scheduledFire] : []
|
|
31785
31577
|
)
|
|
31786
31578
|
);
|
|
@@ -31836,7 +31628,6 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31836
31628
|
if (canPublish && !await canPublish(actorCtx)) {
|
|
31837
31629
|
throw forbiddenError();
|
|
31838
31630
|
}
|
|
31839
|
-
throwIfActorLost(runtime, ctx);
|
|
31840
31631
|
const decodedBody = decodeValue(body);
|
|
31841
31632
|
if (wait) {
|
|
31842
31633
|
try {
|
|
@@ -31880,7 +31671,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31880
31671
|
)
|
|
31881
31672
|
};
|
|
31882
31673
|
return runtime.createActorFactory(
|
|
31883
|
-
|
|
31674
|
+
callbacks,
|
|
31884
31675
|
buildActorConfig(definition, registryConfig, runtime.kind)
|
|
31885
31676
|
);
|
|
31886
31677
|
}
|