@orpc/server 0.0.0-next.aac73c2 → 0.0.0-next.ac2c329

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.
Files changed (36) hide show
  1. package/dist/adapters/fetch/index.d.mts +14 -10
  2. package/dist/adapters/fetch/index.d.ts +14 -10
  3. package/dist/adapters/fetch/index.mjs +104 -8
  4. package/dist/adapters/node/index.d.mts +14 -10
  5. package/dist/adapters/node/index.d.ts +14 -10
  6. package/dist/adapters/node/index.mjs +17 -12
  7. package/dist/adapters/standard/index.d.mts +4 -4
  8. package/dist/adapters/standard/index.d.ts +4 -4
  9. package/dist/adapters/standard/index.mjs +6 -4
  10. package/dist/index.d.mts +27 -27
  11. package/dist/index.d.ts +27 -27
  12. package/dist/index.mjs +7 -7
  13. package/dist/plugins/index.d.mts +100 -6
  14. package/dist/plugins/index.d.ts +100 -6
  15. package/dist/plugins/index.mjs +147 -2
  16. package/dist/shared/server.B5yVxwZh.d.mts +17 -0
  17. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  18. package/dist/shared/server.By38lRwX.d.ts +17 -0
  19. package/dist/shared/{server.CjWkNG6l.mjs → server.C37gDhSZ.mjs} +18 -24
  20. package/dist/shared/{server.DNoBYd3E.d.ts → server.ClO23hLW.d.mts} +15 -8
  21. package/dist/shared/{server.CBh2jYIX.d.mts → server.Cqam9L0P.d.mts} +2 -2
  22. package/dist/shared/{server.B0kTII1X.d.ts → server.CuXY46Yy.d.ts} +2 -2
  23. package/dist/shared/{server.D9QduY95.mjs → server.DFuJLDuo.mjs} +43 -14
  24. package/dist/shared/{server.CYBq7eu_.d.mts → server.DQJX4Gnf.d.mts} +2 -2
  25. package/dist/shared/{server.CYBq7eu_.d.ts → server.DQJX4Gnf.d.ts} +2 -2
  26. package/dist/shared/{server.DHBkTokD.d.mts → server.DsVSuKTu.d.ts} +15 -8
  27. package/package.json +7 -21
  28. package/dist/adapters/hono/index.d.mts +0 -22
  29. package/dist/adapters/hono/index.d.ts +0 -22
  30. package/dist/adapters/hono/index.mjs +0 -32
  31. package/dist/adapters/next/index.d.mts +0 -29
  32. package/dist/adapters/next/index.d.ts +0 -29
  33. package/dist/adapters/next/index.mjs +0 -29
  34. package/dist/shared/server.DatI0acO.d.mts +0 -8
  35. package/dist/shared/server.Et1O6Bm7.mjs +0 -98
  36. package/dist/shared/server.uEHRR3Pg.d.ts +0 -8
@@ -1,14 +1,21 @@
1
- import { C as Context, R as Router } from '../../shared/server.CYBq7eu_.mjs';
2
- import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DHBkTokD.mjs';
3
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
4
- import { F as FriendlyStandardHandleOptions } from '../../shared/server.CBh2jYIX.mjs';
1
+ import { C as Context, R as Router } from '../../shared/server.DQJX4Gnf.mjs';
2
+ import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
3
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.ClO23hLW.mjs';
4
+ import { F as FriendlyStandardHandleOptions } from '../../shared/server.Cqam9L0P.mjs';
5
5
  import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
6
- import { S as StandardRPCHandlerOptions } from '../../shared/server.DatI0acO.mjs';
6
+ import { S as StandardRPCHandlerOptions } from '../../shared/server.B5yVxwZh.mjs';
7
7
  import '@orpc/client';
8
8
  import '@orpc/contract';
9
9
  import '@orpc/standard-server';
10
10
  import '@orpc/client/standard';
11
11
 
