matterbridge 3.4.6 → 3.4.7-dev-20260104-6b10cee

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 (354) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README-DOCKER.md +8 -0
  3. package/dist/broadcastServer.js +0 -117
  4. package/dist/broadcastServerTypes.js +0 -24
  5. package/dist/cli.js +1 -97
  6. package/dist/cliEmitter.js +0 -37
  7. package/dist/cliHistory.js +0 -38
  8. package/dist/clusters/export.js +0 -2
  9. package/dist/deviceManager.js +1 -113
  10. package/dist/devices/airConditioner.js +0 -57
  11. package/dist/devices/batteryStorage.js +1 -48
  12. package/dist/devices/cooktop.js +0 -56
  13. package/dist/devices/dishwasher.js +0 -57
  14. package/dist/devices/evse.js +10 -74
  15. package/dist/devices/export.js +0 -5
  16. package/dist/devices/extractorHood.js +0 -43
  17. package/dist/devices/heatPump.js +2 -50
  18. package/dist/devices/laundryDryer.js +3 -62
  19. package/dist/devices/laundryWasher.js +4 -70
  20. package/dist/devices/microwaveOven.js +5 -88
  21. package/dist/devices/oven.js +0 -85
  22. package/dist/devices/refrigerator.js +0 -102
  23. package/dist/devices/roboticVacuumCleaner.js +9 -100
  24. package/dist/devices/solarPower.js +0 -38
  25. package/dist/devices/speaker.js +0 -84
  26. package/dist/devices/temperatureControl.js +3 -24
  27. package/dist/devices/waterHeater.js +2 -82
  28. package/dist/dgram/coap.js +13 -126
  29. package/dist/dgram/dgram.js +6 -114
  30. package/dist/dgram/mb_coap.js +3 -41
  31. package/dist/dgram/mb_mdns.js +23 -77
  32. package/dist/dgram/mdns.js +139 -371
  33. package/dist/dgram/mdnsReflectorClient.js +5 -71
  34. package/dist/dgram/mdnsReflectorServer.js +8 -73
  35. package/dist/dgram/mdnsReflectorTypes.js +1 -24
  36. package/dist/dgram/multicast.js +1 -62
  37. package/dist/dgram/unicast.js +0 -60
  38. package/dist/frontend.js +38 -485
  39. package/dist/frontendTypes.js +0 -45
  40. package/dist/helpers.js +0 -53
  41. package/dist/index.js +0 -25
  42. package/dist/jestutils/export.js +0 -1
  43. package/dist/jestutils/jestHelpers.js +14 -371
  44. package/dist/logger/export.js +0 -1
  45. package/dist/matter/behaviors.js +0 -2
  46. package/dist/matter/clusters.js +0 -2
  47. package/dist/matter/devices.js +0 -2
  48. package/dist/matter/endpoints.js +0 -2
  49. package/dist/matter/export.js +0 -3
  50. package/dist/matter/types.js +0 -3
  51. package/dist/matterNode.js +8 -369
  52. package/dist/matterbridge.js +46 -824
  53. package/dist/matterbridgeAccessoryPlatform.js +0 -38
  54. package/dist/matterbridgeBehaviors.js +5 -68
  55. package/dist/matterbridgeDeviceTypes.js +14 -635
  56. package/dist/matterbridgeDynamicPlatform.js +0 -38
  57. package/dist/matterbridgeEndpoint.js +53 -1457
  58. package/dist/matterbridgeEndpointHelpers.js +20 -483
  59. package/dist/matterbridgeEndpointTypes.js +0 -25
  60. package/dist/matterbridgePlatform.js +1 -451
  61. package/dist/matterbridgeTypes.js +0 -26
  62. package/dist/pluginManager.js +5 -341
  63. package/dist/shelly.js +7 -178
  64. package/dist/storage/export.js +0 -1
  65. package/dist/update.js +1 -93
  66. package/dist/utils/colorUtils.js +2 -97
  67. package/dist/utils/commandLine.js +0 -60
  68. package/dist/utils/copyDirectory.js +0 -37
  69. package/dist/utils/createDirectory.js +0 -33
  70. package/dist/utils/createZip.js +2 -47
  71. package/dist/utils/deepCopy.js +0 -39
  72. package/dist/utils/deepEqual.js +1 -72
  73. package/dist/utils/error.js +0 -42
  74. package/dist/utils/export.js +0 -1
  75. package/dist/utils/format.js +0 -49
  76. package/dist/utils/hex.js +0 -124
  77. package/dist/utils/inspector.js +1 -69
  78. package/dist/utils/isValid.js +0 -93
  79. package/dist/utils/network.js +5 -125
  80. package/dist/utils/spawn.js +1 -71
  81. package/dist/utils/tracker.js +1 -64
  82. package/dist/utils/wait.js +8 -60
  83. package/dist/workerGlobalPrefix.js +5 -37
  84. package/dist/workerTypes.js +0 -24
  85. package/dist/workers.js +4 -68
  86. package/npm-shrinkwrap.json +25 -25
  87. package/package.json +1 -2
  88. package/packages/mb-lib-test/dist/jestutils/jestHelpers.d.ts +21 -0
  89. package/packages/mb-lib-test/dist/jestutils/jestHelpers.js +77 -0
  90. package/packages/mb-lib-test/dist/module.d.ts +2 -0
  91. package/packages/mb-lib-test/dist/module.js +2 -0
  92. package/packages/mb-lib-test/dist/vitestutils/vitestHelpers.d.ts +21 -0
  93. package/packages/mb-lib-test/dist/vitestutils/vitestHelpers.js +77 -0
  94. package/packages/mb-lib-test/package.json +12 -11
  95. package/reflector/DockerDesktopSetup.png +0 -0
  96. package/reflector/Reflector.md +158 -0
  97. package/reflector/ReflectorClient.png +0 -0
  98. package/reflector/ReflectorServer.png +0 -0
  99. package/reflector/docker-compose.yml +32 -0
  100. package/reflector/mDnsPacket.png +0 -0
  101. package/dist/broadcastServer.d.ts +0 -144
  102. package/dist/broadcastServer.d.ts.map +0 -1
  103. package/dist/broadcastServer.js.map +0 -1
  104. package/dist/broadcastServerTypes.d.ts +0 -841
  105. package/dist/broadcastServerTypes.d.ts.map +0 -1
  106. package/dist/broadcastServerTypes.js.map +0 -1
  107. package/dist/cli.d.ts +0 -30
  108. package/dist/cli.d.ts.map +0 -1
  109. package/dist/cli.js.map +0 -1
  110. package/dist/cliEmitter.d.ts +0 -50
  111. package/dist/cliEmitter.d.ts.map +0 -1
  112. package/dist/cliEmitter.js.map +0 -1
  113. package/dist/cliHistory.d.ts +0 -48
  114. package/dist/cliHistory.d.ts.map +0 -1
  115. package/dist/cliHistory.js.map +0 -1
  116. package/dist/clusters/export.d.ts +0 -2
  117. package/dist/clusters/export.d.ts.map +0 -1
  118. package/dist/clusters/export.js.map +0 -1
  119. package/dist/deviceManager.d.ts +0 -135
  120. package/dist/deviceManager.d.ts.map +0 -1
  121. package/dist/deviceManager.js.map +0 -1
  122. package/dist/devices/airConditioner.d.ts +0 -98
  123. package/dist/devices/airConditioner.d.ts.map +0 -1
  124. package/dist/devices/airConditioner.js.map +0 -1
  125. package/dist/devices/batteryStorage.d.ts +0 -48
  126. package/dist/devices/batteryStorage.d.ts.map +0 -1
  127. package/dist/devices/batteryStorage.js.map +0 -1
  128. package/dist/devices/cooktop.d.ts +0 -61
  129. package/dist/devices/cooktop.d.ts.map +0 -1
  130. package/dist/devices/cooktop.js.map +0 -1
  131. package/dist/devices/dishwasher.d.ts +0 -71
  132. package/dist/devices/dishwasher.d.ts.map +0 -1
  133. package/dist/devices/dishwasher.js.map +0 -1
  134. package/dist/devices/evse.d.ts +0 -76
  135. package/dist/devices/evse.d.ts.map +0 -1
  136. package/dist/devices/evse.js.map +0 -1
  137. package/dist/devices/export.d.ts +0 -17
  138. package/dist/devices/export.d.ts.map +0 -1
  139. package/dist/devices/export.js.map +0 -1
  140. package/dist/devices/extractorHood.d.ts +0 -46
  141. package/dist/devices/extractorHood.d.ts.map +0 -1
  142. package/dist/devices/extractorHood.js.map +0 -1
  143. package/dist/devices/heatPump.d.ts +0 -47
  144. package/dist/devices/heatPump.d.ts.map +0 -1
  145. package/dist/devices/heatPump.js.map +0 -1
  146. package/dist/devices/laundryDryer.d.ts +0 -67
  147. package/dist/devices/laundryDryer.d.ts.map +0 -1
  148. package/dist/devices/laundryDryer.js.map +0 -1
  149. package/dist/devices/laundryWasher.d.ts +0 -81
  150. package/dist/devices/laundryWasher.d.ts.map +0 -1
  151. package/dist/devices/laundryWasher.js.map +0 -1
  152. package/dist/devices/microwaveOven.d.ts +0 -168
  153. package/dist/devices/microwaveOven.d.ts.map +0 -1
  154. package/dist/devices/microwaveOven.js.map +0 -1
  155. package/dist/devices/oven.d.ts +0 -105
  156. package/dist/devices/oven.d.ts.map +0 -1
  157. package/dist/devices/oven.js.map +0 -1
  158. package/dist/devices/refrigerator.d.ts +0 -118
  159. package/dist/devices/refrigerator.d.ts.map +0 -1
  160. package/dist/devices/refrigerator.js.map +0 -1
  161. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  162. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  163. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  164. package/dist/devices/solarPower.d.ts +0 -40
  165. package/dist/devices/solarPower.d.ts.map +0 -1
  166. package/dist/devices/solarPower.js.map +0 -1
  167. package/dist/devices/speaker.d.ts +0 -87
  168. package/dist/devices/speaker.d.ts.map +0 -1
  169. package/dist/devices/speaker.js.map +0 -1
  170. package/dist/devices/temperatureControl.d.ts +0 -166
  171. package/dist/devices/temperatureControl.d.ts.map +0 -1
  172. package/dist/devices/temperatureControl.js.map +0 -1
  173. package/dist/devices/waterHeater.d.ts +0 -111
  174. package/dist/devices/waterHeater.d.ts.map +0 -1
  175. package/dist/devices/waterHeater.js.map +0 -1
  176. package/dist/dgram/coap.d.ts +0 -205
  177. package/dist/dgram/coap.d.ts.map +0 -1
  178. package/dist/dgram/coap.js.map +0 -1
  179. package/dist/dgram/dgram.d.ts +0 -143
  180. package/dist/dgram/dgram.d.ts.map +0 -1
  181. package/dist/dgram/dgram.js.map +0 -1
  182. package/dist/dgram/mb_coap.d.ts +0 -24
  183. package/dist/dgram/mb_coap.d.ts.map +0 -1
  184. package/dist/dgram/mb_coap.js.map +0 -1
  185. package/dist/dgram/mb_mdns.d.ts +0 -24
  186. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  187. package/dist/dgram/mb_mdns.js.map +0 -1
  188. package/dist/dgram/mdns.d.ts +0 -371
  189. package/dist/dgram/mdns.d.ts.map +0 -1
  190. package/dist/dgram/mdns.js.map +0 -1
  191. package/dist/dgram/mdnsReflectorClient.d.ts +0 -88
  192. package/dist/dgram/mdnsReflectorClient.d.ts.map +0 -1
  193. package/dist/dgram/mdnsReflectorClient.js.map +0 -1
  194. package/dist/dgram/mdnsReflectorServer.d.ts +0 -78
  195. package/dist/dgram/mdnsReflectorServer.d.ts.map +0 -1
  196. package/dist/dgram/mdnsReflectorServer.js.map +0 -1
  197. package/dist/dgram/mdnsReflectorTypes.d.ts +0 -28
  198. package/dist/dgram/mdnsReflectorTypes.d.ts.map +0 -1
  199. package/dist/dgram/mdnsReflectorTypes.js.map +0 -1
  200. package/dist/dgram/multicast.d.ts +0 -67
  201. package/dist/dgram/multicast.d.ts.map +0 -1
  202. package/dist/dgram/multicast.js.map +0 -1
  203. package/dist/dgram/unicast.d.ts +0 -64
  204. package/dist/dgram/unicast.d.ts.map +0 -1
  205. package/dist/dgram/unicast.js.map +0 -1
  206. package/dist/frontend.d.ts +0 -245
  207. package/dist/frontend.d.ts.map +0 -1
  208. package/dist/frontend.js.map +0 -1
  209. package/dist/frontendTypes.d.ts +0 -529
  210. package/dist/frontendTypes.d.ts.map +0 -1
  211. package/dist/frontendTypes.js.map +0 -1
  212. package/dist/helpers.d.ts +0 -48
  213. package/dist/helpers.d.ts.map +0 -1
  214. package/dist/helpers.js.map +0 -1
  215. package/dist/index.d.ts +0 -34
  216. package/dist/index.d.ts.map +0 -1
  217. package/dist/index.js.map +0 -1
  218. package/dist/jestutils/export.d.ts +0 -2
  219. package/dist/jestutils/export.d.ts.map +0 -1
  220. package/dist/jestutils/export.js.map +0 -1
  221. package/dist/jestutils/jestHelpers.d.ts +0 -345
  222. package/dist/jestutils/jestHelpers.d.ts.map +0 -1
  223. package/dist/jestutils/jestHelpers.js.map +0 -1
  224. package/dist/logger/export.d.ts +0 -2
  225. package/dist/logger/export.d.ts.map +0 -1
  226. package/dist/logger/export.js.map +0 -1
  227. package/dist/matter/behaviors.d.ts +0 -2
  228. package/dist/matter/behaviors.d.ts.map +0 -1
  229. package/dist/matter/behaviors.js.map +0 -1
  230. package/dist/matter/clusters.d.ts +0 -2
  231. package/dist/matter/clusters.d.ts.map +0 -1
  232. package/dist/matter/clusters.js.map +0 -1
  233. package/dist/matter/devices.d.ts +0 -2
  234. package/dist/matter/devices.d.ts.map +0 -1
  235. package/dist/matter/devices.js.map +0 -1
  236. package/dist/matter/endpoints.d.ts +0 -2
  237. package/dist/matter/endpoints.d.ts.map +0 -1
  238. package/dist/matter/endpoints.js.map +0 -1
  239. package/dist/matter/export.d.ts +0 -5
  240. package/dist/matter/export.d.ts.map +0 -1
  241. package/dist/matter/export.js.map +0 -1
  242. package/dist/matter/types.d.ts +0 -3
  243. package/dist/matter/types.d.ts.map +0 -1
  244. package/dist/matter/types.js.map +0 -1
  245. package/dist/matterNode.d.ts +0 -342
  246. package/dist/matterNode.d.ts.map +0 -1
  247. package/dist/matterNode.js.map +0 -1
  248. package/dist/matterbridge.d.ts +0 -505
  249. package/dist/matterbridge.d.ts.map +0 -1
  250. package/dist/matterbridge.js.map +0 -1
  251. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
  252. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  253. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  254. package/dist/matterbridgeBehaviors.d.ts +0 -2404
  255. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  256. package/dist/matterbridgeBehaviors.js.map +0 -1
  257. package/dist/matterbridgeDeviceTypes.d.ts +0 -698
  258. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  259. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  260. package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
  261. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  262. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  263. package/dist/matterbridgeEndpoint.d.ts +0 -1507
  264. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  265. package/dist/matterbridgeEndpoint.js.map +0 -1
  266. package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
  267. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  268. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  269. package/dist/matterbridgeEndpointTypes.d.ts +0 -166
  270. package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
  271. package/dist/matterbridgeEndpointTypes.js.map +0 -1
  272. package/dist/matterbridgePlatform.d.ts +0 -539
  273. package/dist/matterbridgePlatform.d.ts.map +0 -1
  274. package/dist/matterbridgePlatform.js.map +0 -1
  275. package/dist/matterbridgeTypes.d.ts +0 -252
  276. package/dist/matterbridgeTypes.d.ts.map +0 -1
  277. package/dist/matterbridgeTypes.js.map +0 -1
  278. package/dist/pluginManager.d.ts +0 -372
  279. package/dist/pluginManager.d.ts.map +0 -1
  280. package/dist/pluginManager.js.map +0 -1
  281. package/dist/shelly.d.ts +0 -181
  282. package/dist/shelly.d.ts.map +0 -1
  283. package/dist/shelly.js.map +0 -1
  284. package/dist/storage/export.d.ts +0 -2
  285. package/dist/storage/export.d.ts.map +0 -1
  286. package/dist/storage/export.js.map +0 -1
  287. package/dist/update.d.ts +0 -84
  288. package/dist/update.d.ts.map +0 -1
  289. package/dist/update.js.map +0 -1
  290. package/dist/utils/colorUtils.d.ts +0 -101
  291. package/dist/utils/colorUtils.d.ts.map +0 -1
  292. package/dist/utils/colorUtils.js.map +0 -1
  293. package/dist/utils/commandLine.d.ts +0 -66
  294. package/dist/utils/commandLine.d.ts.map +0 -1
  295. package/dist/utils/commandLine.js.map +0 -1
  296. package/dist/utils/copyDirectory.d.ts +0 -35
  297. package/dist/utils/copyDirectory.d.ts.map +0 -1
  298. package/dist/utils/copyDirectory.js.map +0 -1
  299. package/dist/utils/createDirectory.d.ts +0 -34
  300. package/dist/utils/createDirectory.d.ts.map +0 -1
  301. package/dist/utils/createDirectory.js.map +0 -1
  302. package/dist/utils/createZip.d.ts +0 -39
  303. package/dist/utils/createZip.d.ts.map +0 -1
  304. package/dist/utils/createZip.js.map +0 -1
  305. package/dist/utils/deepCopy.d.ts +0 -32
  306. package/dist/utils/deepCopy.d.ts.map +0 -1
  307. package/dist/utils/deepCopy.js.map +0 -1
  308. package/dist/utils/deepEqual.d.ts +0 -54
  309. package/dist/utils/deepEqual.d.ts.map +0 -1
  310. package/dist/utils/deepEqual.js.map +0 -1
  311. package/dist/utils/error.d.ts +0 -45
  312. package/dist/utils/error.d.ts.map +0 -1
  313. package/dist/utils/error.js.map +0 -1
  314. package/dist/utils/export.d.ts +0 -13
  315. package/dist/utils/export.d.ts.map +0 -1
  316. package/dist/utils/export.js.map +0 -1
  317. package/dist/utils/format.d.ts +0 -53
  318. package/dist/utils/format.d.ts.map +0 -1
  319. package/dist/utils/format.js.map +0 -1
  320. package/dist/utils/hex.d.ts +0 -89
  321. package/dist/utils/hex.d.ts.map +0 -1
  322. package/dist/utils/hex.js.map +0 -1
  323. package/dist/utils/inspector.d.ts +0 -87
  324. package/dist/utils/inspector.d.ts.map +0 -1
  325. package/dist/utils/inspector.js.map +0 -1
  326. package/dist/utils/isValid.d.ts +0 -103
  327. package/dist/utils/isValid.d.ts.map +0 -1
  328. package/dist/utils/isValid.js.map +0 -1
  329. package/dist/utils/network.d.ts +0 -140
  330. package/dist/utils/network.d.ts.map +0 -1
  331. package/dist/utils/network.js.map +0 -1
  332. package/dist/utils/spawn.d.ts +0 -33
  333. package/dist/utils/spawn.d.ts.map +0 -1
  334. package/dist/utils/spawn.js.map +0 -1
  335. package/dist/utils/tracker.d.ts +0 -108
  336. package/dist/utils/tracker.d.ts.map +0 -1
  337. package/dist/utils/tracker.js.map +0 -1
  338. package/dist/utils/wait.d.ts +0 -54
  339. package/dist/utils/wait.d.ts.map +0 -1
  340. package/dist/utils/wait.js.map +0 -1
  341. package/dist/workerGlobalPrefix.d.ts +0 -25
  342. package/dist/workerGlobalPrefix.d.ts.map +0 -1
  343. package/dist/workerGlobalPrefix.js.map +0 -1
  344. package/dist/workerTypes.d.ts +0 -52
  345. package/dist/workerTypes.d.ts.map +0 -1
  346. package/dist/workerTypes.js.map +0 -1
  347. package/dist/workers.d.ts +0 -69
  348. package/dist/workers.d.ts.map +0 -1
  349. package/dist/workers.js.map +0 -1
  350. package/scripts/data_model.mjs +0 -2058
  351. package/scripts/fetch-chip.mjs +0 -102
  352. package/scripts/marked.mjs +0 -133
  353. package/scripts/markedFooter.html +0 -42
  354. package/scripts/markedHeader.html +0 -78
