@orpc/server 0.0.0-next.954e6e2 → 0.0.0-next.95b67ec
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 +26 -17
- package/dist/adapters/fetch/index.d.mts +54 -11
- package/dist/adapters/fetch/index.d.ts +54 -11
- package/dist/adapters/fetch/index.mjs +103 -7
- package/dist/adapters/node/index.d.mts +56 -22
- package/dist/adapters/node/index.d.ts +56 -22
- package/dist/adapters/node/index.mjs +81 -21
- package/dist/adapters/standard/index.d.mts +12 -15
- package/dist/adapters/standard/index.d.ts +12 -15
- package/dist/adapters/standard/index.mjs +6 -5
- package/dist/index.d.mts +701 -127
- package/dist/index.d.ts +701 -127
- package/dist/index.mjs +193 -52
- package/dist/plugins/index.d.mts +143 -18
- package/dist/plugins/index.d.ts +143 -18
- package/dist/plugins/index.mjs +157 -8
- package/dist/shared/server.BM1HMJGg.mjs +190 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
- package/dist/shared/server.CzSMXd8y.d.mts +18 -0
- package/dist/shared/server.DEgjJVit.d.ts +18 -0
- package/dist/shared/{server.V6zT5iYQ.mjs → server.DG7Tamti.mjs} +161 -173
- package/dist/shared/server.DPWk5pjW.d.mts +192 -0
- package/dist/shared/server.DPWk5pjW.d.ts +192 -0
- package/dist/shared/server.QUe9N8P4.d.mts +10 -0
- package/dist/shared/server.YZzrREz9.d.ts +74 -0
- package/dist/shared/server.eWLxY3lq.d.mts +74 -0
- package/package.json +9 -22
- package/dist/adapters/hono/index.d.mts +0 -20
- package/dist/adapters/hono/index.d.ts +0 -20
- package/dist/adapters/hono/index.mjs +0 -32
- package/dist/adapters/next/index.d.mts +0 -27
- package/dist/adapters/next/index.d.ts +0 -27
- package/dist/adapters/next/index.mjs +0 -29
- package/dist/shared/server.B-ewprcf.d.ts +0 -77
- package/dist/shared/server.BBGuTxHE.mjs +0 -163
- package/dist/shared/server.CA-o8cUY.d.mts +0 -9
- package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
- package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
- package/dist/shared/server.DJrh0Ceu.d.mts +0 -77
- package/dist/shared/server.DPQt9YYq.d.ts +0 -9
- package/dist/shared/server.KwueCzFr.mjs +0 -26
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
@@ -1,30 +1,90 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
1
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
2
|
-
import {
|
3
|
-
import '@orpc/client';
|
4
|
-
import '@orpc/shared';
|
5
|
-
import '../../shared/server.Q6ZmnTgO.mjs';
|
6
|
-
import '../../shared/server.V6zT5iYQ.mjs';
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.BVwwTHyO.mjs';
|
7
5
|
import '@orpc/contract';
|
6
|
+
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.BM1HMJGg.mjs';
|
8
7
|
import '@orpc/client/standard';
|
8
|
+
import '@orpc/standard-server/batch';
|
9
|
+
import '../../shared/server.BW-nUGgA.mjs';
|
10
|
+
import '../../shared/server.DG7Tamti.mjs';
|
9
11
|
|
10
|
-
class
|
11
|
-
|
12
|
-
constructor(
|
13
|
-
|
14
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
15
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
|
+
class BodyLimitPlugin {
|
13
|
+
maxBodySize;
|
14
|
+
constructor(options) {
|
15
|
+
this.maxBodySize = options.maxBodySize;
|
16
16
|
}
|
17
|
-
|
18
|
-
options
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
initRuntimeAdapter(options) {
|
18
|
+
options.adapterInterceptors ??= [];
|
19
|
+
options.adapterInterceptors.push(async (options2) => {
|
20
|
+
let isHeaderChecked = false;
|
21
|
+
const checkHeader = () => {
|
22
|
+
if (!isHeaderChecked && Number(options2.request.headers["content-length"]) > this.maxBodySize) {
|
23
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
24
|
+
}
|
25
|
+
isHeaderChecked = true;
|
26
|
+
};
|
27
|
+
const originalEmit = options2.request.emit.bind(options2.request);
|
28
|
+
let currentBodySize = 0;
|
29
|
+
options2.request.emit = (event, ...args) => {
|
30
|
+
if (event === "data") {
|
31
|
+
checkHeader();
|
32
|
+
currentBodySize += args[0].length;
|
33
|
+
if (currentBodySize > this.maxBodySize) {
|
34
|
+
throw new ORPCError("PAYLOAD_TOO_LARGE");
|
35
|
+
}
|
36
|
+
}
|
37
|
+
return originalEmit(event, ...args);
|
38
|
+
};
|
39
|
+
return options2.next();
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
class CompositeNodeHttpHandlerPlugin extends CompositeStandardHandlerPlugin {
|
45
|
+
initRuntimeAdapter(options) {
|
46
|
+
for (const plugin of this.plugins) {
|
47
|
+
plugin.initRuntimeAdapter?.(options);
|
24
48
|
}
|
25
|
-
await sendStandardResponse(res, result.response, options);
|
26
|
-
return { matched: true };
|
27
49
|
}
|
28
50
|
}
|
29
51
|
|
30
|
-
|
52
|
+
class NodeHttpHandler {
|
53
|
+
constructor(standardHandler, options = {}) {
|
54
|
+
this.standardHandler = standardHandler;
|
55
|
+
const plugin = new CompositeNodeHttpHandlerPlugin(options.plugins);
|
56
|
+
plugin.initRuntimeAdapter(options);
|
57
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
58
|
+
this.sendStandardResponseOptions = options;
|
59
|
+
}
|
60
|
+
sendStandardResponseOptions;
|
61
|
+
adapterInterceptors;
|
62
|
+
async handle(request, response, ...rest) {
|
63
|
+
return intercept(
|
64
|
+
this.adapterInterceptors,
|
65
|
+
{
|
66
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
67
|
+
request,
|
68
|
+
response,
|
69
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
70
|
+
},
|
71
|
+
async ({ request: request2, response: response2, sendStandardResponseOptions, ...options }) => {
|
72
|
+
const standardRequest = toStandardLazyRequest(request2, response2);
|
73
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
74
|
+
if (!result.matched) {
|
75
|
+
return { matched: false };
|
76
|
+
}
|
77
|
+
await sendStandardResponse(response2, result.response, sendStandardResponseOptions);
|
78
|
+
return { matched: true };
|
79
|
+
}
|
80
|
+
);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
class RPCHandler extends NodeHttpHandler {
|
85
|
+
constructor(router, options = {}) {
|
86
|
+
super(new StandardRPCHandler(router, options), options);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
@@ -1,29 +1,26 @@
|
|
1
|
-
import { c as StandardCodec,
|
2
|
-
export {
|
3
|
-
import { ORPCError } from '@orpc/client';
|
1
|
+
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.eWLxY3lq.mjs';
|
2
|
+
export { C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.eWLxY3lq.mjs';
|
3
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
4
|
+
import { StandardRPCSerializer } from '@orpc/client/standard';
|
4
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
import { HTTPPath } from '@orpc/contract';
|
6
|
+
import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.DPWk5pjW.mjs';
|
7
|
+
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.CzSMXd8y.mjs';
|
8
|
+
import '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
11
|
-
|
12
|
-
serializer?: RPCSerializer;
|
13
|
-
}
|
14
|
-
declare class RPCCodec implements StandardCodec {
|
11
|
+
declare class StandardRPCCodec implements StandardCodec {
|
15
12
|
private readonly serializer;
|
16
|
-
constructor(
|
13
|
+
constructor(serializer: StandardRPCSerializer);
|
17
14
|
decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
18
15
|
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
19
16
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
17
|
}
|
21
18
|
|
22
|
-
declare class
|
19
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
23
20
|
private readonly tree;
|
24
21
|
private pendingRouters;
|
25
|
-
init(router: AnyRouter, path?: string[]): void;
|
22
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
26
23
|
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
27
24
|
}
|
28
25
|
|
29
|
-
export {
|
26
|
+
export { StandardCodec, StandardMatchResult, StandardMatcher, StandardParams, StandardRPCCodec, StandardRPCMatcher };
|
@@ -1,29 +1,26 @@
|
|
1
|
-
import { c as StandardCodec,
|
2
|
-
export {
|
3
|
-
import { ORPCError } from '@orpc/client';
|
1
|
+
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.YZzrREz9.js';
|
2
|
+
export { C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.YZzrREz9.js';
|
3
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
4
|
+
import { StandardRPCSerializer } from '@orpc/client/standard';
|
4
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
import { HTTPPath } from '@orpc/contract';
|
6
|
+
import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.DPWk5pjW.js';
|
7
|
+
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.DEgjJVit.js';
|
8
|
+
import '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
11
|
-
|
12
|
-
serializer?: RPCSerializer;
|
13
|
-
}
|
14
|
-
declare class RPCCodec implements StandardCodec {
|
11
|
+
declare class StandardRPCCodec implements StandardCodec {
|
15
12
|
private readonly serializer;
|
16
|
-
constructor(
|
13
|
+
constructor(serializer: StandardRPCSerializer);
|
17
14
|
decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
18
15
|
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
19
16
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
17
|
}
|
21
18
|
|
22
|
-
declare class
|
19
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
23
20
|
private readonly tree;
|
24
21
|
private pendingRouters;
|
25
|
-
init(router: AnyRouter, path?: string[]): void;
|
22
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
26
23
|
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
27
24
|
}
|
28
25
|
|
29
|
-
export {
|
26
|
+
export { StandardCodec, StandardMatchResult, StandardMatcher, StandardParams, StandardRPCCodec, StandardRPCMatcher };
|
@@ -1,7 +1,8 @@
|
|
1
|
-
export {
|
2
|
-
import '@orpc/client';
|
1
|
+
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.BM1HMJGg.mjs';
|
2
|
+
import '@orpc/client/standard';
|
3
3
|
import '@orpc/shared';
|
4
|
-
import '
|
5
|
-
import '
|
4
|
+
import '@orpc/standard-server/batch';
|
5
|
+
import '@orpc/client';
|
6
|
+
import '../../shared/server.BW-nUGgA.mjs';
|
6
7
|
import '@orpc/contract';
|
7
|
-
import '
|
8
|
+
import '../../shared/server.DG7Tamti.mjs';
|