@wikicasa-dev/node-common 4.7.12 → 5.0.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.
- package/dist/examples/callpool-demo.js +14 -13
- package/dist/examples/callpool-demo.js.map +1 -1
- package/dist/examples/console-demo.js +25 -25
- package/dist/examples/console-demo.js.map +1 -1
- package/dist/src/Cache.d.ts +39 -2
- package/dist/src/Cache.js +44 -6
- package/dist/src/Cache.js.map +1 -1
- package/dist/src/CacheES.d.ts +28 -0
- package/dist/src/CacheES.js +34 -4
- package/dist/src/CacheES.js.map +1 -1
- package/dist/src/CallPool.d.ts +72 -5
- package/dist/src/CallPool.js +84 -10
- package/dist/src/CallPool.js.map +1 -1
- package/dist/src/Console.d.ts +21 -58
- package/dist/src/Console.js +80 -79
- package/dist/src/Console.js.map +1 -1
- package/dist/src/Crawler.d.ts +18 -0
- package/dist/src/Crawler.js +20 -2
- package/dist/src/Crawler.js.map +1 -1
- package/dist/src/Pool.d.ts +19 -0
- package/dist/src/Pool.js +21 -2
- package/dist/src/Pool.js.map +1 -1
- package/dist/src/common.d.ts +74 -3
- package/dist/src/common.js +80 -7
- package/dist/src/common.js.map +1 -1
- package/dist/src/utils.d.ts +165 -26
- package/dist/src/utils.js +165 -26
- package/dist/src/utils.js.map +1 -1
- package/package.json +20 -23
package/dist/src/CallPool.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface CallPoolConfig {
|
|
|
21
21
|
maxConcurrency: number;
|
|
22
22
|
limitCall?: number;
|
|
23
23
|
limitInterval?: number;
|
|
24
|
+
timeout?: number;
|
|
24
25
|
retry?: Partial<RetryConfig>;
|
|
25
26
|
}
|
|
26
27
|
export declare class CallPool {
|
|
@@ -44,30 +45,96 @@ export declare class CallPool {
|
|
|
44
45
|
private readonly httpsAgent?;
|
|
45
46
|
private readonly httpAgent?;
|
|
46
47
|
constructor(config: CallPoolConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Merge caller-supplied Axios config with proxy, agent, and header defaults.
|
|
50
|
+
*
|
|
51
|
+
* @param config - Optional Axios request overrides
|
|
52
|
+
* @returns Merged Axios configuration
|
|
53
|
+
*/
|
|
47
54
|
private buildAxiosConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Record a call timestamp and prune entries older than one minute (thread-safe).
|
|
57
|
+
*/
|
|
48
58
|
private updateCallStack;
|
|
59
|
+
/**
|
|
60
|
+
* Execute a single task through the rate limiter with automatic retry on transient failures.
|
|
61
|
+
*
|
|
62
|
+
* @param call - Async factory to execute
|
|
63
|
+
* @param resolve - Promise resolve callback
|
|
64
|
+
* @param reject - Promise reject callback
|
|
65
|
+
* @param remainingAttempts - Number of retry attempts left
|
|
66
|
+
*/
|
|
49
67
|
private executeLimited;
|
|
68
|
+
/**
|
|
69
|
+
* Perform an HTTP request immediately, bypassing the pool queue.
|
|
70
|
+
*
|
|
71
|
+
* @param url - Request URL
|
|
72
|
+
* @param config - Optional Axios request configuration
|
|
73
|
+
* @returns Axios response
|
|
74
|
+
*/
|
|
50
75
|
directCall(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse>;
|
|
76
|
+
/**
|
|
77
|
+
* Enqueue an HTTP request to be executed when a concurrency slot is available.
|
|
78
|
+
*
|
|
79
|
+
* @param url - Request URL
|
|
80
|
+
* @param config - Optional Axios request configuration
|
|
81
|
+
* @returns Axios response once the request completes
|
|
82
|
+
*/
|
|
51
83
|
call(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Pick a random modern browser User-Agent string for request rotation.
|
|
86
|
+
*
|
|
87
|
+
* @returns Random User-Agent string or null if none matches
|
|
88
|
+
*/
|
|
52
89
|
private getRandomUserAgent;
|
|
90
|
+
/**
|
|
91
|
+
* Add a custom async task to the pool queue and return its result when complete.
|
|
92
|
+
*
|
|
93
|
+
* @param call - Async factory function to enqueue
|
|
94
|
+
* @returns Resolved value from the call
|
|
95
|
+
*/
|
|
53
96
|
enqueue(call: () => Promise<any>): Promise<any>;
|
|
97
|
+
/**
|
|
98
|
+
* Drain the queue by dispatching tasks up to the current adaptive concurrency limit.
|
|
99
|
+
*/
|
|
54
100
|
private schedule;
|
|
101
|
+
/**
|
|
102
|
+
* Adjust adaptive concurrency based on mean response time and update the progress display.
|
|
103
|
+
*
|
|
104
|
+
* @param startTime - High-resolution timestamp when the task started
|
|
105
|
+
*/
|
|
55
106
|
private updateMetrics;
|
|
56
107
|
print(): string;
|
|
108
|
+
/**
|
|
109
|
+
* Rebuild the visual progress bar string with pool stats (active, queued, mean time, calls/min).
|
|
110
|
+
*/
|
|
57
111
|
updatePrint(): Promise<void>;
|
|
58
112
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @returns
|
|
113
|
+
* Returns the number of calls currently queued
|
|
114
|
+
* @returns The number of queued calls
|
|
61
115
|
*/
|
|
62
116
|
queueLength(): number;
|
|
63
117
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @param checkInterval
|
|
66
|
-
* @returns Promise
|
|
118
|
+
* Waits for all queued calls to complete
|
|
119
|
+
* @param checkInterval Milliseconds between queue status checks (default: 1000ms)
|
|
120
|
+
* @returns Promise that resolves when the queue is empty and no calls are active
|
|
67
121
|
*/
|
|
68
122
|
finish(checkInterval?: number): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Count HTTP calls made in the last 60 seconds (thread-safe).
|
|
125
|
+
*
|
|
126
|
+
* @returns Number of calls within the last minute
|
|
127
|
+
*/
|
|
69
128
|
getActualCallsPerMinute(): Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* Return the cumulative number of calls made since pool creation.
|
|
131
|
+
*
|
|
132
|
+
* @returns Total call count
|
|
133
|
+
*/
|
|
70
134
|
getTotalCalls(): number;
|
|
135
|
+
/**
|
|
136
|
+
* Wait for all pending tasks to finish, then release all internal resources.
|
|
137
|
+
*/
|
|
71
138
|
destroy(): Promise<void>;
|
|
72
139
|
}
|
|
73
140
|
export {};
|
package/dist/src/CallPool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import throttledQueue from "throttled-queue";
|
|
1
|
+
import { throttledQueue } from "throttled-queue";
|
|
2
2
|
import { Console, COLORS } from "./Console.js";
|
|
3
3
|
import { EventEmitter } from "events";
|
|
4
4
|
import axios from "axios";
|
|
@@ -46,6 +46,7 @@ const defaultConfig = {
|
|
|
46
46
|
maxConcurrency: 10,
|
|
47
47
|
limitCall: undefined,
|
|
48
48
|
limitInterval: undefined,
|
|
49
|
+
timeout: 600000,
|
|
49
50
|
retry: defaultRetryConfig,
|
|
50
51
|
};
|
|
51
52
|
export class CallPool {
|
|
@@ -73,7 +74,7 @@ export class CallPool {
|
|
|
73
74
|
this.concurrency = (this.config.minConcurrency + this.config.maxConcurrency) / 2;
|
|
74
75
|
this.queue = [];
|
|
75
76
|
this.activeCount = 0;
|
|
76
|
-
this.limiter = throttledQueue(this.config.limitCall, this.config.limitInterval, true);
|
|
77
|
+
this.limiter = throttledQueue({ maxPerInterval: this.config.limitCall, interval: this.config.limitInterval, evenlySpaced: true });
|
|
77
78
|
this.updatePrint();
|
|
78
79
|
this.agent = new Agent({
|
|
79
80
|
maxSockets: 100,
|
|
@@ -88,6 +89,12 @@ export class CallPool {
|
|
|
88
89
|
this.httpAgent = new HttpsProxyAgent(proxyUrl);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Merge caller-supplied Axios config with proxy, agent, and header defaults.
|
|
94
|
+
*
|
|
95
|
+
* @param config - Optional Axios request overrides
|
|
96
|
+
* @returns Merged Axios configuration
|
|
97
|
+
*/
|
|
91
98
|
buildAxiosConfig(config) {
|
|
92
99
|
return _.merge({
|
|
93
100
|
method: "GET",
|
|
@@ -106,13 +113,16 @@ export class CallPool {
|
|
|
106
113
|
httpAgent: this.httpAgent,
|
|
107
114
|
maxContentLength: Infinity,
|
|
108
115
|
maxBodyLength: Infinity,
|
|
109
|
-
timeout:
|
|
116
|
+
timeout: this.config.timeout,
|
|
110
117
|
headers: {
|
|
111
118
|
...(this.config.proxy === PROXY.DYNAMIC && { "Zyte-Geolocation": "IT" }),
|
|
112
119
|
...(this.config.proxy !== PROXY.NONE && { "User-Agent": this.getRandomUserAgent() }),
|
|
113
120
|
},
|
|
114
121
|
}, config);
|
|
115
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Record a call timestamp and prune entries older than one minute (thread-safe).
|
|
125
|
+
*/
|
|
116
126
|
async updateCallStack() {
|
|
117
127
|
await this.callStackMutex.runExclusive(() => {
|
|
118
128
|
this.totalCalls++;
|
|
@@ -122,6 +132,14 @@ export class CallPool {
|
|
|
122
132
|
this.callStack = this.callStack.filter(timestamp => timestamp > oneMinuteAgo);
|
|
123
133
|
});
|
|
124
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Execute a single task through the rate limiter with automatic retry on transient failures.
|
|
137
|
+
*
|
|
138
|
+
* @param call - Async factory to execute
|
|
139
|
+
* @param resolve - Promise resolve callback
|
|
140
|
+
* @param reject - Promise reject callback
|
|
141
|
+
* @param remainingAttempts - Number of retry attempts left
|
|
142
|
+
*/
|
|
125
143
|
executeLimited(call, resolve, reject, remainingAttempts = this.config.retry?.attempts) {
|
|
126
144
|
const time = performance.now();
|
|
127
145
|
this.activeCount++;
|
|
@@ -133,7 +151,7 @@ export class CallPool {
|
|
|
133
151
|
}
|
|
134
152
|
catch (error) {
|
|
135
153
|
if (this.config.retry?.shouldRetry?.(error) && remainingAttempts > 0) {
|
|
136
|
-
Console.
|
|
154
|
+
Console.warn("Retrying queued call", { pool: this.config.name, remainingAttempts: remainingAttempts - 1 });
|
|
137
155
|
await sleep(this.config.retry.delayMs);
|
|
138
156
|
this.executeLimited(call, resolve, reject, remainingAttempts - 1);
|
|
139
157
|
}
|
|
@@ -148,9 +166,29 @@ export class CallPool {
|
|
|
148
166
|
}
|
|
149
167
|
});
|
|
150
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Perform an HTTP request immediately, bypassing the pool queue.
|
|
171
|
+
*
|
|
172
|
+
* @param url - Request URL
|
|
173
|
+
* @param config - Optional Axios request configuration
|
|
174
|
+
* @returns Axios response
|
|
175
|
+
*/
|
|
151
176
|
async directCall(url, config) {
|
|
152
|
-
|
|
177
|
+
try {
|
|
178
|
+
return await axios(url, this.buildAxiosConfig(config));
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
Console.error("Direct call failed", { pool: this.config.name, url, error });
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
153
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Enqueue an HTTP request to be executed when a concurrency slot is available.
|
|
187
|
+
*
|
|
188
|
+
* @param url - Request URL
|
|
189
|
+
* @param config - Optional Axios request configuration
|
|
190
|
+
* @returns Axios response once the request completes
|
|
191
|
+
*/
|
|
154
192
|
call(url, config) {
|
|
155
193
|
return new Promise((resolve, reject) => {
|
|
156
194
|
this.queue.push({
|
|
@@ -161,6 +199,11 @@ export class CallPool {
|
|
|
161
199
|
this.schedule();
|
|
162
200
|
});
|
|
163
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Pick a random modern browser User-Agent string for request rotation.
|
|
204
|
+
*
|
|
205
|
+
* @returns Random User-Agent string or null if none matches
|
|
206
|
+
*/
|
|
164
207
|
getRandomUserAgent() {
|
|
165
208
|
const browsers = [
|
|
166
209
|
{ name: "Chrome", version: 109 },
|
|
@@ -171,6 +214,12 @@ export class CallPool {
|
|
|
171
214
|
return browsers.some(b => b.name === ua.browserName && b.version <= parseInt(ua.browserVersion));
|
|
172
215
|
});
|
|
173
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Add a custom async task to the pool queue and return its result when complete.
|
|
219
|
+
*
|
|
220
|
+
* @param call - Async factory function to enqueue
|
|
221
|
+
* @returns Resolved value from the call
|
|
222
|
+
*/
|
|
174
223
|
enqueue(call) {
|
|
175
224
|
return new Promise((resolve, reject) => {
|
|
176
225
|
this.queue.push({
|
|
@@ -181,6 +230,9 @@ export class CallPool {
|
|
|
181
230
|
this.schedule();
|
|
182
231
|
});
|
|
183
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Drain the queue by dispatching tasks up to the current adaptive concurrency limit.
|
|
235
|
+
*/
|
|
184
236
|
schedule() {
|
|
185
237
|
if (this.isScheduling)
|
|
186
238
|
return;
|
|
@@ -198,6 +250,11 @@ export class CallPool {
|
|
|
198
250
|
this.isScheduling = false;
|
|
199
251
|
}
|
|
200
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Adjust adaptive concurrency based on mean response time and update the progress display.
|
|
255
|
+
*
|
|
256
|
+
* @param startTime - High-resolution timestamp when the task started
|
|
257
|
+
*/
|
|
201
258
|
updateMetrics(startTime) {
|
|
202
259
|
this.clock--;
|
|
203
260
|
if (this.clock < 0) {
|
|
@@ -217,6 +274,9 @@ export class CallPool {
|
|
|
217
274
|
print() {
|
|
218
275
|
return this._print;
|
|
219
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Rebuild the visual progress bar string with pool stats (active, queued, mean time, calls/min).
|
|
279
|
+
*/
|
|
220
280
|
async updatePrint() {
|
|
221
281
|
const textStart = `${Console.color(this.config.name.padEnd(16), COLORS.YELLOW)} [POOL][`;
|
|
222
282
|
const callsPerMinute = await this.getActualCallsPerMinute();
|
|
@@ -232,31 +292,44 @@ export class CallPool {
|
|
|
232
292
|
//Console.forceSummaryLinesRefresh();
|
|
233
293
|
}
|
|
234
294
|
/**
|
|
235
|
-
*
|
|
236
|
-
* @returns
|
|
295
|
+
* Returns the number of calls currently queued
|
|
296
|
+
* @returns The number of queued calls
|
|
237
297
|
*/
|
|
238
298
|
queueLength() {
|
|
239
299
|
return this.queue.length;
|
|
240
300
|
}
|
|
241
301
|
/**
|
|
242
|
-
*
|
|
243
|
-
* @param checkInterval
|
|
244
|
-
* @returns Promise
|
|
302
|
+
* Waits for all queued calls to complete
|
|
303
|
+
* @param checkInterval Milliseconds between queue status checks (default: 1000ms)
|
|
304
|
+
* @returns Promise that resolves when the queue is empty and no calls are active
|
|
245
305
|
*/
|
|
246
306
|
async finish(checkInterval = 1000) {
|
|
247
307
|
while (this.queue.length > 0 || this.activeCount > 0) {
|
|
248
308
|
await sleep(checkInterval);
|
|
249
309
|
}
|
|
250
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Count HTTP calls made in the last 60 seconds (thread-safe).
|
|
313
|
+
*
|
|
314
|
+
* @returns Number of calls within the last minute
|
|
315
|
+
*/
|
|
251
316
|
async getActualCallsPerMinute() {
|
|
252
317
|
return await this.callStackMutex.runExclusive(() => {
|
|
253
318
|
const oneMinuteAgo = Date.now() - this.MINUTE_IN_MS;
|
|
254
319
|
return this.callStack.filter(timestamp => timestamp > oneMinuteAgo).length;
|
|
255
320
|
});
|
|
256
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Return the cumulative number of calls made since pool creation.
|
|
324
|
+
*
|
|
325
|
+
* @returns Total call count
|
|
326
|
+
*/
|
|
257
327
|
getTotalCalls() {
|
|
258
328
|
return this.totalCalls;
|
|
259
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Wait for all pending tasks to finish, then release all internal resources.
|
|
332
|
+
*/
|
|
260
333
|
async destroy() {
|
|
261
334
|
await this.finish();
|
|
262
335
|
this.queue = [];
|
|
@@ -264,6 +337,7 @@ export class CallPool {
|
|
|
264
337
|
this.limiter = null;
|
|
265
338
|
this.agent.destroy();
|
|
266
339
|
Console.removeSummaryLine(this.config.name);
|
|
340
|
+
Console.debug("Pool destroyed", { pool: this.config.name, totalCalls: this.totalCalls });
|
|
267
341
|
}
|
|
268
342
|
}
|
|
269
343
|
//# sourceMappingURL=CallPool.js.map
|
package/dist/src/CallPool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CallPool.js","sourceRoot":"","sources":["../../src/CallPool.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"CallPool.js","sourceRo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AC;IAED;;;;OAIG;IACI,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO;QAChB,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAEpB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QAEpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAErB,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC7F,CAAC;CACJ"}
|
package/dist/src/Console.d.ts
CHANGED
|
@@ -20,15 +20,16 @@ export declare enum LOG_LEVEL {
|
|
|
20
20
|
DEBUG = "debug",
|
|
21
21
|
VERBOSE = "verbose"
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
export type LogParams = Record<string, unknown>;
|
|
24
|
+
export interface LogOptions {
|
|
24
25
|
level?: LOG_LEVEL;
|
|
25
26
|
color?: COLORS;
|
|
26
27
|
spinner?: boolean;
|
|
27
28
|
prefix?: string;
|
|
28
|
-
[key: string]: any;
|
|
29
29
|
}
|
|
30
30
|
interface LogHistoryEntry {
|
|
31
31
|
message: string;
|
|
32
|
+
params?: LogParams;
|
|
32
33
|
prefix?: string;
|
|
33
34
|
color: COLORS;
|
|
34
35
|
timestamp: Date;
|
|
@@ -65,56 +66,16 @@ export declare class Console implements LoggerService {
|
|
|
65
66
|
* Costruttore pubblico per permettere l'istanziazione diretta.
|
|
66
67
|
*/
|
|
67
68
|
constructor();
|
|
69
|
+
private static formatParamValue;
|
|
70
|
+
private static formatParams;
|
|
68
71
|
private static getEffectiveLevel;
|
|
69
72
|
private static shouldLog;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Scrittura generica su console
|
|
78
|
-
* @param message string
|
|
79
|
-
* @param logOptions LogOptions
|
|
80
|
-
* @returns void
|
|
81
|
-
*/
|
|
82
|
-
static log(message: string, logOptions?: LogOptions): void;
|
|
83
|
-
/**
|
|
84
|
-
* Scrittura di un errore
|
|
85
|
-
* @param message string
|
|
86
|
-
* @param logOptions LogOptions
|
|
87
|
-
* @returns void
|
|
88
|
-
*/
|
|
89
|
-
static error(message: string, logOptions?: LogOptions): void;
|
|
90
|
-
/**
|
|
91
|
-
* Scrittura di un avviso
|
|
92
|
-
* @param message string
|
|
93
|
-
* @param logOptions LogOptions
|
|
94
|
-
* @returns void
|
|
95
|
-
*/
|
|
96
|
-
static warn(message: string, logOptions?: LogOptions): void;
|
|
97
|
-
/**
|
|
98
|
-
* Scrittura di un successo
|
|
99
|
-
* @param message string
|
|
100
|
-
* @param logOptions LogOptions
|
|
101
|
-
* @returns void
|
|
102
|
-
*/
|
|
103
|
-
static success(message: string, logOptions?: LogOptions): void;
|
|
104
|
-
/**
|
|
105
|
-
* Scrittura di un debug
|
|
106
|
-
* @param message string
|
|
107
|
-
* @param logOptions LogOptions
|
|
108
|
-
* @returns void
|
|
109
|
-
*/
|
|
110
|
-
static debug(message: string, logOptions?: LogOptions): void;
|
|
111
|
-
/**
|
|
112
|
-
* Scrittura di un verbose
|
|
113
|
-
* @param message string
|
|
114
|
-
* @param logOptions LogOptions
|
|
115
|
-
* @returns void
|
|
116
|
-
*/
|
|
117
|
-
static verbose(message: string, logOptions?: LogOptions): void;
|
|
73
|
+
static log(message: string, params?: LogParams, options?: LogOptions): void;
|
|
74
|
+
static error(message: string, params?: LogParams, options?: LogOptions): void;
|
|
75
|
+
static warn(message: string, params?: LogParams, options?: LogOptions): void;
|
|
76
|
+
static success(message: string, params?: LogParams, options?: LogOptions): void;
|
|
77
|
+
static debug(message: string, params?: LogParams, options?: LogOptions): void;
|
|
78
|
+
static verbose(message: string, params?: LogParams, options?: LogOptions): void;
|
|
118
79
|
/**
|
|
119
80
|
* Aggiunge una riga di riepilogo (summary) in fondo allo schermo
|
|
120
81
|
* @param fn funzione che restituisce la stringa di testo
|
|
@@ -150,14 +111,19 @@ export declare class Console implements LoggerService {
|
|
|
150
111
|
* @returns string
|
|
151
112
|
*/
|
|
152
113
|
static color(str: string, color: COLORS): string;
|
|
153
|
-
error(message: any,
|
|
154
|
-
warn(message: any,
|
|
155
|
-
log(message: any,
|
|
156
|
-
debug(message: any,
|
|
157
|
-
verbose(message: any,
|
|
114
|
+
error(message: any, ...args: any[]): void;
|
|
115
|
+
warn(message: any, ...args: any[]): void;
|
|
116
|
+
log(message: any, ...args: any[]): void;
|
|
117
|
+
debug(message: any, ...args: any[]): void;
|
|
118
|
+
verbose(message: any, ...args: any[]): void;
|
|
158
119
|
appendSummaryLine(fn: () => string, color?: COLORS, id?: string): void;
|
|
159
120
|
removeSummaryLine(id: string): void;
|
|
160
121
|
clearSummaryLines(): void;
|
|
122
|
+
/**
|
|
123
|
+
* Adapter for NestJS LoggerService rest args.
|
|
124
|
+
* Handles: (params, options), (params), (contextString), ()
|
|
125
|
+
*/
|
|
126
|
+
private extractArgs;
|
|
161
127
|
/**
|
|
162
128
|
* Si assicura che lo schermo sia stato creato (lazy init).
|
|
163
129
|
* @returns void
|
|
@@ -165,9 +131,6 @@ export declare class Console implements LoggerService {
|
|
|
165
131
|
private static ensureInitialized;
|
|
166
132
|
/**
|
|
167
133
|
* Logica comune per stampare messaggi, con o senza spinner.
|
|
168
|
-
* @param message string
|
|
169
|
-
* @param logOptions LogOptions
|
|
170
|
-
* @returns void
|
|
171
134
|
*/
|
|
172
135
|
private static write;
|
|
173
136
|
/**
|