@temporary-name/server 1.9.3-alpha.4275e976ddda4d8be107c2cfde9899bdea9a337d → 1.9.3-alpha.52ad782be6ff2aac22845e524cd6454f857fb89b

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 (34) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +12 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +12 -6
  3. package/dist/adapters/aws-lambda/index.mjs +12 -4
  4. package/dist/adapters/fetch/index.d.mts +12 -6
  5. package/dist/adapters/fetch/index.d.ts +12 -6
  6. package/dist/adapters/fetch/index.mjs +12 -11
  7. package/dist/adapters/node/index.d.mts +12 -6
  8. package/dist/adapters/node/index.d.ts +12 -6
  9. package/dist/adapters/node/index.mjs +12 -11
  10. package/dist/adapters/standard/index.d.mts +23 -13
  11. package/dist/adapters/standard/index.d.ts +23 -13
  12. package/dist/adapters/standard/index.mjs +8 -100
  13. package/dist/index.d.mts +62 -436
  14. package/dist/index.d.ts +62 -436
  15. package/dist/index.mjs +111 -355
  16. package/dist/openapi/index.d.mts +220 -0
  17. package/dist/openapi/index.d.ts +220 -0
  18. package/dist/openapi/index.mjs +742 -0
  19. package/dist/plugins/index.d.mts +2 -2
  20. package/dist/plugins/index.d.ts +2 -2
  21. package/dist/shared/server.B-pKBQ0r.d.mts +23 -0
  22. package/dist/shared/server.BQV-lt_s.d.ts +23 -0
  23. package/dist/shared/server.BdGbIyq8.mjs +396 -0
  24. package/dist/shared/{server.Btxrgkj5.d.ts → server.DAzElr6Q.d.ts} +7 -24
  25. package/dist/shared/{server.C1YnHvvf.d.ts → server.Do2Whl-h.d.mts} +114 -71
  26. package/dist/shared/{server.C1YnHvvf.d.mts → server.Do2Whl-h.d.ts} +114 -71
  27. package/dist/shared/{server.Bo94xDTv.d.mts → server.KIlJQ8K_.d.mts} +7 -24
  28. package/dist/shared/server.Kxw442A9.mjs +247 -0
  29. package/dist/shared/server.SmOM3Fae.mjs +262 -0
  30. package/package.json +19 -13
  31. package/dist/shared/server.BEQrAa3A.mjs +0 -207
  32. package/dist/shared/server.D6K9uoPI.mjs +0 -35
  33. package/dist/shared/server.DZ5BIITo.mjs +0 -9
  34. package/dist/shared/server.X0YaZxSJ.mjs +0 -13
