@orpc/server 1.14.11 → 1.14.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -52
- package/dist/adapters/aws-lambda/index.d.mts +46 -0
- package/dist/adapters/aws-lambda/index.d.ts +46 -0
- package/dist/adapters/aws-lambda/index.mjs +40 -0
- package/dist/adapters/bun-ws/index.d.mts +36 -0
- package/dist/adapters/bun-ws/index.d.ts +36 -0
- package/dist/adapters/bun-ws/index.mjs +47 -0
- package/dist/adapters/crossws/index.d.mts +21 -45
- package/dist/adapters/crossws/index.d.ts +21 -45
- package/dist/adapters/crossws/index.mjs +18 -40
- package/dist/adapters/fastify/index.d.mts +53 -0
- package/dist/adapters/fastify/index.d.ts +53 -0
- package/dist/adapters/fastify/index.mjs +52 -0
- package/dist/adapters/fetch/index.d.mts +96 -64
- package/dist/adapters/fetch/index.d.ts +96 -64
- package/dist/adapters/fetch/index.mjs +139 -34
- package/dist/adapters/message-port/index.d.mts +34 -49
- package/dist/adapters/message-port/index.d.ts +34 -49
- package/dist/adapters/message-port/index.mjs +37 -68
- package/dist/adapters/node/index.d.mts +71 -63
- package/dist/adapters/node/index.d.ts +71 -63
- package/dist/adapters/node/index.mjs +113 -36
- package/dist/adapters/standard/index.d.mts +18 -16
- package/dist/adapters/standard/index.d.ts +18 -16
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +14 -12
- package/dist/adapters/standard-peer/index.d.ts +14 -12
- package/dist/adapters/standard-peer/index.mjs +21 -2
- package/dist/adapters/websocket/index.d.mts +38 -53
- package/dist/adapters/websocket/index.d.ts +38 -53
- package/dist/adapters/websocket/index.mjs +42 -59
- package/dist/adapters/ws/index.d.mts +31 -0
- package/dist/adapters/ws/index.d.ts +31 -0
- package/dist/adapters/ws/index.mjs +41 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +5 -13
- package/dist/hibernation/index.d.mts +44 -0
- package/dist/hibernation/index.d.ts +44 -0
- package/dist/hibernation/index.mjs +65 -0
- package/dist/index.d.mts +770 -166
- package/dist/index.d.ts +770 -166
- package/dist/index.mjs +399 -306
- package/dist/plugins/index.d.mts +121 -214
- package/dist/plugins/index.d.ts +121 -214
- package/dist/plugins/index.mjs +214 -576
- package/dist/shared/server.7cEtMB30.d.ts +74 -0
- package/dist/shared/server.B8gYOD5g.d.mts +12 -0
- package/dist/shared/server.BqadksTP.d.mts +74 -0
- package/dist/shared/server.C8_sRzQB.d.mts +42 -0
- package/dist/shared/server.CMf4nKky.mjs +230 -0
- package/dist/shared/server.ChyoA9XY.d.ts +42 -0
- package/dist/shared/server.D8IXzfqT.d.ts +32 -0
- package/dist/shared/server.DEBcqOjg.mjs +418 -0
- package/dist/shared/{server.W91HSRkE.mjs → server.DZ5BIITo.mjs} +2 -2
- package/dist/shared/server.DzE6WeuY.d.mts +32 -0
- package/dist/shared/server.EfTOZ2Q7.d.ts +12 -0
- package/dist/shared/server.TEVCLCFC.mjs +39 -0
- package/dist/shared/server.qKsRrdxW.d.mts +193 -0
- package/dist/shared/server.qKsRrdxW.d.ts +193 -0
- package/package.json +56 -26
- package/dist/extensions/callable.d.mts +0 -10
- package/dist/extensions/callable.d.ts +0 -10
- package/dist/extensions/callable.mjs +0 -11
- package/dist/shared/server.15O7oC1p.d.mts +0 -61
- package/dist/shared/server.B4BnEWWm.d.mts +0 -67
- package/dist/shared/server.BhsVw7m7.d.ts +0 -104
- package/dist/shared/server.BoiFpNT7.mjs +0 -224
- package/dist/shared/server.COPVXhDG.mjs +0 -271
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.CcR4kgje.d.mts +0 -206
- package/dist/shared/server.CcR4kgje.d.ts +0 -206
- package/dist/shared/server.CnN50DHH.d.ts +0 -67
- package/dist/shared/server.DBs0rrf9.mjs +0 -41
- package/dist/shared/server.DDFizwfU.d.mts +0 -104
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.DofEOwf-.mjs +0 -237
- package/dist/shared/server.m3szVJGU.d.ts +0 -61
|
@@ -1,56 +1,36 @@
|
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { ServerPeer
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ServerPeer } from '@orpc/standard-server-peer';
|
|
3
|
+
import { createServerPeerHandleRequestFn } from '../standard-peer/index.mjs';
|
|
4
|
+
import { b as StandardRPCHandler } from '../../shared/server.CMf4nKky.mjs';
|
|
5
|
+
import '../../shared/server.DZ5BIITo.mjs';
|
|
6
|
+
import '@orpc/client/standard';
|
|
5
7
|
import '@orpc/client';
|
|
6
|
-
import '@
|
|
7
|
-
import '../../shared/server.
|
|
8
|
+
import '@orpc/standard-server';
|
|
9
|
+
import '../../shared/server.DEBcqOjg.mjs';
|
|
8
10
|
import '@orpc/contract';
|
|
9
|
-
import '../../shared/server.BoiFpNT7.mjs';
|
|
10
11
|
|
|
11
12
|
class experimental_CrosswsHandler {
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
14
|
-
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
15
|
-
this.decodePeerMessageOptions = options.decodePeerMessage;
|
|
13
|
+
constructor(standardHandler) {
|
|
14
|
+
this.standardHandler = standardHandler;
|
|
16
15
|
}
|
|
17
16
|
peers = /* @__PURE__ */ new WeakMap();
|
|
18
|
-
encodePeerMessageOptions;
|
|
19
|
-
decodePeerMessageOptions;
|
|
20
|
-
/**
|
|
21
|
-
* Handles a single WebSocket message.
|
|
22
|
-
*
|
|
23
|
-
* Message order matters. Call this immediately after receiving a message,
|
|
24
|
-
* before any other async work, to preserve ordering.
|
|
25
|
-
*
|
|
26
|
-
* @param ws The crossws peer instance. Use the same instance for all messages.
|
|
27
|
-
*/
|
|
28
17
|
async message(ws, message, ...rest) {
|
|
29
18
|
let peer = this.peers.get(ws);
|
|
30
19
|
if (!peer) {
|
|
31
|
-
this.peers.set(ws, peer = new ServerPeer(
|
|
32
|
-
ws.send(
|
|
20
|
+
this.peers.set(ws, peer = new ServerPeer((message2) => {
|
|
21
|
+
ws.send(message2);
|
|
33
22
|
}));
|
|
34
23
|
}
|
|
35
24
|
const encodedMessage = typeof message.rawData === "string" ? message.rawData : message.uint8Array();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest))
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
25
|
+
await peer.message(
|
|
26
|
+
encodedMessage,
|
|
27
|
+
createServerPeerHandleRequestFn(this.standardHandler, resolveMaybeOptionalOptions(rest))
|
|
28
|
+
);
|
|
44
29
|
}
|
|
45
|
-
|
|
46
|
-
* Cleans up peer state for a closed WebSocket.
|
|
47
|
-
*
|
|
48
|
-
* @param ws The same crossws peer instance passed to `.message()`.
|
|
49
|
-
*/
|
|
50
|
-
async close(ws) {
|
|
30
|
+
close(ws) {
|
|
51
31
|
const server = this.peers.get(ws);
|
|
52
32
|
if (server) {
|
|
53
|
-
|
|
33
|
+
server.close();
|
|
54
34
|
this.peers.delete(ws);
|
|
55
35
|
}
|
|
56
36
|
}
|
|
@@ -58,9 +38,7 @@ class experimental_CrosswsHandler {
|
|
|
58
38
|
|
|
59
39
|
class experimental_RPCHandler extends experimental_CrosswsHandler {
|
|
60
40
|
constructor(router, options = {}) {
|
|
61
|
-
|
|
62
|
-
const handler = new StandardHandler(codec, options);
|
|
63
|
-
super(handler, options);
|
|
41
|
+
super(new StandardRPCHandler(router, options));
|
|
64
42
|
}
|
|
65
43
|
}
|
|
66
44
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { FastifyRequest, FastifyReply, SendStandardResponseOptions } from '@orpc/standard-server-fastify';
|
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.mjs';
|
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.B8gYOD5g.mjs';
|
|
5
|
+
import { b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.BqadksTP.mjs';
|
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DzE6WeuY.mjs';
|
|
7
|
+
import '@orpc/client';
|
|
8
|
+
import '@orpc/contract';
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '@orpc/client/standard';
|
|
11
|
+
import '../../shared/server.C8_sRzQB.mjs';
|
|
12
|
+
|
|
13
|
+
type FastifyHandleResult = {
|
|
14
|
+
matched: true;
|
|
15
|
+
} | {
|
|
16
|
+
matched: false;
|
|
17
|
+
};
|
|
18
|
+
interface FastifyInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
|
19
|
+
request: FastifyRequest;
|
|
20
|
+
reply: FastifyReply;
|
|
21
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
|
22
|
+
}
|
|
23
|
+
interface FastifyHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
|
24
|
+
adapterInterceptors?: Interceptor<FastifyInterceptorOptions<T>, Promise<FastifyHandleResult>>[];
|
|
25
|
+
}
|
|
26
|
+
declare class FastifyHandler<T extends Context> {
|
|
27
|
+
private readonly standardHandler;
|
|
28
|
+
private readonly sendStandardResponseOptions;
|
|
29
|
+
private readonly adapterInterceptors;
|
|
30
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
|
|
31
|
+
handle(request: FastifyRequest, reply: FastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FastifyHandleResult>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, StandardRPCHandlerOptions<T> {
|
|
35
|
+
/**
|
|
36
|
+
* Enables or disables the StrictGetMethodPlugin.
|
|
37
|
+
*
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
strictGetMethodPluginEnabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* RPC Handler for Fastify Server
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
46
|
+
* @see {@link https://orpc.dev/docs/adapters/http HTTP Adapter Docs}
|
|
47
|
+
*/
|
|
48
|
+
declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
|
|
49
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { FastifyHandler, RPCHandler };
|
|
53
|
+
export type { FastifyHandleResult, FastifyHandlerOptions, FastifyInterceptorOptions, RPCHandlerOptions };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { FastifyRequest, FastifyReply, SendStandardResponseOptions } from '@orpc/standard-server-fastify';
|
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.js';
|
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.EfTOZ2Q7.js';
|
|
5
|
+
import { b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.7cEtMB30.js';
|
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D8IXzfqT.js';
|
|
7
|
+
import '@orpc/client';
|
|
8
|
+
import '@orpc/contract';
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '@orpc/client/standard';
|
|
11
|
+
import '../../shared/server.ChyoA9XY.js';
|
|
12
|
+
|
|
13
|
+
type FastifyHandleResult = {
|
|
14
|
+
matched: true;
|
|
15
|
+
} | {
|
|
16
|
+
matched: false;
|
|
17
|
+
};
|
|
18
|
+
interface FastifyInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
|
19
|
+
request: FastifyRequest;
|
|
20
|
+
reply: FastifyReply;
|
|
21
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
|
22
|
+
}
|
|
23
|
+
interface FastifyHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
|
24
|
+
adapterInterceptors?: Interceptor<FastifyInterceptorOptions<T>, Promise<FastifyHandleResult>>[];
|
|
25
|
+
}
|
|
26
|
+
declare class FastifyHandler<T extends Context> {
|
|
27
|
+
private readonly standardHandler;
|
|
28
|
+
private readonly sendStandardResponseOptions;
|
|
29
|
+
private readonly adapterInterceptors;
|
|
30
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FastifyHandlerOptions<T>>);
|
|
31
|
+
handle(request: FastifyRequest, reply: FastifyReply, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FastifyHandleResult>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface RPCHandlerOptions<T extends Context> extends FastifyHandlerOptions<T>, StandardRPCHandlerOptions<T> {
|
|
35
|
+
/**
|
|
36
|
+
* Enables or disables the StrictGetMethodPlugin.
|
|
37
|
+
*
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
strictGetMethodPluginEnabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* RPC Handler for Fastify Server
|
|
44
|
+
*
|
|
45
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
46
|
+
* @see {@link https://orpc.dev/docs/adapters/http HTTP Adapter Docs}
|
|
47
|
+
*/
|
|
48
|
+
declare class RPCHandler<T extends Context> extends FastifyHandler<T> {
|
|
49
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { FastifyHandler, RPCHandler };
|
|
53
|
+
export type { FastifyHandleResult, FastifyHandlerOptions, FastifyInterceptorOptions, RPCHandlerOptions };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
+
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-fastify';
|
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
|
4
|
+
import { S as StrictGetMethodPlugin } from '../../shared/server.TEVCLCFC.mjs';
|
|
5
|
+
import { b as StandardRPCHandler } from '../../shared/server.CMf4nKky.mjs';
|
|
6
|
+
import '@orpc/contract';
|
|
7
|
+
import '@orpc/client/standard';
|
|
8
|
+
import '@orpc/client';
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '../../shared/server.DEBcqOjg.mjs';
|
|
11
|
+
|
|
12
|
+
class FastifyHandler {
|
|
13
|
+
constructor(standardHandler, options = {}) {
|
|
14
|
+
this.standardHandler = standardHandler;
|
|
15
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
|
16
|
+
this.sendStandardResponseOptions = options;
|
|
17
|
+
}
|
|
18
|
+
sendStandardResponseOptions;
|
|
19
|
+
adapterInterceptors;
|
|
20
|
+
async handle(request, reply, ...rest) {
|
|
21
|
+
return intercept(
|
|
22
|
+
this.adapterInterceptors,
|
|
23
|
+
{
|
|
24
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
|
25
|
+
request,
|
|
26
|
+
reply,
|
|
27
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
|
28
|
+
},
|
|
29
|
+
async ({ request: request2, reply: reply2, sendStandardResponseOptions, ...options }) => {
|
|
30
|
+
const standardRequest = toStandardLazyRequest(request2, reply2);
|
|
31
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
|
32
|
+
if (!result.matched) {
|
|
33
|
+
return { matched: false };
|
|
34
|
+
}
|
|
35
|
+
await sendStandardResponse(reply2, result.response, sendStandardResponseOptions);
|
|
36
|
+
return { matched: true };
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class RPCHandler extends FastifyHandler {
|
|
43
|
+
constructor(router, options = {}) {
|
|
44
|
+
if (options.strictGetMethodPluginEnabled ?? true) {
|
|
45
|
+
options.plugins ??= [];
|
|
46
|
+
options.plugins.push(new StrictGetMethodPlugin());
|
|
47
|
+
}
|
|
48
|
+
super(new StandardRPCHandler(router, options), options);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { FastifyHandler, RPCHandler };
|
|
@@ -1,92 +1,124 @@
|
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.mjs';
|
|
1
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { ToFetchResponseOptions } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { R as Router } from '../../shared/server.15O7oC1p.mjs';
|
|
7
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.B4BnEWWm.mjs';
|
|
3
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.B8gYOD5g.mjs';
|
|
5
|
+
import { g as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.BqadksTP.mjs';
|
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DzE6WeuY.mjs';
|
|
8
7
|
import '@orpc/client';
|
|
9
8
|
import '@orpc/contract';
|
|
10
|
-
import '@
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '@orpc/client/standard';
|
|
11
|
+
import '../../shared/server.C8_sRzQB.mjs';
|
|
11
12
|
|
|
12
13
|
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>;
|
|
14
|
+
initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
|
|
34
15
|
}
|
|
35
|
-
declare class CompositeFetchHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
|
36
|
-
|
|
37
|
-
protected readonly plugins: FetchHandlerPlugin<T>[];
|
|
38
|
-
constructor(plugins?: FetchHandlerPlugin<T>[]);
|
|
39
|
-
initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
|
|
16
|
+
declare class CompositeFetchHandlerPlugin<T extends Context, TPlugin extends FetchHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements FetchHandlerPlugin<T> {
|
|
17
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
|
40
18
|
}
|
|
41
19
|
|
|
42
|
-
type
|
|
20
|
+
type FetchHandleResult = {
|
|
43
21
|
matched: true;
|
|
44
22
|
response: Response;
|
|
45
23
|
} | {
|
|
46
24
|
matched: false;
|
|
47
|
-
response
|
|
25
|
+
response: undefined;
|
|
48
26
|
};
|
|
49
|
-
interface
|
|
27
|
+
interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
|
50
28
|
request: Request;
|
|
51
|
-
toFetchResponseOptions: ToFetchResponseOptions
|
|
29
|
+
toFetchResponseOptions: ToFetchResponseOptions;
|
|
52
30
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
|
|
57
|
-
*/
|
|
58
|
-
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;
|
|
31
|
+
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
|
32
|
+
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, Promise<FetchHandleResult>>[];
|
|
33
|
+
plugins?: FetchHandlerPlugin<T>[];
|
|
65
34
|
}
|
|
66
35
|
declare class FetchHandler<T extends Context> {
|
|
67
36
|
private readonly standardHandler;
|
|
68
37
|
private readonly toFetchResponseOptions;
|
|
69
|
-
private readonly
|
|
38
|
+
private readonly adapterInterceptors;
|
|
70
39
|
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
71
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<
|
|
40
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface BodyLimitPluginOptions {
|
|
44
|
+
/**
|
|
45
|
+
* The maximum size of the body in bytes.
|
|
46
|
+
*/
|
|
47
|
+
maxBodySize: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The Body Limit Plugin restricts the size of the request body for the Fetch Server.
|
|
51
|
+
*
|
|
52
|
+
* @see {@link https://orpc.dev/docs/plugins/body-limit Body Limit Plugin Docs}
|
|
53
|
+
*/
|
|
54
|
+
declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
|
55
|
+
private readonly maxBodySize;
|
|
56
|
+
constructor(options: BodyLimitPluginOptions);
|
|
57
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
|
72
58
|
}
|
|
73
59
|
|
|
74
|
-
|
|
60
|
+
/**
|
|
61
|
+
* This plugin is heavily inspired by the [Hono Compression Plugin](https://github.com/honojs/hono/blob/1.x/src/middleware/compress/index.ts)
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
declare const ORDERED_SUPPORTED_ENCODINGS: readonly ["gzip", "deflate"];
|
|
65
|
+
interface CompressionPluginOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The compression schemes to use for response compression.
|
|
68
|
+
* Schemes are prioritized by their order in this array and
|
|
69
|
+
* only applied if the client supports them.
|
|
70
|
+
*
|
|
71
|
+
* @default ['gzip', 'deflate']
|
|
72
|
+
*/
|
|
73
|
+
encodings?: readonly (typeof ORDERED_SUPPORTED_ENCODINGS)[number][];
|
|
74
|
+
/**
|
|
75
|
+
* The minimum response size in bytes required to trigger compression.
|
|
76
|
+
* Responses smaller than this threshold will not be compressed to avoid overhead.
|
|
77
|
+
* If the response size cannot be determined, compression will still be applied.
|
|
78
|
+
*
|
|
79
|
+
* @default 1024 (1KB)
|
|
80
|
+
*/
|
|
81
|
+
threshold?: number;
|
|
75
82
|
/**
|
|
76
|
-
*
|
|
83
|
+
* Override the default content-type filter used to determine which responses should be compressed.
|
|
84
|
+
*
|
|
85
|
+
* @warning [Event Iterator](https://orpc.dev/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
|
|
86
|
+
* @default only responses with compressible content types are compressed.
|
|
87
|
+
*/
|
|
88
|
+
filter?: (request: Request, response: Response) => boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The Compression Plugin adds response compression to the Fetch Server.
|
|
92
|
+
* Build on top of [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
|
|
93
|
+
* You might need to polyfill it if your environment does not support it.
|
|
94
|
+
*
|
|
95
|
+
* @see {@link https://orpc.dev/docs/plugins/compression Compression Plugin Docs}
|
|
96
|
+
*/
|
|
97
|
+
declare class CompressionPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
|
98
|
+
private readonly encodings;
|
|
99
|
+
private readonly threshold;
|
|
100
|
+
private readonly filter;
|
|
101
|
+
constructor(options?: CompressionPluginOptions);
|
|
102
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardRPCHandlerOptions<T>, 'plugins'> {
|
|
106
|
+
/**
|
|
107
|
+
* Enables or disables the StrictGetMethodPlugin.
|
|
108
|
+
*
|
|
109
|
+
* @default true
|
|
77
110
|
*/
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* If `false`, this plugin is disabled.
|
|
81
|
-
*
|
|
82
|
-
* @default true
|
|
83
|
-
*/
|
|
84
|
-
enabled?: boolean;
|
|
85
|
-
};
|
|
111
|
+
strictGetMethodPluginEnabled?: boolean;
|
|
86
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* RPC Handler for Fetch Server
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
117
|
+
* @see {@link https://orpc.dev/docs/adapters/http HTTP Adapter Docs}
|
|
118
|
+
*/
|
|
87
119
|
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
88
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
120
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
89
121
|
}
|
|
90
122
|
|
|
91
|
-
export { CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
|
92
|
-
export type {
|
|
123
|
+
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler, RPCHandler };
|
|
124
|
+
export type { BodyLimitPluginOptions, CompressionPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
|
@@ -1,92 +1,124 @@
|
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.js';
|
|
1
2
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import { ToFetchResponseOptions } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { R as Router } from '../../shared/server.m3szVJGU.js';
|
|
7
|
-
import { R as RPCHandlerCodecOptions } from '../../shared/server.CnN50DHH.js';
|
|
3
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.EfTOZ2Q7.js';
|
|
5
|
+
import { g as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.7cEtMB30.js';
|
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.D8IXzfqT.js';
|
|
8
7
|
import '@orpc/client';
|
|
9
8
|
import '@orpc/contract';
|
|
10
|
-
import '@
|
|
9
|
+
import '@orpc/standard-server';
|
|
10
|
+
import '@orpc/client/standard';
|
|
11
|
+
import '../../shared/server.ChyoA9XY.js';
|
|
11
12
|
|
|
12
13
|
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>;
|
|
14
|
+
initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
|
|
34
15
|
}
|
|
35
|
-
declare class CompositeFetchHandlerPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
|
36
|
-
|
|
37
|
-
protected readonly plugins: FetchHandlerPlugin<T>[];
|
|
38
|
-
constructor(plugins?: FetchHandlerPlugin<T>[]);
|
|
39
|
-
initFetchHandlerOptions(options: FetchHandlerOptions<T>): FetchHandlerOptions<T>;
|
|
16
|
+
declare class CompositeFetchHandlerPlugin<T extends Context, TPlugin extends FetchHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements FetchHandlerPlugin<T> {
|
|
17
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
|
40
18
|
}
|
|
41
19
|
|
|
42
|
-
type
|
|
20
|
+
type FetchHandleResult = {
|
|
43
21
|
matched: true;
|
|
44
22
|
response: Response;
|
|
45
23
|
} | {
|
|
46
24
|
matched: false;
|
|
47
|
-
response
|
|
25
|
+
response: undefined;
|
|
48
26
|
};
|
|
49
|
-
interface
|
|
27
|
+
interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
|
50
28
|
request: Request;
|
|
51
|
-
toFetchResponseOptions: ToFetchResponseOptions
|
|
29
|
+
toFetchResponseOptions: ToFetchResponseOptions;
|
|
52
30
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
|
|
57
|
-
*/
|
|
58
|
-
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;
|
|
31
|
+
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
|
32
|
+
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, Promise<FetchHandleResult>>[];
|
|
33
|
+
plugins?: FetchHandlerPlugin<T>[];
|
|
65
34
|
}
|
|
66
35
|
declare class FetchHandler<T extends Context> {
|
|
67
36
|
private readonly standardHandler;
|
|
68
37
|
private readonly toFetchResponseOptions;
|
|
69
|
-
private readonly
|
|
38
|
+
private readonly adapterInterceptors;
|
|
70
39
|
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
71
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<
|
|
40
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface BodyLimitPluginOptions {
|
|
44
|
+
/**
|
|
45
|
+
* The maximum size of the body in bytes.
|
|
46
|
+
*/
|
|
47
|
+
maxBodySize: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The Body Limit Plugin restricts the size of the request body for the Fetch Server.
|
|
51
|
+
*
|
|
52
|
+
* @see {@link https://orpc.dev/docs/plugins/body-limit Body Limit Plugin Docs}
|
|
53
|
+
*/
|
|
54
|
+
declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
|
55
|
+
private readonly maxBodySize;
|
|
56
|
+
constructor(options: BodyLimitPluginOptions);
|
|
57
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
|
72
58
|
}
|
|
73
59
|
|
|
74
|
-
|
|
60
|
+
/**
|
|
61
|
+
* This plugin is heavily inspired by the [Hono Compression Plugin](https://github.com/honojs/hono/blob/1.x/src/middleware/compress/index.ts)
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
declare const ORDERED_SUPPORTED_ENCODINGS: readonly ["gzip", "deflate"];
|
|
65
|
+
interface CompressionPluginOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The compression schemes to use for response compression.
|
|
68
|
+
* Schemes are prioritized by their order in this array and
|
|
69
|
+
* only applied if the client supports them.
|
|
70
|
+
*
|
|
71
|
+
* @default ['gzip', 'deflate']
|
|
72
|
+
*/
|
|
73
|
+
encodings?: readonly (typeof ORDERED_SUPPORTED_ENCODINGS)[number][];
|
|
74
|
+
/**
|
|
75
|
+
* The minimum response size in bytes required to trigger compression.
|
|
76
|
+
* Responses smaller than this threshold will not be compressed to avoid overhead.
|
|
77
|
+
* If the response size cannot be determined, compression will still be applied.
|
|
78
|
+
*
|
|
79
|
+
* @default 1024 (1KB)
|
|
80
|
+
*/
|
|
81
|
+
threshold?: number;
|
|
75
82
|
/**
|
|
76
|
-
*
|
|
83
|
+
* Override the default content-type filter used to determine which responses should be compressed.
|
|
84
|
+
*
|
|
85
|
+
* @warning [Event Iterator](https://orpc.dev/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
|
|
86
|
+
* @default only responses with compressible content types are compressed.
|
|
87
|
+
*/
|
|
88
|
+
filter?: (request: Request, response: Response) => boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The Compression Plugin adds response compression to the Fetch Server.
|
|
92
|
+
* Build on top of [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
|
|
93
|
+
* You might need to polyfill it if your environment does not support it.
|
|
94
|
+
*
|
|
95
|
+
* @see {@link https://orpc.dev/docs/plugins/compression Compression Plugin Docs}
|
|
96
|
+
*/
|
|
97
|
+
declare class CompressionPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
|
98
|
+
private readonly encodings;
|
|
99
|
+
private readonly threshold;
|
|
100
|
+
private readonly filter;
|
|
101
|
+
constructor(options?: CompressionPluginOptions);
|
|
102
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardRPCHandlerOptions<T>, 'plugins'> {
|
|
106
|
+
/**
|
|
107
|
+
* Enables or disables the StrictGetMethodPlugin.
|
|
108
|
+
*
|
|
109
|
+
* @default true
|
|
77
110
|
*/
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* If `false`, this plugin is disabled.
|
|
81
|
-
*
|
|
82
|
-
* @default true
|
|
83
|
-
*/
|
|
84
|
-
enabled?: boolean;
|
|
85
|
-
};
|
|
111
|
+
strictGetMethodPluginEnabled?: boolean;
|
|
86
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* RPC Handler for Fetch Server
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.dev/docs/rpc-handler RPC Handler Docs}
|
|
117
|
+
* @see {@link https://orpc.dev/docs/adapters/http HTTP Adapter Docs}
|
|
118
|
+
*/
|
|
87
119
|
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
88
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
120
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
89
121
|
}
|
|
90
122
|
|
|
91
|
-
export { CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
|
92
|
-
export type {
|
|
123
|
+
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler, RPCHandler };
|
|
124
|
+
export type { BodyLimitPluginOptions, CompressionPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|