rivetkit 2.0.24-rc.1 → 2.0.24
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/schemas/actor-persist/v2.ts +3 -3
- package/dist/schemas/actor-persist/v3.ts +274 -0
- package/dist/schemas/client-protocol/v2.ts +432 -0
- package/dist/schemas/file-system-driver/v2.ts +136 -0
- package/dist/tsup/actor/errors.cjs +2 -4
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +7 -10
- package/dist/tsup/actor/errors.d.ts +7 -10
- package/dist/tsup/actor/errors.js +9 -11
- package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.cts → actor-router-consts-DzI2szci.d.cts} +5 -9
- package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.ts → actor-router-consts-DzI2szci.d.ts} +5 -9
- package/dist/tsup/{chunk-HHFKKVLR.cjs → chunk-3543NCSN.cjs} +45 -57
- package/dist/tsup/chunk-3543NCSN.cjs.map +1 -0
- package/dist/tsup/chunk-4SHILYS5.cjs +5694 -0
- package/dist/tsup/chunk-4SHILYS5.cjs.map +1 -0
- package/dist/tsup/{chunk-ZTH3KYFH.cjs → chunk-5BZO5XPS.cjs} +3 -3
- package/dist/tsup/{chunk-ZTH3KYFH.cjs.map → chunk-5BZO5XPS.cjs.map} +1 -1
- package/dist/tsup/{chunk-PLUN2NQT.js → chunk-BAIGSF64.js} +189 -187
- package/dist/tsup/chunk-BAIGSF64.js.map +1 -0
- package/dist/tsup/{chunk-SHVX2QUR.cjs → chunk-CHLZBSI2.cjs} +17 -17
- package/dist/tsup/chunk-CHLZBSI2.cjs.map +1 -0
- package/dist/tsup/chunk-D3SLADUD.cjs +512 -0
- package/dist/tsup/chunk-D3SLADUD.cjs.map +1 -0
- package/dist/tsup/{chunk-KSRXX3Z4.cjs → chunk-D6762AOA.cjs} +20 -25
- package/dist/tsup/chunk-D6762AOA.cjs.map +1 -0
- package/dist/tsup/{chunk-7L65NNWP.cjs → chunk-DLK5YCTN.cjs} +187 -185
- package/dist/tsup/chunk-DLK5YCTN.cjs.map +1 -0
- package/dist/tsup/{chunk-YBG6R7LX.js → chunk-DUJQWGYD.js} +3 -7
- package/dist/tsup/chunk-DUJQWGYD.js.map +1 -0
- package/dist/tsup/{chunk-CD33GT6Z.js → chunk-EIPANQMF.js} +2 -2
- package/dist/tsup/{chunk-2JYPS5YM.cjs → chunk-ESMTDP7G.cjs} +6 -6
- package/dist/tsup/chunk-ESMTDP7G.cjs.map +1 -0
- package/dist/tsup/{chunk-VHGY7PU5.cjs → chunk-FVAKREFB.cjs} +1900 -1737
- package/dist/tsup/chunk-FVAKREFB.cjs.map +1 -0
- package/dist/tsup/{chunk-BLK27ES3.js → chunk-I3XT7WOF.js} +44 -56
- package/dist/tsup/chunk-I3XT7WOF.js.map +1 -0
- package/dist/tsup/{chunk-YBHYXIP6.js → chunk-IMDS5T42.js} +3 -3
- package/dist/tsup/chunk-IMDS5T42.js.map +1 -0
- package/dist/tsup/{chunk-INNFK746.cjs → chunk-J3HZJF2P.cjs} +10 -14
- package/dist/tsup/chunk-J3HZJF2P.cjs.map +1 -0
- package/dist/tsup/{chunk-BYMKMOBS.js → chunk-MBBJUHSP.js} +1844 -1681
- package/dist/tsup/chunk-MBBJUHSP.js.map +1 -0
- package/dist/tsup/{chunk-BOMZS2TJ.js → chunk-MO5CB6MD.js} +9 -9
- package/dist/tsup/chunk-MO5CB6MD.js.map +1 -0
- package/dist/tsup/chunk-OFOTPKAH.js +512 -0
- package/dist/tsup/chunk-OFOTPKAH.js.map +1 -0
- package/dist/tsup/{chunk-G64QUEDJ.js → chunk-W6RDS6NW.js} +23 -28
- package/dist/tsup/chunk-W6RDS6NW.js.map +1 -0
- package/dist/tsup/{chunk-36JJ4IQB.cjs → chunk-YC5DUHPM.cjs} +4 -8
- package/dist/tsup/chunk-YC5DUHPM.cjs.map +1 -0
- package/dist/tsup/{chunk-FX7TWFQR.js → chunk-YC7YPM2T.js} +2 -6
- package/dist/tsup/chunk-YC7YPM2T.js.map +1 -0
- package/dist/tsup/{chunk-227FEWMB.js → chunk-ZSPU5R4C.js} +3322 -2251
- package/dist/tsup/chunk-ZSPU5R4C.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +5 -7
- package/dist/tsup/client/mod.d.ts +5 -7
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{conn-B3Vhbgnd.d.ts → config-BRDYDraU.d.cts} +1119 -1047
- package/dist/tsup/{conn-DJWL3nGx.d.cts → config-Bo-blHpJ.d.ts} +1119 -1047
- package/dist/tsup/driver-helpers/mod.cjs +5 -13
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +11 -9
- package/dist/tsup/driver-helpers/mod.d.ts +11 -9
- package/dist/tsup/driver-helpers/mod.js +14 -22
- package/dist/tsup/driver-test-suite/mod.cjs +474 -303
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +6 -9
- package/dist/tsup/driver-test-suite/mod.d.ts +6 -9
- package/dist/tsup/driver-test-suite/mod.js +1085 -914
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.d.cts +5 -7
- package/dist/tsup/inspector/mod.d.ts +5 -7
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +10 -16
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +23 -25
- package/dist/tsup/mod.d.ts +23 -25
- package/dist/tsup/mod.js +17 -23
- package/dist/tsup/test/mod.cjs +11 -11
- package/dist/tsup/test/mod.d.cts +4 -6
- package/dist/tsup/test/mod.d.ts +4 -6
- package/dist/tsup/test/mod.js +10 -10
- package/dist/tsup/utils.cjs +3 -5
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +1 -2
- package/dist/tsup/utils.d.ts +1 -2
- package/dist/tsup/utils.js +2 -4
- package/package.json +13 -6
- package/src/actor/config.ts +56 -44
- package/src/actor/conn/driver.ts +61 -0
- package/src/actor/conn/drivers/http.ts +17 -0
- package/src/actor/conn/drivers/raw-request.ts +24 -0
- package/src/actor/conn/drivers/raw-websocket.ts +65 -0
- package/src/actor/conn/drivers/websocket.ts +129 -0
- package/src/actor/conn/mod.ts +232 -0
- package/src/actor/conn/persisted.ts +81 -0
- package/src/actor/conn/state-manager.ts +196 -0
- package/src/actor/contexts/action.ts +23 -0
- package/src/actor/{context.ts → contexts/actor.ts} +19 -8
- package/src/actor/contexts/conn-init.ts +31 -0
- package/src/actor/contexts/conn.ts +48 -0
- package/src/actor/contexts/create-conn-state.ts +13 -0
- package/src/actor/contexts/on-before-connect.ts +13 -0
- package/src/actor/contexts/on-connect.ts +22 -0
- package/src/actor/contexts/request.ts +48 -0
- package/src/actor/contexts/websocket.ts +48 -0
- package/src/actor/definition.ts +3 -3
- package/src/actor/driver.ts +36 -5
- package/src/actor/errors.ts +19 -24
- package/src/actor/instance/connection-manager.ts +465 -0
- package/src/actor/instance/event-manager.ts +292 -0
- package/src/actor/instance/kv.ts +15 -0
- package/src/actor/instance/mod.ts +1107 -0
- package/src/actor/instance/persisted.ts +67 -0
- package/src/actor/instance/schedule-manager.ts +349 -0
- package/src/actor/instance/state-manager.ts +502 -0
- package/src/actor/mod.ts +13 -16
- package/src/actor/protocol/old.ts +131 -43
- package/src/actor/protocol/serde.ts +19 -4
- package/src/actor/router-endpoints.ts +61 -586
- package/src/actor/router-websocket-endpoints.ts +408 -0
- package/src/actor/router.ts +63 -197
- package/src/actor/schedule.ts +1 -1
- package/src/client/actor-conn.ts +183 -249
- package/src/client/actor-handle.ts +29 -6
- package/src/client/client.ts +0 -4
- package/src/client/config.ts +1 -4
- package/src/client/mod.ts +0 -1
- package/src/client/raw-utils.ts +3 -3
- package/src/client/utils.ts +85 -39
- package/src/common/actor-router-consts.ts +5 -12
- package/src/common/{inline-websocket-adapter2.ts → inline-websocket-adapter.ts} +26 -48
- package/src/common/log.ts +1 -1
- package/src/common/router.ts +28 -17
- package/src/common/utils.ts +2 -0
- package/src/driver-helpers/mod.ts +7 -10
- package/src/driver-helpers/utils.ts +18 -9
- package/src/driver-test-suite/mod.ts +26 -50
- package/src/driver-test-suite/test-inline-client-driver.ts +27 -51
- package/src/driver-test-suite/tests/actor-conn-hibernation.ts +150 -0
- package/src/driver-test-suite/tests/actor-conn-state.ts +1 -4
- package/src/driver-test-suite/tests/actor-conn.ts +5 -9
- package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
- package/src/driver-test-suite/tests/actor-driver.ts +0 -7
- package/src/driver-test-suite/tests/actor-handle.ts +12 -12
- package/src/driver-test-suite/tests/actor-metadata.ts +1 -1
- package/src/driver-test-suite/tests/manager-driver.ts +1 -1
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +8 -8
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +6 -5
- package/src/driver-test-suite/tests/raw-http.ts +5 -5
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +7 -7
- package/src/driver-test-suite/tests/request-access.ts +4 -4
- package/src/driver-test-suite/utils.ts +6 -10
- package/src/drivers/engine/actor-driver.ts +614 -424
- package/src/drivers/engine/mod.ts +0 -1
- package/src/drivers/file-system/actor.ts +24 -12
- package/src/drivers/file-system/global-state.ts +427 -37
- package/src/drivers/file-system/manager.ts +71 -83
- package/src/drivers/file-system/mod.ts +3 -0
- package/src/drivers/file-system/utils.ts +18 -8
- package/src/engine-process/mod.ts +38 -38
- package/src/inspector/utils.ts +7 -5
- package/src/manager/driver.ts +11 -4
- package/src/manager/gateway.ts +4 -29
- package/src/manager/protocol/mod.ts +0 -2
- package/src/manager/protocol/query.ts +0 -4
- package/src/manager/router.ts +67 -64
- package/src/manager-api/actors.ts +13 -0
- package/src/mod.ts +1 -3
- package/src/registry/mod.ts +20 -20
- package/src/registry/serve.ts +9 -14
- package/src/remote-manager-driver/actor-websocket-client.ts +1 -16
- package/src/remote-manager-driver/api-endpoints.ts +13 -1
- package/src/remote-manager-driver/api-utils.ts +8 -0
- package/src/remote-manager-driver/metadata.ts +58 -0
- package/src/remote-manager-driver/mod.ts +47 -62
- package/src/remote-manager-driver/ws-proxy.ts +1 -1
- package/src/schemas/actor-persist/mod.ts +1 -1
- package/src/schemas/actor-persist/versioned.ts +56 -31
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +41 -21
- package/src/schemas/client-protocol-zod/mod.ts +103 -0
- package/src/schemas/file-system-driver/mod.ts +1 -1
- package/src/schemas/file-system-driver/versioned.ts +42 -19
- package/src/serde.ts +33 -11
- package/src/test/mod.ts +7 -3
- package/src/utils/node.ts +173 -0
- package/src/utils.ts +0 -4
- package/dist/tsup/chunk-227FEWMB.js.map +0 -1
- package/dist/tsup/chunk-2JYPS5YM.cjs.map +0 -1
- package/dist/tsup/chunk-36JJ4IQB.cjs.map +0 -1
- package/dist/tsup/chunk-7L65NNWP.cjs.map +0 -1
- package/dist/tsup/chunk-BLK27ES3.js.map +0 -1
- package/dist/tsup/chunk-BOMZS2TJ.js.map +0 -1
- package/dist/tsup/chunk-BYMKMOBS.js.map +0 -1
- package/dist/tsup/chunk-FX7TWFQR.js.map +0 -1
- package/dist/tsup/chunk-G64QUEDJ.js.map +0 -1
- package/dist/tsup/chunk-HHFKKVLR.cjs.map +0 -1
- package/dist/tsup/chunk-INNFK746.cjs.map +0 -1
- package/dist/tsup/chunk-KSRXX3Z4.cjs.map +0 -1
- package/dist/tsup/chunk-O44LFKSB.cjs +0 -4623
- package/dist/tsup/chunk-O44LFKSB.cjs.map +0 -1
- package/dist/tsup/chunk-PLUN2NQT.js.map +0 -1
- package/dist/tsup/chunk-S4UJG7ZE.js +0 -1119
- package/dist/tsup/chunk-S4UJG7ZE.js.map +0 -1
- package/dist/tsup/chunk-SHVX2QUR.cjs.map +0 -1
- package/dist/tsup/chunk-VFB23BYZ.cjs +0 -1119
- package/dist/tsup/chunk-VFB23BYZ.cjs.map +0 -1
- package/dist/tsup/chunk-VHGY7PU5.cjs.map +0 -1
- package/dist/tsup/chunk-YBG6R7LX.js.map +0 -1
- package/dist/tsup/chunk-YBHYXIP6.js.map +0 -1
- package/src/actor/action.ts +0 -178
- package/src/actor/conn-drivers.ts +0 -216
- package/src/actor/conn-socket.ts +0 -8
- package/src/actor/conn.ts +0 -272
- package/src/actor/instance.ts +0 -2336
- package/src/actor/persisted.ts +0 -49
- package/src/actor/unstable-react.ts +0 -110
- package/src/driver-test-suite/tests/actor-reconnect.ts +0 -170
- package/src/drivers/engine/kv.ts +0 -3
- package/src/manager/hono-websocket-adapter.ts +0 -393
- /package/dist/tsup/{chunk-CD33GT6Z.js.map → chunk-EIPANQMF.js.map} +0 -0
|
@@ -1,69 +1,10 @@
|
|
|
1
|
-
import { SSEStreamingApi } from 'hono/streaming';
|
|
2
|
-
import { WSContext } from 'hono/ws';
|
|
3
|
-
import { GetUpgradeWebSocket, promiseWithResolvers } from './utils.cjs';
|
|
4
1
|
import z$1, { z } from 'zod';
|
|
5
|
-
import { Logger } from 'pino';
|
|
6
2
|
import { Env, Context, Hono } from 'hono';
|
|
3
|
+
import { Logger } from 'pino';
|
|
4
|
+
import { GetUpgradeWebSocket } from './utils.js';
|
|
7
5
|
import * as nanoevents from 'nanoevents';
|
|
8
6
|
import z__default from 'zod/v4';
|
|
9
7
|
|
|
10
|
-
type uint = bigint;
|
|
11
|
-
type Init = {
|
|
12
|
-
readonly actorId: string;
|
|
13
|
-
readonly connectionId: string;
|
|
14
|
-
readonly connectionToken: string;
|
|
15
|
-
};
|
|
16
|
-
type Error$1 = {
|
|
17
|
-
readonly group: string;
|
|
18
|
-
readonly code: string;
|
|
19
|
-
readonly message: string;
|
|
20
|
-
readonly metadata: ArrayBuffer | null;
|
|
21
|
-
readonly actionId: uint | null;
|
|
22
|
-
};
|
|
23
|
-
type ActionResponse = {
|
|
24
|
-
readonly id: uint;
|
|
25
|
-
readonly output: ArrayBuffer;
|
|
26
|
-
};
|
|
27
|
-
type Event = {
|
|
28
|
-
readonly name: string;
|
|
29
|
-
readonly args: ArrayBuffer;
|
|
30
|
-
};
|
|
31
|
-
type ToClientBody = {
|
|
32
|
-
readonly tag: "Init";
|
|
33
|
-
readonly val: Init;
|
|
34
|
-
} | {
|
|
35
|
-
readonly tag: "Error";
|
|
36
|
-
readonly val: Error$1;
|
|
37
|
-
} | {
|
|
38
|
-
readonly tag: "ActionResponse";
|
|
39
|
-
readonly val: ActionResponse;
|
|
40
|
-
} | {
|
|
41
|
-
readonly tag: "Event";
|
|
42
|
-
readonly val: Event;
|
|
43
|
-
};
|
|
44
|
-
type ToClient = {
|
|
45
|
-
readonly body: ToClientBody;
|
|
46
|
-
};
|
|
47
|
-
type ActionRequest = {
|
|
48
|
-
readonly id: uint;
|
|
49
|
-
readonly name: string;
|
|
50
|
-
readonly args: ArrayBuffer;
|
|
51
|
-
};
|
|
52
|
-
type SubscriptionRequest = {
|
|
53
|
-
readonly eventName: string;
|
|
54
|
-
readonly subscribe: boolean;
|
|
55
|
-
};
|
|
56
|
-
type ToServerBody = {
|
|
57
|
-
readonly tag: "ActionRequest";
|
|
58
|
-
readonly val: ActionRequest;
|
|
59
|
-
} | {
|
|
60
|
-
readonly tag: "SubscriptionRequest";
|
|
61
|
-
readonly val: SubscriptionRequest;
|
|
62
|
-
};
|
|
63
|
-
type ToServer = {
|
|
64
|
-
readonly body: ToServerBody;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
8
|
interface RivetEvent {
|
|
68
9
|
type: string;
|
|
69
10
|
target?: any;
|
|
@@ -113,6 +54,27 @@ interface UniversalWebSocket {
|
|
|
113
54
|
onmessage?: ((event: RivetMessageEvent) => void) | null;
|
|
114
55
|
}
|
|
115
56
|
|
|
57
|
+
type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
|
|
58
|
+
type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
|
|
59
|
+
type DatabaseProvider<DB extends {
|
|
60
|
+
execute: (query: string) => any;
|
|
61
|
+
}> = {
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new database client for the actor.
|
|
64
|
+
* The result is passed to the actor context as `c.db`.
|
|
65
|
+
* @experimental
|
|
66
|
+
*/
|
|
67
|
+
createClient: (ctx: {
|
|
68
|
+
getDatabase: () => Promise<string | unknown>;
|
|
69
|
+
}) => Promise<DB>;
|
|
70
|
+
/**
|
|
71
|
+
* Runs before the actor has started.
|
|
72
|
+
* Use this to run migrations or other setup tasks.
|
|
73
|
+
* @experimental
|
|
74
|
+
*/
|
|
75
|
+
onMigrate: (client: DB) => void | Promise<void>;
|
|
76
|
+
};
|
|
77
|
+
|
|
116
78
|
declare const ActorsSchema: z.ZodRecord<z.ZodString, z.ZodType<ActorDefinition<any, any, any, any, any, any, any>, z.ZodTypeDef, ActorDefinition<any, any, any, any, any, any, any>>>;
|
|
117
79
|
type RegistryActors = z.infer<typeof ActorsSchema>;
|
|
118
80
|
/** Base config used for the actor config across all platforms. */
|
|
@@ -153,12 +115,12 @@ declare const DriverConfigSchema: z.ZodObject<{
|
|
|
153
115
|
manager: z.ZodType<ManagerDriverBuilder, z.ZodTypeDef, ManagerDriverBuilder>;
|
|
154
116
|
actor: z.ZodType<ActorDriverBuilder, z.ZodTypeDef, ActorDriverBuilder>;
|
|
155
117
|
}, "strip", z.ZodTypeAny, {
|
|
156
|
-
actor: ActorDriverBuilder;
|
|
157
118
|
name: string;
|
|
119
|
+
actor: ActorDriverBuilder;
|
|
158
120
|
manager: ManagerDriverBuilder;
|
|
159
121
|
}, {
|
|
160
|
-
actor: ActorDriverBuilder;
|
|
161
122
|
name: string;
|
|
123
|
+
actor: ActorDriverBuilder;
|
|
162
124
|
manager: ManagerDriverBuilder;
|
|
163
125
|
}>;
|
|
164
126
|
type DriverConfig = z.infer<typeof DriverConfigSchema>;
|
|
@@ -170,12 +132,12 @@ declare const RunnerConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
170
132
|
manager: z.ZodType<ManagerDriverBuilder, z.ZodTypeDef, ManagerDriverBuilder>;
|
|
171
133
|
actor: z.ZodType<ActorDriverBuilder, z.ZodTypeDef, ActorDriverBuilder>;
|
|
172
134
|
}, "strip", z.ZodTypeAny, {
|
|
173
|
-
actor: ActorDriverBuilder;
|
|
174
135
|
name: string;
|
|
136
|
+
actor: ActorDriverBuilder;
|
|
175
137
|
manager: ManagerDriverBuilder;
|
|
176
138
|
}, {
|
|
177
|
-
actor: ActorDriverBuilder;
|
|
178
139
|
name: string;
|
|
140
|
+
actor: ActorDriverBuilder;
|
|
179
141
|
manager: ManagerDriverBuilder;
|
|
180
142
|
}>>;
|
|
181
143
|
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
@@ -262,17 +224,15 @@ declare const RunnerConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
262
224
|
namespace: z.ZodDefault<z.ZodString>;
|
|
263
225
|
runnerName: z.ZodDefault<z.ZodString>;
|
|
264
226
|
encoding: z.ZodDefault<z.ZodEnum<["json", "cbor", "bare"]>>;
|
|
265
|
-
transport: z.ZodDefault<z.ZodEnum<["websocket", "sse"]>>;
|
|
266
227
|
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
267
228
|
getUpgradeWebSocket: z.ZodOptional<z.ZodType<GetUpgradeWebSocket, z.ZodTypeDef, GetUpgradeWebSocket>>;
|
|
268
|
-
|
|
229
|
+
disableMetadataLookup: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
269
230
|
}, "strip", z.ZodTypeAny, {
|
|
270
231
|
encoding: "json" | "cbor" | "bare";
|
|
271
232
|
namespace: string;
|
|
272
233
|
runnerName: string;
|
|
273
|
-
transport: "websocket" | "sse";
|
|
274
234
|
headers: Record<string, string>;
|
|
275
|
-
|
|
235
|
+
disableMetadataLookup: boolean;
|
|
276
236
|
inspector: {
|
|
277
237
|
enabled: boolean | {
|
|
278
238
|
actor: boolean;
|
|
@@ -296,8 +256,8 @@ declare const RunnerConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
296
256
|
baseLogger?: Logger | undefined;
|
|
297
257
|
};
|
|
298
258
|
driver?: {
|
|
299
|
-
actor: ActorDriverBuilder;
|
|
300
259
|
name: string;
|
|
260
|
+
actor: ActorDriverBuilder;
|
|
301
261
|
manager: ManagerDriverBuilder;
|
|
302
262
|
} | undefined;
|
|
303
263
|
endpoint?: string | undefined;
|
|
@@ -318,18 +278,17 @@ declare const RunnerConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
318
278
|
}, {
|
|
319
279
|
encoding?: "json" | "cbor" | "bare" | undefined;
|
|
320
280
|
driver?: {
|
|
321
|
-
actor: ActorDriverBuilder;
|
|
322
281
|
name: string;
|
|
282
|
+
actor: ActorDriverBuilder;
|
|
323
283
|
manager: ManagerDriverBuilder;
|
|
324
284
|
} | undefined;
|
|
325
285
|
endpoint?: string | undefined;
|
|
326
286
|
token?: string | undefined;
|
|
327
287
|
namespace?: string | undefined;
|
|
328
288
|
runnerName?: string | undefined;
|
|
329
|
-
transport?: "websocket" | "sse" | undefined;
|
|
330
289
|
headers?: Record<string, string> | undefined;
|
|
331
290
|
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
332
|
-
|
|
291
|
+
disableMetadataLookup?: boolean | undefined;
|
|
333
292
|
inspector?: {
|
|
334
293
|
enabled?: boolean | {
|
|
335
294
|
actor?: boolean | undefined;
|
|
@@ -374,10 +333,11 @@ interface ManagerDriver {
|
|
|
374
333
|
getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined>;
|
|
375
334
|
getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
|
|
376
335
|
createActor(input: CreateInput): Promise<ActorOutput>;
|
|
336
|
+
listActors(input: ListActorsInput): Promise<ActorOutput[]>;
|
|
377
337
|
sendRequest(actorId: string, actorRequest: Request): Promise<Response>;
|
|
378
|
-
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown
|
|
338
|
+
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown): Promise<UniversalWebSocket>;
|
|
379
339
|
proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
|
|
380
|
-
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown
|
|
340
|
+
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown): Promise<Response>;
|
|
381
341
|
displayInformation(): ManagerDisplayInformation;
|
|
382
342
|
extraStartupLog?: () => Record<string, unknown>;
|
|
383
343
|
modifyManagerRouter?: (registryConfig: RegistryConfig, router: Hono) => void;
|
|
@@ -416,19 +376,31 @@ interface CreateInput<E extends Env = any> {
|
|
|
416
376
|
input?: unknown;
|
|
417
377
|
region?: string;
|
|
418
378
|
}
|
|
379
|
+
interface ListActorsInput<E extends Env = any> {
|
|
380
|
+
c?: Context | undefined;
|
|
381
|
+
name: string;
|
|
382
|
+
key?: string;
|
|
383
|
+
includeDestroyed?: boolean;
|
|
384
|
+
}
|
|
419
385
|
interface ActorOutput {
|
|
420
386
|
actorId: string;
|
|
421
387
|
name: string;
|
|
422
388
|
key: ActorKey;
|
|
389
|
+
createTs?: number;
|
|
423
390
|
}
|
|
424
391
|
|
|
425
392
|
type ActorDriverBuilder = (registryConfig: RegistryConfig, runConfig: RunnerConfig, managerDriver: ManagerDriver, inlineClient: AnyClient) => ActorDriver;
|
|
426
393
|
interface ActorDriver {
|
|
427
394
|
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
428
395
|
getContext(actorId: string): unknown;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
396
|
+
/** Batch write multiple key-value pairs. Keys and values are Uint8Arrays. */
|
|
397
|
+
kvBatchPut(actorId: string, entries: [Uint8Array, Uint8Array][]): Promise<void>;
|
|
398
|
+
/** Batch read multiple keys. Returns null for keys that don't exist. */
|
|
399
|
+
kvBatchGet(actorId: string, keys: Uint8Array[]): Promise<(Uint8Array | null)[]>;
|
|
400
|
+
/** Batch delete multiple keys. */
|
|
401
|
+
kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
|
|
402
|
+
/** List all keys with a given prefix. */
|
|
403
|
+
kvListPrefix(actorId: string, prefix: Uint8Array): Promise<[Uint8Array, Uint8Array][]>;
|
|
432
404
|
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
433
405
|
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
434
406
|
/**
|
|
@@ -439,9 +411,15 @@ interface ActorDriver {
|
|
|
439
411
|
/**
|
|
440
412
|
* Requests the actor to go to sleep.
|
|
441
413
|
*
|
|
442
|
-
* This will call `
|
|
414
|
+
* This will call `ActorInstance.onStop` independently.
|
|
443
415
|
*/
|
|
444
416
|
startSleep?(actorId: string): void;
|
|
417
|
+
/**
|
|
418
|
+
* Destroys the actor and its associated data.
|
|
419
|
+
*
|
|
420
|
+
* This will call `ActorInstance.onStop` independently.
|
|
421
|
+
*/
|
|
422
|
+
startDestroy(actorId: string): void;
|
|
445
423
|
/**
|
|
446
424
|
* Shuts down the actor runner.
|
|
447
425
|
*/
|
|
@@ -450,6 +428,11 @@ interface ActorDriver {
|
|
|
450
428
|
serverlessHandleStart?(c: Context): Promise<Response>;
|
|
451
429
|
/** Extra properties to add to logs for each actor. */
|
|
452
430
|
getExtraActorLogParams?(): Record<string, string>;
|
|
431
|
+
onBeforeActorStart?(actor: AnyActorInstance): Promise<void>;
|
|
432
|
+
onCreateConn?(conn: AnyConn): void;
|
|
433
|
+
onDestroyConn?(conn: AnyConn): void;
|
|
434
|
+
onBeforePersistConn?(conn: AnyConn): void;
|
|
435
|
+
onAfterPersistConn?(conn: AnyConn): void;
|
|
453
436
|
}
|
|
454
437
|
|
|
455
438
|
type ServerlessActorDriverBuilder = (updateConfig: (config: RunnerConfig) => void) => ActorDriver;
|
|
@@ -470,27 +453,6 @@ declare class Registry<A extends RegistryActors> {
|
|
|
470
453
|
}
|
|
471
454
|
declare function setup<A extends RegistryActors>(input: RegistryConfigInput<A>): Registry<A>;
|
|
472
455
|
|
|
473
|
-
type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
|
|
474
|
-
type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
|
|
475
|
-
type DatabaseProvider<DB extends {
|
|
476
|
-
execute: (query: string) => any;
|
|
477
|
-
}> = {
|
|
478
|
-
/**
|
|
479
|
-
* Creates a new database client for the actor.
|
|
480
|
-
* The result is passed to the actor context as `c.db`.
|
|
481
|
-
* @experimental
|
|
482
|
-
*/
|
|
483
|
-
createClient: (ctx: {
|
|
484
|
-
getDatabase: () => Promise<string | unknown>;
|
|
485
|
-
}) => Promise<DB>;
|
|
486
|
-
/**
|
|
487
|
-
* Runs before the actor has started.
|
|
488
|
-
* Use this to run migrations or other setup tasks.
|
|
489
|
-
* @experimental
|
|
490
|
-
*/
|
|
491
|
-
onMigrate: (client: DB) => void | Promise<void>;
|
|
492
|
-
};
|
|
493
|
-
|
|
494
456
|
declare class Schedule {
|
|
495
457
|
#private;
|
|
496
458
|
constructor(actor: AnyActorInstance);
|
|
@@ -578,6 +540,28 @@ declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TData
|
|
|
578
540
|
* @experimental
|
|
579
541
|
*/
|
|
580
542
|
sleep(): void;
|
|
543
|
+
/**
|
|
544
|
+
* Forces the actor to destroy.
|
|
545
|
+
*
|
|
546
|
+
* This will return immediately, then call `onStop` and `onDestroy`.
|
|
547
|
+
*
|
|
548
|
+
* @experimental
|
|
549
|
+
*/
|
|
550
|
+
destroy(): void;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Base context for connection-based handlers.
|
|
555
|
+
* Extends ActorContext with connection-specific functionality.
|
|
556
|
+
*/
|
|
557
|
+
declare abstract class ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
558
|
+
readonly conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Context for a remote procedure call.
|
|
563
|
+
*/
|
|
564
|
+
declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
581
565
|
}
|
|
582
566
|
|
|
583
567
|
type AnyActorDefinition = ActorDefinition<any, any, any, any, any, any, any>;
|
|
@@ -625,19 +609,13 @@ type Encoding = z.infer<typeof EncodingSchema>;
|
|
|
625
609
|
/**
|
|
626
610
|
* Helper class that helps serialize data without re-serializing for the same encoding.
|
|
627
611
|
*/
|
|
628
|
-
declare class CachedSerializer<T> {
|
|
612
|
+
declare class CachedSerializer<TBare, TJson, T = TBare> {
|
|
629
613
|
#private;
|
|
630
|
-
constructor(data: T, versionedDataHandler: VersionedDataHandler<T
|
|
614
|
+
constructor(data: T, versionedDataHandler: VersionedDataHandler<TBare>, zodSchema: z.ZodType<TJson>, toJson: (value: T) => TJson, toBare: (value: T) => TBare);
|
|
631
615
|
get rawData(): T;
|
|
632
616
|
serialize(encoding: Encoding): OutputData;
|
|
633
617
|
}
|
|
634
618
|
|
|
635
|
-
declare const TransportSchema: z.ZodEnum<["websocket", "sse"]>;
|
|
636
|
-
/**
|
|
637
|
-
* Transport mechanism used to communicate between client & actor.
|
|
638
|
-
*/
|
|
639
|
-
type Transport = z.infer<typeof TransportSchema>;
|
|
640
|
-
|
|
641
619
|
declare const ActorKeySchema: z.ZodArray<z.ZodString, "many">;
|
|
642
620
|
type ActorKey = z.infer<typeof ActorKeySchema>;
|
|
643
621
|
declare const CreateRequestSchema: z.ZodObject<{
|
|
@@ -646,13 +624,13 @@ declare const CreateRequestSchema: z.ZodObject<{
|
|
|
646
624
|
input: z.ZodOptional<z.ZodUnknown>;
|
|
647
625
|
region: z.ZodOptional<z.ZodString>;
|
|
648
626
|
}, "strip", z.ZodTypeAny, {
|
|
649
|
-
key: string[];
|
|
650
627
|
name: string;
|
|
628
|
+
key: string[];
|
|
651
629
|
input?: unknown;
|
|
652
630
|
region?: string | undefined;
|
|
653
631
|
}, {
|
|
654
|
-
key: string[];
|
|
655
632
|
name: string;
|
|
633
|
+
key: string[];
|
|
656
634
|
input?: unknown;
|
|
657
635
|
region?: string | undefined;
|
|
658
636
|
}>;
|
|
@@ -661,42 +639,42 @@ declare const ActorQuerySchema: z.ZodUnion<[z.ZodObject<{
|
|
|
661
639
|
name: z.ZodString;
|
|
662
640
|
actorId: z.ZodString;
|
|
663
641
|
}, "strip", z.ZodTypeAny, {
|
|
664
|
-
name: string;
|
|
665
642
|
actorId: string;
|
|
666
|
-
}, {
|
|
667
643
|
name: string;
|
|
644
|
+
}, {
|
|
668
645
|
actorId: string;
|
|
646
|
+
name: string;
|
|
669
647
|
}>;
|
|
670
648
|
}, "strip", z.ZodTypeAny, {
|
|
671
649
|
getForId: {
|
|
672
|
-
name: string;
|
|
673
650
|
actorId: string;
|
|
651
|
+
name: string;
|
|
674
652
|
};
|
|
675
653
|
}, {
|
|
676
654
|
getForId: {
|
|
677
|
-
name: string;
|
|
678
655
|
actorId: string;
|
|
656
|
+
name: string;
|
|
679
657
|
};
|
|
680
658
|
}>, z.ZodObject<{
|
|
681
659
|
getForKey: z.ZodObject<{
|
|
682
660
|
name: z.ZodString;
|
|
683
661
|
key: z.ZodArray<z.ZodString, "many">;
|
|
684
662
|
}, "strip", z.ZodTypeAny, {
|
|
685
|
-
key: string[];
|
|
686
663
|
name: string;
|
|
687
|
-
}, {
|
|
688
664
|
key: string[];
|
|
665
|
+
}, {
|
|
689
666
|
name: string;
|
|
667
|
+
key: string[];
|
|
690
668
|
}>;
|
|
691
669
|
}, "strip", z.ZodTypeAny, {
|
|
692
670
|
getForKey: {
|
|
693
|
-
key: string[];
|
|
694
671
|
name: string;
|
|
672
|
+
key: string[];
|
|
695
673
|
};
|
|
696
674
|
}, {
|
|
697
675
|
getForKey: {
|
|
698
|
-
key: string[];
|
|
699
676
|
name: string;
|
|
677
|
+
key: string[];
|
|
700
678
|
};
|
|
701
679
|
}>, z.ZodObject<{
|
|
702
680
|
getOrCreateForKey: z.ZodObject<{
|
|
@@ -705,27 +683,27 @@ declare const ActorQuerySchema: z.ZodUnion<[z.ZodObject<{
|
|
|
705
683
|
input: z.ZodOptional<z.ZodUnknown>;
|
|
706
684
|
region: z.ZodOptional<z.ZodString>;
|
|
707
685
|
}, "strip", z.ZodTypeAny, {
|
|
708
|
-
key: string[];
|
|
709
686
|
name: string;
|
|
687
|
+
key: string[];
|
|
710
688
|
input?: unknown;
|
|
711
689
|
region?: string | undefined;
|
|
712
690
|
}, {
|
|
713
|
-
key: string[];
|
|
714
691
|
name: string;
|
|
692
|
+
key: string[];
|
|
715
693
|
input?: unknown;
|
|
716
694
|
region?: string | undefined;
|
|
717
695
|
}>;
|
|
718
696
|
}, "strip", z.ZodTypeAny, {
|
|
719
697
|
getOrCreateForKey: {
|
|
720
|
-
key: string[];
|
|
721
698
|
name: string;
|
|
699
|
+
key: string[];
|
|
722
700
|
input?: unknown;
|
|
723
701
|
region?: string | undefined;
|
|
724
702
|
};
|
|
725
703
|
}, {
|
|
726
704
|
getOrCreateForKey: {
|
|
727
|
-
key: string[];
|
|
728
705
|
name: string;
|
|
706
|
+
key: string[];
|
|
729
707
|
input?: unknown;
|
|
730
708
|
region?: string | undefined;
|
|
731
709
|
};
|
|
@@ -736,27 +714,27 @@ declare const ActorQuerySchema: z.ZodUnion<[z.ZodObject<{
|
|
|
736
714
|
input: z.ZodOptional<z.ZodUnknown>;
|
|
737
715
|
region: z.ZodOptional<z.ZodString>;
|
|
738
716
|
}, "strip", z.ZodTypeAny, {
|
|
739
|
-
key: string[];
|
|
740
717
|
name: string;
|
|
718
|
+
key: string[];
|
|
741
719
|
input?: unknown;
|
|
742
720
|
region?: string | undefined;
|
|
743
721
|
}, {
|
|
744
|
-
key: string[];
|
|
745
722
|
name: string;
|
|
723
|
+
key: string[];
|
|
746
724
|
input?: unknown;
|
|
747
725
|
region?: string | undefined;
|
|
748
726
|
}>;
|
|
749
727
|
}, "strip", z.ZodTypeAny, {
|
|
750
728
|
create: {
|
|
751
|
-
key: string[];
|
|
752
729
|
name: string;
|
|
730
|
+
key: string[];
|
|
753
731
|
input?: unknown;
|
|
754
732
|
region?: string | undefined;
|
|
755
733
|
};
|
|
756
734
|
}, {
|
|
757
735
|
create: {
|
|
758
|
-
key: string[];
|
|
759
736
|
name: string;
|
|
737
|
+
key: string[];
|
|
760
738
|
input?: unknown;
|
|
761
739
|
region?: string | undefined;
|
|
762
740
|
};
|
|
@@ -995,18 +973,16 @@ declare const ClientConfigSchema: z$1.ZodObject<{
|
|
|
995
973
|
/** Name of the runner. This is used to group together runners in to different pools. */
|
|
996
974
|
runnerName: z$1.ZodDefault<z$1.ZodString>;
|
|
997
975
|
encoding: z$1.ZodDefault<z$1.ZodEnum<["json", "cbor", "bare"]>>;
|
|
998
|
-
transport: z$1.ZodDefault<z$1.ZodEnum<["websocket", "sse"]>>;
|
|
999
976
|
headers: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>>;
|
|
1000
977
|
getUpgradeWebSocket: z$1.ZodOptional<z$1.ZodType<GetUpgradeWebSocket, z$1.ZodTypeDef, GetUpgradeWebSocket>>;
|
|
1001
978
|
/** Whether to automatically perform health checks when the client is created. */
|
|
1002
|
-
|
|
979
|
+
disableMetadataLookup: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodBoolean>>;
|
|
1003
980
|
}, "strip", z$1.ZodTypeAny, {
|
|
1004
981
|
encoding: "json" | "cbor" | "bare";
|
|
1005
982
|
namespace: string;
|
|
1006
983
|
runnerName: string;
|
|
1007
|
-
transport: "websocket" | "sse";
|
|
1008
984
|
headers: Record<string, string>;
|
|
1009
|
-
|
|
985
|
+
disableMetadataLookup: boolean;
|
|
1010
986
|
endpoint?: string | undefined;
|
|
1011
987
|
token?: string | undefined;
|
|
1012
988
|
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
@@ -1016,10 +992,9 @@ declare const ClientConfigSchema: z$1.ZodObject<{
|
|
|
1016
992
|
token?: string | undefined;
|
|
1017
993
|
namespace?: string | undefined;
|
|
1018
994
|
runnerName?: string | undefined;
|
|
1019
|
-
transport?: "websocket" | "sse" | undefined;
|
|
1020
995
|
headers?: Record<string, string> | undefined;
|
|
1021
996
|
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
1022
|
-
|
|
997
|
+
disableMetadataLookup?: boolean | undefined;
|
|
1023
998
|
}>;
|
|
1024
999
|
type ClientConfig = z$1.infer<typeof ClientConfigSchema>;
|
|
1025
1000
|
type ClientConfigInput = z$1.input<typeof ClientConfigSchema>;
|
|
@@ -1137,7 +1112,6 @@ interface Region {
|
|
|
1137
1112
|
}
|
|
1138
1113
|
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
1139
1114
|
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
1140
|
-
declare const TRANSPORT_SYMBOL: unique symbol;
|
|
1141
1115
|
/**
|
|
1142
1116
|
* Client for managing & connecting to actors.
|
|
1143
1117
|
*
|
|
@@ -1147,7 +1121,6 @@ declare const TRANSPORT_SYMBOL: unique symbol;
|
|
|
1147
1121
|
declare class ClientRaw {
|
|
1148
1122
|
#private;
|
|
1149
1123
|
[ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
|
|
1150
|
-
[TRANSPORT_SYMBOL]: Transport;
|
|
1151
1124
|
/**
|
|
1152
1125
|
* Creates an instance of Client.
|
|
1153
1126
|
*/
|
|
@@ -1213,596 +1186,18 @@ type Client<A extends Registry<any>> = ClientRaw & {
|
|
|
1213
1186
|
type AnyClient = Client<Registry<any>>;
|
|
1214
1187
|
declare function createClientWithDriver<A extends Registry<any>>(driver: ManagerDriver, config: ClientConfig): Client<A>;
|
|
1215
1188
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
* @param conn - The connection associated with the action
|
|
1229
|
-
*/
|
|
1230
|
-
constructor(actorContext: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
1231
|
-
/**
|
|
1232
|
-
* Get the actor state
|
|
1233
|
-
*/
|
|
1234
|
-
get state(): TState;
|
|
1235
|
-
/**
|
|
1236
|
-
* Get the actor variables
|
|
1237
|
-
*/
|
|
1238
|
-
get vars(): TVars;
|
|
1239
|
-
/**
|
|
1240
|
-
* Broadcasts an event to all connected clients.
|
|
1241
|
-
*/
|
|
1242
|
-
broadcast(name: string, ...args: any[]): void;
|
|
1243
|
-
/**
|
|
1244
|
-
* Gets the logger instance.
|
|
1245
|
-
*/
|
|
1246
|
-
get log(): Logger;
|
|
1247
|
-
/**
|
|
1248
|
-
* Gets actor ID.
|
|
1249
|
-
*/
|
|
1250
|
-
get actorId(): string;
|
|
1251
|
-
/**
|
|
1252
|
-
* Gets the actor name.
|
|
1253
|
-
*/
|
|
1254
|
-
get name(): string;
|
|
1255
|
-
/**
|
|
1256
|
-
* Gets the actor key.
|
|
1257
|
-
*/
|
|
1258
|
-
get key(): ActorKey;
|
|
1259
|
-
/**
|
|
1260
|
-
* Gets the region.
|
|
1261
|
-
*/
|
|
1262
|
-
get region(): string;
|
|
1263
|
-
/**
|
|
1264
|
-
* Gets the scheduler.
|
|
1265
|
-
*/
|
|
1266
|
-
get schedule(): Schedule;
|
|
1267
|
-
/**
|
|
1268
|
-
* Gets the map of connections.
|
|
1269
|
-
*/
|
|
1270
|
-
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>;
|
|
1271
|
-
/**
|
|
1272
|
-
* Returns the client for the given registry.
|
|
1273
|
-
*/
|
|
1274
|
-
client<R extends Registry<any>>(): Client<R>;
|
|
1275
|
-
/**
|
|
1276
|
-
* @experimental
|
|
1277
|
-
*/
|
|
1278
|
-
get db(): InferDatabaseClient<TDatabase>;
|
|
1279
|
-
/**
|
|
1280
|
-
* Forces the state to get saved.
|
|
1281
|
-
*/
|
|
1282
|
-
saveState(opts: SaveStateOptions): Promise<void>;
|
|
1283
|
-
/**
|
|
1284
|
-
* Prevents the actor from sleeping until promise is complete.
|
|
1285
|
-
*/
|
|
1286
|
-
waitUntil(promise: Promise<void>): void;
|
|
1287
|
-
/**
|
|
1288
|
-
* AbortSignal that fires when the actor is stopping.
|
|
1289
|
-
*/
|
|
1290
|
-
get abortSignal(): AbortSignal;
|
|
1291
|
-
/**
|
|
1292
|
-
* Forces the actor to sleep.
|
|
1293
|
-
*
|
|
1294
|
-
* Not supported on all drivers.
|
|
1295
|
-
*
|
|
1296
|
-
* @experimental
|
|
1297
|
-
*/
|
|
1298
|
-
sleep(): void;
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
type InitContext = ActorContext<undefined, undefined, undefined, undefined, undefined, undefined>;
|
|
1302
|
-
interface ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1303
|
-
state?: TState;
|
|
1304
|
-
connParams?: TConnParams;
|
|
1305
|
-
connState?: TConnState;
|
|
1306
|
-
vars?: TVars;
|
|
1307
|
-
input?: TInput;
|
|
1308
|
-
database?: TDatabase;
|
|
1309
|
-
}
|
|
1310
|
-
declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
1311
|
-
onCreate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1312
|
-
onStart: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1313
|
-
onStop: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1314
|
-
onStateChange: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1315
|
-
onBeforeConnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1316
|
-
onConnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1317
|
-
onDisconnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1318
|
-
onBeforeActionResponse: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1319
|
-
onFetch: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1320
|
-
onWebSocket: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1321
|
-
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>>;
|
|
1322
|
-
state: z.ZodOptional<z.ZodAny>;
|
|
1323
|
-
createState: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1324
|
-
connState: z.ZodOptional<z.ZodAny>;
|
|
1325
|
-
createConnState: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1326
|
-
vars: z.ZodOptional<z.ZodAny>;
|
|
1327
|
-
db: z.ZodOptional<z.ZodAny>;
|
|
1328
|
-
createVars: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1329
|
-
options: z.ZodDefault<z.ZodObject<{
|
|
1330
|
-
createVarsTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1331
|
-
createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1332
|
-
onConnectTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1333
|
-
onStopTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1334
|
-
stateSaveInterval: z.ZodDefault<z.ZodNumber>;
|
|
1335
|
-
actionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1336
|
-
waitUntilTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1337
|
-
connectionLivenessTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1338
|
-
connectionLivenessInterval: z.ZodDefault<z.ZodNumber>;
|
|
1339
|
-
noSleep: z.ZodDefault<z.ZodBoolean>;
|
|
1340
|
-
sleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1341
|
-
/** @experimental */
|
|
1342
|
-
canHibernatWebSocket: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodType<Request, z.ZodTypeDef, Request>], z.ZodUnknown>, z.ZodBoolean>]>>;
|
|
1343
|
-
}, "strict", z.ZodTypeAny, {
|
|
1344
|
-
createVarsTimeout: number;
|
|
1345
|
-
createConnStateTimeout: number;
|
|
1346
|
-
onConnectTimeout: number;
|
|
1347
|
-
onStopTimeout: number;
|
|
1348
|
-
stateSaveInterval: number;
|
|
1349
|
-
actionTimeout: number;
|
|
1350
|
-
waitUntilTimeout: number;
|
|
1351
|
-
connectionLivenessTimeout: number;
|
|
1352
|
-
connectionLivenessInterval: number;
|
|
1353
|
-
noSleep: boolean;
|
|
1354
|
-
sleepTimeout: number;
|
|
1355
|
-
canHibernatWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
1356
|
-
}, {
|
|
1357
|
-
createVarsTimeout?: number | undefined;
|
|
1358
|
-
createConnStateTimeout?: number | undefined;
|
|
1359
|
-
onConnectTimeout?: number | undefined;
|
|
1360
|
-
onStopTimeout?: number | undefined;
|
|
1361
|
-
stateSaveInterval?: number | undefined;
|
|
1362
|
-
actionTimeout?: number | undefined;
|
|
1363
|
-
waitUntilTimeout?: number | undefined;
|
|
1364
|
-
connectionLivenessTimeout?: number | undefined;
|
|
1365
|
-
connectionLivenessInterval?: number | undefined;
|
|
1366
|
-
noSleep?: boolean | undefined;
|
|
1367
|
-
sleepTimeout?: number | undefined;
|
|
1368
|
-
canHibernatWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
1369
|
-
}>>;
|
|
1370
|
-
}, "strict", z.ZodTypeAny, {
|
|
1371
|
-
options: {
|
|
1372
|
-
createVarsTimeout: number;
|
|
1373
|
-
createConnStateTimeout: number;
|
|
1374
|
-
onConnectTimeout: number;
|
|
1375
|
-
onStopTimeout: number;
|
|
1376
|
-
stateSaveInterval: number;
|
|
1377
|
-
actionTimeout: number;
|
|
1378
|
-
waitUntilTimeout: number;
|
|
1379
|
-
connectionLivenessTimeout: number;
|
|
1380
|
-
connectionLivenessInterval: number;
|
|
1381
|
-
noSleep: boolean;
|
|
1382
|
-
sleepTimeout: number;
|
|
1383
|
-
canHibernatWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
1384
|
-
};
|
|
1385
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1386
|
-
state?: any;
|
|
1387
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1388
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1389
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1390
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1391
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1392
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1393
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1394
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1395
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1396
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1397
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1398
|
-
connState?: any;
|
|
1399
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1400
|
-
vars?: any;
|
|
1401
|
-
db?: any;
|
|
1402
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1403
|
-
}, {
|
|
1404
|
-
state?: any;
|
|
1405
|
-
options?: {
|
|
1406
|
-
createVarsTimeout?: number | undefined;
|
|
1407
|
-
createConnStateTimeout?: number | undefined;
|
|
1408
|
-
onConnectTimeout?: number | undefined;
|
|
1409
|
-
onStopTimeout?: number | undefined;
|
|
1410
|
-
stateSaveInterval?: number | undefined;
|
|
1411
|
-
actionTimeout?: number | undefined;
|
|
1412
|
-
waitUntilTimeout?: number | undefined;
|
|
1413
|
-
connectionLivenessTimeout?: number | undefined;
|
|
1414
|
-
connectionLivenessInterval?: number | undefined;
|
|
1415
|
-
noSleep?: boolean | undefined;
|
|
1416
|
-
sleepTimeout?: number | undefined;
|
|
1417
|
-
canHibernatWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
1418
|
-
} | undefined;
|
|
1419
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1420
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1421
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1422
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1423
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1424
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1425
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1426
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1427
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1428
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1429
|
-
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1430
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1431
|
-
connState?: any;
|
|
1432
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1433
|
-
vars?: any;
|
|
1434
|
-
db?: any;
|
|
1435
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1436
|
-
}>, {
|
|
1437
|
-
options: {
|
|
1438
|
-
createVarsTimeout: number;
|
|
1439
|
-
createConnStateTimeout: number;
|
|
1440
|
-
onConnectTimeout: number;
|
|
1441
|
-
onStopTimeout: number;
|
|
1442
|
-
stateSaveInterval: number;
|
|
1443
|
-
actionTimeout: number;
|
|
1444
|
-
waitUntilTimeout: number;
|
|
1445
|
-
connectionLivenessTimeout: number;
|
|
1446
|
-
connectionLivenessInterval: number;
|
|
1447
|
-
noSleep: boolean;
|
|
1448
|
-
sleepTimeout: number;
|
|
1449
|
-
canHibernatWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
1450
|
-
};
|
|
1451
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1452
|
-
state?: any;
|
|
1453
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1454
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1455
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1456
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1457
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1458
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1459
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1460
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1461
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1462
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1463
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1464
|
-
connState?: any;
|
|
1465
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1466
|
-
vars?: any;
|
|
1467
|
-
db?: any;
|
|
1468
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1469
|
-
}, {
|
|
1470
|
-
state?: any;
|
|
1471
|
-
options?: {
|
|
1472
|
-
createVarsTimeout?: number | undefined;
|
|
1473
|
-
createConnStateTimeout?: number | undefined;
|
|
1474
|
-
onConnectTimeout?: number | undefined;
|
|
1475
|
-
onStopTimeout?: number | undefined;
|
|
1476
|
-
stateSaveInterval?: number | undefined;
|
|
1477
|
-
actionTimeout?: number | undefined;
|
|
1478
|
-
waitUntilTimeout?: number | undefined;
|
|
1479
|
-
connectionLivenessTimeout?: number | undefined;
|
|
1480
|
-
connectionLivenessInterval?: number | undefined;
|
|
1481
|
-
noSleep?: boolean | undefined;
|
|
1482
|
-
sleepTimeout?: number | undefined;
|
|
1483
|
-
canHibernatWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
1484
|
-
} | undefined;
|
|
1485
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1486
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1487
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1488
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1489
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1490
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1491
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1492
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1493
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1494
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1495
|
-
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1496
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1497
|
-
connState?: any;
|
|
1498
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1499
|
-
vars?: any;
|
|
1500
|
-
db?: any;
|
|
1501
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1502
|
-
}>, {
|
|
1503
|
-
options: {
|
|
1504
|
-
createVarsTimeout: number;
|
|
1505
|
-
createConnStateTimeout: number;
|
|
1506
|
-
onConnectTimeout: number;
|
|
1507
|
-
onStopTimeout: number;
|
|
1508
|
-
stateSaveInterval: number;
|
|
1509
|
-
actionTimeout: number;
|
|
1510
|
-
waitUntilTimeout: number;
|
|
1511
|
-
connectionLivenessTimeout: number;
|
|
1512
|
-
connectionLivenessInterval: number;
|
|
1513
|
-
noSleep: boolean;
|
|
1514
|
-
sleepTimeout: number;
|
|
1515
|
-
canHibernatWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
1516
|
-
};
|
|
1517
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1518
|
-
state?: any;
|
|
1519
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1520
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1521
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1522
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1523
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1524
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1525
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1526
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1527
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1528
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1529
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1530
|
-
connState?: any;
|
|
1531
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1532
|
-
vars?: any;
|
|
1533
|
-
db?: any;
|
|
1534
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1535
|
-
}, {
|
|
1536
|
-
state?: any;
|
|
1537
|
-
options?: {
|
|
1538
|
-
createVarsTimeout?: number | undefined;
|
|
1539
|
-
createConnStateTimeout?: number | undefined;
|
|
1540
|
-
onConnectTimeout?: number | undefined;
|
|
1541
|
-
onStopTimeout?: number | undefined;
|
|
1542
|
-
stateSaveInterval?: number | undefined;
|
|
1543
|
-
actionTimeout?: number | undefined;
|
|
1544
|
-
waitUntilTimeout?: number | undefined;
|
|
1545
|
-
connectionLivenessTimeout?: number | undefined;
|
|
1546
|
-
connectionLivenessInterval?: number | undefined;
|
|
1547
|
-
noSleep?: boolean | undefined;
|
|
1548
|
-
sleepTimeout?: number | undefined;
|
|
1549
|
-
canHibernatWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
1550
|
-
} | undefined;
|
|
1551
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1552
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1553
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1554
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1555
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1556
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1557
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1558
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1559
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1560
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1561
|
-
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1562
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1563
|
-
connState?: any;
|
|
1564
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1565
|
-
vars?: any;
|
|
1566
|
-
db?: any;
|
|
1567
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1568
|
-
}>, {
|
|
1569
|
-
options: {
|
|
1570
|
-
createVarsTimeout: number;
|
|
1571
|
-
createConnStateTimeout: number;
|
|
1572
|
-
onConnectTimeout: number;
|
|
1573
|
-
onStopTimeout: number;
|
|
1574
|
-
stateSaveInterval: number;
|
|
1575
|
-
actionTimeout: number;
|
|
1576
|
-
waitUntilTimeout: number;
|
|
1577
|
-
connectionLivenessTimeout: number;
|
|
1578
|
-
connectionLivenessInterval: number;
|
|
1579
|
-
noSleep: boolean;
|
|
1580
|
-
sleepTimeout: number;
|
|
1581
|
-
canHibernatWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
1582
|
-
};
|
|
1583
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1584
|
-
state?: any;
|
|
1585
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1586
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1587
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1588
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1589
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1590
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1591
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1592
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1593
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1594
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1595
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1596
|
-
connState?: any;
|
|
1597
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1598
|
-
vars?: any;
|
|
1599
|
-
db?: any;
|
|
1600
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1601
|
-
}, {
|
|
1602
|
-
state?: any;
|
|
1603
|
-
options?: {
|
|
1604
|
-
createVarsTimeout?: number | undefined;
|
|
1605
|
-
createConnStateTimeout?: number | undefined;
|
|
1606
|
-
onConnectTimeout?: number | undefined;
|
|
1607
|
-
onStopTimeout?: number | undefined;
|
|
1608
|
-
stateSaveInterval?: number | undefined;
|
|
1609
|
-
actionTimeout?: number | undefined;
|
|
1610
|
-
waitUntilTimeout?: number | undefined;
|
|
1611
|
-
connectionLivenessTimeout?: number | undefined;
|
|
1612
|
-
connectionLivenessInterval?: number | undefined;
|
|
1613
|
-
noSleep?: boolean | undefined;
|
|
1614
|
-
sleepTimeout?: number | undefined;
|
|
1615
|
-
canHibernatWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
1616
|
-
} | undefined;
|
|
1617
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1618
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1619
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1620
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1621
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1622
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1623
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1624
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1625
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1626
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1627
|
-
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1628
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1629
|
-
connState?: any;
|
|
1630
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1631
|
-
vars?: any;
|
|
1632
|
-
db?: any;
|
|
1633
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1634
|
-
}>;
|
|
1635
|
-
interface OnConnectOptions {
|
|
1636
|
-
/**
|
|
1637
|
-
* The request object associated with the connection.
|
|
1638
|
-
*
|
|
1639
|
-
* @experimental
|
|
1640
|
-
*/
|
|
1641
|
-
request?: Request;
|
|
1642
|
-
}
|
|
1643
|
-
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1644
|
-
state: TState;
|
|
1645
|
-
} | {
|
|
1646
|
-
createState: (c: InitContext, input: TInput) => TState | Promise<TState>;
|
|
1647
|
-
} | Record<never, never>;
|
|
1648
|
-
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1649
|
-
connState: TConnState;
|
|
1650
|
-
} | {
|
|
1651
|
-
createConnState: (c: InitContext, opts: OnConnectOptions, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
1652
|
-
} | Record<never, never>;
|
|
1653
|
-
/**
|
|
1654
|
-
* @experimental
|
|
1655
|
-
*/
|
|
1656
|
-
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1657
|
-
/**
|
|
1658
|
-
* @experimental
|
|
1659
|
-
*/
|
|
1660
|
-
vars: TVars;
|
|
1661
|
-
} | {
|
|
1662
|
-
/**
|
|
1663
|
-
* @experimental
|
|
1664
|
-
*/
|
|
1665
|
-
createVars: (c: InitContext, driverCtx: any) => TVars | Promise<TVars>;
|
|
1666
|
-
} | Record<never, never>;
|
|
1667
|
-
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1668
|
-
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, ...args: any[]) => any;
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* @experimental
|
|
1672
|
-
*/
|
|
1673
|
-
type AuthIntent = "get" | "create" | "connect" | "action" | "message";
|
|
1674
|
-
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>> {
|
|
1675
|
-
/**
|
|
1676
|
-
* Called when the actor is first initialized.
|
|
1677
|
-
*
|
|
1678
|
-
* Use this hook to initialize your actor's state.
|
|
1679
|
-
* This is called before any other lifecycle hooks.
|
|
1680
|
-
*/
|
|
1681
|
-
onCreate?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, input: TInput) => void | Promise<void>;
|
|
1682
|
-
/**
|
|
1683
|
-
* Called when the actor is started and ready to receive connections and action.
|
|
1684
|
-
*
|
|
1685
|
-
* Use this hook to initialize resources needed for the actor's operation
|
|
1686
|
-
* (timers, external connections, etc.)
|
|
1687
|
-
*
|
|
1688
|
-
* @returns Void or a Promise that resolves when startup is complete
|
|
1689
|
-
*/
|
|
1690
|
-
onStart?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1691
|
-
/**
|
|
1692
|
-
* Called when the actor is stopping or sleeping.
|
|
1693
|
-
*
|
|
1694
|
-
* Use this hook to clean up resources, save state, or perform
|
|
1695
|
-
* any shutdown operations before the actor sleeps or stops.
|
|
1696
|
-
*
|
|
1697
|
-
* Not supported on all platforms.
|
|
1698
|
-
*
|
|
1699
|
-
* @returns Void or a Promise that resolves when shutdown is complete
|
|
1700
|
-
*/
|
|
1701
|
-
onStop?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1702
|
-
/**
|
|
1703
|
-
* Called when the actor's state changes.
|
|
1704
|
-
*
|
|
1705
|
-
* Use this hook to react to state changes, such as updating
|
|
1706
|
-
* external systems or triggering events.
|
|
1707
|
-
*
|
|
1708
|
-
* State changes made within this hook will NOT trigger
|
|
1709
|
-
* another onStateChange call, preventing infinite recursion.
|
|
1710
|
-
*
|
|
1711
|
-
* @param newState The updated state
|
|
1712
|
-
*/
|
|
1713
|
-
onStateChange?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, newState: TState) => void;
|
|
1714
|
-
/**
|
|
1715
|
-
* Called before a client connects to the actor.
|
|
1716
|
-
*
|
|
1717
|
-
* Use this hook to determine if a connection should be accepted
|
|
1718
|
-
* and to initialize connection-specific state.
|
|
1719
|
-
*
|
|
1720
|
-
* @param opts Connection parameters including client-provided data
|
|
1721
|
-
* @returns The initial connection state or a Promise that resolves to it
|
|
1722
|
-
* @throws Throw an error to reject the connection
|
|
1723
|
-
*/
|
|
1724
|
-
onBeforeConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, opts: OnConnectOptions, params: TConnParams) => void | Promise<void>;
|
|
1725
|
-
/**
|
|
1726
|
-
* Called when a client successfully connects to the actor.
|
|
1727
|
-
*
|
|
1728
|
-
* Use this hook to perform actions when a connection is established,
|
|
1729
|
-
* such as sending initial data or updating the actor's state.
|
|
1730
|
-
*
|
|
1731
|
-
* @param conn The connection object
|
|
1732
|
-
* @returns Void or a Promise that resolves when connection handling is complete
|
|
1733
|
-
*/
|
|
1734
|
-
onConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1735
|
-
/**
|
|
1736
|
-
* Called when a client disconnects from the actor.
|
|
1737
|
-
*
|
|
1738
|
-
* Use this hook to clean up resources associated with the connection
|
|
1739
|
-
* or update the actor's state.
|
|
1740
|
-
*
|
|
1741
|
-
* @param conn The connection that is being closed
|
|
1742
|
-
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
1743
|
-
*/
|
|
1744
|
-
onDisconnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1745
|
-
/**
|
|
1746
|
-
* Called before sending an action response to the client.
|
|
1747
|
-
*
|
|
1748
|
-
* Use this hook to modify or transform the output of an action before it's sent
|
|
1749
|
-
* to the client. This is useful for formatting responses, adding metadata,
|
|
1750
|
-
* or applying transformations to the output.
|
|
1751
|
-
*
|
|
1752
|
-
* @param name The name of the action that was called
|
|
1753
|
-
* @param args The arguments that were passed to the action
|
|
1754
|
-
* @param output The output that will be sent to the client
|
|
1755
|
-
* @returns The modified output to send to the client
|
|
1756
|
-
*/
|
|
1757
|
-
onBeforeActionResponse?: <Out>(c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
1758
|
-
/**
|
|
1759
|
-
* Called when a raw HTTP request is made to the actor.
|
|
1760
|
-
*
|
|
1761
|
-
* This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
|
|
1762
|
-
* Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
|
|
1763
|
-
*
|
|
1764
|
-
* @param request The raw HTTP request object
|
|
1765
|
-
* @returns A Response object to send back, or void to continue with default routing
|
|
1766
|
-
*/
|
|
1767
|
-
onFetch?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, request: Request, opts: {}) => Response | Promise<Response>;
|
|
1768
|
-
/**
|
|
1769
|
-
* Called when a raw WebSocket connection is established to the actor.
|
|
1770
|
-
*
|
|
1771
|
-
* This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
|
|
1772
|
-
* Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
|
|
1773
|
-
*
|
|
1774
|
-
* @param websocket The raw WebSocket connection
|
|
1775
|
-
* @param request The original HTTP upgrade request
|
|
1776
|
-
*/
|
|
1777
|
-
onWebSocket?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, websocket: UniversalWebSocket, opts: {
|
|
1778
|
-
request: Request;
|
|
1779
|
-
}) => void | Promise<void>;
|
|
1780
|
-
actions: TActions;
|
|
1781
|
-
}
|
|
1782
|
-
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
1783
|
-
/**
|
|
1784
|
-
* @experimental
|
|
1785
|
-
*/
|
|
1786
|
-
db: TDatabase;
|
|
1787
|
-
} | Record<never, never>;
|
|
1788
|
-
type ActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> = Omit<z.infer<typeof ActorConfigSchema>, "actions" | "onCreate" | "onStart" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onFetch" | "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>;
|
|
1789
|
-
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>> = {
|
|
1790
|
-
types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
1791
|
-
} & Omit<z.input<typeof ActorConfigSchema>, "actions" | "onCreate" | "onStart" | "onStop" | "onStateChange" | "onBeforeConnect" | "onConnect" | "onDisconnect" | "onBeforeActionResponse" | "onFetch" | "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>;
|
|
1792
|
-
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>;
|
|
1793
|
-
|
|
1794
|
-
declare const ActorId: z__default.core.$ZodBranded<z__default.ZodString, "ActorId">;
|
|
1795
|
-
type ActorId = z__default.infer<typeof ActorId>;
|
|
1796
|
-
declare enum ActorFeature {
|
|
1797
|
-
Logs = "logs",
|
|
1798
|
-
Config = "config",
|
|
1799
|
-
Connections = "connections",
|
|
1800
|
-
State = "state",
|
|
1801
|
-
Console = "console",
|
|
1802
|
-
Runtime = "runtime",
|
|
1803
|
-
Metrics = "metrics",
|
|
1804
|
-
EventsMonitoring = "events-monitoring",
|
|
1805
|
-
Database = "database"
|
|
1189
|
+
declare const ActorId: z__default.core.$ZodBranded<z__default.ZodString, "ActorId">;
|
|
1190
|
+
type ActorId = z__default.infer<typeof ActorId>;
|
|
1191
|
+
declare enum ActorFeature {
|
|
1192
|
+
Logs = "logs",
|
|
1193
|
+
Config = "config",
|
|
1194
|
+
Connections = "connections",
|
|
1195
|
+
State = "state",
|
|
1196
|
+
Console = "console",
|
|
1197
|
+
Runtime = "runtime",
|
|
1198
|
+
Metrics = "metrics",
|
|
1199
|
+
EventsMonitoring = "events-monitoring",
|
|
1200
|
+
Database = "database"
|
|
1806
1201
|
}
|
|
1807
1202
|
declare const ActorSchema: z__default.ZodObject<{
|
|
1808
1203
|
id: z__default.core.$ZodBranded<z__default.ZodString, "ActorId">;
|
|
@@ -1958,7 +1353,7 @@ type Tables = z__default.infer<typeof TablesSchema>;
|
|
|
1958
1353
|
declare const ColumnSchema: z__default.ZodObject<{
|
|
1959
1354
|
cid: z__default.ZodNumber;
|
|
1960
1355
|
name: z__default.ZodString;
|
|
1961
|
-
type: z__default.ZodPipe<z__default.ZodString, z__default.ZodTransform<"
|
|
1356
|
+
type: z__default.ZodPipe<z__default.ZodString, z__default.ZodTransform<"blob" | "integer" | "text" | "real" | "numeric" | "serial", string>>;
|
|
1962
1357
|
notnull: z__default.ZodCoercedBoolean<unknown>;
|
|
1963
1358
|
dflt_value: z__default.ZodNullable<z__default.ZodString>;
|
|
1964
1359
|
pk: z__default.ZodNullable<z__default.ZodCoercedBoolean<unknown>>;
|
|
@@ -1967,7 +1362,7 @@ type Column = z__default.infer<typeof ColumnSchema>;
|
|
|
1967
1362
|
declare const ColumnsSchema: z__default.ZodArray<z__default.ZodObject<{
|
|
1968
1363
|
cid: z__default.ZodNumber;
|
|
1969
1364
|
name: z__default.ZodString;
|
|
1970
|
-
type: z__default.ZodPipe<z__default.ZodString, z__default.ZodTransform<"
|
|
1365
|
+
type: z__default.ZodPipe<z__default.ZodString, z__default.ZodTransform<"blob" | "integer" | "text" | "real" | "numeric" | "serial", string>>;
|
|
1971
1366
|
notnull: z__default.ZodCoercedBoolean<unknown>;
|
|
1972
1367
|
dflt_value: z__default.ZodNullable<z__default.ZodString>;
|
|
1973
1368
|
pk: z__default.ZodNullable<z__default.ZodCoercedBoolean<unknown>>;
|
|
@@ -2006,390 +1401,1067 @@ declare const CreateActorSchema: z__default.ZodObject<{
|
|
|
2006
1401
|
}, z__default.core.$strip>;
|
|
2007
1402
|
type CreateActor = z__default.infer<typeof CreateActorSchema>;
|
|
2008
1403
|
|
|
2009
|
-
interface ActorInspectorAccessors {
|
|
2010
|
-
isStateEnabled: () => Promise<boolean>;
|
|
2011
|
-
getState: () => Promise<unknown>;
|
|
2012
|
-
setState: (state: unknown) => Promise<void>;
|
|
2013
|
-
isDbEnabled: () => Promise<boolean>;
|
|
2014
|
-
getDb: () => Promise<InferDatabaseClient<AnyDatabaseProvider>>;
|
|
2015
|
-
getRpcs: () => Promise<string[]>;
|
|
2016
|
-
getConnections: () => Promise<Connection[]>;
|
|
2017
|
-
executeAction: (name: string, params?: unknown[]) => Promise<unknown>;
|
|
1404
|
+
interface ActorInspectorAccessors {
|
|
1405
|
+
isStateEnabled: () => Promise<boolean>;
|
|
1406
|
+
getState: () => Promise<unknown>;
|
|
1407
|
+
setState: (state: unknown) => Promise<void>;
|
|
1408
|
+
isDbEnabled: () => Promise<boolean>;
|
|
1409
|
+
getDb: () => Promise<InferDatabaseClient<AnyDatabaseProvider>>;
|
|
1410
|
+
getRpcs: () => Promise<string[]>;
|
|
1411
|
+
getConnections: () => Promise<Connection[]>;
|
|
1412
|
+
executeAction: (name: string, params?: unknown[]) => Promise<unknown>;
|
|
1413
|
+
}
|
|
1414
|
+
interface ActorInspectorEmitterEvents {
|
|
1415
|
+
stateUpdated: (state: unknown) => void;
|
|
1416
|
+
connectionUpdated: () => void;
|
|
1417
|
+
eventFired: (event: RealtimeEvent) => void;
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Provides a unified interface for inspecting actor external and internal state.
|
|
1421
|
+
*/
|
|
1422
|
+
declare class ActorInspector {
|
|
1423
|
+
#private;
|
|
1424
|
+
readonly accessors: ActorInspectorAccessors;
|
|
1425
|
+
readonly emitter: nanoevents.Emitter<ActorInspectorEmitterEvents>;
|
|
1426
|
+
get lastRealtimeEvents(): (({
|
|
1427
|
+
type: "action";
|
|
1428
|
+
name: string;
|
|
1429
|
+
args: any[];
|
|
1430
|
+
connId: string;
|
|
1431
|
+
} | {
|
|
1432
|
+
type: "broadcast";
|
|
1433
|
+
eventName: string;
|
|
1434
|
+
args: any[];
|
|
1435
|
+
} | {
|
|
1436
|
+
type: "subscribe";
|
|
1437
|
+
eventName: string;
|
|
1438
|
+
connId: string;
|
|
1439
|
+
} | {
|
|
1440
|
+
type: "unsubscribe";
|
|
1441
|
+
eventName: string;
|
|
1442
|
+
connId: string;
|
|
1443
|
+
} | {
|
|
1444
|
+
type: "event";
|
|
1445
|
+
eventName: string;
|
|
1446
|
+
args: any[];
|
|
1447
|
+
connId: string;
|
|
1448
|
+
}) & {
|
|
1449
|
+
id: string;
|
|
1450
|
+
timestamp: number;
|
|
1451
|
+
})[];
|
|
1452
|
+
constructor(accessors: () => ActorInspectorAccessors);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
declare enum DriverReadyState {
|
|
1456
|
+
UNKNOWN = -1,
|
|
1457
|
+
CONNECTING = 0,
|
|
1458
|
+
OPEN = 1,
|
|
1459
|
+
CLOSING = 2,
|
|
1460
|
+
CLOSED = 3
|
|
1461
|
+
}
|
|
1462
|
+
interface ConnDriver {
|
|
1463
|
+
/** The type of driver. Used for debug purposes only. */
|
|
1464
|
+
type: string;
|
|
1465
|
+
/**
|
|
1466
|
+
* If defined, this connection driver talks the RivetKit client driver (see
|
|
1467
|
+
* schemas/client-protocol/).
|
|
1468
|
+
*
|
|
1469
|
+
* If enabled, events like `Init`, subscription events, etc. will be sent
|
|
1470
|
+
* to this connection.
|
|
1471
|
+
*/
|
|
1472
|
+
rivetKitProtocol?: {
|
|
1473
|
+
/** Sends a RivetKit client message. */
|
|
1474
|
+
sendMessage(actor: AnyActorInstance, conn: AnyConn, message: CachedSerializer<any, any, any>): void;
|
|
1475
|
+
};
|
|
1476
|
+
/**
|
|
1477
|
+
* If the connection can be hibernated. If true, this will allow the actor to go to sleep while the connection is still active.
|
|
1478
|
+
**/
|
|
1479
|
+
hibernatable?: {
|
|
1480
|
+
gatewayId: ArrayBuffer;
|
|
1481
|
+
requestId: ArrayBuffer;
|
|
1482
|
+
};
|
|
1483
|
+
/**
|
|
1484
|
+
* 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.
|
|
1485
|
+
*/
|
|
1486
|
+
disconnect(actor: AnyActorInstance, conn: AnyConn, reason?: string): Promise<void>;
|
|
1487
|
+
/** Terminates the connection without graceful handling. */
|
|
1488
|
+
terminate?(actor: AnyActorInstance, conn: AnyConn): void;
|
|
1489
|
+
/**
|
|
1490
|
+
* Returns the ready state of the connection.
|
|
1491
|
+
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
|
|
1492
|
+
*/
|
|
1493
|
+
getConnectionReadyState(actor: AnyActorInstance, conn: AnyConn): DriverReadyState | undefined;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* Persisted data structures for connections.
|
|
1498
|
+
*
|
|
1499
|
+
* Keep this file in sync with the Connection section of rivetkit-typescript/packages/rivetkit/schemas/actor-persist/
|
|
1500
|
+
*/
|
|
1501
|
+
|
|
1502
|
+
type GatewayId = ArrayBuffer;
|
|
1503
|
+
type RequestId = ArrayBuffer;
|
|
1504
|
+
/** Event subscription for connection */
|
|
1505
|
+
interface PersistedSubscription {
|
|
1506
|
+
eventName: string;
|
|
1507
|
+
}
|
|
1508
|
+
/** Connection associated with hibernatable WebSocket that should persist across lifecycles */
|
|
1509
|
+
interface PersistedConn<CP, CS> {
|
|
1510
|
+
/** Connection ID generated by RivetKit */
|
|
1511
|
+
id: string;
|
|
1512
|
+
parameters: CP;
|
|
1513
|
+
state: CS;
|
|
1514
|
+
subscriptions: PersistedSubscription[];
|
|
1515
|
+
gatewayId: GatewayId;
|
|
1516
|
+
requestId: RequestId;
|
|
1517
|
+
serverMessageIndex: number;
|
|
1518
|
+
clientMessageIndex: number;
|
|
1519
|
+
requestPath: string;
|
|
1520
|
+
requestHeaders: Record<string, string>;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* Manages all connection-related operations for an actor instance.
|
|
1525
|
+
* Handles connection creation, tracking, hibernation, and cleanup.
|
|
1526
|
+
*/
|
|
1527
|
+
declare class ConnectionManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
1528
|
+
#private;
|
|
1529
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>);
|
|
1530
|
+
get connections(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
1531
|
+
getConnForId(id: string): Conn<S, CP, CS, V, I, DB> | undefined;
|
|
1532
|
+
get connsWithPersistChanged(): Set<ConnId>;
|
|
1533
|
+
clearConnWithPersistChanged(): void;
|
|
1534
|
+
markConnWithPersistChanged(conn: Conn<S, CP, CS, V, I, DB>): void;
|
|
1535
|
+
/**
|
|
1536
|
+
* Handles pre-connection logic (i.e. auth & create state) before actually connecting the connection.
|
|
1537
|
+
*/
|
|
1538
|
+
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>>;
|
|
1539
|
+
/**
|
|
1540
|
+
* Adds a connection form prepareConn to the actor and calls onConnect.
|
|
1541
|
+
*
|
|
1542
|
+
* This method is intentionally not async since it needs to be called in
|
|
1543
|
+
* `onOpen` for WebSockets. If this is async, the order of open events will
|
|
1544
|
+
* be messed up and cause race conditions that can drop WebSocket messages.
|
|
1545
|
+
* So all async work in prepareConn.
|
|
1546
|
+
*/
|
|
1547
|
+
connectConn(conn: Conn<S, CP, CS, V, I, DB>): void;
|
|
1548
|
+
/**
|
|
1549
|
+
* Handle connection disconnection.
|
|
1550
|
+
*
|
|
1551
|
+
* This is called by `Conn.disconnect`. This should not call `Conn.disconnect.`
|
|
1552
|
+
*/
|
|
1553
|
+
connDisconnected(conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
1554
|
+
/**
|
|
1555
|
+
* Utilify function for call sites that don't need a separate prepare and connect phase.
|
|
1556
|
+
*/
|
|
1557
|
+
prepareAndConnectConn(driver: ConnDriver, params: CP, request: Request | undefined, requestPath: string | undefined, requestHeaders: Record<string, string> | undefined): Promise<Conn<S, CP, CS, V, I, DB>>;
|
|
1558
|
+
/**
|
|
1559
|
+
* Restores connections from persisted data during actor initialization.
|
|
1560
|
+
*/
|
|
1561
|
+
restoreConnections(connections: PersistedConn<CP, CS>[]): void;
|
|
1562
|
+
findHibernatableConn(gatewayIdBuf: ArrayBuffer, requestIdBuf: ArrayBuffer): Conn<S, CP, CS, V, I, DB> | undefined;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/**
|
|
1566
|
+
* Manages event subscriptions and broadcasting for actor instances.
|
|
1567
|
+
* Handles subscription tracking and efficient message distribution to connected clients.
|
|
1568
|
+
*/
|
|
1569
|
+
declare class EventManager<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
1570
|
+
#private;
|
|
1571
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>);
|
|
1572
|
+
/**
|
|
1573
|
+
* Adds a subscription for a connection to an event.
|
|
1574
|
+
*
|
|
1575
|
+
* @param eventName - The name of the event to subscribe to
|
|
1576
|
+
* @param connection - The connection subscribing to the event
|
|
1577
|
+
* @param fromPersist - Whether this subscription is being restored from persistence
|
|
1578
|
+
*/
|
|
1579
|
+
addSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB>, fromPersist: boolean): void;
|
|
1580
|
+
/**
|
|
1581
|
+
* Removes a subscription for a connection from an event.
|
|
1582
|
+
*
|
|
1583
|
+
* @param eventName - The name of the event to unsubscribe from
|
|
1584
|
+
* @param connection - The connection unsubscribing from the event
|
|
1585
|
+
* @param fromRemoveConn - Whether this is being called as part of connection removal
|
|
1586
|
+
*/
|
|
1587
|
+
removeSubscription(eventName: string, connection: Conn<S, CP, CS, V, I, DB>, fromRemoveConn: boolean): void;
|
|
1588
|
+
/**
|
|
1589
|
+
* Broadcasts an event to all subscribed connections.
|
|
1590
|
+
*
|
|
1591
|
+
* @param name - The name of the event to broadcast
|
|
1592
|
+
* @param args - The arguments to send with the event
|
|
1593
|
+
*/
|
|
1594
|
+
broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
1595
|
+
/**
|
|
1596
|
+
* Gets all subscribers for a specific event.
|
|
1597
|
+
*
|
|
1598
|
+
* @param eventName - The name of the event
|
|
1599
|
+
* @returns Set of connections subscribed to the event, or undefined if no subscribers
|
|
1600
|
+
*/
|
|
1601
|
+
getSubscribers(eventName: string): Set<Conn<S, CP, CS, V, I, DB>> | undefined;
|
|
1602
|
+
/**
|
|
1603
|
+
* Gets all events and their subscriber counts.
|
|
1604
|
+
*
|
|
1605
|
+
* @returns Map of event names to subscriber counts
|
|
1606
|
+
*/
|
|
1607
|
+
getEventStats(): Map<string, number>;
|
|
1608
|
+
/**
|
|
1609
|
+
* Clears all subscriptions for a connection.
|
|
1610
|
+
* Used during connection cleanup.
|
|
1611
|
+
*
|
|
1612
|
+
* @param connection - The connection to clear subscriptions for
|
|
1613
|
+
*/
|
|
1614
|
+
clearConnectionSubscriptions(connection: Conn<S, CP, CS, V, I, DB>): void;
|
|
1615
|
+
/**
|
|
1616
|
+
* Gets the total number of unique events being subscribed to.
|
|
1617
|
+
*/
|
|
1618
|
+
get eventCount(): number;
|
|
1619
|
+
/**
|
|
1620
|
+
* Gets the total number of subscriptions across all events.
|
|
1621
|
+
*/
|
|
1622
|
+
get totalSubscriptionCount(): number;
|
|
1623
|
+
/**
|
|
1624
|
+
* Checks if an event has any subscribers.
|
|
1625
|
+
*
|
|
1626
|
+
* @param eventName - The name of the event to check
|
|
1627
|
+
* @returns True if the event has at least one subscriber
|
|
1628
|
+
*/
|
|
1629
|
+
hasSubscribers(eventName: string): boolean;
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Persisted data structures for actors.
|
|
1634
|
+
*
|
|
1635
|
+
* Keep this file in sync with the Connection section of rivetkit-typescript/packages/rivetkit/schemas/actor-persist/
|
|
1636
|
+
*/
|
|
1637
|
+
|
|
1638
|
+
type Cbor = ArrayBuffer;
|
|
1639
|
+
/** Scheduled event to be executed at a specific timestamp */
|
|
1640
|
+
interface PersistedScheduleEvent {
|
|
1641
|
+
eventId: string;
|
|
1642
|
+
timestamp: number;
|
|
1643
|
+
action: string;
|
|
1644
|
+
args?: Cbor;
|
|
2018
1645
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
1646
|
+
/** State object that gets automatically persisted to storage */
|
|
1647
|
+
interface PersistedActor<S, I> {
|
|
1648
|
+
/** Input data passed to the actor on initialization */
|
|
1649
|
+
input?: I;
|
|
1650
|
+
hasInitialized: boolean;
|
|
1651
|
+
state: S;
|
|
1652
|
+
scheduledEvents: PersistedScheduleEvent[];
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
interface SaveStateOptions {
|
|
1656
|
+
/**
|
|
1657
|
+
* Forces the state to be saved immediately. This function will return when the state has saved successfully.
|
|
1658
|
+
*/
|
|
1659
|
+
immediate?: boolean;
|
|
1660
|
+
/** Bypass ready check for stopping. */
|
|
1661
|
+
allowStoppingState?: boolean;
|
|
1662
|
+
/**
|
|
1663
|
+
* Maximum time in milliseconds to wait before forcing a save.
|
|
1664
|
+
*
|
|
1665
|
+
* If a save is already scheduled to occur later than this deadline, it will be rescheduled earlier.
|
|
1666
|
+
*/
|
|
1667
|
+
maxWait?: number;
|
|
2023
1668
|
}
|
|
2024
1669
|
/**
|
|
2025
|
-
*
|
|
1670
|
+
* Manages actor state persistence, proxying, and synchronization.
|
|
1671
|
+
* Handles automatic state change detection and throttled persistence to KV storage.
|
|
2026
1672
|
*/
|
|
2027
|
-
declare class
|
|
1673
|
+
declare class StateManager$1<S, CP, CS, I> {
|
|
2028
1674
|
#private;
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
get
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
1675
|
+
constructor(actor: ActorInstance<S, CP, CS, any, I, any>, actorDriver: ActorDriver, config: any);
|
|
1676
|
+
get persist(): PersistedActor<S, I>;
|
|
1677
|
+
get persistRaw(): PersistedActor<S, I>;
|
|
1678
|
+
get persistChanged(): boolean;
|
|
1679
|
+
get state(): S;
|
|
1680
|
+
set state(value: S);
|
|
1681
|
+
get stateEnabled(): boolean;
|
|
1682
|
+
/**
|
|
1683
|
+
* Initializes state from persisted data or creates new state.
|
|
1684
|
+
*/
|
|
1685
|
+
initializeState(persistData: PersistedActor<S, I>): Promise<void>;
|
|
1686
|
+
/**
|
|
1687
|
+
* Creates proxy for persist object that handles automatic state change detection.
|
|
1688
|
+
*/
|
|
1689
|
+
initPersistProxy(target: PersistedActor<S, I>): undefined;
|
|
1690
|
+
/**
|
|
1691
|
+
* Forces the state to get saved.
|
|
1692
|
+
*/
|
|
1693
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
1694
|
+
/**
|
|
1695
|
+
* Throttled save state method. Used to write to KV at a reasonable cadence.
|
|
1696
|
+
*
|
|
1697
|
+
* Passing a maxWait will override the stateSaveInterval with the min
|
|
1698
|
+
* between that and the maxWait.
|
|
1699
|
+
*/
|
|
1700
|
+
savePersistThrottled(maxWait?: number): void;
|
|
1701
|
+
/**
|
|
1702
|
+
* Clears any pending save timeout.
|
|
1703
|
+
*/
|
|
1704
|
+
clearPendingSaveTimeout(): void;
|
|
1705
|
+
/**
|
|
1706
|
+
* Waits for any pending write operations to complete.
|
|
1707
|
+
*/
|
|
1708
|
+
waitForPendingWrites(): Promise<void>;
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
1712
|
+
type AnyActorInstance = ActorInstance<any, any, any, any, any, any>;
|
|
1713
|
+
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
1714
|
+
#private;
|
|
1715
|
+
actorContext: ActorContext<S, CP, CS, V, I, DB>;
|
|
1716
|
+
driver: ActorDriver;
|
|
1717
|
+
connectionManager: ConnectionManager<S, CP, CS, V, I, DB>;
|
|
1718
|
+
stateManager: StateManager$1<S, CP, CS, I>;
|
|
1719
|
+
eventManager: EventManager<S, CP, CS, V, I, DB>;
|
|
1720
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB>);
|
|
1721
|
+
get log(): Logger;
|
|
1722
|
+
get rLog(): Logger;
|
|
1723
|
+
get isStopping(): boolean;
|
|
1724
|
+
get id(): string;
|
|
1725
|
+
get name(): string;
|
|
1726
|
+
get key(): ActorKey;
|
|
1727
|
+
get region(): string;
|
|
1728
|
+
get inlineClient(): Client<Registry<any>>;
|
|
1729
|
+
get inspector(): ActorInspector;
|
|
1730
|
+
get inspectorToken(): string | undefined;
|
|
1731
|
+
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
1732
|
+
get schedule(): Schedule;
|
|
1733
|
+
get abortSignal(): AbortSignal;
|
|
1734
|
+
get actions(): string[];
|
|
1735
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB>;
|
|
1736
|
+
get persist(): PersistedActor<S, I>;
|
|
1737
|
+
get state(): S;
|
|
1738
|
+
set state(value: S);
|
|
1739
|
+
get stateEnabled(): boolean;
|
|
1740
|
+
get connStateEnabled(): boolean;
|
|
1741
|
+
get vars(): V;
|
|
1742
|
+
get db(): InferDatabaseClient<DB>;
|
|
1743
|
+
start(actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
1744
|
+
isReady(): boolean;
|
|
1745
|
+
assertReady(allowStoppingState?: boolean): void;
|
|
1746
|
+
onStop(mode: "sleep" | "destroy"): Promise<void>;
|
|
1747
|
+
startSleep(): void;
|
|
1748
|
+
startDestroy(): void;
|
|
1749
|
+
beginHonoHttpRequest(): void;
|
|
1750
|
+
endHonoHttpRequest(): void;
|
|
1751
|
+
processMessage(message: {
|
|
1752
|
+
body: {
|
|
1753
|
+
tag: "ActionRequest";
|
|
1754
|
+
val: {
|
|
1755
|
+
id: bigint;
|
|
1756
|
+
name: string;
|
|
1757
|
+
args: unknown;
|
|
1758
|
+
};
|
|
1759
|
+
} | {
|
|
1760
|
+
tag: "SubscriptionRequest";
|
|
1761
|
+
val: {
|
|
1762
|
+
eventName: string;
|
|
1763
|
+
subscribe: boolean;
|
|
1764
|
+
};
|
|
1765
|
+
};
|
|
1766
|
+
}, conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
1767
|
+
executeAction(ctx: ActionContext<S, CP, CS, V, I, DB>, actionName: string, args: unknown[]): Promise<unknown>;
|
|
1768
|
+
handleRawRequest(conn: Conn<S, CP, CS, V, I, DB>, request: Request): Promise<Response>;
|
|
1769
|
+
handleRawWebSocket(conn: Conn<S, CP, CS, V, I, DB>, websocket: UniversalWebSocket, request?: Request): void;
|
|
1770
|
+
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
1771
|
+
onAlarm(): Promise<void>;
|
|
1772
|
+
waitUntil(promise: Promise<void>): void;
|
|
1773
|
+
resetSleepTimer(): void;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/** Pick a subset of persisted data used to represent ephemeral connections */
|
|
1777
|
+
type EphemeralConn<CP, CS> = Pick<PersistedConn<CP, CS>, "id" | "parameters" | "state">;
|
|
1778
|
+
type ConnDataInput<CP, CS> = {
|
|
1779
|
+
ephemeral: EphemeralConn<CP, CS>;
|
|
1780
|
+
} | {
|
|
1781
|
+
hibernatable: PersistedConn<CP, CS>;
|
|
1782
|
+
};
|
|
1783
|
+
/**
|
|
1784
|
+
* Manages connection state persistence, proxying, and change tracking.
|
|
1785
|
+
* Handles automatic state change detection for connection-specific state.
|
|
1786
|
+
*/
|
|
1787
|
+
declare class StateManager<CP, CS> {
|
|
1788
|
+
#private;
|
|
1789
|
+
constructor(conn: Conn<any, CP, CS, any, any, any>, data: ConnDataInput<CP, CS>);
|
|
1790
|
+
/**
|
|
1791
|
+
* Returns the ephemeral or persisted data for this connectioned.
|
|
1792
|
+
*
|
|
1793
|
+
* This property is used to be able to treat both memory & persist conns
|
|
1794
|
+
* identical by looking up the correct underlying data structure.
|
|
1795
|
+
*/
|
|
1796
|
+
get ephemeralData(): EphemeralConn<CP, CS>;
|
|
1797
|
+
get hibernatableData(): PersistedConn<CP, CS> | undefined;
|
|
1798
|
+
hibernatableDataOrError(): PersistedConn<CP, CS>;
|
|
1799
|
+
get hibernatableDataRaw(): PersistedConn<CP, CS> | undefined;
|
|
1800
|
+
get stateEnabled(): boolean;
|
|
1801
|
+
get state(): CS;
|
|
1802
|
+
set state(value: CS);
|
|
1803
|
+
addSubscription({ eventName }: {
|
|
2046
1804
|
eventName: string;
|
|
2047
|
-
|
|
2048
|
-
}
|
|
2049
|
-
type: "event";
|
|
1805
|
+
}): void;
|
|
1806
|
+
removeSubscription({ eventName }: {
|
|
2050
1807
|
eventName: string;
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
1808
|
+
}): boolean | undefined;
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
type ConnId = string;
|
|
1812
|
+
type AnyConn = Conn<any, any, any, any, any, any>;
|
|
1813
|
+
declare const CONN_CONNECTED_SYMBOL: unique symbol;
|
|
1814
|
+
declare const CONN_SPEAKS_RIVETKIT_SYMBOL: unique symbol;
|
|
1815
|
+
declare const CONN_DRIVER_SYMBOL: unique symbol;
|
|
1816
|
+
declare const CONN_ACTOR_SYMBOL: unique symbol;
|
|
1817
|
+
declare const CONN_STATE_MANAGER_SYMBOL: unique symbol;
|
|
1818
|
+
declare const CONN_SEND_MESSAGE_SYMBOL: unique symbol;
|
|
1819
|
+
/**
|
|
1820
|
+
* Represents a client connection to a actor.
|
|
1821
|
+
*
|
|
1822
|
+
* Manages connection-specific data and controls the connection lifecycle.
|
|
1823
|
+
*
|
|
1824
|
+
* @see {@link https://rivet.dev/docs/connections|Connection Documentation}
|
|
1825
|
+
*/
|
|
1826
|
+
declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
1827
|
+
#private;
|
|
1828
|
+
get [CONN_ACTOR_SYMBOL](): ActorInstance<S, CP, CS, V, I, DB>;
|
|
1829
|
+
get [CONN_STATE_MANAGER_SYMBOL](): StateManager<CP, CS>;
|
|
1830
|
+
/**
|
|
1831
|
+
* Connections exist before being connected to an actor. If true, this
|
|
1832
|
+
* connection has been connected.
|
|
1833
|
+
**/
|
|
1834
|
+
[CONN_CONNECTED_SYMBOL]: boolean;
|
|
1835
|
+
/**
|
|
1836
|
+
* If undefined, then no socket is connected to this conn
|
|
1837
|
+
*/
|
|
1838
|
+
[CONN_DRIVER_SYMBOL]?: ConnDriver;
|
|
1839
|
+
/**
|
|
1840
|
+
* If this connection is speaking the RivetKit protocol. If false, this is
|
|
1841
|
+
* a raw connection for WebSocket or fetch or inspector.
|
|
1842
|
+
**/
|
|
1843
|
+
get [CONN_SPEAKS_RIVETKIT_SYMBOL](): boolean;
|
|
1844
|
+
subscriptions: Set<string>;
|
|
1845
|
+
get params(): CP;
|
|
1846
|
+
/**
|
|
1847
|
+
* Gets the current state of the connection.
|
|
1848
|
+
*
|
|
1849
|
+
* Throws an error if the state is not enabled.
|
|
1850
|
+
*/
|
|
1851
|
+
get state(): CS;
|
|
1852
|
+
/**
|
|
1853
|
+
* Sets the state of the connection.
|
|
1854
|
+
*
|
|
1855
|
+
* Throws an error if the state is not enabled.
|
|
1856
|
+
*/
|
|
1857
|
+
set state(value: CS);
|
|
1858
|
+
/**
|
|
1859
|
+
* Unique identifier for the connection.
|
|
1860
|
+
*/
|
|
1861
|
+
get id(): ConnId;
|
|
1862
|
+
/**
|
|
1863
|
+
* @experimental
|
|
1864
|
+
*
|
|
1865
|
+
* If the underlying connection can hibernate.
|
|
1866
|
+
*/
|
|
1867
|
+
get isHibernatable(): boolean;
|
|
1868
|
+
/**
|
|
1869
|
+
* Initializes a new instance of the Connection class.
|
|
1870
|
+
*
|
|
1871
|
+
* This should only be constructed by {@link Actor}.
|
|
1872
|
+
*
|
|
1873
|
+
* @protected
|
|
1874
|
+
*/
|
|
1875
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>, data: ConnDataInput<CP, CS>);
|
|
1876
|
+
/**
|
|
1877
|
+
* Sends a raw message to the underlying connection.
|
|
1878
|
+
*/
|
|
1879
|
+
[CONN_SEND_MESSAGE_SYMBOL](message: CachedSerializer<any, any, any>): void;
|
|
1880
|
+
/**
|
|
1881
|
+
* Sends an event with arguments to the client.
|
|
1882
|
+
*
|
|
1883
|
+
* @param eventName - The name of the event.
|
|
1884
|
+
* @param args - The arguments for the event.
|
|
1885
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1886
|
+
*/
|
|
1887
|
+
send(eventName: string, ...args: unknown[]): void;
|
|
1888
|
+
/**
|
|
1889
|
+
* Disconnects the client with an optional reason.
|
|
1890
|
+
*
|
|
1891
|
+
* @param reason - The reason for disconnection.
|
|
1892
|
+
*/
|
|
1893
|
+
disconnect(reason?: string): Promise<void>;
|
|
2058
1894
|
}
|
|
2059
1895
|
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
1896
|
+
/**
|
|
1897
|
+
* Base context for connection initialization handlers.
|
|
1898
|
+
* Extends ActorContext with request-specific functionality for connection lifecycle events.
|
|
1899
|
+
*/
|
|
1900
|
+
declare abstract class ConnInitContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ActorContext<TState, undefined, undefined, TVars, TInput, TDatabase> {
|
|
1901
|
+
/**
|
|
1902
|
+
* The incoming request that initiated the connection.
|
|
1903
|
+
* May be undefined for connections initiated without a direct HTTP request.
|
|
1904
|
+
*/
|
|
1905
|
+
readonly request: Request | undefined;
|
|
2065
1906
|
}
|
|
2066
1907
|
|
|
2067
|
-
/**
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
connections: PersistedConn<CP, CS>[];
|
|
2073
|
-
scheduledEvents: PersistedScheduleEvent[];
|
|
2074
|
-
hibernatableWebSocket: PersistedHibernatableWebSocket[];
|
|
1908
|
+
/**
|
|
1909
|
+
* Context for the createConnState lifecycle hook.
|
|
1910
|
+
* Called to initialize connection-specific state when a connection is created.
|
|
1911
|
+
*/
|
|
1912
|
+
declare class CreateConnStateContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnInitContext<TState, TVars, TInput, TDatabase> {
|
|
2075
1913
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
subscriptions: PersistedSubscription[];
|
|
2083
|
-
/** Last time the socket was seen. This is set when disconnected so we can determine when we need to clean this up. */
|
|
2084
|
-
lastSeen: number;
|
|
2085
|
-
/** Request ID of the hibernatable WebSocket. See PersistedActor.hibernatableWebSocket */
|
|
2086
|
-
hibernatableRequestId?: ArrayBuffer;
|
|
1914
|
+
|
|
1915
|
+
/**
|
|
1916
|
+
* Context for the onBeforeConnect lifecycle hook.
|
|
1917
|
+
* Called before a connection is established, allowing for validation and early rejection.
|
|
1918
|
+
*/
|
|
1919
|
+
declare class OnBeforeConnectContext<TState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnInitContext<TState, TVars, TInput, TDatabase> {
|
|
2087
1920
|
}
|
|
2088
|
-
|
|
2089
|
-
|
|
1921
|
+
|
|
1922
|
+
/**
|
|
1923
|
+
* Context for the onConnect lifecycle hook.
|
|
1924
|
+
* Called when a connection is successfully established.
|
|
1925
|
+
*/
|
|
1926
|
+
declare class OnConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
2090
1927
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* Context for raw HTTP request handlers (onRequest).
|
|
1931
|
+
*/
|
|
1932
|
+
declare class RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1933
|
+
/**
|
|
1934
|
+
* The incoming HTTP request.
|
|
1935
|
+
* May be undefined for request contexts initiated without a direct HTTP request.
|
|
1936
|
+
*/
|
|
1937
|
+
readonly request: Request | undefined;
|
|
2094
1938
|
}
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
1939
|
+
|
|
1940
|
+
/**
|
|
1941
|
+
* Context for raw WebSocket handlers (onWebSocket).
|
|
1942
|
+
*/
|
|
1943
|
+
declare class WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> extends ConnContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase> {
|
|
1944
|
+
/**
|
|
1945
|
+
* The incoming HTTP request that initiated the WebSocket upgrade.
|
|
1946
|
+
* May be undefined for WebSocket connections initiated without a direct HTTP request.
|
|
1947
|
+
*/
|
|
1948
|
+
readonly request: Request | undefined;
|
|
2102
1949
|
}
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
1950
|
+
|
|
1951
|
+
type InitContext = ActorContext<undefined, undefined, undefined, undefined, undefined, undefined>;
|
|
1952
|
+
interface ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1953
|
+
state?: TState;
|
|
1954
|
+
connParams?: TConnParams;
|
|
1955
|
+
connState?: TConnState;
|
|
1956
|
+
vars?: TVars;
|
|
1957
|
+
input?: TInput;
|
|
1958
|
+
database?: TDatabase;
|
|
2107
1959
|
}
|
|
2108
|
-
|
|
2109
|
-
|
|
1960
|
+
declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
1961
|
+
onCreate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1962
|
+
onDestroy: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1963
|
+
onWake: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1964
|
+
onSleep: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1965
|
+
onStateChange: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1966
|
+
onBeforeConnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1967
|
+
onConnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1968
|
+
onDisconnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1969
|
+
onBeforeActionResponse: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1970
|
+
onRequest: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1971
|
+
onWebSocket: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1972
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>>;
|
|
1973
|
+
state: z.ZodOptional<z.ZodAny>;
|
|
1974
|
+
createState: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1975
|
+
connState: z.ZodOptional<z.ZodAny>;
|
|
1976
|
+
createConnState: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1977
|
+
vars: z.ZodOptional<z.ZodAny>;
|
|
1978
|
+
db: z.ZodOptional<z.ZodAny>;
|
|
1979
|
+
createVars: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1980
|
+
options: z.ZodDefault<z.ZodObject<{
|
|
1981
|
+
createVarsTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1982
|
+
createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1983
|
+
onConnectTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1984
|
+
onSleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1985
|
+
onDestroyTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1986
|
+
stateSaveInterval: z.ZodDefault<z.ZodNumber>;
|
|
1987
|
+
actionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1988
|
+
waitUntilTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1989
|
+
connectionLivenessTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1990
|
+
connectionLivenessInterval: z.ZodDefault<z.ZodNumber>;
|
|
1991
|
+
noSleep: z.ZodDefault<z.ZodBoolean>;
|
|
1992
|
+
sleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1993
|
+
/**
|
|
1994
|
+
* Can hibernate WebSockets for onWebSocket.
|
|
1995
|
+
*
|
|
1996
|
+
* WebSockets using actions/events are hibernatable by default.
|
|
1997
|
+
*
|
|
1998
|
+
* @experimental
|
|
1999
|
+
**/
|
|
2000
|
+
canHibernateWebSocket: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodType<Request, z.ZodTypeDef, Request>], z.ZodUnknown>, z.ZodBoolean>]>>;
|
|
2001
|
+
}, "strict", z.ZodTypeAny, {
|
|
2002
|
+
createVarsTimeout: number;
|
|
2003
|
+
createConnStateTimeout: number;
|
|
2004
|
+
onConnectTimeout: number;
|
|
2005
|
+
onSleepTimeout: number;
|
|
2006
|
+
onDestroyTimeout: number;
|
|
2007
|
+
stateSaveInterval: number;
|
|
2008
|
+
actionTimeout: number;
|
|
2009
|
+
waitUntilTimeout: number;
|
|
2010
|
+
connectionLivenessTimeout: number;
|
|
2011
|
+
connectionLivenessInterval: number;
|
|
2012
|
+
noSleep: boolean;
|
|
2013
|
+
sleepTimeout: number;
|
|
2014
|
+
canHibernateWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
2015
|
+
}, {
|
|
2016
|
+
createVarsTimeout?: number | undefined;
|
|
2017
|
+
createConnStateTimeout?: number | undefined;
|
|
2018
|
+
onConnectTimeout?: number | undefined;
|
|
2019
|
+
onSleepTimeout?: number | undefined;
|
|
2020
|
+
onDestroyTimeout?: number | undefined;
|
|
2021
|
+
stateSaveInterval?: number | undefined;
|
|
2022
|
+
actionTimeout?: number | undefined;
|
|
2023
|
+
waitUntilTimeout?: number | undefined;
|
|
2024
|
+
connectionLivenessTimeout?: number | undefined;
|
|
2025
|
+
connectionLivenessInterval?: number | undefined;
|
|
2026
|
+
noSleep?: boolean | undefined;
|
|
2027
|
+
sleepTimeout?: number | undefined;
|
|
2028
|
+
canHibernateWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
2029
|
+
}>>;
|
|
2030
|
+
}, "strict", z.ZodTypeAny, {
|
|
2031
|
+
options: {
|
|
2032
|
+
createVarsTimeout: number;
|
|
2033
|
+
createConnStateTimeout: number;
|
|
2034
|
+
onConnectTimeout: number;
|
|
2035
|
+
onSleepTimeout: number;
|
|
2036
|
+
onDestroyTimeout: number;
|
|
2037
|
+
stateSaveInterval: number;
|
|
2038
|
+
actionTimeout: number;
|
|
2039
|
+
waitUntilTimeout: number;
|
|
2040
|
+
connectionLivenessTimeout: number;
|
|
2041
|
+
connectionLivenessInterval: number;
|
|
2042
|
+
noSleep: boolean;
|
|
2043
|
+
sleepTimeout: number;
|
|
2044
|
+
canHibernateWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
2045
|
+
};
|
|
2046
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
2047
|
+
state?: any;
|
|
2048
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2049
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2050
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2051
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2052
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2053
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2054
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2055
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2056
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2057
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2058
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2059
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2060
|
+
connState?: any;
|
|
2061
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2062
|
+
vars?: any;
|
|
2063
|
+
db?: any;
|
|
2064
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2065
|
+
}, {
|
|
2066
|
+
options?: {
|
|
2067
|
+
createVarsTimeout?: number | undefined;
|
|
2068
|
+
createConnStateTimeout?: number | undefined;
|
|
2069
|
+
onConnectTimeout?: number | undefined;
|
|
2070
|
+
onSleepTimeout?: number | undefined;
|
|
2071
|
+
onDestroyTimeout?: number | undefined;
|
|
2072
|
+
stateSaveInterval?: number | undefined;
|
|
2073
|
+
actionTimeout?: number | undefined;
|
|
2074
|
+
waitUntilTimeout?: number | undefined;
|
|
2075
|
+
connectionLivenessTimeout?: number | undefined;
|
|
2076
|
+
connectionLivenessInterval?: number | undefined;
|
|
2077
|
+
noSleep?: boolean | undefined;
|
|
2078
|
+
sleepTimeout?: number | undefined;
|
|
2079
|
+
canHibernateWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
2080
|
+
} | undefined;
|
|
2081
|
+
state?: any;
|
|
2082
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2083
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2084
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2085
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2086
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2087
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2088
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2089
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2090
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2091
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2092
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2093
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
2094
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2095
|
+
connState?: any;
|
|
2096
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2097
|
+
vars?: any;
|
|
2098
|
+
db?: any;
|
|
2099
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2100
|
+
}>, {
|
|
2101
|
+
options: {
|
|
2102
|
+
createVarsTimeout: number;
|
|
2103
|
+
createConnStateTimeout: number;
|
|
2104
|
+
onConnectTimeout: number;
|
|
2105
|
+
onSleepTimeout: number;
|
|
2106
|
+
onDestroyTimeout: number;
|
|
2107
|
+
stateSaveInterval: number;
|
|
2108
|
+
actionTimeout: number;
|
|
2109
|
+
waitUntilTimeout: number;
|
|
2110
|
+
connectionLivenessTimeout: number;
|
|
2111
|
+
connectionLivenessInterval: number;
|
|
2112
|
+
noSleep: boolean;
|
|
2113
|
+
sleepTimeout: number;
|
|
2114
|
+
canHibernateWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
2115
|
+
};
|
|
2116
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
2117
|
+
state?: any;
|
|
2118
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2119
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2120
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2121
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2122
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2123
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2124
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2125
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2126
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2127
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2128
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2129
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2130
|
+
connState?: any;
|
|
2131
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2132
|
+
vars?: any;
|
|
2133
|
+
db?: any;
|
|
2134
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2135
|
+
}, {
|
|
2136
|
+
options?: {
|
|
2137
|
+
createVarsTimeout?: number | undefined;
|
|
2138
|
+
createConnStateTimeout?: number | undefined;
|
|
2139
|
+
onConnectTimeout?: number | undefined;
|
|
2140
|
+
onSleepTimeout?: number | undefined;
|
|
2141
|
+
onDestroyTimeout?: number | undefined;
|
|
2142
|
+
stateSaveInterval?: number | undefined;
|
|
2143
|
+
actionTimeout?: number | undefined;
|
|
2144
|
+
waitUntilTimeout?: number | undefined;
|
|
2145
|
+
connectionLivenessTimeout?: number | undefined;
|
|
2146
|
+
connectionLivenessInterval?: number | undefined;
|
|
2147
|
+
noSleep?: boolean | undefined;
|
|
2148
|
+
sleepTimeout?: number | undefined;
|
|
2149
|
+
canHibernateWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
2150
|
+
} | undefined;
|
|
2151
|
+
state?: any;
|
|
2152
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2153
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2154
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2155
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2156
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2157
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2158
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2159
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2160
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2161
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2162
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2163
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
2164
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2165
|
+
connState?: any;
|
|
2166
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2167
|
+
vars?: any;
|
|
2168
|
+
db?: any;
|
|
2169
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2170
|
+
}>, {
|
|
2171
|
+
options: {
|
|
2172
|
+
createVarsTimeout: number;
|
|
2173
|
+
createConnStateTimeout: number;
|
|
2174
|
+
onConnectTimeout: number;
|
|
2175
|
+
onSleepTimeout: number;
|
|
2176
|
+
onDestroyTimeout: number;
|
|
2177
|
+
stateSaveInterval: number;
|
|
2178
|
+
actionTimeout: number;
|
|
2179
|
+
waitUntilTimeout: number;
|
|
2180
|
+
connectionLivenessTimeout: number;
|
|
2181
|
+
connectionLivenessInterval: number;
|
|
2182
|
+
noSleep: boolean;
|
|
2183
|
+
sleepTimeout: number;
|
|
2184
|
+
canHibernateWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
2185
|
+
};
|
|
2186
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
2187
|
+
state?: any;
|
|
2188
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2189
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2190
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2191
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2192
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2193
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2194
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2195
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2196
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2197
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2198
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2199
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2200
|
+
connState?: any;
|
|
2201
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2202
|
+
vars?: any;
|
|
2203
|
+
db?: any;
|
|
2204
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2205
|
+
}, {
|
|
2206
|
+
options?: {
|
|
2207
|
+
createVarsTimeout?: number | undefined;
|
|
2208
|
+
createConnStateTimeout?: number | undefined;
|
|
2209
|
+
onConnectTimeout?: number | undefined;
|
|
2210
|
+
onSleepTimeout?: number | undefined;
|
|
2211
|
+
onDestroyTimeout?: number | undefined;
|
|
2212
|
+
stateSaveInterval?: number | undefined;
|
|
2213
|
+
actionTimeout?: number | undefined;
|
|
2214
|
+
waitUntilTimeout?: number | undefined;
|
|
2215
|
+
connectionLivenessTimeout?: number | undefined;
|
|
2216
|
+
connectionLivenessInterval?: number | undefined;
|
|
2217
|
+
noSleep?: boolean | undefined;
|
|
2218
|
+
sleepTimeout?: number | undefined;
|
|
2219
|
+
canHibernateWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
2220
|
+
} | undefined;
|
|
2221
|
+
state?: any;
|
|
2222
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2223
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2224
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2225
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2226
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2227
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2228
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2229
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2230
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2231
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2232
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2233
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
2234
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2235
|
+
connState?: any;
|
|
2236
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2237
|
+
vars?: any;
|
|
2238
|
+
db?: any;
|
|
2239
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2240
|
+
}>, {
|
|
2241
|
+
options: {
|
|
2242
|
+
createVarsTimeout: number;
|
|
2243
|
+
createConnStateTimeout: number;
|
|
2244
|
+
onConnectTimeout: number;
|
|
2245
|
+
onSleepTimeout: number;
|
|
2246
|
+
onDestroyTimeout: number;
|
|
2247
|
+
stateSaveInterval: number;
|
|
2248
|
+
actionTimeout: number;
|
|
2249
|
+
waitUntilTimeout: number;
|
|
2250
|
+
connectionLivenessTimeout: number;
|
|
2251
|
+
connectionLivenessInterval: number;
|
|
2252
|
+
noSleep: boolean;
|
|
2253
|
+
sleepTimeout: number;
|
|
2254
|
+
canHibernateWebSocket: boolean | ((args_0: Request, ...args: unknown[]) => boolean);
|
|
2255
|
+
};
|
|
2256
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
2257
|
+
state?: any;
|
|
2258
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2259
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2260
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2261
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2262
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2263
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2264
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2265
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2266
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2267
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2268
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2269
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2270
|
+
connState?: any;
|
|
2271
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2272
|
+
vars?: any;
|
|
2273
|
+
db?: any;
|
|
2274
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2275
|
+
}, {
|
|
2276
|
+
options?: {
|
|
2277
|
+
createVarsTimeout?: number | undefined;
|
|
2278
|
+
createConnStateTimeout?: number | undefined;
|
|
2279
|
+
onConnectTimeout?: number | undefined;
|
|
2280
|
+
onSleepTimeout?: number | undefined;
|
|
2281
|
+
onDestroyTimeout?: number | undefined;
|
|
2282
|
+
stateSaveInterval?: number | undefined;
|
|
2283
|
+
actionTimeout?: number | undefined;
|
|
2284
|
+
waitUntilTimeout?: number | undefined;
|
|
2285
|
+
connectionLivenessTimeout?: number | undefined;
|
|
2286
|
+
connectionLivenessInterval?: number | undefined;
|
|
2287
|
+
noSleep?: boolean | undefined;
|
|
2288
|
+
sleepTimeout?: number | undefined;
|
|
2289
|
+
canHibernateWebSocket?: boolean | ((args_0: Request, ...args: unknown[]) => boolean) | undefined;
|
|
2290
|
+
} | undefined;
|
|
2291
|
+
state?: any;
|
|
2292
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
2293
|
+
onDestroy?: ((...args: unknown[]) => unknown) | undefined;
|
|
2294
|
+
onWake?: ((...args: unknown[]) => unknown) | undefined;
|
|
2295
|
+
onSleep?: ((...args: unknown[]) => unknown) | undefined;
|
|
2296
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
2297
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2298
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2299
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
2300
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
2301
|
+
onRequest?: ((...args: unknown[]) => unknown) | undefined;
|
|
2302
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
2303
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
2304
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2305
|
+
connState?: any;
|
|
2306
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
2307
|
+
vars?: any;
|
|
2308
|
+
db?: any;
|
|
2309
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
2310
|
+
}>;
|
|
2311
|
+
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
2312
|
+
state: TState;
|
|
2313
|
+
} | {
|
|
2314
|
+
createState: (c: InitContext, input: TInput) => TState | Promise<TState>;
|
|
2315
|
+
} | Record<never, never>;
|
|
2316
|
+
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> = {
|
|
2317
|
+
connState: TConnState;
|
|
2318
|
+
} | {
|
|
2319
|
+
createConnState: (c: CreateConnStateContext<TState, TVars, TInput, TDatabase>, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
2320
|
+
} | Record<never, never>;
|
|
2110
2321
|
/**
|
|
2111
|
-
*
|
|
2322
|
+
* @experimental
|
|
2112
2323
|
*/
|
|
2113
|
-
|
|
2114
|
-
/**
|
|
2115
|
-
* Forces the state to be saved immediately. This function will return when the state has saved successfully.
|
|
2116
|
-
*/
|
|
2117
|
-
immediate?: boolean;
|
|
2118
|
-
/** Bypass ready check for stopping. */
|
|
2119
|
-
allowStoppingState?: boolean;
|
|
2120
|
-
}
|
|
2121
|
-
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
2122
|
-
type AnyActorInstance = ActorInstance<any, any, any, any, any, any>;
|
|
2123
|
-
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
2124
|
-
#private;
|
|
2125
|
-
actorContext: ActorContext<S, CP, CS, V, I, DB>;
|
|
2126
|
-
get isStopping(): boolean;
|
|
2127
|
-
get [PERSIST_SYMBOL](): PersistedActor<S, CP, CS, I>;
|
|
2128
|
-
get id(): string;
|
|
2129
|
-
get inlineClient(): Client<Registry<any>>;
|
|
2130
|
-
get inspector(): ActorInspector;
|
|
2324
|
+
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
2131
2325
|
/**
|
|
2132
|
-
*
|
|
2133
|
-
*
|
|
2134
|
-
* Constructed in {@link ActorInstance.start}.
|
|
2135
|
-
*
|
|
2136
|
-
* @private
|
|
2326
|
+
* @experimental
|
|
2137
2327
|
*/
|
|
2138
|
-
|
|
2139
|
-
|
|
2328
|
+
vars: TVars;
|
|
2329
|
+
} | {
|
|
2140
2330
|
/**
|
|
2141
|
-
*
|
|
2142
|
-
*
|
|
2143
|
-
* This method is idempotent. It's called automatically when the actor wakes
|
|
2144
|
-
* in order to trigger any pending alarms.
|
|
2331
|
+
* @experimental
|
|
2145
2332
|
*/
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2333
|
+
createVars: (c: InitContext, driverCtx: any) => TVars | Promise<TVars>;
|
|
2334
|
+
} | Record<never, never>;
|
|
2335
|
+
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
2336
|
+
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, ...args: any[]) => any;
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* @experimental
|
|
2340
|
+
*/
|
|
2341
|
+
type AuthIntent = "get" | "create" | "connect" | "action" | "message";
|
|
2342
|
+
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>> {
|
|
2151
2343
|
/**
|
|
2152
|
-
*
|
|
2153
|
-
*
|
|
2154
|
-
* If a clean diconnect, will be removed immediately.
|
|
2344
|
+
* Called when the actor is first initialized.
|
|
2155
2345
|
*
|
|
2156
|
-
*
|
|
2157
|
-
|
|
2158
|
-
__connDisconnected(conn: Conn<S, CP, CS, V, I, DB>, wasClean: boolean, requestId: string): void;
|
|
2159
|
-
/**
|
|
2160
|
-
* Called to create a new connection or reconnect an existing one.
|
|
2161
|
-
*/
|
|
2162
|
-
createConn(socket: ConnSocket, params: any, request?: Request, connectionId?: string, connectionToken?: string): Promise<Conn<S, CP, CS, V, I, DB>>;
|
|
2163
|
-
processMessage(message: ToServer, conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
2164
|
-
/**
|
|
2165
|
-
* Check if the actor is ready to handle requests.
|
|
2166
|
-
*/
|
|
2167
|
-
isReady(): boolean;
|
|
2168
|
-
/**
|
|
2169
|
-
* Returns a list of action methods available on this actor.
|
|
2170
|
-
*/
|
|
2171
|
-
get actions(): string[];
|
|
2172
|
-
/**
|
|
2173
|
-
* Handles raw HTTP requests to the actor.
|
|
2174
|
-
*/
|
|
2175
|
-
handleFetch(request: Request, opts: Record<never, never>): Promise<Response>;
|
|
2176
|
-
/**
|
|
2177
|
-
* Handles raw WebSocket connections to the actor.
|
|
2178
|
-
*/
|
|
2179
|
-
handleWebSocket(websocket: UniversalWebSocket, opts: {
|
|
2180
|
-
request: Request;
|
|
2181
|
-
}): Promise<void>;
|
|
2182
|
-
get log(): Logger;
|
|
2183
|
-
get rLog(): Logger;
|
|
2184
|
-
/**
|
|
2185
|
-
* Gets the name.
|
|
2186
|
-
*/
|
|
2187
|
-
get name(): string;
|
|
2188
|
-
/**
|
|
2189
|
-
* Gets the key.
|
|
2190
|
-
*/
|
|
2191
|
-
get key(): ActorKey;
|
|
2192
|
-
/**
|
|
2193
|
-
* Gets the region.
|
|
2194
|
-
*/
|
|
2195
|
-
get region(): string;
|
|
2196
|
-
/**
|
|
2197
|
-
* Gets the scheduler.
|
|
2346
|
+
* Use this hook to initialize your actor's state.
|
|
2347
|
+
* This is called before any other lifecycle hooks.
|
|
2198
2348
|
*/
|
|
2199
|
-
|
|
2349
|
+
onCreate?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, input: TInput) => void | Promise<void>;
|
|
2200
2350
|
/**
|
|
2201
|
-
*
|
|
2351
|
+
* Called when the actor is destroyed.
|
|
2202
2352
|
*/
|
|
2203
|
-
|
|
2353
|
+
onDestroy?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2204
2354
|
/**
|
|
2205
|
-
*
|
|
2355
|
+
* Called when the actor is started and ready to receive connections and action.
|
|
2206
2356
|
*
|
|
2207
|
-
*
|
|
2208
|
-
|
|
2209
|
-
get state(): S;
|
|
2210
|
-
/**
|
|
2211
|
-
* Gets the database.
|
|
2212
|
-
* @experimental
|
|
2213
|
-
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
2214
|
-
*/
|
|
2215
|
-
get db(): InferDatabaseClient<DB>;
|
|
2216
|
-
/**
|
|
2217
|
-
* Sets the current state.
|
|
2357
|
+
* Use this hook to initialize resources needed for the actor's operation
|
|
2358
|
+
* (timers, external connections, etc.)
|
|
2218
2359
|
*
|
|
2219
|
-
*
|
|
2220
|
-
*/
|
|
2221
|
-
set state(value: S);
|
|
2222
|
-
get vars(): V;
|
|
2223
|
-
/**
|
|
2224
|
-
* Broadcasts an event to all connected clients.
|
|
2225
|
-
* @param name - The name of the event.
|
|
2226
|
-
* @param args - The arguments to send with the event.
|
|
2360
|
+
* @returns Void or a Promise that resolves when startup is complete
|
|
2227
2361
|
*/
|
|
2228
|
-
|
|
2362
|
+
onWake?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2229
2363
|
/**
|
|
2230
|
-
*
|
|
2364
|
+
* Called when the actor is stopping or sleeping.
|
|
2365
|
+
*
|
|
2366
|
+
* Use this hook to clean up resources, save state, or perform
|
|
2367
|
+
* any shutdown operations before the actor sleeps or stops.
|
|
2231
2368
|
*
|
|
2232
|
-
*
|
|
2233
|
-
* returning from an action request early.
|
|
2369
|
+
* Not supported on all platforms.
|
|
2234
2370
|
*
|
|
2235
|
-
* @
|
|
2371
|
+
* @returns Void or a Promise that resolves when shutdown is complete
|
|
2236
2372
|
*/
|
|
2237
|
-
|
|
2373
|
+
onSleep?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2238
2374
|
/**
|
|
2239
|
-
*
|
|
2375
|
+
* Called when the actor's state changes.
|
|
2240
2376
|
*
|
|
2241
|
-
*
|
|
2242
|
-
*
|
|
2377
|
+
* Use this hook to react to state changes, such as updating
|
|
2378
|
+
* external systems or triggering events.
|
|
2243
2379
|
*
|
|
2244
|
-
*
|
|
2245
|
-
|
|
2246
|
-
saveState(opts: SaveStateOptions): Promise<void>;
|
|
2247
|
-
/**
|
|
2248
|
-
* Called by router middleware when an HTTP request begins.
|
|
2249
|
-
*/
|
|
2250
|
-
__beginHonoHttpRequest(): void;
|
|
2251
|
-
/**
|
|
2252
|
-
* Called by router middleware when an HTTP request ends.
|
|
2253
|
-
*/
|
|
2254
|
-
__endHonoHttpRequest(): void;
|
|
2255
|
-
/**
|
|
2256
|
-
* Puts an actor to sleep. This should just start the sleep sequence, most shutdown logic should be in _stop (which is called by the ActorDriver when sleeping).
|
|
2380
|
+
* State changes made within this hook will NOT trigger
|
|
2381
|
+
* another onStateChange call, preventing infinite recursion.
|
|
2257
2382
|
*
|
|
2258
|
-
*
|
|
2259
|
-
* 1. Publish EventActorIntent with ActorIntentSleep (via driver.startSleep)
|
|
2260
|
-
* 2. Engine runner will wait for CommandStopActor
|
|
2261
|
-
* 3. Engine runner will call _onStop and wait for it to finish
|
|
2262
|
-
* 4. Engine runner will publish EventActorStateUpdate with ActorStateSTop
|
|
2263
|
-
**/
|
|
2264
|
-
_startSleep(): void;
|
|
2265
|
-
/**
|
|
2266
|
-
* For the engine:
|
|
2267
|
-
* 1. Engine runner receives CommandStopActor
|
|
2268
|
-
* 2. Engine runner calls _onStop and waits for it to finish
|
|
2269
|
-
* 3. Engine runner publishes EventActorStateUpdate with ActorStateSTop
|
|
2383
|
+
* @param newState The updated state
|
|
2270
2384
|
*/
|
|
2271
|
-
|
|
2272
|
-
/** Abort signal that fires when the actor is stopping. */
|
|
2273
|
-
get abortSignal(): AbortSignal;
|
|
2274
|
-
}
|
|
2275
|
-
|
|
2276
|
-
declare enum ConnDriverKind {
|
|
2277
|
-
WEBSOCKET = 0,
|
|
2278
|
-
SSE = 1,
|
|
2279
|
-
HTTP = 2
|
|
2280
|
-
}
|
|
2281
|
-
interface ConnDriverWebSocketState {
|
|
2282
|
-
encoding: Encoding;
|
|
2283
|
-
websocket: WSContext;
|
|
2284
|
-
closePromise: ReturnType<typeof promiseWithResolvers<void>>;
|
|
2285
|
-
}
|
|
2286
|
-
interface ConnDriverSseState {
|
|
2287
|
-
encoding: Encoding;
|
|
2288
|
-
stream: SSEStreamingApi;
|
|
2289
|
-
}
|
|
2290
|
-
type ConnDriverHttpState = Record<never, never>;
|
|
2291
|
-
type ConnDriverState = {
|
|
2292
|
-
[ConnDriverKind.WEBSOCKET]: ConnDriverWebSocketState;
|
|
2293
|
-
} | {
|
|
2294
|
-
[ConnDriverKind.SSE]: ConnDriverSseState;
|
|
2295
|
-
} | {
|
|
2296
|
-
[ConnDriverKind.HTTP]: ConnDriverHttpState;
|
|
2297
|
-
};
|
|
2298
|
-
|
|
2299
|
-
declare function generateConnId(): string;
|
|
2300
|
-
declare function generateConnToken(): string;
|
|
2301
|
-
type ConnId = string;
|
|
2302
|
-
type ConnectionStatus = "connected" | "reconnecting";
|
|
2303
|
-
/**
|
|
2304
|
-
* Represents a client connection to a actor.
|
|
2305
|
-
*
|
|
2306
|
-
* Manages connection-specific data and controls the connection lifecycle.
|
|
2307
|
-
*
|
|
2308
|
-
* @see {@link https://rivet.dev/docs/connections|Connection Documentation}
|
|
2309
|
-
*/
|
|
2310
|
-
declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
2311
|
-
#private;
|
|
2312
|
-
subscriptions: Set<string>;
|
|
2385
|
+
onStateChange?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, newState: TState) => void;
|
|
2313
2386
|
/**
|
|
2314
|
-
*
|
|
2387
|
+
* Called before a client connects to the actor.
|
|
2315
2388
|
*
|
|
2316
|
-
*
|
|
2317
|
-
|
|
2318
|
-
__persist: PersistedConn<CP, CS>;
|
|
2319
|
-
get __driverState(): ConnDriverState | undefined;
|
|
2320
|
-
/**
|
|
2321
|
-
* Socket connected to this connection.
|
|
2389
|
+
* Use this hook to determine if a connection should be accepted
|
|
2390
|
+
* and to initialize connection-specific state.
|
|
2322
2391
|
*
|
|
2323
|
-
*
|
|
2392
|
+
* @param opts Connection parameters including client-provided data
|
|
2393
|
+
* @returns The initial connection state or a Promise that resolves to it
|
|
2394
|
+
* @throws Throw an error to reject the connection
|
|
2324
2395
|
*/
|
|
2325
|
-
|
|
2326
|
-
get __status(): ConnectionStatus;
|
|
2327
|
-
get params(): CP;
|
|
2328
|
-
get __stateEnabled(): boolean;
|
|
2396
|
+
onBeforeConnect?: (c: OnBeforeConnectContext<TState, TVars, TInput, TDatabase>, params: TConnParams) => void | Promise<void>;
|
|
2329
2397
|
/**
|
|
2330
|
-
*
|
|
2398
|
+
* Called when a client successfully connects to the actor.
|
|
2331
2399
|
*
|
|
2332
|
-
*
|
|
2333
|
-
|
|
2334
|
-
get state(): CS;
|
|
2335
|
-
/**
|
|
2336
|
-
* Sets the state of the connection.
|
|
2400
|
+
* Use this hook to perform actions when a connection is established,
|
|
2401
|
+
* such as sending initial data or updating the actor's state.
|
|
2337
2402
|
*
|
|
2338
|
-
*
|
|
2339
|
-
|
|
2340
|
-
set state(value: CS);
|
|
2341
|
-
/**
|
|
2342
|
-
* Unique identifier for the connection.
|
|
2343
|
-
*/
|
|
2344
|
-
get id(): ConnId;
|
|
2345
|
-
/**
|
|
2346
|
-
* Token used to authenticate this request.
|
|
2347
|
-
*/
|
|
2348
|
-
get _token(): string;
|
|
2349
|
-
/**
|
|
2350
|
-
* Status of the connection.
|
|
2403
|
+
* @param conn The connection object
|
|
2404
|
+
* @returns Void or a Promise that resolves when connection handling is complete
|
|
2351
2405
|
*/
|
|
2352
|
-
|
|
2406
|
+
onConnect?: (c: OnConnectContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2353
2407
|
/**
|
|
2354
|
-
*
|
|
2408
|
+
* Called when a client disconnects from the actor.
|
|
2355
2409
|
*
|
|
2356
|
-
*
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
*
|
|
2410
|
+
* Use this hook to clean up resources associated with the connection
|
|
2411
|
+
* or update the actor's state.
|
|
2412
|
+
*
|
|
2413
|
+
* @param conn The connection that is being closed
|
|
2414
|
+
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
2361
2415
|
*/
|
|
2362
|
-
|
|
2416
|
+
onDisconnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
2363
2417
|
/**
|
|
2364
|
-
*
|
|
2418
|
+
* Called before sending an action response to the client.
|
|
2365
2419
|
*
|
|
2366
|
-
*
|
|
2420
|
+
* Use this hook to modify or transform the output of an action before it's sent
|
|
2421
|
+
* to the client. This is useful for formatting responses, adding metadata,
|
|
2422
|
+
* or applying transformations to the output.
|
|
2367
2423
|
*
|
|
2368
|
-
* @
|
|
2424
|
+
* @param name The name of the action that was called
|
|
2425
|
+
* @param args The arguments that were passed to the action
|
|
2426
|
+
* @param output The output that will be sent to the client
|
|
2427
|
+
* @returns The modified output to send to the client
|
|
2369
2428
|
*/
|
|
2370
|
-
|
|
2429
|
+
onBeforeActionResponse?: <Out>(c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
2371
2430
|
/**
|
|
2372
|
-
*
|
|
2431
|
+
* Called when a raw HTTP request is made to the actor.
|
|
2373
2432
|
*
|
|
2374
|
-
*
|
|
2433
|
+
* This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
|
|
2434
|
+
* Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
|
|
2375
2435
|
*
|
|
2376
|
-
* @
|
|
2436
|
+
* @param c The request context with access to the connection
|
|
2437
|
+
* @param request The raw HTTP request object
|
|
2438
|
+
* @param opts Additional options
|
|
2439
|
+
* @returns A Response object to send back, or void to continue with default routing
|
|
2377
2440
|
*/
|
|
2378
|
-
|
|
2441
|
+
onRequest?: (c: RequestContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, request: Request) => Response | Promise<Response>;
|
|
2379
2442
|
/**
|
|
2380
|
-
*
|
|
2443
|
+
* Called when a raw WebSocket connection is established to the actor.
|
|
2381
2444
|
*
|
|
2382
|
-
*
|
|
2383
|
-
*
|
|
2384
|
-
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
2385
|
-
*/
|
|
2386
|
-
send(eventName: string, ...args: unknown[]): void;
|
|
2387
|
-
/**
|
|
2388
|
-
* Disconnects the client with an optional reason.
|
|
2445
|
+
* This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
|
|
2446
|
+
* Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
|
|
2389
2447
|
*
|
|
2390
|
-
* @param
|
|
2448
|
+
* @param c The WebSocket context with access to the connection
|
|
2449
|
+
* @param websocket The raw WebSocket connection
|
|
2450
|
+
* @param opts Additional options including the original HTTP upgrade request
|
|
2391
2451
|
*/
|
|
2392
|
-
|
|
2452
|
+
onWebSocket?: (c: WebSocketContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, websocket: UniversalWebSocket) => void | Promise<void>;
|
|
2453
|
+
actions: TActions;
|
|
2393
2454
|
}
|
|
2455
|
+
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
2456
|
+
/**
|
|
2457
|
+
* @experimental
|
|
2458
|
+
*/
|
|
2459
|
+
db: TDatabase;
|
|
2460
|
+
} | Record<never, never>;
|
|
2461
|
+
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>;
|
|
2462
|
+
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>> = {
|
|
2463
|
+
types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
2464
|
+
} & 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>;
|
|
2465
|
+
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>;
|
|
2394
2466
|
|
|
2395
|
-
export {
|
|
2467
|
+
export { type ActorConn as $, type ActorDriver as A, type AuthIntent as B, type Client as C, type DriverConfig as D, type Encoding as E, type ActorConfig as F, test as G, type RegistryConfig as H, type InitContext as I, type RegistryActors as J, type RunnerConfigInput as K, RegistryConfigSchema as L, Registry as M, setup as N, OnBeforeConnectContext as O, type ClientConfigInput as P, ActorClientError as Q, type RunnerConfig as R, type ServerlessActorDriverBuilder as S, ActorError as T, type UniversalWebSocket as U, InternalError as V, WebSocketContext as W, MalformedResponseMessage as X, ManagerError as Y, type CreateRequest as Z, type ActorActionFunction as _, type AnyConn as a, type EventUnsubscribe as a0, ActorConnRaw as a1, type ActorHandle as a2, ActorHandleRaw as a3, type ActorAccessor as a4, ClientRaw as a5, type CreateOptions as a6, type ExtractActorsFromRegistry as a7, type ExtractRegistryFromClient as a8, type GetOptions as a9, type RealtimeEvent as aA, RecordedRealtimeEventSchema as aB, type RecordedRealtimeEvent as aC, DatabaseQuerySchema as aD, type DatabaseQuery as aE, TableSchema as aF, type Table as aG, TablesSchema as aH, type Tables as aI, ColumnSchema as aJ, type Column as aK, ColumnsSchema as aL, type Columns as aM, ForeignKeySchema as aN, type ForeignKey as aO, ForeignKeysSchema as aP, type ForeignKeys as aQ, BuildSchema as aR, type Build as aS, BuildsSchema as aT, type Builds as aU, CreateActorSchema as aV, type CreateActor as aW, type GetWithIdOptions as aa, type QueryOptions as ab, type Region as ac, ActorInstance as ad, type ActorOutput as ae, type CreateInput as af, type GetForIdInput as ag, type GetOrCreateWithKeyInput as ah, type GetWithKeyInput as ai, type ListActorsInput as aj, type ManagerDisplayInformation as ak, type ManagerDriver as al, DriverConfigSchema as am, RunnerConfigSchema as an, ActorFeature as ao, ActorId as ap, ActorLogEntry as aq, ActorSchema as ar, type Actor as as, OperationSchema as at, type Operation as au, PatchSchema as av, type Patch as aw, ConnectionSchema as ax, type Connection as ay, RealtimeEventSchema as az, type AnyActorInstance as b, type AnyDatabaseProvider as c, type Actions as d, type ActorConfigInput as e, ActorDefinition as f, type RivetEvent as g, type RivetCloseEvent as h, type RivetMessageEvent as i, type AnyClient as j, createClientWithDriver as k, type ActorQuery as l, type ActorKey as m, Conn as n, ActionContext as o, ActorContext as p, ConnInitContext as q, CreateConnStateContext as r, OnConnectContext as s, RequestContext as t, type ActionContextOf as u, type ActorContextOf as v, type AnyActorDefinition as w, lookupInRegistry as x, type ActorTypes as y, ActorConfigSchema as z };
|