@nestjs/websockets 10.4.11 → 11.0.0-next.2
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/adapters/ws-adapter.d.ts +1 -1
- package/adapters/ws-adapter.js +0 -1
- package/context/ws-context-creator.d.ts +1 -1
- package/context/ws-metadata-constants.d.ts +4 -4
- package/exceptions/base-ws-exception-filter.d.ts +39 -4
- package/exceptions/base-ws-exception-filter.js +35 -16
- package/exceptions/ws-exceptions-handler.d.ts +1 -1
- package/exceptions/ws-exceptions-handler.js +1 -1
- package/gateway-metadata-explorer.d.ts +2 -2
- package/interfaces/gateway-metadata.interface.d.ts +1 -1
- package/package.json +3 -3
- package/utils/param.utils.js +2 -1
package/adapters/ws-adapter.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare abstract class AbstractWsAdapter<TServer extends BaseWsInstance =
|
|
|
10
10
|
private _forceCloseConnections;
|
|
11
11
|
set forceCloseConnections(value: boolean);
|
|
12
12
|
get forceCloseConnections(): boolean;
|
|
13
|
-
constructor(appOrHttpServer?: INestApplicationContext |
|
|
13
|
+
constructor(appOrHttpServer?: INestApplicationContext | object);
|
|
14
14
|
bindClientConnect(server: TServer, callback: Function): void;
|
|
15
15
|
bindClientDisconnect(client: TClient, callback: Function): void;
|
|
16
16
|
close(server: TServer): Promise<void>;
|
package/adapters/ws-adapter.js
CHANGED
|
@@ -29,7 +29,6 @@ class AbstractWsAdapter {
|
|
|
29
29
|
const isCallable = server && (0, shared_utils_1.isFunction)(server.close);
|
|
30
30
|
isCallable && (await new Promise(resolve => server.close(resolve)));
|
|
31
31
|
}
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
33
32
|
async dispose() { }
|
|
34
33
|
}
|
|
35
34
|
exports.AbstractWsAdapter = AbstractWsAdapter;
|
|
@@ -38,7 +38,7 @@ export declare class WsContextCreator {
|
|
|
38
38
|
exchangeKeysForValues<TMetadata = any>(keys: string[], metadata: TMetadata, moduleContext: string, paramsFactory: WsParamsFactory, contextFactory: (args: unknown[]) => ExecutionContextHost): ParamProperties[];
|
|
39
39
|
createPipesFn(pipes: PipeTransform[], paramsOptions: (ParamProperties & {
|
|
40
40
|
metatype?: unknown;
|
|
41
|
-
})[]): (args: unknown[], ...params: unknown[]) => Promise<void
|
|
41
|
+
})[]): ((args: unknown[], ...params: unknown[]) => Promise<void>) | null;
|
|
42
42
|
getParamValue<T>(value: T, { metatype, type, data }: {
|
|
43
43
|
metatype: any;
|
|
44
44
|
type: any;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare const DEFAULT_CALLBACK_METADATA: {
|
|
2
2
|
"3:1": {
|
|
3
3
|
index: number;
|
|
4
|
-
data:
|
|
5
|
-
pipes:
|
|
4
|
+
data: undefined;
|
|
5
|
+
pipes: never[];
|
|
6
6
|
};
|
|
7
7
|
"0:0": {
|
|
8
8
|
index: number;
|
|
9
|
-
data:
|
|
10
|
-
pipes:
|
|
9
|
+
data: undefined;
|
|
10
|
+
pipes: never[];
|
|
11
11
|
};
|
|
12
12
|
};
|
|
@@ -1,15 +1,50 @@
|
|
|
1
|
-
import { ArgumentsHost, WsExceptionFilter } from '@nestjs/common';
|
|
1
|
+
import { ArgumentsHost, Logger, WsExceptionFilter } from '@nestjs/common';
|
|
2
|
+
export interface ErrorPayload<Cause = {
|
|
3
|
+
pattern: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
}> {
|
|
6
|
+
/**
|
|
7
|
+
* Error message identifier.
|
|
8
|
+
*/
|
|
9
|
+
status: 'error';
|
|
10
|
+
/**
|
|
11
|
+
* Error message.
|
|
12
|
+
*/
|
|
13
|
+
message: string;
|
|
14
|
+
/**
|
|
15
|
+
* Message that caused the exception.
|
|
16
|
+
*/
|
|
17
|
+
cause?: Cause;
|
|
18
|
+
}
|
|
19
|
+
interface BaseWsExceptionFilterOptions {
|
|
20
|
+
/**
|
|
21
|
+
* When true, the data that caused the exception will be included in the response.
|
|
22
|
+
* This is useful when you want to provide additional context to the client, or
|
|
23
|
+
* when you need to associate the error with a specific request.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
includeCause?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* A factory function that can be used to control the shape of the "cause" object.
|
|
29
|
+
* This is useful when you need a custom structure for the cause object.
|
|
30
|
+
* @default (pattern, data) => ({ pattern, data })
|
|
31
|
+
*/
|
|
32
|
+
causeFactory?: (pattern: string, data: unknown) => Record<string, any>;
|
|
33
|
+
}
|
|
2
34
|
/**
|
|
3
35
|
* @publicApi
|
|
4
36
|
*/
|
|
5
37
|
export declare class BaseWsExceptionFilter<TError = any> implements WsExceptionFilter<TError> {
|
|
6
|
-
|
|
38
|
+
protected readonly options: BaseWsExceptionFilterOptions;
|
|
39
|
+
protected static readonly logger: Logger;
|
|
40
|
+
constructor(options?: BaseWsExceptionFilterOptions);
|
|
7
41
|
catch(exception: TError, host: ArgumentsHost): void;
|
|
8
42
|
handleError<TClient extends {
|
|
9
43
|
emit: Function;
|
|
10
|
-
}>(client: TClient, exception: TError):
|
|
44
|
+
}>(client: TClient, exception: TError, cause: ErrorPayload['cause']): any;
|
|
11
45
|
handleUnknownError<TClient extends {
|
|
12
46
|
emit: Function;
|
|
13
|
-
}>(exception: TError, client: TClient): void;
|
|
47
|
+
}>(exception: TError, client: TClient, data: ErrorPayload['cause']): void;
|
|
14
48
|
isExceptionObject(err: any): err is Error;
|
|
15
49
|
}
|
|
50
|
+
export {};
|
|
@@ -9,34 +9,53 @@ const ws_exception_1 = require("../errors/ws-exception");
|
|
|
9
9
|
* @publicApi
|
|
10
10
|
*/
|
|
11
11
|
class BaseWsExceptionFilter {
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.options.includeCause = this.options.includeCause ?? true;
|
|
15
|
+
this.options.causeFactory =
|
|
16
|
+
this.options.causeFactory ?? ((pattern, data) => ({ pattern, data }));
|
|
17
|
+
}
|
|
12
18
|
catch(exception, host) {
|
|
13
19
|
const client = host.switchToWs().getClient();
|
|
14
|
-
|
|
20
|
+
const pattern = host.switchToWs().getPattern();
|
|
21
|
+
const data = host.switchToWs().getData();
|
|
22
|
+
this.handleError(client, exception, {
|
|
23
|
+
pattern,
|
|
24
|
+
data,
|
|
25
|
+
});
|
|
15
26
|
}
|
|
16
|
-
handleError(client, exception) {
|
|
27
|
+
handleError(client, exception, cause) {
|
|
17
28
|
if (!(exception instanceof ws_exception_1.WsException)) {
|
|
18
|
-
return this.handleUnknownError(exception, client);
|
|
29
|
+
return this.handleUnknownError(exception, client, cause);
|
|
19
30
|
}
|
|
20
31
|
const status = 'error';
|
|
21
32
|
const result = exception.getError();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if ((0, shared_utils_1.isObject)(result)) {
|
|
34
|
+
return client.emit('exception', result);
|
|
35
|
+
}
|
|
36
|
+
const payload = {
|
|
37
|
+
status,
|
|
38
|
+
message: result,
|
|
39
|
+
};
|
|
40
|
+
if (this.options?.includeCause && cause) {
|
|
41
|
+
payload.cause = this.options.causeFactory(cause.pattern, cause.data);
|
|
42
|
+
}
|
|
43
|
+
client.emit('exception', payload);
|
|
29
44
|
}
|
|
30
|
-
handleUnknownError(exception, client) {
|
|
45
|
+
handleUnknownError(exception, client, data) {
|
|
31
46
|
const status = 'error';
|
|
32
|
-
|
|
47
|
+
const payload = {
|
|
33
48
|
status,
|
|
34
49
|
message: constants_1.MESSAGES.UNKNOWN_EXCEPTION_MESSAGE,
|
|
35
|
-
}
|
|
36
|
-
if (this.
|
|
37
|
-
|
|
50
|
+
};
|
|
51
|
+
if (this.options?.includeCause && data) {
|
|
52
|
+
payload.cause = this.options.causeFactory(data.pattern, data.data);
|
|
53
|
+
}
|
|
54
|
+
client.emit('exception', payload);
|
|
55
|
+
if (!(exception instanceof common_1.IntrinsicException)) {
|
|
56
|
+
const logger = BaseWsExceptionFilter.logger;
|
|
57
|
+
logger.error(exception);
|
|
38
58
|
}
|
|
39
|
-
return BaseWsExceptionFilter.logger.error(exception);
|
|
40
59
|
}
|
|
41
60
|
isExceptionObject(err) {
|
|
42
61
|
return (0, shared_utils_1.isObject)(err) && !!err.message;
|
|
@@ -7,7 +7,7 @@ import { BaseWsExceptionFilter } from './base-ws-exception-filter';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class WsExceptionsHandler extends BaseWsExceptionFilter {
|
|
9
9
|
private filters;
|
|
10
|
-
handle(exception: Error | WsException
|
|
10
|
+
handle(exception: Error | WsException, host: ArgumentsHost): void;
|
|
11
11
|
setCustomFilters(filters: ExceptionFilterMetadata[]): void;
|
|
12
12
|
invokeCustomFilters<T = any>(exception: T, args: ArgumentsHost): boolean;
|
|
13
13
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WsExceptionsHandler = void 0;
|
|
4
|
-
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
4
|
const select_exception_filter_metadata_util_1 = require("@nestjs/common/utils/select-exception-filter-metadata.util");
|
|
5
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
6
6
|
const invalid_exception_filter_exception_1 = require("@nestjs/core/errors/exceptions/invalid-exception-filter.exception");
|
|
7
7
|
const base_ws_exception_filter_1 = require("./base-ws-exception-filter");
|
|
8
8
|
/**
|
|
@@ -4,12 +4,12 @@ import { NestGateway } from './interfaces/nest-gateway.interface';
|
|
|
4
4
|
export interface MessageMappingProperties {
|
|
5
5
|
message: any;
|
|
6
6
|
methodName: string;
|
|
7
|
-
callback: (...args: any[]) => Observable<any> | Promise<any
|
|
7
|
+
callback: (...args: any[]) => Observable<any> | Promise<any>;
|
|
8
8
|
}
|
|
9
9
|
export declare class GatewayMetadataExplorer {
|
|
10
10
|
private readonly metadataScanner;
|
|
11
11
|
constructor(metadataScanner: MetadataScanner);
|
|
12
12
|
explore(instance: NestGateway): MessageMappingProperties[];
|
|
13
|
-
exploreMethodMetadata(instancePrototype: object, methodName: string): MessageMappingProperties;
|
|
13
|
+
exploreMethodMetadata(instancePrototype: object, methodName: string): MessageMappingProperties | null;
|
|
14
14
|
scanForServerHooks(instance: NestGateway): IterableIterator<string>;
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/websockets",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0-next.2",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"tslib": "2.7.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@nestjs/common": "
|
|
22
|
-
"@nestjs/core": "
|
|
21
|
+
"@nestjs/common": "^11.0.0-next.2",
|
|
22
|
+
"@nestjs/core": "^11.0.0-next.2"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@nestjs/common": "^10.0.0",
|
package/utils/param.utils.js
CHANGED
|
@@ -8,7 +8,8 @@ require("reflect-metadata");
|
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
9
|
function createWsParamDecorator(paramtype) {
|
|
10
10
|
return (...pipes) => (target, key, index) => {
|
|
11
|
-
const args = Reflect.getMetadata(constants_1.PARAM_ARGS_METADATA, target.constructor, key) ||
|
|
11
|
+
const args = Reflect.getMetadata(constants_1.PARAM_ARGS_METADATA, target.constructor, key) ||
|
|
12
|
+
{};
|
|
12
13
|
Reflect.defineMetadata(constants_1.PARAM_ARGS_METADATA, (0, route_params_decorator_1.assignMetadata)(args, paramtype, index, undefined, ...pipes), target.constructor, key);
|
|
13
14
|
};
|
|
14
15
|
}
|