@nestjs/common 9.1.5 → 9.1.6
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/cache/cache.providers.js
CHANGED
|
@@ -13,19 +13,25 @@ const default_options_1 = require("./default-options");
|
|
|
13
13
|
function createCacheManager() {
|
|
14
14
|
return {
|
|
15
15
|
provide: cache_constants_1.CACHE_MANAGER,
|
|
16
|
-
useFactory: (options) => {
|
|
16
|
+
useFactory: async (options) => {
|
|
17
17
|
const cacheManager = (0, load_package_util_1.loadPackage)('cache-manager', 'CacheModule', () => require('cache-manager'));
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const cachingFactory = (store, options) => {
|
|
22
|
-
if (cacheManagerMajor < 5) {
|
|
18
|
+
const cacheManagerIsv5OrGreater = 'memoryStore' in cacheManager;
|
|
19
|
+
const cachingFactory = async (store, options) => {
|
|
20
|
+
if (!cacheManagerIsv5OrGreater) {
|
|
23
21
|
return cacheManager.caching(Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), Object.assign(Object.assign({}, options), { store })));
|
|
24
22
|
}
|
|
25
|
-
|
|
23
|
+
let cache = 'memory';
|
|
24
|
+
default_options_1.defaultCacheOptions.ttl *= 1000;
|
|
25
|
+
if (typeof store === 'object' && 'create' in store) {
|
|
26
|
+
cache = store.create;
|
|
27
|
+
}
|
|
28
|
+
else if (typeof store === 'function') {
|
|
29
|
+
cache = store;
|
|
30
|
+
}
|
|
31
|
+
return cacheManager.caching(cache, Object.assign(Object.assign({}, default_options_1.defaultCacheOptions), options));
|
|
26
32
|
};
|
|
27
33
|
return Array.isArray(options)
|
|
28
|
-
? cacheManager.multiCaching(options.map(option => cachingFactory(
|
|
34
|
+
? cacheManager.multiCaching(await Promise.all(options.map(option => cachingFactory(option.store, option))))
|
|
29
35
|
: cachingFactory(options.store, options);
|
|
30
36
|
},
|
|
31
37
|
inject: [cache_module_definition_1.MODULE_OPTIONS_TOKEN],
|
|
@@ -14,7 +14,7 @@ export interface CacheStore {
|
|
|
14
14
|
* @param key cache key
|
|
15
15
|
* @param value cache value
|
|
16
16
|
*/
|
|
17
|
-
set<T>(key: string, value: T, options?: CacheStoreSetOptions<T>): Promise<void> | void;
|
|
17
|
+
set<T>(key: string, value: T, options?: CacheStoreSetOptions<T> | number): Promise<void> | void;
|
|
18
18
|
/**
|
|
19
19
|
* Retrieve a key/value pair from the cache.
|
|
20
20
|
*
|
|
@@ -62,9 +62,10 @@ export interface CacheManagerOptions {
|
|
|
62
62
|
*/
|
|
63
63
|
store?: string | CacheStoreFactory | CacheStore;
|
|
64
64
|
/**
|
|
65
|
-
* Time to live - amount of time
|
|
65
|
+
* Time to live - amount of time that a response is cached before it
|
|
66
66
|
* is deleted. Subsequent request will call through the route handler and refresh
|
|
67
|
-
* the cache. Defaults to 5 seconds.
|
|
67
|
+
* the cache. Defaults to 5 seconds. In `cache-manager@^4` this value is in seconds.
|
|
68
|
+
* In `cache-manager@^5` this value is in milliseconds.
|
|
68
69
|
*/
|
|
69
70
|
ttl?: number;
|
|
70
71
|
/**
|
package/package.json
CHANGED
|
@@ -65,11 +65,13 @@ export declare class ConsoleLogger implements LoggerService {
|
|
|
65
65
|
protected getTimestamp(): string;
|
|
66
66
|
protected printMessages(messages: unknown[], context?: string, logLevel?: LogLevel, writeStreamType?: 'stdout' | 'stderr'): void;
|
|
67
67
|
protected formatPid(pid: number): string;
|
|
68
|
+
protected formatContext(context: string): string;
|
|
68
69
|
protected formatMessage(logLevel: LogLevel, message: unknown, pidMessage: string, formattedLogLevel: string, contextMessage: string, timestampDiff: string): string;
|
|
69
70
|
protected stringifyMessage(message: unknown, logLevel: LogLevel): string;
|
|
70
71
|
protected colorize(message: string, logLevel: LogLevel): string;
|
|
71
72
|
protected printStackTrace(stack: string): void;
|
|
72
73
|
private updateAndGetTimestampDiff;
|
|
74
|
+
protected formatTimestampDiff(timestampDiff: number): string;
|
|
73
75
|
private getContextAndMessagesToPrint;
|
|
74
76
|
private getContextAndStackAndMessagesToPrint;
|
|
75
77
|
private getColorByLogLevel;
|
|
@@ -116,7 +116,7 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
116
116
|
printMessages(messages, context = '', logLevel = 'log', writeStreamType) {
|
|
117
117
|
messages.forEach(message => {
|
|
118
118
|
const pidMessage = this.formatPid(process.pid);
|
|
119
|
-
const contextMessage =
|
|
119
|
+
const contextMessage = this.formatContext(context);
|
|
120
120
|
const timestampDiff = this.updateAndGetTimestampDiff();
|
|
121
121
|
const formattedLogLevel = logLevel.toUpperCase().padStart(7, ' ');
|
|
122
122
|
const formattedMessage = this.formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff);
|
|
@@ -126,6 +126,9 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
126
126
|
formatPid(pid) {
|
|
127
127
|
return `[Nest] ${pid} - `;
|
|
128
128
|
}
|
|
129
|
+
formatContext(context) {
|
|
130
|
+
return context ? (0, cli_colors_util_1.yellow)(`[${context}] `) : '';
|
|
131
|
+
}
|
|
129
132
|
formatMessage(logLevel, message, pidMessage, formattedLogLevel, contextMessage, timestampDiff) {
|
|
130
133
|
const output = this.stringifyMessage(message, logLevel);
|
|
131
134
|
pidMessage = this.colorize(pidMessage, logLevel);
|
|
@@ -151,11 +154,14 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger {
|
|
|
151
154
|
var _a;
|
|
152
155
|
const includeTimestamp = ConsoleLogger_1.lastTimestampAt && ((_a = this.options) === null || _a === void 0 ? void 0 : _a.timestamp);
|
|
153
156
|
const result = includeTimestamp
|
|
154
|
-
?
|
|
157
|
+
? this.formatTimestampDiff(Date.now() - ConsoleLogger_1.lastTimestampAt)
|
|
155
158
|
: '';
|
|
156
159
|
ConsoleLogger_1.lastTimestampAt = Date.now();
|
|
157
160
|
return result;
|
|
158
161
|
}
|
|
162
|
+
formatTimestampDiff(timestampDiff) {
|
|
163
|
+
return (0, cli_colors_util_1.yellow)(` +${timestampDiff}ms`);
|
|
164
|
+
}
|
|
159
165
|
getContextAndMessagesToPrint(args) {
|
|
160
166
|
if ((args === null || args === void 0 ? void 0 : args.length) <= 1) {
|
|
161
167
|
return { messages: args, context: this.context };
|