12
+ interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
13
+ initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
14
+ }
15
+ declare class CompositeFetchHandlerPlugin<T extends Context, TPlugin extends FetchHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements FetchHandlerPlugin<T> {
16
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
17
+ }
18
+
12
19
  type FetchHandleResult = {
13
20
  matched: true;
14
21
  response: Response;
@@ -16,15 +23,12 @@ type FetchHandleResult = {
16
23
  matched: false;
17
24
  response: undefined;
18
25
  };
19
- interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
20
- initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
21
- }
22
26
  interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
23
27
  request: Request;
24
28
  toFetchResponseOptions: ToFetchResponseOptions;
25
29
  }
26
30
  interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
27
- adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, unknown>[];
31
+ adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, ThrowableError>[];
28
32
  plugins?: FetchHandlerPlugin<T>[];
29
33
  }
30
34
  declare class FetchHandler<T extends Context> {
@@ -51,4 +55,4 @@ declare class RPCHandler<T extends Context> extends FetchHandler<T> {
51
55
  constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
52
56
  }
53
57
 
54
- export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
58
+ export { BodyLimitPlugin, type BodyLimitPluginOptions, CompositeFetchHandlerPlugin, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
@@ -1,14 +1,21 @@
1
- import { C as Context, R as Router } from '../../shared/server.CYBq7eu_.js';
2
- import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DNoBYd3E.js';
3
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
4
- import { F as FriendlyStandardHandleOptions } from '../../shared/server.B0kTII1X.js';
1
+ import { C as Context, R as Router } from '../../shared/server.DQJX4Gnf.js';
2
+ import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
3
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DsVSuKTu.js';
4
+ import { F as FriendlyStandardHandleOptions } from '../../shared/server.CuXY46Yy.js';
5
5
  import { ToFetchResponseOptions } from '@orpc/standard-server-fetch';
6
- import { S as StandardRPCHandlerOptions } from '../../shared/server.uEHRR3Pg.js';
6
+ import { S as StandardRPCHandlerOptions } from '../../shared/server.By38lRwX.js';
7
7
  import '@orpc/client';
8
8
  import '@orpc/contract';
9
9
  import '@orpc/standard-server';
10
10
  import '@orpc/client/standard';
11
11
 
12
+ interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
13
+ initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
14
+ }
15
+ declare class CompositeFetchHandlerPlugin<T extends Context, TPlugin extends FetchHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements FetchHandlerPlugin<T> {
16
+ initRuntimeAdapter(options: FetchHandlerOptions<T>): void;
17
+ }
18
+
12
19
  type FetchHandleResult = {
13
20
  matched: true;
14
21
  response: Response;
@@ -16,15 +23,12 @@ type FetchHandleResult = {
16
23
  matched: false;
17
24
  response: undefined;
18
25
  };
19
- interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
20
- initRuntimeAdapter?(options: FetchHandlerOptions<T>): void;
21
- }
22
26
  interface FetchHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
23
27
  request: Request;
24
28
  toFetchResponseOptions: ToFetchResponseOptions;
25
29
  }
26
30
  interface FetchHandlerOptions<T extends Context> extends ToFetchResponseOptions {
27
- adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, unknown>[];
31
+ adapterInterceptors?: Interceptor<FetchHandlerInterceptorOptions<T>, FetchHandleResult, ThrowableError>[];
28
32
  plugins?: FetchHandlerPlugin<T>[];
29
33
  }
