@orpc/server 0.0.0-next.e9dc36e → 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 +12 -678
- package/dist/hono.js +30 -0
- package/dist/index.js +918 -269
- 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 +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 +42 -45
- 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 +4 -0
- package/dist/src/implementer-chainable.d.ts +16 -0
- package/dist/src/index.d.ts +16 -5
- package/dist/src/lazy-decorated.d.ts +8 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +18 -0
- package/dist/src/middleware-decorated.d.ts +9 -0
- package/dist/src/middleware.d.ts +30 -17
- 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 +26 -29
- package/dist/src/procedure-client.d.ts +21 -0
- package/dist/src/procedure-decorated.d.ts +25 -0
- package/dist/src/procedure-implementer.d.ts +21 -16
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +43 -25
- package/dist/src/router-builder.d.ts +31 -20
- package/dist/src/router-client.d.ts +26 -0
- package/dist/src/router-implementer.d.ts +21 -17
- package/dist/src/router-utils.d.ts +15 -0
- package/dist/src/router.d.ts +14 -15
- package/dist/src/types.d.ts +8 -5
- package/package.json +29 -21
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/chunk-TDFYNRZV.js.map +0 -1
- package/dist/fetch.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/src/adapters/fetch.d.ts +0 -42
- package/dist/src/adapters/fetch.d.ts.map +0 -1
- package/dist/src/builder.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/middleware.d.ts.map +0 -1
- package/dist/src/procedure-builder.d.ts.map +0 -1
- package/dist/src/procedure-caller.d.ts +0 -19
- package/dist/src/procedure-caller.d.ts.map +0 -1
- package/dist/src/procedure-implementer.d.ts.map +0 -1
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router-builder.d.ts.map +0 -1
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-caller.d.ts.map +0 -1
- package/dist/src/router-implementer.d.ts.map +0 -1
- package/dist/src/router.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils.d.ts +0 -3
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/adapters/fetch.test.ts +0 -629
- package/src/adapters/fetch.ts +0 -290
- package/src/builder.test.ts +0 -371
- package/src/builder.ts +0 -238
- package/src/index.ts +0 -16
- package/src/middleware.test.ts +0 -260
- package/src/middleware.ts +0 -136
- package/src/procedure-builder.test.ts +0 -223
- package/src/procedure-builder.ts +0 -158
- package/src/procedure-caller.test.ts +0 -171
- package/src/procedure-caller.ts +0 -138
- package/src/procedure-implementer.test.ts +0 -220
- package/src/procedure-implementer.ts +0 -102
- package/src/procedure.test.ts +0 -317
- package/src/procedure.ts +0 -237
- package/src/router-builder.test.ts +0 -106
- package/src/router-builder.ts +0 -122
- package/src/router-caller.test.ts +0 -126
- package/src/router-caller.ts +0 -64
- package/src/router-implementer.test.ts +0 -116
- package/src/router-implementer.ts +0 -113
- package/src/router.test-d.ts +0 -48
- package/src/router.test.ts +0 -142
- package/src/router.ts +0 -91
- package/src/types.test.ts +0 -18
- package/src/types.ts +0 -13
- package/src/utils.test.ts +0 -16
- package/src/utils.ts +0 -16
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { Context, TypeCurrentContext, TypeInitialContext } from './context';
|
2
|
+
import type { Middleware } from './middleware';
|
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<TInitialContext extends Context, TCurrentContext extends Context, TContract extends ContractRouter<any>> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer URoute> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, URoute> : {
|
7
|
+
[K in keyof TContract]: TContract[K] extends ContractRouter<any> ? ChainableImplementer<TInitialContext, TCurrentContext, TContract[K]> : never;
|
8
|
+
} & Omit<RouterImplementer<TInitialContext, TCurrentContext, TContract>, '~type' | '~orpc'>;
|
9
|
+
export declare function createChainableImplementer<TInitialContext extends Context, TCurrentContext extends Context, TContract extends ContractRouter<any>>(contract: TContract, options: {
|
10
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
11
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
12
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
13
|
+
inputValidationIndex: number;
|
14
|
+
outputValidationIndex: number;
|
15
|
+
}): ChainableImplementer<TInitialContext, TCurrentContext, TContract>;
|
16
|
+
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
import { Builder } from './builder';
|
2
2
|
export * from './builder';
|
3
|
+
export * from './config';
|
4
|
+
export * from './context';
|
5
|
+
export * from './error';
|
6
|
+
export * from './hidden';
|
7
|
+
export * from './implementer-chainable';
|
8
|
+
export * from './lazy';
|
9
|
+
export * from './lazy-decorated';
|
3
10
|
export * from './middleware';
|
11
|
+
export * from './middleware-decorated';
|
4
12
|
export * from './procedure';
|
5
13
|
export * from './procedure-builder';
|
6
|
-
export * from './procedure-
|
14
|
+
export * from './procedure-client';
|
15
|
+
export * from './procedure-decorated';
|
7
16
|
export * from './procedure-implementer';
|
17
|
+
export * from './procedure-utils';
|
8
18
|
export * from './router';
|
9
|
-
export * from './router-
|
19
|
+
export * from './router-builder';
|
20
|
+
export * from './router-client';
|
10
21
|
export * from './router-implementer';
|
22
|
+
export * from './router-utils';
|
11
23
|
export * from './types';
|
12
|
-
export
|
13
|
-
export
|
14
|
-
export declare const os: Builder<Record<string, unknown> | undefined, undefined>;
|
24
|
+
export { isDefinedError, ORPCError, safe, type } from '@orpc/contract';
|
25
|
+
export declare const os: Builder<import("./context").Context>;
|
15
26
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Lazy } from './lazy';
|
2
|
+
import type { ANY_PROCEDURE } from './procedure';
|
3
|
+
import { type ANY_ROUTER } from './router';
|
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);
|
7
|
+
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
8
|
+
//# sourceMappingURL=lazy-decorated.d.ts.map
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export declare const LAZY_LOADER_SYMBOL: unique symbol;
|
2
|
+
export interface Lazy<T> {
|
3
|
+
[LAZY_LOADER_SYMBOL]: () => Promise<{
|
4
|
+
default: T;
|
5
|
+
}>;
|
6
|
+
}
|
7
|
+
export type Lazyable<T> = T | Lazy<T>;
|
8
|
+
export type ANY_LAZY = Lazy<any>;
|
9
|
+
export declare function lazy<T>(loader: () => Promise<{
|
10
|
+
default: T;
|
11
|
+
}>): Lazy<T>;
|
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
|
+
}>;
|
16
|
+
export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
|
17
|
+
export declare function flatLazy<T extends ANY_LAZY>(lazied: T): FlattenLazy<T>;
|
18
|
+
//# sourceMappingURL=lazy.d.ts.map
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { Context } from './context';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
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>;
|
7
|
+
}
|
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>;
|
9
|
+
//# sourceMappingURL=middleware-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,26 +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
|
}
|
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>;
|
18
34
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
19
35
|
(input: TInput): TMappedInput;
|
20
36
|
}
|
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>;
|
37
|
+
export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
|
38
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
26
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,31 +1,28 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Context,
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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>;
|
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;
|
16
|
+
}
|
17
|
+
export declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
18
|
+
'~type': "ProcedureBuilder";
|
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>;
|
30
27
|
}
|
31
28
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Context } from './context';
|
4
|
+
import type { Lazyable } from './lazy';
|
5
|
+
import type { Procedure } from './procedure';
|
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>>;
|
8
|
+
/**
|
9
|
+
* Options for creating a procedure caller with comprehensive type safety
|
10
|
+
*/
|
11
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
|
12
|
+
/**
|
13
|
+
* This is helpful for logging and analytics.
|
14
|
+
*/
|
15
|
+
path?: string[];
|
16
|
+
} & ({
|
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>;
|
21
|
+
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -0,0 +1,25 @@
|
|
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';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
6
|
+
import { Procedure } from './procedure';
|
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
|
+
}
|
25
|
+
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,18 +1,23 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type { Context,
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
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;
|
14
|
+
};
|
15
|
+
export declare class ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TRoute extends Route> {
|
16
|
+
'~type': "ProcedureImplementer";
|
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,29 +1,47 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import
|
5
|
-
import
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
15
|
-
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
16
|
-
});
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
5
|
+
import type { Lazy } from './lazy';
|
6
|
+
import type { Middleware } from './middleware';
|
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;
|
17
15
|
}
|
18
|
-
export
|
19
|
-
|
20
|
-
route: (opts: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
21
|
-
use: (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, TFuncOutput>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema, TFuncOutput>) & (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema, TFuncOutput>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, TFuncOutput>, UMappedInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema, TFuncOutput>);
|
22
|
-
} & (undefined extends TContext ? ProcedureCaller<Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>> : unknown);
|
23
|
-
export interface ProcedureFunc<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TOutput extends SchemaOutput<TOutputSchema>> {
|
24
|
-
(input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, TOutput>>;
|
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>>;
|
25
18
|
}
|
26
|
-
|
27
|
-
|
28
|
-
|
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> {
|
39
|
+
'~type': "Procedure";
|
40
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>;
|
41
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TRoute>);
|
42
|
+
}
|
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>;
|
45
|
+
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
46
|
+
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
29
47
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -1,22 +1,33 @@
|
|
1
|
-
import type {
|
2
|
-
import type { Context,
|
3
|
-
import {
|
4
|
-
import
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, Route, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { FlattenLazy, Lazy } from './lazy';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { Procedure } from './procedure';
|
6
|
+
import type { ANY_ROUTER, Router } from './router';
|
7
|
+
import { type DecoratedLazy } from './lazy-decorated';
|
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
|
+
};
|
12
|
+
export type RouterBuilderDef<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = {
|
13
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
14
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
15
|
+
prefix?: HTTPPath;
|
16
|
+
tags?: readonly string[];
|
17
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
18
|
+
errorMap: TErrorMap;
|
19
|
+
};
|
20
|
+
export declare class RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
21
|
+
'~type': "RouterBuilder";
|
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<{
|
30
|
+
default: U;
|
31
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, TErrorMap>;
|
21
32
|
}
|
22
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, any> ? 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
|