@orpc/server 2.0.0-beta.4 → 2.0.0-beta.40

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 (60) hide show
  1. package/README.md +97 -94
  2. package/dist/adapters/aws-lambda/index.d.mts +50 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +50 -0
  4. package/dist/adapters/aws-lambda/index.mjs +39 -0
  5. package/dist/adapters/crossws/index.d.mts +21 -12
  6. package/dist/adapters/crossws/index.d.ts +21 -12
  7. package/dist/adapters/crossws/index.mjs +14 -10
  8. package/dist/adapters/fastify/index.d.mts +42 -0
  9. package/dist/adapters/fastify/index.d.ts +42 -0
  10. package/dist/adapters/fastify/index.mjs +39 -0
  11. package/dist/adapters/fetch/index.d.mts +21 -114
  12. package/dist/adapters/fetch/index.d.ts +21 -114
  13. package/dist/adapters/fetch/index.mjs +20 -182
  14. package/dist/adapters/message-port/index.d.mts +23 -20
  15. package/dist/adapters/message-port/index.d.ts +23 -20
  16. package/dist/adapters/message-port/index.mjs +31 -34
  17. package/dist/adapters/node/index.d.mts +19 -96
  18. package/dist/adapters/node/index.d.ts +19 -96
  19. package/dist/adapters/node/index.mjs +19 -157
  20. package/dist/adapters/standard/index.d.mts +91 -17
  21. package/dist/adapters/standard/index.d.ts +91 -17
  22. package/dist/adapters/standard/index.mjs +4 -4
  23. package/dist/adapters/standard-peer/index.d.mts +6 -11
  24. package/dist/adapters/standard-peer/index.d.ts +6 -11
  25. package/dist/adapters/standard-peer/index.mjs +10 -2
  26. package/dist/adapters/websocket/index.d.mts +45 -29
  27. package/dist/adapters/websocket/index.d.ts +45 -29
  28. package/dist/adapters/websocket/index.mjs +37 -28
  29. package/dist/extensions/callable.d.mts +5 -5
  30. package/dist/extensions/callable.d.ts +5 -5
  31. package/dist/extensions/callable.mjs +2 -2
  32. package/dist/helpers/index.d.mts +23 -6
  33. package/dist/helpers/index.d.ts +23 -6
  34. package/dist/helpers/index.mjs +13 -5
  35. package/dist/index.d.mts +332 -37
  36. package/dist/index.d.ts +332 -37
  37. package/dist/index.mjs +131 -49
  38. package/dist/plugins/index.d.mts +243 -31
  39. package/dist/plugins/index.d.ts +243 -31
  40. package/dist/plugins/index.mjs +527 -30
  41. package/dist/shared/server.1ExWFMze.mjs +69 -0
  42. package/dist/shared/{server.CjOb6ItT.mjs → server.24nXyhbl.mjs} +1 -1
  43. package/dist/shared/{server.DBANIheG.d.ts → server.B5K1CViq.d.mts} +24 -13
  44. package/dist/shared/{server.BsNNjG5J.d.mts → server.BpmUhems.d.mts} +32 -20
  45. package/dist/shared/{server.BL22TloH.d.mts → server.BsujoJoF.d.mts} +38 -59
  46. package/dist/shared/{server.BL22TloH.d.ts → server.BsujoJoF.d.ts} +38 -59
  47. package/dist/shared/{server.BwHnWUuN.mjs → server.BynNaBBA.mjs} +24 -19
  48. package/dist/shared/{server.GDpX6Df8.mjs → server.C0lFtoHU.mjs} +162 -68
  49. package/dist/shared/server.C7xllBNN.d.mts +34 -0
  50. package/dist/shared/server.CFqSIFnT.d.mts +14 -0
  51. package/dist/shared/{server.Pa0F03f_.d.ts → server.CRwPbhLO.d.ts} +32 -20
  52. package/dist/shared/{server.DJIkub_t.d.mts → server.Cxranw-8.d.ts} +24 -13
  53. package/dist/shared/server.D0dr-F8u.d.ts +34 -0
  54. package/dist/shared/{server.CrlKQucM.mjs → server.Djb_ebJT.mjs} +25 -53
  55. package/dist/shared/server.RRVK1xTV.d.ts +14 -0
  56. package/package.json +47 -14
  57. package/dist/shared/server.CX4vUnDk.mjs +0 -11
  58. package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
  59. package/dist/shared/server.D_QauotT.mjs +0 -30
  60. package/dist/shared/server.d_2NS3g5.d.ts +0 -66