@@ -1,44 +1,7 @@
1
- /**
2
- * This file contains the validation functions.
3
- *
4
- * @file isValid.ts
5
- * @author Luca Liguori
6
- * @created 2025-02-16
7
- * @version 1.0.1
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2025, 2026, 2027 Luca Liguori.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- /**
25
- * Checks if a given string is a valid IPv4 address.
26
- *
27
- * @param {string} ipv4Address - The string to be checked.
28
- * @returns {boolean} - Returns true if the string is a valid IPv4 address, otherwise returns false.
29
- */
30
1
  export function isValidIpv4Address(ipv4Address) {
31
2
  const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
32
3
  return ipv4Regex.test(ipv4Address);
33
4
  }
34
- /**
35
- * Checks if a value is a valid number within the specified range.
36
- *
37
- * @param {unknown} value - The value to be checked.
38
- * @param {number} min - The minimum value allowed (optional).
39
- * @param {number} max - The maximum value allowed (optional).
40
- * @returns {value is number} Returns true if the value is a valid number within the specified range, otherwise false.
41
- */
42
5
  export function isValidNumber(value, min, max) {
43
6
  if (value === undefined || value === null || typeof value !== 'number' || Number.isNaN(value) || !Number.isFinite(value))
44
7
  return false;
@@ -48,23 +11,9 @@ export function isValidNumber(value, min, max) {
48
11
  return false;
49
12
  return true;
50
13
  }
51
- /**
52
- * Checks if a value is a valid boolean.
53
- *
54
- * @param {unknown} value - The value to be checked.
55
- * @returns {value is boolean} `true` if the value is a valid boolean, `false` otherwise.
56
- */
57
14
  export function isValidBoolean(value) {
58
15
  return value !== undefined && value !== null && typeof value === 'boolean';
59
16
  }
60
- /**
61
- * Checks if a value is a valid string.
62
- *
63
- * @param {unknown} value - The value to be checked.
64
- * @param {number} minLength - The min string length (optional).
65
- * @param {number} maxLength - The max string length (optional).
66
- * @returns {value is string} A boolean indicating whether the value is a valid string.
67
- */
68
17
  export function isValidString(value, minLength, maxLength) {
69
18
  if (value === undefined || value === null || typeof value !== 'string')
70
19
  return false;
@@ -74,23 +23,9 @@ export function isValidString(value, minLength, maxLength) {
74
23
  return false;
75
24
  return true;
76
25
  }
77
- /**
78
- * Checks if a value is a valid RegExp.
79
- *
80
- * @param {unknown} value - The value to be checked.
81
- * @returns {value is RegExp} A boolean indicating whether the value is a valid RegExp.
82
- */
83
26
  export function isValidRegExp(value) {
84
27
  return value !== undefined && value !== null && value instanceof RegExp;
85
28
  }
86
- /**
87
- * Checks if a value is a valid object.
88
- *
89
- * @param {unknown} value - The value to be checked.
90
- * @param {number} minLength - The min number of keys (optional).
91
- * @param {number} maxLength - The max number of keys (optional).
92
- * @returns {value is object} A boolean indicating whether the value is a valid object.
93
- */
94
29
  export function isValidObject(value, minLength, maxLength) {
95
30
  if (value === undefined || value === null || typeof value !== 'object' || Array.isArray(value))
96
31
  return false;
@@ -101,14 +36,6 @@ export function isValidObject(value, minLength, maxLength) {
101
36
  return false;
102
37
  return true;
103
38
  }
104
- /**
105
- * Checks if a value is a valid array.
106
- *
107
- * @param {unknown} value - The value to be checked.
108
- * @param {number} minLength - The min number of elements (optional).
109
- * @param {number} maxLength - The max number of elements (optional).
110
- * @returns {value is unknown[]} A boolean indicating whether the value is a valid array.
111
- */
112
39
  export function isValidArray(value, minLength, maxLength) {
113
40
  if (value === undefined || value === null || !Array.isArray(value))
114
41
  return false;
@@ -118,31 +45,12 @@ export function isValidArray(value, minLength, maxLength) {
118
45
  return false;
119
46
  return true;
120
47
  }
121
- /**
122
- * Checks if the given value is null.
123
- *
124
- * @param {unknown} value - The value to check.
125
- * @returns {value is null} `true` if the value is null, `false` otherwise.
126
- */
127
48
  export function isValidNull(value) {
128
49
  return value === null;
129
50
  }
130
- /**
131
- * Checks if a value is undefined.
132
- *
133
- * @param {unknown} value - The value to check.
134
- * @returns {value is undefined} `true` if the value is undefined, `false` otherwise.
135
- */
136
51
  export function isValidUndefined(value) {
137
52
  return value === undefined;
138
53
  }
139
- /**
140
- * Converts a semantic version string like "6.11.0-1011-raspi" to a numeric version code like 61100.
141
- * Format: major * 10000 + minor * 100 + patch
142
- *
143
- * @param {string} versionString The version string to parse
144
- * @returns {number | undefined} A numeric version code or undefined if parsing fails
145
- */
146
54
  export function parseVersionString(versionString) {
147
55
  if (!isValidString(versionString))
148
56
  return undefined;
@@ -159,4 +67,3 @@ export function parseVersionString(versionString) {
159
67
  }
160
68
  return major * 10000 + minor * 100 + patch;
161
69
  }
162
- //# sourceMappingURL=isValid.js.map
@@ -1,34 +1,5 @@
1
- /**
2
- * @description This file contains the network functions.
3
- * @file network.ts
4
- * @author Luca Liguori
5
- * @created 2024-02-17
6
- * @version 1.0.1
7
- * @license Apache-2.0
8
- *
9
- * Copyright 2024, 2025, 2026 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
- // Node.js modules
24
1
  import os from 'node:os';
25
- // AnsiLogger module
26
2
  import { AnsiLogger, BLUE, CYAN, nf } from 'node-ansi-logger';
27
- /**
28
- * Retrieves the first non-internal network interface details.
29
- *
30
- * @returns {os.NetworkInterfaceInfo | undefined} The details of the selected network interface, or undefined if not found.
31
- */
32
3
  export function getInterfaceDetails() {
33
4
  const result = { interfaceName: '', ipv4Address: undefined, ipv6Address: undefined, macAddress: undefined };
34
5
  for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
@@ -50,11 +21,6 @@ export function getInterfaceDetails() {
50
21
  if (result.interfaceName)
51
22
  return result;
52
23
  }
53
- /**
54
- * Retrieves the first non-internal network interface name.
55
- *
56
- * @returns {string | undefined} The name of the selected network interface, or undefined if not found.
57
- */
58
24
  export function getInterfaceName() {
59
25
  for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
60
26
  if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
@@ -65,17 +31,6 @@ export function getInterfaceName() {
65
31
  }
66
32
  }
67
33
  }
68
- /**
69
- * Retrieves the IPv4 address of the first non-internal network interface.
70
- *
71
- * @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
72
- *
73
- * @remarks
74
- * Type of ipv4 addresses:
75
- * 192.168.x.x, 10.x.x.x, 172.16–31.x.x: RFC 1918 = Private networks
76
- * 169.254.0.0 – 169.254.255.255: APIPA = Automatic Private IP Addressing
77
- * 100.64.0.0 – 100.127.255.255: CGNAT = Carrier-Grade NAT RFC 6598 = Shared Address Space
78
- */
79
34
  export function getIpv4InterfaceAddress() {
80
35
  for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
81
36
  if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
@@ -86,34 +41,6 @@ export function getIpv4InterfaceAddress() {
86
41
  }
87
42
  }
88
43
  }
89
- /**
90
- * Retrieves the IPv6 address of the first non-internal network interface.
91
- *
92
- * If `scope` is true, appends a zone id (scope) for link-local addresses when
93
- * available:
94
- * - On Windows: uses `%<scopeid>` (e.g. `...%11`)
95
- * - On other platforms: uses `%<interfaceName>` (e.g. `...%eth0`)
96
- *
97
- * @param {boolean} [scope] - Whether to append a zone id when available.
98
- * @returns {string | undefined} The IPv6 address of the selected network interface, or undefined if not found.
99
- *
100
- * @remarks
101
- * Type of IPv6 addresses (preferred order for Matter)
102
- *
103
- * fd00::/8
104
- * - IPv6 ULA (Unique Local Address)
105
- * - Private IPv6 networks (RFC 4193)
106
- * - ✔ PREFERRED
107
- *
108
- * 2000::/3
109
- * - Global Unicast IPv6
110
- * - Publicly routable IPv6
111
- * - ⚠ OPTIONAL (advanced setups only)
112
- *
113
- * fe80::/10
114
- * - IPv6 Link-Local
115
- * - Interface-scoped only, non-routable
116
- */
117
44
  export function getIpv6InterfaceAddress(scope = false) {
118
45
  for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
119
46
  if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
@@ -123,7 +50,6 @@ export function getIpv6InterfaceAddress(scope = false) {
123
50
  const address = detail.address;
124
51
  if (!scope)
125
52
  return address;
126
- // Defensive check: if already has a zone id, keep it. Should never happen from os.networkInterfaces().
127
53
  if (address.includes('%'))
128
54
  return address;
129
55
  const isWindows = os.platform() === 'win32';
@@ -136,11 +62,6 @@ export function getIpv6InterfaceAddress(scope = false) {
136
62
  }
137
63
  }
138
64
  }
139
- /**
140
- * Retrieves the mac address of the first non-internal network interface.
141
- *
142
- * @returns {string | undefined} The mac address, or undefined if not found.
143
- */
144
65
  export function getMacAddress() {
145
66
  for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
146
67
  if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
@@ -151,14 +72,9 @@ export function getMacAddress() {
151
72
  }
152
73
  }
153
74
  }
154
- /**
155
- * Logs the available network interfaces and their details.
156
- *
157
- * @returns {void}
158
- */
159
75
  export function logInterfaces() {
160
- const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
161
- log.logLevel = "info" /* LogLevel.INFO */;
76
+ const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
77
+ log.logLevel = "info";
162
78
  log.logName = 'LogInterfaces';
163
79
  log.info('Available Network Interfaces:');
164
80
  const availableAddresses = Object.entries(os.networkInterfaces());
@@ -172,35 +88,16 @@ export function logInterfaces() {
172
88
  }
173
89
  }
174
90
  }
175
- /**
176
- * Resolves the given hostname to an IP address.
177
- *
178
- * @param {string} hostname - The hostname to resolve.
179
- * @param {0 | 4 | 6} [family] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
180
- * @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
181
- *
182
- * @remarks
183
- * This function uses DNS lookup to resolve the hostname, which can take some time to complete.
184
- */
185
91
  export async function resolveHostname(hostname, family = 4) {
186
92
  const dns = await import('node:dns');
187
93
  try {
188
- const addresses = await dns.promises.lookup(hostname.toLowerCase() /* + '.local'*/, { family });
94
+ const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
189
95
  return addresses.address;
190
96
  }
191
97
  catch (_error) {
192
98
  return null;
193
99
  }
194
100
  }
195
- /**
196
- * Retrieves the version of an npm package from the npm registry.
197
- *
198
- * @param {string} packageName - The name of the npm package.
199
- * @param {string} [tag] - The tag of the package version to retrieve (default is 'latest').
200
- * @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
201
- * @returns {Promise<string>} A promise that resolves to the version string of the package.
202
- * @throws {Error} If the request fails or the tag is not found.
203
- */
204
101
  export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
205
102
  const https = await import('node:https');
206
103
  return new Promise((resolve, reject) => {
@@ -214,7 +111,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
214
111
  let data = '';
215
112
  if (res.statusCode !== 200) {
216
113
  clearTimeout(timeoutId);
217
- res.resume(); // Discard response data to close the socket properly
114
+ res.resume();
218
115
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
219
116
  return;
220
117
  }
@@ -225,7 +122,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
225
122
  clearTimeout(timeoutId);
226
123
  try {
227
124
  const jsonData = JSON.parse(data);
228
- // console.log(`Package ${packageName} tag ${tag}`, jsonData);
229
125
  const version = jsonData['dist-tags']?.[tag];
230
126
  if (version) {
231
127
  resolve(version);
@@ -245,15 +141,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
245
141
  });
246
142
  });
247
143
  }
