@orpc/server 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/fetch/index.d.mts +47 -2
- package/dist/adapters/fetch/index.d.ts +47 -2
- package/dist/adapters/fetch/index.mjs +70 -1
- package/dist/adapters/node/index.d.mts +23 -2
- package/dist/adapters/node/index.d.ts +23 -2
- package/dist/adapters/node/index.mjs +66 -10
- package/package.json +10 -9
@@ -57,6 +57,51 @@ declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T
|
|
57
57
|
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
58
58
|
}
|
59
59
|
|
60
|
+
/**
|
61
|
+
* This plugin is heavily inspired by the [Hono Compression Plugin](https://github.com/honojs/hono/blob/main/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;
|
82
|
+
/**
|
83
|
+
* Override the default content-type filter used to determine which responses should be compressed.
|
84
|
+
*
|
85
|
+
* @warning [Event Iterator](https://orpc.unnoq.com/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.unnoq.com/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
|
+
|
60
105
|
type RPCHandlerOptions<T extends Context> = FetchHandlerOptions<T> & StandardRPCHandlerOptions<T> & {
|
61
106
|
/**
|
62
107
|
* Enables or disables the StrictGetMethodPlugin.
|
@@ -75,5 +120,5 @@ declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
75
120
|
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
76
121
|
}
|
77
122
|
|
78
|
-
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
79
|
-
export type { BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
123
|
+
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler, RPCHandler };
|
124
|
+
export type { BodyLimitPluginOptions, CompressionPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
@@ -57,6 +57,51 @@ declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T
|
|
57
57
|
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
58
58
|
}
|
59
59
|
|
60
|
+
/**
|
61
|
+
* This plugin is heavily inspired by the [Hono Compression Plugin](https://github.com/honojs/hono/blob/main/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;
|
82
|
+
/**
|
83
|
+
* Override the default content-type filter used to determine which responses should be compressed.
|
84
|
+
*
|
85
|
+
* @warning [Event Iterator](https://orpc.unnoq.com/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.unnoq.com/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
|
+
|
60
105
|
type RPCHandlerOptions<T extends Context> = FetchHandlerOptions<T> & StandardRPCHandlerOptions<T> & {
|
61
106
|
/**
|
62
107
|
* Enables or disables the StrictGetMethodPlugin.
|
@@ -75,5 +120,5 @@ declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
|
75
120
|
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
76
121
|
}
|
77
122
|
|
78
|
-
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
79
|
-
export type { BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
123
|
+
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler, RPCHandler };
|
124
|
+
export type { BodyLimitPluginOptions, CompressionPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandlerOptions };
|
@@ -56,6 +56,75 @@ class BodyLimitPlugin {
|
|
56
56
|
}
|
57
57
|
}
|
58
58
|
|
59
|
+
const ORDERED_SUPPORTED_ENCODINGS = ["gzip", "deflate"];
|
60
|
+
class CompressionPlugin {
|
61
|
+
encodings;
|
62
|
+
threshold;
|
63
|
+
filter;
|
64
|
+
constructor(options = {}) {
|
65
|
+
this.encodings = options.encodings ?? ORDERED_SUPPORTED_ENCODINGS;
|
66
|
+
this.threshold = options.threshold ?? 1024;
|
67
|
+
this.filter = (request, response) => {
|
68
|
+
const hasContentDisposition = response.headers.has("content-disposition");
|
69
|
+
const contentType = response.headers.get("content-type");
|
70
|
+
if (!hasContentDisposition && contentType?.startsWith("text/event-stream")) {
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
return options.filter ? options.filter(request, response) : isCompressibleContentType(contentType);
|
74
|
+
};
|
75
|
+
}
|
76
|
+
initRuntimeAdapter(options) {
|
77
|
+
options.adapterInterceptors ??= [];
|
78
|
+
options.adapterInterceptors.unshift(async (options2) => {
|
79
|
+
const result = await options2.next();
|
80
|
+
if (!result.matched) {
|
81
|
+
return result;
|
82
|
+
}
|
83
|
+
const response = result.response;
|
84
|
+
if (response.headers.has("content-encoding") || response.headers.has("transfer-encoding") || isNoTransformCacheControl(response.headers.get("cache-control"))) {
|
85
|
+
return result;
|
86
|
+
}
|
87
|
+
const contentLength = response.headers.get("content-length");
|
88
|
+
if (contentLength && Number(contentLength) < this.threshold) {
|
89
|
+
return result;
|
90
|
+
}
|
91
|
+
const acceptEncoding = options2.request.headers.get("accept-encoding")?.split(",").map((enc) => enc.trim().split(";")[0]);
|
92
|
+
const encoding = this.encodings.find((enc) => acceptEncoding?.includes(enc));
|
93
|
+
if (!response.body || encoding === void 0) {
|
94
|
+
return result;
|
95
|
+
}
|
96
|
+
if (!this.filter(options2.request, response)) {
|
97
|
+
return result;
|
98
|
+
}
|
99
|
+
const compressedBody = response.body.pipeThrough(new CompressionStream(encoding));
|
100
|
+
const compressedHeaders = new Headers(response.headers);
|
101
|
+
compressedHeaders.delete("content-length");
|
102
|
+
compressedHeaders.set("content-encoding", encoding);
|
103
|
+
return {
|
104
|
+
...result,
|
105
|
+
response: new Response(compressedBody, {
|
106
|
+
...response,
|
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
|
+
|
59
128
|
class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
|
60
129
|
initRuntimeAdapter(options) {
|
61
130
|
for (const plugin of this.plugins) {
|
@@ -107,4 +176,4 @@ class RPCHandler extends FetchHandler {
|
|
107
176
|
}
|
108
177
|
}
|
109
178
|
|
110
|
-
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
|
179
|
+
export { BodyLimitPlugin, CompositeFetchHandlerPlugin, CompressionPlugin, FetchHandler, RPCHandler };
|
@@ -3,6 +3,7 @@ import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
4
|
import { g as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.gqRxT-yN.mjs';
|
5
5
|
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BEFBl-Cb.mjs';
|
6
|
+
import compression from '@orpc/interop/compression';
|
6
7
|
import { S as StandardRPCHandlerOptions } from '../../shared/server.BU4WI18A.mjs';
|
7
8
|
import '@orpc/client';
|
8
9
|
import '@orpc/contract';
|
@@ -56,6 +57,26 @@ declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugi
|
|
56
57
|
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
57
58
|
}
|
58
59
|
|
60
|
+
interface CompressionPluginOptions extends compression.CompressionOptions {
|
61
|
+
/**
|
62
|
+
* Override the default content-type filter used to determine which responses should be compressed.
|
63
|
+
*
|
64
|
+
* @warning [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
|
65
|
+
* @default only responses with compressible content types are compressed.
|
66
|
+
*/
|
67
|
+
filter?: (req: NodeHttpRequest, res: NodeHttpResponse) => boolean;
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* The Compression Plugin adds response compression to the Node.js HTTP Server.
|
71
|
+
*
|
72
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/compression Compression Plugin Docs}
|
73
|
+
*/
|
74
|
+
declare class CompressionPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
75
|
+
private readonly compressionHandler;
|
76
|
+
constructor(options?: CompressionPluginOptions);
|
77
|
+
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
78
|
+
}
|
79
|
+
|
59
80
|
type RPCHandlerOptions<T extends Context> = NodeHttpHandlerOptions<T> & StandardRPCHandlerOptions<T> & {
|
60
81
|
/**
|
61
82
|
* Enables or disables the StrictGetMethodPlugin.
|
@@ -74,5 +95,5 @@ declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
74
95
|
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
75
96
|
}
|
76
97
|
|
77
|
-
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
78
|
-
export type { BodyLimitPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
98
|
+
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, CompressionPlugin, NodeHttpHandler, RPCHandler };
|
99
|
+
export type { BodyLimitPluginOptions, CompressionPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
@@ -3,6 +3,7 @@ import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
4
|
import { g as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandleOptions, f as StandardHandler } from '../../shared/server.Bmh5xd4n.js';
|
5
5
|
import { F as FriendlyStandardHandleOptions } from '../../shared/server.B7b2w3_i.js';
|
6
|
+
import compression from '@orpc/interop/compression';
|
6
7
|
import { S as StandardRPCHandlerOptions } from '../../shared/server.D0H-iaY3.js';
|
7
8
|
import '@orpc/client';
|
8
9
|
import '@orpc/contract';
|
@@ -56,6 +57,26 @@ declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugi
|
|
56
57
|
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
57
58
|
}
|
58
59
|
|
60
|
+
interface CompressionPluginOptions extends compression.CompressionOptions {
|
61
|
+
/**
|
62
|
+
* Override the default content-type filter used to determine which responses should be compressed.
|
63
|
+
*
|
64
|
+
* @warning [Event Iterator](https://orpc.unnoq.com/docs/event-iterator) responses are never compressed, regardless of this filter's return value.
|
65
|
+
* @default only responses with compressible content types are compressed.
|
66
|
+
*/
|
67
|
+
filter?: (req: NodeHttpRequest, res: NodeHttpResponse) => boolean;
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* The Compression Plugin adds response compression to the Node.js HTTP Server.
|
71
|
+
*
|
72
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/compression Compression Plugin Docs}
|
73
|
+
*/
|
74
|
+
declare class CompressionPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
75
|
+
private readonly compressionHandler;
|
76
|
+
constructor(options?: CompressionPluginOptions);
|
77
|
+
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
78
|
+
}
|
79
|
+
|
59
80
|
type RPCHandlerOptions<T extends Context> = NodeHttpHandlerOptions<T> & StandardRPCHandlerOptions<T> & {
|
60
81
|
/**
|
61
82
|
* Enables or disables the StrictGetMethodPlugin.
|
@@ -74,5 +95,5 @@ declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
|
74
95
|
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
75
96
|
}
|
76
97
|
|
77
|
-
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
78
|
-
export type { BodyLimitPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
98
|
+
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, CompressionPlugin, NodeHttpHandler, RPCHandler };
|
99
|
+
export type { BodyLimitPluginOptions, CompressionPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
|
-
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { once, toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import compression from '@orpc/interop/compression';
|
3
4
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
4
5
|
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
5
6
|
import '@orpc/standard-server';
|
@@ -19,14 +20,12 @@ class BodyLimitPlugin {
|
|
19
20
|
initRuntimeAdapter(options) {
|
20
21
|
options.adapterInterceptors ??= [];
|
21
22
|
options.adapterInterceptors.push(async (options2) => {
|
22
|
-
|
23
|
-
|
24
|
-
if (!isHeaderChecked && Number(options2.request.headers["content-length"]) > this.maxBodySize) {
|
23
|
+
const checkHeader = once(() => {
|
24
|
+
if (Number(options2.request.headers["content-length"]) > this.maxBodySize) {
|
25
25
|
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
26
26
|
}
|
27
|
-
|
28
|
-
|
29
|
-
const originalEmit = options2.request.emit.bind(options2.request);
|
27
|
+
});
|
28
|
+
const originalEmit = options2.request.emit;
|
30
29
|
let currentBodySize = 0;
|
31
30
|
options2.request.emit = (event, ...args) => {
|
32
31
|
if (event === "data") {
|
@@ -36,9 +35,66 @@ class BodyLimitPlugin {
|
|
36
35
|
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
37
36
|
}
|
38
37
|
}
|
39
|
-
return originalEmit(event, ...args);
|
38
|
+
return originalEmit.call(options2.request, event, ...args);
|
40
39
|
};
|
41
|
-
|
40
|
+
try {
|
41
|
+
return await options2.next(options2);
|
42
|
+
} finally {
|
43
|
+
options2.request.emit = originalEmit;
|
44
|
+
}
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
class CompressionPlugin {
|
50
|
+
compressionHandler;
|
51
|
+
constructor(options = {}) {
|
52
|
+
this.compressionHandler = compression({
|
53
|
+
...options,
|
54
|
+
filter: (req, res) => {
|
55
|
+
const hasContentDisposition = res.hasHeader("content-disposition");
|
56
|
+
const contentType = res.getHeader("content-type")?.toString();
|
57
|
+
if (!hasContentDisposition && contentType?.startsWith("text/event-stream")) {
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
return options.filter ? options.filter(req, res) : compression.filter(req, res);
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}
|
64
|
+
initRuntimeAdapter(options) {
|
65
|
+
options.adapterInterceptors ??= [];
|
66
|
+
options.adapterInterceptors.unshift(async (options2) => {
|
67
|
+
let resolve;
|
68
|
+
let reject;
|
69
|
+
const promise = new Promise((res, rej) => {
|
70
|
+
resolve = res;
|
71
|
+
reject = rej;
|
72
|
+
});
|
73
|
+
const originalWrite = options2.response.write;
|
74
|
+
const originalEnd = options2.response.end;
|
75
|
+
const originalOn = options2.response.on;
|
76
|
+
this.compressionHandler(
|
77
|
+
options2.request,
|
78
|
+
options2.response,
|
79
|
+
async (err) => {
|
80
|
+
if (err) {
|
81
|
+
reject(err);
|
82
|
+
} else {
|
83
|
+
try {
|
84
|
+
resolve(await options2.next());
|
85
|
+
} catch (error) {
|
86
|
+
reject(error);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
);
|
91
|
+
try {
|
92
|
+
return await promise;
|
93
|
+
} finally {
|
94
|
+
options2.response.write = originalWrite;
|
95
|
+
options2.response.end = originalEnd;
|
96
|
+
options2.response.on = originalOn;
|
97
|
+
}
|
42
98
|
});
|
43
99
|
}
|
44
100
|
}
|
@@ -93,4 +149,4 @@ class RPCHandler extends NodeHttpHandler {
|
|
93
149
|
}
|
94
150
|
}
|
95
151
|
|
96
|
-
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
152
|
+
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, CompressionPlugin, NodeHttpHandler, RPCHandler };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.8.
|
4
|
+
"version": "1.8.1",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -102,14 +102,15 @@
|
|
102
102
|
},
|
103
103
|
"dependencies": {
|
104
104
|
"cookie": "^1.0.2",
|
105
|
-
"@orpc/client": "1.8.
|
106
|
-
"@orpc/
|
107
|
-
"@orpc/
|
108
|
-
"@orpc/
|
109
|
-
"@orpc/standard-server
|
110
|
-
"@orpc/standard-server-
|
111
|
-
"@orpc/standard-server-
|
112
|
-
"@orpc/standard-server-peer": "1.8.
|
105
|
+
"@orpc/client": "1.8.1",
|
106
|
+
"@orpc/contract": "1.8.1",
|
107
|
+
"@orpc/interop": "1.8.1",
|
108
|
+
"@orpc/shared": "1.8.1",
|
109
|
+
"@orpc/standard-server": "1.8.1",
|
110
|
+
"@orpc/standard-server-aws-lambda": "1.8.1",
|
111
|
+
"@orpc/standard-server-fetch": "1.8.1",
|
112
|
+
"@orpc/standard-server-peer": "1.8.1",
|
113
|
+
"@orpc/standard-server-node": "1.8.1"
|
113
114
|
},
|
114
115
|
"devDependencies": {
|
115
116
|
"@types/ws": "^8.18.1",
|