@procwire/transport 1.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/LICENSE +21 -0
- package/README.md +844 -0
- package/dist/channel/builder.d.ts +68 -0
- package/dist/channel/builder.d.ts.map +1 -0
- package/dist/channel/builder.js +120 -0
- package/dist/channel/builder.js.map +1 -0
- package/dist/channel/index.d.ts +6 -0
- package/dist/channel/index.d.ts.map +1 -0
- package/dist/channel/index.js +6 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/quickstart.d.ts +94 -0
- package/dist/channel/quickstart.d.ts.map +1 -0
- package/dist/channel/quickstart.js +104 -0
- package/dist/channel/quickstart.js.map +1 -0
- package/dist/channel/request-channel.d.ts +119 -0
- package/dist/channel/request-channel.d.ts.map +1 -0
- package/dist/channel/request-channel.js +476 -0
- package/dist/channel/request-channel.js.map +1 -0
- package/dist/channel/types.d.ts +226 -0
- package/dist/channel/types.d.ts.map +1 -0
- package/dist/channel/types.js +2 -0
- package/dist/channel/types.js.map +1 -0
- package/dist/framing/index.d.ts +4 -0
- package/dist/framing/index.d.ts.map +1 -0
- package/dist/framing/index.js +4 -0
- package/dist/framing/index.js.map +1 -0
- package/dist/framing/length-prefixed.d.ts +55 -0
- package/dist/framing/length-prefixed.d.ts.map +1 -0
- package/dist/framing/length-prefixed.js +102 -0
- package/dist/framing/length-prefixed.js.map +1 -0
- package/dist/framing/line-delimited.d.ts +61 -0
- package/dist/framing/line-delimited.d.ts.map +1 -0
- package/dist/framing/line-delimited.js +94 -0
- package/dist/framing/line-delimited.js.map +1 -0
- package/dist/framing/types.d.ts +35 -0
- package/dist/framing/types.d.ts.map +1 -0
- package/dist/framing/types.js +2 -0
- package/dist/framing/types.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/process/handle.d.ts +64 -0
- package/dist/process/handle.d.ts.map +1 -0
- package/dist/process/handle.js +107 -0
- package/dist/process/handle.js.map +1 -0
- package/dist/process/index.d.ts +37 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/process/index.js +37 -0
- package/dist/process/index.js.map +1 -0
- package/dist/process/manager.d.ts +58 -0
- package/dist/process/manager.d.ts.map +1 -0
- package/dist/process/manager.js +360 -0
- package/dist/process/manager.js.map +1 -0
- package/dist/process/types.d.ts +322 -0
- package/dist/process/types.d.ts.map +1 -0
- package/dist/process/types.js +2 -0
- package/dist/process/types.js.map +1 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +6 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/jsonrpc.d.ts +146 -0
- package/dist/protocol/jsonrpc.d.ts.map +1 -0
- package/dist/protocol/jsonrpc.js +288 -0
- package/dist/protocol/jsonrpc.js.map +1 -0
- package/dist/protocol/simple.d.ts +139 -0
- package/dist/protocol/simple.d.ts.map +1 -0
- package/dist/protocol/simple.js +297 -0
- package/dist/protocol/simple.js.map +1 -0
- package/dist/protocol/types.d.ts +117 -0
- package/dist/protocol/types.d.ts.map +1 -0
- package/dist/protocol/types.js +2 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/serialization/index.d.ts +5 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +5 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/serialization/json.d.ts +66 -0
- package/dist/serialization/json.d.ts.map +1 -0
- package/dist/serialization/json.js +66 -0
- package/dist/serialization/json.js.map +1 -0
- package/dist/serialization/raw.d.ts +38 -0
- package/dist/serialization/raw.d.ts.map +1 -0
- package/dist/serialization/raw.js +41 -0
- package/dist/serialization/raw.js.map +1 -0
- package/dist/serialization/registry.d.ts +91 -0
- package/dist/serialization/registry.d.ts.map +1 -0
- package/dist/serialization/registry.js +119 -0
- package/dist/serialization/registry.js.map +1 -0
- package/dist/serialization/types.d.ts +27 -0
- package/dist/serialization/types.d.ts.map +1 -0
- package/dist/serialization/types.js +2 -0
- package/dist/serialization/types.js.map +1 -0
- package/dist/transport/factory.d.ts +139 -0
- package/dist/transport/factory.d.ts.map +1 -0
- package/dist/transport/factory.js +162 -0
- package/dist/transport/factory.js.map +1 -0
- package/dist/transport/index.d.ts +6 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +9 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/socket-server.d.ts +48 -0
- package/dist/transport/socket-server.d.ts.map +1 -0
- package/dist/transport/socket-server.js +215 -0
- package/dist/transport/socket-server.js.map +1 -0
- package/dist/transport/socket-transport.d.ts +67 -0
- package/dist/transport/socket-transport.d.ts.map +1 -0
- package/dist/transport/socket-transport.js +193 -0
- package/dist/transport/socket-transport.js.map +1 -0
- package/dist/transport/stdio-transport.d.ts +94 -0
- package/dist/transport/stdio-transport.d.ts.map +1 -0
- package/dist/transport/stdio-transport.js +234 -0
- package/dist/transport/stdio-transport.js.map +1 -0
- package/dist/transport/types.d.ts +131 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +2 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/utils/assert.d.ts +16 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +31 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/disposables.d.ts +38 -0
- package/dist/utils/disposables.d.ts.map +1 -0
- package/dist/utils/disposables.js +59 -0
- package/dist/utils/disposables.js.map +1 -0
- package/dist/utils/errors.d.ts +43 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +69 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/events.d.ts +58 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +95 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pipe-path.d.ts +48 -0
- package/dist/utils/pipe-path.d.ts.map +1 -0
- package/dist/utils/pipe-path.js +89 -0
- package/dist/utils/pipe-path.js.map +1 -0
- package/dist/utils/platform.d.ts +16 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +22 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/time.d.ts +38 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +55 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +85 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @procwire/transport
|
|
3
|
+
*
|
|
4
|
+
* Core IPC transport library with zero runtime dependencies.
|
|
5
|
+
* Provides modular, type-safe building blocks for inter-process communication.
|
|
6
|
+
*
|
|
7
|
+
* Architecture layers (bottom to top):
|
|
8
|
+
* - Transport: Raw byte transfer (stdio, pipes, sockets)
|
|
9
|
+
* - Framing: Message boundary detection
|
|
10
|
+
* - Serialization: Object <-> binary conversion
|
|
11
|
+
* - Protocol: Request/response messaging
|
|
12
|
+
* - Channel: High-level communication API
|
|
13
|
+
* - Process: Child process lifecycle management
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
// Core types
|
|
18
|
+
export * from "./transport/index.js";
|
|
19
|
+
export * from "./framing/index.js";
|
|
20
|
+
export * from "./serialization/index.js";
|
|
21
|
+
export * from "./protocol/index.js";
|
|
22
|
+
export * from "./channel/index.js";
|
|
23
|
+
export * from "./process/index.js";
|
|
24
|
+
// Utilities
|
|
25
|
+
export * from "./utils/index.js";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,aAAa;AACb,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AAEnC,YAAY;AACZ,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ProcessHandle as IProcessHandle, ProcessHandleEvents, ProcessState } from "./types.js";
|
|
2
|
+
import type { Channel } from "../channel/types.js";
|
|
3
|
+
import type { Unsubscribe } from "../utils/disposables.js";
|
|
4
|
+
/**
|
|
5
|
+
* Process handle implementation.
|
|
6
|
+
* Encapsulates a managed process and its communication channels.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ProcessHandle implements IProcessHandle {
|
|
9
|
+
private readonly _id;
|
|
10
|
+
private _pid;
|
|
11
|
+
private _state;
|
|
12
|
+
private readonly _controlChannel;
|
|
13
|
+
private readonly _dataChannel;
|
|
14
|
+
private readonly events;
|
|
15
|
+
constructor(id: string, pid: number | null, controlChannel: Channel, dataChannel?: Channel | null);
|
|
16
|
+
get id(): string;
|
|
17
|
+
get pid(): number | null;
|
|
18
|
+
get state(): ProcessState;
|
|
19
|
+
get controlChannel(): Channel;
|
|
20
|
+
get dataChannel(): Channel | null;
|
|
21
|
+
/**
|
|
22
|
+
* Updates process ID.
|
|
23
|
+
* @internal Used by ProcessManager
|
|
24
|
+
*/
|
|
25
|
+
setPid(pid: number | null): void;
|
|
26
|
+
/**
|
|
27
|
+
* Updates process state and emits state change event.
|
|
28
|
+
* @internal Used by ProcessManager
|
|
29
|
+
*/
|
|
30
|
+
setState(newState: ProcessState): void;
|
|
31
|
+
/**
|
|
32
|
+
* Sends a request via control channel.
|
|
33
|
+
*/
|
|
34
|
+
request(method: string, params?: unknown, timeout?: number): Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Sends a notification via control channel.
|
|
37
|
+
*/
|
|
38
|
+
notify(method: string, params?: unknown): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Sends a request via data channel.
|
|
41
|
+
* @throws {Error} if data channel is not available
|
|
42
|
+
*/
|
|
43
|
+
requestViaData(method: string, params?: unknown, timeout?: number): Promise<unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Closes the handle and its channels.
|
|
46
|
+
* Does not terminate the process.
|
|
47
|
+
*/
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Subscribes to handle events.
|
|
51
|
+
*/
|
|
52
|
+
on<K extends keyof ProcessHandleEvents>(event: K, handler: (data: ProcessHandleEvents[K]) => void): Unsubscribe;
|
|
53
|
+
/**
|
|
54
|
+
* Emits an exit event.
|
|
55
|
+
* @internal Used by ProcessManager
|
|
56
|
+
*/
|
|
57
|
+
emitExit(code: number | null, signal: string | null): void;
|
|
58
|
+
/**
|
|
59
|
+
* Emits an error event.
|
|
60
|
+
* @internal Used by ProcessManager
|
|
61
|
+
*/
|
|
62
|
+
emitError(error: Error): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/process/handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,IAAI,cAAc,EAC/B,mBAAmB,EACnB,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D;;;GAGG;AACH,qBAAa,aAAc,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiB;IAC9C,OAAO,CAAC,QA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,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAG9B"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { EventEmitter } from "../utils/events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Process handle implementation.
|
|
4
|
+
* Encapsulates a managed process and its communication channels.
|
|
5
|
+
*/
|
|
6
|
+
export class ProcessHandle {
|
|
7
|
+
_id;
|
|
8
|
+
_pid;
|
|
9
|
+
_state;
|
|
10
|
+
_controlChannel;
|
|
11
|
+
_dataChannel;
|
|
12
|
+
events = new EventEmitter();
|
|
13
|
+
constructor(id, pid, controlChannel, dataChannel = null) {
|
|
14
|
+
this._id = id;
|
|
15
|
+
this._pid = pid;
|
|
16
|
+
this._state = "starting";
|
|
17
|
+
this._controlChannel = controlChannel;
|
|
18
|
+
this._dataChannel = dataChannel;
|
|
19
|
+
}
|
|
20
|
+
get id() {
|
|
21
|
+
return this._id;
|
|
22
|
+
}
|
|
23
|
+
get pid() {
|
|
24
|
+
return this._pid;
|
|
25
|
+
}
|
|
26
|
+
get state() {
|
|
27
|
+
return this._state;
|
|
28
|
+
}
|
|
29
|
+
get controlChannel() {
|
|
30
|
+
return this._controlChannel;
|
|
31
|
+
}
|
|
32
|
+
get dataChannel() {
|
|
33
|
+
return this._dataChannel;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Updates process ID.
|
|
37
|
+
* @internal Used by ProcessManager
|
|
38
|
+
*/
|
|
39
|
+
setPid(pid) {
|
|
40
|
+
this._pid = pid;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Updates process state and emits state change event.
|
|
44
|
+
* @internal Used by ProcessManager
|
|
45
|
+
*/
|
|
46
|
+
setState(newState) {
|
|
47
|
+
if (newState === this._state) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const from = this._state;
|
|
51
|
+
this._state = newState;
|
|
52
|
+
this.events.emit("stateChange", { from, to: newState });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sends a request via control channel.
|
|
56
|
+
*/
|
|
57
|
+
async request(method, params, timeout) {
|
|
58
|
+
return this._controlChannel.request(method, params, timeout);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sends a notification via control channel.
|
|
62
|
+
*/
|
|
63
|
+
async notify(method, params) {
|
|
64
|
+
return this._controlChannel.notify(method, params);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Sends a request via data channel.
|
|
68
|
+
* @throws {Error} if data channel is not available
|
|
69
|
+
*/
|
|
70
|
+
async requestViaData(method, params, timeout) {
|
|
71
|
+
if (!this._dataChannel) {
|
|
72
|
+
throw new Error(`Data channel not available for process '${this._id}'`);
|
|
73
|
+
}
|
|
74
|
+
return this._dataChannel.request(method, params, timeout);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Closes the handle and its channels.
|
|
78
|
+
* Does not terminate the process.
|
|
79
|
+
*/
|
|
80
|
+
async close() {
|
|
81
|
+
await Promise.all([
|
|
82
|
+
this._controlChannel.close(),
|
|
83
|
+
this._dataChannel ? this._dataChannel.close() : Promise.resolve(),
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Subscribes to handle events.
|
|
88
|
+
*/
|
|
89
|
+
on(event, handler) {
|
|
90
|
+
return this.events.on(event, handler);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Emits an exit event.
|
|
94
|
+
* @internal Used by ProcessManager
|
|
95
|
+
*/
|
|
96
|
+
emitExit(code, signal) {
|
|
97
|
+
this.events.emit("exit", { code, signal });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Emits an error event.
|
|
101
|
+
* @internal Used by ProcessManager
|
|
102
|
+
*/
|
|
103
|
+
emitError(error) {
|
|
104
|
+
this.events.emit("error", error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
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MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,KAAY;QACpB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process management layer - manages child process lifecycle with restart policies.
|
|
3
|
+
*
|
|
4
|
+
* Key features:
|
|
5
|
+
* - Spawn and manage multiple child processes
|
|
6
|
+
* - Dual-channel architecture: control (stdio) + data (pipe/socket)
|
|
7
|
+
* - Automatic restart with exponential backoff
|
|
8
|
+
* - Graceful termination with force-kill fallback
|
|
9
|
+
* - Event-driven lifecycle management
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const manager = new ProcessManager({
|
|
14
|
+
* restartPolicy: {
|
|
15
|
+
* enabled: true,
|
|
16
|
+
* maxRestarts: 3,
|
|
17
|
+
* backoffMs: 1000,
|
|
18
|
+
* maxBackoffMs: 30000
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const handle = await manager.spawn('worker-1', {
|
|
23
|
+
* executablePath: 'node',
|
|
24
|
+
* args: ['worker.js'],
|
|
25
|
+
* dataChannel: { enabled: true }
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const result = await handle.request('compute', { task: 'heavy' });
|
|
29
|
+
* await manager.terminate('worker-1');
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @module process
|
|
33
|
+
*/
|
|
34
|
+
export { ProcessManager } from "./manager.js";
|
|
35
|
+
export { ProcessHandle } from "./handle.js";
|
|
36
|
+
export type { ProcessState, RestartPolicy, ChannelConfig, DataChannelConfig, SpawnOptions, ProcessManagerConfig, ProcessManagerEvents, ProcessHandleEvents, ProcessHandle as IProcessHandle, ProcessManager as IProcessManager, } from "./types.js";
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/process/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,YAAY,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,IAAI,cAAc,EAC/B,cAAc,IAAI,eAAe,GAClC,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process management layer - manages child process lifecycle with restart policies.
|
|
3
|
+
*
|
|
4
|
+
* Key features:
|
|
5
|
+
* - Spawn and manage multiple child processes
|
|
6
|
+
* - Dual-channel architecture: control (stdio) + data (pipe/socket)
|
|
7
|
+
* - Automatic restart with exponential backoff
|
|
8
|
+
* - Graceful termination with force-kill fallback
|
|
9
|
+
* - Event-driven lifecycle management
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const manager = new ProcessManager({
|
|
14
|
+
* restartPolicy: {
|
|
15
|
+
* enabled: true,
|
|
16
|
+
* maxRestarts: 3,
|
|
17
|
+
* backoffMs: 1000,
|
|
18
|
+
* maxBackoffMs: 30000
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* const handle = await manager.spawn('worker-1', {
|
|
23
|
+
* executablePath: 'node',
|
|
24
|
+
* args: ['worker.js'],
|
|
25
|
+
* dataChannel: { enabled: true }
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const result = await handle.request('compute', { task: 'heavy' });
|
|
29
|
+
* await manager.terminate('worker-1');
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @module process
|
|
33
|
+
*/
|
|
34
|
+
// Core classes
|
|
35
|
+
export { ProcessManager } from "./manager.js";
|
|
36
|
+
export { ProcessHandle } from "./handle.js";
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/process/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,eAAe;AACf,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ProcessManager as IProcessManager, ProcessManagerConfig, ProcessManagerEvents, SpawnOptions } from "./types.js";
|
|
2
|
+
import type { ProcessHandle as IProcessHandle } from "./types.js";
|
|
3
|
+
import type { Unsubscribe } from "../utils/disposables.js";
|
|
4
|
+
/**
|
|
5
|
+
* Process manager implementation.
|
|
6
|
+
* Manages the lifecycle of multiple child processes with restart capability.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ProcessManager implements IProcessManager {
|
|
9
|
+
private readonly config;
|
|
10
|
+
private readonly processes;
|
|
11
|
+
private readonly events;
|
|
12
|
+
constructor(config?: ProcessManagerConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Spawns a new managed process.
|
|
15
|
+
*/
|
|
16
|
+
spawn(id: string, options: SpawnOptions): Promise<IProcessHandle>;
|
|
17
|
+
/**
|
|
18
|
+
* Terminates a managed process.
|
|
19
|
+
*/
|
|
20
|
+
terminate(id: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Terminates all managed processes.
|
|
23
|
+
*/
|
|
24
|
+
terminateAll(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets a process handle by ID.
|
|
27
|
+
*/
|
|
28
|
+
getHandle(id: string): IProcessHandle | null;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a process is running.
|
|
31
|
+
*/
|
|
32
|
+
isRunning(id: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Subscribes to manager events.
|
|
35
|
+
*/
|
|
36
|
+
on<K extends keyof ProcessManagerEvents>(event: K, handler: (data: ProcessManagerEvents[K]) => void): Unsubscribe;
|
|
37
|
+
/**
|
|
38
|
+
* Handles process exit event.
|
|
39
|
+
*/
|
|
40
|
+
private handleProcessExit;
|
|
41
|
+
/**
|
|
42
|
+
* Restarts a crashed process.
|
|
43
|
+
*/
|
|
44
|
+
private restartProcess;
|
|
45
|
+
/**
|
|
46
|
+
* Cleans up process resources.
|
|
47
|
+
*/
|
|
48
|
+
private cleanupProcess;
|
|
49
|
+
/**
|
|
50
|
+
* Builds control channel from stdio transport.
|
|
51
|
+
*/
|
|
52
|
+
private buildControlChannel;
|
|
53
|
+
/**
|
|
54
|
+
* Builds data channel from pipe transport.
|
|
55
|
+
*/
|
|
56
|
+
private buildDataChannel;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/process/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,IAAI,eAAe,EACjC,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EAGb,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AA8B3D;;;GAGG;AACH,qBAAa,cAAe,YAAW,eAAe;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiC;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqC;IAC/D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;gBAEvD,MAAM,GAAE,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