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