@decaf-ts/utils 1.1.0 → 1.2.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.
Files changed (94) hide show
  1. package/README.md +1 -1
  2. package/dist/utils.cjs +1 -1
  3. package/dist/utils.cjs.map +1 -1
  4. package/dist/utils.js +1 -1
  5. package/dist/utils.js.map +1 -1
  6. package/lib/cjs/cli/commands/build-scripts.cjs +87 -0
  7. package/lib/cjs/cli/commands/build-scripts.cjs.map +1 -1
  8. package/lib/cjs/index.cjs +1 -1
  9. package/lib/esm/cli/commands/build-scripts.js +87 -0
  10. package/lib/esm/cli/commands/build-scripts.js.map +1 -1
  11. package/lib/esm/index.js +1 -1
  12. package/lib/types/assets/slogans.d.cts +19 -0
  13. package/lib/types/assets/slogans.d.mts +19 -0
  14. package/lib/types/bin/build-scripts.d.cts +1 -0
  15. package/lib/types/bin/build-scripts.d.mts +1 -0
  16. package/lib/types/bin/release-chain-dispatch.d.cts +1 -0
  17. package/lib/types/bin/release-chain-dispatch.d.mts +1 -0
  18. package/lib/types/bin/release-chain.d.cts +1 -0
  19. package/lib/types/bin/release-chain.d.mts +1 -0
  20. package/lib/types/bin/tag-release.d.cts +1 -0
  21. package/lib/types/bin/tag-release.d.mts +1 -0
  22. package/lib/types/cli/command.d.cts +104 -0
  23. package/lib/types/cli/command.d.mts +104 -0
  24. package/lib/types/cli/commands/build-scripts.d.cts +148 -0
  25. package/lib/types/cli/commands/build-scripts.d.mts +148 -0
  26. package/lib/types/cli/commands/build-scripts.d.ts +3 -0
  27. package/lib/types/cli/commands/index.d.cts +3 -0
  28. package/lib/types/cli/commands/index.d.mts +3 -0
  29. package/lib/types/cli/commands/release-chain.d.cts +62 -0
  30. package/lib/types/cli/commands/release-chain.d.mts +62 -0
  31. package/lib/types/cli/commands/tag-release.d.cts +105 -0
  32. package/lib/types/cli/commands/tag-release.d.mts +105 -0
  33. package/lib/types/cli/constants.d.cts +75 -0
  34. package/lib/types/cli/constants.d.mts +75 -0
  35. package/lib/types/cli/index.d.cts +4 -0
  36. package/lib/types/cli/index.d.mts +4 -0
  37. package/lib/types/cli/types.d.cts +30 -0
  38. package/lib/types/cli/types.d.mts +30 -0
  39. package/lib/types/index.d.cts +38 -0
  40. package/lib/types/index.d.mts +38 -0
  41. package/lib/types/index.d.ts +1 -1
  42. package/lib/types/input/index.d.cts +2 -0
  43. package/lib/types/input/index.d.mts +2 -0
  44. package/lib/types/input/input.d.cts +517 -0
  45. package/lib/types/input/input.d.mts +517 -0
  46. package/lib/types/input/types.d.cts +159 -0
  47. package/lib/types/input/types.d.mts +159 -0
  48. package/lib/types/output/common.d.cts +53 -0
  49. package/lib/types/output/common.d.mts +53 -0
  50. package/lib/types/output/index.d.cts +1 -0
  51. package/lib/types/output/index.d.mts +1 -0
  52. package/lib/types/release-chain/index.d.cts +43 -0
  53. package/lib/types/release-chain/index.d.mts +43 -0
  54. package/lib/types/tests/Consumer.d.cts +151 -0
  55. package/lib/types/tests/Consumer.d.mts +151 -0
  56. package/lib/types/tests/ProducerChildProcess.d.cts +18 -0
  57. package/lib/types/tests/ProducerChildProcess.d.mts +18 -0
  58. package/lib/types/tests/TestReporter.d.cts +245 -0
  59. package/lib/types/tests/TestReporter.d.mts +245 -0
  60. package/lib/types/tests/index.d.cts +4 -0
  61. package/lib/types/tests/index.d.mts +4 -0
  62. package/lib/types/tests/jestPerformanceRunner.d.cts +37 -0
  63. package/lib/types/tests/jestPerformanceRunner.d.mts +37 -0
  64. package/lib/types/tests/utils.d.cts +5 -0
  65. package/lib/types/tests/utils.d.mts +5 -0
  66. package/lib/types/utils/constants.d.cts +65 -0
  67. package/lib/types/utils/constants.d.mts +65 -0
  68. package/lib/types/utils/fs.d.cts +259 -0
  69. package/lib/types/utils/fs.d.mts +259 -0
  70. package/lib/types/utils/http.d.cts +41 -0
  71. package/lib/types/utils/http.d.mts +41 -0
  72. package/lib/types/utils/index.d.cts +6 -0
  73. package/lib/types/utils/index.d.mts +6 -0
  74. package/lib/types/utils/md.d.cts +156 -0
  75. package/lib/types/utils/md.d.mts +156 -0
  76. package/lib/types/utils/performanceRunner.d.cts +129 -0
  77. package/lib/types/utils/performanceRunner.d.mts +129 -0
  78. package/lib/types/utils/timeout.d.cts +12 -0
  79. package/lib/types/utils/timeout.d.mts +12 -0
  80. package/lib/types/utils/types.d.cts +112 -0
  81. package/lib/types/utils/types.d.mts +112 -0
  82. package/lib/types/utils/utils.d.cts +133 -0
  83. package/lib/types/utils/utils.d.mts +133 -0
  84. package/lib/types/writers/OutputWriter.d.cts +49 -0
  85. package/lib/types/writers/OutputWriter.d.mts +49 -0
  86. package/lib/types/writers/RegexpOutputWriter.d.cts +110 -0
  87. package/lib/types/writers/RegexpOutputWriter.d.mts +110 -0
  88. package/lib/types/writers/StandardOutputWriter.d.cts +130 -0
  89. package/lib/types/writers/StandardOutputWriter.d.mts +130 -0
  90. package/lib/types/writers/index.d.cts +4 -0
  91. package/lib/types/writers/index.d.mts +4 -0
  92. package/lib/types/writers/types.d.cts +29 -0
  93. package/lib/types/writers/types.d.mts +29 -0
  94. package/package.json +14 -8