248
- /**
249
- * Retrieves a file from the public directory of the Matterbridge GitHub repository.
250
- *
251
- * @param {string} branch - The branch from which to fetch the file.
252
- * @param {string} file - The file path to fetch.
253
- * @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
254
- * @returns {Promise<Record<string, boolean | string | number>>} A promise that resolves to the parsed JSON object from the file.
255
- * @throws {Error} If the request fails or the JSON parsing fails.
256
- */
257
144
  export async function getGitHubUpdate(branch, file, timeout = 10000) {
258
145
  const https = await import('node:https');
259
146
  return new Promise((resolve, reject) => {
@@ -267,7 +154,7 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
267
154
  let data = '';
268
155
  if (res.statusCode !== 200) {
269
156
  clearTimeout(timeoutId);
270
- res.resume(); // Discard response data to close the socket properly
157
+ res.resume();
271
158
  reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
272
159
  return;
273
160
  }
@@ -285,18 +172,12 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
285
172
  }
286
173
  });
287
174
  });
288
- // istanbul ignore next cause it's just a precaution for network errors
289
175
  req.on('error', (error) => {
290
176
  clearTimeout(timeoutId);
291
177
  reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
292
178
  });
293
179
  });
294
180
  }
295
- /**
296
- * Retrieves the path to the global Node.js modules directory.
297
- *
298
- * @returns {Promise<string>} A promise that resolves to the path of the global Node.js modules directory.
299
- */
300
181
  export async function getGlobalNodeModules() {
301
182
  const { exec } = await import('node:child_process');
302
183
  return new Promise((resolve, reject) => {
@@ -310,4 +191,3 @@ export async function getGlobalNodeModules() {
310
191
  });
311
192
  });
