@camstack/server 1.2.943 → 1.2.944
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/closure-pins.json +350 -0
- package/dist/api/core/auth-sessions.procedures.js +18 -0
- package/dist/api/core/auth.router.js +19 -6
- package/dist/api/server-upload.js +17 -1
- package/dist/api/trpc/generated-cap-routers.js +83 -0
- package/dist/auth/native-return.js +9 -3
- package/dist/auth/sso-routes.js +5 -1
- package/dist/core/addon/instance-lifecycle.js +4 -1
- package/dist/core/auth/handoff-code.service.js +35 -1
- package/dist/server-root/index.js +313 -70
- package/package.json +21 -11
- package/system/dist/{action-index-B1fgpQBt.mjs → action-index-DpYmsOKh.mjs} +1 -1
- package/system/dist/{action-index-B_cLRwXJ.js → action-index-Dz9rd1qa.js} +1 -1
- package/system/dist/{addon-settings.cap-CZ4MC7ha.mjs → addon-settings.cap-CHpmuaQG.mjs} +1 -1
- package/system/dist/{addon-settings.cap-DrLdMFIe.js → addon-settings.cap-nZVHPo3X.js} +1 -1
- package/system/dist/{alert-episode-Be--PngO.mjs → alert-episode-D-1VUUkZ.mjs} +1 -1
- package/system/dist/{alert-episode-Bqktmt-i.js → alert-episode-DaQ3prSe.js} +1 -1
- package/system/dist/{base-addon-CRsXtYFG.js → base-addon-BG7p06Hb.js} +136 -15
- package/system/dist/{base-addon-BcS6r1cT.mjs → base-addon-BcVoYZbC.mjs} +136 -15
- package/system/dist/{base-device-DAdWzDOl.js → base-device-DeSNiwZ4.js} +4 -4
- package/system/dist/{base-device-DJXF5eDN.mjs → base-device-w_MD0Bf4.mjs} +4 -4
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +3 -3
- package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +3 -3
- package/system/dist/builtins/camera-grid/index.mjs +3 -3
- package/system/dist/builtins/composer/composer.addon.js +7 -7
- package/system/dist/builtins/composer/composer.addon.mjs +7 -7
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/actions-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/block-supervisor.d.ts +16 -4
- package/system/dist/builtins/core-blocks/core-block-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +1018 -323
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +986 -291
- package/system/dist/builtins/core-blocks/migrations/index.d.ts +5 -2
- package/system/dist/builtins/core-blocks/migrations/tag-ids.d.ts +42 -0
- package/system/dist/builtins/core-blocks/migrations/tags-as-records.d.ts +47 -0
- package/system/dist/builtins/core-blocks/record-kinds.d.ts +12 -1
- package/system/dist/builtins/core-blocks/runs-api.d.ts +3 -1
- package/system/dist/builtins/core-blocks/runs-ledger.d.ts +3 -1
- package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/tags-service.d.ts +52 -27
- package/system/dist/builtins/core-blocks/tags-wiring.d.ts +2 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +76 -67
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +76 -67
- package/system/dist/builtins/device-history/device-history.addon.js +4 -4
- package/system/dist/builtins/device-history/device-history.addon.mjs +4 -4
- package/system/dist/builtins/device-manager/device-manager.addon.js +1602 -760
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +1588 -746
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +13 -136
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-provider-context.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-row-store.d.ts +21 -4
- package/system/dist/builtins/device-manager/device-search.d.ts +6 -0
- package/system/dist/builtins/device-manager/location-alignment.d.ts +9 -2
- package/system/dist/builtins/device-manager/migrate-device.d.ts +7 -2
- package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +132 -1
- package/system/dist/builtins/device-manager/migrations/device-tag-ids.d.ts +25 -0
- package/system/dist/builtins/device-manager/migrations/index.d.ts +16 -0
- package/system/dist/builtins/device-manager/migrations/orphan-children.d.ts +33 -0
- package/system/dist/builtins/device-manager/migrations/ports.d.ts +17 -0
- package/system/dist/builtins/device-manager/migrations/rooms-as-records.d.ts +52 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +3 -1
- package/system/dist/builtins/device-manager/removal-cleanup.d.ts +7 -0
- package/system/dist/builtins/device-manager/room-actions.d.ts +27 -0
- package/system/dist/builtins/device-manager/room-store.d.ts +19 -0
- package/system/dist/builtins/device-manager/tag-names.d.ts +32 -0
- package/system/dist/builtins/device-manager/wireable-enum-catalog.d.ts +18 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +2 -2
- package/system/dist/builtins/keychain/index.mjs +2 -2
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +2 -2
- package/system/dist/builtins/loki-logging/index.mjs +2 -2
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +3 -1
- package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +15 -10
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +15 -10
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +1 -1
- package/system/dist/builtins/system-config/system-config.addon.mjs +1 -1
- package/system/dist/builtins/winston-logging/index.js +2 -2
- package/system/dist/builtins/winston-logging/index.mjs +2 -2
- package/system/dist/{command-catalog-C29hVOOg.js → command-catalog-CI0tu1Nt.js} +1 -1
- package/system/dist/{command-catalog-xAeqxbZk.mjs → command-catalog-zwlIA3T5.mjs} +1 -1
- package/system/dist/{composition-sources-C327LGFn.mjs → composition-sources-CXxXfh1z.mjs} +1 -1
- package/system/dist/{composition-sources-Do5qM6EB.js → composition-sources-DNgSItK-.js} +1 -1
- package/system/dist/{core-blocks.cap-CdTGUKtr.js → core-blocks.cap-BHEok4VO.js} +125 -373
- package/system/dist/{core-blocks.cap-DLkEfV5b.mjs → core-blocks.cap-CPgZRcpj.mjs} +109 -327
- package/system/dist/{device-manager.cap-DJs8izI6.js → device-manager.cap-B9qVf7ag.js} +163 -22
- package/system/dist/{device-manager.cap-eYrj1Ezp.mjs → device-manager.cap-CV4KGp3e.mjs} +134 -17
- package/system/dist/{error.cap-CU1FB6uE.mjs → error.cap-B8l7L8e4.mjs} +7 -1
- package/system/dist/{error.cap-BuKbL3Ac.js → error.cap-BqlvgBJd.js} +7 -1
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/index.js +7 -7
- package/system/dist/index.mjs +6 -6
- package/system/dist/{legacy-integration-rows-door-CdqYAj-o.js → legacy-integration-rows-door-BK8eoGlF.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-LSgpClpX.mjs → legacy-integration-rows-door-CwzC5XNk.mjs} +1 -1
- package/system/dist/{migration-DGAc6ywR.mjs → migration-BvbfW9g-.mjs} +6 -0
- package/system/dist/{migration-BOQlFZCN.js → migration-CHPdAdNh.js} +6 -0
- package/system/dist/{prefix-walk-BFnw8NBu.js → named-entity-store-DFwLij9c.js} +244 -90
- package/system/dist/{prefix-walk-Mtij0NNT.mjs → named-entity-store-DOnyyFFf.mjs} +195 -89
- package/system/dist/{notification-rules.cap-BUIuYPlQ.mjs → notification-rules.cap-ClvK6QT1.mjs} +10 -5
- package/system/dist/{notification-rules.cap-BJKUjizS.js → notification-rules.cap-uSLoe2pA.js} +10 -5
- package/system/dist/{notification-targets-DMW7xgR2.js → notification-targets-ChqpBbtR.js} +2 -2
- package/system/dist/{notification-targets-4bGYH5J7.mjs → notification-targets-DUA6-F2t.mjs} +2 -2
- package/system/dist/{device-row-store-CTocYKqC.mjs → record-kinds-BD2xv4Pd.mjs} +222 -93
- package/system/dist/{device-row-store-C0P2H18h.js → record-kinds-BV8Gcpsx.js} +246 -93
- package/system/dist/records/named-entity-store.d.ts +60 -0
- package/system/dist/{rename-composition-block-Cdh-dRmY.mjs → rename-composition-block-C3QQ9UUE.mjs} +134 -33
- package/system/dist/{rename-composition-block-D9Uc1AF7.js → rename-composition-block-Cx3X8QSm.js} +134 -33
- package/system/dist/{retention-source.cap-C6Hy0hlM.js → retention-source.cap-A-TMhU5O.js} +1 -1
- package/system/dist/{retention-source.cap-550kkyp5.mjs → retention-source.cap-Ct07pM30.mjs} +1 -1
- package/system/dist/{storage-admin.cap-Ci4QbL6P.mjs → storage-admin.cap-C54s9_B9.mjs} +8 -2
- package/system/dist/{storage-admin.cap-DqW1ol4j.js → storage-admin.cap-DSPHi7ut.js} +8 -2
- package/system/dist/{stream-catalog.cap-CjEQFknc.js → stream-catalog.cap-7WPsugOy.js} +1 -1
- package/system/dist/{stream-catalog.cap-DVniDdRD.mjs → stream-catalog.cap-CzwRDaqT.mjs} +1 -1
- package/system/dist/{tag-BxLazvVb.js → tag-BLraBqvp.js} +12 -0
- package/system/dist/{tag-uZBAq6ox.mjs → tag-DU8pm9Bi.mjs} +7 -1
- package/system/dist/time-window-B6UhCArd.js +679 -0
- package/system/dist/time-window-BnUBULgu.mjs +578 -0
- package/system/dist/{wal-maintenance-BgYiAy5b.js → wal-maintenance-CkPfVApC.js} +0 -0
- package/system/dist/{wal-maintenance-Bey5ChBb.mjs → wal-maintenance-u84_1sVl.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { r as MotionStatusSchema } from "../../stream-catalog.cap-
|
|
2
|
-
import { _ as hydrateSchema, a as isSecretRefOwnedBy, b as EventCategory$1, f as defineAddonMigrations, i as collectSecretMarkerRefs, l as RecordIntegrationInstances, o as resolveSecretMarkers, r as secretTreeFromSchema, s as transformSecretWrite, t as BaseAddon } from "../../base-addon-
|
|
1
|
+
import { r as MotionStatusSchema } from "../../stream-catalog.cap-CzwRDaqT.mjs";
|
|
2
|
+
import { _ as hydrateSchema, a as isSecretRefOwnedBy, b as EventCategory$1, f as defineAddonMigrations, i as collectSecretMarkerRefs, l as RecordIntegrationInstances, o as resolveSecretMarkers, r as secretTreeFromSchema, s as transformSecretWrite, t as BaseAddon } from "../../base-addon-BcVoYZbC.mjs";
|
|
3
3
|
import { W as isSecretMarker, Z as errMsg$1 } from "../../scoped-settings-DVWUIP7Z.mjs";
|
|
4
|
-
import { $ as RemoteLayoutPayloadSchema, $n as unitsForQuantity, $t as FanPresetSchema, A as TemplateKindSchema, At as measurementFitsRole, B as SmokeStatusSchema, Bn as AutomationControlStatusSchema, Bt as timedRunRemaining, C as WaterHeaterStatusSchema, Cn as ContactStatusSchema, Ct as projectDeviceRow, D as VacuumControlStatusSchema, Dn as COMPOSER_RUNNER_ID, Dt as contactMeasurement, Et as resolveHeroSceneId, F as TamperStatusSchema, Fn as CarbonMonoxideStatusSchema, Ft as TimedRunStatusSchema, G as hasOwnRunningPowerDefaults, Gt as GroupStatusSchema, H as schedulersCapability, Hn as AirQualitySensorStatusSchema, Ht as HeatingValveStatusSchema, I as tagsCapability, In as BrightnessStatusSchema, It as timedRunCapability, J as REMOTE_MEDIA_COMMANDS, K as runningPowerDefaultsFor, Kn as actionWaitTotalMs, L as SWITCH_DEFAULT_OPTIONS, Lt as timedRunLimitOf, M as AutomationTemplatePayloadSchema, Mn as ClimateControlStatusSchema, Mt as temperatureMeasurement, N as reexpandAutomationInstance, Nt as textMeasurement, O as UpdateStatusSchema, Ot as emptyMeasurement, P as TemperatureSensorStatusSchema, Pt as NOT_REPORTED, Q as RemoteAssumedStateSchema, Qn as baseUnitForQuantity, Qt as FAN_CAPTURE_FIELDS, R as SwitchStatusSchema, Rn as BinaryStatusSchema, Rt as timedRunMaxIn, S as WeatherStatusSchema, Sn as ControlStatusSchema, St as ROW_READING_FACT_IDS, T as ValveStatusSchema, Tn as ConsumablesStatusSchema, Tt as REMOTE_OPEN_ACTION_ID, Ut as HeatPumpStatusSchema, V as ScriptRunnerStatusSchema, Vn as AmbientLightSensorStatusSchema, Vt as timedRunSeconds, W as RunningStateStatusSchema, Wn as actionsCapability, Wt as heatPumpInstantCop, X as EMPTY_REMOTE_ASSUMED_STATE, Xn as normalizeActionUnits, Xt as GasStatusSchema, Y as remoteCapability, Yn as capUnitResolver, Yt as GroupActiveSchema, Z as EMPTY_REMOTE_CONFIG, Zn as normalizeRecipeUnits, Zt as FloodStatusSchema, _ as WorkloadStatusSchema, _t as LawnMowerControlStatusSchema, an as SetOscillationAxisInputSchema, ar as addonIdOfActionId, bn as CoverStatusSchema, bt as HumidifierStatusSchema, c as kebabToCamel, cn as EnumSensorStatusSchema, cr as resolveActionVariables, dn as DishwasherStatusSchema, dt as NumericSensorStatusSchema, en as fanPresetsCapability, er as ActionError, et as readStoredRemoteConfig, ft as NetworkLinkStatusSchema, ht as LockControlStatusSchema, ir as INTERNAL_ACTION_PREFIX, it as PowerMeterStatusSchema, j as checkTemplatePayload, jt as powerMeasurement, k as templateCapability, kn as ColorStatusSchema, kt as humidityMeasurement, ln as DoorbellStatusSchema, lr as EventEmitterStatusSchema, lt as PetFeederStatusSchema, m as ALL_CAPABILITY_DEFINITIONS, mt as MeterStatusSchema, nn as FAN_OSCILLATION_AXIS_SETTABLE, nr as ActionVariableSchema, nt as PressureSensorStatusSchema, on as fanAxisPath, or as internalActionId, ot as PetFountainStatusSchema, pt as MotionTriggerStatusSchema, q as remoteLayoutComponentsCapability, qn as actionSourceCapability, qt as GroupCommandsSchema, rn as FanControlStatusSchema, rr as IDLE_ACTION_STATUS, rt as PresenceStatusSchema, sr as isInternalActionId, t as composedBlockIdOf, tn as FAN_OSCILLATION_AXES, tr as ActionMinDelaySecSchema, tt as PumpCycleStatusSchema, un as DoNotDisturbStatusSchema, vt as ImageStatusSchema, w as VibrationStatusSchema, wt as HERO_SCENE_ROW_IDS, x as WeatherStationStatusSchema, xt as heroLayoutCapability, yt as HumiditySensorStatusSchema, zn as BatteryStatusSchema, zt as timedRunQuickRun } from "../../rename-composition-block-
|
|
5
|
-
import { r as listNotificationTargets } from "../../notification-targets-
|
|
6
|
-
import {
|
|
4
|
+
import { $ as RemoteLayoutPayloadSchema, $n as unitsForQuantity, $t as FanPresetSchema, A as TemplateKindSchema, At as measurementFitsRole, B as SmokeStatusSchema, Bn as AutomationControlStatusSchema, Bt as timedRunRemaining, C as WaterHeaterStatusSchema, Cn as ContactStatusSchema, Ct as projectDeviceRow, D as VacuumControlStatusSchema, Dn as COMPOSER_RUNNER_ID, Dt as contactMeasurement, Et as resolveHeroSceneId, F as TamperStatusSchema, Fn as CarbonMonoxideStatusSchema, Ft as TimedRunStatusSchema, G as hasOwnRunningPowerDefaults, Gt as GroupStatusSchema, H as schedulersCapability, Hn as AirQualitySensorStatusSchema, Ht as HeatingValveStatusSchema, I as tagsCapability, In as BrightnessStatusSchema, It as timedRunCapability, J as REMOTE_MEDIA_COMMANDS, K as runningPowerDefaultsFor, Kn as actionWaitTotalMs, L as SWITCH_DEFAULT_OPTIONS, Lt as timedRunLimitOf, M as AutomationTemplatePayloadSchema, Mn as ClimateControlStatusSchema, Mt as temperatureMeasurement, N as reexpandAutomationInstance, Nt as textMeasurement, O as UpdateStatusSchema, Ot as emptyMeasurement, P as TemperatureSensorStatusSchema, Pt as NOT_REPORTED, Q as RemoteAssumedStateSchema, Qn as baseUnitForQuantity, Qt as FAN_CAPTURE_FIELDS, R as SwitchStatusSchema, Rn as BinaryStatusSchema, Rt as timedRunMaxIn, S as WeatherStatusSchema, Sn as ControlStatusSchema, St as ROW_READING_FACT_IDS, T as ValveStatusSchema, Tn as ConsumablesStatusSchema, Tt as REMOTE_OPEN_ACTION_ID, Ut as HeatPumpStatusSchema, V as ScriptRunnerStatusSchema, Vn as AmbientLightSensorStatusSchema, Vt as timedRunSeconds, W as RunningStateStatusSchema, Wn as actionsCapability, Wt as heatPumpInstantCop, X as EMPTY_REMOTE_ASSUMED_STATE, Xn as normalizeActionUnits, Xt as GasStatusSchema, Y as remoteCapability, Yn as capUnitResolver, Yt as GroupActiveSchema, Z as EMPTY_REMOTE_CONFIG, Zn as normalizeRecipeUnits, Zt as FloodStatusSchema, _ as WorkloadStatusSchema, _t as LawnMowerControlStatusSchema, an as SetOscillationAxisInputSchema, ar as addonIdOfActionId, bn as CoverStatusSchema, bt as HumidifierStatusSchema, c as kebabToCamel, cn as EnumSensorStatusSchema, cr as resolveActionVariables, dn as DishwasherStatusSchema, dt as NumericSensorStatusSchema, en as fanPresetsCapability, er as ActionError, et as readStoredRemoteConfig, ft as NetworkLinkStatusSchema, ht as LockControlStatusSchema, ir as INTERNAL_ACTION_PREFIX, it as PowerMeterStatusSchema, j as checkTemplatePayload, jt as powerMeasurement, k as templateCapability, kn as ColorStatusSchema, kt as humidityMeasurement, ln as DoorbellStatusSchema, lr as EventEmitterStatusSchema, lt as PetFeederStatusSchema, m as ALL_CAPABILITY_DEFINITIONS, mt as MeterStatusSchema, nn as FAN_OSCILLATION_AXIS_SETTABLE, nr as ActionVariableSchema, nt as PressureSensorStatusSchema, on as fanAxisPath, or as internalActionId, ot as PetFountainStatusSchema, pt as MotionTriggerStatusSchema, q as remoteLayoutComponentsCapability, qn as actionSourceCapability, qt as GroupCommandsSchema, rn as FanControlStatusSchema, rr as IDLE_ACTION_STATUS, rt as PresenceStatusSchema, sr as isInternalActionId, t as composedBlockIdOf, tn as FAN_OSCILLATION_AXES, tr as ActionMinDelaySecSchema, tt as PumpCycleStatusSchema, un as DoNotDisturbStatusSchema, vt as ImageStatusSchema, w as VibrationStatusSchema, wt as HERO_SCENE_ROW_IDS, x as WeatherStationStatusSchema, xt as heroLayoutCapability, yt as HumiditySensorStatusSchema, zn as BatteryStatusSchema, zt as timedRunQuickRun } from "../../rename-composition-block-C3QQ9UUE.mjs";
|
|
5
|
+
import { r as listNotificationTargets } from "../../notification-targets-DUA6-F2t.mjs";
|
|
6
|
+
import { t as userError } from "../../camstack-error-viZYfcj9.mjs";
|
|
7
|
+
import { i as NcTaggedRuleKindSchema, o as AlarmPanelStatusSchema, u as NotificationSchema } from "../../notification-rules.cap-ClvK6QT1.mjs";
|
|
7
8
|
import { s as defineRecordKinds } from "../../record-kind-ub6NXqfh.mjs";
|
|
8
9
|
import { n as entryBody, t as defineEntryKind } from "../../entry-kind-D9MuVJCK.mjs";
|
|
9
|
-
import {
|
|
10
|
+
import { c as TagBodySchema, f as IDENTITY_LINK_KINDS } from "../../device-manager.cap-CV4KGp3e.mjs";
|
|
10
11
|
import { n as ruleFireOfClaim } from "../../command-origin-claim-D1Wy7Qld.mjs";
|
|
11
12
|
import { n as baseUnitOf } from "../../quantity-D3g5SxsZ.mjs";
|
|
12
|
-
import { a as
|
|
13
|
+
import { a as TagsFieldSchema, c as removeFromTags, i as TagStyleSchema, l as renameInTags, n as TagIdsFieldSchema, o as defaultTagColorId, r as TagNameSchema, s as normalizeTags, u as tagKey } from "../../tag-DU8pm9Bi.mjs";
|
|
13
14
|
import { n as DeviceRole, r as DeviceType$1, t as DeviceFeature } from "../../device-type-TUGqGmaI.mjs";
|
|
14
15
|
import { r as isAirConditioner, t as canonicalStoredDeviceType } from "../../device-kind-C37Ra2wd.mjs";
|
|
15
|
-
import { a as
|
|
16
|
-
import {
|
|
16
|
+
import { A as MediaPlayerStatusSchema, Bt as holdOf, C as PowerSourceStateSchema, Ct as nestedStepsOf, Et as validateRecipeBounds, Ft as forEachLeaf, Gt as QuantityUnitError, I as remoteSourceSteps, It as hasEventLeaves, J as capLinkServedFields, L as resolveRemoteSource, Lt as isEventLeaf, P as findChannelSource, Q as CAP_CUSTOMIZE_CATALOG, Rt as compareValues, S as PowerSourceInfoSchema, St as REPEAT_ITEM_VAR, Tt as stepGuardOf, U as toTimings, X as expandCapLinks, Y as declaredCapLink, Z as projectCapLinkOf, _ as replacedFieldKeys, _t as validateSchedulerInput, a as coreBlockComposition, at as AutomationStateDocSchema, b as powerSourceActuatorConflicts, bt as AutomationRecipeSchema, c as coreBlocksCapability, ct as buildStepArgsTrace, d as resolveCoreBlockFiles, en as ACTION_TARGET_INVALIDATION_EVENTS, f as describeComposableCaps, ft as SchedulerError, g as planComposition, h as compositionUnionReads, ht as SchedulerSchema, i as coreBlockAddonId, l as normalizeCoreBlockWrite, lt as DEFAULT_HOLD_OVERRIDE, m as compositionSourceRefs, n as CORE_BLOCK_ADDON_PREFIX, nn as canonicalStoredStepTargets, o as coreBlockIdFromAddonId, ot as EMPTY_AUTOMATION_STATE, p as buildCapabilityLookup, r as CoreBlockSchema, rn as ON_FOR_MAX_SECONDS, s as coreBlockSourceKind, st as appendTrace, t as CORE_BLOCKS_ADDON_ID, tn as ActionTargetResolver, u as resolveCoreBlockEntry, v as topLevelFieldsOf, vt as ActionStepSchema, w as powerSourceCapability, wt as stepConditionsOf, x as powerSourceLinkOfComposition, xt as HTTP_TEXT_CAP, y as validateComposition, z as customKeyOfRole } from "../../core-blocks.cap-CPgZRcpj.mjs";
|
|
17
|
+
import { a as findVocabAction, i as assertDeviceOffers, n as actionEffect, o as vocabActionIdFor, s as vocabCall, t as VocabActionError } from "../../action-index-DpYmsOKh.mjs";
|
|
17
18
|
import { A as compositionSourceKey, C as canonicalStoredBlockTarget, E as compositionFeatureEnabled, I as HelperMemberSchema, L as helperMembers, S as CompositionSchema, T as composedDeviceStableId, V as DAY_MS, _t as evaluateDwell, q as historyRetentionFromSettings, v as COMPOSER_ADDON_ID, w as composedDeviceRef } from "../../compile-OBMHlqD-.mjs";
|
|
18
|
-
import {
|
|
19
|
+
import { _ as zoneOnlySite, d as nextOccurrence, f as occurrenceOn, g as weekdayOfLocalDate, p as siteFor, u as localDateOf } from "../../time-window-BnUBULgu.mjs";
|
|
20
|
+
import { _ as stableIdMapOf, a as loadPrefixed, d as ConditionMirror, f as collectWhenMirrorSources, g as nextTimeBoundaryInMs, h as hasTimeLeaves, l as tagIdFromKey, m as hasHoldLeaves, n as EntityNotFoundError, o as unwrapStoredValue, p as evaluateWhenTree, r as NamedEntityStore, t as EntityNameTakenError } from "../../named-entity-store-DOnyyFFf.mjs";
|
|
19
21
|
import { t } from "../../l10n-Bu6aUvSY.mjs";
|
|
20
22
|
import { t as integrationInstancesCapability } from "../../integration-instances.cap-BWttO42A.mjs";
|
|
21
23
|
import { t as commandOrigin$1 } from "../../cap-call-context-DNwdgGSQ.mjs";
|
|
22
|
-
import { r as compileScalarOverride, t as describeCompositionSources } from "../../composition-sources-
|
|
24
|
+
import { r as compileScalarOverride, t as describeCompositionSources } from "../../composition-sources-CXxXfh1z.mjs";
|
|
23
25
|
import { r as seedInstanceOnce, t as DeclaredDevices } from "../../declared-device-CKERA1Hi.mjs";
|
|
24
26
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
25
27
|
import { i as capSeriesKey, m as parseConfirmedStateChanged, p as isRecord$1 } from "../../capture-engine-B2MmoNND.mjs";
|
|
@@ -1189,7 +1191,9 @@ function emitLeaf(trigger, path) {
|
|
|
1189
1191
|
function emitStepBody(action) {
|
|
1190
1192
|
switch (action.kind) {
|
|
1191
1193
|
case "wait": return ` await sleep(${j(action.seconds * 1e3)})`;
|
|
1192
|
-
case "command":
|
|
1194
|
+
case "command":
|
|
1195
|
+
if (action.onFor !== void 0) return ` await holdTargetOn(scope, ${j(action.target)}, ${j(action.actionId)}, ${j(action.onFor.seconds * 1e3)}, vars)`;
|
|
1196
|
+
return ` await actuateTarget(scope, ${j(action.target)}, ${j(action.actionId)}, ${j(action.args ?? {})}, vars)`;
|
|
1193
1197
|
case "action": return ` // an Action run, awaited: the step takes THAT run's outcome
|
|
1194
1198
|
await runActionBody(${j(action)}, {
|
|
1195
1199
|
...env,
|
|
@@ -1397,6 +1401,7 @@ function renderAutomationBlock(input) {
|
|
|
1397
1401
|
}] : []));
|
|
1398
1402
|
const hasTime = hasTimeLeaves(recipe.when) || recipe.actions.some((a) => stepConditionsOf(a).some(({ when }) => hasTimeLeaves(when)));
|
|
1399
1403
|
const hasWaitUntil = recipe.actions.some((a) => a.kind === "wait-until" || nestedStepsOf(a).some((n) => n.kind === "wait-until"));
|
|
1404
|
+
const hasOnFor = recipe.actions.some((a) => [a, ...nestedStepsOf(a)].some((n) => n.kind === "command" && n.onFor !== void 0));
|
|
1400
1405
|
const eventLeaves = [];
|
|
1401
1406
|
forEachLeaf(recipe.when, (leaf, path) => {
|
|
1402
1407
|
if (isEventLeaf(leaf)) eventLeaves.push({
|
|
@@ -1413,6 +1418,7 @@ function renderAutomationBlock(input) {
|
|
|
1413
1418
|
AutomationWhen,
|
|
1414
1419
|
AutomationStepTrace,
|
|
1415
1420
|
BodyEnv,
|
|
1421
|
+
OnForHold,
|
|
1416
1422
|
RunnableStep,
|
|
1417
1423
|
StepScope,
|
|
1418
1424
|
TimeSite,
|
|
@@ -1425,6 +1431,8 @@ import {
|
|
|
1425
1431
|
BecomesWatch,
|
|
1426
1432
|
ConditionMirror,
|
|
1427
1433
|
HoldTracker,
|
|
1434
|
+
OnForHolds,
|
|
1435
|
+
switchRunLimitOf,
|
|
1428
1436
|
DetectionTriggerFilter,
|
|
1429
1437
|
DeviceFiredWatch,
|
|
1430
1438
|
EventCategory,
|
|
@@ -1506,6 +1514,12 @@ const HAS_TIME = ${hasTime}
|
|
|
1506
1514
|
/** Guards (a step's \`if\`) with a \`for\`: they keep their own mirror and clocks, fed the same way. */
|
|
1507
1515
|
const GUARD_HOLD_TREES: ReadonlyArray<{ path: string; when: AutomationWhen }> = ${j(guardHoldTrees)}
|
|
1508
1516
|
|
|
1517
|
+
/** A command step holds its device on for a time: the block listens for that device's reports. */
|
|
1518
|
+
const HAS_ON_FOR = ${hasOnFor}
|
|
1519
|
+
|
|
1520
|
+
/** Where each holdable cap says "on". */
|
|
1521
|
+
const ON_FOR_FIELDS: Readonly<Record<string, string>> = { switch: 'on' }
|
|
1522
|
+
|
|
1509
1523
|
/** setTimeout cannot arm past 2^31-1 ms; a longer wait re-arms on wake. */
|
|
1510
1524
|
const MAX_TIMER_MS = 2_000_000_000
|
|
1511
1525
|
|
|
@@ -1631,8 +1645,10 @@ ${hasTime ? ` /** The site clock a \`time-is\` leaf reads: memory only at evalu
|
|
|
1631
1645
|
try {
|
|
1632
1646
|
const doc = await ctx.api.coreBlocks.getAutomationRunState.query({ blockId: BLOCK_ID })
|
|
1633
1647
|
lastRunStartedAt = doc.lastRunStartedAt
|
|
1648
|
+
onFor.restore(doc.onForHolds ?? [])
|
|
1634
1649
|
} catch (err: unknown) {
|
|
1635
1650
|
stampUnknown = true
|
|
1651
|
+
if (HAS_ON_FOR) retryOnForRestore(BLOCK_ID)
|
|
1636
1652
|
ctx.logger.warn('could not read the stored cooldown stamp — the first run is let through', {
|
|
1637
1653
|
blockId: BLOCK_ID,
|
|
1638
1654
|
error: err instanceof Error ? err.message : String(err),
|
|
@@ -1640,7 +1656,21 @@ ${hasTime ? ` /** The site clock a \`time-is\` leaf reads: memory only at evalu
|
|
|
1640
1656
|
}
|
|
1641
1657
|
}
|
|
1642
1658
|
|
|
1643
|
-
|
|
1659
|
+
/** The holds, written through the same ordered chain, but a failure REJECTS: the caller knows the hold is not durable. */
|
|
1660
|
+
function persistOnFor(holds: readonly OnForHold[]): Promise<void> {
|
|
1661
|
+
if (BLOCK_ID === null) return Promise.resolve()
|
|
1662
|
+
const blockId = BLOCK_ID
|
|
1663
|
+
const run = sendChain.then(() =>
|
|
1664
|
+
ctx.api.coreBlocks.reportAutomationRun.mutate({ blockId, keepTraces: KEEP_TRACES, onForHolds: [...holds] }),
|
|
1665
|
+
)
|
|
1666
|
+
sendChain = run.then(
|
|
1667
|
+
() => undefined,
|
|
1668
|
+
() => undefined,
|
|
1669
|
+
)
|
|
1670
|
+
return run.then(() => undefined)
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
function send(payload: { trace?: AutomationRunTrace; runStartedAt?: number; onForHolds?: OnForHold[] }): Promise<void> {
|
|
1644
1674
|
if (BLOCK_ID === null) return Promise.resolve()
|
|
1645
1675
|
const blockId = BLOCK_ID
|
|
1646
1676
|
sendChain = sendChain.then(async () => {
|
|
@@ -1866,6 +1896,125 @@ ${hasTime ? ` // a time-is leaf changes sides at a boundary with no device ev
|
|
|
1866
1896
|
await runForDevices(resolved.deviceIds, scope, (deviceId) => actuate(scope, deviceId, cap, method, callArgs, vars))
|
|
1867
1897
|
}
|
|
1868
1898
|
|
|
1899
|
+
/** "On for N" (on-for.ts): the devices this block turned on and owes an off. They outlive every run. */
|
|
1900
|
+
const onFor = new OnForHolds<ReturnType<typeof setTimeout>>({
|
|
1901
|
+
timers: {
|
|
1902
|
+
set: (fn, ms) => setTimeout(fn, Math.min(ms, MAX_TIMER_MS)),
|
|
1903
|
+
clear: (handle) => clearTimeout(handle),
|
|
1904
|
+
now: () => Date.now(),
|
|
1905
|
+
},
|
|
1906
|
+
readOn: async (deviceId, action) => {
|
|
1907
|
+
const read = await readField(deviceId, action.cap, action.fieldPath)
|
|
1908
|
+
return read.ok && typeof read.value === 'boolean' ? read.value : null
|
|
1909
|
+
},
|
|
1910
|
+
send: async (deviceId, actionId) => {
|
|
1911
|
+
const call = vocabCall(actionId, {})
|
|
1912
|
+
await callCap(deviceId, call.cap, call.method, call.args)
|
|
1913
|
+
ctx.logger.info('on-for: sent ' + actionId, { tags: { deviceId } })
|
|
1914
|
+
},
|
|
1915
|
+
persist: (holds) => persistOnFor(holds),
|
|
1916
|
+
// a hold never outlasts what the device may be kept on for (switch-run-limits.ts): cut at arming, stored holds too
|
|
1917
|
+
limitSecondsOf: async (deviceId) => {
|
|
1918
|
+
const [row] = await ctx.api.deviceManager.listAll.query({ deviceIds: [deviceId], projection: 'slim' })
|
|
1919
|
+
return row === undefined ? null : switchRunLimitOf(row.type, row.role).maxSeconds
|
|
1920
|
+
},
|
|
1921
|
+
onLimitUnknown: (deviceId) => {
|
|
1922
|
+
ctx.logger.warn('on-for: the device limit could not be read — the hold is kept as asked', {
|
|
1923
|
+
tags: { deviceId },
|
|
1924
|
+
})
|
|
1925
|
+
},
|
|
1926
|
+
onClamped: (deviceId, askedMs, limitMs) => {
|
|
1927
|
+
ctx.logger.warn('on-for: ' + askedMs / 1000 + ' s is over what the device may be held on — cut to ' + limitMs / 1000 + ' s', {
|
|
1928
|
+
tags: { deviceId },
|
|
1929
|
+
})
|
|
1930
|
+
},
|
|
1931
|
+
onError: (deviceId, what, err) => {
|
|
1932
|
+
ctx.logger.error('on-for: ' + what, {
|
|
1933
|
+
tags: { deviceId },
|
|
1934
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1935
|
+
})
|
|
1936
|
+
},
|
|
1937
|
+
onDropped: (hold, reason) => {
|
|
1938
|
+
ctx.logger.error('on-for: ' + reason + ' — the hold is given up, the device may still be on', {
|
|
1939
|
+
tags: { deviceId: hold.deviceId },
|
|
1940
|
+
})
|
|
1941
|
+
},
|
|
1942
|
+
})
|
|
1943
|
+
disposers.push(() => onFor.dispose())
|
|
1944
|
+
if (HAS_ON_FOR) {
|
|
1945
|
+
// a held device that reports "off" was switched by someone else: the hold ends
|
|
1946
|
+
disposers.push(
|
|
1947
|
+
ctx.eventBus.subscribe({ category: EventCategory.DeviceStateChanged }, (event) => {
|
|
1948
|
+
const deviceId = event.data['deviceId']
|
|
1949
|
+
if (typeof deviceId !== 'number') return
|
|
1950
|
+
const hold = onFor.list().find((h) => h.deviceId === deviceId)
|
|
1951
|
+
if (hold === undefined) return
|
|
1952
|
+
void readField(deviceId, hold.cap, ON_FOR_FIELDS[hold.cap] ?? 'on').then((read) => {
|
|
1953
|
+
if (read.ok && typeof read.value === 'boolean') onFor.observe(deviceId, hold.cap, read.value)
|
|
1954
|
+
})
|
|
1955
|
+
}),
|
|
1956
|
+
)
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
/** The stored holds could not be read at start: asked again until the hub answers. */
|
|
1960
|
+
function retryOnForRestore(blockId: string): void {
|
|
1961
|
+
const timer = setTimeout(() => {
|
|
1962
|
+
if (stopped) return
|
|
1963
|
+
ctx.api.coreBlocks.getAutomationRunState.query({ blockId }).then(
|
|
1964
|
+
(doc) => onFor.restore(doc.onForHolds ?? []),
|
|
1965
|
+
() => retryOnForRestore(blockId),
|
|
1966
|
+
)
|
|
1967
|
+
}, RECONCILE_MS)
|
|
1968
|
+
disposers.push(() => clearTimeout(timer))
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
async function holdTargetOn(
|
|
1972
|
+
scope: StepScope,
|
|
1973
|
+
target: ActionTarget,
|
|
1974
|
+
actionId: string,
|
|
1975
|
+
ms: number,
|
|
1976
|
+
vars: Record<string, unknown>,
|
|
1977
|
+
): Promise<void> {
|
|
1978
|
+
const resolved = await targets.resolve(target, actionId, vars, {
|
|
1979
|
+
actionId,
|
|
1980
|
+
owner: BLOCK_ID ?? undefined,
|
|
1981
|
+
})
|
|
1982
|
+
if (resolved.deviceIds.length === 0) {
|
|
1983
|
+
scope.markEmpty(resolved.emptyReason ?? 'the target matched no device')
|
|
1984
|
+
return
|
|
1985
|
+
}
|
|
1986
|
+
const hold = async (deviceId: number): Promise<void> => {
|
|
1987
|
+
const outcome = await onFor.trigger(deviceId, actionId, ms)
|
|
1988
|
+
scope.setArgs({ onForMs: ms, outcome })
|
|
1989
|
+
const tags = { tags: { deviceId } }
|
|
1990
|
+
switch (outcome) {
|
|
1991
|
+
case 'turned-on':
|
|
1992
|
+
ctx.logger.info('on-for: turned on, off in ' + ms / 1000 + ' s', tags)
|
|
1993
|
+
return
|
|
1994
|
+
case 'extended':
|
|
1995
|
+
ctx.logger.info('on-for: the time restarts, off in ' + ms / 1000 + ' s', tags)
|
|
1996
|
+
return
|
|
1997
|
+
case 'already-on':
|
|
1998
|
+
ctx.logger.info('on-for: already on — nothing sent, and it will not be turned off', tags)
|
|
1999
|
+
return
|
|
2000
|
+
case 'unknown':
|
|
2001
|
+
ctx.logger.warn('on-for: the state could not be read — nothing sent', tags)
|
|
2002
|
+
throw new Error('the device state could not be read')
|
|
2003
|
+
case 'failed':
|
|
2004
|
+
throw new Error('the device could not be turned on')
|
|
2005
|
+
case 'not-holdable':
|
|
2006
|
+
throw new Error(actionId + ' cannot be held on for a time')
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
const [only] = resolved.deviceIds
|
|
2010
|
+
if (resolved.deviceIds.length === 1 && only !== undefined) {
|
|
2011
|
+
scope.setDeviceId(only)
|
|
2012
|
+
await hold(only)
|
|
2013
|
+
return
|
|
2014
|
+
}
|
|
2015
|
+
await runForDevices(resolved.deviceIds, scope, hold)
|
|
2016
|
+
}
|
|
2017
|
+
|
|
1869
2018
|
function warnMissingVar(name: string): void {
|
|
1870
2019
|
ctx.logger.warn('template referenced a var that was never set', { var: name })
|
|
1871
2020
|
}
|
|
@@ -1911,6 +2060,16 @@ ${hasTime ? ` // a time-is leaf changes sides at a boundary with no device ev
|
|
|
1911
2060
|
const resolved: Record<string, unknown> =
|
|
1912
2061
|
substituted !== null && typeof substituted === 'object' ? { ...substituted } : {}
|
|
1913
2062
|
scope.setArgs(resolved)
|
|
2063
|
+
await callCap(deviceId, cap, method, resolved)
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
/** One device method call, through the cap's router. */
|
|
2067
|
+
async function callCap(
|
|
2068
|
+
deviceId: number,
|
|
2069
|
+
cap: string,
|
|
2070
|
+
method: string,
|
|
2071
|
+
resolved: Record<string, unknown>,
|
|
2072
|
+
): Promise<void> {
|
|
1914
2073
|
// Forked-addon ctx.api namespaces are tRPC Proxies over a noop function
|
|
1915
2074
|
// (typeof === 'function'), not plain objects — reject only null/undefined.
|
|
1916
2075
|
const client: unknown = Reflect.get(ctx.api, capToRouterKey(cap))
|
|
@@ -3477,15 +3636,25 @@ var BUILTIN_REMOTE_COMPONENTS = [
|
|
|
3477
3636
|
* traces and run modes apply; the template only fixes the shape. The operator
|
|
3478
3637
|
* reads and writes it from the COMMANDED device's Customize tab.
|
|
3479
3638
|
*
|
|
3480
|
-
*
|
|
3481
|
-
* part, event, shared kind and payload predicates)
|
|
3482
|
-
*
|
|
3483
|
-
*
|
|
3484
|
-
*
|
|
3639
|
+
* A source is something that HAPPENS: a device that fired (`device-fired`,
|
|
3640
|
+
* optionally one part, event, shared kind and payload predicates), a device
|
|
3641
|
+
* event of a category, a device field taking a value (`device-becomes`: motion
|
|
3642
|
+
* detected), or a camera detecting a class (`detection`). The action is a plain
|
|
3643
|
+
* on, off or toggle of one capability of the target. "On" may be held for a
|
|
3644
|
+
* time (`onForSeconds`): the engine turns the target on only if it is off and
|
|
3645
|
+
* off again when the time is up, each new event restarting the time
|
|
3646
|
+
* (`automation/on-for.ts`). An optional time window limits when it runs. A
|
|
3647
|
+
* linked trigger commands the target; it never claims the target's state (that
|
|
3648
|
+
* belongs to the target's own provider, D663).
|
|
3485
3649
|
*/
|
|
3486
3650
|
var LINKED_TRIGGER_TEMPLATE_ID = "builtin:linked-trigger";
|
|
3487
3651
|
/** The input key whose value is the commanded device: the read keys on it. */
|
|
3488
3652
|
var LINKED_TRIGGER_TARGET_INPUT = "target";
|
|
3653
|
+
/** The template input keys of the optional duration and time window. */
|
|
3654
|
+
var LINKED_TRIGGER_ON_FOR_INPUT = "onFor";
|
|
3655
|
+
var LINKED_TRIGGER_WINDOW_INPUT = "active";
|
|
3656
|
+
/** The optional limit on the state of a device (a derived "is night"). */
|
|
3657
|
+
var LINKED_TRIGGER_STATE_INPUT = "activeWhen";
|
|
3489
3658
|
//#endregion
|
|
3490
3659
|
//#region ../types/dist/esm/template/builtin-automation-templates.mjs
|
|
3491
3660
|
/**
|
|
@@ -3497,114 +3666,13 @@ var LINKED_TRIGGER_TARGET_INPUT = "target";
|
|
|
3497
3666
|
*/
|
|
3498
3667
|
var BUILTIN_TEMPLATE_ID_PREFIX = "builtin:";
|
|
3499
3668
|
/** The optional limit a built-in ends with: no value, no limit. */
|
|
3500
|
-
var ACTIVE_WINDOW_KEY =
|
|
3669
|
+
var ACTIVE_WINDOW_KEY = LINKED_TRIGGER_WINDOW_INPUT;
|
|
3501
3670
|
var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
3502
|
-
id: `${BUILTIN_TEMPLATE_ID_PREFIX}motion-light`,
|
|
3503
|
-
name: "Motion → light, off after a delay",
|
|
3504
|
-
payload: {
|
|
3505
|
-
version: 1,
|
|
3506
|
-
description: "Turns lights on when a motion sensor detects motion and off once it has been quiet for the delay. New motion restarts the delay.",
|
|
3507
|
-
body: {
|
|
3508
|
-
when: {
|
|
3509
|
-
kind: "device-becomes",
|
|
3510
|
-
cap: "motion",
|
|
3511
|
-
fieldPath: "detected",
|
|
3512
|
-
becomes: true
|
|
3513
|
-
},
|
|
3514
|
-
actions: [
|
|
3515
|
-
{
|
|
3516
|
-
kind: "command",
|
|
3517
|
-
actionId: "switch.on"
|
|
3518
|
-
},
|
|
3519
|
-
{
|
|
3520
|
-
kind: "wait",
|
|
3521
|
-
seconds: 300
|
|
3522
|
-
},
|
|
3523
|
-
{
|
|
3524
|
-
kind: "command",
|
|
3525
|
-
actionId: "switch.off"
|
|
3526
|
-
}
|
|
3527
|
-
],
|
|
3528
|
-
runMode: { mode: "restart" }
|
|
3529
|
-
},
|
|
3530
|
-
inputs: [
|
|
3531
|
-
{
|
|
3532
|
-
kind: "device",
|
|
3533
|
-
key: "sensor",
|
|
3534
|
-
label: "Motion sensor",
|
|
3535
|
-
filter: { capability: "motion" }
|
|
3536
|
-
},
|
|
3537
|
-
{
|
|
3538
|
-
kind: "device",
|
|
3539
|
-
key: "lights",
|
|
3540
|
-
label: "Lights",
|
|
3541
|
-
multiple: true,
|
|
3542
|
-
filter: { capability: "switch" }
|
|
3543
|
-
},
|
|
3544
|
-
{
|
|
3545
|
-
kind: "duration",
|
|
3546
|
-
key: "delay",
|
|
3547
|
-
label: "Off after (seconds)",
|
|
3548
|
-
min: 10,
|
|
3549
|
-
max: 3600,
|
|
3550
|
-
default: 300
|
|
3551
|
-
},
|
|
3552
|
-
{
|
|
3553
|
-
kind: "time-window",
|
|
3554
|
-
key: ACTIVE_WINDOW_KEY,
|
|
3555
|
-
label: "Only when",
|
|
3556
|
-
description: "Limit the automation to a time of day, to some days, or both.",
|
|
3557
|
-
optional: true
|
|
3558
|
-
}
|
|
3559
|
-
],
|
|
3560
|
-
bindings: [
|
|
3561
|
-
{
|
|
3562
|
-
kind: "value",
|
|
3563
|
-
input: "sensor",
|
|
3564
|
-
path: ["when", "deviceId"]
|
|
3565
|
-
},
|
|
3566
|
-
{
|
|
3567
|
-
kind: "value",
|
|
3568
|
-
input: "lights",
|
|
3569
|
-
path: [
|
|
3570
|
-
"actions",
|
|
3571
|
-
0,
|
|
3572
|
-
"target"
|
|
3573
|
-
],
|
|
3574
|
-
as: "target"
|
|
3575
|
-
},
|
|
3576
|
-
{
|
|
3577
|
-
kind: "value",
|
|
3578
|
-
input: "delay",
|
|
3579
|
-
path: [
|
|
3580
|
-
"actions",
|
|
3581
|
-
1,
|
|
3582
|
-
"seconds"
|
|
3583
|
-
]
|
|
3584
|
-
},
|
|
3585
|
-
{
|
|
3586
|
-
kind: "value",
|
|
3587
|
-
input: "lights",
|
|
3588
|
-
path: [
|
|
3589
|
-
"actions",
|
|
3590
|
-
2,
|
|
3591
|
-
"target"
|
|
3592
|
-
],
|
|
3593
|
-
as: "target"
|
|
3594
|
-
},
|
|
3595
|
-
{
|
|
3596
|
-
kind: "gate",
|
|
3597
|
-
input: ACTIVE_WINDOW_KEY,
|
|
3598
|
-
path: ["when"]
|
|
3599
|
-
}
|
|
3600
|
-
]
|
|
3601
|
-
}
|
|
3602
|
-
}, {
|
|
3603
3671
|
id: LINKED_TRIGGER_TEMPLATE_ID,
|
|
3604
3672
|
name: "Linked trigger",
|
|
3605
3673
|
payload: {
|
|
3606
3674
|
version: 1,
|
|
3607
|
-
description: "Commands one device (on, off or
|
|
3675
|
+
description: "Commands one device (on, off, toggle, or on for a time) when a device fires an event, reports a state or a camera detects a class.",
|
|
3608
3676
|
body: {
|
|
3609
3677
|
when: {
|
|
3610
3678
|
kind: "any",
|
|
@@ -3633,8 +3701,36 @@ var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
|
3633
3701
|
key: "when",
|
|
3634
3702
|
label: "When",
|
|
3635
3703
|
entry: "trigger",
|
|
3636
|
-
allow: [
|
|
3704
|
+
allow: [
|
|
3705
|
+
"device-fired",
|
|
3706
|
+
"device-event",
|
|
3707
|
+
"device-becomes",
|
|
3708
|
+
"detection"
|
|
3709
|
+
],
|
|
3637
3710
|
maxItems: 10
|
|
3711
|
+
},
|
|
3712
|
+
{
|
|
3713
|
+
kind: "duration",
|
|
3714
|
+
key: LINKED_TRIGGER_ON_FOR_INPUT,
|
|
3715
|
+
label: "On for (seconds)",
|
|
3716
|
+
description: "Turns it on only if it is off, and off again after this long. A new event restarts the time.",
|
|
3717
|
+
min: 1,
|
|
3718
|
+
max: ON_FOR_MAX_SECONDS,
|
|
3719
|
+
optional: true
|
|
3720
|
+
},
|
|
3721
|
+
{
|
|
3722
|
+
kind: "time-window",
|
|
3723
|
+
key: ACTIVE_WINDOW_KEY,
|
|
3724
|
+
label: "Only when",
|
|
3725
|
+
description: "Limit the automation to a time of day, to some days, or both.",
|
|
3726
|
+
optional: true
|
|
3727
|
+
},
|
|
3728
|
+
{
|
|
3729
|
+
kind: "device-state",
|
|
3730
|
+
key: LINKED_TRIGGER_STATE_INPUT,
|
|
3731
|
+
label: "Only while",
|
|
3732
|
+
description: "Limit the automation to while a device reads a value, such as a derived night.",
|
|
3733
|
+
optional: true
|
|
3638
3734
|
}
|
|
3639
3735
|
],
|
|
3640
3736
|
bindings: [
|
|
@@ -3657,6 +3753,26 @@ var BUILTIN_AUTOMATION_TEMPLATES = [{
|
|
|
3657
3753
|
kind: "entries",
|
|
3658
3754
|
input: "when",
|
|
3659
3755
|
path: ["when", "children"]
|
|
3756
|
+
},
|
|
3757
|
+
{
|
|
3758
|
+
kind: "value",
|
|
3759
|
+
input: LINKED_TRIGGER_ON_FOR_INPUT,
|
|
3760
|
+
path: [
|
|
3761
|
+
"actions",
|
|
3762
|
+
0,
|
|
3763
|
+
"onFor",
|
|
3764
|
+
"seconds"
|
|
3765
|
+
]
|
|
3766
|
+
},
|
|
3767
|
+
{
|
|
3768
|
+
kind: "gate",
|
|
3769
|
+
input: ACTIVE_WINDOW_KEY,
|
|
3770
|
+
path: ["when"]
|
|
3771
|
+
},
|
|
3772
|
+
{
|
|
3773
|
+
kind: "gate",
|
|
3774
|
+
input: LINKED_TRIGGER_STATE_INPUT,
|
|
3775
|
+
path: ["when"]
|
|
3660
3776
|
}
|
|
3661
3777
|
]
|
|
3662
3778
|
}
|
|
@@ -8472,13 +8588,16 @@ var BlockSupervisor = class {
|
|
|
8472
8588
|
* then never re-launch it.
|
|
8473
8589
|
*/
|
|
8474
8590
|
/**
|
|
8475
|
-
* The block row is already gone.
|
|
8476
|
-
* claims are released before this resolves.
|
|
8477
|
-
*
|
|
8591
|
+
* The block row is already gone. ONE composer apply names it retired so its
|
|
8592
|
+
* claims are released before this resolves. It is NOT queued on the converge
|
|
8593
|
+
* chain: that chain also launches, stops and reports every code block, and a
|
|
8594
|
+
* delete waiting behind a pass that is compiling or spawning one paid for all
|
|
8595
|
+
* of it. The composer serialises its own applies, so this one is ordered
|
|
8596
|
+
* against a concurrent pass there. A release that does not land is returned;
|
|
8597
|
+
* the id stays retired so the following pass tries again.
|
|
8478
8598
|
*/
|
|
8479
8599
|
retireComposition(blockId) {
|
|
8480
|
-
this.
|
|
8481
|
-
return this.converge().then(() => this.claimsOf(blockId));
|
|
8600
|
+
return this.releaseRetired(blockId);
|
|
8482
8601
|
}
|
|
8483
8602
|
/**
|
|
8484
8603
|
* One apply, awaited. Used when an edit replaced a block's caps: the
|
|
@@ -8561,7 +8680,7 @@ var BlockSupervisor = class {
|
|
|
8561
8680
|
}
|
|
8562
8681
|
await this.launch(block);
|
|
8563
8682
|
}
|
|
8564
|
-
await this.convergeCompositions(
|
|
8683
|
+
await this.convergeCompositions(snapshots);
|
|
8565
8684
|
}
|
|
8566
8685
|
/**
|
|
8567
8686
|
* Send every composition placed here to the composer and mirror its verdicts
|
|
@@ -8569,8 +8688,8 @@ var BlockSupervisor = class {
|
|
|
8569
8688
|
* does not trust its store or seed yet) is mirrored as `starting`; the next
|
|
8570
8689
|
* pass of this same converge is the retry — no timer of its own (D3).
|
|
8571
8690
|
*/
|
|
8572
|
-
async convergeCompositions(
|
|
8573
|
-
const compositions =
|
|
8691
|
+
async convergeCompositions(runners) {
|
|
8692
|
+
const compositions = this.deps.store.list().flatMap((block) => {
|
|
8574
8693
|
const composition = coreBlockComposition(block);
|
|
8575
8694
|
return composition !== null && this.isPlacedHere(block) ? [{
|
|
8576
8695
|
block,
|
|
@@ -8594,6 +8713,7 @@ var BlockSupervisor = class {
|
|
|
8594
8713
|
return;
|
|
8595
8714
|
}
|
|
8596
8715
|
const restart = this.pendingCompositionRestarts;
|
|
8716
|
+
const sentRetired = this.retiredBlockIds;
|
|
8597
8717
|
const integrationId = this.deps.integrationId();
|
|
8598
8718
|
const storeLoaded = this.deps.storeLoaded();
|
|
8599
8719
|
try {
|
|
@@ -8609,7 +8729,7 @@ var BlockSupervisor = class {
|
|
|
8609
8729
|
})),
|
|
8610
8730
|
restartBlockIds: [...restart],
|
|
8611
8731
|
unreadableBlocks: [...unreadable],
|
|
8612
|
-
retiredBlockIds: [...
|
|
8732
|
+
retiredBlockIds: [...sentRetired]
|
|
8613
8733
|
});
|
|
8614
8734
|
if (this.failedApplies > 0) {
|
|
8615
8735
|
this.deps.logger.info("the composer answered again", { meta: { failedApplies: this.failedApplies } });
|
|
@@ -8617,7 +8737,7 @@ var BlockSupervisor = class {
|
|
|
8617
8737
|
}
|
|
8618
8738
|
this.pendingCompositionRestarts = new Set([...this.pendingCompositionRestarts].filter((id) => !restart.has(id)));
|
|
8619
8739
|
this.emptyAppliesOwed = !nothingToSay || !result.acted ? 2 : Math.max(0, this.emptyAppliesOwed - 1);
|
|
8620
|
-
this.noteRelease(result);
|
|
8740
|
+
this.noteRelease(result, sentRetired);
|
|
8621
8741
|
const verdicts = new Map(result.blocks.map((v) => [v.blockId, v]));
|
|
8622
8742
|
for (const { block } of compositions) {
|
|
8623
8743
|
const verdict = verdicts.get(block.id);
|
|
@@ -8638,12 +8758,57 @@ var BlockSupervisor = class {
|
|
|
8638
8758
|
for (const { block } of compositions) if (block.status === "stopped" && block.enabled) await this.report(block.id, "starting", `the composer is not reachable yet: ${error}`);
|
|
8639
8759
|
}
|
|
8640
8760
|
}
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
|
|
8761
|
+
async releaseRetired(blockId) {
|
|
8762
|
+
const composer = this.deps.composer;
|
|
8763
|
+
if (composer === null) throw new Error(`core-blocks: claims of "${blockId}" were not released — no composer is available on this node — claims cannot be released`);
|
|
8764
|
+
const sent = new Set([...this.retiredBlockIds, blockId]);
|
|
8765
|
+
this.retiredBlockIds = sent;
|
|
8766
|
+
let result;
|
|
8767
|
+
try {
|
|
8768
|
+
result = await composer.apply(this.compositionApplyInput(/* @__PURE__ */ new Set(), sent));
|
|
8769
|
+
} catch (err) {
|
|
8770
|
+
throw new Error(`core-blocks: claims of "${blockId}" were not released — ${errMsg$1(err)}`, { cause: err });
|
|
8771
|
+
}
|
|
8772
|
+
const unreleased = result.unreleasedClaims ?? [];
|
|
8773
|
+
if (!result.acted) throw new Error(`core-blocks: claims of "${blockId}" were not released — the composer did not apply — claims stay until it does`);
|
|
8774
|
+
this.settleRetired(sent, unreleased);
|
|
8775
|
+
return unreleased.filter((claim) => claim.owner === blockId);
|
|
8776
|
+
}
|
|
8777
|
+
/**
|
|
8778
|
+
* After an apply that acted: an id it SENT stays retired only while it still
|
|
8779
|
+
* holds a claim; an id added meanwhile (not in `sent`) is left alone — a
|
|
8780
|
+
* concurrent apply must not forget a retirement it never carried.
|
|
8781
|
+
*/
|
|
8782
|
+
settleRetired(sent, unreleased) {
|
|
8783
|
+
const failed = new Set(unreleased.map((claim) => claim.owner));
|
|
8784
|
+
this.retiredBlockIds = new Set([...this.retiredBlockIds].filter((id) => !sent.has(id) || failed.has(id)));
|
|
8785
|
+
}
|
|
8786
|
+
/** What one composer apply carries: every composition placed here, plus the retired ids. */
|
|
8787
|
+
compositionApplyInput(restart, retired) {
|
|
8788
|
+
const compositions = this.deps.store.list().flatMap((block) => {
|
|
8789
|
+
const composition = coreBlockComposition(block);
|
|
8790
|
+
return composition !== null && this.isPlacedHere(block) ? [{
|
|
8791
|
+
block,
|
|
8792
|
+
composition
|
|
8793
|
+
}] : [];
|
|
8794
|
+
});
|
|
8795
|
+
return {
|
|
8796
|
+
integrationId: this.deps.integrationId(),
|
|
8797
|
+
storeLoaded: this.deps.storeLoaded(),
|
|
8798
|
+
blocks: compositions.map(({ block, composition }) => ({
|
|
8799
|
+
id: block.id,
|
|
8800
|
+
name: block.name,
|
|
8801
|
+
enabled: block.enabled,
|
|
8802
|
+
updatedAt: block.updatedAt,
|
|
8803
|
+
composition
|
|
8804
|
+
})),
|
|
8805
|
+
restartBlockIds: [...restart],
|
|
8806
|
+
unreadableBlocks: [...this.deps.store.unreadableCompositions()],
|
|
8807
|
+
retiredBlockIds: [...retired]
|
|
8808
|
+
};
|
|
8644
8809
|
}
|
|
8645
8810
|
/** Remember which retired ids still hold a claim. An apply that did not act keeps every id. */
|
|
8646
|
-
noteRelease(result) {
|
|
8811
|
+
noteRelease(result, sent) {
|
|
8647
8812
|
const unreleased = result.unreleasedClaims ?? [];
|
|
8648
8813
|
if (!result.acted) {
|
|
8649
8814
|
this.releaseReport = {
|
|
@@ -8656,8 +8821,7 @@ var BlockSupervisor = class {
|
|
|
8656
8821
|
error: null,
|
|
8657
8822
|
unreleased
|
|
8658
8823
|
};
|
|
8659
|
-
|
|
8660
|
-
this.retiredBlockIds = new Set([...this.retiredBlockIds].filter((id) => failed.has(id)));
|
|
8824
|
+
this.settleRetired(sent, unreleased);
|
|
8661
8825
|
}
|
|
8662
8826
|
/** Compile, write the package, spawn. Each failure is reported ON the block
|
|
8663
8827
|
* — the author asked for this to run, so they are owed the reason it does
|
|
@@ -8770,6 +8934,7 @@ var ActionRowBodySchema = z.object({
|
|
|
8770
8934
|
variables: z.array(ActionVariableSchema).max(20).optional(),
|
|
8771
8935
|
minDelaySec: ActionMinDelaySecSchema.optional(),
|
|
8772
8936
|
tags: TagsFieldSchema.optional(),
|
|
8937
|
+
tagIds: TagIdsFieldSchema.optional(),
|
|
8773
8938
|
createdAt: z.number(),
|
|
8774
8939
|
updatedAt: z.number()
|
|
8775
8940
|
});
|
|
@@ -8781,10 +8946,12 @@ var TemplateRowBodySchema = z.object({
|
|
|
8781
8946
|
name: z.string().min(1).max(120),
|
|
8782
8947
|
payload: z.unknown(),
|
|
8783
8948
|
tags: TagsFieldSchema.optional(),
|
|
8949
|
+
tagIds: TagIdsFieldSchema.optional(),
|
|
8784
8950
|
createdAt: z.number(),
|
|
8785
8951
|
updatedAt: z.number()
|
|
8786
8952
|
});
|
|
8787
8953
|
var TagStyleRowBodySchema = TagStyleSchema;
|
|
8954
|
+
var TagRowBodySchema = TagBodySchema;
|
|
8788
8955
|
var _coreBlocksRecordKinds = defineRecordKinds({
|
|
8789
8956
|
"timed-runs": {
|
|
8790
8957
|
schema: z.object({
|
|
@@ -8870,13 +9037,21 @@ var _coreBlocksRecordKinds = defineRecordKinds({
|
|
|
8870
9037
|
retention: { none: "operator delete only; a template a device still uses is refused" },
|
|
8871
9038
|
maxDataBytes: 256 * 1024
|
|
8872
9039
|
},
|
|
9040
|
+
tags: {
|
|
9041
|
+
schema: TagRowBodySchema,
|
|
9042
|
+
class: "config",
|
|
9043
|
+
writeTrigger: "ensureTag / updateTag / deleteTag, and the tags-as-records migration (D1089)",
|
|
9044
|
+
device: "none",
|
|
9045
|
+
at: "none",
|
|
9046
|
+
retention: { none: "operator action only: deleting the tag" }
|
|
9047
|
+
},
|
|
8873
9048
|
"tag-styles": {
|
|
8874
9049
|
schema: TagStyleRowBodySchema,
|
|
8875
9050
|
class: "config",
|
|
8876
|
-
writeTrigger: "
|
|
9051
|
+
writeTrigger: "legacy only — the tags-as-records migration reads then deletes rows (D1089)",
|
|
8877
9052
|
device: "none",
|
|
8878
9053
|
at: "none",
|
|
8879
|
-
retention: { none: "
|
|
9054
|
+
retention: { none: "rows deleted by the tags-as-records migration" }
|
|
8880
9055
|
},
|
|
8881
9056
|
settings: {
|
|
8882
9057
|
schema: CoreBlockSettingsBodySchema,
|
|
@@ -9955,6 +10130,19 @@ var CoreBlockStore = class CoreBlockStore {
|
|
|
9955
10130
|
await this.persist(next);
|
|
9956
10131
|
this.byId.set(next.id, next);
|
|
9957
10132
|
}
|
|
10133
|
+
/** Replace the tag ids of a block (D1089); everything else is left as it is. */
|
|
10134
|
+
async setTagIds(blockId, tagIds) {
|
|
10135
|
+
const existing = this.byId.get(blockId);
|
|
10136
|
+
if (!existing) throw new Error(`core block not found: ${blockId}`);
|
|
10137
|
+
const { tagIds: _previous, ...rest } = existing;
|
|
10138
|
+
const unique = [...new Set(tagIds)];
|
|
10139
|
+
const next = CoreBlockSchema.parse(unique.length === 0 ? rest : {
|
|
10140
|
+
...rest,
|
|
10141
|
+
tagIds: unique
|
|
10142
|
+
});
|
|
10143
|
+
await this.persist(next);
|
|
10144
|
+
this.byId.set(next.id, next);
|
|
10145
|
+
}
|
|
9958
10146
|
/**
|
|
9959
10147
|
* Store a composition block (D659): hub-placed, no code, never `running` on
|
|
9960
10148
|
* creation — the composer's verdict, mirrored by the supervisor, says that.
|
|
@@ -10786,6 +10974,260 @@ async function splitPumpCycleFromFountain(ports) {
|
|
|
10786
10974
|
};
|
|
10787
10975
|
}
|
|
10788
10976
|
//#endregion
|
|
10977
|
+
//#region src/builtins/core-blocks/migrations/tag-ids.ts
|
|
10978
|
+
/**
|
|
10979
|
+
* Every core-blocks record that carries tags gets the ids of those tags (D1089, the
|
|
10980
|
+
* core-blocks step of the tags migration): `tagIds` is added beside the kept `tags` names,
|
|
10981
|
+
* aligned by index, each id derived from the folded name (`tagIdFromKey`) so the device
|
|
10982
|
+
* manager and the notification rules mint the same id for the same name without reading each
|
|
10983
|
+
* other. The names stay for one release.
|
|
10984
|
+
*
|
|
10985
|
+
* Four owners: core blocks (the tags sit on the block inside the row body), schedulers,
|
|
10986
|
+
* templates and actions. A row with no tags, or one that already has `tagIds`, is left
|
|
10987
|
+
* alone, so a rerun edits nothing. A row whose names repeat one tag in two spellings is
|
|
10988
|
+
* rewritten with both fields de-duplicated, so the index alignment holds. Each row is
|
|
10989
|
+
* replaced only if it is still at the revision that was read; a row changed meanwhile fails
|
|
10990
|
+
* the run, which retries on the next boot.
|
|
10991
|
+
*/
|
|
10992
|
+
var CORE_BLOCKS_TAG_IDS_ID = "core-blocks/2026-11-23-tag-ids";
|
|
10993
|
+
function stringList(value) {
|
|
10994
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
10995
|
+
}
|
|
10996
|
+
function tagsOfBlock(block) {
|
|
10997
|
+
return {
|
|
10998
|
+
tags: stringList(block["tags"]),
|
|
10999
|
+
hasTagIds: Array.isArray(block["tagIds"])
|
|
11000
|
+
};
|
|
11001
|
+
}
|
|
11002
|
+
function tagIdsPortsOver(kinds, logger) {
|
|
11003
|
+
const rowOf = (owner, row, tags, hasTagIds) => ({
|
|
11004
|
+
owner,
|
|
11005
|
+
id: row.id,
|
|
11006
|
+
rev: row.rev,
|
|
11007
|
+
tags,
|
|
11008
|
+
hasTagIds
|
|
11009
|
+
});
|
|
11010
|
+
return {
|
|
11011
|
+
listTaggedRows: async () => {
|
|
11012
|
+
const blocks = (await (0, import_read_all_rows.readAllRows)(kinds.blocks)).map((row) => {
|
|
11013
|
+
const { tags, hasTagIds } = tagsOfBlock(row.data.block);
|
|
11014
|
+
return rowOf("blocks", row, tags, hasTagIds);
|
|
11015
|
+
});
|
|
11016
|
+
const schedulers = (await (0, import_read_all_rows.readAllRows)(kinds.schedulers)).map((row) => rowOf("schedulers", row, row.data.tags ?? [], row.data.tagIds !== void 0));
|
|
11017
|
+
const templates = (await (0, import_read_all_rows.readAllRows)(kinds.templates)).map((row) => rowOf("templates", row, row.data.tags ?? [], row.data.tagIds !== void 0));
|
|
11018
|
+
const actions = (await (0, import_read_all_rows.readAllRows)(kinds.actions)).map((row) => rowOf("actions", row, row.data.tags ?? [], row.data.tagIds !== void 0));
|
|
11019
|
+
return [
|
|
11020
|
+
...blocks,
|
|
11021
|
+
...schedulers,
|
|
11022
|
+
...templates,
|
|
11023
|
+
...actions
|
|
11024
|
+
];
|
|
11025
|
+
},
|
|
11026
|
+
writeTagIds: async (row, tagIds, tags) => {
|
|
11027
|
+
const ids = [...tagIds];
|
|
11028
|
+
const names = tags === null ? null : [...tags];
|
|
11029
|
+
switch (row.owner) {
|
|
11030
|
+
case "blocks": {
|
|
11031
|
+
const current = await kinds.blocks.get(row.id);
|
|
11032
|
+
if (current === null || current.rev !== row.rev) throw movedError(row);
|
|
11033
|
+
const block = {
|
|
11034
|
+
...current.data.block,
|
|
11035
|
+
tagIds: ids,
|
|
11036
|
+
...names === null ? {} : { tags: names }
|
|
11037
|
+
};
|
|
11038
|
+
await kinds.blocks.put({
|
|
11039
|
+
id: row.id,
|
|
11040
|
+
data: {
|
|
11041
|
+
...current.data,
|
|
11042
|
+
block
|
|
11043
|
+
}
|
|
11044
|
+
}, { ifRev: row.rev });
|
|
11045
|
+
return;
|
|
11046
|
+
}
|
|
11047
|
+
case "schedulers": {
|
|
11048
|
+
const current = await kinds.schedulers.get(row.id);
|
|
11049
|
+
if (current === null || current.rev !== row.rev) throw movedError(row);
|
|
11050
|
+
await kinds.schedulers.put({
|
|
11051
|
+
id: row.id,
|
|
11052
|
+
data: {
|
|
11053
|
+
...current.data,
|
|
11054
|
+
tagIds: ids,
|
|
11055
|
+
...names === null ? {} : { tags: names }
|
|
11056
|
+
}
|
|
11057
|
+
}, { ifRev: row.rev });
|
|
11058
|
+
return;
|
|
11059
|
+
}
|
|
11060
|
+
case "templates": {
|
|
11061
|
+
const current = await kinds.templates.get(row.id);
|
|
11062
|
+
if (current === null || current.rev !== row.rev) throw movedError(row);
|
|
11063
|
+
await kinds.templates.put({
|
|
11064
|
+
id: row.id,
|
|
11065
|
+
data: {
|
|
11066
|
+
...current.data,
|
|
11067
|
+
tagIds: ids,
|
|
11068
|
+
...names === null ? {} : { tags: names }
|
|
11069
|
+
}
|
|
11070
|
+
}, { ifRev: row.rev });
|
|
11071
|
+
return;
|
|
11072
|
+
}
|
|
11073
|
+
case "actions": {
|
|
11074
|
+
const current = await kinds.actions.get(row.id);
|
|
11075
|
+
if (current === null || current.rev !== row.rev) throw movedError(row);
|
|
11076
|
+
await kinds.actions.put({
|
|
11077
|
+
id: row.id,
|
|
11078
|
+
data: {
|
|
11079
|
+
...current.data,
|
|
11080
|
+
tagIds: ids,
|
|
11081
|
+
...names === null ? {} : { tags: names }
|
|
11082
|
+
}
|
|
11083
|
+
}, { ifRev: row.rev });
|
|
11084
|
+
return;
|
|
11085
|
+
}
|
|
11086
|
+
}
|
|
11087
|
+
},
|
|
11088
|
+
info: (message, meta) => {
|
|
11089
|
+
logger.info(message, { meta });
|
|
11090
|
+
}
|
|
11091
|
+
};
|
|
11092
|
+
}
|
|
11093
|
+
function movedError(row) {
|
|
11094
|
+
return /* @__PURE__ */ new Error(`${row.owner} record ${row.id} changed since it was read`);
|
|
11095
|
+
}
|
|
11096
|
+
async function addTagIds(ports) {
|
|
11097
|
+
const rows = await ports.listTaggedRows();
|
|
11098
|
+
let written = 0;
|
|
11099
|
+
for (const row of rows) {
|
|
11100
|
+
if (row.hasTagIds) continue;
|
|
11101
|
+
const names = normalizeTags(row.tags);
|
|
11102
|
+
if (names.length === 0) continue;
|
|
11103
|
+
const sameNames = names.length === row.tags.length;
|
|
11104
|
+
await ports.writeTagIds(row, names.map((name) => tagIdFromKey(tagKey(name))), sameNames ? null : names);
|
|
11105
|
+
written += 1;
|
|
11106
|
+
}
|
|
11107
|
+
if (written === 0) return {
|
|
11108
|
+
outcome: "already-done",
|
|
11109
|
+
summary: { records: 0 }
|
|
11110
|
+
};
|
|
11111
|
+
ports.info("core-blocks tag ids added", { records: written });
|
|
11112
|
+
return {
|
|
11113
|
+
outcome: "done",
|
|
11114
|
+
summary: { records: written }
|
|
11115
|
+
};
|
|
11116
|
+
}
|
|
11117
|
+
//#endregion
|
|
11118
|
+
//#region src/builtins/core-blocks/migrations/tags-as-records.ts
|
|
11119
|
+
/**
|
|
11120
|
+
* Tags become records with an id (D1089, the last step of the tags migration).
|
|
11121
|
+
*
|
|
11122
|
+
* Before: a tag was a NAME on the records it labelled; its only registry was a style row
|
|
11123
|
+
* (`tag-styles`: colour and icon). After: one `tags` record per tag in use or styled, whose
|
|
11124
|
+
* id is the one the per-owner steps already wrote into `tagIds` (`tagIdFromKey` of the folded
|
|
11125
|
+
* name), carrying the colour and icon of its style. The style rows are then deleted.
|
|
11126
|
+
*
|
|
11127
|
+
* Idempotent and ordered so a crash loses nothing: every record is written BEFORE any style
|
|
11128
|
+
* row is deleted, an existing record is never overwritten (a seed never overwrites), and a
|
|
11129
|
+
* rerun finds no style row and every tag present. The display spelling is the style's, else
|
|
11130
|
+
* the one used most (the first alphabetically on a tie).
|
|
11131
|
+
*
|
|
11132
|
+
* `dependsOn` the owner steps that add `tagIds`, so a record exists under the id they used.
|
|
11133
|
+
* Names held by owners outside this addon (the device manager, the notification rules) are
|
|
11134
|
+
* read best effort: one that cannot be reached right now is logged and skipped, because its
|
|
11135
|
+
* tag is created on first use by `ensureTag` and its rows keep the kept names meanwhile; a
|
|
11136
|
+
* styled tag is carried either way.
|
|
11137
|
+
*/
|
|
11138
|
+
var TAGS_AS_RECORDS_ID = "core-blocks/2026-11-23-tags-as-records";
|
|
11139
|
+
function tagsAsRecordsPortsOver(input) {
|
|
11140
|
+
return {
|
|
11141
|
+
localNames: async () => (await input.tagIds.listTaggedRows()).flatMap((row) => [...row.tags]),
|
|
11142
|
+
externalNames: async () => {
|
|
11143
|
+
try {
|
|
11144
|
+
return await input.external();
|
|
11145
|
+
} catch (err) {
|
|
11146
|
+
input.logger.warn("tags migration: another owner could not be read, skipped", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
11147
|
+
return null;
|
|
11148
|
+
}
|
|
11149
|
+
},
|
|
11150
|
+
listStyles: async () => (await (0, import_read_all_rows.readAllRows)(input.styles)).map((row) => ({
|
|
11151
|
+
id: row.id,
|
|
11152
|
+
style: row.data
|
|
11153
|
+
})),
|
|
11154
|
+
existingTagIds: async () => new Set((await (0, import_read_all_rows.readAllRows)(input.tags)).map((row) => row.id)),
|
|
11155
|
+
createTag: async (id, body) => {
|
|
11156
|
+
await input.tags.put({
|
|
11157
|
+
id,
|
|
11158
|
+
data: body
|
|
11159
|
+
}, { ifRev: 0 });
|
|
11160
|
+
},
|
|
11161
|
+
deleteStyle: async (id) => {
|
|
11162
|
+
await input.styles.delete(id);
|
|
11163
|
+
},
|
|
11164
|
+
info: (message, meta) => {
|
|
11165
|
+
input.logger.info(message, { meta });
|
|
11166
|
+
},
|
|
11167
|
+
warn: (message, meta) => {
|
|
11168
|
+
input.logger.warn(message, { meta });
|
|
11169
|
+
}
|
|
11170
|
+
};
|
|
11171
|
+
}
|
|
11172
|
+
function mostUsed(counts) {
|
|
11173
|
+
const best = [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0];
|
|
11174
|
+
return best === void 0 ? "" : best[0];
|
|
11175
|
+
}
|
|
11176
|
+
async function writeTagRecords(ports) {
|
|
11177
|
+
const styles = await ports.listStyles();
|
|
11178
|
+
const external = await ports.externalNames();
|
|
11179
|
+
if (external === null) {
|
|
11180
|
+
ports.warn("tags migration: another owner could not be read, will retry on the next boot", {});
|
|
11181
|
+
throw new Error("tags migration: names of other owners could not be read, retrying next boot");
|
|
11182
|
+
}
|
|
11183
|
+
const spellings = /* @__PURE__ */ new Map();
|
|
11184
|
+
for (const name of [...await ports.localNames(), ...external]) {
|
|
11185
|
+
const trimmed = name.trim();
|
|
11186
|
+
if (trimmed.length === 0) continue;
|
|
11187
|
+
const counts = spellings.get(tagKey(trimmed)) ?? /* @__PURE__ */ new Map();
|
|
11188
|
+
counts.set(trimmed, (counts.get(trimmed) ?? 0) + 1);
|
|
11189
|
+
spellings.set(tagKey(trimmed), counts);
|
|
11190
|
+
}
|
|
11191
|
+
const styleOf = new Map(styles.map((row) => [tagKey(row.style.name), row.style]));
|
|
11192
|
+
const existing = await ports.existingTagIds();
|
|
11193
|
+
const keys = new Set([...spellings.keys(), ...styleOf.keys()]);
|
|
11194
|
+
let created = 0;
|
|
11195
|
+
for (const key of [...keys].sort()) {
|
|
11196
|
+
const id = tagIdFromKey(key);
|
|
11197
|
+
if (existing.has(id)) continue;
|
|
11198
|
+
const style = styleOf.get(key);
|
|
11199
|
+
const counts = spellings.get(key);
|
|
11200
|
+
const name = style?.name ?? (counts === void 0 ? key : mostUsed(counts));
|
|
11201
|
+
await ports.createTag(id, {
|
|
11202
|
+
name,
|
|
11203
|
+
...style === void 0 ? {} : {
|
|
11204
|
+
colour: style.color,
|
|
11205
|
+
icon: style.icon
|
|
11206
|
+
}
|
|
11207
|
+
});
|
|
11208
|
+
created += 1;
|
|
11209
|
+
}
|
|
11210
|
+
for (const row of styles) await ports.deleteStyle(row.id);
|
|
11211
|
+
if (created === 0 && styles.length === 0) return {
|
|
11212
|
+
outcome: "already-done",
|
|
11213
|
+
summary: {
|
|
11214
|
+
tags: 0,
|
|
11215
|
+
styles: 0
|
|
11216
|
+
}
|
|
11217
|
+
};
|
|
11218
|
+
ports.info("tags are records", {
|
|
11219
|
+
tags: created,
|
|
11220
|
+
styles: styles.length
|
|
11221
|
+
});
|
|
11222
|
+
return {
|
|
11223
|
+
outcome: "done",
|
|
11224
|
+
summary: {
|
|
11225
|
+
tags: created,
|
|
11226
|
+
styles: styles.length
|
|
11227
|
+
}
|
|
11228
|
+
};
|
|
11229
|
+
}
|
|
11230
|
+
//#endregion
|
|
10789
11231
|
//#region src/builtins/core-blocks/migrations/remote-config-migrations.ts
|
|
10790
11232
|
/**
|
|
10791
11233
|
* Two shape changes of a stored remote, both owned by core-blocks (it owns the
|
|
@@ -11058,9 +11500,6 @@ async function renameRemoteColourRoles(ports) {
|
|
|
11058
11500
|
}
|
|
11059
11501
|
};
|
|
11060
11502
|
}
|
|
11061
|
-
//#endregion
|
|
11062
|
-
//#region src/builtins/core-blocks/migrations/index.ts
|
|
11063
|
-
/** The `core-blocks` catalogue (D987): offered to the engine when the hub-resident addon initialises. */
|
|
11064
11503
|
var ADDON_MIGRATIONS = [
|
|
11065
11504
|
{
|
|
11066
11505
|
meta: {
|
|
@@ -11157,6 +11596,42 @@ var ADDON_MIGRATIONS = [
|
|
|
11157
11596
|
fixtureMark: "the block createdBy and name, which the migration does not know"
|
|
11158
11597
|
},
|
|
11159
11598
|
procedure: regenerateAutomationsConfirmedView
|
|
11599
|
+
},
|
|
11600
|
+
{
|
|
11601
|
+
meta: {
|
|
11602
|
+
id: CORE_BLOCKS_TAG_IDS_ID,
|
|
11603
|
+
owner: "core-blocks",
|
|
11604
|
+
level: "addon-state",
|
|
11605
|
+
seq: 7,
|
|
11606
|
+
dependsOn: [],
|
|
11607
|
+
store: "settings",
|
|
11608
|
+
scope: "cluster",
|
|
11609
|
+
onFailure: "tolerate",
|
|
11610
|
+
bodyKind: "procedure",
|
|
11611
|
+
description: "Add the ids of its tags to each block, scheduler, template and action beside the kept names, derived from the folded name",
|
|
11612
|
+
fixtureMark: "the name and the enabled flag of each record, which the migration does not know"
|
|
11613
|
+
},
|
|
11614
|
+
procedure: addTagIds
|
|
11615
|
+
},
|
|
11616
|
+
{
|
|
11617
|
+
meta: {
|
|
11618
|
+
id: TAGS_AS_RECORDS_ID,
|
|
11619
|
+
owner: "core-blocks",
|
|
11620
|
+
level: "addon-state",
|
|
11621
|
+
seq: 8,
|
|
11622
|
+
dependsOn: [
|
|
11623
|
+
CORE_BLOCKS_TAG_IDS_ID,
|
|
11624
|
+
"device-manager/2026-11-23-device-tag-ids",
|
|
11625
|
+
"pipeline-analytics/2026-11-23-rule-tag-ids"
|
|
11626
|
+
],
|
|
11627
|
+
store: "settings",
|
|
11628
|
+
scope: "cluster",
|
|
11629
|
+
onFailure: "tolerate",
|
|
11630
|
+
bodyKind: "procedure",
|
|
11631
|
+
description: "Write one tags record per tag in use or styled, carrying the colour and icon of its style, then delete the tag style rows",
|
|
11632
|
+
fixtureMark: "the colour and icon of each styled tag"
|
|
11633
|
+
},
|
|
11634
|
+
procedure: writeTagRecords
|
|
11160
11635
|
}
|
|
11161
11636
|
];
|
|
11162
11637
|
//#endregion
|
|
@@ -11303,7 +11778,8 @@ var RunsLedger = class {
|
|
|
11303
11778
|
version: 1,
|
|
11304
11779
|
lastRunStartedAt: row.data.lastRunStartedAt,
|
|
11305
11780
|
traces: row.data.traces,
|
|
11306
|
-
lastError: row.data.lastError
|
|
11781
|
+
lastError: row.data.lastError,
|
|
11782
|
+
...row.data.onForHolds === void 0 ? {} : { onForHolds: row.data.onForHolds }
|
|
11307
11783
|
};
|
|
11308
11784
|
}
|
|
11309
11785
|
/** Several owners in ONE read; an owner with no row is idle. */
|
|
@@ -11315,7 +11791,8 @@ var RunsLedger = class {
|
|
|
11315
11791
|
version: 1,
|
|
11316
11792
|
lastRunStartedAt: row.data.lastRunStartedAt,
|
|
11317
11793
|
traces: row.data.traces,
|
|
11318
|
-
lastError: row.data.lastError
|
|
11794
|
+
lastError: row.data.lastError,
|
|
11795
|
+
...row.data.onForHolds === void 0 ? {} : { onForHolds: row.data.onForHolds }
|
|
11319
11796
|
});
|
|
11320
11797
|
return out;
|
|
11321
11798
|
}
|
|
@@ -11335,6 +11812,7 @@ var RunsLedger = class {
|
|
|
11335
11812
|
const traces = report.trace === void 0 ? current.traces.slice(-keep) : appendTrace(current.traces, report.trace, keep);
|
|
11336
11813
|
const failure = report.trace === void 0 ? void 0 : failureOf(report.trace);
|
|
11337
11814
|
const lastError = report.trace === void 0 || isSkip(report.trace) ? current.lastError : failure;
|
|
11815
|
+
const onForHolds = report.onForHolds ?? current.onForHolds;
|
|
11338
11816
|
await this.runs.put({
|
|
11339
11817
|
id: owner,
|
|
11340
11818
|
data: {
|
|
@@ -11342,7 +11820,8 @@ var RunsLedger = class {
|
|
|
11342
11820
|
lastRunStartedAt: report.runStartedAt ?? current.lastRunStartedAt,
|
|
11343
11821
|
traces,
|
|
11344
11822
|
lastError: lastError ?? null,
|
|
11345
|
-
updatedAt: this.now()
|
|
11823
|
+
updatedAt: this.now(),
|
|
11824
|
+
...onForHolds === void 0 ? {} : { onForHolds: [...onForHolds] }
|
|
11346
11825
|
}
|
|
11347
11826
|
});
|
|
11348
11827
|
}
|
|
@@ -12246,6 +12725,20 @@ var ActionsStore = class ActionsStore {
|
|
|
12246
12725
|
}
|
|
12247
12726
|
});
|
|
12248
12727
|
}
|
|
12728
|
+
/** Replace the tag ids of an internal action (D1089); everything else is left as it is. */
|
|
12729
|
+
async setTagIds(actionId, tagIds) {
|
|
12730
|
+
const existing = isInternalActionId(actionId) ? await this.actions.get(uuidOf(actionId)) : null;
|
|
12731
|
+
if (existing === null) throw new ActionError("not-found", `no internal action "${actionId}"`);
|
|
12732
|
+
const { tagIds: _previous, ...rest } = existing.data;
|
|
12733
|
+
const unique = [...new Set(tagIds)];
|
|
12734
|
+
await this.actions.put({
|
|
12735
|
+
id: existing.id,
|
|
12736
|
+
data: unique.length === 0 ? rest : {
|
|
12737
|
+
...rest,
|
|
12738
|
+
tagIds: unique
|
|
12739
|
+
}
|
|
12740
|
+
});
|
|
12741
|
+
}
|
|
12249
12742
|
async delete(actionId) {
|
|
12250
12743
|
if (!isInternalActionId(actionId)) return false;
|
|
12251
12744
|
return this.actions.delete(uuidOf(actionId));
|
|
@@ -12345,14 +12838,15 @@ function buildRunsApi(ledger, logger) {
|
|
|
12345
12838
|
return {
|
|
12346
12839
|
async reportAutomationRun(input) {
|
|
12347
12840
|
requireOwner(input, "reportAutomationRun");
|
|
12348
|
-
if (input.trace === void 0 && input.runStartedAt === void 0) {
|
|
12841
|
+
if (input.trace === void 0 && input.runStartedAt === void 0 && input.onForHolds === void 0) {
|
|
12349
12842
|
logger.warn("reportAutomationRun ignored — it carried neither a trace nor a stamp", { meta: { blockId: input.blockId } });
|
|
12350
12843
|
throw new Error("core-blocks: reportAutomationRun needs a trace or a runStartedAt");
|
|
12351
12844
|
}
|
|
12352
12845
|
await ledger.report(automationOwner(input.blockId), {
|
|
12353
12846
|
...input.trace === void 0 ? {} : { trace: input.trace },
|
|
12354
12847
|
...input.runStartedAt === void 0 ? {} : { runStartedAt: input.runStartedAt },
|
|
12355
|
-
...input.keepTraces === void 0 ? {} : { keepTraces: input.keepTraces }
|
|
12848
|
+
...input.keepTraces === void 0 ? {} : { keepTraces: input.keepTraces },
|
|
12849
|
+
...input.onForHolds === void 0 ? {} : { onForHolds: input.onForHolds }
|
|
12356
12850
|
});
|
|
12357
12851
|
},
|
|
12358
12852
|
async getAutomationRunState(input) {
|
|
@@ -12361,7 +12855,8 @@ function buildRunsApi(ledger, logger) {
|
|
|
12361
12855
|
return {
|
|
12362
12856
|
version: 1,
|
|
12363
12857
|
lastRunStartedAt: view.lastRunStartedAt,
|
|
12364
|
-
traces: [...view.traces]
|
|
12858
|
+
traces: [...view.traces],
|
|
12859
|
+
...view.onForHolds === void 0 ? {} : { onForHolds: [...view.onForHolds] }
|
|
12365
12860
|
};
|
|
12366
12861
|
},
|
|
12367
12862
|
async getTraces(input) {
|
|
@@ -14625,6 +15120,21 @@ var SchedulersStore = class SchedulersStore {
|
|
|
14625
15120
|
data: body
|
|
14626
15121
|
});
|
|
14627
15122
|
}
|
|
15123
|
+
/** Replace the tag ids of a scheduler (D1089); everything else is left as it is. */
|
|
15124
|
+
async setTagIds(schedulerId, tagIds) {
|
|
15125
|
+
const existing = await this.schedulers.get(schedulerId);
|
|
15126
|
+
if (existing === null) throw new SchedulerError("not-found", `no scheduler "${schedulerId}"`);
|
|
15127
|
+
const { tagIds: _previous, ...rest } = existing.data;
|
|
15128
|
+
const unique = [...new Set(tagIds)];
|
|
15129
|
+
const body = unique.length === 0 ? rest : {
|
|
15130
|
+
...rest,
|
|
15131
|
+
tagIds: unique
|
|
15132
|
+
};
|
|
15133
|
+
await this.schedulers.put({
|
|
15134
|
+
id: existing.id,
|
|
15135
|
+
data: body
|
|
15136
|
+
});
|
|
15137
|
+
}
|
|
14628
15138
|
async delete(schedulerId) {
|
|
14629
15139
|
const removed = await this.schedulers.delete(schedulerId);
|
|
14630
15140
|
if (removed) await this.state.delete(schedulerId);
|
|
@@ -18608,20 +19118,21 @@ async function readComposedDeviceNames(port) {
|
|
|
18608
19118
|
//#endregion
|
|
18609
19119
|
//#region src/builtins/core-blocks/tags-service.ts
|
|
18610
19120
|
/**
|
|
18611
|
-
* The `tags` cap (
|
|
18612
|
-
* scheduler, a template, an action, a device
|
|
18613
|
-
*
|
|
18614
|
-
*
|
|
18615
|
-
*
|
|
18616
|
-
*
|
|
19121
|
+
* The `tags` cap (D1089). A tag is a RECORD with an opaque id; a core block, a
|
|
19122
|
+
* scheduler, a template, an action, a device and a notification rule carry the
|
|
19123
|
+
* id, and the name, colour, icon and description live on the record only. So
|
|
19124
|
+
* `updateTag` — a rename included — is ONE write to ONE record, and no owner
|
|
19125
|
+
* has to be reachable. `deleteTag` keeps the one fan-out that remains: it
|
|
19126
|
+
* clears the id from every owner, and refuses while an owner cannot be read.
|
|
19127
|
+
*
|
|
19128
|
+
* `list`, `setStyle`, `rename` and `remove` are the old name-based surface, now
|
|
19129
|
+
* thin shims over the entity methods (kept for one release).
|
|
18617
19130
|
*
|
|
18618
19131
|
* Owners are reached through {@link TagOwnerPort}s: the local stores directly,
|
|
18619
19132
|
* the devices and notification rules through their caps over `ctx.api` — never
|
|
18620
|
-
* a second copy.
|
|
18621
|
-
*
|
|
18622
|
-
* Tags compare trimmed and case-insensitively (`sameTag`).
|
|
19133
|
+
* a second copy. A names-only owner (a notification rule, until its own
|
|
19134
|
+
* migration lands) still carries text; the service keeps its names in step.
|
|
18623
19135
|
*/
|
|
18624
|
-
/** The order owners are read and rewritten in; also the order a first spelling is picked. */
|
|
18625
19136
|
var OWNER_KINDS = [
|
|
18626
19137
|
"coreBlocks",
|
|
18627
19138
|
"schedulers",
|
|
@@ -18630,6 +19141,14 @@ var OWNER_KINDS = [
|
|
|
18630
19141
|
"devices",
|
|
18631
19142
|
"notificationRules"
|
|
18632
19143
|
];
|
|
19144
|
+
var zeroCounts = () => ({
|
|
19145
|
+
coreBlocks: 0,
|
|
19146
|
+
schedulers: 0,
|
|
19147
|
+
templates: 0,
|
|
19148
|
+
actions: 0,
|
|
19149
|
+
devices: 0,
|
|
19150
|
+
notificationRules: 0
|
|
19151
|
+
});
|
|
18633
19152
|
/** The list counts: an owner that could not be read is `null`, never `0` (D393). */
|
|
18634
19153
|
function withUnknown(counts, unreachable) {
|
|
18635
19154
|
return {
|
|
@@ -18642,8 +19161,8 @@ function withUnknown(counts, unreachable) {
|
|
|
18642
19161
|
};
|
|
18643
19162
|
}
|
|
18644
19163
|
/**
|
|
18645
|
-
* A
|
|
18646
|
-
*
|
|
19164
|
+
* A delete refused because one owner kind could not be read. Nothing was
|
|
19165
|
+
* written; `owner` names which one, so the operator knows what to bring back.
|
|
18647
19166
|
*/
|
|
18648
19167
|
var TagOwnerUnreachableError = class extends Error {
|
|
18649
19168
|
owner;
|
|
@@ -18653,36 +19172,72 @@ var TagOwnerUnreachableError = class extends Error {
|
|
|
18653
19172
|
this.owner = owner;
|
|
18654
19173
|
}
|
|
18655
19174
|
};
|
|
18656
|
-
var NO_UPDATES = {
|
|
18657
|
-
coreBlocks: 0,
|
|
18658
|
-
schedulers: 0,
|
|
18659
|
-
templates: 0,
|
|
18660
|
-
actions: 0,
|
|
18661
|
-
devices: 0,
|
|
18662
|
-
notificationRules: 0
|
|
18663
|
-
};
|
|
18664
19175
|
function requireName(value, what) {
|
|
18665
19176
|
const parsed = TagNameSchema.safeParse(value);
|
|
18666
19177
|
if (!parsed.success) throw new Error(`[tags] ${what} is not a valid tag name: ${parsed.error.issues[0]?.message ?? "invalid"}`);
|
|
18667
19178
|
return parsed.data;
|
|
18668
19179
|
}
|
|
19180
|
+
/** A patch field: absent keeps the current value, `null` clears it, a value replaces it. */
|
|
19181
|
+
function applied(patch, current) {
|
|
19182
|
+
if (patch === void 0) return current;
|
|
19183
|
+
return patch === null ? void 0 : patch;
|
|
19184
|
+
}
|
|
19185
|
+
/** Does `record` carry the tag? By id; a record not migrated yet by its kept name. */
|
|
19186
|
+
function carries(record, tag) {
|
|
19187
|
+
if (record.tagIds.includes(tag.id)) return true;
|
|
19188
|
+
if (record.tagIds.length > 0) return false;
|
|
19189
|
+
return record.tags.some((name) => tagKey(name) === tagKey(tag.name));
|
|
19190
|
+
}
|
|
18669
19191
|
var TagsService = class {
|
|
18670
19192
|
deps;
|
|
19193
|
+
store;
|
|
19194
|
+
loaded = null;
|
|
18671
19195
|
constructor(deps) {
|
|
18672
19196
|
this.deps = deps;
|
|
19197
|
+
this.store = new NamedEntityStore("tag", deps.tags, (body) => TagRowBodySchema.parse(body));
|
|
18673
19198
|
}
|
|
18674
|
-
|
|
18675
|
-
|
|
18676
|
-
|
|
18677
|
-
|
|
18678
|
-
const page = await this.deps.styles.query(cursor === void 0 ? {} : { cursor });
|
|
18679
|
-
for (const row of page.records) out.push(row.data);
|
|
18680
|
-
cursor = page.nextCursor ?? void 0;
|
|
18681
|
-
} while (cursor !== void 0);
|
|
18682
|
-
return out;
|
|
19199
|
+
/** Read the records once; every method awaits it. */
|
|
19200
|
+
ready() {
|
|
19201
|
+
this.loaded ??= this.store.load();
|
|
19202
|
+
return this.loaded;
|
|
18683
19203
|
}
|
|
19204
|
+
ensureTag = async ({ name }) => {
|
|
19205
|
+
await this.ready();
|
|
19206
|
+
const clean = requireName(name, "a tag name");
|
|
19207
|
+
return this.store.ensure(clean, {}, tagIdFromKey(tagKey(clean)));
|
|
19208
|
+
};
|
|
19209
|
+
listTags = async () => {
|
|
19210
|
+
await this.ready();
|
|
19211
|
+
return [...this.store.list()];
|
|
19212
|
+
};
|
|
19213
|
+
updateTag = async ({ id, patch }) => {
|
|
19214
|
+
await this.ready();
|
|
19215
|
+
try {
|
|
19216
|
+
const before = this.store.get(id);
|
|
19217
|
+
const updated = await this.store.update(id, (current) => this.patched(current, patch));
|
|
19218
|
+
if (before !== null && before.name !== updated.name) await this.followRenameOnNamesOnlyOwners(before.name, updated.name);
|
|
19219
|
+
return updated;
|
|
19220
|
+
} catch (err) {
|
|
19221
|
+
if (err instanceof EntityNotFoundError) throw userError("system.tag-not-found", void 0, `[tags] tag not found: ${id}`);
|
|
19222
|
+
if (err instanceof EntityNameTakenError) throw userError("system.tag-name-taken", void 0, `[tags] ${err.message}`);
|
|
19223
|
+
throw err;
|
|
19224
|
+
}
|
|
19225
|
+
};
|
|
19226
|
+
deleteTag = async ({ id }) => {
|
|
19227
|
+
await this.ready();
|
|
19228
|
+
const tag = this.store.get(id);
|
|
19229
|
+
if (tag === null) return { updated: { ...zeroCounts() } };
|
|
19230
|
+
const updated = await this.clearFromOwners(tag, null);
|
|
19231
|
+
await this.store.delete(id);
|
|
19232
|
+
this.deps.logger.info("tag deleted", { meta: {
|
|
19233
|
+
id,
|
|
19234
|
+
name: tag.name,
|
|
19235
|
+
updated
|
|
19236
|
+
} });
|
|
19237
|
+
return { updated };
|
|
19238
|
+
};
|
|
18684
19239
|
list = async () => {
|
|
18685
|
-
|
|
19240
|
+
await this.ready();
|
|
18686
19241
|
const unreachable = /* @__PURE__ */ new Set();
|
|
18687
19242
|
const read = [];
|
|
18688
19243
|
for (const kind of OWNER_KINDS) try {
|
|
@@ -18697,56 +19252,89 @@ var TagsService = class {
|
|
|
18697
19252
|
error: err instanceof Error ? err.message : String(err)
|
|
18698
19253
|
} });
|
|
18699
19254
|
}
|
|
18700
|
-
const zero = () => ({ ...NO_UPDATES });
|
|
18701
19255
|
const entries = /* @__PURE__ */ new Map();
|
|
18702
|
-
for (const
|
|
18703
|
-
name:
|
|
18704
|
-
|
|
19256
|
+
for (const tag of this.store.list()) entries.set(tag.id, {
|
|
19257
|
+
name: tag.name,
|
|
19258
|
+
styled: true,
|
|
19259
|
+
counts: zeroCounts(),
|
|
19260
|
+
record: tag
|
|
18705
19261
|
});
|
|
19262
|
+
const byKey = new Map([...entries].map(([id, e]) => [tagKey(e.name), id]));
|
|
18706
19263
|
for (const { kind, records } of read) for (const record of records) {
|
|
18707
19264
|
const seen = /* @__PURE__ */ new Set();
|
|
18708
|
-
|
|
18709
|
-
|
|
18710
|
-
|
|
18711
|
-
|
|
18712
|
-
|
|
18713
|
-
|
|
18714
|
-
counts:
|
|
19265
|
+
const touch = (entryId, name, record0) => {
|
|
19266
|
+
if (seen.has(entryId)) return;
|
|
19267
|
+
seen.add(entryId);
|
|
19268
|
+
const entry = entries.get(entryId) ?? {
|
|
19269
|
+
name,
|
|
19270
|
+
styled: false,
|
|
19271
|
+
counts: zeroCounts(),
|
|
19272
|
+
record: record0
|
|
18715
19273
|
};
|
|
18716
19274
|
entry.counts[kind] += 1;
|
|
18717
|
-
entries.set(
|
|
19275
|
+
entries.set(entryId, entry);
|
|
19276
|
+
};
|
|
19277
|
+
for (const id of record.tagIds) {
|
|
19278
|
+
const known = this.store.get(id);
|
|
19279
|
+
if (known !== null) touch(id, known.name, known);
|
|
19280
|
+
}
|
|
19281
|
+
if (record.tagIds.length === 0) for (const name of record.tags) {
|
|
19282
|
+
const key = tagKey(name);
|
|
19283
|
+
if (key.length === 0) continue;
|
|
19284
|
+
const existing = byKey.get(key);
|
|
19285
|
+
if (existing === void 0) byKey.set(key, `name:${key}`);
|
|
19286
|
+
touch(existing ?? `name:${key}`, name.trim(), null);
|
|
18718
19287
|
}
|
|
18719
19288
|
}
|
|
18720
19289
|
const out = [];
|
|
18721
|
-
for (const
|
|
18722
|
-
|
|
18723
|
-
|
|
18724
|
-
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
counts: withUnknown(entry.counts, unreachable)
|
|
18729
|
-
});
|
|
18730
|
-
}
|
|
19290
|
+
for (const entry of entries.values()) out.push({
|
|
19291
|
+
name: entry.name,
|
|
19292
|
+
color: entry.record?.colour ?? defaultTagColorId(entry.name),
|
|
19293
|
+
icon: entry.record?.icon ?? "tag",
|
|
19294
|
+
styled: entry.record?.colour !== void 0 || entry.record?.icon !== void 0,
|
|
19295
|
+
counts: withUnknown(entry.counts, unreachable)
|
|
19296
|
+
});
|
|
18731
19297
|
return out.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
18732
19298
|
};
|
|
18733
19299
|
setStyle = async ({ name, color, icon }) => {
|
|
18734
|
-
const
|
|
18735
|
-
await this.
|
|
18736
|
-
id:
|
|
18737
|
-
|
|
18738
|
-
|
|
18739
|
-
color,
|
|
19300
|
+
const tag = await this.ensureTag({ name });
|
|
19301
|
+
await this.updateTag({
|
|
19302
|
+
id: tag.id,
|
|
19303
|
+
patch: {
|
|
19304
|
+
colour: color,
|
|
18740
19305
|
icon
|
|
18741
19306
|
}
|
|
18742
19307
|
});
|
|
18743
19308
|
};
|
|
18744
19309
|
rename = async ({ from, to }) => {
|
|
19310
|
+
await this.ready();
|
|
18745
19311
|
const source = requireName(from, "the tag to rename");
|
|
18746
19312
|
const target = requireName(to, "the new tag name");
|
|
18747
|
-
const
|
|
18748
|
-
|
|
18749
|
-
|
|
19313
|
+
const sourceTag = this.store.findByName(source);
|
|
19314
|
+
if (sourceTag === null) {
|
|
19315
|
+
const updated = await this.renameNamesOnly(source, target);
|
|
19316
|
+
this.deps.logger.info("tag renamed (names only)", { meta: {
|
|
19317
|
+
from: source,
|
|
19318
|
+
to: target
|
|
19319
|
+
} });
|
|
19320
|
+
return { updated };
|
|
19321
|
+
}
|
|
19322
|
+
const targetTag = this.store.findByName(target);
|
|
19323
|
+
if (targetTag === null || targetTag.id === sourceTag.id) {
|
|
19324
|
+
await this.updateTag({
|
|
19325
|
+
id: sourceTag.id,
|
|
19326
|
+
patch: { name: target }
|
|
19327
|
+
});
|
|
19328
|
+
const updated = await this.countCarrying(sourceTag, target);
|
|
19329
|
+
this.deps.logger.info("tag renamed", { meta: {
|
|
19330
|
+
from: source,
|
|
19331
|
+
to: target
|
|
19332
|
+
} });
|
|
19333
|
+
return { updated };
|
|
19334
|
+
}
|
|
19335
|
+
const updated = await this.clearFromOwners(sourceTag, targetTag);
|
|
19336
|
+
await this.store.delete(sourceTag.id);
|
|
19337
|
+
this.deps.logger.info("tags merged", { meta: {
|
|
18750
19338
|
from: source,
|
|
18751
19339
|
to: target,
|
|
18752
19340
|
updated
|
|
@@ -18754,90 +19342,139 @@ var TagsService = class {
|
|
|
18754
19342
|
return { updated };
|
|
18755
19343
|
};
|
|
18756
19344
|
remove = async ({ name }) => {
|
|
19345
|
+
await this.ready();
|
|
18757
19346
|
const target = requireName(name, "the tag to remove");
|
|
18758
|
-
const
|
|
18759
|
-
await this.
|
|
18760
|
-
this.
|
|
18761
|
-
name: target,
|
|
18762
|
-
updated
|
|
18763
|
-
} });
|
|
19347
|
+
const tag = this.store.findByName(target);
|
|
19348
|
+
if (tag === null) return { updated: await this.removeNamesOnly(target) };
|
|
19349
|
+
const { updated } = await this.deleteTag({ id: tag.id });
|
|
18764
19350
|
return { updated };
|
|
18765
19351
|
};
|
|
19352
|
+
patched(current, patch) {
|
|
19353
|
+
const next = { name: patch.name ?? current.name };
|
|
19354
|
+
const colour = applied(patch.colour, current.colour);
|
|
19355
|
+
const icon = applied(patch.icon, current.icon);
|
|
19356
|
+
const description = applied(patch.description, current.description);
|
|
19357
|
+
const order = applied(patch.order, current.order);
|
|
19358
|
+
if (colour !== void 0) next.colour = colour;
|
|
19359
|
+
if (icon !== void 0) next.icon = icon;
|
|
19360
|
+
if (description !== void 0) next.description = description;
|
|
19361
|
+
if (order !== void 0) next.order = order;
|
|
19362
|
+
return next;
|
|
19363
|
+
}
|
|
18766
19364
|
/**
|
|
18767
|
-
*
|
|
18768
|
-
*
|
|
18769
|
-
*
|
|
18770
|
-
* operator repeats the same call (every step is idempotent).
|
|
19365
|
+
* Remove `tag` from every owner record that carries it, or — with `into` —
|
|
19366
|
+
* replace it with that tag. Every owner is READ first: one that cannot be
|
|
19367
|
+
* read refuses the whole call before anything is written.
|
|
18771
19368
|
*/
|
|
18772
|
-
async
|
|
18773
|
-
const updated = { ...NO_UPDATES };
|
|
18774
|
-
const failed = [];
|
|
19369
|
+
async clearFromOwners(tag, into) {
|
|
18775
19370
|
const plan = [];
|
|
18776
|
-
for (const kind of OWNER_KINDS)
|
|
18777
|
-
|
|
18778
|
-
|
|
18779
|
-
|
|
18780
|
-
|
|
19371
|
+
for (const kind of OWNER_KINDS) {
|
|
19372
|
+
let records;
|
|
19373
|
+
try {
|
|
19374
|
+
records = await this.deps.owners[kind].list();
|
|
19375
|
+
} catch (err) {
|
|
19376
|
+
throw new TagOwnerUnreachableError(kind, tag.name, err);
|
|
19377
|
+
}
|
|
19378
|
+
for (const record of records) if (carries(record, tag)) plan.push({
|
|
18781
19379
|
kind,
|
|
18782
|
-
|
|
18783
|
-
next
|
|
19380
|
+
record
|
|
18784
19381
|
});
|
|
18785
19382
|
}
|
|
18786
|
-
|
|
18787
|
-
|
|
19383
|
+
const updated = zeroCounts();
|
|
19384
|
+
const failed = [];
|
|
19385
|
+
for (const { kind, record } of plan) try {
|
|
19386
|
+
await this.rewriteRecord(kind, record, tag, into);
|
|
18788
19387
|
updated[kind] += 1;
|
|
18789
19388
|
} catch (err) {
|
|
18790
|
-
failed.push(`${kind}:${id}`);
|
|
18791
|
-
const deviceId = kind === "devices" ? Number(id) : void 0;
|
|
19389
|
+
failed.push(`${kind}:${record.id}`);
|
|
19390
|
+
const deviceId = kind === "devices" ? Number(record.id) : void 0;
|
|
18792
19391
|
this.deps.logger.error("tag rewrite failed for one record — the rest were still attempted", {
|
|
18793
19392
|
...deviceId === void 0 || !Number.isFinite(deviceId) ? {} : { tags: { deviceId } },
|
|
18794
19393
|
meta: {
|
|
18795
|
-
tag,
|
|
19394
|
+
tag: tag.name,
|
|
18796
19395
|
kind,
|
|
18797
|
-
recordId: id,
|
|
19396
|
+
recordId: record.id,
|
|
18798
19397
|
error: err instanceof Error ? err.message : String(err)
|
|
18799
19398
|
}
|
|
18800
19399
|
});
|
|
18801
19400
|
}
|
|
18802
|
-
if (failed.length > 0) throw new Error(`[tags] "${tag}" was not
|
|
19401
|
+
if (failed.length > 0) throw new Error(`[tags] "${tag.name}" was not cleared on ${failed.length} record(s) (${failed.slice(0, 5).join(", ")}); the tag was left alone — repeat the call`);
|
|
18803
19402
|
return updated;
|
|
18804
19403
|
}
|
|
19404
|
+
async rewriteRecord(kind, record, tag, into) {
|
|
19405
|
+
const port = this.deps.owners[kind];
|
|
19406
|
+
const names = into === null ? removeFromTags(record.tags, tag.name) : renameInTags(record.tags, tag.name, into.name);
|
|
19407
|
+
if (port.storage === "names") {
|
|
19408
|
+
if (names !== null) await port.setTags(record.id, names);
|
|
19409
|
+
return;
|
|
19410
|
+
}
|
|
19411
|
+
const withoutTag = record.tagIds.filter((id) => id !== tag.id);
|
|
19412
|
+
const ids = into === null || withoutTag.includes(into.id) ? withoutTag : [...withoutTag, into.id];
|
|
19413
|
+
const nextIds = record.tagIds.length === 0 && into !== null ? [into.id] : ids;
|
|
19414
|
+
if (port.setTagsAndIds !== void 0) {
|
|
19415
|
+
await port.setTagsAndIds(record.id, [...names ?? record.tags], nextIds);
|
|
19416
|
+
return;
|
|
19417
|
+
}
|
|
19418
|
+
await port.setTagIds(record.id, nextIds);
|
|
19419
|
+
if (names !== null) await port.setTags(record.id, names);
|
|
19420
|
+
}
|
|
19421
|
+
/** How many records carry `tag` (by id or kept name) — the shim's `updated`; an unreadable owner counts 0. */
|
|
19422
|
+
async countCarrying(tag, newName) {
|
|
19423
|
+
const counts = zeroCounts();
|
|
19424
|
+
for (const kind of OWNER_KINDS) try {
|
|
19425
|
+
for (const record of await this.deps.owners[kind].list()) if (carries(record, tag) || carries(record, {
|
|
19426
|
+
id: tag.id,
|
|
19427
|
+
name: newName
|
|
19428
|
+
})) counts[kind] += 1;
|
|
19429
|
+
} catch {}
|
|
19430
|
+
return counts;
|
|
19431
|
+
}
|
|
18805
19432
|
/**
|
|
18806
|
-
*
|
|
18807
|
-
*
|
|
18808
|
-
*
|
|
19433
|
+
* A safety net for a record that still holds text only (an owner, or a node whose
|
|
19434
|
+
* notification center has not run its tag-ids step yet): the tag record was renamed once, so
|
|
19435
|
+
* the names such a record keeps are moved here, or it would keep naming a tag nothing
|
|
19436
|
+
* carries any more.
|
|
19437
|
+
* An owner that cannot be read is logged and skipped, never the cause of a failed rename.
|
|
18809
19438
|
*/
|
|
18810
|
-
async
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
async moveStyle(from, to) {
|
|
18819
|
-
const fromKey = tagKey(from);
|
|
18820
|
-
const toKey = tagKey(to);
|
|
18821
|
-
const fromStyle = await this.deps.styles.get(fromKey);
|
|
18822
|
-
if (fromKey === toKey) {
|
|
18823
|
-
if (fromStyle !== null) await this.deps.styles.put({
|
|
18824
|
-
id: toKey,
|
|
18825
|
-
data: {
|
|
18826
|
-
...fromStyle.data,
|
|
18827
|
-
name: to
|
|
19439
|
+
async followRenameOnNamesOnlyOwners(from, to) {
|
|
19440
|
+
for (const kind of OWNER_KINDS) {
|
|
19441
|
+
const port = this.deps.owners[kind];
|
|
19442
|
+
try {
|
|
19443
|
+
for (const record of await port.list()) {
|
|
19444
|
+
if (port.storage === "ids" && record.tagIds.length > 0) continue;
|
|
19445
|
+
const next = renameInTags(record.tags, from, to);
|
|
19446
|
+
if (next !== null) await port.setTags(record.id, next);
|
|
18828
19447
|
}
|
|
18829
|
-
})
|
|
18830
|
-
|
|
18831
|
-
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
...fromStyle.data,
|
|
18837
|
-
name: to
|
|
19448
|
+
} catch (err) {
|
|
19449
|
+
this.deps.logger.warn("tag renamed, but a names-only owner could not follow", { meta: {
|
|
19450
|
+
owner: kind,
|
|
19451
|
+
from,
|
|
19452
|
+
to,
|
|
19453
|
+
error: err instanceof Error ? err.message : String(err)
|
|
19454
|
+
} });
|
|
18838
19455
|
}
|
|
18839
|
-
}
|
|
18840
|
-
|
|
19456
|
+
}
|
|
19457
|
+
}
|
|
19458
|
+
/** Names-only tags: a name on owners that have no record for it (a pre-migration state). */
|
|
19459
|
+
async renameNamesOnly(from, to) {
|
|
19460
|
+
const updated = zeroCounts();
|
|
19461
|
+
for (const kind of OWNER_KINDS) for (const record of await this.deps.owners[kind].list()) {
|
|
19462
|
+
const next = renameInTags(record.tags, from, to);
|
|
19463
|
+
if (next === null) continue;
|
|
19464
|
+
await this.deps.owners[kind].setTags(record.id, next);
|
|
19465
|
+
updated[kind] += 1;
|
|
19466
|
+
}
|
|
19467
|
+
return updated;
|
|
19468
|
+
}
|
|
19469
|
+
async removeNamesOnly(name) {
|
|
19470
|
+
const updated = zeroCounts();
|
|
19471
|
+
for (const kind of OWNER_KINDS) for (const record of await this.deps.owners[kind].list()) {
|
|
19472
|
+
const next = removeFromTags(record.tags, name);
|
|
19473
|
+
if (next === null) continue;
|
|
19474
|
+
await this.deps.owners[kind].setTags(record.id, next);
|
|
19475
|
+
updated[kind] += 1;
|
|
19476
|
+
}
|
|
19477
|
+
return updated;
|
|
18841
19478
|
}
|
|
18842
19479
|
};
|
|
18843
19480
|
//#endregion
|
|
@@ -18849,35 +19486,47 @@ var TagsService = class {
|
|
|
18849
19486
|
*/
|
|
18850
19487
|
function coreBlocksPort(blocks) {
|
|
18851
19488
|
return {
|
|
19489
|
+
storage: "ids",
|
|
18852
19490
|
list: async () => blocks().list().map((b) => ({
|
|
18853
19491
|
id: b.id,
|
|
18854
|
-
tags: b.tags ?? []
|
|
19492
|
+
tags: b.tags ?? [],
|
|
19493
|
+
tagIds: b.tagIds ?? []
|
|
18855
19494
|
})),
|
|
18856
19495
|
setTags: async (id, tags) => {
|
|
18857
19496
|
await blocks().setTags(id, tags);
|
|
19497
|
+
},
|
|
19498
|
+
setTagIds: async (id, tagIds) => {
|
|
19499
|
+
await blocks().setTagIds(id, tagIds);
|
|
18858
19500
|
}
|
|
18859
19501
|
};
|
|
18860
19502
|
}
|
|
18861
19503
|
function schedulersPort(store) {
|
|
18862
19504
|
return {
|
|
19505
|
+
storage: "ids",
|
|
18863
19506
|
list: async () => (await store.list()).map((s) => ({
|
|
18864
19507
|
id: s.id,
|
|
18865
|
-
tags: s.tags ?? []
|
|
19508
|
+
tags: s.tags ?? [],
|
|
19509
|
+
tagIds: s.tagIds ?? []
|
|
18866
19510
|
})),
|
|
18867
|
-
setTags: (id, tags) => store.setTags(id, tags)
|
|
19511
|
+
setTags: (id, tags) => store.setTags(id, tags),
|
|
19512
|
+
setTagIds: (id, tagIds) => store.setTagIds(id, tagIds)
|
|
18868
19513
|
};
|
|
18869
19514
|
}
|
|
18870
19515
|
function actionsPort(store) {
|
|
18871
19516
|
return {
|
|
19517
|
+
storage: "ids",
|
|
18872
19518
|
list: async () => (await store.list()).map((a) => ({
|
|
18873
19519
|
id: a.id,
|
|
18874
|
-
tags: a.tags ?? []
|
|
19520
|
+
tags: a.tags ?? [],
|
|
19521
|
+
tagIds: a.tagIds ?? []
|
|
18875
19522
|
})),
|
|
18876
|
-
setTags: (id, tags) => store.setTags(id, tags)
|
|
19523
|
+
setTags: (id, tags) => store.setTags(id, tags),
|
|
19524
|
+
setTagIds: (id, tagIds) => store.setTagIds(id, tagIds)
|
|
18877
19525
|
};
|
|
18878
19526
|
}
|
|
18879
19527
|
function templatesPort(templates) {
|
|
18880
19528
|
return {
|
|
19529
|
+
storage: "ids",
|
|
18881
19530
|
list: async () => {
|
|
18882
19531
|
const out = [];
|
|
18883
19532
|
let cursor;
|
|
@@ -18885,7 +19534,8 @@ function templatesPort(templates) {
|
|
|
18885
19534
|
const page = await templates.query(cursor === void 0 ? {} : { cursor });
|
|
18886
19535
|
for (const row of page.records) out.push({
|
|
18887
19536
|
id: row.id,
|
|
18888
|
-
tags: row.data.tags ?? []
|
|
19537
|
+
tags: row.data.tags ?? [],
|
|
19538
|
+
tagIds: row.data.tagIds ?? []
|
|
18889
19539
|
});
|
|
18890
19540
|
cursor = page.nextCursor ?? void 0;
|
|
18891
19541
|
} while (cursor !== void 0);
|
|
@@ -18903,6 +19553,19 @@ function templatesPort(templates) {
|
|
|
18903
19553
|
tags: normalized
|
|
18904
19554
|
}
|
|
18905
19555
|
});
|
|
19556
|
+
},
|
|
19557
|
+
setTagIds: async (id, tagIds) => {
|
|
19558
|
+
const row = await templates.get(id);
|
|
19559
|
+
if (row === null) throw new Error(`no template "${id}"`);
|
|
19560
|
+
const { tagIds: _previous, ...rest } = row.data;
|
|
19561
|
+
const unique = [...new Set(tagIds)];
|
|
19562
|
+
await templates.put({
|
|
19563
|
+
id,
|
|
19564
|
+
data: unique.length === 0 ? rest : {
|
|
19565
|
+
...rest,
|
|
19566
|
+
tagIds: unique
|
|
19567
|
+
}
|
|
19568
|
+
});
|
|
18906
19569
|
}
|
|
18907
19570
|
};
|
|
18908
19571
|
}
|
|
@@ -18913,10 +19576,12 @@ function devicesPort(api) {
|
|
|
18913
19576
|
return current;
|
|
18914
19577
|
};
|
|
18915
19578
|
return {
|
|
19579
|
+
storage: "ids",
|
|
18916
19580
|
list: async () => {
|
|
18917
19581
|
return (await need().deviceManager.listAll.query({ projection: "slim" })).map((d) => ({
|
|
18918
19582
|
id: String(d.id),
|
|
18919
|
-
tags: d.tags ?? []
|
|
19583
|
+
tags: d.tags ?? [],
|
|
19584
|
+
tagIds: d.tagIds ?? []
|
|
18920
19585
|
}));
|
|
18921
19586
|
},
|
|
18922
19587
|
setTags: async (id, tags) => {
|
|
@@ -18924,6 +19589,12 @@ function devicesPort(api) {
|
|
|
18924
19589
|
deviceId: Number(id),
|
|
18925
19590
|
tags
|
|
18926
19591
|
});
|
|
19592
|
+
},
|
|
19593
|
+
setTagIds: async (id, tagIds) => {
|
|
19594
|
+
await need().deviceManager.setTags.mutate({
|
|
19595
|
+
deviceId: Number(id),
|
|
19596
|
+
tagIds
|
|
19597
|
+
});
|
|
18927
19598
|
}
|
|
18928
19599
|
};
|
|
18929
19600
|
}
|
|
@@ -18950,22 +19621,30 @@ function parseRuleTagOwnerId(id) {
|
|
|
18950
19621
|
};
|
|
18951
19622
|
}
|
|
18952
19623
|
function notificationRulesPort(api) {
|
|
19624
|
+
const entries = async () => (await needApi(api).notificationRules.listRuleTags.query({})).rules.map((r) => ({
|
|
19625
|
+
id: ruleTagOwnerId(r.kind, r.ruleId),
|
|
19626
|
+
tags: r.tags,
|
|
19627
|
+
tagIds: r.tagIds
|
|
19628
|
+
}));
|
|
19629
|
+
const write = async (id, tags, tagIds) => {
|
|
19630
|
+
const { kind, ruleId } = parseRuleTagOwnerId(id);
|
|
19631
|
+
await needApi(api).notificationRules.setRuleTags.mutate({
|
|
19632
|
+
kind,
|
|
19633
|
+
ruleId,
|
|
19634
|
+
tags,
|
|
19635
|
+
...tagIds === void 0 ? {} : { tagIds }
|
|
19636
|
+
});
|
|
19637
|
+
};
|
|
18953
19638
|
return {
|
|
18954
|
-
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
|
|
18958
|
-
|
|
18959
|
-
|
|
19639
|
+
storage: "ids",
|
|
19640
|
+
list: entries,
|
|
19641
|
+
setTagIds: async (id, tagIds) => {
|
|
19642
|
+
const current = (await entries()).find((entry) => entry.id === id);
|
|
19643
|
+
if (current === void 0) throw new Error(`[tags] notification rule not found: ${id}`);
|
|
19644
|
+
await write(id, [...current.tags], tagIds);
|
|
18960
19645
|
},
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
await needApi(api).notificationRules.setRuleTags.mutate({
|
|
18964
|
-
kind,
|
|
18965
|
-
ruleId,
|
|
18966
|
-
tags
|
|
18967
|
-
});
|
|
18968
|
-
}
|
|
19646
|
+
setTagsAndIds: (id, tags, tagIds) => write(id, tags, tagIds),
|
|
19647
|
+
setTags: (id, tags) => write(id, tags, void 0)
|
|
18969
19648
|
};
|
|
18970
19649
|
}
|
|
18971
19650
|
function buildTagsService(deps) {
|
|
@@ -18985,7 +19664,7 @@ function buildTagsService(deps) {
|
|
|
18985
19664
|
devices: deps.devices ?? devicesPort(deps.api),
|
|
18986
19665
|
notificationRules: deps.notificationRules ?? notificationRulesPort(deps.api)
|
|
18987
19666
|
},
|
|
18988
|
-
|
|
19667
|
+
tags: records.kind(coreBlocksRecordKinds.tags),
|
|
18989
19668
|
logger: deps.logger
|
|
18990
19669
|
});
|
|
18991
19670
|
}
|
|
@@ -19112,7 +19791,23 @@ var CoreBlocksAddon = class extends BaseAddon {
|
|
|
19112
19791
|
await records.declare(coreBlocksRecordKinds);
|
|
19113
19792
|
await records.declare(blocksInstanceRecordKinds);
|
|
19114
19793
|
this.blocksInstances = buildBlocksInstances(records);
|
|
19794
|
+
const migrationLogger = this.ctx.logger.child("migrations");
|
|
19795
|
+
const tagIdsPorts = tagIdsPortsOver({
|
|
19796
|
+
blocks: records.kind(coreBlocksRecordKinds.blocks),
|
|
19797
|
+
schedulers: records.kind(coreBlocksRecordKinds.schedulers),
|
|
19798
|
+
templates: records.kind(coreBlocksRecordKinds.templates),
|
|
19799
|
+
actions: records.kind(coreBlocksRecordKinds.actions)
|
|
19800
|
+
}, migrationLogger);
|
|
19801
|
+
const api = () => this.ctx.api;
|
|
19115
19802
|
await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, {
|
|
19803
|
+
...tagIdsPorts,
|
|
19804
|
+
...tagsAsRecordsPortsOver({
|
|
19805
|
+
tagIds: tagIdsPorts,
|
|
19806
|
+
external: async () => [...await devicesPort(api).list(), ...await notificationRulesPort(api).list()].flatMap((owner) => owner.tags),
|
|
19807
|
+
styles: records.kind(coreBlocksRecordKinds["tag-styles"]),
|
|
19808
|
+
tags: records.kind(coreBlocksRecordKinds.tags),
|
|
19809
|
+
logger: migrationLogger
|
|
19810
|
+
}),
|
|
19116
19811
|
...coreBlocksMigrationPorts(records.kind(coreBlocksRecordKinds.blocks), this.ctx.logger.child("migrations"), () => Date.now()),
|
|
19117
19812
|
...remoteMigrationPortsOver(this.ctx.settings ?? NO_DEVICE_STORES, records.kind(coreBlocksRecordKinds.templates), this.ctx.logger.child("migrations"))
|
|
19118
19813
|
}));
|