@orpc/server 0.0.0-next.9b9ade5 → 0.0.0-next.9e880d7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +4 -1
  2. package/dist/adapters/fetch/index.d.mts +5 -3
  3. package/dist/adapters/fetch/index.d.ts +5 -3
  4. package/dist/adapters/fetch/index.mjs +3 -3
  5. package/dist/adapters/hono/index.d.mts +4 -2
  6. package/dist/adapters/hono/index.d.ts +4 -2
  7. package/dist/adapters/hono/index.mjs +3 -3
  8. package/dist/adapters/next/index.d.mts +4 -2
  9. package/dist/adapters/next/index.d.ts +4 -2
  10. package/dist/adapters/next/index.mjs +3 -3
  11. package/dist/adapters/node/index.d.mts +5 -3
  12. package/dist/adapters/node/index.d.ts +5 -3
  13. package/dist/adapters/node/index.mjs +7 -6
  14. package/dist/adapters/standard/index.d.mts +9 -8
  15. package/dist/adapters/standard/index.d.ts +9 -8
  16. package/dist/adapters/standard/index.mjs +2 -2
  17. package/dist/index.d.mts +53 -44
  18. package/dist/index.d.ts +53 -44
  19. package/dist/index.mjs +21 -22
  20. package/dist/plugins/index.d.mts +3 -3
  21. package/dist/plugins/index.d.ts +3 -3
  22. package/dist/shared/{server.DmW25ynm.d.ts → server.B3Tm0IXY.d.ts} +2 -2
  23. package/dist/shared/{server.CPteJIPP.d.mts → server.BYTulgUc.d.mts} +12 -11
  24. package/dist/shared/{server.CPteJIPP.d.ts → server.BYTulgUc.d.ts} +12 -11
  25. package/dist/shared/{server.CM3tWr3C.d.mts → server.BeJithK4.d.mts} +2 -2
  26. package/dist/shared/{server.CMrS28Go.mjs → server.BtxZnWJ9.mjs} +35 -7
  27. package/dist/shared/server.Bz_xNBjz.d.mts +8 -0
  28. package/dist/shared/{server.Cq3B6PoL.mjs → server.DoP20NVH.mjs} +6 -5
  29. package/dist/shared/server.EhgR_5_I.d.ts +8 -0
  30. package/dist/shared/{server.CSZRzcSW.mjs → server.jG7ZuX3S.mjs} +4 -4
  31. package/package.json +7 -7
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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, ORPCErrorFromErrorMap, 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 ConflictContextGuard, d as MergedContext, 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.CPteJIPP.js';
4
- export { E as InferRouterCurrentContexts, D as InferRouterInitialContexts, F as InferRouterInputs, G as InferRouterOutputs, k as LAZY_SYMBOL, l as LazyMeta, s as MiddlewareNextFn, r as MiddlewareNextFnOptions, v as MiddlewareOptions, t as MiddlewareOutputFn, q as MiddlewareResult, P as ProcedureClientInterceptorOptions, y as ProcedureDef, x as ProcedureHandlerOptions, B as createProcedureClient, p as getLazyMeta, o as isLazy, z as isProcedure, n as lazy, m as mergeContext, w as middlewareOutputFn, u as unlazy } from './shared/server.CPteJIPP.js';
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 ContextExtendsGuard, d as MergedCurrentContext, e as MergedInitialContext, f as MapInputMiddleware, g as CreateProcedureClientOptions, h as ProcedureClient, i as AnyMiddleware, L as Lazyable, a as AnyRouter, j as Lazy, A as AnyProcedure, k as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.BYTulgUc.js';
4
+ export { K as InferRouterCurrentContexts, J as InferRouterInitialContexts, N as InferRouterInputs, Q as InferRouterOutputs, p as LAZY_SYMBOL, q as LazyMeta, y as MiddlewareNextFn, x as MiddlewareNextFnOptions, B as MiddlewareOptions, z as MiddlewareOutputFn, w as MiddlewareResult, n as ORPCErrorConstructorMapItem, l as ORPCErrorConstructorMapItemOptions, P as ProcedureClientInterceptorOptions, F as ProcedureDef, E as ProcedureHandlerOptions, o as createORPCErrorConstructorMap, H as createProcedureClient, t as getLazyMeta, s as isLazy, G as isProcedure, r as lazy, m as mergeCurrentContext, D as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.BYTulgUc.js';
5
5
  import { ClientContext, ClientRest, ClientPromiseResult } from '@orpc/client';
6
6
  export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
7
  import { MaybeOptionalOptions } from '@orpc/shared';
@@ -12,8 +12,8 @@ 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<U extends Context>(middleware: Middleware<TCurrentContext, U, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
16
- use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
15
+ use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & ContextExtendsGuard<MergedCurrentContext<TCurrentContext, UOutContext>, TCurrentContext> & DecoratedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
16
+ use<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ContextExtendsGuard<TCurrentContext, UInContext> & ContextExtendsGuard<MergedCurrentContext<TCurrentContext, UOutContext>, TCurrentContext> & 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
  */
@@ -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<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
63
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & 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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
79
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & 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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
89
- 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
89
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & 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, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ContextExtendsGuard<TCurrentContext, UInContext> & 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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
99
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & 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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
108
- 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
108
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & 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, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ContextExtendsGuard<TCurrentContext, UInContext> & 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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & RouterBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
117
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & 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
  mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
127
- concat<UOutContext extends Context>(middleware: Middleware<TInContext & TOutContext, UOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, MergedContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
128
- concat<UOutContext extends Context, UMappedInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<TInput, UMappedInput>): DecoratedMiddleware<TInContext, MergedContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
128
+ concat<UOutContext extends Context, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext, UOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): ContextExtendsGuard<MergedCurrentContext<TInContext, TOutContext>, UInContext> & 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, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<TInput, UMappedInput>): ContextExtendsGuard<MergedCurrentContext<TInContext, TOutContext>, UInContext> & 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,21 @@ 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<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, TMeta>;
165
+ middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<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>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, 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, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
168
+ use<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<unknown, UInput>): ContextExtendsGuard<TCurrentContext, UInContext> & BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
167
169
  meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