312
193
  }
313
- //# sourceMappingURL=network.js.map
@@ -1,69 +1,28 @@
1
- /**
2
- * @description This file contains the spawn functions.
3
- * @file spawn.ts
4
- * @author Luca Liguori
5
- * @created 2025-02-16
6
- * @version 1.2.0
7
- * @license Apache-2.0
8
- *
9
- * Copyright 2025, 2026, 2027 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
1
  import { AnsiLogger } from 'node-ansi-logger';
24
2
  import { BroadcastServer } from '../broadcastServer.js';
25
3
  import { hasParameter } from './commandLine.js';
26
- /**
27
- * Spawns a child process with the given command and arguments.
28
- *
29
- * @param {string} command - The command to execute.
30
- * @param {string[]} args - The arguments to pass to the command (default: []).
31
- * @param {'install' | 'uninstall'} packageCommand - The optional package command being executed (e.g., 'install', 'uninstall').
32
- * @param {string} [packageName] - The optional name of the package being installed.
33
- * @returns {Promise<boolean>} A promise that resolves to true if the command executed successfully, false otherwise.
34
- */
35
4
  export async function spawnCommand(command, args, packageCommand, packageName) {
36
5
  const { spawn } = await import('node:child_process');
37
- /** Broadcast server */
38
6
  const debug = hasParameter('debug') || hasParameter('verbose');
39
7
  const verbose = hasParameter('verbose');
40
- const log = new AnsiLogger({ logName: 'Spawn', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: debug ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */ });
8
+ const log = new AnsiLogger({ logName: 'Spawn', logTimestampFormat: 4, logLevel: debug ? "debug" : "info" });
41
9
  const server = new BroadcastServer('spawn', log);
42
10
  const sendLog = (name, message) => {
43
11
  try {
44
12
  server.request({ type: 'frontend_logmessage', src: 'spawn', dst: 'frontend', params: { level: 'spawn', time: log.now(), name, message } });
45
13
  }
46
14
  catch (err) {
47
- // istanbul ignore next cause it's a precaution
48
15
  log.debug(`Failed to send log message to frontend: ${err instanceof Error ? err.message : String(err)}`);
49
16
  }
50
17
  };
51
18
  if (verbose)
52
19
  log.debug(`Spawning command: ${command} with ${args.join(' ')} ${packageCommand} ${packageName}`);
53
- /*
54
- * npm > npm.cmd on windows
55
- * cmd.exe ['dir'] on windows
56
- */
57
20
  const cmdLine = command + ' ' + args.join(' ');
58
21
  if (process.platform === 'win32' && command === 'npm') {
59
- // Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
60
22
  const argstring = 'npm ' + args.join(' ');
61
23
  args.splice(0, args.length, '/c', argstring);
62
24
  command = 'cmd.exe';
63
25
  }
64
- // Decide when using sudo on linux and macOS
65
- // When you need sudo: Spawn stderr: npm error Error: EACCES: permission denied
66
- // When you don't need sudo: Failed to start child process "npm install -g matterbridge-eve-door": spawn sudo ENOENT
67
26
  if (hasParameter('sudo') || (process.platform !== 'win32' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
68
27
  args.unshift(command);
69
28
  command = 'sudo';
@@ -119,20 +78,6 @@ export async function spawnCommand(command, args, packageCommand, packageName) {
119
78
  sendLog('Matterbridge:spawn', line);
120
79
  }
121
80
  });
122
- /*
123
- childProcess.stdout.on('close', () => {
124
- log.debug(`Spawn output (stdout): closed`);
125
- resolve(true);
126
- });
127
- childProcess.stdout.on('end', () => {
128
- log.debug(`Spawn output (stdout): ended`);
129
- resolve(true);
130
- });
131
- childProcess.stdout.on('error', () => {
132
- log.debug(`Spawn output (stdout): error`);
133
- resolve(true);
134
- });
135
- */
136
81
  }
