@orpc/server 0.0.0-next.a055cad → 0.0.0-next.a2e4a58
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-GK2Z6B6W.js +230 -0
- package/dist/chunk-SXUFCJBY.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +11 -103
- package/dist/hono.js +30 -0
- package/dist/index.js +889 -313
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder-with-errors-middlewares.d.ts +51 -0
- package/dist/src/builder-with-errors.d.ts +52 -0
- package/dist/src/builder-with-middlewares.d.ts +48 -0
- package/dist/src/builder.d.ts +42 -46
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +11 -0
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +6 -0
- package/dist/src/implementer-chainable.d.ts +14 -0
- package/dist/src/index.d.ts +13 -4
- package/dist/src/lazy-decorated.d.ts +7 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +6 -11
- package/dist/src/middleware-decorated.d.ts +10 -0
- package/dist/src/middleware.d.ts +22 -12
- package/dist/src/procedure-builder-with-input.d.ts +34 -0
- package/dist/src/procedure-builder-with-output.d.ts +33 -0
- package/dist/src/procedure-builder.d.ts +24 -28
- package/dist/src/procedure-client.d.ts +22 -0
- package/dist/src/procedure-decorated.d.ts +26 -0
- package/dist/src/procedure-implementer.d.ts +19 -19
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +39 -26
- package/dist/src/router-builder.d.ts +29 -23
- package/dist/src/router-client.d.ts +26 -0
- package/dist/src/router-implementer.d.ts +19 -21
- package/dist/src/router.d.ts +11 -16
- package/dist/src/types.d.ts +10 -4
- package/package.json +22 -11
- package/dist/chunk-MZXEMHFS.js +0 -272
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/procedure-caller.d.ts +0 -25
- package/dist/src/router-caller.d.ts +0 -25
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
export declare function setRouterContract<T extends object>(obj: T, contract: ContractRouter<any>): T;
|
3
|
+
export declare function getRouterContract(obj: object): ContractRouter<any> | undefined;
|
4
|
+
export declare function deepSetLazyRouterPrefix<T extends object>(router: T, prefix: HTTPPath): T;
|
5
|
+
export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
|
6
|
+
//# sourceMappingURL=hidden.d.ts.map
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { Middleware } from './middleware';
|
2
|
+
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
3
|
+
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
5
|
+
import { RouterImplementer } from './router-implementer';
|
6
|
+
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter<any>> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
7
|
+
[K in keyof TContract]: TContract[K] extends ContractRouter<any> ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
8
|
+
} & Omit<RouterImplementer<TContext, TExtraContext, TContract>, '~type' | '~orpc'>;
|
9
|
+
export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter<any> = any>(contract: TContract, options: {
|
10
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, any>[];
|
11
|
+
inputValidationIndex: number;
|
12
|
+
outputValidationIndex: number;
|
13
|
+
}): ChainableImplementer<TContext, TExtraContext, TContract>;
|
14
|
+
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,17 +1,26 @@
|
|
1
|
+
import type { WELL_CONTEXT } from './types';
|
1
2
|
import { Builder } from './builder';
|
2
3
|
export * from './builder';
|
4
|
+
export * from './config';
|
5
|
+
export * from './error';
|
6
|
+
export * from './hidden';
|
7
|
+
export * from './implementer-chainable';
|
3
8
|
export * from './lazy';
|
9
|
+
export * from './lazy-decorated';
|
4
10
|
export * from './middleware';
|
11
|
+
export * from './middleware-decorated';
|
5
12
|
export * from './procedure';
|
6
13
|
export * from './procedure-builder';
|
7
|
-
export * from './procedure-
|
14
|
+
export * from './procedure-client';
|
15
|
+
export * from './procedure-decorated';
|
8
16
|
export * from './procedure-implementer';
|
17
|
+
export * from './procedure-utils';
|
9
18
|
export * from './router';
|
10
19
|
export * from './router-builder';
|
11
|
-
export * from './router-
|
20
|
+
export * from './router-client';
|
12
21
|
export * from './router-implementer';
|
13
22
|
export * from './types';
|
14
23
|
export * from './utils';
|
15
|
-
export
|
16
|
-
export declare const os: Builder<
|
24
|
+
export { isDefinedError, ORPCError, safe, type } from '@orpc/contract';
|
25
|
+
export declare const os: Builder<WELL_CONTEXT>;
|
17
26
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { Lazy } from './lazy';
|
2
|
+
import { type ANY_ROUTER } from './router';
|
3
|
+
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
|
4
|
+
[K in keyof T]: DecoratedLazy<T[K]>;
|
5
|
+
} : unknown);
|
6
|
+
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
7
|
+
//# sourceMappingURL=lazy-decorated.d.ts.map
|
package/dist/src/lazy.d.ts
CHANGED
@@ -1,23 +1,18 @@
|
|
1
|
-
import type { Procedure } from './procedure';
|
2
|
-
import type { ProcedureCaller } from './procedure-caller';
|
3
1
|
export declare const LAZY_LOADER_SYMBOL: unique symbol;
|
4
2
|
export interface Lazy<T> {
|
5
3
|
[LAZY_LOADER_SYMBOL]: () => Promise<{
|
6
4
|
default: T;
|
7
5
|
}>;
|
8
6
|
}
|
7
|
+
export type Lazyable<T> = T | Lazy<T>;
|
9
8
|
export type ANY_LAZY = Lazy<any>;
|
10
|
-
export declare function
|
9
|
+
export declare function lazy<T>(loader: () => Promise<{
|
11
10
|
default: T;
|
12
11
|
}>): Lazy<T>;
|
13
|
-
export declare function loadLazy<T>(lazy: Lazy<T>): Promise<{
|
14
|
-
default: T;
|
15
|
-
}>;
|
16
12
|
export declare function isLazy(item: unknown): item is ANY_LAZY;
|
13
|
+
export declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
14
|
+
default: T extends Lazy<infer U> ? U : T;
|
15
|
+
}>;
|
17
16
|
export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
|
18
|
-
export declare function
|
19
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : (T extends Procedure<infer UContext, any, any, any, any> ? Lazy<T> & (undefined extends UContext ? ProcedureCaller<T> : unknown) : T extends Record<any, any> ? {
|
20
|
-
[K in keyof T]: DecoratedLazy<T[K]>;
|
21
|
-
} /** Notice: this still a lazy, but type not work when I & Lazy<T>, maybe it's a bug, should improve */ : Lazy<T>);
|
22
|
-
export declare function decorateLazy<T>(lazy: Lazy<T>): DecoratedLazy<T>;
|
17
|
+
export declare function flatLazy<T extends ANY_LAZY>(lazied: T): FlattenLazy<T>;
|
23
18
|
//# sourceMappingURL=lazy.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { ContextGuard } from './context';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
+
import type { Context, MergeContext } from './types';
|
5
|
+
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap> {
|
6
|
+
concat: (<UExtraContext extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput, TErrorConstructorMap>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>) & (<UExtraContext extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput, TErrorConstructorMap>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>);
|
7
|
+
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput, TErrorConstructorMap>;
|
8
|
+
}
|
9
|
+
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap>;
|
10
|
+
//# sourceMappingURL=middleware-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,26 +1,36 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
|
+
import type { ANY_PROCEDURE } from './procedure';
|
4
|
+
import type { AbortSignal, Context } from './types';
|
3
5
|
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
4
6
|
output: TOutput;
|
5
7
|
context: TExtraContext;
|
6
8
|
}>;
|
7
|
-
export interface
|
8
|
-
|
9
|
+
export interface MiddlewareNextFn<TOutput> {
|
10
|
+
<UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
|
9
11
|
context?: UExtraContext;
|
10
12
|
} : {
|
11
13
|
context: UExtraContext;
|
12
|
-
})
|
13
|
-
output: <UOutput>(output: UOutput) => MiddlewareResult<undefined, UOutput>;
|
14
|
+
}): MiddlewareResult<UExtraContext, TOutput>;
|
14
15
|
}
|
15
|
-
export interface
|
16
|
-
(
|
16
|
+
export interface MiddlewareOutputFn<TOutput> {
|
17
|
+
(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
17
18
|
}
|
19
|
+
export interface MiddlewareOptions<TContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
20
|
+
context: TContext;
|
21
|
+
path: string[];
|
22
|
+
procedure: ANY_PROCEDURE;
|
23
|
+
signal?: AbortSignal;
|
24
|
+
next: MiddlewareNextFn<TOutput>;
|
25
|
+
errors: TErrorConstructorMap;
|
26
|
+
}
|
27
|
+
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
28
|
+
(options: MiddlewareOptions<TContext, TOutput, TErrorConstructorMap>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
29
|
+
}
|
30
|
+
export type ANY_MIDDLEWARE = Middleware<any, any, any, any, any>;
|
18
31
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
19
32
|
(input: TInput): TMappedInput;
|
20
33
|
}
|
21
|
-
export
|
22
|
-
|
23
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
24
|
-
}
|
25
|
-
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput>;
|
34
|
+
export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
|
35
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
26
36
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import type { Context, MergeContext } from './types';
|
7
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
8
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
9
|
+
export interface ProcedureBuilderWithInputDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
|
10
|
+
contract: ContractProcedure<TInputSchema, undefined, TErrorMap>;
|
11
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>[];
|
12
|
+
inputValidationIndex: number;
|
13
|
+
outputValidationIndex: number;
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* `ProcedureBuilderWithInput` is a branch of `ProcedureBuilder` which it has input schema.
|
17
|
+
*
|
18
|
+
* Why?
|
19
|
+
* - prevents override input schema after .input
|
20
|
+
* - allows .use between .input and .output
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
export declare class ProcedureBuilderWithInput<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
|
24
|
+
'~type': "ProcedureBuilderWithInput";
|
25
|
+
'~orpc': ProcedureBuilderWithInputDef<TContext, TExtraContext, TInputSchema, TErrorMap>;
|
26
|
+
constructor(def: ProcedureBuilderWithInputDef<TContext, TExtraContext, TInputSchema, TErrorMap>);
|
27
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithInput<TContext, TExtraContext, TInputSchema, TErrorMap & U>;
|
28
|
+
route(route: RouteOptions): ProcedureBuilderWithInput<TContext, TExtraContext, TInputSchema, TErrorMap>;
|
29
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>>): ProcedureBuilderWithInput<TContext, MergeContext<TExtraContext, U>, TInputSchema, TErrorMap>;
|
30
|
+
use<UExtra extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TErrorMap>;
|
31
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureImplementer<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
|
32
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, undefined, UFuncOutput, TErrorMap>;
|
33
|
+
}
|
34
|
+
//# sourceMappingURL=procedure-builder-with-input.d.ts.map
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaInput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import type { Context, MergeContext } from './types';
|
7
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
8
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
9
|
+
export interface ProcedureBuilderWithOutputDef<TContext extends Context, TExtraContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
10
|
+
contract: ContractProcedure<undefined, TOutputSchema, TErrorMap>;
|
11
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
|
12
|
+
inputValidationIndex: number;
|
13
|
+
outputValidationIndex: number;
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* `ProcedureBuilderWithOutput` is a branch of `ProcedureBuilder` which it has output schema.
|
17
|
+
*
|
18
|
+
* Why?
|
19
|
+
* - prevents override output schema after .output
|
20
|
+
* - allows .use between .input and .output
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
export declare class ProcedureBuilderWithOutput<TContext extends Context, TExtraContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
24
|
+
'~type': "ProcedureBuilderWithOutput";
|
25
|
+
'~orpc': ProcedureBuilderWithOutputDef<TContext, TExtraContext, TOutputSchema, TErrorMap>;
|
26
|
+
constructor(def: ProcedureBuilderWithOutputDef<TContext, TExtraContext, TOutputSchema, TErrorMap>);
|
27
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithOutput<TContext, TExtraContext, TOutputSchema, TErrorMap & U>;
|
28
|
+
route(route: RouteOptions): ProcedureBuilderWithOutput<TContext, TExtraContext, TOutputSchema, TErrorMap>;
|
29
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureBuilderWithOutput<TContext, MergeContext<TExtraContext, U>, TOutputSchema, TErrorMap>;
|
30
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureImplementer<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
|
31
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>;
|
32
|
+
}
|
33
|
+
//# sourceMappingURL=procedure-builder-with-output.d.ts.map
|
@@ -1,31 +1,27 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
2
6
|
import type { Context, MergeContext } from './types';
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
input<
|
20
|
-
output<
|
21
|
-
|
22
|
-
* Convert to ProcedureBuilder
|
23
|
-
*/
|
24
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
25
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
26
|
-
/**
|
27
|
-
* Convert to Procedure
|
28
|
-
*/
|
29
|
-
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
7
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
8
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
9
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
10
|
+
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
11
|
+
contract: ContractProcedure<undefined, undefined, TErrorMap>;
|
12
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
|
13
|
+
inputValidationIndex: number;
|
14
|
+
outputValidationIndex: number;
|
15
|
+
}
|
16
|
+
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
17
|
+
'~type': "ProcedureBuilder";
|
18
|
+
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TErrorMap>;
|
19
|
+
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TErrorMap>);
|
20
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilder<TContext, TExtraContext, TErrorMap & U>;
|
21
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TErrorMap>;
|
22
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): ProcedureBuilder<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
|
23
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilderWithInput<TContext, TExtraContext, U, TErrorMap>;
|
24
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilderWithOutput<TContext, TExtraContext, U, TErrorMap>;
|
25
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>;
|
30
26
|
}
|
31
27
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Lazyable } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
import type { Context, Meta } from './types';
|
6
|
+
export type ProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
7
|
+
/**
|
8
|
+
* Options for creating a procedure caller with comprehensive type safety
|
9
|
+
*/
|
10
|
+
export type CreateProcedureClientOptions<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = {
|
11
|
+
/**
|
12
|
+
* This is helpful for logging and analytics.
|
13
|
+
*/
|
14
|
+
path?: string[];
|
15
|
+
} & ({
|
16
|
+
context: Value<TContext, [clientContext: TClientContext]>;
|
17
|
+
} | (undefined extends TContext ? {
|
18
|
+
context?: Value<TContext, [clientContext: TClientContext]>;
|
19
|
+
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
20
|
+
export type CreateProcedureClientRest<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TContext, TOutputSchema, THandlerOutput, TClientContext>] | (undefined extends TContext ? [] : never);
|
21
|
+
export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, ...[options]: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
22
|
+
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { ClientRest, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
6
|
+
import type { Context, MergeContext } from './types';
|
7
|
+
import { Procedure } from './procedure';
|
8
|
+
export declare class DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> {
|
9
|
+
static decorate<UContext extends Context, UExtraContext extends Context, UInputSchema extends Schema, UOutputSchema extends Schema, UHandlerOutput extends SchemaInput<UOutputSchema>, UErrorMap extends ErrorMap>(procedure: Procedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>): DecoratedProcedure<any, any, any, any, any, any> | DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>;
|
10
|
+
prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
11
|
+
route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
12
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap & U>;
|
13
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
|
+
use<UExtra extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
|
+
unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
|
+
unshiftMiddleware(...middlewares: Middleware<TContext, Context & Partial<MergeContext<TContext, TExtraContext>> | undefined, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
17
|
+
/**
|
18
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
19
|
+
*/
|
20
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
21
|
+
/**
|
22
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
23
|
+
*/
|
24
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
25
|
+
}
|
26
|
+
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,22 +1,22 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type {
|
3
|
-
import type {
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
4
6
|
import type { Context, MergeContext } from './types';
|
5
|
-
import {
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
use<
|
17
|
-
|
18
|
-
|
19
|
-
default: U;
|
20
|
-
}>): DecoratedLazy<U>;
|
7
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
8
|
+
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
9
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
10
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, any>[];
|
11
|
+
inputValidationIndex: number;
|
12
|
+
outputValidationIndex: number;
|
13
|
+
};
|
14
|
+
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
15
|
+
'~type': "ProcedureImplementer";
|
16
|
+
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
+
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
18
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
19
|
+
use<UExtra extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
20
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
21
21
|
}
|
22
22
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Lazyable } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { Context } from './types';
|
5
|
+
import { type CreateProcedureClientRest } from './procedure-client';
|
6
|
+
/**
|
7
|
+
* Directly call a procedure without creating a client.
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* const output = await call(getting, 'input')
|
12
|
+
* const output = await call(getting, 'input', { context: { db: 'postgres' } })
|
13
|
+
* ```
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
export declare function call<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,32 +1,45 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
4
|
import type { Lazy } from './lazy';
|
3
|
-
import type {
|
4
|
-
import type { Context, MergeContext
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
};
|
13
|
-
constructor(zz$p: {
|
14
|
-
middlewares?: Middleware<any, any, any, any>[];
|
15
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
16
|
-
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
17
|
-
});
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { AbortSignal, Context, MergeContext } from './types';
|
7
|
+
export interface ProcedureHandlerOptions<TContext extends Context, TExtraContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
8
|
+
context: MergeContext<TContext, TExtraContext>;
|
9
|
+
input: TInput;
|
10
|
+
path: string[];
|
11
|
+
procedure: ANY_PROCEDURE;
|
12
|
+
signal?: AbortSignal;
|
13
|
+
errors: TErrorConstructorMap;
|
18
14
|
}
|
19
|
-
export
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
16
|
+
(opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* Why is `ErrorConstructorMap` passed to `middlewares` as `any`?
|
20
|
+
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
|
+
*
|
22
|
+
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
23
|
+
* causes unexpected errors in the router (the root cause is unclear, but it occurs consistently).
|
24
|
+
* To avoid these issues, `any` is used as a workaround.
|
25
|
+
*
|
26
|
+
* This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
|
27
|
+
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
|
+
*/
|
29
|
+
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
30
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, any>[];
|
31
|
+
inputValidationIndex: number;
|
32
|
+
outputValidationIndex: number;
|
33
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
34
|
+
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
29
35
|
}
|
30
|
-
export declare
|
36
|
+
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
37
|
+
'~type': "Procedure";
|
38
|
+
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
39
|
+
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
40
|
+
}
|
41
|
+
export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any>;
|
42
|
+
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any>;
|
43
|
+
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
31
44
|
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
32
45
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -1,27 +1,33 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { FlattenLazy, Lazy } from './lazy';
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { Procedure } from './procedure';
|
7
|
+
import type { ANY_ROUTER, Router } from './router';
|
3
8
|
import type { Context, MergeContext } from './types';
|
4
|
-
import { type
|
5
|
-
import {
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
import { type DecoratedLazy } from './lazy-decorated';
|
10
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
11
|
+
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER, TErrorMapExtra extends ErrorMap> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U, TErrorMapExtra>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap & TErrorMapExtra> : {
|
12
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K], TErrorMapExtra> : never;
|
13
|
+
};
|
14
|
+
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> = {
|
15
|
+
prefix?: HTTPPath;
|
16
|
+
tags?: readonly string[];
|
17
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
|
18
|
+
errorMap: TErrorMap;
|
19
|
+
};
|
20
|
+
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
21
|
+
'~type': "RouterBuilder";
|
22
|
+
'~orpc': RouterBuilderDef<TContext, TExtraContext, TErrorMap>;
|
23
|
+
constructor(def: RouterBuilderDef<TContext, TExtraContext, TErrorMap>);
|
24
|
+
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, TErrorMap>;
|
25
|
+
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, TErrorMap>;
|
26
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): RouterBuilder<TContext, TExtraContext, TErrorMap & U>;
|
27
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): RouterBuilder<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
|
28
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
|
29
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
24
30
|
default: U;
|
25
|
-
}>):
|
31
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
|
26
32
|
}
|
27
33
|
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import type { Hooks, Value } from '@orpc/shared';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import type { Meta } from './types';
|
6
|
+
import { type ANY_ROUTER, type Router } from './router';
|
7
|
+
/**
|
8
|
+
* FIXME: separate RouterClient and ContractRouterClient, don't mix them
|
9
|
+
*/
|
10
|
+
export type RouterClient<TRouter extends ANY_ROUTER, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
11
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
|
12
|
+
};
|
13
|
+
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
14
|
+
/**
|
15
|
+
* This is helpful for logging and analytics.
|
16
|
+
*
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
path?: string[];
|
20
|
+
} & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
|
21
|
+
context?: Value<UContext>;
|
22
|
+
} : {
|
23
|
+
context: Value<UContext>;
|
24
|
+
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
25
|
+
export declare function createRouterClient<TRouter extends ANY_ROUTER, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
26
|
+
//# sourceMappingURL=router-client.d.ts.map
|