@orpc/nest 2.0.0-beta.51 → 2.0.0-beta.53
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 +4 -5
- package/dist/implement.d.ts +9 -2
- package/dist/implement.js +36 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
|
|
|
63
63
|
|
|
64
64
|
| Package | Purpose | Docs |
|
|
65
65
|
| -------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
66
|
-
| [@orpc/contract](https://www.npmjs.com/package/@orpc/contract) | Define API contract as the single source of truth. | [Procedure Contract](https://orpc.dev/docs/contract/procedure), [Contract
|
|
66
|
+
| [@orpc/contract](https://www.npmjs.com/package/@orpc/contract) | Define API contract as the single source of truth. | [Procedure Contract](https://orpc.dev/docs/contract/procedure), [Router Contract](https://orpc.dev/docs/contract/router), [Implementation](https://orpc.dev/docs/contract/implementation), [Generate from OpenAPI](https://orpc.dev/docs/contract/generate-from-openapi) |
|
|
67
67
|
| [@orpc/server](https://www.npmjs.com/package/@orpc/server) | Build APIs or implement contracts. | [Procedure](https://orpc.dev/docs/procedure), [Router](https://orpc.dev/docs/router), [Middleware](https://orpc.dev/docs/middleware), [Context](https://orpc.dev/docs/context), [RPC Handler](https://orpc.dev/docs/rpc/handler) |
|
|
68
68
|
| [@orpc/client](https://www.npmjs.com/package/@orpc/client) | Consume APIs with end-to-end type safety. | [Client-Side Clients](https://orpc.dev/docs/client/client-side), [Server-Side Clients](https://orpc.dev/docs/client/server-side), [RPC Link](https://orpc.dev/docs/rpc/link), [Error Handling](https://orpc.dev/docs/client/error-handling) |
|
|
69
69
|
| [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi) | Add OpenAPI compatibility to APIs. | [OpenAPI Handler](https://orpc.dev/docs/openapi/handler), [OpenAPI Link](https://orpc.dev/docs/openapi/link), [Specification](https://orpc.dev/docs/openapi/specification), [Scalar](https://orpc.dev/docs/openapi/scalar) |
|
|
@@ -183,25 +183,24 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
183
183
|
<td align="center"><a href="https://github.com/pumpkinlink?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="139" alt="Denis"/><br />Denis</a></td>
|
|
184
184
|
<td align="center"><a href="https://github.com/christopher-kapic?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="139" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
|
|
185
185
|
<td align="center"><a href="http://ballingt.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="139" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
|
|
186
|
-
<td align="center"><a href="https://lee-sam.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="139" alt="Sam"/><br />Sam</a></td>
|
|
187
186
|
<td align="center"><a href="https://github.com/Titoine?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="139" alt="Titoine"/><br />Titoine</a></td>
|
|
188
187
|
<td align="center"><a href="https://rigtch.fm/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="139" alt="Igor Makowski"/><br />Igor Makowski</a></td>
|
|
188
|
+
<td align="center"><a href="https://blog.cwang.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
|
|
189
189
|
</tr>
|
|
190
190
|
<tr>
|
|
191
|
-
<td align="center"><a href="https://blog.cwang.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
|
|
192
191
|
<td align="center"><a href="https://dubinets.io/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Lev Dubinets"><img src="https://avatars.githubusercontent.com/u/3114081?u=f547f5d5012cab54851f1b1ad72d10e537f78fc2&v=4" width="139" alt="Lev Dubinets"/><br />Lev Dubinets</a></td>
|
|
193
192
|
<td align="center"><a href="https://kellychan.im/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
194
193
|
<td align="center"><a href="https://guyariely.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
195
194
|
<td align="center"><a href="https://paulsenon.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
|
|
196
195
|
<td align="center"><a href="https://usagerail.com/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="UsageRail"><img src="https://avatars.githubusercontent.com/u/347653714?v=4" width="139" alt="UsageRail"/><br />UsageRail</a></td>
|
|
196
|
+
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
197
197
|
</tr>
|
|
198
198
|
<tr>
|
|
199
|
-
<td align="center"><a href="https://piscis.dev/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="139" alt="Alex"/><br />Alex</a></td>
|
|
200
199
|
<td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
201
200
|
</tr>
|
|
202
201
|
</table>
|
|
203
202
|
|
|
204
|
-
With thanks to [
|
|
203
|
+
With thanks to [41 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
205
204
|
|
|
206
205
|
## Open Source Programs
|
|
207
206
|
|
package/dist/implement.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ORPCModuleConfig } from "./module.js";
|
|
2
|
-
import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
|
|
2
|
+
import { CallHandler, ExecutionContext, HttpException, NestInterceptor } from "@nestjs/common";
|
|
3
3
|
import { HttpAdapterHost } from "@nestjs/core";
|
|
4
4
|
import { RouterContract } from "@orpc/contract";
|
|
5
5
|
import { ContractedRouter, DefaultInitialContext } from "@orpc/server";
|
|
@@ -26,4 +26,11 @@ export declare class ImplementInterceptor implements NestInterceptor {
|
|
|
26
26
|
private readonly httpAdapterHost;
|
|
27
27
|
constructor(config: ORPCModuleConfig | undefined, httpAdapterHost: HttpAdapterHost);
|
|
28
28
|
intercept(ctx: ExecutionContext, next: CallHandler): Observable<any>;
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The `HttpException` oRPC throws to let NestJS send an error response.
|
|
32
|
+
* Exception filters can use it to tell oRPC error responses apart from other exceptions.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://orpc.dev/docs/integrations/nest#error-handling | Implement oRPC contract with NestJS - Error Handling}
|
|
35
|
+
*/
|
|
36
|
+
export declare class ORPCHttpException extends HttpException {}
|
package/dist/implement.js
CHANGED
|
@@ -11,7 +11,7 @@ import { DEFAULT_OPENAPI_METHOD, getDynamicPathParams, getOpenAPIMeta } from "@o
|
|
|
11
11
|
import { OpenAPIHandlerCodecCore } from "@orpc/openapi/standard";
|
|
12
12
|
import { DEFAULT_SUCCESS_STATUS, Procedure, getRouter, unlazy } from "@orpc/server";
|
|
13
13
|
import { StandardHandler } from "@orpc/server/standard";
|
|
14
|
-
import { NullProtoObj, isAsyncIteratorObject, listenAbort, mergeHttpPath, stringifyJSON, toArray, value } from "@orpc/shared";
|
|
14
|
+
import { NullProtoObj, isAsyncIteratorObject, isNonPrimitive, listenAbort, mergeHttpPath, stringifyJSON, toArray, value } from "@orpc/shared";
|
|
15
15
|
import { flattenStandardHeader, generateContentDisposition, getRequiredStandardBodyHint } from "@standard-server/core";
|
|
16
16
|
import { toEventStream, toStandardLazyRequest } from "@standard-server/node";
|
|
17
17
|
import { mergeMap } from "rxjs";
|
|
@@ -26,6 +26,13 @@ const MethodDecoratorMap = {
|
|
|
26
26
|
DELETE: Delete,
|
|
27
27
|
OPTIONS: Options
|
|
28
28
|
};
|
|
29
|
+
const ACCUMULATED_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
30
|
+
"__guards__",
|
|
31
|
+
"__interceptors__",
|
|
32
|
+
"__pipes__",
|
|
33
|
+
"__exceptionFilters__",
|
|
34
|
+
"__headers__"
|
|
35
|
+
]);
|
|
29
36
|
/**
|
|
30
37
|
* Decorator that implements an oRPC contract (procedure or router contract)
|
|
31
38
|
* on a NestJS controller method. It registers the corresponding NestJS routes
|
|
@@ -67,20 +74,22 @@ function toNestRouteDecorator(contract) {
|
|
|
67
74
|
return applyDecorators(MethodDecoratorMap[method](path), HttpCode(successStatus));
|
|
68
75
|
}
|
|
69
76
|
function implementRouterContract(contract, target, propertyKey, descriptor) {
|
|
77
|
+
const originalMethod = descriptor.value;
|
|
70
78
|
for (const [key, childContract] of Object.entries(contract)) {
|
|
79
|
+
if (!isNonPrimitive(childContract)) continue;
|
|
71
80
|
let methodName = `${propertyKey}_${key}`;
|
|
72
81
|
let i = 0;
|
|
73
82
|
while (methodName in target) methodName = `${propertyKey}_${key}_${i++}`;
|
|
74
83
|
target[methodName] = async function(...args) {
|
|
75
|
-
const router = await
|
|
84
|
+
const router = await target[propertyKey].apply(this, args);
|
|
76
85
|
return getRouter(router, [key]);
|
|
77
86
|
};
|
|
78
|
-
Object.
|
|
87
|
+
const childDescriptor = Object.getOwnPropertyDescriptor(target, methodName);
|
|
79
88
|
queueMicrotask(() => {
|
|
89
|
+
inheritFunctionMetadata(childDescriptor.value, originalMethod, target[propertyKey]);
|
|
80
90
|
for (const p of Reflect.getOwnMetadataKeys(target, propertyKey)) Reflect.defineMetadata(p, Reflect.getOwnMetadata(p, target, propertyKey), target, methodName);
|
|
81
91
|
for (const p of Reflect.getOwnMetadataKeys(target.constructor, propertyKey)) Reflect.defineMetadata(p, Reflect.getOwnMetadata(p, target.constructor, propertyKey), target.constructor, methodName);
|
|
82
92
|
});
|
|
83
|
-
const childDescriptor = Object.getOwnPropertyDescriptor(target, methodName);
|
|
84
93
|
if (childContract instanceof ProcedureContract) {
|
|
85
94
|
const routeDecorator = toNestRouteDecorator(childContract);
|
|
86
95
|
queueMicrotask(() => {
|
|
@@ -89,6 +98,19 @@ function implementRouterContract(contract, target, propertyKey, descriptor) {
|
|
|
89
98
|
} else implementRouterContract(childContract, target, methodName, childDescriptor);
|
|
90
99
|
}
|
|
91
100
|
}
|
|
101
|
+
function inheritFunctionMetadata(method, originalMethod, finalMethod) {
|
|
102
|
+
Object.setPrototypeOf(method, finalMethod);
|
|
103
|
+
if (finalMethod === originalMethod) return;
|
|
104
|
+
for (const key of Reflect.getMetadataKeys(originalMethod)) {
|
|
105
|
+
const originalValue = Reflect.getMetadata(key, originalMethod);
|
|
106
|
+
if (!Reflect.hasMetadata(key, finalMethod)) Reflect.defineMetadata(key, originalValue, method);
|
|
107
|
+
else if (ACCUMULATED_METADATA_KEYS.has(key)) {
|
|
108
|
+
const originalItems = toArray(originalValue);
|
|
109
|
+
const finalItems = toArray(Reflect.getMetadata(key, finalMethod));
|
|
110
|
+
Reflect.defineMetadata(key, [...originalItems.filter((item) => !finalItems.includes(item)), ...finalItems], method);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
92
114
|
let ImplementInterceptor = class ImplementInterceptor {
|
|
93
115
|
config;
|
|
94
116
|
codec;
|
|
@@ -129,7 +151,7 @@ let ImplementInterceptor = class ImplementInterceptor {
|
|
|
129
151
|
if (index === 0) httpAdapter.setHeader(res, key, value);
|
|
130
152
|
else httpAdapter.appendHeader(res, key, value);
|
|
131
153
|
});
|
|
132
|
-
if (nestBody instanceof
|
|
154
|
+
if (nestBody instanceof ORPCHttpException) throw nestBody;
|
|
133
155
|
return nestBody;
|
|
134
156
|
}));
|
|
135
157
|
}
|
|
@@ -142,6 +164,13 @@ ImplementInterceptor = __decorate([
|
|
|
142
164
|
__decorateMetadata("design:paramtypes", [Object, typeof HttpAdapterHost === "undefined" ? Object : HttpAdapterHost])
|
|
143
165
|
], ImplementInterceptor);
|
|
144
166
|
/**
|
|
167
|
+
* The `HttpException` oRPC throws to let NestJS send an error response.
|
|
168
|
+
* Exception filters can use it to tell oRPC error responses apart from other exceptions.
|
|
169
|
+
*
|
|
170
|
+
* @see {@link https://orpc.dev/docs/integrations/nest#error-handling | Implement oRPC contract with NestJS - Error Handling}
|
|
171
|
+
*/
|
|
172
|
+
var ORPCHttpException = class extends HttpException {};
|
|
173
|
+
/**
|
|
145
174
|
* Mirrors `toNodeHttpBody` from `@standard-server/node`, but returns a body NestJS can respond with.
|
|
146
175
|
*/
|
|
147
176
|
function toNestHttpBody(response, signal, options) {
|
|
@@ -182,7 +211,7 @@ function toNestHttpBody(response, signal, options) {
|
|
|
182
211
|
}
|
|
183
212
|
if (status >= 300 && typeof body === "object" && body !== null && !Array.isArray(body)) {
|
|
184
213
|
if (headers["content-type"] !== void 0) headers["standard-server"] = getRequiredStandardBodyHint("json", headers);
|
|
185
|
-
return [new
|
|
214
|
+
return [new ORPCHttpException(body, status), headers];
|
|
186
215
|
}
|
|
187
216
|
headers["content-type"] ??= "application/json";
|
|
188
217
|
headers["standard-server"] = getRequiredStandardBodyHint("json", headers);
|
|
@@ -250,4 +279,4 @@ function toNestPattern(path) {
|
|
|
250
279
|
}
|
|
251
280
|
return path;
|
|
252
281
|
}
|
|
253
|
-
export { Implement, ImplementInterceptor };
|
|
282
|
+
export { Implement, ImplementInterceptor, ORPCHttpException };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ORPC_MODULE_CONFIG_SYMBOL } from "./constants.js";
|
|
2
|
-
import { Implement, ImplementInterceptor } from "./implement.js";
|
|
2
|
+
import { Implement, ImplementInterceptor, ORPCHttpException } from "./implement.js";
|
|
3
3
|
import { NestStandardLazyRequest, ORPCModule, ORPCModuleConfig } from "./module.js";
|
|
4
|
-
export { Implement as Impl, Implement, ImplementInterceptor, NestStandardLazyRequest, ORPCModule, ORPCModuleConfig, ORPC_MODULE_CONFIG_SYMBOL };
|
|
4
|
+
export { Implement as Impl, Implement, ImplementInterceptor, NestStandardLazyRequest, ORPCHttpException, ORPCModule, ORPCModuleConfig, ORPC_MODULE_CONFIG_SYMBOL };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ORPC_MODULE_CONFIG_SYMBOL } from "./constants.js";
|
|
2
|
-
export { Implement as Impl, Implement, ImplementInterceptor } from "./implement.js";
|
|
2
|
+
export { Implement as Impl, Implement, ImplementInterceptor, ORPCHttpException } from "./implement.js";
|
|
3
3
|
export { ORPCModule } from "./module.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/nest",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.53",
|
|
4
4
|
"description": "NestJS integration for oRPC: implement typesafe contracts in NestJS controllers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contract-first",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@orpc/
|
|
41
|
-
"@orpc/
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/shared": "2.0.0-beta.51",
|
|
40
|
+
"@orpc/contract": "2.0.0-beta.53",
|
|
41
|
+
"@orpc/openapi": "2.0.0-beta.53",
|
|
42
|
+
"@orpc/server": "2.0.0-beta.53",
|
|
43
|
+
"@orpc/shared": "2.0.0-beta.53",
|
|
45
44
|
"@oxc-project/runtime": "^0.157.0",
|
|
46
45
|
"@standard-server/core": "~0.16.0",
|
|
47
46
|
"@standard-server/node": "~0.16.0"
|