@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.
@@ -3233,16 +3233,28 @@ var Receive = class {
3233
3233
  this.unsubscribeWake?.();
3234
3234
  this.unsubscribeWake = null;
3235
3235
  }
3236
- /** Ask for a mirror refresh at most once per REFRESH_INTERVAL_MS. */
3237
- maybeRefresh(deps) {
3236
+ /**
3237
+ * Flush what has been accepted, then ask for a mirror refresh — at most once
3238
+ * per REFRESH_INTERVAL_MS.
3239
+ *
3240
+ * The flush is not incidental. A `claimed` ack is what materializes a token
3241
+ * into SERVER inventory, and acks otherwise sit queued until ACK_BATCH_SIZE
3242
+ * (200) — so for any ordinary drain, including the 54-token case this exists
3243
+ * for, refreshing before the flush would query an inventory holding none of
3244
+ * the tokens just accepted, and the balance would still only move at the end.
3245
+ * Ordering is preserved: store() still precedes the ack (§5.7).
3246
+ */
3247
+ async maybeRefresh(deps, pending, epochOf) {
3238
3248
  if (deps.refreshView === void 0) return;
3239
3249
  const now = deps.now?.() ?? Date.now();
3240
3250
  if (now - this.lastRefreshAt < REFRESH_INTERVAL_MS) return;
3241
3251
  this.lastRefreshAt = now;
3252
+ await flushAcks(deps, pending, epochOf);
3242
3253
  deps.refreshView();
3243
3254
  }
3244
3255
  async doDrain() {
3245
3256
  const deps = this.deps;
3257
+ this.lastRefreshAt = deps.now?.() ?? Date.now();
3246
3258
  const engine = deps.engine();
3247
3259
  const stored = [];
3248
3260
  const pending = [];
@@ -3252,9 +3264,10 @@ var Receive = class {
3252
3264
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
3253
3265
  for (let pass = 0; pass < 2; pass++) {
3254
3266
  for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
3267
+ const storedBefore = stored.length;
3255
3268
  await this.processEntry(deps, engine, entry, pending, stored);
3256
3269
  if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
3257
- if (stored.length > 0) this.maybeRefresh(deps);
3270
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
3258
3271
  }
3259
3272
  await flushAcks(deps, pending, pageEpoch);
3260
3273
  const served = deps.delivery.incomingEpoch();