@camstack/server 1.2.816 → 1.2.817

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.
Files changed (94) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/core/cap-providers.js +2 -43
  3. package/dist/api/trpc/generated-cap-routers.js +14 -17
  4. package/dist/core/addon/addon-registry.service.js +3 -3
  5. package/dist/core/addon/instance-lifecycle.js +79 -4
  6. package/package.json +18 -8
  7. package/system/dist/{agent-https-CK_B6QXQ.mjs → agent-https-8yyIi2Mv.mjs} +1 -1
  8. package/system/dist/{agent-https-pirjJaDw.js → agent-https-CSHd24Sz.js} +1 -1
  9. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  10. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  11. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  12. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  13. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  14. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  15. package/system/dist/builtins/autotrack/index.js +1 -1
  16. package/system/dist/builtins/autotrack/index.mjs +1 -1
  17. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  18. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  19. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  20. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  21. package/system/dist/builtins/camera-grid/index.js +8 -4
  22. package/system/dist/builtins/camera-grid/index.mjs +8 -4
  23. package/system/dist/builtins/composer/composer.addon.js +3 -3
  24. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  25. package/system/dist/builtins/console-logging/index.js +1 -1
  26. package/system/dist/builtins/console-logging/index.mjs +1 -1
  27. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +1 -0
  28. package/system/dist/builtins/core-blocks/core-blocks.addon.js +16 -8
  29. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +16 -8
  30. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  31. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  32. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  33. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  34. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  35. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  36. package/system/dist/builtins/keychain/index.js +4 -4
  37. package/system/dist/builtins/keychain/index.mjs +4 -4
  38. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  39. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  40. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  41. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  42. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  43. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  44. package/system/dist/builtins/loki-logging/index.js +3 -3
  45. package/system/dist/builtins/loki-logging/index.mjs +3 -3
  46. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  47. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  48. package/system/dist/builtins/platform-probe/index.js +1 -1
  49. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  50. package/system/dist/builtins/record-entries/index.js +1 -1
  51. package/system/dist/builtins/record-entries/index.mjs +1 -1
  52. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  53. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  54. package/system/dist/builtins/snapshot/index.js +1 -1
  55. package/system/dist/builtins/snapshot/index.mjs +1 -1
  56. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  57. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  58. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  59. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  60. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  61. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  62. package/system/dist/builtins/storage-orchestrator/location-store.d.ts +5 -14
  63. package/system/dist/builtins/storage-orchestrator/record-kinds.d.ts +0 -1
  64. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +35 -75
  65. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +35 -75
  66. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +9 -32
  67. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  68. package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
  69. package/system/dist/builtins/winston-logging/index.js +1 -1
  70. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  71. package/system/dist/{capture-engine-9qCs6J2S.js → capture-engine-Cius-WCQ.js} +1 -1
  72. package/system/dist/{capture-engine-MPu8CRiM.mjs → capture-engine-D2eAoc9W.mjs} +1 -1
  73. package/system/dist/{composition-sources-N-9OE7DA.js → composition-sources-AJ8V5KOI.js} +1 -1
  74. package/system/dist/{composition-sources-CAPpmqL0.mjs → composition-sources-CdcDO-Ut.mjs} +1 -1
  75. package/system/dist/{constants-o31-vUsL.js → constants-BVIwtt_O.js} +1 -1
  76. package/system/dist/{constants-D75PEb9b.mjs → constants-GPP-Z7D3.mjs} +1 -1
  77. package/system/dist/{device-ca-C3wqsnBw.js → device-ca-BFJn5TzU.js} +1 -1
  78. package/system/dist/{device-ca-D9C75-ee.mjs → device-ca-WLUZEMzG.mjs} +1 -1
  79. package/system/dist/{dist-DBoCrtvm.mjs → dist-QnMV8AH-.mjs} +15 -39
  80. package/system/dist/{dist-BmEptO1d.js → dist-X-i__4Xc.js} +14 -44
  81. package/system/dist/file-host-worker.js +1 -1
  82. package/system/dist/file-host-worker.mjs +1 -1
  83. package/system/dist/{hub-mdns-ciao-B8Lh4Gx1.js → hub-mdns-ciao-DxC8z6eX.js} +2 -2
  84. package/system/dist/{hub-mdns-ciao-ho8U9Zs6.mjs → hub-mdns-ciao-awDw9o6E.mjs} +2 -2
  85. package/system/dist/index.js +8 -8
  86. package/system/dist/index.mjs +8 -8
  87. package/system/dist/{legacy-integration-rows-door-Cc47aOOP.mjs → legacy-integration-rows-door-COW5hMUZ.mjs} +1 -1
  88. package/system/dist/{legacy-integration-rows-door-v-8WFbCS.js → legacy-integration-rows-door-Cbb1WKDb.js} +1 -1
  89. package/system/dist/migrations/hub/2026-11-08-storage-locations-write-set.d.ts +3 -0
  90. package/system/dist/{restore-archive-DS-Hgq3V.mjs → restore-archive-Dp13UUld.mjs} +82 -82
  91. package/system/dist/{restore-archive-BYOda1Dl.js → restore-archive-q01U_u2A.js} +1 -1
  92. package/system/dist/{wal-maintenance-D5CHoEtS.js → wal-maintenance-F8p6X7gc.js} +0 -0
  93. package/system/dist/{wal-maintenance-DtqrYJN3.mjs → wal-maintenance-PzTcTuqZ.mjs} +0 -0
  94. package/system/package.json +1 -1