package/dist/index.d.ts CHANGED
@@ -1,361 +1,88 @@
1
- import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
2
- export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
3
- import { IntersectPick, ClientContext, MaybeOptionalOptions, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
1
+ import { Schemas, ErrorMap, Meta, ContractProcedure, MergedErrorMap, Route, AnySchema, InferSchemaOutput, InferSchemaInput, ContractRouter, ContractProcedureDef, UnknownSchemas, AnyContractRouter, InferContractRouterErrorMap, InferContractRouterMeta, AnyContractProcedure, ErrorFromErrorMap, Schema } from '@temporary-name/contract';
2
+ export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
3
+ import { ClientContext, MaybeOptionalOptions, IntersectPick, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
4
4
  export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
5
- import { C as Context, b as Procedure, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, e as MapInputMiddleware, f as CreateProcedureClientOptions, g as ProcedureClient, h as AnyMiddleware, L as Lazyable, A as AnyRouter, i as Lazy, a as AnyProcedure, j as ProcedureHandler, R as Router, I as InferRouterInitialContext } from './shared/server.C1YnHvvf.js';
6
- export { H as InferRouterCurrentContexts, G as InferRouterInitialContexts, J as InferRouterInputs, K as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, w as MiddlewareNextFn, v as MiddlewareNextFnOptions, y as MiddlewareOptions, x as MiddlewareOutputFn, t as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, P as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, n as createORPCErrorConstructorMap, F as createProcedureClient, s as getLazyMeta, r as isLazy, E as isProcedure, q as lazy, m as mergeCurrentContext, z as middlewareOutputFn, u as unlazy } from './shared/server.C1YnHvvf.js';
5
+ import { SchemaClass } from '@temporary-name/zod';
6
+ import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, e as ProcedureHandler, E as EnhanceRouterOptions, R as Router, f as EnhancedRouter, g as MapInputMiddleware, A as AnyMiddleware, L as Lazy, h as AnyProcedure, i as Lazyable, j as AnyRouter, I as InferRouterInitialContext } from './shared/server.Do2Whl-h.js';
7
+ export { U as AccessibleLazyRouter, Z as ContractProcedureCallbackOptions, N as InferRouterCurrentContexts, K as InferRouterInitialContexts, Q as InferRouterInputs, S as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, _ as LazyTraverseContractProceduresOptions, x as MiddlewareNextFn, w as MiddlewareNextFnOptions, z as MiddlewareOptions, y as MiddlewareOutputFn, v as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, H as ProcedureClientInterceptorOptions, F as ProcedureDef, D as ProcedureHandlerOptions, Y as TraverseContractProcedureCallbackOptions, X as TraverseContractProceduresOptions, a1 as UnlaziedRouter, V as createAccessibleLazyRouter, n as createORPCErrorConstructorMap, J as createProcedureClient, W as enhanceRouter, t as getLazyMeta, T as getRouter, s as isLazy, G as isProcedure, r as lazy, q as lazyInternal, m as mergeCurrentContext, B as middlewareOutputFn, a0 as resolveContractProcedures, $ as traverseContractProcedures, u as unlazy, a2 as unlazyRouter } from './shared/server.Do2Whl-h.js';
7
8
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
8
9
 
9
- 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> {
10
- /**
11
- * Adds type-safe custom errors.
12
- * The provided errors are spared-merged with any existing errors.
13
- *
14
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
15
- */
16
- errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
17
- /**
18
- * Sets or updates the metadata.
19
- * The provided metadata is spared-merged with any existing metadata.
20
- *
21
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
22
- */
23
- meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
24
- /**
25
- * Sets or updates the route definition.
26
- * The provided route is spared-merged with any existing route.
27
- * This option is typically relevant when integrating with OpenAPI.
28
- *
29
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
30
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
31
- */
32
- route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
33
- /**
34
- * Uses a middleware to modify the context or improve the pipeline.
35
- *
36
- * @info Supports both normal middleware and inline middleware implementations.
37
- * @info Pass second argument to map the input.
38
- * @note The current context must be satisfy middleware dependent-context
39
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
40
- */
41
- 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>;
42
- /**
43
- * Uses a middleware to modify the context or improve the pipeline.
44
- *
45
- * @info Supports both normal middleware and inline middleware implementations.
46
- * @info Pass second argument to map the input.
47
- * @note The current context must be satisfy middleware dependent-context
48
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
49
- */
50
- 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>;
10
+ declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
51
11
  /**
52
12
  * Make this procedure callable (works like a function while still being a procedure).
53
13
  *
54
14
  * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
55
15
  */
56
- callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
57
- }
58
-
59
- declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
60
- 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> & {
61
- [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
62
- };
63
- declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
64
- 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> : {
65
- [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
66
- };
67
- interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
68
- middlewares: readonly AnyMiddleware[];
69
- errorMap: TErrorMap;
70
- dedupeLeadingMiddlewares: boolean;
71
- }
72
- 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>;
73
- interface TraverseContractProceduresOptions {
74
- router: AnyContractRouter | AnyRouter;
75
- path: readonly string[];
16
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> & ProcedureClient<TClientContext, TSchemas, TErrorMap>;
76
17
  }
77
- interface TraverseContractProcedureCallbackOptions {
78
- contract: AnyContractProcedure | AnyProcedure;
79
- path: readonly string[];
80
- }
81
- /**
82
- * @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
83
- */
84
- type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
85
- interface LazyTraverseContractProceduresOptions {
86
- router: Lazy<AnyRouter>;
87
- path: readonly string[];
88
- }
89
- declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
90
- declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
91
- type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
92
- [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
93
- };
94
- declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
95
18
 
96
- interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
19
+ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedure<TSchemas, TErrorMap, TMeta> {
20
+ z: SchemaClass<TGateName>;
97
21
  /**
98
22
  * This property holds the defined options.
99
23
  */
100
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
24
+ '~orpc': BuilderDef<TSchemas, TErrorMap, TMeta>;
25
+ constructor(def: BuilderDef<TSchemas, TErrorMap, TMeta>);
101
26
  /**
102
- * Adds type-safe custom errors.
103
- * The provided errors are spared-merged with any existing errors.
27
+ * Adds type-safe custom errors to the contract.
28
+ * The provided errors are spared-merged with any existing errors in the contract.
104
29
  *
105
30
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
106
31
  */
107
- 'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
108
- /**
109
- * Uses a middleware to modify the context or improve the pipeline.
110
- *
111
- * @info Supports both normal middleware and inline middleware implementations.
112
- * @note The current context must be satisfy middleware dependent-context
113
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
114
- */
115
- '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, TGateName>;
32
+ errors<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
116
33
  /**
117
- * Sets or updates the metadata.
118
- * The provided metadata is spared-merged with any existing metadata.
34
+ * Sets or updates the metadata for the contract.
35
+ * The provided metadata is spared-merged with any existing metadata in the contract.
119
36
  *
120
37
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
121
38
  */
122
- 'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
39
+ meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName>;
123
40
  /**
124
- * Sets or updates the route definition.
125
- * The provided route is spared-merged with any existing route.
41
+ * Sets or updates the route definition for the contract.
42
+ * The provided route is spared-merged with any existing route in the contract.
126
43
  * This option is typically relevant when integrating with OpenAPI.
127
44
  *
128
45
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
129
46
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
130
47
  */
131
- 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
48
+ route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName>;
132
49
  /**
133
50
  * Defines the input validation schema.
134
51
  *
135
52
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
136
53
  */
137
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
54
+ input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, {
55
+ inputSchema: USchema;
56
+ outputSchema: TSchemas['outputSchema'];
57
+ }, TErrorMap, TMeta, TGateName>;
138
58
  /**
139
59
  * Defines the output validation schema.
140
60
  *
141
61
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
142
62
  */
143
- 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
144
- /**
145
- * Defines the handler of the procedure.
146
- *
147
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
148
- */
149
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
150
- /**
151
- * Prefixes all procedures in the router.
152
- * The provided prefix is post-appended to any existing router prefix.
153
- *
154
- * @note This option does not affect procedures that do not define a path in their route definition.
155
- *
156
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
157
- */
158
- 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
159
- /**
160
- * Adds tags to all procedures in the router.
161
- * This helpful when you want to group procedures together in the OpenAPI specification.
162
- *
163
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
164
- */
165
- 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
166
- /**
167
- * Applies all of the previously defined options to the specified router.
168
- *
169
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
170
- */
171
- 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
172
- /**
173
- * Create a lazy router
174
- * And applies all of the previously defined options to the specified router.
175
- *
176
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
177
- */
178
- 'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
179
- default: U;
180
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
181
- }
182
- interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
183
- /**
184
- * This property holds the defined options.
185
- */
186
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
187
- /**
188
- * Adds type-safe custom errors.
189
- * The provided errors are spared-merged with any existing errors.
190
- *
191
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
192
- */
193
- 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
194
- /**
195
- * Uses a middleware to modify the context or improve the pipeline.
196
- *
197
- * @info Supports both normal middleware and inline middleware implementations.
198
- * @note The current context must be satisfy middleware dependent-context
199
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
200
- */
201
- '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, TGateName>;
202
- /**
203
- * Sets or updates the metadata.
204
- * The provided metadata is spared-merged with any existing metadata.
205
- *
206
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
207
- */
208
- 'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
209
- /**
210
- * Sets or updates the route definition.
211
- * The provided route is spared-merged with any existing route.
212
- * This option is typically relevant when integrating with OpenAPI.
213
- *
214
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
215
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
216
- */
217
- 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
218
- /**
219
- * Defines the input validation schema.
220
- *
221
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
222
- */
223
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
224
- /**
225
- * Defines the output validation schema.
226
- *
227
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
228
- */
229
- 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
230
- /**
231
- * Defines the handler of the procedure.
232
- *
233
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
234
- */
235
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
236
- }
237
- interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
238
- /**
239
- * This property holds the defined options.
240
- */
241
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
242
- /**
243
- * Adds type-safe custom errors.
244
- * The provided errors are spared-merged with any existing errors.
245
- *
246
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
247
- */
248
- 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
249
- /**
250
- * Uses a middleware to modify the context or improve the pipeline.
251
- *
252
- * @info Supports both normal middleware and inline middleware implementations.
253
- * @note The current context must be satisfy middleware dependent-context
254
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
255
- */
256
- '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, TGateName>;
257
- /**
258
- * Sets or updates the metadata.
259
- * The provided metadata is spared-merged with any existing metadata.
260
- *
261
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
262
- */
263
- 'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
264
- /**
265
- * Sets or updates the route definition.
266
- * The provided route is spared-merged with any existing route.
267
- * This option is typically relevant when integrating with OpenAPI.
268
- *
269
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
270
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
271
- */
272
- 'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
273
- /**
274
- * Defines the input validation schema.
275
- *
276
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
277
- */
278
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
279
- /**
280
- * Defines the handler of the procedure.
281
- *
282
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
283
- */
284
- 'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
285
- }
286
- interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
287
- /**
288
- * This property holds the defined options.
289
- */
290
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
291
- /**
292
- * Adds type-safe custom errors.
293
- * The provided errors are spared-merged with any existing errors.
294
- *
295
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
296
- */
297
- 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
298
- /**
299
- * Uses a middleware to modify the context or improve the pipeline.
300
- *
301
- * @info Supports both normal middleware and inline middleware implementations.
302
- * @info Pass second argument to map the input.
303
- * @note The current context must be satisfy middleware dependent-context
304
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
305
- */
306
- '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, TGateName>;
63
+ output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, {
64
+ inputSchema: TSchemas['inputSchema'];
65
+ outputSchema: USchema;
66
+ }, TErrorMap, TMeta, TGateName>;
307
67
  /**
308
68
  * Uses a middleware to modify the context or improve the pipeline.
309
69
  *
310
70
  * @info Supports both normal middleware and inline middleware implementations.
311
- * @info Pass second argument to map the input.
312
71
  * @note The current context must be satisfy middleware dependent-context
313
72
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
314
73
  */