168
170
  route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
169
171
  input<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
@@ -171,16 +173,17 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
171
173
  handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
172
174
  prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
173
175
  tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
174
- router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TErrorMap>;
176
+ router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
175
177
  lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
176
178
  default: U;
177
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TErrorMap>;
179
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
178
180
  }
179
181
  declare const os: Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
180
182
 
181
183
  interface Config {
182
184
  initialInputValidationIndex: number;
183
185
  initialOutputValidationIndex: number;
186
+ dedupeLeadingMiddlewares: boolean;
184
187
  }
185
188
  declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
186
189
 
@@ -188,8 +191,8 @@ declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T
188
191
  * Like `DecoratedProcedure`, but removed all method that can change the contract.
189
192
  */
190
193
  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<U extends Context>(middleware: Middleware<TCurrentContext, U, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
192
- use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
194
+ use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & ContextExtendsGuard<MergedCurrentContext<TCurrentContext, UOutContext>, TCurrentContext> & ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
195
+ use<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ContextExtendsGuard<TCurrentContext, UInContext> & ContextExtendsGuard<MergedCurrentContext<TCurrentContext, UOutContext>, TCurrentContext> & ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
193
196
  /**
194
197
  * Make this procedure callable (works like a function while still being a procedure).
195
198
  */
@@ -204,17 +207,17 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
204
207
  */
205
208
  interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
206
209
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
207
- 'use'<U extends Context>(middleware: Middleware<TCurrentContext, U, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
208
- 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
210
+ 'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ContextExtendsGuard<TCurrentContext, UInContext> & ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
211
+ 'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ContextExtendsGuard<TCurrentContext, UInContext> & ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
209
212
  'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
210
213
  }
211
214
 
212
215
  interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
213
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<T, TInitialContext, MergedContext<TCurrentContext, U>>;
214
- router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, Record<never, never>>;
216
+ use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ContextExtendsGuard<TCurrentContext, UInContext> & ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
217
+ router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
215
218
  lazy<U extends Router<T, TInitialContext>>(loader: () => Promise<{
216
219
  default: U;
217
- }>): EnhancedRouter<Lazy<U>, TInitialContext, Record<never, never>>;
220
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
218
221
  }
