@orpc/server 2.0.0-beta.4 → 2.0.0-beta.41
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 +97 -94
- package/dist/adapters/aws-lambda/index.d.mts +50 -0
- package/dist/adapters/aws-lambda/index.d.ts +50 -0
- package/dist/adapters/aws-lambda/index.mjs +39 -0
- package/dist/adapters/crossws/index.d.mts +21 -12
- package/dist/adapters/crossws/index.d.ts +21 -12
- package/dist/adapters/crossws/index.mjs +14 -10
- package/dist/adapters/fastify/index.d.mts +42 -0
- package/dist/adapters/fastify/index.d.ts +42 -0
- package/dist/adapters/fastify/index.mjs +39 -0
- package/dist/adapters/fetch/index.d.mts +21 -114
- package/dist/adapters/fetch/index.d.ts +21 -114
- package/dist/adapters/fetch/index.mjs +20 -182
- package/dist/adapters/message-port/index.d.mts +23 -20
- package/dist/adapters/message-port/index.d.ts +23 -20
- package/dist/adapters/message-port/index.mjs +31 -34
- package/dist/adapters/node/index.d.mts +19 -96
- package/dist/adapters/node/index.d.ts +19 -96
- package/dist/adapters/node/index.mjs +19 -157
- package/dist/adapters/standard/index.d.mts +91 -17
- package/dist/adapters/standard/index.d.ts +91 -17
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/adapters/standard-peer/index.d.mts +6 -11
- package/dist/adapters/standard-peer/index.d.ts +6 -11
- package/dist/adapters/standard-peer/index.mjs +10 -2
- package/dist/adapters/websocket/index.d.mts +45 -29
- package/dist/adapters/websocket/index.d.ts +45 -29
- package/dist/adapters/websocket/index.mjs +39 -28
- package/dist/extensions/callable.d.mts +5 -5
- package/dist/extensions/callable.d.ts +5 -5
- package/dist/extensions/callable.mjs +2 -2
- package/dist/helpers/index.d.mts +23 -6
- package/dist/helpers/index.d.ts +23 -6
- package/dist/helpers/index.mjs +13 -5
- package/dist/index.d.mts +332 -37
- package/dist/index.d.ts +332 -37
- package/dist/index.mjs +141 -65
- package/dist/plugins/index.d.mts +255 -31
- package/dist/plugins/index.d.ts +255 -31
- package/dist/plugins/index.mjs +559 -38
- package/dist/shared/server.1ExWFMze.mjs +69 -0
- package/dist/shared/{server.CjOb6ItT.mjs → server.AVQWL-DI.mjs} +1 -1
- package/dist/shared/{server.BL22TloH.d.mts → server.BEdOJs6S.d.mts} +41 -62
- package/dist/shared/{server.BL22TloH.d.ts → server.BEdOJs6S.d.ts} +41 -62
- package/dist/shared/{server.GDpX6Df8.mjs → server.BFEVk-EI.mjs} +164 -70
- package/dist/shared/{server.BwHnWUuN.mjs → server.BgvqVW_v.mjs} +25 -20
- package/dist/shared/server.BllfVJLm.d.mts +34 -0
- package/dist/shared/server.COfbQ0D8.d.ts +34 -0
- package/dist/shared/{server.DBANIheG.d.ts → server.CVO0hWyj.d.mts} +24 -13
- package/dist/shared/{server.BsNNjG5J.d.mts → server.DD1roZl9.d.mts} +32 -20
- package/dist/shared/server.DFEuNUt4.d.ts +14 -0
- package/dist/shared/{server.DJIkub_t.d.mts → server.DJNkZPfD.d.ts} +24 -13
- package/dist/shared/{server.Pa0F03f_.d.ts → server.DZeVx8K9.d.ts} +32 -20
- package/dist/shared/{server.CrlKQucM.mjs → server.FEqy7Hrj.mjs} +25 -53
- package/dist/shared/server.UG_xdTub.d.mts +14 -0
- package/package.json +48 -14
- package/dist/shared/server.CX4vUnDk.mjs +0 -11
- package/dist/shared/server.Cj5lgPuG.d.mts +0 -66
- package/dist/shared/server.D_QauotT.mjs +0 -30
- package/dist/shared/server.d_2NS3g5.d.ts +0 -66
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
|
|
2
|
-
import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.
|
|
2
|
+
import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BEdOJs6S.mjs';
|
|
3
3
|
|
|
4
|
-
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any
|
|
4
|
+
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
|
|
5
5
|
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
6
6
|
};
|
|
7
|
-
type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap
|
|
7
|
+
type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : {
|
|
8
8
|
[K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
|
|
9
9
|
};
|
|
10
10
|
type AnyRouter = Router<any>;
|
|
@@ -12,50 +12,62 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $>
|
|
|
12
12
|
/**
|
|
13
13
|
* Infer all initial context of the router.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
16
|
-
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* **Note**: A procedure is a router too.
|
|
17
|
+
*
|
|
18
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
|
|
17
19
|
*/
|
|
18
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any
|
|
20
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
|
|
19
21
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Infer all current context of the router.
|
|
23
25
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* **Note**: A procedure is a router too.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
|
|
26
30
|
*/
|
|
27
|
-
type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any
|
|
31
|
+
type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
|
|
28
32
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
|
|
29
33
|
};
|
|
30
34
|
/**
|
|
31
|
-
* Infer all router inputs
|
|
35
|
+
* Infer all router inputs.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* **Note**: A procedure is a router too.
|
|
32
39
|
*
|
|
33
|
-
* @
|
|
34
|
-
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
40
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
|
|
35
41
|
*/
|
|
36
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any
|
|
42
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
37
43
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
38
44
|
};
|
|
39
45
|
/**
|
|
40
|
-
* Infer all router outputs
|
|
46
|
+
* Infer all router outputs.
|
|
41
47
|
*
|
|
42
|
-
* @
|
|
43
|
-
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* **Note**: A procedure is a router too.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
|
|
44
52
|
*/
|
|
45
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any
|
|
53
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
46
54
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
47
55
|
};
|
|
48
56
|
/**
|
|
49
57
|
* Infer the union of throwable errors for entire router.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
|
|
50
60
|
*/
|
|
51
|
-
type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap
|
|
61
|
+
type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
52
62
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
|
|
53
63
|
}[keyof T];
|
|
54
64
|
/**
|
|
55
65
|
* Infer throwable errors for each procedure, preserving the router shape.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
|
|
56
68
|
*/
|
|
57
|
-
type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap
|
|
69
|
+
type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
58
70
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
|
|
59
71
|
};
|
|
60
72
|
|
|
61
|
-
export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R,
|
|
73
|
+
export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest } from '@standard-server/core';
|
|
3
|
+
import { C as Context } from './server.BEdOJs6S.js';
|
|
4
|
+
import { a as StandardHandlerHandleOptions } from './server.DJNkZPfD.js';
|
|
5
|
+
|
|
6
|
+
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
7
|
+
context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
8
|
+
} : {
|
|
9
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
+
});
|
|
11
|
+
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
12
|
+
|
|
13
|
+
export { resolveFriendlyStandardHandlerHandleOptions as r };
|
|
14
|
+
export type { FriendlyStandardHandlerHandleOptions as F };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { OrderablePlugin,
|
|
3
|
-
import { StandardLazyRequest, StandardResponse } from '@
|
|
4
|
-
import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.
|
|
2
|
+
import { OrderablePlugin, Value, Promisable, Interceptor } from '@orpc/shared';
|
|
3
|
+
import { StandardLazyRequest, StandardResponse } from '@standard-server/core';
|
|
4
|
+
import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.BEdOJs6S.js';
|
|
5
5
|
import { Schema, ErrorMap } from '@orpc/contract';
|
|
6
6
|
|
|
7
7
|
interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
|
|
@@ -36,6 +36,17 @@ declare class CompositeStandardHandlerPlugin<T extends Context> implements Stand
|
|
|
36
36
|
|
|
37
37
|
interface StandardHandlerHandleOptions<T extends Context> {
|
|
38
38
|
prefix?: `/${string}` | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The initial context, or a function (sync or async) that receives the request and returns it.
|
|
41
|
+
* The function only runs once the request passes the prefix check.
|
|
42
|
+
*/
|
|
43
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `StandardHandlerHandleOptions` after the context has been resolved,
|
|
47
|
+
* this is what interceptors and codecs receive.
|
|
48
|
+
*/
|
|
49
|
+
interface ResolvedStandardHandlerHandleOptions<T extends Context> extends Omit<StandardHandlerHandleOptions<T>, 'context'> {
|
|
39
50
|
context: T;
|
|
40
51
|
}
|
|
41
52
|
type StandardHandlerHandleResult = {
|
|
@@ -45,11 +56,11 @@ type StandardHandlerHandleResult = {
|
|
|
45
56
|
matched: false;
|
|
46
57
|
response?: undefined;
|
|
47
58
|
};
|
|
48
|
-
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure,
|
|
59
|
+
interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, ResolvedStandardHandlerHandleOptions<T> {
|
|
49
60
|
request: StandardLazyRequest;
|
|
50
61
|
}
|
|
51
62
|
type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
|
|
52
|
-
interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends
|
|
63
|
+
interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends ResolvedStandardHandlerHandleOptions<T> {
|
|
53
64
|
request: StandardLazyRequest;
|
|
54
65
|
}
|
|
55
66
|
type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
|
|
@@ -73,7 +84,7 @@ interface StandardHandlerOptions<TContext extends Context> {
|
|
|
73
84
|
* ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
|
|
74
85
|
* useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
|
|
75
86
|
*/
|
|
76
|
-
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap
|
|
87
|
+
clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap>[];
|
|
77
88
|
plugins?: StandardHandlerPlugin<TContext>[];
|
|
78
89
|
}
|
|
79
90
|
declare class StandardHandler<T extends Context> {
|
|
@@ -82,9 +93,9 @@ declare class StandardHandler<T extends Context> {
|
|
|
82
93
|
private readonly interceptors;
|
|
83
94
|
private readonly clientInterceptors;
|
|
84
95
|
constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
|
|
85
|
-
handle(request: StandardLazyRequest,
|
|
96
|
+
handle(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
|
|
86
97
|
}
|
|
87
|
-
declare class
|
|
98
|
+
declare class TracingHandlerPlugin implements StandardHandlerPlugin<any> {
|
|
88
99
|
name: string;
|
|
89
100
|
init(options: StandardHandlerOptions<any>): StandardHandlerOptions<any>;
|
|
90
101
|
}
|
|
@@ -95,10 +106,10 @@ interface StandardHandlerCodecResolvedProcedure {
|
|
|
95
106
|
decodeInput: () => Promise<unknown>;
|
|
96
107
|
}
|
|
97
108
|
interface StandardHandlerCodec<T extends Context> {
|
|
98
|
-
resolveProcedure(request: StandardLazyRequest, options:
|
|
99
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options:
|
|
100
|
-
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options:
|
|
109
|
+
resolveProcedure(request: StandardLazyRequest, options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
110
|
+
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
111
|
+
encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: ResolvedStandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
export { CompositeStandardHandlerPlugin as C,
|
|
104
|
-
export type {
|
|
114
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, TracingHandlerPlugin as T };
|
|
115
|
+
export type { ResolvedStandardHandlerHandleOptions as R, StandardHandlerHandleOptions as a, StandardHandlerPlugin as b, StandardHandlerOptions as c, StandardHandlerRoutingInterceptorOptions as d, StandardHandlerInterceptorOptions as e, StandardHandlerCodec as f, StandardHandlerCodecResolvedProcedure as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
|
|
2
|
-
import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.
|
|
2
|
+
import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.BEdOJs6S.js';
|
|
3
3
|
|
|
4
|
-
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any
|
|
4
|
+
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any> | {
|
|
5
5
|
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
6
6
|
};
|
|
7
|
-
type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap
|
|
7
|
+
type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap> : {
|
|
8
8
|
[K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
|
|
9
9
|
};
|
|
10
10
|
type AnyRouter = Router<any>;
|
|
@@ -12,50 +12,62 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $>
|
|
|
12
12
|
/**
|
|
13
13
|
* Infer all initial context of the router.
|
|
14
14
|
*
|
|
15
|
-
* @
|
|
16
|
-
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* **Note**: A procedure is a router too.
|
|
17
|
+
*
|
|
18
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-initial-contexts | Router - Infer Router Initial Contexts}
|
|
17
19
|
*/
|
|
18
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any
|
|
20
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
|
|
19
21
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Infer all current context of the router.
|
|
23
25
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* **Note**: A procedure is a router too.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts}
|
|
26
30
|
*/
|
|
27
|
-
type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any
|
|
31
|
+
type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
|
|
28
32
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
|
|
29
33
|
};
|
|
30
34
|
/**
|
|
31
|
-
* Infer all router inputs
|
|
35
|
+
* Infer all router inputs.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* **Note**: A procedure is a router too.
|
|
32
39
|
*
|
|
33
|
-
* @
|
|
34
|
-
* @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
|
|
40
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs}
|
|
35
41
|
*/
|
|
36
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any
|
|
42
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
37
43
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
38
44
|
};
|
|
39
45
|
/**
|
|
40
|
-
* Infer all router outputs
|
|
46
|
+
* Infer all router outputs.
|
|
41
47
|
*
|
|
42
|
-
* @
|
|
43
|
-
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* **Note**: A procedure is a router too.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs}
|
|
44
52
|
*/
|
|
45
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any
|
|
53
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
46
54
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
47
55
|
};
|
|
48
56
|
/**
|
|
49
57
|
* Infer the union of throwable errors for entire router.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error}
|
|
50
60
|
*/
|
|
51
|
-
type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap
|
|
61
|
+
type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
52
62
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
|
|
53
63
|
}[keyof T];
|
|
54
64
|
/**
|
|
55
65
|
* Infer throwable errors for each procedure, preserving the router shape.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors}
|
|
56
68
|
*/
|
|
57
|
-
type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap
|
|
69
|
+
type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
58
70
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
|
|
59
71
|
};
|
|
60
72
|
|
|
61
|
-
export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R,
|
|
73
|
+
export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterFinalContexts as a, InferRouterError as b, InferRouterErrors as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
function createORPCErrorConstructorMap(errorMap) {
|
|
6
|
-
const proxy = new Proxy(errorMap, {
|
|
7
|
-
get(target, code) {
|
|
8
|
-
if (typeof code !== "string") {
|
|
9
|
-
return getOrBind(target, code);
|
|
10
|
-
}
|
|
11
|
-
const item = (...rest) => {
|
|
12
|
-
const options = resolveMaybeOptionalOptions(rest);
|
|
13
|
-
const config = errorMap[code];
|
|
14
|
-
const error = new ORPCError(code, {
|
|
15
|
-
message: options.message ?? config?.message,
|
|
16
|
-
data: options.data,
|
|
17
|
-
cause: options.cause
|
|
18
|
-
});
|
|
19
|
-
if (config) {
|
|
20
|
-
error.defined = true;
|
|
21
|
-
error.inferable = true;
|
|
22
|
-
}
|
|
23
|
-
return error;
|
|
24
|
-
};
|
|
25
|
-
return item;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return proxy;
|
|
29
|
-
}
|
|
1
|
+
import { wrapAsyncIteratorPreservingEventMeta, ORPCError } from '@orpc/client';
|
|
2
|
+
import { createORPCErrorConstructorMap, reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
|
|
3
|
+
import { getConstructor, isTypescriptObject, resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, getTracer, traceAsyncIterator, traceReadableStream, mergeTwoLevels } from '@orpc/shared';
|
|
30
4
|
|
|
31
5
|
class Lazy {
|
|
32
6
|
"~orpc";
|
|
@@ -34,7 +8,7 @@ class Lazy {
|
|
|
34
8
|
this["~orpc"] = def;
|
|
35
9
|
}
|
|
36
10
|
/**
|
|
37
|
-
* Checks if the given instance satisfies the {@
|
|
11
|
+
* Checks if the given instance satisfies the {@link Lazy} class/interface.
|
|
38
12
|
*/
|
|
39
13
|
static [Symbol.hasInstance](instance) {
|
|
40
14
|
if (this !== Lazy) {
|
|
@@ -84,12 +58,11 @@ function createProcedureClient(lazyableProcedure, ...rest) {
|
|
|
84
58
|
);
|
|
85
59
|
});
|
|
86
60
|
if (isAsyncIteratorObject(output)) {
|
|
87
|
-
return override(output,
|
|
88
|
-
traceAsyncIterator("
|
|
61
|
+
return override(output, wrapAsyncIteratorPreservingEventMeta(
|
|
62
|
+
getTracer() ? traceAsyncIterator("consume_async_iterator_object_output", output) : output,
|
|
89
63
|
{ mapError: reconcileError }
|
|
90
64
|
));
|
|
91
|
-
}
|
|
92
|
-
if (output instanceof ReadableStream) {
|
|
65
|
+
} else if (getTracer() && output instanceof ReadableStream) {
|
|
93
66
|
return override(output, traceReadableStream("consume_octet_stream_output", output));
|
|
94
67
|
}
|
|
95
68
|
return output;
|
|
@@ -149,10 +122,19 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
149
122
|
const orderedMiddlewares = procedure["~orpc"].orderedMiddlewares;
|
|
150
123
|
const next = async (midIndex, context, input) => {
|
|
151
124
|
let currentInput = input;
|
|
125
|
+
let middlewareInput = input;
|
|
152
126
|
const startInputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].inputSchemasLengthAtUse ?? 0;
|
|
153
127
|
const endInputIndex = midIndex === orderedMiddlewares.length ? inputSchemas.length : orderedMiddlewares[midIndex].inputSchemasLengthAtUse ?? 0;
|
|
154
|
-
|
|
155
|
-
|
|
128
|
+
if (!procedure["~orpc"].disableInputValidation) {
|
|
129
|
+
for (let i = startInputIndex; i < endInputIndex; i++) {
|
|
130
|
+
const validated = await validateInput(
|
|
131
|
+
i,
|
|
132
|
+
inputSchemas[i],
|
|
133
|
+
i !== 0 ? mergeTwoLevels(options.input, currentInput) : currentInput
|
|
134
|
+
);
|
|
135
|
+
currentInput = i !== 0 ? mergeTwoLevels(currentInput, validated) : validated;
|
|
136
|
+
}
|
|
137
|
+
middlewareInput = endInputIndex > 0 && endInputIndex < inputSchemas.length ? mergeTwoLevels(options.input, currentInput) : currentInput;
|
|
156
138
|
}
|
|
157
139
|
let currentOutput;
|
|
158
140
|
let currentContext = context;
|
|
@@ -175,7 +157,7 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
175
157
|
},
|
|
176
158
|
lastEventId: options.lastEventId
|
|
177
159
|
},
|
|
178
|
-
|
|
160
|
+
middlewareInput,
|
|
179
161
|
middlewareDone
|
|
180
162
|
);
|
|
181
163
|
});
|
|
@@ -186,23 +168,13 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
186
168
|
"handler",
|
|
187
169
|
() => procedure["~orpc"].handler({ ...options, context, input: currentInput }, currentInput)
|
|
188
170
|
);
|
|
189
|
-
if (currentOutput instanceof ORPCError) {
|
|
190
|
-
if (procedure["~orpc"].opaqueReturnedErrors) {
|
|
191
|
-
throw currentOutput;
|
|
192
|
-
}
|
|
193
|
-
if (currentOutput.inferable && !currentOutput.defined) {
|
|
194
|
-
throw currentOutput;
|
|
195
|
-
}
|
|
196
|
-
const error = cloneORPCError(currentOutput);
|
|
197
|
-
error.defined = false;
|
|
198
|
-
error.inferable = true;
|
|
199
|
-
throw error;
|
|
200
|
-
}
|
|
201
171
|
}
|
|
202
172
|
const startOutputIndex = midIndex === 0 ? 0 : orderedMiddlewares[midIndex - 1].outputSchemasLengthAtUse ?? 0;
|
|
203
173
|
const endOutputIndex = midIndex === orderedMiddlewares.length ? outputSchemas.length : orderedMiddlewares[midIndex].outputSchemasLengthAtUse ?? 0;
|
|
204
|
-
|
|
205
|
-
|
|
174
|
+
if (!procedure["~orpc"].disableOutputValidation) {
|
|
175
|
+
for (let i = endOutputIndex - 1; i >= startOutputIndex; i--) {
|
|
176
|
+
currentOutput = await validateOutput(i, outputSchemas[i], currentOutput);
|
|
177
|
+
}
|
|
206
178
|
}
|
|
207
179
|
return { output: currentOutput, context: currentContext };
|
|
208
180
|
};
|
|
@@ -216,7 +188,7 @@ class Procedure {
|
|
|
216
188
|
this["~orpc"] = def;
|
|
217
189
|
}
|
|
218
190
|
/**
|
|
219
|
-
* Checks if the given instance satisfies the {@
|
|
191
|
+
* Checks if the given instance satisfies the {@link Procedure} class/interface.
|
|
220
192
|
*/
|
|
221
193
|
static [Symbol.hasInstance](instance) {
|
|
222
194
|
if (this !== Procedure) {
|
|
@@ -230,4 +202,4 @@ class Procedure {
|
|
|
230
202
|
}
|
|
231
203
|
}
|
|
232
204
|
|
|
233
|
-
export { Lazy as L, Procedure as P,
|
|
205
|
+
export { Lazy as L, Procedure as P, createProcedureClient as c, unlazy as u };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardLazyRequest } from '@standard-server/core';
|
|
3
|
+
import { C as Context } from './server.BEdOJs6S.mjs';
|
|
4
|
+
import { a as StandardHandlerHandleOptions } from './server.CVO0hWyj.mjs';
|
|
5
|
+
|
|
6
|
+
type FriendlyStandardHandlerHandleOptions<T extends Context> = Omit<StandardHandlerHandleOptions<T>, 'context'> & (object extends T ? {
|
|
7
|
+
context?: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
8
|
+
} : {
|
|
9
|
+
context: Value<Promisable<T>, [request: StandardLazyRequest]>;
|
|
10
|
+
});
|
|
11
|
+
declare function resolveFriendlyStandardHandlerHandleOptions<T extends Context>(options: FriendlyStandardHandlerHandleOptions<T>): StandardHandlerHandleOptions<T>;
|
|
12
|
+
|
|
13
|
+
export { resolveFriendlyStandardHandlerHandleOptions as r };
|
|
14
|
+
export type { FriendlyStandardHandlerHandleOptions as F };
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.41",
|
|
5
|
+
"description": "Build typesafe APIs with oRPC: RPC and OpenAPI support, middleware, and adapters for Node.js, Bun, Deno, Fetch, Fastify, WebSocket, AWS Lambda, and more",
|
|
5
6
|
"license": "MIT",
|
|
7
|
+
"funding": [
|
|
8
|
+
"https://github.com/sponsors/dinwwwh",
|
|
9
|
+
"https://opencollective.com/middleapi"
|
|
10
|
+
],
|
|
6
11
|
"homepage": "https://orpc.dev",
|
|
7
12
|
"repository": {
|
|
8
13
|
"type": "git",
|
|
@@ -10,7 +15,20 @@
|
|
|
10
15
|
"directory": "packages/server"
|
|
11
16
|
},
|
|
12
17
|
"keywords": [
|
|
13
|
-
"orpc"
|
|
18
|
+
"orpc",
|
|
19
|
+
"rpc",
|
|
20
|
+
"api",
|
|
21
|
+
"typescript",
|
|
22
|
+
"typesafe",
|
|
23
|
+
"server",
|
|
24
|
+
"openapi",
|
|
25
|
+
"middleware",
|
|
26
|
+
"nodejs",
|
|
27
|
+
"bun",
|
|
28
|
+
"deno",
|
|
29
|
+
"fastify",
|
|
30
|
+
"websocket",
|
|
31
|
+
"aws-lambda"
|
|
14
32
|
],
|
|
15
33
|
"sideEffects": [
|
|
16
34
|
"./dist/extensions/callable.mjs"
|
|
@@ -52,6 +70,16 @@
|
|
|
52
70
|
"import": "./dist/adapters/node/index.mjs",
|
|
53
71
|
"default": "./dist/adapters/node/index.mjs"
|
|
54
72
|
},
|
|
73
|
+
"./aws-lambda": {
|
|
74
|
+
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
75
|
+
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
76
|
+
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
77
|
+
},
|
|
78
|
+
"./fastify": {
|
|
79
|
+
"types": "./dist/adapters/fastify/index.d.mts",
|
|
80
|
+
"import": "./dist/adapters/fastify/index.mjs",
|
|
81
|
+
"default": "./dist/adapters/fastify/index.mjs"
|
|
82
|
+
},
|
|
55
83
|
"./websocket": {
|
|
56
84
|
"types": "./dist/adapters/websocket/index.d.mts",
|
|
57
85
|
"import": "./dist/adapters/websocket/index.mjs",
|
|
@@ -77,31 +105,37 @@
|
|
|
77
105
|
"dist"
|
|
78
106
|
],
|
|
79
107
|
"peerDependencies": {
|
|
80
|
-
"crossws": ">=0.3.4"
|
|
108
|
+
"crossws": ">=0.3.4",
|
|
109
|
+
"fastify": ">=5.6.1"
|
|
81
110
|
},
|
|
82
111
|
"peerDependenciesMeta": {
|
|
83
112
|
"crossws": {
|
|
84
113
|
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"fastify": {
|
|
116
|
+
"optional": true
|
|
85
117
|
}
|
|
86
118
|
},
|
|
87
119
|
"dependencies": {
|
|
88
|
-
"@
|
|
89
|
-
"@
|
|
90
|
-
"@
|
|
91
|
-
"@
|
|
92
|
-
"
|
|
93
|
-
"@
|
|
94
|
-
"@
|
|
95
|
-
"@
|
|
96
|
-
"@
|
|
120
|
+
"@orpc/client": "2.0.0-beta.41",
|
|
121
|
+
"@orpc/contract": "2.0.0-beta.41",
|
|
122
|
+
"@orpc/shared": "2.0.0-beta.41",
|
|
123
|
+
"@standard-server/aws-lambda": "~0.10.0",
|
|
124
|
+
"@standard-server/core": "~0.10.0",
|
|
125
|
+
"@standard-server/fastify": "~0.10.0",
|
|
126
|
+
"@standard-server/fetch": "~0.10.0",
|
|
127
|
+
"@standard-server/node": "~0.10.0",
|
|
128
|
+
"@standard-server/peer": "~0.10.0",
|
|
129
|
+
"cookie": "^2.0.1"
|
|
97
130
|
},
|
|
98
131
|
"devDependencies": {
|
|
99
132
|
"crossws": "^0.4.6",
|
|
133
|
+
"fastify": "^5.12.1",
|
|
100
134
|
"supertest": "^7.2.2",
|
|
101
|
-
"
|
|
135
|
+
"ws": "^8.21.3",
|
|
136
|
+
"zod": "^4.5.4"
|
|
102
137
|
},
|
|
103
138
|
"scripts": {
|
|
104
|
-
"build": "unbuild",
|
|
105
139
|
"type:check": "tsc -b"
|
|
106
140
|
}
|
|
107
141
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { value } from '@orpc/shared';
|
|
2
|
-
|
|
3
|
-
function createStandardPeerRequestHandler(handler, options) {
|
|
4
|
-
return async (request) => {
|
|
5
|
-
const context = await value(options.context ?? {}, request);
|
|
6
|
-
const { response } = await handler.handle(request, { ...options, context });
|
|
7
|
-
return response ?? { status: 404, headers: {}, body: "No procedure matched" };
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { createStandardPeerRequestHandler as c };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { RPCSerializer, AnyORPCError } from '@orpc/client';
|
|
2
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
|
|
4
|
-
import { A as AnyProcedure, C as Context } from './server.BL22TloH.mjs';
|
|
5
|
-
import { A as AnyRouter } from './server.BsNNjG5J.mjs';
|
|
6
|
-
import { AnyProcedureContract } from '@orpc/contract';
|
|
7
|
-
import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.DJIkub_t.mjs';
|
|
8
|
-
|
|
9
|
-
interface RPCMatcherOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Filter which procedures are exposed for matching. Return `false` to exclude.
|
|
12
|
-
*
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
|
|
16
|
-
}
|
|
17
|
-
declare class RPCMatcher {
|
|
18
|
-
private readonly filter;
|
|
19
|
-
private readonly rootRouter;
|
|
20
|
-
private readonly tree;
|
|
21
|
-
private pendingLazyRouters;
|
|
22
|
-
constructor(router: AnyRouter, options?: RPCMatcherOptions);
|
|
23
|
-
private index;
|
|
24
|
-
match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
|
|
25
|
-
path: string[];
|
|
26
|
-
procedure: AnyProcedure;
|
|
27
|
-
} | undefined>;
|
|
28
|
-
private matchPathname;
|
|
29
|
-
private resolvePendingLazyRouters;
|
|
30
|
-
private resolveProcedure;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
|
|
34
|
-
/**
|
|
35
|
-
* Override the default RPC serializer.
|
|
36
|
-
*/
|
|
37
|
-
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
38
|
-
/**
|
|
39
|
-
* Resolve HTTP status for encoded successful outputs.
|
|
40
|
-
*
|
|
41
|
-
* Value should be in range `200-299`
|
|
42
|
-
* Return `undefined` or `null` to fallback to default
|
|
43
|
-
*
|
|
44
|
-
* @default DEFAULT_ERROR_STATUS, DEFAULT_ERROR_STATUS
|
|
45
|
-
*/
|
|
46
|
-
outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
|
|
47
|
-
/**
|
|
48
|
-
* Mapping ORPCError Code -> HTTP Status Code
|
|
49
|
-
*
|
|
50
|
-
* @default COMMON_ERROR_STATUS_MAP
|
|
51
|
-
*/
|
|
52
|
-
errorStatusMap?: Record<string, number> | undefined;
|
|
53
|
-
}
|
|
54
|
-
declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
|
|
55
|
-
private readonly matcher;
|
|
56
|
-
private readonly serializer;
|
|
57
|
-
private readonly errorStatusMap;
|
|
58
|
-
private readonly outputStatus;
|
|
59
|
-
constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
|
|
60
|
-
resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
|
|
61
|
-
encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
62
|
-
encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { RPCHandlerCodec as a, RPCMatcher as b };
|
|
66
|
-
export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
|