@camstack/server 1.2.927 → 1.2.929
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +11 -14
- package/system/dist/addon-id-CVg1_r5E.mjs +39 -0
- package/system/dist/addon-id-Di0lNJ89.js +50 -0
- package/system/dist/addon-pages.cap-Df9FQwN1.js +49 -0
- package/system/dist/addon-pages.cap-DksUlE8j.mjs +44 -0
- package/system/dist/addon-settings.cap-3-TIIMq_.mjs +592 -0
- package/system/dist/addon-settings.cap-DAiE0Nb0.js +651 -0
- package/system/dist/addon-widgets.cap-C4jxflbF.js +200 -0
- package/system/dist/addon-widgets.cap-D9m48X78.mjs +183 -0
- package/system/dist/base-addon-DD5dIfcZ.js +4624 -0
- package/system/dist/base-addon-Md14i7pe.mjs +4505 -0
- package/system/dist/base-device-2sL1DMm1.js +1103 -0
- package/system/dist/base-device-IuM1AwXZ.mjs +1098 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +8 -6
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +3 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +8 -6
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +3 -1
- package/system/dist/builtins/alerts/alerts.addon.js +113 -56
- package/system/dist/builtins/alerts/alerts.addon.mjs +58 -1
- package/system/dist/builtins/autotrack/index.js +21 -17
- package/system/dist/builtins/autotrack/index.mjs +5 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +14 -11
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -2
- package/system/dist/builtins/calendars/calendars.addon.js +8 -6
- package/system/dist/builtins/calendars/calendars.addon.mjs +3 -1
- package/system/dist/builtins/camera-grid/index.js +615 -58
- package/system/dist/builtins/camera-grid/index.mjs +558 -1
- package/system/dist/builtins/composer/composer.addon.js +788 -209
- package/system/dist/builtins/composer/composer.addon.mjs +583 -4
- package/system/dist/builtins/console-logging/index.js +4 -3
- package/system/dist/builtins/console-logging/index.mjs +2 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +7887 -381
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +7511 -5
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +731 -21
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +711 -1
- package/system/dist/builtins/device-history/device-history.addon.js +110 -31
- package/system/dist/builtins/device-history/device-history.addon.mjs +81 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +12806 -227
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +12583 -5
- package/system/dist/builtins/hub-forwarder/index.js +4 -3
- package/system/dist/builtins/hub-forwarder/index.mjs +2 -1
- package/system/dist/builtins/keychain/index.js +31 -28
- package/system/dist/builtins/keychain/index.mjs +7 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +15 -12
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +4 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +140 -39
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +103 -3
- package/system/dist/builtins/local-network/local-network.addon.js +43 -39
- package/system/dist/builtins/local-network/local-network.addon.mjs +7 -3
- package/system/dist/builtins/loki-logging/index.js +23 -17
- package/system/dist/builtins/loki-logging/index.mjs +7 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +156 -15
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +142 -1
- package/system/dist/builtins/platform-probe/index.js +25 -23
- package/system/dist/builtins/platform-probe/index.mjs +4 -2
- package/system/dist/builtins/record-entries/index.js +9 -7
- package/system/dist/builtins/record-entries/index.mjs +3 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +4 -4
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +97 -44
- package/system/dist/builtins/snapshot/index.mjs +54 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +5 -4
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +2 -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 +87 -61
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +29 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +81 -72
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +10 -1
- package/system/dist/builtins/system-config/system-config.addon.js +17 -14
- package/system/dist/builtins/system-config/system-config.addon.mjs +6 -3
- package/system/dist/builtins/winston-logging/index.js +7 -5
- package/system/dist/builtins/winston-logging/index.mjs +3 -1
- package/system/dist/calendars.cap-CaFlShS9.js +155 -0
- package/system/dist/calendars.cap-_C4eD4fi.mjs +138 -0
- package/system/dist/camstack-error-DJ-TUAi1.js +23 -0
- package/system/dist/camstack-error-viZYfcj9.mjs +18 -0
- package/system/dist/cap-call-context-Bd76CbOW.js +95 -0
- package/system/dist/cap-call-context-DNwdgGSQ.mjs +78 -0
- package/system/dist/capability-definition-C2rJdVeX.mjs +177 -0
- package/system/dist/capability-definition-HCmTem8c.js +242 -0
- package/system/dist/{capture-engine-BcuwOSXv.js → capture-engine-DZ0LIUqA.js} +5 -4
- package/system/dist/{capture-engine-Bz7eXFjT.mjs → capture-engine-DiwbjoWp.mjs} +2 -1
- package/system/dist/command-origin-claim-Cief660O.js +35 -0
- package/system/dist/command-origin-claim-D1Wy7Qld.mjs +24 -0
- package/system/dist/composition-sources-Caqv7O7z.mjs +391 -0
- package/system/dist/composition-sources-CgnHjm8Q.js +408 -0
- package/system/dist/{constants-D2etJ02O.js → constants-Ba3FTIHl.js} +1 -1
- package/system/dist/constants-C860Y6U4.js +26 -0
- package/system/dist/{constants-BcUTQd1M.mjs → constants-DB4piTD5.mjs} +1 -1
- package/system/dist/constants-DCLpoF4L.mjs +21 -0
- package/system/dist/coral-accelerators-7o8hqvcN.js +564 -0
- package/system/dist/coral-accelerators-BKcXP59c.mjs +521 -0
- package/system/dist/core-blocks.cap-C6iKAZ-x.mjs +17986 -0
- package/system/dist/core-blocks.cap-LEMqVwxO.js +18705 -0
- package/system/dist/custom-actions-BFUSalC9.mjs +25 -0
- package/system/dist/custom-actions-D92NRi2c.js +36 -0
- package/system/dist/database-snapshot.cap-DF38e-0P.js +162 -0
- package/system/dist/database-snapshot.cap-dhrc9xnY.mjs +133 -0
- package/system/dist/declared-device-BWphj9WE.js +303 -0
- package/system/dist/declared-device-CKERA1Hi.mjs +286 -0
- package/system/dist/{device-ca-ExMN3xW3.mjs → device-ca-BLM6fccc.mjs} +2 -1
- package/system/dist/{device-ca-CU8zh9Pi.js → device-ca-C5kJE6mL.js} +7 -6
- package/system/dist/device-certificate-Cddm4Idn.mjs +91 -0
- package/system/dist/device-certificate-CguVACQO.js +162 -0
- package/system/dist/device-identifiers-BQg9EQi1.js +600 -0
- package/system/dist/device-identifiers-iSuQCKmK.mjs +529 -0
- package/system/dist/device-kind-BJ2pfsjw.mjs +78 -0
- package/system/dist/device-kind-CsSiv_YF.js +101 -0
- package/system/dist/device-manager.cap-2abwVLCM.js +2874 -0
- package/system/dist/device-manager.cap-CFZSPfUh.mjs +2749 -0
- package/system/dist/device-provider.cap-3Uvk6f5-.mjs +331 -0
- package/system/dist/device-provider.cap-D7TV2kVH.js +366 -0
- package/system/dist/{device-row-store-CeW_GWh9.mjs → device-row-store-YF3jtmkk.mjs} +4 -1
- package/system/dist/{device-row-store-BMIR-n3m.js → device-row-store-doTfMOqn.js} +12 -9
- package/system/dist/device-transitions.cap-B5w5PYU_.js +860 -0
- package/system/dist/device-transitions.cap-DojcwEuX.mjs +819 -0
- package/system/dist/device-type-CbQsnFdC.js +477 -0
- package/system/dist/device-type-DgEvK3ch.mjs +454 -0
- package/system/dist/entry-kind-D9MuVJCK.mjs +44 -0
- package/system/dist/entry-kind-cq90c--V.js +55 -0
- package/system/dist/error.cap-CSM_SRfR.mjs +3423 -0
- package/system/dist/error.cap-DBhgPeWK.js +3848 -0
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/history-catalog-BKRarIL_.js +831 -0
- package/system/dist/history-catalog-BwTeQ4Mr.mjs +802 -0
- package/system/dist/{hub-identity-Csxx2Q8k.js → hub-identity-BMdR3Mw9.js} +2 -2
- package/system/dist/{hub-identity-BBXzP6Ve.mjs → hub-identity-DjMN9Ac2.mjs} +1 -1
- package/system/dist/{hub-mdns-ciao-By5577HM.js → hub-mdns-ciao--0v1TKME.js} +5 -5
- package/system/dist/{hub-mdns-ciao-DG17NbGU.mjs → hub-mdns-ciao-DBrtHOcc.mjs} +2 -2
- package/system/dist/index.js +763 -151
- package/system/dist/index.mjs +624 -12
- package/system/dist/integration-instances.cap-Cl9O-k4h.mjs +538 -0
- package/system/dist/integration-instances.cap-dJIxg2_s.js +549 -0
- package/system/dist/keychain-admin.cap-Db_oFX4H.js +425 -0
- package/system/dist/keychain-admin.cap-GtM7gVGG.mjs +396 -0
- package/system/dist/l10n-Bu6aUvSY.mjs +10 -0
- package/system/dist/l10n-CGMvp7NF.js +15 -0
- package/system/dist/labels-DX5S8deC.js +81 -0
- package/system/dist/labels-DsBcU7md.mjs +64 -0
- package/system/dist/{legacy-integration-rows-door-CVwOo5aq.js → legacy-integration-rows-door-B1nzxxr5.js} +2 -2
- package/system/dist/{legacy-integration-rows-door-D9tQOUzh.mjs → legacy-integration-rows-door-nTvo_6jQ.mjs} +1 -1
- package/system/dist/log-destination.cap-CxZzAVaR.mjs +143 -0
- package/system/dist/log-destination.cap-DELPJkZ0.js +148 -0
- package/system/dist/low-power-sleep.cap-7lfVU41N.js +103 -0
- package/system/dist/low-power-sleep.cap-tGPmaZ_V.mjs +92 -0
- package/system/dist/mask-shape-Ci8Co9w0.mjs +57 -0
- package/system/dist/mask-shape-CmPA2fst.js +92 -0
- package/system/dist/metrics-provider.cap-BNmcHDkQ.mjs +405 -0
- package/system/dist/metrics-provider.cap-BcmQUt6l.js +410 -0
- package/system/dist/migration-BMjgkyG2.js +380 -0
- package/system/dist/migration-DRJAtdy7.mjs +321 -0
- package/system/dist/network-access.cap-B5TWLDCC.js +1099 -0
- package/system/dist/network-access.cap-BJnGbE6n.mjs +1004 -0
- package/system/dist/notification-rules.cap-B__YBgnG.js +3422 -0
- package/system/dist/notification-rules.cap-D9ArZlwx.mjs +3357 -0
- package/system/dist/ops-log-CB4pIdqi.mjs +64 -0
- package/system/dist/ops-log-pxt9176Z.js +81 -0
- package/system/dist/pinned-binary-BOhOSNff.js +28 -0
- package/system/dist/pinned-binary-CrIRAi4G.mjs +23 -0
- package/system/dist/platform-probe.cap-1WrMhWHx.js +250 -0
- package/system/dist/platform-probe.cap-BFeqFLtQ.mjs +233 -0
- package/system/dist/prefix-walk-B4b2-9aK.mjs +790 -0
- package/system/dist/prefix-walk-DC0ljmbB.js +843 -0
- package/system/dist/ptz-autotrack.cap-BW7w0zHD.js +229 -0
- package/system/dist/ptz-autotrack.cap-DT2GypXw.mjs +224 -0
- package/system/dist/quantity-D3g5SxsZ.mjs +114 -0
- package/system/dist/quantity-lY1KiTSZ.js +143 -0
- package/system/dist/raw-secret-migration-DxuBFtvi.js +50 -0
- package/system/dist/raw-secret-migration-iv88mLoc.mjs +39 -0
- package/system/dist/record-entries.cap-sMUhTvTU.mjs +75 -0
- package/system/dist/record-entries.cap-ti1C046R.js +80 -0
- package/system/dist/record-kind-DoBfYHCs.js +203 -0
- package/system/dist/record-kind-ub6NXqfh.mjs +162 -0
- package/system/dist/recording-archive.cap-7OrIn9e5.mjs +1299 -0
- package/system/dist/recording-archive.cap-D7bo-QSM.js +1328 -0
- package/system/dist/records.cap-ClcWV64i.js +329 -0
- package/system/dist/records.cap-CwLT2ByG.mjs +294 -0
- package/system/dist/relocate-CdVQAk-w.js +804 -0
- package/system/dist/relocate-CoZZTui1.mjs +661 -0
- package/system/dist/rename-composition-block-7WIICIDq.mjs +33525 -0
- package/system/dist/rename-composition-block-CcWLwVhG.js +34692 -0
- package/system/dist/{restore-archive-kwtBd00M.mjs → restore-archive-CjAyKpgX.mjs} +3 -1
- package/system/dist/{restore-archive-CIFvqOze.js → restore-archive-CkTkv3Ss.js} +6 -4
- package/system/dist/scoped-settings-CylSSq_8.js +955 -0
- package/system/dist/scoped-settings-DVWUIP7Z.mjs +650 -0
- package/system/dist/server-name-BIhLuHvX.mjs +35 -0
- package/system/dist/server-name-OALNvpqC.js +52 -0
- package/system/dist/settings-store.cap-Ci4F2zul.mjs +569 -0
- package/system/dist/settings-store.cap-wlJhCspr.js +640 -0
- package/system/dist/snapshot.cap-3suPdBHV.js +250 -0
- package/system/dist/snapshot.cap-Bs8Oyaqh.mjs +245 -0
- package/system/dist/source-info-DGB7SdB_.mjs +190 -0
- package/system/dist/source-info-DtWf4k2j.js +225 -0
- package/system/dist/storage-admin.cap-BSv1NjKJ.mjs +883 -0
- package/system/dist/storage-admin.cap-he0OqvVM.js +906 -0
- package/system/dist/storage-location-CBT8GCD6.mjs +163 -0
- package/system/dist/storage-location-CTweDMZf.js +198 -0
- package/system/dist/storage-location-mode-B21UVRRX.mjs +167 -0
- package/system/dist/storage-location-mode-CS4sMzo-.js +232 -0
- package/system/dist/storage-migration.cap-CyyATY_p.js +330 -0
- package/system/dist/storage-migration.cap-D7QqGobp.mjs +313 -0
- package/system/dist/storage-occupancy.cap-2rmnS58Z.js +622 -0
- package/system/dist/storage-occupancy.cap-CqBztTl9.mjs +611 -0
- package/system/dist/storage-provider.cap-Bw0CfxVc.js +213 -0
- package/system/dist/storage-provider.cap-CMeck2w4.mjs +202 -0
- package/system/dist/stream-catalog.cap-Bp7SkgIf.mjs +6560 -0
- package/system/dist/stream-catalog.cap-D3uwePiA.js +6763 -0
- package/system/dist/streaming-shared-B8cXatuU.mjs +431 -0
- package/system/dist/streaming-shared-DQwFZOSi.js +526 -0
- package/system/dist/system-reasons-Be_k1W8g.js +25 -0
- package/system/dist/system-reasons-CYj4qwyS.mjs +20 -0
- package/system/dist/tag-BxLazvVb.js +2138 -0
- package/system/dist/tag-uZBAq6ox.mjs +2073 -0
- package/system/dist/user-management.cap-B9QDu8NE.js +825 -0
- package/system/dist/user-management.cap-DBIi77sB.mjs +766 -0
- package/system/dist/vector-store.cap-DnyfrYDn.js +330 -0
- package/system/dist/vector-store.cap-h2GHWQ1t.mjs +319 -0
- package/system/dist/{wal-maintenance-CTrCPzds.mjs → wal-maintenance-BG01rOn9.mjs} +0 -0
- package/system/dist/{wal-maintenance-dq7T3quB.js → wal-maintenance-DyrebYKF.js} +0 -0
- package/system/dist/zod-secret-DS7mj1bk.js +78 -0
- package/system/dist/zod-secret-zY4nM61M.mjs +73 -0
- package/system/package.json +1 -1
- package/system/dist/composition-sources-BI614LJx.mjs +0 -141
- package/system/dist/composition-sources-v_kkb8A9.js +0 -152
- package/system/dist/coral-accelerators-BSVsBVzt.js +0 -250
- package/system/dist/coral-accelerators-DBlgWB8k.mjs +0 -231
- package/system/dist/dist-BCHMSqzc.mjs +0 -143467
- package/system/dist/dist-BZfvhfS1.js +0 -146970
- package/system/dist/prefix-walk-DAOBSyH1.mjs +0 -88
- package/system/dist/prefix-walk-Dv6MLZlM.js +0 -99
- package/system/dist/rename-composition-block-C9HuBrKS.js +0 -112
- package/system/dist/rename-composition-block-DtaYmYAR.mjs +0 -101
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region ../types/dist/esm/capabilities/custom-actions.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Identity — preserves literal types for downstream inference.
|
|
4
|
+
*
|
|
5
|
+
* The constraint is `Record<string, unknown>` (not `CustomActionsSpec`) so
|
|
6
|
+
* TypeScript does not widen each entry's literal `kind`/`auth` fields to
|
|
7
|
+
* the broader unions declared on `CustomActionSpec`'s default generics.
|
|
8
|
+
* Shape validity is enforced separately by the `customAction(...)` helper
|
|
9
|
+
* whose return type is already a `CustomActionSpec<...>`.
|
|
10
|
+
*/
|
|
11
|
+
function defineCustomActions(spec) {
|
|
12
|
+
return spec;
|
|
13
|
+
}
|
|
14
|
+
function customAction(input, output, options) {
|
|
15
|
+
return {
|
|
16
|
+
input,
|
|
17
|
+
output,
|
|
18
|
+
kind: options?.kind ?? "query",
|
|
19
|
+
auth: options?.auth ?? "protected",
|
|
20
|
+
scope: options?.scope ?? { kind: "system" },
|
|
21
|
+
...options?.caller ? { caller: "required" } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineCustomActions as n, customAction as t };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region ../types/dist/esm/capabilities/custom-actions.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Identity — preserves literal types for downstream inference.
|
|
4
|
+
*
|
|
5
|
+
* The constraint is `Record<string, unknown>` (not `CustomActionsSpec`) so
|
|
6
|
+
* TypeScript does not widen each entry's literal `kind`/`auth` fields to
|
|
7
|
+
* the broader unions declared on `CustomActionSpec`'s default generics.
|
|
8
|
+
* Shape validity is enforced separately by the `customAction(...)` helper
|
|
9
|
+
* whose return type is already a `CustomActionSpec<...>`.
|
|
10
|
+
*/
|
|
11
|
+
function defineCustomActions(spec) {
|
|
12
|
+
return spec;
|
|
13
|
+
}
|
|
14
|
+
function customAction(input, output, options) {
|
|
15
|
+
return {
|
|
16
|
+
input,
|
|
17
|
+
output,
|
|
18
|
+
kind: options?.kind ?? "query",
|
|
19
|
+
auth: options?.auth ?? "protected",
|
|
20
|
+
scope: options?.scope ?? { kind: "system" },
|
|
21
|
+
...options?.caller ? { caller: "required" } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
Object.defineProperty(exports, "customAction", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function() {
|
|
28
|
+
return customAction;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "defineCustomActions", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return defineCustomActions;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const require_capability_definition = require("./capability-definition-HCmTem8c.js");
|
|
2
|
+
const require_system_reasons = require("./system-reasons-Be_k1W8g.js");
|
|
3
|
+
const require_settings_store_cap = require("./settings-store.cap-wlJhCspr.js");
|
|
4
|
+
let zod = require("zod");
|
|
5
|
+
//#region ../types/dist/esm/capabilities/database-snapshot.cap.mjs
|
|
6
|
+
/**
|
|
7
|
+
* The suffix of a verified snapshot, written next to the live database it
|
|
8
|
+
* copies: `<db>.backup-snapshot`. A restore promotes it back over `<db>`
|
|
9
|
+
* (`server/backend/src/sqlite-restore.ts` spells the same string — the
|
|
10
|
+
* launcher stays free of `@camstack/*` runtime imports — and a spec pins the
|
|
11
|
+
* two together).
|
|
12
|
+
*/
|
|
13
|
+
var DATABASE_SNAPSHOT_SUFFIX = ".backup-snapshot";
|
|
14
|
+
/**
|
|
15
|
+
* The suffix of a copy still being written or verified. A file under this name
|
|
16
|
+
* is never archived and never promoted: only a copy that passed every check is
|
|
17
|
+
* renamed to {@link DATABASE_SNAPSHOT_SUFFIX}.
|
|
18
|
+
*/
|
|
19
|
+
var DATABASE_SNAPSHOT_PARTIAL_SUFFIX = ".backup-snapshot-partial";
|
|
20
|
+
/**
|
|
21
|
+
* How long one snapshot may take end to end: the pinned copy of the whole
|
|
22
|
+
* database plus `PRAGMA integrity_check` over the copy, on the hub's slowest
|
|
23
|
+
* disk. ~800 MB at a pessimistic 10 MB/s is under 3 minutes; the bound is
|
|
24
|
+
* generous because a timeout fails the whole backup run.
|
|
25
|
+
*/
|
|
26
|
+
var DATABASE_SNAPSHOT_TIMEOUT_MS = 30 * 6e4;
|
|
27
|
+
/**
|
|
28
|
+
* The databases an owner snapshots — declared by the OWNER, so a caller never
|
|
29
|
+
* guesses which file is live from what sits beside it (a cleanly closed
|
|
30
|
+
* database has no sidecars and is just as owned). Paths are absolute on the
|
|
31
|
+
* owner's host.
|
|
32
|
+
*/
|
|
33
|
+
var DatabaseSnapshotTargetsSchema = /* @__PURE__ */ zod.z.object({ databases: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.object({
|
|
34
|
+
/** Which owned file this is — the handle `writeSnapshot` takes. */
|
|
35
|
+
databaseId: require_settings_store_cap.DataStoreDatabaseSchema,
|
|
36
|
+
livePath: /* @__PURE__ */ zod.z.string()
|
|
37
|
+
})) });
|
|
38
|
+
/** One b-tree table of the snapshot and the rows it holds. */
|
|
39
|
+
var DatabaseSnapshotTableSchema = /* @__PURE__ */ zod.z.object({
|
|
40
|
+
name: /* @__PURE__ */ zod.z.string(),
|
|
41
|
+
rows: /* @__PURE__ */ zod.z.number().int().nonnegative()
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* What the owner wrote. Every path is ABSOLUTE on the owner's host — the
|
|
45
|
+
* caller pins the call to its own node, so it can read the file; a caller
|
|
46
|
+
* that finds the path outside its own data root refuses it rather than
|
|
47
|
+
* archiving something it cannot place.
|
|
48
|
+
*/
|
|
49
|
+
var DatabaseSnapshotResultSchema = /* @__PURE__ */ zod.z.object({
|
|
50
|
+
/** The live database the snapshot copies. Never to be copied as a file. */
|
|
51
|
+
livePath: /* @__PURE__ */ zod.z.string(),
|
|
52
|
+
/** The verified copy: `<livePath>` + {@link DATABASE_SNAPSHOT_SUFFIX}. */
|
|
53
|
+
snapshotPath: /* @__PURE__ */ zod.z.string(),
|
|
54
|
+
sizeBytes: /* @__PURE__ */ zod.z.number().int().nonnegative(),
|
|
55
|
+
pageCount: /* @__PURE__ */ zod.z.number().int().nonnegative(),
|
|
56
|
+
pageSize: /* @__PURE__ */ zod.z.number().int().positive(),
|
|
57
|
+
/**
|
|
58
|
+
* Every b-tree table with its row count. Read inside the SAME read
|
|
59
|
+
* transaction the copy was taken from, and found EQUAL on the copy — so
|
|
60
|
+
* this is the content of the snapshot, not an estimate of the source.
|
|
61
|
+
*/
|
|
62
|
+
tables: /* @__PURE__ */ zod.z.array(DatabaseSnapshotTableSchema),
|
|
63
|
+
/** Wall time of the pinned copy (row counts included). */
|
|
64
|
+
copyMs: /* @__PURE__ */ zod.z.number().nonnegative(),
|
|
65
|
+
/** Wall time of the checks on the copy (`integrity_check`, row counts). */
|
|
66
|
+
verifyMs: /* @__PURE__ */ zod.z.number().nonnegative(),
|
|
67
|
+
/** When the pinned read transaction began (ms epoch) — the snapshot's instant. */
|
|
68
|
+
takenAt: /* @__PURE__ */ zod.z.number()
|
|
69
|
+
});
|
|
70
|
+
/** A snapshot the owner wrote, with the file it belongs to. */
|
|
71
|
+
var DatabaseSnapshotWrittenSchema = /* @__PURE__ */ DatabaseSnapshotResultSchema.extend({ databaseId: require_settings_store_cap.DataStoreDatabaseSchema });
|
|
72
|
+
/** Which database `writeSnapshot` copies. Required: an unstated ask is not guessed. */
|
|
73
|
+
var DatabaseSnapshotRequestSchema = /* @__PURE__ */ zod.z.object({ databaseId: require_settings_store_cap.DataStoreDatabaseSchema });
|
|
74
|
+
/**
|
|
75
|
+
* A snapshot as an ARCHIVE records it (`ArchiveManifest.sqliteSnapshots`):
|
|
76
|
+
* the same facts, with both paths relative to the archive root (the node's
|
|
77
|
+
* data dir), because an archive outlives the host that made it.
|
|
78
|
+
*/
|
|
79
|
+
var ArchiveSqliteSnapshotSchema = /* @__PURE__ */ DatabaseSnapshotResultSchema.extend({
|
|
80
|
+
/** Archive-relative path of the live database the archive does NOT carry. */
|
|
81
|
+
livePath: /* @__PURE__ */ zod.z.string(),
|
|
82
|
+
/** Archive-relative path of the verified copy it carries in its place. */
|
|
83
|
+
snapshotPath: /* @__PURE__ */ zod.z.string(),
|
|
84
|
+
/** Absent on an archive made before several files were owned: that was `settings`. */
|
|
85
|
+
databaseId: /* @__PURE__ */ require_settings_store_cap.DataStoreDatabaseSchema.optional()
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* database-snapshot — the OWNER of a live SQLite database writes a consistent,
|
|
89
|
+
* verified copy of it (D693).
|
|
90
|
+
*
|
|
91
|
+
* A live database cannot be copied as files: three files written by a live
|
|
92
|
+
* process cannot be read at one instant from outside it, and a tar of the
|
|
93
|
+
* `.db` / `-wal` / `-shm` trio was measured torn in 6/6 archives (D679). Nor may
|
|
94
|
+
* another process open it (D679 rule 2). So the process that owns the
|
|
95
|
+
* connection writes the copy — through its own connection, on a thread,
|
|
96
|
+
* pinned to one read transaction — and checks it before handing it out.
|
|
97
|
+
*
|
|
98
|
+
* Hub-only and internal: `sqlite-settings` is the registrant, and its consumer
|
|
99
|
+
* is `backup-orchestrator`, which calls it pinned to its own node so the path
|
|
100
|
+
* it gets back is on its own host. `auth: 'admin'` explicitly — `internal`
|
|
101
|
+
* does not gate the mount (see `data-store-provider`).
|
|
102
|
+
*/
|
|
103
|
+
var databaseSnapshotCapability = {
|
|
104
|
+
name: "database-snapshot",
|
|
105
|
+
scope: "system",
|
|
106
|
+
mode: "singleton",
|
|
107
|
+
internal: true,
|
|
108
|
+
methods: {
|
|
109
|
+
/**
|
|
110
|
+
* EVERY database file this owner has open, with its id. Answered from
|
|
111
|
+
* memory — no file is touched — so a backup can ask it before deciding
|
|
112
|
+
* anything. A file created at runtime is listed from the moment it opens,
|
|
113
|
+
* so no backup can leave it out (D693).
|
|
114
|
+
*/
|
|
115
|
+
listDatabases: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({}), DatabaseSnapshotTargetsSchema, { auth: "admin" }),
|
|
116
|
+
/**
|
|
117
|
+
* Write `<db>.backup-snapshot` for ONE database and return what it holds.
|
|
118
|
+
* Throws — and leaves no file under the final name — when the copy fails
|
|
119
|
+
* `integrity_check` or its row counts differ from the pinned source's, or
|
|
120
|
+
* when the database is not open. A second call for the SAME database while
|
|
121
|
+
* one is running joins it; different databases run one after the other
|
|
122
|
+
* (the disk reserve check is per copy).
|
|
123
|
+
*/
|
|
124
|
+
writeSnapshot: /* @__PURE__ */ require_capability_definition.method(DatabaseSnapshotRequestSchema, DatabaseSnapshotWrittenSchema, {
|
|
125
|
+
kind: "mutation",
|
|
126
|
+
auth: "admin",
|
|
127
|
+
timeoutMs: DATABASE_SNAPSHOT_TIMEOUT_MS
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
vocabulary: { notOperatorFacing: require_system_reasons.NOT_A_DEVICE.INTERNAL }
|
|
131
|
+
};
|
|
132
|
+
//#endregion
|
|
133
|
+
Object.defineProperty(exports, "ArchiveSqliteSnapshotSchema", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function() {
|
|
136
|
+
return ArchiveSqliteSnapshotSchema;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, "DATABASE_SNAPSHOT_PARTIAL_SUFFIX", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function() {
|
|
142
|
+
return DATABASE_SNAPSHOT_PARTIAL_SUFFIX;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
Object.defineProperty(exports, "DATABASE_SNAPSHOT_SUFFIX", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
get: function() {
|
|
148
|
+
return DATABASE_SNAPSHOT_SUFFIX;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(exports, "DATABASE_SNAPSHOT_TIMEOUT_MS", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get: function() {
|
|
154
|
+
return DATABASE_SNAPSHOT_TIMEOUT_MS;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(exports, "databaseSnapshotCapability", {
|
|
158
|
+
enumerable: true,
|
|
159
|
+
get: function() {
|
|
160
|
+
return databaseSnapshotCapability;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { c as method } from "./capability-definition-C2rJdVeX.mjs";
|
|
2
|
+
import { t as NOT_A_DEVICE } from "./system-reasons-CYj4qwyS.mjs";
|
|
3
|
+
import { a as DataStoreDatabaseSchema } from "./settings-store.cap-Ci4F2zul.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region ../types/dist/esm/capabilities/database-snapshot.cap.mjs
|
|
6
|
+
/**
|
|
7
|
+
* The suffix of a verified snapshot, written next to the live database it
|
|
8
|
+
* copies: `<db>.backup-snapshot`. A restore promotes it back over `<db>`
|
|
9
|
+
* (`server/backend/src/sqlite-restore.ts` spells the same string — the
|
|
10
|
+
* launcher stays free of `@camstack/*` runtime imports — and a spec pins the
|
|
11
|
+
* two together).
|
|
12
|
+
*/
|
|
13
|
+
var DATABASE_SNAPSHOT_SUFFIX = ".backup-snapshot";
|
|
14
|
+
/**
|
|
15
|
+
* The suffix of a copy still being written or verified. A file under this name
|
|
16
|
+
* is never archived and never promoted: only a copy that passed every check is
|
|
17
|
+
* renamed to {@link DATABASE_SNAPSHOT_SUFFIX}.
|
|
18
|
+
*/
|
|
19
|
+
var DATABASE_SNAPSHOT_PARTIAL_SUFFIX = ".backup-snapshot-partial";
|
|
20
|
+
/**
|
|
21
|
+
* How long one snapshot may take end to end: the pinned copy of the whole
|
|
22
|
+
* database plus `PRAGMA integrity_check` over the copy, on the hub's slowest
|
|
23
|
+
* disk. ~800 MB at a pessimistic 10 MB/s is under 3 minutes; the bound is
|
|
24
|
+
* generous because a timeout fails the whole backup run.
|
|
25
|
+
*/
|
|
26
|
+
var DATABASE_SNAPSHOT_TIMEOUT_MS = 30 * 6e4;
|
|
27
|
+
/**
|
|
28
|
+
* The databases an owner snapshots — declared by the OWNER, so a caller never
|
|
29
|
+
* guesses which file is live from what sits beside it (a cleanly closed
|
|
30
|
+
* database has no sidecars and is just as owned). Paths are absolute on the
|
|
31
|
+
* owner's host.
|
|
32
|
+
*/
|
|
33
|
+
var DatabaseSnapshotTargetsSchema = /* @__PURE__ */ z.object({ databases: /* @__PURE__ */ z.array(/* @__PURE__ */ z.object({
|
|
34
|
+
/** Which owned file this is — the handle `writeSnapshot` takes. */
|
|
35
|
+
databaseId: DataStoreDatabaseSchema,
|
|
36
|
+
livePath: /* @__PURE__ */ z.string()
|
|
37
|
+
})) });
|
|
38
|
+
/** One b-tree table of the snapshot and the rows it holds. */
|
|
39
|
+
var DatabaseSnapshotTableSchema = /* @__PURE__ */ z.object({
|
|
40
|
+
name: /* @__PURE__ */ z.string(),
|
|
41
|
+
rows: /* @__PURE__ */ z.number().int().nonnegative()
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* What the owner wrote. Every path is ABSOLUTE on the owner's host — the
|
|
45
|
+
* caller pins the call to its own node, so it can read the file; a caller
|
|
46
|
+
* that finds the path outside its own data root refuses it rather than
|
|
47
|
+
* archiving something it cannot place.
|
|
48
|
+
*/
|
|
49
|
+
var DatabaseSnapshotResultSchema = /* @__PURE__ */ z.object({
|
|
50
|
+
/** The live database the snapshot copies. Never to be copied as a file. */
|
|
51
|
+
livePath: /* @__PURE__ */ z.string(),
|
|
52
|
+
/** The verified copy: `<livePath>` + {@link DATABASE_SNAPSHOT_SUFFIX}. */
|
|
53
|
+
snapshotPath: /* @__PURE__ */ z.string(),
|
|
54
|
+
sizeBytes: /* @__PURE__ */ z.number().int().nonnegative(),
|
|
55
|
+
pageCount: /* @__PURE__ */ z.number().int().nonnegative(),
|
|
56
|
+
pageSize: /* @__PURE__ */ z.number().int().positive(),
|
|
57
|
+
/**
|
|
58
|
+
* Every b-tree table with its row count. Read inside the SAME read
|
|
59
|
+
* transaction the copy was taken from, and found EQUAL on the copy — so
|
|
60
|
+
* this is the content of the snapshot, not an estimate of the source.
|
|
61
|
+
*/
|
|
62
|
+
tables: /* @__PURE__ */ z.array(DatabaseSnapshotTableSchema),
|
|
63
|
+
/** Wall time of the pinned copy (row counts included). */
|
|
64
|
+
copyMs: /* @__PURE__ */ z.number().nonnegative(),
|
|
65
|
+
/** Wall time of the checks on the copy (`integrity_check`, row counts). */
|
|
66
|
+
verifyMs: /* @__PURE__ */ z.number().nonnegative(),
|
|
67
|
+
/** When the pinned read transaction began (ms epoch) — the snapshot's instant. */
|
|
68
|
+
takenAt: /* @__PURE__ */ z.number()
|
|
69
|
+
});
|
|
70
|
+
/** A snapshot the owner wrote, with the file it belongs to. */
|
|
71
|
+
var DatabaseSnapshotWrittenSchema = /* @__PURE__ */ DatabaseSnapshotResultSchema.extend({ databaseId: DataStoreDatabaseSchema });
|
|
72
|
+
/** Which database `writeSnapshot` copies. Required: an unstated ask is not guessed. */
|
|
73
|
+
var DatabaseSnapshotRequestSchema = /* @__PURE__ */ z.object({ databaseId: DataStoreDatabaseSchema });
|
|
74
|
+
/**
|
|
75
|
+
* A snapshot as an ARCHIVE records it (`ArchiveManifest.sqliteSnapshots`):
|
|
76
|
+
* the same facts, with both paths relative to the archive root (the node's
|
|
77
|
+
* data dir), because an archive outlives the host that made it.
|
|
78
|
+
*/
|
|
79
|
+
var ArchiveSqliteSnapshotSchema = /* @__PURE__ */ DatabaseSnapshotResultSchema.extend({
|
|
80
|
+
/** Archive-relative path of the live database the archive does NOT carry. */
|
|
81
|
+
livePath: /* @__PURE__ */ z.string(),
|
|
82
|
+
/** Archive-relative path of the verified copy it carries in its place. */
|
|
83
|
+
snapshotPath: /* @__PURE__ */ z.string(),
|
|
84
|
+
/** Absent on an archive made before several files were owned: that was `settings`. */
|
|
85
|
+
databaseId: /* @__PURE__ */ DataStoreDatabaseSchema.optional()
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* database-snapshot — the OWNER of a live SQLite database writes a consistent,
|
|
89
|
+
* verified copy of it (D693).
|
|
90
|
+
*
|
|
91
|
+
* A live database cannot be copied as files: three files written by a live
|
|
92
|
+
* process cannot be read at one instant from outside it, and a tar of the
|
|
93
|
+
* `.db` / `-wal` / `-shm` trio was measured torn in 6/6 archives (D679). Nor may
|
|
94
|
+
* another process open it (D679 rule 2). So the process that owns the
|
|
95
|
+
* connection writes the copy — through its own connection, on a thread,
|
|
96
|
+
* pinned to one read transaction — and checks it before handing it out.
|
|
97
|
+
*
|
|
98
|
+
* Hub-only and internal: `sqlite-settings` is the registrant, and its consumer
|
|
99
|
+
* is `backup-orchestrator`, which calls it pinned to its own node so the path
|
|
100
|
+
* it gets back is on its own host. `auth: 'admin'` explicitly — `internal`
|
|
101
|
+
* does not gate the mount (see `data-store-provider`).
|
|
102
|
+
*/
|
|
103
|
+
var databaseSnapshotCapability = {
|
|
104
|
+
name: "database-snapshot",
|
|
105
|
+
scope: "system",
|
|
106
|
+
mode: "singleton",
|
|
107
|
+
internal: true,
|
|
108
|
+
methods: {
|
|
109
|
+
/**
|
|
110
|
+
* EVERY database file this owner has open, with its id. Answered from
|
|
111
|
+
* memory — no file is touched — so a backup can ask it before deciding
|
|
112
|
+
* anything. A file created at runtime is listed from the moment it opens,
|
|
113
|
+
* so no backup can leave it out (D693).
|
|
114
|
+
*/
|
|
115
|
+
listDatabases: /* @__PURE__ */ method(/* @__PURE__ */ z.object({}), DatabaseSnapshotTargetsSchema, { auth: "admin" }),
|
|
116
|
+
/**
|
|
117
|
+
* Write `<db>.backup-snapshot` for ONE database and return what it holds.
|
|
118
|
+
* Throws — and leaves no file under the final name — when the copy fails
|
|
119
|
+
* `integrity_check` or its row counts differ from the pinned source's, or
|
|
120
|
+
* when the database is not open. A second call for the SAME database while
|
|
121
|
+
* one is running joins it; different databases run one after the other
|
|
122
|
+
* (the disk reserve check is per copy).
|
|
123
|
+
*/
|
|
124
|
+
writeSnapshot: /* @__PURE__ */ method(DatabaseSnapshotRequestSchema, DatabaseSnapshotWrittenSchema, {
|
|
125
|
+
kind: "mutation",
|
|
126
|
+
auth: "admin",
|
|
127
|
+
timeoutMs: DATABASE_SNAPSHOT_TIMEOUT_MS
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
vocabulary: { notOperatorFacing: NOT_A_DEVICE.INTERNAL }
|
|
131
|
+
};
|
|
132
|
+
//#endregion
|
|
133
|
+
export { databaseSnapshotCapability as a, DATABASE_SNAPSHOT_TIMEOUT_MS as i, DATABASE_SNAPSHOT_PARTIAL_SUFFIX as n, DATABASE_SNAPSHOT_SUFFIX as r, ArchiveSqliteSnapshotSchema as t };
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
const require_scoped_settings = require("./scoped-settings-CylSSq_8.js");
|
|
2
|
+
//#region ../types/dist/esm/device/declared-device.mjs
|
|
3
|
+
/** Marker written to a declared integration's `info`. */
|
|
4
|
+
var DECLARED_INTEGRATION_FIXED_KEY = "fixed";
|
|
5
|
+
/**
|
|
6
|
+
* Give a declared integration its instance record, ONCE. The record is read first and left
|
|
7
|
+
* exactly as it is when it exists (an operator's rename, a field the addon later adds): a seed
|
|
8
|
+
* never overwrites. A read that fails throws and writes nothing (D49) — the next pass retries.
|
|
9
|
+
* True when the record was written by this call.
|
|
10
|
+
*/
|
|
11
|
+
async function seedInstanceOnce(instances, seed) {
|
|
12
|
+
const existing = await instances.getInstance({ id: seed.id });
|
|
13
|
+
if (existing !== null && existing !== void 0) return false;
|
|
14
|
+
await instances.createInstance({
|
|
15
|
+
id: seed.id,
|
|
16
|
+
name: seed.name
|
|
17
|
+
});
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Strip the `<node>/<addon>` suffix a forked child carries.
|
|
22
|
+
*
|
|
23
|
+
* Comparing `ctx.kernel.localNodeId` raw skipped EVERY node — including the one
|
|
24
|
+
* that was supposed to act — because on the hub it reads `hub/<addon>`.
|
|
25
|
+
*/
|
|
26
|
+
function declarationOwnerNodeId(localNodeId) {
|
|
27
|
+
const raw = localNodeId ?? "hub";
|
|
28
|
+
if (!raw.includes("/")) return raw;
|
|
29
|
+
return raw.split("/")[0] ?? "hub";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The one way an addon owns a device it declares.
|
|
33
|
+
*
|
|
34
|
+
* Construct once with the addon's ports, then call {@link reconcile} on boot and
|
|
35
|
+
* on every convergence tick. There is no second get-or-create helper — a guard
|
|
36
|
+
* in `scripts/` enforces that.
|
|
37
|
+
*/
|
|
38
|
+
var DeclaredDevices = class {
|
|
39
|
+
ports;
|
|
40
|
+
constructor(ports) {
|
|
41
|
+
const addonId = ports.addonId;
|
|
42
|
+
if (typeof addonId !== "string" || addonId.length === 0) throw new Error(`DeclaredDevices: addonId must be the declaring addon's id, got ${JSON.stringify(addonId)}. On an addon context it is \`ctx.id\` — there is no \`ctx.addonId\`.`);
|
|
43
|
+
this.ports = ports;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Converge the declared set. Idempotent, and safe to call repeatedly.
|
|
47
|
+
*
|
|
48
|
+
* Throws only what the ports throw on the FIRST index read; every other
|
|
49
|
+
* failure is per-device and logged, so one bad declaration never takes the
|
|
50
|
+
* others down.
|
|
51
|
+
*/
|
|
52
|
+
async reconcile(spec) {
|
|
53
|
+
if ((spec.placement ?? "hub") === "hub") {
|
|
54
|
+
const nodeId = declarationOwnerNodeId(this.ports.localNodeId);
|
|
55
|
+
if (nodeId !== "hub") {
|
|
56
|
+
this.ports.logger.info("declared devices are hub-owned — skipping on this node", { meta: {
|
|
57
|
+
nodeId,
|
|
58
|
+
rawNodeId: this.ports.localNodeId ?? null
|
|
59
|
+
} });
|
|
60
|
+
return {
|
|
61
|
+
integrationId: null,
|
|
62
|
+
devices: [],
|
|
63
|
+
removed: [],
|
|
64
|
+
owned: false
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
let integrationId;
|
|
69
|
+
if (spec.integrationId !== void 0) integrationId = spec.integrationId;
|
|
70
|
+
else {
|
|
71
|
+
const own = await this.ensureIntegration(spec.integrationName);
|
|
72
|
+
integrationId = own.id;
|
|
73
|
+
await this.seedInstance(own);
|
|
74
|
+
}
|
|
75
|
+
const index = await this.readIndex();
|
|
76
|
+
const live = await this.readLiveByStableId();
|
|
77
|
+
const outcomes = [];
|
|
78
|
+
for (const declaration of spec.devices) {
|
|
79
|
+
const outcome = await this.applyDeclaration(declaration, integrationId, index, live);
|
|
80
|
+
if (outcome !== null) outcomes.push(outcome);
|
|
81
|
+
}
|
|
82
|
+
const removed = await this.sweepWithdrawn(spec.devices, integrationId, index);
|
|
83
|
+
return {
|
|
84
|
+
integrationId,
|
|
85
|
+
devices: outcomes,
|
|
86
|
+
removed,
|
|
87
|
+
owned: true
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get-or-create the FIXED integration, and RE-ASSERT the flag every pass.
|
|
92
|
+
*
|
|
93
|
+
* The re-assertion is the fix for the defect the hand-rolled version shipped
|
|
94
|
+
* with: writing `info.fixed` only on the create path left every pre-existing
|
|
95
|
+
* install without it, and the kernel kept offering to delete an integration
|
|
96
|
+
* the addon owns.
|
|
97
|
+
*/
|
|
98
|
+
async ensureIntegration(integrationName) {
|
|
99
|
+
const existing = await this.ports.getIntegration(this.ports.addonId);
|
|
100
|
+
if (existing === null) {
|
|
101
|
+
const created = await this.ports.createIntegration({
|
|
102
|
+
addonId: this.ports.addonId,
|
|
103
|
+
name: integrationName,
|
|
104
|
+
info: { [DECLARED_INTEGRATION_FIXED_KEY]: true }
|
|
105
|
+
});
|
|
106
|
+
this.ports.logger.info("declared a fixed integration", { meta: {
|
|
107
|
+
integrationId: created.id,
|
|
108
|
+
name: integrationName
|
|
109
|
+
} });
|
|
110
|
+
return {
|
|
111
|
+
id: created.id,
|
|
112
|
+
name: integrationName
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (existing.info?.["fixed"] !== true) {
|
|
116
|
+
await this.ports.updateIntegration({
|
|
117
|
+
id: existing.id,
|
|
118
|
+
info: { [DECLARED_INTEGRATION_FIXED_KEY]: true }
|
|
119
|
+
});
|
|
120
|
+
this.ports.logger.info("re-asserted `fixed` on a declared integration", { meta: { integrationId: existing.id } });
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
id: existing.id,
|
|
124
|
+
name: existing.name ?? integrationName
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** Seed the instance record of an integration this declarer owns; best-effort, retried next pass. */
|
|
128
|
+
async seedInstance(integration) {
|
|
129
|
+
const { seedInstance } = this.ports;
|
|
130
|
+
if (seedInstance === void 0) return;
|
|
131
|
+
try {
|
|
132
|
+
await seedInstance({
|
|
133
|
+
id: integration.id,
|
|
134
|
+
name: integration.name
|
|
135
|
+
});
|
|
136
|
+
} catch (err) {
|
|
137
|
+
this.ports.logger.warn("could not seed the instance record of a declared integration", {
|
|
138
|
+
tags: { integrationId: integration.id },
|
|
139
|
+
meta: { error: require_scoped_settings.errMsg(err) }
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async readIndex() {
|
|
144
|
+
const rows = await this.ports.listOwnDevices();
|
|
145
|
+
return new Map(rows.map((row) => [row.stableId, row]));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Devices this kernel already has CONSTRUCTED, by stableId.
|
|
149
|
+
*
|
|
150
|
+
* Distinct from {@link readIndex}, and the distinction is the bug: the index
|
|
151
|
+
* is persisted rows, this is live objects. A row without an object must be
|
|
152
|
+
* adopted; an object must be left exactly as it is.
|
|
153
|
+
*
|
|
154
|
+
* Failure is non-fatal and deliberately so — an empty map degrades to the
|
|
155
|
+
* previous behaviour (attempt the adopt) rather than skipping a device that
|
|
156
|
+
* genuinely needs bringing up.
|
|
157
|
+
*/
|
|
158
|
+
async readLiveByStableId() {
|
|
159
|
+
try {
|
|
160
|
+
const devices = await this.ports.devices.getAll();
|
|
161
|
+
return new Map(devices.map((device) => [device.stableId, device]));
|
|
162
|
+
} catch (err) {
|
|
163
|
+
this.ports.logger.warn("could not read live devices — falling back to adopt-by-row", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
164
|
+
return /* @__PURE__ */ new Map();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* One declaration: adopt what exists, create what does not.
|
|
169
|
+
*
|
|
170
|
+
* The create branch is the destructive one — it seeds `initialMeta`, and
|
|
171
|
+
* `initialMeta.name` lands as an unconditional `setName`. A transiently empty
|
|
172
|
+
* index therefore looks exactly like a first boot and would silently re-stamp
|
|
173
|
+
* the declared name over the operator's rename. D49: that branch needs a
|
|
174
|
+
* second read to agree.
|
|
175
|
+
*/
|
|
176
|
+
async applyDeclaration(declaration, integrationId, index, live) {
|
|
177
|
+
try {
|
|
178
|
+
const alreadyLive = live.get(declaration.stableId);
|
|
179
|
+
if (alreadyLive !== void 0) return {
|
|
180
|
+
stableId: declaration.stableId,
|
|
181
|
+
deviceId: alreadyLive.id,
|
|
182
|
+
device: alreadyLive,
|
|
183
|
+
created: false
|
|
184
|
+
};
|
|
185
|
+
let existing = index.get(declaration.stableId);
|
|
186
|
+
if (existing === void 0) {
|
|
187
|
+
existing = (await this.readIndex()).get(declaration.stableId);
|
|
188
|
+
if (existing !== void 0) this.ports.logger.warn("device index disagreed with itself — adopting instead of re-creating", {
|
|
189
|
+
tags: { deviceId: existing.id },
|
|
190
|
+
meta: {
|
|
191
|
+
stableId: declaration.stableId,
|
|
192
|
+
addonId: this.ports.addonId
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (existing !== void 0) {
|
|
197
|
+
const device = await this.ports.devices.create(declaration.stableId, declaration.DeviceClass, {}, null, void 0);
|
|
198
|
+
this.ports.logger.info("declared device adopted", {
|
|
199
|
+
tags: { deviceId: device.id },
|
|
200
|
+
meta: {
|
|
201
|
+
stableId: declaration.stableId,
|
|
202
|
+
integrationId
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
stableId: declaration.stableId,
|
|
207
|
+
deviceId: device.id,
|
|
208
|
+
device,
|
|
209
|
+
created: false
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const device = await this.ports.devices.create(declaration.stableId, declaration.DeviceClass, declaration.config ?? {}, null, {
|
|
213
|
+
type: declaration.type,
|
|
214
|
+
name: declaration.name,
|
|
215
|
+
integrationId,
|
|
216
|
+
...declaration.role === void 0 ? {} : { role: declaration.role }
|
|
217
|
+
});
|
|
218
|
+
this.ports.logger.info("declared device created", {
|
|
219
|
+
tags: { deviceId: device.id },
|
|
220
|
+
meta: {
|
|
221
|
+
stableId: declaration.stableId,
|
|
222
|
+
integrationId
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
stableId: declaration.stableId,
|
|
227
|
+
deviceId: device.id,
|
|
228
|
+
device,
|
|
229
|
+
created: true
|
|
230
|
+
};
|
|
231
|
+
} catch (err) {
|
|
232
|
+
this.ports.logger.warn("a declared device could not be brought up", { meta: {
|
|
233
|
+
stableId: declaration.stableId,
|
|
234
|
+
error: err instanceof Error ? err.message : String(err)
|
|
235
|
+
} });
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Remove rows under the addon's FIXED integration whose declaration is gone.
|
|
241
|
+
*
|
|
242
|
+
* Bounded to that integration: a declared integration has no operator
|
|
243
|
+
* add-flow, so every row under it got there by declaration. Devices this
|
|
244
|
+
* addon owns OUTSIDE it (a provider's adopted devices) are never candidates.
|
|
245
|
+
*
|
|
246
|
+
* Bounded in count, and every deletion is logged with its `deviceId` — a
|
|
247
|
+
* withdrawal that removes an operator-visible row silently is the failure
|
|
248
|
+
* mode, not the removal itself.
|
|
249
|
+
*/
|
|
250
|
+
async sweepWithdrawn(declarations, integrationId, index) {
|
|
251
|
+
const declared = new Set(declarations.map((d) => d.stableId));
|
|
252
|
+
const candidates = [...index.values()].filter((row) => row.integrationId === integrationId && !declared.has(row.stableId));
|
|
253
|
+
if (candidates.length === 0) return [];
|
|
254
|
+
if (candidates.length > 32) {
|
|
255
|
+
this.ports.logger.warn("withdrawal sweep exceeded its bound — removing nothing", { meta: {
|
|
256
|
+
integrationId,
|
|
257
|
+
candidates: candidates.length,
|
|
258
|
+
bound: 32
|
|
259
|
+
} });
|
|
260
|
+
return [];
|
|
261
|
+
}
|
|
262
|
+
const removed = [];
|
|
263
|
+
for (const row of candidates) try {
|
|
264
|
+
await this.ports.devices.remove(row.id);
|
|
265
|
+
removed.push(row.id);
|
|
266
|
+
this.ports.logger.info("declared device removed — its declaration was withdrawn", {
|
|
267
|
+
tags: { deviceId: row.id },
|
|
268
|
+
meta: {
|
|
269
|
+
stableId: row.stableId,
|
|
270
|
+
integrationId
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
} catch (err) {
|
|
274
|
+
this.ports.logger.warn("a withdrawn declared device could not be removed", {
|
|
275
|
+
tags: { deviceId: row.id },
|
|
276
|
+
meta: {
|
|
277
|
+
stableId: row.stableId,
|
|
278
|
+
error: err instanceof Error ? err.message : String(err)
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return removed;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
//#endregion
|
|
286
|
+
Object.defineProperty(exports, "DeclaredDevices", {
|
|
287
|
+
enumerable: true,
|
|
288
|
+
get: function() {
|
|
289
|
+
return DeclaredDevices;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
Object.defineProperty(exports, "declarationOwnerNodeId", {
|
|
293
|
+
enumerable: true,
|
|
294
|
+
get: function() {
|
|
295
|
+
return declarationOwnerNodeId;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
Object.defineProperty(exports, "seedInstanceOnce", {
|
|
299
|
+
enumerable: true,
|
|
300
|
+
get: function() {
|
|
301
|
+
return seedInstanceOnce;
|
|
302
|
+
}
|
|
303
|
+
});
|