219
222
  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
223
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
@@ -222,22 +225,28 @@ type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TIn
222
225
 
223
226
  interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
224
227
  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<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, InferContractRouterMeta<T>>;
226
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<T, TInitialContext, MergedContext<TCurrentContext, U>>;
227
- router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, Record<never, never>>;
228
+ middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, InferContractRouterMeta<T>>;
229
+ use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ContextExtendsGuard<TCurrentContext, UInContext> & ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
230
+ router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
228
231
  lazy<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
229
232
  default: U;
230
- }>): EnhancedRouter<Lazy<U>, TInitialContext, Record<never, never>>;
233
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
231
234
  }
232
235
  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
236
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
234
237
  });
235
238
  declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
236
239
  type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
237
- $context<U extends Context>(): Implementer<TContract, U, U>;
240
+ $context<U extends Context>(): Implementer<TContract, U & Record<never, never>, U>;
238
241
  $config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
239
242
  } & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
240
- declare function implement<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config?: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
243
+ declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
244
+
245
+ declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
246
+ declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
247
+ dedupeLeading: boolean;
248
+ }): readonly AnyMiddleware[];
249
+ declare function addMiddleware(middlewares: readonly AnyMiddleware[], addition: AnyMiddleware): AnyMiddleware[];
241
250
 
242
251
  declare function createAssertedLazyProcedure(lazied: Lazy<any>): Lazy<AnyProcedure>;
