rivetkit 2.0.3 → 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 +11 -0
- 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 +28 -31
- 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 +13 -1
- 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 +7 -1
- 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 +39 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +73 -28
- package/dist/tsup/actor/errors.d.ts +73 -28
- package/dist/tsup/actor/errors.js +54 -17
- 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-PO4VLDWA.js → chunk-JEAEA2PB.js} +8 -6
- 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-TZJKSBUQ.cjs → chunk-V2GHLYC6.cjs} +8 -6
- 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 +11 -10
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +57 -19
- package/dist/tsup/client/mod.d.ts +57 -19
- package/dist/tsup/client/mod.js +15 -14
- package/dist/tsup/common/log.cjs +12 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +31 -17
- package/dist/tsup/common/log.d.ts +31 -17
- package/dist/tsup/common/log.js +15 -7
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +4 -4
- 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 +27 -7
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +43 -14
- package/dist/tsup/driver-helpers/mod.d.ts +43 -14
- package/dist/tsup/driver-helpers/mod.js +41 -21
- package/dist/tsup/driver-test-suite/mod.cjs +2749 -2394
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +28 -12
- package/dist/tsup/driver-test-suite/mod.d.ts +28 -12
- package/dist/tsup/driver-test-suite/mod.js +3319 -2964
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +118 -7
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +126 -404
- package/dist/tsup/inspector/mod.d.ts +126 -404
- package/dist/tsup/inspector/mod.js +159 -48
- package/dist/tsup/keys-CydblqMh.d.cts +13 -0
- package/dist/tsup/keys-CydblqMh.d.ts +13 -0
- package/dist/tsup/mod.cjs +21 -12
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +102 -76
- package/dist/tsup/mod.d.ts +102 -76
- package/dist/tsup/mod.js +51 -42
- 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 +84 -15
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +15 -16
- package/dist/tsup/test/mod.d.ts +15 -16
- package/dist/tsup/test/mod.js +85 -16
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
- package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
- package/dist/tsup/utils.cjs +20 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +114 -2
- package/dist/tsup/utils.d.ts +114 -2
- package/dist/tsup/utils.js +19 -2
- package/dist/tsup/v3-DnYObHH3.d.cts +279 -0
- package/dist/tsup/v3-DnYObHH3.d.ts +279 -0
- package/dist/tsup/workflow/mod.cjs +16 -0
- package/dist/tsup/workflow/mod.cjs.map +1 -0
- package/dist/tsup/workflow/mod.d.cts +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 +101 -16
- package/src/actor/config.ts +674 -218
- 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 +8 -18
- package/src/actor/definition.ts +23 -45
- package/src/actor/driver.ts +78 -48
- package/src/actor/errors.ts +281 -85
- 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/{drivers/engine → actor}/keys.test.ts +13 -4
- package/src/actor/log.ts +4 -13
- package/src/actor/mod.ts +37 -40
- package/src/actor/protocol/old.ts +205 -70
- package/src/actor/protocol/serde.ts +100 -9
- package/src/actor/router-endpoints.ts +249 -534
- package/src/actor/router-websocket-endpoints.test.ts +54 -0
- package/src/actor/router-websocket-endpoints.ts +405 -0
- package/src/actor/router.ts +305 -188
- package/src/actor/schedule.ts +1 -1
- package/src/actor/schema.ts +291 -0
- package/src/actor/utils.test.ts +48 -0
- package/src/actor/utils.ts +71 -11
- package/src/client/actor-common.ts +4 -2
- package/src/client/actor-conn.ts +758 -300
- package/src/client/actor-handle.ts +198 -62
- package/src/client/actor-query.ts +112 -0
- package/src/client/client.ts +59 -124
- package/src/client/config.ts +151 -0
- package/src/client/errors.ts +37 -2
- package/src/client/log.ts +2 -4
- package/src/client/mod.browser.ts +2 -0
- package/src/client/mod.ts +33 -19
- package/src/client/queue.ts +146 -0
- package/src/client/raw-utils.ts +84 -27
- package/src/client/utils.ts +141 -39
- package/src/common/actor-router-consts.ts +59 -0
- package/src/common/cors.ts +57 -0
- package/src/common/eventsource.ts +7 -43
- package/src/common/inline-websocket-adapter.ts +154 -0
- package/src/common/log.ts +191 -101
- package/src/common/logfmt.ts +23 -30
- package/src/common/router.ts +114 -27
- package/src/common/utils.ts +35 -18
- package/src/common/websocket-interface.ts +7 -49
- package/src/common/websocket.ts +2 -2
- 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 +19 -8
- package/src/driver-helpers/utils.ts +46 -9
- package/src/driver-test-suite/log.ts +1 -3
- package/src/driver-test-suite/mod.ts +188 -108
- package/src/driver-test-suite/test-inline-client-driver.ts +179 -274
- package/src/driver-test-suite/tests/access-control.ts +218 -0
- package/src/driver-test-suite/tests/action-features.ts +69 -2
- package/src/driver-test-suite/tests/actor-conn-hibernation.ts +152 -0
- package/src/driver-test-suite/tests/actor-conn-state.ts +73 -22
- package/src/driver-test-suite/tests/actor-conn.ts +375 -128
- 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 +0 -7
- package/src/driver-test-suite/tests/actor-error-handling.ts +4 -12
- package/src/driver-test-suite/tests/actor-handle.ts +78 -25
- package/src/driver-test-suite/tests/actor-inline-client.ts +34 -23
- package/src/driver-test-suite/tests/actor-inspector.ts +216 -522
- package/src/driver-test-suite/tests/actor-kv.ts +65 -0
- package/src/driver-test-suite/tests/actor-metadata.ts +1 -1
- 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 +31 -42
- package/src/driver-test-suite/tests/actor-sleep.ts +27 -25
- package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
- package/src/driver-test-suite/tests/actor-vars.ts +6 -2
- package/src/driver-test-suite/tests/actor-workflow.ts +118 -0
- package/src/driver-test-suite/tests/manager-driver.ts +32 -9
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +71 -31
- package/src/driver-test-suite/tests/raw-http.ts +22 -10
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
- package/src/driver-test-suite/tests/raw-websocket.ts +86 -57
- package/src/driver-test-suite/tests/request-access.ts +130 -134
- package/src/driver-test-suite/utils.ts +28 -16
- package/src/drivers/default.ts +22 -15
- package/src/drivers/engine/actor-driver.ts +864 -197
- package/src/drivers/engine/config.ts +41 -37
- package/src/drivers/engine/log.ts +1 -3
- package/src/drivers/engine/mod.ts +16 -16
- package/src/drivers/file-system/actor.ts +46 -35
- package/src/drivers/file-system/global-state.ts +903 -131
- package/src/drivers/file-system/kv-limits.ts +70 -0
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +171 -177
- package/src/drivers/file-system/mod.ts +47 -17
- package/src/drivers/file-system/sqlite-runtime.ts +210 -0
- package/src/drivers/file-system/utils.ts +26 -10
- 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 +29 -0
- package/src/inspector/actor-inspector.ts +352 -0
- package/src/inspector/config.ts +11 -45
- package/src/inspector/handler.ts +273 -0
- package/src/inspector/log.ts +1 -1
- package/src/inspector/mod.browser.ts +8 -0
- package/src/inspector/mod.ts +4 -2
- package/src/inspector/serve-ui.ts +40 -0
- package/src/inspector/transport.ts +18 -0
- package/src/inspector/utils.ts +13 -57
- package/src/manager/driver.ts +40 -14
- package/src/manager/gateway.ts +668 -0
- package/src/manager/log.ts +2 -4
- package/src/manager/mod.ts +2 -2
- package/src/manager/protocol/mod.ts +1 -3
- package/src/manager/protocol/query.ts +2 -6
- package/src/manager/router-schema.ts +22 -0
- package/src/manager/router.ts +555 -1687
- package/src/manager-api/actors.ts +83 -0
- package/src/manager-api/common.ts +4 -0
- package/src/mod.ts +10 -6
- 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 +2 -4
- 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/{drivers/engine → remote-manager-driver}/ws-proxy.ts +46 -27
- 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 -1
- package/src/schemas/actor-persist/versioned.ts +211 -19
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +310 -43
- package/src/schemas/client-protocol-zod/mod.ts +118 -0
- package/src/schemas/file-system-driver/mod.ts +1 -1
- package/src/schemas/file-system-driver/versioned.ts +128 -21
- package/src/schemas/persist/mod.ts +1 -0
- package/src/schemas/transport/mod.ts +1 -0
- package/src/serde.ts +67 -13
- 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 +1 -3
- package/src/test/mod.ts +70 -124
- 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 +278 -13
- 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
- package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
- package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
- package/dist/tsup/chunk-3H7O2A7I.js +0 -525
- package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
- package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
- package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
- package/dist/tsup/chunk-4NSUQZ2H.js +0 -1790
- package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
- package/dist/tsup/chunk-6PDXBYI5.js +0 -132
- package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
- package/dist/tsup/chunk-6WKQDDUD.cjs +0 -1790
- package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
- package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
- package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
- package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
- package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
- package/dist/tsup/chunk-FCCPJNMA.cjs +0 -132
- package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
- package/dist/tsup/chunk-FLMTTN27.js +0 -244
- package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
- package/dist/tsup/chunk-GIR3AFFI.cjs +0 -315
- package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
- package/dist/tsup/chunk-INGJP237.js +0 -315
- package/dist/tsup/chunk-INGJP237.js.map +0 -1
- package/dist/tsup/chunk-KJCJLKRM.js +0 -116
- package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
- package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
- package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
- package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
- package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
- package/dist/tsup/chunk-OGAPU3UG.cjs +0 -525
- package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
- package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
- package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
- package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
- package/dist/tsup/chunk-R2OPSKIV.cjs +0 -244
- package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
- package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
- package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
- package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
- package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
- package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
- package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
- package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
- package/dist/tsup/chunk-UVUPOS46.js +0 -230
- package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
- package/dist/tsup/chunk-VRRHBNJC.js +0 -189
- package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
- package/dist/tsup/chunk-XFSS33EQ.js +0 -202
- package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
- package/dist/tsup/common-CpqORuCq.d.cts +0 -218
- package/dist/tsup/common-CpqORuCq.d.ts +0 -218
- package/dist/tsup/connection-BR_Ve4ku.d.cts +0 -2117
- package/dist/tsup/connection-BwUMoe6n.d.ts +0 -2117
- package/dist/tsup/router-endpoints-AYkXG8Tl.d.cts +0 -66
- package/dist/tsup/router-endpoints-DAbqVFx2.d.ts +0 -66
- package/src/actor/action.ts +0 -182
- package/src/actor/connection.ts +0 -260
- package/src/actor/context.ts +0 -171
- package/src/actor/generic-conn-driver.ts +0 -234
- package/src/actor/instance.ts +0 -1800
- package/src/actor/persisted.ts +0 -42
- package/src/actor/unstable-react.ts +0 -110
- package/src/client/http-client-driver.ts +0 -326
- package/src/common/fake-event-source.ts +0 -266
- package/src/common/inline-websocket-adapter2.ts +0 -445
- package/src/common/versioned-data.ts +0 -95
- package/src/driver-test-suite/tests/actor-auth.ts +0 -591
- package/src/drivers/engine/api-endpoints.ts +0 -128
- package/src/drivers/engine/api-utils.ts +0 -70
- package/src/drivers/engine/kv.ts +0 -3
- package/src/drivers/engine/manager-driver.ts +0 -391
- package/src/inline-client-driver/log.ts +0 -7
- package/src/inline-client-driver/mod.ts +0 -385
- package/src/inspector/actor.ts +0 -298
- package/src/inspector/manager.ts +0 -86
- package/src/inspector/protocol/actor.ts +0 -10
- package/src/inspector/protocol/common.ts +0 -196
- package/src/inspector/protocol/manager.ts +0 -10
- package/src/inspector/protocol/mod.ts +0 -2
- package/src/manager/auth.ts +0 -121
- package/src/manager/hono-websocket-adapter.ts +0 -333
- package/src/registry/config.ts +0 -32
- package/src/registry/mod.ts +0 -124
- package/src/registry/run-config.ts +0 -54
- package/src/registry/serve.ts +0 -53
- package/src/test/config.ts +0 -16
- /package/src/{drivers/engine → actor}/keys.ts +0 -0
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
import * as cbor from "cbor-x";
|
|
2
|
-
import type { Context as HonoContext } from "hono";
|
|
3
|
-
import invariant from "invariant";
|
|
4
|
-
import onChange from "on-change";
|
|
5
|
-
import type { WebSocket } from "ws";
|
|
6
|
-
import * as errors from "@/actor/errors";
|
|
7
|
-
import type { Encoding } from "@/actor/protocol/serde";
|
|
8
|
-
import {
|
|
9
|
-
PATH_CONNECT_WEBSOCKET,
|
|
10
|
-
PATH_RAW_WEBSOCKET_PREFIX,
|
|
11
|
-
} from "@/actor/router";
|
|
12
|
-
import {
|
|
13
|
-
HEADER_CONN_ID,
|
|
14
|
-
HEADER_CONN_PARAMS,
|
|
15
|
-
HEADER_CONN_TOKEN,
|
|
16
|
-
HEADER_ENCODING,
|
|
17
|
-
HEADER_EXPOSE_INTERNAL_ERROR,
|
|
18
|
-
} from "@/actor/router-endpoints";
|
|
19
|
-
import { assertUnreachable } from "@/actor/utils";
|
|
20
|
-
import type { ClientDriver } from "@/client/client";
|
|
21
|
-
import { ActorError as ClientActorError } from "@/client/errors";
|
|
22
|
-
import { sendHttpRequest } from "@/client/utils";
|
|
23
|
-
import { importEventSource } from "@/common/eventsource";
|
|
24
|
-
import type { UniversalEventSource } from "@/common/eventsource-interface";
|
|
25
|
-
import { deconstructError } from "@/common/utils";
|
|
26
|
-
import type { ManagerDriver } from "@/manager/driver";
|
|
27
|
-
import type { ActorQuery } from "@/manager/protocol/query";
|
|
28
|
-
import type { RunConfig } from "@/mod";
|
|
29
|
-
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
30
|
-
import {
|
|
31
|
-
HTTP_ACTION_REQUEST_VERSIONED,
|
|
32
|
-
HTTP_ACTION_RESPONSE_VERSIONED,
|
|
33
|
-
TO_CLIENT_VERSIONED,
|
|
34
|
-
TO_SERVER_VERSIONED,
|
|
35
|
-
} from "@/schemas/client-protocol/versioned";
|
|
36
|
-
import { bufferToArrayBuffer, httpUserAgent } from "@/utils";
|
|
37
|
-
import { logger } from "./log";
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Client driver that calls the manager driver inline.
|
|
41
|
-
*
|
|
42
|
-
* This is only applicable to standalone & coordinated topologies.
|
|
43
|
-
*
|
|
44
|
-
* This driver can access private resources.
|
|
45
|
-
*
|
|
46
|
-
* This driver serves a double purpose as:
|
|
47
|
-
* - Providing the client for the internal requests
|
|
48
|
-
* - Provide the driver for the manager HTTP router (see manager/router.ts)
|
|
49
|
-
*/
|
|
50
|
-
export function createInlineClientDriver(
|
|
51
|
-
managerDriver: ManagerDriver,
|
|
52
|
-
): ClientDriver {
|
|
53
|
-
const driver: ClientDriver = {
|
|
54
|
-
action: async <Args extends Array<unknown> = unknown[], Response = unknown>(
|
|
55
|
-
c: HonoContext | undefined,
|
|
56
|
-
actorQuery: ActorQuery,
|
|
57
|
-
encoding: Encoding,
|
|
58
|
-
params: unknown,
|
|
59
|
-
actionName: string,
|
|
60
|
-
args: Args,
|
|
61
|
-
opts: { signal?: AbortSignal },
|
|
62
|
-
): Promise<Response> => {
|
|
63
|
-
try {
|
|
64
|
-
// Get the actor ID
|
|
65
|
-
const { actorId } = await queryActor(c, actorQuery, managerDriver);
|
|
66
|
-
logger().debug("found actor for action", { actorId });
|
|
67
|
-
invariant(actorId, "Missing actor ID");
|
|
68
|
-
|
|
69
|
-
// Invoke the action
|
|
70
|
-
logger().debug("handling action", { actionName, encoding });
|
|
71
|
-
const responseData = await sendHttpRequest<
|
|
72
|
-
protocol.HttpActionRequest,
|
|
73
|
-
protocol.HttpActionResponse
|
|
74
|
-
>({
|
|
75
|
-
url: `http://actor/action/${encodeURIComponent(actionName)}`,
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: {
|
|
78
|
-
[HEADER_ENCODING]: encoding,
|
|
79
|
-
...(params !== undefined
|
|
80
|
-
? { [HEADER_CONN_PARAMS]: JSON.stringify(params) }
|
|
81
|
-
: {}),
|
|
82
|
-
[HEADER_EXPOSE_INTERNAL_ERROR]: "true",
|
|
83
|
-
},
|
|
84
|
-
body: {
|
|
85
|
-
args: bufferToArrayBuffer(cbor.encode(args)),
|
|
86
|
-
} satisfies protocol.HttpActionRequest,
|
|
87
|
-
encoding: encoding,
|
|
88
|
-
customFetch: managerDriver.sendRequest.bind(managerDriver, actorId),
|
|
89
|
-
signal: opts?.signal,
|
|
90
|
-
requestVersionedDataHandler: HTTP_ACTION_REQUEST_VERSIONED,
|
|
91
|
-
responseVersionedDataHandler: HTTP_ACTION_RESPONSE_VERSIONED,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return cbor.decode(new Uint8Array(responseData.output));
|
|
95
|
-
} catch (err) {
|
|
96
|
-
// Standardize to ClientActorError instead of the native backend error
|
|
97
|
-
const { code, message, metadata } = deconstructError(
|
|
98
|
-
err,
|
|
99
|
-
logger(),
|
|
100
|
-
{},
|
|
101
|
-
true,
|
|
102
|
-
);
|
|
103
|
-
const x = new ClientActorError(code, message, metadata);
|
|
104
|
-
throw new ClientActorError(code, message, metadata);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
resolveActorId: async (
|
|
109
|
-
c: HonoContext | undefined,
|
|
110
|
-
actorQuery: ActorQuery,
|
|
111
|
-
_encodingKind: Encoding,
|
|
112
|
-
): Promise<string> => {
|
|
113
|
-
// Get the actor ID
|
|
114
|
-
const { actorId } = await queryActor(c, actorQuery, managerDriver);
|
|
115
|
-
logger().debug("resolved actor", { actorId });
|
|
116
|
-
invariant(actorId, "missing actor ID");
|
|
117
|
-
|
|
118
|
-
return actorId;
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
connectWebSocket: async (
|
|
122
|
-
c: HonoContext | undefined,
|
|
123
|
-
actorQuery: ActorQuery,
|
|
124
|
-
encodingKind: Encoding,
|
|
125
|
-
params?: unknown,
|
|
126
|
-
): Promise<WebSocket> => {
|
|
127
|
-
// Get the actor ID
|
|
128
|
-
const { actorId } = await queryActor(c, actorQuery, managerDriver);
|
|
129
|
-
logger().debug("found actor for action", { actorId });
|
|
130
|
-
invariant(actorId, "Missing actor ID");
|
|
131
|
-
|
|
132
|
-
// Invoke the action
|
|
133
|
-
logger().debug("opening websocket", { actorId, encoding: encodingKind });
|
|
134
|
-
|
|
135
|
-
// Open WebSocket
|
|
136
|
-
const ws = await managerDriver.openWebSocket(
|
|
137
|
-
PATH_CONNECT_WEBSOCKET,
|
|
138
|
-
actorId,
|
|
139
|
-
encodingKind,
|
|
140
|
-
params,
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// Node & browser WebSocket types are incompatible
|
|
144
|
-
return ws as any;
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
connectSse: async (
|
|
148
|
-
c: HonoContext | undefined,
|
|
149
|
-
actorQuery: ActorQuery,
|
|
150
|
-
encodingKind: Encoding,
|
|
151
|
-
params: unknown,
|
|
152
|
-
): Promise<UniversalEventSource> => {
|
|
153
|
-
// Get the actor ID
|
|
154
|
-
const { actorId } = await queryActor(c, actorQuery, managerDriver);
|
|
155
|
-
logger().debug("found actor for sse connection", { actorId });
|
|
156
|
-
invariant(actorId, "Missing actor ID");
|
|
157
|
-
|
|
158
|
-
logger().debug("opening sse connection", {
|
|
159
|
-
actorId,
|
|
160
|
-
encoding: encodingKind,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
const EventSourceClass = await importEventSource();
|
|
164
|
-
|
|
165
|
-
const eventSource = new EventSourceClass("http://actor/connect/sse", {
|
|
166
|
-
fetch: (input, init) => {
|
|
167
|
-
return fetch(input, {
|
|
168
|
-
...init,
|
|
169
|
-
headers: {
|
|
170
|
-
...init?.headers,
|
|
171
|
-
"User-Agent": httpUserAgent(),
|
|
172
|
-
[HEADER_ENCODING]: encodingKind,
|
|
173
|
-
...(params !== undefined
|
|
174
|
-
? { [HEADER_CONN_PARAMS]: JSON.stringify(params) }
|
|
175
|
-
: {}),
|
|
176
|
-
[HEADER_EXPOSE_INTERNAL_ERROR]: "true",
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
}) as UniversalEventSource;
|
|
181
|
-
|
|
182
|
-
return eventSource;
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
sendHttpMessage: async (
|
|
186
|
-
c: HonoContext | undefined,
|
|
187
|
-
actorId: string,
|
|
188
|
-
encoding: Encoding,
|
|
189
|
-
connectionId: string,
|
|
190
|
-
connectionToken: string,
|
|
191
|
-
message: protocol.ToServer,
|
|
192
|
-
): Promise<void> => {
|
|
193
|
-
logger().debug("sending http message", { actorId, connectionId });
|
|
194
|
-
|
|
195
|
-
// Send an HTTP request to the connections endpoint
|
|
196
|
-
await sendHttpRequest({
|
|
197
|
-
url: "http://actor/connections/message",
|
|
198
|
-
method: "POST",
|
|
199
|
-
headers: {
|
|
200
|
-
[HEADER_ENCODING]: encoding,
|
|
201
|
-
[HEADER_CONN_ID]: connectionId,
|
|
202
|
-
[HEADER_CONN_TOKEN]: connectionToken,
|
|
203
|
-
[HEADER_EXPOSE_INTERNAL_ERROR]: "true",
|
|
204
|
-
},
|
|
205
|
-
body: message,
|
|
206
|
-
encoding,
|
|
207
|
-
skipParseResponse: true,
|
|
208
|
-
customFetch: managerDriver.sendRequest.bind(managerDriver, actorId),
|
|
209
|
-
requestVersionedDataHandler: TO_SERVER_VERSIONED,
|
|
210
|
-
responseVersionedDataHandler: TO_CLIENT_VERSIONED,
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
rawHttpRequest: async (
|
|
215
|
-
c: HonoContext | undefined,
|
|
216
|
-
actorQuery: ActorQuery,
|
|
217
|
-
encoding: Encoding,
|
|
218
|
-
params: unknown,
|
|
219
|
-
path: string,
|
|
220
|
-
init: RequestInit,
|
|
221
|
-
): Promise<Response> => {
|
|
222
|
-
try {
|
|
223
|
-
// Get the actor ID
|
|
224
|
-
const { actorId } = await queryActor(c, actorQuery, managerDriver);
|
|
225
|
-
logger().debug("found actor for raw http", { actorId });
|
|
226
|
-
invariant(actorId, "Missing actor ID");
|
|
227
|
-
|
|
228
|
-
// Build the URL with normalized path
|
|
229
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
230
|
-
const url = new URL(`http://actor/raw/http/${normalizedPath}`);
|
|
231
|
-
|
|
232
|
-
// Forward conn params if provided
|
|
233
|
-
const proxyRequestHeaders = new Headers(init.headers);
|
|
234
|
-
if (params) {
|
|
235
|
-
proxyRequestHeaders.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Forward the request to the actor
|
|
239
|
-
const proxyRequest = new Request(url, {
|
|
240
|
-
...init,
|
|
241
|
-
headers: proxyRequestHeaders,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
return await managerDriver.sendRequest(actorId, proxyRequest);
|
|
245
|
-
} catch (err) {
|
|
246
|
-
// Standardize to ClientActorError instead of the native backend error
|
|
247
|
-
const { code, message, metadata } = deconstructError(
|
|
248
|
-
err,
|
|
249
|
-
logger(),
|
|
250
|
-
{},
|
|
251
|
-
true,
|
|
252
|
-
);
|
|
253
|
-
throw new ClientActorError(code, message, metadata);
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
|
|
257
|
-
rawWebSocket: async (
|
|
258
|
-
c: HonoContext | undefined,
|
|
259
|
-
actorQuery: ActorQuery,
|
|
260
|
-
encoding: Encoding,
|
|
261
|
-
params: unknown,
|
|
262
|
-
path: string,
|
|
263
|
-
protocols: string | string[] | undefined,
|
|
264
|
-
): Promise<WebSocket> => {
|
|
265
|
-
// Get the actor ID
|
|
266
|
-
const { actorId } = await queryActor(c, actorQuery, managerDriver);
|
|
267
|
-
logger().debug("found actor for action", { actorId });
|
|
268
|
-
invariant(actorId, "Missing actor ID");
|
|
269
|
-
|
|
270
|
-
// Normalize path to match raw HTTP behavior
|
|
271
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
272
|
-
logger().debug("opening websocket", {
|
|
273
|
-
actorId,
|
|
274
|
-
encoding,
|
|
275
|
-
path: normalizedPath,
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
// Open WebSocket
|
|
279
|
-
const ws = await managerDriver.openWebSocket(
|
|
280
|
-
`${PATH_RAW_WEBSOCKET_PREFIX}${normalizedPath}`,
|
|
281
|
-
actorId,
|
|
282
|
-
encoding,
|
|
283
|
-
params,
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
// Node & browser WebSocket types are incompatible
|
|
287
|
-
return ws as any;
|
|
288
|
-
},
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
return driver;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Query the manager driver to get or create a actor based on the provided query
|
|
296
|
-
*/
|
|
297
|
-
export async function queryActor(
|
|
298
|
-
c: HonoContext | undefined,
|
|
299
|
-
query: ActorQuery,
|
|
300
|
-
driver: ManagerDriver,
|
|
301
|
-
): Promise<{ actorId: string }> {
|
|
302
|
-
logger().debug("querying actor", { query });
|
|
303
|
-
let actorOutput: { actorId: string };
|
|
304
|
-
if ("getForId" in query) {
|
|
305
|
-
const output = await driver.getForId({
|
|
306
|
-
c,
|
|
307
|
-
name: query.getForId.name,
|
|
308
|
-
actorId: query.getForId.actorId,
|
|
309
|
-
});
|
|
310
|
-
if (!output) throw new errors.ActorNotFound(query.getForId.actorId);
|
|
311
|
-
actorOutput = output;
|
|
312
|
-
} else if ("getForKey" in query) {
|
|
313
|
-
const existingActor = await driver.getWithKey({
|
|
314
|
-
c,
|
|
315
|
-
name: query.getForKey.name,
|
|
316
|
-
key: query.getForKey.key,
|
|
317
|
-
});
|
|
318
|
-
if (!existingActor) {
|
|
319
|
-
throw new errors.ActorNotFound(
|
|
320
|
-
`${query.getForKey.name}:${JSON.stringify(query.getForKey.key)}`,
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
actorOutput = existingActor;
|
|
324
|
-
} else if ("getOrCreateForKey" in query) {
|
|
325
|
-
const getOrCreateOutput = await driver.getOrCreateWithKey({
|
|
326
|
-
c,
|
|
327
|
-
name: query.getOrCreateForKey.name,
|
|
328
|
-
key: query.getOrCreateForKey.key,
|
|
329
|
-
input: query.getOrCreateForKey.input,
|
|
330
|
-
region: query.getOrCreateForKey.region,
|
|
331
|
-
});
|
|
332
|
-
actorOutput = {
|
|
333
|
-
actorId: getOrCreateOutput.actorId,
|
|
334
|
-
};
|
|
335
|
-
} else if ("create" in query) {
|
|
336
|
-
const createOutput = await driver.createActor({
|
|
337
|
-
c,
|
|
338
|
-
name: query.create.name,
|
|
339
|
-
key: query.create.key,
|
|
340
|
-
input: query.create.input,
|
|
341
|
-
region: query.create.region,
|
|
342
|
-
});
|
|
343
|
-
actorOutput = {
|
|
344
|
-
actorId: createOutput.actorId,
|
|
345
|
-
};
|
|
346
|
-
} else {
|
|
347
|
-
throw new errors.InvalidRequest("Invalid query format");
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
logger().debug("actor query result", {
|
|
351
|
-
actorId: actorOutput.actorId,
|
|
352
|
-
});
|
|
353
|
-
return { actorId: actorOutput.actorId };
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Removes the on-change library's proxy recursively from a value so we can clone it with `structuredClone`.
|
|
358
|
-
*/
|
|
359
|
-
function unproxyRecursive<T>(objProxied: T): T {
|
|
360
|
-
const obj = onChange.target<any>(objProxied);
|
|
361
|
-
|
|
362
|
-
// Short circuit if this object was proxied
|
|
363
|
-
//
|
|
364
|
-
// If the reference is different, then this value was proxied and no
|
|
365
|
-
// nested values are proxied
|
|
366
|
-
if (obj !== objProxied) return obj;
|
|
367
|
-
|
|
368
|
-
// Handle null/undefined
|
|
369
|
-
if (!obj || typeof obj !== "object") {
|
|
370
|
-
return obj;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Handle arrays
|
|
374
|
-
if (Array.isArray(obj)) {
|
|
375
|
-
return obj.map((x) => unproxyRecursive<any>(x)) as T;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// Handle objects
|
|
379
|
-
const result: any = {};
|
|
380
|
-
for (const key in obj) {
|
|
381
|
-
result[key] = unproxyRecursive<any>(obj[key]);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return result;
|
|
385
|
-
}
|
package/src/inspector/actor.ts
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { sValidator } from "@hono/standard-validator";
|
|
2
|
-
import jsonPatch from "@rivetkit/fast-json-patch";
|
|
3
|
-
import { Hono } from "hono";
|
|
4
|
-
import { streamSSE } from "hono/streaming";
|
|
5
|
-
import { createNanoEvents, type Unsubscribe } from "nanoevents";
|
|
6
|
-
import z from "zod/v4";
|
|
7
|
-
import type {
|
|
8
|
-
AnyDatabaseProvider,
|
|
9
|
-
InferDatabaseClient,
|
|
10
|
-
} from "@/actor/database";
|
|
11
|
-
import {
|
|
12
|
-
ColumnsSchema,
|
|
13
|
-
type Connection,
|
|
14
|
-
ForeignKeysSchema,
|
|
15
|
-
PatchSchema,
|
|
16
|
-
type RealtimeEvent,
|
|
17
|
-
type RecordedRealtimeEvent,
|
|
18
|
-
TablesSchema,
|
|
19
|
-
} from "./protocol/common";
|
|
20
|
-
|
|
21
|
-
export type ActorInspectorRouterEnv = {
|
|
22
|
-
Variables: {
|
|
23
|
-
inspector: ActorInspector;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Create a router for the Actor Inspector.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export function createActorInspectorRouter() {
|
|
32
|
-
return new Hono<ActorInspectorRouterEnv>()
|
|
33
|
-
.get("/ping", (c) => {
|
|
34
|
-
return c.json({ message: "pong" }, 200);
|
|
35
|
-
})
|
|
36
|
-
.get("/state", async (c) => {
|
|
37
|
-
if (await c.var.inspector.accessors.isStateEnabled()) {
|
|
38
|
-
return c.json(
|
|
39
|
-
{
|
|
40
|
-
enabled: true,
|
|
41
|
-
state: await c.var.inspector.accessors.getState(),
|
|
42
|
-
},
|
|
43
|
-
200,
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return c.json({ enabled: false, state: null }, 200);
|
|
47
|
-
})
|
|
48
|
-
.patch(
|
|
49
|
-
"/state",
|
|
50
|
-
sValidator(
|
|
51
|
-
"json",
|
|
52
|
-
z.object({ patch: PatchSchema }).or(z.object({ replace: z.any() })),
|
|
53
|
-
),
|
|
54
|
-
async (c) => {
|
|
55
|
-
if (!(await c.var.inspector.accessors.isStateEnabled())) {
|
|
56
|
-
return c.json({ enabled: false }, 200);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const body = c.req.valid("json");
|
|
60
|
-
if ("replace" in body) {
|
|
61
|
-
await c.var.inspector.accessors.setState(body.replace);
|
|
62
|
-
return c.json(
|
|
63
|
-
{
|
|
64
|
-
enabled: true,
|
|
65
|
-
state: await c.var.inspector.accessors.getState(),
|
|
66
|
-
},
|
|
67
|
-
200,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
const state = await c.var.inspector.accessors.getState();
|
|
71
|
-
|
|
72
|
-
const { newDocument: newState } = jsonPatch.applyPatch(
|
|
73
|
-
state,
|
|
74
|
-
body.patch,
|
|
75
|
-
);
|
|
76
|
-
await c.var.inspector.accessors.setState(newState);
|
|
77
|
-
|
|
78
|
-
return c.json(
|
|
79
|
-
{ enabled: true, state: await c.var.inspector.accessors.getState() },
|
|
80
|
-
200,
|
|
81
|
-
);
|
|
82
|
-
},
|
|
83
|
-
)
|
|
84
|
-
.get("/state/stream", async (c) => {
|
|
85
|
-
if (!(await c.var.inspector.accessors.isStateEnabled())) {
|
|
86
|
-
return c.json({ enabled: false }, 200);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let id = 0;
|
|
90
|
-
let unsub: Unsubscribe;
|
|
91
|
-
return streamSSE(
|
|
92
|
-
c,
|
|
93
|
-
async (stream) => {
|
|
94
|
-
unsub = c.var.inspector.emitter.on("stateUpdated", async (state) => {
|
|
95
|
-
stream.writeSSE({
|
|
96
|
-
data: JSON.stringify(state) || "",
|
|
97
|
-
event: "state-update",
|
|
98
|
-
id: String(id++),
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const { promise } = Promise.withResolvers<void>();
|
|
103
|
-
|
|
104
|
-
return promise;
|
|
105
|
-
},
|
|
106
|
-
async () => {
|
|
107
|
-
unsub?.();
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
})
|
|
111
|
-
.get("/connections", async (c) => {
|
|
112
|
-
const connections = await c.var.inspector.accessors.getConnections();
|
|
113
|
-
return c.json({ connections }, 200);
|
|
114
|
-
})
|
|
115
|
-
.get("/connections/stream", async (c) => {
|
|
116
|
-
let id = 0;
|
|
117
|
-
let unsub: Unsubscribe;
|
|
118
|
-
return streamSSE(
|
|
119
|
-
c,
|
|
120
|
-
async (stream) => {
|
|
121
|
-
unsub = c.var.inspector.emitter.on("connectionUpdated", async () => {
|
|
122
|
-
stream.writeSSE({
|
|
123
|
-
data: JSON.stringify(
|
|
124
|
-
await c.var.inspector.accessors.getConnections(),
|
|
125
|
-
),
|
|
126
|
-
event: "connection-update",
|
|
127
|
-
id: String(id++),
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const { promise } = Promise.withResolvers<void>();
|
|
132
|
-
|
|
133
|
-
return promise;
|
|
134
|
-
},
|
|
135
|
-
async () => {
|
|
136
|
-
unsub?.();
|
|
137
|
-
},
|
|
138
|
-
);
|
|
139
|
-
})
|
|
140
|
-
.get("/events", async (c) => {
|
|
141
|
-
const events = c.var.inspector.lastRealtimeEvents;
|
|
142
|
-
return c.json({ events }, 200);
|
|
143
|
-
})
|
|
144
|
-
.post("/events/clear", async (c) => {
|
|
145
|
-
c.var.inspector.lastRealtimeEvents.length = 0; // Clear the events
|
|
146
|
-
return c.json({ message: "Events cleared" }, 200);
|
|
147
|
-
})
|
|
148
|
-
.get("/events/stream", async (c) => {
|
|
149
|
-
let id = 0;
|
|
150
|
-
let unsub: Unsubscribe;
|
|
151
|
-
return streamSSE(
|
|
152
|
-
c,
|
|
153
|
-
async (stream) => {
|
|
154
|
-
unsub = c.var.inspector.emitter.on("eventFired", () => {
|
|
155
|
-
stream.writeSSE({
|
|
156
|
-
data: JSON.stringify(c.var.inspector.lastRealtimeEvents),
|
|
157
|
-
event: "realtime-event",
|
|
158
|
-
id: String(id++),
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const { promise } = Promise.withResolvers<void>();
|
|
163
|
-
|
|
164
|
-
return promise;
|
|
165
|
-
},
|
|
166
|
-
async () => {
|
|
167
|
-
unsub?.();
|
|
168
|
-
},
|
|
169
|
-
);
|
|
170
|
-
})
|
|
171
|
-
.get("/rpcs", async (c) => {
|
|
172
|
-
const rpcs = await c.var.inspector.accessors.getRpcs();
|
|
173
|
-
return c.json({ rpcs }, 200);
|
|
174
|
-
})
|
|
175
|
-
.get("/db", async (c) => {
|
|
176
|
-
if (!(await c.var.inspector.accessors.isDbEnabled())) {
|
|
177
|
-
return c.json({ enabled: false, db: null }, 200);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Access the SQLite database
|
|
181
|
-
const db = await c.var.inspector.accessors.getDb();
|
|
182
|
-
|
|
183
|
-
// Get list of tables
|
|
184
|
-
const rows = await db.execute(`PRAGMA table_list`);
|
|
185
|
-
const tables = TablesSchema.parse(rows).filter(
|
|
186
|
-
(table) => table.schema !== "temp" && !table.name.startsWith("sqlite_"),
|
|
187
|
-
);
|
|
188
|
-
// Get columns for each table
|
|
189
|
-
const tablesInfo = await Promise.all(
|
|
190
|
-
tables.map((table) => db.execute(`PRAGMA table_info(${table.name})`)),
|
|
191
|
-
);
|
|
192
|
-
const columns = tablesInfo.map((def) => ColumnsSchema.parse(def));
|
|
193
|
-
|
|
194
|
-
// Get foreign keys for each table
|
|
195
|
-
const foreignKeysList = await Promise.all(
|
|
196
|
-
tables.map((table) =>
|
|
197
|
-
db.execute(`PRAGMA foreign_key_list(${table.name})`),
|
|
198
|
-
),
|
|
199
|
-
);
|
|
200
|
-
const foreignKeys = foreignKeysList.map((def) =>
|
|
201
|
-
ForeignKeysSchema.parse(def),
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
// Get record counts for each table
|
|
205
|
-
const countInfo = await Promise.all(
|
|
206
|
-
tables.map((table) =>
|
|
207
|
-
db.execute(`SELECT COUNT(*) as count FROM ${table.name}`),
|
|
208
|
-
),
|
|
209
|
-
);
|
|
210
|
-
const counts = countInfo.map((def) => {
|
|
211
|
-
return def[0].count || 0;
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
return c.json(
|
|
215
|
-
{
|
|
216
|
-
enabled: true,
|
|
217
|
-
db: tablesInfo.map((_, index) => {
|
|
218
|
-
return {
|
|
219
|
-
table: tables[index],
|
|
220
|
-
columns: columns[index],
|
|
221
|
-
foreignKeys: foreignKeys[index],
|
|
222
|
-
records: counts[index],
|
|
223
|
-
};
|
|
224
|
-
}),
|
|
225
|
-
},
|
|
226
|
-
200,
|
|
227
|
-
);
|
|
228
|
-
})
|
|
229
|
-
.post(
|
|
230
|
-
"/db",
|
|
231
|
-
sValidator(
|
|
232
|
-
"json",
|
|
233
|
-
z.object({ query: z.string(), params: z.array(z.any()).optional() }),
|
|
234
|
-
),
|
|
235
|
-
async (c) => {
|
|
236
|
-
if (!(await c.var.inspector.accessors.isDbEnabled())) {
|
|
237
|
-
return c.json({ enabled: false }, 200);
|
|
238
|
-
}
|
|
239
|
-
const db = await c.var.inspector.accessors.getDb();
|
|
240
|
-
|
|
241
|
-
try {
|
|
242
|
-
const result = (await db.execute(
|
|
243
|
-
c.req.valid("json").query,
|
|
244
|
-
...(c.req.valid("json").params || []),
|
|
245
|
-
)) as unknown;
|
|
246
|
-
return c.json({ result }, 200);
|
|
247
|
-
} catch (error) {
|
|
248
|
-
c;
|
|
249
|
-
return c.json({ error: (error as Error).message }, 500);
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
interface ActorInspectorAccessors {
|
|
256
|
-
isStateEnabled: () => Promise<boolean>;
|
|
257
|
-
getState: () => Promise<unknown>;
|
|
258
|
-
setState: (state: unknown) => Promise<void>;
|
|
259
|
-
isDbEnabled: () => Promise<boolean>;
|
|
260
|
-
getDb: () => Promise<InferDatabaseClient<AnyDatabaseProvider>>;
|
|
261
|
-
getRpcs: () => Promise<string[]>;
|
|
262
|
-
getConnections: () => Promise<Connection[]>;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
interface ActorInspectorEmitterEvents {
|
|
266
|
-
stateUpdated: (state: unknown) => void;
|
|
267
|
-
connectionUpdated: () => void;
|
|
268
|
-
eventFired: (event: RealtimeEvent) => void;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Provides a unified interface for inspecting actor external and internal state.
|
|
273
|
-
*/
|
|
274
|
-
export class ActorInspector {
|
|
275
|
-
public readonly accessors: ActorInspectorAccessors;
|
|
276
|
-
public readonly emitter = createNanoEvents<ActorInspectorEmitterEvents>();
|
|
277
|
-
|
|
278
|
-
#lastRealtimeEvents: RecordedRealtimeEvent[] = [];
|
|
279
|
-
|
|
280
|
-
get lastRealtimeEvents() {
|
|
281
|
-
return this.#lastRealtimeEvents;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
constructor(accessors: () => ActorInspectorAccessors) {
|
|
285
|
-
this.accessors = accessors();
|
|
286
|
-
this.emitter.on("eventFired", (event) => {
|
|
287
|
-
this.#lastRealtimeEvents.push({
|
|
288
|
-
id: crypto.randomUUID(),
|
|
289
|
-
timestamp: Date.now(),
|
|
290
|
-
...event,
|
|
291
|
-
});
|
|
292
|
-
// keep the last 100 events
|
|
293
|
-
if (this.#lastRealtimeEvents.length > 100) {
|
|
294
|
-
this.#lastRealtimeEvents = this.#lastRealtimeEvents.slice(-100);
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|