@orpc/server 1.10.0 → 1.10.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.
| 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { SupportedMessagePort } from '@orpc/client/message-port';
         
     | 
| 
       2 
     | 
    
         
            -
            import { MaybeOptionalOptions } from '@orpc/shared';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { Value, Promisable, MaybeOptionalOptions } from '@orpc/shared';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { DecodedResponseMessage } from '@orpc/standard-server-peer';
         
     | 
| 
       3 
4 
     | 
    
         
             
            import { C as Context, R as Router } from '../../shared/server.B4BGqy3Y.mjs';
         
     | 
| 
       4 
5 
     | 
    
         
             
            import { f as StandardHandler } from '../../shared/server.DBCUJijK.mjs';
         
     | 
| 
       5 
6 
     | 
    
         
             
            import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.mjs';
         
     | 
| 
         @@ -7,17 +8,41 @@ import { S as StandardRPCHandlerOptions } from '../../shared/server.Ck-gOLzq.mjs 
     | 
|
| 
       7 
8 
     | 
    
         
             
            import '@orpc/client';
         
     | 
| 
       8 
9 
     | 
    
         
             
            import '@orpc/contract';
         
     | 
| 
       9 
10 
     | 
    
         
             
            import '@orpc/standard-server';
         
     | 
| 
       10 
     | 
    
         
            -
            import '@orpc/standard-server-peer';
         
     | 
| 
       11 
11 
     | 
    
         
             
            import '../../shared/server.CVKCo60T.mjs';
         
     | 
| 
       12 
12 
     | 
    
         
             
            import '@orpc/client/standard';
         
     | 
| 
       13 
13 
     | 
    
         
             
            import '../../shared/server.DzV1hr3z.mjs';
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
      
 15 
     | 
    
         
            +
            interface MessagePortHandlerOptions<_T extends Context> {
         
     | 
| 
      
 16 
     | 
    
         
            +
                /**
         
     | 
| 
      
 17 
     | 
    
         
            +
                 * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
         
     | 
| 
      
 18 
     | 
    
         
            +
                 * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
         
     | 
| 
      
 19 
     | 
    
         
            +
                 * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
         
     | 
| 
      
 20 
     | 
    
         
            +
                 *
         
     | 
| 
      
 21 
     | 
    
         
            +
                 * @remarks
         
     | 
| 
      
 22 
     | 
    
         
            +
                 * - return null | undefined to disable this feature
         
     | 
| 
      
 23 
     | 
    
         
            +
                 *
         
     | 
| 
      
 24 
     | 
    
         
            +
                 * @warning Make sure your message port supports `transfer` before using this feature.
         
     | 
| 
      
 25 
     | 
    
         
            +
                 * @example
         
     | 
| 
      
 26 
     | 
    
         
            +
                 * ```ts
         
     | 
| 
      
 27 
     | 
    
         
            +
                 * experimental_transfer: (message, port) => {
         
     | 
| 
      
 28 
     | 
    
         
            +
                 *   const transfer = deepFindTransferableObjects(message) // implement your own logic
         
     | 
| 
      
 29 
     | 
    
         
            +
                 *   return transfer.length ? transfer : null // only enable when needed
         
     | 
| 
      
 30 
     | 
    
         
            +
                 * }
         
     | 
| 
      
 31 
     | 
    
         
            +
                 * ```
         
     | 
| 
      
 32 
     | 
    
         
            +
                 *
         
     | 
| 
      
 33 
     | 
    
         
            +
                 * @see {@link https://orpc.unnoq.com/docs/adapters/message-port#transfer Message Port Transfer Docs}
         
     | 
| 
      
 34 
     | 
    
         
            +
                 */
         
     | 
| 
      
 35 
     | 
    
         
            +
                experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedResponseMessage, port: SupportedMessagePort]>;
         
     | 
| 
      
 36 
     | 
    
         
            +
            }
         
     | 
| 
       15 
