@d-zero/dealer 1.6.0 → 1.6.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/README.md +3 -3
- package/dist/deal.d.ts +2 -2
- package/dist/dealer.d.ts +3 -3
- package/dist/display.js +33 -18
- package/dist/lanes.js +3 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ async function deal<T extends WeakKey>(
|
|
|
54
54
|
setLineHeader: (lineHeader: string) => void,
|
|
55
55
|
push: (...items: T[]) => Promise<void>,
|
|
56
56
|
) => Promise<() => void | Promise<void>> | (() => void | Promise<void>),
|
|
57
|
-
options?: DealOptions
|
|
57
|
+
options?: DealOptions<T>,
|
|
58
58
|
): Promise<void>;
|
|
59
59
|
```
|
|
60
60
|
|
|
@@ -83,7 +83,7 @@ async function deal<T extends WeakKey>(
|
|
|
83
83
|
### DealOptions型
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
-
type DealOptions = DealerOptions &
|
|
86
|
+
type DealOptions<T = unknown> = DealerOptions<T> &
|
|
87
87
|
LanesOptions & {
|
|
88
88
|
readonly header?: DealHeader;
|
|
89
89
|
readonly debug?: boolean;
|
|
@@ -135,7 +135,7 @@ type DealHeader = (
|
|
|
135
135
|
#### コンストラクタ
|
|
136
136
|
|
|
137
137
|
```ts
|
|
138
|
-
constructor(items: readonly T[], options?: DealerOptions)
|
|
138
|
+
constructor(items: readonly T[], options?: DealerOptions<T>)
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
- `items`: 処理対象のアイテム
|
package/dist/deal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DealerOptions } from './dealer.js';
|
|
2
2
|
import type { LanesOptions } from './lanes.js';
|
|
3
3
|
import type { DelayOptions } from '@d-zero/shared/delay';
|
|
4
|
-
export type DealOptions = DealerOptions & LanesOptions & {
|
|
4
|
+
export type DealOptions<T = unknown> = DealerOptions<T> & LanesOptions & {
|
|
5
5
|
readonly header?: DealHeader;
|
|
6
6
|
readonly debug?: boolean;
|
|
7
7
|
readonly interval?: number | DelayOptions;
|
|
@@ -41,4 +41,4 @@ export type DealHeader = (progress: number, done: number, total: number, limit:
|
|
|
41
41
|
* @param options - Configuration options including interval delay
|
|
42
42
|
* @returns Promise that resolves when all items are processed
|
|
43
43
|
*/
|
|
44
|
-
export declare function deal<T extends WeakKey>(items: readonly T[], setup: (process: T, update: (log: string) => void, index: number, setLineHeader: (lineHeader: string) => void, push: (...items: T[]) => Promise<void>) => Promise<() => void | Promise<void>> | (() => void | Promise<void>), options?: DealOptions): Promise<void>;
|
|
44
|
+
export declare function deal<T extends WeakKey>(items: readonly T[], setup: (process: T, update: (log: string) => void, index: number, setLineHeader: (lineHeader: string) => void, push: (...items: T[]) => Promise<void>) => Promise<() => void | Promise<void>> | (() => void | Promise<void>), options?: DealOptions<T>): Promise<void>;
|
package/dist/dealer.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ProcessInitializer } from './types.js';
|
|
2
|
-
export interface DealerOptions {
|
|
2
|
+
export interface DealerOptions<T = unknown> {
|
|
3
3
|
limit?: number;
|
|
4
|
-
onPush?: (item:
|
|
4
|
+
onPush?: (item: T) => boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare class Dealer<T extends WeakKey> {
|
|
7
7
|
#private;
|
|
8
|
-
constructor(items: readonly T[], options?: DealerOptions);
|
|
8
|
+
constructor(items: readonly T[], options?: DealerOptions<T>);
|
|
9
9
|
debug(listener: (log: string) => void): void;
|
|
10
10
|
finish(listener: () => void): void;
|
|
11
11
|
play(): void;
|
package/dist/display.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import readline from 'node:readline';
|
|
2
|
-
import c from 'ansi-colors';
|
|
3
1
|
import { countDownFunctionParser } from './count-down-function-parser.js';
|
|
4
2
|
import { riffle } from './riffle.js';
|
|
5
|
-
const RESET =
|
|
3
|
+
const RESET = '\u001B[0m';
|
|
4
|
+
const CURSOR_UP = (n) => `\u001B[${n}A`;
|
|
5
|
+
const CURSOR_TO_COL0 = '\u001B[G';
|
|
6
|
+
const ERASE_DOWN = '\u001B[0J';
|
|
6
7
|
const animationPresets = {
|
|
7
8
|
earth: [2, '🌏', '🌍', '🌎'],
|
|
8
9
|
dots: [5, '. ', '.. ', '...'],
|
|
@@ -12,10 +13,13 @@ const animationPresets = {
|
|
|
12
13
|
};
|
|
13
14
|
export class Display {
|
|
14
15
|
#animations;
|
|
16
|
+
#closed = false;
|
|
15
17
|
#coundDownMap = new Map();
|
|
16
18
|
#debugMessages = [];
|
|
17
19
|
#frameInterval;
|
|
18
20
|
#lastWroteLineNum = 0;
|
|
21
|
+
#resizeHandler = null;
|
|
22
|
+
#sigintHandler = null;
|
|
19
23
|
#stack = null;
|
|
20
24
|
#startTime = Date.now();
|
|
21
25
|
#timer = null;
|
|
@@ -28,18 +32,34 @@ export class Display {
|
|
|
28
32
|
const fps = options?.fps ?? 30;
|
|
29
33
|
this.#frameInterval = 1000 / fps;
|
|
30
34
|
this.#verbose = options?.verbose ?? false;
|
|
31
|
-
|
|
35
|
+
this.#resizeHandler = () => this.#resize();
|
|
36
|
+
process.stdout.on('resize', this.#resizeHandler);
|
|
37
|
+
if (!this.#verbose) {
|
|
38
|
+
this.#sigintHandler = () => {
|
|
39
|
+
this.close();
|
|
40
|
+
process.exit(130);
|
|
41
|
+
};
|
|
42
|
+
process.on('SIGINT', this.#sigintHandler);
|
|
43
|
+
}
|
|
32
44
|
}
|
|
33
45
|
close() {
|
|
34
|
-
if (this.#verbose) {
|
|
46
|
+
if (this.#verbose || this.#closed) {
|
|
35
47
|
return;
|
|
36
48
|
}
|
|
49
|
+
this.#closed = true;
|
|
37
50
|
if (this.#timer) {
|
|
38
51
|
clearTimeout(this.#timer);
|
|
39
52
|
this.#timer = null;
|
|
40
53
|
}
|
|
41
54
|
this.#write();
|
|
42
|
-
|
|
55
|
+
if (this.#resizeHandler) {
|
|
56
|
+
process.stdout.off('resize', this.#resizeHandler);
|
|
57
|
+
this.#resizeHandler = null;
|
|
58
|
+
}
|
|
59
|
+
if (this.#sigintHandler) {
|
|
60
|
+
process.off('SIGINT', this.#sigintHandler);
|
|
61
|
+
this.#sigintHandler = null;
|
|
62
|
+
}
|
|
43
63
|
this.#lastWroteLineNum = 0;
|
|
44
64
|
this.#stack = null;
|
|
45
65
|
}
|
|
@@ -59,16 +79,6 @@ export class Display {
|
|
|
59
79
|
}
|
|
60
80
|
this.#enterFrame();
|
|
61
81
|
}
|
|
62
|
-
#clear() {
|
|
63
|
-
if (this.#verbose) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
for (let i = 0; i < this.#lastWroteLineNum; i++) {
|
|
67
|
-
readline.moveCursor(process.stdout, 0, -1);
|
|
68
|
-
readline.cursorTo(process.stdout, 0);
|
|
69
|
-
readline.clearLine(process.stdout, 0);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
82
|
#countDown(text) {
|
|
73
83
|
const parsed = countDownFunctionParser(text);
|
|
74
84
|
if (!parsed) {
|
|
@@ -114,12 +124,17 @@ export class Display {
|
|
|
114
124
|
if (!this.#stack) {
|
|
115
125
|
return;
|
|
116
126
|
}
|
|
117
|
-
this.#clear();
|
|
118
127
|
const outputBuffer = [];
|
|
119
128
|
for (const stack of this.#stack) {
|
|
120
129
|
outputBuffer.push(this.#text(stack));
|
|
121
130
|
}
|
|
122
|
-
|
|
131
|
+
const content = outputBuffer.join('\n') + '\n';
|
|
132
|
+
let output = '';
|
|
133
|
+
if (this.#lastWroteLineNum > 0) {
|
|
134
|
+
output += CURSOR_UP(this.#lastWroteLineNum) + CURSOR_TO_COL0 + ERASE_DOWN;
|
|
135
|
+
}
|
|
136
|
+
output += content;
|
|
137
|
+
process.stdout.write(output);
|
|
123
138
|
this.#lastWroteLineNum = this.#stack.length;
|
|
124
139
|
}
|
|
125
140
|
}
|
package/dist/lanes.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Display } from './display.js';
|
|
2
|
+
const RESET = '\u001B[0m';
|
|
2
3
|
export class Lanes {
|
|
3
4
|
#display;
|
|
4
5
|
#header;
|
|
@@ -45,7 +46,7 @@ export class Lanes {
|
|
|
45
46
|
}
|
|
46
47
|
update(id, log) {
|
|
47
48
|
if (this.#verbose) {
|
|
48
|
-
this.#display.write(this.#header
|
|
49
|
+
this.#display.write(`${RESET}${this.#header}${RESET} ${log}`);
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
this.#logs.set(id, log);
|
|
@@ -59,7 +60,7 @@ export class Lanes {
|
|
|
59
60
|
logs.sort(this.#sort);
|
|
60
61
|
const messages = logs.map(([, message]) => `${this.#indent}${message}`);
|
|
61
62
|
if (this.#header) {
|
|
62
|
-
messages.unshift(...this.#header.split('\n'));
|
|
63
|
+
messages.unshift(...this.#header.split('\n').map((line) => `${RESET}${line}${RESET}`));
|
|
63
64
|
}
|
|
64
65
|
this.#display.write(...messages);
|
|
65
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/dealer",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "A tool that provides an API and CLI for parallel processing of collections and sequential logging to standard output",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"clean": "tsc --build --clean"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@d-zero/shared": "0.
|
|
26
|
+
"@d-zero/shared": "0.20.0",
|
|
27
27
|
"ansi-colors": "4.1.3"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1830747a6fee6194c897d54966c25ada5237645e"
|
|
30
30
|
}
|