@camstack/server 1.2.838 → 1.2.839
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 +10 -0
- package/dist/api/core/auth.router.js +19 -0
- package/dist/api/trpc/device-access.js +54 -0
- package/dist/api/trpc/trpc.middleware.js +3 -2
- package/package.json +7 -6
- 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 +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- 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 +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- 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 +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +4 -4
- package/system/dist/builtins/composer/composer.addon.mjs +4 -4
- 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/core-blocks.addon.js +45 -6
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +45 -6
- package/system/dist/builtins/core-blocks/scheduler/scheduler-engine.d.ts +7 -0
- package/system/dist/builtins/core-blocks/step-condition-door.d.ts +4 -0
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
- 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 +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- 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 +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- 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 +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/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 +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
- 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-Bgml6l8Z.js → capture-engine-7E2O4-UN.js} +1 -1
- package/system/dist/{capture-engine-BQjIa865.mjs → capture-engine-B5IBWIRT.mjs} +1 -1
- package/system/dist/{composition-sources-CrL4KcSA.mjs → composition-sources-Cfqn4cly.mjs} +1 -1
- package/system/dist/{composition-sources-C7hUy8w0.js → composition-sources-DLtc8lSL.js} +1 -1
- package/system/dist/{constants-CUAo3cLm.js → constants-Cc70YreG.js} +1 -1
- package/system/dist/{constants-Bw5qtfbX.mjs → constants-DjsgCnZk.mjs} +1 -1
- package/system/dist/{device-ca-YELIR9gF.js → device-ca-C6JqeFfK.js} +1 -1
- package/system/dist/{device-ca-BDmoMgA3.mjs → device-ca-CVP5h3u1.mjs} +1 -1
- package/system/dist/{dist-D3_60xED.js → dist-CLnTYKFn.js} +346 -21
- package/system/dist/{dist-yQfQUpYA.mjs → dist-OmrC_RZs.mjs} +335 -22
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-C8FGw7Mt.mjs → hub-identity-CKQVXf4o.mjs} +1 -1
- package/system/dist/{hub-identity-c_zPVKOY.js → hub-identity-TrZcnJkB.js} +1 -1
- package/system/dist/{hub-mdns-ciao-CM64AtFQ.mjs → hub-mdns-ciao-C8G0K1Z1.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-CaWa1FY1.js → hub-mdns-ciao-ocg6suyX.js} +2 -2
- package/system/dist/index.js +8 -8
- package/system/dist/index.mjs +8 -8
- package/system/dist/{legacy-integration-rows-door-D5Qe0A95.mjs → legacy-integration-rows-door-BPkJUGaX.mjs} +1 -1
- package/system/dist/{legacy-integration-rows-door-BnEJMuwz.js → legacy-integration-rows-door-b6CUxtXX.js} +1 -1
- package/system/dist/{rename-composition-block-DXN1dVXs.mjs → rename-composition-block-DPlsP1xF.mjs} +1 -1
- package/system/dist/{rename-composition-block-CbAR4yC9.js → rename-composition-block-N7lslQJK.js} +1 -1
- package/system/dist/{restore-archive-C88Ee7w9.mjs → restore-archive-Btc3H-Fg.mjs} +1 -1
- package/system/dist/{restore-archive-DDzgcjNf.js → restore-archive-CcuEoEtj.js} +1 -1
- package/system/dist/{wal-maintenance-BNN52u-q.js → wal-maintenance-B2_uCEi5.js} +0 -0
- package/system/dist/{wal-maintenance-EvgkvDZK.mjs → wal-maintenance-g7yvxLMj.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -43263,7 +43263,7 @@ function weekdayOfLocalDate(localDate) {
|
|
|
43263
43263
|
const { y, m, d } = parseLocalDate(localDate);
|
|
43264
43264
|
return WEEKDAY_BY_INDEX[new Date(Date.UTC(y, m - 1, d)).getUTCDay()] ?? "sun";
|
|
43265
43265
|
}
|
|
43266
|
-
function addDays(localDate, days) {
|
|
43266
|
+
function addDays$1(localDate, days) {
|
|
43267
43267
|
const { y, m, d } = parseLocalDate(localDate);
|
|
43268
43268
|
return new Date(Date.UTC(y, m - 1, d + days)).toISOString().slice(0, 10);
|
|
43269
43269
|
}
|
|
@@ -43325,9 +43325,9 @@ function nextOccurrence(spec, afterMs, site, options = {}) {
|
|
|
43325
43325
|
const at = occurrenceOn(spec, own, site);
|
|
43326
43326
|
return at !== null && at > afterMs ? at : null;
|
|
43327
43327
|
}
|
|
43328
|
-
const first = addDays(localDateOf(afterMs, site.timeZone), -1);
|
|
43328
|
+
const first = addDays$1(localDateOf(afterMs, site.timeZone), -1);
|
|
43329
43329
|
for (let i = 0; i < 400; i += 1) {
|
|
43330
|
-
const localDate = addDays(first, i);
|
|
43330
|
+
const localDate = addDays$1(first, i);
|
|
43331
43331
|
if (days !== void 0 && !days.includes(weekdayOfLocalDate(localDate))) continue;
|
|
43332
43332
|
const at = occurrenceOn(spec, localDate, site);
|
|
43333
43333
|
if (at !== null && at > afterMs) return at;
|
|
@@ -43371,7 +43371,8 @@ function zoneOnlySite(timeZone) {
|
|
|
43371
43371
|
return {
|
|
43372
43372
|
lat: 0,
|
|
43373
43373
|
lon: 0,
|
|
43374
|
-
timeZone
|
|
43374
|
+
timeZone,
|
|
43375
|
+
zoneOnly: true
|
|
43375
43376
|
};
|
|
43376
43377
|
}
|
|
43377
43378
|
/**
|
|
@@ -43473,6 +43474,13 @@ var AutomationConditionOperatorSchema = zod.z.enum([
|
|
|
43473
43474
|
"in"
|
|
43474
43475
|
]);
|
|
43475
43476
|
/**
|
|
43477
|
+
* The stable name of an event leaf. A path (`when.0.1`) moves when a row is
|
|
43478
|
+
* reordered; the id does not, so a `triggered-by` leaf keeps pointing at the
|
|
43479
|
+
* same row. Optional: a leaf nothing refers to needs none.
|
|
43480
|
+
*/
|
|
43481
|
+
var EVENT_LEAF_ID_RE = /^[A-Za-z0-9_-]{1,40}$/;
|
|
43482
|
+
var eventLeafId = { id: zod.z.string().regex(EVENT_LEAF_ID_RE).optional() };
|
|
43483
|
+
/**
|
|
43476
43484
|
* D8 compliance, and it is the reason a "becomes" leaf is not merely an event
|
|
43477
43485
|
* subscription: it evaluates against the **state mirror**, which is reconciled,
|
|
43478
43486
|
* and an event only WAKES the evaluation. A dropped event therefore DELAYS a
|
|
@@ -43480,6 +43488,7 @@ var AutomationConditionOperatorSchema = zod.z.enum([
|
|
|
43480
43488
|
*/
|
|
43481
43489
|
var DeviceBecomesLeafSchema = zod.z.object({
|
|
43482
43490
|
kind: zod.z.literal("device-becomes"),
|
|
43491
|
+
...eventLeafId,
|
|
43483
43492
|
deviceId: zod.z.number().int().nonnegative(),
|
|
43484
43493
|
cap: zod.z.string().min(1),
|
|
43485
43494
|
fieldPath: zod.z.string().min(1),
|
|
@@ -43532,6 +43541,7 @@ var DeviceBecomesLeafSchema = zod.z.object({
|
|
|
43532
43541
|
});
|
|
43533
43542
|
var DeviceEventLeafSchema = zod.z.object({
|
|
43534
43543
|
kind: zod.z.literal("device-event"),
|
|
43544
|
+
...eventLeafId,
|
|
43535
43545
|
/** An `EventCategory` value. */
|
|
43536
43546
|
category: zod.z.string().min(1),
|
|
43537
43547
|
deviceId: zod.z.number().int().nonnegative().optional()
|
|
@@ -43544,18 +43554,24 @@ var DeviceEventLeafSchema = zod.z.object({
|
|
|
43544
43554
|
*/
|
|
43545
43555
|
var ScheduleLeafSchema = zod.z.object({
|
|
43546
43556
|
kind: zod.z.literal("schedule"),
|
|
43557
|
+
...eventLeafId,
|
|
43547
43558
|
at: TimeSpecSchema.optional(),
|
|
43548
43559
|
days: zod.z.array(WeekdayKeySchema).min(1).max(7).optional(),
|
|
43549
43560
|
/** @deprecated legacy cron — new schedules use `at`. */
|
|
43550
43561
|
cron: zod.z.string().min(1).max(120).optional()
|
|
43551
43562
|
}).refine((leaf) => leaf.at === void 0 !== (leaf.cron === void 0), { message: "a schedule names exactly one of `at` (a time spec) and `cron` (legacy)" }).refine((leaf) => leaf.days === void 0 || leaf.at !== void 0, { message: "`days` goes with `at`; a cron expression carries its own days" });
|
|
43552
|
-
var ManualLeafSchema = zod.z.object({
|
|
43563
|
+
var ManualLeafSchema = zod.z.object({
|
|
43564
|
+
kind: zod.z.literal("manual"),
|
|
43565
|
+
...eventLeafId
|
|
43566
|
+
});
|
|
43553
43567
|
var IntervalLeafSchema = zod.z.object({
|
|
43554
43568
|
kind: zod.z.literal("interval"),
|
|
43569
|
+
...eventLeafId,
|
|
43555
43570
|
minutes: zod.z.number().int().min(1).max(1440)
|
|
43556
43571
|
});
|
|
43557
43572
|
var DetectionLeafSchema = zod.z.object({
|
|
43558
43573
|
kind: zod.z.literal("detection"),
|
|
43574
|
+
...eventLeafId,
|
|
43559
43575
|
/** One macro class each, optionally narrowed by a label; a track of any listed subject fires. */
|
|
43560
43576
|
subjects: zod.z.array(DetectionSubjectSchema).min(1),
|
|
43561
43577
|
deviceIds: zod.z.array(zod.z.number().int().nonnegative()).min(1),
|
|
@@ -43566,6 +43582,7 @@ var DetectionLeafSchema = zod.z.object({
|
|
|
43566
43582
|
});
|
|
43567
43583
|
var StationaryLeafSchema = zod.z.object({
|
|
43568
43584
|
kind: zod.z.literal("stationary"),
|
|
43585
|
+
...eventLeafId,
|
|
43569
43586
|
deviceIds: zod.z.array(zod.z.number().int().nonnegative()).min(1),
|
|
43570
43587
|
subjects: zod.z.array(StationarySubjectSchema).min(1).optional(),
|
|
43571
43588
|
zones: zod.z.array(zod.z.string().min(1)).min(1).optional(),
|
|
@@ -43611,6 +43628,41 @@ var StationaryPresentLeafSchema = zod.z.object({
|
|
|
43611
43628
|
minCount: zod.z.number().int().positive().optional()
|
|
43612
43629
|
});
|
|
43613
43630
|
/**
|
|
43631
|
+
* True while the site-local clock is inside a daily window and/or on one of
|
|
43632
|
+
* the named days. `days` names the local day a window STARTS on, so
|
|
43633
|
+
* 22:00-06:00 on weekdays is still inside at 01:00 Saturday. A one-date spec
|
|
43634
|
+
* (`kind: 'date'`) is refused: only a clock time or a sun event makes a window
|
|
43635
|
+
* that repeats every day.
|
|
43636
|
+
*/
|
|
43637
|
+
var TimeIsLeafSchema = zod.z.object({
|
|
43638
|
+
kind: zod.z.literal("time-is"),
|
|
43639
|
+
between: zod.z.object({
|
|
43640
|
+
from: TimeSpecSchema,
|
|
43641
|
+
to: TimeSpecSchema
|
|
43642
|
+
}).optional(),
|
|
43643
|
+
days: zod.z.array(WeekdayKeySchema).min(1).max(7).optional()
|
|
43644
|
+
}).superRefine((leaf, ctx) => {
|
|
43645
|
+
if (leaf.between === void 0 && leaf.days === void 0) ctx.addIssue({
|
|
43646
|
+
code: "custom",
|
|
43647
|
+
message: "a time-is leaf needs a between window, days, or both"
|
|
43648
|
+
});
|
|
43649
|
+
for (const end of ["from", "to"]) if (leaf.between?.[end].kind === "date") ctx.addIssue({
|
|
43650
|
+
code: "custom",
|
|
43651
|
+
message: "a one-date time cannot bound a daily window: use a clock time or a sun event",
|
|
43652
|
+
path: ["between", end]
|
|
43653
|
+
});
|
|
43654
|
+
});
|
|
43655
|
+
/**
|
|
43656
|
+
* True for the run that one of the named event leaves started. It reads the
|
|
43657
|
+
* run, not a device: in the tree it is judged against the leaf that fired, in
|
|
43658
|
+
* a step guard against the trigger the run carries. A run no event leaf
|
|
43659
|
+
* started (a state-only tree becoming true) is false.
|
|
43660
|
+
*/
|
|
43661
|
+
var TriggeredByLeafSchema = zod.z.object({
|
|
43662
|
+
kind: zod.z.literal("triggered-by"),
|
|
43663
|
+
leafIds: zod.z.array(zod.z.string().regex(EVENT_LEAF_ID_RE)).min(1).max(20)
|
|
43664
|
+
});
|
|
43665
|
+
/**
|
|
43614
43666
|
* The escape hatch: the bounded expression engine over named device bindings.
|
|
43615
43667
|
* Declared as a plain object so a discriminated union can read `kind`; the
|
|
43616
43668
|
* author-time validation is the SAME function `ExpressionSourceSchema` runs.
|
|
@@ -43656,7 +43708,9 @@ var AutomationWhenSchema = zod.z.lazy(() => zod.z.discriminatedUnion("kind", [
|
|
|
43656
43708
|
StationaryLeafSchema,
|
|
43657
43709
|
DeviceIsLeafSchema,
|
|
43658
43710
|
StationaryPresentLeafSchema,
|
|
43659
|
-
ExpressionLeafSchema
|
|
43711
|
+
ExpressionLeafSchema,
|
|
43712
|
+
TimeIsLeafSchema,
|
|
43713
|
+
TriggeredByLeafSchema
|
|
43660
43714
|
]));
|
|
43661
43715
|
var EVENT_KINDS = new Set([
|
|
43662
43716
|
"device-becomes",
|
|
@@ -43710,6 +43764,32 @@ function hasEventLeaves(node) {
|
|
|
43710
43764
|
});
|
|
43711
43765
|
return found;
|
|
43712
43766
|
}
|
|
43767
|
+
/** The event leaves of the tree that carry an id, in tree order. */
|
|
43768
|
+
function identifiedEventLeaves(when) {
|
|
43769
|
+
const found = [];
|
|
43770
|
+
forEachLeaf(when, (leaf, path) => {
|
|
43771
|
+
if (isEventLeaf(leaf) && leaf.id !== void 0) found.push({
|
|
43772
|
+
id: leaf.id,
|
|
43773
|
+
path,
|
|
43774
|
+
leaf
|
|
43775
|
+
});
|
|
43776
|
+
});
|
|
43777
|
+
return found;
|
|
43778
|
+
}
|
|
43779
|
+
/** The id of the event leaf at `path` (`when.0.1`); null when the leaf has none or the path names no event leaf. */
|
|
43780
|
+
function eventLeafIdAt(when, path) {
|
|
43781
|
+
return identifiedEventLeaves(when).find((entry) => entry.path === path)?.id ?? null;
|
|
43782
|
+
}
|
|
43783
|
+
/** Does the tree hold a `triggered-by` leaf? */
|
|
43784
|
+
function hasTriggeredByLeaves(when) {
|
|
43785
|
+
let found = false;
|
|
43786
|
+
forEachLeaf(when, (leaf) => {
|
|
43787
|
+
if (leaf.kind === "triggered-by") found = true;
|
|
43788
|
+
});
|
|
43789
|
+
return found;
|
|
43790
|
+
}
|
|
43791
|
+
/** Why a `triggered-by` leaf is refused outside an automation: there is no trigger row to name. */
|
|
43792
|
+
var TRIGGERED_BY_NEEDS_AUTOMATION = "\"triggered by\" reads which trigger started an automation — an action or a scheduler has no trigger rows, so it could never be true here";
|
|
43713
43793
|
function hasEmptyContainer(node) {
|
|
43714
43794
|
if (isLeaf(node)) return false;
|
|
43715
43795
|
if (node.kind === "not") return hasEmptyContainer(node.child);
|
|
@@ -43768,6 +43848,11 @@ function validateWhenTree(when) {
|
|
|
43768
43848
|
if (depth > 4) return `the rules nest ${depth} levels deep — the limit is 4. "not (any of …)" is the same as "all of (not …)", which is one level shallower`;
|
|
43769
43849
|
const leaves = countWhenLeaves(when);
|
|
43770
43850
|
if (leaves > 32) return `the rules use ${leaves} rows — the limit is 32`;
|
|
43851
|
+
const seen = /* @__PURE__ */ new Set();
|
|
43852
|
+
for (const entry of identifiedEventLeaves(when)) {
|
|
43853
|
+
if (seen.has(entry.id)) return `two trigger rows share the id "${entry.id}" — an id names one row`;
|
|
43854
|
+
seen.add(entry.id);
|
|
43855
|
+
}
|
|
43771
43856
|
const need = eventNeed(when, "when", false);
|
|
43772
43857
|
if ("error" in need) return need.error;
|
|
43773
43858
|
const [first, second] = need.paths;
|
|
@@ -44099,7 +44184,18 @@ var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).re
|
|
|
44099
44184
|
message: "a domain target needs the vocabulary action it applies to (actionId)",
|
|
44100
44185
|
path: ["actionId"]
|
|
44101
44186
|
}).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
|
|
44102
|
-
|
|
44187
|
+
/**
|
|
44188
|
+
* A step of a STANDALONE list (an action, a scheduler point, a preset): the
|
|
44189
|
+
* same two step kinds an automation runs, minus a guard that reads the
|
|
44190
|
+
* automation's trigger, which such a list does not have.
|
|
44191
|
+
*/
|
|
44192
|
+
var ActionStepSchema = zod.z.discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]).superRefine((step, ctx) => {
|
|
44193
|
+
if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
|
|
44194
|
+
code: "custom",
|
|
44195
|
+
message: TRIGGERED_BY_NEEDS_AUTOMATION,
|
|
44196
|
+
path: ["if"]
|
|
44197
|
+
});
|
|
44198
|
+
});
|
|
44103
44199
|
var AutomationActionSchema = zod.z.discriminatedUnion("kind", [
|
|
44104
44200
|
GuardedWaitStepSchema,
|
|
44105
44201
|
GuardedCapStepSchema,
|
|
@@ -44183,6 +44279,91 @@ function convertLegacyRecipe(legacy) {
|
|
|
44183
44279
|
*/
|
|
44184
44280
|
var AutomationRecipeSchema = zod.z.union([CurrentAutomationRecipeSchema, LegacyAutomationRecipeSchema.transform(convertLegacyRecipe)]);
|
|
44185
44281
|
/**
|
|
44282
|
+
* A daily window as a STATE: is this instant inside it, and when does that
|
|
44283
|
+
* next change? Pure — the answer is built per local date from
|
|
44284
|
+
* {@link occurrenceOn}, so a DST change needs no special case.
|
|
44285
|
+
*
|
|
44286
|
+
* Rules:
|
|
44287
|
+
* - A window whose `to` is not after its `from` on the same local date WRAPS:
|
|
44288
|
+
* it runs from `from` on day D to `to` on D+1.
|
|
44289
|
+
* - `days` names the local day a window STARTS on. 22:00-06:00 on weekdays is
|
|
44290
|
+
* inside at 01:00 Saturday (it started Friday). With `days` and no
|
|
44291
|
+
* `between` the window is the whole local day.
|
|
44292
|
+
* - A sun event that does not happen on a day (polar day or night) gives that
|
|
44293
|
+
* day no window. A sun event on a site WITHOUT a location (or an unknown
|
|
44294
|
+
* zone) cannot be judged at all: the result is `unknown`, never a guess.
|
|
44295
|
+
*/
|
|
44296
|
+
var MIDNIGHT = {
|
|
44297
|
+
kind: "clock",
|
|
44298
|
+
hh: 0,
|
|
44299
|
+
mm: 0
|
|
44300
|
+
};
|
|
44301
|
+
/** Start dates looked at for a boundary: yesterday .. the day after tomorrow. */
|
|
44302
|
+
var LOOKAHEAD_DAYS = 2;
|
|
44303
|
+
function addDays(localDate, days) {
|
|
44304
|
+
const [y, m, d] = localDate.split("-").map(Number);
|
|
44305
|
+
return new Date(Date.UTC(y ?? 0, (m ?? 1) - 1, (d ?? 1) + days)).toISOString().slice(0, 10);
|
|
44306
|
+
}
|
|
44307
|
+
function unresolvable(window, site) {
|
|
44308
|
+
if (!isKnownTimeZone(site.timeZone)) return `the site time zone "${site.timeZone}" is not a known IANA zone`;
|
|
44309
|
+
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";
|
|
44310
|
+
return null;
|
|
44311
|
+
}
|
|
44312
|
+
/** The interval that STARTS on local day `startDate`, or null when that day has none. */
|
|
44313
|
+
function intervalStartingOn(window, startDate, site) {
|
|
44314
|
+
if (window.days !== void 0 && !window.days.includes(weekdayOfLocalDate(startDate))) return null;
|
|
44315
|
+
if (window.between === void 0) {
|
|
44316
|
+
const start = occurrenceOn(MIDNIGHT, startDate, site);
|
|
44317
|
+
const end = occurrenceOn(MIDNIGHT, addDays(startDate, 1), site);
|
|
44318
|
+
return start === null || end === null ? null : {
|
|
44319
|
+
start,
|
|
44320
|
+
end
|
|
44321
|
+
};
|
|
44322
|
+
}
|
|
44323
|
+
const start = occurrenceOn(window.between.from, startDate, site);
|
|
44324
|
+
const sameDayEnd = occurrenceOn(window.between.to, startDate, site);
|
|
44325
|
+
if (start === null || sameDayEnd === null) return null;
|
|
44326
|
+
if (sameDayEnd > start) return {
|
|
44327
|
+
start,
|
|
44328
|
+
end: sameDayEnd
|
|
44329
|
+
};
|
|
44330
|
+
const end = occurrenceOn(window.between.to, addDays(startDate, 1), site);
|
|
44331
|
+
return end === null || end <= start ? null : {
|
|
44332
|
+
start,
|
|
44333
|
+
end
|
|
44334
|
+
};
|
|
44335
|
+
}
|
|
44336
|
+
function judgeTimeWindow(window, nowMs, site) {
|
|
44337
|
+
const blocked = unresolvable(window, site);
|
|
44338
|
+
if (blocked !== null) return {
|
|
44339
|
+
inside: false,
|
|
44340
|
+
unknown: true,
|
|
44341
|
+
nextChangeAtMs: null,
|
|
44342
|
+
why: `cannot be judged: ${blocked}`
|
|
44343
|
+
};
|
|
44344
|
+
const today = localDateOf(nowMs, site.timeZone);
|
|
44345
|
+
let inside = false;
|
|
44346
|
+
let next = null;
|
|
44347
|
+
for (let offset = -1; offset <= LOOKAHEAD_DAYS; offset += 1) {
|
|
44348
|
+
const interval = intervalStartingOn(window, addDays(today, offset), site);
|
|
44349
|
+
if (interval === null) continue;
|
|
44350
|
+
if (interval.start <= nowMs && nowMs < interval.end) inside = true;
|
|
44351
|
+
for (const boundary of [interval.start, interval.end]) if (boundary > nowMs && (next === null || boundary < next)) next = boundary;
|
|
44352
|
+
}
|
|
44353
|
+
if (window.between === void 0) {
|
|
44354
|
+
const midnight = occurrenceOn(MIDNIGHT, addDays(today, 1), site);
|
|
44355
|
+
if (midnight !== null && midnight > nowMs && (next === null || midnight < next)) next = midnight;
|
|
44356
|
+
}
|
|
44357
|
+
const days = window.days === void 0 ? "" : ` on ${window.days.join(", ")}`;
|
|
44358
|
+
const span = window.between === void 0 ? "the whole day" : "the window";
|
|
44359
|
+
return {
|
|
44360
|
+
inside,
|
|
44361
|
+
unknown: false,
|
|
44362
|
+
nextChangeAtMs: next,
|
|
44363
|
+
why: inside ? `inside ${span}${days}` : `outside ${span}${days}`
|
|
44364
|
+
};
|
|
44365
|
+
}
|
|
44366
|
+
/**
|
|
44186
44367
|
* Evaluating an automation's condition tree against the ConditionMirror.
|
|
44187
44368
|
*
|
|
44188
44369
|
* D49: a trigger is a one-shot event, so its gate must never hang on a read
|
|
@@ -44254,6 +44435,8 @@ function collectInto(cond, out) {
|
|
|
44254
44435
|
...binding.addonId !== void 0 ? { addonId: binding.addonId } : {}
|
|
44255
44436
|
});
|
|
44256
44437
|
return;
|
|
44438
|
+
case "time-is": return;
|
|
44439
|
+
case "triggered-by": return;
|
|
44257
44440
|
default: return;
|
|
44258
44441
|
}
|
|
44259
44442
|
}
|
|
@@ -44270,6 +44453,32 @@ function collectWhenMirrorSources(cond) {
|
|
|
44270
44453
|
return true;
|
|
44271
44454
|
});
|
|
44272
44455
|
}
|
|
44456
|
+
/** Does the tree hold a `time-is` leaf? */
|
|
44457
|
+
function hasTimeLeaves(when) {
|
|
44458
|
+
let found = false;
|
|
44459
|
+
forEachLeaf(when, (leaf) => {
|
|
44460
|
+
if (leaf.kind === "time-is") found = true;
|
|
44461
|
+
});
|
|
44462
|
+
return found;
|
|
44463
|
+
}
|
|
44464
|
+
/**
|
|
44465
|
+
* The soonest ANY `time-is` leaf changes sides (ms from `now`), over every
|
|
44466
|
+
* leaf of the tree — a short-circuit that skipped a leaf in the last
|
|
44467
|
+
* evaluation must not hide its boundary. Undefined: no time leaf, no site, or
|
|
44468
|
+
* no boundary within reach.
|
|
44469
|
+
*/
|
|
44470
|
+
function nextTimeBoundaryInMs(when, now, site, rootPath = "when") {
|
|
44471
|
+
if (site === void 0) return void 0;
|
|
44472
|
+
let due;
|
|
44473
|
+
forEachLeaf(when, (leaf) => {
|
|
44474
|
+
if (leaf.kind !== "time-is") return;
|
|
44475
|
+
const next = judgeTimeWindow(leaf, now, site).nextChangeAtMs;
|
|
44476
|
+
if (next === null) return;
|
|
44477
|
+
const ms = Math.max(0, next - now);
|
|
44478
|
+
due = due === void 0 ? ms : Math.min(due, ms);
|
|
44479
|
+
}, rootPath);
|
|
44480
|
+
return due;
|
|
44481
|
+
}
|
|
44273
44482
|
function sliceKey(deviceId, cap) {
|
|
44274
44483
|
return `${deviceId}|${cap}`;
|
|
44275
44484
|
}
|
|
@@ -44601,6 +44810,53 @@ function evalNode(cond, path, reader, now, out, state) {
|
|
|
44601
44810
|
});
|
|
44602
44811
|
return ok;
|
|
44603
44812
|
}
|
|
44813
|
+
case "time-is": {
|
|
44814
|
+
if (state.site === void 0) {
|
|
44815
|
+
state.unknown = true;
|
|
44816
|
+
out.push({
|
|
44817
|
+
path,
|
|
44818
|
+
kind: cond.kind,
|
|
44819
|
+
outcome: "fail",
|
|
44820
|
+
reason: "the site clock is not known here → fail"
|
|
44821
|
+
});
|
|
44822
|
+
return false;
|
|
44823
|
+
}
|
|
44824
|
+
const verdict = judgeTimeWindow(cond, now, state.site);
|
|
44825
|
+
if (verdict.unknown) state.unknown = true;
|
|
44826
|
+
if (verdict.nextChangeAtMs !== null) {
|
|
44827
|
+
const due = Math.max(0, verdict.nextChangeAtMs - now);
|
|
44828
|
+
state.timeDueInMs = state.timeDueInMs === void 0 ? due : Math.min(state.timeDueInMs, due);
|
|
44829
|
+
}
|
|
44830
|
+
out.push({
|
|
44831
|
+
path,
|
|
44832
|
+
kind: cond.kind,
|
|
44833
|
+
outcome: verdict.inside ? "pass" : "fail",
|
|
44834
|
+
reason: `${verdict.why} → ${verdict.inside ? "pass" : "fail"}`
|
|
44835
|
+
});
|
|
44836
|
+
return verdict.inside;
|
|
44837
|
+
}
|
|
44838
|
+
case "triggered-by": {
|
|
44839
|
+
const named = cond.leafIds.map((id) => `"${id}"`).join(", ");
|
|
44840
|
+
if (state.trigger === "unknown") {
|
|
44841
|
+
state.unknown = true;
|
|
44842
|
+
out.push({
|
|
44843
|
+
path,
|
|
44844
|
+
kind: cond.kind,
|
|
44845
|
+
outcome: "fail",
|
|
44846
|
+
reason: `what started this run is not known here, so "triggered by ${named}" cannot be judged → fail`
|
|
44847
|
+
});
|
|
44848
|
+
return false;
|
|
44849
|
+
}
|
|
44850
|
+
const fired = state.trigger.leafId;
|
|
44851
|
+
const ok = fired !== null && cond.leafIds.includes(fired);
|
|
44852
|
+
out.push({
|
|
44853
|
+
path,
|
|
44854
|
+
kind: cond.kind,
|
|
44855
|
+
outcome: ok ? "pass" : "fail",
|
|
44856
|
+
reason: `${fired === null ? "no named trigger started this run" : `started by "${fired}"`}, wanted ${named} → ${ok ? "pass" : "fail"}`
|
|
44857
|
+
});
|
|
44858
|
+
return ok;
|
|
44859
|
+
}
|
|
44604
44860
|
case "not": {
|
|
44605
44861
|
const at = out.length;
|
|
44606
44862
|
out.push({
|
|
@@ -44659,13 +44915,17 @@ function evaluateWhenTree(when, reader, now, options = {}) {
|
|
|
44659
44915
|
firedPath: options.firedPath,
|
|
44660
44916
|
holds: options.holds,
|
|
44661
44917
|
unknown: false,
|
|
44662
|
-
holdDueInMs: void 0
|
|
44918
|
+
holdDueInMs: void 0,
|
|
44919
|
+
site: options.site,
|
|
44920
|
+
timeDueInMs: void 0,
|
|
44921
|
+
trigger: options.trigger ?? { leafId: options.firedPath === void 0 ? null : eventLeafIdAt(when, options.firedPath) }
|
|
44663
44922
|
};
|
|
44664
44923
|
return {
|
|
44665
44924
|
pass: evalNode(when, options.rootPath ?? "when", reader, now, nodes, state),
|
|
44666
44925
|
unknown: state.unknown,
|
|
44667
44926
|
nodes,
|
|
44668
|
-
...state.holdDueInMs === void 0 ? {} : { holdDueInMs: state.holdDueInMs }
|
|
44927
|
+
...state.holdDueInMs === void 0 ? {} : { holdDueInMs: state.holdDueInMs },
|
|
44928
|
+
...state.timeDueInMs === void 0 ? {} : { timeDueInMs: state.timeDueInMs }
|
|
44669
44929
|
};
|
|
44670
44930
|
}
|
|
44671
44931
|
var DETECTION_DESCRIPTIONS = {
|
|
@@ -44682,6 +44942,11 @@ var STATIONARY_DESCRIPTIONS = {
|
|
|
44682
44942
|
phase: "appeared or departed",
|
|
44683
44943
|
entryId: "the stopped object"
|
|
44684
44944
|
};
|
|
44945
|
+
var BECOMES_DESCRIPTIONS = {
|
|
44946
|
+
deviceId: "the device that changed",
|
|
44947
|
+
from: "the value before the change, empty when it is not known",
|
|
44948
|
+
to: "the value it changed to"
|
|
44949
|
+
};
|
|
44685
44950
|
function describe$1(descriptions) {
|
|
44686
44951
|
return Object.entries(descriptions).map(([name, description]) => ({
|
|
44687
44952
|
name,
|
|
@@ -44690,8 +44955,40 @@ function describe$1(descriptions) {
|
|
|
44690
44955
|
}
|
|
44691
44956
|
describe$1(DETECTION_DESCRIPTIONS);
|
|
44692
44957
|
describe$1(STATIONARY_DESCRIPTIONS);
|
|
44958
|
+
describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
|
|
44959
|
+
...v,
|
|
44960
|
+
hintKey: "becomesDeviceId"
|
|
44961
|
+
} : v);
|
|
44693
44962
|
new Set(Object.values(COCO_TO_MACRO.mapping));
|
|
44694
44963
|
/**
|
|
44964
|
+
* Save-time check of a `when` tree against the SITE: a `time-is` window
|
|
44965
|
+
* bounded by a sun event needs the site location, and any window needs a known
|
|
44966
|
+
* time zone. Refused before the save with a typed reason — at run time the
|
|
44967
|
+
* same leaf can only read `unknown`, and a rule that never decides is a rule
|
|
44968
|
+
* the operator believes is working. Pure: the site reading is handed in.
|
|
44969
|
+
*/
|
|
44970
|
+
var WINDOW_ENDS = ["from", "to"];
|
|
44971
|
+
/** Every `time-is` window end of the tree this site cannot place. `rootPath` replaces the leading `when`. */
|
|
44972
|
+
function whenSiteIssues(when, reading, rootPath = "when") {
|
|
44973
|
+
const issues = [];
|
|
44974
|
+
forEachLeaf(when, (leaf, path) => {
|
|
44975
|
+
if (leaf.kind !== "time-is" || leaf.between === void 0) return;
|
|
44976
|
+
for (const end of WINDOW_ENDS) {
|
|
44977
|
+
const checked = validateTimeSpecForSite(leaf.between[end], reading);
|
|
44978
|
+
if (!checked.ok) issues.push({
|
|
44979
|
+
path: `${path}.between.${end}`,
|
|
44980
|
+
reason: checked.reason,
|
|
44981
|
+
message: checked.message
|
|
44982
|
+
});
|
|
44983
|
+
}
|
|
44984
|
+
}, rootPath);
|
|
44985
|
+
return issues;
|
|
44986
|
+
}
|
|
44987
|
+
/** The same check over the guard (`if`) of every step of a list, reported under `<rootPath>.<i>.if`. */
|
|
44988
|
+
function stepGuardSiteIssues(steps, reading, rootPath) {
|
|
44989
|
+
return steps.flatMap((step, i) => step.if === void 0 ? [] : whenSiteIssues(step.if, reading, `${rootPath}.${i}.if`));
|
|
44990
|
+
}
|
|
44991
|
+
/**
|
|
44695
44992
|
* Schedulers (D983) — an entity that performs actions over the day.
|
|
44696
44993
|
*
|
|
44697
44994
|
* A scheduler has profiles; a profile has weekdays and a timeline of POINTS.
|
|
@@ -44714,6 +45011,13 @@ var SchedulerStateTreeSchema = AutomationWhenSchema.superRefine((when, ctx) => {
|
|
|
44714
45011
|
});
|
|
44715
45012
|
return;
|
|
44716
45013
|
}
|
|
45014
|
+
if (hasTriggeredByLeaves(when)) {
|
|
45015
|
+
ctx.addIssue({
|
|
45016
|
+
code: "custom",
|
|
45017
|
+
message: TRIGGERED_BY_NEEDS_AUTOMATION
|
|
45018
|
+
});
|
|
45019
|
+
return;
|
|
45020
|
+
}
|
|
44717
45021
|
const problem = validateWhenTree(when);
|
|
44718
45022
|
if (problem !== null) ctx.addIssue({
|
|
44719
45023
|
code: "custom",
|
|
@@ -44802,10 +45106,20 @@ function holdRefusalOf(step) {
|
|
|
44802
45106
|
*/
|
|
44803
45107
|
function validateSchedulerInput(input, reading) {
|
|
44804
45108
|
const issues = [];
|
|
45109
|
+
const siteIssues = (found) => {
|
|
45110
|
+
for (const issue of found) issues.push({
|
|
45111
|
+
path: issue.path,
|
|
45112
|
+
message: issue.message
|
|
45113
|
+
});
|
|
45114
|
+
};
|
|
45115
|
+
if (input.activeWhen !== void 0) siteIssues(whenSiteIssues(input.activeWhen, reading, "activeWhen"));
|
|
44805
45116
|
input.profiles.forEach((profile, pi) => {
|
|
44806
45117
|
const ids = /* @__PURE__ */ new Set();
|
|
45118
|
+
if (profile.activeWhen !== void 0) siteIssues(whenSiteIssues(profile.activeWhen, reading, `profiles.${pi}.activeWhen`));
|
|
44807
45119
|
profile.points.forEach((point, qi) => {
|
|
44808
45120
|
const base = `profiles.${pi}.points.${qi}`;
|
|
45121
|
+
if (point.conditions !== void 0) siteIssues(whenSiteIssues(point.conditions, reading, `${base}.conditions`));
|
|
45122
|
+
siteIssues(stepGuardSiteIssues(point.steps, reading, `${base}.steps`));
|
|
44809
45123
|
if (ids.has(point.id)) issues.push({
|
|
44810
45124
|
path: `${base}.id`,
|
|
44811
45125
|
message: `point id "${point.id}" is used twice`
|
|
@@ -45029,6 +45343,8 @@ var AutomationConditionTraceNodeSchema = zod.z.object({
|
|
|
45029
45343
|
"device-is",
|
|
45030
45344
|
"expression",
|
|
45031
45345
|
"stationary-present",
|
|
45346
|
+
"time-is",
|
|
45347
|
+
"triggered-by",
|
|
45032
45348
|
"device-becomes",
|
|
45033
45349
|
"device-event",
|
|
45034
45350
|
"schedule",
|
|
@@ -45456,21 +45772,18 @@ var ActionRunChangedSchema = zod.z.object({
|
|
|
45456
45772
|
lastRunAt: zod.z.number().nullable(),
|
|
45457
45773
|
lastError: zod.z.string().nullable()
|
|
45458
45774
|
});
|
|
45459
|
-
/**
|
|
45460
|
-
* The guard of a conditional step (#472): the step's `if` is the ONE `when`
|
|
45461
|
-
* tree (D980), read on a {@link ConditionMirror} filled for exactly the leaves
|
|
45462
|
-
* the tree names, at the moment the step is reached. A state that cannot be
|
|
45463
|
-
* read is UNKNOWN, and unknown runs neither side (D49: a failed read changes
|
|
45464
|
-
* nothing, and never decides a branch).
|
|
45465
|
-
*/
|
|
45466
45775
|
/** Fill a mirror for the tree's leaves from `fetchers` and judge it NOW. */
|
|
45467
|
-
async function evaluateStepCondition(when, fetchers, now = Date.now, history) {
|
|
45776
|
+
async function evaluateStepCondition(when, fetchers, now = Date.now, history, site, trigger) {
|
|
45468
45777
|
const mirror = history?.mirror ?? new ConditionMirror(collectWhenMirrorSources(when));
|
|
45469
45778
|
await mirror.refresh(fetchers);
|
|
45470
|
-
const evaluation = evaluateWhenTree(when, mirror, now(), {
|
|
45471
|
-
|
|
45472
|
-
|
|
45473
|
-
|
|
45779
|
+
const evaluation = evaluateWhenTree(when, mirror, now(), {
|
|
45780
|
+
...history === void 0 ? {} : {
|
|
45781
|
+
holds: history.holds,
|
|
45782
|
+
rootPath: history.rootPath
|
|
45783
|
+
},
|
|
45784
|
+
...site === void 0 ? {} : { site },
|
|
45785
|
+
trigger: trigger ?? "unknown"
|
|
45786
|
+
});
|
|
45474
45787
|
const first = evaluation.nodes.filter((n) => n.outcome !== "pass").map((n) => n.reason)[0];
|
|
45475
45788
|
if (evaluation.unknown) return {
|
|
45476
45789
|
result: "unknown",
|
|
@@ -120900,6 +121213,12 @@ Object.defineProperty(exports, "groupTemplate", {
|
|
|
120900
121213
|
return groupTemplate;
|
|
120901
121214
|
}
|
|
120902
121215
|
});
|
|
121216
|
+
Object.defineProperty(exports, "hasTimeLeaves", {
|
|
121217
|
+
enumerable: true,
|
|
121218
|
+
get: function() {
|
|
121219
|
+
return hasTimeLeaves;
|
|
121220
|
+
}
|
|
121221
|
+
});
|
|
120903
121222
|
Object.defineProperty(exports, "helperMembers", {
|
|
120904
121223
|
enumerable: true,
|
|
120905
121224
|
get: function() {
|
|
@@ -121302,6 +121621,12 @@ Object.defineProperty(exports, "nextOccurrence", {
|
|
|
121302
121621
|
return nextOccurrence;
|
|
121303
121622
|
}
|
|
121304
121623
|
});
|
|
121624
|
+
Object.defineProperty(exports, "nextTimeBoundaryInMs", {
|
|
121625
|
+
enumerable: true,
|
|
121626
|
+
get: function() {
|
|
121627
|
+
return nextTimeBoundaryInMs;
|
|
121628
|
+
}
|
|
121629
|
+
});
|
|
121305
121630
|
Object.defineProperty(exports, "nodeIdOfScopedKey", {
|
|
121306
121631
|
enumerable: true,
|
|
121307
121632
|
get: function() {
|