@orpc/server 0.0.0-next.93e6063 → 0.0.0-next.93fa264

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 (64) hide show
  1. package/README.md +28 -20
  2. package/dist/adapters/aws-lambda/index.d.mts +45 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +45 -0
  4. package/dist/adapters/aws-lambda/index.mjs +41 -0
  5. package/dist/adapters/bun-ws/index.d.mts +35 -0
  6. package/dist/adapters/bun-ws/index.d.ts +35 -0
  7. package/dist/adapters/bun-ws/index.mjs +46 -0
  8. package/dist/adapters/crossws/index.d.mts +30 -0
  9. package/dist/adapters/crossws/index.d.ts +30 -0
  10. package/dist/adapters/crossws/index.mjs +46 -0
  11. package/dist/adapters/fetch/index.d.mts +62 -11
  12. package/dist/adapters/fetch/index.d.ts +62 -11
  13. package/dist/adapters/fetch/index.mjs +108 -7
  14. package/dist/adapters/message-port/index.d.mts +28 -0
  15. package/dist/adapters/message-port/index.d.ts +28 -0
  16. package/dist/adapters/message-port/index.mjs +41 -0
  17. package/dist/adapters/node/index.d.mts +64 -22
  18. package/dist/adapters/node/index.d.ts +64 -22
  19. package/dist/adapters/node/index.mjs +86 -21
  20. package/dist/adapters/standard/index.d.mts +12 -15
  21. package/dist/adapters/standard/index.d.ts +12 -15
  22. package/dist/adapters/standard/index.mjs +4 -4
  23. package/dist/adapters/websocket/index.d.mts +51 -0
  24. package/dist/adapters/websocket/index.d.ts +51 -0
  25. package/dist/adapters/websocket/index.mjs +69 -0
  26. package/dist/adapters/ws/index.d.mts +28 -0
  27. package/dist/adapters/ws/index.d.ts +28 -0
  28. package/dist/adapters/ws/index.mjs +39 -0
  29. package/dist/hibernation/index.d.mts +44 -0
  30. package/dist/hibernation/index.d.ts +44 -0
  31. package/dist/hibernation/index.mjs +65 -0
  32. package/dist/index.d.mts +711 -132
  33. package/dist/index.d.ts +711 -132
  34. package/dist/index.mjs +207 -52
  35. package/dist/plugins/index.d.mts +144 -19
  36. package/dist/plugins/index.d.ts +144 -19
  37. package/dist/plugins/index.mjs +165 -15
  38. package/dist/shared/server.-ACo36I0.d.ts +74 -0
  39. package/dist/shared/server.BPAWobQg.d.ts +12 -0
  40. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  41. package/dist/shared/server.Bd52nNaH.d.mts +12 -0
  42. package/dist/shared/server.BliFSTnG.d.mts +10 -0
  43. package/dist/shared/{server.BBGuTxHE.mjs → server.CHvOkcM3.mjs} +69 -46
  44. package/dist/shared/server.DD2C4ujN.d.mts +192 -0
  45. package/dist/shared/server.DD2C4ujN.d.ts +192 -0
  46. package/dist/shared/{server.V6zT5iYQ.mjs → server.DG7Tamti.mjs} +161 -173
  47. package/dist/shared/server.DZ5BIITo.mjs +9 -0
  48. package/dist/shared/server.Dq8xr7PQ.d.mts +74 -0
  49. package/dist/shared/server.IG2MjhrD.d.ts +10 -0
  50. package/package.json +59 -20
  51. package/dist/adapters/hono/index.d.mts +0 -20
  52. package/dist/adapters/hono/index.d.ts +0 -20
  53. package/dist/adapters/hono/index.mjs +0 -32
  54. package/dist/adapters/next/index.d.mts +0 -27
  55. package/dist/adapters/next/index.d.ts +0 -27
  56. package/dist/adapters/next/index.mjs +0 -29
  57. package/dist/shared/server.B-ewprcf.d.ts +0 -77
  58. package/dist/shared/server.CA-o8cUY.d.mts +0 -9
  59. package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
  60. package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
  61. package/dist/shared/server.DJrh0Ceu.d.mts +0 -77
  62. package/dist/shared/server.DPQt9YYq.d.ts +0 -9
  63. package/dist/shared/server.KwueCzFr.mjs +0 -26
  64. package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
