@camstack/system 1.2.107 → 1.2.109

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/dist/index.js CHANGED
@@ -2151,13 +2151,9 @@ function readInfo(raw) {
2151
2151
  return {};
2152
2152
  }
2153
2153
  var integrationCounter = 0;
2154
- var deviceCounter = 0;
2155
2154
  function nextIntegrationId() {
2156
2155
  return `int_${String(++integrationCounter).padStart(4, "0")}`;
2157
2156
  }
2158
- function nextDeviceId() {
2159
- return `dev_${String(++deviceCounter).padStart(4, "0")}`;
2160
- }
2161
2157
  var INTEGRATIONS_COLUMNS = [
2162
2158
  {
2163
2159
  name: "id",
@@ -2224,95 +2220,6 @@ var INTEGRATION_SETTINGS_COLUMNS = [
2224
2220
  defaultValue: "string"
2225
2221
  }
2226
2222
  ];
2227
- var DEVICES_COLUMNS = [
2228
- {
2229
- name: "id",
2230
- type: "TEXT",
2231
- primaryKey: true
2232
- },
2233
- {
2234
- name: "integration_id",
2235
- type: "TEXT",
2236
- notNull: true
2237
- },
2238
- {
2239
- name: "stable_id",
2240
- type: "TEXT",
2241
- notNull: true,
2242
- unique: true
2243
- },
2244
- {
2245
- name: "type",
2246
- type: "TEXT",
2247
- notNull: true,
2248
- defaultValue: "camera"
2249
- },
2250
- {
2251
- name: "name",
2252
- type: "TEXT",
2253
- notNull: true
2254
- },
2255
- {
2256
- name: "enabled",
2257
- type: "INTEGER",
2258
- notNull: true,
2259
- defaultValue: 1
2260
- },
2261
- {
2262
- name: "info",
2263
- type: "JSON",
2264
- notNull: true,
2265
- defaultValue: "{}"
2266
- },
2267
- {
2268
- name: "created_at",
2269
- type: "INTEGER",
2270
- notNull: true
2271
- },
2272
- {
2273
- name: "updated_at",
2274
- type: "INTEGER",
2275
- notNull: true
2276
- }
2277
- ];
2278
- var DEVICES_INDEXES = [
2279
- {
2280
- name: "idx_devices_integration",
2281
- columns: ["integration_id"]
2282
- },
2283
- {
2284
- name: "idx_devices_stable",
2285
- columns: ["stable_id"],
2286
- unique: true
2287
- },
2288
- {
2289
- name: "idx_devices_type",
2290
- columns: ["type"]
2291
- }
2292
- ];
2293
- var DEVICE_SETTINGS_COLUMNS = [
2294
- {
2295
- name: "device_id",
2296
- type: "TEXT",
2297
- notNull: true
2298
- },
2299
- {
2300
- name: "key",
2301
- type: "TEXT",
2302
- notNull: true
2303
- },
2304
- {
2305
- name: "value",
2306
- type: "TEXT",
2307
- notNull: true
2308
- },
2309
- {
2310
- name: "value_type",
2311
- type: "TEXT",
2312
- notNull: true,
2313
- defaultValue: "string"
2314
- }
2315
- ];
2316
2223
  /**
2317
2224
  * @durable class=config owner=integration-registry
2318
2225
  * write="`createIntegration` — an operator adds a provider, or an addon declares
@@ -2331,29 +2238,19 @@ var INTEGRATIONS = "integrations";
2331
2238
  */
2332
2239
  var INTEGRATION_SETTINGS = "integration_settings";
2333
2240
  /**
2334
- * `stable_id` carries a UNIQUE column constraint AND a UNIQUE index
2335
- * (`idx_devices_stable`): that pair is what stops a provider re-announcing the
2336
- * same physical camera from creating a second device row. An insert that
2337
- * collides throws rather than duplicating.
2241
+ * The persisted INTEGRATIONS one row per provider instance an operator (or a
2242
+ * declaring addon) added, plus that instance's settings.
2338
2243
  *
2339
- * @durable class=config owner=integration-registry
2340
- * write="`createDevice` a provider adopts a device under a stable id;
2341
- * `updateDevice` rewrites name/enabled/info"
2342
- * retention="`deleteDevice`, or the cascade in `deleteIntegration`. Nothing ages
2343
- * out. The `dev_NNNN` counter resumes from the highest surviving row at boot,
2344
- * so wiping the table restarts numbering and re-adopted cameras come back
2345
- * under DIFFERENT ids than every stored track and rule refers to."
2346
- */
2347
- var DEVICES = "devices";
2348
- /**
2349
- * @durable class=config owner=integration-registry
2350
- * write="`setDeviceSetting` — one row per (device_id, key), deleted and
2351
- * re-inserted on every write; per-camera operator intent lands here"
2352
- * retention="cascade only — `deleteDevice` and `deleteIntegration` remove a
2353
- * device's rows. No sweep; losing the table silently reverts every camera to
2354
- * its defaults."
2244
+ * It had a device half once: `devices` + `device_settings_kv`, `dev_NNNN` ids,
2245
+ * `createDevice` / `listCameras` / `setDeviceSetting`. It was removed on
2246
+ * 2026-08-19 with both tables ([D183](../../../../../docs/decisions/adr-0183-code-that-is-deleted-takes-its-tables-with-it.md)):
2247
+ * measured on the reference hub it held 0 rows against 974 live devices, no
2248
+ * production caller ever reached it, and its id-space could not be reconciled
2249
+ * with the numeric ids every track, rule and binding in the system uses. The
2250
+ * fleet is `device-manager:devices`. Do not add a device method here — the
2251
+ * device authority is the device-manager, and a second one that agrees with
2252
+ * nothing is how this half came to exist.
2355
2253
  */
2356
- var DEVICE_SETTINGS = "device_settings_kv";
2357
2254
  var IntegrationRegistry = class IntegrationRegistry {
2358
2255
  store;
2359
2256
  constructor(backend) {
@@ -2369,15 +2266,6 @@ var IntegrationRegistry = class IntegrationRegistry {
2369
2266
  collection: INTEGRATION_SETTINGS,
2370
2267
  columns: INTEGRATION_SETTINGS_COLUMNS
2371
2268
  });
2372
- await this.store.declareCollection({
2373
- collection: DEVICES,
2374
- columns: DEVICES_COLUMNS,
2375
- indexes: DEVICES_INDEXES
2376
- });
2377
- await this.store.declareCollection({
2378
- collection: DEVICE_SETTINGS,
2379
- columns: DEVICE_SETTINGS_COLUMNS
2380
- });
2381
2269
  const ints = await this.store.query({
2382
2270
  collection: INTEGRATIONS,
2383
2271
  filter: {
@@ -2392,20 +2280,6 @@ var IntegrationRegistry = class IntegrationRegistry {
2392
2280
  const num = parseInt(ints[0].id.replace("int_", ""), 10);
2393
2281
  if (!isNaN(num)) integrationCounter = num;
2394
2282
  }
2395
- const devs = await this.store.query({
2396
- collection: DEVICES,
2397
- filter: {
2398
- orderBy: {
2399
- field: "id",
2400
- direction: "desc"
2401
- },
2402
- limit: 1
2403
- }
2404
- });
2405
- if (devs[0]) {
2406
- const num = parseInt(devs[0].id.replace("dev_", ""), 10);
2407
- if (!isNaN(num)) deviceCounter = num;
2408
- }
2409
2283
  }
2410
2284
  async createIntegration(input) {
2411
2285
  const id = nextIntegrationId();
@@ -2489,15 +2363,6 @@ var IntegrationRegistry = class IntegrationRegistry {
2489
2363
  async deleteIntegration(id) {
2490
2364
  const integration = await this.getIntegration(id);
2491
2365
  if (integration !== null && IntegrationRegistry.isFixed(integration)) throw new Error(`integration "${id}" is fixed — it belongs to the addon that declared it and cannot be deleted`);
2492
- const devices = await this.listDevices(id);
2493
- for (const d of devices) await this.store.deleteWhere({
2494
- collection: DEVICE_SETTINGS,
2495
- filter: { where: { device_id: d.id } }
2496
- });
2497
- await this.store.deleteWhere({
2498
- collection: DEVICES,
2499
- filter: { where: { integration_id: id } }
2500
- });
2501
2366
  await this.store.deleteWhere({
2502
2367
  collection: INTEGRATION_SETTINGS,
2503
2368
  filter: { where: { integration_id: id } }
@@ -2542,139 +2407,6 @@ var IntegrationRegistry = class IntegrationRegistry {
2542
2407
  async setIntegrationSettings(integrationId, settings) {
2543
2408
  for (const [key, value] of Object.entries(settings)) await this.setIntegrationSetting(integrationId, key, value);
2544
2409
  }
2545
- async createDevice(input) {
2546
- const id = nextDeviceId();
2547
- const now = Math.floor(Date.now() / 1e3);
2548
- await this.store.insert({
2549
- collection: DEVICES,
2550
- record: {
2551
- id,
2552
- data: {
2553
- integration_id: input.integrationId,
2554
- stable_id: input.stableId,
2555
- type: input.type,
2556
- name: input.name,
2557
- enabled: input.enabled !== false ? 1 : 0,
2558
- info: input.info ?? {},
2559
- created_at: now,
2560
- updated_at: now
2561
- }
2562
- }
2563
- });
2564
- if (input.settings) await this.setDeviceSettings(id, input.settings);
2565
- return {
2566
- id,
2567
- integrationId: input.integrationId,
2568
- stableId: input.stableId,
2569
- type: input.type,
2570
- name: input.name,
2571
- enabled: input.enabled !== false,
2572
- info: input.info ?? {},
2573
- createdAt: now,
2574
- updatedAt: now
2575
- };
2576
- }
2577
- async getDevice(id) {
2578
- const rows = await this.store.query({
2579
- collection: DEVICES,
2580
- filter: {
2581
- where: { id },
2582
- limit: 1
2583
- }
2584
- });
2585
- return rows[0] ? this.mapDevice(rows[0].data) : null;
2586
- }
2587
- async getDeviceByStableId(stableId) {
2588
- const rows = await this.store.query({
2589
- collection: DEVICES,
2590
- filter: {
2591
- where: { stable_id: stableId },
2592
- limit: 1
2593
- }
2594
- });
2595
- return rows[0] ? this.mapDevice(rows[0].data) : null;
2596
- }
2597
- async listDevices(integrationId) {
2598
- return (await this.store.query({
2599
- collection: DEVICES,
2600
- filter: {
2601
- ...integrationId ? { where: { integration_id: integrationId } } : {},
2602
- orderBy: {
2603
- field: "created_at",
2604
- direction: "asc"
2605
- }
2606
- }
2607
- })).map((r) => this.mapDevice(r.data));
2608
- }
2609
- async listCameras() {
2610
- return (await this.store.query({
2611
- collection: DEVICES,
2612
- filter: {
2613
- where: { type: "camera" },
2614
- orderBy: {
2615
- field: "created_at",
2616
- direction: "asc"
2617
- }
2618
- }
2619
- })).map((r) => this.mapDevice(r.data));
2620
- }
2621
- async updateDevice(id, updates) {
2622
- const updateRow = { updated_at: Math.floor(Date.now() / 1e3) };
2623
- if (updates.name !== void 0) updateRow["name"] = updates.name;
2624
- if (updates.enabled !== void 0) updateRow["enabled"] = updates.enabled ? 1 : 0;
2625
- if (updates.info !== void 0) updateRow["info"] = updates.info;
2626
- await this.store.updateWhere({
2627
- collection: DEVICES,
2628
- filter: { where: { id } },
2629
- data: updateRow
2630
- });
2631
- return this.getDevice(id);
2632
- }
2633
- async deleteDevice(id) {
2634
- await this.store.deleteWhere({
2635
- collection: DEVICE_SETTINGS,
2636
- filter: { where: { device_id: id } }
2637
- });
2638
- await this.store.deleteWhere({
2639
- collection: DEVICES,
2640
- filter: { where: { id } }
2641
- });
2642
- return true;
2643
- }
2644
- async getDeviceSettings(deviceId) {
2645
- const result = {};
2646
- const rows = await this.store.query({
2647
- collection: DEVICE_SETTINGS,
2648
- filter: { where: { device_id: deviceId } }
2649
- });
2650
- for (const row of rows) result[String(row.data["key"])] = deserializeSetting(row.data["value"], String(row.data["value_type"]));
2651
- return result;
2652
- }
2653
- async setDeviceSetting(deviceId, key, value) {
2654
- const s = serializeSetting(value);
2655
- await this.store.deleteWhere({
2656
- collection: DEVICE_SETTINGS,
2657
- filter: { where: {
2658
- device_id: deviceId,
2659
- key
2660
- } }
2661
- });
2662
- await this.store.insert({
2663
- collection: DEVICE_SETTINGS,
2664
- record: {
2665
- id: `${deviceId}:${key}`,
2666
- data: {
2667
- device_id: deviceId,
2668
- key,
2669
- value: s.value,
2670
- value_type: s.valueType
2671
- }
2672
- }
2673
- });
2674
- }
2675
- async setDeviceSettings(deviceId, settings) {
2676
- for (const [key, value] of Object.entries(settings)) await this.setDeviceSetting(deviceId, key, value);
2677
- }
2678
2410
  mapIntegration(row) {
2679
2411
  return {
2680
2412
  id: String(row["id"]),
@@ -2686,19 +2418,6 @@ var IntegrationRegistry = class IntegrationRegistry {
2686
2418
  updatedAt: Number(row["updated_at"])
2687
2419
  };
2688
2420
  }
2689
- mapDevice(row) {
2690
- return {
2691
- id: String(row["id"]),
2692
- integrationId: String(row["integration_id"]),
2693
- stableId: String(row["stable_id"]),
2694
- type: String(row["type"]),
2695
- name: String(row["name"]),
2696
- enabled: row["enabled"] === 1,
2697
- info: readInfo(row["info"]),
2698
- createdAt: Number(row["created_at"]),
2699
- updatedAt: Number(row["updated_at"])
2700
- };
2701
- }
2702
2421
  };
2703
2422
  //#endregion
2704
2423
  //#region src/kernel/deps/ensure-native-prebuilds.ts