@camstack/server 1.2.941 → 1.2.943
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.
- package/CHANGELOG.md +20 -0
- package/dist/api/trpc/generated-cap-mounts.js +19 -1
- package/dist/api/trpc/generated-cap-routers.js +676 -596
- package/package.json +13 -11
- package/system/dist/action-index-B1fgpQBt.mjs +9925 -0
- package/system/dist/action-index-B_cLRwXJ.js +9972 -0
- package/system/dist/alert-episode-Be--PngO.mjs +64 -0
- package/system/dist/alert-episode-Bqktmt-i.js +93 -0
- package/system/dist/{base-addon-Md14i7pe.mjs → base-addon-BcS6r1cT.mjs} +20 -7
- package/system/dist/{base-addon-DD5dIfcZ.js → base-addon-CRsXtYFG.js} +20 -7
- package/system/dist/{base-device-CH8rfD9j.js → base-device-DAdWzDOl.js} +138 -34
- package/system/dist/{base-device-BcGO6LTT.mjs → base-device-DJXF5eDN.mjs} +138 -34
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alert-episode-policy.d.ts +9 -5
- package/system/dist/builtins/alerts/alerts.addon.js +30 -80
- package/system/dist/builtins/alerts/alerts.addon.mjs +18 -68
- package/system/dist/builtins/autotrack/index.js +2 -2
- package/system/dist/builtins/autotrack/index.mjs +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +9 -9
- package/system/dist/builtins/camera-grid/index.mjs +6 -6
- package/system/dist/builtins/composer/composer.addon.js +99 -99
- package/system/dist/builtins/composer/composer.addon.mjs +11 -11
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/automation-template-instances.d.ts +14 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +6 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +296 -193
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +237 -134
- package/system/dist/builtins/core-blocks/link-contributions.d.ts +2 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +91 -18
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +91 -18
- package/system/dist/builtins/core-notifier/group-notification-output.d.ts +8 -16
- package/system/dist/builtins/device-history/device-history.addon.d.ts +8 -0
- package/system/dist/builtins/device-history/device-history.addon.js +580 -60
- package/system/dist/builtins/device-history/device-history.addon.mjs +569 -49
- package/system/dist/builtins/device-history/retention/device-raw-overrides.d.ts +16 -0
- package/system/dist/builtins/device-history/retention/retention-knobs.d.ts +14 -0
- package/system/dist/builtins/device-history/retention/retention.d.ts +21 -1
- package/system/dist/builtins/device-history/transitions/change-coalescing.d.ts +48 -0
- package/system/dist/builtins/device-history/transitions/derived-changes.d.ts +49 -0
- package/system/dist/builtins/device-history/transitions/history-change-port.d.ts +20 -0
- package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +18 -3
- package/system/dist/builtins/device-manager/device-config-secrets.d.ts +14 -0
- package/system/dist/builtins/device-manager/device-identity-index.d.ts +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +226 -479
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +218 -471
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +0 -5
- package/system/dist/builtins/device-manager/identity-link-reconciler.d.ts +5 -0
- package/system/dist/builtins/device-manager/transitions/command-recorder.d.ts +38 -0
- package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +8 -9
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +2 -2
- package/system/dist/builtins/keychain/index.mjs +2 -2
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +2 -2
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/address-book.d.ts +3 -1
- package/system/dist/builtins/local-network/local-network.addon.d.ts +26 -1
- package/system/dist/builtins/local-network/local-network.addon.js +66 -11
- package/system/dist/builtins/local-network/local-network.addon.mjs +66 -11
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +4 -4
- package/system/dist/builtins/snapshot/index.mjs +4 -4
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +1 -1
- package/system/dist/builtins/system-config/system-config.addon.mjs +1 -1
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-CUZ3W0oZ.mjs → capture-engine-B2MmoNND.mjs} +1 -1
- package/system/dist/{capture-engine-mtDXEBAq.js → capture-engine-D_1IJmMs.js} +1 -1
- package/system/dist/command-catalog-C29hVOOg.js +210 -0
- package/system/dist/command-catalog-xAeqxbZk.mjs +169 -0
- package/system/dist/{error.cap-DCwbIGEF.mjs → compile-OBMHlqD-.mjs} +97 -100
- package/system/dist/{error.cap-BxLEHP6z.js → compile-SpeAhaZ6.js} +107 -116
- package/system/dist/{composition-sources-B56CU8hi.mjs → composition-sources-C327LGFn.mjs} +2 -2
- package/system/dist/{composition-sources-D_Bfwji0.js → composition-sources-Do5qM6EB.js} +17 -17
- package/system/dist/{core-blocks.cap-xt5_fK5Z.js → core-blocks.cap-CdTGUKtr.js} +194 -10110
- package/system/dist/{core-blocks.cap-DDECcMeI.mjs → core-blocks.cap-DLkEfV5b.mjs} +54 -9910
- package/system/dist/{device-kind-BJ2pfsjw.mjs → device-kind-C37Ra2wd.mjs} +4 -2
- package/system/dist/{device-kind-CsSiv_YF.js → device-kind-FMhJg8uC.js} +4 -2
- package/system/dist/{device-manager.cap-DyHOIh5T.js → device-manager.cap-DJs8izI6.js} +13 -4
- package/system/dist/{device-manager.cap-DIBK62-r.mjs → device-manager.cap-eYrj1Ezp.mjs} +13 -4
- package/system/dist/{device-provider.cap-BKUGJSo0.js → device-provider.cap-CNlYBQ5D.js} +1 -1
- package/system/dist/{device-provider.cap-DU6HMUXH.mjs → device-provider.cap-D8mJllVM.mjs} +1 -1
- package/system/dist/{device-row-store-O4mNbp5q.js → device-row-store-C0P2H18h.js} +2 -2
- package/system/dist/{device-row-store-C-_R-h1Z.mjs → device-row-store-CTocYKqC.mjs} +2 -2
- package/system/dist/{device-type-CbQsnFdC.js → device-type-Cnc0NiSX.js} +13 -0
- package/system/dist/{device-type-DgEvK3ch.mjs → device-type-TUGqGmaI.mjs} +13 -0
- package/system/dist/error.cap-BuKbL3Ac.js +125 -0
- package/system/dist/error.cap-CU1FB6uE.mjs +102 -0
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{history-catalog-BwTeQ4Mr.mjs → history-catalog-A_dzXNpv.mjs} +98 -3
- package/system/dist/{history-catalog-BKRarIL_.js → history-catalog-CiTMP3-E.js} +98 -3
- package/system/dist/index.js +28 -6
- package/system/dist/index.mjs +28 -6
- package/system/dist/kernel/addon-version-policy.d.ts +10 -0
- package/system/dist/{legacy-integration-rows-door-B1nzxxr5.js → legacy-integration-rows-door-CdqYAj-o.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-nTvo_6jQ.mjs → legacy-integration-rows-door-LSgpClpX.mjs} +1 -1
- package/system/dist/{low-power-sleep.cap-B6mz6ojP.js → low-power-sleep.cap-BJWyAuUQ.js} +1 -1
- package/system/dist/{low-power-sleep.cap-C3Vi8Vxj.mjs → low-power-sleep.cap-D9Orx3LS.mjs} +1 -1
- package/system/dist/migrations/hub/2026-11-22-device-transitions-commands-only.d.ts +10 -0
- package/system/dist/{network-access.cap-BEN_uRVb.js → network-access.cap-CTQ2WQoi.js} +38 -12
- package/system/dist/{network-access.cap-Dy8FNNVs.mjs → network-access.cap-Dx5K0I5i.mjs} +33 -13
- package/system/dist/{notification-rules.cap-Drwz-A4n.js → notification-rules.cap-BJKUjizS.js} +45 -9
- package/system/dist/{notification-rules.cap-0vVvsxQ1.mjs → notification-rules.cap-BUIuYPlQ.mjs} +45 -9
- package/system/dist/{notification-targets-DR-D-vIt.mjs → notification-targets-4bGYH5J7.mjs} +2 -2
- package/system/dist/{notification-targets-Cc_3OBH9.js → notification-targets-DMW7xgR2.js} +2 -2
- package/system/dist/{prefix-walk-CCO_VZVo.js → prefix-walk-BFnw8NBu.js} +5 -5
- package/system/dist/{prefix-walk-BhT0ZoKl.mjs → prefix-walk-Mtij0NNT.mjs} +2 -2
- package/system/dist/{ptz-autotrack.cap-DOz0xL0O.js → ptz-autotrack.cap-B9eyZU8w.js} +1 -1
- package/system/dist/{ptz-autotrack.cap-CDF6FeTK.mjs → ptz-autotrack.cap-Dw2k-po9.mjs} +1 -1
- package/system/dist/{recording-archive.cap-RHAN45fa.mjs → recording-archive.cap-CTlm86R8.mjs} +1 -1
- package/system/dist/{recording-archive.cap-BPJ7kvnd.js → recording-archive.cap-Wo-hEZhz.js} +1 -1
- package/system/dist/{rename-composition-block-DWUkrazx.mjs → rename-composition-block-Cdh-dRmY.mjs} +395 -20
- package/system/dist/{rename-composition-block-CH2vRIW7.js → rename-composition-block-D9Uc1AF7.js} +406 -31
- package/system/dist/{retention-CUOVI1p7.mjs → retention-CQs8QR1B.mjs} +33 -3
- package/system/dist/{device-transitions.cap-DCXP3zwY.mjs → retention-source.cap-550kkyp5.mjs} +98 -21
- package/system/dist/{device-transitions.cap-zOGvAIHz.js → retention-source.cap-C6Hy0hlM.js} +103 -20
- package/system/dist/{retention-BcOSL6b9.js → retention-xcjk_k1w.js} +33 -3
- package/system/dist/{snapshot.cap-Cis6JRwn.js → snapshot.cap-CHm29hBs.js} +1 -1
- package/system/dist/{snapshot.cap-BkfHpJVO.mjs → snapshot.cap-CO68YvJU.mjs} +1 -1
- package/system/dist/{stream-catalog.cap-D8Y-uXcy.js → stream-catalog.cap-CjEQFknc.js} +2 -2
- package/system/dist/{stream-catalog.cap-D1Hy19Yc.mjs → stream-catalog.cap-DVniDdRD.mjs} +2 -2
- package/system/dist/{user-management.cap-Ctd4c_im.mjs → user-management.cap-4IEUCSdL.mjs} +2 -2
- package/system/dist/{user-management.cap-DyVb68rY.js → user-management.cap-DV9Jfsj3.js} +2 -2
- package/system/dist/{wal-maintenance-CjpslZUL.mjs → wal-maintenance-Bey5ChBb.mjs} +0 -0
- package/system/dist/{wal-maintenance-DKTXQ7UF.js → wal-maintenance-BgYiAy5b.js} +0 -0
- package/system/package.json +4 -1
- package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +0 -81
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { b as EventCategory, m as emitReadiness, t as BaseAddon } from "../../base-addon-
|
|
1
|
+
import { b as EventCategory, m as emitReadiness, t as BaseAddon } from "../../base-addon-BcS6r1cT.mjs";
|
|
2
2
|
import { P as RecordTooLargeError, Z as errMsg, k as InvalidRecordError } from "../../scoped-settings-DVWUIP7Z.mjs";
|
|
3
3
|
import { s as defineRecordKinds } from "../../record-kind-ub6NXqfh.mjs";
|
|
4
|
-
import { t as DEVICE_TOMBSTONE_RETENTION_MS } from "../../device-manager.cap-
|
|
5
|
-
import { a as
|
|
4
|
+
import { t as DEVICE_TOMBSTONE_RETENTION_MS } from "../../device-manager.cap-eYrj1Ezp.mjs";
|
|
5
|
+
import { a as deviceRemovalHookCapability, c as DeviceTransitionSchema, i as deviceRunsCapability, n as deviceTransitionsCapability, o as DEVICE_HISTORY_ENERGY_KEY, r as DeviceRunSchema, s as deviceHistoryCapability, t as retentionSourceCapability } from "../../retention-source.cap-550kkyp5.mjs";
|
|
6
6
|
import { i as isReadingQuantity, r as historyUnitFor } from "../../quantity-D3g5SxsZ.mjs";
|
|
7
|
-
import { r as DeviceType } from "../../device-type-
|
|
8
|
-
import { a as wattMillisecondsToKwh, n as HISTORY_ITEM_CATALOG, t as HISTORY_CATALOG } from "../../history-catalog-
|
|
9
|
-
import {
|
|
10
|
-
import { a as
|
|
7
|
+
import { r as DeviceType } from "../../device-type-TUGqGmaI.mjs";
|
|
8
|
+
import { a as wattMillisecondsToKwh, n as HISTORY_ITEM_CATALOG, t as HISTORY_CATALOG } from "../../history-catalog-A_dzXNpv.mjs";
|
|
9
|
+
import { t as auditedFields } from "../../command-catalog-xAeqxbZk.mjs";
|
|
10
|
+
import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, m as parseConfirmedStateChanged, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-B2MmoNND.mjs";
|
|
11
|
+
import { a as FIVE_MINUTES_MS, c as bucketEndOf, i as DAY_MS, l as bucketStartOf, n as RetentionJob, o as HOUR_MS, r as DepartureTracker, s as ROLLUP_GRACE_MS, t as DEFAULT_RETENTION, u as floorTo } from "../../retention-CQs8QR1B.mjs";
|
|
11
12
|
import { randomUUID } from "node:crypto";
|
|
12
13
|
//#region ../types/dist/esm/device/device-removal-reconcile.mjs
|
|
13
14
|
/** How often an implementer re-asks for tombstones after its start-up pass. */
|
|
@@ -3523,11 +3524,200 @@ var DeviceRunsService = class {
|
|
|
3523
3524
|
return out;
|
|
3524
3525
|
}
|
|
3525
3526
|
};
|
|
3527
|
+
function fieldKey(capName, field) {
|
|
3528
|
+
return `${capName}|${field}`;
|
|
3529
|
+
}
|
|
3530
|
+
function sameValue(a, b) {
|
|
3531
|
+
if (Object.is(a, b)) return true;
|
|
3532
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
3533
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
3534
|
+
}
|
|
3535
|
+
function closeBurst(capName, burst, now, out) {
|
|
3536
|
+
if (now - burst.lastAt < 5e3 && now - burst.firstAt < 6e4) return;
|
|
3537
|
+
for (const [field, held] of burst.fields) {
|
|
3538
|
+
if (sameValue(held.from, held.to)) continue;
|
|
3539
|
+
out.push({
|
|
3540
|
+
capName,
|
|
3541
|
+
field,
|
|
3542
|
+
at: burst.lastAt,
|
|
3543
|
+
from: held.from,
|
|
3544
|
+
to: held.to
|
|
3545
|
+
});
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
/** Group the points of each capability into bursts and answer the net change of each field. */
|
|
3549
|
+
function coalesceChanges(input) {
|
|
3550
|
+
const byCap = /* @__PURE__ */ new Map();
|
|
3551
|
+
for (const point of input.points) {
|
|
3552
|
+
const list = byCap.get(point.capName);
|
|
3553
|
+
if (list === void 0) byCap.set(point.capName, [point]);
|
|
3554
|
+
else list.push(point);
|
|
3555
|
+
}
|
|
3556
|
+
const out = [];
|
|
3557
|
+
for (const [capName, points] of byCap) {
|
|
3558
|
+
const held = /* @__PURE__ */ new Map();
|
|
3559
|
+
for (const point of points) {
|
|
3560
|
+
const key = fieldKey(capName, point.field);
|
|
3561
|
+
const known = input.before.get(key);
|
|
3562
|
+
if (known !== void 0) held.set(key, known);
|
|
3563
|
+
}
|
|
3564
|
+
let burst = null;
|
|
3565
|
+
for (const point of points.toSorted((a, b) => a.at - b.at)) {
|
|
3566
|
+
const key = fieldKey(capName, point.field);
|
|
3567
|
+
const prior = held.get(key);
|
|
3568
|
+
held.set(key, point.value);
|
|
3569
|
+
if (prior === void 0 || sameValue(prior, point.value)) continue;
|
|
3570
|
+
if (burst !== null && (point.at - burst.lastAt >= 5e3 || point.at - burst.firstAt >= 6e4)) {
|
|
3571
|
+
closeBurst(capName, burst, Number.POSITIVE_INFINITY, out);
|
|
3572
|
+
burst = null;
|
|
3573
|
+
}
|
|
3574
|
+
burst ??= {
|
|
3575
|
+
firstAt: point.at,
|
|
3576
|
+
lastAt: point.at,
|
|
3577
|
+
fields: /* @__PURE__ */ new Map()
|
|
3578
|
+
};
|
|
3579
|
+
burst.lastAt = point.at;
|
|
3580
|
+
const earlier = burst.fields.get(point.field);
|
|
3581
|
+
burst.fields.set(point.field, {
|
|
3582
|
+
from: earlier?.from ?? prior,
|
|
3583
|
+
to: point.value
|
|
3584
|
+
});
|
|
3585
|
+
}
|
|
3586
|
+
if (burst !== null) closeBurst(capName, burst, input.now, out);
|
|
3587
|
+
}
|
|
3588
|
+
return out.toSorted((a, b) => b.at - a.at);
|
|
3589
|
+
}
|
|
3590
|
+
//#endregion
|
|
3591
|
+
//#region src/builtins/device-history/transitions/derived-changes.ts
|
|
3592
|
+
/** The most raw points read for one series; the newest are kept past it. */
|
|
3593
|
+
var DERIVED_POINTS_MAX = 1e4;
|
|
3594
|
+
function valueOf(kind, point) {
|
|
3595
|
+
if (kind === "enum") return point.state ?? void 0;
|
|
3596
|
+
if (point.value === null) return void 0;
|
|
3597
|
+
if (kind === "boolean") return point.value !== 0;
|
|
3598
|
+
if (kind === "gauge") return point.value;
|
|
3599
|
+
}
|
|
3600
|
+
var DerivedChanges = class {
|
|
3601
|
+
port;
|
|
3602
|
+
clock;
|
|
3603
|
+
constructor(port, clock) {
|
|
3604
|
+
this.port = port;
|
|
3605
|
+
this.clock = clock;
|
|
3606
|
+
}
|
|
3607
|
+
/** The settled changes of the device's audited fields in `window`, newest first. */
|
|
3608
|
+
async read(deviceId, window) {
|
|
3609
|
+
const series = this.port.auditedSeries(deviceId).filter((s) => s.kind !== "counter").filter((s) => window.capName === void 0 || s.capName === window.capName);
|
|
3610
|
+
const points = [];
|
|
3611
|
+
const before = /* @__PURE__ */ new Map();
|
|
3612
|
+
for (const s of series) {
|
|
3613
|
+
const read = await this.port.readRaw(deviceId, s, window.from, window.to);
|
|
3614
|
+
if (read.before !== null) {
|
|
3615
|
+
const prior = valueOf(s.kind, read.before);
|
|
3616
|
+
if (prior !== void 0) before.set(fieldKey(s.capName, s.field), prior);
|
|
3617
|
+
}
|
|
3618
|
+
for (const p of read.points) {
|
|
3619
|
+
const value = valueOf(s.kind, p);
|
|
3620
|
+
if (value !== void 0) points.push({
|
|
3621
|
+
capName: s.capName,
|
|
3622
|
+
field: s.field,
|
|
3623
|
+
at: p.t,
|
|
3624
|
+
value
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
return coalesceChanges({
|
|
3629
|
+
points,
|
|
3630
|
+
before,
|
|
3631
|
+
now: this.clock()
|
|
3632
|
+
});
|
|
3633
|
+
}
|
|
3634
|
+
};
|
|
3635
|
+
//#endregion
|
|
3636
|
+
//#region src/builtins/device-history/transitions/history-change-port.ts
|
|
3637
|
+
/**
|
|
3638
|
+
* The derived-changes reader's view of device-history (D1084): which audited fields of a device
|
|
3639
|
+
* have a series, and their raw points. A field with no series (its cap has no `history` block)
|
|
3640
|
+
* has no derived row.
|
|
3641
|
+
*/
|
|
3642
|
+
/** `cap:<capName>.<field>` → its parts, or `null` for a key that is not a top-level cap field. */
|
|
3643
|
+
function splitCapKey(key) {
|
|
3644
|
+
if (!key.startsWith("cap:")) return null;
|
|
3645
|
+
const rest = key.slice(CAP_KEY_PREFIX.length);
|
|
3646
|
+
const dot = rest.indexOf(".");
|
|
3647
|
+
if (dot <= 0 || dot === rest.length - 1) return null;
|
|
3648
|
+
return {
|
|
3649
|
+
capName: rest.slice(0, dot),
|
|
3650
|
+
field: rest.slice(dot + 1)
|
|
3651
|
+
};
|
|
3652
|
+
}
|
|
3653
|
+
var HistoryChangePort = class {
|
|
3654
|
+
deps;
|
|
3655
|
+
constructor(deps) {
|
|
3656
|
+
this.deps = deps;
|
|
3657
|
+
}
|
|
3658
|
+
auditedSeries(deviceId) {
|
|
3659
|
+
const out = [];
|
|
3660
|
+
for (const series of this.deps.registry.forSubject(`d:${deviceId}`)) {
|
|
3661
|
+
if (series.scope !== "") continue;
|
|
3662
|
+
const parts = splitCapKey(series.key);
|
|
3663
|
+
if (parts === null || !auditedFields(parts.capName).has(parts.field)) continue;
|
|
3664
|
+
const kind = this.deps.registry.metric(series.key)?.kind;
|
|
3665
|
+
if (kind === void 0) continue;
|
|
3666
|
+
out.push({
|
|
3667
|
+
capName: parts.capName,
|
|
3668
|
+
field: parts.field,
|
|
3669
|
+
kind
|
|
3670
|
+
});
|
|
3671
|
+
}
|
|
3672
|
+
return out;
|
|
3673
|
+
}
|
|
3674
|
+
async readRaw(deviceId, series, from, to) {
|
|
3675
|
+
const result = await this.deps.query.query({
|
|
3676
|
+
key: capSeriesKey(series.capName, series.field),
|
|
3677
|
+
subject: {
|
|
3678
|
+
kind: "device",
|
|
3679
|
+
deviceId
|
|
3680
|
+
},
|
|
3681
|
+
scope: "",
|
|
3682
|
+
from,
|
|
3683
|
+
to,
|
|
3684
|
+
resolution: "raw",
|
|
3685
|
+
maxPoints: DERIVED_POINTS_MAX
|
|
3686
|
+
});
|
|
3687
|
+
if (result.truncated) this.deps.logger.warn("derived device changes read cut at the raw point cap; the oldest points are left out", {
|
|
3688
|
+
tags: { deviceId },
|
|
3689
|
+
meta: {
|
|
3690
|
+
field: `${series.capName}.${series.field}`,
|
|
3691
|
+
cap: DERIVED_POINTS_MAX
|
|
3692
|
+
}
|
|
3693
|
+
});
|
|
3694
|
+
const first = result.series[0];
|
|
3695
|
+
if (first === void 0) return {
|
|
3696
|
+
before: null,
|
|
3697
|
+
points: []
|
|
3698
|
+
};
|
|
3699
|
+
return {
|
|
3700
|
+
before: first.before === null ? null : {
|
|
3701
|
+
t: first.before.t,
|
|
3702
|
+
value: first.before.value,
|
|
3703
|
+
state: first.before.state
|
|
3704
|
+
},
|
|
3705
|
+
points: first.points.map((p) => ({
|
|
3706
|
+
t: p.t,
|
|
3707
|
+
value: p.last,
|
|
3708
|
+
state: p.state
|
|
3709
|
+
}))
|
|
3710
|
+
};
|
|
3711
|
+
}
|
|
3712
|
+
};
|
|
3526
3713
|
var deviceTransitionsRecordKinds = defineRecordKinds({ "device-transitions": {
|
|
3527
|
-
schema: DeviceTransitionSchema,
|
|
3714
|
+
schema: DeviceTransitionSchema.refine((row) => row.outcome !== "device", {
|
|
3715
|
+
message: "a derived device change is not stored",
|
|
3716
|
+
path: ["outcome"]
|
|
3717
|
+
}),
|
|
3528
3718
|
class: "audit",
|
|
3529
3719
|
database: "events",
|
|
3530
|
-
writeTrigger: "the hub kernel delivers a batch of
|
|
3720
|
+
writeTrigger: "the hub kernel delivers a batch of completed device commands, one row per command with its actor and ok or failed outcome",
|
|
3531
3721
|
device: "required",
|
|
3532
3722
|
at: "required",
|
|
3533
3723
|
indexes: [
|
|
@@ -3586,6 +3776,101 @@ function assertOneFilter(filters) {
|
|
|
3586
3776
|
function isRejectedRow(err) {
|
|
3587
3777
|
return err instanceof InvalidRecordError || err instanceof RecordTooLargeError;
|
|
3588
3778
|
}
|
|
3779
|
+
var SOURCE_CHANGE = 0;
|
|
3780
|
+
var SOURCE_COMMAND = 1;
|
|
3781
|
+
function compareKeys(a, b) {
|
|
3782
|
+
if (a.at !== b.at) return a.at - b.at;
|
|
3783
|
+
if (a.source !== b.source) return a.source - b.source;
|
|
3784
|
+
return compareIds(a.id, b.id);
|
|
3785
|
+
}
|
|
3786
|
+
/**
|
|
3787
|
+
* Ids in the order the store yields one millisecond: insertion order, which for a command id
|
|
3788
|
+
* `<deviceId>:<at>:c<seq>` is its sequence NUMBER, so `c9` precedes `c10`. A plain string compare
|
|
3789
|
+
* puts `c10` first and a cursor on either side of that pair drops a row.
|
|
3790
|
+
*/
|
|
3791
|
+
function compareIds(a, b) {
|
|
3792
|
+
const left = a.match(/\d+|\D+/g) ?? [];
|
|
3793
|
+
const right = b.match(/\d+|\D+/g) ?? [];
|
|
3794
|
+
for (let i = 0; i < Math.min(left.length, right.length); i += 1) {
|
|
3795
|
+
const x = left[i] ?? "";
|
|
3796
|
+
const y = right[i] ?? "";
|
|
3797
|
+
if (x === y) continue;
|
|
3798
|
+
if (/^\d/.test(x) && /^\d/.test(y)) return Number(x) - Number(y);
|
|
3799
|
+
return x < y ? -1 : 1;
|
|
3800
|
+
}
|
|
3801
|
+
return left.length - right.length;
|
|
3802
|
+
}
|
|
3803
|
+
function commandKey(row) {
|
|
3804
|
+
return {
|
|
3805
|
+
key: {
|
|
3806
|
+
at: row.at,
|
|
3807
|
+
source: SOURCE_COMMAND,
|
|
3808
|
+
id: row.id
|
|
3809
|
+
},
|
|
3810
|
+
row
|
|
3811
|
+
};
|
|
3812
|
+
}
|
|
3813
|
+
/** A derived change as a row: actor `device`, outcome `device`, an id that names what it is. */
|
|
3814
|
+
function changeKey(deviceId, change) {
|
|
3815
|
+
const id = `chg:${deviceId}:${change.at}:${change.capName}.${change.field}`;
|
|
3816
|
+
return {
|
|
3817
|
+
key: {
|
|
3818
|
+
at: change.at,
|
|
3819
|
+
source: SOURCE_CHANGE,
|
|
3820
|
+
id
|
|
3821
|
+
},
|
|
3822
|
+
row: {
|
|
3823
|
+
id,
|
|
3824
|
+
deviceId,
|
|
3825
|
+
at: change.at,
|
|
3826
|
+
capName: change.capName,
|
|
3827
|
+
field: change.field,
|
|
3828
|
+
from: change.from,
|
|
3829
|
+
to: change.to,
|
|
3830
|
+
outcome: "device",
|
|
3831
|
+
actor: { kind: "device" }
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
}
|
|
3835
|
+
function cursorOf(item) {
|
|
3836
|
+
return `${item.key.at}.${item.key.source}.${item.key.id}`;
|
|
3837
|
+
}
|
|
3838
|
+
function parseCursor(cursor) {
|
|
3839
|
+
const first = cursor.indexOf(".");
|
|
3840
|
+
const second = cursor.indexOf(".", first + 1);
|
|
3841
|
+
const at = Number(cursor.slice(0, first));
|
|
3842
|
+
const source = cursor.slice(first + 1, second);
|
|
3843
|
+
if (first < 0 || second < 0 || !Number.isFinite(at) || source !== "0" && source !== "1") throw new Error("invalid cursor");
|
|
3844
|
+
return {
|
|
3845
|
+
at,
|
|
3846
|
+
source: source === "1" ? SOURCE_COMMAND : SOURCE_CHANGE,
|
|
3847
|
+
id: cursor.slice(second + 1)
|
|
3848
|
+
};
|
|
3849
|
+
}
|
|
3850
|
+
/** Take the first `count` rows of several newest-first sources, merged into one newest-first run. */
|
|
3851
|
+
async function takeMerged(sources, count) {
|
|
3852
|
+
const iterators = sources.map((s) => s[Symbol.asyncIterator]());
|
|
3853
|
+
const heads = await Promise.all(iterators.map((it) => it.next()));
|
|
3854
|
+
const out = [];
|
|
3855
|
+
try {
|
|
3856
|
+
while (out.length < count) {
|
|
3857
|
+
let best = -1;
|
|
3858
|
+
for (const [i, head] of heads.entries()) {
|
|
3859
|
+
if (head.done === true) continue;
|
|
3860
|
+
const current = best < 0 ? void 0 : heads[best];
|
|
3861
|
+
if (current === void 0 || current.done === true || compareKeys(head.value.key, current.value.key) > 0) best = i;
|
|
3862
|
+
}
|
|
3863
|
+
const winner = best < 0 ? void 0 : heads[best];
|
|
3864
|
+
if (winner === void 0 || winner.done === true) break;
|
|
3865
|
+
out.push(winner.value);
|
|
3866
|
+
const it = iterators[best];
|
|
3867
|
+
if (it !== void 0) heads[best] = await it.next();
|
|
3868
|
+
}
|
|
3869
|
+
} finally {
|
|
3870
|
+
await Promise.all(iterators.map((it) => it.return?.()));
|
|
3871
|
+
}
|
|
3872
|
+
return out;
|
|
3873
|
+
}
|
|
3589
3874
|
var TransitionsService = class {
|
|
3590
3875
|
deps;
|
|
3591
3876
|
handle = null;
|
|
@@ -3674,56 +3959,104 @@ var TransitionsService = class {
|
|
|
3674
3959
|
refused
|
|
3675
3960
|
};
|
|
3676
3961
|
}
|
|
3962
|
+
/**
|
|
3963
|
+
* One time-ordered page of a device's commands and its own changes, newest first. The cursor
|
|
3964
|
+
* is the sort key of the last row returned (time, source, id), so a page boundary is the same
|
|
3965
|
+
* whichever source the last row came from. `outcome` and every actor kind but `device` select
|
|
3966
|
+
* commands; `actorKind: 'device'` selects the derived changes.
|
|
3967
|
+
*/
|
|
3677
3968
|
async list(input) {
|
|
3678
3969
|
assertOneFilter({
|
|
3679
3970
|
capName: input.capName,
|
|
3680
3971
|
actorKind: input.actorKind,
|
|
3681
3972
|
outcome: input.outcome
|
|
3682
3973
|
});
|
|
3683
|
-
const
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3974
|
+
const after = input.cursor === void 0 ? null : parseCursor(input.cursor);
|
|
3975
|
+
const wantCommands = input.actorKind !== "device";
|
|
3976
|
+
const wantChanges = input.outcome === void 0 && (input.actorKind === void 0 || input.actorKind === "device");
|
|
3977
|
+
const sources = [];
|
|
3978
|
+
if (wantCommands) sources.push(this.commandRows(input, after));
|
|
3979
|
+
if (wantChanges) sources.push(await this.changeRows(input, after));
|
|
3980
|
+
const page = await takeMerged(sources, input.limit + 1);
|
|
3981
|
+
const rows = page.slice(0, input.limit);
|
|
3982
|
+
const last = rows[rows.length - 1];
|
|
3983
|
+
return {
|
|
3984
|
+
transitions: rows.map((r) => r.row),
|
|
3985
|
+
nextCursor: page.length > input.limit && last !== void 0 ? cursorOf(last) : null
|
|
3687
3986
|
};
|
|
3688
|
-
|
|
3987
|
+
}
|
|
3988
|
+
/** Stored commands, newest first, strictly after the cursor. */
|
|
3989
|
+
async *commandRows(input, after) {
|
|
3689
3990
|
const handle = this.kind();
|
|
3690
|
-
const
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
...range
|
|
3695
|
-
},
|
|
3696
|
-
...paging
|
|
3697
|
-
}) : input.actorKind !== void 0 ? await handle.query({
|
|
3698
|
-
where: {
|
|
3699
|
-
deviceId: input.deviceId,
|
|
3700
|
-
"actor.kind": input.actorKind,
|
|
3701
|
-
...range
|
|
3702
|
-
},
|
|
3703
|
-
...paging
|
|
3704
|
-
}) : input.outcome !== void 0 ? await handle.query({
|
|
3705
|
-
where: {
|
|
3706
|
-
deviceId: input.deviceId,
|
|
3707
|
-
outcome: input.outcome,
|
|
3708
|
-
...range
|
|
3709
|
-
},
|
|
3710
|
-
...paging
|
|
3711
|
-
}) : await handle.query({
|
|
3712
|
-
deviceId: input.deviceId,
|
|
3713
|
-
...input.atFrom !== void 0 ? { atFrom: input.atFrom } : {},
|
|
3714
|
-
...input.atTo !== void 0 ? { atTo: input.atTo } : {},
|
|
3715
|
-
...paging
|
|
3991
|
+
const atTo = Math.min(input.atTo ?? Number.POSITIVE_INFINITY, after === null ? Infinity : after.at + 1);
|
|
3992
|
+
const range = rangeOf({
|
|
3993
|
+
atFrom: input.atFrom,
|
|
3994
|
+
atTo: Number.isFinite(atTo) ? atTo : void 0
|
|
3716
3995
|
});
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3996
|
+
let cursor;
|
|
3997
|
+
for (;;) {
|
|
3998
|
+
const paging = {
|
|
3999
|
+
desc: true,
|
|
4000
|
+
limit: input.limit + 1,
|
|
4001
|
+
...cursor !== void 0 ? { cursor } : {}
|
|
4002
|
+
};
|
|
4003
|
+
const page = input.capName !== void 0 ? await handle.query({
|
|
4004
|
+
where: {
|
|
4005
|
+
deviceId: input.deviceId,
|
|
4006
|
+
capName: input.capName,
|
|
4007
|
+
...range
|
|
4008
|
+
},
|
|
4009
|
+
...paging
|
|
4010
|
+
}) : input.actorKind !== void 0 ? await handle.query({
|
|
4011
|
+
where: {
|
|
4012
|
+
deviceId: input.deviceId,
|
|
4013
|
+
"actor.kind": input.actorKind,
|
|
4014
|
+
...range
|
|
4015
|
+
},
|
|
4016
|
+
...paging
|
|
4017
|
+
}) : input.outcome !== void 0 ? await handle.query({
|
|
4018
|
+
where: {
|
|
4019
|
+
deviceId: input.deviceId,
|
|
4020
|
+
outcome: input.outcome,
|
|
4021
|
+
...range
|
|
4022
|
+
},
|
|
4023
|
+
...paging
|
|
4024
|
+
}) : await handle.query({
|
|
4025
|
+
deviceId: input.deviceId,
|
|
4026
|
+
...input.atFrom !== void 0 ? { atFrom: input.atFrom } : {},
|
|
4027
|
+
...atTo !== Infinity ? { atTo } : {},
|
|
4028
|
+
...paging
|
|
4029
|
+
});
|
|
4030
|
+
for (const record of page.records) {
|
|
4031
|
+
const keyed = commandKey(record.data);
|
|
4032
|
+
if (after === null || compareKeys(keyed.key, after) < 0) yield keyed;
|
|
4033
|
+
}
|
|
4034
|
+
if (page.nextCursor === null) return;
|
|
4035
|
+
cursor = page.nextCursor;
|
|
4036
|
+
}
|
|
3721
4037
|
}
|
|
4038
|
+
/** The device's derived changes, newest first, strictly after the cursor. */
|
|
4039
|
+
async changeRows(input, after) {
|
|
4040
|
+
const now = this.deps.clock();
|
|
4041
|
+
const rows = (await this.deps.derived.read(input.deviceId, {
|
|
4042
|
+
from: input.atFrom ?? 0,
|
|
4043
|
+
to: Math.min(input.atTo ?? now, now),
|
|
4044
|
+
capName: input.capName
|
|
4045
|
+
})).filter((c) => input.atTo === void 0 || c.at < input.atTo).filter((c) => input.atFrom === void 0 || c.at >= input.atFrom).map((c) => changeKey(input.deviceId, c)).toSorted((a, b) => compareKeys(b.key, a.key)).filter((k) => after === null || compareKeys(k.key, after) < 0);
|
|
4046
|
+
return (async function* () {
|
|
4047
|
+
for (const row of rows) yield row;
|
|
4048
|
+
})();
|
|
4049
|
+
}
|
|
4050
|
+
/** The fleet page: stored commands only. A device's own changes are derived per device. */
|
|
3722
4051
|
async listRecent(input) {
|
|
3723
4052
|
assertOneFilter({
|
|
3724
4053
|
actorKind: input.actorKind,
|
|
3725
4054
|
outcome: input.outcome
|
|
3726
4055
|
});
|
|
4056
|
+
if (input.actorKind === "device") return {
|
|
4057
|
+
transitions: [],
|
|
4058
|
+
nextCursor: null
|
|
4059
|
+
};
|
|
3727
4060
|
const paging = {
|
|
3728
4061
|
desc: true,
|
|
3729
4062
|
limit: input.limit,
|
|
@@ -3809,6 +4142,138 @@ var TransitionsService = class {
|
|
|
3809
4142
|
}
|
|
3810
4143
|
};
|
|
3811
4144
|
//#endregion
|
|
4145
|
+
//#region src/builtins/device-history/retention/device-raw-overrides.ts
|
|
4146
|
+
function positive(value) {
|
|
4147
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
4148
|
+
}
|
|
4149
|
+
function parseRawOverride(record) {
|
|
4150
|
+
const rawDays = positive(record["rawDays"]);
|
|
4151
|
+
const rawDiscreteDays = positive(record["rawDiscreteDays"]);
|
|
4152
|
+
return {
|
|
4153
|
+
...rawDays === void 0 ? {} : { rawDays },
|
|
4154
|
+
...rawDiscreteDays === void 0 ? {} : { rawDiscreteDays }
|
|
4155
|
+
};
|
|
4156
|
+
}
|
|
4157
|
+
/** Every device with an override, one read for the ids and one batch for the values. Throws when the store cannot be asked. */
|
|
4158
|
+
async function readRawOverrides(settings) {
|
|
4159
|
+
const ids = await settings.listDeviceStoreIds();
|
|
4160
|
+
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
4161
|
+
const rows = await settings.readDeviceStoreBatch(ids);
|
|
4162
|
+
const out = /* @__PURE__ */ new Map();
|
|
4163
|
+
for (const [deviceId, record] of rows) {
|
|
4164
|
+
const parsed = parseRawOverride(record);
|
|
4165
|
+
if (parsed.rawDays !== void 0 || parsed.rawDiscreteDays !== void 0) out.set(deviceId, parsed);
|
|
4166
|
+
}
|
|
4167
|
+
return out;
|
|
4168
|
+
}
|
|
4169
|
+
//#endregion
|
|
4170
|
+
//#region src/builtins/device-history/retention/retention-knobs.ts
|
|
4171
|
+
var DEVICE_HISTORY_ADDON_ID = "device-history";
|
|
4172
|
+
var CAP = "device-history";
|
|
4173
|
+
var RAW_KEYS = ["rawDays", "rawDiscreteDays"];
|
|
4174
|
+
var SPECS = [
|
|
4175
|
+
{
|
|
4176
|
+
key: "rawDays",
|
|
4177
|
+
label: "Raw points of measurements",
|
|
4178
|
+
min: 1,
|
|
4179
|
+
max: 60,
|
|
4180
|
+
zeroMeansForever: false
|
|
4181
|
+
},
|
|
4182
|
+
{
|
|
4183
|
+
key: "rawDiscreteDays",
|
|
4184
|
+
label: "Raw points of states",
|
|
4185
|
+
min: 1,
|
|
4186
|
+
max: 365,
|
|
4187
|
+
zeroMeansForever: false
|
|
4188
|
+
},
|
|
4189
|
+
{
|
|
4190
|
+
key: "fiveMinuteDays",
|
|
4191
|
+
label: "5-minute rollup",
|
|
4192
|
+
min: 1,
|
|
4193
|
+
max: 365,
|
|
4194
|
+
zeroMeansForever: false
|
|
4195
|
+
},
|
|
4196
|
+
{
|
|
4197
|
+
key: "hourDays",
|
|
4198
|
+
label: "1-hour rollup",
|
|
4199
|
+
min: 7,
|
|
4200
|
+
max: 3650,
|
|
4201
|
+
zeroMeansForever: false
|
|
4202
|
+
},
|
|
4203
|
+
{
|
|
4204
|
+
key: "dayDays",
|
|
4205
|
+
label: "1-day rollup",
|
|
4206
|
+
min: 0,
|
|
4207
|
+
max: 36500,
|
|
4208
|
+
zeroMeansForever: true
|
|
4209
|
+
},
|
|
4210
|
+
{
|
|
4211
|
+
key: "transitionDays",
|
|
4212
|
+
label: "Device commands",
|
|
4213
|
+
min: 7,
|
|
4214
|
+
max: 3650,
|
|
4215
|
+
zeroMeansForever: false
|
|
4216
|
+
}
|
|
4217
|
+
];
|
|
4218
|
+
function isRawKey(key) {
|
|
4219
|
+
return key === "rawDays" || key === "rawDiscreteDays";
|
|
4220
|
+
}
|
|
4221
|
+
function knobFor(spec, policy, deviceId, override) {
|
|
4222
|
+
const cluster = policy[spec.key];
|
|
4223
|
+
const base = {
|
|
4224
|
+
id: `${DEVICE_HISTORY_ADDON_ID}:${spec.key}`,
|
|
4225
|
+
owner: DEVICE_HISTORY_ADDON_ID,
|
|
4226
|
+
key: spec.key,
|
|
4227
|
+
labelKey: `retention.${DEVICE_HISTORY_ADDON_ID}.${spec.key}`,
|
|
4228
|
+
label: spec.label,
|
|
4229
|
+
group: "history",
|
|
4230
|
+
unit: "days",
|
|
4231
|
+
defaultValue: DEFAULT_RETENTION[spec.key],
|
|
4232
|
+
min: spec.min,
|
|
4233
|
+
max: spec.max,
|
|
4234
|
+
zeroMeansForever: spec.zeroMeansForever
|
|
4235
|
+
};
|
|
4236
|
+
if (!isRawKey(spec.key)) return {
|
|
4237
|
+
...base,
|
|
4238
|
+
value: cluster,
|
|
4239
|
+
scope: "cluster",
|
|
4240
|
+
write: {
|
|
4241
|
+
method: "updateScopedSettings",
|
|
4242
|
+
addonId: DEVICE_HISTORY_ADDON_ID,
|
|
4243
|
+
cap: CAP,
|
|
4244
|
+
scope: "cluster",
|
|
4245
|
+
key: spec.key
|
|
4246
|
+
}
|
|
4247
|
+
};
|
|
4248
|
+
const own = override?.[spec.key];
|
|
4249
|
+
return {
|
|
4250
|
+
...base,
|
|
4251
|
+
value: own ?? cluster,
|
|
4252
|
+
scope: "device",
|
|
4253
|
+
...deviceId === void 0 ? {} : { deviceId },
|
|
4254
|
+
inherited: own === void 0,
|
|
4255
|
+
inheritedValue: cluster,
|
|
4256
|
+
write: deviceId === void 0 ? {
|
|
4257
|
+
method: "updateScopedSettings",
|
|
4258
|
+
addonId: DEVICE_HISTORY_ADDON_ID,
|
|
4259
|
+
cap: CAP,
|
|
4260
|
+
scope: "cluster",
|
|
4261
|
+
key: spec.key
|
|
4262
|
+
} : {
|
|
4263
|
+
method: "updateDeviceSettings",
|
|
4264
|
+
addonId: DEVICE_HISTORY_ADDON_ID,
|
|
4265
|
+
key: spec.key
|
|
4266
|
+
}
|
|
4267
|
+
};
|
|
4268
|
+
}
|
|
4269
|
+
/**
|
|
4270
|
+
* Without a device: every knob, a raw window listed with the cluster value it defaults to.
|
|
4271
|
+
* With one: only the device-scoped knobs, each saying whether the device follows the cluster.
|
|
4272
|
+
*/
|
|
4273
|
+
function deviceHistoryKnobs(policy, deviceId, override) {
|
|
4274
|
+
return (deviceId === void 0 ? SPECS : SPECS.filter((s) => RAW_KEYS.some((k) => k === s.key))).map((spec) => knobFor(spec, policy, deviceId, override));
|
|
4275
|
+
}
|
|
4276
|
+
//#endregion
|
|
3812
4277
|
//#region src/builtins/device-history/device-history.addon.ts
|
|
3813
4278
|
/**
|
|
3814
4279
|
* device-history — the ONE mechanism for numeric history (D850). Hub-only, its
|
|
@@ -3833,6 +4298,7 @@ var TransitionsService = class {
|
|
|
3833
4298
|
*/
|
|
3834
4299
|
var DEFAULT_CONFIG = {
|
|
3835
4300
|
rawDays: DEFAULT_RETENTION.rawDays,
|
|
4301
|
+
rawDiscreteDays: DEFAULT_RETENTION.rawDiscreteDays,
|
|
3836
4302
|
fiveMinuteDays: DEFAULT_RETENTION.fiveMinuteDays,
|
|
3837
4303
|
hourDays: DEFAULT_RETENTION.hourDays,
|
|
3838
4304
|
dayDays: 0,
|
|
@@ -3900,6 +4366,7 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3900
4366
|
const c = this.config;
|
|
3901
4367
|
return {
|
|
3902
4368
|
rawDays: positiveOr(c.rawDays, DEFAULT_RETENTION.rawDays),
|
|
4369
|
+
rawDiscreteDays: positiveOr(c.rawDiscreteDays, DEFAULT_RETENTION.rawDiscreteDays),
|
|
3903
4370
|
fiveMinuteDays: positiveOr(c.fiveMinuteDays, DEFAULT_RETENTION.fiveMinuteDays),
|
|
3904
4371
|
hourDays: positiveOr(c.hourDays, DEFAULT_RETENTION.hourDays),
|
|
3905
4372
|
dayDays: positiveOr(c.dayDays, 0) > 0 ? c.dayDays : null,
|
|
@@ -3978,6 +4445,11 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3978
4445
|
record: async (input) => this.requireTransitions().record(callerOf(input), input.transitions),
|
|
3979
4446
|
getStatus: async () => this.requireTransitions().status()
|
|
3980
4447
|
};
|
|
4448
|
+
const retentionSource = { listRetentionKnobs: async (input) => {
|
|
4449
|
+
const deviceId = input.deviceId;
|
|
4450
|
+
const stored = deviceId === void 0 ? void 0 : await this.ctx.settings?.readDeviceStore(deviceId);
|
|
4451
|
+
return deviceHistoryKnobs(this.retention(), deviceId, stored === void 0 ? void 0 : parseRawOverride(stored));
|
|
4452
|
+
} };
|
|
3981
4453
|
this.emitStoreReadiness("starting");
|
|
3982
4454
|
this.ctx.logger.info("Initialized — device-history provider registered (store opens on hub link)");
|
|
3983
4455
|
const removalHook = {
|
|
@@ -4037,6 +4509,10 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
4037
4509
|
{
|
|
4038
4510
|
capability: deviceRemovalHookCapability,
|
|
4039
4511
|
provider: removalHook
|
|
4512
|
+
},
|
|
4513
|
+
{
|
|
4514
|
+
capability: retentionSourceCapability,
|
|
4515
|
+
provider: retentionSource
|
|
4040
4516
|
}
|
|
4041
4517
|
];
|
|
4042
4518
|
}
|
|
@@ -4081,9 +4557,11 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
4081
4557
|
const runsOpened = await runs.open();
|
|
4082
4558
|
this.runsProvider = runsOpened.provider;
|
|
4083
4559
|
this.runs = runs;
|
|
4084
|
-
const transitions = await this.openTransitions();
|
|
4560
|
+
const transitions = await this.openTransitions(runtime);
|
|
4085
4561
|
this.transitions = transitions;
|
|
4086
4562
|
runtime.retentionJob.attachTransitions(transitions);
|
|
4563
|
+
const settings = this.ctx.settings;
|
|
4564
|
+
if (settings !== void 0) runtime.retentionJob.attachDeviceOverrides(() => readRawOverrides(settings));
|
|
4087
4565
|
this.unsubscribe = this.ctx.eventBus.subscribe({ category: EventCategory.DeviceStateChanged }, (event) => {
|
|
4088
4566
|
const data = parseConfirmedStateChanged(event.data);
|
|
4089
4567
|
if (data === null) return;
|
|
@@ -4137,14 +4615,19 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
4137
4615
|
clock: () => Date.now()
|
|
4138
4616
|
});
|
|
4139
4617
|
}
|
|
4140
|
-
async openTransitions() {
|
|
4618
|
+
async openTransitions(runtime) {
|
|
4141
4619
|
const { ctx } = this;
|
|
4142
4620
|
const records = ctx.records;
|
|
4143
4621
|
if (records === void 0) throw new Error("device-history needs ctx.records on the hub for the transition ledger");
|
|
4144
4622
|
const transitions = new TransitionsService({
|
|
4145
4623
|
records,
|
|
4146
4624
|
logger: ctx.logger,
|
|
4147
|
-
clock: () => Date.now()
|
|
4625
|
+
clock: () => Date.now(),
|
|
4626
|
+
derived: new DerivedChanges(new HistoryChangePort({
|
|
4627
|
+
registry: runtime.registry,
|
|
4628
|
+
query: runtime.query,
|
|
4629
|
+
logger: ctx.logger
|
|
4630
|
+
}), () => Date.now())
|
|
4148
4631
|
});
|
|
4149
4632
|
await transitions.open();
|
|
4150
4633
|
return transitions;
|
|
@@ -4166,22 +4649,59 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
4166
4649
|
scopedSettingsCapabilities() {
|
|
4167
4650
|
return ["device-history"];
|
|
4168
4651
|
}
|
|
4652
|
+
/**
|
|
4653
|
+
* D865: the two raw windows a device may override, in the standard per-device store. Unset
|
|
4654
|
+
* means the device follows the cluster value (shown by the retention catalog).
|
|
4655
|
+
*/
|
|
4656
|
+
deviceSettingsSchema() {
|
|
4657
|
+
return this.schema({ sections: [{
|
|
4658
|
+
id: "retention",
|
|
4659
|
+
title: "History retention",
|
|
4660
|
+
description: "Leave a field empty to follow the system-wide window (Data → Retention).",
|
|
4661
|
+
columns: 2,
|
|
4662
|
+
fields: [{
|
|
4663
|
+
type: "number",
|
|
4664
|
+
key: "rawDays",
|
|
4665
|
+
label: "Raw points of measurements (days)",
|
|
4666
|
+
min: 1,
|
|
4667
|
+
max: 60,
|
|
4668
|
+
step: 1
|
|
4669
|
+
}, {
|
|
4670
|
+
type: "number",
|
|
4671
|
+
key: "rawDiscreteDays",
|
|
4672
|
+
label: "Raw points of states (days)",
|
|
4673
|
+
min: 1,
|
|
4674
|
+
max: 365,
|
|
4675
|
+
step: 1
|
|
4676
|
+
}]
|
|
4677
|
+
}] });
|
|
4678
|
+
}
|
|
4169
4679
|
async clusterSettingsSchema(cap) {
|
|
4170
4680
|
if (cap !== "device-history") return null;
|
|
4171
4681
|
return this.schema({ sections: [{
|
|
4172
4682
|
id: "retention",
|
|
4173
4683
|
title: "Retention",
|
|
4174
|
-
description: "How long each tier is kept. The raw points feed the 5-minute rollup; the 1-day tier is kept forever unless a number of days is set. Device transitions (who changed what) are kept for their own number of days.",
|
|
4684
|
+
description: "How long each tier is kept. The raw points feed the 5-minute rollup, and a state series keeps them longer than a measurement; the 1-day tier is kept forever unless a number of days is set. Device transitions (who changed what) are kept for their own number of days.",
|
|
4175
4685
|
columns: 2,
|
|
4176
4686
|
fields: [
|
|
4177
4687
|
{
|
|
4178
4688
|
type: "number",
|
|
4179
4689
|
key: "rawDays",
|
|
4180
|
-
label: "Raw points (days)",
|
|
4690
|
+
label: "Raw points of measurements (days)",
|
|
4691
|
+
description: "Gauges and counters: temperature, power, battery level.",
|
|
4181
4692
|
min: 1,
|
|
4182
4693
|
max: 60,
|
|
4183
4694
|
step: 1
|
|
4184
4695
|
},
|
|
4696
|
+
{
|
|
4697
|
+
type: "number",
|
|
4698
|
+
key: "rawDiscreteDays",
|
|
4699
|
+
label: "Raw points of states (days)",
|
|
4700
|
+
description: "Booleans and enums: on/off, open/closed, modes. These are the changes the Interactions view lists, so they are kept longer.",
|
|
4701
|
+
min: 1,
|
|
4702
|
+
max: 365,
|
|
4703
|
+
step: 1
|
|
4704
|
+
},
|
|
4185
4705
|
{
|
|
4186
4706
|
type: "number",
|
|
4187
4707
|
key: "fiveMinuteDays",
|