@ping-app/ping-openmls-sdk 0.10.6 → 0.10.7

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/worker.cjs CHANGED
@@ -283,11 +283,17 @@ function changedHoldings(before, after) {
283
283
  }
284
284
 
285
285
  // src/catch-up-pass.ts
286
+ var STORE_MOVED = "store moved: ";
287
+ function isStoreMoved(e) {
288
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
289
+ return text !== null && text.startsWith(STORE_MOVED);
290
+ }
286
291
  function catchUpPass(deps) {
287
292
  const seen = /* @__PURE__ */ new Set();
288
293
  const delivered = [];
289
294
  let pending = null;
290
295
  let relisted = false;
296
+ let stopped = false;
291
297
  const sortedUnseen = (ids) => ids.filter((id) => !seen.has(conversationKey(id))).sort((a, b) => conversationKey(a) < conversationKey(b) ? -1 : 1);
292
298
  const initial = async () => {
293
299
  const heads = await deps.fetchHeads();
@@ -298,6 +304,16 @@ function catchUpPass(deps) {
298
304
  return sortedUnseen(behind);
299
305
  };
300
306
  return async () => {
307
+ if (stopped) return false;
308
+ if (pending === null) {
309
+ try {
310
+ await deps.door();
311
+ } catch (e) {
312
+ stopped = true;
313
+ deps.finish(false, e);
314
+ return false;
315
+ }
316
+ }
301
317
  try {
302
318
  if (pending === null) pending = await initial();
303
319
  if (pending.length === 0 && !relisted) {
@@ -310,6 +326,13 @@ function catchUpPass(deps) {
310
326
  }
311
327
  const id = pending[0];
312
328
  if (id === void 0) {
329
+ try {
330
+ await deps.door();
331
+ } catch (e) {
332
+ stopped = true;
333
+ deps.finish(false, e);
334
+ return false;
335
+ }
313
336
  deps.finish(true, delivered);
314
337
  return false;
315
338
  }
@@ -319,7 +342,12 @@ function catchUpPass(deps) {
319
342
  for (const m of page.messages) delivered.push(m);
320
343
  deps.onPage(page);
321
344
  more = page.has_more;
322
- } catch {
345
+ } catch (e) {
346
+ if (isStoreMoved(e)) {
347
+ stopped = true;
348
+ deps.finish(false, e);
349
+ return false;
350
+ }
323
351
  }
324
352
  if (!more) {
325
353
  seen.add(conversationKey(id));
@@ -787,6 +815,12 @@ function catchUpPassStepper(msg) {
787
815
  return false;
788
816
  }
789
817
  pass = catchUpPass({
818
+ // The client's door (ruling V1993): a guarded call that does nothing
819
+ // on a live client (no id, so no row and no checkpoint) and rejects
820
+ // with the typed stop on a client that failed closed.
821
+ door: async () => {
822
+ await ensureClient().confirmApplied([]);
823
+ },
790
824
  listConversationIds: () => ensureClient().listConversations().map((meta) => meta.id),
791
825
  fetchHeads: async () => transportFeatures.fetchLogHeads ? await fetchLogHeadsProxy() ?? null : null,
792
826
  conversationsBehind: (heads) => ensureClient().conversationsBehind(heads),
@@ -1054,6 +1088,16 @@ async function dispatchRequest(msg) {
1054
1088
  return null;
1055
1089
  });
1056
1090
  }
1091
+ case "discardPendingRoot": {
1092
+ return accountExclusive(async () => {
1093
+ const store = pendingStore();
1094
+ return (0, import_ping_wasm.discardPendingRoot)(
1095
+ makeProxyStorage(msg.storageFeatures),
1096
+ store,
1097
+ msg.slot
1098
+ );
1099
+ });
1100
+ }
1057
1101
  // The restore as a rotation: the same Worker that never runs a client.
1058
1102
  case "openBackupForRestore": {
1059
1103
  accountWorker();