rivetkit 2.0.42 → 2.1.0-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/{tsup/config-CLnylLYY.d.ts → browser/client.d.ts} +2127 -1910
- package/dist/browser/client.js +5182 -0
- package/dist/browser/client.js.map +1 -0
- package/dist/browser/inspector/client.d.ts +130 -0
- package/dist/browser/inspector/client.js +2854 -0
- package/dist/browser/inspector/client.js.map +1 -0
- package/dist/browser/v3-DnYObHH3.d.ts +279 -0
- package/dist/schemas/actor-inspector/v2.ts +796 -0
- package/dist/schemas/actor-inspector/v3.ts +899 -0
- package/dist/schemas/actor-persist/v4.ts +406 -0
- package/dist/schemas/client-protocol/v3.ts +554 -0
- package/dist/schemas/persist/v1.ts +781 -0
- package/dist/schemas/transport/v1.ts +697 -0
- package/dist/tsup/actor/errors.cjs +27 -3
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +37 -1
- package/dist/tsup/actor/errors.d.ts +37 -1
- package/dist/tsup/actor/errors.js +26 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.cts → actor-router-consts-D29T1Z-K.d.cts} +1 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.ts → actor-router-consts-D29T1Z-K.d.ts} +1 -1
- package/dist/tsup/chunk-424PT5DM.js +23 -0
- package/dist/tsup/chunk-424PT5DM.js.map +1 -0
- package/dist/tsup/{chunk-JDAD2YFA.js → chunk-5ESWDTHJ.js} +148 -273
- package/dist/tsup/chunk-5ESWDTHJ.js.map +1 -0
- package/dist/tsup/{chunk-FJ3KTN4V.js → chunk-6LIBPELE.js} +119 -11
- package/dist/tsup/chunk-6LIBPELE.js.map +1 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
- package/dist/tsup/{chunk-LFVF5SCU.js → chunk-7HTNH26M.js} +126 -1
- package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
- package/dist/tsup/chunk-7K4CYDGD.js +630 -0
- package/dist/tsup/chunk-7K4CYDGD.js.map +1 -0
- package/dist/tsup/{chunk-XXGJCOL6.js → chunk-A6YIZWTK.js} +2 -2
- package/dist/tsup/chunk-AIYEYMX5.cjs +630 -0
- package/dist/tsup/chunk-AIYEYMX5.cjs.map +1 -0
- package/dist/tsup/{chunk-Q6W7RJJP.js → chunk-DIGBC2VI.js} +211 -2316
- package/dist/tsup/chunk-DIGBC2VI.js.map +1 -0
- package/dist/tsup/{chunk-RZW2DNND.cjs → chunk-F6JYU5IK.cjs} +1957 -1039
- package/dist/tsup/chunk-F6JYU5IK.cjs.map +1 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs +534 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs.map +1 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs +1036 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs.map +1 -0
- package/dist/tsup/chunk-IVG73YCW.js +534 -0
- package/dist/tsup/chunk-IVG73YCW.js.map +1 -0
- package/dist/tsup/chunk-KJSYAUOM.js +96 -0
- package/dist/tsup/chunk-KJSYAUOM.js.map +1 -0
- package/dist/tsup/{chunk-2XQS746M.cjs → chunk-L47L3ZWJ.cjs} +127 -2
- package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
- package/dist/tsup/{chunk-H4TB4X25.cjs → chunk-LW6KLR7A.cjs} +126 -18
- package/dist/tsup/chunk-LW6KLR7A.cjs.map +1 -0
- package/dist/tsup/chunk-LXUQ667X.js +2006 -0
- package/dist/tsup/chunk-LXUQ667X.js.map +1 -0
- package/dist/tsup/{chunk-GMAVRZSF.js → chunk-M2T62AZQ.js} +1790 -872
- package/dist/tsup/chunk-M2T62AZQ.js.map +1 -0
- package/dist/tsup/chunk-MZ37VV3P.js +5974 -0
- package/dist/tsup/chunk-MZ37VV3P.js.map +1 -0
- package/dist/tsup/chunk-N4KRDJ56.js +72 -0
- package/dist/tsup/chunk-N4KRDJ56.js.map +1 -0
- package/dist/tsup/chunk-NIYZDWMW.cjs +2006 -0
- package/dist/tsup/chunk-NIYZDWMW.cjs.map +1 -0
- package/dist/tsup/chunk-OMEPCQK2.js +649 -0
- package/dist/tsup/chunk-OMEPCQK2.js.map +1 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs +2657 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs.map +1 -0
- package/dist/tsup/chunk-T5YCUGVS.js +1036 -0
- package/dist/tsup/chunk-T5YCUGVS.js.map +1 -0
- package/dist/tsup/{chunk-EJVBH5VF.cjs → chunk-TPGXWFQT.cjs} +3 -3
- package/dist/tsup/{chunk-EJVBH5VF.cjs.map → chunk-TPGXWFQT.cjs.map} +1 -1
- package/dist/tsup/{chunk-X35U3YNX.cjs → chunk-TYLXNCA5.cjs} +214 -339
- package/dist/tsup/chunk-TYLXNCA5.cjs.map +1 -0
- package/dist/tsup/chunk-VKVNIQRQ.js +257 -0
- package/dist/tsup/chunk-VKVNIQRQ.js.map +1 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs +649 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs +5974 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs.map +1 -0
- package/dist/tsup/chunk-ZFY5J2EP.cjs +257 -0
- package/dist/tsup/chunk-ZFY5J2EP.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -10
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +11 -5
- package/dist/tsup/client/mod.d.ts +11 -5
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +4 -4
- package/dist/tsup/common/log.d.cts +2 -2
- package/dist/tsup/common/log.d.ts +2 -2
- package/dist/tsup/common/log.js +3 -2
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -3
- package/dist/tsup/config-BFqid9Gr.d.ts +2574 -0
- package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
- package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
- package/dist/tsup/{config-CZB2-W8x.d.cts → config-CAZphOS1.d.cts} +681 -355
- package/dist/tsup/db/drizzle/mod.cjs +49 -0
- package/dist/tsup/db/drizzle/mod.cjs.map +1 -0
- package/dist/tsup/db/drizzle/mod.d.cts +17 -0
- package/dist/tsup/db/drizzle/mod.d.ts +17 -0
- package/dist/tsup/db/drizzle/mod.js +49 -0
- package/dist/tsup/db/drizzle/mod.js.map +1 -0
- package/dist/tsup/db/mod.cjs +9 -0
- package/dist/tsup/db/mod.cjs.map +1 -0
- package/dist/tsup/db/mod.d.cts +9 -0
- package/dist/tsup/db/mod.d.ts +9 -0
- package/dist/tsup/db/mod.js +9 -0
- package/dist/tsup/db/mod.js.map +1 -0
- package/dist/tsup/{driver-D0QX9M11.d.ts → driver-Bxv62E2p.d.ts} +2 -2
- package/dist/tsup/{driver-q-zqG7fc.d.cts → driver-DYXwJR5D.d.cts} +2 -2
- package/dist/tsup/driver-helpers/mod.cjs +12 -6
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +12 -5
- package/dist/tsup/driver-helpers/mod.d.ts +12 -5
- package/dist/tsup/driver-helpers/mod.js +12 -5
- package/dist/tsup/driver-test-suite/mod.cjs +1370 -116
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +10 -4
- package/dist/tsup/driver-test-suite/mod.d.ts +10 -4
- package/dist/tsup/driver-test-suite/mod.js +2093 -838
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +29 -3
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +124 -3
- package/dist/tsup/inspector/mod.d.ts +124 -3
- package/dist/tsup/inspector/mod.js +72 -45
- package/dist/tsup/keys-CydblqMh.d.cts +13 -0
- package/dist/tsup/keys-CydblqMh.d.ts +13 -0
- package/dist/tsup/mod.cjs +16 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +26 -14
- package/dist/tsup/mod.d.ts +26 -14
- package/dist/tsup/mod.js +20 -13
- package/dist/tsup/serve-test-suite/mod.cjs +1165 -83
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +1114 -29
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +84 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +10 -5
- package/dist/tsup/test/mod.d.ts +10 -5
- package/dist/tsup/test/mod.js +85 -11
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +10 -4
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +72 -2
- package/dist/tsup/utils.d.ts +72 -2
- package/dist/tsup/utils.js +9 -2
- package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
- package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
- package/dist/tsup/workflow/mod.cjs +16 -0
- package/dist/tsup/workflow/mod.cjs.map +1 -0
- package/dist/tsup/workflow/mod.d.cts +83 -0
- package/dist/tsup/workflow/mod.d.ts +83 -0
- package/dist/tsup/workflow/mod.js +16 -0
- package/dist/tsup/workflow/mod.js.map +1 -0
- package/package.json +62 -5
- package/src/actor/config.ts +478 -68
- package/src/actor/conn/mod.ts +68 -16
- package/src/actor/conn/state-manager.ts +2 -2
- package/src/actor/contexts/action.ts +20 -12
- package/src/actor/contexts/base/actor.ts +137 -7
- package/src/actor/contexts/base/conn-init.ts +27 -7
- package/src/actor/contexts/base/conn.ts +27 -18
- package/src/actor/contexts/before-action-response.ts +9 -2
- package/src/actor/contexts/before-connect.ts +7 -2
- package/src/actor/contexts/connect.ts +9 -2
- package/src/actor/contexts/create-conn-state.ts +7 -2
- package/src/actor/contexts/create-vars.ts +16 -3
- package/src/actor/contexts/create.ts +16 -3
- package/src/actor/contexts/destroy.ts +9 -3
- package/src/actor/contexts/disconnect.ts +10 -4
- package/src/actor/contexts/index.ts +4 -3
- package/src/actor/contexts/request.ts +23 -6
- package/src/actor/contexts/run.ts +47 -0
- package/src/actor/contexts/sleep.ts +9 -3
- package/src/actor/contexts/state-change.ts +9 -3
- package/src/actor/contexts/wake.ts +9 -3
- package/src/actor/contexts/websocket.ts +23 -6
- package/src/actor/database.ts +8 -18
- package/src/actor/definition.ts +20 -6
- package/src/actor/driver.ts +32 -3
- package/src/actor/errors.ts +127 -0
- package/src/actor/instance/connection-manager.ts +183 -80
- package/src/actor/instance/event-manager.ts +26 -15
- package/src/actor/instance/keys.ts +117 -0
- package/src/actor/instance/mod.ts +784 -174
- package/src/actor/instance/queue-manager.ts +603 -0
- package/src/actor/instance/queue.ts +287 -0
- package/src/actor/instance/schedule-manager.ts +49 -7
- package/src/actor/instance/state-manager.ts +35 -11
- package/src/actor/instance/traces-driver.ts +128 -0
- package/src/actor/mod.ts +26 -2
- package/src/actor/protocol/old.ts +28 -13
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +177 -21
- package/src/actor/router-websocket-endpoints.ts +18 -29
- package/src/actor/router.ts +177 -0
- package/src/actor/schema.ts +291 -0
- package/src/actor/utils.ts +40 -0
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +100 -33
- package/src/client/actor-handle.ts +61 -33
- package/src/client/client.ts +2 -4
- package/src/client/config.ts +1 -1
- package/src/client/mod.browser.ts +2 -0
- package/src/client/mod.ts +1 -4
- package/src/client/queue.ts +146 -0
- package/src/client/utils.ts +1 -1
- package/src/common/log.ts +1 -1
- package/src/common/utils.ts +3 -3
- package/src/db/config.ts +100 -0
- package/src/db/drizzle/mod.ts +226 -0
- package/src/db/drizzle/sqlite-core.ts +22 -0
- package/src/db/mod.ts +125 -0
- package/src/db/shared.ts +92 -0
- package/src/db/sqlite-vfs.ts +12 -0
- package/src/driver-helpers/mod.ts +1 -0
- package/src/driver-test-suite/mod.ts +69 -43
- package/src/driver-test-suite/tests/access-control.ts +218 -0
- package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
- package/src/driver-test-suite/tests/actor-db.ts +394 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +259 -358
- package/src/driver-test-suite/tests/actor-kv.ts +41 -20
- package/src/driver-test-suite/tests/actor-queue.ts +324 -0
- package/src/driver-test-suite/tests/actor-run.ts +181 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +5 -2
- package/src/driver-test-suite/tests/actor-sleep.ts +3 -3
- package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
- package/src/driver-test-suite/tests/actor-workflow.ts +108 -0
- package/src/driver-test-suite/tests/manager-driver.ts +11 -0
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +1 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +12 -12
- package/src/drivers/default.ts +7 -2
- package/src/drivers/engine/actor-driver.ts +45 -37
- package/src/drivers/engine/config.ts +1 -1
- package/src/drivers/file-system/actor.ts +20 -2
- package/src/drivers/file-system/global-state.ts +569 -258
- package/src/drivers/file-system/kv-limits.ts +70 -0
- package/src/drivers/file-system/manager.ts +22 -6
- package/src/drivers/file-system/mod.ts +39 -16
- package/src/drivers/file-system/sqlite-runtime.ts +210 -0
- package/src/inspector/actor-inspector.ts +224 -102
- package/src/inspector/config.ts +1 -1
- package/src/inspector/handler.ts +102 -20
- package/src/inspector/mod.browser.ts +8 -0
- package/src/inspector/mod.ts +2 -0
- package/src/inspector/serve-ui.ts +40 -0
- package/src/inspector/transport.ts +18 -0
- package/src/inspector/utils.ts +5 -39
- package/src/manager/gateway.ts +1 -1
- package/src/manager/protocol/mod.ts +1 -1
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router-schema.ts +1 -1
- package/src/manager/router.ts +38 -12
- package/src/manager-api/actors.ts +1 -1
- package/src/manager-api/common.ts +1 -1
- package/src/registry/config/driver.ts +1 -1
- package/src/registry/config/index.ts +212 -43
- package/src/registry/config/legacy-runner.ts +1 -1
- package/src/registry/config/runner.ts +1 -1
- package/src/registry/config/serverless.ts +1 -1
- package/src/registry/index.ts +7 -5
- package/src/remote-manager-driver/api-utils.ts +1 -1
- package/src/schemas/actor-inspector/mod.ts +1 -1
- package/src/schemas/actor-inspector/versioned.ts +195 -8
- package/src/schemas/actor-persist/versioned.ts +87 -7
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +127 -11
- package/src/schemas/client-protocol-zod/mod.ts +16 -1
- package/src/schemas/persist/mod.ts +1 -0
- package/src/schemas/transport/mod.ts +1 -0
- package/src/serde.ts +1 -1
- package/src/serve-test-suite/mod.ts +10 -9
- package/src/test/mod.ts +15 -56
- package/src/utils/endpoint-parser.test.ts +1 -1
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +12 -1
- package/src/utils/node.ts +15 -2
- package/src/utils.test.ts +34 -0
- package/src/utils.ts +140 -6
- package/src/workflow/constants.ts +2 -0
- package/src/workflow/context.ts +532 -0
- package/src/workflow/driver.ts +191 -0
- package/src/workflow/inspector.ts +268 -0
- package/src/workflow/mod.ts +122 -0
- package/dist/tsup/chunk-2IJTYN6K.cjs +0 -278
- package/dist/tsup/chunk-2IJTYN6K.cjs.map +0 -1
- package/dist/tsup/chunk-2XQS746M.cjs.map +0 -1
- package/dist/tsup/chunk-3VP5CSHV.cjs +0 -114
- package/dist/tsup/chunk-3VP5CSHV.cjs.map +0 -1
- package/dist/tsup/chunk-AQFSQMBG.js +0 -114
- package/dist/tsup/chunk-AQFSQMBG.js.map +0 -1
- package/dist/tsup/chunk-E6ZE2YEA.js +0 -664
- package/dist/tsup/chunk-E6ZE2YEA.js.map +0 -1
- package/dist/tsup/chunk-FJ3KTN4V.js.map +0 -1
- package/dist/tsup/chunk-GBENOENJ.cjs +0 -8
- package/dist/tsup/chunk-GBENOENJ.cjs.map +0 -1
- package/dist/tsup/chunk-GD7UXGOE.cjs +0 -4762
- package/dist/tsup/chunk-GD7UXGOE.cjs.map +0 -1
- package/dist/tsup/chunk-GMAVRZSF.js.map +0 -1
- package/dist/tsup/chunk-H4TB4X25.cjs.map +0 -1
- package/dist/tsup/chunk-JDAD2YFA.js.map +0 -1
- package/dist/tsup/chunk-KCOVZOPS.js +0 -1946
- package/dist/tsup/chunk-KCOVZOPS.js.map +0 -1
- package/dist/tsup/chunk-KDFWJKMJ.cjs +0 -664
- package/dist/tsup/chunk-KDFWJKMJ.cjs.map +0 -1
- package/dist/tsup/chunk-LFVF5SCU.js.map +0 -1
- package/dist/tsup/chunk-Q6W7RJJP.js.map +0 -1
- package/dist/tsup/chunk-RUW5CZ5Z.cjs +0 -1949
- package/dist/tsup/chunk-RUW5CZ5Z.cjs.map +0 -1
- package/dist/tsup/chunk-RZW2DNND.cjs.map +0 -1
- package/dist/tsup/chunk-TCOEBUUE.js +0 -278
- package/dist/tsup/chunk-TCOEBUUE.js.map +0 -1
- package/dist/tsup/chunk-X35U3YNX.cjs.map +0 -1
- package/dist/tsup/keys-Chhy4ylv.d.cts +0 -8
- package/dist/tsup/keys-Chhy4ylv.d.ts +0 -8
- package/dist/tsup/v1-Gq4avTK3.d.cts +0 -240
- package/dist/tsup/v1-Gq4avTK3.d.ts +0 -240
- /package/dist/tsup/{chunk-XXGJCOL6.js.map → chunk-A6YIZWTK.js.map} +0 -0
package/src/actor/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
2
|
import type { UniversalWebSocket } from "@/common/websocket-interface";
|
|
3
3
|
import type { Conn } from "./conn/mod";
|
|
4
4
|
import type {
|
|
@@ -13,12 +13,14 @@ import type {
|
|
|
13
13
|
DestroyContext,
|
|
14
14
|
DisconnectContext,
|
|
15
15
|
RequestContext,
|
|
16
|
+
RunContext,
|
|
16
17
|
SleepContext,
|
|
17
18
|
StateChangeContext,
|
|
18
19
|
WakeContext,
|
|
19
20
|
WebSocketContext,
|
|
20
21
|
} from "./contexts";
|
|
21
22
|
import type { AnyDatabaseProvider } from "./database";
|
|
23
|
+
import type { EventSchemaConfig, QueueSchemaConfig } from "./schema";
|
|
22
24
|
|
|
23
25
|
export interface ActorTypes<
|
|
24
26
|
TState,
|
|
@@ -41,6 +43,133 @@ const zFunction = <
|
|
|
41
43
|
T extends (...args: any[]) => any = (...args: unknown[]) => unknown,
|
|
42
44
|
>() => z.custom<T>((val) => typeof val === "function");
|
|
43
45
|
|
|
46
|
+
export type InspectorUnsubscribe = () => void;
|
|
47
|
+
|
|
48
|
+
export interface WorkflowInspectorConfig<THistory = unknown> {
|
|
49
|
+
getHistory: () => THistory | null;
|
|
50
|
+
onHistoryUpdated?: (
|
|
51
|
+
listener: (history: THistory) => void,
|
|
52
|
+
) => InspectorUnsubscribe;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface RunInspectorConfig<THistory = unknown> {
|
|
56
|
+
workflow?: WorkflowInspectorConfig<THistory>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const WorkflowInspectorConfigSchema = z.object({
|
|
60
|
+
getHistory: zFunction<WorkflowInspectorConfig<unknown>["getHistory"]>(),
|
|
61
|
+
onHistoryUpdated:
|
|
62
|
+
zFunction<
|
|
63
|
+
NonNullable<WorkflowInspectorConfig<unknown>["onHistoryUpdated"]>
|
|
64
|
+
>().optional(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const RunInspectorConfigSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
workflow: WorkflowInspectorConfigSchema.optional(),
|
|
70
|
+
})
|
|
71
|
+
.optional();
|
|
72
|
+
|
|
73
|
+
// Schema for run handler with metadata
|
|
74
|
+
export const RunConfigSchema = z.object({
|
|
75
|
+
/** Display name for the actor in the Inspector UI. */
|
|
76
|
+
name: z.string().optional(),
|
|
77
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
78
|
+
icon: z.string().optional(),
|
|
79
|
+
/** The run handler function. */
|
|
80
|
+
run: zFunction(),
|
|
81
|
+
/** Inspector integration for long-running run handlers. */
|
|
82
|
+
inspector: RunInspectorConfigSchema.optional(),
|
|
83
|
+
});
|
|
84
|
+
type RunConfigRuntime = z.infer<typeof RunConfigSchema>;
|
|
85
|
+
export type RunConfig<
|
|
86
|
+
TState = unknown,
|
|
87
|
+
TConnParams = unknown,
|
|
88
|
+
TConnState = unknown,
|
|
89
|
+
TVars = unknown,
|
|
90
|
+
TInput = unknown,
|
|
91
|
+
TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider,
|
|
92
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
93
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
94
|
+
> = Omit<RunConfigRuntime, "run"> & {
|
|
95
|
+
run: (
|
|
96
|
+
c: RunContext<
|
|
97
|
+
TState,
|
|
98
|
+
TConnParams,
|
|
99
|
+
TConnState,
|
|
100
|
+
TVars,
|
|
101
|
+
TInput,
|
|
102
|
+
TDatabase,
|
|
103
|
+
TEvents,
|
|
104
|
+
TQueues
|
|
105
|
+
>,
|
|
106
|
+
) => void | Promise<void>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
type AnyRunConfig = RunConfig<
|
|
110
|
+
any,
|
|
111
|
+
any,
|
|
112
|
+
any,
|
|
113
|
+
any,
|
|
114
|
+
any,
|
|
115
|
+
AnyDatabaseProvider,
|
|
116
|
+
any,
|
|
117
|
+
any
|
|
118
|
+
>;
|
|
119
|
+
|
|
120
|
+
export const RUN_FUNCTION_CONFIG_SYMBOL = Symbol.for(
|
|
121
|
+
"rivetkit.run_function_config",
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
interface RunFunctionConfig {
|
|
125
|
+
name?: string;
|
|
126
|
+
icon?: string;
|
|
127
|
+
inspector?: RunInspectorConfig;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type RunFunctionWithConfig = ((...args: any[]) => any) & {
|
|
131
|
+
[RUN_FUNCTION_CONFIG_SYMBOL]?: RunFunctionConfig;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// Run can be either a function or an object with name/icon/run
|
|
135
|
+
const zRunHandler = z.union([zFunction(), RunConfigSchema]).optional();
|
|
136
|
+
|
|
137
|
+
/** Extract the run function from either a function or RunConfig object. */
|
|
138
|
+
export function getRunFunction(
|
|
139
|
+
run: ((...args: any[]) => any) | AnyRunConfig | undefined,
|
|
140
|
+
): ((...args: any[]) => any) | undefined {
|
|
141
|
+
if (!run) return undefined;
|
|
142
|
+
if (typeof run === "function") return run;
|
|
143
|
+
return run.run;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Extract run metadata (name/icon) from RunConfig if provided. */
|
|
147
|
+
export function getRunMetadata(
|
|
148
|
+
run: ((...args: any[]) => any) | AnyRunConfig | undefined,
|
|
149
|
+
): { name?: string; icon?: string } {
|
|
150
|
+
if (!run) return {};
|
|
151
|
+
if (typeof run === "function") {
|
|
152
|
+
const config = (run as RunFunctionWithConfig)[
|
|
153
|
+
RUN_FUNCTION_CONFIG_SYMBOL
|
|
154
|
+
];
|
|
155
|
+
if (!config) return {};
|
|
156
|
+
return { name: config.name, icon: config.icon };
|
|
157
|
+
}
|
|
158
|
+
return { name: run.name, icon: run.icon };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Extract run inspector configuration if provided. */
|
|
162
|
+
export function getRunInspectorConfig(
|
|
163
|
+
run: ((...args: any[]) => any) | AnyRunConfig | undefined,
|
|
164
|
+
): RunInspectorConfig | undefined {
|
|
165
|
+
if (!run) return undefined;
|
|
166
|
+
if (typeof run === "function") {
|
|
167
|
+
return (run as RunFunctionWithConfig)[RUN_FUNCTION_CONFIG_SYMBOL]
|
|
168
|
+
?.inspector;
|
|
169
|
+
}
|
|
170
|
+
return run.inspector;
|
|
171
|
+
}
|
|
172
|
+
|
|
44
173
|
// This schema is used to validate the input at runtime. The generic types are defined below in `ActorConfig`.
|
|
45
174
|
//
|
|
46
175
|
// We don't use Zod generics with `z.custom` because:
|
|
@@ -52,6 +181,7 @@ export const ActorConfigSchema = z
|
|
|
52
181
|
onDestroy: zFunction().optional(),
|
|
53
182
|
onWake: zFunction().optional(),
|
|
54
183
|
onSleep: zFunction().optional(),
|
|
184
|
+
run: zRunHandler,
|
|
55
185
|
onStateChange: zFunction().optional(),
|
|
56
186
|
onBeforeConnect: zFunction().optional(),
|
|
57
187
|
onConnect: zFunction().optional(),
|
|
@@ -60,6 +190,8 @@ export const ActorConfigSchema = z
|
|
|
60
190
|
onRequest: zFunction().optional(),
|
|
61
191
|
onWebSocket: zFunction().optional(),
|
|
62
192
|
actions: z.record(z.string(), zFunction()).default(() => ({})),
|
|
193
|
+
events: z.record(z.string(), z.any()).optional(),
|
|
194
|
+
queues: z.record(z.string(), z.any()).optional(),
|
|
63
195
|
state: z.any().optional(),
|
|
64
196
|
createState: zFunction().optional(),
|
|
65
197
|
connState: z.any().optional(),
|
|
@@ -69,20 +201,32 @@ export const ActorConfigSchema = z
|
|
|
69
201
|
createVars: zFunction().optional(),
|
|
70
202
|
options: z
|
|
71
203
|
.object({
|
|
204
|
+
/** Display name for the actor in the Inspector UI. */
|
|
205
|
+
name: z.string().optional(),
|
|
206
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
207
|
+
icon: z.string().optional(),
|
|
72
208
|
createVarsTimeout: z.number().positive().default(5000),
|
|
73
209
|
createConnStateTimeout: z.number().positive().default(5000),
|
|
74
210
|
onConnectTimeout: z.number().positive().default(5000),
|
|
75
|
-
// This must be less than
|
|
211
|
+
// This must be less than engine config > pegboard.actor_stop_threshold
|
|
76
212
|
onSleepTimeout: z.number().positive().default(5000),
|
|
213
|
+
// This must be less than engine config > pegboard.actor_stop_threshold
|
|
77
214
|
onDestroyTimeout: z.number().positive().default(5000),
|
|
78
215
|
stateSaveInterval: z.number().positive().default(10_000),
|
|
79
216
|
actionTimeout: z.number().positive().default(60_000),
|
|
80
217
|
// Max time to wait for waitUntil background promises during shutdown
|
|
81
218
|
waitUntilTimeout: z.number().positive().default(15_000),
|
|
219
|
+
// Max time to wait for run handler to stop during shutdown
|
|
220
|
+
runStopTimeout: z.number().positive().default(15_000),
|
|
82
221
|
connectionLivenessTimeout: z.number().positive().default(2500),
|
|
83
222
|
connectionLivenessInterval: z.number().positive().default(5000),
|
|
84
223
|
noSleep: z.boolean().default(false),
|
|
85
224
|
sleepTimeout: z.number().positive().default(30_000),
|
|
225
|
+
maxQueueSize: z.number().positive().default(1000),
|
|
226
|
+
maxQueueMessageSize: z
|
|
227
|
+
.number()
|
|
228
|
+
.positive()
|
|
229
|
+
.default(64 * 1024),
|
|
86
230
|
/**
|
|
87
231
|
* Can hibernate WebSockets for onWebSocket.
|
|
88
232
|
*
|
|
@@ -139,14 +283,16 @@ type CreateState<
|
|
|
139
283
|
TVars,
|
|
140
284
|
TInput,
|
|
141
285
|
TDatabase extends AnyDatabaseProvider,
|
|
286
|
+
TEvents extends EventSchemaConfig,
|
|
287
|
+
TQueues extends QueueSchemaConfig,
|
|
142
288
|
> =
|
|
143
289
|
| { state: TState }
|
|
144
290
|
| {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
291
|
+
createState: (
|
|
292
|
+
c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>,
|
|
293
|
+
input: TInput,
|
|
294
|
+
) => TState | Promise<TState>;
|
|
295
|
+
}
|
|
150
296
|
| Record<never, never>;
|
|
151
297
|
|
|
152
298
|
// Creates connection state config
|
|
@@ -161,14 +307,23 @@ type CreateConnState<
|
|
|
161
307
|
TVars,
|
|
162
308
|
TInput,
|
|
163
309
|
TDatabase extends AnyDatabaseProvider,
|
|
310
|
+
TEvents extends EventSchemaConfig,
|
|
311
|
+
TQueues extends QueueSchemaConfig,
|
|
164
312
|
> =
|
|
165
313
|
| { connState: TConnState }
|
|
166
314
|
| {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
315
|
+
createConnState: (
|
|
316
|
+
c: CreateConnStateContext<
|
|
317
|
+
TState,
|
|
318
|
+
TVars,
|
|
319
|
+
TInput,
|
|
320
|
+
TDatabase,
|
|
321
|
+
TEvents,
|
|
322
|
+
TQueues
|
|
323
|
+
>,
|
|
324
|
+
params: TConnParams,
|
|
325
|
+
) => TConnState | Promise<TConnState>;
|
|
326
|
+
}
|
|
172
327
|
| Record<never, never>;
|
|
173
328
|
|
|
174
329
|
// Creates vars config
|
|
@@ -184,22 +339,30 @@ type CreateVars<
|
|
|
184
339
|
TVars,
|
|
185
340
|
TInput,
|
|
186
341
|
TDatabase extends AnyDatabaseProvider,
|
|
342
|
+
TEvents extends EventSchemaConfig,
|
|
343
|
+
TQueues extends QueueSchemaConfig,
|
|
187
344
|
> =
|
|
188
345
|
| {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
346
|
+
/**
|
|
347
|
+
* @experimental
|
|
348
|
+
*/
|
|
349
|
+
vars: TVars;
|
|
350
|
+
}
|
|
194
351
|
| {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
352
|
+
/**
|
|
353
|
+
* @experimental
|
|
354
|
+
*/
|
|
355
|
+
createVars: (
|
|
356
|
+
c: CreateVarsContext<
|
|
357
|
+
TState,
|
|
358
|
+
TInput,
|
|
359
|
+
TDatabase,
|
|
360
|
+
TEvents,
|
|
361
|
+
TQueues
|
|
362
|
+
>,
|
|
363
|
+
driverCtx: any,
|
|
364
|
+
) => TVars | Promise<TVars>;
|
|
365
|
+
}
|
|
203
366
|
| Record<never, never>;
|
|
204
367
|
|
|
205
368
|
export interface Actions<
|
|
@@ -209,6 +372,8 @@ export interface Actions<
|
|
|
209
372
|
TVars,
|
|
210
373
|
TInput,
|
|
211
374
|
TDatabase extends AnyDatabaseProvider,
|
|
375
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
376
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
212
377
|
> {
|
|
213
378
|
[Action: string]: (
|
|
214
379
|
c: ActionContext<
|
|
@@ -217,7 +382,9 @@ export interface Actions<
|
|
|
217
382
|
TConnState,
|
|
218
383
|
TVars,
|
|
219
384
|
TInput,
|
|
220
|
-
TDatabase
|
|
385
|
+
TDatabase,
|
|
386
|
+
TEvents,
|
|
387
|
+
TQueues
|
|
221
388
|
>,
|
|
222
389
|
...args: any[]
|
|
223
390
|
) => any;
|
|
@@ -240,13 +407,17 @@ interface BaseActorConfig<
|
|
|
240
407
|
TVars,
|
|
241
408
|
TInput,
|
|
242
409
|
TDatabase extends AnyDatabaseProvider,
|
|
410
|
+
TEvents extends EventSchemaConfig,
|
|
411
|
+
TQueues extends QueueSchemaConfig,
|
|
243
412
|
TActions extends Actions<
|
|
244
413
|
TState,
|
|
245
414
|
TConnParams,
|
|
246
415
|
TConnState,
|
|
247
416
|
TVars,
|
|
248
417
|
TInput,
|
|
249
|
-
TDatabase
|
|
418
|
+
TDatabase,
|
|
419
|
+
TEvents,
|
|
420
|
+
TQueues
|
|
250
421
|
>,
|
|
251
422
|
> {
|
|
252
423
|
/**
|
|
@@ -256,7 +427,7 @@ interface BaseActorConfig<
|
|
|
256
427
|
* This is called before any other lifecycle hooks.
|
|
257
428
|
*/
|
|
258
429
|
onCreate?: (
|
|
259
|
-
c: CreateContext<TState, TInput, TDatabase>,
|
|
430
|
+
c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>,
|
|
260
431
|
input: TInput,
|
|
261
432
|
) => void | Promise<void>;
|
|
262
433
|
|
|
@@ -270,7 +441,9 @@ interface BaseActorConfig<
|
|
|
270
441
|
TConnState,
|
|
271
442
|
TVars,
|
|
272
443
|
TInput,
|
|
273
|
-
TDatabase
|
|
444
|
+
TDatabase,
|
|
445
|
+
TEvents,
|
|
446
|
+
TQueues
|
|
274
447
|
>,
|
|
275
448
|
) => void | Promise<void>;
|
|
276
449
|
|
|
@@ -289,7 +462,9 @@ interface BaseActorConfig<
|
|
|
289
462
|
TConnState,
|
|
290
463
|
TVars,
|
|
291
464
|
TInput,
|
|
292
|
-
TDatabase
|
|
465
|
+
TDatabase,
|
|
466
|
+
TEvents,
|
|
467
|
+
TQueues
|
|
293
468
|
>,
|
|
294
469
|
) => void | Promise<void>;
|
|
295
470
|
|
|
@@ -310,10 +485,59 @@ interface BaseActorConfig<
|
|
|
310
485
|
TConnState,
|
|
311
486
|
TVars,
|
|
312
487
|
TInput,
|
|
313
|
-
TDatabase
|
|
488
|
+
TDatabase,
|
|
489
|
+
TEvents,
|
|
490
|
+
TQueues
|
|
314
491
|
>,
|
|
315
492
|
) => void | Promise<void>;
|
|
316
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Called after the actor starts up. Does not block actor startup.
|
|
496
|
+
*
|
|
497
|
+
* Use this for background tasks like:
|
|
498
|
+
* - Reading from queues in a loop
|
|
499
|
+
* - Tick loops for periodic work
|
|
500
|
+
* - Custom workflow logic
|
|
501
|
+
*
|
|
502
|
+
* **Important:** The actor may go to sleep at any time during the `run`
|
|
503
|
+
* handler. Use `c.keepAwake(promise)` to wrap async operations that should
|
|
504
|
+
* not be interrupted by sleep.
|
|
505
|
+
*
|
|
506
|
+
* The handler receives an abort signal via `c.abortSignal` and a
|
|
507
|
+
* `c.aborted` alias for loop checks. Use these to gracefully exit.
|
|
508
|
+
*
|
|
509
|
+
* If this handler exits or throws, the actor will crash and reschedule.
|
|
510
|
+
* On shutdown, the actor waits for this handler to complete with a
|
|
511
|
+
* configurable timeout (options.runStopTimeout, default 15s).
|
|
512
|
+
*
|
|
513
|
+
* Can be either a function or a RunConfig object with optional name/icon metadata.
|
|
514
|
+
*
|
|
515
|
+
* @returns Void or a Promise. If the promise exits, the actor crashes.
|
|
516
|
+
*/
|
|
517
|
+
run?:
|
|
518
|
+
| ((
|
|
519
|
+
c: RunContext<
|
|
520
|
+
TState,
|
|
521
|
+
TConnParams,
|
|
522
|
+
TConnState,
|
|
523
|
+
TVars,
|
|
524
|
+
TInput,
|
|
525
|
+
TDatabase,
|
|
526
|
+
TEvents,
|
|
527
|
+
TQueues
|
|
528
|
+
>,
|
|
529
|
+
) => void | Promise<void>)
|
|
530
|
+
| RunConfig<
|
|
531
|
+
TState,
|
|
532
|
+
TConnParams,
|
|
533
|
+
TConnState,
|
|
534
|
+
TVars,
|
|
535
|
+
TInput,
|
|
536
|
+
TDatabase,
|
|
537
|
+
TEvents,
|
|
538
|
+
TQueues
|
|
539
|
+
>;
|
|
540
|
+
|
|
317
541
|
/**
|
|
318
542
|
* Called when the actor's state changes.
|
|
319
543
|
*
|
|
@@ -332,7 +556,9 @@ interface BaseActorConfig<
|
|
|
332
556
|
TConnState,
|
|
333
557
|
TVars,
|
|
334
558
|
TInput,
|
|
335
|
-
TDatabase
|
|
559
|
+
TDatabase,
|
|
560
|
+
TEvents,
|
|
561
|
+
TQueues
|
|
336
562
|
>,
|
|
337
563
|
newState: TState,
|
|
338
564
|
) => void;
|
|
@@ -348,7 +574,14 @@ interface BaseActorConfig<
|
|
|
348
574
|
* @throws Throw an error to reject the connection
|
|
349
575
|
*/
|
|
350
576
|
onBeforeConnect?: (
|
|
351
|
-
c: BeforeConnectContext<
|
|
577
|
+
c: BeforeConnectContext<
|
|
578
|
+
TState,
|
|
579
|
+
TVars,
|
|
580
|
+
TInput,
|
|
581
|
+
TDatabase,
|
|
582
|
+
TEvents,
|
|
583
|
+
TQueues
|
|
584
|
+
>,
|
|
352
585
|
params: TConnParams,
|
|
353
586
|
) => void | Promise<void>;
|
|
354
587
|
|
|
@@ -368,9 +601,20 @@ interface BaseActorConfig<
|
|
|
368
601
|
TConnState,
|
|
369
602
|
TVars,
|
|
370
603
|
TInput,
|
|
371
|
-
TDatabase
|
|
604
|
+
TDatabase,
|
|
605
|
+
TEvents,
|
|
606
|
+
TQueues
|
|
607
|
+
>,
|
|
608
|
+
conn: Conn<
|
|
609
|
+
TState,
|
|
610
|
+
TConnParams,
|
|
611
|
+
TConnState,
|
|
612
|
+
TVars,
|
|
613
|
+
TInput,
|
|
614
|
+
TDatabase,
|
|
615
|
+
TEvents,
|
|
616
|
+
TQueues
|
|
372
617
|
>,
|
|
373
|
-
conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>,
|
|
374
618
|
) => void | Promise<void>;
|
|
375
619
|
|
|
376
620
|
/**
|
|
@@ -389,9 +633,20 @@ interface BaseActorConfig<
|
|
|
389
633
|
TConnState,
|
|
390
634
|
TVars,
|
|
391
635
|
TInput,
|
|
392
|
-
TDatabase
|
|
636
|
+
TDatabase,
|
|
637
|
+
TEvents,
|
|
638
|
+
TQueues
|
|
639
|
+
>,
|
|
640
|
+
conn: Conn<
|
|
641
|
+
TState,
|
|
642
|
+
TConnParams,
|
|
643
|
+
TConnState,
|
|
644
|
+
TVars,
|
|
645
|
+
TInput,
|
|
646
|
+
TDatabase,
|
|
647
|
+
TEvents,
|
|
648
|
+
TQueues
|
|
393
649
|
>,
|
|
394
|
-
conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>,
|
|
395
650
|
) => void | Promise<void>;
|
|
396
651
|
|
|
397
652
|
/**
|
|
@@ -413,7 +668,9 @@ interface BaseActorConfig<
|
|
|
413
668
|
TConnState,
|
|
414
669
|
TVars,
|
|
415
670
|
TInput,
|
|
416
|
-
TDatabase
|
|
671
|
+
TDatabase,
|
|
672
|
+
TEvents,
|
|
673
|
+
TQueues
|
|
417
674
|
>,
|
|
418
675
|
name: string,
|
|
419
676
|
args: unknown[],
|
|
@@ -438,7 +695,9 @@ interface BaseActorConfig<
|
|
|
438
695
|
TConnState,
|
|
439
696
|
TVars,
|
|
440
697
|
TInput,
|
|
441
|
-
TDatabase
|
|
698
|
+
TDatabase,
|
|
699
|
+
TEvents,
|
|
700
|
+
TQueues
|
|
442
701
|
>,
|
|
443
702
|
request: Request,
|
|
444
703
|
) => Response | Promise<Response>;
|
|
@@ -460,21 +719,33 @@ interface BaseActorConfig<
|
|
|
460
719
|
TConnState,
|
|
461
720
|
TVars,
|
|
462
721
|
TInput,
|
|
463
|
-
TDatabase
|
|
722
|
+
TDatabase,
|
|
723
|
+
TEvents,
|
|
724
|
+
TQueues
|
|
464
725
|
>,
|
|
465
726
|
websocket: UniversalWebSocket,
|
|
466
727
|
) => void | Promise<void>;
|
|
467
728
|
|
|
468
729
|
actions?: TActions;
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Schema map for events broadcasted by this actor.
|
|
733
|
+
*/
|
|
734
|
+
events?: TEvents;
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Schema map for queue payloads sent by this actor.
|
|
738
|
+
*/
|
|
739
|
+
queues?: TQueues;
|
|
469
740
|
}
|
|
470
741
|
|
|
471
742
|
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> =
|
|
472
743
|
| {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
744
|
+
/**
|
|
745
|
+
* @experimental
|
|
746
|
+
*/
|
|
747
|
+
db: TDatabase;
|
|
748
|
+
}
|
|
478
749
|
| Record<never, never>;
|
|
479
750
|
|
|
480
751
|
// 1. Infer schema
|
|
@@ -487,12 +758,18 @@ export type ActorConfig<
|
|
|
487
758
|
TVars,
|
|
488
759
|
TInput,
|
|
489
760
|
TDatabase extends AnyDatabaseProvider,
|
|
761
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
762
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
490
763
|
> = Omit<
|
|
491
764
|
z.infer<typeof ActorConfigSchema>,
|
|
492
765
|
| "actions"
|
|
766
|
+
| "events"
|
|
767
|
+
| "queues"
|
|
493
768
|
| "onCreate"
|
|
494
769
|
| "onDestroy"
|
|
495
770
|
| "onWake"
|
|
771
|
+
| "onSleep"
|
|
772
|
+
| "run"
|
|
496
773
|
| "onStateChange"
|
|
497
774
|
| "onBeforeConnect"
|
|
498
775
|
| "onConnect"
|
|
@@ -515,11 +792,49 @@ export type ActorConfig<
|
|
|
515
792
|
TVars,
|
|
516
793
|
TInput,
|
|
517
794
|
TDatabase,
|
|
518
|
-
|
|
795
|
+
TEvents,
|
|
796
|
+
TQueues,
|
|
797
|
+
Actions<
|
|
798
|
+
TState,
|
|
799
|
+
TConnParams,
|
|
800
|
+
TConnState,
|
|
801
|
+
TVars,
|
|
802
|
+
TInput,
|
|
803
|
+
TDatabase,
|
|
804
|
+
TEvents,
|
|
805
|
+
TQueues
|
|
806
|
+
>
|
|
807
|
+
> &
|
|
808
|
+
CreateState<
|
|
809
|
+
TState,
|
|
810
|
+
TConnParams,
|
|
811
|
+
TConnState,
|
|
812
|
+
TVars,
|
|
813
|
+
TInput,
|
|
814
|
+
TDatabase,
|
|
815
|
+
TEvents,
|
|
816
|
+
TQueues
|
|
817
|
+
> &
|
|
818
|
+
CreateConnState<
|
|
819
|
+
TState,
|
|
820
|
+
TConnParams,
|
|
821
|
+
TConnState,
|
|
822
|
+
TVars,
|
|
823
|
+
TInput,
|
|
824
|
+
TDatabase,
|
|
825
|
+
TEvents,
|
|
826
|
+
TQueues
|
|
827
|
+
> &
|
|
828
|
+
CreateVars<
|
|
829
|
+
TState,
|
|
830
|
+
TConnParams,
|
|
831
|
+
TConnState,
|
|
832
|
+
TVars,
|
|
833
|
+
TInput,
|
|
834
|
+
TDatabase,
|
|
835
|
+
TEvents,
|
|
836
|
+
TQueues
|
|
519
837
|
> &
|
|
520
|
-
CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> &
|
|
521
|
-
CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> &
|
|
522
|
-
CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> &
|
|
523
838
|
ActorDatabaseConfig<TDatabase>;
|
|
524
839
|
|
|
525
840
|
// See description on `ActorConfig`
|
|
@@ -530,13 +845,17 @@ export type ActorConfigInput<
|
|
|
530
845
|
TVars = undefined,
|
|
531
846
|
TInput = undefined,
|
|
532
847
|
TDatabase extends AnyDatabaseProvider = undefined,
|
|
848
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
849
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
533
850
|
TActions extends Actions<
|
|
534
851
|
TState,
|
|
535
852
|
TConnParams,
|
|
536
853
|
TConnState,
|
|
537
854
|
TVars,
|
|
538
855
|
TInput,
|
|
539
|
-
TDatabase
|
|
856
|
+
TDatabase,
|
|
857
|
+
TEvents,
|
|
858
|
+
TQueues
|
|
540
859
|
> = Record<never, never>,
|
|
541
860
|
> = {
|
|
542
861
|
types?: ActorTypes<
|
|
@@ -550,10 +869,13 @@ export type ActorConfigInput<
|
|
|
550
869
|
} & Omit<
|
|
551
870
|
z.input<typeof ActorConfigSchema>,
|
|
552
871
|
| "actions"
|
|
872
|
+
| "events"
|
|
873
|
+
| "queues"
|
|
553
874
|
| "onCreate"
|
|
554
875
|
| "onDestroy"
|
|
555
876
|
| "onWake"
|
|
556
877
|
| "onSleep"
|
|
878
|
+
| "run"
|
|
557
879
|
| "onStateChange"
|
|
558
880
|
| "onBeforeConnect"
|
|
559
881
|
| "onConnect"
|
|
@@ -576,11 +898,40 @@ export type ActorConfigInput<
|
|
|
576
898
|
TVars,
|
|
577
899
|
TInput,
|
|
578
900
|
TDatabase,
|
|
901
|
+
TEvents,
|
|
902
|
+
TQueues,
|
|
579
903
|
TActions
|
|
580
904
|
> &
|
|
581
|
-
CreateState<
|
|
582
|
-
|
|
583
|
-
|
|
905
|
+
CreateState<
|
|
906
|
+
TState,
|
|
907
|
+
TConnParams,
|
|
908
|
+
TConnState,
|
|
909
|
+
TVars,
|
|
910
|
+
TInput,
|
|
911
|
+
TDatabase,
|
|
912
|
+
TEvents,
|
|
913
|
+
TQueues
|
|
914
|
+
> &
|
|
915
|
+
CreateConnState<
|
|
916
|
+
TState,
|
|
917
|
+
TConnParams,
|
|
918
|
+
TConnState,
|
|
919
|
+
TVars,
|
|
920
|
+
TInput,
|
|
921
|
+
TDatabase,
|
|
922
|
+
TEvents,
|
|
923
|
+
TQueues
|
|
924
|
+
> &
|
|
925
|
+
CreateVars<
|
|
926
|
+
TState,
|
|
927
|
+
TConnParams,
|
|
928
|
+
TConnState,
|
|
929
|
+
TVars,
|
|
930
|
+
TInput,
|
|
931
|
+
TDatabase,
|
|
932
|
+
TEvents,
|
|
933
|
+
TQueues
|
|
934
|
+
> &
|
|
584
935
|
ActorDatabaseConfig<TDatabase>;
|
|
585
936
|
|
|
586
937
|
// For testing type definitions:
|
|
@@ -591,13 +942,17 @@ export function test<
|
|
|
591
942
|
TVars,
|
|
592
943
|
TInput,
|
|
593
944
|
TDatabase extends AnyDatabaseProvider,
|
|
945
|
+
TEvents extends EventSchemaConfig,
|
|
946
|
+
TQueues extends QueueSchemaConfig,
|
|
594
947
|
TActions extends Actions<
|
|
595
948
|
TState,
|
|
596
949
|
TConnParams,
|
|
597
950
|
TConnState,
|
|
598
951
|
TVars,
|
|
599
952
|
TInput,
|
|
600
|
-
TDatabase
|
|
953
|
+
TDatabase,
|
|
954
|
+
TEvents,
|
|
955
|
+
TQueues
|
|
601
956
|
>,
|
|
602
957
|
>(
|
|
603
958
|
input: ActorConfigInput<
|
|
@@ -607,16 +962,29 @@ export function test<
|
|
|
607
962
|
TVars,
|
|
608
963
|
TInput,
|
|
609
964
|
TDatabase,
|
|
965
|
+
TEvents,
|
|
966
|
+
TQueues,
|
|
610
967
|
TActions
|
|
611
968
|
>,
|
|
612
|
-
): ActorConfig<
|
|
969
|
+
): ActorConfig<
|
|
970
|
+
TState,
|
|
971
|
+
TConnParams,
|
|
972
|
+
TConnState,
|
|
973
|
+
TVars,
|
|
974
|
+
TInput,
|
|
975
|
+
TDatabase,
|
|
976
|
+
TEvents,
|
|
977
|
+
TQueues
|
|
978
|
+
> {
|
|
613
979
|
const config = ActorConfigSchema.parse(input) as ActorConfig<
|
|
614
980
|
TState,
|
|
615
981
|
TConnParams,
|
|
616
982
|
TConnState,
|
|
617
983
|
TVars,
|
|
618
984
|
TInput,
|
|
619
|
-
TDatabase
|
|
985
|
+
TDatabase,
|
|
986
|
+
TEvents,
|
|
987
|
+
TQueues
|
|
620
988
|
>;
|
|
621
989
|
return config;
|
|
622
990
|
}
|
|
@@ -627,6 +995,16 @@ export function test<
|
|
|
627
995
|
|
|
628
996
|
export const DocActorOptionsSchema = z
|
|
629
997
|
.object({
|
|
998
|
+
name: z
|
|
999
|
+
.string()
|
|
1000
|
+
.optional()
|
|
1001
|
+
.describe("Display name for the actor in the Inspector UI."),
|
|
1002
|
+
icon: z
|
|
1003
|
+
.string()
|
|
1004
|
+
.optional()
|
|
1005
|
+
.describe(
|
|
1006
|
+
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '🚀') or FontAwesome icon name (e.g., 'rocket').",
|
|
1007
|
+
),
|
|
630
1008
|
createVarsTimeout: z
|
|
631
1009
|
.number()
|
|
632
1010
|
.optional()
|
|
@@ -667,6 +1045,12 @@ export const DocActorOptionsSchema = z
|
|
|
667
1045
|
.describe(
|
|
668
1046
|
"Max time in ms to wait for waitUntil background promises during shutdown. Default: 15000",
|
|
669
1047
|
),
|
|
1048
|
+
runStopTimeout: z
|
|
1049
|
+
.number()
|
|
1050
|
+
.optional()
|
|
1051
|
+
.describe(
|
|
1052
|
+
"Max time in ms to wait for run handler to stop during shutdown. Default: 15000",
|
|
1053
|
+
),
|
|
670
1054
|
connectionLivenessTimeout: z
|
|
671
1055
|
.number()
|
|
672
1056
|
.optional()
|
|
@@ -689,6 +1073,18 @@ export const DocActorOptionsSchema = z
|
|
|
689
1073
|
.describe(
|
|
690
1074
|
"Time in ms of inactivity before the actor sleeps. Default: 30000",
|
|
691
1075
|
),
|
|
1076
|
+
maxQueueSize: z
|
|
1077
|
+
.number()
|
|
1078
|
+
.optional()
|
|
1079
|
+
.describe(
|
|
1080
|
+
"Maximum number of queue messages before rejecting new messages. Default: 1000",
|
|
1081
|
+
),
|
|
1082
|
+
maxQueueMessageSize: z
|
|
1083
|
+
.number()
|
|
1084
|
+
.optional()
|
|
1085
|
+
.describe(
|
|
1086
|
+
"Maximum size of each queue message in bytes. Default: 65536",
|
|
1087
|
+
),
|
|
692
1088
|
canHibernateWebSocket: z
|
|
693
1089
|
.boolean()
|
|
694
1090
|
.optional()
|
|
@@ -762,22 +1158,28 @@ export const DocActorConfigSchema = z
|
|
|
762
1158
|
.describe(
|
|
763
1159
|
"Called when the actor is stopping or sleeping. Use to clean up resources.",
|
|
764
1160
|
),
|
|
765
|
-
|
|
1161
|
+
run: z
|
|
766
1162
|
.unknown()
|
|
767
1163
|
.optional()
|
|
768
1164
|
.describe(
|
|
769
|
-
"Called
|
|
1165
|
+
"Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits or throws, the actor crashes.",
|
|
770
1166
|
),
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
1167
|
+
onStateChange: z
|
|
1168
|
+
.unknown()
|
|
1169
|
+
.optional()
|
|
1170
|
+
.describe(
|
|
1171
|
+
"Called when the actor's state changes. State changes within this hook won't trigger recursion.",
|
|
1172
|
+
),
|
|
1173
|
+
onBeforeConnect: z
|
|
1174
|
+
.unknown()
|
|
1175
|
+
.optional()
|
|
1176
|
+
.describe(
|
|
1177
|
+
"Called before a client connects. Throw an error to reject the connection.",
|
|
1178
|
+
),
|
|
1179
|
+
onConnect: z
|
|
1180
|
+
.unknown()
|
|
1181
|
+
.optional()
|
|
1182
|
+
.describe("Called when a client successfully connects."),
|
|
781
1183
|
onDisconnect: z
|
|
782
1184
|
.unknown()
|
|
783
1185
|
.optional()
|
|
@@ -806,6 +1208,14 @@ export const DocActorConfigSchema = z
|
|
|
806
1208
|
.describe(
|
|
807
1209
|
"Map of action name to handler function. Defaults to an empty object.",
|
|
808
1210
|
),
|
|
1211
|
+
events: z
|
|
1212
|
+
.record(z.string(), z.unknown())
|
|
1213
|
+
.optional()
|
|
1214
|
+
.describe("Map of event names to schemas."),
|
|
1215
|
+
queues: z
|
|
1216
|
+
.record(z.string(), z.unknown())
|
|
1217
|
+
.optional()
|
|
1218
|
+
.describe("Map of queue names to schemas."),
|
|
809
1219
|
options: DocActorOptionsSchema.optional(),
|
|
810
1220
|
})
|
|
811
1221
|
.describe("Actor configuration passed to the actor() function.");
|