@orpc/standard-server-fetch 1.1.1 → 1.3.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 +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +46 -45
- package/package.json +3 -3
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
2
|
|
|
3
|
-
declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
3
|
+
declare function toEventIterator(stream: ReadableStream<Uint8Array> | null): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
4
4
|
interface ToEventStreamOptions {
|
|
5
5
|
/**
|
|
6
6
|
* If true, a ping comment is sent periodically to keep the connection alive.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
2
|
|
|
3
|
-
declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
3
|
+
declare function toEventIterator(stream: ReadableStream<Uint8Array> | null): AsyncIteratorObject<unknown | void, unknown | void, void> & AsyncGenerator<unknown | void, unknown | void, void>;
|
|
4
4
|
interface ToEventStreamOptions {
|
|
5
5
|
/**
|
|
6
6
|
* If true, a ping comment is sent periodically to keep the connection alive.
|
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EventDecoderStream,
|
|
1
|
+
import { createAsyncIteratorObject, parseEmptyableJSON, isTypescriptObject, stringifyJSON, isAsyncIteratorObject, once } from '@orpc/shared';
|
|
2
|
+
import { EventDecoderStream, withEventMeta, ErrorEvent, encodeEventMessage, getEventMeta, getFilenameFromContentDisposition, generateContentDisposition } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
4
|
function toEventIterator(stream) {
|
|
5
|
-
const eventStream = stream
|
|
6
|
-
const reader = eventStream
|
|
7
|
-
async
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
case "error": {
|
|
24
|
-
let error = new ErrorEvent({
|
|
25
|
-
data: parseEmptyableJSON(value.data)
|
|
26
|
-
});
|
|
27
|
-
error = withEventMeta(error, value);
|
|
28
|
-
throw error;
|
|
5
|
+
const eventStream = stream?.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
6
|
+
const reader = eventStream?.getReader();
|
|
7
|
+
return createAsyncIteratorObject(async () => {
|
|
8
|
+
while (true) {
|
|
9
|
+
if (reader === void 0) {
|
|
10
|
+
return { done: true, value: void 0 };
|
|
11
|
+
}
|
|
12
|
+
const { done, value } = await reader.read();
|
|
13
|
+
if (done) {
|
|
14
|
+
return { done: true, value: void 0 };
|
|
15
|
+
}
|
|
16
|
+
switch (value.event) {
|
|
17
|
+
case "message": {
|
|
18
|
+
let message = parseEmptyableJSON(value.data);
|
|
19
|
+
if (isTypescriptObject(message)) {
|
|
20
|
+
message = withEventMeta(message, value);
|
|
29
21
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
return { done: false, value: message };
|
|
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);
|
|
36
35
|
}
|
|
36
|
+
return { done: true, value: done2 };
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
} finally {
|
|
40
|
-
await reader.cancel();
|
|
41
39
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
40
|
+
}, async () => {
|
|
41
|
+
await reader?.cancel();
|
|
42
|
+
});
|
|
44
43
|
}
|
|
45
44
|
function toEventStream(iterator, options = {}) {
|
|
46
45
|
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
47
46
|
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
48
47
|
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
48
|
+
let cancelled = false;
|
|
49
49
|
let timeout;
|
|
50
50
|
const stream = new ReadableStream({
|
|
51
51
|
async pull(controller) {
|
|
@@ -59,6 +59,9 @@ function toEventStream(iterator, options = {}) {
|
|
|
59
59
|
}
|
|
60
60
|
const value = await iterator.next();
|
|
61
61
|
clearInterval(timeout);
|
|
62
|
+
if (cancelled) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
62
65
|
const meta = getEventMeta(value.value);
|
|
63
66
|
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
64
67
|
controller.enqueue(encodeEventMessage({
|
|
@@ -72,6 +75,9 @@ function toEventStream(iterator, options = {}) {
|
|
|
72
75
|
}
|
|
73
76
|
} catch (err) {
|
|
74
77
|
clearInterval(timeout);
|
|
78
|
+
if (cancelled) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
75
81
|
controller.enqueue(encodeEventMessage({
|
|
76
82
|
...getEventMeta(err),
|
|
77
83
|
event: "error",
|
|
@@ -80,21 +86,16 @@ function toEventStream(iterator, options = {}) {
|
|
|
80
86
|
controller.close();
|
|
81
87
|
}
|
|
82
88
|
},
|
|
83
|
-
async cancel(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await iterator.return?.();
|
|
88
|
-
}
|
|
89
|
+
async cancel() {
|
|
90
|
+
cancelled = true;
|
|
91
|
+
clearInterval(timeout);
|
|
92
|
+
await iterator.return?.();
|
|
89
93
|
}
|
|
90
94
|
}).pipeThrough(new TextEncoderStream());
|
|
91
95
|
return stream;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
async function toStandardBody(re) {
|
|
95
|
-
if (re.body === null) {
|
|
96
|
-
return void 0;
|
|
97
|
-
}
|
|
98
99
|
const contentDisposition = re.headers.get("content-disposition");
|
|
99
100
|
if (typeof contentDisposition === "string") {
|
|
100
101
|
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-fetch",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/shared": "1.
|
|
27
|
-
"@orpc/standard-server": "1.
|
|
26
|
+
"@orpc/shared": "1.3.0",
|
|
27
|
+
"@orpc/standard-server": "1.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@hono/node-server": "^1.14.1"
|