@camstack/server 1.2.792 → 1.2.793
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 +6 -0
- package/dist/api/trpc/generated-cap-routers.js +0 -43
- package/package.json +9 -14
- package/system/dist/{agent-https-BmVaVskH.mjs → agent-https-LDtzwOC3.mjs} +1 -1
- package/system/dist/{agent-https-DOs15BCJ.js → agent-https-dPSUE1iZ.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/addon.d.ts +27 -31
- package/system/dist/builtins/camera-grid/grid-instances.d.ts +18 -0
- package/system/dist/builtins/camera-grid/grid-record-kinds.d.ts +31 -0
- package/system/dist/builtins/camera-grid/index.d.ts +2 -2
- package/system/dist/builtins/camera-grid/index.js +386 -146
- package/system/dist/builtins/camera-grid/index.mjs +382 -146
- package/system/dist/builtins/camera-grid/migrations/__fixtures__/seed.d.ts +13 -0
- package/system/dist/builtins/camera-grid/migrations/camera-grids-to-records.d.ts +26 -0
- package/system/dist/builtins/camera-grid/migrations/index.d.ts +6 -0
- package/system/dist/builtins/composer/composer.addon.js +3 -3
- package/system/dist/builtins/composer/composer.addon.mjs +3 -3
- 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.js +3 -3
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
- 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 +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- 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 +284 -284
- 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-BVpkq9Mv.js → capture-engine-B-X0ZNPG.js} +1 -1
- package/system/dist/{capture-engine-D-oUDtX5.mjs → capture-engine-ek8d0K7v.mjs} +1 -1
- package/system/dist/{composition-sources-DKCbVA67.js → composition-sources-DGKK9sGT.js} +1 -1
- package/system/dist/{composition-sources-Br7JhpbD.mjs → composition-sources-Dr69aWyC.mjs} +1 -1
- package/system/dist/{constants-Bl0Qxbek.mjs → constants-CAlOFVXO.mjs} +1 -1
- package/system/dist/{constants-CJVY-mUq.js → constants-DuVFATnX.js} +1 -1
- package/system/dist/{device-ca-i8EbKp3q.js → device-ca-CJyaKA2l.js} +1 -1
- package/system/dist/{device-ca-BeDGy8NK.mjs → device-ca-FfLv_YPi.mjs} +1 -1
- package/system/dist/{dist-Ddkk4Dqq.js → dist-CJoLQeEj.js} +1 -76
- package/system/dist/{dist-CPUbgRkb.mjs → dist-Dgkqkron.mjs} +1 -76
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-DgF4SifE.mjs → hub-mdns-ciao-Bczd9NSt.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-lHRHbXqV.js → hub-mdns-ciao-q3IAAxK6.js} +2 -2
- package/system/dist/index.js +8 -20
- package/system/dist/index.mjs +8 -20
- package/system/dist/{legacy-integration-rows-door-9JSt493H.mjs → legacy-integration-rows-door-CTCq-5la.mjs} +1 -1
- package/system/dist/{legacy-integration-rows-door-n9GIUxgq.js → legacy-integration-rows-door-CfpoIqz-.js} +1 -1
- package/system/dist/{restore-archive-DWS1l6ac.mjs → restore-archive-DR05cy7P.mjs} +82 -82
- package/system/dist/{restore-archive-BDvLSZtj.js → restore-archive-HS5O901O.js} +1 -1
- package/system/dist/{wal-maintenance-BQJAmAwS.mjs → wal-maintenance-D5xF2jrM.mjs} +0 -0
- package/system/dist/{wal-maintenance-CWlz_qRq.js → wal-maintenance-DHtTtKh4.js} +0 -0
- package/system/package.json +4 -1
- package/system/dist/builtins/camera-grid/grid-row-normalization.d.ts +0 -10
|
@@ -3,8 +3,9 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
require("../../chunk-Cek0wNdY.js");
|
|
6
|
-
const require_dist = require("../../dist-
|
|
6
|
+
const require_dist = require("../../dist-CJoLQeEj.js");
|
|
7
7
|
let zod = require("zod");
|
|
8
|
+
let node_crypto = require("node:crypto");
|
|
8
9
|
let _camstack_types_node = require("@camstack/types/node");
|
|
9
10
|
let node_fs = require("node:fs");
|
|
10
11
|
let node_path = require("node:path");
|
|
@@ -367,66 +368,282 @@ function gridPlanFor(instance, encode) {
|
|
|
367
368
|
};
|
|
368
369
|
}
|
|
369
370
|
//#endregion
|
|
370
|
-
//#region src/builtins/camera-grid/grid-
|
|
371
|
+
//#region src/builtins/camera-grid/grid-record-kinds.ts
|
|
371
372
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* cannot parse so one bad row can never make the declaration reconcile
|
|
381
|
-
* destructive. A freshly typed name is exactly such a row, so without this step
|
|
382
|
-
* a new grid would be silently discarded at the moment of creation.
|
|
373
|
+
* A camera grid as a record (D1013): one `camera-grid` row per grid, owned by the `camera-grid`
|
|
374
|
+
* builtin, listed and edited through `integration-instances` on the Camera grids page. The layout
|
|
375
|
+
* (cells, frame rate, published profiles) is authored in the camera's own device details and
|
|
376
|
+
* saved onto the same record.
|
|
377
|
+
*
|
|
378
|
+
* The record id IS the grid id the old settings list carried (a uuid), so the camera
|
|
379
|
+
* `camera-grid-<id>` and everything that names it keeps its stable identity. `cameraStableId` is
|
|
380
|
+
* stored only where it is not derivable from the id.
|
|
383
381
|
*/
|
|
384
|
-
/**
|
|
385
|
-
var
|
|
386
|
-
|
|
382
|
+
/** Checked against the interface by its annotation: a drifted field fails the typecheck. */
|
|
383
|
+
var GridBodySchema = zod.z.object({
|
|
384
|
+
name: zod.z.string().min(1).max(160),
|
|
385
|
+
cameraStableId: zod.z.string().min(1).max(256).optional(),
|
|
386
|
+
fps: zod.z.number().int().min(1).max(60),
|
|
387
|
+
publishedProfiles: zod.z.array(zod.z.enum([
|
|
388
|
+
"high",
|
|
389
|
+
"mid",
|
|
390
|
+
"low"
|
|
391
|
+
])).max(3),
|
|
392
|
+
cells: zod.z.array(GridCellSchema).max(16),
|
|
393
|
+
enabled: zod.z.boolean().optional()
|
|
394
|
+
});
|
|
395
|
+
var CAMERA_GRID_KIND_NAME = "camera-grid";
|
|
396
|
+
var cameraGridKind = require_dist.defineEntryKind(CAMERA_GRID_KIND_NAME, {
|
|
397
|
+
title: "Camera grids",
|
|
398
|
+
nameField: "name",
|
|
399
|
+
schema: GridBodySchema,
|
|
400
|
+
writeTrigger: "an operator adds, switches or deletes a grid, or saves its layout in the camera details"
|
|
401
|
+
});
|
|
402
|
+
/** Canvas cadence and published rungs a new grid starts with, until the layout editor changes them. */
|
|
387
403
|
var DEFAULT_FPS = 10;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return
|
|
404
|
+
var DEFAULT_PUBLISHED = ["mid", "low"];
|
|
405
|
+
/** The body a new grid starts with: a name only, no cells, so it declares a camera and emits nothing. */
|
|
406
|
+
function initialGridBody(name) {
|
|
407
|
+
return {
|
|
408
|
+
name,
|
|
409
|
+
fps: DEFAULT_FPS,
|
|
410
|
+
publishedProfiles: DEFAULT_PUBLISHED,
|
|
411
|
+
cells: []
|
|
412
|
+
};
|
|
392
413
|
}
|
|
393
|
-
|
|
394
|
-
|
|
414
|
+
/** The row `readGridInstances` parses, from a record. */
|
|
415
|
+
function rawGridOfRecord(id, body) {
|
|
416
|
+
return {
|
|
417
|
+
id,
|
|
418
|
+
cameraStableId: body.cameraStableId ?? newGridCameraStableId(id),
|
|
419
|
+
name: body.name,
|
|
420
|
+
enabled: require_dist.isInstanceEnabled(body),
|
|
421
|
+
fps: body.fps,
|
|
422
|
+
publishedProfiles: body.publishedProfiles,
|
|
423
|
+
cells: body.cells
|
|
424
|
+
};
|
|
395
425
|
}
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/builtins/camera-grid/migrations/camera-grids-to-records.ts
|
|
396
428
|
/**
|
|
397
|
-
*
|
|
398
|
-
*
|
|
429
|
+
* The grids a pre-record install kept in the addon settings (`cameraGrids`) become `camera-grid`
|
|
430
|
+
* records (planning#440 step 7, D1013). The record id IS the old row id, so the camera
|
|
431
|
+
* `camera-grid-<id>` and every binding, layout and recording that names it keeps its identity.
|
|
432
|
+
*
|
|
433
|
+
* Rows are first normalised the way the old boot-time normaliser did (a missing or non-uuid id is
|
|
434
|
+
* minted, a missing stable id is derived). The id is minted DETERMINISTICALLY from the row, so an
|
|
435
|
+
* interrupted run converts the same row to the same record. Every good row is written, read back
|
|
436
|
+
* equal, and an existing record is never overwritten.
|
|
437
|
+
*
|
|
438
|
+
* A row that still cannot be converted (nameless, malformed, a duplicate id or camera) never
|
|
439
|
+
* blocks the others: the old reader skipped it and ran the rest. The legacy key is rewritten to
|
|
440
|
+
* hold ONLY those raw rows (nothing reads it any more; kept for forensics), one warn per row, and
|
|
441
|
+
* the migration lands as done. With no bad row the key is deleted.
|
|
399
442
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
443
|
+
var LEGACY_GRIDS_KEY = "cameraGrids";
|
|
444
|
+
/**
|
|
445
|
+
* The shape the settings list stored, frozen here: the migration owns what it reads. `width` and
|
|
446
|
+
* `height` of rows written long ago are dropped (nothing reads them: the canvas is derived).
|
|
447
|
+
*/
|
|
448
|
+
var LegacyRowSchema = zod.z.object({
|
|
449
|
+
id: zod.z.string().uuid(),
|
|
450
|
+
cameraStableId: zod.z.string().min(1).max(256).optional(),
|
|
451
|
+
name: zod.z.string().min(1).max(160),
|
|
452
|
+
enabled: zod.z.boolean().default(true),
|
|
453
|
+
fps: zod.z.number().int().min(1).max(60).default(10),
|
|
454
|
+
publishedProfiles: zod.z.array(zod.z.enum([
|
|
455
|
+
"high",
|
|
456
|
+
"mid",
|
|
457
|
+
"low"
|
|
458
|
+
])).max(3).default(["mid", "low"]),
|
|
459
|
+
cells: zod.z.array(GridCellSchema).max(16).default([])
|
|
460
|
+
});
|
|
461
|
+
var UUID = zod.z.string().uuid();
|
|
462
|
+
/** A uuid derived from the row itself, so a rerun mints the same id for the same row. */
|
|
463
|
+
function mintedId(raw) {
|
|
464
|
+
const hex = (0, node_crypto.createHash)("sha1").update(JSON.stringify(raw)).digest("hex");
|
|
465
|
+
const variant = (Number.parseInt(hex.charAt(16), 16) & 3 | 8).toString(16);
|
|
466
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
467
|
+
}
|
|
468
|
+
function verdictOf(raw) {
|
|
469
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return {
|
|
470
|
+
kind: "skip",
|
|
471
|
+
reason: "the row is not an object"
|
|
472
|
+
};
|
|
473
|
+
const name = Reflect.get(raw, "name");
|
|
474
|
+
if (typeof name !== "string" || name.trim().length === 0) return {
|
|
475
|
+
kind: "skip",
|
|
476
|
+
reason: "the row has no name"
|
|
477
|
+
};
|
|
478
|
+
const rawId = Reflect.get(raw, "id");
|
|
479
|
+
const id = UUID.safeParse(rawId).success && typeof rawId === "string" ? rawId : mintedId(raw);
|
|
480
|
+
const parsed = LegacyRowSchema.safeParse({
|
|
481
|
+
...raw,
|
|
482
|
+
id,
|
|
483
|
+
name: name.trim()
|
|
484
|
+
});
|
|
485
|
+
if (!parsed.success) return {
|
|
486
|
+
kind: "skip",
|
|
487
|
+
reason: "the row does not match the legacy shape"
|
|
488
|
+
};
|
|
489
|
+
const row = parsed.data;
|
|
490
|
+
const derived = row.cameraStableId === void 0 || row.cameraStableId === newGridCameraStableId(row.id);
|
|
491
|
+
return {
|
|
492
|
+
kind: "draft",
|
|
493
|
+
draft: {
|
|
494
|
+
id: row.id,
|
|
495
|
+
body: {
|
|
496
|
+
name: row.name,
|
|
497
|
+
...derived ? {} : { cameraStableId: row.cameraStableId },
|
|
498
|
+
fps: row.fps,
|
|
499
|
+
publishedProfiles: row.publishedProfiles,
|
|
500
|
+
cells: row.cells,
|
|
501
|
+
...row.enabled ? {} : { enabled: false }
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function canonical(value) {
|
|
507
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
508
|
+
if (value !== null && typeof value === "object") return `{${Object.entries(value).filter(([, v]) => v !== void 0).toSorted(([a], [b]) => a < b ? -1 : 1).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
509
|
+
return JSON.stringify(value);
|
|
510
|
+
}
|
|
511
|
+
/** Absent `enabled` means on, so the two spellings of "on" read back as equal. */
|
|
512
|
+
function sameBody(a, b) {
|
|
513
|
+
const norm = (body) => canonical({
|
|
514
|
+
...body,
|
|
515
|
+
enabled: require_dist.isInstanceEnabled(body)
|
|
516
|
+
});
|
|
517
|
+
return norm(a) === norm(b);
|
|
518
|
+
}
|
|
519
|
+
function rowName(raw) {
|
|
520
|
+
if (raw === null || typeof raw !== "object") return "(not an object)";
|
|
521
|
+
const id = Reflect.get(raw, "id");
|
|
522
|
+
return typeof id === "string" && id.length > 0 ? `'${id}'` : "(no id)";
|
|
523
|
+
}
|
|
524
|
+
async function copyGridsToRecords(ports) {
|
|
525
|
+
const legacy = await ports.readLegacy();
|
|
526
|
+
if (legacy.kind === "absent" || !Array.isArray(legacy.value)) return {
|
|
527
|
+
outcome: "already-done",
|
|
528
|
+
summary: { reason: "no-legacy-data" }
|
|
529
|
+
};
|
|
530
|
+
const rows = legacy.value;
|
|
531
|
+
const drafts = [];
|
|
532
|
+
const skipped = [];
|
|
533
|
+
const ids = /* @__PURE__ */ new Set();
|
|
534
|
+
const cameras = /* @__PURE__ */ new Set();
|
|
535
|
+
for (const raw of rows) {
|
|
536
|
+
const verdict = verdictOf(raw);
|
|
537
|
+
if (verdict.kind === "skip") {
|
|
538
|
+
skipped.push({
|
|
539
|
+
raw,
|
|
540
|
+
reason: verdict.reason
|
|
541
|
+
});
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
const camera = verdict.draft.body.cameraStableId ?? newGridCameraStableId(verdict.draft.id);
|
|
545
|
+
if (ids.has(verdict.draft.id) || cameras.has(camera)) {
|
|
546
|
+
skipped.push({
|
|
547
|
+
raw,
|
|
548
|
+
reason: "a duplicate grid or camera"
|
|
549
|
+
});
|
|
407
550
|
continue;
|
|
408
551
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
height: positiveInt(row["height"], DEFAULT_HEIGHT),
|
|
419
|
-
fps: positiveInt(row["fps"], DEFAULT_FPS),
|
|
420
|
-
cells: Array.isArray(row["cells"]) ? row["cells"] : []
|
|
552
|
+
ids.add(verdict.draft.id);
|
|
553
|
+
cameras.add(camera);
|
|
554
|
+
drafts.push(verdict.draft);
|
|
555
|
+
}
|
|
556
|
+
if (drafts.length === 0 && skipped.length > 0) {
|
|
557
|
+
ports.warn(`camera-grid: ${skipped.length} legacy row(s) are kept unconverted in the old list and ignored`);
|
|
558
|
+
return {
|
|
559
|
+
outcome: "already-done",
|
|
560
|
+
summary: { skipped: skipped.length }
|
|
421
561
|
};
|
|
422
|
-
if (!changed) changed = Object.keys(normalized).some((key) => normalized[key] !== row[key]);
|
|
423
|
-
rows.push(normalized);
|
|
424
562
|
}
|
|
563
|
+
const have = await ports.listIds();
|
|
564
|
+
let created = 0;
|
|
565
|
+
let kept = 0;
|
|
566
|
+
for (const { id, body } of drafts) {
|
|
567
|
+
if (have.has(id)) {
|
|
568
|
+
kept += 1;
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
await ports.putRecord(id, body);
|
|
572
|
+
const back = await ports.readRecord(id);
|
|
573
|
+
if (back === null || !sameBody(back, body)) throw new Error(`camera-grid: grid '${id}' did not read back as written; the legacy list is kept`);
|
|
574
|
+
created += 1;
|
|
575
|
+
}
|
|
576
|
+
for (const { raw, reason } of skipped) ports.warn(`camera-grid: row ${rowName(raw)} was not copied into records (${reason}) and is ignored`);
|
|
577
|
+
if (skipped.length === 0) await ports.dropLegacyKey();
|
|
578
|
+
else await ports.keepLegacyRows(skipped.map((entry) => entry.raw));
|
|
579
|
+
return {
|
|
580
|
+
outcome: "done",
|
|
581
|
+
summary: {
|
|
582
|
+
created,
|
|
583
|
+
kept,
|
|
584
|
+
skipped: skipped.length
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function gridPortsOver(api) {
|
|
589
|
+
const records = api.records.kind(cameraGridKind);
|
|
425
590
|
return {
|
|
426
|
-
|
|
427
|
-
|
|
591
|
+
readLegacy: async () => {
|
|
592
|
+
const { store } = await api.settings.read({});
|
|
593
|
+
return Object.prototype.hasOwnProperty.call(store, "cameraGrids") ? {
|
|
594
|
+
kind: "present",
|
|
595
|
+
value: store[LEGACY_GRIDS_KEY]
|
|
596
|
+
} : { kind: "absent" };
|
|
597
|
+
},
|
|
598
|
+
listIds: async () => {
|
|
599
|
+
const out = /* @__PURE__ */ new Set();
|
|
600
|
+
let cursor;
|
|
601
|
+
do {
|
|
602
|
+
const page = await records.query({
|
|
603
|
+
limit: 500,
|
|
604
|
+
...cursor === void 0 ? {} : { cursor }
|
|
605
|
+
});
|
|
606
|
+
for (const row of page.records) out.add(row.id);
|
|
607
|
+
cursor = page.nextCursor ?? void 0;
|
|
608
|
+
} while (cursor !== void 0);
|
|
609
|
+
return out;
|
|
610
|
+
},
|
|
611
|
+
putRecord: async (id, body) => {
|
|
612
|
+
await records.put({
|
|
613
|
+
id,
|
|
614
|
+
data: body,
|
|
615
|
+
ifRev: 0
|
|
616
|
+
});
|
|
617
|
+
},
|
|
618
|
+
readRecord: async (id) => (await records.get({ id }))?.data ?? null,
|
|
619
|
+
dropLegacyKey: async () => {
|
|
620
|
+
await api.settings.deleteKeys({ keys: [LEGACY_GRIDS_KEY] });
|
|
621
|
+
},
|
|
622
|
+
keepLegacyRows: async (kept) => {
|
|
623
|
+
await api.settings.write({ patch: { [LEGACY_GRIDS_KEY]: [...kept] } });
|
|
624
|
+
},
|
|
625
|
+
warn: (message) => {
|
|
626
|
+
api.log.warn({ message });
|
|
627
|
+
}
|
|
428
628
|
};
|
|
429
629
|
}
|
|
630
|
+
/** The `camera-grid` catalogue (D987): offered to the engine when the addon initialises. */
|
|
631
|
+
var ADDON_MIGRATIONS = [{
|
|
632
|
+
meta: {
|
|
633
|
+
id: "camera-grid/2026-11-07-grids-to-records",
|
|
634
|
+
owner: "camera-grid",
|
|
635
|
+
level: "addon-state",
|
|
636
|
+
seq: 1,
|
|
637
|
+
dependsOn: [],
|
|
638
|
+
store: "settings",
|
|
639
|
+
scope: "cluster",
|
|
640
|
+
onFailure: "tolerate",
|
|
641
|
+
bodyKind: "procedure",
|
|
642
|
+
description: "Copy the addon-level grid list (cameraGrids) into camera-grid records under the same ids, each read back; the legacy key is deleted only once every row has its record",
|
|
643
|
+
fixtureMark: "cells[0].source.x of a grid row, read back from its record"
|
|
644
|
+
},
|
|
645
|
+
procedure: copyGridsToRecords
|
|
646
|
+
}];
|
|
430
647
|
//#endregion
|
|
431
648
|
//#region src/builtins/camera-grid/grid-activity-mirror.ts
|
|
432
649
|
/**
|
|
@@ -2945,10 +3162,7 @@ var RECONCILE_MS = 6e4;
|
|
|
2945
3162
|
*/
|
|
2946
3163
|
var SOURCE_ACQUIRE_BUDGET_MS = 8e3;
|
|
2947
3164
|
var SOURCE_ACQUIRE_PAUSE_MS = 700;
|
|
2948
|
-
var DEFAULTS = {
|
|
2949
|
-
cameraGrids: [],
|
|
2950
|
-
cameraGridTombstones: []
|
|
2951
|
-
};
|
|
3165
|
+
var DEFAULTS = {};
|
|
2952
3166
|
/** One composition per (grid, profile) — a grid composes each separately. */
|
|
2953
3167
|
function sessionKey(instanceId, profile) {
|
|
2954
3168
|
return `${instanceId}::${profile}`;
|
|
@@ -2981,7 +3195,15 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
2981
3195
|
/** Keyed by instance id — ONE composition per grid. */
|
|
2982
3196
|
sessions = /* @__PURE__ */ new Map();
|
|
2983
3197
|
deviceIdByInstanceId = /* @__PURE__ */ new Map();
|
|
2984
|
-
|
|
3198
|
+
instances = null;
|
|
3199
|
+
/** The grids, as the last read of the records saw them. */
|
|
3200
|
+
instanceRows = [];
|
|
3201
|
+
/**
|
|
3202
|
+
* False until the records are readable and the grids migration landed: a camera is never
|
|
3203
|
+
* withdrawn on a list that may be incomplete (D49).
|
|
3204
|
+
*/
|
|
3205
|
+
instancesTrusted = false;
|
|
3206
|
+
migrationLanded = false;
|
|
2985
3207
|
/**
|
|
2986
3208
|
* What each grid can honestly publish, per profile.
|
|
2987
3209
|
*
|
|
@@ -3008,9 +3230,8 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
3008
3230
|
super({ ...DEFAULTS });
|
|
3009
3231
|
}
|
|
3010
3232
|
async onInitialize() {
|
|
3011
|
-
this.replaceTombstones(this.config.cameraGridTombstones);
|
|
3012
|
-
await this.normalizeRows();
|
|
3013
3233
|
if (require_dist.declarationOwnerNodeId(this.ctx.kernel.localNodeId) === "hub") {
|
|
3234
|
+
await this.initInstanceRecords();
|
|
3014
3235
|
await this.resolveFfmpeg();
|
|
3015
3236
|
const relay = new GridStreamRelay({
|
|
3016
3237
|
logger: this.ctx.logger.child("relay"),
|
|
@@ -3061,21 +3282,18 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
3061
3282
|
}, RECONCILE_MS);
|
|
3062
3283
|
this.reconcileTimer.unref?.();
|
|
3063
3284
|
}
|
|
3064
|
-
|
|
3285
|
+
const providers = [{
|
|
3065
3286
|
capability: require_dist.cameraGridLayoutCapability,
|
|
3066
3287
|
provider: buildGridLayoutNativeProvider({
|
|
3067
3288
|
getLayout: (deviceId) => this.gridViewFor(deviceId),
|
|
3068
3289
|
saveLayout: (patch) => this.saveGridLayout(patch)
|
|
3069
3290
|
})
|
|
3070
|
-
}]
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
await this.normalizeRows();
|
|
3075
|
-
await this.applyLayoutChanges();
|
|
3076
|
-
if (this.relay) this.reconcile().catch((error) => {
|
|
3077
|
-
this.ctx.logger.warn("camera grid: reconciliation after a config change failed", { meta: { error: require_dist.errMsg(error) } });
|
|
3291
|
+
}];
|
|
3292
|
+
if (this.instances !== null) providers.push({
|
|
3293
|
+
capability: require_dist.integrationInstancesCapability,
|
|
3294
|
+
provider: this.instances.toProvider()
|
|
3078
3295
|
});
|
|
3296
|
+
return { providers };
|
|
3079
3297
|
}
|
|
3080
3298
|
async onShutdown() {
|
|
3081
3299
|
if (this.reconcileTimer) clearInterval(this.reconcileTimer);
|
|
@@ -3088,36 +3306,104 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
3088
3306
|
this.snapshots = null;
|
|
3089
3307
|
this.frameSampler = null;
|
|
3090
3308
|
}
|
|
3091
|
-
|
|
3092
|
-
return
|
|
3093
|
-
this.ctx.logger.warn(message);
|
|
3094
|
-
});
|
|
3309
|
+
instanceList() {
|
|
3310
|
+
return this.instanceRows;
|
|
3095
3311
|
}
|
|
3096
3312
|
instanceById(instanceId) {
|
|
3097
|
-
return this.
|
|
3313
|
+
return this.instanceRows.find((instance) => instance.id === instanceId);
|
|
3098
3314
|
}
|
|
3099
3315
|
/**
|
|
3100
|
-
*
|
|
3101
|
-
*
|
|
3102
|
-
*
|
|
3103
|
-
* IGNORES what it cannot parse — so creation would silently do nothing.
|
|
3316
|
+
* Hub only: declare the `camera-grid` kind, serve it through `integration-instances`, move the
|
|
3317
|
+
* old settings list into records (D987), then read the rows. A migration that did not land
|
|
3318
|
+
* leaves the declared cameras exactly as they are (`instancesTrusted` stays false).
|
|
3104
3319
|
*/
|
|
3105
|
-
async
|
|
3106
|
-
const
|
|
3107
|
-
if (
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3320
|
+
async initInstanceRecords() {
|
|
3321
|
+
const records = this.ctx.records;
|
|
3322
|
+
if (records === void 0) throw new Error("camera-grid: ctx.records is not available on the hub");
|
|
3323
|
+
await records.declare({ [CAMERA_GRID_KIND_NAME]: cameraGridKind });
|
|
3324
|
+
this.instances = new require_dist.RecordIntegrationInstances(records, cameraGridKind, {
|
|
3325
|
+
description: {
|
|
3326
|
+
role: "services",
|
|
3327
|
+
instanceMode: "multiple",
|
|
3328
|
+
kind: CAMERA_GRID_KIND_NAME,
|
|
3329
|
+
canTest: false,
|
|
3330
|
+
kinds: [{
|
|
3331
|
+
id: CAMERA_GRID_KIND_NAME,
|
|
3332
|
+
label: "Camera grid",
|
|
3333
|
+
functionCap: "camera-grid-layout",
|
|
3334
|
+
canTest: false
|
|
3335
|
+
}]
|
|
3336
|
+
},
|
|
3337
|
+
kindOf: () => CAMERA_GRID_KIND_NAME,
|
|
3338
|
+
formSchema: () => this.instanceForm(),
|
|
3339
|
+
initialBody: (name) => initialGridBody(name),
|
|
3340
|
+
mintId: () => crypto.randomUUID(),
|
|
3341
|
+
configured: () => true,
|
|
3342
|
+
onChanged: (id, change) => this.onInstanceChanged(id, change)
|
|
3343
|
+
});
|
|
3344
|
+
const report = await this.runMigrations(ADDON_MIGRATIONS, gridPortsOver);
|
|
3345
|
+
this.migrationLanded = report.declared && !report.failed.includes("camera-grid/2026-11-07-grids-to-records") && !report.blocked.includes("camera-grid/2026-11-07-grids-to-records");
|
|
3346
|
+
if (!this.migrationLanded) this.ctx.logger.error("camera grid: the grids migration has not landed - the declared cameras are left as they are until it does", { meta: {
|
|
3347
|
+
declared: report.declared,
|
|
3348
|
+
failed: report.failed,
|
|
3349
|
+
blocked: report.blocked
|
|
3111
3350
|
} });
|
|
3112
|
-
await this.
|
|
3351
|
+
await this.refreshInstanceRows();
|
|
3352
|
+
}
|
|
3353
|
+
/** Re-read every grid record. A failed read changes nothing (D49). */
|
|
3354
|
+
async refreshInstanceRows() {
|
|
3355
|
+
const handle = this.ctx.records?.kind(cameraGridKind);
|
|
3356
|
+
if (handle === void 0 || !this.migrationLanded) {
|
|
3357
|
+
this.instancesTrusted = false;
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3360
|
+
try {
|
|
3361
|
+
const raw = [];
|
|
3362
|
+
let cursor;
|
|
3363
|
+
do {
|
|
3364
|
+
const page = await handle.query({
|
|
3365
|
+
limit: 500,
|
|
3366
|
+
...cursor === void 0 ? {} : { cursor }
|
|
3367
|
+
});
|
|
3368
|
+
for (const row of page.records) raw.push(rawGridOfRecord(row.id, row.data));
|
|
3369
|
+
cursor = page.nextCursor ?? void 0;
|
|
3370
|
+
} while (cursor !== void 0);
|
|
3371
|
+
this.instanceRows = readGridInstances(raw, (message) => {
|
|
3372
|
+
this.ctx.logger.warn(message);
|
|
3373
|
+
});
|
|
3374
|
+
this.instancesTrusted = true;
|
|
3375
|
+
} catch (error) {
|
|
3376
|
+
this.instancesTrusted = false;
|
|
3377
|
+
this.ctx.logger.warn("camera grid: the grid records could not be read - keeping the last list", { meta: { error: require_dist.errMsg(error) } });
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
/**
|
|
3381
|
+
* A grid is created with a name only; its layout is authored afterwards in the camera's own
|
|
3382
|
+
* device details (a generated form for the geometry would render "cell 1 source = 592" and be
|
|
3383
|
+
* unusable), so the form carries no field of its own.
|
|
3384
|
+
*/
|
|
3385
|
+
instanceForm() {
|
|
3386
|
+
return { sections: [{
|
|
3387
|
+
id: "camera-grid",
|
|
3388
|
+
title: "Camera grid",
|
|
3389
|
+
description: "A grid is a composite camera: several cameras composed into one picture, recorded and played back like any other camera. Create one with a name; open its camera to lay it out. Object detection is switched OFF on a new grid - the cameras it is composed from are already analysed.",
|
|
3390
|
+
fields: []
|
|
3391
|
+
}] };
|
|
3113
3392
|
}
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3393
|
+
/** Runs after every create / edit / switch / delete of a grid record, on the hub. */
|
|
3394
|
+
async onInstanceChanged(_id, _change) {
|
|
3395
|
+
await this.refreshInstanceRows();
|
|
3396
|
+
if (this.relay === null) return;
|
|
3397
|
+
await this.applyLayoutChanges();
|
|
3398
|
+
await this.reconcile().catch((error) => {
|
|
3399
|
+
this.ctx.logger.warn("camera grid: reconciliation after an instance change failed", { meta: { error: require_dist.errMsg(error) } });
|
|
3400
|
+
});
|
|
3117
3401
|
}
|
|
3118
3402
|
async reconcile() {
|
|
3119
3403
|
if (!this.relay) return;
|
|
3120
|
-
|
|
3404
|
+
await this.refreshInstanceRows();
|
|
3405
|
+
if (!this.instancesTrusted) return;
|
|
3406
|
+
const instances = this.instanceList();
|
|
3121
3407
|
const declarations = buildGridCameraDeclarations(instances);
|
|
3122
3408
|
await this.refreshSourcePlans(instances);
|
|
3123
3409
|
await this.retireWithdrawnSessions(instances);
|
|
@@ -3144,7 +3430,7 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
3144
3430
|
});
|
|
3145
3431
|
},
|
|
3146
3432
|
listOwnDevices: async () => {
|
|
3147
|
-
return gridCameraReconciliationIndex(await this.ctx.api.deviceManager.listAll.query({ addonId: require_dist.bareAddonId(this.ctx.id) }), this.integrationId, declarations
|
|
3433
|
+
return gridCameraReconciliationIndex(await this.ctx.api.deviceManager.listAll.query({ addonId: require_dist.bareAddonId(this.ctx.id) }), this.integrationId, declarations);
|
|
3148
3434
|
}
|
|
3149
3435
|
}).reconcile({
|
|
3150
3436
|
integrationName: INTEGRATION_NAME,
|
|
@@ -3608,11 +3894,17 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
3608
3894
|
fps: updated.fps
|
|
3609
3895
|
}
|
|
3610
3896
|
});
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3897
|
+
const handle = this.ctx.records?.kind(cameraGridKind);
|
|
3898
|
+
if (handle === void 0) throw new Error("camera-grid: the grid records are not available");
|
|
3899
|
+
await handle.patch(instance.id, {
|
|
3900
|
+
name: updated.name,
|
|
3901
|
+
fps: updated.fps,
|
|
3902
|
+
publishedProfiles: updated.publishedProfiles,
|
|
3903
|
+
cells: updated.cells
|
|
3904
|
+
});
|
|
3905
|
+
await this.refreshInstanceRows();
|
|
3906
|
+
await this.applyLayoutChanges();
|
|
3907
|
+
await this.refreshSourcePlans(this.instanceList());
|
|
3616
3908
|
this.ensureSessions(instance.id, input.deviceId);
|
|
3617
3909
|
const view = this.gridViewFor(input.deviceId);
|
|
3618
3910
|
if (!view) throw new Error("camera-grid: the grid vanished while it was being saved");
|
|
@@ -3641,62 +3933,6 @@ var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
|
3641
3933
|
this.ffmpegResolving = attempt;
|
|
3642
3934
|
return attempt;
|
|
3643
3935
|
}
|
|
3644
|
-
/**
|
|
3645
|
-
* The integration page: a list of grids, with a NAME.
|
|
3646
|
-
*
|
|
3647
|
-
* Deliberately nothing else. A generated form for the geometry would render
|
|
3648
|
-
* "cell 1 source = 592, cell 1 crop x = 0.25" and be unusable, so the
|
|
3649
|
-
* geometry lives in a WIDGET on the camera's own device details, declared by
|
|
3650
|
-
* the `camera-grid-layout` CAPABILITY (`camera-grid-layout.cap.ts`). It used
|
|
3651
|
-
* to be a `type:'widget'` field in this addon's own `deviceSettingsSchema()`
|
|
3652
|
-
* and it rendered NOWHERE: that section is only fetched for the four addons
|
|
3653
|
-
* hand-listed in `PIPELINE_CLUSTER_DEVICE_ADDONS`, and an addon not on the
|
|
3654
|
-
* list falls off silently. A cap-declared widget is placed by the framework,
|
|
3655
|
-
* on the camera, beside PTZ and motion zones.
|
|
3656
|
-
*/
|
|
3657
|
-
globalSettingsSchema() {
|
|
3658
|
-
return this.schema({ sections: [{
|
|
3659
|
-
id: "camera-grids",
|
|
3660
|
-
title: "Camera grids",
|
|
3661
|
-
titleKey: "server:globalSettings.s_camera-grids.title",
|
|
3662
|
-
description: "A grid is a composite camera: several cameras composed into one picture, recorded and played back like any other camera. Create one here with a name; open its camera to lay it out. Object detection is switched OFF on a new grid — the cameras it is composed from are already analysed.",
|
|
3663
|
-
descriptionKey: "server:globalSettings.s_camera-grids.description",
|
|
3664
|
-
columns: 1,
|
|
3665
|
-
fields: [this.field({
|
|
3666
|
-
type: "editable-array",
|
|
3667
|
-
key: "cameraGrids",
|
|
3668
|
-
label: "Grids",
|
|
3669
|
-
labelKey: "server:globalSettings.s_camera-grids.cameraGrids.label",
|
|
3670
|
-
default: [],
|
|
3671
|
-
maxRows: 16,
|
|
3672
|
-
addLabel: "Add grid",
|
|
3673
|
-
emptyMessage: "No camera grids yet.",
|
|
3674
|
-
rowTitleTemplate: "{name}",
|
|
3675
|
-
defaultItem: {
|
|
3676
|
-
name: "",
|
|
3677
|
-
enabled: true
|
|
3678
|
-
},
|
|
3679
|
-
itemFields: [{
|
|
3680
|
-
type: "text",
|
|
3681
|
-
key: "name",
|
|
3682
|
-
label: "Name",
|
|
3683
|
-
labelKey: "server:globalSettings.s_camera-grids.cameraGrids.name.label",
|
|
3684
|
-
required: true
|
|
3685
|
-
}, {
|
|
3686
|
-
type: "boolean",
|
|
3687
|
-
key: "enabled",
|
|
3688
|
-
label: "Enabled",
|
|
3689
|
-
labelKey: "server:globalSettings.s_camera-grids.cameraGrids.enabled.label",
|
|
3690
|
-
description: "A disabled grid withdraws its camera.",
|
|
3691
|
-
descriptionKey: "server:globalSettings.s_camera-grids.cameraGrids.enabled.description",
|
|
3692
|
-
default: true
|
|
3693
|
-
}]
|
|
3694
|
-
})]
|
|
3695
|
-
}] });
|
|
3696
|
-
}
|
|
3697
|
-
integrationSettingSections() {
|
|
3698
|
-
return ["camera-grids"];
|
|
3699
|
-
}
|
|
3700
3936
|
};
|
|
3701
3937
|
//#endregion
|
|
3702
3938
|
//#region src/builtins/camera-grid/grid-filter-graph.ts
|
|
@@ -3963,10 +4199,12 @@ async function startGridChild(ctx, plan, sources, onEnded) {
|
|
|
3963
4199
|
};
|
|
3964
4200
|
}
|
|
3965
4201
|
//#endregion
|
|
4202
|
+
exports.CAMERA_GRID_KIND_NAME = CAMERA_GRID_KIND_NAME;
|
|
3966
4203
|
exports.CameraGridAddon = CameraGridAddon;
|
|
3967
4204
|
exports.GRID_CAM_STREAM_ID = GRID_CAM_STREAM_ID;
|
|
3968
4205
|
exports.GRID_PROFILES = GRID_PROFILES;
|
|
3969
4206
|
exports.GRID_SILENCED_CAP_NAMES = GRID_SILENCED_CAP_NAMES;
|
|
4207
|
+
exports.GridBodySchema = GridBodySchema;
|
|
3970
4208
|
exports.GridCameraDevice = GridCameraDevice;
|
|
3971
4209
|
exports.GridFrameSampler = GridFrameSampler;
|
|
3972
4210
|
exports.GridLastFrameFileStore = GridLastFrameFileStore;
|
|
@@ -3975,6 +4213,7 @@ exports.GridStreamRelay = GridStreamRelay;
|
|
|
3975
4213
|
exports.GridStreamSession = GridStreamSession;
|
|
3976
4214
|
exports.buildGridCameraDeclarations = buildGridCameraDeclarations;
|
|
3977
4215
|
exports.buildGridFilterGraph = buildGridFilterGraph;
|
|
4216
|
+
exports.cameraGridKind = cameraGridKind;
|
|
3978
4217
|
exports.default = CameraGridAddon;
|
|
3979
4218
|
exports.deriveGridCanvas = deriveGridCanvas;
|
|
3980
4219
|
exports.gridCamStreamId = gridCamStreamId;
|
|
@@ -3985,10 +4224,11 @@ exports.gridSnapshotAnswerFor = gridSnapshotAnswerFor;
|
|
|
3985
4224
|
exports.gridSourceDial = gridSourceDial;
|
|
3986
4225
|
exports.gridStreamDescriptor = gridStreamDescriptor;
|
|
3987
4226
|
exports.gridStreamInvocation = gridStreamInvocation;
|
|
4227
|
+
exports.initialGridBody = initialGridBody;
|
|
3988
4228
|
exports.installGridCameraRuntime = installGridCameraRuntime;
|
|
3989
4229
|
exports.newGridCameraStableId = newGridCameraStableId;
|
|
3990
|
-
exports.normalizeGridRows = normalizeGridRows;
|
|
3991
4230
|
exports.parseGridStreamPath = parseGridStreamPath;
|
|
4231
|
+
exports.rawGridOfRecord = rawGridOfRecord;
|
|
3992
4232
|
exports.readGridInstances = readGridInstances;
|
|
3993
4233
|
exports.silenceAnalysisFor = silenceAnalysisFor;
|
|
3994
4234
|
exports.startGridChild = startGridChild;
|