@dxos/client-services 0.1.50 → 0.1.51-main.04cd027

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 (30) hide show
  1. package/dist/lib/browser/{chunk-BAHSFG33.mjs → chunk-ARBZHWMK.mjs} +126 -74
  2. package/dist/lib/browser/chunk-ARBZHWMK.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  6. package/dist/lib/node/index.cjs +139 -87
  7. package/dist/lib/node/index.cjs.map +3 -3
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/packlets/testing/index.cjs +156 -104
  10. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  11. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  12. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  13. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  14. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -1
  15. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  16. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  18. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  19. package/package.json +30 -30
  20. package/src/packlets/devtools/feeds.ts +1 -0
  21. package/src/packlets/identity/identity-manager.ts +4 -1
  22. package/src/packlets/identity/identity.test.ts +9 -3
  23. package/src/packlets/invitations/invitations-handler.ts +14 -6
  24. package/src/packlets/invitations/space-invitation-protocol.test.ts +8 -1
  25. package/src/packlets/logging/logging-service.ts +58 -15
  26. package/src/packlets/spaces/data-space-manager.test.ts +64 -1
  27. package/src/packlets/spaces/data-space-manager.ts +2 -1
  28. package/src/packlets/spaces/data-space.ts +8 -3
  29. package/src/packlets/spaces/spaces-service.ts +7 -0
  30. package/dist/lib/browser/chunk-BAHSFG33.mjs.map +0 -7
@@ -63,7 +63,7 @@ var createMockCredential = async ({ signer, issuer }) => (0, import_credentials.
63
63
  // packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
64
64
  var import_node_assert13 = __toESM(require("node:assert"));
65
65
  var import_async19 = require("@dxos/async");
66
- var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
66
+ var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
67
67
 
68
68
  // packages/sdk/client-services/src/packlets/services/service-host.ts
69
69
  var import_node_assert12 = __toESM(require("node:assert"));
@@ -75,7 +75,7 @@ var import_log15 = require("@dxos/log");
75
75
  var import_messaging = require("@dxos/messaging");
76
76
  var import_network_manager2 = require("@dxos/network-manager");
77
77
  var import_protocols9 = require("@dxos/protocols");
78
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
78
+ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
79
79
 
80
80
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
81
81
  var import_async = require("@dxos/async");
@@ -148,11 +148,15 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
148
148
  }
149
149
  });
150
150
  next({
151
- feeds: Array.from(feedMap.values()).map((feed) => ({
152
- feedKey: feed.key,
153
- length: feed.properties.length,
154
- bytes: feed.core.byteLength
155
- }))
151
+ feeds: Array.from(feedMap.values()).map((feed) => {
152
+ var _a, _b;
153
+ return {
154
+ feedKey: feed.key,
155
+ length: feed.properties.length,
156
+ bytes: feed.core.byteLength,
157
+ downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
158
+ };
159
+ })
156
160
  });
157
161
  };
158
162
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -891,7 +895,8 @@ var IdentityManager = class {
891
895
  });
892
896
  (0, import_node_assert2.default)(identityRecord.haloSpace.dataFeedKey);
893
897
  const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.dataFeedKey, {
894
- writable: true
898
+ writable: true,
899
+ sparse: true
895
900
  });
896
901
  const space = await this._constructSpace({
897
902
  spaceRecord: identityRecord.haloSpace,
@@ -914,7 +919,7 @@ var IdentityManager = class {
914
919
  identityKey: identityRecord.identityKey
915
920
  }, {
916
921
  file: "identity-manager.ts",
917
- line: 223,
922
+ line: 226,
918
923
  scope: this,
919
924
  callSite: (f, a) => f(...a)
920
925
  });
@@ -935,7 +940,7 @@ var IdentityManager = class {
935
940
  onAuthFailure: () => {
936
941
  import_log3.log.warn("auth failure", {}, {
937
942
  file: "identity-manager.ts",
938
- line: 242,
943
+ line: 245,
939
944
  scope: this,
940
945
  callSite: (f, a) => f(...a)
941
946
  });
@@ -1417,7 +1422,7 @@ var InvitationsHandler = class {
1417
1422
  ...protocol.toJSON()
1418
1423
  }, {
1419
1424
  file: "invitations-handler.ts",
1420
- line: 100,
1425
+ line: 99,
1421
1426
  scope: this,
1422
1427
  callSite: (f, a) => f(...a)
1423
1428
  });
@@ -1458,7 +1463,7 @@ var InvitationsHandler = class {
1458
1463
  id: traceId
1459
1464
  }), {
1460
1465
  file: "invitations-handler.ts",
1461
- line: 139,
1466
+ line: 138,
1462
1467
  scope: this,
1463
1468
  callSite: (f, a) => f(...a)
1464
1469
  });
@@ -1466,7 +1471,7 @@ var InvitationsHandler = class {
1466
1471
  ...protocol.toJSON()
1467
1472
  }, {
1468
1473
  file: "invitations-handler.ts",
1469
- line: 140,
1474
+ line: 139,
1470
1475
  scope: this,
1471
1476
  callSite: (f, a) => f(...a)
1472
1477
  });
@@ -1482,7 +1487,7 @@ var InvitationsHandler = class {
1482
1487
  ...protocol.toJSON()
1483
1488
  }, {
1484
1489
  file: "invitations-handler.ts",
1485
- line: 143,
1490
+ line: 142,
1486
1491
  scope: this,
1487
1492
  callSite: (f, a) => f(...a)
1488
1493
  });
@@ -1494,7 +1499,7 @@ var InvitationsHandler = class {
1494
1499
  id: traceId
1495
1500
  }), {
1496
1501
  file: "invitations-handler.ts",
1497
- line: 145,
1502
+ line: 144,
1498
1503
  scope: this,
1499
1504
  callSite: (f, a) => f(...a)
1500
1505
  });
@@ -1504,7 +1509,7 @@ var InvitationsHandler = class {
1504
1509
  ...protocol.toJSON()
1505
1510
  }, {
1506
1511
  file: "invitations-handler.ts",
1507
- line: 148,
1512
+ line: 147,
1508
1513
  scope: this,
1509
1514
  callSite: (f, a) => f(...a)
1510
1515
  });
@@ -1515,7 +1520,7 @@ var InvitationsHandler = class {
1515
1520
  } else {
1516
1521
  import_log5.log.error("failed", err, {
1517
1522
  file: "invitations-handler.ts",
1518
- line: 151,
1523
+ line: 150,
1519
1524
  scope: this,
1520
1525
  callSite: (f, a) => f(...a)
1521
1526
  });
@@ -1526,13 +1531,13 @@ var InvitationsHandler = class {
1526
1531
  error: err
1527
1532
  }), {
1528
1533
  file: "invitations-handler.ts",
1529
- line: 154,
1534
+ line: 153,
1530
1535
  scope: this,
1531
1536
  callSite: (f, a) => f(...a)
1532
1537
  });
1533
1538
  } finally {
1534
1539
  if (type !== import_services4.Invitation.Type.MULTIUSE) {
1535
- await (0, import_async9.sleep)(import_client_protocol2.ON_CLOSE_DELAY);
1540
+ await swarmConnection.close();
1536
1541
  await ctx.dispose();
1537
1542
  }
1538
1543
  }
@@ -1568,9 +1573,10 @@ var InvitationsHandler = class {
1568
1573
  });
1569
1574
  return extension;
1570
1575
  };
1576
+ let swarmConnection;
1571
1577
  (0, import_async9.scheduleTask)(ctx, async () => {
1572
1578
  const topic = invitation.swarmKey;
1573
- const swarmConnection = await this._networkManager.joinSwarm({
1579
+ swarmConnection = await this._networkManager.joinSwarm({
1574
1580
  topic,
1575
1581
  peerId: topic,
1576
1582
  protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
@@ -1601,6 +1607,7 @@ var InvitationsHandler = class {
1601
1607
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
1602
1608
  (0, import_node_assert6.default)(protocol);
1603
1609
  const authenticated = new import_async9.Trigger();
1610
+ let admitted = false;
1604
1611
  let currentState;
1605
1612
  const stream = new import_async9.PushStream();
1606
1613
  const setState = (newData) => {
@@ -1618,7 +1625,7 @@ var InvitationsHandler = class {
1618
1625
  ...protocol.toJSON()
1619
1626
  }, {
1620
1627
  file: "invitations-handler.ts",
1621
- line: 225,
1628
+ line: 230,
1622
1629
  scope: this,
1623
1630
  callSite: (f, a) => f(...a)
1624
1631
  });
@@ -1628,7 +1635,7 @@ var InvitationsHandler = class {
1628
1635
  } else {
1629
1636
  import_log5.log.warn("auth failed", err, {
1630
1637
  file: "invitations-handler.ts",
1631
- line: 228,
1638
+ line: 233,
1632
1639
  scope: this,
1633
1640
  callSite: (f, a) => f(...a)
1634
1641
  });
@@ -1642,7 +1649,7 @@ var InvitationsHandler = class {
1642
1649
  ...protocol.toJSON()
1643
1650
  }, {
1644
1651
  file: "invitations-handler.ts",
1645
- line: 236,
1652
+ line: 241,
1646
1653
  scope: this,
1647
1654
  callSite: (f, a) => f(...a)
1648
1655
  });
@@ -1657,11 +1664,11 @@ var InvitationsHandler = class {
1657
1664
  currentState
1658
1665
  }, {
1659
1666
  file: "invitations-handler.ts",
1660
- line: 246,
1667
+ line: 251,
1661
1668
  scope: this,
1662
1669
  callSite: (f, a) => f(...a)
1663
1670
  });
1664
- if (currentState !== import_services4.Invitation.State.SUCCESS) {
1671
+ if (!admitted) {
1665
1672
  stream.error(new Error("Remote peer disconnected."));
1666
1673
  }
1667
1674
  });
@@ -1672,7 +1679,7 @@ var InvitationsHandler = class {
1672
1679
  id: traceId
1673
1680
  }), {
1674
1681
  file: "invitations-handler.ts",
1675
- line: 255,
1682
+ line: 260,
1676
1683
  scope: this,
1677
1684
  callSite: (f, a) => f(...a)
1678
1685
  });
@@ -1684,7 +1691,7 @@ var InvitationsHandler = class {
1684
1691
  ...protocol.toJSON()
1685
1692
  }, {
1686
1693
  file: "invitations-handler.ts",
1687
- line: 263,
1694
+ line: 268,
1688
1695
  scope: this,
1689
1696
  callSite: (f, a) => f(...a)
1690
1697
  });
@@ -1695,7 +1702,7 @@ var InvitationsHandler = class {
1695
1702
  ...protocol.toJSON()
1696
1703
  }, {
1697
1704
  file: "invitations-handler.ts",
1698
- line: 267,
1705
+ line: 272,
1699
1706
  scope: this,
1700
1707
  callSite: (f, a) => f(...a)
1701
1708
  });
@@ -1705,7 +1712,7 @@ var InvitationsHandler = class {
1705
1712
  response: introductionResponse
1706
1713
  }, {
1707
1714
  file: "invitations-handler.ts",
1708
- line: 271,
1715
+ line: 276,
1709
1716
  scope: this,
1710
1717
  callSite: (f, a) => f(...a)
1711
1718
  });
