@goodbyenjn/utils 26.3.0 → 26.4.1

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/exec.d.ts ADDED
@@ -0,0 +1,129 @@
1
+ import { o as Nullable, p as TemplateFn, t as index_d_exports } from "./chunks/chunk-3c6f28c7.js";
2
+ import { i as Result } from "./chunks/chunk-bd9f56dd.js";
3
+ import { ChildProcess, SpawnOptions } from "node:child_process";
4
+ import { Readable } from "node:stream";
5
+
6
+ //#region src/exec/types.d.ts
7
+ type KillSignal = Parameters<ChildProcess["kill"]>[0];
8
+ interface Output {
9
+ stdout: string;
10
+ stderr: string;
11
+ exitCode: number | undefined;
12
+ }
13
+ interface BaseProcessOptions {
14
+ stdin: BaseProcessInstance | string;
15
+ signal: AbortSignal;
16
+ spawnOptions: SpawnOptions;
17
+ timeout: number;
18
+ persist: boolean;
19
+ throwOnError: boolean;
20
+ }
21
+ interface BaseProcessInstance extends PromiseLike<any>, AsyncIterable<any> {
22
+ get process(): ChildProcess | undefined;
23
+ get aborted(): boolean;
24
+ get killed(): boolean;
25
+ get pid(): number | undefined;
26
+ get exitCode(): number | undefined;
27
+ exec: (...params: any[]) => any;
28
+ pipe: (...params: any[]) => any;
29
+ kill: (signal?: KillSignal) => boolean;
30
+ }
31
+ type ExecParams = ExecSpawnParams | ExecCommandTemplateParams | ExecCommandStringParams | ExecFactoryParams;
32
+ type BaseExec = BaseExecSpawn & BaseExecCommandTemplate & BaseExecCommandString & BaseExecFactory;
33
+ type ExecSpawnParams = [command: string, args?: string[], options?: Partial<BaseProcessOptions>];
34
+ type BaseExecSpawn = (...params: ExecSpawnParams) => unknown;
35
+ type ExecCommandTemplateParams = Parameters<TemplateFn>;
36
+ type BaseExecCommandTemplate = (...params: ExecCommandTemplateParams) => unknown;
37
+ type ExecCommandStringParams = [command: string];
38
+ type BaseExecCommandString = (...params: ExecCommandStringParams) => unknown;
39
+ type ExecFactoryParams = [options: Partial<BaseProcessOptions>];
40
+ type BaseExecFactory = (...params: ExecFactoryParams) => BaseExecCommandTemplate & BaseExecCommandString;
41
+ //#endregion
42
+ //#region src/exec/error.d.ts
43
+ declare class NonZeroExitError extends Error {
44
+ static is(value: unknown): value is NonZeroExitError;
45
+ readonly result: BaseProcessInstance;
46
+ readonly output?: Output;
47
+ get exitCode(): number | undefined;
48
+ constructor(result: BaseProcessInstance, output?: Output);
49
+ }
50
+ //#endregion
51
+ //#region src/exec/process.d.ts
52
+ declare abstract class BaseProcess implements BaseProcessInstance {
53
+ protected static execImpl(self: BaseProcess, params: ExecParams): BaseExec;
54
+ protected _process: ChildProcess | undefined;
55
+ protected _aborted: boolean;
56
+ protected options: Partial<BaseProcessOptions>;
57
+ protected streamOut: Nullable<Readable>;
58
+ protected streamErr: Nullable<Readable>;
59
+ protected thrownError?: Error;
60
+ protected closeProcess: () => void;
61
+ protected processClosed: Promise<void>;
62
+ get process(): ChildProcess | undefined;
63
+ get aborted(): boolean;
64
+ get killed(): boolean;
65
+ get pid(): number | undefined;
66
+ get exitCode(): number | undefined;
67
+ constructor(options?: Partial<BaseProcessOptions>);
68
+ exec: any;
69
+ pipe: any;
70
+ kill(signal?: KillSignal): boolean;
71
+ then<TResult1 = any, TResult2 = never>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
72
+ protected spawn(command: string, args: string[]): this;
73
+ protected cleanup(): Promise<void>;
74
+ abstract [Symbol.asyncIterator](): AsyncIterator<any>;
75
+ protected abstract thenImpl(): Promise<any>;
76
+ protected abstract construct(): BaseProcess;
77
+ }
78
+ //#endregion
79
+ //#region src/exec/safe/types.d.ts
80
+ type ProcessOptions$1 = BaseProcessOptions & ExtendProcessOptions$1;
81
+ interface ExtendProcessOptions$1 {
82
+ stdin: ProcessInstance$1 | string;
83
+ }
84
+ type ProcessInstance$1 = BaseProcessInstance & ExtendProcessInstance$1;
85
+ interface ExtendProcessInstance$1 extends PromiseLike<Result<Output, Error>>, AsyncIterable<Result<string, Error>> {
86
+ exec: Exec$1;
87
+ pipe: Exec$1;
88
+ }
89
+ type Exec$1 = index_d_exports.SetReturnType<BaseExecSpawn, ProcessInstance$1> & index_d_exports.SetReturnType<BaseExecCommandTemplate, ProcessInstance$1> & index_d_exports.SetReturnType<BaseExecCommandString, ProcessInstance$1> & index_d_exports.SetReturnType<BaseExecFactory, index_d_exports.SetReturnType<BaseExecCommandTemplate, ProcessInstance$1> & index_d_exports.SetReturnType<BaseExecCommandString, ProcessInstance$1>>;
90
+ //#endregion
91
+ //#region src/exec/safe/index.d.ts
92
+ declare class Process$1 extends BaseProcess implements ProcessInstance$1 {
93
+ exec: Exec$1;
94
+ pipe: Exec$1;
95
+ protected options: Partial<ProcessOptions$1>;
96
+ constructor(options?: Partial<ProcessOptions$1>);
97
+ [Symbol.asyncIterator](): AsyncIterator<Result<string, Error>>;
98
+ protected thenImpl(): Promise<Result<Output, Error>>;
99
+ protected maybeThrow(output?: Output): Result<void, Error>;
100
+ protected construct(): Process$1;
101
+ }
102
+ declare const exec$1: Exec$1;
103
+ //#endregion
104
+ //#region src/exec/unsafe/types.d.ts
105
+ type ProcessOptions = BaseProcessOptions & ExtendProcessOptions;
106
+ interface ExtendProcessOptions {
107
+ stdin: ProcessInstance;
108
+ }
109
+ type ProcessInstance = BaseProcessInstance & ExtendProcessInstance;
110
+ interface ExtendProcessInstance extends PromiseLike<Output>, AsyncIterable<string> {
111
+ exec: Exec;
112
+ pipe: Exec;
113
+ }
114
+ type Exec = index_d_exports.SetReturnType<BaseExecSpawn, ProcessInstance> & index_d_exports.SetReturnType<BaseExecCommandTemplate, ProcessInstance> & index_d_exports.SetReturnType<BaseExecCommandString, ProcessInstance> & index_d_exports.SetReturnType<BaseExecFactory, index_d_exports.SetReturnType<BaseExecCommandTemplate, ProcessInstance> & index_d_exports.SetReturnType<BaseExecCommandString, ProcessInstance>>;
115
+ //#endregion
116
+ //#region src/exec/unsafe/index.d.ts
117
+ declare class Process extends BaseProcess implements ProcessInstance {
118
+ exec: Exec;
119
+ pipe: Exec;
120
+ protected options: Partial<ProcessOptions>;
121
+ constructor(options?: Partial<ProcessOptions>);
122
+ [Symbol.asyncIterator](): AsyncIterator<string>;
123
+ protected thenImpl(): Promise<Output>;
124
+ protected maybeThrow(output?: Output): void;
125
+ protected construct(): Process;
126
+ }
127
+ declare const exec: Exec;
128
+ //#endregion
129
+ export { type Exec, NonZeroExitError, type Output, Process, type ProcessInstance, type ProcessOptions, type Exec$1 as SafeExec, Process$1 as SafeProcess, type ProcessInstance$1 as SafeProcessInstance, type ProcessOptions$1 as SafeProcessOptions, exec, exec$1 as safeExec };