modestbench 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE.md +55 -0
  3. package/README.md +699 -0
  4. package/dist/bootstrap.cjs +37 -0
  5. package/dist/bootstrap.cjs.map +1 -0
  6. package/dist/bootstrap.d.cts +17 -0
  7. package/dist/bootstrap.d.cts.map +1 -0
  8. package/dist/bootstrap.d.ts +17 -0
  9. package/dist/bootstrap.d.ts.map +1 -0
  10. package/dist/bootstrap.js +33 -0
  11. package/dist/bootstrap.js.map +1 -0
  12. package/dist/cli/commands/history.cjs +459 -0
  13. package/dist/cli/commands/history.cjs.map +1 -0
  14. package/dist/cli/commands/history.d.cts +34 -0
  15. package/dist/cli/commands/history.d.cts.map +1 -0
  16. package/dist/cli/commands/history.d.ts +34 -0
  17. package/dist/cli/commands/history.d.ts.map +1 -0
  18. package/dist/cli/commands/history.js +422 -0
  19. package/dist/cli/commands/history.js.map +1 -0
  20. package/dist/cli/commands/init.cjs +566 -0
  21. package/dist/cli/commands/init.cjs.map +1 -0
  22. package/dist/cli/commands/init.d.cts +26 -0
  23. package/dist/cli/commands/init.d.cts.map +1 -0
  24. package/dist/cli/commands/init.d.ts +26 -0
  25. package/dist/cli/commands/init.d.ts.map +1 -0
  26. package/dist/cli/commands/init.js +562 -0
  27. package/dist/cli/commands/init.js.map +1 -0
  28. package/dist/cli/commands/run.cjs +285 -0
  29. package/dist/cli/commands/run.cjs.map +1 -0
  30. package/dist/cli/commands/run.d.cts +37 -0
  31. package/dist/cli/commands/run.d.cts.map +1 -0
  32. package/dist/cli/commands/run.d.ts +37 -0
  33. package/dist/cli/commands/run.d.ts.map +1 -0
  34. package/dist/cli/commands/run.js +248 -0
  35. package/dist/cli/commands/run.js.map +1 -0
  36. package/dist/cli/index.cjs +523 -0
  37. package/dist/cli/index.cjs.map +1 -0
  38. package/dist/cli/index.d.cts +58 -0
  39. package/dist/cli/index.d.cts.map +1 -0
  40. package/dist/cli/index.d.ts +58 -0
  41. package/dist/cli/index.d.ts.map +1 -0
  42. package/dist/cli/index.js +515 -0
  43. package/dist/cli/index.js.map +1 -0
  44. package/dist/config/manager.cjs +370 -0
  45. package/dist/config/manager.cjs.map +1 -0
  46. package/dist/config/manager.d.cts +46 -0
  47. package/dist/config/manager.d.cts.map +1 -0
  48. package/dist/config/manager.d.ts +46 -0
  49. package/dist/config/manager.d.ts.map +1 -0
  50. package/dist/config/manager.js +333 -0
  51. package/dist/config/manager.js.map +1 -0
  52. package/dist/config/schema.cjs +182 -0
  53. package/dist/config/schema.cjs.map +1 -0
  54. package/dist/config/schema.d.cts +51 -0
  55. package/dist/config/schema.d.cts.map +1 -0
  56. package/dist/config/schema.d.ts +51 -0
  57. package/dist/config/schema.d.ts.map +1 -0
  58. package/dist/config/schema.js +145 -0
  59. package/dist/config/schema.js.map +1 -0
  60. package/dist/constants.cjs +22 -0
  61. package/dist/constants.cjs.map +1 -0
  62. package/dist/constants.d.cts +10 -0
  63. package/dist/constants.d.cts.map +1 -0
  64. package/dist/constants.d.ts +10 -0
  65. package/dist/constants.d.ts.map +1 -0
  66. package/dist/constants.js +19 -0
  67. package/dist/constants.js.map +1 -0
  68. package/dist/core/benchmark-schema.cjs +135 -0
  69. package/dist/core/benchmark-schema.cjs.map +1 -0
  70. package/dist/core/benchmark-schema.d.cts +139 -0
  71. package/dist/core/benchmark-schema.d.cts.map +1 -0
  72. package/dist/core/benchmark-schema.d.ts +139 -0
  73. package/dist/core/benchmark-schema.d.ts.map +1 -0
  74. package/dist/core/benchmark-schema.js +132 -0
  75. package/dist/core/benchmark-schema.js.map +1 -0
  76. package/dist/core/engine.cjs +669 -0
  77. package/dist/core/engine.cjs.map +1 -0
  78. package/dist/core/engine.d.cts +128 -0
  79. package/dist/core/engine.d.cts.map +1 -0
  80. package/dist/core/engine.d.ts +128 -0
  81. package/dist/core/engine.d.ts.map +1 -0
  82. package/dist/core/engine.js +632 -0
  83. package/dist/core/engine.js.map +1 -0
  84. package/dist/core/engines/accurate-engine.cjs +292 -0
  85. package/dist/core/engines/accurate-engine.cjs.map +1 -0
  86. package/dist/core/engines/accurate-engine.d.cts +63 -0
  87. package/dist/core/engines/accurate-engine.d.cts.map +1 -0
  88. package/dist/core/engines/accurate-engine.d.ts +63 -0
  89. package/dist/core/engines/accurate-engine.d.ts.map +1 -0
  90. package/dist/core/engines/accurate-engine.js +288 -0
  91. package/dist/core/engines/accurate-engine.js.map +1 -0
  92. package/dist/core/engines/index.cjs +21 -0
  93. package/dist/core/engines/index.cjs.map +1 -0
  94. package/dist/core/engines/index.d.cts +16 -0
  95. package/dist/core/engines/index.d.cts.map +1 -0
  96. package/dist/core/engines/index.d.ts +16 -0
  97. package/dist/core/engines/index.d.ts.map +1 -0
  98. package/dist/core/engines/index.js +16 -0
  99. package/dist/core/engines/index.js.map +1 -0
  100. package/dist/core/engines/tinybench-engine.cjs +286 -0
  101. package/dist/core/engines/tinybench-engine.cjs.map +1 -0
  102. package/dist/core/engines/tinybench-engine.d.cts +18 -0
  103. package/dist/core/engines/tinybench-engine.d.cts.map +1 -0
  104. package/dist/core/engines/tinybench-engine.d.ts +18 -0
  105. package/dist/core/engines/tinybench-engine.d.ts.map +1 -0
  106. package/dist/core/engines/tinybench-engine.js +282 -0
  107. package/dist/core/engines/tinybench-engine.js.map +1 -0
  108. package/dist/core/error-manager.cjs +303 -0
  109. package/dist/core/error-manager.cjs.map +1 -0
  110. package/dist/core/error-manager.d.cts +77 -0
  111. package/dist/core/error-manager.d.cts.map +1 -0
  112. package/dist/core/error-manager.d.ts +77 -0
  113. package/dist/core/error-manager.d.ts.map +1 -0
  114. package/dist/core/error-manager.js +299 -0
  115. package/dist/core/error-manager.js.map +1 -0
  116. package/dist/core/loader.cjs +287 -0
  117. package/dist/core/loader.cjs.map +1 -0
  118. package/dist/core/loader.d.cts +55 -0
  119. package/dist/core/loader.d.cts.map +1 -0
  120. package/dist/core/loader.d.ts +55 -0
  121. package/dist/core/loader.d.ts.map +1 -0
  122. package/dist/core/loader.js +250 -0
  123. package/dist/core/loader.js.map +1 -0
  124. package/dist/core/stats-utils.cjs +99 -0
  125. package/dist/core/stats-utils.cjs.map +1 -0
  126. package/dist/core/stats-utils.d.cts +50 -0
  127. package/dist/core/stats-utils.d.cts.map +1 -0
  128. package/dist/core/stats-utils.d.ts +50 -0
  129. package/dist/core/stats-utils.d.ts.map +1 -0
  130. package/dist/core/stats-utils.js +94 -0
  131. package/dist/core/stats-utils.js.map +1 -0
  132. package/dist/index.cjs +64 -0
  133. package/dist/index.cjs.map +1 -0
  134. package/dist/index.d.cts +22 -0
  135. package/dist/index.d.cts.map +1 -0
  136. package/dist/index.d.ts +22 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +30 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/progress/manager.cjs +325 -0
  141. package/dist/progress/manager.cjs.map +1 -0
  142. package/dist/progress/manager.d.cts +125 -0
  143. package/dist/progress/manager.d.cts.map +1 -0
  144. package/dist/progress/manager.d.ts +125 -0
  145. package/dist/progress/manager.d.ts.map +1 -0
  146. package/dist/progress/manager.js +321 -0
  147. package/dist/progress/manager.js.map +1 -0
  148. package/dist/reporters/csv.cjs +250 -0
  149. package/dist/reporters/csv.cjs.map +1 -0
  150. package/dist/reporters/csv.d.cts +92 -0
  151. package/dist/reporters/csv.d.cts.map +1 -0
  152. package/dist/reporters/csv.d.ts +92 -0
  153. package/dist/reporters/csv.d.ts.map +1 -0
  154. package/dist/reporters/csv.js +246 -0
  155. package/dist/reporters/csv.js.map +1 -0
  156. package/dist/reporters/human.cjs +516 -0
  157. package/dist/reporters/human.cjs.map +1 -0
  158. package/dist/reporters/human.d.cts +86 -0
  159. package/dist/reporters/human.d.cts.map +1 -0
  160. package/dist/reporters/human.d.ts +86 -0
  161. package/dist/reporters/human.d.ts.map +1 -0
  162. package/dist/reporters/human.js +509 -0
  163. package/dist/reporters/human.js.map +1 -0
  164. package/dist/reporters/index.cjs +17 -0
  165. package/dist/reporters/index.cjs.map +1 -0
  166. package/dist/reporters/index.d.cts +10 -0
  167. package/dist/reporters/index.d.cts.map +1 -0
  168. package/dist/reporters/index.d.ts +10 -0
  169. package/dist/reporters/index.d.ts.map +1 -0
  170. package/dist/reporters/index.js +10 -0
  171. package/dist/reporters/index.js.map +1 -0
  172. package/dist/reporters/json.cjs +215 -0
  173. package/dist/reporters/json.cjs.map +1 -0
  174. package/dist/reporters/json.d.cts +79 -0
  175. package/dist/reporters/json.d.cts.map +1 -0
  176. package/dist/reporters/json.d.ts +79 -0
  177. package/dist/reporters/json.d.ts.map +1 -0
  178. package/dist/reporters/json.js +211 -0
  179. package/dist/reporters/json.js.map +1 -0
  180. package/dist/reporters/registry.cjs +255 -0
  181. package/dist/reporters/registry.cjs.map +1 -0
  182. package/dist/reporters/registry.d.cts +155 -0
  183. package/dist/reporters/registry.d.cts.map +1 -0
  184. package/dist/reporters/registry.d.ts +155 -0
  185. package/dist/reporters/registry.d.ts.map +1 -0
  186. package/dist/reporters/registry.js +249 -0
  187. package/dist/reporters/registry.js.map +1 -0
  188. package/dist/reporters/simple.cjs +328 -0
  189. package/dist/reporters/simple.cjs.map +1 -0
  190. package/dist/reporters/simple.d.cts +51 -0
  191. package/dist/reporters/simple.d.cts.map +1 -0
  192. package/dist/reporters/simple.d.ts +51 -0
  193. package/dist/reporters/simple.d.ts.map +1 -0
  194. package/dist/reporters/simple.js +321 -0
  195. package/dist/reporters/simple.js.map +1 -0
  196. package/dist/schema/modestbench-config.schema.json +162 -0
  197. package/dist/storage/history.cjs +456 -0
  198. package/dist/storage/history.cjs.map +1 -0
  199. package/dist/storage/history.d.cts +99 -0
  200. package/dist/storage/history.d.cts.map +1 -0
  201. package/dist/storage/history.d.ts +99 -0
  202. package/dist/storage/history.d.ts.map +1 -0
  203. package/dist/storage/history.js +452 -0
  204. package/dist/storage/history.js.map +1 -0
  205. package/dist/types/cli.cjs +21 -0
  206. package/dist/types/cli.cjs.map +1 -0
  207. package/dist/types/cli.d.cts +296 -0
  208. package/dist/types/cli.d.cts.map +1 -0
  209. package/dist/types/cli.d.ts +296 -0
  210. package/dist/types/cli.d.ts.map +1 -0
  211. package/dist/types/cli.js +18 -0
  212. package/dist/types/cli.js.map +1 -0
  213. package/dist/types/core.cjs +14 -0
  214. package/dist/types/core.cjs.map +1 -0
  215. package/dist/types/core.d.cts +380 -0
  216. package/dist/types/core.d.cts.map +1 -0
  217. package/dist/types/core.d.ts +380 -0
  218. package/dist/types/core.d.ts.map +1 -0
  219. package/dist/types/core.js +13 -0
  220. package/dist/types/core.js.map +1 -0
  221. package/dist/types/index.cjs +27 -0
  222. package/dist/types/index.cjs.map +1 -0
  223. package/dist/types/index.d.cts +11 -0
  224. package/dist/types/index.d.cts.map +1 -0
  225. package/dist/types/index.d.ts +11 -0
  226. package/dist/types/index.d.ts.map +1 -0
  227. package/dist/types/index.js +11 -0
  228. package/dist/types/index.js.map +1 -0
  229. package/dist/types/interfaces.cjs +10 -0
  230. package/dist/types/interfaces.cjs.map +1 -0
  231. package/dist/types/interfaces.d.cts +381 -0
  232. package/dist/types/interfaces.d.cts.map +1 -0
  233. package/dist/types/interfaces.d.ts +381 -0
  234. package/dist/types/interfaces.d.ts.map +1 -0
  235. package/dist/types/interfaces.js +9 -0
  236. package/dist/types/interfaces.js.map +1 -0
  237. package/dist/types/utility.cjs +92 -0
  238. package/dist/types/utility.cjs.map +1 -0
  239. package/dist/types/utility.d.cts +330 -0
  240. package/dist/types/utility.d.cts.map +1 -0
  241. package/dist/types/utility.d.ts +330 -0
  242. package/dist/types/utility.d.ts.map +1 -0
  243. package/dist/types/utility.js +78 -0
  244. package/dist/types/utility.js.map +1 -0
  245. package/package.json +211 -0
  246. package/src/bootstrap.ts +35 -0
  247. package/src/cli/commands/history.ts +569 -0
  248. package/src/cli/commands/init.ts +658 -0
  249. package/src/cli/commands/run.ts +346 -0
  250. package/src/cli/index.ts +642 -0
  251. package/src/config/manager.ts +387 -0
  252. package/src/config/schema.ts +188 -0
  253. package/src/constants.ts +21 -0
  254. package/src/core/benchmark-schema.ts +185 -0
  255. package/src/core/engine.ts +888 -0
  256. package/src/core/engines/accurate-engine.ts +408 -0
  257. package/src/core/engines/index.ts +16 -0
  258. package/src/core/engines/tinybench-engine.ts +335 -0
  259. package/src/core/error-manager.ts +372 -0
  260. package/src/core/loader.ts +324 -0
  261. package/src/core/stats-utils.ts +135 -0
  262. package/src/index.ts +46 -0
  263. package/src/progress/manager.ts +415 -0
  264. package/src/reporters/csv.ts +368 -0
  265. package/src/reporters/human.ts +707 -0
  266. package/src/reporters/index.ts +10 -0
  267. package/src/reporters/json.ts +302 -0
  268. package/src/reporters/registry.ts +349 -0
  269. package/src/reporters/simple.ts +459 -0
  270. package/src/storage/history.ts +600 -0
  271. package/src/types/cli.ts +312 -0
  272. package/src/types/core.ts +414 -0
  273. package/src/types/index.ts +18 -0
  274. package/src/types/interfaces.ts +451 -0
  275. package/src/types/utility.ts +446 -0
