@camstack/server 1.2.891 → 1.2.893
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 +22 -0
- package/dist/api/trpc/generated-cap-mounts.js +2 -1
- package/dist/api/trpc/generated-cap-routers.js +204 -39
- package/dist/core/addon/addon-registry.service.js +47 -0
- package/dist/core/addon/retire-undeclared-fixed-integrations.js +57 -0
- package/package.json +14 -15
- package/system/dist/addon-runner.js +25 -9
- package/system/dist/addon-runner.mjs +25 -9
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/addon.d.ts +65 -41
- package/system/dist/builtins/camera-grid/grid-blocks.d.ts +51 -0
- package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +4 -3
- package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +3 -1
- package/system/dist/builtins/camera-grid/grid-plan.d.ts +3 -3
- package/system/dist/builtins/camera-grid/index.d.ts +2 -6
- package/system/dist/builtins/camera-grid/index.js +431 -727
- package/system/dist/builtins/camera-grid/index.mjs +428 -719
- package/system/dist/builtins/composer/composed-device.d.ts +12 -2
- package/system/dist/builtins/composer/composer.addon.js +28 -10
- package/system/dist/builtins/composer/composer.addon.mjs +28 -10
- package/system/dist/builtins/composer/composition-declarations.d.ts +3 -1
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +174 -39
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +175 -40
- package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +19 -1
- package/system/dist/builtins/core-blocks/power-source-devices.d.ts +9 -0
- package/system/dist/builtins/core-blocks/power-source-service.d.ts +39 -2
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-identifiers-action.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-identity-index.d.ts +73 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +401 -14
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +401 -14
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-row-store.d.ts +7 -3
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
- package/system/dist/builtins/device-manager/workload-transition.d.ts +23 -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 +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-nmelnj-Y.mjs → capture-engine-CIVKm_jN.mjs} +1 -1
- package/system/dist/{capture-engine-DXz37Mjg.js → capture-engine-mZ2J-GD6.js} +1 -1
- package/system/dist/{composition-sources-BLn3cU74.js → composition-sources-CGP5ZUYo.js} +1 -1
- package/system/dist/{composition-sources-uphZtYtN.mjs → composition-sources-bJP8_Z2o.mjs} +1 -1
- package/system/dist/{constants-BAaGwvKn.js → constants-BD8oSQro.js} +1 -1
- package/system/dist/{constants-DWU46D02.mjs → constants-w-6vvTPp.mjs} +1 -1
- package/system/dist/{device-ca-jbH_rqZh.js → device-ca-CXxnQaff.js} +1 -1
- package/system/dist/{device-ca-CK6mLB2w.mjs → device-ca-DE_oetBE.mjs} +1 -1
- package/system/dist/{dist-m5beNMze.js → dist-B2-Uflhy.js} +2573 -443
- package/system/dist/{dist-Dgq9nuvh.mjs → dist-Be8yFd71.mjs} +2460 -444
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-CKCA89XP.js → hub-identity-BjYvJU_v.js} +1 -1
- package/system/dist/{hub-identity-DlBBoHJC.mjs → hub-identity-C3g7b58L.mjs} +1 -1
- package/system/dist/{hub-mdns-ciao-CqcCGPdi.js → hub-mdns-ciao-BRfv9GfW.js} +2 -2
- package/system/dist/{hub-mdns-ciao-B8uFW-RG.mjs → hub-mdns-ciao-v6X_SbWl.mjs} +2 -2
- package/system/dist/index.js +33 -19
- package/system/dist/index.mjs +33 -19
- package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +3 -6
- package/system/dist/kernel/moleculer/switch-toggle.d.ts +7 -2
- package/system/dist/{legacy-integration-rows-door-Co0gj1Lm.js → legacy-integration-rows-door-B0q34gh3.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-HI4nmSe_.mjs → legacy-integration-rows-door-DG35DG06.mjs} +1 -1
- package/system/dist/{rename-composition-block-UeVUYCwx.js → rename-composition-block-DNte3Cs9.js} +1 -1
- package/system/dist/{rename-composition-block-BthBMrXA.mjs → rename-composition-block-LEbZ4oZE.mjs} +1 -1
- package/system/dist/{restore-archive-P-ICnU58.mjs → restore-archive--4ENkU5f.mjs} +1 -1
- package/system/dist/{restore-archive-CJLsfBwK.js → restore-archive-DpFPheMK.js} +1 -1
- package/system/dist/{wal-maintenance-CUtwx-2Z.js → wal-maintenance-BWUJktqT.js} +0 -0
- package/system/dist/{wal-maintenance-qWjb7_f2.mjs → wal-maintenance-DQVDhuVJ.mjs} +0 -0
- package/system/package.json +2 -5
- package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +0 -59
- package/system/dist/builtins/camera-grid/grid-instances.d.ts +0 -40
- package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +0 -31
- package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +0 -13
- package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +0 -26
- package/system/dist/builtins/camera-grid/migrations/index.d.ts +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $i as localDateOf, $n as builtinAutomationTemplate, $r as evaluateStepCondition, An as actionWaitTotalMs, B as DEFAULT_HOLD_OVERRIDE, Ca as normalizeTags, Cl as hydrateSchema, Cn as TemplateKindSchema, Cr as coreBlockIdFromAddonId, D as CORE_BLOCK_ADDON_PREFIX, Da as occurrenceOn, Di as internalActionId, Ds as COMPOSER_ADDON_ID, E as CORE_BLOCKS_ADDON_ID, Ei as integrationInstancesCapability, Es as zoneOnlySite, Fa as planComposition, Fl as isSecretRefOwnedBy, Ga as projectDeviceRow, Go as stableIdMapOf, Ha as problemsBlockSave, Hs as composedDeviceStableId, Ic as RecordIntegrationInstances, Ja as readRecipeLiteral, Jl as resolveSecretMarkers, Jn as buildCapabilityLookup, Jt as PowerSourceInfoSchema, Ka as proposeRunningThreshold, Ki as kebabToCamel, Ks as compositionSourceKey, La as powerSourceActuatorConflicts, Lr as describeComposableCaps, Ls as canonicalStoredBlockTarget, Mn as addonIdOfActionId, N as CoreBlockSchema, Nl as isSecretMarker, No as seedInstanceOnce, Oo as schedulersCapability, Or as customKeyOfRole, Os as CompositionSchema, Ot as IDLE_ACTION_STATUS, Pi as isBuiltinTemplateId, Pr as defaultTagColorId, Ps as HelperMemberSchema, Ql as secretTreeFromSchema, Qs as historyRetentionFromSettings, Qt as QuantityUnitError, Ra as powerSourceCapability, Rt as MediaPlayerStatusSchema, Sa as normalizeCoreBlockWrite, Si as heroLayoutCapability, Sn as TagsFieldSchema, Sr as coreBlockComposition, T as COMPOSER_RUNNER_ID, Ti as instanceCodeHash, Tr as coreBlocksCapability, Us as compositionFeatureEnabled, Va as prepareRecipeUnits, Vn as assertStepsOffered, Vo as siteFor, Vs as composedDeviceRef, Vt as NcTaggedRuleKindSchema, Ya as readStoredRemoteConfig, Yc as actionEffect, Yl as ruleFireOfClaim, Zn as buildHeroModel, Zs as helperMembers, _ as BUILTIN_REMOTE_COMPONENTS, _i as generateAutomationBlock, _l as entryBody, al as collectSecretMarkerRefs, an as RunningStateStatusSchema, ao as renameInTags, as as templateCapability, au as vocabActionIdFor, ba as nextTimeBoundaryInMs, bn as TagNameSchema, c as ActionError, cl as commandOrigin$1, co as resolveActionVariables, cr as checkTemplatePayload, cs as timedRunMaxIn, ct as EMPTY_AUTOMATION_STATE, d as ActionTargetResolver, dl as defineAddonMigrations, dn as SchedulerSchema, do as resolveCoreBlockEntry, dr as collectWhenMirrorSources, ds as toTimings, du as DeviceType$1, ei as evaluateWhenTree, en as REMOTE_MEDIA_COMMANDS, eo as reexpandAutomationInstance, f as ActionVariableSchema, fc as BaseAddon, fi as findChannelSource, fo as resolveCoreBlockFiles, ft as FAN_CAPTURE_FIELDS, fu as errMsg$1, g as BUILTIN_AUTOMATION_TEMPLATES, gs as validateSchedulerInput, gt as FanControlStatusSchema, h as AutomationTemplatePayloadSchema, hr as compileScalarOverride, in as RemoteLayoutPayloadSchema, io as removeFromTags, ir as capUnitResolver, is as tagsCapability, j as ConditionMirror, jn as actionsCapability, kn as actionSourceCapability, ks as DAY_MS, kt as INTERNAL_ACTION_PREFIX, l as ActionMinDelaySecSchema, li as fanPresetsCapability, ln as SWITCH_DEFAULT_OPTIONS, ls as timedRunQuickRun, lt as EMPTY_REMOTE_ASSUMED_STATE, m as AutomationStateDocSchema, ml as defineRecordKinds, mn as SetOscillationAxisInputSchema, ms as validateComposition, mt as FAN_OSCILLATION_AXIS_SETTABLE, mu as EventCategory$1, n as ACTION_TARGET_INVALIDATION_EVENTS, no as remoteLayoutComponentsCapability, nt as DeclaredDevices, oi as fanAxisPath, oo as replaceRecipeLiteral, os as timedRunCapability, ou as vocabCall, pl as defineEntryKind, po as resolveHeroLayout, pt as FAN_OSCILLATION_AXES, qc as VocabActionError, qn as buildActionSteps, ra as lockDoorLinkOfComposition, rn as RemoteAssumedStateSchema, ro as remoteSourceSteps, rr as canonicalStoredStepTargets, rs as tagKey, ru as transformSecretWrite, s as ALL_CAPABILITY_DEFINITIONS, so as replacedFieldKeys, ss as timedRunLimitOf, to as remoteCapability, u as ActionStepSchema, un as SchedulerError, ur as collectDeviceTemplates, us as timedRunSeconds, ut as EMPTY_REMOTE_CONFIG, uu as DeviceRole, vr as compositionSourceRefs, vt as FanPresetSchema, wo as runSteps, wr as coreBlockSourceKind, xa as normalizeActionUnits, xi as hasTimeLeaves, xn as TagStyleSchema, xo as resolveStepArgs, xr as coreBlockAddonId, xs as weekdayOfLocalDate, ya as nextOccurrence, yo as resolveRemoteSource, yr as compositionUnionReads, za as powerSourceLinkOfComposition, zi as isInternalActionId, zn as appendTrace } from "../../dist-Be8yFd71.mjs";
|
|
2
2
|
import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
|
|
3
|
-
import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-
|
|
4
|
-
import { i as capSeriesKey } from "../../capture-engine-
|
|
3
|
+
import { i as parseDeviceStateChanged, r as isRecord$1, t as describeCompositionSources } from "../../composition-sources-bJP8_Z2o.mjs";
|
|
4
|
+
import { i as capSeriesKey } from "../../capture-engine-CIVKm_jN.mjs";
|
|
5
5
|
import { t as prefixRange } from "../../prefix-range-Dl0znowN.mjs";
|
|
6
6
|
import { n as unwrapStoredValue, t as loadPrefixed } from "../../prefix-walk-DAOBSyH1.mjs";
|
|
7
7
|
import { n as readCurrentCommandOrigin } from "../../cap-call-scope-Bic6Ekfw.mjs";
|
|
@@ -10,7 +10,7 @@ import { z } from "zod";
|
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { customizationBlockName } from "@camstack/types/node";
|
|
12
12
|
import * as path$1 from "node:path";
|
|
13
|
-
import { nodeIdOfScopedKey } from "@camstack/types/addon";
|
|
13
|
+
import { isCapMethodAbsent, nodeIdOfScopedKey } from "@camstack/types/addon";
|
|
14
14
|
import * as fs from "node:fs/promises";
|
|
15
15
|
import { isDeepStrictEqual } from "node:util";
|
|
16
16
|
import * as os$1 from "node:os";
|
|
@@ -4105,10 +4105,23 @@ function buildActionsRuntime(deps) {
|
|
|
4105
4105
|
* The link and the off time are read from the STORED composition on each call
|
|
4106
4106
|
* (D676), never cached as a second copy. A forced restart is switch off now,
|
|
4107
4107
|
* switch on after `offSeconds`, through an injected scheduler so a spec drives
|
|
4108
|
-
* the clock; the pending switch-on is cancelled on `stop()`.
|
|
4108
|
+
* the clock; the pending switch-on is cancelled on `stop()`. A switch that declares
|
|
4109
|
+
* a native power cycle (a PoE port) is cycled in one call instead, and never
|
|
4110
|
+
* switched off or on. A switch that ANSWERED it only reports (D1058) is never
|
|
4111
|
+
* switched on or off: power on / off are refused as `not-settable`, and `getStatus`
|
|
4112
|
+
* says so (`switchSettable`) for the surfaces that withdraw them.
|
|
4109
4113
|
*
|
|
4110
4114
|
* Every refusal is a typed result with its reason, logged with the device tag.
|
|
4111
4115
|
*/
|
|
4116
|
+
/** `switch.getOptions` FAILED (not absent): what the switch can do is unknown. */
|
|
4117
|
+
var SwitchOptionsUnreadableError = class extends Error {
|
|
4118
|
+
switchDeviceId;
|
|
4119
|
+
constructor(switchDeviceId, cause) {
|
|
4120
|
+
super(`switch ${switchDeviceId}: its options could not be read (${cause instanceof Error ? cause.message : String(cause)}); not power-cycling and not switching it off blind`);
|
|
4121
|
+
this.name = "SwitchOptionsUnreadableError";
|
|
4122
|
+
this.switchDeviceId = switchDeviceId;
|
|
4123
|
+
}
|
|
4124
|
+
};
|
|
4112
4125
|
var timeoutScheduler = { schedule: (delayMs, fire) => {
|
|
4113
4126
|
const handle = setTimeout(fire, delayMs);
|
|
4114
4127
|
return { cancel: () => clearTimeout(handle) };
|
|
@@ -4118,28 +4131,40 @@ var PowerSourceService = class {
|
|
|
4118
4131
|
deps;
|
|
4119
4132
|
/** Restarts whose switch-on has not run yet, by device id. */
|
|
4120
4133
|
restarting = /* @__PURE__ */ new Map();
|
|
4134
|
+
/**
|
|
4135
|
+
* Devices whose switch-options read is failing now: warned once per streak, cleared by a
|
|
4136
|
+
* success or when the device is no longer linked. A removed device leaves at most one bare id
|
|
4137
|
+
* behind (this service has no removal hook); the set dies with the process.
|
|
4138
|
+
*/
|
|
4139
|
+
optionsReadFailing = /* @__PURE__ */ new Set();
|
|
4121
4140
|
constructor(deps) {
|
|
4122
4141
|
this.deps = deps;
|
|
4123
4142
|
}
|
|
4124
4143
|
getStatus = async ({ deviceId }) => {
|
|
4125
4144
|
const link = await this.linkOf(deviceId);
|
|
4126
|
-
if (link === null)
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4145
|
+
if (link === null) {
|
|
4146
|
+
this.optionsReadFailing.delete(deviceId);
|
|
4147
|
+
return {
|
|
4148
|
+
linked: false,
|
|
4149
|
+
switchDeviceId: null,
|
|
4150
|
+
switchName: null,
|
|
4151
|
+
switchOn: null,
|
|
4152
|
+
switchOnline: null,
|
|
4153
|
+
switchSettable: null,
|
|
4154
|
+
restartInProgress: false,
|
|
4155
|
+
offSeconds: 0
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4135
4158
|
const switchDevice = await this.deps.devices.find(link.switch).catch(() => null);
|
|
4136
4159
|
const switchOn = switchDevice === null ? null : await this.deps.devices.readOn(switchDevice.id).catch(() => null);
|
|
4160
|
+
const switchSettable = switchDevice === null ? null : await this.settableOf(deviceId, switchDevice.id);
|
|
4137
4161
|
return {
|
|
4138
4162
|
linked: true,
|
|
4139
4163
|
switchDeviceId: switchDevice?.id ?? null,
|
|
4140
4164
|
switchName: switchDevice?.name ?? link.switch.stableId,
|
|
4141
4165
|
switchOn,
|
|
4142
4166
|
switchOnline: switchDevice?.online ?? null,
|
|
4167
|
+
switchSettable,
|
|
4143
4168
|
restartInProgress: this.restarting.has(deviceId),
|
|
4144
4169
|
offSeconds: link.offSeconds
|
|
4145
4170
|
};
|
|
@@ -4161,6 +4186,28 @@ var PowerSourceService = class {
|
|
|
4161
4186
|
const { link, switchDevice } = lookup.resolved;
|
|
4162
4187
|
const switchId = switchDevice.id;
|
|
4163
4188
|
pending.switchId = switchId;
|
|
4189
|
+
const cycle = this.deps.devices.cycle;
|
|
4190
|
+
if (cycle !== void 0) {
|
|
4191
|
+
let cycled;
|
|
4192
|
+
try {
|
|
4193
|
+
cycled = await cycle(switchId);
|
|
4194
|
+
} catch (err) {
|
|
4195
|
+
this.restarting.delete(deviceId);
|
|
4196
|
+
const reason = err instanceof SwitchOptionsUnreadableError ? "switch-options-unreadable" : "switch-call-failed";
|
|
4197
|
+
return this.refuse(deviceId, reason, errorText$3(err), switchId);
|
|
4198
|
+
}
|
|
4199
|
+
if (cycled) {
|
|
4200
|
+
this.restarting.delete(deviceId);
|
|
4201
|
+
this.deps.logger.info("power-source: forced restart through the switch’s native power cycle", {
|
|
4202
|
+
tags: { deviceId },
|
|
4203
|
+
meta: {
|
|
4204
|
+
switchId,
|
|
4205
|
+
switchName: switchDevice.name
|
|
4206
|
+
}
|
|
4207
|
+
});
|
|
4208
|
+
return ACCEPTED;
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4164
4211
|
try {
|
|
4165
4212
|
await this.deps.devices.setOn(switchId, false);
|
|
4166
4213
|
} catch (err) {
|
|
@@ -4215,6 +4262,7 @@ var PowerSourceService = class {
|
|
|
4215
4262
|
const lookup = await this.lookup(deviceId);
|
|
4216
4263
|
if (lookup.kind === "refused") return this.refuse(deviceId, lookup.reason, lookup.message, null);
|
|
4217
4264
|
const { switchDevice } = lookup.resolved;
|
|
4265
|
+
if (await this.settableOf(deviceId, switchDevice.id) === false) return this.refuse(deviceId, "not-settable", `the switch ${switchDevice.name} only reports its state; it cannot be switched ${on ? "on" : "off"}`, switchDevice.id);
|
|
4218
4266
|
try {
|
|
4219
4267
|
await this.deps.devices.setOn(switchDevice.id, on);
|
|
4220
4268
|
} catch (err) {
|
|
@@ -4229,6 +4277,32 @@ var PowerSourceService = class {
|
|
|
4229
4277
|
});
|
|
4230
4278
|
return ACCEPTED;
|
|
4231
4279
|
}
|
|
4280
|
+
/**
|
|
4281
|
+
* Whether the switch can be set: `true` for a plain switch (no options reader, or a provider
|
|
4282
|
+
* without `getOptions`), `null` when the read FAILED — never `false` for unknown. Every hero
|
|
4283
|
+
* build reads `getStatus`, so a failing read warns once per device per failure streak (tagged);
|
|
4284
|
+
* a successful read ends the streak.
|
|
4285
|
+
*/
|
|
4286
|
+
async settableOf(deviceId, switchId) {
|
|
4287
|
+
const options = this.deps.devices.options;
|
|
4288
|
+
if (options === void 0) return true;
|
|
4289
|
+
try {
|
|
4290
|
+
const settable = (await options(switchId)).supportsSetState;
|
|
4291
|
+
this.optionsReadFailing.delete(deviceId);
|
|
4292
|
+
return settable;
|
|
4293
|
+
} catch (err) {
|
|
4294
|
+
if (this.optionsReadFailing.has(deviceId)) return null;
|
|
4295
|
+
this.optionsReadFailing.add(deviceId);
|
|
4296
|
+
this.deps.logger.warn("power-source: the switch options could not be read; settable unknown", {
|
|
4297
|
+
tags: { deviceId },
|
|
4298
|
+
meta: {
|
|
4299
|
+
switchId,
|
|
4300
|
+
error: errorText$3(err)
|
|
4301
|
+
}
|
|
4302
|
+
});
|
|
4303
|
+
return null;
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4232
4306
|
/** The link and the switch, or the reason there is nothing to act on. Reads the switch state: unknown is refused. */
|
|
4233
4307
|
async lookup(deviceId) {
|
|
4234
4308
|
const stored = await this.storedLinkOf(deviceId);
|
|
@@ -6201,6 +6275,8 @@ var RemoteComponentsService = class {
|
|
|
6201
6275
|
* count comes from the remote cap and is `null` when it cannot be asked.
|
|
6202
6276
|
*/
|
|
6203
6277
|
var REMOTE_CAP = "remote";
|
|
6278
|
+
var SWITCH_CAP = "switch";
|
|
6279
|
+
var POWER_SOURCE_CAP = "power-source";
|
|
6204
6280
|
/** Models built at once for a list; the cap bounds the list, this bounds the fan-out on the registry. */
|
|
6205
6281
|
var ROW_MODELS_CONCURRENCY = 16;
|
|
6206
6282
|
var HeroLayoutService = class {
|
|
@@ -6235,6 +6311,8 @@ var HeroLayoutService = class {
|
|
|
6235
6311
|
}
|
|
6236
6312
|
}));
|
|
6237
6313
|
const remoteCommands = await this.remoteCommands(deviceId);
|
|
6314
|
+
const switchOptions = bound.includes(SWITCH_CAP) ? await this.switchOptions(deviceId) : void 0;
|
|
6315
|
+
const powerSupplySettable = bound.includes(POWER_SOURCE_CAP) ? await this.powerSupplySettable(deviceId) : null;
|
|
6238
6316
|
return buildHeroModel({
|
|
6239
6317
|
device: {
|
|
6240
6318
|
id: deviceId,
|
|
@@ -6250,7 +6328,9 @@ var HeroLayoutService = class {
|
|
|
6250
6328
|
slices,
|
|
6251
6329
|
now: this.deps.now(),
|
|
6252
6330
|
remoteCommands,
|
|
6253
|
-
access: { canActuate: canActuate ?? true }
|
|
6331
|
+
access: { canActuate: canActuate ?? true },
|
|
6332
|
+
...switchOptions !== void 0 ? { switchOptions } : {},
|
|
6333
|
+
powerSupplySettable
|
|
6254
6334
|
});
|
|
6255
6335
|
};
|
|
6256
6336
|
/**
|
|
@@ -6283,6 +6363,34 @@ var HeroLayoutService = class {
|
|
|
6283
6363
|
return null;
|
|
6284
6364
|
}
|
|
6285
6365
|
}
|
|
6366
|
+
/**
|
|
6367
|
+
* What the switch can do. A provider without `getOptions` answers the defaults through the
|
|
6368
|
+
* reader; a read that FAILED is unknown — the hero draws on/off, as before (D315) — and is
|
|
6369
|
+
* logged with the device.
|
|
6370
|
+
*/
|
|
6371
|
+
async switchOptions(deviceId) {
|
|
6372
|
+
try {
|
|
6373
|
+
return await this.deps.reader.switchOptions(deviceId);
|
|
6374
|
+
} catch (error) {
|
|
6375
|
+
this.deps.logger.warn("hero model: the switch options could not be read; on/off drawn", {
|
|
6376
|
+
tags: { deviceId },
|
|
6377
|
+
meta: { error: error instanceof Error ? error.message : String(error) }
|
|
6378
|
+
});
|
|
6379
|
+
return;
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
6382
|
+
/** Whether the supply's switch can be set; a failed read is unknown (on/off drawn), logged. */
|
|
6383
|
+
async powerSupplySettable(deviceId) {
|
|
6384
|
+
try {
|
|
6385
|
+
return await this.deps.reader.powerSupplySettable(deviceId);
|
|
6386
|
+
} catch (error) {
|
|
6387
|
+
this.deps.logger.warn("hero model: the power supply status could not be read; power on/off drawn", {
|
|
6388
|
+
tags: { deviceId },
|
|
6389
|
+
meta: { error: error instanceof Error ? error.message : String(error) }
|
|
6390
|
+
});
|
|
6391
|
+
return null;
|
|
6392
|
+
}
|
|
6393
|
+
}
|
|
6286
6394
|
async remoteCommands(deviceId) {
|
|
6287
6395
|
try {
|
|
6288
6396
|
return await this.deps.reader.remoteCommands(deviceId);
|
|
@@ -6407,6 +6515,54 @@ async function seedLockDoors(deps) {
|
|
|
6407
6515
|
}
|
|
6408
6516
|
}
|
|
6409
6517
|
//#endregion
|
|
6518
|
+
//#region src/builtins/core-blocks/power-source-devices.ts
|
|
6519
|
+
/**
|
|
6520
|
+
* The devices `power-source` acts on, reached over `ctx.api`: the linked switch is read,
|
|
6521
|
+
* set, and — when its provider declares a native power cycle — cycled in one call.
|
|
6522
|
+
*/
|
|
6523
|
+
/** The switch's options; the defaults when its provider has no `getOptions`; throws typed when the read failed. */
|
|
6524
|
+
async function switchOptionsOf(api, deviceId) {
|
|
6525
|
+
try {
|
|
6526
|
+
return await api.switch.getOptions.query({ deviceId });
|
|
6527
|
+
} catch (err) {
|
|
6528
|
+
if (isCapMethodAbsent(err)) return SWITCH_DEFAULT_OPTIONS;
|
|
6529
|
+
throw new SwitchOptionsUnreadableError(deviceId, err);
|
|
6530
|
+
}
|
|
6531
|
+
}
|
|
6532
|
+
function powerSourceDevicesOver(requireApi) {
|
|
6533
|
+
return {
|
|
6534
|
+
find: async (ref) => {
|
|
6535
|
+
const row = (await requireApi().deviceManager.listAll.query({
|
|
6536
|
+
addonId: ref.addonId,
|
|
6537
|
+
projection: "slim"
|
|
6538
|
+
})).find((r) => r.stableId === ref.stableId);
|
|
6539
|
+
return row === void 0 ? null : {
|
|
6540
|
+
id: row.id,
|
|
6541
|
+
name: row.name,
|
|
6542
|
+
online: row.online
|
|
6543
|
+
};
|
|
6544
|
+
},
|
|
6545
|
+
readOn: async (deviceId) => {
|
|
6546
|
+
const status = await requireApi().switch.getStatus.query({ deviceId });
|
|
6547
|
+
const on = status !== null && typeof status === "object" ? Reflect.get(status, "on") : void 0;
|
|
6548
|
+
return typeof on === "boolean" ? on : null;
|
|
6549
|
+
},
|
|
6550
|
+
setOn: async (deviceId, on) => {
|
|
6551
|
+
await requireApi().switch.setState.mutate({
|
|
6552
|
+
deviceId,
|
|
6553
|
+
on
|
|
6554
|
+
});
|
|
6555
|
+
},
|
|
6556
|
+
options: (deviceId) => switchOptionsOf(requireApi(), deviceId),
|
|
6557
|
+
cycle: async (deviceId) => {
|
|
6558
|
+
const api = requireApi();
|
|
6559
|
+
if (!(await switchOptionsOf(api, deviceId)).supportsPowerCycle) return false;
|
|
6560
|
+
await api.switch.powerCycle.mutate({ deviceId });
|
|
6561
|
+
return true;
|
|
6562
|
+
}
|
|
6563
|
+
};
|
|
6564
|
+
}
|
|
6565
|
+
//#endregion
|
|
6410
6566
|
//#region src/builtins/core-blocks/fan-link-forward.ts
|
|
6411
6567
|
/**
|
|
6412
6568
|
* A write to a fan-control field the operator linked in Customize goes to the
|
|
@@ -9890,7 +10046,9 @@ var CoreBlocksAddon = class extends BaseAddon {
|
|
|
9890
10046
|
deviceId,
|
|
9891
10047
|
capName
|
|
9892
10048
|
}),
|
|
9893
|
-
remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length
|
|
10049
|
+
remoteCommands: async (deviceId) => (await requireApi().remote.listCommands.query({ deviceId })).commands.length,
|
|
10050
|
+
switchOptions: (deviceId) => switchOptionsOf(requireApi(), deviceId),
|
|
10051
|
+
powerSupplySettable: async (deviceId) => (await requireApi().powerSource.getStatus.query({ deviceId })).switchSettable ?? null
|
|
9894
10052
|
}
|
|
9895
10053
|
});
|
|
9896
10054
|
}
|
|
@@ -9910,30 +10068,7 @@ var CoreBlocksAddon = class extends BaseAddon {
|
|
|
9910
10068
|
if (!api) throw new Error("core-blocks: no ctx.api on this node — power-source cannot reach devices");
|
|
9911
10069
|
return api;
|
|
9912
10070
|
};
|
|
9913
|
-
return
|
|
9914
|
-
find: async (ref) => {
|
|
9915
|
-
const row = (await requireApi().deviceManager.listAll.query({
|
|
9916
|
-
addonId: ref.addonId,
|
|
9917
|
-
projection: "slim"
|
|
9918
|
-
})).find((r) => r.stableId === ref.stableId);
|
|
9919
|
-
return row === void 0 ? null : {
|
|
9920
|
-
id: row.id,
|
|
9921
|
-
name: row.name,
|
|
9922
|
-
online: row.online
|
|
9923
|
-
};
|
|
9924
|
-
},
|
|
9925
|
-
readOn: async (deviceId) => {
|
|
9926
|
-
const status = await requireApi().switch.getStatus.query({ deviceId });
|
|
9927
|
-
const on = status !== null && typeof status === "object" ? Reflect.get(status, "on") : void 0;
|
|
9928
|
-
return typeof on === "boolean" ? on : null;
|
|
9929
|
-
},
|
|
9930
|
-
setOn: async (deviceId, on) => {
|
|
9931
|
-
await requireApi().switch.setState.mutate({
|
|
9932
|
-
deviceId,
|
|
9933
|
-
on
|
|
9934
|
-
});
|
|
9935
|
-
}
|
|
9936
|
-
};
|
|
10071
|
+
return powerSourceDevicesOver(requireApi);
|
|
9937
10072
|
}
|
|
9938
10073
|
buildRemote(records) {
|
|
9939
10074
|
const settings = this.ctx.settings;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* says "not answered", never "off" (D315/D393). The remote's saved command
|
|
9
9
|
* count comes from the remote cap and is `null` when it cannot be asked.
|
|
10
10
|
*/
|
|
11
|
-
import { type IHeroLayoutProvider, type IScopedLogger, type ReadingQuantity } from "@camstack/types";
|
|
11
|
+
import { type IHeroLayoutProvider, type IScopedLogger, type ReadingQuantity, type SwitchOptions } from "@camstack/types";
|
|
12
12
|
/** What the registry says about the device. */
|
|
13
13
|
export interface HeroDeviceFacts {
|
|
14
14
|
readonly type: string;
|
|
@@ -31,6 +31,16 @@ export interface HeroLayoutReader {
|
|
|
31
31
|
readonly slice: (deviceId: number, capName: string) => Promise<unknown>;
|
|
32
32
|
/** Saved remote commands; throws when the remote cannot be asked. */
|
|
33
33
|
readonly remoteCommands: (deviceId: number) => Promise<number>;
|
|
34
|
+
/**
|
|
35
|
+
* The `switch` provider's `getOptions`: the defaults when it has none (a plain on/off switch);
|
|
36
|
+
* throws when it cannot be asked.
|
|
37
|
+
*/
|
|
38
|
+
readonly switchOptions: (deviceId: number) => Promise<SwitchOptions>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the switch that powers the device can be set (`power-source.getStatus().switchSettable`);
|
|
41
|
+
* `null` = not known. Throws when it cannot be asked.
|
|
42
|
+
*/
|
|
43
|
+
readonly powerSupplySettable: (deviceId: number) => Promise<boolean | null>;
|
|
34
44
|
}
|
|
35
45
|
export interface HeroLayoutServiceDeps {
|
|
36
46
|
readonly reader: HeroLayoutReader;
|
|
@@ -49,5 +59,13 @@ export declare class HeroLayoutService implements IHeroLayoutProvider {
|
|
|
49
59
|
*/
|
|
50
60
|
readonly getRowModels: IHeroLayoutProvider["getRowModels"];
|
|
51
61
|
private rowOf;
|
|
62
|
+
/**
|
|
63
|
+
* What the switch can do. A provider without `getOptions` answers the defaults through the
|
|
64
|
+
* reader; a read that FAILED is unknown — the hero draws on/off, as before (D315) — and is
|
|
65
|
+
* logged with the device.
|
|
66
|
+
*/
|
|
67
|
+
private switchOptions;
|
|
68
|
+
/** Whether the supply's switch can be set; a failed read is unknown (on/off drawn), logged. */
|
|
69
|
+
private powerSupplySettable;
|
|
52
70
|
private remoteCommands;
|
|
53
71
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The devices `power-source` acts on, reached over `ctx.api`: the linked switch is read,
|
|
3
|
+
* set, and — when its provider declares a native power cycle — cycled in one call.
|
|
4
|
+
*/
|
|
5
|
+
import { type AddonApi, type SwitchOptions } from "@camstack/types";
|
|
6
|
+
import { type PowerSourceDevices } from "./power-source-service.js";
|
|
7
|
+
/** The switch's options; the defaults when its provider has no `getOptions`; throws typed when the read failed. */
|
|
8
|
+
export declare function switchOptionsOf(api: AddonApi, deviceId: number): Promise<SwitchOptions>;
|
|
9
|
+
export declare function powerSourceDevicesOver(requireApi: () => AddonApi): PowerSourceDevices;
|
|
@@ -10,23 +10,47 @@
|
|
|
10
10
|
* The link and the off time are read from the STORED composition on each call
|
|
11
11
|
* (D676), never cached as a second copy. A forced restart is switch off now,
|
|
12
12
|
* switch on after `offSeconds`, through an injected scheduler so a spec drives
|
|
13
|
-
* the clock; the pending switch-on is cancelled on `stop()`.
|
|
13
|
+
* the clock; the pending switch-on is cancelled on `stop()`. A switch that declares
|
|
14
|
+
* a native power cycle (a PoE port) is cycled in one call instead, and never
|
|
15
|
+
* switched off or on. A switch that ANSWERED it only reports (D1058) is never
|
|
16
|
+
* switched on or off: power on / off are refused as `not-settable`, and `getStatus`
|
|
17
|
+
* says so (`switchSettable`) for the surfaces that withdraw them.
|
|
14
18
|
*
|
|
15
19
|
* Every refusal is a typed result with its reason, logged with the device tag.
|
|
16
20
|
*/
|
|
17
|
-
import { type CompositionSourceRef, type CoreBlock, type IPowerSourceProvider, type IScopedLogger, type PowerSourceActionResult, type PowerSourceInfo } from "@camstack/types";
|
|
21
|
+
import { type CompositionSourceRef, type CoreBlock, type IPowerSourceProvider, type IScopedLogger, type PowerSourceActionResult, type PowerSourceInfo, type SwitchOptions } from "@camstack/types";
|
|
18
22
|
/** What the service needs to know about a device it names. */
|
|
19
23
|
export interface PowerSourceDevice {
|
|
20
24
|
readonly id: number;
|
|
21
25
|
readonly name: string;
|
|
22
26
|
readonly online: boolean;
|
|
23
27
|
}
|
|
28
|
+
/** `switch.getOptions` FAILED (not absent): what the switch can do is unknown. */
|
|
29
|
+
export declare class SwitchOptionsUnreadableError extends Error {
|
|
30
|
+
readonly switchDeviceId: number;
|
|
31
|
+
constructor(switchDeviceId: number, cause: unknown);
|
|
32
|
+
}
|
|
24
33
|
export interface PowerSourceDevices {
|
|
25
34
|
/** The device for a source ref, or null when it cannot be found. */
|
|
26
35
|
readonly find: (ref: CompositionSourceRef) => Promise<PowerSourceDevice | null>;
|
|
27
36
|
/** The switch's on/off state, or null when it has none. Throws when it cannot be read. */
|
|
28
37
|
readonly readOn: (switchDeviceId: number) => Promise<boolean | null>;
|
|
29
38
|
readonly setOn: (switchDeviceId: number, on: boolean) => Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* What the switch can do (`switch.getOptions`): the defaults when its provider has no such
|
|
41
|
+
* method, `SwitchOptionsUnreadableError` when the read FAILED.
|
|
42
|
+
* Absent = every switch here is a plain on/off switch.
|
|
43
|
+
*/
|
|
44
|
+
readonly options?: (switchDeviceId: number) => Promise<SwitchOptions>;
|
|
45
|
+
/**
|
|
46
|
+
* Cut and restore the switch's output in ONE native call, when its provider declares it
|
|
47
|
+
* (`switch.getOptions().supportsPowerCycle`). Resolves true when it cycled, false when the
|
|
48
|
+
* switch has no native cycle (the restart is then off / wait / on). Throws
|
|
49
|
+
* `SwitchOptionsUnreadableError` when what the switch can do could not be read, and any other
|
|
50
|
+
* error when the cycle call fails.
|
|
51
|
+
* Absent = no switch here has one.
|
|
52
|
+
*/
|
|
53
|
+
readonly cycle?: (switchDeviceId: number) => Promise<boolean>;
|
|
30
54
|
}
|
|
31
55
|
export interface PowerSourceTimer {
|
|
32
56
|
readonly cancel: () => void;
|
|
@@ -45,6 +69,12 @@ export declare class PowerSourceService implements IPowerSourceProvider {
|
|
|
45
69
|
private readonly deps;
|
|
46
70
|
/** Restarts whose switch-on has not run yet, by device id. */
|
|
47
71
|
private readonly restarting;
|
|
72
|
+
/**
|
|
73
|
+
* Devices whose switch-options read is failing now: warned once per streak, cleared by a
|
|
74
|
+
* success or when the device is no longer linked. A removed device leaves at most one bare id
|
|
75
|
+
* behind (this service has no removal hook); the set dies with the process.
|
|
76
|
+
*/
|
|
77
|
+
private readonly optionsReadFailing;
|
|
48
78
|
constructor(deps: PowerSourceServiceDeps);
|
|
49
79
|
getStatus: ({ deviceId }: {
|
|
50
80
|
deviceId: number;
|
|
@@ -62,6 +92,13 @@ export declare class PowerSourceService implements IPowerSourceProvider {
|
|
|
62
92
|
stop(): void;
|
|
63
93
|
private finishRestart;
|
|
64
94
|
private switchTo;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the switch can be set: `true` for a plain switch (no options reader, or a provider
|
|
97
|
+
* without `getOptions`), `null` when the read FAILED — never `false` for unknown. Every hero
|
|
98
|
+
* build reads `getStatus`, so a failing read warns once per device per failure streak (tagged);
|
|
99
|
+
* a successful read ends the streak.
|
|
100
|
+
*/
|
|
101
|
+
private settableOf;
|
|
65
102
|
/** The link and the switch, or the reason there is nothing to act on. Reads the switch state: unknown is refused. */
|
|
66
103
|
private lookup;
|
|
67
104
|
/** The stored link of the device `deviceId`, read from the customizations now. */
|
|
@@ -3,8 +3,8 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
require("../../chunk-Cek0wNdY.js");
|
|
6
|
-
const require_dist = require("../../dist-
|
|
7
|
-
const require_capture_engine = require("../../capture-engine-
|
|
6
|
+
const require_dist = require("../../dist-B2-Uflhy.js");
|
|
7
|
+
const require_capture_engine = require("../../capture-engine-mZ2J-GD6.js");
|
|
8
8
|
const require_retention = require("../../retention-BcOSL6b9.js");
|
|
9
9
|
let node_crypto = require("node:crypto");
|
|
10
10
|
//#region src/builtins/device-history/capture/point-writer.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-
|
|
1
|
+
import { Al as isReadingQuantity, Bn as armRemovalReconcile, Cc as InvalidRecordError, Ct as HISTORY_ITEM_CATALOG, Gr as deviceRunsCapability, Jr as deviceTransitionsCapability, Sl as historyUnitFor, St as HISTORY_CATALOG, U as DEVICE_HISTORY_ENERGY_KEY, Vr as deviceHistoryCapability, Wr as deviceRemovalHookCapability, dc as wattMillisecondsToKwh, du as DeviceType, fc as BaseAddon, gl as emitReadiness, it as DeviceRunSchema, ml as defineRecordKinds, mu as EventCategory, yc as DeviceTransitionSchema, zc as RecordTooLargeError } from "../../dist-Be8yFd71.mjs";
|
|
2
|
+
import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-CIVKm_jN.mjs";
|
|
3
3
|
import { a as FIVE_MINUTES_MS, c as bucketEndOf, i as DAY_MS, l as bucketStartOf, n as RetentionJob, o as HOUR_MS, r as DepartureTracker, s as ROLLUP_GRACE_MS, t as DEFAULT_RETENTION, u as floorTo } from "../../retention-CUOVI1p7.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
//#region src/builtins/device-history/capture/point-writer.ts
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IDeviceManagerProvider } from "@camstack/types";
|
|
2
|
+
import type { ProviderContext } from "./device-provider-context.js";
|
|
3
|
+
/** Why a `setIdentifiers` call was refused. */
|
|
4
|
+
export type SetIdentifiersRefusal = "unknown-device" | "not-owner" | "invalid";
|
|
5
|
+
export declare class SetIdentifiersRefusedError extends Error {
|
|
6
|
+
readonly reason: SetIdentifiersRefusal;
|
|
7
|
+
constructor(reason: SetIdentifiersRefusal, message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function setIdentifiers(pctx: ProviderContext, input: Parameters<IDeviceManagerProvider["setIdentifiers"]>[0]): ReturnType<IDeviceManagerProvider["setIdentifiers"]>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The identifier INDEX (planning#593): identifier key → devices, so the
|
|
3
|
+
* device-manager can say which devices of DIFFERENT integrations share
|
|
4
|
+
* provider-declared identifiers (D1059) without reading the fleet per question.
|
|
5
|
+
*
|
|
6
|
+
* It is a PROJECTION of the device rows, never an authority: it holds, per
|
|
7
|
+
* device, only what the pair rule needs — owning addon, integration instance and
|
|
8
|
+
* the declared identifiers — and it moves with the rows, as the
|
|
9
|
+
* {@link DeviceRowObserver} of the one `DeviceRowStore`. Every write of a row
|
|
10
|
+
* passes through that store (`upsert`, `upsertRegistration`, `patch`, `remove`;
|
|
11
|
+
* `swapIds` is built of them), so a row that changes reaches the index on the
|
|
12
|
+
* same statement. A deleted device leaves the index on its row's DELETE — the
|
|
13
|
+
* statement `removeDevice` runs right before it records the tombstone (D865) —
|
|
14
|
+
* not on an event or on absence from a listing.
|
|
15
|
+
*
|
|
16
|
+
* It loads once, from the fleet listing the device-manager already reads at
|
|
17
|
+
* boot ({@link seed}). Until then it answers `unknown` (D315), never `[]`; a row
|
|
18
|
+
* write that lands while the snapshot is in flight is buffered and replayed over
|
|
19
|
+
* it, so the seed can never roll a newer write back.
|
|
20
|
+
*
|
|
21
|
+
* Read-only: it finds candidates, it links nothing (that is step 3).
|
|
22
|
+
*/
|
|
23
|
+
import { type IdentityCandidates, type IdentityConfidence, type IdentityMatchedKey } from "@camstack/types";
|
|
24
|
+
import type { PersistedDeviceMeta } from "./device-meta-types.js";
|
|
25
|
+
import type { DeviceRegistrationRow, DeviceRow, DeviceRowPatch } from "./device-row-store.js";
|
|
26
|
+
/** What the row store tells its observer, after each statement succeeded. */
|
|
27
|
+
export interface DeviceRowObserver {
|
|
28
|
+
/** A whole row was written (`upsert`). */
|
|
29
|
+
rowWritten(meta: PersistedDeviceMeta): void;
|
|
30
|
+
/** The registration columns were written (`upsertRegistration`) — insert or update. */
|
|
31
|
+
registrationWritten(row: DeviceRegistrationRow): void;
|
|
32
|
+
/** Named columns of an existing row were written (`patch`). */
|
|
33
|
+
rowPatched(deviceId: number, patch: DeviceRowPatch): void;
|
|
34
|
+
/** The row was deleted (`remove`). */
|
|
35
|
+
rowRemoved(deviceId: number): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Grade the keys two devices share. `null` when they are no candidate at all
|
|
39
|
+
* (no strong key matched).
|
|
40
|
+
*
|
|
41
|
+
* | Matched keys | Confidence |
|
|
42
|
+
* | ----------------------------------------- | ------------ |
|
|
43
|
+
* | two strong KINDS (e.g. `mac` + `serial`) | `auto` |
|
|
44
|
+
* | `mac` + `ip` | `auto` |
|
|
45
|
+
* | exactly one strong kind | `proposal` |
|
|
46
|
+
* | weak keys only (`hostname`, `ip`) | no candidate |
|
|
47
|
+
*
|
|
48
|
+
* Strength counts distinct KINDS, not values: two MACs of one device matching
|
|
49
|
+
* the other's two MACs are one kind of evidence, so a proposal.
|
|
50
|
+
*/
|
|
51
|
+
export declare function classifyIdentityMatch(keys: readonly IdentityMatchedKey[]): IdentityConfidence | null;
|
|
52
|
+
export declare class DeviceIdentityIndex implements DeviceRowObserver {
|
|
53
|
+
private readonly devices;
|
|
54
|
+
private readonly byKey;
|
|
55
|
+
/** `null` once seeded; until then, the writes to replay over the snapshot. */
|
|
56
|
+
private pending;
|
|
57
|
+
/** Load from a fleet snapshot, then replay every write that landed meanwhile. */
|
|
58
|
+
seed(rows: readonly DeviceRow[]): void;
|
|
59
|
+
rowWritten(meta: PersistedDeviceMeta): void;
|
|
60
|
+
registrationWritten(row: DeviceRegistrationRow): void;
|
|
61
|
+
rowPatched(deviceId: number, patch: DeviceRowPatch): void;
|
|
62
|
+
rowRemoved(deviceId: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Every cross-integration candidate pair, graded by `classifyIdentityMatch`,
|
|
65
|
+
* plus the devices whose identity is unknown (nothing declared).
|
|
66
|
+
*/
|
|
67
|
+
candidates(): IdentityCandidates;
|
|
68
|
+
private pairOf;
|
|
69
|
+
/** True when the write was buffered for replay over a seed still in flight. */
|
|
70
|
+
private buffer;
|
|
71
|
+
private put;
|
|
72
|
+
private drop;
|
|
73
|
+
}
|