@interncom/diplomatic 0.8.2 → 0.8.4

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.
@@ -3,8 +3,6 @@ import { HostHandle, IHostConnectionInfo, IHostMetadata } from "../../shared/typ
3
3
  import type { HostStatsUpdate, IHostRow, IHostStore } from "../../types";
4
4
  export declare class MemoryHostStore<Handle extends HostHandle> implements IHostStore<Handle> {
5
5
  hosts: Map<string, IHostRow<Handle>>;
6
- /** Serializes recordStats so concurrent peeks do not drop bag/dupe deltas. */
7
- private statsChain;
8
6
  add(info: IHostConnectionInfo<Handle>): Promise<void>;
9
7
  touch(label: string, seq: number): Promise<void>;
10
8
  recordStats(label: string, u: HostStatsUpdate): Promise<void>;
@@ -83,10 +83,10 @@ export declare function msg2StoredMsgData({ head, body }: IMsgParts): IStoredMes
83
83
  */
84
84
  export declare function handleNotif<Handle extends HostHandle>(bytes: Uint8Array, { conn, store, enclave, host, crypto, onProgress, }: ISyncParams<Handle>, scheduleSync: () => void): Promise<void>;
85
85
  /**
86
- * Full host inventory (PEEK from seq 0): set absolute numBags/numDupes/lastSeq,
87
- * and optionally enqueue downloads (msgs on host missing locally) and/or
88
- * uploads (local msgs missing on host). Does not pull/push network beyond
89
- * peek — caller should sync() to drain queues.
86
+ * Full host inventory (PEEK from seq 0): set lastSeq; optionally enqueue
87
+ * downloads (msgs on host missing locally) and/or uploads (local msgs missing
88
+ * on host). Returns ephemeral bag tallies + msgcheck (not persisted). Does not
89
+ * pull/push beyond peek — caller should sync() to drain queues.
90
90
  *
91
91
  * lastSeq is set to the max bag seq in the inventory (0 if empty), including
92
92
  * rewind when the host has fewer bags than a prior cursor believed.
@@ -36,38 +36,16 @@ export interface ISeedStore {
36
36
  }
37
37
  export interface IHostRow<Handle extends HostHandle> extends IHostConnectionInfo<Handle>, Partial<IHostMetadata> {
38
38
  lastSeq: number;
39
- /**
40
- * Bags known on this host (full reconcile sets absolute; incremental peek
41
- * adds newly seen seqs).
42
- */
43
- numBags: number;
44
- /**
45
- * Extra bags beyond one per msg (`Σ max(0, bags_for_msg − 1)`). Absolute on
46
- * reconcile; +delta on peek when a new duplicate bag for a known msg is seen.
47
- */
48
- numDupes: number;
49
39
  }
50
40
  /**
51
- * Atomic host cursor + bag/dupe stats update (one store transaction).
52
- * Absolute fields replace; deltas add. `lastSeq` only advances; use
53
- * `setLastSeq` for a full-inventory absolute cursor (reconcile).
41
+ * Host row cursor write (one store transaction).
42
+ * `lastSeq` only advances unless `setLastSeq` is set.
54
43
  */
55
44
  export type HostStatsUpdate = {
56
45
  /** New lastSeq if greater than current (incremental peek/push). */
57
46
  lastSeq?: number;
58
47
  /** Absolute lastSeq, including rewind (full inventory). */
59
48
  setLastSeq?: number;
60
- /** Absolute bag count (full inventory). */
61
- numBags?: number;
62
- /** Absolute dupe count (full inventory). */
63
- numDupes?: number;
64
- /** Count of newly peeked bags to add to numBags. */
65
- bagDelta?: number;
66
- /**
67
- * Count of newly seen extra bags for a msg already on the host (duplicate
68
- * bags for the same msg) to add to numDupes.
69
- */
70
- dupeDelta?: number;
71
49
  };
