@camstack/server 1.2.752 → 1.2.754

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 (93) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/api/trpc/generated-cap-routers.js +10 -0
  3. package/dist/core/moleculer/moleculer.service.js +13 -1
  4. package/package.json +8 -8
  5. package/system/dist/addon-utils.mjs +1 -1
  6. package/system/dist/{agent-https-Oc0Go3Gs.js → agent-https-B0bjQVfy.js} +1 -1
  7. package/system/dist/{agent-https-DoGV9jKg.mjs → agent-https-cxghRfum.mjs} +1 -1
  8. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  9. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
  10. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  11. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
  12. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  13. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  14. package/system/dist/builtins/autotrack/index.js +1 -1
  15. package/system/dist/builtins/autotrack/index.mjs +1 -1
  16. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  17. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
  18. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  19. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  20. package/system/dist/builtins/camera-grid/index.js +1 -1
  21. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  22. package/system/dist/builtins/composer/composer.addon.js +18 -22
  23. package/system/dist/builtins/composer/composer.addon.mjs +17 -21
  24. package/system/dist/builtins/console-logging/index.js +1 -1
  25. package/system/dist/builtins/console-logging/index.mjs +1 -1
  26. package/system/dist/builtins/core-blocks/composition-api.d.ts +4 -1
  27. package/system/dist/builtins/core-blocks/core-blocks.addon.js +232 -15
  28. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +232 -15
  29. package/system/dist/builtins/core-blocks/running-proposal.d.ts +32 -0
  30. package/system/dist/builtins/device-history/device-history.addon.js +24 -23
  31. package/system/dist/builtins/device-history/device-history.addon.mjs +3 -2
  32. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  33. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  34. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  35. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  36. package/system/dist/builtins/keychain/index.js +3 -3
  37. package/system/dist/builtins/keychain/index.mjs +3 -3
  38. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  39. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  40. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  41. package/system/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
  42. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  43. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  44. package/system/dist/builtins/loki-logging/index.js +1 -1
  45. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  46. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  47. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
  48. package/system/dist/builtins/platform-probe/index.js +1 -1
  49. package/system/dist/builtins/platform-probe/index.mjs +10 -10
  50. package/system/dist/builtins/record-entries/index.js +1 -1
  51. package/system/dist/builtins/record-entries/index.mjs +1 -1
  52. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  53. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  54. package/system/dist/builtins/snapshot/index.js +5 -1
  55. package/system/dist/builtins/snapshot/index.mjs +5 -1
  56. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  57. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
  58. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  59. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  60. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2 -2
  61. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
  62. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  63. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  64. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  65. package/system/dist/builtins/system-config/system-config.addon.mjs +285 -285
  66. package/system/dist/builtins/winston-logging/index.js +1 -1
  67. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  68. package/system/dist/{retention-C-lijsmN.mjs → capture-engine-CfJdhMTH.mjs} +2 -246
  69. package/system/dist/{retention-WjI-Op7G.js → capture-engine-eRAebXP1.js} +1 -305
  70. package/system/dist/{composition-sources-Bxahhz4f.js → composition-sources-BvDYLpw_.js} +1 -1
  71. package/system/dist/{composition-sources-CzRiSzCV.mjs → composition-sources-ChtkMq1Q.mjs} +1 -1
  72. package/system/dist/{constants-uI6uXyjP.mjs → constants-CYNsr0lM.mjs} +1 -1
  73. package/system/dist/{constants-0rC5QY6i.js → constants-DkC9-VOa.js} +1 -1
  74. package/system/dist/{coral-accelerators-DBlgWB8k.mjs → coral-accelerators-BW3OcrLD.mjs} +6 -6
  75. package/system/dist/{custom-action-registry-oHl1xltx.mjs → custom-action-registry-BIJZBObd.mjs} +37 -37
  76. package/system/dist/{device-ca-CL_Arugd.js → device-ca-BxInMpK2.js} +1 -1
  77. package/system/dist/{device-ca-D7TyMlsS.mjs → device-ca-CQg3PTnE.mjs} +1 -1
  78. package/system/dist/{dist-Iq3vrBOE.mjs → dist-C5eIFTMo.mjs} +752 -554
  79. package/system/dist/{dist-CYnRCUzN.js → dist-DFWnAzAY.js} +775 -553
  80. package/system/dist/file-host-worker.js +1 -1
  81. package/system/dist/file-host-worker.mjs +1 -1
  82. package/system/dist/{hub-mdns-ciao-CNLYSVyJ.js → hub-mdns-ciao-BQDdPkPO.js} +2 -2
  83. package/system/dist/{hub-mdns-ciao-CvMKderb.mjs → hub-mdns-ciao-DW_g42El.mjs} +2 -2
  84. package/system/dist/index.js +9 -8
  85. package/system/dist/index.mjs +220 -219
  86. package/system/dist/kernel/transport/parent-unowned-call.d.ts +10 -0
  87. package/system/dist/{restore-archive-vzWYLf6p.mjs → restore-archive-D8ZIN10X.mjs} +150 -150
  88. package/system/dist/{restore-archive-Dw04PiG5.js → restore-archive-DRjYgh6D.js} +1 -1
  89. package/system/dist/retention-B9l9TnGE.mjs +245 -0
  90. package/system/dist/retention-BNONb5X_.js +304 -0
  91. package/system/dist/{wal-maintenance-DQXiTaph.js → wal-maintenance-D0zSmIwJ.js} +0 -0
  92. package/system/dist/{wal-maintenance-BzTHorT2.mjs → wal-maintenance-xYk-FpJW.mjs} +0 -0
  93. package/system/package.json +1 -1
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-CYnRCUzN.js");
6
+ const require_dist = require("../../dist-DFWnAzAY.js");
7
7
  const require_formatter = require("../../formatter-xbxeV4GD.js");
