@livestore/common-cf 0.0.0-snapshot-1f9c9c089ebe6383b200e90029453307ef7a8ae2 → 0.0.0-snapshot-7594f44e1dae838d58f3489ee25a5df735c2dcb6
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.
|
@@ -14,8 +14,18 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @see {@link https://developers.cloudflare.com/durable-objects/best-practices/websockets/ Cloudflare WebSocket Best Practices}
|
|
16
16
|
*/
|
|
17
|
-
import { Layer, Mailbox, RpcMessage, RpcServer } from '@livestore/utils/effect';
|
|
17
|
+
import { Context, Layer, Mailbox, RpcMessage, RpcServer } from '@livestore/utils/effect';
|
|
18
18
|
import type * as CfTypes from '../cf-types.ts';
|
|
19
|
+
declare const WsContext_base: Context.TagClass<WsContext, "WsContext", {
|
|
20
|
+
readonly ws: CfTypes.WebSocket;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Context service providing access to the current WebSocket.
|
|
24
|
+
* This is useful for reading WebSocket attachment data (e.g., forwarded headers)
|
|
25
|
+
* inside RPC handlers.
|
|
26
|
+
*/
|
|
27
|
+
export declare class WsContext extends WsContext_base {
|
|
28
|
+
}
|
|
19
29
|
/**
|
|
20
30
|
* Configuration options for setting up WebSocket RPC on a Durable Object.
|
|
21
31
|
*/
|
|
@@ -28,8 +38,22 @@ export interface DurableObjectWebSocketRpcConfig {
|
|
|
28
38
|
* - 'accept': Use traditional WebSocket handling (not yet implemented)
|
|
29
39
|
*/
|
|
30
40
|
webSocketMode: 'hibernate' | 'accept';
|
|
31
|
-
/**
|
|
32
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Effect RPC layer that requires `RpcServer.Protocol` (and `WsContext` if used)
|
|
43
|
+
* and provides the RPC server runtime.
|
|
44
|
+
*
|
|
45
|
+
* This is typically created by:
|
|
46
|
+
* ```typescript
|
|
47
|
+
* RpcServer.layer(MyRpcs).pipe(Layer.provide(handlersLayer))
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* `WsContext` is provided by the WebSocket protocol layer, so handlers can access
|
|
51
|
+
* WebSocket attachment data (e.g., forwarded headers stored after WebSocket upgrade).
|
|
52
|
+
*
|
|
53
|
+
* The layer requirements (`RIn`) must be a subset of `RpcServer.Protocol | WsContext`,
|
|
54
|
+
* which are both provided by the WebSocket protocol layer.
|
|
55
|
+
*/
|
|
56
|
+
rpcLayer: Layer.Layer<never, never, RpcServer.Protocol | WsContext>;
|
|
33
57
|
/** Function to get access to incoming requests */
|
|
34
58
|
onMessage?: (msg: RpcMessage.FromClientEncoded, ws: CfTypes.WebSocket) => void;
|
|
35
59
|
mainLayer?: Layer.Layer<never, never, never>;
|
|
@@ -107,4 +131,5 @@ export interface WsRpcServerArgs {
|
|
|
107
131
|
/** Mailbox queue for receiving incoming messages from the WebSocket */
|
|
108
132
|
incomingQueue: Mailbox.Mailbox<Uint8Array<ArrayBufferLike> | string>;
|
|
109
133
|
}
|
|
134
|
+
export {};
|
|
110
135
|
//# sourceMappingURL=ws-rpc-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-rpc-server.d.ts","sourceRoot":"","sources":["../../src/ws-rpc/ws-rpc-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"ws-rpc-server.d.ts","sourceRoot":"","sources":["../../src/ws-rpc/ws-rpc-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EACL,OAAO,EAIP,KAAK,EAGL,OAAO,EACP,UAAU,EAEV,SAAS,EAGV,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAA;;iBAOoC,OAAO,CAAC,SAAS;;AALnG;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAyE;CAAG;AAE3G;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,+CAA+C;IAC/C,MAAM,EAAE,OAAO,CAAC,aAAa,CAAA;IAC7B;;;;OAIG;IACH,aAAa,EAAE,WAAW,GAAG,QAAQ,CAAA;IACrC;;;;;;;;;;;;;;OAcG;IACH,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;IACnE,kDAAkD;IAClD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,iBAAiB,EAAE,EAAE,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAA;IAC9E,SAAS,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;CAC7C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,eAAO,MAAM,8BAA8B,GAAI,4DAM5C,+BAA+B;;;CAsFjC,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC,SAAS,CAAA;IACrB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,iBAAiB,EAAE,EAAE,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAA;IAClF,uEAAuE;IACvE,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,CAAA;CACrE"}
|
|
@@ -15,7 +15,14 @@
|
|
|
15
15
|
* @see {@link https://developers.cloudflare.com/durable-objects/best-practices/websockets/ Cloudflare WebSocket Best Practices}
|
|
16
16
|
*/
|
|
17
17
|
import { notYetImplemented, omitUndefineds } from '@livestore/utils';
|
|
18
|
-
import { constVoid, Effect, Exit, Layer, Logger, LogLevel, Mailbox, RpcMessage, RpcSerialization, RpcServer, Scope, Stream, } from '@livestore/utils/effect';
|
|
18
|
+
import { Context, constVoid, Effect, Exit, Layer, Logger, LogLevel, Mailbox, RpcMessage, RpcSerialization, RpcServer, Scope, Stream, } from '@livestore/utils/effect';
|
|
19
|
+
/**
|
|
20
|
+
* Context service providing access to the current WebSocket.
|
|
21
|
+
* This is useful for reading WebSocket attachment data (e.g., forwarded headers)
|
|
22
|
+
* inside RPC handlers.
|
|
23
|
+
*/
|
|
24
|
+
export class WsContext extends Context.Tag('WsContext')() {
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* Sets up WebSocket RPC functionality on a Cloudflare Durable Object with hibernation support.
|
|
21
28
|
*
|
|
@@ -133,12 +140,15 @@ export const setupDurableObjectWebSocketRpc = ({ doSelf, rpcLayer, webSocketMode
|
|
|
133
140
|
* This layer handles the low-level WebSocket protocol details for RPC communication,
|
|
134
141
|
* including message serialization, routing, and error handling.
|
|
135
142
|
*
|
|
143
|
+
* Also provides `WsContext` with the current WebSocket so handlers can access
|
|
144
|
+
* WebSocket attachment data (e.g., forwarded headers).
|
|
145
|
+
*
|
|
136
146
|
* @param args Configuration for WebSocket RPC protocol
|
|
137
|
-
* @returns Effect layer that provides RPC server protocol functionality
|
|
147
|
+
* @returns Effect layer that provides RPC server protocol functionality and WsContext
|
|
138
148
|
*
|
|
139
149
|
* @internal This is typically used internally by `setupDurableObjectWebSocketRpc`
|
|
140
150
|
*/
|
|
141
|
-
export const layerRpcServerWebsocket = (args) => Layer.scoped(RpcServer.Protocol, makeSocketProtocol(args));
|
|
151
|
+
export const layerRpcServerWebsocket = (args) => Layer.mergeAll(Layer.scoped(RpcServer.Protocol, makeSocketProtocol(args)), Layer.succeed(WsContext, { ws: args.ws }));
|
|
142
152
|
/**
|
|
143
153
|
* Creates the low-level RPC protocol implementation for WebSocket communication.
|
|
144
154
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws-rpc-server.js","sourceRoot":"","sources":["../../src/ws-rpc/ws-rpc-server.ts"],"names":[],"mappings":"AAAA;;;;;;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AA;YACxF,CAAC;QACH,CAAC,CAAC,EACF,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,IAAI,CACZ,CAAA;QAED,+BAA+B;QAC/B,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;YACxC,WAAW;YACX,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC5D,GAAG,CAAC,SAAS;gBACX,OAAO,MAAM,CAAC,IAAI,CAAA;YACpB,CAAC;YACD,yBAAyB;YACzB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAwB,CAAC;YAClE,cAAc,EAAE,MAAM,CAAC,WAAW;YAClC,WAAW,EAAE,IAAI;YACjB,qBAAqB,EAAE,KAAK;YAC5B,uBAAuB,EAAE,IAAI;SAC9B,CAAC,CAAC,CAAA;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/common-cf",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-7594f44e1dae838d58f3489ee25a5df735c2dcb6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@cloudflare/workers-types": "4.20251118.0",
|
|
12
|
-
"@livestore/
|
|
13
|
-
"@livestore/
|
|
12
|
+
"@livestore/common": "0.0.0-snapshot-7594f44e1dae838d58f3489ee25a5df735c2dcb6",
|
|
13
|
+
"@livestore/utils": "0.0.0-snapshot-7594f44e1dae838d58f3489ee25a5df735c2dcb6"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"vitest": "3.2.4",
|
|
17
17
|
"wrangler": "4.42.2",
|
|
18
|
-
"@livestore/utils-dev": "0.0.0-snapshot-
|
|
18
|
+
"@livestore/utils-dev": "0.0.0-snapshot-7594f44e1dae838d58f3489ee25a5df735c2dcb6"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { notYetImplemented, omitUndefineds } from '@livestore/utils'
|
|
19
19
|
import {
|
|
20
|
+
Context,
|
|
20
21
|
constVoid,
|
|
21
22
|
Effect,
|
|
22
23
|
Exit,
|
|
@@ -32,6 +33,13 @@ import {
|
|
|
32
33
|
} from '@livestore/utils/effect'
|
|
33
34
|
import type * as CfTypes from '../cf-types.ts'
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Context service providing access to the current WebSocket.
|
|
38
|
+
* This is useful for reading WebSocket attachment data (e.g., forwarded headers)
|
|
39
|
+
* inside RPC handlers.
|
|
40
|
+
*/
|
|
41
|
+
export class WsContext extends Context.Tag('WsContext')<WsContext, { readonly ws: CfTypes.WebSocket }>() {}
|
|
42
|
+
|
|
35
43
|
/**
|
|
36
44
|
* Configuration options for setting up WebSocket RPC on a Durable Object.
|
|
37
45
|
*/
|
|
@@ -44,8 +52,22 @@ export interface DurableObjectWebSocketRpcConfig {
|
|
|
44
52
|
* - 'accept': Use traditional WebSocket handling (not yet implemented)
|
|
45
53
|
*/
|
|
46
54
|
webSocketMode: 'hibernate' | 'accept'
|
|
47
|
-
/**
|
|
48
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Effect RPC layer that requires `RpcServer.Protocol` (and `WsContext` if used)
|
|
57
|
+
* and provides the RPC server runtime.
|
|
58
|
+
*
|
|
59
|
+
* This is typically created by:
|
|
60
|
+
* ```typescript
|
|
61
|
+
* RpcServer.layer(MyRpcs).pipe(Layer.provide(handlersLayer))
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* `WsContext` is provided by the WebSocket protocol layer, so handlers can access
|
|
65
|
+
* WebSocket attachment data (e.g., forwarded headers stored after WebSocket upgrade).
|
|
66
|
+
*
|
|
67
|
+
* The layer requirements (`RIn`) must be a subset of `RpcServer.Protocol | WsContext`,
|
|
68
|
+
* which are both provided by the WebSocket protocol layer.
|
|
69
|
+
*/
|
|
70
|
+
rpcLayer: Layer.Layer<never, never, RpcServer.Protocol | WsContext>
|
|
49
71
|
/** Function to get access to incoming requests */
|
|
50
72
|
onMessage?: (msg: RpcMessage.FromClientEncoded, ws: CfTypes.WebSocket) => void
|
|
51
73
|
mainLayer?: Layer.Layer<never, never, never>
|
|
@@ -221,13 +243,16 @@ export interface WsRpcServerArgs {
|
|
|
221
243
|
* This layer handles the low-level WebSocket protocol details for RPC communication,
|
|
222
244
|
* including message serialization, routing, and error handling.
|
|
223
245
|
*
|
|
246
|
+
* Also provides `WsContext` with the current WebSocket so handlers can access
|
|
247
|
+
* WebSocket attachment data (e.g., forwarded headers).
|
|
248
|
+
*
|
|
224
249
|
* @param args Configuration for WebSocket RPC protocol
|
|
225
|
-
* @returns Effect layer that provides RPC server protocol functionality
|
|
250
|
+
* @returns Effect layer that provides RPC server protocol functionality and WsContext
|
|
226
251
|
*
|
|
227
252
|
* @internal This is typically used internally by `setupDurableObjectWebSocketRpc`
|
|
228
253
|
*/
|
|
229
254
|
export const layerRpcServerWebsocket = (args: WsRpcServerArgs) =>
|
|
230
|
-
Layer.scoped(RpcServer.Protocol, makeSocketProtocol(args))
|
|
255
|
+
Layer.mergeAll(Layer.scoped(RpcServer.Protocol, makeSocketProtocol(args)), Layer.succeed(WsContext, { ws: args.ws }))
|
|
231
256
|
|
|
232
257
|
/**
|
|
233
258
|
* Creates the low-level RPC protocol implementation for WebSocket communication.
|