rivetkit 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/schemas/actor-persist/v1.ts +21 -24
- package/dist/schemas/client-protocol/v1.ts +6 -0
- package/dist/tsup/actor/errors.cjs +10 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +17 -4
- package/dist/tsup/actor/errors.d.ts +17 -4
- package/dist/tsup/actor/errors.js +11 -3
- package/dist/tsup/{chunk-6PDXBYI5.js → chunk-3F2YSRJL.js} +8 -23
- package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
- package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
- package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
- package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
- package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
- package/dist/tsup/{chunk-OGAPU3UG.cjs → chunk-6LJT3QRL.cjs} +39 -25
- package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
- package/dist/tsup/{chunk-6WKQDDUD.cjs → chunk-GICQ3YCU.cjs} +143 -141
- package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
- package/dist/tsup/{chunk-FLMTTN27.js → chunk-H26RP6GD.js} +15 -8
- package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
- package/dist/tsup/chunk-HI3HWJRC.js +20 -0
- package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
- package/dist/tsup/{chunk-4NSUQZ2H.js → chunk-HLLF4B4Q.js} +116 -114
- package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
- package/dist/tsup/{chunk-FCCPJNMA.cjs → chunk-IH6CKNDW.cjs} +12 -27
- package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
- package/dist/tsup/chunk-LV2S3OU3.js +250 -0
- package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
- package/dist/tsup/{chunk-R2OPSKIV.cjs → chunk-LWNKVZG5.cjs} +20 -13
- package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
- package/dist/tsup/{chunk-INGJP237.js → chunk-NFU2BBT5.js} +102 -43
- package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
- package/dist/tsup/{chunk-3H7O2A7I.js → chunk-PQY7KKTL.js} +33 -19
- package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
- package/dist/tsup/{chunk-PO4VLDWA.js → chunk-QK72M5JB.js} +3 -5
- package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
- package/dist/tsup/{chunk-TZJKSBUQ.cjs → chunk-QNNXFOQV.cjs} +3 -5
- package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
- package/dist/tsup/{chunk-GIR3AFFI.cjs → chunk-SBHHJ6QS.cjs} +102 -43
- package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
- package/dist/tsup/chunk-TQ62L3X7.js +325 -0
- package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
- package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
- package/dist/tsup/chunk-XJQHKJ4P.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -10
- package/dist/tsup/client/mod.d.cts +7 -13
- package/dist/tsup/client/mod.d.ts +7 -13
- package/dist/tsup/client/mod.js +9 -9
- package/dist/tsup/common/log.cjs +12 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +23 -17
- package/dist/tsup/common/log.d.ts +23 -17
- package/dist/tsup/common/log.js +15 -7
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -4
- package/dist/tsup/{common-CpqORuCq.d.cts → common-CXCe7s6i.d.cts} +2 -2
- package/dist/tsup/{common-CpqORuCq.d.ts → common-CXCe7s6i.d.ts} +2 -2
- package/dist/tsup/{connection-BwUMoe6n.d.ts → connection-BI-6UIBJ.d.ts} +196 -226
- package/dist/tsup/{connection-BR_Ve4ku.d.cts → connection-Dyd4NLGW.d.cts} +196 -226
- package/dist/tsup/driver-helpers/mod.cjs +6 -9
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +5 -6
- package/dist/tsup/driver-helpers/mod.d.ts +5 -6
- package/dist/tsup/driver-helpers/mod.js +6 -9
- package/dist/tsup/driver-test-suite/mod.cjs +155 -1363
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +11 -5
- package/dist/tsup/driver-test-suite/mod.d.ts +11 -5
- package/dist/tsup/driver-test-suite/mod.js +876 -2084
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +6 -8
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +3 -3
- package/dist/tsup/inspector/mod.d.ts +3 -3
- package/dist/tsup/inspector/mod.js +8 -10
- package/dist/tsup/mod.cjs +9 -15
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +47 -42
- package/dist/tsup/mod.d.ts +47 -42
- package/dist/tsup/mod.js +10 -16
- package/dist/tsup/{router-endpoints-DAbqVFx2.d.ts → router-endpoints-BTe_Rsdn.d.cts} +2 -3
- package/dist/tsup/{router-endpoints-AYkXG8Tl.d.cts → router-endpoints-CBSrKHmo.d.ts} +2 -3
- package/dist/tsup/test/mod.cjs +10 -14
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +9 -13
- package/dist/tsup/{utils-CT0cv4jd.d.ts → utils-fwx3o3K9.d.cts} +1 -0
- package/dist/tsup/{utils-CT0cv4jd.d.cts → utils-fwx3o3K9.d.ts} +1 -0
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/package.json +4 -4
- package/src/actor/action.ts +1 -5
- package/src/actor/config.ts +27 -295
- package/src/actor/connection.ts +9 -12
- package/src/actor/context.ts +1 -4
- package/src/actor/definition.ts +7 -11
- package/src/actor/errors.ts +97 -35
- package/src/actor/generic-conn-driver.ts +28 -16
- package/src/actor/instance.ts +177 -133
- package/src/actor/log.ts +4 -13
- package/src/actor/mod.ts +0 -5
- package/src/actor/protocol/old.ts +42 -26
- package/src/actor/protocol/serde.ts +1 -1
- package/src/actor/router-endpoints.ts +41 -38
- package/src/actor/router.ts +20 -18
- package/src/actor/unstable-react.ts +1 -1
- package/src/actor/utils.ts +6 -2
- package/src/client/actor-common.ts +1 -1
- package/src/client/actor-conn.ts +152 -91
- package/src/client/actor-handle.ts +85 -25
- package/src/client/actor-query.ts +65 -0
- package/src/client/client.ts +29 -98
- package/src/client/config.ts +44 -0
- package/src/client/errors.ts +1 -0
- package/src/client/log.ts +2 -4
- package/src/client/mod.ts +16 -12
- package/src/client/raw-utils.ts +82 -25
- package/src/client/utils.ts +5 -3
- package/src/common/fake-event-source.ts +10 -9
- package/src/common/inline-websocket-adapter2.ts +39 -30
- package/src/common/log.ts +176 -101
- package/src/common/logfmt.ts +21 -30
- package/src/common/router.ts +12 -19
- package/src/common/utils.ts +27 -13
- package/src/common/websocket.ts +0 -1
- package/src/driver-helpers/mod.ts +1 -1
- package/src/driver-test-suite/log.ts +1 -3
- package/src/driver-test-suite/mod.ts +86 -60
- package/src/driver-test-suite/tests/actor-handle.ts +33 -0
- package/src/driver-test-suite/tests/manager-driver.ts +5 -3
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -226
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -392
- package/src/driver-test-suite/tests/request-access.ts +112 -126
- package/src/driver-test-suite/utils.ts +13 -10
- package/src/drivers/default.ts +7 -4
- package/src/drivers/engine/actor-driver.ts +22 -13
- package/src/drivers/engine/config.ts +2 -10
- package/src/drivers/engine/kv.ts +1 -1
- package/src/drivers/engine/log.ts +1 -3
- package/src/drivers/engine/mod.ts +2 -3
- package/src/drivers/file-system/actor.ts +1 -1
- package/src/drivers/file-system/global-state.ts +33 -20
- package/src/drivers/file-system/log.ts +1 -3
- package/src/drivers/file-system/manager.ts +31 -8
- package/src/inspector/config.ts +9 -4
- package/src/inspector/log.ts +1 -1
- package/src/inspector/manager.ts +2 -2
- package/src/inspector/utils.ts +1 -1
- package/src/manager/driver.ts +10 -2
- package/src/manager/hono-websocket-adapter.ts +21 -12
- package/src/manager/log.ts +2 -4
- package/src/manager/mod.ts +1 -1
- package/src/manager/router.ts +277 -1657
- package/src/manager-api/routes/actors-create.ts +16 -0
- package/src/manager-api/routes/actors-delete.ts +4 -0
- package/src/manager-api/routes/actors-get-by-id.ts +7 -0
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
- package/src/manager-api/routes/actors-get.ts +7 -0
- package/src/manager-api/routes/common.ts +18 -0
- package/src/mod.ts +0 -2
- package/src/registry/config.ts +1 -1
- package/src/registry/log.ts +2 -4
- package/src/registry/mod.ts +57 -24
- package/src/registry/run-config.ts +31 -33
- package/src/registry/serve.ts +4 -5
- package/src/remote-manager-driver/actor-http-client.ts +72 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +43 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +274 -0
- package/src/{drivers/engine → remote-manager-driver}/ws-proxy.ts +24 -14
- package/src/serde.ts +8 -2
- package/src/test/log.ts +1 -3
- package/src/test/mod.ts +17 -16
- package/dist/tsup/chunk-2CRLFV6Z.cjs +0 -202
- package/dist/tsup/chunk-2CRLFV6Z.cjs.map +0 -1
- package/dist/tsup/chunk-3H7O2A7I.js.map +0 -1
- package/dist/tsup/chunk-42I3OZ3Q.js +0 -15
- package/dist/tsup/chunk-42I3OZ3Q.js.map +0 -1
- package/dist/tsup/chunk-4NSUQZ2H.js.map +0 -1
- package/dist/tsup/chunk-6PDXBYI5.js.map +0 -1
- package/dist/tsup/chunk-6WKQDDUD.cjs.map +0 -1
- package/dist/tsup/chunk-CTBOSFUH.cjs +0 -116
- package/dist/tsup/chunk-CTBOSFUH.cjs.map +0 -1
- package/dist/tsup/chunk-EGVZZFE2.js +0 -2857
- package/dist/tsup/chunk-EGVZZFE2.js.map +0 -1
- package/dist/tsup/chunk-FCCPJNMA.cjs.map +0 -1
- package/dist/tsup/chunk-FLMTTN27.js.map +0 -1
- package/dist/tsup/chunk-GIR3AFFI.cjs.map +0 -1
- package/dist/tsup/chunk-INGJP237.js.map +0 -1
- package/dist/tsup/chunk-KJCJLKRM.js +0 -116
- package/dist/tsup/chunk-KJCJLKRM.js.map +0 -1
- package/dist/tsup/chunk-KUPQZYUQ.cjs +0 -15
- package/dist/tsup/chunk-KUPQZYUQ.cjs.map +0 -1
- package/dist/tsup/chunk-O2MBYIXO.cjs +0 -2857
- package/dist/tsup/chunk-O2MBYIXO.cjs.map +0 -1
- package/dist/tsup/chunk-OGAPU3UG.cjs.map +0 -1
- package/dist/tsup/chunk-OV6AYD4S.js +0 -4406
- package/dist/tsup/chunk-OV6AYD4S.js.map +0 -1
- package/dist/tsup/chunk-PO4VLDWA.js.map +0 -1
- package/dist/tsup/chunk-R2OPSKIV.cjs.map +0 -1
- package/dist/tsup/chunk-TZJKSBUQ.cjs.map +0 -1
- package/dist/tsup/chunk-UBUC5C3G.cjs +0 -189
- package/dist/tsup/chunk-UBUC5C3G.cjs.map +0 -1
- package/dist/tsup/chunk-UIM22YJL.cjs +0 -4406
- package/dist/tsup/chunk-UIM22YJL.cjs.map +0 -1
- package/dist/tsup/chunk-URVFQMYI.cjs +0 -230
- package/dist/tsup/chunk-URVFQMYI.cjs.map +0 -1
- package/dist/tsup/chunk-UVUPOS46.js +0 -230
- package/dist/tsup/chunk-UVUPOS46.js.map +0 -1
- package/dist/tsup/chunk-VRRHBNJC.js +0 -189
- package/dist/tsup/chunk-VRRHBNJC.js.map +0 -1
- package/dist/tsup/chunk-XFSS33EQ.js +0 -202
- package/dist/tsup/chunk-XFSS33EQ.js.map +0 -1
- package/src/client/http-client-driver.ts +0 -326
- package/src/driver-test-suite/test-inline-client-driver.ts +0 -402
- package/src/driver-test-suite/tests/actor-auth.ts +0 -591
- package/src/drivers/engine/api-endpoints.ts +0 -128
- package/src/drivers/engine/api-utils.ts +0 -70
- package/src/drivers/engine/manager-driver.ts +0 -391
- package/src/inline-client-driver/log.ts +0 -7
- package/src/inline-client-driver/mod.ts +0 -385
- package/src/manager/auth.ts +0 -121
- /package/src/{drivers/engine → actor}/keys.test.ts +0 -0
- /package/src/{drivers/engine → actor}/keys.ts +0 -0
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import * as cbor from "cbor-x";
|
|
2
|
-
import type { Context as HonoContext } from "hono";
|
|
3
|
-
import type { WebSocket } from "ws";
|
|
4
|
-
import type { Encoding } from "@/actor/protocol/serde";
|
|
5
|
-
import {
|
|
6
|
-
HEADER_ACTOR_QUERY,
|
|
7
|
-
HEADER_CONN_PARAMS,
|
|
8
|
-
HEADER_ENCODING,
|
|
9
|
-
} from "@/actor/router-endpoints";
|
|
10
|
-
import { assertUnreachable } from "@/actor/utils";
|
|
11
|
-
import type { ClientDriver } from "@/client/client";
|
|
12
|
-
import { ActorError as ClientActorError } from "@/client/errors";
|
|
13
|
-
import type { Transport } from "@/client/mod";
|
|
14
|
-
import type { UniversalEventSource } from "@/common/eventsource-interface";
|
|
15
|
-
import { importWebSocket } from "@/common/websocket";
|
|
16
|
-
import type { ActorQuery } from "@/manager/protocol/query";
|
|
17
|
-
import type {
|
|
18
|
-
TestInlineDriverCallRequest,
|
|
19
|
-
TestInlineDriverCallResponse,
|
|
20
|
-
} from "@/manager/router";
|
|
21
|
-
import type * as protocol from "@/schemas/client-protocol/mod";
|
|
22
|
-
import { logger } from "./log";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Creates a client driver used for testing the inline client driver. This will send a request to the HTTP server which will then internally call the internal client and return the response.
|
|
26
|
-
*/
|
|
27
|
-
export function createTestInlineClientDriver(
|
|
28
|
-
endpoint: string,
|
|
29
|
-
transport: Transport,
|
|
30
|
-
): ClientDriver {
|
|
31
|
-
return {
|
|
32
|
-
action: async <Args extends Array<unknown> = unknown[], Response = unknown>(
|
|
33
|
-
_c: HonoContext | undefined,
|
|
34
|
-
actorQuery: ActorQuery,
|
|
35
|
-
encoding: Encoding,
|
|
36
|
-
params: unknown,
|
|
37
|
-
name: string,
|
|
38
|
-
args: Args,
|
|
39
|
-
): Promise<Response> => {
|
|
40
|
-
return makeInlineRequest<Response>(
|
|
41
|
-
endpoint,
|
|
42
|
-
encoding,
|
|
43
|
-
transport,
|
|
44
|
-
"action",
|
|
45
|
-
[undefined, actorQuery, encoding, params, name, args],
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
resolveActorId: async (
|
|
50
|
-
_c: HonoContext | undefined,
|
|
51
|
-
actorQuery: ActorQuery,
|
|
52
|
-
encodingKind: Encoding,
|
|
53
|
-
params: unknown,
|
|
54
|
-
): Promise<string> => {
|
|
55
|
-
return makeInlineRequest<string>(
|
|
56
|
-
endpoint,
|
|
57
|
-
encodingKind,
|
|
58
|
-
transport,
|
|
59
|
-
"resolveActorId",
|
|
60
|
-
[undefined, actorQuery, encodingKind, params],
|
|
61
|
-
);
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
connectWebSocket: async (
|
|
65
|
-
_c: HonoContext | undefined,
|
|
66
|
-
actorQuery: ActorQuery,
|
|
67
|
-
encodingKind: Encoding,
|
|
68
|
-
params: unknown,
|
|
69
|
-
): Promise<WebSocket> => {
|
|
70
|
-
const WebSocket = await importWebSocket();
|
|
71
|
-
|
|
72
|
-
logger().debug("creating websocket connection via test inline driver", {
|
|
73
|
-
actorQuery,
|
|
74
|
-
encodingKind,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Create WebSocket connection to the test endpoint
|
|
78
|
-
const wsUrl = new URL(
|
|
79
|
-
`${endpoint}/registry/.test/inline-driver/connect-websocket`,
|
|
80
|
-
);
|
|
81
|
-
wsUrl.searchParams.set("actorQuery", JSON.stringify(actorQuery));
|
|
82
|
-
if (params !== undefined)
|
|
83
|
-
wsUrl.searchParams.set("params", JSON.stringify(params));
|
|
84
|
-
wsUrl.searchParams.set("encodingKind", encodingKind);
|
|
85
|
-
|
|
86
|
-
// Convert http/https to ws/wss
|
|
87
|
-
const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
88
|
-
const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}${wsUrl.search}`;
|
|
89
|
-
|
|
90
|
-
logger().debug("connecting to websocket", { url: finalWsUrl });
|
|
91
|
-
|
|
92
|
-
// Create and return the WebSocket
|
|
93
|
-
// Node & browser WebSocket types are incompatible
|
|
94
|
-
const ws = new WebSocket(finalWsUrl, [
|
|
95
|
-
// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
96
|
-
"rivetkit",
|
|
97
|
-
]) as any;
|
|
98
|
-
|
|
99
|
-
return ws;
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
connectSse: async (
|
|
103
|
-
_c: HonoContext | undefined,
|
|
104
|
-
actorQuery: ActorQuery,
|
|
105
|
-
encodingKind: Encoding,
|
|
106
|
-
params: unknown,
|
|
107
|
-
): Promise<UniversalEventSource> => {
|
|
108
|
-
logger().debug("creating sse connection via test inline driver", {
|
|
109
|
-
actorQuery,
|
|
110
|
-
encodingKind,
|
|
111
|
-
params,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Dynamically import EventSource if needed
|
|
115
|
-
const EventSourceImport = await import("eventsource");
|
|
116
|
-
// Handle both ES modules (default) and CommonJS export patterns
|
|
117
|
-
const EventSourceConstructor =
|
|
118
|
-
(EventSourceImport as any).default || EventSourceImport;
|
|
119
|
-
|
|
120
|
-
// Encode parameters for the URL
|
|
121
|
-
const actorQueryParam = encodeURIComponent(JSON.stringify(actorQuery));
|
|
122
|
-
const encodingParam = encodeURIComponent(encodingKind);
|
|
123
|
-
const paramsParam = params
|
|
124
|
-
? encodeURIComponent(JSON.stringify(params))
|
|
125
|
-
: null;
|
|
126
|
-
|
|
127
|
-
// Create SSE connection URL
|
|
128
|
-
const sseUrl = new URL(
|
|
129
|
-
`${endpoint}/registry/.test/inline-driver/connect-sse`,
|
|
130
|
-
);
|
|
131
|
-
sseUrl.searchParams.set("actorQueryRaw", actorQueryParam);
|
|
132
|
-
sseUrl.searchParams.set("encodingKind", encodingParam);
|
|
133
|
-
if (paramsParam) {
|
|
134
|
-
sseUrl.searchParams.set("params", paramsParam);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
logger().debug("connecting to sse", { url: sseUrl.toString() });
|
|
138
|
-
|
|
139
|
-
// Create and return the EventSource
|
|
140
|
-
const eventSource = new EventSourceConstructor(sseUrl.toString());
|
|
141
|
-
|
|
142
|
-
// Wait for the connection to be established before returning
|
|
143
|
-
await new Promise<void>((resolve, reject) => {
|
|
144
|
-
eventSource.onopen = () => {
|
|
145
|
-
logger().debug("sse connection established");
|
|
146
|
-
resolve();
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
eventSource.onerror = (event: Event) => {
|
|
150
|
-
logger().error("sse connection failed", { event });
|
|
151
|
-
reject(new Error("Failed to establish SSE connection"));
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// Set a timeout in case the connection never establishes
|
|
155
|
-
setTimeout(() => {
|
|
156
|
-
if (eventSource.readyState !== EventSourceConstructor.OPEN) {
|
|
157
|
-
reject(new Error("SSE connection timed out"));
|
|
158
|
-
}
|
|
159
|
-
}, 10000); // 10 second timeout
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return eventSource as UniversalEventSource;
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
sendHttpMessage: async (
|
|
166
|
-
_c: HonoContext | undefined,
|
|
167
|
-
actorId: string,
|
|
168
|
-
encoding: Encoding,
|
|
169
|
-
connectionId: string,
|
|
170
|
-
connectionToken: string,
|
|
171
|
-
message: protocol.ToServer,
|
|
172
|
-
): Promise<void> => {
|
|
173
|
-
logger().debug("sending http message via test inline driver", {
|
|
174
|
-
actorId,
|
|
175
|
-
encoding,
|
|
176
|
-
connectionId,
|
|
177
|
-
transport,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const result = await fetch(
|
|
181
|
-
`${endpoint}/registry/.test/inline-driver/call`,
|
|
182
|
-
{
|
|
183
|
-
method: "POST",
|
|
184
|
-
headers: {
|
|
185
|
-
"Content-Type": "application/json",
|
|
186
|
-
},
|
|
187
|
-
body: JSON.stringify({
|
|
188
|
-
encoding,
|
|
189
|
-
transport,
|
|
190
|
-
method: "sendHttpMessage",
|
|
191
|
-
args: [
|
|
192
|
-
undefined,
|
|
193
|
-
actorId,
|
|
194
|
-
encoding,
|
|
195
|
-
connectionId,
|
|
196
|
-
connectionToken,
|
|
197
|
-
message,
|
|
198
|
-
],
|
|
199
|
-
} satisfies TestInlineDriverCallRequest),
|
|
200
|
-
},
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
if (!result.ok) {
|
|
204
|
-
throw new Error(`Failed to send HTTP message: ${result.statusText}`);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Discard response
|
|
208
|
-
await result.body?.cancel();
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
rawHttpRequest: async (
|
|
212
|
-
_c: HonoContext | undefined,
|
|
213
|
-
actorQuery: ActorQuery,
|
|
214
|
-
encoding: Encoding,
|
|
215
|
-
params: unknown,
|
|
216
|
-
path: string,
|
|
217
|
-
init: RequestInit,
|
|
218
|
-
): Promise<Response> => {
|
|
219
|
-
// Normalize path to match other drivers
|
|
220
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
221
|
-
|
|
222
|
-
logger().debug("sending raw http request via test inline driver", {
|
|
223
|
-
actorQuery,
|
|
224
|
-
encoding,
|
|
225
|
-
path: normalizedPath,
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// Use the dedicated raw HTTP endpoint
|
|
229
|
-
const url = `${endpoint}/registry/.test/inline-driver/raw-http/${normalizedPath}`;
|
|
230
|
-
|
|
231
|
-
logger().debug("rewriting http url", {
|
|
232
|
-
from: path,
|
|
233
|
-
to: url,
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// Merge headers with our metadata
|
|
237
|
-
const headers = new Headers(init.headers);
|
|
238
|
-
headers.set(HEADER_ACTOR_QUERY, JSON.stringify(actorQuery));
|
|
239
|
-
headers.set(HEADER_ENCODING, encoding);
|
|
240
|
-
if (params !== undefined) {
|
|
241
|
-
headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Forward the request directly
|
|
245
|
-
const response = await fetch(url, {
|
|
246
|
-
...init,
|
|
247
|
-
headers,
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
// Check if it's an error response from our handler
|
|
251
|
-
if (
|
|
252
|
-
!response.ok &&
|
|
253
|
-
response.headers.get("content-type")?.includes("application/json")
|
|
254
|
-
) {
|
|
255
|
-
try {
|
|
256
|
-
// Clone the response to avoid consuming the body
|
|
257
|
-
const clonedResponse = response.clone();
|
|
258
|
-
const errorData = (await clonedResponse.json()) as any;
|
|
259
|
-
if (errorData.error) {
|
|
260
|
-
// Handle both error formats:
|
|
261
|
-
// 1. { error: { code, message, metadata } } - structured format
|
|
262
|
-
// 2. { error: "message" } - simple string format (from custom onFetch handlers)
|
|
263
|
-
if (typeof errorData.error === "object") {
|
|
264
|
-
throw new ClientActorError(
|
|
265
|
-
errorData.error.code,
|
|
266
|
-
errorData.error.message,
|
|
267
|
-
errorData.error.metadata,
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
// For simple string errors, just return the response as-is
|
|
271
|
-
// This allows custom onFetch handlers to return their own error formats
|
|
272
|
-
}
|
|
273
|
-
} catch (e) {
|
|
274
|
-
// If it's not our error format, just return the response as-is
|
|
275
|
-
if (!(e instanceof ClientActorError)) {
|
|
276
|
-
return response;
|
|
277
|
-
}
|
|
278
|
-
throw e;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return response;
|
|
283
|
-
},
|
|
284
|
-
|
|
285
|
-
rawWebSocket: async (
|
|
286
|
-
_c: HonoContext | undefined,
|
|
287
|
-
actorQuery: ActorQuery,
|
|
288
|
-
encoding: Encoding,
|
|
289
|
-
params: unknown,
|
|
290
|
-
path: string,
|
|
291
|
-
protocols: string | string[] | undefined,
|
|
292
|
-
): Promise<WebSocket> => {
|
|
293
|
-
logger().debug("test inline driver rawWebSocket called");
|
|
294
|
-
const WebSocket = await importWebSocket();
|
|
295
|
-
|
|
296
|
-
// Normalize path to match other drivers
|
|
297
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
298
|
-
|
|
299
|
-
logger().debug(
|
|
300
|
-
"creating raw websocket connection via test inline driver",
|
|
301
|
-
{
|
|
302
|
-
actorQuery,
|
|
303
|
-
encoding,
|
|
304
|
-
path: normalizedPath,
|
|
305
|
-
protocols,
|
|
306
|
-
},
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
// Create WebSocket connection to the test endpoint
|
|
310
|
-
const wsUrl = new URL(
|
|
311
|
-
`${endpoint}/registry/.test/inline-driver/raw-websocket`,
|
|
312
|
-
);
|
|
313
|
-
wsUrl.searchParams.set("actorQuery", JSON.stringify(actorQuery));
|
|
314
|
-
if (params !== undefined)
|
|
315
|
-
wsUrl.searchParams.set("params", JSON.stringify(params));
|
|
316
|
-
wsUrl.searchParams.set("encodingKind", encoding);
|
|
317
|
-
wsUrl.searchParams.set("path", normalizedPath);
|
|
318
|
-
if (protocols !== undefined)
|
|
319
|
-
wsUrl.searchParams.set("protocols", JSON.stringify(protocols));
|
|
320
|
-
|
|
321
|
-
// Convert http/https to ws/wss
|
|
322
|
-
const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
323
|
-
const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}${wsUrl.search}`;
|
|
324
|
-
|
|
325
|
-
logger().debug("connecting to raw websocket", { url: finalWsUrl });
|
|
326
|
-
|
|
327
|
-
logger().debug("rewriting websocket url", {
|
|
328
|
-
from: path,
|
|
329
|
-
to: finalWsUrl,
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
// Create and return the WebSocket
|
|
333
|
-
// Node & browser WebSocket types are incompatible
|
|
334
|
-
const ws = new WebSocket(finalWsUrl, [
|
|
335
|
-
// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts
|
|
336
|
-
"rivetkit",
|
|
337
|
-
]) as any;
|
|
338
|
-
|
|
339
|
-
logger().debug("test inline driver created websocket", {
|
|
340
|
-
readyState: ws.readyState,
|
|
341
|
-
url: ws.url,
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
return ws;
|
|
345
|
-
},
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
async function makeInlineRequest<T>(
|
|
350
|
-
endpoint: string,
|
|
351
|
-
encoding: Encoding,
|
|
352
|
-
transport: Transport,
|
|
353
|
-
method: string,
|
|
354
|
-
args: unknown[],
|
|
355
|
-
): Promise<T> {
|
|
356
|
-
logger().debug("sending inline request", {
|
|
357
|
-
encoding,
|
|
358
|
-
transport,
|
|
359
|
-
method,
|
|
360
|
-
args,
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
// Call driver
|
|
364
|
-
const response = await fetch(
|
|
365
|
-
`${endpoint}/registry/.test/inline-driver/call`,
|
|
366
|
-
{
|
|
367
|
-
method: "POST",
|
|
368
|
-
headers: {
|
|
369
|
-
"Content-Type": "application/json",
|
|
370
|
-
},
|
|
371
|
-
body: cbor.encode({
|
|
372
|
-
encoding,
|
|
373
|
-
transport,
|
|
374
|
-
method,
|
|
375
|
-
args,
|
|
376
|
-
} satisfies TestInlineDriverCallRequest),
|
|
377
|
-
},
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
if (!response.ok) {
|
|
381
|
-
throw new Error(`Failed to call inline ${method}: ${response.statusText}`);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// Parse response
|
|
385
|
-
const buffer = await response.arrayBuffer();
|
|
386
|
-
const callResponse: TestInlineDriverCallResponse<T> = cbor.decode(
|
|
387
|
-
new Uint8Array(buffer),
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
// Throw or OK
|
|
391
|
-
if ("ok" in callResponse) {
|
|
392
|
-
return callResponse.ok;
|
|
393
|
-
} else if ("err" in callResponse) {
|
|
394
|
-
throw new ClientActorError(
|
|
395
|
-
callResponse.err.code,
|
|
396
|
-
callResponse.err.message,
|
|
397
|
-
callResponse.err.metadata,
|
|
398
|
-
);
|
|
399
|
-
} else {
|
|
400
|
-
assertUnreachable(callResponse);
|
|
401
|
-
}
|
|
402
|
-
}
|