rivetkit 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/schemas/actor-persist/v1.ts +21 -24
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/tsup/actor/errors.cjs +10 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +17 -4
- package/dist/tsup/actor/errors.d.ts +17 -4
- package/dist/tsup/actor/errors.js +11 -3
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-2MD57QF4.js} +119 -115
- package/dist/tsup/chunk-2MD57QF4.js.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-5QGQK44L.cjs} +103 -44
- package/dist/tsup/chunk-5QGQK44L.cjs.map +1 -0
- package/dist/tsup/chunk-5YTI25C3.cjs +250 -0
- package/dist/tsup/chunk-5YTI25C3.cjs.map +1 -0
- package/dist/tsup/chunk-B2QGJGZQ.js +338 -0
- package/dist/tsup/chunk-B2QGJGZQ.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-CFFKMUYH.js} +61 -22
- package/dist/tsup/chunk-CFFKMUYH.js.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-CKA54YQN.js} +15 -8
- package/dist/tsup/chunk-CKA54YQN.js.map +1 -0
- package/dist/tsup/chunk-D7NWUCRK.cjs +20 -0
- package/dist/tsup/chunk-D7NWUCRK.cjs.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-FGFT4FVX.cjs} +12 -27
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +1 -0
- package/dist/tsup/chunk-I5VTWPHW.js +20 -0
- package/dist/tsup/chunk-I5VTWPHW.js.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-IRMBWX36.cjs} +146 -142
- package/dist/tsup/chunk-IRMBWX36.cjs.map +1 -0
- package/dist/tsup/chunk-L7QRXNWP.js +6562 -0
- package/dist/tsup/chunk-L7QRXNWP.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LZIBTLEY.cjs} +20 -13
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +1 -0
- package/dist/tsup/chunk-MRZS2J4X.cjs +6562 -0
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-PG3K2LI7.js} +3 -5
- package/dist/tsup/chunk-PG3K2LI7.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-PHSQJ6QI.cjs} +3 -5
- package/dist/tsup/chunk-PHSQJ6QI.cjs.map +1 -0
- package/dist/tsup/chunk-RM2SVURR.cjs +338 -0
- package/dist/tsup/chunk-RM2SVURR.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-WADSS5X4.cjs} +66 -27
- package/dist/tsup/chunk-WADSS5X4.cjs.map +1 -0
- package/dist/tsup/chunk-WNGOBAA7.js +250 -0
- package/dist/tsup/chunk-WNGOBAA7.js.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-YPZFLUO6.js} +103 -44
- package/dist/tsup/chunk-YPZFLUO6.js.map +1 -0
- package/dist/tsup/{chunk-6PDXBYI5.js → chunk-YW6Y6VNE.js} +8 -23
- package/dist/tsup/chunk-YW6Y6VNE.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -10
- package/dist/tsup/client/mod.d.cts +7 -13
- package/dist/tsup/client/mod.d.ts +7 -13
- package/dist/tsup/client/mod.js +9 -9
- package/dist/tsup/common/log.cjs +12 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +23 -17
- package/dist/tsup/common/log.d.ts +23 -17
- package/dist/tsup/common/log.js +15 -7
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -4
- package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
- package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
- package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BvE-Oq7t.d.ts} +215 -234
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-DTzmWwU5.d.cts} +215 -234
- package/dist/tsup/driver-helpers/mod.cjs +6 -9
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +5 -6
- package/dist/tsup/driver-helpers/mod.d.ts +5 -6
- package/dist/tsup/driver-helpers/mod.js +6 -9
- package/dist/tsup/driver-test-suite/mod.cjs +615 -1357
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +12 -6
- package/dist/tsup/driver-test-suite/mod.d.ts +12 -6
- package/dist/tsup/driver-test-suite/mod.js +1334 -2076
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -8
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +3 -3
- package/dist/tsup/inspector/mod.d.ts +3 -3
- package/dist/tsup/inspector/mod.js +8 -10
- package/dist/tsup/mod.cjs +9 -15
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +47 -42
- package/dist/tsup/mod.d.ts +47 -42
- package/dist/tsup/mod.js +10 -16
- package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-CctffZNL.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-DFm1BglJ.d.ts} +2 -3
- package/dist/tsup/test/mod.cjs +10 -14
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +9 -13
- package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
- package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
- package/dist/tsup/utils.cjs +5 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +19 -2
- package/dist/tsup/utils.d.ts +19 -2
- package/dist/tsup/utils.js +4 -2
- package/package.json +6 -6
- package/src/actor/action.ts +1 -5
- package/src/actor/config.ts +27 -295
- package/src/actor/connection.ts +9 -12
- package/src/actor/context.ts +1 -4
- package/src/actor/definition.ts +7 -11
- package/src/actor/errors.ts +98 -36
- package/src/actor/generic-conn-driver.ts +28 -16
- package/src/actor/instance.ts +177 -133
- package/src/actor/log.ts +4 -13
- package/src/actor/mod.ts +0 -5
- package/src/actor/protocol/old.ts +42 -26
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +47 -39
- package/src/actor/router.ts +22 -19
- package/src/actor/unstable-react.ts +1 -1
- package/src/actor/utils.ts +6 -2
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +152 -91
- package/src/client/actor-handle.ts +85 -25
- package/src/client/actor-query.ts +65 -0
- package/src/client/client.ts +29 -98
- package/src/client/config.ts +44 -0
- package/src/client/errors.ts +1 -0
- package/src/client/log.ts +2 -4
- package/src/client/mod.ts +16 -12
- package/src/client/raw-utils.ts +82 -25
- package/src/client/utils.ts +5 -3
- package/src/common/fake-event-source.ts +10 -9
- package/src/common/inline-websocket-adapter2.ts +39 -30
- package/src/common/log.ts +176 -101
- package/src/common/logfmt.ts +21 -30
- package/src/common/router.ts +12 -19
- package/src/common/utils.ts +27 -13
- package/src/common/websocket.ts +0 -1
- package/src/driver-helpers/mod.ts +1 -1
- package/src/driver-test-suite/log.ts +1 -3
- package/src/driver-test-suite/mod.ts +87 -61
- package/src/driver-test-suite/test-inline-client-driver.ts +441 -255
- package/src/driver-test-suite/tests/actor-error-handling.ts +4 -12
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +2 -1
- package/src/driver-test-suite/tests/manager-driver.ts +5 -3
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
- package/src/driver-test-suite/tests/request-access.ts +112 -126
- package/src/driver-test-suite/utils.ts +10 -6
- package/src/drivers/default.ts +7 -4
- package/src/drivers/engine/actor-driver.ts +22 -13
- package/src/drivers/engine/config.ts +2 -10
- package/src/drivers/engine/kv.ts +1 -1
- package/src/drivers/engine/log.ts +1 -3
- package/src/drivers/engine/mod.ts +2 -3
- package/src/drivers/file-system/actor.ts +1 -1
- package/src/drivers/file-system/global-state.ts +36 -21
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +33 -15
- package/src/inspector/config.ts +9 -4
- package/src/inspector/log.ts +1 -1
- package/src/inspector/manager.ts +2 -2
- package/src/inspector/utils.ts +1 -1
- package/src/manager/driver.ts +10 -2
- package/src/manager/hono-websocket-adapter.ts +21 -12
- package/src/manager/log.ts +2 -4
- package/src/manager/mod.ts +1 -1
- package/src/manager/router.ts +378 -1390
- package/src/manager-api/routes/actors-create.ts +16 -0
- package/src/manager-api/routes/actors-delete.ts +4 -0
- package/src/manager-api/routes/actors-get-by-id.ts +7 -0
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
- package/src/manager-api/routes/actors-get.ts +7 -0
- package/src/manager-api/routes/common.ts +18 -0
- package/src/mod.ts +0 -2
- package/src/registry/config.ts +1 -1
- package/src/registry/log.ts +2 -4
- package/src/registry/mod.ts +63 -34
- package/src/registry/run-config.ts +39 -26
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +74 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +64 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +46 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +275 -0
- package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
- package/src/serde.ts +8 -2
- package/src/test/log.ts +1 -3
- package/src/test/mod.ts +17 -16
- package/src/utils.ts +53 -0
- package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
- package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
- package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
- package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
- package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
- package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
- package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
- package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
- package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
- package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
- package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
- package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
- package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
- package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
- package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
- package/dist/tsup/chunk-INGJP237.js.map +0 -1
- package/dist/tsup/chunk-KJCJLKRM.js +0 -116
- package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
- package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
- package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
- package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
- package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
- package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
- package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
- package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
- package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
- package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
- package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
- package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
- package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
- package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
- package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
- package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
- package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
- package/dist/tsup/chunk-UVUPOS46.js +0 -230
- package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
- package/dist/tsup/chunk-VRRHBNJC.js +0 -189
- package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
- package/dist/tsup/chunk-XFSS33EQ.js +0 -202
- package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
- package/src/client/http-client-driver.ts +0 -326
- package/src/driver-test-suite/tests/actor-auth.ts +0 -591
- package/src/drivers/engine/api-endpoints.ts +0 -128
- package/src/drivers/engine/api-utils.ts +0 -70
- package/src/drivers/engine/manager-driver.ts +0 -391
- package/src/inline-client-driver/log.ts +0 -7
- package/src/inline-client-driver/mod.ts +0 -385
- package/src/manager/auth.ts +0 -121
- /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
- /package/src/{drivers/engine → actor}/keys.ts +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import z$1, { z } from 'zod';
|
|
2
|
+
import { Logger } from 'pino';
|
|
2
3
|
import * as hono from 'hono';
|
|
3
4
|
import { Env, Context, Hono } from 'hono';
|
|
4
|
-
import { WebSocket as WebSocket$1 } from 'ws';
|
|
5
|
-
import { Logger } from './common/log.js';
|
|
6
5
|
import { UpgradeWebSocket } from './utils.js';
|
|
7
6
|
import * as nanoevents from 'nanoevents';
|
|
8
|
-
import { g as Connection, h as RealtimeEvent } from './common-
|
|
7
|
+
import { g as Connection, h as RealtimeEvent } from './common-CXCe7s6i.js';
|
|
9
8
|
import { SSEStreamingApi } from 'hono/streaming';
|
|
10
9
|
import { WSContext } from 'hono/ws';
|
|
11
10
|
|
|
@@ -16,6 +15,7 @@ type Init = {
|
|
|
16
15
|
readonly connectionToken: string;
|
|
17
16
|
};
|
|
18
17
|
type Error$1 = {
|
|
18
|
+
readonly group: string;
|
|
19
19
|
readonly code: string;
|
|
20
20
|
readonly message: string;
|
|
21
21
|
readonly metadata: ArrayBuffer | null;
|
|
@@ -121,7 +121,7 @@ declare class CachedSerializer<T> {
|
|
|
121
121
|
serialize(encoding: Encoding): OutputData;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
declare const ActorsSchema: z.ZodRecord<z.ZodString, z.ZodType<ActorDefinition<any, any, any, any, any, any, any
|
|
124
|
+
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>>>;
|
|
125
125
|
type RegistryActors = z.infer<typeof ActorsSchema>;
|
|
126
126
|
/** Base config used for the actor config across all platforms. */
|
|
127
127
|
declare const RegistryConfigSchema: z.ZodObject<{
|
|
@@ -194,6 +194,52 @@ interface UniversalWebSocket {
|
|
|
194
194
|
onmessage?: ((event: RivetMessageEvent) => void) | null;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
198
|
+
declare const ClientConfigSchema: z$1.ZodObject<{
|
|
199
|
+
/** Configure serving the API */
|
|
200
|
+
api: z$1.ZodDefault<z$1.ZodObject<{
|
|
201
|
+
host: z$1.ZodDefault<z$1.ZodString>;
|
|
202
|
+
port: z$1.ZodDefault<z$1.ZodNumber>;
|
|
203
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
204
|
+
host: string;
|
|
205
|
+
port: number;
|
|
206
|
+
}, {
|
|
207
|
+
host?: string | undefined;
|
|
208
|
+
port?: number | undefined;
|
|
209
|
+
}>>;
|
|
210
|
+
/** Endpoint to connect to the Rivet engine. Can be configured via RIVET_ENGINE env var. */
|
|
211
|
+
endpoint: z$1.ZodDefault<z$1.ZodNullable<z$1.ZodString>>;
|
|
212
|
+
namespace: z$1.ZodDefault<z$1.ZodString>;
|
|
213
|
+
runnerName: z$1.ZodDefault<z$1.ZodString>;
|
|
214
|
+
encoding: z$1.ZodDefault<z$1.ZodEnum<["json", "cbor", "bare"]>>;
|
|
215
|
+
transport: z$1.ZodDefault<z$1.ZodEnum<["websocket", "sse"]>>;
|
|
216
|
+
getUpgradeWebSocket: z$1.ZodOptional<z$1.ZodType<GetUpgradeWebSocket, z$1.ZodTypeDef, GetUpgradeWebSocket>>;
|
|
217
|
+
}, "strip", z$1.ZodTypeAny, {
|
|
218
|
+
encoding: "json" | "cbor" | "bare";
|
|
219
|
+
api: {
|
|
220
|
+
host: string;
|
|
221
|
+
port: number;
|
|
222
|
+
};
|
|
223
|
+
endpoint: string | null;
|
|
224
|
+
namespace: string;
|
|
225
|
+
runnerName: string;
|
|
226
|
+
transport: "websocket" | "sse";
|
|
227
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
228
|
+
}, {
|
|
229
|
+
encoding?: "json" | "cbor" | "bare" | undefined;
|
|
230
|
+
api?: {
|
|
231
|
+
host?: string | undefined;
|
|
232
|
+
port?: number | undefined;
|
|
233
|
+
} | undefined;
|
|
234
|
+
endpoint?: string | null | undefined;
|
|
235
|
+
namespace?: string | undefined;
|
|
236
|
+
runnerName?: string | undefined;
|
|
237
|
+
transport?: "websocket" | "sse" | undefined;
|
|
238
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
239
|
+
}>;
|
|
240
|
+
type ClientConfig = z$1.infer<typeof ClientConfigSchema>;
|
|
241
|
+
type ClientConfigInput = z$1.input<typeof ClientConfigSchema>;
|
|
242
|
+
|
|
197
243
|
type ManagerDriverBuilder = (registryConfig: RegistryConfig, runConfig: RunConfig) => ManagerDriver;
|
|
198
244
|
interface ManagerDriver {
|
|
199
245
|
getForId(input: GetForIdInput): Promise<ActorOutput | undefined>;
|
|
@@ -201,12 +247,17 @@ interface ManagerDriver {
|
|
|
201
247
|
getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
|
|
202
248
|
createActor(input: CreateInput): Promise<ActorOutput>;
|
|
203
249
|
sendRequest(actorId: string, actorRequest: Request): Promise<Response>;
|
|
204
|
-
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown): Promise<
|
|
250
|
+
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown): Promise<UniversalWebSocket>;
|
|
205
251
|
proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
|
|
206
252
|
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown, authData: unknown): Promise<Response>;
|
|
253
|
+
displayInformation(): ManagerDisplayInformation;
|
|
207
254
|
extraStartupLog?: () => Record<string, unknown>;
|
|
208
255
|
modifyManagerRouter?: (registryConfig: RegistryConfig, router: Hono) => void;
|
|
209
256
|
}
|
|
257
|
+
interface ManagerDisplayInformation {
|
|
258
|
+
name: string;
|
|
259
|
+
properties: Record<string, string>;
|
|
260
|
+
}
|
|
210
261
|
interface GetForIdInput<E extends Env = any> {
|
|
211
262
|
c?: Context | undefined;
|
|
212
263
|
name: string;
|
|
@@ -237,7 +288,6 @@ interface ActorOutput {
|
|
|
237
288
|
key: ActorKey;
|
|
238
289
|
}
|
|
239
290
|
|
|
240
|
-
type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
241
291
|
declare const DriverConfigSchema: z.ZodObject<{
|
|
242
292
|
/** Machine-readable name to identify this driver by. */
|
|
243
293
|
name: z.ZodString;
|
|
@@ -255,6 +305,23 @@ declare const DriverConfigSchema: z.ZodObject<{
|
|
|
255
305
|
type DriverConfig = z.infer<typeof DriverConfigSchema>;
|
|
256
306
|
/** Base config used for the actor config across all platforms. */
|
|
257
307
|
declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
308
|
+
api: z.ZodDefault<z.ZodObject<{
|
|
309
|
+
host: z.ZodDefault<z.ZodString>;
|
|
310
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
311
|
+
}, "strip", z.ZodTypeAny, {
|
|
312
|
+
host: string;
|
|
313
|
+
port: number;
|
|
314
|
+
}, {
|
|
315
|
+
host?: string | undefined;
|
|
316
|
+
port?: number | undefined;
|
|
317
|
+
}>>;
|
|
318
|
+
endpoint: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
319
|
+
namespace: z.ZodDefault<z.ZodString>;
|
|
320
|
+
runnerName: z.ZodDefault<z.ZodString>;
|
|
321
|
+
encoding: z.ZodDefault<z.ZodEnum<["json", "cbor", "bare"]>>;
|
|
322
|
+
transport: z.ZodDefault<z.ZodEnum<["websocket", "sse"]>>;
|
|
323
|
+
getUpgradeWebSocket: z.ZodOptional<z.ZodType<GetUpgradeWebSocket, z.ZodTypeDef, GetUpgradeWebSocket>>;
|
|
324
|
+
} & {
|
|
258
325
|
driver: z.ZodOptional<z.ZodObject<{
|
|
259
326
|
/** Machine-readable name to identify this driver by. */
|
|
260
327
|
name: z.ZodString;
|
|
@@ -269,10 +336,6 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
269
336
|
name: string;
|
|
270
337
|
manager: ManagerDriverBuilder;
|
|
271
338
|
}>>;
|
|
272
|
-
/** Endpoint to connect to the Rivet engine. Can be configured via RIVET_ENGINE env var. */
|
|
273
|
-
engine: z.ZodOptional<z.ZodString>;
|
|
274
|
-
getUpgradeWebSocket: z.ZodOptional<z.ZodType<GetUpgradeWebSocket, z.ZodTypeDef, GetUpgradeWebSocket>>;
|
|
275
|
-
role: z.ZodDefault<z.ZodOptional<z.ZodEnum<["all", "server", "runner"]>>>;
|
|
276
339
|
/** CORS configuration for the router. Uses Hono's CORS middleware options. */
|
|
277
340
|
cors: z.ZodOptional<z.ZodType<{
|
|
278
341
|
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
@@ -334,13 +397,39 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
334
397
|
token?: ((...args: unknown[]) => string) | undefined;
|
|
335
398
|
defaultEndpoint?: string | undefined;
|
|
336
399
|
}>>>;
|
|
400
|
+
/** @experimental */
|
|
401
|
+
disableServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
402
|
+
/** @experimental */
|
|
403
|
+
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
337
404
|
/**
|
|
405
|
+
* @experimental
|
|
406
|
+
*
|
|
338
407
|
* Base path for the router. This is used to prefix all routes.
|
|
339
408
|
* For example, if the base path is `/api`, then the route `/actors` will be
|
|
340
409
|
* available at `/api/actors`.
|
|
341
410
|
*/
|
|
342
411
|
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
412
|
+
/**
|
|
413
|
+
* @experimental
|
|
414
|
+
*
|
|
415
|
+
* Disable welcome message.
|
|
416
|
+
* */
|
|
417
|
+
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
418
|
+
/**
|
|
419
|
+
* @experimental
|
|
420
|
+
* */
|
|
421
|
+
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
422
|
+
baseLogger: z.ZodOptional<z.ZodType<Logger, z.ZodTypeDef, Logger>>;
|
|
423
|
+
level: z.ZodOptional<z.ZodEnum<["trace", "debug", "info", "warn", "error", "fatal", "silent"]>>;
|
|
424
|
+
}, "strip", z.ZodTypeAny, {
|
|
425
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
426
|
+
baseLogger?: Logger | undefined;
|
|
427
|
+
}, {
|
|
428
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
429
|
+
baseLogger?: Logger | undefined;
|
|
430
|
+
}>>>;
|
|
343
431
|
}, "strip", z.ZodTypeAny, {
|
|
432
|
+
encoding: "json" | "cbor" | "bare";
|
|
344
433
|
inspector: {
|
|
345
434
|
enabled: boolean;
|
|
346
435
|
cors: {
|
|
@@ -354,9 +443,28 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
354
443
|
token: (...args: unknown[]) => string;
|
|
355
444
|
defaultEndpoint?: string | undefined;
|
|
356
445
|
};
|
|
357
|
-
|
|
446
|
+
api: {
|
|
447
|
+
host: string;
|
|
448
|
+
port: number;
|
|
449
|
+
};
|
|
450
|
+
endpoint: string | null;
|
|
451
|
+
namespace: string;
|
|
452
|
+
runnerName: string;
|
|
453
|
+
transport: "websocket" | "sse";
|
|
358
454
|
maxIncomingMessageSize: number;
|
|
455
|
+
disableServer: boolean;
|
|
456
|
+
disableActorDriver: boolean;
|
|
359
457
|
basePath: string;
|
|
458
|
+
noWelcome: boolean;
|
|
459
|
+
logging: {
|
|
460
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
461
|
+
baseLogger?: Logger | undefined;
|
|
462
|
+
};
|
|
463
|
+
driver?: {
|
|
464
|
+
actor: ActorDriverBuilder;
|
|
465
|
+
name: string;
|
|
466
|
+
manager: ManagerDriverBuilder;
|
|
467
|
+
} | undefined;
|
|
360
468
|
cors?: {
|
|
361
469
|
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
362
470
|
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
@@ -365,14 +473,14 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
365
473
|
credentials?: boolean;
|
|
366
474
|
exposeHeaders?: string[];
|
|
367
475
|
} | undefined;
|
|
476
|
+
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
477
|
+
}, {
|
|
478
|
+
encoding?: "json" | "cbor" | "bare" | undefined;
|
|
368
479
|
driver?: {
|
|
369
480
|
actor: ActorDriverBuilder;
|
|
370
481
|
name: string;
|
|
371
482
|
manager: ManagerDriverBuilder;
|
|
372
483
|
} | undefined;
|
|
373
|
-
engine?: string | undefined;
|
|
374
|
-
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
375
|
-
}, {
|
|
376
484
|
inspector?: {
|
|
377
485
|
enabled?: boolean | undefined;
|
|
378
486
|
cors?: {
|
|
@@ -394,25 +502,33 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
394
502
|
credentials?: boolean;
|
|
395
503
|
exposeHeaders?: string[];
|
|
396
504
|
} | undefined;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
manager: ManagerDriverBuilder;
|
|
505
|
+
api?: {
|
|
506
|
+
host?: string | undefined;
|
|
507
|
+
port?: number | undefined;
|
|
401
508
|
} | undefined;
|
|
402
|
-
|
|
509
|
+
endpoint?: string | null | undefined;
|
|
510
|
+
namespace?: string | undefined;
|
|
511
|
+
runnerName?: string | undefined;
|
|
512
|
+
transport?: "websocket" | "sse" | undefined;
|
|
403
513
|
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
404
|
-
role?: "all" | "server" | "runner" | undefined;
|
|
405
514
|
maxIncomingMessageSize?: number | undefined;
|
|
515
|
+
disableServer?: boolean | undefined;
|
|
516
|
+
disableActorDriver?: boolean | undefined;
|
|
406
517
|
basePath?: string | undefined;
|
|
518
|
+
noWelcome?: boolean | undefined;
|
|
519
|
+
logging?: {
|
|
520
|
+
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
521
|
+
baseLogger?: Logger | undefined;
|
|
522
|
+
} | undefined;
|
|
407
523
|
}>>;
|
|
408
524
|
type RunConfig = z.infer<typeof RunConfigSchema>;
|
|
409
525
|
type RunConfigInput = z.input<typeof RunConfigSchema>;
|
|
410
526
|
|
|
411
527
|
interface ServerOutput<A extends Registry<any>> {
|
|
528
|
+
/** Client to communicate with the actors. */
|
|
412
529
|
client: Client<A>;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
serve: (hono?: Hono) => void;
|
|
530
|
+
/** Fetch handler to manually route requests to the Rivet manager API. */
|
|
531
|
+
fetch: (request: Request, ...args: any) => Response | Promise<Response>;
|
|
416
532
|
}
|
|
417
533
|
declare class Registry<A extends RegistryActors> {
|
|
418
534
|
#private;
|
|
@@ -421,11 +537,7 @@ declare class Registry<A extends RegistryActors> {
|
|
|
421
537
|
/**
|
|
422
538
|
* Runs the registry for a server.
|
|
423
539
|
*/
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Runs the registry as a standalone server.
|
|
427
|
-
*/
|
|
428
|
-
runServer(inputConfig?: RunConfigInput): Promise<void>;
|
|
540
|
+
start(inputConfig?: RunConfigInput): ServerOutput<this>;
|
|
429
541
|
}
|
|
430
542
|
declare function setup<A extends RegistryActors>(input: RegistryConfigInput<A>): Registry<A>;
|
|
431
543
|
|
|
@@ -498,10 +610,10 @@ interface SaveStateOptions {
|
|
|
498
610
|
allowStoppingState?: boolean;
|
|
499
611
|
}
|
|
500
612
|
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
501
|
-
type AnyActorInstance = ActorInstance<any, any, any, any, any, any
|
|
502
|
-
declare class ActorInstance<S, CP, CS, V, I,
|
|
613
|
+
type AnyActorInstance = ActorInstance<any, any, any, any, any, any>;
|
|
614
|
+
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
503
615
|
#private;
|
|
504
|
-
actorContext: ActorContext<S, CP, CS, V, I,
|
|
616
|
+
actorContext: ActorContext<S, CP, CS, V, I, DB>;
|
|
505
617
|
get isStopping(): boolean;
|
|
506
618
|
get id(): string;
|
|
507
619
|
get inlineClient(): Client<Registry<any>>;
|
|
@@ -513,23 +625,23 @@ declare class ActorInstance<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider>
|
|
|
513
625
|
*
|
|
514
626
|
* @private
|
|
515
627
|
*/
|
|
516
|
-
constructor(config: ActorConfig<S, CP, CS, V, I,
|
|
628
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB>);
|
|
517
629
|
start(connectionDrivers: ConnectionDriversMap, actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
518
630
|
_onAlarm(): Promise<void>;
|
|
519
631
|
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
520
632
|
get stateEnabled(): boolean;
|
|
521
|
-
__getConnForId(id: string): Conn<S, CP, CS, V, I,
|
|
633
|
+
__getConnForId(id: string): Conn<S, CP, CS, V, I, DB> | undefined;
|
|
522
634
|
/**
|
|
523
635
|
* Removes a connection and cleans up its resources.
|
|
524
636
|
*/
|
|
525
|
-
__removeConn(conn: Conn<S, CP, CS, V, I,
|
|
637
|
+
__removeConn(conn: Conn<S, CP, CS, V, I, DB> | undefined): void;
|
|
526
638
|
prepareConn(params: any, request?: Request): Promise<CS>;
|
|
527
639
|
__getConnDriver(driverId: ConnectionDriver): ConnDriver;
|
|
528
640
|
/**
|
|
529
641
|
* Called after establishing a connection handshake.
|
|
530
642
|
*/
|
|
531
|
-
createConn(connectionId: string, connectionToken: string, params: CP, state: CS, driverId: ConnectionDriver, driverState: unknown, authData: unknown): Promise<Conn<S, CP, CS, V, I,
|
|
532
|
-
processMessage(message: ToServer, conn: Conn<S, CP, CS, V, I,
|
|
643
|
+
createConn(connectionId: string, connectionToken: string, params: CP, state: CS, driverId: ConnectionDriver, driverState: unknown, authData: unknown): Promise<Conn<S, CP, CS, V, I, DB>>;
|
|
644
|
+
processMessage(message: ToServer, conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
533
645
|
/**
|
|
534
646
|
* Check if the actor is ready to handle requests.
|
|
535
647
|
*/
|
|
@@ -541,20 +653,15 @@ declare class ActorInstance<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider>
|
|
|
541
653
|
/**
|
|
542
654
|
* Handles raw HTTP requests to the actor.
|
|
543
655
|
*/
|
|
544
|
-
handleFetch(request: Request, opts: {
|
|
545
|
-
auth: AD;
|
|
546
|
-
}): Promise<Response>;
|
|
656
|
+
handleFetch(request: Request, opts: {}): Promise<Response>;
|
|
547
657
|
/**
|
|
548
658
|
* Handles raw WebSocket connections to the actor.
|
|
549
659
|
*/
|
|
550
660
|
handleWebSocket(websocket: UniversalWebSocket, opts: {
|
|
551
661
|
request: Request;
|
|
552
|
-
auth: AD;
|
|
553
662
|
}): Promise<void>;
|
|
554
|
-
/**
|
|
555
|
-
* Gets the logger instance.
|
|
556
|
-
*/
|
|
557
663
|
get log(): Logger;
|
|
664
|
+
get rLog(): Logger;
|
|
558
665
|
/**
|
|
559
666
|
* Gets the name.
|
|
560
667
|
*/
|
|
@@ -574,7 +681,7 @@ declare class ActorInstance<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider>
|
|
|
574
681
|
/**
|
|
575
682
|
* Gets the map of connections.
|
|
576
683
|
*/
|
|
577
|
-
get conns(): Map<ConnId, Conn<S, CP, CS, V, I,
|
|
684
|
+
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
578
685
|
/**
|
|
579
686
|
* Gets the current state.
|
|
580
687
|
*
|
|
@@ -628,9 +735,9 @@ declare class ActorInstance<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider>
|
|
|
628
735
|
/**
|
|
629
736
|
* ActorContext class that provides access to actor methods and state
|
|
630
737
|
*/
|
|
631
|
-
declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
738
|
+
declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
632
739
|
#private;
|
|
633
|
-
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput,
|
|
740
|
+
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
634
741
|
/**
|
|
635
742
|
* Get the actor state
|
|
636
743
|
*/
|
|
@@ -672,7 +779,7 @@ declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TAuth
|
|
|
672
779
|
/**
|
|
673
780
|
* Gets the map of connections.
|
|
674
781
|
*/
|
|
675
|
-
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput,
|
|
782
|
+
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>;
|
|
676
783
|
/**
|
|
677
784
|
* Returns the client for the given registry.
|
|
678
785
|
*/
|
|
@@ -707,18 +814,16 @@ declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TAuth
|
|
|
707
814
|
sleep(): void;
|
|
708
815
|
}
|
|
709
816
|
|
|
710
|
-
type InitContext = ActorContext<undefined, undefined, undefined, undefined, undefined, undefined
|
|
711
|
-
interface ActorTypes<TState, TConnParams, TConnState, TVars, TInput,
|
|
817
|
+
type InitContext = ActorContext<undefined, undefined, undefined, undefined, undefined, undefined>;
|
|
818
|
+
interface ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
712
819
|
state?: TState;
|
|
713
820
|
connParams?: TConnParams;
|
|
714
821
|
connState?: TConnState;
|
|
715
822
|
vars?: TVars;
|
|
716
823
|
input?: TInput;
|
|
717
|
-
authData?: TAuthData;
|
|
718
824
|
database?: TDatabase;
|
|
719
825
|
}
|
|
720
826
|
declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
721
|
-
onAuth: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
722
827
|
onCreate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
723
828
|
onStart: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
724
829
|
onStop: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
@@ -791,7 +896,6 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
791
896
|
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
792
897
|
state?: any;
|
|
793
898
|
db?: any;
|
|
794
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
795
899
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
796
900
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
797
901
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -808,6 +912,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
808
912
|
vars?: any;
|
|
809
913
|
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
810
914
|
}, {
|
|
915
|
+
state?: any;
|
|
811
916
|
options?: {
|
|
812
917
|
createVarsTimeout?: number | undefined;
|
|
813
918
|
createConnStateTimeout?: number | undefined;
|
|
@@ -821,9 +926,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
821
926
|
noSleep?: boolean | undefined;
|
|
822
927
|
sleepTimeout?: number | undefined;
|
|
823
928
|
} | undefined;
|
|
824
|
-
state?: any;
|
|
825
929
|
db?: any;
|
|
826
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
827
930
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
828
931
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
829
932
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -857,7 +960,6 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
857
960
|
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
858
961
|
state?: any;
|
|
859
962
|
db?: any;
|
|
860
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
861
963
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
862
964
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
863
965
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -874,6 +976,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
874
976
|
vars?: any;
|
|
875
977
|
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
876
978
|
}, {
|
|
979
|
+
state?: any;
|
|
877
980
|
options?: {
|
|
878
981
|
createVarsTimeout?: number | undefined;
|
|
879
982
|
createConnStateTimeout?: number | undefined;
|
|
@@ -887,9 +990,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
887
990
|
noSleep?: boolean | undefined;
|
|
888
991
|
sleepTimeout?: number | undefined;
|
|
889
992
|
} | undefined;
|
|
890
|
-
state?: any;
|
|
891
993
|
db?: any;
|
|
892
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
893
994
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
894
995
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
895
996
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -923,7 +1024,6 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
923
1024
|
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
924
1025
|
state?: any;
|
|
925
1026
|
db?: any;
|
|
926
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
927
1027
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
928
1028
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
929
1029
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -940,6 +1040,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
940
1040
|
vars?: any;
|
|
941
1041
|
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
942
1042
|
}, {
|
|
1043
|
+
state?: any;
|
|
943
1044
|
options?: {
|
|
944
1045
|
createVarsTimeout?: number | undefined;
|
|
945
1046
|
createConnStateTimeout?: number | undefined;
|
|
@@ -953,9 +1054,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
953
1054
|
noSleep?: boolean | undefined;
|
|
954
1055
|
sleepTimeout?: number | undefined;
|
|
955
1056
|
} | undefined;
|
|
956
|
-
state?: any;
|
|
957
1057
|
db?: any;
|
|
958
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
959
1058
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
960
1059
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
961
1060
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -989,7 +1088,6 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
989
1088
|
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
990
1089
|
state?: any;
|
|
991
1090
|
db?: any;
|
|
992
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
993
1091
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
994
1092
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
995
1093
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -1006,6 +1104,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
1006
1104
|
vars?: any;
|
|
1007
1105
|
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1008
1106
|
}, {
|
|
1107
|
+
state?: any;
|
|
1009
1108
|
options?: {
|
|
1010
1109
|
createVarsTimeout?: number | undefined;
|
|
1011
1110
|
createConnStateTimeout?: number | undefined;
|
|
@@ -1019,9 +1118,7 @@ declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObj
|
|
|
1019
1118
|
noSleep?: boolean | undefined;
|
|
1020
1119
|
sleepTimeout?: number | undefined;
|
|
1021
1120
|
} | undefined;
|
|
1022
|
-
state?: any;
|
|
1023
1121
|
db?: any;
|
|
1024
|
-
onAuth?: ((...args: unknown[]) => unknown) | undefined;
|
|
1025
1122
|
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1026
1123
|
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1027
1124
|
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
@@ -1047,12 +1144,12 @@ interface OnConnectOptions {
|
|
|
1047
1144
|
*/
|
|
1048
1145
|
request?: Request;
|
|
1049
1146
|
}
|
|
1050
|
-
type CreateState<TState, TConnParams, TConnState, TVars, TInput,
|
|
1147
|
+
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1051
1148
|
state: TState;
|
|
1052
1149
|
} | {
|
|
1053
1150
|
createState: (c: InitContext, input: TInput) => TState | Promise<TState>;
|
|
1054
1151
|
} | Record<never, never>;
|
|
1055
|
-
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput,
|
|
1152
|
+
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1056
1153
|
connState: TConnState;
|
|
1057
1154
|
} | {
|
|
1058
1155
|
createConnState: (c: InitContext, opts: OnConnectOptions, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
@@ -1060,7 +1157,7 @@ type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TAuthData,
|
|
|
1060
1157
|
/**
|
|
1061
1158
|
* @experimental
|
|
1062
1159
|
*/
|
|
1063
|
-
type CreateVars<TState, TConnParams, TConnState, TVars, TInput,
|
|
1160
|
+
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1064
1161
|
/**
|
|
1065
1162
|
* @experimental
|
|
1066
1163
|
*/
|
|
@@ -1071,56 +1168,21 @@ type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TAuthData, TData
|
|
|
1071
1168
|
*/
|
|
1072
1169
|
createVars: (c: InitContext, driverCtx: any) => TVars | Promise<TVars>;
|
|
1073
1170
|
} | Record<never, never>;
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
* Called on the HTTP server before clients can interact with the actor.
|
|
1077
|
-
*
|
|
1078
|
-
* Only called for public endpoints. Calls to actors from within the backend
|
|
1079
|
-
* do not trigger this handler.
|
|
1080
|
-
*
|
|
1081
|
-
* Data returned from this handler will be available on `c.conn.auth`.
|
|
1082
|
-
*
|
|
1083
|
-
* This function is required for any public HTTP endpoint access. Use this hook
|
|
1084
|
-
* to validate client credentials and return authentication data that will be
|
|
1085
|
-
* available on connections. This runs on the HTTP server (not the actor)
|
|
1086
|
-
* in order to reduce load on the actor & prevent denial of server attacks
|
|
1087
|
-
* against individual actors.
|
|
1088
|
-
*
|
|
1089
|
-
* If you need access to actor state for authentication, use onBeforeConnect
|
|
1090
|
-
* with an empty onAuth function instead.
|
|
1091
|
-
*
|
|
1092
|
-
* You can also provide your own authentication middleware on your router if you
|
|
1093
|
-
* choose, then use onAuth to pass the authentication data (e.g. user ID) to the
|
|
1094
|
-
* actor itself.
|
|
1095
|
-
*
|
|
1096
|
-
* @param opts Authentication options including request and intent
|
|
1097
|
-
* @returns Authentication data to attach to connections (must be serializable)
|
|
1098
|
-
* @throws Throw an error to deny access to the actor
|
|
1099
|
-
*/
|
|
1100
|
-
onAuth: (opts: OnAuthOptions, params: TConnParams) => TAuthData | Promise<TAuthData>;
|
|
1101
|
-
} | Record<never, never>;
|
|
1102
|
-
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TAuthData, TDatabase extends AnyDatabaseProvider> {
|
|
1103
|
-
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TAuthData, TDatabase>, ...args: any[]) => any;
|
|
1171
|
+
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1172
|
+
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, ...args: any[]) => any;
|
|
1104
1173
|
}
|
|
1105
1174
|
/**
|
|
1106
1175
|
* @experimental
|
|
1107
1176
|
*/
|
|
1108
1177
|
type AuthIntent = "get" | "create" | "connect" | "action" | "message";
|
|
1109
|
-
interface
|
|
1110
|
-
request: Request;
|
|
1111
|
-
/**
|
|
1112
|
-
* @experimental
|
|
1113
|
-
*/
|
|
1114
|
-
intents: Set<AuthIntent>;
|
|
1115
|
-
}
|
|
1116
|
-
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthData, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TAuthData, TDatabase>> {
|
|
1178
|
+
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>> {
|
|
1117
1179
|
/**
|
|
1118
1180
|
* Called when the actor is first initialized.
|
|
1119
1181
|
*
|
|
1120
1182
|
* Use this hook to initialize your actor's state.
|
|
1121
1183
|
* This is called before any other lifecycle hooks.
|
|
1122
1184
|
*/
|
|
1123
|
-
onCreate?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1185
|
+
onCreate?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, input: TInput) => void | Promise<void>;
|
|
1124
1186
|
/**
|
|
1125
1187
|
* Called when the actor is started and ready to receive connections and action.
|
|
1126
1188
|
*
|
|
@@ -1129,7 +1191,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1129
1191
|
*
|
|
1130
1192
|
* @returns Void or a Promise that resolves when startup is complete
|
|
1131
1193
|
*/
|
|
1132
|
-
onStart?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1194
|
+
onStart?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1133
1195
|
/**
|
|
1134
1196
|
* Called when the actor is stopping or sleeping.
|
|
1135
1197
|
*
|
|
@@ -1140,7 +1202,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1140
1202
|
*
|
|
1141
1203
|
* @returns Void or a Promise that resolves when shutdown is complete
|
|
1142
1204
|
*/
|
|
1143
|
-
onStop?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1205
|
+
onStop?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1144
1206
|
/**
|
|
1145
1207
|
* Called when the actor's state changes.
|
|
1146
1208
|
*
|
|
@@ -1152,28 +1214,18 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1152
1214
|
*
|
|
1153
1215
|
* @param newState The updated state
|
|
1154
1216
|
*/
|
|
1155
|
-
onStateChange?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1217
|
+
onStateChange?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, newState: TState) => void;
|
|
1156
1218
|
/**
|
|
1157
1219
|
* Called before a client connects to the actor.
|
|
1158
1220
|
*
|
|
1159
|
-
* Unlike onAuth, this handler is still called for both internal and
|
|
1160
|
-
* public clients.
|
|
1161
|
-
*
|
|
1162
1221
|
* Use this hook to determine if a connection should be accepted
|
|
1163
|
-
* and to initialize connection-specific state.
|
|
1164
|
-
* on the actor and has access to actor state, but uses slightly
|
|
1165
|
-
* more resources on the actor rather than authenticating with onAuth.
|
|
1166
|
-
*
|
|
1167
|
-
* For authentication without actor state access, prefer onAuth.
|
|
1168
|
-
*
|
|
1169
|
-
* For authentication with actor state, use onBeforeConnect with an empty
|
|
1170
|
-
* onAuth handler.
|
|
1222
|
+
* and to initialize connection-specific state.
|
|
1171
1223
|
*
|
|
1172
1224
|
* @param opts Connection parameters including client-provided data
|
|
1173
1225
|
* @returns The initial connection state or a Promise that resolves to it
|
|
1174
1226
|
* @throws Throw an error to reject the connection
|
|
1175
1227
|
*/
|
|
1176
|
-
onBeforeConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1228
|
+
onBeforeConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, opts: OnConnectOptions, params: TConnParams) => void | Promise<void>;
|
|
1177
1229
|
/**
|
|
1178
1230
|
* Called when a client successfully connects to the actor.
|
|
1179
1231
|
*
|
|
@@ -1183,7 +1235,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1183
1235
|
* @param conn The connection object
|
|
1184
1236
|
* @returns Void or a Promise that resolves when connection handling is complete
|
|
1185
1237
|
*/
|
|
1186
|
-
onConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1238
|
+
onConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1187
1239
|
/**
|
|
1188
1240
|
* Called when a client disconnects from the actor.
|
|
1189
1241
|
*
|
|
@@ -1193,7 +1245,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1193
1245
|
* @param conn The connection that is being closed
|
|
1194
1246
|
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
1195
1247
|
*/
|
|
1196
|
-
onDisconnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1248
|
+
onDisconnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1197
1249
|
/**
|
|
1198
1250
|
* Called before sending an action response to the client.
|
|
1199
1251
|
*
|
|
@@ -1206,7 +1258,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1206
1258
|
* @param output The output that will be sent to the client
|
|
1207
1259
|
* @returns The modified output to send to the client
|
|
1208
1260
|
*/
|
|
1209
|
-
onBeforeActionResponse?: <Out>(c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1261
|
+
onBeforeActionResponse?: <Out>(c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
1210
1262
|
/**
|
|
1211
1263
|
* Called when a raw HTTP request is made to the actor.
|
|
1212
1264
|
*
|
|
@@ -1216,9 +1268,7 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1216
1268
|
* @param request The raw HTTP request object
|
|
1217
1269
|
* @returns A Response object to send back, or void to continue with default routing
|
|
1218
1270
|
*/
|
|
1219
|
-
onFetch?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1220
|
-
auth: TAuthData;
|
|
1221
|
-
}) => Response | Promise<Response>;
|
|
1271
|
+
onFetch?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, request: Request, opts: {}) => Response | Promise<Response>;
|
|
1222
1272
|
/**
|
|
1223
1273
|
* Called when a raw WebSocket connection is established to the actor.
|
|
1224
1274
|
*
|
|
@@ -1228,9 +1278,8 @@ interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TAuthD
|
|
|
1228
1278
|
* @param websocket The raw WebSocket connection
|
|
1229
1279
|
* @param request The original HTTP upgrade request
|
|
1230
1280
|
*/
|
|
1231
|
-
onWebSocket?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1281
|
+
onWebSocket?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, websocket: UniversalWebSocket, opts: {
|
|
1232
1282
|
request: Request;
|
|
1233
|
-
auth: TAuthData;
|
|
1234
1283
|
}) => void | Promise<void>;
|
|
1235
1284
|
actions: TActions;
|
|
1236
1285
|
}
|
|
@@ -1240,48 +1289,11 @@ type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
|
1240
1289
|
*/
|
|
1241
1290
|
db: TDatabase;
|
|
1242
1291
|
} | Record<never, never>;
|
|
1243
|
-
type ActorConfig<TState, TConnParams, TConnState, TVars, TInput,
|
|
1244
|
-
type ActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined,
|
|
1245
|
-
types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput,
|
|
1246
|
-
} & Omit<z.input<typeof ActorConfigSchema>, "actions" | "
|
|
1247
|
-
declare function test<TState, TConnParams, TConnState, TVars, TInput,
|
|
1248
|
-
|
|
1249
|
-
interface UniversalEvent {
|
|
1250
|
-
type: string;
|
|
1251
|
-
target?: any;
|
|
1252
|
-
currentTarget?: any;
|
|
1253
|
-
}
|
|
1254
|
-
interface UniversalMessageEvent extends UniversalEvent {
|
|
1255
|
-
data: string;
|
|
1256
|
-
lastEventId: string;
|
|
1257
|
-
origin: string;
|
|
1258
|
-
}
|
|
1259
|
-
interface UniversalErrorEvent extends UniversalEvent {
|
|
1260
|
-
message: string;
|
|
1261
|
-
filename?: string;
|
|
1262
|
-
lineno?: number;
|
|
1263
|
-
colno?: number;
|
|
1264
|
-
error?: any;
|
|
1265
|
-
}
|
|
1266
|
-
/**
|
|
1267
|
-
* Common EventSource interface that can be implemented by different EventSource-like classes
|
|
1268
|
-
* This is compatible with the standard EventSource API but allows for custom implementations
|
|
1269
|
-
*/
|
|
1270
|
-
interface UniversalEventSource {
|
|
1271
|
-
readonly CONNECTING: 0;
|
|
1272
|
-
readonly OPEN: 1;
|
|
1273
|
-
readonly CLOSED: 2;
|
|
1274
|
-
readonly readyState: 0 | 1 | 2;
|
|
1275
|
-
readonly url: string;
|
|
1276
|
-
readonly withCredentials: boolean;
|
|
1277
|
-
close(): void;
|
|
1278
|
-
addEventListener(type: string, listener: (event: any) => void): void;
|
|
1279
|
-
removeEventListener(type: string, listener: (event: any) => void): void;
|
|
1280
|
-
dispatchEvent(event: UniversalEvent): boolean;
|
|
1281
|
-
onopen?: ((event: UniversalEvent) => void) | null;
|
|
1282
|
-
onmessage?: ((event: UniversalMessageEvent) => void) | null;
|
|
1283
|
-
onerror?: ((event: UniversalErrorEvent) => void) | null;
|
|
1284
|
-
}
|
|
1292
|
+
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>;
|
|
1293
|
+
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>> = {
|
|
1294
|
+
types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
1295
|
+
} & 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>;
|
|
1296
|
+
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>;
|
|
1285
1297
|
|
|
1286
1298
|
declare const ActorKeySchema: z.ZodArray<z.ZodString, "many">;
|
|
1287
1299
|
type ActorKey = z.infer<typeof ActorKeySchema>;
|
|
@@ -1426,16 +1438,16 @@ declare function createGenericConnDrivers(globalState: GenericConnGlobalState):
|
|
|
1426
1438
|
*
|
|
1427
1439
|
* @typeParam A Actor this action belongs to
|
|
1428
1440
|
*/
|
|
1429
|
-
declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1441
|
+
declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1430
1442
|
#private;
|
|
1431
|
-
readonly conn: Conn<TState, TConnParams, TConnState, TVars, TInput,
|
|
1443
|
+
readonly conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
1432
1444
|
/**
|
|
1433
1445
|
* Should not be called directly.
|
|
1434
1446
|
*
|
|
1435
1447
|
* @param actorContext - The actor context
|
|
1436
1448
|
* @param conn - The connection associated with the action
|
|
1437
1449
|
*/
|
|
1438
|
-
constructor(actorContext: ActorContext<TState, TConnParams, TConnState, TVars, TInput,
|
|
1450
|
+
constructor(actorContext: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
1439
1451
|
/**
|
|
1440
1452
|
* Get the actor state
|
|
1441
1453
|
*/
|
|
@@ -1475,7 +1487,7 @@ declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TAut
|
|
|
1475
1487
|
/**
|
|
1476
1488
|
* Gets the map of connections.
|
|
1477
1489
|
*/
|
|
1478
|
-
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput,
|
|
1490
|
+
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>;
|
|
1479
1491
|
/**
|
|
1480
1492
|
* Returns the client for the given registry.
|
|
1481
1493
|
*/
|
|
@@ -1506,20 +1518,20 @@ declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TAut
|
|
|
1506
1518
|
sleep(): void;
|
|
1507
1519
|
}
|
|
1508
1520
|
|
|
1509
|
-
type AnyActorDefinition = ActorDefinition<any, any, any, any, any, any, any
|
|
1521
|
+
type AnyActorDefinition = ActorDefinition<any, any, any, any, any, any, any>;
|
|
1510
1522
|
/**
|
|
1511
1523
|
* Extracts the context type from an ActorDefinition
|
|
1512
1524
|
*/
|
|
1513
|
-
type ActorContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer
|
|
1525
|
+
type ActorContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB, any> ? ActorContext<S, CP, CS, V, I, DB> : never;
|
|
1514
1526
|
/**
|
|
1515
1527
|
* Extracts the context type from an ActorDefinition
|
|
1516
1528
|
*/
|
|
1517
|
-
type ActionContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer
|
|
1518
|
-
declare class ActorDefinition<S, CP, CS, V, I,
|
|
1529
|
+
type ActionContextOf<AD extends AnyActorDefinition> = AD extends ActorDefinition<infer S, infer CP, infer CS, infer V, infer I, infer DB, any> ? ActionContext<S, CP, CS, V, I, DB> : never;
|
|
1530
|
+
declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, R extends Actions<S, CP, CS, V, I, DB>> {
|
|
1519
1531
|
#private;
|
|
1520
|
-
constructor(config: ActorConfig<S, CP, CS, V, I,
|
|
1521
|
-
get config(): ActorConfig<S, CP, CS, V, I,
|
|
1522
|
-
instantiate(): ActorInstance<S, CP, CS, V, I,
|
|
1532
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB>);
|
|
1533
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB>;
|
|
1534
|
+
instantiate(): ActorInstance<S, CP, CS, V, I, DB>;
|
|
1523
1535
|
}
|
|
1524
1536
|
declare function lookupInRegistry(registryConfig: RegistryConfig, name: string): AnyActorDefinition;
|
|
1525
1537
|
|
|
@@ -1542,7 +1554,7 @@ type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unk
|
|
|
1542
1554
|
/**
|
|
1543
1555
|
* Maps action methods from actor definition to typed function signatures.
|
|
1544
1556
|
*/
|
|
1545
|
-
type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends ActorDefinition<any, any, any, any, any, any,
|
|
1557
|
+
type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends ActorDefinition<any, any, any, any, any, any, infer R> ? {
|
|
1546
1558
|
[K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
|
|
1547
1559
|
} : never;
|
|
1548
1560
|
|
|
@@ -1557,10 +1569,11 @@ declare class MalformedResponseMessage extends ActorClientError {
|
|
|
1557
1569
|
constructor(cause?: unknown);
|
|
1558
1570
|
}
|
|
1559
1571
|
declare class ActorError extends ActorClientError {
|
|
1572
|
+
readonly group: string;
|
|
1560
1573
|
readonly code: string;
|
|
1561
1574
|
readonly metadata?: unknown | undefined;
|
|
1562
1575
|
__type: string;
|
|
1563
|
-
constructor(code: string, message: string, metadata?: unknown | undefined);
|
|
1576
|
+
constructor(group: string, code: string, message: string, metadata?: unknown | undefined);
|
|
1564
1577
|
}
|
|
1565
1578
|
|
|
1566
1579
|
/**
|
|
@@ -1590,7 +1603,7 @@ declare class ActorConnRaw {
|
|
|
1590
1603
|
*
|
|
1591
1604
|
* @protected
|
|
1592
1605
|
*/
|
|
1593
|
-
constructor(client: ClientRaw, driver:
|
|
1606
|
+
constructor(client: ClientRaw, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1594
1607
|
/**
|
|
1595
1608
|
* Call a raw action connection. See {@link ActorConn} for type-safe action calls.
|
|
1596
1609
|
*
|
|
@@ -1621,7 +1634,7 @@ enc
|
|
|
1621
1634
|
* @param {string} eventName - The name of the event to subscribe to.
|
|
1622
1635
|
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
1623
1636
|
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
1624
|
-
* @see {@link https://rivet.
|
|
1637
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1625
1638
|
*/
|
|
1626
1639
|
on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1627
1640
|
/**
|
|
@@ -1631,7 +1644,7 @@ enc
|
|
|
1631
1644
|
* @param {string} eventName - The name of the event to subscribe to.
|
|
1632
1645
|
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
1633
1646
|
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
1634
|
-
* @see {@link https://rivet.
|
|
1647
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1635
1648
|
*/
|
|
1636
1649
|
once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1637
1650
|
/**
|
|
@@ -1680,7 +1693,7 @@ declare class ActorHandleRaw {
|
|
|
1680
1693
|
*
|
|
1681
1694
|
* @protected
|
|
1682
1695
|
*/
|
|
1683
|
-
constructor(client: any, driver:
|
|
1696
|
+
constructor(client: any, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1684
1697
|
/**
|
|
1685
1698
|
* Call a raw action. This method sends an HTTP request to invoke the named action.
|
|
1686
1699
|
*
|
|
@@ -1794,14 +1807,6 @@ interface ActorAccessor<AD extends AnyActorDefinition> {
|
|
|
1794
1807
|
*/
|
|
1795
1808
|
create(key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
1796
1809
|
}
|
|
1797
|
-
/**
|
|
1798
|
-
* Options for configuring the client.
|
|
1799
|
-
* @typedef {Object} ClientOptions
|
|
1800
|
-
*/
|
|
1801
|
-
interface ClientOptions {
|
|
1802
|
-
encoding?: Encoding;
|
|
1803
|
-
transport?: Transport;
|
|
1804
|
-
}
|
|
1805
1810
|
/**
|
|
1806
1811
|
* Options for querying actors.
|
|
1807
1812
|
* @typedef {Object} QueryOptions
|
|
@@ -1852,8 +1857,8 @@ interface CreateOptions extends QueryOptions {
|
|
|
1852
1857
|
* @typedef {Object} Region
|
|
1853
1858
|
* @property {string} id - The region ID.
|
|
1854
1859
|
* @property {string} name - The region name.
|
|
1855
|
-
* @see {@link https://rivet.
|
|
1856
|
-
* @see {@link https://rivet.
|
|
1860
|
+
* @see {@link https://rivet.dev/docs/edge|Edge Networking}
|
|
1861
|
+
* @see {@link https://rivet.dev/docs/regions|Available Regions}
|
|
1857
1862
|
*/
|
|
1858
1863
|
interface Region {
|
|
1859
1864
|
/**
|
|
@@ -1868,34 +1873,11 @@ interface Region {
|
|
|
1868
1873
|
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
1869
1874
|
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
1870
1875
|
declare const TRANSPORT_SYMBOL: unique symbol;
|
|
1871
|
-
interface ClientDriver {
|
|
1872
|
-
action<Args extends Array<unknown> = unknown[], Response = unknown>(c: Context | undefined, actorQuery: ActorQuery, encoding: Encoding, params: unknown, name: string, args: Args, opts: {
|
|
1873
|
-
signal?: AbortSignal;
|
|
1874
|
-
} | undefined): Promise<Response>;
|
|
1875
|
-
resolveActorId(c: Context | undefined, actorQuery: ActorQuery, encodingKind: Encoding, params: unknown, opts: {
|
|
1876
|
-
signal?: AbortSignal;
|
|
1877
|
-
} | undefined): Promise<string>;
|
|
1878
|
-
connectWebSocket(c: Context | undefined, actorQuery: ActorQuery, encodingKind: Encoding, params: unknown, opts: {
|
|
1879
|
-
signal?: AbortSignal;
|
|
1880
|
-
} | undefined): Promise<WebSocket$1>;
|
|
1881
|
-
connectSse(c: Context | undefined, actorQuery: ActorQuery, encodingKind: Encoding, params: unknown, opts: {
|
|
1882
|
-
signal?: AbortSignal;
|
|
1883
|
-
} | undefined): Promise<UniversalEventSource>;
|
|
1884
|
-
sendHttpMessage(c: Context | undefined, actorId: string, encoding: Encoding, connectionId: string, connectionToken: string, message: ToServer, opts: {
|
|
1885
|
-
signal?: AbortSignal;
|
|
1886
|
-
} | undefined): Promise<void>;
|
|
1887
|
-
rawHttpRequest(c: Context | undefined, actorQuery: ActorQuery, encoding: Encoding, params: unknown, path: string, init: RequestInit, opts: {
|
|
1888
|
-
signal?: AbortSignal;
|
|
1889
|
-
} | undefined): Promise<Response>;
|
|
1890
|
-
rawWebSocket(c: Context | undefined, actorQuery: ActorQuery, encoding: Encoding, params: unknown, path: string, protocols: string | string[] | undefined, opts: {
|
|
1891
|
-
signal?: AbortSignal;
|
|
1892
|
-
} | undefined): Promise<WebSocket$1>;
|
|
1893
|
-
}
|
|
1894
1876
|
/**
|
|
1895
1877
|
* Client for managing & connecting to actors.
|
|
1896
1878
|
*
|
|
1897
1879
|
* @template A The actors map type that defines the available actors.
|
|
1898
|
-
* @see {@link https://rivet.
|
|
1880
|
+
* @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
|
|
1899
1881
|
*/
|
|
1900
1882
|
declare class ClientRaw {
|
|
1901
1883
|
#private;
|
|
@@ -1904,11 +1886,11 @@ declare class ClientRaw {
|
|
|
1904
1886
|
/**
|
|
1905
1887
|
* Creates an instance of Client.
|
|
1906
1888
|
*
|
|
1907
|
-
* @param {string} managerEndpoint - The manager endpoint. See {@link https://rivet.
|
|
1908
|
-
* @param {
|
|
1909
|
-
* @see {@link https://rivet.
|
|
1889
|
+
* @param {string} managerEndpoint - The manager endpoint. See {@link https://rivet.dev/docs/setup|Initial Setup} for instructions on getting the manager endpoint.
|
|
1890
|
+
* @param {ClientConfig} [opts] - Options for configuring the client.
|
|
1891
|
+
* @see {@link https://rivet.dev/docs/setup|Initial Setup}
|
|
1910
1892
|
*/
|
|
1911
|
-
constructor(driver:
|
|
1893
|
+
constructor(driver: ManagerDriver, opts?: ClientConfig);
|
|
1912
1894
|
/**
|
|
1913
1895
|
* Gets a stateless handle to a actor by its ID.
|
|
1914
1896
|
*
|
|
@@ -1968,7 +1950,7 @@ type Client<A extends Registry<any>> = ClientRaw & {
|
|
|
1968
1950
|
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
|
|
1969
1951
|
};
|
|
1970
1952
|
type AnyClient = Client<Registry<any>>;
|
|
1971
|
-
declare function createClientWithDriver<A extends Registry<any>>(driver:
|
|
1953
|
+
declare function createClientWithDriver<A extends Registry<any>>(driver: ManagerDriver, config?: ClientConfig): Client<A>;
|
|
1972
1954
|
|
|
1973
1955
|
type ConnectionDriversMap = Record<ConnectionDriver, ConnDriver>;
|
|
1974
1956
|
type ActorDriverBuilder = (registryConfig: RegistryConfig, runConfig: RunConfig, managerDriver: ManagerDriver, inlineClient: AnyClient) => ActorDriver;
|
|
@@ -2028,7 +2010,7 @@ interface PersistedSubscription {
|
|
|
2028
2010
|
declare function generateConnId(): string;
|
|
2029
2011
|
declare function generateConnToken(): string;
|
|
2030
2012
|
type ConnId = string;
|
|
2031
|
-
type AnyConn = Conn<any, any, any, any, any, any
|
|
2013
|
+
type AnyConn = Conn<any, any, any, any, any, any>;
|
|
2032
2014
|
declare const CONNECTION_DRIVER_WEBSOCKET = "webSocket";
|
|
2033
2015
|
declare const CONNECTION_DRIVER_SSE = "sse";
|
|
2034
2016
|
declare const CONNECTION_DRIVER_HTTP = "http";
|
|
@@ -2039,9 +2021,9 @@ type ConnectionStatus = "connected" | "reconnecting";
|
|
|
2039
2021
|
*
|
|
2040
2022
|
* Manages connection-specific data and controls the connection lifecycle.
|
|
2041
2023
|
*
|
|
2042
|
-
* @see {@link https://rivet.
|
|
2024
|
+
* @see {@link https://rivet.dev/docs/connections|Connection Documentation}
|
|
2043
2025
|
*/
|
|
2044
|
-
declare class Conn<S, CP, CS, V, I,
|
|
2026
|
+
declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
2045
2027
|
#private;
|
|
2046
2028
|
subscriptions: Set<string>;
|
|
2047
2029
|
/**
|
|
@@ -2051,7 +2033,6 @@ declare class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
|
|
|
2051
2033
|
*/
|
|
2052
2034
|
__persist: PersistedConn<CP, CS>;
|
|
2053
2035
|
get params(): CP;
|
|
2054
|
-
get auth(): AD;
|
|
2055
2036
|
get driver(): ConnectionDriver;
|
|
2056
2037
|
get _stateEnabled(): boolean;
|
|
2057
2038
|
/**
|
|
@@ -2089,7 +2070,7 @@ declare class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
|
|
|
2089
2070
|
*
|
|
2090
2071
|
* @protected
|
|
2091
2072
|
*/
|
|
2092
|
-
constructor(actor: ActorInstance<S, CP, CS, V, I,
|
|
2073
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>, persist: PersistedConn<CP, CS>, driver: ConnDriver, stateEnabled: boolean);
|
|
2093
2074
|
/**
|
|
2094
2075
|
* Sends a WebSocket message to the client.
|
|
2095
2076
|
*
|
|
@@ -2103,7 +2084,7 @@ declare class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
|
|
|
2103
2084
|
*
|
|
2104
2085
|
* @param eventName - The name of the event.
|
|
2105
2086
|
* @param args - The arguments for the event.
|
|
2106
|
-
* @see {@link https://rivet.
|
|
2087
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
2107
2088
|
*/
|
|
2108
2089
|
send(eventName: string, ...args: unknown[]): void;
|
|
2109
2090
|
/**
|
|
@@ -2114,4 +2095,4 @@ declare class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
|
|
|
2114
2095
|
disconnect(reason?: string): Promise<void>;
|
|
2115
2096
|
}
|
|
2116
2097
|
|
|
2117
|
-
export { type
|
|
2098
|
+
export { type CreateRequest as $, type ActorDriver as A, type AnyActorInstance as B, type Client as C, type DriverConfig as D, type Encoding as E, type ActorTypes as F, GenericConnGlobalState as G, ActorConfigSchema as H, type InitContext as I, type AuthIntent as J, type ActorConfig as K, test as L, type RegistryConfig as M, type RegistryActors as N, type OnConnectOptions as O, RegistryConfigSchema as P, Registry as Q, type RunConfig as R, setup as S, type ClientConfigInput as T, type UniversalWebSocket as U, type Transport as V, ActorClientError as W, ActorError as X, InternalError as Y, MalformedResponseMessage as Z, ManagerError as _, type AnyDatabaseProvider as a, type ActorActionFunction as a0, type ActorConn as a1, type EventUnsubscribe as a2, ActorConnRaw as a3, type ActorHandle as a4, ActorHandleRaw as a5, type ActorAccessor as a6, ClientRaw as a7, type CreateOptions as a8, type ExtractActorsFromRegistry as a9, type ExtractRegistryFromClient as aa, type GetOptions as ab, type GetWithIdOptions as ac, type QueryOptions as ad, type Region as ae, ActorInstance as af, type ActorOutput as ag, type CreateInput as ah, type GetForIdInput as ai, type GetOrCreateWithKeyInput as aj, type GetWithKeyInput as ak, type ManagerDisplayInformation as al, type ManagerDriver as am, DriverConfigSchema as an, RunConfigSchema as ao, type Actions as b, type ActorConfigInput as c, ActorDefinition as d, generateConnToken as e, type AnyClient as f, generateConnId as g, createClientWithDriver as h, type ActorQuery as i, type RivetCloseEvent as j, type RivetEvent as k, type RivetMessageEvent as l, type ActorKey as m, ActionContext as n, Conn as o, type ConnectionDriver as p, type ConnectionStatus as q, CONNECTION_DRIVER_HTTP as r, CONNECTION_DRIVER_SSE as s, CONNECTION_DRIVER_WEBSOCKET as t, ActorContext as u, type ActionContextOf as v, type ActorContextOf as w, type AnyActorDefinition as x, lookupInRegistry as y, createGenericConnDrivers as z };
|