@orpc/server 0.29.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-XDC42C3C.js → chunk-GK2Z6B6W.js} +34 -31
- package/dist/{chunk-VY6NXNQT.js → chunk-SXUFCJBY.js} +2 -2
- package/dist/fetch.js +2 -2
- package/dist/hono.js +2 -2
- package/dist/index.js +525 -88
- package/dist/next.js +2 -2
- package/dist/node.js +2 -2
- package/dist/src/builder-with-errors-middlewares.d.ts +50 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +47 -0
- package/dist/src/builder.d.ts +28 -21
- package/dist/src/context.d.ts +11 -0
- package/dist/src/error.d.ts +1 -1
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +7 -3
- package/dist/src/index.d.ts +2 -2
- package/dist/src/middleware-decorated.d.ts +2 -1
- package/dist/src/middleware.d.ts +1 -0
- 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 +19 -16
- package/dist/src/procedure-decorated.d.ts +8 -8
- package/dist/src/procedure-implementer.d.ts +6 -3
- package/dist/src/procedure.d.ts +4 -2
- package/dist/src/router-builder.d.ts +18 -14
- package/dist/src/router-implementer.d.ts +7 -6
- package/dist/src/router.d.ts +2 -2
- package/package.json +3 -3
package/dist/next.js
CHANGED
@@ -4,8 +4,8 @@ import {
|
|
4
4
|
ORPCProcedureMatcher,
|
5
5
|
RPCHandler,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-SXUFCJBY.js";
|
8
|
+
import "./chunk-GK2Z6B6W.js";
|
9
9
|
|
10
10
|
// src/adapters/next/serve.ts
|
11
11
|
import { value } from "@orpc/shared";
|
package/dist/node.js
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { FlattenLazy } from './lazy';
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { ProcedureHandler } from './procedure';
|
7
|
+
import type { Router } from './router';
|
8
|
+
import type { AdaptedRouter } from './router-builder';
|
9
|
+
import type { Context, MergeContext } from './types';
|
10
|
+
import { ProcedureBuilder } from './procedure-builder';
|
11
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
12
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
13
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
14
|
+
import { RouterBuilder } from './router-builder';
|
15
|
+
export interface BuilderWithErrorsMiddlewaresDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
16
|
+
types?: {
|
17
|
+
context: TContext;
|
18
|
+
};
|
19
|
+
errorMap: TErrorMap;
|
20
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
|
21
|
+
inputValidationIndex: number;
|
22
|
+
outputValidationIndex: number;
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* `BuilderWithErrorsMiddlewares` is a combination of `BuilderWithErrorsMiddlewares` and `BuilderWithErrors`.
|
26
|
+
*
|
27
|
+
* Why?
|
28
|
+
* - prevents .middleware after .use (can mislead the behavior)
|
29
|
+
* - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
|
30
|
+
* - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
export declare class BuilderWithErrorsMiddlewares<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
34
|
+
'~type': "BuilderWithErrorsMiddlewares";
|
35
|
+
'~orpc': BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>;
|
36
|
+
constructor(def: BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>);
|
37
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, TErrorMap & U>;
|
38
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
|
39
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TErrorMap>;
|
40
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, TErrorMap>;
|
41
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, TErrorMap>;
|
42
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>;
|
43
|
+
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, TErrorMap>;
|
44
|
+
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, TErrorMap>;
|
45
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
|
46
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
47
|
+
default: U;
|
48
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
|
49
|
+
}
|
50
|
+
//# sourceMappingURL=builder-with-errors-middlewares.d.ts.map
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { FlattenLazy } from './lazy';
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { DecoratedMiddleware } from './middleware-decorated';
|
7
|
+
import type { ProcedureHandler } from './procedure';
|
8
|
+
import type { Router } from './router';
|
9
|
+
import type { AdaptedRouter } from './router-builder';
|
10
|
+
import type { Context, MergeContext } from './types';
|
11
|
+
import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
|
12
|
+
import { ProcedureBuilder } from './procedure-builder';
|
13
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
14
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
15
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
16
|
+
import { RouterBuilder } from './router-builder';
|
17
|
+
export interface BuilderWithErrorsDef<TContext extends Context, TErrorMap extends ErrorMap> {
|
18
|
+
types?: {
|
19
|
+
context: TContext;
|
20
|
+
};
|
21
|
+
errorMap: TErrorMap;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* `BuilderWithErrors` is a branch of `Builder` which it has error map.
|
25
|
+
*
|
26
|
+
* Why?
|
27
|
+
* - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
|
28
|
+
*
|
29
|
+
*/
|
30
|
+
export declare class BuilderWithErrors<TContext extends Context, TErrorMap extends ErrorMap> {
|
31
|
+
'~type': "BuilderWithErrors";
|
32
|
+
'~orpc': BuilderWithErrorsDef<TContext, TErrorMap>;
|
33
|
+
constructor(def: BuilderWithErrorsDef<TContext, TErrorMap>);
|
34
|
+
context<UContext extends Context = TContext>(): BuilderWithErrors<UContext, TErrorMap>;
|
35
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, TErrorMap & U>;
|
36
|
+
middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>;
|
37
|
+
use<U extends Context & ContextGuard<TContext>>(middleware: Middleware<TContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, U, TErrorMap>;
|
38
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, undefined, TErrorMap>;
|
39
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, undefined, USchema, TErrorMap>;
|
40
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, undefined, USchema, TErrorMap>;
|
41
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>;
|
42
|
+
prefix(prefix: HTTPPath): RouterBuilder<TContext, undefined, TErrorMap>;
|
43
|
+
tag(...tags: string[]): RouterBuilder<TContext, undefined, TErrorMap>;
|
44
|
+
router<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
|
45
|
+
lazy<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
46
|
+
default: U;
|
47
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
|
48
|
+
}
|
49
|
+
//# sourceMappingURL=builder-with-errors.d.ts.map
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { FlattenLazy } from './lazy';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import type { Router } from './router';
|
7
|
+
import type { AdaptedRouter } from './router-builder';
|
8
|
+
import type { Context, MergeContext } from './types';
|
9
|
+
import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
|
10
|
+
import { type ChainableImplementer } from './implementer-chainable';
|
11
|
+
import { ProcedureBuilder } from './procedure-builder';
|
12
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
13
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
14
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
15
|
+
import { RouterBuilder } from './router-builder';
|
16
|
+
/**
|
17
|
+
* `BuilderWithMiddlewares` is a branch of `Builder` which it has middlewares.
|
18
|
+
*
|
19
|
+
* Why?
|
20
|
+
* - prevents .middleware after .use (can mislead the behavior)
|
21
|
+
* - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
export interface BuilderWithMiddlewaresDef<TContext extends Context, TExtraContext extends Context> {
|
25
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
|
26
|
+
inputValidationIndex: number;
|
27
|
+
outputValidationIndex: number;
|
28
|
+
}
|
29
|
+
export declare class BuilderWithMiddlewares<TContext extends Context, TExtraContext extends Context> {
|
30
|
+
'~type': "BuilderHasMiddlewares";
|
31
|
+
'~orpc': BuilderWithMiddlewaresDef<TContext, TExtraContext>;
|
32
|
+
constructor(def: BuilderWithMiddlewaresDef<TContext, TExtraContext>);
|
33
|
+
use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<TContext, MergeContext<TExtraContext, U>>;
|
34
|
+
errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, U>;
|
35
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, Record<never, never>>;
|
36
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, Record<never, never>>;
|
37
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, Record<never, never>>;
|
38
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>;
|
39
|
+
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
|
40
|
+
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
|
41
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
|
42
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
|
43
|
+
default: U;
|
44
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
|
45
|
+
contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TContext, TExtraContext, U>;
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=builder-with-middlewares.d.ts.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,36 +1,43 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
2
3
|
import type { FlattenLazy } from './lazy';
|
3
4
|
import type { Middleware } from './middleware';
|
4
5
|
import type { DecoratedMiddleware } from './middleware-decorated';
|
5
6
|
import type { ProcedureHandler } from './procedure';
|
6
7
|
import type { Router } from './router';
|
7
8
|
import type { AdaptedRouter } from './router-builder';
|
8
|
-
import type { Context, MergeContext
|
9
|
+
import type { Context, MergeContext } from './types';
|
10
|
+
import { BuilderWithErrors } from './builder-with-errors';
|
11
|
+
import { BuilderWithMiddlewares } from './builder-with-middlewares';
|
9
12
|
import { type ChainableImplementer } from './implementer-chainable';
|
10
13
|
import { ProcedureBuilder } from './procedure-builder';
|
14
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
15
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
11
16
|
import { DecoratedProcedure } from './procedure-decorated';
|
12
17
|
import { RouterBuilder } from './router-builder';
|
13
|
-
export interface BuilderDef<TContext extends Context
|
14
|
-
|
18
|
+
export interface BuilderDef<TContext extends Context> {
|
19
|
+
types?: {
|
20
|
+
context: TContext;
|
21
|
+
};
|
15
22
|
}
|
16
|
-
export declare class Builder<TContext extends Context
|
23
|
+
export declare class Builder<TContext extends Context> {
|
17
24
|
'~type': "Builder";
|
18
|
-
'~orpc': BuilderDef<TContext
|
19
|
-
constructor(def: BuilderDef<TContext
|
20
|
-
context<UContext extends Context =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
handler<UFuncOutput
|
28
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext,
|
29
|
-
tag(...tags: string[]): RouterBuilder<TContext,
|
30
|
-
router<U extends Router<MergeContext<TContext,
|
31
|
-
lazy<U extends Router<MergeContext<TContext,
|
25
|
+
'~orpc': BuilderDef<TContext>;
|
26
|
+
constructor(def: BuilderDef<TContext>);
|
27
|
+
context<UContext extends Context = TContext>(): Builder<UContext>;
|
28
|
+
middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, Record<never, never>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, Record<never, never>>;
|
29
|
+
errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, U>;
|
30
|
+
use<U extends Context & ContextGuard<TContext>>(middleware: Middleware<TContext, U, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<TContext, U>;
|
31
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, undefined, Record<never, never>>;
|
32
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, undefined, USchema, Record<never, never>>;
|
33
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, undefined, USchema, Record<never, never>>;
|
34
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TContext, undefined, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TContext, undefined, undefined, undefined, UFuncOutput, Record<never, never>>;
|
35
|
+
prefix(prefix: HTTPPath): RouterBuilder<TContext, undefined, Record<never, never>>;
|
36
|
+
tag(...tags: string[]): RouterBuilder<TContext, undefined, Record<never, never>>;
|
37
|
+
router<U extends Router<MergeContext<TContext, undefined>, any>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
|
38
|
+
lazy<U extends Router<MergeContext<TContext, undefined>, any>>(loader: () => Promise<{
|
32
39
|
default: U;
|
33
|
-
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
34
|
-
contract<U extends
|
40
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
|
41
|
+
contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TContext, undefined, U>;
|
35
42
|
}
|
36
43
|
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { Context } from './types';
|
2
|
+
/**
|
3
|
+
* U extends Context & ContextGuard<TContext>
|
4
|
+
*
|
5
|
+
* Purpose:
|
6
|
+
* - Ensures that any extension `U` of `Context` must conform to the current `TContext`.
|
7
|
+
* - This is useful when redefining `TContext` to maintain type compatibility with the existing context.
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
export type ContextGuard<T extends Context> = Partial<T> | undefined;
|
11
|
+
//# sourceMappingURL=context.d.ts.map
|
package/dist/src/error.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { ORPCError } from '@orpc/contract';
|
|
3
3
|
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
|
4
4
|
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
5
5
|
export type ORPCErrorConstructorMapItem<TCode extends string, TDataSchema extends Schema> = (...rest: ORPCErrorConstructorMapItemRest<SchemaInput<TDataSchema>>) => ORPCError<TCode, SchemaOutput<TDataSchema>>;
|
6
|
-
export type ORPCErrorConstructorMap<T extends ErrorMap> =
|
6
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
7
7
|
[K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
|
8
8
|
};
|
9
9
|
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
package/dist/src/hidden.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
-
export declare function setRouterContract<T extends object>(obj: T, contract: ContractRouter): T;
|
3
|
-
export declare function getRouterContract(obj: object): ContractRouter | undefined;
|
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
4
|
export declare function deepSetLazyRouterPrefix<T extends object>(router: T, prefix: HTTPPath): T;
|
5
5
|
export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
|
6
6
|
//# sourceMappingURL=hidden.d.ts.map
|
@@ -3,8 +3,12 @@ import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
|
3
3
|
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
4
|
import { ProcedureImplementer } from './procedure-implementer';
|
5
5
|
import { RouterImplementer } from './router-implementer';
|
6
|
-
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter
|
7
|
-
[K in keyof TContract]: TContract[K] extends ContractRouter ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
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
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>(contract: TContract,
|
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>;
|
10
14
|
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -20,6 +20,6 @@ export * from './router-client';
|
|
20
20
|
export * from './router-implementer';
|
21
21
|
export * from './types';
|
22
22
|
export * from './utils';
|
23
|
-
export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from '@orpc/contract';
|
24
|
-
export declare const os: Builder<WELL_CONTEXT
|
23
|
+
export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe, type } from '@orpc/contract';
|
24
|
+
export declare const os: Builder<WELL_CONTEXT>;
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,8 +1,9 @@
|
|
1
|
+
import type { ContextGuard } from './context';
|
1
2
|
import type { ORPCErrorConstructorMap } from './error';
|
2
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
4
|
import type { Context, MergeContext } from './types';
|
4
5
|
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap> {
|
5
|
-
concat: (<UExtraContext extends Context &
|
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>);
|
6
7
|
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput, TErrorConstructorMap>;
|
7
8
|
}
|
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>;
|
package/dist/src/middleware.d.ts
CHANGED
@@ -32,4 +32,5 @@ export interface MapInputMiddleware<TInput, TMappedInput> {
|
|
32
32
|
(input: TInput): TMappedInput;
|
33
33
|
}
|
34
34
|
export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
|
35
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
35
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,24 +1,27 @@
|
|
1
|
-
import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
2
3
|
import type { ORPCErrorConstructorMap } from './error';
|
3
|
-
import type {
|
4
|
+
import type { Middleware } from './middleware';
|
4
5
|
import type { ProcedureHandler } from './procedure';
|
5
6
|
import type { Context, MergeContext } from './types';
|
7
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
8
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
6
9
|
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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;
|
11
15
|
}
|
12
|
-
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context,
|
16
|
+
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
13
17
|
'~type': "ProcedureBuilder";
|
14
|
-
'~orpc': ProcedureBuilderDef<TContext, TExtraContext,
|
15
|
-
constructor(def: ProcedureBuilderDef<TContext, TExtraContext,
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
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>;
|
23
26
|
}
|
24
27
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import type { ClientRest, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ClientRest, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
2
3
|
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
5
|
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
@@ -8,19 +9,18 @@ export declare class DecoratedProcedure<TContext extends Context, TExtraContext
|
|
8
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>;
|
9
10
|
prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
10
11
|
route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
11
|
-
|
12
|
-
use<
|
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>;
|
13
15
|
unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
|
-
unshiftMiddleware<
|
16
|
+
unshiftMiddleware(...middlewares: Middleware<TContext, Context & Partial<MergeContext<TContext, TExtraContext>> | undefined, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
17
|
/**
|
16
18
|
* Make this procedure callable (works like a function while still being a procedure).
|
17
|
-
* **Note**: this only takes effect when this method is called at the end of the chain.
|
18
19
|
*/
|
19
|
-
callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>):
|
20
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
21
|
/**
|
21
22
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
22
|
-
* **Note**: this only takes effect when this method is called at the end of the chain.
|
23
23
|
*/
|
24
|
-
actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>):
|
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
25
|
}
|
26
26
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
2
3
|
import type { ORPCErrorConstructorMap } from './error';
|
3
4
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
5
|
import type { ProcedureHandler } from './procedure';
|
@@ -6,14 +7,16 @@ import type { Context, MergeContext } from './types';
|
|
6
7
|
import { DecoratedProcedure } from './procedure-decorated';
|
7
8
|
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
9
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
-
middlewares
|
10
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, any>[];
|
11
|
+
inputValidationIndex: number;
|
12
|
+
outputValidationIndex: number;
|
10
13
|
};
|
11
14
|
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
12
15
|
'~type': "ProcedureImplementer";
|
13
16
|
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
14
17
|
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
15
|
-
use<U extends Context &
|
16
|
-
use<UExtra extends Context &
|
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>;
|
17
20
|
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
18
21
|
}
|
19
22
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -16,7 +16,7 @@ export interface ProcedureHandler<TContext extends Context, TExtraContext extend
|
|
16
16
|
(opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
17
17
|
}
|
18
18
|
/**
|
19
|
-
* Why is `ErrorConstructorMap` passed to `
|
19
|
+
* Why is `ErrorConstructorMap` passed to `middlewares` as `any`?
|
20
20
|
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
21
|
*
|
22
22
|
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
@@ -27,7 +27,9 @@ export interface ProcedureHandler<TContext extends Context, TExtraContext extend
|
|
27
27
|
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
28
|
*/
|
29
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
|
30
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, any>[];
|
31
|
+
inputValidationIndex: number;
|
32
|
+
outputValidationIndex: number;
|
31
33
|
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
32
34
|
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
33
35
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
1
|
+
import type { ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ContextGuard } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
4
|
import type { FlattenLazy, Lazy } from './lazy';
|
3
5
|
import type { Middleware } from './middleware';
|
4
6
|
import type { Procedure } from './procedure';
|
@@ -6,24 +8,26 @@ import type { ANY_ROUTER, Router } from './router';
|
|
6
8
|
import type { Context, MergeContext } from './types';
|
7
9
|
import { type DecoratedLazy } from './lazy-decorated';
|
8
10
|
import { DecoratedProcedure } from './procedure-decorated';
|
9
|
-
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
10
|
-
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K]> : never;
|
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;
|
11
13
|
};
|
12
|
-
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context> = {
|
14
|
+
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> = {
|
13
15
|
prefix?: HTTPPath;
|
14
16
|
tags?: readonly string[];
|
15
|
-
middlewares
|
17
|
+
middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
|
18
|
+
errorMap: TErrorMap;
|
16
19
|
};
|
17
|
-
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
20
|
+
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
|
18
21
|
'~type': "RouterBuilder";
|
19
|
-
'~orpc': RouterBuilderDef<TContext, TExtraContext>;
|
20
|
-
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
21
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
22
|
-
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
23
|
-
|
24
|
-
|
25
|
-
|
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<{
|
26
30
|
default: U;
|
27
|
-
}>): AdaptedRouter<TContext, FlattenLazy<U
|
31
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
|
28
32
|
}
|
29
33
|
//# sourceMappingURL=router-builder.d.ts.map
|