@orpc/server 1.14.6 → 2.0.0-beta.10

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.
Files changed (78) hide show
  1. package/README.md +78 -137
  2. package/dist/adapters/crossws/index.d.mts +42 -21
  3. package/dist/adapters/crossws/index.d.ts +42 -21
  4. package/dist/adapters/crossws/index.mjs +37 -18
  5. package/dist/adapters/fetch/index.d.mts +83 -67
  6. package/dist/adapters/fetch/index.d.ts +83 -67
  7. package/dist/adapters/fetch/index.mjs +131 -106
  8. package/dist/adapters/message-port/index.d.mts +51 -34
  9. package/dist/adapters/message-port/index.d.ts +51 -34
  10. package/dist/adapters/message-port/index.mjs +73 -38
  11. package/dist/adapters/node/index.d.mts +82 -60
  12. package/dist/adapters/node/index.d.ts +82 -60
  13. package/dist/adapters/node/index.mjs +127 -98
  14. package/dist/adapters/standard/index.d.mts +16 -18
  15. package/dist/adapters/standard/index.d.ts +16 -18
  16. package/dist/adapters/standard/index.mjs +5 -5
  17. package/dist/adapters/standard-peer/index.d.mts +12 -14
  18. package/dist/adapters/standard-peer/index.d.ts +12 -14
  19. package/dist/adapters/standard-peer/index.mjs +2 -21
  20. package/dist/adapters/websocket/index.d.mts +50 -36
  21. package/dist/adapters/websocket/index.d.ts +50 -36
  22. package/dist/adapters/websocket/index.mjs +55 -42
  23. package/dist/extensions/callable.d.mts +10 -0
  24. package/dist/extensions/callable.d.ts +10 -0
  25. package/dist/extensions/callable.mjs +11 -0
  26. package/dist/helpers/index.d.mts +2 -2
  27. package/dist/helpers/index.d.ts +2 -2
  28. package/dist/helpers/index.mjs +1 -1
  29. package/dist/index.d.mts +163 -770
  30. package/dist/index.d.ts +163 -770
  31. package/dist/index.mjs +296 -403
  32. package/dist/plugins/index.d.mts +120 -127
  33. package/dist/plugins/index.d.ts +120 -127
  34. package/dist/plugins/index.mjs +252 -223
  35. package/dist/shared/server.BL22TloH.d.mts +184 -0
  36. package/dist/shared/server.BL22TloH.d.ts +184 -0
  37. package/dist/shared/server.BsNNjG5J.d.mts +61 -0
  38. package/dist/shared/server.BwHnWUuN.mjs +222 -0
  39. package/dist/shared/server.CX4vUnDk.mjs +11 -0
  40. package/dist/shared/server.Cj5lgPuG.d.mts +66 -0
  41. package/dist/shared/server.CjOb6ItT.mjs +41 -0
  42. package/dist/shared/server.CrlKQucM.mjs +233 -0
  43. package/dist/shared/server.DBANIheG.d.ts +104 -0
  44. package/dist/shared/server.DJIkub_t.d.mts +104 -0
  45. package/dist/shared/server.D_QauotT.mjs +30 -0
  46. package/dist/shared/server.GDpX6Df8.mjs +271 -0
  47. package/dist/shared/server.Pa0F03f_.d.ts +61 -0
  48. package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
  49. package/dist/shared/server.d_2NS3g5.d.ts +66 -0
  50. package/package.json +26 -55
  51. package/dist/adapters/aws-lambda/index.d.mts +0 -46
  52. package/dist/adapters/aws-lambda/index.d.ts +0 -46
  53. package/dist/adapters/aws-lambda/index.mjs +0 -40
  54. package/dist/adapters/bun-ws/index.d.mts +0 -36
  55. package/dist/adapters/bun-ws/index.d.ts +0 -36
  56. package/dist/adapters/bun-ws/index.mjs +0 -47
  57. package/dist/adapters/fastify/index.d.mts +0 -53
  58. package/dist/adapters/fastify/index.d.ts +0 -53
  59. package/dist/adapters/fastify/index.mjs +0 -52
  60. package/dist/adapters/ws/index.d.mts +0 -31
  61. package/dist/adapters/ws/index.d.ts +0 -31
  62. package/dist/adapters/ws/index.mjs +0 -37
  63. package/dist/hibernation/index.d.mts +0 -44
  64. package/dist/hibernation/index.d.ts +0 -44
  65. package/dist/hibernation/index.mjs +0 -65
  66. package/dist/shared/server.7cEtMB30.d.ts +0 -74
  67. package/dist/shared/server.B8gYOD5g.d.mts +0 -12
  68. package/dist/shared/server.BqadksTP.d.mts +0 -74
  69. package/dist/shared/server.C8_sRzQB.d.mts +0 -42
  70. package/dist/shared/server.ChUyt5-i.d.mts +0 -32
  71. package/dist/shared/server.ChyoA9XY.d.ts +0 -42
  72. package/dist/shared/server.DEBcqOjg.mjs +0 -418
  73. package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
  74. package/dist/shared/server.TEVCLCFC.mjs +0 -39
  75. package/dist/shared/server.ZxHCEN1h.mjs +0 -226
  76. package/dist/shared/server.qKsRrdxW.d.mts +0 -193
  77. package/dist/shared/server.qKsRrdxW.d.ts +0 -193
  78. package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
