@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.ca29a36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -0
- package/dist/chunk-MBMXGUNI.js +32 -0
- package/dist/chunk-MHVECKBC.js +421 -0
- package/dist/chunk-NTHCS5CK.js +182 -0
- package/dist/chunk-TXHKQO7N.js +120 -0
- package/dist/fetch.js +6 -102
- package/dist/hono.js +34 -0
- package/dist/index.js +341 -322
- package/dist/next.js +31 -0
- package/dist/node.js +31 -0
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +3 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
- package/dist/src/adapters/fetch/types.d.ts +14 -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 +3 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/adapters/standard/handler.d.ts +53 -0
- package/dist/src/adapters/standard/index.d.ts +6 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/types.d.ts +21 -0
- package/dist/src/builder-variants.d.ts +75 -0
- package/dist/src/builder.d.ts +48 -39
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +8 -0
- package/dist/src/error.d.ts +12 -0
- package/dist/src/hidden.d.ts +8 -0
- package/dist/src/implementer-procedure.d.ts +33 -0
- package/dist/src/implementer-variants.d.ts +18 -0
- package/dist/src/implementer.d.ts +29 -0
- package/dist/src/index.d.ts +19 -9
- package/dist/src/lazy-utils.d.ts +6 -0
- package/dist/src/lazy.d.ts +22 -0
- package/dist/src/middleware-decorated.d.ts +11 -0
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +30 -18
- package/dist/src/plugins/base.d.ts +11 -0
- package/dist/src/plugins/cors.d.ts +19 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +33 -0
- package/dist/src/procedure-decorated.d.ts +24 -0
- package/dist/src/procedure-utils.d.ts +19 -0
- package/dist/src/procedure.d.ts +27 -25
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +12 -0
- package/dist/src/router.d.ts +26 -16
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +13 -0
- package/package.json +37 -9
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -19
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/router-builder.d.ts +0 -22
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-implementer.d.ts +0 -20
- package/dist/src/types.d.ts +0 -8
package/dist/next.js
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import {
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-MBMXGUNI.js";
|
4
|
+
import "./chunk-NTHCS5CK.js";
|
5
|
+
import "./chunk-MHVECKBC.js";
|
6
|
+
import "./chunk-TXHKQO7N.js";
|
7
|
+
|
8
|
+
// src/adapters/next/serve.ts
|
9
|
+
import { value } from "@orpc/shared";
|
10
|
+
function serve(handler, ...[options]) {
|
11
|
+
const main = async (req) => {
|
12
|
+
const context = await value(options?.context ?? {}, req);
|
13
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
14
|
+
if (matched) {
|
15
|
+
return response;
|
16
|
+
}
|
17
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
18
|
+
};
|
19
|
+
return {
|
20
|
+
GET: main,
|
21
|
+
POST: main,
|
22
|
+
PUT: main,
|
23
|
+
PATCH: main,
|
24
|
+
DELETE: main
|
25
|
+
};
|
26
|
+
}
|
27
|
+
export {
|
28
|
+
RPCHandler,
|
29
|
+
serve
|
30
|
+
};
|
31
|
+
//# sourceMappingURL=next.js.map
|
package/dist/node.js
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import {
|
2
|
+
RPCCodec,
|
3
|
+
RPCMatcher,
|
4
|
+
StandardHandler
|
5
|
+
} from "./chunk-NTHCS5CK.js";
|
6
|
+
import "./chunk-MHVECKBC.js";
|
7
|
+
import "./chunk-TXHKQO7N.js";
|
8
|
+
|
9
|
+
// src/adapters/node/rpc-handler.ts
|
10
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/standard-server-node";
|
11
|
+
var RPCHandler = class {
|
12
|
+
standardHandler;
|
13
|
+
constructor(router, options) {
|
14
|
+
const codec = options?.codec ?? new RPCCodec();
|
15
|
+
const matcher = options?.matcher ?? new RPCMatcher();
|
16
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
17
|
+
}
|
18
|
+
async handle(req, res, ...rest) {
|
19
|
+
const standardRequest = toStandardRequest(req, res);
|
20
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
21
|
+
if (!result.matched) {
|
22
|
+
return { matched: false };
|
23
|
+
}
|
24
|
+
await sendStandardResponse(res, result.response);
|
25
|
+
return { matched: true };
|
26
|
+
}
|
27
|
+
};
|
28
|
+
export {
|
29
|
+
RPCHandler
|
30
|
+
};
|
31
|
+
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { Router } from '../../router';
|
4
|
+
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
5
|
+
import type { FetchHandler, FetchHandleResult } from './types';
|
6
|
+
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
7
|
+
private readonly standardHandler;
|
8
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
9
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { StandardHandleOptions } from '../standard';
|
4
|
+
export type FetchHandleResult = {
|
5
|
+
matched: true;
|
6
|
+
response: Response;
|
7
|
+
} | {
|
8
|
+
matched: false;
|
9
|
+
response: undefined;
|
10
|
+
};
|
11
|
+
export interface FetchHandler<T extends Context> {
|
12
|
+
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
13
|
+
}
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
2
|
+
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
3
|
+
import type { Context } from '../../context';
|
4
|
+
import type { FetchHandler } from '../fetch';
|
5
|
+
import type { StandardHandleOptions } from '../standard';
|
6
|
+
export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
+
context?: Value<T, [HonoContext]>;
|
8
|
+
} : {
|
9
|
+
context: Value<T, [HonoContext]>;
|
10
|
+
});
|
11
|
+
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
|
12
|
+
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { MaybeOptionalOptions, Value } from '@orpc/shared';
|
2
|
+
import type { NextRequest } from 'next/server';
|
3
|
+
import type { Context } from '../../context';
|
4
|
+
import type { FetchHandler } from '../fetch';
|
5
|
+
import type { StandardHandleOptions } from '../standard';
|
6
|
+
export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
+
context?: Value<T, [NextRequest]>;
|
8
|
+
} : {
|
9
|
+
context: Value<T, [NextRequest]>;
|
10
|
+
});
|
11
|
+
export interface ServeResult {
|
12
|
+
GET(req: NextRequest): Promise<Response>;
|
13
|
+
POST(req: NextRequest): Promise<Response>;
|
14
|
+
PUT(req: NextRequest): Promise<Response>;
|
15
|
+
PATCH(req: NextRequest): Promise<Response>;
|
16
|
+
DELETE(req: NextRequest): Promise<Response>;
|
17
|
+
}
|
18
|
+
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
|
19
|
+
//# sourceMappingURL=serve.d.ts.map
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { Router } from '../../router';
|
4
|
+
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
5
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
|
6
|
+
export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
7
|
+
private readonly standardHandler;
|
8
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
9
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
3
|
+
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
4
|
+
import type { Context } from '../../context';
|
5
|
+
import type { StandardHandleOptions } from '../standard';
|
6
|
+
export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
7
|
+
/**
|
8
|
+
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
9
|
+
* This is useful for `express.js` middleware.
|
10
|
+
*/
|
11
|
+
originalUrl?: string;
|
12
|
+
};
|
13
|
+
export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
14
|
+
export type NodeHttpHandleResult = {
|
15
|
+
matched: true;
|
16
|
+
} | {
|
17
|
+
matched: false;
|
18
|
+
};
|
19
|
+
export interface NodeHttpHandler<T extends Context> {
|
20
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
|
21
|
+
}
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import type { ErrorFromErrorMap, HTTPPath, Meta, Schema, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
4
|
+
import type { Context } from '../../context';
|
5
|
+
import type { Plugin } from '../../plugins';
|
6
|
+
import type { ProcedureClientInterceptorOptions } from '../../procedure-client';
|
7
|
+
import type { Router } from '../../router';
|
8
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
9
|
+
export type StandardHandleOptions<T extends Context> = {
|
10
|
+
prefix?: HTTPPath;
|
11
|
+
} & (Record<never, never> extends T ? {
|
12
|
+
context?: T;
|
13
|
+
} : {
|
14
|
+
context: T;
|
15
|
+
});
|
16
|
+
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
17
|
+
context: T;
|
18
|
+
};
|
19
|
+
export type StandardHandleResult = {
|
20
|
+
matched: true;
|
21
|
+
response: StandardResponse;
|
22
|
+
} | {
|
23
|
+
matched: false;
|
24
|
+
response: undefined;
|
25
|
+
};
|
26
|
+
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
27
|
+
request: StandardRequest;
|
28
|
+
};
|
29
|
+
export interface StandardHandlerOptions<TContext extends Context> {
|
30
|
+
plugins?: Plugin<TContext>[];
|
31
|
+
/**
|
32
|
+
* Interceptors at the request level, helpful when you want catch errors
|
33
|
+
*/
|
34
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
35
|
+
/**
|
36
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
37
|
+
*/
|
38
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
39
|
+
/**
|
40
|
+
*
|
41
|
+
* Interceptors for procedure client.
|
42
|
+
*/
|
43
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Schema, Record<never, never>, Meta>, SchemaOutput<Schema, unknown>, ErrorFromErrorMap<Record<never, never>>>[];
|
44
|
+
}
|
45
|
+
export declare class StandardHandler<T extends Context> {
|
46
|
+
private readonly matcher;
|
47
|
+
private readonly codec;
|
48
|
+
private readonly options;
|
49
|
+
private readonly plugin;
|
50
|
+
constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
|
51
|
+
handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
52
|
+
}
|
53
|
+
//# sourceMappingURL=handler.d.ts.map
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
2
|
+
import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
3
|
+
import type { AnyProcedure } from '../../procedure';
|
4
|
+
import type { StandardCodec, StandardParams } from './types';
|
5
|
+
import { RPCSerializer } from '@orpc/client/rpc';
|
6
|
+
export interface StandardCodecOptions {
|
7
|
+
serializer?: RPCSerializer;
|
8
|
+
}
|
9
|
+
export declare class RPCCodec implements StandardCodec {
|
10
|
+
private readonly serializer;
|
11
|
+
constructor(options?: StandardCodecOptions);
|
12
|
+
decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
13
|
+
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
14
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
15
|
+
}
|
16
|
+
//# sourceMappingURL=rpc-codec.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Context } from '../../context';
|
2
|
+
import type { StandardHandlerOptions } from './handler';
|
3
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
4
|
+
export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
|
5
|
+
matcher?: StandardMatcher;
|
6
|
+
codec?: StandardCodec;
|
7
|
+
}
|
8
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { StandardMatcher, StandardMatchResult } from './types';
|
3
|
+
import { type AnyRouter } from '../../router';
|
4
|
+
export declare class RPCMatcher implements StandardMatcher {
|
5
|
+
private readonly tree;
|
6
|
+
private pendingRouters;
|
7
|
+
init(router: AnyRouter, path?: string[]): void;
|
8
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=rpc-matcher.d.ts.map
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { ORPCError } from '@orpc/client';
|
2
|
+
import type { HTTPPath } from '@orpc/contract';
|
3
|
+
import type { StandardRequest, StandardResponse } from '@orpc/standard-server';
|
4
|
+
import type { AnyProcedure } from '../../procedure';
|
5
|
+
import type { AnyRouter } from '../../router';
|
6
|
+
export type StandardParams = Record<string, string>;
|
7
|
+
export type StandardMatchResult = {
|
8
|
+
path: string[];
|
9
|
+
procedure: AnyProcedure;
|
10
|
+
params?: StandardParams;
|
11
|
+
} | undefined;
|
12
|
+
export interface StandardMatcher {
|
13
|
+
init(router: AnyRouter): void;
|
14
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
15
|
+
}
|
16
|
+
export interface StandardCodec {
|
17
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
18
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
19
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { BuilderDef } from './builder';
|
3
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
5
|
+
import type { FlattenLazy } from './lazy-utils';
|
6
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
7
|
+
import type { ProcedureHandler } from './procedure';
|
8
|
+
import type { DecoratedProcedure } from './procedure-decorated';
|
9
|
+
import type { AdaptedRouter, AdaptRouterOptions, Router } from './router';
|
10
|
+
export interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
11
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
12
|
+
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
13
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
14
|
+
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
15
|
+
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
16
|
+
'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
17
|
+
'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
18
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
19
|
+
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
20
|
+
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
21
|
+
'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
|
22
|
+
'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
|
23
|
+
default: U;
|
24
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
|
25
|
+
}
|
26
|
+
export interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
27
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
28
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
29
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
30
|
+
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
31
|
+
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
32
|
+
'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
33
|
+
'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
34
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
35
|
+
}
|
36
|
+
export interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
37
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
38
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
39
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
40
|
+
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
41
|
+
'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
42
|
+
'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
43
|
+
'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
44
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
45
|
+
}
|
46
|
+
export interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
47
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
48
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
49
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
50
|
+
'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
51
|
+
'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
52
|
+
'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
53
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
54
|
+
}
|
55
|
+
export interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
56
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
57
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
58
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
59
|
+
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
60
|
+
'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
61
|
+
'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
62
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
63
|
+
}
|
64
|
+
export interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
65
|
+
'~orpc': AdaptRouterOptions<TErrorMap>;
|
66
|
+
'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
|
67
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & RouterBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
|
68
|
+
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
69
|
+
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
70
|
+
'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
|
71
|
+
'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
|
72
|
+
default: U;
|
73
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
|
74
|
+
}
|
75
|
+
//# sourceMappingURL=builder-variants.d.ts.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,49 +1,58 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import type { Context,
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
export
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Convert to ContractProcedureBuilder
|
26
|
-
*/
|
27
|
-
route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
28
|
-
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
29
|
-
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
1
|
+
import type { ContractProcedureDef, ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { BuilderWithMiddlewares, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithOutput, RouterBuilder } from './builder-variants';
|
3
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
5
|
+
import type { FlattenLazy } from './lazy-utils';
|
6
|
+
import type { AnyMiddleware, MapInputMiddleware, Middleware } from './middleware';
|
7
|
+
import type { DecoratedMiddleware } from './middleware-decorated';
|
8
|
+
import type { ProcedureHandler } from './procedure';
|
9
|
+
import type { AdaptedRouter, AdaptRouterOptions, Router } from './router';
|
10
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
11
|
+
export interface BuilderConfig {
|
12
|
+
initialInputValidationIndex?: number;
|
13
|
+
initialOutputValidationIndex?: number;
|
14
|
+
}
|
15
|
+
export interface BuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptRouterOptions<TErrorMap> {
|
16
|
+
middlewares: AnyMiddleware[];
|
17
|
+
inputValidationIndex: number;
|
18
|
+
outputValidationIndex: number;
|
19
|
+
config: BuilderConfig;
|
20
|
+
}
|
21
|
+
export declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
22
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
23
|
+
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
30
24
|
/**
|
31
|
-
*
|
25
|
+
* Reset config
|
32
26
|
*/
|
33
|
-
|
27
|
+
$config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
34
28
|
/**
|
35
|
-
*
|
29
|
+
* Reset initial context
|
36
30
|
*/
|
37
|
-
|
31
|
+
$context<U extends Context>(): Builder<U, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
38
32
|
/**
|
39
|
-
*
|
33
|
+
* Reset initial meta
|
40
34
|
*/
|
41
|
-
|
42
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
43
|
-
tags(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
35
|
+
$meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U>;
|
44
36
|
/**
|
45
|
-
*
|
37
|
+
* Reset initial route
|
46
38
|
*/
|
47
|
-
|
39
|
+
$route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
40
|
+
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
41
|
+
middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, TMeta>;
|
42
|
+
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
43
|
+
use<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
44
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
45
|
+
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
46
|
+
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
47
|
+
input<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
48
|
+
output<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
49
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
50
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
51
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
52
|
+
router<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
|
53
|
+
lazy<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
|
54
|
+
default: U;
|
55
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
|
48
56
|
}
|
57
|
+
export declare const os: Builder<Context, Context, undefined, undefined, {}, {}>;
|
49
58
|
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { IsNever } from '@orpc/shared';
|
2
|
+
export type Context = Record<string, any>;
|
3
|
+
export type MergedContext<T extends Context, U extends Context> = T & U;
|
4
|
+
export declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
5
|
+
export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
6
|
+
[K in keyof T]: IsNever<T[K]>;
|
7
|
+
}[keyof T] ? never : unknown;
|
8
|
+
//# sourceMappingURL=context.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ORPCErrorCode, ORPCErrorOptions } from '@orpc/client';
|
2
|
+
import type { ErrorMap, ErrorMapItem, SchemaInput } from '@orpc/contract';
|
3
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import { ORPCError } from '@orpc/client';
|
5
|
+
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
6
|
+
export type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
|
7
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
8
|
+
[K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, SchemaInput<UInputSchema>> : never : never;
|
9
|
+
};
|
10
|
+
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
11
|
+
export declare function validateORPCError(map: ErrorMap, error: ORPCError<any, any>): Promise<ORPCError<string, unknown>>;
|
12
|
+
//# sourceMappingURL=error.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { AnyContractRouter, ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { AnyRouter } from './router';
|
4
|
+
export declare function setRouterContract<T extends AnyRouter>(obj: T, contract: AnyContractRouter): T;
|
5
|
+
export declare function getRouterContract(obj: object): ContractRouter<any> | undefined;
|
6
|
+
export declare function deepSetLazyRouterPrefix<T extends Lazy<any>>(router: T, prefix: HTTPPath): T;
|
7
|
+
export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
|
8
|
+
//# sourceMappingURL=hidden.d.ts.map
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { ClientContext, ClientRest } from '@orpc/client';
|
2
|
+
import type { ErrorMap, Meta, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
3
|
+
import type { MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
import type { BuilderDef } from './builder';
|
5
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
6
|
+
import type { ORPCErrorConstructorMap } from './error';
|
7
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
8
|
+
import type { Procedure, ProcedureHandler } from './procedure';
|
9
|
+
import type { CreateProcedureClientOptions, ProcedureClient } from './procedure-client';
|
10
|
+
import type { DecoratedProcedure } from './procedure-decorated';
|
11
|
+
/**
|
12
|
+
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
13
|
+
*/
|
14
|
+
export interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
|
15
|
+
use: (<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>) => ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>) & (<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>) => ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
16
|
+
/**
|
17
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
18
|
+
*/
|
19
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
|
+
/**
|
21
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
22
|
+
*/
|
23
|
+
actionable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta, TClientContext>>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
27
|
+
*/
|
28
|
+
export interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
29
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
30
|
+
'use': (<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>) => ConflictContextGuard<MergedContext<TCurrentContext, U>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, TErrorMap, TMeta>) & (<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>) => ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
31
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
32
|
+
}
|
33
|
+
//# sourceMappingURL=implementer-procedure.d.ts.map
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { ProcedureImplementer } from './implementer-procedure';
|
5
|
+
import type { FlattenLazy } from './lazy-utils';
|
6
|
+
import type { Middleware } from './middleware';
|
7
|
+
import type { AdaptedRouter, Router } from './router';
|
8
|
+
export interface RouterImplementerWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
9
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
|
10
|
+
router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
|
11
|
+
lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
|
12
|
+
default: U;
|
13
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
|
14
|
+
}
|
15
|
+
export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
16
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
17
|
+
});
|
18
|
+
//# sourceMappingURL=implementer-variants.d.ts.map
|