@orpc/nest 2.0.0-beta.46 → 2.0.0-beta.47
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 +6 -3
- package/dist/index.mjs +65 -54
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -156,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
156
156
|
<td align="center"><a href="https://github.com/christ12938?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
|
|
157
157
|
<td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
158
158
|
<td align="center"><a href="https://github.com/itigoore01?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="167" alt="shota"/><br />shota</a></td>
|
|
159
|
+
<td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
|
|
159
160
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
160
|
-
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
161
161
|
</tr>
|
|
162
162
|
<tr>
|
|
163
|
+
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
163
164
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
164
165
|
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
165
166
|
</tr>
|
|
@@ -198,7 +199,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
198
199
|
</tr>
|
|
199
200
|
</table>
|
|
200
201
|
|
|
201
|
-
With thanks to [
|
|
202
|
+
With thanks to [39 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
202
203
|
|
|
203
204
|
## Open Source Programs
|
|
204
205
|
|
|
@@ -206,7 +207,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
206
207
|
|
|
207
208
|
<table>
|
|
208
209
|
<tr>
|
|
209
|
-
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude
|
|
210
|
+
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
|
|
211
|
+
<td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
|
|
212
|
+
<td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
|
|
210
213
|
</tr>
|
|
211
214
|
</table>
|
|
212
215
|
|
package/dist/index.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { getOpenAPIMeta, DEFAULT_OPENAPI_METHOD, getDynamicPathParams } from '@o
|
|
|
7
7
|
import { OpenAPIHandlerCodecCore } from '@orpc/openapi/standard';
|
|
8
8
|
import { unlazy, Procedure, DEFAULT_SUCCESS_STATUS, getRouter } from '@orpc/server';
|
|
9
9
|
import { StandardHandler } from '@orpc/server/standard';
|
|
10
|
-
import { value, isAsyncIteratorObject, stringifyJSON,
|
|
11
|
-
import {
|
|
10
|
+
import { value, toArray, mergeHttpPath, isAsyncIteratorObject, stringifyJSON, NullProtoObj } from '@orpc/shared';
|
|
11
|
+
import { generateContentDisposition, getRequiredStandardBodyHint, flattenStandardHeader } from '@standard-server/core';
|
|
12
12
|
import { toStandardLazyRequest, toEventStream } from '@standard-server/node';
|
|
13
13
|
import { mergeMap } from 'rxjs';
|
|
14
14
|
|
|
@@ -194,61 +194,22 @@ let ImplementInterceptor = class {
|
|
|
194
194
|
"oRPC NestJS handler returned an unmatched result, which should never happen. Please check your plugins/interceptors or report a bug."
|
|
195
195
|
);
|
|
196
196
|
}
|
|
197
|
+
const [nestBody, headers] = toNestHttpBody(result.response, standardRequest.signal, this.config.toNestResponse);
|
|
197
198
|
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
198
199
|
httpAdapter.status(res, result.response.status);
|
|
199
|
-
for (const key of Object.keys(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
httpAdapter.setHeader(res, key, value3);
|
|
207
|
-
} else {
|
|
208
|
-
httpAdapter.appendHeader(res, key, value3);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const body = result.response.body;
|
|
214
|
-
if (body instanceof ReadableStream) {
|
|
215
|
-
httpAdapter.setHeader(res, "standard-server", "octet-stream");
|
|
216
|
-
return toStreamableFile(Readable.fromWeb(body), standardRequest.signal, {
|
|
217
|
-
type: flattenStandardHeader(result.response.headers["content-type"]) ?? "application/octet-stream"
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
if (isAsyncIteratorObject(body)) {
|
|
221
|
-
return toStreamableFile(toEventStream(body, this.config.toNestResponse?.eventStream), standardRequest.signal, {
|
|
222
|
-
type: "text/event-stream"
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
if (body instanceof Blob) {
|
|
226
|
-
httpAdapter.setHeader(res, "standard-server", "file");
|
|
227
|
-
return toStreamableFile(Readable.fromWeb(body.stream()), standardRequest.signal, {
|
|
228
|
-
type: body.type,
|
|
229
|
-
disposition: flattenStandardHeader(result.response.headers["content-disposition"]) ?? generateContentDisposition(body instanceof File ? body.name : "blob"),
|
|
230
|
-
// BunS3 can use NaN for the size
|
|
231
|
-
length: Number.isFinite(body.size) ? body.size : void 0
|
|
200
|
+
for (const key of Object.keys(headers)) {
|
|
201
|
+
toArray(headers[key]).forEach((value2, index) => {
|
|
202
|
+
if (index === 0) {
|
|
203
|
+
httpAdapter.setHeader(res, key, value2);
|
|
204
|
+
} else {
|
|
205
|
+
httpAdapter.appendHeader(res, key, value2);
|
|
206
|
+
}
|
|
232
207
|
});
|
|
233
208
|
}
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
return toStreamableFile(Readable.fromWeb(response.body), standardRequest.signal, {
|
|
237
|
-
type: response.headers.get("content-type")
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
if (body instanceof URLSearchParams) {
|
|
241
|
-
httpAdapter.setHeader(res, "content-type", "application/x-www-form-urlencoded");
|
|
242
|
-
return body.toString();
|
|
243
|
-
}
|
|
244
|
-
if (body === void 0) {
|
|
245
|
-
return body;
|
|
209
|
+
if (nestBody instanceof HttpException) {
|
|
210
|
+
throw nestBody;
|
|
246
211
|
}
|
|
247
|
-
|
|
248
|
-
throw new HttpException(body, result.response.status);
|
|
249
|
-
}
|
|
250
|
-
httpAdapter.setHeader(res, "content-type", "application/json");
|
|
251
|
-
return typeof body === "string" || body === null ? stringifyJSON(body) : body;
|
|
212
|
+
return nestBody;
|
|
252
213
|
})
|
|
253
214
|
);
|
|
254
215
|
}
|
|
@@ -259,6 +220,54 @@ ImplementInterceptor = __decorateClass([
|
|
|
259
220
|
__decorateParam(0, Optional()),
|
|
260
221
|
__decorateParam(1, Inject(HttpAdapterHost))
|
|
261
222
|
], ImplementInterceptor);
|
|
223
|
+
function toNestHttpBody(response, signal, options) {
|
|
224
|
+
const { status, body } = response;
|
|
225
|
+
const headers = { ...response.headers };
|
|
226
|
+
if (body instanceof ReadableStream) {
|
|
227
|
+
headers["standard-server"] ??= "octet-stream";
|
|
228
|
+
headers["content-type"] ??= "application/octet-stream";
|
|
229
|
+
return [toStreamableFile(Readable.fromWeb(body), headers, signal), headers];
|
|
230
|
+
}
|
|
231
|
+
if (body instanceof Blob) {
|
|
232
|
+
headers["standard-server"] ??= "file";
|
|
233
|
+
headers["content-type"] ??= body.type;
|
|
234
|
+
headers["content-disposition"] ??= generateContentDisposition(body instanceof File ? body.name : "blob");
|
|
235
|
+
if (Number.isFinite(body.size)) {
|
|
236
|
+
headers["content-length"] = body.size.toString();
|
|
237
|
+
}
|
|
238
|
+
return [toStreamableFile(Readable.fromWeb(body.stream()), headers, signal), headers];
|
|
239
|
+
}
|
|
240
|
+
headers["standard-server"] = void 0;
|
|
241
|
+
headers["content-length"] = void 0;
|
|
242
|
+
if (body === void 0) {
|
|
243
|
+
headers["standard-server"] = getRequiredStandardBodyHint("none", headers);
|
|
244
|
+
return [void 0, headers];
|
|
245
|
+
}
|
|
246
|
+
if (body instanceof FormData) {
|
|
247
|
+
const response2 = new Response(body);
|
|
248
|
+
headers["content-type"] = response2.headers.get("content-type");
|
|
249
|
+
return [toStreamableFile(Readable.fromWeb(response2.body), headers, signal), headers];
|
|
250
|
+
}
|
|
251
|
+
if (body instanceof URLSearchParams) {
|
|
252
|
+
headers["content-type"] ??= "application/x-www-form-urlencoded";
|
|
253
|
+
headers["standard-server"] = getRequiredStandardBodyHint("url-search-params", headers);
|
|
254
|
+
return [body.toString(), headers];
|
|
255
|
+
}
|
|
256
|
+
if (isAsyncIteratorObject(body)) {
|
|
257
|
+
headers["content-type"] ??= "text/event-stream";
|
|
258
|
+
headers["standard-server"] = getRequiredStandardBodyHint("event-stream", headers);
|
|
259
|
+
return [toStreamableFile(toEventStream(body, options?.eventStream), headers, signal), headers];
|
|
260
|
+
}
|
|
261
|
+
if (status >= 300 && typeof body === "object" && body !== null && !Array.isArray(body)) {
|
|
262
|
+
if (headers["content-type"] !== void 0) {
|
|
263
|
+
headers["standard-server"] = getRequiredStandardBodyHint("json", headers);
|
|
264
|
+
}
|
|
265
|
+
return [new HttpException(body, status), headers];
|
|
266
|
+
}
|
|
267
|
+
headers["content-type"] ??= "application/json";
|
|
268
|
+
headers["standard-server"] = getRequiredStandardBodyHint("json", headers);
|
|
269
|
+
return [typeof body === "string" || body === null || headers["standard-server"] !== void 0 ? stringifyJSON(body) : body, headers];
|
|
270
|
+
}
|
|
262
271
|
class NestHandlerCodec extends OpenAPIHandlerCodecCore {
|
|
263
272
|
CONTEXT_SYMBOL = Symbol("ORPC_NEST_HANDLER_CODEC_CONTEXT");
|
|
264
273
|
withMatch(context, match) {
|
|
@@ -280,13 +289,15 @@ class NestHandlerCodec extends OpenAPIHandlerCodecCore {
|
|
|
280
289
|
};
|
|
281
290
|
}
|
|
282
291
|
}
|
|
283
|
-
function toStreamableFile(stream,
|
|
292
|
+
function toStreamableFile(stream, headers, signal) {
|
|
293
|
+
const type = flattenStandardHeader(headers["content-type"]);
|
|
294
|
+
headers["content-type"] = void 0;
|
|
284
295
|
if (signal?.aborted) {
|
|
285
296
|
stream.destroy();
|
|
286
297
|
} else {
|
|
287
298
|
signal?.addEventListener("abort", () => stream.destroy(), { once: true });
|
|
288
299
|
}
|
|
289
|
-
return new StreamableFile(stream,
|
|
300
|
+
return new StreamableFile(stream, { type });
|
|
290
301
|
}
|
|
291
302
|
function flattenParamValue(value2) {
|
|
292
303
|
return Array.isArray(value2) ? value2.join("/") : value2;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/nest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.47",
|
|
5
5
|
"description": "NestJS integration for oRPC: implement typesafe contracts in NestJS controllers",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@orpc/client": "2.0.0-beta.
|
|
56
|
-
"@orpc/contract": "2.0.0-beta.
|
|
57
|
-
"@orpc/openapi": "2.0.0-beta.
|
|
58
|
-
"@orpc/server": "2.0.0-beta.
|
|
59
|
-
"@orpc/shared": "2.0.0-beta.
|
|
60
|
-
"@standard-server/core": "~0.
|
|
61
|
-
"@standard-server/node": "~0.
|
|
55
|
+
"@orpc/client": "2.0.0-beta.47",
|
|
56
|
+
"@orpc/contract": "2.0.0-beta.47",
|
|
57
|
+
"@orpc/openapi": "2.0.0-beta.47",
|
|
58
|
+
"@orpc/server": "2.0.0-beta.47",
|
|
59
|
+
"@orpc/shared": "2.0.0-beta.47",
|
|
60
|
+
"@standard-server/core": "~0.13.0",
|
|
61
|
+
"@standard-server/node": "~0.13.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@fastify/cookie": "^11.1.3",
|