@orkestrel/process 0.0.10 → 0.0.11
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 +10 -21
- package/dist/src/core/index.cjs +18 -13
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +27 -18
- package/dist/src/core/index.d.ts +27 -18
- package/dist/src/core/index.js +18 -13
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +24 -9
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +57 -49
- package/dist/src/server/index.d.ts +57 -49
- package/dist/src/server/index.js +24 -9
- package/dist/src/server/index.js.map +1 -1
- package/package.json +8 -9
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import { Buffer as Buffer_2 } from 'node:buffer';
|
|
2
|
-
import { DetachOptions } from '@orkestrel/process';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
-
import { ExecutableOptions } from '@orkestrel/process';
|
|
5
|
-
import { ExecuteInput } from '@orkestrel/process';
|
|
6
|
-
import { ExecuteOptions } from '@orkestrel/process';
|
|
7
|
-
import { ExecuteResult } from '@orkestrel/process';
|
|
8
|
-
import { ExecuteSyncOptions } from '@orkestrel/process';
|
|
9
|
-
import { ProcessCommand } from '@orkestrel/process';
|
|
10
|
-
import { ProcessEventMap } from '@orkestrel/process';
|
|
11
|
-
import { ProcessExit } from '@orkestrel/process';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { Readable } from 'node:stream';
|
|
23
|
-
import { SessionEventMap } from '@orkestrel/process';
|
|
24
|
-
import { SessionInterface } from '@orkestrel/process';
|
|
25
|
-
import { SessionInterface as SessionInterface_2 } from '@orkestrel/process';
|
|
26
|
-
import { SessionOptions } from '@orkestrel/process';
|
|
27
|
-
import { SessionOptions as SessionOptions_2 } from '@orkestrel/process';
|
|
28
|
-
import { SpawnInput } from '@orkestrel/process';
|
|
2
|
+
import type { DetachOptions } from '@orkestrel/process';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
+
import type { ExecutableOptions } from '@orkestrel/process';
|
|
5
|
+
import type { ExecuteInput } from '@orkestrel/process';
|
|
6
|
+
import type { ExecuteOptions } from '@orkestrel/process';
|
|
7
|
+
import type { ExecuteResult } from '@orkestrel/process';
|
|
8
|
+
import type { ExecuteSyncOptions } from '@orkestrel/process';
|
|
9
|
+
import type { ProcessCommand } from '@orkestrel/process';
|
|
10
|
+
import type { ProcessEventMap } from '@orkestrel/process';
|
|
11
|
+
import type { ProcessExit } from '@orkestrel/process';
|
|
12
|
+
import type { ProcessInterface } from '@orkestrel/process';
|
|
13
|
+
import type { ProcessManagerEventMap } from '@orkestrel/process';
|
|
14
|
+
import type { ProcessManagerInterface } from '@orkestrel/process';
|
|
15
|
+
import type { ProcessManagerOptions } from '@orkestrel/process';
|
|
16
|
+
import type { ProcessOptions } from '@orkestrel/process';
|
|
17
|
+
import type { Readable } from 'node:stream';
|
|
18
|
+
import type { SessionEventMap } from '@orkestrel/process';
|
|
19
|
+
import type { SessionInterface } from '@orkestrel/process';
|
|
20
|
+
import type { SessionOptions } from '@orkestrel/process';
|
|
21
|
+
import type { SpawnInput } from '@orkestrel/process';
|
|
29
22
|
|
|
30
23
|
/**
|
|
31
24
|
* Builds the executable candidates an explicit platform would search.
|
|
@@ -151,26 +144,37 @@ export declare function buildSpawn(command: ProcessCommand, options?: Executable
|
|
|
151
144
|
export declare function captureChunk(chunk: unknown, room: number): Buffer_2 | undefined;
|
|
152
145
|
|
|
153
146
|
/**
|
|
154
|
-
* Creates one supervised child process
|
|
147
|
+
* Creates one supervised child process and returns it as a {@link ProcessInterface}, so a caller
|
|
148
|
+
* holds the published contract rather than the `Process` class.
|
|
155
149
|
*
|
|
156
150
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
157
151
|
* @returns The launched {@link ProcessInterface}
|
|
158
152
|
*
|
|
159
|
-
* @example
|
|
153
|
+
* @example Supervise a child and read its lines
|
|
160
154
|
* ```ts
|
|
161
155
|
* import { createProcess } from '@orkestrel/process/server'
|
|
162
156
|
*
|
|
163
157
|
* const child = createProcess({
|
|
164
|
-
* command: { file: 'node', arguments: ['
|
|
158
|
+
* command: { file: 'node', arguments: ['-e', 'console.log("ready"); console.log("done")'] },
|
|
165
159
|
* workspace: process.cwd(),
|
|
166
|
-
* grace:
|
|
160
|
+
* grace: 5_000, // POSIX only: the window between SIGTERM and SIGKILL
|
|
167
161
|
* })
|
|
162
|
+
*
|
|
163
|
+
* const lines: string[] = []
|
|
164
|
+
* for await (const line of child.lines) lines.push(line)
|
|
165
|
+
* lines // ['ready', 'done']
|
|
166
|
+
*
|
|
167
|
+
* const exit = await child.exit
|
|
168
|
+
* exit.code // 0
|
|
169
|
+
* await child.destroy()
|
|
168
170
|
* ```
|
|
169
171
|
*/
|
|
170
172
|
export declare function createProcess(options: ProcessOptions): ProcessInterface;
|
|
171
173
|
|
|
172
174
|
/**
|
|
173
|
-
* Creates one keyed registry of supervised child processes
|
|
175
|
+
* Creates one empty keyed registry of supervised child processes and returns it as a
|
|
176
|
+
* {@link ProcessManagerInterface}, so a caller holds the published contract rather than the
|
|
177
|
+
* `ProcessManager` class.
|
|
174
178
|
*
|
|
175
179
|
* @param options - Initial fleet-level observation hooks and listener-error handling
|
|
176
180
|
* @returns The {@link ProcessManagerInterface} registry
|
|
@@ -185,7 +189,8 @@ export declare function createProcess(options: ProcessOptions): ProcessInterface
|
|
|
185
189
|
export declare function createProcessManager(options?: ProcessManagerOptions): ProcessManagerInterface;
|
|
186
190
|
|
|
187
191
|
/**
|
|
188
|
-
* Creates one raw byte session over a supervised child process
|
|
192
|
+
* Creates one raw byte session over a supervised child process and returns it as a
|
|
193
|
+
* {@link SessionInterface}, so a caller holds the published contract rather than the `Session` class.
|
|
189
194
|
*
|
|
190
195
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
191
196
|
* @returns The launched {@link SessionInterface}
|
|
@@ -416,7 +421,8 @@ export declare function mergeEnvironment(isolated: boolean, base?: Readonly<Reco
|
|
|
416
421
|
export declare function mergePlatformEnvironment(platform: NodeJS.Platform, parent: Readonly<Record<string, string | undefined>>, isolated: boolean, base?: Readonly<Record<string, string | undefined>>, override?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
|
|
417
422
|
|
|
418
423
|
/**
|
|
419
|
-
* Supervises one child
|
|
424
|
+
* Supervises one child, frames its standard output into lines under a bounded backlog, and keeps
|
|
425
|
+
* every observation channel aligned at termination.
|
|
420
426
|
*
|
|
421
427
|
* @remarks
|
|
422
428
|
* The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
|
|
@@ -446,7 +452,7 @@ export declare function mergePlatformEnvironment(platform: NodeJS.Platform, pare
|
|
|
446
452
|
* await child.destroy()
|
|
447
453
|
* ```
|
|
448
454
|
*/
|
|
449
|
-
export declare class Process implements
|
|
455
|
+
export declare class Process implements ProcessInterface {
|
|
450
456
|
#private;
|
|
451
457
|
/**
|
|
452
458
|
* Spawns one child process and begins stream capture.
|
|
@@ -454,7 +460,7 @@ export declare class Process implements ProcessInterface_2 {
|
|
|
454
460
|
* @param options - Command, workspace, termination, capture, stdin, and observation settings
|
|
455
461
|
* @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
|
|
456
462
|
*/
|
|
457
|
-
constructor(options:
|
|
463
|
+
constructor(options: ProcessOptions);
|
|
458
464
|
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
459
465
|
get pid(): number | undefined;
|
|
460
466
|
/** Holds the exit code the host recorded, or `null` while the child has not exited and when a signal ended it. */
|
|
@@ -474,7 +480,7 @@ export declare class Process implements ProcessInterface_2 {
|
|
|
474
480
|
/** Reports whether termination began, including after the terminal moment. */
|
|
475
481
|
get stopping(): boolean;
|
|
476
482
|
/** Settles with the terminal child state, observed once after stream close or the drain cutoff. */
|
|
477
|
-
get exit(): Promise<
|
|
483
|
+
get exit(): Promise<ProcessExit>;
|
|
478
484
|
/**
|
|
479
485
|
* Writes one line to the open standard-input channel.
|
|
480
486
|
*
|
|
@@ -587,7 +593,8 @@ export declare interface ProcessChildInterface {
|
|
|
587
593
|
}
|
|
588
594
|
|
|
589
595
|
/**
|
|
590
|
-
*
|
|
596
|
+
* Launches supervised children under caller-chosen ids, evicts each one as it settles, and destroys
|
|
597
|
+
* every live child on teardown.
|
|
591
598
|
*
|
|
592
599
|
* @remarks
|
|
593
600
|
* A child launched under an id joins the registry and emits `launch`; when it settles it removes
|
|
@@ -615,14 +622,14 @@ export declare interface ProcessChildInterface {
|
|
|
615
622
|
* await manager.destroy()
|
|
616
623
|
* ```
|
|
617
624
|
*/
|
|
618
|
-
export declare class ProcessManager implements
|
|
625
|
+
export declare class ProcessManager implements ProcessManagerInterface {
|
|
619
626
|
#private;
|
|
620
627
|
/**
|
|
621
628
|
* Constructs a process registry.
|
|
622
629
|
*
|
|
623
630
|
* @param options - Initial fleet-level observation hooks and listener-error handling
|
|
624
631
|
*/
|
|
625
|
-
constructor(options?:
|
|
632
|
+
constructor(options?: ProcessManagerOptions);
|
|
626
633
|
/** Holds the typed fleet-level observation surface. */
|
|
627
634
|
get emitter(): EmitterInterface<ProcessManagerEventMap>;
|
|
628
635
|
/** Counts the live children. */
|
|
@@ -633,13 +640,13 @@ export declare class ProcessManager implements ProcessManagerInterface_2 {
|
|
|
633
640
|
* @param id - The registry key
|
|
634
641
|
* @returns The child, or `undefined`
|
|
635
642
|
*/
|
|
636
|
-
process(id: string):
|
|
643
|
+
process(id: string): ProcessInterface | undefined;
|
|
637
644
|
/**
|
|
638
645
|
* Returns a snapshot of every live child.
|
|
639
646
|
*
|
|
640
647
|
* @returns The live children in launch order
|
|
641
648
|
*/
|
|
642
|
-
processes(): readonly
|
|
649
|
+
processes(): readonly ProcessInterface[];
|
|
643
650
|
/**
|
|
644
651
|
* Spawns and registers one child under `id`.
|
|
645
652
|
*
|
|
@@ -657,7 +664,7 @@ export declare class ProcessManager implements ProcessManagerInterface_2 {
|
|
|
657
664
|
* @returns The launched child
|
|
658
665
|
* @throws A {@link ProcessError} coded `duplicate` when `id` is already live, `protocol` when the registry is being destroyed, or `invalid` when an option or command string is malformed
|
|
659
666
|
*/
|
|
660
|
-
launch(id: string, options:
|
|
667
|
+
launch(id: string, options: ProcessOptions): ProcessInterface;
|
|
661
668
|
/**
|
|
662
669
|
* Terminates the named children and awaits their exit.
|
|
663
670
|
*
|
|
@@ -745,7 +752,8 @@ export declare function readPlatformVariable(environment: Readonly<Record<string
|
|
|
745
752
|
export declare function readVariable(environment: Readonly<Record<string, string | undefined>>, name: string): string | undefined;
|
|
746
753
|
|
|
747
754
|
/**
|
|
748
|
-
* Resolves a command file to the executable path the host would launch
|
|
755
|
+
* Resolves a command file to the executable path the host would launch, or to `undefined` on a POSIX
|
|
756
|
+
* host, which performs its own lookup.
|
|
749
757
|
*
|
|
750
758
|
* @param file - The command executable name or path
|
|
751
759
|
* @param options - The directory searched first and the child's effective environment
|
|
@@ -789,7 +797,7 @@ export declare function resolveExecutable(file: string, options?: ExecutableOpti
|
|
|
789
797
|
* })
|
|
790
798
|
* ```
|
|
791
799
|
*/
|
|
792
|
-
export declare class Session implements
|
|
800
|
+
export declare class Session implements SessionInterface {
|
|
793
801
|
#private;
|
|
794
802
|
/**
|
|
795
803
|
* Spawns one child process and begins byte capture.
|
|
@@ -797,7 +805,7 @@ export declare class Session implements SessionInterface_2 {
|
|
|
797
805
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
798
806
|
* @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
|
|
799
807
|
*/
|
|
800
|
-
constructor(options:
|
|
808
|
+
constructor(options: SessionOptions);
|
|
801
809
|
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
802
810
|
get pid(): number | undefined;
|
|
803
811
|
/** Holds the exit code the host recorded, or `null` while the child has not exited and when a signal ended it. */
|
|
@@ -815,7 +823,7 @@ export declare class Session implements SessionInterface_2 {
|
|
|
815
823
|
/** Settles at the child's own ending, awaited without the terminal moment's drain window. */
|
|
816
824
|
get ending(): Promise<void>;
|
|
817
825
|
/** Settles with the terminal child state, observed once after stream close or the drain cutoff. */
|
|
818
|
-
get exit(): Promise<
|
|
826
|
+
get exit(): Promise<ProcessExit>;
|
|
819
827
|
/**
|
|
820
828
|
* Writes raw bytes to the open standard-input channel.
|
|
821
829
|
*
|
|
@@ -972,7 +980,7 @@ export declare class Supervisor {
|
|
|
972
980
|
* @param face - The composing face's callbacks for each lifecycle moment
|
|
973
981
|
* @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
|
|
974
982
|
*/
|
|
975
|
-
constructor(options:
|
|
983
|
+
constructor(options: ProcessOptions, face: SupervisorFace);
|
|
976
984
|
/** Holds the child's standard-output stream, for the composing face to attach its own consumer to. */
|
|
977
985
|
get stdout(): Readable;
|
|
978
986
|
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
@@ -997,7 +1005,7 @@ export declare class Supervisor {
|
|
|
997
1005
|
*/
|
|
998
1006
|
get ending(): Promise<void>;
|
|
999
1007
|
/** Settles with the terminal child state, observed once after stream close or the drain cutoff. */
|
|
1000
|
-
get exit(): Promise<
|
|
1008
|
+
get exit(): Promise<ProcessExit>;
|
|
1001
1009
|
/**
|
|
1002
1010
|
* Writes raw bytes to the open standard-input channel.
|
|
1003
1011
|
*
|
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import { Buffer as Buffer_2 } from 'node:buffer';
|
|
2
|
-
import { DetachOptions } from '@orkestrel/process';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
-
import { ExecutableOptions } from '@orkestrel/process';
|
|
5
|
-
import { ExecuteInput } from '@orkestrel/process';
|
|
6
|
-
import { ExecuteOptions } from '@orkestrel/process';
|
|
7
|
-
import { ExecuteResult } from '@orkestrel/process';
|
|
8
|
-
import { ExecuteSyncOptions } from '@orkestrel/process';
|
|
9
|
-
import { ProcessCommand } from '@orkestrel/process';
|
|
10
|
-
import { ProcessEventMap } from '@orkestrel/process';
|
|
11
|
-
import { ProcessExit } from '@orkestrel/process';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { Readable } from 'node:stream';
|
|
23
|
-
import { SessionEventMap } from '@orkestrel/process';
|
|
24
|
-
import { SessionInterface } from '@orkestrel/process';
|
|
25
|
-
import { SessionInterface as SessionInterface_2 } from '@orkestrel/process';
|
|
26
|
-
import { SessionOptions } from '@orkestrel/process';
|
|
27
|
-
import { SessionOptions as SessionOptions_2 } from '@orkestrel/process';
|
|
28
|
-
import { SpawnInput } from '@orkestrel/process';
|
|
2
|
+
import type { DetachOptions } from '@orkestrel/process';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
+
import type { ExecutableOptions } from '@orkestrel/process';
|
|
5
|
+
import type { ExecuteInput } from '@orkestrel/process';
|
|
6
|
+
import type { ExecuteOptions } from '@orkestrel/process';
|
|
7
|
+
import type { ExecuteResult } from '@orkestrel/process';
|
|
8
|
+
import type { ExecuteSyncOptions } from '@orkestrel/process';
|
|
9
|
+
import type { ProcessCommand } from '@orkestrel/process';
|
|
10
|
+
import type { ProcessEventMap } from '@orkestrel/process';
|
|
11
|
+
import type { ProcessExit } from '@orkestrel/process';
|
|
12
|
+
import type { ProcessInterface } from '@orkestrel/process';
|
|
13
|
+
import type { ProcessManagerEventMap } from '@orkestrel/process';
|
|
14
|
+
import type { ProcessManagerInterface } from '@orkestrel/process';
|
|
15
|
+
import type { ProcessManagerOptions } from '@orkestrel/process';
|
|
16
|
+
import type { ProcessOptions } from '@orkestrel/process';
|
|
17
|
+
import type { Readable } from 'node:stream';
|
|
18
|
+
import type { SessionEventMap } from '@orkestrel/process';
|
|
19
|
+
import type { SessionInterface } from '@orkestrel/process';
|
|
20
|
+
import type { SessionOptions } from '@orkestrel/process';
|
|
21
|
+
import type { SpawnInput } from '@orkestrel/process';
|
|
29
22
|
|
|
30
23
|
/**
|
|
31
24
|
* Builds the executable candidates an explicit platform would search.
|
|
@@ -151,26 +144,37 @@ export declare function buildSpawn(command: ProcessCommand, options?: Executable
|
|
|
151
144
|
export declare function captureChunk(chunk: unknown, room: number): Buffer_2 | undefined;
|
|
152
145
|
|
|
153
146
|
/**
|
|
154
|
-
* Creates one supervised child process
|
|
147
|
+
* Creates one supervised child process and returns it as a {@link ProcessInterface}, so a caller
|
|
148
|
+
* holds the published contract rather than the `Process` class.
|
|
155
149
|
*
|
|
156
150
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
157
151
|
* @returns The launched {@link ProcessInterface}
|
|
158
152
|
*
|
|
159
|
-
* @example
|
|
153
|
+
* @example Supervise a child and read its lines
|
|
160
154
|
* ```ts
|
|
161
155
|
* import { createProcess } from '@orkestrel/process/server'
|
|
162
156
|
*
|
|
163
157
|
* const child = createProcess({
|
|
164
|
-
* command: { file: 'node', arguments: ['
|
|
158
|
+
* command: { file: 'node', arguments: ['-e', 'console.log("ready"); console.log("done")'] },
|
|
165
159
|
* workspace: process.cwd(),
|
|
166
|
-
* grace:
|
|
160
|
+
* grace: 5_000, // POSIX only: the window between SIGTERM and SIGKILL
|
|
167
161
|
* })
|
|
162
|
+
*
|
|
163
|
+
* const lines: string[] = []
|
|
164
|
+
* for await (const line of child.lines) lines.push(line)
|
|
165
|
+
* lines // ['ready', 'done']
|
|
166
|
+
*
|
|
167
|
+
* const exit = await child.exit
|
|
168
|
+
* exit.code // 0
|
|
169
|
+
* await child.destroy()
|
|
168
170
|
* ```
|
|
169
171
|
*/
|
|
170
172
|
export declare function createProcess(options: ProcessOptions): ProcessInterface;
|
|
171
173
|
|
|
172
174
|
/**
|
|
173
|
-
* Creates one keyed registry of supervised child processes
|
|
175
|
+
* Creates one empty keyed registry of supervised child processes and returns it as a
|
|
176
|
+
* {@link ProcessManagerInterface}, so a caller holds the published contract rather than the
|
|
177
|
+
* `ProcessManager` class.
|
|
174
178
|
*
|
|
175
179
|
* @param options - Initial fleet-level observation hooks and listener-error handling
|
|
176
180
|
* @returns The {@link ProcessManagerInterface} registry
|
|
@@ -185,7 +189,8 @@ export declare function createProcess(options: ProcessOptions): ProcessInterface
|
|
|
185
189
|
export declare function createProcessManager(options?: ProcessManagerOptions): ProcessManagerInterface;
|
|
186
190
|
|
|
187
191
|
/**
|
|
188
|
-
* Creates one raw byte session over a supervised child process
|
|
192
|
+
* Creates one raw byte session over a supervised child process and returns it as a
|
|
193
|
+
* {@link SessionInterface}, so a caller holds the published contract rather than the `Session` class.
|
|
189
194
|
*
|
|
190
195
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
191
196
|
* @returns The launched {@link SessionInterface}
|
|
@@ -416,7 +421,8 @@ export declare function mergeEnvironment(isolated: boolean, base?: Readonly<Reco
|
|
|
416
421
|
export declare function mergePlatformEnvironment(platform: NodeJS.Platform, parent: Readonly<Record<string, string | undefined>>, isolated: boolean, base?: Readonly<Record<string, string | undefined>>, override?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
|
|
417
422
|
|
|
418
423
|
/**
|
|
419
|
-
* Supervises one child
|
|
424
|
+
* Supervises one child, frames its standard output into lines under a bounded backlog, and keeps
|
|
425
|
+
* every observation channel aligned at termination.
|
|
420
426
|
*
|
|
421
427
|
* @remarks
|
|
422
428
|
* The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
|
|
@@ -446,7 +452,7 @@ export declare function mergePlatformEnvironment(platform: NodeJS.Platform, pare
|
|
|
446
452
|
* await child.destroy()
|
|
447
453
|
* ```
|
|
448
454
|
*/
|
|
449
|
-
export declare class Process implements
|
|
455
|
+
export declare class Process implements ProcessInterface {
|
|
450
456
|
#private;
|
|
451
457
|
/**
|
|
452
458
|
* Spawns one child process and begins stream capture.
|
|
@@ -454,7 +460,7 @@ export declare class Process implements ProcessInterface_2 {
|
|
|
454
460
|
* @param options - Command, workspace, termination, capture, stdin, and observation settings
|
|
455
461
|
* @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
|
|
456
462
|
*/
|
|
457
|
-
constructor(options:
|
|
463
|
+
constructor(options: ProcessOptions);
|
|
458
464
|
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
459
465
|
get pid(): number | undefined;
|
|
460
466
|
/** Holds the exit code the host recorded, or `null` while the child has not exited and when a signal ended it. */
|
|
@@ -474,7 +480,7 @@ export declare class Process implements ProcessInterface_2 {
|
|
|
474
480
|
/** Reports whether termination began, including after the terminal moment. */
|
|
475
481
|
get stopping(): boolean;
|
|
476
482
|
/** Settles with the terminal child state, observed once after stream close or the drain cutoff. */
|
|
477
|
-
get exit(): Promise<
|
|
483
|
+
get exit(): Promise<ProcessExit>;
|
|
478
484
|
/**
|
|
479
485
|
* Writes one line to the open standard-input channel.
|
|
480
486
|
*
|
|
@@ -587,7 +593,8 @@ export declare interface ProcessChildInterface {
|
|
|
587
593
|
}
|
|
588
594
|
|
|
589
595
|
/**
|
|
590
|
-
*
|
|
596
|
+
* Launches supervised children under caller-chosen ids, evicts each one as it settles, and destroys
|
|
597
|
+
* every live child on teardown.
|
|
591
598
|
*
|
|
592
599
|
* @remarks
|
|
593
600
|
* A child launched under an id joins the registry and emits `launch`; when it settles it removes
|
|
@@ -615,14 +622,14 @@ export declare interface ProcessChildInterface {
|
|
|
615
622
|
* await manager.destroy()
|
|
616
623
|
* ```
|
|
617
624
|
*/
|
|
618
|
-
export declare class ProcessManager implements
|
|
625
|
+
export declare class ProcessManager implements ProcessManagerInterface {
|
|
619
626
|
#private;
|
|
620
627
|
/**
|
|
621
628
|
* Constructs a process registry.
|
|
622
629
|
*
|
|
623
630
|
* @param options - Initial fleet-level observation hooks and listener-error handling
|
|
624
631
|
*/
|
|
625
|
-
constructor(options?:
|
|
632
|
+
constructor(options?: ProcessManagerOptions);
|
|
626
633
|
/** Holds the typed fleet-level observation surface. */
|
|
627
634
|
get emitter(): EmitterInterface<ProcessManagerEventMap>;
|
|
628
635
|
/** Counts the live children. */
|
|
@@ -633,13 +640,13 @@ export declare class ProcessManager implements ProcessManagerInterface_2 {
|
|
|
633
640
|
* @param id - The registry key
|
|
634
641
|
* @returns The child, or `undefined`
|
|
635
642
|
*/
|
|
636
|
-
process(id: string):
|
|
643
|
+
process(id: string): ProcessInterface | undefined;
|
|
637
644
|
/**
|
|
638
645
|
* Returns a snapshot of every live child.
|
|
639
646
|
*
|
|
640
647
|
* @returns The live children in launch order
|
|
641
648
|
*/
|
|
642
|
-
processes(): readonly
|
|
649
|
+
processes(): readonly ProcessInterface[];
|
|
643
650
|
/**
|
|
644
651
|
* Spawns and registers one child under `id`.
|
|
645
652
|
*
|
|
@@ -657,7 +664,7 @@ export declare class ProcessManager implements ProcessManagerInterface_2 {
|
|
|
657
664
|
* @returns The launched child
|
|
658
665
|
* @throws A {@link ProcessError} coded `duplicate` when `id` is already live, `protocol` when the registry is being destroyed, or `invalid` when an option or command string is malformed
|
|
659
666
|
*/
|
|
660
|
-
launch(id: string, options:
|
|
667
|
+
launch(id: string, options: ProcessOptions): ProcessInterface;
|
|
661
668
|
/**
|
|
662
669
|
* Terminates the named children and awaits their exit.
|
|
663
670
|
*
|
|
@@ -745,7 +752,8 @@ export declare function readPlatformVariable(environment: Readonly<Record<string
|
|
|
745
752
|
export declare function readVariable(environment: Readonly<Record<string, string | undefined>>, name: string): string | undefined;
|
|
746
753
|
|
|
747
754
|
/**
|
|
748
|
-
* Resolves a command file to the executable path the host would launch
|
|
755
|
+
* Resolves a command file to the executable path the host would launch, or to `undefined` on a POSIX
|
|
756
|
+
* host, which performs its own lookup.
|
|
749
757
|
*
|
|
750
758
|
* @param file - The command executable name or path
|
|
751
759
|
* @param options - The directory searched first and the child's effective environment
|
|
@@ -789,7 +797,7 @@ export declare function resolveExecutable(file: string, options?: ExecutableOpti
|
|
|
789
797
|
* })
|
|
790
798
|
* ```
|
|
791
799
|
*/
|
|
792
|
-
export declare class Session implements
|
|
800
|
+
export declare class Session implements SessionInterface {
|
|
793
801
|
#private;
|
|
794
802
|
/**
|
|
795
803
|
* Spawns one child process and begins byte capture.
|
|
@@ -797,7 +805,7 @@ export declare class Session implements SessionInterface_2 {
|
|
|
797
805
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
798
806
|
* @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
|
|
799
807
|
*/
|
|
800
|
-
constructor(options:
|
|
808
|
+
constructor(options: SessionOptions);
|
|
801
809
|
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
802
810
|
get pid(): number | undefined;
|
|
803
811
|
/** Holds the exit code the host recorded, or `null` while the child has not exited and when a signal ended it. */
|
|
@@ -815,7 +823,7 @@ export declare class Session implements SessionInterface_2 {
|
|
|
815
823
|
/** Settles at the child's own ending, awaited without the terminal moment's drain window. */
|
|
816
824
|
get ending(): Promise<void>;
|
|
817
825
|
/** Settles with the terminal child state, observed once after stream close or the drain cutoff. */
|
|
818
|
-
get exit(): Promise<
|
|
826
|
+
get exit(): Promise<ProcessExit>;
|
|
819
827
|
/**
|
|
820
828
|
* Writes raw bytes to the open standard-input channel.
|
|
821
829
|
*
|
|
@@ -972,7 +980,7 @@ export declare class Supervisor {
|
|
|
972
980
|
* @param face - The composing face's callbacks for each lifecycle moment
|
|
973
981
|
* @throws A {@link ProcessError} coded `invalid` when an option or command string is malformed
|
|
974
982
|
*/
|
|
975
|
-
constructor(options:
|
|
983
|
+
constructor(options: ProcessOptions, face: SupervisorFace);
|
|
976
984
|
/** Holds the child's standard-output stream, for the composing face to attach its own consumer to. */
|
|
977
985
|
get stdout(): Readable;
|
|
978
986
|
/** Holds the host process id, fixed when construction returns, or `undefined` when the spawn produced none. */
|
|
@@ -997,7 +1005,7 @@ export declare class Supervisor {
|
|
|
997
1005
|
*/
|
|
998
1006
|
get ending(): Promise<void>;
|
|
999
1007
|
/** Settles with the terminal child state, observed once after stream close or the drain cutoff. */
|
|
1000
|
-
get exit(): Promise<
|
|
1008
|
+
get exit(): Promise<ProcessExit>;
|
|
1001
1009
|
/**
|
|
1002
1010
|
* Writes raw bytes to the open standard-input channel.
|
|
1003
1011
|
*
|
package/dist/src/server/index.js
CHANGED
|
@@ -306,7 +306,8 @@ function buildExecutableCandidates(file, workspace, environment, platform) {
|
|
|
306
306
|
return Object.freeze(targets);
|
|
307
307
|
}
|
|
308
308
|
/**
|
|
309
|
-
* Resolves a command file to the executable path the host would launch
|
|
309
|
+
* Resolves a command file to the executable path the host would launch, or to `undefined` on a POSIX
|
|
310
|
+
* host, which performs its own lookup.
|
|
310
311
|
*
|
|
311
312
|
* @param file - The command executable name or path
|
|
312
313
|
* @param options - The directory searched first and the child's effective environment
|
|
@@ -1445,7 +1446,8 @@ var Supervisor = class {
|
|
|
1445
1446
|
//#endregion
|
|
1446
1447
|
//#region src/server/processes/Process.ts
|
|
1447
1448
|
/**
|
|
1448
|
-
* Supervises one child
|
|
1449
|
+
* Supervises one child, frames its standard output into lines under a bounded backlog, and keeps
|
|
1450
|
+
* every observation channel aligned at termination.
|
|
1449
1451
|
*
|
|
1450
1452
|
* @remarks
|
|
1451
1453
|
* The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
|
|
@@ -1734,7 +1736,8 @@ var Process = class {
|
|
|
1734
1736
|
//#endregion
|
|
1735
1737
|
//#region src/server/processes/ProcessManager.ts
|
|
1736
1738
|
/**
|
|
1737
|
-
*
|
|
1739
|
+
* Launches supervised children under caller-chosen ids, evicts each one as it settles, and destroys
|
|
1740
|
+
* every live child on teardown.
|
|
1738
1741
|
*
|
|
1739
1742
|
* @remarks
|
|
1740
1743
|
* A child launched under an id joins the registry and emits `launch`; when it settles it removes
|
|
@@ -2080,27 +2083,37 @@ var Session = class {
|
|
|
2080
2083
|
//#endregion
|
|
2081
2084
|
//#region src/server/factories.ts
|
|
2082
2085
|
/**
|
|
2083
|
-
* Creates one supervised child process
|
|
2086
|
+
* Creates one supervised child process and returns it as a {@link ProcessInterface}, so a caller
|
|
2087
|
+
* holds the published contract rather than the `Process` class.
|
|
2084
2088
|
*
|
|
2085
2089
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
2086
2090
|
* @returns The launched {@link ProcessInterface}
|
|
2087
2091
|
*
|
|
2088
|
-
* @example
|
|
2092
|
+
* @example Supervise a child and read its lines
|
|
2089
2093
|
* ```ts
|
|
2090
2094
|
* import { createProcess } from '@orkestrel/process/server'
|
|
2091
2095
|
*
|
|
2092
2096
|
* const child = createProcess({
|
|
2093
|
-
* command: { file: 'node', arguments: ['
|
|
2097
|
+
* command: { file: 'node', arguments: ['-e', 'console.log("ready"); console.log("done")'] },
|
|
2094
2098
|
* workspace: process.cwd(),
|
|
2095
|
-
* grace:
|
|
2099
|
+
* grace: 5_000, // POSIX only: the window between SIGTERM and SIGKILL
|
|
2096
2100
|
* })
|
|
2101
|
+
*
|
|
2102
|
+
* const lines: string[] = []
|
|
2103
|
+
* for await (const line of child.lines) lines.push(line)
|
|
2104
|
+
* lines // ['ready', 'done']
|
|
2105
|
+
*
|
|
2106
|
+
* const exit = await child.exit
|
|
2107
|
+
* exit.code // 0
|
|
2108
|
+
* await child.destroy()
|
|
2097
2109
|
* ```
|
|
2098
2110
|
*/
|
|
2099
2111
|
function createProcess(options) {
|
|
2100
2112
|
return new Process(options);
|
|
2101
2113
|
}
|
|
2102
2114
|
/**
|
|
2103
|
-
* Creates one raw byte session over a supervised child process
|
|
2115
|
+
* Creates one raw byte session over a supervised child process and returns it as a
|
|
2116
|
+
* {@link SessionInterface}, so a caller holds the published contract rather than the `Session` class.
|
|
2104
2117
|
*
|
|
2105
2118
|
* @param options - Command, workspace, termination, evidence, stdin, and observation settings
|
|
2106
2119
|
* @returns The launched {@link SessionInterface}
|
|
@@ -2120,7 +2133,9 @@ function createSession(options) {
|
|
|
2120
2133
|
return new Session(options);
|
|
2121
2134
|
}
|
|
2122
2135
|
/**
|
|
2123
|
-
* Creates one keyed registry of supervised child processes
|
|
2136
|
+
* Creates one empty keyed registry of supervised child processes and returns it as a
|
|
2137
|
+
* {@link ProcessManagerInterface}, so a caller holds the published contract rather than the
|
|
2138
|
+
* `ProcessManager` class.
|
|
2124
2139
|
*
|
|
2125
2140
|
* @param options - Initial fleet-level observation hooks and listener-error handling
|
|
2126
2141
|
* @returns The {@link ProcessManagerInterface} registry
|