315
- '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, TGateName>;
316
- /**
317
- * Sets or updates the metadata.
318
- * The provided metadata is spared-merged with any existing metadata.
319
- *
320
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
321
- */
322
- 'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
323
- /**
324
- * Sets or updates the route definition.
325
- * The provided route is spared-merged with any existing route.
326
- * This option is typically relevant when integrating with OpenAPI.
327
- *
328
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
329
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
330
- */
331
- 'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
74
+ 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>, TSchemas, TErrorMap, TMeta, TGateName>;
75
+ useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
76
+ isGateEnabled: typeof isGateEnabled;
77
+ }>, TSchemas, TErrorMap, TMeta, TInferredGateName>;
332
78
  /**
333
79
  * Defines the handler of the procedure.
334
80
  *
335
81
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
336
82
  */
337
- 'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
83
+ handler(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
338
84
  }
339
- interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
340
- /**
341
- * This property holds the defined options.
342
- */
343
- '~orpc': EnhanceRouterOptions<TErrorMap>;
344
- /**
345
- * Adds type-safe custom errors.
346
- * The provided errors are spared-merged with any existing errors.
347
- *
348
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
349
- */
350
- 'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
351
- /**
352
- * Uses a middleware to modify the context or improve the pipeline.
353
- *
354
- * @info Supports both normal middleware and inline middleware implementations.
355
- * @note The current context must be satisfy middleware dependent-context
356
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
357
- */
358
- '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>;
85
+ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName> {
359
86
  /**
360
87
  * Prefixes all procedures in the router.
361
88
  * The provided prefix is post-appended to any existing router prefix.
@@ -364,29 +91,26 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
364
91
  *
365
92
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
366
93
  */
367
- 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
94
+ prefix(prefix: HTTPPath): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName>;
368
95
  /**
369
96
  * Adds tags to all procedures in the router.
370
97
  * This helpful when you want to group procedures together in the OpenAPI specification.
371
98
  *
372
99
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
373
100
  */
374
- 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
101
+ tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
375
102
  /**
376
103
  * Applies all of the previously defined options to the specified router.
377
104
  *
378
105
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
379
106
  */
380
- 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
107
+ router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
108
+ }
109
+ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, TErrorMap, TMeta, any>, 'prefix' | 'tag' | 'router'> {
381
110
  /**
382
- * Create a lazy router
383
- * And applies all of the previously defined options to the specified router.
384
- *
385
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
111
+ * This property holds the defined options.
386
112
  */
387
- 'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
388
- default: U;
389
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
113
+ '~orpc': EnhanceRouterOptions<TErrorMap>;
390
114
  }