package/dist/index.d.mts CHANGED
@@ -1,220 +1,810 @@
1
- import { Schema, ErrorMap, Meta, MergedErrorMap, Route, SchemaOutput, SchemaInput, HTTPPath, ContractRouter, ContractProcedureDef, AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ErrorFromErrorMap, AnyContractProcedure } from '@orpc/contract';
2
- export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, HTTPMethod, HTTPPath, InputStructure, Meta, ORPCErrorFromErrorMap, OutputStructure, Route, Schema, SchemaInput, SchemaOutput, ValidationError, eventIterator, type } from '@orpc/contract';
3
- import { L as Lazy, A as AnyProcedure, 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 ProcedureHandler, i as AdaptRouterOptions, R as Router, j as AdaptedRouter, k as AnyMiddleware, a as AnyRouter, l as Lazyable, I as InferRouterInitialContext } from './shared/server.Cn9ybJtE.mjs';
4
- export { K as AccessibleLazyRouter, F as InferRouterInputs, G as InferRouterOutputs, n as LAZY_LOADER_SYMBOL, o as LazyMeta, p as LazyOptions, v as MiddlewareNextFn, t as MiddlewareNextFnOptions, x as MiddlewareOptions, w as MiddlewareOutputFn, s as MiddlewareResult, P as ProcedureClientInterceptorOptions, B as ProcedureDef, z as ProcedureHandlerOptions, H as adaptRouter, N as createAccessibleLazyRouter, E as createProcedureClient, J as getRouterChild, r as isLazy, D as isProcedure, q as lazy, m as mergeContext, y as middlewareOutputFn, u as unlazy } from './shared/server.Cn9ybJtE.mjs';
5
- import { ClientContext, ClientRest, ClientPromiseResult } from '@orpc/client';
6
- export { ORPCError, isDefinedError, safe } from '@orpc/client';
7
- import { MaybeOptionalOptions } from '@orpc/shared';
8
- export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
1
+ import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, HTTPMethod, ClientPromiseResult } from '@orpc/client';
2
+ export { ClientContext, HTTPMethod, HTTPPath, ORPCError, isDefinedError, safe } from '@orpc/client';
3
+ import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
4
+ export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
5
+ import { ThrowableError, IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
6
+ export { EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, IntersectPick, Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
7
+ import { C as Context, P as Procedure, M as Middleware, O as ORPCErrorConstructorMap, a as MergedInitialContext, b as MergedCurrentContext, c as MapInputMiddleware, d as CreateProcedureClientOptions, e as ProcedureClient, A as AnyMiddleware, L as Lazyable, f as AnyRouter, g as Lazy, h as AnyProcedure, i as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.DD2C4ujN.mjs';
8
+ export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, n as LAZY_SYMBOL, o as LazyMeta, w as MiddlewareNextFn, t as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, s as MiddlewareResult, k as ORPCErrorConstructorMapItem, j as ORPCErrorConstructorMapItemOptions, F as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, l as createORPCErrorConstructorMap, G as createProcedureClient, r as getLazyMeta, q as isLazy, E as isProcedure, p as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.DD2C4ujN.mjs';
9
9
  export { getEventMeta, withEventMeta } from '@orpc/standard-server';
10
10
 
11
- type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
12
- declare function flatLazy<T extends Lazy<any>>(lazied: T): FlattenLazy<T>;
13
- declare function createLazyProcedureFormAnyLazy(lazied: Lazy<any>): Lazy<AnyProcedure>;
11
+ type ActionableError<T> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
12
+ defined: true;
13
+ } : ORPCErrorJSON<string, unknown> & {
14
+ defined: false;
15
+ };
16
+ type UnactionableError<T> = T extends {
17
+ defined: true;
18
+ } & ORPCErrorJSON<infer U, infer V> ? ORPCError<U, V> : ThrowableError;
19
+ type ActionableClientRest<TInput> = [input: TInput] | (undefined extends TInput ? [input?: TInput] : [input: TInput]);
20
+ type ActionableClientResult<TOutput, TError extends ORPCErrorJSON<any, any>> = [error: null, data: TOutput] | [error: TError, data: undefined];
21
+ interface ActionableClient<TInput, TOutput, TError extends ORPCErrorJSON<any, any>> {
22
+ (...rest: ActionableClientRest<TInput>): Promise<ActionableClientResult<TOutput, TError>>;
23
+ }
24
+ type ProcedureActionableClient<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = ActionableClient<InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ActionableError<ErrorFromErrorMap<TErrorMap>>>;
25
+ declare function createActionableClient<TInput, TOutput, TError>(client: Client<Record<never, never>, TInput, TOutput, TError>): ActionableClient<TInput, TOutput, ActionableError<TError>>;
14
26
 
15
- declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
16
- errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, MergedErrorMap<TErrorMap, U>, TMeta>;
17
- meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
18
- route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
19
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
20
- use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
27
+ declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> {
28
+ /**
29
+ * Adds type-safe custom errors.
30
+ * The provided errors are spared-merged with any existing errors.
31
+ *
32
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
33
+ */
34
+ errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
35
+ /**
36
+ * Sets or updates the metadata.
37
+ * The provided metadata is spared-merged with any existing metadata.
38
+ *
39
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
40
+ */
41
+ meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
42
+ /**
43
+ * Sets or updates the route definition.
44
+ * The provided route is spared-merged with any existing route.
45
+ * This option is typically relevant when integrating with OpenAPI.
46
+ *
47
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
48
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
49
+ */
50
+ route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
51
+ /**
52
+ * Uses a middleware to modify the context or improve the pipeline.
53
+ *
54
+ * @info Supports both normal middleware and inline middleware implementations.
55
+ * @info Pass second argument to map the input.
56
+ * @note The current context must be satisfy middleware dependent-context
57
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
58
+ */
59
+ 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>;
60
+ /**
61
+ * Uses a middleware to modify the context or improve the pipeline.
62
+ *
63
+ * @info Supports both normal middleware and inline middleware implementations.
64
+ * @info Pass second argument to map the input.
65
+ * @note The current context must be satisfy middleware dependent-context
66
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
67
+ */
68
+ 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>;
21
69
  /**
22
70
  * Make this procedure callable (works like a function while still being a procedure).
71
+ *
72
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
23
73
  */
24
- callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
74
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
25
75
  /**
26
- * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
76
+ * Make this procedure compatible with server action.
77
+ *
78
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
27
79
  */
28
- actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
80
+ actionable(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap>;
29
81
  }
30
82
 
31
- interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
83
+ declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
84
+ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
85
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
86
+ };
87
+ declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
88
+ 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> : {
89
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
90
+ };
91
+ interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
92
+ middlewares: readonly AnyMiddleware[];
93
+ errorMap: TErrorMap;
94
+ dedupeLeadingMiddlewares: boolean;
95
+ }
96
+ 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>;
97
+ interface TraverseContractProceduresOptions {
98
+ router: AnyContractRouter | AnyRouter;
99
+ path: readonly string[];
100
+ }
101
+ interface ContractProcedureCallbackOptions {
102
+ contract: AnyContractProcedure;
103
+ path: readonly string[];
104
+ }
105
+ interface LazyTraverseContractProceduresOptions {
106
+ router: Lazy<AnyRouter>;
107
+ path: readonly string[];
108
+ }
109
+ declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
110
+ declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void): Promise<void>;
111
+ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
112
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
113
+ };
114
+ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
115
+
116
+ interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
117
+ /**
118
+ * This property holds the defined options.
119
+ */
32
120
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
121
+ /**
122
+ * Adds type-safe custom errors.
123
+ * The provided errors are spared-merged with any existing errors.
124
+ *
125
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
126
+ */
33
127
  'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
