@orpc/server 1.14.11 → 1.14.13
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 +98 -52
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +40 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +21 -45
- package/dist/adapters/crossws/index.d.ts +21 -45
- package/dist/adapters/crossws/index.mjs +18 -40
- package/dist/adapters/fastify/index.d.mts +53 -0
- package/dist/adapters/fastify/index.d.ts +53 -0
- package/dist/adapters/fastify/index.mjs +52 -0
- package/dist/adapters/fetch/index.d.mts +96 -64
- package/dist/adapters/fetch/index.d.ts +96 -64
- package/dist/adapters/fetch/index.mjs +139 -34
- package/dist/adapters/message-port/index.d.mts +34 -49
- package/dist/adapters/message-port/index.d.ts +34 -49
- package/dist/adapters/message-port/index.mjs +37 -68
- package/dist/adapters/node/index.d.mts +71 -63
- package/dist/adapters/node/index.d.ts +71 -63
- package/dist/adapters/node/index.mjs +113 -36
- package/dist/adapters/standard/index.d.mts +18 -16
- package/dist/adapters/standard/index.d.ts +18 -16
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +14 -12
- package/dist/adapters/standard-peer/index.d.ts +14 -12
- package/dist/adapters/standard-peer/index.mjs +21 -2
- package/dist/adapters/websocket/index.d.mts +38 -53
- package/dist/adapters/websocket/index.d.ts +38 -53
- package/dist/adapters/websocket/index.mjs +42 -59
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +41 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +5 -13
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +770 -166
- package/dist/index.d.ts +770 -166
- package/dist/index.mjs +399 -306
- package/dist/plugins/index.d.mts +121 -214
- package/dist/plugins/index.d.ts +121 -214
- package/dist/plugins/index.mjs +214 -576
- package/dist/shared/server.7cEtMB30.d.ts +74 -0
- package/dist/shared/server.B8gYOD5g.d.mts +12 -0
- package/dist/shared/server.BqadksTP.d.mts +74 -0
- package/dist/shared/server.C8_sRzQB.d.mts +42 -0
- package/dist/shared/server.CMf4nKky.mjs +230 -0
- package/dist/shared/server.ChyoA9XY.d.ts +42 -0
- package/dist/shared/server.D8IXzfqT.d.ts +32 -0
- package/dist/shared/server.DEBcqOjg.mjs +418 -0
- package/dist/shared/{server.W91HSRkE.mjs → server.DZ5BIITo.mjs} +2 -2
- package/dist/shared/server.DzE6WeuY.d.mts +32 -0
- package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
- package/dist/shared/server.TEVCLCFC.mjs +39 -0
- package/dist/shared/server.qKsRrdxW.d.mts +193 -0
- package/dist/shared/server.qKsRrdxW.d.ts +193 -0
- package/package.json +56 -26
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.d.ts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/shared/server.15O7oC1p.d.mts +0 -61
- package/dist/shared/server.B4BnEWWm.d.mts +0 -67
- package/dist/shared/server.BhsVw7m7.d.ts +0 -104
- package/dist/shared/server.BoiFpNT7.mjs +0 -224
- package/dist/shared/server.COPVXhDG.mjs +0 -271
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.CcR4kgje.d.mts +0 -206
- package/dist/shared/server.CcR4kgje.d.ts +0 -206
- package/dist/shared/server.CnN50DHH.d.ts +0 -67
- package/dist/shared/server.DBs0rrf9.mjs +0 -41
- package/dist/shared/server.DDFizwfU.d.mts +0 -104
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.DofEOwf-.mjs +0 -237
- package/dist/shared/server.m3szVJGU.d.ts +0 -61
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { ServerPeer, EncodedMessage, ServerPeerHandleRequestFn } from '@orpc/standard-server-peer';
|
|
2
|
+
import { C as Context } from '../../shared/server.qKsRrdxW.mjs';
|
|
3
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.B8gYOD5g.mjs';
|
|
4
|
+
import { f as StandardHandler } from '../../shared/server.BqadksTP.mjs';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/contract';
|
|
7
|
+
import '@orpc/shared';
|
|
8
|
+
import '@orpc/standard-server';
|
|
7
9
|
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare function
|
|
10
|
+
type HandleStandardServerPeerMessageOptions<T extends Context> = Omit<FriendlyStandardHandleOptions<T>, 'prefix'>;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `createServerPeerRequestHandleFn` instead.
|
|
13
|
+
*/
|
|
14
|
+
declare function handleStandardServerPeerMessage<T extends Context>(handler: StandardHandler<T>, peer: ServerPeer, message: EncodedMessage, options: HandleStandardServerPeerMessageOptions<T>): Promise<void>;
|
|
15
|
+
declare function createServerPeerHandleRequestFn<T extends Context>(handler: StandardHandler<T>, options: HandleStandardServerPeerMessageOptions<T>): ServerPeerHandleRequestFn;
|
|
14
16
|
|
|
15
|
-
export {
|
|
16
|
-
export type {
|
|
17
|
+
export { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
|
|
18
|
+
export type { HandleStandardServerPeerMessageOptions };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { ServerPeer, EncodedMessage, ServerPeerHandleRequestFn } from '@orpc/standard-server-peer';
|
|
2
|
+
import { C as Context } from '../../shared/server.qKsRrdxW.js';
|
|
3
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.EfTOZ2Q7.js';
|
|
4
|
+
import { f as StandardHandler } from '../../shared/server.7cEtMB30.js';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/contract';
|
|
7
|
+
import '@orpc/shared';
|
|
8
|
+
import '@orpc/standard-server';
|
|
7
9
|
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare function
|
|
10
|
+
type HandleStandardServerPeerMessageOptions<T extends Context> = Omit<FriendlyStandardHandleOptions<T>, 'prefix'>;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `createServerPeerRequestHandleFn` instead.
|
|
13
|
+
*/
|
|
14
|
+
declare function handleStandardServerPeerMessage<T extends Context>(handler: StandardHandler<T>, peer: ServerPeer, message: EncodedMessage, options: HandleStandardServerPeerMessageOptions<T>): Promise<void>;
|
|
15
|
+
declare function createServerPeerHandleRequestFn<T extends Context>(handler: StandardHandler<T>, options: HandleStandardServerPeerMessageOptions<T>): ServerPeerHandleRequestFn;
|
|
14
16
|
|
|
15
|
-
export {
|
|
16
|
-
export type {
|
|
17
|
+
export { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
|
|
18
|
+
export type { HandleStandardServerPeerMessageOptions };
|
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
|
2
|
+
|
|
3
|
+
async function handleStandardServerPeerMessage(handler, peer, message, options) {
|
|
4
|
+
const [id, request] = await peer.message(message);
|
|
5
|
+
if (!request) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const handle = createServerPeerHandleRequestFn(handler, options);
|
|
9
|
+
await peer.response(id, await handle(request));
|
|
10
|
+
}
|
|
11
|
+
function createServerPeerHandleRequestFn(handler, options) {
|
|
12
|
+
return async (request) => {
|
|
13
|
+
const { response } = await handler.handle(
|
|
14
|
+
{ ...request, body: () => Promise.resolve(request.body) },
|
|
15
|
+
resolveFriendlyStandardHandleOptions(options)
|
|
16
|
+
);
|
|
17
|
+
return response ?? { status: 404, headers: {}, body: "No procedure matched" };
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
|
|
@@ -1,71 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { R as Router } from '../../shared/server.15O7oC1p.mjs';
|
|
7
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.B4BnEWWm.mjs';
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.mjs';
|
|
3
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.mjs';
|
|
4
|
+
import { f as StandardHandler } from '../../shared/server.BqadksTP.mjs';
|
|
5
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DzE6WeuY.mjs';
|
|
8
6
|
import '@orpc/client';
|
|
9
7
|
import '@orpc/contract';
|
|
10
|
-
import '@
|
|
8
|
+
import '@orpc/standard-server-peer';
|
|
9
|
+
import '../../shared/server.B8gYOD5g.mjs';
|
|
10
|
+
import '@orpc/standard-server';
|
|
11
|
+
import '@orpc/client/standard';
|
|
12
|
+
import '../../shared/server.C8_sRzQB.mjs';
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type WebSocketLike = {
|
|
17
|
-
send: (data: string | Uint8Array<ArrayBuffer>) => unknown;
|
|
18
|
-
};
|
|
19
|
-
interface WebSocketHandlerOptions<_T extends Context> {
|
|
20
|
-
/**
|
|
21
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
22
|
-
*/
|
|
23
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
14
|
+
type MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
|
|
15
|
+
declare class WebsocketHandler<T extends Context> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(standardHandler: StandardHandler<T>);
|
|
24
18
|
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
28
|
-
}
|
|
29
|
-
declare class WebSocketHandler<T extends Context> {
|
|
30
|
-
private readonly handler;
|
|
31
|
-
private readonly peers;
|
|
32
|
-
private readonly encodePeerMessageOptions;
|
|
33
|
-
private readonly decodePeerMessageOptions;
|
|
34
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
35
|
-
/**
|
|
36
|
-
* Handles a single WebSocket message.
|
|
37
|
-
*
|
|
38
|
-
* Message order matters. Call this immediately after receiving a message,
|
|
39
|
-
* before any other async work, to preserve ordering.
|
|
19
|
+
* Upgrades a WebSocket to enable handling
|
|
40
20
|
*
|
|
41
|
-
*
|
|
42
|
-
* directly (for example, `arraybuffer`).
|
|
21
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
|
43
22
|
*
|
|
44
|
-
* @
|
|
45
|
-
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
23
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
|
46
24
|
*/
|
|
47
|
-
|
|
48
|
-
matched: boolean;
|
|
49
|
-
}>;
|
|
25
|
+
upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
|
|
50
26
|
/**
|
|
51
|
-
*
|
|
27
|
+
* Handles a single message received from a WebSocket.
|
|
28
|
+
*
|
|
29
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
52
30
|
*
|
|
53
|
-
* @param ws The
|
|
31
|
+
* @param ws The WebSocket instance
|
|
32
|
+
* @param data The message payload, usually place in `event.data`
|
|
54
33
|
*/
|
|
55
|
-
|
|
34
|
+
message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
|
56
35
|
/**
|
|
57
|
-
*
|
|
36
|
+
* Closes the WebSocket peer and cleans up.
|
|
58
37
|
*
|
|
59
|
-
*
|
|
38
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
60
39
|
*/
|
|
61
|
-
|
|
40
|
+
close(ws: MinimalWebsocket): void;
|
|
62
41
|
}
|
|
63
42
|
|
|
64
|
-
interface RPCHandlerOptions<T extends Context> extends
|
|
43
|
+
interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T> {
|
|
65
44
|
}
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
/**
|
|
46
|
+
* RPC Handler for Websocket adapter
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
49
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
|
|
50
|
+
*/
|
|
51
|
+
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
52
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
68
53
|
}
|
|
69
54
|
|
|
70
|
-
export { RPCHandler,
|
|
71
|
-
export type {
|
|
55
|
+
export { RPCHandler, WebsocketHandler };
|
|
56
|
+
export type { MinimalWebsocket, RPCHandlerOptions };
|
|
@@ -1,71 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { R as Router } from '../../shared/server.m3szVJGU.js';
|
|
7
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.CnN50DHH.js';
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.js';
|
|
3
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.js';
|
|
4
|
+
import { f as StandardHandler } from '../../shared/server.7cEtMB30.js';
|
|
5
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D8IXzfqT.js';
|
|
8
6
|
import '@orpc/client';
|
|
9
7
|
import '@orpc/contract';
|
|
10
|
-
import '@
|
|
8
|
+
import '@orpc/standard-server-peer';
|
|
9
|
+
import '../../shared/server.EfTOZ2Q7.js';
|
|
10
|
+
import '@orpc/standard-server';
|
|
11
|
+
import '@orpc/client/standard';
|
|
12
|
+
import '../../shared/server.ChyoA9XY.js';
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type WebSocketLike = {
|
|
17
|
-
send: (data: string | Uint8Array<ArrayBuffer>) => unknown;
|
|
18
|
-
};
|
|
19
|
-
interface WebSocketHandlerOptions<_T extends Context> {
|
|
20
|
-
/**
|
|
21
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
22
|
-
*/
|
|
23
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
14
|
+
type MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
|
|
15
|
+
declare class WebsocketHandler<T extends Context> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(standardHandler: StandardHandler<T>);
|
|
24
18
|
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
28
|
-
}
|
|
29
|
-
declare class WebSocketHandler<T extends Context> {
|
|
30
|
-
private readonly handler;
|
|
31
|
-
private readonly peers;
|
|
32
|
-
private readonly encodePeerMessageOptions;
|
|
33
|
-
private readonly decodePeerMessageOptions;
|
|
34
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
35
|
-
/**
|
|
36
|
-
* Handles a single WebSocket message.
|
|
37
|
-
*
|
|
38
|
-
* Message order matters. Call this immediately after receiving a message,
|
|
39
|
-
* before any other async work, to preserve ordering.
|
|
19
|
+
* Upgrades a WebSocket to enable handling
|
|
40
20
|
*
|
|
41
|
-
*
|
|
42
|
-
* directly (for example, `arraybuffer`).
|
|
21
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
|
43
22
|
*
|
|
44
|
-
* @
|
|
45
|
-
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
23
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
|
46
24
|
*/
|
|
47
|
-
|
|
48
|
-
matched: boolean;
|
|
49
|
-
}>;
|
|
25
|
+
upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
|
|
50
26
|
/**
|
|
51
|
-
*
|
|
27
|
+
* Handles a single message received from a WebSocket.
|
|
28
|
+
*
|
|
29
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
52
30
|
*
|
|
53
|
-
* @param ws The
|
|
31
|
+
* @param ws The WebSocket instance
|
|
32
|
+
* @param data The message payload, usually place in `event.data`
|
|
54
33
|
*/
|
|
55
|
-
|
|
34
|
+
message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
|
56
35
|
/**
|
|
57
|
-
*
|
|
36
|
+
* Closes the WebSocket peer and cleans up.
|
|
58
37
|
*
|
|
59
|
-
*
|
|
38
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
60
39
|
*/
|
|
61
|
-
|
|
40
|
+
close(ws: MinimalWebsocket): void;
|
|
62
41
|
}
|
|
63
42
|
|
|
64
|
-
interface RPCHandlerOptions<T extends Context> extends
|
|
43
|
+
interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T> {
|
|
65
44
|
}
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
/**
|
|
46
|
+
* RPC Handler for Websocket adapter
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
49
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
|
|
50
|
+
*/
|
|
51
|
+
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
52
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
68
53
|
}
|
|
69
54
|
|
|
70
|
-
export { RPCHandler,
|
|
71
|
-
export type {
|
|
55
|
+
export { RPCHandler, WebsocketHandler };
|
|
56
|
+
export type { MinimalWebsocket, RPCHandlerOptions };
|
|
@@ -1,84 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ServerPeer
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { readAsBuffer, resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { ServerPeer } from '@orpc/standard-server-peer';
|
|
3
|
+
import { createServerPeerHandleRequestFn } from '../standard-peer/index.mjs';
|
|
4
|
+
import { b as StandardRPCHandler } from '../../shared/server.CMf4nKky.mjs';
|
|
5
|
+
import '../../shared/server.DZ5BIITo.mjs';
|
|
6
|
+
import '@orpc/client/standard';
|
|
5
7
|
import '@orpc/client';
|
|
6
|
-
import '@
|
|
7
|
-
import '../../shared/server.
|
|
8
|
+
import '@orpc/standard-server';
|
|
9
|
+
import '../../shared/server.DEBcqOjg.mjs';
|
|
8
10
|
import '@orpc/contract';
|
|
9
|
-
import '../../shared/server.BoiFpNT7.mjs';
|
|
10
11
|
|
|
11
|
-
class
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this
|
|
12
|
+
class WebsocketHandler {
|
|
13
|
+
#peers = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
#handler;
|
|
15
|
+
constructor(standardHandler) {
|
|
16
|
+
this.#handler = standardHandler;
|
|
16
17
|
}
|
|
17
|
-
peers = /* @__PURE__ */ new WeakMap();
|
|
18
|
-
encodePeerMessageOptions;
|
|
19
|
-
decodePeerMessageOptions;
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
19
|
+
* Upgrades a WebSocket to enable handling
|
|
22
20
|
*
|
|
23
|
-
*
|
|
24
|
-
* before any other async work, to preserve ordering.
|
|
21
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
|
25
22
|
*
|
|
26
|
-
*
|
|
27
|
-
|
|
23
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
|
24
|
+
*/
|
|
25
|
+
upgrade(ws, ...rest) {
|
|
26
|
+
ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
|
|
27
|
+
ws.addEventListener("close", () => this.close(ws));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Handles a single message received from a WebSocket.
|
|
31
|
+
*
|
|
32
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
28
33
|
*
|
|
29
|
-
* @param ws The WebSocket instance
|
|
30
|
-
* @param data The
|
|
34
|
+
* @param ws The WebSocket instance
|
|
35
|
+
* @param data The message payload, usually place in `event.data`
|
|
31
36
|
*/
|
|
32
37
|
async message(ws, data, ...rest) {
|
|
33
|
-
let peer = this
|
|
38
|
+
let peer = this.#peers.get(ws);
|
|
34
39
|
if (!peer) {
|
|
35
|
-
this
|
|
36
|
-
const encoded2 = await encodePeerMessage(message, this.encodePeerMessageOptions);
|
|
37
|
-
await ws.send(encoded2);
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
const encoded = toStringOrBytes(data);
|
|
41
|
-
const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
|
|
42
|
-
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
43
|
-
await peer.message(
|
|
44
|
-
result.message,
|
|
45
|
-
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
46
|
-
);
|
|
40
|
+
this.#peers.set(ws, peer = new ServerPeer(ws.send.bind(ws)));
|
|
47
41
|
}
|
|
48
|
-
|
|
42
|
+
const message = data instanceof Blob ? await readAsBuffer(data) : data;
|
|
43
|
+
await peer.message(
|
|
44
|
+
message,
|
|
45
|
+
createServerPeerHandleRequestFn(this.#handler, resolveMaybeOptionalOptions(rest))
|
|
46
|
+
);
|
|
49
47
|
}
|
|
50
48
|
/**
|
|
51
|
-
*
|
|
49
|
+
* Closes the WebSocket peer and cleans up.
|
|
52
50
|
*
|
|
53
|
-
* @
|
|
51
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
|
54
52
|
*/
|
|
55
|
-
|
|
56
|
-
const peer = this
|
|
53
|
+
close(ws) {
|
|
54
|
+
const peer = this.#peers.get(ws);
|
|
57
55
|
if (peer) {
|
|
58
|
-
|
|
59
|
-
await peer.close();
|
|
56
|
+
peer.close();
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Attaches message and close event listeners to a WebSocket.
|
|
64
|
-
*
|
|
65
|
-
* Prefer this over calling `.message()` and `.close()` manually.
|
|
66
|
-
*/
|
|
67
|
-
upgrade(ws, ...rest) {
|
|
68
|
-
ws.addEventListener("message", sequential(async (event) => {
|
|
69
|
-
const data = event.data instanceof Blob ? await loadBytes(event.data) : event.data;
|
|
70
|
-
this.message(ws, data, ...rest);
|
|
71
|
-
}));
|
|
72
|
-
ws.addEventListener("close", () => this.close(ws));
|
|
73
|
-
}
|
|
74
59
|
}
|
|
75
60
|
|
|
76
|
-
class RPCHandler extends
|
|
61
|
+
class RPCHandler extends WebsocketHandler {
|
|
77
62
|
constructor(router, options = {}) {
|
|
78
|
-
|
|
79
|
-
const handler = new StandardHandler(codec, options);
|
|
80
|
-
super(handler, options);
|
|
63
|
+
super(new StandardRPCHandler(router, options));
|
|
81
64
|
}
|
|
82
65
|
}
|
|
83
66
|
|
|
84
|
-
export { RPCHandler,
|
|
67
|
+
export { RPCHandler, WebsocketHandler };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { WebSocket } from 'ws';
|
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.mjs';
|
|
4
|
+
import { f as StandardHandler } from '../../shared/server.BqadksTP.mjs';
|
|
5
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.mjs';
|
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DzE6WeuY.mjs';
|
|
7
|
+
import '@orpc/client';
|
|
8
|
+
import '@orpc/contract';
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '@orpc/standard-server-peer';
|
|
11
|
+
import '../../shared/server.B8gYOD5g.mjs';
|
|
12
|
+
import '@orpc/client/standard';
|
|
13
|
+
import '../../shared/server.C8_sRzQB.mjs';
|
|
14
|
+
|
|
15
|
+
declare class WsHandler<T extends Context> {
|
|
16
|
+
private readonly standardHandler;
|
|
17
|
+
constructor(standardHandler: StandardHandler<T>);
|
|
18
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* RPC Handler for ws (node ws) adapter
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
25
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
|
|
26
|
+
*/
|
|
27
|
+
declare class RPCHandler<T extends Context> extends WsHandler<T> {
|
|
28
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { RPCHandler, WsHandler };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { WebSocket } from 'ws';
|
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.js';
|
|
4
|
+
import { f as StandardHandler } from '../../shared/server.7cEtMB30.js';
|
|
5
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.js';
|
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D8IXzfqT.js';
|
|
7
|
+
import '@orpc/client';
|
|
8
|
+
import '@orpc/contract';
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '@orpc/standard-server-peer';
|
|
11
|
+
import '../../shared/server.EfTOZ2Q7.js';
|
|
12
|
+
import '@orpc/client/standard';
|
|
13
|
+
import '../../shared/server.ChyoA9XY.js';
|
|
14
|
+
|
|
15
|
+
declare class WsHandler<T extends Context> {
|
|
16
|
+
private readonly standardHandler;
|
|
17
|
+
constructor(standardHandler: StandardHandler<T>);
|
|
18
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* RPC Handler for ws (node ws) adapter
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
25
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket Websocket Adapter Docs}
|
|
26
|
+
*/
|
|
27
|
+
declare class RPCHandler<T extends Context> extends WsHandler<T> {
|
|
28
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { RPCHandler, WsHandler };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readAsBuffer, resolveMaybeOptionalOptions, logError } from '@orpc/shared';
|
|
2
|
+
import { ServerPeer } from '@orpc/standard-server-peer';
|
|
3
|
+
import { createServerPeerHandleRequestFn } from '../standard-peer/index.mjs';
|
|
4
|
+
import { b as StandardRPCHandler } from '../../shared/server.CMf4nKky.mjs';
|
|
5
|
+
import '../../shared/server.DZ5BIITo.mjs';
|
|
6
|
+
import '@orpc/client/standard';
|
|
7
|
+
import '@orpc/client';
|
|
8
|
+
import '@orpc/standard-server';
|
|
9
|
+
import '../../shared/server.DEBcqOjg.mjs';
|
|
10
|
+
import '@orpc/contract';
|
|
11
|
+
|
|
12
|
+
class WsHandler {
|
|
13
|
+
constructor(standardHandler) {
|
|
14
|
+
this.standardHandler = standardHandler;
|
|
15
|
+
}
|
|
16
|
+
async upgrade(ws, ...rest) {
|
|
17
|
+
const peer = new ServerPeer(ws.send.bind(ws));
|
|
18
|
+
ws.addEventListener("message", async (event) => {
|
|
19
|
+
const message = Array.isArray(event.data) ? await readAsBuffer(new Blob(event.data)) : event.data;
|
|
20
|
+
try {
|
|
21
|
+
await peer.message(
|
|
22
|
+
message,
|
|
23
|
+
createServerPeerHandleRequestFn(this.standardHandler, resolveMaybeOptionalOptions(rest))
|
|
24
|
+
);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
logError(error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
ws.addEventListener("close", () => {
|
|
30
|
+
peer.close();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class RPCHandler extends WsHandler {
|
|
36
|
+
constructor(router, options = {}) {
|
|
37
|
+
super(new StandardRPCHandler(router, options));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { RPCHandler, WsHandler };
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SerializeOptions, ParseOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -25,9 +25,9 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
25
25
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array
|
|
28
|
+
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array | undefined;
|
|
29
29
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
30
|
+
interface SetCookieOptions extends SerializeOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
33
|
*
|
|
@@ -46,7 +46,7 @@ interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyO
|
|
|
46
46
|
*
|
|
47
47
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
48
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600
|
|
49
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; HttpOnly; Max-Age=3600')
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
*/
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SerializeOptions, ParseOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -25,9 +25,9 @@ declare function encodeBase64url(data: Uint8Array): string;
|
|
|
25
25
|
* expect(new TextDecoder().decode(decoded)).toEqual(text)
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array
|
|
28
|
+
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array | undefined;
|
|
29
29
|
|
|
30
|
-
interface SetCookieOptions extends
|
|
30
|
+
interface SetCookieOptions extends SerializeOptions {
|
|
31
31
|
/**
|
|
32
32
|
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
33
33
|
*
|
|
@@ -46,7 +46,7 @@ interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyO
|
|
|
46
46
|
*
|
|
47
47
|
* setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
|
|
48
48
|
*
|
|
49
|
-
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600
|
|
49
|
+
* expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; HttpOnly; Max-Age=3600')
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
*/
|