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,118 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
WORKFLOW_QUEUE_NAME,
|
|
4
|
+
} from "../../../fixtures/driver-test-suite/workflow";
|
|
5
|
+
import type { DriverTestConfig } from "../mod";
|
|
6
|
+
import { setupDriverTest, waitFor } from "../utils";
|
|
7
|
+
|
|
8
|
+
export function runActorWorkflowTests(driverTestConfig: DriverTestConfig) {
|
|
9
|
+
describe("Actor Workflow Tests", () => {
|
|
10
|
+
test("replays steps and guards state access", async (c) => {
|
|
11
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
12
|
+
const actor = client.workflowCounterActor.getOrCreate([
|
|
13
|
+
"workflow-basic",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
let state = await actor.getState();
|
|
17
|
+
for (let i = 0; i < 50; i++) {
|
|
18
|
+
if (
|
|
19
|
+
state.runCount > 0 &&
|
|
20
|
+
state.history.length > 0 &&
|
|
21
|
+
state.guardTriggered
|
|
22
|
+
) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
await waitFor(driverTestConfig, 100);
|
|
26
|
+
state = await actor.getState();
|
|
27
|
+
}
|
|
28
|
+
expect(state.runCount).toBeGreaterThan(0);
|
|
29
|
+
expect(state.history.length).toBeGreaterThan(0);
|
|
30
|
+
expect(state.guardTriggered).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("consumes queue messages via workflow queue.next", async (c) => {
|
|
34
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
35
|
+
const actor = client.workflowQueueActor.getOrCreate(["workflow-queue"]);
|
|
36
|
+
|
|
37
|
+
await actor.send(WORKFLOW_QUEUE_NAME, {
|
|
38
|
+
hello: "world",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
await waitFor(driverTestConfig, 200);
|
|
42
|
+
const messages = await actor.getMessages();
|
|
43
|
+
expect(messages).toEqual([{ hello: "world" }]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("workflow queue.next supports completing wait sends", async (c) => {
|
|
47
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
48
|
+
const actor = client.workflowQueueActor.getOrCreate([
|
|
49
|
+
"workflow-queue-wait",
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const result = await actor.sendAndWait({ value: 123 });
|
|
53
|
+
expect(result).toEqual({
|
|
54
|
+
status: "completed",
|
|
55
|
+
response: { echo: { value: 123 } },
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("db and client are step-only in workflow context", async (c) => {
|
|
60
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
61
|
+
const actor = client.workflowAccessActor.getOrCreate([
|
|
62
|
+
"workflow-access",
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
let state = await actor.getState();
|
|
66
|
+
for (let i = 0; i < 20 && state.insideDbCount === 0; i++) {
|
|
67
|
+
await waitFor(driverTestConfig, 50);
|
|
68
|
+
state = await actor.getState();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expect(state.outsideDbError).toBe(
|
|
72
|
+
"db is only available inside workflow steps",
|
|
73
|
+
);
|
|
74
|
+
expect(state.outsideClientError).toBe(
|
|
75
|
+
"client is only available inside workflow steps",
|
|
76
|
+
);
|
|
77
|
+
expect(state.insideDbCount).toBeGreaterThan(0);
|
|
78
|
+
expect(state.insideClientAvailable).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("sleeps and resumes between ticks", async (c) => {
|
|
82
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
83
|
+
const actor = client.workflowSleepActor.getOrCreate(["workflow-sleep"]);
|
|
84
|
+
|
|
85
|
+
const initial = await actor.getState();
|
|
86
|
+
await waitFor(driverTestConfig, 200);
|
|
87
|
+
const next = await actor.getState();
|
|
88
|
+
|
|
89
|
+
expect(next.ticks).toBeGreaterThan(initial.ticks);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test.skipIf(driverTestConfig.skip?.sleep)(
|
|
93
|
+
"workflow run teardown does not wait for runStopTimeout",
|
|
94
|
+
async (c) => {
|
|
95
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
96
|
+
const actor = client.workflowStopTeardownActor.getOrCreate([
|
|
97
|
+
"workflow-stop-teardown",
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
await actor.getTimeline();
|
|
101
|
+
await waitFor(driverTestConfig, 1_200);
|
|
102
|
+
const timeline = await actor.getTimeline();
|
|
103
|
+
|
|
104
|
+
expect(timeline.wakeAts.length).toBeGreaterThanOrEqual(2);
|
|
105
|
+
expect(timeline.sleepAts.length).toBeGreaterThanOrEqual(1);
|
|
106
|
+
|
|
107
|
+
const firstSleepDelayMs =
|
|
108
|
+
timeline.sleepAts[0] - timeline.wakeAts[0];
|
|
109
|
+
expect(firstSleepDelayMs).toBeLessThan(1_800);
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// NOTE: Test for workflow persistence across actor sleep is complex because
|
|
114
|
+
// calling c.sleep() during a workflow prevents clean shutdown. The workflow
|
|
115
|
+
// persistence is implicitly tested by the "sleeps and resumes between ticks"
|
|
116
|
+
// test which verifies the workflow continues from persisted state.
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import type { ActorError } from "@/client/mod";
|
|
3
|
+
import type { DriverTestConfig } from "../mod";
|
|
4
|
+
import { setupDriverTest } from "../utils";
|
|
5
|
+
|
|
6
|
+
export function runManagerDriverTests(driverTestConfig: DriverTestConfig) {
|
|
7
|
+
describe("Manager Driver Tests", () => {
|
|
8
|
+
describe("Client Connection Methods", () => {
|
|
9
|
+
test("connect() - finds or creates a actor", async (c) => {
|
|
10
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
11
|
+
|
|
12
|
+
// Basic connect() with no parameters creates a default actor
|
|
13
|
+
const counterA = client.counter.getOrCreate();
|
|
14
|
+
await counterA.increment(5);
|
|
15
|
+
|
|
16
|
+
// Get the same actor again to verify state persisted
|
|
17
|
+
const counterAAgain = client.counter.getOrCreate();
|
|
18
|
+
const count = await counterAAgain.increment(0);
|
|
19
|
+
expect(count).toBe(5);
|
|
20
|
+
|
|
21
|
+
// Connect with key creates a new actor with specific parameters
|
|
22
|
+
const counterB = client.counter.getOrCreate([
|
|
23
|
+
"counter-b",
|
|
24
|
+
"testing",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
await counterB.increment(10);
|
|
28
|
+
const countB = await counterB.increment(0);
|
|
29
|
+
expect(countB).toBe(10);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("throws ActorAlreadyExists when creating duplicate actors", async (c) => {
|
|
33
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
34
|
+
|
|
35
|
+
// Create a unique actor with specific key
|
|
36
|
+
const uniqueKey = ["duplicate-actor-test", crypto.randomUUID()];
|
|
37
|
+
const counter = client.counter.getOrCreate(uniqueKey);
|
|
38
|
+
await counter.increment(5);
|
|
39
|
+
|
|
40
|
+
// Expect duplicate actor
|
|
41
|
+
try {
|
|
42
|
+
await client.counter.create(uniqueKey);
|
|
43
|
+
expect.fail("did not error on duplicate create");
|
|
44
|
+
} catch (err) {
|
|
45
|
+
expect((err as ActorError).group).toBe("actor");
|
|
46
|
+
expect((err as ActorError).code).toBe("duplicate_key");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Verify the original actor still works and has its state
|
|
50
|
+
const count = await counter.increment(0);
|
|
51
|
+
expect(count).toBe(5);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("Connection Options", () => {
|
|
56
|
+
test("get without create prevents actor creation", async (c) => {
|
|
57
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
58
|
+
|
|
59
|
+
// Try to get a nonexistent actor with no create
|
|
60
|
+
const nonexistentId = `nonexistent-${crypto.randomUUID()}`;
|
|
61
|
+
|
|
62
|
+
// Should fail when actor doesn't exist
|
|
63
|
+
try {
|
|
64
|
+
await client.counter.get([nonexistentId]).resolve();
|
|
65
|
+
expect.fail("did not error for get");
|
|
66
|
+
} catch (err) {
|
|
67
|
+
expect((err as ActorError).group).toBe("actor");
|
|
68
|
+
expect((err as ActorError).code).toBe("not_found");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Create the actor
|
|
72
|
+
const createdCounter =
|
|
73
|
+
client.counter.getOrCreate(nonexistentId);
|
|
74
|
+
await createdCounter.increment(3);
|
|
75
|
+
|
|
76
|
+
// Now no create should work since the actor exists
|
|
77
|
+
const retrievedCounter = client.counter.get(nonexistentId);
|
|
78
|
+
|
|
79
|
+
const count = await retrievedCounter.increment(0);
|
|
80
|
+
expect(count).toBe(3);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("connection params are passed to actors", async (c) => {
|
|
84
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
85
|
+
|
|
86
|
+
// Create a actor with connection params
|
|
87
|
+
// Note: In a real test we'd verify these are received by the actor,
|
|
88
|
+
// but our simple counter actor doesn't use connection params.
|
|
89
|
+
// This test just ensures the params are accepted by the driver.
|
|
90
|
+
const counter = client.counter.getOrCreate(undefined, {
|
|
91
|
+
params: {
|
|
92
|
+
userId: "user-123",
|
|
93
|
+
authToken: "token-abc",
|
|
94
|
+
settings: { increment: 5 },
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await counter.increment(1);
|
|
99
|
+
const count = await counter.increment(0);
|
|
100
|
+
expect(count).toBe(1);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("Actor Creation & Retrieval", () => {
|
|
105
|
+
test("creates and retrieves actors by ID", async (c) => {
|
|
106
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
107
|
+
|
|
108
|
+
// Create a unique ID for this test
|
|
109
|
+
const uniqueId = `test-counter-${crypto.randomUUID()}`;
|
|
110
|
+
|
|
111
|
+
// Create actor with specific ID
|
|
112
|
+
const counter = client.counter.getOrCreate([uniqueId]);
|
|
113
|
+
await counter.increment(10);
|
|
114
|
+
|
|
115
|
+
// Retrieve the same actor by ID and verify state
|
|
116
|
+
const retrievedCounter = client.counter.getOrCreate([uniqueId]);
|
|
117
|
+
const count = await retrievedCounter.increment(0); // Get current value
|
|
118
|
+
expect(count).toBe(10);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("passes input to actor during creation", async (c) => {
|
|
122
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
123
|
+
|
|
124
|
+
// Test data to pass as input
|
|
125
|
+
const testInput = {
|
|
126
|
+
name: "test-actor",
|
|
127
|
+
value: 42,
|
|
128
|
+
nested: { foo: "bar" },
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Create actor with input
|
|
132
|
+
const actor = await client.inputActor.create(undefined, {
|
|
133
|
+
input: testInput,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Verify both createState and onCreate received the input
|
|
137
|
+
const inputs = await actor.getInputs();
|
|
138
|
+
|
|
139
|
+
// Input should be available in createState
|
|
140
|
+
expect(inputs.initialInput).toEqual(testInput);
|
|
141
|
+
|
|
142
|
+
// Input should also be available in onCreate lifecycle hook
|
|
143
|
+
expect(inputs.onCreateInput).toEqual(testInput);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("input is undefined when not provided", async (c) => {
|
|
147
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
148
|
+
|
|
149
|
+
// Create actor without providing input
|
|
150
|
+
const actor = await client.inputActor.create();
|
|
151
|
+
|
|
152
|
+
// Get inputs and verify they're undefined
|
|
153
|
+
const inputs = await actor.getInputs();
|
|
154
|
+
|
|
155
|
+
// Should be undefined in createState
|
|
156
|
+
expect(inputs.initialInput).toBeUndefined();
|
|
157
|
+
|
|
158
|
+
// Should be undefined in onCreate lifecycle hook too
|
|
159
|
+
expect(inputs.onCreateInput).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("getOrCreate passes input to actor during creation", async (c) => {
|
|
163
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
164
|
+
|
|
165
|
+
// Create a unique key for this test
|
|
166
|
+
const uniqueKey = [`input-test-${crypto.randomUUID()}`];
|
|
167
|
+
|
|
168
|
+
// Test data to pass as input
|
|
169
|
+
const testInput = {
|
|
170
|
+
name: "getorcreate-test",
|
|
171
|
+
value: 100,
|
|
172
|
+
nested: { baz: "qux" },
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// Use getOrCreate with input
|
|
176
|
+
const actor = client.inputActor.getOrCreate(uniqueKey, {
|
|
177
|
+
createWithInput: testInput,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Verify both createState and onCreate received the input
|
|
181
|
+
const inputs = await actor.getInputs();
|
|
182
|
+
|
|
183
|
+
// Input should be available in createState
|
|
184
|
+
expect(inputs.initialInput).toEqual(testInput);
|
|
185
|
+
|
|
186
|
+
// Input should also be available in onCreate lifecycle hook
|
|
187
|
+
expect(inputs.onCreateInput).toEqual(testInput);
|
|
188
|
+
|
|
189
|
+
// Verify that calling getOrCreate again with the same key
|
|
190
|
+
// returns the existing actor and doesn't create a new one
|
|
191
|
+
const existingActor = client.inputActor.getOrCreate(uniqueKey);
|
|
192
|
+
const existingInputs = await existingActor.getInputs();
|
|
193
|
+
|
|
194
|
+
// Should still have the original inputs
|
|
195
|
+
expect(existingInputs.initialInput).toEqual(testInput);
|
|
196
|
+
expect(existingInputs.onCreateInput).toEqual(testInput);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// TODO: Correctly test region for each provider
|
|
200
|
+
//test("creates and retrieves actors with region", async (c) => {
|
|
201
|
+
// const { client } = await setupDriverTest(c,
|
|
202
|
+
// driverTestConfig,
|
|
203
|
+
// COUNTER_APP_PATH
|
|
204
|
+
// );
|
|
205
|
+
//
|
|
206
|
+
// // Create actor with a specific region
|
|
207
|
+
// const counter = client.counter.getOrCreate({
|
|
208
|
+
// create: {
|
|
209
|
+
// key: ["metadata-test", "testing"],
|
|
210
|
+
// region: "test-region",
|
|
211
|
+
// },
|
|
212
|
+
// });
|
|
213
|
+
//
|
|
214
|
+
// // Set state to identify this specific instance
|
|
215
|
+
// await counter.increment(42);
|
|
216
|
+
//
|
|
217
|
+
// // Retrieve by ID (since metadata is not used for retrieval)
|
|
218
|
+
// const retrievedCounter = client.counter.getOrCreate(["metadata-test"]);
|
|
219
|
+
//
|
|
220
|
+
// // Verify it's the same instance
|
|
221
|
+
// const count = await retrievedCounter.increment(0);
|
|
222
|
+
// expect(count).toBe(42);
|
|
223
|
+
//});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("Key Matching", () => {
|
|
227
|
+
test("multi-part actor keys are passed through correctly", async (c) => {
|
|
228
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
229
|
+
|
|
230
|
+
// Create an actor with a multi-part key
|
|
231
|
+
const multiPartKey = ["tenant/with/slash", "room"];
|
|
232
|
+
const counter = client.counter.getOrCreate(multiPartKey);
|
|
233
|
+
|
|
234
|
+
// Should be preserved as a multi-part key (["tenant/with/slash", "room"])
|
|
235
|
+
expect(await counter.getKey()).toEqual(multiPartKey);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("matches actors only with exactly the same keys", async (c) => {
|
|
239
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
240
|
+
|
|
241
|
+
// Create actor with multiple keys
|
|
242
|
+
const originalCounter = client.counter.getOrCreate([
|
|
243
|
+
"counter-match",
|
|
244
|
+
"test",
|
|
245
|
+
"us-east",
|
|
246
|
+
]);
|
|
247
|
+
await originalCounter.increment(10);
|
|
248
|
+
|
|
249
|
+
// Should match with exact same keys
|
|
250
|
+
const exactMatchCounter = client.counter.getOrCreate([
|
|
251
|
+
"counter-match",
|
|
252
|
+
"test",
|
|
253
|
+
"us-east",
|
|
254
|
+
]);
|
|
255
|
+
const exactMatchCount = await exactMatchCounter.increment(0);
|
|
256
|
+
expect(exactMatchCount).toBe(10);
|
|
257
|
+
|
|
258
|
+
// Should NOT match with subset of keys - should create new actor
|
|
259
|
+
const subsetMatchCounter = client.counter.getOrCreate([
|
|
260
|
+
"counter-match",
|
|
261
|
+
"test",
|
|
262
|
+
]);
|
|
263
|
+
const subsetMatchCount = await subsetMatchCounter.increment(0);
|
|
264
|
+
expect(subsetMatchCount).toBe(0); // Should be a new counter with 0
|
|
265
|
+
|
|
266
|
+
// Should NOT match with just one key - should create new actor
|
|
267
|
+
const singleKeyCounter = client.counter.getOrCreate([
|
|
268
|
+
"counter-match",
|
|
269
|
+
]);
|
|
270
|
+
const singleKeyCount = await singleKeyCounter.increment(0);
|
|
271
|
+
expect(singleKeyCount).toBe(0); // Should be a new counter with 0
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("string key matches array with single string key", async (c) => {
|
|
275
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
276
|
+
|
|
277
|
+
// Create actor with string key
|
|
278
|
+
const stringKeyCounter =
|
|
279
|
+
client.counter.getOrCreate("string-key-test");
|
|
280
|
+
await stringKeyCounter.increment(7);
|
|
281
|
+
|
|
282
|
+
// Should match with equivalent array key
|
|
283
|
+
const arrayKeyCounter = client.counter.getOrCreate([
|
|
284
|
+
"string-key-test",
|
|
285
|
+
]);
|
|
286
|
+
const count = await arrayKeyCounter.increment(0);
|
|
287
|
+
expect(count).toBe(7);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test("undefined key matches empty array key and no key", async (c) => {
|
|
291
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
292
|
+
|
|
293
|
+
// Create actor with undefined key
|
|
294
|
+
const undefinedKeyCounter =
|
|
295
|
+
client.counter.getOrCreate(undefined);
|
|
296
|
+
await undefinedKeyCounter.increment(12);
|
|
297
|
+
|
|
298
|
+
// Should match with empty array key
|
|
299
|
+
const emptyArrayKeyCounter = client.counter.getOrCreate([]);
|
|
300
|
+
const emptyArrayCount = await emptyArrayKeyCounter.increment(0);
|
|
301
|
+
expect(emptyArrayCount).toBe(12);
|
|
302
|
+
|
|
303
|
+
// Should match with no key
|
|
304
|
+
const noKeyCounter = client.counter.getOrCreate();
|
|
305
|
+
const noKeyCount = await noKeyCounter.increment(0);
|
|
306
|
+
expect(noKeyCount).toBe(12);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test("no keys does not match actors with keys", async (c) => {
|
|
310
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
311
|
+
|
|
312
|
+
// Create counter with keys
|
|
313
|
+
const keyedCounter = client.counter.getOrCreate([
|
|
314
|
+
"counter-with-keys",
|
|
315
|
+
"special",
|
|
316
|
+
]);
|
|
317
|
+
await keyedCounter.increment(15);
|
|
318
|
+
|
|
319
|
+
// Should not match when searching with no keys
|
|
320
|
+
const noKeysCounter = client.counter.getOrCreate();
|
|
321
|
+
const count = await noKeysCounter.increment(10);
|
|
322
|
+
expect(count).toBe(10);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test("actors with keys match actors with no keys", async (c) => {
|
|
326
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
327
|
+
|
|
328
|
+
// Create a counter with no keys
|
|
329
|
+
const noKeysCounter = client.counter.getOrCreate();
|
|
330
|
+
await noKeysCounter.increment(25);
|
|
331
|
+
|
|
332
|
+
// Get counter with keys - should create a new one
|
|
333
|
+
const keyedCounter = client.counter.getOrCreate([
|
|
334
|
+
"new-counter",
|
|
335
|
+
"prod",
|
|
336
|
+
]);
|
|
337
|
+
const keyedCount = await keyedCounter.increment(0);
|
|
338
|
+
|
|
339
|
+
// Should be a new counter, not the one created above
|
|
340
|
+
expect(keyedCount).toBe(0);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
describe("Multiple Actor Instances", () => {
|
|
345
|
+
// TODO: This test is flakey https://github.com/rivet-dev/rivetkit/issues/873
|
|
346
|
+
test("creates multiple actor instances of the same type", async (c) => {
|
|
347
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
348
|
+
|
|
349
|
+
// Create multiple instances with different IDs
|
|
350
|
+
const instance1 = client.counter.getOrCreate(["multi-1"]);
|
|
351
|
+
const instance2 = client.counter.getOrCreate(["multi-2"]);
|
|
352
|
+
const instance3 = client.counter.getOrCreate(["multi-3"]);
|
|
353
|
+
|
|
354
|
+
// Set different states
|
|
355
|
+
await instance1.increment(1);
|
|
356
|
+
await instance2.increment(2);
|
|
357
|
+
await instance3.increment(3);
|
|
358
|
+
|
|
359
|
+
// Retrieve all instances again
|
|
360
|
+
const retrieved1 = client.counter.getOrCreate(["multi-1"]);
|
|
361
|
+
const retrieved2 = client.counter.getOrCreate(["multi-2"]);
|
|
362
|
+
const retrieved3 = client.counter.getOrCreate(["multi-3"]);
|
|
363
|
+
|
|
364
|
+
// Verify separate state
|
|
365
|
+
expect(await retrieved1.increment(0)).toBe(1);
|
|
366
|
+
expect(await retrieved2.increment(0)).toBe(2);
|
|
367
|
+
expect(await retrieved3.increment(0)).toBe(3);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("handles default instance with no explicit ID", async (c) => {
|
|
371
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
372
|
+
|
|
373
|
+
// Get default instance (no ID specified)
|
|
374
|
+
const defaultCounter = client.counter.getOrCreate();
|
|
375
|
+
|
|
376
|
+
// Set state
|
|
377
|
+
await defaultCounter.increment(5);
|
|
378
|
+
|
|
379
|
+
// Get default instance again
|
|
380
|
+
const sameDefaultCounter = client.counter.getOrCreate();
|
|
381
|
+
|
|
382
|
+
// Verify state is maintained
|
|
383
|
+
const count = await sameDefaultCounter.increment(0);
|
|
384
|
+
expect(count).toBe(5);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
}
|