@dxos/client-services 0.1.31 → 0.1.32-next.86f5578

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 (52) hide show
  1. package/dist/lib/browser/{chunk-DFO3FW2W.mjs → chunk-E3FD43YN.mjs} +423 -209
  2. package/dist/lib/browser/chunk-E3FD43YN.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 +3 -3
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +424 -210
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +432 -218
  11. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  12. package/dist/types/src/packlets/identity/identity-manager.d.ts +6 -0
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  14. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
  16. package/dist/types/src/packlets/services/service-host.d.ts +1 -0
  17. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  18. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +19 -1
  19. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  20. package/dist/types/src/packlets/spaces/data-space.d.ts +24 -4
  21. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +29 -1
  23. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/testing/host-test-builder.d.ts +2 -2
  26. package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +1 -1
  27. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +1 -0
  28. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +1 -1
  29. package/package.json +30 -30
  30. package/src/packlets/identity/identity-manager.ts +32 -17
  31. package/src/packlets/invitations/device-invitations-handler.ts +5 -3
  32. package/src/packlets/invitations/space-invitations-handler.test.ts +20 -3
  33. package/src/packlets/invitations/space-invitations-handler.ts +15 -8
  34. package/src/packlets/services/service-context.test.ts +6 -5
  35. package/src/packlets/services/service-host.ts +7 -2
  36. package/src/packlets/spaces/data-space-manager.test.ts +17 -2
  37. package/src/packlets/spaces/data-space-manager.ts +76 -30
  38. package/src/packlets/spaces/data-space.ts +90 -15
  39. package/src/packlets/spaces/notarization-plugin.test.ts +3 -1
  40. package/src/packlets/spaces/notarization-plugin.ts +64 -23
  41. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  42. package/src/packlets/spaces/spaces-service.ts +28 -17
  43. package/src/packlets/testing/host-test-builder.ts +2 -2
  44. package/src/packlets/testing/test-builder.ts +2 -2
  45. package/src/packlets/tests/client-services.test.ts +24 -11
  46. package/src/packlets/tests/client.test.ts +3 -6
  47. package/src/packlets/tests/halo-profile.test.ts +5 -5
  48. package/src/packlets/tests/spaces-invitations.test.ts +4 -4
  49. package/src/packlets/tests/spaces.test.ts +20 -11
  50. package/src/packlets/tests/text.test.ts +6 -6
  51. package/src/packlets/vault/vault-resource-lock.ts +10 -1
  52. package/dist/lib/browser/chunk-DFO3FW2W.mjs.map +0 -7
@@ -587,7 +587,7 @@ var IdentityManager = class {
587
587
  identityRecord
588
588
  }, {
589
589
  file: "identity-manager.ts",
590
- line: 63,
590
+ line: 71,
591
591
  scope: this,
592
592
  callSite: (f, a) => f(...a)
593
593
  });
@@ -606,7 +606,7 @@ var IdentityManager = class {
606
606
  assert2(!this._identity, "Identity already exists.");
607
607
  log3("creating identity...", {}, {
608
608
  file: "identity-manager.ts",
609
- line: 78,
609
+ line: 86,
610
610
  scope: this,
611
611
  callSite: (f, a) => f(...a)
612
612
  });
@@ -615,21 +615,23 @@ var IdentityManager = class {
615
615
  identityKey: await this._keyring.createKey(),
616
616
  deviceKey: await this._keyring.createKey(),
617
617
  haloSpace: {
618
- spaceKey: await this._keyring.createKey(),
618
+ key: await this._keyring.createKey(),
619
619
  genesisFeedKey: controlFeedKey,
620
- writeControlFeedKey: controlFeedKey,
621
- writeDataFeedKey: await this._keyring.createKey()
620
+ controlFeedKey,
621
+ dataFeedKey: await this._keyring.createKey()
622
622
  }
623
623
  };
624
624
  const identity = await this._constructIdentity(identityRecord);
625
625
  await identity.open();
626
626
  {
627
627
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
628
+ assert2(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.");
629
+ assert2(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.");
628
630
  const credentials = [
629
631
  // Space genesis.
630
- ...await generator.createSpaceGenesis(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.genesisFeedKey),
632
+ ...await generator.createSpaceGenesis(identityRecord.haloSpace.key, identityRecord.haloSpace.genesisFeedKey),
631
633
  // Feed admission.
632
- await generator.createFeedAdmission(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.writeDataFeedKey, AdmittedFeed2.Designation.DATA)
634
+ await generator.createFeedAdmission(identityRecord.haloSpace.key, identityRecord.haloSpace.dataFeedKey, AdmittedFeed2.Designation.DATA)
633
635
  ];
634
636
  if (displayName) {
635
637
  credentials.push(await generator.createProfileCredential({
@@ -654,7 +656,7 @@ var IdentityManager = class {
654
656
  deviceKey: identity.deviceKey
655
657
  }, {
656
658
  file: "identity-manager.ts",
657
- line: 136,
659
+ line: 143,
658
660
  scope: this,
659
661
  callSite: (f, a) => f(...a)
660
662
  });
@@ -668,7 +670,7 @@ var IdentityManager = class {
668
670
  params
669
671
  }, {
670
672
  file: "identity-manager.ts",
671
- line: 144,
673
+ line: 151,
672
674
  scope: this,
673
675
  callSite: (f, a) => f(...a)
674
676
  });
@@ -677,10 +679,11 @@ var IdentityManager = class {
677
679
  identityKey: params.identityKey,
678
680
  deviceKey: params.deviceKey,
679
681
  haloSpace: {
680
- spaceKey: params.haloSpaceKey,
682
+ key: params.haloSpaceKey,
681
683
  genesisFeedKey: params.haloGenesisFeedKey,
682
- writeControlFeedKey: params.controlFeedKey,
683
- writeDataFeedKey: params.dataFeedKey
684
+ controlFeedKey: params.controlFeedKey,
685
+ dataFeedKey: params.dataFeedKey,
686
+ controlTimeframe: params.controlTimeframe
684
687
  }
685
688
  };
686
689
  const identity = await this._constructIdentity(identityRecord);
@@ -694,7 +697,7 @@ var IdentityManager = class {
694
697
  deviceKey: identity.deviceKey
695
698
  }, {
696
699
  file: "identity-manager.ts",
697
- line: 164,
700
+ line: 172,
698
701
  scope: this,
699
702
  callSite: (f, a) => f(...a)
700
703
  });
@@ -706,14 +709,16 @@ var IdentityManager = class {
706
709
  identityRecord
707
710
  }, {
708
711
  file: "identity-manager.ts",
709
- line: 170,
712
+ line: 178,
710
713
  scope: this,
711
714
  callSite: (f, a) => f(...a)
712
715
  });
713
- const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.writeControlFeedKey, {
716
+ assert2(identityRecord.haloSpace.controlFeedKey);
717
+ const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
714
718
  writable: true
715
719
  });
716
- const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.writeDataFeedKey, {
720
+ assert2(identityRecord.haloSpace.dataFeedKey);
721
+ const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.dataFeedKey, {
717
722
  writable: true
718
723
  });
719
724
  const space = await this._constructSpace({
@@ -737,16 +742,19 @@ var IdentityManager = class {
737
742
  identityKey: identityRecord.identityKey
738
743
  }, {
739
744
  file: "identity-manager.ts",
740
- line: 196,
745
+ line: 206,
741
746
  scope: this,
742
747
  callSite: (f, a) => f(...a)
743
748
  });
749
+ if (identityRecord.haloSpace.controlTimeframe) {
750
+ identity.controlPipeline.state.setTargetTimeframe(identityRecord.haloSpace.controlTimeframe);
751
+ }
744
752
  return identity;
745
753
  }
746
754
  async _constructSpace({ spaceRecord, swarmIdentity, identityKey }) {
747
755
  return this._spaceManager.constructSpace({
748
756
  metadata: {
749
- key: spaceRecord.spaceKey,
757
+ key: spaceRecord.key,
750
758
  genesisFeedKey: spaceRecord.genesisFeedKey
751
759
  },
752
760
  swarmIdentity,
@@ -862,7 +870,8 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
862
870
  return {
863
871
  identityKey: identity.identityKey,
864
872
  haloSpaceKey: identity.haloSpaceKey,
865
- genesisFeedKey: identity.haloGenesisFeedKey
873
+ genesisFeedKey: identity.haloGenesisFeedKey,
874
+ controlTimeframe: identity.controlPipeline.state.timeframe
866
875
  };
867
876
  },
868
877
  authenticate: async ({ authenticationCode: code }) => {
@@ -870,7 +879,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
870
879
  authenticationCode: code
871
880
  }, {
872
881
  file: "device-invitations-handler.ts",
873
- line: 106,
882
+ line: 107,
874
883
  scope: this,
875
884
  callSite: (f, a) => f(...a)
876
885
  });
@@ -892,7 +901,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
892
901
  guest: credentials.deviceKey
893
902
  }, {
894
903
  file: "device-invitations-handler.ts",
895
- line: 121,
904
+ line: 122,
896
905
  scope: this,
897
906
  callSite: (f, a) => f(...a)
898
907
  });
@@ -911,7 +920,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
911
920
  host: identity.deviceKey
912
921
  }, {
913
922
  file: "device-invitations-handler.ts",
914
- line: 137,
923
+ line: 138,
915
924
  scope: this,
916
925
  callSite: (f, a) => f(...a)
917
926
  });
