rivetkit 2.0.6 → 2.0.7-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schemas/actor-persist/v1.ts +0 -6
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.cts +28 -0
- package/dist/tsup/actor-router-consts-B3Lu87yJ.d.ts +28 -0
- package/dist/tsup/{chunk-MRRT2CZD.cjs → chunk-3MBP4WNC.cjs} +7 -7
- package/dist/tsup/{chunk-MRRT2CZD.cjs.map → chunk-3MBP4WNC.cjs.map} +1 -1
- package/dist/tsup/{chunk-TWGATZ3X.cjs → chunk-3Y45CIF4.cjs} +922 -872
- package/dist/tsup/chunk-3Y45CIF4.cjs.map +1 -0
- package/dist/tsup/chunk-4GP7BZSR.js +102 -0
- package/dist/tsup/chunk-4GP7BZSR.js.map +1 -0
- package/dist/tsup/{chunk-UFWAK3X2.cjs → chunk-5ZOHIKWG.cjs} +660 -385
- package/dist/tsup/chunk-5ZOHIKWG.cjs.map +1 -0
- package/dist/tsup/{chunk-5JBFVV4C.cjs → chunk-6EUWRXLT.cjs} +21 -7
- package/dist/tsup/chunk-6EUWRXLT.cjs.map +1 -0
- package/dist/tsup/{chunk-UTI5NCES.cjs → chunk-6OVKCDSH.cjs} +6 -6
- package/dist/tsup/{chunk-UTI5NCES.cjs.map → chunk-6OVKCDSH.cjs.map} +1 -1
- package/dist/tsup/{chunk-VPV4MWXR.js → chunk-7N56ZUC7.js} +3 -3
- package/dist/tsup/{chunk-DIAYNQTE.cjs → chunk-B3TLRM4Q.cjs} +12 -12
- package/dist/tsup/{chunk-DIAYNQTE.cjs.map → chunk-B3TLRM4Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-4CKHQRXG.js → chunk-BW5DPM6Z.js} +515 -240
- package/dist/tsup/chunk-BW5DPM6Z.js.map +1 -0
- package/dist/tsup/{chunk-NTCUGYSD.cjs → chunk-DFS77KAA.cjs} +34 -31
- package/dist/tsup/chunk-DFS77KAA.cjs.map +1 -0
- package/dist/tsup/{chunk-VCEHU56K.js → chunk-E4UVJKSV.js} +2 -2
- package/dist/tsup/chunk-G4ABMAQY.cjs +102 -0
- package/dist/tsup/chunk-G4ABMAQY.cjs.map +1 -0
- package/dist/tsup/{chunk-ZYLTS2EM.js → chunk-GZVBFXBI.js} +2 -2
- package/dist/tsup/{chunk-W6LN7AF5.js → chunk-HPT3I7UU.js} +866 -816
- package/dist/tsup/chunk-HPT3I7UU.js.map +1 -0
- package/dist/tsup/{chunk-7OUKNSTU.js → chunk-JD54PXWP.js} +17 -14
- package/dist/tsup/chunk-JD54PXWP.js.map +1 -0
- package/dist/tsup/{chunk-KG3C7MKR.cjs → chunk-K4ENQCC4.cjs} +3 -3
- package/dist/tsup/{chunk-KG3C7MKR.cjs.map → chunk-K4ENQCC4.cjs.map} +1 -1
- package/dist/tsup/{chunk-WC2PSJWN.js → chunk-PUSQNDJG.js} +2 -2
- package/dist/tsup/{chunk-RGQR2J7S.js → chunk-RVP5RUSC.js} +20 -6
- package/dist/tsup/chunk-RVP5RUSC.js.map +1 -0
- package/dist/tsup/{chunk-TCUI5JFE.cjs → chunk-SAZCNSVY.cjs} +45 -18
- package/dist/tsup/chunk-SAZCNSVY.cjs.map +1 -0
- package/dist/tsup/{chunk-G75SVQON.js → chunk-SBKRVQS2.js} +9 -5
- package/dist/tsup/chunk-SBKRVQS2.js.map +1 -0
- package/dist/tsup/{chunk-6P6RA47N.cjs → chunk-TZGUSEIJ.cjs} +14 -10
- package/dist/tsup/chunk-TZGUSEIJ.cjs.map +1 -0
- package/dist/tsup/{chunk-2K3JMDAN.js → chunk-YQ4XQYPM.js} +40 -13
- package/dist/tsup/chunk-YQ4XQYPM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +7 -8
- package/dist/tsup/client/mod.d.ts +7 -8
- 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/{connection-BLemxi4f.d.ts → conn-DCSQgIlw.d.ts} +1605 -1353
- package/dist/tsup/{connection-CpDIydXf.d.cts → conn-DdzHTm2E.d.cts} +1605 -1353
- package/dist/tsup/driver-helpers/mod.cjs +31 -5
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +7 -8
- package/dist/tsup/driver-helpers/mod.d.ts +7 -8
- package/dist/tsup/driver-helpers/mod.js +33 -7
- package/dist/tsup/driver-test-suite/mod.cjs +317 -222
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +7 -7
- package/dist/tsup/driver-test-suite/mod.d.ts +7 -7
- package/dist/tsup/driver-test-suite/mod.js +582 -487
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +16 -6
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +34 -7
- package/dist/tsup/inspector/mod.d.ts +34 -7
- package/dist/tsup/inspector/mod.js +17 -7
- package/dist/tsup/mod.cjs +10 -20
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -7
- package/dist/tsup/mod.d.ts +9 -7
- package/dist/tsup/mod.js +9 -19
- package/dist/tsup/test/mod.cjs +11 -11
- package/dist/tsup/test/mod.d.cts +6 -7
- package/dist/tsup/test/mod.d.ts +6 -7
- package/dist/tsup/test/mod.js +10 -10
- package/dist/tsup/utils.cjs +4 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +11 -1
- package/dist/tsup/utils.d.ts +11 -1
- package/dist/tsup/utils.js +3 -1
- package/package.json +8 -4
- package/src/actor/action.ts +1 -1
- package/src/actor/config.ts +1 -1
- package/src/actor/conn-drivers.ts +205 -0
- package/src/actor/conn-socket.ts +6 -0
- package/src/actor/{connection.ts → conn.ts} +78 -84
- package/src/actor/context.ts +1 -1
- package/src/actor/driver.ts +4 -43
- package/src/actor/instance.ts +162 -86
- package/src/actor/mod.ts +1 -11
- package/src/actor/persisted.ts +2 -5
- package/src/actor/protocol/old.ts +1 -1
- package/src/actor/router-endpoints.ts +142 -106
- package/src/actor/router.ts +81 -45
- package/src/actor/utils.ts +5 -1
- package/src/client/actor-conn.ts +154 -23
- package/src/client/client.ts +1 -1
- package/src/client/config.ts +7 -0
- package/src/common/actor-router-consts.ts +29 -8
- package/src/common/router.ts +2 -1
- package/src/common/versioned-data.ts +5 -5
- package/src/driver-helpers/mod.ts +14 -1
- package/src/driver-test-suite/mod.ts +11 -2
- package/src/driver-test-suite/test-inline-client-driver.ts +36 -18
- package/src/driver-test-suite/tests/actor-conn-state.ts +66 -22
- package/src/driver-test-suite/tests/actor-conn.ts +65 -126
- package/src/driver-test-suite/tests/actor-reconnect.ts +160 -0
- package/src/driver-test-suite/tests/actor-sleep.ts +0 -1
- package/src/driver-test-suite/tests/raw-websocket.ts +0 -35
- package/src/driver-test-suite/utils.ts +3 -3
- package/src/drivers/default.ts +8 -7
- package/src/drivers/engine/actor-driver.ts +53 -31
- package/src/drivers/engine/config.ts +4 -0
- package/src/drivers/file-system/actor.ts +0 -6
- package/src/drivers/file-system/global-state.ts +3 -14
- package/src/drivers/file-system/manager.ts +12 -8
- package/src/inspector/actor.ts +4 -3
- package/src/inspector/config.ts +10 -1
- package/src/inspector/mod.ts +1 -0
- package/src/inspector/utils.ts +23 -4
- package/src/manager/driver.ts +11 -1
- package/src/manager/gateway.ts +407 -0
- package/src/manager/router.ts +269 -468
- package/src/manager-api/actors.ts +61 -0
- package/src/manager-api/common.ts +4 -0
- package/src/mod.ts +1 -1
- package/src/registry/mod.ts +119 -10
- package/src/remote-manager-driver/actor-http-client.ts +30 -19
- package/src/remote-manager-driver/actor-websocket-client.ts +43 -16
- package/src/remote-manager-driver/api-endpoints.ts +19 -21
- package/src/remote-manager-driver/api-utils.ts +10 -1
- package/src/remote-manager-driver/mod.ts +51 -48
- package/src/remote-manager-driver/ws-proxy.ts +2 -9
- package/src/test/mod.ts +6 -2
- package/src/utils.ts +21 -2
- package/dist/tsup/actor-router-consts-BK6arfy8.d.cts +0 -17
- package/dist/tsup/actor-router-consts-BK6arfy8.d.ts +0 -17
- package/dist/tsup/chunk-2K3JMDAN.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-4CKHQRXG.js.map +0 -1
- package/dist/tsup/chunk-5JBFVV4C.cjs.map +0 -1
- package/dist/tsup/chunk-6P6RA47N.cjs.map +0 -1
- package/dist/tsup/chunk-7OUKNSTU.js.map +0 -1
- package/dist/tsup/chunk-G75SVQON.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-NTCUGYSD.cjs.map +0 -1
- package/dist/tsup/chunk-RGQR2J7S.js.map +0 -1
- package/dist/tsup/chunk-TCUI5JFE.cjs.map +0 -1
- package/dist/tsup/chunk-TWGATZ3X.cjs.map +0 -1
- package/dist/tsup/chunk-UFWAK3X2.cjs.map +0 -1
- package/dist/tsup/chunk-W6LN7AF5.js.map +0 -1
- package/dist/tsup/common-CXCe7s6i.d.cts +0 -218
- package/dist/tsup/common-CXCe7s6i.d.ts +0 -218
- package/src/actor/generic-conn-driver.ts +0 -246
- package/src/common/fake-event-source.ts +0 -267
- package/src/manager-api/routes/actors-create.ts +0 -16
- package/src/manager-api/routes/actors-delete.ts +0 -4
- package/src/manager-api/routes/actors-get-by-id.ts +0 -7
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +0 -29
- package/src/manager-api/routes/actors-get.ts +0 -7
- package/src/manager-api/routes/common.ts +0 -18
- /package/dist/tsup/{chunk-VPV4MWXR.js.map → chunk-7N56ZUC7.js.map} +0 -0
- /package/dist/tsup/{chunk-VCEHU56K.js.map → chunk-E4UVJKSV.js.map} +0 -0
- /package/dist/tsup/{chunk-ZYLTS2EM.js.map → chunk-GZVBFXBI.js.map} +0 -0
- /package/dist/tsup/{chunk-WC2PSJWN.js.map → chunk-PUSQNDJG.js.map} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { SSEStreamingApi } from 'hono/streaming';
|
|
2
|
+
import { WSContext } from 'hono/ws';
|
|
3
|
+
import { UpgradeWebSocket, promiseWithResolvers } from './utils.cjs';
|
|
1
4
|
import z$1, { z } from 'zod';
|
|
2
5
|
import { Logger } from 'pino';
|
|
3
6
|
import * as hono from 'hono';
|
|
4
7
|
import { Env, Context, Hono } from 'hono';
|
|
5
|
-
import { UpgradeWebSocket } from './utils.cjs';
|
|
6
8
|
import * as nanoevents from 'nanoevents';
|
|
7
|
-
import
|
|
8
|
-
import { SSEStreamingApi } from 'hono/streaming';
|
|
9
|
-
import { WSContext } from 'hono/ws';
|
|
9
|
+
import z__default from 'zod/v4';
|
|
10
10
|
|
|
11
11
|
type uint = bigint;
|
|
12
12
|
type Init = {
|
|
@@ -65,60 +65,43 @@ type ToServer = {
|
|
|
65
65
|
readonly body: ToServerBody;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
type
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}> = {
|
|
73
|
-
/**
|
|
74
|
-
* Creates a new database client for the actor.
|
|
75
|
-
* The result is passed to the actor context as `c.db`.
|
|
76
|
-
* @experimental
|
|
77
|
-
*/
|
|
78
|
-
createClient: (ctx: {
|
|
79
|
-
getDatabase: () => Promise<string | unknown>;
|
|
80
|
-
}) => Promise<DB>;
|
|
81
|
-
/**
|
|
82
|
-
* Runs before the actor has started.
|
|
83
|
-
* Use this to run migrations or other setup tasks.
|
|
84
|
-
* @experimental
|
|
85
|
-
*/
|
|
86
|
-
onMigrate: (client: DB) => void | Promise<void>;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
type MigrationFn<TFrom, TTo> = (data: TFrom) => TTo;
|
|
90
|
-
interface VersionedDataConfig<T> {
|
|
91
|
-
currentVersion: number;
|
|
92
|
-
migrations: Map<number, MigrationFn<any, any>>;
|
|
93
|
-
serializeVersion: (data: T) => Uint8Array;
|
|
94
|
-
deserializeVersion: (bytes: Uint8Array) => T;
|
|
68
|
+
interface RivetEvent {
|
|
69
|
+
type: string;
|
|
70
|
+
target?: any;
|
|
71
|
+
currentTarget?: any;
|
|
95
72
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
private embedVersion;
|
|
104
|
-
private extractVersion;
|
|
73
|
+
interface RivetMessageEvent extends RivetEvent {
|
|
74
|
+
data: any;
|
|
75
|
+
}
|
|
76
|
+
interface RivetCloseEvent extends RivetEvent {
|
|
77
|
+
code: number;
|
|
78
|
+
reason: string;
|
|
79
|
+
wasClean: boolean;
|
|
105
80
|
}
|
|
106
|
-
|
|
107
|
-
/** Data that's been serialized. */
|
|
108
|
-
type OutputData = string | Uint8Array;
|
|
109
|
-
declare const EncodingSchema: z.ZodEnum<["json", "cbor", "bare"]>;
|
|
110
|
-
/**
|
|
111
|
-
* Encoding used to communicate between the client & actor.
|
|
112
|
-
*/
|
|
113
|
-
type Encoding = z.infer<typeof EncodingSchema>;
|
|
114
81
|
/**
|
|
115
|
-
*
|
|
82
|
+
* Common WebSocket interface that can be implemented by different WebSocket-like classes
|
|
83
|
+
* This is compatible with the standard WebSocket API but allows for custom implementations
|
|
116
84
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
85
|
+
interface UniversalWebSocket {
|
|
86
|
+
readonly CONNECTING: 0;
|
|
87
|
+
readonly OPEN: 1;
|
|
88
|
+
readonly CLOSING: 2;
|
|
89
|
+
readonly CLOSED: 3;
|
|
90
|
+
readonly readyState: 0 | 1 | 2 | 3;
|
|
91
|
+
binaryType: "arraybuffer" | "blob";
|
|
92
|
+
readonly bufferedAmount: number;
|
|
93
|
+
readonly extensions: string;
|
|
94
|
+
readonly protocol: string;
|
|
95
|
+
readonly url: string;
|
|
96
|
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
97
|
+
close(code?: number, reason?: string): void;
|
|
98
|
+
addEventListener(type: string, listener: (event: any) => void): void;
|
|
99
|
+
removeEventListener(type: string, listener: (event: any) => void): void;
|
|
100
|
+
dispatchEvent(event: RivetEvent): boolean;
|
|
101
|
+
onopen?: ((event: RivetEvent) => void) | null;
|
|
102
|
+
onclose?: ((event: RivetCloseEvent) => void) | null;
|
|
103
|
+
onerror?: ((event: RivetEvent) => void) | null;
|
|
104
|
+
onmessage?: ((event: RivetMessageEvent) => void) | null;
|
|
122
105
|
}
|
|
123
106
|
|
|
124
107
|
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>>>;
|
|
@@ -155,45 +138,6 @@ type RegistryConfigInput<A extends RegistryActors> = Omit<z.input<typeof Registr
|
|
|
155
138
|
use: A;
|
|
156
139
|
};
|
|
157
140
|
|
|
158
|
-
interface RivetEvent {
|
|
159
|
-
type: string;
|
|
160
|
-
target?: any;
|
|
161
|
-
currentTarget?: any;
|
|
162
|
-
}
|
|
163
|
-
interface RivetMessageEvent extends RivetEvent {
|
|
164
|
-
data: any;
|
|
165
|
-
}
|
|
166
|
-
interface RivetCloseEvent extends RivetEvent {
|
|
167
|
-
code: number;
|
|
168
|
-
reason: string;
|
|
169
|
-
wasClean: boolean;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Common WebSocket interface that can be implemented by different WebSocket-like classes
|
|
173
|
-
* This is compatible with the standard WebSocket API but allows for custom implementations
|
|
174
|
-
*/
|
|
175
|
-
interface UniversalWebSocket {
|
|
176
|
-
readonly CONNECTING: 0;
|
|
177
|
-
readonly OPEN: 1;
|
|
178
|
-
readonly CLOSING: 2;
|
|
179
|
-
readonly CLOSED: 3;
|
|
180
|
-
readonly readyState: 0 | 1 | 2 | 3;
|
|
181
|
-
binaryType: "arraybuffer" | "blob";
|
|
182
|
-
readonly bufferedAmount: number;
|
|
183
|
-
readonly extensions: string;
|
|
184
|
-
readonly protocol: string;
|
|
185
|
-
readonly url: string;
|
|
186
|
-
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
187
|
-
close(code?: number, reason?: string): void;
|
|
188
|
-
addEventListener(type: string, listener: (event: any) => void): void;
|
|
189
|
-
removeEventListener(type: string, listener: (event: any) => void): void;
|
|
190
|
-
dispatchEvent(event: RivetEvent): boolean;
|
|
191
|
-
onopen?: ((event: RivetEvent) => void) | null;
|
|
192
|
-
onclose?: ((event: RivetCloseEvent) => void) | null;
|
|
193
|
-
onerror?: ((event: RivetEvent) => void) | null;
|
|
194
|
-
onmessage?: ((event: RivetMessageEvent) => void) | null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
141
|
type GetUpgradeWebSocket = () => UpgradeWebSocket;
|
|
198
142
|
declare const ClientConfigSchema: z$1.ZodObject<{
|
|
199
143
|
/** Configure serving the API */
|
|
@@ -207,6 +151,8 @@ declare const ClientConfigSchema: z$1.ZodObject<{
|
|
|
207
151
|
host?: string | undefined;
|
|
208
152
|
port?: number | undefined;
|
|
209
153
|
}>>;
|
|
154
|
+
token: z$1.ZodEffects<z$1.ZodOptional<z$1.ZodString>, string | undefined, string | undefined>;
|
|
155
|
+
headers: z$1.ZodDefault<z$1.ZodOptional<z$1.ZodRecord<z$1.ZodString, z$1.ZodString>>>;
|
|
210
156
|
/** Endpoint to connect to the Rivet engine. Can be configured via RIVET_ENGINE env var. */
|
|
211
157
|
endpoint: z$1.ZodDefault<z$1.ZodNullable<z$1.ZodString>>;
|
|
212
158
|
namespace: z$1.ZodDefault<z$1.ZodString>;
|
|
@@ -220,10 +166,12 @@ declare const ClientConfigSchema: z$1.ZodObject<{
|
|
|
220
166
|
host: string;
|
|
221
167
|
port: number;
|
|
222
168
|
};
|
|
169
|
+
headers: Record<string, string>;
|
|
223
170
|
endpoint: string | null;
|
|
224
171
|
namespace: string;
|
|
225
172
|
runnerName: string;
|
|
226
173
|
transport: "websocket" | "sse";
|
|
174
|
+
token?: string | undefined;
|
|
227
175
|
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
228
176
|
}, {
|
|
229
177
|
encoding?: "json" | "cbor" | "bare" | undefined;
|
|
@@ -231,6 +179,8 @@ declare const ClientConfigSchema: z$1.ZodObject<{
|
|
|
231
179
|
host?: string | undefined;
|
|
232
180
|
port?: number | undefined;
|
|
233
181
|
} | undefined;
|
|
182
|
+
token?: string | undefined;
|
|
183
|
+
headers?: Record<string, string> | undefined;
|
|
234
184
|
endpoint?: string | null | undefined;
|
|
235
185
|
namespace?: string | undefined;
|
|
236
186
|
runnerName?: string | undefined;
|
|
@@ -247,9 +197,9 @@ interface ManagerDriver {
|
|
|
247
197
|
getOrCreateWithKey(input: GetOrCreateWithKeyInput): Promise<ActorOutput>;
|
|
248
198
|
createActor(input: CreateInput): Promise<ActorOutput>;
|
|
249
199
|
sendRequest(actorId: string, actorRequest: Request): Promise<Response>;
|
|
250
|
-
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown): Promise<UniversalWebSocket>;
|
|
200
|
+
openWebSocket(path: string, actorId: string, encoding: Encoding, params: unknown, connId?: string, connToken?: string): Promise<UniversalWebSocket>;
|
|
251
201
|
proxyRequest(c: Context, actorRequest: Request, actorId: string): Promise<Response>;
|
|
252
|
-
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown,
|
|
202
|
+
proxyWebSocket(c: Context, path: string, actorId: string, encoding: Encoding, params: unknown, connId?: string, connToken?: string): Promise<Response>;
|
|
253
203
|
displayInformation(): ManagerDisplayInformation;
|
|
254
204
|
extraStartupLog?: () => Record<string, unknown>;
|
|
255
205
|
modifyManagerRouter?: (registryConfig: RegistryConfig, router: Hono) => void;
|
|
@@ -288,6 +238,26 @@ interface ActorOutput {
|
|
|
288
238
|
key: ActorKey;
|
|
289
239
|
}
|
|
290
240
|
|
|
241
|
+
type ActorDriverBuilder = (registryConfig: RegistryConfig, runConfig: RunConfig, managerDriver: ManagerDriver, inlineClient: AnyClient) => ActorDriver;
|
|
242
|
+
interface ActorDriver {
|
|
243
|
+
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
244
|
+
getContext(actorId: string): unknown;
|
|
245
|
+
readPersistedData(actorId: string): Promise<Uint8Array | undefined>;
|
|
246
|
+
/** ActorInstance ensure that only one instance of writePersistedData is called in parallel at a time. */
|
|
247
|
+
writePersistedData(actorId: string, data: Uint8Array): Promise<void>;
|
|
248
|
+
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
249
|
+
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* @experimental
|
|
252
|
+
* This is an experimental API that may change in the future.
|
|
253
|
+
*/
|
|
254
|
+
getDatabase(actorId: string): Promise<unknown | undefined>;
|
|
255
|
+
sleep?(actorId: string): Promise<void>;
|
|
256
|
+
shutdown?(immediate: boolean): Promise<void>;
|
|
257
|
+
/** This handles the serverless start request. This should manage the lifecycle of the runner tied to the request lifecycle. */
|
|
258
|
+
serverlessHandleStart?(c: Context): Promise<Response>;
|
|
259
|
+
}
|
|
260
|
+
|
|
291
261
|
declare const DriverConfigSchema: z.ZodObject<{
|
|
292
262
|
/** Machine-readable name to identify this driver by. */
|
|
293
263
|
name: z.ZodString;
|
|
@@ -315,6 +285,8 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
315
285
|
host?: string | undefined;
|
|
316
286
|
port?: number | undefined;
|
|
317
287
|
}>>;
|
|
288
|
+
token: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
289
|
+
headers: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
318
290
|
endpoint: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
319
291
|
namespace: z.ZodDefault<z.ZodString>;
|
|
320
292
|
runnerName: z.ZodDefault<z.ZodString>;
|
|
@@ -338,15 +310,15 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
338
310
|
}>>;
|
|
339
311
|
/** CORS configuration for the router. Uses Hono's CORS middleware options. */
|
|
340
312
|
cors: z.ZodOptional<z.ZodType<{
|
|
341
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
342
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
313
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
314
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
343
315
|
allowHeaders?: string[];
|
|
344
316
|
maxAge?: number;
|
|
345
317
|
credentials?: boolean;
|
|
346
318
|
exposeHeaders?: string[];
|
|
347
319
|
}, z.ZodTypeDef, {
|
|
348
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
349
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
320
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
321
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
350
322
|
allowHeaders?: string[];
|
|
351
323
|
maxAge?: number;
|
|
352
324
|
credentials?: boolean;
|
|
@@ -354,17 +326,26 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
354
326
|
}>>;
|
|
355
327
|
maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
356
328
|
inspector: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
357
|
-
enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean
|
|
329
|
+
enabled: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
|
|
330
|
+
actor: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
331
|
+
manager: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
332
|
+
}, "strip", z.ZodTypeAny, {
|
|
333
|
+
actor: boolean;
|
|
334
|
+
manager: boolean;
|
|
335
|
+
}, {
|
|
336
|
+
actor?: boolean | undefined;
|
|
337
|
+
manager?: boolean | undefined;
|
|
338
|
+
}>]>>>;
|
|
358
339
|
cors: z.ZodDefault<z.ZodOptional<z.ZodType<{
|
|
359
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
360
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
340
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
341
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
361
342
|
allowHeaders?: string[];
|
|
362
343
|
maxAge?: number;
|
|
363
344
|
credentials?: boolean;
|
|
364
345
|
exposeHeaders?: string[];
|
|
365
346
|
}, z.ZodTypeDef, {
|
|
366
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
367
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
347
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
348
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
368
349
|
allowHeaders?: string[];
|
|
369
350
|
maxAge?: number;
|
|
370
351
|
credentials?: boolean;
|
|
@@ -373,10 +354,13 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
373
354
|
token: z.ZodDefault<z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodString>>>;
|
|
374
355
|
defaultEndpoint: z.ZodOptional<z.ZodString>;
|
|
375
356
|
}, "strip", z.ZodTypeAny, {
|
|
376
|
-
enabled: boolean
|
|
357
|
+
enabled: boolean | {
|
|
358
|
+
actor: boolean;
|
|
359
|
+
manager: boolean;
|
|
360
|
+
};
|
|
377
361
|
cors: {
|
|
378
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
379
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
362
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
363
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
380
364
|
allowHeaders?: string[];
|
|
381
365
|
maxAge?: number;
|
|
382
366
|
credentials?: boolean;
|
|
@@ -385,10 +369,13 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
385
369
|
token: (...args: unknown[]) => string;
|
|
386
370
|
defaultEndpoint?: string | undefined;
|
|
387
371
|
}, {
|
|
388
|
-
enabled?: boolean |
|
|
372
|
+
enabled?: boolean | {
|
|
373
|
+
actor?: boolean | undefined;
|
|
374
|
+
manager?: boolean | undefined;
|
|
375
|
+
} | undefined;
|
|
389
376
|
cors?: {
|
|
390
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
391
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
377
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
378
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
392
379
|
allowHeaders?: string[];
|
|
393
380
|
maxAge?: number;
|
|
394
381
|
credentials?: boolean;
|
|
@@ -431,10 +418,13 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
431
418
|
}, "strip", z.ZodTypeAny, {
|
|
432
419
|
encoding: "json" | "cbor" | "bare";
|
|
433
420
|
inspector: {
|
|
434
|
-
enabled: boolean
|
|
421
|
+
enabled: boolean | {
|
|
422
|
+
actor: boolean;
|
|
423
|
+
manager: boolean;
|
|
424
|
+
};
|
|
435
425
|
cors: {
|
|
436
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
437
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
426
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
427
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
438
428
|
allowHeaders?: string[];
|
|
439
429
|
maxAge?: number;
|
|
440
430
|
credentials?: boolean;
|
|
@@ -447,6 +437,7 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
447
437
|
host: string;
|
|
448
438
|
port: number;
|
|
449
439
|
};
|
|
440
|
+
headers: Record<string, string>;
|
|
450
441
|
endpoint: string | null;
|
|
451
442
|
namespace: string;
|
|
452
443
|
runnerName: string;
|
|
@@ -466,13 +457,14 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
466
457
|
manager: ManagerDriverBuilder;
|
|
467
458
|
} | undefined;
|
|
468
459
|
cors?: {
|
|
469
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
470
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
460
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
461
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
471
462
|
allowHeaders?: string[];
|
|
472
463
|
maxAge?: number;
|
|
473
464
|
credentials?: boolean;
|
|
474
465
|
exposeHeaders?: string[];
|
|
475
466
|
} | undefined;
|
|
467
|
+
token?: string | undefined;
|
|
476
468
|
getUpgradeWebSocket?: GetUpgradeWebSocket | undefined;
|
|
477
469
|
}, {
|
|
478
470
|
encoding?: "json" | "cbor" | "bare" | undefined;
|
|
@@ -482,10 +474,13 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
482
474
|
manager: ManagerDriverBuilder;
|
|
483
475
|
} | undefined;
|
|
484
476
|
inspector?: {
|
|
485
|
-
enabled?: boolean |
|
|
477
|
+
enabled?: boolean | {
|
|
478
|
+
actor?: boolean | undefined;
|
|
479
|
+
manager?: boolean | undefined;
|
|
480
|
+
} | undefined;
|
|
486
481
|
cors?: {
|
|
487
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
488
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
482
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
483
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
489
484
|
allowHeaders?: string[];
|
|
490
485
|
maxAge?: number;
|
|
491
486
|
credentials?: boolean;
|
|
@@ -495,8 +490,8 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
495
490
|
defaultEndpoint?: string | undefined;
|
|
496
491
|
} | undefined;
|
|
497
492
|
cors?: {
|
|
498
|
-
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
499
|
-
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
493
|
+
origin: string | string[] | ((origin: string, c: hono.Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
494
|
+
allowMethods?: string[] | ((origin: string, c: hono.Context) => Promise<string[]> | string[]);
|
|
500
495
|
allowHeaders?: string[];
|
|
501
496
|
maxAge?: number;
|
|
502
497
|
credentials?: boolean;
|
|
@@ -506,6 +501,8 @@ declare const RunConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
506
501
|
host?: string | undefined;
|
|
507
502
|
port?: number | undefined;
|
|
508
503
|
} | undefined;
|
|
504
|
+
token?: string | undefined;
|
|
505
|
+
headers?: Record<string, string> | undefined;
|
|
509
506
|
endpoint?: string | null | undefined;
|
|
510
507
|
namespace?: string | undefined;
|
|
511
508
|
runnerName?: string | undefined;
|
|
@@ -538,58 +535,30 @@ declare class Registry<A extends RegistryActors> {
|
|
|
538
535
|
* Runs the registry for a server.
|
|
539
536
|
*/
|
|
540
537
|
start(inputConfig?: RunConfigInput): ServerOutput<this>;
|
|
538
|
+
startServerless(inputConfig?: RunConfigInput): ServerOutput<this>;
|
|
541
539
|
}
|
|
542
540
|
declare function setup<A extends RegistryActors>(input: RegistryConfigInput<A>): Registry<A>;
|
|
543
541
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
readonly emitter: nanoevents.Emitter<ActorInspectorEmitterEvents>;
|
|
565
|
-
get lastRealtimeEvents(): (({
|
|
566
|
-
type: "action";
|
|
567
|
-
name: string;
|
|
568
|
-
args: any[];
|
|
569
|
-
connId: string;
|
|
570
|
-
} | {
|
|
571
|
-
type: "broadcast";
|
|
572
|
-
eventName: string;
|
|
573
|
-
args: any[];
|
|
574
|
-
} | {
|
|
575
|
-
type: "subscribe";
|
|
576
|
-
eventName: string;
|
|
577
|
-
connId: string;
|
|
578
|
-
} | {
|
|
579
|
-
type: "unsubscribe";
|
|
580
|
-
eventName: string;
|
|
581
|
-
connId: string;
|
|
582
|
-
} | {
|
|
583
|
-
type: "event";
|
|
584
|
-
eventName: string;
|
|
585
|
-
args: any[];
|
|
586
|
-
connId: string;
|
|
587
|
-
}) & {
|
|
588
|
-
id: string;
|
|
589
|
-
timestamp: number;
|
|
590
|
-
})[];
|
|
591
|
-
constructor(accessors: () => ActorInspectorAccessors);
|
|
592
|
-
}
|
|
542
|
+
type InferDatabaseClient<DBProvider extends AnyDatabaseProvider> = DBProvider extends DatabaseProvider<any> ? Awaited<ReturnType<DBProvider["createClient"]>> : never;
|
|
543
|
+
type AnyDatabaseProvider = DatabaseProvider<any> | undefined;
|
|
544
|
+
type DatabaseProvider<DB extends {
|
|
545
|
+
execute: (query: string) => any;
|
|
546
|
+
}> = {
|
|
547
|
+
/**
|
|
548
|
+
* Creates a new database client for the actor.
|
|
549
|
+
* The result is passed to the actor context as `c.db`.
|
|
550
|
+
* @experimental
|
|
551
|
+
*/
|
|
552
|
+
createClient: (ctx: {
|
|
553
|
+
getDatabase: () => Promise<string | unknown>;
|
|
554
|
+
}) => Promise<DB>;
|
|
555
|
+
/**
|
|
556
|
+
* Runs before the actor has started.
|
|
557
|
+
* Use this to run migrations or other setup tasks.
|
|
558
|
+
* @experimental
|
|
559
|
+
*/
|
|
560
|
+
onMigrate: (client: DB) => void | Promise<void>;
|
|
561
|
+
};
|
|
593
562
|
|
|
594
563
|
declare class Schedule {
|
|
595
564
|
#private;
|
|
@@ -599,157 +568,23 @@ declare class Schedule {
|
|
|
599
568
|
}
|
|
600
569
|
|
|
601
570
|
/**
|
|
602
|
-
*
|
|
571
|
+
* ActorContext class that provides access to actor methods and state
|
|
603
572
|
*/
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Forces the state to be saved immediately. This function will return when the state has saved successfully.
|
|
607
|
-
*/
|
|
608
|
-
immediate?: boolean;
|
|
609
|
-
/** Bypass ready check for stopping. */
|
|
610
|
-
allowStoppingState?: boolean;
|
|
611
|
-
}
|
|
612
|
-
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
613
|
-
type AnyActorInstance = ActorInstance<any, any, any, any, any, any>;
|
|
614
|
-
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
573
|
+
declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
615
574
|
#private;
|
|
616
|
-
|
|
617
|
-
get isStopping(): boolean;
|
|
618
|
-
get id(): string;
|
|
619
|
-
get inlineClient(): Client<Registry<any>>;
|
|
620
|
-
get inspector(): ActorInspector;
|
|
575
|
+
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
621
576
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* Constructed in {@link ActorInstance.start}.
|
|
625
|
-
*
|
|
626
|
-
* @private
|
|
577
|
+
* Get the actor state
|
|
627
578
|
*/
|
|
628
|
-
|
|
629
|
-
start(connectionDrivers: ConnectionDriversMap, actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
630
|
-
_onAlarm(): Promise<void>;
|
|
631
|
-
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
632
|
-
get stateEnabled(): boolean;
|
|
633
|
-
__getConnForId(id: string): Conn<S, CP, CS, V, I, DB> | undefined;
|
|
579
|
+
get state(): TState;
|
|
634
580
|
/**
|
|
635
|
-
*
|
|
581
|
+
* Get the actor variables
|
|
636
582
|
*/
|
|
637
|
-
|
|
638
|
-
prepareConn(params: any, request?: Request): Promise<CS>;
|
|
639
|
-
__getConnDriver(driverId: ConnectionDriver): ConnDriver;
|
|
583
|
+
get vars(): TVars;
|
|
640
584
|
/**
|
|
641
|
-
*
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
processMessage(message: ToServer, conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
645
|
-
/**
|
|
646
|
-
* Check if the actor is ready to handle requests.
|
|
647
|
-
*/
|
|
648
|
-
isReady(): boolean;
|
|
649
|
-
/**
|
|
650
|
-
* Returns a list of action methods available on this actor.
|
|
651
|
-
*/
|
|
652
|
-
get actions(): string[];
|
|
653
|
-
/**
|
|
654
|
-
* Handles raw HTTP requests to the actor.
|
|
655
|
-
*/
|
|
656
|
-
handleFetch(request: Request, opts: {}): Promise<Response>;
|
|
657
|
-
/**
|
|
658
|
-
* Handles raw WebSocket connections to the actor.
|
|
659
|
-
*/
|
|
660
|
-
handleWebSocket(websocket: UniversalWebSocket, opts: {
|
|
661
|
-
request: Request;
|
|
662
|
-
}): Promise<void>;
|
|
663
|
-
get log(): Logger;
|
|
664
|
-
get rLog(): Logger;
|
|
665
|
-
/**
|
|
666
|
-
* Gets the name.
|
|
667
|
-
*/
|
|
668
|
-
get name(): string;
|
|
669
|
-
/**
|
|
670
|
-
* Gets the key.
|
|
671
|
-
*/
|
|
672
|
-
get key(): ActorKey;
|
|
673
|
-
/**
|
|
674
|
-
* Gets the region.
|
|
675
|
-
*/
|
|
676
|
-
get region(): string;
|
|
677
|
-
/**
|
|
678
|
-
* Gets the scheduler.
|
|
679
|
-
*/
|
|
680
|
-
get schedule(): Schedule;
|
|
681
|
-
/**
|
|
682
|
-
* Gets the map of connections.
|
|
683
|
-
*/
|
|
684
|
-
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
685
|
-
/**
|
|
686
|
-
* Gets the current state.
|
|
687
|
-
*
|
|
688
|
-
* Changing properties of this value will automatically be persisted.
|
|
689
|
-
*/
|
|
690
|
-
get state(): S;
|
|
691
|
-
/**
|
|
692
|
-
* Gets the database.
|
|
693
|
-
* @experimental
|
|
694
|
-
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
695
|
-
*/
|
|
696
|
-
get db(): InferDatabaseClient<DB>;
|
|
697
|
-
/**
|
|
698
|
-
* Sets the current state.
|
|
699
|
-
*
|
|
700
|
-
* This property will automatically be persisted.
|
|
701
|
-
*/
|
|
702
|
-
set state(value: S);
|
|
703
|
-
get vars(): V;
|
|
704
|
-
/**
|
|
705
|
-
* Broadcasts an event to all connected clients.
|
|
706
|
-
* @param name - The name of the event.
|
|
707
|
-
* @param args - The arguments to send with the event.
|
|
708
|
-
*/
|
|
709
|
-
_broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
710
|
-
/**
|
|
711
|
-
* Prevents the actor from sleeping until promise is complete.
|
|
712
|
-
*
|
|
713
|
-
* This allows the actor runtime to ensure that a promise completes while
|
|
714
|
-
* returning from an action request early.
|
|
715
|
-
*
|
|
716
|
-
* @param promise - The promise to run in the background.
|
|
717
|
-
*/
|
|
718
|
-
_waitUntil(promise: Promise<void>): void;
|
|
719
|
-
/**
|
|
720
|
-
* Forces the state to get saved.
|
|
721
|
-
*
|
|
722
|
-
* This is helpful if running a long task that may fail later or when
|
|
723
|
-
* running a background job that updates the state.
|
|
724
|
-
*
|
|
725
|
-
* @param opts - Options for saving the state.
|
|
726
|
-
*/
|
|
727
|
-
saveState(opts: SaveStateOptions): Promise<void>;
|
|
728
|
-
/** 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). */
|
|
729
|
-
_sleep(): Promise<void>;
|
|
730
|
-
_stop(): Promise<void>;
|
|
731
|
-
/** Abort signal that fires when the actor is stopping. */
|
|
732
|
-
get abortSignal(): AbortSignal;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* ActorContext class that provides access to actor methods and state
|
|
737
|
-
*/
|
|
738
|
-
declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
739
|
-
#private;
|
|
740
|
-
constructor(actor: ActorInstance<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
741
|
-
/**
|
|
742
|
-
* Get the actor state
|
|
743
|
-
*/
|
|
744
|
-
get state(): TState;
|
|
745
|
-
/**
|
|
746
|
-
* Get the actor variables
|
|
747
|
-
*/
|
|
748
|
-
get vars(): TVars;
|
|
749
|
-
/**
|
|
750
|
-
* Broadcasts an event to all connected clients.
|
|
751
|
-
* @param name - The name of the event.
|
|
752
|
-
* @param args - The arguments to send with the event.
|
|
585
|
+
* Broadcasts an event to all connected clients.
|
|
586
|
+
* @param name - The name of the event.
|
|
587
|
+
* @param args - The arguments to send with the event.
|
|
753
588
|
*/
|
|
754
589
|
broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
755
590
|
/**
|
|
@@ -814,624 +649,603 @@ declare class ActorContext<TState, TConnParams, TConnState, TVars, TInput, TData
|
|
|
814
649
|
sleep(): void;
|
|
815
650
|
}
|
|
816
651
|
|
|
817
|
-
type
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
652
|
+
type AnyActorDefinition = ActorDefinition<any, any, any, any, any, any, any>;
|
|
653
|
+
/**
|
|
654
|
+
* Extracts the context type from an ActorDefinition
|
|
655
|
+
*/
|
|
656
|
+
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;
|
|
657
|
+
/**
|
|
658
|
+
* Extracts the context type from an ActorDefinition
|
|
659
|
+
*/
|
|
660
|
+
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;
|
|
661
|
+
declare class ActorDefinition<S, CP, CS, V, I, DB extends AnyDatabaseProvider, R extends Actions<S, CP, CS, V, I, DB>> {
|
|
662
|
+
#private;
|
|
663
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB>);
|
|
664
|
+
get config(): ActorConfig<S, CP, CS, V, I, DB>;
|
|
665
|
+
instantiate(): ActorInstance<S, CP, CS, V, I, DB>;
|
|
825
666
|
}
|
|
826
|
-
declare
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
667
|
+
declare function lookupInRegistry(registryConfig: RegistryConfig, name: string): AnyActorDefinition;
|
|
668
|
+
|
|
669
|
+
type MigrationFn<TFrom, TTo> = (data: TFrom) => TTo;
|
|
670
|
+
interface VersionedDataConfig<T> {
|
|
671
|
+
currentVersion: number;
|
|
672
|
+
migrations: Map<number, MigrationFn<any, any>>;
|
|
673
|
+
serializeVersion: (data: T) => Uint8Array;
|
|
674
|
+
deserializeVersion: (bytes: Uint8Array) => T;
|
|
675
|
+
}
|
|
676
|
+
declare class VersionedDataHandler<T> {
|
|
677
|
+
private config;
|
|
678
|
+
constructor(config: VersionedDataConfig<T>);
|
|
679
|
+
serializeWithEmbeddedVersion(data: T): Uint8Array;
|
|
680
|
+
deserializeWithEmbeddedVersion(bytes: Uint8Array): T;
|
|
681
|
+
serialize(data: T, version: number): Uint8Array;
|
|
682
|
+
deserialize(bytes: Uint8Array, version: number): T;
|
|
683
|
+
private embedVersion;
|
|
684
|
+
private extractVersion;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** Data that's been serialized. */
|
|
688
|
+
type OutputData = string | Uint8Array;
|
|
689
|
+
declare const EncodingSchema: z.ZodEnum<["json", "cbor", "bare"]>;
|
|
690
|
+
/**
|
|
691
|
+
* Encoding used to communicate between the client & actor.
|
|
692
|
+
*/
|
|
693
|
+
type Encoding = z.infer<typeof EncodingSchema>;
|
|
694
|
+
/**
|
|
695
|
+
* Helper class that helps serialize data without re-serializing for the same encoding.
|
|
696
|
+
*/
|
|
697
|
+
declare class CachedSerializer<T> {
|
|
698
|
+
#private;
|
|
699
|
+
constructor(data: T, versionedDataHandler: VersionedDataHandler<T>);
|
|
700
|
+
get rawData(): T;
|
|
701
|
+
serialize(encoding: Encoding): OutputData;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
declare const TransportSchema: z.ZodEnum<["websocket", "sse"]>;
|
|
705
|
+
/**
|
|
706
|
+
* Transport mechanism used to communicate between client & actor.
|
|
707
|
+
*/
|
|
708
|
+
type Transport = z.infer<typeof TransportSchema>;
|
|
709
|
+
|
|
710
|
+
declare const ActorKeySchema: z.ZodArray<z.ZodString, "many">;
|
|
711
|
+
type ActorKey = z.infer<typeof ActorKeySchema>;
|
|
712
|
+
declare const CreateRequestSchema: z.ZodObject<{
|
|
713
|
+
name: z.ZodString;
|
|
714
|
+
key: z.ZodArray<z.ZodString, "many">;
|
|
715
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
716
|
+
region: z.ZodOptional<z.ZodString>;
|
|
717
|
+
}, "strip", z.ZodTypeAny, {
|
|
718
|
+
key: string[];
|
|
719
|
+
name: string;
|
|
720
|
+
input?: unknown;
|
|
721
|
+
region?: string | undefined;
|
|
722
|
+
}, {
|
|
723
|
+
key: string[];
|
|
724
|
+
name: string;
|
|
725
|
+
input?: unknown;
|
|
726
|
+
region?: string | undefined;
|
|
727
|
+
}>;
|
|
728
|
+
declare const ActorQuerySchema: z.ZodUnion<[z.ZodObject<{
|
|
729
|
+
getForId: z.ZodObject<{
|
|
730
|
+
name: z.ZodString;
|
|
731
|
+
actorId: z.ZodString;
|
|
732
|
+
}, "strip", z.ZodTypeAny, {
|
|
733
|
+
name: string;
|
|
734
|
+
actorId: string;
|
|
869
735
|
}, {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
connectionLivenessTimeout?: number | undefined;
|
|
878
|
-
connectionLivenessInterval?: number | undefined;
|
|
879
|
-
noSleep?: boolean | undefined;
|
|
880
|
-
sleepTimeout?: number | undefined;
|
|
881
|
-
}>>;
|
|
882
|
-
}, "strict", z.ZodTypeAny, {
|
|
883
|
-
options: {
|
|
884
|
-
createVarsTimeout: number;
|
|
885
|
-
createConnStateTimeout: number;
|
|
886
|
-
onConnectTimeout: number;
|
|
887
|
-
onStopTimeout: number;
|
|
888
|
-
stateSaveInterval: number;
|
|
889
|
-
actionTimeout: number;
|
|
890
|
-
waitUntilTimeout: number;
|
|
891
|
-
connectionLivenessTimeout: number;
|
|
892
|
-
connectionLivenessInterval: number;
|
|
893
|
-
noSleep: boolean;
|
|
894
|
-
sleepTimeout: number;
|
|
736
|
+
name: string;
|
|
737
|
+
actorId: string;
|
|
738
|
+
}>;
|
|
739
|
+
}, "strip", z.ZodTypeAny, {
|
|
740
|
+
getForId: {
|
|
741
|
+
name: string;
|
|
742
|
+
actorId: string;
|
|
895
743
|
};
|
|
896
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
897
|
-
state?: any;
|
|
898
|
-
db?: any;
|
|
899
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
900
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
901
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
902
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
903
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
904
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
905
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
906
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
907
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
908
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
909
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
910
|
-
connState?: any;
|
|
911
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
912
|
-
vars?: any;
|
|
913
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
914
744
|
}, {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
935
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
936
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
937
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
938
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
939
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
940
|
-
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
941
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
942
|
-
connState?: any;
|
|
943
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
944
|
-
vars?: any;
|
|
945
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
946
|
-
}>, {
|
|
947
|
-
options: {
|
|
948
|
-
createVarsTimeout: number;
|
|
949
|
-
createConnStateTimeout: number;
|
|
950
|
-
onConnectTimeout: number;
|
|
951
|
-
onStopTimeout: number;
|
|
952
|
-
stateSaveInterval: number;
|
|
953
|
-
actionTimeout: number;
|
|
954
|
-
waitUntilTimeout: number;
|
|
955
|
-
connectionLivenessTimeout: number;
|
|
956
|
-
connectionLivenessInterval: number;
|
|
957
|
-
noSleep: boolean;
|
|
958
|
-
sleepTimeout: number;
|
|
745
|
+
getForId: {
|
|
746
|
+
name: string;
|
|
747
|
+
actorId: string;
|
|
748
|
+
};
|
|
749
|
+
}>, z.ZodObject<{
|
|
750
|
+
getForKey: z.ZodObject<{
|
|
751
|
+
name: z.ZodString;
|
|
752
|
+
key: z.ZodArray<z.ZodString, "many">;
|
|
753
|
+
}, "strip", z.ZodTypeAny, {
|
|
754
|
+
key: string[];
|
|
755
|
+
name: string;
|
|
756
|
+
}, {
|
|
757
|
+
key: string[];
|
|
758
|
+
name: string;
|
|
759
|
+
}>;
|
|
760
|
+
}, "strip", z.ZodTypeAny, {
|
|
761
|
+
getForKey: {
|
|
762
|
+
key: string[];
|
|
763
|
+
name: string;
|
|
959
764
|
};
|
|
960
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
961
|
-
state?: any;
|
|
962
|
-
db?: any;
|
|
963
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
964
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
965
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
966
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
967
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
968
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
969
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
970
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
971
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
972
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
973
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
974
|
-
connState?: any;
|
|
975
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
976
|
-
vars?: any;
|
|
977
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
978
765
|
}, {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
connState?: any;
|
|
1007
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1008
|
-
vars?: any;
|
|
1009
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1010
|
-
}>, {
|
|
1011
|
-
options: {
|
|
1012
|
-
createVarsTimeout: number;
|
|
1013
|
-
createConnStateTimeout: number;
|
|
1014
|
-
onConnectTimeout: number;
|
|
1015
|
-
onStopTimeout: number;
|
|
1016
|
-
stateSaveInterval: number;
|
|
1017
|
-
actionTimeout: number;
|
|
1018
|
-
waitUntilTimeout: number;
|
|
1019
|
-
connectionLivenessTimeout: number;
|
|
1020
|
-
connectionLivenessInterval: number;
|
|
1021
|
-
noSleep: boolean;
|
|
1022
|
-
sleepTimeout: number;
|
|
766
|
+
getForKey: {
|
|
767
|
+
key: string[];
|
|
768
|
+
name: string;
|
|
769
|
+
};
|
|
770
|
+
}>, z.ZodObject<{
|
|
771
|
+
getOrCreateForKey: z.ZodObject<{
|
|
772
|
+
name: z.ZodString;
|
|
773
|
+
key: z.ZodArray<z.ZodString, "many">;
|
|
774
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
775
|
+
region: z.ZodOptional<z.ZodString>;
|
|
776
|
+
}, "strip", z.ZodTypeAny, {
|
|
777
|
+
key: string[];
|
|
778
|
+
name: string;
|
|
779
|
+
input?: unknown;
|
|
780
|
+
region?: string | undefined;
|
|
781
|
+
}, {
|
|
782
|
+
key: string[];
|
|
783
|
+
name: string;
|
|
784
|
+
input?: unknown;
|
|
785
|
+
region?: string | undefined;
|
|
786
|
+
}>;
|
|
787
|
+
}, "strip", z.ZodTypeAny, {
|
|
788
|
+
getOrCreateForKey: {
|
|
789
|
+
key: string[];
|
|
790
|
+
name: string;
|
|
791
|
+
input?: unknown;
|
|
792
|
+
region?: string | undefined;
|
|
1023
793
|
};
|
|
1024
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1025
|
-
state?: any;
|
|
1026
|
-
db?: any;
|
|
1027
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1028
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1029
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1030
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1031
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1032
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1033
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1034
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1035
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1036
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1037
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1038
|
-
connState?: any;
|
|
1039
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1040
|
-
vars?: any;
|
|
1041
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1042
794
|
}, {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
vars?: any;
|
|
1073
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1074
|
-
}>, {
|
|
1075
|
-
options: {
|
|
1076
|
-
createVarsTimeout: number;
|
|
1077
|
-
createConnStateTimeout: number;
|
|
1078
|
-
onConnectTimeout: number;
|
|
1079
|
-
onStopTimeout: number;
|
|
1080
|
-
stateSaveInterval: number;
|
|
1081
|
-
actionTimeout: number;
|
|
1082
|
-
waitUntilTimeout: number;
|
|
1083
|
-
connectionLivenessTimeout: number;
|
|
1084
|
-
connectionLivenessInterval: number;
|
|
1085
|
-
noSleep: boolean;
|
|
1086
|
-
sleepTimeout: number;
|
|
795
|
+
getOrCreateForKey: {
|
|
796
|
+
key: string[];
|
|
797
|
+
name: string;
|
|
798
|
+
input?: unknown;
|
|
799
|
+
region?: string | undefined;
|
|
800
|
+
};
|
|
801
|
+
}>, z.ZodObject<{
|
|
802
|
+
create: z.ZodObject<{
|
|
803
|
+
name: z.ZodString;
|
|
804
|
+
key: z.ZodArray<z.ZodString, "many">;
|
|
805
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
806
|
+
region: z.ZodOptional<z.ZodString>;
|
|
807
|
+
}, "strip", z.ZodTypeAny, {
|
|
808
|
+
key: string[];
|
|
809
|
+
name: string;
|
|
810
|
+
input?: unknown;
|
|
811
|
+
region?: string | undefined;
|
|
812
|
+
}, {
|
|
813
|
+
key: string[];
|
|
814
|
+
name: string;
|
|
815
|
+
input?: unknown;
|
|
816
|
+
region?: string | undefined;
|
|
817
|
+
}>;
|
|
818
|
+
}, "strip", z.ZodTypeAny, {
|
|
819
|
+
create: {
|
|
820
|
+
key: string[];
|
|
821
|
+
name: string;
|
|
822
|
+
input?: unknown;
|
|
823
|
+
region?: string | undefined;
|
|
1087
824
|
};
|
|
1088
|
-
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1089
|
-
state?: any;
|
|
1090
|
-
db?: any;
|
|
1091
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1092
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1093
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1094
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1095
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1096
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1097
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1098
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1099
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1100
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1101
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1102
|
-
connState?: any;
|
|
1103
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1104
|
-
vars?: any;
|
|
1105
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1106
825
|
}, {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
waitUntilTimeout?: number | undefined;
|
|
1116
|
-
connectionLivenessTimeout?: number | undefined;
|
|
1117
|
-
connectionLivenessInterval?: number | undefined;
|
|
1118
|
-
noSleep?: boolean | undefined;
|
|
1119
|
-
sleepTimeout?: number | undefined;
|
|
1120
|
-
} | undefined;
|
|
1121
|
-
db?: any;
|
|
1122
|
-
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1123
|
-
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1124
|
-
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1125
|
-
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1126
|
-
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1127
|
-
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1128
|
-
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1129
|
-
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1130
|
-
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1131
|
-
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1132
|
-
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1133
|
-
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1134
|
-
connState?: any;
|
|
1135
|
-
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1136
|
-
vars?: any;
|
|
1137
|
-
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1138
|
-
}>;
|
|
1139
|
-
interface OnConnectOptions {
|
|
1140
|
-
/**
|
|
1141
|
-
* The request object associated with the connection.
|
|
1142
|
-
*
|
|
1143
|
-
* @experimental
|
|
1144
|
-
*/
|
|
1145
|
-
request?: Request;
|
|
1146
|
-
}
|
|
1147
|
-
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1148
|
-
state: TState;
|
|
1149
|
-
} | {
|
|
1150
|
-
createState: (c: InitContext, input: TInput) => TState | Promise<TState>;
|
|
1151
|
-
} | Record<never, never>;
|
|
1152
|
-
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1153
|
-
connState: TConnState;
|
|
1154
|
-
} | {
|
|
1155
|
-
createConnState: (c: InitContext, opts: OnConnectOptions, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
1156
|
-
} | Record<never, never>;
|
|
826
|
+
create: {
|
|
827
|
+
key: string[];
|
|
828
|
+
name: string;
|
|
829
|
+
input?: unknown;
|
|
830
|
+
region?: string | undefined;
|
|
831
|
+
};
|
|
832
|
+
}>]>;
|
|
833
|
+
type ActorQuery = z.infer<typeof ActorQuerySchema>;
|
|
1157
834
|
/**
|
|
1158
|
-
*
|
|
835
|
+
* Interface representing a request to create a actor.
|
|
1159
836
|
*/
|
|
1160
|
-
type
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
837
|
+
type CreateRequest = z.infer<typeof CreateRequestSchema>;
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Action function returned by Actor connections and handles.
|
|
841
|
+
*
|
|
842
|
+
* @typedef {Function} ActorActionFunction
|
|
843
|
+
* @template Args
|
|
844
|
+
* @template Response
|
|
845
|
+
* @param {...Args} args - Arguments for the action function.
|
|
846
|
+
* @returns {Promise<Response>}
|
|
847
|
+
*/
|
|
848
|
+
type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
|
|
849
|
+
/**
|
|
850
|
+
* Maps action methods from actor definition to typed function signatures.
|
|
851
|
+
*/
|
|
852
|
+
type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends ActorDefinition<any, any, any, any, any, any, infer R> ? {
|
|
853
|
+
[K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
|
|
854
|
+
} : never;
|
|
855
|
+
|
|
856
|
+
declare class ActorClientError extends Error {
|
|
857
|
+
}
|
|
858
|
+
declare class InternalError extends ActorClientError {
|
|
859
|
+
}
|
|
860
|
+
declare class ManagerError extends ActorClientError {
|
|
861
|
+
constructor(error: string, opts?: ErrorOptions);
|
|
862
|
+
}
|
|
863
|
+
declare class MalformedResponseMessage extends ActorClientError {
|
|
864
|
+
constructor(cause?: unknown);
|
|
865
|
+
}
|
|
866
|
+
declare class ActorError extends ActorClientError {
|
|
867
|
+
readonly group: string;
|
|
868
|
+
readonly code: string;
|
|
869
|
+
readonly metadata?: unknown | undefined;
|
|
870
|
+
__type: string;
|
|
871
|
+
constructor(group: string, code: string, message: string, metadata?: unknown | undefined);
|
|
1173
872
|
}
|
|
873
|
+
|
|
1174
874
|
/**
|
|
1175
|
-
*
|
|
875
|
+
* A function that unsubscribes from an event.
|
|
876
|
+
*
|
|
877
|
+
* @typedef {Function} EventUnsubscribe
|
|
1176
878
|
*/
|
|
1177
|
-
type
|
|
1178
|
-
|
|
879
|
+
type EventUnsubscribe = () => void;
|
|
880
|
+
/**
|
|
881
|
+
* A function that handles connection errors.
|
|
882
|
+
*
|
|
883
|
+
* @typedef {Function} ActorErrorCallback
|
|
884
|
+
*/
|
|
885
|
+
type ActorErrorCallback = (error: ActorError) => void;
|
|
886
|
+
declare const CONNECT_SYMBOL: unique symbol;
|
|
887
|
+
/**
|
|
888
|
+
* Provides underlying functions for {@link ActorConn}. See {@link ActorConn} for using type-safe remote procedure calls.
|
|
889
|
+
*
|
|
890
|
+
* @see {@link ActorConn}
|
|
891
|
+
*/
|
|
892
|
+
declare class ActorConnRaw {
|
|
893
|
+
#private;
|
|
1179
894
|
/**
|
|
1180
|
-
*
|
|
895
|
+
* Do not call this directly.
|
|
1181
896
|
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
897
|
+
* Creates an instance of ActorConnRaw.
|
|
898
|
+
*
|
|
899
|
+
* @protected
|
|
1184
900
|
*/
|
|
1185
|
-
|
|
901
|
+
constructor(client: ClientRaw, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1186
902
|
/**
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
* Use this hook to initialize resources needed for the actor's operation
|
|
1190
|
-
* (timers, external connections, etc.)
|
|
903
|
+
* Call a raw action connection. See {@link ActorConn} for type-safe action calls.
|
|
1191
904
|
*
|
|
1192
|
-
* @
|
|
905
|
+
* @see {@link ActorConn}
|
|
906
|
+
* @template Args - The type of arguments to pass to the action function.
|
|
907
|
+
* @template Response - The type of the response returned by the action function.
|
|
908
|
+
* @param {string} name - The name of the action function to call.
|
|
909
|
+
* @param {...Args} args - The arguments to pass to the action function.
|
|
910
|
+
* @returns {Promise<Response>} - A promise that resolves to the response of the action function.
|
|
1193
911
|
*/
|
|
1194
|
-
|
|
912
|
+
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
913
|
+
name: string;
|
|
914
|
+
args: Args;
|
|
915
|
+
signal?: AbortSignal;
|
|
916
|
+
}): Promise<Response>;
|
|
1195
917
|
/**
|
|
1196
|
-
*
|
|
1197
|
-
|
|
1198
|
-
*
|
|
1199
|
-
* any shutdown operations before the actor sleeps or stops.
|
|
1200
|
-
*
|
|
1201
|
-
* Not supported on all platforms.
|
|
918
|
+
* Do not call this directly.
|
|
919
|
+
enc
|
|
920
|
+
* Establishes a connection to the server using the specified endpoint & encoding & driver.
|
|
1202
921
|
*
|
|
1203
|
-
* @
|
|
922
|
+
* @protected
|
|
1204
923
|
*/
|
|
1205
|
-
|
|
924
|
+
[CONNECT_SYMBOL](): void;
|
|
1206
925
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
* Use this hook to react to state changes, such as updating
|
|
1210
|
-
* external systems or triggering events.
|
|
1211
|
-
*
|
|
1212
|
-
* State changes made within this hook will NOT trigger
|
|
1213
|
-
* another onStateChange call, preventing infinite recursion.
|
|
926
|
+
* Subscribes to an event that will happen repeatedly.
|
|
1214
927
|
*
|
|
1215
|
-
* @
|
|
928
|
+
* @template Args - The type of arguments the event callback will receive.
|
|
929
|
+
* @param {string} eventName - The name of the event to subscribe to.
|
|
930
|
+
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
931
|
+
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
932
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1216
933
|
*/
|
|
1217
|
-
|
|
934
|
+
on<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1218
935
|
/**
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
1221
|
-
* Use this hook to determine if a connection should be accepted
|
|
1222
|
-
* and to initialize connection-specific state.
|
|
936
|
+
* Subscribes to an event that will be triggered only once.
|
|
1223
937
|
*
|
|
1224
|
-
* @
|
|
1225
|
-
* @
|
|
1226
|
-
* @
|
|
938
|
+
* @template Args - The type of arguments the event callback will receive.
|
|
939
|
+
* @param {string} eventName - The name of the event to subscribe to.
|
|
940
|
+
* @param {(...args: Args) => void} callback - The callback function to execute when the event is triggered.
|
|
941
|
+
* @returns {EventUnsubscribe} - A function to unsubscribe from the event.
|
|
942
|
+
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1227
943
|
*/
|
|
1228
|
-
|
|
944
|
+
once<Args extends Array<unknown> = unknown[]>(eventName: string, callback: (...args: Args) => void): EventUnsubscribe;
|
|
1229
945
|
/**
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
* Use this hook to perform actions when a connection is established,
|
|
1233
|
-
* such as sending initial data or updating the actor's state.
|
|
946
|
+
* Subscribes to connection errors.
|
|
1234
947
|
*
|
|
1235
|
-
* @param
|
|
1236
|
-
* @returns
|
|
948
|
+
* @param {ActorErrorCallback} callback - The callback function to execute when a connection error occurs.
|
|
949
|
+
* @returns {() => void} - A function to unsubscribe from the error handler.
|
|
1237
950
|
*/
|
|
1238
|
-
|
|
951
|
+
onError(callback: ActorErrorCallback): () => void;
|
|
1239
952
|
/**
|
|
1240
|
-
*
|
|
953
|
+
* Disconnects from the actor.
|
|
1241
954
|
*
|
|
1242
|
-
*
|
|
1243
|
-
* or update the actor's state.
|
|
1244
|
-
*
|
|
1245
|
-
* @param conn The connection that is being closed
|
|
1246
|
-
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
955
|
+
* @returns {Promise<void>} A promise that resolves when the socket is gracefully closed.
|
|
1247
956
|
*/
|
|
1248
|
-
|
|
957
|
+
dispose(): Promise<void>;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* ```
|
|
964
|
+
* const room = client.connect<ChatRoom>(...etc...);
|
|
965
|
+
* // This calls the action named `sendMessage` on the `ChatRoom` actor.
|
|
966
|
+
* await room.sendMessage('Hello, world!');
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
970
|
+
*
|
|
971
|
+
* @template AD The actor class that this connection is for.
|
|
972
|
+
* @see {@link ActorConnRaw}
|
|
973
|
+
*/
|
|
974
|
+
type ActorConn<AD extends AnyActorDefinition> = ActorConnRaw & ActorDefinitionActions<AD>;
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Provides underlying functions for stateless {@link ActorHandle} for action calls.
|
|
978
|
+
* Similar to ActorConnRaw but doesn't maintain a connection.
|
|
979
|
+
*
|
|
980
|
+
* @see {@link ActorHandle}
|
|
981
|
+
*/
|
|
982
|
+
declare class ActorHandleRaw {
|
|
983
|
+
#private;
|
|
1249
984
|
/**
|
|
1250
|
-
*
|
|
985
|
+
* Do not call this directly.
|
|
1251
986
|
*
|
|
1252
|
-
*
|
|
1253
|
-
* to the client. This is useful for formatting responses, adding metadata,
|
|
1254
|
-
* or applying transformations to the output.
|
|
987
|
+
* Creates an instance of ActorHandleRaw.
|
|
1255
988
|
*
|
|
1256
|
-
* @
|
|
1257
|
-
* @param args The arguments that were passed to the action
|
|
1258
|
-
* @param output The output that will be sent to the client
|
|
1259
|
-
* @returns The modified output to send to the client
|
|
989
|
+
* @protected
|
|
1260
990
|
*/
|
|
1261
|
-
|
|
991
|
+
constructor(client: any, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1262
992
|
/**
|
|
1263
|
-
*
|
|
993
|
+
* Call a raw action. This method sends an HTTP request to invoke the named action.
|
|
1264
994
|
*
|
|
1265
|
-
*
|
|
1266
|
-
*
|
|
995
|
+
* @see {@link ActorHandle}
|
|
996
|
+
* @template Args - The type of arguments to pass to the action function.
|
|
997
|
+
* @template Response - The type of the response returned by the action function.
|
|
998
|
+
*/
|
|
999
|
+
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
1000
|
+
name: string;
|
|
1001
|
+
args: Args;
|
|
1002
|
+
signal?: AbortSignal;
|
|
1003
|
+
}): Promise<Response>;
|
|
1004
|
+
/**
|
|
1005
|
+
* Establishes a persistent connection to the actor.
|
|
1267
1006
|
*
|
|
1268
|
-
* @
|
|
1269
|
-
* @returns A
|
|
1007
|
+
* @template AD The actor class that this connection is for.
|
|
1008
|
+
* @returns {ActorConn<AD>} A connection to the actor.
|
|
1270
1009
|
*/
|
|
1271
|
-
|
|
1010
|
+
connect(): ActorConn<AnyActorDefinition>;
|
|
1272
1011
|
/**
|
|
1273
|
-
*
|
|
1012
|
+
* Makes a raw HTTP request to the actor.
|
|
1274
1013
|
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1014
|
+
* @param input - The URL, path, or Request object
|
|
1015
|
+
* @param init - Standard fetch RequestInit options
|
|
1016
|
+
* @returns Promise<Response> - The raw HTTP response
|
|
1017
|
+
*/
|
|
1018
|
+
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
1019
|
+
/**
|
|
1020
|
+
* Creates a raw WebSocket connection to the actor.
|
|
1277
1021
|
*
|
|
1278
|
-
* @param
|
|
1279
|
-
* @param
|
|
1022
|
+
* @param path - The path for the WebSocket connection (e.g., "stream")
|
|
1023
|
+
* @param protocols - Optional WebSocket subprotocols
|
|
1024
|
+
* @returns WebSocket - A raw WebSocket connection
|
|
1280
1025
|
*/
|
|
1281
|
-
|
|
1282
|
-
request: Request;
|
|
1283
|
-
}) => void | Promise<void>;
|
|
1284
|
-
actions: TActions;
|
|
1285
|
-
}
|
|
1286
|
-
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
1026
|
+
websocket(path?: string, protocols?: string | string[]): Promise<WebSocket>;
|
|
1287
1027
|
/**
|
|
1288
|
-
*
|
|
1028
|
+
* Resolves the actor to get its unique actor ID
|
|
1029
|
+
*
|
|
1030
|
+
* @returns {Promise<string>} - A promise that resolves to the actor's ID
|
|
1289
1031
|
*/
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
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>;
|
|
1297
|
-
|
|
1298
|
-
declare const ActorKeySchema: z.ZodArray<z.ZodString, "many">;
|
|
1299
|
-
type ActorKey = z.infer<typeof ActorKeySchema>;
|
|
1300
|
-
declare const CreateRequestSchema: z.ZodObject<{
|
|
1301
|
-
name: z.ZodString;
|
|
1302
|
-
key: z.ZodArray<z.ZodString, "many">;
|
|
1303
|
-
input: z.ZodOptional<z.ZodUnknown>;
|
|
1304
|
-
region: z.ZodOptional<z.ZodString>;
|
|
1305
|
-
}, "strip", z.ZodTypeAny, {
|
|
1306
|
-
key: string[];
|
|
1307
|
-
name: string;
|
|
1308
|
-
input?: unknown;
|
|
1309
|
-
region?: string | undefined;
|
|
1310
|
-
}, {
|
|
1311
|
-
key: string[];
|
|
1312
|
-
name: string;
|
|
1313
|
-
input?: unknown;
|
|
1314
|
-
region?: string | undefined;
|
|
1315
|
-
}>;
|
|
1316
|
-
declare const ActorQuerySchema: z.ZodUnion<[z.ZodObject<{
|
|
1317
|
-
getForId: z.ZodObject<{
|
|
1318
|
-
name: z.ZodString;
|
|
1319
|
-
actorId: z.ZodString;
|
|
1320
|
-
}, "strip", z.ZodTypeAny, {
|
|
1321
|
-
name: string;
|
|
1322
|
-
actorId: string;
|
|
1323
|
-
}, {
|
|
1324
|
-
name: string;
|
|
1325
|
-
actorId: string;
|
|
1326
|
-
}>;
|
|
1327
|
-
}, "strip", z.ZodTypeAny, {
|
|
1328
|
-
getForId: {
|
|
1329
|
-
name: string;
|
|
1330
|
-
actorId: string;
|
|
1331
|
-
};
|
|
1332
|
-
}, {
|
|
1333
|
-
getForId: {
|
|
1334
|
-
name: string;
|
|
1335
|
-
actorId: string;
|
|
1336
|
-
};
|
|
1337
|
-
}>, z.ZodObject<{
|
|
1338
|
-
getForKey: z.ZodObject<{
|
|
1339
|
-
name: z.ZodString;
|
|
1340
|
-
key: z.ZodArray<z.ZodString, "many">;
|
|
1341
|
-
}, "strip", z.ZodTypeAny, {
|
|
1342
|
-
key: string[];
|
|
1343
|
-
name: string;
|
|
1344
|
-
}, {
|
|
1345
|
-
key: string[];
|
|
1346
|
-
name: string;
|
|
1347
|
-
}>;
|
|
1348
|
-
}, "strip", z.ZodTypeAny, {
|
|
1349
|
-
getForKey: {
|
|
1350
|
-
key: string[];
|
|
1351
|
-
name: string;
|
|
1352
|
-
};
|
|
1353
|
-
}, {
|
|
1354
|
-
getForKey: {
|
|
1355
|
-
key: string[];
|
|
1356
|
-
name: string;
|
|
1357
|
-
};
|
|
1358
|
-
}>, z.ZodObject<{
|
|
1359
|
-
getOrCreateForKey: z.ZodObject<{
|
|
1360
|
-
name: z.ZodString;
|
|
1361
|
-
key: z.ZodArray<z.ZodString, "many">;
|
|
1362
|
-
input: z.ZodOptional<z.ZodUnknown>;
|
|
1363
|
-
region: z.ZodOptional<z.ZodString>;
|
|
1364
|
-
}, "strip", z.ZodTypeAny, {
|
|
1365
|
-
key: string[];
|
|
1366
|
-
name: string;
|
|
1367
|
-
input?: unknown;
|
|
1368
|
-
region?: string | undefined;
|
|
1369
|
-
}, {
|
|
1370
|
-
key: string[];
|
|
1371
|
-
name: string;
|
|
1372
|
-
input?: unknown;
|
|
1373
|
-
region?: string | undefined;
|
|
1374
|
-
}>;
|
|
1375
|
-
}, "strip", z.ZodTypeAny, {
|
|
1376
|
-
getOrCreateForKey: {
|
|
1377
|
-
key: string[];
|
|
1378
|
-
name: string;
|
|
1379
|
-
input?: unknown;
|
|
1380
|
-
region?: string | undefined;
|
|
1381
|
-
};
|
|
1382
|
-
}, {
|
|
1383
|
-
getOrCreateForKey: {
|
|
1384
|
-
key: string[];
|
|
1385
|
-
name: string;
|
|
1386
|
-
input?: unknown;
|
|
1387
|
-
region?: string | undefined;
|
|
1388
|
-
};
|
|
1389
|
-
}>, z.ZodObject<{
|
|
1390
|
-
create: z.ZodObject<{
|
|
1391
|
-
name: z.ZodString;
|
|
1392
|
-
key: z.ZodArray<z.ZodString, "many">;
|
|
1393
|
-
input: z.ZodOptional<z.ZodUnknown>;
|
|
1394
|
-
region: z.ZodOptional<z.ZodString>;
|
|
1395
|
-
}, "strip", z.ZodTypeAny, {
|
|
1396
|
-
key: string[];
|
|
1397
|
-
name: string;
|
|
1398
|
-
input?: unknown;
|
|
1399
|
-
region?: string | undefined;
|
|
1400
|
-
}, {
|
|
1401
|
-
key: string[];
|
|
1402
|
-
name: string;
|
|
1403
|
-
input?: unknown;
|
|
1404
|
-
region?: string | undefined;
|
|
1405
|
-
}>;
|
|
1406
|
-
}, "strip", z.ZodTypeAny, {
|
|
1407
|
-
create: {
|
|
1408
|
-
key: string[];
|
|
1409
|
-
name: string;
|
|
1410
|
-
input?: unknown;
|
|
1411
|
-
region?: string | undefined;
|
|
1412
|
-
};
|
|
1413
|
-
}, {
|
|
1414
|
-
create: {
|
|
1415
|
-
key: string[];
|
|
1416
|
-
name: string;
|
|
1417
|
-
input?: unknown;
|
|
1418
|
-
region?: string | undefined;
|
|
1419
|
-
};
|
|
1420
|
-
}>]>;
|
|
1421
|
-
type ActorQuery = z.infer<typeof ActorQuerySchema>;
|
|
1422
|
-
/**
|
|
1423
|
-
* Interface representing a request to create a actor.
|
|
1424
|
-
*/
|
|
1425
|
-
type CreateRequest = z.infer<typeof CreateRequestSchema>;
|
|
1426
|
-
|
|
1427
|
-
declare class GenericConnGlobalState {
|
|
1428
|
-
websockets: Map<string, WSContext<unknown>>;
|
|
1429
|
-
sseStreams: Map<string, SSEStreamingApi>;
|
|
1032
|
+
resolve({ signal }?: {
|
|
1033
|
+
signal?: AbortSignal;
|
|
1034
|
+
}): Promise<string>;
|
|
1430
1035
|
}
|
|
1431
1036
|
/**
|
|
1432
|
-
*
|
|
1037
|
+
* Stateless handle to a actor. Allows calling actor's remote procedure calls with inferred types
|
|
1038
|
+
* without establishing a persistent connection.
|
|
1039
|
+
*
|
|
1040
|
+
* @example
|
|
1041
|
+
* ```
|
|
1042
|
+
* const room = client.get<ChatRoom>(...etc...);
|
|
1043
|
+
* // This calls the action named `sendMessage` on the `ChatRoom` actor without a connection.
|
|
1044
|
+
* await room.sendMessage('Hello, world!');
|
|
1045
|
+
* ```
|
|
1046
|
+
*
|
|
1047
|
+
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
1048
|
+
*
|
|
1049
|
+
* @template AD The actor class that this handle is for.
|
|
1050
|
+
* @see {@link ActorHandleRaw}
|
|
1433
1051
|
*/
|
|
1434
|
-
|
|
1052
|
+
type ActorHandle<AD extends AnyActorDefinition> = Omit<ActorHandleRaw, "connect"> & {
|
|
1053
|
+
connect(): ActorConn<AD>;
|
|
1054
|
+
resolve(): Promise<string>;
|
|
1055
|
+
} & ActorDefinitionActions<AD>;
|
|
1056
|
+
|
|
1057
|
+
/** Extract the actor registry from the registry definition. */
|
|
1058
|
+
type ExtractActorsFromRegistry<A extends Registry<any>> = A extends Registry<infer Actors> ? Actors : never;
|
|
1059
|
+
/** Extract the registry definition from the client. */
|
|
1060
|
+
type ExtractRegistryFromClient<C extends Client<Registry<{}>>> = C extends Client<infer A> ? A : never;
|
|
1061
|
+
/**
|
|
1062
|
+
* Represents a actor accessor that provides methods to interact with a specific actor.
|
|
1063
|
+
*/
|
|
1064
|
+
interface ActorAccessor<AD extends AnyActorDefinition> {
|
|
1065
|
+
/**
|
|
1066
|
+
* Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
|
|
1067
|
+
* The actor name is automatically injected from the property accessor.
|
|
1068
|
+
*
|
|
1069
|
+
* @template AD The actor class that this handle is for.
|
|
1070
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
1071
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1072
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1073
|
+
*/
|
|
1074
|
+
get(key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Gets a stateless handle to a actor by its key, creating it if necessary.
|
|
1077
|
+
* The actor name is automatically injected from the property accessor.
|
|
1078
|
+
*
|
|
1079
|
+
* @template AD The actor class that this handle is for.
|
|
1080
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
1081
|
+
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
1082
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1083
|
+
*/
|
|
1084
|
+
getOrCreate(key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Gets a stateless handle to a actor by its ID.
|
|
1087
|
+
*
|
|
1088
|
+
* @template AD The actor class that this handle is for.
|
|
1089
|
+
* @param {string} actorId - The ID of the actor.
|
|
1090
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1091
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1092
|
+
*/
|
|
1093
|
+
getForId(actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
1094
|
+
/**
|
|
1095
|
+
* Creates a new actor with the name automatically injected from the property accessor,
|
|
1096
|
+
* and returns a stateless handle to it with the actor ID resolved.
|
|
1097
|
+
*
|
|
1098
|
+
* @template AD The actor class that this handle is for.
|
|
1099
|
+
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
1100
|
+
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
1101
|
+
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
1102
|
+
*/
|
|
1103
|
+
create(key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Options for querying actors.
|
|
1107
|
+
* @typedef {Object} QueryOptions
|
|
1108
|
+
* @property {unknown} [parameters] - Parameters to pass to the connection.
|
|
1109
|
+
*/
|
|
1110
|
+
interface QueryOptions {
|
|
1111
|
+
/** Parameters to pass to the connection. */
|
|
1112
|
+
params?: unknown;
|
|
1113
|
+
/** Signal to abort the request. */
|
|
1114
|
+
signal?: AbortSignal;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Options for getting a actor by ID.
|
|
1118
|
+
* @typedef {QueryOptions} GetWithIdOptions
|
|
1119
|
+
*/
|
|
1120
|
+
interface GetWithIdOptions extends QueryOptions {
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Options for getting a actor.
|
|
1124
|
+
* @typedef {QueryOptions} GetOptions
|
|
1125
|
+
*/
|
|
1126
|
+
interface GetOptions extends QueryOptions {
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Options for getting or creating a actor.
|
|
1130
|
+
* @typedef {QueryOptions} GetOrCreateOptions
|
|
1131
|
+
* @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
|
|
1132
|
+
*/
|
|
1133
|
+
interface GetOrCreateOptions extends QueryOptions {
|
|
1134
|
+
/** Region to create the actor in if it doesn't exist. */
|
|
1135
|
+
createInRegion?: string;
|
|
1136
|
+
/** Input data to pass to the actor. */
|
|
1137
|
+
createWithInput?: unknown;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Options for creating a actor.
|
|
1141
|
+
* @typedef {QueryOptions} CreateOptions
|
|
1142
|
+
* @property {string} [region] - The region to create the actor in.
|
|
1143
|
+
*/
|
|
1144
|
+
interface CreateOptions extends QueryOptions {
|
|
1145
|
+
/** The region to create the actor in. */
|
|
1146
|
+
region?: string;
|
|
1147
|
+
/** Input data to pass to the actor. */
|
|
1148
|
+
input?: unknown;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Represents a region to connect to.
|
|
1152
|
+
* @typedef {Object} Region
|
|
1153
|
+
* @property {string} id - The region ID.
|
|
1154
|
+
* @property {string} name - The region name.
|
|
1155
|
+
* @see {@link https://rivet.dev/docs/edge|Edge Networking}
|
|
1156
|
+
* @see {@link https://rivet.dev/docs/regions|Available Regions}
|
|
1157
|
+
*/
|
|
1158
|
+
interface Region {
|
|
1159
|
+
/**
|
|
1160
|
+
* The region slug.
|
|
1161
|
+
*/
|
|
1162
|
+
id: string;
|
|
1163
|
+
/**
|
|
1164
|
+
* The human-friendly region name.
|
|
1165
|
+
*/
|
|
1166
|
+
name: string;
|
|
1167
|
+
}
|
|
1168
|
+
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
1169
|
+
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
1170
|
+
declare const TRANSPORT_SYMBOL: unique symbol;
|
|
1171
|
+
/**
|
|
1172
|
+
* Client for managing & connecting to actors.
|
|
1173
|
+
*
|
|
1174
|
+
* @template A The actors map type that defines the available actors.
|
|
1175
|
+
* @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
|
|
1176
|
+
*/
|
|
1177
|
+
declare class ClientRaw {
|
|
1178
|
+
#private;
|
|
1179
|
+
[ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
|
|
1180
|
+
[TRANSPORT_SYMBOL]: Transport;
|
|
1181
|
+
/**
|
|
1182
|
+
* Creates an instance of Client.
|
|
1183
|
+
*
|
|
1184
|
+
* @param {string} managerEndpoint - The manager endpoint. See {@link https://rivet.dev/docs/setup|Initial Setup} for instructions on getting the manager endpoint.
|
|
1185
|
+
* @param {ClientConfig} [opts] - Options for configuring the client.
|
|
1186
|
+
* @see {@link https://rivet.dev/docs/setup|Initial Setup}
|
|
1187
|
+
*/
|
|
1188
|
+
constructor(driver: ManagerDriver, opts?: ClientConfig);
|
|
1189
|
+
/**
|
|
1190
|
+
* Gets a stateless handle to a actor by its ID.
|
|
1191
|
+
*
|
|
1192
|
+
* @template AD The actor class that this handle is for.
|
|
1193
|
+
* @param {string} name - The name of the actor.
|
|
1194
|
+
* @param {string} actorId - The ID of the actor.
|
|
1195
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1196
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1197
|
+
*/
|
|
1198
|
+
getForId<AD extends AnyActorDefinition>(name: string, actorId: string, opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
1199
|
+
/**
|
|
1200
|
+
* Gets a stateless handle to a actor by its key, but does not create the actor if it doesn't exist.
|
|
1201
|
+
*
|
|
1202
|
+
* @template AD The actor class that this handle is for.
|
|
1203
|
+
* @param {string} name - The name of the actor.
|
|
1204
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
1205
|
+
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1206
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1207
|
+
*/
|
|
1208
|
+
get<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetWithIdOptions): ActorHandle<AD>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Gets a stateless handle to a actor by its key, creating it if necessary.
|
|
1211
|
+
*
|
|
1212
|
+
* @template AD The actor class that this handle is for.
|
|
1213
|
+
* @param {string} name - The name of the actor.
|
|
1214
|
+
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
1215
|
+
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
1216
|
+
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
1217
|
+
*/
|
|
1218
|
+
getOrCreate<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: GetOrCreateOptions): ActorHandle<AD>;
|
|
1219
|
+
/**
|
|
1220
|
+
* Creates a new actor with the provided key and returns a stateless handle to it.
|
|
1221
|
+
* Resolves the actor ID and returns a handle with getForId query.
|
|
1222
|
+
*
|
|
1223
|
+
* @template AD The actor class that this handle is for.
|
|
1224
|
+
* @param {string} name - The name of the actor.
|
|
1225
|
+
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
1226
|
+
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
1227
|
+
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
1228
|
+
*/
|
|
1229
|
+
create<AD extends AnyActorDefinition>(name: string, key?: string | string[], opts?: CreateOptions): Promise<ActorHandle<AD>>;
|
|
1230
|
+
[CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(conn: ActorConnRaw): ActorConn<AD>;
|
|
1231
|
+
/**
|
|
1232
|
+
* Disconnects from all actors.
|
|
1233
|
+
*
|
|
1234
|
+
* @returns {Promise<void>} A promise that resolves when all connections are closed.
|
|
1235
|
+
*/
|
|
1236
|
+
dispose(): Promise<void>;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Client type with actor accessors.
|
|
1240
|
+
* This adds property accessors for actor names to the ClientRaw base class.
|
|
1241
|
+
*
|
|
1242
|
+
* @template A The actor registry type.
|
|
1243
|
+
*/
|
|
1244
|
+
type Client<A extends Registry<any>> = ClientRaw & {
|
|
1245
|
+
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
|
|
1246
|
+
};
|
|
1247
|
+
type AnyClient = Client<Registry<any>>;
|
|
1248
|
+
declare function createClientWithDriver<A extends Registry<any>>(driver: ManagerDriver, config?: ClientConfig): Client<A>;
|
|
1435
1249
|
|
|
1436
1250
|
/**
|
|
1437
1251
|
* Context for a remote procedure call.
|
|
@@ -1442,565 +1256,1001 @@ declare class ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDat
|
|
|
1442
1256
|
#private;
|
|
1443
1257
|
readonly conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
1444
1258
|
/**
|
|
1445
|
-
* Should not be called directly.
|
|
1259
|
+
* Should not be called directly.
|
|
1260
|
+
*
|
|
1261
|
+
* @param actorContext - The actor context
|
|
1262
|
+
* @param conn - The connection associated with the action
|
|
1263
|
+
*/
|
|
1264
|
+
constructor(actorContext: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
1265
|
+
/**
|
|
1266
|
+
* Get the actor state
|
|
1267
|
+
*/
|
|
1268
|
+
get state(): TState;
|
|
1269
|
+
/**
|
|
1270
|
+
* Get the actor variables
|
|
1271
|
+
*/
|
|
1272
|
+
get vars(): TVars;
|
|
1273
|
+
/**
|
|
1274
|
+
* Broadcasts an event to all connected clients.
|
|
1275
|
+
*/
|
|
1276
|
+
broadcast(name: string, ...args: any[]): void;
|
|
1277
|
+
/**
|
|
1278
|
+
* Gets the logger instance.
|
|
1279
|
+
*/
|
|
1280
|
+
get log(): Logger;
|
|
1281
|
+
/**
|
|
1282
|
+
* Gets actor ID.
|
|
1283
|
+
*/
|
|
1284
|
+
get actorId(): string;
|
|
1285
|
+
/**
|
|
1286
|
+
* Gets the actor name.
|
|
1287
|
+
*/
|
|
1288
|
+
get name(): string;
|
|
1289
|
+
/**
|
|
1290
|
+
* Gets the actor key.
|
|
1291
|
+
*/
|
|
1292
|
+
get key(): ActorKey;
|
|
1293
|
+
/**
|
|
1294
|
+
* Gets the region.
|
|
1295
|
+
*/
|
|
1296
|
+
get region(): string;
|
|
1297
|
+
/**
|
|
1298
|
+
* Gets the scheduler.
|
|
1299
|
+
*/
|
|
1300
|
+
get schedule(): Schedule;
|
|
1301
|
+
/**
|
|
1302
|
+
* Gets the map of connections.
|
|
1303
|
+
*/
|
|
1304
|
+
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Returns the client for the given registry.
|
|
1307
|
+
*/
|
|
1308
|
+
client<R extends Registry<any>>(): Client<R>;
|
|
1309
|
+
/**
|
|
1310
|
+
* @experimental
|
|
1311
|
+
*/
|
|
1312
|
+
get db(): InferDatabaseClient<TDatabase>;
|
|
1313
|
+
/**
|
|
1314
|
+
* Forces the state to get saved.
|
|
1315
|
+
*/
|
|
1316
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
1317
|
+
/**
|
|
1318
|
+
* Prevents the actor from sleeping until promise is complete.
|
|
1319
|
+
*/
|
|
1320
|
+
waitUntil(promise: Promise<void>): void;
|
|
1321
|
+
/**
|
|
1322
|
+
* AbortSignal that fires when the actor is stopping.
|
|
1323
|
+
*/
|
|
1324
|
+
get abortSignal(): AbortSignal;
|
|
1325
|
+
/**
|
|
1326
|
+
* Forces the actor to sleep.
|
|
1327
|
+
*
|
|
1328
|
+
* Not supported on all drivers.
|
|
1329
|
+
*
|
|
1330
|
+
* @experimental
|
|
1331
|
+
*/
|
|
1332
|
+
sleep(): void;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
type InitContext = ActorContext<undefined, undefined, undefined, undefined, undefined, undefined>;
|
|
1336
|
+
interface ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1337
|
+
state?: TState;
|
|
1338
|
+
connParams?: TConnParams;
|
|
1339
|
+
connState?: TConnState;
|
|
1340
|
+
vars?: TVars;
|
|
1341
|
+
input?: TInput;
|
|
1342
|
+
database?: TDatabase;
|
|
1343
|
+
}
|
|
1344
|
+
declare const ActorConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
1345
|
+
onCreate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1346
|
+
onStart: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1347
|
+
onStop: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1348
|
+
onStateChange: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1349
|
+
onBeforeConnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1350
|
+
onConnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1351
|
+
onDisconnect: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1352
|
+
onBeforeActionResponse: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1353
|
+
onFetch: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1354
|
+
onWebSocket: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1355
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>>;
|
|
1356
|
+
state: z.ZodOptional<z.ZodAny>;
|
|
1357
|
+
createState: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1358
|
+
connState: z.ZodOptional<z.ZodAny>;
|
|
1359
|
+
createConnState: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1360
|
+
vars: z.ZodOptional<z.ZodAny>;
|
|
1361
|
+
db: z.ZodOptional<z.ZodAny>;
|
|
1362
|
+
createVars: z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>>;
|
|
1363
|
+
options: z.ZodDefault<z.ZodObject<{
|
|
1364
|
+
createVarsTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1365
|
+
createConnStateTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1366
|
+
onConnectTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1367
|
+
onStopTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1368
|
+
stateSaveInterval: z.ZodDefault<z.ZodNumber>;
|
|
1369
|
+
actionTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1370
|
+
waitUntilTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1371
|
+
connectionLivenessTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1372
|
+
connectionLivenessInterval: z.ZodDefault<z.ZodNumber>;
|
|
1373
|
+
noSleep: z.ZodDefault<z.ZodBoolean>;
|
|
1374
|
+
sleepTimeout: z.ZodDefault<z.ZodNumber>;
|
|
1375
|
+
}, "strict", z.ZodTypeAny, {
|
|
1376
|
+
createVarsTimeout: number;
|
|
1377
|
+
createConnStateTimeout: number;
|
|
1378
|
+
onConnectTimeout: number;
|
|
1379
|
+
onStopTimeout: number;
|
|
1380
|
+
stateSaveInterval: number;
|
|
1381
|
+
actionTimeout: number;
|
|
1382
|
+
waitUntilTimeout: number;
|
|
1383
|
+
connectionLivenessTimeout: number;
|
|
1384
|
+
connectionLivenessInterval: number;
|
|
1385
|
+
noSleep: boolean;
|
|
1386
|
+
sleepTimeout: number;
|
|
1387
|
+
}, {
|
|
1388
|
+
createVarsTimeout?: number | undefined;
|
|
1389
|
+
createConnStateTimeout?: number | undefined;
|
|
1390
|
+
onConnectTimeout?: number | undefined;
|
|
1391
|
+
onStopTimeout?: number | undefined;
|
|
1392
|
+
stateSaveInterval?: number | undefined;
|
|
1393
|
+
actionTimeout?: number | undefined;
|
|
1394
|
+
waitUntilTimeout?: number | undefined;
|
|
1395
|
+
connectionLivenessTimeout?: number | undefined;
|
|
1396
|
+
connectionLivenessInterval?: number | undefined;
|
|
1397
|
+
noSleep?: boolean | undefined;
|
|
1398
|
+
sleepTimeout?: number | undefined;
|
|
1399
|
+
}>>;
|
|
1400
|
+
}, "strict", z.ZodTypeAny, {
|
|
1401
|
+
options: {
|
|
1402
|
+
createVarsTimeout: number;
|
|
1403
|
+
createConnStateTimeout: number;
|
|
1404
|
+
onConnectTimeout: number;
|
|
1405
|
+
onStopTimeout: number;
|
|
1406
|
+
stateSaveInterval: number;
|
|
1407
|
+
actionTimeout: number;
|
|
1408
|
+
waitUntilTimeout: number;
|
|
1409
|
+
connectionLivenessTimeout: number;
|
|
1410
|
+
connectionLivenessInterval: number;
|
|
1411
|
+
noSleep: boolean;
|
|
1412
|
+
sleepTimeout: number;
|
|
1413
|
+
};
|
|
1414
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1415
|
+
state?: any;
|
|
1416
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1417
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1418
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1419
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1420
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1421
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1422
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1423
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1424
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1425
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1426
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1427
|
+
connState?: any;
|
|
1428
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1429
|
+
vars?: any;
|
|
1430
|
+
db?: any;
|
|
1431
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1432
|
+
}, {
|
|
1433
|
+
state?: any;
|
|
1434
|
+
options?: {
|
|
1435
|
+
createVarsTimeout?: number | undefined;
|
|
1436
|
+
createConnStateTimeout?: number | undefined;
|
|
1437
|
+
onConnectTimeout?: number | undefined;
|
|
1438
|
+
onStopTimeout?: number | undefined;
|
|
1439
|
+
stateSaveInterval?: number | undefined;
|
|
1440
|
+
actionTimeout?: number | undefined;
|
|
1441
|
+
waitUntilTimeout?: number | undefined;
|
|
1442
|
+
connectionLivenessTimeout?: number | undefined;
|
|
1443
|
+
connectionLivenessInterval?: number | undefined;
|
|
1444
|
+
noSleep?: boolean | undefined;
|
|
1445
|
+
sleepTimeout?: number | undefined;
|
|
1446
|
+
} | undefined;
|
|
1447
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1448
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1449
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1450
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1451
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1452
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1453
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1454
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1455
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1456
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1457
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1458
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1459
|
+
connState?: any;
|
|
1460
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1461
|
+
vars?: any;
|
|
1462
|
+
db?: any;
|
|
1463
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1464
|
+
}>, {
|
|
1465
|
+
options: {
|
|
1466
|
+
createVarsTimeout: number;
|
|
1467
|
+
createConnStateTimeout: number;
|
|
1468
|
+
onConnectTimeout: number;
|
|
1469
|
+
onStopTimeout: number;
|
|
1470
|
+
stateSaveInterval: number;
|
|
1471
|
+
actionTimeout: number;
|
|
1472
|
+
waitUntilTimeout: number;
|
|
1473
|
+
connectionLivenessTimeout: number;
|
|
1474
|
+
connectionLivenessInterval: number;
|
|
1475
|
+
noSleep: boolean;
|
|
1476
|
+
sleepTimeout: number;
|
|
1477
|
+
};
|
|
1478
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1479
|
+
state?: any;
|
|
1480
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1481
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1482
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1483
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1484
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1485
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1486
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1487
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1488
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1489
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1490
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1491
|
+
connState?: any;
|
|
1492
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1493
|
+
vars?: any;
|
|
1494
|
+
db?: any;
|
|
1495
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1496
|
+
}, {
|
|
1497
|
+
state?: any;
|
|
1498
|
+
options?: {
|
|
1499
|
+
createVarsTimeout?: number | undefined;
|
|
1500
|
+
createConnStateTimeout?: number | undefined;
|
|
1501
|
+
onConnectTimeout?: number | undefined;
|
|
1502
|
+
onStopTimeout?: number | undefined;
|
|
1503
|
+
stateSaveInterval?: number | undefined;
|
|
1504
|
+
actionTimeout?: number | undefined;
|
|
1505
|
+
waitUntilTimeout?: number | undefined;
|
|
1506
|
+
connectionLivenessTimeout?: number | undefined;
|
|
1507
|
+
connectionLivenessInterval?: number | undefined;
|
|
1508
|
+
noSleep?: boolean | undefined;
|
|
1509
|
+
sleepTimeout?: number | undefined;
|
|
1510
|
+
} | undefined;
|
|
1511
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1512
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1513
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1514
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1515
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1516
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1517
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1518
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1519
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1520
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1521
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1522
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1523
|
+
connState?: any;
|
|
1524
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1525
|
+
vars?: any;
|
|
1526
|
+
db?: any;
|
|
1527
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1528
|
+
}>, {
|
|
1529
|
+
options: {
|
|
1530
|
+
createVarsTimeout: number;
|
|
1531
|
+
createConnStateTimeout: number;
|
|
1532
|
+
onConnectTimeout: number;
|
|
1533
|
+
onStopTimeout: number;
|
|
1534
|
+
stateSaveInterval: number;
|
|
1535
|
+
actionTimeout: number;
|
|
1536
|
+
waitUntilTimeout: number;
|
|
1537
|
+
connectionLivenessTimeout: number;
|
|
1538
|
+
connectionLivenessInterval: number;
|
|
1539
|
+
noSleep: boolean;
|
|
1540
|
+
sleepTimeout: number;
|
|
1541
|
+
};
|
|
1542
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1543
|
+
state?: any;
|
|
1544
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1545
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1546
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1547
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1548
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1549
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1550
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1551
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1552
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1553
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1554
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1555
|
+
connState?: any;
|
|
1556
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1557
|
+
vars?: any;
|
|
1558
|
+
db?: any;
|
|
1559
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1560
|
+
}, {
|
|
1561
|
+
state?: any;
|
|
1562
|
+
options?: {
|
|
1563
|
+
createVarsTimeout?: number | undefined;
|
|
1564
|
+
createConnStateTimeout?: number | undefined;
|
|
1565
|
+
onConnectTimeout?: number | undefined;
|
|
1566
|
+
onStopTimeout?: number | undefined;
|
|
1567
|
+
stateSaveInterval?: number | undefined;
|
|
1568
|
+
actionTimeout?: number | undefined;
|
|
1569
|
+
waitUntilTimeout?: number | undefined;
|
|
1570
|
+
connectionLivenessTimeout?: number | undefined;
|
|
1571
|
+
connectionLivenessInterval?: number | undefined;
|
|
1572
|
+
noSleep?: boolean | undefined;
|
|
1573
|
+
sleepTimeout?: number | undefined;
|
|
1574
|
+
} | undefined;
|
|
1575
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1576
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1577
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1578
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1579
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1580
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1581
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1582
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1583
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1584
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1585
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1586
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1587
|
+
connState?: any;
|
|
1588
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1589
|
+
vars?: any;
|
|
1590
|
+
db?: any;
|
|
1591
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1592
|
+
}>, {
|
|
1593
|
+
options: {
|
|
1594
|
+
createVarsTimeout: number;
|
|
1595
|
+
createConnStateTimeout: number;
|
|
1596
|
+
onConnectTimeout: number;
|
|
1597
|
+
onStopTimeout: number;
|
|
1598
|
+
stateSaveInterval: number;
|
|
1599
|
+
actionTimeout: number;
|
|
1600
|
+
waitUntilTimeout: number;
|
|
1601
|
+
connectionLivenessTimeout: number;
|
|
1602
|
+
connectionLivenessInterval: number;
|
|
1603
|
+
noSleep: boolean;
|
|
1604
|
+
sleepTimeout: number;
|
|
1605
|
+
};
|
|
1606
|
+
actions: Record<string, (...args: unknown[]) => unknown>;
|
|
1607
|
+
state?: any;
|
|
1608
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1609
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1610
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1611
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1612
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1613
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1614
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1615
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1616
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1617
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1618
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1619
|
+
connState?: any;
|
|
1620
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1621
|
+
vars?: any;
|
|
1622
|
+
db?: any;
|
|
1623
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1624
|
+
}, {
|
|
1625
|
+
state?: any;
|
|
1626
|
+
options?: {
|
|
1627
|
+
createVarsTimeout?: number | undefined;
|
|
1628
|
+
createConnStateTimeout?: number | undefined;
|
|
1629
|
+
onConnectTimeout?: number | undefined;
|
|
1630
|
+
onStopTimeout?: number | undefined;
|
|
1631
|
+
stateSaveInterval?: number | undefined;
|
|
1632
|
+
actionTimeout?: number | undefined;
|
|
1633
|
+
waitUntilTimeout?: number | undefined;
|
|
1634
|
+
connectionLivenessTimeout?: number | undefined;
|
|
1635
|
+
connectionLivenessInterval?: number | undefined;
|
|
1636
|
+
noSleep?: boolean | undefined;
|
|
1637
|
+
sleepTimeout?: number | undefined;
|
|
1638
|
+
} | undefined;
|
|
1639
|
+
onCreate?: ((...args: unknown[]) => unknown) | undefined;
|
|
1640
|
+
onStart?: ((...args: unknown[]) => unknown) | undefined;
|
|
1641
|
+
onStop?: ((...args: unknown[]) => unknown) | undefined;
|
|
1642
|
+
onStateChange?: ((...args: unknown[]) => unknown) | undefined;
|
|
1643
|
+
onBeforeConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1644
|
+
onConnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1645
|
+
onDisconnect?: ((...args: unknown[]) => unknown) | undefined;
|
|
1646
|
+
onBeforeActionResponse?: ((...args: unknown[]) => unknown) | undefined;
|
|
1647
|
+
onFetch?: ((...args: unknown[]) => unknown) | undefined;
|
|
1648
|
+
onWebSocket?: ((...args: unknown[]) => unknown) | undefined;
|
|
1649
|
+
actions?: Record<string, (...args: unknown[]) => unknown> | undefined;
|
|
1650
|
+
createState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1651
|
+
connState?: any;
|
|
1652
|
+
createConnState?: ((...args: unknown[]) => unknown) | undefined;
|
|
1653
|
+
vars?: any;
|
|
1654
|
+
db?: any;
|
|
1655
|
+
createVars?: ((...args: unknown[]) => unknown) | undefined;
|
|
1656
|
+
}>;
|
|
1657
|
+
interface OnConnectOptions {
|
|
1658
|
+
/**
|
|
1659
|
+
* The request object associated with the connection.
|
|
1446
1660
|
*
|
|
1447
|
-
* @param actorContext - The actor context
|
|
1448
|
-
* @param conn - The connection associated with the action
|
|
1449
|
-
*/
|
|
1450
|
-
constructor(actorContext: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>);
|
|
1451
|
-
/**
|
|
1452
|
-
* Get the actor state
|
|
1453
|
-
*/
|
|
1454
|
-
get state(): TState;
|
|
1455
|
-
/**
|
|
1456
|
-
* Get the actor variables
|
|
1457
|
-
*/
|
|
1458
|
-
get vars(): TVars;
|
|
1459
|
-
/**
|
|
1460
|
-
* Broadcasts an event to all connected clients.
|
|
1461
|
-
*/
|
|
1462
|
-
broadcast(name: string, ...args: any[]): void;
|
|
1463
|
-
/**
|
|
1464
|
-
* Gets the logger instance.
|
|
1465
|
-
*/
|
|
1466
|
-
get log(): Logger;
|
|
1467
|
-
/**
|
|
1468
|
-
* Gets actor ID.
|
|
1469
|
-
*/
|
|
1470
|
-
get actorId(): string;
|
|
1471
|
-
/**
|
|
1472
|
-
* Gets the actor name.
|
|
1473
|
-
*/
|
|
1474
|
-
get name(): string;
|
|
1475
|
-
/**
|
|
1476
|
-
* Gets the actor key.
|
|
1477
|
-
*/
|
|
1478
|
-
get key(): ActorKey;
|
|
1479
|
-
/**
|
|
1480
|
-
* Gets the region.
|
|
1481
|
-
*/
|
|
1482
|
-
get region(): string;
|
|
1483
|
-
/**
|
|
1484
|
-
* Gets the scheduler.
|
|
1485
|
-
*/
|
|
1486
|
-
get schedule(): Schedule;
|
|
1487
|
-
/**
|
|
1488
|
-
* Gets the map of connections.
|
|
1489
|
-
*/
|
|
1490
|
-
get conns(): Map<ConnId, Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>>;
|
|
1491
|
-
/**
|
|
1492
|
-
* Returns the client for the given registry.
|
|
1493
|
-
*/
|
|
1494
|
-
client<R extends Registry<any>>(): Client<R>;
|
|
1495
|
-
/**
|
|
1496
1661
|
* @experimental
|
|
1497
1662
|
*/
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1663
|
+
request?: Request;
|
|
1664
|
+
}
|
|
1665
|
+
type CreateState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1666
|
+
state: TState;
|
|
1667
|
+
} | {
|
|
1668
|
+
createState: (c: InitContext, input: TInput) => TState | Promise<TState>;
|
|
1669
|
+
} | Record<never, never>;
|
|
1670
|
+
type CreateConnState<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1671
|
+
connState: TConnState;
|
|
1672
|
+
} | {
|
|
1673
|
+
createConnState: (c: InitContext, opts: OnConnectOptions, params: TConnParams) => TConnState | Promise<TConnState>;
|
|
1674
|
+
} | Record<never, never>;
|
|
1675
|
+
/**
|
|
1676
|
+
* @experimental
|
|
1677
|
+
*/
|
|
1678
|
+
type CreateVars<TState, TConnParams, TConnState, TVars, TInput, TDatabase> = {
|
|
1507
1679
|
/**
|
|
1508
|
-
*
|
|
1680
|
+
* @experimental
|
|
1509
1681
|
*/
|
|
1510
|
-
|
|
1682
|
+
vars: TVars;
|
|
1683
|
+
} | {
|
|
1511
1684
|
/**
|
|
1512
|
-
* Forces the actor to sleep.
|
|
1513
|
-
*
|
|
1514
|
-
* Not supported on all drivers.
|
|
1515
|
-
*
|
|
1516
1685
|
* @experimental
|
|
1517
1686
|
*/
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
/**
|
|
1523
|
-
* Extracts the context type from an ActorDefinition
|
|
1524
|
-
*/
|
|
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;
|
|
1526
|
-
/**
|
|
1527
|
-
* Extracts the context type from an ActorDefinition
|
|
1528
|
-
*/
|
|
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>> {
|
|
1531
|
-
#private;
|
|
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>;
|
|
1535
|
-
}
|
|
1536
|
-
declare function lookupInRegistry(registryConfig: RegistryConfig, name: string): AnyActorDefinition;
|
|
1537
|
-
|
|
1538
|
-
declare const TransportSchema: z.ZodEnum<["websocket", "sse"]>;
|
|
1539
|
-
/**
|
|
1540
|
-
* Transport mechanism used to communicate between client & actor.
|
|
1541
|
-
*/
|
|
1542
|
-
type Transport = z.infer<typeof TransportSchema>;
|
|
1543
|
-
|
|
1544
|
-
/**
|
|
1545
|
-
* Action function returned by Actor connections and handles.
|
|
1546
|
-
*
|
|
1547
|
-
* @typedef {Function} ActorActionFunction
|
|
1548
|
-
* @template Args
|
|
1549
|
-
* @template Response
|
|
1550
|
-
* @param {...Args} args - Arguments for the action function.
|
|
1551
|
-
* @returns {Promise<Response>}
|
|
1552
|
-
*/
|
|
1553
|
-
type ActorActionFunction<Args extends Array<unknown> = unknown[], Response = unknown> = (...args: Args extends [unknown, ...infer Rest] ? Rest : Args) => Promise<Response>;
|
|
1554
|
-
/**
|
|
1555
|
-
* Maps action methods from actor definition to typed function signatures.
|
|
1556
|
-
*/
|
|
1557
|
-
type ActorDefinitionActions<AD extends AnyActorDefinition> = AD extends ActorDefinition<any, any, any, any, any, any, infer R> ? {
|
|
1558
|
-
[K in keyof R]: R[K] extends (...args: infer Args) => infer Return ? ActorActionFunction<Args, Return> : never;
|
|
1559
|
-
} : never;
|
|
1560
|
-
|
|
1561
|
-
declare class ActorClientError extends Error {
|
|
1562
|
-
}
|
|
1563
|
-
declare class InternalError extends ActorClientError {
|
|
1564
|
-
}
|
|
1565
|
-
declare class ManagerError extends ActorClientError {
|
|
1566
|
-
constructor(error: string, opts?: ErrorOptions);
|
|
1567
|
-
}
|
|
1568
|
-
declare class MalformedResponseMessage extends ActorClientError {
|
|
1569
|
-
constructor(cause?: unknown);
|
|
1570
|
-
}
|
|
1571
|
-
declare class ActorError extends ActorClientError {
|
|
1572
|
-
readonly group: string;
|
|
1573
|
-
readonly code: string;
|
|
1574
|
-
readonly metadata?: unknown | undefined;
|
|
1575
|
-
__type: string;
|
|
1576
|
-
constructor(group: string, code: string, message: string, metadata?: unknown | undefined);
|
|
1687
|
+
createVars: (c: InitContext, driverCtx: any) => TVars | Promise<TVars>;
|
|
1688
|
+
} | Record<never, never>;
|
|
1689
|
+
interface Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider> {
|
|
1690
|
+
[Action: string]: (c: ActionContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, ...args: any[]) => any;
|
|
1577
1691
|
}
|
|
1578
|
-
|
|
1579
|
-
/**
|
|
1580
|
-
* A function that unsubscribes from an event.
|
|
1581
|
-
*
|
|
1582
|
-
* @typedef {Function} EventUnsubscribe
|
|
1583
|
-
*/
|
|
1584
|
-
type EventUnsubscribe = () => void;
|
|
1585
|
-
/**
|
|
1586
|
-
* A function that handles connection errors.
|
|
1587
|
-
*
|
|
1588
|
-
* @typedef {Function} ActorErrorCallback
|
|
1589
|
-
*/
|
|
1590
|
-
type ActorErrorCallback = (error: ActorError) => void;
|
|
1591
|
-
declare const CONNECT_SYMBOL: unique symbol;
|
|
1592
1692
|
/**
|
|
1593
|
-
*
|
|
1594
|
-
*
|
|
1595
|
-
* @see {@link ActorConn}
|
|
1693
|
+
* @experimental
|
|
1596
1694
|
*/
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
/**
|
|
1600
|
-
* Do not call this directly.
|
|
1601
|
-
*
|
|
1602
|
-
* Creates an instance of ActorConnRaw.
|
|
1603
|
-
*
|
|
1604
|
-
* @protected
|
|
1605
|
-
*/
|
|
1606
|
-
constructor(client: ClientRaw, driver: ManagerDriver, params: unknown, encoding: Encoding, actorQuery: ActorQuery);
|
|
1607
|
-
/**
|
|
1608
|
-
* Call a raw action connection. See {@link ActorConn} for type-safe action calls.
|
|
1609
|
-
*
|
|
1610
|
-
* @see {@link ActorConn}
|
|
1611
|
-
* @template Args - The type of arguments to pass to the action function.
|
|
1612
|
-
* @template Response - The type of the response returned by the action function.
|
|
1613
|
-
* @param {string} name - The name of the action function to call.
|
|
1614
|
-
* @param {...Args} args - The arguments to pass to the action function.
|
|
1615
|
-
* @returns {Promise<Response>} - A promise that resolves to the response of the action function.
|
|
1616
|
-
*/
|
|
1617
|
-
action<Args extends Array<unknown> = unknown[], Response = unknown>(opts: {
|
|
1618
|
-
name: string;
|
|
1619
|
-
args: Args;
|
|
1620
|
-
signal?: AbortSignal;
|
|
1621
|
-
}): Promise<Response>;
|
|
1695
|
+
type AuthIntent = "get" | "create" | "connect" | "action" | "message";
|
|
1696
|
+
interface BaseActorConfig<TState, TConnParams, TConnState, TVars, TInput, TDatabase extends AnyDatabaseProvider, TActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, TDatabase>> {
|
|
1622
1697
|
/**
|
|
1623
|
-
*
|
|
1624
|
-
enc
|
|
1625
|
-
* Establishes a connection to the server using the specified endpoint & encoding & driver.
|
|
1698
|
+
* Called when the actor is first initialized.
|
|
1626
1699
|
*
|
|
1627
|
-
*
|
|
1700
|
+
* Use this hook to initialize your actor's state.
|
|
1701
|
+
* This is called before any other lifecycle hooks.
|
|
1628
1702
|
*/
|
|
1629
|
-
|
|
1703
|
+
onCreate?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, input: TInput) => void | Promise<void>;
|
|
1630
1704
|
/**
|
|
1631
|
-
*
|
|
1705
|
+
* Called when the actor is started and ready to receive connections and action.
|
|
1632
1706
|
*
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1635
|
-
*
|
|
1636
|
-
* @returns
|
|
1637
|
-
* @see {@link https://rivet.dev/docs/events|Events Documentation}
|
|
1707
|
+
* Use this hook to initialize resources needed for the actor's operation
|
|
1708
|
+
* (timers, external connections, etc.)
|
|
1709
|
+
*
|
|
1710
|
+
* @returns Void or a Promise that resolves when startup is complete
|
|
1638
1711
|
*/
|
|
1639
|
-
|
|
1712
|
+
onStart?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1640
1713
|
/**
|
|
1641
|
-
*
|
|
1714
|
+
* Called when the actor is stopping or sleeping.
|
|
1642
1715
|
*
|
|
1643
|
-
*
|
|
1644
|
-
*
|
|
1645
|
-
*
|
|
1646
|
-
*
|
|
1647
|
-
*
|
|
1716
|
+
* Use this hook to clean up resources, save state, or perform
|
|
1717
|
+
* any shutdown operations before the actor sleeps or stops.
|
|
1718
|
+
*
|
|
1719
|
+
* Not supported on all platforms.
|
|
1720
|
+
*
|
|
1721
|
+
* @returns Void or a Promise that resolves when shutdown is complete
|
|
1648
1722
|
*/
|
|
1649
|
-
|
|
1723
|
+
onStop?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1650
1724
|
/**
|
|
1651
|
-
*
|
|
1725
|
+
* Called when the actor's state changes.
|
|
1652
1726
|
*
|
|
1653
|
-
*
|
|
1654
|
-
*
|
|
1727
|
+
* Use this hook to react to state changes, such as updating
|
|
1728
|
+
* external systems or triggering events.
|
|
1729
|
+
*
|
|
1730
|
+
* State changes made within this hook will NOT trigger
|
|
1731
|
+
* another onStateChange call, preventing infinite recursion.
|
|
1732
|
+
*
|
|
1733
|
+
* @param newState The updated state
|
|
1655
1734
|
*/
|
|
1656
|
-
|
|
1735
|
+
onStateChange?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, newState: TState) => void;
|
|
1657
1736
|
/**
|
|
1658
|
-
*
|
|
1737
|
+
* Called before a client connects to the actor.
|
|
1659
1738
|
*
|
|
1660
|
-
*
|
|
1739
|
+
* Use this hook to determine if a connection should be accepted
|
|
1740
|
+
* and to initialize connection-specific state.
|
|
1741
|
+
*
|
|
1742
|
+
* @param opts Connection parameters including client-provided data
|
|
1743
|
+
* @returns The initial connection state or a Promise that resolves to it
|
|
1744
|
+
* @throws Throw an error to reject the connection
|
|
1661
1745
|
*/
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1664
|
-
/**
|
|
1665
|
-
* Connection to a actor. Allows calling actor's remote procedure calls with inferred types. See {@link ActorConnRaw} for underlying methods.
|
|
1666
|
-
*
|
|
1667
|
-
* @example
|
|
1668
|
-
* ```
|
|
1669
|
-
* const room = client.connect<ChatRoom>(...etc...);
|
|
1670
|
-
* // This calls the action named `sendMessage` on the `ChatRoom` actor.
|
|
1671
|
-
* await room.sendMessage('Hello, world!');
|
|
1672
|
-
* ```
|
|
1673
|
-
*
|
|
1674
|
-
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
1675
|
-
*
|
|
1676
|
-
* @template AD The actor class that this connection is for.
|
|
1677
|
-
* @see {@link ActorConnRaw}
|
|
1678
|
-
*/
|
|
1679
|
-
type ActorConn<AD extends AnyActorDefinition> = ActorConnRaw & ActorDefinitionActions<AD>;
|
|
1680
|
-
|
|
1681
|
-
/**
|
|
1682
|
-
* Provides underlying functions for stateless {@link ActorHandle} for action calls.
|
|
1683
|
-
* Similar to ActorConnRaw but doesn't maintain a connection.
|
|
1684
|
-
*
|
|
1685
|
-
* @see {@link ActorHandle}
|
|
1686
|
-
*/
|
|
1687
|
-
declare class ActorHandleRaw {
|
|
1688
|
-
#private;
|
|
1746
|
+
onBeforeConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, opts: OnConnectOptions, params: TConnParams) => void | Promise<void>;
|
|
1689
1747
|
/**
|
|
1690
|
-
*
|
|
1748
|
+
* Called when a client successfully connects to the actor.
|
|
1691
1749
|
*
|
|
1692
|
-
*
|
|
1750
|
+
* Use this hook to perform actions when a connection is established,
|
|
1751
|
+
* such as sending initial data or updating the actor's state.
|
|
1693
1752
|
*
|
|
1694
|
-
* @
|
|
1753
|
+
* @param conn The connection object
|
|
1754
|
+
* @returns Void or a Promise that resolves when connection handling is complete
|
|
1695
1755
|
*/
|
|
1696
|
-
|
|
1756
|
+
onConnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1697
1757
|
/**
|
|
1698
|
-
*
|
|
1758
|
+
* Called when a client disconnects from the actor.
|
|
1699
1759
|
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
1702
|
-
*
|
|
1760
|
+
* Use this hook to clean up resources associated with the connection
|
|
1761
|
+
* or update the actor's state.
|
|
1762
|
+
*
|
|
1763
|
+
* @param conn The connection that is being closed
|
|
1764
|
+
* @returns Void or a Promise that resolves when disconnect handling is complete
|
|
1703
1765
|
*/
|
|
1704
|
-
|
|
1705
|
-
name: string;
|
|
1706
|
-
args: Args;
|
|
1707
|
-
signal?: AbortSignal;
|
|
1708
|
-
}): Promise<Response>;
|
|
1766
|
+
onDisconnect?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, conn: Conn<TState, TConnParams, TConnState, TVars, TInput, TDatabase>) => void | Promise<void>;
|
|
1709
1767
|
/**
|
|
1710
|
-
*
|
|
1768
|
+
* Called before sending an action response to the client.
|
|
1711
1769
|
*
|
|
1712
|
-
*
|
|
1713
|
-
*
|
|
1770
|
+
* Use this hook to modify or transform the output of an action before it's sent
|
|
1771
|
+
* to the client. This is useful for formatting responses, adding metadata,
|
|
1772
|
+
* or applying transformations to the output.
|
|
1773
|
+
*
|
|
1774
|
+
* @param name The name of the action that was called
|
|
1775
|
+
* @param args The arguments that were passed to the action
|
|
1776
|
+
* @param output The output that will be sent to the client
|
|
1777
|
+
* @returns The modified output to send to the client
|
|
1714
1778
|
*/
|
|
1715
|
-
|
|
1779
|
+
onBeforeActionResponse?: <Out>(c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, name: string, args: unknown[], output: Out) => Out | Promise<Out>;
|
|
1716
1780
|
/**
|
|
1717
|
-
*
|
|
1781
|
+
* Called when a raw HTTP request is made to the actor.
|
|
1718
1782
|
*
|
|
1719
|
-
*
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
1783
|
+
* This handler receives raw HTTP requests made to `/actors/{actorName}/http/*` endpoints.
|
|
1784
|
+
* Use this hook to handle custom HTTP patterns, REST APIs, or other HTTP-based protocols.
|
|
1785
|
+
*
|
|
1786
|
+
* @param request The raw HTTP request object
|
|
1787
|
+
* @returns A Response object to send back, or void to continue with default routing
|
|
1722
1788
|
*/
|
|
1723
|
-
|
|
1789
|
+
onFetch?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, request: Request, opts: {}) => Response | Promise<Response>;
|
|
1724
1790
|
/**
|
|
1725
|
-
*
|
|
1791
|
+
* Called when a raw WebSocket connection is established to the actor.
|
|
1726
1792
|
*
|
|
1727
|
-
*
|
|
1728
|
-
*
|
|
1729
|
-
*
|
|
1793
|
+
* This handler receives WebSocket connections made to `/actors/{actorName}/websocket/*` endpoints.
|
|
1794
|
+
* Use this hook to handle custom WebSocket protocols, binary streams, or other WebSocket-based communication.
|
|
1795
|
+
*
|
|
1796
|
+
* @param websocket The raw WebSocket connection
|
|
1797
|
+
* @param request The original HTTP upgrade request
|
|
1730
1798
|
*/
|
|
1731
|
-
|
|
1799
|
+
onWebSocket?: (c: ActorContext<TState, TConnParams, TConnState, TVars, TInput, TDatabase>, websocket: UniversalWebSocket, opts: {
|
|
1800
|
+
request: Request;
|
|
1801
|
+
}) => void | Promise<void>;
|
|
1802
|
+
actions: TActions;
|
|
1803
|
+
}
|
|
1804
|
+
type ActorDatabaseConfig<TDatabase extends AnyDatabaseProvider> = {
|
|
1732
1805
|
/**
|
|
1733
|
-
*
|
|
1734
|
-
*
|
|
1735
|
-
* @returns {Promise<string>} - A promise that resolves to the actor's ID
|
|
1806
|
+
* @experimental
|
|
1736
1807
|
*/
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1808
|
+
db: TDatabase;
|
|
1809
|
+
} | Record<never, never>;
|
|
1810
|
+
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>;
|
|
1811
|
+
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>> = {
|
|
1812
|
+
types?: ActorTypes<TState, TConnParams, TConnState, TVars, TInput, TDatabase>;
|
|
1813
|
+
} & 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>;
|
|
1814
|
+
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>;
|
|
1815
|
+
|
|
1816
|
+
declare const ActorId: z__default.core.$ZodBranded<z__default.ZodString, "ActorId">;
|
|
1817
|
+
type ActorId = z__default.infer<typeof ActorId>;
|
|
1818
|
+
declare enum ActorFeature {
|
|
1819
|
+
Logs = "logs",
|
|
1820
|
+
Config = "config",
|
|
1821
|
+
Connections = "connections",
|
|
1822
|
+
State = "state",
|
|
1823
|
+
Console = "console",
|
|
1824
|
+
Runtime = "runtime",
|
|
1825
|
+
Metrics = "metrics",
|
|
1826
|
+
EventsMonitoring = "events-monitoring",
|
|
1827
|
+
Database = "database"
|
|
1828
|
+
}
|
|
1829
|
+
declare const ActorSchema: z__default.ZodObject<{
|
|
1830
|
+
id: z__default.core.$ZodBranded<z__default.ZodString, "ActorId">;
|
|
1831
|
+
name: z__default.ZodString;
|
|
1832
|
+
key: z__default.ZodArray<z__default.ZodString>;
|
|
1833
|
+
tags: z__default.ZodOptional<z__default.ZodRecord<z__default.ZodString, z__default.ZodString>>;
|
|
1834
|
+
region: z__default.ZodOptional<z__default.ZodString>;
|
|
1835
|
+
createdAt: z__default.ZodOptional<z__default.ZodString>;
|
|
1836
|
+
startedAt: z__default.ZodOptional<z__default.ZodString>;
|
|
1837
|
+
destroyedAt: z__default.ZodOptional<z__default.ZodString>;
|
|
1838
|
+
features: z__default.ZodOptional<z__default.ZodArray<z__default.ZodEnum<typeof ActorFeature>>>;
|
|
1839
|
+
}, z__default.core.$strip>;
|
|
1840
|
+
type Actor = z__default.infer<typeof ActorSchema>;
|
|
1841
|
+
declare const ActorLogEntry: z__default.ZodObject<{
|
|
1842
|
+
level: z__default.ZodString;
|
|
1843
|
+
message: z__default.ZodString;
|
|
1844
|
+
timestamp: z__default.ZodString;
|
|
1845
|
+
metadata: z__default.ZodOptional<z__default.ZodRecord<z__default.ZodString, z__default.ZodAny>>;
|
|
1846
|
+
}, z__default.core.$strip>;
|
|
1847
|
+
type ActorLogEntry = z__default.infer<typeof ActorLogEntry>;
|
|
1848
|
+
declare const OperationSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
|
|
1849
|
+
op: z__default.ZodLiteral<"remove">;
|
|
1850
|
+
path: z__default.ZodString;
|
|
1851
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1852
|
+
op: z__default.ZodLiteral<"add">;
|
|
1853
|
+
path: z__default.ZodString;
|
|
1854
|
+
value: z__default.ZodUnknown;
|
|
1855
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1856
|
+
op: z__default.ZodLiteral<"replace">;
|
|
1857
|
+
path: z__default.ZodString;
|
|
1858
|
+
value: z__default.ZodUnknown;
|
|
1859
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1860
|
+
op: z__default.ZodLiteral<"move">;
|
|
1861
|
+
path: z__default.ZodString;
|
|
1862
|
+
from: z__default.ZodString;
|
|
1863
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1864
|
+
op: z__default.ZodLiteral<"copy">;
|
|
1865
|
+
path: z__default.ZodString;
|
|
1866
|
+
from: z__default.ZodString;
|
|
1867
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1868
|
+
op: z__default.ZodLiteral<"test">;
|
|
1869
|
+
path: z__default.ZodString;
|
|
1870
|
+
value: z__default.ZodUnknown;
|
|
1871
|
+
}, z__default.core.$strip>]>;
|
|
1872
|
+
type Operation = z__default.infer<typeof OperationSchema>;
|
|
1873
|
+
declare const PatchSchema: z__default.ZodArray<z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
|
|
1874
|
+
op: z__default.ZodLiteral<"remove">;
|
|
1875
|
+
path: z__default.ZodString;
|
|
1876
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1877
|
+
op: z__default.ZodLiteral<"add">;
|
|
1878
|
+
path: z__default.ZodString;
|
|
1879
|
+
value: z__default.ZodUnknown;
|
|
1880
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1881
|
+
op: z__default.ZodLiteral<"replace">;
|
|
1882
|
+
path: z__default.ZodString;
|
|
1883
|
+
value: z__default.ZodUnknown;
|
|
1884
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1885
|
+
op: z__default.ZodLiteral<"move">;
|
|
1886
|
+
path: z__default.ZodString;
|
|
1887
|
+
from: z__default.ZodString;
|
|
1888
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1889
|
+
op: z__default.ZodLiteral<"copy">;
|
|
1890
|
+
path: z__default.ZodString;
|
|
1891
|
+
from: z__default.ZodString;
|
|
1892
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1893
|
+
op: z__default.ZodLiteral<"test">;
|
|
1894
|
+
path: z__default.ZodString;
|
|
1895
|
+
value: z__default.ZodUnknown;
|
|
1896
|
+
}, z__default.core.$strip>]>>;
|
|
1897
|
+
type Patch = z__default.infer<typeof PatchSchema>;
|
|
1898
|
+
declare const ConnectionSchema: z__default.ZodObject<{
|
|
1899
|
+
params: z__default.ZodOptional<z__default.ZodRecord<z__default.ZodString, z__default.ZodAny>>;
|
|
1900
|
+
id: z__default.ZodString;
|
|
1901
|
+
stateEnabled: z__default.ZodOptional<z__default.ZodBoolean>;
|
|
1902
|
+
state: z__default.ZodOptional<z__default.ZodAny>;
|
|
1903
|
+
auth: z__default.ZodOptional<z__default.ZodRecord<z__default.ZodString, z__default.ZodAny>>;
|
|
1904
|
+
}, z__default.core.$strip>;
|
|
1905
|
+
type Connection = z__default.infer<typeof ConnectionSchema>;
|
|
1906
|
+
declare const RealtimeEventSchema: z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
|
|
1907
|
+
type: z__default.ZodLiteral<"action">;
|
|
1908
|
+
name: z__default.ZodString;
|
|
1909
|
+
args: z__default.ZodArray<z__default.ZodAny>;
|
|
1910
|
+
connId: z__default.ZodString;
|
|
1911
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1912
|
+
type: z__default.ZodLiteral<"broadcast">;
|
|
1913
|
+
eventName: z__default.ZodString;
|
|
1914
|
+
args: z__default.ZodArray<z__default.ZodAny>;
|
|
1915
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1916
|
+
type: z__default.ZodLiteral<"subscribe">;
|
|
1917
|
+
eventName: z__default.ZodString;
|
|
1918
|
+
connId: z__default.ZodString;
|
|
1919
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1920
|
+
type: z__default.ZodLiteral<"unsubscribe">;
|
|
1921
|
+
eventName: z__default.ZodString;
|
|
1922
|
+
connId: z__default.ZodString;
|
|
1923
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1924
|
+
type: z__default.ZodLiteral<"event">;
|
|
1925
|
+
eventName: z__default.ZodString;
|
|
1926
|
+
args: z__default.ZodArray<z__default.ZodAny>;
|
|
1927
|
+
connId: z__default.ZodString;
|
|
1928
|
+
}, z__default.core.$strip>]>;
|
|
1929
|
+
type RealtimeEvent = z__default.infer<typeof RealtimeEventSchema>;
|
|
1930
|
+
declare const RecordedRealtimeEventSchema: z__default.ZodIntersection<z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
|
|
1931
|
+
type: z__default.ZodLiteral<"action">;
|
|
1932
|
+
name: z__default.ZodString;
|
|
1933
|
+
args: z__default.ZodArray<z__default.ZodAny>;
|
|
1934
|
+
connId: z__default.ZodString;
|
|
1935
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1936
|
+
type: z__default.ZodLiteral<"broadcast">;
|
|
1937
|
+
eventName: z__default.ZodString;
|
|
1938
|
+
args: z__default.ZodArray<z__default.ZodAny>;
|
|
1939
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1940
|
+
type: z__default.ZodLiteral<"subscribe">;
|
|
1941
|
+
eventName: z__default.ZodString;
|
|
1942
|
+
connId: z__default.ZodString;
|
|
1943
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1944
|
+
type: z__default.ZodLiteral<"unsubscribe">;
|
|
1945
|
+
eventName: z__default.ZodString;
|
|
1946
|
+
connId: z__default.ZodString;
|
|
1947
|
+
}, z__default.core.$strip>, z__default.ZodObject<{
|
|
1948
|
+
type: z__default.ZodLiteral<"event">;
|
|
1949
|
+
eventName: z__default.ZodString;
|
|
1950
|
+
args: z__default.ZodArray<z__default.ZodAny>;
|
|
1951
|
+
connId: z__default.ZodString;
|
|
1952
|
+
}, z__default.core.$strip>]>, z__default.ZodObject<{
|
|
1953
|
+
id: z__default.ZodString;
|
|
1954
|
+
timestamp: z__default.ZodNumber;
|
|
1955
|
+
}, z__default.core.$strip>>;
|
|
1956
|
+
type RecordedRealtimeEvent = z__default.infer<typeof RecordedRealtimeEventSchema>;
|
|
1957
|
+
declare const DatabaseQuerySchema: z__default.ZodObject<{
|
|
1958
|
+
sql: z__default.ZodString;
|
|
1959
|
+
args: z__default.ZodArray<z__default.ZodUnion<[z__default.ZodString, z__default.ZodNumber]>>;
|
|
1960
|
+
}, z__default.core.$strip>;
|
|
1961
|
+
type DatabaseQuery = z__default.infer<typeof DatabaseQuerySchema>;
|
|
1962
|
+
declare const TableSchema: z__default.ZodObject<{
|
|
1963
|
+
schema: z__default.ZodString;
|
|
1964
|
+
name: z__default.ZodString;
|
|
1965
|
+
type: z__default.ZodEnum<{
|
|
1966
|
+
table: "table";
|
|
1967
|
+
view: "view";
|
|
1968
|
+
}>;
|
|
1969
|
+
}, z__default.core.$strip>;
|
|
1970
|
+
type Table = z__default.infer<typeof TableSchema>;
|
|
1971
|
+
declare const TablesSchema: z__default.ZodArray<z__default.ZodObject<{
|
|
1972
|
+
schema: z__default.ZodString;
|
|
1973
|
+
name: z__default.ZodString;
|
|
1974
|
+
type: z__default.ZodEnum<{
|
|
1975
|
+
table: "table";
|
|
1976
|
+
view: "view";
|
|
1977
|
+
}>;
|
|
1978
|
+
}, z__default.core.$strip>>;
|
|
1979
|
+
type Tables = z__default.infer<typeof TablesSchema>;
|
|
1980
|
+
declare const ColumnSchema: z__default.ZodObject<{
|
|
1981
|
+
cid: z__default.ZodNumber;
|
|
1982
|
+
name: z__default.ZodString;
|
|
1983
|
+
type: z__default.ZodPipe<z__default.ZodString, z__default.ZodTransform<"integer" | "blob" | "text" | "real" | "numeric" | "serial", string>>;
|
|
1984
|
+
notnull: z__default.ZodCoercedBoolean<unknown>;
|
|
1985
|
+
dflt_value: z__default.ZodNullable<z__default.ZodString>;
|
|
1986
|
+
pk: z__default.ZodNullable<z__default.ZodCoercedBoolean<unknown>>;
|
|
1987
|
+
}, z__default.core.$strip>;
|
|
1988
|
+
type Column = z__default.infer<typeof ColumnSchema>;
|
|
1989
|
+
declare const ColumnsSchema: z__default.ZodArray<z__default.ZodObject<{
|
|
1990
|
+
cid: z__default.ZodNumber;
|
|
1991
|
+
name: z__default.ZodString;
|
|
1992
|
+
type: z__default.ZodPipe<z__default.ZodString, z__default.ZodTransform<"integer" | "blob" | "text" | "real" | "numeric" | "serial", string>>;
|
|
1993
|
+
notnull: z__default.ZodCoercedBoolean<unknown>;
|
|
1994
|
+
dflt_value: z__default.ZodNullable<z__default.ZodString>;
|
|
1995
|
+
pk: z__default.ZodNullable<z__default.ZodCoercedBoolean<unknown>>;
|
|
1996
|
+
}, z__default.core.$strip>>;
|
|
1997
|
+
type Columns = z__default.infer<typeof ColumnsSchema>;
|
|
1998
|
+
declare const ForeignKeySchema: z__default.ZodObject<{
|
|
1999
|
+
id: z__default.ZodNumber;
|
|
2000
|
+
table: z__default.ZodString;
|
|
2001
|
+
from: z__default.ZodString;
|
|
2002
|
+
to: z__default.ZodString;
|
|
2003
|
+
}, z__default.core.$strip>;
|
|
2004
|
+
type ForeignKey = z__default.infer<typeof ForeignKeySchema>;
|
|
2005
|
+
declare const ForeignKeysSchema: z__default.ZodArray<z__default.ZodObject<{
|
|
2006
|
+
id: z__default.ZodNumber;
|
|
2007
|
+
table: z__default.ZodString;
|
|
2008
|
+
from: z__default.ZodString;
|
|
2009
|
+
to: z__default.ZodString;
|
|
2010
|
+
}, z__default.core.$strip>>;
|
|
2011
|
+
type ForeignKeys = z__default.infer<typeof ForeignKeysSchema>;
|
|
2012
|
+
declare const BuildSchema: z__default.ZodObject<{
|
|
2013
|
+
name: z__default.ZodString;
|
|
2014
|
+
createdAt: z__default.ZodOptional<z__default.ZodString>;
|
|
2015
|
+
tags: z__default.ZodOptional<z__default.ZodRecord<z__default.ZodString, z__default.ZodString>>;
|
|
2016
|
+
}, z__default.core.$strip>;
|
|
2017
|
+
type Build = z__default.infer<typeof BuildSchema>;
|
|
2018
|
+
declare const BuildsSchema: z__default.ZodArray<z__default.ZodObject<{
|
|
2019
|
+
name: z__default.ZodString;
|
|
2020
|
+
createdAt: z__default.ZodOptional<z__default.ZodString>;
|
|
2021
|
+
tags: z__default.ZodOptional<z__default.ZodRecord<z__default.ZodString, z__default.ZodString>>;
|
|
2022
|
+
}, z__default.core.$strip>>;
|
|
2023
|
+
type Builds = z__default.infer<typeof BuildsSchema>;
|
|
2024
|
+
declare const CreateActorSchema: z__default.ZodObject<{
|
|
2025
|
+
name: z__default.ZodString;
|
|
2026
|
+
key: z__default.ZodArray<z__default.ZodString>;
|
|
2027
|
+
input: z__default.ZodAny;
|
|
2028
|
+
}, z__default.core.$strip>;
|
|
2029
|
+
type CreateActor = z__default.infer<typeof CreateActorSchema>;
|
|
2030
|
+
|
|
2031
|
+
interface ActorInspectorAccessors {
|
|
2032
|
+
isStateEnabled: () => Promise<boolean>;
|
|
2033
|
+
getState: () => Promise<unknown>;
|
|
2034
|
+
setState: (state: unknown) => Promise<void>;
|
|
2035
|
+
isDbEnabled: () => Promise<boolean>;
|
|
2036
|
+
getDb: () => Promise<InferDatabaseClient<AnyDatabaseProvider>>;
|
|
2037
|
+
getRpcs: () => Promise<string[]>;
|
|
2038
|
+
getConnections: () => Promise<Connection[]>;
|
|
2039
|
+
}
|
|
2040
|
+
interface ActorInspectorEmitterEvents {
|
|
2041
|
+
stateUpdated: (state: unknown) => void;
|
|
2042
|
+
connectionUpdated: () => void;
|
|
2043
|
+
eventFired: (event: RealtimeEvent) => void;
|
|
1740
2044
|
}
|
|
1741
2045
|
/**
|
|
1742
|
-
*
|
|
1743
|
-
* without establishing a persistent connection.
|
|
1744
|
-
*
|
|
1745
|
-
* @example
|
|
1746
|
-
* ```
|
|
1747
|
-
* const room = client.get<ChatRoom>(...etc...);
|
|
1748
|
-
* // This calls the action named `sendMessage` on the `ChatRoom` actor without a connection.
|
|
1749
|
-
* await room.sendMessage('Hello, world!');
|
|
1750
|
-
* ```
|
|
1751
|
-
*
|
|
1752
|
-
* Private methods (e.g. those starting with `_`) are automatically excluded.
|
|
1753
|
-
*
|
|
1754
|
-
* @template AD The actor class that this handle is for.
|
|
1755
|
-
* @see {@link ActorHandleRaw}
|
|
2046
|
+
* Provides a unified interface for inspecting actor external and internal state.
|
|
1756
2047
|
*/
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
2048
|
+
declare class ActorInspector {
|
|
2049
|
+
#private;
|
|
2050
|
+
readonly accessors: ActorInspectorAccessors;
|
|
2051
|
+
readonly emitter: nanoevents.Emitter<ActorInspectorEmitterEvents>;
|
|
2052
|
+
get lastRealtimeEvents(): (({
|
|
2053
|
+
type: "action";
|
|
2054
|
+
name: string;
|
|
2055
|
+
args: any[];
|
|
2056
|
+
connId: string;
|
|
2057
|
+
} | {
|
|
2058
|
+
type: "broadcast";
|
|
2059
|
+
eventName: string;
|
|
2060
|
+
args: any[];
|
|
2061
|
+
} | {
|
|
2062
|
+
type: "subscribe";
|
|
2063
|
+
eventName: string;
|
|
2064
|
+
connId: string;
|
|
2065
|
+
} | {
|
|
2066
|
+
type: "unsubscribe";
|
|
2067
|
+
eventName: string;
|
|
2068
|
+
connId: string;
|
|
2069
|
+
} | {
|
|
2070
|
+
type: "event";
|
|
2071
|
+
eventName: string;
|
|
2072
|
+
args: any[];
|
|
2073
|
+
connId: string;
|
|
2074
|
+
}) & {
|
|
2075
|
+
id: string;
|
|
2076
|
+
timestamp: number;
|
|
2077
|
+
})[];
|
|
2078
|
+
constructor(accessors: () => ActorInspectorAccessors);
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
interface ConnSocket {
|
|
2082
|
+
socketId: string;
|
|
2083
|
+
driverState: ConnDriverState;
|
|
2084
|
+
}
|
|
1761
2085
|
|
|
1762
|
-
/** Extract the actor registry from the registry definition. */
|
|
1763
|
-
type ExtractActorsFromRegistry<A extends Registry<any>> = A extends Registry<infer Actors> ? Actors : never;
|
|
1764
|
-
/** Extract the registry definition from the client. */
|
|
1765
|
-
type ExtractRegistryFromClient<C extends Client<Registry<{}>>> = C extends Client<infer A> ? A : never;
|
|
1766
2086
|
/**
|
|
1767
|
-
*
|
|
2087
|
+
* Options for the `_saveState` method.
|
|
1768
2088
|
*/
|
|
1769
|
-
interface
|
|
2089
|
+
interface SaveStateOptions {
|
|
2090
|
+
/**
|
|
2091
|
+
* Forces the state to be saved immediately. This function will return when the state has saved successfully.
|
|
2092
|
+
*/
|
|
2093
|
+
immediate?: boolean;
|
|
2094
|
+
/** Bypass ready check for stopping. */
|
|
2095
|
+
allowStoppingState?: boolean;
|
|
2096
|
+
}
|
|
2097
|
+
/** Actor type alias with all `any` types. Used for `extends` in classes referencing this actor. */
|
|
2098
|
+
type AnyActorInstance = ActorInstance<any, any, any, any, any, any>;
|
|
2099
|
+
declare class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
2100
|
+
#private;
|
|
2101
|
+
actorContext: ActorContext<S, CP, CS, V, I, DB>;
|
|
2102
|
+
get isStopping(): boolean;
|
|
2103
|
+
get id(): string;
|
|
2104
|
+
get inlineClient(): Client<Registry<any>>;
|
|
2105
|
+
get inspector(): ActorInspector;
|
|
1770
2106
|
/**
|
|
1771
|
-
*
|
|
1772
|
-
* The actor name is automatically injected from the property accessor.
|
|
2107
|
+
* This constructor should never be used directly.
|
|
1773
2108
|
*
|
|
1774
|
-
*
|
|
1775
|
-
*
|
|
1776
|
-
* @
|
|
1777
|
-
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2109
|
+
* Constructed in {@link ActorInstance.start}.
|
|
2110
|
+
*
|
|
2111
|
+
* @private
|
|
1778
2112
|
*/
|
|
1779
|
-
|
|
2113
|
+
constructor(config: ActorConfig<S, CP, CS, V, I, DB>);
|
|
2114
|
+
start(actorDriver: ActorDriver, inlineClient: Client<Registry<any>>, actorId: string, name: string, key: ActorKey, region: string): Promise<void>;
|
|
2115
|
+
_onAlarm(): Promise<void>;
|
|
2116
|
+
scheduleEvent(timestamp: number, action: string, args: unknown[]): Promise<void>;
|
|
2117
|
+
get stateEnabled(): boolean;
|
|
2118
|
+
get connStateEnabled(): boolean;
|
|
2119
|
+
__getConnForId(id: string): Conn<S, CP, CS, V, I, DB> | undefined;
|
|
1780
2120
|
/**
|
|
1781
|
-
*
|
|
1782
|
-
* The actor name is automatically injected from the property accessor.
|
|
2121
|
+
* Connection disconnected.
|
|
1783
2122
|
*
|
|
1784
|
-
*
|
|
1785
|
-
*
|
|
1786
|
-
*
|
|
1787
|
-
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2123
|
+
* If a clean diconnect, will be removed immediately.
|
|
2124
|
+
*
|
|
2125
|
+
* If not a clean disconnect, will keep the connection alive for a given interval to wait for reconnect.
|
|
1788
2126
|
*/
|
|
1789
|
-
|
|
2127
|
+
__connDisconnected(conn: Conn<S, CP, CS, V, I, DB>, wasClean: boolean, socketId: string): void;
|
|
1790
2128
|
/**
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
* @template AD The actor class that this handle is for.
|
|
1794
|
-
* @param {string} actorId - The ID of the actor.
|
|
1795
|
-
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1796
|
-
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2129
|
+
* Called to create a new connection or reconnect an existing one.
|
|
1797
2130
|
*/
|
|
1798
|
-
|
|
2131
|
+
createConn(socket: ConnSocket, params: any, request?: Request, connectionId?: string, connectionToken?: string): Promise<Conn<S, CP, CS, V, I, DB>>;
|
|
2132
|
+
processMessage(message: ToServer, conn: Conn<S, CP, CS, V, I, DB>): Promise<void>;
|
|
1799
2133
|
/**
|
|
1800
|
-
*
|
|
1801
|
-
* and returns a stateless handle to it with the actor ID resolved.
|
|
1802
|
-
*
|
|
1803
|
-
* @template AD The actor class that this handle is for.
|
|
1804
|
-
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
1805
|
-
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
1806
|
-
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
2134
|
+
* Check if the actor is ready to handle requests.
|
|
1807
2135
|
*/
|
|
1808
|
-
|
|
1809
|
-
}
|
|
1810
|
-
/**
|
|
1811
|
-
* Options for querying actors.
|
|
1812
|
-
* @typedef {Object} QueryOptions
|
|
1813
|
-
* @property {unknown} [parameters] - Parameters to pass to the connection.
|
|
1814
|
-
*/
|
|
1815
|
-
interface QueryOptions {
|
|
1816
|
-
/** Parameters to pass to the connection. */
|
|
1817
|
-
params?: unknown;
|
|
1818
|
-
/** Signal to abort the request. */
|
|
1819
|
-
signal?: AbortSignal;
|
|
1820
|
-
}
|
|
1821
|
-
/**
|
|
1822
|
-
* Options for getting a actor by ID.
|
|
1823
|
-
* @typedef {QueryOptions} GetWithIdOptions
|
|
1824
|
-
*/
|
|
1825
|
-
interface GetWithIdOptions extends QueryOptions {
|
|
1826
|
-
}
|
|
1827
|
-
/**
|
|
1828
|
-
* Options for getting a actor.
|
|
1829
|
-
* @typedef {QueryOptions} GetOptions
|
|
1830
|
-
*/
|
|
1831
|
-
interface GetOptions extends QueryOptions {
|
|
1832
|
-
}
|
|
1833
|
-
/**
|
|
1834
|
-
* Options for getting or creating a actor.
|
|
1835
|
-
* @typedef {QueryOptions} GetOrCreateOptions
|
|
1836
|
-
* @property {string} [createInRegion] - Region to create the actor in if it doesn't exist.
|
|
1837
|
-
*/
|
|
1838
|
-
interface GetOrCreateOptions extends QueryOptions {
|
|
1839
|
-
/** Region to create the actor in if it doesn't exist. */
|
|
1840
|
-
createInRegion?: string;
|
|
1841
|
-
/** Input data to pass to the actor. */
|
|
1842
|
-
createWithInput?: unknown;
|
|
1843
|
-
}
|
|
1844
|
-
/**
|
|
1845
|
-
* Options for creating a actor.
|
|
1846
|
-
* @typedef {QueryOptions} CreateOptions
|
|
1847
|
-
* @property {string} [region] - The region to create the actor in.
|
|
1848
|
-
*/
|
|
1849
|
-
interface CreateOptions extends QueryOptions {
|
|
1850
|
-
/** The region to create the actor in. */
|
|
1851
|
-
region?: string;
|
|
1852
|
-
/** Input data to pass to the actor. */
|
|
1853
|
-
input?: unknown;
|
|
1854
|
-
}
|
|
1855
|
-
/**
|
|
1856
|
-
* Represents a region to connect to.
|
|
1857
|
-
* @typedef {Object} Region
|
|
1858
|
-
* @property {string} id - The region ID.
|
|
1859
|
-
* @property {string} name - The region name.
|
|
1860
|
-
* @see {@link https://rivet.dev/docs/edge|Edge Networking}
|
|
1861
|
-
* @see {@link https://rivet.dev/docs/regions|Available Regions}
|
|
1862
|
-
*/
|
|
1863
|
-
interface Region {
|
|
2136
|
+
isReady(): boolean;
|
|
1864
2137
|
/**
|
|
1865
|
-
*
|
|
2138
|
+
* Returns a list of action methods available on this actor.
|
|
1866
2139
|
*/
|
|
1867
|
-
|
|
2140
|
+
get actions(): string[];
|
|
1868
2141
|
/**
|
|
1869
|
-
*
|
|
2142
|
+
* Handles raw HTTP requests to the actor.
|
|
1870
2143
|
*/
|
|
1871
|
-
|
|
1872
|
-
}
|
|
1873
|
-
declare const ACTOR_CONNS_SYMBOL: unique symbol;
|
|
1874
|
-
declare const CREATE_ACTOR_CONN_PROXY: unique symbol;
|
|
1875
|
-
declare const TRANSPORT_SYMBOL: unique symbol;
|
|
1876
|
-
/**
|
|
1877
|
-
* Client for managing & connecting to actors.
|
|
1878
|
-
*
|
|
1879
|
-
* @template A The actors map type that defines the available actors.
|
|
1880
|
-
* @see {@link https://rivet.dev/docs/manage|Create & Manage Actors}
|
|
1881
|
-
*/
|
|
1882
|
-
declare class ClientRaw {
|
|
1883
|
-
#private;
|
|
1884
|
-
[ACTOR_CONNS_SYMBOL]: Set<ActorConnRaw>;
|
|
1885
|
-
[TRANSPORT_SYMBOL]: Transport;
|
|
2144
|
+
handleFetch(request: Request, opts: Record<never, never>): Promise<Response>;
|
|
1886
2145
|
/**
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
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}
|
|
2146
|
+
* Handles raw WebSocket connections to the actor.
|
|
1892
2147
|
*/
|
|
1893
|
-
|
|
2148
|
+
handleWebSocket(websocket: UniversalWebSocket, opts: {
|
|
2149
|
+
request: Request;
|
|
2150
|
+
}): Promise<void>;
|
|
2151
|
+
get log(): Logger;
|
|
2152
|
+
get rLog(): Logger;
|
|
1894
2153
|
/**
|
|
1895
|
-
* Gets
|
|
1896
|
-
*
|
|
1897
|
-
* @template AD The actor class that this handle is for.
|
|
1898
|
-
* @param {string} name - The name of the actor.
|
|
1899
|
-
* @param {string} actorId - The ID of the actor.
|
|
1900
|
-
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1901
|
-
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2154
|
+
* Gets the name.
|
|
1902
2155
|
*/
|
|
1903
|
-
|
|
2156
|
+
get name(): string;
|
|
1904
2157
|
/**
|
|
1905
|
-
* Gets
|
|
1906
|
-
*
|
|
1907
|
-
* @template AD The actor class that this handle is for.
|
|
1908
|
-
* @param {string} name - The name of the actor.
|
|
1909
|
-
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
1910
|
-
* @param {GetWithIdOptions} [opts] - Options for getting the actor.
|
|
1911
|
-
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2158
|
+
* Gets the key.
|
|
1912
2159
|
*/
|
|
1913
|
-
get
|
|
2160
|
+
get key(): ActorKey;
|
|
1914
2161
|
/**
|
|
1915
|
-
* Gets
|
|
1916
|
-
*
|
|
1917
|
-
* @template AD The actor class that this handle is for.
|
|
1918
|
-
* @param {string} name - The name of the actor.
|
|
1919
|
-
* @param {string | string[]} [key=[]] - The key to identify the actor. Can be a single string or an array of strings.
|
|
1920
|
-
* @param {GetOptions} [opts] - Options for getting the actor.
|
|
1921
|
-
* @returns {ActorHandle<AD>} - A handle to the actor.
|
|
2162
|
+
* Gets the region.
|
|
1922
2163
|
*/
|
|
1923
|
-
|
|
2164
|
+
get region(): string;
|
|
1924
2165
|
/**
|
|
1925
|
-
*
|
|
1926
|
-
* Resolves the actor ID and returns a handle with getForId query.
|
|
1927
|
-
*
|
|
1928
|
-
* @template AD The actor class that this handle is for.
|
|
1929
|
-
* @param {string} name - The name of the actor.
|
|
1930
|
-
* @param {string | string[]} key - The key to identify the actor. Can be a single string or an array of strings.
|
|
1931
|
-
* @param {CreateOptions} [opts] - Options for creating the actor (excluding name and key).
|
|
1932
|
-
* @returns {Promise<ActorHandle<AD>>} - A promise that resolves to a handle to the actor.
|
|
2166
|
+
* Gets the scheduler.
|
|
1933
2167
|
*/
|
|
1934
|
-
|
|
1935
|
-
[CREATE_ACTOR_CONN_PROXY]<AD extends AnyActorDefinition>(conn: ActorConnRaw): ActorConn<AD>;
|
|
2168
|
+
get schedule(): Schedule;
|
|
1936
2169
|
/**
|
|
1937
|
-
*
|
|
2170
|
+
* Gets the map of connections.
|
|
2171
|
+
*/
|
|
2172
|
+
get conns(): Map<ConnId, Conn<S, CP, CS, V, I, DB>>;
|
|
2173
|
+
/**
|
|
2174
|
+
* Gets the current state.
|
|
1938
2175
|
*
|
|
1939
|
-
*
|
|
2176
|
+
* Changing properties of this value will automatically be persisted.
|
|
1940
2177
|
*/
|
|
1941
|
-
|
|
1942
|
-
}
|
|
1943
|
-
/**
|
|
1944
|
-
* Client type with actor accessors.
|
|
1945
|
-
* This adds property accessors for actor names to the ClientRaw base class.
|
|
1946
|
-
*
|
|
1947
|
-
* @template A The actor registry type.
|
|
1948
|
-
*/
|
|
1949
|
-
type Client<A extends Registry<any>> = ClientRaw & {
|
|
1950
|
-
[K in keyof ExtractActorsFromRegistry<A>]: ActorAccessor<ExtractActorsFromRegistry<A>[K]>;
|
|
1951
|
-
};
|
|
1952
|
-
type AnyClient = Client<Registry<any>>;
|
|
1953
|
-
declare function createClientWithDriver<A extends Registry<any>>(driver: ManagerDriver, config?: ClientConfig): Client<A>;
|
|
1954
|
-
|
|
1955
|
-
type ConnectionDriversMap = Record<ConnectionDriver, ConnDriver>;
|
|
1956
|
-
type ActorDriverBuilder = (registryConfig: RegistryConfig, runConfig: RunConfig, managerDriver: ManagerDriver, inlineClient: AnyClient) => ActorDriver;
|
|
1957
|
-
interface ActorDriver {
|
|
1958
|
-
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
1959
|
-
getGenericConnGlobalState(actorId: string): GenericConnGlobalState;
|
|
1960
|
-
getContext(actorId: string): unknown;
|
|
1961
|
-
readPersistedData(actorId: string): Promise<Uint8Array | undefined>;
|
|
1962
|
-
/** ActorInstance ensure that only one instance of writePersistedData is called in parallel at a time. */
|
|
1963
|
-
writePersistedData(actorId: string, data: Uint8Array): Promise<void>;
|
|
1964
|
-
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
1965
|
-
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
2178
|
+
get state(): S;
|
|
1966
2179
|
/**
|
|
2180
|
+
* Gets the database.
|
|
1967
2181
|
* @experimental
|
|
1968
|
-
*
|
|
2182
|
+
* @throws {DatabaseNotEnabled} If the database is not enabled.
|
|
1969
2183
|
*/
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
2184
|
+
get db(): InferDatabaseClient<DB>;
|
|
2185
|
+
/**
|
|
2186
|
+
* Sets the current state.
|
|
2187
|
+
*
|
|
2188
|
+
* This property will automatically be persisted.
|
|
2189
|
+
*/
|
|
2190
|
+
set state(value: S);
|
|
2191
|
+
get vars(): V;
|
|
2192
|
+
/**
|
|
2193
|
+
* Broadcasts an event to all connected clients.
|
|
2194
|
+
* @param name - The name of the event.
|
|
2195
|
+
* @param args - The arguments to send with the event.
|
|
2196
|
+
*/
|
|
2197
|
+
_broadcast<Args extends Array<unknown>>(name: string, ...args: Args): void;
|
|
1983
2198
|
/**
|
|
1984
|
-
*
|
|
2199
|
+
* Prevents the actor from sleeping until promise is complete.
|
|
2200
|
+
*
|
|
2201
|
+
* This allows the actor runtime to ensure that a promise completes while
|
|
2202
|
+
* returning from an action request early.
|
|
2203
|
+
*
|
|
2204
|
+
* @param promise - The promise to run in the background.
|
|
1985
2205
|
*/
|
|
1986
|
-
|
|
2206
|
+
_waitUntil(promise: Promise<void>): void;
|
|
1987
2207
|
/**
|
|
1988
|
-
*
|
|
1989
|
-
*
|
|
2208
|
+
* Forces the state to get saved.
|
|
2209
|
+
*
|
|
2210
|
+
* This is helpful if running a long task that may fail later or when
|
|
2211
|
+
* running a background job that updates the state.
|
|
2212
|
+
*
|
|
2213
|
+
* @param opts - Options for saving the state.
|
|
1990
2214
|
*/
|
|
1991
|
-
|
|
2215
|
+
saveState(opts: SaveStateOptions): Promise<void>;
|
|
2216
|
+
/** 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). */
|
|
2217
|
+
_sleep(): Promise<void>;
|
|
2218
|
+
_stop(): Promise<void>;
|
|
2219
|
+
/** Abort signal that fires when the actor is stopping. */
|
|
2220
|
+
get abortSignal(): AbortSignal;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
declare enum ConnDriverKind {
|
|
2224
|
+
WEBSOCKET = 0,
|
|
2225
|
+
SSE = 1,
|
|
2226
|
+
HTTP = 2
|
|
1992
2227
|
}
|
|
2228
|
+
interface ConnDriverWebSocketState {
|
|
2229
|
+
encoding: Encoding;
|
|
2230
|
+
websocket: WSContext;
|
|
2231
|
+
closePromise: ReturnType<typeof promiseWithResolvers<void>>;
|
|
2232
|
+
}
|
|
2233
|
+
interface ConnDriverSseState {
|
|
2234
|
+
encoding: Encoding;
|
|
2235
|
+
stream: SSEStreamingApi;
|
|
2236
|
+
}
|
|
2237
|
+
type ConnDriverHttpState = Record<never, never>;
|
|
2238
|
+
type ConnDriverState = {
|
|
2239
|
+
[ConnDriverKind.WEBSOCKET]: ConnDriverWebSocketState;
|
|
2240
|
+
} | {
|
|
2241
|
+
[ConnDriverKind.SSE]: ConnDriverSseState;
|
|
2242
|
+
} | {
|
|
2243
|
+
[ConnDriverKind.HTTP]: ConnDriverHttpState;
|
|
2244
|
+
};
|
|
1993
2245
|
|
|
1994
2246
|
/** Object representing connection that gets persisted to storage. */
|
|
1995
2247
|
interface PersistedConn<CP, CS> {
|
|
1996
2248
|
connId: string;
|
|
1997
2249
|
token: string;
|
|
1998
|
-
connDriver: ConnectionDriver;
|
|
1999
|
-
connDriverState: unknown;
|
|
2000
2250
|
params: CP;
|
|
2001
2251
|
state: CS;
|
|
2002
|
-
authData?: unknown;
|
|
2003
2252
|
subscriptions: PersistedSubscription[];
|
|
2253
|
+
/** Last time the socket was seen. This is set when disconencted so we can determine when we need to clean this up. */
|
|
2004
2254
|
lastSeen: number;
|
|
2005
2255
|
}
|
|
2006
2256
|
interface PersistedSubscription {
|
|
@@ -2010,11 +2260,6 @@ interface PersistedSubscription {
|
|
|
2010
2260
|
declare function generateConnId(): string;
|
|
2011
2261
|
declare function generateConnToken(): string;
|
|
2012
2262
|
type ConnId = string;
|
|
2013
|
-
type AnyConn = Conn<any, any, any, any, any, any>;
|
|
2014
|
-
declare const CONNECTION_DRIVER_WEBSOCKET = "webSocket";
|
|
2015
|
-
declare const CONNECTION_DRIVER_SSE = "sse";
|
|
2016
|
-
declare const CONNECTION_DRIVER_HTTP = "http";
|
|
2017
|
-
type ConnectionDriver = typeof CONNECTION_DRIVER_WEBSOCKET | typeof CONNECTION_DRIVER_SSE | typeof CONNECTION_DRIVER_HTTP;
|
|
2018
2263
|
type ConnectionStatus = "connected" | "reconnecting";
|
|
2019
2264
|
/**
|
|
2020
2265
|
* Represents a client connection to a actor.
|
|
@@ -2032,9 +2277,16 @@ declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
2032
2277
|
* Any data that should be stored indefinitely should be held within this object.
|
|
2033
2278
|
*/
|
|
2034
2279
|
__persist: PersistedConn<CP, CS>;
|
|
2280
|
+
get __driverState(): ConnDriverState | undefined;
|
|
2281
|
+
/**
|
|
2282
|
+
* Socket connected to this connection.
|
|
2283
|
+
*
|
|
2284
|
+
* If undefined, then nothing is connected to this.
|
|
2285
|
+
*/
|
|
2286
|
+
__socket?: ConnSocket;
|
|
2287
|
+
get __status(): ConnectionStatus;
|
|
2035
2288
|
get params(): CP;
|
|
2036
|
-
get
|
|
2037
|
-
get _stateEnabled(): boolean;
|
|
2289
|
+
get __stateEnabled(): boolean;
|
|
2038
2290
|
/**
|
|
2039
2291
|
* Gets the current state of the connection.
|
|
2040
2292
|
*
|
|
@@ -2070,7 +2322,7 @@ declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
2070
2322
|
*
|
|
2071
2323
|
* @protected
|
|
2072
2324
|
*/
|
|
2073
|
-
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>, persist: PersistedConn<CP, CS
|
|
2325
|
+
constructor(actor: ActorInstance<S, CP, CS, V, I, DB>, persist: PersistedConn<CP, CS>);
|
|
2074
2326
|
/**
|
|
2075
2327
|
* Sends a WebSocket message to the client.
|
|
2076
2328
|
*
|
|
@@ -2095,4 +2347,4 @@ declare class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
2095
2347
|
disconnect(reason?: string): Promise<void>;
|
|
2096
2348
|
}
|
|
2097
2349
|
|
|
2098
|
-
export {
|
|
2350
|
+
export { type ActorHandle as $, type ActorDriver as A, test as B, type Client as C, type DriverConfig as D, type Encoding as E, type RegistryConfig as F, type RegistryActors as G, type RunConfigInput as H, type InitContext as I, RegistryConfigSchema as J, Registry as K, setup as L, type ClientConfigInput as M, ActorClientError as N, type OnConnectOptions as O, ActorError as P, InternalError as Q, type RivetEvent as R, MalformedResponseMessage as S, type Transport as T, type UniversalWebSocket as U, ManagerError as V, type CreateRequest as W, type ActorActionFunction as X, type ActorConn as Y, type EventUnsubscribe as Z, ActorConnRaw as _, type RivetCloseEvent as a, ActorHandleRaw as a0, type ActorAccessor as a1, ClientRaw as a2, type CreateOptions as a3, type ExtractActorsFromRegistry as a4, type ExtractRegistryFromClient as a5, type GetOptions as a6, type GetWithIdOptions as a7, type QueryOptions as a8, type Region as a9, type DatabaseQuery as aA, TableSchema as aB, type Table as aC, TablesSchema as aD, type Tables as aE, ColumnSchema as aF, type Column as aG, ColumnsSchema as aH, type Columns as aI, ForeignKeySchema as aJ, type ForeignKey as aK, ForeignKeysSchema as aL, type ForeignKeys as aM, BuildSchema as aN, type Build as aO, BuildsSchema as aP, type Builds as aQ, CreateActorSchema as aR, type CreateActor as aS, ActorInstance as aa, type ActorOutput as ab, type CreateInput as ac, type GetForIdInput as ad, type GetOrCreateWithKeyInput as ae, type GetWithKeyInput as af, type ManagerDisplayInformation as ag, type ManagerDriver as ah, DriverConfigSchema as ai, RunConfigSchema as aj, ActorFeature as ak, ActorId as al, ActorLogEntry as am, ActorSchema as an, type Actor as ao, OperationSchema as ap, type Operation as aq, PatchSchema as ar, type Patch as as, ConnectionSchema as at, type Connection as au, RealtimeEventSchema as av, type RealtimeEvent as aw, RecordedRealtimeEventSchema as ax, type RecordedRealtimeEvent as ay, DatabaseQuerySchema as az, type RivetMessageEvent as b, type RunConfig as c, type AnyDatabaseProvider as d, type Actions as e, type ActorConfigInput as f, ActorDefinition as g, generateConnId as h, generateConnToken as i, type AnyClient as j, createClientWithDriver as k, type ActorQuery as l, type ActorKey as m, ActionContext as n, Conn as o, type ConnectionStatus as p, ActorContext as q, type ActionContextOf as r, type ActorContextOf as s, type AnyActorDefinition as t, lookupInRegistry as u, type AnyActorInstance as v, type ActorTypes as w, ActorConfigSchema as x, type AuthIntent as y, type ActorConfig as z };
|