@camstack/server 1.2.943 → 1.2.944
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/closure-pins.json +350 -0
- package/dist/api/core/auth-sessions.procedures.js +18 -0
- package/dist/api/core/auth.router.js +19 -6
- package/dist/api/server-upload.js +17 -1
- package/dist/api/trpc/generated-cap-routers.js +83 -0
- package/dist/auth/native-return.js +9 -3
- package/dist/auth/sso-routes.js +5 -1
- package/dist/core/addon/instance-lifecycle.js +4 -1
- package/dist/core/auth/handoff-code.service.js +35 -1
- package/dist/server-root/index.js +313 -70
- package/package.json +21 -11
- package/system/dist/{action-index-B1fgpQBt.mjs → action-index-DpYmsOKh.mjs} +1 -1
- package/system/dist/{action-index-B_cLRwXJ.js → action-index-Dz9rd1qa.js} +1 -1
- package/system/dist/{addon-settings.cap-CZ4MC7ha.mjs → addon-settings.cap-CHpmuaQG.mjs} +1 -1
- package/system/dist/{addon-settings.cap-DrLdMFIe.js → addon-settings.cap-nZVHPo3X.js} +1 -1
- package/system/dist/{alert-episode-Be--PngO.mjs → alert-episode-D-1VUUkZ.mjs} +1 -1
- package/system/dist/{alert-episode-Bqktmt-i.js → alert-episode-DaQ3prSe.js} +1 -1
- package/system/dist/{base-addon-CRsXtYFG.js → base-addon-BG7p06Hb.js} +136 -15
- package/system/dist/{base-addon-BcS6r1cT.mjs → base-addon-BcVoYZbC.mjs} +136 -15
- package/system/dist/{base-device-DAdWzDOl.js → base-device-DeSNiwZ4.js} +4 -4
- package/system/dist/{base-device-DJXF5eDN.mjs → base-device-w_MD0Bf4.mjs} +4 -4
- 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/alerts.addon.js +3 -3
- package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- 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 +3 -3
- package/system/dist/builtins/camera-grid/index.mjs +3 -3
- package/system/dist/builtins/composer/composer.addon.js +7 -7
- package/system/dist/builtins/composer/composer.addon.mjs +7 -7
- 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/actions-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/block-supervisor.d.ts +16 -4
- package/system/dist/builtins/core-blocks/core-block-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +1018 -323
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +986 -291
- package/system/dist/builtins/core-blocks/migrations/index.d.ts +5 -2
- package/system/dist/builtins/core-blocks/migrations/tag-ids.d.ts +42 -0
- package/system/dist/builtins/core-blocks/migrations/tags-as-records.d.ts +47 -0
- package/system/dist/builtins/core-blocks/record-kinds.d.ts +12 -1
- package/system/dist/builtins/core-blocks/runs-api.d.ts +3 -1
- package/system/dist/builtins/core-blocks/runs-ledger.d.ts +3 -1
- package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/tags-service.d.ts +52 -27
- package/system/dist/builtins/core-blocks/tags-wiring.d.ts +2 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +76 -67
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +76 -67
- package/system/dist/builtins/device-history/device-history.addon.js +4 -4
- package/system/dist/builtins/device-history/device-history.addon.mjs +4 -4
- package/system/dist/builtins/device-manager/device-manager.addon.js +1602 -760
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +1588 -746
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +13 -136
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-provider-context.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-row-store.d.ts +21 -4
- package/system/dist/builtins/device-manager/device-search.d.ts +6 -0
- package/system/dist/builtins/device-manager/location-alignment.d.ts +9 -2
- package/system/dist/builtins/device-manager/migrate-device.d.ts +7 -2
- package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +132 -1
- package/system/dist/builtins/device-manager/migrations/device-tag-ids.d.ts +25 -0
- package/system/dist/builtins/device-manager/migrations/index.d.ts +16 -0
- package/system/dist/builtins/device-manager/migrations/orphan-children.d.ts +33 -0
- package/system/dist/builtins/device-manager/migrations/ports.d.ts +17 -0
- package/system/dist/builtins/device-manager/migrations/rooms-as-records.d.ts +52 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +3 -1
- package/system/dist/builtins/device-manager/removal-cleanup.d.ts +7 -0
- package/system/dist/builtins/device-manager/room-actions.d.ts +27 -0
- package/system/dist/builtins/device-manager/room-store.d.ts +19 -0
- package/system/dist/builtins/device-manager/tag-names.d.ts +32 -0
- package/system/dist/builtins/device-manager/wireable-enum-catalog.d.ts +18 -0
- 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 +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +2 -2
- package/system/dist/builtins/loki-logging/index.mjs +2 -2
- 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 +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- 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/migrations/migration-engine.d.ts +3 -1
- package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +15 -10
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +15 -10
- 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 +2 -2
- package/system/dist/builtins/winston-logging/index.mjs +2 -2
- package/system/dist/{command-catalog-C29hVOOg.js → command-catalog-CI0tu1Nt.js} +1 -1
- package/system/dist/{command-catalog-xAeqxbZk.mjs → command-catalog-zwlIA3T5.mjs} +1 -1
- package/system/dist/{composition-sources-C327LGFn.mjs → composition-sources-CXxXfh1z.mjs} +1 -1
- package/system/dist/{composition-sources-Do5qM6EB.js → composition-sources-DNgSItK-.js} +1 -1
- package/system/dist/{core-blocks.cap-CdTGUKtr.js → core-blocks.cap-BHEok4VO.js} +125 -373
- package/system/dist/{core-blocks.cap-DLkEfV5b.mjs → core-blocks.cap-CPgZRcpj.mjs} +109 -327
- package/system/dist/{device-manager.cap-DJs8izI6.js → device-manager.cap-B9qVf7ag.js} +163 -22
- package/system/dist/{device-manager.cap-eYrj1Ezp.mjs → device-manager.cap-CV4KGp3e.mjs} +134 -17
- package/system/dist/{error.cap-CU1FB6uE.mjs → error.cap-B8l7L8e4.mjs} +7 -1
- package/system/dist/{error.cap-BuKbL3Ac.js → error.cap-BqlvgBJd.js} +7 -1
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/index.js +7 -7
- package/system/dist/index.mjs +6 -6
- package/system/dist/{legacy-integration-rows-door-CdqYAj-o.js → legacy-integration-rows-door-BK8eoGlF.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-LSgpClpX.mjs → legacy-integration-rows-door-CwzC5XNk.mjs} +1 -1
- package/system/dist/{migration-DGAc6ywR.mjs → migration-BvbfW9g-.mjs} +6 -0
- package/system/dist/{migration-BOQlFZCN.js → migration-CHPdAdNh.js} +6 -0
- package/system/dist/{prefix-walk-BFnw8NBu.js → named-entity-store-DFwLij9c.js} +244 -90
- package/system/dist/{prefix-walk-Mtij0NNT.mjs → named-entity-store-DOnyyFFf.mjs} +195 -89
- package/system/dist/{notification-rules.cap-BUIuYPlQ.mjs → notification-rules.cap-ClvK6QT1.mjs} +10 -5
- package/system/dist/{notification-rules.cap-BJKUjizS.js → notification-rules.cap-uSLoe2pA.js} +10 -5
- package/system/dist/{notification-targets-DMW7xgR2.js → notification-targets-ChqpBbtR.js} +2 -2
- package/system/dist/{notification-targets-4bGYH5J7.mjs → notification-targets-DUA6-F2t.mjs} +2 -2
- package/system/dist/{device-row-store-CTocYKqC.mjs → record-kinds-BD2xv4Pd.mjs} +222 -93
- package/system/dist/{device-row-store-C0P2H18h.js → record-kinds-BV8Gcpsx.js} +246 -93
- package/system/dist/records/named-entity-store.d.ts +60 -0
- package/system/dist/{rename-composition-block-Cdh-dRmY.mjs → rename-composition-block-C3QQ9UUE.mjs} +134 -33
- package/system/dist/{rename-composition-block-D9Uc1AF7.js → rename-composition-block-Cx3X8QSm.js} +134 -33
- package/system/dist/{retention-source.cap-C6Hy0hlM.js → retention-source.cap-A-TMhU5O.js} +1 -1
- package/system/dist/{retention-source.cap-550kkyp5.mjs → retention-source.cap-Ct07pM30.mjs} +1 -1
- package/system/dist/{storage-admin.cap-Ci4QbL6P.mjs → storage-admin.cap-C54s9_B9.mjs} +8 -2
- package/system/dist/{storage-admin.cap-DqW1ol4j.js → storage-admin.cap-DSPHi7ut.js} +8 -2
- package/system/dist/{stream-catalog.cap-CjEQFknc.js → stream-catalog.cap-7WPsugOy.js} +1 -1
- package/system/dist/{stream-catalog.cap-DVniDdRD.mjs → stream-catalog.cap-CzwRDaqT.mjs} +1 -1
- package/system/dist/{tag-BxLazvVb.js → tag-BLraBqvp.js} +12 -0
- package/system/dist/{tag-uZBAq6ox.mjs → tag-DU8pm9Bi.mjs} +7 -1
- package/system/dist/time-window-B6UhCArd.js +679 -0
- package/system/dist/time-window-BnUBULgu.mjs +578 -0
- package/system/dist/{wal-maintenance-BgYiAy5b.js → wal-maintenance-CkPfVApC.js} +0 -0
- package/system/dist/{wal-maintenance-Bey5ChBb.mjs → wal-maintenance-u84_1sVl.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -1,93 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ft as forEachLeaf, Ht as faultMatches, Lt as isEventLeaf, Pt as eventLeafIdAt, Rt as compareValues, Ut as readFault, Vt as describeWantedFaults, Wt as anySubjectMatches, qt as isQuantityValue, zt as describeHoldMs } from "./core-blocks.cap-CPgZRcpj.mjs";
|
|
2
2
|
import { lt as toExpressionValue, st as evaluateExpressionSource } from "./compile-OBMHlqD-.mjs";
|
|
3
|
+
import { a as judgeTimeWindow } from "./time-window-BnUBULgu.mjs";
|
|
4
|
+
import { t as require_read_all_rows } from "./read-all-rows-TaPqdWNF.mjs";
|
|
3
5
|
import { t as prefixRange } from "./prefix-range-Dl0znowN.mjs";
|
|
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 (!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(weekdayOfLocalDate(startDate))) return null;
|
|
39
|
-
if (window.between === void 0) {
|
|
40
|
-
const start = occurrenceOn(MIDNIGHT, startDate, site);
|
|
41
|
-
const end = occurrenceOn(MIDNIGHT, addDays(startDate, 1), site);
|
|
42
|
-
return start === null || end === null ? null : {
|
|
43
|
-
start,
|
|
44
|
-
end
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const start = occurrenceOn(window.between.from, startDate, site);
|
|
48
|
-
const sameDayEnd = 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 = 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 = 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 = 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
6
|
//#region ../types/dist/esm/automation/condition-eval.mjs
|
|
92
7
|
/**
|
|
93
8
|
* Evaluating an automation's condition tree against the ConditionMirror.
|
|
@@ -701,6 +616,40 @@ function hasHoldLeaves(when) {
|
|
|
701
616
|
return found;
|
|
702
617
|
}
|
|
703
618
|
//#endregion
|
|
619
|
+
//#region ../types/dist/esm/entities/entity-id.mjs
|
|
620
|
+
/** The fold every entity name compares by: trimmed, lower-cased. */
|
|
621
|
+
function entityNameKey(name) {
|
|
622
|
+
return name.trim().toLowerCase();
|
|
623
|
+
}
|
|
624
|
+
/** cyrb53 — a small, well-mixed 53-bit string hash. */
|
|
625
|
+
function mix53(text, seed) {
|
|
626
|
+
let h1 = 3735928559 ^ seed;
|
|
627
|
+
let h2 = 1103547991 ^ seed;
|
|
628
|
+
for (let i = 0; i < text.length; i++) {
|
|
629
|
+
const ch = text.charCodeAt(i);
|
|
630
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
631
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
632
|
+
}
|
|
633
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
634
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
635
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
636
|
+
}
|
|
637
|
+
function hex14(n) {
|
|
638
|
+
return n.toString(16).padStart(14, "0");
|
|
639
|
+
}
|
|
640
|
+
/** The id a migration mints for `kind` from the entity's folded `key`. Pure. */
|
|
641
|
+
function entityIdFromKey(kind, key) {
|
|
642
|
+
const folded = `${kind}:${entityNameKey(key)}`;
|
|
643
|
+
return `${kind}_${hex14(mix53(folded, 1))}${hex14(mix53(folded, 2))}`;
|
|
644
|
+
}
|
|
645
|
+
var roomIdFromKey = (key) => entityIdFromKey("room", key);
|
|
646
|
+
var tagIdFromKey = (key) => entityIdFromKey("tag", key);
|
|
647
|
+
var zoneIdFromKey = (key) => entityIdFromKey("zone", key);
|
|
648
|
+
/** A fresh random id for an entity created after the migrations. */
|
|
649
|
+
function newEntityId(kind) {
|
|
650
|
+
return `${kind}_${globalThis.crypto.randomUUID().replaceAll("-", "")}`;
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
704
653
|
//#region src/kernel/prefix-walk.ts
|
|
705
654
|
function isRecord(value) {
|
|
706
655
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -787,4 +736,161 @@ async function loadPrefixed(door, collection, prefix, decode = unwrapStoredValue
|
|
|
787
736
|
}
|
|
788
737
|
}
|
|
789
738
|
//#endregion
|
|
790
|
-
|
|
739
|
+
//#region src/builtins/device-manager/write-lock.ts
|
|
740
|
+
function createWriteLock() {
|
|
741
|
+
let chain = Promise.resolve();
|
|
742
|
+
return async (fn) => {
|
|
743
|
+
const previous = chain;
|
|
744
|
+
let release = () => {};
|
|
745
|
+
chain = new Promise((resolve) => {
|
|
746
|
+
release = resolve;
|
|
747
|
+
});
|
|
748
|
+
try {
|
|
749
|
+
await previous.catch(() => {});
|
|
750
|
+
return await fn();
|
|
751
|
+
} finally {
|
|
752
|
+
release();
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
//#endregion
|
|
757
|
+
//#region src/records/named-entity-store.ts
|
|
758
|
+
/**
|
|
759
|
+
* A set of named entities held as records with an id (D1089): a room, a site
|
|
760
|
+
* zone, a tag.
|
|
761
|
+
*
|
|
762
|
+
* The store reads every record once (few, hand-made) and keeps the working copy
|
|
763
|
+
* here; a write goes to the record first and lands in the map only when it
|
|
764
|
+
* succeeded. ONE operation is ONE `put` of ONE record — a rename never touches
|
|
765
|
+
* a record that merely references the entity.
|
|
766
|
+
*
|
|
767
|
+
* A name is unique within the store, compared by `entityNameKey`. `ensure` of a
|
|
768
|
+
* name that exists returns the existing entity, so "type a new name in the
|
|
769
|
+
* picker" is one call. A reference whose id is unknown reads as `null`
|
|
770
|
+
* ({@link nameOf}): a reader never throws on it and never shows the raw id.
|
|
771
|
+
*/
|
|
772
|
+
var import_read_all_rows = require_read_all_rows();
|
|
773
|
+
/** Refused: the name belongs to another entity of the same kind. */
|
|
774
|
+
var EntityNameTakenError = class extends Error {
|
|
775
|
+
entityKind;
|
|
776
|
+
name;
|
|
777
|
+
constructor(entityKind, name) {
|
|
778
|
+
super(`[${entityKind}] name already taken: ${name}`);
|
|
779
|
+
this.entityKind = entityKind;
|
|
780
|
+
this.name = name;
|
|
781
|
+
this.name = "EntityNameTakenError";
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
/** Refused: no entity has this id. */
|
|
785
|
+
var EntityNotFoundError = class extends Error {
|
|
786
|
+
entityKind;
|
|
787
|
+
id;
|
|
788
|
+
constructor(entityKind, id) {
|
|
789
|
+
super(`[${entityKind}] not found: ${id}`);
|
|
790
|
+
this.entityKind = entityKind;
|
|
791
|
+
this.id = id;
|
|
792
|
+
this.name = "EntityNotFoundError";
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
var NamedEntityStore = class {
|
|
796
|
+
entityKind;
|
|
797
|
+
kind;
|
|
798
|
+
validate;
|
|
799
|
+
entities = /* @__PURE__ */ new Map();
|
|
800
|
+
lock = createWriteLock();
|
|
801
|
+
constructor(entityKind, kind, validate) {
|
|
802
|
+
this.entityKind = entityKind;
|
|
803
|
+
this.kind = kind;
|
|
804
|
+
this.validate = validate;
|
|
805
|
+
}
|
|
806
|
+
async load() {
|
|
807
|
+
const rows = await (0, import_read_all_rows.readAllRows)(this.kind);
|
|
808
|
+
this.entities = new Map(rows.map((row) => [row.id, {
|
|
809
|
+
...row.data,
|
|
810
|
+
id: row.id
|
|
811
|
+
}]));
|
|
812
|
+
}
|
|
813
|
+
/** The name of entity `id`, or `null` when unset or unknown. Never the id. */
|
|
814
|
+
nameOf(id) {
|
|
815
|
+
if (id === null || id === void 0) return null;
|
|
816
|
+
return this.entities.get(id)?.name ?? null;
|
|
817
|
+
}
|
|
818
|
+
get(id) {
|
|
819
|
+
return this.entities.get(id) ?? null;
|
|
820
|
+
}
|
|
821
|
+
/** The entity named `name` (trimmed, case-insensitive), or `null`. */
|
|
822
|
+
findByName(name) {
|
|
823
|
+
const key = entityNameKey(name);
|
|
824
|
+
for (const entity of this.entities.values()) if (entityNameKey(entity.name) === key) return entity;
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
list() {
|
|
828
|
+
return [...this.entities.values()].toSorted((a, b) => {
|
|
829
|
+
const ao = orderOf(a);
|
|
830
|
+
const bo = orderOf(b);
|
|
831
|
+
if (ao !== bo) return ao - bo;
|
|
832
|
+
return a.name.localeCompare(b.name, void 0, { sensitivity: "base" });
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Create the entity named `name`, or return the one that has it. `preferredId` is the id a
|
|
837
|
+
* migration already wrote into referencing rows: it is adopted when no entity holds it (a record
|
|
838
|
+
* that arrives late never orphans a migrated id), else a fresh id is minted.
|
|
839
|
+
*/
|
|
840
|
+
async ensure(name, extra, preferredId) {
|
|
841
|
+
return this.lock(async () => {
|
|
842
|
+
const existing = this.findByName(name);
|
|
843
|
+
if (existing !== null) return existing;
|
|
844
|
+
const body = this.validate({
|
|
845
|
+
...extra,
|
|
846
|
+
name: name.trim()
|
|
847
|
+
});
|
|
848
|
+
const id = preferredId !== void 0 && !this.entities.has(preferredId) ? preferredId : newEntityId(this.entityKind);
|
|
849
|
+
await this.kind.put({
|
|
850
|
+
id,
|
|
851
|
+
data: body
|
|
852
|
+
});
|
|
853
|
+
const created = {
|
|
854
|
+
...body,
|
|
855
|
+
id
|
|
856
|
+
};
|
|
857
|
+
this.entities.set(id, created);
|
|
858
|
+
return created;
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
/** Replace the body of `id` with `next(current)`: ONE put. */
|
|
862
|
+
async update(id, next) {
|
|
863
|
+
return this.lock(async () => {
|
|
864
|
+
const current = this.entities.get(id);
|
|
865
|
+
if (current === void 0) throw new EntityNotFoundError(this.entityKind, id);
|
|
866
|
+
const { id: _id, ...currentBody } = current;
|
|
867
|
+
const body = this.validate(next(this.validate(currentBody)));
|
|
868
|
+
const holder = this.findByName(body.name);
|
|
869
|
+
if (holder !== null && holder.id !== id) throw new EntityNameTakenError(this.entityKind, body.name);
|
|
870
|
+
await this.kind.put({
|
|
871
|
+
id,
|
|
872
|
+
data: body
|
|
873
|
+
});
|
|
874
|
+
const updated = {
|
|
875
|
+
...body,
|
|
876
|
+
id
|
|
877
|
+
};
|
|
878
|
+
this.entities.set(id, updated);
|
|
879
|
+
return updated;
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
/** Remove the record. Returns whether it existed. The caller clears references. */
|
|
883
|
+
async delete(id) {
|
|
884
|
+
return this.lock(async () => {
|
|
885
|
+
if (!this.entities.has(id)) return false;
|
|
886
|
+
await this.kind.delete(id);
|
|
887
|
+
this.entities.delete(id);
|
|
888
|
+
return true;
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
function orderOf(entity) {
|
|
893
|
+
return entity.order ?? Number.MAX_SAFE_INTEGER;
|
|
894
|
+
}
|
|
895
|
+
//#endregion
|
|
896
|
+
export { stableIdMapOf as _, loadPrefixed as a, roomIdFromKey as c, ConditionMirror as d, collectWhenMirrorSources as f, nextTimeBoundaryInMs as g, hasTimeLeaves as h, createWriteLock as i, tagIdFromKey as l, hasHoldLeaves as m, EntityNotFoundError as n, unwrapStoredValue as o, evaluateWhenTree as p, NamedEntityStore as r, entityNameKey as s, EntityNameTakenError as t, zoneIdFromKey as u };
|
package/system/dist/{notification-rules.cap-BUIuYPlQ.mjs → notification-rules.cap-ClvK6QT1.mjs}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { r as CamProfileSchema } from "./streaming-shared-B8cXatuU.mjs";
|
|
2
2
|
import { c as method } from "./capability-definition-C1TLUVJR.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as TagsFieldSchema, n as TagIdsFieldSchema } from "./tag-DU8pm9Bi.mjs";
|
|
4
4
|
import { r as DeviceType } from "./device-type-TUGqGmaI.mjs";
|
|
5
5
|
import { t } from "./l10n-Bu6aUvSY.mjs";
|
|
6
|
-
import { t as DeviceErrorSeveritySchema } from "./error.cap-
|
|
6
|
+
import { t as DeviceErrorSeveritySchema } from "./error.cap-B8l7L8e4.mjs";
|
|
7
7
|
import { r as MaskPolygonShapeSchema } from "./mask-shape-Ci8Co9w0.mjs";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
//#region ../types/dist/esm/capabilities/notification-output.cap.mjs
|
|
@@ -2091,7 +2091,9 @@ var NcRuleInputSchema = /* @__PURE__ */ z.object({
|
|
|
2091
2091
|
* Renamed or removed fleet-wide only through the `tags` cap, which writes
|
|
2092
2092
|
* here with `setRuleTags`.
|
|
2093
2093
|
*/
|
|
2094
|
-
tags: /* @__PURE__ */ TagsFieldSchema.optional()
|
|
2094
|
+
tags: /* @__PURE__ */ TagsFieldSchema.optional(),
|
|
2095
|
+
/** The ids of those tags, index-aligned with `tags` (D1089). Absent = names only; a `tags` write without ids drops them. */
|
|
2096
|
+
tagIds: /* @__PURE__ */ TagIdsFieldSchema.optional()
|
|
2095
2097
|
});
|
|
2096
2098
|
/**
|
|
2097
2099
|
* The rule kinds that carry tags (D1054) — each one its own store. Every kind
|
|
@@ -2107,7 +2109,9 @@ var NcTaggedRuleKindSchema = /* @__PURE__ */ z.enum([
|
|
|
2107
2109
|
var NcRuleTagsEntrySchema = /* @__PURE__ */ z.object({
|
|
2108
2110
|
kind: NcTaggedRuleKindSchema,
|
|
2109
2111
|
ruleId: /* @__PURE__ */ z.string(),
|
|
2110
|
-
tags: /* @__PURE__ */ z.array(/* @__PURE__ */ z.string())
|
|
2112
|
+
tags: /* @__PURE__ */ z.array(/* @__PURE__ */ z.string()),
|
|
2113
|
+
/** The tag ids, index-aligned with `tags`; `[]` for a rule not migrated yet. */
|
|
2114
|
+
tagIds: /* @__PURE__ */ z.array(/* @__PURE__ */ z.string())
|
|
2111
2115
|
});
|
|
2112
2116
|
/**
|
|
2113
2117
|
* Partial patch for `updateRule` — any subset of the input fields, plus the
|
|
@@ -3169,7 +3173,8 @@ var notificationRulesCapability = {
|
|
|
3169
3173
|
setRuleTags: /* @__PURE__ */ method(/* @__PURE__ */ z.object({
|
|
3170
3174
|
kind: NcTaggedRuleKindSchema,
|
|
3171
3175
|
ruleId: /* @__PURE__ */ z.string(),
|
|
3172
|
-
tags: TagsFieldSchema
|
|
3176
|
+
tags: TagsFieldSchema,
|
|
3177
|
+
tagIds: /* @__PURE__ */ TagIdsFieldSchema.optional()
|
|
3173
3178
|
}), /* @__PURE__ */ z.object({ success: /* @__PURE__ */ z.literal(true) }), {
|
|
3174
3179
|
kind: "mutation",
|
|
3175
3180
|
auth: "admin"
|
package/system/dist/{notification-rules.cap-BJKUjizS.js → notification-rules.cap-uSLoe2pA.js}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_streaming_shared = require("./streaming-shared-DQwFZOSi.js");
|
|
2
2
|
const require_capability_definition = require("./capability-definition-BEVd01Xj.js");
|
|
3
|
-
const require_tag = require("./tag-
|
|
3
|
+
const require_tag = require("./tag-BLraBqvp.js");
|
|
4
4
|
const require_device_type = require("./device-type-Cnc0NiSX.js");
|
|
5
5
|
const require_l10n = require("./l10n-CGMvp7NF.js");
|
|
6
|
-
const require_error_cap = require("./error.cap-
|
|
6
|
+
const require_error_cap = require("./error.cap-BqlvgBJd.js");
|
|
7
7
|
const require_mask_shape = require("./mask-shape-CmPA2fst.js");
|
|
8
8
|
let zod = require("zod");
|
|
9
9
|
//#region ../types/dist/esm/capabilities/notification-output.cap.mjs
|
|
@@ -2091,7 +2091,9 @@ var NcRuleInputSchema = /* @__PURE__ */ zod.z.object({
|
|
|
2091
2091
|
* Renamed or removed fleet-wide only through the `tags` cap, which writes
|
|
2092
2092
|
* here with `setRuleTags`.
|
|
2093
2093
|
*/
|
|
2094
|
-
tags: /* @__PURE__ */ require_tag.TagsFieldSchema.optional()
|
|
2094
|
+
tags: /* @__PURE__ */ require_tag.TagsFieldSchema.optional(),
|
|
2095
|
+
/** The ids of those tags, index-aligned with `tags` (D1089). Absent = names only; a `tags` write without ids drops them. */
|
|
2096
|
+
tagIds: /* @__PURE__ */ require_tag.TagIdsFieldSchema.optional()
|
|
2095
2097
|
});
|
|
2096
2098
|
/**
|
|
2097
2099
|
* The rule kinds that carry tags (D1054) — each one its own store. Every kind
|
|
@@ -2107,7 +2109,9 @@ var NcTaggedRuleKindSchema = /* @__PURE__ */ zod.z.enum([
|
|
|
2107
2109
|
var NcRuleTagsEntrySchema = /* @__PURE__ */ zod.z.object({
|
|
2108
2110
|
kind: NcTaggedRuleKindSchema,
|
|
2109
2111
|
ruleId: /* @__PURE__ */ zod.z.string(),
|
|
2110
|
-
tags: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string())
|
|
2112
|
+
tags: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string()),
|
|
2113
|
+
/** The tag ids, index-aligned with `tags`; `[]` for a rule not migrated yet. */
|
|
2114
|
+
tagIds: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string())
|
|
2111
2115
|
});
|
|
2112
2116
|
/**
|
|
2113
2117
|
* Partial patch for `updateRule` — any subset of the input fields, plus the
|
|
@@ -3169,7 +3173,8 @@ var notificationRulesCapability = {
|
|
|
3169
3173
|
setRuleTags: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({
|
|
3170
3174
|
kind: NcTaggedRuleKindSchema,
|
|
3171
3175
|
ruleId: /* @__PURE__ */ zod.z.string(),
|
|
3172
|
-
tags: require_tag.TagsFieldSchema
|
|
3176
|
+
tags: require_tag.TagsFieldSchema,
|
|
3177
|
+
tagIds: /* @__PURE__ */ require_tag.TagIdsFieldSchema.optional()
|
|
3173
3178
|
}), /* @__PURE__ */ zod.z.object({ success: /* @__PURE__ */ zod.z.literal(true) }), {
|
|
3174
3179
|
kind: "mutation",
|
|
3175
3180
|
auth: "admin"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_base_addon = require("./base-addon-
|
|
2
|
-
const require_notification_rules_cap = require("./notification-rules.cap-
|
|
1
|
+
const require_base_addon = require("./base-addon-BG7p06Hb.js");
|
|
2
|
+
const require_notification_rules_cap = require("./notification-rules.cap-uSLoe2pA.js");
|
|
3
3
|
const require_entry_kind = require("./entry-kind-cq90c--V.js");
|
|
4
4
|
let zod = require("zod");
|
|
5
5
|
//#region ../types/dist/esm/addon/compose-instance-kinds.mjs
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as optionalLinkField, l as RecordIntegrationInstances, v as isInstanceOn, y as recordInstanceSwitch } from "./base-addon-
|
|
2
|
-
import { d as TargetSchema } from "./notification-rules.cap-
|
|
1
|
+
import { d as optionalLinkField, l as RecordIntegrationInstances, v as isInstanceOn, y as recordInstanceSwitch } from "./base-addon-BcVoYZbC.mjs";
|
|
2
|
+
import { d as TargetSchema } from "./notification-rules.cap-ClvK6QT1.mjs";
|
|
3
3
|
import { t as defineEntryKind } from "./entry-kind-D9MuVJCK.mjs";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
//#region ../types/dist/esm/addon/compose-instance-kinds.mjs
|