@orpc/server 1.14.6 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -136
- package/dist/adapters/crossws/index.d.mts +42 -21
- package/dist/adapters/crossws/index.d.ts +42 -21
- package/dist/adapters/crossws/index.mjs +37 -18
- package/dist/adapters/fetch/index.d.mts +83 -67
- package/dist/adapters/fetch/index.d.ts +83 -67
- package/dist/adapters/fetch/index.mjs +131 -106
- package/dist/adapters/message-port/index.d.mts +51 -34
- package/dist/adapters/message-port/index.d.ts +51 -34
- package/dist/adapters/message-port/index.mjs +73 -38
- package/dist/adapters/node/index.d.mts +82 -60
- package/dist/adapters/node/index.d.ts +82 -60
- package/dist/adapters/node/index.mjs +127 -98
- package/dist/adapters/standard/index.d.mts +16 -18
- package/dist/adapters/standard/index.d.ts +16 -18
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +12 -14
- package/dist/adapters/standard-peer/index.d.ts +12 -14
- package/dist/adapters/standard-peer/index.mjs +2 -21
- package/dist/adapters/websocket/index.d.mts +39 -34
- package/dist/adapters/websocket/index.d.ts +39 -34
- package/dist/adapters/websocket/index.mjs +42 -33
- package/dist/extensions/callable.d.mts +10 -0
- package/dist/extensions/callable.d.ts +10 -0
- package/dist/extensions/callable.mjs +11 -0
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/index.mjs +1 -1
- package/dist/index.d.mts +163 -770
- package/dist/index.d.ts +163 -770
- package/dist/index.mjs +296 -403
- package/dist/plugins/index.d.mts +105 -143
- package/dist/plugins/index.d.ts +105 -143
- package/dist/plugins/index.mjs +232 -255
- package/dist/shared/server.BB_Ik9Ph.d.mts +104 -0
- package/dist/shared/server.BL22TloH.d.mts +184 -0
- package/dist/shared/server.BL22TloH.d.ts +184 -0
- package/dist/shared/server.B_U9y00a.d.mts +66 -0
- package/dist/shared/server.BsNNjG5J.d.mts +61 -0
- package/dist/shared/server.BwHnWUuN.mjs +222 -0
- package/dist/shared/server.CX4vUnDk.mjs +11 -0
- package/dist/shared/server.CjOb6ItT.mjs +41 -0
- package/dist/shared/server.CrlKQucM.mjs +233 -0
- package/dist/shared/server.D_QauotT.mjs +30 -0
- package/dist/shared/server.EOHJ3NJr.d.ts +104 -0
- package/dist/shared/server.GDpX6Df8.mjs +271 -0
- package/dist/shared/server.Pa0F03f_.d.ts +61 -0
- package/dist/shared/server.T9F3bzZx.d.ts +66 -0
- package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
- package/package.json +26 -55
- package/dist/adapters/aws-lambda/index.d.mts +0 -46
- package/dist/adapters/aws-lambda/index.d.ts +0 -46
- package/dist/adapters/aws-lambda/index.mjs +0 -40
- package/dist/adapters/bun-ws/index.d.mts +0 -36
- package/dist/adapters/bun-ws/index.d.ts +0 -36
- package/dist/adapters/bun-ws/index.mjs +0 -47
- package/dist/adapters/fastify/index.d.mts +0 -53
- package/dist/adapters/fastify/index.d.ts +0 -53
- package/dist/adapters/fastify/index.mjs +0 -52
- package/dist/adapters/ws/index.d.mts +0 -31
- package/dist/adapters/ws/index.d.ts +0 -31
- package/dist/adapters/ws/index.mjs +0 -37
- package/dist/hibernation/index.d.mts +0 -44
- package/dist/hibernation/index.d.ts +0 -44
- package/dist/hibernation/index.mjs +0 -65
- package/dist/shared/server.7cEtMB30.d.ts +0 -74
- package/dist/shared/server.B8gYOD5g.d.mts +0 -12
- package/dist/shared/server.BqadksTP.d.mts +0 -74
- package/dist/shared/server.C8_sRzQB.d.mts +0 -42
- package/dist/shared/server.ChUyt5-i.d.mts +0 -32
- package/dist/shared/server.ChyoA9XY.d.ts +0 -42
- package/dist/shared/server.DEBcqOjg.mjs +0 -418
- package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
- package/dist/shared/server.TEVCLCFC.mjs +0 -39
- package/dist/shared/server.ZxHCEN1h.mjs +0 -226
- package/dist/shared/server.qKsRrdxW.d.mts +0 -193
- package/dist/shared/server.qKsRrdxW.d.ts +0 -193
- package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CompositeStandardHandlerPlugin,
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { A as AnyProcedure } from '../../shared/server.qKsRrdxW.mjs';
|
|
7
|
-
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions, c as StandardRPCMatcher, b as StandardRPCMatcherOptions } from '../../shared/server.ChUyt5-i.mjs';
|
|
8
|
-
export { F as FriendlyStandardHandleOptions, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.B8gYOD5g.mjs';
|
|
9
|
-
import '@orpc/contract';
|
|
1
|
+
import { b as StandardHandlerHandleOptions } from '../../shared/server.BB_Ik9Ph.mjs';
|
|
2
|
+
export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, S as StandardHandler, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure, g as StandardHandlerHandleResult, h as StandardHandlerInterceptor, i as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, e as StandardHandlerPlugin, j as StandardHandlerRoutingInterceptor, f as StandardHandlerRoutingInterceptorOptions } from '../../shared/server.BB_Ik9Ph.mjs';
|
|
3
|
+
export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions } from '../../shared/server.B_U9y00a.mjs';
|
|
4
|
+
import { C as Context } from '../../shared/server.BL22TloH.mjs';
|
|
5
|
+
import '@orpc/client';
|
|
10
6
|
import '@orpc/shared';
|
|
11
|
-
import '
|
|
7
|
+
import '@standardserver/core';
|
|
8
|
+
import '@orpc/contract';
|
|
9
|
+
import '../../shared/server.BsNNjG5J.mjs';
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
11
|
+
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
20
17
|
|
|
21
|
-
export {
|
|
18
|
+
export { StandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions };
|
|
19
|
+
export type { FriendlyStandardHandlerHandleOptions };
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as CompositeStandardHandlerPlugin,
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { A as AnyProcedure } from '../../shared/server.qKsRrdxW.js';
|
|
7
|
-
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions, c as StandardRPCMatcher, b as StandardRPCMatcherOptions } from '../../shared/server.yoEB3Fx4.js';
|
|
8
|
-
export { F as FriendlyStandardHandleOptions, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.EfTOZ2Q7.js';
|
|
9
|
-
import '@orpc/contract';
|
|
1
|
+
import { b as StandardHandlerHandleOptions } from '../../shared/server.EOHJ3NJr.js';
|
|
2
|
+
export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, S as StandardHandler, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure, g as StandardHandlerHandleResult, h as StandardHandlerInterceptor, i as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, e as StandardHandlerPlugin, j as StandardHandlerRoutingInterceptor, f as StandardHandlerRoutingInterceptorOptions } from '../../shared/server.EOHJ3NJr.js';
|
|
3
|
+
export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions } from '../../shared/server.T9F3bzZx.js';
|
|
4
|
+
import { C as Context } from '../../shared/server.BL22TloH.js';
|
|
5
|
+
import '@orpc/client';
|
|
10
6
|
import '@orpc/shared';
|
|
11
|
-
import '
|
|
7
|
+
import '@standardserver/core';
|
|
8
|
+
import '@orpc/contract';
|
|
9
|
+
import '../../shared/server.Pa0F03f_.js';
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
11
|
+
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
20
17
|
|
|
21
|
-
export {
|
|
18
|
+
export { StandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions };
|
|
19
|
+
export type { FriendlyStandardHandlerHandleOptions };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin,
|
|
2
|
-
export { r as
|
|
3
|
-
import '@orpc/client/standard';
|
|
1
|
+
export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, R as RPCHandlerCodec, a as RPCMatcher, S as StandardHandler } from '../../shared/server.GDpX6Df8.mjs';
|
|
2
|
+
export { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
|
|
4
3
|
import '@orpc/client';
|
|
5
4
|
import '@orpc/shared';
|
|
6
|
-
import '@
|
|
7
|
-
import '../../shared/server.
|
|
5
|
+
import '@standardserver/core';
|
|
6
|
+
import '../../shared/server.CrlKQucM.mjs';
|
|
8
7
|
import '@orpc/contract';
|
|
8
|
+
import '../../shared/server.BwHnWUuN.mjs';
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
3
|
+
import { C as Context } from '../../shared/server.BL22TloH.mjs';
|
|
4
|
+
import { b as StandardHandlerHandleOptions, S as StandardHandler } from '../../shared/server.BB_Ik9Ph.mjs';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/contract';
|
|
7
|
-
import '@orpc/shared';
|
|
8
|
-
import '@orpc/standard-server';
|
|
9
7
|
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
declare function
|
|
8
|
+
type StandardPeerRequestHandlerOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
9
|
+
context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
+
} : {
|
|
11
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
12
|
+
});
|
|
13
|
+
declare function createStandardPeerRequestHandler<T extends Context>(handler: StandardHandler<T>, options: StandardPeerRequestHandlerOptions<T>): (request: StandardLazyRequest) => Promise<StandardResponse>;
|
|
16
14
|
|
|
17
|
-
export {
|
|
18
|
-
export type {
|
|
15
|
+
export { createStandardPeerRequestHandler };
|
|
16
|
+
export type { StandardPeerRequestHandlerOptions };
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
3
|
+
import { C as Context } from '../../shared/server.BL22TloH.js';
|
|
4
|
+
import { b as StandardHandlerHandleOptions, S as StandardHandler } from '../../shared/server.EOHJ3NJr.js';
|
|
5
5
|
import '@orpc/client';
|
|
6
6
|
import '@orpc/contract';
|
|
7
|
-
import '@orpc/shared';
|
|
8
|
-
import '@orpc/standard-server';
|
|
9
7
|
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
declare function
|
|
8
|
+
type StandardPeerRequestHandlerOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
9
|
+
context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
+
} : {
|
|
11
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
12
|
+
});
|
|
13
|
+
declare function createStandardPeerRequestHandler<T extends Context>(handler: StandardHandler<T>, options: StandardPeerRequestHandlerOptions<T>): (request: StandardLazyRequest) => Promise<StandardResponse>;
|
|
16
14
|
|
|
17
|
-
export {
|
|
18
|
-
export type {
|
|
15
|
+
export { createStandardPeerRequestHandler };
|
|
16
|
+
export type { StandardPeerRequestHandlerOptions };
|
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
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
|
+
export { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
|
|
2
|
+
import '@orpc/shared';
|
|
@@ -1,56 +1,61 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
|
+
import { C as Context } from '../../shared/server.BL22TloH.mjs';
|
|
4
|
+
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.BB_Ik9Ph.mjs';
|
|
5
|
+
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
|
|
6
|
+
import { R as Router } from '../../shared/server.BsNNjG5J.mjs';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.B_U9y00a.mjs';
|
|
6
8
|
import '@orpc/client';
|
|
7
9
|
import '@orpc/contract';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.B8gYOD5g.mjs';
|
|
10
|
-
import '@orpc/standard-server';
|
|
11
|
-
import '@orpc/client/standard';
|
|
12
|
-
import '../../shared/server.C8_sRzQB.mjs';
|
|
10
|
+
import '@standardserver/core';
|
|
13
11
|
|
|
14
|
-
type
|
|
12
|
+
type WebsocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send'>;
|
|
13
|
+
interface WebsocketHandlerOptions<_T extends Context> {
|
|
14
|
+
/**
|
|
15
|
+
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
16
|
+
*/
|
|
17
|
+
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
20
|
+
*/
|
|
21
|
+
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
22
|
+
}
|
|
15
23
|
declare class WebsocketHandler<T extends Context> {
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
private readonly handler;
|
|
25
|
+
private readonly peers;
|
|
26
|
+
private readonly encodePeerMessageOptions;
|
|
27
|
+
private readonly decodePeerMessageOptions;
|
|
28
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebsocketHandlerOptions<T>>);
|
|
18
29
|
/**
|
|
19
|
-
*
|
|
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()`
|
|
30
|
+
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
24
31
|
*/
|
|
25
|
-
upgrade(ws:
|
|
32
|
+
upgrade(ws: WebsocketLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
26
33
|
/**
|
|
27
34
|
* Handles a single message received from a WebSocket.
|
|
28
35
|
*
|
|
29
|
-
* @warning
|
|
36
|
+
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
30
37
|
*
|
|
31
|
-
* @param ws The WebSocket instance
|
|
32
|
-
* @param data The message
|
|
38
|
+
* @param ws The WebSocket instance, require consistent instance across messages for proper peer management
|
|
39
|
+
* @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
|
|
33
40
|
*/
|
|
34
|
-
message(ws:
|
|
41
|
+
message(ws: WebsocketLike, data: string | ArrayBuffer | Blob | Exclude<ConstructorParameters<typeof Blob>[0], undefined>[0][] | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
42
|
+
matched: boolean;
|
|
43
|
+
}>;
|
|
35
44
|
/**
|
|
36
|
-
*
|
|
45
|
+
* Called when a websocket is closed, to clean up any associated peer state.
|
|
46
|
+
*
|
|
47
|
+
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
37
48
|
*
|
|
38
|
-
* @
|
|
49
|
+
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
39
50
|
*/
|
|
40
|
-
close(ws:
|
|
51
|
+
close(ws: WebsocketLike): Promise<void>;
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
interface RPCHandlerOptions<T extends Context> extends
|
|
54
|
+
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebsocketHandlerOptions<T> {
|
|
44
55
|
}
|
|
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
56
|
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
52
|
-
constructor(router: Router<
|
|
57
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
export { RPCHandler, WebsocketHandler };
|
|
56
|
-
export type {
|
|
61
|
+
export type { RPCHandlerOptions, WebsocketHandlerOptions, WebsocketLike };
|
|
@@ -1,56 +1,61 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
3
|
+
import { C as Context } from '../../shared/server.BL22TloH.js';
|
|
4
|
+
import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.EOHJ3NJr.js';
|
|
5
|
+
import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
|
|
6
|
+
import { R as Router } from '../../shared/server.Pa0F03f_.js';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.T9F3bzZx.js';
|
|
6
8
|
import '@orpc/client';
|
|
7
9
|
import '@orpc/contract';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.EfTOZ2Q7.js';
|
|
10
|
-
import '@orpc/standard-server';
|
|
11
|
-
import '@orpc/client/standard';
|
|
12
|
-
import '../../shared/server.ChyoA9XY.js';
|
|
10
|
+
import '@standardserver/core';
|
|
13
11
|
|
|
14
|
-
type
|
|
12
|
+
type WebsocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send'>;
|
|
13
|
+
interface WebsocketHandlerOptions<_T extends Context> {
|
|
14
|
+
/**
|
|
15
|
+
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
16
|
+
*/
|
|
17
|
+
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
20
|
+
*/
|
|
21
|
+
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
22
|
+
}
|
|
15
23
|
declare class WebsocketHandler<T extends Context> {
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
private readonly handler;
|
|
25
|
+
private readonly peers;
|
|
26
|
+
private readonly encodePeerMessageOptions;
|
|
27
|
+
private readonly decodePeerMessageOptions;
|
|
28
|
+
constructor(handler: StandardHandler<T>, options?: NoInfer<WebsocketHandlerOptions<T>>);
|
|
18
29
|
/**
|
|
19
|
-
*
|
|
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()`
|
|
30
|
+
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
24
31
|
*/
|
|
25
|
-
upgrade(ws:
|
|
32
|
+
upgrade(ws: WebsocketLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
|
|
26
33
|
/**
|
|
27
34
|
* Handles a single message received from a WebSocket.
|
|
28
35
|
*
|
|
29
|
-
* @warning
|
|
36
|
+
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
30
37
|
*
|
|
31
|
-
* @param ws The WebSocket instance
|
|
32
|
-
* @param data The message
|
|
38
|
+
* @param ws The WebSocket instance, require consistent instance across messages for proper peer management
|
|
39
|
+
* @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
|
|
33
40
|
*/
|
|
34
|
-
message(ws:
|
|
41
|
+
message(ws: WebsocketLike, data: string | ArrayBuffer | Blob | Exclude<ConstructorParameters<typeof Blob>[0], undefined>[0][] | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
|
|
42
|
+
matched: boolean;
|
|
43
|
+
}>;
|
|
35
44
|
/**
|
|
36
|
-
*
|
|
45
|
+
* Called when a websocket is closed, to clean up any associated peer state.
|
|
46
|
+
*
|
|
47
|
+
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
37
48
|
*
|
|
38
|
-
* @
|
|
49
|
+
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
39
50
|
*/
|
|
40
|
-
close(ws:
|
|
51
|
+
close(ws: WebsocketLike): Promise<void>;
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
interface RPCHandlerOptions<T extends Context> extends
|
|
54
|
+
interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebsocketHandlerOptions<T> {
|
|
44
55
|
}
|
|
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
56
|
declare class RPCHandler<T extends Context> extends WebsocketHandler<T> {
|
|
52
|
-
constructor(router: Router<
|
|
57
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
export { RPCHandler, WebsocketHandler };
|
|
56
|
-
export type {
|
|
61
|
+
export type { RPCHandlerOptions, WebsocketHandlerOptions, WebsocketLike };
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ServerPeer } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import '../../shared/server.DZ5BIITo.mjs';
|
|
6
|
-
import '@orpc/client/standard';
|
|
1
|
+
import { toStringOrBytes, resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standardserver/peer';
|
|
3
|
+
import { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
|
|
4
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.GDpX6Df8.mjs';
|
|
7
5
|
import '@orpc/client';
|
|
8
|
-
import '@
|
|
9
|
-
import '../../shared/server.
|
|
6
|
+
import '@standardserver/core';
|
|
7
|
+
import '../../shared/server.CrlKQucM.mjs';
|
|
10
8
|
import '@orpc/contract';
|
|
9
|
+
import '../../shared/server.BwHnWUuN.mjs';
|
|
11
10
|
|
|
12
11
|
class WebsocketHandler {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this
|
|
12
|
+
constructor(handler, options = {}) {
|
|
13
|
+
this.handler = handler;
|
|
14
|
+
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
15
|
+
this.decodePeerMessageOptions = options.decodePeerMessage;
|
|
17
16
|
}
|
|
17
|
+
peers = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
encodePeerMessageOptions;
|
|
19
|
+
decodePeerMessageOptions;
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
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()`
|
|
21
|
+
* Attaches necessary event listeners to a WebSocket to handle incoming messages and peer management.
|
|
24
22
|
*/
|
|
25
23
|
upgrade(ws, ...rest) {
|
|
26
24
|
ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
|
|
@@ -29,38 +27,49 @@ class WebsocketHandler {
|
|
|
29
27
|
/**
|
|
30
28
|
* Handles a single message received from a WebSocket.
|
|
31
29
|
*
|
|
32
|
-
* @warning
|
|
30
|
+
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
33
31
|
*
|
|
34
|
-
* @param ws The WebSocket instance
|
|
35
|
-
* @param data The message
|
|
32
|
+
* @param ws The WebSocket instance, require consistent instance across messages for proper peer management
|
|
33
|
+
* @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
|
|
36
34
|
*/
|
|
37
35
|
async message(ws, data, ...rest) {
|
|
38
|
-
let peer = this
|
|
36
|
+
let peer = this.peers.get(ws);
|
|
39
37
|
if (!peer) {
|
|
40
|
-
this
|
|
38
|
+
this.peers.set(ws, peer = new ServerPeer(async (message) => {
|
|
39
|
+
return ws.send(await encodePeerMessage(message, this.encodePeerMessageOptions));
|
|
40
|
+
}));
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const encoded = await toStringOrBytes(data);
|
|
43
|
+
const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
|
|
44
|
+
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
45
|
+
await peer.message(
|
|
46
|
+
result.message,
|
|
47
|
+
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
|
-
*
|
|
53
|
+
* Called when a websocket is closed, to clean up any associated peer state.
|
|
54
|
+
*
|
|
55
|
+
* @warning AVOID calling this method, if `.upgrade()` is used, as `.upgrade()` already sets up necessary event listeners to call this method for incoming messages and manage peer lifecycle.
|
|
50
56
|
*
|
|
51
|
-
* @
|
|
57
|
+
* @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
|
|
52
58
|
*/
|
|
53
|
-
close(ws) {
|
|
54
|
-
const peer = this
|
|
59
|
+
async close(ws) {
|
|
60
|
+
const peer = this.peers.get(ws);
|
|
55
61
|
if (peer) {
|
|
56
|
-
peer.close();
|
|
62
|
+
await peer.close();
|
|
63
|
+
this.peers.delete(ws);
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
class RPCHandler extends WebsocketHandler {
|
|
62
69
|
constructor(router, options = {}) {
|
|
63
|
-
|
|
70
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
71
|
+
const handler = new StandardHandler(codec, options);
|
|
72
|
+
super(handler, options);
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnyORPCError, ClientContext } from '@orpc/client';
|
|
2
|
+
import { AnySchema, ErrorMap } from '@orpc/contract';
|
|
3
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
+
import { C as Context, P as ProcedureClientOptions, a as Procedure, b as ProcedureClient } from '../shared/server.BL22TloH.mjs';
|
|
5
|
+
|
|
6
|
+
declare module "../index" {
|
|
7
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
8
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnyORPCError, ClientContext } from '@orpc/client';
|
|
2
|
+
import { AnySchema, ErrorMap } from '@orpc/contract';
|
|
3
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
|
4
|
+
import { C as Context, P as ProcedureClientOptions, a as Procedure, b as ProcedureClient } from '../shared/server.BL22TloH.js';
|
|
5
|
+
|
|
6
|
+
declare module "../index" {
|
|
7
|
+
interface DecoratedProcedure<TInitialContext extends Context, TInjectedContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError> {
|
|
8
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): Procedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { c as createProcedureClient } from '../shared/server.CrlKQucM.mjs';
|
|
2
|
+
import { D as DecoratedProcedure } from '../shared/server.CjOb6ItT.mjs';
|
|
3
|
+
import '@orpc/client';
|
|
4
|
+
import '@orpc/contract';
|
|
5
|
+
import '@orpc/shared';
|
|
6
|
+
|
|
7
|
+
DecoratedProcedure.prototype.callable = function callable(...rest) {
|
|
8
|
+
const callable2 = createProcedureClient(this, ...rest);
|
|
9
|
+
callable2["~orpc"] = this["~orpc"];
|
|
10
|
+
return callable2;
|
|
11
|
+
};
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseOptions, SerializeOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -25,7 +25,7 @@ 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 | undefined;
|
|
28
|
+
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
29
|
|
|
30
30
|
interface SetCookieOptions extends SerializeOptions {
|
|
31
31
|
/**
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseOptions, SerializeOptions } from 'cookie';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Encodes a Uint8Array to base64url format
|
|
@@ -25,7 +25,7 @@ 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 | undefined;
|
|
28
|
+
declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
|
|
29
29
|
|
|
30
30
|
interface SetCookieOptions extends SerializeOptions {
|
|
31
31
|
/**
|
package/dist/helpers/index.mjs
CHANGED