@orpc/standard-server-fetch 0.0.0-next.f9e0a4c → 0.0.0-next.f9e5dec
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 -1
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +16 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -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>
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
36
|
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
35
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -54,6 +57,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
54
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
55
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
59
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
57
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
58
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
59
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
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 {
|
|
@@ -211,7 +223,7 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
211
223
|
}
|
|
212
224
|
|
|
213
225
|
function toStandardHeaders(headers, standardHeaders = {}) {
|
|
214
|
-
|
|
226
|
+
headers.forEach((value, key) => {
|
|
215
227
|
if (Array.isArray(standardHeaders[key])) {
|
|
216
228
|
standardHeaders[key].push(value);
|
|
217
229
|
} else if (standardHeaders[key] !== void 0) {
|
|
@@ -219,7 +231,7 @@ function toStandardHeaders(headers, standardHeaders = {}) {
|
|
|
219
231
|
} else {
|
|
220
232
|
standardHeaders[key] = value;
|
|
221
233
|
}
|
|
222
|
-
}
|
|
234
|
+
});
|
|
223
235
|
return standardHeaders;
|
|
224
236
|
}
|
|
225
237
|
function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
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.f9e5dec",
|
|
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/shared": "0.0.0-next.
|
|
27
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
26
|
+
"@orpc/shared": "0.0.0-next.f9e5dec",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.f9e5dec"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@hono/node-server": "^1.
|
|
30
|
+
"@hono/node-server": "^1.19.6"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "unbuild",
|