@dxos/client-services 0.8.1-main.ba2dec9 → 0.8.1-staging.31c3ee1

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/{node-esm/chunk-FLBMHVSB.mjs → browser/chunk-G4AZ6KHY.mjs} +1354 -869
  2. package/dist/lib/browser/chunk-G4AZ6KHY.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/testing/index.mjs +1 -1
  6. package/dist/lib/node/{chunk-K7LO776I.cjs → chunk-II76TP7N.cjs} +1058 -722
  7. package/dist/lib/node/chunk-II76TP7N.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +47 -47
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +8 -8
  11. package/dist/lib/{browser/chunk-VJODS5QE.mjs → node-esm/chunk-2H5CIBX2.mjs} +769 -570
  12. package/dist/lib/node-esm/chunk-2H5CIBX2.mjs.map +7 -0
  13. package/dist/lib/node-esm/index.mjs +1 -1
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +1 -1
  16. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  17. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +6 -0
  18. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  20. package/dist/types/src/packlets/space-export/index.d.ts +3 -0
  21. package/dist/types/src/packlets/space-export/index.d.ts.map +1 -0
  22. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -0
  23. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -0
  24. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +23 -0
  25. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -0
  26. package/dist/types/src/packlets/space-export/tar.test.d.ts +2 -0
  27. package/dist/types/src/packlets/space-export/tar.test.d.ts.map +1 -0
  28. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +8 -2
  29. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/data-space.d.ts +1 -0
  31. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  32. package/dist/types/src/packlets/spaces/spaces-service.d.ts +3 -1
  33. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  34. package/dist/types/src/version.d.ts +1 -1
  35. package/dist/types/src/version.d.ts.map +1 -1
  36. package/package.json +39 -38
  37. package/src/packlets/devices/devices-service.ts +2 -2
  38. package/src/packlets/devtools/feeds.ts +4 -3
  39. package/src/packlets/identity/contacts-service.ts +2 -2
  40. package/src/packlets/identity/identity-recovery-manager.ts +27 -0
  41. package/src/packlets/identity/identity-service.ts +2 -0
  42. package/src/packlets/space-export/index.ts +6 -0
  43. package/src/packlets/space-export/space-archive-reader.ts +33 -0
  44. package/src/packlets/space-export/space-archive-writer.ts +83 -0
  45. package/src/packlets/space-export/tar.test.ts +25 -0
  46. package/src/packlets/spaces/data-space-manager.ts +70 -9
  47. package/src/packlets/spaces/data-space.ts +14 -1
  48. package/src/packlets/spaces/spaces-service.ts +45 -7
  49. package/src/version.ts +1 -1
  50. package/dist/lib/browser/chunk-VJODS5QE.mjs.map +0 -7
  51. package/dist/lib/node/chunk-K7LO776I.cjs.map +0 -7
  52. package/dist/lib/node-esm/chunk-FLBMHVSB.mjs.map +0 -7
@@ -1,7 +1,7 @@
1
- import "@dxos/node-std/globals";
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // packages/sdk/client-services/src/packlets/devtools/feeds.ts
4
- import { EventSubscriptions } from "@dxos/async";
4
+ import { SubscriptionList } from "@dxos/async";
5
5
  import { Stream } from "@dxos/codec-protobuf/stream";
6
6
  import { FeedIterator } from "@dxos/feed-store";
7
7
  import { PublicKey } from "@dxos/keys";
