@orpc/server 0.0.0-next.d7b5662 → 0.0.0-next.da84cda
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-VY6NXNQT.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/{chunk-YAVPFNPF.js → chunk-XDC42C3C.js} +78 -33
- package/dist/fetch.js +10 -281
- package/dist/hono.js +30 -0
- package/dist/index.js +143 -111
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/{fetch → adapters/fetch}/index.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +2 -2
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder.d.ts +11 -10
- package/dist/src/error.d.ts +10 -0
- package/dist/src/implementer-chainable.d.ts +2 -2
- package/dist/src/index.d.ts +3 -1
- package/dist/src/lazy-decorated.d.ts +3 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +20 -8
- package/dist/src/procedure-builder.d.ts +17 -15
- package/dist/src/procedure-client.d.ts +9 -21
- package/dist/src/procedure-decorated.d.ts +22 -10
- package/dist/src/procedure-implementer.d.ts +13 -12
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +33 -13
- package/dist/src/router-builder.d.ts +4 -4
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +2 -2
- package/dist/src/router.d.ts +4 -4
- package/dist/src/types.d.ts +2 -0
- package/package.json +24 -8
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/orpc-payload-codec.d.ts +0 -9
- package/dist/src/fetch/types.d.ts +0 -16
- /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
2
|
+
import type { Router } from '../../router';
|
3
|
+
import type { Context } from '../../types';
|
4
|
+
import type { RPCHandlerOptions } from '../fetch/orpc-handler';
|
5
|
+
import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
|
6
|
+
import { type ExpressableIncomingMessage } from './request-listener';
|
7
|
+
export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
|
8
|
+
private readonly orpcFetchHandler;
|
9
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
10
|
+
handle(req: ExpressableIncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
11
|
+
}
|
12
|
+
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
|
+
export interface ExpressableIncomingMessage extends IncomingMessage {
|
3
|
+
originalUrl?: string;
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
* Creates a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object from a Node.js
|
7
|
+
* [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) and
|
8
|
+
* [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) pair.
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
export declare function createRequest(req: ExpressableIncomingMessage, res: ServerResponse): Request;
|
12
|
+
/**
|
13
|
+
* Creates a [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object from the headers
|
14
|
+
* in a Node.js [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
|
15
|
+
*
|
16
|
+
* @param req The incoming request object.
|
17
|
+
* @returns A headers object.
|
18
|
+
*/
|
19
|
+
export declare function createHeaders(req: IncomingMessage): Headers;
|
20
|
+
/**
|
21
|
+
* Sends a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) to the client using the
|
22
|
+
* Node.js [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) object.
|
23
|
+
*
|
24
|
+
* @param res The server response object.
|
25
|
+
* @param response The response to send.
|
26
|
+
*/
|
27
|
+
export declare function sendResponse(res: ServerResponse, response: Response): Promise<void>;
|
28
|
+
//# sourceMappingURL=request-listener.d.ts.map
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Promisable } from '@orpc/shared';
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
4
|
+
import type { Context } from '../../types';
|
5
|
+
export type RequestHandleOptions<T extends Context> = {
|
6
|
+
prefix?: HTTPPath;
|
7
|
+
beforeSend?: (response: Response, context: T) => Promisable<void>;
|
8
|
+
} & (undefined extends T ? {
|
9
|
+
context?: T;
|
10
|
+
} : {
|
11
|
+
context: T;
|
12
|
+
});
|
13
|
+
export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (undefined extends T ? [] : never);
|
14
|
+
export type RequestHandleResult = {
|
15
|
+
matched: true;
|
16
|
+
} | {
|
17
|
+
matched: false;
|
18
|
+
};
|
19
|
+
export interface RequestHandler<T extends Context> {
|
20
|
+
handle: (req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>) => Promise<RequestHandleResult>;
|
21
|
+
}
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { FlattenLazy } from './lazy';
|
3
3
|
import type { Middleware } from './middleware';
|
4
4
|
import type { DecoratedMiddleware } from './middleware-decorated';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
5
6
|
import type { Router } from './router';
|
6
7
|
import type { AdaptedRouter } from './router-builder';
|
7
8
|
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
8
9
|
import { type ChainableImplementer } from './implementer-chainable';
|
9
|
-
import { type ProcedureFunc } from './procedure';
|
10
10
|
import { ProcedureBuilder } from './procedure-builder';
|
11
|
-
import {
|
11
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
12
12
|
import { RouterBuilder } from './router-builder';
|
13
13
|
export interface BuilderDef<TContext extends Context, TExtraContext extends Context> {
|
14
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
14
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
15
15
|
}
|
16
16
|
export declare class Builder<TContext extends Context, TExtraContext extends Context> {
|
17
17
|
'~type': "Builder";
|
18
18
|
'~orpc': BuilderDef<TContext, TExtraContext>;
|
19
19
|
constructor(def: BuilderDef<TContext, TExtraContext>);
|
20
20
|
context<UContext extends Context = WELL_CONTEXT>(): Builder<UContext, undefined>;
|
21
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown
|
22
|
-
middleware<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput
|
23
|
-
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
24
|
-
input<USchema extends Schema
|
25
|
-
output<USchema extends Schema
|
26
|
-
|
21
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): Builder<TContext, MergeContext<TExtraContext, U>>;
|
22
|
+
middleware<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput, Record<string, unknown>>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput, Record<string, unknown>>;
|
23
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined, undefined>;
|
24
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined, undefined>;
|
25
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema, undefined>;
|
26
|
+
errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, undefined, undefined, UErrorMap>;
|
27
|
+
handler<UFuncOutput = undefined>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, undefined>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, undefined>;
|
27
28
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
28
29
|
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
29
30
|
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { ErrorMap, ErrorMapItem, ORPCErrorOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import { ORPCError } from '@orpc/contract';
|
3
|
+
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
|
4
|
+
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
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> = T extends undefined ? Record<string, unknown> : {
|
7
|
+
[K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
|
8
|
+
};
|
9
|
+
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
10
|
+
//# sourceMappingURL=error.d.ts.map
|
@@ -3,8 +3,8 @@ 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> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : {
|
6
|
+
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
7
7
|
[K in keyof TContract]: TContract[K] extends ContractRouter ? 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, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
9
|
+
export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter = any>(contract: TContract, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[]): ChainableImplementer<TContext, TExtraContext, TContract>;
|
10
10
|
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { WELL_CONTEXT } from './types';
|
2
2
|
import { Builder } from './builder';
|
3
3
|
export * from './builder';
|
4
|
+
export * from './error';
|
4
5
|
export * from './hidden';
|
5
6
|
export * from './implementer-chainable';
|
6
7
|
export * from './lazy';
|
@@ -12,12 +13,13 @@ export * from './procedure-builder';
|
|
12
13
|
export * from './procedure-client';
|
13
14
|
export * from './procedure-decorated';
|
14
15
|
export * from './procedure-implementer';
|
16
|
+
export * from './procedure-utils';
|
15
17
|
export * from './router';
|
16
18
|
export * from './router-builder';
|
17
19
|
export * from './router-client';
|
18
20
|
export * from './router-implementer';
|
19
21
|
export * from './types';
|
20
22
|
export * from './utils';
|
21
|
-
export
|
23
|
+
export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from '@orpc/contract';
|
22
24
|
export declare const os: Builder<WELL_CONTEXT, undefined>;
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,10 +1,7 @@
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Lazy } from './lazy';
|
3
|
-
import type { Procedure } from './procedure';
|
4
|
-
import type { ProcedureClient } from './procedure-client';
|
5
2
|
import { type ANY_ROUTER } from './router';
|
6
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends
|
7
|
-
[K in keyof T]:
|
8
|
-
});
|
3
|
+
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
|
4
|
+
[K in keyof T]: DecoratedLazy<T[K]>;
|
5
|
+
} : unknown);
|
9
6
|
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
10
7
|
//# sourceMappingURL=lazy-decorated.d.ts.map
|
@@ -1,8 +1,9 @@
|
|
1
|
+
import type { ORPCErrorConstructorMap } from './error';
|
1
2
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
-
import type { Context, MergeContext
|
3
|
-
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput
|
4
|
-
concat: (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput>) & (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput>);
|
5
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
3
|
+
import type { Context, MergeContext } from './types';
|
4
|
+
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 & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput, TErrorConstructorMap>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>) & (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, 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
|
+
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput, TErrorConstructorMap>;
|
6
7
|
}
|
7
|
-
export declare function decorateMiddleware<TContext extends Context
|
8
|
+
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>;
|
8
9
|
//# sourceMappingURL=middleware-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
3
|
+
import type { ANY_PROCEDURE } from './procedure';
|
4
|
+
import type { AbortSignal, Context } from './types';
|
3
5
|
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
4
6
|
output: TOutput;
|
5
7
|
context: TExtraContext;
|
6
8
|
}>;
|
7
|
-
export interface
|
8
|
-
|
9
|
+
export interface MiddlewareNextFn<TOutput> {
|
10
|
+
<UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
|
9
11
|
context?: UExtraContext;
|
10
12
|
} : {
|
11
13
|
context: UExtraContext;
|
12
|
-
})
|
13
|
-
output: <UOutput>(output: UOutput) => MiddlewareResult<undefined, UOutput>;
|
14
|
+
}): MiddlewareResult<UExtraContext, TOutput>;
|
14
15
|
}
|
15
|
-
export interface
|
16
|
-
(
|
16
|
+
export interface MiddlewareOutputFn<TOutput> {
|
17
|
+
(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
17
18
|
}
|
18
|
-
export
|
19
|
+
export interface MiddlewareOptions<TContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
20
|
+
context: TContext;
|
21
|
+
path: string[];
|
22
|
+
procedure: ANY_PROCEDURE;
|
23
|
+
signal?: AbortSignal;
|
24
|
+
next: MiddlewareNextFn<TOutput>;
|
25
|
+
errors: TErrorConstructorMap;
|
26
|
+
}
|
27
|
+
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
28
|
+
(options: MiddlewareOptions<TContext, TOutput, TErrorConstructorMap>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
29
|
+
}
|
30
|
+
export type ANY_MIDDLEWARE = Middleware<any, any, any, any, any>;
|
19
31
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
20
32
|
(input: TInput): TMappedInput;
|
21
33
|
}
|
@@ -1,22 +1,24 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
1
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
-
import type {
|
4
|
+
import type { ProcedureHandler } from './procedure';
|
3
5
|
import type { Context, MergeContext } from './types';
|
4
|
-
import {
|
5
|
-
import { type ProcedureFunc } from './procedure';
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
6
7
|
import { ProcedureImplementer } from './procedure-implementer';
|
7
|
-
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
8
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
9
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
8
|
+
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
10
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
10
11
|
}
|
11
|
-
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
12
|
+
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
12
13
|
'~type': "ProcedureBuilder";
|
13
|
-
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
14
|
-
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
15
|
-
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
16
|
-
input<U extends Schema
|
17
|
-
output<U extends Schema
|
18
|
-
|
19
|
-
use<
|
20
|
-
|
14
|
+
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
15
|
+
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
16
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
|
18
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
|
19
|
+
errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, UErrorMap>;
|
20
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
21
|
+
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
22
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
21
23
|
}
|
22
24
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,34 +1,22 @@
|
|
1
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Hooks, Value } from '@orpc/shared';
|
3
3
|
import type { Lazyable } from './lazy';
|
4
4
|
import type { Procedure } from './procedure';
|
5
|
-
import type { Context, Meta
|
6
|
-
export type
|
7
|
-
context?: TClientContext;
|
8
|
-
} : {
|
9
|
-
context: TClientContext;
|
10
|
-
});
|
11
|
-
export interface ProcedureClient<TInput, TOutput, TClientContext> {
|
12
|
-
(...opts: [input: TInput, options: ProcedureClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never)): Promise<TOutput>;
|
13
|
-
}
|
5
|
+
import type { Context, Meta } from './types';
|
6
|
+
export type ProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
14
7
|
/**
|
15
8
|
* Options for creating a procedure caller with comprehensive type safety
|
16
9
|
*/
|
17
|
-
export type CreateProcedureClientOptions<TContext extends Context,
|
18
|
-
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, TFuncOutput>>;
|
10
|
+
export type CreateProcedureClientOptions<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = {
|
19
11
|
/**
|
20
12
|
* This is helpful for logging and analytics.
|
21
|
-
*
|
22
|
-
* @internal
|
23
13
|
*/
|
24
14
|
path?: string[];
|
25
15
|
} & ({
|
26
|
-
|
27
|
-
* The context used when calling the procedure.
|
28
|
-
*/
|
29
|
-
context: Value<TContext>;
|
16
|
+
context: Value<TContext, [clientContext: TClientContext]>;
|
30
17
|
} | (undefined extends TContext ? {
|
31
|
-
context?:
|
32
|
-
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema,
|
33
|
-
export
|
18
|
+
context?: Value<TContext, [clientContext: TClientContext]>;
|
19
|
+
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
20
|
+
export type CreateProcedureClientRest<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TContext, TOutputSchema, THandlerOutput, TClientContext>] | (undefined extends TContext ? [] : never);
|
21
|
+
export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, ...[options]: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
34
22
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -1,14 +1,26 @@
|
|
1
|
-
import type { HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ClientRest, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
4
5
|
import type { Context, MergeContext } from './types';
|
5
6
|
import { Procedure } from './procedure';
|
6
|
-
export
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
export declare class DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> {
|
8
|
+
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
|
+
prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
10
|
+
route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
11
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
12
|
+
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
13
|
+
unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
|
+
unshiftMiddleware<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(...middlewares: Middleware<TContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
15
|
+
/**
|
16
|
+
* 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
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & 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
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
23
|
+
*/
|
24
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
25
|
+
}
|
14
26
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,18 +1,19 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
-
import type {
|
4
|
-
import type { DecoratedProcedure } from './procedure-decorated';
|
4
|
+
import type { ProcedureHandler } from './procedure';
|
5
5
|
import type { Context, MergeContext } from './types';
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
7
|
+
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>[];
|
9
10
|
};
|
10
|
-
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
11
|
+
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
11
12
|
'~type': "ProcedureImplementer";
|
12
|
-
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
13
|
-
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
14
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
|
15
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
|
16
|
-
|
13
|
+
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
14
|
+
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
15
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
16
|
+
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(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
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
17
18
|
}
|
18
19
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Lazyable } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { Context } from './types';
|
5
|
+
import { type CreateProcedureClientRest } from './procedure-client';
|
6
|
+
/**
|
7
|
+
* Directly call a procedure without creating a client.
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* const output = await call(getting, 'input')
|
12
|
+
* const output = await call(getting, 'input', { context: { db: 'postgres' } })
|
13
|
+
* ```
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
export declare function call<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,23 +1,43 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
4
|
import type { Lazy } from './lazy';
|
3
5
|
import type { Middleware } from './middleware';
|
4
|
-
import type { Context, MergeContext
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
import type { AbortSignal, Context, MergeContext } from './types';
|
7
|
+
export interface ProcedureHandlerOptions<TContext extends Context, TExtraContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
8
|
+
context: MergeContext<TContext, TExtraContext>;
|
9
|
+
input: TInput;
|
10
|
+
path: string[];
|
11
|
+
procedure: ANY_PROCEDURE;
|
12
|
+
signal?: AbortSignal;
|
13
|
+
errors: TErrorConstructorMap;
|
8
14
|
}
|
9
|
-
export interface
|
10
|
-
|
11
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
12
|
-
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
15
|
+
export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
16
|
+
(opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
13
17
|
}
|
14
|
-
|
18
|
+
/**
|
19
|
+
* Why is `ErrorConstructorMap` passed to `Middleware` as `any`?
|
20
|
+
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
|
+
*
|
22
|
+
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
23
|
+
* causes unexpected errors in the router (the root cause is unclear, but it occurs consistently).
|
24
|
+
* To avoid these issues, `any` is used as a workaround.
|
25
|
+
*
|
26
|
+
* This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
|
27
|
+
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
|
+
*/
|
29
|
+
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
30
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, any, any>[];
|
31
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
32
|
+
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
33
|
+
}
|
34
|
+
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
15
35
|
'~type': "Procedure";
|
16
|
-
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema,
|
17
|
-
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema,
|
36
|
+
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
37
|
+
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
18
38
|
}
|
19
|
-
export type ANY_PROCEDURE = Procedure<any, any, any, any, any>;
|
20
|
-
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>;
|
39
|
+
export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any>;
|
40
|
+
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any>;
|
21
41
|
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
22
42
|
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
23
43
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -5,14 +5,14 @@ import type { Procedure } from './procedure';
|
|
5
5
|
import type { ANY_ROUTER, Router } from './router';
|
6
6
|
import type { Context, MergeContext } from './types';
|
7
7
|
import { type DecoratedLazy } from './lazy-decorated';
|
8
|
-
import {
|
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> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : {
|
8
|
+
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
10
|
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K]> : never;
|
11
11
|
};
|
12
12
|
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context> = {
|
13
13
|
prefix?: HTTPPath;
|
14
14
|
tags?: readonly string[];
|
15
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
15
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
16
16
|
};
|
17
17
|
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
18
18
|
'~type': "RouterBuilder";
|
@@ -20,7 +20,7 @@ export declare class RouterBuilder<TContext extends Context, TExtraContext exten
|
|
20
20
|
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
21
21
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
22
22
|
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
23
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown
|
23
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): RouterBuilder<TContext, MergeContext<TExtraContext, U>>;
|
24
24
|
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
25
25
|
lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
|
26
26
|
default: U;
|
@@ -1,15 +1,16 @@
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
1
|
import type { Hooks, Value } from '@orpc/shared';
|
3
2
|
import type { Lazy } from './lazy';
|
4
3
|
import type { Procedure } from './procedure';
|
5
|
-
import type { ProcedureClient } from './procedure-client';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
6
5
|
import type { Meta } from './types';
|
7
6
|
import { type ANY_ROUTER, type Router } from './router';
|
8
|
-
|
9
|
-
|
7
|
+
/**
|
8
|
+
* FIXME: separate RouterClient and ContractRouterClient, don't mix them
|
9
|
+
*/
|
10
|
+
export type RouterClient<TRouter extends ANY_ROUTER, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
11
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
|
10
12
|
};
|
11
13
|
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
12
|
-
router: TRouter | Lazy<undefined>;
|
13
14
|
/**
|
14
15
|
* This is helpful for logging and analytics.
|
15
16
|
*
|
@@ -21,5 +22,5 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
|
21
22
|
} : {
|
22
23
|
context: Value<UContext>;
|
23
24
|
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
|
24
|
-
export declare function createRouterClient<TRouter extends ANY_ROUTER>(
|
25
|
+
export declare function createRouterClient<TRouter extends ANY_ROUTER, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
25
26
|
//# sourceMappingURL=router-client.d.ts.map
|
@@ -5,14 +5,14 @@ import type { Router } from './router';
|
|
5
5
|
import type { AdaptedRouter } from './router-builder';
|
6
6
|
import type { Context, MergeContext } from './types';
|
7
7
|
export interface RouterImplementerDef<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
8
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
8
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
9
9
|
contract: TContract;
|
10
10
|
}
|
11
11
|
export declare class RouterImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
12
12
|
'~type': "RouterImplementer";
|
13
13
|
'~orpc': RouterImplementerDef<TContext, TExtraContext, TContract>;
|
14
14
|
constructor(def: RouterImplementerDef<TContext, TExtraContext, TContract>);
|
15
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown
|
15
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): RouterImplementer<TContext, MergeContext<TExtraContext, U>, TContract>;
|
16
16
|
router<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(router: U): AdaptedRouter<TContext, U>;
|
17
17
|
lazy<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(loader: () => Promise<{
|
18
18
|
default: U;
|