@akala/pm 15.2.9 → 15.3.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/changelog.md +7 -3
- package/dist/esm/ipc-adapter.d.ts +9 -6
- package/dist/esm/ipc-adapter.js +27 -17
- package/dist/esm/ipc-adapter.js.map +1 -1
- package/dist/esm/messageport-adapter.d.ts +10 -6
- package/dist/esm/messageport-adapter.js +48 -15
- package/dist/esm/messageport-adapter.js.map +1 -1
- package/dist/esm/virtual-scroll-prefixer.d.ts +12 -0
- package/dist/esm/virtual-scroll-prefixer.js +47 -0
- package/dist/esm/virtual-scroll-prefixer.js.map +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/ipc-adapter.ts +45 -23
- package/src/messageport-adapter.ts +59 -19
- package/src/virtual-scroll-prefixer.ts +67 -0
package/changelog.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
# (2025-06-
|
1
|
+
# (2025-06-18)
|
2
2
|
|
3
3
|
|
4
4
|
### Bug Fixes
|
5
5
|
|
6
|
-
*
|
7
|
-
|
6
|
+
* remove deprecated ac command usage 5cf4a82
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* enhance IpcAdapter and MessagePortAdapter to support improved event handling and subscription management 24090fb
|
8
12
|
|
9
13
|
|
10
14
|
|
@@ -1,14 +1,17 @@
|
|
1
1
|
import { ChildProcess } from "child_process";
|
2
2
|
import * as jsonrpc from '@akala/json-rpc-ws';
|
3
|
-
import {
|
4
|
-
export declare class IpcAdapter implements jsonrpc.SocketAdapter {
|
3
|
+
import { AllEventKeys, AllEvents, EventArgs, EventKeys, EventListener, EventOptions, EventReturnType, Subscription, TeardownManager } from "@akala/core";
|
4
|
+
export declare class IpcAdapter extends TeardownManager implements jsonrpc.SocketAdapter {
|
5
5
|
private cp;
|
6
6
|
get open(): boolean;
|
7
|
-
pipe(socket: jsonrpc.SocketAdapter
|
7
|
+
pipe(socket: jsonrpc.SocketAdapter): void;
|
8
8
|
close(): void;
|
9
9
|
send(data: string): void;
|
10
|
-
off<
|
11
|
-
on<
|
12
|
-
once<
|
10
|
+
off<const TEvent extends AllEventKeys<jsonrpc.SocketAdapterAkalaEventMap>>(event: TEvent, handler: EventListener<AllEvents<jsonrpc.SocketAdapterAkalaEventMap>[TEvent]>): boolean;
|
11
|
+
on<const TEvent extends AllEventKeys<jsonrpc.SocketAdapterAkalaEventMap>>(event: TEvent, handler: EventListener<AllEvents<jsonrpc.SocketAdapterAkalaEventMap>[TEvent]>, options?: EventOptions<AllEvents<jsonrpc.SocketAdapterAkalaEventMap>[TEvent]>): Subscription;
|
12
|
+
once<const TEvent extends AllEventKeys<jsonrpc.SocketAdapterAkalaEventMap>>(event: TEvent, handler: EventListener<AllEvents<jsonrpc.SocketAdapterAkalaEventMap>[TEvent]>): Subscription;
|
13
13
|
constructor(cp: ChildProcess | typeof process);
|
14
|
+
hasListener<const TKey extends AllEventKeys<jsonrpc.SocketAdapterAkalaEventMap>>(name: TKey): boolean;
|
15
|
+
get definedEvents(): AllEventKeys<jsonrpc.SocketAdapterAkalaEventMap>[];
|
16
|
+
emit<const TEvent extends EventKeys<jsonrpc.SocketAdapterAkalaEventMap>>(event: TEvent, ...args: EventArgs<jsonrpc.SocketAdapterAkalaEventMap[TEvent]>): false | EventReturnType<jsonrpc.SocketAdapterAkalaEventMap[TEvent]>;
|
14
17
|
}
|
package/dist/esm/ipc-adapter.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
import { StatefulSubscription, TeardownManager } from "@akala/core";
|
2
|
+
export class IpcAdapter extends TeardownManager {
|
2
3
|
cp;
|
3
4
|
get open() { return !!this.cp.pid; }
|
4
5
|
pipe(socket) {
|
@@ -26,35 +27,44 @@ export class IpcAdapter {
|
|
26
27
|
this.cp.off('disconnect', handler);
|
27
28
|
break;
|
28
29
|
}
|
30
|
+
return true;
|
29
31
|
}
|
30
|
-
on(event, handler) {
|
32
|
+
on(event, handler, options) {
|
31
33
|
switch (event) {
|
32
34
|
case 'message':
|
33
|
-
|
34
|
-
|
35
|
+
if (options?.once)
|
36
|
+
this.cp.on('message', handler);
|
37
|
+
else
|
38
|
+
this.cp.on('message', handler);
|
39
|
+
return new StatefulSubscription(() => this.cp.off('message', handler)).unsubscribe;
|
35
40
|
case 'open':
|
36
41
|
handler(null);
|
37
42
|
break;
|
38
43
|
case 'close':
|
39
|
-
|
40
|
-
|
44
|
+
if (options?.once)
|
45
|
+
this.cp.once('disconnect', handler);
|
46
|
+
else
|
47
|
+
this.cp.on('disconnect', handler);
|
48
|
+
return new StatefulSubscription(() => this.cp.off('disconnect', handler)).unsubscribe;
|
41
49
|
}
|
42
50
|
}
|
43
51
|
once(event, handler) {
|
44
|
-
|
45
|
-
case 'message':
|
46
|
-
this.cp.once('message', handler);
|
47
|
-
break;
|
48
|
-
case 'open':
|
49
|
-
handler(null);
|
50
|
-
break;
|
51
|
-
case 'close':
|
52
|
-
this.cp.once('disconnect', () => handler(null));
|
53
|
-
break;
|
54
|
-
}
|
52
|
+
return this.on(event, handler, { once: true });
|
55
53
|
}
|
56
54
|
constructor(cp) {
|
55
|
+
super();
|
57
56
|
this.cp = cp;
|
58
57
|
}
|
58
|
+
hasListener(name) {
|
59
|
+
if (name === 'open')
|
60
|
+
return false;
|
61
|
+
return !!this.cp.listenerCount(name);
|
62
|
+
}
|
63
|
+
get definedEvents() {
|
64
|
+
return ['close', 'error', 'message'].filter(ev => this.hasListener(ev));
|
65
|
+
}
|
66
|
+
emit(event, ...args) {
|
67
|
+
throw new Error("Method not implemented.");
|
68
|
+
}
|
59
69
|
}
|
60
70
|
//# sourceMappingURL=ipc-adapter.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ipc-adapter.js","sourceRoot":"","sources":["../../src/ipc-adapter.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"ipc-adapter.js","sourceRoot":"","sources":["../../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AO,EAAE,OAAO,EAAE,SAAS,CAAW,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,CAAqE,KAAa,EAAE,GAAG,IAA2D;QAElJ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CACJ"}
|
@@ -1,14 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { AllEventKeys, AllEvents, EventArgs, EventKeys, EventListener, EventOptions, EventReturnType, Subscription, TeardownManager } from "@akala/core";
|
2
|
+
import { SocketAdapter, SocketAdapterAkalaEventMap } from "@akala/json-rpc-ws";
|
2
3
|
import { MessagePort, Worker } from "worker_threads";
|
3
|
-
export declare class MessagePortAdapter implements SocketAdapter {
|
4
|
+
export declare class MessagePortAdapter extends TeardownManager implements SocketAdapter {
|
4
5
|
private cp;
|
5
6
|
private isOpen;
|
6
7
|
get open(): boolean;
|
7
8
|
close(): void;
|
8
9
|
send(data: string): void;
|
9
|
-
on<
|
10
|
-
once<
|
10
|
+
on<const TEvent extends AllEventKeys<SocketAdapterAkalaEventMap>>(event: TEvent, handler: EventListener<AllEvents<SocketAdapterAkalaEventMap>[TEvent]>, options?: EventOptions<AllEvents<SocketAdapterAkalaEventMap>[TEvent]>): Subscription;
|
11
|
+
once<const TEvent extends AllEventKeys<SocketAdapterAkalaEventMap>>(event: TEvent, handler: EventListener<AllEvents<SocketAdapterAkalaEventMap>[TEvent]>): Subscription;
|
11
12
|
constructor(cp: MessagePort | Worker);
|
12
|
-
off<
|
13
|
-
pipe(socket: SocketAdapter
|
13
|
+
off<const TEvent extends AllEventKeys<SocketAdapterAkalaEventMap>>(event: TEvent, handler: EventListener<AllEvents<SocketAdapterAkalaEventMap>[TEvent]>): boolean;
|
14
|
+
pipe(socket: SocketAdapter): void;
|
15
|
+
hasListener<const TKey extends AllEventKeys<SocketAdapterAkalaEventMap>>(name: TKey): boolean;
|
16
|
+
get definedEvents(): AllEventKeys<SocketAdapterAkalaEventMap>[];
|
17
|
+
emit<const TEvent extends EventKeys<SocketAdapterAkalaEventMap>>(event: TEvent, ...args: EventArgs<SocketAdapterAkalaEventMap[TEvent]>): false | EventReturnType<SocketAdapterAkalaEventMap[TEvent]>;
|
14
18
|
}
|
@@ -1,5 +1,6 @@
|
|
1
|
+
import { StatefulSubscription, TeardownManager } from "@akala/core";
|
1
2
|
import { Worker } from "worker_threads";
|
2
|
-
export class MessagePortAdapter {
|
3
|
+
export class MessagePortAdapter extends TeardownManager {
|
3
4
|
cp;
|
4
5
|
isOpen = true;
|
5
6
|
get open() { return this.isOpen; }
|
@@ -12,42 +13,74 @@ export class MessagePortAdapter {
|
|
12
13
|
send(data) {
|
13
14
|
this.cp.postMessage(data);
|
14
15
|
}
|
15
|
-
on(event, handler) {
|
16
|
+
on(event, handler, options) {
|
16
17
|
switch (event) {
|
17
18
|
case 'message':
|
18
|
-
|
19
|
-
|
19
|
+
if (options?.once)
|
20
|
+
this.cp.on('message', handler);
|
21
|
+
else
|
22
|
+
this.cp.on('message', handler);
|
23
|
+
return new StatefulSubscription(() => this.cp.off('message', handler)).unsubscribe;
|
20
24
|
case 'open':
|
21
25
|
handler(null);
|
22
26
|
break;
|
23
27
|
case 'close':
|
24
|
-
|
25
|
-
|
28
|
+
if (options?.once)
|
29
|
+
this.cp.once('disconnect', handler);
|
30
|
+
else
|
31
|
+
this.cp.on('disconnect', handler);
|
32
|
+
return new StatefulSubscription(() => this.cp.off('disconnect', handler)).unsubscribe;
|
26
33
|
}
|
27
34
|
}
|
28
35
|
once(event, handler) {
|
36
|
+
return this.on(event, handler, { once: true });
|
37
|
+
}
|
38
|
+
constructor(cp) {
|
39
|
+
super();
|
40
|
+
this.cp = cp;
|
41
|
+
cp.on('close', () => this.isOpen = false);
|
42
|
+
}
|
43
|
+
off(event, handler) {
|
29
44
|
switch (event) {
|
30
45
|
case 'message':
|
31
|
-
this.cp.
|
46
|
+
this.cp.off('message', handler);
|
32
47
|
break;
|
33
48
|
case 'open':
|
34
49
|
handler(null);
|
35
50
|
break;
|
36
51
|
case 'close':
|
37
|
-
this.cp.
|
52
|
+
this.cp.off('disconnect', handler);
|
38
53
|
break;
|
39
54
|
}
|
40
|
-
|
41
|
-
constructor(cp) {
|
42
|
-
this.cp = cp;
|
43
|
-
cp.on('close', () => this.isOpen = false);
|
44
|
-
}
|
45
|
-
off(event, handler) {
|
46
|
-
this.cp.off(event, handler);
|
55
|
+
return true;
|
47
56
|
}
|
48
57
|
pipe(socket) {
|
49
58
|
this.on('message', (message) => socket.send(message));
|
50
59
|
this.on('close', () => socket.close());
|
51
60
|
}
|
61
|
+
// _write(chunk: string | Buffer, encoding: string, callback: (error?: any) => void)
|
62
|
+
// {
|
63
|
+
// // The underlying source only deals with strings.
|
64
|
+
// if (Buffer.isBuffer(chunk))
|
65
|
+
// chunk = chunk.toString('utf8');
|
66
|
+
// if (this.cp.send)
|
67
|
+
// this.cp.send(chunk + '\n', callback);
|
68
|
+
// else
|
69
|
+
// callback(new Error('there is no send method on this process'));
|
70
|
+
// }
|
71
|
+
// _read()
|
72
|
+
// {
|
73
|
+
// }
|
74
|
+
hasListener(name) {
|
75
|
+
if (name === 'open')
|
76
|
+
return false;
|
77
|
+
return !!this.cp.listenerCount(name);
|
78
|
+
}
|
79
|
+
get definedEvents() {
|
80
|
+
return ['close', 'error', 'message'].filter(ev => this.hasListener(ev));
|
81
|
+
}
|
82
|
+
emit(event, ...args) {
|
83
|
+
throw new Error("Method not implemented.");
|
84
|
+
}
|
52
85
|
}
|
53
86
|
//# sourceMappingURL=messageport-adapter.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"messageport-adapter.js","sourceRoot":"","sources":["../../src/messageport-adapter.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"messageport-adapter.js","sourceRoot":"","sources":["../../src/messageport-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+F,oBA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AU;IACV,IAAI;IACJ,IAAI;IAGJ,WAAW,CAA8D,IAAU;QAE/E,IAAI,IAAI,KAAK,MAAM;YACf,OAAO,KAAK,CAAC;QACjB,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,aAAa;QAEb,OAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAW,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,IAAI,CAA6D,KAAa,EAAE,GAAG,IAAmD;QAElI,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CACJ"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Transform } from 'stream';
|
2
|
+
export declare class VirtualScrollPrefixer extends Transform {
|
3
|
+
private buffer;
|
4
|
+
private readonly maxLines;
|
5
|
+
private readonly prefixer;
|
6
|
+
constructor(prefix: string, options?: {
|
7
|
+
maxLines?: number;
|
8
|
+
useColors?: boolean;
|
9
|
+
});
|
10
|
+
_transform(chunk: Buffer | string, encoding: string, callback: () => void): void;
|
11
|
+
_flush(callback: () => void): void;
|
12
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { Transform } from 'stream';
|
2
|
+
import { NewLinePrefixer } from './new-line-prefixer.js';
|
3
|
+
export class VirtualScrollPrefixer extends Transform {
|
4
|
+
buffer = [];
|
5
|
+
maxLines;
|
6
|
+
prefixer;
|
7
|
+
constructor(prefix, options = {}) {
|
8
|
+
super();
|
9
|
+
this.maxLines = options.maxLines || 5;
|
10
|
+
this.prefixer = new NewLinePrefixer(prefix, { useColors: options.useColors });
|
11
|
+
}
|
12
|
+
_transform(chunk, encoding, callback) {
|
13
|
+
// Convert chunk to string if it's a buffer
|
14
|
+
const str = Buffer.isBuffer(chunk) ? chunk.toString() : chunk;
|
15
|
+
// Split the input into lines
|
16
|
+
const lines = str.split('\n');
|
17
|
+
// Process each line
|
18
|
+
lines.forEach((line, i) => {
|
19
|
+
if (line || i < lines.length - 1) { // Skip empty lines at the end
|
20
|
+
// Add the new line to the buffer
|
21
|
+
this.buffer.push(line);
|
22
|
+
// If buffer exceeds max lines, remove the oldest line
|
23
|
+
if (this.buffer.length > this.maxLines) {
|
24
|
+
this.buffer.shift();
|
25
|
+
}
|
26
|
+
// Clear the terminal and rewrite all lines
|
27
|
+
this.push('\x1b[' + this.maxLines + 'A\x1b[0G\x1b[0J'); // Move cursor up and clear screen below
|
28
|
+
// Write each line in the buffer
|
29
|
+
this.buffer.forEach(bufferedLine => {
|
30
|
+
const prefixed = new Promise((resolve) => {
|
31
|
+
this.prefixer._transform(bufferedLine, 'utf8', () => {
|
32
|
+
this.prefixer.once('data', (data) => {
|
33
|
+
resolve(data);
|
34
|
+
});
|
35
|
+
});
|
36
|
+
});
|
37
|
+
prefixed.then(data => this.push(data + '\n'));
|
38
|
+
});
|
39
|
+
}
|
40
|
+
});
|
41
|
+
callback();
|
42
|
+
}
|
43
|
+
_flush(callback) {
|
44
|
+
callback();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=virtual-scroll-prefixer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"virtual-scroll-prefixer.js","sourceRoot":"","sources":["../../src/virtual-scroll-prefixer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAExC,MAAM,GAAa,EAAE,CAAC;IACb,QAAQ,CAAS;IACjB,QAAQ,CAAkB;IAE3C,YAAY,MAAc,EAAE,UAAsD,EAAE;QAEhF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,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