8
8
  const require_log_file_read_protocol = require("../../log-file-read-protocol-D0WcLbIV.js");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { bo as BaseAddon, ni as logDestinationCapability } from "../../dist-Iq3vrBOE.mjs";
1
+ import { ri as logDestinationCapability, wo as BaseAddon } from "../../dist-C5eIFTMo.mjs";
2
2
  import { t as formatLogLine } from "../../formatter-DkYZ4LXp.mjs";
3
3
  import { a as LogFileIndexStore, i as serveRead, n as isFromReader, t as CancelBook } from "../../log-file-read-protocol-B7M3X3bT.mjs";
4
4
  import { createRequire } from "node:module";
@@ -1,4 +1,4 @@
1
- import { ac as DeviceType, ko as HISTORY_DEFAULT_MIN_INTERVAL_MS, xs as historyItemFieldPath } from "./dist-Iq3vrBOE.mjs";
1
+ import { No as HISTORY_DEFAULT_MIN_INTERVAL_MS, Ts as historyItemFieldPath, lc as DeviceType } from "./dist-C5eIFTMo.mjs";
2
2
  //#region src/builtins/device-history/store/series-registry.ts
3
3
  function subjectIdOf(subject) {
4
4
  return subject.kind === "device" ? `d:${subject.deviceId}` : `n:${subject.nodeId}`;
@@ -646,248 +646,4 @@ var CaptureEngine = class {
646
646
  }
647
647
  };
648
648
  //#endregion
