rivetkit 2.3.0-rc.10 → 2.3.0-rc.11
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/browser/client.d.ts +105 -56
- package/dist/browser/client.js +128 -87
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +40 -20
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/agent-os/index.cjs +2103 -2090
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +106 -66
- package/dist/tsup/agent-os/index.d.ts +106 -66
- package/dist/tsup/agent-os/index.js +2102 -2089
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-4K3MV2MW.cjs → chunk-2NXFKPRB.cjs} +10 -10
- package/dist/tsup/chunk-2NXFKPRB.cjs.map +1 -0
- package/dist/tsup/{chunk-6BI2MS3S.js → chunk-3P2JUHWJ.js} +2 -2
- package/dist/tsup/{chunk-KU6VKVEK.js → chunk-4FP4FFB5.js} +18 -6
- package/dist/tsup/chunk-4FP4FFB5.js.map +1 -0
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-BRP62GZC.js} +3 -3
- package/dist/tsup/chunk-BRP62GZC.js.map +1 -0
- package/dist/tsup/{chunk-G34LIR7S.js → chunk-GRFBV2U7.js} +22 -7
- package/dist/tsup/chunk-GRFBV2U7.js.map +1 -0
- package/dist/tsup/{chunk-PWFGP2US.cjs → chunk-GX6W4MW3.cjs} +138 -24
- package/dist/tsup/chunk-GX6W4MW3.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-HXUEHHJF.js} +2 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-KORQB2IR.cjs} +3 -3
- package/dist/tsup/{chunk-QAZLM4WT.cjs.map → chunk-KORQB2IR.cjs.map} +1 -1
- package/dist/tsup/{chunk-BM3EOY7M.js → chunk-KRC4L3YB.js} +134 -20
- package/dist/tsup/chunk-KRC4L3YB.js.map +1 -0
- package/dist/tsup/{chunk-G5RULGYQ.cjs → chunk-LNP7Q6I6.cjs} +24 -9
- package/dist/tsup/chunk-LNP7Q6I6.cjs.map +1 -0
- package/dist/tsup/{chunk-Z4C3W2CQ.cjs → chunk-LW5HNCWD.cjs} +3 -3
- package/dist/tsup/{chunk-Z4C3W2CQ.cjs.map → chunk-LW5HNCWD.cjs.map} +1 -1
- package/dist/tsup/{chunk-J5P6S2LC.cjs → chunk-RDBGKI66.cjs} +25 -13
- package/dist/tsup/chunk-RDBGKI66.cjs.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-T3VCJ4PV.js} +3 -1
- package/dist/tsup/chunk-T3VCJ4PV.js.map +1 -0
- package/dist/tsup/{chunk-WU2O2KIE.js → chunk-TTLUIDVH.js} +61 -77
- package/dist/tsup/chunk-TTLUIDVH.js.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-VE2X4KMG.cjs} +2 -2
- package/dist/tsup/{chunk-LD5YASJU.cjs.map → chunk-VE2X4KMG.cjs.map} +1 -1
- package/dist/tsup/{chunk-XV52XUWU.js → chunk-WXYWDLJY.js} +4 -4
- package/dist/tsup/chunk-WXYWDLJY.js.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-XCDCURZ4.cjs} +4 -2
- package/dist/tsup/chunk-XCDCURZ4.cjs.map +1 -0
- package/dist/tsup/{chunk-TE4VCDNY.cjs → chunk-XG25CGSW.cjs} +217 -233
- package/dist/tsup/chunk-XG25CGSW.cjs.map +1 -0
- package/dist/tsup/{chunk-3LGP4JSO.cjs → chunk-Y3JBOFBG.cjs} +8 -8
- package/dist/tsup/{chunk-3LGP4JSO.cjs.map → chunk-Y3JBOFBG.cjs.map} +1 -1
- package/dist/tsup/{chunk-CMYS77J6.js → chunk-YRQ4F5CD.js} +3 -3
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +4 -4
- package/dist/tsup/client/mod.d.ts +4 -4
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-Ca8dN4cS.d.cts → config-CTwe3WwC.d.cts} +69 -19
- package/dist/tsup/{config-CxjGYf4K.d.cts → config-D49x8NpL.d.cts} +1 -2
- package/dist/tsup/{config-CxjGYf4K.d.ts → config-D49x8NpL.d.ts} +1 -2
- package/dist/tsup/{config-0Ta55UV0.d.ts → config-De5UVu0V.d.ts} +69 -19
- package/dist/tsup/{context-B_IWbWne.d.ts → context-DPHISlUi.d.ts} +8 -8
- package/dist/tsup/{context-CUrQ9MHc.d.cts → context-Dmj477Uh.d.cts} +8 -8
- package/dist/tsup/db/drizzle.cjs +3 -3
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +501 -315
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +405 -219
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +3 -3
- package/dist/tsup/test/mod.d.ts +3 -3
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +307 -282
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +5 -5
- package/dist/tsup/workflow/mod.d.ts +5 -5
- package/dist/tsup/workflow/mod.js +501 -476
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +22 -11
- package/src/actor/config.ts +48 -41
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +11 -14
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +9 -3
- package/src/actor/instance/mod.ts +22 -30
- package/src/actor/keys.ts +1 -1
- package/src/actor/mod.ts +20 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/client/actor-common.ts +90 -54
- package/src/client/actor-conn.ts +8 -36
- package/src/client/actor-handle.ts +67 -50
- package/src/client/actor-query.ts +5 -5
- package/src/client/errors.ts +1 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +8 -6
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +2 -7
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/transport/v1.ts +659 -543
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +2 -8
- package/src/common/database/native-database.ts +1 -1
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +1 -0
- package/src/common/router.ts +13 -17
- package/src/common/utils.ts +0 -149
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/mod.ts +1 -1
- package/src/drivers/engine/actor-driver.ts +63 -72
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +1 -1
- package/src/engine-client/actor-websocket-client.ts +6 -5
- package/src/engine-client/api-endpoints.ts +47 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +1 -1
- package/src/engine-client/mod.ts +6 -3
- package/src/engine-client/ws-proxy.ts +4 -4
- package/src/inspector/client.browser.ts +5 -11
- package/src/inspector/mod.ts +1 -3
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +7 -7
- package/src/registry/index.ts +70 -71
- package/src/registry/napi-runtime.ts +7 -2
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +179 -153
- package/src/registry/process-metrics.ts +238 -0
- package/src/registry/runtime.ts +1 -3
- package/src/registry/wasm-runtime.ts +3 -2
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +11 -8
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/router.ts +1 -1
- package/src/utils/serve.ts +4 -5
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +61 -33
- package/src/workflow/driver.ts +4 -6
- package/src/workflow/inspector.ts +4 -3
- package/src/workflow/mod.ts +15 -17
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-4K3MV2MW.cjs.map +0 -1
- package/dist/tsup/chunk-BM3EOY7M.js.map +0 -1
- package/dist/tsup/chunk-G34LIR7S.js.map +0 -1
- package/dist/tsup/chunk-G5RULGYQ.cjs.map +0 -1
- package/dist/tsup/chunk-J5P6S2LC.cjs.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-KU6VKVEK.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-PWFGP2US.cjs.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-TE4VCDNY.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/chunk-WU2O2KIE.js.map +0 -1
- package/dist/tsup/chunk-XV52XUWU.js.map +0 -1
- /package/dist/tsup/{chunk-6BI2MS3S.js.map → chunk-3P2JUHWJ.js.map} +0 -0
- /package/dist/tsup/{chunk-CMYS77J6.js.map → chunk-YRQ4F5CD.js.map} +0 -0
package/src/registry/native.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CONN_STATE_MANAGER_SYMBOL,
|
|
5
5
|
getRunFunction,
|
|
6
6
|
getRunInspectorConfig,
|
|
7
|
+
RAW_STATE_SYMBOL,
|
|
7
8
|
type WorkflowInspectorConfig,
|
|
8
9
|
} from "@/actor/config";
|
|
9
10
|
import type { AnyActorDefinition } from "@/actor/definition";
|
|
@@ -32,6 +33,7 @@ import { convertRegistryConfigToClientConfig } from "@/client/config";
|
|
|
32
33
|
import { HEADER_CONN_PARAMS } from "@/common/actor-router-consts";
|
|
33
34
|
import type { AnyDatabaseProvider } from "@/common/database/config";
|
|
34
35
|
import { wrapJsNativeDatabase } from "@/common/database/native-database";
|
|
36
|
+
import { assertJsonCompatValue, type JsonCompatValue } from "@/common/encoding";
|
|
35
37
|
import { decodeWorkflowHistoryTransport } from "@/common/inspector-transport";
|
|
36
38
|
import { deconstructError, stringifyError } from "@/common/utils";
|
|
37
39
|
import type {
|
|
@@ -49,7 +51,6 @@ import type {
|
|
|
49
51
|
} from "@/registry/config";
|
|
50
52
|
import {
|
|
51
53
|
decodeCborCompat,
|
|
52
|
-
decodeCborJsonCompat,
|
|
53
54
|
encodeCborCompat,
|
|
54
55
|
} from "@/serde";
|
|
55
56
|
import { getEnvUniversal, VERSION } from "@/utils";
|
|
@@ -79,6 +80,7 @@ import type {
|
|
|
79
80
|
WebSocketHandle,
|
|
80
81
|
} from "./runtime";
|
|
81
82
|
import { loadWasmRuntime } from "./wasm-runtime";
|
|
83
|
+
import { createWriteThroughProxy } from "./write-through-proxy";
|
|
82
84
|
|
|
83
85
|
const textEncoder = new TextEncoder();
|
|
84
86
|
const textDecoder = new TextDecoder();
|
|
@@ -345,6 +347,15 @@ function databaseNotConfiguredError(): RivetError {
|
|
|
345
347
|
);
|
|
346
348
|
}
|
|
347
349
|
|
|
350
|
+
function databaseClientNotReadyError(): RivetError {
|
|
351
|
+
return new RivetError(
|
|
352
|
+
"actor",
|
|
353
|
+
"database_client_not_ready",
|
|
354
|
+
"actor database client was not initialized before user code ran. this is an internal lifecycle error; the migration callback should have pre-warmed the client. file an issue if you can reproduce.",
|
|
355
|
+
{ public: true },
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
348
359
|
function stateNotEnabledError(): RivetError {
|
|
349
360
|
return new RivetError(
|
|
350
361
|
"actor",
|
|
@@ -587,11 +598,11 @@ function decodeValue<T>(value?: RuntimeBytes | null): T {
|
|
|
587
598
|
return undefined as T;
|
|
588
599
|
}
|
|
589
600
|
|
|
590
|
-
return
|
|
601
|
+
return decodeCborCompat(value);
|
|
591
602
|
}
|
|
592
603
|
|
|
593
604
|
function encodeValue(value: unknown): RuntimeBytes {
|
|
594
|
-
return encodeCborCompat(value);
|
|
605
|
+
return encodeCborCompat(value as JsonCompatValue);
|
|
595
606
|
}
|
|
596
607
|
|
|
597
608
|
function unwrapTsfnPayload<T>(error: unknown, payload: T): T {
|
|
@@ -924,6 +935,7 @@ function serializeWorkflowEntryKind(
|
|
|
924
935
|
}
|
|
925
936
|
}
|
|
926
937
|
|
|
938
|
+
// TODO: Switch inspector routes to CBOR encoding
|
|
927
939
|
function serializeWorkflowHistoryForJson(data: ArrayBuffer | null): {
|
|
928
940
|
nameRegistry: string[];
|
|
929
941
|
entries: Array<{
|
|
@@ -957,7 +969,7 @@ function serializeWorkflowHistoryForJson(data: ArrayBuffer | null): {
|
|
|
957
969
|
|
|
958
970
|
const history = decodeWorkflowHistoryTransport(data);
|
|
959
971
|
|
|
960
|
-
return {
|
|
972
|
+
return jsonSafe({
|
|
961
973
|
nameRegistry: [...history.nameRegistry],
|
|
962
974
|
entries: history.entries.map((entry) => ({
|
|
963
975
|
id: entry.id,
|
|
@@ -987,7 +999,7 @@ function serializeWorkflowHistoryForJson(data: ArrayBuffer | null): {
|
|
|
987
999
|
],
|
|
988
1000
|
),
|
|
989
1001
|
),
|
|
990
|
-
};
|
|
1002
|
+
});
|
|
991
1003
|
}
|
|
992
1004
|
|
|
993
1005
|
function toHttpJsonCompatible<T>(value: T): T {
|
|
@@ -1066,55 +1078,6 @@ function decodeArgs(value?: RuntimeBytes | null): unknown[] {
|
|
|
1066
1078
|
: [decoded];
|
|
1067
1079
|
}
|
|
1068
1080
|
|
|
1069
|
-
function createWriteThroughProxy<T>(
|
|
1070
|
-
value: T,
|
|
1071
|
-
commit: (next: T) => void,
|
|
1072
|
-
beforeChange?: () => void,
|
|
1073
|
-
): T {
|
|
1074
|
-
if (!value || typeof value !== "object") {
|
|
1075
|
-
return value;
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
const proxies = new WeakMap<object, object>();
|
|
1079
|
-
const wrap = (target: object): object => {
|
|
1080
|
-
const cached = proxies.get(target);
|
|
1081
|
-
if (cached) {
|
|
1082
|
-
return cached;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
const proxy = new Proxy(target, {
|
|
1086
|
-
get(innerTarget, property, receiver) {
|
|
1087
|
-
const result = Reflect.get(innerTarget, property, receiver);
|
|
1088
|
-
return result && typeof result === "object"
|
|
1089
|
-
? wrap(result as object)
|
|
1090
|
-
: result;
|
|
1091
|
-
},
|
|
1092
|
-
set(innerTarget, property, nextValue, receiver) {
|
|
1093
|
-
beforeChange?.();
|
|
1094
|
-
const updated = Reflect.set(
|
|
1095
|
-
innerTarget,
|
|
1096
|
-
property,
|
|
1097
|
-
nextValue,
|
|
1098
|
-
receiver,
|
|
1099
|
-
);
|
|
1100
|
-
commit(value);
|
|
1101
|
-
return updated;
|
|
1102
|
-
},
|
|
1103
|
-
deleteProperty(innerTarget, property) {
|
|
1104
|
-
beforeChange?.();
|
|
1105
|
-
const updated = Reflect.deleteProperty(innerTarget, property);
|
|
1106
|
-
commit(value);
|
|
1107
|
-
return updated;
|
|
1108
|
-
},
|
|
1109
|
-
});
|
|
1110
|
-
|
|
1111
|
-
proxies.set(target, proxy);
|
|
1112
|
-
return proxy;
|
|
1113
|
-
};
|
|
1114
|
-
|
|
1115
|
-
return wrap(value as object) as T;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
1081
|
function buildRequest(init: {
|
|
1119
1082
|
method: string;
|
|
1120
1083
|
uri: string;
|
|
@@ -1204,14 +1167,25 @@ class NativeConnAdapter {
|
|
|
1204
1167
|
);
|
|
1205
1168
|
}
|
|
1206
1169
|
|
|
1170
|
+
[RAW_STATE_SYMBOL](): unknown {
|
|
1171
|
+
return this.#readState();
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1207
1174
|
get state(): unknown {
|
|
1208
1175
|
const nextState = this.#readState();
|
|
1209
|
-
return createWriteThroughProxy(
|
|
1210
|
-
|
|
1211
|
-
|
|
1176
|
+
return createWriteThroughProxy(
|
|
1177
|
+
nextState,
|
|
1178
|
+
(nextValue) => {
|
|
1179
|
+
this.#writeState(nextValue, { writeNative: true });
|
|
1180
|
+
},
|
|
1181
|
+
(newValue) => {
|
|
1182
|
+
assertJsonCompatValue(newValue);
|
|
1183
|
+
},
|
|
1184
|
+
);
|
|
1212
1185
|
}
|
|
1213
1186
|
|
|
1214
1187
|
set state(value: unknown) {
|
|
1188
|
+
assertJsonCompatValue(value);
|
|
1215
1189
|
this.#writeState(value, { writeNative: true });
|
|
1216
1190
|
}
|
|
1217
1191
|
|
|
@@ -1683,7 +1657,12 @@ class NativeQueueAdapter {
|
|
|
1683
1657
|
signal?: AbortSignal;
|
|
1684
1658
|
},
|
|
1685
1659
|
) {
|
|
1686
|
-
|
|
1660
|
+
const { token, cleanup } = await createCancellationTokenHandle(
|
|
1661
|
+
this.#runtime,
|
|
1662
|
+
options?.signal,
|
|
1663
|
+
);
|
|
1664
|
+
|
|
1665
|
+
try {
|
|
1687
1666
|
await callNative(() =>
|
|
1688
1667
|
this.#runtime.actorQueueWaitForNamesAvailable(
|
|
1689
1668
|
this.#ctx,
|
|
@@ -1691,57 +1670,11 @@ class NativeQueueAdapter {
|
|
|
1691
1670
|
{
|
|
1692
1671
|
timeoutMs: options?.timeout,
|
|
1693
1672
|
},
|
|
1673
|
+
token,
|
|
1694
1674
|
),
|
|
1695
1675
|
);
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
const deadline =
|
|
1700
|
-
options.timeout === undefined
|
|
1701
|
-
? undefined
|
|
1702
|
-
: Date.now() + options.timeout;
|
|
1703
|
-
|
|
1704
|
-
for (;;) {
|
|
1705
|
-
if (options.signal.aborted) {
|
|
1706
|
-
throw actorAbortedError();
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
const remainingTimeout =
|
|
1710
|
-
deadline === undefined
|
|
1711
|
-
? undefined
|
|
1712
|
-
: Math.max(0, deadline - Date.now());
|
|
1713
|
-
const sliceTimeout =
|
|
1714
|
-
remainingTimeout === undefined
|
|
1715
|
-
? 100
|
|
1716
|
-
: Math.min(remainingTimeout, 100);
|
|
1717
|
-
|
|
1718
|
-
try {
|
|
1719
|
-
await callNative(() =>
|
|
1720
|
-
this.#runtime.actorQueueWaitForNamesAvailable(
|
|
1721
|
-
this.#ctx,
|
|
1722
|
-
[...names],
|
|
1723
|
-
{
|
|
1724
|
-
timeoutMs: sliceTimeout,
|
|
1725
|
-
},
|
|
1726
|
-
),
|
|
1727
|
-
);
|
|
1728
|
-
return;
|
|
1729
|
-
} catch (error) {
|
|
1730
|
-
if (
|
|
1731
|
-
(error as { group?: string; code?: string }).group ===
|
|
1732
|
-
"queue" &&
|
|
1733
|
-
(error as { group?: string; code?: string }).code ===
|
|
1734
|
-
"timed_out"
|
|
1735
|
-
) {
|
|
1736
|
-
if (
|
|
1737
|
-
remainingTimeout === undefined ||
|
|
1738
|
-
remainingTimeout > 100
|
|
1739
|
-
) {
|
|
1740
|
-
continue;
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
throw error;
|
|
1744
|
-
}
|
|
1676
|
+
} finally {
|
|
1677
|
+
cleanup?.();
|
|
1745
1678
|
}
|
|
1746
1679
|
}
|
|
1747
1680
|
|
|
@@ -2323,6 +2256,104 @@ class TrackedWebSocketHandleAdapter implements UniversalWebSocket {
|
|
|
2323
2256
|
}
|
|
2324
2257
|
}
|
|
2325
2258
|
|
|
2259
|
+
class NativeConnectionMap implements ReadonlyMap<string, NativeConnAdapter> {
|
|
2260
|
+
#runtime: CoreRuntime;
|
|
2261
|
+
#ctx: ActorContextHandle;
|
|
2262
|
+
#schemas: NativeValidationConfig;
|
|
2263
|
+
|
|
2264
|
+
constructor(
|
|
2265
|
+
runtime: CoreRuntime,
|
|
2266
|
+
ctx: ActorContextHandle,
|
|
2267
|
+
schemas: NativeValidationConfig,
|
|
2268
|
+
) {
|
|
2269
|
+
this.#runtime = runtime;
|
|
2270
|
+
this.#ctx = ctx;
|
|
2271
|
+
this.#schemas = schemas;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
#connToAdapter(conn: ConnHandle): NativeConnAdapter {
|
|
2275
|
+
return new NativeConnAdapter(
|
|
2276
|
+
this.#runtime,
|
|
2277
|
+
conn,
|
|
2278
|
+
this.#schemas,
|
|
2279
|
+
this.#ctx,
|
|
2280
|
+
(connId) =>
|
|
2281
|
+
callNativeSync(() =>
|
|
2282
|
+
this.#runtime.actorQueueHibernationRemoval(
|
|
2283
|
+
this.#ctx,
|
|
2284
|
+
connId,
|
|
2285
|
+
),
|
|
2286
|
+
),
|
|
2287
|
+
);
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
get size(): number {
|
|
2291
|
+
return callNativeSync(() => this.#runtime.actorConns(this.#ctx)).length;
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
get(key: string): NativeConnAdapter | undefined {
|
|
2295
|
+
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
2296
|
+
const conn = conns.find((c) => this.#runtime.connId(c) === key);
|
|
2297
|
+
if (!conn) return undefined;
|
|
2298
|
+
return this.#connToAdapter(conn);
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
has(key: string): boolean {
|
|
2302
|
+
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
2303
|
+
return conns.some((c) => this.#runtime.connId(c) === key);
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
keys(): MapIterator<string> {
|
|
2307
|
+
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
2308
|
+
return conns
|
|
2309
|
+
.map((c) => this.#runtime.connId(c))
|
|
2310
|
+
[Symbol.iterator]() satisfies MapIterator<string>;
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
values(): MapIterator<NativeConnAdapter> {
|
|
2314
|
+
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
2315
|
+
return conns
|
|
2316
|
+
.map((c) => this.#connToAdapter(c))
|
|
2317
|
+
[Symbol.iterator]() satisfies MapIterator<NativeConnAdapter>;
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
entries(): MapIterator<[string, NativeConnAdapter]> {
|
|
2321
|
+
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
2322
|
+
return conns
|
|
2323
|
+
.map(
|
|
2324
|
+
(c) =>
|
|
2325
|
+
[this.#runtime.connId(c), this.#connToAdapter(c)] as [
|
|
2326
|
+
string,
|
|
2327
|
+
NativeConnAdapter,
|
|
2328
|
+
],
|
|
2329
|
+
)
|
|
2330
|
+
[Symbol.iterator]() satisfies MapIterator<
|
|
2331
|
+
[string, NativeConnAdapter]
|
|
2332
|
+
>;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
forEach(
|
|
2336
|
+
callback: (
|
|
2337
|
+
value: NativeConnAdapter,
|
|
2338
|
+
key: string,
|
|
2339
|
+
map: ReadonlyMap<string, NativeConnAdapter>,
|
|
2340
|
+
) => void,
|
|
2341
|
+
thisArg?: unknown,
|
|
2342
|
+
): void {
|
|
2343
|
+
const conns = callNativeSync(() => this.#runtime.actorConns(this.#ctx));
|
|
2344
|
+
for (const conn of conns) {
|
|
2345
|
+
const id = this.#runtime.connId(conn);
|
|
2346
|
+
callback.call(thisArg, this.#connToAdapter(conn), id, this);
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
[Symbol.iterator](): MapIterator<[string, NativeConnAdapter]> {
|
|
2351
|
+
return this.entries();
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
readonly [Symbol.toStringTag] = "NativeConnectionMap";
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2326
2357
|
export class ActorContextHandleAdapter {
|
|
2327
2358
|
#runtime: CoreRuntime;
|
|
2328
2359
|
#ctx: ActorContextHandle;
|
|
@@ -2331,9 +2362,9 @@ export class ActorContextHandleAdapter {
|
|
|
2331
2362
|
#abortSignalCleanup?: () => void;
|
|
2332
2363
|
#client?: AnyClient;
|
|
2333
2364
|
#clientFactory?: () => AnyClient;
|
|
2365
|
+
#connMap?: NativeConnectionMap;
|
|
2334
2366
|
#databaseProvider?: Exclude<AnyDatabaseProvider, undefined>;
|
|
2335
2367
|
#db?: unknown;
|
|
2336
|
-
#dbProxy?: unknown;
|
|
2337
2368
|
#dispatchCancelToken?: CancellationTokenHandle;
|
|
2338
2369
|
#kv?: NativeKvAdapter;
|
|
2339
2370
|
#queue?: NativeQueueAdapter;
|
|
@@ -2396,32 +2427,25 @@ export class ActorContextHandleAdapter {
|
|
|
2396
2427
|
throw databaseNotConfiguredError();
|
|
2397
2428
|
}
|
|
2398
2429
|
|
|
2399
|
-
if (
|
|
2400
|
-
this.#
|
|
2401
|
-
|
|
2402
|
-
{
|
|
2403
|
-
get: (_target, property) => {
|
|
2404
|
-
if (property === "then") {
|
|
2405
|
-
return undefined;
|
|
2406
|
-
}
|
|
2430
|
+
if (this.#db) {
|
|
2431
|
+
return this.#db;
|
|
2432
|
+
}
|
|
2407
2433
|
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
);
|
|
2414
|
-
if (typeof value !== "function") {
|
|
2415
|
-
return value;
|
|
2416
|
-
}
|
|
2417
|
-
return await value.apply(client, args);
|
|
2418
|
-
};
|
|
2419
|
-
},
|
|
2420
|
-
},
|
|
2421
|
-
);
|
|
2434
|
+
const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
|
|
2435
|
+
const cachedClient = runtimeState.databaseClient;
|
|
2436
|
+
if (cachedClient) {
|
|
2437
|
+
this.#db = cachedClient.client;
|
|
2438
|
+
return this.#db;
|
|
2422
2439
|
}
|
|
2423
2440
|
|
|
2424
|
-
|
|
2441
|
+
throw databaseClientNotReadyError();
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
[RAW_STATE_SYMBOL](): unknown {
|
|
2445
|
+
if (!this.#stateEnabled) {
|
|
2446
|
+
throw stateNotEnabledError();
|
|
2447
|
+
}
|
|
2448
|
+
return this.#readState();
|
|
2425
2449
|
}
|
|
2426
2450
|
|
|
2427
2451
|
get state(): unknown {
|
|
@@ -2444,8 +2468,9 @@ export class ActorContextHandleAdapter {
|
|
|
2444
2468
|
(nextValue) => {
|
|
2445
2469
|
this.#writeState(nextValue, { scheduleSave: true });
|
|
2446
2470
|
},
|
|
2447
|
-
() => {
|
|
2471
|
+
(newValue) => {
|
|
2448
2472
|
this.#assertCanMutateState();
|
|
2473
|
+
assertJsonCompatValue(newValue);
|
|
2449
2474
|
},
|
|
2450
2475
|
);
|
|
2451
2476
|
}
|
|
@@ -2457,6 +2482,7 @@ export class ActorContextHandleAdapter {
|
|
|
2457
2482
|
throw stateNotEnabledError();
|
|
2458
2483
|
}
|
|
2459
2484
|
this.#assertCanMutateState();
|
|
2485
|
+
assertJsonCompatValue(value);
|
|
2460
2486
|
this.#writeState(value, { scheduleSave: true });
|
|
2461
2487
|
}
|
|
2462
2488
|
|
|
@@ -2523,27 +2549,15 @@ export class ActorContextHandleAdapter {
|
|
|
2523
2549
|
return callNativeSync(() => this.#runtime.actorRegion(this.#ctx));
|
|
2524
2550
|
}
|
|
2525
2551
|
|
|
2526
|
-
get conns():
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
this.#ctx,
|
|
2536
|
-
(connId) =>
|
|
2537
|
-
callNativeSync(() =>
|
|
2538
|
-
this.#runtime.actorQueueHibernationRemoval(
|
|
2539
|
-
this.#ctx,
|
|
2540
|
-
connId,
|
|
2541
|
-
),
|
|
2542
|
-
),
|
|
2543
|
-
),
|
|
2544
|
-
],
|
|
2545
|
-
),
|
|
2546
|
-
);
|
|
2552
|
+
get conns(): ReadonlyMap<string, NativeConnAdapter> {
|
|
2553
|
+
if (!this.#connMap) {
|
|
2554
|
+
this.#connMap = new NativeConnectionMap(
|
|
2555
|
+
this.#runtime,
|
|
2556
|
+
this.#ctx,
|
|
2557
|
+
this.#schemas,
|
|
2558
|
+
);
|
|
2559
|
+
}
|
|
2560
|
+
return this.#connMap;
|
|
2547
2561
|
}
|
|
2548
2562
|
|
|
2549
2563
|
get log() {
|
|
@@ -3548,6 +3562,10 @@ export function buildNativeFactory(
|
|
|
3548
3562
|
getNativeWorkflowInspector(ctx) !== undefined,
|
|
3549
3563
|
});
|
|
3550
3564
|
} catch (error) {
|
|
3565
|
+
logger().error({
|
|
3566
|
+
msg: "error replaying workflow history",
|
|
3567
|
+
error,
|
|
3568
|
+
});
|
|
3551
3569
|
return errorResponse(error);
|
|
3552
3570
|
}
|
|
3553
3571
|
}
|
|
@@ -3727,6 +3745,10 @@ export function buildNativeFactory(
|
|
|
3727
3745
|
);
|
|
3728
3746
|
return jsonResponse({ output });
|
|
3729
3747
|
} catch (error) {
|
|
3748
|
+
logger().error({
|
|
3749
|
+
msg: "Error handling inspector action request",
|
|
3750
|
+
error,
|
|
3751
|
+
});
|
|
3730
3752
|
return errorResponse(error);
|
|
3731
3753
|
}
|
|
3732
3754
|
}
|
|
@@ -3741,6 +3763,10 @@ export function buildNativeFactory(
|
|
|
3741
3763
|
{ status: 404 },
|
|
3742
3764
|
);
|
|
3743
3765
|
} catch (error) {
|
|
3766
|
+
logger().error({
|
|
3767
|
+
msg: "Error handling inspector request",
|
|
3768
|
+
error,
|
|
3769
|
+
});
|
|
3744
3770
|
return errorResponse(error);
|
|
3745
3771
|
} finally {
|
|
3746
3772
|
await actorCtx.dispose();
|