@nestjs/websockets 11.1.16 → 12.0.0-alpha.1

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 (74) hide show
  1. package/adapters/index.d.ts +1 -1
  2. package/adapters/index.js +1 -4
  3. package/adapters/ws-adapter.d.ts +2 -2
  4. package/adapters/ws-adapter.js +10 -12
  5. package/constants.js +13 -16
  6. package/context/exception-filters-context.d.ts +3 -3
  7. package/context/exception-filters-context.js +7 -12
  8. package/context/ws-context-creator.d.ts +7 -16
  9. package/context/ws-context-creator.js +38 -30
  10. package/context/ws-metadata-constants.js +5 -8
  11. package/context/ws-proxy.d.ts +1 -1
  12. package/context/ws-proxy.js +8 -12
  13. package/decorators/ack.decorator.js +4 -7
  14. package/decorators/connected-socket.decorator.js +3 -6
  15. package/decorators/gateway-server.decorator.js +3 -7
  16. package/decorators/index.d.ts +6 -6
  17. package/decorators/index.js +6 -9
  18. package/decorators/message-body.decorator.d.ts +27 -1
  19. package/decorators/message-body.decorator.js +4 -7
  20. package/decorators/socket-gateway.decorator.d.ts +1 -1
  21. package/decorators/socket-gateway.decorator.js +5 -8
  22. package/decorators/subscribe-message.decorator.js +4 -8
  23. package/enums/ws-paramtype.enum.js +2 -5
  24. package/errors/index.d.ts +1 -1
  25. package/errors/index.js +1 -4
  26. package/errors/invalid-socket-port.exception.d.ts +1 -1
  27. package/errors/invalid-socket-port.exception.js +2 -6
  28. package/errors/ws-exception.js +6 -9
  29. package/exceptions/base-ws-exception-filter.d.ts +1 -1
  30. package/exceptions/base-ws-exception-filter.js +12 -15
  31. package/exceptions/index.d.ts +1 -1
  32. package/exceptions/index.js +1 -4
  33. package/exceptions/ws-exceptions-handler.d.ts +4 -4
  34. package/exceptions/ws-exceptions-handler.js +8 -16
  35. package/factories/server-and-event-streams-factory.d.ts +1 -1
  36. package/factories/server-and-event-streams-factory.js +5 -9
  37. package/factories/ws-params-factory.js +7 -11
  38. package/gateway-metadata-explorer.d.ts +2 -2
  39. package/gateway-metadata-explorer.js +15 -18
  40. package/index.d.ts +6 -6
  41. package/index.js +6 -9
  42. package/interfaces/gateway-metadata.interface.d.ts +1 -1
  43. package/interfaces/gateway-metadata.interface.js +1 -2
  44. package/interfaces/hooks/index.d.ts +3 -3
  45. package/interfaces/hooks/index.js +3 -6
  46. package/interfaces/hooks/on-gateway-connection.interface.js +1 -2
  47. package/interfaces/hooks/on-gateway-disconnect.interface.d.ts +1 -1
  48. package/interfaces/hooks/on-gateway-disconnect.interface.js +1 -2
  49. package/interfaces/hooks/on-gateway-init.interface.js +1 -2
  50. package/interfaces/index.d.ts +5 -5
  51. package/interfaces/index.js +5 -8
  52. package/interfaces/nest-gateway.interface.d.ts +1 -1
  53. package/interfaces/nest-gateway.interface.js +1 -2
  54. package/interfaces/server-and-event-streams-host.interface.js +1 -2
  55. package/interfaces/web-socket-server.interface.js +1 -2
  56. package/interfaces/websockets-entrypoint-metadata.interface.js +1 -2
  57. package/interfaces/ws-response.interface.js +1 -2
  58. package/internal.d.ts +8 -0
  59. package/internal.js +8 -0
  60. package/package.json +18 -4
  61. package/socket-module.d.ts +5 -8
  62. package/socket-module.js +26 -33
  63. package/socket-server-provider.d.ts +4 -4
  64. package/socket-server-provider.js +9 -11
  65. package/sockets-container.d.ts +1 -1
  66. package/sockets-container.js +3 -9
  67. package/tsconfig.build.json +1 -7
  68. package/utils/compare-element.util.js +1 -4
  69. package/utils/index.d.ts +1 -1
  70. package/utils/index.js +1 -4
  71. package/utils/param.utils.d.ts +3 -3
  72. package/utils/param.utils.js +40 -17
  73. package/web-sockets-controller.d.ts +9 -10
  74. package/web-sockets-controller.js +41 -28
