@orpc/standard-server-fetch 0.0.0-next.c788572 → 0.0.0-next.c84c835
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 -6
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +46 -47
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
31
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
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.
|
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
34
34
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
35
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
36
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -49,13 +49,12 @@ 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/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
53
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
52
54
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
53
|
-
- [@orpc/
|
|
54
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
55
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
56
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
55
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
57
56
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
58
|
-
- [@orpc/
|
|
57
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
59
58
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
60
59
|
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
61
60
|
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
2
3
|
|
|
3
|
-
declare function toEventIterator(stream: ReadableStream<Uint8Array>):
|
|
4
|
+
declare function toEventIterator(stream: ReadableStream<Uint8Array> | null): AsyncIteratorClass<unknown>;
|
|
4
5
|
interface ToEventStreamOptions {
|
|
5
6
|
/**
|
|
6
7
|
* If true, a ping comment is sent periodically to keep the connection alive.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
2
3
|
|
|
3
|
-
declare function toEventIterator(stream: ReadableStream<Uint8Array>):
|
|
4
|
+
declare function toEventIterator(stream: ReadableStream<Uint8Array> | null): AsyncIteratorClass<unknown>;
|
|
4
5
|
interface ToEventStreamOptions {
|
|
5
6
|
/**
|
|
6
7
|
* 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 { AsyncIteratorClass, 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
|
-
|
|
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 new AsyncIteratorClass(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) {
|
|
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";
|
|
@@ -150,8 +151,6 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
150
151
|
}
|
|
151
152
|
if (isAsyncIteratorObject(body)) {
|
|
152
153
|
headers.set("content-type", "text/event-stream");
|
|
153
|
-
headers.set("cache-control", "no-cache");
|
|
154
|
-
headers.set("connection", "keep-alive");
|
|
155
154
|
return toEventStream(body, options);
|
|
156
155
|
}
|
|
157
156
|
headers.set("content-type", "application/json");
|
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.c84c835",
|
|
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.c84c835",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.c84c835"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@hono/node-server": "^1.
|
|
30
|
+
"@hono/node-server": "^1.15.0"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "unbuild",
|