@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.
@@ -199,13 +199,14 @@ var DocumentsSynchronizer = class extends Resource {
199
199
  // packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
200
200
  import { Event as Event2, asyncTimeout } from "@dxos/async";
201
201
  import { getBackend, getHeads, isAutomerge, equals as headsEquals, save } from "@dxos/automerge/automerge";
202
- import { Repo } from "@dxos/automerge/automerge-repo";
202
+ import { Repo, interpretAsDocumentId } from "@dxos/automerge/automerge-repo";
203
203
  import { Context, Resource as Resource4, cancelWithContext } from "@dxos/context";
204
204
  import { invariant as invariant3 } from "@dxos/invariant";
205
205
  import { PublicKey } from "@dxos/keys";
206
206
  import { log as log4 } from "@dxos/log";
207
207
  import { objectPointerCodec } from "@dxos/protocols";
208
208
  import { trace } from "@dxos/tracing";
209
+ import { bufferToArray } from "@dxos/util";
209
210
 
210
211
  // packages/core/echo/echo-pipeline/src/automerge/collection-synchronizer.ts
211
212
  import { asyncReturn, Event, scheduleTask, scheduleTaskInterval } from "@dxos/async";
@@ -1027,16 +1028,29 @@ var AutomergeHost = class extends Resource4 {
1027
1028
  }
1028
1029
  return handle;
1029
1030
  }
1031
+ async exportDoc(ctx, id) {
1032
+ const documentId = interpretAsDocumentId(id);
1033
+ const chunks = await this._storage.loadRange([
1034
+ documentId
1035
+ ]);
1036
+ return bufferToArray(Buffer.concat(chunks.map((c) => c.data)));
1037
+ }
1030
1038
  /**
1031
1039
  * Create new persisted document.
1032
1040
  */
1033
1041
  createDoc(initialValue, opts) {
1034
1042
  if (opts?.preserveHistory) {
1043
+ if (initialValue instanceof Uint8Array) {
1044
+ return this._repo.import(initialValue);
1045
+ }
1035
1046
  if (!isAutomerge(initialValue)) {
1036
1047
  throw new TypeError("Initial value must be an Automerge document");
1037
1048
  }
1038
1049
  return this._repo.import(save(initialValue));
1039
1050
  } else {
1051
+ if (initialValue instanceof Uint8Array) {
1052
+ throw new Error("Cannot create document from Uint8Array without preserving history");
1053
+ }
1040
1054
  return this._repo.create(initialValue);
1041
1055
  }
1042
1056
  }
@@ -1059,7 +1073,7 @@ var AutomergeHost = class extends Resource4 {
1059
1073
  await Promise.all(headsToWait.map(async (entry, index) => {
1060
1074
  const handle = await this.loadDoc(Context.default(void 0, {
1061
1075
  F: __dxlog_file4,
1062
- L: 264
1076
+ L: 282
1063
1077
  }), entry.documentId);
1064
1078
  await waitForHeads(handle, entry.heads);
1065
1079
  }));
@@ -1072,7 +1086,7 @@ var AutomergeHost = class extends Resource4 {
1072
1086
  documentId
1073
1087
  }, {
1074
1088
  F: __dxlog_file4,
1075
- L: 276,
1089
+ L: 294,
1076
1090
  S: this,
1077
1091
  C: (f, a) => f(...a)
1078
1092
  });
@@ -1088,7 +1102,7 @@ var AutomergeHost = class extends Resource4 {
1088
1102
  documentId
1089
1103
  }, {
1090
1104
  F: __dxlog_file4,
1091
- L: 280,
1105
+ L: 298,
1092
1106
  S: this,
1093
1107
  C: (f, a) => f(...a)
1094
1108
  });