34
- '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>;
128
+ /**
129
+ * Uses a middleware to modify the context or improve the pipeline.
130
+ *
131
+ * @info Supports both normal middleware and inline middleware implementations.
132
+ * @note The current context must be satisfy middleware dependent-context
133
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
134
+ */
135
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
136
+ /**
137
+ * Sets or updates the metadata.
138
+ * The provided metadata is spared-merged with any existing metadata.
139
+ *
140
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
141
+ */
35
142
  'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
143
+ /**
144
+ * Sets or updates the route definition.
145
+ * The provided route is spared-merged with any existing route.
146
+ * This option is typically relevant when integrating with OpenAPI.
147
+ *
148
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
149
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
150
+ */
36
151
  'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
37
- 'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
38
- 'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
39
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
152
+ /**
153
+ * Defines the input validation schema.
154
+ *
155
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
156
+ */
157
+ 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
158
+ /**
159
+ * Defines the output validation schema.
160
+ *
161
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
162
+ */
163
+ 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
164
+ /**
165
+ * Defines the handler of the procedure.
166
+ *
167
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
168
+ */
169
+ 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
170
+ /**
171
+ * Prefixes all procedures in the router.
172
+ * The provided prefix is post-appended to any existing router prefix.
173
+ *
174
+ * @note This option does not affect procedures that do not define a path in their route definition.
175
+ *
176
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
177
+ */
40
178
  'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
179
+ /**
180
+ * Adds tags to all procedures in the router.
181
+ * This helpful when you want to group procedures together in the OpenAPI specification.
182
+ *
183
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
184
+ */
41
185
  'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
42
- 'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
43
- 'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
186
+ /**
187
+ * Applies all of the previously defined options to the specified router.
188
+ *
189
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
190
+ */
191
+ 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
192
+ /**
193
+ * Create a lazy router
194
+ * And applies all of the previously defined options to the specified router.
195
+ *
196
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
197
+ */
198
+ 'lazy'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
44
199
  default: U;
45
- }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
200
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
46
201
  }
47
- interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
202
+ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
203
+ /**
204
+ * This property holds the defined options.
205
+ */
48
206
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
207
+ /**
208
+ * Adds type-safe custom errors.
209
+ * The provided errors are spared-merged with any existing errors.
210
+ *
211
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
212
+ */
49
213
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
50
- '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>;
214
+ /**
215
+ * Uses a middleware to modify the context or improve the pipeline.
216
+ *
217
+ * @info Supports both normal middleware and inline middleware implementations.
218
+ * @note The current context must be satisfy middleware dependent-context
219
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
220
+ */
221
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
222
+ /**
223
+ * Sets or updates the metadata.
224
+ * The provided metadata is spared-merged with any existing metadata.
225
+ *
226
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
227
+ */
51
228
  'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
229
+ /**
230
+ * Sets or updates the route definition.
231
+ * The provided route is spared-merged with any existing route.
232
+ * This option is typically relevant when integrating with OpenAPI.
233
+ *
234
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
235
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
236
+ */
52
237
  'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
53
- 'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
54
- 'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
55
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
238
+ /**
239
+ * Defines the input validation schema.
240
+ *
241
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
242
+ */
243
+ 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
244
+ /**
245
+ * Defines the output validation schema.
246
+ *
247
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
248
+ */
249
+ 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
250
+ /**
251
+ * Defines the handler of the procedure.
252
+ *
253
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
254
+ */
255
+ 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
56
256
  }
57
- interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
257
+ interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
258
+ /**
259
+ * This property holds the defined options.
260
+ */
58
261
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
262
+ /**
263
+ * Adds type-safe custom errors.
264
+ * The provided errors are spared-merged with any existing errors.
265
+ *
266
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
267
+ */
59
268
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
60
- 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
- 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
269
+ /**
270
+ * Uses a middleware to modify the context or improve the pipeline.
271
+ *
272
+ * @info Supports both normal middleware and inline middleware implementations.
273
+ * @info Pass second argument to map the input.
274
+ * @note The current context must be satisfy middleware dependent-context
275
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
276
+ */
277
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
278
+ /**
279
+ * Uses a middleware to modify the context or improve the pipeline.
280
+ *
281
+ * @info Supports both normal middleware and inline middleware implementations.
282
+ * @info Pass second argument to map the input.
283
+ * @note The current context must be satisfy middleware dependent-context
284
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
285
+ */
286
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
287
+ /**
288
+ * Sets or updates the metadata.
289
+ * The provided metadata is spared-merged with any existing metadata.
290
+ *
291
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
292
+ */
62
293
  'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
294
+ /**
295
+ * Sets or updates the route definition.
296
+ * The provided route is spared-merged with any existing route.
297
+ * This option is typically relevant when integrating with OpenAPI.
298
+ *
299
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
300
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
301
+ */
63
302
  'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
64
- 'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
65
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, SchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
303
+ /**
304
+ * Defines the output validation schema.
305
+ *
306
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
307
+ */
308
+ 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
309
+ /**
310
+ * Defines the handler of the procedure.
311
+ *
312
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
313
+ */
314
+ 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
66
315
  }
67
- interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
316
+ interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
317
+ /**
318
+ * This property holds the defined options.
319
+ */
68
320
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
321
+ /**
322
+ * Adds type-safe custom errors.
323
+ * The provided errors are spared-merged with any existing errors.
324
+ *
325
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
326
+ */
69
327
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
70
- 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
328
+ /**
329
+ * Uses a middleware to modify the context or improve the pipeline.
330
+ *
331
+ * @info Supports both normal middleware and inline middleware implementations.
332
+ * @note The current context must be satisfy middleware dependent-context
333
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
334
+ */
335
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
336
+ /**
337
+ * Sets or updates the metadata.
338
+ * The provided metadata is spared-merged with any existing metadata.
339
+ *
340
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
341
+ */
71
342
  'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
343
+ /**
344
+ * Sets or updates the route definition.
345
+ * The provided route is spared-merged with any existing route.
346
+ * This option is typically relevant when integrating with OpenAPI.
347
+ *
348
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
349
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
350
+ */
72
351
  'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