391
115
 
392
116
  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> {
@@ -411,23 +135,18 @@ interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Co
411
135
  }
412
136
  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>;
413
137
 
414
- interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
138
+ interface BuilderDef<TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
415
139
  middlewares: readonly AnyMiddleware[];
416
140
  inputValidationIndex: number;
417
141
  outputValidationIndex: number;
418
142
  }
419
- declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
420
- /**
421
- * This property holds the defined options.
422
- */
423
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
424
- constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
143
+ declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName> {
425
144
  /**
426
145
  * Set or override the initial context.
427
146
  *
428
147
  * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
429
148
  */
430
- $context<U extends Context>(): Builder<U & Record<never, never>, U, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
149
+ $context<U extends Context>(): Builder<U, U, TSchemas, TErrorMap, TMeta, TGateName>;
431
150
  /**
432
151
  * Creates a middleware.
433
152
  *
@@ -435,91 +154,8 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
435
154
  */
436
155
  middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
437
156
  middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
438
- /**
439
- * Adds type-safe custom errors.
440
- * The provided errors are spared-merged with any existing errors.
441
- *
442
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
443
- */
444
- errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
445
- /**
446
- * Uses a middleware to modify the context or improve the pipeline.
447
- *
448
- * @info Supports both normal middleware and inline middleware implementations.
449
- * @note The current context must be satisfy middleware dependent-context
450
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
451
- */
452
- 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, TGateName>;
453
- useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
454
- isGateEnabled: typeof isGateEnabled;
455
- }>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
456
- /**
457
- * Sets or updates the metadata.
458
- * The provided metadata is spared-merged with any existing metadata.
459
- *
460
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
461
- */
462
- meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
463
- /**
464
- * Sets or updates the route definition.
465
- * The provided route is spared-merged with any existing route.
466
- * This option is typically relevant when integrating with OpenAPI.
467
- *
468
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
469
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
470
- */
471
- route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
472
- /**
473
- * Defines the input validation schema.
474
- *
475
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
476
- */
477
- input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
478
- /**
479
- * Defines the output validation schema.
480
- *
481
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
482
- */
483
- output<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
484
- /**
485
- * Defines the handler of the procedure.
486
- *
487
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
488
- */
489
- handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
490
- /**
491
- * Prefixes all procedures in the router.
492
- * The provided prefix is post-appended to any existing router prefix.
493
- *
494
- * @note This option does not affect procedures that do not define a path in their route definition.
495
- *
496
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
497
- */
498
- prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
499
- /**
500
- * Adds tags to all procedures in the router.
501
- * This helpful when you want to group procedures together in the OpenAPI specification.
502
- *
503
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
504
- */
505
- tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
506
- /**
507
- * Applies all of the previously defined options to the specified router.
508
- *
509
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
510
- */
511
- router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
512
- /**
513
- * Create a lazy router
514
- * And applies all of the previously defined options to the specified router.
515
- *
516
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
517
- */
518
- lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
519
- default: U;
520
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
521
157
  }