@@ -7,26 +7,17 @@
7
7
  * tests pass a fake (in-memory `Map`-backed) implementation. Same
8
8
  * pattern as `IntegrationRegistry` in `sqlite-storage/`.
9
9
  */
10
- import type { LegacyStorageLocationDefault, RecordKindHandle, RecordsAccess, StorageLocation } from "@camstack/types";
10
+ import type { RecordKindHandle, RecordsAccess, StorageLocation } from "@camstack/types";
11
11
  import { type StorageLocationBody, type StorageSeedMarkerBody } from "./record-kinds.js";
12
12
  /**
13
- * A location as it comes back OFF DISK: the live record plus the retired
14
- * `isDefault` column, which exists only so the orchestrator's boot migration
15
- * can turn an old default into the enabled write set and say which row it came
16
- * from. No other reader may take this type.
17
- */
18
- export type PersistedStorageLocation = StorageLocation & LegacyStorageLocationDefault;
19
- /**
20
13
  * Abstract storage interface for `StorageLocation` records. Methods are
21
14
  * async because production-side implementations hit SQLite — but the
22
15
  * orchestrator's mutation paths fire-and-forget the writes so a slow
23
16
  * disk doesn't block the cap surface.
24
17
  */
25
18
  export interface ILocationStore {
26
- /** Read every persisted location. Called once at boot. Rows carry the
27
- * RETIRED `isDefault` column when it was set, for the one reader allowed to
28
- * see it: the orchestrator's boot migration onto the `enabled` write set. */
29
- loadAll(): Promise<readonly PersistedStorageLocation[]>;
19
+ /** Read every persisted location. Called once at boot. */
20
+ loadAll(): Promise<readonly StorageLocation[]>;
30
21
  /** Insert or replace a single location by id. */
31
22
  upsert(loc: StorageLocation): Promise<void>;
32
23
  /** Remove a location by id. */
@@ -79,7 +70,7 @@ export declare class SqliteLocationStore implements ILocationStore {
79
70
  markTypeSeeded(type: string): Promise<void>;
80
71
  unmarkTypeSeeded(type: string): Promise<void>;
81
72
  static recordStoresOf(records: Pick<RecordsAccess, "kind">): RecordKindHandle<StorageLocationBody>;
82
- loadAll(): Promise<readonly PersistedStorageLocation[]>;
73
+ loadAll(): Promise<readonly StorageLocation[]>;
83
74
  upsert(loc: StorageLocation): Promise<void>;
84
75
  delete(id: string): Promise<void>;
85
76
  }
@@ -90,4 +81,4 @@ export declare class SqliteLocationStore implements ILocationStore {
90
81
  * other marker (a legacy ref the migration has not moved yet) stays in `config` untouched.
91
82
  */
92
83
  export declare function locationToBody(loc: StorageLocation, staged?: Readonly<Record<string, string | null>>): StorageLocationBody;
93
- export declare function bodyToPersistedLocation(id: string, body: StorageLocationBody): PersistedStorageLocation | null;
84
+ export declare function bodyToPersistedLocation(id: string, body: StorageLocationBody): StorageLocation | null;
@@ -14,7 +14,6 @@ export type StorageLocationBody = {
14
14
  readonly nodeId?: string;
15
15
  readonly enabled?: boolean;
16
16
  readonly mode?: z.infer<typeof StorageLocationModeSchema>;
17
- readonly isDefault?: boolean;
18
17
  /**
19
18
  * The provider's credentials by config key (`password`, `privateKey`, ...), kept in the keychain
20
19
  * and bound to THIS row: the records door stores the value and deleting the row deletes it.
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-BmEptO1d.js");
6
+ const require_dist = require("../../dist-X-i__4Xc.js");
7
7
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
8
8
  let zod = require("zod");
9
9
  let node_crypto = require("node:crypto");
@@ -58,7 +58,6 @@ var StorageLocationBodySchema = zod.z.object({
58
58
  nodeId: zod.z.string().optional(),
59
59
  enabled: zod.z.boolean().optional(),
60
60
  mode: require_dist.StorageLocationModeSchema.optional(),
61
- isDefault: zod.z.boolean().optional(),
62
61
  secrets: zod.z.record(zod.z.string(), zod.z.string().meta({ secret: true })).optional()
63
62
  });
64
63
  var StorageSeedMarkerBodySchema = zod.z.object({ seededAt: zod.z.number() });
@@ -248,7 +247,6 @@ function bodyToPersistedLocation(id, body) {
248
247
  ...body.nodeId !== void 0 ? { nodeId: body.nodeId } : {},
249
248
  ...body.enabled !== void 0 ? { enabled: body.enabled } : {},
250
249
  ...body.mode !== void 0 ? { mode: body.mode } : {},
251
- ...require_dist.LegacyStorageLocationDefaultSchema.parse({ isDefault: body.isDefault ?? false }),
252
250
  isSystem: body.isSystem,
253
251
  createdAt: body.createdAt,
254
252
  updatedAt: body.updatedAt
@@ -3255,77 +3253,7 @@ var StorageOrchestratorService = class {
3255
3253
  backfilled: backfill.length,
3256
3254
  total: this.locations.size
3257
3255
  } });
3258
- this.migrateOntoTheWriteSet(rows);
3259
- }
3260
- /**
3261
- * ONE explicit migration onto the four-state model (D385), run once per boot
3262
- * against the rows that came off disk. Idempotent: the second boot finds
3263
- * nothing to do.
3264
- *
3265
- * Two steps, in order, and each one is a WRITE — the point is that "absent"
3266
- * stops existing rather than being re-interpreted on every read forever:
3267
- *
3268
- * 1. A row with no `mode` is stamped with the mode its legacy flags imply
3269
- * (`legacyModeOf`): `config.readOnly === true` → `readonly` and the
3270
- * config key is DELETED; `enabled === false` → `readonly` (the
3271
- * CONSERVATIVE direction — a state change must never start deleting
3272
- * footage on its own); everything else → `active`. `withLocationMode`
3273
- * derives `enabled` from the mode, so the two can never disagree, and
3274
- * this subsumes the D383 pass that stamped flagless rows `enabled: true`.
3275
- * 2. A type left with NO write target — only reachable from a hand-edited
3276
- * store or a row an older build wrote — gets one made `active`, chosen as
3277
- * the row the RETIRED default flag named, else the `:default`-slugged
3278
- * row, else the lexicographically first. Loudly: a class with no write
3279
- * target records nowhere, and refusing to repair it here would leave the
3280
- * hub silently unable to write with no operator action pending.
3281
- *
3282
- * An operator's explicit `readonly`/`drain`/`disabled` is never reversed by
3283
- * step 1 — only step 2 touches it, and only when the alternative is a class
3284
- * that cannot write at all.
3285
- *
3286
- * On the live hub every location is enabled with no `readOnly`, so step 1 is
3287
- * a no-op that stamps `active` and nothing else changes.
3288
- */
3289
- migrateOntoTheWriteSet(rows) {
3290
- const legacyDefaultOfType = /* @__PURE__ */ new Map();
3291
- for (const row of rows) if (row.isDefault === true) legacyDefaultOfType.set(row.type, row.id);
3292
- const stamped = [];
3293
- for (const loc of this.locations.values()) {
3294
- if (loc.mode !== void 0) continue;
3295
- this.persistMigrated(require_dist.withLocationMode(loc, require_dist.legacyModeOf(loc) ?? "active"));
3296
- stamped.push(loc.id);
3297
- }
3298
- const repaired = [];
3299
- for (const type of new Set([...this.locations.values()].map((l) => l.type))) {
3300
- const ofType = [...this.locations.values()].filter((l) => l.type === type);
3301
- if (ofType.some((l) => require_dist.isLocationEnabled(l))) continue;
3302
- const legacyDefault = legacyDefaultOfType.get(type);
3303
- const pick = ofType.find((l) => l.id === legacyDefault) ?? ofType.find((l) => l.id === `${type}:default`) ?? ofType.toSorted((a, b) => a.id.localeCompare(b.id))[0];
3304
- if (!pick) continue;
3305
- this.persistMigrated(require_dist.withLocationMode(pick, "active"));
3306
- repaired.push(pick.id);
3307
- }
3308
- if (stamped.length > 0 || repaired.length > 0) this.logger.info("storage-orchestrator: migrated locations onto the state model", { meta: {
3309
- stamped,
3310
- repaired
3311
- } });
3312
- for (const id of repaired) this.logger.warn("storage-orchestrator: a storage type had NO enabled location — re-enabled one so it can write. Every other location of that type stays read-only until you enable it.", { meta: { id } });
3313
- }
3314
- /** Apply one migrated row in memory and mirror it to the store. */
3315
- persistMigrated(next) {
3316
- const withStamp = {
3317
- ...next,
3318
- updatedAt: Date.now()
3319
- };
3320
- this.locations.set(withStamp.id, withStamp);
3321
- const store = this.locationStore;
3322
- if (!store) return;
3323
- store.upsert(withStamp).catch((err) => {
3324
- this.logger.error("storage-orchestrator: state-model migration persist failed", { meta: {
3325
- id: withStamp.id,
3326
- error: err instanceof Error ? err.message : String(err)
3327
- } });
3328
- });
3256
+ this.repairWriteSets();
3329
3257
  }
3330
3258
  /**
3331
3259
  * Inject the declaration-driven cardinality source. Called once by the
@@ -3381,7 +3309,39 @@ var StorageOrchestratorService = class {
3381
3309
  await this.loadSeedMemory(this.locationStore, rows.length);
3382
3310
  for (const loc of rows) this.locations.set(loc.id, loc);
3383
3311
  this.logger.info("storage-orchestrator: hydrated locations from store", { meta: { loaded: this.locations.size } });
3384
- this.migrateOntoTheWriteSet(rows);
3312
+ this.repairWriteSets();
3313
+ }
3314
+ /**
3315
+ * A type with NO enabled location records nowhere, so this is a runtime invariant, not a
3316
+ * one-time migration: a hand-edited store, a restore or an older build can break it at any
3317
+ * boot. Idempotent: a type that can write is left alone. One location is made `active` (the
3318
+ * `<type>:default` row, else the lexicographically first id), persisted, and said loudly.
3319
+ * The mode is read and written only through `storage-location-mode` (D385); an operator's
3320
+ * `readonly`/`drain`/`disabled` is touched only when the alternative is a type that cannot write.
3321
+ */
3322
+ repairWriteSets() {
3323
+ const repaired = [];
3324
+ for (const type of new Set([...this.locations.values()].map((l) => l.type))) {
3325
+ const ofType = [...this.locations.values()].filter((l) => l.type === type);
3326
+ if (ofType.some((l) => require_dist.isLocationEnabled(l))) continue;
3327
+ const pick = ofType.find((l) => l.id === `${type}:default`) ?? ofType.toSorted((a, b) => a.id.localeCompare(b.id))[0];
3328
+ if (!pick) continue;
3329
+ const next = {
3330
+ ...require_dist.withLocationMode(pick, "active"),
3331
+ updatedAt: Date.now()
3332
+ };
3333
+ this.locations.set(next.id, next);
3334
+ repaired.push(next.id);
3335
+ const store = this.locationStore;
3336
+ if (!store) continue;
3337
+ store.upsert(next).catch((err) => {
3338
+ this.logger.error("storage-orchestrator: write-set repair persist failed", { meta: {
3339
+ id: next.id,
3340
+ error: err instanceof Error ? err.message : String(err)
3341
+ } });
3342
+ });
3343
+ }
3344
+ for (const id of repaired) this.logger.warn("storage-orchestrator: a storage type had NO enabled location — re-enabled one so it can write. Every other location of that type stays read-only until you enable it.", { meta: { id } });
3385
3345
  }
3386
3346
  /**
3387
3347
  * Boot backfill (SP1): stamp `nodeId` on every persisted node-local
@@ -1,4 +1,4 @@
1
- import { $o as BaseAddon, Ac as parseSecretRef, Di as modeForSwitch, Ec as normalizeNodeId, Er as evictionPolicyOfLocation, Ga as storageMigrationCapability, Hs as buildSecretRef, Mc as recordSecretRef, Na as settingsStoreCapability, Oi as modeMayWrite, Pc as resolveSecretMarkers, Qa as switchStateOfMode, Qs as defineCustomActions, Sc as makeSecretMarker, Us as collectSecretConfigKeys, Vc as toSecretFieldView, Wa as storageCapability, Wr as integrationInstancesCapability, Xs as customAction, Zc as EventCategory, Zs as defineAddonMigrations, _c as isSecretClear, _o as withLocationMode, bi as mayWriteToLocation, ec as defineRecordKinds, en as StorageCleanupJobSchema, li as legacyModeOf, nn as StorageLocationTypeSchema, qt as STORAGE_LOCATION_MODES, rn as StorageMigrationJobSchema, ti as isLocationEnabled, tn as StorageLocationModeSchema, va as resolveLocationMode, vc as isSecretFieldView, vs as REDACTED_SECRET, xt as LegacyStorageLocationDefaultSchema, yc as isSecretMarker, yi as mayReadLocation, zr as gbToBytes } from "../../dist-DBoCrtvm.mjs";
1
+ import { $s as defineRecordKinds, $t as StorageCleanupJobSchema, Bc as toSecretFieldView, Di as modeMayWrite, Ei as modeForSwitch, Hs as collectSecretConfigKeys, Kt as STORAGE_LOCATION_MODES, Ma as settingsStoreCapability, Nc as resolveSecretMarkers, Qo as BaseAddon, Rr as gbToBytes, Tc as normalizeNodeId, Tr as evictionPolicyOfLocation, Ua as storageCapability, Ur as integrationInstancesCapability, Vs as buildSecretRef, Wa as storageMigrationCapability, Xc as EventCategory, Xs as defineAddonMigrations, Ys as customAction, Za as switchStateOfMode, Zs as defineCustomActions, _a as resolveLocationMode, _c as isSecretFieldView, _s as REDACTED_SECRET, ei as isLocationEnabled, en as StorageLocationModeSchema, gc as isSecretClear, go as withLocationMode, jc as recordSecretRef, kc as parseSecretRef, nn as StorageMigrationJobSchema, tn as StorageLocationTypeSchema, vc as isSecretMarker, vi as mayReadLocation, xc as makeSecretMarker, yi as mayWriteToLocation } from "../../dist-QnMV8AH-.mjs";
2
2
  import { t as require_read_all_rows } from "../../read-all-rows-TaPqdWNF.mjs";
3
3
  import { z } from "zod";
4
4
  import { randomUUID } from "node:crypto";
@@ -53,7 +53,6 @@ var StorageLocationBodySchema = z.object({
53
53
  nodeId: z.string().optional(),
54
54
  enabled: z.boolean().optional(),
55
55
  mode: StorageLocationModeSchema.optional(),
56
- isDefault: z.boolean().optional(),
57
56
  secrets: z.record(z.string(), z.string().meta({ secret: true })).optional()
58
57
  });
59
58
  var StorageSeedMarkerBodySchema = z.object({ seededAt: z.number() });
@@ -243,7 +242,6 @@ function bodyToPersistedLocation(id, body) {
243
242
  ...body.nodeId !== void 0 ? { nodeId: body.nodeId } : {},
244
243
  ...body.enabled !== void 0 ? { enabled: body.enabled } : {},
245
244
  ...body.mode !== void 0 ? { mode: body.mode } : {},
246
- ...LegacyStorageLocationDefaultSchema.parse({ isDefault: body.isDefault ?? false }),
247
245
  isSystem: body.isSystem,
248
246
  createdAt: body.createdAt,
249
247
  updatedAt: body.updatedAt
@@ -3250,77 +3248,7 @@ var StorageOrchestratorService = class {
3250
3248
  backfilled: backfill.length,
3251
3249
  total: this.locations.size
3252
3250
  } });
3253
- this.migrateOntoTheWriteSet(rows);
3254
- }
3255
- /**
3256
- * ONE explicit migration onto the four-state model (D385), run once per boot
3257
- * against the rows that came off disk. Idempotent: the second boot finds
3258
- * nothing to do.
3259
- *
3260
- * Two steps, in order, and each one is a WRITE — the point is that "absent"
3261
- * stops existing rather than being re-interpreted on every read forever:
3262
- *
3263
- * 1. A row with no `mode` is stamped with the mode its legacy flags imply
3264
- * (`legacyModeOf`): `config.readOnly === true` → `readonly` and the
3265
- * config key is DELETED; `enabled === false` → `readonly` (the
3266
- * CONSERVATIVE direction — a state change must never start deleting
3267
- * footage on its own); everything else → `active`. `withLocationMode`
3268
- * derives `enabled` from the mode, so the two can never disagree, and
3269
- * this subsumes the D383 pass that stamped flagless rows `enabled: true`.
3270
- * 2. A type left with NO write target — only reachable from a hand-edited
3271
- * store or a row an older build wrote — gets one made `active`, chosen as
3272
- * the row the RETIRED default flag named, else the `:default`-slugged
3273
- * row, else the lexicographically first. Loudly: a class with no write
3274
- * target records nowhere, and refusing to repair it here would leave the
3275
- * hub silently unable to write with no operator action pending.
3276
- *
3277
- * An operator's explicit `readonly`/`drain`/`disabled` is never reversed by
3278
- * step 1 — only step 2 touches it, and only when the alternative is a class
3279
- * that cannot write at all.
3280
- *
3281
- * On the live hub every location is enabled with no `readOnly`, so step 1 is
3282
- * a no-op that stamps `active` and nothing else changes.
3283
- */
3284
- migrateOntoTheWriteSet(rows) {
3285
- const legacyDefaultOfType = /* @__PURE__ */ new Map();
3286
- for (const row of rows) if (row.isDefault === true) legacyDefaultOfType.set(row.type, row.id);
3287
- const stamped = [];
3288
- for (const loc of this.locations.values()) {
3289
- if (loc.mode !== void 0) continue;
3290
- this.persistMigrated(withLocationMode(loc, legacyModeOf(loc) ?? "active"));
3291
- stamped.push(loc.id);
3292
- }
3293
- const repaired = [];
3294
- for (const type of new Set([...this.locations.values()].map((l) => l.type))) {
3295
- const ofType = [...this.locations.values()].filter((l) => l.type === type);
3296
- if (ofType.some((l) => isLocationEnabled(l))) continue;
3297
- const legacyDefault = legacyDefaultOfType.get(type);
3298
- const pick = ofType.find((l) => l.id === legacyDefault) ?? ofType.find((l) => l.id === `${type}:default`) ?? ofType.toSorted((a, b) => a.id.localeCompare(b.id))[0];
3299
- if (!pick) continue;
3300
- this.persistMigrated(withLocationMode(pick, "active"));
3301
- repaired.push(pick.id);
3302
- }
3303
- if (stamped.length > 0 || repaired.length > 0) this.logger.info("storage-orchestrator: migrated locations onto the state model", { meta: {
3304
- stamped,
3305
- repaired
3306
- } });
3307
- for (const id of repaired) this.logger.warn("storage-orchestrator: a storage type had NO enabled location — re-enabled one so it can write. Every other location of that type stays read-only until you enable it.", { meta: { id } });
3308
- }
3309
- /** Apply one migrated row in memory and mirror it to the store. */
3310
- persistMigrated(next) {
3311
- const withStamp = {
3312
- ...next,
3313
- updatedAt: Date.now()
3314
- };
3315
- this.locations.set(withStamp.id, withStamp);
3316
- const store = this.locationStore;
3317
- if (!store) return;
3318
- store.upsert(withStamp).catch((err) => {
3319
- this.logger.error("storage-orchestrator: state-model migration persist failed", { meta: {
3320
- id: withStamp.id,
3321
- error: err instanceof Error ? err.message : String(err)
3322
- } });
3323
- });
3251
+ this.repairWriteSets();
3324
3252
  }
3325
3253
  /**
3326
3254
  * Inject the declaration-driven cardinality source. Called once by the
@@ -3376,7 +3304,39 @@ var StorageOrchestratorService = class {
3376
3304
  await this.loadSeedMemory(this.locationStore, rows.length);
3377
3305
  for (const loc of rows) this.locations.set(loc.id, loc);
3378
3306
  this.logger.info("storage-orchestrator: hydrated locations from store", { meta: { loaded: this.locations.size } });
3379
- this.migrateOntoTheWriteSet(rows);
3307
+ this.repairWriteSets();
3308
+ }
3309
+ /**
3310
+ * A type with NO enabled location records nowhere, so this is a runtime invariant, not a
3311
+ * one-time migration: a hand-edited store, a restore or an older build can break it at any
3312
+ * boot. Idempotent: a type that can write is left alone. One location is made `active` (the
3313
+ * `<type>:default` row, else the lexicographically first id), persisted, and said loudly.
3314
+ * The mode is read and written only through `storage-location-mode` (D385); an operator's
3315
+ * `readonly`/`drain`/`disabled` is touched only when the alternative is a type that cannot write.
3316
+ */
3317
+ repairWriteSets() {
3318
+ const repaired = [];
3319
+ for (const type of new Set([...this.locations.values()].map((l) => l.type))) {
3320
+ const ofType = [...this.locations.values()].filter((l) => l.type === type);
3321
+ if (ofType.some((l) => isLocationEnabled(l))) continue;
3322
+ const pick = ofType.find((l) => l.id === `${type}:default`) ?? ofType.toSorted((a, b) => a.id.localeCompare(b.id))[0];
3323
+ if (!pick) continue;
3324
+ const next = {
3325
+ ...withLocationMode(pick, "active"),
3326
+ updatedAt: Date.now()
3327
+ };
3328
+ this.locations.set(next.id, next);
3329
+ repaired.push(next.id);
3330
+ const store = this.locationStore;
3331
+ if (!store) continue;
3332
+ store.upsert(next).catch((err) => {
3333
+ this.logger.error("storage-orchestrator: write-set repair persist failed", { meta: {
3334
+ id: next.id,
3335
+ error: err instanceof Error ? err.message : String(err)
3336
+ } });
3337
+ });
3338
+ }
3339
+ for (const id of repaired) this.logger.warn("storage-orchestrator: a storage type had NO enabled location — re-enabled one so it can write. Every other location of that type stays read-only until you enable it.", { meta: { id } });
3380
3340
  }
3381
3341
  /**
3382
3342
  * Boot backfill (SP1): stamp `nodeId` on every persisted node-local
@@ -215,38 +215,6 @@ export declare class StorageOrchestratorService {
215
215
  */
216
216
  attachStore(store: ILocationStore): Promise<void>;
217
217
  /**
218
- * ONE explicit migration onto the four-state model (D385), run once per boot
219
- * against the rows that came off disk. Idempotent: the second boot finds
220
- * nothing to do.
221
- *
222
- * Two steps, in order, and each one is a WRITE — the point is that "absent"
223
- * stops existing rather than being re-interpreted on every read forever:
224
- *
225
- * 1. A row with no `mode` is stamped with the mode its legacy flags imply
226
- * (`legacyModeOf`): `config.readOnly === true` → `readonly` and the
227
- * config key is DELETED; `enabled === false` → `readonly` (the
228
- * CONSERVATIVE direction — a state change must never start deleting
229
- * footage on its own); everything else → `active`. `withLocationMode`
230
- * derives `enabled` from the mode, so the two can never disagree, and
231
- * this subsumes the D383 pass that stamped flagless rows `enabled: true`.
232
- * 2. A type left with NO write target — only reachable from a hand-edited
233
- * store or a row an older build wrote — gets one made `active`, chosen as
234
- * the row the RETIRED default flag named, else the `:default`-slugged
235
- * row, else the lexicographically first. Loudly: a class with no write
236
- * target records nowhere, and refusing to repair it here would leave the
237
- * hub silently unable to write with no operator action pending.
238
- *
239
- * An operator's explicit `readonly`/`drain`/`disabled` is never reversed by
240
- * step 1 — only step 2 touches it, and only when the alternative is a class
241
- * that cannot write at all.
242
- *
243
- * On the live hub every location is enabled with no `readOnly`, so step 1 is
244
- * a no-op that stamps `active` and nothing else changes.
245
- */
246
- private migrateOntoTheWriteSet;
247
- /** Apply one migrated row in memory and mirror it to the store. */
248
- private persistMigrated;
249
- /**
250
218
  * Inject the declaration-driven cardinality source. Called once by the
251
219
  * addon after the kernel aggregates every addon's `storageLocations`
252
220
  * declarations into a `StorageLocationRegistry`.
@@ -288,6 +256,15 @@ export declare class StorageOrchestratorService {
288
256
  */
289
257
  initialize(): Promise<void>;
290
258
  /**
259
+ * A type with NO enabled location records nowhere, so this is a runtime invariant, not a
260
+ * one-time migration: a hand-edited store, a restore or an older build can break it at any
261
+ * boot. Idempotent: a type that can write is left alone. One location is made `active` (the
262
+ * `<type>:default` row, else the lexicographically first id), persisted, and said loudly.
263
+ * The mode is read and written only through `storage-location-mode` (D385); an operator's
264
+ * `readonly`/`drain`/`disabled` is touched only when the alternative is a type that cannot write.
265
+ */
266
+ private repairWriteSets;
267
+ /**
291
268
  * Boot backfill (SP1): stamp `nodeId` on every persisted node-local
292
269
  * location that lacks one. Single-node deployments seeded their
293
270
  * filesystem locations before `nodeId` existed — they live on `hubNodeId`
@@ -3,11 +3,11 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-BmEptO1d.js");
6
+ const require_dist = require("../../dist-X-i__4Xc.js");
7
7
  const require_safe_buffer$1 = require("../../safe-buffer-D3aoa-7X.js");
8
8
  const require_x509_es = require("../../x509.es-WtnRNyYS.js");
9
- const require_agent_https = require("../../agent-https-pirjJaDw.js");
10
- const require_constants$8 = require("../../constants-o31-vUsL.js");
9
+ const require_agent_https = require("../../agent-https-CSHd24Sz.js");
10
+ const require_constants$8 = require("../../constants-BVIwtt_O.js");
11
11
  const require_src$1 = require("../../src-CnAqG6EF.js");
12
12
  let zod = require("zod");
13
13
  let node_crypto = require("node:crypto");