@camstack/server 1.2.942 → 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 +26 -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 +22 -26
- 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-config-secrets.d.ts +14 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +1655 -764
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +1641 -750
- 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,83 +1,56 @@
|
|
|
1
|
+
import { k as InvalidRecordError } from "./scoped-settings-DVWUIP7Z.mjs";
|
|
1
2
|
import { s as defineRecordKinds } from "./record-kind-ub6NXqfh.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { d as ZoneBodySchema, n as DeviceTombstoneSchema, o as DiscoveryProposalBodySchema, p as IdentityLinkBodySchema, s as RoomBodySchema } from "./device-manager.cap-CV4KGp3e.mjs";
|
|
3
4
|
import { n as DeviceIdentifierKeySchema, r as DeviceIdentifiersSchema } from "./device-identifiers-iSuQCKmK.mjs";
|
|
5
|
+
import { u as preconditionOf } from "./migration-BvbfW9g-.mjs";
|
|
4
6
|
import { t as canonicalStoredDeviceType } from "./device-kind-C37Ra2wd.mjs";
|
|
5
|
-
//#region
|
|
7
|
+
//#region ../types/dist/esm/records/records-access.mjs
|
|
8
|
+
function isRecord(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function zodSummary(error) {
|
|
12
|
+
return error.issues.slice(0, 5).map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
13
|
+
}
|
|
6
14
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - **refused, nothing moved** — a precheck of `swapIds` (a row missing, the
|
|
13
|
-
* temp id taken), the mirror drain that runs before the rows move, or a
|
|
14
|
-
* claim found in the mirror after that drain (it landed while the migration
|
|
15
|
-
* was starting). Both cameras are switched back to exactly what they were,
|
|
16
|
-
* because nothing about either device changed.
|
|
17
|
-
* - **failed while moving** — any other throw from `swapIds` (rows partially
|
|
18
|
-
* moved), or from `swapHardwareState` (rows swapped, state not). The two
|
|
19
|
-
* devices may wear each other's identity; switching them back on would run
|
|
20
|
-
* pipelines against crossed identities, so they stay off and the operator is
|
|
21
|
-
* told to intervene.
|
|
22
|
-
*
|
|
23
|
-
* Only a step that KNOWS it wrote nothing may throw this. An unknown error is
|
|
24
|
-
* read as "may have moved" — the safe reading.
|
|
15
|
+
* The ONE body check of a record kind: its Zod schema, and an object at the
|
|
16
|
+
* root. `ctx.records` runs it before every write; a migration edit builder
|
|
17
|
+
* (`recordUpsertEdit`) runs it too, so a plan carries a body the kind accepts.
|
|
18
|
+
* `shaped` is the body after secret leaves were turned into what the schema
|
|
19
|
+
* reads (the caller's job; a kind without secrets passes it as is).
|
|
25
20
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
ttlMs: 2160 * 60 * 60 * 1e3,
|
|
60
|
-
from: "at"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"identity-links": {
|
|
64
|
-
schema: IdentityLinkBodySchema,
|
|
65
|
-
class: "config",
|
|
66
|
-
writeTrigger: "the identity-link reconciler sees a candidate appear, upgrade or lose its evidence; the operator confirms, dismisses or unlinks (D1063)",
|
|
67
|
-
device: "none",
|
|
68
|
-
at: "none",
|
|
69
|
-
indexes: [{
|
|
70
|
-
name: "a_device",
|
|
71
|
-
fields: ["a.deviceId"]
|
|
72
|
-
}, {
|
|
73
|
-
name: "b_device",
|
|
74
|
-
fields: ["b.deviceId"]
|
|
75
|
-
}],
|
|
76
|
-
retention: { none: "a link lives as long as both its devices; a dismissal is sticky (operator intent)" }
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
var deviceManagerRecordKinds = _deviceManagerRecordKinds;
|
|
80
|
-
_deviceManagerRecordKinds.tombstones;
|
|
21
|
+
function parseRecordBody(def, id, shaped) {
|
|
22
|
+
const parsed = def.schema.safeParse(shaped);
|
|
23
|
+
if (!parsed.success) throw new InvalidRecordError(`${def.name}/${id}: ${zodSummary(parsed.error)}`);
|
|
24
|
+
if (!isRecord(parsed.data)) throw new InvalidRecordError(`${def.name}/${id}: the body must be an object`);
|
|
25
|
+
return parsed.data;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region ../types/dist/esm/migrations/migration-record-edits.mjs
|
|
29
|
+
function refuseSecrets(kind) {
|
|
30
|
+
if (kind.declaration.secretPaths.length > 0) throw new InvalidRecordError(`${kind.name}: a kind with secret fields cannot be written by a migration plan (the keychain is outside its transaction); use a procedure`);
|
|
31
|
+
}
|
|
32
|
+
/** An `upsertRecord` edit whose body the kind's schema accepted. */
|
|
33
|
+
function recordUpsertEdit(input) {
|
|
34
|
+
refuseSecrets(input.kind);
|
|
35
|
+
const value = parseRecordBody(input.kind, input.id, input.data);
|
|
36
|
+
return {
|
|
37
|
+
op: "upsertRecord",
|
|
38
|
+
owner: input.owner,
|
|
39
|
+
kind: input.kind.name,
|
|
40
|
+
recordKey: input.id,
|
|
41
|
+
...input.deviceId === void 0 ? {} : { deviceId: input.deviceId },
|
|
42
|
+
...input.at === void 0 ? {} : { at: input.at },
|
|
43
|
+
value,
|
|
44
|
+
...input.read === void 0 ? {} : { precondition: preconditionOf(input.read) }
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The precondition of a device edit: the identity the plan read. */
|
|
48
|
+
function deviceIdentityPrecondition(identity) {
|
|
49
|
+
return preconditionOf({
|
|
50
|
+
addonId: identity.addonId,
|
|
51
|
+
stableId: identity.stableId
|
|
52
|
+
});
|
|
53
|
+
}
|
|
81
54
|
//#endregion
|
|
82
55
|
//#region src/builtins/device-manager/fleet-read-census.ts
|
|
83
56
|
/** How many stack frames identify a call site. One frame is a method; three are
|
|
@@ -205,6 +178,34 @@ var FleetReadCensus = class FleetReadCensus {
|
|
|
205
178
|
}
|
|
206
179
|
};
|
|
207
180
|
//#endregion
|
|
181
|
+
//#region src/builtins/device-manager/migration-refused.ts
|
|
182
|
+
/**
|
|
183
|
+
* A migration step that REFUSED with nothing moved.
|
|
184
|
+
*
|
|
185
|
+
* `migrateDevice` distinguishes two kinds of failure after the disable phase,
|
|
186
|
+
* and they must never be confused (D663 task 5b ruling I-1):
|
|
187
|
+
*
|
|
188
|
+
* - **refused, nothing moved** — a precheck of `swapIds` (a row missing, the
|
|
189
|
+
* temp id taken), the mirror drain that runs before the rows move, or a
|
|
190
|
+
* claim found in the mirror after that drain (it landed while the migration
|
|
191
|
+
* was starting). Both cameras are switched back to exactly what they were,
|
|
192
|
+
* because nothing about either device changed.
|
|
193
|
+
* - **failed while moving** — any other throw from `swapIds` (rows partially
|
|
194
|
+
* moved), or from `swapHardwareState` (rows swapped, state not). The two
|
|
195
|
+
* devices may wear each other's identity; switching them back on would run
|
|
196
|
+
* pipelines against crossed identities, so they stay off and the operator is
|
|
197
|
+
* told to intervene.
|
|
198
|
+
*
|
|
199
|
+
* Only a step that KNOWS it wrote nothing may throw this. An unknown error is
|
|
200
|
+
* read as "may have moved" — the safe reading.
|
|
201
|
+
*/
|
|
202
|
+
var MigrationRefusedError = class extends Error {
|
|
203
|
+
constructor(message, options) {
|
|
204
|
+
super(message, options);
|
|
205
|
+
this.name = "MigrationRefusedError";
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
//#endregion
|
|
208
209
|
//#region src/builtins/device-manager/device-row-store.ts
|
|
209
210
|
/**
|
|
210
211
|
* `device-manager:devices` — ONE ROW PER DEVICE.
|
|
@@ -343,10 +344,18 @@ var DEVICE_ROWS_COLUMNS = [
|
|
|
343
344
|
name: "location",
|
|
344
345
|
type: "TEXT"
|
|
345
346
|
},
|
|
347
|
+
{
|
|
348
|
+
name: "locationId",
|
|
349
|
+
type: "TEXT"
|
|
350
|
+
},
|
|
346
351
|
{
|
|
347
352
|
name: "tags",
|
|
348
353
|
type: "JSON"
|
|
349
354
|
},
|
|
355
|
+
{
|
|
356
|
+
name: "tagIds",
|
|
357
|
+
type: "JSON"
|
|
358
|
+
},
|
|
350
359
|
{
|
|
351
360
|
name: "disabled",
|
|
352
361
|
type: "BOOLEAN",
|
|
@@ -482,6 +491,21 @@ function deviceRowBackendOf(client) {
|
|
|
482
491
|
count: (input) => client.count.query(input)
|
|
483
492
|
};
|
|
484
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* The room patch for a child whose parent number changes hardware: a child
|
|
496
|
+
* whose room equals the room its old parent number carried inherited it (the
|
|
497
|
+
* `setLocation` cascade), so it takes the room of the number it now hangs
|
|
498
|
+
* off. A child with a different room keeps it.
|
|
499
|
+
*/
|
|
500
|
+
function inheritedRoomPatch(child, oldParentRoom, newParentRoom) {
|
|
501
|
+
if ((child.meta.locationId ?? null) !== (oldParentRoom ?? null)) return {};
|
|
502
|
+
if ((oldParentRoom ?? null) === (newParentRoom ?? null)) return {};
|
|
503
|
+
return { locationId: newParentRoom ?? null };
|
|
504
|
+
}
|
|
505
|
+
var NO_DERIVED_NAMES = {
|
|
506
|
+
room: () => null,
|
|
507
|
+
tag: () => null
|
|
508
|
+
};
|
|
485
509
|
function isPlainObject(value) {
|
|
486
510
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
487
511
|
}
|
|
@@ -510,7 +534,7 @@ function readStringArray(value) {
|
|
|
510
534
|
* `name`). A row like that cannot be projected into a `DeviceInfo` and taking
|
|
511
535
|
* the whole fleet read down for it would be worse — the caller logs the skip.
|
|
512
536
|
*/
|
|
513
|
-
function decodeDeviceRow(data) {
|
|
537
|
+
function decodeDeviceRow(data, names = NO_DERIVED_NAMES) {
|
|
514
538
|
const deviceId = readNumber(data["deviceId"]);
|
|
515
539
|
const addonId = readString(data["addonId"]);
|
|
516
540
|
const stableId = readString(data["stableId"]);
|
|
@@ -518,8 +542,13 @@ function decodeDeviceRow(data) {
|
|
|
518
542
|
const type = storedType === void 0 ? void 0 : canonicalStoredDeviceType(storedType);
|
|
519
543
|
const name = readString(data["name"]);
|
|
520
544
|
if (deviceId === void 0 || addonId === void 0 || stableId === void 0 || type === void 0 || name === void 0) return null;
|
|
521
|
-
const
|
|
522
|
-
const
|
|
545
|
+
const locationId = readString(data["locationId"]);
|
|
546
|
+
const keptTags = readStringArray(data["tags"]);
|
|
547
|
+
const tagIds = readStringArray(data["tagIds"]);
|
|
548
|
+
const tags = tagIds === void 0 ? keptTags : tagIds.flatMap((id, i) => {
|
|
549
|
+
const name = names.tag(id) ?? keptTags?.[i];
|
|
550
|
+
return name === void 0 ? [] : [name];
|
|
551
|
+
});
|
|
523
552
|
const parentDeviceId = readNumber(data["parentDeviceId"]);
|
|
524
553
|
const userNamed = readBoolean(data["userNamed"]);
|
|
525
554
|
const features = readStringArray(data["features"]);
|
|
@@ -543,8 +572,10 @@ function decodeDeviceRow(data) {
|
|
|
543
572
|
stableId,
|
|
544
573
|
type,
|
|
545
574
|
name,
|
|
546
|
-
location:
|
|
575
|
+
location: names.room(locationId ?? null),
|
|
576
|
+
locationId: locationId ?? null,
|
|
547
577
|
...tags !== void 0 && tags.length > 0 ? { tags: [...tags] } : {},
|
|
578
|
+
...tagIds === void 0 ? {} : { tagIds: [...tagIds] },
|
|
548
579
|
disabled: readBoolean(data["disabled"]) ?? false,
|
|
549
580
|
parentDeviceId: parentDeviceId ?? null,
|
|
550
581
|
...alias !== void 0 ? { alias } : {},
|
|
@@ -593,8 +624,8 @@ function encodeDeviceRow(meta, extra = {}) {
|
|
|
593
624
|
name: meta.name,
|
|
594
625
|
alias: meta.alias ?? null,
|
|
595
626
|
userNamed: meta.userNamed ?? null,
|
|
596
|
-
|
|
597
|
-
|
|
627
|
+
locationId: meta.locationId,
|
|
628
|
+
tagIds: meta.tagIds === void 0 ? null : [...meta.tagIds],
|
|
598
629
|
disabled: meta.disabled,
|
|
599
630
|
parentDeviceId: meta.parentDeviceId,
|
|
600
631
|
registered: extra.registered ?? false,
|
|
@@ -634,6 +665,12 @@ var DeviceRowStore = class {
|
|
|
634
665
|
logger;
|
|
635
666
|
observer;
|
|
636
667
|
declared = null;
|
|
668
|
+
/** Where `meta.location` / `meta.tags` get their names (D1089); set once the records are read. */
|
|
669
|
+
names = NO_DERIVED_NAMES;
|
|
670
|
+
/** Wire the room and tag name lookups the decoder derives `location` / `tags` from. */
|
|
671
|
+
setDerivedNames(names) {
|
|
672
|
+
this.names = names;
|
|
673
|
+
}
|
|
637
674
|
/** Call-site attribution for fleet reads. Armed only by
|
|
638
675
|
* `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
|
|
639
676
|
census;
|
|
@@ -689,7 +726,7 @@ var DeviceRowStore = class {
|
|
|
689
726
|
key: String(deviceId)
|
|
690
727
|
});
|
|
691
728
|
if (!isPlainObject(raw)) return null;
|
|
692
|
-
const decoded = decodeDeviceRow(raw);
|
|
729
|
+
const decoded = decodeDeviceRow(raw, this.names);
|
|
693
730
|
if (decoded === null) {
|
|
694
731
|
this.logger.warn("device row skipped — identity fields missing", { tags: { deviceId } });
|
|
695
732
|
return null;
|
|
@@ -897,6 +934,18 @@ var DeviceRowStore = class {
|
|
|
897
934
|
await this.declare();
|
|
898
935
|
return this.backend.count({ collection: DEVICE_ROWS_COLLECTION });
|
|
899
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* The named columns of EVERY row, raw: no decode, no derived names. The migrations read the
|
|
939
|
+
* legacy `location` and the kept `tags` this way, because the decoded row no longer shows them.
|
|
940
|
+
*/
|
|
941
|
+
async readRawColumns(columns) {
|
|
942
|
+
await this.declare();
|
|
943
|
+
return (await this.backend.query({
|
|
944
|
+
collection: DEVICE_ROWS_COLLECTION,
|
|
945
|
+
filter: {},
|
|
946
|
+
columns
|
|
947
|
+
})).map((record) => record.data);
|
|
948
|
+
}
|
|
900
949
|
async list(filter, columns, callerAddonId) {
|
|
901
950
|
const site = this.census.siteOf(callerAddonId);
|
|
902
951
|
await this.declare();
|
|
@@ -908,7 +957,7 @@ var DeviceRowStore = class {
|
|
|
908
957
|
this.census.record(site, records.length);
|
|
909
958
|
const out = [];
|
|
910
959
|
for (const record of records) {
|
|
911
|
-
const decoded = decodeDeviceRow(record.data);
|
|
960
|
+
const decoded = decodeDeviceRow(record.data, this.names);
|
|
912
961
|
if (decoded === null) {
|
|
913
962
|
this.logger.warn("device row skipped — identity fields missing", { meta: { rowId: record.id } });
|
|
914
963
|
continue;
|
|
@@ -972,7 +1021,7 @@ var DeviceRowStore = class {
|
|
|
972
1021
|
type: row.type,
|
|
973
1022
|
name: row.name,
|
|
974
1023
|
userNamed: row.userNamed,
|
|
975
|
-
|
|
1024
|
+
locationId: row.locationId,
|
|
976
1025
|
disabled: row.disabled,
|
|
977
1026
|
parentDeviceId: row.parentDeviceId,
|
|
978
1027
|
registered: row.registered,
|
|
@@ -1026,23 +1075,36 @@ var DeviceRowStore = class {
|
|
|
1026
1075
|
throw new MigrationRefusedError(`[device-manager] swapIds: precheck failed before any row moved — ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
1027
1076
|
});
|
|
1028
1077
|
await this.moveRow(rowA, tempId);
|
|
1029
|
-
await this.moveRow(
|
|
1078
|
+
await this.moveRow({
|
|
1079
|
+
...rowB,
|
|
1080
|
+
meta: {
|
|
1081
|
+
...rowB.meta,
|
|
1082
|
+
locationId: rowA.meta.locationId
|
|
1083
|
+
}
|
|
1084
|
+
}, a);
|
|
1030
1085
|
await this.moveRow({
|
|
1031
1086
|
...rowA,
|
|
1032
1087
|
meta: {
|
|
1033
1088
|
...rowA.meta,
|
|
1034
|
-
id: tempId
|
|
1089
|
+
id: tempId,
|
|
1090
|
+
locationId: rowB.meta.locationId
|
|
1035
1091
|
}
|
|
1036
1092
|
}, b);
|
|
1037
|
-
for (const
|
|
1038
|
-
|
|
1093
|
+
for (const child of childrenOfA) await this.patch(child.meta.id, {
|
|
1094
|
+
parentDeviceId: b,
|
|
1095
|
+
...inheritedRoomPatch(child, rowA.meta.locationId, rowB.meta.locationId)
|
|
1096
|
+
});
|
|
1097
|
+
for (const child of childrenOfB) await this.patch(child.meta.id, {
|
|
1098
|
+
parentDeviceId: a,
|
|
1099
|
+
...inheritedRoomPatch(child, rowB.meta.locationId, rowA.meta.locationId)
|
|
1100
|
+
});
|
|
1039
1101
|
this.logger.info("device ids swapped", {
|
|
1040
1102
|
tags: { deviceId: a },
|
|
1041
1103
|
meta: {
|
|
1042
1104
|
a,
|
|
1043
1105
|
b,
|
|
1044
|
-
childrenOfA,
|
|
1045
|
-
childrenOfB
|
|
1106
|
+
childrenOfA: childrenOfA.map((r) => r.meta.id),
|
|
1107
|
+
childrenOfB: childrenOfB.map((r) => r.meta.id)
|
|
1046
1108
|
}
|
|
1047
1109
|
});
|
|
1048
1110
|
}
|
|
@@ -1058,8 +1120,8 @@ var DeviceRowStore = class {
|
|
|
1058
1120
|
return {
|
|
1059
1121
|
rowA,
|
|
1060
1122
|
rowB,
|
|
1061
|
-
childrenOfA:
|
|
1062
|
-
childrenOfB:
|
|
1123
|
+
childrenOfA: await this.listByParent(a),
|
|
1124
|
+
childrenOfB: await this.listByParent(b)
|
|
1063
1125
|
};
|
|
1064
1126
|
}
|
|
1065
1127
|
/** Rewrite a row under a new id and drop the old key. Not exported: the only
|
|
@@ -1112,5 +1174,72 @@ var DeviceRowStore = class {
|
|
|
1112
1174
|
};
|
|
1113
1175
|
}
|
|
1114
1176
|
};
|
|
1177
|
+
var _deviceManagerRecordKinds = defineRecordKinds({
|
|
1178
|
+
tombstones: {
|
|
1179
|
+
schema: DeviceTombstoneSchema.omit({ deviceId: true }),
|
|
1180
|
+
class: "ledger",
|
|
1181
|
+
writeTrigger: "`removeDevice` records one row per deleted device after the device row is gone; re-record keeps the earlier `deletedAt`",
|
|
1182
|
+
device: "none",
|
|
1183
|
+
at: "required",
|
|
1184
|
+
indexes: [{
|
|
1185
|
+
name: "deleted_at",
|
|
1186
|
+
fields: ["deletedAt"]
|
|
1187
|
+
}],
|
|
1188
|
+
retention: {
|
|
1189
|
+
owner: "device-manager",
|
|
1190
|
+
reason: "90 days (`DEVICE_TOMBSTONE_RETENTION_MS`), pruned whenever a tombstone is written or the list is read"
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
"discovery-proposals": {
|
|
1194
|
+
schema: DiscoveryProposalBodySchema,
|
|
1195
|
+
class: "config",
|
|
1196
|
+
writeTrigger: "the passive listener and the 30-minute sweep of `local-network` re-see a device (`lastSeenAt` and `at` move); `dismissDiscoveryProposal` sets `dismissed`",
|
|
1197
|
+
device: "none",
|
|
1198
|
+
at: "required",
|
|
1199
|
+
indexes: [{
|
|
1200
|
+
name: "last_seen_at",
|
|
1201
|
+
fields: ["lastSeenAt"]
|
|
1202
|
+
}],
|
|
1203
|
+
retention: {
|
|
1204
|
+
ttlMs: 2160 * 60 * 60 * 1e3,
|
|
1205
|
+
from: "at"
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
rooms: {
|
|
1209
|
+
schema: RoomBodySchema,
|
|
1210
|
+
class: "config",
|
|
1211
|
+
writeTrigger: "`ensureRoom` creates one, `updateRoom` edits it (rename, icon, description, zone); `deleteRoom` removes it and clears every device reference in one operation",
|
|
1212
|
+
device: "none",
|
|
1213
|
+
at: "none",
|
|
1214
|
+
indexes: [],
|
|
1215
|
+
retention: { none: "a room lives until the operator deletes it" }
|
|
1216
|
+
},
|
|
1217
|
+
zones: {
|
|
1218
|
+
schema: ZoneBodySchema,
|
|
1219
|
+
class: "config",
|
|
1220
|
+
writeTrigger: "`setSiteZone` / `setLocationZone` create one, `renameSiteZone` edits it, `removeSiteZone` removes it and clears the `zoneId` of its rooms",
|
|
1221
|
+
device: "none",
|
|
1222
|
+
at: "none",
|
|
1223
|
+
indexes: [],
|
|
1224
|
+
retention: { none: "a zone lives until the operator deletes it" }
|
|
1225
|
+
},
|
|
1226
|
+
"identity-links": {
|
|
1227
|
+
schema: IdentityLinkBodySchema,
|
|
1228
|
+
class: "config",
|
|
1229
|
+
writeTrigger: "the identity-link reconciler sees a candidate appear, upgrade or lose its evidence; the operator confirms, dismisses or unlinks (D1063)",
|
|
1230
|
+
device: "none",
|
|
1231
|
+
at: "none",
|
|
1232
|
+
indexes: [{
|
|
1233
|
+
name: "a_device",
|
|
1234
|
+
fields: ["a.deviceId"]
|
|
1235
|
+
}, {
|
|
1236
|
+
name: "b_device",
|
|
1237
|
+
fields: ["b.deviceId"]
|
|
1238
|
+
}],
|
|
1239
|
+
retention: { none: "a link lives as long as both its devices; a dismissal is sticky (operator intent)" }
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1242
|
+
var deviceManagerRecordKinds = _deviceManagerRecordKinds;
|
|
1243
|
+
_deviceManagerRecordKinds.tombstones;
|
|
1115
1244
|
//#endregion
|
|
1116
|
-
export {
|
|
1245
|
+
export { deviceRowBackendOf as a, recordUpsertEdit as c, DeviceRowStore as i, parseRecordBody as l, DEVICE_ROWS_COLLECTION as n, MigrationRefusedError as o, DEVICE_ROWS_FLEET_LIMIT as r, deviceIdentityPrecondition as s, deviceManagerRecordKinds as t };
|