@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,84 +1,56 @@
|
|
|
1
|
+
const require_scoped_settings = require("./scoped-settings-CylSSq_8.js");
|
|
1
2
|
const require_record_kind = require("./record-kind-DoBfYHCs.js");
|
|
2
|
-
const require_device_manager_cap = require("./device-manager.cap-
|
|
3
|
+
const require_device_manager_cap = require("./device-manager.cap-B9qVf7ag.js");
|
|
3
4
|
const require_device_identifiers = require("./device-identifiers-BQg9EQi1.js");
|
|
5
|
+
const require_migration = require("./migration-CHPdAdNh.js");
|
|
4
6
|
const require_device_kind = require("./device-kind-FMhJg8uC.js");
|
|
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
|
-
retention: {
|
|
60
|
-
ttlMs: 2160 * 60 * 60 * 1e3,
|
|
61
|
-
from: "at"
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
"identity-links": {
|
|
65
|
-
schema: require_device_manager_cap.IdentityLinkBodySchema,
|
|
66
|
-
class: "config",
|
|
67
|
-
writeTrigger: "the identity-link reconciler sees a candidate appear, upgrade or lose its evidence; the operator confirms, dismisses or unlinks (D1063)",
|
|
68
|
-
device: "none",
|
|
69
|
-
at: "none",
|
|
70
|
-
indexes: [{
|
|
71
|
-
name: "a_device",
|
|
72
|
-
fields: ["a.deviceId"]
|
|
73
|
-
}, {
|
|
74
|
-
name: "b_device",
|
|
75
|
-
fields: ["b.deviceId"]
|
|
76
|
-
}],
|
|
77
|
-
retention: { none: "a link lives as long as both its devices; a dismissal is sticky (operator intent)" }
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
var deviceManagerRecordKinds = _deviceManagerRecordKinds;
|
|
81
|
-
_deviceManagerRecordKinds.tombstones;
|
|
21
|
+
function parseRecordBody(def, id, shaped) {
|
|
22
|
+
const parsed = def.schema.safeParse(shaped);
|
|
23
|
+
if (!parsed.success) throw new require_scoped_settings.InvalidRecordError(`${def.name}/${id}: ${zodSummary(parsed.error)}`);
|
|
24
|
+
if (!isRecord(parsed.data)) throw new require_scoped_settings.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 require_scoped_settings.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: require_migration.preconditionOf(input.read) }
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The precondition of a device edit: the identity the plan read. */
|
|
48
|
+
function deviceIdentityPrecondition(identity) {
|
|
49
|
+
return require_migration.preconditionOf({
|
|
50
|
+
addonId: identity.addonId,
|
|
51
|
+
stableId: identity.stableId
|
|
52
|
+
});
|
|
53
|
+
}
|
|
82
54
|
//#endregion
|
|
83
55
|
//#region src/builtins/device-manager/fleet-read-census.ts
|
|
84
56
|
/** How many stack frames identify a call site. One frame is a method; three are
|
|
@@ -206,6 +178,34 @@ var FleetReadCensus = class FleetReadCensus {
|
|
|
206
178
|
}
|
|
207
179
|
};
|
|
208
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
|
|
209
209
|
//#region src/builtins/device-manager/device-row-store.ts
|
|
210
210
|
/**
|
|
211
211
|
* `device-manager:devices` — ONE ROW PER DEVICE.
|
|
@@ -344,10 +344,18 @@ var DEVICE_ROWS_COLUMNS = [
|
|
|
344
344
|
name: "location",
|
|
345
345
|
type: "TEXT"
|
|
346
346
|
},
|
|
347
|
+
{
|
|
348
|
+
name: "locationId",
|
|
349
|
+
type: "TEXT"
|
|
350
|
+
},
|
|
347
351
|
{
|
|
348
352
|
name: "tags",
|
|
349
353
|
type: "JSON"
|
|
350
354
|
},
|
|
355
|
+
{
|
|
356
|
+
name: "tagIds",
|
|
357
|
+
type: "JSON"
|
|
358
|
+
},
|
|
351
359
|
{
|
|
352
360
|
name: "disabled",
|
|
353
361
|
type: "BOOLEAN",
|
|
@@ -483,6 +491,21 @@ function deviceRowBackendOf(client) {
|
|
|
483
491
|
count: (input) => client.count.query(input)
|
|
484
492
|
};
|
|
485
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
|
+
};
|
|
486
509
|
function isPlainObject(value) {
|
|
487
510
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
488
511
|
}
|
|
@@ -511,7 +534,7 @@ function readStringArray(value) {
|
|
|
511
534
|
* `name`). A row like that cannot be projected into a `DeviceInfo` and taking
|
|
512
535
|
* the whole fleet read down for it would be worse — the caller logs the skip.
|
|
513
536
|
*/
|
|
514
|
-
function decodeDeviceRow(data) {
|
|
537
|
+
function decodeDeviceRow(data, names = NO_DERIVED_NAMES) {
|
|
515
538
|
const deviceId = readNumber(data["deviceId"]);
|
|
516
539
|
const addonId = readString(data["addonId"]);
|
|
517
540
|
const stableId = readString(data["stableId"]);
|
|
@@ -519,8 +542,13 @@ function decodeDeviceRow(data) {
|
|
|
519
542
|
const type = storedType === void 0 ? void 0 : require_device_kind.canonicalStoredDeviceType(storedType);
|
|
520
543
|
const name = readString(data["name"]);
|
|
521
544
|
if (deviceId === void 0 || addonId === void 0 || stableId === void 0 || type === void 0 || name === void 0) return null;
|
|
522
|
-
const
|
|
523
|
-
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
|
+
});
|
|
524
552
|
const parentDeviceId = readNumber(data["parentDeviceId"]);
|
|
525
553
|
const userNamed = readBoolean(data["userNamed"]);
|
|
526
554
|
const features = readStringArray(data["features"]);
|
|
@@ -544,8 +572,10 @@ function decodeDeviceRow(data) {
|
|
|
544
572
|
stableId,
|
|
545
573
|
type,
|
|
546
574
|
name,
|
|
547
|
-
location:
|
|
575
|
+
location: names.room(locationId ?? null),
|
|
576
|
+
locationId: locationId ?? null,
|
|
548
577
|
...tags !== void 0 && tags.length > 0 ? { tags: [...tags] } : {},
|
|
578
|
+
...tagIds === void 0 ? {} : { tagIds: [...tagIds] },
|
|
549
579
|
disabled: readBoolean(data["disabled"]) ?? false,
|
|
550
580
|
parentDeviceId: parentDeviceId ?? null,
|
|
551
581
|
...alias !== void 0 ? { alias } : {},
|
|
@@ -594,8 +624,8 @@ function encodeDeviceRow(meta, extra = {}) {
|
|
|
594
624
|
name: meta.name,
|
|
595
625
|
alias: meta.alias ?? null,
|
|
596
626
|
userNamed: meta.userNamed ?? null,
|
|
597
|
-
|
|
598
|
-
|
|
627
|
+
locationId: meta.locationId,
|
|
628
|
+
tagIds: meta.tagIds === void 0 ? null : [...meta.tagIds],
|
|
599
629
|
disabled: meta.disabled,
|
|
600
630
|
parentDeviceId: meta.parentDeviceId,
|
|
601
631
|
registered: extra.registered ?? false,
|
|
@@ -635,6 +665,12 @@ var DeviceRowStore = class {
|
|
|
635
665
|
logger;
|
|
636
666
|
observer;
|
|
637
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
|
+
}
|
|
638
674
|
/** Call-site attribution for fleet reads. Armed only by
|
|
639
675
|
* `CAMSTACK_FLEET_READ_CENSUS_MS`; see `fleet-read-census.ts`. */
|
|
640
676
|
census;
|
|
@@ -690,7 +726,7 @@ var DeviceRowStore = class {
|
|
|
690
726
|
key: String(deviceId)
|
|
691
727
|
});
|
|
692
728
|
if (!isPlainObject(raw)) return null;
|
|
693
|
-
const decoded = decodeDeviceRow(raw);
|
|
729
|
+
const decoded = decodeDeviceRow(raw, this.names);
|
|
694
730
|
if (decoded === null) {
|
|
695
731
|
this.logger.warn("device row skipped — identity fields missing", { tags: { deviceId } });
|
|
696
732
|
return null;
|
|
@@ -898,6 +934,18 @@ var DeviceRowStore = class {
|
|
|
898
934
|
await this.declare();
|
|
899
935
|
return this.backend.count({ collection: DEVICE_ROWS_COLLECTION });
|
|
900
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
|
+
}
|
|
901
949
|
async list(filter, columns, callerAddonId) {
|
|
902
950
|
const site = this.census.siteOf(callerAddonId);
|
|
903
951
|
await this.declare();
|
|
@@ -909,7 +957,7 @@ var DeviceRowStore = class {
|
|
|
909
957
|
this.census.record(site, records.length);
|
|
910
958
|
const out = [];
|
|
911
959
|
for (const record of records) {
|
|
912
|
-
const decoded = decodeDeviceRow(record.data);
|
|
960
|
+
const decoded = decodeDeviceRow(record.data, this.names);
|
|
913
961
|
if (decoded === null) {
|
|
914
962
|
this.logger.warn("device row skipped — identity fields missing", { meta: { rowId: record.id } });
|
|
915
963
|
continue;
|
|
@@ -973,7 +1021,7 @@ var DeviceRowStore = class {
|
|
|
973
1021
|
type: row.type,
|
|
974
1022
|
name: row.name,
|
|
975
1023
|
userNamed: row.userNamed,
|
|
976
|
-
|
|
1024
|
+
locationId: row.locationId,
|
|
977
1025
|
disabled: row.disabled,
|
|
978
1026
|
parentDeviceId: row.parentDeviceId,
|
|
979
1027
|
registered: row.registered,
|
|
@@ -1027,23 +1075,36 @@ var DeviceRowStore = class {
|
|
|
1027
1075
|
throw new MigrationRefusedError(`[device-manager] swapIds: precheck failed before any row moved — ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
1028
1076
|
});
|
|
1029
1077
|
await this.moveRow(rowA, tempId);
|
|
1030
|
-
await this.moveRow(
|
|
1078
|
+
await this.moveRow({
|
|
1079
|
+
...rowB,
|
|
1080
|
+
meta: {
|
|
1081
|
+
...rowB.meta,
|
|
1082
|
+
locationId: rowA.meta.locationId
|
|
1083
|
+
}
|
|
1084
|
+
}, a);
|
|
1031
1085
|
await this.moveRow({
|
|
1032
1086
|
...rowA,
|
|
1033
1087
|
meta: {
|
|
1034
1088
|
...rowA.meta,
|
|
1035
|
-
id: tempId
|
|
1089
|
+
id: tempId,
|
|
1090
|
+
locationId: rowB.meta.locationId
|
|
1036
1091
|
}
|
|
1037
1092
|
}, b);
|
|
1038
|
-
for (const
|
|
1039
|
-
|
|
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
|
+
});
|
|
1040
1101
|
this.logger.info("device ids swapped", {
|
|
1041
1102
|
tags: { deviceId: a },
|
|
1042
1103
|
meta: {
|
|
1043
1104
|
a,
|
|
1044
1105
|
b,
|
|
1045
|
-
childrenOfA,
|
|
1046
|
-
childrenOfB
|
|
1106
|
+
childrenOfA: childrenOfA.map((r) => r.meta.id),
|
|
1107
|
+
childrenOfB: childrenOfB.map((r) => r.meta.id)
|
|
1047
1108
|
}
|
|
1048
1109
|
});
|
|
1049
1110
|
}
|
|
@@ -1059,8 +1120,8 @@ var DeviceRowStore = class {
|
|
|
1059
1120
|
return {
|
|
1060
1121
|
rowA,
|
|
1061
1122
|
rowB,
|
|
1062
|
-
childrenOfA:
|
|
1063
|
-
childrenOfB:
|
|
1123
|
+
childrenOfA: await this.listByParent(a),
|
|
1124
|
+
childrenOfB: await this.listByParent(b)
|
|
1064
1125
|
};
|
|
1065
1126
|
}
|
|
1066
1127
|
/** Rewrite a row under a new id and drop the old key. Not exported: the only
|
|
@@ -1113,6 +1174,74 @@ var DeviceRowStore = class {
|
|
|
1113
1174
|
};
|
|
1114
1175
|
}
|
|
1115
1176
|
};
|
|
1177
|
+
var DeviceTombstoneBodySchema = require_device_manager_cap.DeviceTombstoneSchema.omit({ deviceId: true });
|
|
1178
|
+
var _deviceManagerRecordKinds = require_record_kind.defineRecordKinds({
|
|
1179
|
+
tombstones: {
|
|
1180
|
+
schema: DeviceTombstoneBodySchema,
|
|
1181
|
+
class: "ledger",
|
|
1182
|
+
writeTrigger: "`removeDevice` records one row per deleted device after the device row is gone; re-record keeps the earlier `deletedAt`",
|
|
1183
|
+
device: "none",
|
|
1184
|
+
at: "required",
|
|
1185
|
+
indexes: [{
|
|
1186
|
+
name: "deleted_at",
|
|
1187
|
+
fields: ["deletedAt"]
|
|
1188
|
+
}],
|
|
1189
|
+
retention: {
|
|
1190
|
+
owner: "device-manager",
|
|
1191
|
+
reason: "90 days (`DEVICE_TOMBSTONE_RETENTION_MS`), pruned whenever a tombstone is written or the list is read"
|
|
1192
|
+
}
|
|
1193
|
+
},
|
|
1194
|
+
"discovery-proposals": {
|
|
1195
|
+
schema: require_device_manager_cap.DiscoveryProposalBodySchema,
|
|
1196
|
+
class: "config",
|
|
1197
|
+
writeTrigger: "the passive listener and the 30-minute sweep of `local-network` re-see a device (`lastSeenAt` and `at` move); `dismissDiscoveryProposal` sets `dismissed`",
|
|
1198
|
+
device: "none",
|
|
1199
|
+
at: "required",
|
|
1200
|
+
indexes: [{
|
|
1201
|
+
name: "last_seen_at",
|
|
1202
|
+
fields: ["lastSeenAt"]
|
|
1203
|
+
}],
|
|
1204
|
+
retention: {
|
|
1205
|
+
ttlMs: 2160 * 60 * 60 * 1e3,
|
|
1206
|
+
from: "at"
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
rooms: {
|
|
1210
|
+
schema: require_device_manager_cap.RoomBodySchema,
|
|
1211
|
+
class: "config",
|
|
1212
|
+
writeTrigger: "`ensureRoom` creates one, `updateRoom` edits it (rename, icon, description, zone); `deleteRoom` removes it and clears every device reference in one operation",
|
|
1213
|
+
device: "none",
|
|
1214
|
+
at: "none",
|
|
1215
|
+
indexes: [],
|
|
1216
|
+
retention: { none: "a room lives until the operator deletes it" }
|
|
1217
|
+
},
|
|
1218
|
+
zones: {
|
|
1219
|
+
schema: require_device_manager_cap.ZoneBodySchema,
|
|
1220
|
+
class: "config",
|
|
1221
|
+
writeTrigger: "`setSiteZone` / `setLocationZone` create one, `renameSiteZone` edits it, `removeSiteZone` removes it and clears the `zoneId` of its rooms",
|
|
1222
|
+
device: "none",
|
|
1223
|
+
at: "none",
|
|
1224
|
+
indexes: [],
|
|
1225
|
+
retention: { none: "a zone lives until the operator deletes it" }
|
|
1226
|
+
},
|
|
1227
|
+
"identity-links": {
|
|
1228
|
+
schema: require_device_manager_cap.IdentityLinkBodySchema,
|
|
1229
|
+
class: "config",
|
|
1230
|
+
writeTrigger: "the identity-link reconciler sees a candidate appear, upgrade or lose its evidence; the operator confirms, dismisses or unlinks (D1063)",
|
|
1231
|
+
device: "none",
|
|
1232
|
+
at: "none",
|
|
1233
|
+
indexes: [{
|
|
1234
|
+
name: "a_device",
|
|
1235
|
+
fields: ["a.deviceId"]
|
|
1236
|
+
}, {
|
|
1237
|
+
name: "b_device",
|
|
1238
|
+
fields: ["b.deviceId"]
|
|
1239
|
+
}],
|
|
1240
|
+
retention: { none: "a link lives as long as both its devices; a dismissal is sticky (operator intent)" }
|
|
1241
|
+
}
|
|
1242
|
+
});
|
|
1243
|
+
var deviceManagerRecordKinds = _deviceManagerRecordKinds;
|
|
1244
|
+
_deviceManagerRecordKinds.tombstones;
|
|
1116
1245
|
//#endregion
|
|
1117
1246
|
Object.defineProperty(exports, "DEVICE_ROWS_COLLECTION", {
|
|
1118
1247
|
enumerable: true,
|
|
@@ -1120,6 +1249,12 @@ Object.defineProperty(exports, "DEVICE_ROWS_COLLECTION", {
|
|
|
1120
1249
|
return DEVICE_ROWS_COLLECTION;
|
|
1121
1250
|
}
|
|
1122
1251
|
});
|
|
1252
|
+
Object.defineProperty(exports, "DEVICE_ROWS_FLEET_LIMIT", {
|
|
1253
|
+
enumerable: true,
|
|
1254
|
+
get: function() {
|
|
1255
|
+
return DEVICE_ROWS_FLEET_LIMIT;
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1123
1258
|
Object.defineProperty(exports, "DeviceRowStore", {
|
|
1124
1259
|
enumerable: true,
|
|
1125
1260
|
get: function() {
|
|
@@ -1132,6 +1267,12 @@ Object.defineProperty(exports, "MigrationRefusedError", {
|
|
|
1132
1267
|
return MigrationRefusedError;
|
|
1133
1268
|
}
|
|
1134
1269
|
});
|
|
1270
|
+
Object.defineProperty(exports, "deviceIdentityPrecondition", {
|
|
1271
|
+
enumerable: true,
|
|
1272
|
+
get: function() {
|
|
1273
|
+
return deviceIdentityPrecondition;
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1135
1276
|
Object.defineProperty(exports, "deviceManagerRecordKinds", {
|
|
1136
1277
|
enumerable: true,
|
|
1137
1278
|
get: function() {
|
|
@@ -1144,3 +1285,15 @@ Object.defineProperty(exports, "deviceRowBackendOf", {
|
|
|
1144
1285
|
return deviceRowBackendOf;
|
|
1145
1286
|
}
|
|
1146
1287
|
});
|
|
1288
|
+
Object.defineProperty(exports, "parseRecordBody", {
|
|
1289
|
+
enumerable: true,
|
|
1290
|
+
get: function() {
|
|
1291
|
+
return parseRecordBody;
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
Object.defineProperty(exports, "recordUpsertEdit", {
|
|
1295
|
+
enumerable: true,
|
|
1296
|
+
get: function() {
|
|
1297
|
+
return recordUpsertEdit;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of named entities held as records with an id (D1089): a room, a site
|
|
3
|
+
* zone, a tag.
|
|
4
|
+
*
|
|
5
|
+
* The store reads every record once (few, hand-made) and keeps the working copy
|
|
6
|
+
* here; a write goes to the record first and lands in the map only when it
|
|
7
|
+
* succeeded. ONE operation is ONE `put` of ONE record — a rename never touches
|
|
8
|
+
* a record that merely references the entity.
|
|
9
|
+
*
|
|
10
|
+
* A name is unique within the store, compared by `entityNameKey`. `ensure` of a
|
|
11
|
+
* name that exists returns the existing entity, so "type a new name in the
|
|
12
|
+
* picker" is one call. A reference whose id is unknown reads as `null`
|
|
13
|
+
* ({@link nameOf}): a reader never throws on it and never shows the raw id.
|
|
14
|
+
*/
|
|
15
|
+
import { type EntityKind, type RecordKindHandle } from "@camstack/types";
|
|
16
|
+
export interface NamedBody {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly order?: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** The entity as it travels: the record id beside its body. */
|
|
21
|
+
export type Entity<TBody extends NamedBody> = TBody & {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
};
|
|
24
|
+
/** Refused: the name belongs to another entity of the same kind. */
|
|
25
|
+
export declare class EntityNameTakenError extends Error {
|
|
26
|
+
readonly entityKind: EntityKind;
|
|
27
|
+
readonly name: string;
|
|
28
|
+
constructor(entityKind: EntityKind, name: string);
|
|
29
|
+
}
|
|
30
|
+
/** Refused: no entity has this id. */
|
|
31
|
+
export declare class EntityNotFoundError extends Error {
|
|
32
|
+
readonly entityKind: EntityKind;
|
|
33
|
+
readonly id: string;
|
|
34
|
+
constructor(entityKind: EntityKind, id: string);
|
|
35
|
+
}
|
|
36
|
+
export declare class NamedEntityStore<TBody extends NamedBody> {
|
|
37
|
+
readonly entityKind: EntityKind;
|
|
38
|
+
private readonly kind;
|
|
39
|
+
private readonly validate;
|
|
40
|
+
private entities;
|
|
41
|
+
private readonly lock;
|
|
42
|
+
constructor(entityKind: EntityKind, kind: RecordKindHandle<TBody>, validate: (body: unknown) => TBody);
|
|
43
|
+
load(): Promise<void>;
|
|
44
|
+
/** The name of entity `id`, or `null` when unset or unknown. Never the id. */
|
|
45
|
+
nameOf(id: string | null | undefined): string | null;
|
|
46
|
+
get(id: string): Entity<TBody> | null;
|
|
47
|
+
/** The entity named `name` (trimmed, case-insensitive), or `null`. */
|
|
48
|
+
findByName(name: string): Entity<TBody> | null;
|
|
49
|
+
list(): readonly Entity<TBody>[];
|
|
50
|
+
/**
|
|
51
|
+
* Create the entity named `name`, or return the one that has it. `preferredId` is the id a
|
|
52
|
+
* migration already wrote into referencing rows: it is adopted when no entity holds it (a record
|
|
53
|
+
* that arrives late never orphans a migrated id), else a fresh id is minted.
|
|
54
|
+
*/
|
|
55
|
+
ensure(name: string, extra: Omit<TBody, "name">, preferredId?: string): Promise<Entity<TBody>>;
|
|
56
|
+
/** Replace the body of `id` with `next(current)`: ONE put. */
|
|
57
|
+
update(id: string, next: (current: TBody) => TBody): Promise<Entity<TBody>>;
|
|
58
|
+
/** Remove the record. Returns whether it existed. The caller clears references. */
|
|
59
|
+
delete(id: string): Promise<boolean>;
|
|
60
|
+
}
|