649
- //#region src/builtins/device-history/time/bucket-time.ts
650
- /**
651
- * Bucket arithmetic for the three rollup tiers (D850, plan §4/§5.5).
652
- *
653
- * 5m and 1h buckets are aligned to UTC; a 1d bucket starts at HUB-LOCAL
654
- * midnight, so a day is 23, 24 or 25 hours long across a DST change (operator
655
- * answer Q4). Pure: the zone is the process zone (`TZ`), nothing is read from
656
- * the environment here.
657
- */
658
- var FIVE_MINUTES_MS = 5 * 6e4;
659
- var HOUR_MS = 60 * 6e4;
660
- var DAY_MS = 24 * HOUR_MS;
661
- function floorTo(ts, widthMs) {
662
- return Math.floor(ts / widthMs) * widthMs;
663
- }
664
- /** Hub-local midnight at or before `ts`. */
665
- function startOfLocalDay(ts) {
666
- const d = new Date(ts);
667
- d.setHours(0, 0, 0, 0);
668
- return d.getTime();
669
- }
670
- /** The local midnight following the local midnight `dayStart`. */
671
- function nextLocalDayStart(dayStart) {
672
- const d = new Date(dayStart);
673
- d.setDate(d.getDate() + 1);
674
- d.setHours(0, 0, 0, 0);
675
- return d.getTime();
676
- }
677
- /** Start of the `tier` bucket containing `ts`. */
678
- function bucketStartOf(tier, ts) {
679
- if (tier === "5m") return floorTo(ts, FIVE_MINUTES_MS);
680
- if (tier === "1h") return floorTo(ts, HOUR_MS);
681
- return startOfLocalDay(ts);
682
- }
683
- /** Exclusive end of the `tier` bucket that starts at `start`. */
684
- function bucketEndOf(tier, start) {
685
- if (tier === "5m") return start + FIVE_MINUTES_MS;
686
- if (tier === "1h") return start + HOUR_MS;
687
- return nextLocalDayStart(start);
688
- }
689
- /** Quiet time after a bucket closes before it is rolled up (late writers). */
690
- var ROLLUP_GRACE_MS = {
691
- "5m": 3e4,
692
- "1h": 5 * 6e4,
693
- "1d": 15 * 6e4
694
- };
695
- //#endregion
696
- //#region src/builtins/device-history/retention/departure-tracker.ts
697
- var DEPARTED_ABSENCE_MS = 7 * DAY_MS;
698
- var DepartureTracker = class {
699
- store;
700
- registry;
701
- logger;
702
- missing = /* @__PURE__ */ new Map();
703
- constructor(store, registry, logger) {
704
- this.store = store;
705
- this.registry = registry;
706
- this.logger = logger;
707
- }
708
- async load() {
709
- this.missing = await this.store.loadDepartures();
710
- }
711
- missingSince(deviceId) {
712
- return this.missing.get(deviceId);
713
- }
714
- /** Forget a device's clock — its series were removed because it was DELETED (D865). */
715
- async forget(deviceId) {
716
- await this.store.clearMissing([deviceId]);
717
- const next = new Map(this.missing);
718
- next.delete(deviceId);
719
- this.missing = next;
720
- }
721
- /** Feed one SUCCESSFUL listing. A failed read never reaches here. */
722
- async observe(listed, now) {
723
- const withSeries = new Set(this.registry.all().flatMap((s) => s.deviceId === null ? [] : [s.deviceId]));
724
- const back = [...this.missing.keys()].filter((id) => listed.has(id));
725
- const gone = [...withSeries].filter((id) => !listed.has(id) && !this.missing.has(id));
726
- try {
727
- await this.store.clearMissing(back);
728
- await this.store.markMissing(gone, now);
729
- } catch (err) {
730
- this.logger.warn("device-history: departure clock not written", { meta: { error: err instanceof Error ? err.message : String(err) } });
731
- return;
732
- }
733
- const next = new Map(this.missing);
734
- for (const id of back) next.delete(id);
735
- for (const id of gone) next.set(id, now);
736
- this.missing = next;
737
- }
738
- };
739
- //#endregion
740
- //#region src/builtins/device-history/retention/retention.ts
741
- var DEFAULT_RETENTION = {
742
- rawDays: 7,
743
- fiveMinuteDays: 30,
744
- hourDays: 365,
745
- dayDays: null
746
- };
747
- /** Cutoff per tier: rows strictly older are deleted. `null` = keep forever. */
748
- function retentionCutoffs(policy, now) {
749
- return {
750
- raw: now - policy.rawDays * DAY_MS,
751
- "5m": now - policy.fiveMinuteDays * DAY_MS,
752
- "1h": now - policy.hourDays * DAY_MS,
753
- "1d": policy.dayDays === null || policy.dayDays <= 0 ? null : now - policy.dayDays * DAY_MS
754
- };
755
- }
756
- var TIERS = [
757
- "raw",
758
- "5m",
759
- "1h",
760
- "1d"
761
- ];
762
- var RETENTION_STEP_MS = {
763
- raw: HOUR_MS,
764
- "5m": HOUR_MS,
765
- "1h": DAY_MS,
766
- "1d": DAY_MS
767
- };
768
- var MAX_PURGES_PER_RUN = 20;
769
- /** Width of one delete statement's time range, per tier. */
770
- var SLICE_MS = {
771
- raw: DAY_MS,
772
- "5m": DAY_MS,
773
- "1h": 30 * DAY_MS,
774
- "1d": 30 * DAY_MS
775
- };
776
- /** A bucket's start may precede the series' first point by up to a day. */
777
- var BUCKET_LEAD_MS = 2 * DAY_MS;
778
- /** The short tiers hold nothing older than this unless the operator configured more. */
779
- var SHORT_TIER_LOOKBACK_MS = 400 * DAY_MS;
780
- var yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
781
- var RetentionJob = class {
782
- deps;
783
- appliedUpTo = /* @__PURE__ */ new Map();
784
- running = null;
785
- constructor(deps) {
786
- this.deps = deps;
787
- }
788
- run(policy, now) {
789
- if (this.running !== null) return this.running;
790
- const run = this.doRun(policy, now).finally(() => {
791
- this.running = null;
792
- });
793
- this.running = run;
794
- return run;
795
- }
796
- async doRun(policy, now) {
797
- const { registry, counters, logger } = this.deps;
798
- const cutoffs = retentionCutoffs(policy, now);
799
- try {
800
- for (const tier of TIERS) {
801
- const cutoff = cutoffs[tier];
802
- if (cutoff === null) continue;
803
- for (const series of registry.all()) {
804
- if (series.firstTs - 864e5 >= cutoff) continue;
805
- if (tier === "raw" && registry.metric(series.key)?.ingest === "buckets") continue;
806
- const marker = `${tier}:${series.id}`;
807
- const applied = this.appliedUpTo.get(marker);
808
- if (applied !== void 0 && cutoff - applied < RETENTION_STEP_MS[tier]) continue;
809
- const lo = Math.max(0, applied === void 0 ? series.firstTs - BUCKET_LEAD_MS : applied - RETENTION_STEP_MS[tier]);
810
- counters.addDeleted(tier, await this.deleteSliced(tier, series.id, lo, cutoff - 1));
811
- this.appliedUpTo.set(marker, cutoff);
812
- }
813
- }
814
- await this.purgeDeparted(now);
815
- counters.retentionLastRunAt = now;
816
- } catch (err) {
817
- logger.warn("device-history: retention pass failed — retried at the next run", { meta: { error: err instanceof Error ? err.message : String(err) } });
818
- }
819
- }
820
- /** Delete `[lo, hiInclusive]` of one tier in time slices, yielding between them. */
821
- /** Drop the visit markers of a purged series. */
822
- forgetSeries(seriesId) {
823
- for (const tier of TIERS) this.appliedUpTo.delete(`${tier}:${seriesId}`);
824
- }
825
- async deleteSliced(tier, seriesId, lo, hiInclusive) {
826
- const yieldNow = this.deps.yieldNow ?? yieldToEventLoop;
827
- let deleted = 0;
828
- for (let from = lo; from <= hiInclusive; from += SLICE_MS[tier]) {
829
- const to = Math.min(from + SLICE_MS[tier] - 1, hiInclusive);
830
- deleted += await this.deps.store.deleteRange(tier, seriesId, from, to);
831
- await yieldNow();
832
- }
833
- return deleted;
834
- }
835
- /**
836
- * Tier by tier in slices, then the series row (and whatever the slices missed).
837
- * Answers the rows the slices deleted per tier. The caller removes the series
838
- * from the registry, which releases its per-series state.
839
- */
840
- async purgeSeries(series, now) {
841
- const deleted = {
842
- raw: 0,
843
- "5m": 0,
844
- "1h": 0,
845
- "1d": 0
846
- };
847
- for (const tier of TIERS) {
848
- const lo = tier === "raw" || tier === "5m" ? Math.max(series.firstTs - BUCKET_LEAD_MS, now - SHORT_TIER_LOOKBACK_MS) : series.firstTs - BUCKET_LEAD_MS;
849
- deleted[tier] = await this.deleteSliced(tier, series.id, Math.max(0, lo), now + DAY_MS);
850
- this.deps.counters.addDeleted(tier, deleted[tier]);
851
- }
852
- await this.deps.store.deleteSeries(series.id);
853
- return deleted;
854
- }
855
- /**
856
- * Delete every series of a DELETED device now (D865). Driven by a tombstone
857
- * through the `device-removal-hook`, never by a listing: the week-long
858
- * absence clock above remains the backstop for a device removed before
859
- * tombstones existed.
860
- */
861
- async purgeDevice(deviceId, now) {
862
- const { registry, counters } = this.deps;
863
- let purged = 0;
864
- for (const series of registry.all()) {
865
- if (series.deviceId !== deviceId) continue;
866
- await this.purgeSeries(series, now);
867
- registry.remove(series.id);
868
- counters.purgedSeries += 1;
869
- purged += 1;
870
- }
871
- return purged;
872
- }
873
- async purgeDeparted(now) {
874
- const { registry, departures, counters, logger } = this.deps;
875
- let purged = 0;
876
- for (const series of registry.all()) {
877
- if (purged >= MAX_PURGES_PER_RUN) break;
878
- if (series.deviceId === null) continue;
879
- const since = departures.missingSince(series.deviceId);
880
- if (since === void 0 || now - since < DEPARTED_ABSENCE_MS) continue;
881
- await this.purgeSeries(series, now);
882
- registry.remove(series.id);
883
- counters.purgedSeries += 1;
884
- purged += 1;
885
- logger.info("device-history: purged the series of an unregistered device", {
886
- tags: { deviceId: series.deviceId },
887
- meta: { key: series.key }
888
- });
889
- }
890
- }
891
- };
892
- //#endregion
893
- export { subjectIdOf as S, readUnit as _, FIVE_MINUTES_MS as a, SeriesRegistry as b, bucketEndOf as c, CAP_KEY_PREFIX as d, CaptureEngine as f, readPath as g, catalogMetrics as h, DAY_MS as i, bucketStartOf as l, capSeriesKey as m, RetentionJob as n, HOUR_MS as o, capItemSeriesKey as p, DepartureTracker as r, ROLLUP_GRACE_MS as s, DEFAULT_RETENTION as t, floorTo as u, DeviceDirectory as v, identityOf as x, isRealDeviceType as y };
649
+ export { catalogMetrics as a, DeviceDirectory as c, identityOf as d, subjectIdOf as f, capSeriesKey as i, isRealDeviceType as l, CaptureEngine as n, readPath as o, capItemSeriesKey as r, readUnit as s, CAP_KEY_PREFIX as t, SeriesRegistry as u };
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CYnRCUzN.js");
1
+ const require_dist = require("./dist-DFWnAzAY.js");
2
2
  //#region src/builtins/device-history/store/series-registry.ts
