@orpc/standard-server-fetch 0.0.0-next.d3b4900 → 0.0.0-next.d5f6b77
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 +14 -17
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +32 -25
- 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,7 @@ 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/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
53
|
- [@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
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).
|
|
58
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).
|
package/dist/index.d.mts
CHANGED
|
@@ -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
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { stringifyJSON, parseEmptyableJSON, isTypescriptObject, isAsyncIteratorObject, once } from '@orpc/shared';
|
|
2
|
-
import { EventDecoderStream, encodeEventMessage, getEventMeta, ErrorEvent, withEventMeta,
|
|
2
|
+
import { EventDecoderStream, encodeEventMessage, getEventMeta, ErrorEvent, withEventMeta, getFilenameFromContentDisposition, generateContentDisposition } from '@orpc/standard-server';
|
|
3
3
|
|
|
4
4
|
function toEventIterator(stream) {
|
|
5
5
|
const eventStream = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
@@ -46,6 +46,7 @@ function toEventStream(iterator, options = {}) {
|
|
|
46
46
|
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
47
47
|
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
48
48
|
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
49
|
+
let cancelled = false;
|
|
49
50
|
let timeout;
|
|
50
51
|
const stream = new ReadableStream({
|
|
51
52
|
async pull(controller) {
|
|
@@ -59,16 +60,25 @@ function toEventStream(iterator, options = {}) {
|
|
|
59
60
|
}
|
|
60
61
|
const value = await iterator.next();
|
|
61
62
|
clearInterval(timeout);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (cancelled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const meta = getEventMeta(value.value);
|
|
67
|
+
if (!value.done || value.value !== void 0 || meta !== void 0) {
|
|
68
|
+
controller.enqueue(encodeEventMessage({
|
|
69
|
+
...meta,
|
|
70
|
+
event: value.done ? "done" : "message",
|
|
71
|
+
data: stringifyJSON(value.value)
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
67
74
|
if (value.done) {
|
|
68
75
|
controller.close();
|
|
69
76
|
}
|
|
70
77
|
} catch (err) {
|
|
71
78
|
clearInterval(timeout);
|
|
79
|
+
if (cancelled) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
72
82
|
controller.enqueue(encodeEventMessage({
|
|
73
83
|
...getEventMeta(err),
|
|
74
84
|
event: "error",
|
|
@@ -78,6 +88,8 @@ function toEventStream(iterator, options = {}) {
|
|
|
78
88
|
}
|
|
79
89
|
},
|
|
80
90
|
async cancel(reason) {
|
|
91
|
+
cancelled = true;
|
|
92
|
+
clearInterval(timeout);
|
|
81
93
|
if (reason) {
|
|
82
94
|
await iterator.throw?.(reason);
|
|
83
95
|
} else {
|
|
@@ -89,18 +101,16 @@ function toEventStream(iterator, options = {}) {
|
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
async function toStandardBody(re) {
|
|
92
|
-
if (
|
|
104
|
+
if (re.body === null) {
|
|
93
105
|
return void 0;
|
|
94
106
|
}
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const fileName =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
}
|
|
107
|
+
const contentDisposition = re.headers.get("content-disposition");
|
|
108
|
+
if (typeof contentDisposition === "string") {
|
|
109
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
110
|
+
const blob2 = await re.blob();
|
|
111
|
+
return new File([blob2], fileName, {
|
|
112
|
+
type: blob2.type
|
|
113
|
+
});
|
|
104
114
|
}
|
|
105
115
|
const contentType = re.headers.get("content-type");
|
|
106
116
|
if (!contentType || contentType.startsWith("application/json")) {
|
|
@@ -126,6 +136,7 @@ async function toStandardBody(re) {
|
|
|
126
136
|
});
|
|
127
137
|
}
|
|
128
138
|
function toFetchBody(body, headers, options = {}) {
|
|
139
|
+
const currentContentDisposition = headers.get("content-disposition");
|
|
129
140
|
headers.delete("content-type");
|
|
130
141
|
headers.delete("content-disposition");
|
|
131
142
|
if (body === void 0) {
|
|
@@ -136,7 +147,7 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
136
147
|
headers.set("content-length", body.size.toString());
|
|
137
148
|
headers.set(
|
|
138
149
|
"content-disposition",
|
|
139
|
-
|
|
150
|
+
currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob")
|
|
140
151
|
);
|
|
141
152
|
return body;
|
|
142
153
|
}
|
|
@@ -182,15 +193,13 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
|
182
193
|
}
|
|
183
194
|
|
|
184
195
|
function toStandardLazyRequest(request) {
|
|
185
|
-
const raw = { adapter: "fetch", request };
|
|
186
196
|
return {
|
|
187
|
-
raw,
|
|
188
197
|
url: new URL(request.url),
|
|
189
198
|
signal: request.signal,
|
|
190
199
|
method: request.method,
|
|
191
|
-
body: once(() => toStandardBody(
|
|
200
|
+
body: once(() => toStandardBody(request)),
|
|
192
201
|
get headers() {
|
|
193
|
-
const headers = toStandardHeaders(
|
|
202
|
+
const headers = toStandardHeaders(request.headers);
|
|
194
203
|
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
195
204
|
return headers;
|
|
196
205
|
},
|
|
@@ -216,13 +225,11 @@ function toFetchResponse(response, options = {}) {
|
|
|
216
225
|
return new Response(body, { headers, status: response.status });
|
|
217
226
|
}
|
|
218
227
|
function toStandardLazyResponse(response) {
|
|
219
|
-
const raw = { adapter: "fetch", response };
|
|
220
228
|
return {
|
|
221
|
-
|
|
222
|
-
body: once(() => toStandardBody(raw.response)),
|
|
229
|
+
body: once(() => toStandardBody(response)),
|
|
223
230
|
status: response.status,
|
|
224
231
|
get headers() {
|
|
225
|
-
const headers = toStandardHeaders(
|
|
232
|
+
const headers = toStandardHeaders(response.headers);
|
|
226
233
|
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
227
234
|
return headers;
|
|
228
235
|
},
|
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.d5f6b77",
|
|
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.d5f6b77",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.d5f6b77"
|
|
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",
|