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,78 @@
|
|
|
1
|
+
// This file consolidates all environment variables that affect RivetKit's behavior.
|
|
2
|
+
//
|
|
3
|
+
// IMPORTANT: When adding or modifying environment variables here, also update the
|
|
4
|
+
// documentation at: website/src/content/docs/general/environment-variables.mdx
|
|
5
|
+
|
|
6
|
+
import { getEnvUniversal } from "@/utils";
|
|
7
|
+
|
|
8
|
+
// Rivet configuration
|
|
9
|
+
export const getRivetEngine = (): string | undefined =>
|
|
10
|
+
getEnvUniversal("RIVET_ENGINE");
|
|
11
|
+
export const getRivetEndpoint = (): string | undefined =>
|
|
12
|
+
getEnvUniversal("RIVET_ENDPOINT");
|
|
13
|
+
export const getRivetToken = (): string | undefined =>
|
|
14
|
+
getEnvUniversal("RIVET_TOKEN");
|
|
15
|
+
export const getRivetNamespace = (): string | undefined =>
|
|
16
|
+
getEnvUniversal("RIVET_NAMESPACE");
|
|
17
|
+
export const getRivetRunner = (): string | undefined =>
|
|
18
|
+
getEnvUniversal("RIVET_RUNNER");
|
|
19
|
+
export const getRivetTotalSlots = (): number | undefined => {
|
|
20
|
+
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
21
|
+
return value !== undefined ? parseInt(value, 10) : undefined;
|
|
22
|
+
};
|
|
23
|
+
export const getRivetRunnerKey = (): string | undefined =>
|
|
24
|
+
getEnvUniversal("RIVET_RUNNER_KEY");
|
|
25
|
+
export const getRivetRunEngine = (): boolean =>
|
|
26
|
+
getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
27
|
+
export const getRivetRunEngineVersion = (): string | undefined =>
|
|
28
|
+
getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
29
|
+
export const getRivetRunnerKind = (): string | undefined =>
|
|
30
|
+
getEnvUniversal("RIVET_RUNNER_KIND");
|
|
31
|
+
export const getRivetRunnerVersion = (): number | undefined => {
|
|
32
|
+
const value = getEnvUniversal("RIVET_RUNNER_VERSION");
|
|
33
|
+
return value !== undefined ? parseInt(value, 10) : undefined;
|
|
34
|
+
};
|
|
35
|
+
export const getRivetPublicEndpoint = (): string | undefined =>
|
|
36
|
+
getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
37
|
+
export const getRivetPublicToken = (): string | undefined =>
|
|
38
|
+
getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
39
|
+
// There is no RIVET_PUBLIC_NAMESPACE because the frontend and backend cannot
|
|
40
|
+
// use different namespaces
|
|
41
|
+
|
|
42
|
+
// RivetKit configuration
|
|
43
|
+
export const getRivetkitInspectorToken = (): string | undefined =>
|
|
44
|
+
getEnvUniversal("RIVET_INSPECTOR_TOKEN");
|
|
45
|
+
export const getRivetkitInspectorDisable = (): boolean =>
|
|
46
|
+
getEnvUniversal("RIVET_INSPECTOR_DISABLE") === "1";
|
|
47
|
+
export const getRivetkitStoragePath = (): string | undefined =>
|
|
48
|
+
getEnvUniversal("RIVETKIT_STORAGE_PATH");
|
|
49
|
+
|
|
50
|
+
// Logging configuration
|
|
51
|
+
// DEPRECATED: LOG_LEVEL will be removed in a future version
|
|
52
|
+
export const getLogLevel = (): string | undefined =>
|
|
53
|
+
getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
54
|
+
export const getLogTarget = (): boolean =>
|
|
55
|
+
getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
56
|
+
export const getLogTimestamp = (): boolean =>
|
|
57
|
+
getEnvUniversal("RIVET_LOG_TIMESTAMP") === "1";
|
|
58
|
+
export const getLogMessage = (): boolean =>
|
|
59
|
+
getEnvUniversal("RIVET_LOG_MESSAGE") === "1";
|
|
60
|
+
export const getLogErrorStack = (): boolean =>
|
|
61
|
+
getEnvUniversal("RIVET_LOG_ERROR_STACK") === "1";
|
|
62
|
+
export const getLogHeaders = (): boolean =>
|
|
63
|
+
getEnvUniversal("RIVET_LOG_HEADERS") === "1";
|
|
64
|
+
|
|
65
|
+
// Environment configuration
|
|
66
|
+
export const getNodeEnv = (): string | undefined => getEnvUniversal("NODE_ENV");
|
|
67
|
+
export const getNextPhase = (): string | undefined =>
|
|
68
|
+
getEnvUniversal("NEXT_PHASE");
|
|
69
|
+
export const isDev = (): boolean => getNodeEnv() !== "production";
|
|
70
|
+
|
|
71
|
+
// Experimental
|
|
72
|
+
/**
|
|
73
|
+
* Enables experimental OTel tracing for Rivet Actors.
|
|
74
|
+
*
|
|
75
|
+
* When disabled, actors use an in-memory no-op traces implementation.
|
|
76
|
+
*/
|
|
77
|
+
export const getRivetExperimentalOtel = (): boolean =>
|
|
78
|
+
getEnvUniversal("RIVET_EXPERIMENTAL_OTEL") === "1";
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
// Global variables for Node.js modules.
|
|
4
|
+
//
|
|
5
|
+
// We use synchronous require() instead of async import() for Node.js module loading because:
|
|
6
|
+
// 1. These modules are only needed in Node.js environments (not browser/edge)
|
|
7
|
+
// 2. registry.start() cannot be async and needs immediate access to Node modules
|
|
8
|
+
// 3. The setup process must be synchronous to avoid breaking the API
|
|
9
|
+
//
|
|
10
|
+
// Biome only allows imports of node modules in this file in order to ensure
|
|
11
|
+
// we're forcing the use of dynamic imports.
|
|
12
|
+
let nodeCrypto: typeof import("node:crypto") | undefined;
|
|
13
|
+
let nodeFsSync: typeof import("node:fs") | undefined;
|
|
14
|
+
let nodeFs: typeof import("node:fs/promises") | undefined;
|
|
15
|
+
let nodePath: typeof import("node:path") | undefined;
|
|
16
|
+
let nodeOs: typeof import("node:os") | undefined;
|
|
17
|
+
let nodeChildProcess: typeof import("node:child_process") | undefined;
|
|
18
|
+
let nodeStream: typeof import("node:stream/promises") | undefined;
|
|
19
|
+
let nodeUrl: typeof import("node:url") | undefined;
|
|
20
|
+
|
|
21
|
+
let hasImportedDependencies = false;
|
|
22
|
+
|
|
23
|
+
// Helper to get a require function that works in both CommonJS and ESM.
|
|
24
|
+
// We use require() instead of await import() because registry.start() cannot
|
|
25
|
+
// be async and needs immediate access to Node.js modules during setup.
|
|
26
|
+
export function getRequireFn() {
|
|
27
|
+
// TODO: This causes issues in tsup
|
|
28
|
+
// CommonJS context - use global require
|
|
29
|
+
// if (typeof require !== "undefined") {
|
|
30
|
+
// console.log("existing require");
|
|
31
|
+
// return require;
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// ESM context - use createRequire with import.meta.url
|
|
35
|
+
return createRequire(import.meta.url);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Dynamically imports all required Node.js dependencies. We do this early in a
|
|
40
|
+
* single function call in order to surface errors early.
|
|
41
|
+
*
|
|
42
|
+
* This function is idempotent and will only import once.
|
|
43
|
+
*
|
|
44
|
+
* @throws Error if Node.js modules are not available (e.g., in browser/edge environments)
|
|
45
|
+
*/
|
|
46
|
+
export function importNodeDependencies(): void {
|
|
47
|
+
// Check if already loaded
|
|
48
|
+
if (hasImportedDependencies) return;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// Get a require function that works in both CommonJS and ESM
|
|
52
|
+
const requireFn = getRequireFn();
|
|
53
|
+
|
|
54
|
+
// Use requireFn with webpack ignore comment to prevent bundling
|
|
55
|
+
nodeCrypto = requireFn(/* webpackIgnore: true */ "node:crypto");
|
|
56
|
+
nodeFsSync = requireFn(/* webpackIgnore: true */ "node:fs");
|
|
57
|
+
nodeFs = requireFn(/* webpackIgnore: true */ "node:fs/promises");
|
|
58
|
+
nodePath = requireFn(/* webpackIgnore: true */ "node:path");
|
|
59
|
+
nodeOs = requireFn(/* webpackIgnore: true */ "node:os");
|
|
60
|
+
nodeChildProcess = requireFn(
|
|
61
|
+
/* webpackIgnore: true */ "node:child_process",
|
|
62
|
+
);
|
|
63
|
+
nodeStream = requireFn(
|
|
64
|
+
/* webpackIgnore: true */ "node:stream/promises",
|
|
65
|
+
);
|
|
66
|
+
nodeUrl = requireFn(/* webpackIgnore: true */ "node:url");
|
|
67
|
+
hasImportedDependencies = true;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.warn(
|
|
70
|
+
"Node.js modules not available, file system driver will not work",
|
|
71
|
+
err,
|
|
72
|
+
);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Gets the Node.js crypto module.
|
|
79
|
+
* @throws Error if crypto module is not loaded
|
|
80
|
+
*/
|
|
81
|
+
export function getNodeCrypto(): typeof import("node:crypto") {
|
|
82
|
+
if (!nodeCrypto) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
"Node crypto module not loaded. Ensure importNodeDependencies() has been called.",
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return nodeCrypto;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets the Node.js fs module.
|
|
92
|
+
* @throws Error if fs module is not loaded
|
|
93
|
+
*/
|
|
94
|
+
export function getNodeFsSync(): typeof import("node:fs") {
|
|
95
|
+
if (!nodeFsSync) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Node fs module not loaded. Ensure importNodeDependencies() has been called.",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return nodeFsSync;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets the Node.js fs/promises module.
|
|
105
|
+
* @throws Error if fs/promises module is not loaded
|
|
106
|
+
*/
|
|
107
|
+
export function getNodeFs(): typeof import("node:fs/promises") {
|
|
108
|
+
if (!nodeFs) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
"Node fs/promises module not loaded. Ensure importNodeDependencies() has been called.",
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
return nodeFs;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Gets the Node.js path module.
|
|
118
|
+
* @throws Error if path module is not loaded
|
|
119
|
+
*/
|
|
120
|
+
export function getNodePath(): typeof import("node:path") {
|
|
121
|
+
if (!nodePath) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Node path module not loaded. Ensure importNodeDependencies() has been called.",
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return nodePath;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets the Node.js os module.
|
|
131
|
+
* @throws Error if os module is not loaded
|
|
132
|
+
*/
|
|
133
|
+
export function getNodeOs(): typeof import("node:os") {
|
|
134
|
+
if (!nodeOs) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
"Node os module not loaded. Ensure importNodeDependencies() has been called.",
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return nodeOs;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Gets the Node.js child_process module.
|
|
144
|
+
* @throws Error if child_process module is not loaded
|
|
145
|
+
*/
|
|
146
|
+
export function getNodeChildProcess(): typeof import("node:child_process") {
|
|
147
|
+
if (!nodeChildProcess) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
"Node child_process module not loaded. Ensure importNodeDependencies() has been called.",
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return nodeChildProcess;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Gets the Node.js stream/promises module.
|
|
157
|
+
* @throws Error if stream/promises module is not loaded
|
|
158
|
+
*/
|
|
159
|
+
export function getNodeStream(): typeof import("node:stream/promises") {
|
|
160
|
+
if (!nodeStream) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
"Node stream/promises module not loaded. Ensure importNodeDependencies() has been called.",
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return nodeStream;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Gets the Node.js url module lazily.
|
|
170
|
+
*/
|
|
171
|
+
export function getNodeUrl(): typeof import("node:url") {
|
|
172
|
+
if (!nodeUrl) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
"Node url module not loaded. Ensure importNodeDependencies() has been called.",
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return nodeUrl;
|
|
178
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Hono } from "hono";
|
|
3
|
+
import { createMiddleware } from "hono/factory";
|
|
4
|
+
import { cors } from "@/common/cors";
|
|
5
|
+
import {
|
|
6
|
+
handleRouteError,
|
|
7
|
+
handleRouteNotFound,
|
|
8
|
+
loggerMiddleware,
|
|
9
|
+
} from "@/common/router";
|
|
10
|
+
import { getLogger } from "@/common/log";
|
|
11
|
+
|
|
12
|
+
export function logger() {
|
|
13
|
+
return getLogger("router");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createRouter(
|
|
17
|
+
basePath: string,
|
|
18
|
+
builder: (app: OpenAPIHono) => void,
|
|
19
|
+
): {
|
|
20
|
+
router: Hono;
|
|
21
|
+
openapi: OpenAPIHono;
|
|
22
|
+
} {
|
|
23
|
+
const router = new OpenAPIHono({ strict: false }).basePath(basePath);
|
|
24
|
+
|
|
25
|
+
router.use("*", loggerMiddleware(logger()), cors());
|
|
26
|
+
|
|
27
|
+
// HACK: Add Sec-WebSocket-Protocol header to fix KIT-339
|
|
28
|
+
//
|
|
29
|
+
// Some Deno WebSocket providers do not auto-set the protocol, which
|
|
30
|
+
// will cause some WebSocket clients to fail
|
|
31
|
+
router.use(
|
|
32
|
+
"*",
|
|
33
|
+
createMiddleware(async (c, next) => {
|
|
34
|
+
const upgrade = c.req.header("upgrade");
|
|
35
|
+
const isWebSocket = upgrade?.toLowerCase() === "websocket";
|
|
36
|
+
const isGet = c.req.method === "GET";
|
|
37
|
+
|
|
38
|
+
if (isGet && isWebSocket) {
|
|
39
|
+
c.header("Sec-WebSocket-Protocol", "rivet");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await next();
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
builder(router);
|
|
47
|
+
|
|
48
|
+
// Error handling
|
|
49
|
+
router.notFound(handleRouteNotFound);
|
|
50
|
+
router.onError(handleRouteError);
|
|
51
|
+
|
|
52
|
+
return { router: router as Hono, openapi: router };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function buildOpenApiResponses<T>(schema: T) {
|
|
56
|
+
return {
|
|
57
|
+
200: {
|
|
58
|
+
description: "Success",
|
|
59
|
+
content: {
|
|
60
|
+
"application/json": {
|
|
61
|
+
schema,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
400: {
|
|
66
|
+
description: "User error",
|
|
67
|
+
},
|
|
68
|
+
500: {
|
|
69
|
+
description: "Internal error",
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function buildOpenApiRequestBody<T>(schema: T) {
|
|
75
|
+
return {
|
|
76
|
+
required: true,
|
|
77
|
+
content: {
|
|
78
|
+
"application/json": {
|
|
79
|
+
schema,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import { detectRuntime, stringifyError, type Runtime } from "../utils";
|
|
3
|
+
import { RegistryConfig } from "@/registry/config";
|
|
4
|
+
import { logger } from "@/registry/log";
|
|
5
|
+
|
|
6
|
+
// TODO: Go back to dynamic import for this
|
|
7
|
+
import getPort from "get-port";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_PORT = 6420;
|
|
10
|
+
export type ServeStatic =
|
|
11
|
+
typeof import("@hono/node-server/serve-static").serveStatic;
|
|
12
|
+
const serveStaticLoaderPromises: Partial<Record<Runtime, Promise<ServeStatic>>> =
|
|
13
|
+
{};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Finds a free port starting from the given port.
|
|
17
|
+
*
|
|
18
|
+
* Tries ports incrementally until a free one is found.
|
|
19
|
+
*/
|
|
20
|
+
export async function findFreePort(
|
|
21
|
+
startPort: number = DEFAULT_PORT,
|
|
22
|
+
): Promise<number> {
|
|
23
|
+
// TODO: Fix this
|
|
24
|
+
// const getPortModule = "get-port";
|
|
25
|
+
// const { default: getPort } = await import(/* webpackIgnore: true */ getPortModule);
|
|
26
|
+
|
|
27
|
+
// Create an iterable of ports starting from startPort
|
|
28
|
+
function* portRange(start: number, count: number = 100): Iterable<number> {
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
30
|
+
yield start + i;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return getPort({ port: portRange(startPort) });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function crossPlatformServe(
|
|
38
|
+
config: RegistryConfig,
|
|
39
|
+
managerPort: number,
|
|
40
|
+
app: Hono<any>,
|
|
41
|
+
runtime: Runtime = detectRuntime(),
|
|
42
|
+
): Promise<{ upgradeWebSocket: any }> {
|
|
43
|
+
logger().debug({ msg: "detected runtime for serve", runtime });
|
|
44
|
+
|
|
45
|
+
switch (runtime) {
|
|
46
|
+
case "deno":
|
|
47
|
+
return serveDeno(config, managerPort, app);
|
|
48
|
+
case "bun":
|
|
49
|
+
return serveBun(config, managerPort, app);
|
|
50
|
+
case "node":
|
|
51
|
+
return serveNode(config, managerPort, app);
|
|
52
|
+
default:
|
|
53
|
+
return serveNode(config, managerPort, app);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function loadRuntimeServeStatic(
|
|
58
|
+
runtime: Runtime,
|
|
59
|
+
): Promise<ServeStatic> {
|
|
60
|
+
if (!serveStaticLoaderPromises[runtime]) {
|
|
61
|
+
if (runtime === "node") {
|
|
62
|
+
const nodeServeStaticModule = "@hono/node-server/serve-static";
|
|
63
|
+
serveStaticLoaderPromises[runtime] = import(
|
|
64
|
+
/* webpackIgnore: true */
|
|
65
|
+
nodeServeStaticModule
|
|
66
|
+
).then((x) => x.serveStatic);
|
|
67
|
+
} else if (runtime === "bun") {
|
|
68
|
+
const bunModule = "hono/bun";
|
|
69
|
+
serveStaticLoaderPromises[runtime] = import(
|
|
70
|
+
/* webpackIgnore: true */
|
|
71
|
+
bunModule
|
|
72
|
+
).then((x) => x.serveStatic as ServeStatic);
|
|
73
|
+
} else if (runtime === "deno") {
|
|
74
|
+
const denoModule = "hono/deno";
|
|
75
|
+
serveStaticLoaderPromises[runtime] = import(
|
|
76
|
+
/* webpackIgnore: true */
|
|
77
|
+
denoModule
|
|
78
|
+
).then((x) => x.serveStatic as ServeStatic);
|
|
79
|
+
} else {
|
|
80
|
+
throw new Error(`unsupported runtime: ${runtime}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return await serveStaticLoaderPromises[runtime]!;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function serveNode(
|
|
88
|
+
config: RegistryConfig,
|
|
89
|
+
managerPort: number,
|
|
90
|
+
app: Hono<any>,
|
|
91
|
+
): Promise<{ upgradeWebSocket: any }> {
|
|
92
|
+
// Import @hono/node-server using string variable to prevent static analysis
|
|
93
|
+
const nodeServerModule = "@hono/node-server";
|
|
94
|
+
let serve: any;
|
|
95
|
+
try {
|
|
96
|
+
const dep = await import(
|
|
97
|
+
/* webpackIgnore: true */
|
|
98
|
+
nodeServerModule
|
|
99
|
+
);
|
|
100
|
+
serve = dep.serve;
|
|
101
|
+
} catch (err) {
|
|
102
|
+
logger().error({
|
|
103
|
+
msg: "failed to import @hono/node-server. please run 'npm install @hono/node-server @hono/node-ws'",
|
|
104
|
+
error: stringifyError(err),
|
|
105
|
+
});
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Import @hono/node-ws using string variable to prevent static analysis
|
|
110
|
+
const nodeWsModule = "@hono/node-ws";
|
|
111
|
+
let createNodeWebSocket: any;
|
|
112
|
+
try {
|
|
113
|
+
const dep = await import(
|
|
114
|
+
/* webpackIgnore: true */
|
|
115
|
+
nodeWsModule
|
|
116
|
+
);
|
|
117
|
+
createNodeWebSocket = dep.createNodeWebSocket;
|
|
118
|
+
} catch (err) {
|
|
119
|
+
logger().error({
|
|
120
|
+
msg: "failed to import @hono/node-ws. please run 'npm install @hono/node-server @hono/node-ws'",
|
|
121
|
+
error: stringifyError(err),
|
|
122
|
+
});
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Inject WS
|
|
127
|
+
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({
|
|
128
|
+
app: app,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Start server
|
|
132
|
+
const port = managerPort;
|
|
133
|
+
const hostname = config.managerHost;
|
|
134
|
+
const server = serve({ fetch: app.fetch, port, hostname }, () =>
|
|
135
|
+
logger().info({ msg: "server listening", port, hostname }),
|
|
136
|
+
);
|
|
137
|
+
injectWebSocket(server);
|
|
138
|
+
|
|
139
|
+
return { upgradeWebSocket };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function serveDeno(
|
|
143
|
+
config: RegistryConfig,
|
|
144
|
+
managerPort: number,
|
|
145
|
+
app: Hono<any>,
|
|
146
|
+
): Promise<{ upgradeWebSocket: any }> {
|
|
147
|
+
// Import hono/deno using string variable to prevent static analysis
|
|
148
|
+
const honoDenoModule = "hono/deno";
|
|
149
|
+
let upgradeWebSocket: any;
|
|
150
|
+
try {
|
|
151
|
+
const dep = await import(
|
|
152
|
+
/* webpackIgnore: true */
|
|
153
|
+
honoDenoModule
|
|
154
|
+
);
|
|
155
|
+
upgradeWebSocket = dep.upgradeWebSocket;
|
|
156
|
+
} catch (err) {
|
|
157
|
+
logger().error({
|
|
158
|
+
msg: "failed to import hono/deno",
|
|
159
|
+
error: stringifyError(err),
|
|
160
|
+
});
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const port = config.managerPort;
|
|
165
|
+
const hostname = config.managerHost;
|
|
166
|
+
|
|
167
|
+
// Use Deno.serve
|
|
168
|
+
Deno.serve({ port, hostname }, app.fetch);
|
|
169
|
+
logger().info({ msg: "server listening", port, hostname });
|
|
170
|
+
|
|
171
|
+
return { upgradeWebSocket };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function serveBun(
|
|
175
|
+
config: RegistryConfig,
|
|
176
|
+
managerPort: number,
|
|
177
|
+
app: Hono<any>,
|
|
178
|
+
): Promise<{ upgradeWebSocket: any }> {
|
|
179
|
+
// Import hono/bun using string variable to prevent static analysis
|
|
180
|
+
const honoBunModule = "hono/bun";
|
|
181
|
+
let createBunWebSocket: any;
|
|
182
|
+
try {
|
|
183
|
+
const dep = await import(
|
|
184
|
+
/* webpackIgnore: true */
|
|
185
|
+
honoBunModule
|
|
186
|
+
);
|
|
187
|
+
createBunWebSocket = dep.createBunWebSocket;
|
|
188
|
+
} catch (err) {
|
|
189
|
+
logger().error({
|
|
190
|
+
msg: "failed to import hono/bun",
|
|
191
|
+
error: stringifyError(err),
|
|
192
|
+
});
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const { websocket, upgradeWebSocket } = createBunWebSocket();
|
|
197
|
+
|
|
198
|
+
const port = config.managerPort;
|
|
199
|
+
const hostname = config.managerHost;
|
|
200
|
+
|
|
201
|
+
// Use Bun.serve
|
|
202
|
+
// @ts-expect-error - Bun global
|
|
203
|
+
Bun.serve({
|
|
204
|
+
fetch: app.fetch,
|
|
205
|
+
port,
|
|
206
|
+
hostname,
|
|
207
|
+
websocket,
|
|
208
|
+
});
|
|
209
|
+
logger().info({ msg: "server listening", port, hostname });
|
|
210
|
+
|
|
211
|
+
return { upgradeWebSocket };
|
|
212
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { joinSignals } from "./utils";
|
|
3
|
+
|
|
4
|
+
describe("joinSignals", () => {
|
|
5
|
+
test("returns a non-aborted signal when no inputs are provided", () => {
|
|
6
|
+
const signal = joinSignals();
|
|
7
|
+
expect(signal.aborted).toBe(false);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("returns the same signal when only one input is provided", () => {
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const signal = joinSignals(controller.signal);
|
|
13
|
+
expect(signal).toBe(controller.signal);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("aborts immediately when any input signal is already aborted", () => {
|
|
17
|
+
const controllerA = new AbortController();
|
|
18
|
+
const controllerB = new AbortController();
|
|
19
|
+
controllerA.abort("already-aborted");
|
|
20
|
+
|
|
21
|
+
const signal = joinSignals(controllerA.signal, controllerB.signal);
|
|
22
|
+
expect(signal.aborted).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("aborts when one of the joined signals aborts", () => {
|
|
26
|
+
const controllerA = new AbortController();
|
|
27
|
+
const controllerB = new AbortController();
|
|
28
|
+
const signal = joinSignals(controllerA.signal, controllerB.signal);
|
|
29
|
+
|
|
30
|
+
expect(signal.aborted).toBe(false);
|
|
31
|
+
controllerB.abort("stopped");
|
|
32
|
+
expect(signal.aborted).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
});
|