@fairfox/polly 0.58.0 → 0.59.0

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.
@@ -27,8 +27,8 @@ export type { MeshKeyring, MeshNetworkAdapterOptions, } from "./shared/lib/mesh-
27
27
  export { DEFAULT_MESH_KEY_ID, MeshNetworkAdapter, } from "./shared/lib/mesh-network-adapter";
28
28
  export type { MeshSignalingClientOptions, SignalingMessage as MeshSignalingMessage, } from "./shared/lib/mesh-signaling-client";
29
29
  export { MeshSignalingClient } from "./shared/lib/mesh-signaling-client";
30
- export type { MeshStateOptions } from "./shared/lib/mesh-state";
31
- export { $meshCounter, $meshList, $meshState, $meshText, configureMeshState, getLastConfiguredRepoPeerId, getMeshStateModuleId, isMeshStateConfigured, MESH_STATE_MODULE_ID, resetMeshState, wasMeshStateResolved, } from "./shared/lib/mesh-state";
30
+ export type { MeshStateLoadedRejectionBreadcrumb, MeshStateOptions, } from "./shared/lib/mesh-state";
31
+ export { $meshCounter, $meshList, $meshState, $meshText, configureMeshState, getLastConfiguredRepoPeerId, getLastLoadedRejection, getLazyInvocations, getLazyReachedRepo, getMeshStateModuleId, isMeshStateConfigured, MESH_STATE_MODULE_ID, resetMeshState, wasMeshStateResolved, } from "./shared/lib/mesh-state";
32
32
  export type { HandleSyncSnapshot, InFlightSyncSnapshot, MeshWebRTCAdapterOptions, SlotInitiationDecision, SlotInitiationRejectionReason, SweepSnapshot, SyncHandshakeAttemptSnapshot, SyncProgressEvent, TransportSnapshot, } from "./shared/lib/mesh-webrtc-adapter";
33
33
  export { DEFAULT_ICE_SERVERS, MeshWebRTCAdapter } from "./shared/lib/mesh-webrtc-adapter";
34
34
  export type { CreatePairingTokenOptions, PairingToken, } from "./shared/lib/pairing";
