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
|
@@ -1,691 +1,572 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import z$2, { z } from 'zod/v4';
|
|
2
2
|
import { UniversalWebSocket } from '@rivetkit/virtual-websocket';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { SqliteVfs } from '@rivetkit/sqlite-vfs';
|
|
4
|
+
import { Traces, OtlpExportTraceServiceRequestJson, SpanHandle, SpanStatusInput } from '@rivetkit/traces';
|
|
5
|
+
import { Context, Handler, Env, Hono } from 'hono';
|
|
6
|
+
import { z as z$1 } from 'zod';
|
|
5
7
|
import { Logger } from 'pino';
|
|
6
|
-
import {
|
|
8
|
+
import { VersionedDataHandler } from 'vbare';
|
|
9
|
+
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
7
10
|
import * as nanoevents from 'nanoevents';
|
|
8
|
-
import {
|
|
11
|
+
import { W as WorkflowHistory, k as QueueStatus } from './v3-DnYObHH3.js';
|
|
12
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
13
|
+
import '@rivetkit/bare-ts';
|
|
9
14
|
|
|
10
|
-
type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
|
|
11
15
|
type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Context provided to database providers for creating database clients
|
|
18
|
+
*/
|
|
19
|
+
interface DatabaseProviderContext {
|
|
20
|
+
/**
|
|
21
|
+
* Actor ID
|
|
22
|
+
*/
|
|
23
|
+
actorId: string;
|
|
24
|
+
/**
|
|
25
|
+
* Override the default raw database client (optional).
|
|
26
|
+
* If not provided, a KV-backed client will be constructed.
|
|
27
|
+
*/
|
|
28
|
+
overrideRawDatabaseClient?: () => Promise<RawDatabaseClient | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Override the default Drizzle database client (optional).
|
|
31
|
+
* If not provided, a KV-backed client will be constructed.
|
|
32
|
+
*/
|
|
33
|
+
overrideDrizzleDatabaseClient?: () => Promise<DrizzleDatabaseClient | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* KV operations for constructing KV-backed database clients
|
|
36
|
+
*/
|
|
37
|
+
kv: {
|
|
38
|
+
batchPut: (entries: [Uint8Array, Uint8Array][]) => Promise<void>;
|
|
39
|
+
batchGet: (keys: Uint8Array[]) => Promise<(Uint8Array | null)[]>;
|
|
40
|
+
batchDelete: (keys: Uint8Array[]) => Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* SQLite VFS instance for creating KV-backed databases.
|
|
44
|
+
* This should be actor-scoped because @rivetkit/sqlite is not re-entrant per
|
|
45
|
+
* module instance.
|
|
46
|
+
*/
|
|
47
|
+
sqliteVfs?: SqliteVfs;
|
|
48
|
+
}
|
|
49
|
+
type DatabaseProvider<DB extends RawAccess> = {
|
|
15
50
|
/**
|
|
16
51
|
* Creates a new database client for the actor.
|
|
17
52
|
* The result is passed to the actor context as `c.db`.
|
|
18
53
|
* @experimental
|
|
19
54
|
*/
|
|
20
|
-
createClient: (ctx:
|
|
21
|
-
getDatabase: () => Promise<string | unknown>;
|
|
22
|
-
}) => Promise<DB>;
|
|
55
|
+
createClient: (ctx: DatabaseProviderContext) => Promise<DB>;
|
|
23
56
|
/**
|
|
24
57
|
* Runs before the actor has started.
|
|
25
58
|
* Use this to run migrations or other setup tasks.
|
|
26
59
|
* @experimental
|
|
27
60
|
*/
|
|
28
61
|
onMigrate: (client: DB) => void | Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Runs when the actor is being destroyed.
|
|
64
|
+
* Use this to clean up database connections and release resources.
|
|
65
|
+
* @experimental
|
|
66
|
+
*/
|
|
67
|
+
onDestroy?: (client: DB) => void | Promise<void>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Raw database client with basic exec method
|
|
71
|
+
*/
|
|
72
|
+
interface RawDatabaseClient {
|
|
73
|
+
exec: <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]> | TRow[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Drizzle database client interface (will be extended by drizzle-orm types)
|
|
77
|
+
*/
|
|
78
|
+
interface DrizzleDatabaseClient {
|
|
79
|
+
}
|
|
80
|
+
type ExecuteFunction = <TRow extends Record<string, unknown> = Record<string, unknown>>(query: string, ...args: unknown[]) => Promise<TRow[]>;
|
|
81
|
+
type RawAccess = {
|
|
82
|
+
/**
|
|
83
|
+
* Executes a raw SQL query.
|
|
84
|
+
*/
|
|
85
|
+
execute: ExecuteFunction;
|
|
86
|
+
/**
|
|
87
|
+
* Closes the database connection and releases resources.
|
|
88
|
+
*/
|
|
89
|
+
close: () => Promise<void>;
|
|
29
90
|
};
|
|
30
91
|
|
|
31
|
-
type
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
92
|
+
type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
|
|
93
|
+
|
|
94
|
+
type SchemaHookResult = boolean | Promise<boolean>;
|
|
95
|
+
type SchemaHook<TContext = any> = (ctx: TContext) => SchemaHookResult;
|
|
96
|
+
interface EventTypeToken<T, TContext = any> {
|
|
97
|
+
readonly _eventType?: T;
|
|
98
|
+
readonly canSubscribe?: SchemaHook<TContext>;
|
|
99
|
+
readonly schema?: PrimitiveSchema;
|
|
100
|
+
}
|
|
101
|
+
interface QueueTypeToken<TMessage, TComplete = never, TContext = any> {
|
|
102
|
+
readonly _queueMessage?: TMessage;
|
|
103
|
+
readonly _queueComplete?: TComplete;
|
|
104
|
+
readonly canPublish?: SchemaHook<TContext>;
|
|
105
|
+
readonly message?: PrimitiveSchema;
|
|
106
|
+
readonly complete?: PrimitiveSchema;
|
|
107
|
+
}
|
|
108
|
+
type PrimitiveSchema = StandardSchemaV1 | EventTypeToken<unknown, any>;
|
|
109
|
+
interface EventSchemaDefinition<TContext = any> {
|
|
110
|
+
schema: PrimitiveSchema;
|
|
111
|
+
canSubscribe?: SchemaHook<TContext>;
|
|
112
|
+
}
|
|
113
|
+
interface QueueSchemaDefinition<TContext = any> {
|
|
114
|
+
message: PrimitiveSchema;
|
|
115
|
+
complete?: PrimitiveSchema;
|
|
116
|
+
canPublish?: SchemaHook<TContext>;
|
|
117
|
+
}
|
|
118
|
+
type EventSchema<TContext = any> = PrimitiveSchema | EventSchemaDefinition<TContext>;
|
|
119
|
+
type QueueSchema = PrimitiveSchema | QueueSchemaDefinition<any> | QueueTypeToken<unknown, unknown, any>;
|
|
120
|
+
type EventSchemaConfig<TContext = any> = Record<string, EventSchema<TContext>>;
|
|
121
|
+
type QueueSchemaConfig<TContext = any> = Record<string, QueueSchema>;
|
|
122
|
+
type InferSchema<T> = T extends QueueSchemaDefinition<any> ? InferSchema<T["message"]> : T extends QueueTypeToken<infer M, unknown, any> ? M : T extends EventSchemaDefinition<any> ? InferSchema<T["schema"]> : T extends StandardSchemaV1<any, infer O> ? O : T extends EventTypeToken<infer R, any> ? R : never;
|
|
123
|
+
type InferSchemaMap<T extends Record<string, unknown>> = {
|
|
124
|
+
[K in keyof T]: InferSchema<T[K]>;
|
|
125
|
+
};
|
|
126
|
+
type InferQueueComplete<T> = T extends QueueTypeToken<unknown, infer C, any> ? [C] extends [never] ? never : C : T extends QueueSchemaDefinition<any> ? T["complete"] extends PrimitiveSchema ? InferSchema<T["complete"]> : never : never;
|
|
127
|
+
type InferQueueCompleteMap<T extends QueueSchemaConfig> = {
|
|
128
|
+
[K in keyof T]: InferQueueComplete<T[K]>;
|
|
129
|
+
};
|
|
130
|
+
type InferEventArgs<T> = T extends readonly unknown[] ? number extends T["length"] ? [T] : T : [T];
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* User-facing KV storage interface exposed on ActorContext.
|
|
134
|
+
*/
|
|
135
|
+
type KvValueType = "text" | "arrayBuffer" | "binary";
|
|
136
|
+
type KvKeyType = "text" | "binary";
|
|
137
|
+
type KvKey = Uint8Array | string;
|
|
138
|
+
type KvValueTypeMap = {
|
|
139
|
+
text: string;
|
|
140
|
+
arrayBuffer: ArrayBuffer;
|
|
141
|
+
binary: Uint8Array;
|
|
142
|
+
};
|
|
143
|
+
type KvKeyTypeMap = {
|
|
144
|
+
text: string;
|
|
145
|
+
binary: Uint8Array;
|
|
146
|
+
};
|
|
147
|
+
type KvValueOptions<T extends KvValueType = "text"> = {
|
|
148
|
+
type?: T;
|
|
149
|
+
};
|
|
150
|
+
type KvListOptions<T extends KvValueType = "text", K extends KvKeyType = "text"> = KvValueOptions<T> & {
|
|
151
|
+
keyType?: K;
|
|
152
|
+
};
|
|
153
|
+
declare class ActorKv {
|
|
154
|
+
#private;
|
|
155
|
+
constructor(driver: ActorDriver, actorId: string);
|
|
42
156
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* This lives on the driver because the base endpoint varies by runtime.
|
|
157
|
+
* Get a single value by key.
|
|
46
158
|
*/
|
|
47
|
-
|
|
48
|
-
displayInformation(): ManagerDisplayInformation;
|
|
49
|
-
extraStartupLog?: () => Record<string, unknown>;
|
|
50
|
-
modifyManagerRouter?: (config: RegistryConfig, router: Hono) => void;
|
|
159
|
+
get<T extends KvValueType = "text">(key: KvKey, options?: KvValueOptions<T>): Promise<KvValueTypeMap[T] | null>;
|
|
51
160
|
/**
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
161
|
+
* Get multiple values by keys.
|
|
162
|
+
*/
|
|
163
|
+
getBatch<T extends KvValueType = "text">(keys: KvKey[], options?: KvValueOptions<T>): Promise<(KvValueTypeMap[T] | null)[]>;
|
|
164
|
+
/**
|
|
165
|
+
* Put a single key-value pair.
|
|
166
|
+
*/
|
|
167
|
+
put<T extends KvValueType = KvValueType>(key: KvKey, value: KvValueTypeMap[T], options?: KvValueOptions<T>): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Put multiple key-value pairs.
|
|
170
|
+
*/
|
|
171
|
+
putBatch<T extends KvValueType = KvValueType>(entries: [KvKey, KvValueTypeMap[T]][], options?: KvValueOptions<T>): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Delete a single key.
|
|
174
|
+
*/
|
|
175
|
+
delete(key: KvKey): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Delete multiple keys.
|
|
178
|
+
*/
|
|
179
|
+
deleteBatch(keys: KvKey[]): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* List all keys with a given prefix.
|
|
182
|
+
* Returns key-value pairs where keys have the user prefix removed.
|
|
183
|
+
*/
|
|
184
|
+
list<T extends KvValueType = "text", K extends KvKeyType = "text">(prefix: KvKeyTypeMap[K], options?: KvListOptions<T, K>): Promise<[KvKeyTypeMap[K], KvValueTypeMap[T]][]>;
|
|
66
185
|
}
|
|
67
|
-
|
|
68
|
-
|
|
186
|
+
|
|
187
|
+
interface QueueMessage {
|
|
188
|
+
id: bigint;
|
|
69
189
|
name: string;
|
|
70
|
-
|
|
190
|
+
body: unknown;
|
|
191
|
+
createdAt: number;
|
|
71
192
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
193
|
+
declare class QueueManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
194
|
+
#private;
|
|
195
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>, driver: ActorDriver);
|
|
196
|
+
/** Returns the current number of messages in the queue. */
|
|
197
|
+
get size(): number;
|
|
198
|
+
/** Loads queue metadata from storage and initializes internal state. */
|
|
199
|
+
initialize(): Promise<void>;
|
|
200
|
+
/** Adds a message to the queue with the given name and body. */
|
|
201
|
+
enqueue(name: string, body: unknown): Promise<QueueMessage>;
|
|
202
|
+
/**
|
|
203
|
+
* Adds a message and waits for completion.
|
|
204
|
+
*/
|
|
205
|
+
enqueueAndWait(name: string, body: unknown, timeout?: number): Promise<{
|
|
206
|
+
status: "completed" | "timedOut";
|
|
207
|
+
response?: unknown;
|
|
208
|
+
}>;
|
|
209
|
+
completeMessage(message: QueueMessage, response?: unknown): Promise<void>;
|
|
210
|
+
completeMessageById(messageId: bigint, response?: unknown): Promise<void>;
|
|
211
|
+
/** Receives messages from the queue matching the given names. Waits until messages are available or timeout is reached. */
|
|
212
|
+
receive(names: string[] | undefined, count: number, timeout?: number, abortSignal?: AbortSignal, completable?: boolean): Promise<QueueMessage[]>;
|
|
213
|
+
waitForNames(names: readonly string[] | undefined, abortSignal?: AbortSignal): Promise<void>;
|
|
214
|
+
/** Returns all messages currently in the queue without removing them. */
|
|
215
|
+
getMessages(): Promise<QueueMessage[]>;
|
|
216
|
+
/** Deletes messages matching the provided IDs. Returns the IDs that were removed. */
|
|
217
|
+
deleteMessagesById(ids: bigint[]): Promise<bigint[]>;
|
|
78
218
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
name:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
219
|
+
|
|
220
|
+
type QueueMessageOf<Name extends string, Body> = Omit<QueueMessage, "name" | "body"> & {
|
|
221
|
+
name: Name;
|
|
222
|
+
body: Body;
|
|
223
|
+
};
|
|
224
|
+
type QueueName<TQueues extends QueueSchemaConfig> = keyof TQueues & string;
|
|
225
|
+
type QueueFilterName<TQueues extends QueueSchemaConfig> = keyof TQueues extends never ? string : QueueName<TQueues>;
|
|
226
|
+
type QueueMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? QueueMessage : TName extends QueueName<TQueues> ? QueueMessageOf<TName, InferSchemaMap<TQueues>[TName]> : never;
|
|
227
|
+
type QueueCompleteArgs<T> = undefined extends T ? [response?: T] : [response: T];
|
|
228
|
+
type QueueCompleteArgsForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = keyof TQueues extends never ? [response?: unknown] : TName extends QueueName<TQueues> ? [InferQueueCompleteMap<TQueues>[TName]] extends [never] ? [response?: unknown] : QueueCompleteArgs<InferQueueCompleteMap<TQueues>[TName]> : [response?: unknown];
|
|
229
|
+
type QueueCompletableMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>> = QueueMessageForName<TQueues, TName> & {
|
|
230
|
+
complete(...args: QueueCompleteArgsForName<TQueues, TName>): Promise<void>;
|
|
231
|
+
};
|
|
232
|
+
type QueueResultMessageForName<TQueues extends QueueSchemaConfig, TName extends QueueFilterName<TQueues>, TCompletable extends boolean> = TCompletable extends true ? QueueCompletableMessageForName<TQueues, TName> : QueueMessageForName<TQueues, TName>;
|
|
233
|
+
/** Options for receiving queue messages. */
|
|
234
|
+
interface QueueNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
235
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
236
|
+
names?: readonly TName[];
|
|
237
|
+
/** Maximum number of messages to receive. Defaults to 1. */
|
|
238
|
+
count?: number;
|
|
239
|
+
/** Timeout in milliseconds. Omit to wait indefinitely. */
|
|
240
|
+
timeout?: number;
|
|
241
|
+
/** Optional abort signal for this receive call. */
|
|
242
|
+
signal?: AbortSignal;
|
|
243
|
+
/** Whether to return completable messages. */
|
|
244
|
+
completable?: TCompletable;
|
|
245
|
+
}
|
|
246
|
+
/** Options for non-blocking queue reads. */
|
|
247
|
+
interface QueueTryNextOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
248
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
249
|
+
names?: readonly TName[];
|
|
250
|
+
/** Maximum number of messages to receive. Defaults to 1. */
|
|
251
|
+
count?: number;
|
|
252
|
+
/** Whether to return completable messages. */
|
|
253
|
+
completable?: TCompletable;
|
|
254
|
+
}
|
|
255
|
+
/** Options for queue async iteration. */
|
|
256
|
+
interface QueueIterOptions<TName extends string = string, TCompletable extends boolean = boolean> {
|
|
257
|
+
/** Queue names to receive from. If omitted, reads from all queue names. */
|
|
258
|
+
names?: readonly TName[];
|
|
259
|
+
/** Optional abort signal for this iterator. */
|
|
260
|
+
signal?: AbortSignal;
|
|
261
|
+
/** Whether to return completable messages. */
|
|
262
|
+
completable?: TCompletable;
|
|
85
263
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
264
|
+
/** User-facing queue interface exposed on ActorContext. */
|
|
265
|
+
declare class ActorQueue<S, CP, CS, V, I, DB extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
|
|
266
|
+
#private;
|
|
267
|
+
constructor(queueManager: QueueManager<S, CP, CS, V, I, DB, TEvents, TQueues>, abortSignal: AbortSignal);
|
|
268
|
+
next<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueNextOptions<TName, TCompletable>): Promise<Array<QueueResultMessageForName<TQueues, TName, TCompletable>>>;
|
|
269
|
+
tryNext<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueTryNextOptions<TName, TCompletable>): Promise<Array<QueueResultMessageForName<TQueues, TName, TCompletable>>>;
|
|
270
|
+
iter<const TName extends QueueFilterName<TQueues>, const TCompletable extends boolean = false>(opts?: QueueIterOptions<TName, TCompletable>): AsyncIterableIterator<QueueResultMessageForName<TQueues, TName, TCompletable>>;
|
|
271
|
+
/** Sends a message to the specified queue. */
|
|
272
|
+
send<K extends keyof TQueues & string>(name: K, body: InferSchemaMap<TQueues>[K]): Promise<QueueMessage>;
|
|
273
|
+
send(name: keyof TQueues extends never ? string : never, body: unknown): Promise<QueueMessage>;
|
|
91
274
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
connectableTs?: number | null;
|
|
99
|
-
sleepTs?: number | null;
|
|
100
|
-
destroyTs?: number | null;
|
|
101
|
-
error?: unknown;
|
|
275
|
+
|
|
276
|
+
declare class Schedule {
|
|
277
|
+
#private;
|
|
278
|
+
constructor(actor: AnyActorInstance);
|
|
279
|
+
after(duration: number, fn: string, ...args: unknown[]): Promise<void>;
|
|
280
|
+
at(timestamp: number, fn: string, ...args: unknown[]): Promise<void>;
|
|
102
281
|
}
|
|
103
282
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/** Batch delete multiple keys. */
|
|
113
|
-
kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
|
|
114
|
-
/** List all keys with a given prefix. */
|
|
115
|
-
kvListPrefix(actorId: string, prefix: Uint8Array): Promise<[Uint8Array, Uint8Array][]>;
|
|
116
|
-
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
117
|
-
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
283
|
+
declare const ACTOR_CONTEXT_INTERNAL_SYMBOL: unique symbol;
|
|
284
|
+
/**
|
|
285
|
+
* ActorContext class that provides access to actor methods and state
|
|
286
|
+
*/
|
|
287
|
+
declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
|
|
288
|
+
#private;
|
|
289
|
+
[ACTOR_CONTEXT_INTERNAL_SYMBOL]: AnyActorInstance;
|
|
290
|
+
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>);
|
|
118
291
|
/**
|
|
119
|
-
*
|
|
120
|
-
* This is an experimental API that may change in the future.
|
|
292
|
+
* Gets the KV storage interface.
|
|
121
293
|
*/
|
|
122
|
-
|
|
294
|
+
get kv(): ActorKv;
|
|
123
295
|
/**
|
|
124
|
-
*
|
|
296
|
+
* Get the actor state
|
|
125
297
|
*
|
|
126
|
-
*
|
|
298
|
+
* @remarks
|
|
299
|
+
* This property is not available in `createState` since the state hasn't been created yet.
|
|
127
300
|
*/
|
|
128
|
-
|
|
301
|
+
get state(): TState extends never ? never : TState;
|
|
129
302
|
/**
|
|
130
|
-
*
|
|
303
|
+
* Get the actor variables
|
|
131
304
|
*
|
|
132
|
-
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* This property is not available in `createVars` since the variables haven't been created yet.
|
|
307
|
+
* Variables are only available if you define `vars` or `createVars` in your actor config.
|
|
133
308
|
*/
|
|
134
|
-
|
|
309
|
+
get vars(): TVars extends never ? never : TVars;
|
|
135
310
|
/**
|
|
136
|
-
*
|
|
311
|
+
* Broadcasts an event to all connected clients.
|
|
312
|
+
* @param name - The name of the event.
|
|
313
|
+
* @param args - The arguments to send with the event.
|
|
137
314
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
token: () => string;
|
|
233
|
-
defaultEndpoint?: string | undefined;
|
|
234
|
-
} | {
|
|
235
|
-
enabled: {
|
|
236
|
-
manager: boolean;
|
|
237
|
-
actor: boolean;
|
|
238
|
-
};
|
|
239
|
-
token: () => string;
|
|
240
|
-
defaultEndpoint?: string | undefined;
|
|
241
|
-
};
|
|
242
|
-
serverless: {
|
|
243
|
-
publicEndpoint: string | undefined;
|
|
244
|
-
spawnEngine: boolean;
|
|
245
|
-
engineVersion: string;
|
|
246
|
-
basePath: string;
|
|
247
|
-
publicToken: string | undefined;
|
|
248
|
-
configureRunnerPool?: {
|
|
249
|
-
url: string;
|
|
250
|
-
name?: string | undefined;
|
|
251
|
-
headers?: Record<string, string> | undefined;
|
|
252
|
-
maxRunners?: number | undefined;
|
|
253
|
-
minRunners?: number | undefined;
|
|
254
|
-
requestLifespan?: number | undefined;
|
|
255
|
-
runnersMargin?: number | undefined;
|
|
256
|
-
slotsPerRunner?: number | undefined;
|
|
257
|
-
metadata?: Record<string, unknown> | undefined;
|
|
258
|
-
metadataPollInterval?: number | undefined;
|
|
259
|
-
drainOnVersionUpgrade?: boolean | undefined;
|
|
260
|
-
} | undefined;
|
|
261
|
-
};
|
|
262
|
-
use: Record<string, AnyActorDefinition>;
|
|
263
|
-
test: {
|
|
264
|
-
enabled: boolean;
|
|
265
|
-
};
|
|
266
|
-
maxIncomingMessageSize: number;
|
|
267
|
-
maxOutgoingMessageSize: number;
|
|
268
|
-
noWelcome: boolean;
|
|
269
|
-
logging: {
|
|
270
|
-
baseLogger?: Logger | undefined;
|
|
271
|
-
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
272
|
-
};
|
|
273
|
-
headers: Record<string, string>;
|
|
274
|
-
managerBasePath: string;
|
|
275
|
-
managerPort: number;
|
|
276
|
-
runner: {
|
|
277
|
-
totalSlots: number;
|
|
278
|
-
runnerName: string;
|
|
279
|
-
runnerKey: string | undefined;
|
|
280
|
-
version: number;
|
|
281
|
-
};
|
|
282
|
-
driver?: {
|
|
283
|
-
name: string;
|
|
284
|
-
displayName: string;
|
|
285
|
-
manager: ManagerDriverBuilder;
|
|
286
|
-
actor: ActorDriverBuilder;
|
|
287
|
-
autoStartActorDriver: boolean;
|
|
288
|
-
} | undefined;
|
|
289
|
-
managerHost?: string | undefined;
|
|
290
|
-
}, {
|
|
291
|
-
use: Record<string, AnyActorDefinition>;
|
|
292
|
-
test: {
|
|
293
|
-
enabled: boolean;
|
|
294
|
-
};
|
|
295
|
-
maxIncomingMessageSize: number;
|
|
296
|
-
maxOutgoingMessageSize: number;
|
|
297
|
-
noWelcome: boolean;
|
|
298
|
-
logging: {
|
|
299
|
-
baseLogger?: Logger | undefined;
|
|
300
|
-
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
301
|
-
};
|
|
302
|
-
endpoint: string | undefined;
|
|
303
|
-
token: string | undefined;
|
|
304
|
-
namespace: string | undefined;
|
|
305
|
-
headers: Record<string, string>;
|
|
306
|
-
managerBasePath: string;
|
|
307
|
-
managerPort: number;
|
|
308
|
-
inspector: {
|
|
309
|
-
enabled: boolean;
|
|
310
|
-
token: () => string;
|
|
311
|
-
defaultEndpoint?: string | undefined;
|
|
312
|
-
};
|
|
313
|
-
serverless: {
|
|
314
|
-
spawnEngine: boolean;
|
|
315
|
-
engineVersion: string;
|
|
316
|
-
basePath: string;
|
|
317
|
-
publicEndpoint: string | undefined;
|
|
318
|
-
publicToken: string | undefined;
|
|
319
|
-
configureRunnerPool?: {
|
|
320
|
-
url: string;
|
|
321
|
-
name?: string | undefined;
|
|
322
|
-
headers?: Record<string, string> | undefined;
|
|
323
|
-
maxRunners?: number | undefined;
|
|
324
|
-
minRunners?: number | undefined;
|
|
325
|
-
requestLifespan?: number | undefined;
|
|
326
|
-
runnersMargin?: number | undefined;
|
|
327
|
-
slotsPerRunner?: number | undefined;
|
|
328
|
-
metadata?: Record<string, unknown> | undefined;
|
|
329
|
-
metadataPollInterval?: number | undefined;
|
|
330
|
-
drainOnVersionUpgrade?: boolean | undefined;
|
|
331
|
-
} | undefined;
|
|
332
|
-
};
|
|
333
|
-
runner: {
|
|
334
|
-
totalSlots: number;
|
|
335
|
-
runnerName: string;
|
|
336
|
-
runnerKey: string | undefined;
|
|
337
|
-
version: number;
|
|
338
|
-
};
|
|
339
|
-
driver?: {
|
|
340
|
-
name: string;
|
|
341
|
-
displayName: string;
|
|
342
|
-
manager: ManagerDriverBuilder;
|
|
343
|
-
actor: ActorDriverBuilder;
|
|
344
|
-
autoStartActorDriver: boolean;
|
|
345
|
-
} | undefined;
|
|
346
|
-
serveManager?: boolean | undefined;
|
|
347
|
-
managerHost?: string | undefined;
|
|
348
|
-
}>>;
|
|
349
|
-
type RegistryConfig = z.infer<typeof RegistryConfigSchema>;
|
|
350
|
-
type RegistryConfigInput<A extends RegistryActors> = Omit<z.input<typeof RegistryConfigSchema>, "use"> & {
|
|
351
|
-
use: A;
|
|
352
|
-
};
|
|
353
|
-
declare function buildActorNames(config: RegistryConfig): Record<string, {
|
|
354
|
-
metadata: Record<string, any>;
|
|
355
|
-
}>;
|
|
356
|
-
declare const DocInspectorConfigSchema: z.ZodOptional<z.ZodObject<{
|
|
357
|
-
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
358
|
-
token: z.ZodOptional<z.ZodString>;
|
|
359
|
-
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
360
|
-
}, z.core.$strip>>;
|
|
361
|
-
declare const DocConfigureRunnerPoolSchema: z.ZodOptional<z.ZodObject<{
|
|
362
|
-
name: z.ZodOptional<z.ZodString>;
|
|
363
|
-
url: z.ZodString;
|
|
364
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
365
|
-
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
366
|
-
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
367
|
-
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
368
|
-
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
369
|
-
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
370
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
371
|
-
metadataPollInterval: z.ZodOptional<z.ZodNumber>;
|
|
372
|
-
}, z.core.$strip>>;
|
|
373
|
-
declare const DocServerlessConfigSchema: z.ZodObject<{
|
|
374
|
-
spawnEngine: z.ZodOptional<z.ZodBoolean>;
|
|
375
|
-
engineVersion: z.ZodOptional<z.ZodString>;
|
|
376
|
-
configureRunnerPool: z.ZodOptional<z.ZodObject<{
|
|
377
|
-
name: z.ZodOptional<z.ZodString>;
|
|
378
|
-
url: z.ZodString;
|
|
379
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
380
|
-
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
381
|
-
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
382
|
-
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
383
|
-
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
384
|
-
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
385
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
386
|
-
metadataPollInterval: z.ZodOptional<z.ZodNumber>;
|
|
387
|
-
}, z.core.$strip>>;
|
|
388
|
-
basePath: z.ZodOptional<z.ZodString>;
|
|
389
|
-
publicEndpoint: z.ZodOptional<z.ZodString>;
|
|
390
|
-
publicToken: z.ZodOptional<z.ZodString>;
|
|
391
|
-
}, z.core.$strip>;
|
|
392
|
-
declare const DocRunnerConfigSchema: z.ZodObject<{
|
|
393
|
-
totalSlots: z.ZodOptional<z.ZodNumber>;
|
|
394
|
-
runnerName: z.ZodOptional<z.ZodString>;
|
|
395
|
-
runnerKey: z.ZodOptional<z.ZodString>;
|
|
396
|
-
version: z.ZodOptional<z.ZodNumber>;
|
|
397
|
-
}, z.core.$strip>;
|
|
398
|
-
declare const DocRegistryConfigSchema: z.ZodObject<{
|
|
399
|
-
use: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
400
|
-
maxIncomingMessageSize: z.ZodOptional<z.ZodNumber>;
|
|
401
|
-
maxOutgoingMessageSize: z.ZodOptional<z.ZodNumber>;
|
|
402
|
-
noWelcome: z.ZodOptional<z.ZodBoolean>;
|
|
403
|
-
logging: z.ZodOptional<z.ZodObject<{
|
|
404
|
-
level: z.ZodOptional<z.ZodEnum<{
|
|
405
|
-
error: "error";
|
|
406
|
-
trace: "trace";
|
|
407
|
-
fatal: "fatal";
|
|
408
|
-
warn: "warn";
|
|
409
|
-
info: "info";
|
|
410
|
-
debug: "debug";
|
|
411
|
-
silent: "silent";
|
|
412
|
-
}>>;
|
|
413
|
-
}, z.core.$strip>>;
|
|
414
|
-
endpoint: z.ZodOptional<z.ZodString>;
|
|
415
|
-
token: z.ZodOptional<z.ZodString>;
|
|
416
|
-
namespace: z.ZodOptional<z.ZodString>;
|
|
417
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
418
|
-
serveManager: z.ZodOptional<z.ZodBoolean>;
|
|
419
|
-
managerBasePath: z.ZodOptional<z.ZodString>;
|
|
420
|
-
managerPort: z.ZodOptional<z.ZodNumber>;
|
|
421
|
-
inspector: z.ZodOptional<z.ZodObject<{
|
|
422
|
-
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
423
|
-
token: z.ZodOptional<z.ZodString>;
|
|
424
|
-
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
425
|
-
}, z.core.$strip>>;
|
|
426
|
-
serverless: z.ZodOptional<z.ZodObject<{
|
|
427
|
-
spawnEngine: z.ZodOptional<z.ZodBoolean>;
|
|
428
|
-
engineVersion: z.ZodOptional<z.ZodString>;
|
|
429
|
-
configureRunnerPool: z.ZodOptional<z.ZodObject<{
|
|
430
|
-
name: z.ZodOptional<z.ZodString>;
|
|
431
|
-
url: z.ZodString;
|
|
432
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
433
|
-
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
434
|
-
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
435
|
-
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
436
|
-
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
437
|
-
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
438
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
439
|
-
metadataPollInterval: z.ZodOptional<z.ZodNumber>;
|
|
440
|
-
}, z.core.$strip>>;
|
|
441
|
-
basePath: z.ZodOptional<z.ZodString>;
|
|
442
|
-
publicEndpoint: z.ZodOptional<z.ZodString>;
|
|
443
|
-
publicToken: z.ZodOptional<z.ZodString>;
|
|
444
|
-
}, z.core.$strip>>;
|
|
445
|
-
runner: z.ZodOptional<z.ZodObject<{
|
|
446
|
-
totalSlots: z.ZodOptional<z.ZodNumber>;
|
|
447
|
-
runnerName: z.ZodOptional<z.ZodString>;
|
|
448
|
-
runnerKey: z.ZodOptional<z.ZodString>;
|
|
449
|
-
version: z.ZodOptional<z.ZodNumber>;
|
|
450
|
-
}, z.core.$strip>>;
|
|
451
|
-
}, z.core.$strip>;
|
|
315
|
+
broadcast<K extends keyof TEvents & string>(name: K, ...args: InferEventArgs<InferSchemaMap<TEvents>[K]>): void;
|
|
316
|
+
broadcast(name: keyof TEvents extends never ? string : never, ...args: Array<unknown>): void;
|
|
317
|
+
/**
|
|
318
|
+
* Gets the logger instance.
|
|
319
|
+
*/
|
|
320
|
+
get log(): Logger;
|
|
321
|
+
/**
|
|
322
|
+
* Access to queue receive helpers.
|
|
323
|
+
*/
|
|
324
|
+
get queue(): ActorQueue<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
|
|
325
|
+
/**
|
|
326
|
+
* Gets actor ID.
|
|
327
|
+
*/
|
|
328
|
+
get actorId(): string;
|
|
329
|
+
/**
|
|
330
|
+
* Gets the actor name.
|
|
331
|
+
*/
|
|
332
|
+
get name(): string;
|
|
333
|
+
/**
|
|
334
|
+
* Gets the actor key.
|
|
335
|
+
*/
|
|
336
|
+
get key(): ActorKey;
|
|
337
|
+
/**
|
|
338
|
+
* Gets the region.
|
|
339
|
+
*/
|
|
340
|
+
get region(): string;
|
|
341
|
+
/**
|
|
342
|
+
* Gets the scheduler.
|
|
343
|
+
*/
|
|
344
|
+
get schedule(): Schedule;
|
|
345
|
+
/**
|
|
346
|
+
* Gets the map of connections.
|
|
347
|
+
*/
|
|
348
|
+
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>>;
|
|
349
|
+
/**
|
|
350
|
+
* Returns the client for the given registry.
|
|
351
|
+
*/
|
|
352
|
+
client<R extends Registry<any>>(): Client<R>;
|
|
353
|
+
/**
|
|
354
|
+
* Gets the database.
|
|
355
|
+
*
|
|
356
|
+
* @experimental
|
|
357
|
+
* @remarks
|
|
358
|
+
* This property is only available if you define a `db` provider in your actor config.
|
|
359
|
+
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
360
|
+
*/
|
|
361
|
+
get db(): TDatabase extends never ? never : InferDatabaseClient<TDatabase>;
|
|
362
|
+
/**
|
|
363
|
+
* Forces the state to get saved.
|
|
364
|
+
*
|
|
365
|
+
* @param opts - Options for saving the state.
|
|
366
|
+
*/
|
|
367
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
368
|
+
/**
|
|
369
|
+
* Prevents the actor from sleeping until promise is complete.
|
|
370
|
+
*/
|
|
371
|
+
waitUntil(promise: Promise<void>): void;
|
|
372
|
+
/**
|
|
373
|
+
* Prevents the actor from sleeping while the given promise is running.
|
|
374
|
+
*
|
|
375
|
+
* Use this when performing async operations in the `run` handler or other
|
|
376
|
+
* background contexts where you need to ensure the actor stays awake.
|
|
377
|
+
*
|
|
378
|
+
* Returns the resolved value and resets the sleep timer on completion.
|
|
379
|
+
* Errors are propagated to the caller.
|
|
380
|
+
*/
|
|
381
|
+
keepAwake<T>(promise: Promise<T>): Promise<T>;
|
|
382
|
+
/**
|
|
383
|
+
* AbortSignal that fires when the actor is stopping.
|
|
384
|
+
*/
|
|
385
|
+
get abortSignal(): AbortSignal;
|
|
386
|
+
/**
|
|
387
|
+
* True when the actor is stopping.
|
|
388
|
+
*
|
|
389
|
+
* Alias for `c.abortSignal.aborted`.
|
|
390
|
+
*/
|
|
391
|
+
get aborted(): boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Forces the actor to sleep.
|
|
394
|
+
*
|
|
395
|
+
* Not supported on all drivers.
|
|
396
|
+
*
|
|
397
|
+
* @experimental
|
|
398
|
+
*/
|
|
399
|
+
sleep(): void;
|
|
400
|
+
/**
|
|
401
|
+
* Forces the actor to destroy.
|
|
402
|
+
*
|
|
403
|
+
* This will return immediately, then call `onStop` and `onDestroy`.
|
|
404
|
+
*
|
|
405
|
+
* @experimental
|
|
406
|
+
*/
|
|
407
|
+
destroy(): void;
|
|
408
|
+
}
|
|
452
409
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Base context for connection-based handlers.
|
|
412
|
+
* Extends ActorContext with connection-specific functionality.
|
|
413
|
+
*/
|
|
414
|
+
declare abstract class ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
415
|
+
readonly conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
|
|
459
416
|
}
|
|
460
|
-
declare function lookupInRegistry(config: RegistryConfig, name: string): AnyActorDefinition;
|
|
461
417
|
|
|
462
|
-
/** Data that's been serialized. */
|
|
463
|
-
type OutputData = string | Uint8Array;
|
|
464
|
-
declare const EncodingSchema: z.ZodEnum<{
|
|
465
|
-
json: "json";
|
|
466
|
-
cbor: "cbor";
|
|
467
|
-
bare: "bare";
|
|
468
|
-
}>;
|
|
469
418
|
/**
|
|
470
|
-
*
|
|
419
|
+
* Context for a remote procedure call.
|
|
471
420
|
*/
|
|
472
|
-
|
|
421
|
+
declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
422
|
+
}
|
|
423
|
+
|
|
473
424
|
/**
|
|
474
|
-
*
|
|
425
|
+
* Base context for connection initialization handlers.
|
|
426
|
+
* Extends ActorContext with request-specific functionality for connection lifecycle events.
|
|
475
427
|
*/
|
|
476
|
-
declare class
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
428
|
+
declare abstract class ConnInitContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, never, never, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
429
|
+
/**
|
|
430
|
+
* The incoming request that initiated the connection.
|
|
431
|
+
* May be undefined for connections initiated without a direct HTTP request.
|
|
432
|
+
*/
|
|
433
|
+
readonly request: Request | undefined;
|
|
481
434
|
}
|
|
482
435
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}, z.core.$strip>>;
|
|
489
|
-
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
490
|
-
maxOutgoingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
491
|
-
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
492
|
-
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
493
|
-
token: z.ZodDefault<z.ZodOptional<z.ZodCustom<() => string, () => string>>>;
|
|
494
|
-
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
495
|
-
}, z.core.$strip>>>;
|
|
496
|
-
disableDefaultServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
497
|
-
defaultServerPort: z.ZodDefault<z.ZodNumber>;
|
|
498
|
-
runEngine: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
499
|
-
runEngineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
500
|
-
overrideServerAddress: z.ZodOptional<z.ZodString>;
|
|
501
|
-
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
502
|
-
runnerKind: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
503
|
-
serverless: "serverless";
|
|
504
|
-
normal: "normal";
|
|
505
|
-
}>>>;
|
|
506
|
-
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
507
|
-
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
508
|
-
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
509
|
-
baseLogger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
510
|
-
level: z.ZodOptional<z.ZodEnum<{
|
|
511
|
-
error: "error";
|
|
512
|
-
trace: "trace";
|
|
513
|
-
fatal: "fatal";
|
|
514
|
-
warn: "warn";
|
|
515
|
-
info: "info";
|
|
516
|
-
debug: "debug";
|
|
517
|
-
silent: "silent";
|
|
518
|
-
}>>;
|
|
519
|
-
}, z.core.$strip>>>;
|
|
520
|
-
autoConfigureServerless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
521
|
-
url: z.ZodOptional<z.ZodString>;
|
|
522
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
523
|
-
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
524
|
-
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
525
|
-
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
526
|
-
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
527
|
-
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
528
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
529
|
-
}, z.core.$strip>]>>;
|
|
530
|
-
endpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string, string | undefined>>;
|
|
531
|
-
token: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
532
|
-
namespace: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
533
|
-
runnerName: z.ZodDefault<z.ZodString>;
|
|
534
|
-
encoding: z.ZodDefault<z.ZodEnum<{
|
|
535
|
-
json: "json";
|
|
536
|
-
cbor: "cbor";
|
|
537
|
-
bare: "bare";
|
|
538
|
-
}>>;
|
|
539
|
-
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
540
|
-
getUpgradeWebSocket: z.ZodOptional<z.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
|
|
541
|
-
disableMetadataLookup: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
542
|
-
devtools: z.ZodDefault<z.ZodBoolean>;
|
|
543
|
-
runnerKey: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
544
|
-
totalSlots: z.ZodDefault<z.ZodNumber>;
|
|
545
|
-
}, z.core.$strip>, z.ZodTransform<{
|
|
546
|
-
runnerKey: string | undefined;
|
|
547
|
-
endpoint: string | undefined;
|
|
548
|
-
namespace: string;
|
|
549
|
-
token: string | undefined;
|
|
550
|
-
runnerName: string;
|
|
551
|
-
encoding: "json" | "cbor" | "bare";
|
|
552
|
-
headers: Record<string, string>;
|
|
553
|
-
disableMetadataLookup: boolean;
|
|
554
|
-
devtools: boolean;
|
|
555
|
-
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
556
|
-
maxIncomingMessageSize: number;
|
|
557
|
-
maxOutgoingMessageSize: number;
|
|
558
|
-
inspector: {
|
|
559
|
-
enabled: boolean;
|
|
560
|
-
token: () => string;
|
|
561
|
-
defaultEndpoint?: string | undefined;
|
|
562
|
-
};
|
|
563
|
-
disableDefaultServer: boolean;
|
|
564
|
-
defaultServerPort: number;
|
|
565
|
-
runEngine: boolean;
|
|
566
|
-
runEngineVersion: string;
|
|
567
|
-
disableActorDriver: boolean;
|
|
568
|
-
runnerKind: "serverless" | "normal";
|
|
569
|
-
basePath: string;
|
|
570
|
-
noWelcome: boolean;
|
|
571
|
-
logging: {
|
|
572
|
-
baseLogger?: Logger | undefined;
|
|
573
|
-
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
574
|
-
};
|
|
575
|
-
totalSlots: number;
|
|
576
|
-
driver?: {
|
|
577
|
-
name: string;
|
|
578
|
-
manager: ManagerDriverBuilder;
|
|
579
|
-
actor: ActorDriverBuilder;
|
|
580
|
-
} | undefined;
|
|
581
|
-
overrideServerAddress?: string | undefined;
|
|
582
|
-
autoConfigureServerless?: boolean | {
|
|
583
|
-
url?: string | undefined;
|
|
584
|
-
headers?: Record<string, string> | undefined;
|
|
585
|
-
maxRunners?: number | undefined;
|
|
586
|
-
minRunners?: number | undefined;
|
|
587
|
-
requestLifespan?: number | undefined;
|
|
588
|
-
runnersMargin?: number | undefined;
|
|
589
|
-
slotsPerRunner?: number | undefined;
|
|
590
|
-
metadata?: Record<string, unknown> | undefined;
|
|
591
|
-
} | undefined;
|
|
592
|
-
}, {
|
|
593
|
-
maxIncomingMessageSize: number;
|
|
594
|
-
maxOutgoingMessageSize: number;
|
|
595
|
-
inspector: {
|
|
596
|
-
enabled: boolean;
|
|
597
|
-
token: () => string;
|
|
598
|
-
defaultEndpoint?: string | undefined;
|
|
599
|
-
};
|
|
600
|
-
disableDefaultServer: boolean;
|
|
601
|
-
defaultServerPort: number;
|
|
602
|
-
runEngine: boolean;
|
|
603
|
-
runEngineVersion: string;
|
|
604
|
-
disableActorDriver: boolean;
|
|
605
|
-
runnerKind: "serverless" | "normal";
|
|
606
|
-
basePath: string;
|
|
607
|
-
noWelcome: boolean;
|
|
608
|
-
logging: {
|
|
609
|
-
baseLogger?: Logger | undefined;
|
|
610
|
-
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
611
|
-
};
|
|
612
|
-
endpoint: string;
|
|
613
|
-
token: string | undefined;
|
|
614
|
-
namespace: string | undefined;
|
|
615
|
-
runnerName: string;
|
|
616
|
-
encoding: "json" | "cbor" | "bare";
|
|
617
|
-
headers: Record<string, string>;
|
|
618
|
-
disableMetadataLookup: boolean;
|
|
619
|
-
devtools: boolean;
|
|
620
|
-
runnerKey: string | undefined;
|
|
621
|
-
totalSlots: number;
|
|
622
|
-
driver?: {
|
|
623
|
-
name: string;
|
|
624
|
-
manager: ManagerDriverBuilder;
|
|
625
|
-
actor: ActorDriverBuilder;
|
|
626
|
-
} | undefined;
|
|
627
|
-
overrideServerAddress?: string | undefined;
|
|
628
|
-
autoConfigureServerless?: boolean | {
|
|
629
|
-
url?: string | undefined;
|
|
630
|
-
headers?: Record<string, string> | undefined;
|
|
631
|
-
maxRunners?: number | undefined;
|
|
632
|
-
minRunners?: number | undefined;
|
|
633
|
-
requestLifespan?: number | undefined;
|
|
634
|
-
runnersMargin?: number | undefined;
|
|
635
|
-
slotsPerRunner?: number | undefined;
|
|
636
|
-
metadata?: Record<string, unknown> | undefined;
|
|
637
|
-
} | undefined;
|
|
638
|
-
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
639
|
-
}>>>;
|
|
640
|
-
type LegacyRunnerConfigInput = z.input<typeof LegacyRunnerConfigSchema>;
|
|
436
|
+
/**
|
|
437
|
+
* Context for the onBeforeActionResponse lifecycle hook.
|
|
438
|
+
*/
|
|
439
|
+
declare class BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
440
|
+
}
|
|
641
441
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
442
|
+
/**
|
|
443
|
+
* Context for the onBeforeConnect lifecycle hook.
|
|
444
|
+
*/
|
|
445
|
+
declare class BeforeConnectContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnInitContext<TState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
645
446
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Context for the onConnect lifecycle hook.
|
|
450
|
+
*/
|
|
451
|
+
declare class ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
651
452
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Context for the onCreate lifecycle hook.
|
|
456
|
+
*/
|
|
457
|
+
declare class CreateContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, never, never, never, TInput, TDatabase, TEvents, TQueues> {
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Context for the createConnState lifecycle hook.
|
|
462
|
+
* Called to initialize connection-specific state when a connection is created.
|
|
463
|
+
*/
|
|
464
|
+
declare class CreateConnStateContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnInitContext<TState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Context for the createVars lifecycle hook.
|
|
469
|
+
*/
|
|
470
|
+
declare class CreateVarsContext<TState, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, never, never, never, TInput, TDatabase, TEvents, TQueues> {
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Context for the onDestroy lifecycle hook.
|
|
475
|
+
*/
|
|
476
|
+
declare class DestroyContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Context for the onDisconnect lifecycle hook.
|
|
481
|
+
*/
|
|
482
|
+
declare class DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Context for raw HTTP request handlers (onRequest).
|
|
487
|
+
*/
|
|
488
|
+
declare class RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
677
489
|
/**
|
|
678
|
-
*
|
|
490
|
+
* The incoming HTTP request.
|
|
491
|
+
* May be undefined for request contexts initiated without a direct HTTP request.
|
|
679
492
|
*/
|
|
680
|
-
|
|
493
|
+
readonly request: Request | undefined;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Context for the run lifecycle hook.
|
|
498
|
+
*
|
|
499
|
+
* This context is passed to the `run` handler which executes after the actor
|
|
500
|
+
* starts. It does not block actor startup and is intended for background tasks.
|
|
501
|
+
*
|
|
502
|
+
* Use `c.aborted` to detect when the actor is stopping and gracefully exit.
|
|
503
|
+
*/
|
|
504
|
+
declare class RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Context for the onSleep lifecycle hook.
|
|
509
|
+
*/
|
|
510
|
+
declare class SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Context for the onStateChange lifecycle hook.
|
|
515
|
+
*/
|
|
516
|
+
declare class StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Context for the onWake lifecycle hook.
|
|
521
|
+
*/
|
|
522
|
+
declare class WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Context for raw WebSocket handlers (onWebSocket).
|
|
527
|
+
*/
|
|
528
|
+
declare class WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> {
|
|
681
529
|
/**
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
* @deprecated Use {@link Registry.startRunner} for long-running servers or {@link Registry.handler} for serverless deployments.
|
|
530
|
+
* The incoming HTTP request that initiated the WebSocket upgrade.
|
|
531
|
+
* May be undefined for WebSocket connections initiated without a direct HTTP request.
|
|
685
532
|
*/
|
|
686
|
-
|
|
533
|
+
readonly request: Request | undefined;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Data that's been serialized. */
|
|
537
|
+
type OutputData = string | Uint8Array;
|
|
538
|
+
declare const EncodingSchema: z.ZodEnum<{
|
|
539
|
+
json: "json";
|
|
540
|
+
cbor: "cbor";
|
|
541
|
+
bare: "bare";
|
|
542
|
+
}>;
|
|
543
|
+
/**
|
|
544
|
+
* Encoding used to communicate between the client & actor.
|
|
545
|
+
*/
|
|
546
|
+
type Encoding = z.infer<typeof EncodingSchema>;
|
|
547
|
+
/**
|
|
548
|
+
* Helper class that helps serialize data without re-serializing for the same encoding.
|
|
549
|
+
*/
|
|
550
|
+
declare class CachedSerializer<TBare, TJson, T = TBare> {
|
|
551
|
+
#private;
|
|
552
|
+
constructor(data: T, versionedDataHandler: VersionedDataHandler<TBare>, version: number, zodSchema: z.ZodType<TJson>, toJson: (value: T) => TJson, toBare: (value: T) => TBare);
|
|
553
|
+
get rawData(): T;
|
|
554
|
+
serialize(encoding: Encoding): OutputData;
|
|
687
555
|
}
|
|
688
|
-
|
|
556
|
+
|
|
557
|
+
type UpgradeWebSocket = (createEvents: (c: Context) => any) => Handler;
|
|
558
|
+
type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
559
|
+
|
|
560
|
+
declare const KEYS: {
|
|
561
|
+
PERSIST_DATA: Uint8Array<ArrayBuffer>;
|
|
562
|
+
CONN_PREFIX: Uint8Array<ArrayBuffer>;
|
|
563
|
+
INSPECTOR_TOKEN: Uint8Array<ArrayBuffer>;
|
|
564
|
+
KV: Uint8Array<ArrayBuffer>;
|
|
565
|
+
QUEUE_PREFIX: Uint8Array<ArrayBuffer>;
|
|
566
|
+
WORKFLOW_PREFIX: Uint8Array<ArrayBuffer>;
|
|
567
|
+
TRACES_PREFIX: Uint8Array<ArrayBuffer>;
|
|
568
|
+
SQLITE_PREFIX: Uint8Array<ArrayBuffer>;
|
|
569
|
+
};
|
|
689
570
|
|
|
690
571
|
declare const ActorKeySchema: z.ZodArray<z.ZodString>;
|
|
691
572
|
type ActorKey = z.infer<typeof ActorKeySchema>;
|
|
@@ -726,1523 +607,1859 @@ type ActorQuery = z.infer<typeof ActorQuerySchema>;
|
|
|
726
607
|
*/
|
|
727
608
|
type CreateRequest = z.infer<typeof CreateRequestSchema>;
|
|
728
609
|
|
|
610
|
+
interface ActorInspectorEmitterEvents {
|
|
611
|
+
stateUpdated: (state: unknown) => void;
|
|
612
|
+
connectionsUpdated: () => void;
|
|
613
|
+
queueUpdated: () => void;
|
|
614
|
+
workflowHistoryUpdated: (history: WorkflowHistory) => void;
|
|
615
|
+
}
|
|
729
616
|
/**
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
* @typedef {Function} ActorActionFunction
|
|
733
|
-
* @template Args
|
|
734
|
-
* @template Response
|
|
735
|
-
* @param {...Args} args - Arguments for the action function.
|
|
736
|
-
* @returns {Promise<Response>}
|
|
737
|
-
*/
|
|
738
|
-
type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
|
|
739
|
-
/**
|
|
740
|
-
* Maps action methods from actor definition to typed function signatures.
|
|
617
|
+
* Provides a unified interface for inspecting actor external and internal state.
|
|
741
618
|
*/
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
619
|
+
declare class ActorInspector {
|
|
620
|
+
#private;
|
|
621
|
+
private readonly actor;
|
|
622
|
+
readonly emitter: nanoevents.Emitter<ActorInspectorEmitterEvents>;
|
|
623
|
+
constructor(actor: AnyActorInstance);
|
|
624
|
+
getQueueSize(): number;
|
|
625
|
+
getQueueStatus(limit: number): Promise<QueueStatus>;
|
|
626
|
+
updateQueueSize(size: number): void;
|
|
627
|
+
isWorkflowEnabled(): boolean;
|
|
628
|
+
getWorkflowHistory(): WorkflowHistory | null;
|
|
629
|
+
isDatabaseEnabled(): boolean;
|
|
630
|
+
getDatabaseSchema(): Promise<ArrayBuffer>;
|
|
631
|
+
getDatabaseTableRows(table: string, limit: number, offset: number): Promise<ArrayBuffer>;
|
|
632
|
+
isStateEnabled(): boolean;
|
|
633
|
+
getState(): ArrayBuffer;
|
|
634
|
+
getRpcs(): string[];
|
|
635
|
+
getConnections(): {
|
|
636
|
+
type: string | undefined;
|
|
637
|
+
id: string;
|
|
638
|
+
details: ArrayBuffer;
|
|
639
|
+
}[];
|
|
640
|
+
setState(state: ArrayBuffer): Promise<void>;
|
|
641
|
+
executeAction(name: string, params: ArrayBuffer): Promise<ArrayBuffer>;
|
|
642
|
+
getStateJson(): unknown;
|
|
643
|
+
setStateJson(state: unknown): Promise<void>;
|
|
644
|
+
getConnectionsJson(): {
|
|
645
|
+
id: string;
|
|
646
|
+
details: unknown;
|
|
647
|
+
}[];
|
|
648
|
+
executeActionJson(name: string, args: unknown[]): Promise<unknown>;
|
|
649
|
+
getTracesJson(options: {
|
|
650
|
+
startMs: number;
|
|
651
|
+
endMs: number;
|
|
652
|
+
limit: number;
|
|
653
|
+
}): Promise<{
|
|
654
|
+
otlp: unknown;
|
|
655
|
+
clamped: boolean;
|
|
656
|
+
}>;
|
|
657
|
+
getWorkflowHistoryJson(): {
|
|
658
|
+
history: unknown | null;
|
|
659
|
+
isWorkflowEnabled: boolean;
|
|
660
|
+
};
|
|
661
|
+
getQueueStatusJson(limit: number): Promise<{
|
|
662
|
+
size: number;
|
|
663
|
+
maxSize: number;
|
|
664
|
+
truncated: boolean;
|
|
665
|
+
messages: {
|
|
666
|
+
id: number;
|
|
667
|
+
name: string;
|
|
668
|
+
createdAtMs: number;
|
|
669
|
+
}[];
|
|
670
|
+
}>;
|
|
755
671
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
672
|
+
|
|
673
|
+
declare enum DriverReadyState {
|
|
674
|
+
UNKNOWN = -1,
|
|
675
|
+
CONNECTING = 0,
|
|
676
|
+
OPEN = 1,
|
|
677
|
+
CLOSING = 2,
|
|
678
|
+
CLOSED = 3
|
|
762
679
|
}
|
|
763
|
-
|
|
764
|
-
|
|
680
|
+
interface ConnDriver {
|
|
681
|
+
/** The type of driver. Used for debug purposes only. */
|
|
682
|
+
type: string;
|
|
683
|
+
/**
|
|
684
|
+
* If defined, this connection driver talks the RivetKit client driver (see
|
|
685
|
+
* schemas/client-protocol/).
|
|
686
|
+
*
|
|
687
|
+
* If enabled, events like `Init`, subscription events, etc. will be sent
|
|
688
|
+
* to this connection.
|
|
689
|
+
*/
|
|
690
|
+
rivetKitProtocol?: {
|
|
691
|
+
/** Sends a RivetKit client message. */
|
|
692
|
+
sendMessage(actor: AnyActorInstance, conn: AnyConn, message: CachedSerializer<any, any, any>): void;
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* If the connection can be hibernated. If true, this will allow the actor to go to sleep while the connection is still active.
|
|
696
|
+
**/
|
|
697
|
+
hibernatable?: {
|
|
698
|
+
gatewayId: ArrayBuffer;
|
|
699
|
+
requestId: ArrayBuffer;
|
|
700
|
+
};
|
|
701
|
+
/**
|
|
702
|
+
* This returns a promise since we commonly disconnect at the end of a program, and not waiting will cause the socket to not close cleanly.
|
|
703
|
+
*/
|
|
704
|
+
disconnect(actor: AnyActorInstance, conn: AnyConn, reason?: string): Promise<void>;
|
|
705
|
+
/** Terminates the connection without graceful handling. */
|
|
706
|
+
terminate?(actor: AnyActorInstance, conn: AnyConn): void;
|
|
707
|
+
/**
|
|
708
|
+
* Returns the ready state of the connection.
|
|
709
|
+
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
|
|
710
|
+
*/
|
|
711
|
+
getConnectionReadyState(actor: AnyActorInstance, conn: AnyConn): DriverReadyState | undefined;
|
|
765
712
|
}
|
|
766
713
|
|
|
767
714
|
/**
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
* - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
|
|
771
|
-
* - `"connecting"`: Attempting to establish connection
|
|
772
|
-
* - `"connected"`: Connection is active
|
|
773
|
-
* - `"disconnected"`: Connection was lost, will auto-reconnect
|
|
774
|
-
*/
|
|
775
|
-
type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
|
|
776
|
-
/**
|
|
777
|
-
* A function that unsubscribes from an event.
|
|
778
|
-
*
|
|
779
|
-
* @typedef {Function} EventUnsubscribe
|
|
780
|
-
*/
|
|
781
|
-
type EventUnsubscribe = () => void;
|
|
782
|
-
/**
|
|
783
|
-
* A function that handles connection errors.
|
|
784
|
-
*
|
|
785
|
-
* @typedef {Function} ActorErrorCallback
|
|
786
|
-
*/
|
|
787
|
-
type ActorErrorCallback = (error: ActorError) => void;
|
|
788
|
-
/**
|
|
789
|
-
* A callback for connection state changes.
|
|
790
|
-
*
|
|
791
|
-
* @typedef {Function} ConnectionStateCallback
|
|
792
|
-
*/
|
|
793
|
-
type ConnectionStateCallback = () => void;
|
|
794
|
-
/**
|
|
795
|
-
* A callback for connection status changes.
|
|
715
|
+
* Persisted data structures for connections.
|
|
796
716
|
*
|
|
797
|
-
*
|
|
717
|
+
* Keep this file in sync with the Connection section of rivetkit-typescript/packages/rivetkit/schemas/actor-persist/
|
|
798
718
|
*/
|
|
799
|
-
|
|
800
|
-
|
|
719
|
+
|
|
720
|
+
type GatewayId = ArrayBuffer;
|
|
721
|
+
type RequestId = ArrayBuffer;
|
|
722
|
+
/** Event subscription for connection */
|
|
723
|
+
interface PersistedSubscription {
|
|
724
|
+
eventName: string;
|
|
725
|
+
}
|
|
726
|
+
/** Connection associated with hibernatable WebSocket that should persist across lifecycles */
|
|
727
|
+
interface PersistedConn<CP, CS> {
|
|
728
|
+
/** Connection ID generated by RivetKit */
|
|
729
|
+
id: string;
|
|
730
|
+
parameters: CP;
|
|
731
|
+
state: CS;
|
|
732
|
+
subscriptions: PersistedSubscription[];
|
|
733
|
+
gatewayId: GatewayId;
|
|
734
|
+
requestId: RequestId;
|
|
735
|
+
serverMessageIndex: number;
|
|
736
|
+
clientMessageIndex: number;
|
|
737
|
+
requestPath: string;
|
|
738
|
+
requestHeaders: Record<string, string>;
|
|
739
|
+
}
|
|
740
|
+
|
|
801
741
|
/**
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
* @see {@link ActorConn}
|
|
742
|
+
* Manages all connection-related operations for an actor instance.
|
|
743
|
+
* Handles connection creation, tracking, hibernation, and cleanup.
|
|
805
744
|
*/
|
|
806
|
-
declare class
|
|
745
|
+
declare class ConnectionManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
807
746
|
#private;
|
|
747
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>);
|
|
748
|
+
get connections(): Map<ConnId, Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
749
|
+
getConnForId(id: string): Conn<S, CP, CS, V, I, DB, E, Q> | undefined;
|
|
750
|
+
get connsWithPersistChanged(): Set<ConnId>;
|
|
751
|
+
get pendingDisconnectCount(): number;
|
|
752
|
+
clearConnWithPersistChanged(): void;
|
|
753
|
+
markConnWithPersistChanged(conn: Conn<S, CP, CS, V, I, DB, E, Q>): void;
|
|
808
754
|
/**
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
* Creates an instance of ActorConnRaw.
|
|
812
|
-
*
|
|
813
|
-
* @protected
|
|
755
|
+
* Handles pre-connection logic (i.e. auth & create state) before actually connecting the connection.
|
|
814
756
|
*/
|
|
815
|
-
|
|
757
|
+
prepareConn(driver: ConnDriver, params: CP, request: Request | undefined, requestPath: string | undefined, requestHeaders: Record<string, string> | undefined, isHibernatable: boolean, isRestoringHibernatable: boolean): Promise<Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
816
758
|
/**
|
|
817
|
-
*
|
|
759
|
+
* Adds a connection form prepareConn to the actor and calls onConnect.
|
|
818
760
|
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
* @param {...Args} args - The arguments to pass to the action function.
|
|
824
|
-
* @returns {Promise<Response>} - A promise that resolves to the response of the action function.
|
|
761
|
+
* This method is intentionally not async since it needs to be called in
|
|
762
|
+
* `onOpen` for WebSockets. If this is async, the order of open events will
|
|
763
|
+
* be messed up and cause race conditions that can drop WebSocket messages.
|
|
764
|
+
* So all async work in prepareConn.
|
|
825
765
|
*/
|
|
826
|
-
|
|
827
|
-
name: string;
|
|
828
|
-
args: Args;
|
|
829
|
-
signal?: AbortSignal;
|
|
830
|
-
}): Promise<Response>;
|
|
766
|
+
connectConn(conn: Conn<S, CP, CS, V, I, DB, E, Q>): void;
|
|
831
767
|
/**
|
|
832
|
-
*
|
|
833
|
-
enc
|
|
834
|
-
* Establishes a connection to the server using the specified endpoint & encoding & driver.
|
|
768
|
+
* Handle connection disconnection.
|
|
835
769
|
*
|
|
836
|
-
*
|
|
770
|
+
* This is called by `Conn.disconnect`. This should not call `Conn.disconnect.`
|
|
837
771
|
*/
|
|
838
|
-
|
|
772
|
+
connDisconnected(conn: Conn<S, CP, CS, V, I, DB, E, Q>): Promise<void>;
|
|
773
|
+
cleanupPersistedHibernatableConnections(reason?: string): Promise<number>;
|
|
839
774
|
/**
|
|
840
|
-
*
|
|
775
|
+
* Utilify function for call sites that don't need a separate prepare and connect phase.
|
|
776
|
+
*/
|
|
777
|
+
prepareAndConnectConn(driver: ConnDriver, params: CP, request: Request | undefined, requestPath: string | undefined, requestHeaders: Record<string, string> | undefined): Promise<Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
778
|
+
/**
|
|
779
|
+
* Restores connections from persisted data during actor initialization.
|
|
780
|
+
*/
|
|
781
|
+
restoreConnections(connections: PersistedConn<CP, CS>[]): void;
|
|
782
|
+
findHibernatableConn(gatewayIdBuf: ArrayBuffer, requestIdBuf: ArrayBuffer): Conn<S, CP, CS, V, I, DB, E, Q> | undefined;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Manages event subscriptions and broadcasting for actor instances.
|
|
787
|
+
* Handles subscription tracking and efficient message distribution to connected clients.
|
|
788
|
+
*/
|
|
789
|
+
declare class EventManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
790
|
+
#private;
|
|
791
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>);
|
|
792
|
+
/**
|
|
793
|
+
* Adds a subscription for a connection to an event.
|
|
841
794
|
*
|
|
842
|
-
* @
|
|
843
|
-
* @param
|
|
844
|
-
* @param
|
|
845
|
-
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
846
|
-
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
795
|
+
* @param eventName - The name of the event to subscribe to
|
|
796
|
+
* @param connection - The connection subscribing to the event
|
|
797
|
+
* @param fromPersist - Whether this subscription is being restored from persistence
|
|
847
798
|
*/
|
|
848
|
-
|
|
799
|
+
addSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB, E, Q>, fromPersist: boolean): void;
|
|
849
800
|
/**
|
|
850
|
-
*
|
|
801
|
+
* Removes a subscription for a connection from an event.
|
|
851
802
|
*
|
|
852
|
-
* @
|
|
853
|
-
* @param
|
|
854
|
-
* @param
|
|
855
|
-
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
856
|
-
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
803
|
+
* @param eventName - The name of the event to unsubscribe from
|
|
804
|
+
* @param connection - The connection unsubscribing from the event
|
|
805
|
+
* @param fromRemoveConn - Whether this is being called as part of connection removal
|
|
857
806
|
*/
|
|
858
|
-
|
|
807
|
+
removeSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB, E, Q>, fromRemoveConn: boolean): void;
|
|
859
808
|
/**
|
|
860
|
-
*
|
|
809
|
+
* Broadcasts an event to all subscribed connections.
|
|
861
810
|
*
|
|
862
|
-
* @param
|
|
863
|
-
* @
|
|
811
|
+
* @param name - The name of the event to broadcast
|
|
812
|
+
* @param args - The arguments to send with the event
|
|
864
813
|
*/
|
|
865
|
-
|
|
814
|
+
broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
866
815
|
/**
|
|
867
|
-
*
|
|
816
|
+
* Gets all subscribers for a specific event.
|
|
868
817
|
*
|
|
869
|
-
* @
|
|
818
|
+
* @param eventName - The name of the event
|
|
819
|
+
* @returns Set of connections subscribed to the event, or undefined if no subscribers
|
|
870
820
|
*/
|
|
871
|
-
|
|
821
|
+
getSubscribers(eventName: string): Set<Conn<S, CP, CS, V, I, DB, E, Q>> | undefined;
|
|
872
822
|
/**
|
|
873
|
-
*
|
|
823
|
+
* Gets all events and their subscriber counts.
|
|
874
824
|
*
|
|
875
|
-
* @
|
|
876
|
-
* @returns {boolean} - True if the connection is open, false otherwise.
|
|
825
|
+
* @returns Map of event names to subscriber counts
|
|
877
826
|
*/
|
|
878
|
-
|
|
827
|
+
getEventStats(): Map<string, number>;
|
|
879
828
|
/**
|
|
880
|
-
*
|
|
829
|
+
* Clears all subscriptions for a connection.
|
|
830
|
+
* Used during connection cleanup.
|
|
881
831
|
*
|
|
882
|
-
*
|
|
832
|
+
* @param connection - The connection to clear subscriptions for
|
|
833
|
+
*/
|
|
834
|
+
clearConnectionSubscriptions(connection: Conn<S, CP, CS, V, I, DB, E, Q>): void;
|
|
835
|
+
/**
|
|
836
|
+
* Gets the total number of unique events being subscribed to.
|
|
837
|
+
*/
|
|
838
|
+
get eventCount(): number;
|
|
839
|
+
/**
|
|
840
|
+
* Gets the total number of subscriptions across all events.
|
|
841
|
+
*/
|
|
842
|
+
get totalSubscriptionCount(): number;
|
|
843
|
+
/**
|
|
844
|
+
* Checks if an event has any subscribers.
|
|
883
845
|
*
|
|
884
|
-
* @param
|
|
885
|
-
* @returns
|
|
846
|
+
* @param eventName - The name of the event to check
|
|
847
|
+
* @returns True if the event has at least one subscriber
|
|
886
848
|
*/
|
|
887
|
-
|
|
849
|
+
hasSubscribers(eventName: string): boolean;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Persisted data structures for actors.
|
|
854
|
+
*
|
|
855
|
+
* Keep this file in sync with the Connection section of rivetkit-typescript/packages/rivetkit/schemas/actor-persist/
|
|
856
|
+
*/
|
|
857
|
+
|
|
858
|
+
type Cbor = ArrayBuffer;
|
|
859
|
+
/** Scheduled event to be executed at a specific timestamp */
|
|
860
|
+
interface PersistedScheduleEvent {
|
|
861
|
+
eventId: string;
|
|
862
|
+
timestamp: number;
|
|
863
|
+
action: string;
|
|
864
|
+
args?: Cbor;
|
|
865
|
+
}
|
|
866
|
+
/** State object that gets automatically persisted to storage */
|
|
867
|
+
interface PersistedActor<S, I> {
|
|
868
|
+
/** Input data passed to the actor on initialization */
|
|
869
|
+
input?: I;
|
|
870
|
+
hasInitialized: boolean;
|
|
871
|
+
state: S;
|
|
872
|
+
scheduledEvents: PersistedScheduleEvent[];
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
interface SaveStateOptions {
|
|
888
876
|
/**
|
|
889
|
-
*
|
|
877
|
+
* Forces the state to be saved immediately. This function will return when the state has saved successfully.
|
|
878
|
+
*/
|
|
879
|
+
immediate?: boolean;
|
|
880
|
+
/** Bypass ready check for stopping. */
|
|
881
|
+
allowStoppingState?: boolean;
|
|
882
|
+
/**
|
|
883
|
+
* Maximum time in milliseconds to wait before forcing a save.
|
|
890
884
|
*
|
|
891
|
-
*
|
|
892
|
-
|
|
885
|
+
* If a save is already scheduled to occur later than this deadline, it will be rescheduled earlier.
|
|
886
|
+
*/
|
|
887
|
+
maxWait?: number;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Manages actor state persistence, proxying, and synchronization.
|
|
891
|
+
* Handles automatic state change detection and throttled persistence to KV storage.
|
|
892
|
+
*/
|
|
893
|
+
declare class StateManager$1<S, CP, CS, I, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
894
|
+
#private;
|
|
895
|
+
constructor(actor: ActorInstance<S, CP, CS, any, I, any, E, Q>, actorDriver: ActorDriver, config: any);
|
|
896
|
+
get persist(): PersistedActor<S, I>;
|
|
897
|
+
get persistRaw(): PersistedActor<S, I>;
|
|
898
|
+
get persistChanged(): boolean;
|
|
899
|
+
get state(): S;
|
|
900
|
+
set state(value: S);
|
|
901
|
+
get stateEnabled(): boolean;
|
|
902
|
+
/**
|
|
903
|
+
* Initializes state from persisted data or creates new state.
|
|
904
|
+
*/
|
|
905
|
+
initializeState(persistData: PersistedActor<S, I>): Promise<void>;
|
|
906
|
+
/**
|
|
907
|
+
* Creates proxy for persist object that handles automatic state change detection.
|
|
908
|
+
*/
|
|
909
|
+
initPersistProxy(target: PersistedActor<S, I>): undefined;
|
|
910
|
+
/**
|
|
911
|
+
* Forces the state to get saved.
|
|
912
|
+
*/
|
|
913
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
914
|
+
/**
|
|
915
|
+
* Throttled save state method. Used to write to KV at a reasonable cadence.
|
|
893
916
|
*
|
|
894
|
-
*
|
|
895
|
-
*
|
|
917
|
+
* Passing a maxWait will override the stateSaveInterval with the min
|
|
918
|
+
* between that and the maxWait.
|
|
896
919
|
*/
|
|
897
|
-
|
|
920
|
+
savePersistThrottled(maxWait?: number): void;
|
|
921
|
+
/**
|
|
922
|
+
* Clears any pending save timeout.
|
|
923
|
+
*/
|
|
924
|
+
clearPendingSaveTimeout(): void;
|
|
925
|
+
/**
|
|
926
|
+
* Waits for any pending write operations to complete.
|
|
927
|
+
*/
|
|
928
|
+
waitForPendingWrites(): Promise<void>;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
932
|
+
type AnyActorInstance = ActorInstance<any, any, any, any, any, any, any, any>;
|
|
933
|
+
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
934
|
+
#private;
|
|
935
|
+
actorContext: ActorContext<S, CP, CS, V, I, DB, E, Q>;
|
|
936
|
+
driver: ActorDriver;
|
|
937
|
+
connectionManager: ConnectionManager<S, CP, CS, V, I, DB, E, Q>;
|
|
938
|
+
stateManager: StateManager$1<S, CP, CS, I, E, Q>;
|
|
939
|
+
eventManager: EventManager<S, CP, CS, V, I, DB, E, Q>;
|
|
940
|
+
queueManager: QueueManager<S, CP, CS, V, I, DB, E, Q>;
|
|
941
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
|
|
942
|
+
get log(): Logger;
|
|
943
|
+
get rLog(): Logger;
|
|
944
|
+
get isStopping(): boolean;
|
|
945
|
+
get id(): string;
|
|
946
|
+
get name(): string;
|
|
947
|
+
get key(): ActorKey;
|
|
948
|
+
get region(): string;
|
|
949
|
+
get inlineClient(): Client<Registry<any>>;
|
|
950
|
+
get inspector(): ActorInspector;
|
|
951
|
+
get traces(): Traces<OtlpExportTraceServiceRequestJson>;
|
|
952
|
+
get inspectorToken(): string | undefined;
|
|
953
|
+
getCurrentTraceSpan(): SpanHandle | null;
|
|
954
|
+
startTraceSpan(name: string, attributes?: Record<string, unknown>): SpanHandle;
|
|
955
|
+
endTraceSpan(handle: SpanHandle, status?: SpanStatusInput): void;
|
|
956
|
+
runInTraceSpan<T>(name: string, attributes: Record<string, unknown> | undefined, fn: () => T | Promise<T>): Promise<T>;
|
|
957
|
+
emitTraceEvent(name: string, attributes?: Record<string, unknown>, handle?: SpanHandle): void;
|
|
958
|
+
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB, E, Q>>;
|
|
959
|
+
get schedule(): Schedule;
|
|
960
|
+
get abortSignal(): AbortSignal;
|
|
961
|
+
get actions(): string[];
|
|
962
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
|
|
963
|
+
get persist(): PersistedActor<S, I>;
|
|
964
|
+
get state(): S;
|
|
965
|
+
set state(value: S);
|
|
966
|
+
get stateEnabled(): boolean;
|
|
967
|
+
get connStateEnabled(): boolean;
|
|
968
|
+
get vars(): V;
|
|
969
|
+
get db(): InferDatabaseClient<DB>;
|
|
970
|
+
start(actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
971
|
+
isReady(): boolean;
|
|
972
|
+
assertReady(allowStoppingState?: boolean): void;
|
|
973
|
+
cleanupPersistedConnections(reason?: string): Promise<number>;
|
|
974
|
+
onStop(mode: "sleep" | "destroy"): Promise<void>;
|
|
975
|
+
startSleep(): void;
|
|
976
|
+
startDestroy(): void;
|
|
977
|
+
beginHonoHttpRequest(): void;
|
|
978
|
+
endHonoHttpRequest(): void;
|
|
979
|
+
processMessage(message: {
|
|
980
|
+
body: {
|
|
981
|
+
tag: "ActionRequest";
|
|
982
|
+
val: {
|
|
983
|
+
id: bigint;
|
|
984
|
+
name: string;
|
|
985
|
+
args: unknown;
|
|
986
|
+
};
|
|
987
|
+
} | {
|
|
988
|
+
tag: "SubscriptionRequest";
|
|
989
|
+
val: {
|
|
990
|
+
eventName: string;
|
|
991
|
+
subscribe: boolean;
|
|
992
|
+
};
|
|
993
|
+
};
|
|
994
|
+
}, conn: Conn<S, CP, CS, V, I, DB, E, Q>): Promise<void>;
|
|
995
|
+
assertCanSubscribe(ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>, eventName: string): Promise<void>;
|
|
996
|
+
assertCanPublish(ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>, queueName: string): Promise<void>;
|
|
997
|
+
executeAction(ctx: ActionContext<S, CP, CS, V, I, DB, E, Q>, actionName: string, args: unknown[]): Promise<unknown>;
|
|
998
|
+
handleRawRequest(conn: Conn<S, CP, CS, V, I, DB, E, Q>, request: Request): Promise<Response>;
|
|
999
|
+
handleRawWebSocket(conn: Conn<S, CP, CS, V, I, DB, E, Q>, websocket: UniversalWebSocket, request?: Request): void;
|
|
1000
|
+
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
1001
|
+
onAlarm(): Promise<void>;
|
|
1002
|
+
waitUntil(promise: Promise<void>): void;
|
|
898
1003
|
/**
|
|
899
|
-
*
|
|
1004
|
+
* Prevents the actor from sleeping while the given promise is running.
|
|
900
1005
|
*
|
|
901
|
-
*
|
|
1006
|
+
* Use this when performing async operations in the `run` handler or other
|
|
1007
|
+
* background contexts where you need to ensure the actor stays awake.
|
|
902
1008
|
*
|
|
903
|
-
*
|
|
904
|
-
*
|
|
1009
|
+
* Returns the resolved value and resets the sleep timer on completion.
|
|
1010
|
+
* Errors are propagated to the caller.
|
|
905
1011
|
*/
|
|
906
|
-
|
|
1012
|
+
keepAwake<T>(promise: Promise<T>): Promise<T>;
|
|
1013
|
+
beginQueueWait(): void;
|
|
1014
|
+
endQueueWait(): void;
|
|
1015
|
+
resetSleepTimer(): void;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** Pick a subset of persisted data used to represent ephemeral connections */
|
|
1019
|
+
type EphemeralConn<CP, CS> = Pick<PersistedConn<CP, CS>, "id" | "parameters" | "state">;
|
|
1020
|
+
type ConnDataInput<CP, CS> = {
|
|
1021
|
+
ephemeral: EphemeralConn<CP, CS>;
|
|
1022
|
+
} | {
|
|
1023
|
+
hibernatable: PersistedConn<CP, CS>;
|
|
1024
|
+
};
|
|
1025
|
+
/**
|
|
1026
|
+
* Manages connection state persistence, proxying, and change tracking.
|
|
1027
|
+
* Handles automatic state change detection for connection-specific state.
|
|
1028
|
+
*/
|
|
1029
|
+
declare class StateManager<CP, CS> {
|
|
1030
|
+
#private;
|
|
1031
|
+
constructor(conn: Conn<any, CP, CS, any, any, any, any, any>, data: ConnDataInput<CP, CS>);
|
|
907
1032
|
/**
|
|
908
|
-
*
|
|
1033
|
+
* Returns the ephemeral or persisted data for this connectioned.
|
|
909
1034
|
*
|
|
910
|
-
*
|
|
1035
|
+
* This property is used to be able to treat both memory & persist conns
|
|
1036
|
+
* identical by looking up the correct underlying data structure.
|
|
911
1037
|
*/
|
|
912
|
-
|
|
1038
|
+
get ephemeralData(): EphemeralConn<CP, CS>;
|
|
1039
|
+
get hibernatableData(): PersistedConn<CP, CS> | undefined;
|
|
1040
|
+
hibernatableDataOrError(): PersistedConn<CP, CS>;
|
|
1041
|
+
get hibernatableDataRaw(): PersistedConn<CP, CS> | undefined;
|
|
1042
|
+
get stateEnabled(): boolean;
|
|
1043
|
+
get state(): CS;
|
|
1044
|
+
set state(value: CS);
|
|
1045
|
+
addSubscription({ eventName }: {
|
|
1046
|
+
eventName: string;
|
|
1047
|
+
}): void;
|
|
1048
|
+
removeSubscription({ eventName }: {
|
|
1049
|
+
eventName: string;
|
|
1050
|
+
}): boolean | undefined;
|
|
913
1051
|
}
|
|
914
|
-
/**
|
|
915
|
-
* Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
|
|
916
|
-
*
|
|
917
|
-
* @example
|
|
918
|
-
* ```
|
|
919
|
-
* const room = client.connect<ChatRoom>(...etc...);
|
|
920
|
-
* // This calls the action named `sendMessage` on the `ChatRoom` actor.
|
|
921
|
-
* await room.sendMessage('Hello, world!');
|
|
922
|
-
* ```
|
|
923
|
-
*
|
|
924
|
-
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
925
|
-
*
|
|
926
|
-
* @template AD The actor class that this connection is for.
|
|
927
|
-
* @see {@link ActorConnRaw}
|
|
928
|
-
*/
|
|
929
|
-
type ActorConn<AD extends AnyActorDefinition> = ActorConnRaw & ActorDefinitionActions<AD>;
|
|
930
1052
|
|
|
1053
|
+
type ConnId = string;
|
|
1054
|
+
type AnyConn = Conn<any, any, any, any, any, any, any, any>;
|
|
1055
|
+
declare const CONN_CONNECTED_SYMBOL: unique symbol;
|
|
1056
|
+
declare const CONN_SPEAKS_RIVETKIT_SYMBOL: unique symbol;
|
|
1057
|
+
declare const CONN_DRIVER_SYMBOL: unique symbol;
|
|
1058
|
+
declare const CONN_ACTOR_SYMBOL: unique symbol;
|
|
1059
|
+
declare const CONN_STATE_MANAGER_SYMBOL: unique symbol;
|
|
1060
|
+
declare const CONN_SEND_MESSAGE_SYMBOL: unique symbol;
|
|
931
1061
|
/**
|
|
932
|
-
*
|
|
933
|
-
* Similar to ActorConnRaw but doesn't maintain a connection.
|
|
1062
|
+
* Represents a client connection to a actor.
|
|
934
1063
|
*
|
|
935
|
-
*
|
|
1064
|
+
* Manages connection-specific data and controls the connection lifecycle.
|
|
1065
|
+
*
|
|
1066
|
+
* @see {@link https://rivet.dev/docs/connections|Connection Documentation}
|
|
936
1067
|
*/
|
|
937
|
-
declare class
|
|
1068
|
+
declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>> {
|
|
938
1069
|
#private;
|
|
1070
|
+
get [CONN_ACTOR_SYMBOL](): ActorInstance<S, CP, CS, V, I, DB, E, Q>;
|
|
1071
|
+
get [CONN_STATE_MANAGER_SYMBOL](): StateManager<CP, CS>;
|
|
939
1072
|
/**
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1073
|
+
* Connections exist before being connected to an actor. If true, this
|
|
1074
|
+
* connection has been connected.
|
|
1075
|
+
**/
|
|
1076
|
+
[CONN_CONNECTED_SYMBOL]: boolean;
|
|
1077
|
+
/**
|
|
1078
|
+
* If undefined, then no socket is connected to this conn
|
|
945
1079
|
*/
|
|
946
|
-
|
|
1080
|
+
[CONN_DRIVER_SYMBOL]?: ConnDriver;
|
|
947
1081
|
/**
|
|
948
|
-
*
|
|
1082
|
+
* If this connection is speaking the RivetKit protocol. If false, this is
|
|
1083
|
+
* a raw connection for WebSocket or fetch or inspector.
|
|
1084
|
+
**/
|
|
1085
|
+
get [CONN_SPEAKS_RIVETKIT_SYMBOL](): boolean;
|
|
1086
|
+
subscriptions: Set<string>;
|
|
1087
|
+
get params(): CP;
|
|
1088
|
+
/**
|
|
1089
|
+
* Gets the current state of the connection.
|
|
949
1090
|
*
|
|
950
|
-
*
|
|
951
|
-
* @template Args - The type of arguments to pass to the action function.
|
|
952
|
-
* @template Response - The type of the response returned by the action function.
|
|
1091
|
+
* Throws an error if the state is not enabled.
|
|
953
1092
|
*/
|
|
954
|
-
|
|
955
|
-
name: string;
|
|
956
|
-
args: Args;
|
|
957
|
-
signal?: AbortSignal;
|
|
958
|
-
}): Promise<Response>;
|
|
1093
|
+
get state(): CS;
|
|
959
1094
|
/**
|
|
960
|
-
*
|
|
1095
|
+
* Sets the state of the connection.
|
|
961
1096
|
*
|
|
962
|
-
*
|
|
963
|
-
* @returns {ActorConn<AD>} A connection to the actor.
|
|
1097
|
+
* Throws an error if the state is not enabled.
|
|
964
1098
|
*/
|
|
965
|
-
|
|
1099
|
+
set state(value: CS);
|
|
1100
|
+
/**
|
|
1101
|
+
* Unique identifier for the connection.
|
|
1102
|
+
*/
|
|
1103
|
+
get id(): ConnId;
|
|
966
1104
|
/**
|
|
967
|
-
*
|
|
1105
|
+
* @experimental
|
|
968
1106
|
*
|
|
969
|
-
*
|
|
970
|
-
* @param init - Standard fetch RequestInit options
|
|
971
|
-
* @returns Promise<Response> - The raw HTTP response
|
|
1107
|
+
* If the underlying connection can hibernate.
|
|
972
1108
|
*/
|
|
973
|
-
|
|
1109
|
+
get isHibernatable(): boolean;
|
|
974
1110
|
/**
|
|
975
|
-
*
|
|
1111
|
+
* Initializes a new instance of the Connection class.
|
|
1112
|
+
*
|
|
1113
|
+
* This should only be constructed by {@link Actor}.
|
|
976
1114
|
*
|
|
977
|
-
* @
|
|
978
|
-
* @param protocols - Optional WebSocket subprotocols
|
|
979
|
-
* @returns WebSocket - A raw WebSocket connection
|
|
1115
|
+
* @protected
|
|
980
1116
|
*/
|
|
981
|
-
|
|
1117
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB, E, Q>, data: ConnDataInput<CP, CS>);
|
|
982
1118
|
/**
|
|
983
|
-
*
|
|
1119
|
+
* Sends a raw message to the underlying connection.
|
|
984
1120
|
*/
|
|
985
|
-
|
|
986
|
-
signal?: AbortSignal;
|
|
987
|
-
}): Promise<string>;
|
|
1121
|
+
[CONN_SEND_MESSAGE_SYMBOL](message: CachedSerializer<any, any, any>): void;
|
|
988
1122
|
/**
|
|
989
|
-
*
|
|
1123
|
+
* Sends an event with arguments to the client.
|
|
1124
|
+
*
|
|
1125
|
+
* @param eventName - The name of the event.
|
|
1126
|
+
* @param args - The arguments for the event.
|
|
1127
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
990
1128
|
*/
|
|
991
|
-
|
|
1129
|
+
send<K extends keyof E & string>(eventName: K, ...args: InferEventArgs<InferSchemaMap<E>[K]>): void;
|
|
1130
|
+
send(eventName: keyof E extends never ? string : never, ...args: unknown[]): void;
|
|
1131
|
+
/**
|
|
1132
|
+
* Disconnects the client with an optional reason.
|
|
1133
|
+
*
|
|
1134
|
+
* @param reason - The reason for disconnection.
|
|
1135
|
+
*/
|
|
1136
|
+
disconnect(reason?: string): Promise<void>;
|
|
992
1137
|
}
|
|
993
|
-
/**
|
|
994
|
-
* Stateless handle to a actor. Allows calling actor's remote procedure calls with inferred types
|
|
995
|
-
* without establishing a persistent connection.
|
|
996
|
-
*
|
|
997
|
-
* @example
|
|
998
|
-
* ```
|
|
999
|
-
* const room = client.get<ChatRoom>(...etc...);
|
|
1000
|
-
* // This calls the action named `sendMessage` on the `ChatRoom` actor without a connection.
|
|
1001
|
-
* await room.sendMessage('Hello, world!');
|
|
1002
|
-
* ```
|
|
1003
|
-
*
|
|
1004
|
-
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
1005
|
-
*
|
|
1006
|
-
* @template AD The actor class that this handle is for.
|
|
1007
|
-
* @see {@link ActorHandleRaw}
|
|
1008
|
-
*/
|
|
1009
|
-
type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect"> & {
|
|
1010
|
-
connect(): ActorConn<AD>;
|
|
1011
|
-
resolve(): Promise<string>;
|
|
1012
|
-
} & ActorDefinitionActions<AD>;
|
|
1013
1138
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1139
|
+
type InspectorUnsubscribe = () => void;
|
|
1140
|
+
declare const RunConfigSchema: z.ZodObject<{
|
|
1141
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1142
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
1143
|
+
run: z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
|
|
1144
|
+
inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
1145
|
+
workflow: z.ZodOptional<z.ZodObject<{
|
|
1146
|
+
getHistory: z.ZodCustom<() => unknown, () => unknown>;
|
|
1147
|
+
onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
|
|
1148
|
+
}, z.core.$strip>>;
|
|
1149
|
+
}, z.core.$strip>>>;
|
|
1150
|
+
}, z.core.$strip>;
|
|
1151
|
+
type RunConfigRuntime = z.infer<typeof RunConfigSchema>;
|
|
1152
|
+
type RunConfig<TState = unknown, TConnParams = unknown, TConnState = unknown, TVars = unknown, TInput = unknown, TDatabase extends AnyDatabaseProvider = AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<RunConfigRuntime, "run"> & {
|
|
1153
|
+
run: (c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1154
|
+
};
|
|
1155
|
+
declare const ActorConfigSchema: z.ZodObject<{
|
|
1156
|
+
onCreate: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1157
|
+
onDestroy: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1158
|
+
onWake: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1159
|
+
onSleep: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1160
|
+
run: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>, z.ZodObject<{
|
|
1161
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1162
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
1163
|
+
run: z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
|
|
1164
|
+
inspector: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
1165
|
+
workflow: z.ZodOptional<z.ZodObject<{
|
|
1166
|
+
getHistory: z.ZodCustom<() => unknown, () => unknown>;
|
|
1167
|
+
onHistoryUpdated: z.ZodOptional<z.ZodCustom<(listener: (history: unknown) => void) => InspectorUnsubscribe, (listener: (history: unknown) => void) => InspectorUnsubscribe>>;
|
|
1168
|
+
}, z.core.$strip>>;
|
|
1169
|
+
}, z.core.$strip>>>;
|
|
1170
|
+
}, z.core.$strip>]>>;
|
|
1171
|
+
onStateChange: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1172
|
+
onBeforeConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1173
|
+
onConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1174
|
+
onDisconnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1175
|
+
onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1176
|
+
onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1177
|
+
onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1178
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
|
|
1179
|
+
events: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
1180
|
+
queues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
1181
|
+
state: z.ZodOptional<z.ZodAny>;
|
|
1182
|
+
createState: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1183
|
+
connState: z.ZodOptional<z.ZodAny>;
|
|
1184
|
+
createConnState: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1185
|
+
vars: z.ZodOptional<z.ZodAny>;
|
|
1186
|
+
db: z.ZodOptional<z.ZodAny>;
|
|
1187
|
+
createVars: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
1188
|
+
options: z.ZodPrefault<z.ZodObject<{
|
|
1189
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1190
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
1191
|
+
createVarsTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1192
|
+
createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1193
|
+
onConnectTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1194
|
+
onSleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1195
|
+
onDestroyTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1196
|
+
stateSaveInterval: z.ZodDefault<z.ZodNumber>;
|
|
1197
|
+
actionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1198
|
+
waitUntilTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1199
|
+
runStopTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1200
|
+
connectionLivenessTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1201
|
+
connectionLivenessInterval: z.ZodDefault<z.ZodNumber>;
|
|
1202
|
+
noSleep: z.ZodDefault<z.ZodBoolean>;
|
|
1203
|
+
sleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1204
|
+
maxQueueSize: z.ZodDefault<z.ZodNumber>;
|
|
1205
|
+
maxQueueMessageSize: z.ZodDefault<z.ZodNumber>;
|
|
1206
|
+
canHibernateWebSocket: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
|
|
1207
|
+
}, z.core.$strict>>;
|
|
1208
|
+
}, z.core.$strict>;
|
|
1209
|
+
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
|
|
1210
|
+
state: TState;
|
|
1211
|
+
} | {
|
|
1212
|
+
createState: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => TState | Promise<TState>;
|
|
1213
|
+
} | Record<never, never>;
|
|
1214
|
+
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
|
|
1215
|
+
connState: TConnState;
|
|
1216
|
+
} | {
|
|
1217
|
+
createConnState: (c: CreateConnStateContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
1218
|
+
} | Record<never, never>;
|
|
1018
1219
|
/**
|
|
1019
|
-
*
|
|
1220
|
+
* @experimental
|
|
1020
1221
|
*/
|
|
1021
|
-
|
|
1222
|
+
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig> = {
|
|
1022
1223
|
/**
|
|
1023
|
-
*
|
|
1024
|
-
|
|
1224
|
+
* @experimental
|
|
1225
|
+
*/
|
|
1226
|
+
vars: TVars;
|
|
1227
|
+
} | {
|
|
1228
|
+
/**
|
|
1229
|
+
* @experimental
|
|
1230
|
+
*/
|
|
1231
|
+
createVars: (c: CreateVarsContext<TState, TInput, TDatabase, TEvents, TQueues>, driverCtx: any) => TVars | Promise<TVars>;
|
|
1232
|
+
} | Record<never, never>;
|
|
1233
|
+
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> {
|
|
1234
|
+
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, ...args: any[]) => any;
|
|
1235
|
+
}
|
|
1236
|
+
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig, TQueues extends QueueSchemaConfig, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> {
|
|
1237
|
+
/**
|
|
1238
|
+
* Called when the actor is first initialized.
|
|
1025
1239
|
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
|
|
1029
|
-
|
|
1240
|
+
* Use this hook to initialize your actor's state.
|
|
1241
|
+
* This is called before any other lifecycle hooks.
|
|
1242
|
+
*/
|
|
1243
|
+
onCreate?: (c: CreateContext<TState, TInput, TDatabase, TEvents, TQueues>, input: TInput) => void | Promise<void>;
|
|
1244
|
+
/**
|
|
1245
|
+
* Called when the actor is destroyed.
|
|
1030
1246
|
*/
|
|
1031
|
-
|
|
1247
|
+
onDestroy?: (c: DestroyContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1032
1248
|
/**
|
|
1033
|
-
*
|
|
1034
|
-
* The actor name is automatically injected from the property accessor.
|
|
1249
|
+
* Called when the actor is started and ready to receive connections and action.
|
|
1035
1250
|
*
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
1039
|
-
* @returns
|
|
1251
|
+
* Use this hook to initialize resources needed for the actor's operation
|
|
1252
|
+
* (timers, external connections, etc.)
|
|
1253
|
+
*
|
|
1254
|
+
* @returns Void or a Promise that resolves when startup is complete
|
|
1040
1255
|
*/
|
|
1041
|
-
|
|
1256
|
+
onWake?: (c: WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1042
1257
|
/**
|
|
1043
|
-
*
|
|
1258
|
+
* Called when the actor is stopping or sleeping.
|
|
1044
1259
|
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1260
|
+
* Use this hook to clean up resources, save state, or perform
|
|
1261
|
+
* any shutdown operations before the actor sleeps or stops.
|
|
1262
|
+
*
|
|
1263
|
+
* Not supported on all platforms.
|
|
1264
|
+
*
|
|
1265
|
+
* @returns Void or a Promise that resolves when shutdown is complete
|
|
1049
1266
|
*/
|
|
1050
|
-
|
|
1267
|
+
onSleep?: (c: SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1051
1268
|
/**
|
|
1052
|
-
*
|
|
1053
|
-
* and returns a stateless handle to it with the actor ID resolved.
|
|
1269
|
+
* Called after the actor starts up. Does not block actor startup.
|
|
1054
1270
|
*
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1271
|
+
* Use this for background tasks like:
|
|
1272
|
+
* - Reading from queues in a loop
|
|
1273
|
+
* - Tick loops for periodic work
|
|
1274
|
+
* - Custom workflow logic
|
|
1275
|
+
*
|
|
1276
|
+
* **Important:** The actor may go to sleep at any time during the `run`
|
|
1277
|
+
* handler. Use `c.keepAwake(promise)` to wrap async operations that should
|
|
1278
|
+
* not be interrupted by sleep.
|
|
1279
|
+
*
|
|
1280
|
+
* The handler receives an abort signal via `c.abortSignal` and a
|
|
1281
|
+
* `c.aborted` alias for loop checks. Use these to gracefully exit.
|
|
1282
|
+
*
|
|
1283
|
+
* If this handler exits or throws, the actor will crash and reschedule.
|
|
1284
|
+
* On shutdown, the actor waits for this handler to complete with a
|
|
1285
|
+
* configurable timeout (options.runStopTimeout, default 15s).
|
|
1286
|
+
*
|
|
1287
|
+
* Can be either a function or a RunConfig object with optional name/icon metadata.
|
|
1288
|
+
*
|
|
1289
|
+
* @returns Void or a Promise. If the promise exits, the actor crashes.
|
|
1059
1290
|
*/
|
|
1060
|
-
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Options for querying actors.
|
|
1064
|
-
* @typedef {Object} QueryOptions
|
|
1065
|
-
* @property {unknown} [parameters] - Parameters to pass to the connection.
|
|
1066
|
-
*/
|
|
1067
|
-
interface QueryOptions {
|
|
1068
|
-
/** Parameters to pass to the connection. */
|
|
1069
|
-
params?: unknown;
|
|
1070
|
-
/** Signal to abort the request. */
|
|
1071
|
-
signal?: AbortSignal;
|
|
1072
|
-
}
|
|
1073
|
-
/**
|
|
1074
|
-
* Options for getting a actor by ID.
|
|
1075
|
-
* @typedef {QueryOptions} GetWithIdOptions
|
|
1076
|
-
*/
|
|
1077
|
-
interface GetWithIdOptions extends QueryOptions {
|
|
1078
|
-
}
|
|
1079
|
-
/**
|
|
1080
|
-
* Options for getting a actor.
|
|
1081
|
-
* @typedef {QueryOptions} GetOptions
|
|
1082
|
-
*/
|
|
1083
|
-
interface GetOptions extends QueryOptions {
|
|
1084
|
-
}
|
|
1085
|
-
/**
|
|
1086
|
-
* Options for getting or creating a actor.
|
|
1087
|
-
* @typedef {QueryOptions} GetOrCreateOptions
|
|
1088
|
-
* @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
|
|
1089
|
-
*/
|
|
1090
|
-
interface GetOrCreateOptions extends QueryOptions {
|
|
1091
|
-
/** Region to create the actor in if it doesn't exist. */
|
|
1092
|
-
createInRegion?: string;
|
|
1093
|
-
/** Input data to pass to the actor. */
|
|
1094
|
-
createWithInput?: unknown;
|
|
1095
|
-
}
|
|
1096
|
-
/**
|
|
1097
|
-
* Options for creating a actor.
|
|
1098
|
-
* @typedef {QueryOptions} CreateOptions
|
|
1099
|
-
* @property {string} [region] - The region to create the actor in.
|
|
1100
|
-
*/
|
|
1101
|
-
interface CreateOptions extends QueryOptions {
|
|
1102
|
-
/** The region to create the actor in. */
|
|
1103
|
-
region?: string;
|
|
1104
|
-
/** Input data to pass to the actor. */
|
|
1105
|
-
input?: unknown;
|
|
1106
|
-
}
|
|
1107
|
-
/**
|
|
1108
|
-
* Represents a region to connect to.
|
|
1109
|
-
* @typedef {Object} Region
|
|
1110
|
-
* @property {string} id - The region ID.
|
|
1111
|
-
* @property {string} name - The region name.
|
|
1112
|
-
* @see {@link https://rivet.dev/docs/edge|Edge Networking}
|
|
1113
|
-
* @see {@link https://rivet.dev/docs/regions|Available Regions}
|
|
1114
|
-
*/
|
|
1115
|
-
interface Region {
|
|
1291
|
+
run?: ((c: RunContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>) | RunConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>;
|
|
1116
1292
|
/**
|
|
1117
|
-
*
|
|
1293
|
+
* Called when the actor's state changes.
|
|
1294
|
+
*
|
|
1295
|
+
* Use this hook to react to state changes, such as updating
|
|
1296
|
+
* external systems or triggering events.
|
|
1297
|
+
*
|
|
1298
|
+
* State changes made within this hook will NOT trigger
|
|
1299
|
+
* another onStateChange call, preventing infinite recursion.
|
|
1300
|
+
*
|
|
1301
|
+
* @param newState The updated state
|
|
1118
1302
|
*/
|
|
1119
|
-
|
|
1303
|
+
onStateChange?: (c: StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, newState: TState) => void;
|
|
1120
1304
|
/**
|
|
1121
|
-
*
|
|
1305
|
+
* Called before a client connects to the actor.
|
|
1306
|
+
*
|
|
1307
|
+
* Use this hook to determine if a connection should be accepted
|
|
1308
|
+
* and to initialize connection-specific state.
|
|
1309
|
+
*
|
|
1310
|
+
* @param opts Connection parameters including client-provided data
|
|
1311
|
+
* @returns The initial connection state or a Promise that resolves to it
|
|
1312
|
+
* @throws Throw an error to reject the connection
|
|
1122
1313
|
*/
|
|
1123
|
-
|
|
1124
|
-
}
|
|
1125
|
-
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
1126
|
-
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
1127
|
-
/**
|
|
1128
|
-
* Client for managing & connecting to actors.
|
|
1129
|
-
*
|
|
1130
|
-
* @template A The actors map type that defines the available actors.
|
|
1131
|
-
* @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
|
|
1132
|
-
*/
|
|
1133
|
-
declare class ClientRaw {
|
|
1134
|
-
#private;
|
|
1135
|
-
[ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
|
|
1314
|
+
onBeforeConnect?: (c: BeforeConnectContext<TState, TVars, TInput, TDatabase, TEvents, TQueues>, params: TConnParams) => void | Promise<void>;
|
|
1136
1315
|
/**
|
|
1137
|
-
*
|
|
1316
|
+
* Called when a client successfully connects to the actor.
|
|
1317
|
+
*
|
|
1318
|
+
* Use this hook to perform actions when a connection is established,
|
|
1319
|
+
* such as sending initial data or updating the actor's state.
|
|
1320
|
+
*
|
|
1321
|
+
* @param conn The connection object
|
|
1322
|
+
* @returns Void or a Promise that resolves when connection handling is complete
|
|
1138
1323
|
*/
|
|
1139
|
-
|
|
1324
|
+
onConnect?: (c: ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1140
1325
|
/**
|
|
1141
|
-
*
|
|
1326
|
+
* Called when a client disconnects from the actor.
|
|
1142
1327
|
*
|
|
1143
|
-
*
|
|
1144
|
-
*
|
|
1145
|
-
*
|
|
1146
|
-
* @param
|
|
1147
|
-
* @returns
|
|
1328
|
+
* Use this hook to clean up resources associated with the connection
|
|
1329
|
+
* or update the actor's state.
|
|
1330
|
+
*
|
|
1331
|
+
* @param conn The connection that is being closed
|
|
1332
|
+
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
1148
1333
|
*/
|
|
1149
|
-
|
|
1334
|
+
onDisconnect?: (c: DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>) => void | Promise<void>;
|
|
1150
1335
|
/**
|
|
1151
|
-
*
|
|
1336
|
+
* Called before sending an action response to the client.
|
|
1152
1337
|
*
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
* @
|
|
1338
|
+
* Use this hook to modify or transform the output of an action before it's sent
|
|
1339
|
+
* to the client. This is useful for formatting responses, adding metadata,
|
|
1340
|
+
* or applying transformations to the output.
|
|
1341
|
+
*
|
|
1342
|
+
* @param name The name of the action that was called
|
|
1343
|
+
* @param args The arguments that were passed to the action
|
|
1344
|
+
* @param output The output that will be sent to the client
|
|
1345
|
+
* @returns The modified output to send to the client
|
|
1158
1346
|
*/
|
|
1159
|
-
|
|
1347
|
+
onBeforeActionResponse?: <Out>(c: BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
1160
1348
|
/**
|
|
1161
|
-
*
|
|
1349
|
+
* Called when a raw HTTP request is made to the actor.
|
|
1162
1350
|
*
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1166
|
-
* @param
|
|
1167
|
-
* @
|
|
1351
|
+
* This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
|
|
1352
|
+
* Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
|
|
1353
|
+
*
|
|
1354
|
+
* @param c The request context with access to the connection
|
|
1355
|
+
* @param request The raw HTTP request object
|
|
1356
|
+
* @param opts Additional options
|
|
1357
|
+
* @returns A Response object to send back, or void to continue with default routing
|
|
1168
1358
|
*/
|
|
1169
|
-
|
|
1359
|
+
onRequest?: (c: RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, request: Request) => Response | Promise<Response>;
|
|
1170
1360
|
/**
|
|
1171
|
-
*
|
|
1172
|
-
* Resolves the actor ID and returns a handle with getForId query.
|
|
1361
|
+
* Called when a raw WebSocket connection is established to the actor.
|
|
1173
1362
|
*
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1177
|
-
* @param
|
|
1178
|
-
* @
|
|
1363
|
+
* This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
|
|
1364
|
+
* Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
|
|
1365
|
+
*
|
|
1366
|
+
* @param c The WebSocket context with access to the connection
|
|
1367
|
+
* @param websocket The raw WebSocket connection
|
|
1368
|
+
* @param opts Additional options including the original HTTP upgrade request
|
|
1179
1369
|
*/
|
|
1180
|
-
|
|
1181
|
-
|
|
1370
|
+
onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>, websocket: UniversalWebSocket) => void | Promise<void>;
|
|
1371
|
+
actions?: TActions;
|
|
1182
1372
|
/**
|
|
1183
|
-
*
|
|
1373
|
+
* Schema map for events broadcasted by this actor.
|
|
1374
|
+
*/
|
|
1375
|
+
events?: TEvents;
|
|
1376
|
+
/**
|
|
1377
|
+
* Schema map for queue payloads sent by this actor.
|
|
1378
|
+
*/
|
|
1379
|
+
queues?: TQueues;
|
|
1380
|
+
}
|
|
1381
|
+
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
1382
|
+
/**
|
|
1383
|
+
* @experimental
|
|
1384
|
+
*/
|
|
1385
|
+
db: TDatabase;
|
|
1386
|
+
} | Record<never, never>;
|
|
1387
|
+
type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "events" | "queues" | "onCreate" | "onDestroy" | "onWake" | "onSleep" | "run" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TEvents, TQueues> & ActorDatabaseConfig<TDatabase>;
|
|
1388
|
+
|
|
1389
|
+
type ManagerDriverBuilder = (config: RegistryConfig) => ManagerDriver;
|
|
1390
|
+
interface ManagerDriver {
|
|
1391
|
+
getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
|
|
1392
|
+
getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
|
|
1393
|
+
getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
|
|
1394
|
+
createActor(input: CreateInput): Promise<ActorOutput>;
|
|
1395
|
+
listActors(input: ListActorsInput): Promise<ActorOutput[]>;
|
|
1396
|
+
sendRequest(actorId: string, actorRequest: Request): Promise<Response>;
|
|
1397
|
+
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown): Promise<UniversalWebSocket>;
|
|
1398
|
+
proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
|
|
1399
|
+
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
|
|
1400
|
+
/**
|
|
1401
|
+
* Build a public gateway URL for a specific actor.
|
|
1184
1402
|
*
|
|
1185
|
-
*
|
|
1403
|
+
* This lives on the driver because the base endpoint varies by runtime.
|
|
1186
1404
|
*/
|
|
1187
|
-
|
|
1405
|
+
buildGatewayUrl(actorId: string): Promise<string>;
|
|
1406
|
+
displayInformation(): ManagerDisplayInformation;
|
|
1407
|
+
extraStartupLog?: () => Record<string, unknown>;
|
|
1408
|
+
modifyManagerRouter?: (config: RegistryConfig, router: Hono) => void;
|
|
1409
|
+
/**
|
|
1410
|
+
* Allows lazily setting getUpgradeWebSocket after the manager router has
|
|
1411
|
+
* been initialized.
|
|
1412
|
+
**/
|
|
1413
|
+
setGetUpgradeWebSocket(getUpgradeWebSocket: GetUpgradeWebSocket): void;
|
|
1414
|
+
/** Read a key. Returns null if the key doesn't exist. */
|
|
1415
|
+
kvGet(actorId: string, key: Uint8Array): Promise<string | null>;
|
|
1416
|
+
}
|
|
1417
|
+
interface ManagerDisplayInformation {
|
|
1418
|
+
properties: Record<string, string>;
|
|
1419
|
+
}
|
|
1420
|
+
interface GetForIdInput<E extends Env = any> {
|
|
1421
|
+
c?: Context | undefined;
|
|
1422
|
+
name: string;
|
|
1423
|
+
actorId: string;
|
|
1424
|
+
}
|
|
1425
|
+
interface GetWithKeyInput<E extends Env = any> {
|
|
1426
|
+
c?: Context | undefined;
|
|
1427
|
+
name: string;
|
|
1428
|
+
key: ActorKey;
|
|
1429
|
+
}
|
|
1430
|
+
interface GetOrCreateWithKeyInput<E extends Env = any> {
|
|
1431
|
+
c?: Context | undefined;
|
|
1432
|
+
name: string;
|
|
1433
|
+
key: ActorKey;
|
|
1434
|
+
input?: unknown;
|
|
1435
|
+
region?: string;
|
|
1188
1436
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
type Client<A extends Registry<any>> = ClientRaw & {
|
|
1196
|
-
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
|
|
1197
|
-
};
|
|
1198
|
-
type AnyClient = Client<Registry<any>>;
|
|
1199
|
-
declare function createClientWithDriver<A extends Registry<any>>(driver: ManagerDriver, config?: {
|
|
1200
|
-
encoding?: Encoding;
|
|
1201
|
-
}): Client<A>;
|
|
1202
|
-
|
|
1203
|
-
interface ActorInspectorEmitterEvents {
|
|
1204
|
-
stateUpdated: (state: unknown) => void;
|
|
1205
|
-
connectionsUpdated: () => void;
|
|
1206
|
-
eventFired: (event: EventDetails) => void;
|
|
1207
|
-
eventsChanged: () => void;
|
|
1437
|
+
interface CreateInput<E extends Env = any> {
|
|
1438
|
+
c?: Context | undefined;
|
|
1439
|
+
name: string;
|
|
1440
|
+
key: ActorKey;
|
|
1441
|
+
input?: unknown;
|
|
1442
|
+
region?: string;
|
|
1208
1443
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1444
|
+
interface ListActorsInput<E extends Env = any> {
|
|
1445
|
+
c?: Context | undefined;
|
|
1211
1446
|
name: string;
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
args: unknown[];
|
|
1226
|
-
connId: string;
|
|
1227
|
-
} | {
|
|
1228
|
-
type: "broadcast";
|
|
1229
|
-
eventName: string;
|
|
1230
|
-
args: unknown[];
|
|
1231
|
-
};
|
|
1232
|
-
/**
|
|
1233
|
-
* Provides a unified interface for inspecting actor external and internal state.
|
|
1234
|
-
*/
|
|
1235
|
-
declare class ActorInspector {
|
|
1236
|
-
#private;
|
|
1237
|
-
private readonly actor;
|
|
1238
|
-
readonly emitter: nanoevents.Emitter<ActorInspectorEmitterEvents>;
|
|
1239
|
-
constructor(actor: AnyActorInstance);
|
|
1240
|
-
getLastEvents(): Event[];
|
|
1241
|
-
clearEvents(): void;
|
|
1242
|
-
isDatabaseEnabled(): boolean;
|
|
1243
|
-
isStateEnabled(): boolean;
|
|
1244
|
-
getState(): ArrayBuffer;
|
|
1245
|
-
getRpcs(): string[];
|
|
1246
|
-
getConnections(): {
|
|
1247
|
-
type: string | undefined;
|
|
1248
|
-
id: string;
|
|
1249
|
-
details: ArrayBuffer;
|
|
1250
|
-
}[];
|
|
1251
|
-
setState(state: ArrayBuffer): Promise<void>;
|
|
1252
|
-
executeAction(name: string, params: ArrayBuffer): Promise<ArrayBuffer>;
|
|
1447
|
+
key?: string;
|
|
1448
|
+
includeDestroyed?: boolean;
|
|
1449
|
+
}
|
|
1450
|
+
interface ActorOutput {
|
|
1451
|
+
actorId: string;
|
|
1452
|
+
name: string;
|
|
1453
|
+
key: ActorKey;
|
|
1454
|
+
createTs?: number;
|
|
1455
|
+
startTs?: number | null;
|
|
1456
|
+
connectableTs?: number | null;
|
|
1457
|
+
sleepTs?: number | null;
|
|
1458
|
+
destroyTs?: number | null;
|
|
1459
|
+
error?: unknown;
|
|
1253
1460
|
}
|
|
1254
1461
|
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
};
|
|
1270
|
-
type KvValueOptions<T extends KvValueType = "text"> = {
|
|
1271
|
-
type?: T;
|
|
1272
|
-
};
|
|
1273
|
-
type KvListOptions<T extends KvValueType = "text", K extends KvKeyType = "text"> = KvValueOptions<T> & {
|
|
1274
|
-
keyType?: K;
|
|
1275
|
-
};
|
|
1276
|
-
declare class ActorKv {
|
|
1277
|
-
#private;
|
|
1278
|
-
constructor(driver: ActorDriver, actorId: string);
|
|
1279
|
-
/**
|
|
1280
|
-
* Get a single value by key.
|
|
1281
|
-
*/
|
|
1282
|
-
get<T extends KvValueType = "text">(key: KvKey, options?: KvValueOptions<T>): Promise<KvValueTypeMap[T] | null>;
|
|
1462
|
+
type ActorDriverBuilder = (config: RegistryConfig, managerDriver: ManagerDriver, inlineClient: AnyClient) => ActorDriver;
|
|
1463
|
+
interface ActorDriver {
|
|
1464
|
+
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
1465
|
+
getContext(actorId: string): unknown;
|
|
1466
|
+
/** Batch write multiple key-value pairs. Keys and values are Uint8Arrays. */
|
|
1467
|
+
kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
|
|
1468
|
+
/** Batch read multiple keys. Returns null for keys that don't exist. */
|
|
1469
|
+
kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
|
|
1470
|
+
/** Batch delete multiple keys. */
|
|
1471
|
+
kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
|
|
1472
|
+
/** List all keys with a given prefix. */
|
|
1473
|
+
kvListPrefix(actorId: string, prefix: Uint8Array): Promise<[Uint8Array, Uint8Array][]>;
|
|
1474
|
+
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
1475
|
+
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
1283
1476
|
/**
|
|
1284
|
-
*
|
|
1477
|
+
* Override the default raw database client for the actor.
|
|
1478
|
+
* If not provided, rivetkit will construct a KV-backed SQLite client.
|
|
1479
|
+
* @experimental
|
|
1285
1480
|
*/
|
|
1286
|
-
|
|
1481
|
+
overrideRawDatabaseClient?(actorId: string): Promise<RawDatabaseClient | undefined>;
|
|
1287
1482
|
/**
|
|
1288
|
-
*
|
|
1483
|
+
* Override the default Drizzle database client for the actor.
|
|
1484
|
+
* If not provided, rivetkit will construct a KV-backed Drizzle client.
|
|
1485
|
+
* @experimental
|
|
1289
1486
|
*/
|
|
1290
|
-
|
|
1487
|
+
overrideDrizzleDatabaseClient?(actorId: string): Promise<BaseSQLiteDatabase<any, any, any, any> | undefined>;
|
|
1291
1488
|
/**
|
|
1292
|
-
*
|
|
1489
|
+
* Creates a SQLite VFS instance for creating KV-backed databases.
|
|
1490
|
+
* If not provided, the database provider will need an override.
|
|
1491
|
+
*
|
|
1492
|
+
* @rivetkit/sqlite's async build is not re-entrant per module instance. Drivers
|
|
1493
|
+
* should return a new instance per call for actor-level isolation.
|
|
1494
|
+
*
|
|
1495
|
+
* This is a method (not a property) so drivers can use dynamic imports,
|
|
1496
|
+
* keeping the core driver tree-shakeable from @rivetkit/sqlite.
|
|
1293
1497
|
*/
|
|
1294
|
-
|
|
1498
|
+
createSqliteVfs?(): SqliteVfs | Promise<SqliteVfs>;
|
|
1295
1499
|
/**
|
|
1296
|
-
*
|
|
1500
|
+
* Requests the actor to go to sleep.
|
|
1501
|
+
*
|
|
1502
|
+
* This will call `ActorInstance.onStop` independently.
|
|
1297
1503
|
*/
|
|
1298
|
-
|
|
1504
|
+
startSleep?(actorId: string): void;
|
|
1299
1505
|
/**
|
|
1300
|
-
*
|
|
1506
|
+
* Destroys the actor and its associated data.
|
|
1507
|
+
*
|
|
1508
|
+
* This will call `ActorInstance.onStop` independently.
|
|
1301
1509
|
*/
|
|
1302
|
-
|
|
1510
|
+
startDestroy(actorId: string): void;
|
|
1303
1511
|
/**
|
|
1304
|
-
*
|
|
1305
|
-
* Returns key-value pairs where keys have the user prefix removed.
|
|
1512
|
+
* Shuts down the actor runner.
|
|
1306
1513
|
*/
|
|
1307
|
-
|
|
1514
|
+
shutdownRunner?(immediate: boolean): Promise<void>;
|
|
1515
|
+
/** This handles the serverless start request. This should manage the lifecycle of the runner tied to the request lifecycle. */
|
|
1516
|
+
serverlessHandleStart?(c: Context): Promise<Response>;
|
|
1517
|
+
/** Extra properties to add to logs for each actor. */
|
|
1518
|
+
getExtraActorLogParams?(): Record<string, string>;
|
|
1519
|
+
onBeforeActorStart?(actor: AnyActorInstance): Promise<void>;
|
|
1520
|
+
onCreateConn?(conn: AnyConn): void;
|
|
1521
|
+
onDestroyConn?(conn: AnyConn): void;
|
|
1522
|
+
onBeforePersistConn?(conn: AnyConn): void;
|
|
1523
|
+
onAfterPersistConn?(conn: AnyConn): void;
|
|
1308
1524
|
}
|
|
1309
1525
|
|
|
1310
|
-
declare
|
|
1526
|
+
declare const ActorsSchema: z$1.ZodRecord<z$1.ZodString, z$1.ZodCustom<ActorDefinition<any, any, any, any, any, any, any, any, any>, ActorDefinition<any, any, any, any, any, any, any, any, any>>>;
|
|
1527
|
+
type RegistryActors = z$1.infer<typeof ActorsSchema>;
|
|
1528
|
+
declare const RegistryConfigSchema: z$1.ZodPipe<z$1.ZodObject<{
|
|
1529
|
+
use: z$1.ZodRecord<z$1.ZodString, z$1.ZodCustom<AnyActorDefinition, AnyActorDefinition>>;
|
|
1530
|
+
test: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1531
|
+
enabled: z$1.ZodBoolean;
|
|
1532
|
+
}, z$1.core.$strip>>>;
|
|
1533
|
+
driver: z$1.ZodOptional<z$1.ZodObject<{
|
|
1534
|
+
name: z$1.ZodString;
|
|
1535
|
+
displayName: z$1.ZodString;
|
|
1536
|
+
manager: z$1.ZodCustom<ManagerDriverBuilder, ManagerDriverBuilder>;
|
|
1537
|
+
actor: z$1.ZodCustom<ActorDriverBuilder, ActorDriverBuilder>;
|
|
1538
|
+
autoStartActorDriver: z$1.ZodBoolean;
|
|
1539
|
+
}, z$1.core.$strip>>;
|
|
1540
|
+
storagePath: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1541
|
+
maxIncomingMessageSize: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
|
|
1542
|
+
maxOutgoingMessageSize: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
|
|
1543
|
+
noWelcome: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
|
|
1544
|
+
logging: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1545
|
+
baseLogger: z$1.ZodOptional<z$1.ZodCustom<Logger, Logger>>;
|
|
1546
|
+
level: z$1.ZodOptional<z$1.ZodEnum<{
|
|
1547
|
+
error: "error";
|
|
1548
|
+
trace: "trace";
|
|
1549
|
+
fatal: "fatal";
|
|
1550
|
+
warn: "warn";
|
|
1551
|
+
info: "info";
|
|
1552
|
+
debug: "debug";
|
|
1553
|
+
silent: "silent";
|
|
1554
|
+
}>>;
|
|
1555
|
+
}, z$1.core.$strip>>>;
|
|
1556
|
+
endpoint: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1557
|
+
token: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1558
|
+
namespace: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1559
|
+
headers: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>>;
|
|
1560
|
+
serveManager: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1561
|
+
managerBasePath: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
1562
|
+
managerPort: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodNumber>>;
|
|
1563
|
+
managerHost: z$1.ZodOptional<z$1.ZodString>;
|
|
1564
|
+
inspector: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1565
|
+
enabled: z$1.ZodDefault<z$1.ZodBoolean>;
|
|
1566
|
+
token: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodCustom<() => string, () => string>>>;
|
|
1567
|
+
defaultEndpoint: z$1.ZodOptional<z$1.ZodString>;
|
|
1568
|
+
}, z$1.core.$strip>>>;
|
|
1569
|
+
serverless: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1570
|
+
spawnEngine: z$1.ZodDefault<z$1.ZodBoolean>;
|
|
1571
|
+
engineVersion: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
1572
|
+
configureRunnerPool: z$1.ZodOptional<z$1.ZodOptional<z$1.ZodObject<{
|
|
1573
|
+
name: z$1.ZodOptional<z$1.ZodString>;
|
|
1574
|
+
url: z$1.ZodString;
|
|
1575
|
+
headers: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>;
|
|
1576
|
+
maxRunners: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1577
|
+
minRunners: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1578
|
+
requestLifespan: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1579
|
+
runnersMargin: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1580
|
+
slotsPerRunner: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1581
|
+
metadata: z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodUnknown>>;
|
|
1582
|
+
metadataPollInterval: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1583
|
+
drainOnVersionUpgrade: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1584
|
+
}, z$1.core.$strip>>>;
|
|
1585
|
+
basePath: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodString>>;
|
|
1586
|
+
publicEndpoint: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1587
|
+
publicToken: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1588
|
+
}, z$1.core.$strip>>>;
|
|
1589
|
+
runner: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodObject<{
|
|
1590
|
+
totalSlots: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1591
|
+
runnerName: z$1.ZodDefault<z$1.ZodString>;
|
|
1592
|
+
runnerKey: z$1.ZodPipe<z$1.ZodOptional<z$1.ZodString>, z$1.ZodTransform<string | undefined, string | undefined>>;
|
|
1593
|
+
version: z$1.ZodDefault<z$1.ZodNumber>;
|
|
1594
|
+
}, z$1.core.$strip>>>;
|
|
1595
|
+
}, z$1.core.$strip>, z$1.ZodTransform<{
|
|
1596
|
+
endpoint: string | undefined;
|
|
1597
|
+
namespace: string;
|
|
1598
|
+
token: string | undefined;
|
|
1599
|
+
serveManager: boolean;
|
|
1600
|
+
publicEndpoint: string | undefined;
|
|
1601
|
+
publicNamespace: string | undefined;
|
|
1602
|
+
publicToken: string | undefined;
|
|
1603
|
+
inspector: {
|
|
1604
|
+
enabled: boolean;
|
|
1605
|
+
token: () => string;
|
|
1606
|
+
defaultEndpoint?: string | undefined;
|
|
1607
|
+
} | {
|
|
1608
|
+
enabled: {
|
|
1609
|
+
manager: boolean;
|
|
1610
|
+
actor: boolean;
|
|
1611
|
+
};
|
|
1612
|
+
token: () => string;
|
|
1613
|
+
defaultEndpoint?: string | undefined;
|
|
1614
|
+
};
|
|
1615
|
+
serverless: {
|
|
1616
|
+
publicEndpoint: string | undefined;
|
|
1617
|
+
spawnEngine: boolean;
|
|
1618
|
+
engineVersion: string;
|
|
1619
|
+
basePath: string;
|
|
1620
|
+
publicToken: string | undefined;
|
|
1621
|
+
configureRunnerPool?: {
|
|
1622
|
+
url: string;
|
|
1623
|
+
name?: string | undefined;
|
|
1624
|
+
headers?: Record<string, string> | undefined;
|
|
1625
|
+
maxRunners?: number | undefined;
|
|
1626
|
+
minRunners?: number | undefined;
|
|
1627
|
+
requestLifespan?: number | undefined;
|
|
1628
|
+
runnersMargin?: number | undefined;
|
|
1629
|
+
slotsPerRunner?: number | undefined;
|
|
1630
|
+
metadata?: Record<string, unknown> | undefined;
|
|
1631
|
+
metadataPollInterval?: number | undefined;
|
|
1632
|
+
drainOnVersionUpgrade?: boolean | undefined;
|
|
1633
|
+
} | undefined;
|
|
1634
|
+
};
|
|
1635
|
+
use: Record<string, AnyActorDefinition>;
|
|
1636
|
+
test: {
|
|
1637
|
+
enabled: boolean;
|
|
1638
|
+
};
|
|
1639
|
+
storagePath: string | undefined;
|
|
1640
|
+
maxIncomingMessageSize: number;
|
|
1641
|
+
maxOutgoingMessageSize: number;
|
|
1642
|
+
noWelcome: boolean;
|
|
1643
|
+
logging: {
|
|
1644
|
+
baseLogger?: Logger | undefined;
|
|
1645
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
1646
|
+
};
|
|
1647
|
+
headers: Record<string, string>;
|
|
1648
|
+
managerBasePath: string;
|
|
1649
|
+
managerPort: number;
|
|
1650
|
+
runner: {
|
|
1651
|
+
totalSlots: number;
|
|
1652
|
+
runnerName: string;
|
|
1653
|
+
runnerKey: string | undefined;
|
|
1654
|
+
version: number;
|
|
1655
|
+
};
|
|
1656
|
+
driver?: {
|
|
1657
|
+
name: string;
|
|
1658
|
+
displayName: string;
|
|
1659
|
+
manager: ManagerDriverBuilder;
|
|
1660
|
+
actor: ActorDriverBuilder;
|
|
1661
|
+
autoStartActorDriver: boolean;
|
|
1662
|
+
} | undefined;
|
|
1663
|
+
managerHost?: string | undefined;
|
|
1664
|
+
}, {
|
|
1665
|
+
use: Record<string, AnyActorDefinition>;
|
|
1666
|
+
test: {
|
|
1667
|
+
enabled: boolean;
|
|
1668
|
+
};
|
|
1669
|
+
storagePath: string | undefined;
|
|
1670
|
+
maxIncomingMessageSize: number;
|
|
1671
|
+
maxOutgoingMessageSize: number;
|
|
1672
|
+
noWelcome: boolean;
|
|
1673
|
+
logging: {
|
|
1674
|
+
baseLogger?: Logger | undefined;
|
|
1675
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
1676
|
+
};
|
|
1677
|
+
endpoint: string | undefined;
|
|
1678
|
+
token: string | undefined;
|
|
1679
|
+
namespace: string | undefined;
|
|
1680
|
+
headers: Record<string, string>;
|
|
1681
|
+
managerBasePath: string;
|
|
1682
|
+
managerPort: number;
|
|
1683
|
+
inspector: {
|
|
1684
|
+
enabled: boolean;
|
|
1685
|
+
token: () => string;
|
|
1686
|
+
defaultEndpoint?: string | undefined;
|
|
1687
|
+
};
|
|
1688
|
+
serverless: {
|
|
1689
|
+
spawnEngine: boolean;
|
|
1690
|
+
engineVersion: string;
|
|
1691
|
+
basePath: string;
|
|
1692
|
+
publicEndpoint: string | undefined;
|
|
1693
|
+
publicToken: string | undefined;
|
|
1694
|
+
configureRunnerPool?: {
|
|
1695
|
+
url: string;
|
|
1696
|
+
name?: string | undefined;
|
|
1697
|
+
headers?: Record<string, string> | undefined;
|
|
1698
|
+
maxRunners?: number | undefined;
|
|
1699
|
+
minRunners?: number | undefined;
|
|
1700
|
+
requestLifespan?: number | undefined;
|
|
1701
|
+
runnersMargin?: number | undefined;
|
|
1702
|
+
slotsPerRunner?: number | undefined;
|
|
1703
|
+
metadata?: Record<string, unknown> | undefined;
|
|
1704
|
+
metadataPollInterval?: number | undefined;
|
|
1705
|
+
drainOnVersionUpgrade?: boolean | undefined;
|
|
1706
|
+
} | undefined;
|
|
1707
|
+
};
|
|
1708
|
+
runner: {
|
|
1709
|
+
totalSlots: number;
|
|
1710
|
+
runnerName: string;
|
|
1711
|
+
runnerKey: string | undefined;
|
|
1712
|
+
version: number;
|
|
1713
|
+
};
|
|
1714
|
+
driver?: {
|
|
1715
|
+
name: string;
|
|
1716
|
+
displayName: string;
|
|
1717
|
+
manager: ManagerDriverBuilder;
|
|
1718
|
+
actor: ActorDriverBuilder;
|
|
1719
|
+
autoStartActorDriver: boolean;
|
|
1720
|
+
} | undefined;
|
|
1721
|
+
serveManager?: boolean | undefined;
|
|
1722
|
+
managerHost?: string | undefined;
|
|
1723
|
+
}>>;
|
|
1724
|
+
type RegistryConfig = z$1.infer<typeof RegistryConfigSchema>;
|
|
1725
|
+
type RegistryConfigInput<A extends RegistryActors> = Omit<z$1.input<typeof RegistryConfigSchema>, "use"> & {
|
|
1726
|
+
use: A;
|
|
1727
|
+
};
|
|
1728
|
+
|
|
1729
|
+
type AnyActorDefinition = ActorDefinition<any, any, any, any, any, any, any, any, any>;
|
|
1730
|
+
declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, E extends EventSchemaConfig = Record<never, never>, Q extends QueueSchemaConfig = Record<never, never>, R extends Actions<S, CP, CS, V, I, DB, E, Q> = Actions<S, CP, CS, V, I, DB, E, Q>> {
|
|
1311
1731
|
#private;
|
|
1312
|
-
constructor(
|
|
1313
|
-
|
|
1314
|
-
|
|
1732
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB, E, Q>);
|
|
1733
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB, E, Q>;
|
|
1734
|
+
instantiate(): ActorInstance<S, CP, CS, V, I, DB, E, Q>;
|
|
1315
1735
|
}
|
|
1316
1736
|
|
|
1317
1737
|
/**
|
|
1318
|
-
*
|
|
1738
|
+
* Action function returned by Actor connections and handles.
|
|
1739
|
+
*
|
|
1740
|
+
* @typedef {Function} ActorActionFunction
|
|
1741
|
+
* @template Args
|
|
1742
|
+
* @template Response
|
|
1743
|
+
* @param {...Args} args - Arguments for the action function.
|
|
1744
|
+
* @returns {Promise<Response>}
|
|
1319
1745
|
*/
|
|
1320
|
-
|
|
1321
|
-
#private;
|
|
1322
|
-
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
1323
|
-
/**
|
|
1324
|
-
* Gets the KV storage interface.
|
|
1325
|
-
*/
|
|
1326
|
-
get kv(): ActorKv;
|
|
1327
|
-
/**
|
|
1328
|
-
* Get the actor state
|
|
1329
|
-
*
|
|
1330
|
-
* @remarks
|
|
1331
|
-
* This property is not available in `createState` since the state hasn't been created yet.
|
|
1332
|
-
*/
|
|
1333
|
-
get state(): TState extends never ? never : TState;
|
|
1334
|
-
/**
|
|
1335
|
-
* Get the actor variables
|
|
1336
|
-
*
|
|
1337
|
-
* @remarks
|
|
1338
|
-
* This property is not available in `createVars` since the variables haven't been created yet.
|
|
1339
|
-
* Variables are only available if you define `vars` or `createVars` in your actor config.
|
|
1340
|
-
*/
|
|
1341
|
-
get vars(): TVars extends never ? never : TVars;
|
|
1342
|
-
/**
|
|
1343
|
-
* Broadcasts an event to all connected clients.
|
|
1344
|
-
* @param name - The name of the event.
|
|
1345
|
-
* @param args - The arguments to send with the event.
|
|
1346
|
-
*/
|
|
1347
|
-
broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
1348
|
-
/**
|
|
1349
|
-
* Gets the logger instance.
|
|
1350
|
-
*/
|
|
1351
|
-
get log(): Logger;
|
|
1352
|
-
/**
|
|
1353
|
-
* Gets actor ID.
|
|
1354
|
-
*/
|
|
1355
|
-
get actorId(): string;
|
|
1356
|
-
/**
|
|
1357
|
-
* Gets the actor name.
|
|
1358
|
-
*/
|
|
1359
|
-
get name(): string;
|
|
1360
|
-
/**
|
|
1361
|
-
* Gets the actor key.
|
|
1362
|
-
*/
|
|
1363
|
-
get key(): ActorKey;
|
|
1364
|
-
/**
|
|
1365
|
-
* Gets the region.
|
|
1366
|
-
*/
|
|
1367
|
-
get region(): string;
|
|
1368
|
-
/**
|
|
1369
|
-
* Gets the scheduler.
|
|
1370
|
-
*/
|
|
1371
|
-
get schedule(): Schedule;
|
|
1372
|
-
/**
|
|
1373
|
-
* Gets the map of connections.
|
|
1374
|
-
*/
|
|
1375
|
-
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>;
|
|
1376
|
-
/**
|
|
1377
|
-
* Returns the client for the given registry.
|
|
1378
|
-
*/
|
|
1379
|
-
client<R extends Registry<any>>(): Client<R>;
|
|
1380
|
-
/**
|
|
1381
|
-
* Gets the database.
|
|
1382
|
-
*
|
|
1383
|
-
* @experimental
|
|
1384
|
-
* @remarks
|
|
1385
|
-
* This property is only available if you define a `db` provider in your actor config.
|
|
1386
|
-
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
1387
|
-
*/
|
|
1388
|
-
get db(): TDatabase extends never ? never : InferDatabaseClient<TDatabase>;
|
|
1389
|
-
/**
|
|
1390
|
-
* Forces the state to get saved.
|
|
1391
|
-
*
|
|
1392
|
-
* @param opts - Options for saving the state.
|
|
1393
|
-
*/
|
|
1394
|
-
saveState(opts: SaveStateOptions): Promise<void>;
|
|
1395
|
-
/**
|
|
1396
|
-
* Prevents the actor from sleeping until promise is complete.
|
|
1397
|
-
*/
|
|
1398
|
-
waitUntil(promise: Promise<void>): void;
|
|
1399
|
-
/**
|
|
1400
|
-
* AbortSignal that fires when the actor is stopping.
|
|
1401
|
-
*/
|
|
1402
|
-
get abortSignal(): AbortSignal;
|
|
1403
|
-
/**
|
|
1404
|
-
* Forces the actor to sleep.
|
|
1405
|
-
*
|
|
1406
|
-
* Not supported on all drivers.
|
|
1407
|
-
*
|
|
1408
|
-
* @experimental
|
|
1409
|
-
*/
|
|
1410
|
-
sleep(): void;
|
|
1411
|
-
/**
|
|
1412
|
-
* Forces the actor to destroy.
|
|
1413
|
-
*
|
|
1414
|
-
* This will return immediately, then call `onStop` and `onDestroy`.
|
|
1415
|
-
*
|
|
1416
|
-
* @experimental
|
|
1417
|
-
*/
|
|
1418
|
-
destroy(): void;
|
|
1419
|
-
}
|
|
1420
|
-
type ActorContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? ActorContext<S, CP, CS, V, I, DB> : never;
|
|
1421
|
-
|
|
1746
|
+
type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
|
|
1422
1747
|
/**
|
|
1423
|
-
*
|
|
1424
|
-
* Extends ActorContext with connection-specific functionality.
|
|
1748
|
+
* Maps action methods from actor definition to typed function signatures.
|
|
1425
1749
|
*/
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
}
|
|
1429
|
-
type ConnContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? ConnContext<S, CP, CS, V, I, DB> : never;
|
|
1750
|
+
type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends ActorDefinition<any, any, any, any, any, any, any, any, infer R> ? {
|
|
1751
|
+
[K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
|
|
1752
|
+
} : never;
|
|
1430
1753
|
|
|
1431
|
-
|
|
1432
|
-
* Base context for connection initialization handlers.
|
|
1433
|
-
* Extends ActorContext with request-specific functionality for connection lifecycle events.
|
|
1434
|
-
*/
|
|
1435
|
-
declare abstract class ConnInitContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, never, never, TVars, TInput, TDatabase> {
|
|
1436
|
-
/**
|
|
1437
|
-
* The incoming request that initiated the connection.
|
|
1438
|
-
* May be undefined for connections initiated without a direct HTTP request.
|
|
1439
|
-
*/
|
|
1440
|
-
readonly request: Request | undefined;
|
|
1754
|
+
declare class ActorClientError extends Error {
|
|
1441
1755
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
/**
|
|
1445
|
-
* Context for a remote procedure call.
|
|
1446
|
-
*/
|
|
1447
|
-
declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1756
|
+
declare class InternalError extends ActorClientError {
|
|
1448
1757
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
*/
|
|
1452
|
-
type ActionContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? ActionContext<S, CP, CS, V, I, DB> : never;
|
|
1453
|
-
|
|
1454
|
-
/**
|
|
1455
|
-
* Context for the onBeforeActionResponse lifecycle hook.
|
|
1456
|
-
*/
|
|
1457
|
-
declare class BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1758
|
+
declare class ManagerError extends ActorClientError {
|
|
1759
|
+
constructor(error: string, opts?: ErrorOptions);
|
|
1458
1760
|
}
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1761
|
+
declare class MalformedResponseMessage extends ActorClientError {
|
|
1762
|
+
constructor(cause?: unknown);
|
|
1763
|
+
}
|
|
1764
|
+
declare class ActorError extends ActorClientError {
|
|
1765
|
+
readonly group: string;
|
|
1766
|
+
readonly code: string;
|
|
1767
|
+
readonly metadata?: unknown | undefined;
|
|
1768
|
+
__type: string;
|
|
1769
|
+
constructor(group: string, code: string, message: string, metadata?: unknown | undefined);
|
|
1770
|
+
}
|
|
1771
|
+
declare class ActorConnDisposed extends ActorClientError {
|
|
1772
|
+
constructor();
|
|
1465
1773
|
}
|
|
1466
|
-
type BeforeConnectContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, any, any, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? BeforeConnectContext<S, V, I, DB> : never;
|
|
1467
1774
|
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1775
|
+
interface QueueSendWaitOptions {
|
|
1776
|
+
wait: true;
|
|
1777
|
+
timeout?: number;
|
|
1778
|
+
signal?: AbortSignal;
|
|
1779
|
+
}
|
|
1780
|
+
interface QueueSendNoWaitOptions {
|
|
1781
|
+
wait?: false;
|
|
1782
|
+
timeout?: never;
|
|
1783
|
+
signal?: AbortSignal;
|
|
1784
|
+
}
|
|
1785
|
+
interface QueueSendResult {
|
|
1786
|
+
status: "completed" | "timedOut";
|
|
1787
|
+
response?: unknown;
|
|
1472
1788
|
}
|
|
1473
|
-
type ConnectContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? ConnectContext<S, CP, CS, V, I, DB> : never;
|
|
1474
1789
|
|
|
1475
1790
|
/**
|
|
1476
|
-
*
|
|
1791
|
+
* Connection status for an actor connection.
|
|
1792
|
+
*
|
|
1793
|
+
* - `"idle"`: Not connected, no auto-reconnect (initial state, after dispose, or disabled)
|
|
1794
|
+
* - `"connecting"`: Attempting to establish connection
|
|
1795
|
+
* - `"connected"`: Connection is active
|
|
1796
|
+
* - `"disconnected"`: Connection was lost, will auto-reconnect
|
|
1477
1797
|
*/
|
|
1478
|
-
|
|
1479
|
-
}
|
|
1480
|
-
type CreateContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, any, any, any, infer I, infer DB extends AnyDatabaseProvider, any> ? CreateContext<S, I, DB> : never;
|
|
1481
|
-
|
|
1798
|
+
type ActorConnStatus = "idle" | "connecting" | "connected" | "disconnected";
|
|
1482
1799
|
/**
|
|
1483
|
-
*
|
|
1484
|
-
*
|
|
1800
|
+
* A function that unsubscribes from an event.
|
|
1801
|
+
*
|
|
1802
|
+
* @typedef {Function} EventUnsubscribe
|
|
1485
1803
|
*/
|
|
1486
|
-
|
|
1487
|
-
}
|
|
1488
|
-
type CreateConnStateContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, any, any, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? CreateConnStateContext<S, V, I, DB> : never;
|
|
1489
|
-
|
|
1804
|
+
type EventUnsubscribe = () => void;
|
|
1490
1805
|
/**
|
|
1491
|
-
*
|
|
1806
|
+
* A function that handles connection errors.
|
|
1807
|
+
*
|
|
1808
|
+
* @typedef {Function} ActorErrorCallback
|
|
1492
1809
|
*/
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1495
|
-
type CreateVarsContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, any, any, any, infer I, infer DB extends AnyDatabaseProvider, any> ? CreateVarsContext<S, I, DB> : never;
|
|
1496
|
-
|
|
1810
|
+
type ActorErrorCallback = (error: ActorError) => void;
|
|
1497
1811
|
/**
|
|
1498
|
-
*
|
|
1812
|
+
* A callback for connection state changes.
|
|
1813
|
+
*
|
|
1814
|
+
* @typedef {Function} ConnectionStateCallback
|
|
1499
1815
|
*/
|
|
1500
|
-
|
|
1501
|
-
}
|
|
1502
|
-
type DestroyContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? DestroyContext<S, CP, CS, V, I, DB> : never;
|
|
1503
|
-
|
|
1816
|
+
type ConnectionStateCallback = () => void;
|
|
1504
1817
|
/**
|
|
1505
|
-
*
|
|
1818
|
+
* A callback for connection status changes.
|
|
1819
|
+
*
|
|
1820
|
+
* @typedef {Function} StatusChangeCallback
|
|
1506
1821
|
*/
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
type DisconnectContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? DisconnectContext<S, CP, CS, V, I, DB> : never;
|
|
1510
|
-
|
|
1822
|
+
type StatusChangeCallback = (status: ActorConnStatus) => void;
|
|
1823
|
+
declare const CONNECT_SYMBOL: unique symbol;
|
|
1511
1824
|
/**
|
|
1512
|
-
*
|
|
1825
|
+
* Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
|
|
1826
|
+
*
|
|
1827
|
+
* @see {@link ActorConn}
|
|
1513
1828
|
*/
|
|
1514
|
-
declare class
|
|
1829
|
+
declare class ActorConnRaw {
|
|
1830
|
+
#private;
|
|
1831
|
+
/**
|
|
1832
|
+
* Do not call this directly.
|
|
1833
|
+
*
|
|
1834
|
+
* Creates an instance of ActorConnRaw.
|
|
1835
|
+
*
|
|
1836
|
+
* @protected
|
|
1837
|
+
*/
|
|
1838
|
+
constructor(client: ClientRaw, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1839
|
+
send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
|
|
1840
|
+
send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
|
|
1841
|
+
/**
|
|
1842
|
+
* Call a raw action connection. See {@link ActorConn} for type-safe action calls.
|
|
1843
|
+
*
|
|
1844
|
+
* @see {@link ActorConn}
|
|
1845
|
+
* @template Args - The type of arguments to pass to the action function.
|
|
1846
|
+
* @template Response - The type of the response returned by the action function.
|
|
1847
|
+
* @param {string} name - The name of the action function to call.
|
|
1848
|
+
* @param {...Args} args - The arguments to pass to the action function.
|
|
1849
|
+
* @returns {Promise<Response>} - A promise that resolves to the response of the action function.
|
|
1850
|
+
*/
|
|
1851
|
+
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
1852
|
+
name: string;
|
|
1853
|
+
args: Args;
|
|
1854
|
+
signal?: AbortSignal;
|
|
1855
|
+
}): Promise<Response>;
|
|
1856
|
+
/**
|
|
1857
|
+
* Do not call this directly.
|
|
1858
|
+
* Establishes a connection to the server using the specified endpoint & encoding & driver.
|
|
1859
|
+
*
|
|
1860
|
+
* @protected
|
|
1861
|
+
*/
|
|
1862
|
+
[CONNECT_SYMBOL](): void;
|
|
1515
1863
|
/**
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1864
|
+
* Subscribes to an event that will happen repeatedly.
|
|
1865
|
+
*
|
|
1866
|
+
* @template Args - The type of arguments the event callback will receive.
|
|
1867
|
+
* @param {string} eventName - The name of the event to subscribe to.
|
|
1868
|
+
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
1869
|
+
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
1870
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1518
1871
|
*/
|
|
1519
|
-
|
|
1520
|
-
}
|
|
1521
|
-
type RequestContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? RequestContext<S, CP, CS, V, I, DB> : never;
|
|
1522
|
-
|
|
1523
|
-
/**
|
|
1524
|
-
* Context for the onSleep lifecycle hook.
|
|
1525
|
-
*/
|
|
1526
|
-
declare class SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1527
|
-
}
|
|
1528
|
-
type SleepContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? SleepContext<S, CP, CS, V, I, DB> : never;
|
|
1529
|
-
|
|
1530
|
-
/**
|
|
1531
|
-
* Context for the onStateChange lifecycle hook.
|
|
1532
|
-
*/
|
|
1533
|
-
declare class StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1534
|
-
}
|
|
1535
|
-
type StateChangeContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? StateChangeContext<S, CP, CS, V, I, DB> : never;
|
|
1536
|
-
|
|
1537
|
-
/**
|
|
1538
|
-
* Context for the onWake lifecycle hook.
|
|
1539
|
-
*/
|
|
1540
|
-
declare class WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1541
|
-
}
|
|
1542
|
-
type WakeContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? WakeContext<S, CP, CS, V, I, DB> : never;
|
|
1543
|
-
|
|
1544
|
-
/**
|
|
1545
|
-
* Context for raw WebSocket handlers (onWebSocket).
|
|
1546
|
-
*/
|
|
1547
|
-
declare class WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1872
|
+
on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1548
1873
|
/**
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1874
|
+
* Subscribes to an event that will be triggered only once.
|
|
1875
|
+
*
|
|
1876
|
+
* @template Args - The type of arguments the event callback will receive.
|
|
1877
|
+
* @param {string} eventName - The name of the event to subscribe to.
|
|
1878
|
+
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
1879
|
+
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
1880
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1551
1881
|
*/
|
|
1552
|
-
|
|
1553
|
-
}
|
|
1554
|
-
type WebSocketContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB extends AnyDatabaseProvider, any> ? WebSocketContext<S, CP, CS, V, I, DB> : never;
|
|
1555
|
-
|
|
1556
|
-
declare enum DriverReadyState {
|
|
1557
|
-
UNKNOWN = -1,
|
|
1558
|
-
CONNECTING = 0,
|
|
1559
|
-
OPEN = 1,
|
|
1560
|
-
CLOSING = 2,
|
|
1561
|
-
CLOSED = 3
|
|
1562
|
-
}
|
|
1563
|
-
interface ConnDriver {
|
|
1564
|
-
/** The type of driver. Used for debug purposes only. */
|
|
1565
|
-
type: string;
|
|
1882
|
+
once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1566
1883
|
/**
|
|
1567
|
-
*
|
|
1568
|
-
* schemas/client-protocol/).
|
|
1884
|
+
* Subscribes to connection errors.
|
|
1569
1885
|
*
|
|
1570
|
-
*
|
|
1571
|
-
* to
|
|
1886
|
+
* @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
|
|
1887
|
+
* @returns {() => void} - A function to unsubscribe from the error handler.
|
|
1572
1888
|
*/
|
|
1573
|
-
|
|
1574
|
-
/** Sends a RivetKit client message. */
|
|
1575
|
-
sendMessage(actor: AnyActorInstance, conn: AnyConn, message: CachedSerializer<any, any, any>): void;
|
|
1576
|
-
};
|
|
1889
|
+
onError(callback: ActorErrorCallback): () => void;
|
|
1577
1890
|
/**
|
|
1578
|
-
*
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
};
|
|
1891
|
+
* Returns the current connection status.
|
|
1892
|
+
*
|
|
1893
|
+
* @returns {ActorConnStatus} - The current connection status.
|
|
1894
|
+
*/
|
|
1895
|
+
get connStatus(): ActorConnStatus;
|
|
1584
1896
|
/**
|
|
1585
|
-
*
|
|
1897
|
+
* Returns whether the connection is currently open.
|
|
1898
|
+
*
|
|
1899
|
+
* @deprecated Use `connStatus` instead.
|
|
1900
|
+
* @returns {boolean} - True if the connection is open, false otherwise.
|
|
1586
1901
|
*/
|
|
1587
|
-
|
|
1588
|
-
/** Terminates the connection without graceful handling. */
|
|
1589
|
-
terminate?(actor: AnyActorInstance, conn: AnyConn): void;
|
|
1902
|
+
get isConnected(): boolean;
|
|
1590
1903
|
/**
|
|
1591
|
-
*
|
|
1592
|
-
*
|
|
1904
|
+
* Subscribes to connection open events.
|
|
1905
|
+
*
|
|
1906
|
+
* This is called when the WebSocket connection is established and the Init message is received.
|
|
1907
|
+
*
|
|
1908
|
+
* @param {ConnectionStateCallback} callback - The callback function to execute when the connection opens.
|
|
1909
|
+
* @returns {() => void} - A function to unsubscribe from the open handler.
|
|
1593
1910
|
*/
|
|
1594
|
-
|
|
1911
|
+
onOpen(callback: ConnectionStateCallback): () => void;
|
|
1912
|
+
/**
|
|
1913
|
+
* Subscribes to connection close events.
|
|
1914
|
+
*
|
|
1915
|
+
* This is called when the WebSocket connection is closed. The connection will automatically
|
|
1916
|
+
* attempt to reconnect unless disposed.
|
|
1917
|
+
*
|
|
1918
|
+
* @param {ConnectionStateCallback} callback - The callback function to execute when the connection closes.
|
|
1919
|
+
* @returns {() => void} - A function to unsubscribe from the close handler.
|
|
1920
|
+
*/
|
|
1921
|
+
onClose(callback: ConnectionStateCallback): () => void;
|
|
1922
|
+
/**
|
|
1923
|
+
* Subscribes to connection status changes.
|
|
1924
|
+
*
|
|
1925
|
+
* This is called whenever the connection status changes between Disconnected, Connecting, and Connected.
|
|
1926
|
+
*
|
|
1927
|
+
* @param {StatusChangeCallback} callback - The callback function to execute when the status changes.
|
|
1928
|
+
* @returns {() => void} - A function to unsubscribe from the status change handler.
|
|
1929
|
+
*/
|
|
1930
|
+
onStatusChange(callback: StatusChangeCallback): () => void;
|
|
1931
|
+
/**
|
|
1932
|
+
* Disconnects from the actor.
|
|
1933
|
+
*
|
|
1934
|
+
* @returns {Promise<void>} A promise that resolves when the socket is gracefully closed.
|
|
1935
|
+
*/
|
|
1936
|
+
dispose(): Promise<void>;
|
|
1595
1937
|
}
|
|
1596
|
-
|
|
1597
1938
|
/**
|
|
1598
|
-
*
|
|
1939
|
+
* Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
|
|
1599
1940
|
*
|
|
1600
|
-
*
|
|
1941
|
+
* @example
|
|
1942
|
+
* ```
|
|
1943
|
+
* const room = client.connect<ChatRoom>(...etc...);
|
|
1944
|
+
* // This calls the action named `sendMessage` on the `ChatRoom` actor.
|
|
1945
|
+
* await room.sendMessage('Hello, world!');
|
|
1946
|
+
* ```
|
|
1947
|
+
*
|
|
1948
|
+
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
1949
|
+
*
|
|
1950
|
+
* @template AD The actor class that this connection is for.
|
|
1951
|
+
* @see {@link ActorConnRaw}
|
|
1601
1952
|
*/
|
|
1602
|
-
|
|
1603
|
-
type GatewayId = ArrayBuffer;
|
|
1604
|
-
type RequestId = ArrayBuffer;
|
|
1605
|
-
/** Event subscription for connection */
|
|
1606
|
-
interface PersistedSubscription {
|
|
1607
|
-
eventName: string;
|
|
1608
|
-
}
|
|
1609
|
-
/** Connection associated with hibernatable WebSocket that should persist across lifecycles */
|
|
1610
|
-
interface PersistedConn<CP, CS> {
|
|
1611
|
-
/** Connection ID generated by RivetKit */
|
|
1612
|
-
id: string;
|
|
1613
|
-
parameters: CP;
|
|
1614
|
-
state: CS;
|
|
1615
|
-
subscriptions: PersistedSubscription[];
|
|
1616
|
-
gatewayId: GatewayId;
|
|
1617
|
-
requestId: RequestId;
|
|
1618
|
-
serverMessageIndex: number;
|
|
1619
|
-
clientMessageIndex: number;
|
|
1620
|
-
requestPath: string;
|
|
1621
|
-
requestHeaders: Record<string, string>;
|
|
1622
|
-
}
|
|
1953
|
+
type ActorConn<AD extends AnyActorDefinition> = ActorConnRaw & ActorDefinitionActions<AD>;
|
|
1623
1954
|
|
|
1624
1955
|
/**
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1956
|
+
* Provides underlying functions for stateless {@link ActorHandle} for action calls.
|
|
1957
|
+
* Similar to ActorConnRaw but doesn't maintain a connection.
|
|
1958
|
+
*
|
|
1959
|
+
* @see {@link ActorHandle}
|
|
1627
1960
|
*/
|
|
1628
|
-
declare class
|
|
1961
|
+
declare class ActorHandleRaw {
|
|
1629
1962
|
#private;
|
|
1630
|
-
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>);
|
|
1631
|
-
get connections(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
1632
|
-
getConnForId(id: string): Conn<S, CP, CS, V, I, DB> | undefined;
|
|
1633
|
-
get connsWithPersistChanged(): Set<ConnId>;
|
|
1634
|
-
clearConnWithPersistChanged(): void;
|
|
1635
|
-
markConnWithPersistChanged(conn: Conn<S, CP, CS, V, I, DB>): void;
|
|
1636
1963
|
/**
|
|
1637
|
-
*
|
|
1964
|
+
* Do not call this directly.
|
|
1965
|
+
*
|
|
1966
|
+
* Creates an instance of ActorHandleRaw.
|
|
1967
|
+
*
|
|
1968
|
+
* @protected
|
|
1638
1969
|
*/
|
|
1639
|
-
|
|
1970
|
+
constructor(client: any, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1971
|
+
send(name: string, body: unknown, options: QueueSendWaitOptions): Promise<QueueSendResult>;
|
|
1972
|
+
send(name: string, body: unknown, options?: QueueSendNoWaitOptions): Promise<void>;
|
|
1640
1973
|
/**
|
|
1641
|
-
*
|
|
1974
|
+
* Call a raw action. This method sends an HTTP request to invoke the named action.
|
|
1642
1975
|
*
|
|
1643
|
-
*
|
|
1644
|
-
*
|
|
1645
|
-
*
|
|
1646
|
-
* So all async work in prepareConn.
|
|
1976
|
+
* @see {@link ActorHandle}
|
|
1977
|
+
* @template Args - The type of arguments to pass to the action function.
|
|
1978
|
+
* @template Response - The type of the response returned by the action function.
|
|
1647
1979
|
*/
|
|
1648
|
-
|
|
1980
|
+
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
1981
|
+
name: string;
|
|
1982
|
+
args: Args;
|
|
1983
|
+
signal?: AbortSignal;
|
|
1984
|
+
}): Promise<Response>;
|
|
1649
1985
|
/**
|
|
1650
|
-
*
|
|
1986
|
+
* Establishes a persistent connection to the actor.
|
|
1651
1987
|
*
|
|
1652
|
-
*
|
|
1988
|
+
* @template AD The actor class that this connection is for.
|
|
1989
|
+
* @returns {ActorConn<AD>} A connection to the actor.
|
|
1990
|
+
*/
|
|
1991
|
+
connect(): ActorConn<AnyActorDefinition>;
|
|
1992
|
+
/**
|
|
1993
|
+
* Fetches a resource from this actor via the /request endpoint. This is a
|
|
1994
|
+
* convenience wrapper around the raw HTTP API.
|
|
1653
1995
|
*/
|
|
1654
|
-
|
|
1996
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
1655
1997
|
/**
|
|
1656
|
-
*
|
|
1998
|
+
* Opens a raw WebSocket connection to this actor.
|
|
1657
1999
|
*/
|
|
1658
|
-
|
|
2000
|
+
webSocket(path?: string, protocols?: string | string[]): Promise<any>;
|
|
1659
2001
|
/**
|
|
1660
|
-
*
|
|
2002
|
+
* Resolves the actor to get its unique actor ID.
|
|
1661
2003
|
*/
|
|
1662
|
-
|
|
1663
|
-
|
|
2004
|
+
resolve(): Promise<string>;
|
|
2005
|
+
/**
|
|
2006
|
+
* Returns the raw URL for routing traffic to the actor.
|
|
2007
|
+
*/
|
|
2008
|
+
getGatewayUrl(): Promise<string>;
|
|
1664
2009
|
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Stateless handle to a actor. Allows calling actor's remote procedure calls with inferred types
|
|
2012
|
+
* without establishing a persistent connection.
|
|
2013
|
+
*
|
|
2014
|
+
* @example
|
|
2015
|
+
* ```
|
|
2016
|
+
* const room = client.get<ChatRoom>(...etc...);
|
|
2017
|
+
* // This calls the action named `sendMessage` on the `ChatRoom` actor without a connection.
|
|
2018
|
+
* await room.sendMessage('Hello, world!');
|
|
2019
|
+
* ```
|
|
2020
|
+
*
|
|
2021
|
+
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
2022
|
+
*
|
|
2023
|
+
* @template AD The actor class that this handle is for.
|
|
2024
|
+
* @see {@link ActorHandleRaw}
|
|
2025
|
+
*/
|
|
2026
|
+
type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect"> & {
|
|
2027
|
+
connect(): ActorConn<AD>;
|
|
2028
|
+
resolve(): Promise<string>;
|
|
2029
|
+
} & ActorDefinitionActions<AD>;
|
|
2030
|
+
|
|
2031
|
+
declare const ClientConfigSchema: z$2.ZodPipe<z$2.ZodObject<{
|
|
2032
|
+
endpoint: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string, string | undefined>>;
|
|
2033
|
+
token: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
|
|
2034
|
+
namespace: z$2.ZodPipe<z$2.ZodOptional<z$2.ZodString>, z$2.ZodTransform<string | undefined, string | undefined>>;
|
|
2035
|
+
runnerName: z$2.ZodDefault<z$2.ZodString>;
|
|
2036
|
+
encoding: z$2.ZodDefault<z$2.ZodEnum<{
|
|
2037
|
+
json: "json";
|
|
2038
|
+
cbor: "cbor";
|
|
2039
|
+
bare: "bare";
|
|
2040
|
+
}>>;
|
|
2041
|
+
headers: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodString>>>;
|
|
2042
|
+
getUpgradeWebSocket: z$2.ZodOptional<z$2.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
|
|
2043
|
+
disableMetadataLookup: z$2.ZodDefault<z$2.ZodOptional<z$2.ZodBoolean>>;
|
|
2044
|
+
devtools: z$2.ZodDefault<z$2.ZodBoolean>;
|
|
2045
|
+
}, z$2.core.$strip>, z$2.ZodTransform<{
|
|
2046
|
+
endpoint: string | undefined;
|
|
2047
|
+
namespace: string;
|
|
2048
|
+
token: string | undefined;
|
|
2049
|
+
runnerName: string;
|
|
2050
|
+
encoding: "json" | "cbor" | "bare";
|
|
2051
|
+
headers: Record<string, string>;
|
|
2052
|
+
disableMetadataLookup: boolean;
|
|
2053
|
+
devtools: boolean;
|
|
2054
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2055
|
+
}, {
|
|
2056
|
+
endpoint: string;
|
|
2057
|
+
token: string | undefined;
|
|
2058
|
+
namespace: string | undefined;
|
|
2059
|
+
runnerName: string;
|
|
2060
|
+
encoding: "json" | "cbor" | "bare";
|
|
2061
|
+
headers: Record<string, string>;
|
|
2062
|
+
disableMetadataLookup: boolean;
|
|
2063
|
+
devtools: boolean;
|
|
2064
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2065
|
+
}>>;
|
|
2066
|
+
type ClientConfigInput = z$2.input<typeof ClientConfigSchema>;
|
|
1665
2067
|
|
|
2068
|
+
/** Extract the actor registry from the registry definition. */
|
|
2069
|
+
type ExtractActorsFromRegistry<A extends Registry<any>> = A extends Registry<infer Actors> ? Actors : never;
|
|
2070
|
+
/** Extract the registry definition from the client. */
|
|
2071
|
+
type ExtractRegistryFromClient<C extends Client<Registry<{}>>> = C extends Client<infer A> ? A : never;
|
|
1666
2072
|
/**
|
|
1667
|
-
*
|
|
1668
|
-
* Handles subscription tracking and efficient message distribution to connected clients.
|
|
2073
|
+
* Represents a actor accessor that provides methods to interact with a specific actor.
|
|
1669
2074
|
*/
|
|
1670
|
-
|
|
1671
|
-
#private;
|
|
1672
|
-
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>);
|
|
1673
|
-
/**
|
|
1674
|
-
* Adds a subscription for a connection to an event.
|
|
1675
|
-
*
|
|
1676
|
-
* @param eventName - The name of the event to subscribe to
|
|
1677
|
-
* @param connection - The connection subscribing to the event
|
|
1678
|
-
* @param fromPersist - Whether this subscription is being restored from persistence
|
|
1679
|
-
*/
|
|
1680
|
-
addSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB>, fromPersist: boolean): void;
|
|
1681
|
-
/**
|
|
1682
|
-
* Removes a subscription for a connection from an event.
|
|
1683
|
-
*
|
|
1684
|
-
* @param eventName - The name of the event to unsubscribe from
|
|
1685
|
-
* @param connection - The connection unsubscribing from the event
|
|
1686
|
-
* @param fromRemoveConn - Whether this is being called as part of connection removal
|
|
1687
|
-
*/
|
|
1688
|
-
removeSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB>, fromRemoveConn: boolean): void;
|
|
1689
|
-
/**
|
|
1690
|
-
* Broadcasts an event to all subscribed connections.
|
|
1691
|
-
*
|
|
1692
|
-
* @param name - The name of the event to broadcast
|
|
1693
|
-
* @param args - The arguments to send with the event
|
|
1694
|
-
*/
|
|
1695
|
-
broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
2075
|
+
interface ActorAccessor<AD extends AnyActorDefinition> {
|
|
1696
2076
|
/**
|
|
1697
|
-
* Gets
|
|
2077
|
+
* Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
|
|
2078
|
+
* The actor name is automatically injected from the property accessor.
|
|
1698
2079
|
*
|
|
1699
|
-
* @
|
|
1700
|
-
* @
|
|
2080
|
+
* @template AD The actor class that this handle is for.
|
|
2081
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2082
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2083
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1701
2084
|
*/
|
|
1702
|
-
|
|
2085
|
+
get(key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
1703
2086
|
/**
|
|
1704
|
-
* Gets
|
|
2087
|
+
* Gets a stateless handle to a actor by its key, creating it if necessary.
|
|
2088
|
+
* The actor name is automatically injected from the property accessor.
|
|
1705
2089
|
*
|
|
1706
|
-
* @
|
|
2090
|
+
* @template AD The actor class that this handle is for.
|
|
2091
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2092
|
+
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
2093
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1707
2094
|
*/
|
|
1708
|
-
|
|
2095
|
+
getOrCreate(key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
|
|
1709
2096
|
/**
|
|
1710
|
-
*
|
|
1711
|
-
* Used during connection cleanup.
|
|
2097
|
+
* Gets a stateless handle to a actor by its ID.
|
|
1712
2098
|
*
|
|
1713
|
-
* @
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
* Gets the total number of unique events being subscribed to.
|
|
1718
|
-
*/
|
|
1719
|
-
get eventCount(): number;
|
|
1720
|
-
/**
|
|
1721
|
-
* Gets the total number of subscriptions across all events.
|
|
2099
|
+
* @template AD The actor class that this handle is for.
|
|
2100
|
+
* @param {string} actorId - The ID of the actor.
|
|
2101
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2102
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1722
2103
|
*/
|
|
1723
|
-
|
|
2104
|
+
getForId(actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
1724
2105
|
/**
|
|
1725
|
-
*
|
|
2106
|
+
* Creates a new actor with the name automatically injected from the property accessor,
|
|
2107
|
+
* and returns a stateless handle to it with the actor ID resolved.
|
|
1726
2108
|
*
|
|
1727
|
-
* @
|
|
1728
|
-
* @
|
|
2109
|
+
* @template AD The actor class that this handle is for.
|
|
2110
|
+
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
2111
|
+
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
2112
|
+
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
1729
2113
|
*/
|
|
1730
|
-
|
|
2114
|
+
create(key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
1731
2115
|
}
|
|
1732
|
-
|
|
1733
2116
|
/**
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1736
|
-
*
|
|
2117
|
+
* Options for querying actors.
|
|
2118
|
+
* @typedef {Object} QueryOptions
|
|
2119
|
+
* @property {unknown} [parameters] - Parameters to pass to the connection.
|
|
1737
2120
|
*/
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
timestamp: number;
|
|
1744
|
-
action: string;
|
|
1745
|
-
args?: Cbor;
|
|
2121
|
+
interface QueryOptions {
|
|
2122
|
+
/** Parameters to pass to the connection. */
|
|
2123
|
+
params?: unknown;
|
|
2124
|
+
/** Signal to abort the request. */
|
|
2125
|
+
signal?: AbortSignal;
|
|
1746
2126
|
}
|
|
1747
|
-
/**
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
state: S;
|
|
1753
|
-
scheduledEvents: PersistedScheduleEvent[];
|
|
2127
|
+
/**
|
|
2128
|
+
* Options for getting a actor by ID.
|
|
2129
|
+
* @typedef {QueryOptions} GetWithIdOptions
|
|
2130
|
+
*/
|
|
2131
|
+
interface GetWithIdOptions extends QueryOptions {
|
|
1754
2132
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
immediate?: boolean;
|
|
1761
|
-
/** Bypass ready check for stopping. */
|
|
1762
|
-
allowStoppingState?: boolean;
|
|
1763
|
-
/**
|
|
1764
|
-
* Maximum time in milliseconds to wait before forcing a save.
|
|
1765
|
-
*
|
|
1766
|
-
* If a save is already scheduled to occur later than this deadline, it will be rescheduled earlier.
|
|
1767
|
-
*/
|
|
1768
|
-
maxWait?: number;
|
|
2133
|
+
/**
|
|
2134
|
+
* Options for getting a actor.
|
|
2135
|
+
* @typedef {QueryOptions} GetOptions
|
|
2136
|
+
*/
|
|
2137
|
+
interface GetOptions extends QueryOptions {
|
|
1769
2138
|
}
|
|
1770
2139
|
/**
|
|
1771
|
-
*
|
|
1772
|
-
*
|
|
2140
|
+
* Options for getting or creating a actor.
|
|
2141
|
+
* @typedef {QueryOptions} GetOrCreateOptions
|
|
2142
|
+
* @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
|
|
1773
2143
|
*/
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
get persistChanged(): boolean;
|
|
1780
|
-
get state(): S;
|
|
1781
|
-
set state(value: S);
|
|
1782
|
-
get stateEnabled(): boolean;
|
|
1783
|
-
/**
|
|
1784
|
-
* Initializes state from persisted data or creates new state.
|
|
1785
|
-
*/
|
|
1786
|
-
initializeState(persistData: PersistedActor<S, I>): Promise<void>;
|
|
1787
|
-
/**
|
|
1788
|
-
* Creates proxy for persist object that handles automatic state change detection.
|
|
1789
|
-
*/
|
|
1790
|
-
initPersistProxy(target: PersistedActor<S, I>): undefined;
|
|
1791
|
-
/**
|
|
1792
|
-
* Forces the state to get saved.
|
|
1793
|
-
*/
|
|
1794
|
-
saveState(opts: SaveStateOptions): Promise<void>;
|
|
1795
|
-
/**
|
|
1796
|
-
* Throttled save state method. Used to write to KV at a reasonable cadence.
|
|
1797
|
-
*
|
|
1798
|
-
* Passing a maxWait will override the stateSaveInterval with the min
|
|
1799
|
-
* between that and the maxWait.
|
|
1800
|
-
*/
|
|
1801
|
-
savePersistThrottled(maxWait?: number): void;
|
|
1802
|
-
/**
|
|
1803
|
-
* Clears any pending save timeout.
|
|
1804
|
-
*/
|
|
1805
|
-
clearPendingSaveTimeout(): void;
|
|
1806
|
-
/**
|
|
1807
|
-
* Waits for any pending write operations to complete.
|
|
1808
|
-
*/
|
|
1809
|
-
waitForPendingWrites(): Promise<void>;
|
|
2144
|
+
interface GetOrCreateOptions extends QueryOptions {
|
|
2145
|
+
/** Region to create the actor in if it doesn't exist. */
|
|
2146
|
+
createInRegion?: string;
|
|
2147
|
+
/** Input data to pass to the actor. */
|
|
2148
|
+
createWithInput?: unknown;
|
|
1810
2149
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
constructor(config: ActorConfig<S, CP, CS, V, I, DB>);
|
|
1822
|
-
get log(): Logger;
|
|
1823
|
-
get rLog(): Logger;
|
|
1824
|
-
get isStopping(): boolean;
|
|
1825
|
-
get id(): string;
|
|
1826
|
-
get name(): string;
|
|
1827
|
-
get key(): ActorKey;
|
|
1828
|
-
get region(): string;
|
|
1829
|
-
get inlineClient(): Client<Registry<any>>;
|
|
1830
|
-
get inspector(): ActorInspector;
|
|
1831
|
-
get inspectorToken(): string | undefined;
|
|
1832
|
-
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
1833
|
-
get schedule(): Schedule;
|
|
1834
|
-
get abortSignal(): AbortSignal;
|
|
1835
|
-
get actions(): string[];
|
|
1836
|
-
get config(): ActorConfig<S, CP, CS, V, I, DB>;
|
|
1837
|
-
get persist(): PersistedActor<S, I>;
|
|
1838
|
-
get state(): S;
|
|
1839
|
-
set state(value: S);
|
|
1840
|
-
get stateEnabled(): boolean;
|
|
1841
|
-
get connStateEnabled(): boolean;
|
|
1842
|
-
get vars(): V;
|
|
1843
|
-
get db(): InferDatabaseClient<DB>;
|
|
1844
|
-
start(actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
1845
|
-
isReady(): boolean;
|
|
1846
|
-
assertReady(allowStoppingState?: boolean): void;
|
|
1847
|
-
onStop(mode: "sleep" | "destroy"): Promise<void>;
|
|
1848
|
-
startSleep(): void;
|
|
1849
|
-
startDestroy(): void;
|
|
1850
|
-
beginHonoHttpRequest(): void;
|
|
1851
|
-
endHonoHttpRequest(): void;
|
|
1852
|
-
processMessage(message: {
|
|
1853
|
-
body: {
|
|
1854
|
-
tag: "ActionRequest";
|
|
1855
|
-
val: {
|
|
1856
|
-
id: bigint;
|
|
1857
|
-
name: string;
|
|
1858
|
-
args: unknown;
|
|
1859
|
-
};
|
|
1860
|
-
} | {
|
|
1861
|
-
tag: "SubscriptionRequest";
|
|
1862
|
-
val: {
|
|
1863
|
-
eventName: string;
|
|
1864
|
-
subscribe: boolean;
|
|
1865
|
-
};
|
|
1866
|
-
};
|
|
1867
|
-
}, conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
1868
|
-
executeAction(ctx: ActionContext<S, CP, CS, V, I, DB>, actionName: string, args: unknown[]): Promise<unknown>;
|
|
1869
|
-
handleRawRequest(conn: Conn<S, CP, CS, V, I, DB>, request: Request): Promise<Response>;
|
|
1870
|
-
handleRawWebSocket(conn: Conn<S, CP, CS, V, I, DB>, websocket: UniversalWebSocket, request?: Request): void;
|
|
1871
|
-
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
1872
|
-
onAlarm(): Promise<void>;
|
|
1873
|
-
waitUntil(promise: Promise<void>): void;
|
|
1874
|
-
resetSleepTimer(): void;
|
|
2150
|
+
/**
|
|
2151
|
+
* Options for creating a actor.
|
|
2152
|
+
* @typedef {QueryOptions} CreateOptions
|
|
2153
|
+
* @property {string} [region] - The region to create the actor in.
|
|
2154
|
+
*/
|
|
2155
|
+
interface CreateOptions extends QueryOptions {
|
|
2156
|
+
/** The region to create the actor in. */
|
|
2157
|
+
region?: string;
|
|
2158
|
+
/** Input data to pass to the actor. */
|
|
2159
|
+
input?: unknown;
|
|
1875
2160
|
}
|
|
1876
|
-
|
|
1877
|
-
/** Pick a subset of persisted data used to represent ephemeral connections */
|
|
1878
|
-
type EphemeralConn<CP, CS> = Pick<PersistedConn<CP, CS>, "id" | "parameters" | "state">;
|
|
1879
|
-
type ConnDataInput<CP, CS> = {
|
|
1880
|
-
ephemeral: EphemeralConn<CP, CS>;
|
|
1881
|
-
} | {
|
|
1882
|
-
hibernatable: PersistedConn<CP, CS>;
|
|
1883
|
-
};
|
|
1884
2161
|
/**
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
2162
|
+
* Represents a region to connect to.
|
|
2163
|
+
* @typedef {Object} Region
|
|
2164
|
+
* @property {string} id - The region ID.
|
|
2165
|
+
* @property {string} name - The region name.
|
|
2166
|
+
* @see {@link https://rivet.dev/docs/edge|Edge Networking}
|
|
2167
|
+
* @see {@link https://rivet.dev/docs/regions|Available Regions}
|
|
2168
|
+
*/
|
|
2169
|
+
interface Region {
|
|
2170
|
+
/**
|
|
2171
|
+
* The region slug.
|
|
2172
|
+
*/
|
|
2173
|
+
id: string;
|
|
2174
|
+
/**
|
|
2175
|
+
* The human-friendly region name.
|
|
2176
|
+
*/
|
|
2177
|
+
name: string;
|
|
2178
|
+
}
|
|
2179
|
+
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
2180
|
+
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
2181
|
+
/**
|
|
2182
|
+
* Client for managing & connecting to actors.
|
|
2183
|
+
*
|
|
2184
|
+
* @template A The actors map type that defines the available actors.
|
|
2185
|
+
* @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
|
|
1887
2186
|
*/
|
|
1888
|
-
declare class
|
|
2187
|
+
declare class ClientRaw {
|
|
1889
2188
|
#private;
|
|
1890
|
-
|
|
2189
|
+
[ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
|
|
1891
2190
|
/**
|
|
1892
|
-
*
|
|
2191
|
+
* Creates an instance of Client.
|
|
2192
|
+
*/
|
|
2193
|
+
constructor(driver: ManagerDriver, encoding: Encoding | undefined);
|
|
2194
|
+
/**
|
|
2195
|
+
* Gets a stateless handle to a actor by its ID.
|
|
1893
2196
|
*
|
|
1894
|
-
*
|
|
1895
|
-
*
|
|
2197
|
+
* @template AD The actor class that this handle is for.
|
|
2198
|
+
* @param {string} name - The name of the actor.
|
|
2199
|
+
* @param {string} actorId - The ID of the actor.
|
|
2200
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2201
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1896
2202
|
*/
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
2203
|
+
getForId<AD extends AnyActorDefinition>(name: string, actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
2204
|
+
/**
|
|
2205
|
+
* Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
|
|
2206
|
+
*
|
|
2207
|
+
* @template AD The actor class that this handle is for.
|
|
2208
|
+
* @param {string} name - The name of the actor.
|
|
2209
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2210
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
2211
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2212
|
+
*/
|
|
2213
|
+
get<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
2214
|
+
/**
|
|
2215
|
+
* Gets a stateless handle to a actor by its key, creating it if necessary.
|
|
2216
|
+
*
|
|
2217
|
+
* @template AD The actor class that this handle is for.
|
|
2218
|
+
* @param {string} name - The name of the actor.
|
|
2219
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
2220
|
+
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
2221
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2222
|
+
*/
|
|
2223
|
+
getOrCreate<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
|
|
2224
|
+
/**
|
|
2225
|
+
* Creates a new actor with the provided key and returns a stateless handle to it.
|
|
2226
|
+
* Resolves the actor ID and returns a handle with getForId query.
|
|
2227
|
+
*
|
|
2228
|
+
* @template AD The actor class that this handle is for.
|
|
2229
|
+
* @param {string} name - The name of the actor.
|
|
2230
|
+
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
2231
|
+
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
2232
|
+
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
2233
|
+
*/
|
|
2234
|
+
create<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
2235
|
+
[CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(conn: ActorConnRaw): ActorConn<AD>;
|
|
2236
|
+
/**
|
|
2237
|
+
* Disconnects from all actors.
|
|
2238
|
+
*
|
|
2239
|
+
* @returns {Promise<void>} A promise that resolves when all connections are closed.
|
|
2240
|
+
*/
|
|
2241
|
+
dispose(): Promise<void>;
|
|
1910
2242
|
}
|
|
1911
|
-
|
|
1912
|
-
type ConnId = string;
|
|
1913
|
-
type AnyConn = Conn<any, any, any, any, any, any>;
|
|
1914
|
-
declare const CONN_CONNECTED_SYMBOL: unique symbol;
|
|
1915
|
-
declare const CONN_SPEAKS_RIVETKIT_SYMBOL: unique symbol;
|
|
1916
|
-
declare const CONN_DRIVER_SYMBOL: unique symbol;
|
|
1917
|
-
declare const CONN_ACTOR_SYMBOL: unique symbol;
|
|
1918
|
-
declare const CONN_STATE_MANAGER_SYMBOL: unique symbol;
|
|
1919
|
-
declare const CONN_SEND_MESSAGE_SYMBOL: unique symbol;
|
|
1920
2243
|
/**
|
|
1921
|
-
*
|
|
1922
|
-
*
|
|
1923
|
-
* Manages connection-specific data and controls the connection lifecycle.
|
|
2244
|
+
* Client type with actor accessors.
|
|
2245
|
+
* This adds property accessors for actor names to the ClientRaw base class.
|
|
1924
2246
|
*
|
|
1925
|
-
* @
|
|
2247
|
+
* @template A The actor registry type.
|
|
1926
2248
|
*/
|
|
1927
|
-
|
|
2249
|
+
type Client<A extends Registry<any>> = ClientRaw & {
|
|
2250
|
+
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
|
|
2251
|
+
};
|
|
2252
|
+
type AnyClient = Client<Registry<any>>;
|
|
2253
|
+
|
|
2254
|
+
declare const LegacyRunnerConfigSchema: z.ZodDefault<z.ZodPipe<z.ZodObject<{
|
|
2255
|
+
driver: z.ZodOptional<z.ZodObject<{
|
|
2256
|
+
name: z.ZodString;
|
|
2257
|
+
manager: z.ZodCustom<ManagerDriverBuilder, ManagerDriverBuilder>;
|
|
2258
|
+
actor: z.ZodCustom<ActorDriverBuilder, ActorDriverBuilder>;
|
|
2259
|
+
}, z.core.$strip>>;
|
|
2260
|
+
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2261
|
+
maxOutgoingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
2262
|
+
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
2263
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
2264
|
+
token: z.ZodDefault<z.ZodOptional<z.ZodCustom<() => string, () => string>>>;
|
|
2265
|
+
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
2266
|
+
}, z.core.$strip>>>;
|
|
2267
|
+
disableDefaultServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2268
|
+
defaultServerPort: z.ZodDefault<z.ZodNumber>;
|
|
2269
|
+
runEngine: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2270
|
+
runEngineVersion: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2271
|
+
overrideServerAddress: z.ZodOptional<z.ZodString>;
|
|
2272
|
+
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2273
|
+
runnerKind: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
2274
|
+
serverless: "serverless";
|
|
2275
|
+
normal: "normal";
|
|
2276
|
+
}>>>;
|
|
2277
|
+
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
2278
|
+
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2279
|
+
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
2280
|
+
baseLogger: z.ZodOptional<z.ZodCustom<Logger, Logger>>;
|
|
2281
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
2282
|
+
error: "error";
|
|
2283
|
+
trace: "trace";
|
|
2284
|
+
fatal: "fatal";
|
|
2285
|
+
warn: "warn";
|
|
2286
|
+
info: "info";
|
|
2287
|
+
debug: "debug";
|
|
2288
|
+
silent: "silent";
|
|
2289
|
+
}>>;
|
|
2290
|
+
}, z.core.$strip>>>;
|
|
2291
|
+
autoConfigureServerless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
2292
|
+
url: z.ZodOptional<z.ZodString>;
|
|
2293
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
2294
|
+
maxRunners: z.ZodOptional<z.ZodNumber>;
|
|
2295
|
+
minRunners: z.ZodOptional<z.ZodNumber>;
|
|
2296
|
+
requestLifespan: z.ZodOptional<z.ZodNumber>;
|
|
2297
|
+
runnersMargin: z.ZodOptional<z.ZodNumber>;
|
|
2298
|
+
slotsPerRunner: z.ZodOptional<z.ZodNumber>;
|
|
2299
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2300
|
+
}, z.core.$strip>]>>;
|
|
2301
|
+
endpoint: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string, string | undefined>>;
|
|
2302
|
+
token: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
2303
|
+
namespace: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
2304
|
+
runnerName: z.ZodDefault<z.ZodString>;
|
|
2305
|
+
encoding: z.ZodDefault<z.ZodEnum<{
|
|
2306
|
+
json: "json";
|
|
2307
|
+
cbor: "cbor";
|
|
2308
|
+
bare: "bare";
|
|
2309
|
+
}>>;
|
|
2310
|
+
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
2311
|
+
getUpgradeWebSocket: z.ZodOptional<z.ZodCustom<GetUpgradeWebSocket, GetUpgradeWebSocket>>;
|
|
2312
|
+
disableMetadataLookup: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
2313
|
+
devtools: z.ZodDefault<z.ZodBoolean>;
|
|
2314
|
+
runnerKey: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
|
|
2315
|
+
totalSlots: z.ZodDefault<z.ZodNumber>;
|
|
2316
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
2317
|
+
runnerKey: string | undefined;
|
|
2318
|
+
endpoint: string | undefined;
|
|
2319
|
+
namespace: string;
|
|
2320
|
+
token: string | undefined;
|
|
2321
|
+
runnerName: string;
|
|
2322
|
+
encoding: "json" | "cbor" | "bare";
|
|
2323
|
+
headers: Record<string, string>;
|
|
2324
|
+
disableMetadataLookup: boolean;
|
|
2325
|
+
devtools: boolean;
|
|
2326
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2327
|
+
maxIncomingMessageSize: number;
|
|
2328
|
+
maxOutgoingMessageSize: number;
|
|
2329
|
+
inspector: {
|
|
2330
|
+
enabled: boolean;
|
|
2331
|
+
token: () => string;
|
|
2332
|
+
defaultEndpoint?: string | undefined;
|
|
2333
|
+
};
|
|
2334
|
+
disableDefaultServer: boolean;
|
|
2335
|
+
defaultServerPort: number;
|
|
2336
|
+
runEngine: boolean;
|
|
2337
|
+
runEngineVersion: string;
|
|
2338
|
+
disableActorDriver: boolean;
|
|
2339
|
+
runnerKind: "serverless" | "normal";
|
|
2340
|
+
basePath: string;
|
|
2341
|
+
noWelcome: boolean;
|
|
2342
|
+
logging: {
|
|
2343
|
+
baseLogger?: Logger | undefined;
|
|
2344
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
2345
|
+
};
|
|
2346
|
+
totalSlots: number;
|
|
2347
|
+
driver?: {
|
|
2348
|
+
name: string;
|
|
2349
|
+
manager: ManagerDriverBuilder;
|
|
2350
|
+
actor: ActorDriverBuilder;
|
|
2351
|
+
} | undefined;
|
|
2352
|
+
overrideServerAddress?: string | undefined;
|
|
2353
|
+
autoConfigureServerless?: boolean | {
|
|
2354
|
+
url?: string | undefined;
|
|
2355
|
+
headers?: Record<string, string> | undefined;
|
|
2356
|
+
maxRunners?: number | undefined;
|
|
2357
|
+
minRunners?: number | undefined;
|
|
2358
|
+
requestLifespan?: number | undefined;
|
|
2359
|
+
runnersMargin?: number | undefined;
|
|
2360
|
+
slotsPerRunner?: number | undefined;
|
|
2361
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2362
|
+
} | undefined;
|
|
2363
|
+
}, {
|
|
2364
|
+
maxIncomingMessageSize: number;
|
|
2365
|
+
maxOutgoingMessageSize: number;
|
|
2366
|
+
inspector: {
|
|
2367
|
+
enabled: boolean;
|
|
2368
|
+
token: () => string;
|
|
2369
|
+
defaultEndpoint?: string | undefined;
|
|
2370
|
+
};
|
|
2371
|
+
disableDefaultServer: boolean;
|
|
2372
|
+
defaultServerPort: number;
|
|
2373
|
+
runEngine: boolean;
|
|
2374
|
+
runEngineVersion: string;
|
|
2375
|
+
disableActorDriver: boolean;
|
|
2376
|
+
runnerKind: "serverless" | "normal";
|
|
2377
|
+
basePath: string;
|
|
2378
|
+
noWelcome: boolean;
|
|
2379
|
+
logging: {
|
|
2380
|
+
baseLogger?: Logger | undefined;
|
|
2381
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
2382
|
+
};
|
|
2383
|
+
endpoint: string;
|
|
2384
|
+
token: string | undefined;
|
|
2385
|
+
namespace: string | undefined;
|
|
2386
|
+
runnerName: string;
|
|
2387
|
+
encoding: "json" | "cbor" | "bare";
|
|
2388
|
+
headers: Record<string, string>;
|
|
2389
|
+
disableMetadataLookup: boolean;
|
|
2390
|
+
devtools: boolean;
|
|
2391
|
+
runnerKey: string | undefined;
|
|
2392
|
+
totalSlots: number;
|
|
2393
|
+
driver?: {
|
|
2394
|
+
name: string;
|
|
2395
|
+
manager: ManagerDriverBuilder;
|
|
2396
|
+
actor: ActorDriverBuilder;
|
|
2397
|
+
} | undefined;
|
|
2398
|
+
overrideServerAddress?: string | undefined;
|
|
2399
|
+
autoConfigureServerless?: boolean | {
|
|
2400
|
+
url?: string | undefined;
|
|
2401
|
+
headers?: Record<string, string> | undefined;
|
|
2402
|
+
maxRunners?: number | undefined;
|
|
2403
|
+
minRunners?: number | undefined;
|
|
2404
|
+
requestLifespan?: number | undefined;
|
|
2405
|
+
runnersMargin?: number | undefined;
|
|
2406
|
+
slotsPerRunner?: number | undefined;
|
|
2407
|
+
metadata?: Record<string, unknown> | undefined;
|
|
2408
|
+
} | undefined;
|
|
2409
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
2410
|
+
}>>>;
|
|
2411
|
+
type LegacyRunnerConfigInput = z.input<typeof LegacyRunnerConfigSchema>;
|
|
2412
|
+
|
|
2413
|
+
type FetchHandler = (request: Request, ...args: any) => Response | Promise<Response>;
|
|
2414
|
+
interface ServerlessHandler {
|
|
2415
|
+
fetch: FetchHandler;
|
|
2416
|
+
}
|
|
2417
|
+
interface LegacyStartServerOutput<A extends Registry<any>> {
|
|
2418
|
+
/** Client to communicate with the actors. */
|
|
2419
|
+
client: Client<A>;
|
|
2420
|
+
/** Fetch handler to manually route requests to the Rivet manager API. */
|
|
2421
|
+
fetch: FetchHandler;
|
|
2422
|
+
}
|
|
2423
|
+
declare class Registry<A extends RegistryActors> {
|
|
1928
2424
|
#private;
|
|
1929
|
-
get
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
* Connections exist before being connected to an actor. If true, this
|
|
1933
|
-
* connection has been connected.
|
|
1934
|
-
**/
|
|
1935
|
-
[CONN_CONNECTED_SYMBOL]: boolean;
|
|
1936
|
-
/**
|
|
1937
|
-
* If undefined, then no socket is connected to this conn
|
|
1938
|
-
*/
|
|
1939
|
-
[CONN_DRIVER_SYMBOL]?: ConnDriver;
|
|
1940
|
-
/**
|
|
1941
|
-
* If this connection is speaking the RivetKit protocol. If false, this is
|
|
1942
|
-
* a raw connection for WebSocket or fetch or inspector.
|
|
1943
|
-
**/
|
|
1944
|
-
get [CONN_SPEAKS_RIVETKIT_SYMBOL](): boolean;
|
|
1945
|
-
subscriptions: Set<string>;
|
|
1946
|
-
get params(): CP;
|
|
1947
|
-
/**
|
|
1948
|
-
* Gets the current state of the connection.
|
|
1949
|
-
*
|
|
1950
|
-
* Throws an error if the state is not enabled.
|
|
1951
|
-
*/
|
|
1952
|
-
get state(): CS;
|
|
1953
|
-
/**
|
|
1954
|
-
* Sets the state of the connection.
|
|
1955
|
-
*
|
|
1956
|
-
* Throws an error if the state is not enabled.
|
|
1957
|
-
*/
|
|
1958
|
-
set state(value: CS);
|
|
1959
|
-
/**
|
|
1960
|
-
* Unique identifier for the connection.
|
|
1961
|
-
*/
|
|
1962
|
-
get id(): ConnId;
|
|
2425
|
+
get config(): RegistryConfigInput<A>;
|
|
2426
|
+
parseConfig(): RegistryConfig;
|
|
2427
|
+
constructor(config: RegistryConfigInput<A>);
|
|
1963
2428
|
/**
|
|
1964
|
-
*
|
|
2429
|
+
* Handle an incoming HTTP request for serverless deployments.
|
|
1965
2430
|
*
|
|
1966
|
-
*
|
|
2431
|
+
* @example
|
|
2432
|
+
* ```ts
|
|
2433
|
+
* const app = new Hono();
|
|
2434
|
+
* app.all("/api/rivet/*", (c) => registry.handler(c.req.raw));
|
|
2435
|
+
* export default app;
|
|
2436
|
+
* ```
|
|
1967
2437
|
*/
|
|
1968
|
-
|
|
2438
|
+
handler(request: Request): Promise<Response>;
|
|
1969
2439
|
/**
|
|
1970
|
-
*
|
|
1971
|
-
*
|
|
1972
|
-
* This should only be constructed by {@link Actor}.
|
|
2440
|
+
* Returns a fetch handler for serverless deployments.
|
|
1973
2441
|
*
|
|
1974
|
-
* @
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
* Sends a raw message to the underlying connection.
|
|
2442
|
+
* @example
|
|
2443
|
+
* ```ts
|
|
2444
|
+
* export default registry.serve();
|
|
2445
|
+
* ```
|
|
1979
2446
|
*/
|
|
1980
|
-
|
|
2447
|
+
serve(): ServerlessHandler;
|
|
1981
2448
|
/**
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
1984
|
-
* @param eventName - The name of the event.
|
|
1985
|
-
* @param args - The arguments for the event.
|
|
1986
|
-
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
2449
|
+
* Starts an actor runner for standalone server deployments.
|
|
1987
2450
|
*/
|
|
1988
|
-
|
|
2451
|
+
startRunner(): void;
|
|
1989
2452
|
/**
|
|
1990
|
-
*
|
|
2453
|
+
* Runs the registry for a server.
|
|
1991
2454
|
*
|
|
1992
|
-
* @
|
|
2455
|
+
* @deprecated Use {@link Registry.startRunner} for long-running servers or {@link Registry.handler} for serverless deployments.
|
|
1993
2456
|
*/
|
|
1994
|
-
|
|
2457
|
+
start(inputConfig?: LegacyRunnerConfigInput): LegacyStartServerOutput<this>;
|
|
1995
2458
|
}
|
|
1996
2459
|
|
|
1997
|
-
interface ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1998
|
-
state?: TState;
|
|
1999
|
-
connParams?: TConnParams;
|
|
2000
|
-
connState?: TConnState;
|
|
2001
|
-
vars?: TVars;
|
|
2002
|
-
input?: TInput;
|
|
2003
|
-
database?: TDatabase;
|
|
2004
|
-
}
|
|
2005
|
-
declare const ActorConfigSchema: z.ZodObject<{
|
|
2006
|
-
onCreate: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2007
|
-
onDestroy: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2008
|
-
onWake: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2009
|
-
onSleep: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2010
|
-
onStateChange: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2011
|
-
onBeforeConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2012
|
-
onConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2013
|
-
onDisconnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2014
|
-
onBeforeActionResponse: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2015
|
-
onRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2016
|
-
onWebSocket: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2017
|
-
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>>;
|
|
2018
|
-
state: z.ZodOptional<z.ZodAny>;
|
|
2019
|
-
createState: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2020
|
-
connState: z.ZodOptional<z.ZodAny>;
|
|
2021
|
-
createConnState: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2022
|
-
vars: z.ZodOptional<z.ZodAny>;
|
|
2023
|
-
db: z.ZodOptional<z.ZodAny>;
|
|
2024
|
-
createVars: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
2025
|
-
options: z.ZodPrefault<z.ZodObject<{
|
|
2026
|
-
createVarsTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2027
|
-
createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2028
|
-
onConnectTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2029
|
-
onSleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2030
|
-
onDestroyTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2031
|
-
stateSaveInterval: z.ZodDefault<z.ZodNumber>;
|
|
2032
|
-
actionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2033
|
-
waitUntilTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2034
|
-
connectionLivenessTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2035
|
-
connectionLivenessInterval: z.ZodDefault<z.ZodNumber>;
|
|
2036
|
-
noSleep: z.ZodDefault<z.ZodBoolean>;
|
|
2037
|
-
sleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
2038
|
-
canHibernateWebSocket: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(request: Request) => boolean, (request: Request) => boolean>]>>;
|
|
2039
|
-
}, z.core.$strict>>;
|
|
2040
|
-
}, z.core.$strict>;
|
|
2041
|
-
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> = {
|
|
2042
|
-
state: TState;
|
|
2043
|
-
} | {
|
|
2044
|
-
createState: (c: CreateContext<TState, TInput, TDatabase>, input: TInput) => TState | Promise<TState>;
|
|
2045
|
-
} | Record<never, never>;
|
|
2046
|
-
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> = {
|
|
2047
|
-
connState: TConnState;
|
|
2048
|
-
} | {
|
|
2049
|
-
createConnState: (c: CreateConnStateContext<TState, TVars, TInput, TDatabase>, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
2050
|
-
} | Record<never, never>;
|
|
2051
|
-
/**
|
|
2052
|
-
* @experimental
|
|
2053
|
-
*/
|
|
2054
|
-
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> = {
|
|
2055
|
-
/**
|
|
2056
|
-
* @experimental
|
|
2057
|
-
*/
|
|
2058
|
-
vars: TVars;
|
|
2059
|
-
} | {
|
|
2060
|
-
/**
|
|
2061
|
-
* @experimental
|
|
2062
|
-
*/
|
|
2063
|
-
createVars: (c: CreateVarsContext<TState, TInput, TDatabase>, driverCtx: any) => TVars | Promise<TVars>;
|
|
2064
|
-
} | Record<never, never>;
|
|
2065
|
-
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
2066
|
-
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, ...args: any[]) => any;
|
|
2067
|
-
}
|
|
2068
2460
|
/**
|
|
2069
|
-
*
|
|
2461
|
+
* Creates a client with the actor accessor proxy.
|
|
2070
2462
|
*/
|
|
2071
|
-
|
|
2072
|
-
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>> {
|
|
2073
|
-
/**
|
|
2074
|
-
* Called when the actor is first initialized.
|
|
2075
|
-
*
|
|
2076
|
-
* Use this hook to initialize your actor's state.
|
|
2077
|
-
* This is called before any other lifecycle hooks.
|
|
2078
|
-
*/
|
|
2079
|
-
onCreate?: (c: CreateContext<TState, TInput, TDatabase>, input: TInput) => void | Promise<void>;
|
|
2080
|
-
/**
|
|
2081
|
-
* Called when the actor is destroyed.
|
|
2082
|
-
*/
|
|
2083
|
-
onDestroy?: (c: DestroyContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2084
|
-
/**
|
|
2085
|
-
* Called when the actor is started and ready to receive connections and action.
|
|
2086
|
-
*
|
|
2087
|
-
* Use this hook to initialize resources needed for the actor's operation
|
|
2088
|
-
* (timers, external connections, etc.)
|
|
2089
|
-
*
|
|
2090
|
-
* @returns Void or a Promise that resolves when startup is complete
|
|
2091
|
-
*/
|
|
2092
|
-
onWake?: (c: WakeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2093
|
-
/**
|
|
2094
|
-
* Called when the actor is stopping or sleeping.
|
|
2095
|
-
*
|
|
2096
|
-
* Use this hook to clean up resources, save state, or perform
|
|
2097
|
-
* any shutdown operations before the actor sleeps or stops.
|
|
2098
|
-
*
|
|
2099
|
-
* Not supported on all platforms.
|
|
2100
|
-
*
|
|
2101
|
-
* @returns Void or a Promise that resolves when shutdown is complete
|
|
2102
|
-
*/
|
|
2103
|
-
onSleep?: (c: SleepContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2104
|
-
/**
|
|
2105
|
-
* Called when the actor's state changes.
|
|
2106
|
-
*
|
|
2107
|
-
* Use this hook to react to state changes, such as updating
|
|
2108
|
-
* external systems or triggering events.
|
|
2109
|
-
*
|
|
2110
|
-
* State changes made within this hook will NOT trigger
|
|
2111
|
-
* another onStateChange call, preventing infinite recursion.
|
|
2112
|
-
*
|
|
2113
|
-
* @param newState The updated state
|
|
2114
|
-
*/
|
|
2115
|
-
onStateChange?: (c: StateChangeContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, newState: TState) => void;
|
|
2116
|
-
/**
|
|
2117
|
-
* Called before a client connects to the actor.
|
|
2118
|
-
*
|
|
2119
|
-
* Use this hook to determine if a connection should be accepted
|
|
2120
|
-
* and to initialize connection-specific state.
|
|
2121
|
-
*
|
|
2122
|
-
* @param opts Connection parameters including client-provided data
|
|
2123
|
-
* @returns The initial connection state or a Promise that resolves to it
|
|
2124
|
-
* @throws Throw an error to reject the connection
|
|
2125
|
-
*/
|
|
2126
|
-
onBeforeConnect?: (c: BeforeConnectContext<TState, TVars, TInput, TDatabase>, params: TConnParams) => void | Promise<void>;
|
|
2127
|
-
/**
|
|
2128
|
-
* Called when a client successfully connects to the actor.
|
|
2129
|
-
*
|
|
2130
|
-
* Use this hook to perform actions when a connection is established,
|
|
2131
|
-
* such as sending initial data or updating the actor's state.
|
|
2132
|
-
*
|
|
2133
|
-
* @param conn The connection object
|
|
2134
|
-
* @returns Void or a Promise that resolves when connection handling is complete
|
|
2135
|
-
*/
|
|
2136
|
-
onConnect?: (c: ConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2137
|
-
/**
|
|
2138
|
-
* Called when a client disconnects from the actor.
|
|
2139
|
-
*
|
|
2140
|
-
* Use this hook to clean up resources associated with the connection
|
|
2141
|
-
* or update the actor's state.
|
|
2142
|
-
*
|
|
2143
|
-
* @param conn The connection that is being closed
|
|
2144
|
-
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
2145
|
-
*/
|
|
2146
|
-
onDisconnect?: (c: DisconnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2147
|
-
/**
|
|
2148
|
-
* Called before sending an action response to the client.
|
|
2149
|
-
*
|
|
2150
|
-
* Use this hook to modify or transform the output of an action before it's sent
|
|
2151
|
-
* to the client. This is useful for formatting responses, adding metadata,
|
|
2152
|
-
* or applying transformations to the output.
|
|
2153
|
-
*
|
|
2154
|
-
* @param name The name of the action that was called
|
|
2155
|
-
* @param args The arguments that were passed to the action
|
|
2156
|
-
* @param output The output that will be sent to the client
|
|
2157
|
-
* @returns The modified output to send to the client
|
|
2158
|
-
*/
|
|
2159
|
-
onBeforeActionResponse?: <Out>(c: BeforeActionResponseContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
2160
|
-
/**
|
|
2161
|
-
* Called when a raw HTTP request is made to the actor.
|
|
2162
|
-
*
|
|
2163
|
-
* This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
|
|
2164
|
-
* Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
|
|
2165
|
-
*
|
|
2166
|
-
* @param c The request context with access to the connection
|
|
2167
|
-
* @param request The raw HTTP request object
|
|
2168
|
-
* @param opts Additional options
|
|
2169
|
-
* @returns A Response object to send back, or void to continue with default routing
|
|
2170
|
-
*/
|
|
2171
|
-
onRequest?: (c: RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, request: Request) => Response | Promise<Response>;
|
|
2172
|
-
/**
|
|
2173
|
-
* Called when a raw WebSocket connection is established to the actor.
|
|
2174
|
-
*
|
|
2175
|
-
* This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
|
|
2176
|
-
* Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
|
|
2177
|
-
*
|
|
2178
|
-
* @param c The WebSocket context with access to the connection
|
|
2179
|
-
* @param websocket The raw WebSocket connection
|
|
2180
|
-
* @param opts Additional options including the original HTTP upgrade request
|
|
2181
|
-
*/
|
|
2182
|
-
onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, websocket: UniversalWebSocket) => void | Promise<void>;
|
|
2183
|
-
actions?: TActions;
|
|
2184
|
-
}
|
|
2185
|
-
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
2186
|
-
/**
|
|
2187
|
-
* @experimental
|
|
2188
|
-
*/
|
|
2189
|
-
db: TDatabase;
|
|
2190
|
-
} | Record<never, never>;
|
|
2191
|
-
type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "onCreate" | "onDestroy" | "onWake" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> & ActorDatabaseConfig<TDatabase>;
|
|
2192
|
-
type ActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TDatabase extends AnyDatabaseProvider = undefined, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = Record<never, never>> = {
|
|
2193
|
-
types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
2194
|
-
} & Omit<z.input<typeof ActorConfigSchema>, "actions" | "onCreate" | "onDestroy" | "onWake" | "onSleep" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onRequest" | "onWebSocket" | "state" | "createState" | "connState" | "createConnState" | "vars" | "createVars" | "db"> & BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TActions> & CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> & CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> & CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> & ActorDatabaseConfig<TDatabase>;
|
|
2195
|
-
declare function test<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>(input: ActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, TDatabase, TActions>): ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
2196
|
-
declare const DocActorOptionsSchema: z.ZodObject<{
|
|
2197
|
-
createVarsTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2198
|
-
createConnStateTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2199
|
-
onConnectTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2200
|
-
onSleepTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2201
|
-
onDestroyTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2202
|
-
stateSaveInterval: z.ZodOptional<z.ZodNumber>;
|
|
2203
|
-
actionTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2204
|
-
waitUntilTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2205
|
-
connectionLivenessTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2206
|
-
connectionLivenessInterval: z.ZodOptional<z.ZodNumber>;
|
|
2207
|
-
noSleep: z.ZodOptional<z.ZodBoolean>;
|
|
2208
|
-
sleepTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2209
|
-
canHibernateWebSocket: z.ZodOptional<z.ZodBoolean>;
|
|
2210
|
-
}, z.core.$strip>;
|
|
2211
|
-
declare const DocActorConfigSchema: z.ZodObject<{
|
|
2212
|
-
state: z.ZodOptional<z.ZodUnknown>;
|
|
2213
|
-
createState: z.ZodOptional<z.ZodUnknown>;
|
|
2214
|
-
connState: z.ZodOptional<z.ZodUnknown>;
|
|
2215
|
-
createConnState: z.ZodOptional<z.ZodUnknown>;
|
|
2216
|
-
vars: z.ZodOptional<z.ZodUnknown>;
|
|
2217
|
-
createVars: z.ZodOptional<z.ZodUnknown>;
|
|
2218
|
-
db: z.ZodOptional<z.ZodUnknown>;
|
|
2219
|
-
onCreate: z.ZodOptional<z.ZodUnknown>;
|
|
2220
|
-
onDestroy: z.ZodOptional<z.ZodUnknown>;
|
|
2221
|
-
onWake: z.ZodOptional<z.ZodUnknown>;
|
|
2222
|
-
onSleep: z.ZodOptional<z.ZodUnknown>;
|
|
2223
|
-
onStateChange: z.ZodOptional<z.ZodUnknown>;
|
|
2224
|
-
onBeforeConnect: z.ZodOptional<z.ZodUnknown>;
|
|
2225
|
-
onConnect: z.ZodOptional<z.ZodUnknown>;
|
|
2226
|
-
onDisconnect: z.ZodOptional<z.ZodUnknown>;
|
|
2227
|
-
onBeforeActionResponse: z.ZodOptional<z.ZodUnknown>;
|
|
2228
|
-
onRequest: z.ZodOptional<z.ZodUnknown>;
|
|
2229
|
-
onWebSocket: z.ZodOptional<z.ZodUnknown>;
|
|
2230
|
-
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2231
|
-
options: z.ZodOptional<z.ZodObject<{
|
|
2232
|
-
createVarsTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2233
|
-
createConnStateTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2234
|
-
onConnectTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2235
|
-
onSleepTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2236
|
-
onDestroyTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2237
|
-
stateSaveInterval: z.ZodOptional<z.ZodNumber>;
|
|
2238
|
-
actionTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2239
|
-
waitUntilTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2240
|
-
connectionLivenessTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2241
|
-
connectionLivenessInterval: z.ZodOptional<z.ZodNumber>;
|
|
2242
|
-
noSleep: z.ZodOptional<z.ZodBoolean>;
|
|
2243
|
-
sleepTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2244
|
-
canHibernateWebSocket: z.ZodOptional<z.ZodBoolean>;
|
|
2245
|
-
}, z.core.$strip>>;
|
|
2246
|
-
}, z.core.$strip>;
|
|
2463
|
+
declare function createClient<A extends Registry<any>>(endpointOrConfig?: string | ClientConfigInput): Client<A>;
|
|
2247
2464
|
|
|
2248
|
-
export {
|
|
2465
|
+
export { type ActorAccessor, type ActorActionFunction, ActorClientError, type ActorConn, ActorConnDisposed, ActorConnRaw, type ActorConnStatus, ActorDefinition, ActorError, type ActorHandle, ActorHandleRaw, type AnyActorDefinition, type Client, ClientRaw, type ConnectionStateCallback, type CreateOptions, type CreateRequest, type Encoding, type EventUnsubscribe, type ExtractActorsFromRegistry, type ExtractRegistryFromClient, type GetOptions, type GetWithIdOptions, InternalError, KEYS as KV_KEYS, MalformedResponseMessage, ManagerError, type QueryOptions, type Region, type StatusChangeCallback, createClient };
|