@orpc/server 0.0.0-next.31590a1 → 0.0.0-next.32cb70c
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-ESTRJAOX.js +299 -0
- package/dist/{chunk-NOA3GBJQ.js → chunk-KK4SDLC7.js} +9 -69
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +9 -12
- package/dist/hono.js +13 -25
- package/dist/index.js +2 -16
- package/dist/next.js +10 -13
- package/dist/node.js +61 -149
- package/dist/src/adapters/fetch/index.d.ts +4 -2
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +10 -2
- package/dist/src/adapters/hono/middleware.d.ts +2 -3
- package/dist/src/adapters/next/serve.d.ts +2 -3
- package/dist/src/adapters/node/index.d.ts +3 -2
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +14 -13
- package/dist/src/implementer-variants.d.ts +5 -6
- package/dist/src/implementer.d.ts +6 -7
- package/dist/src/index.d.ts +1 -3
- package/package.json +3 -17
- package/dist/chunk-CVIWJKJC.js +0 -308
- package/dist/chunk-EYGVJA7A.js +0 -136
- package/dist/chunk-OXB4YX67.js +0 -111
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/fetch/utils.d.ts +0 -6
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
- package/dist/src/adapters/node/utils.d.ts +0 -5
- package/dist/src/adapters/standard/handler.d.ts +0 -47
- package/dist/src/adapters/standard/index.d.ts +0 -7
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
- package/dist/src/adapters/standard/types.d.ts +0 -44
- package/dist/src/plugins/base.d.ts +0 -11
- package/dist/src/plugins/cors.d.ts +0 -18
- package/dist/src/plugins/index.d.ts +0 -4
- package/dist/src/plugins/response-headers.d.ts +0 -10
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -17
package/dist/node.js
CHANGED
@@ -1,175 +1,87 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
} from "./chunk-CVIWJKJC.js";
|
6
|
-
import "./chunk-NOA3GBJQ.js";
|
7
|
-
import "./chunk-OXB4YX67.js";
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-ESTRJAOX.js";
|
4
|
+
import "./chunk-KK4SDLC7.js";
|
8
5
|
|
9
|
-
// src/adapters/node/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
+
});
|
15
12
|
const method = req.method ?? "GET";
|
13
|
+
const headers = createHeaders(req);
|
16
14
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
17
|
-
const host =
|
15
|
+
const host = headers.get("Host") ?? "localhost";
|
18
16
|
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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");
|
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
|
+
});
|
54
27
|
}
|
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
28
|
});
|
87
|
-
|
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");
|
29
|
+
init.duplex = "half";
|
101
30
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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);
|
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]);
|
118
38
|
}
|
119
|
-
return
|
39
|
+
return headers;
|
120
40
|
}
|
121
|
-
function
|
122
|
-
const
|
123
|
-
|
124
|
-
headers
|
125
|
-
|
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];
|
49
|
+
}
|
50
|
+
} else {
|
51
|
+
headers[key] = value;
|
126
52
|
}
|
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
53
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
chunks.push(chunk);
|
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
|
+
}
|
141
59
|
}
|
142
|
-
|
143
|
-
}
|
144
|
-
function nodeHttpResponseToAbortSignal(res) {
|
145
|
-
const controller = new AbortController();
|
146
|
-
res.on("close", () => {
|
147
|
-
controller.abort();
|
148
|
-
});
|
149
|
-
return controller.signal;
|
60
|
+
res.end();
|
150
61
|
}
|
151
62
|
|
152
|
-
// src/adapters/node/
|
153
|
-
var
|
154
|
-
|
63
|
+
// src/adapters/node/orpc-handler.ts
|
64
|
+
var RPCHandler2 = class {
|
65
|
+
orpcFetchHandler;
|
155
66
|
constructor(router, options) {
|
156
|
-
|
157
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
158
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
67
|
+
this.orpcFetchHandler = new RPCHandler(router, options);
|
159
68
|
}
|
160
69
|
async handle(req, res, ...rest) {
|
161
|
-
const
|
162
|
-
const result = await this.
|
163
|
-
if (
|
70
|
+
const request = createRequest(req, res);
|
71
|
+
const result = await this.orpcFetchHandler.handle(request, ...rest);
|
72
|
+
if (result.matched === false) {
|
164
73
|
return { matched: false };
|
165
74
|
}
|
166
|
-
|
75
|
+
const context = rest[0]?.context ?? {};
|
76
|
+
await rest[0]?.beforeSend?.(result.response, context);
|
77
|
+
await sendResponse(res, result.response);
|
167
78
|
return { matched: true };
|
168
79
|
}
|
169
80
|
};
|
170
81
|
export {
|
171
|
-
RPCHandler,
|
172
|
-
|
173
|
-
|
82
|
+
RPCHandler2 as RPCHandler,
|
83
|
+
createHeaders,
|
84
|
+
createRequest,
|
85
|
+
sendResponse
|
174
86
|
};
|
175
87
|
//# sourceMappingURL=node.js.map
|
@@ -1,4 +1,6 @@
|
|
1
|
-
export * from './
|
1
|
+
export * from './orpc-handler';
|
2
|
+
export * from './orpc-payload-codec';
|
3
|
+
export * from './orpc-procedure-matcher';
|
4
|
+
export * as SuperJSON from './super-json';
|
2
5
|
export * from './types';
|
3
|
-
export * from './utils';
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { Hooks } from '@orpc/shared';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { Router } from '../../router';
|
4
|
+
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
|
+
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
+
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
+
export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
+
signal?: AbortSignal;
|
9
|
+
}> & {
|
10
|
+
procedureMatcher?: PublicORPCProcedureMatcher;
|
11
|
+
payloadCodec?: PublicORPCPayloadCodec;
|
12
|
+
};
|
13
|
+
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
+
private readonly options?;
|
15
|
+
private readonly procedureMatcher;
|
16
|
+
private readonly payloadCodec;
|
17
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
|
18
|
+
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=orpc-handler.d.ts.map
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { type HTTPMethod } from '@orpc/contract';
|
2
|
+
export declare class ORPCPayloadCodec {
|
3
|
+
/**
|
4
|
+
* If method is GET, the payload will be encoded as query string.
|
5
|
+
* If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
|
6
|
+
*/
|
7
|
+
encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
|
8
|
+
query?: URLSearchParams;
|
9
|
+
body?: FormData | string;
|
10
|
+
headers?: Headers;
|
11
|
+
method: HTTPMethod;
|
12
|
+
};
|
13
|
+
decode(re: Request | Response): Promise<unknown>;
|
14
|
+
}
|
15
|
+
export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
|
16
|
+
//# sourceMappingURL=orpc-payload-codec.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { AnyProcedure } from '../../procedure';
|
2
|
+
import type { AnyRouter } from '../../router';
|
3
|
+
export declare class ORPCProcedureMatcher {
|
4
|
+
private readonly router;
|
5
|
+
constructor(router: AnyRouter);
|
6
|
+
match(pathname: string): Promise<{
|
7
|
+
path: string[];
|
8
|
+
procedure: AnyProcedure;
|
9
|
+
} | undefined>;
|
10
|
+
}
|
11
|
+
export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
|
12
|
+
//# sourceMappingURL=orpc-procedure-matcher.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Segment } from '@orpc/shared';
|
2
|
+
export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
|
3
|
+
export type JSONMeta = [JSONExtraType, Segment[]][];
|
4
|
+
export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
|
5
|
+
data: unknown;
|
6
|
+
meta: JSONMeta;
|
7
|
+
};
|
8
|
+
export declare function deserialize({ data, meta, }: {
|
9
|
+
data: unknown;
|
10
|
+
meta: JSONMeta;
|
11
|
+
}): unknown;
|
12
|
+
//# sourceMappingURL=super-json.d.ts.map
|
@@ -1,5 +1,13 @@
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
1
2
|
import type { Context } from '../../context';
|
2
|
-
|
3
|
+
export type FetchHandleOptions<T extends Context> = {
|
4
|
+
prefix?: HTTPPath;
|
5
|
+
} & (Record<never, never> extends T ? {
|
6
|
+
context?: T;
|
7
|
+
} : {
|
8
|
+
context: T;
|
9
|
+
});
|
10
|
+
export type FetchHandleRest<T extends Context> = [options: FetchHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
3
11
|
export type FetchHandleResult = {
|
4
12
|
matched: true;
|
5
13
|
response: Response;
|
@@ -8,6 +16,6 @@ export type FetchHandleResult = {
|
|
8
16
|
response: undefined;
|
9
17
|
};
|
10
18
|
export interface FetchHandler<T extends Context> {
|
11
|
-
handle(request: Request, ...rest:
|
19
|
+
handle(request: Request, ...rest: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
12
20
|
}
|
13
21
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import type { Context as HonoContext, MiddlewareHandler } from 'hono';
|
2
2
|
import type { Context } from '../../context';
|
3
|
-
import type { FetchHandler } from '../fetch';
|
4
|
-
import type { StandardHandleOptions } from '../standard';
|
3
|
+
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
5
4
|
import { type Value } from '@orpc/shared';
|
6
|
-
export type CreateMiddlewareOptions<T extends Context> = Omit<
|
5
|
+
export type CreateMiddlewareOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
6
|
context?: Value<T, [HonoContext]>;
|
8
7
|
} : {
|
9
8
|
context: Value<T, [HonoContext]>;
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import type { NextRequest } from 'next/server';
|
2
2
|
import type { Context } from '../../context';
|
3
|
-
import type { FetchHandler } from '../fetch';
|
4
|
-
import type { StandardHandleOptions } from '../standard';
|
3
|
+
import type { FetchHandleOptions, FetchHandler } from '../fetch';
|
5
4
|
import { type Value } from '@orpc/shared';
|
6
|
-
export type ServeOptions<T extends Context> = Omit<
|
5
|
+
export type ServeOptions<T extends Context> = Omit<FetchHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
7
6
|
context?: Value<T, [NextRequest]>;
|
8
7
|
} : {
|
9
8
|
context: Value<T, [NextRequest]>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ServerResponse } from 'node:http';
|
2
|
+
import type { Context } from '../../context';
|
3
|
+
import type { Router } from '../../router';
|
4
|
+
import type { RPCHandlerOptions } from '../fetch/orpc-handler';
|
5
|
+
import type { RequestHandler, RequestHandleRest, RequestHandleResult } from './types';
|
6
|
+
import { type ExpressableIncomingMessage } from './request-listener';
|
7
|
+
export declare class RPCHandler<T extends Context> implements RequestHandler<T> {
|
8
|
+
private readonly orpcFetchHandler;
|
9
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
10
|
+
handle(req: ExpressableIncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
11
|
+
}
|
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 { HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Promisable } from '@orpc/shared';
|
1
3
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
2
|
-
import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
3
4
|
import type { Context } from '../../context';
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
};
|
12
|
-
export type
|
13
|
-
export type
|
5
|
+
export type RequestHandleOptions<T extends Context> = {
|
6
|
+
prefix?: HTTPPath;
|
7
|
+
beforeSend?(response: Response, context: T): Promisable<void>;
|
8
|
+
} & (Record<never, never> extends T ? {
|
9
|
+
context?: T;
|
10
|
+
} : {
|
11
|
+
context: T;
|
12
|
+
});
|
13
|
+
export type RequestHandleRest<T extends Context> = [options: RequestHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
|
14
|
+
export type RequestHandleResult = {
|
14
15
|
matched: true;
|
15
16
|
} | {
|
16
17
|
matched: false;
|
17
18
|
};
|
18
|
-
export interface
|
19
|
-
handle(req:
|
19
|
+
export interface RequestHandler<T extends Context> {
|
20
|
+
handle(req: IncomingMessage, res: ServerResponse, ...rest: RequestHandleRest<T>): Promise<RequestHandleResult>;
|
20
21
|
}
|
21
22
|
//# sourceMappingURL=types.d.ts.map
|
@@ -1,17 +1,16 @@
|
|
1
|
-
import type { AnyContractRouter, ContractProcedure,
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouter, ContractRouterToErrorMap, ORPCErrorConstructorMap } from '@orpc/contract';
|
2
2
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
3
|
import type { ProcedureImplementer } from './implementer-procedure';
|
4
4
|
import type { FlattenLazy } from './lazy-utils';
|
5
5
|
import type { Middleware } from './middleware';
|
6
6
|
import type { AdaptedRouter, Router } from './router';
|
7
|
-
export
|
8
|
-
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>,
|
7
|
+
export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : TContract extends ContractRouter<infer UMeta> ? {
|
8
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, UMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
|
9
9
|
router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
|
10
10
|
lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
|
11
11
|
default: U;
|
12
12
|
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
|
13
|
-
}
|
14
|
-
export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
13
|
+
} & {
|
15
14
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
16
|
-
});
|
15
|
+
} : never);
|
17
16
|
//# sourceMappingURL=implementer-variants.d.ts.map
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouter, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
|
2
2
|
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
3
|
import type { ProcedureImplementer } from './implementer-procedure';
|
4
4
|
import type { ImplementerInternalWithMiddlewares } from './implementer-variants';
|
@@ -7,18 +7,17 @@ import { type BuilderConfig } from './builder';
|
|
7
7
|
import { type FlattenLazy } from './lazy-utils';
|
8
8
|
import { type DecoratedMiddleware } from './middleware-decorated';
|
9
9
|
import { type AdaptedRouter, type Router } from './router';
|
10
|
-
export
|
10
|
+
export type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : TContract extends ContractRouter<infer UMeta> ? {
|
11
11
|
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
12
|
-
middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>,
|
13
|
-
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>,
|
12
|
+
middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, UMeta>;
|
13
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, UMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
|
14
14
|
router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
|
15
15
|
lazy<U extends Router<TCurrentContext, TContract>>(loader: () => Promise<{
|
16
16
|
default: U;
|
17
17
|
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
|
18
|
-
}
|
19
|
-
export type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
18
|
+
} & {
|
20
19
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
21
|
-
});
|
20
|
+
} : never);
|
22
21
|
export declare function implementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
23
22
|
export type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
24
23
|
$context<U extends Context>(): Implementer<TContract, U, U>;
|
package/dist/src/index.d.ts
CHANGED
@@ -17,7 +17,5 @@ export * from './procedure-utils';
|
|
17
17
|
export * from './router';
|
18
18
|
export * from './router-accessible-lazy';
|
19
19
|
export * from './router-client';
|
20
|
-
export
|
21
|
-
export { isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
|
22
|
-
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
20
|
+
export { isDefinedError, ORPCError, safe, type } from '@orpc/contract';
|
23
21
|
//# sourceMappingURL=index.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.0.0-next.
|
4
|
+
"version": "0.0.0-next.32cb70c",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -19,16 +19,6 @@
|
|
19
19
|
"import": "./dist/index.js",
|
20
20
|
"default": "./dist/index.js"
|
21
21
|
},
|
22
|
-
"./plugins": {
|
23
|
-
"types": "./dist/src/plugins/index.d.ts",
|
24
|
-
"import": "./dist/plugins.js",
|
25
|
-
"default": "./dist/plugins.js"
|
26
|
-
},
|
27
|
-
"./standard": {
|
28
|
-
"types": "./dist/src/adapters/standard/index.d.ts",
|
29
|
-
"import": "./dist/standard.js",
|
30
|
-
"default": "./dist/standard.js"
|
31
|
-
},
|
32
22
|
"./fetch": {
|
33
23
|
"types": "./dist/src/adapters/fetch/index.d.ts",
|
34
24
|
"import": "./dist/fetch.js",
|
@@ -63,12 +53,8 @@
|
|
63
53
|
"next": ">=14.0.0"
|
64
54
|
},
|
65
55
|
"dependencies": {
|
66
|
-
"
|
67
|
-
"@orpc/
|
68
|
-
"@orpc/shared": "0.0.0-next.31590a1"
|
69
|
-
},
|
70
|
-
"devDependencies": {
|
71
|
-
"light-my-request": "^6.5.1"
|
56
|
+
"@orpc/contract": "0.0.0-next.32cb70c",
|
57
|
+
"@orpc/shared": "0.0.0-next.32cb70c"
|
72
58
|
},
|
73
59
|
"scripts": {
|
74
60
|
"build": "tsup --onSuccess='tsc -b --noCheck'",
|