@orpc/server 0.0.0-next.c788572 → 0.0.0-next.c854c60
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 +4 -5
- package/dist/adapters/aws-lambda/index.d.mts +45 -0
- package/dist/adapters/aws-lambda/index.d.ts +45 -0
- package/dist/adapters/aws-lambda/index.mjs +41 -0
- package/dist/adapters/bun-ws/index.d.mts +35 -0
- package/dist/adapters/bun-ws/index.d.ts +35 -0
- package/dist/adapters/bun-ws/index.mjs +46 -0
- package/dist/adapters/crossws/index.d.mts +30 -0
- package/dist/adapters/crossws/index.d.ts +30 -0
- package/dist/adapters/crossws/index.mjs +46 -0
- package/dist/adapters/fetch/index.d.mts +17 -9
- package/dist/adapters/fetch/index.d.ts +17 -9
- package/dist/adapters/fetch/index.mjs +8 -3
- package/dist/adapters/message-port/index.d.mts +28 -0
- package/dist/adapters/message-port/index.d.ts +28 -0
- package/dist/adapters/message-port/index.mjs +41 -0
- package/dist/adapters/node/index.d.mts +17 -9
- package/dist/adapters/node/index.d.ts +17 -9
- package/dist/adapters/node/index.mjs +8 -3
- package/dist/adapters/standard/index.d.mts +4 -4
- package/dist/adapters/standard/index.d.ts +4 -4
- package/dist/adapters/standard/index.mjs +4 -5
- package/dist/adapters/websocket/index.d.mts +27 -0
- package/dist/adapters/websocket/index.d.ts +27 -0
- package/dist/adapters/websocket/index.mjs +39 -0
- package/dist/adapters/ws/index.d.mts +28 -0
- package/dist/adapters/ws/index.d.ts +28 -0
- package/dist/adapters/ws/index.mjs +39 -0
- package/dist/index.d.mts +12 -7
- package/dist/index.d.ts +12 -7
- package/dist/index.mjs +24 -7
- package/dist/plugins/index.d.mts +13 -13
- package/dist/plugins/index.d.ts +13 -13
- package/dist/plugins/index.mjs +10 -9
- package/dist/shared/{server.D5fBlF9j.d.ts → server.-ACo36I0.d.ts} +9 -9
- package/dist/shared/{server.CuD15qZB.d.ts → server.BPAWobQg.d.ts} +3 -9
- package/dist/shared/{server.CN0534_m.d.mts → server.Bd52nNaH.d.mts} +3 -9
- package/dist/shared/{server.DjgtLwKi.d.mts → server.BliFSTnG.d.mts} +2 -2
- package/dist/shared/{server.qf03T-Xn.mjs → server.CHvOkcM3.mjs} +11 -15
- package/dist/shared/{server.DPWk5pjW.d.mts → server.DD2C4ujN.d.mts} +4 -4
- package/dist/shared/{server.DPWk5pjW.d.ts → server.DD2C4ujN.d.ts} +4 -4
- package/dist/shared/{server.BVwwTHyO.mjs → server.DZ5BIITo.mjs} +1 -1
- package/dist/shared/{server.DY7OKEoj.d.mts → server.Dq8xr7PQ.d.mts} +9 -9
- package/dist/shared/{server.CjlA3NKP.d.ts → server.IG2MjhrD.d.ts} +2 -2
- package/package.json +56 -8
@@ -1,9 +1,9 @@
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
2
|
-
import { Interceptor,
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DD2C4ujN.mjs';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
|
-
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
6
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
4
|
+
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.Dq8xr7PQ.mjs';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BliFSTnG.mjs';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.Bd52nNaH.mjs';
|
7
7
|
import '@orpc/client';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/standard-server';
|
@@ -27,7 +27,7 @@ interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardH
|
|
27
27
|
sendStandardResponseOptions: SendStandardResponseOptions;
|
28
28
|
}
|
29
29
|
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
30
|
-
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult
|
30
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, Promise<NodeHttpHandleResult>>[];
|
31
31
|
plugins?: NodeHttpHandlerPlugin<T>[];
|
32
32
|
}
|
33
33
|
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
@@ -55,15 +55,23 @@ declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugi
|
|
55
55
|
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
56
56
|
}
|
57
57
|
|
58
|
+
type RPCHandlerOptions<T extends Context> = NodeHttpHandlerOptions<T> & StandardRPCHandlerOptions<T> & {
|
59
|
+
/**
|
60
|
+
* Enables or disables the StrictGetMethodPlugin.
|
61
|
+
*
|
62
|
+
* @default true
|
63
|
+
*/
|
64
|
+
strictGetMethodPluginEnabled?: boolean;
|
65
|
+
};
|
58
66
|
/**
|
59
67
|
* RPC Handler for Node.js HTTP Server
|
60
68
|
*
|
61
69
|
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
62
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
70
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
63
71
|
*/
|
64
72
|
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
65
|
-
constructor(router: Router<any, T>, options?: NoInfer<
|
73
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
66
74
|
}
|
67
75
|
|
68
76
|
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
69
|
-
export type { BodyLimitPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin };
|
77
|
+
export type { BodyLimitPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
2
|
-
import { Interceptor,
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DD2C4ujN.js';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
|
4
|
-
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
6
|
-
import { S as StandardRPCHandlerOptions } from '../../shared/server.
|
4
|
+
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.-ACo36I0.js';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.IG2MjhrD.js';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.BPAWobQg.js';
|
7
7
|
import '@orpc/client';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/standard-server';
|
@@ -27,7 +27,7 @@ interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardH
|
|
27
27
|
sendStandardResponseOptions: SendStandardResponseOptions;
|
28
28
|
}
|
29
29
|
interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
|
30
|
-
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult
|
30
|
+
adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, Promise<NodeHttpHandleResult>>[];
|
31
31
|
plugins?: NodeHttpHandlerPlugin<T>[];
|
32
32
|
}
|
33
33
|
declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
|
@@ -55,15 +55,23 @@ declare class BodyLimitPlugin<T extends Context> implements NodeHttpHandlerPlugi
|
|
55
55
|
initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
|
56
56
|
}
|
57
57
|
|
58
|
+
type RPCHandlerOptions<T extends Context> = NodeHttpHandlerOptions<T> & StandardRPCHandlerOptions<T> & {
|
59
|
+
/**
|
60
|
+
* Enables or disables the StrictGetMethodPlugin.
|
61
|
+
*
|
62
|
+
* @default true
|
63
|
+
*/
|
64
|
+
strictGetMethodPluginEnabled?: boolean;
|
65
|
+
};
|
58
66
|
/**
|
59
67
|
* RPC Handler for Node.js HTTP Server
|
60
68
|
*
|
61
69
|
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
62
|
-
* @see {@link https://orpc.unnoq.com/docs/
|
70
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/http HTTP Adapter Docs}
|
63
71
|
*/
|
64
72
|
declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
|
65
|
-
constructor(router: Router<any, T>, options?: NoInfer<
|
73
|
+
constructor(router: Router<any, T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
66
74
|
}
|
67
75
|
|
68
76
|
export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
|
69
|
-
export type { BodyLimitPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin };
|
77
|
+
export type { BodyLimitPluginOptions, NodeHttpHandleResult, NodeHttpHandlerInterceptorOptions, NodeHttpHandlerOptions, NodeHttpHandlerPlugin, RPCHandlerOptions };
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
2
2
|
import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
|
3
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@orpc/standard-server-node';
|
4
|
-
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
4
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
5
|
+
import '@orpc/standard-server';
|
5
6
|
import '@orpc/contract';
|
6
|
-
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.
|
7
|
+
import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.CHvOkcM3.mjs';
|
7
8
|
import '@orpc/client/standard';
|
8
9
|
import '@orpc/standard-server/batch';
|
9
|
-
import '../../shared/server.BW-nUGgA.mjs';
|
10
|
+
import { S as StrictGetMethodPlugin } from '../../shared/server.BW-nUGgA.mjs';
|
10
11
|
import '../../shared/server.DG7Tamti.mjs';
|
11
12
|
|
12
13
|
class BodyLimitPlugin {
|
@@ -83,6 +84,10 @@ class NodeHttpHandler {
|
|
83
84
|
|
84
85
|
class RPCHandler extends NodeHttpHandler {
|
85
86
|
constructor(router, options = {}) {
|
87
|
+
if (options.strictGetMethodPluginEnabled ?? true) {
|
88
|
+
options.plugins ??= [];
|
89
|
+
options.plugins.push(new StrictGetMethodPlugin());
|
90
|
+
}
|
86
91
|
super(new StandardRPCHandler(router, options), options);
|
87
92
|
}
|
88
93
|
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.
|
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.
|
1
|
+
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.Dq8xr7PQ.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.Dq8xr7PQ.mjs';
|
3
3
|
import { ORPCError, HTTPPath } from '@orpc/client';
|
4
4
|
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
-
import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.
|
7
|
-
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.
|
6
|
+
import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.DD2C4ujN.mjs';
|
7
|
+
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.Bd52nNaH.mjs';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.
|
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.
|
1
|
+
import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.-ACo36I0.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.-ACo36I0.js';
|
3
3
|
import { ORPCError, HTTPPath } from '@orpc/client';
|
4
4
|
import { StandardRPCSerializer } from '@orpc/client/standard';
|
5
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
6
|
-
import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.
|
7
|
-
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.
|
6
|
+
import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.DD2C4ujN.js';
|
7
|
+
export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.BPAWobQg.js';
|
8
8
|
import '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
@@ -1,8 +1,7 @@
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.
|
1
|
+
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.CHvOkcM3.mjs';
|
2
2
|
import '@orpc/client/standard';
|
3
|
-
import '@orpc/shared';
|
4
|
-
import '@orpc/standard-server/batch';
|
5
3
|
import '@orpc/client';
|
6
|
-
import '
|
7
|
-
import '@orpc/
|
4
|
+
import '@orpc/shared';
|
5
|
+
import '@orpc/standard-server';
|
8
6
|
import '../../shared/server.DG7Tamti.mjs';
|
7
|
+
import '@orpc/contract';
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { C as Context, R as Router } from '../../shared/server.DD2C4ujN.mjs';
|
3
|
+
import { i as StandardHandler } from '../../shared/server.Dq8xr7PQ.mjs';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BliFSTnG.mjs';
|
5
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.Bd52nNaH.mjs';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server';
|
9
|
+
import '@orpc/client/standard';
|
10
|
+
|
11
|
+
declare class experimental_WebsocketHandler<T extends Context> {
|
12
|
+
private readonly standardHandler;
|
13
|
+
constructor(standardHandler: StandardHandler<T>);
|
14
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): void;
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* RPC Handler for Websocket adapter
|
19
|
+
*
|
20
|
+
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
21
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
22
|
+
*/
|
23
|
+
declare class experimental_RPCHandler<T extends Context> extends experimental_WebsocketHandler<T> {
|
24
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
25
|
+
}
|
26
|
+
|
27
|
+
export { experimental_RPCHandler, experimental_WebsocketHandler };
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { C as Context, R as Router } from '../../shared/server.DD2C4ujN.js';
|
3
|
+
import { i as StandardHandler } from '../../shared/server.-ACo36I0.js';
|
4
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.IG2MjhrD.js';
|
5
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.BPAWobQg.js';
|
6
|
+
import '@orpc/client';
|
7
|
+
import '@orpc/contract';
|
8
|
+
import '@orpc/standard-server';
|
9
|
+
import '@orpc/client/standard';
|
10
|
+
|
11
|
+
declare class experimental_WebsocketHandler<T extends Context> {
|
12
|
+
private readonly standardHandler;
|
13
|
+
constructor(standardHandler: StandardHandler<T>);
|
14
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): void;
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* RPC Handler for Websocket adapter
|
19
|
+
*
|
20
|
+
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
21
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
22
|
+
*/
|
23
|
+
declare class experimental_RPCHandler<T extends Context> extends experimental_WebsocketHandler<T> {
|
24
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
25
|
+
}
|
26
|
+
|
27
|
+
export { experimental_RPCHandler, experimental_WebsocketHandler };
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
|
+
import '@orpc/client';
|
5
|
+
import '@orpc/standard-server';
|
6
|
+
import '@orpc/contract';
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CHvOkcM3.mjs';
|
8
|
+
import '@orpc/client/standard';
|
9
|
+
import '../../shared/server.DG7Tamti.mjs';
|
10
|
+
|
11
|
+
class experimental_WebsocketHandler {
|
12
|
+
constructor(standardHandler) {
|
13
|
+
this.standardHandler = standardHandler;
|
14
|
+
}
|
15
|
+
upgrade(ws, ...rest) {
|
16
|
+
const peer = new ServerPeer(ws.send.bind(ws));
|
17
|
+
ws.addEventListener("message", async (event) => {
|
18
|
+
const message = event.data instanceof Blob ? await event.data.arrayBuffer() : event.data;
|
19
|
+
const [id, request] = await peer.message(message);
|
20
|
+
if (!request) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
const options = resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest));
|
24
|
+
const { response } = await this.standardHandler.handle({ ...request, body: () => Promise.resolve(request.body) }, options);
|
25
|
+
await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
|
26
|
+
});
|
27
|
+
ws.addEventListener("close", () => {
|
28
|
+
peer.close();
|
29
|
+
});
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
class experimental_RPCHandler extends experimental_WebsocketHandler {
|
34
|
+
constructor(router, options = {}) {
|
35
|
+
super(new StandardRPCHandler(router, options));
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
export { experimental_RPCHandler, experimental_WebsocketHandler };
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { WebSocket } from 'ws';
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.DD2C4ujN.mjs';
|
4
|
+
import { i as StandardHandler } from '../../shared/server.Dq8xr7PQ.mjs';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.BliFSTnG.mjs';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.Bd52nNaH.mjs';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
|
12
|
+
declare class experimental_WsHandler<T extends Context> {
|
13
|
+
private readonly standardHandler;
|
14
|
+
constructor(standardHandler: StandardHandler<T>);
|
15
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): Promise<void>;
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* RPC Handler for ws (node ws) adapter
|
20
|
+
*
|
21
|
+
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
22
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
23
|
+
*/
|
24
|
+
declare class experimental_RPCHandler<T extends Context> extends experimental_WsHandler<T> {
|
25
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
26
|
+
}
|
27
|
+
|
28
|
+
export { experimental_RPCHandler, experimental_WsHandler };
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { WebSocket } from 'ws';
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.DD2C4ujN.js';
|
4
|
+
import { i as StandardHandler } from '../../shared/server.-ACo36I0.js';
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.IG2MjhrD.js';
|
6
|
+
import { S as StandardRPCHandlerOptions } from '../../shared/server.BPAWobQg.js';
|
7
|
+
import '@orpc/client';
|
8
|
+
import '@orpc/contract';
|
9
|
+
import '@orpc/standard-server';
|
10
|
+
import '@orpc/client/standard';
|
11
|
+
|
12
|
+
declare class experimental_WsHandler<T extends Context> {
|
13
|
+
private readonly standardHandler;
|
14
|
+
constructor(standardHandler: StandardHandler<T>);
|
15
|
+
upgrade(ws: Pick<WebSocket, 'addEventListener' | 'send'>, ...rest: MaybeOptionalOptions<Omit<FriendlyStandardHandleOptions<T>, 'prefix'>>): Promise<void>;
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* RPC Handler for ws (node ws) adapter
|
20
|
+
*
|
21
|
+
* @see {@link https://orpc.unnoq.com/docs/rpc-handler RPC Handler Docs}
|
22
|
+
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket Websocket Adapter Docs}
|
23
|
+
*/
|
24
|
+
declare class experimental_RPCHandler<T extends Context> extends experimental_WsHandler<T> {
|
25
|
+
constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T>>);
|
26
|
+
}
|
27
|
+
|
28
|
+
export { experimental_RPCHandler, experimental_WsHandler };
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import { ServerPeer } from '@orpc/standard-server-peer';
|
3
|
+
import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.DZ5BIITo.mjs';
|
4
|
+
import '@orpc/client';
|
5
|
+
import '@orpc/standard-server';
|
6
|
+
import '@orpc/contract';
|
7
|
+
import { b as StandardRPCHandler } from '../../shared/server.CHvOkcM3.mjs';
|
8
|
+
import '@orpc/client/standard';
|
9
|
+
import '../../shared/server.DG7Tamti.mjs';
|
10
|
+
|
11
|
+
class experimental_WsHandler {
|
12
|
+
constructor(standardHandler) {
|
13
|
+
this.standardHandler = standardHandler;
|
14
|
+
}
|
15
|
+
async upgrade(ws, ...rest) {
|
16
|
+
const peer = new ServerPeer(ws.send.bind(ws));
|
17
|
+
ws.addEventListener("message", async (event) => {
|
18
|
+
const message = Array.isArray(event.data) ? await new Blob(event.data).arrayBuffer() : event.data;
|
19
|
+
const [id, request] = await peer.message(message);
|
20
|
+
if (!request) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
const options = resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest));
|
24
|
+
const { response } = await this.standardHandler.handle({ ...request, body: () => Promise.resolve(request.body) }, options);
|
25
|
+
await peer.response(id, response ?? { status: 404, headers: {}, body: "No procedure matched" });
|
26
|
+
});
|
27
|
+
ws.addEventListener("close", () => {
|
28
|
+
peer.close();
|
29
|
+
});
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
class experimental_RPCHandler extends experimental_WsHandler {
|
34
|
+
constructor(router, options = {}) {
|
35
|
+
super(new StandardRPCHandler(router, options));
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
export { experimental_RPCHandler, experimental_WsHandler };
|
package/dist/index.d.mts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientPromiseResult } from '@orpc/client';
|
2
2
|
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
3
|
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
|
4
4
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
5
5
|
import { ThrowableError, IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
-
export { IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
-
import { C as Context, P as Procedure, M as Middleware, O as ORPCErrorConstructorMap, a as MergedInitialContext, b as MergedCurrentContext, c as MapInputMiddleware, d as CreateProcedureClientOptions, e as ProcedureClient, A as AnyMiddleware, L as Lazyable, f as AnyRouter, g as Lazy, h as AnyProcedure, i as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.
|
8
|
-
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, n as LAZY_SYMBOL, o as LazyMeta, w as MiddlewareNextFn, t as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, s as MiddlewareResult, k as ORPCErrorConstructorMapItem, j as ORPCErrorConstructorMapItemOptions, F as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, l as createORPCErrorConstructorMap, G as createProcedureClient, r as getLazyMeta, q as isLazy, E as isProcedure, p as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.
|
6
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
+
import { C as Context, P as Procedure, M as Middleware, O as ORPCErrorConstructorMap, a as MergedInitialContext, b as MergedCurrentContext, c as MapInputMiddleware, d as CreateProcedureClientOptions, e as ProcedureClient, A as AnyMiddleware, L as Lazyable, f as AnyRouter, g as Lazy, h as AnyProcedure, i as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.DD2C4ujN.mjs';
|
8
|
+
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, n as LAZY_SYMBOL, o as LazyMeta, w as MiddlewareNextFn, t as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, s as MiddlewareResult, k as ORPCErrorConstructorMapItem, j as ORPCErrorConstructorMapItemOptions, F as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, l as createORPCErrorConstructorMap, G as createProcedureClient, r as getLazyMeta, q as isLazy, E as isProcedure, p as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.DD2C4ujN.mjs';
|
9
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
10
|
|
11
11
|
type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
|
@@ -479,14 +479,14 @@ interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Co
|
|
479
479
|
* @info Pass second argument to map the input.
|
480
480
|
* @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
|
481
481
|
*/
|
482
|
-
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext,
|
482
|
+
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
483
483
|
/**
|
484
484
|
* Concatenates two middlewares.
|
485
485
|
*
|
486
486
|
* @info Pass second argument to map the input.
|
487
487
|
* @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
|
488
488
|
*/
|
489
|
-
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<
|
489
|
+
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<UInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
490
490
|
}
|
491
491
|
declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
492
492
|
|
@@ -789,6 +789,11 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
789
789
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
790
790
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
791
791
|
|
792
|
+
/**
|
793
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the router.
|
794
|
+
*/
|
795
|
+
declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
|
796
|
+
|
792
797
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
793
798
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
794
799
|
dedupeLeading: boolean;
|
@@ -825,5 +830,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
825
830
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
826
831
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
827
832
|
|
828
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
833
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
829
834
|
export type { AccessibleLazyRouter, ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProceduresOptions, UnactionableError, UnlaziedRouter };
|
package/dist/index.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientPromiseResult } from '@orpc/client';
|
2
2
|
export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
|
3
3
|
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
|
4
4
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
5
5
|
import { ThrowableError, IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
6
|
-
export { IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
-
import { C as Context, P as Procedure, M as Middleware, O as ORPCErrorConstructorMap, a as MergedInitialContext, b as MergedCurrentContext, c as MapInputMiddleware, d as CreateProcedureClientOptions, e as ProcedureClient, A as AnyMiddleware, L as Lazyable, f as AnyRouter, g as Lazy, h as AnyProcedure, i as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.
|
8
|
-
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, n as LAZY_SYMBOL, o as LazyMeta, w as MiddlewareNextFn, t as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, s as MiddlewareResult, k as ORPCErrorConstructorMapItem, j as ORPCErrorConstructorMapItemOptions, F as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, l as createORPCErrorConstructorMap, G as createProcedureClient, r as getLazyMeta, q as isLazy, E as isProcedure, p as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.
|
6
|
+
export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
|
+
import { C as Context, P as Procedure, M as Middleware, O as ORPCErrorConstructorMap, a as MergedInitialContext, b as MergedCurrentContext, c as MapInputMiddleware, d as CreateProcedureClientOptions, e as ProcedureClient, A as AnyMiddleware, L as Lazyable, f as AnyRouter, g as Lazy, h as AnyProcedure, i as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.DD2C4ujN.js';
|
8
|
+
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, n as LAZY_SYMBOL, o as LazyMeta, w as MiddlewareNextFn, t as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, s as MiddlewareResult, k as ORPCErrorConstructorMapItem, j as ORPCErrorConstructorMapItemOptions, F as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, l as createORPCErrorConstructorMap, G as createProcedureClient, r as getLazyMeta, q as isLazy, E as isProcedure, p as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.DD2C4ujN.js';
|
9
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
10
|
|
11
11
|
type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
|
@@ -479,14 +479,14 @@ interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Co
|
|
479
479
|
* @info Pass second argument to map the input.
|
480
480
|
* @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
|
481
481
|
*/
|
482
|
-
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext,
|
482
|
+
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
483
483
|
/**
|
484
484
|
* Concatenates two middlewares.
|
485
485
|
*
|
486
486
|
* @info Pass second argument to map the input.
|
487
487
|
* @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
|
488
488
|
*/
|
489
|
-
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<
|
489
|
+
concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<UInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
490
490
|
}
|
491
491
|
declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
492
492
|
|
@@ -789,6 +789,11 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
789
789
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
790
790
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
791
791
|
|
792
|
+
/**
|
793
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the router.
|
794
|
+
*/
|
795
|
+
declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
|
796
|
+
|
792
797
|
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
793
798
|
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
794
799
|
dedupeLeading: boolean;
|
@@ -825,5 +830,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
825
830
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
826
831
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
827
832
|
|
828
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
833
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|
829
834
|
export type { AccessibleLazyRouter, ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProceduresOptions, UnactionableError, UnlaziedRouter };
|
package/dist/index.mjs
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
1
|
+
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter, fallbackContractConfig } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure
|
4
|
-
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures,
|
3
|
+
import { P as Procedure, b as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, u as unlazy, g as getRouter, i as isProcedure, d as isLazy, f as createAssertedLazyProcedure } from './shared/server.DG7Tamti.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, p as call, r as createAccessibleLazyRouter, a as createContractedProcedure, h as createORPCErrorConstructorMap, q as getHiddenRouterContract, j as getLazyMeta, n as isStartWithMiddlewares, m as mergeCurrentContext, o as mergeMiddlewares, k as middlewareOutputFn, w as resolveContractProcedures, t as traverseContractProcedures, x as unlazyRouter, v as validateORPCError } from './shared/server.DG7Tamti.mjs';
|
5
5
|
import { toORPCError } from '@orpc/client';
|
6
6
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
|
-
|
7
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
8
|
+
export { EventPublisher, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
8
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
9
10
|
|
10
11
|
const DEFAULT_CONFIG = {
|
@@ -50,6 +51,9 @@ function createActionableClient(client) {
|
|
50
51
|
try {
|
51
52
|
return [null, await client(input)];
|
52
53
|
} catch (error) {
|
54
|
+
if (error instanceof Error && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_")) {
|
55
|
+
throw error;
|
56
|
+
}
|
53
57
|
return [toORPCError(error).toJSON(), void 0];
|
54
58
|
}
|
55
59
|
};
|
@@ -444,12 +448,25 @@ function implement(contract, config = {}) {
|
|
444
448
|
return impl;
|
445
449
|
}
|
446
450
|
|
451
|
+
function inferRPCMethodFromRouter(router) {
|
452
|
+
return async (_, path) => {
|
453
|
+
const { default: procedure } = await unlazy(getRouter(router, path));
|
454
|
+
if (!isProcedure(procedure)) {
|
455
|
+
throw new Error(
|
456
|
+
`[inferRPCMethodFromRouter] No valid procedure found at path "${path.join(".")}". This may happen when the router is not properly configured.`
|
457
|
+
);
|
458
|
+
}
|
459
|
+
const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
|
460
|
+
return method === "HEAD" ? "GET" : method;
|
461
|
+
};
|
462
|
+
}
|
463
|
+
|
447
464
|
function createRouterClient(router, ...rest) {
|
448
465
|
if (isProcedure(router)) {
|
449
|
-
const caller = createProcedureClient(router,
|
466
|
+
const caller = createProcedureClient(router, resolveMaybeOptionalOptions(rest));
|
450
467
|
return caller;
|
451
468
|
}
|
452
|
-
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router),
|
469
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createAssertedLazyProcedure(router), resolveMaybeOptionalOptions(rest)) : {};
|
453
470
|
const recursive = new Proxy(procedureCaller, {
|
454
471
|
get(target, key) {
|
455
472
|
if (typeof key !== "string") {
|
@@ -468,4 +485,4 @@ function createRouterClient(router, ...rest) {
|
|
468
485
|
return recursive;
|
469
486
|
}
|
470
487
|
|
471
|
-
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
488
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createActionableClient, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isLazy, isProcedure, lazy, os, setHiddenRouterContract, unlazy };
|