@orpc/standard-server-node 0.0.0-next.f72e6b9 → 0.0.0-next.fa75202
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 +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +43 -46
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -49,6 +49,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
49
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
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
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
|
52
53
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
53
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).
|
|
54
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,22 +84,16 @@ 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);
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
async function toStandardBody(req) {
|
|
96
|
-
const method = req.method ?? "GET";
|
|
97
|
-
if (method === "GET" || method === "HEAD") {
|
|
98
|
-
return void 0;
|
|
99
|
-
}
|
|
100
97
|
const contentDisposition = req.headers["content-disposition"];
|
|
101
98
|
const contentType = req.headers["content-type"];
|
|
102
99
|
if (typeof contentDisposition === "string") {
|
|
@@ -123,7 +120,7 @@ async function toStandardBody(req) {
|
|
|
123
120
|
return _streamToFile(req, "blob", contentType);
|
|
124
121
|
}
|
|
125
122
|
function toNodeHttpBody(body, headers, options = {}) {
|
|
126
|
-
const currentContentDisposition =
|
|
123
|
+
const currentContentDisposition = flattenHeader(headers["content-disposition"]);
|
|
127
124
|
delete headers["content-type"];
|
|
128
125
|
delete headers["content-disposition"];
|
|
129
126
|
if (body === void 0) {
|
|
@@ -208,7 +205,7 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
208
205
|
return new Promise((resolve, reject) => {
|
|
209
206
|
res.on("error", reject);
|
|
210
207
|
res.on("finish", resolve);
|
|
211
|
-
const resHeaders = standardResponse.headers;
|
|
208
|
+
const resHeaders = { ...standardResponse.headers };
|
|
212
209
|
const resBody = toNodeHttpBody(standardResponse.body, resHeaders, options);
|
|
213
210
|
res.writeHead(standardResponse.status, resHeaders);
|
|
214
211
|
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.fa75202",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/
|
|
27
|
-
"@orpc/
|
|
26
|
+
"@orpc/shared": "0.0.0-next.fa75202",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.fa75202"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "^22.
|
|
30
|
+
"@types/node": "^22.15.17",
|
|
31
31
|
"@types/supertest": "^6.0.3",
|
|
32
32
|
"supertest": "^7.1.0"
|
|
33
33
|
},
|