@decaf-ts/utils 1.0.10 → 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 (210) 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/assets/slogans.cjs +3 -2
  7. package/lib/cjs/assets/slogans.cjs.map +1 -0
  8. package/lib/cjs/bin/build-scripts.cjs +5 -4
  9. package/lib/cjs/bin/build-scripts.cjs.map +1 -0
  10. package/lib/cjs/bin/release-chain-dispatch.cjs +5 -4
  11. package/lib/cjs/bin/release-chain-dispatch.cjs.map +1 -0
  12. package/lib/cjs/bin/release-chain.cjs +5 -4
  13. package/lib/cjs/bin/release-chain.cjs.map +1 -0
  14. package/lib/cjs/bin/tag-release.cjs +5 -4
  15. package/lib/cjs/bin/tag-release.cjs.map +1 -0
  16. package/lib/cjs/cli/command.cjs +11 -10
  17. package/lib/cjs/cli/command.cjs.map +1 -0
  18. package/lib/cjs/cli/commands/build-scripts.cjs +163 -44
  19. package/lib/cjs/cli/commands/build-scripts.cjs.map +1 -0
  20. package/lib/cjs/cli/commands/index.cjs +1 -0
  21. package/lib/cjs/cli/commands/index.cjs.map +1 -0
  22. package/lib/cjs/cli/commands/release-chain.cjs +12 -11
  23. package/lib/cjs/cli/commands/release-chain.cjs.map +1 -0
  24. package/lib/cjs/cli/commands/tag-release.cjs +21 -20
  25. package/lib/cjs/cli/commands/tag-release.cjs.map +1 -0
  26. package/lib/cjs/cli/constants.cjs +1 -0
  27. package/lib/cjs/cli/constants.cjs.map +1 -0
  28. package/lib/cjs/cli/index.cjs +1 -0
  29. package/lib/cjs/cli/index.cjs.map +1 -0
  30. package/lib/cjs/cli/types.cjs +1 -0
  31. package/lib/cjs/cli/types.cjs.map +1 -0
  32. package/lib/cjs/index.cjs +2 -1
  33. package/lib/cjs/index.cjs.map +1 -0
  34. package/lib/cjs/input/index.cjs +1 -0
  35. package/lib/cjs/input/index.cjs.map +1 -0
  36. package/lib/cjs/input/input.cjs +1 -0
  37. package/lib/cjs/input/input.cjs.map +1 -0
  38. package/lib/cjs/input/types.cjs +1 -0
  39. package/lib/cjs/input/types.cjs.map +1 -0
  40. package/lib/cjs/output/common.cjs +4 -3
  41. package/lib/cjs/output/common.cjs.map +1 -0
  42. package/lib/cjs/output/index.cjs +1 -0
  43. package/lib/cjs/output/index.cjs.map +1 -0
  44. package/lib/cjs/release-chain/index.cjs +1 -0
  45. package/lib/cjs/release-chain/index.cjs.map +1 -0
  46. package/lib/cjs/tests/Consumer.cjs +3 -2
  47. package/lib/cjs/tests/Consumer.cjs.map +1 -0
  48. package/lib/cjs/tests/ProducerChildProcess.cjs.map +1 -0
  49. package/lib/cjs/tests/TestReporter.cjs +5 -4
  50. package/lib/cjs/tests/TestReporter.cjs.map +1 -0
  51. package/lib/cjs/tests/index.cjs +1 -0
  52. package/lib/cjs/tests/index.cjs.map +1 -0
  53. package/lib/cjs/tests/jestPerformanceRunner.cjs +5 -4
  54. package/lib/cjs/tests/jestPerformanceRunner.cjs.map +1 -0
  55. package/lib/cjs/tests/utils.cjs +5 -4
  56. package/lib/cjs/tests/utils.cjs.map +1 -0
  57. package/lib/cjs/utils/constants.cjs +3 -16
  58. package/lib/cjs/utils/constants.cjs.map +1 -0
  59. package/lib/cjs/utils/fs.cjs +16 -15
  60. package/lib/cjs/utils/fs.cjs.map +1 -0
  61. package/lib/cjs/utils/http.cjs +1 -0
  62. package/lib/cjs/utils/http.cjs.map +1 -0
  63. package/lib/cjs/utils/index.cjs +1 -0
  64. package/lib/cjs/utils/index.cjs.map +1 -0
  65. package/lib/cjs/utils/md.cjs +1 -0
  66. package/lib/cjs/utils/md.cjs.map +1 -0
  67. package/lib/cjs/utils/performanceRunner.cjs +1 -0
  68. package/lib/cjs/utils/performanceRunner.cjs.map +1 -0
  69. package/lib/cjs/utils/timeout.cjs +1 -0
  70. package/lib/cjs/utils/timeout.cjs.map +1 -0
  71. package/lib/cjs/utils/types.cjs +1 -0
  72. package/lib/cjs/utils/types.cjs.map +1 -0
  73. package/lib/cjs/utils/utils.cjs +5 -4
  74. package/lib/cjs/utils/utils.cjs.map +1 -0
  75. package/lib/cjs/writers/OutputWriter.cjs +1 -0
  76. package/lib/cjs/writers/OutputWriter.cjs.map +1 -0
  77. package/lib/cjs/writers/RegexpOutputWriter.cjs +3 -2
  78. package/lib/cjs/writers/RegexpOutputWriter.cjs.map +1 -0
  79. package/lib/cjs/writers/StandardOutputWriter.cjs +3 -2
  80. package/lib/cjs/writers/StandardOutputWriter.cjs.map +1 -0
  81. package/lib/cjs/writers/index.cjs +1 -0
  82. package/lib/cjs/writers/index.cjs.map +1 -0
  83. package/lib/cjs/writers/types.cjs +1 -0
  84. package/lib/cjs/writers/types.cjs.map +1 -0
  85. package/lib/esm/cli/commands/build-scripts.js +142 -24
  86. package/lib/esm/cli/commands/build-scripts.js.map +1 -1
  87. package/lib/esm/index.js +1 -1
  88. package/lib/types/assets/slogans.d.cts +19 -0
  89. package/lib/types/assets/slogans.d.mts +19 -0
  90. package/lib/types/bin/build-scripts.d.cts +1 -0
  91. package/lib/types/bin/build-scripts.d.mts +1 -0
  92. package/lib/types/bin/release-chain-dispatch.d.cts +1 -0
  93. package/lib/types/bin/release-chain-dispatch.d.mts +1 -0
  94. package/lib/types/bin/release-chain.d.cts +1 -0
  95. package/lib/types/bin/release-chain.d.mts +1 -0
  96. package/lib/types/bin/tag-release.d.cts +1 -0
  97. package/lib/types/bin/tag-release.d.mts +1 -0
  98. package/lib/types/cli/command.d.cts +104 -0
  99. package/lib/types/cli/command.d.mts +104 -0
  100. package/lib/types/cli/commands/build-scripts.d.cts +148 -0
  101. package/lib/types/cli/commands/build-scripts.d.mts +148 -0
  102. package/lib/types/cli/commands/build-scripts.d.ts +5 -0
  103. package/lib/types/cli/commands/index.d.cts +3 -0
  104. package/lib/types/cli/commands/index.d.mts +3 -0
  105. package/lib/types/cli/commands/release-chain.d.cts +62 -0
  106. package/lib/types/cli/commands/release-chain.d.mts +62 -0
  107. package/lib/types/cli/commands/tag-release.d.cts +105 -0
  108. package/lib/types/cli/commands/tag-release.d.mts +105 -0
  109. package/lib/types/cli/constants.d.cts +75 -0
  110. package/lib/types/cli/constants.d.mts +75 -0
  111. package/lib/types/cli/index.d.cts +4 -0
  112. package/lib/types/cli/index.d.mts +4 -0
  113. package/lib/types/cli/types.d.cts +30 -0
  114. package/lib/types/cli/types.d.mts +30 -0
  115. package/lib/types/index.d.cts +38 -0
  116. package/lib/types/index.d.mts +38 -0
  117. package/lib/types/index.d.ts +1 -1
  118. package/lib/types/input/index.d.cts +2 -0
  119. package/lib/types/input/index.d.mts +2 -0
  120. package/lib/types/input/input.d.cts +517 -0
  121. package/lib/types/input/input.d.mts +517 -0
  122. package/lib/types/input/types.d.cts +159 -0
  123. package/lib/types/input/types.d.mts +159 -0
  124. package/lib/types/output/common.d.cts +53 -0
  125. package/lib/types/output/common.d.mts +53 -0
  126. package/lib/types/output/index.d.cts +1 -0
  127. package/lib/types/output/index.d.mts +1 -0
  128. package/lib/types/release-chain/index.d.cts +43 -0
  129. package/lib/types/release-chain/index.d.mts +43 -0
  130. package/lib/types/tests/Consumer.d.cts +151 -0
  131. package/lib/types/tests/Consumer.d.mts +151 -0
  132. package/lib/types/tests/ProducerChildProcess.d.cts +18 -0
  133. package/lib/types/tests/ProducerChildProcess.d.mts +18 -0
  134. package/lib/types/tests/TestReporter.d.cts +245 -0
  135. package/lib/types/tests/TestReporter.d.mts +245 -0
  136. package/lib/types/tests/index.d.cts +4 -0
  137. package/lib/types/tests/index.d.mts +4 -0
  138. package/lib/types/tests/jestPerformanceRunner.d.cts +37 -0
  139. package/lib/types/tests/jestPerformanceRunner.d.mts +37 -0
  140. package/lib/types/tests/utils.d.cts +5 -0
  141. package/lib/types/tests/utils.d.mts +5 -0
  142. package/lib/types/utils/constants.d.cts +65 -0
  143. package/lib/types/utils/constants.d.mts +65 -0
  144. package/lib/types/utils/fs.d.cts +259 -0
  145. package/lib/types/utils/fs.d.mts +259 -0
  146. package/lib/types/utils/http.d.cts +41 -0
  147. package/lib/types/utils/http.d.mts +41 -0
  148. package/lib/types/utils/index.d.cts +6 -0
  149. package/lib/types/utils/index.d.mts +6 -0
  150. package/lib/types/utils/md.d.cts +156 -0
  151. package/lib/types/utils/md.d.mts +156 -0
  152. package/lib/types/utils/performanceRunner.d.cts +129 -0
  153. package/lib/types/utils/performanceRunner.d.mts +129 -0
  154. package/lib/types/utils/timeout.d.cts +12 -0
  155. package/lib/types/utils/timeout.d.mts +12 -0
  156. package/lib/types/utils/types.d.cts +112 -0
  157. package/lib/types/utils/types.d.mts +112 -0
  158. package/lib/types/utils/utils.d.cts +133 -0
  159. package/lib/types/utils/utils.d.mts +133 -0
  160. package/lib/types/writers/OutputWriter.d.cts +49 -0
  161. package/lib/types/writers/OutputWriter.d.mts +49 -0
  162. package/lib/types/writers/RegexpOutputWriter.d.cts +110 -0
  163. package/lib/types/writers/RegexpOutputWriter.d.mts +110 -0
  164. package/lib/types/writers/StandardOutputWriter.d.cts +130 -0
  165. package/lib/types/writers/StandardOutputWriter.d.mts +130 -0
  166. package/lib/types/writers/index.d.cts +4 -0
  167. package/lib/types/writers/index.d.mts +4 -0
  168. package/lib/types/writers/types.d.cts +29 -0
  169. package/lib/types/writers/types.d.mts +29 -0
  170. package/package.json +14 -8
  171. package/lib/cjs/assets/slogans.js.map +0 -1
  172. package/lib/cjs/bin/build-scripts.js.map +0 -1
  173. package/lib/cjs/bin/release-chain-dispatch.js.map +0 -1
  174. package/lib/cjs/bin/release-chain.js.map +0 -1
  175. package/lib/cjs/bin/tag-release.js.map +0 -1
  176. package/lib/cjs/cli/command.js.map +0 -1
  177. package/lib/cjs/cli/commands/build-scripts.js.map +0 -1
  178. package/lib/cjs/cli/commands/index.js.map +0 -1
  179. package/lib/cjs/cli/commands/release-chain.js.map +0 -1
  180. package/lib/cjs/cli/commands/tag-release.js.map +0 -1
  181. package/lib/cjs/cli/constants.js.map +0 -1
  182. package/lib/cjs/cli/index.js.map +0 -1
  183. package/lib/cjs/cli/types.js.map +0 -1
  184. package/lib/cjs/index.js.map +0 -1
  185. package/lib/cjs/input/index.js.map +0 -1
  186. package/lib/cjs/input/input.js.map +0 -1
  187. package/lib/cjs/input/types.js.map +0 -1
  188. package/lib/cjs/output/common.js.map +0 -1
  189. package/lib/cjs/output/index.js.map +0 -1
  190. package/lib/cjs/release-chain/index.js.map +0 -1
  191. package/lib/cjs/tests/Consumer.js.map +0 -1
  192. package/lib/cjs/tests/ProducerChildProcess.js.map +0 -1
  193. package/lib/cjs/tests/TestReporter.js.map +0 -1
  194. package/lib/cjs/tests/index.js.map +0 -1
  195. package/lib/cjs/tests/jestPerformanceRunner.js.map +0 -1
  196. package/lib/cjs/tests/utils.js.map +0 -1
  197. package/lib/cjs/utils/constants.js.map +0 -1
  198. package/lib/cjs/utils/fs.js.map +0 -1
  199. package/lib/cjs/utils/http.js.map +0 -1
  200. package/lib/cjs/utils/index.js.map +0 -1
  201. package/lib/cjs/utils/md.js.map +0 -1
  202. package/lib/cjs/utils/performanceRunner.js.map +0 -1
  203. package/lib/cjs/utils/timeout.js.map +0 -1
  204. package/lib/cjs/utils/types.js.map +0 -1
  205. package/lib/cjs/utils/utils.js.map +0 -1
  206. package/lib/cjs/writers/OutputWriter.js.map +0 -1
  207. package/lib/cjs/writers/RegexpOutputWriter.js.map +0 -1
  208. package/lib/cjs/writers/StandardOutputWriter.js.map +0 -1
  209. package/lib/cjs/writers/index.js.map +0 -1
  210. package/lib/cjs/writers/types.js.map +0 -1
