@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
package/dist/lib/node/index.cjs
CHANGED
|
@@ -90,24 +90,25 @@ var import_keys2 = require("@dxos/keys");
|
|
|
90
90
|
var import_log3 = require("@dxos/log");
|
|
91
91
|
var import_protocols = require("@dxos/protocols");
|
|
92
92
|
var import_tracing = require("@dxos/tracing");
|
|
93
|
+
var import_util = require("@dxos/util");
|
|
93
94
|
var import_async4 = require("@dxos/async");
|
|
94
95
|
var import_automerge3 = require("@dxos/automerge/automerge");
|
|
95
96
|
var import_context3 = require("@dxos/context");
|
|
96
97
|
var import_log4 = require("@dxos/log");
|
|
97
|
-
var
|
|
98
|
+
var import_util2 = require("@dxos/util");
|
|
98
99
|
var import_async5 = require("@dxos/async");
|
|
99
100
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
100
101
|
var import_context4 = require("@dxos/context");
|
|
101
102
|
var import_invariant4 = require("@dxos/invariant");
|
|
102
103
|
var import_log5 = require("@dxos/log");
|
|
103
|
-
var
|
|
104
|
+
var import_util3 = require("@dxos/util");
|
|
104
105
|
var import_protocols2 = require("@dxos/protocols");
|
|
105
106
|
var import_indexing = require("@dxos/indexing");
|
|
106
107
|
var import_context5 = require("@dxos/context");
|
|
107
108
|
var import_invariant5 = require("@dxos/invariant");
|
|
108
109
|
var import_keys3 = require("@dxos/keys");
|
|
109
110
|
var import_log6 = require("@dxos/log");
|
|
110
|
-
var
|
|
111
|
+
var import_util4 = require("@dxos/util");
|
|
111
112
|
var A2 = __toESM(require("@dxos/automerge/automerge"));
|
|
112
113
|
var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
113
114
|
var import_context6 = require("@dxos/context");
|
|
@@ -117,7 +118,7 @@ var import_teleport_extension_automerge_replicator = require("@dxos/teleport-ext
|
|
|
117
118
|
var import_invariant7 = require("@dxos/invariant");
|
|
118
119
|
var import_keys4 = require("@dxos/keys");
|
|
119
120
|
var import_tracing2 = require("@dxos/tracing");
|
|
120
|
-
var
|
|
121
|
+
var import_util5 = require("@dxos/util");
|
|
121
122
|
var import_context7 = require("@dxos/context");
|
|
122
123
|
var import_debug = require("@dxos/debug");
|
|
123
124
|
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
@@ -144,17 +145,18 @@ var import_invariant10 = require("@dxos/invariant");
|
|
|
144
145
|
var import_keys5 = require("@dxos/keys");
|
|
145
146
|
var import_protocols5 = require("@dxos/protocols");
|
|
146
147
|
var import_tracing5 = require("@dxos/tracing");
|
|
147
|
-
var
|
|
148
|
+
var import_util6 = require("@dxos/util");
|
|
148
149
|
var import_lodash = __toESM(require("lodash.isequal"));
|
|
149
150
|
var import_async7 = require("@dxos/async");
|
|
150
151
|
var import_automerge_repo4 = require("@dxos/automerge/automerge-repo");
|
|
151
152
|
var import_context11 = require("@dxos/context");
|
|
153
|
+
var import_automerge_repo5 = require("@dxos/automerge/automerge-repo");
|
|
152
154
|
var import_echo_protocol4 = require("@dxos/echo-protocol");
|
|
153
155
|
var import_invariant11 = require("@dxos/invariant");
|
|
154
156
|
var A4 = __toESM(require("@dxos/automerge/automerge"));
|
|
155
157
|
var import_log10 = require("@dxos/log");
|
|
156
158
|
var import_async8 = require("@dxos/async");
|
|
157
|
-
var
|
|
159
|
+
var import_automerge_repo6 = require("@dxos/automerge/automerge-repo");
|
|
158
160
|
var import_context12 = require("@dxos/context");
|
|
159
161
|
var import_crypto = require("@dxos/crypto");
|
|
160
162
|
var import_invariant12 = require("@dxos/invariant");
|
|
@@ -162,7 +164,7 @@ var import_log11 = require("@dxos/log");
|
|
|
162
164
|
var import_protocols6 = require("@dxos/protocols");
|
|
163
165
|
var import_buf = require("@dxos/protocols/buf");
|
|
164
166
|
var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
|
|
165
|
-
var
|
|
167
|
+
var import_util7 = require("@dxos/util");
|
|
166
168
|
var import_async9 = require("@dxos/async");
|
|
167
169
|
var import_context13 = require("@dxos/context");
|
|
168
170
|
var import_log12 = require("@dxos/log");
|
|
@@ -476,7 +478,7 @@ var CollectionSynchronizer = class extends import_context3.Resource {
|
|
|
476
478
|
}
|
|
477
479
|
}
|
|
478
480
|
_getOrCreatePerCollectionState(collectionId) {
|
|
479
|
-
return (0,
|
|
481
|
+
return (0, import_util2.defaultMap)(this._perCollectionStates, collectionId, () => ({
|
|
480
482
|
localState: void 0,
|
|
481
483
|
remoteStates: /* @__PURE__ */ new Map(),
|
|
482
484
|
interestedPeers: /* @__PURE__ */ new Set(),
|
|
@@ -711,7 +713,7 @@ var EchoNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
|
711
713
|
return connection.connection.shouldSyncCollection({
|
|
712
714
|
collectionId
|
|
713
715
|
}) ? connection.connection.peerId : null;
|
|
714
|
-
}).filter(
|
|
716
|
+
}).filter(import_util3.isNonNullable);
|
|
715
717
|
}
|
|
716
718
|
_onConnectionOpen(connection) {
|
|
717
719
|
(0, import_log5.log)("Connection opened", {
|
|
@@ -1116,16 +1118,29 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1116
1118
|
}
|
|
1117
1119
|
return handle;
|
|
1118
1120
|
}
|
|
1121
|
+
async exportDoc(ctx, id) {
|
|
1122
|
+
const documentId = (0, import_automerge_repo.interpretAsDocumentId)(id);
|
|
1123
|
+
const chunks = await this._storage.loadRange([
|
|
1124
|
+
documentId
|
|
1125
|
+
]);
|
|
1126
|
+
return (0, import_util.bufferToArray)(Buffer.concat(chunks.map((c) => c.data)));
|
|
1127
|
+
}
|
|
1119
1128
|
/**
|
|
1120
1129
|
* Create new persisted document.
|
|
1121
1130
|
*/
|
|
1122
1131
|
createDoc(initialValue, opts) {
|
|
1123
1132
|
if (opts?.preserveHistory) {
|
|
1133
|
+
if (initialValue instanceof Uint8Array) {
|
|
1134
|
+
return this._repo.import(initialValue);
|
|
1135
|
+
}
|
|
1124
1136
|
if (!(0, import_automerge2.isAutomerge)(initialValue)) {
|
|
1125
1137
|
throw new TypeError("Initial value must be an Automerge document");
|
|
1126
1138
|
}
|
|
1127
1139
|
return this._repo.import((0, import_automerge2.save)(initialValue));
|
|
1128
1140
|
} else {
|
|
1141
|
+
if (initialValue instanceof Uint8Array) {
|
|
1142
|
+
throw new Error("Cannot create document from Uint8Array without preserving history");
|
|
1143
|
+
}
|
|
1129
1144
|
return this._repo.create(initialValue);
|
|
1130
1145
|
}
|
|
1131
1146
|
}
|
|
@@ -1148,7 +1163,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1148
1163
|
await Promise.all(headsToWait.map(async (entry, index) => {
|
|
1149
1164
|
const handle = await this.loadDoc(import_context2.Context.default(void 0, {
|
|
1150
1165
|
F: __dxlog_file4,
|
|
1151
|
-
L:
|
|
1166
|
+
L: 282
|
|
1152
1167
|
}), entry.documentId);
|
|
1153
1168
|
await waitForHeads(handle, entry.heads);
|
|
1154
1169
|
}));
|
|
@@ -1161,7 +1176,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1161
1176
|
documentId
|
|
1162
1177
|
}, {
|
|
1163
1178
|
F: __dxlog_file4,
|
|
1164
|
-
L:
|
|
1179
|
+
L: 294,
|
|
1165
1180
|
S: this,
|
|
1166
1181
|
C: (f, a) => f(...a)
|
|
1167
1182
|
});
|
|
@@ -1177,7 +1192,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1177
1192
|
documentId
|
|
1178
1193
|
}, {
|
|
1179
1194
|
F: __dxlog_file4,
|
|
1180
|
-
L:
|
|
1195
|
+
L: 298,
|
|
1181
1196
|
S: this,
|
|
1182
1197
|
C: (f, a) => f(...a)
|
|
1183
1198
|
});
|
|
@@ -1186,7 +1201,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1186
1201
|
const doc = handle.docSync();
|
|
1187
1202
|
(0, import_invariant3.invariant)(doc, void 0, {
|
|
1188
1203
|
F: __dxlog_file4,
|
|
1189
|
-
L:
|
|
1204
|
+
L: 303,
|
|
1190
1205
|
S: this,
|
|
1191
1206
|
A: [
|
|
1192
1207
|
"doc",
|
|
@@ -1200,7 +1215,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1200
1215
|
}
|
|
1201
1216
|
import_log3.log.info("done re-indexing heads", void 0, {
|
|
1202
1217
|
F: __dxlog_file4,
|
|
1203
|
-
L:
|
|
1218
|
+
L: 310,
|
|
1204
1219
|
S: this,
|
|
1205
1220
|
C: (f, a) => f(...a)
|
|
1206
1221
|
});
|
|
@@ -1415,7 +1430,7 @@ var AutomergeHost = class extends import_context2.Resource {
|
|
|
1415
1430
|
count: toReplicate.length
|
|
1416
1431
|
}, {
|
|
1417
1432
|
F: __dxlog_file4,
|
|
1418
|
-
L:
|
|
1433
|
+
L: 549,
|
|
1419
1434
|
S: this,
|
|
1420
1435
|
C: (f, a) => f(...a)
|
|
1421
1436
|
});
|
|
@@ -1482,7 +1497,7 @@ var changeIsPresentInDoc = (doc, changeHash) => {
|
|
|
1482
1497
|
var decodeCollectionState = (state) => {
|
|
1483
1498
|
(0, import_invariant3.invariant)(typeof state === "object" && state !== null, "Invalid state", {
|
|
1484
1499
|
F: __dxlog_file4,
|
|
1485
|
-
L:
|
|
1500
|
+
L: 610,
|
|
1486
1501
|
S: void 0,
|
|
1487
1502
|
A: [
|
|
1488
1503
|
"typeof state === 'object' && state !== null",
|
|
@@ -1832,7 +1847,7 @@ var MeshEchoReplicator = class {
|
|
|
1832
1847
|
C: (f, a) => f(...a)
|
|
1833
1848
|
});
|
|
1834
1849
|
const spaceId = await (0, import_chunk_TC2PRBEU.createIdFromSpaceKey)(spaceKey);
|
|
1835
|
-
(0,
|
|
1850
|
+
(0, import_util4.defaultMap)(this._authorizedDevices, spaceId, () => new import_util4.ComplexSet(import_keys3.PublicKey.hash)).add(deviceKey);
|
|
1836
1851
|
for (const connection of this._connections) {
|
|
1837
1852
|
if (connection.remoteDeviceKey && connection.remoteDeviceKey.equals(deviceKey)) {
|
|
1838
1853
|
if (this._connectionsPerPeer.has(connection.peerId)) {
|
|
@@ -1861,8 +1876,8 @@ var EchoDataMonitor = class {
|
|
|
1861
1876
|
this._storageAverages = createStorageAverages();
|
|
1862
1877
|
this._replicationAverages = createNetworkAverages();
|
|
1863
1878
|
this._sizeByMessageType = {};
|
|
1864
|
-
this._lastReceivedMessages = new
|
|
1865
|
-
this._lastSentMessages = new
|
|
1879
|
+
this._lastReceivedMessages = new import_util5.CircularBuffer(100);
|
|
1880
|
+
this._lastSentMessages = new import_util5.CircularBuffer(100);
|
|
1866
1881
|
this._connectionsCount = 0;
|
|
1867
1882
|
}
|
|
1868
1883
|
tick(timeMs) {
|
|
@@ -1899,7 +1914,7 @@ var EchoDataMonitor = class {
|
|
|
1899
1914
|
failedPerSecond: this._replicationAverages.sendsFailedPerSecond.average()
|
|
1900
1915
|
},
|
|
1901
1916
|
countByMessageType: this._computeMessageHistogram("type"),
|
|
1902
|
-
avgSizeByMessageType: (0,
|
|
1917
|
+
avgSizeByMessageType: (0, import_util5.mapValues)(this._sizeByMessageType, (summary) => summary.average())
|
|
1903
1918
|
}
|
|
1904
1919
|
};
|
|
1905
1920
|
}
|
|
@@ -2136,7 +2151,7 @@ EchoDataMonitor = _ts_decorate3([
|
|
|
2136
2151
|
var isAutomergeProtocolMessage = (message) => {
|
|
2137
2152
|
return !(isCollectionQueryMessage(message) || isCollectionStateMessage(message));
|
|
2138
2153
|
};
|
|
2139
|
-
var createSlidingWindow = (overrides) => new
|
|
2154
|
+
var createSlidingWindow = (overrides) => new import_util5.SlidingWindowSummary({
|
|
2140
2155
|
dataPoints: DEFAULT_AVG_WINDOW_SIZE,
|
|
2141
2156
|
precision: 2,
|
|
2142
2157
|
...overrides
|
|
@@ -2490,7 +2505,7 @@ var QueryState = class extends import_context10.Resource {
|
|
|
2490
2505
|
spaceKey: import_keys5.PublicKey.from(spaceKey),
|
|
2491
2506
|
rank: result.rank
|
|
2492
2507
|
};
|
|
2493
|
-
}))).filter(
|
|
2508
|
+
}))).filter(import_util6.isNonNullable);
|
|
2494
2509
|
if (this._firstRun) {
|
|
2495
2510
|
this.metrics.documentLoadTime = performance.now() - beginFilter;
|
|
2496
2511
|
}
|
|
@@ -2559,7 +2574,7 @@ var filterToIndexQuery = (filter) => {
|
|
|
2559
2574
|
});
|
|
2560
2575
|
if (filter.type || (filter.or ?? []).length > 0 && (filter.or ?? []).every((subFilter) => !subFilter.not && subFilter.type)) {
|
|
2561
2576
|
return {
|
|
2562
|
-
typenames: filter.type && filter.type.length > 0 ? filter.type.map((type) => dxnToIndexerTypename(import_keys5.DXN.parse(type))) : (filter.or ?? []).flatMap((f) => f.type?.map((type) => dxnToIndexerTypename(import_keys5.DXN.parse(type))) ?? []).filter(
|
|
2577
|
+
typenames: filter.type && filter.type.length > 0 ? filter.type.map((type) => dxnToIndexerTypename(import_keys5.DXN.parse(type))) : (filter.or ?? []).flatMap((f) => f.type?.map((type) => dxnToIndexerTypename(import_keys5.DXN.parse(type))) ?? []).filter(import_util6.isNonNullable),
|
|
2563
2578
|
inverted: filter.not
|
|
2564
2579
|
};
|
|
2565
2580
|
} else {
|
|
@@ -2796,6 +2811,19 @@ var measureDocMetrics = (doc) => {
|
|
|
2796
2811
|
};
|
|
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 = (0, import_automerge_repo5.interpretAsDocumentId)(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
|
(0, import_invariant11.invariant)(doc, void 0, {
|
|
2848
2876
|
F: __dxlog_file13,
|
|
2849
|
-
L:
|
|
2877
|
+
L: 93,
|
|
2850
2878
|
S: this,
|
|
2851
2879
|
A: [
|
|
2852
2880
|
"doc",
|
|
@@ -3073,6 +3101,9 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3073
3101
|
async loadDoc(ctx, documentId, opts) {
|
|
3074
3102
|
return await this._automergeHost.loadDoc(ctx, documentId, opts);
|
|
3075
3103
|
}
|
|
3104
|
+
async exportDoc(ctx, id) {
|
|
3105
|
+
return await this._automergeHost.exportDoc(ctx, id);
|
|
3106
|
+
}
|
|
3076
3107
|
/**
|
|
3077
3108
|
* Create new persisted document.
|
|
3078
3109
|
*/
|
|
@@ -3085,7 +3116,7 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3085
3116
|
async createSpaceRoot(spaceKey) {
|
|
3086
3117
|
(0, import_invariant8.invariant)(this._lifecycleState === import_context7.LifecycleState.OPEN, void 0, {
|
|
3087
3118
|
F: __dxlog_file15,
|
|
3088
|
-
L:
|
|
3119
|
+
L: 224,
|
|
3089
3120
|
S: this,
|
|
3090
3121
|
A: [
|
|
3091
3122
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -3113,7 +3144,7 @@ var EchoHost = class extends import_context7.Resource {
|
|
|
3113
3144
|
async openSpaceRoot(spaceId, automergeUrl) {
|
|
3114
3145
|
(0, import_invariant8.invariant)(this._lifecycleState === import_context7.LifecycleState.OPEN, void 0, {
|
|
3115
3146
|
F: __dxlog_file15,
|
|
3116
|
-
L:
|
|
3147
|
+
L: 243,
|
|
3117
3148
|
S: this,
|
|
3118
3149
|
A: [
|
|
3119
3150
|
"this._lifecycleState === LifecycleState.OPEN",
|
|
@@ -3532,7 +3563,7 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3532
3563
|
if (message.serviceId !== this._targetServiceId) {
|
|
3533
3564
|
return;
|
|
3534
3565
|
}
|
|
3535
|
-
const payload =
|
|
3566
|
+
const payload = import_automerge_repo6.cbor.decode(message.payload.value);
|
|
3536
3567
|
import_log11.log.verbose("edge replicator receive", {
|
|
3537
3568
|
type: payload.type,
|
|
3538
3569
|
documentId: payload.type === "sync" && payload.documentId,
|
|
@@ -3566,7 +3597,7 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3566
3597
|
S: this,
|
|
3567
3598
|
C: (f, a) => f(...a)
|
|
3568
3599
|
});
|
|
3569
|
-
const encoded =
|
|
3600
|
+
const encoded = import_automerge_repo6.cbor.encode(message);
|
|
3570
3601
|
await this._edgeConnection.send(import_buf.buf.create(import_messenger_pb.MessageSchema, {
|
|
3571
3602
|
serviceId: this._targetServiceId,
|
|
3572
3603
|
source: {
|
|
@@ -3574,7 +3605,7 @@ var EdgeReplicatorConnection = class extends import_context12.Resource {
|
|
|
3574
3605
|
peerKey: this._edgeConnection.peerKey
|
|
3575
3606
|
},
|
|
3576
3607
|
payload: {
|
|
3577
|
-
value: (0,
|
|
3608
|
+
value: (0, import_util7.bufferToArray)(encoded)
|
|
3578
3609
|
}
|
|
3579
3610
|
}));
|
|
3580
3611
|
}
|