@orpc/nest 1.16.3 → 1.16.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +38 -3
  2. package/package.json +11 -11
package/dist/index.mjs CHANGED
@@ -79,6 +79,13 @@ const MethodDecoratorMap = {
79
79
  DELETE: Delete,
80
80
  OPTIONS: Options
81
81
  };
82
+ const ACCUMULATED_METADATA_KEYS = /* @__PURE__ */ new Set([
83
+ "__guards__",
84
+ "__interceptors__",
85
+ "__pipes__",
86
+ "__exceptionFilters__",
87
+ "__headers__"
88
+ ]);
82
89
  function Implement(contract) {
83
90
  if (isContractProcedure(contract)) {
84
91
  const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
@@ -99,6 +106,7 @@ function Implement(contract) {
99
106
  };
100
107
  }
101
108
  return (target, propertyKey, descriptor) => {
109
+ const originalMethod = descriptor.value;
102
110
  for (const key in contract) {
103
111
  let methodName = `${propertyKey}_${key}`;
104
112
  let i = 0;
@@ -106,20 +114,47 @@ function Implement(contract) {
106
114
  methodName = `${propertyKey}_${key}_${i++}`;
107
115
  }
108
116
  target[methodName] = async function(...args) {
109
- const router = await descriptor.value.apply(this, args);
117
+ const router = await target[propertyKey].apply(this, args);
110
118
  return getRouter(router, [key]);
111
119
  };
112
- Object.setPrototypeOf(target[methodName], descriptor.value);
120
+ const childDescriptor = Object.getOwnPropertyDescriptor(target, methodName);
121
+ Object.setPrototypeOf(childDescriptor.value, originalMethod);
122
+ queueMicrotask(() => {
123
+ inheritFunctionMetadata(childDescriptor.value, originalMethod, target[propertyKey]);
124
+ });
113
125
  for (const p of Reflect.getOwnMetadataKeys(target, propertyKey)) {
114
126
  Reflect.defineMetadata(p, Reflect.getOwnMetadata(p, target, propertyKey), target, methodName);
115
127
  }
116
128
  for (const p of Reflect.getOwnMetadataKeys(target.constructor, propertyKey)) {
117
129
  Reflect.defineMetadata(p, Reflect.getOwnMetadata(p, target.constructor, propertyKey), target.constructor, methodName);
118
130
  }
119
- Implement(get(contract, [key]))(target, methodName, Object.getOwnPropertyDescriptor(target, methodName));
131
+ Implement(get(contract, [key]))(target, methodName, childDescriptor);
120
132
  }
121
133
  };
122
134
  }
135
+ function inheritFunctionMetadata(method, originalMethod, finalMethod) {
136
+ Object.setPrototypeOf(method, finalMethod);
137
+ if (finalMethod === originalMethod) {
138
+ return;
139
+ }
140
+ for (const key of Reflect.getMetadataKeys(originalMethod)) {
141
+ if (Reflect.hasOwnMetadata(key, method)) {
142
+ continue;
143
+ }
144
+ const originalValue = Reflect.getMetadata(key, originalMethod);
145
+ if (!Reflect.hasMetadata(key, finalMethod)) {
146
+ Reflect.defineMetadata(key, originalValue, method);
147
+ } else if (ACCUMULATED_METADATA_KEYS.has(key)) {
148
+ const originalItems = toArray(originalValue);
149
+ const finalItems = toArray(Reflect.getMetadata(key, finalMethod));
150
+ Reflect.defineMetadata(
151
+ key,
152
+ [...originalItems.filter((item) => !finalItems.includes(item)), ...finalItems],
153
+ method
154
+ );
155
+ }
156
+ }
157
+ }
123
158
  let ImplementInterceptor = class {
124
159
  config;
125
160
  codec;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/nest",
3
3
  "type": "module",
4
- "version": "1.16.3",
4
+ "version": "1.16.4",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.dev",
7
7
  "repository": {
@@ -39,16 +39,16 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@orpc/client": "1.16.3",
43
- "@orpc/openapi-client": "1.16.3",
44
- "@orpc/contract": "1.16.3",
45
- "@orpc/shared": "1.16.3",
46
- "@orpc/standard-server": "1.16.3",
47
- "@orpc/server": "1.16.3",
48
- "@orpc/standard-server-fetch": "1.16.3",
49
- "@orpc/standard-server-fastify": "1.16.3",
50
- "@orpc/openapi": "1.16.3",
51
- "@orpc/standard-server-node": "1.16.3"
42
+ "@orpc/client": "1.16.4",
43
+ "@orpc/contract": "1.16.4",
44
+ "@orpc/openapi": "1.16.4",
45
+ "@orpc/server": "1.16.4",
46
+ "@orpc/shared": "1.16.4",
47
+ "@orpc/openapi-client": "1.16.4",
48
+ "@orpc/standard-server": "1.16.4",
49
+ "@orpc/standard-server-fetch": "1.16.4",
50
+ "@orpc/standard-server-fastify": "1.16.4",
51
+ "@orpc/standard-server-node": "1.16.4"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@fastify/cookie": "^11.0.2",