@orpc/server 0.0.0-next.65596ea → 0.0.0-next.66774c1
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 +8 -9
- package/dist/adapters/aws-lambda/index.d.mts +7 -6
- package/dist/adapters/aws-lambda/index.d.ts +7 -6
- package/dist/adapters/aws-lambda/index.mjs +7 -6
- package/dist/adapters/bun-ws/index.d.mts +12 -11
- package/dist/adapters/bun-ws/index.d.ts +12 -11
- package/dist/adapters/bun-ws/index.mjs +16 -20
- package/dist/adapters/crossws/index.d.mts +8 -5
- package/dist/adapters/crossws/index.d.ts +8 -5
- package/dist/adapters/crossws/index.mjs +11 -17
- package/dist/adapters/fetch/index.d.mts +5 -4
- package/dist/adapters/fetch/index.d.ts +5 -4
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/message-port/index.d.mts +11 -8
- package/dist/adapters/message-port/index.d.ts +11 -8
- package/dist/adapters/message-port/index.mjs +14 -16
- package/dist/adapters/node/index.d.mts +5 -4
- package/dist/adapters/node/index.d.ts +5 -4
- package/dist/adapters/node/index.mjs +4 -3
- package/dist/adapters/standard/index.d.mts +8 -13
- package/dist/adapters/standard/index.d.ts +8 -13
- package/dist/adapters/standard/index.mjs +3 -2
- package/dist/adapters/standard-peer/index.d.mts +18 -0
- package/dist/adapters/standard-peer/index.d.ts +18 -0
- package/dist/adapters/standard-peer/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +36 -9
- package/dist/adapters/websocket/index.d.ts +36 -9
- package/dist/adapters/websocket/index.mjs +49 -20
- package/dist/adapters/ws/index.d.mts +11 -8
- package/dist/adapters/ws/index.d.ts +11 -8
- package/dist/adapters/ws/index.mjs +13 -14
- package/dist/helpers/index.d.mts +134 -0
- package/dist/helpers/index.d.ts +134 -0
- package/dist/helpers/index.mjs +188 -0
- 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 +21 -47
- package/dist/index.d.ts +21 -47
- package/dist/index.mjs +22 -8
- package/dist/plugins/index.d.mts +19 -6
- package/dist/plugins/index.d.ts +19 -6
- package/dist/plugins/index.mjs +94 -60
- package/dist/shared/server.B7b2w3_i.d.ts +12 -0
- package/dist/shared/server.BEFBl-Cb.d.mts +12 -0
- package/dist/shared/server.BU4WI18A.d.mts +32 -0
- package/dist/shared/{server.DG7Tamti.mjs → server.B_fj3X5m.mjs} +92 -51
- package/dist/shared/{server.-ACo36I0.d.ts → server.Bmh5xd4n.d.ts} +3 -3
- package/dist/shared/{server.DD2C4ujN.d.mts → server.CYNGeoCm.d.mts} +6 -4
- package/dist/shared/{server.DD2C4ujN.d.ts → server.CYNGeoCm.d.ts} +6 -4
- package/dist/shared/{server.CHvOkcM3.mjs → server.CYRYFTxo.mjs} +74 -41
- package/dist/shared/server.D0H-iaY3.d.ts +32 -0
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/server.DhJj-1X9.d.mts +42 -0
- package/dist/shared/server.UVMTOWrk.mjs +26 -0
- package/dist/shared/{server.Dq8xr7PQ.d.mts → server.gqRxT-yN.d.mts} +3 -3
- package/dist/shared/server.jMTkVNIb.d.ts +42 -0
- package/package.json +29 -13
- package/dist/shared/server.BPAWobQg.d.ts +0 -12
- package/dist/shared/server.Bd52nNaH.d.mts +0 -12
- package/dist/shared/server.BliFSTnG.d.mts +0 -10
- package/dist/shared/server.IG2MjhrD.d.ts +0 -10
@@ -1,13 +1,14 @@
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.CYNGeoCm.mjs';
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
|
-
import {
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
6
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
4
|
+
import { g as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.gqRxT-yN.mjs';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BEFBl-Cb.mjs';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.BU4WI18A.mjs';
|
7
7
|
import '@orpc/client';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/standard-server';
|
10
10
|
import '@orpc/client/standard';
|
11
|
+
import '../../shared/server.DhJj-1X9.mjs';
|
11
12
|
|
12
13
|
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
13
14
|
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
@@ -1,13 +1,14 @@
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.CYNGeoCm.js';
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
|
-
import {
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
6
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
4
|
+
import { g as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.Bmh5xd4n.js';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.B7b2w3_i.js';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D0H-iaY3.js';
|
7
7
|
import '@orpc/client';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/standard-server';
|
10
10
|
import '@orpc/client/standard';
|
11
|
+
import '../../shared/server.jMTkVNIb.js';
|
11
12
|
|
12
13
|
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
13
14
|
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
2
|
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
4
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.CYRYFTxo.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
9
|
import '@orpc/standard-server/batch';
|
10
|
+
import '@orpc/standard-server-fetch';
|
10
11
|
import { S as StrictGetMethodPlugin } from '../../shared/server.BW-nUGgA.mjs';
|
11
|
-
import '../../shared/server.
|
12
|
+
import '../../shared/server.B_fj3X5m.mjs';
|
12
13
|
|
13
14
|
class BodyLimitPlugin {
|
14
15
|
maxBodySize;
|
@@ -1,12 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
export { C as CompositeStandardHandlerPlugin,
|
3
|
-
import { ORPCError
|
1
|
+
import { S as StandardCodec, a as StandardParams } from '../../shared/server.gqRxT-yN.mjs';
|
2
|
+
export { C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, c as StandardHandleResult, f as StandardHandler, d as StandardHandlerInterceptorOptions, e as StandardHandlerOptions, g as StandardHandlerPlugin, h as StandardMatchResult, i as StandardMatcher } from '../../shared/server.gqRxT-yN.mjs';
|
3
|
+
import { ORPCError } from '@orpc/client';
|
4
4
|
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
-
import {
|
7
|
-
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.
|
6
|
+
import { A as AnyProcedure } from '../../shared/server.CYNGeoCm.mjs';
|
7
|
+
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions, c as StandardRPCMatcher, b as StandardRPCMatcherOptions } from '../../shared/server.BU4WI18A.mjs';
|
8
|
+
export { F as FriendlyStandardHandleOptions, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.BEFBl-Cb.mjs';
|
8
9
|
import '@orpc/contract';
|
9
10
|
import '@orpc/shared';
|
11
|
+
import '../../shared/server.DhJj-1X9.mjs';
|
10
12
|
|
11
13
|
declare class StandardRPCCodec implements StandardCodec {
|
12
14
|
private readonly serializer;
|
@@ -16,11 +18,4 @@ declare class StandardRPCCodec implements StandardCodec {
|
|
16
18
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
17
19
|
}
|
18
20
|
|
19
|
-
|
20
|
-
private readonly tree;
|
21
|
-
private pendingRouters;
|
22
|
-
init(router: AnyRouter, path?: readonly string[]): void;
|
23
|
-
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
24
|
-
}
|
25
|
-
|
26
|
-
export { StandardCodec, StandardMatchResult, StandardMatcher, StandardParams, StandardRPCCodec, StandardRPCMatcher };
|
21
|
+
export { StandardCodec, StandardParams, StandardRPCCodec };
|
@@ -1,12 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
export { C as CompositeStandardHandlerPlugin,
|
3
|
-
import { ORPCError
|
1
|
+
import { S as StandardCodec, a as StandardParams } from '../../shared/server.Bmh5xd4n.js';
|
2
|
+
export { C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, c as StandardHandleResult, f as StandardHandler, d as StandardHandlerInterceptorOptions, e as StandardHandlerOptions, g as StandardHandlerPlugin, h as StandardMatchResult, i as StandardMatcher } from '../../shared/server.Bmh5xd4n.js';
|
3
|
+
import { ORPCError } from '@orpc/client';
|
4
4
|
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
-
import {
|
7
|
-
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.
|
6
|
+
import { A as AnyProcedure } from '../../shared/server.CYNGeoCm.js';
|
7
|
+
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions, c as StandardRPCMatcher, b as StandardRPCMatcherOptions } from '../../shared/server.D0H-iaY3.js';
|
8
|
+
export { F as FriendlyStandardHandleOptions, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.B7b2w3_i.js';
|
8
9
|
import '@orpc/contract';
|
9
10
|
import '@orpc/shared';
|
11
|
+
import '../../shared/server.jMTkVNIb.js';
|
10
12
|
|
11
13
|
declare class StandardRPCCodec implements StandardCodec {
|
12
14
|
private readonly serializer;
|
@@ -16,11 +18,4 @@ declare class StandardRPCCodec implements StandardCodec {
|
|
16
18
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
17
19
|
}
|
18
20
|
|
19
|
-
|
20
|
-
private readonly tree;
|
21
|
-
private pendingRouters;
|
22
|
-
init(router: AnyRouter, path?: readonly string[]): void;
|
23
|
-
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
24
|
-
}
|
25
|
-
|
26
|
-
export { StandardCodec, StandardMatchResult, StandardMatcher, StandardParams, StandardRPCCodec, StandardRPCMatcher };
|
21
|
+
export { StandardCodec, StandardParams, StandardRPCCodec };
|
@@ -1,7 +1,8 @@
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.
|
1
|
+
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.CYRYFTxo.mjs';
|
2
|
+
export { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
2
3
|
import '@orpc/client/standard';
|
3
4
|
import '@orpc/client';
|
4
5
|
import '@orpc/shared';
|
5
6
|
import '@orpc/standard-server';
|
6
|
-
import '../../shared/server.
|
7
|
+
import '../../shared/server.B_fj3X5m.mjs';
|
7
8
|
import '@orpc/contract';
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { ServerPeer, EncodedMessage, ServerPeerHandleRequestFn } from '@orpc/standard-server-peer';
|
2
|
+
import { C as Context } from '../../shared/server.CYNGeoCm.mjs';
|
3
|
+
import { f as StandardHandler } from '../../shared/server.gqRxT-yN.mjs';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BEFBl-Cb.mjs';
|
5
|
+
import '@orpc/client';
|
6
|
+
import '@orpc/contract';
|
7
|
+
import '@orpc/shared';
|
8
|
+
import '@orpc/standard-server';
|
9
|
+
|
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;
|
16
|
+
|
17
|
+
export { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
|
18
|
+
export type { HandleStandardServerPeerMessageOptions };
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { ServerPeer, EncodedMessage, ServerPeerHandleRequestFn } from '@orpc/standard-server-peer';
|
2
|
+
import { C as Context } from '../../shared/server.CYNGeoCm.js';
|
3
|
+
import { f as StandardHandler } from '../../shared/server.Bmh5xd4n.js';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.B7b2w3_i.js';
|
5
|
+
import '@orpc/client';
|
6
|
+
import '@orpc/contract';
|
7
|
+
import '@orpc/shared';
|
8
|
+
import '@orpc/standard-server';
|
9
|
+
|
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;
|
16
|
+
|
17
|
+
export { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
|
18
|
+
export type { HandleStandardServerPeerMessageOptions };
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export { c as createServerPeerHandleRequestFn, h as handleStandardServerPeerMessage } from '../../shared/server.UVMTOWrk.mjs';
|
2
|
+
import '@orpc/client';
|
3
|
+
import '@orpc/shared';
|
4
|
+
import '@orpc/standard-server';
|
5
|
+
import '@orpc/contract';
|
6
|
+
import '@orpc/client/standard';
|
7
|
+
import '../../shared/server.DZ5BIITo.mjs';
|
@@ -1,17 +1,43 @@
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import { C as Context, R as Router } from '../../shared/server.
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
2
|
+
import { C as Context, R as Router } from '../../shared/server.CYNGeoCm.mjs';
|
3
|
+
import { f as StandardHandler } from '../../shared/server.gqRxT-yN.mjs';
|
4
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.mjs';
|
5
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.BU4WI18A.mjs';
|
6
6
|
import '@orpc/client';
|
7
7
|
import '@orpc/contract';
|
8
8
|
import '@orpc/standard-server';
|
9
|
+
import '@orpc/standard-server-peer';
|
10
|
+
import '../../shared/server.BEFBl-Cb.mjs';
|
9
11
|
import '@orpc/client/standard';
|
12
|
+
import '../../shared/server.DhJj-1X9.mjs';
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
type MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
|
15
|
+
declare class WebsocketHandler<T extends Context> {
|
16
|
+
#private;
|
13
17
|
constructor(standardHandler: StandardHandler<T>);
|
14
|
-
|
18
|
+
/**
|
19
|
+
* Upgrades a WebSocket to enable handling
|
20
|
+
*
|
21
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
22
|
+
*
|
23
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
24
|
+
*/
|
25
|
+
upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
|
26
|
+
/**
|
27
|
+
* Handles a single message received from a WebSocket.
|
28
|
+
*
|
29
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
30
|
+
*
|
31
|
+
* @param ws The WebSocket instance
|
32
|
+
* @param data The message payload, usually place in `event.data`
|
33
|
+
*/
|
34
|
+
message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
35
|
+
/**
|
36
|
+
* Closes the WebSocket peer and cleans up.
|
37
|
+
*
|
38
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
39
|
+
*/
|
40
|
+
close(ws: MinimalWebsocket): void;
|
15
41
|
}
|
16
42
|
|
17
43
|
/**
|
@@ -20,8 +46,9 @@ declare class experimental_WebsocketHandler<T extends Context> {
|
|
20
46
|
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
21
47
|
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
22
48
|
*/
|
23
|
-
declare class
|
49
|
+
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
24
50
|
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
25
51
|
}
|
26
52
|
|
27
|
-
export {
|
53
|
+
export { RPCHandler, WebsocketHandler };
|
54
|
+
export type { MinimalWebsocket };
|
@@ -1,17 +1,43 @@
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import { C as Context, R as Router } from '../../shared/server.
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
2
|
+
import { C as Context, R as Router } from '../../shared/server.CYNGeoCm.js';
|
3
|
+
import { f as StandardHandler } from '../../shared/server.Bmh5xd4n.js';
|
4
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.js';
|
5
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D0H-iaY3.js';
|
6
6
|
import '@orpc/client';
|
7
7
|
import '@orpc/contract';
|
8
8
|
import '@orpc/standard-server';
|
9
|
+
import '@orpc/standard-server-peer';
|
10
|
+
import '../../shared/server.B7b2w3_i.js';
|
9
11
|
import '@orpc/client/standard';
|
12
|
+
import '../../shared/server.jMTkVNIb.js';
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
type MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
|
15
|
+
declare class WebsocketHandler<T extends Context> {
|
16
|
+
#private;
|
13
17
|
constructor(standardHandler: StandardHandler<T>);
|
14
|
-
|
18
|
+
/**
|
19
|
+
* Upgrades a WebSocket to enable handling
|
20
|
+
*
|
21
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
22
|
+
*
|
23
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
24
|
+
*/
|
25
|
+
upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
|
26
|
+
/**
|
27
|
+
* Handles a single message received from a WebSocket.
|
28
|
+
*
|
29
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
30
|
+
*
|
31
|
+
* @param ws The WebSocket instance
|
32
|
+
* @param data The message payload, usually place in `event.data`
|
33
|
+
*/
|
34
|
+
message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
35
|
+
/**
|
36
|
+
* Closes the WebSocket peer and cleans up.
|
37
|
+
*
|
38
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
39
|
+
*/
|
40
|
+
close(ws: MinimalWebsocket): void;
|
15
41
|
}
|
16
42
|
|
17
43
|
/**
|
@@ -20,8 +46,9 @@ declare class experimental_WebsocketHandler<T extends Context> {
|
|
20
46
|
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
21
47
|
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
22
48
|
*/
|
23
|
-
declare class
|
49
|
+
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
24
50
|
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
25
51
|
}
|
26
52
|
|
27
|
-
export {
|
53
|
+
export { RPCHandler, WebsocketHandler };
|
54
|
+
export type { MinimalWebsocket };
|
@@ -1,38 +1,67 @@
|
|
1
|
-
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
1
|
+
import { readAsBuffer, resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
-
import {
|
3
|
+
import { c as createServerPeerHandleRequestFn } from '../../shared/server.UVMTOWrk.mjs';
|
4
4
|
import '@orpc/client';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CYRYFTxo.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DZ5BIITo.mjs';
|
10
|
+
import '../../shared/server.B_fj3X5m.mjs';
|
10
11
|
|
11
|
-
class
|
12
|
+
class WebsocketHandler {
|
13
|
+
#peers = /* @__PURE__ */ new WeakMap();
|
14
|
+
#handler;
|
12
15
|
constructor(standardHandler) {
|
13
|
-
this
|
16
|
+
this.#handler = standardHandler;
|
14
17
|
}
|
18
|
+
/**
|
19
|
+
* Upgrades a WebSocket to enable handling
|
20
|
+
*
|
21
|
+
* This attaches the necessary 'message' and 'close' listeners to the WebSocket
|
22
|
+
*
|
23
|
+
* @warning Do not use this method if you're using `.message()` or `.close()`
|
24
|
+
*/
|
15
25
|
upgrade(ws, ...rest) {
|
16
|
-
|
17
|
-
ws.addEventListener("
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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.
|
33
|
+
*
|
34
|
+
* @param ws The WebSocket instance
|
35
|
+
* @param data The message payload, usually place in `event.data`
|
36
|
+
*/
|
37
|
+
async message(ws, data, ...rest) {
|
38
|
+
let peer = this.#peers.get(ws);
|
39
|
+
if (!peer) {
|
40
|
+
this.#peers.set(ws, peer = new ServerPeer(ws.send.bind(ws)));
|
41
|
+
}
|
42
|
+
const message = data instanceof Blob ? await readAsBuffer(data) : data;
|
43
|
+
await peer.message(
|
44
|
+
message,
|
45
|
+
createServerPeerHandleRequestFn(this.#handler, resolveMaybeOptionalOptions(rest))
|
46
|
+
);
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Closes the WebSocket peer and cleans up.
|
50
|
+
*
|
51
|
+
* @warning Avoid calling this directly if `.upgrade()` is used.
|
52
|
+
*/
|
53
|
+
close(ws) {
|
54
|
+
const peer = this.#peers.get(ws);
|
55
|
+
if (peer) {
|
27
56
|
peer.close();
|
28
|
-
}
|
57
|
+
}
|
29
58
|
}
|
30
59
|
}
|
31
60
|
|
32
|
-
class
|
61
|
+
class RPCHandler extends WebsocketHandler {
|
33
62
|
constructor(router, options = {}) {
|
34
63
|
super(new StandardRPCHandler(router, options));
|
35
64
|
}
|
36
65
|
}
|
37
66
|
|
38
|
-
export {
|
67
|
+
export { RPCHandler, WebsocketHandler };
|
@@ -1,18 +1,21 @@
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { WebSocket } from 'ws';
|
3
|
-
import { C as Context, R as Router } from '../../shared/server.
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.CYNGeoCm.mjs';
|
4
|
+
import { f as StandardHandler } from '../../shared/server.gqRxT-yN.mjs';
|
5
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.mjs';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.BU4WI18A.mjs';
|
7
7
|
import '@orpc/client';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/standard-server';
|
10
|
+
import '@orpc/standard-server-peer';
|
11
|
+
import '../../shared/server.BEFBl-Cb.mjs';
|
10
12
|
import '@orpc/client/standard';
|
13
|
+
import '../../shared/server.DhJj-1X9.mjs';
|
11
14
|
|
12
|
-
declare class
|
15
|
+
declare class WsHandler<T extends Context> {
|
13
16
|
private readonly standardHandler;
|
14
17
|
constructor(standardHandler: StandardHandler<T>);
|
15
|
-
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<
|
18
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
16
19
|
}
|
17
20
|
|
18
21
|
/**
|
@@ -21,8 +24,8 @@ declare class experimental_WsHandler<T extends Context> {
|
|
21
24
|
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
22
25
|
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
23
26
|
*/
|
24
|
-
declare class
|
27
|
+
declare class RPCHandler<T extends Context> extends WsHandler<T> {
|
25
28
|
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
26
29
|
}
|
27
30
|
|
28
|
-
export {
|
31
|
+
export { RPCHandler, WsHandler };
|
@@ -1,18 +1,21 @@
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { WebSocket } from 'ws';
|
3
|
-
import { C as Context, R as Router } from '../../shared/server.
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.CYNGeoCm.js';
|
4
|
+
import { f as StandardHandler } from '../../shared/server.Bmh5xd4n.js';
|
5
|
+
import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.js';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D0H-iaY3.js';
|
7
7
|
import '@orpc/client';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/standard-server';
|
10
|
+
import '@orpc/standard-server-peer';
|
11
|
+
import '../../shared/server.B7b2w3_i.js';
|
10
12
|
import '@orpc/client/standard';
|
13
|
+
import '../../shared/server.jMTkVNIb.js';
|
11
14
|
|
12
|
-
declare class
|
15
|
+
declare class WsHandler<T extends Context> {
|
13
16
|
private readonly standardHandler;
|
14
17
|
constructor(standardHandler: StandardHandler<T>);
|
15
|
-
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<
|
18
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
|
16
19
|
}
|
17
20
|
|
18
21
|
/**
|
@@ -21,8 +24,8 @@ declare class experimental_WsHandler<T extends Context> {
|
|
21
24
|
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
22
25
|
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
23
26
|
*/
|
24
|
-
declare class
|
27
|
+
declare class RPCHandler<T extends Context> extends WsHandler<T> {
|
25
28
|
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
26
29
|
}
|
27
30
|
|
28
|
-
export {
|
31
|
+
export { RPCHandler, WsHandler };
|
@@ -1,27 +1,26 @@
|
|
1
|
-
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
1
|
+
import { readAsBuffer, resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
2
|
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
-
import {
|
3
|
+
import { c as createServerPeerHandleRequestFn } from '../../shared/server.UVMTOWrk.mjs';
|
4
4
|
import '@orpc/client';
|
5
5
|
import '@orpc/standard-server';
|
6
6
|
import '@orpc/contract';
|
7
|
-
import { b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CYRYFTxo.mjs';
|
8
8
|
import '@orpc/client/standard';
|
9
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DZ5BIITo.mjs';
|
10
|
+
import '../../shared/server.B_fj3X5m.mjs';
|
10
11
|
|
11
|
-
class
|
12
|
+
class WsHandler {
|
12
13
|
constructor(standardHandler) {
|
13
14
|
this.standardHandler = standardHandler;
|
14
15
|
}
|
15
16
|
async upgrade(ws, ...rest) {
|
16
17
|
const peer = new ServerPeer(ws.send.bind(ws));
|
17
18
|
ws.addEventListener("message", async (event) => {
|
18
|
-
const
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
const { response } = await this.standardHandler.handle({ ...request, body: () => Promise.resolve(request.body) }, options);
|
24
|
-
await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
|
19
|
+
const message = Array.isArray(event.data) ? await readAsBuffer(new Blob(event.data)) : event.data;
|
20
|
+
await peer.message(
|
21
|
+
message,
|
22
|
+
createServerPeerHandleRequestFn(this.standardHandler, resolveMaybeOptionalOptions(rest))
|
23
|
+
);
|
25
24
|
});
|
26
25
|
ws.addEventListener("close", () => {
|
27
26
|
peer.close();
|
@@ -29,10 +28,10 @@ class experimental_WsHandler {
|
|
29
28
|
}
|
30
29
|
}
|
31
30
|
|
32
|
-
class
|
31
|
+
class RPCHandler extends WsHandler {
|
33
32
|
constructor(router, options = {}) {
|
34
33
|
super(new StandardRPCHandler(router, options));
|
35
34
|
}
|
36
35
|
}
|
37
36
|
|
38
|
-
export {
|
37
|
+
export { RPCHandler, WsHandler };
|