rivetkit 2.0.42 → 2.1.0-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/dist/{tsup/config-CLnylLYY.d.ts → browser/client.d.ts} +2127 -1910
- 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/schemas/actor-inspector/v2.ts +796 -0
- package/dist/schemas/actor-inspector/v3.ts +899 -0
- package/dist/schemas/actor-persist/v4.ts +406 -0
- package/dist/schemas/client-protocol/v3.ts +554 -0
- package/dist/schemas/persist/v1.ts +781 -0
- package/dist/schemas/transport/v1.ts +697 -0
- package/dist/tsup/actor/errors.cjs +27 -3
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +37 -1
- package/dist/tsup/actor/errors.d.ts +37 -1
- package/dist/tsup/actor/errors.js +26 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.cts → actor-router-consts-D29T1Z-K.d.cts} +1 -1
- package/dist/tsup/{actor-router-consts-DzI2szci.d.ts → actor-router-consts-D29T1Z-K.d.ts} +1 -1
- package/dist/tsup/chunk-424PT5DM.js +23 -0
- package/dist/tsup/chunk-424PT5DM.js.map +1 -0
- package/dist/tsup/{chunk-JDAD2YFA.js → chunk-5ESWDTHJ.js} +148 -273
- package/dist/tsup/chunk-5ESWDTHJ.js.map +1 -0
- package/dist/tsup/{chunk-FJ3KTN4V.js → chunk-6LIBPELE.js} +119 -11
- package/dist/tsup/chunk-6LIBPELE.js.map +1 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs +96 -0
- package/dist/tsup/chunk-6LJAZ5R4.cjs.map +1 -0
- package/dist/tsup/{chunk-LFVF5SCU.js → chunk-7HTNH26M.js} +126 -1
- package/dist/tsup/chunk-7HTNH26M.js.map +1 -0
- package/dist/tsup/chunk-7K4CYDGD.js +630 -0
- package/dist/tsup/chunk-7K4CYDGD.js.map +1 -0
- package/dist/tsup/{chunk-XXGJCOL6.js → chunk-A6YIZWTK.js} +2 -2
- package/dist/tsup/chunk-AIYEYMX5.cjs +630 -0
- package/dist/tsup/chunk-AIYEYMX5.cjs.map +1 -0
- package/dist/tsup/{chunk-Q6W7RJJP.js → chunk-DIGBC2VI.js} +211 -2316
- package/dist/tsup/chunk-DIGBC2VI.js.map +1 -0
- package/dist/tsup/{chunk-RZW2DNND.cjs → chunk-F6JYU5IK.cjs} +1957 -1039
- package/dist/tsup/chunk-F6JYU5IK.cjs.map +1 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs +534 -0
- package/dist/tsup/chunk-HAZL2EPK.cjs.map +1 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs +23 -0
- package/dist/tsup/chunk-HDQ2JUQT.cjs.map +1 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs +1036 -0
- package/dist/tsup/chunk-HIDX4C5Y.cjs.map +1 -0
- package/dist/tsup/chunk-IVG73YCW.js +534 -0
- package/dist/tsup/chunk-IVG73YCW.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-2XQS746M.cjs → chunk-L47L3ZWJ.cjs} +127 -2
- package/dist/tsup/chunk-L47L3ZWJ.cjs.map +1 -0
- package/dist/tsup/{chunk-H4TB4X25.cjs → chunk-LW6KLR7A.cjs} +126 -18
- package/dist/tsup/chunk-LW6KLR7A.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-GMAVRZSF.js → chunk-M2T62AZQ.js} +1790 -872
- package/dist/tsup/chunk-M2T62AZQ.js.map +1 -0
- package/dist/tsup/chunk-MZ37VV3P.js +5974 -0
- package/dist/tsup/chunk-MZ37VV3P.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-OMEPCQK2.js +649 -0
- package/dist/tsup/chunk-OMEPCQK2.js.map +1 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs +72 -0
- package/dist/tsup/chunk-SR3KQE7Q.cjs.map +1 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs +2657 -0
- package/dist/tsup/chunk-SSEP6DHP.cjs.map +1 -0
- package/dist/tsup/chunk-T5YCUGVS.js +1036 -0
- package/dist/tsup/chunk-T5YCUGVS.js.map +1 -0
- package/dist/tsup/{chunk-EJVBH5VF.cjs → chunk-TPGXWFQT.cjs} +3 -3
- package/dist/tsup/{chunk-EJVBH5VF.cjs.map → chunk-TPGXWFQT.cjs.map} +1 -1
- package/dist/tsup/{chunk-X35U3YNX.cjs → chunk-TYLXNCA5.cjs} +214 -339
- package/dist/tsup/chunk-TYLXNCA5.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-XWBAQO5H.cjs +649 -0
- package/dist/tsup/chunk-XWBAQO5H.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs +5974 -0
- package/dist/tsup/chunk-YQ4LDVD6.cjs.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 +9 -10
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +11 -5
- package/dist/tsup/client/mod.d.ts +11 -5
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +4 -4
- package/dist/tsup/common/log.d.cts +2 -2
- package/dist/tsup/common/log.d.ts +2 -2
- package/dist/tsup/common/log.js +3 -2
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -3
- package/dist/tsup/config-BFqid9Gr.d.ts +2574 -0
- package/dist/tsup/config-BiNoIHRs.d.cts +80 -0
- package/dist/tsup/config-BiNoIHRs.d.ts +80 -0
- package/dist/tsup/{config-CZB2-W8x.d.cts → config-CAZphOS1.d.cts} +681 -355
- 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-D0QX9M11.d.ts → driver-Bxv62E2p.d.ts} +2 -2
- package/dist/tsup/{driver-q-zqG7fc.d.cts → driver-DYXwJR5D.d.cts} +2 -2
- package/dist/tsup/driver-helpers/mod.cjs +12 -6
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +12 -5
- package/dist/tsup/driver-helpers/mod.d.ts +12 -5
- package/dist/tsup/driver-helpers/mod.js +12 -5
- package/dist/tsup/driver-test-suite/mod.cjs +1370 -116
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +10 -4
- package/dist/tsup/driver-test-suite/mod.d.ts +10 -4
- package/dist/tsup/driver-test-suite/mod.js +2093 -838
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +29 -3
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +124 -3
- package/dist/tsup/inspector/mod.d.ts +124 -3
- package/dist/tsup/inspector/mod.js +72 -45
- package/dist/tsup/keys-CydblqMh.d.cts +13 -0
- package/dist/tsup/keys-CydblqMh.d.ts +13 -0
- package/dist/tsup/mod.cjs +16 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +26 -14
- package/dist/tsup/mod.d.ts +26 -14
- package/dist/tsup/mod.js +20 -13
- package/dist/tsup/serve-test-suite/mod.cjs +1165 -83
- package/dist/tsup/serve-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/serve-test-suite/mod.js +1114 -29
- package/dist/tsup/serve-test-suite/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +84 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +10 -5
- package/dist/tsup/test/mod.d.ts +10 -5
- package/dist/tsup/test/mod.js +85 -11
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils.cjs +10 -4
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +72 -2
- package/dist/tsup/utils.d.ts +72 -2
- package/dist/tsup/utils.js +9 -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 +83 -0
- package/dist/tsup/workflow/mod.d.ts +83 -0
- package/dist/tsup/workflow/mod.js +16 -0
- package/dist/tsup/workflow/mod.js.map +1 -0
- package/package.json +62 -5
- package/src/actor/config.ts +478 -68
- package/src/actor/conn/mod.ts +68 -16
- package/src/actor/conn/state-manager.ts +2 -2
- package/src/actor/contexts/action.ts +20 -12
- package/src/actor/contexts/base/actor.ts +137 -7
- package/src/actor/contexts/base/conn-init.ts +27 -7
- package/src/actor/contexts/base/conn.ts +27 -18
- package/src/actor/contexts/before-action-response.ts +9 -2
- package/src/actor/contexts/before-connect.ts +7 -2
- package/src/actor/contexts/connect.ts +9 -2
- package/src/actor/contexts/create-conn-state.ts +7 -2
- package/src/actor/contexts/create-vars.ts +16 -3
- package/src/actor/contexts/create.ts +16 -3
- package/src/actor/contexts/destroy.ts +9 -3
- package/src/actor/contexts/disconnect.ts +10 -4
- package/src/actor/contexts/index.ts +4 -3
- package/src/actor/contexts/request.ts +23 -6
- package/src/actor/contexts/run.ts +47 -0
- package/src/actor/contexts/sleep.ts +9 -3
- package/src/actor/contexts/state-change.ts +9 -3
- package/src/actor/contexts/wake.ts +9 -3
- package/src/actor/contexts/websocket.ts +23 -6
- package/src/actor/database.ts +8 -18
- package/src/actor/definition.ts +20 -6
- package/src/actor/driver.ts +32 -3
- package/src/actor/errors.ts +127 -0
- package/src/actor/instance/connection-manager.ts +183 -80
- package/src/actor/instance/event-manager.ts +26 -15
- package/src/actor/instance/keys.ts +117 -0
- package/src/actor/instance/mod.ts +784 -174
- package/src/actor/instance/queue-manager.ts +603 -0
- package/src/actor/instance/queue.ts +287 -0
- package/src/actor/instance/schedule-manager.ts +49 -7
- package/src/actor/instance/state-manager.ts +35 -11
- package/src/actor/instance/traces-driver.ts +128 -0
- package/src/actor/mod.ts +26 -2
- package/src/actor/protocol/old.ts +28 -13
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +177 -21
- package/src/actor/router-websocket-endpoints.ts +18 -29
- package/src/actor/router.ts +177 -0
- package/src/actor/schema.ts +291 -0
- package/src/actor/utils.ts +40 -0
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +100 -33
- package/src/client/actor-handle.ts +61 -33
- package/src/client/client.ts +2 -4
- package/src/client/config.ts +1 -1
- package/src/client/mod.browser.ts +2 -0
- package/src/client/mod.ts +1 -4
- package/src/client/queue.ts +146 -0
- package/src/client/utils.ts +1 -1
- package/src/common/log.ts +1 -1
- package/src/common/utils.ts +3 -3
- 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/driver-helpers/mod.ts +1 -0
- package/src/driver-test-suite/mod.ts +69 -43
- package/src/driver-test-suite/tests/access-control.ts +218 -0
- package/src/driver-test-suite/tests/actor-db-raw.ts +73 -0
- package/src/driver-test-suite/tests/actor-db.ts +394 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +259 -358
- package/src/driver-test-suite/tests/actor-kv.ts +41 -20
- package/src/driver-test-suite/tests/actor-queue.ts +324 -0
- package/src/driver-test-suite/tests/actor-run.ts +181 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +5 -2
- package/src/driver-test-suite/tests/actor-sleep.ts +3 -3
- package/src/driver-test-suite/tests/actor-stateless.ts +70 -0
- package/src/driver-test-suite/tests/actor-workflow.ts +108 -0
- package/src/driver-test-suite/tests/manager-driver.ts +11 -0
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +1 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +12 -12
- package/src/drivers/default.ts +7 -2
- package/src/drivers/engine/actor-driver.ts +45 -37
- package/src/drivers/engine/config.ts +1 -1
- package/src/drivers/file-system/actor.ts +20 -2
- package/src/drivers/file-system/global-state.ts +569 -258
- package/src/drivers/file-system/kv-limits.ts +70 -0
- package/src/drivers/file-system/manager.ts +22 -6
- package/src/drivers/file-system/mod.ts +39 -16
- package/src/drivers/file-system/sqlite-runtime.ts +210 -0
- package/src/inspector/actor-inspector.ts +224 -102
- package/src/inspector/config.ts +1 -1
- package/src/inspector/handler.ts +102 -20
- package/src/inspector/mod.browser.ts +8 -0
- package/src/inspector/mod.ts +2 -0
- package/src/inspector/serve-ui.ts +40 -0
- package/src/inspector/transport.ts +18 -0
- package/src/inspector/utils.ts +5 -39
- package/src/manager/gateway.ts +1 -1
- package/src/manager/protocol/mod.ts +1 -1
- package/src/manager/protocol/query.ts +1 -1
- package/src/manager/router-schema.ts +1 -1
- package/src/manager/router.ts +38 -12
- package/src/manager-api/actors.ts +1 -1
- package/src/manager-api/common.ts +1 -1
- package/src/registry/config/driver.ts +1 -1
- package/src/registry/config/index.ts +212 -43
- package/src/registry/config/legacy-runner.ts +1 -1
- package/src/registry/config/runner.ts +1 -1
- package/src/registry/config/serverless.ts +1 -1
- package/src/registry/index.ts +7 -5
- package/src/remote-manager-driver/api-utils.ts +1 -1
- package/src/schemas/actor-inspector/mod.ts +1 -1
- package/src/schemas/actor-inspector/versioned.ts +195 -8
- package/src/schemas/actor-persist/versioned.ts +87 -7
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +127 -11
- package/src/schemas/client-protocol-zod/mod.ts +16 -1
- package/src/schemas/persist/mod.ts +1 -0
- package/src/schemas/transport/mod.ts +1 -0
- package/src/serde.ts +1 -1
- package/src/serve-test-suite/mod.ts +10 -9
- package/src/test/mod.ts +15 -56
- package/src/utils/endpoint-parser.test.ts +1 -1
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +12 -1
- package/src/utils/node.ts +15 -2
- package/src/utils.test.ts +34 -0
- package/src/utils.ts +140 -6
- package/src/workflow/constants.ts +2 -0
- package/src/workflow/context.ts +532 -0
- package/src/workflow/driver.ts +191 -0
- package/src/workflow/inspector.ts +268 -0
- package/src/workflow/mod.ts +122 -0
- package/dist/tsup/chunk-2IJTYN6K.cjs +0 -278
- package/dist/tsup/chunk-2IJTYN6K.cjs.map +0 -1
- package/dist/tsup/chunk-2XQS746M.cjs.map +0 -1
- package/dist/tsup/chunk-3VP5CSHV.cjs +0 -114
- package/dist/tsup/chunk-3VP5CSHV.cjs.map +0 -1
- package/dist/tsup/chunk-AQFSQMBG.js +0 -114
- package/dist/tsup/chunk-AQFSQMBG.js.map +0 -1
- package/dist/tsup/chunk-E6ZE2YEA.js +0 -664
- package/dist/tsup/chunk-E6ZE2YEA.js.map +0 -1
- package/dist/tsup/chunk-FJ3KTN4V.js.map +0 -1
- package/dist/tsup/chunk-GBENOENJ.cjs +0 -8
- package/dist/tsup/chunk-GBENOENJ.cjs.map +0 -1
- package/dist/tsup/chunk-GD7UXGOE.cjs +0 -4762
- package/dist/tsup/chunk-GD7UXGOE.cjs.map +0 -1
- package/dist/tsup/chunk-GMAVRZSF.js.map +0 -1
- package/dist/tsup/chunk-H4TB4X25.cjs.map +0 -1
- package/dist/tsup/chunk-JDAD2YFA.js.map +0 -1
- package/dist/tsup/chunk-KCOVZOPS.js +0 -1946
- package/dist/tsup/chunk-KCOVZOPS.js.map +0 -1
- package/dist/tsup/chunk-KDFWJKMJ.cjs +0 -664
- package/dist/tsup/chunk-KDFWJKMJ.cjs.map +0 -1
- package/dist/tsup/chunk-LFVF5SCU.js.map +0 -1
- package/dist/tsup/chunk-Q6W7RJJP.js.map +0 -1
- package/dist/tsup/chunk-RUW5CZ5Z.cjs +0 -1949
- package/dist/tsup/chunk-RUW5CZ5Z.cjs.map +0 -1
- package/dist/tsup/chunk-RZW2DNND.cjs.map +0 -1
- package/dist/tsup/chunk-TCOEBUUE.js +0 -278
- package/dist/tsup/chunk-TCOEBUUE.js.map +0 -1
- package/dist/tsup/chunk-X35U3YNX.cjs.map +0 -1
- package/dist/tsup/keys-Chhy4ylv.d.cts +0 -8
- package/dist/tsup/keys-Chhy4ylv.d.ts +0 -8
- package/dist/tsup/v1-Gq4avTK3.d.cts +0 -240
- package/dist/tsup/v1-Gq4avTK3.d.ts +0 -240
- /package/dist/tsup/{chunk-XXGJCOL6.js.map → chunk-A6YIZWTK.js.map} +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { SqliteRuntimeDatabase } from "./sqlite-runtime";
|
|
2
|
+
|
|
3
|
+
// Keep these limits in sync with engine/packages/pegboard/src/actor_kv/mod.rs.
|
|
4
|
+
const KV_MAX_KEY_SIZE = 2 * 1024;
|
|
5
|
+
const KV_MAX_VALUE_SIZE = 128 * 1024;
|
|
6
|
+
const KV_MAX_KEYS = 128;
|
|
7
|
+
const KV_MAX_PUT_PAYLOAD_SIZE = 976 * 1024;
|
|
8
|
+
const KV_MAX_STORAGE_SIZE = 10 * 1024 * 1024 * 1024;
|
|
9
|
+
const KV_KEY_WRAPPER_OVERHEAD_SIZE = 2;
|
|
10
|
+
|
|
11
|
+
export function estimateKvSize(db: SqliteRuntimeDatabase): number {
|
|
12
|
+
const row = db.get<{ total: number | bigint | null }>(
|
|
13
|
+
"SELECT COALESCE(SUM(LENGTH(key) + LENGTH(value)), 0) AS total FROM kv",
|
|
14
|
+
);
|
|
15
|
+
return row ? Number(row.total ?? 0) : 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function validateKvKey(
|
|
19
|
+
key: Uint8Array,
|
|
20
|
+
keyLabel: "key" | "prefix key" = "key",
|
|
21
|
+
): void {
|
|
22
|
+
if (key.byteLength + KV_KEY_WRAPPER_OVERHEAD_SIZE > KV_MAX_KEY_SIZE) {
|
|
23
|
+
throw new Error(`${keyLabel} is too long (max 2048 bytes)`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function validateKvKeys(keys: Uint8Array[]): void {
|
|
28
|
+
if (keys.length > KV_MAX_KEYS) {
|
|
29
|
+
throw new Error("a maximum of 128 keys is allowed");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (const key of keys) {
|
|
33
|
+
validateKvKey(key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function validateKvEntries(
|
|
38
|
+
entries: [Uint8Array, Uint8Array][],
|
|
39
|
+
totalSize: number,
|
|
40
|
+
): void {
|
|
41
|
+
if (entries.length > KV_MAX_KEYS) {
|
|
42
|
+
throw new Error("A maximum of 128 key-value entries is allowed");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let payloadSize = 0;
|
|
46
|
+
for (const [key, value] of entries) {
|
|
47
|
+
payloadSize +=
|
|
48
|
+
key.byteLength + KV_KEY_WRAPPER_OVERHEAD_SIZE + value.byteLength;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (payloadSize > KV_MAX_PUT_PAYLOAD_SIZE) {
|
|
52
|
+
throw new Error("total payload is too large (max 976 KiB)");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const storageRemaining = Math.max(0, KV_MAX_STORAGE_SIZE - totalSize);
|
|
56
|
+
if (payloadSize > storageRemaining) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`not enough space left in storage (${storageRemaining} bytes remaining, current payload is ${payloadSize} bytes)`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (const [key, value] of entries) {
|
|
63
|
+
validateKvKey(key);
|
|
64
|
+
if (value.byteLength > KV_MAX_VALUE_SIZE) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`value is too large (max ${KV_MAX_VALUE_SIZE / 1024} KiB)`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -86,6 +86,7 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
86
86
|
|
|
87
87
|
// Extract just the pathname for routing (without query params)
|
|
88
88
|
const pathOnly = normalizedPath.split("?")[0];
|
|
89
|
+
const { gatewayId, requestId } = createHibernatableRequestMetadata();
|
|
89
90
|
|
|
90
91
|
const wsHandler = await routeWebSocket(
|
|
91
92
|
fakeRequest,
|
|
@@ -96,9 +97,9 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
96
97
|
actorId,
|
|
97
98
|
encoding,
|
|
98
99
|
params,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
gatewayId,
|
|
101
|
+
requestId,
|
|
102
|
+
true,
|
|
102
103
|
false,
|
|
103
104
|
);
|
|
104
105
|
return createInlineWebSocket(wsHandler);
|
|
@@ -129,6 +130,7 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
129
130
|
const normalizedPath = pathOnly.startsWith("/")
|
|
130
131
|
? pathOnly
|
|
131
132
|
: `/${pathOnly}`;
|
|
133
|
+
const { gatewayId, requestId } = createHibernatableRequestMetadata();
|
|
132
134
|
const wsHandler = await routeWebSocket(
|
|
133
135
|
// TODO: Create new request with new path
|
|
134
136
|
c.req.raw,
|
|
@@ -139,9 +141,9 @@ export class FileSystemManagerDriver implements ManagerDriver {
|
|
|
139
141
|
actorId,
|
|
140
142
|
encoding,
|
|
141
143
|
params,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
gatewayId,
|
|
145
|
+
requestId,
|
|
146
|
+
true,
|
|
145
147
|
false,
|
|
146
148
|
);
|
|
147
149
|
return upgradeWebSocket(() => wsHandler)(c, noopNext());
|
|
@@ -282,3 +284,17 @@ function actorStateToOutput(state: schema.ActorState): ActorOutput {
|
|
|
282
284
|
destroyTs: state.destroyTs !== null ? Number(state.destroyTs) : null,
|
|
283
285
|
};
|
|
284
286
|
}
|
|
287
|
+
|
|
288
|
+
function createHibernatableRequestMetadata(): {
|
|
289
|
+
gatewayId: ArrayBuffer;
|
|
290
|
+
requestId: ArrayBuffer;
|
|
291
|
+
} {
|
|
292
|
+
const gatewayId = new Uint8Array(4);
|
|
293
|
+
const requestId = new Uint8Array(4);
|
|
294
|
+
crypto.getRandomValues(gatewayId);
|
|
295
|
+
crypto.getRandomValues(requestId);
|
|
296
|
+
return {
|
|
297
|
+
gatewayId: gatewayId.buffer.slice(0),
|
|
298
|
+
requestId: requestId.buffer.slice(0),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
@@ -1,30 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { DriverConfig } from "@/registry/config";
|
|
1
3
|
import { importNodeDependencies } from "@/utils/node";
|
|
2
4
|
import { FileSystemActorDriver } from "./actor";
|
|
3
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
type FileSystemDriverOptions,
|
|
7
|
+
FileSystemGlobalState,
|
|
8
|
+
} from "./global-state";
|
|
4
9
|
import { FileSystemManagerDriver } from "./manager";
|
|
5
|
-
import { DriverConfig } from "@/registry/config";
|
|
6
10
|
|
|
7
11
|
export { FileSystemActorDriver } from "./actor";
|
|
8
12
|
export { FileSystemGlobalState } from "./global-state";
|
|
9
13
|
export { FileSystemManagerDriver } from "./manager";
|
|
10
14
|
export { getStoragePath } from "./utils";
|
|
11
15
|
|
|
16
|
+
const CreateFileSystemDriverOptionsSchema = z.object({
|
|
17
|
+
/** Custom path for storage. */
|
|
18
|
+
path: z.string().optional(),
|
|
19
|
+
/** Deprecated: file-system driver KV is now always SQLite-backed. */
|
|
20
|
+
useNativeSqlite: z.boolean().optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
type CreateFileSystemDriverOptionsInput = z.input<
|
|
24
|
+
typeof CreateFileSystemDriverOptionsSchema
|
|
25
|
+
>;
|
|
26
|
+
|
|
12
27
|
export function createFileSystemOrMemoryDriver(
|
|
13
28
|
persist: boolean = true,
|
|
14
|
-
|
|
29
|
+
options?: CreateFileSystemDriverOptionsInput,
|
|
15
30
|
): DriverConfig {
|
|
16
31
|
importNodeDependencies();
|
|
17
32
|
|
|
18
|
-
|
|
33
|
+
if (options?.useNativeSqlite === false) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"File-system driver no longer supports non-SQLite KV storage. Remove useNativeSqlite: false.",
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const stateOptions: FileSystemDriverOptions = {
|
|
40
|
+
persist,
|
|
41
|
+
customPath: options?.path,
|
|
42
|
+
useNativeSqlite: true,
|
|
43
|
+
};
|
|
44
|
+
const state = new FileSystemGlobalState(stateOptions);
|
|
19
45
|
const driverConfig: DriverConfig = {
|
|
20
46
|
name: persist ? "file-system" : "memory",
|
|
21
47
|
displayName: persist ? "File System" : "Memory",
|
|
22
48
|
manager: (config) =>
|
|
23
|
-
new FileSystemManagerDriver(
|
|
24
|
-
config,
|
|
25
|
-
state,
|
|
26
|
-
driverConfig,
|
|
27
|
-
),
|
|
49
|
+
new FileSystemManagerDriver(config, state, driverConfig),
|
|
28
50
|
actor: (config, managerDriver, inlineClient) => {
|
|
29
51
|
const actorDriver = new FileSystemActorDriver(
|
|
30
52
|
config,
|
|
@@ -33,11 +55,7 @@ export function createFileSystemOrMemoryDriver(
|
|
|
33
55
|
state,
|
|
34
56
|
);
|
|
35
57
|
|
|
36
|
-
state.onRunnerStart(
|
|
37
|
-
config,
|
|
38
|
-
inlineClient,
|
|
39
|
-
actorDriver,
|
|
40
|
-
);
|
|
58
|
+
state.onRunnerStart(config, inlineClient, actorDriver);
|
|
41
59
|
|
|
42
60
|
return actorDriver;
|
|
43
61
|
},
|
|
@@ -46,8 +64,13 @@ export function createFileSystemOrMemoryDriver(
|
|
|
46
64
|
return driverConfig;
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
export function createFileSystemDriver(
|
|
50
|
-
|
|
67
|
+
export function createFileSystemDriver(
|
|
68
|
+
opts?: CreateFileSystemDriverOptionsInput,
|
|
69
|
+
): DriverConfig {
|
|
70
|
+
const validatedOpts = opts
|
|
71
|
+
? CreateFileSystemDriverOptionsSchema.parse(opts)
|
|
72
|
+
: undefined;
|
|
73
|
+
return createFileSystemOrMemoryDriver(true, validatedOpts);
|
|
51
74
|
}
|
|
52
75
|
|
|
53
76
|
export function createMemoryDriver(): DriverConfig {
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { getRequireFn } from "@/utils/node";
|
|
2
|
+
|
|
3
|
+
type SqliteRuntimeKind = "bun" | "node" | "better-sqlite3";
|
|
4
|
+
type SqliteDatabaseCtor = new (path: string) => SqliteRawDatabase;
|
|
5
|
+
|
|
6
|
+
interface SqliteStatement {
|
|
7
|
+
run(...params: unknown[]): unknown;
|
|
8
|
+
get<T = Record<string, unknown>>(...params: unknown[]): T | undefined;
|
|
9
|
+
all<T = Record<string, unknown>>(...params: unknown[]): T[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SqliteRawDatabase {
|
|
13
|
+
exec(sql: string): unknown;
|
|
14
|
+
close(): unknown;
|
|
15
|
+
prepare?(sql: string): SqliteStatement;
|
|
16
|
+
query?(sql: string): SqliteStatement;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SqliteRuntimeDatabase {
|
|
20
|
+
exec(sql: string): void;
|
|
21
|
+
run(sql: string, params?: readonly unknown[]): void;
|
|
22
|
+
get<T = Record<string, unknown>>(
|
|
23
|
+
sql: string,
|
|
24
|
+
params?: readonly unknown[],
|
|
25
|
+
): T | undefined;
|
|
26
|
+
all<T = Record<string, unknown>>(
|
|
27
|
+
sql: string,
|
|
28
|
+
params?: readonly unknown[],
|
|
29
|
+
): T[];
|
|
30
|
+
close(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SqliteRuntime {
|
|
34
|
+
kind: SqliteRuntimeKind;
|
|
35
|
+
open(path: string): SqliteRuntimeDatabase;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function normalizeParams(params: readonly unknown[] | undefined): unknown[] {
|
|
39
|
+
if (!params || params.length === 0) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return params.map((value) => {
|
|
44
|
+
if (value instanceof Uint8Array) {
|
|
45
|
+
return Buffer.from(value);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createPreparedDatabaseAdapter(
|
|
52
|
+
rawDb: SqliteRawDatabase,
|
|
53
|
+
prepare: (sql: string) => SqliteStatement,
|
|
54
|
+
): SqliteRuntimeDatabase {
|
|
55
|
+
return {
|
|
56
|
+
exec: (sql) => {
|
|
57
|
+
rawDb.exec(sql);
|
|
58
|
+
},
|
|
59
|
+
run: (sql, params) => {
|
|
60
|
+
const stmt = prepare(sql);
|
|
61
|
+
stmt.run(...normalizeParams(params));
|
|
62
|
+
},
|
|
63
|
+
get: <T = Record<string, unknown>>(
|
|
64
|
+
sql: string,
|
|
65
|
+
params?: readonly unknown[],
|
|
66
|
+
) => {
|
|
67
|
+
const stmt = prepare(sql);
|
|
68
|
+
return stmt.get<T>(...normalizeParams(params));
|
|
69
|
+
},
|
|
70
|
+
all: <T = Record<string, unknown>>(
|
|
71
|
+
sql: string,
|
|
72
|
+
params?: readonly unknown[],
|
|
73
|
+
) => {
|
|
74
|
+
const stmt = prepare(sql);
|
|
75
|
+
return stmt.all<T>(...normalizeParams(params));
|
|
76
|
+
},
|
|
77
|
+
close: () => {
|
|
78
|
+
rawDb.close();
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function configureSqliteRuntimeDatabase(
|
|
84
|
+
rawDb: SqliteRawDatabase,
|
|
85
|
+
path: string,
|
|
86
|
+
): void {
|
|
87
|
+
// Wait briefly when the database file is still being released by another
|
|
88
|
+
// process during restarts to reduce transient "database is locked" failures.
|
|
89
|
+
rawDb.exec("PRAGMA busy_timeout = 5000");
|
|
90
|
+
|
|
91
|
+
// WAL improves concurrent read/write behavior for file-backed databases.
|
|
92
|
+
if (path !== ":memory:") {
|
|
93
|
+
rawDb.exec("PRAGMA journal_mode = WAL");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function loadSqliteRuntime(): SqliteRuntime {
|
|
98
|
+
const requireFn = getRequireFn();
|
|
99
|
+
const loadErrors: string[] = [];
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const bunSqlite = requireFn(/* webpackIgnore: true */ "bun:sqlite") as {
|
|
103
|
+
Database?: SqliteDatabaseCtor;
|
|
104
|
+
};
|
|
105
|
+
const BunDatabase = bunSqlite.Database;
|
|
106
|
+
if (BunDatabase) {
|
|
107
|
+
return {
|
|
108
|
+
kind: "bun",
|
|
109
|
+
open: (path) => {
|
|
110
|
+
const rawDb = new BunDatabase(path);
|
|
111
|
+
configureSqliteRuntimeDatabase(rawDb, path);
|
|
112
|
+
const query = rawDb.query?.bind(rawDb);
|
|
113
|
+
if (!query) throw new Error("bun:sqlite database missing query method");
|
|
114
|
+
return createPreparedDatabaseAdapter(rawDb, query);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
loadErrors.push(`bun:sqlite unavailable: ${String(error)}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const nodeSqlite = requireFn(/* webpackIgnore: true */ "node:sqlite") as {
|
|
124
|
+
DatabaseSync?: SqliteDatabaseCtor;
|
|
125
|
+
};
|
|
126
|
+
const NodeDatabaseSync = nodeSqlite.DatabaseSync;
|
|
127
|
+
if (NodeDatabaseSync) {
|
|
128
|
+
return {
|
|
129
|
+
kind: "node",
|
|
130
|
+
open: (path) => {
|
|
131
|
+
const rawDb = new NodeDatabaseSync(path);
|
|
132
|
+
configureSqliteRuntimeDatabase(rawDb, path);
|
|
133
|
+
const prepare = rawDb.prepare?.bind(rawDb);
|
|
134
|
+
if (!prepare) {
|
|
135
|
+
throw new Error("node:sqlite DatabaseSync missing prepare method");
|
|
136
|
+
}
|
|
137
|
+
return createPreparedDatabaseAdapter(rawDb, prepare);
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
loadErrors.push(`node:sqlite unavailable: ${String(error)}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
const betterSqlite3Module = requireFn(
|
|
147
|
+
/* webpackIgnore: true */ "better-sqlite3",
|
|
148
|
+
) as SqliteDatabaseCtor | { default?: SqliteDatabaseCtor };
|
|
149
|
+
const BetterSqlite3 =
|
|
150
|
+
typeof betterSqlite3Module === "function"
|
|
151
|
+
? betterSqlite3Module
|
|
152
|
+
: betterSqlite3Module.default;
|
|
153
|
+
if (BetterSqlite3) {
|
|
154
|
+
return {
|
|
155
|
+
kind: "better-sqlite3",
|
|
156
|
+
open: (path) => {
|
|
157
|
+
const rawDb = new BetterSqlite3(path);
|
|
158
|
+
configureSqliteRuntimeDatabase(rawDb, path);
|
|
159
|
+
const prepare = rawDb.prepare?.bind(rawDb);
|
|
160
|
+
if (!prepare) {
|
|
161
|
+
throw new Error("better-sqlite3 database missing prepare method");
|
|
162
|
+
}
|
|
163
|
+
return createPreparedDatabaseAdapter(rawDb, prepare);
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
loadErrors.push(`better-sqlite3 unavailable: ${String(error)}`);
|
|
169
|
+
throw new Error(
|
|
170
|
+
`No SQLite runtime available. Tried bun:sqlite, node:sqlite, and better-sqlite3. Install better-sqlite3 (e.g. "pnpm add better-sqlite3") if native runtimes are unavailable.\n${loadErrors.join("\n")}`,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
throw new Error(
|
|
175
|
+
`No SQLite runtime available. Tried bun:sqlite, node:sqlite, and better-sqlite3.\n${loadErrors.join("\n")}`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function computePrefixUpperBound(
|
|
180
|
+
prefix: Uint8Array,
|
|
181
|
+
): Uint8Array | undefined {
|
|
182
|
+
if (prefix.length === 0) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const upperBound = new Uint8Array(prefix);
|
|
187
|
+
for (let i = upperBound.length - 1; i >= 0; i--) {
|
|
188
|
+
if (upperBound[i] !== 0xff) {
|
|
189
|
+
upperBound[i] += 1;
|
|
190
|
+
return upperBound.slice(0, i + 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function ensureUint8Array(
|
|
197
|
+
value: unknown,
|
|
198
|
+
fieldName: string,
|
|
199
|
+
): Uint8Array {
|
|
200
|
+
if (value instanceof Uint8Array) {
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
if (value instanceof ArrayBuffer) {
|
|
204
|
+
return new Uint8Array(value);
|
|
205
|
+
}
|
|
206
|
+
if (ArrayBuffer.isView(value)) {
|
|
207
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
208
|
+
}
|
|
209
|
+
throw new Error(`SQLite row field "${fieldName}" is not binary data`);
|
|
210
|
+
}
|