522
- type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, TMeta, never>;
158
+ type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, UnknownSchemas, Record<never, never>, TMeta, never>;
523
159
  interface ApiBuilderOpts<TMeta extends Meta> {
524
160
  meta?: TMeta;
525
161
  }
@@ -529,7 +165,7 @@ declare const os: ApiBuilder<Record<never, never>>;
529
165
  /**
530
166
  * Like `DecoratedProcedure`, but removed all method that can change the contract.
531
167
  */
532
- 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> {
168
+ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
533
169
  /**
534
170
  * Uses a middleware to modify the context or improve the pipeline.
535
171
  *
@@ -538,7 +174,7 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
538
174
  * @note The current context must be satisfy middleware dependent-context
539
175
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
540
176
  */
541
- 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>;
177
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
542
178
  /**
543
179
  * Uses a middleware to modify the context or improve the pipeline.
544
180
  *
@@ -547,19 +183,19 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
547
183
  * @note The current context must be satisfy middleware dependent-context
548
184
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
549
185
  */
550
- 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>;
186
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TSchemas['inputSchema']>, UInput>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
551
187
  /**
552
188
  * Make this procedure callable (works like a function while still being a procedure).
553
189
  *
554
190
  * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
555
191
  */
556
- callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
192
+ callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> & ProcedureClient<TClientContext, TSchemas, TErrorMap>;
557
193
  }
