@orpc/nest 2.0.0-beta.50 → 2.0.0-beta.52

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 CHANGED
@@ -78,13 +78,14 @@ Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [
78
78
 
79
79
  **Built-in features**
80
80
 
81
- | Package | Purpose | Docs |
82
- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
83
- | [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
84
- | [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
85
- | [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
86
- | [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
87
- | [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
81
+ | Package | Purpose | Docs |
82
+ | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
83
+ | [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher) | Pub/Sub with memory, Redis, and Upstash adapters. | [Publisher](https://orpc.dev/docs/helpers/publisher) |
84
+ | [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit) | Rate limiting with memory, Redis, and Upstash adapters. | [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
85
+ | [@orpc/experimental-lock](https://www.npmjs.com/package/@orpc/experimental-lock) | Locking with memory, Redis, and Upstash adapters. | [Lock](https://orpc.dev/docs/helpers/lock) |
86
+ | [@orpc/experimental-openapi-inference](https://www.npmjs.com/package/@orpc/experimental-openapi-inference) | Generate OpenAPI specs from TypeScript types, no output schemas required. | [Type Inference](https://orpc.dev/docs/openapi/specification#type-inference) |
87
+ | [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation) | Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | [Hibernation](https://orpc.dev/docs/integrations/hibernation) |
88
+ | [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema) | Smart coercion for OpenAPI requests. | [Smart Coercion](https://orpc.dev/docs/plugins/smart-coercion) |
88
89
 
89
90
  **Framework & ecosystem integrations**
90
91
 
@@ -182,16 +183,16 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
182
183
  <td align="center"><a href="https://github.com/pumpkinlink?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&amp;v=4" width="139" alt="Denis"/><br />Denis</a></td>
183
184
  <td align="center"><a href="https://github.com/christopher-kapic?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&amp;v=4" width="139" alt="Christopher Kapic"/><br />Christopher Kapic</a></td>
184
185
  <td align="center"><a href="http://ballingt.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&amp;v=4" width="139" alt="Tom Ballinger"/><br />Tom Ballinger</a></td>
185
- <td align="center"><a href="https://lee-sam.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&amp;v=4" width="139" alt="Sam"/><br />Sam</a></td>
186
186
  <td align="center"><a href="https://github.com/Titoine?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&amp;v=4" width="139" alt="Titoine"/><br />Titoine</a></td>
187
187
  <td align="center"><a href="https://rigtch.fm/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&amp;v=4" width="139" alt="Igor Makowski"/><br />Igor Makowski</a></td>
188
+ <td align="center"><a href="https://blog.cwang.io/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&amp;v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
188
189
  </tr>
189
190
  <tr>
190
- <td align="center"><a href="https://blog.cwang.io/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&amp;v=4" width="139" alt="hanayashiki"/><br />hanayashiki</a></td>
191
191
  <td align="center"><a href="https://dubinets.io/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Lev Dubinets"><img src="https://avatars.githubusercontent.com/u/3114081?u=f547f5d5012cab54851f1b1ad72d10e537f78fc2&amp;v=4" width="139" alt="Lev Dubinets"/><br />Lev Dubinets</a></td>
192
192
  <td align="center"><a href="https://kellychan.im/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
193
193
  <td align="center"><a href="https://guyariely.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&amp;v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
194
194
  <td align="center"><a href="https://paulsenon.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&amp;v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
195
+ <td align="center"><a href="https://usagerail.com/?ref=middleapi&amp;utm_source=middleapi&amp;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>
195
196
  <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
196
197
  </tr>
197
198
  <tr>
@@ -199,7 +200,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
199
200
  </tr>
200
201
  </table>
201
202
 
202
- With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
203
+ With thanks to [41 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
203
204
 
204
205
  ## Open Source Programs
205
206
 
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 descriptor.value.apply(this, args);
84
+ const router = await target[propertyKey].apply(this, args);
76
85
  return getRouter(router, [key]);
77
86
  };
78
- Object.setPrototypeOf(target[methodName], descriptor.value);
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;
package/dist/module.d.ts CHANGED
@@ -17,7 +17,7 @@ export interface NestStandardLazyRequest extends StandardLazyRequest {
17
17
  */
18
18
  params?: Record<string, string | string[]> | undefined;
19
19
  }
20
- export type ORPCModuleConfig = OpenAPIHandlerCodecCoreOptions<DefaultInitialContext> & StandardHandlerOptions<DefaultInitialContext> & (object extends DefaultInitialContext ? {
20
+ export type ORPCModuleConfig = OpenAPIHandlerCodecCoreOptions<DefaultInitialContext> & StandardHandlerOptions<DefaultInitialContext> & ({} extends DefaultInitialContext ? {
21
21
  context?: Value<Promisable<DefaultInitialContext>, [ctx: ExecutionContext]> | undefined;
22
22
  } : {
23
23
  context: Value<Promisable<DefaultInitialContext>, [ctx: ExecutionContext]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orpc/nest",
3
- "version": "2.0.0-beta.50",
3
+ "version": "2.0.0-beta.52",
4
4
  "description": "NestJS integration for oRPC: implement typesafe contracts in NestJS controllers",
5
5
  "keywords": [
6
6
  "contract-first",
@@ -37,11 +37,11 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@orpc/client": "2.0.0-beta.50",
41
- "@orpc/contract": "2.0.0-beta.50",
42
- "@orpc/openapi": "2.0.0-beta.50",
43
- "@orpc/server": "2.0.0-beta.50",
44
- "@orpc/shared": "2.0.0-beta.50",
40
+ "@orpc/client": "2.0.0-beta.52",
41
+ "@orpc/contract": "2.0.0-beta.52",
42
+ "@orpc/openapi": "2.0.0-beta.52",
43
+ "@orpc/server": "2.0.0-beta.52",
44
+ "@orpc/shared": "2.0.0-beta.52",
45
45
  "@oxc-project/runtime": "^0.157.0",
46
46
  "@standard-server/core": "~0.16.0",
47
47
  "@standard-server/node": "~0.16.0"