@fairfox/polly 0.66.0 → 0.69.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.
package/dist/src/mesh.js CHANGED
@@ -1419,13 +1419,13 @@ class MeshSignalingClient {
1419
1419
 
1420
1420
  // src/shared/lib/mesh-state.ts
1421
1421
  import {
1422
- Automerge,
1422
+ Automerge as Automerge3,
1423
1423
  interpretAsDocumentId
1424
1424
  } from "@automerge/automerge-repo/slim";
1425
1425
  import nacl3 from "tweetnacl";
1426
1426
 
1427
1427
  // src/shared/lib/crdt-specialised.ts
1428
- import { Counter, updateText } from "@automerge/automerge-repo/slim";
1428
+ import { Automerge, Counter, updateText } from "@automerge/automerge-repo/slim";
1429
1429
  import { effect, signal } from "@preact/signals";
1430
1430
 
1431
1431
  // src/shared/lib/migrate-primitive.ts
@@ -1650,6 +1650,14 @@ function createSpecialisedPrimitive(config) {
1650
1650
  loaded,
1651
1651
  get handle() {
1652
1652
  return currentHandle;
1653
+ },
1654
+ get changeCount() {
1655
+ if (!currentHandle)
1656
+ return;
1657
+ const doc = currentHandle.doc();
1658
+ if (!doc)
1659
+ return;
1660
+ return Automerge.getAllChanges(doc).length;
1653
1661
  }
1654
1662
  };
1655
1663
  }
@@ -1720,6 +1728,7 @@ function $crdtList(key, initialValue, options) {
1720
1728
  }
1721
1729
 
1722
1730
  // src/shared/lib/crdt-state.ts
1731
+ import { Automerge as Automerge2 } from "@automerge/automerge-repo/slim";
1723
1732
  import { effect as effect2, signal as signal2 } from "@preact/signals";
1724
1733
  function $crdtState(options) {
1725
1734
  if (migrationRegistry.isMarked(options.key, options.primitive)) {
@@ -1853,6 +1862,14 @@ function $crdtState(options) {
1853
1862
  loaded,
1854
1863
  get handle() {
1855
1864
  return currentHandle;
1865
+ },
1866
+ get changeCount() {
1867
+ if (!currentHandle)
1868
+ return;
1869
+ const doc = currentHandle.doc();
1870
+ if (!doc)
1871
+ return;
1872
+ return Automerge2.getAllChanges(doc).length;
1856
1873
  }
1857
1874
  };
1858
1875
  }
@@ -2071,6 +2088,31 @@ function buildHandleFactory(repo, key, initialDoc) {
2071
2088
  }
2072
2089
  };
2073
2090
  }
2091
+ var SEED_ACTOR_DOMAIN = "polly/meshState/seedActor/v1";
2092
+ function deriveSeedActor(documentId) {
2093
+ const docIdString = documentId;
2094
+ const digest = nacl3.hash(keyEncoder.encode(`${SEED_ACTOR_DOMAIN}:${docIdString}`));
2095
+ let hex = "";
2096
+ for (let i = 0;i < 16; i++) {
2097
+ hex += (digest[i] ?? 0).toString(16).padStart(2, "0");
2098
+ }
2099
+ return hex;
2100
+ }
2101
+ function seedDocumentBytes(documentId, initialDoc) {
2102
+ const disable = typeof process !== "undefined" && process.env?.["POLLY_113_DISABLE_FIX"] === "1";
2103
+ if (disable) {
2104
+ return Automerge3.save(Automerge3.from(initialDoc));
2105
+ }
2106
+ const actor = deriveSeedActor(documentId);
2107
+ const empty = Automerge3.init({ actor });
2108
+ const seeded = Automerge3.change(empty, { time: 0 }, (d) => {
2109
+ const source = initialDoc;
2110
+ for (const key of Object.keys(source)) {
2111
+ d[key] = source[key];
2112
+ }
2113
+ });
2114
+ return Automerge3.save(seeded);
2115
+ }
2074
2116
  async function loadOrSeed(repo, documentId, initialDoc, docIdString, setExitReason) {
2075
2117
  const loadPromise = repo.storageSubsystem?.loadDoc(documentId);
2076
2118
  const stored = loadPromise ? await withStorageTimeout("loadDoc", docIdString, loadPromise) : undefined;
@@ -2078,7 +2120,7 @@ async function loadOrSeed(repo, documentId, initialDoc, docIdString, setExitReas
2078
2120
  setExitReason("loaded-from-storage");
2079
2121
  return repo.find(documentId, { allowableStates: ["ready"] });
2080
2122
  }
2081
- const seeded = Automerge.save(Automerge.from(initialDoc));
2123
+ const seeded = seedDocumentBytes(documentId, initialDoc);
2082
2124
  const handle = repo.import(seeded, { docId: documentId });
2083
2125
  handle.doneLoading();
2084
2126
  setExitReason("seeded-and-imported");
@@ -3940,4 +3982,4 @@ export {
3940
3982
  $meshCounter
3941
3983
  };
3942
3984
 
3943
- //# debugId=E998FF56BA12701D64756E2164756E21
3985
+ //# debugId=516309C916BB154F64756E2164756E21