@orpc/server 0.0.0-next.8b5a6d6 → 0.0.0-next.911bdd9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-3BAPJGK6.js +302 -0
- package/dist/chunk-E7GUWVR4.js +186 -0
- package/dist/fetch.js +10 -108
- package/dist/index.js +371 -317
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/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 +26 -44
- package/dist/src/hidden.d.ts +6 -0
- package/dist/src/implementer-chainable.d.ts +10 -0
- package/dist/src/index.d.ts +10 -3
- package/dist/src/lazy-decorated.d.ts +10 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +6 -11
- package/dist/src/middleware-decorated.d.ts +8 -0
- package/dist/src/middleware.d.ts +18 -11
- package/dist/src/procedure-builder.d.ts +15 -24
- package/dist/src/procedure-client.d.ts +34 -0
- package/dist/src/procedure-decorated.d.ts +14 -0
- package/dist/src/procedure-implementer.d.ts +13 -17
- package/dist/src/procedure.d.ts +23 -25
- package/dist/src/router-builder.d.ts +23 -21
- package/dist/src/router-client.d.ts +25 -0
- package/dist/src/router-implementer.d.ts +18 -21
- package/dist/src/router.d.ts +11 -16
- package/dist/src/types.d.ts +8 -8
- package/package.json +11 -11
- package/dist/chunk-3JMSDC5L.js +0 -274
- 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 -28
- package/dist/src/procedure-caller.d.ts +0 -26
- package/dist/src/router-caller.d.ts +0 -25
package/dist/node.js
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
import {
|
2
|
+
ORPCHandler
|
3
|
+
} from "./chunk-3BAPJGK6.js";
|
4
|
+
import "./chunk-E7GUWVR4.js";
|
5
|
+
|
6
|
+
// src/adapters/node/request-listener.ts
|
7
|
+
function createRequest(req, res) {
|
8
|
+
const controller = new AbortController();
|
9
|
+
res.on("close", () => {
|
10
|
+
controller.abort();
|
11
|
+
});
|
12
|
+
const method = req.method ?? "GET";
|
13
|
+
const headers = createHeaders(req);
|
14
|
+
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
15
|
+
const host = headers.get("Host") ?? "localhost";
|
16
|
+
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
17
|
+
const init = { method, headers, signal: controller.signal };
|
18
|
+
if (method !== "GET" && method !== "HEAD") {
|
19
|
+
init.body = new ReadableStream({
|
20
|
+
start(controller2) {
|
21
|
+
req.on("data", (chunk) => {
|
22
|
+
controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
23
|
+
});
|
24
|
+
req.on("end", () => {
|
25
|
+
controller2.close();
|
26
|
+
});
|
27
|
+
}
|
28
|
+
});
|
29
|
+
init.duplex = "half";
|
30
|
+
}
|
31
|
+
return new Request(url, init);
|
32
|
+
}
|
33
|
+
function createHeaders(req) {
|
34
|
+
const headers = new Headers();
|
35
|
+
const rawHeaders = req.rawHeaders;
|
36
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
37
|
+
headers.append(rawHeaders[i], rawHeaders[i + 1]);
|
38
|
+
}
|
39
|
+
return headers;
|
40
|
+
}
|
41
|
+
async function sendResponse(res, response) {
|
42
|
+
const headers = {};
|
43
|
+
for (const [key, value] of response.headers) {
|
44
|
+
if (key in headers) {
|
45
|
+
if (Array.isArray(headers[key])) {
|
46
|
+
headers[key].push(value);
|
47
|
+
} else {
|
48
|
+
headers[key] = [headers[key], value];
|
49
|
+
}
|
50
|
+
} else {
|
51
|
+
headers[key] = value;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
res.writeHead(response.status, headers);
|
55
|
+
if (response.body != null && res.req.method !== "HEAD") {
|
56
|
+
for await (const chunk of response.body) {
|
57
|
+
res.write(chunk);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
res.end();
|
61
|
+
}
|
62
|
+
|
63
|
+
// src/adapters/node/orpc-handler.ts
|
64
|
+
var ORPCHandler2 = class {
|
65
|
+
orpcFetchHandler;
|
66
|
+
constructor(router, options) {
|
67
|
+
this.orpcFetchHandler = new ORPCHandler(router, options);
|
68
|
+
}
|
69
|
+
async handle(req, res, ...[options]) {
|
70
|
+
const request = createRequest(req, res);
|
71
|
+
const castedOptions = options ?? {};
|
72
|
+
const result = await this.orpcFetchHandler.handle(request, castedOptions);
|
73
|
+
if (result.matched === false) {
|
74
|
+
return { matched: false };
|
75
|
+
}
|
76
|
+
await options?.beforeSend?.(result.response, castedOptions.context);
|
77
|
+
await sendResponse(res, result.response);
|
78
|
+
return { matched: true };
|
79
|
+
}
|
80
|
+
};
|
81
|
+
export {
|
82
|
+
ORPCHandler2 as ORPCHandler,
|
83
|
+
createHeaders,
|
84
|
+
createRequest,
|
85
|
+
sendResponse
|
86
|
+
};
|
87
|
+
//# sourceMappingURL=node.js.map
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { Hooks } from '@orpc/shared';
|
2
|
+
import type { Router } from '../../router';
|
3
|
+
import type { Context } from '../../types';
|
4
|
+
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
|
+
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
+
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
+
export type ORPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
+
signal?: AbortSignal;
|
9
|
+
}> & {
|
10
|
+
procedureMatcher?: PublicORPCProcedureMatcher;
|
11
|
+
payloadCodec?: PublicORPCPayloadCodec;
|
12
|
+
};
|
13
|
+
export declare class ORPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
+
private readonly options?;
|
15
|
+
private readonly procedureMatcher;
|
16
|
+
private readonly payloadCodec;
|
17
|
+
constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>> | undefined);
|
18
|
+
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { HTTPMethod } from '@orpc/contract';
|
2
|
+
export declare class ORPCPayloadCodec {
|
3
|
+
/**
|
4
|
+
* If method is GET, the payload will be encoded as query string.
|
5
|
+
* If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
|
6
|
+
*/
|
7
|
+
encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
|
8
|
+
query?: URLSearchParams;
|
9
|
+
body?: FormData | string;
|
10
|
+
headers?: Headers;
|
11
|
+
method: HTTPMethod;
|
12
|
+
};
|
13
|
+
decode(re: Request | Response): Promise<unknown>;
|
14
|
+
}
|
15
|
+
export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
|
16
|
+
//# sourceMappingURL=orpc-payload-codec.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ANY_PROCEDURE } from '../../procedure';
|
2
|
+
import { type ANY_ROUTER } from '../../router';
|
3
|
+
export declare class ORPCProcedureMatcher {
|
4
|
+
private readonly router;
|
5
|
+
constructor(router: ANY_ROUTER);
|
6
|
+
match(pathname: string): Promise<{
|
7
|
+
path: string[];
|
8
|
+
procedure: ANY_PROCEDURE;
|
9
|
+
} | undefined>;
|
10
|
+
}
|
11
|
+
export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
|
12
|
+
//# sourceMappingURL=orpc-procedure-matcher.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Segment } from '@orpc/shared';
|
2
|
+
export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
|
3
|
+
export type JSONMeta = [JSONExtraType, Segment[]][];
|
4
|
+
export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
|
5
|
+
data: unknown;
|
6
|
+
meta: JSONMeta;
|
7
|
+
};
|
8
|
+
export declare function deserialize({ data, meta, }: {
|
9
|
+
data: unknown;
|
10
|
+
meta: JSONMeta;
|
11
|
+
}): unknown;
|
12
|
+
//# sourceMappingURL=super-json.d.ts.map
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Context } from '../../types';
|
3
|
+
export type FetchHandleOptions<T extends Context> = {
|
4
|
+
prefix?: HTTPPath;
|
5
|
+
} & (undefined extends T ? {
|
6
|
+
context?: T;
|
7
|
+
} : {
|
8
|
+
context: T;
|
9
|
+
});
|
10
|
+
export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (undefined extends T ? [] : never);
|
11
|
+
export type FetchHandleResult = {
|
12
|
+
matched: true;
|
13
|
+
response: Response;
|
14
|
+
} | {
|
15
|
+
matched: false;
|
16
|
+
response: undefined;
|
17
|
+
};
|
18
|
+
export interface FetchHandler<T extends Context> {
|
19
|
+
handle: (request: Request, ...rest: FetchHandleRest<T>) => Promise<FetchHandleResult>;
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -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 { ORPCHandlerOptions } from '../fetch/orpc-handler';
|
5
|
+
import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
|
6
|
+
import { type ExpressableIncomingMessage } from './request-listener';
|
7
|
+
export declare class ORPCHandler<T extends Context> implements RequestHandler<T> {
|
8
|
+
private readonly orpcFetchHandler;
|
9
|
+
constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<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,53 +1,35 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
import
|
7
|
-
import {
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { FlattenLazy } from './lazy';
|
3
|
+
import type { Middleware } from './middleware';
|
4
|
+
import type { DecoratedMiddleware } from './middleware-decorated';
|
5
|
+
import type { Router } from './router';
|
6
|
+
import type { AdaptedRouter } from './router-builder';
|
7
|
+
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
8
|
+
import { type ChainableImplementer } from './implementer-chainable';
|
9
|
+
import { type ProcedureHandler } from './procedure';
|
8
10
|
import { ProcedureBuilder } from './procedure-builder';
|
9
|
-
import {
|
11
|
+
import { type DecoratedProcedure } from './procedure-decorated';
|
10
12
|
import { RouterBuilder } from './router-builder';
|
11
|
-
|
13
|
+
export interface BuilderDef<TContext extends Context, TExtraContext extends Context> {
|
14
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any>[];
|
15
|
+
}
|
12
16
|
export declare class Builder<TContext extends Context, TExtraContext extends Context> {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
* Self chainable
|
21
|
-
*/
|
22
|
-
context<UContext extends Context>(): IsEqual<UContext, Context> extends true ? Builder<TContext, TExtraContext> : Builder<UContext, TExtraContext>;
|
23
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, unknown, unknown>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
24
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, unknown>, mapInput: MapInputMiddleware<unknown, UMappedInput>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
25
|
-
/**
|
26
|
-
* Convert to ContractProcedureBuilder
|
27
|
-
*/
|
28
|
-
route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
17
|
+
'~type': "Builder";
|
18
|
+
'~orpc': BuilderDef<TContext, TExtraContext>;
|
19
|
+
constructor(def: BuilderDef<TContext, TExtraContext>);
|
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>): 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>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>;
|
23
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
29
24
|
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
30
25
|
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
31
|
-
|
32
|
-
* Convert to Procedure
|
33
|
-
*/
|
34
|
-
func<UFuncOutput = undefined>(func: ProcedureFunc<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
|
35
|
-
/**
|
36
|
-
* Convert to ProcedureImplementer | RouterBuilder
|
37
|
-
*/
|
38
|
-
contract<UContract extends ContractProcedure<any, any> | ContractRouter>(contract: UContract): UContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : UContract extends ContractRouter ? ChainedRouterImplementer<TContext, UContract, TExtraContext> : never;
|
39
|
-
/**
|
40
|
-
* Create ExtendedMiddleware
|
41
|
-
*/
|
42
|
-
middleware<UExtraContext extends Context = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>;
|
26
|
+
handler<UFuncOutput = undefined>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
|
43
27
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
*/
|
48
|
-
router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>;
|
49
|
-
lazy<U extends Router<TContext> | Procedure<TContext, any, any, any, any>>(loader: () => Promise<{
|
28
|
+
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
29
|
+
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
30
|
+
lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
|
50
31
|
default: U;
|
51
|
-
}>):
|
32
|
+
}>): AdaptedRouter<TContext, FlattenLazy<U>>;
|
33
|
+
contract<U extends ANY_CONTRACT_PROCEDURE | ContractRouter>(contract: U): ChainableImplementer<TContext, TExtraContext, U>;
|
52
34
|
}
|
53
35
|
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1,6 @@
|
|
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;
|
4
|
+
export declare function deepSetLazyRouterPrefix<T extends object>(router: T, prefix: HTTPPath): T;
|
5
|
+
export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
|
6
|
+
//# sourceMappingURL=hidden.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { Middleware } from './middleware';
|
2
|
+
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
3
|
+
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
|
+
import { ProcedureImplementer } from './procedure-implementer';
|
5
|
+
import { RouterImplementer } from './router-implementer';
|
6
|
+
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : {
|
7
|
+
[K in keyof TContract]: TContract[K] extends ContractRouter ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
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>[]): ChainableImplementer<TContext, TExtraContext, TContract>;
|
10
|
+
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,17 +1,24 @@
|
|
1
|
+
import type { WELL_CONTEXT } from './types';
|
1
2
|
import { Builder } from './builder';
|
2
3
|
export * from './builder';
|
4
|
+
export * from './hidden';
|
5
|
+
export * from './implementer-chainable';
|
3
6
|
export * from './lazy';
|
7
|
+
export * from './lazy-decorated';
|
4
8
|
export * from './middleware';
|
9
|
+
export * from './middleware-decorated';
|
5
10
|
export * from './procedure';
|
6
11
|
export * from './procedure-builder';
|
7
|
-
export * from './procedure-
|
12
|
+
export * from './procedure-client';
|
13
|
+
export * from './procedure-decorated';
|
8
14
|
export * from './procedure-implementer';
|
9
15
|
export * from './router';
|
10
16
|
export * from './router-builder';
|
11
|
-
export * from './router-
|
17
|
+
export * from './router-client';
|
12
18
|
export * from './router-implementer';
|
13
19
|
export * from './types';
|
14
20
|
export * from './utils';
|
21
|
+
export { configGlobal, fallbackToGlobalConfig } from '@orpc/contract';
|
15
22
|
export * from '@orpc/shared/error';
|
16
|
-
export declare const os: Builder<
|
23
|
+
export declare const os: Builder<WELL_CONTEXT, undefined>;
|
17
24
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { ProcedureClient } from './procedure-client';
|
5
|
+
import { type ANY_ROUTER } from './router';
|
6
|
+
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends Procedure<infer UContext, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? undefined extends UContext ? ProcedureClient<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, unknown> : unknown : {
|
7
|
+
[K in keyof T]: T[K] extends object ? DecoratedLazy<T[K]> : never;
|
8
|
+
});
|
9
|
+
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
10
|
+
//# sourceMappingURL=lazy-decorated.d.ts.map
|
package/dist/src/lazy.d.ts
CHANGED
@@ -1,23 +1,18 @@
|
|
1
|
-
import type { Procedure } from './procedure';
|
2
|
-
import type { ProcedureCaller } from './procedure-caller';
|
3
1
|
export declare const LAZY_LOADER_SYMBOL: unique symbol;
|
4
2
|
export interface Lazy<T> {
|
5
3
|
[LAZY_LOADER_SYMBOL]: () => Promise<{
|
6
4
|
default: T;
|
7
5
|
}>;
|
8
6
|
}
|
7
|
+
export type Lazyable<T> = T | Lazy<T>;
|
9
8
|
export type ANY_LAZY = Lazy<any>;
|
10
|
-
export declare function
|
9
|
+
export declare function lazy<T>(loader: () => Promise<{
|
11
10
|
default: T;
|
12
11
|
}>): Lazy<T>;
|
13
|
-
export declare function loadLazy<T>(lazy: Lazy<T>): Promise<{
|
14
|
-
default: T;
|
15
|
-
}>;
|
16
12
|
export declare function isLazy(item: unknown): item is ANY_LAZY;
|
13
|
+
export declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
14
|
+
default: T extends Lazy<infer U> ? U : T;
|
15
|
+
}>;
|
17
16
|
export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
|
18
|
-
export declare function
|
19
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : (T extends Procedure<infer UContext, any, any, any, any> ? Lazy<T> & (undefined extends UContext ? ProcedureCaller<T> : unknown) : T extends Record<any, any> ? {
|
20
|
-
[K in keyof T]: DecoratedLazy<T[K]>;
|
21
|
-
} /** Notice: this still a lazy, but type not work when I & Lazy<T>, maybe it's a bug, should improve */ : Lazy<T>);
|
22
|
-
export declare function decorateLazy<T>(lazy: Lazy<T>): DecoratedLazy<T>;
|
17
|
+
export declare function flatLazy<T extends ANY_LAZY>(lazied: T): FlattenLazy<T>;
|
23
18
|
//# sourceMappingURL=lazy.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
+
import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
3
|
+
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput> extends Middleware<TContext, TExtraContext, 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>;
|
6
|
+
}
|
7
|
+
export declare function decorateMiddleware<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TInput = unknown, TOutput = unknown>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput>;
|
8
|
+
//# sourceMappingURL=middleware-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,26 +1,33 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
2
|
+
import type { ANY_PROCEDURE } from './procedure';
|
3
|
+
import type { Context } from './types';
|
3
4
|
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
4
5
|
output: TOutput;
|
5
6
|
context: TExtraContext;
|
6
7
|
}>;
|
7
|
-
export interface
|
8
|
-
|
8
|
+
export interface MiddlewareNextFn<TOutput> {
|
9
|
+
<UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
|
9
10
|
context?: UExtraContext;
|
10
11
|
} : {
|
11
12
|
context: UExtraContext;
|
12
|
-
})
|
13
|
-
|
13
|
+
}): MiddlewareResult<UExtraContext, TOutput>;
|
14
|
+
}
|
15
|
+
export interface MiddlewareOutputFn<TOutput> {
|
16
|
+
(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
17
|
+
}
|
18
|
+
export interface MiddlewareOptions<TContext extends Context, TOutput> {
|
19
|
+
context: TContext;
|
20
|
+
path: string[];
|
21
|
+
procedure: ANY_PROCEDURE;
|
22
|
+
signal?: AbortSignal;
|
23
|
+
next: MiddlewareNextFn<TOutput>;
|
14
24
|
}
|
15
25
|
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput> {
|
16
|
-
(
|
26
|
+
(options: MiddlewareOptions<TContext, TOutput>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
17
27
|
}
|
28
|
+
export type ANY_MIDDLEWARE = Middleware<any, any, any, any>;
|
18
29
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
19
30
|
(input: TInput): TMappedInput;
|
20
31
|
}
|
21
|
-
export
|
22
|
-
concat: (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UInput = TInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, TInput & UInput, TOutput>) & (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput>, mapInput: MapInputMiddleware<UInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, TInput & UInput, TOutput>);
|
23
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
24
|
-
}
|
25
|
-
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput>;
|
32
|
+
export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
|
26
33
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,31 +1,22 @@
|
|
1
1
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
+
import type { DecoratedProcedure } from './procedure-decorated';
|
2
3
|
import type { Context, MergeContext } from './types';
|
3
4
|
import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
4
|
-
import { type
|
5
|
+
import { type ProcedureHandler } from './procedure';
|
5
6
|
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>[];
|
10
|
+
}
|
6
11
|
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
* Self chainable
|
17
|
-
*/
|
18
|
-
route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
19
|
-
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, TOutputSchema>;
|
20
|
-
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, USchema>;
|
21
|
-
/**
|
22
|
-
* Convert to ProcedureBuilder
|
23
|
-
*/
|
24
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
25
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
26
|
-
/**
|
27
|
-
* Convert to Procedure
|
28
|
-
*/
|
29
|
-
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
12
|
+
'~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 = undefined>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema>;
|
17
|
+
output<U extends Schema = undefined>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U>;
|
18
|
+
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>;
|
19
|
+
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>;
|
20
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
30
21
|
}
|
31
22
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Lazyable } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
import type { Context, Meta, WELL_CONTEXT, WithSignal } from './types';
|
6
|
+
export type ProcedureClientOptions<TClientContext> = WithSignal & (undefined extends TClientContext ? {
|
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
|
+
}
|
14
|
+
/**
|
15
|
+
* Options for creating a procedure caller with comprehensive type safety
|
16
|
+
*/
|
17
|
+
export type CreateProcedureClientOptions<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> = {
|
18
|
+
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput>>;
|
19
|
+
/**
|
20
|
+
* This is helpful for logging and analytics.
|
21
|
+
*
|
22
|
+
* @internal
|
23
|
+
*/
|
24
|
+
path?: string[];
|
25
|
+
} & ({
|
26
|
+
/**
|
27
|
+
* The context used when calling the procedure.
|
28
|
+
*/
|
29
|
+
context: Value<TContext>;
|
30
|
+
} | (undefined extends TContext ? {
|
31
|
+
context?: undefined;
|
32
|
+
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
33
|
+
export declare function createProcedureClient<TContext extends Context = WELL_CONTEXT, TInputSchema extends Schema = undefined, TOutputSchema extends Schema = undefined, THandlerOutput extends SchemaInput<TOutputSchema> = SchemaInput<TOutputSchema>>(options: CreateProcedureClientOptions<TContext, TInputSchema, TOutputSchema, THandlerOutput>): ProcedureClient<SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, unknown>;
|
34
|
+
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
|
+
import type { ProcedureClient } from './procedure-client';
|
4
|
+
import type { Context, MergeContext } from './types';
|
5
|
+
import { Procedure } from './procedure';
|
6
|
+
export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>> = Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput> & {
|
7
|
+
prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
8
|
+
route: (route: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
9
|
+
use: (<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput>) & (<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema, THandlerOutput>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput>);
|
10
|
+
unshiftTag: (...tags: string[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
11
|
+
unshiftMiddleware: <U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(...middlewares: Middleware<TContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>>[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
12
|
+
} & (undefined extends TContext ? ProcedureClient<SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, unknown> : unknown);
|
13
|
+
export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>>(procedure: Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
14
|
+
//# sourceMappingURL=procedure-decorated.d.ts.map
|