@camstack/server 1.2.928 → 1.2.930

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 (241) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +10 -10
  3. package/system/dist/addon-id-CVg1_r5E.mjs +39 -0
  4. package/system/dist/addon-id-Di0lNJ89.js +50 -0
  5. package/system/dist/addon-pages.cap-Df9FQwN1.js +49 -0
  6. package/system/dist/addon-pages.cap-DksUlE8j.mjs +44 -0
  7. package/system/dist/addon-settings.cap-3-TIIMq_.mjs +592 -0
  8. package/system/dist/addon-settings.cap-DAiE0Nb0.js +651 -0
  9. package/system/dist/addon-utils.mjs +1 -1
  10. package/system/dist/addon-widgets.cap-C4jxflbF.js +200 -0
  11. package/system/dist/addon-widgets.cap-D9m48X78.mjs +183 -0
  12. package/system/dist/base-addon-DD5dIfcZ.js +4624 -0
  13. package/system/dist/base-addon-Md14i7pe.mjs +4505 -0
  14. package/system/dist/base-device-2sL1DMm1.js +1103 -0
  15. package/system/dist/base-device-IuM1AwXZ.mjs +1098 -0
  16. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +8 -6
  17. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +6 -4
  18. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +8 -6
  19. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +7 -5
  20. package/system/dist/builtins/alerts/alerts.addon.js +113 -56
  21. package/system/dist/builtins/alerts/alerts.addon.mjs +60 -3
  22. package/system/dist/builtins/autotrack/index.js +21 -17
  23. package/system/dist/builtins/autotrack/index.mjs +5 -1
  24. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +14 -11
  25. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +8 -5
  26. package/system/dist/builtins/calendars/calendars.addon.js +8 -6
  27. package/system/dist/builtins/calendars/calendars.addon.mjs +3 -1
  28. package/system/dist/builtins/camera-grid/index.js +615 -58
  29. package/system/dist/builtins/camera-grid/index.mjs +558 -1
  30. package/system/dist/builtins/composer/composer.addon.js +788 -209
  31. package/system/dist/builtins/composer/composer.addon.mjs +583 -4
  32. package/system/dist/builtins/console-logging/index.js +4 -3
  33. package/system/dist/builtins/console-logging/index.mjs +2 -1
  34. package/system/dist/builtins/core-blocks/actions-service.d.ts +18 -1
  35. package/system/dist/builtins/core-blocks/core-blocks.addon.js +8670 -386
  36. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +8294 -11
  37. package/system/dist/builtins/core-blocks/tcp-connect.d.ts +3 -0
  38. package/system/dist/builtins/core-notifier/core-notifier.addon.js +250 -21
  39. package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +230 -1
  40. package/system/dist/builtins/device-history/device-history.addon.js +110 -31
  41. package/system/dist/builtins/device-history/device-history.addon.mjs +81 -2
  42. package/system/dist/builtins/device-manager/device-manager.addon.js +12806 -227
  43. package/system/dist/builtins/device-manager/device-manager.addon.mjs +12583 -5
  44. package/system/dist/builtins/hub-forwarder/index.js +4 -3
  45. package/system/dist/builtins/hub-forwarder/index.mjs +2 -1
  46. package/system/dist/builtins/keychain/index.js +31 -28
  47. package/system/dist/builtins/keychain/index.mjs +7 -4
  48. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +15 -12
  49. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +4 -1
  50. package/system/dist/builtins/local-auth/local-auth.addon.js +140 -39
  51. package/system/dist/builtins/local-auth/local-auth.addon.mjs +106 -6
  52. package/system/dist/builtins/local-network/local-network.addon.js +43 -39
  53. package/system/dist/builtins/local-network/local-network.addon.mjs +7 -3
  54. package/system/dist/builtins/loki-logging/index.js +23 -17
  55. package/system/dist/builtins/loki-logging/index.mjs +7 -1
  56. package/system/dist/builtins/native-metrics/native-metrics.addon.js +156 -15
  57. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +151 -10
  58. package/system/dist/builtins/platform-probe/index.js +25 -23
  59. package/system/dist/builtins/platform-probe/index.mjs +12 -10
  60. package/system/dist/builtins/record-entries/index.js +9 -7
  61. package/system/dist/builtins/record-entries/index.mjs +3 -1
  62. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +4 -4
  63. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  64. package/system/dist/builtins/snapshot/index.js +97 -44
  65. package/system/dist/builtins/snapshot/index.mjs +54 -1
  66. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +5 -4
  67. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +21 -20
  68. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  69. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  70. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +87 -61
  71. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +29 -3
  72. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +81 -72
  73. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +10 -1
  74. package/system/dist/builtins/system-config/system-config.addon.js +17 -14
  75. package/system/dist/builtins/system-config/system-config.addon.mjs +118 -115
  76. package/system/dist/builtins/winston-logging/index.js +7 -5
  77. package/system/dist/builtins/winston-logging/index.mjs +3 -1
  78. package/system/dist/calendars.cap-CaFlShS9.js +155 -0
  79. package/system/dist/calendars.cap-_C4eD4fi.mjs +138 -0
  80. package/system/dist/camstack-error-DJ-TUAi1.js +23 -0
  81. package/system/dist/camstack-error-viZYfcj9.mjs +18 -0
  82. package/system/dist/cap-call-context-Bd76CbOW.js +95 -0
  83. package/system/dist/cap-call-context-DNwdgGSQ.mjs +78 -0
  84. package/system/dist/capability-definition-C2rJdVeX.mjs +177 -0
  85. package/system/dist/capability-definition-HCmTem8c.js +242 -0
  86. package/system/dist/{capture-engine-BcuwOSXv.js → capture-engine-DZ0LIUqA.js} +5 -4
  87. package/system/dist/{capture-engine-Bz7eXFjT.mjs → capture-engine-DiwbjoWp.mjs} +2 -1
  88. package/system/dist/command-origin-claim-Cief660O.js +35 -0
  89. package/system/dist/command-origin-claim-D1Wy7Qld.mjs +24 -0
  90. package/system/dist/composition-sources-BEUWn2s_.mjs +391 -0
  91. package/system/dist/composition-sources-acfR4hDq.js +408 -0
  92. package/system/dist/{constants-D2etJ02O.js → constants-Ba3FTIHl.js} +1 -1
  93. package/system/dist/constants-C860Y6U4.js +26 -0
  94. package/system/dist/{constants-BcUTQd1M.mjs → constants-DB4piTD5.mjs} +1 -1
  95. package/system/dist/constants-DCLpoF4L.mjs +21 -0
  96. package/system/dist/coral-accelerators-7o8hqvcN.js +564 -0
  97. package/system/dist/coral-accelerators-BKcXP59c.mjs +521 -0
  98. package/system/dist/core-blocks.cap-BMeMCBrx.js +18733 -0
  99. package/system/dist/core-blocks.cap-BRPsLAij.mjs +18008 -0
  100. package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
  101. package/system/dist/custom-actions-BFUSalC9.mjs +25 -0
  102. package/system/dist/custom-actions-D92NRi2c.js +36 -0
  103. package/system/dist/database-snapshot.cap-DF38e-0P.js +162 -0
  104. package/system/dist/database-snapshot.cap-dhrc9xnY.mjs +133 -0
  105. package/system/dist/declared-device-BWphj9WE.js +303 -0
  106. package/system/dist/declared-device-CKERA1Hi.mjs +286 -0
  107. package/system/dist/{device-ca-ExMN3xW3.mjs → device-ca-BLM6fccc.mjs} +2 -1
  108. package/system/dist/{device-ca-CU8zh9Pi.js → device-ca-C5kJE6mL.js} +7 -6
  109. package/system/dist/device-certificate-Cddm4Idn.mjs +91 -0
  110. package/system/dist/device-certificate-CguVACQO.js +162 -0
  111. package/system/dist/device-identifiers-BQg9EQi1.js +600 -0
  112. package/system/dist/device-identifiers-iSuQCKmK.mjs +529 -0
  113. package/system/dist/device-kind-BJ2pfsjw.mjs +78 -0
  114. package/system/dist/device-kind-CsSiv_YF.js +101 -0
  115. package/system/dist/device-manager.cap-2abwVLCM.js +2874 -0
  116. package/system/dist/device-manager.cap-CFZSPfUh.mjs +2749 -0
  117. package/system/dist/device-provider.cap-3Uvk6f5-.mjs +331 -0
  118. package/system/dist/device-provider.cap-D7TV2kVH.js +366 -0
  119. package/system/dist/{device-row-store-CeW_GWh9.mjs → device-row-store-YF3jtmkk.mjs} +4 -1
  120. package/system/dist/{device-row-store-BMIR-n3m.js → device-row-store-doTfMOqn.js} +12 -9
  121. package/system/dist/device-transitions.cap-B5w5PYU_.js +860 -0
  122. package/system/dist/device-transitions.cap-DojcwEuX.mjs +819 -0
  123. package/system/dist/device-type-CbQsnFdC.js +477 -0
  124. package/system/dist/device-type-DgEvK3ch.mjs +454 -0
  125. package/system/dist/entry-kind-D9MuVJCK.mjs +44 -0
  126. package/system/dist/entry-kind-cq90c--V.js +55 -0
  127. package/system/dist/error.cap-CSM_SRfR.mjs +3423 -0
  128. package/system/dist/error.cap-DBhgPeWK.js +3848 -0
  129. package/system/dist/file-host-worker.js +1 -1
  130. package/system/dist/file-host-worker.mjs +1 -1
  131. package/system/dist/history-catalog-BKRarIL_.js +831 -0
  132. package/system/dist/history-catalog-BwTeQ4Mr.mjs +802 -0
  133. package/system/dist/{hub-identity-Csxx2Q8k.js → hub-identity-BMdR3Mw9.js} +2 -2
  134. package/system/dist/{hub-identity-CYC1820R.mjs → hub-identity-DjMN9Ac2.mjs} +10 -10
  135. package/system/dist/{hub-mdns-ciao-By5577HM.js → hub-mdns-ciao--0v1TKME.js} +5 -5
  136. package/system/dist/{hub-mdns-ciao-CCDxM5qz.mjs → hub-mdns-ciao-DBrtHOcc.mjs} +2 -2
  137. package/system/dist/index.js +763 -151
  138. package/system/dist/index.mjs +832 -220
  139. package/system/dist/integration-instances.cap-Cl9O-k4h.mjs +538 -0
  140. package/system/dist/integration-instances.cap-dJIxg2_s.js +549 -0
  141. package/system/dist/keychain-admin.cap-Db_oFX4H.js +425 -0
  142. package/system/dist/keychain-admin.cap-GtM7gVGG.mjs +396 -0
  143. package/system/dist/l10n-Bu6aUvSY.mjs +10 -0
  144. package/system/dist/l10n-CGMvp7NF.js +15 -0
  145. package/system/dist/labels-DX5S8deC.js +81 -0
  146. package/system/dist/labels-DsBcU7md.mjs +64 -0
  147. package/system/dist/{legacy-integration-rows-door-CVwOo5aq.js → legacy-integration-rows-door-B1nzxxr5.js} +2 -2
  148. package/system/dist/{legacy-integration-rows-door-D9tQOUzh.mjs → legacy-integration-rows-door-nTvo_6jQ.mjs} +1 -1
  149. package/system/dist/log-destination.cap-CxZzAVaR.mjs +143 -0
  150. package/system/dist/log-destination.cap-DELPJkZ0.js +148 -0
  151. package/system/dist/low-power-sleep.cap-7lfVU41N.js +103 -0
  152. package/system/dist/low-power-sleep.cap-tGPmaZ_V.mjs +92 -0
  153. package/system/dist/mask-shape-Ci8Co9w0.mjs +57 -0
  154. package/system/dist/mask-shape-CmPA2fst.js +92 -0
  155. package/system/dist/metrics-provider.cap-BNmcHDkQ.mjs +405 -0
  156. package/system/dist/metrics-provider.cap-BcmQUt6l.js +410 -0
  157. package/system/dist/migration-BMjgkyG2.js +380 -0
  158. package/system/dist/migration-DRJAtdy7.mjs +321 -0
  159. package/system/dist/network-access.cap-B5TWLDCC.js +1099 -0
  160. package/system/dist/network-access.cap-BJnGbE6n.mjs +1004 -0
  161. package/system/dist/notification-rules.cap-BDh0LDhV.js +3428 -0
  162. package/system/dist/notification-rules.cap-DUmiMBQB.mjs +3357 -0
  163. package/system/dist/notification-targets-CRH-9Dy5.js +509 -0
  164. package/system/dist/notification-targets-DaNE-pIt.mjs +486 -0
  165. package/system/dist/ops-log-CB4pIdqi.mjs +64 -0
  166. package/system/dist/ops-log-pxt9176Z.js +81 -0
  167. package/system/dist/pinned-binary-BOhOSNff.js +28 -0
  168. package/system/dist/pinned-binary-CrIRAi4G.mjs +23 -0
  169. package/system/dist/platform-probe.cap-1WrMhWHx.js +250 -0
  170. package/system/dist/platform-probe.cap-BFeqFLtQ.mjs +233 -0
  171. package/system/dist/prefix-walk-BkMxoXpL.js +843 -0
  172. package/system/dist/prefix-walk-ifwg_ukx.mjs +790 -0
  173. package/system/dist/ptz-autotrack.cap-BW7w0zHD.js +229 -0
  174. package/system/dist/ptz-autotrack.cap-DT2GypXw.mjs +224 -0
  175. package/system/dist/quantity-D3g5SxsZ.mjs +114 -0
  176. package/system/dist/quantity-lY1KiTSZ.js +143 -0
  177. package/system/dist/raw-secret-migration-DxuBFtvi.js +50 -0
  178. package/system/dist/raw-secret-migration-iv88mLoc.mjs +39 -0
  179. package/system/dist/record-entries.cap-sMUhTvTU.mjs +75 -0
  180. package/system/dist/record-entries.cap-ti1C046R.js +80 -0
  181. package/system/dist/record-kind-DoBfYHCs.js +203 -0
  182. package/system/dist/record-kind-ub6NXqfh.mjs +162 -0
  183. package/system/dist/recording-archive.cap-7OrIn9e5.mjs +1299 -0
  184. package/system/dist/recording-archive.cap-D7bo-QSM.js +1328 -0
  185. package/system/dist/records.cap-ClcWV64i.js +329 -0
  186. package/system/dist/records.cap-CwLT2ByG.mjs +294 -0
  187. package/system/dist/relocate-CdVQAk-w.js +804 -0
  188. package/system/dist/relocate-CoZZTui1.mjs +661 -0
  189. package/system/dist/rename-composition-block-BJsL58Ih.js +34798 -0
  190. package/system/dist/rename-composition-block-OAtErZgq.mjs +33631 -0
  191. package/system/dist/{restore-archive-BJfyu0sG.mjs → restore-archive-CjAyKpgX.mjs} +96 -94
  192. package/system/dist/{restore-archive-CIFvqOze.js → restore-archive-CkTkv3Ss.js} +6 -4
  193. package/system/dist/scoped-settings-CylSSq_8.js +955 -0
  194. package/system/dist/scoped-settings-DVWUIP7Z.mjs +650 -0
  195. package/system/dist/server-name-BIhLuHvX.mjs +35 -0
  196. package/system/dist/server-name-OALNvpqC.js +52 -0
  197. package/system/dist/settings-store.cap-Ci4F2zul.mjs +569 -0
  198. package/system/dist/settings-store.cap-wlJhCspr.js +640 -0
  199. package/system/dist/snapshot.cap-3suPdBHV.js +250 -0
  200. package/system/dist/snapshot.cap-Bs8Oyaqh.mjs +245 -0
  201. package/system/dist/source-info-DGB7SdB_.mjs +190 -0
  202. package/system/dist/source-info-DtWf4k2j.js +225 -0
  203. package/system/dist/storage-admin.cap-BSv1NjKJ.mjs +883 -0
  204. package/system/dist/storage-admin.cap-he0OqvVM.js +906 -0
  205. package/system/dist/storage-location-CBT8GCD6.mjs +163 -0
  206. package/system/dist/storage-location-CTweDMZf.js +198 -0
  207. package/system/dist/storage-location-mode-B21UVRRX.mjs +167 -0
  208. package/system/dist/storage-location-mode-CS4sMzo-.js +232 -0
  209. package/system/dist/storage-migration.cap-CyyATY_p.js +330 -0
  210. package/system/dist/storage-migration.cap-D7QqGobp.mjs +313 -0
  211. package/system/dist/storage-occupancy.cap-2rmnS58Z.js +622 -0
  212. package/system/dist/storage-occupancy.cap-CqBztTl9.mjs +611 -0
  213. package/system/dist/storage-provider.cap-Bw0CfxVc.js +213 -0
  214. package/system/dist/storage-provider.cap-CMeck2w4.mjs +202 -0
  215. package/system/dist/stream-catalog.cap-Bp7SkgIf.mjs +6560 -0
  216. package/system/dist/stream-catalog.cap-D3uwePiA.js +6763 -0
  217. package/system/dist/streaming-shared-B8cXatuU.mjs +431 -0
  218. package/system/dist/streaming-shared-DQwFZOSi.js +526 -0
  219. package/system/dist/system-reasons-Be_k1W8g.js +25 -0
  220. package/system/dist/system-reasons-CYj4qwyS.mjs +20 -0
  221. package/system/dist/tag-BxLazvVb.js +2138 -0
  222. package/system/dist/tag-uZBAq6ox.mjs +2073 -0
  223. package/system/dist/user-management.cap-B9QDu8NE.js +825 -0
  224. package/system/dist/user-management.cap-DBIi77sB.mjs +766 -0
  225. package/system/dist/vector-store.cap-DnyfrYDn.js +330 -0
  226. package/system/dist/vector-store.cap-h2GHWQ1t.mjs +319 -0
  227. package/system/dist/{wal-maintenance-CTrCPzds.mjs → wal-maintenance-BG01rOn9.mjs} +0 -0
  228. package/system/dist/{wal-maintenance-dq7T3quB.js → wal-maintenance-DyrebYKF.js} +0 -0
  229. package/system/dist/zod-secret-DS7mj1bk.js +78 -0
  230. package/system/dist/zod-secret-zY4nM61M.mjs +73 -0
  231. package/system/package.json +1 -1
  232. package/system/dist/composition-sources-BI614LJx.mjs +0 -141
  233. package/system/dist/composition-sources-v_kkb8A9.js +0 -152
  234. package/system/dist/coral-accelerators-BSVsBVzt.js +0 -250
  235. package/system/dist/coral-accelerators-BW3OcrLD.mjs +0 -231
  236. package/system/dist/dist-BCHMSqzc.mjs +0 -143467
  237. package/system/dist/dist-BZfvhfS1.js +0 -146970
  238. package/system/dist/prefix-walk-DAOBSyH1.mjs +0 -88
  239. package/system/dist/prefix-walk-Dv6MLZlM.js +0 -99
  240. package/system/dist/rename-composition-block-C9HuBrKS.js +0 -112
  241. package/system/dist/rename-composition-block-DtaYmYAR.mjs +0 -101
