| … | … | @@ -211,6 +211,7 @@ export class MetadataBase { |
| 211 | 211 | // ── Public API: generic ───────────────────────────────────── |
| 212 | 212 | |
| 213 | 213 | async append (op) { |
| 214 | if (!this._base) throw new Error('MetadataBase not ready') |
| 214 | 215 | await this._base.append(op) |
| 215 | 216 | } |
| 216 | 217 | |
| … | … | @@ -225,12 +226,14 @@ export class MetadataBase { |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | 228 | async getByKey (key) { |
| 229 | if (!this._base) return null |
| 228 | 230 | await this._base.update() |
| 229 | 231 | const entry = await this._base.view.get(key) |
| 230 | 232 | return entry ? entry.value : null |
| 231 | 233 | } |
| 232 | 234 | |
| 233 | 235 | async list (ns) { |
| 236 | if (!this._base) return [] |
| 234 | 237 | await this._base.update() |
| 235 | 238 | const results = [] |
| 236 | 239 | for await (const entry of this._base.view.createReadStream({ |
| … | … | @@ -289,6 +292,7 @@ export class MetadataBase { |
| 289 | 292 | // ── Writer management ─────────────────────────────────────── |
| 290 | 293 | |
| 291 | 294 | async addWriter (key) { |
| 295 | if (!this._base) return |
| 292 | 296 | const keyHex = Buffer.isBuffer(key) ? key.toString('hex') : key |
| 293 | 297 | await this._base.append({ ns: '_addWriter', key: keyHex, indexer: true, ts: Date.now() }) |
| 294 | 298 | } |
| … | … | @@ -315,6 +319,7 @@ export class MetadataBase { |
| 315 | 319 | // ── Writer exchange (Protomux) ────────────────────────────── |
| 316 | 320 | |
| 317 | 321 | _exchangeWriters (socket) { |
| 322 | if (!this._base) return |
| 318 | 323 | const mux = Protomux.from(socket) |
| 319 | 324 | if (!mux || !this._base.key) return |
| 320 | 325 | |
| … | … | @@ -375,6 +380,7 @@ export class MetadataBase { |
| 375 | 380 | // ── Lifecycle ─────────────────────────────────────────────── |
| 376 | 381 | |
| 377 | 382 | async update () { |
| 383 | if (!this._base) return |
| 378 | 384 | await this._base.update() |
| 379 | 385 | } |
| 380 | 386 | |