@orpc/server 1.0.0-beta.3 → 1.0.0-beta.4
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 +8 -0
- package/dist/adapters/fetch/index.d.mts +37 -11
- package/dist/adapters/fetch/index.d.ts +37 -11
- package/dist/adapters/fetch/index.mjs +5 -5
- package/dist/adapters/hono/index.d.mts +4 -3
- package/dist/adapters/hono/index.d.ts +4 -3
- package/dist/adapters/hono/index.mjs +5 -5
- package/dist/adapters/next/index.d.mts +4 -3
- package/dist/adapters/next/index.d.ts +4 -3
- package/dist/adapters/next/index.mjs +5 -5
- package/dist/adapters/node/index.d.mts +38 -21
- package/dist/adapters/node/index.d.ts +38 -21
- package/dist/adapters/node/index.mjs +73 -20
- package/dist/adapters/standard/index.d.mts +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- package/dist/adapters/standard/index.mjs +1 -2
- package/dist/plugins/index.d.mts +10 -11
- package/dist/plugins/index.d.ts +10 -11
- package/dist/plugins/index.mjs +9 -5
- package/dist/shared/{server.CPqNKiJp.d.ts → server.23VRZIfj.d.ts} +14 -23
- package/dist/shared/server.B4eSvRkD.mjs +98 -0
- package/dist/shared/server.BG5ftPWa.d.ts +10 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.C-CCcROC.d.mts +10 -0
- package/dist/shared/{server.BqBN5WhH.d.mts → server.CIbpOMZX.d.mts} +1 -1
- package/dist/shared/{server.Dm3ZuTuI.d.ts → server.DCcCuA52.d.ts} +1 -1
- package/dist/shared/{server.P4_D9lKb.d.mts → server.DJqfB27m.d.mts} +14 -23
- package/dist/shared/{server.BY9sDlwl.mjs → server.DnR6v9pj.mjs} +28 -26
- package/package.json +8 -8
- package/dist/shared/server.Dba3Iiyp.mjs +0 -12
- package/dist/shared/server.Del5OmaY.mjs +0 -29
package/README.md
CHANGED
@@ -117,6 +117,14 @@ export const createPlanet = os
|
|
117
117
|
export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
|
118
118
|
```
|
119
119
|
|
120
|
+
## Sponsors
|
121
|
+
|
122
|
+
<p align="center">
|
123
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
124
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
125
|
+
</a>
|
126
|
+
</p>
|
127
|
+
|
120
128
|
## License
|
121
129
|
|
122
130
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
3
1
|
import { C as Context, R as Router } from '../../shared/server.MZvbGc3n.mjs';
|
4
|
-
import { S as StandardHandleOptions } from '../../shared/server.
|
5
|
-
import {
|
2
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DJqfB27m.mjs';
|
3
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.C-CCcROC.mjs';
|
5
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.CIbpOMZX.mjs';
|
6
7
|
import '@orpc/client';
|
7
8
|
import '@orpc/contract';
|
8
9
|
import '@orpc/standard-server';
|
@@ -15,14 +16,39 @@ type FetchHandleResult = {
|
|
15
16
|
matched: false;
|
16
17
|
response: undefined;
|
17
18
|
};
|
18
|
-
interface
|
19
|
-
|
19
|
+
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
20
|
+
initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
|
20
21
|
}
|
21
|
-
|
22
|
-
|
22
|
+
interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
23
|
+
request: Request;
|
24
|
+
toFetchResponseOptions: ToFetchResponseOptions;
|
25
|
+
}
|
26
|
+
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
27
|
+
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, unknown>[];
|
28
|
+
plugins?: FetchHandlerPlugin<T>[];
|
29
|
+
}
|
30
|
+
declare class FetchHandler<T extends Context> {
|
23
31
|
private readonly standardHandler;
|
24
|
-
|
25
|
-
|
32
|
+
private readonly toFetchResponseOptions;
|
33
|
+
private readonly adapterInterceptors;
|
34
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
35
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
36
|
+
}
|
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
|
+
|
50
|
+
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
51
|
+
constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
|
26
52
|
}
|
27
53
|
|
28
|
-
export { type
|
54
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
3
1
|
import { C as Context, R as Router } from '../../shared/server.MZvbGc3n.js';
|
4
|
-
import { S as StandardHandleOptions } from '../../shared/server.
|
5
|
-
import {
|
2
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.23VRZIfj.js';
|
3
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BG5ftPWa.js';
|
5
|
+
import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DCcCuA52.js';
|
6
7
|
import '@orpc/client';
|
7
8
|
import '@orpc/contract';
|
8
9
|
import '@orpc/standard-server';
|
@@ -15,14 +16,39 @@ type FetchHandleResult = {
|
|
15
16
|
matched: false;
|
16
17
|
response: undefined;
|
17
18
|
};
|
18
|
-
interface
|
19
|
-
|
19
|
+
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
20
|
+
initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
|
20
21
|
}
|
21
|
-
|
22
|
-
|
22
|
+
interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
23
|
+
request: Request;
|
24
|
+
toFetchResponseOptions: ToFetchResponseOptions;
|
25
|
+
}
|
26
|
+
interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
|
27
|
+
adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, unknown>[];
|
28
|
+
plugins?: FetchHandlerPlugin<T>[];
|
29
|
+
}
|
30
|
+
declare class FetchHandler<T extends Context> {
|
23
31
|
private readonly standardHandler;
|
24
|
-
|
25
|
-
|
32
|
+
private readonly toFetchResponseOptions;
|
33
|
+
private readonly adapterInterceptors;
|
34
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<FetchHandlerOptions<T>>);
|
35
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
36
|
+
}
|
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
|
+
|
50
|
+
declare class RPCHandler<T extends Context> extends FetchHandler<T> {
|
51
|
+
constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
|
26
52
|
}
|
27
53
|
|
28
|
-
export { type
|
54
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
|
@@ -1,9 +1,9 @@
|
|
1
|
-
export { R as RPCHandler } from '../../shared/server.
|
2
|
-
import '@orpc/client/standard';
|
3
|
-
import '@orpc/standard-server-fetch';
|
4
|
-
import '../../shared/server.BY9sDlwl.mjs';
|
1
|
+
export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.B4eSvRkD.mjs';
|
5
2
|
import '@orpc/client';
|
3
|
+
import '@orpc/client/standard';
|
4
|
+
import '../../shared/server.DnR6v9pj.mjs';
|
6
5
|
import '@orpc/shared';
|
7
|
-
import '../../shared/server.Dba3Iiyp.mjs';
|
8
6
|
import '../../shared/server.BtxZnWJ9.mjs';
|
9
7
|
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.BVwwTHyO.mjs';
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
-
export { FetchHandleResult, 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';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.DJqfB27m.mjs';
|
7
|
+
import '../../shared/server.C-CCcROC.mjs';
|
7
8
|
import '@orpc/standard-server-fetch';
|
8
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.CIbpOMZX.mjs';
|
9
10
|
import '@orpc/client/standard';
|
10
11
|
import '@orpc/client';
|
11
12
|
import '@orpc/contract';
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, 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';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.23VRZIfj.js';
|
7
|
+
import '../../shared/server.BG5ftPWa.js';
|
7
8
|
import '@orpc/standard-server-fetch';
|
8
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DCcCuA52.js';
|
9
10
|
import '@orpc/client/standard';
|
10
11
|
import '@orpc/client';
|
11
12
|
import '@orpc/contract';
|
@@ -1,12 +1,12 @@
|
|
1
|
-
export { 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 '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/server.BY9sDlwl.mjs';
|
6
3
|
import '@orpc/client';
|
7
|
-
import '
|
4
|
+
import '@orpc/client/standard';
|
5
|
+
import '../../shared/server.DnR6v9pj.mjs';
|
8
6
|
import '../../shared/server.BtxZnWJ9.mjs';
|
9
7
|
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.BVwwTHyO.mjs';
|
10
10
|
|
11
11
|
function createMiddleware(handler, ...[options]) {
|
12
12
|
return async (c, next) => {
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.mjs';
|
2
|
-
export { FetchHandleResult, 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';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.DJqfB27m.mjs';
|
7
|
+
import '../../shared/server.C-CCcROC.mjs';
|
7
8
|
import '@orpc/standard-server-fetch';
|
8
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.CIbpOMZX.mjs';
|
9
10
|
import '@orpc/client/standard';
|
10
11
|
import '@orpc/client';
|
11
12
|
import '@orpc/contract';
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FetchHandler } from '../fetch/index.js';
|
2
|
-
export { FetchHandleResult, 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';
|
6
|
-
import { S as StandardHandleOptions } from '../../shared/server.
|
6
|
+
import { S as StandardHandleOptions } from '../../shared/server.23VRZIfj.js';
|
7
|
+
import '../../shared/server.BG5ftPWa.js';
|
7
8
|
import '@orpc/standard-server-fetch';
|
8
|
-
import '../../shared/server.
|
9
|
+
import '../../shared/server.DCcCuA52.js';
|
9
10
|
import '@orpc/client/standard';
|
10
11
|
import '@orpc/client';
|
11
12
|
import '@orpc/contract';
|
@@ -1,12 +1,12 @@
|
|
1
|
-
export { 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 '@orpc/standard-server-fetch';
|
5
|
-
import '../../shared/server.BY9sDlwl.mjs';
|
6
3
|
import '@orpc/client';
|
7
|
-
import '
|
4
|
+
import '@orpc/client/standard';
|
5
|
+
import '../../shared/server.DnR6v9pj.mjs';
|
8
6
|
import '../../shared/server.BtxZnWJ9.mjs';
|
9
7
|
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server-fetch';
|
9
|
+
import '../../shared/server.BVwwTHyO.mjs';
|
10
10
|
|
11
11
|
function serve(handler, ...[options]) {
|
12
12
|
const main = async (req) => {
|
@@ -1,36 +1,53 @@
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
3
1
|
import { C as Context, R as Router } from '../../shared/server.MZvbGc3n.mjs';
|
4
|
-
import {
|
5
|
-
import { S as
|
6
|
-
import {
|
7
|
-
import {
|
2
|
+
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
3
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DJqfB27m.mjs';
|
4
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.C-CCcROC.mjs';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.CIbpOMZX.mjs';
|
8
7
|
import '@orpc/client';
|
9
8
|
import '@orpc/contract';
|
10
9
|
import '@orpc/standard-server';
|
11
10
|
import '@orpc/client/standard';
|
12
11
|
|
13
|
-
type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
14
|
-
/**
|
15
|
-
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
16
|
-
* This is useful for `express.js` middleware.
|
17
|
-
*/
|
18
|
-
originalUrl?: string;
|
19
|
-
};
|
20
|
-
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
21
12
|
type NodeHttpHandleResult = {
|
22
13
|
matched: true;
|
23
14
|
} | {
|
24
15
|
matched: false;
|
25
16
|
};
|
26
|
-
interface
|
27
|
-
|
17
|
+
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
18
|
+
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
28
19
|
}
|
29
|
-
|
30
|
-
|
20
|
+
interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
21
|
+
request: NodeHttpRequest;
|
22
|
+
response: NodeHttpResponse;
|
23
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
24
|
+
}
|
25
|
+
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
26
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, unknown>[];
|
27
|
+
plugins?: NodeHttpHandlerPlugin<T>[];
|
28
|
+
}
|
29
|
+
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
31
30
|
private readonly standardHandler;
|
32
|
-
|
33
|
-
|
31
|
+
private readonly sendStandardResponseOptions;
|
32
|
+
private readonly adapterInterceptors;
|
33
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
34
|
+
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
35
|
+
}
|
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
|
+
|
49
|
+
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
50
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
34
51
|
}
|
35
52
|
|
36
|
-
export { type
|
53
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
@@ -1,36 +1,53 @@
|
|
1
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
-
import { SendStandardResponseOptions } from '@orpc/standard-server-node';
|
3
1
|
import { C as Context, R as Router } from '../../shared/server.MZvbGc3n.js';
|
4
|
-
import {
|
5
|
-
import { S as
|
6
|
-
import {
|
7
|
-
import {
|
2
|
+
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
3
|
+
import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.23VRZIfj.js';
|
4
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BG5ftPWa.js';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.DCcCuA52.js';
|
8
7
|
import '@orpc/client';
|
9
8
|
import '@orpc/contract';
|
10
9
|
import '@orpc/standard-server';
|
11
10
|
import '@orpc/client/standard';
|
12
11
|
|
13
|
-
type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
14
|
-
/**
|
15
|
-
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
16
|
-
* This is useful for `express.js` middleware.
|
17
|
-
*/
|
18
|
-
originalUrl?: string;
|
19
|
-
};
|
20
|
-
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
21
12
|
type NodeHttpHandleResult = {
|
22
13
|
matched: true;
|
23
14
|
} | {
|
24
15
|
matched: false;
|
25
16
|
};
|
26
|
-
interface
|
27
|
-
|
17
|
+
interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
18
|
+
initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
|
28
19
|
}
|
29
|
-
|
30
|
-
|
20
|
+
interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
21
|
+
request: NodeHttpRequest;
|
22
|
+
response: NodeHttpResponse;
|
23
|
+
sendStandardResponseOptions: SendStandardResponseOptions;
|
24
|
+
}
|
25
|
+
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
26
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, unknown>[];
|
27
|
+
plugins?: NodeHttpHandlerPlugin<T>[];
|
28
|
+
}
|
29
|
+
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
31
30
|
private readonly standardHandler;
|
32
|
-
|
33
|
-
|
31
|
+
private readonly sendStandardResponseOptions;
|
32
|
+
private readonly adapterInterceptors;
|
33
|
+
constructor(standardHandler: StandardHandler<T>, options?: NoInfer<NodeHttpHandlerOptions<T>>);
|
34
|
+
handle(request: NodeHttpRequest, response: NodeHttpResponse, ...rest: MaybeOptionalOptions<FriendlyStandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
35
|
+
}
|
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
|
+
|
49
|
+
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
50
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
|
34
51
|
}
|
35
52
|
|
36
|
-
export { type
|
53
|
+
export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
|
@@ -1,32 +1,85 @@
|
|
1
|
-
import {
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
3
|
-
import {
|
4
|
-
import '@orpc/client';
|
5
|
-
import '
|
6
|
-
import '../../shared/server.Dba3Iiyp.mjs';
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.BVwwTHyO.mjs';
|
5
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
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
|
11
|
-
|
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
|
+
|
42
|
+
class NodeHttpHandler {
|
43
|
+
constructor(standardHandler, options = {}) {
|
44
|
+
this.standardHandler = standardHandler;
|
45
|
+
for (const plugin of toArray(options.plugins)) {
|
46
|
+
plugin.initRuntimeAdapter?.(options);
|
47
|
+
}
|
48
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
49
|
+
this.sendStandardResponseOptions = options;
|
50
|
+
}
|
51
|
+
sendStandardResponseOptions;
|
52
|
+
adapterInterceptors;
|
53
|
+
async handle(request, response, ...rest) {
|
54
|
+
return intercept(
|
55
|
+
this.adapterInterceptors,
|
56
|
+
{
|
57
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
58
|
+
request,
|
59
|
+
response,
|
60
|
+
sendStandardResponseOptions: this.sendStandardResponseOptions
|
61
|
+
},
|
62
|
+
async ({ request: request2, response: response2, sendStandardResponseOptions, ...options }) => {
|
63
|
+
const standardRequest = toStandardLazyRequest(request2, response2);
|
64
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
65
|
+
if (!result.matched) {
|
66
|
+
return { matched: false };
|
67
|
+
}
|
68
|
+
await sendStandardResponse(response2, result.response, sendStandardResponseOptions);
|
69
|
+
return { matched: true };
|
70
|
+
}
|
71
|
+
);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
class RPCHandler extends NodeHttpHandler {
|
12
76
|
constructor(router, options = {}) {
|
13
77
|
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
14
78
|
const serializer = new StandardRPCSerializer(jsonSerializer);
|
15
79
|
const matcher = new StandardRPCMatcher();
|
16
80
|
const codec = new StandardRPCCodec(serializer);
|
17
|
-
|
18
|
-
}
|
19
|
-
async handle(req, res, ...[
|
20
|
-
options = {}
|
21
|
-
]) {
|
22
|
-
const standardRequest = toStandardLazyRequest(req, res);
|
23
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
24
|
-
if (!result.matched) {
|
25
|
-
return { matched: false };
|
26
|
-
}
|
27
|
-
await sendStandardResponse(res, result.response, options);
|
28
|
-
return { matched: true };
|
81
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
29
82
|
}
|
30
83
|
}
|
31
84
|
|
32
|
-
export { RPCHandler };
|
85
|
+
export { BodyLimitPlugin, NodeHttpHandler, RPCHandler };
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
export { S as StandardHandleOptions,
|
1
|
+
import { d as StandardCodec, e as StandardParams, f as StandardMatcher, g as StandardMatchResult } from '../../shared/server.DJqfB27m.mjs';
|
2
|
+
export { S as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, b as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, c as StandardHandlerPlugin } from '../../shared/server.DJqfB27m.mjs';
|
3
3
|
import { ORPCError } from '@orpc/client';
|
4
4
|
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
6
|
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.MZvbGc3n.mjs';
|
7
|
-
export { S as StandardRPCHandlerOptions } from '../../shared/server.
|
7
|
+
export { S as StandardRPCHandlerOptions } from '../../shared/server.CIbpOMZX.mjs';
|
8
8
|
import { HTTPPath } from '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
export { S as StandardHandleOptions,
|
1
|
+
import { d as StandardCodec, e as StandardParams, f as StandardMatcher, g as StandardMatchResult } from '../../shared/server.23VRZIfj.js';
|
2
|
+
export { S as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, b as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, c as StandardHandlerPlugin } from '../../shared/server.23VRZIfj.js';
|
3
3
|
import { ORPCError } from '@orpc/client';
|
4
4
|
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
6
|
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.MZvbGc3n.js';
|
7
|
-
export { S as StandardRPCHandlerOptions } from '../../shared/server.
|
7
|
+
export { S as StandardRPCHandlerOptions } from '../../shared/server.DCcCuA52.js';
|
8
8
|
import { HTTPPath } from '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
@@ -1,6 +1,5 @@
|
|
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
|
-
import '../../shared/server.Dba3Iiyp.mjs';
|
5
4
|
import '../../shared/server.BtxZnWJ9.mjs';
|
6
5
|
import '@orpc/contract';
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
import { b as StandardHandlerInterceptorOptions,
|
2
|
-
export { C as CompositeHandlerPlugin } from '../shared/server.P4_D9lKb.mjs';
|
1
|
+
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DJqfB27m.mjs';
|
3
2
|
import { Value } from '@orpc/shared';
|
4
3
|
import { C as Context } from '../shared/server.MZvbGc3n.mjs';
|
5
4
|
import '@orpc/contract';
|
6
5
|
import '@orpc/standard-server';
|
7
6
|
import '@orpc/client';
|
8
7
|
|
9
|
-
interface CORSOptions<
|
10
|
-
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
11
|
-
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
8
|
+
interface CORSOptions<T extends Context> {
|
9
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
10
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
12
11
|
allowMethods?: readonly string[];
|
13
12
|
allowHeaders?: readonly string[];
|
14
13
|
maxAge?: number;
|
15
14
|
credentials?: boolean;
|
16
15
|
exposeHeaders?: readonly string[];
|
17
16
|
}
|
18
|
-
declare class CORSPlugin<
|
17
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
19
18
|
private readonly options;
|
20
|
-
constructor(options?: CORSOptions<
|
21
|
-
init(options: StandardHandlerOptions<
|
19
|
+
constructor(options?: CORSOptions<T>);
|
20
|
+
init(options: StandardHandlerOptions<T>): void;
|
22
21
|
}
|
23
22
|
|
24
23
|
interface ResponseHeadersPluginContext {
|
25
24
|
resHeaders?: Headers;
|
26
25
|
}
|
27
|
-
declare class ResponseHeadersPlugin<
|
28
|
-
init(options: StandardHandlerOptions<
|
26
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
27
|
+
init(options: StandardHandlerOptions<T>): void;
|
29
28
|
}
|
30
29
|
|
31
|
-
export { type CORSOptions, CORSPlugin,
|
30
|
+
export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
import { b as StandardHandlerInterceptorOptions,
|
2
|
-
export { C as CompositeHandlerPlugin } from '../shared/server.CPqNKiJp.js';
|
1
|
+
import { b as StandardHandlerInterceptorOptions, c as StandardHandlerPlugin, a as StandardHandlerOptions } from '../shared/server.23VRZIfj.js';
|
3
2
|
import { Value } from '@orpc/shared';
|
4
3
|
import { C as Context } from '../shared/server.MZvbGc3n.js';
|
5
4
|
import '@orpc/contract';
|
6
5
|
import '@orpc/standard-server';
|
7
6
|
import '@orpc/client';
|
8
7
|
|
9
|
-
interface CORSOptions<
|
10
|
-
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
11
|
-
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<
|
8
|
+
interface CORSOptions<T extends Context> {
|
9
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
10
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<T>]>;
|
12
11
|
allowMethods?: readonly string[];
|
13
12
|
allowHeaders?: readonly string[];
|
14
13
|
maxAge?: number;
|
15
14
|
credentials?: boolean;
|
16
15
|
exposeHeaders?: readonly string[];
|
17
16
|
}
|
18
|
-
declare class CORSPlugin<
|
17
|
+
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
19
18
|
private readonly options;
|
20
|
-
constructor(options?: CORSOptions<
|
21
|
-
init(options: StandardHandlerOptions<
|
19
|
+
constructor(options?: CORSOptions<T>);
|
20
|
+
init(options: StandardHandlerOptions<T>): void;
|
22
21
|
}
|
23
22
|
|
24
23
|
interface ResponseHeadersPluginContext {
|
25
24
|
resHeaders?: Headers;
|
26
25
|
}
|
27
|
-
declare class ResponseHeadersPlugin<
|
28
|
-
init(options: StandardHandlerOptions<
|
26
|
+
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
27
|
+
init(options: StandardHandlerOptions<T>): void;
|
29
28
|
}
|
30
29
|
|
31
|
-
export { type CORSOptions, CORSPlugin,
|
30
|
+
export { type CORSOptions, CORSPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
export { C as CompositeHandlerPlugin } from '../shared/server.Dba3Iiyp.mjs';
|
2
1
|
import { value } from '@orpc/shared';
|
3
2
|
|
4
3
|
class CORSPlugin {
|
@@ -79,14 +78,19 @@ class ResponseHeadersPlugin {
|
|
79
78
|
init(options) {
|
80
79
|
options.rootInterceptors ??= [];
|
81
80
|
options.rootInterceptors.push(async (interceptorOptions) => {
|
82
|
-
const
|
83
|
-
|
84
|
-
|
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
|
+
});
|
85
89
|
if (!result.matched) {
|
86
90
|
return result;
|
87
91
|
}
|
88
92
|
const responseHeaders = result.response.headers;
|
89
|
-
for (const [key, value] of
|
93
|
+
for (const [key, value] of resHeaders) {
|
90
94
|
if (Array.isArray(responseHeaders[key])) {
|
91
95
|
responseHeaders[key].push(value);
|
92
96
|
} else if (responseHeaders[key] !== void 0) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
import { Interceptor
|
2
|
+
import { Interceptor } from '@orpc/shared';
|
3
3
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
4
|
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.js';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
@@ -20,13 +20,10 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandleOptions<T extends Context> {
|
24
24
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
25
|
context: T;
|
29
|
-
}
|
26
|
+
}
|
30
27
|
type StandardHandleResult = {
|
31
28
|
matched: true;
|
32
29
|
response: StandardResponse;
|
@@ -34,12 +31,14 @@ type StandardHandleResult = {
|
|
34
31
|
matched: false;
|
35
32
|
response: undefined;
|
36
33
|
};
|
37
|
-
|
38
|
-
|
34
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
35
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
36
|
+
}
|
37
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
39
38
|
request: StandardLazyRequest;
|
40
|
-
}
|
39
|
+
}
|
41
40
|
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?:
|
41
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
43
42
|
/**
|
44
43
|
* Interceptors at the request level, helpful when you want catch errors
|
45
44
|
*/
|
@@ -57,19 +56,11 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
57
56
|
declare class StandardHandler<T extends Context> {
|
58
57
|
private readonly matcher;
|
59
58
|
private readonly codec;
|
60
|
-
private readonly
|
61
|
-
private readonly
|
59
|
+
private readonly interceptors;
|
60
|
+
private readonly clientInterceptors;
|
61
|
+
private readonly rootInterceptors;
|
62
62
|
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest,
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
63
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
73
64
|
}
|
74
65
|
|
75
|
-
export {
|
66
|
+
export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import { ORPCError } from '@orpc/client';
|
2
|
+
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
3
|
+
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DnR6v9pj.mjs';
|
4
|
+
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
5
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
6
|
+
import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
|
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
|
+
|
54
|
+
class FetchHandler {
|
55
|
+
constructor(standardHandler, options = {}) {
|
56
|
+
this.standardHandler = standardHandler;
|
57
|
+
for (const plugin of toArray(options.plugins)) {
|
58
|
+
plugin.initRuntimeAdapter?.(options);
|
59
|
+
}
|
60
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
61
|
+
this.toFetchResponseOptions = options;
|
62
|
+
}
|
63
|
+
toFetchResponseOptions;
|
64
|
+
adapterInterceptors;
|
65
|
+
async handle(request, ...rest) {
|
66
|
+
return intercept(
|
67
|
+
this.adapterInterceptors,
|
68
|
+
{
|
69
|
+
...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
|
70
|
+
request,
|
71
|
+
toFetchResponseOptions: this.toFetchResponseOptions
|
72
|
+
},
|
73
|
+
async ({ request: request2, toFetchResponseOptions, ...options }) => {
|
74
|
+
const standardRequest = toStandardLazyRequest(request2);
|
75
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
76
|
+
if (!result.matched) {
|
77
|
+
return result;
|
78
|
+
}
|
79
|
+
return {
|
80
|
+
matched: true,
|
81
|
+
response: toFetchResponse(result.response, toFetchResponseOptions)
|
82
|
+
};
|
83
|
+
}
|
84
|
+
);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
class RPCHandler extends FetchHandler {
|
89
|
+
constructor(router, options = {}) {
|
90
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
91
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
92
|
+
const matcher = new StandardRPCMatcher();
|
93
|
+
const codec = new StandardRPCCodec(serializer);
|
94
|
+
super(new StandardHandler(router, matcher, codec, options), options);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
export { BodyLimitPlugin as B, FetchHandler as F, RPCHandler as R };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.MZvbGc3n.js';
|
2
|
+
import { S as StandardHandleOptions } from './server.23VRZIfj.js';
|
3
|
+
|
4
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
|
+
context?: T;
|
6
|
+
} : {
|
7
|
+
context: T;
|
8
|
+
});
|
9
|
+
|
10
|
+
export type { FriendlyStandardHandleOptions as F };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { C as Context } from './server.MZvbGc3n.mjs';
|
2
|
+
import { S as StandardHandleOptions } from './server.DJqfB27m.mjs';
|
3
|
+
|
4
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
5
|
+
context?: T;
|
6
|
+
} : {
|
7
|
+
context: T;
|
8
|
+
});
|
9
|
+
|
10
|
+
export type { FriendlyStandardHandleOptions as F };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
2
|
import { C as Context } from './server.MZvbGc3n.mjs';
|
3
|
-
import { a as StandardHandlerOptions } from './server.
|
3
|
+
import { a as StandardHandlerOptions } from './server.DJqfB27m.mjs';
|
4
4
|
|
5
5
|
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
6
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
2
|
import { C as Context } from './server.MZvbGc3n.js';
|
3
|
-
import { a as StandardHandlerOptions } from './server.
|
3
|
+
import { a as StandardHandlerOptions } from './server.23VRZIfj.js';
|
4
4
|
|
5
5
|
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
6
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
import { Interceptor
|
2
|
+
import { Interceptor } from '@orpc/shared';
|
3
3
|
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
4
|
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.MZvbGc3n.mjs';
|
5
5
|
import { ORPCError } from '@orpc/client';
|
@@ -20,13 +20,10 @@ interface StandardCodec {
|
|
20
20
|
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
21
|
}
|
22
22
|
|
23
|
-
|
23
|
+
interface StandardHandleOptions<T extends Context> {
|
24
24
|
prefix?: HTTPPath;
|
25
|
-
} & (Record<never, never> extends T ? {
|
26
|
-
context?: T;
|
27
|
-
} : {
|
28
25
|
context: T;
|
29
|
-
}
|
26
|
+
}
|
30
27
|
type StandardHandleResult = {
|
31
28
|
matched: true;
|
32
29
|
response: StandardResponse;
|
@@ -34,12 +31,14 @@ type StandardHandleResult = {
|
|
34
31
|
matched: false;
|
35
32
|
response: undefined;
|
36
33
|
};
|
37
|
-
|
38
|
-
|
34
|
+
interface StandardHandlerPlugin<TContext extends Context> {
|
35
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
36
|
+
}
|
37
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
|
39
38
|
request: StandardLazyRequest;
|
40
|
-
}
|
39
|
+
}
|
41
40
|
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
-
plugins?:
|
41
|
+
plugins?: StandardHandlerPlugin<TContext>[];
|
43
42
|
/**
|
44
43
|
* Interceptors at the request level, helpful when you want catch errors
|
45
44
|
*/
|
@@ -57,19 +56,11 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
57
56
|
declare class StandardHandler<T extends Context> {
|
58
57
|
private readonly matcher;
|
59
58
|
private readonly codec;
|
60
|
-
private readonly
|
61
|
-
private readonly
|
59
|
+
private readonly interceptors;
|
60
|
+
private readonly clientInterceptors;
|
61
|
+
private readonly rootInterceptors;
|
62
62
|
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
-
handle(request: StandardLazyRequest,
|
64
|
-
}
|
65
|
-
|
66
|
-
interface HandlerPlugin<TContext extends Context> {
|
67
|
-
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
-
}
|
69
|
-
declare class CompositeHandlerPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
-
private readonly plugins;
|
71
|
-
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
-
init(options: StandardHandlerOptions<TContext>): void;
|
63
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
73
64
|
}
|
74
65
|
|
75
|
-
export {
|
66
|
+
export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardHandlerPlugin as c, type StandardCodec as d, type StandardParams as e, type StandardMatcher as f, type StandardMatchResult as g, type StandardHandleResult as h, StandardHandler as i };
|
@@ -1,51 +1,53 @@
|
|
1
1
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
|
-
import {
|
3
|
-
import { C as CompositeHandlerPlugin } from './server.Dba3Iiyp.mjs';
|
2
|
+
import { toArray, intercept, parseEmptyableJSON } from '@orpc/shared';
|
4
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';
|
5
4
|
|
6
5
|
class StandardHandler {
|
7
6
|
constructor(router, matcher, codec, options) {
|
8
7
|
this.matcher = matcher;
|
9
8
|
this.codec = codec;
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
for (const plugin of toArray(options.plugins)) {
|
10
|
+
plugin.init?.(options);
|
11
|
+
}
|
12
|
+
this.interceptors = toArray(options.interceptors);
|
13
|
+
this.clientInterceptors = toArray(options.clientInterceptors);
|
14
|
+
this.rootInterceptors = toArray(options.rootInterceptors);
|
13
15
|
this.matcher.init(router);
|
14
16
|
}
|
15
|
-
|
16
|
-
|
17
|
+
interceptors;
|
18
|
+
clientInterceptors;
|
19
|
+
rootInterceptors;
|
20
|
+
handle(request, options) {
|
17
21
|
return intercept(
|
18
|
-
this.
|
19
|
-
{
|
20
|
-
request,
|
21
|
-
...options,
|
22
|
-
context: options?.context ?? {}
|
23
|
-
// context is optional only when all fields are optional so we can safely force it to have a context
|
24
|
-
},
|
22
|
+
this.rootInterceptors,
|
23
|
+
{ ...options, request },
|
25
24
|
async (interceptorOptions) => {
|
26
25
|
let isDecoding = false;
|
27
26
|
try {
|
28
27
|
return await intercept(
|
29
|
-
this.
|
28
|
+
this.interceptors,
|
30
29
|
interceptorOptions,
|
31
|
-
async (
|
32
|
-
const method =
|
33
|
-
const url =
|
34
|
-
|
35
|
-
|
30
|
+
async ({ request: request2, context, prefix }) => {
|
31
|
+
const method = request2.method;
|
32
|
+
const url = request2.url;
|
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, "")}`);
|
36
38
|
if (!match) {
|
37
39
|
return { matched: false, response: void 0 };
|
38
40
|
}
|
39
41
|
const client = createProcedureClient(match.procedure, {
|
40
|
-
context
|
42
|
+
context,
|
41
43
|
path: match.path,
|
42
|
-
interceptors: this.
|
44
|
+
interceptors: this.clientInterceptors
|
43
45
|
});
|
44
46
|
isDecoding = true;
|
45
|
-
const input = await this.codec.decode(
|
47
|
+
const input = await this.codec.decode(request2, match.params, match.procedure);
|
46
48
|
isDecoding = false;
|
47
|
-
const lastEventId = Array.isArray(
|
48
|
-
const output = await client(input, { signal:
|
49
|
+
const lastEventId = Array.isArray(request2.headers["last-event-id"]) ? request2.headers["last-event-id"].at(-1) : request2.headers["last-event-id"];
|
50
|
+
const output = await client(input, { signal: request2.signal, lastEventId });
|
49
51
|
const response = this.codec.encode(output, match.procedure);
|
50
52
|
return {
|
51
53
|
matched: true,
|
@@ -54,7 +56,7 @@ class StandardHandler {
|
|
54
56
|
}
|
55
57
|
);
|
56
58
|
} catch (e) {
|
57
|
-
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
59
|
+
const error = isDecoding && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
58
60
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
59
61
|
cause: e
|
60
62
|
}) : toORPCError(e);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.0-beta.
|
4
|
+
"version": "1.0.0-beta.4",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -58,15 +58,15 @@
|
|
58
58
|
"next": ">=14.0.0"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@orpc/client": "1.0.0-beta.
|
62
|
-
"@orpc/
|
63
|
-
"@orpc/
|
64
|
-
"@orpc/standard-server": "1.0.0-beta.
|
65
|
-
"@orpc/standard-server-
|
66
|
-
"@orpc/
|
61
|
+
"@orpc/client": "1.0.0-beta.4",
|
62
|
+
"@orpc/shared": "1.0.0-beta.4",
|
63
|
+
"@orpc/standard-server": "1.0.0-beta.4",
|
64
|
+
"@orpc/standard-server-fetch": "1.0.0-beta.4",
|
65
|
+
"@orpc/standard-server-node": "1.0.0-beta.4",
|
66
|
+
"@orpc/contract": "1.0.0-beta.4"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
|
-
"
|
69
|
+
"supertest": "^7.0.0"
|
70
70
|
},
|
71
71
|
"scripts": {
|
72
72
|
"build": "unbuild",
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
|
2
|
-
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
-
import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.BY9sDlwl.mjs';
|
4
|
-
|
5
|
-
class RPCHandler {
|
6
|
-
standardHandler;
|
7
|
-
constructor(router, options = {}) {
|
8
|
-
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
9
|
-
const serializer = new StandardRPCSerializer(jsonSerializer);
|
10
|
-
const matcher = new StandardRPCMatcher();
|
11
|
-
const codec = new StandardRPCCodec(serializer);
|
12
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
13
|
-
}
|
14
|
-
async handle(request, ...[
|
15
|
-
options = {}
|
16
|
-
]) {
|
17
|
-
const standardRequest = toStandardLazyRequest(request);
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, options);
|
19
|
-
if (!result.matched) {
|
20
|
-
return result;
|
21
|
-
}
|
22
|
-
return {
|
23
|
-
matched: true,
|
24
|
-
response: toFetchResponse(result.response, options)
|
25
|
-
};
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
export { RPCHandler as R };
|