@@ -1,14 +1,14 @@
1
1
  import { MaybeOptionalOptions } from '@orpc/shared';
2
- import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
2
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
3
3
  import { Message, Peer } from 'crossws';
4
- import { C as Context } from '../../shared/server.BL22TloH.js';
5
- import { S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DBANIheG.js';
6
- import { StandardPeerRequestHandlerOptions } from '../standard-peer/index.js';
7
- import { R as Router } from '../../shared/server.Pa0F03f_.js';
8
- import { R as RPCHandlerCodecOptions } from '../../shared/server.d_2NS3g5.js';
4
+ import { Context } from '../../index.js';
5
+ import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
6
+ import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
7
+ import { Router } from '../../index.js';
8
+ import { RPCHandlerCodecOptions } from '../standard/index.js';
9
9
  import '@orpc/client';
10
10
  import '@orpc/contract';
11
- import '@standardserver/core';
11
+ import '@standard-server/core';
12
12
 
13
13
  type CrosswsPeerLike = Pick<Peer, 'send'>;
14
14
  type CrosswsMessageLike = Pick<Message, 'rawData' | 'uint8Array'>;
@@ -29,23 +29,32 @@ declare class experimental_CrosswsHandler<T extends Context> {
29
29
  private readonly decodePeerMessageOptions;
30
30
  constructor(handler: StandardHandler<T>, options?: NoInfer<experimental_CrosswsHandlerOptions<T>>);
31
31
  /**
32
- * Handles a single message received from a crossws Peer.
32
+ * Handles a single WebSocket message.
33
33
  *
34
- * @param ws The crossws Peer instance, require consistent instance across messages for proper peer management
34
+ * Message order matters. Call this immediately after receiving a message,
35
+ * before any other async work, to preserve ordering.
36
+ *
37
+ * @param ws The crossws peer instance. Use the same instance for all messages.
35
38
  */
36
- message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<StandardPeerRequestHandlerOptions<T>>): Promise<{
39
+ message(ws: CrosswsPeerLike, message: CrosswsMessageLike, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<{
37
40
  matched: boolean;
38
41
  }>;
39
42
  /**
40
- * Closes the peer connection and cleans up associated resources.
43
+ * Cleans up peer state for a closed WebSocket.
41
44
  *
42
- * @param ws The crossws Peer instance to close, require consistent instance for proper peer management
45
+ * @param ws The same crossws peer instance passed to `.message()`.
43
46
  */
44
47
  close(ws: CrosswsPeerLike): Promise<void>;
45
48
  }
46
49
 
47
50
  interface experimental_RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, experimental_CrosswsHandlerOptions<T> {
48
51
  }
52
+ /**
53
+ * Serves an oRPC router over the RPC protocol on a WebSocket connection
54
+ * managed by [crossws](https://github.com/h3js/crossws).
55
+ *
56
+ * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
57
+ */
49
58
  declare class experimental_RPCHandler<T extends Context> extends experimental_CrosswsHandler<T> {
50
59
  constructor(router: Router<T>, options?: NoInfer<experimental_RPCHandlerOptions<T>>);
51
60
  }
@@ -1,12 +1,13 @@
1
1
  import { 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';
2
+ import { ServerPeer, encodePeerMessage, decodePeerMessage, isClientPeerSendMessage } from '@standard-server/peer';
3
+ import { createStandardPeerRequestHandler } from '../standard-peer/index.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.C0lFtoHU.mjs';
5
+ import '../../shared/server.W91HSRkE.mjs';
5
6
  import '@orpc/client';
6
- import '@standardserver/core';
7
- import '../../shared/server.CrlKQucM.mjs';
7
+ import '@standard-server/core';
8
+ import '../../shared/server.Djb_ebJT.mjs';
8
9
  import '@orpc/contract';
9
- import '../../shared/server.BwHnWUuN.mjs';
10
+ import '../../shared/server.BynNaBBA.mjs';
10
11
 
11
12
  class experimental_CrosswsHandler {
12
13
  constructor(handler, options = {}) {
@@ -18,9 +19,12 @@ class experimental_CrosswsHandler {
18
19
  encodePeerMessageOptions;
19
20
  decodePeerMessageOptions;
20
21
  /**
21
- * Handles a single message received from a crossws Peer.
22
+ * Handles a single WebSocket message.
22
23
  *
23
- * @param ws The crossws Peer instance, require consistent instance across messages for proper peer management
24
+ * Message order matters. Call this immediately after receiving a message,
25
+ * before any other async work, to preserve ordering.
26
+ *
27
+ * @param ws The crossws peer instance. Use the same instance for all messages.
24
28
  */
25
29
  async message(ws, message, ...rest) {
26
30
  let peer = this.peers.get(ws);
@@ -40,9 +44,9 @@ class experimental_CrosswsHandler {
40
44
  return result;
41
45
  }
42
46
  /**
43
- * Closes the peer connection and cleans up associated resources.
47
+ * Cleans up peer state for a closed WebSocket.
44
48
  *
45
- * @param ws The crossws Peer instance to close, require consistent instance for proper peer management
49
+ * @param ws The same crossws peer instance passed to `.message()`.
46
50
  */
47
51
  async close(ws) {
48
52
  const server = this.peers.get(ws);
@@ -0,0 +1,42 @@
1
+ import { MaybeOptionalOptions } from '@orpc/shared';
2
+ import { SendStandardResponseOptions, AnyFastifyRequest, AnyFastifyReply } from '@standard-server/fastify';
3
+ import { Context } from '../../index.mjs';
4
+ import { StandardHandler, StandardHandlerOptions } from '../standard/index.mjs';
5
+ import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
6
+ import { Router } from '../../index.mjs';
7
+ import { RPCHandlerCodecOptions } from '../standard/index.mjs';
8
+ import '@orpc/client';
9
+ import '@orpc/contract';
10
+ import '@standard-server/core';
11
+
12
+ type FastifyHandlerHandleResult = {
13
+ matched: true;
14
+ } | {
15
+ matched: false;
16
+ };
17
+ interface FastifyHandlerOptions<_T extends Context> {
18
+ /**
19
+ * Custom options for `sendStandardResponse`, used to send a `Standard Response`
20
+ */
21
+ sendStandardResponse?: SendStandardResponseOptions | undefined;
22
+ }
23
+ declare class FastifyHandler<T extends Context> {
24
+ private readonly standardHandler;
25
+ private readonly sendStandardResponseOptions;
26
+ constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
27
+ handle(request: AnyFastifyRequest, reply: AnyFastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FastifyHandlerHandleResult>;
28
+ }
29
+
30
+ interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
31
+ }
32
+ /**
33
+ * Serves an oRPC router over the RPC protocol inside a Fastify server.
34
+ *
35
+ * @see {@link https://orpc.dev/docs/adapters/fastify | Fastify Adapter}
36
+ */
37
+ declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
38
+ constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
39
+ }
40
+
41
+ export { FastifyHandler, RPCHandler };
42
+ export type { FastifyHandlerHandleResult, FastifyHandlerOptions, RPCHandlerOptions };
@@ -0,0 +1,42 @@
1
+ import { MaybeOptionalOptions } from '@orpc/shared';
2
+ import { SendStandardResponseOptions, AnyFastifyRequest, AnyFastifyReply } from '@standard-server/fastify';
3
+ import { Context } from '../../index.js';
4
+ import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
5
+ import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
6
+ import { Router } from '../../index.js';
7
+ import { RPCHandlerCodecOptions } from '../standard/index.js';
8
+ import '@orpc/client';
9
+ import '@orpc/contract';
10
+ import '@standard-server/core';
11
+
12
+ type FastifyHandlerHandleResult = {
13
+ matched: true;
14
+ } | {
15
+ matched: false;
16
+ };
17
+ interface FastifyHandlerOptions<_T extends Context> {
18
+ /**
19
+ * Custom options for `sendStandardResponse`, used to send a `Standard Response`
20
+ */
21
+ sendStandardResponse?: SendStandardResponseOptions | undefined;
22
+ }
23
+ declare class FastifyHandler<T extends Context> {
24
+ private readonly standardHandler;
25
+ private readonly sendStandardResponseOptions;
26
+ constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
27
+ handle(request: AnyFastifyRequest, reply: AnyFastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FastifyHandlerHandleResult>;
28
+ }
29
+
30
+ interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
31
+ }
32
+ /**
33
+ * Serves an oRPC router over the RPC protocol inside a Fastify server.
34
+ *
35
+ * @see {@link https://orpc.dev/docs/adapters/fastify | Fastify Adapter}
36
+ */
37
+ declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
38
+ constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
39
+ }
40
+
41
+ export { FastifyHandler, RPCHandler };
42
+ export type { FastifyHandlerHandleResult, FastifyHandlerOptions, RPCHandlerOptions };
@@ -0,0 +1,39 @@
1
+ import { resolveMaybeOptionalOptions } from '@orpc/shared';
2
+ import { toStandardLazyRequest, sendStandardResponse } from '@standard-server/fastify';
3
+ import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
4
+ import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.C0lFtoHU.mjs';
5
+ import '@orpc/client';
6
+ import '@standard-server/core';
7
+ import '../../shared/server.Djb_ebJT.mjs';
8
+ import '@orpc/contract';
9
+ import '../../shared/server.BynNaBBA.mjs';
10
+
11
+ class FastifyHandler {
12
+ constructor(standardHandler, options = {}) {
13
+ this.standardHandler = standardHandler;
14
+ this.sendStandardResponseOptions = options.sendStandardResponse;
15
+ }
16
+ sendStandardResponseOptions;
17
+ async handle(request, reply, ...rest) {
18
+ const standardRequest = toStandardLazyRequest(request, reply);
19
+ const result = await this.standardHandler.handle(
20
+ standardRequest,
21
+ resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest))
22
+ );
23
+ if (!result.matched) {
24
+ return result;
25
+ }
26
+ await sendStandardResponse(reply, result.response, this.sendStandardResponseOptions);
27
+ return result;
28
+ }
29
+ }
30
+
31
+ class RPCHandler extends FastifyHandler {
32
+ constructor(router, options = {}) {
33
+ const codec = new RPCHandlerCodec(router, options);
34
+ const handler = new StandardHandler(codec, options);
35
+ super(handler, options);
36
+ }
37
+ }
38
+
39
+ export { FastifyHandler, RPCHandler };
@@ -1,43 +1,14 @@
1
- import { C as Context } from '../../shared/server.BL22TloH.mjs';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
- import { ToFetchResponseOptions } from '@standardserver/fetch';
4
- import { e as StandardHandlerPlugin, b as StandardHandlerHandleOptions, S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DJIkub_t.mjs';
1
+ export { R as BodyLimitPlugin } from '../../shared/server.C7xllBNN.mjs';
2
+ import { MaybeOptionalOptions } from '@orpc/shared';
3
+ import { ToFetchResponseOptions } from '@standard-server/fetch';
4
+ import { Context } from '../../index.mjs';
5
+ import { StandardHandler, StandardHandlerOptions } from '../standard/index.mjs';
5
6
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
6
- import { R as Router } from '../../shared/server.BsNNjG5J.mjs';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.Cj5lgPuG.mjs';
7
+ import { Router } from '../../index.mjs';
8
+ import { RPCHandlerCodecOptions } from '../standard/index.mjs';
8
9
  import '@orpc/client';
9
10
  import '@orpc/contract';
10
- import '@standardserver/core';
11
-
12
- interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
13
- /**
14
- * Initializes the plugin and returns new fetch handler options.
15
- * Called once per plugin instance during composition.
16
- *
17
- * This method allows plugins to wrap, extend, or transform fetch handler options
18
- * such as fetch interceptors, or fetch configuration.
19
- *
20
- * @param options - The current handler options from previous plugins or base configuration
21
- * @returns Transformed handler options with plugin's modifications applied
22
- *
23
- * @example
24
- * ```ts
25
- * initFetchHandlerOptions(options) {
26
- * return {
27
- * ...options,
28
- * interceptors: [...(options.interceptors || []), myInterceptor]
29
- * }
30
- * }
31
- * ```
32
- */
33
- initFetchHandlerOptions?(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
34
- }
35
- declare class CompositeFetchHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
36
- readonly name = "~composite/fetch-handler";
37
- protected readonly plugins: FetchHandlerPlugin<T>[];
38
- constructor(plugins?: FetchHandlerPlugin<T>[]);
39
- initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
40
- }
11
+ import '@standard-server/core';
41
12
 
42
13
  type FetchHandlerHandleResult = {
43
14
  matched: true;
@@ -46,95 +17,31 @@ type FetchHandlerHandleResult = {
46
17
  matched: false;
47
18
  response?: undefined;
48
19
  };
49
- interface FetchHandlerFetchInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
50
- request: Request;
51
- toFetchResponseOptions: ToFetchResponseOptions | undefined;
52
- }
53
- type FetchHandlerFetchInterceptor<T extends Context> = Interceptor<FetchHandlerFetchInterceptorOptions<T>, Promise<FetchHandlerHandleResult>>;
54
- interface FetchHandlerOptions<T extends Context> {
20
+ interface FetchHandlerOptions<_T extends Context> {
55
21
  /**
56
- * Options for how to convert the Fetch Response to a Standard Response, like event iterator options, etc.
22
+ * Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
57
23
  */
58
24
  toFetchResponse?: undefined | ToFetchResponseOptions;
59
- /**
60
- * Interceptors that run before the mapping between the Standard API and Fetch API,
61
- * useful for customizing the mapping behavior (e.g. extending the body parser).
62
- */
63
- fetchInterceptors?: FetchHandlerFetchInterceptor<T>[] | undefined;
64
- plugins?: FetchHandlerPlugin<T>[] | undefined;
65
25
  }
66
26
  declare class FetchHandler<T extends Context> {
67
27
  private readonly standardHandler;
68
28
  private readonly toFetchResponseOptions;
69
- private readonly fetchInterceptors;
70
29
  constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
71
30
  handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FetchHandlerHandleResult>;
72
31
  }
73
32
 
74
- declare const ORDERED_SUPPORTED_ENCODINGS: readonly ["gzip", "deflate"];
75
- interface BodyCompressionHandlerPluginOptions {
76
- /**
77
- * The compression schemes to use for response compression.
78
- * Schemes are prioritized by their order in this array and
79
- * only applied if the client supports them.
80
- *
81
- * @default ['gzip', 'deflate']
82
- */
83
- encodings?: readonly (typeof ORDERED_SUPPORTED_ENCODINGS)[number][];
84
- /**
85
- * The minimum response size in bytes required to trigger compression.
86
- * Responses smaller than this threshold will not be compressed to avoid overhead.
87
- * If the response size cannot be determined, compression will still be applied.
88
- *
89
- * @default 1024 (1KB)
90
- */
91
- threshold?: number;
92
- /**
93
- * Override the default content-type filter used to determine which responses should be compressed.
94
- *
95
- * @warning Event stream responses are never compressed, regardless of this filter's return value.
96
- * @default only responses with compressible content types are compressed.
97
- */
98
- filter?: (request: Request, response: Response) => boolean;
99
- }
100
- declare class BodyCompressionHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
101
- name: string;
102
- private readonly encodings;
103
- private readonly threshold;
104
- private readonly filter;
105
- constructor(options?: BodyCompressionHandlerPluginOptions);
106
- initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
107
- }
108
-
109
- interface BodyLimitHandlerPluginOptions {
110
- /**
111
- * The maximum size of the body in bytes.
112
- */
113
- maxBodySize: number;
114
- }
115
- declare class BodyLimitHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
116
- name: string;
117
- private readonly maxBodySize;
118
- constructor(options: BodyLimitHandlerPluginOptions);
119
- initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
120
- }
121
-
122
- interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
123
- /**
124
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
125
- */
126
- csrfGuardHandlerPlugin?: {
127
- /**
128
- * If `false`, this plugin is disabled.
129
- *
130
- * @default true
131
- */
132
- enabled?: boolean;
133
- };
134
- }
33
+ interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
34
+ }
35
+ /**
36
+ * Serves an oRPC router over the RPC protocol using the Fetch API
37
+ * (Request/Response), supported by modern runtimes like Deno, Bun,
38
+ * Cloudflare Workers, and browsers.
39
+ *
40
+ * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
41
+ */
135
42
  declare class RPCHandler<T extends Context> extends FetchHandler<T> {
136
43
  constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
137
44
  }
138
45
 
139
- export { BodyCompressionHandlerPlugin, BodyLimitHandlerPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
140
- export type { BodyCompressionHandlerPluginOptions, BodyLimitHandlerPluginOptions, FetchHandlerFetchInterceptor, FetchHandlerFetchInterceptorOptions, FetchHandlerHandleResult, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
46
+ export { FetchHandler, RPCHandler };
47
+ export type { FetchHandlerHandleResult, FetchHandlerOptions, RPCHandlerOptions };
@@ -1,43 +1,14 @@
1
- import { C as Context } from '../../shared/server.BL22TloH.js';
2
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
- import { ToFetchResponseOptions } from '@standardserver/fetch';
4
- import { e as StandardHandlerPlugin, b as StandardHandlerHandleOptions, S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DBANIheG.js';
1
+ export { R as BodyLimitPlugin } from '../../shared/server.D0dr-F8u.js';
2
+ import { MaybeOptionalOptions } from '@orpc/shared';
3
+ import { ToFetchResponseOptions } from '@standard-server/fetch';
4
+ import { Context } from '../../index.js';
5
+ import { StandardHandler, StandardHandlerOptions } from '../standard/index.js';
5
6
  import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
6
- import { R as Router } from '../../shared/server.Pa0F03f_.js';
7
- import { R as RPCHandlerCodecOptions } from '../../shared/server.d_2NS3g5.js';
7
+ import { Router } from '../../index.js';
8
+ import { RPCHandlerCodecOptions } from '../standard/index.js';
8
9
  import '@orpc/client';
9
10
  import '@orpc/contract';
10
- import '@standardserver/core';
11
-
12
- interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
13
- /**
14
- * Initializes the plugin and returns new fetch handler options.
15
- * Called once per plugin instance during composition.
16
- *
17
- * This method allows plugins to wrap, extend, or transform fetch handler options
18
- * such as fetch interceptors, or fetch configuration.
19
- *
20
- * @param options - The current handler options from previous plugins or base configuration
21
- * @returns Transformed handler options with plugin's modifications applied
22
- *
23
- * @example
24
- * ```ts
25
- * initFetchHandlerOptions(options) {
26
- * return {
27
- * ...options,
28
- * interceptors: [...(options.interceptors || []), myInterceptor]
29
- * }
30
- * }
31
- * ```
32
- */
33
- initFetchHandlerOptions?(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
34
- }
35
- declare class CompositeFetchHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
36
- readonly name = "~composite/fetch-handler";
37
- protected readonly plugins: FetchHandlerPlugin<T>[];
38
- constructor(plugins?: FetchHandlerPlugin<T>[]);
39
- initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
40
- }
11
+ import '@standard-server/core';
41
12
 
42
13
  type FetchHandlerHandleResult = {
43
14
  matched: true;
@@ -46,95 +17,31 @@ type FetchHandlerHandleResult = {
46
17
  matched: false;
47
18
  response?: undefined;
48
19
  };
49
- interface FetchHandlerFetchInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
50
- request: Request;
51
- toFetchResponseOptions: ToFetchResponseOptions | undefined;
52
- }
53
- type FetchHandlerFetchInterceptor<T extends Context> = Interceptor<FetchHandlerFetchInterceptorOptions<T>, Promise<FetchHandlerHandleResult>>;
54
- interface FetchHandlerOptions<T extends Context> {
20
+ interface FetchHandlerOptions<_T extends Context> {
55
21
  /**
56
- * Options for how to convert the Fetch Response to a Standard Response, like event iterator options, etc.
22
+ * Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
57
23
  */
58
24
  toFetchResponse?: undefined | ToFetchResponseOptions;
59
- /**
60
- * Interceptors that run before the mapping between the Standard API and Fetch API,
61
- * useful for customizing the mapping behavior (e.g. extending the body parser).
62
- */
63
- fetchInterceptors?: FetchHandlerFetchInterceptor<T>[] | undefined;
64
- plugins?: FetchHandlerPlugin<T>[] | undefined;
65
25
  }
66
26
  declare class FetchHandler<T extends Context> {
67
27
  private readonly standardHandler;
68
28
  private readonly toFetchResponseOptions;
69
- private readonly fetchInterceptors;
70
29
  constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
71
30
  handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FetchHandlerHandleResult>;
72
31
  }
73
32
 
74
- declare const ORDERED_SUPPORTED_ENCODINGS: readonly ["gzip", "deflate"];
75
- interface BodyCompressionHandlerPluginOptions {
76
- /**
77
- * The compression schemes to use for response compression.
78
- * Schemes are prioritized by their order in this array and
79
- * only applied if the client supports them.
80
- *
81
- * @default ['gzip', 'deflate']
82
- */
83
- encodings?: readonly (typeof ORDERED_SUPPORTED_ENCODINGS)[number][];
84
- /**
85
- * The minimum response size in bytes required to trigger compression.
86
- * Responses smaller than this threshold will not be compressed to avoid overhead.
87
- * If the response size cannot be determined, compression will still be applied.
88
- *
89
- * @default 1024 (1KB)
90
- */
91
- threshold?: number;
92
- /**
93
- * Override the default content-type filter used to determine which responses should be compressed.
94
- *
95
- * @warning Event stream responses are never compressed, regardless of this filter's return value.
96
- * @default only responses with compressible content types are compressed.
97
- */
98
- filter?: (request: Request, response: Response) => boolean;
99
- }
100
- declare class BodyCompressionHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
101
- name: string;
102
- private readonly encodings;
103
- private readonly threshold;
104
- private readonly filter;
105
- constructor(options?: BodyCompressionHandlerPluginOptions);
106
- initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
107
- }
108
-
109
- interface BodyLimitHandlerPluginOptions {
110
- /**
111
- * The maximum size of the body in bytes.
112
- */
113
- maxBodySize: number;
114
- }
115
- declare class BodyLimitHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
116
- name: string;
117
- private readonly maxBodySize;
118
- constructor(options: BodyLimitHandlerPluginOptions);
119
- initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
120
- }
121
-
122
- interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
123
- /**
124
- * Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
125
- */
126
- csrfGuardHandlerPlugin?: {
127
- /**
128
- * If `false`, this plugin is disabled.
129
- *
130
- * @default true
131
- */
132
- enabled?: boolean;
133
- };
134
- }
33
+ interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, StandardHandlerOptions<T>, RPCHandlerCodecOptions<T> {
34
+ }
35
+ /**
36
+ * Serves an oRPC router over the RPC protocol using the Fetch API
37
+ * (Request/Response), supported by modern runtimes like Deno, Bun,
38
+ * Cloudflare Workers, and browsers.
39
+ *
40
+ * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
41
+ */
135
42
  declare class RPCHandler<T extends Context> extends FetchHandler<T> {
136
43
  constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
137
44
  }
138
45
 
139
- export { BodyCompressionHandlerPlugin, BodyLimitHandlerPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
140
- export type { BodyCompressionHandlerPluginOptions, BodyLimitHandlerPluginOptions, FetchHandlerFetchInterceptor, FetchHandlerFetchInterceptorOptions, FetchHandlerHandleResult, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
46
+ export { FetchHandler, RPCHandler };
47
+ export type { FetchHandlerHandleResult, FetchHandlerOptions, RPCHandlerOptions };