137
82
  if (childProcess.stderr) {
138
83
  childProcess.stderr.on('data', (data) => {
@@ -143,23 +88,8 @@ export async function spawnCommand(command, args, packageCommand, packageName) {
143
88
  sendLog('Matterbridge:spawn', line);
144
89
  }
145
90
  });
146
- /*
147
- childProcess.stderr.on('close', () => {
148
- log.debug(`Spawn verbose (stderr): closed`);
149
- resolve(true);
150
- });
151
- childProcess.stderr.on('end', () => {
152
- log.debug(`Spawn verbose (stderr): ended`);
153
- resolve(true);
154
- });
155
- childProcess.stderr.on('error', () => {
156
- log.debug(`Spawn verbose (stderr): error`);
157
- resolve(true);
158
- });
159
- */
160
91
  }
161
92
  });
162
93
  server.close();
163
94
  return success;
164
95
  }
165
- //# sourceMappingURL=spawn.js.map
@@ -1,27 +1,3 @@
1
- /**
2
- * This file contains the Tracker class.
3
- *
4
- * @file tracker.ts
5
- * @author Luca Liguori
6
- * @created 2025-10-10
7
- * @version 1.0.0
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2025, 2026, 2027 Luca Liguori.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- /* eslint-disable no-console */
25
1
  if (process.argv.includes('--loader') || process.argv.includes('-loader'))
