@interncom/diplomatic 0.3.3 → 0.4.0

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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Split items into request batches by soft byte budget; oversized alone.
3
+ *
4
+ * TODO: async generator instead of materializing all batches up front —
5
+ * minor here, but we should pipeline everything we can for max performance.
6
+ */
7
+ export declare function batchByBytes<T>(items: T[], sizeOf: (t: T) => number, limit: number): T[][];
@@ -19,16 +19,14 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
19
19
  private onScheduleSync?;
20
20
  connections: Map<string, DiplomaticClientAPI<Handle>>;
21
21
  /**
22
- * Serializes sync so doSync never overlaps, while coalescing stampedes:
23
- * concurrent sync() share one in-flight drain and at most one trailing
24
- * pass if more sync was requested mid-flight (see CoalesceTail).
22
+ * Serializes exec so concurrent drainApplyQueue / apply do not interleave
23
+ * markApplied (each job runs fully, in order).
25
24
  */
26
- private syncRuns;
25
+ private applyChain;
27
26
  /**
28
- * Serializes application of archived msgs so concurrent apply /
29
- * drainApplyQueue do not interleave markApplied (each job runs fully, in order).
27
+ * Coalesces overlapping sync() (one in flight + trailing pass).
30
28
  */
31
- private applyChain;
29
+ private syncRuns;
32
30
  clientState: IStateEmitter<IDiplomaticClientState>;
33
31
  xferState: IStateEmitter<IDiplomaticClientXferState>;
34
32
  /**
@@ -45,7 +43,7 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
45
43
  /** Latest progress; part of xferState for snapshot + subscribe. */
46
44
  private lastProgress;
47
45
  /**
48
- * Debounced sync after local writes (when not handing off via onScheduleSync).
46
+ * Debounced full sync after local writes (when not handing off via onScheduleSync).
49
47
  */
50
48
  private scheduledSync;
51
49
  constructor(clock: IClock, state: IStateManager, store: IStore<Handle>, transport: (host: IHostConnectionInfo<Handle>) => ITransport, crypto: ICrypto, forceSkewHandlingByDefault?: boolean, maxPushBytes?: number, maxPullBytes?: number,
@@ -60,13 +58,12 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
60
58
  private getClientState;
61
59
  private getXferState;
62
60
  /**
63
- * Persist msgs to the archive as unapplied (apld=false), apply via
64
- * IStateManager, mark applied, then optionally enqueue upload.
61
+ * Persist msgs (apld=false), exec into app state, then optionally enq upload.
65
62
  *
66
- * Order is intentional for crash safety:
67
- * 1) durable archive 2) apply + apld=true 3) upload queue
68
- * so we never upload something that never applied, and crash between
69
- * 1–2 is recovered by drainApplyQueue.
63
+ * Order (crash-safe):
64
+ * 1) durable archive 2) exec + apld=true 3) upload queue
65
+ * Exec is where the app validates the msg; only successes are pushed.
66
+ * Crash between 1–2 drainApplyQueue / exec stage recovers.
70
67
  */
71
68
  private apply;
72
69
  private enqueueApplyJob;
@@ -94,10 +91,8 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
94
91
  delete(eid: EntityID): Promise<ValStat<IMessageHead>>;
95
92
  genEID(id?: Uint8Array): Promise<ValStat<EntityID>>;
96
93
  /**
97
- * Catch up with hosts (peek → push → pull). Safe under concurrent callers:
98
- * overlapping sync() calls coalesce onto one shared run, with a trailing
99
- * re-run if anyone requested sync while a run was already in flight.
100
- * All waiters resolve with the Status of the final pass of that drain.
94
+ * Catch up: exec pending → per host peek → push → pull‖open exec.
95
+ * Overlapping sync() coalesce (+ trailing if demand mid-flight).
101
96
  */
102
97
  sync(): Promise<Status>;
103
98
  private doSync;
@@ -106,8 +101,7 @@ export declare class SyncClient<Handle extends HostHandle> implements IClient<Ha
106
101
  onProgress?: (index: number, total: number, status: Status) => void;
107
102
  }) => Promise<Status>;
108
103
  /**
109
- * After local apply + upload enqueue: either hand off to a peer (worker via
110
- * onScheduleSync — debounced there) or debounce sync on this client.
104
+ * After local exec + upload enqueue: hand off to worker peer or debounce sync.
111
105
  */
112
106
  private scheduleSync;
113
107
  /** Encode the local message archive; used by worker path (main saves file). */