3
3
  function subjectIdOf(subject) {
4
4
  return subject.kind === "device" ? `d:${subject.deviceId}` : `n:${subject.nodeId}`;
@@ -646,250 +646,6 @@ var CaptureEngine = class {
646
646
  }
647
647
  };
648
648
  //#endregion
649
- //#region src/builtins/device-history/time/bucket-time.ts
650
- /**
651
- * Bucket arithmetic for the three rollup tiers (D850, plan §4/§5.5).
652
- *
653
- * 5m and 1h buckets are aligned to UTC; a 1d bucket starts at HUB-LOCAL
654
- * midnight, so a day is 23, 24 or 25 hours long across a DST change (operator
655
- * answer Q4). Pure: the zone is the process zone (`TZ`), nothing is read from
656
- * the environment here.
657
- */
658
- var FIVE_MINUTES_MS = 5 * 6e4;
659
- var HOUR_MS = 60 * 6e4;
660
- var DAY_MS = 24 * HOUR_MS;
661
- function floorTo(ts, widthMs) {
662
- return Math.floor(ts / widthMs) * widthMs;
663
- }
664
- /** Hub-local midnight at or before `ts`. */
665
- function startOfLocalDay(ts) {
666
- const d = new Date(ts);
667
- d.setHours(0, 0, 0, 0);
668
- return d.getTime();
669
- }
670
- /** The local midnight following the local midnight `dayStart`. */
671
- function nextLocalDayStart(dayStart) {
672
- const d = new Date(dayStart);
673
- d.setDate(d.getDate() + 1);
674
- d.setHours(0, 0, 0, 0);
675
- return d.getTime();
676
- }
677
- /** Start of the `tier` bucket containing `ts`. */
678
- function bucketStartOf(tier, ts) {
679
- if (tier === "5m") return floorTo(ts, FIVE_MINUTES_MS);
680
- if (tier === "1h") return floorTo(ts, HOUR_MS);
681
- return startOfLocalDay(ts);
682
- }
683
- /** Exclusive end of the `tier` bucket that starts at `start`. */
684
- function bucketEndOf(tier, start) {
685
- if (tier === "5m") return start + FIVE_MINUTES_MS;
686
- if (tier === "1h") return start + HOUR_MS;
687
- return nextLocalDayStart(start);
688
- }
689
- /** Quiet time after a bucket closes before it is rolled up (late writers). */
690
- var ROLLUP_GRACE_MS = {
691
- "5m": 3e4,
692
- "1h": 5 * 6e4,
693
- "1d": 15 * 6e4
694
- };
695
- //#endregion
696
- //#region src/builtins/device-history/retention/departure-tracker.ts
697
- var DEPARTED_ABSENCE_MS = 7 * DAY_MS;
698
- var DepartureTracker = class {
699
- store;
700
- registry;
701
- logger;
702
- missing = /* @__PURE__ */ new Map();
703
- constructor(store, registry, logger) {
704
- this.store = store;
705
- this.registry = registry;
706
- this.logger = logger;
707
- }
708
- async load() {
709
- this.missing = await this.store.loadDepartures();
710
- }
711
- missingSince(deviceId) {
712
- return this.missing.get(deviceId);
713
- }
714
- /** Forget a device's clock — its series were removed because it was DELETED (D865). */
715
- async forget(deviceId) {
716
- await this.store.clearMissing([deviceId]);
717
- const next = new Map(this.missing);
718
- next.delete(deviceId);
719
- this.missing = next;
720
- }
721
- /** Feed one SUCCESSFUL listing. A failed read never reaches here. */
722
- async observe(listed, now) {
723
- const withSeries = new Set(this.registry.all().flatMap((s) => s.deviceId === null ? [] : [s.deviceId]));
724
- const back = [...this.missing.keys()].filter((id) => listed.has(id));
725
- const gone = [...withSeries].filter((id) => !listed.has(id) && !this.missing.has(id));
726
- try {
727
- await this.store.clearMissing(back);
728
- await this.store.markMissing(gone, now);
729
- } catch (err) {
730
- this.logger.warn("device-history: departure clock not written", { meta: { error: err instanceof Error ? err.message : String(err) } });
731
- return;
732
- }
733
- const next = new Map(this.missing);
734
- for (const id of back) next.delete(id);
735
- for (const id of gone) next.set(id, now);
736
- this.missing = next;
737
- }
738
- };
739
- //#endregion
740
- //#region src/builtins/device-history/retention/retention.ts
741
- var DEFAULT_RETENTION = {
742
- rawDays: 7,
743
- fiveMinuteDays: 30,
744
- hourDays: 365,
745
- dayDays: null
746
- };
747
- /** Cutoff per tier: rows strictly older are deleted. `null` = keep forever. */
748
- function retentionCutoffs(policy, now) {
749
- return {
750
- raw: now - policy.rawDays * DAY_MS,
751
- "5m": now - policy.fiveMinuteDays * DAY_MS,
752
- "1h": now - policy.hourDays * DAY_MS,
753
- "1d": policy.dayDays === null || policy.dayDays <= 0 ? null : now - policy.dayDays * DAY_MS
754
- };
755
- }
756
- var TIERS = [
757
- "raw",
758
- "5m",
759
- "1h",
760
- "1d"
761
- ];
762
- var RETENTION_STEP_MS = {
763
- raw: HOUR_MS,
764
- "5m": HOUR_MS,
765
- "1h": DAY_MS,
766
- "1d": DAY_MS
767
- };
768
- var MAX_PURGES_PER_RUN = 20;
769
- /** Width of one delete statement's time range, per tier. */
770
- var SLICE_MS = {
771
- raw: DAY_MS,
772
- "5m": DAY_MS,
773
- "1h": 30 * DAY_MS,
774
- "1d": 30 * DAY_MS
775
- };
776
- /** A bucket's start may precede the series' first point by up to a day. */
777
- var BUCKET_LEAD_MS = 2 * DAY_MS;
778
- /** The short tiers hold nothing older than this unless the operator configured more. */
779
- var SHORT_TIER_LOOKBACK_MS = 400 * DAY_MS;
780
- var yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
781
- var RetentionJob = class {
782
- deps;
783
- appliedUpTo = /* @__PURE__ */ new Map();
784
- running = null;
785
- constructor(deps) {
786
- this.deps = deps;
787
- }
788
- run(policy, now) {
789
- if (this.running !== null) return this.running;
790
- const run = this.doRun(policy, now).finally(() => {
791
- this.running = null;
792
- });
793
- this.running = run;
794
- return run;
795
- }
796
- async doRun(policy, now) {
797
- const { registry, counters, logger } = this.deps;
798
- const cutoffs = retentionCutoffs(policy, now);
799
- try {
800
- for (const tier of TIERS) {
801
- const cutoff = cutoffs[tier];
802
- if (cutoff === null) continue;
803
- for (const series of registry.all()) {
804
- if (series.firstTs - 864e5 >= cutoff) continue;
805
- if (tier === "raw" && registry.metric(series.key)?.ingest === "buckets") continue;
806
- const marker = `${tier}:${series.id}`;
807
- const applied = this.appliedUpTo.get(marker);
808
- if (applied !== void 0 && cutoff - applied < RETENTION_STEP_MS[tier]) continue;
809
- const lo = Math.max(0, applied === void 0 ? series.firstTs - BUCKET_LEAD_MS : applied - RETENTION_STEP_MS[tier]);
810
- counters.addDeleted(tier, await this.deleteSliced(tier, series.id, lo, cutoff - 1));
811
- this.appliedUpTo.set(marker, cutoff);
812
- }
813
- }
814
- await this.purgeDeparted(now);
815
- counters.retentionLastRunAt = now;
816
- } catch (err) {
817
- logger.warn("device-history: retention pass failed — retried at the next run", { meta: { error: err instanceof Error ? err.message : String(err) } });
818
- }
819
- }
820
- /** Delete `[lo, hiInclusive]` of one tier in time slices, yielding between them. */
821
- /** Drop the visit markers of a purged series. */
822
- forgetSeries(seriesId) {
823
- for (const tier of TIERS) this.appliedUpTo.delete(`${tier}:${seriesId}`);
824
- }
825
- async deleteSliced(tier, seriesId, lo, hiInclusive) {
826
- const yieldNow = this.deps.yieldNow ?? yieldToEventLoop;
827
- let deleted = 0;
828
- for (let from = lo; from <= hiInclusive; from += SLICE_MS[tier]) {
829
- const to = Math.min(from + SLICE_MS[tier] - 1, hiInclusive);
830
- deleted += await this.deps.store.deleteRange(tier, seriesId, from, to);
831
- await yieldNow();
832
- }
833
- return deleted;
834
- }
835
- /**
836
- * Tier by tier in slices, then the series row (and whatever the slices missed).
837
- * Answers the rows the slices deleted per tier. The caller removes the series
838
- * from the registry, which releases its per-series state.
839
- */
840
- async purgeSeries(series, now) {
841
- const deleted = {
842
- raw: 0,
843
- "5m": 0,
844
- "1h": 0,
845
- "1d": 0
846
- };
847
- for (const tier of TIERS) {
848
- const lo = tier === "raw" || tier === "5m" ? Math.max(series.firstTs - BUCKET_LEAD_MS, now - SHORT_TIER_LOOKBACK_MS) : series.firstTs - BUCKET_LEAD_MS;
849
- deleted[tier] = await this.deleteSliced(tier, series.id, Math.max(0, lo), now + DAY_MS);
850
- this.deps.counters.addDeleted(tier, deleted[tier]);
851
- }
852
- await this.deps.store.deleteSeries(series.id);
853
- return deleted;
854
- }
855
- /**
856
- * Delete every series of a DELETED device now (D865). Driven by a tombstone
857
- * through the `device-removal-hook`, never by a listing: the week-long
858
- * absence clock above remains the backstop for a device removed before
859
- * tombstones existed.
860
- */
861
- async purgeDevice(deviceId, now) {
862
- const { registry, counters } = this.deps;
863
- let purged = 0;
864
- for (const series of registry.all()) {
865
- if (series.deviceId !== deviceId) continue;
866
- await this.purgeSeries(series, now);
867
- registry.remove(series.id);
868
- counters.purgedSeries += 1;
869
- purged += 1;
870
- }
871
- return purged;
872
- }
873
- async purgeDeparted(now) {
874
- const { registry, departures, counters, logger } = this.deps;
875
- let purged = 0;
876
- for (const series of registry.all()) {
877
- if (purged >= MAX_PURGES_PER_RUN) break;
878
- if (series.deviceId === null) continue;
879
- const since = departures.missingSince(series.deviceId);
880
- if (since === void 0 || now - since < DEPARTED_ABSENCE_MS) continue;
881
- await this.purgeSeries(series, now);
882
- registry.remove(series.id);
883
- counters.purgedSeries += 1;
884
- purged += 1;
885
- logger.info("device-history: purged the series of an unregistered device", {
886
- tags: { deviceId: series.deviceId },
887
- meta: { key: series.key }
888
- });
889
- }
890
- }
891
- };
892
- //#endregion
893
649
  Object.defineProperty(exports, "CAP_KEY_PREFIX", {
894
650
  enumerable: true,
895
651
  get: function() {
@@ -902,72 +658,18 @@ Object.defineProperty(exports, "CaptureEngine", {
902
658
  return CaptureEngine;
903
659
  }
904
660
  });
905
- Object.defineProperty(exports, "DAY_MS", {
906
- enumerable: true,
907
- get: function() {
908
- return DAY_MS;
909
- }
910
- });
911
- Object.defineProperty(exports, "DEFAULT_RETENTION", {
912
- enumerable: true,
913
- get: function() {
914
- return DEFAULT_RETENTION;
915
- }
916
- });
917
- Object.defineProperty(exports, "DepartureTracker", {
918
- enumerable: true,
919
- get: function() {
920
- return DepartureTracker;
921
- }
922
- });
923
661
  Object.defineProperty(exports, "DeviceDirectory", {
924
662
  enumerable: true,
925
663
  get: function() {
926
664
  return DeviceDirectory;
927
665
  }
928
666
  });
929
- Object.defineProperty(exports, "FIVE_MINUTES_MS", {
930
- enumerable: true,
931
- get: function() {
932
- return FIVE_MINUTES_MS;
933
- }
934
- });
935
- Object.defineProperty(exports, "HOUR_MS", {
936
- enumerable: true,
937
- get: function() {
938
- return HOUR_MS;
939
- }
940
- });
941
- Object.defineProperty(exports, "ROLLUP_GRACE_MS", {
942
- enumerable: true,
943
- get: function() {
944
- return ROLLUP_GRACE_MS;
945
- }
946
- });
947
- Object.defineProperty(exports, "RetentionJob", {
948
- enumerable: true,
949
- get: function() {
950
- return RetentionJob;
951
- }
952
- });
953
667
  Object.defineProperty(exports, "SeriesRegistry", {
954
668
  enumerable: true,
955
669
  get: function() {
956
670
  return SeriesRegistry;
957
671
  }
958
672
  });
959
- Object.defineProperty(exports, "bucketEndOf", {
960
- enumerable: true,
961
- get: function() {
962
- return bucketEndOf;
963
- }
964
- });
965
- Object.defineProperty(exports, "bucketStartOf", {
966
- enumerable: true,
967
- get: function() {
968
- return bucketStartOf;
969
- }
970
- });
971
673
  Object.defineProperty(exports, "capItemSeriesKey", {
972
674
  enumerable: true,
973
675
  get: function() {
@@ -986,12 +688,6 @@ Object.defineProperty(exports, "catalogMetrics", {
986
688
  return catalogMetrics;
987
689
  }
988
690
  });
989
- Object.defineProperty(exports, "floorTo", {
990
- enumerable: true,
991
- get: function() {
992
- return floorTo;
993
- }
994
- });
995
691
  Object.defineProperty(exports, "identityOf", {
996
692
  enumerable: true,
997
693
  get: function() {
@@ -1,4 +1,4 @@
1
- const require_dist = require("./dist-CYnRCUzN.js");
1
+ const require_dist = require("./dist-DFWnAzAY.js");
2
2
  //#region src/builtins/shared/device-state-changed.ts
3
3
  /** Structural narrowing helper for untrusted bus payloads. */
4
4
  function isRecord(value) {
@@ -1,4 +1,4 @@
1
- import { oc as errMsg, ro as compositionSourceKey } from "./dist-Iq3vrBOE.mjs";
1
+ import { oo as compositionSourceKey, uc as errMsg } from "./dist-C5eIFTMo.mjs";
2
2
  //#region src/builtins/shared/device-state-changed.ts
3
3
  /** Structural narrowing helper for untrusted bus payloads. */
4
4
  function isRecord(value) {
@@ -1,4 +1,4 @@
1
- import { as as buildSecretRef } from "./dist-Iq3vrBOE.mjs";
1
+ import { ls as buildSecretRef } from "./dist-C5eIFTMo.mjs";
2
2
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
3
3
  var MESH_CA_KEY_REF = buildSecretRef({
4
4
  owner: "system",
@@ -1,5 +1,5 @@
1
1
  /** `secret://system/global/meshCaKey` — EC P-256 PKCS#8 PEM of the hub mesh CA. */
2
- var MESH_CA_KEY_REF = require("./dist-CYnRCUzN.js").buildSecretRef({
2
+ var MESH_CA_KEY_REF = require("./dist-DFWnAzAY.js").buildSecretRef({
3
3
  owner: "system",
4
4
  scope: { kind: "global" },
5
5
  fieldPath: "meshCaKey"
@@ -1,5 +1,5 @@
1
1
  import { EDGETPU_LIB_ENV, chooseEdgetpuDelegate, nodeDataRootFromEnv } from "@camstack/types/node";
2
- import fs from "node:fs";
2
+ import Kt from "node:fs";
3
3
  //#region src/builtins/platform-probe/coral-accelerators.ts
4
4
  /**
5
5
  * Coral USB Edge TPU USB identifiers.
@@ -185,21 +185,21 @@ function detectCoralAccelerator(fsx, delegateHost = currentDelegateHost()) {
185
185
  }
186
186
  function safeListOrNull(dir) {
187
187
  try {
188
- return fs.readdirSync(dir);
188
+ return Kt.readdirSync(dir);
189
189
  } catch {
190
190
  return null;
191
191
  }
192
192
  }
193
193
  function safeList(dir) {
194
194
  try {
195
- return fs.readdirSync(dir);
195
+ return Kt.readdirSync(dir);
196
196
  } catch {
197
197
  return [];
198
198
  }
199
199
  }
200
200
  function safeRead(path) {
201
201
  try {
202
- return fs.readFileSync(path, "utf8").trim();
202
+ return Kt.readFileSync(path, "utf8").trim();
203
203
  } catch {
204
204
  return "";
205
205
  }
@@ -213,7 +213,7 @@ var nodeCoralFs = {
213
213
  listApexClass: () => safeList("/sys/class/apex"),
214
214
  canOpen: (path) => {
215
215
  try {
216
- fs.accessSync(path, fs.constants.R_OK | fs.constants.W_OK);
216
+ Kt.accessSync(path, Kt.constants.R_OK | Kt.constants.W_OK);
217
217
  return true;
218
218
  } catch {
219
219
  return false;
@@ -221,7 +221,7 @@ var nodeCoralFs = {
221
221
  },
222
222
  exists: (path) => {
223
223
  try {
224
- return fs.existsSync(path);
224
+ return Kt.existsSync(path);
225
225
  } catch {
226
226
  return false;
227
227
  }