@dxos/echo-pipeline 0.8.2 → 0.8.3-main.672df60

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.
@@ -430,7 +430,7 @@ describe('AutomergeRepo', () => {
430
430
  let clientDoc = A.from<{ field?: string }>({});
431
431
  const { documentId } = parseAutomergeUrl(generateAutomergeUrl());
432
432
  // Sync handshake.
433
- let sentHeads = getHeads(clientDoc);
433
+ let sentHeads: Heads = [];
434
434
 
435
435
  // Sync protocol.
436
436
  const sendDoc = async (doc: A.Doc<any>) => {
@@ -451,6 +451,50 @@ describe('AutomergeRepo', () => {
451
451
  }
452
452
  });
453
453
 
454
+ test('client creates doc and Repo persists it to disk', async () => {
455
+ const storage = await createLevelAdapter();
456
+
457
+ const repo = new Repo({ network: [], storage });
458
+ const receiveByServer = async (blob: Uint8Array, docId: DocumentId) => {
459
+ const serverHandle = await repo.find(docId, FIND_PARAMS);
460
+ serverHandle.update((doc) => {
461
+ return A.loadIncremental(doc, blob);
462
+ });
463
+ };
464
+
465
+ let clientDoc = A.from<{ field?: string }>({ field: 'foo' });
466
+ const { documentId } = parseAutomergeUrl(generateAutomergeUrl());
467
+ // Sync handshake.
468
+ let sentHeads: Heads = [];
469
+
470
+ // Sync protocol.
471
+ const sendDoc = async (doc: A.Doc<any>) => {
472
+ await receiveByServer(saveSince(doc, sentHeads), documentId);
473
+ sentHeads = getHeads(doc);
474
+ };
475
+
476
+ // Change doc and send changes to server.
477
+ const value = 'text to test if sync works';
478
+ {
479
+ clientDoc = A.change(clientDoc, (doc: any) => {
480
+ doc.field = value;
481
+ });
482
+ await sendDoc(clientDoc);
483
+
484
+ const serverHandle = await repo.find<any>(documentId);
485
+ expect(serverHandle.doc()!.field).to.deep.equal(value);
486
+ }
487
+
488
+ await sleep(100);
489
+
490
+ // Re-open repo.
491
+ {
492
+ const repo = new Repo({ network: [], storage });
493
+ const serverHandle = await repo.find<any>(documentId);
494
+ expect(serverHandle.doc()!.field).to.deep.equal(value);
495
+ }
496
+ });
497
+
454
498
  test('two repo sync docs on `update` call', async () => {
455
499
  const { repos, adapters } = await createHostClientRepoTopology();
456
500
  const [repoA, repoB] = repos;
@@ -92,7 +92,7 @@ export class DataServiceImpl implements DataService {
92
92
  const synchronizer = this._subscriptions.get(request.subscriptionId);
93
93
  invariant(synchronizer, 'Subscription not found');
94
94
 
95
- synchronizer.update(request.updates);
95
+ await synchronizer.update(request.updates);
96
96
  }
97
97
 
98
98
  async flush(request: FlushRequest): Promise<void> {
@@ -23,7 +23,7 @@ describe('DocumentsSynchronizer', () => {
23
23
  });
24
24
  await openAndClose(synchronizer);
25
25
 
26
- synchronizer.update([
26
+ await synchronizer.update([
27
27
  {
28
28
  documentId: parseAutomergeUrl(generateAutomergeUrl()).documentId,
29
29
  mutation: A.save(A.from({ text: 'hello' })),
@@ -12,6 +12,8 @@ import { invariant } from '@dxos/invariant';
12
12
  import { log } from '@dxos/log';
13
13
  import { type BatchedDocumentUpdates, type DocumentUpdate } from '@dxos/protocols/proto/dxos/echo/service';
14
14
 
15
+ import { FIND_PARAMS } from '../automerge';
16
+
15
17
  const MAX_UPDATE_FREQ = 10; // [updates/sec]
16
18
 
17
19
  export type DocumentsSynchronizerParams = {
@@ -86,10 +88,10 @@ export class DocumentsSynchronizer extends Resource {
86
88
  this._syncStates.clear();
87
89
  }
88
90
 
89
- update(updates: DocumentUpdate[]): void {
91
+ async update(updates: DocumentUpdate[]): Promise<void> {
90
92
  for (const { documentId, mutation, isNew } of updates) {
91
93
  if (isNew) {
92
- const { handle: doc } = this._params.repo.findWithProgress<DatabaseDirectory>(documentId as DocumentId);
94
+ const doc = await this._params.repo.find<DatabaseDirectory>(documentId as DocumentId, FIND_PARAMS);
93
95
  doc.update((doc) => A.loadIncremental(doc, mutation));
94
96
  this._startSync(doc);
95
97
  } else {
@@ -97,6 +97,8 @@ type StepExecutionResult = {
97
97
  trace: ExecutionTrace;
98
98
  };
99
99
 
100
+ const TRACE_QUERY_EXECUTION = false;
101
+
100
102
  /**
101
103
  * Executes query plans against the Indexer and AutomergeHost.
102
104
  *
@@ -186,12 +188,10 @@ export class QueryExecutor extends Resource {
186
188
  workingSet[index].documentId !== item.documentId,
187
189
  );
188
190
 
189
- // log.info('Query execution result', {
190
- // changed,
191
- // trace: ExecutionTrace.format(trace),
192
- // });
193
- // eslint-disable-next-line no-console
194
- // console.log(ExecutionTrace.format(trace));
191
+ if (TRACE_QUERY_EXECUTION) {
192
+ // eslint-disable-next-line no-console
193
+ console.log(ExecutionTrace.format(trace));
194
+ }
195
195
 
196
196
  return {
197
197
  changed,