@@ -0,0 +1,446 @@
1
+ /**
2
+ * ModestBench Utility Types
3
+ *
4
+ * Defines utility types, helper functions, and common type transformations used
5
+ * throughout the ModestBench system.
6
+ */
7
+
8
+ /**
9
+ * Represents an async function
10
+ */
11
+ export type AsyncCallable<
12
+ TArgs extends readonly unknown[] = readonly unknown[],
13
+ TReturn = unknown,
14
+ > = (...args: TArgs) => Promise<TReturn>;
15
+
16
+ /**
17
+ * Async iterator interface
18
+ */
19
+ export interface AsyncIterable<T> {
20
+ [Symbol.asyncIterator](): AsyncIterator<T>;
21
+ }
22
+
23
+ /**
24
+ * Tuple with at least one element
25
+ */
26
+ export type AtLeastOne<T> = [T, ...T[]];
27
+
28
+ /**
29
+ * Branded type for creating nominal types
30
+ */
31
+ export type Brand<T, TBrand extends string> = T & { readonly __brand: TBrand };
32
+
33
+ /**
34
+ * Builder pattern interface
35
+ */
36
+ export interface Builder<T> {
37
+ build(): T;
38
+ }
39
+
40
+ /**
41
+ * Bytes count
42
+ */
43
+ export type Bytes = Brand<number, 'Bytes'>;
44
+
45
+ /**
46
+ * Cache interface
47
+ */
48
+ export interface Cache<TKey = string, TValue = unknown> {
49
+ clear(): void;
50
+ delete(key: TKey): boolean;
51
+ get(key: TKey): Option<TValue>;
52
+ has(key: TKey): boolean;
53
+ set(key: TKey, value: TValue, ttl?: number): void;
54
+ size(): number;
55
+ }
56
+
57
+ /**
58
+ * Represents a function that can be called with arguments
59
+ */
60
+ export type Callable<
61
+ TArgs extends readonly unknown[] = readonly unknown[],
62
+ TReturn = unknown,
63
+ > = (...args: TArgs) => TReturn;
64
+
65
+ /**
66
+ * Git commit hash
67
+ */
68
+ export type CommitHash = Brand<string, 'CommitHash'>;
69
+
70
+ /**
71
+ * Error with additional context
72
+ */
73
+ export interface ContextualError extends Error {
74
+ readonly code?: string;
75
+ readonly context?: Record<string, unknown>;
76
+ readonly severity?: 'critical' | 'high' | 'low' | 'medium';
77
+ }
78
+
79
+ /**
80
+ * CSV string representation
81
+ */
82
+ export type CsvString = Brand<string, 'CsvString'>;
83
+
84
+ /**
85
+ * Makes all properties in T deeply partial
86
+ */
87
+ export type DeepPartial<T> = {
88
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
89
+ };
90
+
91
+ /**
92
+ * Makes all properties in T deeply readonly
93
+ */
94
+ export type DeepReadonly<T> = {
95
+ readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
96
+ };
97
+
98
+ /**
99
+ * Directory path brand for type safety
100
+ */
101
+ export type DirectoryPath = Brand<string, 'DirectoryPath'>;
102
+
103
+ /**
104
+ * Disposable resource interface
105
+ */
106
+ export interface Disposable {
107
+ dispose(): MaybePromise<void>;
108
+ }
109
+
110
+ /**
111
+ * Environment variable name
112
+ */
113
+ export type EnvVar = Brand<string, 'EnvVar'>;
114
+
115
+ /**
116
+ * Event emitter interface
117
+ */
118
+ export interface EventEmitter<
119
+ TEvents extends Record<string, unknown> = Record<string, unknown>,
120
+ > {
121
+ emit<K extends keyof TEvents>(event: K, data: TEvents[K]): void;
122
+ off<K extends keyof TEvents>(
123
+ event: K,
124
+ listener: EventListener<TEvents[K]>,
125
+ ): void;
126
+ on<K extends keyof TEvents>(
127
+ event: K,
128
+ listener: EventListener<TEvents[K]>,
129
+ ): void;
130
+ once<K extends keyof TEvents>(
131
+ event: K,
132
+ listener: EventListener<TEvents[K]>,
133
+ ): void;
134
+ }
135
+
136
+ /**
137
+ * Event listener function type
138
+ */
139
+ export type EventListener<TData = unknown> = (
140
+ data: TData,
141
+ ) => MaybePromise<void>;
142
+
143
+ /**
144
+ * Factory interface for creating instances
145
+ */
146
+ export interface Factory<T, TOptions = unknown> {
147
+ create(options?: TOptions): T;
148
+ }
149
+
150
+ /**
151
+ * File path brand for type safety
152
+ */
153
+ export type FilePath = Brand<string, 'FilePath'>;
154
+
155
+ /**
156
+ * Integer number
157
+ */
158
+ export type Integer = Brand<number, 'Integer'>;
159
+
160
+ /**
161
+ * JSON string representation
162
+ */
163
+ export type JsonString = Brand<string, 'JsonString'>;
164
+
165
+ /**
166
+ * Extracts keys from T that have values assignable to U
167
+ */
168
+ export type KeysOfType<T, U> = {
169
+ [K in keyof T]: T[K] extends U ? K : never;
170
+ }[keyof T];
171
+
172
+ /**
173
+ * Logger interface
174
+ */
175
+ export interface Logger {
176
+ debug(message: string, ...args: unknown[]): void;
177
+ error(message: string, ...args: unknown[]): void;
178
+ info(message: string, ...args: unknown[]): void;
179
+ trace(message: string, ...args: unknown[]): void;
180
+ warn(message: string, ...args: unknown[]): void;
181
+ }
182
+
183
+ /**
184
+ * Represents a function that may be async or sync
185
+ */
186
+ export type MaybePromise<T> = Promise<T> | T;
187
+
188
+ /**
189
+ * Memory usage information
190
+ */
191
+ export interface MemoryUsage {
192
+ readonly arrayBuffers: Bytes;
193
+ readonly external: Bytes;
194
+ readonly heapTotal: Bytes;
195
+ readonly heapUsed: Bytes;
196
+ readonly rss: Bytes;
197
+ }
198
+
199
+ /**
200
+ * Duration in milliseconds
201
+ */
202
+ export type MillisecondDuration = Brand<number, 'MillisecondDuration'>;
203
+
204
+ /**
205
+ * Timestamp in milliseconds
206
+ */
207
+ export type MillisecondTimestamp = Brand<number, 'MillisecondTimestamp'>;
208
+
209
+ /**
210
+ * Duration in nanoseconds
211
+ */
212
+ export type NanoDuration = Brand<number, 'NanoDuration'>;
213
+
214
+ /**
215
+ * Timestamp in nanoseconds
216
+ */
217
+ export type NanosecondTimestamp = Brand<number, 'NanoTimestamp'>;
218
+
219
+ /**
220
+ * Non-empty array type
221
+ */
222
+ export type NonEmptyArray<T> = [T, ...T[]];
223
+
224
+ /**
225
+ * String that is not empty
226
+ */
227
+ export type NonEmptyString = Brand<string, 'NonEmptyString'>;
228
+
229
+ /**
230
+ * Non-negative number (>= 0)
231
+ */
232
+ export type NonNegativeNumber = Brand<number, 'NonNegativeNumber'>;
233
+
234
+ /**
235
+ * Option type for values that may not exist
236
+ */
237
+ export type Option<T> = null | T | undefined;
238
+
239
+ /**
240
+ * Makes specified keys K in T optional
241
+ */
242
+ export type OptionalKeys<T, K extends keyof T> = Omit<T, K> &
243
+ Partial<Pick<T, K>>;
244
+
245
+ /**
246
+ * Percentage value (0-100)
247
+ */
248
+ export type Percentage = Brand<number, 'Percentage'>;
249
+
250
+ /**
251
+ * Port number (1-65535)
252
+ */
253
+ export type Port = Brand<number, 'Port'>;
254
+
255
+ /**
256
+ * Positive number (> 0)
257
+ */
258
+ export type PositiveNumber = Brand<number, 'PositiveNumber'>;
259
+
260
+ /**
261
+ * Makes specified keys K in T required
262
+ */
263
+ export type RequiredKeys<T, K extends keyof T> = Required<Pick<T, K>> & T;
264
+
265
+ /**
266
+ * System resource usage
267
+ */
268
+ export interface ResourceUsage {
269
+ readonly cpu: {
270
+ readonly system: number;
271
+ readonly user: number;
272
+ };
273
+ readonly memory: MemoryUsage;
274
+ readonly timing: TimingInfo;
275
+ }
276
+
277
+ /**
278
+ * Result type for operations that can fail
279
+ */
280
+ export type Result<T, E = Error> =
281
+ | { readonly data: T; readonly success: true }
282
+ | { readonly error: E; readonly success: false };
283
+
284
+ /**
285
+ * Run identifier
286
+ */
287
+ export type RunId = Brand<string, 'RunId'>;
288
+
289
+ /**
290
+ * Configuration that can be serialized to JSON
291
+ */
292
+ export type SerializableConfig = {
293
+ readonly [K in string]:
294
+ | boolean
295
+ | null
296
+ | number
297
+ | readonly (boolean | null | number | string)[]
298
+ | readonly SerializableConfig[]
299
+ | SerializableConfig
300
+ | string;
301
+ };
302
+
303
+ /**
304
+ * Serializer interface
305
+ */
306
+ export interface Serializer<T, TSerialized = string> {
307
+ deserialize(serialized: TSerialized): T;
308
+ serialize(value: T): TSerialized;
309
+ }
310
+
311
+ /**
312
+ * Stream interface
313
+ */
314
+ export interface Stream<T> extends AsyncIterable<T> {
315
+ filter(predicate: (value: T) => boolean): Stream<T>;
316
+ pipe<U>(transform: (value: T) => U): Stream<U>;
317
+ skip(count: number): Stream<T>;
318
+ take(count: number): Stream<T>;
319
+ toArray(): Promise<T[]>;
320
+ }
321
+
322
+ /**
323
+ * Suite identifier
324
+ */
325
+ export type SuiteId = Brand<string, 'SuiteId'>;
326
+
327
+ /**
328
+ * Task identifier
329
+ */
330
+ export type TaskId = Brand<string, 'TaskId'>;
331
+
332
+ /**
333
+ * Timing information
334
+ */
335
+ export interface TimingInfo {
336
+ readonly duration: MillisecondDuration;
337
+ readonly end: MillisecondTimestamp;
338
+ readonly start: MillisecondTimestamp;
339
+ }
340
+
341
+ /**
342
+ * URL brand for type safety
343
+ */
344
+ export type Url = Brand<string, 'Url'>;
345
+
346
+ /**
347
+ * Validator interface
348
+ */
349
+ export interface Validator<T> {
350
+ validate(value: unknown): value is T;
351
+ validateAsync(value: unknown): Promise<boolean>;
352
+ }
353
+
354
+ /**
355
+ * YAML string representation
356
+ */
357
+ export type YamlString = Brand<string, 'YamlString'>;
358
+
359
+ /**
360
+ * Type predicate for checking if value is not null or undefined
361
+ */
362
+ export const isDefined = <T>(value: null | T | undefined): value is T => {
363
+ return value !== null && value !== undefined;
364
+ };
365
+
366
+ /**
367
+ * Type predicate for checking if value is a non-empty string
368
+ */
369
+ export const isNonEmptyString = (value: unknown): value is NonEmptyString => {
370
+ return typeof value === 'string' && value.length > 0;
371
+ };
372
+
373
+ /**
374
+ * Type predicate for checking if value is a positive number
375
+ */
376
+ export const isPositiveNumber = (value: unknown): value is PositiveNumber => {
377
+ return typeof value === 'number' && value > 0 && !Number.isNaN(value);
378
+ };
379
+
380
+ /**
381
+ * Type predicate for checking if value is a non-negative number
382
+ */
383
+ export const isNonNegativeNumber = (
384
+ value: unknown,
385
+ ): value is NonNegativeNumber => {
386
+ return typeof value === 'number' && value >= 0 && !Number.isNaN(value);
387
+ };
388
+
389
+ /**
390
+ * Type predicate for checking if value is an integer
391
+ */
392
+ export const isInteger = (value: unknown): value is Integer => {
393
+ return typeof value === 'number' && Number.isInteger(value);
394
+ };
395
+
396
+ /**
397
+ * Type predicate for checking if array is non-empty
398
+ */
399
+ export const isNonEmptyArray = <T>(value: T[]): value is NonEmptyArray<T> => {
400
+ return value.length > 0;
401
+ };
402
+
403
+ /**
404
+ * Creates a Result success value
405
+ */
406
+ export const success = <T>(data: T): Result<T, never> => ({
407
+ data,
408
+ success: true,
409
+ });
410
+
411
+ /**
412
+ * Creates a Result error value
413
+ */
414
+ export const failure = <E>(error: E): Result<never, E> => ({
415
+ error,
416
+ success: false,
417
+ });
418
+
419
+ /**
420
+ * Type assertion that a value is defined (throws if not)
421
+ */
422
+ export const assertDefined = <T>(
423
+ value: null | T | undefined,
424
+ message?: string,
425
+ ): T => {
426
+ if (!isDefined(value)) {
427
+ throw new Error(message ?? 'Value is null or undefined');
428
+ }
429
+ return value;
430
+ };
431
+
432
+ /**
433
+ * Creates a branded type value
434
+ */
435
+ export const brand = <T, TBrand extends string>(value: T): Brand<T, TBrand> => {
436
+ return value as Brand<T, TBrand>;
437
+ };
438
+
439
+ /**
440
+ * Removes brand from a branded type
441
+ */
442
+ export const unbrand = <T, TBrand extends string>(
443
+ value: Brand<T, TBrand>,
444
+ ): T => {
445
+ return value as T;
446
+ };