@@ -924,7 +933,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
924
933
  guest: deviceKey
925
934
  }, {
926
935
  file: "device-invitations-handler.ts",
927
- line: 140,
936
+ line: 141,
928
937
  scope: this,
929
938
  callSite: (f, a) => f(...a)
930
939
  });
@@ -933,7 +942,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
933
942
  if (!observable.cancelled) {
934
943
  log4.error("failed", err, {
935
944
  file: "device-invitations-handler.ts",
936
- line: 144,
945
+ line: 145,
937
946
  scope: this,
938
947
  callSite: (f, a) => f(...a)
939
948
  });
@@ -998,22 +1007,22 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
998
1007
  }
999
1008
  log4("connected", {}, {
1000
1009
  file: "device-invitations-handler.ts",
1001
- line: 215,
1010
+ line: 216,
1002
1011
  scope: this,
1003
1012
  callSite: (f, a) => f(...a)
1004
1013
  });
1005
1014
  (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1006
1015
  log4("sending admission request", {}, {
1007
1016
  file: "device-invitations-handler.ts",
1008
- line: 219,
1017
+ line: 220,
1009
1018
  scope: this,
1010
1019
  callSite: (f, a) => f(...a)
1011
1020
  });
1012
- const { identityKey, haloSpaceKey, genesisFeedKey } = await extension.rpc.HaloHostService.requestAdmission();
1021
+ const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = await extension.rpc.HaloHostService.requestAdmission();
1013
1022
  if (invitation.type === void 0 || invitation.type === Invitation.Type.INTERACTIVE) {
1014
1023
  log4("guest waiting for authentication code...", {}, {
1015
1024
  file: "device-invitations-handler.ts",
1016
- line: 226,
1025
+ line: 227,
1017
1026
  scope: this,
1018
1027
  callSite: (f, a) => f(...a)
1019
1028
  });
@@ -1023,7 +1032,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1023
1032
  });
1024
1033
  log4("sending authentication request", {}, {
1025
1034
  file: "device-invitations-handler.ts",
1026
- line: 229,
1035
+ line: 230,
1027
1036
  scope: this,
1028
1037
  callSite: (f, a) => f(...a)
1029
1038
  });
@@ -1041,7 +1050,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1041
1050
  dataFeedKey
1042
1051
  }, {
1043
1052
  file: "device-invitations-handler.ts",
1044
- line: 238,
1053
+ line: 239,
1045
1054
  scope: this,
1046
1055
  callSite: (f, a) => f(...a)
1047
1056
  });
@@ -1056,14 +1065,15 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1056
1065
  haloSpaceKey,
1057
1066
  haloGenesisFeedKey: genesisFeedKey,
1058
1067
  controlFeedKey,
1059
- dataFeedKey
1068
+ dataFeedKey,
1069
+ controlTimeframe
1060
1070
  });
1061
1071
  log4("admitted by host", {
1062
1072
  guest: identity.deviceKey,
1063
1073
  identityKey
1064
1074
  }, {
1065
1075
  file: "device-invitations-handler.ts",
1066
- line: 257,
1076
+ line: 259,
1067
1077
  scope: this,
1068
1078
  callSite: (f, a) => f(...a)
1069
1079
  });
@@ -1072,7 +1082,7 @@ var DeviceInvitationsHandler = class extends AbstractInvitationsHandler {
1072
1082
  if (!observable.cancelled) {
1073
1083
  log4.warn("auth failed", err, {
1074
1084
  file: "device-invitations-handler.ts",
1075
- line: 261,
1085
+ line: 263,
1076
1086
  scope: this,
1077
1087
  callSite: (f, a) => f(...a)
1078
1088
  });
@@ -1516,6 +1526,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1516
1526
  };
1517
1527
  },
1518
1528
  requestAdmission: async ({ identityKey, deviceKey, controlFeedKey, dataFeedKey }) => {
1529
+ var _a2;
1519
1530
  try {
1520
1531
  if (isAuthenticationRequired(invitation) && !authenticationPassed) {
1521
1532
  throw new Error("Not authenticated");
@@ -1536,7 +1547,9 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1536
1547
  await writeMessages2(space.inner.controlPipeline.writer, credentials);
1537
1548
  complete.wake(deviceKey);
1538
1549
  return {
1539
- credential: spaceMemberCredential
1550
+ credential: spaceMemberCredential,
1551
+ controlTimeframe: space.inner.controlPipeline.state.timeframe,
1552
+ dataTimeframe: (_a2 = space.dataPipeline.pipelineState) == null ? void 0 : _a2.timeframe
1540
1553
  };
1541
1554
  } catch (err) {
1542
1555
  observable.callback.onError(err);
@@ -1551,7 +1564,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1551
1564
  host: this._signingContext.deviceKey
1552
1565
  }, {
1553
1566
  file: "space-invitations-handler.ts",
1554
- line: 191,
1567
+ line: 195,
1555
1568
  scope: this,
1556
1569
  callSite: (f, a) => f(...a)
1557
1570
  });
@@ -1564,7 +1577,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1564
1577
  guest: deviceKey
1565
1578
  }, {
1566
1579
  file: "space-invitations-handler.ts",
1567
- line: 194,
1580
+ line: 198,
1568
1581
  scope: this,
1569
1582
  callSite: (f, a) => f(...a)
1570
1583
  });
@@ -1573,7 +1586,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1573
1586
  if (!observable.cancelled) {
1574
1587
  log6.error("failed", err, {
1575
1588
  file: "space-invitations-handler.ts",
1576
- line: 198,
1589
+ line: 202,
1577
1590
  scope: this,
1578
1591
  callSite: (f, a) => f(...a)
1579
1592
  });
@@ -1643,7 +1656,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1643
1656
  guest: this._signingContext.deviceKey
1644
1657
  }, {
1645
1658
  file: "space-invitations-handler.ts",
1646
- line: 271,
1659
+ line: 275,
1647
1660
  scope: this,
1648
1661
  callSite: (f, a) => f(...a)
1649
1662
  });
@@ -1652,7 +1665,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1652
1665
  guest: this._signingContext.deviceKey
1653
1666
  }, {
1654
1667
  file: "space-invitations-handler.ts",
1655
- line: 275,
1668
+ line: 279,
1656
1669
  scope: this,
1657
1670
  callSite: (f, a) => f(...a)
1658
1671
  });
@@ -1664,7 +1677,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1664
1677
  response: introductionResponse
1665
1678
  }, {
1666
1679
  file: "space-invitations-handler.ts",
1667
- line: 279,
1680
+ line: 283,
1668
1681
  scope: this,
1669
1682
  callSite: (f, a) => f(...a)
1670
1683
  });
@@ -1677,7 +1690,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1677
1690
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1678
1691
  log6("guest waiting for authentication code...", {}, {
1679
1692
  file: "space-invitations-handler.ts",
1680
- line: 293,
1693
+ line: 297,
1681
1694
  scope: this,
1682
1695
  callSite: (f, a) => f(...a)
1683
1696
  });
@@ -1687,7 +1700,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1687
1700
  });
1688
1701
  log6("sending authentication request", {}, {
1689
1702
  file: "space-invitations-handler.ts",
1690
- line: 297,
1703
+ line: 301,
1691
1704
  scope: this,
1692
1705
  callSite: (f, a) => f(...a)
1693
1706
  });
@@ -1705,7 +1718,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1705
1718
  attempt
1706
1719
  }, {
1707
1720
  file: "space-invitations-handler.ts",
1708
- line: 307,
1721
+ line: 311,
1709
1722
  scope: this,
1710
1723
  callSite: (f, a) => f(...a)
1711
1724
  });
@@ -1720,11 +1733,11 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1720
1733
  guest: this._signingContext.deviceKey
1721
1734
  }, {
1722
1735
  file: "space-invitations-handler.ts",
1723
- line: 318,
1736
+ line: 322,
1724
1737
  scope: this,
1725
1738
  callSite: (f, a) => f(...a)
1726
1739
  });
