@nestjs/common 10.2.7 → 10.2.8

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.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
3
  import { StreamableFileOptions, StreamableHandlerResponse } from './interfaces';
4
+ import { Logger } from '../services';
4
5
  /**
5
6
  * @see [Streaming files](https://docs.nestjs.com/techniques/streaming-files)
6
7
  *
@@ -9,7 +10,9 @@ import { StreamableFileOptions, StreamableHandlerResponse } from './interfaces';
9
10
  export declare class StreamableFile {
10
11
  readonly options: StreamableFileOptions;
11
12
  private readonly stream;
13
+ protected logger: Logger;
12
14
  protected handleError: (err: Error, response: StreamableHandlerResponse) => void;
15
+ protected logError: (err: Error) => void;
13
16
  constructor(buffer: Uint8Array, options?: StreamableFileOptions);
14
17
  constructor(readable: Readable, options?: StreamableFileOptions);
15
18
  getStream(): Readable;
@@ -20,4 +23,6 @@ export declare class StreamableFile {
20
23
  };
21
24
  get errorHandler(): (err: Error, response: StreamableHandlerResponse) => void;
22
25
  setErrorHandler(handler: (err: Error, response: StreamableHandlerResponse) => void): this;
26
+ get errorLogger(): (err: Error) => void;
27
+ setErrorLogger(handler: (err: Error) => void): this;
23
28
  }
@@ -5,6 +5,7 @@ const stream_1 = require("stream");
5
5
  const util_1 = require("util");
6
6
  const enums_1 = require("../enums");
7
7
  const shared_utils_1 = require("../utils/shared.utils");
8
+ const services_1 = require("../services");
8
9
  /**
9
10
  * @see [Streaming files](https://docs.nestjs.com/techniques/streaming-files)
10
11
  *
@@ -13,6 +14,7 @@ const shared_utils_1 = require("../utils/shared.utils");
13
14
  class StreamableFile {
14
15
  constructor(bufferOrReadStream, options = {}) {
15
16
  this.options = options;
17
+ this.logger = new services_1.Logger('StreamableFile');
16
18
  this.handleError = (err, res) => {
17
19
  if (res.destroyed) {
18
20
  return;
@@ -24,6 +26,9 @@ class StreamableFile {
24
26
  res.statusCode = enums_1.HttpStatus.BAD_REQUEST;
25
27
  res.send(err.message);
26
28
  };
29
+ this.logError = (err) => {
30
+ this.logger.error(err.message, err.stack);
31
+ };
27
32
  if (util_1.types.isUint8Array(bufferOrReadStream)) {
28
33
  this.stream = new stream_1.Readable();
29
34
  this.stream.push(bufferOrReadStream);
@@ -52,5 +57,12 @@ class StreamableFile {
52
57
  this.handleError = handler;
53
58
  return this;
54
59
  }
60
+ get errorLogger() {
61
+ return this.logError;
62
+ }
63
+ setErrorLogger(handler) {
64
+ this.logError = handler;
65
+ return this;
66
+ }
55
67
  }
56
68
  exports.StreamableFile = StreamableFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "10.2.7",
3
+ "version": "10.2.8",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -106,7 +106,7 @@ let ValidationPipe = class ValidationPipe {
106
106
  if (type === 'custom' && !this.validateCustomDecorators) {
107
107
  return false;
108
108
  }
109
- const types = [String, Boolean, Number, Array, Object, Buffer];
109
+ const types = [String, Boolean, Number, Array, Object, Buffer, Date];
110
110
  return !types.some(t => metatype === t) && !(0, shared_utils_1.isNil)(metatype);
111
111
  }
112
112
  transformPrimitive(value, metadata) {
@@ -145,12 +145,19 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
145
145
  return `${pidMessage}${this.getTimestamp()} ${formattedLogLevel} ${contextMessage}${output}${timestampDiff}\n`;
146
146
  }
147
147
  stringifyMessage(message, logLevel) {
148
- // If the message is a function, call it and re-resolve its value.
149
- return (0, shared_utils_1.isFunction)(message)
150
- ? this.stringifyMessage(message(), logLevel)
151
- : (0, shared_utils_1.isPlainObject)(message) || Array.isArray(message)
152
- ? `${this.colorize('Object:', logLevel)}\n${JSON.stringify(message, (key, value) => typeof value === 'bigint' ? value.toString() : value, 2)}\n`
153
- : this.colorize(message, logLevel);
148
+ if ((0, shared_utils_1.isFunction)(message)) {
149
+ const messageAsStr = Function.prototype.toString.call(message);
150
+ const isClass = messageAsStr.startsWith('class ');
151
+ if (isClass) {
152
+ // If the message is a class, we will display the class name.
153
+ return this.stringifyMessage(message.name, logLevel);
154
+ }
155
+ // If the message is a non-class function, call it and re-resolve its value.
156
+ return this.stringifyMessage(message(), logLevel);
157
+ }
158
+ return (0, shared_utils_1.isPlainObject)(message) || Array.isArray(message)
159
+ ? `${this.colorize('Object:', logLevel)}\n${JSON.stringify(message, (key, value) => typeof value === 'bigint' ? value.toString() : value, 2)}\n`
160
+ : this.colorize(message, logLevel);
154
161
  }
155
162
  colorize(message, logLevel) {
156
163
  const color = this.getColorByLogLevel(logLevel);