558
194
  /**
559
195
  * Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
560
196
  */
561
- interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
562
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, string>;
197
+ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
198
+ '~orpc': BuilderDef<TSchemas, TErrorMap, TMeta>;
563
199
  /**
564
200
  * Uses a middleware to modify the context or improve the pipeline.
565
201
  *
@@ -568,7 +204,7 @@ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext
568
204
  * @note The current context must be satisfy middleware dependent-context
569
205
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
570
206
  */
571
- '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>;
207
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
572
208
  /**
573
209
  * Uses a middleware to modify the context or improve the pipeline.
574
210
  *
@@ -577,13 +213,13 @@ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext
577
213
  * @note The current context must be satisfy middleware dependent-context
578
214
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
579
215
  */
580
- '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>;
216
+ 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TSchemas['inputSchema']>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
581
217
  /**
582
218
  * Defines the handler of the procedure.
583
219
  *
584
220
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
585
221
  */
586
- 'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
222
+ 'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
587
223
  }
588
224
 
589
225
  interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
@@ -602,18 +238,8 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
602
238
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
603
239
  */
604
240
  router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
605
- /**
606
- * Create a lazy router
607
- * And applies all of the previously defined options to the specified router.
608
- * And enforces the router match the contract.
609
- *
610
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
611
- */
612
- lazyRoute<U extends Router<T, TInitialContext>>(loader: () => Promise<{
613
- default: U;
614
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
615
241
  }
616
- 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> & {
242
+ type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, USchemas, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
617
243
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
618
244
  };
619
245
 
@@ -651,7 +277,7 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
651
277
  default: U;
652
278
  }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
653
279
  }
654
- 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> & {
280
+ type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, USchemas, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
655
281
  [K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
656
282
  };
657
283
  declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
@@ -661,7 +287,7 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
661
287
  *
662
288
  * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
663
289
  */
664
- $context<U extends Context>(): Implementer<TContract, U & Record<never, never>, U>;
290
+ $context<U extends Context>(): Implementer<TContract, U, U>;
665
291
  } & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
666
292
  declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T): Implementer<T, TContext, TContext>;
667
293
 
@@ -686,9 +312,9 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
686
312
  * ```
687
313
  *
688
314
  */
689
- 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>>;
315
+ declare function call<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, input: InferSchemaInput<TSchemas['inputSchema']>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): ClientPromiseResult<InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
690
316
 
691
- 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> : {
317
+ type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer USchemas, infer UErrorMap, any> ? ProcedureClient<TClientContext, USchemas, UErrorMap> : {
692
318
  [K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
693
319
  };
694
320
  /**
@@ -701,5 +327,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
701
327
  declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
702
328
  declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
703
329
 
704
- export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
705
- export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, BuilderWithMiddlewares, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureBuilder, ProcedureBuilderWithInputOutput, ProcedureBuilderWithOutput, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
330
+ export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, getHiddenRouterContract, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
331
+ export type { ApiBuilder, BuilderDef, DecoratedMiddleware, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares };