@fairfox/polly 0.77.3 → 0.79.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.
Files changed (87) hide show
  1. package/dist/cli/polly.js +46 -3
  2. package/dist/cli/polly.js.map +3 -3
  3. package/dist/src/background/index.js.map +3 -3
  4. package/dist/src/background/message-router.js.map +3 -3
  5. package/dist/src/client/index.js +137 -32
  6. package/dist/src/client/index.js.map +6 -5
  7. package/dist/src/client/wrapper.d.ts +39 -2
  8. package/dist/src/elysia/index.js +22 -3
  9. package/dist/src/elysia/index.js.map +5 -5
  10. package/dist/src/elysia/route-match.d.ts +13 -0
  11. package/dist/src/index.d.ts +1 -1
  12. package/dist/src/index.js +12 -2
  13. package/dist/src/index.js.map +7 -7
  14. package/dist/src/mesh.js +87 -46
  15. package/dist/src/mesh.js.map +12 -11
  16. package/dist/src/peer.js +7 -3
  17. package/dist/src/peer.js.map +6 -6
  18. package/dist/src/polly-ui/Badge.d.ts +5 -0
  19. package/dist/src/polly-ui/Button.d.ts +31 -6
  20. package/dist/src/polly-ui/Dropdown.d.ts +6 -0
  21. package/dist/src/polly-ui/Select.d.ts +11 -1
  22. package/dist/src/polly-ui/TextInput.d.ts +30 -0
  23. package/dist/src/polly-ui/index.css +10 -0
  24. package/dist/src/polly-ui/index.js +81 -32
  25. package/dist/src/polly-ui/index.js.map +10 -10
  26. package/dist/src/polly-ui/styles.css +10 -0
  27. package/dist/src/shared/adapters/index.js.map +3 -3
  28. package/dist/src/shared/lib/context-helpers.js.map +3 -3
  29. package/dist/src/shared/lib/mesh-client.d.ts +38 -0
  30. package/dist/src/shared/lib/mesh-signaling-client.d.ts +6 -5
  31. package/dist/src/shared/lib/mesh-state.d.ts +21 -0
  32. package/dist/src/shared/lib/message-bus.js.map +3 -3
  33. package/dist/src/shared/lib/peer-relay-adapter.d.ts +5 -0
  34. package/dist/src/shared/lib/peer-repo-server.d.ts +15 -0
  35. package/dist/src/shared/lib/resource.js +11 -2
  36. package/dist/src/shared/lib/resource.js.map +6 -6
  37. package/dist/src/shared/lib/state.d.ts +20 -0
  38. package/dist/src/shared/lib/state.js +11 -1
  39. package/dist/src/shared/lib/state.js.map +5 -5
  40. package/dist/src/shared/state/app-state.js +10 -1
  41. package/dist/src/shared/state/app-state.js.map +5 -5
  42. package/dist/tools/init/src/cli.js +23 -2
  43. package/dist/tools/init/src/cli.js.map +4 -4
  44. package/dist/tools/init/templates/pwa/package.json.template +1 -1
  45. package/dist/tools/init/templates/pwa/src/service-worker.ts.template +26 -15
  46. package/dist/tools/init/templates/pwa/src/shared-worker.ts.template +13 -3
  47. package/dist/tools/init/templates/pwa/tsconfig.json.template +2 -2
  48. package/dist/tools/init/templates/pwa/tsconfig.worker.json.template +17 -0
  49. package/dist/tools/test/src/browser/index.js +5 -2
  50. package/dist/tools/test/src/browser/index.js.map +3 -3
  51. package/dist/tools/test/src/contrast/index.js +20 -15
  52. package/dist/tools/test/src/contrast/index.js.map +3 -3
  53. package/dist/tools/test/src/e2e-cli/index.d.ts +10 -0
  54. package/dist/tools/test/src/e2e-cli/run-cli.d.ts +25 -0
  55. package/dist/tools/test/src/e2e-cli/with-temp-dir.d.ts +15 -0
  56. package/dist/tools/test/src/e2e-mesh/index.js +12 -7
  57. package/dist/tools/test/src/e2e-mesh/index.js.map +4 -4
  58. package/dist/tools/test/src/e2e-mesh/launch-peer.d.ts +7 -1
  59. package/dist/tools/test/src/e2e-relay/index.d.ts +12 -0
  60. package/dist/tools/test/src/e2e-relay/wait-for-relay-convergence.d.ts +27 -0
  61. package/dist/tools/test/src/e2e-relay/with-repo-server.d.ts +24 -0
  62. package/dist/tools/test/src/e2e-shared/assert.d.ts +18 -0
  63. package/dist/tools/test/src/e2e-shared/contract.d.ts +40 -0
  64. package/dist/tools/test/src/e2e-shared/index.d.ts +2 -0
  65. package/dist/tools/test/src/tiers/args.d.ts +23 -0
  66. package/dist/tools/test/src/tiers/cli.d.ts +2 -0
  67. package/dist/tools/test/src/tiers/cli.js +490 -0
  68. package/dist/tools/test/src/tiers/cli.js.map +16 -0
  69. package/dist/tools/test/src/tiers/detect.d.ts +12 -0
  70. package/dist/tools/test/src/tiers/discover.d.ts +2 -0
  71. package/dist/tools/test/src/tiers/engine.d.ts +3 -0
  72. package/dist/tools/test/src/tiers/index.d.ts +14 -0
  73. package/dist/tools/test/src/tiers/protocol.d.ts +10 -0
  74. package/dist/tools/test/src/tiers/reporter.d.ts +12 -0
  75. package/dist/tools/test/src/tiers/types.d.ts +94 -0
  76. package/dist/tools/test/src/tiers/worker.d.ts +2 -0
  77. package/dist/tools/test/src/tiers/worker.js +60 -0
  78. package/dist/tools/test/src/tiers/worker.js.map +12 -0
  79. package/dist/tools/verify/src/cli.js +322 -27
  80. package/dist/tools/verify/src/cli.js.map +13 -10
  81. package/dist/tools/verify/src/config.d.ts +10 -0
  82. package/dist/tools/verify/src/config.js.map +2 -2
  83. package/dist/tools/verify/src/stryker/index.js +20 -11
  84. package/dist/tools/verify/src/stryker/index.js.map +3 -3
  85. package/dist/tools/visualize/src/cli.js +8 -5
  86. package/dist/tools/visualize/src/cli.js.map +4 -4
  87. package/package.json +16 -6
package/dist/src/mesh.js CHANGED
@@ -257,6 +257,17 @@ var init_encryption = __esm(() => {
257
257
  };
258
258
  });
259
259
 
260
+ // src/shared/lib/guards.ts
261
+ function hasKeyInObject(input, key) {
262
+ return typeof input === "object" && input !== null && Object.hasOwn(input, key);
263
+ }
264
+ function isRecord(input) {
265
+ return typeof input === "object" && input !== null && !Array.isArray(input);
266
+ }
267
+ function assertNever(value) {
268
+ throw new Error(`assertNever: unexpected value ${JSON.stringify(value)}`);
269
+ }
270
+
260
271
  // src/shared/lib/wasm-init.ts
261
272
  import wasmPath from "@automerge/automerge/automerge.wasm";
262
273
  import { initializeWasm } from "@automerge/automerge-repo/slim";
@@ -437,7 +448,7 @@ class IndexedDBBlobCache {
437
448
  totalSize += value.size;
438
449
  if (!value.pinned) {
439
450
  candidates.push({
440
- hash: key,
451
+ hash: String(key),
441
452
  accessedAt: value.accessedAt,
442
453
  size: value.size
443
454
  });
@@ -1251,6 +1262,10 @@ class MeshNetworkAdapter extends NetworkAdapter {
1251
1262
  return;
1252
1263
  }
1253
1264
  const tag = payload[0];
1265
+ if (tag === undefined) {
1266
+ emitMeshDiagnostic({ kind: "drop:empty-control-payload", senderId });
1267
+ return;
1268
+ }
1254
1269
  const body = payload.subarray(1);
1255
1270
  switch (tag) {
1256
1271
  case MESH_CONTROL_TYPE.Sync:
@@ -2476,15 +2491,17 @@ function partitionStats(report) {
2476
2491
  retransmittedPacketsSent: undefined,
2477
2492
  retransmittedBytesSent: undefined
2478
2493
  };
2479
- const iter = report.values?.() ?? [];
2494
+ const iter = hasStatsIterator(report) ? report.values() : [];
2480
2495
  for (const raw of iter) {
2481
- if (!raw || typeof raw !== "object")
2496
+ if (!isRecord(raw))
2482
2497
  continue;
2483
- const stat = raw;
2484
- ingestStat(stat, out);
2498
+ ingestStat(raw, out);
2485
2499
  }
2486
2500
  return out;
2487
2501
  }
2502
+ function hasStatsIterator(report) {
2503
+ return report !== null && typeof report === "object" && "values" in report && typeof report.values === "function";
2504
+ }
2488
2505
  function ingestStat(stat, out) {
2489
2506
  const id = String(stat["id"]);
2490
2507
  switch (stat["type"]) {
@@ -3630,11 +3647,13 @@ function decodeRevocationSummary(bytes) {
3630
3647
  if (!item || typeof item !== "object") {
3631
3648
  throw new Error(`decodeRevocationSummary: entry ${index} is not an object`);
3632
3649
  }
3633
- const e = item;
3634
- if (typeof e.r !== "string" || typeof e.i !== "string" || typeof e.t !== "number") {
3650
+ const r = "r" in item ? item.r : undefined;
3651
+ const i = "i" in item ? item.i : undefined;
3652
+ const t = "t" in item ? item.t : undefined;
3653
+ if (typeof r !== "string" || typeof i !== "string" || typeof t !== "number") {
3635
3654
  throw new Error(`decodeRevocationSummary: entry ${index} has missing or wrong-typed fields`);
3636
3655
  }
3637
- return { revokedPeerId: e.r, issuerPeerId: e.i, issuedAt: e.t };
3656
+ return { revokedPeerId: r, issuerPeerId: i, issuedAt: t };
3638
3657
  });
3639
3658
  }
3640
3659
  function compareSummaryEntries(a, b) {
@@ -3761,6 +3780,39 @@ function findLazyWrapperDocIdDuplicates(records) {
3761
3780
  }
3762
3781
  return duplicates;
3763
3782
  }
3783
+ function shouldReplaceRevocation(existing, record) {
3784
+ return existing === undefined || record.issuedAt > existing.entry.issuedAt;
3785
+ }
3786
+ function storeRevocationInto(store, record, bytes) {
3787
+ const existing = store.get(record.revokedPeerId);
3788
+ if (!shouldReplaceRevocation(existing, record))
3789
+ return;
3790
+ store.set(record.revokedPeerId, {
3791
+ bytes,
3792
+ entry: {
3793
+ revokedPeerId: record.revokedPeerId,
3794
+ issuerPeerId: record.issuerPeerId,
3795
+ issuedAt: record.issuedAt
3796
+ }
3797
+ });
3798
+ }
3799
+ function revocationsMissingFromSummary(store, summary) {
3800
+ const remoteKeys = new Set(summary.map((entry) => entry.revokedPeerId));
3801
+ const missing = [];
3802
+ for (const stored of store.values()) {
3803
+ if (remoteKeys.has(stored.entry.revokedPeerId))
3804
+ continue;
3805
+ missing.push(stored.bytes);
3806
+ }
3807
+ return missing;
3808
+ }
3809
+ function classifyIncomingRevocation(record, localPeerId, revokedPeers) {
3810
+ if (record.revokedPeerId === localPeerId)
3811
+ return "self";
3812
+ if (revokedPeers.has(record.revokedPeerId))
3813
+ return "duplicate";
3814
+ return "apply";
3815
+ }
3764
3816
  function installPolly107SyncReevaluation(networkAdapter, repo) {
3765
3817
  const disable = typeof process !== "undefined" && process.env?.["POLLY_107_DISABLE_FIX"] === "1";
3766
3818
  if (disable)
@@ -3838,17 +3890,7 @@ async function createMeshClient(options) {
3838
3890
  const localPeerId = options.signaling.peerId;
3839
3891
  const revocationStore = new Map;
3840
3892
  function storeRevocation(record, bytes) {
3841
- const existing = revocationStore.get(record.revokedPeerId);
3842
- if (existing && existing.entry.issuedAt >= record.issuedAt)
3843
- return;
3844
- revocationStore.set(record.revokedPeerId, {
3845
- bytes,
3846
- entry: {
3847
- revokedPeerId: record.revokedPeerId,
3848
- issuerPeerId: record.issuerPeerId,
3849
- issuedAt: record.issuedAt
3850
- }
3851
- });
3893
+ storeRevocationInto(revocationStore, record, bytes);
3852
3894
  }
3853
3895
  const handleRevocationControl = (body, senderId) => {
3854
3896
  const keyring2 = keyringSource();
@@ -3860,28 +3902,30 @@ async function createMeshClient(options) {
3860
3902
  emitMeshDiagnostic({ kind: "revoke:rejected", senderId, reason });
3861
3903
  return;
3862
3904
  }
3863
- if (record.revokedPeerId === localPeerId) {
3864
- selfRevocation = record;
3865
- emitMeshDiagnostic({
3866
- kind: "revoke:self-targeted",
3867
- issuerId: record.issuerPeerId,
3868
- ...record.reason !== undefined && { reason: record.reason },
3869
- issuedAt: record.issuedAt
3870
- });
3871
- return;
3872
- }
3873
- if (keyring2.revokedPeers.has(record.revokedPeerId)) {
3874
- storeRevocation(record, body);
3875
- emitMeshDiagnostic({
3876
- kind: "revoke:duplicate",
3877
- revokedPeerId: record.revokedPeerId,
3878
- issuerId: record.issuerPeerId
3879
- });
3880
- return;
3905
+ switch (classifyIncomingRevocation(record, localPeerId, keyring2.revokedPeers)) {
3906
+ case "self":
3907
+ selfRevocation = record;
3908
+ emitMeshDiagnostic({
3909
+ kind: "revoke:self-targeted",
3910
+ issuerId: record.issuerPeerId,
3911
+ ...record.reason !== undefined && { reason: record.reason },
3912
+ issuedAt: record.issuedAt
3913
+ });
3914
+ return;
3915
+ case "duplicate":
3916
+ storeRevocation(record, body);
3917
+ emitMeshDiagnostic({
3918
+ kind: "revoke:duplicate",
3919
+ revokedPeerId: record.revokedPeerId,
3920
+ issuerId: record.issuerPeerId
3921
+ });
3922
+ return;
3923
+ case "apply":
3924
+ applyRevocation(record, keyring2);
3925
+ storeRevocation(record, body);
3926
+ emitMeshDiagnostic({ kind: "revoke:applied", revokedPeerId: record.revokedPeerId });
3927
+ return;
3881
3928
  }
3882
- applyRevocation(record, keyring2);
3883
- storeRevocation(record, body);
3884
- emitMeshDiagnostic({ kind: "revoke:applied", revokedPeerId: record.revokedPeerId });
3885
3929
  };
3886
3930
  const handleRevocationSummary = (body, senderId) => {
3887
3931
  let summary;
@@ -3895,12 +3939,9 @@ async function createMeshClient(options) {
3895
3939
  });
3896
3940
  return;
3897
3941
  }
3898
- const remoteKeys = new Set(summary.map((entry) => entry.revokedPeerId));
3899
3942
  const senderPeerId = senderId;
3900
- for (const stored of revocationStore.values()) {
3901
- if (remoteKeys.has(stored.entry.revokedPeerId))
3902
- continue;
3903
- networkAdapter.sendControlMessage(MESH_CONTROL_TYPE.Revocation, stored.bytes, [senderPeerId]);
3943
+ for (const bytes of revocationsMissingFromSummary(revocationStore, summary)) {
3944
+ networkAdapter.sendControlMessage(MESH_CONTROL_TYPE.Revocation, bytes, [senderPeerId]);
3904
3945
  }
3905
3946
  };
3906
3947
  const networkAdapter = new MeshNetworkAdapter({
@@ -4310,4 +4351,4 @@ export {
4310
4351
  $meshCounter
4311
4352
  };
4312
4353
 
4313
- //# debugId=0D84EA4EDCC2765464756E2164756E21
4354
+ //# debugId=7FA8CE30CEE539D264756E2164756E21