@orpc/standard-server-fetch 0.0.0-next.fea68c1 → 0.0.0-next.ff41b3a
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 +27 -18
- package/dist/index.d.mts +57 -0
- package/dist/index.d.ts +57 -0
- package/dist/{index.js → index.mjs} +66 -61
- package/package.json +8 -13
- package/dist/src/body.d.ts +0 -8
- package/dist/src/event-source.d.ts +0 -3
- package/dist/src/headers.d.ts +0 -12
- package/dist/src/index.d.ts +0 -6
- package/dist/src/request.d.ts +0 -3
- package/dist/src/response.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
@@ -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
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
+
|
|
3
|
+
declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
4
|
+
interface ToEventStreamOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
eventIteratorKeepAliveEnabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
13
|
+
*
|
|
14
|
+
* @default 5000
|
|
15
|
+
*/
|
|
16
|
+
eventIteratorKeepAliveInterval?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The content of the ping comment. Must not include newline characters.
|
|
19
|
+
*
|
|
20
|
+
* @default ''
|
|
21
|
+
*/
|
|
22
|
+
eventIteratorKeepAliveComment?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
25
|
+
|
|
26
|
+
declare function toStandardBody(re: Request | Response): Promise<StandardBody>;
|
|
27
|
+
interface ToFetchBodyOptions extends ToEventStreamOptions {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param body
|
|
31
|
+
* @param headers - The headers can be changed by the function and effects on the original headers.
|
|
32
|
+
*/
|
|
33
|
+
declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param headers
|
|
37
|
+
* @param standardHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
38
|
+
*/
|
|
39
|
+
declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardHeaders): StandardHeaders;
|
|
40
|
+
/**
|
|
41
|
+
* @param headers
|
|
42
|
+
* @param fetchHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
43
|
+
*/
|
|
44
|
+
declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
45
|
+
|
|
46
|
+
declare function toStandardLazyRequest(request: Request): StandardLazyRequest;
|
|
47
|
+
interface ToFetchRequestOptions extends ToFetchBodyOptions {
|
|
48
|
+
}
|
|
49
|
+
declare function toFetchRequest(request: StandardRequest, options?: ToFetchRequestOptions): Request;
|
|
50
|
+
|
|
51
|
+
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
52
|
+
}
|
|
53
|
+
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
|
+
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
55
|
+
|
|
56
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
57
|
+
export type { ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardRequest, StandardResponse, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
+
|
|
3
|
+
declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
4
|
+
interface ToEventStreamOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
eventIteratorKeepAliveEnabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
13
|
+
*
|
|
14
|
+
* @default 5000
|
|
15
|
+
*/
|
|
16
|
+
eventIteratorKeepAliveInterval?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The content of the ping comment. Must not include newline characters.
|
|
19
|
+
*
|
|
20
|
+
* @default ''
|
|
21
|
+
*/
|
|
22
|
+
eventIteratorKeepAliveComment?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
25
|
+
|
|
26
|
+
declare function toStandardBody(re: Request | Response): Promise<StandardBody>;
|
|
27
|
+
interface ToFetchBodyOptions extends ToEventStreamOptions {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param body
|
|
31
|
+
* @param headers - The headers can be changed by the function and effects on the original headers.
|
|
32
|
+
*/
|
|
33
|
+
declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param headers
|
|
37
|
+
* @param standardHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
38
|
+
*/
|
|
39
|
+
declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardHeaders): StandardHeaders;
|
|
40
|
+
/**
|
|
41
|
+
* @param headers
|
|
42
|
+
* @param fetchHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
43
|
+
*/
|
|
44
|
+
declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
45
|
+
|
|
46
|
+
declare function toStandardLazyRequest(request: Request): StandardLazyRequest;
|
|
47
|
+
interface ToFetchRequestOptions extends ToFetchBodyOptions {
|
|
48
|
+
}
|
|
49
|
+
declare function toFetchRequest(request: StandardRequest, options?: ToFetchRequestOptions): Request;
|
|
50
|
+
|
|
51
|
+
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
52
|
+
}
|
|
53
|
+
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
54
|
+
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
55
|
+
|
|
56
|
+
export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
57
|
+
export type { ToEventStreamOptions, ToFetchBodyOptions, ToFetchRequestOptions, ToFetchResponseOptions };
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { contentDisposition, parseContentDisposition } from "@orpc/standard-server";
|
|
1
|
+
import { stringifyJSON, parseEmptyableJSON, isTypescriptObject, isAsyncIteratorObject, once } from '@orpc/shared';
|
|
2
|
+
import { EventDecoderStream, encodeEventMessage, getEventMeta, ErrorEvent, withEventMeta, getFilenameFromContentDisposition, generateContentDisposition } from '@orpc/standard-server';
|
|
4
3
|
|
|
5
|
-
// src/event-source.ts
|
|
6
|
-
import { isTypescriptObject, parseEmptyableJSON, stringifyJSON } from "@orpc/shared";
|
|
7
|
-
import {
|
|
8
|
-
encodeEventMessage,
|
|
9
|
-
ErrorEvent,
|
|
10
|
-
EventDecoderStream,
|
|
11
|
-
getEventMeta,
|
|
12
|
-
UnknownEvent,
|
|
13
|
-
withEventMeta
|
|
14
|
-
} from "@orpc/standard-server";
|
|
15
4
|
function toEventIterator(stream) {
|
|
16
5
|
const eventStream = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
17
6
|
const reader = eventStream.getReader();
|
|
@@ -45,14 +34,6 @@ function toEventIterator(stream) {
|
|
|
45
34
|
}
|
|
46
35
|
return done2;
|
|
47
36
|
}
|
|
48
|
-
default: {
|
|
49
|
-
let error = new UnknownEvent({
|
|
50
|
-
message: `Unknown event: ${value.event}`,
|
|
51
|
-
data: parseEmptyableJSON(value.data)
|
|
52
|
-
});
|
|
53
|
-
error = withEventMeta(error, value);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
37
|
}
|
|
57
38
|
}
|
|
58
39
|
} finally {
|
|
@@ -61,20 +42,36 @@ function toEventIterator(stream) {
|
|
|
61
42
|
}
|
|
62
43
|
return gen();
|
|
63
44
|
}
|
|
64
|
-
function toEventStream(iterator) {
|
|
45
|
+
function toEventStream(iterator, options = {}) {
|
|
46
|
+
const keepAliveEnabled = options.eventIteratorKeepAliveEnabled ?? true;
|
|
47
|
+
const keepAliveInterval = options.eventIteratorKeepAliveInterval ?? 5e3;
|
|
48
|
+
const keepAliveComment = options.eventIteratorKeepAliveComment ?? "";
|
|
49
|
+
let timeout;
|
|
65
50
|
const stream = new ReadableStream({
|
|
66
51
|
async pull(controller) {
|
|
67
52
|
try {
|
|
53
|
+
if (keepAliveEnabled) {
|
|
54
|
+
timeout = setInterval(() => {
|
|
55
|
+
controller.enqueue(encodeEventMessage({
|
|
56
|
+
comments: [keepAliveComment]
|
|
57
|
+
}));
|
|
58
|
+
}, keepAliveInterval);
|
|
59
|
+
}
|
|
68
60
|
const value = await iterator.next();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
61
|
+
clearInterval(timeout);
|
|
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
|
+
}
|
|
74
70
|
if (value.done) {
|
|
75
71
|
controller.close();
|
|
76
72
|
}
|
|
77
73
|
} catch (err) {
|
|
74
|
+
clearInterval(timeout);
|
|
78
75
|
controller.enqueue(encodeEventMessage({
|
|
79
76
|
...getEventMeta(err),
|
|
80
77
|
event: "error",
|
|
@@ -94,25 +91,22 @@ function toEventStream(iterator) {
|
|
|
94
91
|
return stream;
|
|
95
92
|
}
|
|
96
93
|
|
|
97
|
-
// src/body.ts
|
|
98
94
|
async function toStandardBody(re) {
|
|
99
95
|
if (!re.body) {
|
|
100
96
|
return void 0;
|
|
101
97
|
}
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
const fileName =
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
}
|
|
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
|
+
});
|
|
111
105
|
}
|
|
112
106
|
const contentType = re.headers.get("content-type");
|
|
113
107
|
if (!contentType || contentType.startsWith("application/json")) {
|
|
114
108
|
const text = await re.text();
|
|
115
|
-
return
|
|
109
|
+
return parseEmptyableJSON(text);
|
|
116
110
|
}
|
|
117
111
|
if (contentType.startsWith("multipart/form-data")) {
|
|
118
112
|
return await re.formData();
|
|
@@ -132,7 +126,8 @@ async function toStandardBody(re) {
|
|
|
132
126
|
type: blob.type
|
|
133
127
|
});
|
|
134
128
|
}
|
|
135
|
-
function toFetchBody(body, headers) {
|
|
129
|
+
function toFetchBody(body, headers, options = {}) {
|
|
130
|
+
const currentContentDisposition = headers.get("content-disposition");
|
|
136
131
|
headers.delete("content-type");
|
|
137
132
|
headers.delete("content-disposition");
|
|
138
133
|
if (body === void 0) {
|
|
@@ -143,7 +138,7 @@ function toFetchBody(body, headers) {
|
|
|
143
138
|
headers.set("content-length", body.size.toString());
|
|
144
139
|
headers.set(
|
|
145
140
|
"content-disposition",
|
|
146
|
-
|
|
141
|
+
currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob")
|
|
147
142
|
);
|
|
148
143
|
return body;
|
|
149
144
|
}
|
|
@@ -157,13 +152,12 @@ function toFetchBody(body, headers) {
|
|
|
157
152
|
headers.set("content-type", "text/event-stream");
|
|
158
153
|
headers.set("cache-control", "no-cache");
|
|
159
154
|
headers.set("connection", "keep-alive");
|
|
160
|
-
return toEventStream(body);
|
|
155
|
+
return toEventStream(body, options);
|
|
161
156
|
}
|
|
162
157
|
headers.set("content-type", "application/json");
|
|
163
|
-
return
|
|
158
|
+
return stringifyJSON(body);
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
// src/headers.ts
|
|
167
161
|
function toStandardHeaders(headers, standardHeaders = {}) {
|
|
168
162
|
for (const [key, value] of headers) {
|
|
169
163
|
if (Array.isArray(standardHeaders[key])) {
|
|
@@ -189,11 +183,8 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
|
189
183
|
return fetchHeaders;
|
|
190
184
|
}
|
|
191
185
|
|
|
192
|
-
|
|
193
|
-
import { once } from "@orpc/shared";
|
|
194
|
-
function toStandardRequest(request) {
|
|
186
|
+
function toStandardLazyRequest(request) {
|
|
195
187
|
return {
|
|
196
|
-
raw: { request },
|
|
197
188
|
url: new URL(request.url),
|
|
198
189
|
signal: request.signal,
|
|
199
190
|
method: request.method,
|
|
@@ -208,21 +199,35 @@ function toStandardRequest(request) {
|
|
|
208
199
|
}
|
|
209
200
|
};
|
|
210
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
|
+
}
|
|
211
212
|
|
|
212
|
-
|
|
213
|
-
function toFetchResponse(response) {
|
|
213
|
+
function toFetchResponse(response, options = {}) {
|
|
214
214
|
const headers = toFetchHeaders(response.headers);
|
|
215
|
-
const body = toFetchBody(response.body, headers);
|
|
215
|
+
const body = toFetchBody(response.body, headers, options);
|
|
216
216
|
return new Response(body, { headers, status: response.status });
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
}
|
|
232
|
+
|
|
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.ff41b3a",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -14,28 +14,23 @@
|
|
|
14
14
|
],
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"types": "./dist/
|
|
18
|
-
"import": "./dist/index.
|
|
19
|
-
"default": "./dist/index.
|
|
20
|
-
},
|
|
21
|
-
"./🔒/*": {
|
|
22
|
-
"types": "./dist/src/*.d.ts"
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
23
20
|
}
|
|
24
21
|
},
|
|
25
22
|
"files": [
|
|
26
|
-
"!**/*.map",
|
|
27
|
-
"!**/*.tsbuildinfo",
|
|
28
23
|
"dist"
|
|
29
24
|
],
|
|
30
25
|
"dependencies": {
|
|
31
|
-
"@orpc/shared": "0.0.0-next.
|
|
32
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
26
|
+
"@orpc/shared": "0.0.0-next.ff41b3a",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.ff41b3a"
|
|
33
28
|
},
|
|
34
29
|
"devDependencies": {
|
|
35
|
-
"@hono/node-server": "^1.
|
|
30
|
+
"@hono/node-server": "^1.14.1"
|
|
36
31
|
},
|
|
37
32
|
"scripts": {
|
|
38
|
-
"build": "
|
|
33
|
+
"build": "unbuild",
|
|
39
34
|
"build:watch": "pnpm run build --watch",
|
|
40
35
|
"type:check": "tsc -b"
|
|
41
36
|
}
|
package/dist/src/body.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { StandardBody } from '@orpc/standard-server';
|
|
2
|
-
export declare function toStandardBody(re: Request | Response): Promise<StandardBody>;
|
|
3
|
-
/**
|
|
4
|
-
* @param body
|
|
5
|
-
* @param headers - The headers can be changed by the function and effects on the original headers.
|
|
6
|
-
*/
|
|
7
|
-
export declare function toFetchBody(body: StandardBody, headers: Headers): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
|
|
8
|
-
//# sourceMappingURL=body.d.ts.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
2
|
-
export declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>): ReadableStream<Uint8Array>;
|
|
3
|
-
//# sourceMappingURL=event-source.d.ts.map
|
package/dist/src/headers.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { StandardHeaders } from '@orpc/standard-server';
|
|
2
|
-
/**
|
|
3
|
-
* @param headers
|
|
4
|
-
* @param standardHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
5
|
-
*/
|
|
6
|
-
export declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardHeaders): StandardHeaders;
|
|
7
|
-
/**
|
|
8
|
-
* @param headers
|
|
9
|
-
* @param fetchHeaders - The base headers can be changed by the function and effects on the original headers.
|
|
10
|
-
*/
|
|
11
|
-
export declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
|
|
12
|
-
//# sourceMappingURL=headers.d.ts.map
|
package/dist/src/index.d.ts
DELETED
package/dist/src/request.d.ts
DELETED
package/dist/src/response.d.ts
DELETED