@orpc/standard-server-node 0.0.0-next.f81b4a2 → 0.0.0-next.fcb9d5a
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 +14 -17
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +43 -42
- package/package.json +3 -3
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
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,6 +49,7 @@ 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/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
|
56
53
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
57
54
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
58
55
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { Readable } from 'node:stream';
|
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
4
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
5
5
|
|
|
6
|
-
declare function toEventIterator(stream: Readable): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
6
|
+
declare function toEventIterator(stream: Readable): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
7
7
|
interface ToEventStreamOptions {
|
|
8
8
|
/**
|
|
9
9
|
* If true, a ping comment is sent periodically to keep the connection alive.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Readable } from 'node:stream';
|
|
|
3
3
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
4
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
5
5
|
|
|
6
|
-
declare function toEventIterator(stream: Readable): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
6
|
+
declare function toEventIterator(stream: Readable): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
7
7
|
interface ToEventStreamOptions {
|
|
8
8
|
/**
|
|
9
9
|
* If true, a ping comment is sent periodically to keep the connection alive.
|
package/dist/index.mjs
CHANGED
|
@@ -1,52 +1,49 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import {
|
|
3
|
-
import { EventDecoderStream,
|
|
2
|
+
import { createAsyncIteratorObject, parseEmptyableJSON, isTypescriptObject, stringifyJSON, isAsyncIteratorObject, once } from '@orpc/shared';
|
|
3
|
+
import { EventDecoderStream, withEventMeta, ErrorEvent, encodeEventMessage, getEventMeta, getFilenameFromContentDisposition, flattenHeader, generateContentDisposition } from '@orpc/standard-server';
|
|
4
4
|
|
|
5
5
|
function toEventIterator(stream) {
|
|
6
6
|
const eventStream = Readable.toWeb(stream).pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
7
7
|
const reader = eventStream.getReader();
|
|
8
|
-
async
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
8
|
+
return createAsyncIteratorObject(async () => {
|
|
9
|
+
while (true) {
|
|
10
|
+
const { done, value } = await reader.read();
|
|
11
|
+
if (done) {
|
|
12
|
+
return { done: true, value: void 0 };
|
|
13
|
+
}
|
|
14
|
+
switch (value.event) {
|
|
15
|
+
case "message": {
|
|
16
|
+
let message = parseEmptyableJSON(value.data);
|
|
17
|
+
if (isTypescriptObject(message)) {
|
|
18
|
+
message = withEventMeta(message, value);
|
|
30
19
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
return { done: false, value: message };
|
|
21
|
+
}
|
|
22
|
+
case "error": {
|
|
23
|
+
let error = new ErrorEvent({
|
|
24
|
+
data: parseEmptyableJSON(value.data)
|
|
25
|
+
});
|
|
26
|
+
error = withEventMeta(error, value);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
case "done": {
|
|
30
|
+
let done2 = parseEmptyableJSON(value.data);
|
|
31
|
+
if (isTypescriptObject(done2)) {
|
|
32
|
+
done2 = withEventMeta(done2, value);
|
|
37
33
|
}
|
|
34
|
+
return { done: true, value: done2 };
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
} finally {
|
|
41
|
-
await reader.cancel();
|
|
42
37
|
}
|
|
43
|
-
}
|
|
44
|
-
|
|
38
|
+
}, async () => {
|
|
39
|
+
await reader.cancel();
|
|
40
|
+
});
|
|
45
41
|
}
|
|
46
42
|
function toEventStream(iterator, options = {}) {
|
|
47
43
|
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
48
44
|
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
49
45
|
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
46
|
+
let cancelled = false;
|
|
50
47
|
let timeout;
|
|
51
48
|
const stream = new ReadableStream({
|
|
52
49
|
async pull(controller) {
|
|
@@ -60,6 +57,9 @@ function toEventStream(iterator, options = {}) {
|
|
|
60
57
|
}
|
|
61
58
|
const value = await iterator.next();
|
|
62
59
|
clearInterval(timeout);
|
|
60
|
+
if (cancelled) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
63
|
const meta = getEventMeta(value.value);
|
|
64
64
|
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
65
65
|
controller.enqueue(encodeEventMessage({
|
|
@@ -73,6 +73,9 @@ function toEventStream(iterator, options = {}) {
|
|
|
73
73
|
}
|
|
74
74
|
} catch (err) {
|
|
75
75
|
clearInterval(timeout);
|
|
76
|
+
if (cancelled) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
76
79
|
controller.enqueue(encodeEventMessage({
|
|
77
80
|
...getEventMeta(err),
|
|
78
81
|
event: "error",
|
|
@@ -81,12 +84,10 @@ function toEventStream(iterator, options = {}) {
|
|
|
81
84
|
controller.close();
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
|
-
async cancel(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
await iterator.return?.();
|
|
89
|
-
}
|
|
87
|
+
async cancel() {
|
|
88
|
+
cancelled = true;
|
|
89
|
+
clearInterval(timeout);
|
|
90
|
+
await iterator.return?.();
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
93
|
return Readable.fromWeb(stream);
|
|
@@ -123,7 +124,7 @@ async function toStandardBody(req) {
|
|
|
123
124
|
return _streamToFile(req, "blob", contentType);
|
|
124
125
|
}
|
|
125
126
|
function toNodeHttpBody(body, headers, options = {}) {
|
|
126
|
-
const currentContentDisposition =
|
|
127
|
+
const currentContentDisposition = flattenHeader(headers["content-disposition"]);
|
|
127
128
|
delete headers["content-type"];
|
|
128
129
|
delete headers["content-disposition"];
|
|
129
130
|
if (body === void 0) {
|
|
@@ -208,7 +209,7 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
208
209
|
return new Promise((resolve, reject) => {
|
|
209
210
|
res.on("error", reject);
|
|
210
211
|
res.on("finish", resolve);
|
|
211
|
-
const resHeaders = standardResponse.headers;
|
|
212
|
+
const resHeaders = { ...standardResponse.headers };
|
|
212
213
|
const resBody = toNodeHttpBody(standardResponse.body, resHeaders, options);
|
|
213
214
|
res.writeHead(standardResponse.status, resHeaders);
|
|
214
215
|
if (resBody === void 0) {
|
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.fcb9d5a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,8 +23,8 @@
|
|
|
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.fcb9d5a",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.fcb9d5a"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.14.1",
|