@orpc/server 1.14.9 → 1.14.11

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 +52 -98
  2. package/dist/adapters/crossws/index.d.mts +45 -21
  3. package/dist/adapters/crossws/index.d.ts +45 -21
  4. package/dist/adapters/crossws/index.mjs +40 -18
  5. package/dist/adapters/fetch/index.d.mts +64 -96
  6. package/dist/adapters/fetch/index.d.ts +64 -96
  7. package/dist/adapters/fetch/index.mjs +34 -139
  8. package/dist/adapters/message-port/index.d.mts +49 -34
  9. package/dist/adapters/message-port/index.d.ts +49 -34
  10. package/dist/adapters/message-port/index.mjs +68 -37
  11. package/dist/adapters/node/index.d.mts +63 -71
  12. package/dist/adapters/node/index.d.ts +63 -71
  13. package/dist/adapters/node/index.mjs +36 -113
  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 +53 -38
  21. package/dist/adapters/websocket/index.d.ts +53 -38
  22. package/dist/adapters/websocket/index.mjs +59 -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 +4 -4
  27. package/dist/helpers/index.d.ts +4 -4
  28. package/dist/helpers/index.mjs +13 -5
  29. package/dist/index.d.mts +166 -770
  30. package/dist/index.d.ts +166 -770
  31. package/dist/index.mjs +306 -399
  32. package/dist/plugins/index.d.mts +214 -121
  33. package/dist/plugins/index.d.ts +214 -121
  34. package/dist/plugins/index.mjs +576 -214
  35. package/dist/shared/server.15O7oC1p.d.mts +61 -0
  36. package/dist/shared/server.B4BnEWWm.d.mts +67 -0
  37. package/dist/shared/server.BhsVw7m7.d.ts +104 -0
  38. package/dist/shared/server.BoiFpNT7.mjs +224 -0
  39. package/dist/shared/server.COPVXhDG.mjs +271 -0
  40. package/dist/shared/server.CX4vUnDk.mjs +11 -0
  41. package/dist/shared/server.CcR4kgje.d.mts +206 -0
  42. package/dist/shared/server.CcR4kgje.d.ts +206 -0
  43. package/dist/shared/server.CnN50DHH.d.ts +67 -0
  44. package/dist/shared/server.DBs0rrf9.mjs +41 -0
  45. package/dist/shared/server.DDFizwfU.d.mts +104 -0
  46. package/dist/shared/server.D_QauotT.mjs +30 -0
  47. package/dist/shared/server.DofEOwf-.mjs +237 -0
  48. package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
  49. package/dist/shared/server.m3szVJGU.d.ts +61 -0
  50. package/package.json +26 -56
  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 -41
  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,56 +1,71 @@
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';
1
+ import { Arrayable, MaybeOptionalOptions } from '@orpc/shared';
2
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
3
+ import { C as Context } from '../../shared/server.CcR4kgje.mjs';
4
+ import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DDFizwfU.mjs';
5
+ import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.mjs';
6
+ import { R as Router } from '../../shared/server.15O7oC1p.mjs';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.B4BnEWWm.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 WebSocket message.
37
+ *
38
+ * Message order matters. Call this immediately after receiving a message,
39
+ * before any other async work, to preserve ordering.
20
40
  *
21
- * This attaches the necessary 'message' and 'close' listeners to the WebSocket
41
+ * To avoid async Blob reads, configure `ws.binaryType` to return binary data
42
+ * directly (for example, `arraybuffer`).
22
43
  *
23
- * @warning Do not use this method if you're using `.message()` or `.close()`
44
+ * @param ws The WebSocket instance. Use the same instance for all messages.
45
+ * @param data The received message. Binary data should already be loaded (not a `Blob`).
24
46
  */
25
- upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
47
+ message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
48
+ matched: boolean;
49
+ }>;
26
50
  /**
27
- * Handles a single message received from a WebSocket.
28
- *
29
- * @warning Avoid calling this directly if `.upgrade()` is used.
51
+ * Cleans up peer state for a closed WebSocket.
30
52
  *
31
- * @param ws The WebSocket instance
32
- * @param data The message payload, usually place in `event.data`
53
+ * @param ws The same WebSocket instance passed to `.message()`.
33
54
  */