72
50
  export interface IHostStore<Handle extends HostHandle> {
73
51
  add: (host: IHostConnectionInfo<Handle>) => Promise<void>;
@@ -77,10 +55,7 @@ export interface IHostStore<Handle extends HostHandle> {
77
55
  list: () => Promise<Iterable<IHostRow<Handle>>>;
78
56
  wipe: () => Promise<void>;
79
57
  touch: (label: string, seq: number) => Promise<void>;
80
- /**
81
- * Apply lastSeq / numBags / numDupes in one transaction so counts do not
82
- * drift vs the cursor under concurrent peek/push.
83
- */
58
+ /** Apply lastSeq updates in one transaction. */
84
59
  recordStats: (label: string, u: HostStatsUpdate) => Promise<void>;
85
60
  }
86
61
  /** Options for {@link IClient.reconcile}. */
@@ -91,21 +66,26 @@ export type ReconcileOpts = {
91
66
  push?: boolean;
92
67
  /**
93
68
  * After inventory, run {@link IClient.sync} to drain upload/download queues.
94
- * Default true. Pass false for inventory-only (counts + checksum).
69
+ * Default true. Pass false for inventory-only.
95
70
  */
96
71
  sync?: boolean;
97
72
  };
98
- /** Internal result of a full host inventory (not the public client API). */
99
- export type ReconcileResult = {
100
- /**
101
- * Set-checksum of distinct msgs on the host (archive keys; same construction
102
- * as {@link IClient.msgcheck}). Ephemeral — not stored on the host row.
103
- */
73
+ /**
74
+ * Result of {@link IClient.reconcile}: host msg checksum and bag tallies from
75
+ * the (post-drain) full inventory. Ephemeral — not persisted.
76
+ */
77
+ export type ReconcileReport = {
78
+ /** Distinct msgs on host (same construction as {@link IClient.msgcheck}). */
104
79
  msgcheck: Hash;
105
- bagCount: number;
106
- /** Distinct msgs among bags (dup bags for the same msg count once). */
107
- uniqueMsgs: number;
80
+ /** Total bags on host (includes duplicate bags for the same msg). */
81
+ numBags: number;
82
+ /** Extra bags beyond one per msg. */
108
83
  numDupes: number;
84
+ };
85
+ /** Full inventory details (internal; includes set-diff counts). */
86
+ export type ReconcileResult = ReconcileReport & {
87
+ /** Distinct msgs among bags. */
88
+ uniqueMsgs: number;
109
89
  /** Msgs on host not in local archive. */
110
90
  missingLocal: number;
111
91
  /** Local archive msgs not seen on host. */
@@ -312,13 +292,12 @@ export interface IClient<Handle extends HostHandle> {
312
292
  */
313
293
  countMsgs(apld?: ApldState): Promise<number>;
314
294
  /**
315
- * Full host inventory (peek from seq 0): set numBags/numDupes/lastSeq on the
316
- * host row; optionally enqueue downloads (`pull`) and/or uploads (`push`).
317
- * Returns ephemeral host msg checksum (distinct msgs on host; same as
318
- * {@link msgcheck}) for UI comparison with local archive. Call
319
- * {@link sync} to drain queues. Read counts via {@link hosts}.
295
+ * Full host inventory (peek from seq 0); optionally enqueue pull/push.
296
+ * Default drains via {@link sync}, then re-inventories. Returns ephemeral
297
+ * host msgcheck + numBags + numDupes (not persisted). Advances lastSeq only
298
+ * on the host row.
320
299
  */
321
- reconcile(hostLabel: string, opts?: ReconcileOpts): Promise<ValStat<Hash>>;
300
+ reconcile(hostLabel: string, opts?: ReconcileOpts): Promise<ValStat<ReconcileReport>>;
322
301
  wipe(): Promise<void>;
323
302
  import(file: File): Promise<Status>;
324
303
  export(filename: string, extension?: string): Promise<Status>;
@@ -2,7 +2,7 @@ import { IClock } from "../shared/clock";
2
2
  import { Status } from "../shared/consts";
3
3
  import type { EntityID, Hash, IDeleteParams, IEntRev, IHostConnectionInfo, IInsertParams, IMessageHead, IStateManager, IUpdateParams, MasterSeed, SerializedContent } from "../shared/types";
4
4
  import { type ValStat } from "../shared/valstat";
5
- import type { ApldState, IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore, IStoredMessage, ListMsgsOpts, ReconcileOpts } from "../types";
5
+ import type { ApldState, IClient, IDiplomaticClientState, IDiplomaticClientXferState, IHostRow, IStateEmitter, IStore, IStoredMessage, ListMsgsOpts, ReconcileOpts, ReconcileReport } from "../types";
6
6
  /**
7
7
  * Options for attaching to an app-owned sync Worker.
8
8
  *
@@ -121,9 +121,9 @@ export declare class WorkerClient implements IClient<URL> {
121
121
  countMsgs(apld?: ApldState): Promise<number>;
122
122
  /**
123
123
  * Full host inventory on the worker (network + crypto off main).
124
- * Returns ephemeral host msg checksum; host row stats in shared IDB.
124
+ * Returns ephemeral msgcheck + bag counts (not persisted).
125
125
  */
126
- reconcile(hostLabel: string, opts?: ReconcileOpts): Promise<ValStat<Hash>>;
126
+ reconcile(hostLabel: string, opts?: ReconcileOpts): Promise<ValStat<ReconcileReport>>;
127
127
  /** Archive checksum via worker (listKeys + sort + blake3 off main). */
128
128
  msgcheck(): Promise<Hash>;
129
129
  /**