@tensorix/metahub 0.5.1 → 0.5.2

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.
@@ -411,6 +411,10 @@ var DOMAIN = {
411
411
  blob_policy: {
412
412
  table: "blob_policy",
413
413
  cols: new Set(["full_nodes", "redundancy", "__deleted"])
414
+ },
415
+ nodes: {
416
+ table: "nodes",
417
+ cols: new Set(["label", "platform", "form", "app", "first_seen", "__deleted"])
414
418
  }
415
419
  };
416
420
  var RECORD_META = new Set(["database_id", "created_hlc", "order_key", "__deleted"]);
@@ -428,7 +432,8 @@ var NOT_NULL_ZERO_COLS = new Set([
428
432
  "sites:spa",
429
433
  "site_channels:__deleted",
430
434
  "site_files:__deleted",
431
- "blob_policy:__deleted"
435
+ "blob_policy:__deleted",
436
+ "nodes:__deleted"
432
437
  ]);
433
438
  function decodeMaterializeValue(dataset, col, valueJson) {
434
439
  if (valueJson !== null)
@@ -2509,6 +2514,22 @@ CREATE TABLE IF NOT EXISTS blob_policy (
2509
2514
  redundancy TEXT, -- 'all' | 'any'
2510
2515
  __deleted INTEGER NOT NULL DEFAULT 0
2511
2516
  );
2517
+
2518
+ -- Synced device roster (system tier, see tables.ts): one row per node id, written
2519
+ -- by the device itself on open (describeSelf) and by anyone who renames it.
2520
+ -- Replicates so every device shows the same name and icon for a peer — the only
2521
+ -- record a purely bucket-joined device leaves besides its oplog stream. Each
2522
+ -- column is its own LWW register, so a rename and a platform refresh never
2523
+ -- clobber each other. meta.node_label survives as a node-local read fallback.
2524
+ CREATE TABLE IF NOT EXISTS nodes (
2525
+ id TEXT PRIMARY KEY, -- node_id
2526
+ label TEXT, -- shared display name; any device may set it
2527
+ platform TEXT, -- macos | windows | linux | ios | android | web
2528
+ form TEXT, -- laptop | desktop | phone | server | browser
2529
+ app TEXT, -- cli | server | desktop | web
2530
+ first_seen INTEGER, -- epoch ms of the device's first self-description
2531
+ __deleted INTEGER NOT NULL DEFAULT 0
2532
+ );
2512
2533
  `;
2513
2534
  var FTS_SCHEMA = `
2514
2535
  CREATE VIRTUAL TABLE IF NOT EXISTS search_fts USING fts5(
@@ -3125,22 +3146,28 @@ function migrateSitesAccess(db) {
3125
3146
  backfill("public_grants", "NULL");
3126
3147
  }
3127
3148
  }
3128
- var SITE_CHANNELS_REPLAY_KEY = "site_channels_replay_seq";
3129
- function migrateSiteChannels(db) {
3130
- if (!tableExists3(db, "site_channels"))
3149
+ function replayDataset(db, dataset) {
3150
+ if (!tableExists3(db, dataset))
3131
3151
  return;
3132
- const wm = db.query("SELECT value FROM meta WHERE key = ?").get(SITE_CHANNELS_REPLAY_KEY);
3152
+ const key = `${dataset}_replay_seq`;
3153
+ const wm = db.query("SELECT value FROM meta WHERE key = ?").get(key);
3133
3154
  const since = wm ? Number(wm.value) : 0;
3134
3155
  const changes = db.query(`SELECT seq, ${CHANGE_SELECT} FROM crdt_changes
3135
- WHERE dataset = 'site_channels' AND seq > ? ORDER BY seq`).all(since);
3156
+ WHERE dataset = ? AND seq > ? ORDER BY seq`).all(dataset, since);
3136
3157
  if (changes.length === 0)
3137
3158
  return;
3138
3159
  db.transaction((rows) => {
3139
3160
  for (const change of rows)
3140
3161
  applyChange(db, change);
3141
- db.query("INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value").run(SITE_CHANNELS_REPLAY_KEY, String(rows[rows.length - 1].seq));
3162
+ db.query("INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value").run(key, String(rows[rows.length - 1].seq));
3142
3163
  })(changes);
3143
3164
  }
3165
+ function migrateSiteChannels(db) {
3166
+ replayDataset(db, "site_channels");
3167
+ }
3168
+ function migrateNodes(db) {
3169
+ replayDataset(db, "nodes");
3170
+ }
3144
3171
  function initSchema(db) {
3145
3172
  runSchema(db);
3146
3173
  migrateOplog(db);
@@ -3155,6 +3182,7 @@ function initSchema(db) {
3155
3182
  migrateShares(db);
3156
3183
  migrateSitesAccess(db);
3157
3184
  migrateSiteChannels(db);
3185
+ migrateNodes(db);
3158
3186
  }
3159
3187
 
3160
3188
  // src/core/sync/partition.ts