@@ -0,0 +1,843 @@
1
+ const require_core_blocks_cap = require("./core-blocks.cap-BMeMCBrx.js");
2
+ const require_error_cap = require("./error.cap-DBhgPeWK.js");
3
+ const require_prefix_range = require("./prefix-range-D_KueXbQ.js");
4
+ //#region ../types/dist/esm/time/time-window.mjs
5
+ /**
6
+ * A daily window as a STATE: is this instant inside it, and when does that
7
+ * next change? Pure — the answer is built per local date from
8
+ * {@link occurrenceOn}, so a DST change needs no special case.
9
+ *
10
+ * Rules:
11
+ * - A window whose `to` is not after its `from` on the same local date WRAPS:
12
+ * it runs from `from` on day D to `to` on D+1.
13
+ * - `days` names the local day a window STARTS on. 22:00-06:00 on weekdays is
14
+ * inside at 01:00 Saturday (it started Friday). With `days` and no
15
+ * `between` the window is the whole local day.
16
+ * - A sun event that does not happen on a day (polar day or night) gives that
17
+ * day no window. A sun event on a site WITHOUT a location (or an unknown
18
+ * zone) cannot be judged at all: the result is `unknown`, never a guess.
19
+ */
20
+ var MIDNIGHT = {
21
+ kind: "clock",
22
+ hh: 0,
23
+ mm: 0
24
+ };
25
+ /** Start dates looked at for a boundary: yesterday .. the day after tomorrow. */
26
+ var LOOKAHEAD_DAYS = 2;
27
+ function addDays(localDate, days) {
28
+ const [y, m, d] = localDate.split("-").map(Number);
29
+ return new Date(Date.UTC(y ?? 0, (m ?? 1) - 1, (d ?? 1) + days)).toISOString().slice(0, 10);
30
+ }
31
+ function unresolvable(window, site) {
32
+ if (!require_core_blocks_cap.isKnownTimeZone(site.timeZone)) return `the site time zone "${site.timeZone}" is not a known IANA zone`;
33
+ if (window.between !== void 0 && (window.between.from.kind === "sun" || window.between.to.kind === "sun") && site.zoneOnly === true) return "a sun time needs the site location, and none is set";
34
+ return null;
35
+ }
36
+ /** The interval that STARTS on local day `startDate`, or null when that day has none. */
37
+ function intervalStartingOn(window, startDate, site) {
38
+ if (window.days !== void 0 && !window.days.includes(require_core_blocks_cap.weekdayOfLocalDate(startDate))) return null;
39
+ if (window.between === void 0) {
40
+ const start = require_core_blocks_cap.occurrenceOn(MIDNIGHT, startDate, site);
41
+ const end = require_core_blocks_cap.occurrenceOn(MIDNIGHT, addDays(startDate, 1), site);
42
+ return start === null || end === null ? null : {
43
+ start,
44
+ end
45
+ };
46
+ }
47
+ const start = require_core_blocks_cap.occurrenceOn(window.between.from, startDate, site);
48
+ const sameDayEnd = require_core_blocks_cap.occurrenceOn(window.between.to, startDate, site);
49
+ if (start === null || sameDayEnd === null) return null;
50
+ if (sameDayEnd > start) return {
51
+ start,
52
+ end: sameDayEnd
53
+ };
54
+ const end = require_core_blocks_cap.occurrenceOn(window.between.to, addDays(startDate, 1), site);
55
+ return end === null || end <= start ? null : {
56
+ start,
57
+ end
58
+ };
59
+ }
60
+ function judgeTimeWindow(window, nowMs, site) {
61
+ const blocked = unresolvable(window, site);
62
+ if (blocked !== null) return {
63
+ inside: false,
64
+ unknown: true,
65
+ nextChangeAtMs: null,
66
+ why: `cannot be judged: ${blocked}`
67
+ };
68
+ const today = require_core_blocks_cap.localDateOf(nowMs, site.timeZone);
69
+ let inside = false;
70
+ let next = null;
71
+ for (let offset = -1; offset <= LOOKAHEAD_DAYS; offset += 1) {
72
+ const interval = intervalStartingOn(window, addDays(today, offset), site);
73
+ if (interval === null) continue;
74
+ if (interval.start <= nowMs && nowMs < interval.end) inside = true;
75
+ for (const boundary of [interval.start, interval.end]) if (boundary > nowMs && (next === null || boundary < next)) next = boundary;
76
+ }
77
+ if (window.between === void 0) {
78
+ const midnight = require_core_blocks_cap.occurrenceOn(MIDNIGHT, addDays(today, 1), site);
79
+ if (midnight !== null && midnight > nowMs && (next === null || midnight < next)) next = midnight;
80
+ }
81
+ const days = window.days === void 0 ? "" : ` on ${window.days.join(", ")}`;
82
+ const span = window.between === void 0 ? "the whole day" : "the window";
83
+ return {
84
+ inside,
85
+ unknown: false,
86
+ nextChangeAtMs: next,
87
+ why: inside ? `inside ${span}${days}` : `outside ${span}${days}`
88
+ };
89
+ }
90
+ //#endregion
91
+ //#region ../types/dist/esm/automation/condition-eval.mjs
92
+ /**
93
+ * Evaluating an automation's condition tree against the ConditionMirror.
94
+ *
95
+ * D49: a trigger is a one-shot event, so its gate must never hang on a read
96
+ * that can fail. Every field a condition leaf names is therefore kept in
97
+ * memory — filled at start, updated off device state-changed events, reconciled
98
+ * on a timer — and evaluation reads that memory ONLY. A value the mirror does
99
+ * not hold is UNKNOWN, which is `fail` with a reason, never a throw and never a
100
+ * `pass`. A failed refresh changes nothing: the previous value stays.
101
+ *
102
+ * The evaluator returns a node per tree position (containers, leaves, and the
103
+ * ones a short-circuit never reached) with a stable path and a human reason, so
104
+ * the editor can paint each block.
105
+ */
106
+ /**
107
+ * The key a `stableId → device id` map answers on. A pair (`addonId`, `stableId`)
108
+ * is a device; a bare stableId is only a device while no other addon shares it,
109
+ * so the map's producer puts the bare key in ONLY when it is unique.
110
+ */
111
+ function stableIdKey(stableId, addonId) {
112
+ return addonId === void 0 ? stableId : `${addonId}\u0000${stableId}`;
113
+ }
114
+ /**
115
+ * The `stableIdKey → device id` map a mirror refresh hands back, from a device
116
+ * listing. Every device is reachable by its (addonId, stableId) pair; the bare
117
+ * stableId is offered only while NO other device shares it, so a legacy binding
118
+ * that names no addon reads nothing rather than the wrong device.
119
+ */
120
+ function stableIdMapOf(devices) {
121
+ const out = /* @__PURE__ */ new Map();
122
+ const bare = /* @__PURE__ */ new Map();
123
+ for (const d of devices) {
124
+ if (d.stableId === void 0) continue;
125
+ if (d.addonId !== void 0) out.set(stableIdKey(d.stableId, d.addonId), d.id);
126
+ bare.set(d.stableId, bare.has(d.stableId) ? null : d.id);
127
+ }
128
+ for (const [stableId, id] of bare) if (id !== null) out.set(stableId, id);
129
+ return out;
130
+ }
131
+ /** The cap whose runtime-state slice IS the occupancy snapshot, parked objects included. */
132
+ var ZONE_ANALYTICS_CAP = "zone-analytics";
133
+ /** The cap whose slice holds a device's faults. */
134
+ var ERROR_CAP = "error";
135
+ function collectInto(cond, out) {
136
+ switch (cond.kind) {
137
+ case "all":
138
+ case "any":
139
+ for (const child of cond.children) collectInto(child, out);
140
+ return;
141
+ case "not":
142
+ collectInto(cond.child, out);
143
+ return;
144
+ case "device-is":
145
+ out.push({
146
+ kind: "device",
147
+ deviceId: cond.deviceId,
148
+ cap: cond.cap
149
+ });
150
+ return;
151
+ case "device-fault-is":
152
+ out.push({
153
+ kind: "device",
154
+ deviceId: cond.deviceId,
155
+ cap: ERROR_CAP
156
+ });
157
+ return;
158
+ case "stationary-present":
159
+ out.push({
160
+ kind: "device",
161
+ deviceId: cond.deviceId,
162
+ cap: ZONE_ANALYTICS_CAP
163
+ });
164
+ return;
165
+ case "expression":
166
+ for (const binding of Object.values(cond.bindings)) if (binding.kind === "global") out.push({
167
+ kind: "stable",
168
+ stableId: binding.sourceStableId,
169
+ cap: binding.cap,
170
+ ...binding.addonId !== void 0 ? { addonId: binding.addonId } : {}
171
+ });
172
+ return;
173
+ case "time-is": return;
174
+ case "triggered-by": return;
175
+ default: return;
176
+ }
177
+ }
178
+ /** Every (device, cap) a `when` tree's STATE leaves read, deduplicated. */
179
+ function collectWhenMirrorSources(cond) {
180
+ if (cond === void 0) return [];
181
+ const all = [];
182
+ collectInto(cond, all);
183
+ const seen = /* @__PURE__ */ new Set();
184
+ return all.filter((s) => {
185
+ const key = s.kind === "device" ? `d|${s.deviceId}|${s.cap}` : `s|${stableIdKey(s.stableId, s.addonId)}|${s.cap}`;
186
+ if (seen.has(key)) return false;
187
+ seen.add(key);
188
+ return true;
189
+ });
190
+ }
191
+ /** Does the tree hold a `time-is` leaf? */
192
+ function hasTimeLeaves(when) {
193
+ let found = false;
194
+ require_core_blocks_cap.forEachLeaf(when, (leaf) => {
195
+ if (leaf.kind === "time-is") found = true;
196
+ });
197
+ return found;
198
+ }
199
+ /**
200
+ * The soonest ANY `time-is` leaf changes sides (ms from `now`), over every
201
+ * leaf of the tree — a short-circuit that skipped a leaf in the last
202
+ * evaluation must not hide its boundary. Undefined: no time leaf, no site, or
203
+ * no boundary within reach.
204
+ */
205
+ function nextTimeBoundaryInMs(when, now, site, rootPath = "when") {
206
+ if (site === void 0) return void 0;
207
+ let due;
208
+ require_core_blocks_cap.forEachLeaf(when, (leaf) => {
209
+ if (leaf.kind !== "time-is") return;
210
+ const next = judgeTimeWindow(leaf, now, site).nextChangeAtMs;
211
+ if (next === null) return;
212
+ const ms = Math.max(0, next - now);
213
+ due = due === void 0 ? ms : Math.min(due, ms);
214
+ }, rootPath);
215
+ return due;
216
+ }
217
+ function sliceKey(deviceId, cap) {
218
+ return `${deviceId}|${cap}`;
219
+ }
220
+ function pick(slice, fieldPath) {
221
+ let cursor = slice;
222
+ for (const part of fieldPath.split(".")) {
223
+ if (cursor === null || typeof cursor !== "object") return void 0;
224
+ cursor = Reflect.get(cursor, part);
225
+ }
226
+ return cursor;
227
+ }
228
+ function isSliceObject(value) {
229
+ return typeof value === "object" && value !== null;
230
+ }
231
+ var ConditionMirror = class {
232
+ sources;
233
+ slices = /* @__PURE__ */ new Map();
234
+ stableIds = /* @__PURE__ */ new Map();
235
+ watched;
236
+ constructor(sources) {
237
+ this.sources = sources;
238
+ this.watched = new Set(sources.filter((s) => s.kind === "device").map((s) => sliceKey(s.deviceId, s.cap)));
239
+ }
240
+ /** A `device.state-changed` event. Slices nobody reads are ignored. */
241
+ apply(deviceId, cap, slice) {
242
+ const key = sliceKey(deviceId, cap);
243
+ if (!isSliceObject(slice)) return;
244
+ if (!this.watched.has(key) && !this.isStableTarget(deviceId, cap)) return;
245
+ this.slices.set(key, slice);
246
+ }
247
+ isStableTarget(deviceId, cap) {
248
+ for (const s of this.sources) if (s.kind === "stable" && s.cap === cap && this.stableIds.get(stableIdKey(s.stableId, s.addonId)) === deviceId) return true;
249
+ return false;
250
+ }
251
+ read(deviceId, cap, fieldPath) {
252
+ const slice = this.slices.get(sliceKey(deviceId, cap));
253
+ return slice === void 0 ? void 0 : pick(slice, fieldPath);
254
+ }
255
+ /** The whole slice the mirror holds for a device cap — `undefined` when it holds none. */
256
+ sliceOf(deviceId, cap) {
257
+ return this.slices.get(sliceKey(deviceId, cap));
258
+ }
259
+ readStable(stableId, cap, fieldPath, addonId) {
260
+ const deviceId = this.stableIds.get(stableIdKey(stableId, addonId));
261
+ return deviceId === void 0 ? void 0 : this.read(deviceId, cap, fieldPath);
262
+ }
263
+ /** Fill / reconcile. A read that fails or answers nothing keeps the old value. */
264
+ async refresh(fetchers) {
265
+ let updated = 0;
266
+ let kept = 0;
267
+ if (this.sources.some((s) => s.kind === "stable")) try {
268
+ this.stableIds = await fetchers.fetchStableIds();
269
+ } catch {}
270
+ const targets = /* @__PURE__ */ new Map();
271
+ for (const s of this.sources) {
272
+ const deviceId = s.kind === "device" ? s.deviceId : this.stableIds.get(stableIdKey(s.stableId, s.addonId));
273
+ if (deviceId === void 0) {
274
+ kept += 1;
275
+ continue;
276
+ }
277
+ targets.set(sliceKey(deviceId, s.cap), {
278
+ deviceId,
279
+ cap: s.cap
280
+ });
281
+ }
282
+ for (const [key, target] of targets) try {
283
+ const slice = await fetchers.fetchSlice(target.deviceId, target.cap);
284
+ if (isSliceObject(slice)) {
285
+ this.slices.set(key, slice);
286
+ updated += 1;
287
+ } else kept += 1;
288
+ } catch {
289
+ kept += 1;
290
+ }
291
+ return {
292
+ updated,
293
+ kept
294
+ };
295
+ }
296
+ };
297
+ var OPERATOR_SYMBOL = {
298
+ eq: "=",
299
+ ne: "≠",
300
+ gt: ">",
301
+ gte: "≥",
302
+ lt: "<",
303
+ lte: "≤",
304
+ contains: "contains",
305
+ in: "in"
306
+ };
307
+ var compare = require_core_blocks_cap.compareValues;
308
+ function toTraceValue(value) {
309
+ if (value === void 0 || value === null) return null;
310
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
311
+ if (Array.isArray(value) && value.every((v) => typeof v === "string" || typeof v === "number")) return value;
312
+ return JSON.stringify(value);
313
+ }
314
+ function show(value) {
315
+ return Array.isArray(value) ? `[${value.join(", ")}]` : String(value);
316
+ }
317
+ function markSkipped(cond, path, why, out) {
318
+ out.push({
319
+ path,
320
+ kind: cond.kind,
321
+ outcome: "not-evaluated",
322
+ reason: why
323
+ });
324
+ if (cond.kind === "all" || cond.kind === "any") cond.children.forEach((c, i) => {
325
+ markSkipped(c, `${path}.${i}`, why, out);
326
+ });
327
+ else if (cond.kind === "not") markSkipped(cond.child, `${path}.0`, why, out);
328
+ }
329
+ function parkedObjectsOf(value) {
330
+ if (!Array.isArray(value)) return [];
331
+ const rows = [];
332
+ for (const item of value) {
333
+ const id = Reflect.get(Object(item), "id");
334
+ const className = Reflect.get(Object(item), "className");
335
+ if (typeof id === "string" && typeof className === "string") rows.push({
336
+ id,
337
+ className
338
+ });
339
+ }
340
+ return rows;
341
+ }
342
+ /** `zoneId`s whose `trackIds` list the parked object (`stationary:<id>`, as the snapshot builds it). */
343
+ function zonesOfParked(zones, parkedId) {
344
+ if (!Array.isArray(zones)) return [];
345
+ const out = [];
346
+ for (const zone of zones) {
347
+ const zoneId = Reflect.get(Object(zone), "zoneId");
348
+ const trackIds = Reflect.get(Object(zone), "trackIds");
349
+ if (typeof zoneId === "string" && Array.isArray(trackIds) && trackIds.includes(`stationary:${parkedId}`)) out.push(zoneId);
350
+ }
351
+ return out;
352
+ }
353
+ /**
354
+ * Is a matching parked object there NOW? Read off the mirrored zone-analytics
355
+ * snapshot: `frame` is always present in a snapshot, so its absence means the
356
+ * slice was never read (UNKNOWN, a fail that says so), while a snapshot without
357
+ * `stationaryObjects` is a definite "nothing parked" (the provider omits an
358
+ * empty list).
359
+ */
360
+ function judgeStationaryPresent(cond, reader) {
361
+ if (reader.read(cond.deviceId, ZONE_ANALYTICS_CAP, "frame") === void 0) return {
362
+ pass: false,
363
+ why: `device ${cond.deviceId} occupancy snapshot unknown`,
364
+ unknown: true
365
+ };
366
+ const parked = parkedObjectsOf(reader.read(cond.deviceId, ZONE_ANALYTICS_CAP, "stationaryObjects"));
367
+ if (parked.length === 0) return {
368
+ pass: false,
369
+ why: `no parked objects on device ${cond.deviceId}`
370
+ };
371
+ const zones = reader.read(cond.deviceId, ZONE_ANALYTICS_CAP, "zones");
372
+ const matching = [];
373
+ for (const obj of parked) {
374
+ if (cond.subjects !== void 0 && !require_core_blocks_cap.anySubjectMatches(cond.subjects, { className: obj.className }).matches) continue;
375
+ if (cond.zones !== void 0) {
376
+ const inZones = zonesOfParked(zones, obj.id);
377
+ if (!cond.zones.some((z) => inZones.includes(z))) continue;
378
+ }
379
+ matching.push(obj);
380
+ }
381
+ const needed = cond.minCount ?? 1;
382
+ const first = matching[0];
383
+ if (first !== void 0 && matching.length >= needed) return {
384
+ pass: true,
385
+ why: needed === 1 ? `parked ${first.className} (${first.id}) on device ${cond.deviceId}` : `${matching.length} parked matching on device ${cond.deviceId} (need ${needed})`
386
+ };
387
+ if (matching.length > 0) return {
388
+ pass: false,
389
+ why: `only ${matching.length} of ${needed} needed parked objects match on device ${cond.deviceId}`
390
+ };
391
+ return {
392
+ pass: false,
393
+ why: `${parked.length} parked on device ${cond.deviceId}, none matching the class/zone filter`
394
+ };
395
+ }
396
+ function noteDue(state, hold) {
397
+ if (hold?.due === void 0) return;
398
+ state.holdDueInMs = state.holdDueInMs === void 0 ? hold.due : Math.min(state.holdDueInMs, hold.due);
399
+ }
400
+ /** What a state leaf's hold says, given whether the leaf's own condition is true NOW. */
401
+ function judgeHold(hold, reading, conditionTrue) {
402
+ const window = `${hold.mode === "stable" ? "stable" : "held"} for ${require_core_blocks_cap.describeHoldMs(hold.ms)}`;
403
+ if (reading === void 0) return {
404
+ pass: false,
405
+ unknown: true,
406
+ why: `${window}: nothing keeps this leaf's history here`
407
+ };
408
+ switch (reading.phase) {
409
+ case "met": return {
410
+ pass: true,
411
+ unknown: false,
412
+ why: `${window}: met`
413
+ };
414
+ case "pending": return {
415
+ due: reading.remainingMs,
416
+ pass: false,
417
+ unknown: false,
418
+ why: `${window}: ${require_core_blocks_cap.describeHoldMs(hold.ms - reading.remainingMs)} so far`
419
+ };
420
+ case "inherited": return {
421
+ pass: false,
422
+ unknown: true,
423
+ why: `${window}: it was already true when watching began, so how long it has held is not known`
424
+ };
425
+ case "idle": return {
426
+ pass: false,
427
+ unknown: false,
428
+ why: conditionTrue ? `${window}: just changed` : `${window}: the condition is not true`
429
+ };
430
+ }
431
+ }
432
+ function evalEventLeaf(cond, path, state, out) {
433
+ const occurred = state.firedPath === path;
434
+ out.push({
435
+ path,
436
+ kind: cond.kind,
437
+ outcome: occurred ? "pass" : "fail",
438
+ reason: occurred ? `${cond.kind} occurred → pass` : `${cond.kind} is an instant and did not occur now → fail`
439
+ });
440
+ return occurred;
441
+ }
442
+ function evalNode(cond, path, reader, now, out, state) {
443
+ if (require_core_blocks_cap.isEventLeaf(cond)) return evalEventLeaf(cond, path, state, out);
444
+ switch (cond.kind) {
445
+ case "device-is": {
446
+ const observed = reader.read(cond.deviceId, cond.cap, cond.fieldPath);
447
+ const base = {
448
+ path,
449
+ kind: cond.kind,
450
+ deviceId: cond.deviceId,
451
+ cap: cond.cap,
452
+ fieldPath: cond.fieldPath,
453
+ operator: cond.operator,
454
+ expected: toTraceValue(cond.value),
455
+ observed: toTraceValue(observed)
456
+ };
457
+ if (require_core_blocks_cap.isQuantityValue(cond.value)) {
458
+ out.push({
459
+ ...base,
460
+ outcome: "fail",
461
+ reason: `${cond.fieldPath} expected value's unit was never converted → fail`
462
+ });
463
+ return false;
464
+ }
465
+ if (observed === void 0) {
466
+ state.unknown = true;
467
+ out.push({
468
+ ...base,
469
+ outcome: "fail",
470
+ reason: `${cond.fieldPath} value unknown → fail`
471
+ });
472
+ return false;
473
+ }
474
+ const compared = compare(observed, cond.operator, cond.value);
475
+ const hold = cond.for === void 0 ? void 0 : judgeHold(cond.for, state.holds?.observe(path, cond.for, {
476
+ holds: compared,
477
+ value: observed
478
+ }, now), compared);
479
+ if (hold?.unknown === true) state.unknown = true;
480
+ noteDue(state, hold);
481
+ const ok = compared && (hold === void 0 || hold.pass);
482
+ out.push({
483
+ ...base,
484
+ outcome: ok ? "pass" : "fail",
485
+ reason: `${cond.fieldPath} ${show(observed)}, expected ${OPERATOR_SYMBOL[cond.operator]} ${show(cond.value)}${hold === void 0 ? "" : ` (${hold.why})`} → ${ok ? "pass" : "fail"}`
486
+ });
487
+ return ok;
488
+ }
489
+ case "device-fault-is": {
490
+ const reading = require_core_blocks_cap.readFault(reader.read(cond.deviceId, ERROR_CAP, "active"), reader.read(cond.deviceId, ERROR_CAP, "code"), reader.read(cond.deviceId, ERROR_CAP, "faults"));
491
+ const base = {
492
+ path,
493
+ kind: cond.kind,
494
+ deviceId: cond.deviceId,
495
+ cap: ERROR_CAP,
496
+ fieldPath: "faults",
497
+ expected: cond.codes.join(", ")
498
+ };
499
+ if (reading === void 0) {
500
+ state.unknown = true;
501
+ out.push({
502
+ ...base,
503
+ outcome: "fail",
504
+ reason: "whether the device has a fault is unknown → fail"
505
+ });
506
+ return false;
507
+ }
508
+ const ok = require_core_blocks_cap.faultMatches(reading, cond.codes);
509
+ const shown = reading.active ? reading.codes.join(", ") || "a fault" : "none";
510
+ out.push({
511
+ ...base,
512
+ outcome: ok ? "pass" : "fail",
513
+ observed: shown,
514
+ reason: `faults: ${shown}, expected ${require_core_blocks_cap.describeWantedFaults(cond.codes)} → ${ok ? "pass" : "fail"}`
515
+ });
516
+ return ok;
517
+ }
518
+ case "stationary-present": {
519
+ const verdict = judgeStationaryPresent(cond, reader);
520
+ if (verdict.unknown === true) state.unknown = true;
521
+ out.push({
522
+ path,
523
+ kind: cond.kind,
524
+ outcome: verdict.pass ? "pass" : "fail",
525
+ reason: `${verdict.why} → ${verdict.pass ? "pass" : "fail"}`,
526
+ deviceId: cond.deviceId,
527
+ cap: ZONE_ANALYTICS_CAP
528
+ });
529
+ return verdict.pass;
530
+ }
531
+ case "expression": {
532
+ const values = {};
533
+ for (const [alias, binding] of Object.entries(cond.bindings)) {
534
+ if (binding.kind === "literal") {
535
+ values[alias] = require_error_cap.toExpressionValue(binding.value) ?? null;
536
+ continue;
537
+ }
538
+ const raw = binding.kind === "global" ? reader.readStable(binding.sourceStableId, binding.cap, binding.fieldPath, binding.addonId) : void 0;
539
+ if (raw === void 0) {
540
+ out.push({
541
+ path,
542
+ kind: cond.kind,
543
+ outcome: "fail",
544
+ reason: `${alias} value unknown → fail`
545
+ });
546
+ state.unknown = true;
547
+ return false;
548
+ }
549
+ values[alias] = require_error_cap.toExpressionValue(raw) ?? null;
550
+ }
551
+ const result = require_error_cap.evaluateExpressionSource(cond.expr, values, now);
552
+ if (!result.ok) {
553
+ out.push({
554
+ path,
555
+ kind: cond.kind,
556
+ outcome: "fail",
557
+ reason: `${cond.expr}: ${result.error} → fail`
558
+ });
559
+ return false;
560
+ }
561
+ const truth = result.value === true;
562
+ const hold = cond.for === void 0 ? void 0 : judgeHold(cond.for, state.holds?.observe(path, cond.for, {
563
+ holds: truth,
564
+ value: truth
565
+ }, now), truth);
566
+ if (hold?.unknown === true) state.unknown = true;
567
+ noteDue(state, hold);
568
+ const ok = truth && (hold === void 0 || hold.pass);
569
+ out.push({
570
+ path,
571
+ kind: cond.kind,
572
+ outcome: ok ? "pass" : "fail",
573
+ reason: `${cond.expr} with ${JSON.stringify(values)}${hold === void 0 ? "" : ` (${hold.why})`} → ${ok ? "pass" : "fail"}`
574
+ });
575
+ return ok;
576
+ }
577
+ case "time-is": {
578
+ if (state.site === void 0) {
579
+ state.unknown = true;
580
+ out.push({
581
+ path,
582
+ kind: cond.kind,
583
+ outcome: "fail",
584
+ reason: "the site clock is not known here → fail"
585
+ });
586
+ return false;
587
+ }
588
+ const verdict = judgeTimeWindow(cond, now, state.site);
589
+ if (verdict.unknown) state.unknown = true;
590
+ if (verdict.nextChangeAtMs !== null) {
591
+ const due = Math.max(0, verdict.nextChangeAtMs - now);
592
+ state.timeDueInMs = state.timeDueInMs === void 0 ? due : Math.min(state.timeDueInMs, due);
593
+ }
594
+ out.push({
595
+ path,
596
+ kind: cond.kind,
597
+ outcome: verdict.inside ? "pass" : "fail",
598
+ reason: `${verdict.why} → ${verdict.inside ? "pass" : "fail"}`
599
+ });
600
+ return verdict.inside;
601
+ }
602
+ case "triggered-by": {
603
+ const named = cond.leafIds.map((id) => `"${id}"`).join(", ");
604
+ if (state.trigger === "unknown") {
605
+ state.unknown = true;
606
+ out.push({
607
+ path,
608
+ kind: cond.kind,
609
+ outcome: "fail",
610
+ reason: `what started this run is not known here, so "triggered by ${named}" cannot be judged → fail`
611
+ });
612
+ return false;
613
+ }
614
+ const fired = state.trigger.leafId;
615
+ const ok = fired !== null && cond.leafIds.includes(fired);
616
+ out.push({
617
+ path,
618
+ kind: cond.kind,
619
+ outcome: ok ? "pass" : "fail",
620
+ reason: `${fired === null ? "no named trigger started this run" : `started by "${fired}"`}, wanted ${named} → ${ok ? "pass" : "fail"}`
621
+ });
622
+ return ok;
623
+ }
624
+ case "not": {
625
+ const at = out.length;
626
+ out.push({
627
+ path,
628
+ kind: "not",
629
+ outcome: "not-evaluated",
630
+ reason: ""
631
+ });
632
+ const inner = evalNode(cond.child, `${path}.0`, reader, now, out, state);
633
+ const ok = !inner;
634
+ out.splice(at, 1, {
635
+ path,
636
+ kind: "not",
637
+ outcome: ok ? "pass" : "fail",
638
+ reason: `not (${inner ? "pass" : "fail"}) → ${ok ? "pass" : "fail"}`
639
+ });
640
+ return ok;
641
+ }
642
+ case "all":
643
+ case "any": {
644
+ const isAll = cond.kind === "all";
645
+ const at = out.length;
646
+ out.push({
647
+ path,
648
+ kind: cond.kind,
649
+ outcome: "not-evaluated",
650
+ reason: ""
651
+ });
652
+ let decided = null;
653
+ for (let i = 0; i < cond.children.length; i += 1) {
654
+ const child = cond.children[i];
655
+ if (child === void 0) continue;
656
+ if (decided !== null) {
657
+ markSkipped(child, `${path}.${i}`, `short-circuited by ${path}.${decided}`, out);
658
+ continue;
659
+ }
660
+ const ok = evalNode(child, `${path}.${i}`, reader, now, out, state);
661
+ if (isAll ? !ok : ok) decided = i;
662
+ }
663
+ const ok = isAll ? decided === null : decided !== null;
664
+ const reason = isAll ? ok ? `all ${cond.children.length} passed → pass` : `${path}.${decided} failed → fail` : ok ? `${path}.${decided} passed → pass` : `none of ${cond.children.length} passed → fail`;
665
+ out.splice(at, 1, {
666
+ path,
667
+ kind: cond.kind,
668
+ outcome: ok ? "pass" : "fail",
669
+ reason
670
+ });
671
+ return ok;
672
+ }
673
+ }
674
+ }
675
+ /** Evaluate a `when` tree: the fired event leaf is true, every other event leaf false. */
676
+ function evaluateWhenTree(when, reader, now, options = {}) {
677
+ const nodes = [];
678
+ const state = {
679
+ firedPath: options.firedPath,
680
+ holds: options.holds,
681
+ unknown: false,
682
+ holdDueInMs: void 0,
683
+ site: options.site,
684
+ timeDueInMs: void 0,
685
+ trigger: options.trigger ?? { leafId: options.firedPath === void 0 ? null : require_core_blocks_cap.eventLeafIdAt(when, options.firedPath) }
686
+ };
687
+ return {
688
+ pass: evalNode(when, options.rootPath ?? "when", reader, now, nodes, state),
689
+ unknown: state.unknown,
690
+ nodes,
691
+ ...state.holdDueInMs === void 0 ? {} : { holdDueInMs: state.holdDueInMs },
692
+ ...state.timeDueInMs === void 0 ? {} : { timeDueInMs: state.timeDueInMs }
693
+ };
694
+ }
695
+ /** Does any state leaf of the tree carry a `for`? */
696
+ function hasHoldLeaves(when) {
697
+ let found = false;
698
+ require_core_blocks_cap.forEachLeaf(when, (leaf) => {
699
+ if ((leaf.kind === "device-is" || leaf.kind === "expression") && leaf.for !== void 0) found = true;
700
+ });
701
+ return found;
702
+ }
703
+ //#endregion
704
+ //#region src/kernel/prefix-walk.ts
705
+ function isRecord(value) {
706
+ return typeof value === "object" && value !== null && !Array.isArray(value);
707
+ }
708
+ function unwrapStoredValue(parsed) {
709
+ if (!isRecord(parsed) || !("value" in parsed)) return parsed;
710
+ return parsed.value;
711
+ }
712
+ /**
713
+ * Rows one page of a prefix read asks for.
714
+ *
715
+ * Below `SETTINGS_QUERY_DEFAULT_ROW_CAP` (2 000, `query-bounds.ts`) on purpose:
716
+ * this read now names its own bound, so the engine's defensive cap is never the
717
+ * thing that decides how much of the answer the caller gets.
718
+ */
719
+ var PREFIX_PAGE_ROWS = 1e3;
720
+ /**
721
+ * Pages one prefix read may take before it refuses.
722
+ *
723
+ * 512 pages is 512 000 rows — three orders of magnitude past the largest live
724
+ * scope (`addon-device-settings` for one addon over a ~1 019-device fleet) and
725
+ * still a bound, because a walk with no bound is the defect this file was
726
+ * fixing, not one to reintroduce.
727
+ */
728
+ var PREFIX_PAGE_BUDGET = 512;
729
+ /**
730
+ * Every row under `prefix`, or a throw — never the first 2 000 of them.
731
+ *
732
+ * **The defect.** This issued ONE `query` with no `limit`, and
733
+ * `queryDeclared` resolves an absent limit to `SETTINGS_QUERY_DEFAULT_ROW_CAP`
734
+ * and cuts the result there. On the live hub that fired 138 times in two hours
735
+ * (`settings-store query truncated by a defensive row cap`, collection
736
+ * `addon-device-settings`, `rowCap: 2000`, `requestedLimit: null`): a
737
+ * ~1 019-device fleet with more than two stored keys per device puts one
738
+ * addon's `<addonId>:` range past the cap. The engine warned; the door did not
739
+ * notice, and handed its caller a short map that is **shape-identical to a
740
+ * complete one**. Every device whose rows sort past the cap reads as "has no
741
+ * stored settings", which is exactly what a device with none looks like.
742
+ *
743
+ * **The fix is a keyset walk, not a bigger limit.** The cursor is the last id
744
+ * of the previous page, INCLUSIVE — so the page boundary re-reads exactly one
745
+ * row (ids are unique, so a full page always advances) and no row can fall
746
+ * between two pages the way an `OFFSET` walk drops rows under a concurrent
747
+ * write (D295 rule 1). Re-reading is free here: the accumulator is keyed by
748
+ * suffix, so the duplicate overwrites itself with its own value.
749
+ *
750
+ * `ORDER BY id` is not decoration — the cursor is only meaningful if the
751
+ * engine returns the range in the order the cursor advances through. It is the
752
+ * primary key, so the ordering is the range scan's own.
753
+ *
754
+ * @throws when the prefix cannot be expressed as a range and the collection is
755
+ * larger than one page, or when the walk exceeds {@link PREFIX_PAGE_BUDGET}.
756
+ * A throw is the point: a caller that cannot be answered completely must not
757
+ * be handed something that looks like a complete answer.
758
+ */
759
+ async function loadPrefixed(door, collection, prefix, decode = unwrapStoredValue) {
760
+ const range = require_prefix_range.prefixRange(prefix);
761
+ const result = {};
762
+ let cursor = range?.lo ?? null;
763
+ for (let page = 0;; page++) {
764
+ if (page >= PREFIX_PAGE_BUDGET) throw new Error(`settings door: reading "${prefix}" from "${collection}" exceeded ${PREFIX_PAGE_BUDGET} pages of ${PREFIX_PAGE_ROWS} rows. Refusing to return the part that was read — a partial scope read is indistinguishable from an empty one.`);
765
+ const rows = await door.query({
766
+ collection,
767
+ filter: {
768
+ ...range !== null && cursor !== null ? { whereBetween: { id: [cursor, range.hi] } } : {},
769
+ orderBy: {
770
+ field: "id",
771
+ direction: "asc"
772
+ },
773
+ limit: PREFIX_PAGE_ROWS
774
+ }
775
+ });
776
+ for (const row of rows) {
777
+ if (range !== null && (row.id < range.lo || row.id >= range.hi)) continue;
778
+ if (!row.id.startsWith(prefix)) continue;
779
+ result[row.id.slice(prefix.length)] = decode(row.data);
780
+ }
781
+ if (rows.length < PREFIX_PAGE_ROWS) return result;
782
+ const last = rows[rows.length - 1];
783
+ if (last === void 0) return result;
784
+ if (range === null) throw new Error(`settings door: prefix "${prefix}" on "${collection}" cannot be expressed as an id range, and the unfiltered read filled a page — the answer would be partial. Use an ASCII, non-empty prefix.`);
785
+ if (last.id === cursor) throw new Error(`settings door: reading "${prefix}" from "${collection}" made no progress at id "${last.id}" — ids under a prefix must be unique.`);
786
+ cursor = last.id;
787
+ }
788
+ }
789
+ //#endregion
790
+ Object.defineProperty(exports, "ConditionMirror", {
791
+ enumerable: true,
792
+ get: function() {
793
+ return ConditionMirror;
794
+ }
795
+ });
796
+ Object.defineProperty(exports, "collectWhenMirrorSources", {
797
+ enumerable: true,
798
+ get: function() {
799
+ return collectWhenMirrorSources;
800
+ }
801
+ });
802
+ Object.defineProperty(exports, "evaluateWhenTree", {
803
+ enumerable: true,
804
+ get: function() {
805
+ return evaluateWhenTree;
806
+ }
807
+ });
808
+ Object.defineProperty(exports, "hasHoldLeaves", {
809
+ enumerable: true,
810
+ get: function() {
811
+ return hasHoldLeaves;
812
+ }
813
+ });
814
+ Object.defineProperty(exports, "hasTimeLeaves", {
815
+ enumerable: true,
816
+ get: function() {
817
+ return hasTimeLeaves;
818
+ }
819
+ });
820
+ Object.defineProperty(exports, "loadPrefixed", {
821
+ enumerable: true,
822
+ get: function() {
823
+ return loadPrefixed;
824
+ }
825
+ });
826
+ Object.defineProperty(exports, "nextTimeBoundaryInMs", {
827
+ enumerable: true,
828
+ get: function() {
829
+ return nextTimeBoundaryInMs;
830
+ }
831
+ });
832
+ Object.defineProperty(exports, "stableIdMapOf", {
833
+ enumerable: true,
834
+ get: function() {
835
+ return stableIdMapOf;
836
+ }
837
+ });
838
+ Object.defineProperty(exports, "unwrapStoredValue", {
839
+ enumerable: true,
840
+ get: function() {
841
+ return unwrapStoredValue;
842
+ }
843
+ });