@unicitylabs/sphere-sdk 0.14.11-dev.2 → 0.14.11-dev.3

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.
@@ -13005,16 +13005,28 @@ var Receive = class {
13005
13005
  this.unsubscribeWake?.();
13006
13006
  this.unsubscribeWake = null;
13007
13007
  }
13008
- /** Ask for a mirror refresh at most once per REFRESH_INTERVAL_MS. */
13009
- maybeRefresh(deps) {
13008
+ /**
13009
+ * Flush what has been accepted, then ask for a mirror refresh — at most once
13010
+ * per REFRESH_INTERVAL_MS.
13011
+ *
13012
+ * The flush is not incidental. A `claimed` ack is what materializes a token
13013
+ * into SERVER inventory, and acks otherwise sit queued until ACK_BATCH_SIZE
13014
+ * (200) — so for any ordinary drain, including the 54-token case this exists
13015
+ * for, refreshing before the flush would query an inventory holding none of
13016
+ * the tokens just accepted, and the balance would still only move at the end.
13017
+ * Ordering is preserved: store() still precedes the ack (§5.7).
13018
+ */
13019
+ async maybeRefresh(deps, pending, epochOf) {
13010
13020
  if (deps.refreshView === void 0) return;
13011
13021
  const now = deps.now?.() ?? Date.now();
13012
13022
  if (now - this.lastRefreshAt < REFRESH_INTERVAL_MS) return;
13013
13023
  this.lastRefreshAt = now;
13024
+ await flushAcks(deps, pending, epochOf);
13014
13025
  deps.refreshView();
13015
13026
  }
13016
13027
  async doDrain() {
13017
13028
  const deps = this.deps;
13029
+ this.lastRefreshAt = deps.now?.() ?? Date.now();
13018
13030
  const engine = deps.engine();
13019
13031
  const stored = [];
13020
13032
  const pending = [];
@@ -13024,9 +13036,10 @@ var Receive = class {
13024
13036
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
13025
13037
  for (let pass = 0; pass < 2; pass++) {
13026
13038
  for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
13039
+ const storedBefore = stored.length;
13027
13040
  await this.processEntry(deps, engine, entry, pending, stored);
13028
13041
  if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
13029
- if (stored.length > 0) this.maybeRefresh(deps);
13042
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
13030
13043
  }
13031
13044
  await flushAcks(deps, pending, pageEpoch);
13032
13045
  const served = deps.delivery.incomingEpoch();