@orpc/standard-server-fetch 0.0.0-next.f4d410a → 0.0.0-next.f4ed9ab
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 +25 -17
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +59 -58
- 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,6 +49,8 @@ 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.
|
|
52
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
|
53
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
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).
|
|
57
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).
|
|
58
56
|
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
@@ -60,11 +58,21 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
60
58
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
61
59
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
62
60
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
61
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
62
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
63
63
|
|
|
64
64
|
## `@orpc/standard-server-fetch`
|
|
65
65
|
|
|
66
66
|
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) server adapter for oRPC.
|
|
67
67
|
|
|
68
|
+
## Sponsors
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
72
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
73
|
+
</a>
|
|
74
|
+
</p>
|
|
75
|
+
|
|
68
76
|
## License
|
|
69
77
|
|
|
70
78
|
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,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>): 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.
|
|
@@ -53,4 +53,5 @@ interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
|
53
53
|
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
54
|
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
55
55
|
|
|
56
|
-
export {
|
|
56
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
57
|
+
export type { ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions };
|
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>): 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.
|
|
@@ -53,4 +53,5 @@ interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
|
53
53
|
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
54
|
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
55
55
|
|
|
56
|
-
export {
|
|
56
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
57
|
+
export type { ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,48 @@
|
|
|
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
5
|
const eventStream = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
6
6
|
const reader = eventStream.getReader();
|
|
7
|
-
async
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
message = withEventMeta(message, value);
|
|
19
|
-
}
|
|
20
|
-
yield message;
|
|
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;
|
|
7
|
+
return createAsyncIteratorObject(async () => {
|
|
8
|
+
while (true) {
|
|
9
|
+
const { done, value } = await reader.read();
|
|
10
|
+
if (done) {
|
|
11
|
+
return { done: true, value: void 0 };
|
|
12
|
+
}
|
|
13
|
+
switch (value.event) {
|
|
14
|
+
case "message": {
|
|
15
|
+
let message = parseEmptyableJSON(value.data);
|
|
16
|
+
if (isTypescriptObject(message)) {
|
|
17
|
+
message = withEventMeta(message, value);
|
|
29
18
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
return { done: false, value: message };
|
|
20
|
+
}
|
|
21
|
+
case "error": {
|
|
22
|
+
let error = new ErrorEvent({
|
|
23
|
+
data: parseEmptyableJSON(value.data)
|
|
24
|
+
});
|
|
25
|
+
error = withEventMeta(error, value);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
case "done": {
|
|
29
|
+
let done2 = parseEmptyableJSON(value.data);
|
|
30
|
+
if (isTypescriptObject(done2)) {
|
|
31
|
+
done2 = withEventMeta(done2, value);
|
|
36
32
|
}
|
|
33
|
+
return { done: true, value: done2 };
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
} finally {
|
|
40
|
-
await reader.cancel();
|
|
41
36
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
37
|
+
}, async () => {
|
|
38
|
+
await reader.cancel();
|
|
39
|
+
});
|
|
44
40
|
}
|
|
45
41
|
function toEventStream(iterator, options = {}) {
|
|
46
42
|
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
47
43
|
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
48
44
|
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
45
|
+
let cancelled = false;
|
|
49
46
|
let timeout;
|
|
50
47
|
const stream = new ReadableStream({
|
|
51
48
|
async pull(controller) {
|
|
@@ -59,16 +56,25 @@ function toEventStream(iterator, options = {}) {
|
|
|
59
56
|
}
|
|
60
57
|
const value = await iterator.next();
|
|
61
58
|
clearInterval(timeout);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
if (cancelled) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const meta = getEventMeta(value.value);
|
|
63
|
+
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
64
|
+
controller.enqueue(encodeEventMessage({
|
|
65
|
+
...meta,
|
|
66
|
+
event: value.done ? "done" : "message",
|
|
67
|
+
data: stringifyJSON(value.value)
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
67
70
|
if (value.done) {
|
|
68
71
|
controller.close();
|
|
69
72
|
}
|
|
70
73
|
} catch (err) {
|
|
71
74
|
clearInterval(timeout);
|
|
75
|
+
if (cancelled) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
72
78
|
controller.enqueue(encodeEventMessage({
|
|
73
79
|
...getEventMeta(err),
|
|
74
80
|
event: "error",
|
|
@@ -77,30 +83,26 @@ function toEventStream(iterator, options = {}) {
|
|
|
77
83
|
controller.close();
|
|
78
84
|
}
|
|
79
85
|
},
|
|
80
|
-
async cancel(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await iterator.return?.();
|
|
85
|
-
}
|
|
86
|
+
async cancel() {
|
|
87
|
+
cancelled = true;
|
|
88
|
+
clearInterval(timeout);
|
|
89
|
+
await iterator.return?.();
|
|
86
90
|
}
|
|
87
91
|
}).pipeThrough(new TextEncoderStream());
|
|
88
92
|
return stream;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
async function toStandardBody(re) {
|
|
92
|
-
if (
|
|
96
|
+
if (re.body === null) {
|
|
93
97
|
return void 0;
|
|
94
98
|
}
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const fileName =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
}
|
|
@@ -183,7 +186,6 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
|
183
186
|
|
|
184
187
|
function toStandardLazyRequest(request) {
|
|
185
188
|
return {
|
|
186
|
-
raw: { request },
|
|
187
189
|
url: new URL(request.url),
|
|
188
190
|
signal: request.signal,
|
|
189
191
|
method: request.method,
|
|
@@ -216,7 +218,6 @@ function toFetchResponse(response, options = {}) {
|
|
|
216
218
|
}
|
|
217
219
|
function toStandardLazyResponse(response) {
|
|
218
220
|
return {
|
|
219
|
-
raw: { response },
|
|
220
221
|
body: once(() => toStandardBody(response)),
|
|
221
222
|
status: response.status,
|
|
222
223
|
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.f4ed9ab",
|
|
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/shared": "0.0.0-next.f4ed9ab",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.f4ed9ab"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@hono/node-server": "^1.
|
|
30
|
+
"@hono/node-server": "^1.14.1"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "unbuild",
|