@backloghq/opslog 0.4.0 → 0.4.1

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/store.d.ts CHANGED
@@ -47,18 +47,19 @@ export declare class Store<T = Record<string, unknown>> {
47
47
  loadArchive(segment: string): Promise<Map<string, T>>;
48
48
  stats(): StoreStats;
49
49
  /**
50
- * Reload state from the backend (multi-writer mode).
51
- * Re-reads the manifest, snapshot, and all agent WAL files.
52
- * Use this to pick up writes from other agents.
50
+ * Reload state from the backend.
51
+ * In multi-writer mode: re-reads manifest, snapshot, and all agent WAL files.
52
+ * In single-writer/readOnly mode: re-reads the active ops file for new entries.
53
+ * Use this to pick up writes from other agents or processes.
53
54
  */
54
55
  refresh(): Promise<void>;
55
56
  private watchTimer;
56
57
  private watchCallback;
57
58
  /**
58
- * Tail the WAL for new operations. Re-reads the active ops file
59
- * and replays any new operations since the last known count.
59
+ * Tail the WAL for new operations.
60
+ * In single-writer/readOnly: re-reads the active ops file for new entries.
61
+ * In multi-writer: re-reads ALL agent WAL files from the manifest.
60
62
  * Returns the newly applied operations.
61
- * Works in any mode (single-writer readOnly, multi-writer, etc).
62
63
  */
63
64
  tail(): Promise<Operation<T>[]>;
64
65
  /**
package/dist/store.js CHANGED
@@ -299,30 +299,41 @@ export class Store {
299
299
  };
300
300
  }
301
301
  /**
302
- * Reload state from the backend (multi-writer mode).
303
- * Re-reads the manifest, snapshot, and all agent WAL files.
304
- * Use this to pick up writes from other agents.
302
+ * Reload state from the backend.
303
+ * In multi-writer mode: re-reads manifest, snapshot, and all agent WAL files.
304
+ * In single-writer/readOnly mode: re-reads the active ops file for new entries.
305
+ * Use this to pick up writes from other agents or processes.
305
306
  */
306
307
  async refresh() {
307
308
  this.ensureOpen();
308
- if (!this.isMultiWriter()) {
309
- throw new Error("refresh() is only available in multi-writer mode");
309
+ if (this.isMultiWriter()) {
310
+ return this.serialize(() => this._refresh());
310
311
  }
311
- return this.serialize(() => this._refresh());
312
+ // Single-writer / readOnly: just tail the active ops file
313
+ await this.tail();
312
314
  }
313
315
  // --- WAL tailing ---
314
316
  watchTimer = null;
315
317
  watchCallback = null;
316
318
  /**
317
- * Tail the WAL for new operations. Re-reads the active ops file
318
- * and replays any new operations since the last known count.
319
+ * Tail the WAL for new operations.
320
+ * In single-writer/readOnly: re-reads the active ops file for new entries.
321
+ * In multi-writer: re-reads ALL agent WAL files from the manifest.
319
322
  * Returns the newly applied operations.
320
- * Works in any mode (single-writer readOnly, multi-writer, etc).
321
323
  */
322
324
  async tail() {
323
325
  this.ensureOpen();
324
326
  const prevCount = this.ops.length;
325
- // Re-read the ops file for new entries
327
+ if (this.isMultiWriter()) {
328
+ // Multi-writer: full refresh to pick up all agents' writes
329
+ await this.serialize(() => this._refresh());
330
+ // Return the difference
331
+ if (this.ops.length > prevCount) {
332
+ return this.ops.slice(prevCount);
333
+ }
334
+ return [];
335
+ }
336
+ // Single-writer / readOnly: just re-read our ops file
326
337
  const allOps = (await this.backend.readOps(this.activeOpsPath));
327
338
  if (allOps.length <= prevCount)
328
339
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backloghq/opslog",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Embedded event-sourced document store. Append-only operation log with immutable snapshots, zero native dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",