@orpc/server 0.26.0 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-6BY63WA5.js → chunk-3BAPJGK6.js} +12 -13
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +2 -19
- package/dist/hono.js +30 -0
- package/dist/next.js +36 -0
- package/dist/node.js +65 -23
- package/dist/src/adapters/fetch/index.d.ts +0 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +8 -8
- package/dist/src/adapters/fetch/types.d.ts +11 -6
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +1 -1
- package/dist/src/adapters/node/orpc-handler.d.ts +5 -5
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +10 -9
- package/package.json +18 -8
- package/dist/src/adapters/fetch/composite-handler.d.ts +0 -8
- package/dist/src/adapters/node/composite-handler.d.ts +0 -9
@@ -236,28 +236,24 @@ var ORPCProcedureMatcher = class {
|
|
236
236
|
};
|
237
237
|
|
238
238
|
// src/adapters/fetch/orpc-handler.ts
|
239
|
-
import { executeWithHooks,
|
239
|
+
import { executeWithHooks, trim as trim2 } from "@orpc/shared";
|
240
240
|
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
241
241
|
var ORPCHandler = class {
|
242
242
|
constructor(router, options) {
|
243
|
-
this.router = router;
|
244
243
|
this.options = options;
|
245
244
|
this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
|
246
245
|
this.payloadCodec = options?.payloadCodec ?? new ORPCPayloadCodec();
|
247
246
|
}
|
248
247
|
procedureMatcher;
|
249
248
|
payloadCodec;
|
250
|
-
|
251
|
-
return Boolean(request.headers.get(ORPC_HANDLER_HEADER)?.includes(ORPC_HANDLER_VALUE));
|
252
|
-
}
|
253
|
-
async fetch(request, ...[options]) {
|
249
|
+
async handle(request, ...[options]) {
|
254
250
|
const context = options?.context;
|
255
251
|
const execute = async () => {
|
256
252
|
const url = new URL(request.url);
|
257
253
|
const pathname = `/${trim2(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
|
258
254
|
const match = await this.procedureMatcher.match(pathname);
|
259
255
|
if (!match) {
|
260
|
-
|
256
|
+
return { matched: false, response: void 0 };
|
261
257
|
}
|
262
258
|
const input = await this.payloadCodec.decode(request);
|
263
259
|
const client = createProcedureClient({
|
@@ -265,20 +261,22 @@ var ORPCHandler = class {
|
|
265
261
|
procedure: match.procedure,
|
266
262
|
path: match.path
|
267
263
|
});
|
268
|
-
const output = await client(input, { signal:
|
264
|
+
const output = await client(input, { signal: request.signal });
|
269
265
|
const { body, headers } = this.payloadCodec.encode(output);
|
270
|
-
|
266
|
+
const response = new Response(body, { headers });
|
267
|
+
return { matched: true, response };
|
271
268
|
};
|
272
269
|
try {
|
273
|
-
|
270
|
+
const result = await executeWithHooks({
|
274
271
|
context,
|
275
272
|
execute,
|
276
273
|
input: request,
|
277
274
|
hooks: this.options,
|
278
275
|
meta: {
|
279
|
-
signal:
|
276
|
+
signal: request.signal
|
280
277
|
}
|
281
278
|
});
|
279
|
+
return result;
|
282
280
|
} catch (e) {
|
283
281
|
const error = e instanceof ORPCError2 ? e : new ORPCError2({
|
284
282
|
code: "INTERNAL_SERVER_ERROR",
|
@@ -286,10 +284,11 @@ var ORPCHandler = class {
|
|
286
284
|
cause: e
|
287
285
|
});
|
288
286
|
const { body, headers } = this.payloadCodec.encode(error.toJSON());
|
289
|
-
|
287
|
+
const response = new Response(body, {
|
290
288
|
headers,
|
291
289
|
status: error.status
|
292
290
|
});
|
291
|
+
return { matched: true, response };
|
293
292
|
}
|
294
293
|
}
|
295
294
|
};
|
@@ -300,4 +299,4 @@ export {
|
|
300
299
|
ORPCProcedureMatcher,
|
301
300
|
ORPCHandler
|
302
301
|
};
|
303
|
-
//# sourceMappingURL=chunk-
|
302
|
+
//# sourceMappingURL=chunk-3BAPJGK6.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=chunk-WUOGVGWG.js.map
|
package/dist/fetch.js
CHANGED
@@ -1,29 +1,12 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
1
2
|
import {
|
2
3
|
ORPCHandler,
|
3
4
|
ORPCPayloadCodec,
|
4
5
|
ORPCProcedureMatcher,
|
5
6
|
super_json_exports
|
6
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-3BAPJGK6.js";
|
7
8
|
import "./chunk-E7GUWVR4.js";
|
8
|
-
|
9
|
-
// src/adapters/fetch/composite-handler.ts
|
10
|
-
var CompositeHandler = class {
|
11
|
-
constructor(handlers) {
|
12
|
-
this.handlers = handlers;
|
13
|
-
}
|
14
|
-
async fetch(request, ...opt) {
|
15
|
-
for (const handler of this.handlers) {
|
16
|
-
if (handler.condition(request)) {
|
17
|
-
return handler.fetch(request, ...opt);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
return new Response("None of the handlers can handle the request.", {
|
21
|
-
status: 404
|
22
|
-
});
|
23
|
-
}
|
24
|
-
};
|
25
9
|
export {
|
26
|
-
CompositeHandler,
|
27
10
|
ORPCHandler,
|
28
11
|
ORPCPayloadCodec,
|
29
12
|
ORPCProcedureMatcher,
|
package/dist/hono.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
2
|
+
import {
|
3
|
+
ORPCHandler,
|
4
|
+
ORPCPayloadCodec,
|
5
|
+
ORPCProcedureMatcher,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-3BAPJGK6.js";
|
8
|
+
import "./chunk-E7GUWVR4.js";
|
9
|
+
|
10
|
+
// src/adapters/hono/middleware.ts
|
11
|
+
import { value } from "@orpc/shared";
|
12
|
+
function createMiddleware(handler, ...[options]) {
|
13
|
+
return async (c, next) => {
|
14
|
+
const context = await value(options?.context, c);
|
15
|
+
const { matched, response } = await handler.handle(c.req.raw, { ...options, context });
|
16
|
+
if (matched) {
|
17
|
+
c.res = response;
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
await next();
|
21
|
+
};
|
22
|
+
}
|
23
|
+
export {
|
24
|
+
ORPCHandler,
|
25
|
+
ORPCPayloadCodec,
|
26
|
+
ORPCProcedureMatcher,
|
27
|
+
super_json_exports as SuperJSON,
|
28
|
+
createMiddleware
|
29
|
+
};
|
30
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/next.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
2
|
+
import {
|
3
|
+
ORPCHandler,
|
4
|
+
ORPCPayloadCodec,
|
5
|
+
ORPCProcedureMatcher,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-3BAPJGK6.js";
|
8
|
+
import "./chunk-E7GUWVR4.js";
|
9
|
+
|
10
|
+
// src/adapters/next/serve.ts
|
11
|
+
import { value } from "@orpc/shared";
|
12
|
+
function serve(handler, ...[options]) {
|
13
|
+
const main = async (req) => {
|
14
|
+
const context = await value(options?.context, req);
|
15
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
16
|
+
if (matched) {
|
17
|
+
return response;
|
18
|
+
}
|
19
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
20
|
+
};
|
21
|
+
return {
|
22
|
+
GET: main,
|
23
|
+
POST: main,
|
24
|
+
PUT: main,
|
25
|
+
PATCH: main,
|
26
|
+
DELETE: main
|
27
|
+
};
|
28
|
+
}
|
29
|
+
export {
|
30
|
+
ORPCHandler,
|
31
|
+
ORPCPayloadCodec,
|
32
|
+
ORPCProcedureMatcher,
|
33
|
+
super_json_exports as SuperJSON,
|
34
|
+
serve
|
35
|
+
};
|
36
|
+
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
@@ -1,45 +1,87 @@
|
|
1
1
|
import {
|
2
2
|
ORPCHandler
|
3
|
-
} from "./chunk-
|
3
|
+
} from "./chunk-3BAPJGK6.js";
|
4
4
|
import "./chunk-E7GUWVR4.js";
|
5
5
|
|
6
|
-
// src/adapters/node/
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
// src/adapters/node/request-listener.ts
|
7
|
+
function createRequest(req, res) {
|
8
|
+
const controller = new AbortController();
|
9
|
+
res.on("close", () => {
|
10
|
+
controller.abort();
|
11
|
+
});
|
12
|
+
const method = req.method ?? "GET";
|
13
|
+
const headers = createHeaders(req);
|
14
|
+
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
15
|
+
const host = headers.get("Host") ?? "localhost";
|
16
|
+
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
17
|
+
const init = { method, headers, signal: controller.signal };
|
18
|
+
if (method !== "GET" && method !== "HEAD") {
|
19
|
+
init.body = new ReadableStream({
|
20
|
+
start(controller2) {
|
21
|
+
req.on("data", (chunk) => {
|
22
|
+
controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
23
|
+
});
|
24
|
+
req.on("end", () => {
|
25
|
+
controller2.close();
|
26
|
+
});
|
27
|
+
}
|
28
|
+
});
|
29
|
+
init.duplex = "half";
|
30
|
+
}
|
31
|
+
return new Request(url, init);
|
32
|
+
}
|
33
|
+
function createHeaders(req) {
|
34
|
+
const headers = new Headers();
|
35
|
+
const rawHeaders = req.rawHeaders;
|
36
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
37
|
+
headers.append(rawHeaders[i], rawHeaders[i + 1]);
|
10
38
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
39
|
+
return headers;
|
40
|
+
}
|
41
|
+
async function sendResponse(res, response) {
|
42
|
+
const headers = {};
|
43
|
+
for (const [key, value] of response.headers) {
|
44
|
+
if (key in headers) {
|
45
|
+
if (Array.isArray(headers[key])) {
|
46
|
+
headers[key].push(value);
|
47
|
+
} else {
|
48
|
+
headers[key] = [headers[key], value];
|
15
49
|
}
|
50
|
+
} else {
|
51
|
+
headers[key] = value;
|
16
52
|
}
|
17
|
-
res.statusCode = 404;
|
18
|
-
res.end("None of the handlers can handle the request.");
|
19
53
|
}
|
20
|
-
|
54
|
+
res.writeHead(response.status, headers);
|
55
|
+
if (response.body != null && res.req.method !== "HEAD") {
|
56
|
+
for await (const chunk of response.body) {
|
57
|
+
res.write(chunk);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
res.end();
|
61
|
+
}
|
21
62
|
|
22
63
|
// src/adapters/node/orpc-handler.ts
|
23
|
-
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
24
|
-
import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE } from "@orpc/shared";
|
25
64
|
var ORPCHandler2 = class {
|
26
65
|
orpcFetchHandler;
|
27
66
|
constructor(router, options) {
|
28
67
|
this.orpcFetchHandler = new ORPCHandler(router, options);
|
29
68
|
}
|
30
|
-
condition(request) {
|
31
|
-
return Boolean(request.headers[ORPC_HANDLER_HEADER]?.includes(ORPC_HANDLER_VALUE));
|
32
|
-
}
|
33
69
|
async handle(req, res, ...[options]) {
|
34
|
-
const request = createRequest(req, res
|
70
|
+
const request = createRequest(req, res);
|
35
71
|
const castedOptions = options ?? {};
|
36
|
-
const
|
37
|
-
|
38
|
-
|
72
|
+
const result = await this.orpcFetchHandler.handle(request, castedOptions);
|
73
|
+
if (result.matched === false) {
|
74
|
+
return { matched: false };
|
75
|
+
}
|
76
|
+
await options?.beforeSend?.(result.response, castedOptions.context);
|
77
|
+
await sendResponse(res, result.response);
|
78
|
+
return { matched: true };
|
39
79
|
}
|
40
80
|
};
|
41
81
|
export {
|
42
|
-
|
43
|
-
|
82
|
+
ORPCHandler2 as ORPCHandler,
|
83
|
+
createHeaders,
|
84
|
+
createRequest,
|
85
|
+
sendResponse
|
44
86
|
};
|
45
87
|
//# sourceMappingURL=node.js.map
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import type { Hooks } from '@orpc/shared';
|
2
2
|
import type { Router } from '../../router';
|
3
|
-
import type { Context
|
4
|
-
import type {
|
3
|
+
import type { Context } from '../../types';
|
4
|
+
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
5
|
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
6
|
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
-
export type ORPCHandlerOptions<T extends Context> = Hooks<Request,
|
7
|
+
export type ORPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
+
signal?: AbortSignal;
|
9
|
+
}> & {
|
8
10
|
procedureMatcher?: PublicORPCProcedureMatcher;
|
9
11
|
payloadCodec?: PublicORPCPayloadCodec;
|
10
12
|
};
|
11
|
-
export declare class ORPCHandler<T extends Context> implements
|
12
|
-
readonly
|
13
|
-
readonly options?: NoInfer<ORPCHandlerOptions<T>> | undefined;
|
13
|
+
export declare class ORPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
+
private readonly options?;
|
14
15
|
private readonly procedureMatcher;
|
15
16
|
private readonly payloadCodec;
|
16
17
|
constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>> | undefined);
|
17
|
-
|
18
|
-
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
18
|
+
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
19
|
}
|
20
20
|
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -1,16 +1,21 @@
|
|
1
1
|
import type { HTTPPath } from '@orpc/contract';
|
2
|
-
import type { Context
|
3
|
-
export type
|
2
|
+
import type { Context } from '../../types';
|
3
|
+
export type FetchHandleOptions<T extends Context> = {
|
4
4
|
prefix?: HTTPPath;
|
5
5
|
} & (undefined extends T ? {
|
6
6
|
context?: T;
|
7
7
|
} : {
|
8
8
|
context: T;
|
9
9
|
});
|
10
|
+
export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (undefined extends T ? [] : never);
|
11
|
+
export type FetchHandleResult = {
|
12
|
+
matched: true;
|
13
|
+
response: Response;
|
14
|
+
} | {
|
15
|
+
matched: false;
|
16
|
+
response: undefined;
|
17
|
+
};
|
10
18
|
export interface FetchHandler<T extends Context> {
|
11
|
-
|
12
|
-
}
|
13
|
-
export interface ConditionalFetchHandler<T extends Context> extends FetchHandler<T> {
|
14
|
-
condition: (request: Request) => boolean;
|
19
|
+
handle: (request: Request, ...rest: FetchHandleRest<T>) => Promise<FetchHandleResult>;
|
15
20
|
}
|
16
21
|
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
|
+
import type { Context } from '../../types';
|
3
|
+
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
4
|
+
import { type Value } from '@orpc/shared';
|
5
|
+
export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (undefined extends T ? {
|
6
|
+
context?: Value<T, [HonoContext]>;
|
7
|
+
} : {
|
8
|
+
context: Value<T, [HonoContext]>;
|
9
|
+
});
|
10
|
+
export type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (undefined extends T ? [] : never);
|
11
|
+
export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
|
12
|
+
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
2
|
+
import type { Context } from '../../types';
|
3
|
+
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
4
|
+
import { type Value } from '@orpc/shared';
|
5
|
+
export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (undefined extends T ? {
|
6
|
+
context?: Value<T, [NextRequest]>;
|
7
|
+
} : {
|
8
|
+
context: Value<T, [NextRequest]>;
|
9
|
+
});
|
10
|
+
export type ServeRest<T extends Context> = [options: ServeOptions<T>] | (undefined extends T ? [] : never);
|
11
|
+
export interface ServeResult {
|
12
|
+
GET: (req: NextRequest) => Promise<Response>;
|
13
|
+
POST: (req: NextRequest) => Promise<Response>;
|
14
|
+
PUT: (req: NextRequest) => Promise<Response>;
|
15
|
+
PATCH: (req: NextRequest) => Promise<Response>;
|
16
|
+
DELETE: (req: NextRequest) => Promise<Response>;
|
17
|
+
}
|
18
|
+
export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
|
19
|
+
//# sourceMappingURL=serve.d.ts.map
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ServerResponse } from 'node:http';
|
2
2
|
import type { Router } from '../../router';
|
3
3
|
import type { Context } from '../../types';
|
4
4
|
import type { ORPCHandlerOptions } from '../fetch/orpc-handler';
|
5
|
-
import type {
|
6
|
-
|
5
|
+
import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
|
6
|
+
import { type ExpressableIncomingMessage } from './request-listener';
|
7
|
+
export declare class ORPCHandler<T extends Context> implements RequestHandler<T> {
|
7
8
|
private readonly orpcFetchHandler;
|
8
9
|
constructor(router: Router<T, any>, options?: NoInfer<ORPCHandlerOptions<T>>);
|
9
|
-
|
10
|
-
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
10
|
+
handle(req: ExpressableIncomingMessage, res: ServerResponse, ...[options]: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
11
11
|
}
|
12
12
|
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
|
+
export interface ExpressableIncomingMessage extends IncomingMessage {
|
3
|
+
originalUrl?: string;
|
4
|
+
}
|
5
|
+
/**
|
6
|
+
* Creates a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object from a Node.js
|
7
|
+
* [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) and
|
8
|
+
* [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) pair.
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
export declare function createRequest(req: ExpressableIncomingMessage, res: ServerResponse): Request;
|
12
|
+
/**
|
13
|
+
* Creates a [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object from the headers
|
14
|
+
* in a Node.js [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
|
15
|
+
*
|
16
|
+
* @param req The incoming request object.
|
17
|
+
* @returns A headers object.
|
18
|
+
*/
|
19
|
+
export declare function createHeaders(req: IncomingMessage): Headers;
|
20
|
+
/**
|
21
|
+
* Sends a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) to the client using the
|
22
|
+
* Node.js [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) object.
|
23
|
+
*
|
24
|
+
* @param res The server response object.
|
25
|
+
* @param response The response to send.
|
26
|
+
*/
|
27
|
+
export declare function sendResponse(res: ServerResponse, response: Response): Promise<void>;
|
28
|
+
//# sourceMappingURL=request-listener.d.ts.map
|
@@ -1,21 +1,22 @@
|
|
1
|
-
import type { RequestOptions as BaseRequestOptions } from '@mjackson/node-fetch-server';
|
2
1
|
import type { HTTPPath } from '@orpc/contract';
|
3
2
|
import type { Promisable } from '@orpc/shared';
|
4
3
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
5
|
-
import type { Context
|
6
|
-
export type
|
4
|
+
import type { Context } from '../../types';
|
5
|
+
export type RequestHandleOptions<T extends Context> = {
|
7
6
|
prefix?: HTTPPath;
|
7
|
+
beforeSend?: (response: Response, context: T) => Promisable<void>;
|
8
8
|
} & (undefined extends T ? {
|
9
9
|
context?: T;
|
10
10
|
} : {
|
11
11
|
context: T;
|
12
|
-
})
|
13
|
-
|
12
|
+
});
|
13
|
+
export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (undefined extends T ? [] : never);
|
14
|
+
export type RequestHandleResult = {
|
15
|
+
matched: true;
|
16
|
+
} | {
|
17
|
+
matched: false;
|
14
18
|
};
|
15
19
|
export interface RequestHandler<T extends Context> {
|
16
|
-
handle: (req: IncomingMessage, res: ServerResponse, ...
|
17
|
-
}
|
18
|
-
export interface ConditionalRequestHandler<T extends Context> extends RequestHandler<T> {
|
19
|
-
condition: (request: IncomingMessage) => boolean;
|
20
|
+
handle: (req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>) => Promise<RequestHandleResult>;
|
20
21
|
}
|
21
22
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.27.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -24,6 +24,16 @@
|
|
24
24
|
"import": "./dist/fetch.js",
|
25
25
|
"default": "./dist/fetch.js"
|
26
26
|
},
|
27
|
+
"./hono": {
|
28
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
29
|
+
"import": "./dist/hono.js",
|
30
|
+
"default": "./dist/hono.js"
|
31
|
+
},
|
32
|
+
"./next": {
|
33
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
34
|
+
"import": "./dist/next.js",
|
35
|
+
"default": "./dist/next.js"
|
36
|
+
},
|
27
37
|
"./node": {
|
28
38
|
"types": "./dist/src/adapters/node/index.d.ts",
|
29
39
|
"import": "./dist/node.js",
|
@@ -38,16 +48,16 @@
|
|
38
48
|
"!**/*.tsbuildinfo",
|
39
49
|
"dist"
|
40
50
|
],
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"@orpc/shared": "0.26.0"
|
51
|
+
"peerDependencies": {
|
52
|
+
"hono": ">=4.6.0",
|
53
|
+
"next": ">=14.0.0"
|
45
54
|
},
|
46
|
-
"
|
47
|
-
"
|
55
|
+
"dependencies": {
|
56
|
+
"@orpc/contract": "0.27.0",
|
57
|
+
"@orpc/shared": "0.27.0"
|
48
58
|
},
|
49
59
|
"scripts": {
|
50
|
-
"build": "tsup --
|
60
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
51
61
|
"build:watch": "pnpm run build --watch",
|
52
62
|
"type:check": "tsc -b"
|
53
63
|
}
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import type { Context } from '../../types';
|
2
|
-
import type { ConditionalFetchHandler, FetchHandler, FetchOptions } from './types';
|
3
|
-
export declare class CompositeHandler<T extends Context> implements FetchHandler<T> {
|
4
|
-
private readonly handlers;
|
5
|
-
constructor(handlers: ConditionalFetchHandler<T>[]);
|
6
|
-
fetch(request: Request, ...opt: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
7
|
-
}
|
8
|
-
//# sourceMappingURL=composite-handler.d.ts.map
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
|
-
import type { Context } from '../../types';
|
3
|
-
import type { ConditionalRequestHandler, RequestHandler, RequestOptions } from './types';
|
4
|
-
export declare class CompositeHandler<T extends Context> implements RequestHandler<T> {
|
5
|
-
private readonly handlers;
|
6
|
-
constructor(handlers: ConditionalRequestHandler<T>[]);
|
7
|
-
handle(req: IncomingMessage, res: ServerResponse, ...opt: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
8
|
-
}
|
9
|
-
//# sourceMappingURL=composite-handler.d.ts.map
|