@camstack/server 1.2.809 → 1.2.811
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 +17 -0
- package/dist/api/trpc/cap-router-runtime.js +3 -0
- package/dist/api/trpc/generated-cap-mounts.js +3 -1
- package/dist/api/trpc/generated-cap-routers.js +1869 -1789
- package/dist/core/addon/hub-addon-api.js +8 -1
- package/dist/core/moleculer/moleculer.service.js +3 -0
- package/package.json +10 -8
- package/system/dist/addon-runner.js +4 -1
- package/system/dist/addon-runner.mjs +5 -2
- package/system/dist/{agent-https-DS4b0ucn.mjs → agent-https-CyEBY3RB.mjs} +1 -1
- package/system/dist/{agent-https-CuChFRA2.js → agent-https-a3mE4PW4.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 +3 -101
- package/system/dist/builtins/alerts/alerts.addon.mjs +40 -134
- 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/backup-orchestrator/destination-policy.d.ts +1 -1
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +6 -5
- package/system/dist/builtins/composer/composer.addon.mjs +6 -5
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +358 -32
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +361 -35
- package/system/dist/builtins/core-blocks/hero-layout-service.d.ts +42 -0
- package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +1 -1
- package/system/dist/builtins/core-blocks/remote-service.d.ts +38 -0
- package/system/dist/builtins/device-history/device-history.addon.d.ts +5 -0
- package/system/dist/builtins/device-history/device-history.addon.js +357 -18
- package/system/dist/builtins/device-history/device-history.addon.mjs +357 -18
- package/system/dist/builtins/device-history/retention/retention.d.ts +14 -1
- package/system/dist/builtins/device-history/transitions/device-transitions-record-kinds.d.ts +14 -0
- package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +80 -0
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +2 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +712 -18
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +780 -95
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +7 -0
- package/system/dist/builtins/device-manager/transitions/command-args.d.ts +4 -0
- package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +68 -0
- package/system/dist/builtins/device-manager/transitions/transitions-sender.d.ts +37 -0
- package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +25 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +8 -2
- package/system/dist/builtins/loki-logging/index.mjs +8 -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/location-store.d.ts +0 -6
- 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 +7 -7
- 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-Byc5Fkp0.js → capture-engine-BO9mSlY-.js} +1 -1
- package/system/dist/{capture-engine-CnVIcnyN.mjs → capture-engine-ByF-6AFH.mjs} +1 -1
- package/system/dist/{composition-sources-BhM6G9QT.mjs → composition-sources-AziMFo7T.mjs} +1 -1
- package/system/dist/{composition-sources-BxK6ttP9.js → composition-sources-BMJUPUh2.js} +1 -1
- package/system/dist/{constants-Bf1PEHRU.mjs → constants-CTikgsC_.mjs} +1 -1
- package/system/dist/{constants--xo6Q-KA.js → constants-CjRlgRlu.js} +1 -1
- package/system/dist/{device-ca-Do0-HV_h.mjs → device-ca-CNRlFqFC.mjs} +1 -1
- package/system/dist/{device-ca-Uq5KGFSq.js → device-ca-Dxl6kVcJ.js} +1 -1
- package/system/dist/{dist-CogtCQxu.mjs → dist-BPq13Y8j.mjs} +17544 -15612
- package/system/dist/{dist-2SHQaxaS.js → dist-CkJnelZr.js} +17615 -15617
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-aFHCKrif.mjs → hub-mdns-ciao-CrjItezp.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-DqPrLiYH.js → hub-mdns-ciao-Cx6yJBl9.js} +2 -2
- package/system/dist/index.js +67 -75
- package/system/dist/index.mjs +53 -68
- package/system/dist/kernel/cap-router-builder.d.ts +9 -0
- package/system/dist/kernel/command-observation.d.ts +76 -0
- package/system/dist/kernel/index.d.ts +2 -0
- package/system/dist/kernel/transport/child-cap-protocol.d.ts +10 -1
- package/system/dist/kernel/transport/local-child-registry.d.ts +15 -0
- package/system/dist/{legacy-integration-rows-door-Bz8rivxI.js → legacy-integration-rows-door-CKM-LxvL.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-CiuxDLoc.mjs → legacy-integration-rows-door-Dxcqwc-w.mjs} +1 -1
- package/system/dist/log-redactor-BhIEMaG9.js +149 -0
- package/system/dist/log-redactor-XLDrPzOi.mjs +120 -0
- package/system/dist/logging/log-redactor.d.ts +2 -0
- package/system/dist/{restore-archive-PlBC2NwT.mjs → restore-archive-BFA-hEhX.mjs} +5 -5
- package/system/dist/{restore-archive-D-3wmHDq.js → restore-archive-BQWOdGAB.js} +1 -1
- package/system/dist/{retention-BNONb5X_.js → retention-BcOSL6b9.js} +33 -2
- package/system/dist/{retention-B9l9TnGE.mjs → retention-CUOVI1p7.mjs} +33 -2
- package/system/dist/{wal-maintenance-BTR55y--.js → wal-maintenance-CiCgL4Hp.js} +0 -0
- package/system/dist/{wal-maintenance-jrhYTCn2.mjs → wal-maintenance-zJ4-ORo6.mjs} +0 -0
- package/system/package.json +7 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-
|
|
3
|
-
import { a as FIVE_MINUTES_MS, c as bucketEndOf, i as DAY_MS, l as bucketStartOf, n as RetentionJob, o as HOUR_MS, r as DepartureTracker, s as ROLLUP_GRACE_MS, t as DEFAULT_RETENTION, u as floorTo } from "../../retention-
|
|
1
|
+
import { $s as emitReadiness, Cs as RecordTooLargeError, V as DEVICE_HISTORY_ENERGY_KEY, Wc as DeviceType, Xo as BaseAddon, Y as DeviceRunSchema, Yo as wattMillisecondsToKwh, Zs as defineRecordKinds, _r as deviceRemovalHookCapability, dt as HISTORY_ITEM_CATALOG, fc as isReadingQuantity, hr as deviceHistoryCapability, ic as historyUnitFor, qc as EventCategory, rs as DeviceTransitionSchema, ss as InvalidRecordError, ut as HISTORY_CATALOG, vr as deviceRunsCapability, xn as armRemovalReconcile, xr as deviceTransitionsCapability } from "../../dist-BPq13Y8j.mjs";
|
|
2
|
+
import { a as catalogMetrics, c as DeviceDirectory, d as identityOf, f as subjectIdOf, i as capSeriesKey, l as isRealDeviceType, n as CaptureEngine, o as readPath, r as capItemSeriesKey, s as readUnit, t as CAP_KEY_PREFIX, u as SeriesRegistry } from "../../capture-engine-ByF-6AFH.mjs";
|
|
3
|
+
import { a as FIVE_MINUTES_MS, c as bucketEndOf, i as DAY_MS, l as bucketStartOf, n as RetentionJob, o as HOUR_MS, r as DepartureTracker, s as ROLLUP_GRACE_MS, t as DEFAULT_RETENTION, u as floorTo } from "../../retention-CUOVI1p7.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
//#region src/builtins/device-history/capture/point-writer.ts
|
|
6
6
|
var FLUSH_INTERVAL_MS = 1e4;
|
|
@@ -3277,6 +3277,291 @@ var DeviceRunsService = class {
|
|
|
3277
3277
|
return out;
|
|
3278
3278
|
}
|
|
3279
3279
|
};
|
|
3280
|
+
var deviceTransitionsRecordKinds = defineRecordKinds({ "device-transitions": {
|
|
3281
|
+
schema: DeviceTransitionSchema,
|
|
3282
|
+
class: "audit",
|
|
3283
|
+
database: "events",
|
|
3284
|
+
writeTrigger: "the hub kernel delivers a batch of correlated device transitions (commands matched to slice changes, or unmatched)",
|
|
3285
|
+
device: "required",
|
|
3286
|
+
at: "required",
|
|
3287
|
+
indexes: [
|
|
3288
|
+
{
|
|
3289
|
+
name: "device_cap_at",
|
|
3290
|
+
fields: [
|
|
3291
|
+
"deviceId",
|
|
3292
|
+
"capName",
|
|
3293
|
+
"at"
|
|
3294
|
+
]
|
|
3295
|
+
},
|
|
3296
|
+
{
|
|
3297
|
+
name: "device_actor_at",
|
|
3298
|
+
fields: [
|
|
3299
|
+
"deviceId",
|
|
3300
|
+
"actor.kind",
|
|
3301
|
+
"at"
|
|
3302
|
+
]
|
|
3303
|
+
},
|
|
3304
|
+
{
|
|
3305
|
+
name: "device_outcome_at",
|
|
3306
|
+
fields: [
|
|
3307
|
+
"deviceId",
|
|
3308
|
+
"outcome",
|
|
3309
|
+
"at"
|
|
3310
|
+
]
|
|
3311
|
+
},
|
|
3312
|
+
{
|
|
3313
|
+
name: "actor_at",
|
|
3314
|
+
fields: ["actor.kind", "at"]
|
|
3315
|
+
},
|
|
3316
|
+
{
|
|
3317
|
+
name: "outcome_at",
|
|
3318
|
+
fields: ["outcome", "at"]
|
|
3319
|
+
}
|
|
3320
|
+
],
|
|
3321
|
+
retention: {
|
|
3322
|
+
owner: "device-history",
|
|
3323
|
+
reason: "swept by the device-history retention pass under the transitionDays setting (default 365 days)"
|
|
3324
|
+
},
|
|
3325
|
+
deviceRemoval: "delete"
|
|
3326
|
+
} });
|
|
3327
|
+
var yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
|
|
3328
|
+
function rangeOf(window) {
|
|
3329
|
+
const range = {
|
|
3330
|
+
...window.atFrom !== void 0 ? { gte: window.atFrom } : {},
|
|
3331
|
+
...window.atTo !== void 0 ? { lt: window.atTo } : {}
|
|
3332
|
+
};
|
|
3333
|
+
return Object.keys(range).length > 0 ? { at: range } : {};
|
|
3334
|
+
}
|
|
3335
|
+
/** One equality filter per call: each is served by its own declared index. */
|
|
3336
|
+
function assertOneFilter(filters) {
|
|
3337
|
+
const named = Object.entries(filters).filter(([, value]) => value !== void 0).map(([key]) => key);
|
|
3338
|
+
if (named.length > 1) throw new Error(`filter by one of ${Object.keys(filters).join(", ")} per call (got ${named.join(" and ")})`);
|
|
3339
|
+
}
|
|
3340
|
+
function isRejectedRow(err) {
|
|
3341
|
+
return err instanceof InvalidRecordError || err instanceof RecordTooLargeError;
|
|
3342
|
+
}
|
|
3343
|
+
var TransitionsService = class {
|
|
3344
|
+
deps;
|
|
3345
|
+
handle = null;
|
|
3346
|
+
lastWriteAt = null;
|
|
3347
|
+
refused = /* @__PURE__ */ new Map();
|
|
3348
|
+
constructor(deps) {
|
|
3349
|
+
this.deps = deps;
|
|
3350
|
+
}
|
|
3351
|
+
/** Declare the kind. */
|
|
3352
|
+
async open() {
|
|
3353
|
+
await this.deps.records.declare(deviceTransitionsRecordKinds);
|
|
3354
|
+
this.handle = this.deps.records.kind(deviceTransitionsRecordKinds["device-transitions"]);
|
|
3355
|
+
}
|
|
3356
|
+
kind() {
|
|
3357
|
+
if (this.handle === null) throw new Error("the transition ledger is not open yet");
|
|
3358
|
+
return this.handle;
|
|
3359
|
+
}
|
|
3360
|
+
count(reason, by) {
|
|
3361
|
+
this.refused.set(reason, (this.refused.get(reason) ?? 0) + by);
|
|
3362
|
+
}
|
|
3363
|
+
/**
|
|
3364
|
+
* Write a batch. Only the kernel may: a forked addon is stamped by the
|
|
3365
|
+
* transport and an HTTP session's stamp is stripped, so anything but the
|
|
3366
|
+
* kernel's own id is refused, counted and logged. A storage failure throws,
|
|
3367
|
+
* so the sender keeps the batch (D49).
|
|
3368
|
+
*/
|
|
3369
|
+
async record(callerAddonId, transitions) {
|
|
3370
|
+
if (callerAddonId !== "device-manager") {
|
|
3371
|
+
this.count("not-kernel", transitions.length);
|
|
3372
|
+
this.deps.logger.warn("device-transitions: refused a batch from a caller that is not the kernel (not-kernel)", { meta: {
|
|
3373
|
+
caller: callerAddonId,
|
|
3374
|
+
rows: transitions.length
|
|
3375
|
+
} });
|
|
3376
|
+
return {
|
|
3377
|
+
written: 0,
|
|
3378
|
+
refused: transitions.map((t) => ({
|
|
3379
|
+
id: t.id,
|
|
3380
|
+
reason: "not-kernel"
|
|
3381
|
+
}))
|
|
3382
|
+
};
|
|
3383
|
+
}
|
|
3384
|
+
if (transitions.length === 0) return {
|
|
3385
|
+
written: 0,
|
|
3386
|
+
refused: []
|
|
3387
|
+
};
|
|
3388
|
+
const handle = this.kind();
|
|
3389
|
+
const puts = transitions.map((t) => ({
|
|
3390
|
+
id: t.id,
|
|
3391
|
+
deviceId: t.deviceId,
|
|
3392
|
+
at: t.at,
|
|
3393
|
+
data: t
|
|
3394
|
+
}));
|
|
3395
|
+
try {
|
|
3396
|
+
await handle.putMany(puts);
|
|
3397
|
+
this.lastWriteAt = this.deps.clock();
|
|
3398
|
+
return {
|
|
3399
|
+
written: transitions.length,
|
|
3400
|
+
refused: []
|
|
3401
|
+
};
|
|
3402
|
+
} catch (err) {
|
|
3403
|
+
if (!isRejectedRow(err)) throw err;
|
|
3404
|
+
}
|
|
3405
|
+
let written = 0;
|
|
3406
|
+
const refused = [];
|
|
3407
|
+
for (const put of puts) try {
|
|
3408
|
+
await handle.put(put);
|
|
3409
|
+
written += 1;
|
|
3410
|
+
} catch (err) {
|
|
3411
|
+
if (!isRejectedRow(err)) throw err;
|
|
3412
|
+
refused.push({
|
|
3413
|
+
id: put.id,
|
|
3414
|
+
reason: "invalid"
|
|
3415
|
+
});
|
|
3416
|
+
this.count("invalid", 1);
|
|
3417
|
+
this.deps.logger.warn("device-transitions: a transition was rejected by the ledger (invalid)", {
|
|
3418
|
+
tags: { deviceId: put.deviceId },
|
|
3419
|
+
meta: {
|
|
3420
|
+
id: put.id,
|
|
3421
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3422
|
+
}
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
if (written > 0) this.lastWriteAt = this.deps.clock();
|
|
3426
|
+
return {
|
|
3427
|
+
written,
|
|
3428
|
+
refused
|
|
3429
|
+
};
|
|
3430
|
+
}
|
|
3431
|
+
async list(input) {
|
|
3432
|
+
assertOneFilter({
|
|
3433
|
+
capName: input.capName,
|
|
3434
|
+
actorKind: input.actorKind,
|
|
3435
|
+
outcome: input.outcome
|
|
3436
|
+
});
|
|
3437
|
+
const paging = {
|
|
3438
|
+
desc: true,
|
|
3439
|
+
limit: input.limit,
|
|
3440
|
+
...input.cursor !== void 0 ? { cursor: input.cursor } : {}
|
|
3441
|
+
};
|
|
3442
|
+
const range = rangeOf(input);
|
|
3443
|
+
const handle = this.kind();
|
|
3444
|
+
const page = input.capName !== void 0 ? await handle.query({
|
|
3445
|
+
where: {
|
|
3446
|
+
deviceId: input.deviceId,
|
|
3447
|
+
capName: input.capName,
|
|
3448
|
+
...range
|
|
3449
|
+
},
|
|
3450
|
+
...paging
|
|
3451
|
+
}) : input.actorKind !== void 0 ? await handle.query({
|
|
3452
|
+
where: {
|
|
3453
|
+
deviceId: input.deviceId,
|
|
3454
|
+
"actor.kind": input.actorKind,
|
|
3455
|
+
...range
|
|
3456
|
+
},
|
|
3457
|
+
...paging
|
|
3458
|
+
}) : input.outcome !== void 0 ? await handle.query({
|
|
3459
|
+
where: {
|
|
3460
|
+
deviceId: input.deviceId,
|
|
3461
|
+
outcome: input.outcome,
|
|
3462
|
+
...range
|
|
3463
|
+
},
|
|
3464
|
+
...paging
|
|
3465
|
+
}) : await handle.query({
|
|
3466
|
+
deviceId: input.deviceId,
|
|
3467
|
+
...input.atFrom !== void 0 ? { atFrom: input.atFrom } : {},
|
|
3468
|
+
...input.atTo !== void 0 ? { atTo: input.atTo } : {},
|
|
3469
|
+
...paging
|
|
3470
|
+
});
|
|
3471
|
+
return {
|
|
3472
|
+
transitions: page.records.map((row) => row.data),
|
|
3473
|
+
nextCursor: page.nextCursor
|
|
3474
|
+
};
|
|
3475
|
+
}
|
|
3476
|
+
async listRecent(input) {
|
|
3477
|
+
assertOneFilter({
|
|
3478
|
+
actorKind: input.actorKind,
|
|
3479
|
+
outcome: input.outcome
|
|
3480
|
+
});
|
|
3481
|
+
const paging = {
|
|
3482
|
+
desc: true,
|
|
3483
|
+
limit: input.limit,
|
|
3484
|
+
...input.cursor !== void 0 ? { cursor: input.cursor } : {}
|
|
3485
|
+
};
|
|
3486
|
+
const range = rangeOf(input);
|
|
3487
|
+
const handle = this.kind();
|
|
3488
|
+
const where = input.actorKind !== void 0 ? {
|
|
3489
|
+
"actor.kind": input.actorKind,
|
|
3490
|
+
...range
|
|
3491
|
+
} : input.outcome !== void 0 ? {
|
|
3492
|
+
outcome: input.outcome,
|
|
3493
|
+
...range
|
|
3494
|
+
} : null;
|
|
3495
|
+
const page = where !== null ? await handle.query({
|
|
3496
|
+
where,
|
|
3497
|
+
...paging
|
|
3498
|
+
}) : await handle.query({
|
|
3499
|
+
...input.atFrom !== void 0 ? { atFrom: input.atFrom } : {},
|
|
3500
|
+
...input.atTo !== void 0 ? { atTo: input.atTo } : {},
|
|
3501
|
+
...paging
|
|
3502
|
+
});
|
|
3503
|
+
return {
|
|
3504
|
+
transitions: page.records.map((row) => row.data),
|
|
3505
|
+
nextCursor: page.nextCursor
|
|
3506
|
+
};
|
|
3507
|
+
}
|
|
3508
|
+
async get(input) {
|
|
3509
|
+
const row = await this.kind().get(input.id);
|
|
3510
|
+
return row !== null && row.data.deviceId === input.deviceId ? row.data : null;
|
|
3511
|
+
}
|
|
3512
|
+
async status() {
|
|
3513
|
+
let rows = null;
|
|
3514
|
+
try {
|
|
3515
|
+
rows = await this.kind().count({});
|
|
3516
|
+
} catch (err) {
|
|
3517
|
+
this.deps.logger.warn("device-transitions: the row count failed - reported as unknown", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
3518
|
+
}
|
|
3519
|
+
return {
|
|
3520
|
+
rows,
|
|
3521
|
+
lastWriteAt: this.lastWriteAt,
|
|
3522
|
+
refused: Object.fromEntries(this.refused)
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* Delete every row older than `cutoff` (a row AT the cutoff is kept), in
|
|
3527
|
+
* day-wide slices from the oldest row, yielding between them. Answers the
|
|
3528
|
+
* rows deleted.
|
|
3529
|
+
*/
|
|
3530
|
+
async sweep(cutoff) {
|
|
3531
|
+
const handle = this.kind();
|
|
3532
|
+
const first = (await handle.query({
|
|
3533
|
+
desc: false,
|
|
3534
|
+
limit: 1
|
|
3535
|
+
})).records[0]?.at;
|
|
3536
|
+
if (first === void 0 || first === null || first >= cutoff) return 0;
|
|
3537
|
+
const yieldNow = this.deps.yieldNow ?? yieldToEventLoop;
|
|
3538
|
+
let deleted = 0;
|
|
3539
|
+
for (let lo = first; lo < cutoff; lo += DAY_MS) {
|
|
3540
|
+
deleted += await handle.deleteWhere({ atBefore: Math.min(lo + DAY_MS, cutoff) });
|
|
3541
|
+
await yieldNow();
|
|
3542
|
+
}
|
|
3543
|
+
return deleted;
|
|
3544
|
+
}
|
|
3545
|
+
/** The D865 hook body: how many transition rows the removal deleted. */
|
|
3546
|
+
async removeDevice(deviceId) {
|
|
3547
|
+
return (await this.deps.records.deleteDevice(deviceId, { kinds: ["device-transitions"] }))["device-transitions"] ?? 0;
|
|
3548
|
+
}
|
|
3549
|
+
/** Rows per device, for the admin clean-up listing. */
|
|
3550
|
+
async countByDevice() {
|
|
3551
|
+
const handle = this.handle;
|
|
3552
|
+
if (handle === null) return [];
|
|
3553
|
+
const rows = await handle.aggregate({
|
|
3554
|
+
op: "count",
|
|
3555
|
+
groupBy: "deviceId"
|
|
3556
|
+
});
|
|
3557
|
+
const out = [];
|
|
3558
|
+
for (const row of rows) if (typeof row.group === "number" && row.value !== null) out.push({
|
|
3559
|
+
deviceId: row.group,
|
|
3560
|
+
count: row.value
|
|
3561
|
+
});
|
|
3562
|
+
return out;
|
|
3563
|
+
}
|
|
3564
|
+
};
|
|
3280
3565
|
//#endregion
|
|
3281
3566
|
//#region src/builtins/device-history/device-history.addon.ts
|
|
3282
3567
|
/**
|
|
@@ -3304,7 +3589,8 @@ var DEFAULT_CONFIG = {
|
|
|
3304
3589
|
rawDays: DEFAULT_RETENTION.rawDays,
|
|
3305
3590
|
fiveMinuteDays: DEFAULT_RETENTION.fiveMinuteDays,
|
|
3306
3591
|
hourDays: DEFAULT_RETENTION.hourDays,
|
|
3307
|
-
dayDays: 0
|
|
3592
|
+
dayDays: 0,
|
|
3593
|
+
transitionDays: DEFAULT_RETENTION.transitionDays
|
|
3308
3594
|
};
|
|
3309
3595
|
function isRecord(value) {
|
|
3310
3596
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -3324,6 +3610,7 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3324
3610
|
removalHook = null;
|
|
3325
3611
|
runsProvider = null;
|
|
3326
3612
|
runs = null;
|
|
3613
|
+
transitions = null;
|
|
3327
3614
|
/** This instance's readiness generation (the base class keeps its own private). */
|
|
3328
3615
|
readinessGeneration = `device-history-${Date.now().toString(36)}`;
|
|
3329
3616
|
constructor() {
|
|
@@ -3342,6 +3629,7 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3342
3629
|
for (const capName of [
|
|
3343
3630
|
deviceHistoryCapability.name,
|
|
3344
3631
|
deviceRunsCapability.name,
|
|
3632
|
+
deviceTransitionsCapability.name,
|
|
3345
3633
|
deviceRemovalHookCapability.name
|
|
3346
3634
|
]) try {
|
|
3347
3635
|
emitReadiness(ctx.eventBus, {
|
|
@@ -3368,7 +3656,8 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3368
3656
|
rawDays: positiveOr(c.rawDays, DEFAULT_RETENTION.rawDays),
|
|
3369
3657
|
fiveMinuteDays: positiveOr(c.fiveMinuteDays, DEFAULT_RETENTION.fiveMinuteDays),
|
|
3370
3658
|
hourDays: positiveOr(c.hourDays, DEFAULT_RETENTION.hourDays),
|
|
3371
|
-
dayDays: positiveOr(c.dayDays, 0) > 0 ? c.dayDays : null
|
|
3659
|
+
dayDays: positiveOr(c.dayDays, 0) > 0 ? c.dayDays : null,
|
|
3660
|
+
transitionDays: positiveOr(c.transitionDays, DEFAULT_RETENTION.transitionDays)
|
|
3372
3661
|
};
|
|
3373
3662
|
}
|
|
3374
3663
|
/** Unraid array counters still stored in GiB. A failed listing throws to the caller. */
|
|
@@ -3392,6 +3681,10 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3392
3681
|
if (this.runsProvider === null) throw new Error("device-runs is starting — the run ledger is not open yet");
|
|
3393
3682
|
return this.runsProvider;
|
|
3394
3683
|
}
|
|
3684
|
+
requireTransitions() {
|
|
3685
|
+
if (this.transitions === null) throw new Error("device-transitions is starting — the transition ledger is not open yet");
|
|
3686
|
+
return this.transitions;
|
|
3687
|
+
}
|
|
3395
3688
|
async onInitialize() {
|
|
3396
3689
|
const provider = {
|
|
3397
3690
|
listSeries: async (input) => this.requireRuntime().query.listSeries({
|
|
@@ -3431,36 +3724,54 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3431
3724
|
getRun: async (input) => this.requireRuns().getRun(input),
|
|
3432
3725
|
getCurrentRun: async (input) => this.requireRuns().getCurrentRun(input)
|
|
3433
3726
|
};
|
|
3727
|
+
const transitionsFacade = {
|
|
3728
|
+
listTransitions: async (input) => this.requireTransitions().list(input),
|
|
3729
|
+
getTransition: async (input) => this.requireTransitions().get(input),
|
|
3730
|
+
listRecentTransitions: async (input) => this.requireTransitions().listRecent(input),
|
|
3731
|
+
record: async (input) => this.requireTransitions().record(callerOf(input), input.transitions),
|
|
3732
|
+
getStatus: async () => this.requireTransitions().status()
|
|
3733
|
+
};
|
|
3434
3734
|
this.emitStoreReadiness("starting");
|
|
3435
3735
|
this.ctx.logger.info("Initialized — device-history provider registered (store opens on hub link)");
|
|
3436
3736
|
const removalHook = {
|
|
3437
3737
|
onDeviceRemoved: async (input) => {
|
|
3438
3738
|
const { series } = await this.requireRuntime().removeDevice(input.deviceId);
|
|
3439
3739
|
const deviceRuns = await this.runs?.removeDevice(input.deviceId) ?? 0;
|
|
3440
|
-
|
|
3740
|
+
const deviceTransitions = await this.transitions?.removeDevice(input.deviceId) ?? 0;
|
|
3741
|
+
if (series > 0 || deviceRuns > 0 || deviceTransitions > 0) this.ctx.logger.info("device-history: removed the history of a deleted device", {
|
|
3441
3742
|
tags: { deviceId: input.deviceId },
|
|
3442
3743
|
meta: {
|
|
3443
3744
|
counts: {
|
|
3444
3745
|
series,
|
|
3445
|
-
deviceRuns
|
|
3746
|
+
deviceRuns,
|
|
3747
|
+
deviceTransitions
|
|
3446
3748
|
},
|
|
3447
3749
|
deletedAt: input.deletedAt
|
|
3448
3750
|
}
|
|
3449
3751
|
});
|
|
3450
3752
|
return { counts: {
|
|
3451
3753
|
series,
|
|
3452
|
-
deviceRuns
|
|
3754
|
+
deviceRuns,
|
|
3755
|
+
deviceTransitions
|
|
3453
3756
|
} };
|
|
3454
3757
|
},
|
|
3455
|
-
listDeviceData: async () => [
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
deviceId,
|
|
3462
|
-
|
|
3463
|
-
|
|
3758
|
+
listDeviceData: async () => [
|
|
3759
|
+
...[...this.requireRuntime().seriesByDevice()].map(([deviceId, count]) => ({
|
|
3760
|
+
store: "series",
|
|
3761
|
+
deviceId,
|
|
3762
|
+
count
|
|
3763
|
+
})),
|
|
3764
|
+
...(await this.runs?.countByDevice() ?? []).map(({ deviceId, count }) => ({
|
|
3765
|
+
store: "runs",
|
|
3766
|
+
deviceId,
|
|
3767
|
+
count
|
|
3768
|
+
})),
|
|
3769
|
+
...(await this.transitions?.countByDevice() ?? []).map(({ deviceId, count }) => ({
|
|
3770
|
+
store: "transitions",
|
|
3771
|
+
deviceId,
|
|
3772
|
+
count
|
|
3773
|
+
}))
|
|
3774
|
+
]
|
|
3464
3775
|
};
|
|
3465
3776
|
this.removalHook = removalHook;
|
|
3466
3777
|
return [
|
|
@@ -3472,6 +3783,10 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3472
3783
|
capability: deviceRunsCapability,
|
|
3473
3784
|
provider: runsFacade
|
|
3474
3785
|
},
|
|
3786
|
+
{
|
|
3787
|
+
capability: deviceTransitionsCapability,
|
|
3788
|
+
provider: transitionsFacade
|
|
3789
|
+
},
|
|
3475
3790
|
{
|
|
3476
3791
|
capability: deviceRemovalHookCapability,
|
|
3477
3792
|
provider: removalHook
|
|
@@ -3518,6 +3833,9 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3518
3833
|
const runsOpened = await runs.open();
|
|
3519
3834
|
this.runsProvider = runsOpened.provider;
|
|
3520
3835
|
this.runs = runs;
|
|
3836
|
+
const transitions = await this.openTransitions();
|
|
3837
|
+
this.transitions = transitions;
|
|
3838
|
+
runtime.retentionJob.attachTransitions(transitions);
|
|
3521
3839
|
this.unsubscribe = this.ctx.eventBus.subscribe({ category: EventCategory.DeviceStateChanged }, (event) => {
|
|
3522
3840
|
const data = event.data;
|
|
3523
3841
|
if (!isRecord(data)) return;
|
|
@@ -3571,6 +3889,18 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3571
3889
|
clock: () => Date.now()
|
|
3572
3890
|
});
|
|
3573
3891
|
}
|
|
3892
|
+
async openTransitions() {
|
|
3893
|
+
const { ctx } = this;
|
|
3894
|
+
const records = ctx.records;
|
|
3895
|
+
if (records === void 0) throw new Error("device-history needs ctx.records on the hub for the transition ledger");
|
|
3896
|
+
const transitions = new TransitionsService({
|
|
3897
|
+
records,
|
|
3898
|
+
logger: ctx.logger,
|
|
3899
|
+
clock: () => Date.now()
|
|
3900
|
+
});
|
|
3901
|
+
await transitions.open();
|
|
3902
|
+
return transitions;
|
|
3903
|
+
}
|
|
3574
3904
|
async stopRuntime() {
|
|
3575
3905
|
this.unsubscribe?.();
|
|
3576
3906
|
this.unsubscribe = null;
|
|
@@ -3583,6 +3913,7 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3583
3913
|
this.runtime = null;
|
|
3584
3914
|
this.runs = null;
|
|
3585
3915
|
this.runsProvider = null;
|
|
3916
|
+
this.transitions = null;
|
|
3586
3917
|
}
|
|
3587
3918
|
scopedSettingsCapabilities() {
|
|
3588
3919
|
return ["device-history"];
|
|
@@ -3592,7 +3923,7 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3592
3923
|
return this.schema({ sections: [{
|
|
3593
3924
|
id: "retention",
|
|
3594
3925
|
title: "Retention",
|
|
3595
|
-
description: "How long each tier is kept. The raw points feed the 5-minute rollup; the 1-day tier is kept forever unless a number of days is set.",
|
|
3926
|
+
description: "How long each tier is kept. The raw points feed the 5-minute rollup; the 1-day tier is kept forever unless a number of days is set. Device transitions (who changed what) are kept for their own number of days.",
|
|
3596
3927
|
columns: 2,
|
|
3597
3928
|
fields: [
|
|
3598
3929
|
{
|
|
@@ -3626,6 +3957,14 @@ var DeviceHistoryAddon = class extends BaseAddon {
|
|
|
3626
3957
|
min: 0,
|
|
3627
3958
|
max: 36500,
|
|
3628
3959
|
step: 1
|
|
3960
|
+
},
|
|
3961
|
+
{
|
|
3962
|
+
type: "number",
|
|
3963
|
+
key: "transitionDays",
|
|
3964
|
+
label: "Device transitions (days)",
|
|
3965
|
+
min: 7,
|
|
3966
|
+
max: 3650,
|
|
3967
|
+
step: 1
|
|
3629
3968
|
}
|
|
3630
3969
|
]
|
|
3631
3970
|
}] });
|
|
@@ -30,8 +30,17 @@ export interface RetentionPolicy {
|
|
|
30
30
|
readonly hourDays: number;
|
|
31
31
|
/** `null` (or 0) keeps the daily tier forever. */
|
|
32
32
|
readonly dayDays: number | null;
|
|
33
|
+
/** Days a device transition (D1022) is kept; the same pass sweeps the ledger. */
|
|
34
|
+
readonly transitionDays: number;
|
|
33
35
|
}
|
|
34
36
|
export declare const DEFAULT_RETENTION: RetentionPolicy;
|
|
37
|
+
/** Rows of the transition ledger strictly older than this are deleted; the row AT it is kept. */
|
|
38
|
+
export declare function transitionCutoff(policy: RetentionPolicy, now: number): number;
|
|
39
|
+
/** What the retention pass needs of the transition ledger. */
|
|
40
|
+
export interface TransitionSweeper {
|
|
41
|
+
/** Delete every row older than `cutoff`; answers the rows deleted. */
|
|
42
|
+
sweep(cutoff: number): Promise<number>;
|
|
43
|
+
}
|
|
35
44
|
/** Cutoff per tier: rows strictly older are deleted. `null` = keep forever. */
|
|
36
45
|
export declare function retentionCutoffs(policy: RetentionPolicy, now: number): Readonly<Record<StoredTier, number | null>>;
|
|
37
46
|
export interface RetentionDeps {
|
|
@@ -47,10 +56,14 @@ export declare class RetentionJob {
|
|
|
47
56
|
private readonly deps;
|
|
48
57
|
private readonly appliedUpTo;
|
|
49
58
|
private running;
|
|
59
|
+
private transitions;
|
|
50
60
|
constructor(deps: RetentionDeps);
|
|
61
|
+
/** The ledger opens after the history runtime does; the pass sweeps it from then on. */
|
|
62
|
+
attachTransitions(sweeper: TransitionSweeper): void;
|
|
51
63
|
run(policy: RetentionPolicy, now: number): Promise<void>;
|
|
52
64
|
private doRun;
|
|
53
|
-
/**
|
|
65
|
+
/** The fifth step: the transition ledger, under its own failure so the tiers never wait on it. */
|
|
66
|
+
private sweepTransitions;
|
|
54
67
|
/** Drop the visit markers of a purged series. */
|
|
55
68
|
forgetSeries(seriesId: number): void;
|
|
56
69
|
private deleteSliced;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The record kind of the transition ledger (D1022). Declared by the
|
|
3
|
+
* device-history addon (owner stamp `device-history`) in the `events` file:
|
|
4
|
+
* one row per recorded transition, swept by the device-history retention pass
|
|
5
|
+
* under the `transitionDays` setting - the engine does nothing on its own.
|
|
6
|
+
*
|
|
7
|
+
* Kept in a module with no side effects: the records guards import it.
|
|
8
|
+
*/
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import { DeviceTransitionSchema, type DefinedRecordKind } from "@camstack/types";
|
|
11
|
+
export type DeviceTransitionsRecordKindsMap = {
|
|
12
|
+
readonly "device-transitions": DefinedRecordKind<z.ZodType<z.infer<typeof DeviceTransitionSchema>>>;
|
|
13
|
+
};
|
|
14
|
+
export declare const deviceTransitionsRecordKinds: DeviceTransitionsRecordKindsMap;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transition ledger as the device-history addon sees it (D1022): the
|
|
3
|
+
* declared kind, the kernel-only writer, the paged reads, the retention sweep
|
|
4
|
+
* and the device-removal hook body (D865).
|
|
5
|
+
*
|
|
6
|
+
* Reads go to the store: an answered empty page is "no transitions". The
|
|
7
|
+
* ledger is not a second copy of any device fact - the hub mirror stays the
|
|
8
|
+
* one authority, and nothing here is read back to decide a device's state.
|
|
9
|
+
*/
|
|
10
|
+
import { type DeviceTransition, type IScopedLogger, type RecordsAccess, type TransitionActorKind, type TransitionOutcome, type TransitionRecordResult, type TransitionsStatus } from "@camstack/types";
|
|
11
|
+
/** The only caller `record` accepts: the hub kernel's device-manager states its own id. */
|
|
12
|
+
export declare const KERNEL_CALLER = "device-manager";
|
|
13
|
+
export interface TransitionsServiceDeps {
|
|
14
|
+
readonly records: RecordsAccess;
|
|
15
|
+
readonly logger: IScopedLogger;
|
|
16
|
+
readonly clock: () => number;
|
|
17
|
+
/** Gives the thread back between delete slices; a spec counts it. */
|
|
18
|
+
readonly yieldNow?: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
interface Window {
|
|
21
|
+
readonly atFrom?: number | undefined;
|
|
22
|
+
readonly atTo?: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface ListTransitionsInput extends Window {
|
|
25
|
+
readonly deviceId: number;
|
|
26
|
+
readonly capName?: string | undefined;
|
|
27
|
+
readonly actorKind?: TransitionActorKind | undefined;
|
|
28
|
+
readonly outcome?: TransitionOutcome | undefined;
|
|
29
|
+
readonly limit: number;
|
|
30
|
+
readonly cursor?: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface ListRecentInput extends Window {
|
|
33
|
+
readonly actorKind?: TransitionActorKind | undefined;
|
|
34
|
+
readonly outcome?: TransitionOutcome | undefined;
|
|
35
|
+
readonly limit: number;
|
|
36
|
+
readonly cursor?: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
export interface TransitionPage {
|
|
39
|
+
readonly transitions: readonly DeviceTransition[];
|
|
40
|
+
readonly nextCursor: string | null;
|
|
41
|
+
}
|
|
42
|
+
export declare class TransitionsService {
|
|
43
|
+
private readonly deps;
|
|
44
|
+
private handle;
|
|
45
|
+
private lastWriteAt;
|
|
46
|
+
private readonly refused;
|
|
47
|
+
constructor(deps: TransitionsServiceDeps);
|
|
48
|
+
/** Declare the kind. */
|
|
49
|
+
open(): Promise<void>;
|
|
50
|
+
private kind;
|
|
51
|
+
private count;
|
|
52
|
+
/**
|
|
53
|
+
* Write a batch. Only the kernel may: a forked addon is stamped by the
|
|
54
|
+
* transport and an HTTP session's stamp is stripped, so anything but the
|
|
55
|
+
* kernel's own id is refused, counted and logged. A storage failure throws,
|
|
56
|
+
* so the sender keeps the batch (D49).
|
|
57
|
+
*/
|
|
58
|
+
record(callerAddonId: string | null, transitions: readonly DeviceTransition[]): Promise<TransitionRecordResult>;
|
|
59
|
+
list(input: ListTransitionsInput): Promise<TransitionPage>;
|
|
60
|
+
listRecent(input: ListRecentInput): Promise<TransitionPage>;
|
|
61
|
+
get(input: {
|
|
62
|
+
readonly deviceId: number;
|
|
63
|
+
readonly id: string;
|
|
64
|
+
}): Promise<DeviceTransition | null>;
|
|
65
|
+
status(): Promise<TransitionsStatus>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete every row older than `cutoff` (a row AT the cutoff is kept), in
|
|
68
|
+
* day-wide slices from the oldest row, yielding between them. Answers the
|
|
69
|
+
* rows deleted.
|
|
70
|
+
*/
|
|
71
|
+
sweep(cutoff: number): Promise<number>;
|
|
72
|
+
/** The D865 hook body: how many transition rows the removal deleted. */
|
|
73
|
+
removeDevice(deviceId: number): Promise<number>;
|
|
74
|
+
/** Rows per device, for the admin clean-up listing. */
|
|
75
|
+
countByDevice(): Promise<readonly {
|
|
76
|
+
deviceId: number;
|
|
77
|
+
count: number;
|
|
78
|
+
}[]>;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
@@ -56,6 +56,8 @@ export declare class DeviceManagerAddon extends BaseAddon {
|
|
|
56
56
|
* `ctx`); `null` before initialise / when `ctx.settings` is absent.
|
|
57
57
|
*/
|
|
58
58
|
private stateMirrorImpl;
|
|
59
|
+
/** The transition audit (D1022): command + mirror correlation, shipped to device-history. */
|
|
60
|
+
private transitions;
|
|
59
61
|
/**
|
|
60
62
|
* Removes the claimed-status overlay this addon installed on the capability
|
|
61
63
|
* registry (D663, S3): `getStatus` of a claimed cap answers the mirror for
|