@orpc/standard-server 1.8.6 → 1.8.7
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/batch/index.mjs +40 -30
- package/package.json +2 -2
package/dist/batch/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { stringifyJSON, parseEmptyableJSON, isAsyncIteratorObject, isObject } from '@orpc/shared';
|
1
|
+
import { stringifyJSON, parseEmptyableJSON, AsyncIteratorClass, isAsyncIteratorObject, isObject } from '@orpc/shared';
|
2
2
|
|
3
3
|
function toBatchAbortSignal(signals) {
|
4
4
|
const realSignals = signals.filter((signal) => signal !== void 0);
|
@@ -91,46 +91,56 @@ function toBatchResponse(options) {
|
|
91
91
|
return {
|
92
92
|
headers: options.headers,
|
93
93
|
status: options.status,
|
94
|
-
body:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
94
|
+
body: new AsyncIteratorClass(
|
95
|
+
async () => {
|
96
|
+
const { done, value } = await options.body.next();
|
97
|
+
if (done) {
|
98
|
+
return { done, value };
|
99
|
+
}
|
100
|
+
return {
|
101
|
+
done,
|
102
|
+
value: {
|
103
|
+
index: value.index,
|
104
|
+
status: value.status === options.status ? void 0 : value.status,
|
105
|
+
headers: Object.keys(value.headers).length ? value.headers : void 0,
|
106
|
+
body: value.body
|
107
|
+
}
|
108
|
+
};
|
109
|
+
},
|
110
|
+
async (reason) => {
|
111
|
+
if (reason !== "next") {
|
112
|
+
await options.body.return?.();
|
103
113
|
}
|
104
|
-
} finally {
|
105
|
-
await options.body.return?.();
|
106
114
|
}
|
107
|
-
|
115
|
+
)
|
108
116
|
};
|
109
117
|
}
|
110
118
|
function parseBatchResponse(response) {
|
111
119
|
const body = response.body;
|
112
120
|
if (isAsyncIteratorObject(body) || Array.isArray(body)) {
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
});
|
120
|
-
}
|
121
|
-
yield {
|
122
|
-
index: item.index,
|
123
|
-
status: item.status ?? response.status,
|
124
|
-
headers: item.headers ?? {},
|
125
|
-
body: item.body
|
126
|
-
};
|
121
|
+
const iterator = (async function* () {
|
122
|
+
for await (const item of body) {
|
123
|
+
if (!isObject(item) || !("index" in item) || typeof item.index !== "number") {
|
124
|
+
throw new TypeError("Invalid batch response", {
|
125
|
+
cause: item
|
126
|
+
});
|
127
127
|
}
|
128
|
-
|
129
|
-
|
128
|
+
yield {
|
129
|
+
index: item.index,
|
130
|
+
status: item.status ?? response.status,
|
131
|
+
headers: item.headers ?? {},
|
132
|
+
body: item.body
|
133
|
+
};
|
134
|
+
}
|
135
|
+
})();
|
136
|
+
return new AsyncIteratorClass(
|
137
|
+
() => iterator.next(),
|
138
|
+
async (reason) => {
|
139
|
+
if (reason !== "next" && isAsyncIteratorObject(body)) {
|
130
140
|
await body.return?.();
|
131
141
|
}
|
132
142
|
}
|
133
|
-
|
143
|
+
);
|
134
144
|
}
|
135
145
|
throw new TypeError("Invalid batch response", {
|
136
146
|
cause: response
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/standard-server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.8.
|
4
|
+
"version": "1.8.7",
|
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": "1.8.
|
31
|
+
"@orpc/shared": "1.8.7"
|
32
32
|
},
|
33
33
|
"scripts": {
|
34
34
|
"build": "unbuild",
|