@orpc/server 0.0.0-next.93e6063 → 0.0.0-next.9486ab5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/adapters/fetch/index.d.mts +38 -11
- package/dist/adapters/fetch/index.d.ts +38 -11
- package/dist/adapters/fetch/index.mjs +6 -6
- package/dist/adapters/hono/index.d.mts +6 -4
- package/dist/adapters/hono/index.d.ts +6 -4
- package/dist/adapters/hono/index.mjs +6 -6
- package/dist/adapters/next/index.d.mts +6 -4
- package/dist/adapters/next/index.d.ts +6 -4
- package/dist/adapters/next/index.mjs +6 -6
- package/dist/adapters/node/index.d.mts +40 -22
- package/dist/adapters/node/index.d.ts +40 -22
- package/dist/adapters/node/index.mjs +77 -22
- package/dist/adapters/standard/index.d.mts +12 -15
- package/dist/adapters/standard/index.d.ts +12 -15
- package/dist/adapters/standard/index.mjs +2 -3
- package/dist/index.d.mts +156 -120
- package/dist/index.d.ts +156 -120
- package/dist/index.mjs +78 -48
- package/dist/plugins/index.d.mts +15 -16
- package/dist/plugins/index.d.ts +15 -16
- package/dist/plugins/index.mjs +10 -6
- package/dist/shared/server.89QkKw3a.d.mts +10 -0
- package/dist/shared/server.B1S3zwuw.d.mts +8 -0
- package/dist/shared/server.BMkFIQUb.d.mts +66 -0
- package/dist/shared/server.BT0gne12.d.ts +8 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/{server.V6zT5iYQ.mjs → server.CjWkNG6l.mjs} +151 -160
- package/dist/shared/server.D0YVcfZk.d.mts +143 -0
- package/dist/shared/server.D0YVcfZk.d.ts +143 -0
- package/dist/shared/{server.BBGuTxHE.mjs → server.D9QduY95.mjs} +43 -45
- package/dist/shared/server.Et1O6Bm7.mjs +98 -0
- package/dist/shared/server.taqJyaMn.d.ts +10 -0
- package/dist/shared/server.ywWqDZgA.d.ts +66 -0
- package/package.json +8 -8
- package/dist/shared/server.B-ewprcf.d.ts +0 -77
- package/dist/shared/server.CA-o8cUY.d.mts +0 -9
- package/dist/shared/server.Cn9ybJtE.d.mts +0 -152
- package/dist/shared/server.Cn9ybJtE.d.ts +0 -152
- package/dist/shared/server.DJrh0Ceu.d.mts +0 -77
- package/dist/shared/server.DPQt9YYq.d.ts +0 -9
- package/dist/shared/server.KwueCzFr.mjs +0 -26
- package/dist/shared/server.Q6ZmnTgO.mjs +0 -12
@@ -1,29 +1,26 @@
|
|
1
|
-
import {
|
2
|
-
export { S as StandardHandleOptions,
|
3
|
-
import { ORPCError } from '@orpc/client';
|
1
|
+
import { d as StandardCodec, e as StandardParams, f as StandardMatcher, g as StandardMatchResult } from '../../shared/server.ywWqDZgA.js';
|
2
|
+
export { S as StandardHandleOptions, h as StandardHandleResult, i as StandardHandler, b as StandardHandlerInterceptorOptions, a as StandardHandlerOptions, c as StandardHandlerPlugin } from '../../shared/server.ywWqDZgA.js';
|
3
|
+
import { ORPCError, HTTPPath } from '@orpc/client';
|
4
|
+
import { StandardRPCSerializer } from '@orpc/client/standard';
|
4
5
|
import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
5
|
-
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.
|
6
|
-
|
7
|
-
|
8
|
-
import { HTTPPath } from '@orpc/contract';
|
6
|
+
import { A as AnyProcedure, a as AnyRouter } from '../../shared/server.D0YVcfZk.js';
|
7
|
+
export { S as StandardRPCHandlerOptions } from '../../shared/server.BT0gne12.js';
|
8
|
+
import '@orpc/contract';
|
9
9
|
import '@orpc/shared';
|
10
10
|
|
11
|
-
|
12
|
-
serializer?: RPCSerializer;
|
13
|
-
}
|
14
|
-
declare class RPCCodec implements StandardCodec {
|
11
|
+
declare class StandardRPCCodec implements StandardCodec {
|
15
12
|
private readonly serializer;
|
16
|
-
constructor(
|
13
|
+
constructor(serializer: StandardRPCSerializer);
|
17
14
|
decode(request: StandardLazyRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
18
15
|
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
19
16
|
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
17
|
}
|
21
18
|
|
22
|
-
declare class
|
19
|
+
declare class StandardRPCMatcher implements StandardMatcher {
|
23
20
|
private readonly tree;
|
24
21
|
private pendingRouters;
|
25
|
-
init(router: AnyRouter, path?: string[]): void;
|
22
|
+
init(router: AnyRouter, path?: readonly string[]): void;
|
26
23
|
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
27
24
|
}
|
28
25
|
|
29
|
-
export {
|
26
|
+
export { StandardCodec, StandardMatchResult, StandardMatcher, StandardParams, StandardRPCCodec, StandardRPCMatcher };
|
@@ -1,7 +1,6 @@
|
|
1
|
-
export {
|
1
|
+
export { S as StandardHandler, a as StandardRPCCodec, b as StandardRPCMatcher } from '../../shared/server.D9QduY95.mjs';
|
2
2
|
import '@orpc/client';
|
3
3
|
import '@orpc/shared';
|
4
|
-
import '../../shared/server.
|
5
|
-
import '../../shared/server.V6zT5iYQ.mjs';
|
4
|
+
import '../../shared/server.CjWkNG6l.mjs';
|
6
5
|
import '@orpc/contract';
|
7
6
|
import '@orpc/client/standard';
|
package/dist/index.d.mts
CHANGED
@@ -1,117 +1,163 @@
|
|
1
|
-
import {
|
2
|
-
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, HTTPMethod, HTTPPath, InputStructure, Meta, ORPCErrorFromErrorMap, OutputStructure, Route, Schema, SchemaInput, SchemaOutput, ValidationError, eventIterator, type } from '@orpc/contract';
|
3
|
-
import { L as Lazy, A as AnyProcedure, C as Context, b as Procedure, M as Middleware, O as ORPCErrorConstructorMap, c as ConflictContextGuard, d as MergedContext, e as MapInputMiddleware, f as CreateProcedureClientOptions, g as ProcedureClient, h as ProcedureHandler, i as AdaptRouterOptions, R as Router, j as AdaptedRouter, k as AnyMiddleware, a as AnyRouter, l as Lazyable, I as InferRouterInitialContext } from './shared/server.Cn9ybJtE.mjs';
|
4
|
-
export { K as AccessibleLazyRouter, F as InferRouterInputs, G as InferRouterOutputs, n as LAZY_LOADER_SYMBOL, o as LazyMeta, p as LazyOptions, v as MiddlewareNextFn, t as MiddlewareNextFnOptions, x as MiddlewareOptions, w as MiddlewareOutputFn, s as MiddlewareResult, P as ProcedureClientInterceptorOptions, B as ProcedureDef, z as ProcedureHandlerOptions, H as adaptRouter, N as createAccessibleLazyRouter, E as createProcedureClient, J as getRouterChild, r as isLazy, D as isProcedure, q as lazy, m as mergeContext, y as middlewareOutputFn, u as unlazy } from './shared/server.Cn9ybJtE.mjs';
|
5
|
-
import { ClientContext, ClientRest, ClientPromiseResult } from '@orpc/client';
|
1
|
+
import { ORPCErrorJSON, ORPCError, Client, ClientContext, HTTPPath, ClientPromiseResult } from '@orpc/client';
|
6
2
|
export { ORPCError, isDefinedError, safe } from '@orpc/client';
|
7
|
-
import {
|
3
|
+
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, ErrorFromErrorMap, Meta, MergedErrorMap, Route, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta } from '@orpc/contract';
|
4
|
+
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type } from '@orpc/contract';
|
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.D0YVcfZk.mjs';
|
6
|
+
export { J as InferRouterCurrentContexts, H as InferRouterInitialContexts, K as InferRouterInputs, N as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, x as MiddlewareNextFn, w as MiddlewareNextFnOptions, z as MiddlewareOptions, y as MiddlewareOutputFn, t as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, P as ProcedureClientInterceptorOptions, E as ProcedureDef, D as ProcedureHandlerOptions, n as createORPCErrorConstructorMap, G as createProcedureClient, s as getLazyMeta, r as isLazy, F as isProcedure, q as lazy, m as mergeCurrentContext, B as middlewareOutputFn, u as unlazy, v as validateORPCError } from './shared/server.D0YVcfZk.mjs';
|
7
|
+
import { IntersectPick, MaybeOptionalOptions } from '@orpc/shared';
|
8
8
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
9
9
|
export { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
10
10
|
|
11
|
-
type
|
12
|
-
|
13
|
-
|
11
|
+
type ActionableError<T extends Error> = T extends ORPCError<infer U, infer V> ? ORPCErrorJSON<U, V> & {
|
12
|
+
defined: true;
|
13
|
+
} : ORPCErrorJSON<string, unknown> & {
|
14
|
+
defined: false;
|
15
|
+
};
|
16
|
+
type UnactionableError<T> = T extends {
|
17
|
+
defined: true;
|
18
|
+
} & ORPCErrorJSON<infer U, infer V> ? ORPCError<U, V> : Error;
|
19
|
+
type ActionableClientRest<TInput> = [input: TInput] | (undefined extends TInput ? [input?: TInput] : [input: TInput]);
|
20
|
+
type ActionableClientResult<TOutput, TError extends ORPCErrorJSON<any, any>> = [error: null, data: TOutput] | [error: TError, data: undefined];
|
21
|
+
interface ActionableClient<TInput, TOutput, TError extends ORPCErrorJSON<any, any>> {
|
22
|
+
(...rest: ActionableClientRest<TInput>): Promise<ActionableClientResult<TOutput, TError>>;
|
23
|
+
}
|
24
|
+
type ProcedureActionableClient<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = ActionableClient<InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ActionableError<ErrorFromErrorMap<TErrorMap>>>;
|
25
|
+
declare function createActionableClient<TInput, TOutput, TError extends Error>(client: Client<Record<never, never>, TInput, TOutput, TError>): ActionableClient<TInput, TOutput, ActionableError<TError>>;
|
14
26
|
|
15
|
-
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
16
|
-
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema,
|
17
|
-
meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema,
|
18
|
-
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema,
|
19
|
-
use<
|
20
|
-
use<UOutContext extends
|
27
|
+
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
28
|
+
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
29
|
+
meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
30
|
+
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
31
|
+
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>;
|
32
|
+
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
33
|
/**
|
22
34
|
* Make this procedure callable (works like a function while still being a procedure).
|
23
35
|
*/
|
24
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema,
|
36
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
25
37
|
/**
|
26
|
-
* Make this procedure compatible with server action
|
38
|
+
* Make this procedure compatible with server action.
|
27
39
|
*/
|
28
|
-
actionable
|
40
|
+
actionable(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap>;
|
41
|
+
}
|
42
|
+
|
43
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
44
|
+
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> & {
|
45
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
46
|
+
};
|
47
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
48
|
+
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> : {
|
49
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
50
|
+
};
|
51
|
+
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
52
|
+
middlewares: readonly AnyMiddleware[];
|
53
|
+
errorMap: TErrorMap;
|
54
|
+
dedupeLeadingMiddlewares: boolean;
|
29
55
|
}
|
56
|
+
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>;
|
57
|
+
interface TraverseContractProceduresOptions {
|
58
|
+
router: AnyContractRouter | AnyRouter;
|
59
|
+
path: readonly string[];
|
60
|
+
}
|
61
|
+
interface ContractProcedureCallbackOptions {
|
62
|
+
contract: AnyContractProcedure;
|
63
|
+
path: readonly string[];
|
64
|
+
}
|
65
|
+
interface LazyTraverseContractProceduresOptions {
|
66
|
+
router: Lazy<AnyRouter>;
|
67
|
+
path: readonly string[];
|
68
|
+
}
|
69
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
70
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: ContractProcedureCallbackOptions) => void): Promise<void>;
|
71
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
72
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
73
|
+
};
|
74
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
30
75
|
|
31
|
-
interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
76
|
+
interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
32
77
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
33
78
|
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
34
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
79
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
35
80
|
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
36
81
|
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
37
|
-
'input'<USchema extends
|
38
|
-
'output'<USchema extends
|
39
|
-
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema,
|
82
|
+
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
83
|
+
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
84
|
+
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
40
85
|
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
41
86
|
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
42
|
-
'router'<U extends Router<
|
43
|
-
'lazy'<U extends Router<
|
87
|
+
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
88
|
+
'lazy'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
44
89
|
default: U;
|
45
|
-
}>):
|
90
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
46
91
|
}
|
47
|
-
interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
92
|
+
interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
48
93
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
49
94
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
50
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
95
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
51
96
|
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
52
97
|
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
53
|
-
'input'<USchema extends
|
54
|
-
'output'<USchema extends
|
55
|
-
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema,
|
98
|
+
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
99
|
+
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
100
|
+
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
56
101
|
}
|
57
|
-
interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
102
|
+
interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
58
103
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
59
104
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
60
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext,
|
61
|
-
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<
|
105
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
106
|
+
'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
107
|
'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
63
108
|
'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
64
|
-
'output'<USchema extends
|
65
|
-
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext,
|
109
|
+
'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
110
|
+
'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
66
111
|
}
|
67
|
-
interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
112
|
+
interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
68
113
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
69
114
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
70
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown,
|
115
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
71
116
|
'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
72
117
|
'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
73
|
-
'input'<USchema extends
|
74
|
-
'handler'(handler: ProcedureHandler<TCurrentContext, unknown,
|
118
|
+
'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
119
|
+
'handler'(handler: ProcedureHandler<TCurrentContext, unknown, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
75
120
|
}
|
76
|
-
interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
121
|
+
interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
77
122
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
78
123
|
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
79
|
-
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext,
|
80
|
-
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput,
|
124
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
125
|
+
'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInputOutput<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
81
126
|
'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
82
127
|
'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
83
|
-
'handler'(handler: ProcedureHandler<TCurrentContext,
|
128
|
+
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
84
129
|
}
|
85
130
|
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
86
|
-
'~orpc':
|
131
|
+
'~orpc': EnhanceRouterOptions<TErrorMap>;
|
87
132
|
'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>):
|
133
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
|
89
134
|
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
90
135
|
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
91
|
-
'router'<U extends Router<
|
92
|
-
'lazy'<U extends Router<
|
136
|
+
'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
137
|
+
'lazy'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
93
138
|
default: U;
|
94
|
-
}>):
|
139
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
95
140
|
}
|
96
141
|
|
97
142
|
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
|
-
|
99
|
-
concat<UOutContext extends Context,
|
100
|
-
|
143
|
+
mapInput<UInput>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
144
|
+
concat<UOutContext extends Context, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
145
|
+
concat<UOutContext extends Context, UMappedInput, UInContext extends Context = MergedCurrentContext<TInContext, TOutContext>>(middleware: Middleware<UInContext | MergedCurrentContext<TInContext, TOutContext>, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<TInput, UMappedInput>): DecoratedMiddleware<MergedInitialContext<TInContext, UInContext, MergedCurrentContext<TInContext, TOutContext>>, MergedCurrentContext<TOutContext, UOutContext>, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
101
146
|
}
|
102
147
|
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
148
|
|
104
149
|
interface BuilderConfig {
|
105
150
|
initialInputValidationIndex?: number;
|
106
151
|
initialOutputValidationIndex?: number;
|
152
|
+
dedupeLeadingMiddlewares?: boolean;
|
107
153
|
}
|
108
|
-
interface BuilderDef<TInputSchema extends
|
109
|
-
middlewares: AnyMiddleware[];
|
154
|
+
interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
|
155
|
+
middlewares: readonly AnyMiddleware[];
|
110
156
|
inputValidationIndex: number;
|
111
157
|
outputValidationIndex: number;
|
112
158
|
config: BuilderConfig;
|
113
159
|
}
|
114
|
-
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
160
|
+
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
115
161
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
116
162
|
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
117
163
|
/**
|
@@ -121,100 +167,107 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
121
167
|
/**
|
122
168
|
* Reset initial context
|
123
169
|
*/
|
124
|
-
$context<U extends Context>(): Builder<U, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
170
|
+
$context<U extends Context>(): Builder<U & Record<never, never>, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
125
171
|
/**
|
126
172
|
* Reset initial meta
|
127
173
|
*/
|
128
|
-
$meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U
|
174
|
+
$meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
129
175
|
/**
|
130
176
|
* Reset initial route
|
131
177
|
*/
|
132
178
|
$route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
179
|
+
$input<U extends AnySchema>(initialInputSchema?: U): Builder<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap, TMeta>;
|
133
180
|
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<
|
181
|
+
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
135
182
|
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
136
|
-
use<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>):
|
137
|
-
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<unknown, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
183
|
+
use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
138
184
|
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
139
185
|
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
140
|
-
input<USchema extends
|
141
|
-
output<USchema extends
|
142
|
-
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema,
|
186
|
+
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
187
|
+
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
188
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, unknown, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
|
143
189
|
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
144
190
|
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
145
|
-
router<U extends Router<
|
146
|
-
lazy<U extends Router<
|
191
|
+
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
192
|
+
lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
147
193
|
default: U;
|
148
|
-
}>):
|
194
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
149
195
|
}
|
150
|
-
declare const os: Builder<
|
196
|
+
declare const os: Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
151
197
|
|
152
198
|
interface Config {
|
153
199
|
initialInputValidationIndex: number;
|
154
200
|
initialOutputValidationIndex: number;
|
201
|
+
dedupeLeadingMiddlewares: boolean;
|
155
202
|
}
|
156
203
|
declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
|
157
204
|
|
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
205
|
/**
|
164
206
|
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
165
207
|
*/
|
166
|
-
interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
167
|
-
use<
|
168
|
-
use<UOutContext extends
|
208
|
+
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> {
|
209
|
+
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>;
|
210
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
169
211
|
/**
|
170
212
|
* Make this procedure callable (works like a function while still being a procedure).
|
171
213
|
*/
|
172
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema,
|
214
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
173
215
|
/**
|
174
|
-
* Make this procedure compatible with server action
|
216
|
+
* Make this procedure compatible with server action.
|
175
217
|
*/
|
176
|
-
actionable
|
218
|
+
actionable(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta> & ProcedureActionableClient<TInputSchema, TOutputSchema, TErrorMap>;
|
177
219
|
}
|
178
220
|
/**
|
179
221
|
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
180
222
|
*/
|
181
|
-
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends
|
223
|
+
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
182
224
|
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
183
|
-
'use'<
|
184
|
-
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput,
|
185
|
-
'handler'(handler: ProcedureHandler<TCurrentContext,
|
225
|
+
'use'<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
226
|
+
'use'<UOutContext extends Context, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
227
|
+
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
186
228
|
}
|
187
229
|
|
188
|
-
interface RouterImplementerWithMiddlewares<
|
189
|
-
use<
|
190
|
-
router<U extends Router<
|
191
|
-
lazy<U extends Router<
|
230
|
+
interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
231
|
+
use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
|
232
|
+
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
233
|
+
lazy<U extends Router<T, TInitialContext>>(loader: () => Promise<{
|
192
234
|
default: U;
|
193
|
-
}>):
|
235
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
194
236
|
}
|
195
237
|
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
196
238
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
197
239
|
});
|
198
240
|
|
199
|
-
interface RouterImplementer<
|
241
|
+
interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
200
242
|
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
201
|
-
middleware: Middleware<
|
202
|
-
use<
|
203
|
-
router<U extends Router<
|
204
|
-
lazy<U extends Router<
|
243
|
+
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, InferContractRouterMeta<T>>;
|
244
|
+
use<UOutContext extends Context, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<InferContractRouterErrorMap<T>>, InferContractRouterMeta<T>>): ImplementerInternalWithMiddlewares<T, MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>>;
|
245
|
+
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
246
|
+
lazy<U extends Router<T, TCurrentContext>>(loader: () => Promise<{
|
205
247
|
default: U;
|
206
|
-
}>):
|
248
|
+
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
207
249
|
}
|
208
250
|
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
209
251
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
210
252
|
});
|
211
|
-
declare function implementerInternal<
|
253
|
+
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
212
254
|
type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
213
|
-
$context<U extends Context>(): Implementer<TContract, U, U>;
|
255
|
+
$context<U extends Context>(): Implementer<TContract, U & Record<never, never>, U>;
|
214
256
|
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
215
257
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
216
|
-
declare function implement<
|
258
|
+
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T, config?: BuilderConfig): Implementer<T, TContext, TContext>;
|
217
259
|
|
260
|
+
declare function isStartWithMiddlewares(middlewares: readonly AnyMiddleware[], compare: readonly AnyMiddleware[]): boolean;
|
261
|
+
declare function mergeMiddlewares(first: readonly AnyMiddleware[], second: readonly AnyMiddleware[], options: {
|
262
|
+
dedupeLeading: boolean;
|
263
|
+
}): readonly AnyMiddleware[];
|
264
|
+
declare function addMiddleware(middlewares: readonly AnyMiddleware[], addition: AnyMiddleware): AnyMiddleware[];
|
265
|
+
|
266
|
+
declare function createAssertedLazyProcedure(lazied: Lazy<any>): Lazy<AnyProcedure>;
|
267
|
+
/**
|
268
|
+
* Create a new procedure that ensure the contract is applied to the procedure.
|
269
|
+
*/
|
270
|
+
declare function createContractedProcedure(procedure: AnyProcedure, contract: AnyContractProcedure): AnyProcedure;
|
218
271
|
/**
|
219
272
|
* Directly call a procedure without creating a client.
|
220
273
|
*
|
@@ -225,31 +278,14 @@ declare function implement<TContract extends AnyContractRouter, TInitialContext
|
|
225
278
|
* ```
|
226
279
|
*
|
227
280
|
*/
|
228
|
-
declare function call<TInitialContext extends Context, TInputSchema extends
|
281
|
+
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, TInputSchema, TOutputSchema, TErrorMap, TMeta, Record<never, never>>>): ClientPromiseResult<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
229
282
|
|
230
|
-
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends
|
231
|
-
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<
|
283
|
+
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> : {
|
284
|
+
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
232
285
|
};
|
233
|
-
declare function createRouterClient<
|
286
|
+
declare function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...[options]: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): RouterClient<T, TClientContext>;
|
234
287
|
|
235
|
-
|
236
|
-
|
237
|
-
path: string[];
|
238
|
-
}
|
239
|
-
interface EachContractProcedureCallbackOptions {
|
240
|
-
contract: AnyContractProcedure;
|
241
|
-
path: string[];
|
242
|
-
}
|
243
|
-
interface EachContractProcedureLaziedOptions {
|
244
|
-
lazied: Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter> | AnyProcedure>;
|
245
|
-
path: string[];
|
246
|
-
}
|
247
|
-
declare function eachContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void, laziedOptions?: EachContractProcedureLaziedOptions[]): EachContractProcedureLaziedOptions[];
|
248
|
-
declare function eachAllContractProcedure(options: EachContractProcedureOptions, callback: (options: EachContractProcedureCallbackOptions) => void): Promise<void>;
|
249
|
-
declare function convertPathToHttpPath(path: string[]): HTTPPath;
|
250
|
-
/**
|
251
|
-
* Create a new procedure that ensure the contract is applied to the procedure.
|
252
|
-
*/
|
253
|
-
declare function createContractedProcedure(contract: AnyContractProcedure, procedure: AnyProcedure): AnyProcedure;
|
288
|
+
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
289
|
+
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
254
290
|
|
255
|
-
export {
|
291
|
+
export { type AccessibleLazyRouter, type ActionableClient, type ActionableClientRest, type ActionableClientResult, type ActionableError, AnyMiddleware, AnyProcedure, AnyRouter, Builder, type BuilderConfig, type BuilderDef, type BuilderWithMiddlewares, type Config, Context, type ContractProcedureCallbackOptions, CreateProcedureClientOptions, type DecoratedMiddleware, DecoratedProcedure, type EnhanceRouterOptions, type EnhancedRouter, type ImplementedProcedure, type Implementer, type ImplementerInternal, type ImplementerInternalWithMiddlewares, InferRouterInitialContext, Lazy, type LazyTraverseContractProceduresOptions, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, type ProcedureActionableClient, type ProcedureBuilder, type ProcedureBuilderWithInput, type ProcedureBuilderWithInputOutput, type ProcedureBuilderWithOutput, ProcedureClient, ProcedureHandler, type ProcedureImplementer, Router, type RouterBuilder, type RouterClient, type RouterImplementer, type RouterImplementerWithMiddlewares, type TraverseContractProceduresOptions, type UnactionableError, type UnlaziedRouter, addMiddleware, call, createAccessibleLazyRouter, createActionableClient, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, fallbackConfig, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
|