73
- 'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
74
- 'handler'(handler: ProcedureHandler<TCurrentContext, unknown, SchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, unknown, TErrorMap, TMeta>;
352
+ /**
353
+ * Defines the input validation schema.
354
+ *
355
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
356
+ */
357
+ 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
358
+ /**
359
+ * Defines the handler of the procedure.
360
+ *
361
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
362
+ */
363
+ 'handler'(handler: ProcedureHandler<TCurrentContext, unknown, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
75
364
  }
76
- interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
365
+ interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
366
+ /**
367
+ * This property holds the defined options.
368
+ */
77
369
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
370
+ /**
371
+ * Adds type-safe custom errors.
372
+ * The provided errors are spared-merged with any existing errors.
373
+ *
374
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
375
+ */
78
376
  'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
79
- 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
80
- 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
377
+ /**
378
+ * Uses a middleware to modify the context or improve the pipeline.
379
+ *
380
+ * @info Supports both normal middleware and inline middleware implementations.
381
+ * @info Pass second argument to map the input.
382
+ * @note The current context must be satisfy middleware dependent-context
383
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
384
+ */
385
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
386
+ /**
387
+ * Uses a middleware to modify the context or improve the pipeline.
388
+ *
389
+ * @info Supports both normal middleware and inline middleware implementations.
390
+ * @info Pass second argument to map the input.
391
+ * @note The current context must be satisfy middleware dependent-context
392
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
393
+ */
394
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
395
+ /**
396
+ * Sets or updates the metadata.
397
+ * The provided metadata is spared-merged with any existing metadata.
398
+ *
399
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
400
+ */
81
401
  'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
402
+ /**
403
+ * Sets or updates the route definition.
404
+ * The provided route is spared-merged with any existing route.
405
+ * This option is typically relevant when integrating with OpenAPI.
406
+ *
407
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
408
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
409
+ */
82
410
  'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
83
- 'handler'(handler: ProcedureHandler<TCurrentContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, unknown, TErrorMap, TMeta>;
411
+ /**
412
+ * Defines the handler of the procedure.
413
+ *
414
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
415
+ */
416
+ 'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
84
417
  }
85
418
  interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
86
- '~orpc': AdaptRouterOptions<TErrorMap>;
419
+ /**
420
+ * This property holds the defined options.
421
+ */
422
+ '~orpc': EnhanceRouterOptions<TErrorMap>;
423
+ /**
424
+ * Adds type-safe custom errors.
425
+ * The provided errors are spared-merged with any existing errors.
426
+ *
427
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
428
+ */
87
429
  'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
88
- 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & RouterBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
430
+ /**
431
+ * Uses a middleware to modify the context or improve the pipeline.
432
+ *
433
+ * @info Supports both normal middleware and inline middleware implementations.
434
+ * @note The current context must be satisfy middleware dependent-context
435
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
436
+ */
437
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
438
+ /**
439
+ * Prefixes all procedures in the router.
440
+ * The provided prefix is post-appended to any existing router prefix.
441
+ *
442
+ * @note This option does not affect procedures that do not define a path in their route definition.
443
+ *
444
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
445
+ */
89
446
  'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
447
+ /**
448
+ * Adds tags to all procedures in the router.
449
+ * This helpful when you want to group procedures together in the OpenAPI specification.
450
+ *
451
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
452
+ */
90
453
  'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
91
- 'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
92
- 'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
454
+ /**
455
+ * Applies all of the previously defined options to the specified router.
456
+ *
457
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
458
+ */
459
+ 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
460
+ /**
461
+ * Create a lazy router
462
+ * And applies all of the previously defined options to the specified router.
463
+ *
464
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
465
+ */
466
+ 'lazy'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
93
467
  default: U;
94
- }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
468
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
95
469
  }
96
470
 
97
471
  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> {
98
- concat<UOutContext extends Context, UInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, MergedContext<TOutContext, UOutContext>, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>;
99
- concat<UOutContext extends Context, UInput, UMappedInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>): DecoratedMiddleware<TInContext, TOutContext & UOutContext, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>;
100
- mapInput<UInput = unknown>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
472
+ /**
473
+ * Change the expected input type by providing a map function.
474
+ */
475
+ mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
476
+ /**
477
+ * Concatenates two middlewares.
478
+ *
479
+ * @info Pass second argument to map the input.
480
+ * @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
481
+ */
482
+ concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
483
+ /**
484
+ * Concatenates two middlewares.
485
+ *
486
+ * @info Pass second argument to map the input.
487
+ * @see {@link https://orpc.unnoq.com/docs/middleware#concatenation Middleware Concatenation Docs}
488
+ */
489
+ concat<UOutContext extends IntersectPick<MergedCurrentContext<TInContext, TOutContext>, UOutContext>, UInput extends TInput, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<UInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, UInput, TOutput, TErrorConstructorMap, TMeta>;
101
490
  }
102
491
  declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>;
103
492
 
104
493
  interface BuilderConfig {
105
494
  initialInputValidationIndex?: number;
106
495
  initialOutputValidationIndex?: number;
496
+ dedupeLeadingMiddlewares?: boolean;
107
497
  }
