@unicitylabs/sphere-sdk 0.14.11-dev.7 → 0.14.11-dev.8

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.
@@ -11303,12 +11303,19 @@ var SerialChain = class {
11303
11303
  return run;
11304
11304
  }
11305
11305
  };
11306
- function coalesced(run) {
11306
+ function coalesced(run, observe) {
11307
11307
  let inFlight = false;
11308
11308
  let queued = false;
11309
11309
  const start = () => {
11310
11310
  inFlight = true;
11311
- void run().catch(() => void 0).finally(() => {
11311
+ let running;
11312
+ try {
11313
+ running = run();
11314
+ } catch {
11315
+ running = Promise.resolve();
11316
+ }
11317
+ observe?.(running);
11318
+ void running.catch(() => void 0).finally(() => {
11312
11319
  inFlight = false;
11313
11320
  if (!queued) return;
11314
11321
  queued = false;
@@ -13065,6 +13072,17 @@ var Receive = class {
13065
13072
  await flushAcks(deps, pending, epochOf);
13066
13073
  deps.refreshView();
13067
13074
  }
13075
+ /** One listing pass: process each entry, flushing and refreshing as it goes. */
13076
+ async drainPages(ctx, basis) {
13077
+ const { deps, engine, pending, stored, pageEpoch } = ctx;
13078
+ for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
13079
+ const storedBefore = stored.length;
13080
+ await this.processEntry(deps, engine, entry, pending, stored);
13081
+ if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
13082
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
13083
+ }
13084
+ await flushAcks(deps, pending, pageEpoch);
13085
+ }
13068
13086
  async doDrain() {
13069
13087
  const deps = this.deps;
13070
13088
  this.lastRefreshAt = deps.now?.() ?? Date.now();
@@ -13076,13 +13094,7 @@ var Receive = class {
13076
13094
  const record = await deps.kv.get(STORE_KEYS.streamCursor("mailbox"));
13077
13095
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
13078
13096
  for (let pass = 0; pass < 2; pass++) {
13079
- for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
13080
- const storedBefore = stored.length;
13081
- await this.processEntry(deps, engine, entry, pending, stored);
13082
- if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
13083
- if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
13084
- }
13085
- await flushAcks(deps, pending, pageEpoch);
13097
+ await this.drainPages({ deps, engine, pending, stored, pageEpoch }, basis);
13086
13098
  const served = deps.delivery.incomingEpoch();
13087
13099
  if (basis === null || served === null || served === basis.syncEpoch) break;
13088
13100
  await deps.kv.remove(STORE_KEYS.streamCursor("mailbox"));
@@ -13095,6 +13107,7 @@ var Receive = class {
13095
13107
  logger.warn("PaymentsV2", "receive ack flush failed \u2014 cursor holds at the acked prefix:", flushErr);
13096
13108
  });
13097
13109
  }
13110
+ if (stored.length > 0) deps.refreshView?.();
13098
13111
  return stored;
13099
13112
  }
13100
13113
  async processEntry(deps, engine, entry, pending, stored) {
@@ -14025,7 +14038,7 @@ function composeFacadeParts(deps, hooks) {
14025
14038
  const machineDeps = buildMachineDeps(deps, hooks, historyStore);
14026
14039
  const machineStores = createMachineStores(deps.kv);
14027
14040
  const heldStates = /* @__PURE__ */ new Map();
14028
- const refreshView = coalesced(() => view.delta());
14041
+ const refreshView = coalesced(() => view.delta(), hooks.track);
14029
14042
  return {
14030
14043
  ownPubkeyBytes,
14031
14044
  view,
@@ -14168,7 +14181,8 @@ var PaymentsFacade = class {
14168
14181
  const parts = composeFacadeParts(deps, {
14169
14182
  engine: () => this.engine(),
14170
14183
  send: (request) => this.send(request),
14171
- isActiveOp: (id) => this.activeMoneyOps.has(id)
14184
+ isActiveOp: (id) => this.activeMoneyOps.has(id),
14185
+ track: (op) => this.trackTail(op)
14172
14186
  });
14173
14187
  this.view = parts.view;
14174
14188
  this.wakeRefresh = parts.refreshView;
@@ -14308,7 +14322,6 @@ var PaymentsFacade = class {
14308
14322
  }
14309
14323
  async receive() {
14310
14324
  const transfers = await this.track(this.receiveLoop.drainOnce());
14311
- if (transfers.length > 0) this.trackTail(this.view.delta());
14312
14325
  return { transfers };
14313
14326
  }
14314
14327
  mint(coinId, amount) {
@@ -15703,6 +15716,7 @@ var WalletApiDeliveryPort = class {
15703
15716
  await this.settleClaims(acks, settled, outcomes);
15704
15717
  await this.settleRejects(acks, settled);
15705
15718
  } catch (err) {
15719
+ await this.addSeenAll(settled).catch(() => void 0);
15706
15720
  throw asRetryable(err);
15707
15721
  }
15708
15722
  await this.addSeenAll(settled);