@rivetkit/supabase 2.3.22 → 2.3.24-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.js +321 -93
- package/dist/mod.mjs +321 -93
- 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-JJCUSUWO.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-JJCUSUWO.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.24-rc.1",
|
|
13386
13386
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13387
13387
|
license: "Apache-2.0",
|
|
13388
13388
|
keywords: [
|
|
@@ -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-M5J3PXNU.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-LTGBHN5Z.js
|
|
14991
14991
|
function flattenActionHandlers(actions) {
|
|
14992
14992
|
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14993
14993
|
for (const { name, handler } of collectActionEntries(actions)) {
|
|
@@ -15682,7 +15682,7 @@ var AsyncMutex = class {
|
|
|
15682
15682
|
}
|
|
15683
15683
|
};
|
|
15684
15684
|
|
|
15685
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15685
|
+
// ../rivetkit/dist/tsup/chunk-OB5JLDBM.js
|
|
15686
15686
|
function logger() {
|
|
15687
15687
|
return getLogger("actor-client");
|
|
15688
15688
|
}
|
|
@@ -15720,7 +15720,7 @@ async function importWebSocket() {
|
|
|
15720
15720
|
return webSocketPromise;
|
|
15721
15721
|
}
|
|
15722
15722
|
|
|
15723
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15723
|
+
// ../rivetkit/dist/tsup/chunk-B6WTPGOR.js
|
|
15724
15724
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15725
15725
|
|
|
15726
15726
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -16935,7 +16935,7 @@ var TraceAPI = (
|
|
|
16935
16935
|
// ../../../node_modules/.pnpm/@opentelemetry+api@1.9.0/node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
16936
16936
|
var trace = TraceAPI.getInstance();
|
|
16937
16937
|
|
|
16938
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
16938
|
+
// ../rivetkit/dist/tsup/chunk-B6WTPGOR.js
|
|
16939
16939
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
16940
16940
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
16941
16941
|
var PATH_CONNECT = "/connect";
|
|
@@ -23112,7 +23112,7 @@ function apiActorToOutput(actor2) {
|
|
|
23112
23112
|
};
|
|
23113
23113
|
}
|
|
23114
23114
|
|
|
23115
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
23115
|
+
// ../rivetkit/dist/tsup/chunk-QQ454DVR.js
|
|
23116
23116
|
var nativeStateTransactionOpeners = /* @__PURE__ */ new WeakMap();
|
|
23117
23117
|
var nativeStateTransactionClientBinders = /* @__PURE__ */ new WeakMap();
|
|
23118
23118
|
function registerNativeStateTransactionOpener(provider, opener) {
|
|
@@ -26171,6 +26171,12 @@ var NapiCoreRuntime = class {
|
|
|
26171
26171
|
actorId(ctx) {
|
|
26172
26172
|
return asNativeActorContext(ctx).actorId();
|
|
26173
26173
|
}
|
|
26174
|
+
actorGeneration(ctx) {
|
|
26175
|
+
return asNativeActorContext(ctx).generation() ?? void 0;
|
|
26176
|
+
}
|
|
26177
|
+
actorIsLost(ctx) {
|
|
26178
|
+
return asNativeActorContext(ctx).isLost();
|
|
26179
|
+
}
|
|
26174
26180
|
runWithActorInvocationContext(ctx, run) {
|
|
26175
26181
|
return this.#runAs(asNativeActorContext(ctx), run);
|
|
26176
26182
|
}
|
|
@@ -26784,6 +26790,27 @@ function notifyStateChanged(state) {
|
|
|
26784
26790
|
waiter();
|
|
26785
26791
|
}
|
|
26786
26792
|
}
|
|
26793
|
+
function createRunState(actorGeneration) {
|
|
26794
|
+
return {
|
|
26795
|
+
actorGeneration,
|
|
26796
|
+
active: false,
|
|
26797
|
+
closed: false,
|
|
26798
|
+
exclusive: false,
|
|
26799
|
+
exclusiveGeneration: 0,
|
|
26800
|
+
inspectorInitialized: false,
|
|
26801
|
+
queued: 0,
|
|
26802
|
+
waiters: /* @__PURE__ */ new Set()
|
|
26803
|
+
};
|
|
26804
|
+
}
|
|
26805
|
+
function closeRunState(state, disposeInspector = true) {
|
|
26806
|
+
var _a2, _b;
|
|
26807
|
+
state.closed = true;
|
|
26808
|
+
if (disposeInspector) {
|
|
26809
|
+
(_b = (_a2 = state.inspector) == null ? void 0 : _a2.dispose) == null ? void 0 : _b.call(_a2);
|
|
26810
|
+
}
|
|
26811
|
+
state.inspector = void 0;
|
|
26812
|
+
notifyStateChanged(state);
|
|
26813
|
+
}
|
|
26787
26814
|
function waitForStateChange(state) {
|
|
26788
26815
|
return new Promise((resolve) => {
|
|
26789
26816
|
state.waiters.add(resolve);
|
|
@@ -26798,8 +26825,11 @@ var RunHandlerCoordinator = class {
|
|
|
26798
26825
|
get inspectorKind() {
|
|
26799
26826
|
return getRunInspectorKind(this.#run);
|
|
26800
26827
|
}
|
|
26801
|
-
async run(actorId, restart, callback) {
|
|
26802
|
-
const state = this.#getOrCreate(actorId);
|
|
26828
|
+
async run(actorId, restart, callback, actorGeneration) {
|
|
26829
|
+
const state = this.#getOrCreate(actorId, actorGeneration);
|
|
26830
|
+
if (state.closed) {
|
|
26831
|
+
return "closed";
|
|
26832
|
+
}
|
|
26803
26833
|
state.restart = restart;
|
|
26804
26834
|
this.#initializeInspector(actorId, state);
|
|
26805
26835
|
state.queued += 1;
|
|
@@ -26826,21 +26856,27 @@ var RunHandlerCoordinator = class {
|
|
|
26826
26856
|
notifyStateChanged(state);
|
|
26827
26857
|
}
|
|
26828
26858
|
}
|
|
26829
|
-
getInspector(actorId, restart) {
|
|
26859
|
+
getInspector(actorId, restart, actorGeneration) {
|
|
26830
26860
|
var _a2;
|
|
26831
|
-
const state = this.#getOrCreate(actorId);
|
|
26861
|
+
const state = this.#getOrCreate(actorId, actorGeneration);
|
|
26862
|
+
if (state.closed) {
|
|
26863
|
+
return void 0;
|
|
26864
|
+
}
|
|
26832
26865
|
state.restart = restart;
|
|
26833
26866
|
this.#initializeInspector(actorId, state);
|
|
26834
26867
|
return (_a2 = state.inspector) == null ? void 0 : _a2.inspector;
|
|
26835
26868
|
}
|
|
26836
|
-
|
|
26837
|
-
|
|
26869
|
+
/**
|
|
26870
|
+
* Closes the run state for `actorId`. With `actorGeneration`, only state owned by that
|
|
26871
|
+
* generation is closed, so an older generation's late cleanup cannot close a newer one.
|
|
26872
|
+
*/
|
|
26873
|
+
destroy(actorId, actorGeneration, options = {}) {
|
|
26838
26874
|
const state = this.#states.get(actorId);
|
|
26839
26875
|
if (!state) return;
|
|
26840
|
-
state.
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26876
|
+
if (actorGeneration !== void 0 && state.actorGeneration !== void 0 && state.actorGeneration !== actorGeneration) {
|
|
26877
|
+
return;
|
|
26878
|
+
}
|
|
26879
|
+
closeRunState(state, options.disposeInspector ?? true);
|
|
26844
26880
|
this.#states.delete(actorId);
|
|
26845
26881
|
}
|
|
26846
26882
|
#control(actorId, state) {
|
|
@@ -26886,18 +26922,20 @@ var RunHandlerCoordinator = class {
|
|
|
26886
26922
|
}
|
|
26887
26923
|
};
|
|
26888
26924
|
}
|
|
26889
|
-
#getOrCreate(actorId) {
|
|
26925
|
+
#getOrCreate(actorId, actorGeneration) {
|
|
26890
26926
|
let state = this.#states.get(actorId);
|
|
26927
|
+
if (state && actorGeneration !== void 0 && state.actorGeneration !== void 0 && state.actorGeneration !== actorGeneration) {
|
|
26928
|
+
if (actorGeneration < state.actorGeneration) {
|
|
26929
|
+
const detached = createRunState(actorGeneration);
|
|
26930
|
+
detached.closed = true;
|
|
26931
|
+
return detached;
|
|
26932
|
+
}
|
|
26933
|
+
closeRunState(state, false);
|
|
26934
|
+
this.#states.delete(actorId);
|
|
26935
|
+
state = void 0;
|
|
26936
|
+
}
|
|
26891
26937
|
if (!state) {
|
|
26892
|
-
state =
|
|
26893
|
-
active: false,
|
|
26894
|
-
closed: false,
|
|
26895
|
-
exclusive: false,
|
|
26896
|
-
exclusiveGeneration: 0,
|
|
26897
|
-
inspectorInitialized: false,
|
|
26898
|
-
queued: 0,
|
|
26899
|
-
waiters: /* @__PURE__ */ new Set()
|
|
26900
|
-
};
|
|
26938
|
+
state = createRunState(actorGeneration);
|
|
26901
26939
|
this.#states.set(actorId, state);
|
|
26902
26940
|
}
|
|
26903
26941
|
return state;
|
|
@@ -26906,6 +26944,7 @@ var RunHandlerCoordinator = class {
|
|
|
26906
26944
|
if (state.inspectorInitialized) return;
|
|
26907
26945
|
const inspector = createRunInspector(this.#run, {
|
|
26908
26946
|
actorId,
|
|
26947
|
+
actorGeneration: state.actorGeneration,
|
|
26909
26948
|
control: this.#control(actorId, state)
|
|
26910
26949
|
});
|
|
26911
26950
|
if (this.inspectorKind === "workflow") {
|
|
@@ -27231,6 +27270,12 @@ var WasmCoreRuntime = class {
|
|
|
27231
27270
|
actorId(ctx) {
|
|
27232
27271
|
return callHandle(asWasmActorContext(ctx), "actorId");
|
|
27233
27272
|
}
|
|
27273
|
+
actorGeneration(ctx) {
|
|
27274
|
+
return callHandle(asWasmActorContext(ctx), "generation") ?? void 0;
|
|
27275
|
+
}
|
|
27276
|
+
actorIsLost(ctx) {
|
|
27277
|
+
return callHandle(asWasmActorContext(ctx), "isLost");
|
|
27278
|
+
}
|
|
27234
27279
|
runWithActorInvocationContext(_ctx, run) {
|
|
27235
27280
|
return run();
|
|
27236
27281
|
}
|
|
@@ -28057,8 +28102,11 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
|
|
|
28057
28102
|
await closeNativeDatabaseClient(runtime, ctx);
|
|
28058
28103
|
await closeNativeSqlDatabase(runtime, ctx);
|
|
28059
28104
|
void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
|
|
28060
|
-
|
|
28061
|
-
|
|
28105
|
+
try {
|
|
28106
|
+
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
28107
|
+
} finally {
|
|
28108
|
+
clearNativeRuntimeState(runtime, ctx);
|
|
28109
|
+
}
|
|
28062
28110
|
}).catch((error46) => {
|
|
28063
28111
|
logger22().warn({
|
|
28064
28112
|
msg: "deferred native sleep cleanup failed",
|
|
@@ -28067,10 +28115,24 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
|
|
|
28067
28115
|
});
|
|
28068
28116
|
return;
|
|
28069
28117
|
}
|
|
28070
|
-
|
|
28118
|
+
try {
|
|
28119
|
+
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
28120
|
+
} finally {
|
|
28121
|
+
try {
|
|
28122
|
+
await closeNativeDatabaseClient(runtime, ctx);
|
|
28123
|
+
await closeNativeSqlDatabase(runtime, ctx);
|
|
28124
|
+
} finally {
|
|
28125
|
+
clearNativeRuntimeState(runtime, ctx);
|
|
28126
|
+
}
|
|
28127
|
+
}
|
|
28128
|
+
}
|
|
28129
|
+
async function cleanupNativeLostRuntimeState(runtime, ctx) {
|
|
28071
28130
|
await closeNativeDatabaseClient(runtime, ctx);
|
|
28072
|
-
|
|
28073
|
-
|
|
28131
|
+
try {
|
|
28132
|
+
await closeNativeSqlDatabase(runtime, ctx);
|
|
28133
|
+
} finally {
|
|
28134
|
+
clearNativeRuntimeState(runtime, ctx);
|
|
28135
|
+
}
|
|
28074
28136
|
}
|
|
28075
28137
|
function closeNativeSqlDatabase(runtime, ctx) {
|
|
28076
28138
|
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
@@ -28088,6 +28150,9 @@ async function closeNativeDatabaseClient(runtime, ctx) {
|
|
|
28088
28150
|
return;
|
|
28089
28151
|
}
|
|
28090
28152
|
runtimeState.databaseClient = void 0;
|
|
28153
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
28154
|
+
return;
|
|
28155
|
+
}
|
|
28091
28156
|
if (entry.client && typeof entry.client === "object" && "close" in entry.client && typeof entry.client.close === "function") {
|
|
28092
28157
|
await entry.client.close();
|
|
28093
28158
|
}
|
|
@@ -28513,6 +28578,49 @@ function wrapNativeCallback(callback) {
|
|
|
28513
28578
|
}
|
|
28514
28579
|
};
|
|
28515
28580
|
}
|
|
28581
|
+
var LOST_GENERATION_CLEANUP_CALLBACKS = /* @__PURE__ */ new Set(["onSleep", "onDestroy"]);
|
|
28582
|
+
function throwIfActorLost(runtime, ctx) {
|
|
28583
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
28584
|
+
throw actorGenerationLostError();
|
|
28585
|
+
}
|
|
28586
|
+
}
|
|
28587
|
+
function actorGenerationLostError() {
|
|
28588
|
+
return new RivetError(
|
|
28589
|
+
"actor",
|
|
28590
|
+
"stopping",
|
|
28591
|
+
"Actor generation was declared lost; it starts no new user callbacks."
|
|
28592
|
+
);
|
|
28593
|
+
}
|
|
28594
|
+
function refuseCallbacksAfterLost(runtime, callbacks) {
|
|
28595
|
+
const guard = (callback) => {
|
|
28596
|
+
return async (...args) => {
|
|
28597
|
+
var _a2;
|
|
28598
|
+
const ctx = (_a2 = args[1]) == null ? void 0 : _a2.ctx;
|
|
28599
|
+
if (ctx !== void 0 && callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
28600
|
+
throw encodeNativeCallbackError(actorGenerationLostError());
|
|
28601
|
+
}
|
|
28602
|
+
return await callback(...args);
|
|
28603
|
+
};
|
|
28604
|
+
};
|
|
28605
|
+
const guarded = {};
|
|
28606
|
+
for (const [name, value] of Object.entries(callbacks)) {
|
|
28607
|
+
if (LOST_GENERATION_CLEANUP_CALLBACKS.has(name)) {
|
|
28608
|
+
guarded[name] = value;
|
|
28609
|
+
} else if (typeof value === "function") {
|
|
28610
|
+
guarded[name] = guard(value);
|
|
28611
|
+
} else if (name === "actions" && value !== null && typeof value === "object") {
|
|
28612
|
+
guarded[name] = Object.fromEntries(
|
|
28613
|
+
Object.entries(value).map(([actionName, handler]) => [
|
|
28614
|
+
actionName,
|
|
28615
|
+
guard(handler)
|
|
28616
|
+
])
|
|
28617
|
+
);
|
|
28618
|
+
} else {
|
|
28619
|
+
guarded[name] = value;
|
|
28620
|
+
}
|
|
28621
|
+
}
|
|
28622
|
+
return guarded;
|
|
28623
|
+
}
|
|
28516
28624
|
function decodeArgs(value) {
|
|
28517
28625
|
const decoded = decodeValue(value);
|
|
28518
28626
|
return normalizeArgs(decoded);
|
|
@@ -28950,17 +29058,30 @@ var NativeQueueAdapter = class {
|
|
|
28950
29058
|
this.#ctx = ctx;
|
|
28951
29059
|
this.#schemas = schemas;
|
|
28952
29060
|
}
|
|
29061
|
+
// Queue results arrive after awaits, and their schema validation is user code, so each
|
|
29062
|
+
// validation checks that the generation was not lost first.
|
|
29063
|
+
#validateBody(name, body) {
|
|
29064
|
+
throwIfActorLost(this.#runtime, this.#ctx);
|
|
29065
|
+
return validateQueueBody(this.#schemas, name, body);
|
|
29066
|
+
}
|
|
29067
|
+
#validateComplete(name, response) {
|
|
29068
|
+
throwIfActorLost(this.#runtime, this.#ctx);
|
|
29069
|
+
return validateQueueComplete(this.#schemas, name, response);
|
|
29070
|
+
}
|
|
29071
|
+
#wrap(message) {
|
|
29072
|
+
throwIfActorLost(this.#runtime, this.#ctx);
|
|
29073
|
+
return wrapQueueMessage(message, this.#schemas);
|
|
29074
|
+
}
|
|
28953
29075
|
async send(name, body) {
|
|
28954
|
-
const validatedBody =
|
|
28955
|
-
return
|
|
29076
|
+
const validatedBody = this.#validateBody(name, body);
|
|
29077
|
+
return this.#wrap(
|
|
28956
29078
|
await callNative(
|
|
28957
29079
|
() => this.#runtime.actorQueueSend(
|
|
28958
29080
|
this.#ctx,
|
|
28959
29081
|
name,
|
|
28960
29082
|
encodeValue(validatedBody)
|
|
28961
29083
|
)
|
|
28962
|
-
)
|
|
28963
|
-
this.#schemas
|
|
29084
|
+
)
|
|
28964
29085
|
);
|
|
28965
29086
|
}
|
|
28966
29087
|
async next(options) {
|
|
@@ -29003,9 +29124,7 @@ var NativeQueueAdapter = class {
|
|
|
29003
29124
|
token
|
|
29004
29125
|
)
|
|
29005
29126
|
);
|
|
29006
|
-
const wrapped = messages.map(
|
|
29007
|
-
(message) => wrapQueueMessage(message, this.#schemas)
|
|
29008
|
-
);
|
|
29127
|
+
const wrapped = messages.map((message) => this.#wrap(message));
|
|
29009
29128
|
return completable ? wrapped.map(
|
|
29010
29129
|
(message) => this.#makeCompletableMessage(message)
|
|
29011
29130
|
) : wrapped;
|
|
@@ -29019,7 +29138,7 @@ var NativeQueueAdapter = class {
|
|
|
29019
29138
|
options == null ? void 0 : options.signal
|
|
29020
29139
|
);
|
|
29021
29140
|
try {
|
|
29022
|
-
return
|
|
29141
|
+
return this.#wrap(
|
|
29023
29142
|
await callNative(
|
|
29024
29143
|
() => this.#runtime.actorQueueWaitForNames(
|
|
29025
29144
|
this.#ctx,
|
|
@@ -29030,8 +29149,7 @@ var NativeQueueAdapter = class {
|
|
|
29030
29149
|
},
|
|
29031
29150
|
token
|
|
29032
29151
|
)
|
|
29033
|
-
)
|
|
29034
|
-
this.#schemas
|
|
29152
|
+
)
|
|
29035
29153
|
);
|
|
29036
29154
|
} finally {
|
|
29037
29155
|
cleanup == null ? void 0 : cleanup();
|
|
@@ -29061,8 +29179,7 @@ var NativeQueueAdapter = class {
|
|
|
29061
29179
|
await this.waitForNamesAvailable(names ?? [], options);
|
|
29062
29180
|
}
|
|
29063
29181
|
async complete(message, response) {
|
|
29064
|
-
const validatedResponse =
|
|
29065
|
-
this.#schemas,
|
|
29182
|
+
const validatedResponse = this.#validateComplete(
|
|
29066
29183
|
message.name,
|
|
29067
29184
|
response
|
|
29068
29185
|
);
|
|
@@ -29077,7 +29194,7 @@ var NativeQueueAdapter = class {
|
|
|
29077
29194
|
this.#pendingCompletableMessageIds.delete(message.id.toString());
|
|
29078
29195
|
}
|
|
29079
29196
|
async enqueueAndWait(name, body, options) {
|
|
29080
|
-
const validatedBody =
|
|
29197
|
+
const validatedBody = this.#validateBody(name, body);
|
|
29081
29198
|
const { token, cleanup } = await createCancellationTokenHandle(
|
|
29082
29199
|
this.#runtime,
|
|
29083
29200
|
options == null ? void 0 : options.signal
|
|
@@ -29094,11 +29211,7 @@ var NativeQueueAdapter = class {
|
|
|
29094
29211
|
token
|
|
29095
29212
|
)
|
|
29096
29213
|
);
|
|
29097
|
-
return response === void 0 || response === null ? void 0 :
|
|
29098
|
-
this.#schemas,
|
|
29099
|
-
name,
|
|
29100
|
-
decodeValue(response)
|
|
29101
|
-
);
|
|
29214
|
+
return response === void 0 || response === null ? void 0 : this.#validateComplete(name, decodeValue(response));
|
|
29102
29215
|
} finally {
|
|
29103
29216
|
cleanup == null ? void 0 : cleanup();
|
|
29104
29217
|
}
|
|
@@ -29479,6 +29592,9 @@ var TrackedWebSocketHandleAdapter = class {
|
|
|
29479
29592
|
}
|
|
29480
29593
|
}
|
|
29481
29594
|
#callHandler(type, handler, event2) {
|
|
29595
|
+
if ((type === "message" || type === "open") && this.#ctx.isLost) {
|
|
29596
|
+
return;
|
|
29597
|
+
}
|
|
29482
29598
|
try {
|
|
29483
29599
|
const result = handler(event2);
|
|
29484
29600
|
if (!this.#isPromiseLike(result)) {
|
|
@@ -29761,6 +29877,13 @@ var ActorContextHandleAdapter = class {
|
|
|
29761
29877
|
get actorId() {
|
|
29762
29878
|
return callNativeSync(() => this.#runtime.actorId(this.#ctx));
|
|
29763
29879
|
}
|
|
29880
|
+
get actorGeneration() {
|
|
29881
|
+
return callNativeSync(() => this.#runtime.actorGeneration(this.#ctx));
|
|
29882
|
+
}
|
|
29883
|
+
/** Whether this generation was declared lost. A lost generation starts no new user code. */
|
|
29884
|
+
get isLost() {
|
|
29885
|
+
return callNativeSync(() => this.#runtime.actorIsLost(this.#ctx));
|
|
29886
|
+
}
|
|
29764
29887
|
get name() {
|
|
29765
29888
|
return callNativeSync(() => this.#runtime.actorName(this.#ctx));
|
|
29766
29889
|
}
|
|
@@ -29875,6 +29998,9 @@ var ActorContextHandleAdapter = class {
|
|
|
29875
29998
|
return this.#db;
|
|
29876
29999
|
}
|
|
29877
30000
|
const actorId = this.actorId;
|
|
30001
|
+
if (this.isLost) {
|
|
30002
|
+
throw actorGenerationLostError();
|
|
30003
|
+
}
|
|
29878
30004
|
const createdClient = await this.#databaseProvider.createClient({
|
|
29879
30005
|
actorId,
|
|
29880
30006
|
kv: {
|
|
@@ -30027,9 +30153,11 @@ var ActorContextHandleAdapter = class {
|
|
|
30027
30153
|
if (!this.#databaseProvider) {
|
|
30028
30154
|
return;
|
|
30029
30155
|
}
|
|
30030
|
-
await this
|
|
30031
|
-
|
|
30032
|
-
|
|
30156
|
+
const client = await this.ensureDatabaseClient();
|
|
30157
|
+
if (this.isLost) {
|
|
30158
|
+
throw actorGenerationLostError();
|
|
30159
|
+
}
|
|
30160
|
+
await this.#databaseProvider.onMigrate(client);
|
|
30033
30161
|
}
|
|
30034
30162
|
async closeDatabase() {
|
|
30035
30163
|
this.#db = void 0;
|
|
@@ -30301,7 +30429,7 @@ var ActorContextHandleAdapter = class {
|
|
|
30301
30429
|
callNativeSync(
|
|
30302
30430
|
() => this.#runtime.actorRequestSave(this.#ctx, { immediate: false })
|
|
30303
30431
|
);
|
|
30304
|
-
if (!this.#onStateChange) {
|
|
30432
|
+
if (!this.#onStateChange || this.isLost) {
|
|
30305
30433
|
return;
|
|
30306
30434
|
}
|
|
30307
30435
|
actorState.isInOnStateChange = true;
|
|
@@ -30341,6 +30469,12 @@ var NativeWorkflowRuntimeAdapter = class {
|
|
|
30341
30469
|
#onMessagesReceived;
|
|
30342
30470
|
#completions = /* @__PURE__ */ new Map();
|
|
30343
30471
|
id;
|
|
30472
|
+
/** Actor generation, used to keep workflow registrations of different generations apart. */
|
|
30473
|
+
generation;
|
|
30474
|
+
/** Whether this generation was declared lost. Workflow code checks it before each user callback. */
|
|
30475
|
+
get isLost() {
|
|
30476
|
+
return this.#ctx.isLost;
|
|
30477
|
+
}
|
|
30344
30478
|
driver;
|
|
30345
30479
|
queueManager;
|
|
30346
30480
|
stateManager;
|
|
@@ -30348,6 +30482,7 @@ var NativeWorkflowRuntimeAdapter = class {
|
|
|
30348
30482
|
this.#ctx = ctx;
|
|
30349
30483
|
this.#onMessagesReceived = onMessagesReceived;
|
|
30350
30484
|
this.id = ctx.actorId;
|
|
30485
|
+
this.generation = ctx.actorGeneration;
|
|
30351
30486
|
this.driver = {
|
|
30352
30487
|
kvBatchGet: async (actorId, keys) => {
|
|
30353
30488
|
this.#assertActorId(actorId);
|
|
@@ -30630,9 +30765,23 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30630
30765
|
const runHandlerCoordinator = getRunInspectorKind(config3.run) === "workflow" ? new RunHandlerCoordinator(config3.run) : void 0;
|
|
30631
30766
|
const getNativeWorkflowInspector = (ctx) => {
|
|
30632
30767
|
var _a22, _b;
|
|
30768
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
30769
|
+
return void 0;
|
|
30770
|
+
}
|
|
30633
30771
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
30634
30772
|
const restart = () => callNativeSync(() => runtime.actorRestartRunHandler(ctx));
|
|
30635
|
-
|
|
30773
|
+
const actorGeneration = callNativeSync(
|
|
30774
|
+
() => runtime.actorGeneration(ctx)
|
|
30775
|
+
);
|
|
30776
|
+
const inspector = ((_a22 = runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.getInspector(
|
|
30777
|
+
actorId,
|
|
30778
|
+
restart,
|
|
30779
|
+
actorGeneration
|
|
30780
|
+
)) == null ? void 0 : _a22.workflow) ?? ((_b = getRunInspectorConfig(config3.run, actorId)) == null ? void 0 : _b.workflow);
|
|
30781
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
30782
|
+
return void 0;
|
|
30783
|
+
}
|
|
30784
|
+
return inspector;
|
|
30636
30785
|
};
|
|
30637
30786
|
const onStateChange = typeof config3.onStateChange === "function" ? (actorCtx, nextState) => {
|
|
30638
30787
|
config3.onStateChange(actorCtx, nextState);
|
|
@@ -30709,6 +30858,10 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30709
30858
|
return errorResponse(error46, 401);
|
|
30710
30859
|
}
|
|
30711
30860
|
}
|
|
30861
|
+
const inspectorConnParams = (conn) => {
|
|
30862
|
+
throwIfActorLost(runtime, ctx);
|
|
30863
|
+
return conn.params;
|
|
30864
|
+
};
|
|
30712
30865
|
const workflowHistory = () => {
|
|
30713
30866
|
var _a3;
|
|
30714
30867
|
return serializeWorkflowHistoryForJson(
|
|
@@ -30742,7 +30895,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30742
30895
|
id: conn.id,
|
|
30743
30896
|
details: {
|
|
30744
30897
|
type: null,
|
|
30745
|
-
params: conn
|
|
30898
|
+
params: inspectorConnParams(conn),
|
|
30746
30899
|
stateEnabled: true,
|
|
30747
30900
|
state: conn.state,
|
|
30748
30901
|
subscriptions: 0,
|
|
@@ -30946,7 +31099,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30946
31099
|
id: conn.id,
|
|
30947
31100
|
details: {
|
|
30948
31101
|
type: null,
|
|
30949
|
-
params: conn
|
|
31102
|
+
params: inspectorConnParams(conn),
|
|
30950
31103
|
stateEnabled: true,
|
|
30951
31104
|
state: conn.state,
|
|
30952
31105
|
subscriptions: 0,
|
|
@@ -30993,15 +31146,20 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
30993
31146
|
);
|
|
30994
31147
|
}
|
|
30995
31148
|
const args = body.properties !== void 0 ? [body.properties] : normalizeArgs(body.args);
|
|
31149
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
31150
|
+
return jsonResponse(
|
|
31151
|
+
{ error: "actor generation was declared lost" },
|
|
31152
|
+
{ status: 503 }
|
|
31153
|
+
);
|
|
31154
|
+
}
|
|
30996
31155
|
try {
|
|
30997
|
-
const
|
|
30998
|
-
|
|
30999
|
-
|
|
31000
|
-
|
|
31001
|
-
actionName,
|
|
31002
|
-
args
|
|
31003
|
-
)
|
|
31156
|
+
const validatedArgs = validateActionArgs(
|
|
31157
|
+
schemaConfig.actionInputSchemas,
|
|
31158
|
+
actionName,
|
|
31159
|
+
args
|
|
31004
31160
|
);
|
|
31161
|
+
throwIfActorLost(runtime, ctx);
|
|
31162
|
+
const output = await action(actorCtx, ...validatedArgs);
|
|
31005
31163
|
return jsonResponse({ output });
|
|
31006
31164
|
} catch (error46) {
|
|
31007
31165
|
logger22().error({
|
|
@@ -31105,7 +31263,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31105
31263
|
await actorCtx.closeDatabase();
|
|
31106
31264
|
}
|
|
31107
31265
|
await actorCtx.runDatabaseMigrations();
|
|
31108
|
-
if (typeof config3.onMigrate === "function"
|
|
31266
|
+
if (typeof config3.onMigrate === "function" && !callNativeSync(
|
|
31267
|
+
() => runtime.actorIsLost(ctx)
|
|
31268
|
+
)) {
|
|
31109
31269
|
await config3.onMigrate(actorCtx, isNew);
|
|
31110
31270
|
}
|
|
31111
31271
|
} catch (error210) {
|
|
@@ -31148,7 +31308,29 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31148
31308
|
const { ctx } = unwrapTsfnPayload(error46, payload);
|
|
31149
31309
|
const actorCtx = makeActorCtx(ctx);
|
|
31150
31310
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
31311
|
+
const actorGeneration = callNativeSync(
|
|
31312
|
+
() => runtime.actorGeneration(ctx)
|
|
31313
|
+
);
|
|
31314
|
+
const isLost = () => callNativeSync(() => runtime.actorIsLost(ctx));
|
|
31315
|
+
if (isLost()) {
|
|
31316
|
+
try {
|
|
31317
|
+
await cleanupNativeLostRuntimeState(runtime, ctx);
|
|
31318
|
+
} finally {
|
|
31319
|
+
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
|
|
31320
|
+
actorId,
|
|
31321
|
+
actorGeneration,
|
|
31322
|
+
{
|
|
31323
|
+
disposeInspector: false
|
|
31324
|
+
}
|
|
31325
|
+
);
|
|
31326
|
+
await actorCtx.dispose();
|
|
31327
|
+
}
|
|
31328
|
+
return;
|
|
31329
|
+
}
|
|
31151
31330
|
const saveActorState = async () => {
|
|
31331
|
+
if (isLost()) {
|
|
31332
|
+
return;
|
|
31333
|
+
}
|
|
31152
31334
|
if (runtime.kind === "wasm") {
|
|
31153
31335
|
await runtime.actorSaveState(
|
|
31154
31336
|
ctx,
|
|
@@ -31167,14 +31349,26 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31167
31349
|
await saveActorState();
|
|
31168
31350
|
} finally {
|
|
31169
31351
|
try {
|
|
31170
|
-
|
|
31171
|
-
runtime,
|
|
31172
|
-
|
|
31173
|
-
|
|
31174
|
-
|
|
31352
|
+
if (isLost()) {
|
|
31353
|
+
await cleanupNativeLostRuntimeState(runtime, ctx);
|
|
31354
|
+
} else {
|
|
31355
|
+
await cleanupNativeSleepRuntimeState(
|
|
31356
|
+
runtime,
|
|
31357
|
+
ctx,
|
|
31358
|
+
saveActorState
|
|
31359
|
+
);
|
|
31360
|
+
}
|
|
31175
31361
|
} finally {
|
|
31176
|
-
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
|
|
31177
|
-
|
|
31362
|
+
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
|
|
31363
|
+
actorId,
|
|
31364
|
+
actorGeneration,
|
|
31365
|
+
{
|
|
31366
|
+
disposeInspector: !isLost()
|
|
31367
|
+
}
|
|
31368
|
+
);
|
|
31369
|
+
if (!isLost()) {
|
|
31370
|
+
disposeRunInspector(config3.run, actorId);
|
|
31371
|
+
}
|
|
31178
31372
|
await actorCtx.dispose();
|
|
31179
31373
|
}
|
|
31180
31374
|
}
|
|
@@ -31185,10 +31379,17 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31185
31379
|
const { ctx } = unwrapTsfnPayload(error46, payload);
|
|
31186
31380
|
const actorCtx = makeActorCtx(ctx);
|
|
31187
31381
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
31188
|
-
|
|
31189
|
-
|
|
31382
|
+
const isLost = () => callNativeSync(() => runtime.actorIsLost(ctx));
|
|
31383
|
+
runHandlerCoordinator == null ? void 0 : runHandlerCoordinator.destroy(
|
|
31384
|
+
actorId,
|
|
31385
|
+
callNativeSync(() => runtime.actorGeneration(ctx)),
|
|
31386
|
+
{ disposeInspector: !isLost() }
|
|
31387
|
+
);
|
|
31388
|
+
if (!isLost()) {
|
|
31389
|
+
disposeRunInspector(config3.run, actorId);
|
|
31390
|
+
}
|
|
31190
31391
|
try {
|
|
31191
|
-
if (typeof config3.onDestroy === "function") {
|
|
31392
|
+
if (typeof config3.onDestroy === "function" && !isLost()) {
|
|
31192
31393
|
await config3.onDestroy(actorCtx);
|
|
31193
31394
|
}
|
|
31194
31395
|
} finally {
|
|
@@ -31210,12 +31411,14 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31210
31411
|
request ? buildNativeHttpRequest(request) : void 0
|
|
31211
31412
|
);
|
|
31212
31413
|
try {
|
|
31414
|
+
const validatedParams = validateConnParams(
|
|
31415
|
+
schemaConfig.connParamsSchema,
|
|
31416
|
+
decodeValue(params)
|
|
31417
|
+
);
|
|
31418
|
+
throwIfActorLost(runtime, ctx);
|
|
31213
31419
|
await config3.onBeforeConnect(
|
|
31214
31420
|
actorCtx,
|
|
31215
|
-
|
|
31216
|
-
schemaConfig.connParamsSchema,
|
|
31217
|
-
decodeValue(params)
|
|
31218
|
-
)
|
|
31421
|
+
validatedParams
|
|
31219
31422
|
);
|
|
31220
31423
|
} finally {
|
|
31221
31424
|
await actorCtx.dispose();
|
|
@@ -31243,13 +31446,22 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31243
31446
|
() => actorCtx.assertCanMutateState()
|
|
31244
31447
|
);
|
|
31245
31448
|
try {
|
|
31246
|
-
|
|
31247
|
-
|
|
31248
|
-
|
|
31449
|
+
let nextConnState;
|
|
31450
|
+
if (hasStaticConnState) {
|
|
31451
|
+
nextConnState = structuredClone(
|
|
31452
|
+
config3.connState
|
|
31453
|
+
);
|
|
31454
|
+
} else {
|
|
31455
|
+
const validatedParams = validateConnParams(
|
|
31249
31456
|
schemaConfig.connParamsSchema,
|
|
31250
31457
|
decodeValue(params)
|
|
31251
|
-
)
|
|
31252
|
-
|
|
31458
|
+
);
|
|
31459
|
+
throwIfActorLost(runtime, ctx);
|
|
31460
|
+
nextConnState = await config3.createConnState(
|
|
31461
|
+
actorCtx,
|
|
31462
|
+
validatedParams
|
|
31463
|
+
);
|
|
31464
|
+
}
|
|
31253
31465
|
connAdapter.initializeState(nextConnState);
|
|
31254
31466
|
return encodeValue(nextConnState);
|
|
31255
31467
|
} finally {
|
|
@@ -31354,6 +31566,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31354
31566
|
onBeforeActionResponse: typeof config3.onBeforeActionResponse === "function" ? wrapNativeCallback(
|
|
31355
31567
|
async (error46, payload) => {
|
|
31356
31568
|
const { ctx, name, args, output } = unwrapTsfnPayload(error46, payload);
|
|
31569
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
31570
|
+
return output;
|
|
31571
|
+
}
|
|
31357
31572
|
const actorCtx = makeActorCtx(ctx);
|
|
31358
31573
|
try {
|
|
31359
31574
|
return encodeValue(
|
|
@@ -31422,6 +31637,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31422
31637
|
}
|
|
31423
31638
|
};
|
|
31424
31639
|
try {
|
|
31640
|
+
throwIfActorLost(runtime, ctx);
|
|
31425
31641
|
const connParams = validateConnParams(
|
|
31426
31642
|
schemaConfig.connParamsSchema,
|
|
31427
31643
|
rawConnParams ? JSON.parse(rawConnParams) : void 0
|
|
@@ -31456,6 +31672,11 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31456
31672
|
abortRequest
|
|
31457
31673
|
);
|
|
31458
31674
|
}
|
|
31675
|
+
if (callNativeSync(
|
|
31676
|
+
() => runtime.actorIsLost(ctx)
|
|
31677
|
+
)) {
|
|
31678
|
+
throw actorGenerationLostError();
|
|
31679
|
+
}
|
|
31459
31680
|
const response = await config3.onRequest(
|
|
31460
31681
|
requestCtx,
|
|
31461
31682
|
handlerRequest
|
|
@@ -31528,6 +31749,9 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31528
31749
|
const { ctx } = unwrapTsfnPayload(error46, payload);
|
|
31529
31750
|
const actorId = callNativeSync(() => runtime.actorId(ctx));
|
|
31530
31751
|
const executeRun = async () => {
|
|
31752
|
+
if (callNativeSync(() => runtime.actorIsLost(ctx))) {
|
|
31753
|
+
return;
|
|
31754
|
+
}
|
|
31531
31755
|
const actorCtx = makeActorCtx(ctx);
|
|
31532
31756
|
try {
|
|
31533
31757
|
await run(actorCtx);
|
|
@@ -31541,7 +31765,8 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31541
31765
|
() => callNativeSync(
|
|
31542
31766
|
() => runtime.actorRestartRunHandler(ctx)
|
|
31543
31767
|
),
|
|
31544
|
-
executeRun
|
|
31768
|
+
executeRun,
|
|
31769
|
+
callNativeSync(() => runtime.actorGeneration(ctx))
|
|
31545
31770
|
);
|
|
31546
31771
|
return outcome !== "suppressed";
|
|
31547
31772
|
}
|
|
@@ -31581,14 +31806,16 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31581
31806
|
const actorCtx = conn != null ? makeConnCtx(ctx, conn, void 0, cancelToken) : makeActorCtx(ctx, void 0, cancelToken);
|
|
31582
31807
|
const runAction = async () => {
|
|
31583
31808
|
try {
|
|
31809
|
+
const validatedArgs = validateActionArgs(
|
|
31810
|
+
schemaConfig.actionInputSchemas,
|
|
31811
|
+
name,
|
|
31812
|
+
decodeArgs(args)
|
|
31813
|
+
);
|
|
31814
|
+
throwIfActorLost(runtime, ctx);
|
|
31584
31815
|
return encodeValue(
|
|
31585
31816
|
await handler(
|
|
31586
31817
|
actorCtx,
|
|
31587
|
-
...
|
|
31588
|
-
schemaConfig.actionInputSchemas,
|
|
31589
|
-
name,
|
|
31590
|
-
decodeArgs(args)
|
|
31591
|
-
),
|
|
31818
|
+
...validatedArgs,
|
|
31592
31819
|
...scheduledFire ? [scheduledFire] : []
|
|
31593
31820
|
)
|
|
31594
31821
|
);
|
|
@@ -31644,6 +31871,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31644
31871
|
if (canPublish && !await canPublish(actorCtx)) {
|
|
31645
31872
|
throw forbiddenError();
|
|
31646
31873
|
}
|
|
31874
|
+
throwIfActorLost(runtime, ctx);
|
|
31647
31875
|
const decodedBody = decodeValue(body);
|
|
31648
31876
|
if (wait) {
|
|
31649
31877
|
try {
|
|
@@ -31687,7 +31915,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
31687
31915
|
)
|
|
31688
31916
|
};
|
|
31689
31917
|
return runtime.createActorFactory(
|
|
31690
|
-
callbacks,
|
|
31918
|
+
refuseCallbacksAfterLost(runtime, callbacks),
|
|
31691
31919
|
buildActorConfig(definition, registryConfig, runtime.kind)
|
|
31692
31920
|
);
|
|
31693
31921
|
}
|