30
34
  declare class FetchHandler<T extends Context> {
@@ -51,4 +55,4 @@ declare class RPCHandler<T extends Context> extends FetchHandler<T> {
51
55
  constructor(router: Router<any, T>, options?: NoInfer<FetchHandlerOptions<T> & StandardRPCHandlerOptions<T>>);
52
56
  }
53
57
 
54
- export { BodyLimitPlugin, type BodyLimitPluginOptions, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
58
+ export { BodyLimitPlugin, type BodyLimitPluginOptions, CompositeFetchHandlerPlugin, type FetchHandleResult, FetchHandler, type FetchHandlerInterceptorOptions, type FetchHandlerOptions, type FetchHandlerPlugin, RPCHandler };
@@ -1,9 +1,105 @@
1
- export { B as BodyLimitPlugin, F as FetchHandler, R as RPCHandler } from '../../shared/server.Et1O6Bm7.mjs';
2
- import '@orpc/client';
3
- import '@orpc/client/standard';
4
- import '../../shared/server.D9QduY95.mjs';
5
- import '@orpc/shared';
6
- import '../../shared/server.CjWkNG6l.mjs';
1
+ import { ORPCError } from '@orpc/client';
2
+ import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
3
+ import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
4
+ import { r as resolveFriendlyStandardHandleOptions } from '../../shared/server.BVwwTHyO.mjs';
7
5
  import '@orpc/contract';
8
- import '@orpc/standard-server-fetch';
9
- import '../../shared/server.BVwwTHyO.mjs';
6
+ import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.DFuJLDuo.mjs';
7
+ import '@orpc/client/standard';
8
+ import '@orpc/standard-server/batch';
9
+ import '../../shared/server.BW-nUGgA.mjs';
10
+ import '../../shared/server.C37gDhSZ.mjs';
11
+
12
+ class BodyLimitPlugin {
13
+ maxBodySize;
14
+ constructor(options) {
15
+ this.maxBodySize = options.maxBodySize;
16
+ }
17
+ initRuntimeAdapter(options) {
18
+ options.adapterInterceptors ??= [];
19
+ options.adapterInterceptors.push(async (options2) => {
20
+ if (!options2.request.body) {
21
+ return options2.next();
22
+ }
23
+ let currentBodySize = 0;
24
+ const rawReader = options2.request.body.getReader();
25
+ const reader = new ReadableStream({
26
+ start: async (controller) => {
27
+ try {
28
+ if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
29
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
30
+ return;
31
+ }
32
+ while (true) {
33
+ const { done, value } = await rawReader.read();
34
+ if (done) {
35
+ break;
36
+ }
37
+ currentBodySize += value.length;
38
+ if (currentBodySize > this.maxBodySize) {
39
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
40
+ break;
41
+ }
42
+ controller.enqueue(value);
43
+ }
44
+ } finally {
45
+ controller.close();
46
+ }
47
+ }
48
+ });
49
+ const requestInit = { body: reader, duplex: "half" };
50
+ return options2.next({
51
+ ...options2,
52
+ request: new Request(options2.request, requestInit)
53
+ });
54
+ });
55
+ }
56
+ }
57
+
58
+ class CompositeFetchHandlerPlugin extends CompositeStandardHandlerPlugin {
59
+ initRuntimeAdapter(options) {
60
+ for (const plugin of this.plugins) {
61
+ plugin.initRuntimeAdapter?.(options);
62
+ }
63
+ }
64
+ }
65
+
66
+ class FetchHandler {
67
+ constructor(standardHandler, options = {}) {
68
+ this.standardHandler = standardHandler;
69
+ const plugin = new CompositeFetchHandlerPlugin(options.plugins);
70
+ plugin.initRuntimeAdapter(options);
71
+ this.adapterInterceptors = toArray(options.adapterInterceptors);
72
+ this.toFetchResponseOptions = options;
73
+ }
74
+ toFetchResponseOptions;
75
+ adapterInterceptors;
76
+ async handle(request, ...rest) {
77
+ return intercept(
78
+ this.adapterInterceptors,
79
+ {
80
+ ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
81
+ request,
82
+ toFetchResponseOptions: this.toFetchResponseOptions
83
+ },
84
+ async ({ request: request2, toFetchResponseOptions, ...options }) => {
85
+ const standardRequest = toStandardLazyRequest(request2);
86
+ const result = await this.standardHandler.handle(standardRequest, options);
87
+ if (!result.matched) {
88
+ return result;
89
+ }
90
+ return {
91
+ matched: true,
92
+ response: toFetchResponse(result.response, toFetchResponseOptions)
93
+ };
94
+ }
95
+ );
96
+ }
97
+ }
98
+
99
+ class RPCHandler extends FetchHandler {
100
+ constructor(router, options = {}) {
101
+ super(new StandardRPCHandler(router, options), options);
102
+ }
103
+ }
104
+
105
+ export { BodyLimitPlugin, CompositeFetchHandlerPlugin, FetchHandler, RPCHandler };
@@ -1,29 +1,33 @@
1
- import { C as Context, R as Router } from '../../shared/server.CYBq7eu_.mjs';
1
+ import { C as Context, R as Router } from '../../shared/server.DQJX4Gnf.mjs';
2
+ import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
2
3
  import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
3
- import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DHBkTokD.mjs';
4
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
5
- import { F as FriendlyStandardHandleOptions } from '../../shared/server.CBh2jYIX.mjs';
6
- import { S as StandardRPCHandlerOptions } from '../../shared/server.DatI0acO.mjs';
4
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.ClO23hLW.mjs';
5
+ import { F as FriendlyStandardHandleOptions } from '../../shared/server.Cqam9L0P.mjs';
6
+ import { S as StandardRPCHandlerOptions } from '../../shared/server.B5yVxwZh.mjs';
7
7
  import '@orpc/client';
8
8
  import '@orpc/contract';
9
9
  import '@orpc/standard-server';
10
10
  import '@orpc/client/standard';
11
11
 
12
+ interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
13
+ initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
14
+ }
15
+ declare class CompositeNodeHttpHandlerPlugin<T extends Context, TPlugin extends NodeHttpHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements NodeHttpHandlerPlugin<T> {
16
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
17
+ }
18
+
12
19
  type NodeHttpHandleResult = {
13
20
  matched: true;
14
21
  } | {
15
22
  matched: false;
16
23
  };
