rivetkit 2.0.2 → 2.0.4-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/README.md +3 -5
- package/dist/browser/client.d.ts +2485 -0
- 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/inspector.tar.gz +0 -0
- package/dist/schemas/actor-inspector/v1.ts +784 -0
- package/dist/schemas/actor-inspector/v2.ts +796 -0
- package/dist/schemas/actor-inspector/v3.ts +899 -0
- package/dist/schemas/actor-persist/v1.ts +225 -0
- package/dist/schemas/actor-persist/v2.ts +268 -0
- package/dist/schemas/actor-persist/v3.ts +280 -0
- package/dist/schemas/actor-persist/v4.ts +406 -0
- package/dist/schemas/client-protocol/v1.ts +441 -0
- package/dist/schemas/client-protocol/v2.ts +438 -0
- package/dist/schemas/client-protocol/v3.ts +554 -0
- package/dist/schemas/file-system-driver/v1.ts +108 -0
- package/dist/schemas/file-system-driver/v2.ts +142 -0
- package/dist/schemas/file-system-driver/v3.ts +167 -0
- package/dist/schemas/persist/v1.ts +781 -0
- package/dist/schemas/transport/v1.ts +697 -0
- package/dist/tsup/actor/errors.cjs +106 -0
- package/dist/tsup/actor/errors.cjs.map +1 -0
- package/dist/tsup/actor/errors.d.cts +188 -0
- package/dist/tsup/actor/errors.d.ts +188 -0
- package/dist/tsup/actor/errors.js +106 -0
- package/dist/tsup/actor/errors.js.map +1 -0
- package/dist/tsup/actor-router-consts-D29T1Z-K.d.cts +24 -0
- package/dist/tsup/actor-router-consts-D29T1Z-K.d.ts +24 -0
- package/dist/tsup/chunk-325TLXJT.js +1060 -0
- package/dist/tsup/chunk-325TLXJT.js.map +1 -0
- package/dist/tsup/chunk-424PT5DM.js +23 -0
- package/dist/tsup/chunk-424PT5DM.js.map +1 -0
- package/dist/tsup/chunk-4JVIG3SS.cjs +6289 -0
- package/dist/tsup/chunk-4JVIG3SS.cjs.map +1 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
- package/dist/tsup/chunk-6XU3FMCB.cjs +534 -0
- package/dist/tsup/chunk-6XU3FMCB.cjs.map +1 -0
- package/dist/tsup/chunk-7HTNH26M.js +509 -0
- package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
- package/dist/tsup/chunk-AUVH72RE.cjs +5977 -0
- package/dist/tsup/chunk-AUVH72RE.cjs.map +1 -0
- package/dist/tsup/chunk-D4BYUPNQ.js +645 -0
- package/dist/tsup/chunk-D4BYUPNQ.js.map +1 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
- package/dist/tsup/chunk-HHXX2VRM.js +6289 -0
- package/dist/tsup/chunk-HHXX2VRM.js.map +1 -0
- package/dist/tsup/chunk-JEAEA2PB.js +49 -0
- package/dist/tsup/chunk-JEAEA2PB.js.map +1 -0
- package/dist/tsup/chunk-JYSEG3VF.cjs +642 -0
- package/dist/tsup/chunk-JYSEG3VF.cjs.map +1 -0
- package/dist/tsup/chunk-K6DGYILQ.js +2657 -0
- package/dist/tsup/chunk-K6DGYILQ.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-L47L3ZWJ.cjs +509 -0
- package/dist/tsup/chunk-L47L3ZWJ.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-MXNPAB5W.js +5977 -0
- package/dist/tsup/chunk-MXNPAB5W.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-PQZHDKRW.cjs +1060 -0
- package/dist/tsup/chunk-PQZHDKRW.cjs.map +1 -0
- package/dist/tsup/chunk-PVOE6BU7.cjs +1050 -0
- package/dist/tsup/chunk-PVOE6BU7.cjs.map +1 -0
- package/dist/tsup/chunk-Q4UD2GA4.cjs +1810 -0
- package/dist/tsup/chunk-Q4UD2GA4.cjs.map +1 -0
- package/dist/tsup/chunk-QUD664YZ.js +1810 -0
- package/dist/tsup/chunk-QUD664YZ.js.map +1 -0
- package/dist/tsup/chunk-RTOCTWME.js +1050 -0
- package/dist/tsup/chunk-RTOCTWME.js.map +1 -0
- package/dist/tsup/chunk-SAZZ4SB2.cjs +2657 -0
- package/dist/tsup/chunk-SAZZ4SB2.cjs.map +1 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
- package/dist/tsup/chunk-V2GHLYC6.cjs +49 -0
- package/dist/tsup/chunk-V2GHLYC6.cjs.map +1 -0
- package/dist/tsup/chunk-V3WG7XTW.cjs +645 -0
- package/dist/tsup/chunk-V3WG7XTW.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-WMPW7JYC.js +642 -0
- package/dist/tsup/chunk-WMPW7JYC.js.map +1 -0
- package/dist/tsup/chunk-Z7HNQ2WF.js +534 -0
- package/dist/tsup/chunk-Z7HNQ2WF.js.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 +33 -0
- package/dist/tsup/client/mod.cjs.map +1 -0
- package/dist/tsup/client/mod.d.cts +64 -0
- package/dist/tsup/client/mod.d.ts +64 -0
- package/dist/tsup/client/mod.js +33 -0
- package/dist/tsup/client/mod.js.map +1 -0
- package/dist/tsup/common/log.cjs +21 -0
- package/dist/tsup/common/log.cjs.map +1 -0
- package/dist/tsup/common/log.d.cts +34 -0
- package/dist/tsup/common/log.d.ts +34 -0
- package/dist/tsup/common/log.js +21 -0
- package/dist/tsup/common/log.js.map +1 -0
- package/dist/tsup/common/websocket.cjs +10 -0
- package/dist/tsup/common/websocket.cjs.map +1 -0
- package/dist/tsup/common/websocket.d.cts +3 -0
- package/dist/tsup/common/websocket.d.ts +3 -0
- package/dist/tsup/common/websocket.js +10 -0
- package/dist/tsup/common/websocket.js.map +1 -0
- package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
- package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
- package/dist/tsup/config-P3XujgRr.d.ts +2594 -0
- package/dist/tsup/config-_gfywqqI.d.cts +2594 -0
- package/dist/tsup/context-Bxd8Cx4H.d.cts +75 -0
- package/dist/tsup/context-uNA4TRn3.d.ts +75 -0
- 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-BcLvZcKl.d.cts +13 -0
- package/dist/tsup/driver-CPGHKXyh.d.ts +13 -0
- package/dist/tsup/driver-helpers/mod.cjs +53 -0
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -0
- package/dist/tsup/driver-helpers/mod.d.cts +47 -0
- package/dist/tsup/driver-helpers/mod.d.ts +47 -0
- package/dist/tsup/driver-helpers/mod.js +53 -0
- package/dist/tsup/driver-helpers/mod.js.map +1 -0
- package/dist/tsup/driver-test-suite/mod.cjs +4974 -0
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -0
- package/dist/tsup/driver-test-suite/mod.d.cts +73 -0
- package/dist/tsup/driver-test-suite/mod.d.ts +73 -0
- package/dist/tsup/driver-test-suite/mod.js +4974 -0
- package/dist/tsup/driver-test-suite/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +164 -0
- package/dist/tsup/inspector/mod.cjs.map +1 -0
- package/dist/tsup/inspector/mod.d.cts +130 -0
- package/dist/tsup/inspector/mod.d.ts +130 -0
- package/dist/tsup/inspector/mod.js +164 -0
- package/dist/tsup/inspector/mod.js.map +1 -0
- package/dist/tsup/keys-CydblqMh.d.cts +13 -0
- package/dist/tsup/keys-CydblqMh.d.ts +13 -0
- package/dist/tsup/mod.cjs +82 -0
- package/dist/tsup/mod.cjs.map +1 -0
- package/dist/tsup/mod.d.cts +126 -0
- package/dist/tsup/mod.d.ts +126 -0
- package/dist/tsup/mod.js +82 -0
- package/dist/tsup/mod.js.map +1 -0
- package/dist/tsup/serve-test-suite/mod.cjs +2601 -0
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -0
- package/dist/tsup/serve-test-suite/mod.d.cts +9 -0
- package/dist/tsup/serve-test-suite/mod.d.ts +9 -0
- package/dist/tsup/serve-test-suite/mod.js +2601 -0
- package/dist/tsup/serve-test-suite/mod.js.map +1 -0
- package/dist/tsup/test/mod.cjs +90 -0
- package/dist/tsup/test/mod.cjs.map +1 -0
- package/dist/tsup/test/mod.d.cts +26 -0
- package/dist/tsup/test/mod.d.ts +26 -0
- package/dist/tsup/test/mod.js +90 -0
- package/dist/tsup/test/mod.js.map +1 -0
- package/dist/tsup/utils-fwx3o3K9.d.cts +18 -0
- package/dist/tsup/utils-fwx3o3K9.d.ts +18 -0
- package/dist/tsup/utils.cjs +43 -0
- package/dist/tsup/utils.cjs.map +1 -0
- package/dist/tsup/utils.d.cts +148 -0
- package/dist/tsup/utils.d.ts +148 -0
- package/dist/tsup/utils.js +43 -0
- package/dist/tsup/utils.js.map +1 -0
- 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 +25 -0
- package/dist/tsup/workflow/mod.d.ts +25 -0
- package/dist/tsup/workflow/mod.js +16 -0
- package/dist/tsup/workflow/mod.js.map +1 -0
- package/package.json +293 -5
- package/src/actor/config.ts +1221 -0
- package/src/actor/conn/driver.ts +61 -0
- package/src/actor/conn/drivers/http.ts +17 -0
- package/src/actor/conn/drivers/raw-request.ts +24 -0
- package/src/actor/conn/drivers/raw-websocket.ts +65 -0
- package/src/actor/conn/drivers/websocket.ts +144 -0
- package/src/actor/conn/mod.ts +288 -0
- package/src/actor/conn/persisted.ts +81 -0
- package/src/actor/conn/state-manager.ts +196 -0
- package/src/actor/contexts/action.ts +47 -0
- package/src/actor/contexts/base/actor.ts +347 -0
- package/src/actor/contexts/base/conn-init.ts +68 -0
- package/src/actor/contexts/base/conn.ts +73 -0
- package/src/actor/contexts/before-action-response.ts +42 -0
- package/src/actor/contexts/before-connect.ts +31 -0
- package/src/actor/contexts/connect.ts +42 -0
- package/src/actor/contexts/create-conn-state.ts +32 -0
- package/src/actor/contexts/create-vars.ts +39 -0
- package/src/actor/contexts/create.ts +39 -0
- package/src/actor/contexts/destroy.ts +42 -0
- package/src/actor/contexts/disconnect.ts +43 -0
- package/src/actor/contexts/index.ts +33 -0
- package/src/actor/contexts/request.ts +80 -0
- package/src/actor/contexts/run.ts +47 -0
- package/src/actor/contexts/sleep.ts +42 -0
- package/src/actor/contexts/state-change.ts +42 -0
- package/src/actor/contexts/wake.ts +42 -0
- package/src/actor/contexts/websocket.ts +80 -0
- package/src/actor/database.ts +13 -0
- package/src/actor/definition.ts +64 -0
- package/src/actor/driver.ts +114 -0
- package/src/actor/errors.ts +556 -0
- package/src/actor/instance/connection-manager.ts +574 -0
- package/src/actor/instance/event-manager.ts +314 -0
- package/src/actor/instance/keys.ts +146 -0
- package/src/actor/instance/kv.ts +241 -0
- package/src/actor/instance/mod.ts +1658 -0
- package/src/actor/instance/persisted.ts +67 -0
- package/src/actor/instance/queue-manager.ts +603 -0
- package/src/actor/instance/queue.ts +345 -0
- package/src/actor/instance/schedule-manager.ts +392 -0
- package/src/actor/instance/state-manager.ts +542 -0
- package/src/actor/instance/traces-driver.ts +128 -0
- package/src/actor/keys.test.ts +275 -0
- package/src/actor/keys.ts +89 -0
- package/src/actor/log.ts +6 -0
- package/src/actor/mod.ts +110 -0
- package/src/actor/protocol/old.ts +416 -0
- package/src/actor/protocol/serde.ts +222 -0
- package/src/actor/router-endpoints.ts +400 -0
- package/src/actor/router-websocket-endpoints.test.ts +54 -0
- package/src/actor/router-websocket-endpoints.ts +405 -0
- package/src/actor/router.ts +380 -0
- package/src/actor/schedule.ts +17 -0
- package/src/actor/schema.ts +291 -0
- package/src/actor/utils.test.ts +48 -0
- package/src/actor/utils.ts +158 -0
- package/src/client/actor-common.ts +32 -0
- package/src/client/actor-conn.ts +1262 -0
- package/src/client/actor-handle.ts +344 -0
- package/src/client/actor-query.ts +112 -0
- package/src/client/client.ts +558 -0
- package/src/client/config.ts +151 -0
- package/src/client/errors.ts +76 -0
- package/src/client/log.ts +5 -0
- package/src/client/mod.browser.ts +2 -0
- package/src/client/mod.ts +70 -0
- package/src/client/queue.ts +146 -0
- package/src/client/raw-utils.ts +149 -0
- package/src/client/test.ts +44 -0
- package/src/client/utils.ts +252 -0
- package/src/common/actor-router-consts.ts +59 -0
- package/src/common/cors.ts +57 -0
- package/src/common/eventsource-interface.ts +47 -0
- package/src/common/eventsource.ts +44 -0
- package/src/common/inline-websocket-adapter.ts +154 -0
- package/src/common/log-levels.ts +27 -0
- package/src/common/log.ts +229 -0
- package/src/common/logfmt.ts +221 -0
- package/src/common/network.ts +2 -0
- package/src/common/router.ts +174 -0
- package/src/common/utils.ts +339 -0
- package/src/common/websocket-interface.ts +7 -0
- package/src/common/websocket.ts +43 -0
- 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/devtools-loader/index.ts +33 -0
- package/src/devtools-loader/log.ts +5 -0
- package/src/driver-helpers/mod.ts +33 -0
- package/src/driver-helpers/utils.ts +54 -0
- package/src/driver-test-suite/log.ts +5 -0
- package/src/driver-test-suite/mod.ts +293 -0
- package/src/driver-test-suite/test-inline-client-driver.ts +307 -0
- package/src/driver-test-suite/tests/access-control.ts +218 -0
- package/src/driver-test-suite/tests/action-features.ts +203 -0
- package/src/driver-test-suite/tests/actor-conn-hibernation.ts +152 -0
- package/src/driver-test-suite/tests/actor-conn-state.ts +300 -0
- package/src/driver-test-suite/tests/actor-conn.ts +596 -0
- package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
- package/src/driver-test-suite/tests/actor-db.ts +477 -0
- package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
- package/src/driver-test-suite/tests/actor-driver.ts +18 -0
- package/src/driver-test-suite/tests/actor-error-handling.ts +150 -0
- package/src/driver-test-suite/tests/actor-handle.ts +312 -0
- package/src/driver-test-suite/tests/actor-inline-client.ts +163 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +264 -0
- package/src/driver-test-suite/tests/actor-kv.ts +65 -0
- package/src/driver-test-suite/tests/actor-metadata.ts +116 -0
- package/src/driver-test-suite/tests/actor-onstatechange.ts +95 -0
- package/src/driver-test-suite/tests/actor-queue.ts +325 -0
- package/src/driver-test-suite/tests/actor-run.ts +181 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +97 -0
- package/src/driver-test-suite/tests/actor-sleep.ts +415 -0
- package/src/driver-test-suite/tests/actor-state.ts +54 -0
- package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
- package/src/driver-test-suite/tests/actor-vars.ts +97 -0
- package/src/driver-test-suite/tests/actor-workflow.ts +118 -0
- package/src/driver-test-suite/tests/manager-driver.ts +388 -0
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -0
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +454 -0
- package/src/driver-test-suite/tests/raw-http.ts +359 -0
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -0
- package/src/driver-test-suite/tests/raw-websocket.ts +513 -0
- package/src/driver-test-suite/tests/request-access.ts +240 -0
- package/src/driver-test-suite/utils.ts +80 -0
- package/src/drivers/default.ts +38 -0
- package/src/drivers/engine/actor-driver.ts +1027 -0
- package/src/drivers/engine/config.ts +43 -0
- package/src/drivers/engine/log.ts +5 -0
- package/src/drivers/engine/mod.ts +36 -0
- package/src/drivers/file-system/actor.ts +102 -0
- package/src/drivers/file-system/global-state.ts +1445 -0
- package/src/drivers/file-system/kv-limits.ts +70 -0
- package/src/drivers/file-system/log.ts +5 -0
- package/src/drivers/file-system/manager.ts +300 -0
- package/src/drivers/file-system/mod.ts +78 -0
- package/src/drivers/file-system/sqlite-runtime.ts +210 -0
- package/src/drivers/file-system/utils.ts +125 -0
- package/src/engine-process/constants.ts +2 -0
- package/src/engine-process/log.ts +5 -0
- package/src/engine-process/mod.ts +464 -0
- package/src/globals.d.ts +35 -0
- package/src/inspector/actor-inspector.ts +352 -0
- package/src/inspector/config.ts +49 -0
- package/src/inspector/handler.ts +273 -0
- package/src/inspector/log.ts +5 -0
- package/src/inspector/mod.browser.ts +8 -0
- package/src/inspector/mod.ts +4 -0
- package/src/inspector/serve-ui.ts +40 -0
- package/src/inspector/transport.ts +18 -0
- package/src/inspector/utils.ts +32 -0
- package/src/manager/driver.ts +106 -0
- package/src/manager/gateway.ts +668 -0
- package/src/manager/log.ts +5 -0
- package/src/manager/mod.ts +2 -0
- package/src/manager/protocol/mod.ts +22 -0
- package/src/manager/protocol/query.ts +85 -0
- package/src/manager/router-schema.ts +22 -0
- package/src/manager/router.ts +660 -0
- package/src/manager-api/actors.ts +83 -0
- package/src/manager-api/common.ts +4 -0
- package/src/mod.ts +24 -0
- package/src/registry/config/driver.ts +21 -0
- package/src/registry/config/index.ts +510 -0
- package/src/registry/config/legacy-runner.ts +157 -0
- package/src/registry/config/runner.ts +21 -0
- package/src/registry/config/serverless.ts +94 -0
- package/src/registry/index.ts +194 -0
- package/src/registry/log.ts +5 -0
- package/src/remote-manager-driver/actor-http-client.ts +84 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +81 -0
- package/src/remote-manager-driver/api-endpoints.ts +159 -0
- package/src/remote-manager-driver/api-utils.ts +69 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/metadata.ts +64 -0
- package/src/remote-manager-driver/mod.ts +414 -0
- package/src/remote-manager-driver/ws-proxy.ts +189 -0
- package/src/schemas/actor-inspector/mod.ts +1 -0
- package/src/schemas/actor-inspector/versioned.ts +233 -0
- package/src/schemas/actor-persist/mod.ts +1 -0
- package/src/schemas/actor-persist/versioned.ts +217 -0
- package/src/schemas/client-protocol/mod.ts +1 -0
- package/src/schemas/client-protocol/versioned.ts +330 -0
- package/src/schemas/client-protocol-zod/mod.ts +118 -0
- package/src/schemas/file-system-driver/mod.ts +1 -0
- package/src/schemas/file-system-driver/versioned.ts +135 -0
- package/src/schemas/persist/mod.ts +1 -0
- package/src/schemas/transport/mod.ts +1 -0
- package/src/serde.ts +138 -0
- package/src/serve-test-suite/mod.ts +148 -0
- package/src/serverless/configure.ts +82 -0
- package/src/serverless/log.ts +5 -0
- package/src/serverless/router.test.ts +299 -0
- package/src/serverless/router.ts +215 -0
- package/src/test/log.ts +5 -0
- package/src/test/mod.ts +99 -0
- package/src/utils/crypto.ts +24 -0
- package/src/utils/endpoint-parser.test.ts +202 -0
- package/src/utils/endpoint-parser.ts +124 -0
- package/src/utils/env-vars.ts +78 -0
- package/src/utils/node.ts +178 -0
- package/src/utils/router.ts +83 -0
- package/src/utils/serve.ts +212 -0
- package/src/utils.test.ts +34 -0
- package/src/utils.ts +437 -0
- package/src/workflow/constants.ts +2 -0
- package/src/workflow/context.ts +597 -0
- package/src/workflow/driver.ts +194 -0
- package/src/workflow/inspector.ts +268 -0
- package/src/workflow/mod.ts +128 -0
|
@@ -0,0 +1,2485 @@
|
|
|
1
|
+
import z$2, { z } from 'zod/v4';
|
|
2
|
+
import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
|
|
3
|
+
import { SqliteVfs } from '@rivetkit/sqlite-vfs';
|
|
4
|
+
import { Traces, OtlpExportTraceServiceRequestJson, SpanHandle, SpanStatusInput } from '@rivetkit/traces';
|
|
5
|
+
import { Context, Handler, Env, Hono } from 'hono';
|
|
6
|
+
import { z as z$1 } from 'zod';
|
|
7
|
+
import { Logger } from 'pino';
|
|
8
|
+
import { VersionedDataHandler } from 'vbare';
|
|
9
|
+
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
10
|
+
import * as nanoevents from 'nanoevents';
|
|
11
|
+
import { W as WorkflowHistory, k as QueueStatus } from './v3-DnYObHH3.js';
|
|
12
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
13
|
+
import '@rivetkit/bare-ts';
|
|
14
|
+
|
|
15
|
+
type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Context provided to database providers for creating database clients
|
|
18
|
+
*/
|
|
19
|
+
interface DatabaseProviderContext {
|
|
20
|
+
/**
|
|
21
|
+
* Actor ID
|
|
22
|
+
*/
|
|
23
|
+
actorId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Override the default raw database client (optional).
|
|
26
|
+
* If not provided, a KV-backed client will be constructed.
|
|
27
|
+
*/
|
|
28
|
+
overrideRawDatabaseClient?: () => Promise<RawDatabaseClient | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Override the default Drizzle database client (optional).
|
|
31
|
+
* If not provided, a KV-backed client will be constructed.
|
|
32
|
+
*/
|
|
33
|
+
overrideDrizzleDatabaseClient?: () => Promise<DrizzleDatabaseClient | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* KV operations for constructing KV-backed database clients
|
|
36
|
+
*/
|
|
37
|
+
kv: {
|
|
38
|
+
batchPut: (entries: [Uint8Array, Uint8Array][]) => Promise<void>;
|
|
39
|
+
batchGet: (keys: Uint8Array[]) => Promise<(Uint8Array | null)[]>;
|
|
40
|
+
batchDelete: (keys: Uint8Array[]) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* SQLite VFS instance for creating KV-backed databases.
|
|
44
|
+
* This should be actor-scoped because @rivetkit/sqlite is not re-entrant per
|
|
45
|
+
* module instance.
|
|
46
|
+
*/
|
|
47
|
+
sqliteVfs?: SqliteVfs;
|
|
48
|
+
}
|
|
49
|
+
type DatabaseProvider<DB extends RawAccess> = {
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new database client for the actor.
|
|
52
|
+
* The result is passed to the actor context as `c.db`.
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
createClient: (ctx: DatabaseProviderContext) => Promise<DB>;
|
|
56
|
+
/**
|
|
57
|
+
* Runs before the actor has started.
|
|
58
|
+
* Use this to run migrations or other setup tasks.
|
|
59
|
+
* @experimental
|
|
60
|
+
*/
|
|
61
|
+
onMigrate: (client: DB) => void | Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Runs when the actor is being destroyed.
|
|
64
|
+
* Use this to clean up database connections and release resources.
|
|
65
|
+
* @experimental
|
|
66
|
+
*/
|
|
67
|
+
onDestroy?: (client: DB) => void | Promise<void>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Raw database client with basic exec method
|
|
71
|
+
*/
|
|
72
|
+
interface RawDatabaseClient {
|
|
73
|
+
exec: <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]> | TRow[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Drizzle database client interface (will be extended by drizzle-orm types)
|
|
77
|
+
*/
|
|
78
|
+
interface DrizzleDatabaseClient {
|
|
79
|
+
}
|
|
80
|
+
type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
|
|
81
|
+
type RawAccess = {
|
|
82
|
+
/**
|
|
83
|
+
* Executes a raw SQL query.
|
|
84
|
+
*/
|
|
85
|
+
execute: ExecuteFunction;
|
|
86
|
+
/**
|
|
87
|
+
* Closes the database connection and releases resources.
|
|
88
|
+
*/
|
|
89
|
+
close: () => Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
|
|
93
|
+
|
|
94
|
+
type SchemaHookResult = boolean | Promise<boolean>;
|
|
95
|
+
type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
|
|
96
|
+
interface EventTypeToken<T, TContext = any> {
|
|
97
|
+
readonly _eventType?: T;
|
|
98
|
+
readonly canSubscribe?: SchemaHook<TContext>;
|
|
99
|
+
readonly schema?: PrimitiveSchema;
|
|
100
|
+
}
|
|
101
|
+
interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
|
|
102
|
+
readonly _queueMessage?: TMessage;
|
|
103
|
+
readonly _queueComplete?: TComplete;
|
|
104
|
+
readonly canPublish?: SchemaHook<TContext>;
|
|
105
|
+
readonly message?: PrimitiveSchema;
|
|
106
|
+
readonly complete?: PrimitiveSchema;
|
|
107
|
+
}
|
|
108
|
+
type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
|
|
109
|
+
interface EventSchemaDefinition<TContext = any> {
|
|
110
|
+
schema: PrimitiveSchema;
|
|
111
|
+
canSubscribe?: SchemaHook<TContext>;
|
|
112
|
+
}
|
|
113
|
+
interface QueueSchemaDefinition<TContext = any> {
|
|
114
|
+
message: PrimitiveSchema;
|
|
115
|
+
complete?: PrimitiveSchema;
|
|
116
|
+
canPublish?: SchemaHook<TContext>;
|
|
117
|
+
}
|
|
118
|
+
type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
|
|
119
|
+
type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
|
|
120
|
+
type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
|
|
121
|
+
type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
|
|
122
|
+
type InferSchema<T> = T extends QueueSchemaDefinition<any> ? InferSchema<T["message"]> : T extends QueueTypeToken<infer M, unknown, any> ? M : T extends EventSchemaDefinition<any> ? InferSchema<T["schema"]> : T extends StandardSchemaV1<any, infer O> ? O : T extends EventTypeToken<infer R, any> ? R : never;
|
|
123
|
+
type InferSchemaMap<T extends Record<string, unknown>> = {
|
|
124
|
+
[K in keyof T]: InferSchema<T[K]>;
|
|
125
|
+
};
|
|
126
|
+
type InferQueueComplete<T> = T extends QueueTypeToken<unknown, infer C, any> ? [C] extends [never] ? never : C : T extends QueueSchemaDefinition<any> ? T["complete"] extends PrimitiveSchema ? InferSchema<T["complete"]> : never : never;
|
|
127
|
+
type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
|
|
128
|
+
[K in keyof T]: InferQueueComplete<T[K]>;
|
|
129
|
+
};
|
|
130
|
+
type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* User-facing KV storage interface exposed on ActorContext.
|
|
134
|
+
*/
|
|
135
|
+
type KvValueType = "text" | "arrayBuffer" | "binary";
|
|
136
|
+
type KvKeyType = "text" | "binary";
|
|
137
|
+
type KvKey = Uint8Array | string;
|
|
138
|
+
type KvValueTypeMap = {
|
|
139
|
+
text: string;
|
|
140
|
+
arrayBuffer: ArrayBuffer;
|
|
141
|
+
binary: Uint8Array;
|
|
142
|
+
};
|
|
143
|
+
type KvKeyTypeMap = {
|
|
144
|
+
text: string;
|
|
145
|
+
binary: Uint8Array;
|
|
146
|
+
};
|
|
147
|
+
type KvValueOptions<T extends KvValueType = "text"> = {
|
|
148
|
+
type?: T;
|
|
149
|
+
};
|
|
150
|
+
type KvListOptions<T extends KvValueType = "text", K extends KvKeyType = "text"> = KvValueOptions<T> & {
|
|
151
|
+
keyType?: K;
|
|
152
|
+
};
|
|
153
|
+
declare class ActorKv {
|
|
154
|
+
#private;
|
|
155
|
+
constructor(driver: ActorDriver, actorId: string);
|
|
156
|
+
/**
|
|
157
|
+
* Get a single value by key.
|
|
158
|
+
*/
|
|
159
|
+
get<T extends KvValueType = "text">(key: KvKey, options?: KvValueOptions<T>): Promise<KvValueTypeMap[T] | null>;
|
|
160
|
+
/**
|
|
161
|
+
* Get multiple values by keys.
|
|
162
|
+
*/
|
|
163
|
+
getBatch<T extends KvValueType = "text">(keys: KvKey[], options?: KvValueOptions<T>): Promise<(KvValueTypeMap[T] | null)[]>;
|
|
164
|
+
/**
|
|
165
|
+
* Put a single key-value pair.
|
|
166
|
+
*/
|
|
167
|
+
put<T extends KvValueType = KvValueType>(key: KvKey, value: KvValueTypeMap[T], options?: KvValueOptions<T>): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Put multiple key-value pairs.
|
|
170
|
+
*/
|
|
171
|
+
putBatch<T extends KvValueType = KvValueType>(entries: [KvKey, KvValueTypeMap[T]][], options?: KvValueOptions<T>): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Delete a single key.
|
|
174
|
+
*/
|
|
175
|
+
delete(key: KvKey): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Delete multiple keys.
|
|
178
|
+
*/
|
|
179
|
+
deleteBatch(keys: KvKey[]): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* List all keys with a given prefix.
|
|
182
|
+
* Returns key-value pairs where keys have the user prefix removed.
|
|
183
|
+
*/
|
|
184
|
+
list<T extends KvValueType = "text", K extends KvKeyType = "text">(prefix: KvKeyTypeMap[K], options?: KvListOptions<T, K>): Promise<[KvKeyTypeMap[K], KvValueTypeMap[T]][]>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface QueueMessage {
|
|
188
|
+
id: bigint;
|
|
189
|
+
name: string;
|
|
190
|
+
body: unknown;
|
|
191
|
+
createdAt: number;
|
|
192
|
+
}
|
|
193
|
+
declare class QueueManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
194
|
+
#private;
|
|
195
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>, driver: ActorDriver);
|
|
196
|
+
/** Returns the current number of messages in the queue. */
|
|
197
|
+
get size(): number;
|
|
198
|
+
/** Loads queue metadata from storage and initializes internal state. */
|
|
199
|
+
initialize(): Promise<void>;
|
|
200
|
+
/** Adds a message to the queue with the given name and body. */
|
|
201
|
+
enqueue(name: string, body: unknown): Promise<QueueMessage>;
|
|
202
|
+
/**
|
|
203
|
+
* Adds a message and waits for completion.
|
|
204
|
+
*/
|
|
205
|
+
enqueueAndWait(name: string, body: unknown, timeout?: number): Promise<{
|
|
206
|
+
status: "completed" | "timedOut";
|
|
207
|
+
response?: unknown;
|
|
208
|
+
}>;
|
|
209
|
+
completeMessage(message: QueueMessage, response?: unknown): Promise<void>;
|
|
210
|
+
completeMessageById(messageId: bigint, response?: unknown): Promise<void>;
|
|
211
|
+
/** Receives messages from the queue matching the given names. Waits until messages are available or timeout is reached. */
|
|
212
|
+
receive(names: string[] | undefined, count: number, timeout?: number, abortSignal?: AbortSignal, completable?: boolean): Promise<QueueMessage[]>;
|
|
213
|
+
waitForNames(names: readonly string[] | undefined, abortSignal?: AbortSignal): Promise<void>;
|
|
214
|
+
/** Returns all messages currently in the queue without removing them. */
|
|
215
|
+
getMessages(): Promise<QueueMessage[]>;
|
|
216
|
+
/** Deletes messages matching the provided IDs. Returns the IDs that were removed. */
|
|
217
|
+
deleteMessagesById(ids: bigint[]): Promise<bigint[]>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
type QueueMessageOf<Name extends string, Body> = Omit<QueueMessage, "name" | "body"> & {
|
|
221
|
+
name: Name;
|
|
222
|
+
body: Body;
|
|
223
|
+
};
|
|
224
|
+
type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
|
|
225
|
+
type QueueFilterName<TQueues extends QueueSchemaConfig> = keyof TQueues extends never ? string : QueueName<TQueues>;
|
|
226
|
+
type QueueMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? QueueMessage : TName extends QueueName<TQueues> ? QueueMessageOf<TName, InferSchemaMap<TQueues>[TName]> : never;
|
|
227
|
+
type QueueCompleteArgs<T> = undefined extends T ? [response?: T] : [response: T];
|
|
228
|
+
type QueueCompleteArgsForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? [response?: unknown] : TName extends QueueName<TQueues> ? [InferQueueCompleteMap<TQueues>[TName]] extends [never] ? [response?: unknown] : QueueCompleteArgs<InferQueueCompleteMap<TQueues>[TName]> : [response?: unknown];
|
|
229
|
+
type QueueCompletableMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = QueueMessageForName<TQueues, TName> & {
|
|
230
|
+
complete(...args: QueueCompleteArgsForName<TQueues, TName>): Promise<void>;
|
|
231
|
+
};
|
|
232
|
+
type QueueResultMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>, TCompletable extends boolean> = TCompletable extends true ? QueueCompletableMessageForName<TQueues, TName> : QueueMessageForName<TQueues, TName>;
|
|
233
|
+
/** Options for receiving queue messages. */
|
|
234
|
+
interface QueueNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
235
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
236
|
+
names?: readonly TName[];
|
|
237
|
+
/** Timeout in milliseconds. Omit to wait indefinitely. */
|
|
238
|
+
timeout?: number;
|
|
239
|
+
/** Optional abort signal for this receive call. */
|
|
240
|
+
signal?: AbortSignal;
|
|
241
|
+
/** Whether to return completable messages. */
|
|
242
|
+
completable?: TCompletable;
|
|
243
|
+
}
|
|
244
|
+
/** Options for receiving queue message batches. */
|
|
245
|
+
interface QueueNextBatchOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
246
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
247
|
+
names?: readonly TName[];
|
|
248
|
+
/** Maximum number of messages to receive. Defaults to 1. */
|
|
249
|
+
count?: number;
|
|
250
|
+
/** Timeout in milliseconds. Omit to wait indefinitely. */
|
|
251
|
+
timeout?: number;
|
|
252
|
+
/** Optional abort signal for this receive call. */
|
|
253
|
+
signal?: AbortSignal;
|
|
254
|
+
/** Whether to return completable messages. */
|
|
255
|
+
completable?: TCompletable;
|
|
256
|
+
}
|
|
257
|
+
/** Options for non-blocking queue reads. */
|
|
258
|
+
interface QueueTryNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
259
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
260
|
+
names?: readonly TName[];
|
|
261
|
+
/** Whether to return completable messages. */
|
|
262
|
+
completable?: TCompletable;
|
|
263
|
+
}
|
|
264
|
+
/** Options for non-blocking queue batch reads. */
|
|
265
|
+
interface QueueTryNextBatchOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
266
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
267
|
+
names?: readonly TName[];
|
|
268
|
+
/** Maximum number of messages to receive. Defaults to 1. */
|
|
269
|
+
count?: number;
|
|
270
|
+
/** Whether to return completable messages. */
|
|
271
|
+
completable?: TCompletable;
|
|
272
|
+
}
|
|
273
|
+
/** Options for queue async iteration. */
|
|
274
|
+
interface QueueIterOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
275
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
276
|
+
names?: readonly TName[];
|
|
277
|
+
/** Optional abort signal for this iterator. */
|
|
278
|
+
signal?: AbortSignal;
|
|
279
|
+
/** Whether to return completable messages. */
|
|
280
|
+
completable?: TCompletable;
|
|
281
|
+
}
|
|
282
|
+
/** User-facing queue interface exposed on ActorContext. */
|
|
283
|
+
declare class ActorQueue<S, CP, CS, V, I, DB extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
|
|
284
|
+
#private;
|
|
285
|
+
constructor(queueManager: QueueManager<S, CP, CS, V, I, DB, TEvents, TQueues>, abortSignal: AbortSignal);
|
|
286
|
+
next<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextOptions<TName, TCompletable>): Promise<QueueResultMessageForName<TQueues, TName, TCompletable> | undefined>;
|
|
287
|
+
nextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextBatchOptions<TName, TCompletable>): Promise<Array<QueueResultMessageForName<TQueues, TName, TCompletable>>>;
|
|
288
|
+
tryNext<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<QueueResultMessageForName<TQueues, TName, TCompletable> | undefined>;
|
|
289
|
+
tryNextBatch<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextBatchOptions<TName, TCompletable>): Promise<Array<QueueResultMessageForName<TQueues, TName, TCompletable>>>;
|
|
290
|
+
iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterableIterator<QueueResultMessageForName<TQueues, TName, TCompletable>>;
|
|
291
|
+
/** Sends a message to the specified queue. */
|
|
292
|
+
send<K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K]): Promise<QueueMessage>;
|
|
293
|
+
send(name: keyof TQueues extends never ? string : never, body: unknown): Promise<QueueMessage>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
declare class Schedule {
|
|
297
|
+
#private;
|
|
298
|
+
constructor(actor: AnyActorInstance);
|
|
299
|
+
after(duration: number, fn: string, ...args: unknown[]): Promise<void>;
|
|
300
|
+
at(timestamp: number, fn: string, ...args: unknown[]): Promise<void>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
|
|
304
|
+
/**
|
|
305
|
+
* ActorContext class that provides access to actor methods and state
|
|
306
|
+
*/
|
|
307
|
+
declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
|
|
308
|
+
#private;
|
|
309
|
+
[ACTOR_CONTEXT_INTERNAL_SYMBOL]: AnyActorInstance;
|
|
310
|
+
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>);
|
|
311
|
+
/**
|
|
312
|
+
* Gets the KV storage interface.
|
|
313
|
+
*/
|
|
314
|
+
get kv(): ActorKv;
|
|
315
|
+
/**
|
|
316
|
+
* Get the actor state
|
|
317
|
+
*
|
|
318
|
+
* @remarks
|
|
319
|
+
* This property is not available in `createState` since the state hasn't been created yet.
|
|
320
|
+
*/
|
|
321
|
+
get state(): TState extends never ? never : TState;
|
|
322
|
+
/**
|
|
323
|
+
* Get the actor variables
|
|
324
|
+
*
|
|
325
|
+
* @remarks
|
|
326
|
+
* This property is not available in `createVars` since the variables haven't been created yet.
|
|
327
|
+
* Variables are only available if you define `vars` or `createVars` in your actor config.
|
|
328
|
+
*/
|
|
329
|
+
get vars(): TVars extends never ? never : TVars;
|
|
330
|
+
/**
|
|
331
|
+
* Broadcasts an event to all connected clients.
|
|
332
|
+
* @param name - The name of the event.
|
|
333
|
+
* @param args - The arguments to send with the event.
|
|
334
|
+
*/
|
|
335
|
+
broadcast<K extends keyof TEvents & string>(name: K, ...args: InferEventArgs<InferSchemaMap<TEvents>[K]>): void;
|
|
336
|
+
broadcast(name: keyof TEvents extends never ? string : never, ...args: Array<unknown>): void;
|
|
337
|
+
/**
|
|
338
|
+
* Gets the logger instance.
|
|
339
|
+
*/
|
|
340
|
+
get log(): Logger;
|
|
341
|
+
/**
|
|
342
|
+
* Access to queue receive helpers.
|
|
343
|
+
*/
|
|
344
|
+
get queue(): ActorQueue<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
|
|
345
|
+
/**
|
|
346
|
+
* Gets actor ID.
|
|
347
|
+
*/
|
|
348
|
+
get actorId(): string;
|
|
349
|
+
/**
|
|
350
|
+
* Gets the actor name.
|
|
351
|
+
*/
|
|
352
|
+
get name(): string;
|
|
353
|
+
/**
|
|
354
|
+
* Gets the actor key.
|
|
355
|
+
*/
|
|
356
|
+
get key(): ActorKey;
|
|
357
|
+
/**
|
|
358
|
+
* Gets the region.
|
|
359
|
+
*/
|
|
360
|
+
get region(): string;
|
|
361
|
+
/**
|
|
362
|
+
* Gets the scheduler.
|
|
363
|
+
*/
|
|
364
|
+
get schedule(): Schedule;
|
|
365
|
+
/**
|
|
366
|
+
* Gets the map of connections.
|
|
367
|
+
*/
|
|
368
|
+
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
|
|
369
|
+
/**
|
|
370
|
+
* Returns the client for the given registry.
|
|
371
|
+
*/
|
|
372
|
+
client<R extends Registry<any>>(): Client<R>;
|
|
373
|
+
/**
|
|
374
|
+
* Gets the database.
|
|
375
|
+
*
|
|
376
|
+
* @experimental
|
|
377
|
+
* @remarks
|
|
378
|
+
* This property is only available if you define a `db` provider in your actor config.
|
|
379
|
+
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
380
|
+
*/
|
|
381
|
+
get db(): TDatabase extends never ? never : InferDatabaseClient<TDatabase>;
|
|
382
|
+
/**
|
|
383
|
+
* Forces the state to get saved.
|
|
384
|
+
*
|
|
385
|
+
* @param opts - Options for saving the state.
|
|
386
|
+
*/
|
|
387
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
388
|
+
/**
|
|
389
|
+
* Prevents the actor from sleeping until promise is complete.
|
|
390
|
+
*/
|
|
391
|
+
waitUntil(promise: Promise<void>): void;
|
|
392
|
+
/**
|
|
393
|
+
* Prevents the actor from sleeping while the given promise is running.
|
|
394
|
+
*
|
|
395
|
+
* Use this when performing async operations in the `run` handler or other
|
|
396
|
+
* background contexts where you need to ensure the actor stays awake.
|
|
397
|
+
*
|
|
398
|
+
* Returns the resolved value and resets the sleep timer on completion.
|
|
399
|
+
* Errors are propagated to the caller.
|
|
400
|
+
*/
|
|
401
|
+
keepAwake<T>(promise: Promise<T>): Promise<T>;
|
|
402
|
+
/**
|
|
403
|
+
* AbortSignal that fires when the actor is stopping.
|
|
404
|
+
*/
|
|
405
|
+
get abortSignal(): AbortSignal;
|
|
406
|
+
/**
|
|
407
|
+
* True when the actor is stopping.
|
|
408
|
+
*
|
|
409
|
+
* Alias for `c.abortSignal.aborted`.
|
|
410
|
+
*/
|
|
411
|
+
get aborted(): boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Forces the actor to sleep.
|
|
414
|
+
*
|
|
415
|
+
* Not supported on all drivers.
|
|
416
|
+
*
|
|
417
|
+
* @experimental
|
|
418
|
+
*/
|
|
419
|
+
sleep(): void;
|
|
420
|
+
/**
|
|
421
|
+
* Forces the actor to destroy.
|
|
422
|
+
*
|
|
423
|
+
* This will return immediately, then call `onStop` and `onDestroy`.
|
|
424
|
+
*
|
|
425
|
+
* @experimental
|
|
426
|
+
*/
|
|
427
|
+
destroy(): void;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Base context for connection-based handlers.
|
|
432
|
+
* Extends ActorContext with connection-specific functionality.
|
|
433
|
+
*/
|
|
434
|
+
declare abstract class ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
435
|
+
readonly conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Context for a remote procedure call.
|
|
440
|
+
*/
|
|
441
|
+
declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Base context for connection initialization handlers.
|
|
446
|
+
* Extends ActorContext with request-specific functionality for connection lifecycle events.
|
|
447
|
+
*/
|
|
448
|
+
declare abstract class ConnInitContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, never, never, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
449
|
+
/**
|
|
450
|
+
* The incoming request that initiated the connection.
|
|
451
|
+
* May be undefined for connections initiated without a direct HTTP request.
|
|
452
|
+
*/
|
|
453
|
+
readonly request: Request | undefined;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Context for the onBeforeActionResponse lifecycle hook.
|
|
458
|
+
*/
|
|
459
|
+
declare class BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Context for the onBeforeConnect lifecycle hook.
|
|
464
|
+
*/
|
|
465
|
+
declare class BeforeConnectContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnInitContext<TState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Context for the onConnect lifecycle hook.
|
|
470
|
+
*/
|
|
471
|
+
declare class ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Context for the onCreate lifecycle hook.
|
|
476
|
+
*/
|
|
477
|
+
declare class CreateContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, never, never, never, TInput, TDatabase, TEvents, TQueues> {
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Context for the createConnState lifecycle hook.
|
|
482
|
+
* Called to initialize connection-specific state when a connection is created.
|
|
483
|
+
*/
|
|
484
|
+
declare class CreateConnStateContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnInitContext<TState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Context for the createVars lifecycle hook.
|
|
489
|
+
*/
|
|
490
|
+
declare class CreateVarsContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, never, never, never, TInput, TDatabase, TEvents, TQueues> {
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Context for the onDestroy lifecycle hook.
|
|
495
|
+
*/
|
|
496
|
+
declare class DestroyContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Context for the onDisconnect lifecycle hook.
|
|
501
|
+
*/
|
|
502
|
+
declare class DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Context for raw HTTP request handlers (onRequest).
|
|
507
|
+
*/
|
|
508
|
+
declare class RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
509
|
+
/**
|
|
510
|
+
* The incoming HTTP request.
|
|
511
|
+
* May be undefined for request contexts initiated without a direct HTTP request.
|
|
512
|
+
*/
|
|
513
|
+
readonly request: Request | undefined;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Context for the run lifecycle hook.
|
|
518
|
+
*
|
|
519
|
+
* This context is passed to the `run` handler which executes after the actor
|
|
520
|
+
* starts. It does not block actor startup and is intended for background tasks.
|
|
521
|
+
*
|
|
522
|
+
* Use `c.aborted` to detect when the actor is stopping and gracefully exit.
|
|
523
|
+
*/
|
|
524
|
+
declare class RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Context for the onSleep lifecycle hook.
|
|
529
|
+
*/
|
|
530
|
+
declare class SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Context for the onStateChange lifecycle hook.
|
|
535
|
+
*/
|
|
536
|
+
declare class StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Context for the onWake lifecycle hook.
|
|
541
|
+
*/
|
|
542
|
+
declare class WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Context for raw WebSocket handlers (onWebSocket).
|
|
547
|
+
*/
|
|
548
|
+
declare class WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
549
|
+
/**
|
|
550
|
+
* The incoming HTTP request that initiated the WebSocket upgrade.
|
|
551
|
+
* May be undefined for WebSocket connections initiated without a direct HTTP request.
|
|
552
|
+
*/
|
|
553
|
+
readonly request: Request | undefined;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** Data that's been serialized. */
|
|
557
|
+
type OutputData = string | Uint8Array;
|
|
558
|
+
declare const EncodingSchema: z.ZodEnum<{
|
|
559
|
+
json: "json";
|
|
560
|
+
cbor: "cbor";
|
|
561
|
+
bare: "bare";
|
|
562
|
+
}>;
|
|
563
|
+
/**
|
|
564
|
+
* Encoding used to communicate between the client & actor.
|
|
565
|
+
*/
|
|
566
|
+
type Encoding = z.infer<typeof EncodingSchema>;
|
|
567
|
+
/**
|
|
568
|
+
* Helper class that helps serialize data without re-serializing for the same encoding.
|
|
569
|
+
*/
|
|
570
|
+
declare class CachedSerializer<TBare, TJson, T = TBare> {
|
|
571
|
+
#private;
|
|
572
|
+
constructor(data: T, versionedDataHandler: VersionedDataHandler<TBare>, version: number, zodSchema: z.ZodType<TJson>, toJson: (value: T) => TJson, toBare: (value: T) => TBare);
|
|
573
|
+
get rawData(): T;
|
|
574
|
+
serialize(encoding: Encoding): OutputData;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
|
|
578
|
+
type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
579
|
+
|
|
580
|
+
declare const KEYS: {
|
|
581
|
+
PERSIST_DATA: Uint8Array<ArrayBuffer>;
|
|
582
|
+
CONN_PREFIX: Uint8Array<ArrayBuffer>;
|
|
583
|
+
INSPECTOR_TOKEN: Uint8Array<ArrayBuffer>;
|
|
584
|
+
KV: Uint8Array<ArrayBuffer>;
|
|
585
|
+
QUEUE_PREFIX: Uint8Array<ArrayBuffer>;
|
|
586
|
+
WORKFLOW_PREFIX: Uint8Array<ArrayBuffer>;
|
|
587
|
+
TRACES_PREFIX: Uint8Array<ArrayBuffer>;
|
|
588
|
+
SQLITE_PREFIX: Uint8Array<ArrayBuffer>;
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
declare const ActorKeySchema: z.ZodArray<z.ZodString>;
|
|
592
|
+
type ActorKey = z.infer<typeof ActorKeySchema>;
|
|
593
|
+
declare const CreateRequestSchema: z.ZodObject<{
|
|
594
|
+
name: z.ZodString;
|
|
595
|
+
key: z.ZodArray<z.ZodString>;
|
|
596
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
597
|
+
region: z.ZodOptional<z.ZodString>;
|
|
598
|
+
}, z.core.$strip>;
|
|
599
|
+
declare const ActorQuerySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
600
|
+
getForId: z.ZodObject<{
|
|
601
|
+
name: z.ZodString;
|
|
602
|
+
actorId: z.ZodString;
|
|
603
|
+
}, z.core.$strip>;
|
|
604
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
605
|
+
getForKey: z.ZodObject<{
|
|
606
|
+
name: z.ZodString;
|
|
607
|
+
key: z.ZodArray<z.ZodString>;
|
|
608
|
+
}, z.core.$strip>;
|
|
609
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
610
|
+
getOrCreateForKey: z.ZodObject<{
|
|
611
|
+
name: z.ZodString;
|
|
612
|
+
key: z.ZodArray<z.ZodString>;
|
|
613
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
614
|
+
region: z.ZodOptional<z.ZodString>;
|
|
615
|
+
}, z.core.$strip>;
|
|
616
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
617
|
+
create: z.ZodObject<{
|
|
618
|
+
name: z.ZodString;
|
|
619
|
+
key: z.ZodArray<z.ZodString>;
|
|
620
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
621
|
+
region: z.ZodOptional<z.ZodString>;
|
|
622
|
+
}, z.core.$strip>;
|
|
623
|
+
}, z.core.$strip>]>;
|
|
624
|
+
type ActorQuery = z.infer<typeof ActorQuerySchema>;
|
|
625
|
+
/**
|
|
626
|
+
* Interface representing a request to create a actor.
|
|
627
|
+
*/
|
|
628
|
+
type CreateRequest = z.infer<typeof CreateRequestSchema>;
|
|
629
|
+
|
|
630
|
+
interface ActorInspectorEmitterEvents {
|
|
631
|
+
stateUpdated: (state: unknown) => void;
|
|
632
|
+
connectionsUpdated: () => void;
|
|
633
|
+
queueUpdated: () => void;
|
|
634
|
+
workflowHistoryUpdated: (history: WorkflowHistory) => void;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Provides a unified interface for inspecting actor external and internal state.
|
|
638
|
+
*/
|
|
639
|
+
declare class ActorInspector {
|
|
640
|
+
#private;
|
|
641
|
+
private readonly actor;
|
|
642
|
+
readonly emitter: nanoevents.Emitter<ActorInspectorEmitterEvents>;
|
|
643
|
+
constructor(actor: AnyActorInstance);
|
|
644
|
+
getQueueSize(): number;
|
|
645
|
+
getQueueStatus(limit: number): Promise<QueueStatus>;
|
|
646
|
+
updateQueueSize(size: number): void;
|
|
647
|
+
isWorkflowEnabled(): boolean;
|
|
648
|
+
getWorkflowHistory(): WorkflowHistory | null;
|
|
649
|
+
isDatabaseEnabled(): boolean;
|
|
650
|
+
getDatabaseSchema(): Promise<ArrayBuffer>;
|
|
651
|
+
getDatabaseTableRows(table: string, limit: number, offset: number): Promise<ArrayBuffer>;
|
|
652
|
+
isStateEnabled(): boolean;
|
|
653
|
+
getState(): ArrayBuffer;
|
|
654
|
+
getRpcs(): string[];
|
|
655
|
+
getConnections(): {
|
|
656
|
+
type: string | undefined;
|
|
657
|
+
id: string;
|
|
658
|
+
details: ArrayBuffer;
|
|
659
|
+
}[];
|
|
660
|
+
setState(state: ArrayBuffer): Promise<void>;
|
|
661
|
+
executeAction(name: string, params: ArrayBuffer): Promise<ArrayBuffer>;
|
|
662
|
+
getStateJson(): unknown;
|
|
663
|
+
setStateJson(state: unknown): Promise<void>;
|
|
664
|
+
getConnectionsJson(): {
|
|
665
|
+
id: string;
|
|
666
|
+
details: unknown;
|
|
667
|
+
}[];
|
|
668
|
+
executeActionJson(name: string, args: unknown[]): Promise<unknown>;
|
|
669
|
+
getTracesJson(options: {
|
|
670
|
+
startMs: number;
|
|
671
|
+
endMs: number;
|
|
672
|
+
limit: number;
|
|
673
|
+
}): Promise<{
|
|
674
|
+
otlp: unknown;
|
|
675
|
+
clamped: boolean;
|
|
676
|
+
}>;
|
|
677
|
+
getWorkflowHistoryJson(): {
|
|
678
|
+
history: unknown | null;
|
|
679
|
+
isWorkflowEnabled: boolean;
|
|
680
|
+
};
|
|
681
|
+
getQueueStatusJson(limit: number): Promise<{
|
|
682
|
+
size: number;
|
|
683
|
+
maxSize: number;
|
|
684
|
+
truncated: boolean;
|
|
685
|
+
messages: {
|
|
686
|
+
id: number;
|
|
687
|
+
name: string;
|
|
688
|
+
createdAtMs: number;
|
|
689
|
+
}[];
|
|
690
|
+
}>;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
declare enum DriverReadyState {
|
|
694
|
+
UNKNOWN = -1,
|
|
695
|
+
CONNECTING = 0,
|
|
696
|
+
OPEN = 1,
|
|
697
|
+
CLOSING = 2,
|
|
698
|
+
CLOSED = 3
|
|
699
|
+
}
|
|
700
|
+
interface ConnDriver {
|
|
701
|
+
/** The type of driver. Used for debug purposes only. */
|
|
702
|
+
type: string;
|
|
703
|
+
/**
|
|
704
|
+
* If defined, this connection driver talks the RivetKit client driver (see
|
|
705
|
+
* schemas/client-protocol/).
|
|
706
|
+
*
|
|
707
|
+
* If enabled, events like `Init`, subscription events, etc. will be sent
|
|
708
|
+
* to this connection.
|
|
709
|
+
*/
|
|
710
|
+
rivetKitProtocol?: {
|
|
711
|
+
/** Sends a RivetKit client message. */
|
|
712
|
+
sendMessage(actor: AnyActorInstance, conn: AnyConn, message: CachedSerializer<any, any, any>): void;
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* If the connection can be hibernated. If true, this will allow the actor to go to sleep while the connection is still active.
|
|
716
|
+
**/
|
|
717
|
+
hibernatable?: {
|
|
718
|
+
gatewayId: ArrayBuffer;
|
|
719
|
+
requestId: ArrayBuffer;
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* This returns a promise since we commonly disconnect at the end of a program, and not waiting will cause the socket to not close cleanly.
|
|
723
|
+
*/
|
|
724
|
+
disconnect(actor: AnyActorInstance, conn: AnyConn, reason?: string): Promise<void>;
|
|
725
|
+
/** Terminates the connection without graceful handling. */
|
|
726
|
+
terminate?(actor: AnyActorInstance, conn: AnyConn): void;
|
|
727
|
+
/**
|
|
728
|
+
* Returns the ready state of the connection.
|
|
729
|
+
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
|
|
730
|
+
*/
|
|
731
|
+
getConnectionReadyState(actor: AnyActorInstance, conn: AnyConn): DriverReadyState | undefined;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Persisted data structures for connections.
|
|
736
|
+
*
|
|
737
|
+
* Keep this file in sync with the Connection section of rivetkit-typescript/packages/rivetkit/schemas/actor-persist/
|
|
738
|
+
*/
|
|
739
|
+
|
|
740
|
+
type GatewayId = ArrayBuffer;
|
|
741
|
+
type RequestId = ArrayBuffer;
|
|
742
|
+
/** Event subscription for connection */
|
|
743
|
+
interface PersistedSubscription {
|
|
744
|
+
eventName: string;
|
|
745
|
+
}
|
|
746
|
+
/** Connection associated with hibernatable WebSocket that should persist across lifecycles */
|
|
747
|
+
interface PersistedConn<CP, CS> {
|
|
748
|
+
/** Connection ID generated by RivetKit */
|
|
749
|
+
id: string;
|
|
750
|
+
parameters: CP;
|
|
751
|
+
state: CS;
|
|
752
|
+
subscriptions: PersistedSubscription[];
|
|
753
|
+
gatewayId: GatewayId;
|
|
754
|
+
requestId: RequestId;
|
|
755
|
+
serverMessageIndex: number;
|
|
756
|
+
clientMessageIndex: number;
|
|
757
|
+
requestPath: string;
|
|
758
|
+
requestHeaders: Record<string, string>;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Manages all connection-related operations for an actor instance.
|
|
763
|
+
* Handles connection creation, tracking, hibernation, and cleanup.
|
|
764
|
+
*/
|
|
765
|
+
declare class ConnectionManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
766
|
+
#private;
|
|
767
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>);
|
|
768
|
+
get connections(): Map<ConnId, Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
769
|
+
getConnForId(id: string): Conn<S, CP, CS, V, I, DB, E, Q> | undefined;
|
|
770
|
+
get connsWithPersistChanged(): Set<ConnId>;
|
|
771
|
+
get pendingDisconnectCount(): number;
|
|
772
|
+
clearConnWithPersistChanged(): void;
|
|
773
|
+
markConnWithPersistChanged(conn: Conn<S, CP, CS, V, I, DB, E, Q>): void;
|
|
774
|
+
/**
|
|
775
|
+
* Handles pre-connection logic (i.e. auth & create state) before actually connecting the connection.
|
|
776
|
+
*/
|
|
777
|
+
prepareConn(driver: ConnDriver, params: CP, request: Request | undefined, requestPath: string | undefined, requestHeaders: Record<string, string> | undefined, isHibernatable: boolean, isRestoringHibernatable: boolean): Promise<Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
778
|
+
/**
|
|
779
|
+
* Adds a connection form prepareConn to the actor and calls onConnect.
|
|
780
|
+
*
|
|
781
|
+
* This method is intentionally not async since it needs to be called in
|
|
782
|
+
* `onOpen` for WebSockets. If this is async, the order of open events will
|
|
783
|
+
* be messed up and cause race conditions that can drop WebSocket messages.
|
|
784
|
+
* So all async work in prepareConn.
|
|
785
|
+
*/
|
|
786
|
+
connectConn(conn: Conn<S, CP, CS, V, I, DB, E, Q>): void;
|
|
787
|
+
/**
|
|
788
|
+
* Handle connection disconnection.
|
|
789
|
+
*
|
|
790
|
+
* This is called by `Conn.disconnect`. This should not call `Conn.disconnect.`
|
|
791
|
+
*/
|
|
792
|
+
connDisconnected(conn: Conn<S, CP, CS, V, I, DB, E, Q>): Promise<void>;
|
|
793
|
+
cleanupPersistedHibernatableConnections(reason?: string): Promise<number>;
|
|
794
|
+
/**
|
|
795
|
+
* Utilify function for call sites that don't need a separate prepare and connect phase.
|
|
796
|
+
*/
|
|
797
|
+
prepareAndConnectConn(driver: ConnDriver, params: CP, request: Request | undefined, requestPath: string | undefined, requestHeaders: Record<string, string> | undefined): Promise<Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
798
|
+
/**
|
|
799
|
+
* Restores connections from persisted data during actor initialization.
|
|
800
|
+
*/
|
|
801
|
+
restoreConnections(connections: PersistedConn<CP, CS>[]): void;
|
|
802
|
+
findHibernatableConn(gatewayIdBuf: ArrayBuffer, requestIdBuf: ArrayBuffer): Conn<S, CP, CS, V, I, DB, E, Q> | undefined;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Manages event subscriptions and broadcasting for actor instances.
|
|
807
|
+
* Handles subscription tracking and efficient message distribution to connected clients.
|
|
808
|
+
*/
|
|
809
|
+
declare class EventManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
810
|
+
#private;
|
|
811
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>);
|
|
812
|
+
/**
|
|
813
|
+
* Adds a subscription for a connection to an event.
|
|
814
|
+
*
|
|
815
|
+
* @param eventName - The name of the event to subscribe to
|
|
816
|
+
* @param connection - The connection subscribing to the event
|
|
817
|
+
* @param fromPersist - Whether this subscription is being restored from persistence
|
|
818
|
+
*/
|
|
819
|
+
addSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB, E, Q>, fromPersist: boolean): void;
|
|
820
|
+
/**
|
|
821
|
+
* Removes a subscription for a connection from an event.
|
|
822
|
+
*
|
|
823
|
+
* @param eventName - The name of the event to unsubscribe from
|
|
824
|
+
* @param connection - The connection unsubscribing from the event
|
|
825
|
+
* @param fromRemoveConn - Whether this is being called as part of connection removal
|
|
826
|
+
*/
|
|
827
|
+
removeSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB, E, Q>, fromRemoveConn: boolean): void;
|
|
828
|
+
/**
|
|
829
|
+
* Broadcasts an event to all subscribed connections.
|
|
830
|
+
*
|
|
831
|
+
* @param name - The name of the event to broadcast
|
|
832
|
+
* @param args - The arguments to send with the event
|
|
833
|
+
*/
|
|
834
|
+
broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
835
|
+
/**
|
|
836
|
+
* Gets all subscribers for a specific event.
|
|
837
|
+
*
|
|
838
|
+
* @param eventName - The name of the event
|
|
839
|
+
* @returns Set of connections subscribed to the event, or undefined if no subscribers
|
|
840
|
+
*/
|
|
841
|
+
getSubscribers(eventName: string): Set<Conn<S, CP, CS, V, I, DB, E, Q>> | undefined;
|
|
842
|
+
/**
|
|
843
|
+
* Gets all events and their subscriber counts.
|
|
844
|
+
*
|
|
845
|
+
* @returns Map of event names to subscriber counts
|
|
846
|
+
*/
|
|
847
|
+
getEventStats(): Map<string, number>;
|
|
848
|
+
/**
|
|
849
|
+
* Clears all subscriptions for a connection.
|
|
850
|
+
* Used during connection cleanup.
|
|
851
|
+
*
|
|
852
|
+
* @param connection - The connection to clear subscriptions for
|
|
853
|
+
*/
|
|
854
|
+
clearConnectionSubscriptions(connection: Conn<S, CP, CS, V, I, DB, E, Q>): void;
|
|
855
|
+
/**
|
|
856
|
+
* Gets the total number of unique events being subscribed to.
|
|
857
|
+
*/
|
|
858
|
+
get eventCount(): number;
|
|
859
|
+
/**
|
|
860
|
+
* Gets the total number of subscriptions across all events.
|
|
861
|
+
*/
|
|
862
|
+
get totalSubscriptionCount(): number;
|
|
863
|
+
/**
|
|
864
|
+
* Checks if an event has any subscribers.
|
|
865
|
+
*
|
|
866
|
+
* @param eventName - The name of the event to check
|
|
867
|
+
* @returns True if the event has at least one subscriber
|
|
868
|
+
*/
|
|
869
|
+
hasSubscribers(eventName: string): boolean;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Persisted data structures for actors.
|
|
874
|
+
*
|
|
875
|
+
* Keep this file in sync with the Connection section of rivetkit-typescript/packages/rivetkit/schemas/actor-persist/
|
|
876
|
+
*/
|
|
877
|
+
|
|
878
|
+
type Cbor = ArrayBuffer;
|
|
879
|
+
/** Scheduled event to be executed at a specific timestamp */
|
|
880
|
+
interface PersistedScheduleEvent {
|
|
881
|
+
eventId: string;
|
|
882
|
+
timestamp: number;
|
|
883
|
+
action: string;
|
|
884
|
+
args?: Cbor;
|
|
885
|
+
}
|
|
886
|
+
/** State object that gets automatically persisted to storage */
|
|
887
|
+
interface PersistedActor<S, I> {
|
|
888
|
+
/** Input data passed to the actor on initialization */
|
|
889
|
+
input?: I;
|
|
890
|
+
hasInitialized: boolean;
|
|
891
|
+
state: S;
|
|
892
|
+
scheduledEvents: PersistedScheduleEvent[];
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
interface SaveStateOptions {
|
|
896
|
+
/**
|
|
897
|
+
* Forces the state to be saved immediately. This function will return when the state has saved successfully.
|
|
898
|
+
*/
|
|
899
|
+
immediate?: boolean;
|
|
900
|
+
/** Bypass ready check for stopping. */
|
|
901
|
+
allowStoppingState?: boolean;
|
|
902
|
+
/**
|
|
903
|
+
* Maximum time in milliseconds to wait before forcing a save.
|
|
904
|
+
*
|
|
905
|
+
* If a save is already scheduled to occur later than this deadline, it will be rescheduled earlier.
|
|
906
|
+
*/
|
|
907
|
+
maxWait?: number;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Manages actor state persistence, proxying, and synchronization.
|
|
911
|
+
* Handles automatic state change detection and throttled persistence to KV storage.
|
|
912
|
+
*/
|
|
913
|
+
declare class StateManager$1<S, CP, CS, I, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
914
|
+
#private;
|
|
915
|
+
constructor(actor: ActorInstance<S, CP, CS, any, I, any, E, Q>, actorDriver: ActorDriver, config: any);
|
|
916
|
+
get persist(): PersistedActor<S, I>;
|
|
917
|
+
get persistRaw(): PersistedActor<S, I>;
|
|
918
|
+
get persistChanged(): boolean;
|
|
919
|
+
get state(): S;
|
|
920
|
+
set state(value: S);
|
|
921
|
+
get stateEnabled(): boolean;
|
|
922
|
+
/**
|
|
923
|
+
* Initializes state from persisted data or creates new state.
|
|
924
|
+
*/
|
|
925
|
+
initializeState(persistData: PersistedActor<S, I>): Promise<void>;
|
|
926
|
+
/**
|
|
927
|
+
* Creates proxy for persist object that handles automatic state change detection.
|
|
928
|
+
*/
|
|
929
|
+
initPersistProxy(target: PersistedActor<S, I>): undefined;
|
|
930
|
+
/**
|
|
931
|
+
* Forces the state to get saved.
|
|
932
|
+
*/
|
|
933
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
934
|
+
/**
|
|
935
|
+
* Throttled save state method. Used to write to KV at a reasonable cadence.
|
|
936
|
+
*
|
|
937
|
+
* Passing a maxWait will override the stateSaveInterval with the min
|
|
938
|
+
* between that and the maxWait.
|
|
939
|
+
*/
|
|
940
|
+
savePersistThrottled(maxWait?: number): void;
|
|
941
|
+
/**
|
|
942
|
+
* Clears any pending save timeout.
|
|
943
|
+
*/
|
|
944
|
+
clearPendingSaveTimeout(): void;
|
|
945
|
+
/**
|
|
946
|
+
* Waits for any pending write operations to complete.
|
|
947
|
+
*/
|
|
948
|
+
waitForPendingWrites(): Promise<void>;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
952
|
+
type AnyActorInstance = ActorInstance<any, any, any, any, any, any, any, any>;
|
|
953
|
+
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
954
|
+
#private;
|
|
955
|
+
actorContext: ActorContext<S, CP, CS, V, I, DB, E, Q>;
|
|
956
|
+
driver: ActorDriver;
|
|
957
|
+
connectionManager: ConnectionManager<S, CP, CS, V, I, DB, E, Q>;
|
|
958
|
+
stateManager: StateManager$1<S, CP, CS, I, E, Q>;
|
|
959
|
+
eventManager: EventManager<S, CP, CS, V, I, DB, E, Q>;
|
|
960
|
+
queueManager: QueueManager<S, CP, CS, V, I, DB, E, Q>;
|
|
961
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
|
|
962
|
+
get log(): Logger;
|
|
963
|
+
get rLog(): Logger;
|
|
964
|
+
get isStopping(): boolean;
|
|
965
|
+
get id(): string;
|
|
966
|
+
get name(): string;
|
|
967
|
+
get key(): ActorKey;
|
|
968
|
+
get region(): string;
|
|
969
|
+
get inlineClient(): Client<Registry<any>>;
|
|
970
|
+
get inspector(): ActorInspector;
|
|
971
|
+
get traces(): Traces<OtlpExportTraceServiceRequestJson>;
|
|
972
|
+
get inspectorToken(): string | undefined;
|
|
973
|
+
getCurrentTraceSpan(): SpanHandle | null;
|
|
974
|
+
startTraceSpan(name: string, attributes?: Record<string, unknown>): SpanHandle;
|
|
975
|
+
endTraceSpan(handle: SpanHandle, status?: SpanStatusInput): void;
|
|
976
|
+
runInTraceSpan<T>(name: string, attributes: Record<string, unknown> | undefined, fn: () => T | Promise<T>): Promise<T>;
|
|
977
|
+
emitTraceEvent(name: string, attributes?: Record<string, unknown>, handle?: SpanHandle): void;
|
|
978
|
+
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
979
|
+
get schedule(): Schedule;
|
|
980
|
+
get abortSignal(): AbortSignal;
|
|
981
|
+
get actions(): string[];
|
|
982
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
|
|
983
|
+
get persist(): PersistedActor<S, I>;
|
|
984
|
+
get state(): S;
|
|
985
|
+
set state(value: S);
|
|
986
|
+
get stateEnabled(): boolean;
|
|
987
|
+
get connStateEnabled(): boolean;
|
|
988
|
+
get vars(): V;
|
|
989
|
+
get db(): InferDatabaseClient<DB>;
|
|
990
|
+
start(actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
991
|
+
isReady(): boolean;
|
|
992
|
+
assertReady(allowStoppingState?: boolean): void;
|
|
993
|
+
cleanupPersistedConnections(reason?: string): Promise<number>;
|
|
994
|
+
onStop(mode: "sleep" | "destroy"): Promise<void>;
|
|
995
|
+
startSleep(): void;
|
|
996
|
+
startDestroy(): void;
|
|
997
|
+
beginHonoHttpRequest(): void;
|
|
998
|
+
endHonoHttpRequest(): void;
|
|
999
|
+
processMessage(message: {
|
|
1000
|
+
body: {
|
|
1001
|
+
tag: "ActionRequest";
|
|
1002
|
+
val: {
|
|
1003
|
+
id: bigint;
|
|
1004
|
+
name: string;
|
|
1005
|
+
args: unknown;
|
|
1006
|
+
};
|
|
1007
|
+
} | {
|
|
1008
|
+
tag: "SubscriptionRequest";
|
|
1009
|
+
val: {
|
|
1010
|
+
eventName: string;
|
|
1011
|
+
subscribe: boolean;
|
|
1012
|
+
};
|
|
1013
|
+
};
|
|
1014
|
+
}, conn: Conn<S, CP, CS, V, I, DB, E, Q>): Promise<void>;
|
|
1015
|
+
assertCanSubscribe(ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>, eventName: string): Promise<void>;
|
|
1016
|
+
assertCanPublish(ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>, queueName: string): Promise<void>;
|
|
1017
|
+
executeAction(ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>, actionName: string, args: unknown[]): Promise<unknown>;
|
|
1018
|
+
handleRawRequest(conn: Conn<S, CP, CS, V, I, DB, E, Q>, request: Request): Promise<Response>;
|
|
1019
|
+
handleRawWebSocket(conn: Conn<S, CP, CS, V, I, DB, E, Q>, websocket: UniversalWebSocket, request?: Request): void;
|
|
1020
|
+
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
1021
|
+
onAlarm(): Promise<void>;
|
|
1022
|
+
waitUntil(promise: Promise<void>): void;
|
|
1023
|
+
/**
|
|
1024
|
+
* Prevents the actor from sleeping while the given promise is running.
|
|
1025
|
+
*
|
|
1026
|
+
* Use this when performing async operations in the `run` handler or other
|
|
1027
|
+
* background contexts where you need to ensure the actor stays awake.
|
|
1028
|
+
*
|
|
1029
|
+
* Returns the resolved value and resets the sleep timer on completion.
|
|
1030
|
+
* Errors are propagated to the caller.
|
|
1031
|
+
*/
|
|
1032
|
+
keepAwake<T>(promise: Promise<T>): Promise<T>;
|
|
1033
|
+
beginQueueWait(): void;
|
|
1034
|
+
endQueueWait(): void;
|
|
1035
|
+
resetSleepTimer(): void;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/** Pick a subset of persisted data used to represent ephemeral connections */
|
|
1039
|
+
type EphemeralConn<CP, CS> = Pick<PersistedConn<CP, CS>, "id" | "parameters" | "state">;
|
|
1040
|
+
type ConnDataInput<CP, CS> = {
|
|
1041
|
+
ephemeral: EphemeralConn<CP, CS>;
|
|
1042
|
+
} | {
|
|
1043
|
+
hibernatable: PersistedConn<CP, CS>;
|
|
1044
|
+
};
|
|
1045
|
+
/**
|
|
1046
|
+
* Manages connection state persistence, proxying, and change tracking.
|
|
1047
|
+
* Handles automatic state change detection for connection-specific state.
|
|
1048
|
+
*/
|
|
1049
|
+
declare class StateManager<CP, CS> {
|
|
1050
|
+
#private;
|
|
1051
|
+
constructor(conn: Conn<any, CP, CS, any, any, any, any, any>, data: ConnDataInput<CP, CS>);
|
|
1052
|
+
/**
|
|
1053
|
+
* Returns the ephemeral or persisted data for this connectioned.
|
|
1054
|
+
*
|
|
1055
|
+
* This property is used to be able to treat both memory & persist conns
|
|
1056
|
+
* identical by looking up the correct underlying data structure.
|
|
1057
|
+
*/
|
|
1058
|
+
get ephemeralData(): EphemeralConn<CP, CS>;
|
|
1059
|
+
get hibernatableData(): PersistedConn<CP, CS> | undefined;
|
|
1060
|
+
hibernatableDataOrError(): PersistedConn<CP, CS>;
|
|
1061
|
+
get hibernatableDataRaw(): PersistedConn<CP, CS> | undefined;
|
|
1062
|
+
get stateEnabled(): boolean;
|
|
1063
|
+
get state(): CS;
|
|
1064
|
+
set state(value: CS);
|
|
1065
|
+
addSubscription({ eventName }: {
|
|
1066
|
+
eventName: string;
|
|
1067
|
+
}): void;
|
|
1068
|
+
removeSubscription({ eventName }: {
|
|
1069
|
+
eventName: string;
|
|
1070
|
+
}): boolean | undefined;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
type ConnId = string;
|
|
1074
|
+
type AnyConn = Conn<any, any, any, any, any, any, any, any>;
|
|
1075
|
+
declare const CONN_CONNECTED_SYMBOL: unique symbol;
|
|
1076
|
+
declare const CONN_SPEAKS_RIVETKIT_SYMBOL: unique symbol;
|
|
1077
|
+
declare const CONN_DRIVER_SYMBOL: unique symbol;
|
|
1078
|
+
declare const CONN_ACTOR_SYMBOL: unique symbol;
|
|
1079
|
+
declare const CONN_STATE_MANAGER_SYMBOL: unique symbol;
|
|
1080
|
+
declare const CONN_SEND_MESSAGE_SYMBOL: unique symbol;
|
|
1081
|
+
/**
|
|
1082
|
+
* Represents a client connection to a actor.
|
|
1083
|
+
*
|
|
1084
|
+
* Manages connection-specific data and controls the connection lifecycle.
|
|
1085
|
+
*
|
|
1086
|
+
* @see {@link https://rivet.dev/docs/connections|Connection Documentation}
|
|
1087
|
+
*/
|
|
1088
|
+
declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
1089
|
+
#private;
|
|
1090
|
+
get [CONN_ACTOR_SYMBOL](): ActorInstance<S, CP, CS, V, I, DB, E, Q>;
|
|
1091
|
+
get [CONN_STATE_MANAGER_SYMBOL](): StateManager<CP, CS>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Connections exist before being connected to an actor. If true, this
|
|
1094
|
+
* connection has been connected.
|
|
1095
|
+
**/
|
|
1096
|
+
[CONN_CONNECTED_SYMBOL]: boolean;
|
|
1097
|
+
/**
|
|
1098
|
+
* If undefined, then no socket is connected to this conn
|
|
1099
|
+
*/
|
|
1100
|
+
[CONN_DRIVER_SYMBOL]?: ConnDriver;
|
|
1101
|
+
/**
|
|
1102
|
+
* If this connection is speaking the RivetKit protocol. If false, this is
|
|
1103
|
+
* a raw connection for WebSocket or fetch or inspector.
|
|
1104
|
+
**/
|
|
1105
|
+
get [CONN_SPEAKS_RIVETKIT_SYMBOL](): boolean;
|
|
1106
|
+
subscriptions: Set<string>;
|
|
1107
|
+
get params(): CP;
|
|
1108
|
+
/**
|
|
1109
|
+
* Gets the current state of the connection.
|
|
1110
|
+
*
|
|
1111
|
+
* Throws an error if the state is not enabled.
|
|
1112
|
+
*/
|
|
1113
|
+
get state(): CS;
|
|
1114
|
+
/**
|
|
1115
|
+
* Sets the state of the connection.
|
|
1116
|
+
*
|
|
1117
|
+
* Throws an error if the state is not enabled.
|
|
1118
|
+
*/
|
|
1119
|
+
set state(value: CS);
|
|
1120
|
+
/**
|
|
1121
|
+
* Unique identifier for the connection.
|
|
1122
|
+
*/
|
|
1123
|
+
get id(): ConnId;
|
|
1124
|
+
/**
|
|
1125
|
+
* @experimental
|
|
1126
|
+
*
|
|
1127
|
+
* If the underlying connection can hibernate.
|
|
1128
|
+
*/
|
|
1129
|
+
get isHibernatable(): boolean;
|
|
1130
|
+
/**
|
|
1131
|
+
* Initializes a new instance of the Connection class.
|
|
1132
|
+
*
|
|
1133
|
+
* This should only be constructed by {@link Actor}.
|
|
1134
|
+
*
|
|
1135
|
+
* @protected
|
|
1136
|
+
*/
|
|
1137
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>, data: ConnDataInput<CP, CS>);
|
|
1138
|
+
/**
|
|
1139
|
+
* Sends a raw message to the underlying connection.
|
|
1140
|
+
*/
|
|
1141
|
+
[CONN_SEND_MESSAGE_SYMBOL](message: CachedSerializer<any, any, any>): void;
|
|
1142
|
+
/**
|
|
1143
|
+
* Sends an event with arguments to the client.
|
|
1144
|
+
*
|
|
1145
|
+
* @param eventName - The name of the event.
|
|
1146
|
+
* @param args - The arguments for the event.
|
|
1147
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1148
|
+
*/
|
|
1149
|
+
send<K extends keyof E & string>(eventName: K, ...args: InferEventArgs<InferSchemaMap<E>[K]>): void;
|
|
1150
|
+
send(eventName: keyof E extends never ? string : never, ...args: unknown[]): void;
|
|
1151
|
+
/**
|
|
1152
|
+
* Disconnects the client with an optional reason.
|
|
1153
|
+
*
|
|
1154
|
+
* @param reason - The reason for disconnection.
|
|
1155
|
+
*/
|
|
1156
|
+
disconnect(reason?: string): Promise<void>;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
type InspectorUnsubscribe = () => void;
|
|
1160
|
+
declare const RunConfigSchema: z.ZodObject<{
|
|
1161
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1162
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
1163
|
+
run: z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
|
|
1164
|
+
inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
1165
|
+
workflow: z.ZodOptional<z.ZodObject<{
|
|
1166
|
+
getHistory: z.ZodCustom<() => unknown, () => unknown>;
|
|
1167
|
+
onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
|
|
1168
|
+
}, z.core.$strip>>;
|
|
1169
|
+
}, z.core.$strip>>>;
|
|
1170
|
+
}, z.core.$strip>;
|
|
1171
|
+
type RunConfigRuntime = z.infer<typeof RunConfigSchema>;
|
|
1172
|
+
type RunConfig<TState = unknown, TConnParams = unknown, TConnState = unknown, TVars = unknown, TInput = unknown, TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<RunConfigRuntime, "run"> & {
|
|
1173
|
+
run: (c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1174
|
+
};
|
|
1175
|
+
declare const ActorConfigSchema: z.ZodObject<{
|
|
1176
|
+
onCreate: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1177
|
+
onDestroy: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1178
|
+
onWake: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1179
|
+
onSleep: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1180
|
+
run: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>, z.ZodObject<{
|
|
1181
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1182
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
1183
|
+
run: z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
|
|
1184
|
+
inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
1185
|
+
workflow: z.ZodOptional<z.ZodObject<{
|
|
1186
|
+
getHistory: z.ZodCustom<() => unknown, () => unknown>;
|
|
1187
|
+
onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
|
|
1188
|
+
}, z.core.$strip>>;
|
|
1189
|
+
}, z.core.$strip>>>;
|
|
1190
|
+
}, z.core.$strip>]>>;
|
|
1191
|
+
onStateChange: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1192
|
+
onBeforeConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1193
|
+
onConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1194
|
+
onDisconnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1195
|
+
onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1196
|
+
onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1197
|
+
onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1198
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
|
|
1199
|
+
events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
1200
|
+
queues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
1201
|
+
state: z.ZodOptional<z.ZodAny>;
|
|
1202
|
+
createState: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1203
|
+
connState: z.ZodOptional<z.ZodAny>;
|
|
1204
|
+
createConnState: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1205
|
+
vars: z.ZodOptional<z.ZodAny>;
|
|
1206
|
+
db: z.ZodOptional<z.ZodAny>;
|
|
1207
|
+
createVars: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1208
|
+
options: z.ZodPrefault<z.ZodObject<{
|
|
1209
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1210
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
1211
|
+
createVarsTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1212
|
+
createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1213
|
+
onConnectTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1214
|
+
onSleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1215
|
+
onDestroyTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1216
|
+
stateSaveInterval: z.ZodDefault<z.ZodNumber>;
|
|
1217
|
+
actionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1218
|
+
waitUntilTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1219
|
+
runStopTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1220
|
+
connectionLivenessTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1221
|
+
connectionLivenessInterval: z.ZodDefault<z.ZodNumber>;
|
|
1222
|
+
noSleep: z.ZodDefault<z.ZodBoolean>;
|
|
1223
|
+
sleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1224
|
+
maxQueueSize: z.ZodDefault<z.ZodNumber>;
|
|
1225
|
+
maxQueueMessageSize: z.ZodDefault<z.ZodNumber>;
|
|
1226
|
+
canHibernateWebSocket: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
|
|
1227
|
+
}, z.core.$strict>>;
|
|
1228
|
+
}, z.core.$strict>;
|
|
1229
|
+
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
|
|
1230
|
+
state: TState;
|
|
1231
|
+
} | {
|
|
1232
|
+
createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
|
|
1233
|
+
} | Record<never, never>;
|
|
1234
|
+
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
|
|
1235
|
+
connState: TConnState;
|
|
1236
|
+
} | {
|
|
1237
|
+
createConnState: (c: CreateConnStateContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
1238
|
+
} | Record<never, never>;
|
|
1239
|
+
/**
|
|
1240
|
+
* @experimental
|
|
1241
|
+
*/
|
|
1242
|
+
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
|
|
1243
|
+
/**
|
|
1244
|
+
* @experimental
|
|
1245
|
+
*/
|
|
1246
|
+
vars: TVars;
|
|
1247
|
+
} | {
|
|
1248
|
+
/**
|
|
1249
|
+
* @experimental
|
|
1250
|
+
*/
|
|
1251
|
+
createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
|
|
1252
|
+
} | Record<never, never>;
|
|
1253
|
+
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
|
|
1254
|
+
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any;
|
|
1255
|
+
}
|
|
1256
|
+
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> {
|
|
1257
|
+
/**
|
|
1258
|
+
* Called when the actor is first initialized.
|
|
1259
|
+
*
|
|
1260
|
+
* Use this hook to initialize your actor's state.
|
|
1261
|
+
* This is called before any other lifecycle hooks.
|
|
1262
|
+
*/
|
|
1263
|
+
onCreate?: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => void | Promise<void>;
|
|
1264
|
+
/**
|
|
1265
|
+
* Called when the actor is destroyed.
|
|
1266
|
+
*/
|
|
1267
|
+
onDestroy?: (c: DestroyContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1268
|
+
/**
|
|
1269
|
+
* Called when the actor is started and ready to receive connections and action.
|
|
1270
|
+
*
|
|
1271
|
+
* Use this hook to initialize resources needed for the actor's operation
|
|
1272
|
+
* (timers, external connections, etc.)
|
|
1273
|
+
*
|
|
1274
|
+
* @returns Void or a Promise that resolves when startup is complete
|
|
1275
|
+
*/
|
|
1276
|
+
onWake?: (c: WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1277
|
+
/**
|
|
1278
|
+
* Called when the actor is stopping or sleeping.
|
|
1279
|
+
*
|
|
1280
|
+
* Use this hook to clean up resources, save state, or perform
|
|
1281
|
+
* any shutdown operations before the actor sleeps or stops.
|
|
1282
|
+
*
|
|
1283
|
+
* Not supported on all platforms.
|
|
1284
|
+
*
|
|
1285
|
+
* @returns Void or a Promise that resolves when shutdown is complete
|
|
1286
|
+
*/
|
|
1287
|
+
onSleep?: (c: SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1288
|
+
/**
|
|
1289
|
+
* Called after the actor starts up. Does not block actor startup.
|
|
1290
|
+
*
|
|
1291
|
+
* Use this for background tasks like:
|
|
1292
|
+
* - Reading from queues in a loop
|
|
1293
|
+
* - Tick loops for periodic work
|
|
1294
|
+
* - Custom workflow logic
|
|
1295
|
+
*
|
|
1296
|
+
* **Important:** The actor may go to sleep at any time during the `run`
|
|
1297
|
+
* handler. Use `c.keepAwake(promise)` to wrap async operations that should
|
|
1298
|
+
* not be interrupted by sleep.
|
|
1299
|
+
*
|
|
1300
|
+
* The handler receives an abort signal via `c.abortSignal` and a
|
|
1301
|
+
* `c.aborted` alias for loop checks. Use these to gracefully exit.
|
|
1302
|
+
*
|
|
1303
|
+
* If this handler exits or throws, the actor will crash and reschedule.
|
|
1304
|
+
* On shutdown, the actor waits for this handler to complete with a
|
|
1305
|
+
* configurable timeout (options.runStopTimeout, default 15s).
|
|
1306
|
+
*
|
|
1307
|
+
* Can be either a function or a RunConfig object with optional name/icon metadata.
|
|
1308
|
+
*
|
|
1309
|
+
* @returns Void or a Promise. If the promise exits, the actor crashes.
|
|
1310
|
+
*/
|
|
1311
|
+
run?: ((c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>) | RunConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
|
|
1312
|
+
/**
|
|
1313
|
+
* Called when the actor's state changes.
|
|
1314
|
+
*
|
|
1315
|
+
* Use this hook to react to state changes, such as updating
|
|
1316
|
+
* external systems or triggering events.
|
|
1317
|
+
*
|
|
1318
|
+
* State changes made within this hook will NOT trigger
|
|
1319
|
+
* another onStateChange call, preventing infinite recursion.
|
|
1320
|
+
*
|
|
1321
|
+
* @param newState The updated state
|
|
1322
|
+
*/
|
|
1323
|
+
onStateChange?: (c: StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, newState: TState) => void;
|
|
1324
|
+
/**
|
|
1325
|
+
* Called before a client connects to the actor.
|
|
1326
|
+
*
|
|
1327
|
+
* Use this hook to determine if a connection should be accepted
|
|
1328
|
+
* and to initialize connection-specific state.
|
|
1329
|
+
*
|
|
1330
|
+
* @param opts Connection parameters including client-provided data
|
|
1331
|
+
* @returns The initial connection state or a Promise that resolves to it
|
|
1332
|
+
* @throws Throw an error to reject the connection
|
|
1333
|
+
*/
|
|
1334
|
+
onBeforeConnect?: (c: BeforeConnectContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => void | Promise<void>;
|
|
1335
|
+
/**
|
|
1336
|
+
* Called when a client successfully connects to the actor.
|
|
1337
|
+
*
|
|
1338
|
+
* Use this hook to perform actions when a connection is established,
|
|
1339
|
+
* such as sending initial data or updating the actor's state.
|
|
1340
|
+
*
|
|
1341
|
+
* @param conn The connection object
|
|
1342
|
+
* @returns Void or a Promise that resolves when connection handling is complete
|
|
1343
|
+
*/
|
|
1344
|
+
onConnect?: (c: ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1345
|
+
/**
|
|
1346
|
+
* Called when a client disconnects from the actor.
|
|
1347
|
+
*
|
|
1348
|
+
* Use this hook to clean up resources associated with the connection
|
|
1349
|
+
* or update the actor's state.
|
|
1350
|
+
*
|
|
1351
|
+
* @param conn The connection that is being closed
|
|
1352
|
+
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
1353
|
+
*/
|
|
1354
|
+
onDisconnect?: (c: DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1355
|
+
/**
|
|
1356
|
+
* Called before sending an action response to the client.
|
|
1357
|
+
*
|
|
1358
|
+
* Use this hook to modify or transform the output of an action before it's sent
|
|
1359
|
+
* to the client. This is useful for formatting responses, adding metadata,
|
|
1360
|
+
* or applying transformations to the output.
|
|
1361
|
+
*
|
|
1362
|
+
* @param name The name of the action that was called
|
|
1363
|
+
* @param args The arguments that were passed to the action
|
|
1364
|
+
* @param output The output that will be sent to the client
|
|
1365
|
+
* @returns The modified output to send to the client
|
|
1366
|
+
*/
|
|
1367
|
+
onBeforeActionResponse?: <Out>(c: BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
1368
|
+
/**
|
|
1369
|
+
* Called when a raw HTTP request is made to the actor.
|
|
1370
|
+
*
|
|
1371
|
+
* This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
|
|
1372
|
+
* Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
|
|
1373
|
+
*
|
|
1374
|
+
* @param c The request context with access to the connection
|
|
1375
|
+
* @param request The raw HTTP request object
|
|
1376
|
+
* @param opts Additional options
|
|
1377
|
+
* @returns A Response object to send back, or void to continue with default routing
|
|
1378
|
+
*/
|
|
1379
|
+
onRequest?: (c: RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, request: Request) => Response | Promise<Response>;
|
|
1380
|
+
/**
|
|
1381
|
+
* Called when a raw WebSocket connection is established to the actor.
|
|
1382
|
+
*
|
|
1383
|
+
* This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
|
|
1384
|
+
* Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
|
|
1385
|
+
*
|
|
1386
|
+
* @param c The WebSocket context with access to the connection
|
|
1387
|
+
* @param websocket The raw WebSocket connection
|
|
1388
|
+
* @param opts Additional options including the original HTTP upgrade request
|
|
1389
|
+
*/
|
|
1390
|
+
onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
|
|
1391
|
+
actions?: TActions;
|
|
1392
|
+
/**
|
|
1393
|
+
* Schema map for events broadcasted by this actor.
|
|
1394
|
+
*/
|
|
1395
|
+
events?: TEvents;
|
|
1396
|
+
/**
|
|
1397
|
+
* Schema map for queue payloads sent by this actor.
|
|
1398
|
+
*/
|
|
1399
|
+
queues?: TQueues;
|
|
1400
|
+
}
|
|
1401
|
+
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
1402
|
+
/**
|
|
1403
|
+
* @experimental
|
|
1404
|
+
*/
|
|
1405
|
+
db: TDatabase;
|
|
1406
|
+
} | Record<never, never>;
|
|
1407
|
+
type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
|
|
1408
|
+
|
|
1409
|
+
type ManagerDriverBuilder = (config: RegistryConfig) => ManagerDriver;
|
|
1410
|
+
interface ManagerDriver {
|
|
1411
|
+
getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
|
|
1412
|
+
getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
|
|
1413
|
+
getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
|
|
1414
|
+
createActor(input: CreateInput): Promise<ActorOutput>;
|
|
1415
|
+
listActors(input: ListActorsInput): Promise<ActorOutput[]>;
|
|
1416
|
+
sendRequest(actorId: string, actorRequest: Request): Promise<Response>;
|
|
1417
|
+
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown): Promise<UniversalWebSocket>;
|
|
1418
|
+
proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
|
|
1419
|
+
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
|
|
1420
|
+
/**
|
|
1421
|
+
* Build a public gateway URL for a specific actor.
|
|
1422
|
+
*
|
|
1423
|
+
* This lives on the driver because the base endpoint varies by runtime.
|
|
1424
|
+
*/
|
|
1425
|
+
buildGatewayUrl(actorId: string): Promise<string>;
|
|
1426
|
+
displayInformation(): ManagerDisplayInformation;
|
|
1427
|
+
extraStartupLog?: () => Record<string, unknown>;
|
|
1428
|
+
modifyManagerRouter?: (config: RegistryConfig, router: Hono) => void;
|
|
1429
|
+
/**
|
|
1430
|
+
* Allows lazily setting getUpgradeWebSocket after the manager router has
|
|
1431
|
+
* been initialized.
|
|
1432
|
+
**/
|
|
1433
|
+
setGetUpgradeWebSocket(getUpgradeWebSocket: GetUpgradeWebSocket): void;
|
|
1434
|
+
/** Read a key. Returns null if the key doesn't exist. */
|
|
1435
|
+
kvGet(actorId: string, key: Uint8Array): Promise<string | null>;
|
|
1436
|
+
}
|
|
1437
|
+
interface ManagerDisplayInformation {
|
|
1438
|
+
properties: Record<string, string>;
|
|
1439
|
+
}
|
|
1440
|
+
interface GetForIdInput<E extends Env = any> {
|
|
1441
|
+
c?: Context | undefined;
|
|
1442
|
+
name: string;
|
|
1443
|
+
actorId: string;
|
|
1444
|
+
}
|
|
1445
|
+
interface GetWithKeyInput<E extends Env = any> {
|
|
1446
|
+
c?: Context | undefined;
|
|
1447
|
+
name: string;
|
|
1448
|
+
key: ActorKey;
|
|
1449
|
+
}
|
|
1450
|
+
interface GetOrCreateWithKeyInput<E extends Env = any> {
|
|
1451
|
+
c?: Context | undefined;
|
|
1452
|
+
name: string;
|
|
1453
|
+
key: ActorKey;
|
|
1454
|
+
input?: unknown;
|
|
1455
|
+
region?: string;
|
|
1456
|
+
}
|
|
1457
|
+
interface CreateInput<E extends Env = any> {
|
|
1458
|
+
c?: Context | undefined;
|
|
1459
|
+
name: string;
|
|
1460
|
+
key: ActorKey;
|
|
1461
|
+
input?: unknown;
|
|
1462
|
+
region?: string;
|
|
1463
|
+
}
|
|
1464
|
+
interface ListActorsInput<E extends Env = any> {
|
|
1465
|
+
c?: Context | undefined;
|
|
1466
|
+
name: string;
|
|
1467
|
+
key?: string;
|
|
1468
|
+
includeDestroyed?: boolean;
|
|
1469
|
+
}
|
|
1470
|
+
interface ActorOutput {
|
|
1471
|
+
actorId: string;
|
|
1472
|
+
name: string;
|
|
1473
|
+
key: ActorKey;
|
|
1474
|
+
createTs?: number;
|
|
1475
|
+
startTs?: number | null;
|
|
1476
|
+
connectableTs?: number | null;
|
|
1477
|
+
sleepTs?: number | null;
|
|
1478
|
+
destroyTs?: number | null;
|
|
1479
|
+
error?: unknown;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
type ActorDriverBuilder = (config: RegistryConfig, managerDriver: ManagerDriver, inlineClient: AnyClient) => ActorDriver;
|
|
1483
|
+
interface ActorDriver {
|
|
1484
|
+
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
1485
|
+
getContext(actorId: string): unknown;
|
|
1486
|
+
/** Batch write multiple key-value pairs. Keys and values are Uint8Arrays. */
|
|
1487
|
+
kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
|
|
1488
|
+
/** Batch read multiple keys. Returns null for keys that don't exist. */
|
|
1489
|
+
kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
|
|
1490
|
+
/** Batch delete multiple keys. */
|
|
1491
|
+
kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
|
|
1492
|
+
/** List all keys with a given prefix. */
|
|
1493
|
+
kvListPrefix(actorId: string, prefix: Uint8Array): Promise<[Uint8Array, Uint8Array][]>;
|
|
1494
|
+
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
1495
|
+
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
1496
|
+
/**
|
|
1497
|
+
* Override the default raw database client for the actor.
|
|
1498
|
+
* If not provided, rivetkit will construct a KV-backed SQLite client.
|
|
1499
|
+
* @experimental
|
|
1500
|
+
*/
|
|
1501
|
+
overrideRawDatabaseClient?(actorId: string): Promise<RawDatabaseClient | undefined>;
|
|
1502
|
+
/**
|
|
1503
|
+
* Override the default Drizzle database client for the actor.
|
|
1504
|
+
* If not provided, rivetkit will construct a KV-backed Drizzle client.
|
|
1505
|
+
* @experimental
|
|
1506
|
+
*/
|
|
1507
|
+
overrideDrizzleDatabaseClient?(actorId: string): Promise<BaseSQLiteDatabase<any, any, any, any> | undefined>;
|
|
1508
|
+
/**
|
|
1509
|
+
* Creates a SQLite VFS instance for creating KV-backed databases.
|
|
1510
|
+
* If not provided, the database provider will need an override.
|
|
1511
|
+
*
|
|
1512
|
+
* @rivetkit/sqlite's async build is not re-entrant per module instance. Drivers
|
|
1513
|
+
* should return a new instance per call for actor-level isolation.
|
|
1514
|
+
*
|
|
1515
|
+
* This is a method (not a property) so drivers can use dynamic imports,
|
|
1516
|
+
* keeping the core driver tree-shakeable from @rivetkit/sqlite.
|
|
1517
|
+
*/
|
|
1518
|
+
createSqliteVfs?(): SqliteVfs | Promise<SqliteVfs>;
|
|
1519
|
+
/**
|
|
1520
|
+
* Requests the actor to go to sleep.
|
|
1521
|
+
*
|
|
1522
|
+
* This will call `ActorInstance.onStop` independently.
|
|
1523
|
+
*/
|
|
1524
|
+
startSleep?(actorId: string): void;
|
|
1525
|
+
/**
|
|
1526
|
+
* Destroys the actor and its associated data.
|
|
1527
|
+
*
|
|
1528
|
+
* This will call `ActorInstance.onStop` independently.
|
|
1529
|
+
*/
|
|
1530
|
+
startDestroy(actorId: string): void;
|
|
1531
|
+
/**
|
|
1532
|
+
* Shuts down the actor runner.
|
|
1533
|
+
*/
|
|
1534
|
+
shutdownRunner?(immediate: boolean): Promise<void>;
|
|
1535
|
+
/** This handles the serverless start request. This should manage the lifecycle of the runner tied to the request lifecycle. */
|
|
1536
|
+
serverlessHandleStart?(c: Context): Promise<Response>;
|
|
1537
|
+
/** Extra properties to add to logs for each actor. */
|
|
1538
|
+
getExtraActorLogParams?(): Record<string, string>;
|
|
1539
|
+
onBeforeActorStart?(actor: AnyActorInstance): Promise<void>;
|
|
1540
|
+
onCreateConn?(conn: AnyConn): void;
|
|
1541
|
+
onDestroyConn?(conn: AnyConn): void;
|
|
1542
|
+
onBeforePersistConn?(conn: AnyConn): void;
|
|
1543
|
+
onAfterPersistConn?(conn: AnyConn): void;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
declare const ActorsSchema: z$1.ZodRecord<z$1.ZodString, z$1.ZodCustom<ActorDefinition<any, any, any, any, any, any, any, any, any>, ActorDefinition<any, any, any, any, any, any, any, any, any>>>;
|
|
1547
|
+
type RegistryActors = z$1.infer<typeof ActorsSchema>;
|
|
1548
|
+
declare const RegistryConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
|
|
1549
|
+
use: z$1.ZodRecord<z$1.ZodString, z$1.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
|
|
1550
|
+
test: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1551
|
+
enabled: z$1.ZodBoolean;
|
|
1552
|
+
}, z$1.core.$strip>>>;
|
|
1553
|
+
driver: z$1.ZodOptional<z$1.ZodObject<{
|
|
1554
|
+
name: z$1.ZodString;
|
|
1555
|
+
displayName: z$1.ZodString;
|
|
1556
|
+
manager: z$1.ZodCustom<ManagerDriverBuilder, ManagerDriverBuilder>;
|
|
1557
|
+
actor: z$1.ZodCustom<ActorDriverBuilder, ActorDriverBuilder>;
|
|
1558
|
+
autoStartActorDriver: z$1.ZodBoolean;
|
|
1559
|
+
}, z$1.core.$strip>>;
|
|
1560
|
+
storagePath: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1561
|
+
maxIncomingMessageSize: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
|
|
1562
|
+
maxOutgoingMessageSize: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
|
|
1563
|
+
noWelcome: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
|
|
1564
|
+
logging: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1565
|
+
baseLogger: z$1.ZodOptional<z$1.ZodCustom<Logger, Logger>>;
|
|
1566
|
+
level: z$1.ZodOptional<z$1.ZodEnum<{
|
|
1567
|
+
error: "error";
|
|
1568
|
+
trace: "trace";
|
|
1569
|
+
fatal: "fatal";
|
|
1570
|
+
warn: "warn";
|
|
1571
|
+
info: "info";
|
|
1572
|
+
debug: "debug";
|
|
1573
|
+
silent: "silent";
|
|
1574
|
+
}>>;
|
|
1575
|
+
}, z$1.core.$strip>>>;
|
|
1576
|
+
endpoint: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1577
|
+
token: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1578
|
+
namespace: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1579
|
+
headers: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>>;
|
|
1580
|
+
serveManager: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1581
|
+
managerBasePath: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
1582
|
+
managerPort: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
|
|
1583
|
+
managerHost: z$1.ZodOptional<z$1.ZodString>;
|
|
1584
|
+
inspector: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1585
|
+
enabled: z$1.ZodDefault<z$1.ZodBoolean>;
|
|
1586
|
+
token: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodCustom<() => string, () => string>>>;
|
|
1587
|
+
defaultEndpoint: z$1.ZodOptional<z$1.ZodString>;
|
|
1588
|
+
}, z$1.core.$strip>>>;
|
|
1589
|
+
serverless: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1590
|
+
spawnEngine: z$1.ZodDefault<z$1.ZodBoolean>;
|
|
1591
|
+
engineVersion: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
1592
|
+
configureRunnerPool: z$1.ZodOptional<z$1.ZodOptional<z$1.ZodObject<{
|
|
1593
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
1594
|
+
url: z$1.ZodString;
|
|
1595
|
+
headers: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
1596
|
+
maxRunners: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1597
|
+
minRunners: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1598
|
+
requestLifespan: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1599
|
+
runnersMargin: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1600
|
+
slotsPerRunner: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1601
|
+
metadata: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
1602
|
+
metadataPollInterval: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1603
|
+
drainOnVersionUpgrade: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1604
|
+
}, z$1.core.$strip>>>;
|
|
1605
|
+
basePath: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
1606
|
+
publicEndpoint: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1607
|
+
publicToken: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1608
|
+
}, z$1.core.$strip>>>;
|
|
1609
|
+
runner: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1610
|
+
totalSlots: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1611
|
+
runnerName: z$1.ZodDefault<z$1.ZodString>;
|
|
1612
|
+
runnerKey: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1613
|
+
version: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1614
|
+
}, z$1.core.$strip>>>;
|
|
1615
|
+
}, z$1.core.$strip>, z$1.ZodTransform<{
|
|
1616
|
+
endpoint: string | undefined;
|
|
1617
|
+
namespace: string;
|
|
1618
|
+
token: string | undefined;
|
|
1619
|
+
serveManager: boolean;
|
|
1620
|
+
publicEndpoint: string | undefined;
|
|
1621
|
+
publicNamespace: string | undefined;
|
|
1622
|
+
publicToken: string | undefined;
|
|
1623
|
+
inspector: {
|
|
1624
|
+
enabled: boolean;
|
|
1625
|
+
token: () => string;
|
|
1626
|
+
defaultEndpoint?: string | undefined;
|
|
1627
|
+
} | {
|
|
1628
|
+
enabled: {
|
|
1629
|
+
manager: boolean;
|
|
1630
|
+
actor: boolean;
|
|
1631
|
+
};
|
|
1632
|
+
token: () => string;
|
|
1633
|
+
defaultEndpoint?: string | undefined;
|
|
1634
|
+
};
|
|
1635
|
+
serverless: {
|
|
1636
|
+
publicEndpoint: string | undefined;
|
|
1637
|
+
spawnEngine: boolean;
|
|
1638
|
+
engineVersion: string;
|
|
1639
|
+
basePath: string;
|
|
1640
|
+
publicToken: string | undefined;
|
|
1641
|
+
configureRunnerPool?: {
|
|
1642
|
+
url: string;
|
|
1643
|
+
name?: string | undefined;
|
|
1644
|
+
headers?: Record<string, string> | undefined;
|
|
1645
|
+
maxRunners?: number | undefined;
|
|
1646
|
+
minRunners?: number | undefined;
|
|
1647
|
+
requestLifespan?: number | undefined;
|
|
1648
|
+
runnersMargin?: number | undefined;
|
|
1649
|
+
slotsPerRunner?: number | undefined;
|
|
1650
|
+
metadata?: Record<string, unknown> | undefined;
|
|
1651
|
+
metadataPollInterval?: number | undefined;
|
|
1652
|
+
drainOnVersionUpgrade?: boolean | undefined;
|
|
1653
|
+
} | undefined;
|
|
1654
|
+
};
|
|
1655
|
+
use: Record<string, AnyActorDefinition>;
|
|
1656
|
+
test: {
|
|
1657
|
+
enabled: boolean;
|
|
1658
|
+
};
|
|
1659
|
+
storagePath: string | undefined;
|
|
1660
|
+
maxIncomingMessageSize: number;
|
|
1661
|
+
maxOutgoingMessageSize: number;
|
|
1662
|
+
noWelcome: boolean;
|
|
1663
|
+
logging: {
|
|
1664
|
+
baseLogger?: Logger | undefined;
|
|
1665
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
1666
|
+
};
|
|
1667
|
+
headers: Record<string, string>;
|
|
1668
|
+
managerBasePath: string;
|
|
1669
|
+
managerPort: number;
|
|
1670
|
+
runner: {
|
|
1671
|
+
totalSlots: number;
|
|
1672
|
+
runnerName: string;
|
|
1673
|
+
runnerKey: string | undefined;
|
|
1674
|
+
version: number;
|
|
1675
|
+
};
|
|
1676
|
+
driver?: {
|
|
1677
|
+
name: string;
|
|
1678
|
+
displayName: string;
|
|
1679
|
+
manager: ManagerDriverBuilder;
|
|
1680
|
+
actor: ActorDriverBuilder;
|
|
1681
|
+
autoStartActorDriver: boolean;
|
|
1682
|
+
} | undefined;
|
|
1683
|
+
managerHost?: string | undefined;
|
|
1684
|
+
}, {
|
|
1685
|
+
use: Record<string, AnyActorDefinition>;
|
|
1686
|
+
test: {
|
|
1687
|
+
enabled: boolean;
|
|
1688
|
+
};
|
|
1689
|
+
storagePath: string | undefined;
|
|
1690
|
+
maxIncomingMessageSize: number;
|
|
1691
|
+
maxOutgoingMessageSize: number;
|
|
1692
|
+
noWelcome: boolean;
|
|
1693
|
+
logging: {
|
|
1694
|
+
baseLogger?: Logger | undefined;
|
|
1695
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
1696
|
+
};
|
|
1697
|
+
endpoint: string | undefined;
|
|
1698
|
+
token: string | undefined;
|
|
1699
|
+
namespace: string | undefined;
|
|
1700
|
+
headers: Record<string, string>;
|
|
1701
|
+
managerBasePath: string;
|
|
1702
|
+
managerPort: number;
|
|
1703
|
+
inspector: {
|
|
1704
|
+
enabled: boolean;
|
|
1705
|
+
token: () => string;
|
|
1706
|
+
defaultEndpoint?: string | undefined;
|
|
1707
|
+
};
|
|
1708
|
+
serverless: {
|
|
1709
|
+
spawnEngine: boolean;
|
|
1710
|
+
engineVersion: string;
|
|
1711
|
+
basePath: string;
|
|
1712
|
+
publicEndpoint: string | undefined;
|
|
1713
|
+
publicToken: string | undefined;
|
|
1714
|
+
configureRunnerPool?: {
|
|
1715
|
+
url: string;
|
|
1716
|
+
name?: string | undefined;
|
|
1717
|
+
headers?: Record<string, string> | undefined;
|
|
1718
|
+
maxRunners?: number | undefined;
|
|
1719
|
+
minRunners?: number | undefined;
|
|
1720
|
+
requestLifespan?: number | undefined;
|
|
1721
|
+
runnersMargin?: number | undefined;
|
|
1722
|
+
slotsPerRunner?: number | undefined;
|
|
1723
|
+
metadata?: Record<string, unknown> | undefined;
|
|
1724
|
+
metadataPollInterval?: number | undefined;
|
|
1725
|
+
drainOnVersionUpgrade?: boolean | undefined;
|
|
1726
|
+
} | undefined;
|
|
1727
|
+
};
|
|
1728
|
+
runner: {
|
|
1729
|
+
totalSlots: number;
|
|
1730
|
+
runnerName: string;
|
|
1731
|
+
runnerKey: string | undefined;
|
|
1732
|
+
version: number;
|
|
1733
|
+
};
|
|
1734
|
+
driver?: {
|
|
1735
|
+
name: string;
|
|
1736
|
+
displayName: string;
|
|
1737
|
+
manager: ManagerDriverBuilder;
|
|
1738
|
+
actor: ActorDriverBuilder;
|
|
1739
|
+
autoStartActorDriver: boolean;
|
|
1740
|
+
} | undefined;
|
|
1741
|
+
serveManager?: boolean | undefined;
|
|
1742
|
+
managerHost?: string | undefined;
|
|
1743
|
+
}>>;
|
|
1744
|
+
type RegistryConfig = z$1.infer<typeof RegistryConfigSchema>;
|
|
1745
|
+
type RegistryConfigInput<A extends RegistryActors> = Omit<z$1.input<typeof RegistryConfigSchema>, "use"> & {
|
|
1746
|
+
use: A;
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
type AnyActorDefinition = ActorDefinition<any, any, any, any, any, any, any, any, any>;
|
|
1750
|
+
declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
|
|
1751
|
+
#private;
|
|
1752
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
|
|
1753
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
|
|
1754
|
+
instantiate(): ActorInstance<S, CP, CS, V, I, DB, E, Q>;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* Action function returned by Actor connections and handles.
|
|
1759
|
+
*
|
|
1760
|
+
* @typedef {Function} ActorActionFunction
|
|
1761
|
+
* @template Args
|
|
1762
|
+
* @template Response
|
|
1763
|
+
* @param {...Args} args - Arguments for the action function.
|
|
1764
|
+
* @returns {Promise<Response>}
|
|
1765
|
+
*/
|
|
1766
|
+
type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
|
|
1767
|
+
/**
|
|
1768
|
+
* Maps action methods from actor definition to typed function signatures.
|
|
1769
|
+
*/
|
|
1770
|
+
type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends ActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
|
|
1771
|
+
[K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
|
|
1772
|
+
} : never;
|
|
1773
|
+
|
|
1774
|
+
declare class ActorClientError extends Error {
|
|
1775
|
+
}
|
|
1776
|
+
declare class InternalError extends ActorClientError {
|
|
1777
|
+
}
|
|
1778
|
+
declare class ManagerError extends ActorClientError {
|
|
1779
|
+
constructor(error: string, opts?: ErrorOptions);
|
|
1780
|
+
}
|
|
1781
|
+
declare class MalformedResponseMessage extends ActorClientError {
|
|
1782
|
+
constructor(cause?: unknown);
|
|
1783
|
+
}
|
|
1784
|
+
declare class ActorError extends ActorClientError {
|
|
1785
|
+
readonly group: string;
|
|
1786
|
+
readonly code: string;
|
|
1787
|
+
readonly metadata?: unknown | undefined;
|
|
1788
|
+
__type: string;
|
|
1789
|
+
constructor(group: string, code: string, message: string, metadata?: unknown | undefined);
|
|
1790
|
+
}
|
|
1791
|
+
declare class ActorConnDisposed extends ActorClientError {
|
|
1792
|
+
constructor();
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
interface QueueSendWaitOptions {
|
|
1796
|
+
wait: true;
|
|
1797
|
+
timeout?: number;
|
|
1798
|
+
signal?: AbortSignal;
|
|
1799
|
+
}
|
|
1800
|
+
interface QueueSendNoWaitOptions {
|
|
1801
|
+
wait?: false;
|
|
1802
|
+
timeout?: never;
|
|
1803
|
+
signal?: AbortSignal;
|
|
1804
|
+
}
|
|
1805
|
+
interface QueueSendResult {
|
|
1806
|
+
status: "completed" | "timedOut";
|
|
1807
|
+
response?: unknown;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
/**
|
|
1811
|
+
* Connection status for an actor connection.
|
|
1812
|
+
*
|
|
1813
|
+
* - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
|
|
1814
|
+
* - `"connecting"`: Attempting to establish connection
|
|
1815
|
+
* - `"connected"`: Connection is active
|
|
1816
|
+
* - `"disconnected"`: Connection was lost, will auto-reconnect
|
|
1817
|
+
*/
|
|
1818
|
+
type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
|
|
1819
|
+
/**
|
|
1820
|
+
* A function that unsubscribes from an event.
|
|
1821
|
+
*
|
|
1822
|
+
* @typedef {Function} EventUnsubscribe
|
|
1823
|
+
*/
|
|
1824
|
+
type EventUnsubscribe = () => void;
|
|
1825
|
+
/**
|
|
1826
|
+
* A function that handles connection errors.
|
|
1827
|
+
*
|
|
1828
|
+
* @typedef {Function} ActorErrorCallback
|
|
1829
|
+
*/
|
|
1830
|
+
type ActorErrorCallback = (error: ActorError) => void;
|
|
1831
|
+
/**
|
|
1832
|
+
* A callback for connection state changes.
|
|
1833
|
+
*
|
|
1834
|
+
* @typedef {Function} ConnectionStateCallback
|
|
1835
|
+
*/
|
|
1836
|
+
type ConnectionStateCallback = () => void;
|
|
1837
|
+
/**
|
|
1838
|
+
* A callback for connection status changes.
|
|
1839
|
+
*
|
|
1840
|
+
* @typedef {Function} StatusChangeCallback
|
|
1841
|
+
*/
|
|
1842
|
+
type StatusChangeCallback = (status: ActorConnStatus) => void;
|
|
1843
|
+
declare const CONNECT_SYMBOL: unique symbol;
|
|
1844
|
+
/**
|
|
1845
|
+
* Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
|
|
1846
|
+
*
|
|
1847
|
+
* @see {@link ActorConn}
|
|
1848
|
+
*/
|
|
1849
|
+
declare class ActorConnRaw {
|
|
1850
|
+
#private;
|
|
1851
|
+
/**
|
|
1852
|
+
* Do not call this directly.
|
|
1853
|
+
*
|
|
1854
|
+
* Creates an instance of ActorConnRaw.
|
|
1855
|
+
*
|
|
1856
|
+
* @protected
|
|
1857
|
+
*/
|
|
1858
|
+
constructor(client: ClientRaw, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1859
|
+
send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
|
|
1860
|
+
send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
|
|
1861
|
+
/**
|
|
1862
|
+
* Call a raw action connection. See {@link ActorConn} for type-safe action calls.
|
|
1863
|
+
*
|
|
1864
|
+
* @see {@link ActorConn}
|
|
1865
|
+
* @template Args - The type of arguments to pass to the action function.
|
|
1866
|
+
* @template Response - The type of the response returned by the action function.
|
|
1867
|
+
* @param {string} name - The name of the action function to call.
|
|
1868
|
+
* @param {...Args} args - The arguments to pass to the action function.
|
|
1869
|
+
* @returns {Promise<Response>} - A promise that resolves to the response of the action function.
|
|
1870
|
+
*/
|
|
1871
|
+
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
1872
|
+
name: string;
|
|
1873
|
+
args: Args;
|
|
1874
|
+
signal?: AbortSignal;
|
|
1875
|
+
}): Promise<Response>;
|
|
1876
|
+
/**
|
|
1877
|
+
* Do not call this directly.
|
|
1878
|
+
* Establishes a connection to the server using the specified endpoint & encoding & driver.
|
|
1879
|
+
*
|
|
1880
|
+
* @protected
|
|
1881
|
+
*/
|
|
1882
|
+
[CONNECT_SYMBOL](): void;
|
|
1883
|
+
/**
|
|
1884
|
+
* Subscribes to an event that will happen repeatedly.
|
|
1885
|
+
*
|
|
1886
|
+
* @template Args - The type of arguments the event callback will receive.
|
|
1887
|
+
* @param {string} eventName - The name of the event to subscribe to.
|
|
1888
|
+
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
1889
|
+
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
1890
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1891
|
+
*/
|
|
1892
|
+
on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1893
|
+
/**
|
|
1894
|
+
* Subscribes to an event that will be triggered only once.
|
|
1895
|
+
*
|
|
1896
|
+
* @template Args - The type of arguments the event callback will receive.
|
|
1897
|
+
* @param {string} eventName - The name of the event to subscribe to.
|
|
1898
|
+
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
1899
|
+
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
1900
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1901
|
+
*/
|
|
1902
|
+
once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1903
|
+
/**
|
|
1904
|
+
* Subscribes to connection errors.
|
|
1905
|
+
*
|
|
1906
|
+
* @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
|
|
1907
|
+
* @returns {() => void} - A function to unsubscribe from the error handler.
|
|
1908
|
+
*/
|
|
1909
|
+
onError(callback: ActorErrorCallback): () => void;
|
|
1910
|
+
/**
|
|
1911
|
+
* Returns the current connection status.
|
|
1912
|
+
*
|
|
1913
|
+
* @returns {ActorConnStatus} - The current connection status.
|
|
1914
|
+
*/
|
|
1915
|
+
get connStatus(): ActorConnStatus;
|
|
1916
|
+
/**
|
|
1917
|
+
* Returns whether the connection is currently open.
|
|
1918
|
+
*
|
|
1919
|
+
* @deprecated Use `connStatus` instead.
|
|
1920
|
+
* @returns {boolean} - True if the connection is open, false otherwise.
|
|
1921
|
+
*/
|
|
1922
|
+
get isConnected(): boolean;
|
|
1923
|
+
/**
|
|
1924
|
+
* Subscribes to connection open events.
|
|
1925
|
+
*
|
|
1926
|
+
* This is called when the WebSocket connection is established and the Init message is received.
|
|
1927
|
+
*
|
|
1928
|
+
* @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
|
|
1929
|
+
* @returns {() => void} - A function to unsubscribe from the open handler.
|
|
1930
|
+
*/
|
|
1931
|
+
onOpen(callback: ConnectionStateCallback): () => void;
|
|
1932
|
+
/**
|
|
1933
|
+
* Subscribes to connection close events.
|
|
1934
|
+
*
|
|
1935
|
+
* This is called when the WebSocket connection is closed. The connection will automatically
|
|
1936
|
+
* attempt to reconnect unless disposed.
|
|
1937
|
+
*
|
|
1938
|
+
* @param {ConnectionStateCallback} callback - The callback function to execute when the connection closes.
|
|
1939
|
+
* @returns {() => void} - A function to unsubscribe from the close handler.
|
|
1940
|
+
*/
|
|
1941
|
+
onClose(callback: ConnectionStateCallback): () => void;
|
|
1942
|
+
/**
|
|
1943
|
+
* Subscribes to connection status changes.
|
|
1944
|
+
*
|
|
1945
|
+
* This is called whenever the connection status changes between Disconnected, Connecting, and Connected.
|
|
1946
|
+
*
|
|
1947
|
+
* @param {StatusChangeCallback} callback - The callback function to execute when the status changes.
|
|
1948
|
+
* @returns {() => void} - A function to unsubscribe from the status change handler.
|
|
1949
|
+
*/
|
|
1950
|
+
onStatusChange(callback: StatusChangeCallback): () => void;
|
|
1951
|
+
/**
|
|
1952
|
+
* Disconnects from the actor.
|
|
1953
|
+
*
|
|
1954
|
+
* @returns {Promise<void>} A promise that resolves when the socket is gracefully closed.
|
|
1955
|
+
*/
|
|
1956
|
+
dispose(): Promise<void>;
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
* Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
|
|
1960
|
+
*
|
|
1961
|
+
* @example
|
|
1962
|
+
* ```
|
|
1963
|
+
* const room = client.connect<ChatRoom>(...etc...);
|
|
1964
|
+
* // This calls the action named `sendMessage` on the `ChatRoom` actor.
|
|
1965
|
+
* await room.sendMessage('Hello, world!');
|
|
1966
|
+
* ```
|
|
1967
|
+
*
|
|
1968
|
+
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
1969
|
+
*
|
|
1970
|
+
* @template AD The actor class that this connection is for.
|
|
1971
|
+
* @see {@link ActorConnRaw}
|
|
1972
|
+
*/
|
|
1973
|
+
type ActorConn<AD extends AnyActorDefinition> = ActorConnRaw & ActorDefinitionActions<AD>;
|
|
1974
|
+
|
|
1975
|
+
/**
|
|
1976
|
+
* Provides underlying functions for stateless {@link ActorHandle} for action calls.
|
|
1977
|
+
* Similar to ActorConnRaw but doesn't maintain a connection.
|
|
1978
|
+
*
|
|
1979
|
+
* @see {@link ActorHandle}
|
|
1980
|
+
*/
|
|
1981
|
+
declare class ActorHandleRaw {
|
|
1982
|
+
#private;
|
|
1983
|
+
/**
|
|
1984
|
+
* Do not call this directly.
|
|
1985
|
+
*
|
|
1986
|
+
* Creates an instance of ActorHandleRaw.
|
|
1987
|
+
*
|
|
1988
|
+
* @protected
|
|
1989
|
+
*/
|
|
1990
|
+
constructor(client: any, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1991
|
+
send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
|
|
1992
|
+
send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
|
|
1993
|
+
/**
|
|
1994
|
+
* Call a raw action. This method sends an HTTP request to invoke the named action.
|
|
1995
|
+
*
|
|
1996
|
+
* @see {@link ActorHandle}
|
|
1997
|
+
* @template Args - The type of arguments to pass to the action function.
|
|
1998
|
+
* @template Response - The type of the response returned by the action function.
|
|
1999
|
+
*/
|
|
2000
|
+
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
2001
|
+
name: string;
|
|
2002
|
+
args: Args;
|
|
2003
|
+
signal?: AbortSignal;
|
|
2004
|
+
}): Promise<Response>;
|
|
2005
|
+
/**
|
|
2006
|
+
* Establishes a persistent connection to the actor.
|
|
2007
|
+
*
|
|
2008
|
+
* @template AD The actor class that this connection is for.
|
|
2009
|
+
* @returns {ActorConn<AD>} A connection to the actor.
|
|
2010
|
+
*/
|
|
2011
|
+
connect(): ActorConn<AnyActorDefinition>;
|
|
2012
|
+
/**
|
|
2013
|
+
* Fetches a resource from this actor via the /request endpoint. This is a
|
|
2014
|
+
* convenience wrapper around the raw HTTP API.
|
|
2015
|
+
*/
|
|
2016
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
2017
|
+
/**
|
|
2018
|
+
* Opens a raw WebSocket connection to this actor.
|
|
2019
|
+
*/
|
|
2020
|
+
webSocket(path?: string, protocols?: string | string[]): Promise<any>;
|
|
2021
|
+
/**
|
|
2022
|
+
* Resolves the actor to get its unique actor ID.
|
|
2023
|
+
*/
|
|
2024
|
+
resolve(): Promise<string>;
|
|
2025
|
+
/**
|
|
2026
|
+
* Returns the raw URL for routing traffic to the actor.
|
|
2027
|
+
*/
|
|
2028
|
+
getGatewayUrl(): Promise<string>;
|
|
2029
|
+
}
|
|
2030
|
+
/**
|
|
2031
|
+
* Stateless handle to a actor. Allows calling actor's remote procedure calls with inferred types
|
|
2032
|
+
* without establishing a persistent connection.
|
|
2033
|
+
*
|
|
2034
|
+
* @example
|
|
2035
|
+
* ```
|
|
2036
|
+
* const room = client.get<ChatRoom>(...etc...);
|
|
2037
|
+
* // This calls the action named `sendMessage` on the `ChatRoom` actor without a connection.
|
|
2038
|
+
* await room.sendMessage('Hello, world!');
|
|
2039
|
+
* ```
|
|
2040
|
+
*
|
|
2041
|
+
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
2042
|
+
*
|
|
2043
|
+
* @template AD The actor class that this handle is for.
|
|
2044
|
+
* @see {@link ActorHandleRaw}
|
|
2045
|
+
*/
|
|
2046
|
+
type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect"> & {
|
|
2047
|
+
connect(): ActorConn<AD>;
|
|
2048
|
+
resolve(): Promise<string>;
|
|
2049
|
+
} & ActorDefinitionActions<AD>;
|
|
2050
|
+
|
|
2051
|
+
declare const ClientConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
|
|
2052
|
+
endpoint: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string, string | undefined>>;
|
|
2053
|
+
token: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
|
|
2054
|
+
namespace: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
|
|
2055
|
+
runnerName: z$2.ZodDefault<z$2.ZodString>;
|
|
2056
|
+
encoding: z$2.ZodDefault<z$2.ZodEnum<{
|
|
2057
|
+
json: "json";
|
|
2058
|
+
cbor: "cbor";
|
|
2059
|
+
bare: "bare";
|
|
2060
|
+
}>>;
|
|
2061
|
+
headers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodString>>>;
|
|
2062
|
+
getUpgradeWebSocket: z$2.ZodOptional<z$2.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
|
|
2063
|
+
disableMetadataLookup: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
|
|
2064
|
+
devtools: z$2.ZodDefault<z$2.ZodBoolean>;
|
|
2065
|
+
}, z$2.core.$strip>, z$2.ZodTransform<{
|
|
2066
|
+
endpoint: string | undefined;
|
|
2067
|
+
namespace: string;
|
|
2068
|
+
token: string | undefined;
|
|
2069
|
+
runnerName: string;
|
|
2070
|
+
encoding: "json" | "cbor" | "bare";
|
|
2071
|
+
headers: Record<string, string>;
|
|
2072
|
+
disableMetadataLookup: boolean;
|
|
2073
|
+
devtools: boolean;
|
|
2074
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2075
|
+
}, {
|
|
2076
|
+
endpoint: string;
|
|
2077
|
+
token: string | undefined;
|
|
2078
|
+
namespace: string | undefined;
|
|
2079
|
+
runnerName: string;
|
|
2080
|
+
encoding: "json" | "cbor" | "bare";
|
|
2081
|
+
headers: Record<string, string>;
|
|
2082
|
+
disableMetadataLookup: boolean;
|
|
2083
|
+
devtools: boolean;
|
|
2084
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2085
|
+
}>>;
|
|
2086
|
+
type ClientConfigInput = z$2.input<typeof ClientConfigSchema>;
|
|
2087
|
+
|
|
2088
|
+
/** Extract the actor registry from the registry definition. */
|
|
2089
|
+
type ExtractActorsFromRegistry<A extends Registry<any>> = A extends Registry<infer Actors> ? Actors : never;
|
|
2090
|
+
/** Extract the registry definition from the client. */
|
|
2091
|
+
type ExtractRegistryFromClient<C extends Client<Registry<{}>>> = C extends Client<infer A> ? A : never;
|
|
2092
|
+
/**
|
|
2093
|
+
* Represents a actor accessor that provides methods to interact with a specific actor.
|
|
2094
|
+
*/
|
|
2095
|
+
interface ActorAccessor<AD extends AnyActorDefinition> {
|
|
2096
|
+
/**
|
|
2097
|
+
* Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
|
|
2098
|
+
* The actor name is automatically injected from the property accessor.
|
|
2099
|
+
*
|
|
2100
|
+
* @template AD The actor class that this handle is for.
|
|
2101
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2102
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2103
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2104
|
+
*/
|
|
2105
|
+
get(key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
2106
|
+
/**
|
|
2107
|
+
* Gets a stateless handle to a actor by its key, creating it if necessary.
|
|
2108
|
+
* The actor name is automatically injected from the property accessor.
|
|
2109
|
+
*
|
|
2110
|
+
* @template AD The actor class that this handle is for.
|
|
2111
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2112
|
+
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
2113
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2114
|
+
*/
|
|
2115
|
+
getOrCreate(key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
|
|
2116
|
+
/**
|
|
2117
|
+
* Gets a stateless handle to a actor by its ID.
|
|
2118
|
+
*
|
|
2119
|
+
* @template AD The actor class that this handle is for.
|
|
2120
|
+
* @param {string} actorId - The ID of the actor.
|
|
2121
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2122
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2123
|
+
*/
|
|
2124
|
+
getForId(actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
2125
|
+
/**
|
|
2126
|
+
* Creates a new actor with the name automatically injected from the property accessor,
|
|
2127
|
+
* and returns a stateless handle to it with the actor ID resolved.
|
|
2128
|
+
*
|
|
2129
|
+
* @template AD The actor class that this handle is for.
|
|
2130
|
+
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
2131
|
+
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
2132
|
+
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
2133
|
+
*/
|
|
2134
|
+
create(key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Options for querying actors.
|
|
2138
|
+
* @typedef {Object} QueryOptions
|
|
2139
|
+
* @property {unknown} [parameters] - Parameters to pass to the connection.
|
|
2140
|
+
*/
|
|
2141
|
+
interface QueryOptions {
|
|
2142
|
+
/** Parameters to pass to the connection. */
|
|
2143
|
+
params?: unknown;
|
|
2144
|
+
/** Signal to abort the request. */
|
|
2145
|
+
signal?: AbortSignal;
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Options for getting a actor by ID.
|
|
2149
|
+
* @typedef {QueryOptions} GetWithIdOptions
|
|
2150
|
+
*/
|
|
2151
|
+
interface GetWithIdOptions extends QueryOptions {
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
* Options for getting a actor.
|
|
2155
|
+
* @typedef {QueryOptions} GetOptions
|
|
2156
|
+
*/
|
|
2157
|
+
interface GetOptions extends QueryOptions {
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Options for getting or creating a actor.
|
|
2161
|
+
* @typedef {QueryOptions} GetOrCreateOptions
|
|
2162
|
+
* @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
|
|
2163
|
+
*/
|
|
2164
|
+
interface GetOrCreateOptions extends QueryOptions {
|
|
2165
|
+
/** Region to create the actor in if it doesn't exist. */
|
|
2166
|
+
createInRegion?: string;
|
|
2167
|
+
/** Input data to pass to the actor. */
|
|
2168
|
+
createWithInput?: unknown;
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Options for creating a actor.
|
|
2172
|
+
* @typedef {QueryOptions} CreateOptions
|
|
2173
|
+
* @property {string} [region] - The region to create the actor in.
|
|
2174
|
+
*/
|
|
2175
|
+
interface CreateOptions extends QueryOptions {
|
|
2176
|
+
/** The region to create the actor in. */
|
|
2177
|
+
region?: string;
|
|
2178
|
+
/** Input data to pass to the actor. */
|
|
2179
|
+
input?: unknown;
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* Represents a region to connect to.
|
|
2183
|
+
* @typedef {Object} Region
|
|
2184
|
+
* @property {string} id - The region ID.
|
|
2185
|
+
* @property {string} name - The region name.
|
|
2186
|
+
* @see {@link https://rivet.dev/docs/edge|Edge Networking}
|
|
2187
|
+
* @see {@link https://rivet.dev/docs/regions|Available Regions}
|
|
2188
|
+
*/
|
|
2189
|
+
interface Region {
|
|
2190
|
+
/**
|
|
2191
|
+
* The region slug.
|
|
2192
|
+
*/
|
|
2193
|
+
id: string;
|
|
2194
|
+
/**
|
|
2195
|
+
* The human-friendly region name.
|
|
2196
|
+
*/
|
|
2197
|
+
name: string;
|
|
2198
|
+
}
|
|
2199
|
+
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
2200
|
+
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
2201
|
+
/**
|
|
2202
|
+
* Client for managing & connecting to actors.
|
|
2203
|
+
*
|
|
2204
|
+
* @template A The actors map type that defines the available actors.
|
|
2205
|
+
* @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
|
|
2206
|
+
*/
|
|
2207
|
+
declare class ClientRaw {
|
|
2208
|
+
#private;
|
|
2209
|
+
[ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
|
|
2210
|
+
/**
|
|
2211
|
+
* Creates an instance of Client.
|
|
2212
|
+
*/
|
|
2213
|
+
constructor(driver: ManagerDriver, encoding: Encoding | undefined);
|
|
2214
|
+
/**
|
|
2215
|
+
* Gets a stateless handle to a actor by its ID.
|
|
2216
|
+
*
|
|
2217
|
+
* @template AD The actor class that this handle is for.
|
|
2218
|
+
* @param {string} name - The name of the actor.
|
|
2219
|
+
* @param {string} actorId - The ID of the actor.
|
|
2220
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2221
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2222
|
+
*/
|
|
2223
|
+
getForId<AD extends AnyActorDefinition>(name: string, actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
2224
|
+
/**
|
|
2225
|
+
* Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
|
|
2226
|
+
*
|
|
2227
|
+
* @template AD The actor class that this handle is for.
|
|
2228
|
+
* @param {string} name - The name of the actor.
|
|
2229
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2230
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2231
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2232
|
+
*/
|
|
2233
|
+
get<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
2234
|
+
/**
|
|
2235
|
+
* Gets a stateless handle to a actor by its key, creating it if necessary.
|
|
2236
|
+
*
|
|
2237
|
+
* @template AD The actor class that this handle is for.
|
|
2238
|
+
* @param {string} name - The name of the actor.
|
|
2239
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2240
|
+
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
2241
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2242
|
+
*/
|
|
2243
|
+
getOrCreate<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
|
|
2244
|
+
/**
|
|
2245
|
+
* Creates a new actor with the provided key and returns a stateless handle to it.
|
|
2246
|
+
* Resolves the actor ID and returns a handle with getForId query.
|
|
2247
|
+
*
|
|
2248
|
+
* @template AD The actor class that this handle is for.
|
|
2249
|
+
* @param {string} name - The name of the actor.
|
|
2250
|
+
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
2251
|
+
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
2252
|
+
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
2253
|
+
*/
|
|
2254
|
+
create<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
2255
|
+
[CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(conn: ActorConnRaw): ActorConn<AD>;
|
|
2256
|
+
/**
|
|
2257
|
+
* Disconnects from all actors.
|
|
2258
|
+
*
|
|
2259
|
+
* @returns {Promise<void>} A promise that resolves when all connections are closed.
|
|
2260
|
+
*/
|
|
2261
|
+
dispose(): Promise<void>;
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Client type with actor accessors.
|
|
2265
|
+
* This adds property accessors for actor names to the ClientRaw base class.
|
|
2266
|
+
*
|
|
2267
|
+
* @template A The actor registry type.
|
|
2268
|
+
*/
|
|
2269
|
+
type Client<A extends Registry<any>> = ClientRaw & {
|
|
2270
|
+
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
|
|
2271
|
+
};
|
|
2272
|
+
type AnyClient = Client<Registry<any>>;
|
|
2273
|
+
|
|
2274
|
+
declare const LegacyRunnerConfigSchema: z.ZodDefault<z.ZodPipe<z.ZodObject<{
|
|
2275
|
+
driver: z.ZodOptional<z.ZodObject<{
|
|
2276
|
+
name: z.ZodString;
|
|
2277
|
+
manager: z.ZodCustom<ManagerDriverBuilder, ManagerDriverBuilder>;
|
|
2278
|
+
actor: z.ZodCustom<ActorDriverBuilder, ActorDriverBuilder>;
|
|
2279
|
+
}, z.core.$strip>>;
|
|
2280
|
+
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2281
|
+
maxOutgoingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2282
|
+
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
2283
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
2284
|
+
token: z.ZodDefault<z.ZodOptional<z.ZodCustom<() => string, () => string>>>;
|
|
2285
|
+
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
2286
|
+
}, z.core.$strip>>>;
|
|
2287
|
+
disableDefaultServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2288
|
+
defaultServerPort: z.ZodDefault<z.ZodNumber>;
|
|
2289
|
+
runEngine: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2290
|
+
runEngineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2291
|
+
overrideServerAddress: z.ZodOptional<z.ZodString>;
|
|
2292
|
+
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2293
|
+
runnerKind: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
2294
|
+
serverless: "serverless";
|
|
2295
|
+
normal: "normal";
|
|
2296
|
+
}>>>;
|
|
2297
|
+
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2298
|
+
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2299
|
+
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
2300
|
+
baseLogger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
2301
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
2302
|
+
error: "error";
|
|
2303
|
+
trace: "trace";
|
|
2304
|
+
fatal: "fatal";
|
|
2305
|
+
warn: "warn";
|
|
2306
|
+
info: "info";
|
|
2307
|
+
debug: "debug";
|
|
2308
|
+
silent: "silent";
|
|
2309
|
+
}>>;
|
|
2310
|
+
}, z.core.$strip>>>;
|
|
2311
|
+
autoConfigureServerless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
2312
|
+
url: z.ZodOptional<z.ZodString>;
|
|
2313
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
2314
|
+
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
2315
|
+
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
2316
|
+
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
2317
|
+
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
2318
|
+
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
2319
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2320
|
+
}, z.core.$strip>]>>;
|
|
2321
|
+
endpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string, string | undefined>>;
|
|
2322
|
+
token: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
2323
|
+
namespace: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
2324
|
+
runnerName: z.ZodDefault<z.ZodString>;
|
|
2325
|
+
encoding: z.ZodDefault<z.ZodEnum<{
|
|
2326
|
+
json: "json";
|
|
2327
|
+
cbor: "cbor";
|
|
2328
|
+
bare: "bare";
|
|
2329
|
+
}>>;
|
|
2330
|
+
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
2331
|
+
getUpgradeWebSocket: z.ZodOptional<z.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
|
|
2332
|
+
disableMetadataLookup: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2333
|
+
devtools: z.ZodDefault<z.ZodBoolean>;
|
|
2334
|
+
runnerKey: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
2335
|
+
totalSlots: z.ZodDefault<z.ZodNumber>;
|
|
2336
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
2337
|
+
runnerKey: string | undefined;
|
|
2338
|
+
endpoint: string | undefined;
|
|
2339
|
+
namespace: string;
|
|
2340
|
+
token: string | undefined;
|
|
2341
|
+
runnerName: string;
|
|
2342
|
+
encoding: "json" | "cbor" | "bare";
|
|
2343
|
+
headers: Record<string, string>;
|
|
2344
|
+
disableMetadataLookup: boolean;
|
|
2345
|
+
devtools: boolean;
|
|
2346
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2347
|
+
maxIncomingMessageSize: number;
|
|
2348
|
+
maxOutgoingMessageSize: number;
|
|
2349
|
+
inspector: {
|
|
2350
|
+
enabled: boolean;
|
|
2351
|
+
token: () => string;
|
|
2352
|
+
defaultEndpoint?: string | undefined;
|
|
2353
|
+
};
|
|
2354
|
+
disableDefaultServer: boolean;
|
|
2355
|
+
defaultServerPort: number;
|
|
2356
|
+
runEngine: boolean;
|
|
2357
|
+
runEngineVersion: string;
|
|
2358
|
+
disableActorDriver: boolean;
|
|
2359
|
+
runnerKind: "serverless" | "normal";
|
|
2360
|
+
basePath: string;
|
|
2361
|
+
noWelcome: boolean;
|
|
2362
|
+
logging: {
|
|
2363
|
+
baseLogger?: Logger | undefined;
|
|
2364
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
2365
|
+
};
|
|
2366
|
+
totalSlots: number;
|
|
2367
|
+
driver?: {
|
|
2368
|
+
name: string;
|
|
2369
|
+
manager: ManagerDriverBuilder;
|
|
2370
|
+
actor: ActorDriverBuilder;
|
|
2371
|
+
} | undefined;
|
|
2372
|
+
overrideServerAddress?: string | undefined;
|
|
2373
|
+
autoConfigureServerless?: boolean | {
|
|
2374
|
+
url?: string | undefined;
|
|
2375
|
+
headers?: Record<string, string> | undefined;
|
|
2376
|
+
maxRunners?: number | undefined;
|
|
2377
|
+
minRunners?: number | undefined;
|
|
2378
|
+
requestLifespan?: number | undefined;
|
|
2379
|
+
runnersMargin?: number | undefined;
|
|
2380
|
+
slotsPerRunner?: number | undefined;
|
|
2381
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2382
|
+
} | undefined;
|
|
2383
|
+
}, {
|
|
2384
|
+
maxIncomingMessageSize: number;
|
|
2385
|
+
maxOutgoingMessageSize: number;
|
|
2386
|
+
inspector: {
|
|
2387
|
+
enabled: boolean;
|
|
2388
|
+
token: () => string;
|
|
2389
|
+
defaultEndpoint?: string | undefined;
|
|
2390
|
+
};
|
|
2391
|
+
disableDefaultServer: boolean;
|
|
2392
|
+
defaultServerPort: number;
|
|
2393
|
+
runEngine: boolean;
|
|
2394
|
+
runEngineVersion: string;
|
|
2395
|
+
disableActorDriver: boolean;
|
|
2396
|
+
runnerKind: "serverless" | "normal";
|
|
2397
|
+
basePath: string;
|
|
2398
|
+
noWelcome: boolean;
|
|
2399
|
+
logging: {
|
|
2400
|
+
baseLogger?: Logger | undefined;
|
|
2401
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
2402
|
+
};
|
|
2403
|
+
endpoint: string;
|
|
2404
|
+
token: string | undefined;
|
|
2405
|
+
namespace: string | undefined;
|
|
2406
|
+
runnerName: string;
|
|
2407
|
+
encoding: "json" | "cbor" | "bare";
|
|
2408
|
+
headers: Record<string, string>;
|
|
2409
|
+
disableMetadataLookup: boolean;
|
|
2410
|
+
devtools: boolean;
|
|
2411
|
+
runnerKey: string | undefined;
|
|
2412
|
+
totalSlots: number;
|
|
2413
|
+
driver?: {
|
|
2414
|
+
name: string;
|
|
2415
|
+
manager: ManagerDriverBuilder;
|
|
2416
|
+
actor: ActorDriverBuilder;
|
|
2417
|
+
} | undefined;
|
|
2418
|
+
overrideServerAddress?: string | undefined;
|
|
2419
|
+
autoConfigureServerless?: boolean | {
|
|
2420
|
+
url?: string | undefined;
|
|
2421
|
+
headers?: Record<string, string> | undefined;
|
|
2422
|
+
maxRunners?: number | undefined;
|
|
2423
|
+
minRunners?: number | undefined;
|
|
2424
|
+
requestLifespan?: number | undefined;
|
|
2425
|
+
runnersMargin?: number | undefined;
|
|
2426
|
+
slotsPerRunner?: number | undefined;
|
|
2427
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2428
|
+
} | undefined;
|
|
2429
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2430
|
+
}>>>;
|
|
2431
|
+
type LegacyRunnerConfigInput = z.input<typeof LegacyRunnerConfigSchema>;
|
|
2432
|
+
|
|
2433
|
+
type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
|
|
2434
|
+
interface ServerlessHandler {
|
|
2435
|
+
fetch: FetchHandler;
|
|
2436
|
+
}
|
|
2437
|
+
interface LegacyStartServerOutput<A extends Registry<any>> {
|
|
2438
|
+
/** Client to communicate with the actors. */
|
|
2439
|
+
client: Client<A>;
|
|
2440
|
+
/** Fetch handler to manually route requests to the Rivet manager API. */
|
|
2441
|
+
fetch: FetchHandler;
|
|
2442
|
+
}
|
|
2443
|
+
declare class Registry<A extends RegistryActors> {
|
|
2444
|
+
#private;
|
|
2445
|
+
get config(): RegistryConfigInput<A>;
|
|
2446
|
+
parseConfig(): RegistryConfig;
|
|
2447
|
+
constructor(config: RegistryConfigInput<A>);
|
|
2448
|
+
/**
|
|
2449
|
+
* Handle an incoming HTTP request for serverless deployments.
|
|
2450
|
+
*
|
|
2451
|
+
* @example
|
|
2452
|
+
* ```ts
|
|
2453
|
+
* const app = new Hono();
|
|
2454
|
+
* app.all("/api/rivet/*", (c) => registry.handler(c.req.raw));
|
|
2455
|
+
* export default app;
|
|
2456
|
+
* ```
|
|
2457
|
+
*/
|
|
2458
|
+
handler(request: Request): Promise<Response>;
|
|
2459
|
+
/**
|
|
2460
|
+
* Returns a fetch handler for serverless deployments.
|
|
2461
|
+
*
|
|
2462
|
+
* @example
|
|
2463
|
+
* ```ts
|
|
2464
|
+
* export default registry.serve();
|
|
2465
|
+
* ```
|
|
2466
|
+
*/
|
|
2467
|
+
serve(): ServerlessHandler;
|
|
2468
|
+
/**
|
|
2469
|
+
* Starts an actor runner for standalone server deployments.
|
|
2470
|
+
*/
|
|
2471
|
+
startRunner(): void;
|
|
2472
|
+
/**
|
|
2473
|
+
* Runs the registry for a server.
|
|
2474
|
+
*
|
|
2475
|
+
* @deprecated Use {@link Registry.startRunner} for long-running servers or {@link Registry.handler} for serverless deployments.
|
|
2476
|
+
*/
|
|
2477
|
+
start(inputConfig?: LegacyRunnerConfigInput): LegacyStartServerOutput<this>;
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* Creates a client with the actor accessor proxy.
|
|
2482
|
+
*/
|
|
2483
|
+
declare function createClient<A extends Registry<any>>(endpointOrConfig?: string | ClientConfigInput): Client<A>;
|
|
2484
|
+
|
|
2485
|
+
export { type ActorAccessor, type ActorActionFunction, ActorClientError, type ActorConn, ActorConnDisposed, ActorConnRaw, type ActorConnStatus, ActorDefinition, ActorError, type ActorHandle, ActorHandleRaw, type AnyActorDefinition, type Client, ClientRaw, type ConnectionStateCallback, type CreateOptions, type CreateRequest, type Encoding, type EventUnsubscribe, type ExtractActorsFromRegistry, type ExtractRegistryFromClient, type GetOptions, type GetWithIdOptions, InternalError, KEYS as KV_KEYS, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, type StatusChangeCallback, createClient };
|