rivetkit 2.0.5 → 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-5YTI25C3.cjs → chunk-3MBP4WNC.cjs} +7 -7
- package/dist/tsup/{chunk-5YTI25C3.cjs.map → chunk-3MBP4WNC.cjs.map} +1 -1
- package/dist/tsup/chunk-3Y45CIF4.cjs +3726 -0
- 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-5ZOHIKWG.cjs +4071 -0
- package/dist/tsup/chunk-5ZOHIKWG.cjs.map +1 -0
- package/dist/tsup/{chunk-WADSS5X4.cjs → chunk-6EUWRXLT.cjs} +21 -7
- package/dist/tsup/chunk-6EUWRXLT.cjs.map +1 -0
- package/dist/tsup/{chunk-D7NWUCRK.cjs → chunk-6OVKCDSH.cjs} +6 -6
- package/dist/tsup/{chunk-D7NWUCRK.cjs.map → chunk-6OVKCDSH.cjs.map} +1 -1
- package/dist/tsup/{chunk-I5VTWPHW.js → chunk-7N56ZUC7.js} +3 -3
- package/dist/tsup/{chunk-LZIBTLEY.cjs → chunk-B3TLRM4Q.cjs} +13 -25
- package/dist/tsup/chunk-B3TLRM4Q.cjs.map +1 -0
- package/dist/tsup/chunk-BW5DPM6Z.js +4071 -0
- package/dist/tsup/chunk-BW5DPM6Z.js.map +1 -0
- package/dist/tsup/chunk-DFS77KAA.cjs +1046 -0
- package/dist/tsup/chunk-DFS77KAA.cjs.map +1 -0
- package/dist/tsup/{chunk-PG3K2LI7.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-CKA54YQN.js → chunk-GZVBFXBI.js} +3 -15
- package/dist/tsup/chunk-GZVBFXBI.js.map +1 -0
- package/dist/tsup/chunk-HPT3I7UU.js +3726 -0
- package/dist/tsup/chunk-HPT3I7UU.js.map +1 -0
- package/dist/tsup/chunk-JD54PXWP.js +1046 -0
- package/dist/tsup/chunk-JD54PXWP.js.map +1 -0
- package/dist/tsup/{chunk-PHSQJ6QI.cjs → chunk-K4ENQCC4.cjs} +3 -3
- package/dist/tsup/{chunk-PHSQJ6QI.cjs.map → chunk-K4ENQCC4.cjs.map} +1 -1
- package/dist/tsup/{chunk-WNGOBAA7.js → chunk-PUSQNDJG.js} +2 -2
- package/dist/tsup/{chunk-CFFKMUYH.js → chunk-RVP5RUSC.js} +20 -6
- package/dist/tsup/chunk-RVP5RUSC.js.map +1 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs +259 -0
- package/dist/tsup/chunk-SAZCNSVY.cjs.map +1 -0
- package/dist/tsup/{chunk-YW6Y6VNE.js → chunk-SBKRVQS2.js} +9 -5
- package/dist/tsup/chunk-SBKRVQS2.js.map +1 -0
- package/dist/tsup/{chunk-FGFT4FVX.cjs → chunk-TZGUSEIJ.cjs} +14 -10
- package/dist/tsup/chunk-TZGUSEIJ.cjs.map +1 -0
- package/dist/tsup/chunk-YQ4XQYPM.js +259 -0
- 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-BvE-Oq7t.d.ts → conn-DCSQgIlw.d.ts} +1605 -1353
- package/dist/tsup/{connection-DTzmWwU5.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 +319 -216
- 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 +588 -485
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +17 -5
- 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 +20 -8
- package/dist/tsup/mod.cjs +10 -17
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +56 -9
- package/dist/tsup/mod.d.ts +56 -9
- package/dist/tsup/mod.js +17 -24
- package/dist/tsup/test/mod.cjs +11 -9
- package/dist/tsup/test/mod.cjs.map +1 -1
- 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 -8
- 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 +6 -14
- package/src/actor/persisted.ts +2 -5
- package/src/actor/protocol/old.ts +1 -1
- package/src/actor/router-endpoints.ts +147 -138
- package/src/actor/router.ts +89 -52
- package/src/actor/utils.ts +5 -1
- package/src/client/actor-conn.ts +163 -31
- package/src/client/actor-handle.ts +0 -1
- package/src/client/client.ts +2 -2
- package/src/client/config.ts +7 -0
- package/src/client/raw-utils.ts +1 -1
- package/src/client/utils.ts +1 -1
- package/src/common/actor-router-consts.ts +59 -0
- package/src/common/router.ts +2 -1
- package/src/common/versioned-data.ts +5 -5
- package/src/driver-helpers/mod.ts +15 -2
- package/src/driver-test-suite/mod.ts +11 -2
- package/src/driver-test-suite/test-inline-client-driver.ts +40 -22
- 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 +8 -3
- package/src/drivers/default.ts +8 -7
- package/src/drivers/engine/actor-driver.ts +67 -44
- 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 +12 -2
- package/src/manager/gateway.ts +407 -0
- package/src/manager/protocol/query.ts +1 -1
- 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 +126 -12
- package/src/registry/serve.ts +8 -3
- package/src/remote-manager-driver/actor-http-client.ts +30 -19
- package/src/remote-manager-driver/actor-websocket-client.ts +45 -18
- 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 +53 -53
- 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/chunk-2MD57QF4.js +0 -1794
- package/dist/tsup/chunk-2MD57QF4.js.map +0 -1
- package/dist/tsup/chunk-B2QGJGZQ.js +0 -338
- package/dist/tsup/chunk-B2QGJGZQ.js.map +0 -1
- package/dist/tsup/chunk-CFFKMUYH.js.map +0 -1
- package/dist/tsup/chunk-CKA54YQN.js.map +0 -1
- package/dist/tsup/chunk-FGFT4FVX.cjs.map +0 -1
- package/dist/tsup/chunk-IRMBWX36.cjs +0 -1794
- package/dist/tsup/chunk-IRMBWX36.cjs.map +0 -1
- package/dist/tsup/chunk-L7QRXNWP.js +0 -6562
- package/dist/tsup/chunk-L7QRXNWP.js.map +0 -1
- package/dist/tsup/chunk-LZIBTLEY.cjs.map +0 -1
- package/dist/tsup/chunk-MRZS2J4X.cjs +0 -6562
- package/dist/tsup/chunk-MRZS2J4X.cjs.map +0 -1
- package/dist/tsup/chunk-RM2SVURR.cjs +0 -338
- package/dist/tsup/chunk-RM2SVURR.cjs.map +0 -1
- package/dist/tsup/chunk-WADSS5X4.cjs.map +0 -1
- package/dist/tsup/chunk-YW6Y6VNE.js.map +0 -1
- package/dist/tsup/common-CXCe7s6i.d.cts +0 -218
- package/dist/tsup/common-CXCe7s6i.d.ts +0 -218
- package/dist/tsup/router-endpoints-CctffZNL.d.cts +0 -65
- package/dist/tsup/router-endpoints-DFm1BglJ.d.ts +0 -65
- 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-I5VTWPHW.js.map → chunk-7N56ZUC7.js.map} +0 -0
- /package/dist/tsup/{chunk-PG3K2LI7.js.map → chunk-E4UVJKSV.js.map} +0 -0
- /package/dist/tsup/{chunk-WNGOBAA7.js.map → chunk-PUSQNDJG.js.map} +0 -0
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import * as cbor from "cbor-x";
|
|
2
|
+
import invariant from "invariant";
|
|
2
3
|
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
3
4
|
import { TO_CLIENT_VERSIONED } from "@/schemas/client-protocol/versioned";
|
|
4
5
|
import { bufferToArrayBuffer } from "@/utils";
|
|
6
|
+
import {
|
|
7
|
+
CONN_DRIVERS,
|
|
8
|
+
ConnDriverKind,
|
|
9
|
+
type ConnDriverState,
|
|
10
|
+
ConnReadyState,
|
|
11
|
+
getConnDriverKindFromState,
|
|
12
|
+
} from "./conn-drivers";
|
|
13
|
+
import type { ConnSocket } from "./conn-socket";
|
|
5
14
|
import type { AnyDatabaseProvider } from "./database";
|
|
6
|
-
import { type ConnDriver, ConnectionReadyState } from "./driver";
|
|
7
15
|
import * as errors from "./errors";
|
|
8
16
|
import type { ActorInstance } from "./instance";
|
|
9
|
-
import { loggerWithoutContext } from "./log";
|
|
10
17
|
import type { PersistedConn } from "./persisted";
|
|
11
18
|
import { CachedSerializer } from "./protocol/serde";
|
|
12
19
|
import { generateSecureToken } from "./utils";
|
|
@@ -19,23 +26,16 @@ export function generateConnToken(): string {
|
|
|
19
26
|
return generateSecureToken(32);
|
|
20
27
|
}
|
|
21
28
|
|
|
29
|
+
export function generateConnSocketId(): string {
|
|
30
|
+
return crypto.randomUUID();
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
export type ConnId = string;
|
|
23
34
|
|
|
24
35
|
export type AnyConn = Conn<any, any, any, any, any, any>;
|
|
25
36
|
|
|
26
|
-
export const CONNECTION_DRIVER_WEBSOCKET = "webSocket";
|
|
27
|
-
export const CONNECTION_DRIVER_SSE = "sse";
|
|
28
|
-
export const CONNECTION_DRIVER_HTTP = "http";
|
|
29
|
-
|
|
30
|
-
export type ConnectionDriver =
|
|
31
|
-
| typeof CONNECTION_DRIVER_WEBSOCKET
|
|
32
|
-
| typeof CONNECTION_DRIVER_SSE
|
|
33
|
-
| typeof CONNECTION_DRIVER_HTTP;
|
|
34
|
-
|
|
35
37
|
export type ConnectionStatus = "connected" | "reconnecting";
|
|
36
38
|
|
|
37
|
-
export const CONNECTION_CHECK_LIVENESS_SYMBOL = Symbol("checkLiveness");
|
|
38
|
-
|
|
39
39
|
/**
|
|
40
40
|
* Represents a client connection to a actor.
|
|
41
41
|
*
|
|
@@ -46,13 +46,9 @@ export const CONNECTION_CHECK_LIVENESS_SYMBOL = Symbol("checkLiveness");
|
|
|
46
46
|
export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
47
47
|
subscriptions: Set<string> = new Set<string>();
|
|
48
48
|
|
|
49
|
-
#stateEnabled: boolean;
|
|
50
|
-
|
|
51
49
|
// TODO: Remove this cyclical reference
|
|
52
50
|
#actor: ActorInstance<S, CP, CS, V, I, DB>;
|
|
53
51
|
|
|
54
|
-
#status: ConnectionStatus = "connected";
|
|
55
|
-
|
|
56
52
|
/**
|
|
57
53
|
* The proxied state that notifies of changes automatically.
|
|
58
54
|
*
|
|
@@ -60,23 +56,31 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
60
56
|
*/
|
|
61
57
|
__persist: PersistedConn<CP, CS>;
|
|
62
58
|
|
|
59
|
+
get __driverState(): ConnDriverState | undefined {
|
|
60
|
+
return this.__socket?.driverState;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Socket connected to this connection.
|
|
65
65
|
*
|
|
66
|
-
*
|
|
66
|
+
* If undefined, then nothing is connected to this.
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
__socket?: ConnSocket;
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
get __status(): ConnectionStatus {
|
|
71
|
+
if (this.__socket) {
|
|
72
|
+
return "connected";
|
|
73
|
+
} else {
|
|
74
|
+
return "reconnecting";
|
|
75
|
+
}
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
public get
|
|
75
|
-
return this.__persist.
|
|
78
|
+
public get params(): CP {
|
|
79
|
+
return this.__persist.params;
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
public get
|
|
79
|
-
return this.#
|
|
82
|
+
public get __stateEnabled() {
|
|
83
|
+
return this.#actor.connStateEnabled;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
/**
|
|
@@ -118,7 +122,7 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
118
122
|
* Status of the connection.
|
|
119
123
|
*/
|
|
120
124
|
public get status(): ConnectionStatus {
|
|
121
|
-
return this
|
|
125
|
+
return this.__status;
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
/**
|
|
@@ -138,17 +142,13 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
138
142
|
public constructor(
|
|
139
143
|
actor: ActorInstance<S, CP, CS, V, I, DB>,
|
|
140
144
|
persist: PersistedConn<CP, CS>,
|
|
141
|
-
driver: ConnDriver,
|
|
142
|
-
stateEnabled: boolean,
|
|
143
145
|
) {
|
|
144
146
|
this.#actor = actor;
|
|
145
147
|
this.__persist = persist;
|
|
146
|
-
this.#driver = driver;
|
|
147
|
-
this.#stateEnabled = stateEnabled;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
#validateStateEnabled() {
|
|
151
|
-
if (!this
|
|
151
|
+
if (!this.__stateEnabled) {
|
|
152
152
|
throw new errors.ConnStateNotEnabled();
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -161,12 +161,28 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
161
161
|
* @protected
|
|
162
162
|
*/
|
|
163
163
|
public _sendMessage(message: CachedSerializer<protocol.ToClient>) {
|
|
164
|
-
this
|
|
165
|
-
this
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
if (this.__driverState) {
|
|
165
|
+
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
166
|
+
const driver = CONN_DRIVERS[driverKind];
|
|
167
|
+
if (driver.sendMessage) {
|
|
168
|
+
driver.sendMessage(
|
|
169
|
+
this.#actor,
|
|
170
|
+
this,
|
|
171
|
+
(this.__driverState as any)[driverKind],
|
|
172
|
+
message,
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
this.#actor.rLog.debug({
|
|
176
|
+
msg: "conn driver does not support sending messages",
|
|
177
|
+
conn: this.id,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
this.#actor.rLog.warn({
|
|
182
|
+
msg: "missing connection driver state for send message",
|
|
183
|
+
conn: this.id,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
170
186
|
}
|
|
171
187
|
|
|
172
188
|
/**
|
|
@@ -205,53 +221,31 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
|
|
|
205
221
|
* @param reason - The reason for disconnection.
|
|
206
222
|
*/
|
|
207
223
|
public async disconnect(reason?: string) {
|
|
208
|
-
this
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const newLastSeen = Date.now();
|
|
232
|
-
const newStatus = isConnectionClosed ? "reconnecting" : "connected";
|
|
233
|
-
|
|
234
|
-
this.#actor.rLog.debug({
|
|
235
|
-
msg: "liveness probe for connection",
|
|
236
|
-
connId: this.id,
|
|
237
|
-
actorId: this.#actor.id,
|
|
238
|
-
readyState,
|
|
239
|
-
|
|
240
|
-
status: this.#status,
|
|
241
|
-
newStatus,
|
|
242
|
-
|
|
243
|
-
lastSeen: this.__persist.lastSeen,
|
|
244
|
-
currentTs: newLastSeen,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
if (!isConnectionClosed) {
|
|
248
|
-
this.__persist.lastSeen = newLastSeen;
|
|
224
|
+
if (this.__socket && this.__driverState) {
|
|
225
|
+
const driverKind = getConnDriverKindFromState(this.__driverState);
|
|
226
|
+
const driver = CONN_DRIVERS[driverKind];
|
|
227
|
+
if (driver.disconnect) {
|
|
228
|
+
driver.disconnect(
|
|
229
|
+
this.#actor,
|
|
230
|
+
this,
|
|
231
|
+
(this.__driverState as any)[driverKind],
|
|
232
|
+
reason,
|
|
233
|
+
);
|
|
234
|
+
} else {
|
|
235
|
+
this.#actor.rLog.debug({
|
|
236
|
+
msg: "no disconnect handler for conn driver",
|
|
237
|
+
conn: this.id,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
this.#actor.__connDisconnected(this, true, this.__socket.socketId);
|
|
242
|
+
} else {
|
|
243
|
+
this.#actor.rLog.warn({
|
|
244
|
+
msg: "missing connection driver state for disconnect",
|
|
245
|
+
conn: this.id,
|
|
246
|
+
});
|
|
249
247
|
}
|
|
250
248
|
|
|
251
|
-
this
|
|
252
|
-
return {
|
|
253
|
-
status: this.#status,
|
|
254
|
-
lastSeen: this.__persist.lastSeen,
|
|
255
|
-
};
|
|
249
|
+
this.__socket = undefined;
|
|
256
250
|
}
|
|
257
251
|
}
|
package/src/actor/context.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ActorKey } from "@/actor/mod";
|
|
|
2
2
|
import type { Client } from "@/client/client";
|
|
3
3
|
import type { Logger } from "@/common/log";
|
|
4
4
|
import type { Registry } from "@/registry/mod";
|
|
5
|
-
import type { Conn, ConnId } from "./
|
|
5
|
+
import type { Conn, ConnId } from "./conn";
|
|
6
6
|
import type { AnyDatabaseProvider, InferDatabaseClient } from "./database";
|
|
7
7
|
import type { ActorInstance, SaveStateOptions } from "./instance";
|
|
8
8
|
import type { Schedule } from "./schedule";
|
package/src/actor/driver.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Context as HonoContext } from "hono";
|
|
2
2
|
import type { AnyClient } from "@/client/client";
|
|
3
3
|
import type { ManagerDriver } from "@/manager/driver";
|
|
4
4
|
import type { RegistryConfig } from "@/registry/config";
|
|
5
5
|
import type { RunConfig } from "@/registry/run-config";
|
|
6
|
-
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
7
|
-
import type { AnyConn, ConnectionDriver } from "./connection";
|
|
8
|
-
import type { GenericConnGlobalState } from "./generic-conn-driver";
|
|
9
6
|
import type { AnyActorInstance } from "./instance";
|
|
10
7
|
|
|
11
|
-
export type ConnectionDriversMap = Record<ConnectionDriver, ConnDriver>;
|
|
12
|
-
|
|
13
8
|
export type ActorDriverBuilder = (
|
|
14
9
|
registryConfig: RegistryConfig,
|
|
15
10
|
runConfig: RunConfig,
|
|
@@ -22,8 +17,6 @@ export interface ActorDriver {
|
|
|
22
17
|
|
|
23
18
|
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
24
19
|
|
|
25
|
-
getGenericConnGlobalState(actorId: string): GenericConnGlobalState;
|
|
26
|
-
|
|
27
20
|
getContext(actorId: string): unknown;
|
|
28
21
|
|
|
29
22
|
readPersistedData(actorId: string): Promise<Uint8Array | undefined>;
|
|
@@ -45,40 +38,8 @@ export interface ActorDriver {
|
|
|
45
38
|
sleep?(actorId: string): Promise<void>;
|
|
46
39
|
|
|
47
40
|
shutdown?(immediate: boolean): Promise<void>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export enum ConnectionReadyState {
|
|
51
|
-
UNKNOWN = -1,
|
|
52
|
-
CONNECTING = 0,
|
|
53
|
-
OPEN = 1,
|
|
54
|
-
CLOSING = 2,
|
|
55
|
-
CLOSED = 3,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface ConnDriver<ConnDriverState = unknown> {
|
|
59
|
-
sendMessage?(
|
|
60
|
-
actor: AnyActorInstance,
|
|
61
|
-
conn: AnyConn,
|
|
62
|
-
state: ConnDriverState,
|
|
63
|
-
message: CachedSerializer<protocol.ToClient>,
|
|
64
|
-
): void;
|
|
65
41
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
disconnect(
|
|
70
|
-
actor: AnyActorInstance,
|
|
71
|
-
conn: AnyConn,
|
|
72
|
-
state: ConnDriverState,
|
|
73
|
-
reason?: string,
|
|
74
|
-
): Promise<void>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Returns the ready state of the connection.
|
|
78
|
-
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
|
|
79
|
-
*/
|
|
80
|
-
getConnectionReadyState(
|
|
81
|
-
actor: AnyActorInstance,
|
|
82
|
-
conn: AnyConn,
|
|
83
|
-
): ConnectionReadyState | undefined;
|
|
42
|
+
// Serverless
|
|
43
|
+
/** This handles the serverless start request. This should manage the lifecycle of the runner tied to the request lifecycle. */
|
|
44
|
+
serverlessHandleStart?(c: HonoContext): Promise<Response>;
|
|
84
45
|
}
|