@orpc/standard-server-fetch 0.0.0-next.ff68fdb → 0.0.0-next.ffd5805
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 +28 -22
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +63 -64
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -21,28 +21,24 @@
|
|
|
21
21
|
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
23
|
|
|
24
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Highlights
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
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.
|
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,18 +49,28 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
56
|
-
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
|
-
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
58
|
-
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
59
|
-
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
60
|
-
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
61
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/).
|
|
54
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
56
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
62
58
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
59
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
60
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
63
61
|
|
|
64
62
|
## `@orpc/standard-server-fetch`
|
|
65
63
|
|
|
66
64
|
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) server adapter for oRPC.
|
|
67
65
|
|
|
66
|
+
## Sponsors
|
|
67
|
+
|
|
68
|
+
<p align="center">
|
|
69
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
70
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
71
|
+
</a>
|
|
72
|
+
</p>
|
|
73
|
+
|
|
68
74
|
## License
|
|
69
75
|
|
|
70
76
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
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.
|
|
@@ -53,4 +54,5 @@ interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
|
53
54
|
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
55
|
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
55
56
|
|
|
56
|
-
export {
|
|
57
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
58
|
+
export type { ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions };
|
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.
|
|
@@ -53,4 +54,5 @@ interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
|
53
54
|
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
55
|
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
55
56
|
|
|
56
|
-
export {
|
|
57
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
58
|
+
export type { ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions };
|
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,16 +59,25 @@ function toEventStream(iterator, options = {}) {
|
|
|
59
59
|
}
|
|
60
60
|
const value = await iterator.next();
|
|
61
61
|
clearInterval(timeout);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
if (cancelled) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const meta = getEventMeta(value.value);
|
|
66
|
+
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
67
|
+
controller.enqueue(encodeEventMessage({
|
|
68
|
+
...meta,
|
|
69
|
+
event: value.done ? "done" : "message",
|
|
70
|
+
data: stringifyJSON(value.value)
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
67
73
|
if (value.done) {
|
|
68
74
|
controller.close();
|
|
69
75
|
}
|
|
70
76
|
} catch (err) {
|
|
71
77
|
clearInterval(timeout);
|
|
78
|
+
if (cancelled) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
72
81
|
controller.enqueue(encodeEventMessage({
|
|
73
82
|
...getEventMeta(err),
|
|
74
83
|
event: "error",
|
|
@@ -77,30 +86,23 @@ function toEventStream(iterator, options = {}) {
|
|
|
77
86
|
controller.close();
|
|
78
87
|
}
|
|
79
88
|
},
|
|
80
|
-
async cancel(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await iterator.return?.();
|
|
85
|
-
}
|
|
89
|
+
async cancel() {
|
|
90
|
+
cancelled = true;
|
|
91
|
+
clearInterval(timeout);
|
|
92
|
+
await iterator.return?.();
|
|
86
93
|
}
|
|
87
94
|
}).pipeThrough(new TextEncoderStream());
|
|
88
95
|
return stream;
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
async function toStandardBody(re) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const blob2 = await re.blob();
|
|
100
|
-
return new File([blob2], fileName, {
|
|
101
|
-
type: blob2.type
|
|
102
|
-
});
|
|
103
|
-
}
|
|
99
|
+
const contentDisposition = re.headers.get("content-disposition");
|
|
100
|
+
if (typeof contentDisposition === "string") {
|
|
101
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
102
|
+
const blob2 = await re.blob();
|
|
103
|
+
return new File([blob2], fileName, {
|
|
104
|
+
type: blob2.type
|
|
105
|
+
});
|
|
104
106
|
}
|
|
105
107
|
const contentType = re.headers.get("content-type");
|
|
106
108
|
if (!contentType || contentType.startsWith("application/json")) {
|
|
@@ -126,6 +128,7 @@ async function toStandardBody(re) {
|
|
|
126
128
|
});
|
|
127
129
|
}
|
|
128
130
|
function toFetchBody(body, headers, options = {}) {
|
|
131
|
+
const currentContentDisposition = headers.get("content-disposition");
|
|
129
132
|
headers.delete("content-type");
|
|
130
133
|
headers.delete("content-disposition");
|
|
131
134
|
if (body === void 0) {
|
|
@@ -136,7 +139,7 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
136
139
|
headers.set("content-length", body.size.toString());
|
|
137
140
|
headers.set(
|
|
138
141
|
"content-disposition",
|
|
139
|
-
|
|
142
|
+
currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob")
|
|
140
143
|
);
|
|
141
144
|
return body;
|
|
142
145
|
}
|
|
@@ -148,8 +151,6 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
148
151
|
}
|
|
149
152
|
if (isAsyncIteratorObject(body)) {
|
|
150
153
|
headers.set("content-type", "text/event-stream");
|
|
151
|
-
headers.set("cache-control", "no-cache");
|
|
152
|
-
headers.set("connection", "keep-alive");
|
|
153
154
|
return toEventStream(body, options);
|
|
154
155
|
}
|
|
155
156
|
headers.set("content-type", "application/json");
|
|
@@ -183,7 +184,6 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
|
183
184
|
|
|
184
185
|
function toStandardLazyRequest(request) {
|
|
185
186
|
return {
|
|
186
|
-
raw: { request },
|
|
187
187
|
url: new URL(request.url),
|
|
188
188
|
signal: request.signal,
|
|
189
189
|
method: request.method,
|
|
@@ -216,7 +216,6 @@ function toFetchResponse(response, options = {}) {
|
|
|
216
216
|
}
|
|
217
217
|
function toStandardLazyResponse(response) {
|
|
218
218
|
return {
|
|
219
|
-
raw: { response },
|
|
220
219
|
body: once(() => toStandardBody(response)),
|
|
221
220
|
status: response.status,
|
|
222
221
|
get 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.ffd5805",
|
|
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.ffd5805",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.ffd5805"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@hono/node-server": "^1.
|
|
30
|
+
"@hono/node-server": "^1.14.4"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "unbuild",
|