@orpc/server 0.0.0-next.6c5bfe4 → 0.0.0-next.7134cf9
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 +5 -1
- package/dist/adapters/fetch/index.d.mts +5 -3
- package/dist/adapters/fetch/index.d.ts +5 -3
- package/dist/adapters/fetch/index.mjs +4 -4
- package/dist/adapters/hono/index.d.mts +4 -2
- package/dist/adapters/hono/index.d.ts +4 -2
- package/dist/adapters/hono/index.mjs +4 -4
- package/dist/adapters/next/index.d.mts +4 -2
- package/dist/adapters/next/index.d.ts +4 -2
- package/dist/adapters/next/index.mjs +4 -4
- package/dist/adapters/node/index.d.mts +5 -3
- package/dist/adapters/node/index.d.ts +5 -3
- package/dist/adapters/node/index.mjs +8 -7
- package/dist/adapters/standard/index.d.mts +9 -8
- package/dist/adapters/standard/index.d.ts +9 -8
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +58 -50
- package/dist/index.d.ts +58 -50
- package/dist/index.mjs +29 -26
- package/dist/plugins/index.d.mts +9 -9
- package/dist/plugins/index.d.ts +9 -9
- package/dist/plugins/index.mjs +2 -2
- package/dist/shared/{server.N2ttmv6r.mjs → server.BY9sDlwl.mjs} +6 -6
- package/dist/shared/server.BqBN5WhH.d.mts +8 -0
- package/dist/shared/{server.kPUGzsdw.mjs → server.BtxZnWJ9.mjs} +32 -15
- package/dist/shared/{server.BZRSVRDu.d.ts → server.CPqNKiJp.d.ts} +5 -7
- package/dist/shared/{server.Q6ZmnTgO.mjs → server.Dba3Iiyp.mjs} +2 -2
- package/dist/shared/{server.CXu_v2vM.mjs → server.Del5OmaY.mjs} +6 -5
- package/dist/shared/server.Dm3ZuTuI.d.ts +8 -0
- package/dist/shared/{server.CPteJIPP.d.mts → server.MZvbGc3n.d.mts} +11 -11
- package/dist/shared/{server.CPteJIPP.d.ts → server.MZvbGc3n.d.ts} +11 -11
- package/dist/shared/{server.iM8li30u.d.mts → server.P4_D9lKb.d.mts} +5 -7
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, HTTPPath, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
-
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, HTTPMethod, HTTPPath, InferSchemaInput, InferSchemaOutput, InputStructure, Meta,
|
3
|
-
import { C as Context, b as Procedure, M as Middleware, O as ORPCErrorConstructorMap, c as
|
4
|
-
export {
|
2
|
+
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, HTTPMethod, HTTPPath, InferSchemaInput, InferSchemaOutput, InputStructure, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
+
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.MZvbGc3n.js';
|
4
|
+
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.MZvbGc3n.js';
|
5
5
|
import { ClientContext, ClientRest, ClientPromiseResult } from '@orpc/client';
|
6
6
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
|
-
import { MaybeOptionalOptions } from '@orpc/shared';
|
7
|
+
import { IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
8
8
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
9
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
10
|
|
@@ -12,16 +12,16 @@ declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContex
|
|
12
12
|
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
13
13
|
meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
14
14
|
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
15
|
-
use<
|
16
|
-
use<UOutContext extends
|
15
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
16
|
+
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>): DecoratedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
17
17
|
/**
|
18
18
|
* Make this procedure callable (works like a function while still being a procedure).
|
19
19
|
*/
|
20
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>):
|
20
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
21
21
|
/**
|
22
22
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
23
23
|
*/
|
24
|
-
actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>):
|
24
|
+
actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>) => Promise<InferSchemaOutput<TOutputSchema>>);
|
25
25
|
}
|
26
26
|
|
27
27
|
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
@@ -29,14 +29,15 @@ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends
|
|
29
29
|
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
30
30
|
};
|
31
31
|
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
32
|
-
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TErrorMap>> : T extends Procedure<
|
33
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TErrorMap> : never;
|
32
|
+
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
33
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
34
34
|
};
|
35
35
|
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
36
36
|
middlewares: readonly AnyMiddleware[];
|
37
37
|
errorMap: TErrorMap;
|
38
|
+
dedupeLeadingMiddlewares: boolean;
|
38
39
|
}
|
39
|
-
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TErrorMap>;
|
40
|
+
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
|
40
41
|
interface TraverseContractProceduresOptions {
|
41
42
|
router: AnyContractRouter | AnyRouter;
|
42
43
|
path: readonly string[];
|
@@ -59,7 +60,7 @@ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedR
|
|
59
60
|
interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
60
61
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
61
62
|
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
62
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
63
|
+
'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>;
|
63
64
|
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
64
65
|
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
65
66
|
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -67,15 +68,15 @@ interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContex
|
|
67
68
|
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
68
69
|
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
69
70
|
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
70
|
-
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TErrorMap>;
|
71
|
+
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
71
72
|
'lazy'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
72
73
|
default: U;
|
73
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TErrorMap>;
|
74
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
74
75
|
}
|
75
76
|
interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
76
77
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
77
78
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
78
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
79
|
+
'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>;
|
79
80
|
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
80
81
|
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
81
82
|
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -85,8 +86,8 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
|
|
85
86
|
interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
86
87
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
87
88
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
88
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
89
|
-
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>):
|
89
|
+
'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>;
|
90
|
+
'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>;
|
90
91
|
'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
91
92
|
'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
92
93
|
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
@@ -95,7 +96,7 @@ interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentCon
|
|
95
96
|
interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
96
97
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
97
98
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
98
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
99
|
+
'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>;
|
99
100
|
'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
100
101
|
'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
101
102
|
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -104,8 +105,8 @@ interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentCo
|
|
104
105
|
interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
105
106
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
106
107
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
107
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
108
|
-
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>):
|
108
|
+
'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>;
|
109
|
+
'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>;
|
109
110
|
'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
110
111
|
'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
111
112
|
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -113,28 +114,29 @@ interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurr
|
|
113
114
|
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
114
115
|
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
115
116
|
'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
|
116
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
117
|
+
'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>;
|
117
118
|
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
118
119
|
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
119
|
-
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TErrorMap>;
|
120
|
+
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
120
121
|
'lazy'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
121
122
|
default: U;
|
122
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TErrorMap>;
|
123
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
123
124
|
}
|
124
125
|
|
125
126
|
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> {
|
126
|
-
|
127
|
-
concat<UOutContext extends Context,
|
128
|
-
|
127
|
+
mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
128
|
+
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>;
|
129
|
+
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>;
|
129
130
|
}
|
130
131
|
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>;
|
131
132
|
|
132
133
|
interface BuilderConfig {
|
133
134
|
initialInputValidationIndex?: number;
|
134
135
|
initialOutputValidationIndex?: number;
|
136
|
+
dedupeLeadingMiddlewares?: boolean;
|
135
137
|
}
|
136
138
|
interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
|
137
|
-
middlewares: AnyMiddleware[];
|
139
|
+
middlewares: readonly AnyMiddleware[];
|
138
140
|
inputValidationIndex: number;
|
139
141
|
outputValidationIndex: number;
|
140
142
|
config: BuilderConfig;
|
@@ -149,21 +151,20 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
149
151
|
/**
|
150
152
|
* Reset initial context
|
151
153
|
*/
|
152
|
-
$context<U extends Context>(): Builder<U, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
154
|
+
$context<U extends Context>(): Builder<U & Record<never, never>, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
153
155
|
/**
|
154
156
|
* Reset initial meta
|
155
157
|
*/
|
156
|
-
$meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U
|
158
|
+
$meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
157
159
|
/**
|
158
160
|
* Reset initial route
|
159
161
|
*/
|
160
162
|
$route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
161
163
|
$input<U extends AnySchema>(initialInputSchema?: U): Builder<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap, TMeta>;
|
162
164
|
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
163
|
-
middleware: Middleware<
|
165
|
+
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
164
166
|
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
165
|
-
use<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
166
|
-
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<unknown, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
167
|
+
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>;
|
167
168
|
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
168
169
|
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
169
170
|
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
@@ -171,16 +172,17 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
171
172
|
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
172
173
|
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
173
174
|
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
174
|
-
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TErrorMap>;
|
175
|
+
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
175
176
|
lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
176
177
|
default: U;
|
177
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TErrorMap>;
|
178
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
178
179
|
}
|
179
180
|
declare const os: Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
180
181
|
|
181
182
|
interface Config {
|
182
183
|
initialInputValidationIndex: number;
|
183
184
|
initialOutputValidationIndex: number;
|
185
|
+
dedupeLeadingMiddlewares: boolean;
|
184
186
|
}
|
185
187
|
declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
|
186
188
|
|
@@ -188,33 +190,33 @@ declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T
|
|
188
190
|
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
189
191
|
*/
|
190
192
|
interface ImplementedProcedure<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> {
|
191
|
-
use<
|
192
|
-
use<UOutContext extends
|
193
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
194
|
+
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>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
193
195
|
/**
|
194
196
|
* Make this procedure callable (works like a function while still being a procedure).
|
195
197
|
*/
|
196
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>):
|
198
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
197
199
|
/**
|
198
200
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
199
201
|
*/
|
200
|
-
actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>):
|
202
|
+
actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>) => Promise<InferSchemaOutput<TOutputSchema>>);
|
201
203
|
}
|
202
204
|
/**
|
203
205
|
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
204
206
|
*/
|
205
207
|
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
206
208
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
207
|
-
'use'<
|
208
|
-
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>):
|
209
|
+
'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>;
|
210
|
+
'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>;
|
209
211
|
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
210
212
|
}
|
211
213
|
|
212
214
|
interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
213
|
-
use<
|
214
|
-
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, Record<never, never>>;
|
215
|
+
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>>;
|
216
|
+
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
215
217
|
lazy<U extends Router<T, TInitialContext>>(loader: () => Promise<{
|
216
218
|
default: U;
|
217
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, Record<never, never>>;
|
219
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
218
220
|
}
|
219
221
|
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
220
222
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
@@ -222,22 +224,28 @@ type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TIn
|
|
222
224
|
|
223
225
|
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
224
226
|
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
225
|
-
middleware: Middleware<
|
226
|
-
use<
|
227
|
-
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, Record<never, never>>;
|
227
|
+
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, InferContractRouterMeta<T>>;
|
228
|
+
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>>;
|
229
|
+
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
228
230
|
lazy<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
|
229
231
|
default: U;
|
230
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, Record<never, never>>;
|
232
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
231
233
|
}
|
232
234
|
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
233
235
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
234
236
|
});
|
235
237
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
236
238
|
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
237
|
-
$context<U extends Context>(): Implementer<TContract, U, U>;
|
239
|
+
$context<U extends Context>(): Implementer<TContract, U & Record<never, never>, U>;
|
238
240
|
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
239
241
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
240
|
-
declare function implement<
|
242
|
+
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
243
|
+
|
244
|
+
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
245
|
+
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
246
|
+
dedupeLeading: boolean;
|
247
|
+
}): readonly AnyMiddleware[];
|
248
|
+
declare function addMiddleware(middlewares: readonly AnyMiddleware[], addition: AnyMiddleware): AnyMiddleware[];
|
241
249
|
|
242
250
|
declare function createAssertedLazyProcedure(lazied: Lazy<any>): Lazy<AnyProcedure>;
|
243
251
|
/**
|
@@ -266,4 +274,4 @@ declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContrac
|
|
266
274
|
|
267
275
|
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
268
276
|
|
269
|
-
export { type AccessibleLazyRouter, AnyMiddleware, AnyProcedure, AnyRouter, Builder, type BuilderConfig, type BuilderDef, type BuilderWithMiddlewares, type Config,
|
277
|
+
export { type AccessibleLazyRouter, AnyMiddleware, AnyProcedure, AnyRouter, Builder, type BuilderConfig, type BuilderDef, type BuilderWithMiddlewares, type Config, Context, type ContractProcedureCallbackOptions, CreateProcedureClientOptions, type DecoratedMiddleware, DecoratedProcedure, type EnhanceRouterOptions, type EnhancedRouter, type ImplementedProcedure, type Implementer, type ImplementerInternal, type ImplementerInternalWithMiddlewares, InferRouterInitialContext, Lazy, type LazyTraverseContractProceduresOptions, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, type ProcedureBuilder, type ProcedureBuilderWithInput, type ProcedureBuilderWithInputOutput, type ProcedureBuilderWithOutput, ProcedureClient, ProcedureHandler, type ProcedureImplementer, Router, type RouterBuilder, type RouterClient, type RouterImplementer, type RouterImplementerWithMiddlewares, type TraverseContractProceduresOptions, type UnlaziedRouter, addMiddleware, call, createAccessibleLazyRouter, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, toHttpPath, traverseContractProcedures, unlazyRouter };
|
package/dist/index.mjs
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
import { mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, mergeTags, isContractProcedure, getContractRouter } from '@orpc/contract';
|
2
2
|
export { ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.
|
4
|
-
export { L as LAZY_SYMBOL,
|
3
|
+
import { P as Procedure, d as addMiddleware, c as createProcedureClient, e as enhanceRouter, l as lazy, s as setHiddenRouterContract, i as isProcedure, f as isLazy, h as createAssertedLazyProcedure, g as getRouter } from './shared/server.BtxZnWJ9.mjs';
|
4
|
+
export { L as LAZY_SYMBOL, q as call, w as createAccessibleLazyRouter, b as createContractedProcedure, j as createORPCErrorConstructorMap, r as getHiddenRouterContract, k as getLazyMeta, o as isStartWithMiddlewares, m as mergeCurrentContext, p as mergeMiddlewares, n as middlewareOutputFn, x as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, y as unlazyRouter, v as validateORPCError } from './shared/server.BtxZnWJ9.mjs';
|
5
5
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
6
6
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
7
7
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
8
8
|
|
9
9
|
const DEFAULT_CONFIG = {
|
10
10
|
initialInputValidationIndex: 0,
|
11
|
-
initialOutputValidationIndex: 0
|
11
|
+
initialOutputValidationIndex: 0,
|
12
|
+
dedupeLeadingMiddlewares: true
|
12
13
|
};
|
13
14
|
function fallbackConfig(key, value) {
|
14
15
|
if (value === void 0) {
|
@@ -18,7 +19,7 @@ function fallbackConfig(key, value) {
|
|
18
19
|
}
|
19
20
|
|
20
21
|
function decorateMiddleware(middleware) {
|
21
|
-
const decorated = middleware;
|
22
|
+
const decorated = (...args) => middleware(...args);
|
22
23
|
decorated.mapInput = (mapInput) => {
|
23
24
|
const mapped = decorateMiddleware(
|
24
25
|
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
@@ -73,9 +74,13 @@ class DecoratedProcedure extends Procedure {
|
|
73
74
|
* Make this procedure callable (works like a function while still being a procedure).
|
74
75
|
*/
|
75
76
|
callable(...rest) {
|
76
|
-
return
|
77
|
-
|
78
|
-
|
77
|
+
return new Proxy(createProcedureClient(this, ...rest), {
|
78
|
+
get: (target, key) => {
|
79
|
+
return Reflect.has(this, key) ? Reflect.get(this, key) : Reflect.get(target, key);
|
80
|
+
},
|
81
|
+
has: (target, key) => {
|
82
|
+
return Reflect.has(this, key) || Reflect.has(target, key);
|
83
|
+
}
|
79
84
|
});
|
80
85
|
}
|
81
86
|
/**
|
@@ -100,6 +105,7 @@ class Builder {
|
|
100
105
|
return new Builder({
|
101
106
|
...this["~orpc"],
|
102
107
|
config,
|
108
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
|
103
109
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
104
110
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
105
111
|
});
|
@@ -213,13 +219,10 @@ const os = new Builder({
|
|
213
219
|
errorMap: {},
|
214
220
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
215
221
|
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
216
|
-
middlewares: []
|
222
|
+
middlewares: [],
|
223
|
+
dedupeLeadingMiddlewares: true
|
217
224
|
});
|
218
225
|
|
219
|
-
function mergeContext(context, other) {
|
220
|
-
return { ...context, ...other };
|
221
|
-
}
|
222
|
-
|
223
226
|
function implementerInternal(contract, config, middlewares) {
|
224
227
|
if (isContractProcedure(contract)) {
|
225
228
|
const impl2 = new Builder({
|
@@ -227,7 +230,8 @@ function implementerInternal(contract, config, middlewares) {
|
|
227
230
|
config,
|
228
231
|
middlewares,
|
229
232
|
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
230
|
-
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
233
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
|
234
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
231
235
|
});
|
232
236
|
return impl2;
|
233
237
|
}
|
@@ -253,7 +257,8 @@ function implementerInternal(contract, config, middlewares) {
|
|
253
257
|
middlewares,
|
254
258
|
errorMap: {},
|
255
259
|
prefix: void 0,
|
256
|
-
tags: void 0
|
260
|
+
tags: void 0,
|
261
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
257
262
|
});
|
258
263
|
return setHiddenRouterContract(adapted, contract);
|
259
264
|
};
|
@@ -263,7 +268,8 @@ function implementerInternal(contract, config, middlewares) {
|
|
263
268
|
middlewares,
|
264
269
|
errorMap: {},
|
265
270
|
prefix: void 0,
|
266
|
-
tags: void 0
|
271
|
+
tags: void 0,
|
272
|
+
dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
|
267
273
|
});
|
268
274
|
return setHiddenRouterContract(adapted, contract);
|
269
275
|
};
|
@@ -296,17 +302,14 @@ function implement(contract, config = {}) {
|
|
296
302
|
method = (config2) => implement(contract, config2);
|
297
303
|
}
|
298
304
|
const next = Reflect.get(target, key);
|
299
|
-
if (!next || typeof next !== "function" && typeof next !== "object") {
|
300
|
-
return method
|
305
|
+
if (!method || !next || typeof next !== "function" && typeof next !== "object") {
|
306
|
+
return method || next;
|
301
307
|
}
|
302
|
-
|
303
|
-
|
304
|
-
get(
|
305
|
-
|
306
|
-
|
307
|
-
});
|
308
|
-
}
|
309
|
-
return next;
|
308
|
+
return new Proxy(method, {
|
309
|
+
get(_, key2) {
|
310
|
+
return Reflect.get(next, key2);
|
311
|
+
}
|
312
|
+
});
|
310
313
|
}
|
311
314
|
});
|
312
315
|
return impl;
|
@@ -336,4 +339,4 @@ function createRouterClient(router, ...[options]) {
|
|
336
339
|
return recursive;
|
337
340
|
}
|
338
341
|
|
339
|
-
export { Builder, DecoratedProcedure, Procedure, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy,
|
342
|
+
export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
|
package/dist/plugins/index.d.mts
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
export { C as
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.P4_D9lKb.mjs';
|
2
|
+
export { C as CompositeHandlerPlugin } from '../shared/server.P4_D9lKb.mjs';
|
3
3
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
4
|
+
import { C as Context } from '../shared/server.MZvbGc3n.mjs';
|
5
5
|
import '@orpc/contract';
|
6
6
|
import '@orpc/standard-server';
|
7
7
|
import '@orpc/client';
|
8
8
|
|
9
9
|
interface CORSOptions<TContext extends Context> {
|
10
|
-
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
-
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
-
allowMethods?: string[];
|
13
|
-
allowHeaders?: string[];
|
10
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
14
|
maxAge?: number;
|
15
15
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
16
|
+
exposeHeaders?: readonly string[];
|
17
17
|
}
|
18
18
|
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
19
|
private readonly options;
|
20
|
-
constructor(options?:
|
20
|
+
constructor(options?: CORSOptions<TContext>);
|
21
21
|
init(options: StandardHandlerOptions<TContext>): void;
|
22
22
|
}
|
23
23
|
|
package/dist/plugins/index.d.ts
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
export { C as
|
1
|
+
import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.CPqNKiJp.js';
|
2
|
+
export { C as CompositeHandlerPlugin } from '../shared/server.CPqNKiJp.js';
|
3
3
|
import { Value } from '@orpc/shared';
|
4
|
-
import { C as Context } from '../shared/server.
|
4
|
+
import { C as Context } from '../shared/server.MZvbGc3n.js';
|
5
5
|
import '@orpc/contract';
|
6
6
|
import '@orpc/standard-server';
|
7
7
|
import '@orpc/client';
|
8
8
|
|
9
9
|
interface CORSOptions<TContext extends Context> {
|
10
|
-
origin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
-
timingOrigin?: Value<string | string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
-
allowMethods?: string[];
|
13
|
-
allowHeaders?: string[];
|
10
|
+
origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
11
|
+
timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
|
12
|
+
allowMethods?: readonly string[];
|
13
|
+
allowHeaders?: readonly string[];
|
14
14
|
maxAge?: number;
|
15
15
|
credentials?: boolean;
|
16
|
-
exposeHeaders?: string[];
|
16
|
+
exposeHeaders?: readonly string[];
|
17
17
|
}
|
18
18
|
declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
19
19
|
private readonly options;
|
20
|
-
constructor(options?:
|
20
|
+
constructor(options?: CORSOptions<TContext>);
|
21
21
|
init(options: StandardHandlerOptions<TContext>): void;
|
22
22
|
}
|
23
23
|
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
export { C as
|
1
|
+
export { C as CompositeHandlerPlugin } from '../shared/server.Dba3Iiyp.mjs';
|
2
2
|
import { value } from '@orpc/shared';
|
3
3
|
|
4
4
|
class CORSPlugin {
|
5
5
|
options;
|
6
|
-
constructor(options) {
|
6
|
+
constructor(options = {}) {
|
7
7
|
const defaults = {
|
8
8
|
origin: (origin) => origin,
|
9
9
|
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { ORPCError, toORPCError } from '@orpc/client';
|
2
2
|
import { intercept, trim, parseEmptyableJSON } from '@orpc/shared';
|
3
|
-
import { C as
|
4
|
-
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.
|
3
|
+
import { C as CompositeHandlerPlugin } from './server.Dba3Iiyp.mjs';
|
4
|
+
import { c as createProcedureClient, t as traverseContractProcedures, a as toHttpPath, i as isProcedure, u as unlazy, g as getRouter, b as createContractedProcedure } from './server.BtxZnWJ9.mjs';
|
5
5
|
|
6
6
|
class StandardHandler {
|
7
7
|
constructor(router, matcher, codec, options) {
|
8
8
|
this.matcher = matcher;
|
9
9
|
this.codec = codec;
|
10
10
|
this.options = options;
|
11
|
-
this.plugin = new
|
11
|
+
this.plugin = new CompositeHandlerPlugin(options.plugins);
|
12
12
|
this.plugin.init(this.options);
|
13
13
|
this.matcher.init(router);
|
14
14
|
}
|
@@ -69,7 +69,7 @@ class StandardHandler {
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
|
72
|
-
class
|
72
|
+
class StandardRPCCodec {
|
73
73
|
constructor(serializer) {
|
74
74
|
this.serializer = serializer;
|
75
75
|
}
|
@@ -93,7 +93,7 @@ class RPCCodec {
|
|
93
93
|
}
|
94
94
|
}
|
95
95
|
|
96
|
-
class
|
96
|
+
class StandardRPCMatcher {
|
97
97
|
tree = {};
|
98
98
|
pendingRouters = [];
|
99
99
|
init(router, path = []) {
|
@@ -155,4 +155,4 @@ class RPCMatcher {
|
|
155
155
|
}
|
156
156
|
}
|
157
157
|
|
158
|
-
export {
|
158
|
+
export { StandardHandler as S, StandardRPCCodec as a, StandardRPCMatcher as b };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
|
2
|
+
import { C as Context } from './server.MZvbGc3n.mjs';
|
3
|
+
import { a as StandardHandlerOptions } from './server.P4_D9lKb.mjs';
|
4
|
+
|
5
|
+
interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
|
6
|
+
}
|
7
|
+
|
8
|
+
export type { StandardRPCHandlerOptions as S };
|