@@ -1717,7 +1724,7 @@ var InvitationsHandler = class {
1717
1724
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1718
1725
  (0, import_log5.log)("guest waiting for authentication code...", {}, {
1719
1726
  file: "invitations-handler.ts",
1720
- line: 280,
1727
+ line: 285,
1721
1728
  scope: this,
1722
1729
  callSite: (f, a) => f(...a)
1723
1730
  });
@@ -1729,7 +1736,7 @@ var InvitationsHandler = class {
1729
1736
  });
1730
1737
  (0, import_log5.log)("sending authentication request", {}, {
1731
1738
  file: "invitations-handler.ts",
1732
- line: 284,
1739
+ line: 289,
1733
1740
  scope: this,
1734
1741
  callSite: (f, a) => f(...a)
1735
1742
  });
@@ -1750,7 +1757,7 @@ var InvitationsHandler = class {
1750
1757
  attempt
1751
1758
  }, {
1752
1759
  file: "invitations-handler.ts",
1753
- line: 295,
1760
+ line: 300,
1754
1761
  scope: this,
1755
1762
  callSite: (f, a) => f(...a)
1756
1763
  });
@@ -1767,18 +1774,19 @@ var InvitationsHandler = class {
1767
1774
  ...protocol.toJSON()
1768
1775
  }, {
1769
1776
  file: "invitations-handler.ts",
1770
- line: 306,
1777
+ line: 311,
1771
1778
  scope: this,
1772
1779
  callSite: (f, a) => f(...a)
1773
1780
  });
1774
1781
  const admissionRequest = await protocol.createAdmissionRequest();
1775
1782
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
1783
+ admitted = true;
1776
1784
  const result = await protocol.accept(admissionResponse, admissionRequest);
1777
1785
  (0, import_log5.log)("admitted by host", {
1778
1786
  ...protocol.toJSON()
1779
1787
  }, {
1780
1788
  file: "invitations-handler.ts",
1781
- line: 314,
1789
+ line: 322,
1782
1790
  scope: this,
1783
1791
  callSite: (f, a) => f(...a)
1784
1792
  });
@@ -1790,7 +1798,7 @@ var InvitationsHandler = class {
1790
1798
  id: traceId
1791
1799
  }), {
1792
1800
  file: "invitations-handler.ts",
1793
- line: 316,
1801
+ line: 324,
1794
1802
  scope: this,
1795
1803
  callSite: (f, a) => f(...a)
1796
1804
  });
@@ -1800,7 +1808,7 @@ var InvitationsHandler = class {
1800
1808
  ...protocol.toJSON()
1801
1809
  }, {
1802
1810
  file: "invitations-handler.ts",
1803
- line: 319,
1811
+ line: 327,
1804
1812
  scope: this,
1805
1813
  callSite: (f, a) => f(...a)
1806
1814
  });
@@ -1810,7 +1818,7 @@ var InvitationsHandler = class {
1810
1818
  } else {
1811
1819
  (0, import_log5.log)("auth failed", err, {
1812
1820
  file: "invitations-handler.ts",
1813
- line: 322,
1821
+ line: 330,
1814
1822
  scope: this,
1815
1823
  callSite: (f, a) => f(...a)
1816
1824
  });
@@ -1821,7 +1829,7 @@ var InvitationsHandler = class {
1821
1829
  error: err
1822
1830
  }), {
1823
1831
  file: "invitations-handler.ts",
1824
- line: 325,
1832
+ line: 333,
1825
1833
  scope: this,
1826
1834
  callSite: (f, a) => f(...a)
1827
1835
  });
@@ -1839,7 +1847,7 @@ var InvitationsHandler = class {
1839
1847
  ...protocol.toJSON()
1840
1848
  }, {
1841
1849
  file: "invitations-handler.ts",
1842
- line: 336,
1850
+ line: 344,
1843
1851
  scope: this,
1844
1852
  callSite: (f, a) => f(...a)
1845
1853
  });