108
- interface BuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptRouterOptions<TErrorMap> {
109
- middlewares: AnyMiddleware[];
498
+ interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
499
+ middlewares: readonly AnyMiddleware[];
110
500
  inputValidationIndex: number;
111
501
  outputValidationIndex: number;
112
502
  config: BuilderConfig;
113
503
  }
114
- declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
504
+ declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
505
+ /**
506
+ * This property holds the defined options.
507
+ */
115
508
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
116
509
  constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
117
510
  /**
118
- * Reset config
511
+ * Sets or overrides the config.
512
+ *
513
+ * @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
514
+ * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
119
515
  */
120
516
  $config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
121
517
  /**
122
- * Reset initial context
518
+ * Set or override the initial context.
519
+ *
520
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
123
521
  */
124
- $context<U extends Context>(): Builder<U, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
522
+ $context<U extends Context>(): Builder<U & Record<never, never>, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
125
523
  /**
126
- * Reset initial meta
524
+ * Sets or overrides the initial meta.
525
+ *
526
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
127
527
  */
128
- $meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U>;
528
+ $meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
129
529
  /**
130
- * Reset initial route
530
+ * Sets or overrides the initial route.
531
+ * This option is typically relevant when integrating with OpenAPI.
532
+ *
533
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
534
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
131
535
  */
132
536
  $route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
133
- middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
134
- middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, TMeta>;
537
+ /**
538
+ * Sets or overrides the initial input schema.
539
+ *
540
+ * @see {@link https://orpc.unnoq.com/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
541
+ */
542
+ $input<U extends AnySchema>(initialInputSchema?: U): Builder<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap, TMeta>;
543
+ /**
544
+ * Creates a middleware.
545
+ *
546
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
547
+ */
548
+ middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
549
+ middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
550
+ /**
551
+ * Adds type-safe custom errors.
552
+ * The provided errors are spared-merged with any existing errors.
553
+ *
554
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
555
+ */
135
556
  errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
136
- 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>;
137
- 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>;
557
+ /**
558
+ * Uses a middleware to modify the context or improve the pipeline.
559
+ *
560
+ * @info Supports both normal middleware and inline middleware implementations.
561
+ * @note The current context must be satisfy middleware dependent-context
562
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
563
+ */
564
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
565
+ /**
566
+ * Sets or updates the metadata.
567
+ * The provided metadata is spared-merged with any existing metadata.
568
+ *
569
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
570
+ */
138
571
  meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
572
+ /**
573
+ * Sets or updates the route definition.
574
+ * The provided route is spared-merged with any existing route.
575
+ * This option is typically relevant when integrating with OpenAPI.
576
+ *
577
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
578
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
579
+ */
139
580
  route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
140
- input<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
141
- output<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
142
- handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
581
+ /**
582
+ * Defines the input validation schema.
583
+ *
584
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
585
+ */
586
+ input<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
587
+ /**
588
+ * Defines the output validation schema.
589
+ *
590
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
591
+ */
592
+ output<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
593
+ /**
594
+ * Defines the handler of the procedure.
595
+ *
596
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
597
+ */
598
+ handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
599
+ /**
600
+ * Prefixes all procedures in the router.
601
+ * The provided prefix is post-appended to any existing router prefix.
602
+ *
603
+ * @note This option does not affect procedures that do not define a path in their route definition.
604
+ *
605
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
606
+ */
143
607
  prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
608
+ /**
609
+ * Adds tags to all procedures in the router.
610
+ * This helpful when you want to group procedures together in the OpenAPI specification.
611
+ *
612
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
613
+ */
144
614
  tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
145
- router<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
146
- lazy<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
615
+ /**
616
+ * Applies all of the previously defined options to the specified router.
617
+ *
618
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
619
+ */
620
+ router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
621
+ /**
622
+ * Create a lazy router
623
+ * And applies all of the previously defined options to the specified router.
624
+ *
625
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
626
+ */
627
+ lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
147
628
  default: U;
148
- }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
629
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
149
630
  }
150
- declare const os: Builder<Context, Context, undefined, undefined, {}, {}>;
631
+ declare const os: Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
151
632
 
152
633
  interface Config {
153
634
  initialInputValidationIndex: number;
154
635
  initialOutputValidationIndex: number;
636
+ dedupeLeadingMiddlewares: boolean;
155
637
  }
156
638
  declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
157
639
 
158
- declare function setRouterContract<T extends AnyRouter>(obj: T, contract: AnyContractRouter): T;
159
- declare function getRouterContract(obj: object): ContractRouter<any> | undefined;
160
- declare function deepSetLazyRouterPrefix<T extends Lazy<any>>(router: T, prefix: HTTPPath): T;
161
- declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
162
-
163
640
  /**
164
641
  * Like `DecoratedProcedure`, but removed all method that can change the contract.
165
642
  */