@@ -1097,7 +1111,7 @@ var AutomergeHost = class extends Resource4 {
1097
1111
  const doc = handle.docSync();
1098
1112
  invariant3(doc, void 0, {
1099
1113
  F: __dxlog_file4,
1100
- L: 285,
1114
+ L: 303,
1101
1115
  S: this,
1102
1116
  A: [
1103
1117
  "doc",
@@ -1111,7 +1125,7 @@ var AutomergeHost = class extends Resource4 {
1111
1125
  }
1112
1126
  log4.info("done re-indexing heads", void 0, {
1113
1127
  F: __dxlog_file4,
1114
- L: 292,
1128
+ L: 310,
1115
1129
  S: this,
1116
1130
  C: (f, a) => f(...a)
1117
1131
  });
@@ -1326,7 +1340,7 @@ var AutomergeHost = class extends Resource4 {
1326
1340
  count: toReplicate.length
1327
1341
  }, {
1328
1342
  F: __dxlog_file4,
1329
- L: 531,
1343
+ L: 549,
1330
1344
  S: this,
1331
1345
  C: (f, a) => f(...a)
1332
1346
  });
@@ -1393,7 +1407,7 @@ var changeIsPresentInDoc = (doc, changeHash) => {
1393
1407
  var decodeCollectionState = (state) => {
1394
1408
  invariant3(typeof state === "object" && state !== null, "Invalid state", {
1395
1409
  F: __dxlog_file4,
1396
- L: 592,
1410
+ L: 610,
1397
1411
  S: void 0,
1398
1412
  A: [
1399
1413
  "typeof state === 'object' && state !== null",
@@ -2756,10 +2770,11 @@ var createDocumentsIterator = (automergeHost) => (
2756
2770
  // packages/core/echo/echo-pipeline/src/db-host/space-state-manager.ts
2757
2771
  import isEqual from "lodash.isequal";
2758
2772
  import { Event as Event3, UpdateScheduler as UpdateScheduler3 } from "@dxos/async";
2759
- import { interpretAsDocumentId } from "@dxos/automerge/automerge-repo";
2773
+ import { interpretAsDocumentId as interpretAsDocumentId3 } from "@dxos/automerge/automerge-repo";
2760
2774
  import { Resource as Resource8, Context as Context5 } from "@dxos/context";
2761
2775
 
2762
2776
  // packages/core/echo/echo-pipeline/src/db-host/database-root.ts
2777
+ import { interpretAsDocumentId as interpretAsDocumentId2 } from "@dxos/automerge/automerge-repo";
2763
2778
  import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
2764
2779
  import { invariant as invariant10 } from "@dxos/invariant";
2765
2780
 
@@ -2796,6 +2811,19 @@ var measureDocMetrics = (doc) => {
2796
2811
  // packages/core/echo/echo-pipeline/src/db-host/database-root.ts
2797
2812
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/database-root.ts";
2798
2813
  var DatabaseRoot = class {
2814
+ static mapLinks(doc, mapping) {
2815
+ doc.change((d) => {
2816
+ if (!d.links) {
2817
+ return;
2818
+ }
2819
+ for (const [key, value] of Object.entries(d.links)) {
2820
+ const documentId = interpretAsDocumentId2(value.toString());
2821
+ if (mapping[documentId]) {
2822
+ d.links[key] = `automerge:${mapping[documentId]}`;
2823
+ }
2824
+ }
2825
+ });
2826
+ }
2799
2827
  constructor(_rootHandle) {
2800
2828
  this._rootHandle = _rootHandle;
2801
2829
  }
@@ -2846,7 +2874,7 @@ var DatabaseRoot = class {
2846
2874
  const doc = this.docSync();
2847
2875
  invariant10(doc, void 0, {
2848
2876
  F: __dxlog_file13,
2849
- L: 74,
2877
+ L: 93,
2850
2878
  S: this,
2851
2879
  A: [
2852
2880
  "doc",
@@ -2916,7 +2944,7 @@ var SpaceStateManager = class extends Resource8 {
2916
2944
  const documentListCheckScheduler = new UpdateScheduler3(ctx, async () => {
2917
2945
  const documentIds = [
2918
2946
  root.documentId,
2919
- ...root.getAllLinkedDocuments().map((url) => interpretAsDocumentId(url))
2947
+ ...root.getAllLinkedDocuments().map((url) => interpretAsDocumentId3(url))
2920
2948
  ];
2921
2949
  if (!isEqual(documentIds, this._lastSpaceDocumentList.get(spaceId))) {
2922
2950
  this._lastSpaceDocumentList.set(spaceId, documentIds);
@@ -3077,6 +3105,9 @@ var EchoHost = class extends Resource9 {
3077
3105
  async loadDoc(ctx, documentId, opts) {
3078
3106
  return await this._automergeHost.loadDoc(ctx, documentId, opts);
3079
3107
  }
3108
+ async exportDoc(ctx, id) {
3109
+ return await this._automergeHost.exportDoc(ctx, id);
3110
+ }
3080
3111
  /**
3081
3112
  * Create new persisted document.
3082
3113
  */
@@ -3089,7 +3120,7 @@ var EchoHost = class extends Resource9 {
3089
3120
  async createSpaceRoot(spaceKey) {
3090
3121
  invariant11(this._lifecycleState === LifecycleState4.OPEN, void 0, {
3091
3122
  F: __dxlog_file15,
3092
- L: 220,
3123
+ L: 224,
3093
3124
  S: this,
3094
3125
  A: [
3095
3126
  "this._lifecycleState === LifecycleState.OPEN",
@@ -3117,7 +3148,7 @@ var EchoHost = class extends Resource9 {
3117
3148
  async openSpaceRoot(spaceId, automergeUrl) {
3118
3149
  invariant11(this._lifecycleState === LifecycleState4.OPEN, void 0, {
3119
3150
  F: __dxlog_file15,
3120
- L: 239,
3151
+ L: 243,
3121
3152
  S: this,
3122
3153
  A: [
3123
3154
  "this._lifecycleState === LifecycleState.OPEN",
@@ -3155,7 +3186,7 @@ import { log as log12 } from "@dxos/log";
3155
3186
  import { EdgeService } from "@dxos/protocols";
3156
3187
  import { buf } from "@dxos/protocols/buf";
3157
3188
  import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
3158
- import { bufferToArray } from "@dxos/util";
3189
+ import { bufferToArray as bufferToArray2 } from "@dxos/util";
3159
3190
 
3160
3191
  // packages/core/echo/echo-pipeline/src/edge/inflight-request-limiter.ts
3161
3192
  import { Trigger as Trigger2 } from "@dxos/async";
@@ -3597,7 +3628,7 @@ var EdgeReplicatorConnection = class extends Resource11 {
3597
3628
  peerKey: this._edgeConnection.peerKey
3598
3629
  },
3599
3630
  payload: {
3600
- value: bufferToArray(encoded)
3631
+ value: bufferToArray2(encoded)
3601
3632
  }
3602
3633
  }));
3603
3634
  }