@orpc/server 0.0.0-next.d17ef5e → 0.0.0-next.d3b4900
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 +13 -1
- package/dist/adapters/fetch/index.d.ts +13 -1
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/hono/index.d.mts +1 -1
- package/dist/adapters/hono/index.d.ts +1 -1
- package/dist/adapters/hono/index.mjs +3 -3
- package/dist/adapters/next/index.d.mts +1 -1
- package/dist/adapters/next/index.d.ts +1 -1
- package/dist/adapters/next/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +20 -8
- package/dist/adapters/node/index.d.ts +20 -8
- package/dist/adapters/node/index.mjs +38 -6
- package/dist/adapters/standard/index.mjs +1 -1
- package/dist/plugins/index.mjs +9 -4
- package/dist/shared/{server.CTt4UYhI.mjs → server.B4eSvRkD.mjs} +49 -2
- package/dist/shared/{server.CVNC_Jz8.mjs → server.DnR6v9pj.mjs} +6 -3
- package/package.json +7 -7
@@ -35,8 +35,20 @@ declare class FetchHandler<T extends Context> {
|
|
35
35
|
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
36
36
|
}
|
37
37
|
|
38
|
+
interface BodyLimitPluginOptions {
|
39
|
+
/**
|
40
|
+
* The maximum size of the body in bytes.
|
41
|
+
*/
|
42
|
+
maxBodySize: number;
|
43
|
+
}
|
44
|
+
declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
45
|
+
private readonly maxBodySize;
|
46
|
+
constructor(options: BodyLimitPluginOptions);
|
47
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
48
|
+
}
|
49
|
+
|
38
50
|
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
39
51
|
constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
|
40
52
|
}
|
41
53
|
|
42
|
-
export { type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
54
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
@@ -35,8 +35,20 @@ declare class FetchHandler<T extends Context> {
|
|
35
35
|
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
36
36
|
}
|
37
37
|
|
38
|
+
interface BodyLimitPluginOptions {
|
39
|
+
/**
|
40
|
+
* The maximum size of the body in bytes.
|
41
|
+
*/
|
42
|
+
maxBodySize: number;
|
43
|
+
}
|
44
|
+
declare class BodyLimitPlugin<T extends Context> implements FetchHandlerPlugin<T> {
|
45
|
+
private readonly maxBodySize;
|
46
|
+
constructor(options: BodyLimitPluginOptions);
|
47
|
+
initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
|
48
|
+
}
|
49
|
+
|
38
50
|
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
39
51
|
constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
|
40
52
|
}
|
41
53
|
|
42
|
-
export { type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
54
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
@@ -1,7 +1,7 @@
|
|
1
|
-
export { F as FetchHandler, R as RPCHandler } from '../../shared/server.
|
2
|
-
import '@orpc/client/standard';
|
3
|
-
import '../../shared/server.CVNC_Jz8.mjs';
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.B4eSvRkD.mjs';
|
4
2
|
import '@orpc/client';
|
3
|
+
import '@orpc/client/standard';
|
4
|
+
import '../../shared/server.DnR6v9pj.mjs';
|
5
5
|
import '@orpc/shared';
|
6
6
|
import '../../shared/server.BtxZnWJ9.mjs';
|
7
7
|
import '@orpc/contract';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
3
3
|
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
4
|
import { Context as Context$1, MiddlewareHandler } from 'hono';
|
5
5
|
import { C as Context } from '../../shared/server.MZvbGc3n.mjs';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
3
3
|
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
4
|
import { Context as Context$1, MiddlewareHandler } from 'hono';
|
5
5
|
import { C as Context } from '../../shared/server.MZvbGc3n.js';
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export { F as FetchHandler, R as RPCHandler } from '../../shared/server.
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.B4eSvRkD.mjs';
|
2
2
|
import { value } from '@orpc/shared';
|
3
|
-
import '@orpc/client/standard';
|
4
|
-
import '../../shared/server.CVNC_Jz8.mjs';
|
5
3
|
import '@orpc/client';
|
4
|
+
import '@orpc/client/standard';
|
5
|
+
import '../../shared/server.DnR6v9pj.mjs';
|
6
6
|
import '../../shared/server.BtxZnWJ9.mjs';
|
7
7
|
import '@orpc/contract';
|
8
8
|
import '@orpc/standard-server-fetch';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.mjs';
|
3
3
|
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
4
|
import { NextRequest } from 'next/server';
|
5
5
|
import { C as Context } from '../../shared/server.MZvbGc3n.mjs';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
2
|
+
export { BodyLimitPlugin, BodyLimitPluginOptions, FetchHandleResult, FetchHandlerInterceptorOptions, FetchHandlerOptions, FetchHandlerPlugin, RPCHandler } from '../fetch/index.js';
|
3
3
|
import { Value, MaybeOptionalOptions } from '@orpc/shared';
|
4
4
|
import { NextRequest } from 'next/server';
|
5
5
|
import { C as Context } from '../../shared/server.MZvbGc3n.js';
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export { F as FetchHandler, R as RPCHandler } from '../../shared/server.
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.B4eSvRkD.mjs';
|
2
2
|
import { value } from '@orpc/shared';
|
3
|
-
import '@orpc/client/standard';
|
4
|
-
import '../../shared/server.CVNC_Jz8.mjs';
|
5
3
|
import '@orpc/client';
|
4
|
+
import '@orpc/client/standard';
|
5
|
+
import '../../shared/server.DnR6v9pj.mjs';
|
6
6
|
import '../../shared/server.BtxZnWJ9.mjs';
|
7
7
|
import '@orpc/contract';
|
8
8
|
import '@orpc/standard-server-fetch';
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
2
1
|
import { C as Context, R as Router } from '../../shared/server.MZvbGc3n.mjs';
|
2
|
+
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
3
3
|
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DJqfB27m.mjs';
|
4
4
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
5
5
|
import { F as FriendlyStandardHandleOptions } from '../../shared/server.C-CCcROC.mjs';
|
@@ -17,13 +17,13 @@ type NodeHttpHandleResult = {
|
|
17
17
|
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
18
18
|
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
19
19
|
}
|
20
|
+
interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
21
|
+
request: NodeHttpRequest;
|
22
|
+
response: NodeHttpResponse;
|
23
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
24
|
+
}
|
20
25
|
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
21
|
-
adapterInterceptors?: Interceptor<
|
22
|
-
request: NodeHttpRequest;
|
23
|
-
response: NodeHttpResponse;
|
24
|
-
sendStandardResponseOptions: SendStandardResponseOptions;
|
25
|
-
options: StandardHandleOptions<T>;
|
26
|
-
}, NodeHttpHandleResult, unknown>[];
|
26
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, unknown>[];
|
27
27
|
plugins?: NodeHttpHandlerPlugin<T>[];
|
28
28
|
}
|
29
29
|
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
@@ -34,8 +34,20 @@ declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
34
34
|
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
35
35
|
}
|
36
36
|
|
37
|
+
interface BodyLimitPluginOptions {
|
38
|
+
/**
|
39
|
+
* The maximum size of the body in bytes.
|
40
|
+
*/
|
41
|
+
maxBodySize: number;
|
42
|
+
}
|
43
|
+
declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
44
|
+
private readonly maxBodySize;
|
45
|
+
constructor(options: BodyLimitPluginOptions);
|
46
|
+
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
47
|
+
}
|
48
|
+
|
37
49
|
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
38
50
|
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
39
51
|
}
|
40
52
|
|
41
|
-
export { type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
53
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
2
1
|
import { C as Context, R as Router } from '../../shared/server.MZvbGc3n.js';
|
2
|
+
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
3
3
|
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.23VRZIfj.js';
|
4
4
|
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
5
5
|
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BG5ftPWa.js';
|
@@ -17,13 +17,13 @@ type NodeHttpHandleResult = {
|
|
17
17
|
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
18
18
|
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
19
19
|
}
|
20
|
+
interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
21
|
+
request: NodeHttpRequest;
|
22
|
+
response: NodeHttpResponse;
|
23
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
24
|
+
}
|
20
25
|
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
21
|
-
adapterInterceptors?: Interceptor<
|
22
|
-
request: NodeHttpRequest;
|
23
|
-
response: NodeHttpResponse;
|
24
|
-
sendStandardResponseOptions: SendStandardResponseOptions;
|
25
|
-
options: StandardHandleOptions<T>;
|
26
|
-
}, NodeHttpHandleResult, unknown>[];
|
26
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, unknown>[];
|
27
27
|
plugins?: NodeHttpHandlerPlugin<T>[];
|
28
28
|
}
|
29
29
|
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
@@ -34,8 +34,20 @@ declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
34
34
|
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
35
35
|
}
|
36
36
|
|
37
|
+
interface BodyLimitPluginOptions {
|
38
|
+
/**
|
39
|
+
* The maximum size of the body in bytes.
|
40
|
+
*/
|
41
|
+
maxBodySize: number;
|
42
|
+
}
|
43
|
+
declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugin<T> {
|
44
|
+
private readonly maxBodySize;
|
45
|
+
constructor(options: BodyLimitPluginOptions);
|
46
|
+
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
47
|
+
}
|
48
|
+
|
37
49
|
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
38
50
|
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
39
51
|
}
|
40
52
|
|
41
|
-
export { type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
53
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
@@ -1,12 +1,44 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
1
2
|
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
3
4
|
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.BVwwTHyO.mjs';
|
4
5
|
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
5
|
-
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from '../../shared/server.
|
6
|
-
import '@orpc/client';
|
6
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from '../../shared/server.DnR6v9pj.mjs';
|
7
7
|
import '../../shared/server.BtxZnWJ9.mjs';
|
8
8
|
import '@orpc/contract';
|
9
9
|
|
10
|
+
class BodyLimitPlugin {
|
11
|
+
maxBodySize;
|
12
|
+
constructor(options) {
|
13
|
+
this.maxBodySize = options.maxBodySize;
|
14
|
+
}
|
15
|
+
initRuntimeAdapter(options) {
|
16
|
+
options.adapterInterceptors ??= [];
|
17
|
+
options.adapterInterceptors.push(async (options2) => {
|
18
|
+
let isHeaderChecked = false;
|
19
|
+
const checkHeader = () => {
|
20
|
+
if (!isHeaderChecked && Number(options2.request.headers["content-length"]) > this.maxBodySize) {
|
21
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
22
|
+
}
|
23
|
+
isHeaderChecked = true;
|
24
|
+
};
|
25
|
+
const originalEmit = options2.request.emit.bind(options2.request);
|
26
|
+
let currentBodySize = 0;
|
27
|
+
options2.request.emit = (event, ...args) => {
|
28
|
+
if (event === "data") {
|
29
|
+
checkHeader();
|
30
|
+
currentBodySize += args[0].length;
|
31
|
+
if (currentBodySize > this.maxBodySize) {
|
32
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return originalEmit(event, ...args);
|
36
|
+
};
|
37
|
+
return options2.next();
|
38
|
+
});
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
10
42
|
class NodeHttpHandler {
|
11
43
|
constructor(standardHandler, options = {}) {
|
12
44
|
this.standardHandler = standardHandler;
|
@@ -22,12 +54,12 @@ class NodeHttpHandler {
|
|
22
54
|
return intercept(
|
23
55
|
this.adapterInterceptors,
|
24
56
|
{
|
57
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
25
58
|
request,
|
26
59
|
response,
|
27
|
-
sendStandardResponseOptions: this.sendStandardResponseOptions
|
28
|
-
options: resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest))
|
60
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
29
61
|
},
|
30
|
-
async ({ request: request2, response: response2, sendStandardResponseOptions, options }) => {
|
62
|
+
async ({ request: request2, response: response2, sendStandardResponseOptions, ...options }) => {
|
31
63
|
const standardRequest = toStandardLazyRequest(request2, response2);
|
32
64
|
const result = await this.standardHandler.handle(standardRequest, options);
|
33
65
|
if (!result.matched) {
|
@@ -50,4 +82,4 @@ class RPCHandler extends NodeHttpHandler {
|
|
50
82
|
}
|
51
83
|
}
|
52
84
|
|
53
|
-
export { NodeHttpHandler, RPCHandler };
|
85
|
+
export { BodyLimitPlugin, NodeHttpHandler, RPCHandler };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export { S as StandardHandler, a as StandardRPCCodec, b as StandardRPCMatcher } from '../../shared/server.
|
1
|
+
export { S as StandardHandler, a as StandardRPCCodec, b as StandardRPCMatcher } from '../../shared/server.DnR6v9pj.mjs';
|
2
2
|
import '@orpc/client';
|
3
3
|
import '@orpc/shared';
|
4
4
|
import '../../shared/server.BtxZnWJ9.mjs';
|
package/dist/plugins/index.mjs
CHANGED
@@ -78,14 +78,19 @@ class ResponseHeadersPlugin {
|
|
78
78
|
init(options) {
|
79
79
|
options.rootInterceptors ??= [];
|
80
80
|
options.rootInterceptors.push(async (interceptorOptions) => {
|
81
|
-
const
|
82
|
-
|
83
|
-
|
81
|
+
const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
|
82
|
+
const result = await interceptorOptions.next({
|
83
|
+
...interceptorOptions,
|
84
|
+
context: {
|
85
|
+
...interceptorOptions.context,
|
86
|
+
resHeaders
|
87
|
+
}
|
88
|
+
});
|
84
89
|
if (!result.matched) {
|
85
90
|
return result;
|
86
91
|
}
|
87
92
|
const responseHeaders = result.response.headers;
|
88
|
-
for (const [key, value] of
|
93
|
+
for (const [key, value] of resHeaders) {
|
89
94
|
if (Array.isArray(responseHeaders[key])) {
|
90
95
|
responseHeaders[key].push(value);
|
91
96
|
} else if (responseHeaders[key] !== void 0) {
|
@@ -1,9 +1,56 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
1
2
|
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DnR6v9pj.mjs';
|
3
4
|
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
4
5
|
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
5
6
|
import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
|
6
7
|
|
8
|
+
class BodyLimitPlugin {
|
9
|
+
maxBodySize;
|
10
|
+
constructor(options) {
|
11
|
+
this.maxBodySize = options.maxBodySize;
|
12
|
+
}
|
13
|
+
initRuntimeAdapter(options) {
|
14
|
+
options.adapterInterceptors ??= [];
|
15
|
+
options.adapterInterceptors.push(async (options2) => {
|
16
|
+
if (!options2.request.body) {
|
17
|
+
return options2.next();
|
18
|
+
}
|
19
|
+
let currentBodySize = 0;
|
20
|
+
const rawReader = options2.request.body.getReader();
|
21
|
+
const reader = new ReadableStream({
|
22
|
+
start: async (controller) => {
|
23
|
+
try {
|
24
|
+
if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
|
25
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
while (true) {
|
29
|
+
const { done, value } = await rawReader.read();
|
30
|
+
if (done) {
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
currentBodySize += value.length;
|
34
|
+
if (currentBodySize > this.maxBodySize) {
|
35
|
+
controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
controller.enqueue(value);
|
39
|
+
}
|
40
|
+
} finally {
|
41
|
+
controller.close();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
});
|
45
|
+
const requestInit = { body: reader, duplex: "half" };
|
46
|
+
return options2.next({
|
47
|
+
...options2,
|
48
|
+
request: new Request(options2.request, requestInit)
|
49
|
+
});
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
7
54
|
class FetchHandler {
|
8
55
|
constructor(standardHandler, options = {}) {
|
9
56
|
this.standardHandler = standardHandler;
|
@@ -48,4 +95,4 @@ class RPCHandler extends FetchHandler {
|
|
48
95
|
}
|
49
96
|
}
|
50
97
|
|
51
|
-
export { FetchHandler as F, RPCHandler as R };
|
98
|
+
export { BodyLimitPlugin as B, FetchHandler as F, RPCHandler as R };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import { toArray, intercept,
|
2
|
+
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
3
3
|
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
|
4
4
|
|
5
5
|
class StandardHandler {
|
@@ -30,8 +30,11 @@ class StandardHandler {
|
|
30
30
|
async ({ request: request2, context, prefix }) => {
|
31
31
|
const method = request2.method;
|
32
32
|
const url = request2.url;
|
33
|
-
|
34
|
-
|
33
|
+
if (prefix && !url.pathname.startsWith(prefix)) {
|
34
|
+
return { matched: false, response: void 0 };
|
35
|
+
}
|
36
|
+
const pathname = prefix ? url.pathname.replace(prefix, "") : url.pathname;
|
37
|
+
const match = await this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`);
|
35
38
|
if (!match) {
|
36
39
|
return { matched: false, response: void 0 };
|
37
40
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.0-next.
|
4
|
+
"version": "0.0.0-next.d3b4900",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,12 +58,12 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/client": "0.0.0-next.
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/
|
65
|
-
"@orpc/standard-server-
|
66
|
-
"@orpc/
|
61
|
+
"@orpc/client": "0.0.0-next.d3b4900",
|
62
|
+
"@orpc/contract": "0.0.0-next.d3b4900",
|
63
|
+
"@orpc/standard-server": "0.0.0-next.d3b4900",
|
64
|
+
"@orpc/shared": "0.0.0-next.d3b4900",
|
65
|
+
"@orpc/standard-server-fetch": "0.0.0-next.d3b4900",
|
66
|
+
"@orpc/standard-server-node": "0.0.0-next.d3b4900"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"supertest": "^7.0.0"
|