@dxos/echo-pipeline 0.4.8-main.c4e8b01 → 0.4.8-main.c5d7957

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-pipeline",
3
- "version": "0.4.8-main.c4e8b01",
3
+ "version": "0.4.8-main.c5d7957",
4
4
  "description": "ECHO database.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -36,38 +36,38 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "crc-32": "^1.2.2",
39
- "@dxos/async": "0.4.8-main.c4e8b01",
40
- "@dxos/automerge": "0.4.8-main.c4e8b01",
41
- "@dxos/codec-protobuf": "0.4.8-main.c4e8b01",
42
- "@dxos/credentials": "0.4.8-main.c4e8b01",
43
- "@dxos/context": "0.4.8-main.c4e8b01",
44
- "@dxos/crypto": "0.4.8-main.c4e8b01",
45
- "@dxos/debug": "0.4.8-main.c4e8b01",
46
- "@dxos/document-model": "0.4.8-main.c4e8b01",
47
- "@dxos/echo-db": "0.4.8-main.c4e8b01",
48
- "@dxos/feed-store": "0.4.8-main.c4e8b01",
49
- "@dxos/hypercore": "0.4.8-main.c4e8b01",
50
- "@dxos/invariant": "0.4.8-main.c4e8b01",
51
- "@dxos/keyring": "0.4.8-main.c4e8b01",
52
- "@dxos/keys": "0.4.8-main.c4e8b01",
53
- "@dxos/log": "0.4.8-main.c4e8b01",
54
- "@dxos/messaging": "0.4.8-main.c4e8b01",
55
- "@dxos/network-manager": "0.4.8-main.c4e8b01",
56
- "@dxos/model-factory": "0.4.8-main.c4e8b01",
57
- "@dxos/node-std": "0.4.8-main.c4e8b01",
58
- "@dxos/protocols": "0.4.8-main.c4e8b01",
59
- "@dxos/rpc": "0.4.8-main.c4e8b01",
60
- "@dxos/teleport": "0.4.8-main.c4e8b01",
61
- "@dxos/random-access-storage": "0.4.8-main.c4e8b01",
62
- "@dxos/teleport-extension-automerge-replicator": "0.4.8-main.c4e8b01",
63
- "@dxos/teleport-extension-gossip": "0.4.8-main.c4e8b01",
64
- "@dxos/teleport-extension-object-sync": "0.4.8-main.c4e8b01",
65
- "@dxos/text-model": "0.4.8-main.c4e8b01",
66
- "@dxos/tracing": "0.4.8-main.c4e8b01",
67
- "@dxos/typings": "0.4.8-main.c4e8b01",
68
- "@dxos/teleport-extension-replicator": "0.4.8-main.c4e8b01",
69
- "@dxos/util": "0.4.8-main.c4e8b01",
70
- "@dxos/timeframe": "0.4.8-main.c4e8b01"
39
+ "@dxos/async": "0.4.8-main.c5d7957",
40
+ "@dxos/automerge": "0.4.8-main.c5d7957",
41
+ "@dxos/codec-protobuf": "0.4.8-main.c5d7957",
42
+ "@dxos/context": "0.4.8-main.c5d7957",
43
+ "@dxos/credentials": "0.4.8-main.c5d7957",
44
+ "@dxos/crypto": "0.4.8-main.c5d7957",
45
+ "@dxos/debug": "0.4.8-main.c5d7957",
46
+ "@dxos/document-model": "0.4.8-main.c5d7957",
47
+ "@dxos/echo-db": "0.4.8-main.c5d7957",
48
+ "@dxos/feed-store": "0.4.8-main.c5d7957",
49
+ "@dxos/hypercore": "0.4.8-main.c5d7957",
50
+ "@dxos/invariant": "0.4.8-main.c5d7957",
51
+ "@dxos/keyring": "0.4.8-main.c5d7957",
52
+ "@dxos/log": "0.4.8-main.c5d7957",
53
+ "@dxos/keys": "0.4.8-main.c5d7957",
54
+ "@dxos/messaging": "0.4.8-main.c5d7957",
55
+ "@dxos/model-factory": "0.4.8-main.c5d7957",
56
+ "@dxos/network-manager": "0.4.8-main.c5d7957",
57
+ "@dxos/node-std": "0.4.8-main.c5d7957",
58
+ "@dxos/protocols": "0.4.8-main.c5d7957",
59
+ "@dxos/random-access-storage": "0.4.8-main.c5d7957",
60
+ "@dxos/rpc": "0.4.8-main.c5d7957",
61
+ "@dxos/teleport": "0.4.8-main.c5d7957",
62
+ "@dxos/teleport-extension-automerge-replicator": "0.4.8-main.c5d7957",
63
+ "@dxos/teleport-extension-gossip": "0.4.8-main.c5d7957",
64
+ "@dxos/teleport-extension-object-sync": "0.4.8-main.c5d7957",
65
+ "@dxos/teleport-extension-replicator": "0.4.8-main.c5d7957",
66
+ "@dxos/text-model": "0.4.8-main.c5d7957",
67
+ "@dxos/timeframe": "0.4.8-main.c5d7957",
68
+ "@dxos/tracing": "0.4.8-main.c5d7957",
69
+ "@dxos/typings": "0.4.8-main.c5d7957",
70
+ "@dxos/util": "0.4.8-main.c5d7957"
71
71
  },
