@dxos/echo-pipeline 0.4.6-main.e47f68d → 0.4.6

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.
@@ -27,6 +27,9 @@ export class AutomergeHost {
27
27
  private readonly _clientNetwork: LocalHostNetworkAdapter;
28
28
  private readonly _storage: StorageAdapter;
29
29
 
30
+ @trace.info()
31
+ private readonly _peerId: string;
32
+
30
33
  /**
31
34
  * spaceKey -> deviceKey[]
32
35
  */
@@ -43,9 +46,9 @@ export class AutomergeHost {
43
46
  storageDirectory.type === StorageType.IDB
44
47
  ? new IndexedDBStorageAdapter(storageDirectory.path, 'data')
45
48
  : new AutomergeStorageAdapter(storageDirectory);
46
- const localPeerId = `host-${PublicKey.random().toHex()}` as PeerId;
49
+ this._peerId = `host-${PublicKey.random().toHex()}` as PeerId;
47
50
  this._repo = new Repo({
48
- peerId: localPeerId,
51
+ peerId: this._peerId as PeerId,
49
52
  network: [this._clientNetwork, this._meshNetwork],
50
53
  storage: this._storage,
51
54
 
@@ -68,12 +71,14 @@ export class AutomergeHost {
68
71
  }
69
72
 
70
73
  try {
71
- if (!doc.experimental_spaceKey) {
74
+ // experimental_spaceKey is set on old documents, new ones are created with doc.access.spaceKey
75
+ const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
76
+ if (!rawSpaceKey) {
72
77
  log('space key not found for share policy check', { peerId, documentId });
73
78
  return false;
74
79
  }
75
80
 
76
- const spaceKey = PublicKey.from(doc.experimental_spaceKey);
81
+ const spaceKey = PublicKey.from(rawSpaceKey);
77
82
  const authorizedDevices = this._authorizedDevices.get(spaceKey);
78
83
 
79
84
  // TODO(mykola): Hack, stop abusing `peerMetadata` field.
@@ -86,7 +91,7 @@ export class AutomergeHost {
86
91
 
87
92
  const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
88
93
  log('share policy check', {
89
- localPeer: localPeerId,
94
+ localPeer: this._peerId,
90
95
  remotePeer: peerId,
91
96
  documentId,
92
97
  deviceKey,
@@ -114,6 +119,23 @@ export class AutomergeHost {
114
119
  state: handle.state,
115
120
  hasDoc: !!handle.docSync(),
116
121
  heads: handle.docSync() ? automerge.getHeads(handle.docSync()) : null,
122
+ data:
123
+ handle.docSync()?.doc &&
124
+ mapValues(handle.docSync()?.doc, (value, key) => {
125
+ try {
126
+ switch (key) {
127
+ case 'access':
128
+ case 'links':
129
+ return value;
130
+ case 'objects':
131
+ return Object.keys(value as any);
132
+ default:
133
+ return `${value}`;
134
+ }
135
+ } catch (err) {
136
+ return `${err}`;
137
+ }
138
+ }),
117
139
  }));
118
140
  }
119
141