166
- interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
167
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
168
- use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
643
+ 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> {
644
+ /**
645
+ * Uses a middleware to modify the context or improve the pipeline.
646
+ *
647
+ * @info Supports both normal middleware and inline middleware implementations.
648
+ * @info Pass second argument to map the input.
649
+ * @note The current context must be satisfy middleware dependent-context
650
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
651
+ */
652
+ 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>;
653
+ /**
654
+ * Uses a middleware to modify the context or improve the pipeline.
655
+ *
656
+ * @info Supports both normal middleware and inline middleware implementations.
657
+ * @info Pass second argument to map the input.
658
+ * @note The current context must be satisfy middleware dependent-context
659
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
660
+ */
661
+ 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>;
169
662
  /**
170
663
  * Make this procedure callable (works like a function while still being a procedure).
664
+ *
665
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
171
666
  */
172
- callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
667
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
173
668
  /**
174
- * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
669
+ * Make this procedure compatible with server action.
670
+ *
671
+ * @see {@link https://orpc.unnoq.com/docs/server-action Server Action Docs}
175
672
  */
176
- actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
673
+ actionable(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap>;
177
674
  }
178
675
  /**
179
676
  * Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
180
677
  */
181
- interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
678
+ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
182
679
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
183
- 'use'<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
184
- 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
185
- 'handler'(handler: ProcedureHandler<TCurrentContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, unknown, TErrorMap, TMeta>;
680
+ /**
681
+ * Uses a middleware to modify the context or improve the pipeline.
682
+ *
683
+ * @info Supports both normal middleware and inline middleware implementations.
684
+ * @info Pass second argument to map the input.
685
+ * @note The current context must be satisfy middleware dependent-context
686
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
687
+ */
688
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
689
+ /**
690
+ * Uses a middleware to modify the context or improve the pipeline.
691
+ *
692
+ * @info Supports both normal middleware and inline middleware implementations.
693
+ * @info Pass second argument to map the input.
694
+ * @note The current context must be satisfy middleware dependent-context
695
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
696
+ */
697
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
698
+ /**
699
+ * Defines the handler of the procedure.
700
+ *
701
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
702
+ */
703
+ 'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
186
704
  }
187
705
 
188
- interface RouterImplementerWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
189
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
190
- router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
191
- lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
706
+ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
707
+ /**
708
+ * Uses a middleware to modify the context or improve the pipeline.
709
+ *
710
+ * @info Supports both normal middleware and inline middleware implementations.
711
+ * @note The current context must be satisfy middleware dependent-context
712
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
713
+ */
714
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
715
+ /**
716
+ * Applies all of the previously defined options to the specified router.
717
+ * And enforces the router match the contract.
718
+ *
719
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
720
+ */
721
+ router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
722
+ /**
723
+ * Create a lazy router
724
+ * And applies all of the previously defined options to the specified router.
725
+ * And enforces the router match the contract.
726
+ *
727
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
728
+ */
729
+ lazy<U extends Router<T, TInitialContext>>(loader: () => Promise<{
192
730
  default: U;
193
- }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
731
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
194
732
  }
195
- 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> & {
733
+ 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> & {
196
734
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
197
- });
198
-
199
- interface RouterImplementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
200
- middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
201
- middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, ContractRouterToMeta<TContract>>;
202
- use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
203
- router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
204
- lazy<U extends Router<TCurrentContext, TContract>>(loader: () => Promise<{
735
+ };
736
+
737
+ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
738
+ /**
739
+ * Creates a middleware.
740
+ *
741
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
742
+ */
743
+ middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
744
+ middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, InferContractRouterMeta<T>>;
745
+ /**
746
+ * Uses a middleware to modify the context or improve the pipeline.
747
+ *
748
+ * @info Supports both normal middleware and inline middleware implementations.
749
+ * @note The current context must be satisfy middleware dependent-context
750
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
751
+ */
752
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
753
+ /**
754
+ * Applies all of the previously defined options to the specified router.
755
+ * And enforces the router match the contract.
756
+ *
757
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
758
+ */
759
+ router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
760
+ /**
761
+ * Create a lazy router
762
+ * And applies all of the previously defined options to the specified router.
763
+ * And enforces the router match the contract.
764
+ *
765
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
766
+ */
767
+ lazy<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
205
768
  default: U;
206
- }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
769
+ }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
207
770
  }
208
- 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> & {
771
+ 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> & {
209
772
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
210
- });
211
- declare function implementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
773
+ };
774
+ declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
212
775
  type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
