@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.
package/dist/index.js CHANGED
@@ -11233,12 +11233,19 @@ var SerialChain = class {
11233
11233
  return run;
11234
11234
  }
11235
11235
  };
11236
- function coalesced(run) {
11236
+ function coalesced(run, observe) {
11237
11237
  let inFlight = false;
11238
11238
  let queued = false;
11239
11239
  const start = () => {
11240
11240
  inFlight = true;
11241
- void run().catch(() => void 0).finally(() => {
11241
+ let running;
11242
+ try {
11243
+ running = run();
11244
+ } catch {
11245
+ running = Promise.resolve();
11246
+ }
11247
+ observe?.(running);
11248
+ void running.catch(() => void 0).finally(() => {
11242
11249
  inFlight = false;
11243
11250
  if (!queued) return;
11244
11251
  queued = false;
@@ -12995,6 +13002,17 @@ var Receive = class {
12995
13002
  await flushAcks(deps, pending, epochOf);
12996
13003
  deps.refreshView();
12997
13004
  }
13005
+ /** One listing pass: process each entry, flushing and refreshing as it goes. */
13006
+ async drainPages(ctx, basis) {
13007
+ const { deps, engine, pending, stored, pageEpoch } = ctx;
13008
+ for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
13009
+ const storedBefore = stored.length;
13010
+ await this.processEntry(deps, engine, entry, pending, stored);
13011
+ if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
13012
+ if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
13013
+ }
13014
+ await flushAcks(deps, pending, pageEpoch);
13015
+ }
12998
13016
  async doDrain() {
12999
13017
  const deps = this.deps;
13000
13018
  this.lastRefreshAt = deps.now?.() ?? Date.now();
@@ -13006,13 +13024,7 @@ var Receive = class {
13006
13024
  const record = await deps.kv.get(STORE_KEYS.streamCursor("mailbox"));
13007
13025
  let basis = record !== null && record.syncEpoch === deps.syncEpoch() ? record : null;
13008
13026
  for (let pass = 0; pass < 2; pass++) {
13009
- for await (const entry of deps.delivery.incoming(basis === null ? void 0 : String(basis.cursor))) {
13010
- const storedBefore = stored.length;
13011
- await this.processEntry(deps, engine, entry, pending, stored);
13012
- if (pending.length >= ACK_BATCH_SIZE) await flushAcks(deps, pending, pageEpoch);
13013
- if (stored.length > storedBefore) await this.maybeRefresh(deps, pending, pageEpoch);
13014
- }
13015
- await flushAcks(deps, pending, pageEpoch);
13027
+ await this.drainPages({ deps, engine, pending, stored, pageEpoch }, basis);
13016
13028
  const served = deps.delivery.incomingEpoch();
13017
13029
  if (basis === null || served === null || served === basis.syncEpoch) break;
13018
13030
  await deps.kv.remove(STORE_KEYS.streamCursor("mailbox"));
@@ -13025,6 +13037,7 @@ var Receive = class {
13025
13037
  logger.warn("PaymentsV2", "receive ack flush failed \u2014 cursor holds at the acked prefix:", flushErr);
13026
13038
  });
13027
13039
  }
13040
+ if (stored.length > 0) deps.refreshView?.();
13028
13041
  return stored;
13029
13042
  }
13030
13043
  async processEntry(deps, engine, entry, pending, stored) {
@@ -13955,7 +13968,7 @@ function composeFacadeParts(deps, hooks) {
13955
13968
  const machineDeps = buildMachineDeps(deps, hooks, historyStore);
13956
13969
  const machineStores = createMachineStores(deps.kv);
13957
13970
  const heldStates = /* @__PURE__ */ new Map();
13958
- const refreshView = coalesced(() => view.delta());
13971
+ const refreshView = coalesced(() => view.delta(), hooks.track);
13959
13972
  return {
13960
13973
  ownPubkeyBytes,
13961
13974
  view,
@@ -14098,7 +14111,8 @@ var PaymentsFacade = class {
14098
14111
  const parts = composeFacadeParts(deps, {
14099
14112
  engine: () => this.engine(),
14100
14113
  send: (request) => this.send(request),
14101
- isActiveOp: (id) => this.activeMoneyOps.has(id)
14114
+ isActiveOp: (id) => this.activeMoneyOps.has(id),
14115
+ track: (op) => this.trackTail(op)
14102
14116
  });
14103
14117
  this.view = parts.view;
14104
14118
  this.wakeRefresh = parts.refreshView;
@@ -14238,7 +14252,6 @@ var PaymentsFacade = class {
14238
14252
  }
14239
14253
  async receive() {
14240
14254
  const transfers = await this.track(this.receiveLoop.drainOnce());
14241
- if (transfers.length > 0) this.trackTail(this.view.delta());
14242
14255
  return { transfers };
14243
14256
  }
14244
14257
  mint(coinId, amount) {
@@ -15633,6 +15646,7 @@ var WalletApiDeliveryPort = class {
15633
15646
  await this.settleClaims(acks, settled, outcomes);
15634
15647
  await this.settleRejects(acks, settled);
15635
15648
  } catch (err) {
15649
+ await this.addSeenAll(settled).catch(() => void 0);
15636
15650
  throw asRetryable(err);
15637
15651
  }
15638
15652
  await this.addSeenAll(settled);