@dxos/echo-pipeline 0.8.0 → 0.8.1-main.013e445
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/dist/lib/browser/index.mjs +46 -15
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +60 -29
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +46 -15
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +2 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +2 -1
- package/dist/types/src/db-host/database-root.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts +1 -0
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/package.json +34 -34
- package/src/automerge/automerge-host.ts +19 -1
- package/src/db-host/database-root.ts +20 -1
- package/src/db-host/echo-host.ts +4 -0
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type PeerId,
|
|
24
24
|
type StorageAdapterInterface,
|
|
25
25
|
type StorageKey,
|
|
26
|
+
interpretAsDocumentId,
|
|
26
27
|
} from '@dxos/automerge/automerge-repo';
|
|
27
28
|
import { Context, Resource, cancelWithContext, type Lifecycle } from '@dxos/context';
|
|
28
29
|
import { type CollectionId, type SpaceDoc } from '@dxos/echo-protocol';
|
|
@@ -34,6 +35,7 @@ import { log } from '@dxos/log';
|
|
|
34
35
|
import { objectPointerCodec } from '@dxos/protocols';
|
|
35
36
|
import { type DocHeadsList, type FlushRequest } from '@dxos/protocols/proto/dxos/echo/service';
|
|
36
37
|
import { trace } from '@dxos/tracing';
|
|
38
|
+
import { bufferToArray } from '@dxos/util';
|
|
37
39
|
|
|
38
40
|
import { CollectionSynchronizer, diffCollectionState, type CollectionState } from './collection-synchronizer';
|
|
39
41
|
import { type EchoDataMonitor } from './echo-data-monitor';
|
|
@@ -228,17 +230,33 @@ export class AutomergeHost extends Resource {
|
|
|
228
230
|
return handle;
|
|
229
231
|
}
|
|
230
232
|
|
|
233
|
+
async exportDoc(ctx: Context, id: AnyDocumentId): Promise<Uint8Array> {
|
|
234
|
+
const documentId = interpretAsDocumentId(id);
|
|
235
|
+
|
|
236
|
+
const chunks = await this._storage.loadRange([documentId]);
|
|
237
|
+
return bufferToArray(Buffer.concat(chunks.map((c) => c.data!)));
|
|
238
|
+
}
|
|
239
|
+
|
|
231
240
|
/**
|
|
232
241
|
* Create new persisted document.
|
|
233
242
|
*/
|
|
234
|
-
createDoc<T>(initialValue?: T | Doc<T
|
|
243
|
+
createDoc<T>(initialValue?: T | Doc<T> | Uint8Array, opts?: CreateDocOptions): DocHandle<T> {
|
|
235
244
|
if (opts?.preserveHistory) {
|
|
245
|
+
if (initialValue instanceof Uint8Array) {
|
|
246
|
+
return this._repo.import(initialValue);
|
|
247
|
+
}
|
|
248
|
+
|
|
236
249
|
if (!isAutomerge(initialValue)) {
|
|
237
250
|
throw new TypeError('Initial value must be an Automerge document');
|
|
238
251
|
}
|
|
252
|
+
|
|
239
253
|
// TODO(dmaretskyi): There's a more efficient way.
|
|
240
254
|
return this._repo.import(save(initialValue as Doc<T>));
|
|
241
255
|
} else {
|
|
256
|
+
if (initialValue instanceof Uint8Array) {
|
|
257
|
+
throw new Error('Cannot create document from Uint8Array without preserving history');
|
|
258
|
+
}
|
|
259
|
+
|
|
242
260
|
return this._repo.create(initialValue);
|
|
243
261
|
}
|
|
244
262
|
}
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import type * as A from '@dxos/automerge/automerge';
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
interpretAsDocumentId,
|
|
8
|
+
type AutomergeUrl,
|
|
9
|
+
type DocHandle,
|
|
10
|
+
type DocumentId,
|
|
11
|
+
} from '@dxos/automerge/automerge-repo';
|
|
7
12
|
import { type SpaceDoc, SpaceDocVersion } from '@dxos/echo-protocol';
|
|
8
13
|
import { invariant } from '@dxos/invariant';
|
|
9
14
|
|
|
@@ -11,6 +16,20 @@ import { measureDocMetrics, type DocMetrics } from './automerge-metrics';
|
|
|
11
16
|
import { getSpaceKeyFromDoc } from '../automerge';
|
|
12
17
|
|
|
13
18
|
export class DatabaseRoot {
|
|
19
|
+
static mapLinks(doc: DocHandle<SpaceDoc>, mapping: Record<DocumentId, DocumentId>): void {
|
|
20
|
+
doc.change((d) => {
|
|
21
|
+
if (!d.links) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (const [key, value] of Object.entries(d.links)) {
|
|
25
|
+
const documentId = interpretAsDocumentId(value.toString() as any);
|
|
26
|
+
if (mapping[documentId]) {
|
|
27
|
+
d.links[key] = `automerge:${mapping[documentId]}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
14
33
|
constructor(private readonly _rootHandle: DocHandle<SpaceDoc>) {}
|
|
15
34
|
|
|
16
35
|
get documentId(): DocumentId {
|
package/src/db-host/echo-host.ts
CHANGED
|
@@ -206,6 +206,10 @@ export class EchoHost extends Resource {
|
|
|
206
206
|
return await this._automergeHost.loadDoc(ctx, documentId, opts);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
async exportDoc(ctx: Context, id: AnyDocumentId): Promise<Uint8Array> {
|
|
210
|
+
return await this._automergeHost.exportDoc(ctx, id);
|
|
211
|
+
}
|
|
212
|
+
|
|
209
213
|
/**
|
|
210
214
|
* Create new persisted document.
|
|
211
215
|
*/
|