@@ -10,7 +10,7 @@ import { ComplexMap } from "@dxos/util";
10
10
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/feeds.ts";
11
11
  var subscribeToFeeds = ({ feedStore, spaceManager }, { feedKeys }) => {
12
12
  return new Stream(({ next }) => {
13
- const subscriptions = new EventSubscriptions();
13
+ const subscriptions = new SubscriptionList();
14
14
  const feedMap = new ComplexMap(PublicKey.hash);
15
15
  const update = () => {
16
16
  const { feeds } = feedStore;
@@ -72,7 +72,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
72
72
  if (!feedKey) {
73
73
  return;
74
74
  }
75
- const subscriptions = new EventSubscriptions();
75
+ const subscriptions = new SubscriptionList();
76
76
  const timeout = setTimeout(async () => {
77
77
  const feed = feedStore.getFeed(feedKey);
78
78
  if (!feed) {
@@ -397,7 +397,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
397
397
  import { TRACE_PROCESSOR } from "@dxos/tracing";
398
398
 
399
399
  // packages/sdk/client-services/src/version.ts
400
- var DXOS_VERSION = "0.8.1-main.ba2dec9";
400
+ var DXOS_VERSION = "0.8.1-staging.31c3ee1";
401
401
 
402
402
  // packages/sdk/client-services/src/packlets/services/platform.ts
403
403
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -551,98 +551,20 @@ var getStorageDiagnostics = async () => {
551
551
  }));
552
552
  };
553
553
 
554
- // packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
555
- import { Trigger } from "@dxos/async";
556
- import { log as log2 } from "@dxos/log";
557
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
558
- var CHANNEL_NAME = "dxos.diagnostics.broadcast";
559
- var MessageType;
560
- (function(MessageType2) {
561
- MessageType2["PROBE"] = "probe";
562
- MessageType2["PROBE_ACK"] = "probe-ack";
563
- MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
564
- MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
565
- })(MessageType || (MessageType = {}));
554
+ // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-broadcast.ts
566
555
  var createCollectDiagnosticsBroadcastSender = () => {
567
556
  return {
568
- broadcastDiagnosticsRequest: async () => {
569
- let expectedResponse = "probe-ack";
570
- let channel;
571
- try {
572
- const trigger = new Trigger();
573
- channel = new BroadcastChannel(CHANNEL_NAME);
574
- channel.onmessage = (msg) => {
575
- if (expectedResponse === msg.data.type) {
576
- trigger.wake(msg.data);
577
- }
578
- };
579
- channel.postMessage({
580
- type: "probe"
581
- });
582
- await trigger.wait({
583
- timeout: 200
584
- });
585
- expectedResponse = "receive-diagnostics";
586
- trigger.reset();
587
- channel.postMessage({
588
- type: "request-diagnostics"
589
- });
590
- const diagnostics = await trigger.wait({
591
- timeout: 5e3
592
- });
593
- return diagnostics.payload;
594
- } catch (e) {
595
- const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
596
- return {
597
- expectedResponse,
598
- errorDescription
599
- };
600
- } finally {
601
- safeClose(channel);
602
- }
603
- }
557
+ broadcastDiagnosticsRequest: async () => void 0
604
558
  };
605
559
  };
606
- var createCollectDiagnosticsBroadcastHandler = (systemService) => {
607
- let channel;
560
+ var createCollectDiagnosticsBroadcastHandler = (_) => {
608
561
  return {
609
562
  start: () => {
610
- channel = new BroadcastChannel(CHANNEL_NAME);
611
- channel.onmessage = async (message) => {
612
- try {
613
- if (message.data.type === "probe") {
614
- channel?.postMessage({
615
- type: "probe-ack"
616
- });
617
- } else if (message.data.type === "request-diagnostics") {
618
- const diagnostics = await systemService.getDiagnostics({});
619
- channel?.postMessage({
620
- type: "receive-diagnostics",
621
- payload: diagnostics
622
- });
623
- }
624
- } catch (error) {
625
- log2.catch(error, void 0, {
626
- F: __dxlog_file4,
627
- L: 77,
628
- S: void 0,
629
- C: (f, a) => f(...a)
630
- });
631
- }
632
- };
633
563
  },
634
564
  stop: () => {
635
- safeClose(channel);
636
- channel = void 0;
637
565
  }
638
566
  };
639
567
  };
640
- var safeClose = (channel) => {
641
- try {
642
- channel?.close();
643
- } catch (e) {
644
- }
645
- };
646
568
 
647
569
  // packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
648
570
  import { ClientServicesProviderResource } from "@dxos/client-protocol";
@@ -686,12 +608,12 @@ var findConfigs = () => {
686
608
  };
687
609
 
688
610
  // packages/sdk/client-services/src/packlets/identity/authenticator.ts
689
- import { Trigger as Trigger2 } from "@dxos/async";
611
+ import { Trigger } from "@dxos/async";
690
612
  import { Context as Context2 } from "@dxos/context";
691
613
  import { verifyCredential } from "@dxos/credentials";
692
- import { log as log3 } from "@dxos/log";
614
+ import { log as log2 } from "@dxos/log";
693
615
  import { schema } from "@dxos/protocols/proto";
694
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
616
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
695
617
  var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
696
618
  var createAuthProvider = (signer) => async (nonce) => {
697
619
  const credential = await signer.createCredential({
@@ -707,7 +629,7 @@ var TrustedKeySetAuthVerifier = class {
707
629
  constructor(_params) {
708
630
  this._params = _params;
709
631
  this._ctx = new Context2(void 0, {
710
- F: __dxlog_file5,
632
+ F: __dxlog_file4,
711
633
  L: 45
712
634
  });
713
635
  }
@@ -717,20 +639,20 @@ var TrustedKeySetAuthVerifier = class {
717
639
  get verifier() {
718
640
  return async (nonce, auth) => {
719
641
  const credential = Credential.decode(auth);
720
- log3("authenticating...", {
642
+ log2("authenticating...", {
721
643
  credential
722
644
  }, {
723
- F: __dxlog_file5,
645
+ F: __dxlog_file4,
724
646
  L: 56,
725
647
  S: this,
726
648
  C: (f, a) => f(...a)
727
649
  });
728
650
  const result = await verifyCredential(credential);
729
651
  if (result.kind === "fail") {
730
- log3("Invalid credential", {
652
+ log2("Invalid credential", {
731
653
  result
732
654
  }, {
733
- F: __dxlog_file5,
655
+ F: __dxlog_file4,
734
656
  L: 60,
735
657
  S: this,
736
658
  C: (f, a) => f(...a)
@@ -738,11 +660,11 @@ var TrustedKeySetAuthVerifier = class {
738
660
  return false;
739
661
  }
740
662
  if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
741
- log3("Invalid nonce", {
663
+ log2("Invalid nonce", {
742
664
  nonce,
743
665
  credential
744
666
  }, {
745
- F: __dxlog_file5,
667
+ F: __dxlog_file4,
746
668
  L: 65,
747
669
  S: this,
748
670
  C: (f, a) => f(...a)
@@ -750,39 +672,39 @@ var TrustedKeySetAuthVerifier = class {
750
672
  return false;
751
673
  }
752
674
  if (this._isTrustedKey(credential.issuer)) {
753
- log3("key is trusted -- auth success", {
675
+ log2("key is trusted -- auth success", {
754
676
  key: credential.issuer
755
677
  }, {
756
- F: __dxlog_file5,
678
+ F: __dxlog_file4,
757
679
  L: 70,
758
680
  S: this,
759
681
  C: (f, a) => f(...a)
760
682
  });
761
683
  return true;
762
684
  }
763
- const trigger = new Trigger2();
685
+ const trigger = new Trigger();
764
686
  this._ctx.onDispose(() => {
765
687
  trigger.wake(false);
766
688
  });
767
689
  const clear = this._params.update.on(this._ctx, () => {
768
690
  if (this._isTrustedKey(credential.issuer)) {
769
- log3("auth success", {
691
+ log2("auth success", {
770
692
  key: credential.issuer
771
693
  }, {
772
- F: __dxlog_file5,
694
+ F: __dxlog_file4,
773
695
  L: 81,
774
696
  S: this,
775
697
  C: (f, a) => f(...a)
776
698
  });
777
699
  trigger.wake(true);
778
700
  } else {
779
- log3("key is not currently in trusted set, waiting...", {
701
+ log2("key is not currently in trusted set, waiting...", {
780
702
  key: credential.issuer,
781
703
  trusted: [
782
704
  ...this._params.trustedKeysProvider()
783
705
  ]
784
706
  }, {
785
- F: __dxlog_file5,
707
+ F: __dxlog_file4,
786
708
  L: 84,
787
709
  S: this,
788
710
  C: (f, a) => f(...a)
@@ -813,7 +735,7 @@ import { Context as Context3, Resource } from "@dxos/context";
813
735
  import { EdgeConnectionClosedError, EdgeIdentityChangedError } from "@dxos/edge-client";
814
736
  import { invariant as invariant2 } from "@dxos/invariant";
815
737
  import { PublicKey as PublicKey3 } from "@dxos/keys";
816
- import { log as log4, logInfo } from "@dxos/log";
738
+ import { log as log3, logInfo } from "@dxos/log";
817
739
  import { EdgeService } from "@dxos/protocols";
818
740
  import { buf } from "@dxos/protocols/buf";
819
741
  import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
@@ -886,7 +808,7 @@ function _using_ctx() {
886
808
  }
887
809
  };
888
810
  }
889
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/edge-feed-replicator.ts";
811
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/edge-feed-replicator.ts";
890
812
  var EdgeFeedReplicator = class extends Resource {
891
813
  constructor({ messenger, spaceId }) {
892
814
  super();
@@ -905,8 +827,8 @@ var EdgeFeedReplicator = class extends Resource {
905
827
  this._spaceId = spaceId;
906
828
  }
907
829
  async _open() {
908
- log4("open", void 0, {
909
- F: __dxlog_file6,
830
+ log3("open", void 0, {
831
+ F: __dxlog_file5,
910
832
  L: 56,
911
833
  S: this,
912
834
  C: (f, a) => f(...a)
@@ -921,11 +843,11 @@ var EdgeFeedReplicator = class extends Resource {
921
843
  }
922
844
  const [spaceId] = rest;
923
845
  if (spaceId !== this._spaceId) {
924
- log4("spaceID mismatch", {
846
+ log3("spaceID mismatch", {
925
847
  spaceId,
926
848
  _spaceId: this._spaceId
927
849
  }, {
928
- F: __dxlog_file6,
850
+ F: __dxlog_file5,
929
851
  L: 70,
930
852
  S: this,
931
853
  C: (f, a) => f(...a)
@@ -933,12 +855,12 @@ var EdgeFeedReplicator = class extends Resource {
933
855
  return;
934
856
  }
935
857
  const payload = decodeCbor(message.payload.value);
936
- log4("receive", {
858
+ log3("receive", {
937
859
  from: message.source,
938
860
  feedKey: payload.feedKey,
939
861
  type: payload.type
940
862
  }, {
941
- F: __dxlog_file6,
863
+ F: __dxlog_file5,
942
864
  L: 75,
943
865
  S: this,
944
866
  C: (f, a) => f(...a)
@@ -956,8 +878,8 @@ var EdgeFeedReplicator = class extends Resource {
956
878
  }
957
879
  }
958
880
  async _close() {
959
- log4("close", void 0, {
960
- F: __dxlog_file6,
881
+ log3("close", void 0, {
882
+ F: __dxlog_file5,
961
883
  L: 95,
962
884
  S: this,
963
885
  C: (f, a) => f(...a)
@@ -968,8 +890,8 @@ var EdgeFeedReplicator = class extends Resource {
968
890
  this._connected = true;
969
891
  const connectionCtx = this._createConnectionContext();
970
892
  this._connectionCtx = connectionCtx;
971
- log4("connection context created", void 0, {
972
- F: __dxlog_file6,
893
+ log3("connection context created", void 0, {
894
+ F: __dxlog_file5,
973
895
  L: 103,
974
896
  S: this,
975
897
  C: (f, a) => f(...a)
@@ -981,8 +903,8 @@ var EdgeFeedReplicator = class extends Resource {
981
903
  });
982
904
  }
983
905
  async _resetConnection() {
984
- log4("resetConnection", void 0, {
985
- F: __dxlog_file6,
906
+ log3("resetConnection", void 0, {
907
+ F: __dxlog_file5,
986
908
  L: 112,
987
909
  S: this,
988
910
  C: (f, a) => f(...a)
@@ -993,12 +915,12 @@ var EdgeFeedReplicator = class extends Resource {
993
915
  this._remoteLength.clear();
994
916
  }
995
917
  async addFeed(feed) {
996
- log4("addFeed", {
918
+ log3("addFeed", {
997
919
  key: feed.key,
998
920
  connected: this._connected,
999
921
  hasConnectionCtx: !!this._connectionCtx
1000
922
  }, {
1001
- F: __dxlog_file6,
923
+ F: __dxlog_file5,
1002
924
  L: 120,
1003
925
  S: this,
1004
926
  C: (f, a) => f(...a)
@@ -1012,10 +934,10 @@ var EdgeFeedReplicator = class extends Resource {
1012
934
  return defaultMap(this._pushMutex, key, () => new Mutex());
1013
935
  }
1014
936
  async _replicateFeed(ctx, feed) {
1015
- log4("replicateFeed", {
937
+ log3("replicateFeed", {
1016
938
  key: feed.key
1017
939
  }, {
1018
- F: __dxlog_file6,
940
+ F: __dxlog_file5,
1019
941
  L: 133,
1020
942
  S: this,
1021
943
  C: (f, a) => f(...a)
@@ -1030,8 +952,8 @@ var EdgeFeedReplicator = class extends Resource {
1030
952
  }
1031
953
  async _sendMessage(message) {
1032
954
  if (!this._connectionCtx) {
1033
- log4("message dropped because connection was disposed", void 0, {
1034
- F: __dxlog_file6,
955
+ log3("message dropped because connection was disposed", void 0, {
956
+ F: __dxlog_file5,
1035
957
  L: 146,
1036
958
  S: this,
1037
959
  C: (f, a) => f(...a)
@@ -1039,18 +961,18 @@ var EdgeFeedReplicator = class extends Resource {
1039
961
  return;
1040
962
  }
1041
963
  if (message.type === "data") {
1042
- log4("sending blocks", {
964
+ log3("sending blocks", {
1043
965
  feedKey: message.feedKey,
1044
966
  blocks: message.blocks.map((b) => b.index)
1045
967
  }, {
1046
- F: __dxlog_file6,
968
+ F: __dxlog_file5,
1047
969
  L: 151,
1048
970
  S: this,
1049
971
  C: (f, a) => f(...a)
1050
972
  });
1051
973
  }
1052
974
  invariant2(message.feedKey, void 0, {
1053
- F: __dxlog_file6,
975
+ F: __dxlog_file5,
1054
976
  L: 157,
1055
977
  S: this,
1056
978
  A: [
@@ -1059,10 +981,10 @@ var EdgeFeedReplicator = class extends Resource {
1059
981
  ]
1060
982
  });
1061
983
  const payloadValue = bufferToArray(encodeCbor(message));
1062
- log4("send", {
984
+ log3("send", {
1063
985
  type: message.type
1064
986
  }, {
1065
- F: __dxlog_file6,
987
+ F: __dxlog_file5,
1066
988
  L: 160,
1067
989
  S: this,
1068
990
  C: (f, a) => f(...a)
@@ -1080,8 +1002,8 @@ var EdgeFeedReplicator = class extends Resource {
1080
1002
  }
1081
1003
  _onMessage(message) {
1082
1004
  if (!this._connectionCtx) {
1083
- log4.warn("received message after connection context was disposed", void 0, {
1084
- F: __dxlog_file6,
1005
+ log3.warn("received message after connection context was disposed", void 0, {
1006
+ F: __dxlog_file5,
1085
1007
  L: 175,
1086
1008
  S: this,
1087
1009
  C: (f, a) => f(...a)
@@ -1096,10 +1018,10 @@ var EdgeFeedReplicator = class extends Resource {
1096
1018
  const feedKey = PublicKey3.fromHex(message.feedKey);
1097
1019
  const feed = this._feeds.get(feedKey);
1098
1020
  if (!feed) {
1099
- log4.warn("Feed not found", {
1021
+ log3.warn("Feed not found", {
1100
1022
  feedKey
1101
1023
  }, {
1102
- F: __dxlog_file6,
1024
+ F: __dxlog_file5,
1103
1025
  L: 184,
1104
1026
  S: this,
1105
1027
  C: (f, a) => f(...a)
@@ -1114,8 +1036,8 @@ var EdgeFeedReplicator = class extends Resource {
1114
1036
  feedKey
1115
1037
  };
1116
1038
  if (message.length > feed.length) {
1117
- log4("requesting missing blocks", logMeta, {
1118
- F: __dxlog_file6,
1039
+ log3("requesting missing blocks", logMeta, {
1040
+ F: __dxlog_file5,
1119
1041
  L: 194,
1120
1042
  S: this,
1121
1043
  C: (f, a) => f(...a)
@@ -1129,8 +1051,8 @@ var EdgeFeedReplicator = class extends Resource {
1129
1051
  }
1130
1052
  });
1131
1053
  } else if (message.length < feed.length) {
1132
- log4("pushing blocks to remote", logMeta, {
1133
- F: __dxlog_file6,
1054
+ log3("pushing blocks to remote", logMeta, {
1055
+ F: __dxlog_file5,
1134
1056
  L: 202,
1135
1057
  S: this,
1136
1058
  C: (f, a) => f(...a)
@@ -1145,11 +1067,11 @@ var EdgeFeedReplicator = class extends Resource {
1145
1067
  }
1146
1068
  }
1147
1069
  case "data": {
1148
- log4("received data", {
1070
+ log3("received data", {
1149
1071
  feed: message.feedKey,
1150
1072
  blocks: message.blocks.map((b) => b.index)
1151
1073
  }, {
1152
- F: __dxlog_file6,
1074
+ F: __dxlog_file5,
1153
1075
  L: 211,
1154
1076
  S: this,
1155
1077
  C: (f, a) => f(...a)
@@ -1157,10 +1079,10 @@ var EdgeFeedReplicator = class extends Resource {
1157
1079
  const feedKey = PublicKey3.fromHex(message.feedKey);
1158
1080
  const feed = this._feeds.get(feedKey);
1159
1081
  if (!feed) {
1160
- log4.warn("Feed not found", {
1082
+ log3.warn("Feed not found", {
1161
1083
  feedKey
1162
1084
  }, {
1163
- F: __dxlog_file6,
1085
+ F: __dxlog_file5,
1164
1086
  L: 216,
1165
1087
  S: this,
1166
1088
  C: (f, a) => f(...a)
@@ -1171,10 +1093,10 @@ var EdgeFeedReplicator = class extends Resource {
1171
1093
  break;
1172
1094
  }
1173
1095
  default: {
1174
- log4.warn("Unknown message", {
1096
+ log3.warn("Unknown message", {
1175
1097
  ...message
1176
1098
  }, {
1177
- F: __dxlog_file6,
1099
+ F: __dxlog_file5,
1178
1100
  L: 225,
1179
1101
  S: this,
1180
1102
  C: (f, a) => f(...a)
@@ -1184,12 +1106,12 @@ var EdgeFeedReplicator = class extends Resource {
1184
1106
  });
1185
1107
  }
1186
1108
  async _pushBlocks(feed, from, to) {
1187
- log4("pushing blocks", {
1109
+ log3("pushing blocks", {
1188
1110
  feed: feed.key.toHex(),
1189
1111
  from,
1190
1112
  to
1191
1113
  }, {
1192
- F: __dxlog_file6,
1114
+ F: __dxlog_file5,
1193
1115
  L: 232,
1194
1116
  S: this,
1195
1117
  C: (f, a) => f(...a)
@@ -1199,7 +1121,7 @@ var EdgeFeedReplicator = class extends Resource {
1199
1121
  valueEncoding: "binary"
1200
1122
  });
1201
1123
  invariant2(data instanceof Uint8Array, void 0, {
1202
- F: __dxlog_file6,
1124
+ F: __dxlog_file5,
1203
1125
  L: 237,
1204
1126
  S: this,
1205
1127
  A: [
@@ -1223,11 +1145,11 @@ var EdgeFeedReplicator = class extends Resource {
1223
1145
  this._remoteLength.set(feed.key, to);
1224
1146
  }
1225
1147
  async _integrateBlocks(feed, blocks) {
1226
- log4("integrating blocks", {
1148
+ log3("integrating blocks", {
1227
1149
  feed: feed.key.toHex(),
1228
1150
  blocks: blocks.length
1229
1151
  }, {
1230
- F: __dxlog_file6,
1152
+ F: __dxlog_file5,
1231
1153
  L: 258,
1232
1154
  S: this,
1233
1155
  C: (f, a) => f(...a)
@@ -1248,8 +1170,8 @@ var EdgeFeedReplicator = class extends Resource {
1248
1170
  var _usingCtx = _using_ctx();
1249
1171
  const _ = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
1250
1172
  if (!this._remoteLength.has(feed.key)) {
1251
- log4("blocks not pushed because remote length is unknown", void 0, {
1252
- F: __dxlog_file6,
1173
+ log3("blocks not pushed because remote length is unknown", void 0, {
1174
+ F: __dxlog_file5,
1253
1175
  L: 279,
1254
1176
  S: this,
1255
1177
  C: (f, a) => f(...a)
@@ -1273,8 +1195,8 @@ var EdgeFeedReplicator = class extends Resource {
1273
1195
  return;
1274
1196
  }
1275
1197
  if (err instanceof EdgeIdentityChangedError || err instanceof EdgeConnectionClosedError) {
1276
- log4("resetting on reconnect", void 0, {
1277
- F: __dxlog_file6,
1198
+ log3("resetting on reconnect", void 0, {
1199
+ F: __dxlog_file5,
1278
1200
  L: 296,
1279
1201
  S: this,
1280
1202
  C: (f, a) => f(...a)
@@ -1285,7 +1207,7 @@ var EdgeFeedReplicator = class extends Resource {
1285
1207
  }
1286
1208
  }
1287
1209
  }, {
1288
- F: __dxlog_file6,
1210
+ F: __dxlog_file5,
1289
1211
  L: 290
1290
1212
  });
1291
1213
  return connectionCtx;
@@ -1307,12 +1229,13 @@ var bufferizeBlock = (block) => ({
1307
1229
 
1308
1230
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
1309
1231
  import { Event as Event7, Mutex as Mutex2, scheduleTask as scheduleTask4, sleep as sleep3, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
1232
+ import { save } from "@dxos/automerge/automerge";
1310
1233
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
1311
- import { Context as Context5, ContextDisposedError, cancelWithContext as cancelWithContext2 } from "@dxos/context";
1234
+ import { Context as Context6, ContextDisposedError, cancelWithContext as cancelWithContext2 } from "@dxos/context";
1312
1235
  import { timed, warnAfterTimeout } from "@dxos/debug";
1313
1236
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
1314
1237
  import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
1315
- import { failedInvariant } from "@dxos/invariant";
1238
+ import { failedInvariant as failedInvariant3, invariant as invariant11 } from "@dxos/invariant";
1316
1239
  import { PublicKey as PublicKey8 } from "@dxos/keys";
1317
1240
  import { log as log12 } from "@dxos/log";
1318
1241
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -1370,7 +1293,7 @@ var AutomergeSpaceState = class extends Resource2 {
1370
1293
  // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
1371
1294
  import { invariant as invariant3 } from "@dxos/invariant";
1372
1295
  import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
1373
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
1296
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
1374
1297
  var LOAD_DOC_TIMEOUT = 1e4;
1375
1298
  var runEpochMigration = async (ctx, context) => {
1376
1299
  switch (context.migration) {
@@ -1403,7 +1326,7 @@ var runEpochMigration = async (ctx, context) => {
1403
1326
  // TODO(dmaretskyi): This path doesn't seem to fit here. This is not a migration.
1404
1327
  case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
1405
1328
  invariant3(context.newAutomergeRoot, void 0, {
1406
- F: __dxlog_file7,
1329
+ F: __dxlog_file6,
1407
1330
  L: 62,
1408
1331
  S: void 0,
1409
1332
  A: [
@@ -1421,12 +1344,12 @@ var runEpochMigration = async (ctx, context) => {
1421
1344
  };
1422
1345
 
1423
1346
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
1424
- import { DeferredTask, Event as Event3, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger3, scheduleMicroTask as scheduleMicroTask2 } from "@dxos/async";
1347
+ import { DeferredTask, Event as Event3, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger2, scheduleMicroTask as scheduleMicroTask2 } from "@dxos/async";
1425
1348
  import { rejectOnDispose, Resource as Resource3 } from "@dxos/context";
1426
1349
  import { verifyCredential as verifyCredential2 } from "@dxos/credentials";
1427
1350
  import { invariant as invariant4 } from "@dxos/invariant";
1428
1351
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1429
- import { logInfo as logInfo2, log as log5 } from "@dxos/log";
1352
+ import { logInfo as logInfo2, log as log4 } from "@dxos/log";
1430
1353
  import { EdgeCallFailedError } from "@dxos/protocols";
1431
1354
  import { schema as schema2 } from "@dxos/protocols/proto";
1432
1355
  import { RpcExtension } from "@dxos/teleport";
@@ -1437,7 +1360,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1437
1360
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1438
1361
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1439
1362
  }
1440
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
1363
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
1441
1364
  var DEFAULT_RETRY_TIMEOUT = 1e3;
1442
1365
  var DEFAULT_SUCCESS_DELAY = 1e3;
1443
1366
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -1463,7 +1386,7 @@ var NotarizationPlugin = class extends Resource3 {
1463
1386
  setActiveEdgePollingEnabled(enabled) {
1464
1387
  const client = this._edgeClient;
1465
1388
  invariant4(client, void 0, {
1466
- F: __dxlog_file8,
1389
+ F: __dxlog_file7,
1467
1390
  L: 111,
1468
1391
  S: this,
1469
1392
  A: [
@@ -1501,16 +1424,16 @@ var NotarizationPlugin = class extends Resource3 {
1501
1424
  * Request credentials to be notarized.
1502
1425
  */
1503
1426
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY, edgeRetryJitter }) {
1504
- log5("notarize", {
1427
+ log4("notarize", {
1505
1428
  credentials
1506
1429
  }, {
1507
- F: __dxlog_file8,
1430
+ F: __dxlog_file7,
1508
1431
  L: 153,
1509
1432
  S: this,
1510
1433
  C: (f, a) => f(...a)
1511
1434
  });
1512
1435
  invariant4(credentials.every((credential) => credential.id), "Credentials must have an id", {
1513
- F: __dxlog_file8,
1436
+ F: __dxlog_file7,
1514
1437
  L: 154,
1515
1438
  S: this,
1516
1439
  A: [
@@ -1518,13 +1441,13 @@ var NotarizationPlugin = class extends Resource3 {
1518
1441
  "'Credentials must have an id'"
1519
1442
  ]
1520
1443
  });
1521
- const errors = new Trigger3();
1444
+ const errors = new Trigger2();
1522
1445
  const ctx = this._ctx.derive({
1523
1446
  onError: (err) => {
1524
- log5.warn("Notarization error", {
1447
+ log4.warn("Notarization error", {
1525
1448
  err
1526
1449
  }, {
1527
- F: __dxlog_file8,
1450
+ F: __dxlog_file7,
1528
1451
  L: 162,
1529
1452
  S: this,
1530
1453
  C: (f, a) => f(...a)
@@ -1555,8 +1478,8 @@ var NotarizationPlugin = class extends Resource3 {
1555
1478
  allNotarized,
1556
1479
  errors.wait()
1557
1480
  ]);
1558
- log5("done", void 0, {
1559
- F: __dxlog_file8,
1481
+ log4("done", void 0, {
1482
+ F: __dxlog_file7,
1560
1483
  L: 187,
1561
1484
  S: this,
1562
1485
  C: (f, a) => f(...a)
@@ -1576,10 +1499,10 @@ var NotarizationPlugin = class extends Resource3 {
1576
1499
  ...this._extensions
1577
1500
  ].find((peer2) => !peersTried.has(peer2));
1578
1501
  if (!peer) {
1579
- log5.info("Exhausted all peers to notarize with", {
1502
+ log4.info("Exhausted all peers to notarize with", {
1580
1503
  retryIn: retryTimeout
1581
1504
  }, {
1582
- F: __dxlog_file8,
1505
+ F: __dxlog_file7,
1583
1506
  L: 210,
1584
1507
  S: this,
1585
1508
  C: (f, a) => f(...a)
@@ -1589,11 +1512,11 @@ var NotarizationPlugin = class extends Resource3 {
1589
1512
  return;
1590
1513
  }
1591
1514
  peersTried.add(peer);
1592
- log5("try notarizing", {
1515
+ log4("try notarizing", {
1593
1516
  peer: peer.localPeerId,
1594
1517
  credentialId: credentials.map((credential) => credential.id)
1595
1518
  }, {
1596
- F: __dxlog_file8,
1519
+ F: __dxlog_file7,
1597
1520
  L: 217,
1598
1521
  S: this,
1599
1522
  C: (f, a) => f(...a)
@@ -1601,8 +1524,8 @@ var NotarizationPlugin = class extends Resource3 {
1601
1524
  await peer.rpc.NotarizationService.notarize({
1602
1525
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
1603
1526
  });
1604
- log5("success", void 0, {
1605
- F: __dxlog_file8,
1527
+ log4("success", void 0, {
1528
+ F: __dxlog_file7,
1606
1529
  L: 221,
1607
1530
  S: this,
1608
1531
  C: (f, a) => f(...a)
@@ -1610,8 +1533,8 @@ var NotarizationPlugin = class extends Resource3 {
1610
1533
  await sleep(successDelay);
1611
1534
  } catch (err) {
1612
1535
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
1613
- log5.info("error notarizing (recoverable)", err, {
1614
- F: __dxlog_file8,
1536
+ log4.info("error notarizing (recoverable)", err, {
1537
+ F: __dxlog_file7,
1615
1538
  L: 226,
1616
1539
  S: this,
1617
1540
  C: (f, a) => f(...a)
@@ -1639,8 +1562,8 @@ var NotarizationPlugin = class extends Resource3 {
1639
1562
  jitter: timeouts.jitter
1640
1563
  }
1641
1564
  });
1642
- log5("edge notarization success", void 0, {
1643
- F: __dxlog_file8,
1565
+ log4("edge notarization success", void 0, {
1566
+ F: __dxlog_file7,
1644
1567
  L: 254,
1645
1568
  S: this,
1646
1569
  C: (f, a) => f(...a)
@@ -1663,7 +1586,7 @@ var NotarizationPlugin = class extends Resource3 {
1663
1586
  }
1664
1587
  setWriter(writer) {
1665
1588
  invariant4(!this._writer, "Writer already set.", {
1666
- F: __dxlog_file8,
1589
+ F: __dxlog_file7,
1667
1590
  L: 274,
1668
1591
  S: this,
1669
1592
  A: [
@@ -1705,18 +1628,18 @@ var NotarizationPlugin = class extends Resource3 {
1705
1628
  });
1706
1629
  const credentials = response.awaitingNotarization.credentials;
1707
1630
  if (!credentials.length) {
1708
- log5("edge did not return credentials for notarization", void 0, {
1709
- F: __dxlog_file8,
1631
+ log4("edge did not return credentials for notarization", void 0, {
1632
+ F: __dxlog_file7,
1710
1633
  L: 311,
1711
1634
  S: this,
1712
1635
  C: (f, a) => f(...a)
1713
1636
  });
1714
1637
  return;
1715
1638
  }
1716
- log5("got edge credentials for notarization", {
1639
+ log4("got edge credentials for notarization", {
1717
1640
  count: credentials.length
1718
1641
  }, {
1719
- F: __dxlog_file8,
1642
+ F: __dxlog_file7,
1720
1643
  L: 315,
1721
1644
  S: this,
1722
1645
  C: (f, a) => f(...a)
@@ -1726,10 +1649,10 @@ var NotarizationPlugin = class extends Resource3 {
1726
1649
  return credentialCodec.decode(binary);
1727
1650
  });
1728
1651
  await this._notarizeCredentials(writer, decodedCredentials);
1729
- log5.info("notarized edge credentials", {
1652
+ log4.info("notarized edge credentials", {
1730
1653
  count: decodedCredentials.length
1731
1654
  }, {
1732
- F: __dxlog_file8,
1655
+ F: __dxlog_file7,
1733
1656
  L: 324,
1734
1657
  S: this,
1735
1658
  C: (f, a) => f(...a)
@@ -1743,7 +1666,7 @@ var NotarizationPlugin = class extends Resource3 {
1743
1666
  if (this._processedCredentials.has(id)) {
1744
1667
  return;
1745
1668
  }
1746
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger3()).value.wait();
1669
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger2()).value.wait();
1747
1670
  }
1748
1671
  /**
1749
1672
  * Requests from other peers to notarize credentials.
@@ -1757,7 +1680,7 @@ var NotarizationPlugin = class extends Resource3 {
1757
1680
  async _notarizeCredentials(writer, credentials) {
1758
1681
  for (const credential of credentials) {
1759
1682
  invariant4(credential.id, "Credential must have an id", {
1760
- F: __dxlog_file8,
1683
+ F: __dxlog_file7,
1761
1684
  L: 350,
1762
1685
  S: this,
1763
1686
  A: [
@@ -1778,10 +1701,10 @@ var NotarizationPlugin = class extends Resource3 {
1778
1701
  createExtension() {
1779
1702
  const extension = new NotarizationTeleportExtension({
1780
1703
  onOpen: async () => {
1781
- log5("extension opened", {
1704
+ log4("extension opened", {
1782
1705
  peer: extension.localPeerId
1783
1706
  }, {
1784
- F: __dxlog_file8,
1707
+ F: __dxlog_file7,
1785
1708
  L: 365,
1786
1709
  S: this,
1787
1710
  C: (f, a) => f(...a)
@@ -1790,10 +1713,10 @@ var NotarizationPlugin = class extends Resource3 {
1790
1713
  this._extensionOpened.emit();
1791
1714
  },
1792
1715
  onClose: async () => {
1793
- log5("extension closed", {
1716
+ log4("extension closed", {
1794
1717
  peer: extension.localPeerId
1795
1718
  }, {
1796
- F: __dxlog_file8,
1719
+ F: __dxlog_file7,
1797
1720
  L: 370,
1798
1721
  S: this,
1799
1722
  C: (f, a) => f(...a)
@@ -1806,11 +1729,11 @@ var NotarizationPlugin = class extends Resource3 {
1806
1729
  }
1807
1730
  _scheduleTimeout(ctx, errors, timeout) {
1808
1731
  scheduleTask2(ctx, () => {
1809
- log5.warn("Notarization timeout", {
1732
+ log4.warn("Notarization timeout", {
1810
1733
  timeout,
1811
1734
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
1812
1735
  }, {
1813
- F: __dxlog_file8,
1736
+ F: __dxlog_file7,
1814
1737
  L: 382,
1815
1738
  S: this,
1816
1739
  C: (f, a) => f(...a)
@@ -1825,17 +1748,17 @@ _ts_decorate2([
1825
1748
  ], NotarizationPlugin.prototype, "_spaceId", void 0);
1826
1749
  var handleEdgeError = (error) => {
1827
1750
  if (!(error instanceof EdgeCallFailedError) || error.errorData) {
1828
- log5.catch(error, void 0, {
1829
- F: __dxlog_file8,
1751
+ log4.catch(error, void 0, {
1752
+ F: __dxlog_file7,
1830
1753
  L: 396,
1831
1754
  S: void 0,
1832
1755
  C: (f, a) => f(...a)
1833
1756
  });
1834
1757
  } else {
1835
- log5.info("Edge notarization failure", {
1758
+ log4.info("Edge notarization failure", {
1836
1759
  reason: error.reason
1837
1760
  }, {
1838
- F: __dxlog_file8,
1761
+ F: __dxlog_file7,
1839
1762
  L: 398,
1840
1763
  S: void 0,
1841
1764
  C: (f, a) => f(...a)
@@ -1878,7 +1801,7 @@ import { Event as Event5 } from "@dxos/async";
1878
1801
  import { AUTH_TIMEOUT, LOAD_CONTROL_FEEDS_TIMEOUT } from "@dxos/client-protocol";
1879
1802
  import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSignerWithChain, ProfileStateMachine } from "@dxos/credentials";
1880
1803
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
1881
- import { invariant as invariant7 } from "@dxos/invariant";
1804
+ import { invariant as invariant8 } from "@dxos/invariant";
1882
1805
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1883
1806
  import { log as log9 } from "@dxos/log";
1884
1807
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
@@ -1889,8 +1812,8 @@ import { ComplexSet as ComplexSet2 } from "@dxos/util";
1889
1812
  // packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts
1890
1813
  import { getCredentialAssertion } from "@dxos/credentials";
1891
1814
  import { SpaceId } from "@dxos/keys";
1892
- import { log as log6 } from "@dxos/log";
1893
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
1815
+ import { log as log5 } from "@dxos/log";
1816
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/default-space-state-machine.ts";
1894
1817
  var DefaultSpaceStateMachine = class {
1895
1818
  constructor(_params) {
1896
1819
  this._params = _params;
@@ -1903,11 +1826,11 @@ var DefaultSpaceStateMachine = class {
1903
1826
  switch (assertion["@type"]) {
1904
1827
  case "dxos.halo.credentials.DefaultSpace": {
1905
1828
  if (!credential.subject.id.equals(this._params.identityKey)) {
1906
- log6.warn("Invalid default space credential", {
1829
+ log5.warn("Invalid default space credential", {
1907
1830
  expectedIdentity: this._params.identityKey,
1908
1831
  credential
1909
1832
  }, {
1910
- F: __dxlog_file9,
1833
+ F: __dxlog_file8,
1911
1834
  L: 32,
1912
1835
  S: this,
1913
1836
  C: (f, a) => f(...a)
@@ -1915,10 +1838,10 @@ var DefaultSpaceStateMachine = class {
1915
1838
  return;
1916
1839
  }
1917
1840
  if (!SpaceId.isValid(assertion.spaceId)) {
1918
- log6.warn("Invalid default space id", {
1841
+ log5.warn("Invalid default space id", {
1919
1842
  id: assertion.spaceId
1920
1843
  }, {
1921
- F: __dxlog_file9,
1844
+ F: __dxlog_file8,
1922
1845
  L: 36,
1923
1846
  S: this,
1924
1847
  C: (f, a) => f(...a)
@@ -1934,16 +1857,17 @@ var DefaultSpaceStateMachine = class {
1934
1857
 
1935
1858
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
1936
1859
  import { Event as Event4, synchronized, trackLeaks } from "@dxos/async";
1860
+ import { interpretAsDocumentId } from "@dxos/automerge/automerge-repo";
1937
1861
  import { PropertiesType, TYPE_PROPERTIES } from "@dxos/client-protocol";
1938
- import { LifecycleState, Resource as Resource4, cancelWithContext } from "@dxos/context";
1862
+ import { Context as Context4, LifecycleState, Resource as Resource4, cancelWithContext } from "@dxos/context";
1939
1863
  import { createAdmissionCredentials, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
1940
- import { findInlineObjectOfType, AuthStatus, CredentialServerExtension } from "@dxos/echo-pipeline";
1941
- import { SpaceDocVersion, encodeReference } from "@dxos/echo-protocol";
1864
+ import { DatabaseRoot, findInlineObjectOfType, AuthStatus, CredentialServerExtension } from "@dxos/echo-pipeline";
1865
+ import { SpaceDocVersion, createIdFromSpaceKey, encodeReference } from "@dxos/echo-protocol";
1942
1866
  import { createObjectId, getTypeReference } from "@dxos/echo-schema";
1943
1867
  import { writeMessages } from "@dxos/feed-store";
1944
- import { invariant as invariant5 } from "@dxos/invariant";
1868
+ import { assertArgument, assertState, failedInvariant, invariant as invariant5 } from "@dxos/invariant";
1945
1869
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1946
- import { log as log7 } from "@dxos/log";
1870
+ import { log as log6 } from "@dxos/log";
1947
1871
  import { AlreadyJoinedError, trace as Trace } from "@dxos/protocols";
1948
1872
  import { Invitation, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
1949
1873
  import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
@@ -2029,7 +1953,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2029
1953
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2030
1954
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2031
1955
  }
2032
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
1956
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
2033
1957
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
2034
1958
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
2035
1959
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -2085,66 +2009,71 @@ var DataSpaceManager = class extends Resource4 {
2085
2009
  get spaces() {
2086
2010
  return this._spaces;
2087
2011
  }
2012
+ getSpaceById(spaceId) {
2013
+ return [
2014
+ ...this._spaces.values()
2015
+ ].find((space) => space.id === spaceId);
2016
+ }
2088
2017
  async _open() {
2089
- log7("open", void 0, {
2090
- F: __dxlog_file10,
2091
- L: 192,
2018
+ log6("open", void 0, {
2019
+ F: __dxlog_file9,
2020
+ L: 213,
2092
2021
  S: this,
2093
2022
  C: (f, a) => f(...a)
2094
2023
  });
2095
- log7.trace("dxos.echo.data-space-manager.open", Trace.begin({
2024
+ log6.trace("dxos.echo.data-space-manager.open", Trace.begin({
2096
2025
  id: this._instanceId
2097
2026
  }), {
2098
- F: __dxlog_file10,
2099
- L: 193,
2027
+ F: __dxlog_file9,
2028
+ L: 214,
2100
2029
  S: this,
2101
2030
  C: (f, a) => f(...a)
2102
2031
  });
2103
- log7("metadata loaded", {
2032
+ log6("metadata loaded", {
2104
2033
  spaces: this._metadataStore.spaces.length
2105
2034
  }, {
2106
- F: __dxlog_file10,
2107
- L: 194,
2035
+ F: __dxlog_file9,
2036
+ L: 215,
2108
2037
  S: this,
2109
2038
  C: (f, a) => f(...a)
2110
2039
  });
2111
2040
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
2112
2041
  try {
2113
- log7("load space", {
2042
+ log6("load space", {
2114
2043
  spaceMetadata
2115
2044
  }, {
2116
- F: __dxlog_file10,
2117
- L: 198,
2045
+ F: __dxlog_file9,
2046
+ L: 219,
2118
2047
  S: this,
2119
2048
  C: (f, a) => f(...a)
2120
2049
  });
2121
2050
  await this._constructSpace(spaceMetadata);
2122
2051
  } catch (err) {
2123
- log7.error("Error loading space", {
2052
+ log6.error("Error loading space", {
2124
2053
  spaceMetadata,
2125
2054
  err
2126
2055
  }, {
2127
- F: __dxlog_file10,
2128
- L: 201,
2056
+ F: __dxlog_file9,
2057
+ L: 222,
2129
2058
  S: this,
2130
2059
  C: (f, a) => f(...a)
2131
2060
  });
2132
2061
  }
2133
2062
  });
2134
2063
  this.updated.emit();
2135
- log7.trace("dxos.echo.data-space-manager.open", Trace.end({
2064
+ log6.trace("dxos.echo.data-space-manager.open", Trace.end({
2136
2065
  id: this._instanceId
2137
2066
  }), {
2138
- F: __dxlog_file10,
2139
- L: 207,
2067
+ F: __dxlog_file9,
2068
+ L: 228,
2140
2069
  S: this,
2141
2070
  C: (f, a) => f(...a)
2142
2071
  });
2143
2072
  }
2144
2073
  async _close() {
2145
- log7("close", void 0, {
2146
- F: __dxlog_file10,
2147
- L: 212,
2074
+ log6("close", void 0, {
2075
+ F: __dxlog_file9,
2076
+ L: 233,
2148
2077
  S: this,
2149
2078
  C: (f, a) => f(...a)
2150
2079
  });
@@ -2156,19 +2085,13 @@ var DataSpaceManager = class extends Resource4 {
2156
2085
  /**
2157
2086
  * Creates a new space writing the genesis credentials to the control feed.
2158
2087
  */
2159
- async createSpace() {
2160
- invariant5(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
2161
- F: __dxlog_file10,
2162
- L: 224,
2163
- S: this,
2164
- A: [
2165
- "this._lifecycleState === LifecycleState.OPEN",
2166
- "'Not open.'"
2167
- ]
2168
- });
2088
+ async createSpace(options = {}) {
2089
+ assertArgument(!!options.rootUrl === !!options.documents, "root url must be required when providing documents");
2090
+ assertState(this._lifecycleState === LifecycleState.OPEN, "Not open.");
2169
2091
  const spaceKey = await this._keyring.createKey();
2170
2092
  const controlFeedKey = await this._keyring.createKey();
2171
2093
  const dataFeedKey = await this._keyring.createKey();
2094
+ const spaceId = await createIdFromSpaceKey(spaceKey);
2172
2095
  const metadata = {
2173
2096
  key: spaceKey,
2174
2097
  genesisFeedKey: controlFeedKey,
@@ -2176,23 +2099,85 @@ var DataSpaceManager = class extends Resource4 {
2176
2099
  dataFeedKey,
2177
2100
  state: SpaceState.SPACE_ACTIVE
2178
2101
  };
2179
- log7("creating space...", {
2102
+ log6("creating space...", {
2103
+ spaceId,
2180
2104
  spaceKey
2181
2105
  }, {
2182
- F: __dxlog_file10,
2183
- L: 236,
2106
+ F: __dxlog_file9,
2107
+ L: 262,
2108
+ S: this,
2109
+ C: (f, a) => f(...a)
2110
+ });
2111
+ const documentIdMapping = {};
2112
+ if (options.documents) {
2113
+ invariant5(Object.keys(options.documents).every((documentId) => /^[a-zA-Z0-9]+$/.test(documentId)), "Invalid document IDs", {
2114
+ F: __dxlog_file9,
2115
+ L: 267,
2116
+ S: this,
2117
+ A: [
2118
+ "Object.keys(options.documents).every((documentId) => /^[a-zA-Z0-9]+$/.test(documentId))",
2119
+ "'Invalid document IDs'"
2120
+ ]
2121
+ });
2122
+ await Promise.all(Object.entries(options.documents).map(async ([documentId, data]) => {
2123
+ log6("creating document...", {
2124
+ documentId
2125
+ }, {
2126
+ F: __dxlog_file9,
2127
+ L: 274,
2128
+ S: this,
2129
+ C: (f, a) => f(...a)
2130
+ });
2131
+ const newDoc = await this._echoHost.createDoc(data, {
2132
+ preserveHistory: true
2133
+ });
2134
+ documentIdMapping[documentId] = newDoc.documentId;
2135
+ }));
2136
+ }
2137
+ log6("opening space...", {
2138
+ spaceKey
2139
+ }, {
2140
+ F: __dxlog_file9,
2141
+ L: 281,
2142
+ S: this,
2143
+ C: (f, a) => f(...a)
2144
+ });
2145
+ let root;
2146
+ if (options.rootUrl) {
2147
+ const newRootDocId = documentIdMapping[interpretAsDocumentId(options.rootUrl)] ?? failedInvariant();
2148
+ const rootDocHandle = await this._echoHost.loadDoc(Context4.default(void 0, {
2149
+ F: __dxlog_file9,
2150
+ L: 286
2151
+ }), newRootDocId);
2152
+ DatabaseRoot.mapLinks(rootDocHandle, documentIdMapping);
2153
+ root = await this._echoHost.openSpaceRoot(spaceId, `automerge:${newRootDocId}`);
2154
+ } else {
2155
+ root = await this._echoHost.createSpaceRoot(spaceKey);
2156
+ }
2157
+ log6("constructing space...", {
2158
+ spaceKey
2159
+ }, {
2160
+ F: __dxlog_file9,
2161
+ L: 294,
2184
2162
  S: this,
2185
2163
  C: (f, a) => f(...a)
2186
2164
  });
2187
- const root = await this._echoHost.createSpaceRoot(spaceKey);
2188
2165
  const space = await this._constructSpace(metadata);
2189
2166
  await space.open();
2167
+ log6("adding space...", {
2168
+ spaceKey
2169
+ }, {
2170
+ F: __dxlog_file9,
2171
+ L: 299,
2172
+ S: this,
2173
+ C: (f, a) => f(...a)
2174
+ });
2190
2175
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
2191
2176
  await this._metadataStore.addSpace(metadata);
2192
2177
  const memberCredential = credentials[1];
2193
2178
  invariant5(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2194
- F: __dxlog_file10,
2195
- L: 246,
2179
+ F: __dxlog_file9,
2180
+ L: 305,
2196
2181
  S: this,
2197
2182
  A: [
2198
2183
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2201,6 +2186,15 @@ var DataSpaceManager = class extends Resource4 {
2201
2186
  });
2202
2187
  await this._signingContext.recordCredential(memberCredential);
2203
2188
  await space.initializeDataPipeline();
2189
+ log6("space ready.", {
2190
+ spaceId,
2191
+ spaceKey
2192
+ }, {
2193
+ F: __dxlog_file9,
2194
+ L: 310,
2195
+ S: this,
2196
+ C: (f, a) => f(...a)
2197
+ });
2204
2198
  this.updated.emit();
2205
2199
  return space;
2206
2200
  }
@@ -2217,12 +2211,12 @@ var DataSpaceManager = class extends Resource4 {
2217
2211
  throw new Error("Legacy space version is not supported");
2218
2212
  }
2219
2213
  default:
2220
- log7.warn("unknown space version", {
2214
+ log6.warn("unknown space version", {
2221
2215
  version: space.databaseRoot.getVersion(),
2222
2216
  spaceId: space.id
2223
2217
  }, {
2224
- F: __dxlog_file10,
2225
- L: 269,
2218
+ F: __dxlog_file9,
2219
+ L: 330,
2226
2220
  S: this,
2227
2221
  C: (f, a) => f(...a)
2228
2222
  });
@@ -2256,8 +2250,8 @@ var DataSpaceManager = class extends Resource4 {
2256
2250
  async _getSpaceRootDocument(space) {
2257
2251
  const automergeIndex = space.automergeSpaceState.rootUrl;
2258
2252
  invariant5(automergeIndex, void 0, {
2259
- F: __dxlog_file10,
2260
- L: 302,
2253
+ F: __dxlog_file9,
2254
+ L: 363,
2261
2255
  S: this,
2262
2256
  A: [
2263
2257
  "automergeIndex",
@@ -2270,17 +2264,17 @@ var DataSpaceManager = class extends Resource4 {
2270
2264
  }
2271
2265
  // TODO(burdon): Rename join space.
2272
2266
  async acceptSpace(opts) {
2273
- log7("accept space", {
2267
+ log6("accept space", {
2274
2268
  opts
2275
2269
  }, {
2276
- F: __dxlog_file10,
2277
- L: 311,
2270
+ F: __dxlog_file9,
2271
+ L: 372,
2278
2272
  S: this,
2279
2273
  C: (f, a) => f(...a)
2280
2274
  });
2281
2275
  invariant5(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
2282
- F: __dxlog_file10,
2283
- L: 312,
2276
+ F: __dxlog_file9,
2277
+ L: 373,
2284
2278
  S: this,
2285
2279
  A: [
2286
2280
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2288,8 +2282,8 @@ var DataSpaceManager = class extends Resource4 {
2288
2282
  ]
2289
2283
  });
2290
2284
  invariant5(!this._spaces.has(opts.spaceKey), "Space already exists.", {
2291
- F: __dxlog_file10,
2292
- L: 313,
2285
+ F: __dxlog_file9,
2286
+ L: 374,
2293
2287
  S: this,
2294
2288
  A: [
2295
2289
  "!this._spaces.has(opts.spaceKey)",
@@ -2312,8 +2306,8 @@ var DataSpaceManager = class extends Resource4 {
2312
2306
  async admitMember(options) {
2313
2307
  const space = this._spaceManager.spaces.get(options.spaceKey);
2314
2308
  invariant5(space, void 0, {
2315
- F: __dxlog_file10,
2316
- L: 333,
2309
+ F: __dxlog_file9,
2310
+ L: 394,
2317
2311
  S: this,
2318
2312
  A: [
2319
2313
  "space",
@@ -2325,8 +2319,8 @@ var DataSpaceManager = class extends Resource4 {
2325
2319
  }
2326
2320
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
2327
2321
  invariant5(credentials[0].credential, void 0, {
2328
- F: __dxlog_file10,
2329
- L: 352,
2322
+ F: __dxlog_file9,
2323
+ L: 413,
2330
2324
  S: this,
2331
2325
  A: [
2332
2326
  "credentials[0].credential",
@@ -2335,8 +2329,8 @@ var DataSpaceManager = class extends Resource4 {
2335
2329
  });
2336
2330
  const spaceMemberCredential = credentials[0].credential.credential;
2337
2331
  invariant5(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2338
- F: __dxlog_file10,
2339
- L: 354,
2332
+ F: __dxlog_file9,
2333
+ L: 415,
2340
2334
  S: this,
2341
2335
  A: [
2342
2336
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2373,8 +2367,8 @@ var DataSpaceManager = class extends Resource4 {
2373
2367
  async setSpaceEdgeReplicationSetting(spaceKey, setting) {
2374
2368
  const space = this._spaces.get(spaceKey);
2375
2369
  invariant5(space, "Space not found.", {
2376
- F: __dxlog_file10,
2377
- L: 391,
2370
+ F: __dxlog_file9,
2371
+ L: 452,
2378
2372
  S: this,
2379
2373
  A: [
2380
2374
  "space",
@@ -2395,11 +2389,11 @@ var DataSpaceManager = class extends Resource4 {
2395
2389
  space.stateUpdate.emit();
2396
2390
  }
2397
2391
  async _constructSpace(metadata) {
2398
- log7("construct space", {
2392
+ log6("construct space", {
2399
2393
  metadata
2400
2394
  }, {
2401
- F: __dxlog_file10,
2402
- L: 410,
2395
+ F: __dxlog_file9,
2396
+ L: 471,
2403
2397
  S: this,
2404
2398
  C: (f, a) => f(...a)
2405
2399
  });
@@ -2439,11 +2433,11 @@ var DataSpaceManager = class extends Resource4 {
2439
2433
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2440
2434
  await this._connectEchoMeshReplicator(space, session);
2441
2435
  } catch (err) {
2442
- log7.warn("error on authorized connection", {
2436
+ log6.warn("error on authorized connection", {
2443
2437
  err
2444
2438
  }, {
2445
- F: __dxlog_file10,
2446
- L: 452,
2439
+ F: __dxlog_file9,
2440
+ L: 513,
2447
2441
  S: this,
2448
2442
  C: (f, a) => f(...a)
2449
2443
  });
@@ -2451,9 +2445,9 @@ var DataSpaceManager = class extends Resource4 {
2451
2445
  }
2452
2446
  }),
2453
2447
  onAuthFailure: () => {
2454
- log7.warn("auth failure", void 0, {
2455
- F: __dxlog_file10,
2456
- L: 457,
2448
+ log6.warn("auth failure", void 0, {
2449
+ F: __dxlog_file9,
2450
+ L: 518,
2457
2451
  S: this,
2458
2452
  C: (f, a) => f(...a)
2459
2453
  });
@@ -2482,22 +2476,22 @@ var DataSpaceManager = class extends Resource4 {
2482
2476
  signingContext: this._signingContext,
2483
2477
  callbacks: {
2484
2478
  beforeReady: async () => {
2485
- log7("before space ready", {
2479
+ log6("before space ready", {
2486
2480
  space: space.key
2487
2481
  }, {
2488
- F: __dxlog_file10,
2489
- L: 484,
2482
+ F: __dxlog_file9,
2483
+ L: 545,
2490
2484
  S: this,
2491
2485
  C: (f, a) => f(...a)
2492
2486
  });
2493
2487
  },
2494
2488
  afterReady: async () => {
2495
- log7("after space ready", {
2489
+ log6("after space ready", {
2496
2490
  space: space.key,
2497
2491
  open: this._lifecycleState === LifecycleState.OPEN
2498
2492
  }, {
2499
- F: __dxlog_file10,
2500
- L: 487,
2493
+ F: __dxlog_file9,
2494
+ L: 548,
2501
2495
  S: this,
2502
2496
  C: (f, a) => f(...a)
2503
2497
  });
@@ -2512,11 +2506,11 @@ var DataSpaceManager = class extends Resource4 {
2512
2506
  }
2513
2507
  },
2514
2508
  beforeClose: async () => {
2515
- log7("before space close", {
2509
+ log6("before space close", {
2516
2510
  space: space.key
2517
2511
  }, {
2518
- F: __dxlog_file10,
2519
- L: 495,
2512
+ F: __dxlog_file9,
2513
+ L: 556,
2520
2514
  S: this,
2521
2515
  C: (f, a) => f(...a)
2522
2516
  });
@@ -2533,11 +2527,11 @@ var DataSpaceManager = class extends Resource4 {
2533
2527
  if (!setting || setting === EdgeReplicationSetting.ENABLED) {
2534
2528
  await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2535
2529
  } else if (this._echoEdgeReplicator) {
2536
- log7("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
2530
+ log6("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
2537
2531
  spaceId: dataSpace.id
2538
2532
  }, {
2539
- F: __dxlog_file10,
2540
- L: 509,
2533
+ F: __dxlog_file9,
2534
+ L: 570,
2541
2535
  S: this,
2542
2536
  C: (f, a) => f(...a)
2543
2537
  });
@@ -2563,11 +2557,11 @@ var DataSpaceManager = class extends Resource4 {
2563
2557
  async _connectEchoMeshReplicator(space, session) {
2564
2558
  const replicator = this._meshReplicator;
2565
2559
  if (!replicator) {
2566
- log7.warn("p2p automerge replication disabled", {
2560
+ log6.warn("p2p automerge replication disabled", {
2567
2561
  space: space.key
2568
2562
  }, {
2569
- F: __dxlog_file10,
2570
- L: 536,
2563
+ F: __dxlog_file9,
2564
+ L: 597,
2571
2565
  S: this,
2572
2566
  C: (f, a) => f(...a)
2573
2567
  });
@@ -2590,17 +2584,17 @@ var DataSpaceManager = class extends Resource4 {
2590
2584
  return (s && member.role === SpaceMember3.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
2591
2585
  });
2592
2586
  sessionsToClose.forEach((session) => {
2593
- void session.close().catch(log7.error);
2587
+ void session.close().catch(log6.error);
2594
2588
  });
2595
2589
  closedSessions += sessionsToClose.length;
2596
2590
  }
2597
- log7("processed member role changes", {
2591
+ log6("processed member role changes", {
2598
2592
  roleChangeCount: memberInfo.length,
2599
2593
  peersOnline: presence.getPeersOnline().length,
2600
2594
  closedSessions
2601
2595
  }, {
2602
- F: __dxlog_file10,
2603
- L: 562,
2596
+ F: __dxlog_file9,
2597
+ L: 623,
2604
2598
  S: this,
2605
2599
  C: (f, a) => f(...a)
2606
2600
  });
@@ -2611,15 +2605,15 @@ var DataSpaceManager = class extends Resource4 {
2611
2605
  if (role === SpaceMember3.Role.REMOVED) {
2612
2606
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
2613
2607
  if (session != null) {
2614
- log7("closing a session with a removed peer", {
2608
+ log6("closing a session with a removed peer", {
2615
2609
  peerId: peerState.peerId
2616
2610
  }, {
2617
- F: __dxlog_file10,
2618
- L: 576,
2611
+ F: __dxlog_file9,
2612
+ L: 637,
2619
2613
  S: this,
2620
2614
  C: (f, a) => f(...a)
2621
2615
  });
2622
- void session.close().catch(log7.error);
2616
+ void session.close().catch(log6.error);
2623
2617
  }
2624
2618
  }
2625
2619
  }
@@ -2676,16 +2670,177 @@ DataSpaceManager = _ts_decorate3([
2676
2670
  ], DataSpaceManager);
2677
2671
 
2678
2672
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2679
- import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask3 } from "@dxos/async";
2673
+ import { SubscriptionList as SubscriptionList2, UpdateScheduler, scheduleTask as scheduleTask3 } from "@dxos/async";
2680
2674
  import { Stream as Stream7 } from "@dxos/codec-protobuf/stream";
2681
2675
  import { createAdmissionCredentials as createAdmissionCredentials2, createDidFromIdentityKey as createDidFromIdentityKey2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2682
2676
  import { raise } from "@dxos/debug";
2683
2677
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2684
- import { invariant as invariant6 } from "@dxos/invariant";
2678
+ import { assertArgument as assertArgument4, assertState as assertState3, invariant as invariant7 } from "@dxos/invariant";
2679
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
2685
2680
  import { log as log8 } from "@dxos/log";
2686
- import { ApiError, SpaceNotFoundError, encodeError, IdentityNotInitializedError, AuthorizationError } from "@dxos/protocols";
2681
+ import { encodeError, ApiError, AuthorizationError, IdentityNotInitializedError, SpaceNotFoundError } from "@dxos/protocols";
2687
2682
  import { SpaceMember as SpaceMember4, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
2688
2683
  import { trace as trace2 } from "@dxos/tracing";
2684
+
2685
+ // packages/sdk/client-services/src/packlets/space-export/space-archive-writer.ts
2686
+ import { Resource as Resource5 } from "@dxos/context";
2687
+ import { assertArgument as assertArgument2, assertState as assertState2 } from "@dxos/invariant";
2688
+ import { SpaceArchiveFileStructure, SpaceArchiveVersion } from "@dxos/protocols";
2689
+ var CURRENT_VERSION = SpaceArchiveVersion.V1;
2690
+ var SpaceArchiveWriter = class extends Resource5 {
2691
+ constructor() {
2692
+ super(...arguments);
2693
+ this._meta = void 0;
2694
+ this._currentRootUrl = void 0;
2695
+ }
2696
+ async _open(ctx) {
2697
+ this._tar = await import("@obsidize/tar-browserify");
2698
+ }
2699
+ async _close() {
2700
+ return Promise.resolve();
2701
+ }
2702
+ async begin(meta) {
2703
+ assertState2(this._tar, "Not open");
2704
+ assertState2(!this._meta, "Already started");
2705
+ this._meta = meta;
2706
+ this._archive = new this._tar.Archive();
2707
+ }
2708
+ async setCurrentRootUrl(url) {
2709
+ assertArgument2(url.startsWith("automerge:"), "Invalid root URL");
2710
+ assertState2(this._tar, "Not open");
2711
+ assertState2(this._meta, "Not started");
2712
+ this._currentRootUrl = url;
2713
+ }
2714
+ async writeDocument(documentId, data) {
2715
+ assertArgument2(!documentId.startsWith("automerge:"), "Invalid document ID");
2716
+ assertState2(this._archive, "Not open");
2717
+ this._archive.addBinaryFile(`${SpaceArchiveFileStructure.documents}/${documentId}.bin`, data);
2718
+ }
2719
+ async finish() {
2720
+ assertState2(this._archive, "Not open");
2721
+ assertState2(this._meta, "Not started");
2722
+ assertState2(this._currentRootUrl, "No root URL set");
2723
+ const metadata = {
2724
+ version: CURRENT_VERSION,
2725
+ createdAt: Date.now(),
2726
+ exportedBy: this._meta.exportedBy,
2727
+ originalSpaceId: this._meta.spaceId,
2728
+ echo: {
2729
+ currentRootUrl: this._currentRootUrl
2730
+ }
2731
+ };
2732
+ this._archive.addTextFile(SpaceArchiveFileStructure.metadata, JSON.stringify(metadata));
2733
+ const binary = this._archive.toUint8Array();
2734
+ return {
2735
+ filename: `${this._meta.spaceId}.tar`,
2736
+ contents: binary
2737
+ };
2738
+ }
2739
+ };
2740
+
2741
+ // packages/sdk/client-services/src/packlets/space-export/space-archive-reader.ts
2742
+ import { assertArgument as assertArgument3, failedInvariant as failedInvariant2, invariant as invariant6 } from "@dxos/invariant";
2743
+ import { log as log7 } from "@dxos/log";
2744
+ import { SpaceArchiveFileStructure as SpaceArchiveFileStructure2 } from "@dxos/protocols";
2745
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/space-export/space-archive-reader.ts";
2746
+ var extractSpaceArchive = async (archive) => {
2747
+ const { Archive } = await import("@obsidize/tar-browserify");
2748
+ const { entries } = await Archive.extract(archive.contents);
2749
+ const metadataEntry = entries.find((entry2) => entry2.fileName === SpaceArchiveFileStructure2.metadata);
2750
+ assertArgument3(metadataEntry, "Metadata entry not found");
2751
+ const metadata = JSON.parse(metadataEntry.getContentAsText());
2752
+ const documents = {};
2753
+ for (const entry2 of entries.filter((entry3) => entry3.fileName.startsWith(`${SpaceArchiveFileStructure2.documents}/`))) {
2754
+ const documentId = entry2.fileName.replace(`${SpaceArchiveFileStructure2.documents}/`, "").replace(/\.bin$/, "");
2755
+ invariant6(!documentId.includes("/"), void 0, {
2756
+ F: __dxlog_file10,
2757
+ L: 27,
2758
+ S: void 0,
2759
+ A: [
2760
+ "!documentId.includes('/')",
2761
+ ""
2762
+ ]
2763
+ });
2764
+ documents[documentId] = entry2.content ?? failedInvariant2();
2765
+ }
2766
+ log7.info("extracted space archive", {
2767
+ metadata,
2768
+ documents
2769
+ }, {
2770
+ F: __dxlog_file10,
2771
+ L: 31,
2772
+ S: void 0,
2773
+ C: (f, a) => f(...a)
2774
+ });
2775
+ return {
2776
+ metadata,
2777
+ documents
2778
+ };
2779
+ };
2780
+
2781
+ // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2782
+ function _using_ctx2() {
2783
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
2784
+ var err = new Error();
2785
+ err.name = "SuppressedError";
2786
+ err.suppressed = suppressed;
2787
+ err.error = error;
2788
+ return err;
2789
+ }, empty = {}, stack = [];
2790
+ function using(isAwait, value) {
2791
+ if (value != null) {
2792
+ if (Object(value) !== value) {
2793
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
2794
+ }
2795
+ if (isAwait) {
2796
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
2797
+ }
2798
+ if (dispose == null) {
2799
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
2800
+ }
2801
+ if (typeof dispose !== "function") {
2802
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
2803
+ }
2804
+ stack.push({
2805
+ v: value,
2806
+ d: dispose,
2807
+ a: isAwait
2808
+ });
2809
+ } else if (isAwait) {
2810
+ stack.push({
2811
+ d: value,
2812
+ a: isAwait
2813
+ });
2814
+ }
2815
+ return value;
2816
+ }
2817
+ return {
2818
+ e: empty,
2819
+ u: using.bind(null, false),
2820
+ a: using.bind(null, true),
2821
+ d: function() {
2822
+ var error = this.e;
2823
+ function next() {
2824
+ while (resource = stack.pop()) {
2825
+ try {
2826
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
2827
+ if (resource.a) {
2828
+ return Promise.resolve(disposalResult).then(next, err);
2829
+ }
2830
+ } catch (e) {
2831
+ return err(e);
2832
+ }
2833
+ }
2834
+ if (error !== empty) throw error;
2835
+ }
2836
+ function err(e) {
2837
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
2838
+ return next();
2839
+ }
2840
+ return next();
2841
+ }
2842
+ };
2843
+ }
2689
2844
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
2690
2845
  var SpacesServiceImpl = class {
2691
2846
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
@@ -2732,9 +2887,9 @@ var SpacesServiceImpl = class {
2732
2887
  });
2733
2888
  }
2734
2889
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2735
- invariant6(credentials[0].credential, void 0, {
2890
+ invariant7(credentials[0].credential, void 0, {
2736
2891
  F: __dxlog_file11,
2737
- L: 111,
2892
+ L: 118,
2738
2893
  S: this,
2739
2894
  A: [
2740
2895
  "credentials[0].credential",
@@ -2742,9 +2897,9 @@ var SpacesServiceImpl = class {
2742
2897
  ]
2743
2898
  });
2744
2899
  const spaceMemberCredential = credentials[0].credential.credential;
2745
- invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2900
+ invariant7(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2746
2901
  F: __dxlog_file11,
2747
- L: 113,
2902
+ L: 120,
2748
2903
  S: this,
2749
2904
  A: [
2750
2905
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2762,7 +2917,7 @@ var SpacesServiceImpl = class {
2762
2917
  ids: spaces.map((space) => space.id)
2763
2918
  }), {
2764
2919
  F: __dxlog_file11,
2765
- L: 126,
2920
+ L: 133,
2766
2921
  S: this,
2767
2922
  C: (f, a) => f(...a)
2768
2923
  });
@@ -2771,11 +2926,11 @@ var SpacesServiceImpl = class {
2771
2926
  spaces
2772
2927
  });
2773
2928
  }, {
2774
- maxFrequency: false ? void 0 : 2
2929
+ maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
2775
2930
  });
2776
2931
  scheduleTask3(ctx, async () => {
2777
2932
  const dataSpaceManager = await this._getDataSpaceManager();
2778
- const subscriptions = new EventSubscriptions2();
2933
+ const subscriptions = new SubscriptionList2();
2779
2934
  ctx.onDispose(() => subscriptions.clear());
2780
2935
  const subscribeSpaces = () => {
2781
2936
  subscriptions.clear();
@@ -2852,18 +3007,18 @@ var SpacesServiceImpl = class {
2852
3007
  }
2853
3008
  });
2854
3009
  } else {
2855
- invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
3010
+ invariant7(!credential.id, "Id on unsigned credentials is not allowed", {
2856
3011
  F: __dxlog_file11,
2857
- L: 224,
3012
+ L: 231,
2858
3013
  S: this,
2859
3014
  A: [
2860
3015
  "!credential.id",
2861
3016
  "'Id on unsigned credentials is not allowed'"
2862
3017
  ]
2863
3018
  });
2864
- invariant6(this._identityManager.identity, "Identity is not available", {
3019
+ invariant7(this._identityManager.identity, "Identity is not available", {
2865
3020
  F: __dxlog_file11,
2866
- L: 225,
3021
+ L: 232,
2867
3022
  S: this,
2868
3023
  A: [
2869
3024
  "this._identityManager.identity",
@@ -2871,9 +3026,9 @@ var SpacesServiceImpl = class {
2871
3026
  ]
2872
3027
  });
2873
3028
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2874
- invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
3029
+ invariant7(credential.issuer.equals(signer.getIssuer()), void 0, {
2875
3030
  F: __dxlog_file11,
2876
- L: 227,
3031
+ L: 234,
2877
3032
  S: this,
2878
3033
  A: [
2879
3034
  "credential.issuer.equals(signer.getIssuer())",
@@ -2919,11 +3074,58 @@ var SpacesServiceImpl = class {
2919
3074
  credential
2920
3075
  });
2921
3076
  }
3077
+ async exportSpace(request) {
3078
+ try {
3079
+ var _usingCtx = _using_ctx2();
3080
+ const writer = _usingCtx.a(await new SpaceArchiveWriter().open());
3081
+ assertArgument4(SpaceId2.isValid(request.spaceId), "Invalid space ID");
3082
+ const dataSpaceManager = await this._getDataSpaceManager();
3083
+ const space = dataSpaceManager.getSpaceById(request.spaceId) ?? raise(new Error("Space not found"));
3084
+ await writer.begin({
3085
+ spaceId: space.id
3086
+ });
3087
+ const rootUrl = space.automergeSpaceState.lastEpoch?.subject.assertion.automergeRoot;
3088
+ assertState3(rootUrl, "Space does not have a root URL");
3089
+ await writer.setCurrentRootUrl(rootUrl);
3090
+ for await (const [documentId, data] of space.getAllDocuments()) {
3091
+ await writer.writeDocument(documentId, data);
3092
+ }
3093
+ const archive = await writer.finish();
3094
+ return {
3095
+ archive
3096
+ };
3097
+ } catch (_) {
3098
+ _usingCtx.e = _;
3099
+ } finally {
3100
+ await _usingCtx.d();
3101
+ }
3102
+ }
3103
+ async importSpace(request) {
3104
+ const dataSpaceManager = await this._getDataSpaceManager();
3105
+ const extracted = await extractSpaceArchive(request.archive);
3106
+ invariant7(extracted.metadata.echo?.currentRootUrl, "Space archive does not contain a root URL", {
3107
+ F: __dxlog_file11,
3108
+ L: 288,
3109
+ S: this,
3110
+ A: [
3111
+ "extracted.metadata.echo?.currentRootUrl",
3112
+ "'Space archive does not contain a root URL'"
3113
+ ]
3114
+ });
3115
+ const space = await dataSpaceManager.createSpace({
3116
+ documents: extracted.documents,
3117
+ rootUrl: extracted.metadata.echo?.currentRootUrl
3118
+ });
3119
+ await this._updateMetrics();
3120
+ return {
3121
+ newSpaceId: space.id
3122
+ };
3123
+ }
2922
3124
  async _joinByAdmission({ credential }) {
2923
3125
  const assertion = getCredentialAssertion3(credential);
2924
- invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3126
+ invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2925
3127
  F: __dxlog_file11,
2926
- L: 261,
3128
+ L: 299,
2927
3129
  S: this,
2928
3130
  A: [
2929
3131
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2931,9 +3133,9 @@ var SpacesServiceImpl = class {
2931
3133
  ]
2932
3134
  });
2933
3135
  const myIdentity = this._identityManager.identity;
2934
- invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
3136
+ invariant7(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2935
3137
  F: __dxlog_file11,
2936
- L: 263,
3138
+ L: 301,
2937
3139
  S: this,
2938
3140
  A: [
2939
3141
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -3145,7 +3347,7 @@ var Identity = class {
3145
3347
  * Requires identity to be ready.
3146
3348
  */
3147
3349
  getIdentityCredentialSigner() {
3148
- invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3350
+ invariant8(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3149
3351
  F: __dxlog_file12,
3150
3352
  L: 198,
3151
3353
  S: this,
@@ -3247,9 +3449,9 @@ Identity = _ts_decorate4([
3247
3449
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
3248
3450
  import platform from "platform";
3249
3451
  import { Event as Event6 } from "@dxos/async";
3250
- import { Context as Context4 } from "@dxos/context";
3452
+ import { Context as Context5 } from "@dxos/context";
3251
3453
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, createDidFromIdentityKey as createDidFromIdentityKey3, CredentialGenerator } from "@dxos/credentials";
3252
- import { invariant as invariant8 } from "@dxos/invariant";
3454
+ import { invariant as invariant9 } from "@dxos/invariant";
3253
3455
  import { PublicKey as PublicKey7 } from "@dxos/keys";
3254
3456
  import { log as log10 } from "@dxos/log";
3255
3457
  import { trace as trace4 } from "@dxos/protocols";
@@ -3328,13 +3530,13 @@ var IdentityManager = class {
3328
3530
  });
3329
3531
  }
3330
3532
  async close() {
3331
- await this._identity?.close(new Context4(void 0, {
3533
+ await this._identity?.close(new Context5(void 0, {
3332
3534
  F: __dxlog_file13,
3333
3535
  L: 135
3334
3536
  }));
3335
3537
  }
3336
3538
  async createIdentity({ displayName, deviceProfile } = {}) {
3337
- invariant8(!this._identity, "Identity already exists.", {
3539
+ invariant9(!this._identity, "Identity already exists.", {
3338
3540
  F: __dxlog_file13,
3339
3541
  L: 140,
3340
3542
  S: this,
@@ -3361,13 +3563,13 @@ var IdentityManager = class {
3361
3563
  }
3362
3564
  };
3363
3565
  const identity = await this._constructIdentity(identityRecord);
3364
- await identity.open(new Context4(void 0, {
3566
+ await identity.open(new Context5(void 0, {
3365
3567
  F: __dxlog_file13,
3366
3568
  L: 156
3367
3569
  }));
3368
3570
  {
3369
3571
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3370
- invariant8(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3572
+ invariant9(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3371
3573
  F: __dxlog_file13,
3372
3574
  L: 160,
3373
3575
  S: this,
@@ -3376,7 +3578,7 @@ var IdentityManager = class {
3376
3578
  "'Genesis feed key is required.'"
3377
3579
  ]
3378
3580
  });
3379
- invariant8(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3581
+ invariant9(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3380
3582
  F: __dxlog_file13,
3381
3583
  L: 161,
3382
3584
  S: this,
@@ -3469,7 +3671,7 @@ var IdentityManager = class {
3469
3671
  S: this,
3470
3672
  C: (f, a) => f(...a)
3471
3673
  });
3472
- invariant8(!this._identity, "Identity already exists.", {
3674
+ invariant9(!this._identity, "Identity already exists.", {
3473
3675
  F: __dxlog_file13,
3474
3676
  L: 245,
3475
3677
  S: this,
@@ -3490,7 +3692,7 @@ var IdentityManager = class {
3490
3692
  }
3491
3693
  };
3492
3694
  const identity = await this._constructIdentity(identityRecord);
3493
- await identity.open(new Context4(void 0, {
3695
+ await identity.open(new Context5(void 0, {
3494
3696
  F: __dxlog_file13,
3495
3697
  L: 259
3496
3698
  }));
@@ -3534,7 +3736,7 @@ var IdentityManager = class {
3534
3736
  * Update the profile document of an existing identity.
3535
3737
  */
3536
3738
  async updateProfile(profile) {
3537
- invariant8(this._identity, "Identity not initialized.", {
3739
+ invariant9(this._identity, "Identity not initialized.", {
3538
3740
  F: __dxlog_file13,
3539
3741
  L: 291,
3540
3742
  S: this,
@@ -3565,7 +3767,7 @@ var IdentityManager = class {
3565
3767
  return profile;
3566
3768
  }
3567
3769
  async updateDeviceProfile(profile) {
3568
- invariant8(this._identity, "Identity not initialized.", {
3770
+ invariant9(this._identity, "Identity not initialized.", {
3569
3771
  F: __dxlog_file13,
3570
3772
  L: 308,
3571
3773
  S: this,
@@ -3601,7 +3803,7 @@ var IdentityManager = class {
3601
3803
  };
3602
3804
  }
3603
3805
  async _constructIdentity(identityRecord) {
3604
- invariant8(!this._identity, void 0, {
3806
+ invariant9(!this._identity, void 0, {
3605
3807
  F: __dxlog_file13,
3606
3808
  L: 334,
3607
3809
  S: this,
@@ -3627,7 +3829,7 @@ var IdentityManager = class {
3627
3829
  identityKey: identityRecord.deviceKey,
3628
3830
  gossip
3629
3831
  });
3630
- invariant8(identityRecord.haloSpace.controlFeedKey, void 0, {
3832
+ invariant9(identityRecord.haloSpace.controlFeedKey, void 0, {
3631
3833
  F: __dxlog_file13,
3632
3834
  L: 348,
3633
3835
  S: this,
@@ -3639,7 +3841,7 @@ var IdentityManager = class {
3639
3841
  const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
3640
3842
  writable: true
3641
3843
  });
3642
- invariant8(identityRecord.haloSpace.dataFeedKey, void 0, {
3844
+ invariant9(identityRecord.haloSpace.dataFeedKey, void 0, {
3643
3845
  F: __dxlog_file13,
3644
3846
  L: 352,
3645
3847
  S: this,
@@ -3728,17 +3930,17 @@ IdentityManager = _ts_decorate5([
3728
3930
  ], IdentityManager);
3729
3931
 
3730
3932
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
3731
- import { Trigger as Trigger4, sleep as sleep2 } from "@dxos/async";
3933
+ import { Trigger as Trigger3, sleep as sleep2 } from "@dxos/async";
3732
3934
  import { Stream as Stream8 } from "@dxos/codec-protobuf/stream";
3733
- import { Resource as Resource5 } from "@dxos/context";
3935
+ import { Resource as Resource6 } from "@dxos/context";
3734
3936
  import { createCredential as createCredential2, signPresentation } from "@dxos/credentials";
3735
- import { invariant as invariant9 } from "@dxos/invariant";
3937
+ import { invariant as invariant10 } from "@dxos/invariant";
3736
3938
  import { log as log11 } from "@dxos/log";
3737
3939
  import { SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
3738
3940
  import { safeAwaitAll } from "@dxos/util";
3739
3941
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
3740
3942
  var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
3741
- var IdentityServiceImpl = class extends Resource5 {
3943
+ var IdentityServiceImpl = class extends Resource6 {
3742
3944
  constructor(_identityManager, _recoveryManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
3743
3945
  super();
3744
3946
  this._identityManager = _identityManager;
@@ -3766,7 +3968,7 @@ var IdentityServiceImpl = class extends Resource5 {
3766
3968
  async _createDefaultSpace(dataSpaceManager) {
3767
3969
  const space = await dataSpaceManager.createDefaultSpace();
3768
3970
  const identity = this._identityManager.identity;
3769
- invariant9(identity, void 0, {
3971
+ invariant10(identity, void 0, {
3770
3972
  F: __dxlog_file14,
3771
3973
  L: 61,
3772
3974
  S: this,
@@ -3798,7 +4000,7 @@ var IdentityServiceImpl = class extends Resource5 {
3798
4000
  };
3799
4001
  }
3800
4002
  async updateProfile(profile) {
3801
- invariant9(this._identityManager.identity, "Identity not initialized.", {
4003
+ invariant10(this._identityManager.identity, "Identity not initialized.", {
3802
4004
  F: __dxlog_file14,
3803
4005
  L: 88,
3804
4006
  S: this,
@@ -3824,6 +4026,10 @@ var IdentityServiceImpl = class extends Resource5 {
3824
4026
  });
3825
4027
  } else if (request.external) {
3826
4028
  await this._recoveryManager.recoverIdentityWithExternalSignature(request.external);
4029
+ } else if (request.token) {
4030
+ await this._recoveryManager.recoverIdentityWithToken({
4031
+ token: request.token
4032
+ });
3827
4033
  } else {
3828
4034
  throw new Error("Invalid request.");
3829
4035
  }
@@ -3831,9 +4037,9 @@ var IdentityServiceImpl = class extends Resource5 {
3831
4037
  }
3832
4038
  // TODO(burdon): Rename createPresentation?
3833
4039
  async signPresentation({ presentation, nonce }) {
3834
- invariant9(this._identityManager.identity, "Identity not initialized.", {
4040
+ invariant10(this._identityManager.identity, "Identity not initialized.", {
3835
4041
  F: __dxlog_file14,
3836
- L: 116,
4042
+ L: 118,
3837
4043
  S: this,
3838
4044
  A: [
3839
4045
  "this._identityManager.identity",
@@ -3850,9 +4056,9 @@ var IdentityServiceImpl = class extends Resource5 {
3850
4056
  }
3851
4057
  async createAuthCredential() {
3852
4058
  const identity = this._identityManager.identity;
3853
- invariant9(identity, "Identity not initialized.", {
4059
+ invariant10(identity, "Identity not initialized.", {
3854
4060
  F: __dxlog_file14,
3855
- L: 130,
4061
+ L: 132,
3856
4062
  S: this,
3857
4063
  A: [
3858
4064
  "identity",
@@ -3874,7 +4080,7 @@ var IdentityServiceImpl = class extends Resource5 {
3874
4080
  let recodedDefaultSpace = false;
3875
4081
  let foundDefaultSpace = false;
3876
4082
  const dataSpaceManager = this._dataSpaceManagerProvider();
3877
- const recordedDefaultSpaceTrigger = new Trigger4();
4083
+ const recordedDefaultSpaceTrigger = new Trigger3();
3878
4084
  const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
3879
4085
  if (space.state === SpaceState3.SPACE_CLOSED) {
3880
4086
  await space.open();
@@ -3890,7 +4096,7 @@ var IdentityServiceImpl = class extends Resource5 {
3890
4096
  duplicate: space.id
3891
4097
  }, {
3892
4098
  F: __dxlog_file14,
3893
- L: 164,
4099
+ L: 166,
3894
4100
  S: this,
3895
4101
  C: (f, a) => f(...a)
3896
4102
  });
@@ -3904,7 +4110,7 @@ var IdentityServiceImpl = class extends Resource5 {
3904
4110
  }, (err) => {
3905
4111
  log11.catch(err, void 0, {
3906
4112
  F: __dxlog_file14,
3907
- L: 175,
4113
+ L: 177,
3908
4114
  S: this,
3909
4115
  C: (f, a) => f(...a)
3910
4116
  });
@@ -3927,7 +4133,7 @@ function _ts_decorate6(decorators, target, key, desc) {
3927
4133
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3928
4134
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3929
4135
  }
3930
- function _using_ctx2() {
4136
+ function _using_ctx3() {
3931
4137
  var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
3932
4138
  var err = new Error();
3933
4139
  err.name = "SuppressedError";
@@ -3992,9 +4198,9 @@ function _using_ctx2() {
3992
4198
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3993
4199
  var DataSpace = class {
3994
4200
  constructor(params) {
3995
- this._ctx = new Context5(void 0, {
4201
+ this._ctx = new Context6(void 0, {
3996
4202
  F: __dxlog_file15,
3997
- L: 96
4203
+ L: 97
3998
4204
  });
3999
4205
  this._cache = void 0;
4000
4206
  this._edgeFeedReplicator = void 0;
@@ -4047,7 +4253,7 @@ var DataSpace = class {
4047
4253
  state: SpaceState4[this._state]
4048
4254
  }, {
4049
4255
  F: __dxlog_file15,
4050
- L: 172,
4256
+ L: 173,
4051
4257
  S: this,
4052
4258
  C: (f, a) => f(...a)
4053
4259
  });
@@ -4104,9 +4310,9 @@ var DataSpace = class {
4104
4310
  if (this._edgeFeedReplicator) {
4105
4311
  this.inner.protocol.feedAdded.append(this._onFeedAdded);
4106
4312
  }
4107
- await this._inner.open(new Context5(void 0, {
4313
+ await this._inner.open(new Context6(void 0, {
4108
4314
  F: __dxlog_file15,
4109
- L: 246
4315
+ L: 247
4110
4316
  }));
4111
4317
  await this._inner.startProtocol();
4112
4318
  await this._edgeFeedReplicator?.open();
@@ -4115,7 +4321,7 @@ var DataSpace = class {
4115
4321
  state: SpaceState4[this._state]
4116
4322
  }, {
4117
4323
  F: __dxlog_file15,
4118
- L: 252,
4324
+ L: 253,
4119
4325
  S: this,
4120
4326
  C: (f, a) => f(...a)
4121
4327
  });
@@ -4135,14 +4341,14 @@ var DataSpace = class {
4135
4341
  state: SpaceState4[this._state]
4136
4342
  }, {
4137
4343
  F: __dxlog_file15,
4138
- L: 271,
4344
+ L: 272,
4139
4345
  S: this,
4140
4346
  C: (f, a) => f(...a)
4141
4347
  });
4142
4348
  await this._ctx.dispose();
4143
- this._ctx = new Context5(void 0, {
4349
+ this._ctx = new Context6(void 0, {
4144
4350
  F: __dxlog_file15,
4145
- L: 273
4351
+ L: 274
4146
4352
  });
4147
4353
  if (this._edgeFeedReplicator) {
4148
4354
  this.inner.protocol.feedAdded.remove(this._onFeedAdded);
@@ -4175,7 +4381,7 @@ var DataSpace = class {
4175
4381
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
4176
4382
  log12("data pipeline initialization cancelled", err, {
4177
4383
  F: __dxlog_file15,
4178
- L: 311,
4384
+ L: 312,
4179
4385
  S: this,
4180
4386
  C: (f, a) => f(...a)
4181
4387
  });
@@ -4183,7 +4389,7 @@ var DataSpace = class {
4183
4389
  }
4184
4390
  log12.error("Error initializing data pipeline", err, {
4185
4391
  F: __dxlog_file15,
4186
- L: 315,
4392
+ L: 316,
4187
4393
  S: this,
4188
4394
  C: (f, a) => f(...a)
4189
4395
  });
@@ -4192,7 +4398,7 @@ var DataSpace = class {
4192
4398
  state: SpaceState4[this._state]
4193
4399
  }, {
4194
4400
  F: __dxlog_file15,
4195
- L: 317,
4401
+ L: 318,
4196
4402
  S: this,
4197
4403
  C: (f, a) => f(...a)
4198
4404
  });
@@ -4212,13 +4418,13 @@ var DataSpace = class {
4212
4418
  state: SpaceState4[this._state]
4213
4419
  }, {
4214
4420
  F: __dxlog_file15,
4215
- L: 333,
4421
+ L: 334,
4216
4422
  S: this,
4217
4423
  C: (f, a) => f(...a)
4218
4424
  });
4219
4425
  log12("initializing control pipeline", void 0, {
4220
4426
  F: __dxlog_file15,
4221
- L: 335,
4427
+ L: 336,
4222
4428
  S: this,
4223
4429
  C: (f, a) => f(...a)
4224
4430
  });
@@ -4227,25 +4433,52 @@ var DataSpace = class {
4227
4433
  const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState4.SPACE_READY);
4228
4434
  log12("initializing automerge root", void 0, {
4229
4435
  F: __dxlog_file15,
4230
- L: 343,
4436
+ L: 344,
4231
4437
  S: this,
4232
4438
  C: (f, a) => f(...a)
4233
4439
  });
4234
4440
  this._automergeSpaceState.startProcessingRootDocs();
4235
4441
  log12("waiting for space to be ready", void 0, {
4236
4442
  F: __dxlog_file15,
4237
- L: 347,
4443
+ L: 348,
4238
4444
  S: this,
4239
4445
  C: (f, a) => f(...a)
4240
4446
  });
4241
4447
  await ready;
4242
4448
  log12("space is ready", void 0, {
4243
4449
  F: __dxlog_file15,
4244
- L: 349,
4450
+ L: 350,
4245
4451
  S: this,
4246
4452
  C: (f, a) => f(...a)
4247
4453
  });
4248
4454
  }
4455
+ async *getAllDocuments() {
4456
+ invariant11(this._databaseRoot, "Space is not ready", {
4457
+ F: __dxlog_file15,
4458
+ L: 354,
4459
+ S: this,
4460
+ A: [
4461
+ "this._databaseRoot",
4462
+ "'Space is not ready'"
4463
+ ]
4464
+ });
4465
+ const doc = this._databaseRoot.docSync() ?? failedInvariant3();
4466
+ const root = save(doc);
4467
+ yield [
4468
+ this._databaseRoot.documentId,
4469
+ root
4470
+ ];
4471
+ for (const documentUrl of this._databaseRoot.getAllLinkedDocuments()) {
4472
+ const data = await this._echoHost.exportDoc(Context6.default(void 0, {
4473
+ F: __dxlog_file15,
4474
+ L: 360
4475
+ }), documentUrl);
4476
+ yield [
4477
+ documentUrl.replace(/^automerge:/, ""),
4478
+ data
4479
+ ];
4480
+ }
4481
+ }
4249
4482
  async _enterReadyState() {
4250
4483
  await this._callbacks.beforeReady?.();
4251
4484
  this._state = SpaceState4.SPACE_READY;
@@ -4253,7 +4486,7 @@ var DataSpace = class {
4253
4486
  state: SpaceState4[this._state]
4254
4487
  }, {
4255
4488
  F: __dxlog_file15,
4256
- L: 356,
4489
+ L: 369,
4257
4490
  S: this,
4258
4491
  C: (f, a) => f(...a)
4259
4492
  });
@@ -4270,7 +4503,7 @@ var DataSpace = class {
4270
4503
  await this._createWritableFeeds();
4271
4504
  log12("writable feeds created", void 0, {
4272
4505
  F: __dxlog_file15,
4273
- L: 373,
4506
+ L: 386,
4274
4507
  S: this,
4275
4508
  C: (f, a) => f(...a)
4276
4509
  });
@@ -4324,7 +4557,7 @@ var DataSpace = class {
4324
4557
  count: credentials.length
4325
4558
  }, {
4326
4559
  F: __dxlog_file15,
4327
- L: 431,
4560
+ L: 444,
4328
4561
  S: this,
4329
4562
  C: (f, a) => f(...a)
4330
4563
  });
@@ -4335,14 +4568,14 @@ var DataSpace = class {
4335
4568
  });
4336
4569
  log12("credentials notarized", void 0, {
4337
4570
  F: __dxlog_file15,
4338
- L: 435,
4571
+ L: 448,
4339
4572
  S: this,
4340
4573
  C: (f, a) => f(...a)
4341
4574
  });
4342
4575
  } catch (err) {
4343
4576
  log12.error("error notarizing credentials for feed admission", err, {
4344
4577
  F: __dxlog_file15,
4345
- L: 437,
4578
+ L: 450,
4346
4579
  S: this,
4347
4580
  C: (f, a) => f(...a)
4348
4581
  });
@@ -4357,7 +4590,7 @@ var DataSpace = class {
4357
4590
  rootUrl
4358
4591
  }, {
4359
4592
  F: __dxlog_file15,
4360
- L: 447,
4593
+ L: 460,
4361
4594
  S: this,
4362
4595
  C: (f, a) => f(...a)
4363
4596
  });
@@ -4365,7 +4598,7 @@ var DataSpace = class {
4365
4598
  queueMicrotask(async () => {
4366
4599
  try {
4367
4600
  try {
4368
- var _usingCtx = _using_ctx2();
4601
+ var _usingCtx = _using_ctx3();
4369
4602
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4370
4603
  await cancelWithContext2(this._ctx, handle.whenReady());
4371
4604
  });
@@ -4376,7 +4609,7 @@ var DataSpace = class {
4376
4609
  // Ensure only one root is processed at a time.
4377
4610
  _usingCtx.u(await this._epochProcessingMutex.acquire())
4378
4611
  );
4379
- const doc = handle.docSync() ?? failedInvariant();
4612
+ const doc = handle.docSync() ?? failedInvariant3();
4380
4613
  if (!doc.access?.spaceKey) {
4381
4614
  handle.change((doc2) => {
4382
4615
  doc2.access = {
@@ -4409,7 +4642,7 @@ var DataSpace = class {
4409
4642
  err
4410
4643
  }, {
4411
4644
  F: __dxlog_file15,
4412
- L: 490,
4645
+ L: 503,
4413
4646
  S: this,
4414
4647
  C: (f, a) => f(...a)
4415
4648
  });
@@ -4499,7 +4732,7 @@ var DataSpace = class {
4499
4732
  state: SpaceState4[this._state]
4500
4733
  }, {
4501
4734
  F: __dxlog_file15,
4502
- L: 572,
4735
+ L: 585,
4503
4736
  S: this,
4504
4737
  C: (f, a) => f(...a)
4505
4738
  });
@@ -4560,7 +4793,7 @@ DataSpace = _ts_decorate6([
4560
4793
 
4561
4794
  // packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
4562
4795
  import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
4563
- import { invariant as invariant10 } from "@dxos/invariant";
4796
+ import { invariant as invariant12 } from "@dxos/invariant";
4564
4797
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
4565
4798
  import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
4566
4799
  var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
@@ -4590,7 +4823,7 @@ var DeviceInvitationProtocol = class {
4590
4823
  throw new Error("delegation not supported");
4591
4824
  }
4592
4825
  async admit(_, request) {
4593
- invariant10(request.device, void 0, {
4826
+ invariant12(request.device, void 0, {
4594
4827
  F: __dxlog_file16,
4595
4828
  L: 53,
4596
4829
  S: this,
@@ -4601,7 +4834,7 @@ var DeviceInvitationProtocol = class {
4601
4834
  });
4602
4835
  const identity = this._getIdentity();
4603
4836
  const credential = await identity.admitDevice(request.device);
4604
- invariant10(getCredentialAssertion4(credential)["@type"] === "dxos.halo.credentials.AuthorizedDevice", void 0, {
4837
+ invariant12(getCredentialAssertion4(credential)["@type"] === "dxos.halo.credentials.AuthorizedDevice", void 0, {
4605
4838
  F: __dxlog_file16,
4606
4839
  L: 56,
4607
4840
  S: this,
@@ -4646,7 +4879,7 @@ var DeviceInvitationProtocol = class {
4646
4879
  };
4647
4880
  }
4648
4881
  async accept(response, request) {
4649
- invariant10(response.device, void 0, {
4882
+ invariant12(response.device, void 0, {
4650
4883
  F: __dxlog_file16,
4651
4884
  L: 100,
4652
4885
  S: this,
@@ -4656,7 +4889,7 @@ var DeviceInvitationProtocol = class {
4656
4889
  ]
4657
4890
  });
4658
4891
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
4659
- invariant10(request.device, void 0, {
4892
+ invariant12(request.device, void 0, {
4660
4893
  F: __dxlog_file16,
4661
4894
  L: 103,
4662
4895
  S: this,
@@ -4688,7 +4921,7 @@ import { scheduleTask as scheduleTask7, TimeoutError as TimeoutError2 } from "@d
4688
4921
  import { INVITATION_TIMEOUT, getExpirationTime } from "@dxos/client-protocol";
4689
4922
  import { ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
4690
4923
  import { createKeyPair, sign as sign2 } from "@dxos/crypto";
4691
- import { invariant as invariant15 } from "@dxos/invariant";
4924
+ import { invariant as invariant17 } from "@dxos/invariant";
4692
4925
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4693
4926
  import { log as log18 } from "@dxos/log";
4694
4927
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
@@ -4702,8 +4935,8 @@ import { ComplexSet as ComplexSet5 } from "@dxos/util";
4702
4935
  // packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts
4703
4936
  import { scheduleMicroTask as scheduleMicroTask3, scheduleTask as scheduleTask5 } from "@dxos/async";
4704
4937
  import { sign } from "@dxos/crypto";
4705
- import { invariant as invariant11 } from "@dxos/invariant";
4706
- import { SpaceId as SpaceId2 } from "@dxos/keys";
4938
+ import { invariant as invariant13 } from "@dxos/invariant";
4939
+ import { SpaceId as SpaceId3 } from "@dxos/keys";
4707
4940
  import { log as log13 } from "@dxos/log";
4708
4941
  import { EdgeAuthChallengeError, EdgeCallFailedError as EdgeCallFailedError2 } from "@dxos/protocols";
4709
4942
  import { schema as schema3 } from "@dxos/protocols/proto";
@@ -4758,7 +4991,7 @@ var EdgeInvitationHandler = class {
4758
4991
  }
4759
4992
  const invitation = guardedState.current;
4760
4993
  const spaceId = invitation.spaceId;
4761
- const canBeHandledByEdge = invitation.authMethod !== Invitation4.AuthMethod.SHARED_SECRET && invitation.type === Invitation4.Type.DELEGATED && invitation.kind === Invitation4.Kind.SPACE && spaceId != null && SpaceId2.isValid(spaceId);
4994
+ const canBeHandledByEdge = invitation.authMethod !== Invitation4.AuthMethod.SHARED_SECRET && invitation.type === Invitation4.Type.DELEGATED && invitation.kind === Invitation4.Kind.SPACE && spaceId != null && SpaceId3.isValid(spaceId);
4762
4995
  if (!canBeHandledByEdge) {
4763
4996
  log13("invitation could not be handled by edge", {
4764
4997
  invitation
@@ -4854,7 +5087,7 @@ var EdgeInvitationHandler = class {
4854
5087
  };
4855
5088
  }
4856
5089
  async _joinSpaceByInvitation(guardedState, spaceId, request) {
4857
- invariant11(this._client, void 0, {
5090
+ invariant13(this._client, void 0, {
4858
5091
  F: __dxlog_file17,
4859
5092
  L: 160,
4860
5093
  S: this,
@@ -4891,9 +5124,9 @@ var EdgeInvitationHandler = class {
4891
5124
  };
4892
5125
 
4893
5126
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
4894
- import { Trigger as Trigger5 } from "@dxos/async";
4895
- import { cancelWithContext as cancelWithContext4, Context as Context6 } from "@dxos/context";
4896
- import { invariant as invariant12 } from "@dxos/invariant";
5127
+ import { Trigger as Trigger4 } from "@dxos/async";
5128
+ import { cancelWithContext as cancelWithContext4, Context as Context7 } from "@dxos/context";
5129
+ import { invariant as invariant14 } from "@dxos/invariant";
4897
5130
  import { log as log14 } from "@dxos/log";
4898
5131
  import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
4899
5132
  import { schema as schema4 } from "@dxos/protocols/proto";
@@ -4913,11 +5146,11 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4913
5146
  });
4914
5147
  this._invitationFlowMutex = _invitationFlowMutex;
4915
5148
  this._callbacks = _callbacks;
4916
- this._ctx = new Context6(void 0, {
5149
+ this._ctx = new Context7(void 0, {
4917
5150
  F: __dxlog_file18,
4918
5151
  L: 38
4919
5152
  });
4920
- this._remoteOptionsTrigger = new Trigger5();
5153
+ this._remoteOptionsTrigger = new Trigger4();
4921
5154
  this._invitationFlowLock = null;
4922
5155
  }
4923
5156
  hasFlowLock() {
@@ -4927,7 +5160,7 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4927
5160
  return {
4928
5161
  InvitationHostService: {
4929
5162
  options: async (options) => {
4930
- invariant12(!this._remoteOptions, "Remote options already set.", {
5163
+ invariant14(!this._remoteOptions, "Remote options already set.", {
4931
5164
  F: __dxlog_file18,
4932
5165
  L: 68,
4933
5166
  S: this,
@@ -5024,10 +5257,10 @@ var InvitationGuestExtension = class extends RpcExtension2 {
5024
5257
  };
5025
5258
 
5026
5259
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
5027
- import { Trigger as Trigger6, scheduleTask as scheduleTask6 } from "@dxos/async";
5028
- import { cancelWithContext as cancelWithContext5, Context as Context7 } from "@dxos/context";
5260
+ import { Trigger as Trigger5, scheduleTask as scheduleTask6 } from "@dxos/async";
5261
+ import { cancelWithContext as cancelWithContext5, Context as Context8 } from "@dxos/context";
5029
5262
  import { randomBytes, verify } from "@dxos/crypto";
5030
- import { invariant as invariant13, InvariantViolation } from "@dxos/invariant";
5263
+ import { invariant as invariant15, InvariantViolation } from "@dxos/invariant";
5031
5264
  import { PublicKey as PublicKey9 } from "@dxos/keys";
5032
5265
  import { log as log15 } from "@dxos/log";
5033
5266
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, trace as trace6 } from "@dxos/protocols";
@@ -5050,16 +5283,16 @@ var InvitationHostExtension = class extends RpcExtension3 {
5050
5283
  });
5051
5284
  this._invitationFlowMutex = _invitationFlowMutex;
5052
5285
  this._callbacks = _callbacks;
5053
- this._ctx = new Context7(void 0, {
5286
+ this._ctx = new Context8(void 0, {
5054
5287
  F: __dxlog_file19,
5055
5288
  L: 57
5056
5289
  });
5057
- this._remoteOptionsTrigger = new Trigger6();
5290
+ this._remoteOptionsTrigger = new Trigger5();
5058
5291
  this._challenge = void 0;
5059
5292
  this.guestProfile = void 0;
5060
5293
  this.authenticationPassed = false;
5061
5294
  this.authenticationRetry = 0;
5062
- this.completedTrigger = new Trigger6();
5295
+ this.completedTrigger = new Trigger5();
5063
5296
  this._invitationFlowLock = null;
5064
5297
  }
5065
5298
  hasFlowLock() {
@@ -5071,7 +5304,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
5071
5304
  // Perhaps in the future we will have more complex logic here.
5072
5305
  InvitationHostService: {
5073
5306
  options: async (options) => {
5074
- invariant13(!this._remoteOptions, "Remote options already set.", {
5307
+ invariant15(!this._remoteOptions, "Remote options already set.", {
5075
5308
  F: __dxlog_file19,
5076
5309
  L: 106,
5077
5310
  S: this,
@@ -5462,7 +5695,7 @@ var isNonTerminalState = (currentState) => {
5462
5695
  };
5463
5696
 
5464
5697
  // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
5465
- import { invariant as invariant14 } from "@dxos/invariant";
5698
+ import { invariant as invariant16 } from "@dxos/invariant";
5466
5699
  import { PublicKey as PublicKey10 } from "@dxos/keys";
5467
5700
  import { log as log17 } from "@dxos/log";
5468
5701
  import { InvitationOptions as InvitationOptions3 } from "@dxos/protocols/proto/dxos/halo/invitations";
@@ -5474,7 +5707,7 @@ var InvitationTopology = class {
5474
5707
  this._seenPeers = new ComplexSet4(PublicKey10.hash);
5475
5708
  }
5476
5709
  init(controller) {
5477
- invariant14(!this._controller, "Already initialized.", {
5710
+ invariant16(!this._controller, "Already initialized.", {
5478
5711
  F: __dxlog_file21,
5479
5712
  L: 42,
5480
5713
  S: this,
@@ -5486,7 +5719,7 @@ var InvitationTopology = class {
5486
5719
  this._controller = controller;
5487
5720
  }
5488
5721
  update() {
5489
- invariant14(this._controller, "Not initialized.", {
5722
+ invariant16(this._controller, "Not initialized.", {
5490
5723
  F: __dxlog_file21,
5491
5724
  L: 47,
5492
5725
  S: this,
@@ -5520,7 +5753,7 @@ var InvitationTopology = class {
5520
5753
  }
5521
5754
  }
5522
5755
  async onOffer(peer) {
5523
- invariant14(this._controller, "Not initialized.", {
5756
+ invariant16(this._controller, "Not initialized.", {
5524
5757
  F: __dxlog_file21,
5525
5758
  L: 76,
5526
5759
  S: this,
@@ -5589,7 +5822,7 @@ var InvitationsHandler = class {
5589
5822
  C: (f, a) => f(...a)
5590
5823
  });
5591
5824
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
5592
- invariant15(deviceKey, void 0, {
5825
+ invariant17(deviceKey, void 0, {
5593
5826
  F: __dxlog_file22,
5594
5827
  L: 112,
5595
5828
  S: this,
@@ -5781,7 +6014,7 @@ var InvitationsHandler = class {
5781
6014
  });
5782
6015
  const { timeout = INVITATION_TIMEOUT } = invitation;
5783
6016
  if (deviceProfile) {
5784
- invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
6017
+ invariant17(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5785
6018
  F: __dxlog_file22,
5786
6019
  L: 236,
5787
6020
  S: this,
@@ -6019,7 +6252,7 @@ var InvitationsHandler = class {
6019
6252
  stream.error(error);
6020
6253
  await ctx.dispose();
6021
6254
  } else {
6022
- invariant15(invitation.swarmKey, void 0, {
6255
+ invariant17(invitation.swarmKey, void 0, {
6023
6256
  F: __dxlog_file22,
6024
6257
  L: 406,
6025
6258
  S: this,
@@ -6242,7 +6475,7 @@ var InvitationsServiceImpl = class {
6242
6475
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
6243
6476
  import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
6244
6477
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
6245
- import { invariant as invariant16 } from "@dxos/invariant";
6478
+ import { invariant as invariant18 } from "@dxos/invariant";
6246
6479
  import { log as log19 } from "@dxos/log";
6247
6480
  import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError as InvalidInvitationError2, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6248
6481
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
@@ -6276,7 +6509,7 @@ var SpaceInvitationProtocol = class {
6276
6509
  return void 0;
6277
6510
  }
6278
6511
  getInvitationContext() {
6279
- invariant16(this._spaceKey, void 0, {
6512
+ invariant18(this._spaceKey, void 0, {
6280
6513
  F: __dxlog_file23,
6281
6514
  L: 65,
6282
6515
  S: this,
@@ -6286,7 +6519,7 @@ var SpaceInvitationProtocol = class {
6286
6519
  ]
6287
6520
  });
6288
6521
  const space = this._spaceManager.spaces.get(this._spaceKey);
6289
- invariant16(space, void 0, {
6522
+ invariant18(space, void 0, {
6290
6523
  F: __dxlog_file23,
6291
6524
  L: 67,
6292
6525
  S: this,
@@ -6302,7 +6535,7 @@ var SpaceInvitationProtocol = class {
6302
6535
  };
6303
6536
  }
6304
6537
  async admit(invitation, request, guestProfile) {
6305
- invariant16(this._spaceKey && request.space, void 0, {
6538
+ invariant18(this._spaceKey && request.space, void 0, {
6306
6539
  F: __dxlog_file23,
6307
6540
  L: 80,
6308
6541
  S: this,
@@ -6336,7 +6569,7 @@ var SpaceInvitationProtocol = class {
6336
6569
  };
6337
6570
  }
6338
6571
  async delegate(invitation) {
6339
- invariant16(this._spaceKey, void 0, {
6572
+ invariant18(this._spaceKey, void 0, {
6340
6573
  F: __dxlog_file23,
6341
6574
  L: 101,
6342
6575
  S: this,
@@ -6346,7 +6579,7 @@ var SpaceInvitationProtocol = class {
6346
6579
  ]
6347
6580
  });
6348
6581
  const space = this._spaceManager.spaces.get(this._spaceKey);
6349
- invariant16(space, void 0, {
6582
+ invariant18(space, void 0, {
6350
6583
  F: __dxlog_file23,
6351
6584
  L: 103,
6352
6585
  S: this,
@@ -6356,7 +6589,7 @@ var SpaceInvitationProtocol = class {
6356
6589
  ]
6357
6590
  });
6358
6591
  if (invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY) {
6359
- invariant16(invitation.guestKeypair?.publicKey, void 0, {
6592
+ invariant18(invitation.guestKeypair?.publicKey, void 0, {
6360
6593
  F: __dxlog_file23,
6361
6594
  L: 105,
6362
6595
  S: this,
@@ -6384,7 +6617,7 @@ var SpaceInvitationProtocol = class {
6384
6617
  multiUse: invitation.multiUse ?? false,
6385
6618
  guestKey: invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6386
6619
  });
6387
- invariant16(credential.credential, void 0, {
6620
+ invariant18(credential.credential, void 0, {
6388
6621
  F: __dxlog_file23,
6389
6622
  L: 126,
6390
6623
  S: this,
@@ -6399,7 +6632,7 @@ var SpaceInvitationProtocol = class {
6399
6632
  return credential.credential.credential.id;
6400
6633
  }
6401
6634
  async cancelDelegation(invitation) {
6402
- invariant16(this._spaceKey, void 0, {
6635
+ invariant18(this._spaceKey, void 0, {
6403
6636
  F: __dxlog_file23,
6404
6637
  L: 132,
6405
6638
  S: this,
@@ -6408,7 +6641,7 @@ var SpaceInvitationProtocol = class {
6408
6641
  ""
6409
6642
  ]
6410
6643
  });
6411
- invariant16(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6644
+ invariant18(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6412
6645
  F: __dxlog_file23,
6413
6646
  L: 133,
6414
6647
  S: this,
@@ -6418,7 +6651,7 @@ var SpaceInvitationProtocol = class {
6418
6651
  ]
6419
6652
  });
6420
6653
  const space = this._spaceManager.spaces.get(this._spaceKey);
6421
- invariant16(space, void 0, {
6654
+ invariant18(space, void 0, {
6422
6655
  F: __dxlog_file23,
6423
6656
  L: 135,
6424
6657
  S: this,
@@ -6437,7 +6670,7 @@ var SpaceInvitationProtocol = class {
6437
6670
  C: (f, a) => f(...a)
6438
6671
  });
6439
6672
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6440
- invariant16(credential.credential, void 0, {
6673
+ invariant18(credential.credential, void 0, {
6441
6674
  F: __dxlog_file23,
6442
6675
  L: 144,
6443
6676
  S: this,
@@ -6476,7 +6709,7 @@ var SpaceInvitationProtocol = class {
6476
6709
  };
6477
6710
  }
6478
6711
  async accept(response) {
6479
- invariant16(response.space, void 0, {
6712
+ invariant18(response.space, void 0, {
6480
6713
  F: __dxlog_file23,
6481
6714
  L: 179,
6482
6715
  S: this,
@@ -6487,7 +6720,7 @@ var SpaceInvitationProtocol = class {
6487
6720
  });
6488
6721
  const { credential, controlTimeframe, dataTimeframe } = response.space;
6489
6722
  const assertion = getCredentialAssertion5(credential);
6490
- invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6723
+ invariant18(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6491
6724
  F: __dxlog_file23,
6492
6725
  L: 182,
6493
6726
  S: this,
@@ -6496,7 +6729,7 @@ var SpaceInvitationProtocol = class {
6496
6729
  "'Invalid credential'"
6497
6730
  ]
6498
6731
  });
6499
- invariant16(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6732
+ invariant18(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6500
6733
  F: __dxlog_file23,
6501
6734
  L: 183,
6502
6735
  S: this,
@@ -6522,12 +6755,12 @@ var SpaceInvitationProtocol = class {
6522
6755
  };
6523
6756
 
6524
6757
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
6525
- import { Event as Event8, PushStream, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
6758
+ import { Event as Event8, PushStream, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
6526
6759
  import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
6527
- import { Context as Context8 } from "@dxos/context";
6760
+ import { Context as Context9 } from "@dxos/context";
6528
6761
  import { generatePasscode } from "@dxos/credentials";
6529
6762
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
6530
- import { invariant as invariant17 } from "@dxos/invariant";
6763
+ import { invariant as invariant19 } from "@dxos/invariant";
6531
6764
  import { PublicKey as PublicKey12 } from "@dxos/keys";
6532
6765
  import { log as log20 } from "@dxos/log";
6533
6766
  import { Invitation as Invitation9 } from "@dxos/protocols/proto/dxos/client/services";
@@ -6597,7 +6830,7 @@ var InvitationsManager = class {
6597
6830
  const persistentInvitations = this._metadataStore.getInvitations();
6598
6831
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
6599
6832
  const loadTasks = freshInvitations.map((persistentInvitation) => {
6600
- invariant17(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
6833
+ invariant19(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
6601
6834
  F: __dxlog_file24,
6602
6835
  L: 103,
6603
6836
  S: this,
@@ -6654,7 +6887,7 @@ var InvitationsManager = class {
6654
6887
  S: this,
6655
6888
  C: (f, a) => f(...a)
6656
6889
  });
6657
- invariant17(invitationId, void 0, {
6890
+ invariant19(invitationId, void 0, {
6658
6891
  F: __dxlog_file24,
6659
6892
  L: 141,
6660
6893
  S: this,
@@ -6686,7 +6919,7 @@ var InvitationsManager = class {
6686
6919
  S: this,
6687
6920
  C: (f, a) => f(...a)
6688
6921
  });
6689
- invariant17(invitationId, void 0, {
6922
+ invariant19(invitationId, void 0, {
6690
6923
  F: __dxlog_file24,
6691
6924
  L: 152,
6692
6925
  S: this,
@@ -6757,7 +6990,7 @@ var InvitationsManager = class {
6757
6990
  }
6758
6991
  _createObservableInvitation(handler, invitation) {
6759
6992
  const stream = new PushStream();
6760
- const ctx = new Context8({
6993
+ const ctx = new Context9({
6761
6994
  onError: (err) => {
6762
6995
  stream.error(err);
6763
6996
  void ctx.dispose();
@@ -6795,9 +7028,9 @@ var InvitationsManager = class {
6795
7028
  };
6796
7029
  }
6797
7030
  _createObservableAcceptingInvitation(handler, initialState) {
6798
- const otpEnteredTrigger = new Trigger7();
7031
+ const otpEnteredTrigger = new Trigger6();
6799
7032
  const stream = new PushStream();
6800
- const ctx = new Context8({
7033
+ const ctx = new Context9({
6801
7034
  onError: (err) => {
6802
7035
  if (err instanceof TimeoutError3) {
6803
7036
  log20("timeout", {
@@ -6893,9 +7126,9 @@ var InvitationsManager = class {
6893
7126
  }
6894
7127
  };
6895
7128
 
6896
- // packages/sdk/client-services/src/packlets/locks/browser.ts
6897
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger8 } from "@dxos/async";
6898
- import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
7129
+ // packages/sdk/client-services/src/packlets/locks/node.ts
7130
+ import { invariant as invariant20 } from "@dxos/invariant";
7131
+ import { LockFile } from "@dxos/lock-file";
6899
7132
  import { log as log21, logInfo as logInfo3 } from "@dxos/log";
6900
7133
  function _ts_decorate7(decorators, target, key, desc) {
6901
7134
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -6903,115 +7136,50 @@ function _ts_decorate7(decorators, target, key, desc) {
6903
7136
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6904
7137
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6905
7138
  }
6906
- var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6907
- var Message;
6908
- (function(Message2) {
6909
- Message2["ACQUIRING"] = "acquiring";
6910
- })(Message || (Message = {}));
7139
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
6911
7140
  var Lock = class {
6912
- constructor({ lockKey, onAcquire, onRelease }) {
6913
- this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
6914
- this._releaseTrigger = new Trigger8();
6915
- this._lockKey = lockKey;
7141
+ constructor({ lockKey: lockPath, onAcquire, onRelease }) {
7142
+ this._lockPath = lockPath;
6916
7143
  this._onAcquire = onAcquire;
6917
7144
  this._onRelease = onRelease;
6918
- this._broadcastChannel.onmessage = this._onMessage.bind(this);
6919
7145
  }
6920
7146
  get lockKey() {
6921
- return this._lockKey;
7147
+ return this._lockPath;
6922
7148
  }
6923
7149
  async acquire() {
6924
- this._broadcastChannel.postMessage({
6925
- message: "acquiring"
6926
- });
6927
- try {
6928
- log21("aquiring lock...", void 0, {
6929
- F: __dxlog_file25,
6930
- L: 42,
6931
- S: this,
6932
- C: (f, a) => f(...a)
6933
- });
6934
- await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6935
- log21("acquired lock", void 0, {
6936
- F: __dxlog_file25,
6937
- L: 44,
6938
- S: this,
6939
- C: (f, a) => f(...a)
6940
- });
6941
- } catch {
6942
- log21("stealing lock...", void 0, {
6943
- F: __dxlog_file25,
6944
- L: 46,
6945
- S: this,
6946
- C: (f, a) => f(...a)
6947
- });
6948
- await this._requestLock(true);
6949
- log21("stolen lock", void 0, {
6950
- F: __dxlog_file25,
6951
- L: 48,
6952
- S: this,
6953
- C: (f, a) => f(...a)
6954
- });
6955
- }
6956
- }
6957
- async release() {
6958
- this._releaseTrigger.wake();
6959
- }
6960
- _onMessage(event) {
6961
- if (event.data.message === "acquiring") {
6962
- this._releaseTrigger.wake();
6963
- }
6964
- }
6965
- async _requestLock(steal = false) {
6966
- log21("requesting lock...", {
6967
- steal
6968
- }, {
7150
+ log21("acquiring lock...", void 0, {
6969
7151
  F: __dxlog_file25,
6970
- L: 63,
7152
+ L: 32,
6971
7153
  S: this,
6972
7154
  C: (f, a) => f(...a)
6973
7155
  });
6974
- const acquired = new Trigger8();
6975
- void navigator.locks.request(this._lockKey, {
6976
- steal
6977
- }, async () => {
6978
- await this._onAcquire?.();
6979
- acquired.wake();
6980
- this._releaseTrigger = new Trigger8();
6981
- await this._releaseTrigger.wait();
6982
- log21("releasing lock...", void 0, {
6983
- F: __dxlog_file25,
6984
- L: 72,
6985
- S: this,
6986
- C: (f, a) => f(...a)
6987
- });
6988
- await this._onRelease?.();
6989
- log21("released lock", void 0, {
6990
- F: __dxlog_file25,
6991
- L: 74,
6992
- S: this,
6993
- C: (f, a) => f(...a)
6994
- });
6995
- }).catch(async () => {
6996
- await this._onRelease?.();
6997
- });
6998
- await acquired.wait();
6999
- log21("recieved lock", {
7000
- steal
7001
- }, {
7156
+ this._fileHandle = await LockFile.acquire(this._lockPath);
7157
+ await this._onAcquire?.();
7158
+ log21("acquired lock", void 0, {
7002
7159
  F: __dxlog_file25,
7003
- L: 81,
7160
+ L: 37,
7004
7161
  S: this,
7005
7162
  C: (f, a) => f(...a)
7006
7163
  });
7007
7164
  }
7165
+ async release() {
7166
+ await this._onRelease?.();
7167
+ invariant20(this._fileHandle, "Lock is not acquired", {
7168
+ F: __dxlog_file25,
7169
+ L: 42,
7170
+ S: this,
7171
+ A: [
7172
+ "this._fileHandle",
7173
+ "'Lock is not acquired'"
7174
+ ]
7175
+ });
7176
+ await LockFile.release(this._fileHandle);
7177
+ }
7008
7178
  };
7009
7179
  _ts_decorate7([
7010
7180
  logInfo3
7011
7181
  ], Lock.prototype, "lockKey", null);
7012
- var isLocked = (lockPath) => {
7013
- throw new Error("Not implemented");
7014
- };
7182
+ var isLocked = (lockPath) => LockFile.isLocked(lockPath);
7015
7183
 
7016
7184
  // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
7017
7185
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
@@ -7092,8 +7260,8 @@ ClientRpcServer = _ts_decorate8([
7092
7260
 
7093
7261
  // packages/sdk/client-services/src/packlets/agents/edge-agent-manager.ts
7094
7262
  import { DeferredTask as DeferredTask2, Event as Event9, scheduleTask as scheduleTask8, synchronized as synchronized3 } from "@dxos/async";
7095
- import { Resource as Resource6 } from "@dxos/context";
7096
- import { invariant as invariant18 } from "@dxos/invariant";
7263
+ import { Resource as Resource7 } from "@dxos/context";
7264
+ import { invariant as invariant21 } from "@dxos/invariant";
7097
7265
  import { PublicKey as PublicKey13 } from "@dxos/keys";
7098
7266
  import { log as log22 } from "@dxos/log";
7099
7267
  import { EdgeAgentStatus, EdgeCallFailedError as EdgeCallFailedError3 } from "@dxos/protocols";
@@ -7109,7 +7277,7 @@ var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
7109
7277
  var AGENT_STATUS_QUERY_RETRY_INTERVAL = 5e3;
7110
7278
  var AGENT_STATUS_QUERY_RETRY_JITTER = 1e3;
7111
7279
  var AGENT_FEED_ADDED_CHECK_INTERVAL_MS = 3e3;
7112
- var EdgeAgentManager = class extends Resource6 {
7280
+ var EdgeAgentManager = class extends Resource7 {
7113
7281
  constructor(_edgeFeatures, _edgeHttpClient, _dataSpaceManager, _identity) {
7114
7282
  super();
7115
7283
  this._edgeFeatures = _edgeFeatures;
@@ -7126,7 +7294,7 @@ var EdgeAgentManager = class extends Resource6 {
7126
7294
  return this._agentStatus && this._agentStatus !== EdgeAgentStatus.NOT_FOUND;
7127
7295
  }
7128
7296
  async createAgent() {
7129
- invariant18(this.isOpen, void 0, {
7297
+ invariant21(this.isOpen, void 0, {
7130
7298
  F: __dxlog_file26,
7131
7299
  L: 54,
7132
7300
  S: this,
@@ -7135,7 +7303,7 @@ var EdgeAgentManager = class extends Resource6 {
7135
7303
  ""
7136
7304
  ]
7137
7305
  });
7138
- invariant18(this._edgeHttpClient, void 0, {
7306
+ invariant21(this._edgeHttpClient, void 0, {
7139
7307
  F: __dxlog_file26,
7140
7308
  L: 55,
7141
7309
  S: this,
@@ -7144,7 +7312,7 @@ var EdgeAgentManager = class extends Resource6 {
7144
7312
  ""
7145
7313
  ]
7146
7314
  });
7147
- invariant18(this._edgeFeatures?.agents, void 0, {
7315
+ invariant21(this._edgeFeatures?.agents, void 0, {
7148
7316
  F: __dxlog_file26,
7149
7317
  L: 56,
7150
7318
  S: this,
@@ -7222,7 +7390,7 @@ var EdgeAgentManager = class extends Resource6 {
7222
7390
  this._lastKnownDeviceCount = 0;
7223
7391
  }
7224
7392
  async _fetchAgentStatus() {
7225
- invariant18(this._edgeHttpClient, void 0, {
7393
+ invariant21(this._edgeHttpClient, void 0, {
7226
7394
  F: __dxlog_file26,
7227
7395
  L: 121,
7228
7396
  S: this,
@@ -7394,14 +7562,14 @@ var mapStatus = (agentStatus) => {
7394
7562
  };
7395
7563
 
7396
7564
  // packages/sdk/client-services/src/packlets/services/service-context.ts
7397
- import { Mutex as Mutex4, Trigger as Trigger9 } from "@dxos/async";
7398
- import { Context as Context9, Resource as Resource7 } from "@dxos/context";
7565
+ import { Mutex as Mutex4, Trigger as Trigger7 } from "@dxos/async";
7566
+ import { Context as Context10, Resource as Resource8 } from "@dxos/context";
7399
7567
  import { getCredentialAssertion as getCredentialAssertion6 } from "@dxos/credentials";
7400
7568
  import { failUndefined as failUndefined2, warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
7401
7569
  import { EchoEdgeReplicator, EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
7402
7570
  import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from "@dxos/edge-client";
7403
7571
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
7404
- import { invariant as invariant20 } from "@dxos/invariant";
7572
+ import { invariant as invariant23 } from "@dxos/invariant";
7405
7573
  import { Keyring } from "@dxos/keyring";
7406
7574
  import { PublicKey as PublicKey15 } from "@dxos/keys";
7407
7575
  import { log as log24 } from "@dxos/log";
@@ -7414,7 +7582,7 @@ import { safeInstanceof } from "@dxos/util";
7414
7582
  // packages/sdk/client-services/src/packlets/identity/identity-recovery-manager.ts
7415
7583
  import { generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
7416
7584
  import { sign as sign3 } from "@dxos/crypto";
7417
- import { invariant as invariant19 } from "@dxos/invariant";
7585
+ import { invariant as invariant22 } from "@dxos/invariant";
7418
7586
  import { PublicKey as PublicKey14 } from "@dxos/keys";
7419
7587
  import { log as log23 } from "@dxos/log";
7420
7588
  import { EdgeAuthChallengeError as EdgeAuthChallengeError2 } from "@dxos/protocols";
@@ -7430,7 +7598,7 @@ var EdgeIdentityRecoveryManager = class {
7430
7598
  }
7431
7599
  async createRecoveryCredential({ data }) {
7432
7600
  const identity = this._identityProvider();
7433
- invariant19(identity, void 0, {
7601
+ invariant22(identity, void 0, {
7434
7602
  F: __dxlog_file27,
7435
7603
  L: 37,
7436
7604
  S: this,
@@ -7481,7 +7649,7 @@ var EdgeIdentityRecoveryManager = class {
7481
7649
  };
7482
7650
  }
7483
7651
  async requestRecoveryChallenge() {
7484
- invariant19(this._edgeClient, "Not connected to EDGE.", {
7652
+ invariant22(this._edgeClient, "Not connected to EDGE.", {
7485
7653
  F: __dxlog_file27,
7486
7654
  L: 74,
7487
7655
  S: this,
@@ -7511,7 +7679,7 @@ var EdgeIdentityRecoveryManager = class {
7511
7679
  }
7512
7680
  }
7513
7681
  async recoverIdentityWithExternalSignature({ lookupKey, deviceKey, controlFeedKey, signature, clientDataJson, authenticatorData }) {
7514
- invariant19(this._edgeClient, "Not connected to EDGE.", {
7682
+ invariant22(this._edgeClient, "Not connected to EDGE.", {
7515
7683
  F: __dxlog_file27,
7516
7684
  L: 106,
7517
7685
  S: this,
@@ -7541,10 +7709,41 @@ var EdgeIdentityRecoveryManager = class {
7541
7709
  dataFeedKey: await this._keyring.createKey()
7542
7710
  });
7543
7711
  }
7712
+ /**
7713
+ * Recovery identity using an opaque token sent to the user's email.
7714
+ */
7715
+ async recoverIdentityWithToken({ token }) {
7716
+ invariant22(this._edgeClient, "Not connected to EDGE.", {
7717
+ F: __dxlog_file27,
7718
+ L: 139,
7719
+ S: this,
7720
+ A: [
7721
+ "this._edgeClient",
7722
+ "'Not connected to EDGE.'"
7723
+ ]
7724
+ });
7725
+ const deviceKey = await this._keyring.createKey();
7726
+ const controlFeedKey = await this._keyring.createKey();
7727
+ const request = {
7728
+ deviceKey: deviceKey.toHex(),
7729
+ controlFeedKey: controlFeedKey.toHex(),
7730
+ token
7731
+ };
7732
+ const response = await this._edgeClient.recoverIdentity(request);
7733
+ await this._acceptRecoveredIdentity({
7734
+ authorizedDeviceCredential: decodeCredential(response.deviceAuthCredential),
7735
+ haloGenesisFeedKey: PublicKey14.fromHex(response.genesisFeedKey),
7736
+ haloSpaceKey: PublicKey14.fromHex(response.haloSpaceKey),
7737
+ identityKey: PublicKey14.fromHex(response.identityKey),
7738
+ deviceKey,
7739
+ controlFeedKey,
7740
+ dataFeedKey: await this._keyring.createKey()
7741
+ });
7742
+ }
7544
7743
  async recoverIdentity({ recoveryCode }) {
7545
- invariant19(this._edgeClient, "Not connected to EDGE.", {
7744
+ invariant22(this._edgeClient, "Not connected to EDGE.", {
7546
7745
  F: __dxlog_file27,
7547
- L: 136,
7746
+ L: 163,
7548
7747
  S: this,
7549
7748
  A: [
7550
7749
  "this._edgeClient",
@@ -7575,7 +7774,7 @@ var EdgeIdentityRecoveryManager = class {
7575
7774
  }
7576
7775
  log23.info("recovering identity", response, {
7577
7776
  F: __dxlog_file27,
7578
- L: 162,
7777
+ L: 189,
7579
7778
  S: this,
7580
7779
  C: (f, a) => f(...a)
7581
7780
  });
@@ -7603,7 +7802,7 @@ function _ts_decorate10(decorators, target, key, desc) {
7603
7802
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7604
7803
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7605
7804
  }
7606
- function _using_ctx3() {
7805
+ function _using_ctx4() {
7607
7806
  var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
7608
7807
  var err = new Error();
7609
7808
  err.name = "SuppressedError";
@@ -7666,7 +7865,7 @@ function _using_ctx3() {
7666
7865
  };
7667
7866
  }
7668
7867
  var __dxlog_file28 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
7669
- var ServiceContext = class extends Resource7 {
7868
+ var ServiceContext = class extends Resource8 {
7670
7869
  constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
7671
7870
  super();
7672
7871
  this.storage = storage;
@@ -7678,7 +7877,7 @@ var ServiceContext = class extends Resource7 {
7678
7877
  this._runtimeParams = _runtimeParams;
7679
7878
  this._edgeFeatures = _edgeFeatures;
7680
7879
  this._edgeIdentityUpdateMutex = new Mutex4();
7681
- this.initialized = new Trigger9();
7880
+ this.initialized = new Trigger7();
7682
7881
  this._meshReplicator = void 0;
7683
7882
  this._echoEdgeReplicator = void 0;
7684
7883
  this._handlerFactories = /* @__PURE__ */ new Map();
@@ -7821,7 +8020,7 @@ var ServiceContext = class extends Resource7 {
7821
8020
  const identity = await this.identityManager.createIdentity(params);
7822
8021
  await this._setNetworkIdentity();
7823
8022
  await identity.joinNetwork();
7824
- await this._initialize(new Context9(void 0, {
8023
+ await this._initialize(new Context10(void 0, {
7825
8024
  F: __dxlog_file28,
7826
8025
  L: 258
7827
8026
  }));
@@ -7832,7 +8031,7 @@ var ServiceContext = class extends Resource7 {
7832
8031
  throw new Error("Identity must be created before joining a space.");
7833
8032
  }
7834
8033
  const factory = this._handlerFactories.get(invitation.kind);
7835
- invariant20(factory, `Unknown invitation kind: ${invitation.kind}`, {
8034
+ invariant23(factory, `Unknown invitation kind: ${invitation.kind}`, {
7836
8035
  F: __dxlog_file28,
7837
8036
  L: 267,
7838
8037
  S: this,
@@ -7858,7 +8057,7 @@ var ServiceContext = class extends Resource7 {
7858
8057
  });
7859
8058
  await identity.joinNetwork();
7860
8059
  await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
7861
- await this._initialize(new Context9(void 0, {
8060
+ await this._initialize(new Context10(void 0, {
7862
8061
  F: __dxlog_file28,
7863
8062
  L: 286
7864
8063
  }));
@@ -7911,7 +8110,7 @@ var ServiceContext = class extends Resource7 {
7911
8110
  this.edgeAgentManager = new EdgeAgentManager(this._edgeFeatures, this._edgeHttpClient, this.dataSpaceManager, identity);
7912
8111
  await this.edgeAgentManager.open();
7913
8112
  this._handlerFactories.set(Invitation10.Kind.SPACE, (invitation) => {
7914
- invariant20(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
8113
+ invariant23(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7915
8114
  F: __dxlog_file28,
7916
8115
  L: 339,
7917
8116
  S: this,
@@ -7981,7 +8180,7 @@ var ServiceContext = class extends Resource7 {
7981
8180
  }
7982
8181
  async _setNetworkIdentity(params) {
7983
8182
  try {
7984
- var _usingCtx = _using_ctx3();
8183
+ var _usingCtx = _using_ctx4();
7985
8184
  const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
7986
8185
  let edgeIdentity;
7987
8186
  const identity = this.identityManager.identity;
@@ -8003,7 +8202,7 @@ var ServiceContext = class extends Resource7 {
8003
8202
  await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
8004
8203
  await identity.ready();
8005
8204
  });
8006
- invariant20(identity.deviceCredentialChain, void 0, {
8205
+ invariant23(identity.deviceCredentialChain, void 0, {
8007
8206
  F: __dxlog_file28,
8008
8207
  L: 403,
8009
8208
  S: this,
@@ -8128,7 +8327,7 @@ var toStorageType = (type) => {
8128
8327
  };
8129
8328
 
8130
8329
  // packages/sdk/client-services/src/packlets/storage/level.ts
8131
- import path from "@dxos/node-std/path";
8330
+ import path from "node:path";
8132
8331
  import { PublicKey as PublicKey16 } from "@dxos/keys";
8133
8332
  import { createLevel as createKV } from "@dxos/kv-store";
8134
8333
  var createLevel = async (config) => {
@@ -8141,7 +8340,7 @@ var createLevel = async (config) => {
8141
8340
 
8142
8341
  // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
8143
8342
  import { cbor } from "@dxos/automerge/automerge-repo";
8144
- import { invariant as invariant21 } from "@dxos/invariant";
8343
+ import { invariant as invariant24 } from "@dxos/invariant";
8145
8344
  import { log as log25 } from "@dxos/log";
8146
8345
  import { ProfileArchiveEntryType } from "@dxos/protocols";
8147
8346
  import { arrayToBuffer as arrayToBuffer2 } from "@dxos/util";
@@ -8223,7 +8422,7 @@ var importProfileData = async ({ storage, level }, archive) => {
8223
8422
  switch (entry2.type) {
8224
8423
  case ProfileArchiveEntryType.FILE: {
8225
8424
  const directory = await storage.createDirectory();
8226
- invariant21(typeof entry2.key === "string", "Invalid key type", {
8425
+ invariant24(typeof entry2.key === "string", "Invalid key type", {
8227
8426
  F: __dxlog_file29,
8228
8427
  L: 79,
8229
8428
  S: void 0,
@@ -8233,7 +8432,7 @@ var importProfileData = async ({ storage, level }, archive) => {
8233
8432
  ]
8234
8433
  });
8235
8434
  const file = await directory.getOrCreateFile(entry2.key);
8236
- invariant21(entry2.value instanceof Uint8Array, "Invalid value type", {
8435
+ invariant24(entry2.value instanceof Uint8Array, "Invalid value type", {
8237
8436
  F: __dxlog_file29,
8238
8437
  L: 81,
8239
8438
  S: void 0,
@@ -8247,7 +8446,7 @@ var importProfileData = async ({ storage, level }, archive) => {
8247
8446
  break;
8248
8447
  }
8249
8448
  case ProfileArchiveEntryType.KEY_VALUE: {
8250
- invariant21(entry2.key instanceof Uint8Array, "Invalid key type", {
8449
+ invariant24(entry2.key instanceof Uint8Array, "Invalid key type", {
8251
8450
  F: __dxlog_file29,
8252
8451
  L: 87,
8253
8452
  S: void 0,
@@ -8256,7 +8455,7 @@ var importProfileData = async ({ storage, level }, archive) => {
8256
8455
  "'Invalid key type'"
8257
8456
  ]
8258
8457
  });
8259
- invariant21(entry2.value instanceof Uint8Array, "Invalid value type", {
8458
+ invariant24(entry2.value instanceof Uint8Array, "Invalid value type", {
8260
8459
  F: __dxlog_file29,
8261
8460
  L: 88,
8262
8461
  S: void 0,
@@ -8301,9 +8500,9 @@ var importProfileData = async ({ storage, level }, archive) => {
8301
8500
  // packages/sdk/client-services/src/packlets/services/service-host.ts
8302
8501
  import { Event as Event11, synchronized as synchronized4 } from "@dxos/async";
8303
8502
  import { clientServiceBundle } from "@dxos/client-protocol";
8304
- import { Context as Context10 } from "@dxos/context";
8503
+ import { Context as Context11 } from "@dxos/context";
8305
8504
  import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity } from "@dxos/edge-client";
8306
- import { invariant as invariant23 } from "@dxos/invariant";
8505
+ import { invariant as invariant26 } from "@dxos/invariant";
8307
8506
  import { PublicKey as PublicKey19 } from "@dxos/keys";
8308
8507
  import { log as log27 } from "@dxos/log";
8309
8508
  import { EdgeSignalManager, WebsocketSignalManager } from "@dxos/messaging";
@@ -8314,9 +8513,9 @@ import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/trac
8314
8513
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
8315
8514
 
8316
8515
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
8317
- import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
8516
+ import { SubscriptionList as SubscriptionList3 } from "@dxos/async";
8318
8517
  import { Stream as Stream12 } from "@dxos/codec-protobuf/stream";
8319
- import { invariant as invariant22 } from "@dxos/invariant";
8518
+ import { invariant as invariant25 } from "@dxos/invariant";
8320
8519
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
8321
8520
  var __dxlog_file30 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
8322
8521
  var DevicesServiceImpl = class {
@@ -8336,7 +8535,7 @@ var DevicesServiceImpl = class {
8336
8535
  devices: []
8337
8536
  });
8338
8537
  } else {
8339
- invariant22(this._identityManager.identity?.presence, "presence not present", {
8538
+ invariant25(this._identityManager.identity?.presence, "presence not present", {
8340
8539
  F: __dxlog_file30,
8341
8540
  L: 36,
8342
8541
  S: this,
@@ -8385,7 +8584,7 @@ var DevicesServiceImpl = class {
8385
8584
  presenceSubscribed = true;
8386
8585
  }
8387
8586
  };
8388
- const subscriptions = new EventSubscriptions3();
8587
+ const subscriptions = new SubscriptionList3();
8389
8588
  if (this._identityManager.identity) {
8390
8589
  subscribeIdentity();
8391
8590
  subscribePresence();
@@ -8404,7 +8603,7 @@ var DevicesServiceImpl = class {
8404
8603
  };
8405
8604
 
8406
8605
  // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
8407
- import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask9, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
8606
+ import { scheduleTask as scheduleTask9, UpdateScheduler as UpdateScheduler2, SubscriptionList as SubscriptionList4 } from "@dxos/async";
8408
8607
  import { Stream as Stream13 } from "@dxos/codec-protobuf/stream";
8409
8608
  import { PublicKey as PublicKey17 } from "@dxos/keys";
8410
8609
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
@@ -8464,7 +8663,7 @@ var ContactsServiceImpl = class {
8464
8663
  maxFrequency: 2
8465
8664
  });
8466
8665
  scheduleTask9(ctx, async () => {
8467
- const subscriptions = new EventSubscriptions4();
8666
+ const subscriptions = new SubscriptionList4();
8468
8667
  ctx.onDispose(() => subscriptions.clear());
8469
8668
  const subscribeToSpaceAndUpdate = () => {
8470
8669
  const oldSetSize = subscribedSpaceKeySet.size;
@@ -8778,7 +8977,7 @@ var ClientServicesHost = class {
8778
8977
  lockKey,
8779
8978
  onAcquire: () => {
8780
8979
  if (!this._opening) {
8781
- void this.open(new Context10(void 0, {
8980
+ void this.open(new Context11(void 0, {
8782
8981
  F: __dxlog_file31,
8783
8982
  L: 137
8784
8983
  }));
@@ -8836,7 +9035,7 @@ var ClientServicesHost = class {
8836
9035
  * Can only be called once.
8837
9036
  */
8838
9037
  initialize({ config, ...options }) {
8839
- invariant23(!this._open, "service host is open", {
9038
+ invariant26(!this._open, "service host is open", {
8840
9039
  F: __dxlog_file31,
8841
9040
  L: 203,
8842
9041
  S: this,
@@ -8852,7 +9051,7 @@ var ClientServicesHost = class {
8852
9051
  C: (f, a) => f(...a)
8853
9052
  });
8854
9053
  if (config) {
8855
- invariant23(!this._config, "config already set", {
9054
+ invariant26(!this._config, "config already set", {
8856
9055
  F: __dxlog_file31,
8857
9056
  L: 207,
8858
9057
  S: this,
@@ -8887,7 +9086,7 @@ var ClientServicesHost = class {
8887
9086
  edgeConnection: this._edgeConnection
8888
9087
  }) : new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
8889
9088
  this._signalManager = signalManager;
8890
- invariant23(!this._networkManager, "network manager already set", {
9089
+ invariant26(!this._networkManager, "network manager already set", {
8891
9090
  F: __dxlog_file31,
8892
9091
  L: 237,
8893
9092
  S: this,
@@ -8925,7 +9124,7 @@ var ClientServicesHost = class {
8925
9124
  S: this,
8926
9125
  C: (f, a) => f(...a)
8927
9126
  });
8928
- invariant23(this._config, "config not set", {
9127
+ invariant26(this._config, "config not set", {
8929
9128
  F: __dxlog_file31,
8930
9129
  L: 263,
8931
9130
  S: this,
@@ -8934,7 +9133,7 @@ var ClientServicesHost = class {
8934
9133
  "'config not set'"
8935
9134
  ]
8936
9135
  });
8937
- invariant23(this._storage, "storage not set", {
9136
+ invariant26(this._storage, "storage not set", {
8938
9137
  F: __dxlog_file31,
8939
9138
  L: 264,
8940
9139
  S: this,
@@ -8943,7 +9142,7 @@ var ClientServicesHost = class {
8943
9142
  "'storage not set'"
8944
9143
  ]
8945
9144
  });
8946
- invariant23(this._signalManager, "signal manager not set", {
9145
+ invariant26(this._signalManager, "signal manager not set", {
8947
9146
  F: __dxlog_file31,
8948
9147
  L: 265,
8949
9148
  S: this,
@@ -8952,7 +9151,7 @@ var ClientServicesHost = class {
8952
9151
  "'signal manager not set'"
8953
9152
  ]
8954
9153
  });
8955
- invariant23(this._networkManager, "network manager not set", {
9154
+ invariant26(this._networkManager, "network manager not set", {
8956
9155
  F: __dxlog_file31,
8957
9156
  L: 266,
8958
9157
  S: this,
@@ -9180,4 +9379,4 @@ export {
9180
9379
  importProfileData,
9181
9380
  ClientServicesHost
9182
9381
  };
9183
- //# sourceMappingURL=chunk-VJODS5QE.mjs.map
9382
+ //# sourceMappingURL=chunk-2H5CIBX2.mjs.map