@camstack/server 1.2.864 → 1.2.866
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 +12 -0
- package/package.json +9 -7
- package/system/dist/addon-utils.mjs +1 -1
- 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 +4 -4
- 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 +5 -5
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- 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 +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
- 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 +3 -3
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
- 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 +5 -5
- 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 +10 -10
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +10 -10
- 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 +20 -20
- 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 +12 -8
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +12 -8
- 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 +115 -115
- 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-CK9f9H7b.mjs → capture-engine-5g4lu_OQ.mjs} +1 -1
- package/system/dist/{capture-engine-Cofev-f3.js → capture-engine-BCB1OMc_.js} +1 -1
- package/system/dist/{composition-sources-Pqrpujem.js → composition-sources-1yTVou3a.js} +1 -1
- package/system/dist/{composition-sources-Cah5d873.mjs → composition-sources-VkBsGWZh.mjs} +1 -1
- package/system/dist/{constants-BKiAEgH1.mjs → constants-D1lf-y38.mjs} +1 -1
- package/system/dist/{constants-DzdeUhhD.js → constants-r86Qr7xE.js} +1 -1
- package/system/dist/{coral-accelerators-DBlgWB8k.mjs → coral-accelerators-BW3OcrLD.mjs} +6 -6
- package/system/dist/{custom-action-registry-B9zFBNVa.mjs → custom-action-registry-N7flBDwT.mjs} +37 -37
- package/system/dist/{device-ca-DfFm8dSR.js → device-ca-Bs_oj8y_.js} +1 -1
- package/system/dist/{device-ca-MvTMcE3C.mjs → device-ca-aWcNrAeB.mjs} +1 -1
- package/system/dist/{dist-BDIq20ng.mjs → dist-BeM3jcMe.mjs} +824 -538
- package/system/dist/{dist-BJBp-Cna.js → dist-CtlwobAt.js} +824 -538
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-DZw5bjVe.js → hub-identity-C_3WvvUh.js} +1 -1
- package/system/dist/{hub-identity-DErvD_Y9.mjs → hub-identity-CoyjSGzP.mjs} +10 -10
- package/system/dist/{hub-mdns-ciao-Cn4CZvKD.js → hub-mdns-ciao-DrpNoAbD.js} +2 -2
- package/system/dist/{hub-mdns-ciao-DBtitWew.mjs → hub-mdns-ciao-MJdhRgSK.mjs} +2 -2
- package/system/dist/index.js +8 -8
- package/system/dist/index.mjs +217 -217
- package/system/dist/{legacy-integration-rows-door-Dm8DXrzQ.js → legacy-integration-rows-door-DknPUCvT.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-CT9d6do5.mjs → legacy-integration-rows-door-DwD_6A21.mjs} +1 -1
- package/system/dist/{rename-composition-block-BgjpGf0d.mjs → rename-composition-block-B7ZEwdvM.mjs} +1 -1
- package/system/dist/{rename-composition-block-CMrV8Rou.js → rename-composition-block-VNSmpCSW.js} +1 -1
- package/system/dist/{restore-archive-BTpU7KMz.mjs → restore-archive-3-Gd66TK.mjs} +94 -94
- package/system/dist/{restore-archive-BRIGjOQv.js → restore-archive-CizGJ-13.js} +1 -1
- package/system/dist/{wal-maintenance-BsgOZJxC.mjs → wal-maintenance-CMKws6du.mjs} +0 -0
- package/system/dist/{wal-maintenance-DAzeawfH.js → wal-maintenance-cI0DBU7k.js} +0 -0
- package/system/package.json +1 -1
|
@@ -812,7 +812,7 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
|
812
812
|
return EventCategory;
|
|
813
813
|
}({});
|
|
814
814
|
//#endregion
|
|
815
|
-
//#region ../types/dist/composed-stable-id-
|
|
815
|
+
//#region ../types/dist/composed-stable-id-COP6zOXx.mjs
|
|
816
816
|
/**
|
|
817
817
|
import { errMsg } from '@camstack/types'
|
|
818
818
|
* Extract a human-readable message from an unknown error value.
|
|
@@ -825,8 +825,6 @@ function errMsg(err) {
|
|
|
825
825
|
}
|
|
826
826
|
var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
827
827
|
DeviceType["Camera"] = "camera";
|
|
828
|
-
/** Legacy stored value, read only by the hub-to-integration migrations; no live device carries it. */
|
|
829
|
-
DeviceType["Hub"] = "hub";
|
|
830
828
|
DeviceType["Light"] = "light";
|
|
831
829
|
DeviceType["Siren"] = "siren";
|
|
832
830
|
DeviceType["Switch"] = "switch";
|
|
@@ -1261,7 +1259,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
|
|
|
1261
1259
|
*/
|
|
1262
1260
|
var COMPOSED_DEVICE_STABLE_ID_PREFIX = "composed-";
|
|
1263
1261
|
//#endregion
|
|
1264
|
-
//#region ../types/dist/sleep-
|
|
1262
|
+
//#region ../types/dist/sleep-B5XPl2YP.mjs
|
|
1265
1263
|
/**
|
|
1266
1264
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
1267
1265
|
* window to float samples (D455).
|
|
@@ -1988,7 +1986,8 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
1988
1986
|
try {
|
|
1989
1987
|
declaration = await host.declareOwner({
|
|
1990
1988
|
owner,
|
|
1991
|
-
metas: migrations.map((m) => m.meta)
|
|
1989
|
+
metas: migrations.map((m) => m.meta),
|
|
1990
|
+
...options.retired === void 0 ? {} : { retired: [...options.retired] }
|
|
1992
1991
|
});
|
|
1993
1992
|
} catch (err) {
|
|
1994
1993
|
log.error("the migration engine refused or could not take this addon catalogue — none ran", { meta: { error: errMsg(err) } });
|
|
@@ -4039,6 +4038,14 @@ var BaseAddon = class {
|
|
|
4039
4038
|
declareRegistrySwitch(spec) {
|
|
4040
4039
|
this.registrySwitchSpec = spec;
|
|
4041
4040
|
}
|
|
4041
|
+
/**
|
|
4042
|
+
* Ids this addon removed from its catalogue on purpose (`declareRetiredMigrations`): sent with
|
|
4043
|
+
* every declaration so the engine does not read their applied rows as a newer database.
|
|
4044
|
+
*/
|
|
4045
|
+
retiredMigrationIds = [];
|
|
4046
|
+
declareRetiredMigrations(ids) {
|
|
4047
|
+
this.retiredMigrationIds = ids;
|
|
4048
|
+
}
|
|
4042
4049
|
registrySwitchSpec = null;
|
|
4043
4050
|
registrySwitchBound() {
|
|
4044
4051
|
const spec = this.registrySwitchSpec;
|
|
@@ -4062,10 +4069,14 @@ var BaseAddon = class {
|
|
|
4062
4069
|
async runBound(declared, options) {
|
|
4063
4070
|
const added = this.registrySwitchBound();
|
|
4064
4071
|
const migrations = [...declared, ...added];
|
|
4065
|
-
const
|
|
4072
|
+
const widened = options?.only === void 0 || added.length === 0 ? options : {
|
|
4066
4073
|
...options,
|
|
4067
4074
|
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
4068
4075
|
};
|
|
4076
|
+
const phased = this.retiredMigrationIds.length === 0 ? widened ?? {} : {
|
|
4077
|
+
...widened,
|
|
4078
|
+
retired: this.retiredMigrationIds
|
|
4079
|
+
};
|
|
4069
4080
|
const api = this.ctx.api.migrations;
|
|
4070
4081
|
const report = await runAddonMigrations({
|
|
4071
4082
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
@@ -18130,7 +18141,7 @@ function sleep(ms) {
|
|
|
18130
18141
|
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
18131
18142
|
}
|
|
18132
18143
|
//#endregion
|
|
18133
|
-
//#region ../types/dist/implemented-methods-
|
|
18144
|
+
//#region ../types/dist/implemented-methods-0xxMOekw.mjs
|
|
18134
18145
|
var AUDIO_ENCODER_BY_CODEC = {
|
|
18135
18146
|
opus: "libopus",
|
|
18136
18147
|
aac: "aac",
|
|
@@ -46967,71 +46978,6 @@ var EventVocabularyEntrySchema = z.object({
|
|
|
46967
46978
|
payload: z.array(EventVocabularyFieldSchema).optional()
|
|
46968
46979
|
});
|
|
46969
46980
|
/**
|
|
46970
|
-
* The link an automation made FROM a template carries (#527): which template,
|
|
46971
|
-
* the values the operator filled in, and — when the template has since changed
|
|
46972
|
-
* so that those values no longer fit — the problems that say why.
|
|
46973
|
-
*
|
|
46974
|
-
* It lives inside the recipe (`AutomationRecipe.template`), so the one row in
|
|
46975
|
-
* `core_blocks` stays the one artefact: there is no second store of instances
|
|
46976
|
-
* to drift from the blocks, and deleting the automation deletes the link.
|
|
46977
|
-
* "Convert to a free automation" is dropping this field.
|
|
46978
|
-
*
|
|
46979
|
-
* This file depends on nothing in `recipe.ts`, so the recipe can embed it and
|
|
46980
|
-
* the template engine (`template/automation-template.ts`) can import both.
|
|
46981
|
-
*/
|
|
46982
|
-
/** An `event` input's value: the same three narrowing lists a `device-fired` row takes. */
|
|
46983
|
-
var TemplateEventValueSchema = z.object({
|
|
46984
|
-
eventIds: z.array(z.string().min(1)).min(1).max(64).optional(),
|
|
46985
|
-
sourceIds: z.array(z.string().min(1)).min(1).max(64).optional(),
|
|
46986
|
-
kinds: z.array(EventVocabularyKindSchema).min(1).optional()
|
|
46987
|
-
}).refine((value) => value.eventIds !== void 0 || value.sourceIds !== void 0 || value.kinds !== void 0, { message: "an event names at least one event, part or kind" });
|
|
46988
|
-
/** An `action` input's value: a vocabulary action and its open args. */
|
|
46989
|
-
var TemplateActionValueSchema = z.object({
|
|
46990
|
-
actionId: z.string().min(1),
|
|
46991
|
-
args: z.record(z.string(), z.unknown()).optional()
|
|
46992
|
-
});
|
|
46993
|
-
/** The value of one non-group input. Which member is right is the input kind's to judge. */
|
|
46994
|
-
var TemplateScalarValueSchema = z.union([
|
|
46995
|
-
z.number(),
|
|
46996
|
-
z.string(),
|
|
46997
|
-
z.boolean(),
|
|
46998
|
-
z.array(z.number().int().nonnegative()),
|
|
46999
|
-
TemplateEventValueSchema,
|
|
47000
|
-
TemplateActionValueSchema
|
|
47001
|
-
]);
|
|
47002
|
-
/** One row of a repeatable group: row-input key → value. */
|
|
47003
|
-
var TemplateGroupRowSchema = z.record(z.string(), TemplateScalarValueSchema);
|
|
47004
|
-
var TemplateInputValueSchema = z.union([TemplateScalarValueSchema, z.array(TemplateGroupRowSchema)]);
|
|
47005
|
-
/** Input key → value. */
|
|
47006
|
-
var TemplateInputValuesSchema = z.record(z.string(), TemplateInputValueSchema);
|
|
47007
|
-
var TemplateInstanceProblemSchema = z.object({
|
|
47008
|
-
code: z.enum([
|
|
47009
|
-
"missing-input",
|
|
47010
|
-
"invalid-input",
|
|
47011
|
-
"invalid-recipe",
|
|
47012
|
-
"missing-template",
|
|
47013
|
-
"edited-by-hand"
|
|
47014
|
-
]),
|
|
47015
|
-
/** Dotted input address (`buttons.2.targets`); absent for a whole-recipe problem. */
|
|
47016
|
-
input: z.string().optional(),
|
|
47017
|
-
detail: z.string()
|
|
47018
|
-
});
|
|
47019
|
-
var AutomationTemplateLinkSchema = z.object({
|
|
47020
|
-
templateId: z.string().min(1),
|
|
47021
|
-
values: TemplateInputValuesSchema,
|
|
47022
|
-
/**
|
|
47023
|
-
* Fingerprint of the generated code with this literal blanked
|
|
47024
|
-
* (`instanceCodeHash`), stamped by `generateAutomationBlock`. Code that no
|
|
47025
|
-
* longer matches it was edited by hand, and is never regenerated over.
|
|
47026
|
-
*/
|
|
47027
|
-
codeHash: z.string().optional(),
|
|
47028
|
-
/**
|
|
47029
|
-
* Present when the last re-expansion refused these values. The automation
|
|
47030
|
-
* keeps running the body of its last good expansion; nothing is dropped.
|
|
47031
|
-
*/
|
|
47032
|
-
problems: z.array(TemplateInstanceProblemSchema).min(1).optional()
|
|
47033
|
-
});
|
|
47034
|
-
/**
|
|
47035
46981
|
* What an expression's named bindings READ from.
|
|
47036
46982
|
*
|
|
47037
46983
|
* Salvaged verbatim from the deleted device-link mechanism. Wiring's source
|
|
@@ -47096,6 +47042,289 @@ z.object({
|
|
|
47096
47042
|
path: ["expr"]
|
|
47097
47043
|
});
|
|
47098
47044
|
});
|
|
47045
|
+
/**
|
|
47046
|
+
* Where the sun is, from a latitude and a longitude — the one solar
|
|
47047
|
+
* calculation in the repo. Compact NOAA sunrise equation (accurate to about a
|
|
47048
|
+
* minute away from the poles), so no astronomy dependency is needed.
|
|
47049
|
+
*
|
|
47050
|
+
* Two consumers read it: the scene-condition resolver (day / night / dawn /
|
|
47051
|
+
* dusk of a camera) and a schedule's sun time (`time-spec.ts`).
|
|
47052
|
+
*/
|
|
47053
|
+
var DEG = Math.PI / 180;
|
|
47054
|
+
/** The sun's upper limb on the horizon, refraction included: sunrise and sunset. */
|
|
47055
|
+
var SUNRISE_ALTITUDE_DEG = -.833;
|
|
47056
|
+
/** Julian day number for a JS Date (UTC). */
|
|
47057
|
+
function toJulian(date) {
|
|
47058
|
+
return date.getTime() / 864e5 + 2440587.5;
|
|
47059
|
+
}
|
|
47060
|
+
/** Julian day → epoch ms (UTC). */
|
|
47061
|
+
function fromJulian(j) {
|
|
47062
|
+
return (j - 2440587.5) * 864e5;
|
|
47063
|
+
}
|
|
47064
|
+
/**
|
|
47065
|
+
* When the sun crosses `altitudeDeg` on the day `date` falls in at this place.
|
|
47066
|
+
* Pass an instant near local midday of the civil day you mean: the day is
|
|
47067
|
+
* chosen from the instant, and midday is the one that never straddles two.
|
|
47068
|
+
*
|
|
47069
|
+
* `null` when the sun never crosses that altitude that day (polar day or polar
|
|
47070
|
+
* night, or — for a twilight altitude — a summer night that never gets dark
|
|
47071
|
+
* enough). The caller decides what that means; nothing here guesses.
|
|
47072
|
+
*/
|
|
47073
|
+
function sunCrossings(lat, lng, date, altitudeDeg) {
|
|
47074
|
+
const jDate = toJulian(date);
|
|
47075
|
+
const jStar = Math.round(jDate - 2451545 + 8e-4) - lng / 360;
|
|
47076
|
+
const m = (357.5291 + .98560028 * jStar) % 360;
|
|
47077
|
+
const mRad = m * DEG;
|
|
47078
|
+
const lambda = (m + (1.9148 * Math.sin(mRad) + .02 * Math.sin(2 * mRad) + 3e-4 * Math.sin(3 * mRad)) + 180 + 102.9372) % 360 * DEG;
|
|
47079
|
+
const jTransit = 2451545 + jStar + .0053 * Math.sin(mRad) - .0069 * Math.sin(2 * lambda);
|
|
47080
|
+
const declination = Math.asin(Math.sin(lambda) * Math.sin(23.44 * DEG));
|
|
47081
|
+
const latRad = lat * DEG;
|
|
47082
|
+
const cosOmega = (Math.sin(altitudeDeg * DEG) - Math.sin(latRad) * Math.sin(declination)) / (Math.cos(latRad) * Math.cos(declination));
|
|
47083
|
+
if (cosOmega > 1 || cosOmega < -1) return null;
|
|
47084
|
+
const omega = Math.acos(cosOmega) / DEG;
|
|
47085
|
+
return {
|
|
47086
|
+
rise: fromJulian(jTransit - omega / 360),
|
|
47087
|
+
set: fromJulian(jTransit + omega / 360)
|
|
47088
|
+
};
|
|
47089
|
+
}
|
|
47090
|
+
/**
|
|
47091
|
+
* WHEN something happens, as data (D983) — the one time vocabulary of the
|
|
47092
|
+
* scheduler and of an automation's schedule leaf. Three shapes, no cron:
|
|
47093
|
+
*
|
|
47094
|
+
* - `clock` — a wall-clock time every day (`07:30`), read in the site's zone;
|
|
47095
|
+
* - `sun` — a sun event (`sunrise`, `sunset`, `dawn`, `dusk`) plus or minus
|
|
47096
|
+
* up to twelve hours, from the site's coordinates;
|
|
47097
|
+
* - `date` — one local date and time (`2026-12-24T18:00`), once.
|
|
47098
|
+
*
|
|
47099
|
+
* A site is a place and its IANA zone ({@link TimeSite}). Every function here
|
|
47100
|
+
* is pure: the zone arithmetic uses `Intl`, no date library.
|
|
47101
|
+
*
|
|
47102
|
+
* Wall-clock honesty across a DST change: a local time that does not exist
|
|
47103
|
+
* (02:30 on the spring-forward day) happens at the first minute that does
|
|
47104
|
+
* (03:00); one that happens twice (02:30 on the fall-back day) happens at its
|
|
47105
|
+
* FIRST occurrence.
|
|
47106
|
+
*/
|
|
47107
|
+
var SunEventSchema = z.enum([
|
|
47108
|
+
"sunrise",
|
|
47109
|
+
"sunset",
|
|
47110
|
+
"dawn",
|
|
47111
|
+
"dusk"
|
|
47112
|
+
]);
|
|
47113
|
+
var LOCAL_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
47114
|
+
var LOCAL_DATE_TIME = /^(\d{4}-\d{2}-\d{2})T([01]\d|2[0-3]):([0-5]\d)$/;
|
|
47115
|
+
var TimeSpecSchema = z.discriminatedUnion("kind", [
|
|
47116
|
+
z.object({
|
|
47117
|
+
kind: z.literal("clock"),
|
|
47118
|
+
hh: z.number().int().min(0).max(23),
|
|
47119
|
+
mm: z.number().int().min(0).max(59)
|
|
47120
|
+
}),
|
|
47121
|
+
z.object({
|
|
47122
|
+
kind: z.literal("sun"),
|
|
47123
|
+
event: SunEventSchema,
|
|
47124
|
+
/** Minutes after the event (negative: before). */
|
|
47125
|
+
offsetMin: z.number().int().min(-720).max(720)
|
|
47126
|
+
}),
|
|
47127
|
+
z.object({
|
|
47128
|
+
kind: z.literal("date"),
|
|
47129
|
+
/** `YYYY-MM-DDTHH:mm`, site-local. */
|
|
47130
|
+
local: z.string().regex(LOCAL_DATE_TIME, "expected YYYY-MM-DDTHH:mm")
|
|
47131
|
+
})
|
|
47132
|
+
]);
|
|
47133
|
+
/** A day of the week as a schedule names it. */
|
|
47134
|
+
var WeekdayKeySchema = z.enum([
|
|
47135
|
+
"mon",
|
|
47136
|
+
"tue",
|
|
47137
|
+
"wed",
|
|
47138
|
+
"thu",
|
|
47139
|
+
"fri",
|
|
47140
|
+
"sat",
|
|
47141
|
+
"sun"
|
|
47142
|
+
]);
|
|
47143
|
+
var WEEKDAY_BY_INDEX = [
|
|
47144
|
+
"sun",
|
|
47145
|
+
"mon",
|
|
47146
|
+
"tue",
|
|
47147
|
+
"wed",
|
|
47148
|
+
"thu",
|
|
47149
|
+
"fri",
|
|
47150
|
+
"sat"
|
|
47151
|
+
];
|
|
47152
|
+
var MINUTE_MS$3 = 6e4;
|
|
47153
|
+
var DAY_MS$1 = 864e5;
|
|
47154
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
47155
|
+
function formatterFor$1(timeZone) {
|
|
47156
|
+
const cached = formatters.get(timeZone);
|
|
47157
|
+
if (cached !== void 0) return cached;
|
|
47158
|
+
const created = new Intl.DateTimeFormat("en-US", {
|
|
47159
|
+
timeZone,
|
|
47160
|
+
hourCycle: "h23",
|
|
47161
|
+
year: "numeric",
|
|
47162
|
+
month: "2-digit",
|
|
47163
|
+
day: "2-digit",
|
|
47164
|
+
hour: "2-digit",
|
|
47165
|
+
minute: "2-digit",
|
|
47166
|
+
second: "2-digit"
|
|
47167
|
+
});
|
|
47168
|
+
formatters.set(timeZone, created);
|
|
47169
|
+
return created;
|
|
47170
|
+
}
|
|
47171
|
+
function wallClockOf(epochMs, timeZone) {
|
|
47172
|
+
const out = {};
|
|
47173
|
+
for (const part of formatterFor$1(timeZone).formatToParts(new Date(epochMs))) if (part.type !== "literal") out[part.type] = Number(part.value);
|
|
47174
|
+
return {
|
|
47175
|
+
year: out["year"] ?? 0,
|
|
47176
|
+
month: out["month"] ?? 0,
|
|
47177
|
+
day: out["day"] ?? 0,
|
|
47178
|
+
hour: out["hour"] ?? 0,
|
|
47179
|
+
minute: out["minute"] ?? 0,
|
|
47180
|
+
second: out["second"] ?? 0
|
|
47181
|
+
};
|
|
47182
|
+
}
|
|
47183
|
+
/** The zone's offset from UTC at an instant, in ms (positive east of Greenwich). */
|
|
47184
|
+
function offsetMs(epochMs, timeZone) {
|
|
47185
|
+
const w = wallClockOf(epochMs, timeZone);
|
|
47186
|
+
return Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute, w.second) - Math.floor(epochMs / 1e3) * 1e3;
|
|
47187
|
+
}
|
|
47188
|
+
/** Is `timeZone` a zone this runtime knows? */
|
|
47189
|
+
function isKnownTimeZone(timeZone) {
|
|
47190
|
+
try {
|
|
47191
|
+
formatterFor$1(timeZone);
|
|
47192
|
+
return true;
|
|
47193
|
+
} catch {
|
|
47194
|
+
return false;
|
|
47195
|
+
}
|
|
47196
|
+
}
|
|
47197
|
+
/** `YYYY-MM-DD` of an instant, read in the zone. */
|
|
47198
|
+
function localDateOf(epochMs, timeZone) {
|
|
47199
|
+
const w = wallClockOf(epochMs, timeZone);
|
|
47200
|
+
return `${String(w.year).padStart(4, "0")}-${String(w.month).padStart(2, "0")}-${String(w.day).padStart(2, "0")}`;
|
|
47201
|
+
}
|
|
47202
|
+
function parseLocalDate(localDate) {
|
|
47203
|
+
if (!LOCAL_DATE.test(localDate)) throw new Error(`not a local date (YYYY-MM-DD): ${localDate}`);
|
|
47204
|
+
const [y, m, d] = localDate.split("-").map(Number);
|
|
47205
|
+
return {
|
|
47206
|
+
y: y ?? 0,
|
|
47207
|
+
m: m ?? 1,
|
|
47208
|
+
d: d ?? 1
|
|
47209
|
+
};
|
|
47210
|
+
}
|
|
47211
|
+
/** The weekday of a `YYYY-MM-DD` civil date (zone-independent). */
|
|
47212
|
+
function weekdayOfLocalDate(localDate) {
|
|
47213
|
+
const { y, m, d } = parseLocalDate(localDate);
|
|
47214
|
+
return WEEKDAY_BY_INDEX[new Date(Date.UTC(y, m - 1, d)).getUTCDay()] ?? "sun";
|
|
47215
|
+
}
|
|
47216
|
+
function addDays$1(localDate, days) {
|
|
47217
|
+
const { y, m, d } = parseLocalDate(localDate);
|
|
47218
|
+
return new Date(Date.UTC(y, m - 1, d + days)).toISOString().slice(0, 10);
|
|
47219
|
+
}
|
|
47220
|
+
/**
|
|
47221
|
+
* The instant a wall-clock time happens in a zone. A time that does not exist
|
|
47222
|
+
* happens at the first minute that does; one that happens twice, at its first
|
|
47223
|
+
* occurrence.
|
|
47224
|
+
*/
|
|
47225
|
+
function wallToEpoch(localDate, hh, mm, timeZone) {
|
|
47226
|
+
const { y, m, d } = parseLocalDate(localDate);
|
|
47227
|
+
const wall = Date.UTC(y, m - 1, d, hh, mm);
|
|
47228
|
+
const before = offsetMs(wall - DAY_MS$1, timeZone);
|
|
47229
|
+
const after = offsetMs(wall + DAY_MS$1, timeZone);
|
|
47230
|
+
const valid = [wall - before, wall - after].filter((c) => c + offsetMs(c, timeZone) === wall);
|
|
47231
|
+
if (valid.length > 0) return Math.min(...valid);
|
|
47232
|
+
let lo = wall - DAY_MS$1;
|
|
47233
|
+
let hi = wall + DAY_MS$1;
|
|
47234
|
+
while (hi - lo > MINUTE_MS$3) {
|
|
47235
|
+
const mid = Math.floor((lo + hi) / 2 / MINUTE_MS$3) * MINUTE_MS$3;
|
|
47236
|
+
if (offsetMs(mid, timeZone) === before) lo = mid;
|
|
47237
|
+
else hi = mid;
|
|
47238
|
+
}
|
|
47239
|
+
return hi;
|
|
47240
|
+
}
|
|
47241
|
+
function sunEventAltitude(event) {
|
|
47242
|
+
return event === "sunrise" || event === "sunset" ? SUNRISE_ALTITUDE_DEG : -6;
|
|
47243
|
+
}
|
|
47244
|
+
/**
|
|
47245
|
+
* The moment `spec` happens on the site-local date `localDate` (`YYYY-MM-DD`).
|
|
47246
|
+
* See {@link Occurrence} for what `null` means.
|
|
47247
|
+
*/
|
|
47248
|
+
function occurrenceOn(spec, localDate, site) {
|
|
47249
|
+
switch (spec.kind) {
|
|
47250
|
+
case "clock": return wallToEpoch(localDate, spec.hh, spec.mm, site.timeZone);
|
|
47251
|
+
case "date": {
|
|
47252
|
+
const match = LOCAL_DATE_TIME.exec(spec.local);
|
|
47253
|
+
if (match === null || match[1] !== localDate) return null;
|
|
47254
|
+
return wallToEpoch(localDate, Number(match[2]), Number(match[3]), site.timeZone);
|
|
47255
|
+
}
|
|
47256
|
+
case "sun": {
|
|
47257
|
+
const midday = new Date(wallToEpoch(localDate, 12, 0, site.timeZone));
|
|
47258
|
+
const crossings = sunCrossings(site.lat, site.lon, midday, sunEventAltitude(spec.event));
|
|
47259
|
+
if (crossings === null) return null;
|
|
47260
|
+
return (spec.event === "sunrise" || spec.event === "dawn" ? crossings.rise : crossings.set) + spec.offsetMin * MINUTE_MS$3;
|
|
47261
|
+
}
|
|
47262
|
+
}
|
|
47263
|
+
}
|
|
47264
|
+
/**
|
|
47265
|
+
* The first moment strictly after `afterMs` at which `spec` happens, or `null`
|
|
47266
|
+
* when none does within {@link NEXT_OCCURRENCE_HORIZON_DAYS} (a `date` spec in
|
|
47267
|
+
* the past, a sun event that never happens, an empty `days` list).
|
|
47268
|
+
*/
|
|
47269
|
+
function nextOccurrence(spec, afterMs, site, options = {}) {
|
|
47270
|
+
const days = options.days;
|
|
47271
|
+
if (days !== void 0 && days.length === 0) return null;
|
|
47272
|
+
if (spec.kind === "date") {
|
|
47273
|
+
const own = LOCAL_DATE_TIME.exec(spec.local)?.[1];
|
|
47274
|
+
if (own === void 0 || days !== void 0 && !days.includes(weekdayOfLocalDate(own))) return null;
|
|
47275
|
+
const at = occurrenceOn(spec, own, site);
|
|
47276
|
+
return at !== null && at > afterMs ? at : null;
|
|
47277
|
+
}
|
|
47278
|
+
const first = addDays$1(localDateOf(afterMs, site.timeZone), -1);
|
|
47279
|
+
for (let i = 0; i < 400; i += 1) {
|
|
47280
|
+
const localDate = addDays$1(first, i);
|
|
47281
|
+
if (days !== void 0 && !days.includes(weekdayOfLocalDate(localDate))) continue;
|
|
47282
|
+
const at = occurrenceOn(spec, localDate, site);
|
|
47283
|
+
if (at !== null && at > afterMs) return at;
|
|
47284
|
+
}
|
|
47285
|
+
return null;
|
|
47286
|
+
}
|
|
47287
|
+
/**
|
|
47288
|
+
* Can `spec` be scheduled at this site? A sun spec without a location is
|
|
47289
|
+
* REFUSED with its reason — never read as a guessed sunrise. A clock or date
|
|
47290
|
+
* spec needs only a zone, and `site` is `null` in that case when there is no
|
|
47291
|
+
* location (it is not needed to place them; use {@link siteFor} to read them).
|
|
47292
|
+
*/
|
|
47293
|
+
function validateTimeSpecForSite(spec, reading) {
|
|
47294
|
+
if (!isKnownTimeZone(reading.timeZone)) return {
|
|
47295
|
+
ok: false,
|
|
47296
|
+
reason: "unknown-time-zone",
|
|
47297
|
+
message: `the site time zone "${reading.timeZone}" is not a known IANA zone`
|
|
47298
|
+
};
|
|
47299
|
+
const site = siteFor(reading);
|
|
47300
|
+
if (spec.kind === "sun" && site === null) return {
|
|
47301
|
+
ok: false,
|
|
47302
|
+
reason: "sun-needs-site-location",
|
|
47303
|
+
message: `a ${spec.event} time needs the site location, and none is set — set it in Settings, or use a clock time`
|
|
47304
|
+
};
|
|
47305
|
+
return {
|
|
47306
|
+
ok: true,
|
|
47307
|
+
site
|
|
47308
|
+
};
|
|
47309
|
+
}
|
|
47310
|
+
/** The site, when it has a location; a clock spec on a site without one uses {@link zoneOnlySite}. */
|
|
47311
|
+
function siteFor(reading) {
|
|
47312
|
+
if (reading.location === null) return null;
|
|
47313
|
+
return {
|
|
47314
|
+
lat: reading.location.latitude,
|
|
47315
|
+
lon: reading.location.longitude,
|
|
47316
|
+
timeZone: reading.timeZone
|
|
47317
|
+
};
|
|
47318
|
+
}
|
|
47319
|
+
/** A site that can place a clock or date spec but no sun event (coordinates are unused by those). */
|
|
47320
|
+
function zoneOnlySite(timeZone) {
|
|
47321
|
+
return {
|
|
47322
|
+
lat: 0,
|
|
47323
|
+
lon: 0,
|
|
47324
|
+
timeZone,
|
|
47325
|
+
zoneOnly: true
|
|
47326
|
+
};
|
|
47327
|
+
}
|
|
47099
47328
|
/** Unwrap ZodNullable / ZodOptional / ZodDefault wrappers to reach the inner type.
|
|
47100
47329
|
* Zod v4 exposes `.unwrap()` on all three wrapper classes. */
|
|
47101
47330
|
function unwrapSchema(schema) {
|
|
@@ -47690,289 +47919,6 @@ function anySubjectMatches(subjects, observed) {
|
|
|
47690
47919
|
};
|
|
47691
47920
|
}
|
|
47692
47921
|
/**
|
|
47693
|
-
* Where the sun is, from a latitude and a longitude — the one solar
|
|
47694
|
-
* calculation in the repo. Compact NOAA sunrise equation (accurate to about a
|
|
47695
|
-
* minute away from the poles), so no astronomy dependency is needed.
|
|
47696
|
-
*
|
|
47697
|
-
* Two consumers read it: the scene-condition resolver (day / night / dawn /
|
|
47698
|
-
* dusk of a camera) and a schedule's sun time (`time-spec.ts`).
|
|
47699
|
-
*/
|
|
47700
|
-
var DEG = Math.PI / 180;
|
|
47701
|
-
/** The sun's upper limb on the horizon, refraction included: sunrise and sunset. */
|
|
47702
|
-
var SUNRISE_ALTITUDE_DEG = -.833;
|
|
47703
|
-
/** Julian day number for a JS Date (UTC). */
|
|
47704
|
-
function toJulian(date) {
|
|
47705
|
-
return date.getTime() / 864e5 + 2440587.5;
|
|
47706
|
-
}
|
|
47707
|
-
/** Julian day → epoch ms (UTC). */
|
|
47708
|
-
function fromJulian(j) {
|
|
47709
|
-
return (j - 2440587.5) * 864e5;
|
|
47710
|
-
}
|
|
47711
|
-
/**
|
|
47712
|
-
* When the sun crosses `altitudeDeg` on the day `date` falls in at this place.
|
|
47713
|
-
* Pass an instant near local midday of the civil day you mean: the day is
|
|
47714
|
-
* chosen from the instant, and midday is the one that never straddles two.
|
|
47715
|
-
*
|
|
47716
|
-
* `null` when the sun never crosses that altitude that day (polar day or polar
|
|
47717
|
-
* night, or — for a twilight altitude — a summer night that never gets dark
|
|
47718
|
-
* enough). The caller decides what that means; nothing here guesses.
|
|
47719
|
-
*/
|
|
47720
|
-
function sunCrossings(lat, lng, date, altitudeDeg) {
|
|
47721
|
-
const jDate = toJulian(date);
|
|
47722
|
-
const jStar = Math.round(jDate - 2451545 + 8e-4) - lng / 360;
|
|
47723
|
-
const m = (357.5291 + .98560028 * jStar) % 360;
|
|
47724
|
-
const mRad = m * DEG;
|
|
47725
|
-
const lambda = (m + (1.9148 * Math.sin(mRad) + .02 * Math.sin(2 * mRad) + 3e-4 * Math.sin(3 * mRad)) + 180 + 102.9372) % 360 * DEG;
|
|
47726
|
-
const jTransit = 2451545 + jStar + .0053 * Math.sin(mRad) - .0069 * Math.sin(2 * lambda);
|
|
47727
|
-
const declination = Math.asin(Math.sin(lambda) * Math.sin(23.44 * DEG));
|
|
47728
|
-
const latRad = lat * DEG;
|
|
47729
|
-
const cosOmega = (Math.sin(altitudeDeg * DEG) - Math.sin(latRad) * Math.sin(declination)) / (Math.cos(latRad) * Math.cos(declination));
|
|
47730
|
-
if (cosOmega > 1 || cosOmega < -1) return null;
|
|
47731
|
-
const omega = Math.acos(cosOmega) / DEG;
|
|
47732
|
-
return {
|
|
47733
|
-
rise: fromJulian(jTransit - omega / 360),
|
|
47734
|
-
set: fromJulian(jTransit + omega / 360)
|
|
47735
|
-
};
|
|
47736
|
-
}
|
|
47737
|
-
/**
|
|
47738
|
-
* WHEN something happens, as data (D983) — the one time vocabulary of the
|
|
47739
|
-
* scheduler and of an automation's schedule leaf. Three shapes, no cron:
|
|
47740
|
-
*
|
|
47741
|
-
* - `clock` — a wall-clock time every day (`07:30`), read in the site's zone;
|
|
47742
|
-
* - `sun` — a sun event (`sunrise`, `sunset`, `dawn`, `dusk`) plus or minus
|
|
47743
|
-
* up to twelve hours, from the site's coordinates;
|
|
47744
|
-
* - `date` — one local date and time (`2026-12-24T18:00`), once.
|
|
47745
|
-
*
|
|
47746
|
-
* A site is a place and its IANA zone ({@link TimeSite}). Every function here
|
|
47747
|
-
* is pure: the zone arithmetic uses `Intl`, no date library.
|
|
47748
|
-
*
|
|
47749
|
-
* Wall-clock honesty across a DST change: a local time that does not exist
|
|
47750
|
-
* (02:30 on the spring-forward day) happens at the first minute that does
|
|
47751
|
-
* (03:00); one that happens twice (02:30 on the fall-back day) happens at its
|
|
47752
|
-
* FIRST occurrence.
|
|
47753
|
-
*/
|
|
47754
|
-
var SunEventSchema = z.enum([
|
|
47755
|
-
"sunrise",
|
|
47756
|
-
"sunset",
|
|
47757
|
-
"dawn",
|
|
47758
|
-
"dusk"
|
|
47759
|
-
]);
|
|
47760
|
-
var LOCAL_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
47761
|
-
var LOCAL_DATE_TIME = /^(\d{4}-\d{2}-\d{2})T([01]\d|2[0-3]):([0-5]\d)$/;
|
|
47762
|
-
var TimeSpecSchema = z.discriminatedUnion("kind", [
|
|
47763
|
-
z.object({
|
|
47764
|
-
kind: z.literal("clock"),
|
|
47765
|
-
hh: z.number().int().min(0).max(23),
|
|
47766
|
-
mm: z.number().int().min(0).max(59)
|
|
47767
|
-
}),
|
|
47768
|
-
z.object({
|
|
47769
|
-
kind: z.literal("sun"),
|
|
47770
|
-
event: SunEventSchema,
|
|
47771
|
-
/** Minutes after the event (negative: before). */
|
|
47772
|
-
offsetMin: z.number().int().min(-720).max(720)
|
|
47773
|
-
}),
|
|
47774
|
-
z.object({
|
|
47775
|
-
kind: z.literal("date"),
|
|
47776
|
-
/** `YYYY-MM-DDTHH:mm`, site-local. */
|
|
47777
|
-
local: z.string().regex(LOCAL_DATE_TIME, "expected YYYY-MM-DDTHH:mm")
|
|
47778
|
-
})
|
|
47779
|
-
]);
|
|
47780
|
-
/** A day of the week as a schedule names it. */
|
|
47781
|
-
var WeekdayKeySchema = z.enum([
|
|
47782
|
-
"mon",
|
|
47783
|
-
"tue",
|
|
47784
|
-
"wed",
|
|
47785
|
-
"thu",
|
|
47786
|
-
"fri",
|
|
47787
|
-
"sat",
|
|
47788
|
-
"sun"
|
|
47789
|
-
]);
|
|
47790
|
-
var WEEKDAY_BY_INDEX = [
|
|
47791
|
-
"sun",
|
|
47792
|
-
"mon",
|
|
47793
|
-
"tue",
|
|
47794
|
-
"wed",
|
|
47795
|
-
"thu",
|
|
47796
|
-
"fri",
|
|
47797
|
-
"sat"
|
|
47798
|
-
];
|
|
47799
|
-
var MINUTE_MS$3 = 6e4;
|
|
47800
|
-
var DAY_MS$1 = 864e5;
|
|
47801
|
-
var formatters = /* @__PURE__ */ new Map();
|
|
47802
|
-
function formatterFor$1(timeZone) {
|
|
47803
|
-
const cached = formatters.get(timeZone);
|
|
47804
|
-
if (cached !== void 0) return cached;
|
|
47805
|
-
const created = new Intl.DateTimeFormat("en-US", {
|
|
47806
|
-
timeZone,
|
|
47807
|
-
hourCycle: "h23",
|
|
47808
|
-
year: "numeric",
|
|
47809
|
-
month: "2-digit",
|
|
47810
|
-
day: "2-digit",
|
|
47811
|
-
hour: "2-digit",
|
|
47812
|
-
minute: "2-digit",
|
|
47813
|
-
second: "2-digit"
|
|
47814
|
-
});
|
|
47815
|
-
formatters.set(timeZone, created);
|
|
47816
|
-
return created;
|
|
47817
|
-
}
|
|
47818
|
-
function wallClockOf(epochMs, timeZone) {
|
|
47819
|
-
const out = {};
|
|
47820
|
-
for (const part of formatterFor$1(timeZone).formatToParts(new Date(epochMs))) if (part.type !== "literal") out[part.type] = Number(part.value);
|
|
47821
|
-
return {
|
|
47822
|
-
year: out["year"] ?? 0,
|
|
47823
|
-
month: out["month"] ?? 0,
|
|
47824
|
-
day: out["day"] ?? 0,
|
|
47825
|
-
hour: out["hour"] ?? 0,
|
|
47826
|
-
minute: out["minute"] ?? 0,
|
|
47827
|
-
second: out["second"] ?? 0
|
|
47828
|
-
};
|
|
47829
|
-
}
|
|
47830
|
-
/** The zone's offset from UTC at an instant, in ms (positive east of Greenwich). */
|
|
47831
|
-
function offsetMs(epochMs, timeZone) {
|
|
47832
|
-
const w = wallClockOf(epochMs, timeZone);
|
|
47833
|
-
return Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute, w.second) - Math.floor(epochMs / 1e3) * 1e3;
|
|
47834
|
-
}
|
|
47835
|
-
/** Is `timeZone` a zone this runtime knows? */
|
|
47836
|
-
function isKnownTimeZone(timeZone) {
|
|
47837
|
-
try {
|
|
47838
|
-
formatterFor$1(timeZone);
|
|
47839
|
-
return true;
|
|
47840
|
-
} catch {
|
|
47841
|
-
return false;
|
|
47842
|
-
}
|
|
47843
|
-
}
|
|
47844
|
-
/** `YYYY-MM-DD` of an instant, read in the zone. */
|
|
47845
|
-
function localDateOf(epochMs, timeZone) {
|
|
47846
|
-
const w = wallClockOf(epochMs, timeZone);
|
|
47847
|
-
return `${String(w.year).padStart(4, "0")}-${String(w.month).padStart(2, "0")}-${String(w.day).padStart(2, "0")}`;
|
|
47848
|
-
}
|
|
47849
|
-
function parseLocalDate(localDate) {
|
|
47850
|
-
if (!LOCAL_DATE.test(localDate)) throw new Error(`not a local date (YYYY-MM-DD): ${localDate}`);
|
|
47851
|
-
const [y, m, d] = localDate.split("-").map(Number);
|
|
47852
|
-
return {
|
|
47853
|
-
y: y ?? 0,
|
|
47854
|
-
m: m ?? 1,
|
|
47855
|
-
d: d ?? 1
|
|
47856
|
-
};
|
|
47857
|
-
}
|
|
47858
|
-
/** The weekday of a `YYYY-MM-DD` civil date (zone-independent). */
|
|
47859
|
-
function weekdayOfLocalDate(localDate) {
|
|
47860
|
-
const { y, m, d } = parseLocalDate(localDate);
|
|
47861
|
-
return WEEKDAY_BY_INDEX[new Date(Date.UTC(y, m - 1, d)).getUTCDay()] ?? "sun";
|
|
47862
|
-
}
|
|
47863
|
-
function addDays$1(localDate, days) {
|
|
47864
|
-
const { y, m, d } = parseLocalDate(localDate);
|
|
47865
|
-
return new Date(Date.UTC(y, m - 1, d + days)).toISOString().slice(0, 10);
|
|
47866
|
-
}
|
|
47867
|
-
/**
|
|
47868
|
-
* The instant a wall-clock time happens in a zone. A time that does not exist
|
|
47869
|
-
* happens at the first minute that does; one that happens twice, at its first
|
|
47870
|
-
* occurrence.
|
|
47871
|
-
*/
|
|
47872
|
-
function wallToEpoch(localDate, hh, mm, timeZone) {
|
|
47873
|
-
const { y, m, d } = parseLocalDate(localDate);
|
|
47874
|
-
const wall = Date.UTC(y, m - 1, d, hh, mm);
|
|
47875
|
-
const before = offsetMs(wall - DAY_MS$1, timeZone);
|
|
47876
|
-
const after = offsetMs(wall + DAY_MS$1, timeZone);
|
|
47877
|
-
const valid = [wall - before, wall - after].filter((c) => c + offsetMs(c, timeZone) === wall);
|
|
47878
|
-
if (valid.length > 0) return Math.min(...valid);
|
|
47879
|
-
let lo = wall - DAY_MS$1;
|
|
47880
|
-
let hi = wall + DAY_MS$1;
|
|
47881
|
-
while (hi - lo > MINUTE_MS$3) {
|
|
47882
|
-
const mid = Math.floor((lo + hi) / 2 / MINUTE_MS$3) * MINUTE_MS$3;
|
|
47883
|
-
if (offsetMs(mid, timeZone) === before) lo = mid;
|
|
47884
|
-
else hi = mid;
|
|
47885
|
-
}
|
|
47886
|
-
return hi;
|
|
47887
|
-
}
|
|
47888
|
-
function sunEventAltitude(event) {
|
|
47889
|
-
return event === "sunrise" || event === "sunset" ? SUNRISE_ALTITUDE_DEG : -6;
|
|
47890
|
-
}
|
|
47891
|
-
/**
|
|
47892
|
-
* The moment `spec` happens on the site-local date `localDate` (`YYYY-MM-DD`).
|
|
47893
|
-
* See {@link Occurrence} for what `null` means.
|
|
47894
|
-
*/
|
|
47895
|
-
function occurrenceOn(spec, localDate, site) {
|
|
47896
|
-
switch (spec.kind) {
|
|
47897
|
-
case "clock": return wallToEpoch(localDate, spec.hh, spec.mm, site.timeZone);
|
|
47898
|
-
case "date": {
|
|
47899
|
-
const match = LOCAL_DATE_TIME.exec(spec.local);
|
|
47900
|
-
if (match === null || match[1] !== localDate) return null;
|
|
47901
|
-
return wallToEpoch(localDate, Number(match[2]), Number(match[3]), site.timeZone);
|
|
47902
|
-
}
|
|
47903
|
-
case "sun": {
|
|
47904
|
-
const midday = new Date(wallToEpoch(localDate, 12, 0, site.timeZone));
|
|
47905
|
-
const crossings = sunCrossings(site.lat, site.lon, midday, sunEventAltitude(spec.event));
|
|
47906
|
-
if (crossings === null) return null;
|
|
47907
|
-
return (spec.event === "sunrise" || spec.event === "dawn" ? crossings.rise : crossings.set) + spec.offsetMin * MINUTE_MS$3;
|
|
47908
|
-
}
|
|
47909
|
-
}
|
|
47910
|
-
}
|
|
47911
|
-
/**
|
|
47912
|
-
* The first moment strictly after `afterMs` at which `spec` happens, or `null`
|
|
47913
|
-
* when none does within {@link NEXT_OCCURRENCE_HORIZON_DAYS} (a `date` spec in
|
|
47914
|
-
* the past, a sun event that never happens, an empty `days` list).
|
|
47915
|
-
*/
|
|
47916
|
-
function nextOccurrence(spec, afterMs, site, options = {}) {
|
|
47917
|
-
const days = options.days;
|
|
47918
|
-
if (days !== void 0 && days.length === 0) return null;
|
|
47919
|
-
if (spec.kind === "date") {
|
|
47920
|
-
const own = LOCAL_DATE_TIME.exec(spec.local)?.[1];
|
|
47921
|
-
if (own === void 0 || days !== void 0 && !days.includes(weekdayOfLocalDate(own))) return null;
|
|
47922
|
-
const at = occurrenceOn(spec, own, site);
|
|
47923
|
-
return at !== null && at > afterMs ? at : null;
|
|
47924
|
-
}
|
|
47925
|
-
const first = addDays$1(localDateOf(afterMs, site.timeZone), -1);
|
|
47926
|
-
for (let i = 0; i < 400; i += 1) {
|
|
47927
|
-
const localDate = addDays$1(first, i);
|
|
47928
|
-
if (days !== void 0 && !days.includes(weekdayOfLocalDate(localDate))) continue;
|
|
47929
|
-
const at = occurrenceOn(spec, localDate, site);
|
|
47930
|
-
if (at !== null && at > afterMs) return at;
|
|
47931
|
-
}
|
|
47932
|
-
return null;
|
|
47933
|
-
}
|
|
47934
|
-
/**
|
|
47935
|
-
* Can `spec` be scheduled at this site? A sun spec without a location is
|
|
47936
|
-
* REFUSED with its reason — never read as a guessed sunrise. A clock or date
|
|
47937
|
-
* spec needs only a zone, and `site` is `null` in that case when there is no
|
|
47938
|
-
* location (it is not needed to place them; use {@link siteFor} to read them).
|
|
47939
|
-
*/
|
|
47940
|
-
function validateTimeSpecForSite(spec, reading) {
|
|
47941
|
-
if (!isKnownTimeZone(reading.timeZone)) return {
|
|
47942
|
-
ok: false,
|
|
47943
|
-
reason: "unknown-time-zone",
|
|
47944
|
-
message: `the site time zone "${reading.timeZone}" is not a known IANA zone`
|
|
47945
|
-
};
|
|
47946
|
-
const site = siteFor(reading);
|
|
47947
|
-
if (spec.kind === "sun" && site === null) return {
|
|
47948
|
-
ok: false,
|
|
47949
|
-
reason: "sun-needs-site-location",
|
|
47950
|
-
message: `a ${spec.event} time needs the site location, and none is set — set it in Settings, or use a clock time`
|
|
47951
|
-
};
|
|
47952
|
-
return {
|
|
47953
|
-
ok: true,
|
|
47954
|
-
site
|
|
47955
|
-
};
|
|
47956
|
-
}
|
|
47957
|
-
/** The site, when it has a location; a clock spec on a site without one uses {@link zoneOnlySite}. */
|
|
47958
|
-
function siteFor(reading) {
|
|
47959
|
-
if (reading.location === null) return null;
|
|
47960
|
-
return {
|
|
47961
|
-
lat: reading.location.latitude,
|
|
47962
|
-
lon: reading.location.longitude,
|
|
47963
|
-
timeZone: reading.timeZone
|
|
47964
|
-
};
|
|
47965
|
-
}
|
|
47966
|
-
/** A site that can place a clock or date spec but no sun event (coordinates are unused by those). */
|
|
47967
|
-
function zoneOnlySite(timeZone) {
|
|
47968
|
-
return {
|
|
47969
|
-
lat: 0,
|
|
47970
|
-
lon: 0,
|
|
47971
|
-
timeZone,
|
|
47972
|
-
zoneOnly: true
|
|
47973
|
-
};
|
|
47974
|
-
}
|
|
47975
|
-
/**
|
|
47976
47922
|
* Hold semantics — "for N seconds" on a leaf of the `when` tree (#498).
|
|
47977
47923
|
*
|
|
47978
47924
|
* ONE primitive, `for: { ms, mode, tolerance? }`, shared by `device-becomes`,
|
|
@@ -48269,24 +48215,33 @@ var StationaryPresentLeafSchema = z.object({
|
|
|
48269
48215
|
* (`kind: 'date'`) is refused: only a clock time or a sun event makes a window
|
|
48270
48216
|
* that repeats every day.
|
|
48271
48217
|
*/
|
|
48272
|
-
var
|
|
48273
|
-
kind: z.literal("time-is"),
|
|
48218
|
+
var timeIsWindowShape = {
|
|
48274
48219
|
between: z.object({
|
|
48275
48220
|
from: TimeSpecSchema,
|
|
48276
48221
|
to: TimeSpecSchema
|
|
48277
48222
|
}).optional(),
|
|
48278
48223
|
days: z.array(WeekdayKeySchema).min(1).max(7).optional()
|
|
48279
|
-
}
|
|
48280
|
-
|
|
48224
|
+
};
|
|
48225
|
+
function timeIsWindowProblems(window, ctx) {
|
|
48226
|
+
if (window.between === void 0 && window.days === void 0) ctx.addIssue({
|
|
48281
48227
|
code: "custom",
|
|
48282
48228
|
message: "a time-is leaf needs a between window, days, or both"
|
|
48283
48229
|
});
|
|
48284
|
-
for (const end of ["from", "to"]) if (
|
|
48230
|
+
for (const end of ["from", "to"]) if (window.between?.[end].kind === "date") ctx.addIssue({
|
|
48285
48231
|
code: "custom",
|
|
48286
48232
|
message: "a one-date time cannot bound a daily window: use a clock time or a sun event",
|
|
48287
48233
|
path: ["between", end]
|
|
48288
48234
|
});
|
|
48289
|
-
}
|
|
48235
|
+
}
|
|
48236
|
+
/**
|
|
48237
|
+
* What a `time-is` leaf holds beside its kind, judged by the leaf's own rules.
|
|
48238
|
+
* A template's time-window input stores exactly this.
|
|
48239
|
+
*/
|
|
48240
|
+
var TimeIsWindowSchema = z.object(timeIsWindowShape).superRefine(timeIsWindowProblems);
|
|
48241
|
+
var TimeIsLeafSchema = z.object({
|
|
48242
|
+
kind: z.literal("time-is"),
|
|
48243
|
+
...timeIsWindowShape
|
|
48244
|
+
}).superRefine(timeIsWindowProblems);
|
|
48290
48245
|
/**
|
|
48291
48246
|
* True for the run that one of the named event leaves started. It reads the
|
|
48292
48247
|
* run, not a device: in the tree it is judged against the leaf that fired, in
|
|
@@ -48512,6 +48467,89 @@ function validateWhenTree(when) {
|
|
|
48512
48467
|
return null;
|
|
48513
48468
|
}
|
|
48514
48469
|
/**
|
|
48470
|
+
* The link an automation made FROM a template carries (#527): which template,
|
|
48471
|
+
* the values the operator filled in, and — when the template has since changed
|
|
48472
|
+
* so that those values no longer fit — the problems that say why.
|
|
48473
|
+
*
|
|
48474
|
+
* It lives inside the recipe (`AutomationRecipe.template`), so the one row in
|
|
48475
|
+
* `core_blocks` stays the one artefact: there is no second store of instances
|
|
48476
|
+
* to drift from the blocks, and deleting the automation deletes the link.
|
|
48477
|
+
* "Convert to a free automation" is dropping this field.
|
|
48478
|
+
*
|
|
48479
|
+
* This file depends on nothing in `recipe.ts`, so the recipe can embed it and
|
|
48480
|
+
* the template engine (`template/automation-template.ts`) can import both.
|
|
48481
|
+
*/
|
|
48482
|
+
/** An `event` input's value: the same three narrowing lists a `device-fired` row takes. */
|
|
48483
|
+
var TemplateEventValueSchema = z.object({
|
|
48484
|
+
eventIds: z.array(z.string().min(1)).min(1).max(64).optional(),
|
|
48485
|
+
sourceIds: z.array(z.string().min(1)).min(1).max(64).optional(),
|
|
48486
|
+
kinds: z.array(EventVocabularyKindSchema).min(1).optional()
|
|
48487
|
+
}).refine((value) => value.eventIds !== void 0 || value.sourceIds !== void 0 || value.kinds !== void 0, { message: "an event names at least one event, part or kind" });
|
|
48488
|
+
/** An `action` input's value: a vocabulary action and its open args. */
|
|
48489
|
+
var TemplateActionValueSchema = z.object({
|
|
48490
|
+
actionId: z.string().min(1),
|
|
48491
|
+
args: z.record(z.string(), z.unknown()).optional()
|
|
48492
|
+
});
|
|
48493
|
+
/**
|
|
48494
|
+
* A `time-window` input's value: what a `time-is` leaf holds beside its kind.
|
|
48495
|
+
* "No limit" is the input left without a value, never an empty object.
|
|
48496
|
+
*/
|
|
48497
|
+
var TemplateTimeWindowValueSchema = TimeIsWindowSchema;
|
|
48498
|
+
/**
|
|
48499
|
+
* An `entries` input's value: automation elements VERBATIM — event leaves of a
|
|
48500
|
+
* `when` tree, or steps of a branch. Judged with the automation's own schemas
|
|
48501
|
+
* (`valueProblem` in the template engine), so there is no second shape here.
|
|
48502
|
+
*/
|
|
48503
|
+
var TemplateEntrySchema = z.record(z.string(), z.unknown());
|
|
48504
|
+
var TemplateEntriesValueSchema = z.array(TemplateEntrySchema);
|
|
48505
|
+
/** The value of one non-group input. Which member is right is the input kind's to judge. */
|
|
48506
|
+
var TemplateScalarValueSchema = z.union([
|
|
48507
|
+
z.number(),
|
|
48508
|
+
z.string(),
|
|
48509
|
+
z.boolean(),
|
|
48510
|
+
z.array(z.number().int().nonnegative()),
|
|
48511
|
+
TemplateEventValueSchema,
|
|
48512
|
+
TemplateActionValueSchema,
|
|
48513
|
+
TemplateTimeWindowValueSchema,
|
|
48514
|
+
TemplateEntriesValueSchema
|
|
48515
|
+
]);
|
|
48516
|
+
/** One row of a group inside a group row: row-input key → value. */
|
|
48517
|
+
var TemplateNestedRowSchema = z.record(z.string(), TemplateScalarValueSchema);
|
|
48518
|
+
/** What a group row holds under one key: a value, or the rows of a group it nests. */
|
|
48519
|
+
var TemplateRowValueSchema = z.union([TemplateScalarValueSchema, z.array(TemplateNestedRowSchema)]);
|
|
48520
|
+
/** One row of a repeatable group: row-input key → value. */
|
|
48521
|
+
var TemplateGroupRowSchema = z.record(z.string(), TemplateRowValueSchema);
|
|
48522
|
+
var TemplateInputValueSchema = z.union([TemplateScalarValueSchema, z.array(TemplateGroupRowSchema)]);
|
|
48523
|
+
/** Input key → value. */
|
|
48524
|
+
var TemplateInputValuesSchema = z.record(z.string(), TemplateInputValueSchema);
|
|
48525
|
+
var TemplateInstanceProblemSchema = z.object({
|
|
48526
|
+
code: z.enum([
|
|
48527
|
+
"missing-input",
|
|
48528
|
+
"invalid-input",
|
|
48529
|
+
"invalid-recipe",
|
|
48530
|
+
"missing-template",
|
|
48531
|
+
"edited-by-hand"
|
|
48532
|
+
]),
|
|
48533
|
+
/** Dotted input address (`buttons.2.targets`, `buttons.0.commands.1.targets`); absent for a whole-recipe problem. */
|
|
48534
|
+
input: z.string().optional(),
|
|
48535
|
+
detail: z.string()
|
|
48536
|
+
});
|
|
48537
|
+
var AutomationTemplateLinkSchema = z.object({
|
|
48538
|
+
templateId: z.string().min(1),
|
|
48539
|
+
values: TemplateInputValuesSchema,
|
|
48540
|
+
/**
|
|
48541
|
+
* Fingerprint of the generated code with this literal blanked
|
|
48542
|
+
* (`instanceCodeHash`), stamped by `generateAutomationBlock`. Code that no
|
|
48543
|
+
* longer matches it was edited by hand, and is never regenerated over.
|
|
48544
|
+
*/
|
|
48545
|
+
codeHash: z.string().optional(),
|
|
48546
|
+
/**
|
|
48547
|
+
* Present when the last re-expansion refused these values. The automation
|
|
48548
|
+
* keeps running the body of its last good expansion; nothing is dropped.
|
|
48549
|
+
*/
|
|
48550
|
+
problems: z.array(TemplateInstanceProblemSchema).min(1).optional()
|
|
48551
|
+
});
|
|
48552
|
+
/**
|
|
48515
48553
|
* The recipe shape before the single `when` tree: a flat list of triggers
|
|
48516
48554
|
* (OR'd, each an instant) and an optional condition tree. Stored recipes —
|
|
48517
48555
|
* the `AUTOMATION_RECIPE` literal of every block saved so far, and whatever an
|
|
@@ -62091,7 +62129,6 @@ var CAP_CUSTOMIZE_CATALOG = {
|
|
|
62091
62129
|
cardinality: "keyedArray",
|
|
62092
62130
|
deviceTypes: [
|
|
62093
62131
|
DeviceType.Camera,
|
|
62094
|
-
DeviceType.Hub,
|
|
62095
62132
|
DeviceType.Light,
|
|
62096
62133
|
DeviceType.Siren,
|
|
62097
62134
|
DeviceType.Switch,
|
|
@@ -71398,7 +71435,7 @@ var deviceTransitionsCapability = {
|
|
|
71398
71435
|
mode: "singleton",
|
|
71399
71436
|
kind: "wrapper",
|
|
71400
71437
|
defaultActive: true,
|
|
71401
|
-
deviceTypes: Object.values(DeviceType).filter((type) => type !== DeviceType.
|
|
71438
|
+
deviceTypes: Object.values(DeviceType).filter((type) => type !== DeviceType.Container),
|
|
71402
71439
|
methods: {
|
|
71403
71440
|
/**
|
|
71404
71441
|
* Transitions of a device, newest first. `limit` is bounded; page with `cursor`.
|
|
@@ -75678,7 +75715,6 @@ var HeroSceneSchema = z.object({
|
|
|
75678
75715
|
});
|
|
75679
75716
|
var HERO_SCENE_BY_TYPE = {
|
|
75680
75717
|
[DeviceType.Camera]: "camera",
|
|
75681
|
-
[DeviceType.Hub]: "gateway",
|
|
75682
75718
|
[DeviceType.Light]: "light",
|
|
75683
75719
|
[DeviceType.Siren]: "siren",
|
|
75684
75720
|
[DeviceType.Switch]: "plug",
|
|
@@ -81939,7 +81975,9 @@ var migrationsCapability = {
|
|
|
81939
81975
|
*/
|
|
81940
81976
|
declareOwner: method(z.object({
|
|
81941
81977
|
owner: z.string().min(1),
|
|
81942
|
-
metas: z.array(MigrationMetaSchema)
|
|
81978
|
+
metas: z.array(MigrationMetaSchema),
|
|
81979
|
+
/** Ids the owner deliberately removed: an applied row of one is fine, never "newer". */
|
|
81980
|
+
retired: z.array(z.string().min(1)).optional()
|
|
81943
81981
|
}), z.object({
|
|
81944
81982
|
bootId: z.string(),
|
|
81945
81983
|
snapshot: z.enum([
|
|
@@ -105209,7 +105247,26 @@ var BooleanInputSchema = z.object({
|
|
|
105209
105247
|
...inputBase,
|
|
105210
105248
|
default: z.boolean().optional()
|
|
105211
105249
|
});
|
|
105250
|
+
/** A limit on when the automation may run; only a `gate` binding reads it. */
|
|
105251
|
+
var TimeWindowInputSchema = z.object({
|
|
105252
|
+
kind: z.literal("time-window"),
|
|
105253
|
+
...inputBase
|
|
105254
|
+
});
|
|
105255
|
+
/**
|
|
105256
|
+
* A list of automation elements, verbatim: `trigger` entries are event leaves
|
|
105257
|
+
* of a `when` tree (`device-fired`), `step` entries are steps of a branch
|
|
105258
|
+
* (`command`, `wait`). `allow` names the kinds the list takes; each entry is
|
|
105259
|
+
* judged by the automation's own schema, then by `allow`.
|
|
105260
|
+
*/
|
|
105261
|
+
var EntriesInputSchema = z.object({
|
|
105262
|
+
kind: z.literal("entries"),
|
|
105263
|
+
...inputBase,
|
|
105264
|
+
entry: z.enum(["trigger", "step"]),
|
|
105265
|
+
allow: z.array(z.string().min(1)).min(1).max(10),
|
|
105266
|
+
maxItems: z.number().int().min(1).max(20).optional()
|
|
105267
|
+
});
|
|
105212
105268
|
var TemplateScalarInputSchema = z.discriminatedUnion("kind", [
|
|
105269
|
+
EntriesInputSchema,
|
|
105213
105270
|
DeviceInputSchema,
|
|
105214
105271
|
EventInputSchema,
|
|
105215
105272
|
ActionInputSchema$1,
|
|
@@ -105217,14 +105274,26 @@ var TemplateScalarInputSchema = z.discriminatedUnion("kind", [
|
|
|
105217
105274
|
DurationInputSchema,
|
|
105218
105275
|
TextInputSchema,
|
|
105219
105276
|
SelectInputSchema,
|
|
105220
|
-
BooleanInputSchema
|
|
105277
|
+
BooleanInputSchema,
|
|
105278
|
+
TimeWindowInputSchema
|
|
105221
105279
|
]);
|
|
105222
|
-
var
|
|
105280
|
+
var groupBase = {
|
|
105223
105281
|
kind: z.literal("group"),
|
|
105224
105282
|
...inputBase,
|
|
105225
|
-
|
|
105283
|
+
/** What one row is, in the singular and lower case ("button"): "Add button". */
|
|
105284
|
+
rowLabel: z.string().min(1).max(40).optional(),
|
|
105226
105285
|
minRows: z.number().int().min(0).max(20).optional(),
|
|
105227
105286
|
maxRows: z.number().int().min(1).max(20).optional()
|
|
105287
|
+
};
|
|
105288
|
+
/** A group inside a group row: its rows hold values only, never another group. */
|
|
105289
|
+
var NestedGroupInputSchema = z.object({
|
|
105290
|
+
...groupBase,
|
|
105291
|
+
inputs: z.array(TemplateScalarInputSchema).min(1).max(10)
|
|
105292
|
+
});
|
|
105293
|
+
var TemplateRowInputSchema = z.discriminatedUnion("kind", [...TemplateScalarInputSchema.options, NestedGroupInputSchema]);
|
|
105294
|
+
var GroupInputSchema = z.object({
|
|
105295
|
+
...groupBase,
|
|
105296
|
+
inputs: z.array(TemplateRowInputSchema).min(1).max(10)
|
|
105228
105297
|
});
|
|
105229
105298
|
var TemplateInputSchema = z.discriminatedUnion("kind", [...TemplateScalarInputSchema.options, GroupInputSchema]);
|
|
105230
105299
|
var TemplatePathSchema = z.array(z.union([z.string().min(1), z.number().int().nonnegative()])).max(24);
|
|
@@ -105239,39 +105308,160 @@ var TemplateRowIdBindingSchema = z.object({
|
|
|
105239
105308
|
kind: z.literal("row-id"),
|
|
105240
105309
|
path: TemplatePathSchema
|
|
105241
105310
|
});
|
|
105242
|
-
|
|
105311
|
+
/**
|
|
105312
|
+
* Appends an `entries` input's elements, verbatim, to the list at `path`. In a
|
|
105313
|
+
* row's bindings `input` is the row's own entries input and `path` is from the
|
|
105314
|
+
* row's item; at the top level, with `in`, it appends the `input` entries of
|
|
105315
|
+
* EVERY row of the group `in` (all buttons' triggers into one `when`), and
|
|
105316
|
+
* without `in` it appends a top-level entries input.
|
|
105317
|
+
*/
|
|
105318
|
+
var TemplateEntriesBindingSchema = z.object({
|
|
105319
|
+
kind: z.literal("entries"),
|
|
105320
|
+
input: inputKey,
|
|
105321
|
+
path: TemplatePathSchema,
|
|
105322
|
+
in: inputKey.optional()
|
|
105323
|
+
});
|
|
105324
|
+
/** What fills the item of a row that holds values only. */
|
|
105325
|
+
var TemplateLeafRowBindingSchema = z.discriminatedUnion("kind", [TemplateValueBindingSchema, TemplateRowIdBindingSchema]);
|
|
105326
|
+
/** The ids of a row's nested rows, as a list (a branch that reads every leaf of its row). */
|
|
105327
|
+
var TemplateRowIdsBindingSchema = z.object({
|
|
105328
|
+
kind: z.literal("row-ids"),
|
|
105329
|
+
/** The nested group whose rows are named. */
|
|
105330
|
+
input: inputKey,
|
|
105331
|
+
path: TemplatePathSchema
|
|
105332
|
+
});
|
|
105333
|
+
/** One copy of `item` per nested row, appended inside the parent row's item. */
|
|
105334
|
+
var TemplateNestedRowsBindingSchema = z.object({
|
|
105335
|
+
kind: z.literal("rows"),
|
|
105336
|
+
/** The nested group, declared by the parent row's group. */
|
|
105337
|
+
input: inputKey,
|
|
105338
|
+
/** The list the nested rows are appended to, from the parent row's item. */
|
|
105339
|
+
path: TemplatePathSchema,
|
|
105340
|
+
item: z.unknown(),
|
|
105341
|
+
bindings: z.array(TemplateLeafRowBindingSchema).max(40)
|
|
105342
|
+
});
|
|
105343
|
+
var TemplateRowItemBindingSchema = z.discriminatedUnion("kind", [
|
|
105344
|
+
TemplateValueBindingSchema,
|
|
105345
|
+
TemplateEntriesBindingSchema,
|
|
105346
|
+
TemplateRowIdBindingSchema,
|
|
105347
|
+
TemplateRowIdsBindingSchema,
|
|
105348
|
+
TemplateNestedRowsBindingSchema
|
|
105349
|
+
]);
|
|
105243
105350
|
var TemplateRowsBindingSchema = z.object({
|
|
105244
105351
|
kind: z.literal("rows"),
|
|
105245
105352
|
input: inputKey,
|
|
105353
|
+
/**
|
|
105354
|
+
* A group the rows of `input` hold: the binding then appends one item per
|
|
105355
|
+
* NESTED row of every row, and its bindings read the nested row.
|
|
105356
|
+
*/
|
|
105357
|
+
nested: inputKey.optional(),
|
|
105246
105358
|
/** The list in the body the rows are appended to. */
|
|
105247
105359
|
path: TemplatePathSchema,
|
|
105248
105360
|
/** The JSON copied once per row. */
|
|
105249
105361
|
item: z.unknown(),
|
|
105250
105362
|
bindings: z.array(TemplateRowItemBindingSchema).max(40)
|
|
105251
105363
|
});
|
|
105252
|
-
|
|
105253
|
-
|
|
105254
|
-
|
|
105255
|
-
|
|
105256
|
-
|
|
105257
|
-
|
|
105364
|
+
/** Wraps the condition tree at `path` as `all[time-is, <tree>]` when the input has a value. */
|
|
105365
|
+
var TemplateGateBindingSchema = z.object({
|
|
105366
|
+
kind: z.literal("gate"),
|
|
105367
|
+
/** A top-level `time-window` input. */
|
|
105368
|
+
input: inputKey,
|
|
105369
|
+
path: TemplatePathSchema
|
|
105370
|
+
});
|
|
105371
|
+
var TemplateBindingSchema = z.discriminatedUnion("kind", [
|
|
105372
|
+
TemplateValueBindingSchema,
|
|
105373
|
+
TemplateEntriesBindingSchema,
|
|
105374
|
+
TemplateRowsBindingSchema,
|
|
105375
|
+
TemplateGateBindingSchema
|
|
105376
|
+
]);
|
|
105377
|
+
function scalarsOf(inputs) {
|
|
105378
|
+
return inputs.filter((input) => input.kind !== "group");
|
|
105379
|
+
}
|
|
105380
|
+
/** Twice-declared keys and event / action inputs that read no device beside them. */
|
|
105381
|
+
function levelProblems(inputs, path, inRow = false) {
|
|
105382
|
+
const issues = [];
|
|
105383
|
+
const seen = /* @__PURE__ */ new Set();
|
|
105384
|
+
for (const input of inputs) {
|
|
105385
|
+
if (seen.has(input.key)) issues.push({
|
|
105258
105386
|
message: `input "${input.key}" is declared twice`,
|
|
105259
|
-
path
|
|
105387
|
+
path
|
|
105260
105388
|
});
|
|
105261
|
-
|
|
105262
|
-
|
|
105263
|
-
|
|
105264
|
-
|
|
105265
|
-
|
|
105266
|
-
|
|
105267
|
-
|
|
105268
|
-
|
|
105269
|
-
|
|
105270
|
-
|
|
105271
|
-
|
|
105389
|
+
seen.add(input.key);
|
|
105390
|
+
if (input.kind === "group") {
|
|
105391
|
+
issues.push(...levelProblems(input.inputs, path, true));
|
|
105392
|
+
continue;
|
|
105393
|
+
}
|
|
105394
|
+
if (input.kind === "time-window" && inRow) issues.push({
|
|
105395
|
+
message: `time window "${input.key}" limits the whole automation: it is not a row input`,
|
|
105396
|
+
path
|
|
105397
|
+
});
|
|
105398
|
+
if (input.kind !== "event" && input.kind !== "action") continue;
|
|
105399
|
+
if (input.deviceInput === void 0) continue;
|
|
105400
|
+
const device = inputs.find((sibling) => sibling.key === input.deviceInput);
|
|
105401
|
+
if (device === void 0 || device.kind !== "device") issues.push({
|
|
105402
|
+
message: `"${input.key}" reads the device input "${input.deviceInput}", which is not a device input beside it`,
|
|
105403
|
+
path
|
|
105404
|
+
});
|
|
105405
|
+
}
|
|
105406
|
+
return issues;
|
|
105407
|
+
}
|
|
105408
|
+
function nestedGroupOf(group, key) {
|
|
105409
|
+
const found = group.inputs.find((input) => input.key === key);
|
|
105410
|
+
return found !== void 0 && found.kind === "group" ? found : void 0;
|
|
105411
|
+
}
|
|
105412
|
+
function leafBindingProblems(bindings, owner) {
|
|
105413
|
+
const issues = [];
|
|
105414
|
+
for (const row of bindings) {
|
|
105415
|
+
if (row.kind === "row-id") continue;
|
|
105416
|
+
if (row.kind === "value") {
|
|
105417
|
+
const input = owner.inputs.find((i) => i.key === row.input);
|
|
105418
|
+
if (input === void 0) issues.push(`row binding names "${row.input}", which group "${owner.key}" does not declare`);
|
|
105419
|
+
else if (input.kind === "group") issues.push(`group "${input.key}" is bound with rows, not a value`);
|
|
105420
|
+
else if (input.kind === "entries") issues.push(`entries "${input.key}" are bound with entries, not a value`);
|
|
105421
|
+
continue;
|
|
105422
|
+
}
|
|
105423
|
+
const nested = owner.inputs.find((i) => i.key === row.input);
|
|
105424
|
+
if (row.kind === "entries") {
|
|
105425
|
+
if (nested === void 0 || nested.kind !== "entries") issues.push(`"${row.input}" is not an entries input inside "${owner.key}"`);
|
|
105426
|
+
continue;
|
|
105427
|
+
}
|
|
105428
|
+
if (row.kind === "row-ids") {
|
|
105429
|
+
if (nested === void 0 || nested.kind !== "group" && nested.kind !== "entries") issues.push(`"${row.input}" is not a group or entries input inside "${owner.key}"`);
|
|
105430
|
+
continue;
|
|
105431
|
+
}
|
|
105432
|
+
if (nested === void 0 || nested.kind !== "group") {
|
|
105433
|
+
issues.push(`"${row.input}" is not a group inside "${owner.key}"`);
|
|
105434
|
+
continue;
|
|
105272
105435
|
}
|
|
105436
|
+
issues.push(...leafBindingProblems(row.bindings, nested));
|
|
105437
|
+
}
|
|
105438
|
+
return issues;
|
|
105439
|
+
}
|
|
105440
|
+
function rowsBindingProblems(binding, group) {
|
|
105441
|
+
if (binding.nested === void 0) return leafBindingProblems(binding.bindings, group);
|
|
105442
|
+
const nested = nestedGroupOf(group, binding.nested);
|
|
105443
|
+
if (nested === void 0) return [`"${binding.nested}" is not a group inside "${group.key}"`];
|
|
105444
|
+
return leafBindingProblems(binding.bindings, nested);
|
|
105445
|
+
}
|
|
105446
|
+
function bindingProblems(payload, ctx) {
|
|
105447
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
105448
|
+
for (const input of payload.inputs) byKey.set(input.key, input);
|
|
105449
|
+
for (const issue of levelProblems(payload.inputs, ["inputs"])) ctx.addIssue({
|
|
105450
|
+
code: "custom",
|
|
105451
|
+
message: issue.message,
|
|
105452
|
+
path: [...issue.path]
|
|
105273
105453
|
});
|
|
105274
105454
|
payload.bindings.forEach((binding, index) => {
|
|
105455
|
+
if (binding.kind === "entries" && binding.in !== void 0) {
|
|
105456
|
+
const group = byKey.get(binding.in);
|
|
105457
|
+
const entries = group !== void 0 && group.kind === "group" ? group.inputs.find((i) => i.key === binding.input) : void 0;
|
|
105458
|
+
if (entries === void 0 || entries.kind !== "entries") ctx.addIssue({
|
|
105459
|
+
code: "custom",
|
|
105460
|
+
message: `"${binding.input}" is not an entries input inside the group "${binding.in}"`,
|
|
105461
|
+
path: ["bindings", index]
|
|
105462
|
+
});
|
|
105463
|
+
return;
|
|
105464
|
+
}
|
|
105275
105465
|
const input = byKey.get(binding.input);
|
|
105276
105466
|
if (input === void 0) {
|
|
105277
105467
|
ctx.addIssue({
|
|
@@ -105286,6 +105476,18 @@ function bindingProblems(payload, ctx) {
|
|
|
105286
105476
|
message: `group "${input.key}" is bound with rows, not a value`,
|
|
105287
105477
|
path: ["bindings", index]
|
|
105288
105478
|
});
|
|
105479
|
+
if (binding.kind === "entries" !== (input.kind === "entries") && binding.kind !== "rows") {
|
|
105480
|
+
if (binding.kind === "entries" || binding.kind === "value") ctx.addIssue({
|
|
105481
|
+
code: "custom",
|
|
105482
|
+
message: binding.kind === "entries" ? `entries bindings read an entries input: "${input.key}" is ${input.kind}` : `entries "${input.key}" are bound with entries, not a value`,
|
|
105483
|
+
path: ["bindings", index]
|
|
105484
|
+
});
|
|
105485
|
+
}
|
|
105486
|
+
if (binding.kind === "gate" !== (input.kind === "time-window")) ctx.addIssue({
|
|
105487
|
+
code: "custom",
|
|
105488
|
+
message: `a gate reads a time window and a time window is bound with a gate: "${input.key}" is ${input.kind}`,
|
|
105489
|
+
path: ["bindings", index]
|
|
105490
|
+
});
|
|
105289
105491
|
if (binding.kind === "rows") {
|
|
105290
105492
|
if (input.kind !== "group") {
|
|
105291
105493
|
ctx.addIssue({
|
|
@@ -105295,9 +105497,9 @@ function bindingProblems(payload, ctx) {
|
|
|
105295
105497
|
});
|
|
105296
105498
|
return;
|
|
105297
105499
|
}
|
|
105298
|
-
for (const
|
|
105500
|
+
for (const message of rowsBindingProblems(binding, input)) ctx.addIssue({
|
|
105299
105501
|
code: "custom",
|
|
105300
|
-
message
|
|
105502
|
+
message,
|
|
105301
105503
|
path: ["bindings", index]
|
|
105302
105504
|
});
|
|
105303
105505
|
}
|
|
@@ -105333,7 +105535,25 @@ function valueProblem(input, value) {
|
|
|
105333
105535
|
return input.maxLength !== void 0 && value.length > input.maxLength ? `at most ${input.maxLength} characters` : null;
|
|
105334
105536
|
case "select": return typeof value === "string" && input.options.some((o) => o.value === value) ? null : "pick one of the options";
|
|
105335
105537
|
case "boolean": return typeof value === "boolean" ? null : "on or off";
|
|
105538
|
+
case "time-window": {
|
|
105539
|
+
const parsed = TemplateTimeWindowValueSchema.safeParse(value);
|
|
105540
|
+
return parsed.success ? null : parsed.error.issues[0]?.message ?? "pick a time window";
|
|
105541
|
+
}
|
|
105542
|
+
case "entries": return entriesProblem(input, value);
|
|
105543
|
+
}
|
|
105544
|
+
}
|
|
105545
|
+
/** Each entry is judged by the automation's own schema, then by the kinds the input allows. */
|
|
105546
|
+
function entriesProblem(input, value) {
|
|
105547
|
+
const list = TemplateEntriesValueSchema.safeParse(value);
|
|
105548
|
+
if (!list.success) return "a list of entries is required";
|
|
105549
|
+
if (list.data.length === 0) return "add at least one";
|
|
105550
|
+
if (input.maxItems !== void 0 && list.data.length > input.maxItems) return `at most ${input.maxItems}`;
|
|
105551
|
+
for (const entry of list.data) {
|
|
105552
|
+
const parsed = input.entry === "trigger" ? AutomationWhenSchema.safeParse(entry) : AutomationBranchStepSchema.safeParse(entry);
|
|
105553
|
+
if (!parsed.success) return parsed.error.issues[0]?.message ?? "an entry is not valid";
|
|
105554
|
+
if (!input.allow.includes(parsed.data.kind)) return `"${parsed.data.kind}" is not allowed here`;
|
|
105336
105555
|
}
|
|
105556
|
+
return null;
|
|
105337
105557
|
}
|
|
105338
105558
|
function defaultOf(input) {
|
|
105339
105559
|
switch (input.kind) {
|
|
@@ -105364,52 +105584,59 @@ function resolveScalars(inputs, values, prefix, problems) {
|
|
|
105364
105584
|
});
|
|
105365
105585
|
continue;
|
|
105366
105586
|
}
|
|
105367
|
-
const problem = isScalar(raw) ? valueProblem(input, raw) : "a single value is required";
|
|
105368
|
-
if (problem !== null
|
|
105587
|
+
const problem = input.kind === "entries" || isScalar(raw) ? valueProblem(input, raw) : "a single value is required";
|
|
105588
|
+
if (problem !== null) {
|
|
105369
105589
|
problems.push({
|
|
105370
105590
|
code: "invalid-input",
|
|
105371
105591
|
input: address,
|
|
105372
|
-
detail: problem
|
|
105592
|
+
detail: problem
|
|
105373
105593
|
});
|
|
105374
105594
|
continue;
|
|
105375
105595
|
}
|
|
105376
|
-
out.set(input.key, raw);
|
|
105596
|
+
if (input.kind === "entries") out.set(input.key, TemplateEntriesValueSchema.parse(raw));
|
|
105597
|
+
else if (isScalar(raw)) out.set(input.key, raw);
|
|
105377
105598
|
}
|
|
105378
105599
|
return out;
|
|
105379
105600
|
}
|
|
105380
|
-
|
|
105381
|
-
|
|
105601
|
+
/** The rows of one group, each resolved; `null` when the list itself is refused. */
|
|
105602
|
+
function resolveRows(group, values, prefix, problems) {
|
|
105603
|
+
const address = `${prefix}${group.key}`;
|
|
105604
|
+
const raw = values[group.key] ?? [];
|
|
105605
|
+
if (!isRowList(raw)) {
|
|
105606
|
+
problems.push({
|
|
105607
|
+
code: "invalid-input",
|
|
105608
|
+
input: address,
|
|
105609
|
+
detail: "a list of rows is required"
|
|
105610
|
+
});
|
|
105611
|
+
return null;
|
|
105612
|
+
}
|
|
105613
|
+
const min = group.minRows ?? (group.optional === true ? 0 : 1);
|
|
105614
|
+
const max = group.maxRows ?? 20;
|
|
105615
|
+
if (raw.length < min) {
|
|
105616
|
+
problems.push({
|
|
105617
|
+
code: raw.length === 0 ? "missing-input" : "invalid-input",
|
|
105618
|
+
input: address,
|
|
105619
|
+
detail: `"${group.label}" needs at least ${min} row(s)`
|
|
105620
|
+
});
|
|
105621
|
+
return null;
|
|
105622
|
+
}
|
|
105623
|
+
if (raw.length > max) {
|
|
105624
|
+
problems.push({
|
|
105625
|
+
code: "invalid-input",
|
|
105626
|
+
input: address,
|
|
105627
|
+
detail: `"${group.label}" takes at most ${max} row(s)`
|
|
105628
|
+
});
|
|
105629
|
+
return null;
|
|
105630
|
+
}
|
|
105631
|
+
return raw.map((row, index) => resolveLevel$1(group.inputs, row, `${address}.${index}.`, problems));
|
|
105632
|
+
}
|
|
105633
|
+
function resolveLevel$1(inputs, values, prefix, problems) {
|
|
105634
|
+
const scalars = resolveScalars(scalarsOf(inputs), values, prefix, problems);
|
|
105382
105635
|
const groups = /* @__PURE__ */ new Map();
|
|
105383
|
-
for (const input of
|
|
105636
|
+
for (const input of inputs) {
|
|
105384
105637
|
if (input.kind !== "group") continue;
|
|
105385
|
-
const
|
|
105386
|
-
if (
|
|
105387
|
-
problems.push({
|
|
105388
|
-
code: "invalid-input",
|
|
105389
|
-
input: input.key,
|
|
105390
|
-
detail: "a list of rows is required"
|
|
105391
|
-
});
|
|
105392
|
-
continue;
|
|
105393
|
-
}
|
|
105394
|
-
const min = input.minRows ?? (input.optional === true ? 0 : 1);
|
|
105395
|
-
const max = input.maxRows ?? 20;
|
|
105396
|
-
if (raw.length < min) {
|
|
105397
|
-
problems.push({
|
|
105398
|
-
code: raw.length === 0 ? "missing-input" : "invalid-input",
|
|
105399
|
-
input: input.key,
|
|
105400
|
-
detail: `"${input.label}" needs at least ${min} row(s)`
|
|
105401
|
-
});
|
|
105402
|
-
continue;
|
|
105403
|
-
}
|
|
105404
|
-
if (raw.length > max) {
|
|
105405
|
-
problems.push({
|
|
105406
|
-
code: "invalid-input",
|
|
105407
|
-
input: input.key,
|
|
105408
|
-
detail: `"${input.label}" takes at most ${max} row(s)`
|
|
105409
|
-
});
|
|
105410
|
-
continue;
|
|
105411
|
-
}
|
|
105412
|
-
groups.set(input.key, raw.map((row, index) => resolveScalars(input.inputs, row, `${input.key}.${index}.`, problems)));
|
|
105638
|
+
const rows = resolveRows(input, values, prefix, problems);
|
|
105639
|
+
if (rows !== null) groups.set(input.key, rows);
|
|
105413
105640
|
}
|
|
105414
105641
|
return {
|
|
105415
105642
|
scalars,
|
|
@@ -105477,30 +105704,100 @@ function writeValue(root, binding, input, value) {
|
|
|
105477
105704
|
default: return setAt(root, binding.path, value);
|
|
105478
105705
|
}
|
|
105479
105706
|
}
|
|
105480
|
-
|
|
105481
|
-
|
|
105707
|
+
/** The tree at the path, under an `all` beside the window. */
|
|
105708
|
+
function writeGate(root, binding, value) {
|
|
105709
|
+
const window = TemplateTimeWindowValueSchema.parse(value);
|
|
105710
|
+
return setAt(root, binding.path, {
|
|
105711
|
+
kind: "all",
|
|
105712
|
+
children: [{
|
|
105713
|
+
kind: "time-is",
|
|
105714
|
+
...window
|
|
105715
|
+
}, getAt(root, binding.path)]
|
|
105716
|
+
});
|
|
105717
|
+
}
|
|
105718
|
+
/** The name a row is known by: `buttons-0`, and `buttons-0-events-1` for a nested row. */
|
|
105719
|
+
function rowIdOf(parentId, groupKey, index) {
|
|
105720
|
+
const own = `${groupKey}-${index}`;
|
|
105721
|
+
return parentId === null ? own : `${parentId}-${own}`;
|
|
105722
|
+
}
|
|
105723
|
+
function appendAt(root, path, items, key) {
|
|
105724
|
+
const existing = getAt(root, path);
|
|
105482
105725
|
const list = existing === void 0 ? [] : existing;
|
|
105483
|
-
if (!Array.isArray(list)) throw new PathError(`rows of "${
|
|
105484
|
-
|
|
105485
|
-
|
|
105486
|
-
|
|
105487
|
-
|
|
105488
|
-
|
|
105489
|
-
|
|
105490
|
-
|
|
105491
|
-
|
|
105492
|
-
|
|
105493
|
-
|
|
105494
|
-
|
|
105495
|
-
|
|
105496
|
-
|
|
105726
|
+
if (!Array.isArray(list)) throw new PathError(`rows of "${key}" need a list`);
|
|
105727
|
+
return setAt(root, path, [...list, ...items]);
|
|
105728
|
+
}
|
|
105729
|
+
/** The entries a row holds under `key`, each trigger carrying the leaf id the `triggered-by` of its row reads. */
|
|
105730
|
+
function entriesOf$1(row, input, rowId) {
|
|
105731
|
+
const value = row.scalars.get(input.key);
|
|
105732
|
+
const parsed = TemplateEntriesValueSchema.safeParse(value);
|
|
105733
|
+
const entries = parsed.success ? parsed.data : [];
|
|
105734
|
+
if (input.entry !== "trigger") return entries;
|
|
105735
|
+
return entries.map((entry, index) => {
|
|
105736
|
+
const id = Reflect.get(entry, "id");
|
|
105737
|
+
return typeof id === "string" && EVENT_LEAF_ID_RE.test(id) ? entry : {
|
|
105738
|
+
...entry,
|
|
105739
|
+
id: rowIdOf(rowId, input.key, index)
|
|
105740
|
+
};
|
|
105497
105741
|
});
|
|
105498
|
-
|
|
105742
|
+
}
|
|
105743
|
+
/** One row's item: the template JSON with the row's values, ids and nested rows written in. */
|
|
105744
|
+
function fillItem(template, bindings, group, row, rowId) {
|
|
105745
|
+
let item = template;
|
|
105746
|
+
for (const binding of bindings) {
|
|
105747
|
+
if (binding.kind === "row-id") {
|
|
105748
|
+
item = setAt(item, binding.path, rowId);
|
|
105749
|
+
continue;
|
|
105750
|
+
}
|
|
105751
|
+
if (binding.kind === "value") {
|
|
105752
|
+
const input = group.inputs.find((i) => i.key === binding.input);
|
|
105753
|
+
const value = row.scalars.get(binding.input);
|
|
105754
|
+
if (input === void 0 || input.kind === "group" || value === void 0) continue;
|
|
105755
|
+
item = writeValue(item, binding, input, value);
|
|
105756
|
+
continue;
|
|
105757
|
+
}
|
|
105758
|
+
const nested = group.inputs.find((i) => i.key === binding.input);
|
|
105759
|
+
if (binding.kind === "entries") {
|
|
105760
|
+
if (nested === void 0 || nested.kind !== "entries") continue;
|
|
105761
|
+
item = appendAt(item, binding.path, entriesOf$1(row, nested, rowId), nested.key);
|
|
105762
|
+
continue;
|
|
105763
|
+
}
|
|
105764
|
+
if (binding.kind === "row-ids" && nested !== void 0 && nested.kind === "entries") {
|
|
105765
|
+
item = setAt(item, binding.path, entriesOf$1(row, nested, rowId).map((entry) => Reflect.get(entry, "id")));
|
|
105766
|
+
continue;
|
|
105767
|
+
}
|
|
105768
|
+
if (nested === void 0 || nested.kind !== "group") continue;
|
|
105769
|
+
const nestedRows = row.groups.get(nested.key) ?? [];
|
|
105770
|
+
if (binding.kind === "row-ids") {
|
|
105771
|
+
item = setAt(item, binding.path, nestedRows.map((_, index) => rowIdOf(rowId, nested.key, index)));
|
|
105772
|
+
continue;
|
|
105773
|
+
}
|
|
105774
|
+
item = appendAt(item, binding.path, nestedRows.map((nestedRow, index) => fillItem(binding.item, binding.bindings, nested, nestedRow, rowIdOf(rowId, nested.key, index))), nested.key);
|
|
105775
|
+
}
|
|
105776
|
+
return item;
|
|
105777
|
+
}
|
|
105778
|
+
function applyRows(root, binding, group, rows) {
|
|
105779
|
+
if (binding.nested === void 0) {
|
|
105780
|
+
const items = rows.map((row, index) => fillItem(binding.item, binding.bindings, group, row, rowIdOf(null, group.key, index)));
|
|
105781
|
+
return appendAt(root, binding.path, items, group.key);
|
|
105782
|
+
}
|
|
105783
|
+
const nested = nestedGroupOf(group, binding.nested);
|
|
105784
|
+
if (nested === void 0) return root;
|
|
105785
|
+
const items = rows.flatMap((row, index) => (row.groups.get(nested.key) ?? []).map((nestedRow, nestedIndex) => fillItem(binding.item, binding.bindings, nested, nestedRow, rowIdOf(rowIdOf(null, group.key, index), nested.key, nestedIndex))));
|
|
105786
|
+
return appendAt(root, binding.path, items, nested.key);
|
|
105787
|
+
}
|
|
105788
|
+
/** The `input` entries of EVERY row of the group `binding.in`, concatenated onto the list at the path. */
|
|
105789
|
+
function applyEntriesOfRows(root, binding, inputs, resolved) {
|
|
105790
|
+
const group = inputs.find((i) => i.key === binding.in);
|
|
105791
|
+
if (group === void 0 || group.kind !== "group") return root;
|
|
105792
|
+
const entries = group.inputs.find((i) => i.key === binding.input);
|
|
105793
|
+
if (entries === void 0 || entries.kind !== "entries") return root;
|
|
105794
|
+
const items = (resolved.groups.get(group.key) ?? []).flatMap((row, index) => entriesOf$1(row, entries, rowIdOf(null, group.key, index)));
|
|
105795
|
+
return appendAt(root, binding.path, items, entries.key);
|
|
105499
105796
|
}
|
|
105500
105797
|
/** The body with the values written in, as a recipe — or every reason it is not one. */
|
|
105501
105798
|
function expandAutomationTemplate(payload, values) {
|
|
105502
105799
|
const problems = [];
|
|
105503
|
-
const resolved =
|
|
105800
|
+
const resolved = resolveLevel$1(payload.inputs, values, "", problems);
|
|
105504
105801
|
if (problems.length > 0) return {
|
|
105505
105802
|
ok: false,
|
|
105506
105803
|
problems
|
|
@@ -105508,6 +105805,10 @@ function expandAutomationTemplate(payload, values) {
|
|
|
105508
105805
|
let body = payload.body;
|
|
105509
105806
|
try {
|
|
105510
105807
|
for (const binding of payload.bindings) {
|
|
105808
|
+
if (binding.kind === "entries" && binding.in !== void 0) {
|
|
105809
|
+
body = applyEntriesOfRows(body, binding, payload.inputs, resolved);
|
|
105810
|
+
continue;
|
|
105811
|
+
}
|
|
105511
105812
|
const input = payload.inputs.find((i) => i.key === binding.input);
|
|
105512
105813
|
if (input === void 0) continue;
|
|
105513
105814
|
if (binding.kind === "rows") {
|
|
@@ -105518,7 +105819,12 @@ function expandAutomationTemplate(payload, values) {
|
|
|
105518
105819
|
if (input.kind === "group") continue;
|
|
105519
105820
|
const value = resolved.scalars.get(input.key);
|
|
105520
105821
|
if (value === void 0) continue;
|
|
105521
|
-
|
|
105822
|
+
if (binding.kind === "entries") {
|
|
105823
|
+
const list = TemplateEntriesValueSchema.safeParse(value);
|
|
105824
|
+
if (list.success) body = appendAt(body, binding.path, list.data, input.key);
|
|
105825
|
+
continue;
|
|
105826
|
+
}
|
|
105827
|
+
body = binding.kind === "gate" ? writeGate(body, binding, value) : writeValue(body, binding, input, value);
|
|
105522
105828
|
}
|
|
105523
105829
|
} catch (error) {
|
|
105524
105830
|
if (!(error instanceof PathError)) throw error;
|
|
@@ -110227,12 +110533,30 @@ var BUILTIN_REMOTE_COMPONENTS = [
|
|
|
110227
110533
|
* migration and nothing an operator saved is ever overwritten.
|
|
110228
110534
|
*/
|
|
110229
110535
|
var BUILTIN_TEMPLATE_ID_PREFIX = "builtin:";
|
|
110536
|
+
/** One choose branch per row, so the rows a group takes are the branches a choose takes. */
|
|
110537
|
+
var BUTTON_ROWS_MAX = 6;
|
|
110538
|
+
var ROW_ENTRIES_MAX = 10;
|
|
110539
|
+
/** The optional limit both built-ins end with: no value, no limit. */
|
|
110540
|
+
var ACTIVE_WINDOW_KEY = "active";
|
|
110541
|
+
var activeWindowInput = {
|
|
110542
|
+
kind: "time-window",
|
|
110543
|
+
key: ACTIVE_WINDOW_KEY,
|
|
110544
|
+
label: "Only when",
|
|
110545
|
+
description: "Limit the automation to a time of day, to some days, or both.",
|
|
110546
|
+
optional: true
|
|
110547
|
+
};
|
|
110548
|
+
/** Declared last: it moves the tree the other bindings write into one level down. */
|
|
110549
|
+
var activeWindowGate = {
|
|
110550
|
+
kind: "gate",
|
|
110551
|
+
input: ACTIVE_WINDOW_KEY,
|
|
110552
|
+
path: ["when"]
|
|
110553
|
+
};
|
|
110230
110554
|
var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
110231
110555
|
id: `${BUILTIN_TEMPLATE_ID_PREFIX}buttons-to-devices`,
|
|
110232
110556
|
name: "Buttons → devices",
|
|
110233
110557
|
payload: {
|
|
110234
110558
|
version: 1,
|
|
110235
|
-
description: "Each
|
|
110559
|
+
description: "Each button: when it sends an event, run one or more actions.",
|
|
110236
110560
|
body: {
|
|
110237
110561
|
when: {
|
|
110238
110562
|
kind: "any",
|
|
@@ -110251,96 +110575,58 @@ var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
|
110251
110575
|
kind: "group",
|
|
110252
110576
|
key: "buttons",
|
|
110253
110577
|
label: "Buttons",
|
|
110254
|
-
|
|
110255
|
-
|
|
110256
|
-
|
|
110257
|
-
|
|
110258
|
-
|
|
110259
|
-
|
|
110260
|
-
|
|
110261
|
-
|
|
110262
|
-
|
|
110263
|
-
|
|
110264
|
-
|
|
110265
|
-
|
|
110266
|
-
|
|
110267
|
-
|
|
110268
|
-
|
|
110269
|
-
|
|
110270
|
-
|
|
110271
|
-
|
|
110272
|
-
|
|
110273
|
-
|
|
110274
|
-
|
|
110275
|
-
|
|
110276
|
-
|
|
110277
|
-
|
|
110278
|
-
deviceInput: "targets"
|
|
110279
|
-
}
|
|
110280
|
-
]
|
|
110281
|
-
}],
|
|
110282
|
-
bindings: [{
|
|
110283
|
-
kind: "rows",
|
|
110284
|
-
input: "buttons",
|
|
110285
|
-
path: ["when", "children"],
|
|
110286
|
-
item: { kind: "device-fired" },
|
|
110287
|
-
bindings: [
|
|
110288
|
-
{
|
|
110289
|
-
kind: "row-id",
|
|
110290
|
-
path: ["id"]
|
|
110291
|
-
},
|
|
110292
|
-
{
|
|
110293
|
-
kind: "value",
|
|
110294
|
-
input: "button",
|
|
110295
|
-
path: ["deviceId"]
|
|
110296
|
-
},
|
|
110297
|
-
{
|
|
110298
|
-
kind: "value",
|
|
110299
|
-
input: "event",
|
|
110300
|
-
path: []
|
|
110301
|
-
}
|
|
110302
|
-
]
|
|
110303
|
-
}, {
|
|
110304
|
-
kind: "rows",
|
|
110305
|
-
input: "buttons",
|
|
110306
|
-
path: [
|
|
110307
|
-
"actions",
|
|
110308
|
-
0,
|
|
110309
|
-
"branches"
|
|
110310
|
-
],
|
|
110311
|
-
item: {
|
|
110312
|
-
if: {
|
|
110313
|
-
kind: "triggered-by",
|
|
110314
|
-
leafIds: []
|
|
110315
|
-
},
|
|
110316
|
-
steps: [{ kind: "command" }]
|
|
110578
|
+
rowLabel: "button",
|
|
110579
|
+
maxRows: BUTTON_ROWS_MAX,
|
|
110580
|
+
inputs: [{
|
|
110581
|
+
kind: "entries",
|
|
110582
|
+
key: "when",
|
|
110583
|
+
label: "When",
|
|
110584
|
+
entry: "trigger",
|
|
110585
|
+
allow: ["device-fired"],
|
|
110586
|
+
maxItems: ROW_ENTRIES_MAX
|
|
110587
|
+
}, {
|
|
110588
|
+
kind: "entries",
|
|
110589
|
+
key: "do",
|
|
110590
|
+
label: "Actions",
|
|
110591
|
+
entry: "step",
|
|
110592
|
+
allow: ["command"],
|
|
110593
|
+
maxItems: ROW_ENTRIES_MAX
|
|
110594
|
+
}]
|
|
110595
|
+
}, activeWindowInput],
|
|
110596
|
+
bindings: [
|
|
110597
|
+
{
|
|
110598
|
+
kind: "entries",
|
|
110599
|
+
input: "when",
|
|
110600
|
+
in: "buttons",
|
|
110601
|
+
path: ["when", "children"]
|
|
110317
110602
|
},
|
|
110318
|
-
|
|
110319
|
-
|
|
110320
|
-
|
|
110321
|
-
|
|
110322
|
-
|
|
110323
|
-
|
|
110324
|
-
|
|
110325
|
-
|
|
110326
|
-
|
|
110327
|
-
|
|
110328
|
-
|
|
110329
|
-
|
|
110330
|
-
|
|
110331
|
-
|
|
110332
|
-
0,
|
|
110333
|
-
"target"
|
|
110334
|
-
],
|
|
110335
|
-
as: "target"
|
|
110603
|
+
{
|
|
110604
|
+
kind: "rows",
|
|
110605
|
+
input: "buttons",
|
|
110606
|
+
path: [
|
|
110607
|
+
"actions",
|
|
110608
|
+
0,
|
|
110609
|
+
"branches"
|
|
110610
|
+
],
|
|
110611
|
+
item: {
|
|
110612
|
+
if: {
|
|
110613
|
+
kind: "triggered-by",
|
|
110614
|
+
leafIds: []
|
|
110615
|
+
},
|
|
110616
|
+
steps: []
|
|
110336
110617
|
},
|
|
110337
|
-
{
|
|
110338
|
-
kind: "
|
|
110339
|
-
input: "
|
|
110340
|
-
path: ["
|
|
110341
|
-
}
|
|
110342
|
-
|
|
110343
|
-
|
|
110618
|
+
bindings: [{
|
|
110619
|
+
kind: "row-ids",
|
|
110620
|
+
input: "when",
|
|
110621
|
+
path: ["if", "leafIds"]
|
|
110622
|
+
}, {
|
|
110623
|
+
kind: "entries",
|
|
110624
|
+
input: "do",
|
|
110625
|
+
path: ["steps"]
|
|
110626
|
+
}]
|
|
110627
|
+
},
|
|
110628
|
+
activeWindowGate
|
|
110629
|
+
]
|
|
110344
110630
|
}
|
|
110345
110631
|
}, {
|
|
110346
110632
|
id: `${BUILTIN_TEMPLATE_ID_PREFIX}motion-light`,
|
|
@@ -110392,7 +110678,8 @@ var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
|
110392
110678
|
min: 10,
|
|
110393
110679
|
max: 3600,
|
|
110394
110680
|
default: 300
|
|
110395
|
-
}
|
|
110681
|
+
},
|
|
110682
|
+
activeWindowInput
|
|
110396
110683
|
],
|
|
110397
110684
|
bindings: [
|
|
110398
110685
|
{
|
|
@@ -110428,7 +110715,8 @@ var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
|
110428
110715
|
"target"
|
|
110429
110716
|
],
|
|
110430
110717
|
as: "target"
|
|
110431
|
-
}
|
|
110718
|
+
},
|
|
110719
|
+
activeWindowGate
|
|
110432
110720
|
]
|
|
110433
110721
|
}
|
|
110434
110722
|
}];
|
|
@@ -113116,7 +113404,7 @@ var DeclaredDevices = class {
|
|
|
113116
113404
|
return removed;
|
|
113117
113405
|
}
|
|
113118
113406
|
};
|
|
113119
|
-
DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, DeviceType.EnergySystem, DeviceType.Camera, DeviceType.
|
|
113407
|
+
DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.HeatPump, DeviceType.EnergySystem, DeviceType.Camera, DeviceType.Switch, DeviceType.Siren, DeviceType.Light, DeviceType.Fan, DeviceType.Sensor, DeviceType.Climate, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway;
|
|
113120
113408
|
new Set(Object.values(DeviceType));
|
|
113121
113409
|
/** True when a value is a navigable node: a plain object OR a tRPC v11 client
|
|
113122
113410
|
* proxy node (a callable `Proxy(noop)` → `typeof === 'function'`, NOT an
|
|
@@ -115985,7 +116273,6 @@ var CONTROL_LAYOUT = { rows: ["control"] };
|
|
|
115985
116273
|
var BUTTON_LAYOUT = { rows: ["button"] };
|
|
115986
116274
|
var HERO_LAYOUT_BY_TYPE = {
|
|
115987
116275
|
[DeviceType.Camera]: HERO_LAYOUT_DEFAULT,
|
|
115988
|
-
[DeviceType.Hub]: HERO_LAYOUT_DEFAULT,
|
|
115989
116276
|
[DeviceType.Light]: LIGHT_LAYOUT,
|
|
115990
116277
|
[DeviceType.Siren]: HERO_LAYOUT_DEFAULT,
|
|
115991
116278
|
[DeviceType.Switch]: SWITCH_LAYOUT,
|
|
@@ -116709,7 +116996,6 @@ var HERO_MODE_LOOK = {
|
|
|
116709
116996
|
var MODE_LOOK_TYPES = [DeviceType.Climate];
|
|
116710
116997
|
var HERO_LOOK_BY_TYPE = {
|
|
116711
116998
|
[DeviceType.Camera]: CAMERA_LOOK,
|
|
116712
|
-
[DeviceType.Hub]: HERO_LOOK_DEFAULT,
|
|
116713
116999
|
[DeviceType.Light]: LIGHT_LOOK,
|
|
116714
117000
|
[DeviceType.Siren]: HERO_LOOK_DEFAULT,
|
|
116715
117001
|
[DeviceType.Switch]: SWITCH_LOOK,
|
|
@@ -127814,7 +128100,7 @@ function offered(received) {
|
|
|
127814
128100
|
};
|
|
127815
128101
|
}
|
|
127816
128102
|
offered(HA_AS), withheld(HOMEKIT_REASON), withheld(ALEXA_REASON), withheld(GOOGLE_REASON), withheld(MATTER_REASON);
|
|
127817
|
-
DeviceType.Camera, DeviceType.
|
|
128103
|
+
DeviceType.Camera, DeviceType.Light, DeviceType.Siren, DeviceType.Switch, DeviceType.Sensor, DeviceType.Climate, DeviceType.HeatPump, DeviceType.EnergySystem, DeviceType.Button, DeviceType.EventEmitter, DeviceType.Update, DeviceType.Generic, DeviceType.Notifier, DeviceType.Script, DeviceType.Automation, DeviceType.Lock, DeviceType.Cover, DeviceType.Valve, DeviceType.Humidifier, DeviceType.WaterHeater, DeviceType.Fan, DeviceType.MediaPlayer, DeviceType.AlarmPanel, DeviceType.Control, DeviceType.Presence, DeviceType.Weather, DeviceType.Vacuum, DeviceType.LawnMower, DeviceType.Container, DeviceType.Image, DeviceType.PetFeeder, DeviceType.PetFountain, DeviceType.Dishwasher, DeviceType.Washer, DeviceType.Dryer, DeviceType.Gateway;
|
|
127818
128104
|
DeviceRole.Siren, DeviceRole.Floodlight, DeviceRole.Spotlight, DeviceRole.PirSensor, DeviceRole.Chime, DeviceRole.Autotrack, DeviceRole.Nightvision, DeviceRole.PrivacyMask, DeviceRole.Doorbell, DeviceRole.CoverBlind, DeviceRole.CoverShutter, DeviceRole.CoverAwning, DeviceRole.CoverCurtain, DeviceRole.CoverGarage, DeviceRole.CoverGate, DeviceRole.CoverDoor, DeviceRole.CoverWindow, DeviceRole.BinaryHelper, DeviceRole.Outlet, DeviceRole.SwitchHeater, DeviceRole.SwitchFan, DeviceRole.SwitchLight, DeviceRole.ClimateAc, DeviceRole.ClimateThermostat, DeviceRole.ClimateFloor, DeviceRole.ClimateRadiator, DeviceRole.ClimateHeater, DeviceRole.ClimateHeatPumpCircuit, DeviceRole.MotionSensor, DeviceRole.ContactSensor, DeviceRole.LeakSensor, DeviceRole.SmokeSensor, DeviceRole.COSensor, DeviceRole.GasSensor, DeviceRole.TamperSensor, DeviceRole.VibrationSensor, DeviceRole.ConnectivitySensor, DeviceRole.SoundSensor, DeviceRole.BinarySensor, DeviceRole.TemperatureSensor, DeviceRole.HumiditySensor, DeviceRole.AmbientLightSensor, DeviceRole.PressureSensor, DeviceRole.WindSensor, DeviceRole.RainSensor, DeviceRole.UvSensor, DeviceRole.SolarRadiationSensor, DeviceRole.SoilMoistureSensor, DeviceRole.PowerSensor, DeviceRole.EnergySensor, DeviceRole.VoltageSensor, DeviceRole.CurrentSensor, DeviceRole.AirQualitySensor, DeviceRole.BatterySensor, DeviceRole.NumericSensor, DeviceRole.EnumSensor, DeviceRole.DateTimeSensor, DeviceRole.GenericSensor, DeviceRole.NumericControl, DeviceRole.SelectControl, DeviceRole.TextControl, DeviceRole.DateTimeControl, DeviceRole.MobilePushNotifier, DeviceRole.MessagingNotifier, DeviceRole.EmailNotifier, DeviceRole.GenericNotifier, DeviceRole.IrTransmitter;
|
|
127819
128105
|
new Set(Object.values(DeviceType));
|
|
127820
128106
|
new Set(Object.values(DeviceRole));
|