@@ -1849,7 +1857,7 @@ var InvitationsHandler = class {
1849
1857
  } else {
1850
1858
  (0, import_log5.log)("auth failed", err, {
1851
1859
  file: "invitations-handler.ts",
1852
- line: 339,
1860
+ line: 347,
1853
1861
  scope: this,
1854
1862
  callSite: (f, a) => f(...a)
1855
1863
  });
@@ -2211,6 +2219,7 @@ __decorate([
2211
2219
  var import_async12 = require("@dxos/async");
2212
2220
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2213
2221
  var import_log9 = require("@dxos/log");
2222
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2214
2223
  var import_util3 = require("@dxos/util");
2215
2224
  var LoggingServiceImpl = class {
2216
2225
  constructor() {
@@ -2227,31 +2236,60 @@ var LoggingServiceImpl = class {
2227
2236
  import_log9.log.runtimeConfig.processors.splice(index, 1);
2228
2237
  }
2229
2238
  queryLogs(request) {
2230
- var _a;
2231
- const filters = ((_a = request.filters) == null ? void 0 : _a.length) ? request.filters : void 0;
2232
2239
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
2233
2240
  const handler = (entry2) => {
2234
- var _a2, _b, _c;
2235
- if (((_a2 = entry2.meta) == null ? void 0 : _a2.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
2241
+ var _a, _b, _c, _d, _e;
2242
+ if (LOG_PROCESSING > 0) {
2236
2243
  return;
2237
2244
  }
2238
- if ((0, import_log9.shouldLog)(entry2, filters)) {
2239
- const record = {
2240
- ...entry2,
2241
- context: (0, import_util3.jsonify)((0, import_log9.getContextFromEntry)(entry2))
2242
- };
2243
- (_b = record.meta) == null ? true : delete _b.bugcheck;
2244
- (_c = record.meta) == null ? true : delete _c.scope;
2245
+ if (((_a = entry2.meta) == null ? void 0 : _a.file.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
2246
+ return;
2247
+ }
2248
+ if (!shouldLog(entry2, request)) {
2249
+ return;
2250
+ }
2251
+ const record = {
2252
+ ...entry2,
2253
+ context: (0, import_util3.jsonify)((0, import_log9.getContextFromEntry)(entry2)),
2254
+ timestamp: new Date(),
2255
+ meta: {
2256
+ // TODO(dmaretskyi): Fix proto.
2257
+ file: (_c = (_b = entry2.meta) == null ? void 0 : _b.file) != null ? _c : "",
2258
+ line: (_e = (_d = entry2.meta) == null ? void 0 : _d.line) != null ? _e : 0
2259
+ }
2260
+ };
2261
+ try {
2262
+ LOG_PROCESSING++;
2245
2263
  next(record);
2264
+ } finally {
2265
+ LOG_PROCESSING--;
2246
2266
  }
2247
2267
  };
2248
- ctx.onDispose(() => {
2249
- this._logs.off(handler);
2250
- });
2251
- this._logs.on(handler);
2268
+ this._logs.on(ctx, handler);
2252
2269
  });
2253
2270
  }
2254
2271
  };
2272
+ var matchFilter = (filter, level, path, options) => {
2273
+ switch (options) {
2274
+ case import_services7.QueryLogsRequest.MatchingOptions.INCLUSIVE:
2275
+ return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
2276
+ case import_services7.QueryLogsRequest.MatchingOptions.EXPLICIT:
2277
+ return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
2278
+ }
2279
+ };
2280
+ var shouldLog = (entry2, request) => {
2281
+ var _a;
2282
+ const options = (_a = request.options) != null ? _a : import_services7.QueryLogsRequest.MatchingOptions.INCLUSIVE;
2283
+ if (request.filters === void 0) {
2284
+ return options === import_services7.QueryLogsRequest.MatchingOptions.INCLUSIVE;
2285
+ } else {
2286
+ return request.filters.some((filter) => {
2287
+ var _a2, _b;
2288
+ return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.file) != null ? _b : "", options);
2289
+ });
2290
+ }
2291
+ };
2292
+ var LOG_PROCESSING = 0;
2255
2293
 
2256
2294
  // packages/sdk/client-services/src/packlets/network/network-service.ts
2257
2295
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
@@ -2293,7 +2331,7 @@ var import_credentials13 = require("@dxos/credentials");
2293
2331
  var import_keys10 = require("@dxos/keys");
2294
2332
  var import_log12 = require("@dxos/log");
2295
2333
  var import_protocols6 = require("@dxos/protocols");
2296
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
2334
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
2297
2335
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
2298
2336
  var import_util6 = require("@dxos/util");
2299
2337
 
@@ -2306,8 +2344,9 @@ var import_echo_pipeline = require("@dxos/echo-pipeline");
2306
2344
  var import_errors3 = require("@dxos/errors");
2307
2345
  var import_keys9 = require("@dxos/keys");
2308
2346
  var import_log11 = require("@dxos/log");
2309
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2347
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
2310
2348
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
2349
+ var import_timeframe = require("@dxos/timeframe");
2311
2350
  var import_util5 = require("@dxos/util");
2312
2351
 
2313
2352
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
@@ -2566,7 +2605,7 @@ var __decorate2 = function(decorators, target, key, desc) {
2566
2605
  var DataSpace = class DataSpace2 {
2567
2606
  constructor(params) {
2568
2607
  this._ctx = new import_context6.Context();
2569
- this._state = import_services7.SpaceState.CLOSED;
2608
+ this._state = import_services8.SpaceState.CLOSED;
2570
2609
  /**
2571
2610
  * Error for _state === SpaceState.ERROR.
2572
2611
  */
@@ -2620,11 +2659,11 @@ var DataSpace = class DataSpace2 {
2620
2659
  await this.notarizationPlugin.open();
2621
2660
  await this._notarizationPluginConsumer.open();
2622
2661
  await this._inner.open();
2623
- this._state = import_services7.SpaceState.INACTIVE;
2662
+ this._state = import_services8.SpaceState.INACTIVE;
2624
2663
  this.metrics.open = new Date();
2625
2664
  }
2626
2665
  async close() {
2627
- this._state = import_services7.SpaceState.CLOSED;
2666
+ this._state = import_services8.SpaceState.CLOSED;
2628
2667
  await this._ctx.dispose();
2629
2668
  await this.authVerifier.close();
2630
2669
  await this._inner.close();
@@ -2650,7 +2689,7 @@ var DataSpace = class DataSpace2 {
2650
2689
  if (err instanceof import_errors3.CancelledError) {
2651
2690
  (0, import_log11.log)("Data pipeline initialization cancelled", err, {
2652
2691
  file: "data-space.ts",
2653
- line: 172,
2692
+ line: 173,
2654
2693
  scope: this,
2655
2694
  callSite: (f, a) => f(...a)
2656
2695
  });
@@ -2658,11 +2697,11 @@ var DataSpace = class DataSpace2 {
2658
2697
  }
2659
2698
  import_log11.log.error("Error initializing data pipeline", err, {
2660
2699
  file: "data-space.ts",
2661
- line: 176,
2700
+ line: 177,
2662
2701
  scope: this,
2663
2702
  callSite: (f, a) => f(...a)
2664
2703
  });
2665
- this._state = import_services7.SpaceState.ERROR;
2704
+ this._state = import_services8.SpaceState.ERROR;
2666
2705
  this.error = err;
2667
2706
  this.stateUpdate.emit();
2668
2707
  } finally {
@@ -2672,10 +2711,10 @@ var DataSpace = class DataSpace2 {
2672
2711
  }
2673
2712
  async initializeDataPipeline() {
2674
2713
  var _a, _b, _c, _d;
2675
- if (this._state !== import_services7.SpaceState.INACTIVE) {
2714
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
2676
2715
  throw new import_errors3.SystemError("Invalid operation");
2677
2716
  }
2678
- this._state = import_services7.SpaceState.INITIALIZING;
2717
+ this._state = import_services8.SpaceState.INITIALIZING;
2679
2718
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
2680
2719
  ctx: this._ctx,
2681
2720
  breakOnStall: false
@@ -2715,7 +2754,7 @@ var DataSpace = class DataSpace2 {
2715
2754
  callSite: (f, a) => f(...a)
2716
2755
  });
2717
2756
  await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2718
- this._state = import_services7.SpaceState.READY;
2757
+ this._state = import_services8.SpaceState.READY;
2719
2758
  this.stateUpdate.emit();
2720
2759
  await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
2721
2760
  }
@@ -2739,7 +2778,8 @@ var DataSpace = class DataSpace2 {
2739
2778
  }
2740
2779
  if (!this.inner.dataFeedKey) {
2741
2780
  const dataFeed = await this._feedStore.openFeed(await this._keyring.createKey(), {
2742
- writable: true
2781
+ writable: true,
2782
+ sparse: true
2743
2783
  });
2744
2784
  this.inner.setDataFeed(dataFeed);
2745
2785
  credentials.push(await this._signingContext.credentialSigner.createCredential({
@@ -2765,7 +2805,7 @@ var DataSpace = class DataSpace2 {
2765
2805
  async createEpoch() {
2766
2806
  var _a, _b;
2767
2807
  const epoch = await this.dataPipeline.createEpoch();
2768
- await this.inner.controlPipeline.writer.write({
2808
+ const receipt = await this.inner.controlPipeline.writer.write({
2769
2809
  credential: {
2770
2810
  credential: await this._signingContext.credentialSigner.createCredential({
2771
2811
  subject: this.key,
@@ -2776,6 +2816,12 @@ var DataSpace = class DataSpace2 {
2776
2816
  })
2777
2817
  }
2778
2818
  });
2819
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
2820
+ [
2821
+ receipt.feedKey,
2822
+ receipt.seq
2823
+ ]
2824
+ ]));
2779
2825
  for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2780
2826
  const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2781
2827
  if (indexBeforeEpoch) {
@@ -2795,7 +2841,7 @@ DataSpace = __decorate2([
2795
2841
  var import_credentials11 = require("@dxos/credentials");
2796
2842
  var import_debug4 = require("@dxos/debug");
2797
2843
  var import_credentials12 = require("@dxos/protocols/proto/dxos/halo/credentials");
2798
- var import_timeframe = require("@dxos/timeframe");
2844
+ var import_timeframe2 = require("@dxos/timeframe");
2799
2845
  var spaceGenesis = async (keyring, signingContext, space) => {
2800
2846
  var _a, _b, _c, _d;
2801
2847
  const credentials = [
@@ -2846,7 +2892,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2846
2892
  "@type": "dxos.halo.credentials.Epoch",
2847
2893
  number: 0,
2848
2894
  previousId: void 0,
2849
- timeframe: new import_timeframe.Timeframe(),
2895
+ timeframe: new import_timeframe2.Timeframe(),
2850
2896
  snapshotCid: void 0
2851
2897
  }
2852
2898
  })
@@ -3026,7 +3072,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3026
3072
  async waitUntilSpaceReady(spaceKey) {
3027
3073
  await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3028
3074
  const space = this._spaces.get(spaceKey);
3029
- return !!space && space.state === import_services8.SpaceState.READY;
3075
+ return !!space && space.state === import_services9.SpaceState.READY;
3030
3076
  }));
3031
3077
  }
3032
3078
  async _constructSpace(metadata) {
@@ -3051,7 +3097,8 @@ var DataSpaceManager = class DataSpaceManager2 {
3051
3097
  writable: true
3052
3098
  });
3053
3099
  const dataFeed = metadata.dataFeedKey && await this._feedStore.openFeed(metadata.dataFeedKey, {
3054
- writable: true
3100
+ writable: true,
3101
+ sparse: true
3055
3102
  });
3056
3103
  const space = await this._spaceManager.constructSpace({
3057
3104
  metadata,
@@ -3070,7 +3117,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3070
3117
  onAuthFailure: () => {
3071
3118
  import_log12.log.warn("auth failure", {}, {
3072
3119
  file: "data-space-manager.ts",
3073
- line: 212,
3120
+ line: 213,
3074
3121
  scope: this,
3075
3122
  callSite: (f, a) => f(...a)
3076
3123
  });
@@ -3093,7 +3140,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3093
3140
  space: space.key
3094
3141
  }, {
3095
3142
  file: "data-space-manager.ts",
3096
- line: 229,
3143
+ line: 230,
3097
3144
  scope: this,
3098
3145
  callSite: (f, a) => f(...a)
3099
3146
  });
@@ -3105,7 +3152,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3105
3152
  open: this._isOpen
3106
3153
  }, {
3107
3154
  file: "data-space-manager.ts",
3108
- line: 236,
3155
+ line: 237,
3109
3156
  scope: this,
3110
3157
  callSite: (f, a) => f(...a)
3111
3158
  });
@@ -3150,7 +3197,7 @@ var import_debug5 = require("@dxos/debug");
3150
3197
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
3151
3198
  var import_log13 = require("@dxos/log");
3152
3199
  var import_protocols7 = require("@dxos/protocols");
3153
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
3200
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
3154
3201
  var import_util7 = require("@dxos/util");
3155
3202
  var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
3156
3203
  var SpacesServiceImpl = class {
@@ -3180,7 +3227,7 @@ var SpacesServiceImpl = class {
3180
3227
  spaces
3181
3228
  }, {
3182
3229
  file: "spaces-service.ts",
3183
- line: 59,
3230
+ line: 60,
3184
3231
  scope: this,
3185
3232
  callSite: (f, a) => f(...a)
3186
3233
  });
@@ -3197,6 +3244,7 @@ var SpacesServiceImpl = class {
3197
3244
  for (const space of dataSpaceManager.spaces.values()) {
3198
3245
  subscriptions.add(space.stateUpdate.on(ctx, onUpdate));
3199
3246
  subscriptions.add(space.presence.updated.on(ctx, onUpdate));
3247
+ subscriptions.add(space.dataPipeline.onNewEpoch.on(ctx, onUpdate));
3200
3248
  space.inner.controlPipeline.state.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate);
3201
3249
  if (space.dataPipeline.pipelineState) {
3202
3250
  subscriptions.add(space.dataPipeline.pipelineState.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate));
@@ -3267,20 +3315,23 @@ var SpacesServiceImpl = class {
3267
3315
  await space.createEpoch();
3268
3316
  }
3269
3317
  _transformSpace(space) {
3270
- var _a, _b, _c, _d, _e;
3318
+ var _a, _b, _c, _d, _e, _f, _g;
3271
3319
  return {
3272
3320
  spaceKey: space.key,
3273
3321
  state: space.state,
3274
3322
  error: space.error ? (0, import_protocols7.encodeError)(space.error) : void 0,
3275
3323
  pipeline: {
3324
+ currentEpoch: space.dataPipeline.currentEpoch,
3325
+ appliedEpoch: space.dataPipeline.appliedEpoch,
3276
3326
  controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
3277
3327
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3278
3328
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3279
3329
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3280
3330
  dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3281
- currentDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.timeframe,
3282
- targetDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.targetTimeframe,
3283
- totalDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.endTimeframe
3331
+ startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3332
+ currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3333
+ targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3334
+ totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3284
3335
  },
3285
3336
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3286
3337
  var _a2, _b2, _c2;
@@ -3291,9 +3342,10 @@ var SpacesServiceImpl = class {
3291
3342
  displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : (0, import_util7.humanize)(member.key)
3292
3343
  }
3293
3344
  },
3294
- presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE
3345
+ presence: ((_c2 = this._identityManager.identity) == null ? void 0 : _c2.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE
3295
3346
  };
3296
3347
  }),
3348
+ creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3297
3349
  cache: space.cache,
3298
3350
  metrics: space.metrics
3299
3351
  };
@@ -3399,7 +3451,7 @@ var import_keyring = require("@dxos/keyring");
3399
3451
  var import_keys11 = require("@dxos/keys");
3400
3452
  var import_log14 = require("@dxos/log");
3401
3453
  var import_protocols8 = require("@dxos/protocols");
3402
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
3454
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
3403
3455
  var ServiceContext = class {
3404
3456
  // prettier-ignore
3405
3457
  constructor(storage, networkManager, signalManager, modelFactory) {
@@ -3432,7 +3484,7 @@ var ServiceContext = class {
3432
3484
  });
3433
3485
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3434
3486
  this.invitations = new InvitationsHandler(this.networkManager);
3435
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3487
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3436
3488
  var _a;
3437
3489
  return (_a = this.identityManager.identity) != null ? _a : (0, import_debug6.failUndefined)();
3438
3490
  }, this._acceptIdentity.bind(this)));
@@ -3544,7 +3596,7 @@ var ServiceContext = class {
3544
3596
  };
3545
3597
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
3546
3598
  await this.dataSpaceManager.open();
3547
- this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
3599
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
3548
3600
  (0, import_node_assert11.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3549
3601
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3550
3602
  });
@@ -3670,12 +3722,12 @@ var ClientServicesHost = class {
3670
3722
  this._systemService = new SystemServiceImpl({
3671
3723
  config: this._config,
3672
3724
  statusUpdate: this._statusUpdate,
3673
- getCurrentStatus: () => this.isOpen ? import_services11.SystemStatus.ACTIVE : import_services11.SystemStatus.INACTIVE,
3725
+ getCurrentStatus: () => this.isOpen ? import_services12.SystemStatus.ACTIVE : import_services12.SystemStatus.INACTIVE,
3674
3726
  onUpdateStatus: async (status) => {
3675
3727
  var _a, _b;
3676
- if (!this.isOpen && status === import_services11.SystemStatus.ACTIVE) {
3728
+ if (!this.isOpen && status === import_services12.SystemStatus.ACTIVE) {
3677
3729
  await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
3678
- } else if (this.isOpen && status === import_services11.SystemStatus.INACTIVE) {
3730
+ } else if (this.isOpen && status === import_services12.SystemStatus.INACTIVE) {
3679
3731
  await ((_b = this._resourceLock) == null ? void 0 : _b.release());
3680
3732
  }
3681
3733
  },
@@ -3883,7 +3935,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3883
3935
  hostObservable.subscribe(async (hostInvitation) => {
3884
3936
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
3885
3937
  switch (hostInvitation.state) {
3886
- case import_services12.Invitation.State.CONNECTING: {
3938
+ case import_services13.Invitation.State.CONNECTING: {
3887
3939
  if ((_b = (_a = hooks == null ? void 0 : hooks.host) == null ? void 0 : _a.onConnecting) == null ? void 0 : _b.call(_a, hostObservable)) {
3888
3940
  break;
3889
3941
  }
@@ -3891,29 +3943,29 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3891
3943
  guestObservable.subscribe(async (guestInvitation) => {
3892
3944
  var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
3893
3945
  switch (guestInvitation.state) {
3894
- case import_services12.Invitation.State.CONNECTING: {
3946
+ case import_services13.Invitation.State.CONNECTING: {
3895
3947
  if ((_b2 = (_a2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _a2.onConnecting) == null ? void 0 : _b2.call(_a2, guestObservable)) {
3896
3948
  break;
3897
3949
  }
3898
3950
  (0, import_node_assert13.default)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey));
3899
3951
  break;
3900
3952
  }
3901
- case import_services12.Invitation.State.CONNECTED: {
3953
+ case import_services13.Invitation.State.CONNECTED: {
3902
3954
  (_d2 = (_c2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _c2.onConnected) == null ? void 0 : _d2.call(_c2, guestObservable);
3903
3955
  break;
3904
3956
  }
3905
- case import_services12.Invitation.State.READY_FOR_AUTHENTICATION: {
3957
+ case import_services13.Invitation.State.READY_FOR_AUTHENTICATION: {
3906
3958
  if ((_f2 = (_e2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _e2.onReady) == null ? void 0 : _f2.call(_e2, guestObservable)) {
3907
3959
  break;
3908
3960
  }
3909
3961
  await guestObservable.authenticate(await authCode.wait());
3910
3962
  break;
3911
3963
  }
3912
- case import_services12.Invitation.State.AUTHENTICATING: {
3964
+ case import_services13.Invitation.State.AUTHENTICATING: {
3913
3965
  (_h2 = (_g2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _g2.onAuthenticating) == null ? void 0 : _h2.call(_g2, guestObservable);
3914
3966
  break;
3915
3967
  }
3916
- case import_services12.Invitation.State.SUCCESS: {
3968
+ case import_services13.Invitation.State.SUCCESS: {
3917
3969
  if ((_j2 = (_i2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _i2.onSuccess) == null ? void 0 : _j2.call(_i2, guestObservable)) {
3918
3970
  break;
3919
3971
  }
@@ -3922,7 +3974,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3922
3974
  });
3923
3975
  break;
3924
3976
  }
3925
- case import_services12.Invitation.State.CANCELLED: {
3977
+ case import_services13.Invitation.State.CANCELLED: {
3926
3978
  if ((_l2 = (_k2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _k2.onCancelled) == null ? void 0 : _l2.call(_k2, guestObservable)) {
3927
3979
  break;
3928
3980
  }
@@ -3931,7 +3983,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3931
3983
  });
3932
3984
  break;
3933
3985
  }
3934
- case import_services12.Invitation.State.TIMEOUT: {
3986
+ case import_services13.Invitation.State.TIMEOUT: {
3935
3987
  if ((_n2 = (_m2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _m2.onTimeout) == null ? void 0 : _n2.call(_m2, guestObservable)) {
3936
3988
  return;
3937
3989
  }
@@ -3951,11 +4003,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3951
4003
  });
3952
4004
  break;
3953
4005
  }
3954
- case import_services12.Invitation.State.CONNECTED: {
4006
+ case import_services13.Invitation.State.CONNECTED: {
3955
4007
  (_d = (_c = hooks == null ? void 0 : hooks.host) == null ? void 0 : _c.onConnected) == null ? void 0 : _d.call(_c, hostObservable);
3956
4008
  break;
3957
4009
  }
3958
- case import_services12.Invitation.State.READY_FOR_AUTHENTICATION: {
4010
+ case import_services13.Invitation.State.READY_FOR_AUTHENTICATION: {
3959
4011
  if ((_f = (_e = hooks == null ? void 0 : hooks.host) == null ? void 0 : _e.onReady) == null ? void 0 : _f.call(_e, hostObservable)) {
3960
4012
  break;
3961
4013
  }
@@ -3964,11 +4016,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3964
4016
  }
3965
4017
  break;
3966
4018
  }
3967
- case import_services12.Invitation.State.AUTHENTICATING: {
4019
+ case import_services13.Invitation.State.AUTHENTICATING: {
3968
4020
  (_h = (_g = hooks == null ? void 0 : hooks.host) == null ? void 0 : _g.onAuthenticating) == null ? void 0 : _h.call(_g, hostObservable);
3969
4021
  break;
3970
4022
  }
3971
- case import_services12.Invitation.State.SUCCESS: {
4023
+ case import_services13.Invitation.State.SUCCESS: {
3972
4024
  if ((_j = (_i = hooks == null ? void 0 : hooks.host) == null ? void 0 : _i.onSuccess) == null ? void 0 : _j.call(_i, hostObservable)) {
3973
4025
  break;
3974
4026
  }
@@ -3977,7 +4029,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3977
4029
  });
3978
4030
  break;
3979
4031
  }
3980
- case import_services12.Invitation.State.CANCELLED: {
4032
+ case import_services13.Invitation.State.CANCELLED: {
3981
4033
  if ((_l = (_k = hooks == null ? void 0 : hooks.host) == null ? void 0 : _k.onCancelled) == null ? void 0 : _l.call(_k, hostObservable)) {
3982
4034
  break;
3983
4035
  }
@@ -3986,7 +4038,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
3986
4038
  });
3987
4039
  break;
3988
4040
  }
3989
- case import_services12.Invitation.State.TIMEOUT: {
4041
+ case import_services13.Invitation.State.TIMEOUT: {
3990
4042
  if ((_n = (_m = hooks == null ? void 0 : hooks.host) == null ? void 0 : _m.onTimeout) == null ? void 0 : _n.call(_m, hostObservable)) {
3991
4043
  break;
3992
4044
  }
@@ -4012,12 +4064,12 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4012
4064
  };
4013
4065
  var createInvitation = (host, options) => {
4014
4066
  options != null ? options : options = {
4015
- authMethod: import_services12.Invitation.AuthMethod.NONE,
4067
+ authMethod: import_services13.Invitation.AuthMethod.NONE,
4016
4068
  ...options != null ? options : {}
4017
4069
  };
4018
4070
  if (host instanceof ServiceContext) {
4019
4071
  const hostHandler = host.getInvitationHandler({
4020
- kind: import_services12.Invitation.Kind.SPACE,
4072
+ kind: import_services13.Invitation.Kind.SPACE,
4021
4073
  ...options
4022
4074
  });
4023
4075
  return host.invitations.createInvitation(hostHandler, options);