@orpc/server 0.0.0-next.eb37cbe → 0.0.0-next.ed15210
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-6YJ5NGUE.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/chunk-XHFINNVL.js +217 -0
- package/dist/fetch.js +10 -310
- package/dist/hono.js +30 -0
- package/dist/index.js +718 -193
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/{fetch → adapters/fetch}/index.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/{fetch → adapters/fetch}/orpc-payload-codec.d.ts +1 -1
- package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +2 -2
- 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 +49 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +49 -0
- package/dist/src/builder.d.ts +35 -24
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +10 -0
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +1 -3
- package/dist/src/implementer-chainable.d.ts +11 -5
- package/dist/src/index.d.ts +7 -4
- package/dist/src/lazy-decorated.d.ts +4 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +29 -13
- package/dist/src/procedure-builder-with-input.d.ts +35 -0
- package/dist/src/procedure-builder-with-output.d.ts +34 -0
- package/dist/src/procedure-builder.d.ts +24 -18
- package/dist/src/procedure-client.d.ts +9 -22
- package/dist/src/procedure-decorated.d.ts +22 -11
- package/dist/src/procedure-implementer.d.ts +18 -13
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +37 -13
- package/dist/src/router-builder.d.ts +20 -16
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +15 -12
- package/dist/src/router-utils.d.ts +15 -0
- package/dist/src/router.d.ts +9 -6
- package/dist/src/types.d.ts +2 -3
- package/package.json +24 -8
- package/dist/chunk-37HIYNDO.js +0 -182
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/types.d.ts +0 -16
- package/dist/src/utils.d.ts +0 -3
- /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
package/dist/src/index.d.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
import type { WELL_CONTEXT } from './types';
|
2
1
|
import { Builder } from './builder';
|
3
2
|
export * from './builder';
|
3
|
+
export * from './config';
|
4
|
+
export * from './context';
|
5
|
+
export * from './error';
|
4
6
|
export * from './hidden';
|
5
7
|
export * from './implementer-chainable';
|
6
8
|
export * from './lazy';
|
@@ -12,12 +14,13 @@ export * from './procedure-builder';
|
|
12
14
|
export * from './procedure-client';
|
13
15
|
export * from './procedure-decorated';
|
14
16
|
export * from './procedure-implementer';
|
17
|
+
export * from './procedure-utils';
|
15
18
|
export * from './router';
|
16
19
|
export * from './router-builder';
|
17
20
|
export * from './router-client';
|
18
21
|
export * from './router-implementer';
|
22
|
+
export * from './router-utils';
|
19
23
|
export * from './types';
|
20
|
-
export
|
21
|
-
export
|
22
|
-
export declare const os: Builder<WELL_CONTEXT, undefined>;
|
24
|
+
export { isDefinedError, ORPCError, safe, type } from '@orpc/contract';
|
25
|
+
export declare const os: Builder<import("./context").Context>;
|
23
26
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Lazy } from './lazy';
|
3
|
-
import type {
|
4
|
-
import type { ProcedureClient } from './procedure-client';
|
2
|
+
import type { ANY_PROCEDURE } from './procedure';
|
5
3
|
import { type ANY_ROUTER } from './router';
|
6
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends
|
7
|
-
[K in keyof T]:
|
8
|
-
});
|
4
|
+
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_PROCEDURE ? unknown : T extends ANY_ROUTER ? {
|
5
|
+
[K in keyof T]: DecoratedLazy<T[K]>;
|
6
|
+
} : unknown);
|
9
7
|
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
10
8
|
//# sourceMappingURL=lazy-decorated.d.ts.map
|
@@ -1,8 +1,9 @@
|
|
1
|
+
import type { Context } from './context';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
1
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
4
|
+
export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap> {
|
5
|
+
concat: (<UOutContext extends Context, UInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UInput & TInput, TOutput, TErrorConstructorMap>) => DecoratedMiddleware<TInContext, TOutContext & UOutContext, UInput & TInput, TOutput, TErrorConstructorMap>) & (<UOutContext extends Context, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<TInContext & TOutContext, UOutContext, UMappedInput, TOutput, TErrorConstructorMap>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>) => DecoratedMiddleware<TInContext, TOutContext & UOutContext, UInput & TInput, TOutput, TErrorConstructorMap>);
|
6
|
+
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap>;
|
6
7
|
}
|
7
|
-
export declare function decorateMiddleware<
|
8
|
+
export declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap>;
|
8
9
|
//# sourceMappingURL=middleware-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,23 +1,39 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type { Context
|
3
|
-
|
2
|
+
import type { Context } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { ANY_PROCEDURE } from './procedure';
|
5
|
+
import type { AbortSignal } from './types';
|
6
|
+
export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
4
7
|
output: TOutput;
|
5
|
-
context:
|
8
|
+
context: TOutContext;
|
6
9
|
}>;
|
7
|
-
export
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
export type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
11
|
+
context?: TOutContext;
|
12
|
+
} : {
|
13
|
+
context: TOutContext;
|
14
|
+
};
|
15
|
+
export type MiddlewareNextFnRest<TOutContext extends Context> = [options: MiddlewareNextFnOptions<TOutContext>] | (Record<never, never> extends TOutContext ? [] : never);
|
16
|
+
export interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
17
|
+
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MiddlewareNextFnRest<U>): MiddlewareResult<U, TOutput>;
|
14
18
|
}
|
15
|
-
export interface
|
16
|
-
(
|
19
|
+
export interface MiddlewareOutputFn<TOutput> {
|
20
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
17
21
|
}
|
18
|
-
export
|
22
|
+
export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
23
|
+
context: TInContext;
|
24
|
+
path: string[];
|
25
|
+
procedure: ANY_PROCEDURE;
|
26
|
+
signal?: AbortSignal;
|
27
|
+
next: MiddlewareNextFn<TInContext, TOutput>;
|
28
|
+
errors: TErrorConstructorMap;
|
29
|
+
}
|
30
|
+
export interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
31
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
32
|
+
}
|
33
|
+
export type ANY_MIDDLEWARE = Middleware<any, any, any, any, any>;
|
19
34
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
20
35
|
(input: TInput): TMappedInput;
|
21
36
|
}
|
22
37
|
export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
|
38
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
23
39
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, Route, Schema, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
8
|
+
export interface ProcedureBuilderWithInputDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
10
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
11
|
+
contract: ContractProcedure<TInputSchema, undefined, TErrorMap, Route>;
|
12
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
13
|
+
inputValidationIndex: number;
|
14
|
+
outputValidationIndex: number;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* `ProcedureBuilderWithInput` is a branch of `ProcedureBuilder` which it has input schema.
|
18
|
+
*
|
19
|
+
* Why?
|
20
|
+
* - prevents override input schema after .input
|
21
|
+
* - allows .use between .input and .output
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export declare class ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
|
25
|
+
'~type': "ProcedureBuilderWithInput";
|
26
|
+
'~orpc': ProcedureBuilderWithInputDef<TInitialContext, TCurrentContext, TInputSchema, TErrorMap>;
|
27
|
+
constructor(def: ProcedureBuilderWithInputDef<TInitialContext, TCurrentContext, TInputSchema, TErrorMap>);
|
28
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TErrorMap & U>;
|
29
|
+
route(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TErrorMap>;
|
30
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureBuilderWithInput<TInitialContext, TCurrentContext & U, TInputSchema, TErrorMap>;
|
31
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<TCurrentContext & UOutContext> & ProcedureBuilderWithInput<TInitialContext, TCurrentContext & UOutContext, TInputSchema, TErrorMap>;
|
32
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureImplementer<TInitialContext, TCurrentContext, TInputSchema, U, TErrorMap, Route>;
|
33
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, TInputSchema, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, undefined, UFuncOutput, TErrorMap, Route>;
|
34
|
+
}
|
35
|
+
//# sourceMappingURL=procedure-builder-with-input.d.ts.map
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, Route, Schema, SchemaInput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
8
|
+
export interface ProcedureBuilderWithOutputDef<TInitialContext extends Context, TCurrentContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
10
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
11
|
+
contract: ContractProcedure<undefined, TOutputSchema, TErrorMap, Route>;
|
12
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
13
|
+
inputValidationIndex: number;
|
14
|
+
outputValidationIndex: number;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* `ProcedureBuilderWithOutput` is a branch of `ProcedureBuilder` which it has output schema.
|
18
|
+
*
|
19
|
+
* Why?
|
20
|
+
* - prevents override output schema after .output
|
21
|
+
* - allows .use between .input and .output
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export declare class ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
25
|
+
'~type': "ProcedureBuilderWithOutput";
|
26
|
+
'~orpc': ProcedureBuilderWithOutputDef<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap>;
|
27
|
+
constructor(def: ProcedureBuilderWithOutputDef<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap>);
|
28
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap & U>;
|
29
|
+
route(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TOutputSchema, TErrorMap>;
|
30
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureBuilderWithOutput<TInitialContext, TCurrentContext & U, TOutputSchema, TErrorMap>;
|
31
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureImplementer<TInitialContext, TCurrentContext, U, TOutputSchema, TErrorMap, Route>;
|
32
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, undefined, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, undefined, TOutputSchema, UFuncOutput, TErrorMap, Route>;
|
33
|
+
}
|
34
|
+
//# sourceMappingURL=procedure-builder-with-output.d.ts.map
|
@@ -1,22 +1,28 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
7
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
8
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
9
|
+
export interface ProcedureBuilderDef<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
10
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
11
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
12
|
+
contract: ContractProcedure<undefined, undefined, TErrorMap, Route>;
|
13
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
14
|
+
inputValidationIndex: number;
|
15
|
+
outputValidationIndex: number;
|
10
16
|
}
|
11
|
-
export declare class ProcedureBuilder<
|
17
|
+
export declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
12
18
|
'~type': "ProcedureBuilder";
|
13
|
-
'~orpc': ProcedureBuilderDef<
|
14
|
-
constructor(def: ProcedureBuilderDef<
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
handler<UFuncOutput
|
19
|
+
'~orpc': ProcedureBuilderDef<TInitialContext, TCurrentContext, TErrorMap>;
|
20
|
+
constructor(def: ProcedureBuilderDef<TInitialContext, TCurrentContext, TErrorMap>);
|
21
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TErrorMap & U>;
|
22
|
+
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
23
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureBuilder<TInitialContext, TCurrentContext & U, TErrorMap>;
|
24
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, U, TErrorMap>;
|
25
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, U, TErrorMap>;
|
26
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, undefined, undefined, UFuncOutput, TErrorMap, Route>;
|
21
27
|
}
|
22
28
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,34 +1,21 @@
|
|
1
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Context } from './context';
|
3
4
|
import type { Lazyable } from './lazy';
|
4
5
|
import type { Procedure } from './procedure';
|
5
|
-
import type {
|
6
|
-
export type
|
7
|
-
context?: TClientContext;
|
8
|
-
} : {
|
9
|
-
context: TClientContext;
|
10
|
-
});
|
11
|
-
export interface ProcedureClient<TInput, TOutput, TClientContext> {
|
12
|
-
(...opts: [input: TInput, options: ProcedureClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never)): Promise<TOutput>;
|
13
|
-
}
|
6
|
+
import type { Meta } from './types';
|
7
|
+
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>>;
|
14
8
|
/**
|
15
9
|
* Options for creating a procedure caller with comprehensive type safety
|
16
10
|
*/
|
17
|
-
export type CreateProcedureClientOptions<
|
18
|
-
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput>>;
|
11
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
|
19
12
|
/**
|
20
13
|
* This is helpful for logging and analytics.
|
21
|
-
*
|
22
|
-
* @internal
|
23
14
|
*/
|
24
15
|
path?: string[];
|
25
16
|
} & ({
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
} | (undefined extends TContext ? {
|
31
|
-
context?: undefined;
|
32
|
-
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
33
|
-
export declare function createProcedureClient<TContext extends Context = WELL_CONTEXT, TInputSchema extends Schema = undefined, TOutputSchema extends Schema = undefined, THandlerOutput extends SchemaInput<TOutputSchema> = SchemaInput<TOutputSchema>>(options: CreateProcedureClientOptions<TContext, TInputSchema, TOutputSchema, THandlerOutput>): ProcedureClient<SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, unknown>;
|
17
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
18
|
+
} | (Record<never, never> extends TInitialContext ? Record<never, never> : never)) & Hooks<unknown, SchemaOutput<TCurrentContext, THandlerOutput>, TInitialContext, Meta>;
|
19
|
+
export type CreateProcedureClientRest<TInitialContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
|
20
|
+
export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, any>>, ...[options]: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
34
21
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -1,14 +1,25 @@
|
|
1
|
-
import type { HTTPPath,
|
1
|
+
import type { ClientRest, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
-
import type { Context, MergeContext } from './types';
|
5
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
6
|
import { Procedure } from './procedure';
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
export declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TRoute extends Route> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute> {
|
8
|
+
static decorate<UInitialContext extends Context, UCurrentContext extends Context, UInputSchema extends Schema, UOutputSchema extends Schema, UHandlerOutput extends SchemaInput<UOutputSchema>, UErrorMap extends ErrorMap, URoute extends Route>(procedure: Procedure<UInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap, URoute>): DecoratedProcedure<any, any, any, any, any, any, any> | DecoratedProcedure<UInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap, URoute>;
|
9
|
+
prefix(prefix: HTTPPath): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, Route>;
|
10
|
+
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, Route>;
|
11
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap & U, TRoute>;
|
12
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & DecoratedProcedure<TInitialContext, TCurrentContext & U, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>;
|
13
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): ConflictContextGuard<TCurrentContext & UOutContext> & DecoratedProcedure<TInitialContext, TCurrentContext & UOutContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>;
|
14
|
+
unshiftTag(...tags: string[]): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, Route>;
|
15
|
+
unshiftMiddleware<U extends Context>(...middlewares: Middleware<TInitialContext, U, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): ConflictContextGuard<TInitialContext & U> & DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>;
|
16
|
+
/**
|
17
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
18
|
+
*/
|
19
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
|
+
/**
|
21
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
22
|
+
*/
|
23
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
24
|
+
}
|
14
25
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,18 +1,23 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ErrorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type {
|
4
|
-
import
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
export type ProcedureImplementerDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> = {
|
8
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
9
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
10
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TRoute>;
|
11
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
12
|
+
inputValidationIndex: number;
|
13
|
+
outputValidationIndex: number;
|
9
14
|
};
|
10
|
-
export declare class ProcedureImplementer<
|
15
|
+
export declare class ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> {
|
11
16
|
'~type': "ProcedureImplementer";
|
12
|
-
'~orpc': ProcedureImplementerDef<
|
13
|
-
constructor(def: ProcedureImplementerDef<
|
14
|
-
use<U extends Context
|
15
|
-
use<
|
16
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler:
|
17
|
+
'~orpc': ProcedureImplementerDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TRoute>;
|
18
|
+
constructor(def: ProcedureImplementerDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TRoute>);
|
19
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & ProcedureImplementer<TInitialContext, TCurrentContext & U, TInputSchema, TOutputSchema, TErrorMap, TRoute>;
|
20
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<TCurrentContext & UOutContext> & ProcedureImplementer<TInitialContext, TCurrentContext & UOutContext, TInputSchema, TOutputSchema, TErrorMap, TRoute>;
|
21
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TRoute>;
|
17
22
|
}
|
18
23
|
//# 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 { Context } from './context';
|
3
|
+
import type { Lazyable } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
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<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, any>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,23 +1,47 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
5
|
import type { Lazy } from './lazy';
|
3
6
|
import type { Middleware } from './middleware';
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
import type { AbortSignal } from './types';
|
8
|
+
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
9
|
+
context: TCurrentContext;
|
10
|
+
input: TInput;
|
11
|
+
path: string[];
|
12
|
+
procedure: ANY_PROCEDURE;
|
13
|
+
signal?: AbortSignal;
|
14
|
+
errors: TErrorConstructorMap;
|
8
15
|
}
|
9
|
-
export interface
|
10
|
-
|
11
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
12
|
-
handler: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
16
|
+
export interface ProcedureHandler<TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
17
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
13
18
|
}
|
14
|
-
|
19
|
+
/**
|
20
|
+
* Why is `ErrorConstructorMap` passed to `middlewares` as `any`?
|
21
|
+
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
22
|
+
*
|
23
|
+
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
24
|
+
* causes unexpected errors in the router (the root cause is unclear, but it occurs consistently).
|
25
|
+
* To avoid these issues, `any` is used as a workaround.
|
26
|
+
*
|
27
|
+
* This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
|
28
|
+
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
29
|
+
*/
|
30
|
+
export interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TRoute extends Route> {
|
31
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
32
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
33
|
+
inputValidationIndex: number;
|
34
|
+
outputValidationIndex: number;
|
35
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TRoute>;
|
36
|
+
handler: ProcedureHandler<TCurrentContext, any, any, THandlerOutput, any>;
|
37
|
+
}
|
38
|
+
export declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TRoute extends Route> {
|
15
39
|
'~type': "Procedure";
|
16
|
-
'~orpc': ProcedureDef<
|
17
|
-
constructor(def: ProcedureDef<
|
40
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>;
|
41
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>);
|
18
42
|
}
|
19
|
-
export type ANY_PROCEDURE = Procedure<any, any, any, any, any>;
|
20
|
-
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>;
|
43
|
+
export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any, any>;
|
44
|
+
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any, any>;
|
21
45
|
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
22
46
|
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
23
47
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -1,29 +1,33 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, Route, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
3
|
import type { FlattenLazy, Lazy } from './lazy';
|
3
4
|
import type { Middleware } from './middleware';
|
4
5
|
import type { Procedure } from './procedure';
|
5
6
|
import type { ANY_ROUTER, Router } from './router';
|
6
|
-
import type { Context, MergeContext } from './types';
|
7
7
|
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
-
import {
|
9
|
-
export type AdaptedRouter<
|
10
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<
|
8
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
9
|
+
export type AdaptedRouter<TInitialContext extends Context, TRouter extends ANY_ROUTER, TErrorMapExtra extends ErrorMap> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TInitialContext, U, TErrorMapExtra>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? DecoratedProcedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap & TErrorMapExtra, Route> : {
|
10
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TInitialContext, TRouter[K], TErrorMapExtra> : never;
|
11
11
|
};
|
12
|
-
export type RouterBuilderDef<
|
12
|
+
export type RouterBuilderDef<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = {
|
13
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
14
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
13
15
|
prefix?: HTTPPath;
|
14
16
|
tags?: readonly string[];
|
15
|
-
middlewares
|
17
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
18
|
+
errorMap: TErrorMap;
|
16
19
|
};
|
17
|
-
export declare class RouterBuilder<
|
20
|
+
export declare class RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
18
21
|
'~type': "RouterBuilder";
|
19
|
-
'~orpc': RouterBuilderDef<
|
20
|
-
constructor(def: RouterBuilderDef<
|
21
|
-
prefix(prefix: HTTPPath): RouterBuilder<
|
22
|
-
tag(...tags: string[]): RouterBuilder<
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
'~orpc': RouterBuilderDef<TInitialContext, TCurrentContext, TErrorMap>;
|
23
|
+
constructor(def: RouterBuilderDef<TInitialContext, TCurrentContext, TErrorMap>);
|
24
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
25
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
26
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, StrictErrorMap<U> & TErrorMap>;
|
27
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, Record<never, never>>): ConflictContextGuard<TCurrentContext & U> & RouterBuilder<TInitialContext, TCurrentContext & U, TErrorMap>;
|
28
|
+
router<U extends Router<TCurrentContext, ContractRouter<ErrorMap & Partial<TErrorMap>>>>(router: U): AdaptedRouter<TInitialContext, U, TErrorMap>;
|
29
|
+
lazy<U extends Router<TCurrentContext, ContractRouter<ErrorMap & Partial<TErrorMap>>>>(loader: () => Promise<{
|
26
30
|
default: U;
|
27
|
-
}>): AdaptedRouter<
|
31
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, TErrorMap>;
|
28
32
|
}
|
29
33
|
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -1,15 +1,16 @@
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Hooks, Value } from '@orpc/shared';
|
3
2
|
import type { Lazy } from './lazy';
|
4
3
|
import type { Procedure } from './procedure';
|
5
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
6
5
|
import type { Meta } from './types';
|
7
6
|
import { type ANY_ROUTER, type Router } from './router';
|
8
|
-
|
9
|
-
|
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, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
11
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
|
10
12
|
};
|
11
13
|
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
12
|
-
router: TRouter | Lazy<undefined>;
|
13
14
|
/**
|
14
15
|
* This is helpful for logging and analytics.
|
15
16
|
*
|
@@ -21,5 +22,5 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
|
21
22
|
} : {
|
22
23
|
context: Value<UContext>;
|
23
24
|
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
24
|
-
export declare function createRouterClient<TRouter extends ANY_ROUTER>(
|
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>;
|
25
26
|
//# sourceMappingURL=router-client.d.ts.map
|
@@ -1,21 +1,24 @@
|
|
1
1
|
import type { ContractRouter } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
3
|
import type { FlattenLazy } from './lazy';
|
3
4
|
import type { Middleware } from './middleware';
|
4
|
-
import type { Router } from './router';
|
5
|
-
import type
|
6
|
-
|
7
|
-
export interface RouterImplementerDef<
|
8
|
-
|
5
|
+
import type { Router, RouterToContract } from './router';
|
6
|
+
import { type UnshiftedMiddlewaresRouter } from './router-utils';
|
7
|
+
export type EqualContractGuard<TContract extends ContractRouter<any>, TRouter extends Router<any, TContract>> = TContract extends RouterToContract<TRouter> ? unknown : never;
|
8
|
+
export interface RouterImplementerDef<TInitialContext extends Context, TCurrentContext extends Context, TContract extends ContractRouter<any>> {
|
9
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
10
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
11
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
9
12
|
contract: TContract;
|
10
13
|
}
|
11
|
-
export declare class RouterImplementer<
|
14
|
+
export declare class RouterImplementer<TInitialContext extends Context, TCurrentContext extends Context, TContract extends ContractRouter<any>> {
|
12
15
|
'~type': "RouterImplementer";
|
13
|
-
'~orpc': RouterImplementerDef<
|
14
|
-
constructor(def: RouterImplementerDef<
|
15
|
-
use<U extends Context
|
16
|
-
router<U extends Router<
|
17
|
-
lazy<U extends Router<
|
16
|
+
'~orpc': RouterImplementerDef<TInitialContext, TCurrentContext, TContract>;
|
17
|
+
constructor(def: RouterImplementerDef<TInitialContext, TCurrentContext, TContract>);
|
18
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, Record<never, never>>): ConflictContextGuard<TCurrentContext & U> & RouterImplementer<TInitialContext, TCurrentContext & U, TContract>;
|
19
|
+
router<U extends Router<TCurrentContext, TContract>>(router: U): EqualContractGuard<TContract, U> & UnshiftedMiddlewaresRouter<U, TInitialContext>;
|
20
|
+
lazy<U extends Router<TCurrentContext, TContract>>(loader: () => Promise<{
|
18
21
|
default: U;
|
19
|
-
}>):
|
22
|
+
}>): EqualContractGuard<TContract, U> & UnshiftedMiddlewaresRouter<FlattenLazy<U>, TInitialContext>;
|
20
23
|
}
|
21
24
|
//# sourceMappingURL=router-implementer.d.ts.map
|