@orpc/standard-server-node 1.7.10 → 1.8.0
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 +2 -1
- package/dist/index.d.mts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.mjs +34 -31
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
32
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
33
34
|
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
34
35
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
36
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
@@ -38,7 +39,6 @@
|
|
|
38
39
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
40
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
41
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
42
|
|
|
43
43
|
## Documentation
|
|
44
44
|
|
|
@@ -50,6 +50,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
50
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
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.
|
|
53
54
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
55
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
56
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
2
|
-
import { ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
2
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
3
|
import Stream, { Readable } from 'node:stream';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
6
6
|
|
|
7
|
-
|
|
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>;
|
|
8
10
|
interface ToEventStreamOptions extends ToEventStreamOptions$1 {
|
|
9
11
|
}
|
|
10
12
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): Readable;
|
|
@@ -18,7 +20,9 @@ type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
|
|
18
20
|
};
|
|
19
21
|
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
24
|
+
}
|
|
25
|
+
declare function toStandardBody(req: NodeHttpRequest, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
22
26
|
interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
@@ -41,4 +45,4 @@ declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
|
41
45
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
42
46
|
|
|
43
47
|
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
44
|
-
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventStreamOptions, ToNodeHttpBodyOptions };
|
|
48
|
+
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
2
|
-
import { ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
2
|
+
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
3
|
import Stream, { Readable } from 'node:stream';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
6
6
|
|
|
7
|
-
|
|
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>;
|
|
8
10
|
interface ToEventStreamOptions extends ToEventStreamOptions$1 {
|
|
9
11
|
}
|
|
10
12
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): Readable;
|
|
@@ -18,7 +20,9 @@ type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
|
|
18
20
|
};
|
|
19
21
|
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
interface ToStandardBodyOptions extends ToEventIteratorOptions {
|
|
24
|
+
}
|
|
25
|
+
declare function toStandardBody(req: NodeHttpRequest, options?: ToStandardBodyOptions): Promise<StandardBody>;
|
|
22
26
|
interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
@@ -41,4 +45,4 @@ declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
|
41
45
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
42
46
|
|
|
43
47
|
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
44
|
-
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventStreamOptions, ToNodeHttpBodyOptions };
|
|
48
|
+
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import { parseEmptyableJSON, isAsyncIteratorObject, stringifyJSON, once } from '@orpc/shared';
|
|
2
|
+
import { runWithSpan, parseEmptyableJSON, isAsyncIteratorObject, stringifyJSON, AbortError, once } from '@orpc/shared';
|
|
3
3
|
import { getFilenameFromContentDisposition, flattenHeader, generateContentDisposition } from '@orpc/standard-server';
|
|
4
4
|
import { toEventIterator as toEventIterator$1, toEventStream as toEventStream$1 } from '@orpc/standard-server-fetch';
|
|
5
5
|
|
|
6
|
-
function toEventIterator(stream) {
|
|
7
|
-
return toEventIterator$1(Readable.toWeb(stream));
|
|
6
|
+
function toEventIterator(stream, options = {}) {
|
|
7
|
+
return toEventIterator$1(Readable.toWeb(stream), options);
|
|
8
8
|
}
|
|
9
9
|
function toEventStream(iterator, options = {}) {
|
|
10
10
|
return Readable.fromWeb(toEventStream$1(iterator, options));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
});
|
|
38
40
|
}
|
|
39
41
|
function toNodeHttpBody(body, headers, options = {}) {
|
|
40
42
|
const currentContentDisposition = flattenHeader(headers["content-disposition"]);
|
|
@@ -97,7 +99,7 @@ function toAbortSignal(stream) {
|
|
|
97
99
|
stream.once("error", (error) => controller.abort(error));
|
|
98
100
|
stream.once("close", () => {
|
|
99
101
|
if (!stream.writableFinished) {
|
|
100
|
-
controller.abort(new
|
|
102
|
+
controller.abort(new AbortError("Writable stream closed before it finished writing"));
|
|
101
103
|
}
|
|
102
104
|
});
|
|
103
105
|
return controller.signal;
|
|
@@ -111,12 +113,13 @@ function toStandardUrl(req) {
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
function toStandardLazyRequest(req, res) {
|
|
116
|
+
const signal = toAbortSignal(res);
|
|
114
117
|
return {
|
|
115
118
|
method: toStandardMethod(req.method),
|
|
116
119
|
url: toStandardUrl(req),
|
|
117
120
|
headers: req.headers,
|
|
118
|
-
body: once(() => toStandardBody(req)),
|
|
119
|
-
signal
|
|
121
|
+
body: once(() => toStandardBody(req, { signal })),
|
|
122
|
+
signal
|
|
120
123
|
};
|
|
121
124
|
}
|
|
122
125
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/shared": "1.
|
|
27
|
-
"@orpc/standard-server-fetch": "1.
|
|
28
|
-
"@orpc/standard-server": "1.
|
|
26
|
+
"@orpc/shared": "1.8.0",
|
|
27
|
+
"@orpc/standard-server-fetch": "1.8.0",
|
|
28
|
+
"@orpc/standard-server": "1.8.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^22.15.30",
|