@orpc/server 0.0.0-next.3f6c426 → 0.0.0-next.43889a7
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/dist/{chunk-B2EZJB7X.js → chunk-26GHKV43.js} +19 -21
- package/dist/{chunk-6A7XHEBH.js → chunk-LDIL7OEP.js} +87 -59
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +5 -22
- package/dist/hono.js +30 -0
- package/dist/index.js +702 -172
- package/dist/next.js +36 -0
- package/dist/node.js +71 -29
- package/dist/src/adapters/fetch/index.d.ts +0 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +9 -9
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +1 -1
- package/dist/src/adapters/fetch/types.d.ts +12 -7
- 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 +1 -1
- package/dist/src/adapters/node/orpc-handler.d.ts +8 -8
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +11 -10
- package/dist/src/builder-with-errors-middlewares.d.ts +49 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +49 -0
- package/dist/src/builder.d.ts +33 -22
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +10 -0
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +11 -5
- package/dist/src/index.d.ts +6 -5
- package/dist/src/lazy-decorated.d.ts +4 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +29 -13
- package/dist/src/procedure-builder-with-input.d.ts +35 -0
- package/dist/src/procedure-builder-with-output.d.ts +34 -0
- package/dist/src/procedure-builder.d.ts +24 -18
- package/dist/src/procedure-client.d.ts +9 -22
- package/dist/src/procedure-decorated.d.ts +22 -11
- package/dist/src/procedure-implementer.d.ts +18 -13
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +37 -13
- package/dist/src/router-builder.d.ts +20 -16
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +12 -10
- package/dist/src/router.d.ts +6 -6
- package/dist/src/types.d.ts +2 -3
- package/package.json +18 -8
- package/dist/src/adapters/fetch/composite-handler.d.ts +0 -8
- package/dist/src/adapters/node/composite-handler.d.ts +0 -9
- package/dist/src/utils.d.ts +0 -3
package/dist/next.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
2
|
+
import {
|
3
|
+
ORPCPayloadCodec,
|
4
|
+
ORPCProcedureMatcher,
|
5
|
+
RPCHandler,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-26GHKV43.js";
|
8
|
+
import "./chunk-LDIL7OEP.js";
|
9
|
+
|
10
|
+
// src/adapters/next/serve.ts
|
11
|
+
import { value } from "@orpc/shared";
|
12
|
+
function serve(handler, ...[options]) {
|
13
|
+
const main = async (req) => {
|
14
|
+
const context = await value(options?.context ?? {}, req);
|
15
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
16
|
+
if (matched) {
|
17
|
+
return response;
|
18
|
+
}
|
19
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
20
|
+
};
|
21
|
+
return {
|
22
|
+
GET: main,
|
23
|
+
POST: main,
|
24
|
+
PUT: main,
|
25
|
+
PATCH: main,
|
26
|
+
DELETE: main
|
27
|
+
};
|
28
|
+
}
|
29
|
+
export {
|
30
|
+
ORPCPayloadCodec,
|
31
|
+
ORPCProcedureMatcher,
|
32
|
+
RPCHandler,
|
33
|
+
super_json_exports as SuperJSON,
|
34
|
+
serve
|
35
|
+
};
|
36
|
+
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
@@ -1,45 +1,87 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
} from "./chunk-
|
4
|
-
import "./chunk-
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-26GHKV43.js";
|
4
|
+
import "./chunk-LDIL7OEP.js";
|
5
5
|
|
6
|
-
// src/adapters/node/
|
7
|
-
|
8
|
-
|
9
|
-
|
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]);
|
10
38
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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];
|
15
49
|
}
|
50
|
+
} else {
|
51
|
+
headers[key] = value;
|
16
52
|
}
|
17
|
-
res.statusCode = 404;
|
18
|
-
res.end("None of the handlers can handle the request.");
|
19
53
|
}
|
20
|
-
|
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
|
+
}
|
21
62
|
|
22
63
|
// src/adapters/node/orpc-handler.ts
|
23
|
-
|
24
|
-
import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE } from "@orpc/shared";
|
25
|
-
var ORPCHandler2 = class {
|
64
|
+
var RPCHandler2 = class {
|
26
65
|
orpcFetchHandler;
|
27
66
|
constructor(router, options) {
|
28
|
-
this.orpcFetchHandler = new
|
29
|
-
}
|
30
|
-
condition(request) {
|
31
|
-
return Boolean(request.headers[ORPC_HANDLER_HEADER]?.includes(ORPC_HANDLER_VALUE));
|
67
|
+
this.orpcFetchHandler = new RPCHandler(router, options);
|
32
68
|
}
|
33
|
-
async handle(req, res, ...
|
34
|
-
const request = createRequest(req, res
|
35
|
-
const
|
36
|
-
|
37
|
-
|
38
|
-
|
69
|
+
async handle(req, res, ...rest) {
|
70
|
+
const request = createRequest(req, res);
|
71
|
+
const result = await this.orpcFetchHandler.handle(request, ...rest);
|
72
|
+
if (result.matched === false) {
|
73
|
+
return { matched: false };
|
74
|
+
}
|
75
|
+
const context = rest[0]?.context ?? {};
|
76
|
+
await rest[0]?.beforeSend?.(result.response, context);
|
77
|
+
await sendResponse(res, result.response);
|
78
|
+
return { matched: true };
|
39
79
|
}
|
40
80
|
};
|
41
81
|
export {
|
42
|
-
|
43
|
-
|
82
|
+
RPCHandler2 as RPCHandler,
|
83
|
+
createHeaders,
|
84
|
+
createRequest,
|
85
|
+
sendResponse
|
44
86
|
};
|
45
87
|
//# sourceMappingURL=node.js.map
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import type { Hooks } from '@orpc/shared';
|
2
|
+
import type { Context } from '../../context';
|
2
3
|
import type { Router } from '../../router';
|
3
|
-
import type {
|
4
|
-
import type { ConditionalFetchHandler, FetchOptions } from './types';
|
4
|
+
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
5
|
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
6
|
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
-
export type
|
7
|
+
export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
+
signal?: AbortSignal;
|
9
|
+
}> & {
|
8
10
|
procedureMatcher?: PublicORPCProcedureMatcher;
|
9
11
|
payloadCodec?: PublicORPCPayloadCodec;
|
10
12
|
};
|
11
|
-
export declare class
|
12
|
-
readonly
|
13
|
-
readonly options?: NoInfer<ORPCHandlerOptions<T>> | undefined;
|
13
|
+
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
+
private readonly options?;
|
14
15
|
private readonly procedureMatcher;
|
15
16
|
private readonly payloadCodec;
|
16
|
-
constructor(router: Router<T, any>, options?: NoInfer<
|
17
|
-
|
18
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
17
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
|
18
|
+
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
19
|
}
|
20
20
|
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,16 +1,21 @@
|
|
1
1
|
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Context
|
3
|
-
export type
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
export type FetchHandleOptions<T extends Context> = {
|
4
4
|
prefix?: HTTPPath;
|
5
|
-
} & (
|
5
|
+
} & (Record<never, never> extends T ? {
|
6
6
|
context?: T;
|
7
7
|
} : {
|
8
8
|
context: T;
|
9
9
|
});
|
10
|
+
export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
|
+
export type FetchHandleResult = {
|
12
|
+
matched: true;
|
13
|
+
response: Response;
|
14
|
+
} | {
|
15
|
+
matched: false;
|
16
|
+
response: undefined;
|
17
|
+
};
|
10
18
|
export interface FetchHandler<T extends Context> {
|
11
|
-
|
12
|
-
}
|
13
|
-
export interface ConditionalFetchHandler<T extends Context> extends FetchHandler<T> {
|
14
|
-
condition: (request: Request) => boolean;
|
19
|
+
handle: (request: Request, ...rest: FetchHandleRest<T>) => Promise<FetchHandleResult>;
|
15
20
|
}
|
16
21
|
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
4
|
+
import { type Value } from '@orpc/shared';
|
5
|
+
export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
6
|
+
context?: Value<T, [HonoContext]>;
|
7
|
+
} : {
|
8
|
+
context: Value<T, [HonoContext]>;
|
9
|
+
});
|
10
|
+
export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
|
+
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
|
12
|
+
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
4
|
+
import { type Value } from '@orpc/shared';
|
5
|
+
export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
6
|
+
context?: Value<T, [NextRequest]>;
|
7
|
+
} : {
|
8
|
+
context: Value<T, [NextRequest]>;
|
9
|
+
});
|
10
|
+
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
|
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]: ServeRest<T>): ServeResult;
|
19
|
+
//# sourceMappingURL=serve.d.ts.map
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ServerResponse } from 'node:http';
|
2
|
+
import type { Context } from '../../context';
|
2
3
|
import type { Router } from '../../router';
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import
|
6
|
-
export declare class
|
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> {
|
7
8
|
private readonly orpcFetchHandler;
|
8
|
-
constructor(router: Router<T, any>, options?: NoInfer<
|
9
|
-
|
10
|
-
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
9
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
10
|
+
handle(req: ExpressableIncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
11
11
|
}
|
12
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
|
@@ -1,21 +1,22 @@
|
|
1
|
-
import type { RequestOptions as BaseRequestOptions } from '@mjackson/node-fetch-server';
|
2
1
|
import type { HTTPPath } from '@orpc/contract';
|
3
2
|
import type { Promisable } from '@orpc/shared';
|
4
3
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
5
|
-
import type { Context
|
6
|
-
export type
|
4
|
+
import type { Context } from '../../context';
|
5
|
+
export type RequestHandleOptions<T extends Context> = {
|
7
6
|
prefix?: HTTPPath;
|
8
|
-
|
7
|
+
beforeSend?: (response: Response, context: T) => Promisable<void>;
|
8
|
+
} & (Record<never, never> extends T ? {
|
9
9
|
context?: T;
|
10
10
|
} : {
|
11
11
|
context: T;
|
12
|
-
})
|
13
|
-
|
12
|
+
});
|
13
|
+
export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
14
|
+
export type RequestHandleResult = {
|
15
|
+
matched: true;
|
16
|
+
} | {
|
17
|
+
matched: false;
|
14
18
|
};
|
15
19
|
export interface RequestHandler<T extends Context> {
|
16
|
-
handle: (req: IncomingMessage, res: ServerResponse, ...
|
17
|
-
}
|
18
|
-
export interface ConditionalRequestHandler<T extends Context> extends RequestHandler<T> {
|
19
|
-
condition: (request: IncomingMessage) => boolean;
|
20
|
+
handle: (req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>) => Promise<RequestHandleResult>;
|
20
21
|
}
|
21
22
|
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
4
|
+
import type { FlattenLazy } from './lazy';
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { ProcedureHandler } from './procedure';
|
7
|
+
import type { Router } from './router';
|
8
|
+
import type { AdaptedRouter } from './router-builder';
|
9
|
+
import { ProcedureBuilder } from './procedure-builder';
|
10
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
11
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
12
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
13
|
+
import { RouterBuilder } from './router-builder';
|
14
|
+
export interface BuilderWithErrorsMiddlewaresDef<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
15
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
16
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
17
|
+
errorMap: TErrorMap;
|
18
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
19
|
+
inputValidationIndex: number;
|
20
|
+
outputValidationIndex: number;
|
21
|
+
config: ContractBuilderConfig;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* `BuilderWithErrorsMiddlewares` is a combination of `BuilderWithErrorsMiddlewares` and `BuilderWithErrors`.
|
25
|
+
*
|
26
|
+
* Why?
|
27
|
+
* - prevents .middleware after .use (can mislead the behavior)
|
28
|
+
* - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
|
29
|
+
* - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
export declare class BuilderWithErrorsMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> {
|
33
|
+
'~type': "BuilderWithErrorsMiddlewares";
|
34
|
+
'~orpc': BuilderWithErrorsMiddlewaresDef<TInitialContext, TCurrentContext, TErrorMap>;
|
35
|
+
constructor(def: BuilderWithErrorsMiddlewaresDef<TInitialContext, TCurrentContext, TErrorMap>);
|
36
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TInitialContext, TCurrentContext, TErrorMap & U>;
|
37
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): ConflictContextGuard<TCurrentContext & U> & BuilderWithErrorsMiddlewares<TInitialContext, TCurrentContext & U, TErrorMap>;
|
38
|
+
route(route: RouteOptions): ProcedureBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
39
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TErrorMap>;
|
40
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, USchema, TErrorMap>;
|
41
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TCurrentContext, undefined, undefined, UFuncOutput, TErrorMap>;
|
42
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
43
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap>;
|
44
|
+
router<U extends Router<TCurrentContext, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TInitialContext, U, TErrorMap>;
|
45
|
+
lazy<U extends Router<TCurrentContext, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
46
|
+
default: U;
|
47
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, TErrorMap>;
|
48
|
+
}
|
49
|
+
//# sourceMappingURL=builder-with-errors-middlewares.d.ts.map
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
|
2
|
+
import type { BuilderConfig } from './builder';
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
4
|
+
import type { ORPCErrorConstructorMap } from './error';
|
5
|
+
import type { FlattenLazy } from './lazy';
|
6
|
+
import type { Middleware } from './middleware';
|
7
|
+
import type { DecoratedMiddleware } from './middleware-decorated';
|
8
|
+
import type { ProcedureHandler } from './procedure';
|
9
|
+
import type { Router } from './router';
|
10
|
+
import type { AdaptedRouter } from './router-builder';
|
11
|
+
import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
|
12
|
+
import { ProcedureBuilder } from './procedure-builder';
|
13
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
14
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
15
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
16
|
+
import { RouterBuilder } from './router-builder';
|
17
|
+
export interface BuilderWithErrorsDef<TInitialContext extends Context, TErrorMap extends ErrorMap> {
|
18
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
19
|
+
errorMap: TErrorMap;
|
20
|
+
config: BuilderConfig;
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* `BuilderWithErrors` is a branch of `Builder` which it has error map.
|
24
|
+
*
|
25
|
+
* Why?
|
26
|
+
* - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
|
27
|
+
*
|
28
|
+
*/
|
29
|
+
export declare class BuilderWithErrors<TInitialContext extends Context, TErrorMap extends ErrorMap> {
|
30
|
+
'~type': "BuilderWithErrors";
|
31
|
+
'~orpc': BuilderWithErrorsDef<TInitialContext, TErrorMap>;
|
32
|
+
constructor(def: BuilderWithErrorsDef<TInitialContext, TErrorMap>);
|
33
|
+
config(config: ContractBuilderConfig): BuilderWithErrors<TInitialContext, TErrorMap>;
|
34
|
+
context<UContext extends Context & TInitialContext = TInitialContext>(): BuilderWithErrors<UContext, TErrorMap>;
|
35
|
+
errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TInitialContext, TErrorMap & U>;
|
36
|
+
middleware<UOutContext extends Context, TInput, TOutput = any>(middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>;
|
37
|
+
use<U extends Context>(middleware: Middleware<TInitialContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TInitialContext, TInitialContext & U, TErrorMap>;
|
38
|
+
route(route: RouteOptions): ProcedureBuilder<TInitialContext, TInitialContext, TErrorMap>;
|
39
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TInitialContext, TInitialContext, USchema, TErrorMap>;
|
40
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TInitialContext, TInitialContext, USchema, TErrorMap>;
|
41
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TInitialContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TInitialContext, TInitialContext, undefined, undefined, UFuncOutput, TErrorMap>;
|
42
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TInitialContext, TErrorMap>;
|
43
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TInitialContext, TErrorMap>;
|
44
|
+
router<U extends Router<TInitialContext, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TInitialContext, U, TErrorMap>;
|
45
|
+
lazy<U extends Router<TInitialContext, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
|
46
|
+
default: U;
|
47
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, TErrorMap>;
|
48
|
+
}
|
49
|
+
//# sourceMappingURL=builder-with-errors.d.ts.map
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeCurrentContext, TypeInitialContext } from './context';
|
3
|
+
import type { FlattenLazy } from './lazy';
|
4
|
+
import type { Middleware } from './middleware';
|
5
|
+
import type { ProcedureHandler } from './procedure';
|
6
|
+
import type { Router } from './router';
|
7
|
+
import type { AdaptedRouter } from './router-builder';
|
8
|
+
import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
|
9
|
+
import { type ChainableImplementer } from './implementer-chainable';
|
10
|
+
import { ProcedureBuilder } from './procedure-builder';
|
11
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
12
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
13
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
14
|
+
import { RouterBuilder } from './router-builder';
|
15
|
+
/**
|
16
|
+
* `BuilderWithMiddlewares` is a branch of `Builder` which it has middlewares.
|
17
|
+
*
|
18
|
+
* Why?
|
19
|
+
* - prevents .middleware after .use (can mislead the behavior)
|
20
|
+
* - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
export interface BuilderWithMiddlewaresDef<TInitialContext extends Context, TCurrentContext extends Context> {
|
24
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
25
|
+
__currentContext?: TypeCurrentContext<TCurrentContext>;
|
26
|
+
config: ContractBuilderConfig;
|
27
|
+
middlewares: Middleware<any, any, any, any, any>[];
|
28
|
+
inputValidationIndex: number;
|
29
|
+
outputValidationIndex: number;
|
30
|
+
}
|
31
|
+
export declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context> {
|
32
|
+
'~type': "BuilderHasMiddlewares";
|
33
|
+
'~orpc': BuilderWithMiddlewaresDef<TInitialContext, TCurrentContext>;
|
34
|
+
constructor(def: BuilderWithMiddlewaresDef<TInitialContext, TCurrentContext>);
|
35
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, Record<never, never>>): ConflictContextGuard<TCurrentContext & U> & BuilderWithMiddlewares<TInitialContext, TCurrentContext & U>;
|
36
|
+
errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TInitialContext, TCurrentContext, U>;
|
37
|
+
route(route: RouteOptions): ProcedureBuilder<TInitialContext, TCurrentContext, Record<never, never>>;
|
38
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, Record<never, never>>;
|
39
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, USchema, Record<never, never>>;
|
40
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TInitialContext, TCurrentContext, undefined, undefined, UFuncOutput, Record<never, never>>;
|
41
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, Record<never, never>>;
|
42
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, Record<never, never>>;
|
43
|
+
router<U extends Router<TCurrentContext, any>>(router: U): AdaptedRouter<TInitialContext, U, Record<never, never>>;
|
44
|
+
lazy<U extends Router<TCurrentContext, any>>(loader: () => Promise<{
|
45
|
+
default: U;
|
46
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, Record<never, never>>;
|
47
|
+
contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TInitialContext, TCurrentContext, U>;
|
48
|
+
}
|
49
|
+
//# sourceMappingURL=builder-with-middlewares.d.ts.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,35 +1,46 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, TypeInitialContext } from './context';
|
2
3
|
import type { FlattenLazy } from './lazy';
|
3
4
|
import type { Middleware } from './middleware';
|
4
5
|
import type { DecoratedMiddleware } from './middleware-decorated';
|
6
|
+
import type { ProcedureHandler } from './procedure';
|
5
7
|
import type { Router } from './router';
|
6
8
|
import type { AdaptedRouter } from './router-builder';
|
7
|
-
import
|
9
|
+
import { BuilderWithErrors } from './builder-with-errors';
|
10
|
+
import { BuilderWithMiddlewares } from './builder-with-middlewares';
|
8
11
|
import { type ChainableImplementer } from './implementer-chainable';
|
9
|
-
import { type ProcedureFunc } from './procedure';
|
10
12
|
import { ProcedureBuilder } from './procedure-builder';
|
11
|
-
import {
|
13
|
+
import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
|
14
|
+
import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
|
15
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
12
16
|
import { RouterBuilder } from './router-builder';
|
13
|
-
export interface
|
14
|
-
|
17
|
+
export interface BuilderConfig extends ContractBuilderConfig {
|
18
|
+
initialInputValidationIndex?: number;
|
19
|
+
initialOutputValidationIndex?: number;
|
15
20
|
}
|
16
|
-
export
|
21
|
+
export interface BuilderDef<TInitialContext extends Context> {
|
22
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
23
|
+
config: BuilderConfig;
|
24
|
+
}
|
25
|
+
export declare class Builder<TInitialContext extends Context> {
|
17
26
|
'~type': "Builder";
|
18
|
-
'~orpc': BuilderDef<
|
19
|
-
constructor(def: BuilderDef<
|
20
|
-
|
21
|
-
|
22
|
-
middleware<
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
'~orpc': BuilderDef<TInitialContext>;
|
28
|
+
constructor(def: BuilderDef<TInitialContext>);
|
29
|
+
config(config: ContractBuilderConfig): Builder<TInitialContext>;
|
30
|
+
context<UContext extends Context & TInitialContext = TInitialContext>(): Builder<UContext>;
|
31
|
+
middleware<UOutContext extends Context, TInput, TOutput = any>(middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, Record<never, never>>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, Record<never, never>>;
|
32
|
+
errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TInitialContext, U>;
|
33
|
+
use<UOutContext extends Context>(middleware: Middleware<TInitialContext, UOutContext, unknown, unknown, Record<never, never>>): ConflictContextGuard<TInitialContext & UOutContext> & BuilderWithMiddlewares<TInitialContext, TInitialContext & UOutContext>;
|
34
|
+
route(route: RouteOptions): ProcedureBuilder<TInitialContext, TInitialContext, Record<never, never>>;
|
35
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TInitialContext, TInitialContext, USchema, Record<never, never>>;
|
36
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TInitialContext, TInitialContext, USchema, Record<never, never>>;
|
37
|
+
handler<UFuncOutput>(handler: ProcedureHandler<TInitialContext, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TInitialContext, TInitialContext, undefined, undefined, UFuncOutput, Record<never, never>>;
|
38
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TInitialContext, Record<never, never>>;
|
39
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TInitialContext, Record<never, never>>;
|
40
|
+
router<U extends Router<TInitialContext, any>>(router: U): AdaptedRouter<TInitialContext, U, Record<never, never>>;
|
41
|
+
lazy<U extends Router<TInitialContext, any>>(loader: () => Promise<{
|
31
42
|
default: U;
|
32
|
-
}>): AdaptedRouter<
|
33
|
-
contract<U extends
|
43
|
+
}>): AdaptedRouter<TInitialContext, FlattenLazy<U>, Record<never, never>>;
|
44
|
+
contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TInitialContext, TInitialContext, U>;
|
34
45
|
}
|
35
46
|
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { IsNever } from '@orpc/shared';
|
2
|
+
export type Context = Record<string, any>;
|
3
|
+
export type TypeInitialContext<T extends Context> = (type: T) => any;
|
4
|
+
export type TypeCurrentContext<T extends Context> = {
|
5
|
+
type: T;
|
6
|
+
};
|
7
|
+
export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
8
|
+
[K in keyof T]: IsNever<T[K]>;
|
9
|
+
}[keyof T] ? never : unknown;
|
10
|
+
//# sourceMappingURL=context.d.ts.map
|
@@ -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> = {
|
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
|