@orpc/server 1.14.10 → 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.
- package/README.md +52 -98
- package/dist/adapters/crossws/index.d.mts +45 -21
- package/dist/adapters/crossws/index.d.ts +45 -21
- package/dist/adapters/crossws/index.mjs +40 -18
- package/dist/adapters/fetch/index.d.mts +64 -96
- package/dist/adapters/fetch/index.d.ts +64 -96
- package/dist/adapters/fetch/index.mjs +34 -139
- package/dist/adapters/message-port/index.d.mts +49 -34
- package/dist/adapters/message-port/index.d.ts +49 -34
- package/dist/adapters/message-port/index.mjs +68 -37
- package/dist/adapters/node/index.d.mts +63 -71
- package/dist/adapters/node/index.d.ts +63 -71
- package/dist/adapters/node/index.mjs +36 -113
- package/dist/adapters/standard/index.d.mts +16 -18
- package/dist/adapters/standard/index.d.ts +16 -18
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/standard-peer/index.d.mts +12 -14
- package/dist/adapters/standard-peer/index.d.ts +12 -14
- package/dist/adapters/standard-peer/index.mjs +2 -21
- package/dist/adapters/websocket/index.d.mts +53 -38
- package/dist/adapters/websocket/index.d.ts +53 -38
- package/dist/adapters/websocket/index.mjs +59 -42
- package/dist/extensions/callable.d.mts +10 -0
- package/dist/extensions/callable.d.ts +10 -0
- package/dist/extensions/callable.mjs +11 -0
- package/dist/helpers/index.d.mts +4 -4
- package/dist/helpers/index.d.ts +4 -4
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +166 -770
- package/dist/index.d.ts +166 -770
- package/dist/index.mjs +306 -399
- package/dist/plugins/index.d.mts +214 -121
- package/dist/plugins/index.d.ts +214 -121
- package/dist/plugins/index.mjs +576 -214
- package/dist/shared/server.15O7oC1p.d.mts +61 -0
- package/dist/shared/server.B4BnEWWm.d.mts +67 -0
- package/dist/shared/server.BhsVw7m7.d.ts +104 -0
- package/dist/shared/server.BoiFpNT7.mjs +224 -0
- package/dist/shared/server.COPVXhDG.mjs +271 -0
- package/dist/shared/server.CX4vUnDk.mjs +11 -0
- package/dist/shared/server.CcR4kgje.d.mts +206 -0
- package/dist/shared/server.CcR4kgje.d.ts +206 -0
- package/dist/shared/server.CnN50DHH.d.ts +67 -0
- package/dist/shared/server.DBs0rrf9.mjs +41 -0
- package/dist/shared/server.DDFizwfU.d.mts +104 -0
- package/dist/shared/server.D_QauotT.mjs +30 -0
- package/dist/shared/server.DofEOwf-.mjs +237 -0
- package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
- package/dist/shared/server.m3szVJGU.d.ts +61 -0
- package/package.json +26 -56
- package/dist/adapters/aws-lambda/index.d.mts +0 -46
- package/dist/adapters/aws-lambda/index.d.ts +0 -46
- package/dist/adapters/aws-lambda/index.mjs +0 -40
- package/dist/adapters/bun-ws/index.d.mts +0 -36
- package/dist/adapters/bun-ws/index.d.ts +0 -36
- package/dist/adapters/bun-ws/index.mjs +0 -47
- package/dist/adapters/fastify/index.d.mts +0 -53
- package/dist/adapters/fastify/index.d.ts +0 -53
- package/dist/adapters/fastify/index.mjs +0 -52
- package/dist/adapters/ws/index.d.mts +0 -31
- package/dist/adapters/ws/index.d.ts +0 -31
- package/dist/adapters/ws/index.mjs +0 -41
- package/dist/hibernation/index.d.mts +0 -44
- package/dist/hibernation/index.d.ts +0 -44
- package/dist/hibernation/index.mjs +0 -65
- package/dist/shared/server.7cEtMB30.d.ts +0 -74
- package/dist/shared/server.B8gYOD5g.d.mts +0 -12
- package/dist/shared/server.BqadksTP.d.mts +0 -74
- package/dist/shared/server.C8_sRzQB.d.mts +0 -42
- package/dist/shared/server.ChUyt5-i.d.mts +0 -32
- package/dist/shared/server.ChyoA9XY.d.ts +0 -42
- package/dist/shared/server.DEBcqOjg.mjs +0 -418
- package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
- package/dist/shared/server.TEVCLCFC.mjs +0 -39
- package/dist/shared/server.ZxHCEN1h.mjs +0 -226
- package/dist/shared/server.qKsRrdxW.d.mts +0 -193
- package/dist/shared/server.qKsRrdxW.d.ts +0 -193
- package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
|
@@ -1,124 +1,92 @@
|
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.mjs';
|
|
2
1
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { ToFetchResponseOptions } from '@
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { ToFetchResponseOptions } from '@standardserver/fetch';
|
|
3
|
+
import { C as Context } from '../../shared/server.CcR4kgje.mjs';
|
|
4
|
+
import { e as StandardHandlerPlugin, b as StandardHandlerHandleOptions, S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.DDFizwfU.mjs';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.mjs';
|
|
6
|
+
import { R as Router } from '../../shared/server.15O7oC1p.mjs';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.B4BnEWWm.mjs';
|
|
7
8
|
import '@orpc/client';
|
|
8
9
|
import '@orpc/contract';
|
|
9
|
-
import '@
|
|
10
|
-
import '@orpc/client/standard';
|
|
11
|
-
import '../../shared/server.C8_sRzQB.mjs';
|
|
10
|
+
import '@standardserver/core';
|
|
12
11
|
|
|
13
12
|
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
14
|
-
|
|
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>;
|
|
15
34
|
}
|
|
16
|
-
declare class CompositeFetchHandlerPlugin<T extends Context
|
|
17
|
-
|
|
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>;
|
|
18
40
|
}
|
|
19
41
|
|
|
20
|
-
type
|
|
42
|
+
type FetchHandlerHandleResult = {
|
|
21
43
|
matched: true;
|
|
22
44
|
response: Response;
|
|
23
45
|
} | {
|
|
24
46
|
matched: false;
|
|
25
|
-
response
|
|
47
|
+
response?: undefined;
|
|
26
48
|
};
|
|
27
|
-
interface
|
|
49
|
+
interface FetchHandlerFetchInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
28
50
|
request: Request;
|
|
29
|
-
toFetchResponseOptions: ToFetchResponseOptions;
|
|
30
|
-
}
|
|
31
|
-
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
|
32
|
-
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, Promise<FetchHandleResult>>[];
|
|
33
|
-
plugins?: FetchHandlerPlugin<T>[];
|
|
34
|
-
}
|
|
35
|
-
declare class FetchHandler<T extends Context> {
|
|
36
|
-
private readonly standardHandler;
|
|
37
|
-
private readonly toFetchResponseOptions;
|
|
38
|
-
private readonly adapterInterceptors;
|
|
39
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
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;
|
|
51
|
+
toFetchResponseOptions: ToFetchResponseOptions | undefined;
|
|
58
52
|
}
|
|
59
|
-
|
|
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][];
|
|
53
|
+
type FetchHandlerFetchInterceptor<T extends Context> = Interceptor<FetchHandlerFetchInterceptorOptions<T>, Promise<FetchHandlerHandleResult>>;
|
|
54
|
+
interface FetchHandlerOptions<T extends Context> {
|
|
74
55
|
/**
|
|
75
|
-
*
|
|
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)
|
|
56
|
+
* Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
|
|
80
57
|
*/
|
|
81
|
-
|
|
58
|
+
toFetchResponse?: undefined | ToFetchResponseOptions;
|
|
82
59
|
/**
|
|
83
|
-
*
|
|
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.
|
|
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).
|
|
87
62
|
*/
|
|
88
|
-
|
|
63
|
+
fetchInterceptors?: FetchHandlerFetchInterceptor<T>[] | undefined;
|
|
64
|
+
plugins?: FetchHandlerPlugin<T>[] | undefined;
|
|
89
65
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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;
|
|
66
|
+
declare class FetchHandler<T extends Context> {
|
|
67
|
+
private readonly standardHandler;
|
|
68
|
+
private readonly toFetchResponseOptions;
|
|
69
|
+
private readonly fetchInterceptors;
|
|
70
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
71
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FetchHandlerHandleResult>;
|
|
103
72
|
}
|
|
104
73
|
|
|
105
|
-
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<
|
|
74
|
+
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
106
75
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* @default true
|
|
76
|
+
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
110
77
|
*/
|
|
111
|
-
|
|
78
|
+
csrfGuardHandlerPlugin?: {
|
|
79
|
+
/**
|
|
80
|
+
* If `false`, this plugin is disabled.
|
|
81
|
+
*
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
enabled?: boolean;
|
|
85
|
+
};
|
|
112
86
|
}
|
|
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
|
-
*/
|
|
119
87
|
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
120
|
-
constructor(router: Router<
|
|
88
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
121
89
|
}
|
|
122
90
|
|
|
123
|
-
export {
|
|
124
|
-
export type {
|
|
91
|
+
export { CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
|
92
|
+
export type { FetchHandlerFetchInterceptor, FetchHandlerFetchInterceptorOptions, FetchHandlerHandleResult, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
|
@@ -1,124 +1,92 @@
|
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.qKsRrdxW.js';
|
|
2
1
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { ToFetchResponseOptions } from '@
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { ToFetchResponseOptions } from '@standardserver/fetch';
|
|
3
|
+
import { C as Context } from '../../shared/server.CcR4kgje.js';
|
|
4
|
+
import { e as StandardHandlerPlugin, b as StandardHandlerHandleOptions, S as StandardHandler, a as StandardHandlerOptions } from '../../shared/server.BhsVw7m7.js';
|
|
5
|
+
import { FriendlyStandardHandlerHandleOptions } from '../standard/index.js';
|
|
6
|
+
import { R as Router } from '../../shared/server.m3szVJGU.js';
|
|
7
|
+
import { R as RPCHandlerCodecOptions } from '../../shared/server.CnN50DHH.js';
|
|
7
8
|
import '@orpc/client';
|
|
8
9
|
import '@orpc/contract';
|
|
9
|
-
import '@
|
|
10
|
-
import '@orpc/client/standard';
|
|
11
|
-
import '../../shared/server.ChyoA9XY.js';
|
|
10
|
+
import '@standardserver/core';
|
|
12
11
|
|
|
13
12
|
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
14
|
-
|
|
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>;
|
|
15
34
|
}
|
|
16
|
-
declare class CompositeFetchHandlerPlugin<T extends Context
|
|
17
|
-
|
|
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>;
|
|
18
40
|
}
|
|
19
41
|
|
|
20
|
-
type
|
|
42
|
+
type FetchHandlerHandleResult = {
|
|
21
43
|
matched: true;
|
|
22
44
|
response: Response;
|
|
23
45
|
} | {
|
|
24
46
|
matched: false;
|
|
25
|
-
response
|
|
47
|
+
response?: undefined;
|
|
26
48
|
};
|
|
27
|
-
interface
|
|
49
|
+
interface FetchHandlerFetchInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
|
|
28
50
|
request: Request;
|
|
29
|
-
toFetchResponseOptions: ToFetchResponseOptions;
|
|
30
|
-
}
|
|
31
|
-
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
|
32
|
-
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, Promise<FetchHandleResult>>[];
|
|
33
|
-
plugins?: FetchHandlerPlugin<T>[];
|
|
34
|
-
}
|
|
35
|
-
declare class FetchHandler<T extends Context> {
|
|
36
|
-
private readonly standardHandler;
|
|
37
|
-
private readonly toFetchResponseOptions;
|
|
38
|
-
private readonly adapterInterceptors;
|
|
39
|
-
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
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;
|
|
51
|
+
toFetchResponseOptions: ToFetchResponseOptions | undefined;
|
|
58
52
|
}
|
|
59
|
-
|
|
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][];
|
|
53
|
+
type FetchHandlerFetchInterceptor<T extends Context> = Interceptor<FetchHandlerFetchInterceptorOptions<T>, Promise<FetchHandlerHandleResult>>;
|
|
54
|
+
interface FetchHandlerOptions<T extends Context> {
|
|
74
55
|
/**
|
|
75
|
-
*
|
|
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)
|
|
56
|
+
* Options for how to convert the Fetch Response to a Standard Response, like event stream options, etc.
|
|
80
57
|
*/
|
|
81
|
-
|
|
58
|
+
toFetchResponse?: undefined | ToFetchResponseOptions;
|
|
82
59
|
/**
|
|
83
|
-
*
|
|
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.
|
|
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).
|
|
87
62
|
*/
|
|
88
|
-
|
|
63
|
+
fetchInterceptors?: FetchHandlerFetchInterceptor<T>[] | undefined;
|
|
64
|
+
plugins?: FetchHandlerPlugin<T>[] | undefined;
|
|
89
65
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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;
|
|
66
|
+
declare class FetchHandler<T extends Context> {
|
|
67
|
+
private readonly standardHandler;
|
|
68
|
+
private readonly toFetchResponseOptions;
|
|
69
|
+
private readonly fetchInterceptors;
|
|
70
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
|
71
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<FetchHandlerHandleResult>;
|
|
103
72
|
}
|
|
104
73
|
|
|
105
|
-
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<
|
|
74
|
+
interface RPCHandlerOptions<T extends Context> extends FetchHandlerOptions<T>, Omit<StandardHandlerOptions<T>, 'plugins'>, RPCHandlerCodecOptions<T> {
|
|
106
75
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* @default true
|
|
76
|
+
* Configuration for {@link CSRFGuardHandlerPlugin}, which is enabled by default for `RPCHandler` over HTTP.
|
|
110
77
|
*/
|
|
111
|
-
|
|
78
|
+
csrfGuardHandlerPlugin?: {
|
|
79
|
+
/**
|
|
80
|
+
* If `false`, this plugin is disabled.
|
|
81
|
+
*
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
enabled?: boolean;
|
|
85
|
+
};
|
|
112
86
|
}
|
|
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
|
-
*/
|
|
119
87
|
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
120
|
-
constructor(router: Router<
|
|
88
|
+
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
121
89
|
}
|
|
122
90
|
|
|
123
|
-
export {
|
|
124
|
-
export type {
|
|
91
|
+
export { CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
|
92
|
+
export type { FetchHandlerFetchInterceptor, FetchHandlerFetchInterceptorOptions, FetchHandlerHandleResult, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
|
@@ -1,153 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import '@
|
|
8
|
-
import '
|
|
9
|
-
import '../../shared/server.DEBcqOjg.mjs';
|
|
1
|
+
import { sortPlugins, intercept, resolveMaybeOptionalOptions, toArray } from '@orpc/shared';
|
|
2
|
+
import { toStandardLazyRequest, toFetchResponse } from '@standardserver/fetch';
|
|
3
|
+
import { r as resolveFriendlyStandardHandlerHandleOptions } from '../../shared/server.W91HSRkE.mjs';
|
|
4
|
+
import { C as CSRFGuardHandlerPlugin } from '../../shared/server.D_QauotT.mjs';
|
|
5
|
+
import { R as RPCHandlerCodec, S as StandardHandler } from '../../shared/server.COPVXhDG.mjs';
|
|
6
|
+
import '@orpc/client';
|
|
7
|
+
import '@standardserver/core';
|
|
8
|
+
import '../../shared/server.DofEOwf-.mjs';
|
|
10
9
|
import '@orpc/contract';
|
|
10
|
+
import '../../shared/server.BoiFpNT7.mjs';
|
|
11
11
|
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
class CompositeFetchHandlerPlugin {
|
|
13
|
+
name = "~composite/fetch-handler";
|
|
14
|
+
plugins;
|
|
15
|
+
constructor(plugins = []) {
|
|
16
|
+
this.plugins = sortPlugins(plugins);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
options.adapterInterceptors ??= [];
|
|
19
|
-
options.adapterInterceptors.push(async (options2) => {
|
|
20
|
-
if (!options2.request.body) {
|
|
21
|
-
return options2.next();
|
|
22
|
-
}
|
|
23
|
-
let currentBodySize = 0;
|
|
24
|
-
const rawReader = options2.request.body.getReader();
|
|
25
|
-
const reader = new ReadableStream({
|
|
26
|
-
start: async (controller) => {
|
|
27
|
-
try {
|
|
28
|
-
if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
|
|
29
|
-
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
while (true) {
|
|
33
|
-
const { done, value } = await rawReader.read();
|
|
34
|
-
if (done) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
currentBodySize += value.length;
|
|
38
|
-
if (currentBodySize > this.maxBodySize) {
|
|
39
|
-
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
controller.enqueue(value);
|
|
43
|
-
}
|
|
44
|
-
} finally {
|
|
45
|
-
controller.close();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const requestInit = { body: reader, duplex: "half" };
|
|
50
|
-
return options2.next({
|
|
51
|
-
...options2,
|
|
52
|
-
request: new Request(options2.request, requestInit)
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const ORDERED_SUPPORTED_ENCODINGS = ["gzip", "deflate"];
|
|
59
|
-
class CompressionPlugin {
|
|
60
|
-
encodings;
|
|
61
|
-
threshold;
|
|
62
|
-
filter;
|
|
63
|
-
constructor(options = {}) {
|
|
64
|
-
this.encodings = options.encodings ?? ORDERED_SUPPORTED_ENCODINGS;
|
|
65
|
-
this.threshold = options.threshold ?? 1024;
|
|
66
|
-
this.filter = (request, response) => {
|
|
67
|
-
const hasContentDisposition = response.headers.has("content-disposition");
|
|
68
|
-
const contentType = response.headers.get("content-type");
|
|
69
|
-
if (!hasContentDisposition && contentType?.startsWith("text/event-stream")) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return options.filter ? options.filter(request, response) : isCompressibleContentType(contentType);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
initRuntimeAdapter(options) {
|
|
76
|
-
options.adapterInterceptors ??= [];
|
|
77
|
-
options.adapterInterceptors.unshift(async (options2) => {
|
|
78
|
-
const result = await options2.next();
|
|
79
|
-
if (!result.matched) {
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
const response = result.response;
|
|
83
|
-
if (response.headers.has("content-encoding") || response.headers.has("transfer-encoding") || isNoTransformCacheControl(response.headers.get("cache-control"))) {
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
const contentLength = response.headers.get("content-length");
|
|
87
|
-
if (contentLength && Number(contentLength) < this.threshold) {
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
const acceptEncoding = options2.request.headers.get("accept-encoding")?.split(",").map((enc) => enc.trim().split(";")[0]);
|
|
91
|
-
const encoding = this.encodings.find((enc) => acceptEncoding?.includes(enc));
|
|
92
|
-
if (!response.body || encoding === void 0) {
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
if (!this.filter(options2.request, response)) {
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
const compressedBody = response.body.pipeThrough(new CompressionStream(encoding));
|
|
99
|
-
const compressedHeaders = new Headers(response.headers);
|
|
100
|
-
compressedHeaders.delete("content-length");
|
|
101
|
-
compressedHeaders.set("content-encoding", encoding);
|
|
102
|
-
return {
|
|
103
|
-
...result,
|
|
104
|
-
response: new Response(compressedBody, {
|
|
105
|
-
status: response.status,
|
|
106
|
-
statusText: response.statusText,
|
|
107
|
-
headers: compressedHeaders
|
|
108
|
-
})
|
|
109
|
-
};
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
114
|
-
function isCompressibleContentType(contentType) {
|
|
115
|
-
if (contentType === null) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
return COMPRESSIBLE_CONTENT_TYPE_REGEX.test(contentType);
|
|
119
|
-
}
|
|
120
|
-
const CACHE_CONTROL_NO_TRANSFORM_REGEX = /(?:^|,)\s*no-transform\s*(?:,|$)/i;
|
|
121
|
-
function isNoTransformCacheControl(cacheControl) {
|
|
122
|
-
if (cacheControl === null) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
return CACHE_CONTROL_NO_TRANSFORM_REGEX.test(cacheControl);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
|
|
129
|
-
initRuntimeAdapter(options) {
|
|
18
|
+
initFetchHandlerOptions(options) {
|
|
130
19
|
for (const plugin of this.plugins) {
|
|
131
|
-
plugin.
|
|
20
|
+
if (plugin.initFetchHandlerOptions) {
|
|
21
|
+
options = plugin.initFetchHandlerOptions(options);
|
|
22
|
+
}
|
|
132
23
|
}
|
|
24
|
+
return options;
|
|
133
25
|
}
|
|
134
26
|
}
|
|
135
27
|
|
|
136
28
|
class FetchHandler {
|
|
137
29
|
constructor(standardHandler, options = {}) {
|
|
138
30
|
this.standardHandler = standardHandler;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
this.toFetchResponseOptions = options;
|
|
31
|
+
options = new CompositeFetchHandlerPlugin(options.plugins).initFetchHandlerOptions(options);
|
|
32
|
+
this.fetchInterceptors = options.fetchInterceptors;
|
|
33
|
+
this.toFetchResponseOptions = options.toFetchResponse;
|
|
143
34
|
}
|
|
144
35
|
toFetchResponseOptions;
|
|
145
|
-
|
|
36
|
+
fetchInterceptors;
|
|
146
37
|
async handle(request, ...rest) {
|
|
147
38
|
return intercept(
|
|
148
|
-
this.
|
|
39
|
+
this.fetchInterceptors,
|
|
149
40
|
{
|
|
150
|
-
...
|
|
41
|
+
...resolveFriendlyStandardHandlerHandleOptions(resolveMaybeOptionalOptions(rest)),
|
|
151
42
|
request,
|
|
152
43
|
toFetchResponseOptions: this.toFetchResponseOptions
|
|
153
44
|
},
|
|
@@ -168,12 +59,16 @@ class FetchHandler {
|
|
|
168
59
|
|
|
169
60
|
class RPCHandler extends FetchHandler {
|
|
170
61
|
constructor(router, options = {}) {
|
|
171
|
-
if (options.
|
|
172
|
-
options
|
|
173
|
-
|
|
62
|
+
if (options.csrfGuardHandlerPlugin?.enabled !== false) {
|
|
63
|
+
options = {
|
|
64
|
+
...options,
|
|
65
|
+
plugins: [...toArray(options.plugins), new CSRFGuardHandlerPlugin()]
|
|
66
|
+
};
|
|
174
67
|
}
|
|
175
|
-
|
|
68
|
+
const codec = new RPCHandlerCodec(router, options);
|
|
69
|
+
const handler = new StandardHandler(codec, options);
|
|
70
|
+
super(handler, options);
|
|
176
71
|
}
|
|
177
72
|
}
|
|
178
73
|
|
|
179
|
-
export {
|
|
74
|
+
export { CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|