@orpc/server 2.0.0-beta.48 → 2.0.0-beta.49
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 +4 -4
- package/dist/adapters/aws-lambda/handler.d.ts +25 -0
- package/dist/adapters/aws-lambda/handler.js +24 -0
- package/dist/adapters/aws-lambda/index.d.ts +16 -0
- package/dist/adapters/aws-lambda/index.js +2 -0
- package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
- package/dist/adapters/aws-lambda/rpc-handler.js +18 -0
- package/dist/adapters/crossws/handler.d.ts +45 -0
- package/dist/adapters/crossws/handler.js +60 -0
- package/dist/adapters/crossws/index.d.ts +2 -0
- package/dist/adapters/crossws/index.js +2 -0
- package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
- package/dist/adapters/crossws/rpc-handler.js +15 -0
- package/dist/adapters/fastify/handler.d.ts +21 -0
- package/dist/adapters/fastify/handler.js +20 -0
- package/dist/adapters/fastify/index.d.ts +2 -0
- package/dist/adapters/fastify/index.js +2 -0
- package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
- package/dist/adapters/fastify/rpc-handler.js +14 -0
- package/dist/adapters/fetch/handler.d.ts +23 -0
- package/dist/adapters/fetch/handler.js +22 -0
- package/dist/adapters/fetch/index.d.ts +7 -0
- package/dist/adapters/fetch/index.js +7 -0
- package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
- package/dist/adapters/fetch/rpc-handler.js +16 -0
- package/dist/adapters/message-port/handler.d.ts +64 -0
- package/dist/adapters/message-port/handler.js +86 -0
- package/dist/adapters/message-port/index.d.ts +2 -0
- package/dist/adapters/message-port/index.js +2 -0
- package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
- package/dist/adapters/message-port/rpc-handler.js +15 -0
- package/dist/adapters/node/handler.d.ts +21 -0
- package/dist/adapters/node/handler.js +20 -0
- package/dist/adapters/node/index.d.ts +7 -0
- package/dist/adapters/node/index.js +7 -0
- package/dist/adapters/node/rpc-handler.d.ts +16 -0
- package/dist/adapters/node/rpc-handler.js +15 -0
- package/dist/adapters/standard/codec.d.ts +16 -0
- package/dist/adapters/standard/handler.d.ts +68 -0
- package/dist/adapters/standard/handler.js +205 -0
- package/dist/adapters/standard/index.d.ts +6 -0
- package/dist/adapters/standard/index.js +5 -0
- package/dist/adapters/standard/plugin.d.ts +32 -0
- package/dist/adapters/standard/plugin.js +16 -0
- package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
- package/dist/adapters/standard/rpc-handler-codec.js +51 -0
- package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
- package/dist/adapters/standard/rpc-matcher.js +152 -0
- package/dist/adapters/standard/utils.d.ts +10 -0
- package/dist/adapters/standard/utils.js +6 -0
- package/dist/adapters/standard-peer/index.d.ts +1 -0
- package/dist/adapters/standard-peer/index.js +1 -0
- package/dist/adapters/standard-peer/{utils.d.mts → utils.d.ts} +3 -3
- package/dist/adapters/standard-peer/utils.js +7 -0
- package/dist/adapters/websocket/handler.d.ts +59 -0
- package/dist/adapters/websocket/handler.js +85 -0
- package/dist/adapters/websocket/index.d.ts +2 -0
- package/dist/adapters/websocket/index.js +2 -0
- package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
- package/dist/adapters/websocket/rpc-handler.js +15 -0
- package/dist/builder-variants.d.ts +226 -0
- package/dist/builder.d.ts +127 -0
- package/dist/builder.js +226 -0
- package/dist/context.d.ts +6 -0
- package/dist/extensions/callable.d.ts +11 -0
- package/dist/extensions/callable.js +7 -0
- package/dist/helpers/base64url.d.ts +31 -0
- package/dist/helpers/base64url.js +53 -0
- package/dist/helpers/cookie.d.ts +51 -0
- package/dist/helpers/cookie.js +69 -0
- package/dist/helpers/encryption.d.ts +28 -0
- package/dist/helpers/encryption.js +80 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/signing.d.ts +50 -0
- package/dist/helpers/signing.js +88 -0
- package/dist/implementer-procedure.d.ts +16 -0
- package/dist/implementer-procedure.js +44 -0
- package/dist/implementer-router.d.ts +40 -0
- package/dist/implementer-router.js +117 -0
- package/dist/implementer.d.ts +16 -0
- package/dist/implementer.js +37 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +48 -0
- package/dist/lazy.d.ts +20 -0
- package/dist/lazy.js +31 -0
- package/dist/middleware-decorated.d.ts +10 -0
- package/dist/middleware-decorated.js +71 -0
- package/dist/middleware.d.ts +54 -0
- package/dist/plugins/batch.d.ts +102 -0
- package/dist/plugins/batch.js +405 -0
- package/dist/plugins/cors.d.ts +73 -0
- package/dist/plugins/cors.js +112 -0
- package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
- package/dist/plugins/get-method-csrf-protection.js +64 -0
- package/dist/plugins/head-method.d.ts +23 -0
- package/dist/plugins/head-method.js +104 -0
- package/dist/plugins/index.d.ts +39 -0
- package/dist/plugins/index.js +29 -0
- package/dist/plugins/method-override.d.ts +38 -0
- package/dist/plugins/method-override.js +50 -0
- package/dist/plugins/request-compression.d.ts +16 -0
- package/dist/plugins/request-compression.js +82 -0
- package/dist/plugins/request-headers.d.ts +22 -0
- package/dist/plugins/request-headers.js +30 -0
- package/dist/plugins/request-limit.d.ts +30 -0
- package/dist/plugins/request-limit.js +68 -0
- package/dist/plugins/response-compression.d.ts +59 -0
- package/dist/plugins/response-compression.js +209 -0
- package/dist/plugins/response-headers.d.ts +30 -0
- package/dist/plugins/response-headers.js +47 -0
- package/dist/plugins/rethrow.d.ts +33 -0
- package/dist/plugins/rethrow.js +59 -0
- package/dist/plugins/signal-sync.d.ts +13 -0
- package/dist/plugins/signal-sync.js +91 -0
- package/dist/plugins/timeout.d.ts +37 -0
- package/dist/plugins/timeout.js +59 -0
- package/dist/procedure-client.d.ts +19 -0
- package/dist/procedure-client.js +175 -0
- package/dist/procedure-decorated.d.ts +10 -0
- package/dist/procedure-decorated.js +44 -0
- package/dist/procedure-utils.d.ts +41 -0
- package/dist/procedure-utils.js +49 -0
- package/dist/procedure.d.ts +72 -0
- package/dist/procedure.js +24 -0
- package/dist/router-client.d.ts +23 -0
- package/dist/router-client.js +43 -0
- package/dist/{router-hidden.d.mts → router-hidden.d.ts} +3 -3
- package/dist/router-hidden.js +14 -0
- package/dist/router-utils.d.ts +48 -0
- package/dist/router-utils.js +202 -0
- package/dist/router.d.ts +72 -0
- package/package.json +84 -86
- package/dist/adapters/aws-lambda/handler.d.mts +0 -25
- package/dist/adapters/aws-lambda/handler.mjs +0 -21
- package/dist/adapters/aws-lambda/index.d.mts +0 -16
- package/dist/adapters/aws-lambda/index.mjs +0 -2
- package/dist/adapters/aws-lambda/rpc-handler.d.mts +0 -18
- package/dist/adapters/aws-lambda/rpc-handler.mjs +0 -10
- package/dist/adapters/crossws/handler.d.mts +0 -41
- package/dist/adapters/crossws/handler.mjs +0 -38
- package/dist/adapters/crossws/index.d.mts +0 -2
- package/dist/adapters/crossws/index.mjs +0 -2
- package/dist/adapters/crossws/rpc-handler.d.mts +0 -15
- package/dist/adapters/crossws/rpc-handler.mjs +0 -10
- package/dist/adapters/fastify/handler.d.mts +0 -21
- package/dist/adapters/fastify/handler.mjs +0 -20
- package/dist/adapters/fastify/index.d.mts +0 -2
- package/dist/adapters/fastify/index.mjs +0 -2
- package/dist/adapters/fastify/rpc-handler.d.mts +0 -14
- package/dist/adapters/fastify/rpc-handler.mjs +0 -10
- package/dist/adapters/fetch/handler.d.mts +0 -23
- package/dist/adapters/fetch/handler.mjs +0 -22
- package/dist/adapters/fetch/index.d.mts +0 -7
- package/dist/adapters/fetch/index.mjs +0 -5
- package/dist/adapters/fetch/rpc-handler.d.mts +0 -16
- package/dist/adapters/fetch/rpc-handler.mjs +0 -10
- package/dist/adapters/message-port/handler.d.mts +0 -57
- package/dist/adapters/message-port/handler.mjs +0 -62
- package/dist/adapters/message-port/index.d.mts +0 -2
- package/dist/adapters/message-port/index.mjs +0 -2
- package/dist/adapters/message-port/rpc-handler.d.mts +0 -15
- package/dist/adapters/message-port/rpc-handler.mjs +0 -10
- package/dist/adapters/node/handler.d.mts +0 -21
- package/dist/adapters/node/handler.mjs +0 -20
- package/dist/adapters/node/index.d.mts +0 -7
- package/dist/adapters/node/index.mjs +0 -5
- package/dist/adapters/node/rpc-handler.d.mts +0 -15
- package/dist/adapters/node/rpc-handler.mjs +0 -10
- package/dist/adapters/standard/codec.d.mts +0 -16
- package/dist/adapters/standard/handler.d.mts +0 -68
- package/dist/adapters/standard/handler.mjs +0 -185
- package/dist/adapters/standard/index.d.mts +0 -6
- package/dist/adapters/standard/index.mjs +0 -5
- package/dist/adapters/standard/plugin.d.mts +0 -32
- package/dist/adapters/standard/plugin.mjs +0 -16
- package/dist/adapters/standard/rpc-handler-codec.d.mts +0 -42
- package/dist/adapters/standard/rpc-handler-codec.mjs +0 -51
- package/dist/adapters/standard/rpc-matcher.d.mts +0 -53
- package/dist/adapters/standard/rpc-matcher.mjs +0 -140
- package/dist/adapters/standard/utils.d.mts +0 -10
- package/dist/adapters/standard/utils.mjs +0 -6
- package/dist/adapters/standard-peer/index.d.mts +0 -1
- package/dist/adapters/standard-peer/index.mjs +0 -1
- package/dist/adapters/standard-peer/utils.mjs +0 -11
- package/dist/adapters/websocket/handler.d.mts +0 -55
- package/dist/adapters/websocket/handler.mjs +0 -55
- package/dist/adapters/websocket/index.d.mts +0 -2
- package/dist/adapters/websocket/index.mjs +0 -2
- package/dist/adapters/websocket/rpc-handler.d.mts +0 -15
- package/dist/adapters/websocket/rpc-handler.mjs +0 -10
- package/dist/builder-variants.d.mts +0 -267
- package/dist/builder.d.mts +0 -141
- package/dist/builder.mjs +0 -145
- package/dist/context.d.mts +0 -13
- package/dist/extensions/callable.d.mts +0 -17
- package/dist/extensions/callable.mjs +0 -7
- package/dist/helpers/base64url.d.mts +0 -31
- package/dist/helpers/base64url.mjs +0 -25
- package/dist/helpers/cookie.d.mts +0 -50
- package/dist/helpers/cookie.mjs +0 -35
- package/dist/helpers/encryption.d.mts +0 -28
- package/dist/helpers/encryption.mjs +0 -62
- package/dist/helpers/index.d.mts +0 -4
- package/dist/helpers/index.mjs +0 -4
- package/dist/helpers/signing.d.mts +0 -50
- package/dist/helpers/signing.mjs +0 -43
- package/dist/implementer-procedure.d.mts +0 -36
- package/dist/implementer-procedure.mjs +0 -38
- package/dist/implementer-router.d.mts +0 -78
- package/dist/implementer-router.mjs +0 -77
- package/dist/implementer.d.mts +0 -22
- package/dist/implementer.mjs +0 -30
- package/dist/index.d.mts +0 -57
- package/dist/index.mjs +0 -30
- package/dist/lazy.d.mts +0 -20
- package/dist/lazy.mjs +0 -22
- package/dist/middleware-decorated.d.mts +0 -27
- package/dist/middleware-decorated.mjs +0 -65
- package/dist/middleware.d.mts +0 -70
- package/dist/plugins/batch.d.mts +0 -104
- package/dist/plugins/batch.mjs +0 -373
- package/dist/plugins/cors.d.mts +0 -67
- package/dist/plugins/cors.mjs +0 -134
- package/dist/plugins/get-method-csrf-protection.d.mts +0 -23
- package/dist/plugins/get-method-csrf-protection.mjs +0 -45
- package/dist/plugins/head-method.d.mts +0 -23
- package/dist/plugins/head-method.mjs +0 -95
- package/dist/plugins/index.d.mts +0 -39
- package/dist/plugins/index.mjs +0 -23
- package/dist/plugins/method-override.d.mts +0 -38
- package/dist/plugins/method-override.mjs +0 -50
- package/dist/plugins/request-compression.d.mts +0 -16
- package/dist/plugins/request-compression.mjs +0 -67
- package/dist/plugins/request-headers.d.mts +0 -22
- package/dist/plugins/request-headers.mjs +0 -21
- package/dist/plugins/request-limit.d.mts +0 -30
- package/dist/plugins/request-limit.mjs +0 -53
- package/dist/plugins/response-compression.d.mts +0 -59
- package/dist/plugins/response-compression.mjs +0 -172
- package/dist/plugins/response-headers.d.mts +0 -30
- package/dist/plugins/response-headers.mjs +0 -34
- package/dist/plugins/rethrow.d.mts +0 -33
- package/dist/plugins/rethrow.mjs +0 -46
- package/dist/plugins/signal-sync.d.mts +0 -13
- package/dist/plugins/signal-sync.mjs +0 -84
- package/dist/plugins/timeout.d.mts +0 -37
- package/dist/plugins/timeout.mjs +0 -56
- package/dist/procedure-client.d.mts +0 -41
- package/dist/procedure-client.mjs +0 -157
- package/dist/procedure-decorated.d.mts +0 -20
- package/dist/procedure-decorated.mjs +0 -41
- package/dist/procedure-utils.d.mts +0 -52
- package/dist/procedure-utils.mjs +0 -33
- package/dist/procedure.d.mts +0 -93
- package/dist/procedure.mjs +0 -20
- package/dist/router-client.d.mts +0 -27
- package/dist/router-client.mjs +0 -35
- package/dist/router-hidden.mjs +0 -12
- package/dist/router-utils.d.mts +0 -59
- package/dist/router-utils.mjs +0 -191
- package/dist/router.d.mts +0 -61
- /package/dist/adapters/standard/{codec.mjs → codec.js} +0 -0
- /package/dist/{builder-variants.mjs → builder-variants.js} +0 -0
- /package/dist/{constants.d.mts → constants.d.ts} +0 -0
- /package/dist/{constants.mjs → constants.js} +0 -0
- /package/dist/{context.mjs → context.js} +0 -0
- /package/dist/{middleware.mjs → middleware.js} +0 -0
- /package/dist/{router.mjs → router.js} +0 -0
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { Arrayable, MaybeOptionalOptions } from "@orpc/shared";
|
|
2
|
-
import type { DecodePeerMessageOptions, EncodePeerMessageOptions } from "@standard-server/peer";
|
|
3
|
-
import type { Context } from "../../context.mjs";
|
|
4
|
-
import type { FriendlyStandardHandlerHandleOptions, StandardHandler } from "../standard/index.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* Supports standard WebSocket instances, Bun ServerWebSocket, "ws" ServerWebSocket,
|
|
7
|
-
* Cloudflare WebSocket Hibernation, and similar implementations.
|
|
8
|
-
*/
|
|
9
|
-
export type WebSocketLike = {
|
|
10
|
-
send: (data: string | Uint8Array<ArrayBuffer>) => unknown;
|
|
11
|
-
};
|
|
12
|
-
export interface WebSocketHandlerOptions<_T extends Context> {
|
|
13
|
-
/**
|
|
14
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
15
|
-
*/
|
|
16
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
19
|
-
*/
|
|
20
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
21
|
-
}
|
|
22
|
-
export declare class WebSocketHandler<T extends Context> {
|
|
23
|
-
private readonly handler;
|
|
24
|
-
private readonly peers;
|
|
25
|
-
private readonly encodePeerMessageOptions;
|
|
26
|
-
private readonly decodePeerMessageOptions;
|
|
27
|
-
constructor(handler: StandardHandler<T>, options?: NoInfer<WebSocketHandlerOptions<T>>);
|
|
28
|
-
/**
|
|
29
|
-
* Handles a single WebSocket message.
|
|
30
|
-
*
|
|
31
|
-
* Message order matters. Call this immediately after receiving a message,
|
|
32
|
-
* before any other async work, to preserve ordering.
|
|
33
|
-
*
|
|
34
|
-
* To avoid async Blob reads, configure `ws.binaryType` to return binary data
|
|
35
|
-
* directly (for example, `arraybuffer`).
|
|
36
|
-
*
|
|
37
|
-
* @param ws The WebSocket instance. Use the same instance for all messages.
|
|
38
|
-
* @param data The received message. Binary data should already be loaded (not a `Blob`).
|
|
39
|
-
*/
|
|
40
|
-
message(ws: WebSocketLike, data: Arrayable<string | ArrayBuffer | Pick<Uint8Array<ArrayBuffer>, "buffer" | "byteOffset" | "byteLength">>, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): Promise<{
|
|
41
|
-
matched: boolean;
|
|
42
|
-
}>;
|
|
43
|
-
/**
|
|
44
|
-
* Cleans up peer state for a closed WebSocket.
|
|
45
|
-
*
|
|
46
|
-
* @param ws The same WebSocket instance passed to `.message()`.
|
|
47
|
-
*/
|
|
48
|
-
close(ws: WebSocketLike): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Attaches message, close, and error event listeners to a WebSocket.
|
|
51
|
-
*
|
|
52
|
-
* Prefer this over calling `.message()` and `.close()` manually.
|
|
53
|
-
*/
|
|
54
|
-
upgrade(ws: Pick<WebSocket, "send" | "addEventListener" | "removeEventListener">, ...rest: MaybeOptionalOptions<FriendlyStandardHandlerHandleOptions<T>>): void;
|
|
55
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { loadBytes, resolveMaybeOptionalOptions, sequential, toStringOrBytes } from "@orpc/shared";
|
|
2
|
-
import { decodePeerMessage, encodePeerMessage, isClientPeerSendMessage, ServerPeer } from "@standard-server/peer";
|
|
3
|
-
import { createStandardPeerRequestHandler } from "../standard-peer/index.mjs";
|
|
4
|
-
export class WebSocketHandler {
|
|
5
|
-
handler;
|
|
6
|
-
peers = new WeakMap();
|
|
7
|
-
encodePeerMessageOptions;
|
|
8
|
-
decodePeerMessageOptions;
|
|
9
|
-
constructor(handler, options = {}) {
|
|
10
|
-
this.handler = handler;
|
|
11
|
-
this.encodePeerMessageOptions = options.encodePeerMessage;
|
|
12
|
-
this.decodePeerMessageOptions = options.decodePeerMessage;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async message(ws, data, ...rest) {
|
|
16
|
-
let peer = this.peers.get(ws);
|
|
17
|
-
if (!peer) {
|
|
18
|
-
this.peers.set(ws, peer = new ServerPeer(async (message) => {
|
|
19
|
-
const encoded = await encodePeerMessage(message, this.encodePeerMessageOptions);
|
|
20
|
-
await ws.send(encoded);
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const encoded = toStringOrBytes(data);
|
|
25
|
-
const result = decodePeerMessage(encoded, this.decodePeerMessageOptions);
|
|
26
|
-
if (result.matched && isClientPeerSendMessage(result.message)) {
|
|
27
|
-
await peer.message(result.message, createStandardPeerRequestHandler(this.handler, resolveMaybeOptionalOptions(rest)));
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async close(ws) {
|
|
33
|
-
const peer = this.peers.get(ws);
|
|
34
|
-
if (peer) {
|
|
35
|
-
|
|
36
|
-
this.peers.delete(ws);
|
|
37
|
-
await peer.close();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
upgrade(ws, ...rest) {
|
|
42
|
-
|
|
43
|
-
ws.addEventListener("message", sequential(async (event) => {
|
|
44
|
-
|
|
45
|
-
const data = event.data instanceof Blob ? await loadBytes(event.data) : event.data;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.message(ws, data, ...rest);
|
|
49
|
-
}));
|
|
50
|
-
ws.addEventListener("close", () => this.close(ws));
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ws.addEventListener("error", () => {});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../../context.mjs";
|
|
2
|
-
import type { Router } from "../../router.mjs";
|
|
3
|
-
import type { RPCHandlerCodecOptions, StandardHandlerOptions } from "../standard/index.mjs";
|
|
4
|
-
import type { WebSocketHandlerOptions } from "./handler.mjs";
|
|
5
|
-
import { WebSocketHandler } from "./handler.mjs";
|
|
6
|
-
export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, RPCHandlerCodecOptions<T>, WebSocketHandlerOptions<T> {}
|
|
7
|
-
/**
|
|
8
|
-
* Serves an oRPC router over the RPC protocol on a standard WebSocket
|
|
9
|
-
* connection (Deno, Bun, Cloudflare Durable Objects, and more).
|
|
10
|
-
*
|
|
11
|
-
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
12
|
-
*/
|
|
13
|
-
export declare class RPCHandler<T extends Context> extends WebSocketHandler<T> {
|
|
14
|
-
constructor(router: Router<T>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
15
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RPCHandlerCodec, StandardHandler } from "../standard/index.mjs";
|
|
2
|
-
import { WebSocketHandler } from "./handler.mjs";
|
|
3
|
-
|
|
4
|
-
export class RPCHandler extends WebSocketHandler {
|
|
5
|
-
constructor(router, options = {}) {
|
|
6
|
-
const codec = new RPCHandlerCodec(router, options);
|
|
7
|
-
const handler = new StandardHandler(codec, options);
|
|
8
|
-
super(handler, options);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import type { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MergedSchema, MetaPlugin, ORPCErrorConstructorMap, Schema } from "@orpc/contract";
|
|
2
|
-
import type { IntersectPick } from "@orpc/shared";
|
|
3
|
-
import type { BuilderDefinition } from "./builder.mjs";
|
|
4
|
-
import type { Context, MergedContext, MergedInitialContext } from "./context.mjs";
|
|
5
|
-
import type { Lazy } from "./lazy.mjs";
|
|
6
|
-
import type { Middleware } from "./middleware.mjs";
|
|
7
|
-
import type { DecoratedMiddleware } from "./middleware-decorated.mjs";
|
|
8
|
-
import type { ProcedureHandler } from "./procedure.mjs";
|
|
9
|
-
import type { DecoratedProcedure } from "./procedure-decorated.mjs";
|
|
10
|
-
import type { Router } from "./router.mjs";
|
|
11
|
-
import type { AugmentedRouterWithMiddlewares } from "./router-utils.mjs";
|
|
12
|
-
/**
|
|
13
|
-
* The builder variant returned after `.use` is called.
|
|
14
|
-
* `.$context` and `.$config` are no longer available once middleware is applied.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
17
|
-
*/
|
|
18
|
-
export interface BuilderWithMiddlewares<
|
|
19
|
-
TInitialContext extends Context,
|
|
20
|
-
TInjectedContext extends Context,
|
|
21
|
-
TErrorMap extends ErrorMap
|
|
22
|
-
> {
|
|
23
|
-
"~orpc": BuilderDefinition<InitialInputSchema, InitialOutputSchema, TErrorMap>;
|
|
24
|
-
/**
|
|
25
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
26
|
-
*
|
|
27
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
28
|
-
*/
|
|
29
|
-
"meta"(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): BuilderWithMiddlewares<TInitialContext, TInjectedContext, TErrorMap>;
|
|
30
|
-
/**
|
|
31
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
32
|
-
* via the `errors` utility in handlers and middleware.
|
|
33
|
-
*
|
|
34
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
35
|
-
*/
|
|
36
|
-
"errors"<T extends ErrorMap>(errors: T): BuilderWithMiddlewares<TInitialContext, TInjectedContext, MergedErrorMap<TErrorMap, T>>;
|
|
37
|
-
/**
|
|
38
|
-
* Applies a middleware that runs before the handler of every procedure
|
|
39
|
-
* built from this builder.
|
|
40
|
-
*
|
|
41
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
42
|
-
*/
|
|
43
|
-
"use"<
|
|
44
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
45
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
46
|
-
$ErrorMap extends ErrorMap = TErrorMap
|
|
47
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
48
|
-
/**
|
|
49
|
-
* Creates a standalone middleware that can be composed and applied to any
|
|
50
|
-
* compatible builder or procedure with `.use`.
|
|
51
|
-
*
|
|
52
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
53
|
-
*/
|
|
54
|
-
"middleware"<
|
|
55
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
56
|
-
$Input,
|
|
57
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
58
|
-
$Output = any
|
|
59
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, $Input, $Output, TErrorMap>): DecoratedMiddleware<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, $Input, $Output, TErrorMap>;
|
|
60
|
-
/**
|
|
61
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
62
|
-
*
|
|
63
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
64
|
-
*/
|
|
65
|
-
"input"<T extends AnySchema>(schema: T): BuilderWithInput<TInitialContext, TInjectedContext, T, TErrorMap>;
|
|
66
|
-
/**
|
|
67
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
68
|
-
*
|
|
69
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
70
|
-
*/
|
|
71
|
-
"output"<T extends AnySchema>(schema: T): BuilderWithOutput<TInitialContext, TInjectedContext, T, TErrorMap>;
|
|
72
|
-
/**
|
|
73
|
-
* Defines the function that implements the procedure and completes the
|
|
74
|
-
* chain, returning a callable procedure.
|
|
75
|
-
*
|
|
76
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
77
|
-
*/
|
|
78
|
-
"handler"<T>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, Schema<T>, TErrorMap>;
|
|
79
|
-
/**
|
|
80
|
-
* Applies the builder's middleware, errors, and metadata to every procedure
|
|
81
|
-
* in the given router.
|
|
82
|
-
*
|
|
83
|
-
* @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
|
|
84
|
-
*/
|
|
85
|
-
"router"<T extends Router<MergedContext<TInitialContext, TInjectedContext>>>(router: T): AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, TErrorMap>;
|
|
86
|
-
/**
|
|
87
|
-
* Like `.router`, but loads the router lazily on first access, which helps
|
|
88
|
-
* reduce startup time for large applications.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
|
|
91
|
-
*/
|
|
92
|
-
"lazy"<T extends Router<MergedContext<TInitialContext, TInjectedContext>>>(loader: () => Promise<{
|
|
93
|
-
default: T;
|
|
94
|
-
}>): Lazy<AugmentedRouterWithMiddlewares<T, TInitialContext, TInjectedContext, TErrorMap>>;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The builder variant returned after `.input` is called.
|
|
98
|
-
* Only procedure-level methods remain available once an input schema is defined.
|
|
99
|
-
*
|
|
100
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
101
|
-
*/
|
|
102
|
-
export interface BuilderWithInput<
|
|
103
|
-
TInitialContext extends Context,
|
|
104
|
-
TInjectedContext extends Context,
|
|
105
|
-
TInputSchema extends AnySchema,
|
|
106
|
-
TErrorMap extends ErrorMap
|
|
107
|
-
> {
|
|
108
|
-
"~orpc": BuilderDefinition<TInputSchema, InitialOutputSchema, TErrorMap>;
|
|
109
|
-
/**
|
|
110
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
111
|
-
*
|
|
112
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
113
|
-
*/
|
|
114
|
-
"meta"(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, TErrorMap>;
|
|
115
|
-
/**
|
|
116
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
117
|
-
* via the `errors` utility in handlers and middleware.
|
|
118
|
-
*
|
|
119
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
120
|
-
*/
|
|
121
|
-
"errors"<T extends ErrorMap>(errors: T): BuilderWithInput<TInitialContext, TInjectedContext, TInputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
122
|
-
/**
|
|
123
|
-
* Applies a middleware that runs before the handler and can access the
|
|
124
|
-
* validated input.
|
|
125
|
-
*
|
|
126
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
127
|
-
*/
|
|
128
|
-
"use"<
|
|
129
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
130
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
131
|
-
$ErrorMap extends ErrorMap = TErrorMap
|
|
132
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithInput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
133
|
-
/**
|
|
134
|
-
* Adds an additional input schema, merged with the previously defined one.
|
|
135
|
-
*
|
|
136
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
137
|
-
*/
|
|
138
|
-
"input"<T extends AnySchema>(schema: T): BuilderWithInput<TInitialContext, TInjectedContext, MergedSchema<T, TInputSchema>, TErrorMap>;
|
|
139
|
-
/**
|
|
140
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
141
|
-
*
|
|
142
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
143
|
-
*/
|
|
144
|
-
"output"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, T, TErrorMap>;
|
|
145
|
-
/**
|
|
146
|
-
* Defines the function that implements the procedure and completes the
|
|
147
|
-
* chain, returning a callable procedure.
|
|
148
|
-
*
|
|
149
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
150
|
-
*/
|
|
151
|
-
"handler"<T>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, Schema<T>, TErrorMap>;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* The builder variant returned after `.output` is called.
|
|
155
|
-
* Only procedure-level methods remain available once an output schema is defined.
|
|
156
|
-
*
|
|
157
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
158
|
-
*/
|
|
159
|
-
export interface BuilderWithOutput<
|
|
160
|
-
TInitialContext extends Context,
|
|
161
|
-
TInjectedContext extends Context,
|
|
162
|
-
TOutputSchema extends AnySchema,
|
|
163
|
-
TErrorMap extends ErrorMap
|
|
164
|
-
> {
|
|
165
|
-
"~orpc": BuilderDefinition<InitialInputSchema, TOutputSchema, TErrorMap>;
|
|
166
|
-
/**
|
|
167
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
168
|
-
*
|
|
169
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
170
|
-
*/
|
|
171
|
-
"meta"(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, TErrorMap>;
|
|
172
|
-
/**
|
|
173
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
174
|
-
* via the `errors` utility in handlers and middleware.
|
|
175
|
-
*
|
|
176
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
177
|
-
*/
|
|
178
|
-
"errors"<T extends ErrorMap>(errors: T): BuilderWithOutput<TInitialContext, TInjectedContext, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
179
|
-
/**
|
|
180
|
-
* Applies a middleware that runs before the handler and can access the
|
|
181
|
-
* typed output.
|
|
182
|
-
*
|
|
183
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
184
|
-
*/
|
|
185
|
-
"use"<
|
|
186
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
187
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
188
|
-
$ErrorMap extends ErrorMap = TErrorMap
|
|
189
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): BuilderWithOutput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
190
|
-
/**
|
|
191
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
192
|
-
*
|
|
193
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
194
|
-
*/
|
|
195
|
-
"input"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, T, TOutputSchema, TErrorMap>;
|
|
196
|
-
/**
|
|
197
|
-
* Adds an additional output schema, merged with the previously defined one.
|
|
198
|
-
*
|
|
199
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
200
|
-
*/
|
|
201
|
-
"output"<T extends AnySchema>(schema: T): BuilderWithOutput<TInitialContext, TInjectedContext, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
202
|
-
/**
|
|
203
|
-
* Defines the function that implements the procedure and completes the
|
|
204
|
-
* chain, returning a callable procedure.
|
|
205
|
-
*
|
|
206
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
207
|
-
*/
|
|
208
|
-
"handler"<T extends InferSchemaInput<TOutputSchema>>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, InitialInputSchema, TOutputSchema, TErrorMap>;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* The builder variant returned after both `.input` and `.output` are called.
|
|
212
|
-
* Only procedure-level methods remain available.
|
|
213
|
-
*
|
|
214
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
215
|
-
*/
|
|
216
|
-
export interface BuilderWithInputOutput<
|
|
217
|
-
TInitialContext extends Context,
|
|
218
|
-
TInjectedContext extends Context,
|
|
219
|
-
TInputSchema extends AnySchema,
|
|
220
|
-
TOutputSchema extends AnySchema,
|
|
221
|
-
TErrorMap extends ErrorMap
|
|
222
|
-
> {
|
|
223
|
-
"~orpc": BuilderDefinition<TInputSchema, TOutputSchema, TErrorMap>;
|
|
224
|
-
/**
|
|
225
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
226
|
-
*
|
|
227
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
228
|
-
*/
|
|
229
|
-
"meta"(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
230
|
-
/**
|
|
231
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
232
|
-
* via the `errors` utility in handlers and middleware.
|
|
233
|
-
*
|
|
234
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
235
|
-
*/
|
|
236
|
-
"errors"<T extends ErrorMap>(errors: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
237
|
-
/**
|
|
238
|
-
* Applies a middleware that runs before the handler and can access the
|
|
239
|
-
* validated input and typed output.
|
|
240
|
-
*
|
|
241
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
242
|
-
*/
|
|
243
|
-
"use"<
|
|
244
|
-
$OutContext extends IntersectPick<MergedContext<TInitialContext, TInjectedContext>, $OutContext>,
|
|
245
|
-
$InContext extends Context = MergedContext<TInitialContext, TInjectedContext>,
|
|
246
|
-
$ErrorMap extends ErrorMap = TErrorMap
|
|
247
|
-
>(middleware: Middleware<$InContext | MergedContext<TInitialContext, TInjectedContext>, $OutContext, InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>, $ErrorMap>): BuilderWithInputOutput<MergedInitialContext<TInitialContext, TInjectedContext, $InContext>, MergedContext<TInjectedContext, $OutContext>, TInputSchema, TOutputSchema, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
248
|
-
/**
|
|
249
|
-
* Adds an additional input schema, merged with the previously defined one.
|
|
250
|
-
*
|
|
251
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
252
|
-
*/
|
|
253
|
-
"input"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
|
|
254
|
-
/**
|
|
255
|
-
* Adds an additional output schema, merged with the previously defined one.
|
|
256
|
-
*
|
|
257
|
-
* @see {@link https://orpc.dev/docs/procedure#multiple-schemas | Procedure - Multiple Schemas}
|
|
258
|
-
*/
|
|
259
|
-
"output"<T extends AnySchema>(schema: T): BuilderWithInputOutput<TInitialContext, TInjectedContext, TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
260
|
-
/**
|
|
261
|
-
* Defines the function that implements the procedure and completes the
|
|
262
|
-
* chain, returning a callable procedure.
|
|
263
|
-
*
|
|
264
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
265
|
-
*/
|
|
266
|
-
"handler"<T extends InferSchemaInput<TOutputSchema>>(handler: ProcedureHandler<MergedContext<TInitialContext, TInjectedContext>, InferSchemaOutput<TInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
267
|
-
}
|
package/dist/builder.d.mts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, InitialInputSchema, InitialOutputSchema, MergedErrorMap, MetaPlugin, ORPCErrorConstructorMap, ProcedureContractDefinition, Schema } from "@orpc/contract";
|
|
2
|
-
import type { IntersectPick } from "@orpc/shared";
|
|
3
|
-
import type { BuilderWithInput, BuilderWithMiddlewares, BuilderWithOutput } from "./builder-variants.mjs";
|
|
4
|
-
import type { Context, MergedInitialContext } from "./context.mjs";
|
|
5
|
-
import type { Middleware } from "./middleware.mjs";
|
|
6
|
-
import type { DecoratedMiddleware } from "./middleware-decorated.mjs";
|
|
7
|
-
import type { OrderedMiddleware, ProcedureConfig, ProcedureHandler } from "./procedure.mjs";
|
|
8
|
-
import type { AnyRouter } from "./router.mjs";
|
|
9
|
-
import type { AugmentedRouter } from "./router-utils.mjs";
|
|
10
|
-
import { Lazy } from "./lazy.mjs";
|
|
11
|
-
import { DecoratedProcedure } from "./procedure-decorated.mjs";
|
|
12
|
-
/**
|
|
13
|
-
* The initial context type used when `.$context` is not called.
|
|
14
|
-
* Augment this interface with `declare module '@orpc/server'` to define
|
|
15
|
-
* a default initial context type globally.
|
|
16
|
-
*
|
|
17
|
-
* @see {@link https://orpc.dev/docs/context#default-initial-context | Context - Default Initial Context}
|
|
18
|
-
*/
|
|
19
|
-
export interface DefaultInitialContext {}
|
|
20
|
-
export interface BuilderDefinition<
|
|
21
|
-
TInputSchema extends AnySchema,
|
|
22
|
-
TInjectedContext extends AnySchema,
|
|
23
|
-
TErrorMap extends ErrorMap
|
|
24
|
-
> extends ProcedureContractDefinition<TInputSchema, TInjectedContext, TErrorMap>, ProcedureConfig {
|
|
25
|
-
orderedMiddlewares: OrderedMiddleware[];
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* The procedure builder behind `os`. Chain its methods to gradually define
|
|
29
|
-
* context, middleware, errors, schemas, and finally a handler or router.
|
|
30
|
-
*
|
|
31
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
32
|
-
*/
|
|
33
|
-
export declare class Builder<
|
|
34
|
-
TInitialContext extends Context,
|
|
35
|
-
TErrorMap extends ErrorMap
|
|
36
|
-
> {
|
|
37
|
-
"~orpc": BuilderDefinition<InitialInputSchema, InitialOutputSchema, TErrorMap>;
|
|
38
|
-
/**
|
|
39
|
-
* Private constructor to prevent direct instantiation.
|
|
40
|
-
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
41
|
-
*/
|
|
42
|
-
private constructor();
|
|
43
|
-
/**
|
|
44
|
-
* Creates a fresh builder with an empty definition.
|
|
45
|
-
* Prefer the exported `os` instance over calling this directly.
|
|
46
|
-
*
|
|
47
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
48
|
-
*/
|
|
49
|
-
static create<T extends Context = DefaultInitialContext>(): Builder<T & object, Record<never, never>>;
|
|
50
|
-
/**
|
|
51
|
-
* Declares the initial context type that must be provided when executing
|
|
52
|
-
* procedures built from this builder.
|
|
53
|
-
*
|
|
54
|
-
* @see {@link https://orpc.dev/docs/context#initial-context | Context - Initial Context}
|
|
55
|
-
*/
|
|
56
|
-
$context<T extends Context = DefaultInitialContext>(): Builder<T & object, TErrorMap>;
|
|
57
|
-
/**
|
|
58
|
-
* Overrides the procedure configuration, such as disabling runtime
|
|
59
|
-
* input/output validation.
|
|
60
|
-
*
|
|
61
|
-
* @see {@link https://orpc.dev/docs/recipes/validation-customization | Validation Customization}
|
|
62
|
-
*/
|
|
63
|
-
$config(config: ProcedureConfig): Builder<TInitialContext, TErrorMap>;
|
|
64
|
-
/**
|
|
65
|
-
* Applies metadata plugins to procedures built from this builder.
|
|
66
|
-
*
|
|
67
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
68
|
-
*/
|
|
69
|
-
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): Builder<TInitialContext, TErrorMap>;
|
|
70
|
-
/**
|
|
71
|
-
* Defines typesafe errors that procedures built from this builder can throw
|
|
72
|
-
* via the `errors` utility in handlers and middleware.
|
|
73
|
-
*
|
|
74
|
-
* @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
|
|
75
|
-
*/
|
|
76
|
-
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, MergedErrorMap<TErrorMap, U>>;
|
|
77
|
-
/**
|
|
78
|
-
* Applies a middleware that runs before the handler of every procedure
|
|
79
|
-
* built from this builder.
|
|
80
|
-
*
|
|
81
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
82
|
-
*/
|
|
83
|
-
use<
|
|
84
|
-
$OutContext extends IntersectPick<TInitialContext, $OutContext>,
|
|
85
|
-
$InContext extends Context = TInitialContext,
|
|
86
|
-
$ErrorMap extends ErrorMap = TErrorMap
|
|
87
|
-
>(middleware: Middleware<$InContext | TInitialContext, $OutContext, InferSchemaOutput<InitialInputSchema>, InferSchemaInput<InitialOutputSchema>, $ErrorMap>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, object, $InContext>, $OutContext, MergedErrorMap<$ErrorMap, TErrorMap>>;
|
|
88
|
-
/**
|
|
89
|
-
* Creates a standalone middleware that can be composed and applied to any
|
|
90
|
-
* compatible builder or procedure with `.use`.
|
|
91
|
-
*
|
|
92
|
-
* @see {@link https://orpc.dev/docs/middleware | Middleware}
|
|
93
|
-
*/
|
|
94
|
-
middleware<
|
|
95
|
-
$OutContext extends IntersectPick<TInitialContext, $OutContext>,
|
|
96
|
-
$Input,
|
|
97
|
-
$Output = any
|
|
98
|
-
>(middleware: Middleware<TInitialContext, $OutContext, $Input, $Output, TErrorMap>): DecoratedMiddleware<TInitialContext, $OutContext, $Input, $Output, TErrorMap>;
|
|
99
|
-
/**
|
|
100
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
101
|
-
*
|
|
102
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
103
|
-
*/
|
|
104
|
-
input<$ extends AnySchema>(schema: $): BuilderWithInput<TInitialContext, object, $, TErrorMap>;
|
|
105
|
-
/**
|
|
106
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
107
|
-
*
|
|
108
|
-
* @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
|
|
109
|
-
*/
|
|
110
|
-
output<$ extends AnySchema>(schema: $): BuilderWithOutput<TInitialContext, object, $, TErrorMap>;
|
|
111
|
-
/**
|
|
112
|
-
* Defines the function that implements the procedure and completes the
|
|
113
|
-
* chain, returning a callable procedure.
|
|
114
|
-
*
|
|
115
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
116
|
-
*/
|
|
117
|
-
handler<T>(handler: ProcedureHandler<TInitialContext, InferSchemaOutput<InitialInputSchema>, T, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TInitialContext, object, InitialInputSchema, Schema<T>, TErrorMap>;
|
|
118
|
-
/**
|
|
119
|
-
* Applies the builder's middleware, errors, and metadata to every procedure
|
|
120
|
-
* in the given router.
|
|
121
|
-
*
|
|
122
|
-
* @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
|
|
123
|
-
*/
|
|
124
|
-
router<T extends AnyRouter>(router: T): AugmentedRouter<T, TErrorMap>;
|
|
125
|
-
/**
|
|
126
|
-
* Like `.router`, but loads the router lazily on first access, which helps
|
|
127
|
-
* reduce startup time for large applications.
|
|
128
|
-
*
|
|
129
|
-
* @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
|
|
130
|
-
*/
|
|
131
|
-
lazy<T extends AnyRouter>(loader: () => Promise<{
|
|
132
|
-
default: T;
|
|
133
|
-
}>): Lazy<AugmentedRouter<T, TErrorMap>>;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* The oRPC procedure builder. Chain methods like `.input`, `.use`, and `.handler`
|
|
137
|
-
* to define procedures, then compose them into routers.
|
|
138
|
-
*
|
|
139
|
-
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
140
|
-
*/
|
|
141
|
-
export declare const os: Builder<DefaultInitialContext & object, Record<never, never>>;
|