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,196 @@
|
|
|
1
|
+
import type { HibernatingWebSocketMetadata } from "@rivetkit/engine-runner";
|
|
2
|
+
import onChange from "@rivetkit/on-change";
|
|
3
|
+
import * as cbor from "cbor-x";
|
|
4
|
+
import invariant from "invariant";
|
|
5
|
+
import { isCborSerializable } from "@/common/utils";
|
|
6
|
+
import * as errors from "../errors";
|
|
7
|
+
import { assertUnreachable } from "../utils";
|
|
8
|
+
import { CONN_ACTOR_SYMBOL, type Conn } from "./mod";
|
|
9
|
+
import type { PersistedConn } from "./persisted";
|
|
10
|
+
|
|
11
|
+
/** Pick a subset of persisted data used to represent ephemeral connections */
|
|
12
|
+
export type EphemeralConn<CP, CS> = Pick<
|
|
13
|
+
PersistedConn<CP, CS>,
|
|
14
|
+
"id" | "parameters" | "state"
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export type ConnDataInput<CP, CS> =
|
|
18
|
+
| { ephemeral: EphemeralConn<CP, CS> }
|
|
19
|
+
| { hibernatable: PersistedConn<CP, CS> };
|
|
20
|
+
|
|
21
|
+
export type ConnData<CP, CS> =
|
|
22
|
+
| {
|
|
23
|
+
ephemeral: {
|
|
24
|
+
/** In-memory data representing this connection */
|
|
25
|
+
data: EphemeralConn<CP, CS>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
hibernatable: {
|
|
30
|
+
/** Persisted data with on-change proxy */
|
|
31
|
+
data: PersistedConn<CP, CS>;
|
|
32
|
+
/** Raw persisted data without proxy */
|
|
33
|
+
dataRaw: PersistedConn<CP, CS>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Manages connection state persistence, proxying, and change tracking.
|
|
39
|
+
* Handles automatic state change detection for connection-specific state.
|
|
40
|
+
*/
|
|
41
|
+
export class StateManager<CP, CS> {
|
|
42
|
+
#conn: Conn<any, CP, CS, any, any, any, any, any>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Data representing this connection.
|
|
46
|
+
*
|
|
47
|
+
* This is stored as a struct for both ephemeral and hibernatable conns in
|
|
48
|
+
* order to keep the separation clear between the two.
|
|
49
|
+
*/
|
|
50
|
+
#data!: ConnData<CP, CS>;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
conn: Conn<any, CP, CS, any, any, any, any, any>,
|
|
54
|
+
data: ConnDataInput<CP, CS>,
|
|
55
|
+
) {
|
|
56
|
+
this.#conn = conn;
|
|
57
|
+
|
|
58
|
+
if ("ephemeral" in data) {
|
|
59
|
+
this.#data = { ephemeral: { data: data.ephemeral } };
|
|
60
|
+
} else if ("hibernatable" in data) {
|
|
61
|
+
// Listen for changes to the object
|
|
62
|
+
const persistRaw = data.hibernatable;
|
|
63
|
+
const persist = onChange(
|
|
64
|
+
persistRaw,
|
|
65
|
+
(
|
|
66
|
+
path: string,
|
|
67
|
+
value: any,
|
|
68
|
+
_previousValue: any,
|
|
69
|
+
_applyData: any,
|
|
70
|
+
) => {
|
|
71
|
+
this.#handleChange(path, value);
|
|
72
|
+
},
|
|
73
|
+
{ ignoreDetached: true },
|
|
74
|
+
);
|
|
75
|
+
this.#data = {
|
|
76
|
+
hibernatable: { data: persist, dataRaw: persistRaw },
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
assertUnreachable(data);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the ephemeral or persisted data for this connectioned.
|
|
85
|
+
*
|
|
86
|
+
* This property is used to be able to treat both memory & persist conns
|
|
87
|
+
* identical by looking up the correct underlying data structure.
|
|
88
|
+
*/
|
|
89
|
+
get ephemeralData(): EphemeralConn<CP, CS> {
|
|
90
|
+
if ("hibernatable" in this.#data) {
|
|
91
|
+
return this.#data.hibernatable.data;
|
|
92
|
+
} else if ("ephemeral" in this.#data) {
|
|
93
|
+
return this.#data.ephemeral.data;
|
|
94
|
+
} else {
|
|
95
|
+
return assertUnreachable(this.#data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get hibernatableData(): PersistedConn<CP, CS> | undefined {
|
|
100
|
+
if ("hibernatable" in this.#data) {
|
|
101
|
+
return this.#data.hibernatable.data;
|
|
102
|
+
} else {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
hibernatableDataOrError(): PersistedConn<CP, CS> {
|
|
108
|
+
const hibernatable = this.hibernatableData;
|
|
109
|
+
invariant(hibernatable, "missing hibernatable data");
|
|
110
|
+
return hibernatable;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get hibernatableDataRaw(): PersistedConn<CP, CS> | undefined {
|
|
114
|
+
if ("hibernatable" in this.#data) {
|
|
115
|
+
return this.#data.hibernatable.dataRaw;
|
|
116
|
+
} else {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get stateEnabled(): boolean {
|
|
122
|
+
return this.#conn[CONN_ACTOR_SYMBOL].connStateEnabled;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get state(): CS {
|
|
126
|
+
this.#validateStateEnabled();
|
|
127
|
+
const state = this.ephemeralData.state;
|
|
128
|
+
if (!state) throw new Error("state should exists");
|
|
129
|
+
return state;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
set state(value: CS) {
|
|
133
|
+
this.#validateStateEnabled();
|
|
134
|
+
this.ephemeralData.state = value;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
#validateStateEnabled() {
|
|
138
|
+
if (!this.#conn[CONN_ACTOR_SYMBOL].connStateEnabled) {
|
|
139
|
+
throw new errors.ConnStateNotEnabled();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#handleChange(path: string, value: any) {
|
|
144
|
+
// NOTE: This will only be called for hibernatable conns since only
|
|
145
|
+
// hibernatable conns have the on-change proxy
|
|
146
|
+
|
|
147
|
+
// Validate CBOR serializability for state changes
|
|
148
|
+
if (path.startsWith("state")) {
|
|
149
|
+
let invalidPath = "";
|
|
150
|
+
if (
|
|
151
|
+
!isCborSerializable(
|
|
152
|
+
value,
|
|
153
|
+
(invalidPathPart: string) => {
|
|
154
|
+
invalidPath = invalidPathPart;
|
|
155
|
+
},
|
|
156
|
+
"",
|
|
157
|
+
)
|
|
158
|
+
) {
|
|
159
|
+
throw new errors.InvalidStateType({
|
|
160
|
+
path: path + (invalidPath ? `.${invalidPath}` : ""),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this.#conn[CONN_ACTOR_SYMBOL].rLog.debug({
|
|
166
|
+
msg: "conn onChange triggered",
|
|
167
|
+
connId: this.#conn.id,
|
|
168
|
+
path,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Notify actor that this connection has changed
|
|
172
|
+
this.#conn[
|
|
173
|
+
CONN_ACTOR_SYMBOL
|
|
174
|
+
].connectionManager.markConnWithPersistChanged(this.#conn);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
addSubscription({ eventName }: { eventName: string }) {
|
|
178
|
+
const hibernatable = this.hibernatableData;
|
|
179
|
+
if (!hibernatable) return;
|
|
180
|
+
hibernatable.subscriptions.push({
|
|
181
|
+
eventName,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
removeSubscription({ eventName }: { eventName: string }) {
|
|
186
|
+
const hibernatable = this.hibernatableData;
|
|
187
|
+
if (!hibernatable) return;
|
|
188
|
+
const subIdx = hibernatable.subscriptions.findIndex(
|
|
189
|
+
(s) => s.eventName === eventName,
|
|
190
|
+
);
|
|
191
|
+
if (subIdx !== -1) {
|
|
192
|
+
hibernatable.subscriptions.splice(subIdx, 1);
|
|
193
|
+
}
|
|
194
|
+
return subIdx !== -1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Conn } from "../conn/mod";
|
|
2
|
+
import type { AnyDatabaseProvider } from "../database";
|
|
3
|
+
import type { ActorDefinition, AnyActorDefinition } from "../definition";
|
|
4
|
+
import type { ActorInstance } from "../instance/mod";
|
|
5
|
+
import type { EventSchemaConfig, QueueSchemaConfig } from "../schema";
|
|
6
|
+
import { ConnContext } from "./base/conn";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Context for a remote procedure call.
|
|
10
|
+
*/
|
|
11
|
+
export class ActionContext<
|
|
12
|
+
TState,
|
|
13
|
+
TConnParams,
|
|
14
|
+
TConnState,
|
|
15
|
+
TVars,
|
|
16
|
+
TInput,
|
|
17
|
+
TDatabase extends AnyDatabaseProvider,
|
|
18
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
19
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
20
|
+
> extends ConnContext<
|
|
21
|
+
TState,
|
|
22
|
+
TConnParams,
|
|
23
|
+
TConnState,
|
|
24
|
+
TVars,
|
|
25
|
+
TInput,
|
|
26
|
+
TDatabase,
|
|
27
|
+
TEvents,
|
|
28
|
+
TQueues
|
|
29
|
+
> {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extracts the ActionContext type from an ActorDefinition.
|
|
33
|
+
*/
|
|
34
|
+
export type ActionContextOf<AD extends AnyActorDefinition> =
|
|
35
|
+
AD extends ActorDefinition<
|
|
36
|
+
infer S,
|
|
37
|
+
infer CP,
|
|
38
|
+
infer CS,
|
|
39
|
+
infer V,
|
|
40
|
+
infer I,
|
|
41
|
+
infer DB extends AnyDatabaseProvider,
|
|
42
|
+
infer E extends EventSchemaConfig,
|
|
43
|
+
infer Q extends QueueSchemaConfig,
|
|
44
|
+
any
|
|
45
|
+
>
|
|
46
|
+
? ActionContext<S, CP, CS, V, I, DB, E, Q>
|
|
47
|
+
: never;
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import type { ActorKey } from "@/actor/mod";
|
|
2
|
+
import type { Client } from "@/client/client";
|
|
3
|
+
import type { Logger } from "@/common/log";
|
|
4
|
+
import type { Registry } from "@/registry";
|
|
5
|
+
import type { Conn, ConnId } from "../../conn/mod";
|
|
6
|
+
import type { AnyDatabaseProvider, InferDatabaseClient } from "../../database";
|
|
7
|
+
import type { ActorDefinition, AnyActorDefinition } from "../../definition";
|
|
8
|
+
import * as errors from "../../errors";
|
|
9
|
+
import { ActorKv } from "../../instance/kv";
|
|
10
|
+
import type {
|
|
11
|
+
ActorInstance,
|
|
12
|
+
AnyActorInstance,
|
|
13
|
+
SaveStateOptions,
|
|
14
|
+
} from "../../instance/mod";
|
|
15
|
+
import { ActorQueue } from "../../instance/queue";
|
|
16
|
+
import type { Schedule } from "../../schedule";
|
|
17
|
+
import {
|
|
18
|
+
type EventSchemaConfig,
|
|
19
|
+
type InferEventArgs,
|
|
20
|
+
type InferSchemaMap,
|
|
21
|
+
type QueueSchemaConfig,
|
|
22
|
+
hasSchemaConfigKey,
|
|
23
|
+
validateSchemaSync,
|
|
24
|
+
} from "../../schema";
|
|
25
|
+
|
|
26
|
+
export const ACTOR_CONTEXT_INTERNAL_SYMBOL = Symbol.for(
|
|
27
|
+
"rivetkit.actorContextInternal",
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ActorContext class that provides access to actor methods and state
|
|
32
|
+
*/
|
|
33
|
+
export class ActorContext<
|
|
34
|
+
TState,
|
|
35
|
+
TConnParams,
|
|
36
|
+
TConnState,
|
|
37
|
+
TVars,
|
|
38
|
+
TInput,
|
|
39
|
+
TDatabase extends AnyDatabaseProvider,
|
|
40
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
41
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
42
|
+
> {
|
|
43
|
+
[ACTOR_CONTEXT_INTERNAL_SYMBOL]!: AnyActorInstance;
|
|
44
|
+
#actor: ActorInstance<
|
|
45
|
+
TState,
|
|
46
|
+
TConnParams,
|
|
47
|
+
TConnState,
|
|
48
|
+
TVars,
|
|
49
|
+
TInput,
|
|
50
|
+
TDatabase,
|
|
51
|
+
TEvents,
|
|
52
|
+
TQueues
|
|
53
|
+
>;
|
|
54
|
+
#kv: ActorKv | undefined;
|
|
55
|
+
#queue:
|
|
56
|
+
| ActorQueue<
|
|
57
|
+
TState,
|
|
58
|
+
TConnParams,
|
|
59
|
+
TConnState,
|
|
60
|
+
TVars,
|
|
61
|
+
TInput,
|
|
62
|
+
TDatabase,
|
|
63
|
+
TEvents,
|
|
64
|
+
TQueues
|
|
65
|
+
>
|
|
66
|
+
| undefined;
|
|
67
|
+
|
|
68
|
+
constructor(
|
|
69
|
+
actor: ActorInstance<
|
|
70
|
+
TState,
|
|
71
|
+
TConnParams,
|
|
72
|
+
TConnState,
|
|
73
|
+
TVars,
|
|
74
|
+
TInput,
|
|
75
|
+
TDatabase,
|
|
76
|
+
TEvents,
|
|
77
|
+
TQueues
|
|
78
|
+
>,
|
|
79
|
+
) {
|
|
80
|
+
this.#actor = actor;
|
|
81
|
+
this[ACTOR_CONTEXT_INTERNAL_SYMBOL] = actor as AnyActorInstance;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Gets the KV storage interface.
|
|
86
|
+
*/
|
|
87
|
+
get kv(): ActorKv {
|
|
88
|
+
if (!this.#kv) {
|
|
89
|
+
this.#kv = new ActorKv(this.#actor.driver, this.#actor.id);
|
|
90
|
+
}
|
|
91
|
+
return this.#kv;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the actor state
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* This property is not available in `createState` since the state hasn't been created yet.
|
|
99
|
+
*/
|
|
100
|
+
get state(): TState extends never ? never : TState {
|
|
101
|
+
return this.#actor.state as TState extends never ? never : TState;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get the actor variables
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* This property is not available in `createVars` since the variables haven't been created yet.
|
|
109
|
+
* Variables are only available if you define `vars` or `createVars` in your actor config.
|
|
110
|
+
*/
|
|
111
|
+
get vars(): TVars extends never ? never : TVars {
|
|
112
|
+
return this.#actor.vars as TVars extends never ? never : TVars;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Broadcasts an event to all connected clients.
|
|
117
|
+
* @param name - The name of the event.
|
|
118
|
+
* @param args - The arguments to send with the event.
|
|
119
|
+
*/
|
|
120
|
+
broadcast<K extends keyof TEvents & string>(
|
|
121
|
+
name: K,
|
|
122
|
+
...args: InferEventArgs<InferSchemaMap<TEvents>[K]>
|
|
123
|
+
): void;
|
|
124
|
+
broadcast(
|
|
125
|
+
name: keyof TEvents extends never ? string : never,
|
|
126
|
+
...args: Array<unknown>
|
|
127
|
+
): void;
|
|
128
|
+
broadcast(name: string, ...args: Array<unknown>): void {
|
|
129
|
+
if (
|
|
130
|
+
this.#actor.config.events !== undefined &&
|
|
131
|
+
!hasSchemaConfigKey(this.#actor.config.events, name)
|
|
132
|
+
) {
|
|
133
|
+
this.#actor.rLog.warn({
|
|
134
|
+
msg: "broadcasting event not defined in actor events config",
|
|
135
|
+
eventName: name,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const payload = args.length === 1 ? args[0] : args;
|
|
140
|
+
const result = validateSchemaSync(
|
|
141
|
+
this.#actor.config.events,
|
|
142
|
+
name as keyof TEvents & string,
|
|
143
|
+
payload,
|
|
144
|
+
);
|
|
145
|
+
if (!result.success) {
|
|
146
|
+
throw new errors.EventPayloadInvalid(name, result.issues);
|
|
147
|
+
}
|
|
148
|
+
if (args.length === 1) {
|
|
149
|
+
this.#actor.eventManager.broadcast(name, result.data);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (Array.isArray(result.data)) {
|
|
153
|
+
this.#actor.eventManager.broadcast(
|
|
154
|
+
name,
|
|
155
|
+
...(result.data as unknown[]),
|
|
156
|
+
);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.#actor.eventManager.broadcast(name, ...args);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Gets the logger instance.
|
|
164
|
+
*/
|
|
165
|
+
get log(): Logger {
|
|
166
|
+
return this.#actor.log;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Access to queue receive helpers.
|
|
171
|
+
*/
|
|
172
|
+
get queue(): ActorQueue<
|
|
173
|
+
TState,
|
|
174
|
+
TConnParams,
|
|
175
|
+
TConnState,
|
|
176
|
+
TVars,
|
|
177
|
+
TInput,
|
|
178
|
+
TDatabase,
|
|
179
|
+
TEvents,
|
|
180
|
+
TQueues
|
|
181
|
+
> {
|
|
182
|
+
if (!this.#queue) {
|
|
183
|
+
this.#queue = new ActorQueue(
|
|
184
|
+
this.#actor.queueManager,
|
|
185
|
+
this.#actor.abortSignal,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return this.#queue;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Gets actor ID.
|
|
193
|
+
*/
|
|
194
|
+
get actorId(): string {
|
|
195
|
+
return this.#actor.id;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets the actor name.
|
|
200
|
+
*/
|
|
201
|
+
get name(): string {
|
|
202
|
+
return this.#actor.name;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Gets the actor key.
|
|
207
|
+
*/
|
|
208
|
+
get key(): ActorKey {
|
|
209
|
+
return this.#actor.key;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Gets the region.
|
|
214
|
+
*/
|
|
215
|
+
get region(): string {
|
|
216
|
+
return this.#actor.region;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Gets the scheduler.
|
|
221
|
+
*/
|
|
222
|
+
get schedule(): Schedule {
|
|
223
|
+
return this.#actor.schedule;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Gets the map of connections.
|
|
228
|
+
*/
|
|
229
|
+
get conns(): Map<
|
|
230
|
+
ConnId,
|
|
231
|
+
Conn<
|
|
232
|
+
TState,
|
|
233
|
+
TConnParams,
|
|
234
|
+
TConnState,
|
|
235
|
+
TVars,
|
|
236
|
+
TInput,
|
|
237
|
+
TDatabase,
|
|
238
|
+
TEvents,
|
|
239
|
+
TQueues
|
|
240
|
+
>
|
|
241
|
+
> {
|
|
242
|
+
return this.#actor.conns;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Returns the client for the given registry.
|
|
247
|
+
*/
|
|
248
|
+
client<R extends Registry<any>>(): Client<R> {
|
|
249
|
+
return this.#actor.inlineClient as Client<R>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Gets the database.
|
|
254
|
+
*
|
|
255
|
+
* @experimental
|
|
256
|
+
* @remarks
|
|
257
|
+
* This property is only available if you define a `db` provider in your actor config.
|
|
258
|
+
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
259
|
+
*/
|
|
260
|
+
get db(): TDatabase extends never ? never : InferDatabaseClient<TDatabase> {
|
|
261
|
+
return this.#actor.db as TDatabase extends never
|
|
262
|
+
? never
|
|
263
|
+
: InferDatabaseClient<TDatabase>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Forces the state to get saved.
|
|
268
|
+
*
|
|
269
|
+
* @param opts - Options for saving the state.
|
|
270
|
+
*/
|
|
271
|
+
async saveState(opts: SaveStateOptions): Promise<void> {
|
|
272
|
+
return this.#actor.stateManager.saveState(opts);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Prevents the actor from sleeping until promise is complete.
|
|
277
|
+
*/
|
|
278
|
+
waitUntil(promise: Promise<void>): void {
|
|
279
|
+
this.#actor.waitUntil(promise);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Prevents the actor from sleeping while the given promise is running.
|
|
284
|
+
*
|
|
285
|
+
* Use this when performing async operations in the `run` handler or other
|
|
286
|
+
* background contexts where you need to ensure the actor stays awake.
|
|
287
|
+
*
|
|
288
|
+
* Returns the resolved value and resets the sleep timer on completion.
|
|
289
|
+
* Errors are propagated to the caller.
|
|
290
|
+
*/
|
|
291
|
+
keepAwake<T>(promise: Promise<T>): Promise<T> {
|
|
292
|
+
return this.#actor.keepAwake(promise);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* AbortSignal that fires when the actor is stopping.
|
|
297
|
+
*/
|
|
298
|
+
get abortSignal(): AbortSignal {
|
|
299
|
+
return this.#actor.abortSignal;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* True when the actor is stopping.
|
|
304
|
+
*
|
|
305
|
+
* Alias for `c.abortSignal.aborted`.
|
|
306
|
+
*/
|
|
307
|
+
get aborted(): boolean {
|
|
308
|
+
return this.#actor.abortSignal.aborted;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Forces the actor to sleep.
|
|
313
|
+
*
|
|
314
|
+
* Not supported on all drivers.
|
|
315
|
+
*
|
|
316
|
+
* @experimental
|
|
317
|
+
*/
|
|
318
|
+
sleep() {
|
|
319
|
+
this.#actor.startSleep();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Forces the actor to destroy.
|
|
324
|
+
*
|
|
325
|
+
* This will return immediately, then call `onStop` and `onDestroy`.
|
|
326
|
+
*
|
|
327
|
+
* @experimental
|
|
328
|
+
*/
|
|
329
|
+
destroy() {
|
|
330
|
+
this.#actor.startDestroy();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export type ActorContextOf<AD extends AnyActorDefinition> =
|
|
335
|
+
AD extends ActorDefinition<
|
|
336
|
+
infer S,
|
|
337
|
+
infer CP,
|
|
338
|
+
infer CS,
|
|
339
|
+
infer V,
|
|
340
|
+
infer I,
|
|
341
|
+
infer DB extends AnyDatabaseProvider,
|
|
342
|
+
infer E extends EventSchemaConfig,
|
|
343
|
+
infer Q extends QueueSchemaConfig,
|
|
344
|
+
any
|
|
345
|
+
>
|
|
346
|
+
? ActorContext<S, CP, CS, V, I, DB, E, Q>
|
|
347
|
+
: never;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AnyDatabaseProvider } from "../../database";
|
|
2
|
+
import type { ActorDefinition, AnyActorDefinition } from "../../definition";
|
|
3
|
+
import type { ActorInstance } from "../../instance/mod";
|
|
4
|
+
import type { EventSchemaConfig, QueueSchemaConfig } from "../../schema";
|
|
5
|
+
import { ActorContext } from "./actor";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base context for connection initialization handlers.
|
|
9
|
+
* Extends ActorContext with request-specific functionality for connection lifecycle events.
|
|
10
|
+
*/
|
|
11
|
+
export abstract class ConnInitContext<
|
|
12
|
+
TState,
|
|
13
|
+
TVars,
|
|
14
|
+
TInput,
|
|
15
|
+
TDatabase extends AnyDatabaseProvider,
|
|
16
|
+
TEvents extends EventSchemaConfig = Record<never, never>,
|
|
17
|
+
TQueues extends QueueSchemaConfig = Record<never, never>,
|
|
18
|
+
> extends ActorContext<
|
|
19
|
+
TState,
|
|
20
|
+
never,
|
|
21
|
+
never,
|
|
22
|
+
TVars,
|
|
23
|
+
TInput,
|
|
24
|
+
TDatabase,
|
|
25
|
+
TEvents,
|
|
26
|
+
TQueues
|
|
27
|
+
> {
|
|
28
|
+
/**
|
|
29
|
+
* The incoming request that initiated the connection.
|
|
30
|
+
* May be undefined for connections initiated without a direct HTTP request.
|
|
31
|
+
*/
|
|
32
|
+
public readonly request: Request | undefined;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
constructor(
|
|
38
|
+
actor: ActorInstance<
|
|
39
|
+
TState,
|
|
40
|
+
any,
|
|
41
|
+
any,
|
|
42
|
+
TVars,
|
|
43
|
+
TInput,
|
|
44
|
+
TDatabase,
|
|
45
|
+
TEvents,
|
|
46
|
+
TQueues
|
|
47
|
+
>,
|
|
48
|
+
request: Request | undefined,
|
|
49
|
+
) {
|
|
50
|
+
super(actor as any);
|
|
51
|
+
this.request = request;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type ConnInitContextOf<AD extends AnyActorDefinition> =
|
|
56
|
+
AD extends ActorDefinition<
|
|
57
|
+
infer S,
|
|
58
|
+
any,
|
|
59
|
+
any,
|
|
60
|
+
infer V,
|
|
61
|
+
infer I,
|
|
62
|
+
infer DB extends AnyDatabaseProvider,
|
|
63
|
+
infer E extends EventSchemaConfig,
|
|
64
|
+
infer Q extends QueueSchemaConfig,
|
|
65
|
+
any
|
|
66
|
+
>
|
|
67
|
+
? ConnInitContext<S, V, I, DB, E, Q>
|
|
68
|
+
: never;
|