@orpc/standard-server 0.53.0 → 0.54.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.
@@ -18,6 +18,7 @@ interface ToBatchResponseOptions extends StandardResponse {
18
18
  declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse;
19
19
  declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
20
20
 
21
- declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
21
+ declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
22
22
 
23
- export { type BatchResponseBodyItem, type ToBatchRequestOptions, type ToBatchResponseOptions, parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
23
+ export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
24
+ export type { BatchResponseBodyItem, ToBatchRequestOptions, ToBatchResponseOptions };
@@ -18,6 +18,7 @@ interface ToBatchResponseOptions extends StandardResponse {
18
18
  declare function toBatchResponse(options: ToBatchResponseOptions): StandardResponse;
19
19
  declare function parseBatchResponse(response: StandardResponse): AsyncGenerator<BatchResponseBodyItem>;
20
20
 
21
- declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
21
+ declare function toBatchAbortSignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
22
22
 
23
- export { type BatchResponseBodyItem, type ToBatchRequestOptions, type ToBatchResponseOptions, parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
23
+ export { parseBatchRequest, parseBatchResponse, toBatchAbortSignal, toBatchRequest, toBatchResponse };
24
+ export type { BatchResponseBodyItem, ToBatchRequestOptions, ToBatchResponseOptions };
@@ -2,17 +2,22 @@ import { stringifyJSON, parseEmptyableJSON, isAsyncIteratorObject, isObject } fr
2
2
 
3
3
  function toBatchAbortSignal(signals) {
4
4
  const realSignals = signals.filter((signal) => signal !== void 0);
5
- const controller = new AbortController();
6
- const abortedSignals = realSignals.filter((signal) => signal.aborted);
7
- if (abortedSignals.length && abortedSignals.length === realSignals.length) {
8
- controller.abort();
5
+ if (realSignals.length === 0 || realSignals.length !== signals.length) {
6
+ return void 0;
9
7
  }
8
+ const controller = new AbortController();
9
+ const abortIfAllInputsAborted = () => {
10
+ if (realSignals.every((signal) => signal.aborted)) {
11
+ controller.abort();
12
+ }
13
+ };
14
+ abortIfAllInputsAborted();
10
15
  for (const signal of realSignals) {
11
16
  signal.addEventListener("abort", () => {
12
- abortedSignals.push(signal);
13
- if (abortedSignals.length === realSignals.length) {
14
- controller.abort();
15
- }
17
+ abortIfAllInputsAborted();
18
+ }, {
19
+ once: true,
20
+ signal: controller.signal
16
21
  });
17
22
  }
18
23
  return controller.signal;
@@ -23,8 +28,8 @@ function toBatchRequest(options) {
23
28
  let body;
24
29
  const batchRequestItems = options.requests.map((request) => ({
25
30
  body: request.body,
26
- headers: request.headers,
27
- method: request.method,
31
+ headers: Object.keys(request.headers).length ? request.headers : void 0,
32
+ method: request.method === options.method ? void 0 : request.method,
28
33
  url: request.url
29
34
  }));
30
35
  if (options.method === "GET") {
@@ -47,9 +52,9 @@ function parseBatchRequest(request) {
47
52
  }
48
53
  return items.map((item) => {
49
54
  return {
50
- method: item.method,
55
+ method: item.method ?? request.method,
51
56
  url: new URL(item.url),
52
- headers: item.headers,
57
+ headers: item.headers ?? {},
53
58
  body: item.body,
54
59
  signal: request.signal
55
60
  };
@@ -57,7 +62,23 @@ function parseBatchRequest(request) {
57
62
  }
58
63
 
59
64
  function toBatchResponse(options) {
60
- return options;
65
+ return {
66
+ ...options,
67
+ body: async function* () {
68
+ try {
69
+ for await (const item of options.body) {
70
+ yield {
71
+ index: item.index,
72
+ status: item.status === options.status ? void 0 : item.status,
73
+ headers: Object.keys(item.headers).length ? item.headers : void 0,
74
+ body: item.body
75
+ };
76
+ }
77
+ } finally {
78
+ options.body.return?.();
79
+ }
80
+ }()
81
+ };
61
82
  }
62
83
  function parseBatchResponse(response) {
63
84
  const body = response.body;
@@ -69,12 +90,17 @@ function parseBatchResponse(response) {
69
90
  return async function* () {
70
91
  try {
71
92
  for await (const item of body) {
72
- if (!isObject(item) || !("index" in item) || !("status" in item) || !("headers" in item)) {
93
+ if (!isObject(item) || !("index" in item) || typeof item.index !== "number") {
73
94
  throw new TypeError("Invalid batch response", {
74
95
  cause: item
75
96
  });
76
97
  }
77
- yield item;
98
+ yield {
99
+ index: item.index,
100
+ status: item.status ?? response.status,
101
+ headers: item.headers ?? {},
102
+ body: item.body
103
+ };
78
104
  }
79
105
  } finally {
80
106
  await body.return?.();
package/dist/index.d.mts CHANGED
@@ -56,4 +56,5 @@ declare function generateContentDisposition(filename: string): string;
56
56
  declare function getFilenameFromContentDisposition(contentDisposition: string): string | undefined;
57
57
  declare function mergeStandardHeaders(a: StandardHeaders, b: StandardHeaders): StandardHeaders;
58
58
 
59
- export { ErrorEvent, type ErrorEventOptions, EventDecoder, EventDecoderError, type EventDecoderOptions, EventDecoderStream, EventEncoderError, type EventMessage, type EventMeta, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
59
+ export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
60
+ export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta };
package/dist/index.d.ts CHANGED
@@ -56,4 +56,5 @@ declare function generateContentDisposition(filename: string): string;
56
56
  declare function getFilenameFromContentDisposition(contentDisposition: string): string | undefined;
57
57
  declare function mergeStandardHeaders(a: StandardHeaders, b: StandardHeaders): StandardHeaders;
58
58
 
59
- export { ErrorEvent, type ErrorEventOptions, EventDecoder, EventDecoderError, type EventDecoderOptions, EventDecoderStream, EventEncoderError, type EventMessage, type EventMeta, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
59
+ export { ErrorEvent, EventDecoder, EventDecoderError, EventDecoderStream, EventEncoderError, StandardHeaders, assertEventComment, assertEventId, assertEventName, assertEventRetry, decodeEventMessage, encodeEventComments, encodeEventData, encodeEventMessage, generateContentDisposition, getEventMeta, getFilenameFromContentDisposition, mergeStandardHeaders, withEventMeta };
60
+ export type { ErrorEventOptions, EventDecoderOptions, EventMessage, EventMeta };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/standard-server",
3
3
  "type": "module",
4
- "version": "0.53.0",
4
+ "version": "0.54.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://unnoq.com",
7
7
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@orpc/shared": "0.53.0"
31
+ "@orpc/shared": "0.54.0"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "unbuild",