213
- $context<U extends Context>(): Implementer<TContract, U, U>;
776
+ /**
777
+ * Set or override the initial context.
778
+ *
779
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
780
+ */
781
+ $context<U extends Context>(): Implementer<TContract, U & Record<never, never>, U>;
782
+ /**
783
+ * Sets or overrides the config.
784
+ *
785
+ * @see {@link https://orpc.unnoq.com/docs/lifecycle#middlewares-order Middlewares Order Docs}
786
+ * @see {@link https://orpc.unnoq.com/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
787
+ */
214
788
  $config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
215
789
  } & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
216
- declare function implement<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config?: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
790
+ declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
217
791
 
792
+ /**
793
+ * Help RPCLink automatically send requests using the specified HTTP method in the router.
794
+ */
795
+ declare function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>>;
796
+
797
+ declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
798
+ declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
799
+ dedupeLeading: boolean;
800
+ }): readonly AnyMiddleware[];
801
+ declare function addMiddleware(middlewares: readonly AnyMiddleware[], addition: AnyMiddleware): AnyMiddleware[];
802
+
803
+ declare function createAssertedLazyProcedure(lazied: Lazy<any>): Lazy<AnyProcedure>;
804
+ /**
805
+ * Create a new procedure that ensure the contract is applied to the procedure.
806
+ */
807
+ declare function createContractedProcedure(procedure: AnyProcedure, contract: AnyContractProcedure): AnyProcedure;
218
808
  /**
219
809
  * Directly call a procedure without creating a client.
220
810
  *
@@ -225,31 +815,20 @@ declare function implement<TContract extends AnyContractRouter, TInitialContext
225
815
  * ```
226
816
  *
227
817
  */
228
- declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>>, input: SchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, Record<never, never>>>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
818
+ declare function call<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, input: InferSchemaInput<TInputSchema>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): ClientPromiseResult<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
229
819
 
230
- type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
231
- [K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
820
+ type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
821
+ [K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
232
822
  };
233
- declare function createRouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext>(router: TRouter | Lazy<undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<TRouter>, undefined, undefined, unknown, ErrorMap, Meta, TClientContext>>): RouterClient<TRouter, TClientContext>;
234
-
235
- interface EachContractProcedureOptions {
236
- router: AnyRouter | AnyContractRouter;
237
- path: string[];
238
- }
239
- interface EachContractProcedureCallbackOptions {
240
- contract: AnyContractProcedure;
241
- path: string[];
242
- }
243
- interface EachContractProcedureLaziedOptions {
244
- lazied: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
245
- path: string[];
246
- }
247
- declare function eachContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void, laziedOptions?: EachContractProcedureLaziedOptions[]): EachContractProcedureLaziedOptions[];
248
- declare function eachAllContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void): Promise<void>;
249
- declare function convertPathToHttpPath(path: string[]): HTTPPath;
250
823
  /**
251
- * Create a new procedure that ensure the contract is applied to the procedure.
824
+ * Create Server-side client from a router.
825
+ *
826
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
252
827
  */
253
- declare function createContractedProcedure(contract: AnyContractProcedure, procedure: AnyProcedure): AnyProcedure;
828
+ declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): RouterClient<T, TClientContext>;
829
+
830
+ declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
831
+ declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
254
832
 
255
- export { AdaptRouterOptions, AdaptedRouter, AnyMiddleware, AnyProcedure, AnyRouter, Builder, type BuilderConfig, type BuilderDef, type BuilderWithMiddlewares, type Config, ConflictContextGuard, Context, CreateProcedureClientOptions, type DecoratedMiddleware, DecoratedProcedure, type EachContractProcedureCallbackOptions, type EachContractProcedureLaziedOptions, type EachContractProcedureOptions, type FlattenLazy, type ImplementedProcedure, type Implementer, type ImplementerInternal, type ImplementerInternalWithMiddlewares, InferRouterInitialContext, Lazy, 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, call, convertPathToHttpPath, createContractedProcedure, createLazyProcedureFormAnyLazy, createRouterClient, decorateMiddleware, deepSetLazyRouterPrefix, eachAllContractProcedure, eachContractProcedure, fallbackConfig, flatLazy, getLazyRouterPrefix, getRouterContract, implement, implementerInternal, os, setRouterContract };
833
+ export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, inferRPCMethodFromRouter, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
834
+ export type { AccessibleLazyRouter, ActionableClient, ActionableClientRest, ActionableClientResult, ActionableError, BuilderConfig, BuilderDef, BuilderWithMiddlewares, Config, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureActionableClient, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProceduresOptions, UnactionableError, UnlaziedRouter };