@orpc/standard-server-fetch 0.0.0-next.b0f324e → 0.0.0-next.b11d127
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 +26 -17
- package/dist/index.d.mts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.mjs +50 -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,16 +49,29 @@ 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).
|
|
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).
|
|
58
57
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
58
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
59
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
60
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
61
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
61
62
|
|
|
62
63
|
## `@orpc/standard-server-fetch`
|
|
63
64
|
|
|
64
65
|
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) server adapter for oRPC.
|
|
65
66
|
|
|
67
|
+
## Sponsors
|
|
68
|
+
|
|
69
|
+
<p align="center">
|
|
70
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
71
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
72
|
+
</a>
|
|
73
|
+
</p>
|
|
74
|
+
|
|
66
75
|
## License
|
|
67
76
|
|
|
68
77
|
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,4 +1,4 @@
|
|
|
1
|
-
import { StandardBody, StandardHeaders, StandardRequest, StandardResponse } from '@orpc/standard-server';
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
2
|
|
|
3
3
|
declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
4
4
|
interface ToEventStreamOptions {
|
|
@@ -7,19 +7,19 @@ interface ToEventStreamOptions {
|
|
|
7
7
|
*
|
|
8
8
|
* @default true
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
eventIteratorKeepAliveEnabled?: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
13
13
|
*
|
|
14
14
|
* @default 5000
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
eventIteratorKeepAliveInterval?: number;
|
|
17
17
|
/**
|
|
18
18
|
* The content of the ping comment. Must not include newline characters.
|
|
19
19
|
*
|
|
20
20
|
* @default ''
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
eventIteratorKeepAliveComment?: string;
|
|
23
23
|
}
|
|
24
24
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
25
25
|
|
|
@@ -43,10 +43,15 @@ declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardH
|
|
|
43
43
|
*/
|
|
44
44
|
declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
45
45
|
|
|
46
|
-
declare function
|
|
46
|
+
declare function toStandardLazyRequest(request: Request): StandardLazyRequest;
|
|
47
|
+
interface ToFetchRequestOptions extends ToFetchBodyOptions {
|
|
48
|
+
}
|
|
49
|
+
declare function toFetchRequest(request: StandardRequest, options?: ToFetchRequestOptions): Request;
|
|
47
50
|
|
|
48
51
|
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
49
52
|
}
|
|
50
53
|
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
|
+
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
51
55
|
|
|
52
|
-
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,4 +1,4 @@
|
|
|
1
|
-
import { StandardBody, StandardHeaders, StandardRequest, StandardResponse } from '@orpc/standard-server';
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
2
|
|
|
3
3
|
declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
4
4
|
interface ToEventStreamOptions {
|
|
@@ -7,19 +7,19 @@ interface ToEventStreamOptions {
|
|
|
7
7
|
*
|
|
8
8
|
* @default true
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
eventIteratorKeepAliveEnabled?: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
13
13
|
*
|
|
14
14
|
* @default 5000
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
eventIteratorKeepAliveInterval?: number;
|
|
17
17
|
/**
|
|
18
18
|
* The content of the ping comment. Must not include newline characters.
|
|
19
19
|
*
|
|
20
20
|
* @default ''
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
eventIteratorKeepAliveComment?: string;
|
|
23
23
|
}
|
|
24
24
|
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
25
25
|
|
|
@@ -43,10 +43,15 @@ declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardH
|
|
|
43
43
|
*/
|
|
44
44
|
declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
45
45
|
|
|
46
|
-
declare function
|
|
46
|
+
declare function toStandardLazyRequest(request: Request): StandardLazyRequest;
|
|
47
|
+
interface ToFetchRequestOptions extends ToFetchBodyOptions {
|
|
48
|
+
}
|
|
49
|
+
declare function toFetchRequest(request: StandardRequest, options?: ToFetchRequestOptions): Request;
|
|
47
50
|
|
|
48
51
|
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
49
52
|
}
|
|
50
53
|
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
|
+
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
51
55
|
|
|
52
|
-
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());
|
|
@@ -43,27 +43,30 @@ function toEventIterator(stream) {
|
|
|
43
43
|
return gen();
|
|
44
44
|
}
|
|
45
45
|
function toEventStream(iterator, options = {}) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
46
|
+
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
47
|
+
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
48
|
+
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
49
49
|
let timeout;
|
|
50
50
|
const stream = new ReadableStream({
|
|
51
51
|
async pull(controller) {
|
|
52
52
|
try {
|
|
53
|
-
if (
|
|
53
|
+
if (keepAliveEnabled) {
|
|
54
54
|
timeout = setInterval(() => {
|
|
55
55
|
controller.enqueue(encodeEventMessage({
|
|
56
|
-
comments: [
|
|
56
|
+
comments: [keepAliveComment]
|
|
57
57
|
}));
|
|
58
|
-
},
|
|
58
|
+
}, keepAliveInterval);
|
|
59
59
|
}
|
|
60
60
|
const value = await iterator.next();
|
|
61
61
|
clearInterval(timeout);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
}
|
|
@@ -92,15 +95,13 @@ async function toStandardBody(re) {
|
|
|
92
95
|
if (!re.body) {
|
|
93
96
|
return void 0;
|
|
94
97
|
}
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const fileName =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
}
|
|
98
|
+
const contentDisposition = re.headers.get("content-disposition");
|
|
99
|
+
if (typeof contentDisposition === "string") {
|
|
100
|
+
const fileName = getFilenameFromContentDisposition(contentDisposition) ?? "blob";
|
|
101
|
+
const blob2 = await re.blob();
|
|
102
|
+
return new File([blob2], fileName, {
|
|
103
|
+
type: blob2.type
|
|
104
|
+
});
|
|
104
105
|
}
|
|
105
106
|
const contentType = re.headers.get("content-type");
|
|
106
107
|
if (!contentType || contentType.startsWith("application/json")) {
|
|
@@ -126,6 +127,7 @@ async function toStandardBody(re) {
|
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
129
|
function toFetchBody(body, headers, options = {}) {
|
|
130
|
+
const currentContentDisposition = headers.get("content-disposition");
|
|
129
131
|
headers.delete("content-type");
|
|
130
132
|
headers.delete("content-disposition");
|
|
131
133
|
if (body === void 0) {
|
|
@@ -136,7 +138,7 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
136
138
|
headers.set("content-length", body.size.toString());
|
|
137
139
|
headers.set(
|
|
138
140
|
"content-disposition",
|
|
139
|
-
|
|
141
|
+
currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob")
|
|
140
142
|
);
|
|
141
143
|
return body;
|
|
142
144
|
}
|
|
@@ -181,9 +183,8 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
|
181
183
|
return fetchHeaders;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
function
|
|
186
|
+
function toStandardLazyRequest(request) {
|
|
185
187
|
return {
|
|
186
|
-
raw: { request },
|
|
187
188
|
url: new URL(request.url),
|
|
188
189
|
signal: request.signal,
|
|
189
190
|
method: request.method,
|
|
@@ -198,11 +199,35 @@ function toStandardRequest(request) {
|
|
|
198
199
|
}
|
|
199
200
|
};
|
|
200
201
|
}
|
|
202
|
+
function toFetchRequest(request, options = {}) {
|
|
203
|
+
const headers = toFetchHeaders(request.headers);
|
|
204
|
+
const body = toFetchBody(request.body, headers, options);
|
|
205
|
+
return new Request(request.url, {
|
|
206
|
+
signal: request.signal,
|
|
207
|
+
method: request.method,
|
|
208
|
+
headers,
|
|
209
|
+
body
|
|
210
|
+
});
|
|
211
|
+
}
|
|
201
212
|
|
|
202
213
|
function toFetchResponse(response, options = {}) {
|
|
203
214
|
const headers = toFetchHeaders(response.headers);
|
|
204
215
|
const body = toFetchBody(response.body, headers, options);
|
|
205
216
|
return new Response(body, { headers, status: response.status });
|
|
206
217
|
}
|
|
218
|
+
function toStandardLazyResponse(response) {
|
|
219
|
+
return {
|
|
220
|
+
body: once(() => toStandardBody(response)),
|
|
221
|
+
status: response.status,
|
|
222
|
+
get headers() {
|
|
223
|
+
const headers = toStandardHeaders(response.headers);
|
|
224
|
+
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
|
225
|
+
return headers;
|
|
226
|
+
},
|
|
227
|
+
set headers(value) {
|
|
228
|
+
Object.defineProperty(this, "headers", { value, writable: true });
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
207
232
|
|
|
208
|
-
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchResponse, toStandardBody, toStandardHeaders,
|
|
233
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
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.b11d127",
|
|
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/standard-server": "0.0.0-next.
|
|
27
|
-
"@orpc/shared": "0.0.0-next.
|
|
26
|
+
"@orpc/standard-server": "0.0.0-next.b11d127",
|
|
27
|
+
"@orpc/shared": "0.0.0-next.b11d127"
|
|
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",
|