package/dist/src/mesh.js CHANGED
@@ -1779,6 +1779,10 @@ function configureMeshState(repo) {
1779
1779
  function resetMeshState() {
1780
1780
  defaultRepo = undefined;
1781
1781
  lastConfiguredRepoPeerId = undefined;
1782
+ meshStateEverResolved = false;
1783
+ lazyInvocations = 0;
1784
+ lazyReachedRepo = 0;
1785
+ lastLoadedRejection = undefined;
1782
1786
  }
1783
1787
  function isMeshStateConfigured() {
1784
1788
  return defaultRepo !== undefined;
@@ -1787,6 +1791,27 @@ var meshStateEverResolved = false;
1787
1791
  function wasMeshStateResolved() {
1788
1792
  return meshStateEverResolved;
1789
1793
  }
1794
+ var lazyInvocations = 0;
1795
+ function getLazyInvocations() {
1796
+ return lazyInvocations;
1797
+ }
1798
+ var lazyReachedRepo = 0;
1799
+ function getLazyReachedRepo() {
1800
+ return lazyReachedRepo;
1801
+ }
1802
+ var lastLoadedRejection;
1803
+ function getLastLoadedRejection() {
1804
+ return lastLoadedRejection;
1805
+ }
1806
+ function recordLoadedRejection(thrown) {
1807
+ const err = thrown instanceof Error ? thrown : new Error(typeof thrown === "string" ? thrown : String(thrown));
1808
+ lastLoadedRejection = {
1809
+ name: err.name,
1810
+ message: err.message,
1811
+ stack: err.stack,
1812
+ at: Date.now()
1813
+ };
1814
+ }
1790
1815
  function resolveRepo(option) {
1791
1816
  meshStateEverResolved = true;
1792
1817
  const repo = option ?? defaultRepo;
@@ -1808,26 +1833,39 @@ function deriveDocumentId(key) {
1808
1833
  function buildHandleFactory(repo, key, initialDoc) {
1809
1834
  const documentId = deriveDocumentId(key);
1810
1835
  return async () => {
1811
- const cached = repo.handles[documentId];
1812
- if (cached) {
1813
- await cached.whenReady(["ready", "unavailable"]);
1814
- if (cached.state === "ready") {
1815
- return cached;
1836
+ lazyInvocations++;
1837
+ try {
1838
+ const cached = repo.handles[documentId];
1839
+ lazyReachedRepo++;
1840
+ if (cached) {
1841
+ await cached.whenReady(["ready", "unavailable"]);
1842
+ if (cached.state === "ready") {
1843
+ return cached;
1844
+ }
1816
1845
  }
1846
+ const stored = await repo.storageSubsystem?.loadDoc(documentId);
1847
+ if (stored) {
1848
+ return repo.find(documentId, { allowableStates: ["ready"] });
1849
+ }
1850
+ const seeded = Automerge.save(Automerge.from(initialDoc));
1851
+ const handle = repo.import(seeded, { docId: documentId });
1852
+ handle.doneLoading();
1853
+ return handle;
1854
+ } catch (err) {
1855
+ recordLoadedRejection(err);
1856
+ throw err;
1817
1857
  }
1818
- const stored = await repo.storageSubsystem?.loadDoc(documentId);
1819
- if (stored) {
1820
- return repo.find(documentId, { allowableStates: ["ready"] });
1821
- }
1822
- const seeded = Automerge.save(Automerge.from(initialDoc));
1823
- const handle = repo.import(seeded, { docId: documentId });
1824
- handle.doneLoading();
1825
- return handle;
1826
1858
  };
1827
1859
  }
1860
+ function attachLoadedRejectionSink(primitive) {
1861
+ primitive.loaded.catch((err) => {
1862
+ recordLoadedRejection(err);
1863
+ });
1864
+ return primitive;
1865
+ }
1828
1866
  function $meshState(key, initialValue, options = {}) {
1829
1867
  const repo = resolveRepo(options.repo);
1830
- return $crdtState({
1868
+ return attachLoadedRejectionSink($crdtState({
1831
1869
  key,
1832
1870
  primitive: "meshState",
1833
1871
  initialValue,
@@ -1835,37 +1873,37 @@ function $meshState(key, initialValue, options = {}) {
1835
1873
  schemaVersion: options.schemaVersion,
1836
1874
  migrations: options.migrations,
1837
1875
  access: options.access
1838
- });
1876
+ }));
1839
1877
  }
1840
1878
  function $meshText(key, initialValue, options = {}) {
1841
1879
  const repo = resolveRepo(options.repo);
1842
- return $crdtText(key, initialValue, {
1880
+ return attachLoadedRejectionSink($crdtText(key, initialValue, {
1843
1881
  primitive: "meshState",
1844
1882
  getHandle: buildHandleFactory(repo, key, { text: initialValue }),
1845
1883
  schemaVersion: options.schemaVersion,
1846
1884
  migrations: options.migrations,
1847
1885
  access: options.access
1848
- });
1886
+ }));
1849
1887
  }
1850
1888
  function $meshCounter(key, initialValue, options = {}) {
1851
1889
  const repo = resolveRepo(options.repo);
1852
- return $crdtCounter(key, initialValue, {
1890
+ return attachLoadedRejectionSink($crdtCounter(key, initialValue, {
1853
1891
  primitive: "meshState",
1854
1892
  getHandle: buildHandleFactory(repo, key, {}),
1855
1893
  schemaVersion: options.schemaVersion,
1856
1894
  migrations: options.migrations,
1857
1895
  access: options.access
1858
- });
1896
+ }));
1859
1897
  }
1860
1898
  function $meshList(key, initialValue, options = {}) {
1861
1899
  const repo = resolveRepo(options.repo);
1862
- return $crdtList(key, initialValue, {
1900
+ return attachLoadedRejectionSink($crdtList(key, initialValue, {
1863
1901
  primitive: "meshState",
1864
1902
  getHandle: buildHandleFactory(repo, key, { items: initialValue }),
1865
1903
  schemaVersion: options.schemaVersion,
1866
1904
  migrations: options.migrations,
1867
1905
  access: options.access
1868
- });
1906
+ }));
1869
1907
  }
1870
1908
 
1871
1909
  // src/shared/lib/mesh-webrtc-adapter.ts
@@ -3026,7 +3064,10 @@ async function createMeshClient(options) {
3026
3064
  moduleId: getMeshStateModuleId(),
3027
3065
  configured: isMeshStateConfigured(),
3028
3066
  lastConfiguredRepoPeerId: getLastConfiguredRepoPeerId(),
3029
- wasResolved: wasMeshStateResolved()
3067
+ wasResolved: wasMeshStateResolved(),
3068
+ lazyInvocations: getLazyInvocations(),
3069
+ lazyReachedRepo: getLazyReachedRepo(),
3070
+ lastLoadedRejection: getLastLoadedRejection()
3030
3071
  },
3031
3072
  repoHandleCount: Object.keys(repo.handles).length,
3032
3073
  repoHandleIds: Object.keys(repo.handles)
@@ -3046,7 +3087,10 @@ async function createMeshClient(options) {
3046
3087
  moduleId: getMeshStateModuleId(),
3047
3088
  configured: isMeshStateConfigured(),
3048
3089
  lastConfiguredRepoPeerId: getLastConfiguredRepoPeerId(),
3049
- wasResolved: wasMeshStateResolved()
3090
+ wasResolved: wasMeshStateResolved(),
3091
+ lazyInvocations: getLazyInvocations(),
3092
+ lazyReachedRepo: getLazyReachedRepo(),
3093
+ lastLoadedRejection: getLastLoadedRejection()
3050
3094
  },
3051
3095
  repoHandleCount: knownHandleIds.length,
3052
3096
  repoHandleIds: knownHandleIds
@@ -3433,6 +3477,9 @@ export {
3433
3477
  isMeshStateConfigured,
3434
3478
  isBlobRef,
3435
3479
  getMeshStateModuleId,
3480
+ getLazyReachedRepo,
3481
+ getLazyInvocations,
3482
+ getLastLoadedRejection,
3436
3483
  getLastConfiguredRepoPeerId,
3437
3484
  generateSigningKeyPair,
3438
3485
  generateDocumentKey,
@@ -3483,4 +3530,4 @@ export {
3483
3530
  $meshCounter
3484
3531
  };
3485
3532
 
3486
- //# debugId=23078FA0DB4C154064756E2164756E21
3533
+ //# debugId=5E68DFAAE223E09564756E2164756E21