34
- message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
55
+ close(ws: WebSocketLike): Promise<void>;
35
56
  /**
36
- * Closes the WebSocket peer and cleans up.
57
+ * Attaches message and close event listeners to a WebSocket.
37
58
  *
38
- * @warning Avoid calling this directly if `.upgrade()` is used.
59
+ * Prefer this over calling `.message()` and `.close()` manually.
39
60
  */
40
- close(ws: MinimalWebsocket): void;
61
+ upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
41
62
  }
42
63
 
43
- interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T> {
64
+ interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
44
65
  }
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>>);
66
+ declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
67
+ constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
53
68
  }
54
69
 
55
- export { RPCHandler, WebsocketHandler };
56
- export type { MinimalWebsocket, RPCHandlerOptions };
70
+ export { RPCHandler, WebSocketHandler };
71
+ export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
@@ -1,56 +1,71 @@
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';
1
+ import { Arrayable, MaybeOptionalOptions } from '@orpc/shared';
2
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
3
+ import { C as Context } from '../../shared/server.CcR4kgje.js';
4
+ import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.BhsVw7m7.js';
5
+ import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
6
+ import { R as Router } from '../../shared/server.m3szVJGU.js';
7
+ import { R as RPCHandlerCodecOptions } from '../../shared/server.CnN50DHH.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 WebSocket message.
37
+ *
38
+ * Message order matters. Call this immediately after receiving a message,
39
+ * before any other async work, to preserve ordering.
20
40
  *
21
- * This attaches the necessary 'message' and 'close' listeners to the WebSocket
41
+ * To avoid async Blob reads, configure `ws.binaryType` to return binary data
42
+ * directly (for example, `arraybuffer`).
22
43
  *
23
- * @warning Do not use this method if you're using `.message()` or `.close()`
44
+ * @param ws The WebSocket instance. Use the same instance for all messages.
45
+ * @param data The received message. Binary data should already be loaded (not a `Blob`).
24
46
  */
25
- upgrade(ws: MinimalWebsocket, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): void;
47
+ message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, 'buffer' | 'byteOffset' | 'byteLength'>>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
48
+ matched: boolean;
49
+ }>;
26
50
  /**
27
- * Handles a single message received from a WebSocket.
28
- *
29
- * @warning Avoid calling this directly if `.upgrade()` is used.
51
+ * Cleans up peer state for a closed WebSocket.
30
52
  *
31
- * @param ws The WebSocket instance
32
- * @param data The message payload, usually place in `event.data`
53
+ * @param ws The same WebSocket instance passed to `.message()`.
33
54
  */
34
- message(ws: MinimalWebsocket, data: string | ArrayBuffer | Blob, ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>): Promise<void>;
55
+ close(ws: WebSocketLike): Promise<void>;
35
56
  /**
36
- * Closes the WebSocket peer and cleans up.
57
+ * Attaches message and close event listeners to a WebSocket.
37
58
  *
38
- * @warning Avoid calling this directly if `.upgrade()` is used.
59
+ * Prefer this over calling `.message()` and `.close()` manually.
39
60
  */
40
- close(ws: MinimalWebsocket): void;
61
+ upgrade(ws: Pick<WebSocket, 'send' | 'addEventListener' | 'removeEventListener'>, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): void;
41
62
  }
42
63
 
43
- interface RPCHandlerOptions<T extends Context> extends StandardRPCHandlerOptions<T> {
64
+ interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {
44
65
  }
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>>);
66
+ declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
67
+ constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
53
68
  }
54
69
 
55
- export { RPCHandler, WebsocketHandler };
56
- export type { MinimalWebsocket, RPCHandlerOptions };
70
+ export { RPCHandler, WebSocketHandler };
71
+ export type { RPCHandlerOptions, WebSocketHandlerOptions, WebSocketLike };
@@ -1,67 +1,84 @@
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, sequential, loadBytes } 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.COPVXhDG.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.DofEOwf-.mjs';
10
8
  import '@orpc/contract';
9
+ import '../../shared/server.BoiFpNT7.mjs';
11
10
 