1727
- const { credential } = await extension.rpc.SpaceHostService.requestAdmission({
1740
+ const { credential, controlTimeframe, dataTimeframe } = await extension.rpc.SpaceHostService.requestAdmission({
1728
1741
  identityKey: this._signingContext.identityKey,
1729
1742
  deviceKey: this._signingContext.deviceKey,
1730
1743
  controlFeedKey,
@@ -1735,7 +1748,9 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1735
1748
  assert6(credential.subject.id.equals(this._signingContext.identityKey));
1736
1749
  const space = await this._spaceManager.acceptSpace({
1737
1750
  spaceKey: assertion.spaceKey,
1738
- genesisFeedKey: assertion.genesisFeedKey
1751
+ genesisFeedKey: assertion.genesisFeedKey,
1752
+ controlTimeframe,
1753
+ dataTimeframe
1739
1754
  });
1740
1755
  await this._signingContext.recordCredential(credential);
1741
1756
  log6("admitted by host", {
@@ -1743,7 +1758,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1743
1758
  spaceKey: space.key
1744
1759
  }, {
1745
1760
  file: "space-invitations-handler.ts",
1746
- line: 340,
1761
+ line: 347,
1747
1762
  scope: this,
1748
1763
  callSite: (f, a) => f(...a)
1749
1764
  });
@@ -1752,7 +1767,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler2 {
1752
1767
  if (!observable.cancelled) {
1753
1768
  log6.warn("auth failed", err, {
1754
1769
  file: "space-invitations-handler.ts",
1755
- line: 344,
1770
+ line: 351,
1756
1771
  scope: this,
1757
1772
  callSite: (f, a) => f(...a)
1758
1773
  });
@@ -1991,18 +2006,18 @@ var MemoryShellRuntime = class {
1991
2006
 
1992
2007
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
1993
2008
  import { Trigger as Trigger9 } from "@dxos/async";
1994
- import { log as log16, logInfo as logInfo2 } from "@dxos/log";
2009
+ import { log as log17, logInfo as logInfo3 } from "@dxos/log";
1995
2010
  import { MemorySignalManager as MemorySignalManager3, MemorySignalManagerContext as MemorySignalManagerContext3, WebsocketSignalManager as WebsocketSignalManager3 } from "@dxos/messaging";
1996
2011
  import { createWebRTCTransportFactory as createWebRTCTransportFactory2, NetworkManager as NetworkManager3 } from "@dxos/network-manager";
1997
2012
  import { getAsyncValue } from "@dxos/util";
1998
2013
 
1999
2014
  // packages/sdk/client-services/src/packlets/services/service-host.ts
2000
2015
  import assert12 from "@dxos/node-std/assert";
2001
- import { Event as Event6 } from "@dxos/async";
2016
+ import { Event as Event7 } from "@dxos/async";
2002
2017
  import { clientServiceBundle, createDefaultModelFactory } from "@dxos/client";
2003
2018
  import { raise as raise3 } from "@dxos/debug";
2004
2019
  import { DataServiceImpl } from "@dxos/echo-pipeline";
2005
- import { log as log14 } from "@dxos/log";
2020
+ import { log as log15 } from "@dxos/log";
2006
2021
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
2007
2022
 
2008
2023
  // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
@@ -2089,36 +2104,40 @@ var NetworkServiceImpl = class {
2089
2104
 
2090
2105
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2091
2106
  import assert10 from "@dxos/node-std/assert";
2092
- import { Event as Event5, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2093
- import { Context as Context7 } from "@dxos/context";
2107
+ import { Event as Event6, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
2108
+ import { SpaceState as SpaceState2 } from "@dxos/client";
2109
+ import { cancelWithContext, Context as Context7 } from "@dxos/context";
2094
2110
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
2095
- import { spaceGenesis, SnapshotManager } from "@dxos/echo-pipeline";
2111
+ import { SnapshotManager, spaceGenesis } from "@dxos/echo-pipeline";
2096
2112
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2097
- import { log as log8 } from "@dxos/log";
2113
+ import { log as log9 } from "@dxos/log";
2098
2114
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
2099
2115
  import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
2100
2116
 
2101
2117
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2102
- import { trackLeaks } from "@dxos/async";
2118
+ import { Event as Event5, scheduleTask as scheduleTask4, trackLeaks } from "@dxos/async";
2119
+ import { SpaceState } from "@dxos/client";
2103
2120
  import { Context as Context6 } from "@dxos/context";
2104
2121
  import { timed } from "@dxos/debug";
2105
- import { DataPipelineControllerImpl, createMappedFeedWriter } from "@dxos/echo-pipeline";
2122
+ import { createMappedFeedWriter, DataPipeline } from "@dxos/echo-pipeline";
2123
+ import { CancelledError, SystemError } from "@dxos/errors";
2106
2124
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2125
+ import { log as log8 } from "@dxos/log";
2107
2126
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2108
2127
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2109
2128
 
2110
2129
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2111
2130
  import assert9 from "@dxos/node-std/assert";
2112
2131
  import { DeferredTask, Event as Event4, scheduleTask as scheduleTask3, sleep as sleep3, TimeoutError, Trigger as Trigger4 } from "@dxos/async";
2113
- import { Context as Context5 } from "@dxos/context";
2132
+ import { Context as Context5, rejectOnDispose } from "@dxos/context";
2114
2133
  import { PublicKey as PublicKey5 } from "@dxos/keys";
2115
2134
  import { log as log7 } from "@dxos/log";
2116
2135
  import { schema as schema4 } from "@dxos/protocols";
2117
2136
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
2118
2137
  import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
2119
- var RETRY_TIMEOUT = 1e3;
2120
- var SUCCESS_DELAY = 1e3;
2121
- var NOTARIZE_TIMEOUT = 1e4;
2138
+ var DEFAULT_RETRY_TIMEOUT = 1e3;
2139
+ var DEFAULT_SUCCESS_DELAY = 1e3;
2140
+ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2122
2141
  var NotarizationPlugin = class {
2123
2142
  constructor() {
2124
2143
  this._ctx = new Context5();
@@ -2135,12 +2154,12 @@ var NotarizationPlugin = class {
2135
2154
  /**
2136
2155
  * Request credentials to be notarized.
2137
2156
  */
2138
- async notarize(credentials) {
2157
+ async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2139
2158
  log7("notarize", {
2140
2159
  credentials
2141
2160
  }, {
2142
2161
  file: "notarization-plugin.ts",
2143
- line: 50,
2162
+ line: 85,
2144
2163
  scope: this,
2145
2164
  callSite: (f, a) => f(...a)
2146
2165
  });
@@ -2152,7 +2171,7 @@ var NotarizationPlugin = class {
2152
2171
  err
2153
2172
  }, {
2154
2173
  file: "notarization-plugin.ts",
2155
- line: 59,
2174
+ line: 94,
2156
2175
  scope: this,
2157
2176
  callSite: (f, a) => f(...a)
2158
2177
  });
@@ -2160,27 +2179,27 @@ var NotarizationPlugin = class {
2160
2179
  errors.throw(err);
2161
2180
  }
2162
2181
  });
2163
- scheduleTask3(ctx, () => {
2164
- log7.warn("Notarization timeout", {}, {
2165
- file: "notarization-plugin.ts",
2166
- line: 67,
2167
- scope: this,
2168
- callSite: (f, a) => f(...a)
2169
- });
2170
- void ctx.dispose();
2171
- errors.throw(new TimeoutError(NOTARIZE_TIMEOUT, "Notarization timed out"));
2172
- }, NOTARIZE_TIMEOUT);
2182
+ opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2183
+ if (timeout !== 0) {
2184
+ scheduleTask3(ctx, () => {
2185
+ log7.warn("Notarization timeout", {
2186
+ timeout,
2187
+ peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2188
+ }, {
2189
+ file: "notarization-plugin.ts",
2190
+ line: 106,
2191
+ scope: this,
2192
+ callSite: (f, a) => f(...a)
2193
+ });
2194
+ void ctx.dispose();
2195
+ errors.throw(new TimeoutError(timeout, "Notarization timed out"));
2196
+ }, timeout);
2197
+ }
2173
2198
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2174
2199
  const peersTried = /* @__PURE__ */ new Set();
2175
2200
  const notarizeTask = new DeferredTask(ctx, async () => {
2176
2201
  try {
2177
2202
  if (this._extensions.size === 0) {
2178
- log7.warn("No peers to notarize with", {}, {
2179
- file: "notarization-plugin.ts",
2180
- line: 82,
2181
- scope: this,
2182
- callSite: (f, a) => f(...a)
2183
- });
2184
2203
  return;
2185
2204
  }
2186
2205
  const peer = [
@@ -2188,15 +2207,15 @@ var NotarizationPlugin = class {
2188
2207
  ].find((peer2) => !peersTried.has(peer2));
2189
2208
  if (!peer) {
2190
2209
  log7.warn("Exhausted all peers to notarize with", {
2191
- retryIn: RETRY_TIMEOUT
2210
+ retryIn: retryTimeout
2192
2211
  }, {
2193
2212
  file: "notarization-plugin.ts",
2194
- line: 89,
2213
+ line: 131,
2195
2214
  scope: this,
2196
2215
  callSite: (f, a) => f(...a)
2197
2216
  });
2198
2217
  peersTried.clear();
2199
- scheduleTask3(ctx, () => notarizeTask.schedule(), RETRY_TIMEOUT);
2218
+ scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
2200
2219
  return;
2201
2220
  }
2202
2221
  peersTried.add(peer);
@@ -2205,7 +2224,7 @@ var NotarizationPlugin = class {
2205
2224
  credentialId: credentials.map((credential) => credential.id)
2206
2225
  }, {
2207
2226
  file: "notarization-plugin.ts",
2208
- line: 96,
2227
+ line: 138,
2209
2228
  scope: this,
2210
2229
  callSite: (f, a) => f(...a)
2211
2230
  });
@@ -2214,15 +2233,15 @@ var NotarizationPlugin = class {
2214
2233
  });
2215
2234
  log7("success", {}, {
2216
2235
  file: "notarization-plugin.ts",
2217
- line: 100,
2236
+ line: 142,
2218
2237
  scope: this,
2219
2238
  callSite: (f, a) => f(...a)
2220
2239
  });
2221
- await sleep3(SUCCESS_DELAY);
2240
+ await sleep3(successDelay);
2222
2241
  } catch (err) {
2223
2242
  log7.warn("error notarizing (recoverable)", err, {
2224
2243
  file: "notarization-plugin.ts",
2225
- line: 103,
2244
+ line: 145,
2226
2245
  scope: this,
2227
2246
  callSite: (f, a) => f(...a)
2228
2247
  });
@@ -2233,12 +2252,13 @@ var NotarizationPlugin = class {
2233
2252
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2234
2253
  try {
2235
2254
  await Promise.race([
2255
+ rejectOnDispose(ctx),
2236
2256
  allNotarized,
2237
2257
  errors.wait()
2238
2258
  ]);
2239
2259
  log7("done", {}, {
2240
2260
  file: "notarization-plugin.ts",
2241
- line: 114,
2261
+ line: 155,
2242
2262
  scope: this,
2243
2263
  callSite: (f, a) => f(...a)
2244
2264
  });
@@ -2291,7 +2311,7 @@ var NotarizationPlugin = class {
2291
2311
  peer: extension.localPeerId
2292
2312
  }, {
2293
2313
  file: "notarization-plugin.ts",
2294
- line: 163,
2314
+ line: 204,
2295
2315
  scope: this,
2296
2316
  callSite: (f, a) => f(...a)
2297
2317
  });
@@ -2303,7 +2323,7 @@ var NotarizationPlugin = class {
2303
2323
  peer: extension.localPeerId
2304
2324
  }, {
2305
2325
  file: "notarization-plugin.ts",
2306
- line: 168,
2326
+ line: 209,
2307
2327
  scope: this,
2308
2328
  callSite: (f, a) => f(...a)
2309
2329
  });
@@ -2357,18 +2377,22 @@ var __decorate = function(decorators, target, key, desc) {
2357
2377
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2358
2378
  };
2359
2379
  var AUTH_TIMEOUT2 = 3e4;
2360
- var CONTROL_PIPELINE_READY_TIMEFRAME = 3e3;
2361
2380
  var DataSpace = class DataSpace2 {
2362
2381
  constructor(params) {
2363
2382
  this._ctx = new Context6();
2383
+ this._state = SpaceState.CLOSED;
2384
+ this.stateUpdate = new Event5();
2385
+ var _a;
2364
2386
  this._inner = params.inner;
2387
+ this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2365
2388
  this._gossip = params.gossip;
2366
2389
  this._presence = params.presence;
2367
2390
  this._keyring = params.keyring;
2368
2391
  this._feedStore = params.feedStore;
2369
2392
  this._metadataStore = params.metadataStore;
2370
2393
  this._signingContext = params.signingContext;
2371
- this._dataPipelineController = new DataPipelineControllerImpl({
2394
+ this._callbacks = (_a = params.callbacks) != null ? _a : {};
2395
+ this._dataPipeline = new DataPipeline({
2372
2396
  modelFactory: params.modelFactory,
2373
2397
  metadataStore: params.metadataStore,
2374
2398
  snapshotManager: params.snapshotManager,
@@ -2390,15 +2414,15 @@ var DataSpace = class DataSpace2 {
2390
2414
  get isOpen() {
2391
2415
  return this._inner.isOpen;
2392
2416
  }
2417
+ get state() {
2418
+ return this._state;
2419
+ }
2393
2420
  // TODO(burdon): Can we mark this for debugging only?
2394
2421
  get inner() {
2395
2422
  return this._inner;
2396
2423
  }
2397
- get dataPipelineController() {
2398
- return this._dataPipelineController;
2399
- }
2400
- get stateUpdate() {
2401
- return this._inner.stateUpdate;
2424
+ get dataPipeline() {
2425
+ return this._dataPipeline;
2402
2426
  }
2403
2427
  get presence() {
2404
2428
  return this._presence;
@@ -2410,9 +2434,12 @@ var DataSpace = class DataSpace2 {
2410
2434
  await this.notarizationPlugin.open();
2411
2435
  await this._notarizationPluginConsumer.open();
2412
2436
  await this._inner.open();
2437
+ this._state = SpaceState.INACTIVE;
2413
2438
  }
2414
2439
  async close() {
2440
+ this._state = SpaceState.CLOSED;
2415
2441
  await this._ctx.dispose();
2442
+ await this._dataPipeline.close();
2416
2443
  await this.authVerifier.close();
2417
2444
  await this._inner.close();
2418
2445
  await this._notarizationPluginConsumer.close();
@@ -2425,17 +2452,84 @@ var DataSpace = class DataSpace2 {
2425
2452
  listen(channel, callback) {
2426
2453
  return this._gossip.listen(channel, callback);
2427
2454
  }
2455
+ /**
2456
+ * Initialize the data pipeline in a separate task.
2457
+ */
2458
+ initializeDataPipelineAsync() {
2459
+ scheduleTask4(this._ctx, async () => {
2460
+ try {
2461
+ await this.initializeDataPipeline();
2462
+ } catch (err) {
2463
+ if (err instanceof CancelledError) {
2464
+ log8("Data pipeline initialization cancelled", err, {
2465
+ file: "data-space.ts",
2466
+ line: 178,
2467
+ scope: this,
2468
+ callSite: (f, a) => f(...a)
2469
+ });
2470
+ return;
2471
+ }
2472
+ log8.error("Error initializing data pipeline", err, {
2473
+ file: "data-space.ts",
2474
+ line: 182,
2475
+ scope: this,
2476
+ callSite: (f, a) => f(...a)
2477
+ });
2478
+ }
2479
+ });
2480
+ }
2428
2481
  async initializeDataPipeline() {
2482
+ var _a, _b, _c, _d;
2483
+ if (this._state !== SpaceState.INACTIVE) {
2484
+ throw new SystemError("Invalid operation");
2485
+ }
2486
+ this._state = SpaceState.INITIALIZING;
2429
2487
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
2430
- timeout: CONTROL_PIPELINE_READY_TIMEFRAME
2488
+ ctx: this._ctx,
2489
+ breakOnStall: false
2431
2490
  });
2432
2491
  await this._createWritableFeeds();
2492
+ log8("Writable feeds created", {}, {
2493
+ file: "data-space.ts",
2494
+ line: 200,
2495
+ scope: this,
2496
+ callSite: (f, a) => f(...a)
2497
+ });
2498
+ this.stateUpdate.emit();
2433
2499
  this.notarizationPlugin.setWriter(createMappedFeedWriter((credential) => ({
2434
2500
  credential: {
2435
2501
  credential
2436
2502
  }
2437
2503
  }), this._inner.controlPipeline.writer));
2438
- await this._inner.initDataPipeline(this._dataPipelineController);
2504
+ await this._dataPipeline.open({
2505
+ openPipeline: async (start) => {
2506
+ const pipeline = await this._inner.createDataPipeline({
2507
+ start
2508
+ });
2509
+ await pipeline.start();
2510
+ return pipeline;
2511
+ }
2512
+ });
2513
+ log8("waiting for data pipeline to reach target timeframe", {}, {
2514
+ file: "data-space.ts",
2515
+ line: 220,
2516
+ scope: this,
2517
+ callSite: (f, a) => f(...a)
2518
+ });
2519
+ await this._dataPipeline.pipelineState.waitUntilReachedTargetTimeframe({
2520
+ ctx: this._ctx,
2521
+ breakOnStall: false
2522
+ });
2523
+ log8("data pipeline ready", {}, {
2524
+ file: "data-space.ts",
2525
+ line: 227,
2526
+ scope: this,
2527
+ callSite: (f, a) => f(...a)
2528
+ });
2529
+ await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2530
+ this._state = SpaceState.READY;
2531
+ this.stateUpdate.emit();
2532
+ await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
2439
2533
  }
2440
2534
  async _createWritableFeeds() {
2441
2535
  const credentials = [];
@@ -2472,7 +2566,11 @@ var DataSpace = class DataSpace2 {
2472
2566
  }));
2473
2567
  }
2474
2568
  if (credentials.length > 0) {
2475
- await this.notarizationPlugin.notarize(credentials);
2569
+ await this.notarizationPlugin.notarize({
2570
+ ctx: this._ctx,
2571
+ credentials,
2572
+ timeout: 0
2573
+ });
2476
2574
  }
2477
2575
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2478
2576
  }
@@ -2495,7 +2593,6 @@ var __decorate2 = function(decorators, target, key, desc) {
2495
2593
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2496
2594
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2497
2595
  };
2498
- var DATA_PIPELINE_READY_TIMEOUT = 3e3;
2499
2596
  var DataSpaceManager = class DataSpaceManager2 {
2500
2597
  constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _modelFactory, _feedStore, _snapshotStore) {
2501
2598
  this._spaceManager = _spaceManager;
@@ -2507,52 +2604,53 @@ var DataSpaceManager = class DataSpaceManager2 {
2507
2604
  this._feedStore = _feedStore;
2508
2605
  this._snapshotStore = _snapshotStore;
2509
2606
  this._ctx = new Context7();
2510
- this.updated = new Event5();
2607
+ this.updated = new Event6();
2511
2608
  this._spaces = new ComplexMap3(PublicKey7.hash);
2609
+ this._isOpen = false;
2512
2610
  }
2513
2611
  // TODO(burdon): Remove.
2514
2612
  get spaces() {
2515
2613
  return this._spaces;
2516
2614
  }
2517
2615
  async open() {
2616
+ log9("open", {}, {
2617
+ file: "data-space-manager.ts",
2618
+ line: 80,
2619
+ scope: this,
2620
+ callSite: (f, a) => f(...a)
2621
+ });
2518
2622
  await this._metadataStore.load();
2519
- log8("metadata loaded", {
2623
+ log9("metadata loaded", {
2520
2624
  spaces: this._metadataStore.spaces.length
2521
2625
  }, {
2522
2626
  file: "data-space-manager.ts",
2523
- line: 67,
2627
+ line: 82,
2524
2628
  scope: this,
2525
2629
  callSite: (f, a) => f(...a)
2526
2630
  });
2527
2631
  for (const spaceMetadata of this._metadataStore.spaces) {
2528
- log8("load space", {
2632
+ log9("load space", {
2529
2633
  spaceMetadata
2530
2634
  }, {
2531
2635
  file: "data-space-manager.ts",
2532
- line: 70,
2636
+ line: 85,
2533
2637
  scope: this,
2534
2638
  callSite: (f, a) => f(...a)
2535
2639
  });
2536
2640
  const space = await this._constructSpace(spaceMetadata);
2537
- await space.initializeDataPipeline();
2538
- if (spaceMetadata.dataTimeframe) {
2539
- log8("waiting for latest timeframe", {
2540
- spaceMetadata
2541
- }, {
2542
- file: "data-space-manager.ts",
2543
- line: 74,
2544
- scope: this,
2545
- callSite: (f, a) => f(...a)
2546
- });
2547
- await space.dataPipelineController.pipelineState.setTargetTimeframe(spaceMetadata.dataTimeframe);
2548
- }
2549
- await space.dataPipelineController.pipelineState.waitUntilReachedTargetTimeframe({
2550
- timeout: DATA_PIPELINE_READY_TIMEOUT
2551
- });
2552
- this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
2641
+ space.initializeDataPipelineAsync();
2553
2642
  }
2643
+ this._isOpen = true;
2644
+ this.updated.emit();
2554
2645
  }
2555
2646
  async close() {
2647
+ log9("close", {}, {
2648
+ file: "data-space-manager.ts",
2649
+ line: 96,
2650
+ scope: this,
2651
+ callSite: (f, a) => f(...a)
2652
+ });
2653
+ this._isOpen = false;
2556
2654
  await this._ctx.dispose();
2557
2655
  for (const space of this._spaces.values()) {
2558
2656
  await space.close();
@@ -2562,6 +2660,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2562
2660
  * Creates a new space writing the genesis credentials to the control feed.
2563
2661
  */
2564
2662
  async createSpace() {
2663
+ assert10(this._isOpen, "Not open.");
2565
2664
  const spaceKey = await this._keyring.createKey();
2566
2665
  const controlFeedKey = await this._keyring.createKey();
2567
2666
  const dataFeedKey = await this._keyring.createKey();
@@ -2571,11 +2670,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2571
2670
  controlFeedKey,
2572
2671
  dataFeedKey
2573
2672
  };
2574
- log8("creating space...", {
2673
+ log9("creating space...", {
2575
2674
  spaceKey
2576
2675
  }, {
2577
2676
  file: "data-space-manager.ts",
2578
- line: 110,
2677
+ line: 120,
2579
2678
  scope: this,
2580
2679
  callSite: (f, a) => f(...a)
2581
2680
  });
@@ -2586,25 +2685,53 @@ var DataSpaceManager = class DataSpaceManager2 {
2586
2685
  assert10(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2587
2686
  await this._signingContext.recordCredential(memberCredential);
2588
2687
  await space.initializeDataPipeline();
2589
- this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
2590
2688
  this.updated.emit();
2591
2689
  return space;
2592
2690
  }
2593
2691
  // TODO(burdon): Rename join space.
2594
2692
  async acceptSpace(opts) {
2693
+ log9("accept space", {
2694
+ opts
2695
+ }, {
2696
+ file: "data-space-manager.ts",
2697
+ line: 139,
2698
+ scope: this,
2699
+ callSite: (f, a) => f(...a)
2700
+ });
2701
+ assert10(this._isOpen, "Not open.");
2595
2702
  assert10(!this._spaces.has(opts.spaceKey), "Space already exists.");
2596
2703
  const metadata = {
2597
2704
  key: opts.spaceKey,
2598
- genesisFeedKey: opts.genesisFeedKey
2705
+ genesisFeedKey: opts.genesisFeedKey,
2706
+ controlTimeframe: opts.controlTimeframe,
2707
+ dataTimeframe: opts.dataTimeframe
2599
2708
  };
2600
2709
  const space = await this._constructSpace(metadata);
2601
2710
  await this._metadataStore.addSpace(metadata);
2602
- await space.initializeDataPipeline();
2603
- this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
2711
+ space.initializeDataPipelineAsync();
2604
2712
  this.updated.emit();
2605
2713
  return space;
2606
2714
  }
2715
+ /**
2716
+ * Wait until the space data pipeline is fully initialized.
2717
+ * Used by invitation handler.
2718
+ * TODO(dmaretskyi): Consider removing.
2719
+ */
2720
+ async waitUntilSpaceReady(spaceKey) {
2721
+ await cancelWithContext(this._ctx, this.updated.waitForCondition(() => {
2722
+ const space = this._spaces.get(spaceKey);
2723
+ return !!space && space.state === SpaceState2.READY;
2724
+ }));
2725
+ }
2607
2726
  async _constructSpace(metadata) {
2727
+ log9("construct space", {
2728
+ metadata
2729
+ }, {
2730
+ file: "data-space-manager.ts",
2731
+ line: 175,
2732
+ scope: this,
2733
+ callSite: (f, a) => f(...a)
2734
+ });
2608
2735
  const gossip = new Gossip({
2609
2736
  localPeerId: this._signingContext.deviceKey
2610
2737
  });
@@ -2649,9 +2776,42 @@ var DataSpaceManager = class DataSpaceManager2 {
2649
2776
  keyring: this._keyring,
2650
2777
  feedStore: this._feedStore,
2651
2778
  signingContext: this._signingContext,
2652
- snapshotId: metadata.snapshot
2779
+ snapshotId: metadata.snapshot,
2780
+ callbacks: {
2781
+ beforeReady: async () => {
2782
+ log9("before space ready", {
2783
+ space: space.key
2784
+ }, {
2785
+ file: "data-space-manager.ts",
2786
+ line: 224,
2787
+ scope: this,
2788
+ callSite: (f, a) => f(...a)
2789
+ });
2790
+ this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseBackend.createDataServiceHost());
2791
+ },
2792
+ afterReady: async () => {
2793
+ log9("after space ready", {
2794
+ space: space.key,
2795
+ open: this._isOpen
2796
+ }, {
2797
+ file: "data-space-manager.ts",
2798
+ line: 231,
2799
+ scope: this,
2800
+ callSite: (f, a) => f(...a)
2801
+ });
2802
+ if (this._isOpen) {
2803
+ this.updated.emit();
2804
+ }
2805
+ }
2806
+ }
2653
2807
  });
2654
2808
  await dataSpace.open();
2809
+ if (metadata.controlTimeframe) {
2810
+ dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
2811
+ }
2812
+ if (metadata.dataTimeframe) {
2813
+ dataSpace.dataPipeline.setTargetTimeframe(metadata.dataTimeframe);
2814
+ }
2655
2815
  this._spaces.set(metadata.key, dataSpace);
2656
2816
  return dataSpace;
2657
2817
  }
@@ -2673,13 +2833,14 @@ DataSpaceManager = __decorate2([
2673
2833
  ], DataSpaceManager);
2674
2834
 
2675
2835
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2676
- import { EventSubscriptions as EventSubscriptions3, scheduleTask as scheduleTask4 } from "@dxos/async";
2836
+ import { EventSubscriptions as EventSubscriptions3, scheduleTask as scheduleTask5 } from "@dxos/async";
2677
2837
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
2678
2838
  import { raise, todo as todo2 } from "@dxos/debug";
2679
2839
  import { SpaceNotFoundError } from "@dxos/echo-pipeline";
2680
- import { log as log9 } from "@dxos/log";
2681
- import { SpaceMember, SpaceStatus } from "@dxos/protocols/proto/dxos/client/services";
2840
+ import { log as log10 } from "@dxos/log";
2841
+ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2682
2842
  import { humanize } from "@dxos/util";
2843
+ var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
2683
2844
  var SpacesServiceImpl = class {
2684
2845
  constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
2685
2846
  this._identityManager = _identityManager;
@@ -2702,12 +2863,12 @@ var SpacesServiceImpl = class {
2702
2863
  return new Stream10(({ next, ctx }) => {
2703
2864
  const onUpdate = async () => {
2704
2865
  const dataSpaceManager = await this._getDataSpaceManager();
2705
- const spaces = Array.from(dataSpaceManager.spaces.values()).filter((space) => this._dataServiceSubscriptions.getDataService(space.key)).map((space) => this._transformSpace(space));
2706
- log9("update", {
2866
+ const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
2867
+ log10("update", {
2707
2868
  spaces
2708
2869
  }, {
2709
2870
  file: "spaces-service.ts",
2710
- line: 62,
2871
+ line: 60,
2711
2872
  scope: this,
2712
2873
  callSite: (f, a) => f(...a)
2713
2874
  });
@@ -2715,28 +2876,27 @@ var SpacesServiceImpl = class {
2715
2876
  spaces
2716
2877
  });
2717
2878
  };
2718
- setTimeout(async () => {
2879
+ scheduleTask5(ctx, async () => {
2719
2880
  const dataSpaceManager = await this._getDataSpaceManager();
2720
2881
  const subscriptions = new EventSubscriptions3();
2882
+ ctx.onDispose(() => subscriptions.clear());
2721
2883
  const subscribeSpaces = () => {
2722
2884
  subscriptions.clear();
2723
2885
  for (const space of dataSpaceManager.spaces.values()) {
2724
- if (!this._dataServiceSubscriptions.getDataService(space.key)) {
2725
- continue;
2726
- }
2727
2886
  subscriptions.add(space.stateUpdate.on(ctx, onUpdate));
2728
2887
  subscriptions.add(space.presence.updated.on(ctx, onUpdate));
2888
+ space.inner.controlPipeline.state.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate);
2889
+ if (space.dataPipeline.pipelineState) {
2890
+ subscriptions.add(space.dataPipeline.pipelineState.timeframeUpdate.debounce(TIMEFRAME_UPDATE_DEBOUNCE_TIME).on(ctx, onUpdate));
2891
+ }
2729
2892
  }
2730
2893
  };
2731
2894
  dataSpaceManager.updated.on(ctx, () => {
2732
2895
  subscribeSpaces();
2733
2896
  void onUpdate();
2734
2897
  });
2735
- ctx.onDispose(() => subscriptions.clear());
2736
- scheduleTask4(ctx, () => {
2737
- subscribeSpaces();
2738
- void onUpdate();
2739
- });
2898
+ subscribeSpaces();
2899
+ void onUpdate();
2740
2900
  });
2741
2901
  if (!this._identityManager.identity) {
2742
2902
  next({
@@ -2753,7 +2913,7 @@ var SpacesServiceImpl = class {
2753
2913
  }
2754
2914
  subscribeMessages({ spaceKey, channel }) {
2755
2915
  return new Stream10(({ ctx, next }) => {
2756
- scheduleTask4(ctx, async () => {
2916
+ scheduleTask5(ctx, async () => {
2757
2917
  var _a;
2758
2918
  const dataSpaceManager = await this._getDataSpaceManager();
2759
2919
  const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise(new SpaceNotFoundError(spaceKey));
@@ -2774,7 +2934,7 @@ var SpacesServiceImpl = class {
2774
2934
  }
2775
2935
  });
2776
2936
  ctx.onDispose(() => processor.close());
2777
- scheduleTask4(ctx, () => processor.open());
2937
+ scheduleTask5(ctx, () => processor.open());
2778
2938
  });
2779
2939
  }
2780
2940
  async writeCredentials({ spaceKey, credentials }) {
@@ -2789,16 +2949,23 @@ var SpacesServiceImpl = class {
2789
2949
  }
2790
2950
  }
2791
2951
  _transformSpace(space) {
2952
+ var _a, _b;
2792
2953
  return {
2793
2954
  spaceKey: space.key,
2794
- status: space.isOpen ? SpaceStatus.ACTIVE : SpaceStatus.INACTIVE,
2955
+ state: space.state,
2956
+ pipeline: {
2957
+ targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2958
+ currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
2959
+ currentDataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe,
2960
+ targetDataTimeframe: (_b = space.dataPipeline.pipelineState) == null ? void 0 : _b.targetTimeframe
2961
+ },
2795
2962
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2796
- var _a, _b, _c;
2963
+ var _a2, _b2, _c;
2797
2964
  return {
2798
2965
  identity: {
2799
2966
  identityKey: member.key,
2800
2967
  profile: {
2801
- displayName: (_b = (_a = member.assertion.profile) == null ? void 0 : _a.displayName) != null ? _b : humanize(member.key)
2968
+ displayName: (_b2 = (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName) != null ? _b2 : humanize(member.key)
2802
2969
  }
2803
2970
  },
2804
2971
  presence: ((_c = this._identityManager.identity) == null ? void 0 : _c.identityKey.equals(member.key)) || space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
@@ -2898,7 +3065,17 @@ var IFrameProxyRuntime = class {
2898
3065
 
2899
3066
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
2900
3067
  import { asyncTimeout, Trigger as Trigger5 } from "@dxos/async";
2901
- import { log as log10 } from "@dxos/log";
3068
+ import { log as log11, logInfo } from "@dxos/log";
3069
+ var __decorate3 = function(decorators, target, key, desc) {
3070
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3071
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3072
+ r = Reflect.decorate(decorators, target, key, desc);
3073
+ else
3074
+ for (var i = decorators.length - 1; i >= 0; i--)
3075
+ if (d = decorators[i])
3076
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3077
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
3078
+ };
2902
3079
  var Message;
2903
3080
  (function(Message2) {
2904
3081
  Message2["ACQUIRING"] = "acquiring";
@@ -2912,14 +3089,41 @@ var VaultResourceLock = class {
2912
3089
  this._onRelease = onRelease;
2913
3090
  this._broadcastChannel.onmessage = this._onMessage.bind(this);
2914
3091
  }
3092
+ get lockKey() {
3093
+ return this._lockKey;
3094
+ }
2915
3095
  async acquire() {
2916
3096
  this._broadcastChannel.postMessage({
2917
3097
  message: Message.ACQUIRING
2918
3098
  });
2919
3099
  try {
3100
+ log11("aquiring lock...", {}, {
3101
+ file: "vault-resource-lock.ts",
3102
+ line: 44,
3103
+ scope: this,
3104
+ callSite: (f, a) => f(...a)
3105
+ });
2920
3106
  await asyncTimeout(this._requestLock(), 3e3);
3107
+ log11("acquired lock", {}, {
3108
+ file: "vault-resource-lock.ts",
3109
+ line: 46,
3110
+ scope: this,
3111
+ callSite: (f, a) => f(...a)
3112
+ });
2921
3113
  } catch (e) {
3114
+ log11("stealing lock...", {}, {
3115
+ file: "vault-resource-lock.ts",
3116
+ line: 48,
3117
+ scope: this,
3118
+ callSite: (f, a) => f(...a)
3119
+ });
2922
3120
  await this._requestLock(true);
3121
+ log11("stolen lock", {}, {
3122
+ file: "vault-resource-lock.ts",
3123
+ line: 50,
3124
+ scope: this,
3125
+ callSite: (f, a) => f(...a)
3126
+ });
2923
3127
  }
2924
3128
  }
2925
3129
  async release() {
@@ -2931,11 +3135,11 @@ var VaultResourceLock = class {
2931
3135
  }
2932
3136
  }
2933
3137
  async _requestLock(steal = false) {
2934
- log10("requesting lock...", {
3138
+ log11("requesting lock...", {
2935
3139
  steal
2936
3140
  }, {
2937
3141
  file: "vault-resource-lock.ts",
2938
- line: 56,
3142
+ line: 65,
2939
3143
  scope: this,
2940
3144
  callSite: (f, a) => f(...a)
2941
3145
  });
@@ -2948,16 +3152,16 @@ var VaultResourceLock = class {
2948
3152
  acquired.wake();
2949
3153
  this._releaseTrigger = new Trigger5();
2950
3154
  await this._releaseTrigger.wait();
2951
- log10("releasing lock...", {}, {
3155
+ log11("releasing lock...", {}, {
2952
3156
  file: "vault-resource-lock.ts",
2953
- line: 65,
3157
+ line: 74,
2954
3158
  scope: this,
2955
3159
  callSite: (f, a) => f(...a)
2956
3160
  });
2957
3161
  await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
2958
- log10("released lock", {}, {
3162
+ log11("released lock", {}, {
2959
3163
  file: "vault-resource-lock.ts",
2960
- line: 67,
3164
+ line: 76,
2961
3165
  scope: this,
2962
3166
  callSite: (f, a) => f(...a)
2963
3167
  });
@@ -2966,20 +3170,23 @@ var VaultResourceLock = class {
2966
3170
  await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
2967
3171
  });
2968
3172
  await acquired.wait();
2969
- log10("recieved lock", {
3173
+ log11("recieved lock", {
2970
3174
  steal
2971
3175
  }, {
2972
3176
  file: "vault-resource-lock.ts",
2973
- line: 74,
3177
+ line: 83,
2974
3178
  scope: this,
2975
3179
  callSite: (f, a) => f(...a)
2976
3180
  });
2977
3181
  }
2978
3182
  };
3183
+ __decorate3([
3184
+ logInfo
3185
+ ], VaultResourceLock.prototype, "lockKey", null);
2979
3186
 
2980
3187
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
2981
3188
  import { Trigger as Trigger7 } from "@dxos/async";
2982
- import { log as log12 } from "@dxos/log";
3189
+ import { log as log13 } from "@dxos/log";
2983
3190
  import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
2984
3191
  import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manager";
2985
3192
 
@@ -2987,7 +3194,7 @@ import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manag
2987
3194
  import assert11 from "@dxos/node-std/assert";
2988
3195
  import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
2989
3196
  import { iframeServiceBundle as iframeServiceBundle2, workerServiceBundle as workerServiceBundle2 } from "@dxos/client";
2990
- import { log as log11, logInfo } from "@dxos/log";
3197
+ import { log as log12, logInfo as logInfo2 } from "@dxos/log";
2991
3198
  import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
2992
3199
  import { Callback } from "@dxos/util";
2993
3200
 
@@ -3045,7 +3252,7 @@ var ClientRpcServer = class {
3045
3252
  };
3046
3253
 
3047
3254
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3048
- var __decorate3 = function(decorators, target, key, desc) {
3255
+ var __decorate4 = function(decorators, target, key, desc) {
3049
3256
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3050
3257
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3051
3258
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3109,7 +3316,7 @@ var WorkerSession = class {
3109
3316
  try {
3110
3317
  await this.close();
3111
3318
  } catch (err) {
3112
- log11.catch(err, {}, {
3319
+ log12.catch(err, {}, {
3113
3320
  file: "worker-session.ts",
3114
3321
  line: 107,
3115
3322
  scope: this,
@@ -3127,7 +3334,7 @@ var WorkerSession = class {
3127
3334
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
3128
3335
  }
3129
3336
  async open() {
3130
- log11.info("opening..", {}, {
3337
+ log12.info("opening..", {}, {
3131
3338
  file: "worker-session.ts",
3132
3339
  line: 121,
3133
3340
  scope: this,
@@ -3145,7 +3352,7 @@ var WorkerSession = class {
3145
3352
  try {
3146
3353
  await this._iframeRpc.rpc.IframeService.heartbeat();
3147
3354
  } catch (err1) {
3148
- log11.warn("Heartbeat failed", {
3355
+ log12.warn("Heartbeat failed", {
3149
3356
  err: err1
3150
3357
  }, {
3151
3358
  file: "worker-session.ts",
@@ -3156,7 +3363,7 @@ var WorkerSession = class {
3156
3363
  try {
3157
3364
  await this.close();
3158
3365
  } catch (err) {
3159
- log11.catch(err, {}, {
3366
+ log12.catch(err, {}, {
3160
3367
  file: "worker-session.ts",
3161
3368
  line: 137,
3162
3369
  scope: this,
@@ -3167,7 +3374,7 @@ var WorkerSession = class {
3167
3374
  }, this._options.heartbeatInterval);
3168
3375
  }
3169
3376
  async close() {
3170
- log11.info("closing..", {}, {
3377
+ log12.info("closing..", {}, {
3171
3378
  file: "worker-session.ts",
3172
3379
  line: 144,
3173
3380
  scope: this,
@@ -3176,7 +3383,7 @@ var WorkerSession = class {
3176
3383
  try {
3177
3384
  await this.onClose.callIfSet();
3178
3385
  } catch (err) {
3179
- log11.catch(err, {}, {
3386
+ log12.catch(err, {}, {
3180
3387
  file: "worker-session.ts",
3181
3388
  line: 148,
3182
3389
  scope: this,
@@ -3195,7 +3402,7 @@ var WorkerSession = class {
3195
3402
  try {
3196
3403
  await asyncTimeout2(this._shellClientRpc.open(), 1e3);
3197
3404
  } catch (e) {
3198
- log11.info("No shell connected.", {}, {
3405
+ log12.info("No shell connected.", {}, {
3199
3406
  file: "worker-session.ts",
3200
3407
  line: 162,
3201
3408
  scope: this,
@@ -3204,8 +3411,8 @@ var WorkerSession = class {
3204
3411
  }
3205
3412
  }
3206
3413
  };
3207
- __decorate3([
3208
- logInfo
3414
+ __decorate4([
3415
+ logInfo2
3209
3416
  ], WorkerSession.prototype, "origin", void 0);
3210
3417
 
3211
3418
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
@@ -3219,7 +3426,7 @@ var WorkerRuntime = class {
3219
3426
  this._clientServices = new ClientServicesHost();
3220
3427
  }
3221
3428
  async start() {
3222
- log12("starting...", {}, {
3429
+ log13("starting...", {}, {
3223
3430
  file: "worker-runtime.ts",
3224
3431
  line: 44,
3225
3432
  scope: this,
@@ -3240,7 +3447,7 @@ var WorkerRuntime = class {
3240
3447
  });
3241
3448
  await this._clientServices.open();
3242
3449
  this._ready.wake(void 0);
3243
- log12("started", {}, {
3450
+ log13("started", {}, {
3244
3451
  file: "worker-runtime.ts",
3245
3452
  line: 61,
3246
3453
  scope: this,
@@ -3248,7 +3455,7 @@ var WorkerRuntime = class {
3248
3455
  });
3249
3456
  } catch (err) {
3250
3457
  this._ready.wake(err);
3251
- log12.catch(err, {}, {
3458
+ log13.catch(err, {}, {
3252
3459
  file: "worker-runtime.ts",
3253
3460
  line: 64,
3254
3461
  scope: this,
@@ -3306,7 +3513,7 @@ import { failUndefined as failUndefined2 } from "@dxos/debug";
3306
3513
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
3307
3514
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
3308
3515
  import { Keyring } from "@dxos/keyring";
3309
- import { log as log13 } from "@dxos/log";
3516
+ import { log as log14 } from "@dxos/log";
3310
3517
  var ServiceContext = class {
3311
3518
  // prettier-ignore
3312
3519
  constructor(storage, networkManager, modelFactory) {
@@ -3343,7 +3550,7 @@ var ServiceContext = class {
3343
3550
  });
3344
3551
  }
3345
3552
  async open() {
3346
- log13("opening...", {}, {
3553
+ log14("opening...", {}, {
3347
3554
  file: "service-context.ts",
3348
3555
  line: 94,
3349
3556
  scope: this,
@@ -3355,7 +3562,7 @@ var ServiceContext = class {
3355
3562
  if (this.identityManager.identity) {
3356
3563
  await this._initialize();
3357
3564
  }
3358
- log13("opened", {}, {
3565
+ log14("opened", {}, {
3359
3566
  file: "service-context.ts",
3360
3567
  line: 101,
3361
3568
  scope: this,
@@ -3364,7 +3571,7 @@ var ServiceContext = class {
3364
3571
  }
3365
3572
  async close() {
3366
3573
  var _a, _b;
3367
- log13("closing...", {}, {
3574
+ log14("closing...", {}, {
3368
3575
  file: "service-context.ts",
3369
3576
  line: 105,
3370
3577
  scope: this,
@@ -3377,7 +3584,7 @@ var ServiceContext = class {
3377
3584
  await this.feedStore.close();
3378
3585
  await this.networkManager.close();
3379
3586
  this.dataServiceSubscriptions.clear();
3380
- log13("closed", {}, {
3587
+ log14("closed", {}, {
3381
3588
  file: "service-context.ts",
3382
3589
  line: 113,
3383
3590
  scope: this,
@@ -3385,7 +3592,7 @@ var ServiceContext = class {
3385
3592
  });
3386
3593
  }
3387
3594
  async reset() {
3388
- log13("resetting...", {}, {
3595
+ log14("resetting...", {}, {
3389
3596
  file: "service-context.ts",
3390
3597
  line: 117,
3391
3598
  scope: this,
@@ -3393,7 +3600,7 @@ var ServiceContext = class {
3393
3600
  });
3394
3601
  await this.close();
3395
3602
  await this.storage.reset();
3396
- log13("reset", {}, {
3603
+ log14("reset", {}, {
3397
3604
  file: "service-context.ts",
3398
3605
  line: 120,
3399
3606
  scope: this,
@@ -3413,7 +3620,7 @@ var ServiceContext = class {
3413
3620
  // Called when identity is created.
3414
3621
  async _initialize() {
3415
3622
  var _a;
3416
- log13("initializing spaces...", {}, {
3623
+ log14("initializing spaces...", {}, {
3417
3624
  file: "service-context.ts",
3418
3625
  line: 139,
3419
3626
  scope: this,
@@ -3447,7 +3654,7 @@ var ServiceContext = class {
3447
3654
  return;
3448
3655
  }
3449
3656
  if (!this.dataSpaceManager) {
3450
- log13("dataSpaceManager not initialized yet, ignoring space admission", {
3657
+ log14("dataSpaceManager not initialized yet, ignoring space admission", {
3451
3658
  details: assertion
3452
3659
  }, {
3453
3660
  file: "service-context.ts",
@@ -3458,7 +3665,7 @@ var ServiceContext = class {
3458
3665
  return;
3459
3666
  }
3460
3667
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3461
- log13("space already exists, ignoring space admission", {
3668
+ log14("space already exists, ignoring space admission", {
3462
3669
  details: assertion
3463
3670
  }, {
3464
3671
  file: "service-context.ts",
@@ -3469,7 +3676,7 @@ var ServiceContext = class {
3469
3676
  return;
3470
3677
  }
3471
3678
  try {
3472
- log13("accepting space recorded in halo", {
3679
+ log14("accepting space recorded in halo", {
3473
3680
  details: assertion
3474
3681
  }, {
3475
3682
  file: "service-context.ts",
@@ -3482,7 +3689,7 @@ var ServiceContext = class {
3482
3689
  genesisFeedKey: assertion.genesisFeedKey
3483
3690
  });
3484
3691
  } catch (err) {
3485
- log13.catch(err, {}, {
3692
+ log14.catch(err, {}, {
3486
3693
  file: "service-context.ts",
3487
3694
  line: 197,
3488
3695
  scope: this,
@@ -3530,7 +3737,8 @@ var ClientServicesHost = class {
3530
3737
  // TODO(wittjosiah): Turn this on by default.
3531
3738
  lockKey
3532
3739
  } = {}) {
3533
- this._statusUpdate = new Event6();
3740
+ this._statusUpdate = new Event7();
3741
+ this._opening = false;
3534
3742
  this._open = false;
3535
3743
  this._storage = storage;
3536
3744
  this._modelFactory = modelFactory;
@@ -3542,7 +3750,9 @@ var ClientServicesHost = class {
3542
3750
  }
3543
3751
  this._resourceLock = lockKey ? new VaultResourceLock({
3544
3752
  lockKey,
3545
- onAcquire: () => this.open(),
3753
+ onAcquire: () => {
3754
+ this._opening || this.open();
3755
+ },
3546
3756
  onRelease: () => this.close()
3547
3757
  }) : void 0;
3548
3758
  this._systemService = new SystemServiceImpl({
@@ -3598,20 +3808,23 @@ var ClientServicesHost = class {
3598
3808
  }
3599
3809
  }
3600
3810
  async open() {
3601
- var _a, _b;
3811
+ var _a, _b, _c;
3602
3812
  if (this._open) {
3603
3813
  return;
3604
3814
  }
3605
3815
  assert12(this._config, "config not set");
3606
3816
  assert12(this._storage, "storage not set");
3607
3817
  assert12(this._networkManager, "network manager not set");
3608
- log14("opening...", {}, {
3818
+ this._opening = true;
3819
+ log15("opening...", {
3820
+ lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
3821
+ }, {
3609
3822
  file: "service-host.ts",
3610
- line: 166,
3823
+ line: 170,
3611
3824
  scope: this,
3612
3825
  callSite: (f, a) => f(...a)
3613
3826
  });
3614
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
3827
+ await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
3615
3828
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._modelFactory);
3616
3829
  this._serviceRegistry.setServices({
3617
3830
  SystemService: this._systemService,
@@ -3640,14 +3853,15 @@ var ClientServicesHost = class {
3640
3853
  })
3641
3854
  });
3642
3855
  await this._serviceContext.open();
3856
+ this._opening = false;
3643
3857
  this._open = true;
3644
3858
  this._statusUpdate.emit();
3645
- const deviceKey = (_b = this._serviceContext.identityManager.identity) == null ? void 0 : _b.deviceKey;
3646
- log14("opened", {
3859
+ const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
3860
+ log15("opened", {
3647
3861
  deviceKey
3648
3862
  }, {
3649
3863
  file: "service-host.ts",
3650
- line: 219,
3864
+ line: 224,
3651
3865
  scope: this,
3652
3866
  callSite: (f, a) => f(...a)
3653
3867
  });
@@ -3658,11 +3872,11 @@ var ClientServicesHost = class {
3658
3872
  return;
3659
3873
  }
3660
3874
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
3661
- log14("closing...", {
3875
+ log15("closing...", {
3662
3876
  deviceKey
3663
3877
  }, {
3664
3878
  file: "service-host.ts",
3665
- line: 228,
3879
+ line: 233,
3666
3880
  scope: this,
3667
3881
  callSite: (f, a) => f(...a)
3668
3882
  });
@@ -3672,11 +3886,11 @@ var ClientServicesHost = class {
3672
3886
  await this._serviceContext.close();
3673
3887
  this._open = false;
3674
3888
  this._statusUpdate.emit();
3675
- log14("closed", {
3889
+ log15("closed", {
3676
3890
  deviceKey
3677
3891
  }, {
3678
3892
  file: "service-host.ts",
3679
- line: 233,
3893
+ line: 238,
3680
3894
  scope: this,
3681
3895
  callSite: (f, a) => f(...a)
3682
3896
  });
@@ -3707,7 +3921,7 @@ var LocalClientServices = class {
3707
3921
 
3708
3922
  // packages/sdk/client-services/src/packlets/services/utils.ts
3709
3923
  import { Config } from "@dxos/config";
3710
- import { log as log15 } from "@dxos/log";
3924
+ import { log as log16 } from "@dxos/log";
3711
3925
  import { MemorySignalManager as MemorySignalManager2, MemorySignalManagerContext as MemorySignalManagerContext2, WebsocketSignalManager as WebsocketSignalManager2 } from "@dxos/messaging";
3712
3926
  import { createWebRTCTransportFactory, MemoryTransportFactory, NetworkManager as NetworkManager2 } from "@dxos/network-manager";
3713
3927
  var fromHost = (config = new Config()) => {
@@ -3730,7 +3944,7 @@ var createNetworkManager = (config, options = {}) => {
3730
3944
  transportFactory
3731
3945
  });
3732
3946
  }
3733
- log15.warn("P2P network is not configured.", {}, {
3947
+ log16.warn("P2P network is not configured.", {}, {
3734
3948
  file: "utils.ts",
3735
3949
  line: 48,
3736
3950
  scope: void 0,
@@ -3743,7 +3957,7 @@ var createNetworkManager = (config, options = {}) => {
3743
3957
  };
3744
3958
 
3745
3959
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3746
- var __decorate4 = function(decorators, target, key, desc) {
3960
+ var __decorate5 = function(decorators, target, key, desc) {
3747
3961
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3748
3962
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3749
3963
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3773,7 +3987,7 @@ var IFrameHostRuntime = class {
3773
3987
  }
3774
3988
  async start() {
3775
3989
  var _a;
3776
- log16("starting...", {}, {
3990
+ log17("starting...", {}, {
3777
3991
  file: "iframe-host-runtime.ts",
3778
3992
  line: 67,
3779
3993
  scope: this,
@@ -3824,7 +4038,7 @@ var IFrameHostRuntime = class {
3824
4038
  (_a = this._shellRuntime) == null ? void 0 : _a.open()
3825
4039
  ]);
3826
4040
  this._ready.wake(void 0);
3827
- log16("started", {}, {
4041
+ log17("started", {}, {
3828
4042
  file: "iframe-host-runtime.ts",
3829
4043
  line: 110,
3830
4044
  scope: this,
@@ -3832,7 +4046,7 @@ var IFrameHostRuntime = class {
3832
4046
  });
3833
4047
  } catch (err) {
3834
4048
  this._ready.wake(err);
3835
- log16.catch(err, {}, {
4049
+ log17.catch(err, {}, {
3836
4050
  file: "iframe-host-runtime.ts",
3837
4051
  line: 113,
3838
4052
  scope: this,
@@ -3842,7 +4056,7 @@ var IFrameHostRuntime = class {
3842
4056
  }
3843
4057
  async stop() {
3844
4058
  var _a;
3845
- log16("stopping...", {}, {
4059
+ log17("stopping...", {}, {
3846
4060
  file: "iframe-host-runtime.ts",
3847
4061
  line: 118,
3848
4062
  scope: this,
@@ -3851,7 +4065,7 @@ var IFrameHostRuntime = class {
3851
4065
  await this._clientRpc.close();
3852
4066
  await this._clientServices.close();
3853
4067
  await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3854
- log16("stopped", {}, {
4068
+ log17("stopped", {}, {
3855
4069
  file: "iframe-host-runtime.ts",
3856
4070
  line: 122,
3857
4071
  scope: this,
@@ -3859,8 +4073,8 @@ var IFrameHostRuntime = class {
3859
4073
  });
3860
4074
  }
3861
4075
  };
3862
- __decorate4([
3863
- logInfo2
4076
+ __decorate5([
4077
+ logInfo3
3864
4078
  ], IFrameHostRuntime.prototype, "origin", void 0);
3865
4079
 
3866
4080
  export {
@@ -3898,4 +4112,4 @@ export {
3898
4112
  LocalClientServices,
3899
4113
  fromHost
3900
4114
  };
3901
- //# sourceMappingURL=chunk-DFO3FW2W.mjs.map
4115
+ //# sourceMappingURL=chunk-E3FD43YN.mjs.map