@@ -0,0 +1,112 @@
1
+ import { ChildProcessWithoutNullStreams } from "child_process";
2
+ import { Environment } from "@decaf-ts/logging";
3
+ /**
4
+ * @description Defines the structure for promise resolution and rejection.
5
+ * @summary Provides methods to resolve or reject a promise.
6
+ * @template R - The type of the resolved value.
7
+ * @template E - The type of the error value, defaulting to Error.
8
+ * @typedef {Object} PromiseExecutor
9
+ * @property {function(R): void} resolve - Function to resolve the promise.
10
+ * @property {function(E): void} reject - Function to reject the promise.
11
+ * @memberOf module:utils
12
+ */
13
+ export interface PromiseExecutor<R, E = Error> {
14
+ resolve: (value: R | PromiseLike<R>) => void;
15
+ reject: (error: E) => void;
16
+ }
17
+ /**
18
+ * @description Represents the result of a command execution.
19
+ * @summary Extends Promise with additional properties related to the command execution.
20
+ * This interface provides a comprehensive way to handle and interact with the results
21
+ * of an asynchronous command execution, including access to the command details,
22
+ * output logs, and the ability to abort the execution.
23
+ *
24
+ * @template R - The type of the resolved value, defaulting to void.
25
+ * @interface CommandResult
26
+ * @extends Promise<R>
27
+ * @memberOf module:utils
28
+ */
29
+ export interface CommandResult<R = void> {
30
+ promise: Promise<R>;
31
+ /**
32
+ * @description Controller to abort the command execution.
33
+ * @summary Provides a mechanism to cancel the ongoing command execution.
34
+ */
35
+ abort: AbortController;
36
+ /**
37
+ * @description The executed command string.
38
+ * @summary Contains the actual command that was executed.
39
+ */
40
+ command: string;
41
+ /**
42
+ * @description The child process object.
43
+ * @summary Represents the Node.js child process that was spawned to execute the command.
44
+ */
45
+ cmd?: ChildProcessWithoutNullStreams;
46
+ /**
47
+ * @description Array of stdout logs.
48
+ * @summary Contains all the standard output messages produced during the command execution.
49
+ */
50
+ logs: string[];
51
+ /**
52
+ * @description Array of stderr logs.
53
+ * @summary Contains all the standard error messages produced during the command execution.
54
+ */
55
+ errs: string[];
56
+ /**
57
+ * @description allows chaining commands.
58
+ * @summary allows chaining commands (or piping).
59
+ */
60
+ pipe: <E>(cb: (r: R) => E) => Promise<E>;
61
+ }
62
+ /**
63
+ * @description Factory type for creating Environment instances.
64
+ * @summary Defines a function type that creates and returns Environment instances.
65
+ *
66
+ * @template T - The type of object the Environment will accumulate.
67
+ * @template E - The specific Environment type to be created, extending Environment<T>.
68
+ * @typedef {function(...unknown[]): E} EnvironmentFactory
69
+ * @memberOf module:utils
70
+ */
71
+ export type EnvironmentFactory<T extends object, E extends Environment<T>> = (...args: unknown[]) => E;
72
+ /**
73
+ * @description Map of project dependencies with detailed information.
74
+ * @summary Represents the structure of project dependencies categorized by type (production, development, peer).
75
+ * Each category contains an array of objects with name and version information.
76
+ *
77
+ * @typedef {Object} DependencyMap
78
+ * @property {Array<{name: string, version: string}>} prod - Production dependencies with name and version.
79
+ * @property {Array<{name: string, version: string}>} dev - Development dependencies with name and version.
80
+ * @property {Array<{name: string, version: string}>} peer - Peer dependencies with name and version.
81
+ * @memberOf module:utils
82
+ */
83
+ export type DependencyMap = {
84
+ prod: {
85
+ name: string;
86
+ version: string;
87
+ }[];
88
+ dev: {
89
+ name: string;
90
+ version: string;
91
+ }[];
92
+ peer: {
93
+ name: string;
94
+ version: string;
95
+ }[];
96
+ };
97
+ /**
98
+ * @description Simplified map of project dependencies.
99
+ * @summary Represents a simplified structure of project dependencies categorized by type.
100
+ * Each category contains an optional array of dependency names without version information.
101
+ *
102
+ * @typedef {Object} SimpleDependencyMap
103
+ * @property {string[]} [prod] - Optional array of production dependency names.
104
+ * @property {string[]} [dev] - Optional array of development dependency names.
105
+ * @property {string[]} [peer] - Optional array of peer dependency names.
106
+ * @memberOf module:utils
107
+ */
108
+ export type SimpleDependencyMap = {
109
+ prod?: string[];
110
+ dev?: string[];
111
+ peer?: string[];
112
+ };
@@ -0,0 +1,112 @@
1
+ import { ChildProcessWithoutNullStreams } from "child_process";
2
+ import { Environment } from "@decaf-ts/logging";
3
+ /**
4
+ * @description Defines the structure for promise resolution and rejection.
5
+ * @summary Provides methods to resolve or reject a promise.
6
+ * @template R - The type of the resolved value.
7
+ * @template E - The type of the error value, defaulting to Error.
8
+ * @typedef {Object} PromiseExecutor
9
+ * @property {function(R): void} resolve - Function to resolve the promise.
10
+ * @property {function(E): void} reject - Function to reject the promise.
11
+ * @memberOf module:utils
12
+ */
13
+ export interface PromiseExecutor<R, E = Error> {
14
+ resolve: (value: R | PromiseLike<R>) => void;
15
+ reject: (error: E) => void;
16
+ }
17
+ /**
18
+ * @description Represents the result of a command execution.
19
+ * @summary Extends Promise with additional properties related to the command execution.
20
+ * This interface provides a comprehensive way to handle and interact with the results
21
+ * of an asynchronous command execution, including access to the command details,
22
+ * output logs, and the ability to abort the execution.
23
+ *
24
+ * @template R - The type of the resolved value, defaulting to void.
25
+ * @interface CommandResult
26
+ * @extends Promise<R>
27
+ * @memberOf module:utils
28
+ */
29
+ export interface CommandResult<R = void> {
30
+ promise: Promise<R>;
31
+ /**
32
+ * @description Controller to abort the command execution.
33
+ * @summary Provides a mechanism to cancel the ongoing command execution.
34
+ */
35
+ abort: AbortController;
36
+ /**
37
+ * @description The executed command string.
38
+ * @summary Contains the actual command that was executed.
39
+ */
40
+ command: string;
41
+ /**
42
+ * @description The child process object.
43
+ * @summary Represents the Node.js child process that was spawned to execute the command.
44
+ */
45
+ cmd?: ChildProcessWithoutNullStreams;
46
+ /**
47
+ * @description Array of stdout logs.
48
+ * @summary Contains all the standard output messages produced during the command execution.
49
+ */
50
+ logs: string[];
51
+ /**
52
+ * @description Array of stderr logs.
53
+ * @summary Contains all the standard error messages produced during the command execution.
54
+ */
55
+ errs: string[];
56
+ /**
57
+ * @description allows chaining commands.
58
+ * @summary allows chaining commands (or piping).
59
+ */
60
+ pipe: <E>(cb: (r: R) => E) => Promise<E>;
61
+ }
62
+ /**
63
+ * @description Factory type for creating Environment instances.
64
+ * @summary Defines a function type that creates and returns Environment instances.
65
+ *
66
+ * @template T - The type of object the Environment will accumulate.
67
+ * @template E - The specific Environment type to be created, extending Environment<T>.
68
+ * @typedef {function(...unknown[]): E} EnvironmentFactory
69
+ * @memberOf module:utils
70
+ */
71
+ export type EnvironmentFactory<T extends object, E extends Environment<T>> = (...args: unknown[]) => E;
72
+ /**
73
+ * @description Map of project dependencies with detailed information.
74
+ * @summary Represents the structure of project dependencies categorized by type (production, development, peer).
75
+ * Each category contains an array of objects with name and version information.
76
+ *
77
+ * @typedef {Object} DependencyMap
78
+ * @property {Array<{name: string, version: string}>} prod - Production dependencies with name and version.
79
+ * @property {Array<{name: string, version: string}>} dev - Development dependencies with name and version.
80
+ * @property {Array<{name: string, version: string}>} peer - Peer dependencies with name and version.
81
+ * @memberOf module:utils
82
+ */
83
+ export type DependencyMap = {
84
+ prod: {
85
+ name: string;
86
+ version: string;
87
+ }[];
88
+ dev: {
89
+ name: string;
90
+ version: string;
91
+ }[];
92
+ peer: {
93
+ name: string;
94
+ version: string;
95
+ }[];
96
+ };
97
+ /**
98
+ * @description Simplified map of project dependencies.
99
+ * @summary Represents a simplified structure of project dependencies categorized by type.
100
+ * Each category contains an optional array of dependency names without version information.
101
+ *
102
+ * @typedef {Object} SimpleDependencyMap
103
+ * @property {string[]} [prod] - Optional array of production dependency names.
104
+ * @property {string[]} [dev] - Optional array of development dependency names.
105
+ * @property {string[]} [peer] - Optional array of peer dependency names.
106
+ * @memberOf module:utils
107
+ */
108
+ export type SimpleDependencyMap = {
109
+ prod?: string[];
110
+ dev?: string[];
111
+ peer?: string[];
112
+ };
@@ -0,0 +1,133 @@
1
+ import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio } from "child_process";
2
+ import { StandardOutputWriter } from "../writers/StandardOutputWriter.cjs";
3
+ import { CommandResult } from "./types.cjs";
4
+ import { OutputWriterConstructor } from "../writers/types.cjs";
5
+ import { Logger } from "@decaf-ts/logging";
6
+ /**
7
+ * @description Creates a locked version of a function.
8
+ * @summary This higher-order function takes a function and returns a new function that ensures
9
+ * sequential execution of the original function, even when called multiple times concurrently.
10
+ * It uses a Promise-based locking mechanism to queue function calls.
11
+ *
12
+ * @template R - The return type of the input function.
13
+ *
14
+ * @param f - The function to be locked. It can take any number of parameters and return a value of type R.
15
+ * @return A new function with the same signature as the input function, but with sequential execution guaranteed.
16
+ *
17
+ * @function lockify
18
+ *
19
+ * @mermaid
20
+ * sequenceDiagram
21
+ * participant Caller
22
+ * participant LockedFunction
23
+ * participant OriginalFunction
24
+ * Caller->>LockedFunction: Call with params
25
+ * LockedFunction->>LockedFunction: Check current lock
26
+ * alt Lock is resolved
27
+ * LockedFunction->>OriginalFunction: Execute with params
28
+ * OriginalFunction-->>LockedFunction: Return result
29
+ * LockedFunction-->>Caller: Return result
30
+ * else Lock is pending
31
+ * LockedFunction->>LockedFunction: Queue execution
32
+ * LockedFunction-->>Caller: Return promise
33
+ * Note over LockedFunction: Wait for previous execution
34
+ * LockedFunction->>OriginalFunction: Execute with params
35
+ * OriginalFunction-->>LockedFunction: Return result
36
+ * LockedFunction-->>Caller: Resolve promise with result
37
+ * end
38
+ * LockedFunction->>LockedFunction: Update lock
39
+ *
40
+ * @memberOf module:utils
41
+ */
42
+ export declare function lockify<R>(f: (...params: unknown[]) => R): (...params: unknown[]) => Promise<R>;
43
+ /**
44
+ * @description Chains multiple abort signals to a controller.
45
+ * @summary Creates a mechanism where multiple abort signals can trigger a single abort controller.
46
+ * This is useful for coordinating cancellation across multiple asynchronous operations.
47
+ *
48
+ * @param {AbortController} controller - The abort controller to be triggered by signals.
49
+ * @param {...AbortSignal} signals - One or more abort signals that can trigger the controller.
50
+ * @return {AbortController} The input controller, now connected to the signals.
51
+ *
52
+ * @function chainAbortController
53
+ *
54
+ * @memberOf module:utils
55
+ */
56
+ export declare function chainAbortController(controller: AbortController, ...signals: AbortSignal[]): AbortController;
57
+ /**
58
+ * @description Creates a new controller chained to multiple abort signals.
59
+ * @summary Creates a new abort controller that will be triggered if any of the provided signals are aborted.
60
+ *
61
+ * @param {...AbortSignal} signals - One or more abort signals that can trigger the new controller.
62
+ * @return {AbortController} A new abort controller connected to the signals.
63
+ *
64
+ * @function chainAbortController
65
+ *
66
+ * @memberOf module:utils
67
+ */
68
+ export declare function chainAbortController(...signals: AbortSignal[]): AbortController;
69
+ /**
70
+ * @description Spawns a command as a child process with output handling.
71
+ * @summary Creates a child process to execute a command with support for piping multiple commands,
72
+ * custom output handling, and abort control. This function handles the low-level details of
73
+ * spawning processes and connecting their inputs/outputs when piping is used.
74
+ *
75
+ * @template R - The type of the processed output, defaulting to string.
76
+ * @param {StandardOutputWriter<R>} output - The output writer to handle command output.
77
+ * @param {string} command - The command to execute, can include pipe operators.
78
+ * @param {SpawnOptionsWithoutStdio} opts - Options for the spawned process.
79
+ * @param {AbortController} abort - Controller to abort the command execution.
80
+ * @param {Logger} logger - Logger for recording command execution details.
81
+ * @return {ChildProcessWithoutNullStreams} The spawned child process.
82
+ *
83
+ * @function spawnCommand
84
+ *
85
+ * @memberOf module:utils
86
+ */
87
+ export declare function spawnCommand<R = string>(output: StandardOutputWriter<R>, command: string, opts: SpawnOptionsWithoutStdio, abort: AbortController, logger: Logger): ChildProcessWithoutNullStreams;
88
+ /**
89
+ * @description Executes a command asynchronously with customizable output handling.
90
+ * @summary This function runs a shell command as a child process, providing fine-grained
91
+ * control over its execution and output handling. It supports custom output writers,
92
+ * allows for command abortion, and captures both stdout and stderr.
93
+ *
94
+ * @template R - The type of the resolved value from the command execution.
95
+ *
96
+ * @param command - The command to run, either as a string or an array of strings.
97
+ * @param opts - Spawn options for the child process. Defaults to an empty object.
98
+ * @param outputConstructor - Constructor for the output writer. Defaults to StandardOutputWriter.
99
+ * @param args - Additional arguments to pass to the output constructor.
100
+ * @return {CommandResult} A promise that resolves to the command result of type R.
101
+ *
102
+ * @function runCommand
103
+ *
104
+ * @mermaid
105
+ * sequenceDiagram
106
+ * participant Caller
107
+ * participant runCommand
108
+ * participant OutputWriter
109
+ * participant ChildProcess
110
+ * Caller->>runCommand: Call with command and options
111
+ * runCommand->>OutputWriter: Create new instance
112
+ * runCommand->>OutputWriter: Parse command
113
+ * runCommand->>ChildProcess: Spawn process
114
+ * ChildProcess-->>runCommand: Return process object
115
+ * runCommand->>ChildProcess: Set up event listeners
116
+ * loop For each stdout data
117
+ * ChildProcess->>runCommand: Emit stdout data
118
+ * runCommand->>OutputWriter: Handle stdout data
119
+ * end
120
+ * loop For each stderr data
121
+ * ChildProcess->>runCommand: Emit stderr data
122
+ * runCommand->>OutputWriter: Handle stderr data
123
+ * end
124
+ * ChildProcess->>runCommand: Emit error (if any)
125
+ * runCommand->>OutputWriter: Handle error
126
+ * ChildProcess->>runCommand: Emit exit
127
+ * runCommand->>OutputWriter: Handle exit
128
+ * OutputWriter-->>runCommand: Resolve or reject promise
129
+ * runCommand-->>Caller: Return CommandResult
130
+ *
131
+ * @memberOf module:utils
132
+ */
133
+ export declare function runCommand<R = string>(command: string, opts?: SpawnOptionsWithoutStdio, outputConstructor?: OutputWriterConstructor<R, StandardOutputWriter<R>, Error>, ...args: unknown[]): CommandResult<R>;
@@ -0,0 +1,133 @@
1
+ import { ChildProcessWithoutNullStreams, SpawnOptionsWithoutStdio } from "child_process";
2
+ import { StandardOutputWriter } from "../writers/StandardOutputWriter.js";
3
+ import { CommandResult } from "./types.js";
4
+ import { OutputWriterConstructor } from "../writers/types.js";
5
+ import { Logger } from "@decaf-ts/logging";
6
+ /**
7
+ * @description Creates a locked version of a function.
8
+ * @summary This higher-order function takes a function and returns a new function that ensures
9
+ * sequential execution of the original function, even when called multiple times concurrently.
10
+ * It uses a Promise-based locking mechanism to queue function calls.
11
+ *
12
+ * @template R - The return type of the input function.
13
+ *
14
+ * @param f - The function to be locked. It can take any number of parameters and return a value of type R.
15
+ * @return A new function with the same signature as the input function, but with sequential execution guaranteed.
16
+ *
17
+ * @function lockify
18
+ *
19
+ * @mermaid
20
+ * sequenceDiagram
21
+ * participant Caller
22
+ * participant LockedFunction
23
+ * participant OriginalFunction
24
+ * Caller->>LockedFunction: Call with params
25
+ * LockedFunction->>LockedFunction: Check current lock
26
+ * alt Lock is resolved
27
+ * LockedFunction->>OriginalFunction: Execute with params
28
+ * OriginalFunction-->>LockedFunction: Return result
29
+ * LockedFunction-->>Caller: Return result
30
+ * else Lock is pending
31
+ * LockedFunction->>LockedFunction: Queue execution
32
+ * LockedFunction-->>Caller: Return promise
33
+ * Note over LockedFunction: Wait for previous execution
34
+ * LockedFunction->>OriginalFunction: Execute with params
35
+ * OriginalFunction-->>LockedFunction: Return result
36
+ * LockedFunction-->>Caller: Resolve promise with result
37
+ * end
38
+ * LockedFunction->>LockedFunction: Update lock
39
+ *
40
+ * @memberOf module:utils
41
+ */
42
+ export declare function lockify<R>(f: (...params: unknown[]) => R): (...params: unknown[]) => Promise<R>;
43
+ /**
44
+ * @description Chains multiple abort signals to a controller.
45
+ * @summary Creates a mechanism where multiple abort signals can trigger a single abort controller.
46
+ * This is useful for coordinating cancellation across multiple asynchronous operations.
47
+ *
48
+ * @param {AbortController} controller - The abort controller to be triggered by signals.
49
+ * @param {...AbortSignal} signals - One or more abort signals that can trigger the controller.
50
+ * @return {AbortController} The input controller, now connected to the signals.
51
+ *
52
+ * @function chainAbortController
53
+ *
54
+ * @memberOf module:utils
55
+ */
56
+ export declare function chainAbortController(controller: AbortController, ...signals: AbortSignal[]): AbortController;
57
+ /**
58
+ * @description Creates a new controller chained to multiple abort signals.
59
+ * @summary Creates a new abort controller that will be triggered if any of the provided signals are aborted.
60
+ *
61
+ * @param {...AbortSignal} signals - One or more abort signals that can trigger the new controller.
62
+ * @return {AbortController} A new abort controller connected to the signals.
63
+ *
64
+ * @function chainAbortController
65
+ *
66
+ * @memberOf module:utils
67
+ */
68
+ export declare function chainAbortController(...signals: AbortSignal[]): AbortController;
69
+ /**
70
+ * @description Spawns a command as a child process with output handling.
71
+ * @summary Creates a child process to execute a command with support for piping multiple commands,
72
+ * custom output handling, and abort control. This function handles the low-level details of
73
+ * spawning processes and connecting their inputs/outputs when piping is used.
74
+ *
75
+ * @template R - The type of the processed output, defaulting to string.
76
+ * @param {StandardOutputWriter<R>} output - The output writer to handle command output.
77
+ * @param {string} command - The command to execute, can include pipe operators.
78
+ * @param {SpawnOptionsWithoutStdio} opts - Options for the spawned process.
79
+ * @param {AbortController} abort - Controller to abort the command execution.
80
+ * @param {Logger} logger - Logger for recording command execution details.
81
+ * @return {ChildProcessWithoutNullStreams} The spawned child process.
82
+ *
83
+ * @function spawnCommand
84
+ *
85
+ * @memberOf module:utils
86
+ */
87
+ export declare function spawnCommand<R = string>(output: StandardOutputWriter<R>, command: string, opts: SpawnOptionsWithoutStdio, abort: AbortController, logger: Logger): ChildProcessWithoutNullStreams;
88
+ /**
89
+ * @description Executes a command asynchronously with customizable output handling.
90
+ * @summary This function runs a shell command as a child process, providing fine-grained
91
+ * control over its execution and output handling. It supports custom output writers,
92
+ * allows for command abortion, and captures both stdout and stderr.
93
+ *
94
+ * @template R - The type of the resolved value from the command execution.
95
+ *
96
+ * @param command - The command to run, either as a string or an array of strings.
97
+ * @param opts - Spawn options for the child process. Defaults to an empty object.
98
+ * @param outputConstructor - Constructor for the output writer. Defaults to StandardOutputWriter.
99
+ * @param args - Additional arguments to pass to the output constructor.
100
+ * @return {CommandResult} A promise that resolves to the command result of type R.
101
+ *
102
+ * @function runCommand
103
+ *
104
+ * @mermaid
105
+ * sequenceDiagram
106
+ * participant Caller
107
+ * participant runCommand
108
+ * participant OutputWriter
109
+ * participant ChildProcess
110
+ * Caller->>runCommand: Call with command and options
111
+ * runCommand->>OutputWriter: Create new instance
112
+ * runCommand->>OutputWriter: Parse command
113
+ * runCommand->>ChildProcess: Spawn process
114
+ * ChildProcess-->>runCommand: Return process object
115
+ * runCommand->>ChildProcess: Set up event listeners
116
+ * loop For each stdout data
117
+ * ChildProcess->>runCommand: Emit stdout data
118
+ * runCommand->>OutputWriter: Handle stdout data
119
+ * end
120
+ * loop For each stderr data
121
+ * ChildProcess->>runCommand: Emit stderr data
122
+ * runCommand->>OutputWriter: Handle stderr data
123
+ * end
124
+ * ChildProcess->>runCommand: Emit error (if any)
125
+ * runCommand->>OutputWriter: Handle error
126
+ * ChildProcess->>runCommand: Emit exit
127
+ * runCommand->>OutputWriter: Handle exit
128
+ * OutputWriter-->>runCommand: Resolve or reject promise
129
+ * runCommand-->>Caller: Return CommandResult
130
+ *
131
+ * @memberOf module:utils
132
+ */
133
+ export declare function runCommand<R = string>(command: string, opts?: SpawnOptionsWithoutStdio, outputConstructor?: OutputWriterConstructor<R, StandardOutputWriter<R>, Error>, ...args: unknown[]): CommandResult<R>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @description Defines the structure for output writing operations.
3
+ * @summary The OutputWriter interface provides a standardized set of methods for handling
4
+ * various types of output in a command-line interface (CLI) application. It includes
5
+ * methods for writing data, handling errors, and managing the program's exit process.
6
+ * This interface allows for consistent output handling across different parts of the application.
7
+ *
8
+ * @interface OutputWriter
9
+ * @memberOf module:utils
10
+ */
11
+ export interface OutputWriter {
12
+ /**
13
+ * @description Handles the output of data chunks.
14
+ * @summary Processes and writes a chunk of data to the output stream.
15
+ * This method is typically used for standard output operations.
16
+ *
17
+ * @param chunk - The data to be written. Can be of any type.
18
+ * @return void
19
+ */
20
+ data(chunk: any): void;
21
+ /**
22
+ * @description Handles error output.
23
+ * @summary Processes and writes error information to the error output stream.
24
+ * This method is used for non-critical errors or warnings.
25
+ *
26
+ * @param chunk - The error data to be written. Can be of any type.
27
+ * @return void
28
+ */
29
+ error(chunk: any): void;
30
+ /**
31
+ * @description Handles critical errors.
32
+ * @summary Processes and writes critical error information.
33
+ * This method is used for handling and reporting Error objects.
34
+ *
35
+ * @param err - The Error object to be processed and written.
36
+ * @return void
37
+ */
38
+ errors(err: Error): void;
39
+ /**
40
+ * @description Manages the program exit process.
41
+ * @summary Handles the termination of the program with a specified exit code.
42
+ * This method is called when the program needs to exit, either successfully or due to an error.
43
+ *
44
+ * @param code - The exit code to be used when terminating the program.
45
+ * @param logs - Array of log messages to be processed before exiting.
46
+ * @return void
47
+ */
48
+ exit(code: number, logs: string[]): void;
49
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @description Defines the structure for output writing operations.
3
+ * @summary The OutputWriter interface provides a standardized set of methods for handling
4
+ * various types of output in a command-line interface (CLI) application. It includes
5
+ * methods for writing data, handling errors, and managing the program's exit process.
6
+ * This interface allows for consistent output handling across different parts of the application.
7
+ *
8
+ * @interface OutputWriter
9
+ * @memberOf module:utils
10
+ */
11
+ export interface OutputWriter {
12
+ /**
13
+ * @description Handles the output of data chunks.
14
+ * @summary Processes and writes a chunk of data to the output stream.
15
+ * This method is typically used for standard output operations.
16
+ *
17
+ * @param chunk - The data to be written. Can be of any type.
18
+ * @return void
19
+ */
20
+ data(chunk: any): void;
21
+ /**
22
+ * @description Handles error output.
23
+ * @summary Processes and writes error information to the error output stream.
24
+ * This method is used for non-critical errors or warnings.
25
+ *
26
+ * @param chunk - The error data to be written. Can be of any type.
27
+ * @return void
28
+ */
29
+ error(chunk: any): void;
30
+ /**
31
+ * @description Handles critical errors.
32
+ * @summary Processes and writes critical error information.
33
+ * This method is used for handling and reporting Error objects.
34
+ *
35
+ * @param err - The Error object to be processed and written.
36
+ * @return void
37
+ */
38
+ errors(err: Error): void;
39
+ /**
40
+ * @description Manages the program exit process.
41
+ * @summary Handles the termination of the program with a specified exit code.
42
+ * This method is called when the program needs to exit, either successfully or due to an error.
43
+ *
44
+ * @param code - The exit code to be used when terminating the program.
45
+ * @param logs - Array of log messages to be processed before exiting.
46
+ * @return void
47
+ */
48
+ exit(code: number, logs: string[]): void;
49
+ }