@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.caefe3a
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-M65OCXNG.js +136 -0
- package/dist/chunk-OEPDHGQ4.js +378 -0
- package/dist/chunk-OWMUECGT.js +111 -0
- package/dist/chunk-PZ44ZPVC.js +308 -0
- package/dist/fetch.js +14 -102
- package/dist/hono.js +42 -0
- package/dist/index.js +332 -322
- package/dist/next.js +39 -0
- package/dist/node.js +175 -0
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +4 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +13 -0
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +13 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +20 -0
- package/dist/src/adapters/node/index.d.ts +4 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +21 -0
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +47 -0
- package/dist/src/adapters/standard/index.d.ts +7 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
- package/dist/src/adapters/standard/types.d.ts +44 -0
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +47 -39
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +8 -0
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +17 -0
- package/dist/src/implementer.d.ts +28 -0
- package/dist/src/index.d.ts +17 -9
- package/dist/src/lazy-utils.d.ts +6 -0
- package/dist/src/lazy.d.ts +22 -0
- package/dist/src/middleware-decorated.d.ts +10 -0
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +28 -17
- package/dist/src/plugins/base.d.ts +11 -0
- package/dist/src/plugins/cors.d.ts +18 -0
- package/dist/src/plugins/index.d.ts +4 -0
- package/dist/src/plugins/response-headers.d.ts +10 -0
- package/dist/src/procedure-client.d.ts +31 -0
- package/dist/src/procedure-decorated.d.ts +21 -0
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +25 -25
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +10 -0
- package/dist/src/router.d.ts +25 -16
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +17 -0
- package/package.json +34 -9
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -19
- package/dist/src/procedure-implementer.d.ts +0 -18
- package/dist/src/router-builder.d.ts +0 -22
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-implementer.d.ts +0 -20
- package/dist/src/types.d.ts +0 -8
package/dist/next.js
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
import {
|
2
|
+
RPCHandler,
|
3
|
+
fetchReToStandardBody,
|
4
|
+
fetchRequestToStandardRequest,
|
5
|
+
standardBodyToFetchBody,
|
6
|
+
standardResponseToFetchResponse
|
7
|
+
} from "./chunk-M65OCXNG.js";
|
8
|
+
import "./chunk-PZ44ZPVC.js";
|
9
|
+
import "./chunk-OEPDHGQ4.js";
|
10
|
+
import "./chunk-OWMUECGT.js";
|
11
|
+
|
12
|
+
// src/adapters/next/serve.ts
|
13
|
+
import { value } from "@orpc/shared";
|
14
|
+
function serve(handler, ...[options]) {
|
15
|
+
const main = async (req) => {
|
16
|
+
const context = await value(options?.context ?? {}, req);
|
17
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
18
|
+
if (matched) {
|
19
|
+
return response;
|
20
|
+
}
|
21
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
22
|
+
};
|
23
|
+
return {
|
24
|
+
GET: main,
|
25
|
+
POST: main,
|
26
|
+
PUT: main,
|
27
|
+
PATCH: main,
|
28
|
+
DELETE: main
|
29
|
+
};
|
30
|
+
}
|
31
|
+
export {
|
32
|
+
RPCHandler,
|
33
|
+
fetchReToStandardBody,
|
34
|
+
fetchRequestToStandardRequest,
|
35
|
+
serve,
|
36
|
+
standardBodyToFetchBody,
|
37
|
+
standardResponseToFetchResponse
|
38
|
+
};
|
39
|
+
//# sourceMappingURL=next.js.map
|
package/dist/node.js
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
import {
|
2
|
+
RPCCodec,
|
3
|
+
RPCMatcher,
|
4
|
+
StandardHandler
|
5
|
+
} from "./chunk-PZ44ZPVC.js";
|
6
|
+
import "./chunk-OEPDHGQ4.js";
|
7
|
+
import "./chunk-OWMUECGT.js";
|
8
|
+
|
9
|
+
// src/adapters/node/utils.ts
|
10
|
+
import { Buffer, File } from "node:buffer";
|
11
|
+
import { Readable } from "node:stream";
|
12
|
+
import { once } from "@orpc/shared";
|
13
|
+
import cd from "content-disposition";
|
14
|
+
function nodeHttpToStandardRequest(req, res) {
|
15
|
+
const method = req.method ?? "GET";
|
16
|
+
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
17
|
+
const host = req.headers.host ?? "localhost";
|
18
|
+
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
19
|
+
return {
|
20
|
+
raw: { request: req, response: res },
|
21
|
+
method,
|
22
|
+
url,
|
23
|
+
headers: req.headers,
|
24
|
+
body: once(() => {
|
25
|
+
return nodeHttpRequestToStandardBody(req);
|
26
|
+
}),
|
27
|
+
get signal() {
|
28
|
+
const signal = nodeHttpResponseToAbortSignal(res);
|
29
|
+
Object.defineProperty(this, "signal", { value: signal, writable: true });
|
30
|
+
return signal;
|
31
|
+
},
|
32
|
+
set signal(value) {
|
33
|
+
Object.defineProperty(this, "signal", { value, writable: true });
|
34
|
+
}
|
35
|
+
};
|
36
|
+
}
|
37
|
+
function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
38
|
+
return new Promise((resolve, reject) => {
|
39
|
+
res.on("error", reject);
|
40
|
+
res.on("finish", resolve);
|
41
|
+
if (standardResponse.body === void 0) {
|
42
|
+
res.writeHead(standardResponse.status, standardResponse.headers);
|
43
|
+
res.end();
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
if (standardResponse.body instanceof Blob) {
|
47
|
+
const resHeaders = {
|
48
|
+
...standardResponse.headers,
|
49
|
+
"content-type": standardResponse.body.type,
|
50
|
+
"content-length": standardResponse.body.size.toString()
|
51
|
+
};
|
52
|
+
if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
|
53
|
+
resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
|
54
|
+
}
|
55
|
+
res.writeHead(standardResponse.status, resHeaders);
|
56
|
+
Readable.fromWeb(
|
57
|
+
standardResponse.body.stream()
|
58
|
+
// Conflict between types=node and lib=dom so we need to cast it
|
59
|
+
).pipe(res);
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
if (standardResponse.body instanceof FormData) {
|
63
|
+
const response = new Response(standardResponse.body);
|
64
|
+
res.writeHead(standardResponse.status, {
|
65
|
+
...standardResponse.headers,
|
66
|
+
"content-type": response.headers.get("content-type")
|
67
|
+
});
|
68
|
+
Readable.fromWeb(
|
69
|
+
response.body
|
70
|
+
// Conflict between types=node and lib=dom so we need to cast it
|
71
|
+
).pipe(res);
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
if (standardResponse.body instanceof URLSearchParams) {
|
75
|
+
res.writeHead(standardResponse.status, {
|
76
|
+
...standardResponse.headers,
|
77
|
+
"content-type": "application/x-www-form-urlencoded"
|
78
|
+
});
|
79
|
+
const string2 = standardResponse.body.toString();
|
80
|
+
res.end(string2);
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
res.writeHead(standardResponse.status, {
|
84
|
+
...standardResponse.headers,
|
85
|
+
"content-type": "application/json"
|
86
|
+
});
|
87
|
+
const string = JSON.stringify(standardResponse.body);
|
88
|
+
res.end(string);
|
89
|
+
});
|
90
|
+
}
|
91
|
+
async function nodeHttpRequestToStandardBody(req) {
|
92
|
+
const method = req.method ?? "GET";
|
93
|
+
if (method === "GET" || method === "HEAD") {
|
94
|
+
return void 0;
|
95
|
+
}
|
96
|
+
const contentDisposition = req.headers["content-disposition"];
|
97
|
+
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
98
|
+
const contentType = req.headers["content-type"];
|
99
|
+
if (fileName) {
|
100
|
+
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
101
|
+
}
|
102
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
103
|
+
const text = await streamToString(req);
|
104
|
+
if (!text) {
|
105
|
+
return void 0;
|
106
|
+
}
|
107
|
+
return JSON.parse(text);
|
108
|
+
}
|
109
|
+
if (contentType.startsWith("multipart/form-data")) {
|
110
|
+
return await streamToFormData(req, contentType);
|
111
|
+
}
|
112
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
113
|
+
const text = await streamToString(req);
|
114
|
+
return new URLSearchParams(text);
|
115
|
+
}
|
116
|
+
if (contentType.startsWith("text/")) {
|
117
|
+
return await streamToString(req);
|
118
|
+
}
|
119
|
+
return streamToFile(req, "blob", contentType);
|
120
|
+
}
|
121
|
+
function streamToFormData(stream, contentType) {
|
122
|
+
const response = new Response(stream, {
|
123
|
+
// Conflict between types=node and lib=dom so we need to cast it
|
124
|
+
headers: {
|
125
|
+
"content-type": contentType
|
126
|
+
}
|
127
|
+
});
|
128
|
+
return response.formData();
|
129
|
+
}
|
130
|
+
async function streamToString(stream) {
|
131
|
+
let string = "";
|
132
|
+
for await (const chunk of stream) {
|
133
|
+
string += chunk.toString();
|
134
|
+
}
|
135
|
+
return string;
|
136
|
+
}
|
137
|
+
async function streamToFile(stream, fileName, contentType) {
|
138
|
+
const chunks = [];
|
139
|
+
for await (const chunk of stream) {
|
140
|
+
chunks.push(chunk);
|
141
|
+
}
|
142
|
+
return new File([Buffer.concat(chunks)], fileName, { type: contentType });
|
143
|
+
}
|
144
|
+
function nodeHttpResponseToAbortSignal(res) {
|
145
|
+
const controller = new AbortController();
|
146
|
+
res.on("close", () => {
|
147
|
+
controller.abort();
|
148
|
+
});
|
149
|
+
return controller.signal;
|
150
|
+
}
|
151
|
+
|
152
|
+
// src/adapters/node/rpc-handler.ts
|
153
|
+
var RPCHandler = class {
|
154
|
+
standardHandler;
|
155
|
+
constructor(router, options) {
|
156
|
+
const codec = options?.codec ?? new RPCCodec();
|
157
|
+
const matcher = options?.matcher ?? new RPCMatcher();
|
158
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
159
|
+
}
|
160
|
+
async handle(req, res, ...rest) {
|
161
|
+
const standardRequest = nodeHttpToStandardRequest(req, res);
|
162
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
163
|
+
if (!result.matched) {
|
164
|
+
return { matched: false };
|
165
|
+
}
|
166
|
+
await nodeHttpResponseSendStandardResponse(res, result.response);
|
167
|
+
return { matched: true };
|
168
|
+
}
|
169
|
+
};
|
170
|
+
export {
|
171
|
+
RPCHandler,
|
172
|
+
nodeHttpResponseSendStandardResponse,
|
173
|
+
nodeHttpToStandardRequest
|
174
|
+
};
|
175
|
+
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { Context } from '../../context';
|
2
|
+
import type { Router } from '../../router';
|
3
|
+
import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
|
4
|
+
import type { FetchHandler, FetchHandleResult } from './types';
|
5
|
+
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
6
|
+
private readonly standardHandler;
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
8
|
+
handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { Context } from '../../context';
|
2
|
+
import type { StandardHandleRest } from '../standard';
|
3
|
+
export type FetchHandleResult = {
|
4
|
+
matched: true;
|
5
|
+
response: Response;
|
6
|
+
} | {
|
7
|
+
matched: false;
|
8
|
+
response: undefined;
|
9
|
+
};
|
10
|
+
export interface FetchHandler<T extends Context> {
|
11
|
+
handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
|
12
|
+
}
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { StandardBody, StandardRequest, StandardResponse } from '../standard';
|
2
|
+
export declare function fetchReToStandardBody(re: Request | Response): Promise<StandardBody>;
|
3
|
+
export declare function fetchRequestToStandardRequest(request: Request): StandardRequest;
|
4
|
+
export declare function standardBodyToFetchBody(body: StandardBody): Blob | FormData | URLSearchParams | string | undefined;
|
5
|
+
export declare function standardResponseToFetchResponse(response: StandardResponse): Response;
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { FetchHandler } from '../fetch';
|
4
|
+
import type { StandardHandleOptions } from '../standard';
|
5
|
+
import { type Value } from '@orpc/shared';
|
6
|
+
export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
+
context?: Value<T, [HonoContext]>;
|
8
|
+
} : {
|
9
|
+
context: Value<T, [HonoContext]>;
|
10
|
+
});
|
11
|
+
export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
|
12
|
+
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
|
13
|
+
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { FetchHandler } from '../fetch';
|
4
|
+
import type { StandardHandleOptions } from '../standard';
|
5
|
+
import { type Value } from '@orpc/shared';
|
6
|
+
export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
|
+
context?: Value<T, [NextRequest]>;
|
8
|
+
} : {
|
9
|
+
context: Value<T, [NextRequest]>;
|
10
|
+
});
|
11
|
+
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
|
12
|
+
export interface ServeResult {
|
13
|
+
GET(req: NextRequest): Promise<Response>;
|
14
|
+
POST(req: NextRequest): Promise<Response>;
|
15
|
+
PUT(req: NextRequest): Promise<Response>;
|
16
|
+
PATCH(req: NextRequest): Promise<Response>;
|
17
|
+
DELETE(req: NextRequest): Promise<Response>;
|
18
|
+
}
|
19
|
+
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
|
20
|
+
//# sourceMappingURL=serve.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { Context } from '../../context';
|
2
|
+
import type { Router } from '../../router';
|
3
|
+
import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
|
4
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
|
5
|
+
export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
|
6
|
+
private readonly standardHandler;
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
8
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
|
+
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
3
|
+
import type { Context } from '../../context';
|
4
|
+
import type { StandardHandleRest } from '../standard';
|
5
|
+
export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
6
|
+
/**
|
7
|
+
* Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
|
8
|
+
* This is useful for `express.js` middleware.
|
9
|
+
*/
|
10
|
+
originalUrl?: string;
|
11
|
+
};
|
12
|
+
export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
13
|
+
export type NodeHttpHandleResult = {
|
14
|
+
matched: true;
|
15
|
+
} | {
|
16
|
+
matched: false;
|
17
|
+
};
|
18
|
+
export interface NodeHttpHandler<T extends Context> {
|
19
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { StandardRequest, StandardResponse } from '../standard';
|
2
|
+
import type { NodeHttpRequest, NodeHttpResponse } from './types';
|
3
|
+
export declare function nodeHttpToStandardRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardRequest;
|
4
|
+
export declare function nodeHttpResponseSendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse): Promise<void>;
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Interceptor } from '@orpc/shared';
|
3
|
+
import type { Context } from '../../context';
|
4
|
+
import type { Plugin } from '../../plugins';
|
5
|
+
import type { Router } from '../../router';
|
6
|
+
import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
|
7
|
+
export type StandardHandleOptions<T extends Context> = {
|
8
|
+
prefix?: HTTPPath;
|
9
|
+
} & (Record<never, never> extends T ? {
|
10
|
+
context?: T;
|
11
|
+
} : {
|
12
|
+
context: T;
|
13
|
+
});
|
14
|
+
export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
|
15
|
+
context: T;
|
16
|
+
};
|
17
|
+
export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
18
|
+
export type StandardHandleResult = {
|
19
|
+
matched: true;
|
20
|
+
response: StandardResponse;
|
21
|
+
} | {
|
22
|
+
matched: false;
|
23
|
+
response: undefined;
|
24
|
+
};
|
25
|
+
export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
|
26
|
+
request: StandardRequest;
|
27
|
+
};
|
28
|
+
export interface StandardHandlerOptions<TContext extends Context> {
|
29
|
+
plugins?: Plugin<TContext>[];
|
30
|
+
/**
|
31
|
+
* Interceptors at the request level, helpful when you want catch errors
|
32
|
+
*/
|
33
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
34
|
+
/**
|
35
|
+
* Interceptors at the root level, helpful when you want override the response
|
36
|
+
*/
|
37
|
+
interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
38
|
+
}
|
39
|
+
export declare class StandardHandler<TContext extends Context> {
|
40
|
+
private readonly matcher;
|
41
|
+
private readonly codec;
|
42
|
+
private readonly options;
|
43
|
+
private readonly plugin;
|
44
|
+
constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
|
45
|
+
handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): Promise<StandardHandleResult>;
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=handler.d.ts.map
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { ORPCError } from '@orpc/contract';
|
2
|
+
import type { AnyProcedure } from '../../procedure';
|
3
|
+
import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from './types';
|
4
|
+
import { RPCSerializer } from './rpc-serializer';
|
5
|
+
export interface StandardCodecOptions {
|
6
|
+
serializer?: RPCSerializer;
|
7
|
+
}
|
8
|
+
export declare class RPCCodec implements StandardCodec {
|
9
|
+
private readonly serializer;
|
10
|
+
constructor(options?: StandardCodecOptions);
|
11
|
+
decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
|
12
|
+
encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
|
13
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
14
|
+
}
|
15
|
+
//# sourceMappingURL=rpc-codec.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Context } from '../../context';
|
2
|
+
import type { StandardHandlerOptions } from './handler';
|
3
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
4
|
+
export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
|
5
|
+
matcher?: StandardMatcher;
|
6
|
+
codec?: StandardCodec;
|
7
|
+
}
|
8
|
+
//# sourceMappingURL=rpc-handler.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { StandardMatcher, StandardMatchResult } from './types';
|
3
|
+
import { type AnyRouter } from '../../router';
|
4
|
+
export declare class RPCMatcher implements StandardMatcher {
|
5
|
+
private readonly tree;
|
6
|
+
private pendingRouters;
|
7
|
+
init(router: AnyRouter, path?: string[]): void;
|
8
|
+
match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=rpc-matcher.d.ts.map
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { Segment } from '@orpc/shared';
|
2
|
+
export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url', Segment[]][];
|
3
|
+
export type RPCSerialized = {
|
4
|
+
json: unknown;
|
5
|
+
meta: RPCSerializedJsonMeta;
|
6
|
+
} | FormData | Blob;
|
7
|
+
export type RPCSerializedFormDataMaps = Segment[][];
|
8
|
+
export declare class RPCSerializer {
|
9
|
+
serialize(data: unknown): RPCSerialized;
|
10
|
+
deserialize(serialized: RPCSerialized): unknown;
|
11
|
+
}
|
12
|
+
export declare function serializeRPCJson(value: unknown, segments?: Segment[], meta?: RPCSerializedJsonMeta): {
|
13
|
+
json: unknown;
|
14
|
+
meta: RPCSerializedJsonMeta;
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=rpc-serializer.d.ts.map
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import type { AbortSignal, HTTPPath, ORPCError } from '@orpc/contract';
|
2
|
+
import type { JsonValue } from '@orpc/shared';
|
3
|
+
import type { AnyProcedure } from '../../procedure';
|
4
|
+
import type { AnyRouter } from '../../router';
|
5
|
+
export interface StandardHeaders {
|
6
|
+
[key: string]: string | string[] | undefined;
|
7
|
+
}
|
8
|
+
export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData;
|
9
|
+
export interface StandardRequest {
|
10
|
+
/**
|
11
|
+
* Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
|
12
|
+
*/
|
13
|
+
raw: Record<string, unknown>;
|
14
|
+
method: string;
|
15
|
+
url: URL;
|
16
|
+
headers: StandardHeaders;
|
17
|
+
/**
|
18
|
+
* The body has been parsed base on the content-type header.
|
19
|
+
* This method can safely call multiple times (cached).
|
20
|
+
*/
|
21
|
+
body(): Promise<StandardBody>;
|
22
|
+
signal?: AbortSignal;
|
23
|
+
}
|
24
|
+
export interface StandardResponse {
|
25
|
+
status: number;
|
26
|
+
headers: StandardHeaders;
|
27
|
+
body: StandardBody;
|
28
|
+
}
|
29
|
+
export type StandardParams = Record<string, string>;
|
30
|
+
export type StandardMatchResult = {
|
31
|
+
path: string[];
|
32
|
+
procedure: AnyProcedure;
|
33
|
+
params?: StandardParams;
|
34
|
+
} | undefined;
|
35
|
+
export interface StandardMatcher {
|
36
|
+
init(router: AnyRouter): void;
|
37
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
38
|
+
}
|
39
|
+
export interface StandardCodec {
|
40
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
41
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
42
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
43
|
+
}
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { BuilderDef } from './builder';
|
3
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { FlattenLazy } from './lazy-utils';
|
5
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
6
|
+
import type { ProcedureHandler } from './procedure';
|
7
|
+
import type { DecoratedProcedure } from './procedure-decorated';
|
8
|
+
import type { AdaptedRouter, AdaptRouterOptions, Router } from './router';
|
9
|
+
export interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
10
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
11
|
+
'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
12
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
13
|
+
'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
14
|
+
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
15
|
+
'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
16
|
+
'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
17
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
18
|
+
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
19
|
+
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
20
|
+
'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
|
21
|
+
'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
|
22
|
+
default: U;
|
23
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
|
24
|
+
}
|
25
|
+
export interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
26
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
27
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
28
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
29
|
+
'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
30
|
+
'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
31
|
+
'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
32
|
+
'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
33
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
34
|
+
}
|
35
|
+
export interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
36
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
37
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
38
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
39
|
+
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
40
|
+
'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
41
|
+
'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
42
|
+
'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
43
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
44
|
+
}
|
45
|
+
export interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
46
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
47
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
48
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
49
|
+
'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
50
|
+
'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
51
|
+
'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
52
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
53
|
+
}
|
54
|
+
export interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
55
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
56
|
+
'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
57
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
58
|
+
'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
59
|
+
'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
60
|
+
'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
61
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
62
|
+
}
|
63
|
+
export interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
64
|
+
'~orpc': AdaptRouterOptions<TErrorMap>;
|
65
|
+
'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
|
66
|
+
'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & RouterBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
|
67
|
+
'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
68
|
+
'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
69
|
+
'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
|
70
|
+
'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
|
71
|
+
default: U;
|
72
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
|
73
|
+
}
|
74
|
+
//# sourceMappingURL=builder-variants.d.ts.map
|