@orpc/standard-server-node 0.0.0-next.ee46dab → 0.0.0-next.ee89076
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -22
- package/dist/index.d.mts +17 -25
- package/dist/index.d.ts +17 -25
- package/dist/index.mjs +60 -140
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -21,28 +21,24 @@
|
|
|
21
21
|
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
23
|
|
|
24
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Highlights
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
35
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
38
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
39
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
40
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
41
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,13 +49,14 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
54
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
56
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
57
|
-
- [@orpc/
|
|
58
|
-
- [@orpc/
|
|
59
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
60
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
56
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
57
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
61
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
62
|
-
- [@orpc/
|
|
59
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
63
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
64
61
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
65
62
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
2
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
|
+
import Stream, { Readable } from 'node:stream';
|
|
2
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
4
|
-
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
eventIteratorKeepAliveEnabled?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
16
|
-
*
|
|
17
|
-
* @default 5000
|
|
18
|
-
*/
|
|
19
|
-
eventIteratorKeepAliveInterval?: number;
|
|
20
|
-
/**
|
|
21
|
-
* The content of the ping comment. Must not include newline characters.
|
|
22
|
-
*
|
|
23
|
-
* @default ''
|
|
24
|
-
*/
|
|
25
|
-
eventIteratorKeepAliveComment?: string;
|
|
7
|
+
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
8
|
+
}
|
|
9
|
+
declare function toEventIterator(stream: Readable, options?: ToEventIteratorOptions): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
10
|
+
interface ToEventStreamOptions extends ToEventStreamOptions$1 {
|
|
26
11
|
}
|
|
27
12
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): Readable;
|
|
28
13
|
|
|
@@ -35,7 +20,9 @@ type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
|
|
35
20
|
};
|
|
36
21
|
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
|
37
22
|
|
|
38
|
-
|
|
23
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
24
|
+
}
|
|
25
|
+
declare function toStandardBody(req: NodeHttpRequest, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
39
26
|
interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
40
27
|
}
|
|
41
28
|
/**
|
|
@@ -45,12 +32,17 @@ interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
|
45
32
|
*/
|
|
46
33
|
declare function toNodeHttpBody(body: StandardBody, headers: StandardHeaders, options?: ToNodeHttpBodyOptions): Readable | undefined | string;
|
|
47
34
|
|
|
35
|
+
declare function toStandardMethod(method: string | undefined): string;
|
|
36
|
+
|
|
48
37
|
declare function toStandardLazyRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardLazyRequest;
|
|
49
38
|
|
|
50
39
|
interface SendStandardResponseOptions extends ToNodeHttpBodyOptions {
|
|
51
40
|
}
|
|
52
41
|
declare function sendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
53
42
|
|
|
54
|
-
declare function toAbortSignal(
|
|
43
|
+
declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
44
|
+
|
|
45
|
+
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
55
46
|
|
|
56
|
-
export {
|
|
47
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
48
|
+
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
2
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
|
+
import Stream, { Readable } from 'node:stream';
|
|
2
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
4
|
-
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @default true
|
|
12
|
-
*/
|
|
13
|
-
eventIteratorKeepAliveEnabled?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
16
|
-
*
|
|
17
|
-
* @default 5000
|
|
18
|
-
*/
|
|
19
|
-
eventIteratorKeepAliveInterval?: number;
|
|
20
|
-
/**
|
|
21
|
-
* The content of the ping comment. Must not include newline characters.
|
|
22
|
-
*
|
|
23
|
-
* @default ''
|
|
24
|
-
*/
|
|
25
|
-
eventIteratorKeepAliveComment?: string;
|
|
7
|
+
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
8
|
+
}
|
|
9
|
+
declare function toEventIterator(stream: Readable, options?: ToEventIteratorOptions): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
10
|
+
interface ToEventStreamOptions extends ToEventStreamOptions$1 {
|
|
26
11
|
}
|
|
27
12
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): Readable;
|
|
28
13
|
|
|
@@ -35,7 +20,9 @@ type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
|
|
35
20
|
};
|
|
36
21
|
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
|
37
22
|
|
|
38
|
-
|
|
23
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
24
|
+
}
|
|
25
|
+
declare function toStandardBody(req: NodeHttpRequest, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
39
26
|
interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
40
27
|
}
|
|
41
28
|
/**
|
|
@@ -45,12 +32,17 @@ interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
|
45
32
|
*/
|
|
46
33
|
declare function toNodeHttpBody(body: StandardBody, headers: StandardHeaders, options?: ToNodeHttpBodyOptions): Readable | undefined | string;
|
|
47
34
|
|
|
35
|
+
declare function toStandardMethod(method: string | undefined): string;
|
|
36
|
+
|
|
48
37
|
declare function toStandardLazyRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardLazyRequest;
|
|
49
38
|
|
|
50
39
|
interface SendStandardResponseOptions extends ToNodeHttpBodyOptions {
|
|
51
40
|
}
|
|
52
41
|
declare function sendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
53
42
|
|
|
54
|
-
declare function toAbortSignal(
|
|
43
|
+
declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
44
|
+
|
|
45
|
+
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
55
46
|
|
|
56
|
-
export {
|
|
47
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
48
|
+
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,129 +1,45 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { runWithSpan, parseEmptyableJSON, isAsyncIteratorObject, stringifyJSON, AbortError, once } from '@orpc/shared';
|
|
3
|
+
import { getFilenameFromContentDisposition, flattenHeader, generateContentDisposition } from '@orpc/standard-server';
|
|
4
|
+
import { toEventIterator as toEventIterator$1, toEventStream as toEventStream$1 } from '@orpc/standard-server-fetch';
|
|
4
5
|
|
|
5
|
-
function toEventIterator(stream) {
|
|
6
|
-
|
|
7
|
-
const reader = eventStream.getReader();
|
|
8
|
-
async function* gen() {
|
|
9
|
-
try {
|
|
10
|
-
while (true) {
|
|
11
|
-
const { done, value } = await reader.read();
|
|
12
|
-
if (done) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
switch (value.event) {
|
|
16
|
-
case "message": {
|
|
17
|
-
let message = parseEmptyableJSON(value.data);
|
|
18
|
-
if (isTypescriptObject(message)) {
|
|
19
|
-
message = withEventMeta(message, value);
|
|
20
|
-
}
|
|
21
|
-
yield message;
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
case "error": {
|
|
25
|
-
let error = new ErrorEvent({
|
|
26
|
-
data: parseEmptyableJSON(value.data)
|
|
27
|
-
});
|
|
28
|
-
error = withEventMeta(error, value);
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
case "done": {
|
|
32
|
-
let done2 = parseEmptyableJSON(value.data);
|
|
33
|
-
if (isTypescriptObject(done2)) {
|
|
34
|
-
done2 = withEventMeta(done2, value);
|
|
35
|
-
}
|
|
36
|
-
return done2;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
} finally {
|
|
41
|
-
await reader.cancel();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return gen();
|
|
6
|
+
function toEventIterator(stream, options = {}) {
|
|
7
|
+
return toEventIterator$1(Readable.toWeb(stream), options);
|
|
45
8
|
}
|
|
46
9
|
function toEventStream(iterator, options = {}) {
|
|
47
|
-
|
|
48
|
-
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
49
|
-
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
50
|
-
let timeout;
|
|
51
|
-
const stream = new ReadableStream({
|
|
52
|
-
async pull(controller) {
|
|
53
|
-
try {
|
|
54
|
-
if (keepAliveEnabled) {
|
|
55
|
-
timeout = setInterval(() => {
|
|
56
|
-
controller.enqueue(encodeEventMessage({
|
|
57
|
-
comments: [keepAliveComment]
|
|
58
|
-
}));
|
|
59
|
-
}, keepAliveInterval);
|
|
60
|
-
}
|
|
61
|
-
const value = await iterator.next();
|
|
62
|
-
clearInterval(timeout);
|
|
63
|
-
const meta = getEventMeta(value.value);
|
|
64
|
-
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
65
|
-
controller.enqueue(encodeEventMessage({
|
|
66
|
-
...meta,
|
|
67
|
-
event: value.done ? "done" : "message",
|
|
68
|
-
data: stringifyJSON(value.value)
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
if (value.done) {
|
|
72
|
-
controller.close();
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
clearInterval(timeout);
|
|
76
|
-
controller.enqueue(encodeEventMessage({
|
|
77
|
-
...getEventMeta(err),
|
|
78
|
-
event: "error",
|
|
79
|
-
data: err instanceof ErrorEvent ? stringifyJSON(err.data) : void 0
|
|
80
|
-
}));
|
|
81
|
-
controller.close();
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
async cancel(reason) {
|
|
85
|
-
if (reason) {
|
|
86
|
-
await iterator.throw?.(reason);
|
|
87
|
-
} else {
|
|
88
|
-
await iterator.return?.();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return Readable.fromWeb(stream);
|
|
10
|
+
return Readable.fromWeb(toEventStream$1(iterator, options));
|
|
93
11
|
}
|
|
94
12
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
return _streamToFile(req, "blob", contentType);
|
|
13
|
+
function toStandardBody(req, options = {}) {
|
|
14
|
+
return runWithSpan({ name: "parse_standard_body", signal: options.signal }, async () => {
|
|
15
|
+
const contentDisposition = req.headers["content-disposition"];
|
|
16
|
+
const contentType = req.headers["content-type"];
|
|
17
|
+
if (typeof contentDisposition === "string") {
|
|
18
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
19
|
+
return _streamToFile(req, fileName, contentType ?? "");
|
|
20
|
+
}
|
|
21
|
+
if (!contentType || contentType.startsWith("application/json")) {
|
|
22
|
+
const text = await _streamToString(req);
|
|
23
|
+
return parseEmptyableJSON(text);
|
|
24
|
+
}
|
|
25
|
+
if (contentType.startsWith("multipart/form-data")) {
|
|
26
|
+
return _streamToFormData(req, contentType);
|
|
27
|
+
}
|
|
28
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
29
|
+
const text = await _streamToString(req);
|
|
30
|
+
return new URLSearchParams(text);
|
|
31
|
+
}
|
|
32
|
+
if (contentType.startsWith("text/event-stream")) {
|
|
33
|
+
return toEventIterator(req, options);
|
|
34
|
+
}
|
|
35
|
+
if (contentType.startsWith("text/plain")) {
|
|
36
|
+
return _streamToString(req);
|
|
37
|
+
}
|
|
38
|
+
return _streamToFile(req, "blob", contentType);
|
|
39
|
+
});
|
|
124
40
|
}
|
|
125
41
|
function toNodeHttpBody(body, headers, options = {}) {
|
|
126
|
-
const currentContentDisposition =
|
|
42
|
+
const currentContentDisposition = flattenHeader(headers["content-disposition"]);
|
|
127
43
|
delete headers["content-type"];
|
|
128
44
|
delete headers["content-disposition"];
|
|
129
45
|
if (body === void 0) {
|
|
@@ -146,8 +62,6 @@ function toNodeHttpBody(body, headers, options = {}) {
|
|
|
146
62
|
}
|
|
147
63
|
if (isAsyncIteratorObject(body)) {
|
|
148
64
|
headers["content-type"] = "text/event-stream";
|
|
149
|
-
headers["cache-control"] = "no-cache";
|
|
150
|
-
headers.connection = "keep-alive";
|
|
151
65
|
return toEventStream(body, options);
|
|
152
66
|
}
|
|
153
67
|
headers["content-type"] = "application/json";
|
|
@@ -176,54 +90,60 @@ async function _streamToFile(stream, fileName, contentType) {
|
|
|
176
90
|
return new File(chunks, fileName, { type: contentType });
|
|
177
91
|
}
|
|
178
92
|
|
|
179
|
-
function
|
|
93
|
+
function toStandardMethod(method) {
|
|
94
|
+
return method ?? "GET";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toAbortSignal(stream) {
|
|
180
98
|
const controller = new AbortController();
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
controller.abort("Client connection prematurely closed.");
|
|
186
|
-
} else {
|
|
187
|
-
controller.abort("Server closed the connection.");
|
|
99
|
+
stream.once("error", (error) => controller.abort(error));
|
|
100
|
+
stream.once("close", () => {
|
|
101
|
+
if (!stream.writableFinished) {
|
|
102
|
+
controller.abort(new AbortError("Writable stream closed before it finished writing"));
|
|
188
103
|
}
|
|
189
104
|
});
|
|
190
105
|
return controller.signal;
|
|
191
106
|
}
|
|
192
107
|
|
|
193
|
-
function
|
|
194
|
-
const method = req.method ?? "GET";
|
|
108
|
+
function toStandardUrl(req) {
|
|
195
109
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
|
196
110
|
const host = req.headers.host ?? "localhost";
|
|
197
111
|
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
|
112
|
+
return url;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function toStandardLazyRequest(req, res) {
|
|
116
|
+
const signal = toAbortSignal(res);
|
|
198
117
|
return {
|
|
199
|
-
method,
|
|
200
|
-
url,
|
|
118
|
+
method: toStandardMethod(req.method),
|
|
119
|
+
url: toStandardUrl(req),
|
|
201
120
|
headers: req.headers,
|
|
202
|
-
body: once(() => toStandardBody(req)),
|
|
203
|
-
signal
|
|
121
|
+
body: once(() => toStandardBody(req, { signal })),
|
|
122
|
+
signal
|
|
204
123
|
};
|
|
205
124
|
}
|
|
206
125
|
|
|
207
126
|
function sendStandardResponse(res, standardResponse, options = {}) {
|
|
208
127
|
return new Promise((resolve, reject) => {
|
|
209
|
-
res.
|
|
210
|
-
res.
|
|
211
|
-
const resHeaders = standardResponse.headers;
|
|
128
|
+
res.once("error", reject);
|
|
129
|
+
res.once("close", resolve);
|
|
130
|
+
const resHeaders = { ...standardResponse.headers };
|
|
212
131
|
const resBody = toNodeHttpBody(standardResponse.body, resHeaders, options);
|
|
213
132
|
res.writeHead(standardResponse.status, resHeaders);
|
|
214
133
|
if (resBody === void 0) {
|
|
215
|
-
res.end(
|
|
134
|
+
res.end();
|
|
216
135
|
} else if (typeof resBody === "string") {
|
|
217
136
|
res.end(resBody);
|
|
218
137
|
} else {
|
|
219
|
-
res.
|
|
138
|
+
res.once("close", () => {
|
|
220
139
|
if (!resBody.closed) {
|
|
221
140
|
resBody.destroy(res.errored ?? void 0);
|
|
222
141
|
}
|
|
223
142
|
});
|
|
143
|
+
resBody.once("error", (error) => res.destroy(error));
|
|
224
144
|
resBody.pipe(res);
|
|
225
145
|
}
|
|
226
146
|
});
|
|
227
147
|
}
|
|
228
148
|
|
|
229
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest };
|
|
149
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.ee89076",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/shared": "0.0.0-next.
|
|
27
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
26
|
+
"@orpc/shared": "0.0.0-next.ee89076",
|
|
27
|
+
"@orpc/standard-server-fetch": "0.0.0-next.ee89076",
|
|
28
|
+
"@orpc/standard-server": "0.0.0-next.ee89076"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@types/node": "^22.
|
|
31
|
-
"@types/supertest": "^6.0.
|
|
32
|
-
"supertest": "^7.
|
|
31
|
+
"@types/node": "^22.15.30",
|
|
32
|
+
"@types/supertest": "^6.0.3",
|
|
33
|
+
"supertest": "^7.1.4"
|
|
33
34
|
},
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "unbuild",
|