@@ -0,0 +1,110 @@
1
+ import { StandardOutputWriter } from "./StandardOutputWriter.cjs";
2
+ import { PromiseExecutor } from "../utils/types.cjs";
3
+ /**
4
+ * @description A specialized output writer that uses regular expressions to process output.
5
+ * @summary This class extends StandardOutputWriter to provide regex-based output processing.
6
+ * It allows for pattern matching in the output stream and can trigger specific actions
7
+ * based on matched patterns.
8
+ *
9
+ * @template T - The type of the resolved value, defaulting to string.
10
+ *
11
+ * @param cmd - The command string to be executed.
12
+ * @param lock - A PromiseExecutor to control the asynchronous flow.
13
+ * @param regexp - A string or RegExp to match against the output.
14
+ * @param flags - Optional flags for the RegExp constructor, defaults to "g".
15
+ *
16
+ * @class
17
+ * @example
18
+ * ```typescript
19
+ * import { RegexpOutputWriter } from '@decaf-ts/utils';
20
+ * import { PromiseExecutor } from '@decaf-ts/utils';
21
+ *
22
+ * // Create a promise executor
23
+ * const executor: PromiseExecutor<string, Error> = {
24
+ * resolve: (value) => console.log(`Resolved: ${value}`),
25
+ * reject: (error) => console.error(`Rejected: ${error.message}`)
26
+ * };
27
+ *
28
+ * // Create a regexp output writer that matches version numbers
29
+ * const writer = new RegexpOutputWriter('node --version', executor, /v(\d+\.\d+\.\d+)/);
30
+ *
31
+ * // Use the writer to handle command output
32
+ * writer.data('v14.17.0'); // This will automatically resolve with "v14.17.0"
33
+ * ```
34
+ *
35
+ * @mermaid
36
+ * sequenceDiagram
37
+ * participant Client
38
+ * participant RegexpOutputWriter
39
+ * participant StandardOutputWriter
40
+ * participant Logger
41
+ *
42
+ * Client->>RegexpOutputWriter: new RegexpOutputWriter(cmd, lock, regexp, flags)
43
+ * RegexpOutputWriter->>StandardOutputWriter: super(cmd, lock)
44
+ * StandardOutputWriter->>Logger: Logging.for(cmd)
45
+ * RegexpOutputWriter->>RegexpOutputWriter: compile regexp
46
+ *
47
+ * Client->>RegexpOutputWriter: data(chunk)
48
+ * RegexpOutputWriter->>StandardOutputWriter: super.data(chunk)
49
+ * StandardOutputWriter->>Logger: logger.info(log)
50
+ * RegexpOutputWriter->>RegexpOutputWriter: testAndResolve(chunk)
51
+ * RegexpOutputWriter->>RegexpOutputWriter: test(chunk)
52
+ * alt match found
53
+ * RegexpOutputWriter->>RegexpOutputWriter: resolve(match[0])
54
+ * RegexpOutputWriter->>StandardOutputWriter: resolve(match[0])
55
+ * end
56
+ *
57
+ * Client->>RegexpOutputWriter: error(chunk)
58
+ * RegexpOutputWriter->>StandardOutputWriter: super.error(chunk)
59
+ * StandardOutputWriter->>Logger: logger.info(log)
60
+ * RegexpOutputWriter->>RegexpOutputWriter: testAndReject(chunk)
61
+ * RegexpOutputWriter->>RegexpOutputWriter: test(chunk)
62
+ * alt match found
63
+ * RegexpOutputWriter->>RegexpOutputWriter: reject(match[0])
64
+ * RegexpOutputWriter->>StandardOutputWriter: reject(match[0])
65
+ * end
66
+ */
67
+ export declare class RegexpOutputWriter extends StandardOutputWriter<string> {
68
+ /**
69
+ * @description The regular expression used for matching output.
70
+ * @summary This readonly property stores the compiled RegExp used for pattern matching.
71
+ */
72
+ protected readonly regexp: RegExp;
73
+ constructor(cmd: string, lock: PromiseExecutor<string, Error>, regexp: string | RegExp, flags?: string);
74
+ /**
75
+ * @description Tests the input data against the stored regular expression.
76
+ * @summary Executes the regular expression on the input data and returns the match result.
77
+ *
78
+ * @param data - The string to test against the regular expression.
79
+ * @return The result of the regular expression execution, or undefined if an error occurs.
80
+ */
81
+ private test;
82
+ /**
83
+ * @description Tests the data and resolves the promise if a match is found.
84
+ * @summary Executes the test method and resolves the promise with the first match group if successful.
85
+ *
86
+ * @param data - The string to test against the regular expression.
87
+ */
88
+ protected testAndResolve(data: string): void;
89
+ /**
90
+ * @description Tests the data and rejects the promise if a match is found.
91
+ * @summary Executes the test method and rejects the promise with the first match group if successful.
92
+ *
93
+ * @param data - The string to test against the regular expression.
94
+ */
95
+ protected testAndReject(data: string): void;
96
+ /**
97
+ * @description Processes incoming data chunks.
98
+ * @summary Calls the parent class data method and then tests the data for a match to potentially resolve the promise.
99
+ *
100
+ * @param chunk - The data chunk to process.
101
+ */
102
+ data(chunk: any): void;
103
+ /**
104
+ * @description Processes incoming error chunks.
105
+ * @summary Calls the parent class error method and then tests the data for a match to potentially reject the promise.
106
+ *
107
+ * @param chunk - The error chunk to process.
108
+ */
109
+ error(chunk: any): void;
110
+ }
@@ -0,0 +1,110 @@
1
+ import { StandardOutputWriter } from "./StandardOutputWriter.js";
2
+ import { PromiseExecutor } from "../utils/types.js";
3
+ /**
4
+ * @description A specialized output writer that uses regular expressions to process output.
5
+ * @summary This class extends StandardOutputWriter to provide regex-based output processing.
6
+ * It allows for pattern matching in the output stream and can trigger specific actions
7
+ * based on matched patterns.
8
+ *
9
+ * @template T - The type of the resolved value, defaulting to string.
10
+ *
11
+ * @param cmd - The command string to be executed.
12
+ * @param lock - A PromiseExecutor to control the asynchronous flow.
13
+ * @param regexp - A string or RegExp to match against the output.
14
+ * @param flags - Optional flags for the RegExp constructor, defaults to "g".
15
+ *
16
+ * @class
17
+ * @example
18
+ * ```typescript
19
+ * import { RegexpOutputWriter } from '@decaf-ts/utils';
20
+ * import { PromiseExecutor } from '@decaf-ts/utils';
21
+ *
22
+ * // Create a promise executor
23
+ * const executor: PromiseExecutor<string, Error> = {
24
+ * resolve: (value) => console.log(`Resolved: ${value}`),
25
+ * reject: (error) => console.error(`Rejected: ${error.message}`)
26
+ * };
27
+ *
28
+ * // Create a regexp output writer that matches version numbers
29
+ * const writer = new RegexpOutputWriter('node --version', executor, /v(\d+\.\d+\.\d+)/);
30
+ *
31
+ * // Use the writer to handle command output
32
+ * writer.data('v14.17.0'); // This will automatically resolve with "v14.17.0"
33
+ * ```
34
+ *
35
+ * @mermaid
36
+ * sequenceDiagram
37
+ * participant Client
38
+ * participant RegexpOutputWriter
39
+ * participant StandardOutputWriter
40
+ * participant Logger
41
+ *
42
+ * Client->>RegexpOutputWriter: new RegexpOutputWriter(cmd, lock, regexp, flags)
43
+ * RegexpOutputWriter->>StandardOutputWriter: super(cmd, lock)
44
+ * StandardOutputWriter->>Logger: Logging.for(cmd)
45
+ * RegexpOutputWriter->>RegexpOutputWriter: compile regexp
46
+ *
47
+ * Client->>RegexpOutputWriter: data(chunk)
48
+ * RegexpOutputWriter->>StandardOutputWriter: super.data(chunk)
49
+ * StandardOutputWriter->>Logger: logger.info(log)
50
+ * RegexpOutputWriter->>RegexpOutputWriter: testAndResolve(chunk)
51
+ * RegexpOutputWriter->>RegexpOutputWriter: test(chunk)
52
+ * alt match found
53
+ * RegexpOutputWriter->>RegexpOutputWriter: resolve(match[0])
54
+ * RegexpOutputWriter->>StandardOutputWriter: resolve(match[0])
55
+ * end
56
+ *
57
+ * Client->>RegexpOutputWriter: error(chunk)
58
+ * RegexpOutputWriter->>StandardOutputWriter: super.error(chunk)
59
+ * StandardOutputWriter->>Logger: logger.info(log)
60
+ * RegexpOutputWriter->>RegexpOutputWriter: testAndReject(chunk)
61
+ * RegexpOutputWriter->>RegexpOutputWriter: test(chunk)
62
+ * alt match found
63
+ * RegexpOutputWriter->>RegexpOutputWriter: reject(match[0])
64
+ * RegexpOutputWriter->>StandardOutputWriter: reject(match[0])
65
+ * end
66
+ */
67
+ export declare class RegexpOutputWriter extends StandardOutputWriter<string> {
68
+ /**
69
+ * @description The regular expression used for matching output.
70
+ * @summary This readonly property stores the compiled RegExp used for pattern matching.
71
+ */
72
+ protected readonly regexp: RegExp;
73
+ constructor(cmd: string, lock: PromiseExecutor<string, Error>, regexp: string | RegExp, flags?: string);
74
+ /**
75
+ * @description Tests the input data against the stored regular expression.
76
+ * @summary Executes the regular expression on the input data and returns the match result.
77
+ *
78
+ * @param data - The string to test against the regular expression.
79
+ * @return The result of the regular expression execution, or undefined if an error occurs.
80
+ */
81
+ private test;
82
+ /**
83
+ * @description Tests the data and resolves the promise if a match is found.
84
+ * @summary Executes the test method and resolves the promise with the first match group if successful.
85
+ *
86
+ * @param data - The string to test against the regular expression.
87
+ */
88
+ protected testAndResolve(data: string): void;
89
+ /**
90
+ * @description Tests the data and rejects the promise if a match is found.
91
+ * @summary Executes the test method and rejects the promise with the first match group if successful.
92
+ *
93
+ * @param data - The string to test against the regular expression.
94
+ */
95
+ protected testAndReject(data: string): void;
96
+ /**
97
+ * @description Processes incoming data chunks.
98
+ * @summary Calls the parent class data method and then tests the data for a match to potentially resolve the promise.
99
+ *
100
+ * @param chunk - The data chunk to process.
101
+ */
102
+ data(chunk: any): void;
103
+ /**
104
+ * @description Processes incoming error chunks.
105
+ * @summary Calls the parent class error method and then tests the data for a match to potentially reject the promise.
106
+ *
107
+ * @param chunk - The error chunk to process.
108
+ */
109
+ error(chunk: any): void;
110
+ }
@@ -0,0 +1,130 @@
1
+ import { OutputWriter } from "./OutputWriter.cjs";
2
+ import { PromiseExecutor } from "../utils/types.cjs";
3
+ import { OutputType } from "./types.cjs";
4
+ import { Logger } from "@decaf-ts/logging";
5
+ /**
6
+ * @description A standard output writer for handling command execution output.
7
+ * @summary This class implements the OutputWriter interface and provides methods for
8
+ * handling various types of output from command execution, including standard output,
9
+ * error output, and exit codes. It also includes utility methods for parsing commands
10
+ * and resolving or rejecting promises based on execution results.
11
+ *
12
+ * @template R - The type of the resolved value, defaulting to string.
13
+ *
14
+ * @param cmd - The command string to be executed.
15
+ * @param lock - A PromiseExecutor to control the asynchronous flow.
16
+ * @param args - Additional arguments (unused in the current implementation).
17
+ *
18
+ * @class
19
+ * @example
20
+ * ```typescript
21
+ * import { StandardOutputWriter } from '@decaf-ts/utils';
22
+ * import { PromiseExecutor } from '@decaf-ts/utils';
23
+ *
24
+ * // Create a promise executor
25
+ * const executor: PromiseExecutor<string> = {
26
+ * resolve: (value) => console.log(`Resolved: ${value}`),
27
+ * reject: (error) => console.error(`Rejected: ${error.message}`)
28
+ * };
29
+ *
30
+ * // Create a standard output writer
31
+ * const writer = new StandardOutputWriter('ls -la', executor);
32
+ *
33
+ * // Use the writer to handle command output
34
+ * writer.data('File list output...');
35
+ * writer.exit(0, ['Command executed successfully']);
36
+ * ```
37
+ *
38
+ * @mermaid
39
+ * sequenceDiagram
40
+ * participant Client
41
+ * participant StandardOutputWriter
42
+ * participant Logger
43
+ * participant PromiseExecutor
44
+ *
45
+ * Client->>StandardOutputWriter: new StandardOutputWriter(cmd, lock)
46
+ * StandardOutputWriter->>Logger: Logging.for(cmd)
47
+ *
48
+ * Client->>StandardOutputWriter: data(chunk)
49
+ * StandardOutputWriter->>StandardOutputWriter: log("stdout", chunk)
50
+ * StandardOutputWriter->>Logger: logger.info(log)
51
+ *
52
+ * Client->>StandardOutputWriter: error(chunk)
53
+ * StandardOutputWriter->>StandardOutputWriter: log("stderr", chunk)
54
+ * StandardOutputWriter->>Logger: logger.info(log)
55
+ *
56
+ * Client->>StandardOutputWriter: exit(code, logs)
57
+ * StandardOutputWriter->>StandardOutputWriter: log("stdout", exitMessage)
58
+ * alt code === 0
59
+ * StandardOutputWriter->>StandardOutputWriter: resolve(logs)
60
+ * StandardOutputWriter->>PromiseExecutor: lock.resolve(reason)
61
+ * else code !== 0
62
+ * StandardOutputWriter->>StandardOutputWriter: reject(error)
63
+ * StandardOutputWriter->>PromiseExecutor: lock.reject(reason)
64
+ * end
65
+ */
66
+ export declare class StandardOutputWriter<R = string> implements OutputWriter {
67
+ protected cmd: string;
68
+ protected lock: PromiseExecutor<R>;
69
+ protected logger: Logger;
70
+ constructor(cmd: string, lock: PromiseExecutor<R>, ...args: unknown[]);
71
+ /**
72
+ * @description Logs output to the console.
73
+ * @summary Formats and logs the given data with a timestamp and type indicator.
74
+ *
75
+ * @param type - The type of output (stdout or stderr).
76
+ * @param data - The data to be logged.
77
+ */
78
+ protected log(type: OutputType, data: string | Buffer): void;
79
+ /**
80
+ * @description Handles standard output data.
81
+ * @summary Logs the given chunk as standard output.
82
+ *
83
+ * @param chunk - The data chunk to be logged.
84
+ */
85
+ data(chunk: any): void;
86
+ /**
87
+ * @description Handles error output data.
88
+ * @summary Logs the given chunk as error output.
89
+ *
90
+ * @param chunk - The error data chunk to be logged.
91
+ */
92
+ error(chunk: any): void;
93
+ /**
94
+ * @description Handles error objects.
95
+ * @summary Logs the error message from the given Error object.
96
+ *
97
+ * @param err - The Error object to be logged.
98
+ */
99
+ errors(err: Error): void;
100
+ /**
101
+ * @description Handles the exit of a command.
102
+ * @summary Logs the exit code and resolves or rejects the promise based on the code.
103
+ *
104
+ * @param code - The exit code of the command.
105
+ * @param logs - Array of log messages to be processed before exiting.
106
+ */
107
+ exit(code: number | string, logs: string[]): void;
108
+ /**
109
+ * @description Parses a command string or array into components.
110
+ * @summary Converts the command into a consistent format and stores it, then returns it split into command and arguments.
111
+ *
112
+ * @param command - The command as a string or array of strings.
113
+ * @return A tuple containing the command and its arguments as separate elements.
114
+ */
115
+ parseCommand(command: string | string[]): [string, string[]];
116
+ /**
117
+ * @description Resolves the promise with a success message.
118
+ * @summary Logs a success message and resolves the promise with the given reason.
119
+ *
120
+ * @param reason - The reason for resolving the promise.
121
+ */
122
+ protected resolve(reason: R): void;
123
+ /**
124
+ * @description Rejects the promise with an error message.
125
+ * @summary Logs an error message and rejects the promise with the given reason.
126
+ *
127
+ * @param reason - The reason for rejecting the promise, either a number (exit code) or a string.
128
+ */
129
+ protected reject(reason: number | string | Error): void;
130
+ }
@@ -0,0 +1,130 @@
1
+ import { OutputWriter } from "./OutputWriter.js";
2
+ import { PromiseExecutor } from "../utils/types.js";
3
+ import { OutputType } from "./types.js";
4
+ import { Logger } from "@decaf-ts/logging";
5
+ /**
6
+ * @description A standard output writer for handling command execution output.
7
+ * @summary This class implements the OutputWriter interface and provides methods for
8
+ * handling various types of output from command execution, including standard output,
9
+ * error output, and exit codes. It also includes utility methods for parsing commands
10
+ * and resolving or rejecting promises based on execution results.
11
+ *
12
+ * @template R - The type of the resolved value, defaulting to string.
13
+ *
14
+ * @param cmd - The command string to be executed.
15
+ * @param lock - A PromiseExecutor to control the asynchronous flow.
16
+ * @param args - Additional arguments (unused in the current implementation).
17
+ *
18
+ * @class
19
+ * @example
20
+ * ```typescript
21
+ * import { StandardOutputWriter } from '@decaf-ts/utils';
22
+ * import { PromiseExecutor } from '@decaf-ts/utils';
23
+ *
24
+ * // Create a promise executor
25
+ * const executor: PromiseExecutor<string> = {
26
+ * resolve: (value) => console.log(`Resolved: ${value}`),
27
+ * reject: (error) => console.error(`Rejected: ${error.message}`)
28
+ * };
29
+ *
30
+ * // Create a standard output writer
31
+ * const writer = new StandardOutputWriter('ls -la', executor);
32
+ *
33
+ * // Use the writer to handle command output
34
+ * writer.data('File list output...');
35
+ * writer.exit(0, ['Command executed successfully']);
36
+ * ```
37
+ *
38
+ * @mermaid
39
+ * sequenceDiagram
40
+ * participant Client
41
+ * participant StandardOutputWriter
42
+ * participant Logger
43
+ * participant PromiseExecutor
44
+ *
45
+ * Client->>StandardOutputWriter: new StandardOutputWriter(cmd, lock)
46
+ * StandardOutputWriter->>Logger: Logging.for(cmd)
47
+ *
48
+ * Client->>StandardOutputWriter: data(chunk)
49
+ * StandardOutputWriter->>StandardOutputWriter: log("stdout", chunk)
50
+ * StandardOutputWriter->>Logger: logger.info(log)
51
+ *
52
+ * Client->>StandardOutputWriter: error(chunk)
53
+ * StandardOutputWriter->>StandardOutputWriter: log("stderr", chunk)
54
+ * StandardOutputWriter->>Logger: logger.info(log)
55
+ *
56
+ * Client->>StandardOutputWriter: exit(code, logs)
57
+ * StandardOutputWriter->>StandardOutputWriter: log("stdout", exitMessage)
58
+ * alt code === 0
59
+ * StandardOutputWriter->>StandardOutputWriter: resolve(logs)
60
+ * StandardOutputWriter->>PromiseExecutor: lock.resolve(reason)
61
+ * else code !== 0
62
+ * StandardOutputWriter->>StandardOutputWriter: reject(error)
63
+ * StandardOutputWriter->>PromiseExecutor: lock.reject(reason)
64
+ * end
65
+ */
66
+ export declare class StandardOutputWriter<R = string> implements OutputWriter {
67
+ protected cmd: string;
68
+ protected lock: PromiseExecutor<R>;
69
+ protected logger: Logger;
70
+ constructor(cmd: string, lock: PromiseExecutor<R>, ...args: unknown[]);
71
+ /**
72
+ * @description Logs output to the console.
73
+ * @summary Formats and logs the given data with a timestamp and type indicator.
74
+ *
75
+ * @param type - The type of output (stdout or stderr).
76
+ * @param data - The data to be logged.
77
+ */
78
+ protected log(type: OutputType, data: string | Buffer): void;
79
+ /**
80
+ * @description Handles standard output data.
81
+ * @summary Logs the given chunk as standard output.
82
+ *
83
+ * @param chunk - The data chunk to be logged.
84
+ */
85
+ data(chunk: any): void;
86
+ /**
87
+ * @description Handles error output data.
88
+ * @summary Logs the given chunk as error output.
89
+ *
90
+ * @param chunk - The error data chunk to be logged.
91
+ */
92
+ error(chunk: any): void;
93
+ /**
94
+ * @description Handles error objects.
95
+ * @summary Logs the error message from the given Error object.
96
+ *
97
+ * @param err - The Error object to be logged.
98
+ */
99
+ errors(err: Error): void;
100
+ /**
101
+ * @description Handles the exit of a command.
102
+ * @summary Logs the exit code and resolves or rejects the promise based on the code.
103
+ *
104
+ * @param code - The exit code of the command.
105
+ * @param logs - Array of log messages to be processed before exiting.
106
+ */
107
+ exit(code: number | string, logs: string[]): void;
108
+ /**
109
+ * @description Parses a command string or array into components.
110
+ * @summary Converts the command into a consistent format and stores it, then returns it split into command and arguments.
111
+ *
112
+ * @param command - The command as a string or array of strings.
113
+ * @return A tuple containing the command and its arguments as separate elements.
114
+ */
115
+ parseCommand(command: string | string[]): [string, string[]];
116
+ /**
117
+ * @description Resolves the promise with a success message.
118
+ * @summary Logs a success message and resolves the promise with the given reason.
119
+ *
120
+ * @param reason - The reason for resolving the promise.
121
+ */
122
+ protected resolve(reason: R): void;
123
+ /**
124
+ * @description Rejects the promise with an error message.
125
+ * @summary Logs an error message and rejects the promise with the given reason.
126
+ *
127
+ * @param reason - The reason for rejecting the promise, either a number (exit code) or a string.
128
+ */
129
+ protected reject(reason: number | string | Error): void;
130
+ }
@@ -0,0 +1,4 @@
1
+ export * from './OutputWriter.cjs';
2
+ export * from './RegexpOutputWriter.cjs';
3
+ export * from './StandardOutputWriter.cjs';
4
+ export * from './types.cjs';
@@ -0,0 +1,4 @@
1
+ export * from './OutputWriter.js';
2
+ export * from './RegexpOutputWriter.js';
3
+ export * from './StandardOutputWriter.js';
4
+ export * from './types.js';
@@ -0,0 +1,29 @@
1
+ import { StandardOutputWriter } from "./StandardOutputWriter.cjs";
2
+ import { PromiseExecutor } from "../utils/types.cjs";
3
+ /**
4
+ * @description Represents the type of output stream.
5
+ * @summary A union type for standard output and standard error streams.
6
+ * @typedef {("stdout" | "stderr")} OutputType
7
+ * @memberOf module:utils
8
+ */
9
+ export type OutputType = "stdout" | "stderr";
10
+ /**
11
+ * @description Constructor type for output writers.
12
+ * @summary Defines the structure for creating new output writer instances. This type represents
13
+ * a constructor function that takes a PromiseExecutor and additional arguments to create
14
+ * a new instance of an output writer. It allows for flexible creation of different types
15
+ * of output writers while maintaining a consistent interface.
16
+ *
17
+ * @template R - The type of the resolved value, defaulting to string.
18
+ * @template C - The type of the output writer, extending StandardOutputWriter<R>.
19
+ * @template E - The type of the error value, defaulting to number.
20
+ *
21
+ * @param {PromiseExecutor<R, E>} lock - The promise executor for managing asynchronous operations.
22
+ * @param {...unknown[]} args - Additional arguments passed to the constructor.
23
+ * @return {C} An instance of the output writer.
24
+ *
25
+ * @memberOf module:utils
26
+ */
27
+ export type OutputWriterConstructor<R = string, C extends StandardOutputWriter<R> = StandardOutputWriter<R>, E = number> = {
28
+ new (cmd: string, lock: PromiseExecutor<R, E>, ...args: unknown[]): C;
29
+ };
@@ -0,0 +1,29 @@
1
+ import { StandardOutputWriter } from "./StandardOutputWriter.js";
2
+ import { PromiseExecutor } from "../utils/types.js";
3
+ /**
4
+ * @description Represents the type of output stream.
5
+ * @summary A union type for standard output and standard error streams.
6
+ * @typedef {("stdout" | "stderr")} OutputType
7
+ * @memberOf module:utils
8
+ */
9
+ export type OutputType = "stdout" | "stderr";
10
+ /**
11
+ * @description Constructor type for output writers.
12
+ * @summary Defines the structure for creating new output writer instances. This type represents
13
+ * a constructor function that takes a PromiseExecutor and additional arguments to create
14
+ * a new instance of an output writer. It allows for flexible creation of different types
15
+ * of output writers while maintaining a consistent interface.
16
+ *
17
+ * @template R - The type of the resolved value, defaulting to string.
18
+ * @template C - The type of the output writer, extending StandardOutputWriter<R>.
19
+ * @template E - The type of the error value, defaulting to number.
20
+ *
21
+ * @param {PromiseExecutor<R, E>} lock - The promise executor for managing asynchronous operations.
22
+ * @param {...unknown[]} args - Additional arguments passed to the constructor.
23
+ * @return {C} An instance of the output writer.
24
+ *
25
+ * @memberOf module:utils
26
+ */
27
+ export type OutputWriterConstructor<R = string, C extends StandardOutputWriter<R> = StandardOutputWriter<R>, E = number> = {
28
+ new (cmd: string, lock: PromiseExecutor<R, E>, ...args: unknown[]): C;
29
+ };
package/package.json CHANGED
@@ -1,25 +1,31 @@
1
1
  {
2
2
  "name": "@decaf-ts/utils",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "module management utils for decaf-ts",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./lib/types/index.d.ts",
9
- "import": "./lib/esm/index.js",
10
- "require": "./lib/cjs/index.cjs",
8
+ "import": {
9
+ "default": "./lib/esm/index.js"
10
+ },
11
+ "require": {
12
+ "default": "./lib/esm/index.js"
13
+ },
11
14
  "default": "./lib/esm/index.js"
12
15
  },
13
16
  "./tests": {
14
- "types": "./lib/types/tests/index.d.ts",
15
- "import": "./lib/esm/tests/index.js",
16
- "require": "./lib/cjs/tests/index.cjs",
17
+ "import": {
18
+ "default": "./lib/esm/tests/index.js"
19
+ },
20
+ "require": {
21
+ "default": "./lib/esm/tests/index.js"
22
+ },
17
23
  "default": "./lib/esm/tests/index.js"
18
24
  }
19
25
  },
20
26
  "main": "./lib/cjs/index.cjs",
21
27
  "module": "./lib/esm/index.js",
22
- "types": "./lib/types/index.d.ts",
28
+ "types": "./lib/types/index.d.mts",
23
29
  "sideEffects": false,
24
30
  "bin": {
25
31
  "tag-release": "lib/cjs/bin/tag-release.cjs",