26
2
  console.log('\u001B[32mTracker loaded.\u001B[40;0m');
27
3
  import os from 'node:os';
@@ -34,7 +10,6 @@ export class Tracker extends EventEmitter {
34
10
  verbose;
35
11
  trackerInterval;
36
12
  static historyIndex = 0;
37
- // History for 8h at 1 sample each 10 seconds = 2880 entries
38
13
  static historySize = 2880;
39
14
  static history = Array.from({ length: this.historySize }, () => ({
40
15
  timestamp: 0,
@@ -71,7 +46,7 @@ export class Tracker extends EventEmitter {
71
46
  if (process.argv.includes('--verbose') || process.argv.includes('-verbose')) {
72
47
  this.verbose = true;
73
48
  }
74
- this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: this.debug ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */ });
49
+ this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4, logLevel: this.debug ? "debug" : "info" });
75
50
  this.log.logNameColor = YELLOW;
76
51
  if (this.verbose) {
77
52
  this.log.debug(`os.cpus():\n${RESET}`, os.cpus());
@@ -91,11 +66,6 @@ export class Tracker extends EventEmitter {
91
66
  this.runGarbageCollector();
92
67
  });
93
68
  }
94
- /**
95
- * Start tracking cpu and memory usage with a given interval in ms
96
- *
97
- * @param {number} sampleIntervalMs Sample interval in milliseconds. Default is 10000 (10 seconds).
98
- */
99
69
  start(sampleIntervalMs = 10000) {
100
70
  if (this.trackerInterval)
101
71
  return;
@@ -104,21 +74,15 @@ export class Tracker extends EventEmitter {
104
74
  this.prevCpus = os.cpus();
105
75
  this.prevCpuUsage = process.cpuUsage();
106
76
  this.trackerInterval = setInterval(() => {
107
- // Increment tryGcCount and check if we can run garbage collector each hour cause memory might grow over time because of our even small allocations
108
77
  tryGcCount += sampleIntervalMs / 1000;
109
78
  if (tryGcCount > 60 * 60) {
110
79
  this.runGarbageCollector();
111
80
  tryGcCount = 0;
112
81
  }
113
- // Get current history entry in circular buffer
114
82
  const entry = Tracker.history[Tracker.historyIndex];
115
- // Get previous history entry in circular buffer
116
83
  const prevEntry = Tracker.history[(Tracker.historyIndex + Tracker.historySize - 1) % Tracker.historySize];
117
- // Set the timestamp
118
84
  entry.timestamp = Date.now();
119
- // Emit uptime event
120
85
  this.emit('uptime', os.uptime(), process.uptime());
121
- // Track CPU usage
122
86
  const currentCpus = os.cpus();
123
87
  const loads = currentCpus.map((cpu, idx) => {
124
88
  const prev = this.prevCpus[idx]?.times;
@@ -130,7 +94,6 @@ export class Tracker extends EventEmitter {
130
94
  const totalDelta = busyDelta + idleDelta;
131
95
  if (totalDelta <= 0)
132
96
  return 0;
133
- // istanbul ignore next cause is practically impossible to hit this branch
134
97
  return busyDelta / totalDelta;
135
98
  });
136
99
  this.prevCpus = currentCpus;
@@ -138,16 +101,13 @@ export class Tracker extends EventEmitter {
138
101
  const osCpu = Number((avgLoad * 100).toFixed(2));
139
102
  entry.osCpu = osCpu;
140
103
  entry.peakOsCpu = Math.max(prevEntry.peakOsCpu, osCpu);
141
- // Track process CPU usage
142
104
  const diff = process.cpuUsage(this.prevCpuUsage);
143
105
  this.prevCpuUsage = process.cpuUsage();
144
106
  const totalMs = (diff.user + diff.system) / 1000;
145
107
  const processCpu = Number((((totalMs / sampleIntervalMs) * 100) / currentCpus.length).toFixed(2));
146
108
  entry.processCpu = processCpu;
147
109
  entry.peakProcessCpu = Math.max(prevEntry.peakProcessCpu, processCpu);
148
- // Emit cpu event
149
110
  this.emit('cpu', entry.osCpu, entry.processCpu);
150
- // Track memory usage
151
111
  entry.freeMemory = os.freemem();
152
112
  entry.peakFreeMemory = Math.max(prevEntry.peakFreeMemory, entry.freeMemory);
153
113
  entry.totalMemory = os.totalmem();
@@ -164,9 +124,7 @@ export class Tracker extends EventEmitter {
164
124
  entry.arrayBuffers = mem.arrayBuffers;
165
125
  entry.peakArrayBuffers = Math.max(prevEntry.peakArrayBuffers, mem.arrayBuffers);
166
126
  this.emit('memory', entry.freeMemory, entry.totalMemory, entry.rss, entry.heapUsed, entry.heapTotal, entry.external, entry.arrayBuffers);
167
- // Emit tracker event with current snapshot
168
127
  this.emit('snapshot', entry);
169
- // Debug output
170
128
  if (this.debug) {
171
129
  this.log.debug(`Time: ${formatTimeStamp(entry.timestamp)} ` +
172
130
  `os ${CYAN}${BRIGHT}${formatPercent(entry.osCpu)}${RESET}${db} (${entry.peakOsCpu > prevEntry.peakOsCpu ? RED : ''}${formatPercent(entry.peakOsCpu)}${db}) ` +
@@ -177,14 +135,10 @@ export class Tracker extends EventEmitter {
177
135
  `external: ${CYAN}${BRIGHT}${formatBytes(entry.external)}${RESET}${db} (${entry.peakExternal > prevEntry.peakExternal ? RED : ''}${formatBytes(entry.peakExternal)}${db}) ` +
178
136
  `arrayBuffers: ${CYAN}${BRIGHT}${formatBytes(entry.arrayBuffers)}${RESET}${db} (${entry.peakArrayBuffers > prevEntry.peakArrayBuffers ? RED : ''}${formatBytes(entry.peakArrayBuffers)}${db})`);
179
137
  }
180
- // Move to next history index of circular buffer
181
138
  Tracker.historyIndex = (Tracker.historyIndex + 1) % Tracker.historySize;
182
139
  }, sampleIntervalMs);
183
140
  this.log.debug(`Tracker started`);
184
141
  }
185
- /**
186
- * Reset peak values to the currently stored values
187
- */
188
142
  resetPeaks() {
189
143
  const prevHistoryIndex = (Tracker.historyIndex + Tracker.historySize - 1) % Tracker.historySize;
190
144
  Tracker.history[prevHistoryIndex].peakOsCpu = 0;
@@ -198,17 +152,6 @@ export class Tracker extends EventEmitter {
198
152
  this.log.debug(`${CYAN}${BRIGHT}Peaks reset at ${new Date(Date.now()).toLocaleString()}.${RESET}${db}`);
199
153
  this.emit('reset_peaks_done');
200
154
  }
201
- /**
202
- * Manually trigger garbage collection to free memory (if exposed with --expose-gc)
203
- *
204
- * @param {'major' | 'minor'} type - The type of garbage collection to perform ('major' or 'minor'). Default is 'major'.
205
- * @param {'sync' | 'async'} execution - The execution mode of garbage collection ('sync' or 'async'). Default is 'async'.
206
- *
207
- * @remarks
208
- * - major collection refers to old-generation mark-sweep/mark-compact cycles.
209
- * - minor collection refers to young-generation collections (scavenges).
210
- * - sync execution blocks the main thread until GC is complete, which can cause pauses.
211
- */
212
155
  runGarbageCollector(type = 'major', execution = 'async') {
213
156
  if (global.gc && typeof global.gc === 'function') {
214
157
  try {
@@ -229,20 +172,15 @@ export class Tracker extends EventEmitter {
229
172
  this.log.debug(`${CYAN}${BRIGHT}Garbage collection not exposed. Start Node.js with --expose-gc to enable manual garbage collection.${RESET}${db}`);
230
173
  }
231
174
  }
232
- /**
233
- * Stop tracking, clear interval, log history
234
- */
235
175
  stop() {
236
176
  this.log.debug(`Tracker stopping...`);
237
177
  if (this.trackerInterval) {
238
178
  clearInterval(this.trackerInterval);
239
179
  this.trackerInterval = undefined;
240
180
  }
241
- // Log all history entries
242
181
  if (this.debug) {
243
182
  this.log.debug(`Tracker history for ${YELLOW}${BRIGHT}${this.name}:${RESET}`);
244
183
  this.log.debug('Timestamp Host cpu Process cpu Rss Heap Used Heap Total External ArrayBuffers');
245
- // 10/10/2025, 20:52:12 4.76 % ( 4.76 %) 0.16 % ( 0.16 %) 38.45 MB ( 38.45 MB) 3.75 MB ( 3.75 MB) 5.29 MB ( 5.29 MB) 1.66 MB ( 1.66 MB) 10.25 KB ( 10.25 KB)
246
184
  for (let i = 0; i < Tracker.historySize; i++) {
247
185
  const index = (Tracker.historyIndex + i) % Tracker.historySize;
248
186
  const entry = Tracker.history[index];
@@ -261,4 +199,3 @@ export class Tracker extends EventEmitter {
261
199
  this.log.debug(`Tracker stopped`);
262
200
  }
263
201
  }
264
- //# sourceMappingURL=tracker.js.map