Skip to content

Commit afbacbf

Browse files
fix() fix default param metadata (rpc & websockets)
1 parent dd7288a commit afbacbf

7 files changed

Lines changed: 22 additions & 7 deletions

File tree

packages/microservices/context/rpc-context-creator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { PARAM_ARGS_METADATA } from '../constants';
2727
import { RpcException } from '../exceptions';
2828
import { RpcParamsFactory } from '../factories/rpc-params-factory';
2929
import { ExceptionFiltersContext } from './exception-filters-context';
30+
import { DEFAULT_CALLBACK_METADATA } from './rpc-metadata-constants';
3031
import { RpcProxy } from './rpc-proxy';
3132

3233
type RpcParamProperties = ParamProperties & { metatype?: any };
@@ -173,8 +174,8 @@ export class RpcContextCreator {
173174
this.contextUtils.reflectCallbackMetadata<T>(
174175
instance,
175176
methodName,
176-
PARAM_ARGS_METADATA || '',
177-
) || {};
177+
PARAM_ARGS_METADATA,
178+
) || DEFAULT_CALLBACK_METADATA;
178179
const keys = Object.keys(metadata);
179180
const argsLength = this.contextUtils.getArgumentsLength(keys, metadata);
180181
const paramtypes = this.contextUtils.reflectCallbackParamtypes(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { RpcParamtype } from '../enums/rpc-paramtype.enum';
2+
3+
export const DEFAULT_CALLBACK_METADATA = {
4+
[`${RpcParamtype.CONTEXT}:1`]: { index: 1, data: undefined, pipes: [] },
5+
[`${RpcParamtype.PAYLOAD}:0`]: { index: 0, data: undefined, pipes: [] },
6+
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export enum RpcParamtype {
2-
PAYLOAD = 0,
3-
CONTEXT = 1,
2+
PAYLOAD = 3,
3+
CONTEXT = 4,
44
}

packages/microservices/test/context/rpc-context-creator.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ describe('RpcContextCreator', () => {
179179
];
180180
expect(values[0]).to.deep.include(expectedValues[0]);
181181
expect(values[1]).to.deep.include(expectedValues[1]);
182+
expect(values[2]).to.deep.include(expectedValues[2]);
182183
});
183184
});
184185
describe('getParamValue', () => {

packages/websockets/context/ws-context-creator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { PARAM_ARGS_METADATA } from '../constants';
2525
import { WsException } from '../errors/ws-exception';
2626
import { WsParamsFactory } from '../factories/ws-params-factory';
2727
import { ExceptionFiltersContext } from './exception-filters-context';
28+
import { DEFAULT_CALLBACK_METADATA } from './ws-metadata-constants';
2829
import { WsProxy } from './ws-proxy';
2930

3031
type WsParamProperties = ParamProperties & { metatype?: any };
@@ -153,8 +154,8 @@ export class WsContextCreator {
153154
this.contextUtils.reflectCallbackMetadata<T>(
154155
instance,
155156
methodName,
156-
PARAM_ARGS_METADATA || '',
157-
) || {};
157+
PARAM_ARGS_METADATA,
158+
) || DEFAULT_CALLBACK_METADATA;
158159
const keys = Object.keys(metadata);
159160
const argsLength = this.contextUtils.getArgumentsLength(keys, metadata);
160161
const paramtypes = this.contextUtils.reflectCallbackParamtypes(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { WsParamtype } from '../enums/ws-paramtype.enum';
2+
3+
export const DEFAULT_CALLBACK_METADATA = {
4+
[`${WsParamtype.PAYLOAD}:1`]: { index: 1, data: undefined, pipes: [] },
5+
[`${WsParamtype.SOCKET}:0`]: { index: 0, data: undefined, pipes: [] },
6+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export enum WsParamtype {
22
SOCKET = 0,
3-
PAYLOAD = 1,
3+
PAYLOAD = 3,
44
}

0 commit comments

Comments
 (0)