12
- class WebsocketHandler {
13
- #peers = /* @__PURE__ */ new WeakMap();
14
- #handler;
15
- constructor(standardHandler) {
16
- this.#handler = standardHandler;
11
+ class WebSocketHandler {
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
- * Upgrades a WebSocket to enable handling
21
+ * Handles a single WebSocket message.
20
22
  *
21
- * This attaches the necessary 'message' and 'close' listeners to the WebSocket
23
+ * Message order matters. Call this immediately after receiving a message,
24
+ * before any other async work, to preserve ordering.
22
25
  *
23
- * @warning Do not use this method if you're using `.message()` or `.close()`
24
- */
25
- upgrade(ws, ...rest) {
26
- ws.addEventListener("message", (event) => this.message(ws, event.data, ...rest));
27
- ws.addEventListener("close", () => this.close(ws));
28
- }
29
- /**
30
- * Handles a single message received from a WebSocket.
31
- *
32
- * @warning Avoid calling this directly if `.upgrade()` is used.
26
+ * To avoid async Blob reads, configure `ws.binaryType` to return binary data
27
+ * directly (for example, `arraybuffer`).
33
28
  *
34
- * @param ws The WebSocket instance
35
- * @param data The message payload, usually place in `event.data`
29
+ * @param ws The WebSocket instance. Use the same instance for all messages.
30
+ * @param data The received message. Binary data should already be loaded (not a `Blob`).
36
31
  */
37
32
  async message(ws, data, ...rest) {
38
- let peer = this.#peers.get(ws);
33
+ let peer = this.peers.get(ws);
39
34
  if (!peer) {
40
- this.#peers.set(ws, peer = new ServerPeer(ws.send.bind(ws)));
35
+ this.peers.set(ws, peer = new ServerPeer(async (message) => {
36
+ const encoded2 = await encodePeerMessage(message, this.encodePeerMessageOptions);
37
+ await ws.send(encoded2);
38
+ }));
39
+ }
40
+ const encoded = toStringOrBytes(data);
41
+ const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
42
+ if (result.matched && isClientPeerSendMessage(result.message)) {
43
+ await peer.message(
44
+ result.message,
45
+ createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
46
+ );
41
47
  }
42
- const message = data instanceof Blob ? await readAsBuffer(data) : data;
43
- await peer.message(
44
- message,
45
- createServerPeerHandleRequestFn(this.#handler, resolveMaybeOptionalOptions(rest))
46
- );
48
+ return result;
47
49
  }
48
50
  /**
49
- * Closes the WebSocket peer and cleans up.
51
+ * Cleans up peer state for a closed WebSocket.
50
52
  *
51
- * @warning Avoid calling this directly if `.upgrade()` is used.
53
+ * @param ws The same WebSocket instance passed to `.message()`.
52
54
  */
53
- close(ws) {
54
- const peer = this.#peers.get(ws);
55
+ async close(ws) {
56
+ const peer = this.peers.get(ws);
55
57
  if (peer) {
56
- peer.close();
58
+ this.peers.delete(ws);
59
+ await peer.close();
57
60
  }
58
61
  }
62
+ /**
63
+ * Attaches message and close event listeners to a WebSocket.
64
+ *
65
+ * Prefer this over calling `.message()` and `.close()` manually.
66
+ */
67
+ upgrade(ws, ...rest) {
68
+ ws.addEventListener("message", sequential(async (event) => {
69
+ const data = event.data instanceof Blob ? await loadBytes(event.data) : event.data;
70
+ this.message(ws, data, ...rest);
71
+ }));
72
+ ws.addEventListener("close", () => this.close(ws));
73
+ }
59
74
  }
60
75
 
61
- class RPCHandler extends WebsocketHandler {
76
+ class RPCHandler extends WebSocketHandler {
62
77
  constructor(router, options = {}) {
63
- super(new StandardRPCHandler(router, options));
78
+ const codec = new RPCHandlerCodec(router, options);
79
+ const handler = new StandardHandler(codec, options);
80
+ super(handler, options);
64
81
  }
65
82
  }
66
83
 
67
- export { RPCHandler, WebsocketHandler };
84
+ 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.CcR4kgje.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.CcR4kgje.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.DofEOwf-.mjs';
2
+ import { D as DecoratedProcedure } from '../shared/server.DBs0rrf9.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, SetCookie, StringifyOptions } from 'cookie';
2
2
 
3
3
  /**
4
4
  * Encodes a Uint8Array to base64url format
@@ -25,9 +25,9 @@ declare function encodeBase64url(data: Uint8Array): string;
25
25
  * expect(new TextDecoder().decode(decoded)).toEqual(text)
26
26
  * ```
27
27
  */
28
- declare function decodeBase64url(base64url: string | undefined | null): Uint8Array | undefined;
28
+ declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
29
29
 
30
- interface SetCookieOptions extends SerializeOptions {
30
+ interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
31
31
  /**
32
32
  * Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
33
33
  *
@@ -46,7 +46,7 @@ interface SetCookieOptions extends SerializeOptions {
46
46
  *
47
47
  * setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
48
48
  *
49
- * expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; HttpOnly; Max-Age=3600')
49
+ * expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
50
50
  * ```
51
51
  *
52
52
  */
@@ -1,4 +1,4 @@
1
- import { SerializeOptions, ParseOptions } from 'cookie';
1
+ import { ParseOptions, SetCookie, StringifyOptions } from 'cookie';
2
2
 
3
3
  /**
4
4
  * Encodes a Uint8Array to base64url format
@@ -25,9 +25,9 @@ declare function encodeBase64url(data: Uint8Array): string;
25
25
  * expect(new TextDecoder().decode(decoded)).toEqual(text)
26
26
  * ```
27
27
  */
28
- declare function decodeBase64url(base64url: string | undefined | null): Uint8Array | undefined;
28
+ declare function decodeBase64url(base64url: string | undefined | null): Uint8Array<ArrayBuffer> | undefined;
29
29
 
30
- interface SetCookieOptions extends SerializeOptions {
30
+ interface SetCookieOptions extends Omit<SetCookie, 'name' | 'value'>, StringifyOptions {
31
31
  /**
32
32
  * Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
33
33
  *
@@ -46,7 +46,7 @@ interface SetCookieOptions extends SerializeOptions {
46
46
  *
47
47
  * setCookie(headers, 'sessionId', 'abc123', { httpOnly: true, maxAge: 3600 })
48
48
  *
49
- * expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; HttpOnly; Max-Age=3600')
49
+ * expect(headers.get('Set-Cookie')).toBe('sessionId=abc123; Max-Age=3600; Path=/; HttpOnly')
50
50
  * ```
51
51
  *
52
52
  */
@@ -1,4 +1,4 @@
1
- import { serialize, parse } from 'cookie';
1
+ import { parseCookie, stringifySetCookie } from 'cookie';
2
2
 
3
3
  function encodeBase64url(data) {
4
4
  const chunkSize = 8192;
@@ -34,10 +34,17 @@ function setCookie(headers, name, value, options = {}) {
34
34
  if (headers === void 0) {
35
35
  return;
36
36
  }
37
- const cookieString = serialize(name, value, {
37
+ const cookieString = stringifySetCookie({
38
+ // Force path to '/' by default so the cookie is available across the
39
+ // entire app, not just under the directory of the request that set it
40
+ // (which is what browsers do per RFC 6265 §5.1.4 when Path is omitted).
38
41
  path: "/",
39
- ...options
40
- });
42
+ ...options,
43
+ name,
44
+ // prioritize
45
+ value
46
+ // prioritize
47
+ }, options);
41
48
  headers.append("Set-Cookie", cookieString);
42
49
  }
43
50
  function getCookie(headers, name, options = {}) {
@@ -48,12 +55,13 @@ function getCookie(headers, name, options = {}) {
48
55
  if (cookieHeader === null) {
49
56
  return void 0;
50
57
  }
51
- return parse(cookieHeader, options)[name];
58
+ return parseCookie(cookieHeader, options)[name];
52
59
  }
53
60
  function deleteCookie(headers, name, options = {}) {
54
61
  return setCookie(headers, name, "", {
55
62
  ...options,
56
63
  maxAge: 0
64
+ // prioritize
57
65
  });
58
66
  }
59
67