@orpc/standard-server-fetch 0.0.0-next.d0e429d → 0.0.0-next.d16a1b6
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 +1 -1
- package/dist/index.d.mts +54 -0
- package/dist/index.d.ts +54 -0
- package/dist/{index.js → index.mjs} +32 -31
- package/package.json +7 -12
- package/dist/src/body.d.ts +0 -11
- package/dist/src/event-source.d.ts +0 -23
- 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 -6
package/README.md
CHANGED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
eventSourcePingEnabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
13
|
+
*
|
|
14
|
+
* @default 5000
|
|
15
|
+
*/
|
|
16
|
+
eventSourcePingInterval?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The content of the ping comment. Must not include newline characters.
|
|
19
|
+
*
|
|
20
|
+
* @default ''
|
|
21
|
+
*/
|
|
22
|
+
eventSourcePingContent?: 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
|
+
declare function toFetchRequest(request: StandardRequest): Request;
|
|
48
|
+
|
|
49
|
+
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
50
|
+
}
|
|
51
|
+
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
52
|
+
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
53
|
+
|
|
54
|
+
export { type ToEventStreamOptions, type ToFetchBodyOptions, type ToFetchResponseOptions, toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
eventSourcePingEnabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
13
|
+
*
|
|
14
|
+
* @default 5000
|
|
15
|
+
*/
|
|
16
|
+
eventSourcePingInterval?: number;
|
|
17
|
+
/**
|
|
18
|
+
* The content of the ping comment. Must not include newline characters.
|
|
19
|
+
*
|
|
20
|
+
* @default ''
|
|
21
|
+
*/
|
|
22
|
+
eventSourcePingContent?: 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
|
+
declare function toFetchRequest(request: StandardRequest): Request;
|
|
48
|
+
|
|
49
|
+
interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
50
|
+
}
|
|
51
|
+
declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
52
|
+
declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
|
|
53
|
+
|
|
54
|
+
export { type ToEventStreamOptions, type ToFetchBodyOptions, type ToFetchResponseOptions, toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
|
|
@@ -1,16 +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, parseContentDisposition, contentDisposition } 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
|
-
withEventMeta
|
|
13
|
-
} from "@orpc/standard-server";
|
|
14
4
|
function toEventIterator(stream) {
|
|
15
5
|
const eventStream = stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventDecoderStream());
|
|
16
6
|
const reader = eventStream.getReader();
|
|
@@ -98,7 +88,6 @@ function toEventStream(iterator, options = {}) {
|
|
|
98
88
|
return stream;
|
|
99
89
|
}
|
|
100
90
|
|
|
101
|
-
// src/body.ts
|
|
102
91
|
async function toStandardBody(re) {
|
|
103
92
|
if (!re.body) {
|
|
104
93
|
return void 0;
|
|
@@ -116,7 +105,7 @@ async function toStandardBody(re) {
|
|
|
116
105
|
const contentType = re.headers.get("content-type");
|
|
117
106
|
if (!contentType || contentType.startsWith("application/json")) {
|
|
118
107
|
const text = await re.text();
|
|
119
|
-
return
|
|
108
|
+
return parseEmptyableJSON(text);
|
|
120
109
|
}
|
|
121
110
|
if (contentType.startsWith("multipart/form-data")) {
|
|
122
111
|
return await re.formData();
|
|
@@ -164,10 +153,9 @@ function toFetchBody(body, headers, options = {}) {
|
|
|
164
153
|
return toEventStream(body, options);
|
|
165
154
|
}
|
|
166
155
|
headers.set("content-type", "application/json");
|
|
167
|
-
return
|
|
156
|
+
return stringifyJSON(body);
|
|
168
157
|
}
|
|
169
158
|
|
|
170
|
-
// src/headers.ts
|
|
171
159
|
function toStandardHeaders(headers, standardHeaders = {}) {
|
|
172
160
|
for (const [key, value] of headers) {
|
|
173
161
|
if (Array.isArray(standardHeaders[key])) {
|
|
@@ -193,9 +181,7 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
|
|
|
193
181
|
return fetchHeaders;
|
|
194
182
|
}
|
|
195
183
|
|
|
196
|
-
|
|
197
|
-
import { once } from "@orpc/shared";
|
|
198
|
-
function toStandardRequest(request) {
|
|
184
|
+
function toStandardLazyRequest(request) {
|
|
199
185
|
return {
|
|
200
186
|
raw: { request },
|
|
201
187
|
url: new URL(request.url),
|
|
@@ -212,21 +198,36 @@ function toStandardRequest(request) {
|
|
|
212
198
|
}
|
|
213
199
|
};
|
|
214
200
|
}
|
|
201
|
+
function toFetchRequest(request) {
|
|
202
|
+
const headers = toFetchHeaders(request.headers);
|
|
203
|
+
const body = toFetchBody(request.body, headers);
|
|
204
|
+
return new Request(request.url, {
|
|
205
|
+
signal: request.signal,
|
|
206
|
+
method: request.method,
|
|
207
|
+
headers,
|
|
208
|
+
body
|
|
209
|
+
});
|
|
210
|
+
}
|
|
215
211
|
|
|
216
|
-
// src/response.ts
|
|
217
212
|
function toFetchResponse(response, options = {}) {
|
|
218
213
|
const headers = toFetchHeaders(response.headers);
|
|
219
214
|
const body = toFetchBody(response.body, headers, options);
|
|
220
215
|
return new Response(body, { headers, status: response.status });
|
|
221
216
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
217
|
+
function toStandardLazyResponse(response) {
|
|
218
|
+
return {
|
|
219
|
+
raw: { response },
|
|
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.d16a1b6",
|
|
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.d16a1b6",
|
|
27
|
+
"@orpc/standard-server": "0.0.0-next.d16a1b6"
|
|
33
28
|
},
|
|
34
29
|
"devDependencies": {
|
|
35
30
|
"@hono/node-server": "^1.13.8"
|
|
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,11 +0,0 @@
|
|
|
1
|
-
import type { StandardBody } from '@orpc/standard-server';
|
|
2
|
-
import type { ToEventStreamOptions } from './event-source';
|
|
3
|
-
export declare function toStandardBody(re: Request | Response): Promise<StandardBody>;
|
|
4
|
-
export interface ToFetchBodyOptions extends ToEventStreamOptions {
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* @param body
|
|
8
|
-
* @param headers - The headers can be changed by the function and effects on the original headers.
|
|
9
|
-
*/
|
|
10
|
-
export declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
|
|
11
|
-
//# sourceMappingURL=body.d.ts.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare function toEventIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<unknown | void, unknown | void, void>;
|
|
2
|
-
export interface ToEventStreamOptions {
|
|
3
|
-
/**
|
|
4
|
-
* If true, a ping comment is sent periodically to keep the connection alive.
|
|
5
|
-
*
|
|
6
|
-
* @default true
|
|
7
|
-
*/
|
|
8
|
-
eventSourcePingEnabled?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Interval (in milliseconds) between ping comments sent after the last event.
|
|
11
|
-
*
|
|
12
|
-
* @default 5000
|
|
13
|
-
*/
|
|
14
|
-
eventSourcePingInterval?: number;
|
|
15
|
-
/**
|
|
16
|
-
* The content of the ping comment. Must not include newline characters.
|
|
17
|
-
*
|
|
18
|
-
* @default ''
|
|
19
|
-
*/
|
|
20
|
-
eventSourcePingContent?: string;
|
|
21
|
-
}
|
|
22
|
-
export declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
|
|
23
|
-
//# 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
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { StandardResponse } from '@orpc/standard-server';
|
|
2
|
-
import type { ToFetchBodyOptions } from './body';
|
|
3
|
-
export interface ToFetchResponseOptions extends ToFetchBodyOptions {
|
|
4
|
-
}
|
|
5
|
-
export declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
|
|
6
|
-
//# sourceMappingURL=response.d.ts.map
|