rivetkit 0.0.0-main.72cbc7c → 0.0.0-main.78336a1
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 +821 -80
- package/dist/browser/client.js +852 -670
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2079 -234
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +4 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +3 -1
- package/dist/tsup/agent-os/index.cjs +2420 -2093
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +821 -90
- package/dist/tsup/agent-os/index.d.ts +821 -90
- package/dist/tsup/agent-os/index.js +2405 -2078
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-2JSYYH6P.cjs} +22 -7
- package/dist/tsup/chunk-2JSYYH6P.cjs.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-4KGXFC6M.cjs} +232 -18
- package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
- package/dist/tsup/{chunk-GDKM56PU.js → chunk-5NBLGMI2.js} +488 -16
- package/dist/tsup/chunk-5NBLGMI2.js.map +1 -0
- package/dist/tsup/{chunk-WDO5Y6PO.cjs → chunk-635UPRVQ.cjs} +18 -11
- package/dist/tsup/chunk-635UPRVQ.cjs.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-6W5VGLFT.js} +231 -17
- package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
- package/dist/tsup/{chunk-YQQ2ZDKT.cjs → chunk-AIL267JK.cjs} +525 -451
- package/dist/tsup/chunk-AIL267JK.cjs.map +1 -0
- package/dist/tsup/chunk-BHXSPZ5M.cjs +243 -0
- package/dist/tsup/chunk-BHXSPZ5M.cjs.map +1 -0
- package/dist/tsup/{chunk-O25KOT5C.cjs → chunk-EHZH3KUW.cjs} +497 -25
- package/dist/tsup/chunk-EHZH3KUW.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-JI6GZ2C2.js} +3 -12
- package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
- package/dist/tsup/chunk-JRHFO6UE.js +14 -0
- package/dist/tsup/chunk-JRHFO6UE.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-PJSE5ZGN.js → chunk-MIM5VMS6.js} +6 -6
- package/dist/tsup/chunk-MIM5VMS6.js.map +1 -0
- package/dist/tsup/chunk-MLT7XFEF.js +243 -0
- package/dist/tsup/chunk-MLT7XFEF.js.map +1 -0
- package/dist/tsup/{chunk-OFP533QU.cjs → chunk-MPEC2UFV.cjs} +3 -3
- package/dist/tsup/chunk-MPEC2UFV.cjs.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-MYWZCDML.cjs} +3 -12
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-OUQUIBVW.js} +21 -6
- package/dist/tsup/chunk-OUQUIBVW.js.map +1 -0
- package/dist/tsup/{chunk-HSTK7OBI.js → chunk-PUMX2WHE.js} +16 -9
- package/dist/tsup/chunk-PUMX2WHE.js.map +1 -0
- package/dist/tsup/{chunk-5DGOZZKE.cjs → chunk-Q6BQS3UL.cjs} +72 -10
- package/dist/tsup/chunk-Q6BQS3UL.cjs.map +1 -0
- package/dist/tsup/{chunk-OQSBGFIB.cjs → chunk-QAWP2MIM.cjs} +10 -10
- package/dist/tsup/chunk-QAWP2MIM.cjs.map +1 -0
- package/dist/tsup/{chunk-EI55QOUB.js → chunk-QU5UOJLK.js} +390 -316
- package/dist/tsup/chunk-QU5UOJLK.js.map +1 -0
- package/dist/tsup/chunk-TX5AVHTL.cjs +14 -0
- package/dist/tsup/chunk-TX5AVHTL.cjs.map +1 -0
- package/dist/tsup/{chunk-DFHHCPH7.js → chunk-XCSZTG4H.js} +70 -8
- package/dist/tsup/chunk-XCSZTG4H.js.map +1 -0
- package/dist/tsup/{chunk-4KSYSQHX.js → chunk-XKVQ3AMZ.js} +2 -2
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +8 -6
- package/dist/tsup/client/mod.d.ts +8 -6
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-voObiSep.d.cts → config-Ug5M2MOr.d.ts} +869 -59
- package/dist/tsup/{config-CxjGYf4K.d.ts → config-ey2I2zz5.d.cts} +59 -4
- package/dist/tsup/{config-CxjGYf4K.d.cts → config-ey2I2zz5.d.ts} +59 -4
- package/dist/tsup/{config-CRwCN3Ok.d.ts → config-gvHwMas-.d.cts} +869 -59
- package/dist/tsup/context-BSCBvbfM.d.cts +129 -0
- package/dist/tsup/context-DererUCI.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +127 -67
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +127 -67
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -124
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -123
- package/dist/tsup/db/mod.js.map +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 +38 -0
- package/dist/tsup/dynamic/mod.d.ts +38 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +241 -0
- package/dist/tsup/inspector-tab/mod.d.ts +241 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +2754 -607
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +8 -7
- package/dist/tsup/mod.d.ts +8 -7
- package/dist/tsup/mod.js +2688 -541
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -5
- package/dist/tsup/test/mod.d.ts +6 -5
- package/dist/tsup/test/mod.js +25 -20
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/utils-Bbz-3411.d.cts +162 -0
- package/dist/tsup/utils-BqdWVlzm.d.ts +162 -0
- package/dist/tsup/{utils-DVekpm4I.d.cts → utils-vvJQyygr.d.cts} +7 -1
- package/dist/tsup/{utils-DVekpm4I.d.ts → utils-vvJQyygr.d.ts} +7 -1
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +539 -424
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +10 -9
- package/dist/tsup/workflow/mod.d.ts +10 -9
- package/dist/tsup/workflow/mod.js +521 -406
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +63 -16
- package/src/actor/actions.ts +119 -0
- package/src/actor/config.test.ts +78 -0
- package/src/actor/config.ts +505 -88
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +38 -26
- package/src/actor/errors.ts +50 -5
- package/src/actor/keys.ts +1 -1
- package/src/actor/mod.ts +32 -21
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +39 -19
- 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 +80 -54
- package/src/client/actor-conn.ts +17 -41
- package/src/client/actor-handle.ts +140 -72
- package/src/client/actor-query.ts +13 -6
- package/src/client/client.ts +41 -11
- package/src/client/errors.ts +3 -2
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +36 -13
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/utils.ts +4 -7
- package/src/common/actor-router-consts.ts +2 -0
- 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/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +74 -9
- package/src/common/database/mod.test.ts +285 -58
- package/src/common/database/mod.ts +259 -77
- package/src/common/database/native-database.test.ts +9 -0
- package/src/common/database/native-database.ts +192 -2
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +278 -34
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +49 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +15 -8
- package/src/common/router.ts +13 -17
- package/src/common/utils.ts +7 -150
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.test.ts +164 -0
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +4 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +8 -24
- package/src/engine-client/actor-websocket-client.ts +6 -5
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +5 -16
- package/src/engine-client/mod.ts +66 -64
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.test.ts +25 -0
- package/src/registry/config/index.ts +68 -56
- package/src/registry/index.ts +588 -91
- package/src/registry/napi-runtime.ts +427 -23
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +1435 -459
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.test.ts +74 -0
- package/src/registry/runtime.ts +297 -9
- package/src/registry/wasm-runtime.ts +398 -22
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.test.ts +170 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +41 -0
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +683 -242
- package/src/workflow/driver.test.ts +62 -0
- package/src/workflow/driver.ts +259 -119
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-5DGOZZKE.cjs.map +0 -1
- package/dist/tsup/chunk-DFHHCPH7.js.map +0 -1
- package/dist/tsup/chunk-EI55QOUB.js.map +0 -1
- package/dist/tsup/chunk-GDKM56PU.js.map +0 -1
- package/dist/tsup/chunk-HSTK7OBI.js.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
- package/dist/tsup/chunk-LI5MR5BD.js +0 -268
- package/dist/tsup/chunk-LI5MR5BD.js.map +0 -1
- package/dist/tsup/chunk-NDY6IZJ3.cjs +0 -268
- package/dist/tsup/chunk-NDY6IZJ3.cjs.map +0 -1
- package/dist/tsup/chunk-O25KOT5C.cjs.map +0 -1
- package/dist/tsup/chunk-OFP533QU.cjs.map +0 -1
- package/dist/tsup/chunk-OQSBGFIB.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-PJSE5ZGN.js.map +0 -1
- package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-WDO5Y6PO.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/chunk-YQQ2ZDKT.cjs.map +0 -1
- package/dist/tsup/context-BPFYVZ5g.d.ts +0 -92
- package/dist/tsup/context-D0YF1MQq.d.cts +0 -92
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2492
- package/src/drivers/engine/actor-driver.ts +0 -2460
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-4KSYSQHX.js.map → chunk-XKVQ3AMZ.js.map} +0 -0
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ActorContext as WasmActorContext,
|
|
3
|
-
ActorFactory as WasmActorFactory,
|
|
4
|
-
CancellationToken as WasmCancellationToken,
|
|
5
|
-
ConnHandle as WasmConnHandle,
|
|
6
|
-
CoreRegistry as WasmCoreRegistry,
|
|
7
|
-
WebSocketHandle as WasmWebSocketHandle,
|
|
8
|
-
} from "@rivetkit/rivetkit-wasm";
|
|
9
1
|
import { decodeBridgeRivetError, RivetError } from "@/actor/errors";
|
|
10
2
|
import type {
|
|
11
3
|
WasmRuntimeBindings,
|
|
@@ -15,28 +7,36 @@ import type {
|
|
|
15
7
|
import type {
|
|
16
8
|
ActorContextHandle,
|
|
17
9
|
ActorFactoryHandle,
|
|
10
|
+
ActorStateTransactionHandle,
|
|
18
11
|
CancellationTokenHandle,
|
|
19
12
|
ConnHandle,
|
|
20
13
|
CoreRuntime,
|
|
21
14
|
RegistryHandle,
|
|
22
15
|
RuntimeActorConfig,
|
|
23
16
|
RuntimeActorKeySegment,
|
|
17
|
+
RuntimeApplicationListenerConfig,
|
|
24
18
|
RuntimeBytes,
|
|
19
|
+
RuntimeCronFire,
|
|
20
|
+
RuntimeCronJobInfo,
|
|
25
21
|
RuntimeHttpRequest,
|
|
26
22
|
RuntimeInspectorSnapshot,
|
|
27
23
|
RuntimeKvEntry,
|
|
28
24
|
RuntimeKvListOptions,
|
|
25
|
+
RuntimeListenerConfig,
|
|
29
26
|
RuntimeQueueEnqueueAndWaitOptions,
|
|
30
27
|
RuntimeQueueInspectMessage,
|
|
31
28
|
RuntimeQueueMessage,
|
|
32
29
|
RuntimeQueueNextBatchOptions,
|
|
33
30
|
RuntimeQueueTryNextBatchOptions,
|
|
34
31
|
RuntimeQueueWaitOptions,
|
|
32
|
+
RuntimeRegistryRouteResponse,
|
|
35
33
|
RuntimeRequestSaveOpts,
|
|
34
|
+
RuntimeScheduledEventInfo,
|
|
36
35
|
RuntimeServeConfig,
|
|
37
36
|
RuntimeServerlessRequest,
|
|
38
37
|
RuntimeServerlessResponseHead,
|
|
39
38
|
RuntimeServerlessStreamCallback,
|
|
39
|
+
RuntimeSqlBatchStatement,
|
|
40
40
|
RuntimeSqlBindParams,
|
|
41
41
|
RuntimeSqlDatabase,
|
|
42
42
|
RuntimeSqlExecResult,
|
|
@@ -45,6 +45,8 @@ import type {
|
|
|
45
45
|
RuntimeSqlRunResult,
|
|
46
46
|
RuntimeStateDeltaPayload,
|
|
47
47
|
RuntimeWebSocketEvent,
|
|
48
|
+
RuntimeWorkflowKvWrite,
|
|
49
|
+
SqliteTransactionHandle,
|
|
48
50
|
WebSocketHandle,
|
|
49
51
|
} from "./runtime";
|
|
50
52
|
import { normalizeRuntimeSqlExecuteResult } from "./runtime";
|
|
@@ -53,6 +55,35 @@ type WasmBindings = WasmRuntimeBindings;
|
|
|
53
55
|
export type WasmInitInput = WasmRuntimeInitInput;
|
|
54
56
|
type AnyFunction = (...args: unknown[]) => unknown;
|
|
55
57
|
type WasmRuntimeLoadConfig = Pick<WasmRuntimeConfig, "bindings" | "initInput">;
|
|
58
|
+
type WasmActorContext = object;
|
|
59
|
+
type WasmActorFactory = object;
|
|
60
|
+
type WasmConnHandle = object;
|
|
61
|
+
type WasmWebSocketHandle = object;
|
|
62
|
+
|
|
63
|
+
interface WasmCancellationToken {
|
|
64
|
+
aborted(): boolean;
|
|
65
|
+
cancel(): void;
|
|
66
|
+
onCancelled(callback: (...args: unknown[]) => unknown): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface WasmCoreRegistry {
|
|
70
|
+
register(name: string, factory: WasmActorFactory): void;
|
|
71
|
+
serve(config: RuntimeServeConfig): Promise<void>;
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface WasmConstructors {
|
|
76
|
+
CoreRegistry: new () => WasmCoreRegistry;
|
|
77
|
+
ActorFactory: new (
|
|
78
|
+
callbacks: object,
|
|
79
|
+
config: RuntimeActorConfig | undefined | null,
|
|
80
|
+
) => WasmActorFactory;
|
|
81
|
+
CancellationToken: new () => WasmCancellationToken;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function asWasmConstructors(bindings: WasmBindings): WasmConstructors {
|
|
85
|
+
return bindings as unknown as WasmConstructors;
|
|
86
|
+
}
|
|
56
87
|
|
|
57
88
|
function asWasmRegistry(handle: RegistryHandle): WasmCoreRegistry {
|
|
58
89
|
return handle as unknown as WasmCoreRegistry;
|
|
@@ -226,11 +257,11 @@ function childHandle<T>(handle: unknown, name: string): T {
|
|
|
226
257
|
export class WasmCoreRuntime implements CoreRuntime {
|
|
227
258
|
readonly kind = "wasm";
|
|
228
259
|
|
|
229
|
-
#
|
|
260
|
+
#constructors: WasmConstructors;
|
|
230
261
|
#sql = new WeakMap<WasmActorContext, RuntimeSqlDatabase>();
|
|
231
262
|
|
|
232
263
|
constructor(bindings: WasmBindings) {
|
|
233
|
-
this.#
|
|
264
|
+
this.#constructors = asWasmConstructors(bindings);
|
|
234
265
|
}
|
|
235
266
|
|
|
236
267
|
#actorSql(ctx: ActorContextHandle): RuntimeSqlDatabase {
|
|
@@ -245,7 +276,7 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
245
276
|
|
|
246
277
|
createRegistry(): RegistryHandle {
|
|
247
278
|
return callWasmSync(() =>
|
|
248
|
-
asRegistryHandle(new this.#
|
|
279
|
+
asRegistryHandle(new this.#constructors.CoreRegistry()),
|
|
249
280
|
);
|
|
250
281
|
}
|
|
251
282
|
|
|
@@ -266,12 +297,28 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
266
297
|
await callWasm(() => asWasmRegistry(registry).serve(config));
|
|
267
298
|
}
|
|
268
299
|
|
|
300
|
+
async waitRegistryReady(): Promise<void> {
|
|
301
|
+
throw new Error(
|
|
302
|
+
"registry.startAndWait() is not supported by the WASM runtime",
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
269
306
|
async shutdownRegistry(registry: RegistryHandle): Promise<void> {
|
|
270
307
|
await callWasm(() => asWasmRegistry(registry).shutdown());
|
|
271
308
|
}
|
|
272
309
|
|
|
273
|
-
async
|
|
274
|
-
return {
|
|
310
|
+
async registryHealth(): Promise<RuntimeRegistryRouteResponse> {
|
|
311
|
+
return {
|
|
312
|
+
status: 200,
|
|
313
|
+
headers: { "content-type": "application/json" },
|
|
314
|
+
body: new TextEncoder().encode(
|
|
315
|
+
JSON.stringify({
|
|
316
|
+
status: "ok",
|
|
317
|
+
runtime: "rivetkit",
|
|
318
|
+
version: "wasm",
|
|
319
|
+
}),
|
|
320
|
+
),
|
|
321
|
+
};
|
|
275
322
|
}
|
|
276
323
|
|
|
277
324
|
async handleServerlessRequest(
|
|
@@ -291,13 +338,33 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
291
338
|
);
|
|
292
339
|
}
|
|
293
340
|
|
|
341
|
+
async serveListener(
|
|
342
|
+
_registry: RegistryHandle,
|
|
343
|
+
_listener: RuntimeListenerConfig,
|
|
344
|
+
_config: RuntimeServeConfig,
|
|
345
|
+
): Promise<void> {
|
|
346
|
+
throw new Error(
|
|
347
|
+
"registry.listen() is not supported on the wasm runtime; use registry.serve() and mount the handler in your platform's HTTP server instead",
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async serveApplicationListener(
|
|
352
|
+
_registry: RegistryHandle,
|
|
353
|
+
_listener: RuntimeApplicationListenerConfig,
|
|
354
|
+
_config: RuntimeServeConfig,
|
|
355
|
+
): Promise<void> {
|
|
356
|
+
throw new Error(
|
|
357
|
+
"registry.listen() is not supported on the wasm runtime; use an application-owned HTTP server instead",
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
294
361
|
createActorFactory(
|
|
295
362
|
callbacks: object,
|
|
296
363
|
config?: RuntimeActorConfig | undefined | null,
|
|
297
364
|
): ActorFactoryHandle {
|
|
298
365
|
return callWasmSync(() =>
|
|
299
366
|
asActorFactoryHandle(
|
|
300
|
-
new this.#
|
|
367
|
+
new this.#constructors.ActorFactory(callbacks, config),
|
|
301
368
|
),
|
|
302
369
|
);
|
|
303
370
|
}
|
|
@@ -305,7 +372,7 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
305
372
|
createCancellationToken(): CancellationTokenHandle {
|
|
306
373
|
return callWasmSync(
|
|
307
374
|
() =>
|
|
308
|
-
new this.#
|
|
375
|
+
new this.#constructors.CancellationToken() as unknown as CancellationTokenHandle,
|
|
309
376
|
);
|
|
310
377
|
}
|
|
311
378
|
|
|
@@ -354,6 +421,17 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
354
421
|
);
|
|
355
422
|
}
|
|
356
423
|
|
|
424
|
+
async actorSetRunWakeAt(
|
|
425
|
+
ctx: ActorContextHandle,
|
|
426
|
+
timestampMs?: number | undefined | null,
|
|
427
|
+
): Promise<void> {
|
|
428
|
+
await callHandleAsync(
|
|
429
|
+
asWasmActorContext(ctx),
|
|
430
|
+
"setRunWakeAt",
|
|
431
|
+
optionalWasmNumber(timestampMs),
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
357
435
|
actorRequestSave(
|
|
358
436
|
ctx: ActorContextHandle,
|
|
359
437
|
opts?: RuntimeRequestSaveOpts | undefined | null,
|
|
@@ -442,6 +520,17 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
442
520
|
await callHandleAsync(asWasmActorContext(ctx), "saveState", payload);
|
|
443
521
|
}
|
|
444
522
|
|
|
523
|
+
async actorSaveStateAndWorkflowBatch(
|
|
524
|
+
ctx: ActorContextHandle,
|
|
525
|
+
writes: RuntimeWorkflowKvWrite[],
|
|
526
|
+
): Promise<void> {
|
|
527
|
+
await callHandleAsync(
|
|
528
|
+
asWasmActorContext(ctx),
|
|
529
|
+
"saveStateAndWorkflowBatch",
|
|
530
|
+
writes,
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
445
534
|
actorId(ctx: ActorContextHandle): string {
|
|
446
535
|
return callHandle(asWasmActorContext(ctx), "actorId");
|
|
447
536
|
}
|
|
@@ -508,6 +597,15 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
508
597
|
);
|
|
509
598
|
}
|
|
510
599
|
|
|
600
|
+
async actorWaitForTrackedShutdownWorkUnbounded(
|
|
601
|
+
ctx: ActorContextHandle,
|
|
602
|
+
): Promise<void> {
|
|
603
|
+
await callHandle<Promise<void>>(
|
|
604
|
+
asWasmActorContext(ctx),
|
|
605
|
+
"waitForTrackedShutdownWorkUnbounded",
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
|
|
511
609
|
actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void {
|
|
512
610
|
const wasmCtx = asWasmActorContext(ctx);
|
|
513
611
|
const regionId = callHandle<number>(wasmCtx, "beginKeepAwake");
|
|
@@ -670,6 +768,130 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
670
768
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
671
769
|
}
|
|
672
770
|
|
|
771
|
+
async actorSqlExecuteBatch(
|
|
772
|
+
ctx: ActorContextHandle,
|
|
773
|
+
statements: RuntimeSqlBatchStatement[],
|
|
774
|
+
): Promise<RuntimeSqlExecuteResult[]> {
|
|
775
|
+
const results = await callWasm(() =>
|
|
776
|
+
this.#actorSql(ctx).executeBatch(statements),
|
|
777
|
+
);
|
|
778
|
+
return results.map(normalizeRuntimeSqlExecuteResult);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
async actorSqlBeginTransaction(
|
|
782
|
+
ctx: ActorContextHandle,
|
|
783
|
+
timeoutMs?: number,
|
|
784
|
+
name?: string,
|
|
785
|
+
): Promise<SqliteTransactionHandle> {
|
|
786
|
+
return (await callWasm(() =>
|
|
787
|
+
this.#actorSql(ctx).beginTransaction(timeoutMs, name),
|
|
788
|
+
)) as unknown as SqliteTransactionHandle;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
async actorSqlTransactionExec(
|
|
792
|
+
transaction: SqliteTransactionHandle,
|
|
793
|
+
sql: string,
|
|
794
|
+
): Promise<RuntimeSqlExecResult> {
|
|
795
|
+
return await callWasm(() =>
|
|
796
|
+
(
|
|
797
|
+
transaction as unknown as {
|
|
798
|
+
exec(sql: string): Promise<RuntimeSqlExecResult>;
|
|
799
|
+
}
|
|
800
|
+
).exec(sql),
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
async actorSqlTransactionExecute(
|
|
805
|
+
transaction: SqliteTransactionHandle,
|
|
806
|
+
sql: string,
|
|
807
|
+
params?: RuntimeSqlBindParams,
|
|
808
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
809
|
+
const result = await callWasm(() =>
|
|
810
|
+
(
|
|
811
|
+
transaction as unknown as {
|
|
812
|
+
execute(
|
|
813
|
+
sql: string,
|
|
814
|
+
params?: RuntimeSqlBindParams,
|
|
815
|
+
): Promise<RuntimeSqlExecuteResult>;
|
|
816
|
+
}
|
|
817
|
+
).execute(sql, params),
|
|
818
|
+
);
|
|
819
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
async actorSqlTransactionCommit(
|
|
823
|
+
transaction: SqliteTransactionHandle,
|
|
824
|
+
): Promise<void> {
|
|
825
|
+
await callWasm(() =>
|
|
826
|
+
(transaction as unknown as { commit(): Promise<void> }).commit(),
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
async actorSqlTransactionRollback(
|
|
831
|
+
transaction: SqliteTransactionHandle,
|
|
832
|
+
): Promise<void> {
|
|
833
|
+
await callWasm(() =>
|
|
834
|
+
(
|
|
835
|
+
transaction as unknown as { rollback(): Promise<void> }
|
|
836
|
+
).rollback(),
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
async actorBeginStateTransaction(
|
|
840
|
+
ctx: ActorContextHandle,
|
|
841
|
+
timeoutMs?: number,
|
|
842
|
+
): Promise<ActorStateTransactionHandle> {
|
|
843
|
+
return (await callWasm(() =>
|
|
844
|
+
(
|
|
845
|
+
asWasmActorContext(ctx) as unknown as {
|
|
846
|
+
beginStateTransaction(
|
|
847
|
+
timeoutMs?: number,
|
|
848
|
+
): Promise<ActorStateTransactionHandle>;
|
|
849
|
+
}
|
|
850
|
+
).beginStateTransaction(timeoutMs),
|
|
851
|
+
)) as ActorStateTransactionHandle;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
async actorStateTransactionExecute(
|
|
855
|
+
transaction: ActorStateTransactionHandle,
|
|
856
|
+
sql: string,
|
|
857
|
+
params?: RuntimeSqlBindParams,
|
|
858
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
859
|
+
const result = await callWasm(() =>
|
|
860
|
+
(
|
|
861
|
+
transaction as unknown as {
|
|
862
|
+
execute(
|
|
863
|
+
sql: string,
|
|
864
|
+
params?: RuntimeSqlBindParams,
|
|
865
|
+
): Promise<RuntimeSqlExecuteResult>;
|
|
866
|
+
}
|
|
867
|
+
).execute(sql, params),
|
|
868
|
+
);
|
|
869
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
async actorStateTransactionCommit(
|
|
873
|
+
transaction: ActorStateTransactionHandle,
|
|
874
|
+
payload: RuntimeStateDeltaPayload,
|
|
875
|
+
): Promise<void> {
|
|
876
|
+
await callWasm(() =>
|
|
877
|
+
(
|
|
878
|
+
transaction as unknown as {
|
|
879
|
+
commit(payload: RuntimeStateDeltaPayload): Promise<void>;
|
|
880
|
+
}
|
|
881
|
+
).commit(payload),
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
async actorStateTransactionRollback(
|
|
886
|
+
transaction: ActorStateTransactionHandle,
|
|
887
|
+
): Promise<void> {
|
|
888
|
+
await callWasm(() =>
|
|
889
|
+
(
|
|
890
|
+
transaction as unknown as { rollback(): Promise<void> }
|
|
891
|
+
).rollback(),
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
|
|
673
895
|
async actorSqlQuery(
|
|
674
896
|
ctx: ActorContextHandle,
|
|
675
897
|
sql: string,
|
|
@@ -705,6 +927,20 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
705
927
|
await callWasm(() => database.close());
|
|
706
928
|
}
|
|
707
929
|
|
|
930
|
+
async actorRuntimeSocketProvision(
|
|
931
|
+
_ctx: ActorContextHandle,
|
|
932
|
+
): Promise<never> {
|
|
933
|
+
throw new RivetError(
|
|
934
|
+
"actor_runtime_socket",
|
|
935
|
+
"unsupported",
|
|
936
|
+
"Actor Runtime Socket is only available on Unix native runtimes.",
|
|
937
|
+
{
|
|
938
|
+
public: true,
|
|
939
|
+
metadata: { runtime: "wasm" },
|
|
940
|
+
},
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
|
|
708
944
|
async actorQueueSend(
|
|
709
945
|
ctx: ActorContextHandle,
|
|
710
946
|
name: string,
|
|
@@ -753,9 +989,32 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
753
989
|
ctx: ActorContextHandle,
|
|
754
990
|
names: string[],
|
|
755
991
|
options?: RuntimeQueueWaitOptions | undefined | null,
|
|
992
|
+
signal?: CancellationTokenHandle | undefined | null,
|
|
756
993
|
): Promise<void> {
|
|
757
994
|
const queue = childHandle(asWasmActorContext(ctx), "queue");
|
|
758
|
-
await callHandleAsync(
|
|
995
|
+
await callHandleAsync(
|
|
996
|
+
queue,
|
|
997
|
+
"waitForNamesAvailable",
|
|
998
|
+
names,
|
|
999
|
+
options,
|
|
1000
|
+
signal,
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
async actorQueueCompletePersisted(
|
|
1005
|
+
ctx: ActorContextHandle,
|
|
1006
|
+
messageId: bigint,
|
|
1007
|
+
expectedName: string,
|
|
1008
|
+
response?: RuntimeBytes | undefined | null,
|
|
1009
|
+
): Promise<boolean> {
|
|
1010
|
+
const queue = childHandle(asWasmActorContext(ctx), "queue");
|
|
1011
|
+
return await callHandleAsync(
|
|
1012
|
+
queue,
|
|
1013
|
+
"completePersisted",
|
|
1014
|
+
messageId,
|
|
1015
|
+
expectedName,
|
|
1016
|
+
response,
|
|
1017
|
+
);
|
|
759
1018
|
}
|
|
760
1019
|
|
|
761
1020
|
async actorQueueEnqueueAndWait(
|
|
@@ -802,24 +1061,141 @@ export class WasmCoreRuntime implements CoreRuntime {
|
|
|
802
1061
|
return await callHandleAsync(queue, "inspectMessages");
|
|
803
1062
|
}
|
|
804
1063
|
|
|
805
|
-
|
|
1064
|
+
async actorQueueReset(ctx: ActorContextHandle): Promise<void> {
|
|
1065
|
+
const queue = childHandle(asWasmActorContext(ctx), "queue");
|
|
1066
|
+
await callHandleAsync(queue, "reset");
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
async actorScheduleAfter(
|
|
806
1070
|
ctx: ActorContextHandle,
|
|
807
1071
|
durationMs: number | bigint,
|
|
808
1072
|
actionName: string,
|
|
809
1073
|
args: RuntimeBytes,
|
|
810
|
-
):
|
|
1074
|
+
): Promise<string> {
|
|
811
1075
|
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
812
|
-
|
|
1076
|
+
return await callHandleAsync<string>(
|
|
1077
|
+
schedule,
|
|
1078
|
+
"after",
|
|
1079
|
+
wasmNumber(durationMs),
|
|
1080
|
+
actionName,
|
|
1081
|
+
args,
|
|
1082
|
+
);
|
|
813
1083
|
}
|
|
814
1084
|
|
|
815
|
-
actorScheduleAt(
|
|
1085
|
+
async actorScheduleAt(
|
|
816
1086
|
ctx: ActorContextHandle,
|
|
817
1087
|
timestampMs: number | bigint,
|
|
818
1088
|
actionName: string,
|
|
819
1089
|
args: RuntimeBytes,
|
|
820
|
-
):
|
|
1090
|
+
): Promise<string> {
|
|
1091
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1092
|
+
return await callHandleAsync<string>(
|
|
1093
|
+
schedule,
|
|
1094
|
+
"at",
|
|
1095
|
+
wasmNumber(timestampMs),
|
|
1096
|
+
actionName,
|
|
1097
|
+
args,
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
async actorScheduleCancel(ctx: ActorContextHandle, id: string) {
|
|
821
1102
|
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
822
|
-
|
|
1103
|
+
return await callHandleAsync<boolean>(schedule, "cancel", id);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
async actorScheduleGet(ctx: ActorContextHandle, id: string) {
|
|
1107
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1108
|
+
return await callHandleAsync<RuntimeScheduledEventInfo | undefined>(
|
|
1109
|
+
schedule,
|
|
1110
|
+
"get",
|
|
1111
|
+
id,
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
async actorScheduleList(ctx: ActorContextHandle) {
|
|
1116
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1117
|
+
return await callHandleAsync<RuntimeScheduledEventInfo[]>(
|
|
1118
|
+
schedule,
|
|
1119
|
+
"list",
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
async actorCronSet(
|
|
1124
|
+
ctx: ActorContextHandle,
|
|
1125
|
+
name: string,
|
|
1126
|
+
expression: string,
|
|
1127
|
+
timezone: string | undefined,
|
|
1128
|
+
actionName: string,
|
|
1129
|
+
args: RuntimeBytes,
|
|
1130
|
+
maxHistory: number | undefined,
|
|
1131
|
+
) {
|
|
1132
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1133
|
+
await callHandleAsync(
|
|
1134
|
+
schedule,
|
|
1135
|
+
"cronSet",
|
|
1136
|
+
name,
|
|
1137
|
+
expression,
|
|
1138
|
+
timezone,
|
|
1139
|
+
actionName,
|
|
1140
|
+
args,
|
|
1141
|
+
maxHistory,
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
async actorCronEvery(
|
|
1146
|
+
ctx: ActorContextHandle,
|
|
1147
|
+
name: string,
|
|
1148
|
+
intervalMs: number,
|
|
1149
|
+
actionName: string,
|
|
1150
|
+
args: RuntimeBytes,
|
|
1151
|
+
maxHistory: number | undefined,
|
|
1152
|
+
) {
|
|
1153
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1154
|
+
await callHandleAsync(
|
|
1155
|
+
schedule,
|
|
1156
|
+
"cronEvery",
|
|
1157
|
+
name,
|
|
1158
|
+
intervalMs,
|
|
1159
|
+
actionName,
|
|
1160
|
+
args,
|
|
1161
|
+
maxHistory,
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
async actorCronGet(ctx: ActorContextHandle, name: string) {
|
|
1166
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1167
|
+
return await callHandleAsync<RuntimeCronJobInfo | undefined>(
|
|
1168
|
+
schedule,
|
|
1169
|
+
"cronGet",
|
|
1170
|
+
name,
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
async actorCronList(ctx: ActorContextHandle) {
|
|
1175
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1176
|
+
return await callHandleAsync<RuntimeCronJobInfo[]>(
|
|
1177
|
+
schedule,
|
|
1178
|
+
"cronList",
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
async actorCronDelete(ctx: ActorContextHandle, name: string) {
|
|
1183
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1184
|
+
return await callHandleAsync<boolean>(schedule, "cronDelete", name);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
async actorCronHistory(
|
|
1188
|
+
ctx: ActorContextHandle,
|
|
1189
|
+
name: string,
|
|
1190
|
+
limit: number | undefined,
|
|
1191
|
+
) {
|
|
1192
|
+
const schedule = childHandle(asWasmActorContext(ctx), "schedule");
|
|
1193
|
+
return await callHandleAsync<RuntimeCronFire[]>(
|
|
1194
|
+
schedule,
|
|
1195
|
+
"cronHistory",
|
|
1196
|
+
name,
|
|
1197
|
+
limit,
|
|
1198
|
+
);
|
|
823
1199
|
}
|
|
824
1200
|
|
|
825
1201
|
connId(conn: ConnHandle): string {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import onChange from "@rivetkit/on-change";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a proxy that tracks deep mutations on an object and calls `commit`
|
|
5
|
+
* after every change. Uses `@rivetkit/on-change` internally, which correctly
|
|
6
|
+
* detects mutations via methods on Map, Set, Date, TypedArrays, and arrays.
|
|
7
|
+
*
|
|
8
|
+
* If the value is not an object (primitive, null, undefined), it is returned
|
|
9
|
+
* as-is since primitives cannot be proxied or mutated.
|
|
10
|
+
*
|
|
11
|
+
* @param value - The root value to watch.
|
|
12
|
+
* @param commit - Called after every detected mutation with the root object.
|
|
13
|
+
* @param beforeChange - Called before every mutation with the new value being
|
|
14
|
+
* assigned. Throw to reject the change.
|
|
15
|
+
*/
|
|
16
|
+
export function createWriteThroughProxy<T>(
|
|
17
|
+
value: T,
|
|
18
|
+
commit: (next: T) => void,
|
|
19
|
+
beforeChange?: (newValue: unknown) => void,
|
|
20
|
+
): T {
|
|
21
|
+
if (!value || typeof value !== "object") {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return onChange(
|
|
26
|
+
value as T & Record<string, any>,
|
|
27
|
+
() => {
|
|
28
|
+
commit(value);
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
// Rejection is throw-based: beforeChange throws to prevent the
|
|
32
|
+
// mutation. We always return true so on-change applies the change
|
|
33
|
+
// if beforeChange did not throw.
|
|
34
|
+
onValidate(_path: string, newValue: unknown) {
|
|
35
|
+
beforeChange?.(newValue);
|
|
36
|
+
return true;
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
) as T;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the raw target behind an `@rivetkit/on-change` proxy, following
|
|
44
|
+
* chains of proxies wrapping proxies until reaching a plain value.
|
|
45
|
+
*/
|
|
46
|
+
function unwrapProxy(value: unknown): unknown {
|
|
47
|
+
let current = value;
|
|
48
|
+
while (current !== null && typeof current === "object") {
|
|
49
|
+
const target = onChange.target(current as Record<string, any>);
|
|
50
|
+
if (target === current) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
current = target;
|
|
54
|
+
}
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
59
|
+
const proto = Object.getPrototypeOf(value as object);
|
|
60
|
+
return proto === Object.prototype || proto === null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function unwrapDeep(value: unknown, seen: Set<object>): unknown {
|
|
64
|
+
const unwrapped = unwrapProxy(value);
|
|
65
|
+
if (!unwrapped || typeof unwrapped !== "object") {
|
|
66
|
+
return unwrapped;
|
|
67
|
+
}
|
|
68
|
+
if (seen.has(unwrapped)) {
|
|
69
|
+
return unwrapped;
|
|
70
|
+
}
|
|
71
|
+
seen.add(unwrapped);
|
|
72
|
+
|
|
73
|
+
if (Array.isArray(unwrapped)) {
|
|
74
|
+
for (let i = 0; i < unwrapped.length; i++) {
|
|
75
|
+
const child = unwrapDeep(unwrapped[i], seen);
|
|
76
|
+
if (child !== unwrapped[i]) {
|
|
77
|
+
unwrapped[i] = child;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return unwrapped;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (unwrapped instanceof Map) {
|
|
84
|
+
const replacements: [unknown, unknown, unknown][] = [];
|
|
85
|
+
for (const [key, child] of unwrapped.entries()) {
|
|
86
|
+
const nextKey = unwrapDeep(key, seen);
|
|
87
|
+
const nextChild = unwrapDeep(child, seen);
|
|
88
|
+
if (nextKey !== key || nextChild !== child) {
|
|
89
|
+
replacements.push([key, nextKey, nextChild]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const [key, nextKey, nextChild] of replacements) {
|
|
93
|
+
if (nextKey !== key) {
|
|
94
|
+
unwrapped.delete(key);
|
|
95
|
+
}
|
|
96
|
+
unwrapped.set(nextKey, nextChild);
|
|
97
|
+
}
|
|
98
|
+
return unwrapped;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (unwrapped instanceof Set) {
|
|
102
|
+
const replacements: [unknown, unknown][] = [];
|
|
103
|
+
for (const child of unwrapped.values()) {
|
|
104
|
+
const next = unwrapDeep(child, seen);
|
|
105
|
+
if (next !== child) {
|
|
106
|
+
replacements.push([child, next]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const [child, next] of replacements) {
|
|
110
|
+
unwrapped.delete(child);
|
|
111
|
+
unwrapped.add(next);
|
|
112
|
+
}
|
|
113
|
+
return unwrapped;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isPlainObject(unwrapped)) {
|
|
117
|
+
for (const key of Object.keys(unwrapped)) {
|
|
118
|
+
const child = unwrapDeep(unwrapped[key], seen);
|
|
119
|
+
if (child !== unwrapped[key]) {
|
|
120
|
+
unwrapped[key] = child;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return unwrapped;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Strips every `@rivetkit/on-change` proxy out of a value in place, including
|
|
130
|
+
* proxies nested inside plain objects, arrays, `Map`s, and `Set`s.
|
|
131
|
+
*
|
|
132
|
+
* A read of `c.state` or `conn.state` hands back a deep write-through proxy,
|
|
133
|
+
* so an update written as `c.state = { ...c.state, foo }` produces a plain root
|
|
134
|
+
* object whose children are still proxies. Persisting that value as-is makes
|
|
135
|
+
* the next read wrap proxies in another proxy layer, and each layer multiplies
|
|
136
|
+
* the work of traversing the state, so repeated spread updates degrade
|
|
137
|
+
* exponentially. Unwrapping before persisting keeps stored state proxy-free.
|
|
138
|
+
*/
|
|
139
|
+
export function unwrapWriteThroughProxy<T>(value: T): T {
|
|
140
|
+
return unwrapDeep(value, new Set()) as T;
|
|
141
|
+
}
|