@orpc/standard-server-fetch 0.45.0 → 0.46.0

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/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,21 +7,21 @@ interface ToEventStreamOptions {
7
7
  *
8
8
  * @default true
9
9
  */
10
- eventSourcePingEnabled?: boolean;
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
- eventSourcePingInterval?: number;
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
- eventSourcePingContent?: string;
22
+ eventIteratorKeepAliveComment?: string;
23
23
  }
24
- declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
24
+ declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options: ToEventStreamOptions): ReadableStream<Uint8Array>;
25
25
 
26
26
  declare function toStandardBody(re: Request | Response): Promise<StandardBody>;
27
27
  interface ToFetchBodyOptions extends ToEventStreamOptions {
@@ -30,7 +30,7 @@ interface ToFetchBodyOptions extends ToEventStreamOptions {
30
30
  * @param body
31
31
  * @param headers - The headers can be changed by the function and effects on the original headers.
32
32
  */
33
- declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
33
+ declare function toFetchBody(body: StandardBody, headers: Headers, options: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
34
34
 
35
35
  /**
36
36
  * @param headers
@@ -43,10 +43,14 @@ declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardH
43
43
  */
44
44
  declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
45
45
 
46
- declare function toStandardRequest(request: Request): StandardRequest;
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
- declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
53
+ declare function toFetchResponse(response: StandardResponse, options: ToFetchResponseOptions): Response;
54
+ declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
51
55
 
52
- export { type ToEventStreamOptions, type ToFetchBodyOptions, type ToFetchResponseOptions, toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchResponse, toStandardBody, toStandardHeaders, toStandardRequest };
56
+ export { type ToEventStreamOptions, type ToFetchBodyOptions, type ToFetchRequestOptions, type ToFetchResponseOptions, toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
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,21 +7,21 @@ interface ToEventStreamOptions {
7
7
  *
8
8
  * @default true
9
9
  */
10
- eventSourcePingEnabled?: boolean;
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
- eventSourcePingInterval?: number;
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
- eventSourcePingContent?: string;
22
+ eventIteratorKeepAliveComment?: string;
23
23
  }
24
- declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options?: ToEventStreamOptions): ReadableStream<Uint8Array>;
24
+ declare function toEventStream(iterator: AsyncIterator<unknown | void, unknown | void, void>, options: ToEventStreamOptions): ReadableStream<Uint8Array>;
25
25
 
26
26
  declare function toStandardBody(re: Request | Response): Promise<StandardBody>;
27
27
  interface ToFetchBodyOptions extends ToEventStreamOptions {
@@ -30,7 +30,7 @@ interface ToFetchBodyOptions extends ToEventStreamOptions {
30
30
  * @param body
31
31
  * @param headers - The headers can be changed by the function and effects on the original headers.
32
32
  */
33
- declare function toFetchBody(body: StandardBody, headers: Headers, options?: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
33
+ declare function toFetchBody(body: StandardBody, headers: Headers, options: ToFetchBodyOptions): string | Blob | FormData | URLSearchParams | undefined | ReadableStream<Uint8Array>;
34
34
 
35
35
  /**
36
36
  * @param headers
@@ -43,10 +43,14 @@ declare function toStandardHeaders(headers: Headers, standardHeaders?: StandardH
43
43
  */
44
44
  declare function toFetchHeaders(headers: StandardHeaders, fetchHeaders?: Headers): Headers;
45
45
 
46
- declare function toStandardRequest(request: Request): StandardRequest;
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
- declare function toFetchResponse(response: StandardResponse, options?: ToFetchResponseOptions): Response;
53
+ declare function toFetchResponse(response: StandardResponse, options: ToFetchResponseOptions): Response;
54
+ declare function toStandardLazyResponse(response: Response): StandardLazyResponse;
51
55
 
52
- export { type ToEventStreamOptions, type ToFetchBodyOptions, type ToFetchResponseOptions, toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchResponse, toStandardBody, toStandardHeaders, toStandardRequest };
56
+ export { type ToEventStreamOptions, type ToFetchBodyOptions, type ToFetchRequestOptions, type ToFetchResponseOptions, toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchRequest, toFetchResponse, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardLazyResponse };
package/dist/index.mjs CHANGED
@@ -42,20 +42,20 @@ function toEventIterator(stream) {
42
42
  }
43
43
  return gen();
44
44
  }
45
- function toEventStream(iterator, options = {}) {
46
- const pingEnabled = options.eventSourcePingEnabled ?? true;
47
- const pingInterval = options.eventSourcePingInterval ?? 5e3;
48
- const pingContent = options.eventSourcePingContent ?? "";
45
+ function toEventStream(iterator, options) {
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 (pingEnabled) {
53
+ if (keepAliveEnabled) {
54
54
  timeout = setInterval(() => {
55
55
  controller.enqueue(encodeEventMessage({
56
- comments: [pingContent]
56
+ comments: [keepAliveComment]
57
57
  }));
58
- }, pingInterval);
58
+ }, keepAliveInterval);
59
59
  }
60
60
  const value = await iterator.next();
61
61
  clearInterval(timeout);
@@ -125,7 +125,7 @@ async function toStandardBody(re) {
125
125
  type: blob.type
126
126
  });
127
127
  }
128
- function toFetchBody(body, headers, options = {}) {
128
+ function toFetchBody(body, headers, options) {
129
129
  headers.delete("content-type");
130
130
  headers.delete("content-disposition");
131
131
  if (body === void 0) {
@@ -181,7 +181,7 @@ function toFetchHeaders(headers, fetchHeaders = new Headers()) {
181
181
  return fetchHeaders;
182
182
  }
183
183
 
184
- function toStandardRequest(request) {
184
+ function toStandardLazyRequest(request) {
185
185
  return {
186
186
  raw: { request },
187
187
  url: new URL(request.url),
@@ -198,11 +198,36 @@ function toStandardRequest(request) {
198
198
  }
199
199
  };
200
200
  }
201
+ function toFetchRequest(request, options) {
202
+ const headers = toFetchHeaders(request.headers);
203
+ const body = toFetchBody(request.body, headers, options);
204
+ return new Request(request.url, {
205
+ signal: request.signal,
206
+ method: request.method,
207
+ headers,
208
+ body
209
+ });
210
+ }
201
211
 
202
- function toFetchResponse(response, options = {}) {
212
+ function toFetchResponse(response, options) {
203
213
  const headers = toFetchHeaders(response.headers);
204
214
  const body = toFetchBody(response.body, headers, options);
205
215
  return new Response(body, { headers, status: response.status });
206
216
  }
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
+ }
207
232
 
208
- export { toEventIterator, toEventStream, toFetchBody, toFetchHeaders, toFetchResponse, toStandardBody, toStandardHeaders, toStandardRequest };
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.45.0",
4
+ "version": "0.46.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://unnoq.com",
7
7
  "repository": {
@@ -23,8 +23,8 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@orpc/shared": "0.45.0",
27
- "@orpc/standard-server": "0.45.0"
26
+ "@orpc/shared": "0.46.0",
27
+ "@orpc/standard-server": "0.46.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@hono/node-server": "^1.13.8"