17
- interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
18
- initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
19
- }
20
24
  interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
21
25
  request: NodeHttpRequest;
22
26
  response: NodeHttpResponse;
23
27
  sendStandardResponseOptions: SendStandardResponseOptions;
24
28
  }
25
29
  interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
26
- adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, unknown>[];
30
+ adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, ThrowableError>[];
27
31
  plugins?: NodeHttpHandlerPlugin<T>[];
28
32
  }
29
33
  declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
@@ -50,4 +54,4 @@ declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
50
54
  constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
51
55
  }
52
56
 
53
- export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
57
+ export { BodyLimitPlugin, type BodyLimitPluginOptions, CompositeNodeHttpHandlerPlugin, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
@@ -1,29 +1,33 @@
1
- import { C as Context, R as Router } from '../../shared/server.CYBq7eu_.js';
1
+ import { C as Context, R as Router } from '../../shared/server.DQJX4Gnf.js';
2
+ import { Interceptor, ThrowableError, MaybeOptionalOptions } from '@orpc/shared';
2
3
  import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@orpc/standard-server-node';
3
- import { c as StandardHandlerPlugin, S as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DNoBYd3E.js';
4
- import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
5
- import { F as FriendlyStandardHandleOptions } from '../../shared/server.B0kTII1X.js';
6
- import { S as StandardRPCHandlerOptions } from '../../shared/server.uEHRR3Pg.js';
4
+ import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, g as StandardHandleOptions, i as StandardHandler } from '../../shared/server.DsVSuKTu.js';
5
+ import { F as FriendlyStandardHandleOptions } from '../../shared/server.CuXY46Yy.js';
6
+ import { S as StandardRPCHandlerOptions } from '../../shared/server.By38lRwX.js';
7
7
  import '@orpc/client';
8
8
  import '@orpc/contract';
9
9
  import '@orpc/standard-server';
10
10
  import '@orpc/client/standard';
11
11
 
12
+ interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
13
+ initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
14
+ }
15
+ declare class CompositeNodeHttpHandlerPlugin<T extends Context, TPlugin extends NodeHttpHandlerPlugin<T>> extends CompositeStandardHandlerPlugin<T, TPlugin> implements NodeHttpHandlerPlugin<T> {
16
+ initRuntimeAdapter(options: NodeHttpHandlerOptions<T>): void;
17
+ }
18
+
12
19
  type NodeHttpHandleResult = {
13
20
  matched: true;
14
21
  } | {
15
22
  matched: false;
16
23
  };
17
- interface NodeHttpHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
18
- initRuntimeAdapter?(options: NodeHttpHandlerOptions<T>): void;
19
- }
20
24
  interface NodeHttpHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
21
25
  request: NodeHttpRequest;
22
26
  response: NodeHttpResponse;