@@ -1,21 +1,19 @@
1
- import { S as StandardCodec, a as StandardParams } from '../../shared/server.BqadksTP.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.BqadksTP.mjs';
3
- import { ORPCError } from '@orpc/client';
4
- import { StandardRPCSerializer } from '@orpc/client/standard';
5
- import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
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.DJIkub_t.mjs';
2
+ export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, S as StandardHandler, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure, h as StandardHandlerHandleResult, i as StandardHandlerInterceptor, g as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, e as StandardHandlerPlugin, j as StandardHandlerRoutingInterceptor, f as StandardHandlerRoutingInterceptorOptions } from '../../shared/server.DJIkub_t.mjs';
3
+ export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions } from '../../shared/server.Cj5lgPuG.mjs';
4
+ import { C as Context } from '../../shared/server.BL22TloH.mjs';
5
+ export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
+ import '@orpc/client';
10
7
  import '@orpc/shared';
11
- import '../../shared/server.C8_sRzQB.mjs';
8
+ import '@orpc/contract';
9
+ import '../../shared/server.BsNNjG5J.mjs';
12
10
 
13
- declare class StandardRPCCodec implements StandardCodec {
14
- private readonly serializer;
15
- constructor(serializer: StandardRPCSerializer);
16
- decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
17
- encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
18
- encodeError(error: ORPCError<any, any>): StandardResponse;
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 { StandardCodec, StandardParams, StandardRPCCodec };
18
+ export { StandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions };
19
+ export type { FriendlyStandardHandlerHandleOptions };
@@ -1,21 +1,19 @@
1
- import { S as StandardCodec, a as StandardParams } from '../../shared/server.7cEtMB30.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.7cEtMB30.js';
3
- import { ORPCError } from '@orpc/client';
4
- import { StandardRPCSerializer } from '@orpc/client/standard';
5
- import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
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.DBANIheG.js';
2
+ export { C as CompositeStandardHandlerPlugin, O as OtelHandlerPlugin, S as StandardHandler, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure, h as StandardHandlerHandleResult, i as StandardHandlerInterceptor, g as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, e as StandardHandlerPlugin, j as StandardHandlerRoutingInterceptor, f as StandardHandlerRoutingInterceptorOptions } from '../../shared/server.DBANIheG.js';
3
+ export { a as RPCHandlerCodec, R as RPCHandlerCodecOptions, b as RPCMatcher, c as RPCMatcherOptions } from '../../shared/server.d_2NS3g5.js';
4
+ import { C as Context } from '../../shared/server.BL22TloH.js';
5
+ export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
+ import '@orpc/client';
10
7
  import '@orpc/shared';
11
- import '../../shared/server.ChyoA9XY.js';
8
+ import '@orpc/contract';
9
+ import '../../shared/server.Pa0F03f_.js';
12
10
 
13
- declare class StandardRPCCodec implements StandardCodec {
14
- private readonly serializer;
15
- constructor(serializer: StandardRPCSerializer);
16
- decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
17
- encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
18
- encodeError(error: ORPCError<any, any>): StandardResponse;
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 { StandardCodec, StandardParams, StandardRPCCodec };
18
+ export { StandardHandlerHandleOptions, resolveFriendlyStandardHandlerHandleOptions };
19
+ export type { FriendlyStandardHandlerHandleOptions };
@@ -1,8 +1,8 @@
1
- export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.ZxHCEN1h.mjs';
2
- export { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
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 '@orpc/standard-server';
7
- import '../../shared/server.DEBcqOjg.mjs';
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 { 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';
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.DJIkub_t.mjs';
5
5
  import '@orpc/client';
6
6
  import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/standard-server';
9
7
 
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;
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 { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
18
- export type { HandleStandardServerPeerMessageOptions };
15
+ export { createStandardPeerRequestHandler };
16
+ export type { StandardPeerRequestHandlerOptions };
@@ -1,18 +1,16 @@
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';
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.DBANIheG.js';
5
5
  import '@orpc/client';
6
6
  import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/standard-server';
9
7
 
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;
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 { createServerPeerHandleRequestFn, handleStandardServerPeerMessage };
18
- export type { HandleStandardServerPeerMessageOptions };
15
+ export { createStandardPeerRequestHandler };
16
+ export type { StandardPeerRequestHandlerOptions };
@@ -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
+ export { c as createStandardPeerRequestHandler } from '../../shared/server.CX4vUnDk.mjs';
2
+ import '@orpc/shared';
@@ -1,56 +1,70 @@
1
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.ChUyt5-i.mjs';
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.DJIkub_t.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.Cj5lgPuG.mjs';
6
8
  import '@orpc/client';
7
9
  import '@orpc/contract';
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';
10
+ import '@standardserver/core';
13
11
 
14
- type MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
15
- declare class WebsocketHandler<T extends Context> {
16
- #private;
17
- constructor(standardHandler: StandardHandler<T>);
12
+ /**
13
+ * Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
14
+ * Cloudflare WebSocket Hibernation, and similar implementations.
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;
18
24
  /**
19
- * Upgrades a WebSocket to enable handling
25
+ * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
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 message received from a WebSocket.
20
37
  *
21
- * This attaches the necessary 'message' and 'close' listeners to the WebSocket
38
+ * @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.
22
39
  *
23
- * @warning Do not use this method if you're using `.message()` or `.close()`
40
+ * @param ws The WebSocket instance, require consistent instance across messages for proper peer management
41
+ * @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
24
42
  */
25
- upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
43
+ 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<{
44
+ matched: boolean;
45
+ }>;
26
46
  /**
27
- * Handles a single message received from a WebSocket.
47
+ * Called when a websocket is closed, to clean up any associated peer state.
28
48
  *
29
- * @warning Avoid calling this directly if `.upgrade()` is used.
49
+ * @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
50
  *
31
- * @param ws The WebSocket instance
32
- * @param data The message payload, usually place in `event.data`
51
+ * @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
33
52
  */
34
- message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
53
+ close(ws: WebSocketLike): Promise<void>;
35
54
  /**
36
- * Closes the WebSocket peer and cleans up.
55
+ * Attaches websocket event listeners for message and close handling.
37
56
  *
38
- * @warning Avoid calling this directly if `.upgrade()` is used.
57
+ * Use this instead of calling `.message()` and `.close()` manually.
58
+ * Requires a websocket-like object that supports `addEventListener` and `removeEventListener`.
39
59
  */
40
- close(ws: MinimalWebsocket): void;
60
+ upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
41
61
  }
42
62
 
43
- interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T> {
63
+ interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
44
64
  }
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>>);
65
+ declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
66
+ constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
53
67
  }
54
68
 
55
- export { RPCHandler, WebsocketHandler };
56
- export type { MinimalWebsocket, RPCHandlerOptions };
69
+ export { RPCHandler, WebSocketHandler };
70
+ export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
@@ -1,56 +1,70 @@
1
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.yoEB3Fx4.js';
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.DBANIheG.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.d_2NS3g5.js';
6
8
  import '@orpc/client';
7
9
  import '@orpc/contract';
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';
10
+ import '@standardserver/core';
13
11
 
14
- type MinimalWebsocket = Pick<WebSocket, 'addEventListener' | 'send'>;
15
- declare class WebsocketHandler<T extends Context> {
16
- #private;
17
- constructor(standardHandler: StandardHandler<T>);
12
+ /**
13
+ * Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
14
+ * Cloudflare WebSocket Hibernation, and similar implementations.
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;
18
24
  /**
19
- * Upgrades a WebSocket to enable handling
25
+ * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
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 message received from a WebSocket.
20
37
  *
21
- * This attaches the necessary 'message' and 'close' listeners to the WebSocket
38
+ * @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.
22
39
  *
23
- * @warning Do not use this method if you're using `.message()` or `.close()`
40
+ * @param ws The WebSocket instance, require consistent instance across messages for proper peer management
41
+ * @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
24
42
  */
25
- upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
43
+ 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<{
44
+ matched: boolean;
45
+ }>;
26
46
  /**
27
- * Handles a single message received from a WebSocket.
47
+ * Called when a websocket is closed, to clean up any associated peer state.
28
48
  *
29
- * @warning Avoid calling this directly if `.upgrade()` is used.
49
+ * @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
50
  *
31
- * @param ws The WebSocket instance
32
- * @param data The message payload, usually place in `event.data`
51
+ * @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
33
52
  */
34
- message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
53
+ close(ws: WebSocketLike): Promise<void>;
35
54
  /**
36
- * Closes the WebSocket peer and cleans up.
55
+ * Attaches websocket event listeners for message and close handling.
37
56
  *
38
- * @warning Avoid calling this directly if `.upgrade()` is used.
57
+ * Use this instead of calling `.message()` and `.close()` manually.
58
+ * Requires a websocket-like object that supports `addEventListener` and `removeEventListener`.
39
59
  */
40
- close(ws: MinimalWebsocket): void;
60
+ upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
41
61
  }
42
62
 
43
- interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T> {
63
+ interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
44
64
  }
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>>);
65
+ declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
66
+ constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
53
67
  }
54
68
 
55
- export { RPCHandler, WebsocketHandler };
56
- export type { MinimalWebsocket, RPCHandlerOptions };
69
+ export { RPCHandler, WebSocketHandler };
70
+ export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
@@ -1,67 +1,80 @@
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.ZxHCEN1h.mjs';
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 '@orpc/standard-server';
9
- import '../../shared/server.DEBcqOjg.mjs';
6
+ import '@standardserver/core';
7
+ import '../../shared/server.CrlKQucM.mjs';
10
8
  import '@orpc/contract';
9
+ import '../../shared/server.BwHnWUuN.mjs';
11
10
 
12
- class WebsocketHandler {
13
- #peers = /* @__PURE__ */ new WeakMap();
14
- #handler;
15
- constructor(standardHandler) {
16
- this.#handler = standardHandler;
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
- */
25
- upgrade(ws, ...rest) {
26
- ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
27
- ws.addEventListener("close", () => this.close(ws));
11
+ class WebSocketHandler {
12
+ constructor(handler, options = {}) {
13
+ this.handler = handler;
14
+ this.encodePeerMessageOptions = options.encodePeerMessage;
15
+ this.decodePeerMessageOptions = options.decodePeerMessage;
28
16
  }
17
+ peers = /* @__PURE__ */ new WeakMap();
18
+ encodePeerMessageOptions;
19
+ decodePeerMessageOptions;
29
20
  /**
30
21
  * Handles a single message received from a WebSocket.
31
22
  *
32
- * @warning Avoid calling this directly if `.upgrade()` is used.
23
+ * @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
24
  *
34
- * @param ws The WebSocket instance
35
- * @param data The message payload, usually place in `event.data`
25
+ * @param ws The WebSocket instance, require consistent instance across messages for proper peer management
26
+ * @param data The message data received from the WebSocket, can be string, ArrayBuffer, Blob, ...
36
27
  */
37
28
  async message(ws, data, ...rest) {
38
- let peer = this.#peers.get(ws);
29
+ let peer = this.peers.get(ws);
39
30
  if (!peer) {
40
- this.#peers.set(ws, peer = new ServerPeer(ws.send.bind(ws)));
31
+ this.peers.set(ws, peer = new ServerPeer(async (message) => {
32
+ const encoded2 = await encodePeerMessage(message, this.encodePeerMessageOptions);
33
+ await ws.send(encoded2);
34
+ }));
35
+ }
36
+ const encoded = await toStringOrBytes(data);
37
+ const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
38
+ if (result.matched && isClientPeerSendMessage(result.message)) {
39
+ await peer.message(
40
+ result.message,
41
+ createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
42
+ );
41
43
  }
42
- const message = data instanceof Blob ? await readAsBuffer(data) : data;
43
- await peer.message(
44
- message,
45
- createServerPeerHandleRequestFn(this.#handler, resolveMaybeOptionalOptions(rest))
46
- );
44
+ return result;
47
45
  }
48
46
  /**
49
- * Closes the WebSocket peer and cleans up.
47
+ * Called when a websocket is closed, to clean up any associated peer state.
50
48
  *
51
- * @warning Avoid calling this directly if `.upgrade()` is used.
49
+ * @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
+ *
51
+ * @param ws The WebSocket instance to clean up, must be the same instance used in `.message()` calls to properly clean up
52
52
  */
53
- close(ws) {
54
- const peer = this.#peers.get(ws);
53
+ async close(ws) {
54
+ const peer = this.peers.get(ws);
55
55
  if (peer) {
56
- peer.close();
56
+ await peer.close();
57
+ this.peers.delete(ws);
57
58
  }
58
59
  }
60
+ /**
61
+ * Attaches websocket event listeners for message and close handling.
62
+ *
63
+ * Use this instead of calling `.message()` and `.close()` manually.
64
+ * Requires a websocket-like object that supports `addEventListener` and `removeEventListener`.
65
+ */
66
+ upgrade(ws, ...rest) {
67
+ ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
68
+ ws.addEventListener("close", () => this.close(ws));
69
+ }
59
70
  }
60
71
 
61
- class RPCHandler extends WebsocketHandler {
72
+ class RPCHandler extends WebSocketHandler {
62
73
  constructor(router, options = {}) {
63
- super(new StandardRPCHandler(router, options));
74
+ const codec = new RPCHandlerCodec(router, options);
75
+ const handler = new StandardHandler(codec, options);
76
+ super(handler, options);
64
77
  }
65
78
  }
66
79
 
67
- export { RPCHandler, WebsocketHandler };
80
+ export { RPCHandler, WebSocketHandler };
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- import { SerializeOptions, ParseOptions } from 'cookie';
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
  /**
@@ -1,4 +1,4 @@
1
- import { SerializeOptions, ParseOptions } from 'cookie';
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
  /**
@@ -1,4 +1,4 @@
1
- import { serialize, parse } from 'cookie';
1
+ import { parse, serialize } from 'cookie';
2
2
 
3
3
  function encodeBase64url(data) {
4
4
  const chunkSize = 8192;