@orpc/server 0.0.0-next.a05fbfd → 0.0.0-next.a0ab4bf

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