fullnative 0.1.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 +23 -0
- package/LICENSE +21 -0
- package/README.md +161 -0
- package/dist/core/env/env.d.ts +34 -0
- package/dist/core/env/env.d.ts.map +1 -0
- package/dist/core/env/env.js +134 -0
- package/dist/core/env/env.js.map +1 -0
- package/dist/core/env/index.d.ts +10 -0
- package/dist/core/env/index.d.ts.map +1 -0
- package/dist/core/env/index.js +10 -0
- package/dist/core/env/index.js.map +1 -0
- package/dist/core/file/File.d.ts +246 -0
- package/dist/core/file/File.d.ts.map +1 -0
- package/dist/core/file/File.js +397 -0
- package/dist/core/file/File.js.map +1 -0
- package/dist/core/file/Folder.d.ts +235 -0
- package/dist/core/file/Folder.d.ts.map +1 -0
- package/dist/core/file/Folder.js +427 -0
- package/dist/core/file/Folder.js.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +6 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/process/Command.d.ts +94 -0
- package/dist/core/process/Command.d.ts.map +1 -0
- package/dist/core/process/Command.js +143 -0
- package/dist/core/process/Command.js.map +1 -0
- package/dist/core/process/LiveProcess.d.ts +134 -0
- package/dist/core/process/LiveProcess.d.ts.map +1 -0
- package/dist/core/process/LiveProcess.js +214 -0
- package/dist/core/process/LiveProcess.js.map +1 -0
- package/dist/core/process/Process.d.ts +108 -0
- package/dist/core/process/Process.d.ts.map +1 -0
- package/dist/core/process/Process.js +138 -0
- package/dist/core/process/Process.js.map +1 -0
- package/dist/core/process/ProcessError.d.ts +50 -0
- package/dist/core/process/ProcessError.d.ts.map +1 -0
- package/dist/core/process/ProcessError.js +62 -0
- package/dist/core/process/ProcessError.js.map +1 -0
- package/dist/core/process/Result.d.ts +61 -0
- package/dist/core/process/Result.d.ts.map +1 -0
- package/dist/core/process/Result.js +89 -0
- package/dist/core/process/Result.js.map +1 -0
- package/dist/core/process/index.d.ts +7 -0
- package/dist/core/process/index.d.ts.map +1 -0
- package/dist/core/process/index.js +6 -0
- package/dist/core/process/index.js.map +1 -0
- package/dist/core/process/types.d.ts +17 -0
- package/dist/core/process/types.d.ts.map +1 -0
- package/dist/core/process/types.js +2 -0
- package/dist/core/process/types.js.map +1 -0
- package/dist/core/shell/Job.d.ts +149 -0
- package/dist/core/shell/Job.d.ts.map +1 -0
- package/dist/core/shell/Job.js +218 -0
- package/dist/core/shell/Job.js.map +1 -0
- package/dist/core/shell/Shell.d.ts +275 -0
- package/dist/core/shell/Shell.d.ts.map +1 -0
- package/dist/core/shell/Shell.js +461 -0
- package/dist/core/shell/Shell.js.map +1 -0
- package/dist/core/shell/index.d.ts +4 -0
- package/dist/core/shell/index.d.ts.map +1 -0
- package/dist/core/shell/index.js +3 -0
- package/dist/core/shell/index.js.map +1 -0
- package/dist/core/shell/types.d.ts +30 -0
- package/dist/core/shell/types.d.ts.map +1 -0
- package/dist/core/shell/types.js +2 -0
- package/dist/core/shell/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Command } from "./Command.js";
|
|
2
|
+
/**
|
|
3
|
+
* Facade para ejecutar y manejar procesos nativos con una API cómoda.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const proc = new Process();
|
|
7
|
+
*
|
|
8
|
+
* // Ejecución simple
|
|
9
|
+
* const result = await proc.run("echo", "hola");
|
|
10
|
+
* console.log(result.stdout); // "hola\n"
|
|
11
|
+
*
|
|
12
|
+
* // Builder fluido
|
|
13
|
+
* const out = await proc.cmd("git")
|
|
14
|
+
* .withArgs("log", "--oneline")
|
|
15
|
+
* .in("/my/repo")
|
|
16
|
+
* .output();
|
|
17
|
+
*
|
|
18
|
+
* // Proceso interactivo
|
|
19
|
+
* const p = proc.spawn("node", "-i");
|
|
20
|
+
* p.sendLine("1 + 1");
|
|
21
|
+
* p.endInput();
|
|
22
|
+
* await p.wait();
|
|
23
|
+
*/
|
|
24
|
+
export class Process {
|
|
25
|
+
/**
|
|
26
|
+
* Crea un builder de comando (`Command`) sin ejecutarlo.
|
|
27
|
+
*
|
|
28
|
+
* @param command - Comando a ejecutar.
|
|
29
|
+
* @param args - Argumentos del comando.
|
|
30
|
+
* @returns Un nuevo `Command` listo para configurar y ejecutar.
|
|
31
|
+
*/
|
|
32
|
+
cmd(command, ...args) {
|
|
33
|
+
return new Command(command, args);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Ejecuta un comando, espera a que termine y devuelve el resultado.
|
|
37
|
+
*
|
|
38
|
+
* @param command - Comando a ejecutar.
|
|
39
|
+
* @param args - Argumentos del comando.
|
|
40
|
+
* @returns El `Result` de la ejecución.
|
|
41
|
+
*/
|
|
42
|
+
async run(command, ...args) {
|
|
43
|
+
return new Command(command, args).run();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Ejecuta un comando y devuelve solo stdout, con espacios en blanco
|
|
47
|
+
* eliminados de los extremos (trim).
|
|
48
|
+
*
|
|
49
|
+
* @param command - Comando a ejecutar.
|
|
50
|
+
* @param args - Argumentos del comando.
|
|
51
|
+
* @returns El stdout del comando ya trimado.
|
|
52
|
+
*/
|
|
53
|
+
async output(command, ...args) {
|
|
54
|
+
return (await this.run(command, ...args)).stdout.trim();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Ejecuta un script de shell interpretado por el shell del sistema
|
|
58
|
+
* (`/bin/sh` en Unix, `cmd.exe` en Windows) y espera a que termine.
|
|
59
|
+
*
|
|
60
|
+
* @param script - Script de shell a ejecutar.
|
|
61
|
+
* @param options - Opciones de ejecución del proceso.
|
|
62
|
+
* @returns El `Result` de la ejecución.
|
|
63
|
+
*/
|
|
64
|
+
async shell(script, options = {}) {
|
|
65
|
+
const isWin = process.platform === "win32";
|
|
66
|
+
const shell = isWin ? "cmd.exe" : "/bin/sh";
|
|
67
|
+
const flag = isWin ? "/c" : "-c";
|
|
68
|
+
return new Command(shell, [flag, script], options).run();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Inicia un proceso y devuelve un `LiveProcess` para interactuar en vivo.
|
|
72
|
+
*
|
|
73
|
+
* @param command - Comando a ejecutar.
|
|
74
|
+
* @param args - Argumentos del comando.
|
|
75
|
+
* @returns Un `LiveProcess` que envuelve el proceso hijo recién iniciado.
|
|
76
|
+
*/
|
|
77
|
+
spawn(command, ...args) {
|
|
78
|
+
return new Command(command, args).spawn();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Inicia un proceso con opciones de ejecución y devuelve un `LiveProcess`.
|
|
82
|
+
* La firma es *options-first*: las opciones se pasan antes que el comando.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Opciones de ejecución del proceso.
|
|
85
|
+
* @param command - Comando a ejecutar.
|
|
86
|
+
* @param args - Argumentos del comando.
|
|
87
|
+
* @returns Un `LiveProcess` que envuelve el proceso hijo recién iniciado.
|
|
88
|
+
*/
|
|
89
|
+
spawnWith(options, command, ...args) {
|
|
90
|
+
return new Command(command, args, options).spawn();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Ejecuta un script de shell interpretado por el shell del sistema
|
|
94
|
+
* (`/bin/sh` en Unix, `cmd.exe` en Windows) y devuelve un `LiveProcess`
|
|
95
|
+
* interactivo para comunicarse en vivo con el proceso.
|
|
96
|
+
*
|
|
97
|
+
* @param script - Script de shell a ejecutar.
|
|
98
|
+
* @param options - Opciones de ejecución del proceso.
|
|
99
|
+
* @returns Un `LiveProcess` que envuelve el proceso hijo recién iniciado.
|
|
100
|
+
*/
|
|
101
|
+
spawnScript(script, options = {}) {
|
|
102
|
+
const isWin = process.platform === "win32";
|
|
103
|
+
const shell = isWin ? "cmd.exe" : "/bin/sh";
|
|
104
|
+
const flag = isWin ? "/c" : "-c";
|
|
105
|
+
return new Command(shell, [flag, script], options).spawn();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Comprueba si un comando existe en el PATH del sistema.
|
|
109
|
+
* Usa `where` en Windows y `which` en Unix.
|
|
110
|
+
*
|
|
111
|
+
* @param command - Nombre del comando a buscar.
|
|
112
|
+
* @returns `true` si el comando existe y es ejecutable, `false` en caso contrario.
|
|
113
|
+
*/
|
|
114
|
+
async exists(command) {
|
|
115
|
+
const isWin = process.platform === "win32";
|
|
116
|
+
const check = isWin ? "where" : "which";
|
|
117
|
+
const result = await this.run(check, command);
|
|
118
|
+
return result.ok;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Devuelve la ruta completa del comando encontrado en el PATH, o `null`
|
|
122
|
+
* si no existe. Usa `where` en Windows y `which` en Unix; si hay múltiples
|
|
123
|
+
* resultados, devuelve el primero.
|
|
124
|
+
*
|
|
125
|
+
* @param command - Nombre del comando a buscar.
|
|
126
|
+
* @returns La ruta completa del comando, o `null` si no se encuentra.
|
|
127
|
+
*/
|
|
128
|
+
async which(command) {
|
|
129
|
+
const isWin = process.platform === "win32";
|
|
130
|
+
const check = isWin ? "where" : "which";
|
|
131
|
+
const result = await this.run(check, command);
|
|
132
|
+
if (!result.ok)
|
|
133
|
+
return null;
|
|
134
|
+
const path = result.stdout.trim().split(/\r?\n/)[0];
|
|
135
|
+
return path || null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=Process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Process.js","sourceRoot":"","sources":["../../../src/core/process/Process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAKvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,OAAO;IAClB;;;;;;OAMG;IACH,GAAG,CAAC,OAAe,EAAE,GAAG,IAAc;QACpC,OAAO,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-0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error estructurado para fallos de ejecución de procesos.
|
|
3
|
+
*
|
|
4
|
+
* Se lanza cuando un comando termina con código de salida != 0
|
|
5
|
+
* o cuando no se puede iniciar el proceso (ENOENT, EACCES, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* try {
|
|
9
|
+
* await proc.run("nonexistent-cmd");
|
|
10
|
+
* } catch (err) {
|
|
11
|
+
* if (err instanceof ProcessError) {
|
|
12
|
+
* console.log(err.command); // "nonexistent-cmd"
|
|
13
|
+
* console.log(err.kind); // "spawn" | "exit"
|
|
14
|
+
* console.log(err.exitCode); // null si fue spawn, number si fue exit
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export declare class ProcessError extends Error {
|
|
19
|
+
/** Comando que originó el error. */
|
|
20
|
+
readonly command: string;
|
|
21
|
+
/** Argumentos pasados al comando. */
|
|
22
|
+
readonly args: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Tipo de fallo: `"spawn"` si el proceso no pudo iniciarse (p. ej. ENOENT,
|
|
25
|
+
* EACCES) o `"exit"` si terminó con código de salida distinto de 0.
|
|
26
|
+
*/
|
|
27
|
+
readonly kind: "exit" | "spawn";
|
|
28
|
+
/** Código de salida del proceso; `null` si fue un fallo de spawn o terminó por señal. */
|
|
29
|
+
readonly exitCode: number | null;
|
|
30
|
+
/** Señal que terminó el proceso, o `null` si no fue por señal. */
|
|
31
|
+
readonly signal: NodeJS.Signals | null;
|
|
32
|
+
/** Salida de error (stderr) capturada, o cadena vacía si no hubo. */
|
|
33
|
+
readonly stderr: string;
|
|
34
|
+
/**
|
|
35
|
+
* Crea un `ProcessError`.
|
|
36
|
+
*
|
|
37
|
+
* @param command - Comando que originó el error.
|
|
38
|
+
* @param args - Argumentos pasados al comando.
|
|
39
|
+
* @param kind - Tipo de fallo: `"spawn"` o `"exit"`.
|
|
40
|
+
* @param options - Datos adicionales del fallo:
|
|
41
|
+
* `exitCode`, `signal`, `stderr` y `cause` (error nativo original).
|
|
42
|
+
*/
|
|
43
|
+
constructor(command: string, args: readonly string[], kind: "exit" | "spawn", options?: {
|
|
44
|
+
exitCode?: number | null;
|
|
45
|
+
signal?: NodeJS.Signals | null;
|
|
46
|
+
stderr?: string;
|
|
47
|
+
cause?: Error;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=ProcessError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessError.d.ts","sourceRoot":"","sources":["../../../src/core/process/ProcessError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IACvC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;;;;OAQG;gBAED,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,OAAO,GAAE;QACP,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,CAAC;KACV;CAuBT"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error estructurado para fallos de ejecución de procesos.
|
|
3
|
+
*
|
|
4
|
+
* Se lanza cuando un comando termina con código de salida != 0
|
|
5
|
+
* o cuando no se puede iniciar el proceso (ENOENT, EACCES, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* try {
|
|
9
|
+
* await proc.run("nonexistent-cmd");
|
|
10
|
+
* } catch (err) {
|
|
11
|
+
* if (err instanceof ProcessError) {
|
|
12
|
+
* console.log(err.command); // "nonexistent-cmd"
|
|
13
|
+
* console.log(err.kind); // "spawn" | "exit"
|
|
14
|
+
* console.log(err.exitCode); // null si fue spawn, number si fue exit
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export class ProcessError extends Error {
|
|
19
|
+
/** Comando que originó el error. */
|
|
20
|
+
command;
|
|
21
|
+
/** Argumentos pasados al comando. */
|
|
22
|
+
args;
|
|
23
|
+
/**
|
|
24
|
+
* Tipo de fallo: `"spawn"` si el proceso no pudo iniciarse (p. ej. ENOENT,
|
|
25
|
+
* EACCES) o `"exit"` si terminó con código de salida distinto de 0.
|
|
26
|
+
*/
|
|
27
|
+
kind;
|
|
28
|
+
/** Código de salida del proceso; `null` si fue un fallo de spawn o terminó por señal. */
|
|
29
|
+
exitCode;
|
|
30
|
+
/** Señal que terminó el proceso, o `null` si no fue por señal. */
|
|
31
|
+
signal;
|
|
32
|
+
/** Salida de error (stderr) capturada, o cadena vacía si no hubo. */
|
|
33
|
+
stderr;
|
|
34
|
+
/**
|
|
35
|
+
* Crea un `ProcessError`.
|
|
36
|
+
*
|
|
37
|
+
* @param command - Comando que originó el error.
|
|
38
|
+
* @param args - Argumentos pasados al comando.
|
|
39
|
+
* @param kind - Tipo de fallo: `"spawn"` o `"exit"`.
|
|
40
|
+
* @param options - Datos adicionales del fallo:
|
|
41
|
+
* `exitCode`, `signal`, `stderr` y `cause` (error nativo original).
|
|
42
|
+
*/
|
|
43
|
+
constructor(command, args, kind, options = {}) {
|
|
44
|
+
const exitCode = options.exitCode ?? null;
|
|
45
|
+
const signal = options.signal ?? null;
|
|
46
|
+
const stderr = options.stderr ?? "";
|
|
47
|
+
const detail = kind === "spawn"
|
|
48
|
+
? `failed to spawn: ${options.cause?.message ?? "unknown error"}`
|
|
49
|
+
: `exited with code ${exitCode}${signal ? ` (signal: ${signal})` : ""}`;
|
|
50
|
+
super(`Command "${command}" ${detail}${stderr ? `: ${stderr}` : ""}`, {
|
|
51
|
+
cause: options.cause,
|
|
52
|
+
});
|
|
53
|
+
this.name = "ProcessError";
|
|
54
|
+
this.command = command;
|
|
55
|
+
this.args = args;
|
|
56
|
+
this.kind = kind;
|
|
57
|
+
this.exitCode = exitCode;
|
|
58
|
+
this.signal = signal;
|
|
59
|
+
this.stderr = stderr;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=ProcessError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessError.js","sourceRoot":"","sources":["../../../src/core/process/ProcessError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,oCAAoC;IAC3B,OAAO,CAAS;IACzB,qCAAqC;IAC5B,IAAI,CAAoB;IACjC;;;OAGG;IACM,IAAI,CAAmB;IAChC,yFAAyF;IAChF,QAAQ,CAAgB;IACjC,kEAAkE;IACzD,MAAM,CAAwB;IACvC,qEAAqE;IAC5D,MAAM,CAAS;IAExB;;;;;;;;OAQG;IACH,YACE,OAAe,EACf,IAAuB,EACvB,IAAsB,EACtB,UAKI,EAAE;QAEN,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC;QAC1C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;QACtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;QAEpC,MAAM,MAAM,GACV,IAAI,KAAK,OAAO;YACd,CAAC,CAAC,oBAAoB,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE;YACjE,CAAC,CAAC,oBAAoB,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,aAAa,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAE5E,KAAK,CAAC,YAAY,OAAO,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE;YACpE,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resultado inmutable de una ejecución de comando que ya terminó.
|
|
3
|
+
*
|
|
4
|
+
* Contiene toda la información de la ejecución: stdout, stderr, código de
|
|
5
|
+
* salida, señal recibida y duración. Proporciona métodos utilitarios para
|
|
6
|
+
* inspeccionar y transformar el resultado.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Result {
|
|
9
|
+
readonly command: string;
|
|
10
|
+
readonly args: readonly string[];
|
|
11
|
+
readonly stdout: string;
|
|
12
|
+
readonly stderr: string;
|
|
13
|
+
readonly exitCode: number | null;
|
|
14
|
+
readonly signal: NodeJS.Signals | null;
|
|
15
|
+
readonly durationMs: number;
|
|
16
|
+
/**
|
|
17
|
+
* Crea un nuevo resultado de ejecución.
|
|
18
|
+
*
|
|
19
|
+
* @param command - Comando ejecutado.
|
|
20
|
+
* @param args - Argumentos pasados al comando.
|
|
21
|
+
* @param stdout - Salida estándar capturada como texto.
|
|
22
|
+
* @param stderr - Salida de error capturada como texto.
|
|
23
|
+
* @param exitCode - Código de salida del proceso (`null` si fue terminado por señal).
|
|
24
|
+
* @param signal - Señal que terminó el proceso, o `null` si terminó naturalmente.
|
|
25
|
+
* @param durationMs - Duración total de la ejecución en milisegundos.
|
|
26
|
+
*/
|
|
27
|
+
constructor(command: string, args: readonly string[], stdout: string, stderr: string, exitCode: number | null, signal: NodeJS.Signals | null, durationMs: number);
|
|
28
|
+
/** `true` si el proceso terminó con código de salida 0. */
|
|
29
|
+
get ok(): boolean;
|
|
30
|
+
/** `true` si el proceso terminó con código de salida distinto de 0. */
|
|
31
|
+
get failed(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Combina stdout y stderr en un solo string, eliminando espacios
|
|
34
|
+
* en blanco al final.
|
|
35
|
+
*/
|
|
36
|
+
get output(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Devuelve las líneas de stdout separadas por saltos de línea (`\n` o
|
|
39
|
+
* `\r\n`), excluyendo las líneas vacías.
|
|
40
|
+
*/
|
|
41
|
+
get lines(): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Parsea stdout como JSON y lo devuelve como tipo `T`.
|
|
44
|
+
*
|
|
45
|
+
* **Nota:** Esta función realiza un *cast* sin verificación de tipos en
|
|
46
|
+
* tiempo de ejecución. La validez del tipo `T` es responsabilidad del
|
|
47
|
+
* llamador; si la salida no es JSON válido, `JSON.parse` lanzará un
|
|
48
|
+
* `SyntaxError`.
|
|
49
|
+
*
|
|
50
|
+
* @returns El JSON parseado, con tipo `T` (por defecto `unknown`).
|
|
51
|
+
*/
|
|
52
|
+
json<T = unknown>(): T;
|
|
53
|
+
/**
|
|
54
|
+
* Lanza un `ProcessError` si el comando falló (código de salida != 0).
|
|
55
|
+
*
|
|
56
|
+
* @returns `this` si el comando fue exitoso, permitiendo encadenamiento.
|
|
57
|
+
* @throws {ProcessError} Cuando `failed` es `true`.
|
|
58
|
+
*/
|
|
59
|
+
throwIfFailed(): this;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=Result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../../src/core/process/Result.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,qBAAa,MAAM;aAaC,OAAO,EAAE,MAAM;aACf,IAAI,EAAE,SAAS,MAAM,EAAE;aACvB,MAAM,EAAE,MAAM;aACd,MAAM,EAAE,MAAM;aACd,QAAQ,EAAE,MAAM,GAAG,IAAI;aACvB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI;aAC7B,UAAU,EAAE,MAAM;IAlBpC;;;;;;;;;;OAUG;gBAEe,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,EAC7B,UAAU,EAAE,MAAM;IAGpC,2DAA2D;IAC3D,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED,uEAAuE;IACvE,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED;;;;;;;;;OASG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC;IAItB;;;;;OAKG;IACH,aAAa,IAAI,IAAI;CAUtB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ProcessError } from "./ProcessError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resultado inmutable de una ejecución de comando que ya terminó.
|
|
4
|
+
*
|
|
5
|
+
* Contiene toda la información de la ejecución: stdout, stderr, código de
|
|
6
|
+
* salida, señal recibida y duración. Proporciona métodos utilitarios para
|
|
7
|
+
* inspeccionar y transformar el resultado.
|
|
8
|
+
*/
|
|
9
|
+
export class Result {
|
|
10
|
+
command;
|
|
11
|
+
args;
|
|
12
|
+
stdout;
|
|
13
|
+
stderr;
|
|
14
|
+
exitCode;
|
|
15
|
+
signal;
|
|
16
|
+
durationMs;
|
|
17
|
+
/**
|
|
18
|
+
* Crea un nuevo resultado de ejecución.
|
|
19
|
+
*
|
|
20
|
+
* @param command - Comando ejecutado.
|
|
21
|
+
* @param args - Argumentos pasados al comando.
|
|
22
|
+
* @param stdout - Salida estándar capturada como texto.
|
|
23
|
+
* @param stderr - Salida de error capturada como texto.
|
|
24
|
+
* @param exitCode - Código de salida del proceso (`null` si fue terminado por señal).
|
|
25
|
+
* @param signal - Señal que terminó el proceso, o `null` si terminó naturalmente.
|
|
26
|
+
* @param durationMs - Duración total de la ejecución en milisegundos.
|
|
27
|
+
*/
|
|
28
|
+
constructor(command, args, stdout, stderr, exitCode, signal, durationMs) {
|
|
29
|
+
this.command = command;
|
|
30
|
+
this.args = args;
|
|
31
|
+
this.stdout = stdout;
|
|
32
|
+
this.stderr = stderr;
|
|
33
|
+
this.exitCode = exitCode;
|
|
34
|
+
this.signal = signal;
|
|
35
|
+
this.durationMs = durationMs;
|
|
36
|
+
}
|
|
37
|
+
/** `true` si el proceso terminó con código de salida 0. */
|
|
38
|
+
get ok() {
|
|
39
|
+
return this.exitCode === 0;
|
|
40
|
+
}
|
|
41
|
+
/** `true` si el proceso terminó con código de salida distinto de 0. */
|
|
42
|
+
get failed() {
|
|
43
|
+
return !this.ok;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Combina stdout y stderr en un solo string, eliminando espacios
|
|
47
|
+
* en blanco al final.
|
|
48
|
+
*/
|
|
49
|
+
get output() {
|
|
50
|
+
return (this.stdout + this.stderr).trimEnd();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Devuelve las líneas de stdout separadas por saltos de línea (`\n` o
|
|
54
|
+
* `\r\n`), excluyendo las líneas vacías.
|
|
55
|
+
*/
|
|
56
|
+
get lines() {
|
|
57
|
+
return this.stdout.split(/\r?\n/).filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parsea stdout como JSON y lo devuelve como tipo `T`.
|
|
61
|
+
*
|
|
62
|
+
* **Nota:** Esta función realiza un *cast* sin verificación de tipos en
|
|
63
|
+
* tiempo de ejecución. La validez del tipo `T` es responsabilidad del
|
|
64
|
+
* llamador; si la salida no es JSON válido, `JSON.parse` lanzará un
|
|
65
|
+
* `SyntaxError`.
|
|
66
|
+
*
|
|
67
|
+
* @returns El JSON parseado, con tipo `T` (por defecto `unknown`).
|
|
68
|
+
*/
|
|
69
|
+
json() {
|
|
70
|
+
return JSON.parse(this.stdout);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Lanza un `ProcessError` si el comando falló (código de salida != 0).
|
|
74
|
+
*
|
|
75
|
+
* @returns `this` si el comando fue exitoso, permitiendo encadenamiento.
|
|
76
|
+
* @throws {ProcessError} Cuando `failed` es `true`.
|
|
77
|
+
*/
|
|
78
|
+
throwIfFailed() {
|
|
79
|
+
if (this.failed) {
|
|
80
|
+
throw new ProcessError(this.command, this.args, "exit", {
|
|
81
|
+
exitCode: this.exitCode,
|
|
82
|
+
signal: this.signal,
|
|
83
|
+
stderr: this.stderr,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=Result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Result.js","sourceRoot":"","sources":["../../../src/core/process/Result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,OAAO,MAAM;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ACL,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Process } from "./Process.js";
|
|
2
|
+
export { Command } from "./Command.js";
|
|
3
|
+
export { LiveProcess } from "./LiveProcess.js";
|
|
4
|
+
export { Result } from "./Result.js";
|
|
5
|
+
export { ProcessError } from "./ProcessError.js";
|
|
6
|
+
export type { ProcessOptions } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SpawnOptions } from "node:child_process";
|
|
2
|
+
/**
|
|
3
|
+
* Opciones para construir un comando antes de ejecutarlo.
|
|
4
|
+
*
|
|
5
|
+
* Extiende las opciones nativas de `child_process.spawn` con campos
|
|
6
|
+
* adicionales para controlar timeout, entrada por stdin y comportamiento
|
|
7
|
+
* ante códigos de salida distintos de cero.
|
|
8
|
+
*/
|
|
9
|
+
export interface ProcessOptions extends SpawnOptions {
|
|
10
|
+
/** Tiempo máximo de ejecución en ms antes de matar el proceso automáticamente. */
|
|
11
|
+
timeout?: number;
|
|
12
|
+
/** Datos a enviar por stdin al proceso al iniciar la ejecución. */
|
|
13
|
+
input?: string | Buffer;
|
|
14
|
+
/** Si es `true`, lanza un `ProcessError` cuando el código de salida no es 0. */
|
|
15
|
+
rejectOnNonZero?: boolean;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/process/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,gFAAgF;IAChF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/process/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { LiveProcess, type Result } from "../process/index.js";
|
|
2
|
+
import type { JobOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Representa un proceso en segundo plano registrado en una sesión de `Shell`.
|
|
5
|
+
*
|
|
6
|
+
* A diferencia de un `LiveProcess` suelto, un `Job` tiene:
|
|
7
|
+
* - **`name`**: identificador para referenciarlo desde `Shell.jobs`.
|
|
8
|
+
* - **`autoRestart`**: se reinicia solo si el proceso muere.
|
|
9
|
+
* - **Lifecycle atado a la sesión**: `Shell.killAll()` lo mata automáticamente.
|
|
10
|
+
*
|
|
11
|
+
* Expone toda la API de `LiveProcess` (stdin/stdout/kill/wait/onOutput/etc.)
|
|
12
|
+
* más la gestión de reinicio y nombre.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Job {
|
|
15
|
+
/** Identificador del job en el registro de la sesión (`Shell.jobs`). */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** El `LiveProcess` subyacente que el job envuelve. */
|
|
18
|
+
readonly process: LiveProcess;
|
|
19
|
+
/** Script original que se ejecuta (tras resolver aliases). */
|
|
20
|
+
readonly script: string;
|
|
21
|
+
/** Si el proceso muere, se reinicia automáticamente. */
|
|
22
|
+
readonly autoRestart: boolean;
|
|
23
|
+
private _restartCount;
|
|
24
|
+
private readonly _onRestart;
|
|
25
|
+
private _disposed;
|
|
26
|
+
/**
|
|
27
|
+
* Crea un nuevo job a partir de un `LiveProcess`.
|
|
28
|
+
*
|
|
29
|
+
* @param process - El `LiveProcess` a envolver.
|
|
30
|
+
* @param script - Script que se ejecuta (para reinicios).
|
|
31
|
+
* @param options - Opciones del job (`name`, `autoRestart`).
|
|
32
|
+
*/
|
|
33
|
+
constructor(process: LiveProcess, script: string, options?: JobOptions);
|
|
34
|
+
/** PID del proceso subyacente, o `undefined` si aún no tiene. */
|
|
35
|
+
get pid(): number | undefined;
|
|
36
|
+
/** `true` si el proceso está en ejecución. */
|
|
37
|
+
get running(): boolean;
|
|
38
|
+
/** `true` si el proceso ya terminó. */
|
|
39
|
+
get ended(): boolean;
|
|
40
|
+
/** Código de salida del proceso (`null` si no terminó o fue por señal). */
|
|
41
|
+
get exitCode(): number | null;
|
|
42
|
+
/** `true` si el proceso fue detenido explícitamente (distingue kill vs salida natural). */
|
|
43
|
+
get stopped(): boolean;
|
|
44
|
+
/** Tiempo transcurrido desde el inicio, en milisegundos. */
|
|
45
|
+
get elapsed(): number;
|
|
46
|
+
/** Señal que terminó el proceso, o `null` si terminó naturalmente. */
|
|
47
|
+
get signal(): NodeJS.Signals | null;
|
|
48
|
+
/** Comando ejecutado. */
|
|
49
|
+
get command(): string;
|
|
50
|
+
/** Argumentos pasados al comando. */
|
|
51
|
+
get args(): readonly string[];
|
|
52
|
+
/** Fecha y hora de inicio del proceso. */
|
|
53
|
+
get startedAt(): Date;
|
|
54
|
+
/** Cantidad de veces que el job fue reiniciado vía `autoRestart`. */
|
|
55
|
+
get restartCount(): number;
|
|
56
|
+
/** Stream de entrada estándar del proceso. */
|
|
57
|
+
get stdin(): import("stream").Writable | null;
|
|
58
|
+
/** Stream de salida estándar del proceso. */
|
|
59
|
+
get stdout(): import("stream").Readable | null;
|
|
60
|
+
/** Stream de error estándar del proceso. */
|
|
61
|
+
get stderr(): import("stream").Readable | null;
|
|
62
|
+
/**
|
|
63
|
+
* Envía una señal al proceso y lo marca como dispuesto (no se reiniciará).
|
|
64
|
+
*
|
|
65
|
+
* @param signal - Señal a enviar (por defecto `SIGTERM`).
|
|
66
|
+
* @returns `true` si la señal fue entregada.
|
|
67
|
+
*/
|
|
68
|
+
kill(signal?: NodeJS.Signals): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Fuerza la terminación del proceso (SIGKILL) y lo marca como dispuesto.
|
|
71
|
+
*
|
|
72
|
+
* @returns `true` si la señal fue entregada.
|
|
73
|
+
*/
|
|
74
|
+
forceKill(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Escribe datos al stdin del proceso.
|
|
77
|
+
*
|
|
78
|
+
* @param data - Datos a escribir (string o Buffer).
|
|
79
|
+
* @returns `true` si se escribió correctamente.
|
|
80
|
+
*/
|
|
81
|
+
write(data: string | Buffer): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Escribe una línea al stdin del proceso (añade `\n`).
|
|
84
|
+
*
|
|
85
|
+
* @param line - Línea a escribir.
|
|
86
|
+
* @returns `true` si se escribió correctamente.
|
|
87
|
+
*/
|
|
88
|
+
sendLine(line: string): boolean;
|
|
89
|
+
/** Cierra el stdin del proceso. */
|
|
90
|
+
endInput(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Registra un callback para cada chunk de stdout.
|
|
93
|
+
*
|
|
94
|
+
* @param callback - Función a ejecutar con cada chunk.
|
|
95
|
+
* @returns `this` para encadenamiento.
|
|
96
|
+
*/
|
|
97
|
+
onStdout(callback: (chunk: Buffer) => void): this;
|
|
98
|
+
/**
|
|
99
|
+
* Registra un callback para cada chunk de stderr.
|
|
100
|
+
*
|
|
101
|
+
* @param callback - Función a ejecutar con cada chunk.
|
|
102
|
+
* @returns `this` para encadenamiento.
|
|
103
|
+
*/
|
|
104
|
+
onStderr(callback: (chunk: Buffer) => void): this;
|
|
105
|
+
/**
|
|
106
|
+
* Registra un callback para cada chunk de stdout o stderr (combinados).
|
|
107
|
+
*
|
|
108
|
+
* @param callback - Función a ejecutar con cada chunk.
|
|
109
|
+
* @returns `this` para encadenamiento.
|
|
110
|
+
*/
|
|
111
|
+
onOutput(callback: (chunk: Buffer) => void): this;
|
|
112
|
+
/**
|
|
113
|
+
* Registra un callback que se ejecuta cuando el proceso termina.
|
|
114
|
+
*
|
|
115
|
+
* @param callback - Función a ejecutar con el resultado.
|
|
116
|
+
* @returns `this` para encadenamiento.
|
|
117
|
+
*/
|
|
118
|
+
onExit(callback: (result: Result) => void): this;
|
|
119
|
+
/**
|
|
120
|
+
* Registra un callback que se ejecuta cuando el job se reinicia vía `autoRestart`.
|
|
121
|
+
*
|
|
122
|
+
* @param callback - Función a ejecutar con el job reiniciado.
|
|
123
|
+
* @returns `this` para encadenamiento.
|
|
124
|
+
*/
|
|
125
|
+
onRestart(callback: (job: Job) => void): this;
|
|
126
|
+
/**
|
|
127
|
+
* Espera a que el proceso termine y devuelve el resultado.
|
|
128
|
+
*
|
|
129
|
+
* @returns El resultado de la ejecución.
|
|
130
|
+
*/
|
|
131
|
+
wait(): Promise<Result>;
|
|
132
|
+
/**
|
|
133
|
+
* Alias de `wait()`. Espera a que el proceso termine y devuelve el resultado.
|
|
134
|
+
*
|
|
135
|
+
* @returns El resultado de la ejecución.
|
|
136
|
+
*/
|
|
137
|
+
result(): Promise<Result>;
|
|
138
|
+
/**
|
|
139
|
+
* Reemplaza el `LiveProcess` subyacente (interno, usado por `Shell` para `autoRestart`).
|
|
140
|
+
* Incrementa `restartCount` y dispara los callbacks registrados en `onRestart`.
|
|
141
|
+
*
|
|
142
|
+
* @internal
|
|
143
|
+
* @param process - El nuevo `LiveProcess` que reemplaza al actual.
|
|
144
|
+
*/
|
|
145
|
+
_replace(process: LiveProcess): void;
|
|
146
|
+
/** @internal Indica si el job fue dispuesto (no debe reiniciarse). */
|
|
147
|
+
get _disposed_(): boolean;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=Job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Job.d.ts","sourceRoot":"","sources":["../../../src/core/shell/Job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,qBAAa,GAAG;IACd,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsC;IACjE,OAAO,CAAC,SAAS,CAAS;IAE1B;;;;;;OAMG;gBAED,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,UAAe;IAQ1B,iEAAiE;IACjE,IAAI,GAAG,IAAI,MAA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