@orpc/server 0.0.0-next.c6c659d → 0.0.0-next.ccd4e42
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-6RSW63UJ.js +136 -0
- package/dist/chunk-JHLUGXCM.js +294 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/fetch.js +11 -9
- package/dist/hono.js +13 -11
- package/dist/index.js +226 -372
- package/dist/next.js +13 -11
- package/dist/node.js +148 -62
- package/dist/src/adapters/fetch/index.d.ts +2 -4
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +3 -11
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/middleware.d.ts +5 -4
- package/dist/src/adapters/next/serve.d.ts +10 -9
- package/dist/src/adapters/node/index.d.ts +2 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +14 -15
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +33 -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 +50 -29
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +6 -4
- 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 +10 -12
- package/dist/src/lazy-utils.d.ts +4 -2
- package/dist/src/lazy.d.ts +9 -5
- package/dist/src/middleware-decorated.d.ts +7 -6
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +22 -20
- package/dist/src/procedure-client.d.ts +7 -9
- package/dist/src/procedure-decorated.d.ts +11 -16
- package/dist/src/procedure-utils.d.ts +2 -2
- package/dist/src/procedure.d.ts +19 -33
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +6 -11
- package/dist/src/router.d.ts +25 -12
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +16 -0
- package/package.json +12 -3
- package/dist/chunk-MB74GD7C.js +0 -301
- package/dist/chunk-WUOGVGWG.js +0 -1
- package/dist/chunk-ZBJYYEII.js +0 -227
- package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
- package/dist/src/adapters/fetch/super-json.d.ts +0 -12
- package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
- package/dist/src/adapters/node/request-listener.d.ts +0 -28
- package/dist/src/error.d.ts +0 -10
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/lazy-decorated.d.ts +0 -7
- package/dist/src/procedure-builder.d.ts +0 -24
- package/dist/src/procedure-implementer.d.ts +0 -19
- package/dist/src/router-builder.d.ts +0 -29
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/types.d.ts +0 -14
package/dist/next.js
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
import "./chunk-WUOGVGWG.js";
|
2
1
|
import {
|
3
|
-
ORPCPayloadCodec,
|
4
|
-
ORPCProcedureMatcher,
|
5
2
|
RPCHandler,
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
fetchReToStandardBody,
|
4
|
+
fetchRequestToStandardRequest,
|
5
|
+
standardBodyToFetchBody,
|
6
|
+
standardResponseToFetchResponse
|
7
|
+
} from "./chunk-6RSW63UJ.js";
|
8
|
+
import "./chunk-JHLUGXCM.js";
|
9
|
+
import "./chunk-NOA3GBJQ.js";
|
9
10
|
|
10
11
|
// src/adapters/next/serve.ts
|
11
12
|
import { value } from "@orpc/shared";
|
12
13
|
function serve(handler, ...[options]) {
|
13
14
|
const main = async (req) => {
|
14
|
-
const context = await value(options?.context, req);
|
15
|
+
const context = await value(options?.context ?? {}, req);
|
15
16
|
const { matched, response } = await handler.handle(req, { ...options, context });
|
16
17
|
if (matched) {
|
17
18
|
return response;
|
@@ -27,10 +28,11 @@ function serve(handler, ...[options]) {
|
|
27
28
|
};
|
28
29
|
}
|
29
30
|
export {
|
30
|
-
ORPCPayloadCodec,
|
31
|
-
ORPCProcedureMatcher,
|
32
31
|
RPCHandler,
|
33
|
-
|
34
|
-
|
32
|
+
fetchReToStandardBody,
|
33
|
+
fetchRequestToStandardRequest,
|
34
|
+
serve,
|
35
|
+
standardBodyToFetchBody,
|
36
|
+
standardResponseToFetchResponse
|
35
37
|
};
|
36
38
|
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
@@ -1,87 +1,173 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
RPCCodec,
|
3
|
+
RPCMatcher,
|
4
|
+
StandardHandler
|
5
|
+
} from "./chunk-JHLUGXCM.js";
|
6
|
+
import "./chunk-NOA3GBJQ.js";
|
5
7
|
|
6
|
-
// src/adapters/node/
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
// src/adapters/node/utils.ts
|
9
|
+
import { Buffer, File } from "node:buffer";
|
10
|
+
import { Readable } from "node:stream";
|
11
|
+
import { once } from "@orpc/shared";
|
12
|
+
import cd from "content-disposition";
|
13
|
+
function nodeHttpToStandardRequest(req, res) {
|
12
14
|
const method = req.method ?? "GET";
|
13
|
-
const headers = createHeaders(req);
|
14
15
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
15
|
-
const host = headers.
|
16
|
+
const host = req.headers.host ?? "localhost";
|
16
17
|
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
return {
|
19
|
+
raw: { request: req, response: res },
|
20
|
+
method,
|
21
|
+
url,
|
22
|
+
headers: req.headers,
|
23
|
+
body: once(() => {
|
24
|
+
return nodeHttpRequestToStandardBody(req);
|
25
|
+
}),
|
26
|
+
get signal() {
|
27
|
+
const signal = nodeHttpResponseToAbortSignal(res);
|
28
|
+
Object.defineProperty(this, "signal", { value: signal, writable: true });
|
29
|
+
return signal;
|
30
|
+
},
|
31
|
+
set signal(value) {
|
32
|
+
Object.defineProperty(this, "signal", { value, writable: true });
|
33
|
+
}
|
34
|
+
};
|
35
|
+
}
|
36
|
+
function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
37
|
+
return new Promise((resolve, reject) => {
|
38
|
+
res.on("error", reject);
|
39
|
+
res.on("finish", resolve);
|
40
|
+
if (standardResponse.body === void 0) {
|
41
|
+
res.writeHead(standardResponse.status, standardResponse.headers);
|
42
|
+
res.end();
|
43
|
+
}
|
44
|
+
if (standardResponse.body instanceof Blob) {
|
45
|
+
const resHeaders = {
|
46
|
+
...standardResponse.headers,
|
47
|
+
"content-type": standardResponse.body.type,
|
48
|
+
"content-length": standardResponse.body.size.toString()
|
49
|
+
};
|
50
|
+
if (!standardResponse.headers["content-disposition"] && standardResponse.body instanceof Blob) {
|
51
|
+
resHeaders["content-disposition"] = cd(standardResponse.body instanceof File ? standardResponse.body.name : "blob");
|
27
52
|
}
|
53
|
+
res.writeHead(standardResponse.status, resHeaders);
|
54
|
+
Readable.fromWeb(
|
55
|
+
standardResponse.body.stream()
|
56
|
+
// Conflict between types=node and lib=dom so we need to cast it
|
57
|
+
).pipe(res);
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (standardResponse.body instanceof FormData) {
|
61
|
+
const response = new Response(standardResponse.body);
|
62
|
+
res.writeHead(standardResponse.status, {
|
63
|
+
...standardResponse.headers,
|
64
|
+
"content-type": response.headers.get("content-type")
|
65
|
+
});
|
66
|
+
Readable.fromWeb(
|
67
|
+
response.body
|
68
|
+
// Conflict between types=node and lib=dom so we need to cast it
|
69
|
+
).pipe(res);
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
if (standardResponse.body instanceof URLSearchParams) {
|
73
|
+
res.writeHead(standardResponse.status, {
|
74
|
+
...standardResponse.headers,
|
75
|
+
"content-type": "application/x-www-form-urlencoded"
|
76
|
+
});
|
77
|
+
const string2 = standardResponse.body.toString();
|
78
|
+
res.end(string2);
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
res.writeHead(standardResponse.status, {
|
82
|
+
...standardResponse.headers,
|
83
|
+
"content-type": "application/json"
|
28
84
|
});
|
29
|
-
|
30
|
-
|
31
|
-
|
85
|
+
const string = JSON.stringify(standardResponse.body);
|
86
|
+
res.end(string);
|
87
|
+
});
|
32
88
|
}
|
33
|
-
function
|
34
|
-
const
|
35
|
-
|
36
|
-
|
37
|
-
headers.append(rawHeaders[i], rawHeaders[i + 1]);
|
89
|
+
async function nodeHttpRequestToStandardBody(req) {
|
90
|
+
const method = req.method ?? "GET";
|
91
|
+
if (method === "GET" || method === "HEAD") {
|
92
|
+
return void 0;
|
38
93
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
} else {
|
51
|
-
headers[key] = value;
|
94
|
+
const contentDisposition = req.headers["content-disposition"];
|
95
|
+
const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
|
96
|
+
const contentType = req.headers["content-type"];
|
97
|
+
if (fileName) {
|
98
|
+
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
99
|
+
}
|
100
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
101
|
+
const text = await streamToString(req);
|
102
|
+
if (!text) {
|
103
|
+
return void 0;
|
52
104
|
}
|
105
|
+
return JSON.parse(text);
|
106
|
+
}
|
107
|
+
if (contentType.startsWith("multipart/form-data")) {
|
108
|
+
return await streamToFormData(req, contentType);
|
109
|
+
}
|
110
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
111
|
+
const text = await streamToString(req);
|
112
|
+
return new URLSearchParams(text);
|
113
|
+
}
|
114
|
+
if (contentType.startsWith("text/")) {
|
115
|
+
return await streamToString(req);
|
53
116
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
117
|
+
return streamToFile(req, "blob", contentType);
|
118
|
+
}
|
119
|
+
function streamToFormData(stream, contentType) {
|
120
|
+
const response = new Response(stream, {
|
121
|
+
// Conflict between types=node and lib=dom so we need to cast it
|
122
|
+
headers: {
|
123
|
+
"content-type": contentType
|
58
124
|
}
|
125
|
+
});
|
126
|
+
return response.formData();
|
127
|
+
}
|
128
|
+
async function streamToString(stream) {
|
129
|
+
let string = "";
|
130
|
+
for await (const chunk of stream) {
|
131
|
+
string += chunk.toString();
|
59
132
|
}
|
60
|
-
|
133
|
+
return string;
|
134
|
+
}
|
135
|
+
async function streamToFile(stream, fileName, contentType) {
|
136
|
+
const chunks = [];
|
137
|
+
for await (const chunk of stream) {
|
138
|
+
chunks.push(chunk);
|
139
|
+
}
|
140
|
+
return new File([Buffer.concat(chunks)], fileName, { type: contentType });
|
141
|
+
}
|
142
|
+
function nodeHttpResponseToAbortSignal(res) {
|
143
|
+
const controller = new AbortController();
|
144
|
+
res.on("close", () => {
|
145
|
+
controller.abort();
|
146
|
+
});
|
147
|
+
return controller.signal;
|
61
148
|
}
|
62
149
|
|
63
|
-
// src/adapters/node/
|
64
|
-
var
|
65
|
-
|
150
|
+
// src/adapters/node/rpc-handler.ts
|
151
|
+
var RPCHandler = class {
|
152
|
+
standardHandler;
|
66
153
|
constructor(router, options) {
|
67
|
-
|
154
|
+
const codec = options?.codec ?? new RPCCodec();
|
155
|
+
const matcher = options?.matcher ?? new RPCMatcher();
|
156
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
68
157
|
}
|
69
|
-
async handle(req, res, ...
|
70
|
-
const
|
71
|
-
const
|
72
|
-
|
73
|
-
if (result.matched === false) {
|
158
|
+
async handle(req, res, ...rest) {
|
159
|
+
const standardRequest = nodeHttpToStandardRequest(req, res);
|
160
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
161
|
+
if (!result.matched) {
|
74
162
|
return { matched: false };
|
75
163
|
}
|
76
|
-
await
|
77
|
-
await sendResponse(res, result.response);
|
164
|
+
await nodeHttpResponseSendStandardResponse(res, result.response);
|
78
165
|
return { matched: true };
|
79
166
|
}
|
80
167
|
};
|
81
168
|
export {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
sendResponse
|
169
|
+
RPCHandler,
|
170
|
+
nodeHttpResponseSendStandardResponse,
|
171
|
+
nodeHttpToStandardRequest
|
86
172
|
};
|
87
173
|
//# sourceMappingURL=node.js.map
|
@@ -1,6 +1,4 @@
|
|
1
|
-
export * from './
|
2
|
-
export * from './orpc-payload-codec';
|
3
|
-
export * from './orpc-procedure-matcher';
|
4
|
-
export * as SuperJSON from './super-json';
|
1
|
+
export * from './rpc-handler';
|
5
2
|
export * from './types';
|
3
|
+
export * from './utils';
|
6
4
|
//# sourceMappingURL=index.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 { 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
|
@@ -1,13 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
export type FetchHandleOptions<T extends Context> = {
|
4
|
-
prefix?: HTTPPath;
|
5
|
-
} & (undefined extends T ? {
|
6
|
-
context?: T;
|
7
|
-
} : {
|
8
|
-
context: T;
|
9
|
-
});
|
10
|
-
export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (undefined extends T ? [] : never);
|
1
|
+
import type { Context } from '../../context';
|
2
|
+
import type { StandardHandleRest } from '../standard';
|
11
3
|
export type FetchHandleResult = {
|
12
4
|
matched: true;
|
13
5
|
response: Response;
|
@@ -16,6 +8,6 @@ export type FetchHandleResult = {
|
|
16
8
|
response: undefined;
|
17
9
|
};
|
18
10
|
export interface FetchHandler<T extends Context> {
|
19
|
-
handle
|
11
|
+
handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
|
20
12
|
}
|
21
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
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
|
-
import type { Context } from '../../
|
3
|
-
import type {
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { FetchHandler } from '../fetch';
|
4
|
+
import type { StandardHandleOptions } from '../standard';
|
4
5
|
import { type Value } from '@orpc/shared';
|
5
|
-
export type CreateMiddlewareOptions<T extends Context> = Omit<
|
6
|
+
export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
6
7
|
context?: Value<T, [HonoContext]>;
|
7
8
|
} : {
|
8
9
|
context: Value<T, [HonoContext]>;
|
9
10
|
});
|
10
|
-
export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (
|
11
|
+
export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
12
|
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
|
12
13
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -1,19 +1,20 @@
|
|
1
1
|
import type { NextRequest } from 'next/server';
|
2
|
-
import type { Context } from '../../
|
3
|
-
import type {
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { FetchHandler } from '../fetch';
|
4
|
+
import type { StandardHandleOptions } from '../standard';
|
4
5
|
import { type Value } from '@orpc/shared';
|
5
|
-
export type ServeOptions<T extends Context> = Omit<
|
6
|
+
export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
6
7
|
context?: Value<T, [NextRequest]>;
|
7
8
|
} : {
|
8
9
|
context: Value<T, [NextRequest]>;
|
9
10
|
});
|
10
|
-
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (
|
11
|
+
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
|
11
12
|
export interface ServeResult {
|
12
|
-
GET
|
13
|
-
POST
|
14
|
-
PUT
|
15
|
-
PATCH
|
16
|
-
DELETE
|
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>;
|
17
18
|
}
|
18
19
|
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
|
19
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
|
@@ -1,22 +1,21 @@
|
|
1
|
-
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Promisable } from '@orpc/shared';
|
3
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
4
|
-
import type {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
export type
|
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 = {
|
15
14
|
matched: true;
|
16
15
|
} | {
|
17
16
|
matched: false;
|
18
17
|
};
|
19
|
-
export interface
|
20
|
-
handle
|
18
|
+
export interface NodeHttpHandler<T extends Context> {
|
19
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
|
21
20
|
}
|
22
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,33 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Interceptable } from '@orpc/shared';
|
3
|
+
import type { Context } from '../../context';
|
4
|
+
import type { Router } from '../../router';
|
5
|
+
import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
|
6
|
+
export type StandardHandleOptions<T extends Context> = {
|
7
|
+
prefix?: HTTPPath;
|
8
|
+
} & (Record<never, never> extends T ? {
|
9
|
+
context?: T;
|
10
|
+
} : {
|
11
|
+
context: T;
|
12
|
+
});
|
13
|
+
export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
14
|
+
export type StandardHandleResult = {
|
15
|
+
matched: true;
|
16
|
+
response: StandardResponse;
|
17
|
+
} | {
|
18
|
+
matched: false;
|
19
|
+
response: undefined;
|
20
|
+
};
|
21
|
+
export interface StandardHandlerOptions<TContext extends Context> extends Interceptable<{
|
22
|
+
context: TContext;
|
23
|
+
request: StandardRequest;
|
24
|
+
}, StandardHandleResult, unknown> {
|
25
|
+
}
|
26
|
+
export declare class StandardHandler<TContext extends Context> {
|
27
|
+
private readonly matcher;
|
28
|
+
private readonly codec;
|
29
|
+
private readonly options;
|
30
|
+
constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
|
31
|
+
handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): Promise<StandardHandleResult>;
|
32
|
+
}
|
33
|
+
//# 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
|