rivetkit 2.0.24-rc.1 → 2.0.25-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 +6 -0
- package/dist/schemas/actor-persist/v2.ts +9 -3
- package/dist/schemas/actor-persist/v3.ts +280 -0
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/schemas/client-protocol/v2.ts +438 -0
- package/dist/schemas/file-system-driver/v1.ts +6 -0
- package/dist/schemas/file-system-driver/v2.ts +142 -0
- package/dist/tsup/actor/errors.cjs +2 -4
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +7 -10
- package/dist/tsup/actor/errors.d.ts +7 -10
- package/dist/tsup/actor/errors.js +9 -11
- package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.cts → actor-router-consts-DzI2szci.d.cts} +5 -9
- package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.ts → actor-router-consts-DzI2szci.d.ts} +5 -9
- package/dist/tsup/{chunk-ZTH3KYFH.cjs → chunk-3FG5OJ3G.cjs} +3 -3
- package/dist/tsup/{chunk-ZTH3KYFH.cjs.map → chunk-3FG5OJ3G.cjs.map} +1 -1
- package/dist/tsup/{chunk-BLK27ES3.js → chunk-6JN6W6G3.js} +44 -56
- package/dist/tsup/chunk-6JN6W6G3.js.map +1 -0
- package/dist/tsup/chunk-7IBNNGQ2.js +514 -0
- package/dist/tsup/chunk-7IBNNGQ2.js.map +1 -0
- package/dist/tsup/{chunk-36JJ4IQB.cjs → chunk-AZATXPR4.cjs} +4 -8
- package/dist/tsup/chunk-AZATXPR4.cjs.map +1 -0
- package/dist/tsup/chunk-B7MENRD5.cjs +5694 -0
- package/dist/tsup/chunk-B7MENRD5.cjs.map +1 -0
- package/dist/tsup/{chunk-BOMZS2TJ.js → chunk-BBVFDEYD.js} +9 -9
- package/dist/tsup/chunk-BBVFDEYD.js.map +1 -0
- package/dist/tsup/{chunk-KSRXX3Z4.cjs → chunk-D6762AOA.cjs} +20 -25
- package/dist/tsup/chunk-D6762AOA.cjs.map +1 -0
- package/dist/tsup/{chunk-2JYPS5YM.cjs → chunk-E63WZNMR.cjs} +6 -6
- package/dist/tsup/chunk-E63WZNMR.cjs.map +1 -0
- package/dist/tsup/{chunk-YBG6R7LX.js → chunk-EDGN4OC7.js} +3 -7
- package/dist/tsup/chunk-EDGN4OC7.js.map +1 -0
- package/dist/tsup/{chunk-BYMKMOBS.js → chunk-FLOQ3UWM.js} +1844 -1681
- package/dist/tsup/chunk-FLOQ3UWM.js.map +1 -0
- package/dist/tsup/{chunk-7L65NNWP.cjs → chunk-H7GV5DIW.cjs} +187 -185
- package/dist/tsup/chunk-H7GV5DIW.cjs.map +1 -0
- package/dist/tsup/{chunk-227FEWMB.js → chunk-HZYZ7JSF.js} +3322 -2251
- package/dist/tsup/chunk-HZYZ7JSF.js.map +1 -0
- package/dist/tsup/{chunk-FX7TWFQR.js → chunk-IDJK7ILQ.js} +2 -6
- package/dist/tsup/chunk-IDJK7ILQ.js.map +1 -0
- package/dist/tsup/{chunk-VHGY7PU5.cjs → chunk-ILFXA4AL.cjs} +1900 -1737
- package/dist/tsup/chunk-ILFXA4AL.cjs.map +1 -0
- package/dist/tsup/chunk-MV6M3FDL.cjs +514 -0
- package/dist/tsup/chunk-MV6M3FDL.cjs.map +1 -0
- package/dist/tsup/{chunk-PLUN2NQT.js → chunk-NWBKMCWC.js} +189 -187
- package/dist/tsup/chunk-NWBKMCWC.js.map +1 -0
- package/dist/tsup/{chunk-CD33GT6Z.js → chunk-QIHBDXTO.js} +2 -2
- package/dist/tsup/{chunk-G64QUEDJ.js → chunk-W6RDS6NW.js} +23 -28
- package/dist/tsup/chunk-W6RDS6NW.js.map +1 -0
- package/dist/tsup/{chunk-INNFK746.cjs → chunk-WQU4M4ZC.cjs} +10 -14
- package/dist/tsup/chunk-WQU4M4ZC.cjs.map +1 -0
- package/dist/tsup/{chunk-SHVX2QUR.cjs → chunk-XKZA47XS.cjs} +17 -17
- package/dist/tsup/chunk-XKZA47XS.cjs.map +1 -0
- package/dist/tsup/{chunk-HHFKKVLR.cjs → chunk-YHWIOWVA.cjs} +45 -57
- package/dist/tsup/chunk-YHWIOWVA.cjs.map +1 -0
- package/dist/tsup/{chunk-YBHYXIP6.js → chunk-YVL6IRUM.js} +3 -3
- package/dist/tsup/chunk-YVL6IRUM.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.d.cts +5 -7
- package/dist/tsup/client/mod.d.ts +5 -7
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{conn-B3Vhbgnd.d.ts → config-BRDYDraU.d.cts} +1119 -1047
- package/dist/tsup/{conn-DJWL3nGx.d.cts → config-Bo-blHpJ.d.ts} +1119 -1047
- package/dist/tsup/driver-helpers/mod.cjs +5 -13
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +11 -9
- package/dist/tsup/driver-helpers/mod.d.ts +11 -9
- package/dist/tsup/driver-helpers/mod.js +14 -22
- package/dist/tsup/driver-test-suite/mod.cjs +474 -303
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +6 -9
- package/dist/tsup/driver-test-suite/mod.d.ts +6 -9
- package/dist/tsup/driver-test-suite/mod.js +1085 -914
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -6
- package/dist/tsup/inspector/mod.d.cts +5 -7
- package/dist/tsup/inspector/mod.d.ts +5 -7
- package/dist/tsup/inspector/mod.js +5 -5
- package/dist/tsup/mod.cjs +10 -16
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +23 -25
- package/dist/tsup/mod.d.ts +23 -25
- package/dist/tsup/mod.js +17 -23
- package/dist/tsup/test/mod.cjs +11 -11
- package/dist/tsup/test/mod.d.cts +4 -6
- package/dist/tsup/test/mod.d.ts +4 -6
- package/dist/tsup/test/mod.js +10 -10
- package/dist/tsup/utils.cjs +3 -5
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +1 -2
- package/dist/tsup/utils.d.ts +1 -2
- package/dist/tsup/utils.js +2 -4
- package/package.json +13 -6
- package/src/actor/config.ts +56 -44
- package/src/actor/conn/driver.ts +61 -0
- package/src/actor/conn/drivers/http.ts +17 -0
- package/src/actor/conn/drivers/raw-request.ts +24 -0
- package/src/actor/conn/drivers/raw-websocket.ts +65 -0
- package/src/actor/conn/drivers/websocket.ts +129 -0
- package/src/actor/conn/mod.ts +232 -0
- package/src/actor/conn/persisted.ts +81 -0
- package/src/actor/conn/state-manager.ts +196 -0
- package/src/actor/contexts/action.ts +23 -0
- package/src/actor/{context.ts → contexts/actor.ts} +19 -8
- package/src/actor/contexts/conn-init.ts +31 -0
- package/src/actor/contexts/conn.ts +48 -0
- package/src/actor/contexts/create-conn-state.ts +13 -0
- package/src/actor/contexts/on-before-connect.ts +13 -0
- package/src/actor/contexts/on-connect.ts +22 -0
- package/src/actor/contexts/request.ts +48 -0
- package/src/actor/contexts/websocket.ts +48 -0
- package/src/actor/definition.ts +3 -3
- package/src/actor/driver.ts +36 -5
- package/src/actor/errors.ts +19 -24
- package/src/actor/instance/connection-manager.ts +465 -0
- package/src/actor/instance/event-manager.ts +292 -0
- package/src/actor/instance/kv.ts +15 -0
- package/src/actor/instance/mod.ts +1107 -0
- package/src/actor/instance/persisted.ts +67 -0
- package/src/actor/instance/schedule-manager.ts +349 -0
- package/src/actor/instance/state-manager.ts +502 -0
- package/src/actor/mod.ts +13 -16
- package/src/actor/protocol/old.ts +131 -43
- package/src/actor/protocol/serde.ts +19 -4
- package/src/actor/router-endpoints.ts +61 -586
- package/src/actor/router-websocket-endpoints.ts +408 -0
- package/src/actor/router.ts +63 -197
- package/src/actor/schedule.ts +1 -1
- package/src/client/actor-conn.ts +183 -249
- package/src/client/actor-handle.ts +29 -6
- package/src/client/client.ts +0 -4
- package/src/client/config.ts +1 -4
- package/src/client/mod.ts +0 -1
- package/src/client/raw-utils.ts +3 -3
- package/src/client/utils.ts +85 -39
- package/src/common/actor-router-consts.ts +5 -12
- package/src/common/{inline-websocket-adapter2.ts → inline-websocket-adapter.ts} +26 -48
- package/src/common/log.ts +1 -1
- package/src/common/router.ts +28 -17
- package/src/common/utils.ts +2 -0
- package/src/driver-helpers/mod.ts +7 -10
- package/src/driver-helpers/utils.ts +18 -9
- package/src/driver-test-suite/mod.ts +26 -50
- package/src/driver-test-suite/test-inline-client-driver.ts +27 -51
- package/src/driver-test-suite/tests/actor-conn-hibernation.ts +150 -0
- package/src/driver-test-suite/tests/actor-conn-state.ts +1 -4
- package/src/driver-test-suite/tests/actor-conn.ts +5 -9
- package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
- package/src/driver-test-suite/tests/actor-driver.ts +0 -7
- package/src/driver-test-suite/tests/actor-handle.ts +12 -12
- package/src/driver-test-suite/tests/actor-metadata.ts +1 -1
- package/src/driver-test-suite/tests/manager-driver.ts +1 -1
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +8 -8
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +6 -5
- package/src/driver-test-suite/tests/raw-http.ts +5 -5
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +7 -7
- package/src/driver-test-suite/tests/request-access.ts +4 -4
- package/src/driver-test-suite/utils.ts +6 -10
- package/src/drivers/engine/actor-driver.ts +614 -424
- package/src/drivers/engine/mod.ts +0 -1
- package/src/drivers/file-system/actor.ts +24 -12
- package/src/drivers/file-system/global-state.ts +427 -37
- package/src/drivers/file-system/manager.ts +71 -83
- package/src/drivers/file-system/mod.ts +3 -0
- package/src/drivers/file-system/utils.ts +18 -8
- package/src/engine-process/mod.ts +38 -38
- package/src/inspector/utils.ts +7 -5
- package/src/manager/driver.ts +11 -4
- package/src/manager/gateway.ts +4 -29
- package/src/manager/protocol/mod.ts +0 -2
- package/src/manager/protocol/query.ts +0 -4
- package/src/manager/router.ts +67 -64
- package/src/manager-api/actors.ts +13 -0
- package/src/mod.ts +1 -3
- package/src/registry/mod.ts +20 -20
- package/src/registry/serve.ts +9 -14
- package/src/remote-manager-driver/actor-websocket-client.ts +1 -16
- package/src/remote-manager-driver/api-endpoints.ts +13 -1
- package/src/remote-manager-driver/api-utils.ts +8 -0
- package/src/remote-manager-driver/metadata.ts +58 -0
- package/src/remote-manager-driver/mod.ts +47 -62
- package/src/remote-manager-driver/ws-proxy.ts +1 -1
- package/src/schemas/actor-persist/mod.ts +1 -1
- package/src/schemas/actor-persist/versioned.ts +56 -31
- package/src/schemas/client-protocol/mod.ts +1 -1
- package/src/schemas/client-protocol/versioned.ts +41 -21
- package/src/schemas/client-protocol-zod/mod.ts +103 -0
- package/src/schemas/file-system-driver/mod.ts +1 -1
- package/src/schemas/file-system-driver/versioned.ts +42 -19
- package/src/serde.ts +33 -11
- package/src/test/mod.ts +7 -3
- package/src/utils/node.ts +173 -0
- package/src/utils.ts +0 -4
- package/dist/tsup/chunk-227FEWMB.js.map +0 -1
- package/dist/tsup/chunk-2JYPS5YM.cjs.map +0 -1
- package/dist/tsup/chunk-36JJ4IQB.cjs.map +0 -1
- package/dist/tsup/chunk-7L65NNWP.cjs.map +0 -1
- package/dist/tsup/chunk-BLK27ES3.js.map +0 -1
- package/dist/tsup/chunk-BOMZS2TJ.js.map +0 -1
- package/dist/tsup/chunk-BYMKMOBS.js.map +0 -1
- package/dist/tsup/chunk-FX7TWFQR.js.map +0 -1
- package/dist/tsup/chunk-G64QUEDJ.js.map +0 -1
- package/dist/tsup/chunk-HHFKKVLR.cjs.map +0 -1
- package/dist/tsup/chunk-INNFK746.cjs.map +0 -1
- package/dist/tsup/chunk-KSRXX3Z4.cjs.map +0 -1
- package/dist/tsup/chunk-O44LFKSB.cjs +0 -4623
- package/dist/tsup/chunk-O44LFKSB.cjs.map +0 -1
- package/dist/tsup/chunk-PLUN2NQT.js.map +0 -1
- package/dist/tsup/chunk-S4UJG7ZE.js +0 -1119
- package/dist/tsup/chunk-S4UJG7ZE.js.map +0 -1
- package/dist/tsup/chunk-SHVX2QUR.cjs.map +0 -1
- package/dist/tsup/chunk-VFB23BYZ.cjs +0 -1119
- package/dist/tsup/chunk-VFB23BYZ.cjs.map +0 -1
- package/dist/tsup/chunk-VHGY7PU5.cjs.map +0 -1
- package/dist/tsup/chunk-YBG6R7LX.js.map +0 -1
- package/dist/tsup/chunk-YBHYXIP6.js.map +0 -1
- package/src/actor/action.ts +0 -178
- package/src/actor/conn-drivers.ts +0 -216
- package/src/actor/conn-socket.ts +0 -8
- package/src/actor/conn.ts +0 -272
- package/src/actor/instance.ts +0 -2336
- package/src/actor/persisted.ts +0 -49
- package/src/actor/unstable-react.ts +0 -110
- package/src/driver-test-suite/tests/actor-reconnect.ts +0 -170
- package/src/drivers/engine/kv.ts +0 -3
- package/src/manager/hono-websocket-adapter.ts +0 -393
- /package/dist/tsup/{chunk-CD33GT6Z.js.map → chunk-QIHBDXTO.js.map} +0 -0
package/src/client/client.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AnyActorDefinition } from "@/actor/definition";
|
|
2
|
-
import type { Transport } from "@/actor/protocol/old";
|
|
3
2
|
import type { Encoding } from "@/actor/protocol/serde";
|
|
4
3
|
import type { ManagerDriver } from "@/driver-helpers/mod";
|
|
5
4
|
import type { ActorQuery } from "@/manager/protocol/query";
|
|
@@ -149,7 +148,6 @@ export interface Region {
|
|
|
149
148
|
|
|
150
149
|
export const ACTOR_CONNS_SYMBOL = Symbol("actorConns");
|
|
151
150
|
export const CREATE_ACTOR_CONN_PROXY = Symbol("createActorConnProxy");
|
|
152
|
-
export const TRANSPORT_SYMBOL = Symbol("transport");
|
|
153
151
|
|
|
154
152
|
/**
|
|
155
153
|
* Client for managing & connecting to actors.
|
|
@@ -164,7 +162,6 @@ export class ClientRaw {
|
|
|
164
162
|
|
|
165
163
|
#driver: ManagerDriver;
|
|
166
164
|
#encodingKind: Encoding;
|
|
167
|
-
[TRANSPORT_SYMBOL]: Transport;
|
|
168
165
|
|
|
169
166
|
/**
|
|
170
167
|
* Creates an instance of Client.
|
|
@@ -173,7 +170,6 @@ export class ClientRaw {
|
|
|
173
170
|
this.#driver = driver;
|
|
174
171
|
|
|
175
172
|
this.#encodingKind = config.encoding ?? "bare";
|
|
176
|
-
this[TRANSPORT_SYMBOL] = config.transport ?? "websocket";
|
|
177
173
|
}
|
|
178
174
|
|
|
179
175
|
/**
|
package/src/client/config.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
import { TransportSchema } from "@/actor/protocol/old";
|
|
3
2
|
import { EncodingSchema } from "@/actor/protocol/serde";
|
|
4
3
|
import { type GetUpgradeWebSocket, getEnvUniversal } from "@/utils";
|
|
5
4
|
|
|
@@ -33,15 +32,13 @@ export const ClientConfigSchema = z.object({
|
|
|
33
32
|
|
|
34
33
|
encoding: EncodingSchema.default("bare"),
|
|
35
34
|
|
|
36
|
-
transport: TransportSchema.default("websocket"),
|
|
37
|
-
|
|
38
35
|
headers: z.record(z.string()).optional().default({}),
|
|
39
36
|
|
|
40
37
|
// See RunConfig.getUpgradeWebSocket
|
|
41
38
|
getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
|
|
42
39
|
|
|
43
40
|
/** Whether to automatically perform health checks when the client is created. */
|
|
44
|
-
|
|
41
|
+
disableMetadataLookup: z.boolean().optional().default(false),
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
export type ClientConfig = z.infer<typeof ClientConfigSchema>;
|
package/src/client/mod.ts
CHANGED
package/src/client/raw-utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import invariant from "invariant";
|
|
2
|
-
import {
|
|
2
|
+
import { PATH_WEBSOCKET_PREFIX } from "@/common/actor-router-consts";
|
|
3
3
|
import { deconstructError } from "@/common/utils";
|
|
4
4
|
import { HEADER_CONN_PARAMS, type ManagerDriver } from "@/driver-helpers/mod";
|
|
5
5
|
import type { ActorQuery } from "@/manager/protocol/query";
|
|
@@ -69,7 +69,7 @@ export async function rawHttpFetch(
|
|
|
69
69
|
|
|
70
70
|
// Build the URL with normalized path
|
|
71
71
|
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
72
|
-
const url = new URL(`http://actor/
|
|
72
|
+
const url = new URL(`http://actor/request/${normalizedPath}`);
|
|
73
73
|
|
|
74
74
|
// Forward conn params if provided
|
|
75
75
|
const proxyRequestHeaders = new Headers(mergedInit.headers);
|
|
@@ -132,7 +132,7 @@ export async function rawWebSocket(
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
const fullPath = `${
|
|
135
|
+
const fullPath = `${PATH_WEBSOCKET_PREFIX}${pathPortion}${queryPortion}`;
|
|
136
136
|
|
|
137
137
|
logger().debug({
|
|
138
138
|
msg: "opening websocket",
|
package/src/client/utils.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as cbor from "cbor-x";
|
|
2
2
|
import invariant from "invariant";
|
|
3
|
+
import type { z } from "zod";
|
|
3
4
|
import type { Encoding } from "@/actor/protocol/serde";
|
|
4
5
|
import { assertUnreachable } from "@/common/utils";
|
|
5
6
|
import type { VersionedDataHandler } from "@/common/versioned-data";
|
|
6
7
|
import type { HttpResponseError } from "@/schemas/client-protocol/mod";
|
|
7
8
|
import { HTTP_RESPONSE_ERROR_VERSIONED } from "@/schemas/client-protocol/versioned";
|
|
9
|
+
import {
|
|
10
|
+
type HttpResponseError as HttpResponseErrorJson,
|
|
11
|
+
HttpResponseErrorSchema,
|
|
12
|
+
} from "@/schemas/client-protocol-zod/mod";
|
|
8
13
|
import {
|
|
9
14
|
contentTypeForEncoding,
|
|
10
15
|
deserializeWithEncoding,
|
|
@@ -33,25 +38,51 @@ export function messageLength(message: WebSocketMessage): number {
|
|
|
33
38
|
assertUnreachable(message);
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
export interface HttpRequestOpts<
|
|
41
|
+
export interface HttpRequestOpts<
|
|
42
|
+
RequestBare,
|
|
43
|
+
ResponseBare,
|
|
44
|
+
RequestJson = RequestBare,
|
|
45
|
+
ResponseJson = ResponseBare,
|
|
46
|
+
Request = RequestBare,
|
|
47
|
+
Response = ResponseBare,
|
|
48
|
+
> {
|
|
37
49
|
method: string;
|
|
38
50
|
url: string;
|
|
39
51
|
headers: Record<string, string>;
|
|
40
|
-
body?:
|
|
52
|
+
body?: Request;
|
|
41
53
|
encoding: Encoding;
|
|
42
54
|
skipParseResponse?: boolean;
|
|
43
55
|
signal?: AbortSignal;
|
|
44
|
-
customFetch?: (req: Request) => Promise<Response>;
|
|
45
|
-
requestVersionedDataHandler: VersionedDataHandler<
|
|
56
|
+
customFetch?: (req: globalThis.Request) => Promise<globalThis.Response>;
|
|
57
|
+
requestVersionedDataHandler: VersionedDataHandler<RequestBare> | undefined;
|
|
46
58
|
responseVersionedDataHandler:
|
|
47
|
-
| VersionedDataHandler<
|
|
59
|
+
| VersionedDataHandler<ResponseBare>
|
|
48
60
|
| undefined;
|
|
61
|
+
requestZodSchema: z.ZodType<RequestJson>;
|
|
62
|
+
responseZodSchema: z.ZodType<ResponseJson>;
|
|
63
|
+
requestToJson: (value: Request) => RequestJson;
|
|
64
|
+
requestToBare: (value: Request) => RequestBare;
|
|
65
|
+
responseFromJson: (value: ResponseJson) => Response;
|
|
66
|
+
responseFromBare: (value: ResponseBare) => Response;
|
|
49
67
|
}
|
|
50
68
|
|
|
51
69
|
export async function sendHttpRequest<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
RequestBare = unknown,
|
|
71
|
+
ResponseBare = unknown,
|
|
72
|
+
RequestJson = RequestBare,
|
|
73
|
+
ResponseJson = ResponseBare,
|
|
74
|
+
Request = RequestBare,
|
|
75
|
+
Response = ResponseBare,
|
|
76
|
+
>(
|
|
77
|
+
opts: HttpRequestOpts<
|
|
78
|
+
RequestBare,
|
|
79
|
+
ResponseBare,
|
|
80
|
+
RequestJson,
|
|
81
|
+
ResponseJson,
|
|
82
|
+
Request,
|
|
83
|
+
Response
|
|
84
|
+
>,
|
|
85
|
+
): Promise<Response> {
|
|
55
86
|
logger().debug({
|
|
56
87
|
msg: "sending http request",
|
|
57
88
|
url: opts.url,
|
|
@@ -64,19 +95,22 @@ export async function sendHttpRequest<
|
|
|
64
95
|
if (opts.method === "POST" || opts.method === "PUT") {
|
|
65
96
|
invariant(opts.body !== undefined, "missing body");
|
|
66
97
|
contentType = contentTypeForEncoding(opts.encoding);
|
|
67
|
-
bodyData = serializeWithEncoding<
|
|
98
|
+
bodyData = serializeWithEncoding<RequestBare, RequestJson, Request>(
|
|
68
99
|
opts.encoding,
|
|
69
100
|
opts.body,
|
|
70
101
|
opts.requestVersionedDataHandler,
|
|
102
|
+
opts.requestZodSchema,
|
|
103
|
+
opts.requestToJson,
|
|
104
|
+
opts.requestToBare,
|
|
71
105
|
);
|
|
72
106
|
}
|
|
73
107
|
|
|
74
108
|
// Send request
|
|
75
|
-
let response: Response;
|
|
109
|
+
let response: globalThis.Response;
|
|
76
110
|
try {
|
|
77
111
|
// Make the HTTP request
|
|
78
112
|
response = await (opts.customFetch ?? fetch)(
|
|
79
|
-
new Request(opts.url, {
|
|
113
|
+
new globalThis.Request(opts.url, {
|
|
80
114
|
method: opts.method,
|
|
81
115
|
headers: {
|
|
82
116
|
...opts.headers,
|
|
@@ -100,27 +134,52 @@ export async function sendHttpRequest<
|
|
|
100
134
|
|
|
101
135
|
// Parse response error
|
|
102
136
|
if (!response.ok) {
|
|
103
|
-
// Attempt to parse structured data
|
|
104
137
|
const bufferResponse = await response.arrayBuffer();
|
|
105
|
-
|
|
138
|
+
const contentType = response.headers.get("content-type");
|
|
139
|
+
const rayId = response.headers.get("x-rivet-ray-id");
|
|
140
|
+
|
|
141
|
+
// Determine encoding from Content-Type header, defaulting to provided encoding
|
|
142
|
+
const encoding: Encoding = contentType?.includes("application/json")
|
|
143
|
+
? "json"
|
|
144
|
+
: opts.encoding;
|
|
145
|
+
|
|
146
|
+
// Attempt to parse structured error data
|
|
106
147
|
try {
|
|
107
|
-
responseData = deserializeWithEncoding(
|
|
108
|
-
|
|
148
|
+
const responseData = deserializeWithEncoding(
|
|
149
|
+
encoding,
|
|
109
150
|
new Uint8Array(bufferResponse),
|
|
110
151
|
HTTP_RESPONSE_ERROR_VERSIONED,
|
|
152
|
+
HttpResponseErrorSchema,
|
|
153
|
+
// JSON: metadata is already unknown
|
|
154
|
+
(json): HttpResponseErrorJson => json as HttpResponseErrorJson,
|
|
155
|
+
// BARE: decode ArrayBuffer metadata to unknown
|
|
156
|
+
(bare): any => ({
|
|
157
|
+
group: bare.group,
|
|
158
|
+
code: bare.code,
|
|
159
|
+
message: bare.message,
|
|
160
|
+
metadata: bare.metadata
|
|
161
|
+
? cbor.decode(new Uint8Array(bare.metadata))
|
|
162
|
+
: undefined,
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
throw new ActorError(
|
|
167
|
+
responseData.group,
|
|
168
|
+
responseData.code,
|
|
169
|
+
responseData.message,
|
|
170
|
+
responseData.metadata,
|
|
111
171
|
);
|
|
112
172
|
} catch (error) {
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
173
|
+
// If it's already an ActorError, re-throw it
|
|
174
|
+
if (error instanceof ActorError) {
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
116
177
|
|
|
117
|
-
//
|
|
178
|
+
// Otherwise, fall back to generic error with text response
|
|
118
179
|
const textResponse = new TextDecoder("utf-8", {
|
|
119
180
|
fatal: false,
|
|
120
181
|
}).decode(bufferResponse);
|
|
121
182
|
|
|
122
|
-
const rayId = response.headers.get("x-rivet-ray-id");
|
|
123
|
-
|
|
124
183
|
if (rayId) {
|
|
125
184
|
throw new HttpRequestError(
|
|
126
185
|
`${response.statusText} (${response.status}) (Ray ID: ${rayId}):\n${textResponse}`,
|
|
@@ -131,36 +190,23 @@ export async function sendHttpRequest<
|
|
|
131
190
|
);
|
|
132
191
|
}
|
|
133
192
|
}
|
|
134
|
-
|
|
135
|
-
// Decode metadata based on encoding - only binary encodings have CBOR-encoded metadata
|
|
136
|
-
let decodedMetadata: unknown;
|
|
137
|
-
if (responseData.metadata && encodingIsBinary(opts.encoding)) {
|
|
138
|
-
decodedMetadata = cbor.decode(
|
|
139
|
-
new Uint8Array(responseData.metadata),
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Throw structured error
|
|
144
|
-
throw new ActorError(
|
|
145
|
-
responseData.group,
|
|
146
|
-
responseData.code,
|
|
147
|
-
responseData.message,
|
|
148
|
-
decodedMetadata,
|
|
149
|
-
);
|
|
150
193
|
}
|
|
151
194
|
|
|
152
195
|
// Some requests don't need the success response to be parsed, so this can speed things up
|
|
153
196
|
if (opts.skipParseResponse) {
|
|
154
|
-
return undefined as
|
|
197
|
+
return undefined as Response;
|
|
155
198
|
}
|
|
156
199
|
|
|
157
200
|
// Parse the response based on encoding
|
|
158
201
|
try {
|
|
159
202
|
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
160
|
-
return deserializeWithEncoding(
|
|
203
|
+
return deserializeWithEncoding<ResponseBare, ResponseJson, Response>(
|
|
161
204
|
opts.encoding,
|
|
162
205
|
buffer,
|
|
163
206
|
opts.responseVersionedDataHandler,
|
|
207
|
+
opts.responseZodSchema,
|
|
208
|
+
opts.responseFromJson,
|
|
209
|
+
opts.responseFromBare,
|
|
164
210
|
);
|
|
165
211
|
} catch (error) {
|
|
166
212
|
throw new HttpRequestError(`Failed to parse response: ${error}`, {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// NOTE: This is in a separate file from the router since it needs to be shared between the client & the server. If this was in the router file, the client would end up importing the *entire* actor router and tree shaking would not work.
|
|
2
2
|
|
|
3
3
|
// MARK: Paths
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
4
|
+
export const PATH_CONNECT = "/connect";
|
|
5
|
+
export const PATH_WEBSOCKET_BASE = "/websocket";
|
|
6
|
+
export const PATH_WEBSOCKET_PREFIX = "/websocket/";
|
|
7
|
+
export const PATH_INSPECTOR_CONNECT = "/inspector/connect";
|
|
6
8
|
|
|
7
9
|
// MARK: Headers
|
|
8
10
|
export const HEADER_ACTOR_QUERY = "x-rivet-query";
|
|
@@ -14,10 +16,6 @@ export const HEADER_CONN_PARAMS = "x-rivet-conn-params";
|
|
|
14
16
|
|
|
15
17
|
export const HEADER_ACTOR_ID = "x-rivet-actor";
|
|
16
18
|
|
|
17
|
-
export const HEADER_CONN_ID = "x-rivet-conn";
|
|
18
|
-
|
|
19
|
-
export const HEADER_CONN_TOKEN = "x-rivet-conn-token";
|
|
20
|
-
|
|
21
19
|
export const HEADER_RIVET_TOKEN = "x-rivet-token";
|
|
22
20
|
|
|
23
21
|
// MARK: Manager Gateway Headers
|
|
@@ -32,13 +30,10 @@ export const WS_PROTOCOL_TARGET = "rivet_target.";
|
|
|
32
30
|
export const WS_PROTOCOL_ACTOR = "rivet_actor.";
|
|
33
31
|
export const WS_PROTOCOL_ENCODING = "rivet_encoding.";
|
|
34
32
|
export const WS_PROTOCOL_CONN_PARAMS = "rivet_conn_params.";
|
|
35
|
-
export const WS_PROTOCOL_CONN_ID = "rivet_conn.";
|
|
36
|
-
export const WS_PROTOCOL_CONN_TOKEN = "rivet_conn_token.";
|
|
37
33
|
export const WS_PROTOCOL_TOKEN = "rivet_token.";
|
|
38
34
|
|
|
39
35
|
// MARK: WebSocket Inline Test Protocol Prefixes
|
|
40
|
-
export const
|
|
41
|
-
export const WS_PROTOCOL_PATH = "test_path.";
|
|
36
|
+
export const WS_TEST_PROTOCOL_PATH = "test_path.";
|
|
42
37
|
|
|
43
38
|
/**
|
|
44
39
|
* Headers that publics can send from public clients.
|
|
@@ -52,8 +47,6 @@ export const ALLOWED_PUBLIC_HEADERS = [
|
|
|
52
47
|
HEADER_ENCODING,
|
|
53
48
|
HEADER_CONN_PARAMS,
|
|
54
49
|
HEADER_ACTOR_ID,
|
|
55
|
-
HEADER_CONN_ID,
|
|
56
|
-
HEADER_CONN_TOKEN,
|
|
57
50
|
HEADER_RIVET_TARGET,
|
|
58
51
|
HEADER_RIVET_ACTOR,
|
|
59
52
|
HEADER_RIVET_NAMESPACE,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WSContext } from "hono/ws";
|
|
2
|
+
import type { UpgradeWebSocketArgs } from "@/actor/router-websocket-endpoints";
|
|
2
3
|
import type {
|
|
3
4
|
RivetCloseEvent,
|
|
4
5
|
RivetEvent,
|
|
@@ -11,20 +12,11 @@ export function logger() {
|
|
|
11
12
|
return getLogger("fake-event-source2");
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
// TODO: Merge with ConnectWebSocketOutput interface
|
|
15
|
-
export interface UpgradeWebSocketArgs {
|
|
16
|
-
onOpen: (event: any, ws: WSContext) => void;
|
|
17
|
-
onMessage: (event: any, ws: WSContext) => void;
|
|
18
|
-
onClose: (event: any, ws: WSContext) => void;
|
|
19
|
-
onError: (error: any, ws: WSContext) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// TODO: Remove `2` suffix
|
|
23
15
|
/**
|
|
24
16
|
* InlineWebSocketAdapter implements a WebSocket-like interface
|
|
25
17
|
* that connects to a UpgradeWebSocketArgs handler
|
|
26
18
|
*/
|
|
27
|
-
export class
|
|
19
|
+
export class InlineWebSocketAdapter implements UniversalWebSocket {
|
|
28
20
|
// WebSocket readyState values
|
|
29
21
|
readonly CONNECTING = 0 as const;
|
|
30
22
|
readonly OPEN = 1 as const;
|
|
@@ -36,14 +28,8 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
36
28
|
#wsContext: WSContext;
|
|
37
29
|
#readyState: 0 | 1 | 2 | 3 = 0; // Start in CONNECTING state
|
|
38
30
|
#queuedMessages: Array<string | ArrayBuffer | Uint8Array> = [];
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
#bufferedEvents: Array<{
|
|
42
|
-
type: string;
|
|
43
|
-
event: any;
|
|
44
|
-
}> = [];
|
|
45
|
-
|
|
46
|
-
// Event listeners with buffering
|
|
31
|
+
|
|
32
|
+
// Event listeners
|
|
47
33
|
#eventListeners: Map<string, ((ev: any) => void)[]> = new Map();
|
|
48
34
|
|
|
49
35
|
constructor(handler: UpgradeWebSocketArgs) {
|
|
@@ -65,7 +51,11 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
65
51
|
});
|
|
66
52
|
|
|
67
53
|
// Initialize the connection
|
|
68
|
-
|
|
54
|
+
//
|
|
55
|
+
// Defer initialization to allow event listeners to be attached first
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
this.#initialize();
|
|
58
|
+
}, 0);
|
|
69
59
|
}
|
|
70
60
|
|
|
71
61
|
get readyState(): 0 | 1 | 2 | 3 {
|
|
@@ -99,19 +89,28 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
99
89
|
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void {
|
|
100
90
|
logger().debug({ msg: "send called", readyState: this.readyState });
|
|
101
91
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
// Handle different ready states
|
|
93
|
+
if (this.readyState === this.CONNECTING) {
|
|
94
|
+
// Throw InvalidStateError if still connecting
|
|
95
|
+
throw new DOMException(
|
|
96
|
+
"WebSocket is still in CONNECTING state",
|
|
97
|
+
"InvalidStateError",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (
|
|
102
|
+
this.readyState === this.CLOSING ||
|
|
103
|
+
this.readyState === this.CLOSED
|
|
104
|
+
) {
|
|
105
|
+
// Silently ignore if closing or closed
|
|
106
|
+
logger().debug({
|
|
107
|
+
msg: "ignoring send, websocket is closing or closed",
|
|
106
108
|
readyState: this.readyState,
|
|
107
|
-
dataType: typeof data,
|
|
108
|
-
dataLength: typeof data === "string" ? data.length : "binary",
|
|
109
|
-
error,
|
|
110
109
|
});
|
|
111
|
-
this.#fireError(error);
|
|
112
110
|
return;
|
|
113
111
|
}
|
|
114
112
|
|
|
113
|
+
// Must be OPEN at this point
|
|
115
114
|
this.#handler.onMessage({ data }, this.#wsContext);
|
|
116
115
|
}
|
|
117
116
|
|
|
@@ -284,9 +283,6 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
284
283
|
this.#eventListeners.set(type, []);
|
|
285
284
|
}
|
|
286
285
|
this.#eventListeners.get(type)!.push(listener);
|
|
287
|
-
|
|
288
|
-
// Flush any buffered events for this type
|
|
289
|
-
this.#flushBufferedEvents(type);
|
|
290
286
|
}
|
|
291
287
|
|
|
292
288
|
removeEventListener(type: string, listener: (ev: any) => void): void {
|
|
@@ -315,11 +311,6 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
315
311
|
});
|
|
316
312
|
}
|
|
317
313
|
}
|
|
318
|
-
} else {
|
|
319
|
-
logger().debug({
|
|
320
|
-
msg: `no ${type} listeners registered, buffering event`,
|
|
321
|
-
});
|
|
322
|
-
this.#bufferedEvents.push({ type, event });
|
|
323
314
|
}
|
|
324
315
|
|
|
325
316
|
// Also check for on* properties
|
|
@@ -380,19 +371,6 @@ export class InlineWebSocketAdapter2 implements UniversalWebSocket {
|
|
|
380
371
|
return true;
|
|
381
372
|
}
|
|
382
373
|
|
|
383
|
-
#flushBufferedEvents(type: string): void {
|
|
384
|
-
const eventsToFlush = this.#bufferedEvents.filter(
|
|
385
|
-
(buffered) => buffered.type === type,
|
|
386
|
-
);
|
|
387
|
-
this.#bufferedEvents = this.#bufferedEvents.filter(
|
|
388
|
-
(buffered) => buffered.type !== type,
|
|
389
|
-
);
|
|
390
|
-
|
|
391
|
-
for (const { event } of eventsToFlush) {
|
|
392
|
-
this.#dispatchEvent(type, event);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
374
|
#fireOpen(): void {
|
|
397
375
|
try {
|
|
398
376
|
// Create an Event-like object since Event constructor may not be available
|
package/src/common/log.ts
CHANGED
|
@@ -147,7 +147,7 @@ export async function configureDefaultLogger(
|
|
|
147
147
|
},
|
|
148
148
|
hooks: {
|
|
149
149
|
logMethod(inputArgs, method, level) {
|
|
150
|
-
// TODO: This is a hack to not implement our own transport target. We can get better perf if we have our own transport target.
|
|
150
|
+
// TODO: This is a hack to not implement our own Pino transport target. We can get better perf if we have our own transport target.
|
|
151
151
|
|
|
152
152
|
const levelMap: Record<number, string> = {
|
|
153
153
|
10: "trace",
|
package/src/common/router.ts
CHANGED
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
} from "@/actor/router-endpoints";
|
|
8
8
|
import { buildActorNames, type RegistryConfig } from "@/registry/config";
|
|
9
9
|
import type { RunnerConfig } from "@/registry/run-config";
|
|
10
|
-
import
|
|
11
|
-
import { HttpResponseError } from "@/schemas/client-protocol/mod";
|
|
10
|
+
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
12
11
|
import { HTTP_RESPONSE_ERROR_VERSIONED } from "@/schemas/client-protocol/versioned";
|
|
12
|
+
import {
|
|
13
|
+
type HttpResponseError as HttpResponseErrorJson,
|
|
14
|
+
HttpResponseErrorSchema,
|
|
15
|
+
} from "@/schemas/client-protocol-zod/mod";
|
|
13
16
|
import { encodingIsBinary, serializeWithEncoding } from "@/serde";
|
|
14
17
|
import { bufferToArrayBuffer, getEnvUniversal, VERSION } from "@/utils";
|
|
15
18
|
import { getLogger, type Logger } from "./log";
|
|
@@ -68,18 +71,28 @@ export function handleRouteError(error: unknown, c: HonoContext) {
|
|
|
68
71
|
encoding = "json";
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
const errorData = { group, code, message, metadata };
|
|
71
75
|
const output = serializeWithEncoding(
|
|
72
76
|
encoding,
|
|
73
|
-
|
|
74
|
-
group,
|
|
75
|
-
code,
|
|
76
|
-
message,
|
|
77
|
-
// TODO: Cannot serialize non-binary meta since it requires ArrayBuffer atm
|
|
78
|
-
metadata: encodingIsBinary(encoding)
|
|
79
|
-
? bufferToArrayBuffer(cbor.encode(metadata))
|
|
80
|
-
: null,
|
|
81
|
-
},
|
|
77
|
+
errorData,
|
|
82
78
|
HTTP_RESPONSE_ERROR_VERSIONED,
|
|
79
|
+
HttpResponseErrorSchema,
|
|
80
|
+
// JSON: metadata is the raw value (will be serialized by jsonStringifyCompat)
|
|
81
|
+
(value): HttpResponseErrorJson => ({
|
|
82
|
+
group: value.group,
|
|
83
|
+
code: value.code,
|
|
84
|
+
message: value.message,
|
|
85
|
+
metadata: value.metadata,
|
|
86
|
+
}),
|
|
87
|
+
// BARE/CBOR: metadata needs to be CBOR-encoded to ArrayBuffer
|
|
88
|
+
(value): protocol.HttpResponseError => ({
|
|
89
|
+
group: value.group,
|
|
90
|
+
code: value.code,
|
|
91
|
+
message: value.message,
|
|
92
|
+
metadata: value.metadata
|
|
93
|
+
? bufferToArrayBuffer(cbor.encode(value.metadata))
|
|
94
|
+
: null,
|
|
95
|
+
}),
|
|
83
96
|
);
|
|
84
97
|
|
|
85
98
|
// TODO: Remove any
|
|
@@ -125,12 +138,10 @@ export function handleMetadataRequest(
|
|
|
125
138
|
: { normal: {} },
|
|
126
139
|
},
|
|
127
140
|
actorNames: buildActorNames(registryConfig),
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
? undefined
|
|
133
|
-
: getEndpoint(runConfig)),
|
|
141
|
+
// If server address is changed, return a different client endpoint.
|
|
142
|
+
// Otherwise, return null indicating the client should use the current
|
|
143
|
+
// endpoint it's already configured with.
|
|
144
|
+
clientEndpoint: runConfig.overrideServerAddress,
|
|
134
145
|
};
|
|
135
146
|
|
|
136
147
|
return c.json(response);
|
package/src/common/utils.ts
CHANGED
|
@@ -245,6 +245,7 @@ export function deconstructError(
|
|
|
245
245
|
group,
|
|
246
246
|
code,
|
|
247
247
|
message,
|
|
248
|
+
stack: (error as Error)?.stack,
|
|
248
249
|
...EXTRA_ERROR_LOG,
|
|
249
250
|
...extraLog,
|
|
250
251
|
});
|
|
@@ -260,6 +261,7 @@ export function deconstructError(
|
|
|
260
261
|
group,
|
|
261
262
|
code,
|
|
262
263
|
message,
|
|
264
|
+
stack: (error as Error)?.stack,
|
|
263
265
|
...EXTRA_ERROR_LOG,
|
|
264
266
|
...extraLog,
|
|
265
267
|
});
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
export type { ActorDriver } from "@/actor/driver";
|
|
2
|
-
export type { ActorInstance, AnyActorInstance } from "@/actor/instance";
|
|
2
|
+
export type { ActorInstance, AnyActorInstance } from "@/actor/instance/mod";
|
|
3
3
|
export { generateRandomString } from "@/actor/utils";
|
|
4
4
|
export {
|
|
5
5
|
ALLOWED_PUBLIC_HEADERS,
|
|
6
6
|
HEADER_ACTOR_ID,
|
|
7
7
|
HEADER_ACTOR_QUERY,
|
|
8
|
-
HEADER_CONN_ID,
|
|
9
8
|
HEADER_CONN_PARAMS,
|
|
10
|
-
HEADER_CONN_TOKEN,
|
|
11
9
|
HEADER_ENCODING,
|
|
12
10
|
HEADER_RIVET_ACTOR,
|
|
13
11
|
HEADER_RIVET_TARGET,
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
PATH_CONNECT,
|
|
13
|
+
PATH_WEBSOCKET_BASE,
|
|
14
|
+
PATH_WEBSOCKET_PREFIX,
|
|
16
15
|
WS_PROTOCOL_ACTOR,
|
|
17
|
-
WS_PROTOCOL_CONN_ID,
|
|
18
16
|
WS_PROTOCOL_CONN_PARAMS,
|
|
19
|
-
WS_PROTOCOL_CONN_TOKEN,
|
|
20
17
|
WS_PROTOCOL_ENCODING,
|
|
21
|
-
WS_PROTOCOL_PATH,
|
|
22
18
|
WS_PROTOCOL_STANDARD,
|
|
23
19
|
WS_PROTOCOL_TARGET,
|
|
24
|
-
|
|
20
|
+
WS_TEST_PROTOCOL_PATH as WS_PROTOCOL_PATH,
|
|
25
21
|
} from "@/common/actor-router-consts";
|
|
26
22
|
export type {
|
|
27
23
|
ActorOutput,
|
|
@@ -29,6 +25,7 @@ export type {
|
|
|
29
25
|
GetForIdInput,
|
|
30
26
|
GetOrCreateWithKeyInput,
|
|
31
27
|
GetWithKeyInput,
|
|
28
|
+
ListActorsInput,
|
|
32
29
|
ManagerDisplayInformation,
|
|
33
30
|
ManagerDriver,
|
|
34
31
|
} from "@/manager/driver";
|
|
@@ -36,4 +33,4 @@ export {
|
|
|
36
33
|
DriverConfigSchema,
|
|
37
34
|
RunnerConfigSchema as RunConfigSchema,
|
|
38
35
|
} from "@/registry/run-config";
|
|
39
|
-
export {
|
|
36
|
+
export { getInitialActorKvState } from "./utils";
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import * as cbor from "cbor-x";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { KEYS } from "@/actor/instance/kv";
|
|
3
|
+
import type * as persistSchema from "@/schemas/actor-persist/mod";
|
|
4
|
+
import { ACTOR_VERSIONED } from "@/schemas/actor-persist/versioned";
|
|
4
5
|
import { bufferToArrayBuffer } from "@/utils";
|
|
6
|
+
import type { ActorDriver } from "./mod";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
): Uint8Array {
|
|
9
|
-
const persistData: schema.PersistedActor = {
|
|
8
|
+
function serializeEmptyPersistData(input: unknown | undefined): Uint8Array {
|
|
9
|
+
const persistData: persistSchema.Actor = {
|
|
10
10
|
input:
|
|
11
11
|
input !== undefined
|
|
12
12
|
? bufferToArrayBuffer(cbor.encode(input))
|
|
13
13
|
: null,
|
|
14
14
|
hasInitialized: false,
|
|
15
15
|
state: bufferToArrayBuffer(cbor.encode(undefined)),
|
|
16
|
-
connections: [],
|
|
17
16
|
scheduledEvents: [],
|
|
18
|
-
hibernatableWebSocket: [],
|
|
19
17
|
};
|
|
20
|
-
return
|
|
18
|
+
return ACTOR_VERSIONED.serializeWithEmbeddedVersion(persistData);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the initial KV state for a new actor. This is ued by the drivers to
|
|
23
|
+
* write the initial state in to KV storage before starting the actor.
|
|
24
|
+
*/
|
|
25
|
+
export function getInitialActorKvState(
|
|
26
|
+
input: unknown | undefined,
|
|
27
|
+
): [Uint8Array, Uint8Array][] {
|
|
28
|
+
const persistData = serializeEmptyPersistData(input);
|
|
29
|
+
return [[KEYS.PERSIST_DATA, persistData]];
|
|
21
30
|
}
|