243
252
  /**
@@ -266,4 +275,4 @@ declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContrac
266
275
 
267
276
  declare function toHttpPath(path: readonly string[]): HTTPPath;
268
277
 
269
- export { type AccessibleLazyRouter, AnyMiddleware, AnyProcedure, AnyRouter, Builder, type BuilderConfig, type BuilderDef, type BuilderWithMiddlewares, type Config, ConflictContextGuard, 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, MergedContext, Middleware, 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, call, createAccessibleLazyRouter, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, os, resolveContractProcedures, setHiddenRouterContract, toHttpPath, traverseContractProcedures, unlazyRouter };
278
+ export { type AccessibleLazyRouter, AnyMiddleware, AnyProcedure, AnyRouter, Builder, type BuilderConfig, type BuilderDef, type BuilderWithMiddlewares, type Config, Context, ContextExtendsGuard, 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.CMrS28Go.mjs';
4
- export { L as LAZY_SYMBOL, k as call, o as createAccessibleLazyRouter, b as createContractedProcedure, n as getHiddenRouterContract, j as getLazyMeta, m as middlewareOutputFn, r as resolveContractProcedures, a as toHttpPath, t as traverseContractProcedures, u as unlazy, p as unlazyRouter } from './shared/server.CMrS28Go.mjs';
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) {
@@ -104,6 +105,7 @@ class Builder {
104
105
  return new Builder({
105
106
  ...this["~orpc"],
106
107
  config,
108
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares),
107
109
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
108
110
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
109
111
  });
@@ -217,13 +219,10 @@ const os = new Builder({
217
219
  errorMap: {},
218
220
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
219
221
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
220
- middlewares: []
222
+ middlewares: [],
223
+ dedupeLeadingMiddlewares: true
221
224
  });
222
225
 
223
- function mergeContext(context, other) {
224
- return { ...context, ...other };
225
- }
226
-
227
226
  function implementerInternal(contract, config, middlewares) {
228
227
  if (isContractProcedure(contract)) {
229
228
  const impl2 = new Builder({
@@ -231,7 +230,8 @@ function implementerInternal(contract, config, middlewares) {
231
230
  config,
232
231
  middlewares,
233
232
  inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
234
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
233
+ outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length,
234
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
235
235
  });
236
236
  return impl2;
237
237
  }
@@ -257,7 +257,8 @@ function implementerInternal(contract, config, middlewares) {
257
257
  middlewares,
258
258
  errorMap: {},
259
259
  prefix: void 0,
260
- tags: void 0
260
+ tags: void 0,
261
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
261
262
  });
262
263
  return setHiddenRouterContract(adapted, contract);
263
264
  };
@@ -267,7 +268,8 @@ function implementerInternal(contract, config, middlewares) {
267
268
  middlewares,
268
269
  errorMap: {},
269
270
  prefix: void 0,
270
- tags: void 0
271
+ tags: void 0,
272
+ dedupeLeadingMiddlewares: fallbackConfig("dedupeLeadingMiddlewares", config.dedupeLeadingMiddlewares)
271
273
  });
272
274
  return setHiddenRouterContract(adapted, contract);
273
275
  };
@@ -300,17 +302,14 @@ function implement(contract, config = {}) {
300
302
  method = (config2) => implement(contract, config2);
301
303
  }
302
304
  const next = Reflect.get(target, key);
303
- if (!next || typeof next !== "function" && typeof next !== "object") {
304
- return method ?? next;
305
- }
306
- if (method) {
307
- return new Proxy(method, {
308
- get(_, key2) {
309
- return Reflect.get(next, key2);
310
- }
311
- });
305
+ if (!method || !next || typeof next !== "function" && typeof next !== "object") {
306
+ return method || next;
312
307
  }
313
- return next;
308
+ return new Proxy(method, {
309
+ get(_, key2) {
310
+ return Reflect.get(next, key2);
311
+ }
312
+ });
314
313
  }
315
314
  });
316
315
  return impl;
@@ -340,4 +339,4 @@ function createRouterClient(router, ...[options]) {
340
339
  return recursive;
341
340
  }
342
341
 
343
- export { Builder, DecoratedProcedure, Procedure, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, mergeContext, os, setHiddenRouterContract };
342
+ export { Builder, DecoratedProcedure, Procedure, addMiddleware, createAssertedLazyProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getRouter, implement, implementerInternal, isLazy, isProcedure, lazy, os, setHiddenRouterContract };
@@ -1,7 +1,7 @@
1
- import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CM3tWr3C.mjs';
2
- export { C as CompositePlugin } from '../shared/server.CM3tWr3C.mjs';
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.BeJithK4.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.BeJithK4.mjs';
3
3
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.CPteJIPP.mjs';
4
+ import { C as Context } from '../shared/server.BYTulgUc.mjs';
5
5
  import '@orpc/contract';
6
6
  import '@orpc/standard-server';
7
7
  import '@orpc/client';
@@ -1,7 +1,7 @@
1
- import { a as StandardHandlerInterceptorOptions, H as HandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DmW25ynm.js';
2
- export { C as CompositePlugin } from '../shared/server.DmW25ynm.js';
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.B3Tm0IXY.js';
2
+ export { C as CompositePlugin } from '../shared/server.B3Tm0IXY.js';
3
3
  import { Value } from '@orpc/shared';
4
- import { C as Context } from '../shared/server.CPteJIPP.js';
4
+ import { C as Context } from '../shared/server.BYTulgUc.js';
5
5
  import '@orpc/contract';
6
6
  import '@orpc/standard-server';
7
7
  import '@orpc/client';
@@ -1,7 +1,7 @@
1
1
  import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
2
2
  import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
3
3
  import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
4
- import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.CPteJIPP.js';
4
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.BYTulgUc.js';
5
5
  import { ORPCError } from '@orpc/client';
6
6
 
7
7
  type StandardParams = Record<string, string>;
@@ -72,4 +72,4 @@ declare class CompositePlugin<TContext extends Context> implements HandlerPlugin
72
72
  init(options: StandardHandlerOptions<TContext>): void;
73
73
  }
74
74
 
75
- export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
75
+ export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardHandlerInterceptorOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
@@ -1,19 +1,20 @@
1
1
  import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
2
- import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
2
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
3
  import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
4
 
5
5
  type Context = Record<string, any>;
6
- type MergedContext<T extends Context, U extends Context> = T & U;
7
- declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
8
- type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
9
- [K in keyof T]: IsNever<T[K]>;
10
- }[keyof T] ? never : unknown;
6
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
9
+ type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
11
10
 
12
11
  type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
13
12
  type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
14
13
  type ORPCErrorConstructorMap<T extends ErrorMap> = {
15
14
  [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
16
15
  };
16
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
17
+ declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
17
18
 
18
19
  declare const LAZY_SYMBOL: unique symbol;
19
20
  interface LazyMeta {
@@ -51,7 +52,7 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutp
51
52
  }
52
53
  interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
53
54
  __initialContext?: (type: TInitialContext) => unknown;
54
- middlewares: AnyMiddleware[];
55
+ middlewares: readonly AnyMiddleware[];
55
56
  inputValidationIndex: number;
56
57
  outputValidationIndex: number;
57
58
  handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
@@ -72,8 +73,8 @@ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never>
72
73
  } : {
73
74
  context: TOutContext;
74
75
  };
75
- interface MiddlewareNextFn<TInContext extends Context, TOutput> {
76
- <U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
76
+ interface MiddlewareNextFn<TOutput> {
77
+ <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
77
78
  }
78
79
  interface MiddlewareOutputFn<TOutput> {
79
80
  (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
@@ -84,7 +85,7 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
84
85
  procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
85
86
  signal?: AbortSignal;
86
87
  lastEventId: string | undefined;
87
- next: MiddlewareNextFn<TInContext, TOutput>;
88
+ next: MiddlewareNextFn<TOutput>;
88
89
  errors: TErrorConstructorMap;
89
90
  }
90
91
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
@@ -140,4 +141,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
140
141
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
142
  };
142
143
 
143
- export { type AnyProcedure as A, createProcedureClient as B, type Context as C, type InferRouterInitialContexts as D, type InferRouterCurrentContexts as E, type InferRouterInputs as F, type InferRouterOutputs as G, type InferRouterInitialContext as I, type Lazyable as L, type Middleware as M, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, LAZY_SYMBOL as k, type LazyMeta as l, mergeContext as m, lazy as n, isLazy as o, getLazyMeta as p, type MiddlewareResult as q, type MiddlewareNextFnOptions as r, type MiddlewareNextFn as s, type MiddlewareOutputFn as t, unlazy as u, type MiddlewareOptions as v, middlewareOutputFn as w, type ProcedureHandlerOptions as x, type ProcedureDef as y, isProcedure as z };
144
+ export { type AnyProcedure as A, type MiddlewareOptions as B, type Context as C, middlewareOutputFn as D, type ProcedureHandlerOptions as E, type ProcedureDef as F, isProcedure as G, createProcedureClient as H, type InferRouterInitialContext as I, type InferRouterInitialContexts as J, type InferRouterCurrentContexts as K, type Lazyable as L, type Middleware as M, type InferRouterInputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type InferRouterOutputs as Q, type Router as R, type AnyRouter as a, Procedure as b, type ContextExtendsGuard as c, type MergedCurrentContext as d, type MergedInitialContext as e, type MapInputMiddleware as f, type CreateProcedureClientOptions as g, type ProcedureClient as h, type AnyMiddleware as i, type Lazy as j, type ProcedureHandler as k, type ORPCErrorConstructorMapItemOptions as l, mergeCurrentContext as m, type ORPCErrorConstructorMapItem as n, createORPCErrorConstructorMap as o, LAZY_SYMBOL as p, type LazyMeta as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, validateORPCError as v, type MiddlewareResult as w, type MiddlewareNextFnOptions as x, type MiddlewareNextFn as y, type MiddlewareOutputFn as z };
@@ -1,19 +1,20 @@
1
1
  import { ORPCErrorCode, ORPCErrorOptions, ORPCError, ClientContext, Client } from '@orpc/client';
2
- import { IsNever, MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
2
+ import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@orpc/shared';
3
3
  import { ErrorMap, ErrorMapItem, InferSchemaInput, HTTPPath, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract';
4
4
 
5
5
  type Context = Record<string, any>;
6
- type MergedContext<T extends Context, U extends Context> = T & U;
7
- declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
8
- type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
9
- [K in keyof T]: IsNever<T[K]>;
10
- }[keyof T] ? never : unknown;
6
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
7
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
8
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
9
+ type ContextExtendsGuard<T extends Context, U extends Context> = T extends U ? unknown : never;
11
10
 
12
11
  type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
13
12
  type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
14
13
  type ORPCErrorConstructorMap<T extends ErrorMap> = {
15
14
  [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
16
15
  };
16
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
17
+ declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
17
18
 
18
19
  declare const LAZY_SYMBOL: unique symbol;
19
20
  interface LazyMeta {
@@ -51,7 +52,7 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutp
51
52
  }
52
53
  interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
53
54
  __initialContext?: (type: TInitialContext) => unknown;
54
- middlewares: AnyMiddleware[];
55
+ middlewares: readonly AnyMiddleware[];
55
56
  inputValidationIndex: number;
56
57
  outputValidationIndex: number;
57
58
  handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
@@ -72,8 +73,8 @@ type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never>
72
73
  } : {
73
74
  context: TOutContext;
74
75
  };
75
- interface MiddlewareNextFn<TInContext extends Context, TOutput> {
76
- <U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
76
+ interface MiddlewareNextFn<TOutput> {
77
+ <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
77
78
  }
78
79
  interface MiddlewareOutputFn<TOutput> {
79
80
  (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
@@ -84,7 +85,7 @@ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstruct
84
85
  procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
85
86
  signal?: AbortSignal;
86
87
  lastEventId: string | undefined;
87
- next: MiddlewareNextFn<TInContext, TOutput>;
88
+ next: MiddlewareNextFn<TOutput>;
88
89
  errors: TErrorConstructorMap;
89
90
  }
90
91
  interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
@@ -140,4 +141,4 @@ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any
140
141
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
141
142
  };
142
143
 
143
- export { type AnyProcedure as A, createProcedureClient as B, type Context as C, type InferRouterInitialContexts as D, type InferRouterCurrentContexts as E, type InferRouterInputs as F, type InferRouterOutputs as G, type InferRouterInitialContext as I, type Lazyable as L, type Middleware as M, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type Router as R, type AnyRouter as a, Procedure as b, type ConflictContextGuard as c, type MergedContext as d, type MapInputMiddleware as e, type CreateProcedureClientOptions as f, type ProcedureClient as g, type AnyMiddleware as h, type Lazy as i, type ProcedureHandler as j, LAZY_SYMBOL as k, type LazyMeta as l, mergeContext as m, lazy as n, isLazy as o, getLazyMeta as p, type MiddlewareResult as q, type MiddlewareNextFnOptions as r, type MiddlewareNextFn as s, type MiddlewareOutputFn as t, unlazy as u, type MiddlewareOptions as v, middlewareOutputFn as w, type ProcedureHandlerOptions as x, type ProcedureDef as y, isProcedure as z };
144
+ export { type AnyProcedure as A, type MiddlewareOptions as B, type Context as C, middlewareOutputFn as D, type ProcedureHandlerOptions as E, type ProcedureDef as F, isProcedure as G, createProcedureClient as H, type InferRouterInitialContext as I, type InferRouterInitialContexts as J, type InferRouterCurrentContexts as K, type Lazyable as L, type Middleware as M, type InferRouterInputs as N, type ORPCErrorConstructorMap as O, type ProcedureClientInterceptorOptions as P, type InferRouterOutputs as Q, type Router as R, type AnyRouter as a, Procedure as b, type ContextExtendsGuard as c, type MergedCurrentContext as d, type MergedInitialContext as e, type MapInputMiddleware as f, type CreateProcedureClientOptions as g, type ProcedureClient as h, type AnyMiddleware as i, type Lazy as j, type ProcedureHandler as k, type ORPCErrorConstructorMapItemOptions as l, mergeCurrentContext as m, type ORPCErrorConstructorMapItem as n, createORPCErrorConstructorMap as o, LAZY_SYMBOL as p, type LazyMeta as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u, validateORPCError as v, type MiddlewareResult as w, type MiddlewareNextFnOptions as x, type MiddlewareNextFn as y, type MiddlewareOutputFn as z };