@orpc/standard-server-fetch 0.0.0-next.ee89076 → 0.0.0-next.f01f7b1
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 +5 -2
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +14 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -42,7 +45,7 @@
|
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,19 @@ interface ToEventStreamOptions {
|
|
|
23
23
|
* @default ''
|
|
24
24
|
*/
|
|
25
25
|
eventIteratorKeepAliveComment?: string;
|
|
26
|
+
/**
|
|
27
|
+
* If true, an initial comment is sent immediately upon stream start to flush headers.
|
|
28
|
+
* This allows the receiving side to establish the connection without waiting for the first event.
|
|
29
|
+
*
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
eventIteratorInitialCommentEnabled?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The content of the initial comment sent upon stream start. Must not include newline characters.
|
|
35
|
+
*
|
|
36
|
+
* @default ''
|
|
37
|
+
*/
|
|
38
|
+
eventIteratorInitialComment?: string;
|
|
26
39
|
}
|
|
27
40
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
28
41
|
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,19 @@ interface ToEventStreamOptions {
|
|
|
23
23
|
* @default ''
|
|
24
24
|
*/
|
|
25
25
|
eventIteratorKeepAliveComment?: string;
|
|
26
|
+
/**
|
|
27
|
+
* If true, an initial comment is sent immediately upon stream start to flush headers.
|
|
28
|
+
* This allows the receiving side to establish the connection without waiting for the first event.
|
|
29
|
+
*
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
eventIteratorInitialCommentEnabled?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The content of the initial comment sent upon stream start. Must not include newline characters.
|
|
35
|
+
*
|
|
36
|
+
* @default ''
|
|
37
|
+
*/
|
|
38
|
+
eventIteratorInitialComment?: string;
|
|
26
39
|
}
|
|
27
40
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
28
41
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AsyncIteratorClass, startSpan, runInSpanContext, parseEmptyableJSON, isTypescriptObject, setSpanError, stringifyJSON, runWithSpan, isAsyncIteratorObject, once } from '@orpc/shared';
|
|
1
|
+
import { AsyncIteratorClass, startSpan, runInSpanContext, AbortError, parseEmptyableJSON, isTypescriptObject, setSpanError, stringifyJSON, runWithSpan, isAsyncIteratorObject, once } from '@orpc/shared';
|
|
2
2
|
import { EventDecoderStream, withEventMeta, ErrorEvent, encodeEventMessage, getEventMeta, getFilenameFromContentDisposition, generateContentDisposition } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
4
|
function toEventIterator(stream, options = {}) {
|
|
5
5
|
const eventStream = stream?.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
6
6
|
const reader = eventStream?.getReader();
|
|
7
7
|
let span;
|
|
8
|
+
let isCancelled = false;
|
|
8
9
|
return new AsyncIteratorClass(async () => {
|
|
9
10
|
span ??= startSpan("consume_event_iterator_stream");
|
|
10
11
|
try {
|
|
@@ -14,6 +15,9 @@ function toEventIterator(stream, options = {}) {
|
|
|
14
15
|
}
|
|
15
16
|
const { done, value } = await runInSpanContext(span, () => reader.read());
|
|
16
17
|
if (done) {
|
|
18
|
+
if (isCancelled) {
|
|
19
|
+
throw new AbortError("Stream was cancelled");
|
|
20
|
+
}
|
|
17
21
|
return { done: true, value: void 0 };
|
|
18
22
|
}
|
|
19
23
|
switch (value.event) {
|
|
@@ -55,6 +59,7 @@ function toEventIterator(stream, options = {}) {
|
|
|
55
59
|
}, async (reason) => {
|
|
56
60
|
try {
|
|
57
61
|
if (reason !== "next") {
|
|
62
|
+
isCancelled = true;
|
|
58
63
|
span?.addEvent("cancelled");
|
|
59
64
|
}
|
|
60
65
|
await runInSpanContext(span, () => reader?.cancel());
|
|
@@ -70,12 +75,19 @@ function toEventStream(iterator, options = {}) {
|
|
|
70
75
|
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
71
76
|
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
72
77
|
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
78
|
+
const initialCommentEnabled = options.eventIteratorInitialCommentEnabled ?? true;
|
|
79
|
+
const initialComment = options.eventIteratorInitialComment ?? "";
|
|
73
80
|
let cancelled = false;
|
|
74
81
|
let timeout;
|
|
75
82
|
let span;
|
|
76
83
|
const stream = new ReadableStream({
|
|
77
|
-
start() {
|
|
84
|
+
start(controller) {
|
|
78
85
|
span = startSpan("stream_event_iterator");
|
|
86
|
+
if (initialCommentEnabled) {
|
|
87
|
+
controller.enqueue(encodeEventMessage({
|
|
88
|
+
comments: [initialComment]
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
79
91
|
},
|
|
80
92
|
async pull(controller) {
|
|
81
93
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-fetch",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f01f7b1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/
|
|
27
|
-
"@orpc/
|
|
26
|
+
"@orpc/standard-server": "0.0.0-next.f01f7b1",
|
|
27
|
+
"@orpc/shared": "0.0.0-next.f01f7b1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@hono/node-server": "^1.19.
|
|
30
|
+
"@hono/node-server": "^1.19.6"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "unbuild",
|