72
72
  "devDependencies": {
73
73
  "fast-check": "^3.15.1",
@@ -13,7 +13,7 @@ import {
13
13
  } from '@dxos/automerge/automerge-repo';
14
14
  import { IndexedDBStorageAdapter } from '@dxos/automerge/automerge-repo-storage-indexeddb';
15
15
  import { type Stream } from '@dxos/codec-protobuf';
16
- import { Context, cancelWithContext } from '@dxos/context';
16
+ import { Context } from '@dxos/context';
17
17
  import { PublicKey } from '@dxos/keys';
18
18
  import { log } from '@dxos/log';
19
19
  import { idCodec } from '@dxos/protocols';
@@ -31,7 +31,7 @@ import { MeshNetworkAdapter } from './mesh-network-adapter';
31
31
  export type { DocumentId };
32
32
 
33
33
  export interface MetadataMethods {
34
- markDirty(id: string, lastAvailableHash: string): Promise<void>;
34
+ markDirty(idToLastHash: Map<string, string>): Promise<void>;
35
35
  }
36
36
 
37
37
  export type AutomergeHostParams = {
@@ -98,15 +98,13 @@ export class AutomergeHost {
98
98
  }
99
99
 
100
100
  try {
101
- // experimental_spaceKey is set on old documents, new ones are created with doc.access.spaceKey
102
- const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
103
- if (!rawSpaceKey) {
101
+ const spaceKey = getSpaceKeyFromDoc(doc);
102
+ if (!spaceKey) {
104
103
  log('space key not found for share policy check', { peerId, documentId });
105
104
  return false;
106
105
  }
107
106
 
108
- const spaceKey = PublicKey.from(rawSpaceKey);
109
- const authorizedDevices = this._authorizedDevices.get(spaceKey);
107
+ const authorizedDevices = this._authorizedDevices.get(PublicKey.from(spaceKey));
110
108
 
111
109
  // TODO(mykola): Hack, stop abusing `peerMetadata` field.
112
110
  const deviceKeyHex = (this.repo.peerMetadataByPeerId[peerId] as any)?.dxos_deviceKey;
@@ -164,8 +162,7 @@ export class AutomergeHost {
164
162
  }
165
163
 
166
164
  private _onUpdate(event: DocHandleChangePayload<any>) {
167
- const spaceKey = event.doc.access?.spaceKey;
168
- if (!spaceKey) {
165
+ if (this._metadata == null) {
169
166
  return;
170
167
  }
171
168
 
@@ -180,24 +177,16 @@ export class AutomergeHost {
180
177
  return;
181
178
  }
182
179
 
183
- const markingDirtyPromise = Promise.all(
184
- objectIds.map(async (objectId) => {
185
- await cancelWithContext(
186
- this._ctx,
187
- this._metadata!.markDirty(
188
- idCodec.encode({ documentId: event.handle.documentId, objectId }),
189
- lastAvailableHash,
190
- ),
191
- );
192
- }),
193
- )
180
+ const encodedIds = objectIds.map((objectId) => idCodec.encode({ documentId: event.handle.documentId, objectId }));
181
+ const idToLastHash = new Map(encodedIds.map((id) => [id, lastAvailableHash]));
182
+ const markingDirtyPromise = this._metadata
183
+ .markDirty(idToLastHash)
194
184
  .then(() => {
195
185
  this._updatingMetadata.delete(event.handle.documentId);
196
186
  })
197
187
  .catch((err: Error) => {
198
- !this._ctx.disposed && log.catch(err);
188
+ this._ctx.disposed && log.catch(err);
199
189
  });
200
-
201
190
  this._updatingMetadata.set(event.handle.documentId, markingDirtyPromise);
202
191
  }
203
192
 
@@ -285,3 +274,13 @@ const getInlineChanges = (event: DocHandleChangePayload<any>) => {
285
274
  }
286
275
  return [...inlineChangedObjectIds];
287
276
  };
277
+
278
+ export const getSpaceKeyFromDoc = (doc: any): string | null => {
279
+ // experimental_spaceKey is set on old documents, new ones are created with doc.access.spaceKey
280
+ const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
281
+ if (rawSpaceKey == null) {
282
+ return null;
283
+ }
284
+
285
+ return String(rawSpaceKey);
286
+ };
@@ -5,20 +5,18 @@
5
5
  // Copyright 2023 DXOS.org
6
6
  //
7
7
 
8
- import { StorageAdapter, type Chunk, type StorageKey } from '@dxos/automerge/automerge-repo';
8
+ import { type Chunk, type StorageKey, type StorageAdapterInterface } from '@dxos/automerge/automerge-repo';
9
9
  import { type Directory } from '@dxos/random-access-storage';
10
10
  import { arrayToBuffer, bufferToArray } from '@dxos/util';
11
11
 
12
- export class AutomergeStorageAdapter extends StorageAdapter {
12
+ export class AutomergeStorageAdapter implements StorageAdapterInterface {
13
13
  // TODO(mykola): Hack for restricting automerge Repo to access storage if Host is `closed`.
14
14
  // Automerge Repo do not have any lifetime management.
15
15
  private _state: 'opened' | 'closed' = 'opened';
16
16
 
17
- constructor(private readonly _directory: Directory) {
18
- super();
19
- }
17
+ constructor(private readonly _directory: Directory) {}
20
18
 
21
- override async load(key: StorageKey): Promise<Uint8Array | undefined> {
19
+ async load(key: StorageKey): Promise<Uint8Array | undefined> {
22
20
  if (this._state !== 'opened') {
23
21
  return undefined;
24
22
  }
@@ -32,7 +30,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
32
30
  return bufferToArray(buffer);
33
31
  }
34
32
 
35
- override async save(key: StorageKey, data: Uint8Array): Promise<void> {
33
+ async save(key: StorageKey, data: Uint8Array): Promise<void> {
36
34
  if (this._state !== 'opened') {
37
35
  return undefined;
38
36
  }
@@ -44,7 +42,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
44
42
  await file.flush?.();
45
43
  }
46
44
 
47
- override async remove(key: StorageKey): Promise<void> {
45
+ async remove(key: StorageKey): Promise<void> {
48
46
  if (this._state !== 'opened') {
49
47
  return undefined;
50
48
  }
@@ -54,7 +52,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
54
52
  await file.destroy();
55
53
  }
56
54
 
57
- override async loadRange(keyPrefix: StorageKey): Promise<Chunk[]> {
55
+ async loadRange(keyPrefix: StorageKey): Promise<Chunk[]> {
58
56
  if (this._state !== 'opened') {
59
57
  return [];
60
58
  }
@@ -75,7 +73,7 @@ export class AutomergeStorageAdapter extends StorageAdapter {
75
73
  );
76
74
  }
77
75
 
78
- override async removeRange(keyPrefix: StorageKey): Promise<void> {
76
+ async removeRange(keyPrefix: StorageKey): Promise<void> {
79
77
  if (this._state !== 'opened') {
80
78
  return undefined;
81
79
  }