23
27
  sendStandardResponseOptions: SendStandardResponseOptions;
24
28
  }
25
29
  interface NodeHttpHandlerOptions<T extends Context> extends SendStandardResponseOptions {
26
- adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, unknown>[];
30
+ adapterInterceptors?: Interceptor<NodeHttpHandlerInterceptorOptions<T>, NodeHttpHandleResult, ThrowableError>[];
27
31
  plugins?: NodeHttpHandlerPlugin<T>[];
28
32
  }
29
33
  declare class NodeHttpHandler<T extends Context> implements NodeHttpHandler<T> {
@@ -50,4 +54,4 @@ declare class RPCHandler<T extends Context> extends NodeHttpHandler<T> {
50
54
  constructor(router: Router<any, T>, options?: NoInfer<StandardRPCHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
51
55
  }
52
56
 
53
- export { BodyLimitPlugin, type BodyLimitPluginOptions, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
57
+ export { BodyLimitPlugin, type BodyLimitPluginOptions, CompositeNodeHttpHandlerPlugin, type NodeHttpHandleResult, NodeHttpHandler, type NodeHttpHandlerInterceptorOptions, type NodeHttpHandlerOptions, type NodeHttpHandlerPlugin, RPCHandler };
@@ -2,10 +2,12 @@ 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
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.D9QduY95.mjs';
7
- import '../../shared/server.CjWkNG6l.mjs';
8
5
  import '@orpc/contract';
6
+ import { C as CompositeStandardHandlerPlugin, b as StandardRPCHandler } from '../../shared/server.DFuJLDuo.mjs';
7
+ import '@orpc/client/standard';
8
+ import '@orpc/standard-server/batch';
9
+ import '../../shared/server.BW-nUGgA.mjs';
10
+ import '../../shared/server.C37gDhSZ.mjs';
9
11
 
10
12
  class BodyLimitPlugin {
11
13
  maxBodySize;
@@ -39,12 +41,19 @@ class BodyLimitPlugin {
39
41
  }
40
42
  }
41
43
 
44
+ class CompositeNodeHttpHandlerPlugin extends CompositeStandardHandlerPlugin {
45
+ initRuntimeAdapter(options) {
46
+ for (const plugin of this.plugins) {
47
+ plugin.initRuntimeAdapter?.(options);
48
+ }
49
+ }
50
+ }
51
+
42
52
  class NodeHttpHandler {
43
53
  constructor(standardHandler, options = {}) {
44
54
  this.standardHandler = standardHandler;
45
- for (const plugin of toArray(options.plugins)) {
46
- plugin.initRuntimeAdapter?.(options);
47
- }
55
+ const plugin = new CompositeNodeHttpHandlerPlugin(options.plugins);
56
+ plugin.initRuntimeAdapter(options);
48
57
  this.adapterInterceptors = toArray(options.adapterInterceptors);
49
58
  this.sendStandardResponseOptions = options;
50
59
  }
@@ -74,12 +83,8 @@ class NodeHttpHandler {
74
83
 
75
84
  class RPCHandler extends NodeHttpHandler {
76
85
  constructor(router, options = {}) {
77
- const jsonSerializer = new StandardRPCJsonSerializer(options);
78
- const serializer = new StandardRPCSerializer(jsonSerializer);
79
- const matcher = new StandardRPCMatcher();
80
- const codec = new StandardRPCCodec(serializer);
81
- super(new StandardHandler(router, matcher, codec, options), options);
86
+ super(new StandardRPCHandler(router, options), options);
82
87
  }
83
88
  }
84
89
 
85
- export { BodyLimitPlugin, NodeHttpHandler, RPCHandler };
90
+ export { BodyLimitPlugin, CompositeNodeHttpHandlerPlugin, NodeHttpHandler, RPCHandler };
@@ -1,10 +1,10 @@
1
- import { d as StandardCodec, e as StandardParams, f as StandardMatcher, g as StandardMatchResult } from '../../shared/server.DHBkTokD.mjs';
2
- export { S as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, b as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, c as StandardHandlerPlugin } from '../../shared/server.DHBkTokD.mjs';
1
+ import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.ClO23hLW.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.ClO23hLW.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 { A as AnyProcedure, a as AnyRouter } from '../../shared/server.CYBq7eu_.mjs';
7
- export { S as StandardRPCHandlerOptions } from '../../shared/server.DatI0acO.mjs';
6
+ import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.DQJX4Gnf.mjs';
7
+ export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.B5yVxwZh.mjs';
8
8
  import '@orpc/contract';
9
9
  import '@orpc/shared';
10
10
 
@@ -1,10 +1,10 @@
1
- import { d as StandardCodec, e as StandardParams, f as StandardMatcher, g as StandardMatchResult } from '../../shared/server.DNoBYd3E.js';
2
- export { S as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, b as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, c as StandardHandlerPlugin } from '../../shared/server.DNoBYd3E.js';
1
+ import { c as StandardCodec, d as StandardParams, e as StandardMatcher, f as StandardMatchResult } from '../../shared/server.DsVSuKTu.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.DsVSuKTu.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 { A as AnyProcedure, a as AnyRouter } from '../../shared/server.CYBq7eu_.js';
7
- export { S as StandardRPCHandlerOptions } from '../../shared/server.uEHRR3Pg.js';
6
+ import { h as AnyProcedure, f as AnyRouter } from '../../shared/server.DQJX4Gnf.js';
7
+ export { a as StandardRPCHandler, S as StandardRPCHandlerOptions } from '../../shared/server.By38lRwX.js';
8
8
  import '@orpc/contract';
9
9
  import '@orpc/shared';
10
10
 
@@ -1,6 +1,8 @@
1
- export { S as StandardHandler, a as StandardRPCCodec, b as StandardRPCMatcher } from '../../shared/server.D9QduY95.mjs';
2
- import '@orpc/client';
1
+ export { C as CompositeStandardHandlerPlugin, S as StandardHandler, a as StandardRPCCodec, b as StandardRPCHandler, c as StandardRPCMatcher } from '../../shared/server.DFuJLDuo.mjs';
2
+ import '@orpc/client/standard';
3
3
  import '@orpc/shared';
4
- import '../../shared/server.CjWkNG6l.mjs';
4
+ import '@orpc/standard-server/batch';
5
+ import '@orpc/client';
6
+ import '../../shared/server.BW-nUGgA.mjs';
5
7
  import '@orpc/contract';
6
- import '@orpc/client/standard';
8
+ import '../../shared/server.C37gDhSZ.mjs';
package/dist/index.d.mts CHANGED
@@ -1,28 +1,28 @@
1
1
  import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
2
- export { ORPCError, isDefinedError, safe } from '@orpc/client';
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
- export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
5
- import { C as Context, b as Procedure, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, e as MapInputMiddleware, f as CreateProcedureClientOptions, g as ProcedureClient, h as AnyMiddleware, L as Lazyable, a as AnyRouter, i as Lazy, A as AnyProcedure, j as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.CYBq7eu_.mjs';
6
- export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, x as MiddlewareNextFn, w as MiddlewareNextFnOptions, z as MiddlewareOptions, y as MiddlewareOutputFn, t as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, P as ProcedureClientInterceptorOptions, E as ProcedureDef, D as ProcedureHandlerOptions, n as createORPCErrorConstructorMap, G as createProcedureClient, s as getLazyMeta, r as isLazy, F as isProcedure, q as lazy, m as mergeCurrentContext, B as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.CYBq7eu_.mjs';
7
- import { IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
8
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
4
+ export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
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.DQJX4Gnf.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.DQJX4Gnf.mjs';
9
9
  export { getEventMeta, withEventMeta } from '@orpc/standard-server';
10
10
 
11
- type ActionableError<T extends Error> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
11
+ type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
12
12
  defined: true;
13
13
  } : ORPCErrorJSON<string, unknown> & {
14
14
  defined: false;
15
15
  };
16
16
  type UnactionableError<T> = T extends {
17
17
  defined: true;
18
- } & ORPCErrorJSON<infer U, infer V> ? ORPCError<U, V> : Error;
18
+ } & ORPCErrorJSON<infer U, infer V> ? ORPCError<U, V> : ThrowableError;
19
19
  type ActionableClientRest<TInput> = [input: TInput] | (undefined extends TInput ? [input?: TInput] : [input: TInput]);
20
20
  type ActionableClientResult<TOutput, TError extends ORPCErrorJSON<any, any>> = [error: null, data: TOutput] | [error: TError, data: undefined];
21
21
  interface ActionableClient<TInput, TOutput, TError extends ORPCErrorJSON<any, any>> {
22
22
  (...rest: ActionableClientRest<TInput>): Promise<ActionableClientResult<TOutput, TError>>;
23
23
  }
24
24
  type ProcedureActionableClient<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = ActionableClient<InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ActionableError<ErrorFromErrorMap<TErrorMap>>>;
25
- declare function createActionableClient<TInput, TOutput, TError extends Error>(client: Client<Record<never, never>, TInput, TOutput, TError>): ActionableClient<TInput, TOutput, ActionableError<TError>>;
25
+ declare function createActionableClient<TInput, TOutput, TError>(client: Client<Record<never, never>, TInput, TOutput, TError>): ActionableClient<TInput, TOutput, ActionableError<TError>>;
26
26
 
27
27
  declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> {
28
28
  errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
@@ -76,7 +76,7 @@ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedR
76
76
  interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
77
77
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
78
78
  'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
79
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
79
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
80
80
  'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
81
81
  'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
82
82
  'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
@@ -92,7 +92,7 @@ interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContex
92
92
  interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
93
93
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
94
94
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
95
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
95
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
96
96
  'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
97
97
  'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
98
98
  'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
@@ -102,8 +102,8 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
102
102
  interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
103
103
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
104
104
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
105
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
106
- 'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
105
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
106
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
107
107
  'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
108
108
  'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
109
109
  'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
@@ -112,7 +112,7 @@ interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentCon
112
112
  interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
113
113
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
114
114
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
115
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
115
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
116
116
  'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
117
117
  'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
118
118
  'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
@@ -121,8 +121,8 @@ interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentCo
121
121
  interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
122
122
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
123
123
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
124
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
125
- 'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
124
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
125
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
126
126
  'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
127
127
  'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
128
128
  'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
@@ -130,7 +130,7 @@ interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurr
130
130
  interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
131
131
  '~orpc': EnhanceRouterOptions<TErrorMap>;
132
132
  'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
133
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
133
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
134
134
  'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
135
135
  'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
136
136
  'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
@@ -141,8 +141,8 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
141
141
 
142
142
  interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
143
143
  mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
144
- concat<UOutContext extends Context, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
145
- concat<UOutContext extends Context, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<TInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
144
+ concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
145
+ 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<TInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
146
146
  }
147
147
  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>;
148
148
 
@@ -177,10 +177,10 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
177
177
  */
178
178
  $route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
179
179
  $input<U extends AnySchema>(initialInputSchema?: U): Builder<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap, TMeta>;
180
- middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
180
+ middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
181
181
  middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
182
182
  errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
183
- use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
183
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
184
184
  meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
185
185
  route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
186
186
  input<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
@@ -222,13 +222,13 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
222
222
  */
223
223
  interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
224
224
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
225
- 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
226
- 'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
225
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
226
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
227
227
  'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
228
228
  }
229
229
 
230
230
  interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
231
- use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
231
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
232
232
  router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
233
233
  lazy<U extends Router<T, TInitialContext>>(loader: () => Promise<{
234
234
  default: U;
@@ -239,9 +239,9 @@ type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TIn
239
239
  });
240
240
 
241
241
  interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
242
- middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
242
+ middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
243
243
  middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, InferContractRouterMeta<T>>;
244
- use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
244
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
245
245
  router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
246
246
  lazy<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
247
247
  default: U;
@@ -283,7 +283,7 @@ declare function call<TInitialContext extends Context, TInputSchema extends AnyS
283
283
  type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
284
284
  [K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
285
285
  };
286
- declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): RouterClient<T, TClientContext>;
286
+ declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): RouterClient<T, TClientContext>;
287
287
 
288
288
  declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
289
289
  declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;