37 
     | 
    
         
             
            declare class MessagePortHandler<T extends Context> {
         
     | 
| 
       16 
38 
     | 
    
         
             
                private readonly standardHandler;
         
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
      
 39 
     | 
    
         
            +
                private readonly transfer;
         
     | 
| 
      
 40 
     | 
    
         
            +
                constructor(standardHandler: StandardHandler<T>, options?: NoInfer<MessagePortHandlerOptions<T>>);
         
     | 
| 
       18 
41 
     | 
    
         
             
                upgrade(port: SupportedMessagePort, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
         
     | 
| 
       19 
42 
     | 
    
         
             
            }
         
     | 
| 
       20 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
            interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T>, MessagePortHandlerOptions<T> {
         
     | 
| 
      
 45 
     | 
    
         
            +
            }
         
     | 
| 
       21 
46 
     | 
    
         
             
            /**
         
     | 
| 
       22 
47 
     | 
    
         
             
             * RPC Handler for common message port implementations.
         
     | 
| 
       23 
48 
     | 
    
         
             
             *
         
     | 
| 
         @@ -25,7 +50,8 @@ declare class MessagePortHandler<T extends Context> { 
     | 
|
| 
       25 
50 
     | 
    
         
             
             * @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
         
     | 
| 
       26 
51 
     | 
    
         
             
             */
         
     | 
| 
       27 
52 
     | 
    
         
             
            declare class RPCHandler<T extends Context> extends MessagePortHandler<T> {
         
     | 
| 
       28 
     | 
    
         
            -
                constructor(router: Router<any, T>, options?: NoInfer< 
     | 
| 
      
 53 
     | 
    
         
            +
                constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
         
     | 
| 
       29 
54 
     | 
    
         
             
            }
         
     | 
| 
       30 
55 
     | 
    
         | 
| 
       31 
56 
     | 
    
         
             
            export { MessagePortHandler, RPCHandler };
         
     | 
| 
      
 57 
     | 
    
         
            +
            export type { MessagePortHandlerOptions, RPCHandlerOptions };
         
     | 
| 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { SupportedMessagePort } from '@orpc/client/message-port';
         
     | 
| 
       2 
     | 
    
         
            -
            import { MaybeOptionalOptions } from '@orpc/shared';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { Value, Promisable, MaybeOptionalOptions } from '@orpc/shared';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { DecodedResponseMessage } from '@orpc/standard-server-peer';
         
     | 
| 
       3 
4 
     | 
    
         
             
            import { C as Context, R as Router } from '../../shared/server.B4BGqy3Y.js';
         
     | 
| 
       4 
5 
     | 
    
         
             
            import { f as StandardHandler } from '../../shared/server.DPIFWpxG.js';
         
     | 
| 
       5 
6 
     | 
    
         
             
            import { HandleStandardServerPeerMessageOptions } from '../standard-peer/index.js';
         
     | 
| 
         @@ -7,17 +8,41 @@ import { S as StandardRPCHandlerOptions } from '../../shared/server.COL12UTb.js' 
     | 
|
| 
       7 
8 
     | 
    
         
             
            import '@orpc/client';
         
     | 
| 
       8 
9 
     | 
    
         
             
            import '@orpc/contract';
         
     | 
| 
       9 
10 
     | 
    
         
             
            import '@orpc/standard-server';
         
     | 
| 
       10 
     | 
    
         
            -
            import '@orpc/standard-server-peer';
         
     | 
| 
       11 
11 
     | 
    
         
             
            import '../../shared/server.DNtJ-p60.js';
         
     | 
| 
       12 
12 
     | 
    
         
             
            import '@orpc/client/standard';
         
     | 
| 
       13 
13 
     | 
    
         
             
            import '../../shared/server.Cb6yD7DZ.js';
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
      
 15 
     | 
    
         
            +
            interface MessagePortHandlerOptions<_T extends Context> {
         
     | 
| 
      
 16 
     | 
    
         
            +
                /**
         
     | 
| 
      
 17 
     | 
    
         
            +
                 * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
         
     | 
| 
      
 18 
     | 
    
         
            +
                 * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
         
     | 
| 
      
 19 
     | 
    
         
            +
                 * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
         
     | 
| 
      
 20 
     | 
    
         
            +
                 *
         
     | 
| 
      
 21 
     | 
    
         
            +
                 * @remarks
         
     | 
| 
      
 22 
     | 
    
         
            +
                 * - return null | undefined to disable this feature
         
     | 
| 
      
 23 
     | 
    
         
            +
                 *
         
     | 
| 
      
 24 
     | 
    
         
            +
                 * @warning Make sure your message port supports `transfer` before using this feature.
         
     | 
| 
      
 25 
     | 
    
         
            +
                 * @example
         
     | 
| 
      
 26 
     | 
    
         
            +
                 * ```ts
         
     | 
| 
      
 27 
     | 
    
         
            +
                 * experimental_transfer: (message, port) => {
         
     | 
| 
      
 28 
     | 
    
         
            +
                 *   const transfer = deepFindTransferableObjects(message) // implement your own logic
         
     | 
| 
      
 29 
     | 
    
         
            +
                 *   return transfer.length ? transfer : null // only enable when needed
         
     | 
| 
      
 30 
     | 
    
         
            +
                 * }
         
     | 
| 
      
 31 
     | 
    
         
            +
                 * ```
         
     | 
| 
      
 32 
     | 
    
         
            +
                 *
         
     | 
| 
      
 33 
     | 
    
         
            +
                 * @see {@link https://orpc.unnoq.com/docs/adapters/message-port#transfer Message Port Transfer Docs}
         
     | 
| 
      
 34 
     | 
    
         
            +
                 */
         
     | 
| 
      
 35 
     | 
    
         
            +
                experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedResponseMessage, port: SupportedMessagePort]>;
         
     | 
| 
      
 36 
     | 
    
         
            +
            }
         
     | 
| 
       15 
37 
     | 
    
         
             
            declare class MessagePortHandler<T extends Context> {
         
     | 
| 
       16 
38 
     | 
    
         
             
                private readonly standardHandler;
         
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
      
 39 
     | 
    
         
            +
                private readonly transfer;
         
     | 
| 
      
 40 
     | 
    
         
            +
                constructor(standardHandler: StandardHandler<T>, options?: NoInfer<MessagePortHandlerOptions<T>>);
         
     | 
| 
       18 
41 
     | 
    
         
             
                upgrade(port: SupportedMessagePort, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
         
     | 
| 
       19 
42 
     | 
    
         
             
            }
         
     | 
| 
       20 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
            interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T>, MessagePortHandlerOptions<T> {
         
     | 
| 
      
 45 
     | 
    
         
            +
            }
         
     | 
| 
       21 
46 
     | 
    
         
             
            /**
         
     | 
| 
       22 
47 
     | 
    
         
             
             * RPC Handler for common message port implementations.
         
     | 
| 
       23 
48 
     | 
    
         
             
             *
         
     | 
| 
         @@ -25,7 +50,8 @@ declare class MessagePortHandler<T extends Context> { 
     | 
|
| 
       25 
50 
     | 
    
         
             
             * @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
         
     | 
| 
       26 
51 
     | 
    
         
             
             */
         
     | 
| 
       27 
52 
     | 
    
         
             
            declare class RPCHandler<T extends Context> extends MessagePortHandler<T> {
         
     | 
| 
       28 
     | 
    
         
            -
                constructor(router: Router<any, T>, options?: NoInfer< 
     | 
| 
      
 53 
     | 
    
         
            +
                constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
         
     | 
| 
       29 
54 
     | 
    
         
             
            }
         
     | 
| 
       30 
55 
     | 
    
         | 
| 
       31 
56 
     | 
    
         
             
            export { MessagePortHandler, RPCHandler };
         
     | 
| 
      
 57 
     | 
    
         
            +
            export type { MessagePortHandlerOptions, RPCHandlerOptions };
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import { postMessagePortMessage, onMessagePortMessage, onMessagePortClose } from '@orpc/client/message-port';
         
     | 
| 
       2 
     | 
    
         
            -
            import { resolveMaybeOptionalOptions } from '@orpc/shared';
         
     | 
| 
       3 
     | 
    
         
            -
            import {  
     | 
| 
      
 2 
     | 
    
         
            +
            import { value, resolveMaybeOptionalOptions, isObject } from '@orpc/shared';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { experimental_ServerPeerWithoutCodec, serializeResponseMessage, encodeResponseMessage, deserializeRequestMessage, decodeRequestMessage } from '@orpc/standard-server-peer';
         
     | 
| 
       4 
4 
     | 
    
         
             
            import { c as createServerPeerHandleRequestFn } from '../../shared/server.UVMTOWrk.mjs';
         
     | 
| 
       5 
5 
     | 
    
         
             
            import '@orpc/client';
         
     | 
| 
       6 
6 
     | 
    
         
             
            import '@orpc/standard-server';
         
     | 
| 
         @@ -11,18 +11,34 @@ import '../../shared/server.DZ5BIITo.mjs'; 
     | 
|
| 
       11 
11 
     | 
    
         
             
            import '../../shared/server.Ds4HPpvH.mjs';
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            class MessagePortHandler {
         
     | 
| 
       14 
     | 
    
         
            -
              constructor(standardHandler) {
         
     | 
| 
      
 14 
     | 
    
         
            +
              constructor(standardHandler, options = {}) {
         
     | 
| 
       15 
15 
     | 
    
         
             
                this.standardHandler = standardHandler;
         
     | 
| 
      
 16 
     | 
    
         
            +
                this.transfer = options.experimental_transfer;
         
     | 
| 
       16 
17 
     | 
    
         
             
              }
         
     | 
| 
      
 18 
     | 
    
         
            +
              transfer;
         
     | 
| 
       17 
19 
     | 
    
         
             
              upgrade(port, ...rest) {
         
     | 
| 
       18 
     | 
    
         
            -
                const peer = new  
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
      
 20 
     | 
    
         
            +
                const peer = new experimental_ServerPeerWithoutCodec(async (message) => {
         
     | 
| 
      
 21 
     | 
    
         
            +
                  const [id, type, payload] = message;
         
     | 
| 
      
 22 
     | 
    
         
            +
                  const transfer = await value(this.transfer, message, port);
         
     | 
| 
      
 23 
     | 
    
         
            +
                  if (transfer) {
         
     | 
| 
      
 24 
     | 
    
         
            +
                    postMessagePortMessage(port, serializeResponseMessage(id, type, payload), transfer);
         
     | 
| 
      
 25 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 26 
     | 
    
         
            +
                    postMessagePortMessage(port, await encodeResponseMessage(id, type, payload));
         
     | 
| 
      
 27 
     | 
    
         
            +
                  }
         
     | 
| 
       20 
28 
     | 
    
         
             
                });
         
     | 
| 
       21 
29 
     | 
    
         
             
                onMessagePortMessage(port, async (message) => {
         
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                  const handleFn = createServerPeerHandleRequestFn(this.standardHandler, resolveMaybeOptionalOptions(rest));
         
     | 
| 
      
 31 
     | 
    
         
            +
                  if (isObject(message)) {
         
     | 
| 
      
 32 
     | 
    
         
            +
                    await peer.message(
         
     | 
| 
      
 33 
     | 
    
         
            +
                      deserializeRequestMessage(message),
         
     | 
| 
      
 34 
     | 
    
         
            +
                      handleFn
         
     | 
| 
      
 35 
     | 
    
         
            +
                    );
         
     | 
| 
      
 36 
     | 
    
         
            +
                  } else {
         
     | 
| 
      
 37 
     | 
    
         
            +
                    await peer.message(
         
     | 
| 
      
 38 
     | 
    
         
            +
                      await decodeRequestMessage(message),
         
     | 
| 
      
 39 
     | 
    
         
            +
                      handleFn
         
     | 
| 
      
 40 
     | 
    
         
            +
                    );
         
     | 
| 
      
 41 
     | 
    
         
            +
                  }
         
     | 
| 
       26 
42 
     | 
    
         
             
                });
         
     | 
| 
       27 
43 
     | 
    
         
             
                onMessagePortClose(port, () => {
         
     | 
| 
       28 
44 
     | 
    
         
             
                  peer.close();
         
     | 
| 
         @@ -32,7 +48,7 @@ class MessagePortHandler { 
     | 
|
| 
       32 
48 
     | 
    
         | 
| 
       33 
49 
     | 
    
         
             
            class RPCHandler extends MessagePortHandler {
         
     | 
| 
       34 
50 
     | 
    
         
             
              constructor(router, options = {}) {
         
     | 
| 
       35 
     | 
    
         
            -
                super(new StandardRPCHandler(router, options));
         
     | 
| 
      
 51 
     | 
    
         
            +
                super(new StandardRPCHandler(router, options), options);
         
     | 
| 
       36 
52 
     | 
    
         
             
              }
         
     | 
| 
       37 
53 
     | 
    
         
             
            }
         
     | 
| 
       38 
54 
     | 
    
         | 
    
        package/package.json
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "@orpc/server",
         
     | 
| 
       3 
3 
     | 
    
         
             
              "type": "module",
         
     | 
| 
       4 
     | 
    
         
            -
              "version": "1.10. 
     | 
| 
      
 4 
     | 
    
         
            +
              "version": "1.10.1",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "license": "MIT",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "homepage": "https://orpc.unnoq.com",
         
     | 
| 
       7 
7 
     | 
    
         
             
              "repository": {
         
     | 
| 
         @@ -102,18 +102,18 @@ 
     | 
|
| 
       102 
102 
     | 
    
         
             
              },
         
     | 
| 
       103 
103 
     | 
    
         
             
              "dependencies": {
         
     | 
| 
       104 
104 
     | 
    
         
             
                "cookie": "^1.0.2",
         
     | 
| 
       105 
     | 
    
         
            -
                "@orpc/client": "1.10. 
     | 
| 
       106 
     | 
    
         
            -
                "@orpc/ 
     | 
| 
       107 
     | 
    
         
            -
                "@orpc/shared": "1.10. 
     | 
| 
       108 
     | 
    
         
            -
                "@orpc/ 
     | 
| 
       109 
     | 
    
         
            -
                "@orpc/standard-server": "1.10. 
     | 
| 
       110 
     | 
    
         
            -
                "@orpc/standard-server 
     | 
| 
       111 
     | 
    
         
            -
                "@orpc/standard-server- 
     | 
| 
       112 
     | 
    
         
            -
                "@orpc/standard-server- 
     | 
| 
       113 
     | 
    
         
            -
                "@orpc/standard-server-peer": "1.10. 
     | 
| 
      
 105 
     | 
    
         
            +
                "@orpc/client": "1.10.1",
         
     | 
| 
      
 106 
     | 
    
         
            +
                "@orpc/interop": "1.10.1",
         
     | 
| 
      
 107 
     | 
    
         
            +
                "@orpc/shared": "1.10.1",
         
     | 
| 
      
 108 
     | 
    
         
            +
                "@orpc/contract": "1.10.1",
         
     | 
| 
      
 109 
     | 
    
         
            +
                "@orpc/standard-server-aws-lambda": "1.10.1",
         
     | 
| 
      
 110 
     | 
    
         
            +
                "@orpc/standard-server": "1.10.1",
         
     | 
| 
      
 111 
     | 
    
         
            +
                "@orpc/standard-server-node": "1.10.1",
         
     | 
| 
      
 112 
     | 
    
         
            +
                "@orpc/standard-server-fetch": "1.10.1",
         
     | 
| 
      
 113 
     | 
    
         
            +
                "@orpc/standard-server-peer": "1.10.1"
         
     | 
| 
       114 
114 
     | 
    
         
             
              },
         
     | 
| 
       115 
115 
     | 
    
         
             
              "devDependencies": {
         
     | 
| 
       116 
     | 
    
         
            -
                "@tanstack/router-core": "^1.133. 
     | 
| 
      
 116 
     | 
    
         
            +
                "@tanstack/router-core": "^1.133.20",
         
     | 
| 
       117 
117 
     | 
    
         
             
                "@types/ws": "^8.18.1",
         
     | 
| 
       118 
118 
     | 
    
         
             
                "crossws": "^0.4.1",
         
     | 
| 
       119 
119 
     | 
    
         
             
                "next": "^15.5.6",
         
     |