@@ -1 +1 @@
1
- export * from './ws-adapter';
1
+ export * from './ws-adapter.js';
package/adapters/index.js CHANGED
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./ws-adapter"), exports);
1
+ export * from './ws-adapter.js';
@@ -1,6 +1,6 @@
1
- import { INestApplicationContext, WebSocketAdapter } from '@nestjs/common';
2
- import { WsMessageHandler } from '@nestjs/common/interfaces';
1
+ import type { INestApplicationContext, WebSocketAdapter } from '@nestjs/common';
3
2
  import { Observable } from 'rxjs';
3
+ import type { WsMessageHandler } from '@nestjs/common';
4
4
  export interface BaseWsInstance {
5
5
  on: (event: string, callback: Function) => void;
6
6
  close: Function;
@@ -1,10 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractWsAdapter = void 0;
4
- const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
- const core_1 = require("@nestjs/core");
6
- const constants_1 = require("../constants");
7
- class AbstractWsAdapter {
1
+ import { NestApplication } from '@nestjs/core';
2
+ import { CONNECTION_EVENT, DISCONNECT_EVENT } from '../constants.js';
3
+ import { isFunction } from '@nestjs/common/internal';
4
+ export class AbstractWsAdapter {
5
+ httpServer;
6
+ _forceCloseConnections;
8
7
  set forceCloseConnections(value) {
9
8
  this._forceCloseConnections = value;
10
9
  }
@@ -12,7 +11,7 @@ class AbstractWsAdapter {
12
11
  return this._forceCloseConnections;
13
12
  }
14
13
  constructor(appOrHttpServer) {
15
- if (appOrHttpServer && appOrHttpServer instanceof core_1.NestApplication) {
14
+ if (appOrHttpServer && appOrHttpServer instanceof NestApplication) {
16
15
  this.httpServer = appOrHttpServer.getUnderlyingHttpServer();
17
16
  }
18
17
  else {
@@ -20,15 +19,14 @@ class AbstractWsAdapter {
20
19
  }
21
20
  }
22
21
  bindClientConnect(server, callback) {
23
- server.on(constants_1.CONNECTION_EVENT, callback);
22
+ server.on(CONNECTION_EVENT, callback);
24
23
  }
25
24
  bindClientDisconnect(client, callback) {
26
- client.on(constants_1.DISCONNECT_EVENT, callback);
25
+ client.on(DISCONNECT_EVENT, callback);
27
26
  }
28
27
  async close(server) {
29
- const isCallable = server && (0, shared_utils_1.isFunction)(server.close);
28
+ const isCallable = server && isFunction(server.close);
30
29
  isCallable && (await new Promise(resolve => server.close(resolve)));
31
30
  }
32
31
  async dispose() { }
33
32
  }
34
- exports.AbstractWsAdapter = AbstractWsAdapter;
package/constants.js CHANGED
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ERROR_EVENT = exports.CLOSE_EVENT = exports.DISCONNECT_EVENT = exports.CONNECTION_EVENT = exports.PARAM_ARGS_METADATA = exports.GATEWAY_OPTIONS = exports.PORT_METADATA = exports.NAMESPACE_METADATA = exports.GATEWAY_METADATA = exports.GATEWAY_SERVER_METADATA = exports.MESSAGE_METADATA = exports.MESSAGE_MAPPING_METADATA = void 0;
4
- const constants_1 = require("@nestjs/common/constants");
5
- exports.MESSAGE_MAPPING_METADATA = 'websockets:message_mapping';
6
- exports.MESSAGE_METADATA = 'message';
7
- exports.GATEWAY_SERVER_METADATA = 'websockets:is_socket';
8
- exports.GATEWAY_METADATA = 'websockets:is_gateway';
9
- exports.NAMESPACE_METADATA = 'namespace';
10
- exports.PORT_METADATA = 'port';
11
- exports.GATEWAY_OPTIONS = 'websockets:gateway_options';
12
- exports.PARAM_ARGS_METADATA = constants_1.ROUTE_ARGS_METADATA;
13
- exports.CONNECTION_EVENT = 'connection';
14
- exports.DISCONNECT_EVENT = 'disconnect';
15
- exports.CLOSE_EVENT = 'close';
16
- exports.ERROR_EVENT = 'error';
1
+ import { ROUTE_ARGS_METADATA } from '@nestjs/common/internal';
2
+ export const MESSAGE_MAPPING_METADATA = 'websockets:message_mapping';
3
+ export const MESSAGE_METADATA = 'message';
4
+ export const GATEWAY_SERVER_METADATA = 'websockets:is_socket';
5
+ export const GATEWAY_METADATA = 'websockets:is_gateway';
6
+ export const NAMESPACE_METADATA = 'namespace';
7
+ export const PORT_METADATA = 'port';
8
+ export const GATEWAY_OPTIONS = 'websockets:gateway_options';
9
+ export const PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
10
+ export const CONNECTION_EVENT = 'connection';
11
+ export const DISCONNECT_EVENT = 'disconnect';
12
+ export const CLOSE_EVENT = 'close';
13
+ export const ERROR_EVENT = 'error';
@@ -1,6 +1,6 @@
1
- import { BaseExceptionFilterContext } from '@nestjs/core/exceptions/base-exception-filter-context';
2
- import { NestContainer } from '@nestjs/core/injector/container';
3
- import { WsExceptionsHandler } from '../exceptions/ws-exceptions-handler';
1
+ import { WsExceptionsHandler } from '../exceptions/ws-exceptions-handler.js';
2
+ import { BaseExceptionFilterContext } from '@nestjs/core/internal';
3
+ import type { NestContainer } from '@nestjs/core';
4
4
  /**
5
5
  * @publicApi
6
6
  */
@@ -1,22 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExceptionFiltersContext = void 0;
4
- const constants_1 = require("@nestjs/common/constants");
5
- const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
- const base_exception_filter_context_1 = require("@nestjs/core/exceptions/base-exception-filter-context");
7
- const ws_exceptions_handler_1 = require("../exceptions/ws-exceptions-handler");
1
+ import { WsExceptionsHandler } from '../exceptions/ws-exceptions-handler.js';
2
+ import { EXCEPTION_FILTERS_METADATA, isEmptyArray, } from '@nestjs/common/internal';
3
+ import { BaseExceptionFilterContext } from '@nestjs/core/internal';
8
4
  /**
9
5
  * @publicApi
10
6
  */
11
- class ExceptionFiltersContext extends base_exception_filter_context_1.BaseExceptionFilterContext {
7
+ export class ExceptionFiltersContext extends BaseExceptionFilterContext {
12
8
  constructor(container) {
13
9
  super(container);
14
10
  }
15
11
  create(instance, callback, moduleKey) {
16
12
  this.moduleContext = moduleKey;
17
- const exceptionHandler = new ws_exceptions_handler_1.WsExceptionsHandler();
18
- const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA);
19
- if ((0, shared_utils_1.isEmpty)(filters)) {
13
+ const exceptionHandler = new WsExceptionsHandler();
14
+ const filters = this.createContext(instance, callback, EXCEPTION_FILTERS_METADATA);
15
+ if (isEmptyArray(filters)) {
20
16
  return exceptionHandler;
21
17
  }
22
18
  exceptionHandler.setCustomFilters(filters.reverse());
@@ -26,4 +22,3 @@ class ExceptionFiltersContext extends base_exception_filter_context_1.BaseExcept
26
22
  return [];
27
23
  }
28
24
  }
29
- exports.ExceptionFiltersContext = ExceptionFiltersContext;
@@ -1,14 +1,9 @@
1
- import { ContextType, Controller, PipeTransform } from '@nestjs/common/interfaces';
2
- import { GuardsConsumer } from '@nestjs/core/guards/guards-consumer';
3
- import { GuardsContextCreator } from '@nestjs/core/guards/guards-context-creator';
4
- import { ParamProperties } from '@nestjs/core/helpers/context-utils';
5
- import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
6
- import { ParamsMetadata } from '@nestjs/core/helpers/interfaces';
7
- import { InterceptorsConsumer, InterceptorsContextCreator } from '@nestjs/core/interceptors';
8
- import { PipesConsumer, PipesContextCreator } from '@nestjs/core/pipes';
9
- import { WsParamsFactory } from '../factories/ws-params-factory';
10
- import { ExceptionFiltersContext } from './exception-filters-context';
11
- import { WsProxy } from './ws-proxy';
1
+ import type { ArgumentMetadata, ContextType, PipeTransform } from '@nestjs/common';
2
+ import { type Controller } from '@nestjs/common/internal';
3
+ import { type ExecutionContextHost, type GuardsConsumer, type GuardsContextCreator, type InterceptorsConsumer, type InterceptorsContextCreator, type ParamProperties, type ParamsMetadata, type PipesConsumer, type PipesContextCreator } from '@nestjs/core/internal';
4
+ import { WsParamsFactory } from '../factories/ws-params-factory.js';
5
+ import { ExceptionFiltersContext } from './exception-filters-context.js';
6
+ import { WsProxy } from './ws-proxy.js';
12
7
  type WsParamProperties = ParamProperties & {
13
8
  metatype?: any;
14
9
  };
@@ -39,10 +34,6 @@ export declare class WsContextCreator {
39
34
  createPipesFn(pipes: PipeTransform[], paramsOptions: (ParamProperties & {
40
35
  metatype?: unknown;
41
36
  })[]): ((args: unknown[], ...params: unknown[]) => Promise<void>) | null;
42
- getParamValue<T>(value: T, { metatype, type, data }: {
43
- metatype: any;
44
- type: any;
45
- data: any;
46
- }, pipes: PipeTransform[]): Promise<any>;
37
+ getParamValue<T>(value: T, metadata: ArgumentMetadata, pipes: PipeTransform[]): Promise<any>;
47
38
  }
48
39
  export {};
@@ -1,16 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WsContextCreator = void 0;
4
- const constants_1 = require("@nestjs/common/constants");
5
- const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
6
- const constants_2 = require("@nestjs/core/guards/constants");
7
- const context_utils_1 = require("@nestjs/core/helpers/context-utils");
8
- const handler_metadata_storage_1 = require("@nestjs/core/helpers/handler-metadata-storage");
9
- const constants_3 = require("../constants");
10
- const ws_exception_1 = require("../errors/ws-exception");
11
- const ws_params_factory_1 = require("../factories/ws-params-factory");
12
- const ws_metadata_constants_1 = require("./ws-metadata-constants");
13
- class WsContextCreator {
1
+ import { CUSTOM_ROUTE_ARGS_METADATA, isEmptyArray, PARAMTYPES_METADATA, } from '@nestjs/common/internal';
2
+ import { ContextUtils, FORBIDDEN_MESSAGE, HandlerMetadataStorage, } from '@nestjs/core/internal';
3
+ import { MESSAGE_METADATA, PARAM_ARGS_METADATA } from '../constants.js';
4
+ import { WsException } from '../errors/ws-exception.js';
5
+ import { WsParamsFactory } from '../factories/ws-params-factory.js';
6
+ import { DEFAULT_CALLBACK_METADATA } from './ws-metadata-constants.js';
7
+ export class WsContextCreator {
8
+ wsProxy;
9
+ exceptionFiltersContext;
10
+ pipesContextCreator;
11
+ pipesConsumer;
12
+ guardsContextCreator;
13
+ guardsConsumer;
14
+ interceptorsContextCreator;
15
+ interceptorsConsumer;
16
+ contextUtils = new ContextUtils();
17
+ wsParamsFactory = new WsParamsFactory();
18
+ handlerMetadataStorage = new HandlerMetadataStorage();
14
19
  constructor(wsProxy, exceptionFiltersContext, pipesContextCreator, pipesConsumer, guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer) {
15
20
  this.wsProxy = wsProxy;
16
21
  this.exceptionFiltersContext = exceptionFiltersContext;
@@ -20,9 +25,6 @@ class WsContextCreator {
20
25
  this.guardsConsumer = guardsConsumer;
21
26
  this.interceptorsContextCreator = interceptorsContextCreator;
22
27
  this.interceptorsConsumer = interceptorsConsumer;
23
- this.contextUtils = new context_utils_1.ContextUtils();
24
- this.wsParamsFactory = new ws_params_factory_1.WsParamsFactory();
25
- this.handlerMetadataStorage = new handler_metadata_storage_1.HandlerMetadataStorage();
26
28
  }
27
29
  create(instance, callback, moduleKey, methodName) {
28
30
  const contextType = 'ws';
@@ -53,16 +55,16 @@ class WsContextCreator {
53
55
  }, exceptionHandler, targetPattern);
54
56
  }
55
57
  reflectCallbackParamtypes(instance, callback) {
56
- return Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, instance, callback.name);
58
+ return Reflect.getMetadata(PARAMTYPES_METADATA, instance, callback.name);
57
59
  }
58
60
  reflectCallbackPattern(callback) {
59
- return Reflect.getMetadata(constants_3.MESSAGE_METADATA, callback);
61
+ return Reflect.getMetadata(MESSAGE_METADATA, callback);
60
62
  }
61
63
  createGuardsFn(guards, instance, callback, contextType) {
62
64
  const canActivateFn = async (args) => {
63
65
  const canActivate = await this.guardsConsumer.tryActivate(guards, args, instance, callback, contextType);
64
66
  if (!canActivate) {
65
- throw new ws_exception_1.WsException(constants_2.FORBIDDEN_MESSAGE);
67
+ throw new WsException(FORBIDDEN_MESSAGE);
66
68
  }
67
69
  };
68
70
  return guards.length ? canActivateFn : null;
@@ -72,7 +74,7 @@ class WsContextCreator {
72
74
  if (cacheMetadata) {
73
75
  return cacheMetadata;
74
76
  }
75
- const metadata = this.contextUtils.reflectCallbackMetadata(instance, methodName, constants_3.PARAM_ARGS_METADATA) || ws_metadata_constants_1.DEFAULT_CALLBACK_METADATA;
77
+ const metadata = this.contextUtils.reflectCallbackMetadata(instance, methodName, PARAM_ARGS_METADATA) || DEFAULT_CALLBACK_METADATA;
76
78
  const keys = Object.keys(metadata);
77
79
  const argsLength = this.contextUtils.getArgumentsLength(keys, metadata);
78
80
  const paramtypes = this.contextUtils.reflectCallbackParamtypes(instance, methodName);
@@ -89,34 +91,40 @@ class WsContextCreator {
89
91
  exchangeKeysForValues(keys, metadata, moduleContext, paramsFactory, contextFactory) {
90
92
  this.pipesContextCreator.setModuleContext(moduleContext);
91
93
  return keys.map(key => {
92
- const { index, data, pipes: pipesCollection } = metadata[key];
94
+ const { index, data, pipes: pipesCollection, schema } = metadata[key];
93
95
  const pipes = this.pipesContextCreator.createConcreteContext(pipesCollection);
94
96
  const type = this.contextUtils.mapParamType(key);
95
- if (key.includes(constants_1.CUSTOM_ROUTE_ARGS_METADATA)) {
97
+ if (key.includes(CUSTOM_ROUTE_ARGS_METADATA)) {
96
98
  const { factory } = metadata[key];
97
99
  const customExtractValue = this.contextUtils.getCustomFactory(factory, data, contextFactory);
98
- return { index, extractValue: customExtractValue, type, data, pipes };
100
+ return {
101
+ index,
102
+ extractValue: customExtractValue,
103
+ type,
104
+ data,
105
+ pipes,
106
+ schema,
107
+ };
99
108
  }
100
109
  const numericType = Number(type);
101
110
  const extractValue = (...args) => paramsFactory.exchangeKeyForValue(numericType, data, args);
102
- return { index, extractValue, type: numericType, data, pipes };
111
+ return { index, extractValue, type: numericType, data, pipes, schema };
103
112
  });
104
113
  }
105
114
  createPipesFn(pipes, paramsOptions) {
106
115
  const pipesFn = async (args, ...params) => {
107
116
  const resolveParamValue = async (param) => {
108
- const { index, extractValue, type, data, metatype, pipes: paramPipes, } = param;
117
+ const { index, extractValue, type, data, metatype, pipes: paramPipes, schema, } = param;
109
118
  const value = extractValue(...params);
110
- args[index] = await this.getParamValue(value, { metatype, type, data }, pipes.concat(paramPipes));
119
+ args[index] = await this.getParamValue(value, { metatype, type, data, schema }, pipes.concat(paramPipes));
111
120
  };
112
121
  await Promise.all(paramsOptions.map(resolveParamValue));
113
122
  };
114
123
  return paramsOptions.length ? pipesFn : null;
115
124
  }
116
- async getParamValue(value, { metatype, type, data }, pipes) {
117
- return (0, shared_utils_1.isEmpty)(pipes)
125
+ async getParamValue(value, metadata, pipes) {
126
+ return isEmptyArray(pipes)
118
127
  ? value
119
- : this.pipesConsumer.apply(value, { metatype, type, data }, pipes);
128
+ : this.pipesConsumer.apply(value, metadata, pipes);
120
129
  }
121
130
  }
122
- exports.WsContextCreator = WsContextCreator;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CALLBACK_METADATA = void 0;
4
- const ws_paramtype_enum_1 = require("../enums/ws-paramtype.enum");
5
- exports.DEFAULT_CALLBACK_METADATA = {
6
- [`${ws_paramtype_enum_1.WsParamtype.ACK}:2`]: { index: 2, data: undefined, pipes: [] },
7
- [`${ws_paramtype_enum_1.WsParamtype.PAYLOAD}:1`]: { index: 1, data: undefined, pipes: [] },
8
- [`${ws_paramtype_enum_1.WsParamtype.SOCKET}:0`]: { index: 0, data: undefined, pipes: [] },
1
+ import { WsParamtype } from '../enums/ws-paramtype.enum.js';
2
+ export const DEFAULT_CALLBACK_METADATA = {
3
+ [`${WsParamtype.ACK}:2`]: { index: 2, data: undefined, pipes: [] },
4
+ [`${WsParamtype.PAYLOAD}:1`]: { index: 1, data: undefined, pipes: [] },
5
+ [`${WsParamtype.SOCKET}:0`]: { index: 0, data: undefined, pipes: [] },
9
6
  };
@@ -1,4 +1,4 @@
1
- import { WsExceptionsHandler } from '../exceptions/ws-exceptions-handler';
1
+ import { WsExceptionsHandler } from '../exceptions/ws-exceptions-handler.js';
2
2
  export declare class WsProxy {
3
3
  create(targetCallback: (...args: unknown[]) => Promise<any>, exceptionsHandler: WsExceptionsHandler, targetPattern?: string): (...args: unknown[]) => Promise<any>;
4
4
  handleError<T>(exceptionsHandler: WsExceptionsHandler, args: unknown[], error: T): void;
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WsProxy = void 0;
4
- const execution_context_host_1 = require("@nestjs/core/helpers/execution-context-host");
5
- const rxjs_1 = require("rxjs");
6
- const operators_1 = require("rxjs/operators");
7
- class WsProxy {
1
+ import { EMPTY, isObservable } from 'rxjs';
2
+ import { catchError } from 'rxjs/operators';
3
+ import { ExecutionContextHost } from '@nestjs/core/internal';
4
+ export class WsProxy {
8
5
  create(targetCallback, exceptionsHandler, targetPattern) {
9
6
  return async (...args) => {
10
7
  args = [...args, targetPattern ?? 'unknown'];
11
8
  try {
12
9
  const result = await targetCallback(...args);
13
- return !(0, rxjs_1.isObservable)(result)
10
+ return !isObservable(result)
14
11
  ? result
15
- : result.pipe((0, operators_1.catchError)(error => {
12
+ : result.pipe(catchError(error => {
16
13
  this.handleError(exceptionsHandler, args, error);
17
- return rxjs_1.EMPTY;
14
+ return EMPTY;
18
15
  }));
19
16
  }
20
17
  catch (error) {
@@ -23,9 +20,8 @@ class WsProxy {
23
20
  };
24
21
  }
25
22
  handleError(exceptionsHandler, args, error) {
26
- const host = new execution_context_host_1.ExecutionContextHost(args);
23
+ const host = new ExecutionContextHost(args);
27
24
  host.setType('ws');
28
25
  exceptionsHandler.handle(error, host);
29
26
  }
30
27
  }
31
- exports.WsProxy = WsProxy;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Ack = Ack;
4
- const ws_paramtype_enum_1 = require("../enums/ws-paramtype.enum");
5
- const param_utils_1 = require("../utils/param.utils");
1
+ import { WsParamtype } from '../enums/ws-paramtype.enum.js';
2
+ import { createPipesWsParamDecorator } from '../utils/param.utils.js';
6
3
  /**
7
4
  * WebSockets `ack` parameter decorator.
8
5
  * Extracts the `ack` callback function from the arguments of a ws event.
@@ -25,6 +22,6 @@ const param_utils_1 = require("../utils/param.utils");
25
22
  *
26
23
  * @publicApi
27
24
  */
28
- function Ack() {
29
- return (0, param_utils_1.createPipesWsParamDecorator)(ws_paramtype_enum_1.WsParamtype.ACK)();
25
+ export function Ack() {
26
+ return createPipesWsParamDecorator(WsParamtype.ACK)();
30
27
  }
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectedSocket = void 0;
4
- const ws_paramtype_enum_1 = require("../enums/ws-paramtype.enum");
5
- const param_utils_1 = require("../utils/param.utils");
1
+ import { WsParamtype } from '../enums/ws-paramtype.enum.js';
2
+ import { createWsParamDecorator } from '../utils/param.utils.js';
6
3
  /**
7
4
  * @publicApi
8
5
  */
9
- exports.ConnectedSocket = (0, param_utils_1.createWsParamDecorator)(ws_paramtype_enum_1.WsParamtype.SOCKET);
6
+ export const ConnectedSocket = createWsParamDecorator(WsParamtype.SOCKET);
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketServer = void 0;
4
- const constants_1 = require("../constants");
1
+ import { GATEWAY_SERVER_METADATA } from '../constants.js';
5
2
  /**
6
3
  * Attaches native Web Socket Server to a given property.
7
4
  *
8
5
  * @publicApi
9
6
  */
10
- const WebSocketServer = () => {
7
+ export const WebSocketServer = () => {
11
8
  return (target, propertyKey) => {
12
9
  Reflect.set(target, propertyKey, null);
13
- Reflect.defineMetadata(constants_1.GATEWAY_SERVER_METADATA, true, target, propertyKey);
10
+ Reflect.defineMetadata(GATEWAY_SERVER_METADATA, true, target, propertyKey);
14
11
  };
15
12
  };
16
- exports.WebSocketServer = WebSocketServer;
@@ -1,6 +1,6 @@
1
- export * from './connected-socket.decorator';
2
- export * from './gateway-server.decorator';
3
- export * from './message-body.decorator';
4
- export * from './socket-gateway.decorator';
5
- export * from './subscribe-message.decorator';
6
- export * from './ack.decorator';
1
+ export * from './connected-socket.decorator.js';
2
+ export * from './gateway-server.decorator.js';
3
+ export * from './message-body.decorator.js';
4
+ export * from './socket-gateway.decorator.js';
5
+ export * from './subscribe-message.decorator.js';
6
+ export * from './ack.decorator.js';
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./connected-socket.decorator"), exports);
5
- tslib_1.__exportStar(require("./gateway-server.decorator"), exports);
6
- tslib_1.__exportStar(require("./message-body.decorator"), exports);
7
- tslib_1.__exportStar(require("./socket-gateway.decorator"), exports);
8
- tslib_1.__exportStar(require("./subscribe-message.decorator"), exports);
9
- tslib_1.__exportStar(require("./ack.decorator"), exports);
1
+ export * from './connected-socket.decorator.js';
2
+ export * from './gateway-server.decorator.js';
3
+ export * from './message-body.decorator.js';
4
+ export * from './socket-gateway.decorator.js';
5
+ export * from './subscribe-message.decorator.js';
6
+ export * from './ack.decorator.js';
@@ -1,4 +1,4 @@
1
- import { PipeTransform, Type } from '@nestjs/common';
1
+ import type { ParameterDecoratorOptions, PipeTransform, Type } from '@nestjs/common';
2
2
  /**
3
3
  * WebSockets message body parameter decorator.
4
4
  *
@@ -43,3 +43,29 @@ export declare function MessageBody(...pipes: (Type<PipeTransform> | PipeTransfo
43
43
  * @publicApi
44
44
  */
45
45
  export declare function MessageBody(propertyKey: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): ParameterDecorator;
46
+ /**
47
+ * WebSockets message body parameter decorator. Extracts a property from the
48
+ * message payload object with additional options.
49
+ *
50
+ * For example, extracting a single param with schema:
51
+ * ```typescript
52
+ * create(@MessageBody('data', { schema: z.string() }) data: string)
53
+ * ```
54
+ * @param propertyKey name of single property to extract from the message payload
55
+ * @param options options object containing additional configuration for the decorator, such as pipes and schema
56
+ *
57
+ * @publicApi
58
+ */
59
+ export declare function MessageBody(propertyKey: string, options: ParameterDecoratorOptions): ParameterDecorator;
60
+ /**
61
+ * WebSockets message body parameter decorator.
62
+ *
63
+ * For example, passing schema as options:
64
+ * ```typescript
65
+ * create(@MessageBody({ schema: z.object({ data: z.string() }) }) body)
66
+ * ```
67
+ * @param options options object containing additional configuration for the decorator, such as pipes and schema
68
+ *
69
+ * @publicApi
70
+ */
71
+ export declare function MessageBody(options: ParameterDecoratorOptions): ParameterDecorator;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageBody = MessageBody;
4
- const ws_paramtype_enum_1 = require("../enums/ws-paramtype.enum");
5
- const param_utils_1 = require("../utils/param.utils");
6
- function MessageBody(propertyOrPipe, ...pipes) {
7
- return (0, param_utils_1.createPipesWsParamDecorator)(ws_paramtype_enum_1.WsParamtype.PAYLOAD)(propertyOrPipe, ...pipes);
1
+ import { WsParamtype } from '../enums/ws-paramtype.enum.js';
2
+ import { createPipesWsParamDecorator } from '../utils/param.utils.js';
3
+ export function MessageBody(propertyOrPipe, optionsOrPipe, ...pipes) {
4
+ return createPipesWsParamDecorator(WsParamtype.PAYLOAD)(propertyOrPipe, optionsOrPipe, ...pipes);
8
5
  }
@@ -1,4 +1,4 @@
1
- import { GatewayMetadata } from '../interfaces';
1
+ import { GatewayMetadata } from '../interfaces/index.js';
2
2
  /**
3
3
  * Decorator that marks a class as a Nest gateway that enables real-time, bidirectional
4
4
  * and event-based communication between the browser and the server.
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketGateway = WebSocketGateway;
4
- const constants_1 = require("../constants");
5
- function WebSocketGateway(portOrOptions, options) {
1
+ import { GATEWAY_METADATA, GATEWAY_OPTIONS, PORT_METADATA, } from '../constants.js';
2
+ export function WebSocketGateway(portOrOptions, options) {
6
3
  const isPortInt = Number.isInteger(portOrOptions);
7
4
  // eslint-disable-next-line prefer-const
8
5
  let [port, opt] = isPortInt ? [portOrOptions, options] : [0, portOrOptions];
9
6
  opt = opt || {};
10
7
  return (target) => {
11
- Reflect.defineMetadata(constants_1.GATEWAY_METADATA, true, target);
12
- Reflect.defineMetadata(constants_1.PORT_METADATA, port, target);
13
- Reflect.defineMetadata(constants_1.GATEWAY_OPTIONS, opt, target);
8
+ Reflect.defineMetadata(GATEWAY_METADATA, true, target);
9
+ Reflect.defineMetadata(PORT_METADATA, port, target);
10
+ Reflect.defineMetadata(GATEWAY_OPTIONS, opt, target);
14
11
  };
15
12
  }
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SubscribeMessage = void 0;
4
- const constants_1 = require("../constants");
1
+ import { MESSAGE_MAPPING_METADATA, MESSAGE_METADATA } from '../constants.js';
5
2
  /**
6
3
  * Subscribes to messages that fulfils chosen pattern.
7
4
  *
8
5
  * @publicApi
9
6
  */
10
- const SubscribeMessage = (message) => {
7
+ export const SubscribeMessage = (message) => {
11
8
  return (target, key, descriptor) => {
12
- Reflect.defineMetadata(constants_1.MESSAGE_MAPPING_METADATA, true, descriptor.value);
13
- Reflect.defineMetadata(constants_1.MESSAGE_METADATA, message, descriptor.value);
9
+ Reflect.defineMetadata(MESSAGE_MAPPING_METADATA, true, descriptor.value);
10
+ Reflect.defineMetadata(MESSAGE_METADATA, message, descriptor.value);
14
11
  return descriptor;
15
12
  };
16
13
  };
17
- exports.SubscribeMessage = SubscribeMessage;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WsParamtype = void 0;
4
- var WsParamtype;
1
+ export var WsParamtype;
5
2
  (function (WsParamtype) {
6
3
  WsParamtype[WsParamtype["SOCKET"] = 0] = "SOCKET";
7
4
  WsParamtype[WsParamtype["PAYLOAD"] = 3] = "PAYLOAD";
8
5
  WsParamtype[WsParamtype["ACK"] = 13] = "ACK";
9
- })(WsParamtype || (exports.WsParamtype = WsParamtype = {}));
6
+ })(WsParamtype || (WsParamtype = {}));
package/errors/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './ws-exception';
1
+ export * from './ws-exception.js';
package/errors/index.js CHANGED
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./ws-exception"), exports);
1
+ export * from './ws-exception.js';
@@ -1,4 +1,4 @@
1
- import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception';
1
+ import { RuntimeException } from '@nestjs/core/internal';
2
2
  export declare class InvalidSocketPortException extends RuntimeException {
3
3
  constructor(port: number | string, type: any);
4
4
  }
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidSocketPortException = void 0;
4
- const runtime_exception_1 = require("@nestjs/core/errors/exceptions/runtime.exception");
5
- class InvalidSocketPortException extends runtime_exception_1.RuntimeException {
1
+ import { RuntimeException } from '@nestjs/core/internal';
2
+ export class InvalidSocketPortException extends RuntimeException {
6
3
  constructor(port, type) {
7
4
  super(`Invalid port (${port}) in gateway ${type}`);
8
5
  }
9
6
  }
10
- exports.InvalidSocketPortException = InvalidSocketPortException;