@camstack/server 1.2.784 → 1.2.786
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 +13 -0
- package/dist/api/core/cap-providers.js +44 -7
- package/dist/api/trpc/generated-cap-routers.js +0 -9
- package/package.json +40 -15
- package/system/dist/addon-runner.js +11 -2
- package/system/dist/addon-runner.mjs +12 -3
- package/system/dist/{agent-https-Ds3-zbz-.mjs → agent-https-D779EYj3.mjs} +1 -1
- package/system/dist/{agent-https-BobAhSU6.js → agent-https-snFEmSqQ.js} +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composed-device.d.ts +16 -0
- package/system/dist/builtins/composer/composer.addon.js +68 -18
- package/system/dist/builtins/composer/composer.addon.mjs +68 -18
- package/system/dist/builtins/composer/composition-evaluation.d.ts +2 -2
- 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-service.d.ts +16 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +235 -37
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +235 -37
- package/system/dist/builtins/core-blocks/migrations/fountain-drink-drop.d.ts +21 -0
- package/system/dist/builtins/core-blocks/migrations/index.d.ts +1 -0
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +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/sqlite-settings.addon.js +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-7_Barr9F.mjs → capture-engine-DkTEWrRe.mjs} +1 -1
- package/system/dist/{capture-engine-cNrHuwWH.js → capture-engine-NZ11ORZS.js} +1 -1
- package/system/dist/{composition-sources-7wEQtB6b.js → composition-sources-B6GYTy_7.js} +1 -1
- package/system/dist/{composition-sources-QUbTSbQL.mjs → composition-sources-B9-lkIvO.mjs} +1 -1
- package/system/dist/{constants-BmX7aeHq.mjs → constants--9ui1LK0.mjs} +1 -1
- package/system/dist/{constants-_Zq5aGIs.js → constants-DR8hdi45.js} +1 -1
- package/system/dist/{device-ca-DqNfUZx4.mjs → device-ca-D-7tAHJ_.mjs} +1 -1
- package/system/dist/{device-ca-D9nNDHW_.js → device-ca-sIFmKkGM.js} +1 -1
- package/system/dist/{dist-W0Eyg7Fm.mjs → dist-D-iGSnX_.mjs} +1109 -843
- package/system/dist/{dist-CA672buZ.js → dist-h3Yla8gE.js} +1162 -842
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-DYD3STlf.js → hub-mdns-ciao-C5DkUEZF.js} +2 -2
- package/system/dist/{hub-mdns-ciao-VOfs7CqC.mjs → hub-mdns-ciao-DuEfM0fI.mjs} +2 -2
- package/system/dist/index.js +19 -10
- package/system/dist/index.mjs +20 -11
- package/system/dist/kernel/moleculer/migration-api-facade.d.ts +2 -0
- package/system/dist/kernel/transport/local-child-client.d.ts +9 -0
- package/system/dist/{legacy-integration-rows-door-CF_0_-U9.mjs → legacy-integration-rows-door-BTdhD-Yp.mjs} +1 -1
- package/system/dist/{legacy-integration-rows-door-BzVepX_e.js → legacy-integration-rows-door-DTDD5wwC.js} +1 -1
- package/system/dist/{restore-archive-BCXQaw89.js → restore-archive-CkAD_-E9.js} +1 -1
- package/system/dist/{restore-archive-B2l00XlI.mjs → restore-archive-DQWz5Wp-.mjs} +1 -1
- package/system/dist/{wal-maintenance-Z4MNv6Vn.js → wal-maintenance-CB-O-GPP.js} +0 -0
- package/system/dist/{wal-maintenance-bvjbNKbx.mjs → wal-maintenance-DouX1XsY.mjs} +0 -0
- package/system/package.json +1 -1
|
@@ -1171,7 +1171,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
|
|
|
1171
1171
|
return DeviceRole;
|
|
1172
1172
|
}({});
|
|
1173
1173
|
//#endregion
|
|
1174
|
-
//#region ../types/dist/sleep-
|
|
1174
|
+
//#region ../types/dist/sleep-CmjWurK5.mjs
|
|
1175
1175
|
/**
|
|
1176
1176
|
* The audio chunk plane's byte format, and the ONE expansion from a coded
|
|
1177
1177
|
* window to float samples (D455).
|
|
@@ -1919,147 +1919,170 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
|
|
|
1919
1919
|
blockOwner
|
|
1920
1920
|
};
|
|
1921
1921
|
}
|
|
1922
|
-
/**
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
const set = async (next) => {
|
|
1941
|
-
const validated = deps.schema.parse(next);
|
|
1942
|
-
await deps.write({ [deps.key]: validated });
|
|
1943
|
-
};
|
|
1944
|
-
const update = async (fn) => {
|
|
1945
|
-
await set(fn(await get()));
|
|
1946
|
-
};
|
|
1922
|
+
/** The record calls the one-switch migration makes, over the migration API. */
|
|
1923
|
+
function switchRecordsOverMigrationApi(api) {
|
|
1924
|
+
return { kind: (definition) => {
|
|
1925
|
+
const handle = api.records.kind(definition);
|
|
1926
|
+
return {
|
|
1927
|
+
get: (id) => handle.get({ id }),
|
|
1928
|
+
put: (input, opts) => handle.put({
|
|
1929
|
+
...input,
|
|
1930
|
+
...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
|
|
1931
|
+
}),
|
|
1932
|
+
patch: (id, partial) => handle.patch({
|
|
1933
|
+
id,
|
|
1934
|
+
partial
|
|
1935
|
+
})
|
|
1936
|
+
};
|
|
1937
|
+
} };
|
|
1938
|
+
}
|
|
1939
|
+
function integrationRowsApiOver(api) {
|
|
1947
1940
|
return {
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1941
|
+
list: async () => (await api.integrations.list({})).integrations,
|
|
1942
|
+
readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
|
|
1943
|
+
clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
|
|
1951
1944
|
};
|
|
1952
1945
|
}
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
1964
|
-
*
|
|
1965
|
-
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
1966
|
-
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
1967
|
-
* schema and routes reads/writes through these helpers.
|
|
1968
|
-
*
|
|
1969
|
-
* ## No bare-key fallback — deliberate
|
|
1970
|
-
*
|
|
1971
|
-
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
1972
|
-
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
1973
|
-
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
1974
|
-
* the store is invisible to every node, hub included, so one node's
|
|
1975
|
-
* selection can never leak onto another. (This generalizes the
|
|
1976
|
-
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
1977
|
-
* arbitrary set of per-node field keys.)
|
|
1978
|
-
*
|
|
1979
|
-
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
1980
|
-
* LEAF module: import it via its deep path, never from the root barrel.
|
|
1981
|
-
*/
|
|
1982
|
-
/**
|
|
1983
|
-
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
1984
|
-
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
1985
|
-
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
1986
|
-
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
1987
|
-
*/
|
|
1988
|
-
function normalizeNodeId(raw) {
|
|
1989
|
-
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
1990
|
-
const slashIdx = raw.indexOf("/");
|
|
1991
|
-
if (slashIdx < 0) return raw;
|
|
1992
|
-
const bare = raw.slice(0, slashIdx);
|
|
1993
|
-
return bare === "" ? "hub" : bare;
|
|
1994
|
-
}
|
|
1995
|
-
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
1996
|
-
function nodeScopedKey(base, nodeId) {
|
|
1997
|
-
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
1998
|
-
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Read a node's value for a per-node field from the raw shared store:
|
|
2001
|
-
* the node-scoped key when present, otherwise `undefined`.
|
|
2002
|
-
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
2003
|
-
* schema `default` win on `undefined`.
|
|
2004
|
-
*/
|
|
2005
|
-
function readNodeValue(store, base, nodeId) {
|
|
2006
|
-
return store[nodeScopedKey(base, nodeId)];
|
|
2007
|
-
}
|
|
2008
|
-
/**
|
|
2009
|
-
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
2010
|
-
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
2011
|
-
* the write path so a save for one node never clobbers another node's value
|
|
2012
|
-
* (and the bare key is never written). Returns a new object — the input
|
|
2013
|
-
* patch is not mutated.
|
|
2014
|
-
*/
|
|
2015
|
-
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
2016
|
-
const out = {};
|
|
2017
|
-
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
2018
|
-
return out;
|
|
2019
|
-
}
|
|
2020
|
-
/**
|
|
2021
|
-
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
2022
|
-
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
2023
|
-
* values:
|
|
2024
|
-
*
|
|
2025
|
-
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
2026
|
-
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
2027
|
-
* legacy key must never hydrate any node — no bare fallback).
|
|
2028
|
-
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
2029
|
-
* each bare perNode key; when the node has no scoped key the bare key is
|
|
2030
|
-
* left ABSENT so the field's schema `default` wins.
|
|
2031
|
-
*
|
|
2032
|
-
* Returns a new object — the input store is not mutated.
|
|
2033
|
-
*/
|
|
2034
|
-
function projectStore(store, perNodeKeys, nodeId) {
|
|
2035
|
-
const out = {};
|
|
2036
|
-
for (const [key, value] of Object.entries(store)) {
|
|
2037
|
-
if (key.includes("@")) continue;
|
|
2038
|
-
if (perNodeKeys.has(key)) continue;
|
|
2039
|
-
out[key] = value;
|
|
1946
|
+
var PREFIX = "records/";
|
|
1947
|
+
/** The base of every records failure. `detail` is the human part of the message. */
|
|
1948
|
+
var RecordsError = class extends Error {
|
|
1949
|
+
code;
|
|
1950
|
+
detail;
|
|
1951
|
+
constructor(code, detail) {
|
|
1952
|
+
super(`${PREFIX}${code}: ${detail}`);
|
|
1953
|
+
this.name = "RecordsError";
|
|
1954
|
+
this.code = code;
|
|
1955
|
+
this.detail = detail;
|
|
2040
1956
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
1957
|
+
};
|
|
1958
|
+
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
1959
|
+
var RevConflictError = class extends RecordsError {
|
|
1960
|
+
constructor(detail) {
|
|
1961
|
+
super("rev-conflict", detail);
|
|
1962
|
+
this.name = "RevConflictError";
|
|
2044
1963
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
1964
|
+
};
|
|
1965
|
+
/** `data` exceeds the kind's `maxDataBytes`. Bytes are never record fields (D613). */
|
|
1966
|
+
var RecordTooLargeError = class extends RecordsError {
|
|
1967
|
+
constructor(detail) {
|
|
1968
|
+
super("too-large", detail);
|
|
1969
|
+
this.name = "RecordTooLargeError";
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
/** A filter, order or aggregate names a field no declared index serves. */
|
|
1973
|
+
var UnindexedFilterError = class extends RecordsError {
|
|
1974
|
+
constructor(detail) {
|
|
1975
|
+
super("unindexed-filter", detail);
|
|
1976
|
+
this.name = "UnindexedFilterError";
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
/** A bulk delete with no predicate at all. */
|
|
1980
|
+
var FilterRequiredError = class extends RecordsError {
|
|
1981
|
+
constructor(detail) {
|
|
1982
|
+
super("filter-required", detail);
|
|
1983
|
+
this.name = "FilterRequiredError";
|
|
1984
|
+
}
|
|
1985
|
+
};
|
|
1986
|
+
/** The caller declared no such kind (another addon's kind is indistinguishable from none). */
|
|
1987
|
+
var UnknownRecordKindError = class extends RecordsError {
|
|
1988
|
+
constructor(detail) {
|
|
1989
|
+
super("unknown-kind", detail);
|
|
1990
|
+
this.name = "UnknownRecordKindError";
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1993
|
+
var RecordNotFoundError = class extends RecordsError {
|
|
1994
|
+
constructor(detail) {
|
|
1995
|
+
super("not-found", detail);
|
|
1996
|
+
this.name = "RecordNotFoundError";
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
/** A unique index refused the write. */
|
|
2000
|
+
var RecordUniqueViolationError = class extends RecordsError {
|
|
2001
|
+
constructor(detail) {
|
|
2002
|
+
super("unique-violation", detail);
|
|
2003
|
+
this.name = "RecordUniqueViolationError";
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
/** A secret field held a plain string where only a keychain marker may be stored. */
|
|
2007
|
+
var PlaintextSecretError = class extends RecordsError {
|
|
2008
|
+
constructor(detail) {
|
|
2009
|
+
super("plaintext-secret", detail);
|
|
2010
|
+
this.name = "PlaintextSecretError";
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
/** A marker whose ref is not the row's own (the D878 rule). */
|
|
2014
|
+
var ForeignSecretMarkerError = class extends RecordsError {
|
|
2015
|
+
constructor(detail) {
|
|
2016
|
+
super("foreign-marker", detail);
|
|
2017
|
+
this.name = "ForeignSecretMarkerError";
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
2021
|
+
var RecordSecretUnavailableError = class extends RecordsError {
|
|
2022
|
+
constructor(detail) {
|
|
2023
|
+
super("secret-unavailable", detail);
|
|
2024
|
+
this.name = "RecordSecretUnavailableError";
|
|
2025
|
+
}
|
|
2026
|
+
};
|
|
2027
|
+
var InvalidRecordError = class extends RecordsError {
|
|
2028
|
+
constructor(detail) {
|
|
2029
|
+
super("invalid-record", detail);
|
|
2030
|
+
this.name = "InvalidRecordError";
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
2034
|
+
var DeclarationRefusedError = class extends RecordsError {
|
|
2035
|
+
constructor(detail) {
|
|
2036
|
+
super("declaration-refused", detail);
|
|
2037
|
+
this.name = "DeclarationRefusedError";
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
var NoCallerError = class extends RecordsError {
|
|
2041
|
+
constructor(detail) {
|
|
2042
|
+
super("no-caller", detail);
|
|
2043
|
+
this.name = "NoCallerError";
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
var BatchTooLargeError = class extends RecordsError {
|
|
2047
|
+
constructor(detail) {
|
|
2048
|
+
super("batch-too-large", detail);
|
|
2049
|
+
this.name = "BatchTooLargeError";
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2053
2052
|
/**
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2056
|
-
* (
|
|
2053
|
+
* A `transact` the engine refuses before touching a row: an op on a kind the
|
|
2054
|
+
* caller did not declare in ONE file and ONE `transactFamily`. The detail names
|
|
2055
|
+
* which rule (`cross-file`, `cross-family`, `no-family`); it is never a silent split.
|
|
2057
2056
|
*/
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2057
|
+
var TransactRefusedError = class extends RecordsError {
|
|
2058
|
+
constructor(detail) {
|
|
2059
|
+
super("transact-refused", detail);
|
|
2060
|
+
this.name = "TransactRefusedError";
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
function linkTargetOf(meta) {
|
|
2064
|
+
if (typeof meta !== "object" || meta === null) return void 0;
|
|
2065
|
+
const link = Reflect.get(meta, "link");
|
|
2066
|
+
const parsed = LinkTargetSchema.safeParse(link);
|
|
2067
|
+
return parsed.success ? parsed.data : void 0;
|
|
2068
|
+
}
|
|
2069
|
+
var LinkTargetSchema = zod.z.object({
|
|
2070
|
+
cap: zod.z.string().min(1),
|
|
2071
|
+
kind: zod.z.string().min(1).optional()
|
|
2072
|
+
});
|
|
2073
|
+
/** The links a kind declares, read from the meta of its body fields. */
|
|
2074
|
+
function linksOfKind(kind) {
|
|
2075
|
+
const schema = kind.schema;
|
|
2076
|
+
if (!(schema instanceof zod.z.ZodObject)) return [];
|
|
2077
|
+
const links = [];
|
|
2078
|
+
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
2079
|
+
const to = linkTargetOf(zod.z.globalRegistry.get(fieldSchema));
|
|
2080
|
+
if (to !== void 0) links.push({
|
|
2081
|
+
field,
|
|
2082
|
+
to
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
return links;
|
|
2063
2086
|
}
|
|
2064
2087
|
/**
|
|
2065
2088
|
* The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
|
|
@@ -2195,6 +2218,668 @@ function parseSecretRef(ref) {
|
|
|
2195
2218
|
fieldPath
|
|
2196
2219
|
};
|
|
2197
2220
|
}
|
|
2221
|
+
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
2222
|
+
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
2223
|
+
var RECORD_DATABASES = ["settings", "events"];
|
|
2224
|
+
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
2225
|
+
var RECORD_CLASSES = [
|
|
2226
|
+
"config",
|
|
2227
|
+
"ledger",
|
|
2228
|
+
"audit",
|
|
2229
|
+
"mirror",
|
|
2230
|
+
"ephemeral"
|
|
2231
|
+
];
|
|
2232
|
+
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
2233
|
+
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
2234
|
+
var RECORD_BATCH_MAX = 1e3;
|
|
2235
|
+
var RECORD_BATCH_MAX_BYTES = 4 * 1024 * 1024;
|
|
2236
|
+
var RECORD_QUERY_MAX = 1e3;
|
|
2237
|
+
/** Rows one DELETE statement removes before the serving thread yields. */
|
|
2238
|
+
var RECORD_DELETE_BATCH = 5e3;
|
|
2239
|
+
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
2240
|
+
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
2241
|
+
/** The engine's TTL sweep cadence. */
|
|
2242
|
+
var RECORD_SWEEP_INTERVAL_MS = 10 * 6e4;
|
|
2243
|
+
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
2244
|
+
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
2245
|
+
/**
|
|
2246
|
+
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
2247
|
+
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
2248
|
+
* (`auth.accessToken`, `headers[].value`).
|
|
2249
|
+
*
|
|
2250
|
+
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
2251
|
+
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
2252
|
+
* key releases exactly that key's secret.
|
|
2253
|
+
*
|
|
2254
|
+
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
2255
|
+
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
2256
|
+
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
2257
|
+
* leaf names its element: `headers[X-Api].value`.
|
|
2258
|
+
*
|
|
2259
|
+
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
2260
|
+
*/
|
|
2261
|
+
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
2262
|
+
function parseSecretPath(path) {
|
|
2263
|
+
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
2264
|
+
return path.split(".").map((raw) => {
|
|
2265
|
+
const each = raw.endsWith("[]");
|
|
2266
|
+
const map = raw.endsWith("{}");
|
|
2267
|
+
const key = each || map ? raw.slice(0, -2) : raw;
|
|
2268
|
+
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
2269
|
+
return {
|
|
2270
|
+
key,
|
|
2271
|
+
each,
|
|
2272
|
+
map
|
|
2273
|
+
};
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
2277
|
+
function secretArrayPrefixes(path) {
|
|
2278
|
+
const segments = parseSecretPath(path);
|
|
2279
|
+
const prefixes = [];
|
|
2280
|
+
const walked = [];
|
|
2281
|
+
for (const segment of segments) {
|
|
2282
|
+
walked.push(segment.key);
|
|
2283
|
+
if (segment.each) prefixes.push(walked.join("."));
|
|
2284
|
+
}
|
|
2285
|
+
return prefixes;
|
|
2286
|
+
}
|
|
2287
|
+
function isRecord$6(value) {
|
|
2288
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2289
|
+
}
|
|
2290
|
+
function elementId(element, idKey, declared, prefix) {
|
|
2291
|
+
const id = isRecord$6(element) ? element[idKey] : void 0;
|
|
2292
|
+
if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
|
|
2293
|
+
return id;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
2297
|
+
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
2298
|
+
* result is a new body, `data` is untouched.
|
|
2299
|
+
*/
|
|
2300
|
+
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
2301
|
+
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
2302
|
+
if (!isRecord$6(node)) return node;
|
|
2303
|
+
const segment = segments[index];
|
|
2304
|
+
if (segment === void 0) return node;
|
|
2305
|
+
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
2306
|
+
const child = node[segment.key];
|
|
2307
|
+
const keys = [...walkedKeys, segment.key];
|
|
2308
|
+
const last = index === segments.length - 1;
|
|
2309
|
+
if (segment.each) {
|
|
2310
|
+
if (!Array.isArray(child)) return node;
|
|
2311
|
+
const prefix = keys.join(".");
|
|
2312
|
+
const idKey = arrayKeys[prefix];
|
|
2313
|
+
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
2314
|
+
const mapped = child.map((element) => {
|
|
2315
|
+
const id = elementId(element, idKey, declared, prefix);
|
|
2316
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
2317
|
+
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
2318
|
+
});
|
|
2319
|
+
return {
|
|
2320
|
+
...node,
|
|
2321
|
+
[segment.key]: mapped
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
if (segment.map) {
|
|
2325
|
+
if (!isRecord$6(child)) return node;
|
|
2326
|
+
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
2327
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
2328
|
+
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
2329
|
+
return [mapKey, visit({
|
|
2330
|
+
declared,
|
|
2331
|
+
concrete,
|
|
2332
|
+
value
|
|
2333
|
+
})];
|
|
2334
|
+
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
2335
|
+
return {
|
|
2336
|
+
...node,
|
|
2337
|
+
[segment.key]: Object.fromEntries(kept)
|
|
2338
|
+
};
|
|
2339
|
+
}
|
|
2340
|
+
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
2341
|
+
if (last) {
|
|
2342
|
+
const replacement = visit({
|
|
2343
|
+
declared,
|
|
2344
|
+
concrete,
|
|
2345
|
+
value: child
|
|
2346
|
+
});
|
|
2347
|
+
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
2348
|
+
return {
|
|
2349
|
+
...node,
|
|
2350
|
+
[segment.key]: replacement
|
|
2351
|
+
};
|
|
2352
|
+
}
|
|
2353
|
+
return {
|
|
2354
|
+
...node,
|
|
2355
|
+
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
2359
|
+
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
2360
|
+
let current = data;
|
|
2361
|
+
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
2362
|
+
return current;
|
|
2363
|
+
}
|
|
2364
|
+
/** Every present secret leaf, read-only. */
|
|
2365
|
+
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
2366
|
+
const found = [];
|
|
2367
|
+
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
2368
|
+
found.push(leaf);
|
|
2369
|
+
return leaf.value;
|
|
2370
|
+
});
|
|
2371
|
+
return found;
|
|
2372
|
+
}
|
|
2373
|
+
/**
|
|
2374
|
+
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
2375
|
+
* record's refs never collide with the refs a legacy collection of the same name
|
|
2376
|
+
* already holds during an adoption.
|
|
2377
|
+
*/
|
|
2378
|
+
function recordSecretCollection(kind) {
|
|
2379
|
+
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
2380
|
+
}
|
|
2381
|
+
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
2382
|
+
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
2383
|
+
return buildSecretRef({
|
|
2384
|
+
owner,
|
|
2385
|
+
scope: {
|
|
2386
|
+
kind: "row",
|
|
2387
|
+
collection: recordSecretCollection(kind),
|
|
2388
|
+
rowId
|
|
2389
|
+
},
|
|
2390
|
+
fieldPath: concretePath
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
2395
|
+
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
2396
|
+
* token. The form hands it to the secret field, which reveals the value by ref
|
|
2397
|
+
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
2398
|
+
* stored secret (the records door reads a view as KEEP).
|
|
2399
|
+
*
|
|
2400
|
+
* ONE implementation for the entries service and for every addon that serves
|
|
2401
|
+
* its own instances (`RecordIntegrationInstances`).
|
|
2402
|
+
*/
|
|
2403
|
+
function isRecord$5(value) {
|
|
2404
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2405
|
+
}
|
|
2406
|
+
function secretViewsOf(owner, kind, id, decl, data) {
|
|
2407
|
+
if (decl.secretPaths.length === 0) return data;
|
|
2408
|
+
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
2409
|
+
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
2410
|
+
return {
|
|
2411
|
+
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
2412
|
+
v: 1,
|
|
2413
|
+
set: true
|
|
2414
|
+
};
|
|
2415
|
+
});
|
|
2416
|
+
return isRecord$5(shown) ? shown : data;
|
|
2417
|
+
}
|
|
2418
|
+
/** The most instances one addon lists (an integrations page, not a table). */
|
|
2419
|
+
var INSTANCES_LIST_MAX = 1e3;
|
|
2420
|
+
/**
|
|
2421
|
+
* The ONE reader of an instance's switch (D996): an absent field means on, so a row written
|
|
2422
|
+
* before the field existed needs no migration. Every consumer of an instance body asks this.
|
|
2423
|
+
*/
|
|
2424
|
+
function isInstanceEnabled(body) {
|
|
2425
|
+
return body.enabled !== false;
|
|
2426
|
+
}
|
|
2427
|
+
/** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
|
|
2428
|
+
var SWITCH_KEY = "enabled";
|
|
2429
|
+
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
2430
|
+
function topLevelSecretKeys(paths) {
|
|
2431
|
+
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
2432
|
+
}
|
|
2433
|
+
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
2434
|
+
function secretMapKeys(paths) {
|
|
2435
|
+
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
2439
|
+
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
2440
|
+
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
2441
|
+
*/
|
|
2442
|
+
function secretMapPatch(value) {
|
|
2443
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
2444
|
+
const out = {};
|
|
2445
|
+
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
2446
|
+
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
2447
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
2448
|
+
}
|
|
2449
|
+
var RecordIntegrationInstances = class {
|
|
2450
|
+
records;
|
|
2451
|
+
kind;
|
|
2452
|
+
hooks;
|
|
2453
|
+
handle;
|
|
2454
|
+
secretKeys;
|
|
2455
|
+
secretMaps;
|
|
2456
|
+
nameField;
|
|
2457
|
+
switchListeners = /* @__PURE__ */ new Set();
|
|
2458
|
+
constructor(records, kind, hooks) {
|
|
2459
|
+
this.records = records;
|
|
2460
|
+
this.kind = kind;
|
|
2461
|
+
this.hooks = hooks;
|
|
2462
|
+
this.handle = records.kind(kind);
|
|
2463
|
+
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
2464
|
+
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
2465
|
+
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
2466
|
+
}
|
|
2467
|
+
/**
|
|
2468
|
+
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
2469
|
+
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
2470
|
+
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
2471
|
+
*/
|
|
2472
|
+
async readResolved(id) {
|
|
2473
|
+
try {
|
|
2474
|
+
const record = await this.handle.getResolved(id);
|
|
2475
|
+
return record === null ? null : {
|
|
2476
|
+
id,
|
|
2477
|
+
body: record.data,
|
|
2478
|
+
enabled: isInstanceEnabled(record.data),
|
|
2479
|
+
secrets: "resolved"
|
|
2480
|
+
};
|
|
2481
|
+
} catch (err) {
|
|
2482
|
+
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
2483
|
+
const stored = await this.handle.get(id);
|
|
2484
|
+
if (stored === null) return null;
|
|
2485
|
+
return {
|
|
2486
|
+
id,
|
|
2487
|
+
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
2488
|
+
enabled: isInstanceEnabled(stored.data),
|
|
2489
|
+
secrets: "unavailable"
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
2494
|
+
async getResolved(id) {
|
|
2495
|
+
return (await this.readResolved(id))?.body ?? null;
|
|
2496
|
+
}
|
|
2497
|
+
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
2498
|
+
async listResolved() {
|
|
2499
|
+
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
2500
|
+
const out = [];
|
|
2501
|
+
for (const record of page.records) {
|
|
2502
|
+
const read = await this.readResolved(record.id);
|
|
2503
|
+
if (read !== null) out.push(read);
|
|
2504
|
+
}
|
|
2505
|
+
return out;
|
|
2506
|
+
}
|
|
2507
|
+
viewOf(record) {
|
|
2508
|
+
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
2509
|
+
const rawName = record.data[this.nameField];
|
|
2510
|
+
const kind = this.hooks.kindOf?.(record.data);
|
|
2511
|
+
const health = this.hooks.health?.(record.data, record.id);
|
|
2512
|
+
return {
|
|
2513
|
+
id: record.id,
|
|
2514
|
+
name: typeof rawName === "string" ? rawName : record.id,
|
|
2515
|
+
configured: this.hooks.configured(record.data),
|
|
2516
|
+
enabled: isInstanceEnabled(record.data),
|
|
2517
|
+
formValues: shown,
|
|
2518
|
+
...kind !== void 0 ? { kind } : {},
|
|
2519
|
+
...health?.status !== void 0 ? { status: health.status } : {},
|
|
2520
|
+
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
describe = async () => {
|
|
2524
|
+
const declared = linksOfKind(this.kind);
|
|
2525
|
+
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
2526
|
+
kind: this.kind.name,
|
|
2527
|
+
field: link.field,
|
|
2528
|
+
to: link.to
|
|
2529
|
+
})) };
|
|
2530
|
+
return {
|
|
2531
|
+
...this.hooks.description,
|
|
2532
|
+
...links,
|
|
2533
|
+
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
2534
|
+
};
|
|
2535
|
+
};
|
|
2536
|
+
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
2537
|
+
listInstances = async () => {
|
|
2538
|
+
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
2539
|
+
};
|
|
2540
|
+
getInstance = async ({ id }) => {
|
|
2541
|
+
const record = await this.handle.get(id);
|
|
2542
|
+
return record === null ? null : this.viewOf(record);
|
|
2543
|
+
};
|
|
2544
|
+
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
2545
|
+
createInstance = async ({ id, name, kind, values }) => {
|
|
2546
|
+
const minted = id ?? this.hooks.mintId?.({
|
|
2547
|
+
name,
|
|
2548
|
+
...kind !== void 0 ? { kind } : {}
|
|
2549
|
+
});
|
|
2550
|
+
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
2551
|
+
await this.handle.put({
|
|
2552
|
+
id: minted,
|
|
2553
|
+
data: this.hooks.initialBody(name, kind)
|
|
2554
|
+
}, { ifRev: 0 });
|
|
2555
|
+
const patch = this.patchOf(values ?? {});
|
|
2556
|
+
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
2557
|
+
await this.hooks.onChanged?.(minted, "created");
|
|
2558
|
+
return { id: minted };
|
|
2559
|
+
};
|
|
2560
|
+
updateInstance = async ({ id, name, values }) => {
|
|
2561
|
+
const patch = this.patchOf(values);
|
|
2562
|
+
if (name !== void 0) patch[this.nameField] = name;
|
|
2563
|
+
await this.handle.patch(id, patch);
|
|
2564
|
+
await this.hooks.onChanged?.(id, "updated");
|
|
2565
|
+
return { ok: true };
|
|
2566
|
+
};
|
|
2567
|
+
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
2568
|
+
patchOf(values) {
|
|
2569
|
+
const patch = {};
|
|
2570
|
+
for (const [key, value] of Object.entries(values)) {
|
|
2571
|
+
if (value === void 0) continue;
|
|
2572
|
+
if (key === "enabled") continue;
|
|
2573
|
+
if (this.secretMaps.has(key)) {
|
|
2574
|
+
const entries = secretMapPatch(value);
|
|
2575
|
+
if (entries !== null) patch[key] = entries;
|
|
2576
|
+
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
2577
|
+
else if (isSecretClear(value)) patch[key] = null;
|
|
2578
|
+
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
2579
|
+
}
|
|
2580
|
+
return patch;
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Listen to the switch of ANY instance of this helper (in the process that serves it). The
|
|
2584
|
+
* durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
|
|
2585
|
+
* addon reconciles from the record, whichever way it flipped.
|
|
2586
|
+
*/
|
|
2587
|
+
onSwitched(listener) {
|
|
2588
|
+
this.switchListeners.add(listener);
|
|
2589
|
+
}
|
|
2590
|
+
/**
|
|
2591
|
+
* The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
|
|
2592
|
+
* configured thing is an instance, so an id with no record yet (a default integration that was
|
|
2593
|
+
* never configured) gets its record from `initialBody` before the switch is written.
|
|
2594
|
+
*/
|
|
2595
|
+
setInstanceEnabled = async ({ id, enabled }) => {
|
|
2596
|
+
if (await this.handle.get(id) === null) await this.handle.put({
|
|
2597
|
+
id,
|
|
2598
|
+
data: this.hooks.initialBody(id)
|
|
2599
|
+
}, { ifRev: 0 });
|
|
2600
|
+
await this.handle.patch(id, { [SWITCH_KEY]: enabled });
|
|
2601
|
+
await this.hooks.onChanged?.(id, "enabled");
|
|
2602
|
+
for (const listener of this.switchListeners) await listener(id, enabled);
|
|
2603
|
+
return { ok: true };
|
|
2604
|
+
};
|
|
2605
|
+
/** The row and its keychain refs go together (the records door). */
|
|
2606
|
+
deleteInstance = async ({ id }) => {
|
|
2607
|
+
await this.handle.delete(id);
|
|
2608
|
+
await this.hooks.onChanged?.(id, "deleted");
|
|
2609
|
+
return { ok: true };
|
|
2610
|
+
};
|
|
2611
|
+
testInstance = async (input) => {
|
|
2612
|
+
if (this.hooks.test === void 0) return {
|
|
2613
|
+
success: false,
|
|
2614
|
+
status: "unsupported",
|
|
2615
|
+
error: "This integration declares no connection test"
|
|
2616
|
+
};
|
|
2617
|
+
return this.hooks.test(input);
|
|
2618
|
+
};
|
|
2619
|
+
/** The flat provider object to hand to `registerProvider`. */
|
|
2620
|
+
toProvider() {
|
|
2621
|
+
return {
|
|
2622
|
+
describe: this.describe,
|
|
2623
|
+
instanceFormSchema: this.instanceFormSchema,
|
|
2624
|
+
listInstances: this.listInstances,
|
|
2625
|
+
getInstance: this.getInstance,
|
|
2626
|
+
createInstance: this.createInstance,
|
|
2627
|
+
updateInstance: this.updateInstance,
|
|
2628
|
+
setInstanceEnabled: this.setInstanceEnabled,
|
|
2629
|
+
deleteInstance: this.deleteInstance,
|
|
2630
|
+
testInstance: this.testInstance
|
|
2631
|
+
};
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
/**
|
|
2635
|
+
* The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
|
|
2636
|
+
* registry's `enabled` column for a device addon; it now lives only in the instance record's
|
|
2637
|
+
* body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
|
|
2638
|
+
*
|
|
2639
|
+
* For every registry row of the addon that is OFF:
|
|
2640
|
+
* - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
|
|
2641
|
+
* (a default integration that never had settings, Reolink's among them);
|
|
2642
|
+
* - a record whose body states no `enabled`: `enabled: false` is written into it;
|
|
2643
|
+
* - a record that already states `enabled` (either way) is the newer truth and is left alone.
|
|
2644
|
+
* A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
|
|
2645
|
+
* a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
|
|
2646
|
+
* goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
|
|
2647
|
+
*
|
|
2648
|
+
* It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
|
|
2649
|
+
* which is also why `integrations.list` still answers the stored column at that point.
|
|
2650
|
+
*/
|
|
2651
|
+
function registrySwitchToBodyId(addonId, date) {
|
|
2652
|
+
return `${addonId}/${date}-registry-switch-to-body`;
|
|
2653
|
+
}
|
|
2654
|
+
async function moveRegistrySwitchToBody(ports, spec) {
|
|
2655
|
+
const rows = await ports.listIntegrations(spec.addonId);
|
|
2656
|
+
let created = 0;
|
|
2657
|
+
let switched = 0;
|
|
2658
|
+
let kept = 0;
|
|
2659
|
+
for (const row of rows) {
|
|
2660
|
+
if (row.enabled) continue;
|
|
2661
|
+
const body = await ports.readBody(row.id);
|
|
2662
|
+
if (body === null) {
|
|
2663
|
+
if (await ports.createRecord(row.id, {
|
|
2664
|
+
...spec.initialBody(row.name),
|
|
2665
|
+
["enabled"]: false
|
|
2666
|
+
}) === "created") created += 1;
|
|
2667
|
+
else kept += 1;
|
|
2668
|
+
continue;
|
|
2669
|
+
}
|
|
2670
|
+
if ("enabled" in body) {
|
|
2671
|
+
kept += 1;
|
|
2672
|
+
continue;
|
|
2673
|
+
}
|
|
2674
|
+
await ports.switchOff(row.id);
|
|
2675
|
+
switched += 1;
|
|
2676
|
+
}
|
|
2677
|
+
const summary = {
|
|
2678
|
+
integrations: rows.length,
|
|
2679
|
+
off: rows.filter((r) => !r.enabled).length,
|
|
2680
|
+
created,
|
|
2681
|
+
switched,
|
|
2682
|
+
kept
|
|
2683
|
+
};
|
|
2684
|
+
return created === 0 && switched === 0 ? {
|
|
2685
|
+
outcome: "already-done",
|
|
2686
|
+
summary
|
|
2687
|
+
} : {
|
|
2688
|
+
outcome: "done",
|
|
2689
|
+
summary
|
|
2690
|
+
};
|
|
2691
|
+
}
|
|
2692
|
+
/** A migration entry: an addon states its kind and how a new body starts, nothing else. */
|
|
2693
|
+
function registrySwitchToBodyMigration(spec) {
|
|
2694
|
+
return {
|
|
2695
|
+
meta: {
|
|
2696
|
+
id: registrySwitchToBodyId(spec.addonId, spec.date),
|
|
2697
|
+
owner: spec.addonId,
|
|
2698
|
+
level: "addon-state",
|
|
2699
|
+
seq: spec.seq,
|
|
2700
|
+
dependsOn: [],
|
|
2701
|
+
store: "settings",
|
|
2702
|
+
scope: "cluster",
|
|
2703
|
+
onFailure: "block-owner",
|
|
2704
|
+
bodyKind: "procedure",
|
|
2705
|
+
description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
|
|
2706
|
+
fixtureMark: "enabled"
|
|
2707
|
+
},
|
|
2708
|
+
procedure: (ports) => moveRegistrySwitchToBody(ports, {
|
|
2709
|
+
addonId: spec.addonId,
|
|
2710
|
+
initialBody: spec.initialBody
|
|
2711
|
+
})
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2714
|
+
/** The hub and records sides of {@link registrySwitchToBodyMigration}. */
|
|
2715
|
+
function registrySwitchPortsOver(deps) {
|
|
2716
|
+
const handle = deps.records.kind({
|
|
2717
|
+
name: deps.kind.name,
|
|
2718
|
+
declaration: deps.kind.declaration,
|
|
2719
|
+
schema: zod.z.record(zod.z.string(), zod.z.unknown())
|
|
2720
|
+
});
|
|
2721
|
+
return {
|
|
2722
|
+
listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
|
|
2723
|
+
id: i.id,
|
|
2724
|
+
name: i.name,
|
|
2725
|
+
enabled: i.enabled !== false
|
|
2726
|
+
})),
|
|
2727
|
+
readBody: async (id) => (await handle.get(id))?.data ?? null,
|
|
2728
|
+
createRecord: async (id, body) => {
|
|
2729
|
+
if (await handle.get(id) !== null) return "exists";
|
|
2730
|
+
await handle.put({
|
|
2731
|
+
id,
|
|
2732
|
+
data: body
|
|
2733
|
+
}, { ifRev: 0 });
|
|
2734
|
+
return "created";
|
|
2735
|
+
},
|
|
2736
|
+
switchOff: async (id) => {
|
|
2737
|
+
await handle.patch(id, { [SWITCH_KEY]: false });
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
/**
|
|
2742
|
+
* Build a {@link DurableState} over a single store key. Transport-agnostic:
|
|
2743
|
+
* `read`/`write` are the addon-store or device-store accessors. The whole
|
|
2744
|
+
* validated value round-trips on every read/write — the schema is the
|
|
2745
|
+
* single source of truth for what is persisted, so no hand-listed field
|
|
2746
|
+
* set can drop a key on save.
|
|
2747
|
+
*/
|
|
2748
|
+
function createDurableState(deps) {
|
|
2749
|
+
const get = async () => {
|
|
2750
|
+
const raw = (await deps.read())[deps.key];
|
|
2751
|
+
if (raw === void 0) return deps.fallback;
|
|
2752
|
+
const parsed = deps.schema.safeParse(raw);
|
|
2753
|
+
if (!parsed.success) {
|
|
2754
|
+
deps.onParseError?.(deps.key, parsed.error);
|
|
2755
|
+
return deps.fallback;
|
|
2756
|
+
}
|
|
2757
|
+
return parsed.data;
|
|
2758
|
+
};
|
|
2759
|
+
const set = async (next) => {
|
|
2760
|
+
const validated = deps.schema.parse(next);
|
|
2761
|
+
await deps.write({ [deps.key]: validated });
|
|
2762
|
+
};
|
|
2763
|
+
const update = async (fn) => {
|
|
2764
|
+
await set(fn(await get()));
|
|
2765
|
+
};
|
|
2766
|
+
return {
|
|
2767
|
+
get,
|
|
2768
|
+
set,
|
|
2769
|
+
update
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
2774
|
+
*
|
|
2775
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
2776
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
2777
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
2778
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
2779
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
2780
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
2781
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
2782
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
2783
|
+
*
|
|
2784
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
2785
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
2786
|
+
* schema and routes reads/writes through these helpers.
|
|
2787
|
+
*
|
|
2788
|
+
* ## No bare-key fallback — deliberate
|
|
2789
|
+
*
|
|
2790
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
2791
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
2792
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
2793
|
+
* the store is invisible to every node, hub included, so one node's
|
|
2794
|
+
* selection can never leak onto another. (This generalizes the
|
|
2795
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
2796
|
+
* arbitrary set of per-node field keys.)
|
|
2797
|
+
*
|
|
2798
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
2799
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
2800
|
+
*/
|
|
2801
|
+
/**
|
|
2802
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
2803
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
2804
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
2805
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
2806
|
+
*/
|
|
2807
|
+
function normalizeNodeId(raw) {
|
|
2808
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
2809
|
+
const slashIdx = raw.indexOf("/");
|
|
2810
|
+
if (slashIdx < 0) return raw;
|
|
2811
|
+
const bare = raw.slice(0, slashIdx);
|
|
2812
|
+
return bare === "" ? "hub" : bare;
|
|
2813
|
+
}
|
|
2814
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
2815
|
+
function nodeScopedKey(base, nodeId) {
|
|
2816
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
2820
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
2821
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
2822
|
+
* schema `default` win on `undefined`.
|
|
2823
|
+
*/
|
|
2824
|
+
function readNodeValue(store, base, nodeId) {
|
|
2825
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
2826
|
+
}
|
|
2827
|
+
/**
|
|
2828
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
2829
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
2830
|
+
* the write path so a save for one node never clobbers another node's value
|
|
2831
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
2832
|
+
* patch is not mutated.
|
|
2833
|
+
*/
|
|
2834
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
2835
|
+
const out = {};
|
|
2836
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
2837
|
+
return out;
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
2841
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
2842
|
+
* values:
|
|
2843
|
+
*
|
|
2844
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
2845
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
2846
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
2847
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
2848
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
2849
|
+
* left ABSENT so the field's schema `default` wins.
|
|
2850
|
+
*
|
|
2851
|
+
* Returns a new object — the input store is not mutated.
|
|
2852
|
+
*/
|
|
2853
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
2854
|
+
const out = {};
|
|
2855
|
+
for (const [key, value] of Object.entries(store)) {
|
|
2856
|
+
if (key.includes("@")) continue;
|
|
2857
|
+
if (perNodeKeys.has(key)) continue;
|
|
2858
|
+
out[key] = value;
|
|
2859
|
+
}
|
|
2860
|
+
for (const base of perNodeKeys) {
|
|
2861
|
+
const value = readNodeValue(store, base, nodeId);
|
|
2862
|
+
if (value !== void 0) out[base] = value;
|
|
2863
|
+
}
|
|
2864
|
+
return out;
|
|
2865
|
+
}
|
|
2866
|
+
/** Every scope, in the order the guard and the docs list them. */
|
|
2867
|
+
var SCOPED_SETTINGS_SCOPES = [
|
|
2868
|
+
"cluster",
|
|
2869
|
+
"device-defaults",
|
|
2870
|
+
"node"
|
|
2871
|
+
];
|
|
2872
|
+
/**
|
|
2873
|
+
* The node id a node-scoped KEY carries: the part after the `@`. `null` for a key with no `@`
|
|
2874
|
+
* (a cluster or fleet-default key) or an empty node id. A schema key never contains `@`
|
|
2875
|
+
* (guard `check-scoped-settings-declared`), so the first `@` is the separator.
|
|
2876
|
+
*/
|
|
2877
|
+
function nodeIdOfScopedKey(key) {
|
|
2878
|
+
const at = key.indexOf("@");
|
|
2879
|
+
if (at <= 0) return null;
|
|
2880
|
+
const nodeId = key.slice(at + 1);
|
|
2881
|
+
return nodeId === "" ? null : nodeId;
|
|
2882
|
+
}
|
|
2198
2883
|
/** A write to a secret path could not be stored in the keychain, so it was refused. */
|
|
2199
2884
|
var KeychainWriteRefusedError = class extends Error {
|
|
2200
2885
|
fieldPath;
|
|
@@ -2205,7 +2890,7 @@ var KeychainWriteRefusedError = class extends Error {
|
|
|
2205
2890
|
}
|
|
2206
2891
|
};
|
|
2207
2892
|
var KEEP = { kind: "keep" };
|
|
2208
|
-
function isRecord$
|
|
2893
|
+
function isRecord$4(value) {
|
|
2209
2894
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2210
2895
|
}
|
|
2211
2896
|
function defaultMintId() {
|
|
@@ -2218,7 +2903,7 @@ function collectSecretMarkerRefs(value, out = []) {
|
|
|
2218
2903
|
return out;
|
|
2219
2904
|
}
|
|
2220
2905
|
if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
|
|
2221
|
-
else if (isRecord$
|
|
2906
|
+
else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
|
|
2222
2907
|
return out;
|
|
2223
2908
|
}
|
|
2224
2909
|
async function storedValueEquals(secrets, marker, candidate) {
|
|
@@ -2273,7 +2958,7 @@ function rowId(row, idKey) {
|
|
|
2273
2958
|
return null;
|
|
2274
2959
|
}
|
|
2275
2960
|
async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
2276
|
-
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$
|
|
2961
|
+
const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
|
|
2277
2962
|
if (!Array.isArray(incoming)) {
|
|
2278
2963
|
ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
|
|
2279
2964
|
return {
|
|
@@ -2289,7 +2974,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
|
|
|
2289
2974
|
const kept = /* @__PURE__ */ new Set();
|
|
2290
2975
|
const rows = [];
|
|
2291
2976
|
for (const row of incoming) {
|
|
2292
|
-
if (!isRecord$
|
|
2977
|
+
if (!isRecord$4(row)) {
|
|
2293
2978
|
rows.push(row);
|
|
2294
2979
|
continue;
|
|
2295
2980
|
}
|
|
@@ -2314,7 +2999,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
2314
2999
|
case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
|
|
2315
3000
|
case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
|
|
2316
3001
|
case "object": {
|
|
2317
|
-
if (!isRecord$
|
|
3002
|
+
if (!isRecord$4(incoming)) {
|
|
2318
3003
|
if (incoming === void 0) return KEEP;
|
|
2319
3004
|
ctx.deletes.push(...collectSecretMarkerRefs(stored));
|
|
2320
3005
|
return {
|
|
@@ -2322,7 +3007,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
|
|
|
2322
3007
|
value: incoming
|
|
2323
3008
|
};
|
|
2324
3009
|
}
|
|
2325
|
-
const storedObj = isRecord$
|
|
3010
|
+
const storedObj = isRecord$4(stored) ? stored : {};
|
|
2326
3011
|
return {
|
|
2327
3012
|
kind: "value",
|
|
2328
3013
|
value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
|
|
@@ -2445,7 +3130,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
|
|
|
2445
3130
|
value: items
|
|
2446
3131
|
};
|
|
2447
3132
|
}
|
|
2448
|
-
if (isRecord$
|
|
3133
|
+
if (isRecord$4(v)) {
|
|
2449
3134
|
const out = {};
|
|
2450
3135
|
for (const [k, child] of Object.entries(v)) {
|
|
2451
3136
|
const s = substitute(child);
|
|
@@ -2477,7 +3162,7 @@ var SecretOverwriteRefusedError = class extends Error {
|
|
|
2477
3162
|
this.name = "SecretOverwriteRefusedError";
|
|
2478
3163
|
}
|
|
2479
3164
|
};
|
|
2480
|
-
function isRecord$
|
|
3165
|
+
function isRecord$3(value) {
|
|
2481
3166
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2482
3167
|
}
|
|
2483
3168
|
function resolvedValue(pass, marker) {
|
|
@@ -2506,7 +3191,7 @@ function inArray(pass, incoming, stored) {
|
|
|
2506
3191
|
return incoming.map((item, index) => {
|
|
2507
3192
|
const twin = stored[index];
|
|
2508
3193
|
if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
|
|
2509
|
-
if (isRecord$
|
|
3194
|
+
if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
|
|
2510
3195
|
if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
|
|
2511
3196
|
return item;
|
|
2512
3197
|
});
|
|
@@ -2517,7 +3202,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
2517
3202
|
const twin = stored[key];
|
|
2518
3203
|
if (isSecretMarker(twin)) {
|
|
2519
3204
|
if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
|
|
2520
|
-
} else if (isRecord$
|
|
3205
|
+
} else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
|
|
2521
3206
|
else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
|
|
2522
3207
|
}
|
|
2523
3208
|
return out;
|
|
@@ -2525,7 +3210,7 @@ function inArrayRow(pass, incoming, stored) {
|
|
|
2525
3210
|
async function walk(pass, incoming, stored) {
|
|
2526
3211
|
if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
|
|
2527
3212
|
if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
|
|
2528
|
-
if (!isRecord$
|
|
3213
|
+
if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
|
|
2529
3214
|
const out = { ...incoming };
|
|
2530
3215
|
for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
|
|
2531
3216
|
return out;
|
|
@@ -2556,7 +3241,7 @@ async function restoreUnchangedSecrets(input) {
|
|
|
2556
3241
|
function isJsonEqual(a, b) {
|
|
2557
3242
|
if (Object.is(a, b)) return true;
|
|
2558
3243
|
if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
|
|
2559
|
-
if (isRecord$
|
|
3244
|
+
if (isRecord$3(a) && isRecord$3(b)) {
|
|
2560
3245
|
const keys = Object.keys(a);
|
|
2561
3246
|
if (keys.length !== Object.keys(b).length) return false;
|
|
2562
3247
|
return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
|
|
@@ -2580,7 +3265,7 @@ function markerKeysOf(blob, owner) {
|
|
|
2580
3265
|
}
|
|
2581
3266
|
function nodeFromStored(value, owner) {
|
|
2582
3267
|
if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
|
|
2583
|
-
if (!isRecord$
|
|
3268
|
+
if (!isRecord$3(value)) return null;
|
|
2584
3269
|
const children = /* @__PURE__ */ new Map();
|
|
2585
3270
|
for (const [key, child] of Object.entries(value)) {
|
|
2586
3271
|
const node = nodeFromStored(child, owner);
|
|
@@ -3090,13 +3775,48 @@ var BaseAddon = class {
|
|
|
3090
3775
|
if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
|
|
3091
3776
|
return this.runBound(sets.flatMap((set) => set.bind(api)), options);
|
|
3092
3777
|
}
|
|
3093
|
-
|
|
3778
|
+
/**
|
|
3779
|
+
* A device addon states its instance kind once, before its migrations run, and the one-switch
|
|
3780
|
+
* migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
|
|
3781
|
+
* catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
|
|
3782
|
+
* on every declare).
|
|
3783
|
+
*/
|
|
3784
|
+
declareRegistrySwitch(spec) {
|
|
3785
|
+
this.registrySwitchSpec = spec;
|
|
3786
|
+
}
|
|
3787
|
+
registrySwitchSpec = null;
|
|
3788
|
+
registrySwitchBound() {
|
|
3789
|
+
const spec = this.registrySwitchSpec;
|
|
3790
|
+
if (spec === null) return [];
|
|
3791
|
+
const api = this.ctx.migrationApi;
|
|
3792
|
+
if (api === void 0) {
|
|
3793
|
+
this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
|
|
3794
|
+
return [];
|
|
3795
|
+
}
|
|
3796
|
+
return migrationSet([registrySwitchToBodyMigration({
|
|
3797
|
+
addonId: this.ctx.id,
|
|
3798
|
+
date: "2026-11-06",
|
|
3799
|
+
seq: 1e3,
|
|
3800
|
+
initialBody: spec.initialBody
|
|
3801
|
+
})], (a) => registrySwitchPortsOver({
|
|
3802
|
+
api: integrationRowsApiOver(a),
|
|
3803
|
+
records: switchRecordsOverMigrationApi(a),
|
|
3804
|
+
kind: spec.kind
|
|
3805
|
+
})).bind(api);
|
|
3806
|
+
}
|
|
3807
|
+
async runBound(declared, options) {
|
|
3808
|
+
const added = this.registrySwitchBound();
|
|
3809
|
+
const migrations = [...declared, ...added];
|
|
3810
|
+
const phased = options?.only === void 0 || added.length === 0 ? options : {
|
|
3811
|
+
...options,
|
|
3812
|
+
only: [...options.only, ...added.map((m) => m.meta.id)]
|
|
3813
|
+
};
|
|
3094
3814
|
const api = this.ctx.api.migrations;
|
|
3095
3815
|
const report = await runAddonMigrations({
|
|
3096
3816
|
declareOwner: (input) => api.declareOwner.mutate(input),
|
|
3097
3817
|
startMigration: (input) => api.startMigration.mutate(input),
|
|
3098
3818
|
finishMigration: (input) => api.finishMigration.mutate(input)
|
|
3099
|
-
}, migrations, this.ctx.logger,
|
|
3819
|
+
}, migrations, this.ctx.logger, phased);
|
|
3100
3820
|
if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
|
|
3101
3821
|
return report;
|
|
3102
3822
|
}
|
|
@@ -4169,320 +4889,6 @@ function normalizeAddonInitResult(result) {
|
|
|
4169
4889
|
if (Array.isArray(result)) return { providers: result };
|
|
4170
4890
|
return result;
|
|
4171
4891
|
}
|
|
4172
|
-
var PREFIX = "records/";
|
|
4173
|
-
/** The base of every records failure. `detail` is the human part of the message. */
|
|
4174
|
-
var RecordsError = class extends Error {
|
|
4175
|
-
code;
|
|
4176
|
-
detail;
|
|
4177
|
-
constructor(code, detail) {
|
|
4178
|
-
super(`${PREFIX}${code}: ${detail}`);
|
|
4179
|
-
this.name = "RecordsError";
|
|
4180
|
-
this.code = code;
|
|
4181
|
-
this.detail = detail;
|
|
4182
|
-
}
|
|
4183
|
-
};
|
|
4184
|
-
/** A write guarded by `ifRev` found another revision (or an existing row for `ifRev: 0`). */
|
|
4185
|
-
var RevConflictError = class extends RecordsError {
|
|
4186
|
-
constructor(detail) {
|
|
4187
|
-
super("rev-conflict", detail);
|
|
4188
|
-
this.name = "RevConflictError";
|
|
4189
|
-
}
|
|
4190
|
-
};
|
|
4191
|
-
/** `data` exceeds the kind's `maxDataBytes`. Bytes are never record fields (D613). */
|
|
4192
|
-
var RecordTooLargeError = class extends RecordsError {
|
|
4193
|
-
constructor(detail) {
|
|
4194
|
-
super("too-large", detail);
|
|
4195
|
-
this.name = "RecordTooLargeError";
|
|
4196
|
-
}
|
|
4197
|
-
};
|
|
4198
|
-
/** A filter, order or aggregate names a field no declared index serves. */
|
|
4199
|
-
var UnindexedFilterError = class extends RecordsError {
|
|
4200
|
-
constructor(detail) {
|
|
4201
|
-
super("unindexed-filter", detail);
|
|
4202
|
-
this.name = "UnindexedFilterError";
|
|
4203
|
-
}
|
|
4204
|
-
};
|
|
4205
|
-
/** A bulk delete with no predicate at all. */
|
|
4206
|
-
var FilterRequiredError = class extends RecordsError {
|
|
4207
|
-
constructor(detail) {
|
|
4208
|
-
super("filter-required", detail);
|
|
4209
|
-
this.name = "FilterRequiredError";
|
|
4210
|
-
}
|
|
4211
|
-
};
|
|
4212
|
-
/** The caller declared no such kind (another addon's kind is indistinguishable from none). */
|
|
4213
|
-
var UnknownRecordKindError = class extends RecordsError {
|
|
4214
|
-
constructor(detail) {
|
|
4215
|
-
super("unknown-kind", detail);
|
|
4216
|
-
this.name = "UnknownRecordKindError";
|
|
4217
|
-
}
|
|
4218
|
-
};
|
|
4219
|
-
var RecordNotFoundError = class extends RecordsError {
|
|
4220
|
-
constructor(detail) {
|
|
4221
|
-
super("not-found", detail);
|
|
4222
|
-
this.name = "RecordNotFoundError";
|
|
4223
|
-
}
|
|
4224
|
-
};
|
|
4225
|
-
/** A unique index refused the write. */
|
|
4226
|
-
var RecordUniqueViolationError = class extends RecordsError {
|
|
4227
|
-
constructor(detail) {
|
|
4228
|
-
super("unique-violation", detail);
|
|
4229
|
-
this.name = "RecordUniqueViolationError";
|
|
4230
|
-
}
|
|
4231
|
-
};
|
|
4232
|
-
/** A secret field held a plain string where only a keychain marker may be stored. */
|
|
4233
|
-
var PlaintextSecretError = class extends RecordsError {
|
|
4234
|
-
constructor(detail) {
|
|
4235
|
-
super("plaintext-secret", detail);
|
|
4236
|
-
this.name = "PlaintextSecretError";
|
|
4237
|
-
}
|
|
4238
|
-
};
|
|
4239
|
-
/** A marker whose ref is not the row's own (the D878 rule). */
|
|
4240
|
-
var ForeignSecretMarkerError = class extends RecordsError {
|
|
4241
|
-
constructor(detail) {
|
|
4242
|
-
super("foreign-marker", detail);
|
|
4243
|
-
this.name = "ForeignSecretMarkerError";
|
|
4244
|
-
}
|
|
4245
|
-
};
|
|
4246
|
-
/** The keychain could not store or serve a value: explicit, never an empty string. */
|
|
4247
|
-
var RecordSecretUnavailableError = class extends RecordsError {
|
|
4248
|
-
constructor(detail) {
|
|
4249
|
-
super("secret-unavailable", detail);
|
|
4250
|
-
this.name = "RecordSecretUnavailableError";
|
|
4251
|
-
}
|
|
4252
|
-
};
|
|
4253
|
-
var InvalidRecordError = class extends RecordsError {
|
|
4254
|
-
constructor(detail) {
|
|
4255
|
-
super("invalid-record", detail);
|
|
4256
|
-
this.name = "InvalidRecordError";
|
|
4257
|
-
}
|
|
4258
|
-
};
|
|
4259
|
-
/** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
|
|
4260
|
-
var DeclarationRefusedError = class extends RecordsError {
|
|
4261
|
-
constructor(detail) {
|
|
4262
|
-
super("declaration-refused", detail);
|
|
4263
|
-
this.name = "DeclarationRefusedError";
|
|
4264
|
-
}
|
|
4265
|
-
};
|
|
4266
|
-
var NoCallerError = class extends RecordsError {
|
|
4267
|
-
constructor(detail) {
|
|
4268
|
-
super("no-caller", detail);
|
|
4269
|
-
this.name = "NoCallerError";
|
|
4270
|
-
}
|
|
4271
|
-
};
|
|
4272
|
-
var BatchTooLargeError = class extends RecordsError {
|
|
4273
|
-
constructor(detail) {
|
|
4274
|
-
super("batch-too-large", detail);
|
|
4275
|
-
this.name = "BatchTooLargeError";
|
|
4276
|
-
}
|
|
4277
|
-
};
|
|
4278
|
-
/**
|
|
4279
|
-
* A `transact` the engine refuses before touching a row: an op on a kind the
|
|
4280
|
-
* caller did not declare in ONE file and ONE `transactFamily`. The detail names
|
|
4281
|
-
* which rule (`cross-file`, `cross-family`, `no-family`); it is never a silent split.
|
|
4282
|
-
*/
|
|
4283
|
-
var TransactRefusedError = class extends RecordsError {
|
|
4284
|
-
constructor(detail) {
|
|
4285
|
-
super("transact-refused", detail);
|
|
4286
|
-
this.name = "TransactRefusedError";
|
|
4287
|
-
}
|
|
4288
|
-
};
|
|
4289
|
-
/** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
|
|
4290
|
-
/** The files a kind may live in. `history` is device-history's (D850), never records. */
|
|
4291
|
-
var RECORD_DATABASES = ["settings", "events"];
|
|
4292
|
-
/** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
|
|
4293
|
-
var RECORD_CLASSES = [
|
|
4294
|
-
"config",
|
|
4295
|
-
"ledger",
|
|
4296
|
-
"audit",
|
|
4297
|
-
"mirror",
|
|
4298
|
-
"ephemeral"
|
|
4299
|
-
];
|
|
4300
|
-
var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
|
|
4301
|
-
var RECORD_MAX_DATA_BYTES = 1024 * 1024;
|
|
4302
|
-
var RECORD_BATCH_MAX = 1e3;
|
|
4303
|
-
var RECORD_BATCH_MAX_BYTES = 4 * 1024 * 1024;
|
|
4304
|
-
var RECORD_QUERY_MAX = 1e3;
|
|
4305
|
-
/** Rows one DELETE statement removes before the serving thread yields. */
|
|
4306
|
-
var RECORD_DELETE_BATCH = 5e3;
|
|
4307
|
-
/** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
|
|
4308
|
-
var RECORD_SETTINGS_MAX_ROWS = 5e4;
|
|
4309
|
-
/** The engine's TTL sweep cadence. */
|
|
4310
|
-
var RECORD_SWEEP_INTERVAL_MS = 10 * 6e4;
|
|
4311
|
-
/** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
|
|
4312
|
-
var RECORD_SECRET_COLLECTION_PREFIX = "records:";
|
|
4313
|
-
/**
|
|
4314
|
-
* Secret fields of a record, addressed the way a Zod schema declares them
|
|
4315
|
-
* (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
|
|
4316
|
-
* (`auth.accessToken`, `headers[].value`).
|
|
4317
|
-
*
|
|
4318
|
-
* `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
|
|
4319
|
-
* names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
|
|
4320
|
-
* key releases exactly that key's secret.
|
|
4321
|
-
*
|
|
4322
|
-
* Array elements are matched by a DECLARED id key (`secretArrayKeys`:
|
|
4323
|
-
* `{ headers: 'name' }`), never by index, so reordering a list keeps every
|
|
4324
|
-
* keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
|
|
4325
|
-
* leaf names its element: `headers[X-Api].value`.
|
|
4326
|
-
*
|
|
4327
|
-
* Pure and browser-safe. Nothing here mutates: every transform returns a new value.
|
|
4328
|
-
*/
|
|
4329
|
-
/** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
|
|
4330
|
-
function parseSecretPath(path) {
|
|
4331
|
-
if (path.length === 0) throw new InvalidRecordError("an empty secret path");
|
|
4332
|
-
return path.split(".").map((raw) => {
|
|
4333
|
-
const each = raw.endsWith("[]");
|
|
4334
|
-
const map = raw.endsWith("{}");
|
|
4335
|
-
const key = each || map ? raw.slice(0, -2) : raw;
|
|
4336
|
-
if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
|
|
4337
|
-
return {
|
|
4338
|
-
key,
|
|
4339
|
-
each,
|
|
4340
|
-
map
|
|
4341
|
-
};
|
|
4342
|
-
});
|
|
4343
|
-
}
|
|
4344
|
-
/** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
|
|
4345
|
-
function secretArrayPrefixes(path) {
|
|
4346
|
-
const segments = parseSecretPath(path);
|
|
4347
|
-
const prefixes = [];
|
|
4348
|
-
const walked = [];
|
|
4349
|
-
for (const segment of segments) {
|
|
4350
|
-
walked.push(segment.key);
|
|
4351
|
-
if (segment.each) prefixes.push(walked.join("."));
|
|
4352
|
-
}
|
|
4353
|
-
return prefixes;
|
|
4354
|
-
}
|
|
4355
|
-
function isRecord$4(value) {
|
|
4356
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4357
|
-
}
|
|
4358
|
-
function elementId(element, idKey, declared, prefix) {
|
|
4359
|
-
const id = isRecord$4(element) ? element[idKey] : void 0;
|
|
4360
|
-
if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
|
|
4361
|
-
return id;
|
|
4362
|
-
}
|
|
4363
|
-
/**
|
|
4364
|
-
* Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
|
|
4365
|
-
* visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
|
|
4366
|
-
* result is a new body, `data` is untouched.
|
|
4367
|
-
*/
|
|
4368
|
-
var REMOVE_LEAF = Symbol("remove-leaf");
|
|
4369
|
-
function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
|
|
4370
|
-
if (!isRecord$4(node)) return node;
|
|
4371
|
-
const segment = segments[index];
|
|
4372
|
-
if (segment === void 0) return node;
|
|
4373
|
-
if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
|
|
4374
|
-
const child = node[segment.key];
|
|
4375
|
-
const keys = [...walkedKeys, segment.key];
|
|
4376
|
-
const last = index === segments.length - 1;
|
|
4377
|
-
if (segment.each) {
|
|
4378
|
-
if (!Array.isArray(child)) return node;
|
|
4379
|
-
const prefix = keys.join(".");
|
|
4380
|
-
const idKey = arrayKeys[prefix];
|
|
4381
|
-
if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
|
|
4382
|
-
const mapped = child.map((element) => {
|
|
4383
|
-
const id = elementId(element, idKey, declared, prefix);
|
|
4384
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
|
|
4385
|
-
return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
|
|
4386
|
-
});
|
|
4387
|
-
return {
|
|
4388
|
-
...node,
|
|
4389
|
-
[segment.key]: mapped
|
|
4390
|
-
};
|
|
4391
|
-
}
|
|
4392
|
-
if (segment.map) {
|
|
4393
|
-
if (!isRecord$4(child)) return node;
|
|
4394
|
-
const kept = Object.entries(child).map(([mapKey, value]) => {
|
|
4395
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
|
|
4396
|
-
if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
|
|
4397
|
-
return [mapKey, visit({
|
|
4398
|
-
declared,
|
|
4399
|
-
concrete,
|
|
4400
|
-
value
|
|
4401
|
-
})];
|
|
4402
|
-
}).filter(([, value]) => value !== REMOVE_LEAF);
|
|
4403
|
-
return {
|
|
4404
|
-
...node,
|
|
4405
|
-
[segment.key]: Object.fromEntries(kept)
|
|
4406
|
-
};
|
|
4407
|
-
}
|
|
4408
|
-
const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
|
|
4409
|
-
if (last) {
|
|
4410
|
-
const replacement = visit({
|
|
4411
|
-
declared,
|
|
4412
|
-
concrete,
|
|
4413
|
-
value: child
|
|
4414
|
-
});
|
|
4415
|
-
if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
|
|
4416
|
-
return {
|
|
4417
|
-
...node,
|
|
4418
|
-
[segment.key]: replacement
|
|
4419
|
-
};
|
|
4420
|
-
}
|
|
4421
|
-
return {
|
|
4422
|
-
...node,
|
|
4423
|
-
[segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
|
|
4424
|
-
};
|
|
4425
|
-
}
|
|
4426
|
-
/** Replace/remove every present secret leaf; returns a NEW body. */
|
|
4427
|
-
function mapSecretLeaves(data, paths, arrayKeys, visit) {
|
|
4428
|
-
let current = data;
|
|
4429
|
-
for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
|
|
4430
|
-
return current;
|
|
4431
|
-
}
|
|
4432
|
-
/** Every present secret leaf, read-only. */
|
|
4433
|
-
function collectSecretLeaves(data, paths, arrayKeys) {
|
|
4434
|
-
const found = [];
|
|
4435
|
-
mapSecretLeaves(data, paths, arrayKeys, (leaf) => {
|
|
4436
|
-
found.push(leaf);
|
|
4437
|
-
return leaf.value;
|
|
4438
|
-
});
|
|
4439
|
-
return found;
|
|
4440
|
-
}
|
|
4441
|
-
/**
|
|
4442
|
-
* The keychain collection name a kind's secrets live under. Prefixed so a
|
|
4443
|
-
* record's refs never collide with the refs a legacy collection of the same name
|
|
4444
|
-
* already holds during an adoption.
|
|
4445
|
-
*/
|
|
4446
|
-
function recordSecretCollection(kind) {
|
|
4447
|
-
return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
|
|
4448
|
-
}
|
|
4449
|
-
/** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
|
|
4450
|
-
function recordSecretRef(owner, kind, rowId, concretePath) {
|
|
4451
|
-
return buildSecretRef({
|
|
4452
|
-
owner,
|
|
4453
|
-
scope: {
|
|
4454
|
-
kind: "row",
|
|
4455
|
-
collection: recordSecretCollection(kind),
|
|
4456
|
-
rowId
|
|
4457
|
-
},
|
|
4458
|
-
fieldPath: concretePath
|
|
4459
|
-
});
|
|
4460
|
-
}
|
|
4461
|
-
/**
|
|
4462
|
-
* A stored secret, as an admin read shows it: a VIEW naming the row's own
|
|
4463
|
-
* keychain ref (`set: true`), never the value and no longer the bare redaction
|
|
4464
|
-
* token. The form hands it to the secret field, which reveals the value by ref
|
|
4465
|
-
* through the audited `keychain-admin.reveal`; sent back untouched it keeps the
|
|
4466
|
-
* stored secret (the records door reads a view as KEEP).
|
|
4467
|
-
*
|
|
4468
|
-
* ONE implementation for the entries service and for every addon that serves
|
|
4469
|
-
* its own instances (`RecordIntegrationInstances`).
|
|
4470
|
-
*/
|
|
4471
|
-
function isRecord$3(value) {
|
|
4472
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4473
|
-
}
|
|
4474
|
-
function secretViewsOf(owner, kind, id, decl, data) {
|
|
4475
|
-
if (decl.secretPaths.length === 0) return data;
|
|
4476
|
-
const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
|
|
4477
|
-
if (leaf.value !== "__camstack_redacted__") return leaf.value;
|
|
4478
|
-
return {
|
|
4479
|
-
$secret: recordSecretRef(owner, kind, id, leaf.concrete),
|
|
4480
|
-
v: 1,
|
|
4481
|
-
set: true
|
|
4482
|
-
};
|
|
4483
|
-
});
|
|
4484
|
-
return isRecord$3(shown) ? shown : data;
|
|
4485
|
-
}
|
|
4486
4892
|
/**
|
|
4487
4893
|
* Per-listener shared-secret header the hub injects on every reverse-proxied
|
|
4488
4894
|
* data-plane request and the addon's framework wrapper validates — so only the
|
|
@@ -4757,20 +5163,6 @@ function assertTransactScope(members) {
|
|
|
4757
5163
|
if (new Set(kinds.map((m) => m.declaration.transactFamily)).size > 1) throw new TransactRefusedError(`cross-family: the ops span more than one transactFamily (${kinds.map((m) => `${m.kind}=${String(m.declaration.transactFamily)}`).join(", ")})`);
|
|
4758
5164
|
}
|
|
4759
5165
|
/**
|
|
4760
|
-
* Entry kinds (D881): every list of user-created entries (notification
|
|
4761
|
-
* targets, brokers, LLM profiles) is ONE record kind with an id, a name and a
|
|
4762
|
-
* kind-specific body, and the admin UI lists/adds/edits/deletes all of them
|
|
4763
|
-
* through the `record-entries` capability with password fields derived from
|
|
4764
|
-
* the schema (`.meta({ secret: true })`).
|
|
4765
|
-
*/
|
|
4766
|
-
/** The body of a plain entry: a name and the fields the kind adds. */
|
|
4767
|
-
function entryBody(shape) {
|
|
4768
|
-
return zod.z.object({
|
|
4769
|
-
name: zod.z.string().min(1),
|
|
4770
|
-
...shape
|
|
4771
|
-
});
|
|
4772
|
-
}
|
|
4773
|
-
/**
|
|
4774
5166
|
* Declare one entry kind. An entry is configuration: never trimmed by the
|
|
4775
5167
|
* engine, never aged, belonging to no device.
|
|
4776
5168
|
*/
|
|
@@ -7426,6 +7818,10 @@ Object.freeze({
|
|
|
7426
7818
|
"all",
|
|
7427
7819
|
"one"
|
|
7428
7820
|
]
|
|
7821
|
+
},
|
|
7822
|
+
{
|
|
7823
|
+
"path": "positionUpdatedAt",
|
|
7824
|
+
"valueType": "number"
|
|
7429
7825
|
}
|
|
7430
7826
|
],
|
|
7431
7827
|
"meter": [{
|
|
@@ -7680,22 +8076,6 @@ Object.freeze({
|
|
|
7680
8076
|
"path": "pumpRunning",
|
|
7681
8077
|
"valueType": "boolean"
|
|
7682
8078
|
},
|
|
7683
|
-
{
|
|
7684
|
-
"path": "lastDrink",
|
|
7685
|
-
"valueType": "number"
|
|
7686
|
-
},
|
|
7687
|
-
{
|
|
7688
|
-
"path": "currentHourDrink",
|
|
7689
|
-
"valueType": "number"
|
|
7690
|
-
},
|
|
7691
|
-
{
|
|
7692
|
-
"path": "last24hDrink",
|
|
7693
|
-
"valueType": "number"
|
|
7694
|
-
},
|
|
7695
|
-
{
|
|
7696
|
-
"path": "todayDrink",
|
|
7697
|
-
"valueType": "number"
|
|
7698
|
-
},
|
|
7699
8079
|
{
|
|
7700
8080
|
"path": "error",
|
|
7701
8081
|
"valueType": "string"
|
|
@@ -8261,6 +8641,60 @@ Object.freeze({
|
|
|
8261
8641
|
}
|
|
8262
8642
|
]
|
|
8263
8643
|
});
|
|
8644
|
+
Object.freeze({
|
|
8645
|
+
"actions": { "run": 363e4 },
|
|
8646
|
+
"audio-analyzer": { "classify": 3e4 },
|
|
8647
|
+
"custom-model-registry": { "importModelBundle": 18e5 },
|
|
8648
|
+
"database-snapshot": { "writeSnapshot": 18e5 },
|
|
8649
|
+
"device-manager": {
|
|
8650
|
+
"migrateDevice": 72e4,
|
|
8651
|
+
"runDiscoverySweep": 12e4
|
|
8652
|
+
},
|
|
8653
|
+
"device-provider": { "reloadDevice": 18e4 },
|
|
8654
|
+
"llm": {
|
|
8655
|
+
"generate": 6e5,
|
|
8656
|
+
"generateVision": 6e5,
|
|
8657
|
+
"testProfile": 6e5
|
|
8658
|
+
},
|
|
8659
|
+
"llm-runtime": {
|
|
8660
|
+
"complete": 6e5,
|
|
8661
|
+
"completeApple": 6e5,
|
|
8662
|
+
"ensureStarted": 6e5,
|
|
8663
|
+
"installModel": 36e5
|
|
8664
|
+
},
|
|
8665
|
+
"local-network": { "scanNetwork": 9e4 },
|
|
8666
|
+
"model-convert": { "convert": 6e5 },
|
|
8667
|
+
"pipeline-analytics": {
|
|
8668
|
+
"addRetrainFrameFromRecording": 6e4,
|
|
8669
|
+
"offerRetrainArchive": 12e4,
|
|
8670
|
+
"proposeRetrainAnnotationsWithLlm": 18e4,
|
|
8671
|
+
"resolveRetrainTrainingCorpus": 6e4,
|
|
8672
|
+
"writeRetrainArchive": 36e5
|
|
8673
|
+
},
|
|
8674
|
+
"server-management": { "applyServerUpdate": 96e4 },
|
|
8675
|
+
"terminal-session": { "pullOutput": 15e3 },
|
|
8676
|
+
"training": {
|
|
8677
|
+
"canaryResult": 12e4,
|
|
8678
|
+
"cancelJob": 12e4,
|
|
8679
|
+
"planJob": 6e4,
|
|
8680
|
+
"registerResult": 18e5,
|
|
8681
|
+
"rollbackCanary": 12e4,
|
|
8682
|
+
"startJob": 12e4,
|
|
8683
|
+
"startJobBatch": 12e4
|
|
8684
|
+
},
|
|
8685
|
+
"training-provider": {
|
|
8686
|
+
"cancelJob": 6e4,
|
|
8687
|
+
"cleanupJob": 3e5,
|
|
8688
|
+
"getJob": 6e4,
|
|
8689
|
+
"listJobEvents": 6e4,
|
|
8690
|
+
"listJobs": 12e4,
|
|
8691
|
+
"offerArtifact": 3e5,
|
|
8692
|
+
"readResult": 3e5,
|
|
8693
|
+
"submitJob": 18e5,
|
|
8694
|
+
"uploadDataset": 72e5,
|
|
8695
|
+
"validateCredentials": 3e4
|
|
8696
|
+
}
|
|
8697
|
+
});
|
|
8264
8698
|
/**
|
|
8265
8699
|
* Runtime defaults — what `ConfigManager.get()` answers for a key nothing has
|
|
8266
8700
|
* stored, and what the settings store seeds on first boot. Only keys somebody
|
|
@@ -8375,7 +8809,7 @@ function sleep(ms) {
|
|
|
8375
8809
|
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
8376
8810
|
}
|
|
8377
8811
|
//#endregion
|
|
8378
|
-
//#region ../types/dist/composition-
|
|
8812
|
+
//#region ../types/dist/composition-BmBHuDTQ.mjs
|
|
8379
8813
|
var AUDIO_ENCODER_BY_CODEC = {
|
|
8380
8814
|
opus: "libopus",
|
|
8381
8815
|
aac: "aac",
|
|
@@ -9004,34 +9438,62 @@ function asNonNegativeMs(value, name, index) {
|
|
|
9004
9438
|
return ms;
|
|
9005
9439
|
}
|
|
9006
9440
|
/**
|
|
9007
|
-
* `dwell(active, onForMs, offForMs)`: unknown until a delay elapses, then holds
|
|
9441
|
+
* `dwell(active, onForMs, offForMs[, minSamples])`: unknown until a delay elapses, then holds
|
|
9008
9442
|
* the latched boolean through gaps shorter than the opposing delay (D933). A new
|
|
9009
9443
|
* call state seeded with the restored output starts latched on it, so it is never
|
|
9010
9444
|
* unknown after a boot.
|
|
9011
|
-
|
|
9012
|
-
|
|
9445
|
+
*
|
|
9446
|
+
* With `minSamples` above 1 (opt-in; default 1 = time only, as a single-event
|
|
9447
|
+
* binary sensor needs) a flip to ON needs EVIDENCE, not only time: at least that
|
|
9448
|
+
* many input samples that satisfy the condition (the one that opened the pending transition and later
|
|
9449
|
+
* ones, all from source readings), so a deadline timer firing over one held
|
|
9450
|
+
* value never starts a run. A standby plug reports one 5-9 W sample and then
|
|
9451
|
+
* stays silent; the held value used to confirm a start 30 s later. A flip to OFF
|
|
9452
|
+
* is deliberately NOT symmetric: a quiet sensor is how a finished run looks (the
|
|
9453
|
+
* plug reports the drop once and goes silent), so the held "off" value must still
|
|
9454
|
+
* confirm after `offForMs`. A zero ON delay asks for no persistence, so one
|
|
9455
|
+
* sample is enough.
|
|
9456
|
+
*/
|
|
9457
|
+
function evaluateDwell(activeRaw, onForMsRaw, offForMsRaw, minSamplesRaw, call, nowMs, hooks) {
|
|
9013
9458
|
const active = asBoolean(activeRaw, "dwell", 0);
|
|
9014
9459
|
const onForMs = asNonNegativeMs(onForMsRaw, "dwell", 1);
|
|
9015
9460
|
const offForMs = asNonNegativeMs(offForMsRaw, "dwell", 2);
|
|
9461
|
+
const minSamples = minSamplesRaw === void 0 ? 1 : asMinSamples(minSamplesRaw);
|
|
9016
9462
|
call.transition = null;
|
|
9017
9463
|
if (call.latched === null) {
|
|
9018
|
-
if (call.seenSince === null)
|
|
9464
|
+
if (call.seenSince === null) {
|
|
9465
|
+
call.seenSince = nowMs;
|
|
9466
|
+
call.pendingSamples = 0;
|
|
9467
|
+
}
|
|
9468
|
+
if (hooks?.timerDriven !== true) call.pendingSamples += 1;
|
|
9019
9469
|
const delay = active ? onForMs : offForMs;
|
|
9020
|
-
|
|
9470
|
+
const sustained = !active || delay === 0 || minSamples <= 1 || call.pendingSamples >= minSamples;
|
|
9471
|
+
if (nowMs - call.seenSince >= delay && sustained) {
|
|
9021
9472
|
call.latched = active;
|
|
9473
|
+
call.pendingSamples = 0;
|
|
9022
9474
|
return call.latched;
|
|
9023
9475
|
}
|
|
9024
|
-
hooks?.noteDeadline?.(call.seenSince + delay);
|
|
9476
|
+
if (nowMs - call.seenSince < delay) hooks?.noteDeadline?.(call.seenSince + delay);
|
|
9025
9477
|
return null;
|
|
9026
9478
|
}
|
|
9027
9479
|
if (active === call.latched) return holdAgainstReturn(call, active, onForMs, nowMs, hooks);
|
|
9028
9480
|
call.returnSince = null;
|
|
9029
|
-
if (call.pendingSince === null)
|
|
9481
|
+
if (call.pendingSince === null) {
|
|
9482
|
+
call.pendingSince = nowMs;
|
|
9483
|
+
call.pendingSamples = 0;
|
|
9484
|
+
}
|
|
9485
|
+
if (hooks?.timerDriven !== true) call.pendingSamples += 1;
|
|
9030
9486
|
const delay = active ? onForMs : offForMs;
|
|
9031
|
-
|
|
9032
|
-
|
|
9487
|
+
const sustained = !active || delay === 0 || minSamples <= 1 || call.pendingSamples >= minSamples;
|
|
9488
|
+
if (nowMs - call.pendingSince >= delay && sustained) return flip(call, active, call.pendingSince);
|
|
9489
|
+
if (nowMs - call.pendingSince < delay) hooks?.noteDeadline?.(call.pendingSince + delay);
|
|
9033
9490
|
return call.latched;
|
|
9034
9491
|
}
|
|
9492
|
+
function asMinSamples(value) {
|
|
9493
|
+
const n = asFiniteNumber(value, "dwell", 3);
|
|
9494
|
+
if (!Number.isInteger(n) || n < 1) throw new ExpressionEvalError("dwell: minSamples must be a whole number of at least 1");
|
|
9495
|
+
return n;
|
|
9496
|
+
}
|
|
9035
9497
|
function flip(call, to, startedAt) {
|
|
9036
9498
|
const transition = {
|
|
9037
9499
|
value: to,
|
|
@@ -9039,6 +9501,7 @@ function flip(call, to, startedAt) {
|
|
|
9039
9501
|
};
|
|
9040
9502
|
call.latched = to;
|
|
9041
9503
|
call.pendingSince = null;
|
|
9504
|
+
call.pendingSamples = 0;
|
|
9042
9505
|
call.returnSince = null;
|
|
9043
9506
|
call.transition = transition;
|
|
9044
9507
|
return to;
|
|
@@ -9291,7 +9754,7 @@ var table = {
|
|
|
9291
9754
|
},
|
|
9292
9755
|
dwell: {
|
|
9293
9756
|
minArgs: 3,
|
|
9294
|
-
maxArgs:
|
|
9757
|
+
maxArgs: 4,
|
|
9295
9758
|
apply: () => {
|
|
9296
9759
|
throw new ExpressionEvalError("dwell: stateful evaluation context is required");
|
|
9297
9760
|
}
|
|
@@ -9882,13 +10345,14 @@ function evaluateStatefulExpressionCall(invocation, memory, env, hooks) {
|
|
|
9882
10345
|
const call = existing?.kind === "dwell" ? existing : {
|
|
9883
10346
|
kind: "dwell",
|
|
9884
10347
|
pendingSince: null,
|
|
10348
|
+
pendingSamples: 0,
|
|
9885
10349
|
returnSince: null,
|
|
9886
10350
|
transition: null,
|
|
9887
10351
|
latched: typeof env.currentOutput === "boolean" ? env.currentOutput : null,
|
|
9888
10352
|
seenSince: null
|
|
9889
10353
|
};
|
|
9890
10354
|
memory.calls.set(invocation.path, call);
|
|
9891
|
-
const dwelled = evaluateDwell(invocation.args[0], invocation.args[1], invocation.args[2], call, env.nowMs, hooks);
|
|
10355
|
+
const dwelled = evaluateDwell(invocation.args[0], invocation.args[1], invocation.args[2], invocation.args[3], call, env.nowMs, hooks);
|
|
9892
10356
|
memory.dwellTransition = call.transition;
|
|
9893
10357
|
return dwelled;
|
|
9894
10358
|
}
|
|
@@ -11316,245 +11780,6 @@ var IntegrationInstanceRefSchema = zod.z.object({
|
|
|
11316
11780
|
]),
|
|
11317
11781
|
candidateStableId: zod.z.string().optional()
|
|
11318
11782
|
});
|
|
11319
|
-
function linkTargetOf(meta) {
|
|
11320
|
-
if (typeof meta !== "object" || meta === null) return void 0;
|
|
11321
|
-
const link = Reflect.get(meta, "link");
|
|
11322
|
-
const parsed = LinkTargetSchema.safeParse(link);
|
|
11323
|
-
return parsed.success ? parsed.data : void 0;
|
|
11324
|
-
}
|
|
11325
|
-
var LinkTargetSchema = zod.z.object({
|
|
11326
|
-
cap: zod.z.string().min(1),
|
|
11327
|
-
kind: zod.z.string().min(1).optional()
|
|
11328
|
-
});
|
|
11329
|
-
/** The links a kind declares, read from the meta of its body fields. */
|
|
11330
|
-
function linksOfKind(kind) {
|
|
11331
|
-
const schema = kind.schema;
|
|
11332
|
-
if (!(schema instanceof zod.z.ZodObject)) return [];
|
|
11333
|
-
const links = [];
|
|
11334
|
-
for (const [field, fieldSchema] of Object.entries(schema.shape)) {
|
|
11335
|
-
const to = linkTargetOf(zod.z.globalRegistry.get(fieldSchema));
|
|
11336
|
-
if (to !== void 0) links.push({
|
|
11337
|
-
field,
|
|
11338
|
-
to
|
|
11339
|
-
});
|
|
11340
|
-
}
|
|
11341
|
-
return links;
|
|
11342
|
-
}
|
|
11343
|
-
/**
|
|
11344
|
-
* `RecordIntegrationInstances` - the `integration-instances` provider over ONE
|
|
11345
|
-
* entry kind, so an addon that holds a connection serves it in ~30 lines.
|
|
11346
|
-
*
|
|
11347
|
-
* Every instance is one record of the addon's own kind, keyed by the
|
|
11348
|
-
* `integrations` registry id. The records door does the secret work: a field the
|
|
11349
|
-
* kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
|
|
11350
|
-
* deleting the row deletes the secret, and one row's value is never another's.
|
|
11351
|
-
*
|
|
11352
|
-
* Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
|
|
11353
|
-
* token or the view the form was given KEEP the stored secret;
|
|
11354
|
-
* `{ $secretClear: true }` clears it; any other string replaces it.
|
|
11355
|
-
*/
|
|
11356
|
-
/** The most instances one addon lists (an integrations page, not a table). */
|
|
11357
|
-
var INSTANCES_LIST_MAX = 1e3;
|
|
11358
|
-
/** The keys of the kind's secret fields that sit at the top level of the body. */
|
|
11359
|
-
function topLevelSecretKeys(paths) {
|
|
11360
|
-
return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
|
|
11361
|
-
}
|
|
11362
|
-
/** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
|
|
11363
|
-
function secretMapKeys(paths) {
|
|
11364
|
-
return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
|
|
11365
|
-
}
|
|
11366
|
-
/**
|
|
11367
|
-
* A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
|
|
11368
|
-
* view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
|
|
11369
|
-
* or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
|
|
11370
|
-
*/
|
|
11371
|
-
function secretMapPatch(value) {
|
|
11372
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
11373
|
-
const out = {};
|
|
11374
|
-
for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
|
|
11375
|
-
else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
|
|
11376
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
11377
|
-
}
|
|
11378
|
-
/** Does the kind's body schema carry an `enabled` field? */
|
|
11379
|
-
function declaresEnabled(kind) {
|
|
11380
|
-
const json = zod.z.toJSONSchema(kind.schema, {
|
|
11381
|
-
unrepresentable: "any",
|
|
11382
|
-
io: "input"
|
|
11383
|
-
});
|
|
11384
|
-
const properties = Reflect.get(json, "properties");
|
|
11385
|
-
return typeof properties === "object" && properties !== null && "enabled" in properties;
|
|
11386
|
-
}
|
|
11387
|
-
var RecordIntegrationInstances = class {
|
|
11388
|
-
records;
|
|
11389
|
-
kind;
|
|
11390
|
-
hooks;
|
|
11391
|
-
handle;
|
|
11392
|
-
secretKeys;
|
|
11393
|
-
secretMaps;
|
|
11394
|
-
nameField;
|
|
11395
|
-
/** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
|
|
11396
|
-
registryOwnsEnabled;
|
|
11397
|
-
constructor(records, kind, hooks) {
|
|
11398
|
-
this.records = records;
|
|
11399
|
-
this.kind = kind;
|
|
11400
|
-
this.hooks = hooks;
|
|
11401
|
-
this.handle = records.kind(kind);
|
|
11402
|
-
this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
|
|
11403
|
-
this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
|
|
11404
|
-
this.nameField = kind.declaration.entry?.nameField ?? "name";
|
|
11405
|
-
this.registryOwnsEnabled = hooks.description.role === "devices";
|
|
11406
|
-
if (this.registryOwnsEnabled && declaresEnabled(kind)) throw new Error(`kind "${kind.name}": the integrations registry owns the on/off switch of a role "devices" addon, so the body must not declare "enabled"`);
|
|
11407
|
-
}
|
|
11408
|
-
/**
|
|
11409
|
-
* One instance read for the addon's own runtime; null when absent. When the keychain is
|
|
11410
|
-
* locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
|
|
11411
|
-
* caller can keep what it had instead of reconfiguring with an empty secret (D49).
|
|
11412
|
-
*/
|
|
11413
|
-
async readResolved(id) {
|
|
11414
|
-
try {
|
|
11415
|
-
const record = await this.handle.getResolved(id);
|
|
11416
|
-
return record === null ? null : {
|
|
11417
|
-
id,
|
|
11418
|
-
body: record.data,
|
|
11419
|
-
enabled: record.data.enabled !== false,
|
|
11420
|
-
secrets: "resolved"
|
|
11421
|
-
};
|
|
11422
|
-
} catch (err) {
|
|
11423
|
-
if (!(err instanceof RecordSecretUnavailableError)) throw err;
|
|
11424
|
-
const stored = await this.handle.get(id);
|
|
11425
|
-
if (stored === null) return null;
|
|
11426
|
-
return {
|
|
11427
|
-
id,
|
|
11428
|
-
body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
|
|
11429
|
-
enabled: stored.data.enabled !== false,
|
|
11430
|
-
secrets: "unavailable"
|
|
11431
|
-
};
|
|
11432
|
-
}
|
|
11433
|
-
}
|
|
11434
|
-
/** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
|
|
11435
|
-
async getResolved(id) {
|
|
11436
|
-
return (await this.readResolved(id))?.body ?? null;
|
|
11437
|
-
}
|
|
11438
|
-
/** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
|
|
11439
|
-
async listResolved() {
|
|
11440
|
-
const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
|
|
11441
|
-
const out = [];
|
|
11442
|
-
for (const record of page.records) {
|
|
11443
|
-
const read = await this.readResolved(record.id);
|
|
11444
|
-
if (read !== null) out.push(read);
|
|
11445
|
-
}
|
|
11446
|
-
return out;
|
|
11447
|
-
}
|
|
11448
|
-
viewOf(record) {
|
|
11449
|
-
const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
|
|
11450
|
-
const rawName = record.data[this.nameField];
|
|
11451
|
-
const kind = this.hooks.kindOf?.(record.data);
|
|
11452
|
-
const health = this.hooks.health?.(record.data, record.id);
|
|
11453
|
-
return {
|
|
11454
|
-
id: record.id,
|
|
11455
|
-
name: typeof rawName === "string" ? rawName : record.id,
|
|
11456
|
-
configured: this.hooks.configured(record.data),
|
|
11457
|
-
...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
|
|
11458
|
-
formValues: shown,
|
|
11459
|
-
...kind !== void 0 ? { kind } : {},
|
|
11460
|
-
...health?.status !== void 0 ? { status: health.status } : {},
|
|
11461
|
-
...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
|
|
11462
|
-
};
|
|
11463
|
-
}
|
|
11464
|
-
describe = async () => {
|
|
11465
|
-
const declared = linksOfKind(this.kind);
|
|
11466
|
-
const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
|
|
11467
|
-
kind: this.kind.name,
|
|
11468
|
-
field: link.field,
|
|
11469
|
-
to: link.to
|
|
11470
|
-
})) };
|
|
11471
|
-
return {
|
|
11472
|
-
...this.hooks.description,
|
|
11473
|
-
...links,
|
|
11474
|
-
...this.hooks.mintId === void 0 ? {} : { mintsId: true }
|
|
11475
|
-
};
|
|
11476
|
-
};
|
|
11477
|
-
instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
|
|
11478
|
-
listInstances = async () => {
|
|
11479
|
-
return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
|
|
11480
|
-
};
|
|
11481
|
-
getInstance = async ({ id }) => {
|
|
11482
|
-
const record = await this.handle.get(id);
|
|
11483
|
-
return record === null ? null : this.viewOf(record);
|
|
11484
|
-
};
|
|
11485
|
-
/** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
|
|
11486
|
-
createInstance = async ({ id, name, kind, values }) => {
|
|
11487
|
-
const minted = id ?? this.hooks.mintId?.({
|
|
11488
|
-
name,
|
|
11489
|
-
...kind !== void 0 ? { kind } : {}
|
|
11490
|
-
});
|
|
11491
|
-
if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
|
|
11492
|
-
await this.handle.put({
|
|
11493
|
-
id: minted,
|
|
11494
|
-
data: this.hooks.initialBody(name, kind)
|
|
11495
|
-
}, { ifRev: 0 });
|
|
11496
|
-
const patch = this.patchOf(values ?? {});
|
|
11497
|
-
if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
|
|
11498
|
-
await this.hooks.onChanged?.(minted, "created");
|
|
11499
|
-
return { id: minted };
|
|
11500
|
-
};
|
|
11501
|
-
updateInstance = async ({ id, name, values }) => {
|
|
11502
|
-
const patch = this.patchOf(values);
|
|
11503
|
-
if (name !== void 0) patch[this.nameField] = name;
|
|
11504
|
-
await this.handle.patch(id, patch);
|
|
11505
|
-
await this.hooks.onChanged?.(id, "updated");
|
|
11506
|
-
return { ok: true };
|
|
11507
|
-
};
|
|
11508
|
-
/** The record patch a form `values` object means: secrets kept, cleared or replaced. */
|
|
11509
|
-
patchOf(values) {
|
|
11510
|
-
const patch = {};
|
|
11511
|
-
for (const [key, value] of Object.entries(values)) {
|
|
11512
|
-
if (value === void 0) continue;
|
|
11513
|
-
if (this.secretMaps.has(key)) {
|
|
11514
|
-
const entries = secretMapPatch(value);
|
|
11515
|
-
if (entries !== null) patch[key] = entries;
|
|
11516
|
-
} else if (!this.secretKeys.has(key)) patch[key] = value;
|
|
11517
|
-
else if (isSecretClear(value)) patch[key] = null;
|
|
11518
|
-
else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
|
|
11519
|
-
}
|
|
11520
|
-
return patch;
|
|
11521
|
-
}
|
|
11522
|
-
/** The switch lives in the record body; the addon is told so it applies it (D996). */
|
|
11523
|
-
setInstanceEnabled = async ({ id, enabled }) => {
|
|
11524
|
-
if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
|
|
11525
|
-
await this.handle.patch(id, { enabled });
|
|
11526
|
-
await this.hooks.onChanged?.(id, "enabled");
|
|
11527
|
-
return { ok: true };
|
|
11528
|
-
};
|
|
11529
|
-
/** The row and its keychain refs go together (the records door). */
|
|
11530
|
-
deleteInstance = async ({ id }) => {
|
|
11531
|
-
await this.handle.delete(id);
|
|
11532
|
-
await this.hooks.onChanged?.(id, "deleted");
|
|
11533
|
-
return { ok: true };
|
|
11534
|
-
};
|
|
11535
|
-
testInstance = async (input) => {
|
|
11536
|
-
if (this.hooks.test === void 0) return {
|
|
11537
|
-
success: false,
|
|
11538
|
-
status: "unsupported",
|
|
11539
|
-
error: "This integration declares no connection test"
|
|
11540
|
-
};
|
|
11541
|
-
return this.hooks.test(input);
|
|
11542
|
-
};
|
|
11543
|
-
/** The flat provider object to hand to `registerProvider`. */
|
|
11544
|
-
toProvider() {
|
|
11545
|
-
return {
|
|
11546
|
-
describe: this.describe,
|
|
11547
|
-
instanceFormSchema: this.instanceFormSchema,
|
|
11548
|
-
listInstances: this.listInstances,
|
|
11549
|
-
getInstance: this.getInstance,
|
|
11550
|
-
createInstance: this.createInstance,
|
|
11551
|
-
updateInstance: this.updateInstance,
|
|
11552
|
-
setInstanceEnabled: this.setInstanceEnabled,
|
|
11553
|
-
deleteInstance: this.deleteInstance,
|
|
11554
|
-
testInstance: this.testInstance
|
|
11555
|
-
};
|
|
11556
|
-
}
|
|
11557
|
-
};
|
|
11558
11783
|
/**
|
|
11559
11784
|
* Shared video / audio encode profile schemas used by every consumer
|
|
11560
11785
|
* that asks the stream broker to spawn a derived stream
|
|
@@ -18554,31 +18779,21 @@ var APPLIANCE_CAP_VOCABULARY = {
|
|
|
18554
18779
|
"pet-fountain": {
|
|
18555
18780
|
scope: "device",
|
|
18556
18781
|
noun: t("Pet fountain", "Fontana per animali"),
|
|
18557
|
-
actions: [
|
|
18558
|
-
|
|
18559
|
-
|
|
18560
|
-
|
|
18561
|
-
|
|
18562
|
-
|
|
18563
|
-
|
|
18564
|
-
|
|
18565
|
-
|
|
18566
|
-
|
|
18567
|
-
|
|
18568
|
-
|
|
18569
|
-
|
|
18570
|
-
|
|
18571
|
-
|
|
18572
|
-
args: { on: false }
|
|
18573
|
-
},
|
|
18574
|
-
{
|
|
18575
|
-
id: "petFountain.resetDailyConsumption",
|
|
18576
|
-
method: "resetDailyConsumption",
|
|
18577
|
-
label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
|
|
18578
|
-
phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
|
|
18579
|
-
icon: "rotate-ccw"
|
|
18580
|
-
}
|
|
18581
|
-
],
|
|
18782
|
+
actions: [{
|
|
18783
|
+
id: "petFountain.pumpOn",
|
|
18784
|
+
method: "setPump",
|
|
18785
|
+
label: t("Pump on", "Pompa accesa"),
|
|
18786
|
+
phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
|
|
18787
|
+
icon: "play",
|
|
18788
|
+
args: { on: true }
|
|
18789
|
+
}, {
|
|
18790
|
+
id: "petFountain.pumpOff",
|
|
18791
|
+
method: "setPump",
|
|
18792
|
+
label: t("Pump off", "Pompa spenta"),
|
|
18793
|
+
phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
|
|
18794
|
+
icon: "square",
|
|
18795
|
+
args: { on: false }
|
|
18796
|
+
}],
|
|
18582
18797
|
state: [{
|
|
18583
18798
|
kind: "boolean",
|
|
18584
18799
|
field: "empty",
|
|
@@ -43891,8 +44106,15 @@ var ActionInputSchema = zod.z.object({
|
|
|
43891
44106
|
var ActionRunOriginSchema = zod.z.object({
|
|
43892
44107
|
/** The automation block whose step started it. */
|
|
43893
44108
|
blockId: zod.z.string().min(1).optional() });
|
|
43894
|
-
/**
|
|
43895
|
-
|
|
44109
|
+
/**
|
|
44110
|
+
* `started` = the caller did not ask to wait. `timed-out` = the run reached the
|
|
44111
|
+
* ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
|
|
44112
|
+
*/
|
|
44113
|
+
var ActionRunOutcomeSchema = zod.z.union([
|
|
44114
|
+
AutomationRunOutcomeSchema,
|
|
44115
|
+
zod.z.literal("started"),
|
|
44116
|
+
zod.z.literal("timed-out")
|
|
44117
|
+
]);
|
|
43896
44118
|
var ActionRunResultSchema = zod.z.object({
|
|
43897
44119
|
runId: zod.z.string().min(1),
|
|
43898
44120
|
outcome: ActionRunOutcomeSchema,
|
|
@@ -44881,6 +45103,33 @@ var actionSourceCapability = {
|
|
|
44881
45103
|
}
|
|
44882
45104
|
};
|
|
44883
45105
|
/**
|
|
45106
|
+
* The longest an action run may last, and the transport bound that lets a
|
|
45107
|
+
* caller WAIT for it.
|
|
45108
|
+
*
|
|
45109
|
+
* An automation step awaits its action (`actions.run` with `wait: true`), so
|
|
45110
|
+
* the cap call stays open for the whole run. With no declared bound the call
|
|
45111
|
+
* ends at the 60 s socket default: the run carried on correctly while the
|
|
45112
|
+
* automation's trace said `UDS request timed out`, and a `single`-mode block
|
|
45113
|
+
* could start a second run over the first. The ceiling below is the one number
|
|
45114
|
+
* both ends agree on: the provider stops a run that reaches it, and the cap
|
|
45115
|
+
* method's `timeoutMs` outlives it, so the transport is never the layer that
|
|
45116
|
+
* gives up first.
|
|
45117
|
+
*/
|
|
45118
|
+
/** A run still going after this long is stopped and reported `timed-out`. */
|
|
45119
|
+
var ACTION_RUN_MAX_MS = 60 * 6e4;
|
|
45120
|
+
/** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
|
|
45121
|
+
var ACTION_RUN_TIMEOUT_MS = 363e4;
|
|
45122
|
+
/**
|
|
45123
|
+
* The time an action's `wait` steps add up to, in ms (cap steps take extra, never less).
|
|
45124
|
+
* An action step is `cap` or `wait` only (`ActionStepSchema`): steps cannot nest, so the
|
|
45125
|
+
* top-level sum is the whole sum.
|
|
45126
|
+
*/
|
|
45127
|
+
function actionWaitTotalMs(steps) {
|
|
45128
|
+
let total = 0;
|
|
45129
|
+
for (const step of steps) if (step.kind === "wait") total += step.seconds * 1e3;
|
|
45130
|
+
return total;
|
|
45131
|
+
}
|
|
45132
|
+
/**
|
|
44884
45133
|
* actions — the ONE surface for runnable actions, for the UI and for
|
|
44885
45134
|
* automations. Provided by the core-blocks builtin on the hub.
|
|
44886
45135
|
*
|
|
@@ -44898,6 +45147,12 @@ var actionSourceCapability = {
|
|
|
44898
45147
|
* An admin, and an in-process caller (an automation block), may run any action.
|
|
44899
45148
|
* Every refusal is typed (`[not-linked] …`) and logged.
|
|
44900
45149
|
*
|
|
45150
|
+
* **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
|
|
45151
|
+
* run that reaches it and answers `timed-out` (never `ran`); an action whose
|
|
45152
|
+
* `wait` steps alone add up to more is refused at create/update
|
|
45153
|
+
* (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
|
|
45154
|
+
* waited call (an automation step) is never cut by the 60 s transport default.
|
|
45155
|
+
*
|
|
44901
45156
|
* A second `run` of an action that is already running is REFUSED — traced and
|
|
44902
45157
|
* logged — never queued.
|
|
44903
45158
|
*/
|
|
@@ -44929,7 +45184,9 @@ var actionsCapability = {
|
|
|
44929
45184
|
/**
|
|
44930
45185
|
* Start an action. `wait` holds the call until the run ended (an automation
|
|
44931
45186
|
* step does); without it the call returns `started`. A non-admin names the
|
|
44932
|
-
* camera (`deviceId`) that links the action.
|
|
45187
|
+
* camera (`deviceId`) that links the action. A waited call stays open for
|
|
45188
|
+
* the whole run, so it declares `ACTION_RUN_TIMEOUT_MS` (above the ceiling
|
|
45189
|
+
* the provider enforces) instead of the 60 s transport default.
|
|
44933
45190
|
*/
|
|
44934
45191
|
run: method(zod.z.object({
|
|
44935
45192
|
actionId: zod.z.string().min(1),
|
|
@@ -44941,7 +45198,8 @@ var actionsCapability = {
|
|
|
44941
45198
|
role: "viewer",
|
|
44942
45199
|
auth: "protected",
|
|
44943
45200
|
kind: "mutation",
|
|
44944
|
-
caller: "required"
|
|
45201
|
+
caller: "required",
|
|
45202
|
+
timeoutMs: ACTION_RUN_TIMEOUT_MS
|
|
44945
45203
|
}),
|
|
44946
45204
|
stop: method(ActionIdInput, zod.z.void(), {
|
|
44947
45205
|
kind: "mutation",
|
|
@@ -51224,6 +51482,9 @@ var MediaPlayerStatusSchema = zod.z.object({
|
|
|
51224
51482
|
/** Repeat mode. Null when no repeat surface.
|
|
51225
51483
|
* Pair with `DeviceFeature.MediaPlayerRepeat`. */
|
|
51226
51484
|
repeat: MediaPlayerRepeatSchema.nullable(),
|
|
51485
|
+
/** Ms epoch when `position` was read from the device. Null when the driver
|
|
51486
|
+
* does not say; a UI that advances the position while playing counts from it. */
|
|
51487
|
+
positionUpdatedAt: zod.z.number().nullable().default(null),
|
|
51227
51488
|
/** Ms epoch when the slice was last updated. */
|
|
51228
51489
|
lastChangedAt: zod.z.number()
|
|
51229
51490
|
});
|
|
@@ -53050,7 +53311,7 @@ async function runFanOut(calls, invoke) {
|
|
|
53050
53311
|
}
|
|
53051
53312
|
/**
|
|
53052
53313
|
* Cap history catalog, projected from every `*.cap.ts` `history` block.
|
|
53053
|
-
* 43 caps with series (
|
|
53314
|
+
* 43 caps with series (79 series), 37 caps answered `'none'`.
|
|
53054
53315
|
* Field keys are `runtimeState` paths (`a.b` into fixed objects only).
|
|
53055
53316
|
*/
|
|
53056
53317
|
var HISTORY_CATALOG = {
|
|
@@ -53301,14 +53562,6 @@ var HISTORY_CATALOG = {
|
|
|
53301
53562
|
"waterVolume": {
|
|
53302
53563
|
kind: "gauge",
|
|
53303
53564
|
unit: "L"
|
|
53304
|
-
},
|
|
53305
|
-
"todayDrink": {
|
|
53306
|
-
kind: "gauge",
|
|
53307
|
-
unit: "L"
|
|
53308
|
-
},
|
|
53309
|
-
"last24hDrink": {
|
|
53310
|
-
kind: "gauge",
|
|
53311
|
-
unit: "L"
|
|
53312
53565
|
}
|
|
53313
53566
|
},
|
|
53314
53567
|
"power-meter": {
|
|
@@ -53617,8 +53870,8 @@ function overrideExpr(whenSourceTrue, unlessNative) {
|
|
|
53617
53870
|
function isIdentifier(path) {
|
|
53618
53871
|
return IDENT.test(path);
|
|
53619
53872
|
}
|
|
53620
|
-
function dwellExpr(comparison, threshold, start, stop) {
|
|
53621
|
-
return `dwell(x ${comparison === "gte" ? ">=" : "<="} ${threshold}, ${start}, ${stop})`;
|
|
53873
|
+
function dwellExpr(comparison, threshold, start, stop, minSamples = 1) {
|
|
53874
|
+
return `dwell(x ${comparison === "gte" ? ">=" : "<="} ${threshold}, ${start}, ${stop}${minSamples > 1 ? `, ${minSamples}` : ""})`;
|
|
53622
53875
|
}
|
|
53623
53876
|
function linearExpr(inner, scale, offset, clampMin, clampMax) {
|
|
53624
53877
|
const arithmetic = `${inner} * ${scale} + ${offset}`;
|
|
@@ -54636,7 +54889,9 @@ var ThresholdTransformDraftSchema = zod.z.object({
|
|
|
54636
54889
|
comparison: zod.z.enum(["gte", "lte"]),
|
|
54637
54890
|
threshold: zod.z.number(),
|
|
54638
54891
|
startDwellMs: zod.z.number().nonnegative(),
|
|
54639
|
-
stopDwellMs: zod.z.number().nonnegative()
|
|
54892
|
+
stopDwellMs: zod.z.number().nonnegative(),
|
|
54893
|
+
/** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
|
|
54894
|
+
minSamples: zod.z.number().int().min(1).optional()
|
|
54640
54895
|
});
|
|
54641
54896
|
var LinearTransformDraftSchema = zod.z.object({
|
|
54642
54897
|
kind: zod.z.literal("linear"),
|
|
@@ -62142,6 +62397,7 @@ var IntegrationWithStateSchema = zod.z.object({
|
|
|
62142
62397
|
id: zod.z.string(),
|
|
62143
62398
|
addonId: zod.z.string(),
|
|
62144
62399
|
name: zod.z.string(),
|
|
62400
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
62145
62401
|
enabled: zod.z.boolean(),
|
|
62146
62402
|
info: zod.z.record(zod.z.string(), zod.z.unknown()).readonly(),
|
|
62147
62403
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -62154,6 +62410,7 @@ var IntegrationLiteSchema = zod.z.object({
|
|
|
62154
62410
|
id: zod.z.string(),
|
|
62155
62411
|
addonId: zod.z.string(),
|
|
62156
62412
|
name: zod.z.string(),
|
|
62413
|
+
/** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
|
|
62157
62414
|
enabled: zod.z.boolean(),
|
|
62158
62415
|
info: zod.z.record(zod.z.string(), zod.z.unknown()).readonly(),
|
|
62159
62416
|
/** The discovery candidate this integration was set up from (D984). */
|
|
@@ -62253,7 +62510,6 @@ var TestConnectionResultSchema = zod.z.object({
|
|
|
62253
62510
|
var CreateIntegrationInputSchema = zod.z.object({
|
|
62254
62511
|
addonId: zod.z.string(),
|
|
62255
62512
|
name: zod.z.string(),
|
|
62256
|
-
enabled: zod.z.boolean().optional(),
|
|
62257
62513
|
info: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
62258
62514
|
/** `stableId` of the discovery candidate the form was seeded from (D984). */
|
|
62259
62515
|
originStableId: zod.z.string().optional(),
|
|
@@ -62262,6 +62518,11 @@ var CreateIntegrationInputSchema = zod.z.object({
|
|
|
62262
62518
|
var UpdateIntegrationInputSchema = zod.z.object({
|
|
62263
62519
|
id: zod.z.string(),
|
|
62264
62520
|
name: zod.z.string().optional(),
|
|
62521
|
+
/**
|
|
62522
|
+
* Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
|
|
62523
|
+
* terminal), which keeps no instance record: the registry flag is its one store. Any other
|
|
62524
|
+
* integration is switched through `integration-instances.setInstanceEnabled`.
|
|
62525
|
+
*/
|
|
62265
62526
|
enabled: zod.z.boolean().optional(),
|
|
62266
62527
|
info: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
62267
62528
|
});
|
|
@@ -62325,7 +62586,7 @@ var IntegrationInstanceIdSchema = zod.z.string().min(1);
|
|
|
62325
62586
|
var IntegrationInstanceModeSchema = zod.z.enum(["single", "multiple"]);
|
|
62326
62587
|
/**
|
|
62327
62588
|
* What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
|
|
62328
|
-
* instance is an integration that brings devices (
|
|
62589
|
+
* instance is an integration that brings devices (its record body owns the on/off switch);
|
|
62329
62590
|
* `services`: a connection configured from the addon's own function page, never listed on
|
|
62330
62591
|
* Integrations.
|
|
62331
62592
|
* It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
|
|
@@ -62442,8 +62703,8 @@ var IntegrationInstanceSchema = zod.z.object({
|
|
|
62442
62703
|
configured: zod.z.boolean(),
|
|
62443
62704
|
/**
|
|
62444
62705
|
* The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
|
|
62445
|
-
* so a row written before the field existed is on).
|
|
62446
|
-
*
|
|
62706
|
+
* so a row written before the field existed is on). The same for every role, `devices` included:
|
|
62707
|
+
* the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
|
|
62447
62708
|
*/
|
|
62448
62709
|
enabled: zod.z.boolean().optional(),
|
|
62449
62710
|
/** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
|
|
@@ -62493,7 +62754,8 @@ var integrationInstancesCapability = {
|
|
|
62493
62754
|
auth: "admin"
|
|
62494
62755
|
}),
|
|
62495
62756
|
/**
|
|
62496
|
-
* Switch ONE instance on or off
|
|
62757
|
+
* Switch ONE instance on or off, for every role; a missing record is created from the addon's
|
|
62758
|
+
* initial body. A row control, not a form field: `updateInstance.values` is the
|
|
62497
62759
|
* form patch (D62, D996). An off instance keeps its record and secrets and does no work.
|
|
62498
62760
|
*/
|
|
62499
62761
|
setInstanceEnabled: method(zod.z.object({
|
|
@@ -66577,6 +66839,8 @@ var MigrationIntegrationSchema = zod.z.object({
|
|
|
66577
66839
|
addonId: zod.z.string(),
|
|
66578
66840
|
name: zod.z.string(),
|
|
66579
66841
|
info: Rows,
|
|
66842
|
+
/** The registry's stored switch: read by the one-switch migration, nothing else. */
|
|
66843
|
+
enabled: zod.z.boolean().optional(),
|
|
66580
66844
|
originStableId: zod.z.string().optional()
|
|
66581
66845
|
});
|
|
66582
66846
|
var MigrationDeviceSchema = zod.z.object({
|
|
@@ -78700,19 +78964,32 @@ var PetFountainStatusSchema = zod.z.object({
|
|
|
78700
78964
|
empty: zod.z.boolean().nullable(),
|
|
78701
78965
|
/** True while the pump is running. Null while unknown. */
|
|
78702
78966
|
pumpRunning: zod.z.boolean().nullable(),
|
|
78703
|
-
/** Water drunk in the last drink, in litres. */
|
|
78704
|
-
lastDrink: zod.z.number().min(0).nullable().meta(readingMeta("volume")),
|
|
78705
|
-
/** Water drunk in the current hour, in litres. */
|
|
78706
|
-
currentHourDrink: zod.z.number().min(0).nullable().meta(readingMeta("volume")),
|
|
78707
|
-
/** Water drunk over the last 24 hours (rolling), in litres. */
|
|
78708
|
-
last24hDrink: zod.z.number().min(0).nullable().meta(readingMeta("volume")),
|
|
78709
|
-
/** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
|
|
78710
|
-
todayDrink: zod.z.number().min(0).nullable().meta(readingMeta("volume")),
|
|
78711
78967
|
/** Decoded fault message. Null means healthy; a non-null string is an active fault. */
|
|
78712
78968
|
error: zod.z.string().nullable(),
|
|
78713
78969
|
/** Ms epoch when the slice was last refreshed. */
|
|
78714
78970
|
lastFetchedAt: zod.z.number()
|
|
78715
78971
|
});
|
|
78972
|
+
/** The key of the `consumables` item derived from the tank. */
|
|
78973
|
+
var PET_FOUNTAIN_WATER_KEY = "water";
|
|
78974
|
+
/**
|
|
78975
|
+
* The fountain's tank as a `consumables` item: a `supply` drawn as a `tank`.
|
|
78976
|
+
* The level is the fountain's `waterLevel`; the verdict is left to whoever
|
|
78977
|
+
* reads a level (the notification centre judges a level-only supply). Only a fountain that reports no level falls back to its `empty`
|
|
78978
|
+
* flag — a measurement that failed is `null`, never 0 (D393).
|
|
78979
|
+
*/
|
|
78980
|
+
function petFountainWaterItem(status) {
|
|
78981
|
+
const verdict = status.waterLevel !== null || status.empty === null ? null : status.empty ? "empty" : "ok";
|
|
78982
|
+
return {
|
|
78983
|
+
key: PET_FOUNTAIN_WATER_KEY,
|
|
78984
|
+
label: "Water",
|
|
78985
|
+
level: status.waterLevel,
|
|
78986
|
+
status: verdict,
|
|
78987
|
+
kind: "supply",
|
|
78988
|
+
form: "tank",
|
|
78989
|
+
lastResetAt: null,
|
|
78990
|
+
resettable: false
|
|
78991
|
+
};
|
|
78992
|
+
}
|
|
78716
78993
|
var DeviceIdSchema$1 = zod.z.number().int().nonnegative();
|
|
78717
78994
|
var petFountainCapability = {
|
|
78718
78995
|
name: "pet-fountain",
|
|
@@ -78720,21 +78997,15 @@ var petFountainCapability = {
|
|
|
78720
78997
|
deviceNative: true,
|
|
78721
78998
|
mode: "singleton",
|
|
78722
78999
|
deviceTypes: [DeviceType.PetFountain],
|
|
78723
|
-
methods: {
|
|
78724
|
-
|
|
78725
|
-
|
|
78726
|
-
|
|
78727
|
-
|
|
78728
|
-
|
|
78729
|
-
|
|
78730
|
-
|
|
78731
|
-
|
|
78732
|
-
/** Clear the rolling daily consumption counters on the device. */
|
|
78733
|
-
resetDailyConsumption: method(zod.z.object({ deviceId: DeviceIdSchema$1 }), zod.z.void(), {
|
|
78734
|
-
kind: "mutation",
|
|
78735
|
-
auth: "protected"
|
|
78736
|
-
})
|
|
78737
|
-
},
|
|
79000
|
+
methods: {
|
|
79001
|
+
/** Start or stop the pump. */
|
|
79002
|
+
setPump: method(zod.z.object({
|
|
79003
|
+
deviceId: DeviceIdSchema$1,
|
|
79004
|
+
on: zod.z.boolean()
|
|
79005
|
+
}), zod.z.void(), {
|
|
79006
|
+
kind: "mutation",
|
|
79007
|
+
auth: "protected"
|
|
79008
|
+
}) },
|
|
78738
79009
|
status: {
|
|
78739
79010
|
schema: PetFountainStatusSchema,
|
|
78740
79011
|
kind: "push"
|
|
@@ -78758,14 +79029,6 @@ var petFountainCapability = {
|
|
|
78758
79029
|
waterVolume: {
|
|
78759
79030
|
kind: "gauge",
|
|
78760
79031
|
unit: "L"
|
|
78761
|
-
},
|
|
78762
|
-
todayDrink: {
|
|
78763
|
-
kind: "gauge",
|
|
78764
|
-
unit: "L"
|
|
78765
|
-
},
|
|
78766
|
-
last24hDrink: {
|
|
78767
|
-
kind: "gauge",
|
|
78768
|
-
unit: "L"
|
|
78769
79032
|
}
|
|
78770
79033
|
} }
|
|
78771
79034
|
};
|
|
@@ -93504,6 +93767,7 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
|
|
|
93504
93767
|
const call = {
|
|
93505
93768
|
kind: "dwell",
|
|
93506
93769
|
pendingSince: null,
|
|
93770
|
+
pendingSamples: 0,
|
|
93507
93771
|
returnSince: null,
|
|
93508
93772
|
latched: null,
|
|
93509
93773
|
seenSince: null,
|
|
@@ -93513,11 +93777,15 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
|
|
|
93513
93777
|
const hooks = { noteDeadline: (at) => {
|
|
93514
93778
|
deadline = deadline === null ? at : Math.min(deadline, at);
|
|
93515
93779
|
} };
|
|
93780
|
+
const timerHooks = {
|
|
93781
|
+
...hooks,
|
|
93782
|
+
timerDriven: true
|
|
93783
|
+
};
|
|
93516
93784
|
const intervals = [];
|
|
93517
93785
|
let openAt = null;
|
|
93518
|
-
const evaluate = (active, at) => {
|
|
93786
|
+
const evaluate = (active, at, timer) => {
|
|
93519
93787
|
deadline = null;
|
|
93520
|
-
const answer = evaluateDwell(active, startMs, stopMs, call, at, hooks);
|
|
93788
|
+
const answer = evaluateDwell(active, startMs, stopMs, 2, call, at, timer ? timerHooks : hooks);
|
|
93521
93789
|
if (answer === true && openAt === null) openAt = at;
|
|
93522
93790
|
if (answer !== true && openAt !== null) {
|
|
93523
93791
|
intervals.push({
|
|
@@ -93529,9 +93797,9 @@ function runDwell(segments, to, threshold, startMs, stopMs) {
|
|
|
93529
93797
|
};
|
|
93530
93798
|
segments.forEach((segment, i) => {
|
|
93531
93799
|
const active = segment.value >= threshold;
|
|
93532
|
-
evaluate(active, segment.start);
|
|
93800
|
+
evaluate(active, segment.start, false);
|
|
93533
93801
|
const next = segments[i + 1]?.start ?? to;
|
|
93534
|
-
while (deadline !== null && deadline <= next) evaluate(active, deadline);
|
|
93802
|
+
while (deadline !== null && deadline <= next) evaluate(active, deadline, true);
|
|
93535
93803
|
});
|
|
93536
93804
|
if (openAt !== null) intervals.push({
|
|
93537
93805
|
start: openAt,
|
|
@@ -93935,6 +94203,7 @@ function expressionOutcome(source, read, now, stateful) {
|
|
|
93935
94203
|
const deadlines = [];
|
|
93936
94204
|
const hooks = {
|
|
93937
94205
|
noteDeadline: (at) => deadlines.push(at),
|
|
94206
|
+
...stateful?.timerDriven === true ? { timerDriven: true } : {},
|
|
93938
94207
|
convert: (value, from, to) => tryConvertUnit(value, normalizeUnit(from) ?? from, normalizeUnit(to) ?? to) ?? null
|
|
93939
94208
|
};
|
|
93940
94209
|
const result = evaluateExpressionSource(source.expr, values, now, {
|
|
@@ -94182,7 +94451,7 @@ function compileValue$1(input) {
|
|
|
94182
94451
|
value: expression("!x", { x: read })
|
|
94183
94452
|
};
|
|
94184
94453
|
}
|
|
94185
|
-
if (transform.kind === "threshold") return thresholdValue(transform, read);
|
|
94454
|
+
if (transform.kind === "threshold") return thresholdValue(transform, read, transform.minSamples ?? evidenceSamples(input));
|
|
94186
94455
|
if (transform.kind === "linear") return linearValue$1(transform, read, input.sourceValueKind);
|
|
94187
94456
|
return fail$1("transform");
|
|
94188
94457
|
}
|
|
@@ -94190,7 +94459,17 @@ function identityValue(read, valueKind) {
|
|
|
94190
94459
|
if (valueKind === "string") return expression("number(x)", { x: read });
|
|
94191
94460
|
return read;
|
|
94192
94461
|
}
|
|
94193
|
-
|
|
94462
|
+
/**
|
|
94463
|
+
* Only a POWER reading that drives `running-state.running` asks for sample
|
|
94464
|
+
* evidence: a standby plug sends one blip and goes quiet, and the timer over
|
|
94465
|
+
* that held value must not start a run. Any other threshold (a temperature, a
|
|
94466
|
+
* level, a binary contact) confirms on time alone, as it always did.
|
|
94467
|
+
*/
|
|
94468
|
+
function evidenceSamples(input) {
|
|
94469
|
+
const { cap, targetId, source } = input.draft;
|
|
94470
|
+
return cap === "running-state" && targetId === "running" && source.cap === "power-meter" ? 2 : 1;
|
|
94471
|
+
}
|
|
94472
|
+
function thresholdValue(transform, read, minSamples) {
|
|
94194
94473
|
const threshold = unsignedToken(transform.threshold);
|
|
94195
94474
|
if (threshold === null) return fail$1("threshold");
|
|
94196
94475
|
const start = unsignedToken(transform.startDwellMs);
|
|
@@ -94198,7 +94477,7 @@ function thresholdValue(transform, read) {
|
|
|
94198
94477
|
if (start === null || stop === null) return fail$1("dwell");
|
|
94199
94478
|
return {
|
|
94200
94479
|
ok: true,
|
|
94201
|
-
value: expression(dwellExpr(transform.comparison, threshold, start, stop), { x: read })
|
|
94480
|
+
value: expression(dwellExpr(transform.comparison, threshold, start, stop, minSamples), { x: read })
|
|
94202
94481
|
};
|
|
94203
94482
|
}
|
|
94204
94483
|
function linearValue$1(transform, read, valueKind) {
|
|
@@ -101468,13 +101747,6 @@ var METHOD_ACCESS_MAP = Object.freeze({
|
|
|
101468
101747
|
access: "view",
|
|
101469
101748
|
role: "viewer"
|
|
101470
101749
|
},
|
|
101471
|
-
"petFountain.resetDailyConsumption": {
|
|
101472
|
-
capName: "pet-fountain",
|
|
101473
|
-
capScope: "device",
|
|
101474
|
-
addonId: null,
|
|
101475
|
-
access: "delete",
|
|
101476
|
-
role: "viewer"
|
|
101477
|
-
},
|
|
101478
101750
|
"petFountain.setPump": {
|
|
101479
101751
|
capName: "pet-fountain",
|
|
101480
101752
|
capScope: "device",
|
|
@@ -107961,11 +108233,6 @@ Object.freeze({
|
|
|
107961
108233
|
form: "single",
|
|
107962
108234
|
optional: false
|
|
107963
108235
|
}],
|
|
107964
|
-
"petFountain.resetDailyConsumption": [{
|
|
107965
|
-
name: "deviceId",
|
|
107966
|
-
form: "single",
|
|
107967
|
-
optional: false
|
|
107968
|
-
}],
|
|
107969
108236
|
"petFountain.setPump": [{
|
|
107970
108237
|
name: "deviceId",
|
|
107971
108238
|
form: "single",
|
|
@@ -111528,8 +111795,13 @@ zod.z.object({
|
|
|
111528
111795
|
delay: zod.z.number().nonnegative().optional(),
|
|
111529
111796
|
commands: zod.z.record(zod.z.string(), zod.z.unknown())
|
|
111530
111797
|
});
|
|
111531
|
-
entryBody({ brokerId: zod.z.string() });
|
|
111532
111798
|
//#endregion
|
|
111799
|
+
Object.defineProperty(exports, "ACTION_RUN_MAX_MS", {
|
|
111800
|
+
enumerable: true,
|
|
111801
|
+
get: function() {
|
|
111802
|
+
return ACTION_RUN_MAX_MS;
|
|
111803
|
+
}
|
|
111804
|
+
});
|
|
111533
111805
|
Object.defineProperty(exports, "ACTION_TARGET_INVALIDATION_EVENTS", {
|
|
111534
111806
|
enumerable: true,
|
|
111535
111807
|
get: function() {
|
|
@@ -111722,6 +111994,12 @@ Object.defineProperty(exports, "ConditionMirror", {
|
|
|
111722
111994
|
return ConditionMirror;
|
|
111723
111995
|
}
|
|
111724
111996
|
});
|
|
111997
|
+
Object.defineProperty(exports, "ConsumableItemSchema", {
|
|
111998
|
+
enumerable: true,
|
|
111999
|
+
get: function() {
|
|
112000
|
+
return ConsumableItemSchema;
|
|
112001
|
+
}
|
|
112002
|
+
});
|
|
111725
112003
|
Object.defineProperty(exports, "ControlStatusSchema", {
|
|
111726
112004
|
enumerable: true,
|
|
111727
112005
|
get: function() {
|
|
@@ -112166,6 +112444,12 @@ Object.defineProperty(exports, "NoCallerError", {
|
|
|
112166
112444
|
return NoCallerError;
|
|
112167
112445
|
}
|
|
112168
112446
|
});
|
|
112447
|
+
Object.defineProperty(exports, "PET_FOUNTAIN_WATER_KEY", {
|
|
112448
|
+
enumerable: true,
|
|
112449
|
+
get: function() {
|
|
112450
|
+
return PET_FOUNTAIN_WATER_KEY;
|
|
112451
|
+
}
|
|
112452
|
+
});
|
|
112169
112453
|
Object.defineProperty(exports, "PREFERENCES_MAX_VALUE_BYTES", {
|
|
112170
112454
|
enumerable: true,
|
|
112171
112455
|
get: function() {
|
|
@@ -112184,6 +112468,12 @@ Object.defineProperty(exports, "PackageRequiresSchema", {
|
|
|
112184
112468
|
return PackageRequiresSchema;
|
|
112185
112469
|
}
|
|
112186
112470
|
});
|
|
112471
|
+
Object.defineProperty(exports, "PetFountainStatusSchema", {
|
|
112472
|
+
enumerable: true,
|
|
112473
|
+
get: function() {
|
|
112474
|
+
return PetFountainStatusSchema;
|
|
112475
|
+
}
|
|
112476
|
+
});
|
|
112187
112477
|
Object.defineProperty(exports, "PlaintextSecretError", {
|
|
112188
112478
|
enumerable: true,
|
|
112189
112479
|
get: function() {
|
|
@@ -112502,6 +112792,12 @@ Object.defineProperty(exports, "actionSourceCapability", {
|
|
|
112502
112792
|
return actionSourceCapability;
|
|
112503
112793
|
}
|
|
112504
112794
|
});
|
|
112795
|
+
Object.defineProperty(exports, "actionWaitTotalMs", {
|
|
112796
|
+
enumerable: true,
|
|
112797
|
+
get: function() {
|
|
112798
|
+
return actionWaitTotalMs;
|
|
112799
|
+
}
|
|
112800
|
+
});
|
|
112505
112801
|
Object.defineProperty(exports, "actionsCapability", {
|
|
112506
112802
|
enumerable: true,
|
|
112507
112803
|
get: function() {
|
|
@@ -112820,6 +113116,12 @@ Object.defineProperty(exports, "compositionSourceRefs", {
|
|
|
112820
113116
|
return compositionSourceRefs;
|
|
112821
113117
|
}
|
|
112822
113118
|
});
|
|
113119
|
+
Object.defineProperty(exports, "consumablesCapability", {
|
|
113120
|
+
enumerable: true,
|
|
113121
|
+
get: function() {
|
|
113122
|
+
return consumablesCapability;
|
|
113123
|
+
}
|
|
113124
|
+
});
|
|
112823
113125
|
Object.defineProperty(exports, "coreBlockAddonId", {
|
|
112824
113126
|
enumerable: true,
|
|
112825
113127
|
get: function() {
|
|
@@ -113318,6 +113620,12 @@ Object.defineProperty(exports, "isHistoryHelper", {
|
|
|
113318
113620
|
return isHistoryHelper;
|
|
113319
113621
|
}
|
|
113320
113622
|
});
|
|
113623
|
+
Object.defineProperty(exports, "isInstanceEnabled", {
|
|
113624
|
+
enumerable: true,
|
|
113625
|
+
get: function() {
|
|
113626
|
+
return isInstanceEnabled;
|
|
113627
|
+
}
|
|
113628
|
+
});
|
|
113321
113629
|
Object.defineProperty(exports, "isInternalActionId", {
|
|
113322
113630
|
enumerable: true,
|
|
113323
113631
|
get: function() {
|
|
@@ -113684,6 +113992,18 @@ Object.defineProperty(exports, "parseStreamParamsFormPatch", {
|
|
|
113684
113992
|
return parseStreamParamsFormPatch;
|
|
113685
113993
|
}
|
|
113686
113994
|
});
|
|
113995
|
+
Object.defineProperty(exports, "petFountainCapability", {
|
|
113996
|
+
enumerable: true,
|
|
113997
|
+
get: function() {
|
|
113998
|
+
return petFountainCapability;
|
|
113999
|
+
}
|
|
114000
|
+
});
|
|
114001
|
+
Object.defineProperty(exports, "petFountainWaterItem", {
|
|
114002
|
+
enumerable: true,
|
|
114003
|
+
get: function() {
|
|
114004
|
+
return petFountainWaterItem;
|
|
114005
|
+
}
|
|
114006
|
+
});
|
|
113687
114007
|
Object.defineProperty(exports, "pickAppLinkHub", {
|
|
113688
114008
|
enumerable: true,
|
|
113689
114009
|
get: function() {
|