@dxos/echo-pipeline 0.5.0 → 0.5.1-main.0ba1ecb
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/{chunk-KMWJLYEQ.mjs → chunk-VQQD32DM.mjs} +18 -18
- package/dist/lib/browser/{chunk-KMWJLYEQ.mjs.map → chunk-VQQD32DM.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +471 -189
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -8
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-YZA42CKA.cjs → chunk-P7L7ICAH.cjs} +21 -21
- package/dist/lib/node/{chunk-YZA42CKA.cjs.map → chunk-P7L7ICAH.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +482 -207
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -18
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-doc-loader.d.ts +3 -3
- package/dist/types/src/automerge/automerge-doc-loader.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +15 -6
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +26 -0
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -0
- package/dist/types/src/automerge/echo-replicator.d.ts +43 -0
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -0
- package/dist/types/src/automerge/index.d.ts +1 -2
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +3 -2
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/migrations.d.ts +1 -1
- package/dist/types/src/automerge/migrations.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts +1 -1
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/package.json +33 -30
- package/src/automerge/automerge-doc-loader.test.ts +1 -1
- package/src/automerge/automerge-doc-loader.ts +26 -16
- package/src/automerge/automerge-host.test.ts +33 -16
- package/src/automerge/automerge-host.ts +105 -21
- package/src/automerge/automerge-repo.test.ts +38 -6
- package/src/automerge/echo-network-adapter.ts +155 -0
- package/src/automerge/echo-replicator.ts +56 -0
- package/src/automerge/index.ts +1 -2
- package/src/automerge/leveldb-storage-adapter.ts +2 -2
- package/src/automerge/migrations.ts +1 -1
- package/src/automerge/storage-adapter.test.ts +1 -1
- package/src/pipeline/pipeline.ts +1 -0
- package/src/space/control-pipeline.ts +2 -2
- package/src/testing/index.ts +0 -1
- package/dist/types/src/automerge/level.test.d.ts +0 -2
- package/dist/types/src/automerge/level.test.d.ts.map +0 -1
- package/dist/types/src/automerge/reference.d.ts +0 -15
- package/dist/types/src/automerge/reference.d.ts.map +0 -1
- package/dist/types/src/automerge/types.d.ts +0 -73
- package/dist/types/src/automerge/types.d.ts.map +0 -1
- package/dist/types/src/testing/level.d.ts +0 -3
- package/dist/types/src/testing/level.d.ts.map +0 -1
- package/src/automerge/level.test.ts +0 -82
- package/src/automerge/reference.ts +0 -31
- package/src/automerge/types.ts +0 -86
- package/src/testing/level.ts +0 -11
|
@@ -22,20 +22,243 @@ import {
|
|
|
22
22
|
mapTimeframeToFeedIndexes,
|
|
23
23
|
startAfter,
|
|
24
24
|
valueEncoding
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-VQQD32DM.mjs";
|
|
26
26
|
|
|
27
27
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
28
|
-
import {
|
|
29
|
-
import { next as automerge } from "@dxos/automerge/automerge";
|
|
28
|
+
import { Event } from "@dxos/async";
|
|
29
|
+
import { next as automerge, getBackend, getHeads } from "@dxos/automerge/automerge";
|
|
30
30
|
import { Repo } from "@dxos/automerge/automerge-repo";
|
|
31
31
|
import { Context } from "@dxos/context";
|
|
32
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
32
33
|
import { PublicKey } from "@dxos/keys";
|
|
33
|
-
import { log as
|
|
34
|
+
import { log as log4 } from "@dxos/log";
|
|
35
|
+
import { idCodec } from "@dxos/protocols";
|
|
34
36
|
import { trace } from "@dxos/tracing";
|
|
35
37
|
import { ComplexMap, ComplexSet, defaultMap, mapValues } from "@dxos/util";
|
|
36
38
|
|
|
39
|
+
// packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts
|
|
40
|
+
import { Trigger, synchronized } from "@dxos/async";
|
|
41
|
+
import { NetworkAdapter } from "@dxos/automerge/automerge-repo";
|
|
42
|
+
import { LifecycleState } from "@dxos/context";
|
|
43
|
+
import { invariant } from "@dxos/invariant";
|
|
44
|
+
import { log } from "@dxos/log";
|
|
45
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
46
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
47
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
48
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
49
|
+
else
|
|
50
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
51
|
+
if (d = decorators[i])
|
|
52
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
53
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
54
|
+
}
|
|
55
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/echo-network-adapter.ts";
|
|
56
|
+
var EchoNetworkAdapter = class extends NetworkAdapter {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(...arguments);
|
|
59
|
+
this._replicators = /* @__PURE__ */ new Set();
|
|
60
|
+
/**
|
|
61
|
+
* Remote peer id -> connection.
|
|
62
|
+
*/
|
|
63
|
+
this._connections = /* @__PURE__ */ new Map();
|
|
64
|
+
this._lifecycleState = LifecycleState.CLOSED;
|
|
65
|
+
this._connected = new Trigger();
|
|
66
|
+
}
|
|
67
|
+
connect(peerId, peerMetadata) {
|
|
68
|
+
this.peerId = peerId;
|
|
69
|
+
this.peerMetadata = peerMetadata;
|
|
70
|
+
this._connected.wake();
|
|
71
|
+
}
|
|
72
|
+
send(message) {
|
|
73
|
+
const connectionEntry = this._connections.get(message.targetId);
|
|
74
|
+
if (!connectionEntry) {
|
|
75
|
+
throw new Error("Connection not found.");
|
|
76
|
+
}
|
|
77
|
+
connectionEntry.writer.write(message).catch((err) => {
|
|
78
|
+
if (connectionEntry.isOpen) {
|
|
79
|
+
log.catch(err, void 0, {
|
|
80
|
+
F: __dxlog_file,
|
|
81
|
+
L: 40,
|
|
82
|
+
S: this,
|
|
83
|
+
C: (f, a) => f(...a)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
disconnect() {
|
|
89
|
+
}
|
|
90
|
+
async open() {
|
|
91
|
+
invariant(this._lifecycleState === LifecycleState.CLOSED, void 0, {
|
|
92
|
+
F: __dxlog_file,
|
|
93
|
+
L: 51,
|
|
94
|
+
S: this,
|
|
95
|
+
A: [
|
|
96
|
+
"this._lifecycleState === LifecycleState.CLOSED",
|
|
97
|
+
""
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
this._lifecycleState = LifecycleState.OPEN;
|
|
101
|
+
this.emit("ready", {
|
|
102
|
+
network: this
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async close() {
|
|
106
|
+
invariant(this._lifecycleState === LifecycleState.OPEN, void 0, {
|
|
107
|
+
F: __dxlog_file,
|
|
108
|
+
L: 61,
|
|
109
|
+
S: this,
|
|
110
|
+
A: [
|
|
111
|
+
"this._lifecycleState === LifecycleState.OPEN",
|
|
112
|
+
""
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
for (const replicator of this._replicators) {
|
|
116
|
+
await replicator.disconnect();
|
|
117
|
+
}
|
|
118
|
+
this._replicators.clear();
|
|
119
|
+
this._lifecycleState = LifecycleState.CLOSED;
|
|
120
|
+
}
|
|
121
|
+
async whenConnected() {
|
|
122
|
+
await this._connected.wait({
|
|
123
|
+
timeout: 1e4
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async addReplicator(replicator) {
|
|
127
|
+
invariant(this.peerId, void 0, {
|
|
128
|
+
F: __dxlog_file,
|
|
129
|
+
L: 77,
|
|
130
|
+
S: this,
|
|
131
|
+
A: [
|
|
132
|
+
"this.peerId",
|
|
133
|
+
""
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
invariant(!this._replicators.has(replicator), void 0, {
|
|
137
|
+
F: __dxlog_file,
|
|
138
|
+
L: 78,
|
|
139
|
+
S: this,
|
|
140
|
+
A: [
|
|
141
|
+
"!this._replicators.has(replicator)",
|
|
142
|
+
""
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
await replicator.connect({
|
|
146
|
+
peerId: this.peerId,
|
|
147
|
+
onConnectionOpen: this._onConnectionOpen.bind(this),
|
|
148
|
+
onConnectionClosed: this._onConnectionClosed.bind(this)
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async removeReplicator(replicator) {
|
|
152
|
+
invariant(this._replicators.has(replicator), void 0, {
|
|
153
|
+
F: __dxlog_file,
|
|
154
|
+
L: 89,
|
|
155
|
+
S: this,
|
|
156
|
+
A: [
|
|
157
|
+
"this._replicators.has(replicator)",
|
|
158
|
+
""
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
await replicator.disconnect();
|
|
162
|
+
}
|
|
163
|
+
async shouldAdvertize(peerId, params) {
|
|
164
|
+
const connection = this._connections.get(peerId);
|
|
165
|
+
if (!connection) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return connection.connection.shouldAdvertize(params);
|
|
169
|
+
}
|
|
170
|
+
_onConnectionOpen(connection) {
|
|
171
|
+
invariant(!this._connections.has(connection.peerId), void 0, {
|
|
172
|
+
F: __dxlog_file,
|
|
173
|
+
L: 103,
|
|
174
|
+
S: this,
|
|
175
|
+
A: [
|
|
176
|
+
"!this._connections.has(connection.peerId as PeerId)",
|
|
177
|
+
""
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
const reader = connection.readable.getReader();
|
|
181
|
+
const writer = connection.writable.getWriter();
|
|
182
|
+
const connectionEntry = {
|
|
183
|
+
connection,
|
|
184
|
+
reader,
|
|
185
|
+
writer,
|
|
186
|
+
isOpen: true
|
|
187
|
+
};
|
|
188
|
+
this._connections.set(connection.peerId, connectionEntry);
|
|
189
|
+
queueMicrotask(async () => {
|
|
190
|
+
try {
|
|
191
|
+
while (true) {
|
|
192
|
+
const { done, value } = await reader.read();
|
|
193
|
+
if (done) {
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
this.emit("message", value);
|
|
197
|
+
}
|
|
198
|
+
} catch (err) {
|
|
199
|
+
if (connectionEntry.isOpen) {
|
|
200
|
+
log.catch(err, void 0, {
|
|
201
|
+
F: __dxlog_file,
|
|
202
|
+
L: 122,
|
|
203
|
+
S: this,
|
|
204
|
+
C: (f, a) => f(...a)
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
this.emit("peer-candidate", {
|
|
210
|
+
peerId: connection.peerId,
|
|
211
|
+
peerMetadata: {
|
|
212
|
+
// TODO(dmaretskyi): Refactor this.
|
|
213
|
+
dxos_peerSource: "EchoNetworkAdapter"
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
_onConnectionClosed(connection) {
|
|
218
|
+
const entry = this._connections.get(connection.peerId);
|
|
219
|
+
invariant(entry, void 0, {
|
|
220
|
+
F: __dxlog_file,
|
|
221
|
+
L: 138,
|
|
222
|
+
S: this,
|
|
223
|
+
A: [
|
|
224
|
+
"entry",
|
|
225
|
+
""
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
entry.isOpen = false;
|
|
229
|
+
this.emit("peer-disconnected", {
|
|
230
|
+
peerId: connection.peerId
|
|
231
|
+
});
|
|
232
|
+
void entry.reader.cancel().catch((err) => log.catch(err, void 0, {
|
|
233
|
+
F: __dxlog_file,
|
|
234
|
+
L: 143,
|
|
235
|
+
S: this,
|
|
236
|
+
C: (f, a) => f(...a)
|
|
237
|
+
}));
|
|
238
|
+
void entry.writer.abort().catch((err) => log.catch(err, void 0, {
|
|
239
|
+
F: __dxlog_file,
|
|
240
|
+
L: 144,
|
|
241
|
+
S: this,
|
|
242
|
+
C: (f, a) => f(...a)
|
|
243
|
+
}));
|
|
244
|
+
this._connections.delete(connection.peerId);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
_ts_decorate([
|
|
248
|
+
synchronized
|
|
249
|
+
], EchoNetworkAdapter.prototype, "open", null);
|
|
250
|
+
_ts_decorate([
|
|
251
|
+
synchronized
|
|
252
|
+
], EchoNetworkAdapter.prototype, "close", null);
|
|
253
|
+
_ts_decorate([
|
|
254
|
+
synchronized
|
|
255
|
+
], EchoNetworkAdapter.prototype, "addReplicator", null);
|
|
256
|
+
_ts_decorate([
|
|
257
|
+
synchronized
|
|
258
|
+
], EchoNetworkAdapter.prototype, "removeReplicator", null);
|
|
259
|
+
|
|
37
260
|
// packages/core/echo/echo-pipeline/src/automerge/leveldb-storage-adapter.ts
|
|
38
|
-
import { LifecycleState, Resource } from "@dxos/context";
|
|
261
|
+
import { LifecycleState as LifecycleState2, Resource } from "@dxos/context";
|
|
39
262
|
var LevelDBStorageAdapter = class extends Resource {
|
|
40
263
|
constructor(_params) {
|
|
41
264
|
super();
|
|
@@ -43,7 +266,7 @@ var LevelDBStorageAdapter = class extends Resource {
|
|
|
43
266
|
}
|
|
44
267
|
async load(keyArray) {
|
|
45
268
|
try {
|
|
46
|
-
if (this._lifecycleState !==
|
|
269
|
+
if (this._lifecycleState !== LifecycleState2.OPEN) {
|
|
47
270
|
return void 0;
|
|
48
271
|
}
|
|
49
272
|
return await this._params.db.get(keyArray, {
|
|
@@ -57,7 +280,7 @@ var LevelDBStorageAdapter = class extends Resource {
|
|
|
57
280
|
}
|
|
58
281
|
}
|
|
59
282
|
async save(keyArray, binary) {
|
|
60
|
-
if (this._lifecycleState !==
|
|
283
|
+
if (this._lifecycleState !== LifecycleState2.OPEN) {
|
|
61
284
|
return void 0;
|
|
62
285
|
}
|
|
63
286
|
const batch = this._params.db.batch();
|
|
@@ -72,7 +295,7 @@ var LevelDBStorageAdapter = class extends Resource {
|
|
|
72
295
|
await this._params.callbacks?.afterSave?.(keyArray);
|
|
73
296
|
}
|
|
74
297
|
async remove(keyArray) {
|
|
75
|
-
if (this._lifecycleState !==
|
|
298
|
+
if (this._lifecycleState !== LifecycleState2.OPEN) {
|
|
76
299
|
return void 0;
|
|
77
300
|
}
|
|
78
301
|
await this._params.db.del(keyArray, {
|
|
@@ -80,7 +303,7 @@ var LevelDBStorageAdapter = class extends Resource {
|
|
|
80
303
|
});
|
|
81
304
|
}
|
|
82
305
|
async loadRange(keyPrefix) {
|
|
83
|
-
if (this._lifecycleState !==
|
|
306
|
+
if (this._lifecycleState !== LifecycleState2.OPEN) {
|
|
84
307
|
return [];
|
|
85
308
|
}
|
|
86
309
|
const result = [];
|
|
@@ -100,7 +323,7 @@ var LevelDBStorageAdapter = class extends Resource {
|
|
|
100
323
|
return result;
|
|
101
324
|
}
|
|
102
325
|
async removeRange(keyPrefix) {
|
|
103
|
-
if (this._lifecycleState !==
|
|
326
|
+
if (this._lifecycleState !== LifecycleState2.OPEN) {
|
|
104
327
|
return void 0;
|
|
105
328
|
}
|
|
106
329
|
const batch = this._params.db.batch();
|
|
@@ -121,7 +344,8 @@ var LevelDBStorageAdapter = class extends Resource {
|
|
|
121
344
|
};
|
|
122
345
|
var keyEncoder = {
|
|
123
346
|
encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
|
|
124
|
-
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
|
|
347
|
+
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%")),
|
|
348
|
+
format: "buffer"
|
|
125
349
|
};
|
|
126
350
|
var encodingOptions = {
|
|
127
351
|
keyEncoding: keyEncoder,
|
|
@@ -130,16 +354,16 @@ var encodingOptions = {
|
|
|
130
354
|
var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
|
|
131
355
|
|
|
132
356
|
// packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts
|
|
133
|
-
import { Trigger } from "@dxos/async";
|
|
134
|
-
import { NetworkAdapter, cbor } from "@dxos/automerge/automerge-repo";
|
|
357
|
+
import { Trigger as Trigger2 } from "@dxos/async";
|
|
358
|
+
import { NetworkAdapter as NetworkAdapter2, cbor } from "@dxos/automerge/automerge-repo";
|
|
135
359
|
import { Stream } from "@dxos/codec-protobuf";
|
|
136
|
-
import { invariant } from "@dxos/invariant";
|
|
137
|
-
var
|
|
138
|
-
var LocalHostNetworkAdapter = class extends
|
|
360
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
361
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
|
|
362
|
+
var LocalHostNetworkAdapter = class extends NetworkAdapter2 {
|
|
139
363
|
constructor() {
|
|
140
364
|
super(...arguments);
|
|
141
365
|
this._peers = /* @__PURE__ */ new Map();
|
|
142
|
-
this._connected = new
|
|
366
|
+
this._connected = new Trigger2();
|
|
143
367
|
this._isConnected = false;
|
|
144
368
|
}
|
|
145
369
|
/**
|
|
@@ -162,8 +386,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
162
386
|
}
|
|
163
387
|
send(message) {
|
|
164
388
|
const peer = this._peers.get(message.targetId);
|
|
165
|
-
|
|
166
|
-
F:
|
|
389
|
+
invariant2(peer, "Peer not found.", {
|
|
390
|
+
F: __dxlog_file2,
|
|
167
391
|
L: 51,
|
|
168
392
|
S: this,
|
|
169
393
|
A: [
|
|
@@ -187,8 +411,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
187
411
|
syncRepo({ id, syncMessage }) {
|
|
188
412
|
const peerId = this._getPeerId(id);
|
|
189
413
|
return new Stream(({ next, close }) => {
|
|
190
|
-
|
|
191
|
-
F:
|
|
414
|
+
invariant2(!this._peers.has(peerId), "Peer already connected.", {
|
|
415
|
+
F: __dxlog_file2,
|
|
192
416
|
L: 73,
|
|
193
417
|
S: this,
|
|
194
418
|
A: [
|
|
@@ -211,8 +435,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
211
435
|
});
|
|
212
436
|
}
|
|
213
437
|
});
|
|
214
|
-
|
|
215
|
-
F:
|
|
438
|
+
invariant2(this._isConnected, void 0, {
|
|
439
|
+
F: __dxlog_file2,
|
|
216
440
|
L: 90,
|
|
217
441
|
S: this,
|
|
218
442
|
A: [
|
|
@@ -227,8 +451,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
227
451
|
});
|
|
228
452
|
}
|
|
229
453
|
async sendSyncMessage({ id, syncMessage }) {
|
|
230
|
-
|
|
231
|
-
F:
|
|
454
|
+
invariant2(this._isConnected, void 0, {
|
|
455
|
+
F: __dxlog_file2,
|
|
232
456
|
L: 99,
|
|
233
457
|
S: this,
|
|
234
458
|
A: [
|
|
@@ -240,8 +464,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
240
464
|
this.emit("message", message);
|
|
241
465
|
}
|
|
242
466
|
async getHostInfo() {
|
|
243
|
-
|
|
244
|
-
F:
|
|
467
|
+
invariant2(this._isConnected, void 0, {
|
|
468
|
+
F: __dxlog_file2,
|
|
245
469
|
L: 105,
|
|
246
470
|
S: this,
|
|
247
471
|
A: [
|
|
@@ -249,8 +473,8 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
249
473
|
""
|
|
250
474
|
]
|
|
251
475
|
});
|
|
252
|
-
|
|
253
|
-
F:
|
|
476
|
+
invariant2(this.peerId, "Peer id not set.", {
|
|
477
|
+
F: __dxlog_file2,
|
|
254
478
|
L: 106,
|
|
255
479
|
S: this,
|
|
256
480
|
A: [
|
|
@@ -268,17 +492,17 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
268
492
|
};
|
|
269
493
|
|
|
270
494
|
// packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts
|
|
271
|
-
import { Trigger as
|
|
272
|
-
import { NetworkAdapter as
|
|
273
|
-
import { invariant as
|
|
274
|
-
import { log } from "@dxos/log";
|
|
495
|
+
import { Trigger as Trigger3 } from "@dxos/async";
|
|
496
|
+
import { NetworkAdapter as NetworkAdapter3, cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
497
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
498
|
+
import { log as log2 } from "@dxos/log";
|
|
275
499
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
276
|
-
var
|
|
277
|
-
var MeshNetworkAdapter = class extends
|
|
500
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
|
|
501
|
+
var MeshNetworkAdapter = class extends NetworkAdapter3 {
|
|
278
502
|
constructor() {
|
|
279
503
|
super(...arguments);
|
|
280
504
|
this._extensions = /* @__PURE__ */ new Map();
|
|
281
|
-
this._connected = new
|
|
505
|
+
this._connected = new Trigger3();
|
|
282
506
|
}
|
|
283
507
|
/**
|
|
284
508
|
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
@@ -295,8 +519,8 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
295
519
|
send(message) {
|
|
296
520
|
const receiverId = message.targetId;
|
|
297
521
|
const extension = this._extensions.get(receiverId);
|
|
298
|
-
|
|
299
|
-
F:
|
|
522
|
+
invariant3(extension, "Extension not found.", {
|
|
523
|
+
F: __dxlog_file3,
|
|
300
524
|
L: 38,
|
|
301
525
|
S: this,
|
|
302
526
|
A: [
|
|
@@ -306,8 +530,8 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
306
530
|
});
|
|
307
531
|
extension.sendSyncMessage({
|
|
308
532
|
payload: cbor2.encode(message)
|
|
309
|
-
}).catch((err) =>
|
|
310
|
-
F:
|
|
533
|
+
}).catch((err) => log2.catch(err, void 0, {
|
|
534
|
+
F: __dxlog_file3,
|
|
311
535
|
L: 39,
|
|
312
536
|
S: this,
|
|
313
537
|
C: (f, a) => f(...a)
|
|
@@ -316,8 +540,8 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
316
540
|
disconnect() {
|
|
317
541
|
}
|
|
318
542
|
createExtension() {
|
|
319
|
-
|
|
320
|
-
F:
|
|
543
|
+
invariant3(this.peerId, "Peer id not set.", {
|
|
544
|
+
F: __dxlog_file3,
|
|
321
545
|
L: 47,
|
|
322
546
|
S: this,
|
|
323
547
|
A: [
|
|
@@ -331,12 +555,12 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
331
555
|
}, {
|
|
332
556
|
onStartReplication: async (info, remotePeerId) => {
|
|
333
557
|
await this._connected.wait();
|
|
334
|
-
|
|
558
|
+
log2("onStartReplication", {
|
|
335
559
|
id: info.id,
|
|
336
560
|
thisPeerId: this.peerId,
|
|
337
561
|
remotePeerId: remotePeerId.toHex()
|
|
338
562
|
}, {
|
|
339
|
-
F:
|
|
563
|
+
F: __dxlog_file3,
|
|
340
564
|
L: 70,
|
|
341
565
|
S: this,
|
|
342
566
|
C: (f, a) => f(...a)
|
|
@@ -344,12 +568,12 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
344
568
|
if (!this._extensions.has(info.id)) {
|
|
345
569
|
peerInfo = info;
|
|
346
570
|
this._extensions.set(info.id, extension);
|
|
347
|
-
|
|
571
|
+
log2("peer-candidate", {
|
|
348
572
|
id: info.id,
|
|
349
573
|
thisPeerId: this.peerId,
|
|
350
574
|
remotePeerId: remotePeerId.toHex()
|
|
351
575
|
}, {
|
|
352
|
-
F:
|
|
576
|
+
F: __dxlog_file3,
|
|
353
577
|
L: 76,
|
|
354
578
|
S: this,
|
|
355
579
|
C: (f, a) => f(...a)
|
|
@@ -386,7 +610,7 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
386
610
|
|
|
387
611
|
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
388
612
|
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
389
|
-
import { log as
|
|
613
|
+
import { log as log3 } from "@dxos/log";
|
|
390
614
|
import { StorageType } from "@dxos/random-access-storage";
|
|
391
615
|
|
|
392
616
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
@@ -466,7 +690,7 @@ var AutomergeStorageAdapter = class {
|
|
|
466
690
|
};
|
|
467
691
|
|
|
468
692
|
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
469
|
-
var
|
|
693
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
470
694
|
var levelMigration = async ({ db, directory }) => {
|
|
471
695
|
const isNewLevel = !await db.iterator({
|
|
472
696
|
...encodingOptions
|
|
@@ -480,10 +704,10 @@ var levelMigration = async ({ db, directory }) => {
|
|
|
480
704
|
return;
|
|
481
705
|
}
|
|
482
706
|
const batch = db.batch();
|
|
483
|
-
|
|
707
|
+
log3.info("found chunks on old storage adapter", {
|
|
484
708
|
chunks: chunks.length
|
|
485
709
|
}, {
|
|
486
|
-
F:
|
|
710
|
+
F: __dxlog_file4,
|
|
487
711
|
L: 36,
|
|
488
712
|
S: void 0,
|
|
489
713
|
C: (f, a) => f(...a)
|
|
@@ -497,7 +721,7 @@ var levelMigration = async ({ db, directory }) => {
|
|
|
497
721
|
};
|
|
498
722
|
|
|
499
723
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
500
|
-
function
|
|
724
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
501
725
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
502
726
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
503
727
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -507,10 +731,11 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
507
731
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
508
732
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
509
733
|
}
|
|
510
|
-
var
|
|
734
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
511
735
|
var AutomergeHost = class {
|
|
512
|
-
constructor({ directory, db,
|
|
736
|
+
constructor({ directory, db, indexMetadataStore }) {
|
|
513
737
|
this._ctx = new Context();
|
|
738
|
+
this._echoNetworkAdapter = new EchoNetworkAdapter();
|
|
514
739
|
/**
|
|
515
740
|
* spaceKey -> deviceKey[]
|
|
516
741
|
*/
|
|
@@ -518,7 +743,7 @@ var AutomergeHost = class {
|
|
|
518
743
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
519
744
|
this._directory = directory;
|
|
520
745
|
this._db = db;
|
|
521
|
-
this.
|
|
746
|
+
this._indexMetadataStore = indexMetadataStore;
|
|
522
747
|
}
|
|
523
748
|
async open() {
|
|
524
749
|
this._directory && await levelMigration({
|
|
@@ -527,7 +752,10 @@ var AutomergeHost = class {
|
|
|
527
752
|
});
|
|
528
753
|
this._storage = new LevelDBStorageAdapter({
|
|
529
754
|
db: this._db,
|
|
530
|
-
callbacks:
|
|
755
|
+
callbacks: {
|
|
756
|
+
beforeSave: async (params) => this._beforeSave(params),
|
|
757
|
+
afterSave: async () => this._afterSave()
|
|
758
|
+
}
|
|
531
759
|
});
|
|
532
760
|
await this._storage.open?.();
|
|
533
761
|
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
@@ -537,7 +765,8 @@ var AutomergeHost = class {
|
|
|
537
765
|
peerId: this._peerId,
|
|
538
766
|
network: [
|
|
539
767
|
this._clientNetwork,
|
|
540
|
-
this._meshNetwork
|
|
768
|
+
this._meshNetwork,
|
|
769
|
+
this._echoNetworkAdapter
|
|
541
770
|
],
|
|
542
771
|
storage: this._storage,
|
|
543
772
|
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
@@ -549,16 +778,22 @@ var AutomergeHost = class {
|
|
|
549
778
|
if (!documentId) {
|
|
550
779
|
return false;
|
|
551
780
|
}
|
|
781
|
+
const peerMetadata = this.repo.peerMetadataByPeerId[peerId];
|
|
782
|
+
if (peerMetadata?.dxos_peerSource === "EchoNetworkAdapter") {
|
|
783
|
+
return this._echoNetworkAdapter.shouldAdvertize(peerId, {
|
|
784
|
+
documentId
|
|
785
|
+
});
|
|
786
|
+
}
|
|
552
787
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
553
788
|
if (!doc) {
|
|
554
789
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
555
|
-
|
|
790
|
+
log4("doc share policy check", {
|
|
556
791
|
peerId,
|
|
557
792
|
documentId,
|
|
558
793
|
isRequested
|
|
559
794
|
}, {
|
|
560
|
-
F:
|
|
561
|
-
L:
|
|
795
|
+
F: __dxlog_file5,
|
|
796
|
+
L: 124,
|
|
562
797
|
S: this,
|
|
563
798
|
C: (f, a) => f(...a)
|
|
564
799
|
});
|
|
@@ -567,26 +802,26 @@ var AutomergeHost = class {
|
|
|
567
802
|
try {
|
|
568
803
|
const spaceKey = getSpaceKeyFromDoc(doc);
|
|
569
804
|
if (!spaceKey) {
|
|
570
|
-
|
|
805
|
+
log4("space key not found for share policy check", {
|
|
571
806
|
peerId,
|
|
572
807
|
documentId
|
|
573
808
|
}, {
|
|
574
|
-
F:
|
|
575
|
-
L:
|
|
809
|
+
F: __dxlog_file5,
|
|
810
|
+
L: 131,
|
|
576
811
|
S: this,
|
|
577
812
|
C: (f, a) => f(...a)
|
|
578
813
|
});
|
|
579
814
|
return false;
|
|
580
815
|
}
|
|
581
816
|
const authorizedDevices = this._authorizedDevices.get(PublicKey.from(spaceKey));
|
|
582
|
-
const deviceKeyHex =
|
|
817
|
+
const deviceKeyHex = peerMetadata?.dxos_deviceKey;
|
|
583
818
|
if (!deviceKeyHex) {
|
|
584
|
-
|
|
819
|
+
log4("device key not found for share policy check", {
|
|
585
820
|
peerId,
|
|
586
821
|
documentId
|
|
587
822
|
}, {
|
|
588
|
-
F:
|
|
589
|
-
L:
|
|
823
|
+
F: __dxlog_file5,
|
|
824
|
+
L: 140,
|
|
590
825
|
S: this,
|
|
591
826
|
C: (f, a) => f(...a)
|
|
592
827
|
});
|
|
@@ -594,7 +829,7 @@ var AutomergeHost = class {
|
|
|
594
829
|
}
|
|
595
830
|
const deviceKey = PublicKey.from(deviceKeyHex);
|
|
596
831
|
const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
|
|
597
|
-
|
|
832
|
+
log4("share policy check", {
|
|
598
833
|
localPeer: this._peerId,
|
|
599
834
|
remotePeer: peerId,
|
|
600
835
|
documentId,
|
|
@@ -602,16 +837,16 @@ var AutomergeHost = class {
|
|
|
602
837
|
spaceKey,
|
|
603
838
|
isAuthorized
|
|
604
839
|
}, {
|
|
605
|
-
F:
|
|
606
|
-
L:
|
|
840
|
+
F: __dxlog_file5,
|
|
841
|
+
L: 146,
|
|
607
842
|
S: this,
|
|
608
843
|
C: (f, a) => f(...a)
|
|
609
844
|
});
|
|
610
845
|
return isAuthorized;
|
|
611
846
|
} catch (err) {
|
|
612
|
-
|
|
613
|
-
F:
|
|
614
|
-
L:
|
|
847
|
+
log4.catch(err, void 0, {
|
|
848
|
+
F: __dxlog_file5,
|
|
849
|
+
L: 156,
|
|
615
850
|
S: this,
|
|
616
851
|
C: (f, a) => f(...a)
|
|
617
852
|
});
|
|
@@ -621,16 +856,52 @@ var AutomergeHost = class {
|
|
|
621
856
|
});
|
|
622
857
|
this._clientNetwork.ready();
|
|
623
858
|
this._meshNetwork.ready();
|
|
859
|
+
await this._echoNetworkAdapter.open();
|
|
624
860
|
await this._clientNetwork.whenConnected();
|
|
861
|
+
await this._echoNetworkAdapter.whenConnected();
|
|
625
862
|
}
|
|
626
863
|
async close() {
|
|
627
864
|
await this._storage.close?.();
|
|
628
865
|
await this._clientNetwork.close();
|
|
866
|
+
await this._echoNetworkAdapter.close();
|
|
629
867
|
await this._ctx.dispose();
|
|
630
868
|
}
|
|
631
869
|
get repo() {
|
|
632
870
|
return this._repo;
|
|
633
871
|
}
|
|
872
|
+
async addReplicator(replicator) {
|
|
873
|
+
await this._echoNetworkAdapter.addReplicator(replicator);
|
|
874
|
+
}
|
|
875
|
+
async removeReplicator(replicator) {
|
|
876
|
+
await this._echoNetworkAdapter.removeReplicator(replicator);
|
|
877
|
+
}
|
|
878
|
+
async _beforeSave({ path, batch }) {
|
|
879
|
+
const handle = this._repo.handles[path[0]];
|
|
880
|
+
if (!handle) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
const doc = handle.docSync();
|
|
884
|
+
if (!doc) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
const lastAvailableHash = getHeads(doc);
|
|
888
|
+
const objectIds = Object.keys(doc.objects ?? {});
|
|
889
|
+
const encodedIds = objectIds.map((objectId) => idCodec.encode({
|
|
890
|
+
documentId: handle.documentId,
|
|
891
|
+
objectId
|
|
892
|
+
}));
|
|
893
|
+
const idToLastHash = new Map(encodedIds.map((id) => [
|
|
894
|
+
id,
|
|
895
|
+
lastAvailableHash
|
|
896
|
+
]));
|
|
897
|
+
this._indexMetadataStore.markDirty(idToLastHash, batch);
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Called by AutomergeStorageAdapter after levelDB batch commit.
|
|
901
|
+
*/
|
|
902
|
+
async _afterSave() {
|
|
903
|
+
this._indexMetadataStore.notifyMarkedDirty();
|
|
904
|
+
}
|
|
634
905
|
_automergeDocs() {
|
|
635
906
|
return mapValues(this._repo.handles, (handle) => ({
|
|
636
907
|
state: handle.state,
|
|
@@ -659,21 +930,21 @@ var AutomergeHost = class {
|
|
|
659
930
|
//
|
|
660
931
|
// Methods for client-services.
|
|
661
932
|
//
|
|
662
|
-
async flush({
|
|
663
|
-
await Promise.all(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
log3.warn("flush error", {
|
|
668
|
-
documentIds,
|
|
669
|
-
err
|
|
670
|
-
}, {
|
|
671
|
-
F: __dxlog_file4,
|
|
672
|
-
L: 196,
|
|
933
|
+
async flush({ states }) {
|
|
934
|
+
await Promise.all(states?.map(async ({ heads, documentId }) => {
|
|
935
|
+
invariant4(heads, "heads are required for flush", {
|
|
936
|
+
F: __dxlog_file5,
|
|
937
|
+
L: 252,
|
|
673
938
|
S: this,
|
|
674
|
-
|
|
939
|
+
A: [
|
|
940
|
+
"heads",
|
|
941
|
+
"'heads are required for flush'"
|
|
942
|
+
]
|
|
675
943
|
});
|
|
676
|
-
|
|
944
|
+
const handle = this.repo.handles[documentId] ?? this._repo.find(documentId);
|
|
945
|
+
await waitForHeads(handle, heads);
|
|
946
|
+
}) ?? []);
|
|
947
|
+
await this._repo.flush(states?.map(({ documentId }) => documentId));
|
|
677
948
|
}
|
|
678
949
|
syncRepo(request) {
|
|
679
950
|
return this._clientNetwork.syncRepo(request);
|
|
@@ -691,37 +962,37 @@ var AutomergeHost = class {
|
|
|
691
962
|
return this._meshNetwork.createExtension();
|
|
692
963
|
}
|
|
693
964
|
authorizeDevice(spaceKey, deviceKey) {
|
|
694
|
-
|
|
965
|
+
log4("authorizeDevice", {
|
|
695
966
|
spaceKey,
|
|
696
967
|
deviceKey
|
|
697
968
|
}, {
|
|
698
|
-
F:
|
|
699
|
-
L:
|
|
969
|
+
F: __dxlog_file5,
|
|
970
|
+
L: 282,
|
|
700
971
|
S: this,
|
|
701
972
|
C: (f, a) => f(...a)
|
|
702
973
|
});
|
|
703
974
|
defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey.hash)).add(deviceKey);
|
|
704
975
|
}
|
|
705
976
|
};
|
|
706
|
-
|
|
977
|
+
_ts_decorate2([
|
|
707
978
|
trace.info()
|
|
708
979
|
], AutomergeHost.prototype, "_peerId", void 0);
|
|
709
|
-
|
|
980
|
+
_ts_decorate2([
|
|
710
981
|
trace.info({
|
|
711
982
|
depth: null
|
|
712
983
|
})
|
|
713
984
|
], AutomergeHost.prototype, "_automergeDocs", null);
|
|
714
|
-
|
|
985
|
+
_ts_decorate2([
|
|
715
986
|
trace.info({
|
|
716
987
|
depth: null
|
|
717
988
|
})
|
|
718
989
|
], AutomergeHost.prototype, "_automergePeers", null);
|
|
719
|
-
|
|
990
|
+
_ts_decorate2([
|
|
720
991
|
trace.span({
|
|
721
992
|
showInBrowserTimeline: true
|
|
722
993
|
})
|
|
723
994
|
], AutomergeHost.prototype, "flush", null);
|
|
724
|
-
AutomergeHost =
|
|
995
|
+
AutomergeHost = _ts_decorate2([
|
|
725
996
|
trace.resource()
|
|
726
997
|
], AutomergeHost);
|
|
727
998
|
var getSpaceKeyFromDoc = (doc) => {
|
|
@@ -731,15 +1002,33 @@ var getSpaceKeyFromDoc = (doc) => {
|
|
|
731
1002
|
}
|
|
732
1003
|
return String(rawSpaceKey);
|
|
733
1004
|
};
|
|
1005
|
+
var waitForHeads = async (handle, heads) => {
|
|
1006
|
+
await handle.whenReady();
|
|
1007
|
+
const unavailableHeads = new Set(heads);
|
|
1008
|
+
await Event.wrap(handle, "change").waitForCondition(() => {
|
|
1009
|
+
for (const changeHash of unavailableHeads.values()) {
|
|
1010
|
+
if (changeIsPresentInDoc(handle.docSync(), changeHash)) {
|
|
1011
|
+
unavailableHeads.delete(changeHash);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
if (unavailableHeads.size === 0) {
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
1017
|
+
return false;
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1020
|
+
var changeIsPresentInDoc = (doc, changeHash) => {
|
|
1021
|
+
return !!getBackend(doc).getChangeByHash(changeHash);
|
|
1022
|
+
};
|
|
734
1023
|
|
|
735
1024
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts
|
|
736
|
-
import { Event } from "@dxos/async";
|
|
1025
|
+
import { Event as Event2 } from "@dxos/async";
|
|
737
1026
|
import { cancelWithContext } from "@dxos/context";
|
|
738
1027
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
739
|
-
import { invariant as
|
|
740
|
-
import { log as
|
|
1028
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1029
|
+
import { log as log5 } from "@dxos/log";
|
|
741
1030
|
import { trace as trace2 } from "@dxos/tracing";
|
|
742
|
-
function
|
|
1031
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
743
1032
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
744
1033
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
745
1034
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -749,7 +1038,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
749
1038
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
750
1039
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
751
1040
|
}
|
|
752
|
-
var
|
|
1041
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
753
1042
|
var AutomergeDocumentLoaderImpl = class {
|
|
754
1043
|
constructor(_spaceKey, _repo) {
|
|
755
1044
|
this._spaceKey = _spaceKey;
|
|
@@ -757,23 +1046,24 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
757
1046
|
this._spaceRootDocHandle = null;
|
|
758
1047
|
this._objectDocumentHandles = /* @__PURE__ */ new Map();
|
|
759
1048
|
this._objectsPendingDocumentLoad = /* @__PURE__ */ new Set();
|
|
760
|
-
this.onObjectDocumentLoaded = new
|
|
1049
|
+
this.onObjectDocumentLoaded = new Event2();
|
|
761
1050
|
}
|
|
762
1051
|
getAllHandles() {
|
|
763
|
-
return [
|
|
1052
|
+
return this._spaceRootDocHandle != null ? [
|
|
1053
|
+
this._spaceRootDocHandle,
|
|
764
1054
|
...new Set(this._objectDocumentHandles.values())
|
|
765
|
-
];
|
|
1055
|
+
] : [];
|
|
766
1056
|
}
|
|
767
1057
|
async loadSpaceRootDocHandle(ctx, spaceState) {
|
|
768
1058
|
if (this._spaceRootDocHandle != null) {
|
|
769
1059
|
return;
|
|
770
1060
|
}
|
|
771
1061
|
if (!spaceState.rootUrl) {
|
|
772
|
-
|
|
1062
|
+
log5.error("Database opened with no rootUrl", {
|
|
773
1063
|
spaceKey: this._spaceKey
|
|
774
1064
|
}, {
|
|
775
|
-
F:
|
|
776
|
-
L:
|
|
1065
|
+
F: __dxlog_file6,
|
|
1066
|
+
L: 70,
|
|
777
1067
|
S: this,
|
|
778
1068
|
C: (f, a) => f(...a)
|
|
779
1069
|
});
|
|
@@ -781,9 +1071,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
781
1071
|
} else {
|
|
782
1072
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
783
1073
|
const doc = existingDocHandle.docSync();
|
|
784
|
-
|
|
785
|
-
F:
|
|
786
|
-
L:
|
|
1074
|
+
invariant5(doc, void 0, {
|
|
1075
|
+
F: __dxlog_file6,
|
|
1076
|
+
L: 75,
|
|
787
1077
|
S: this,
|
|
788
1078
|
A: [
|
|
789
1079
|
"doc",
|
|
@@ -796,45 +1086,54 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
796
1086
|
this._spaceRootDocHandle = existingDocHandle;
|
|
797
1087
|
}
|
|
798
1088
|
}
|
|
799
|
-
loadObjectDocument(
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
|
|
810
|
-
return;
|
|
811
|
-
}
|
|
812
|
-
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
813
|
-
invariant3(spaceRootDoc, void 0, {
|
|
814
|
-
F: __dxlog_file5,
|
|
815
|
-
L: 88,
|
|
816
|
-
S: this,
|
|
817
|
-
A: [
|
|
818
|
-
"spaceRootDoc",
|
|
819
|
-
""
|
|
820
|
-
]
|
|
821
|
-
});
|
|
822
|
-
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
823
|
-
if (documentUrl == null) {
|
|
824
|
-
this._objectsPendingDocumentLoad.add(objectId);
|
|
825
|
-
log4.info("loading delayed until object links are initialized", {
|
|
826
|
-
objectId
|
|
827
|
-
}, {
|
|
828
|
-
F: __dxlog_file5,
|
|
829
|
-
L: 92,
|
|
1089
|
+
loadObjectDocument(objectIdOrMany) {
|
|
1090
|
+
const objectIds = Array.isArray(objectIdOrMany) ? objectIdOrMany : [
|
|
1091
|
+
objectIdOrMany
|
|
1092
|
+
];
|
|
1093
|
+
let hasUrlsToLoad = false;
|
|
1094
|
+
const urlsToLoad = {};
|
|
1095
|
+
for (const objectId of objectIds) {
|
|
1096
|
+
invariant5(this._spaceRootDocHandle, void 0, {
|
|
1097
|
+
F: __dxlog_file6,
|
|
1098
|
+
L: 88,
|
|
830
1099
|
S: this,
|
|
831
|
-
|
|
1100
|
+
A: [
|
|
1101
|
+
"this._spaceRootDocHandle",
|
|
1102
|
+
""
|
|
1103
|
+
]
|
|
832
1104
|
});
|
|
833
|
-
|
|
1105
|
+
if (this._objectDocumentHandles.has(objectId) || this._objectsPendingDocumentLoad.has(objectId)) {
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
1109
|
+
invariant5(spaceRootDoc, void 0, {
|
|
1110
|
+
F: __dxlog_file6,
|
|
1111
|
+
L: 93,
|
|
1112
|
+
S: this,
|
|
1113
|
+
A: [
|
|
1114
|
+
"spaceRootDoc",
|
|
1115
|
+
""
|
|
1116
|
+
]
|
|
1117
|
+
});
|
|
1118
|
+
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
1119
|
+
if (documentUrl == null) {
|
|
1120
|
+
this._objectsPendingDocumentLoad.add(objectId);
|
|
1121
|
+
log5.info("loading delayed until object links are initialized", {
|
|
1122
|
+
objectId
|
|
1123
|
+
}, {
|
|
1124
|
+
F: __dxlog_file6,
|
|
1125
|
+
L: 97,
|
|
1126
|
+
S: this,
|
|
1127
|
+
C: (f, a) => f(...a)
|
|
1128
|
+
});
|
|
1129
|
+
} else {
|
|
1130
|
+
urlsToLoad[objectId] = documentUrl;
|
|
1131
|
+
hasUrlsToLoad = true;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
if (hasUrlsToLoad) {
|
|
1135
|
+
this._loadLinkedObjects(urlsToLoad);
|
|
834
1136
|
}
|
|
835
|
-
this._loadLinkedObjects({
|
|
836
|
-
[objectId]: documentUrl
|
|
837
|
-
});
|
|
838
1137
|
}
|
|
839
1138
|
onObjectLinksUpdated(links) {
|
|
840
1139
|
if (!links) {
|
|
@@ -845,9 +1144,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
845
1144
|
linksAwaitingLoad.forEach(([objectId]) => this._objectsPendingDocumentLoad.delete(objectId));
|
|
846
1145
|
}
|
|
847
1146
|
getSpaceRootDocHandle() {
|
|
848
|
-
|
|
849
|
-
F:
|
|
850
|
-
L:
|
|
1147
|
+
invariant5(this._spaceRootDocHandle, void 0, {
|
|
1148
|
+
F: __dxlog_file6,
|
|
1149
|
+
L: 120,
|
|
851
1150
|
S: this,
|
|
852
1151
|
A: [
|
|
853
1152
|
"this._spaceRootDocHandle",
|
|
@@ -857,9 +1156,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
857
1156
|
return this._spaceRootDocHandle;
|
|
858
1157
|
}
|
|
859
1158
|
createDocumentForObject(objectId) {
|
|
860
|
-
|
|
861
|
-
F:
|
|
862
|
-
L:
|
|
1159
|
+
invariant5(this._spaceRootDocHandle, void 0, {
|
|
1160
|
+
F: __dxlog_file6,
|
|
1161
|
+
L: 125,
|
|
863
1162
|
S: this,
|
|
864
1163
|
A: [
|
|
865
1164
|
"this._spaceRootDocHandle",
|
|
@@ -897,30 +1196,30 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
897
1196
|
};
|
|
898
1197
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
899
1198
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
900
|
-
|
|
1199
|
+
log5.warn("object already inlined in a different document, ignoring the link", {
|
|
901
1200
|
...logMeta,
|
|
902
1201
|
actualDocumentUrl: objectDocumentHandle.url
|
|
903
1202
|
}, {
|
|
904
|
-
F:
|
|
905
|
-
L:
|
|
1203
|
+
F: __dxlog_file6,
|
|
1204
|
+
L: 155,
|
|
906
1205
|
S: this,
|
|
907
1206
|
C: (f, a) => f(...a)
|
|
908
1207
|
});
|
|
909
1208
|
continue;
|
|
910
1209
|
}
|
|
911
1210
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
912
|
-
|
|
913
|
-
F:
|
|
914
|
-
L:
|
|
1211
|
+
log5.warn("object document was already loaded", logMeta, {
|
|
1212
|
+
F: __dxlog_file6,
|
|
1213
|
+
L: 162,
|
|
915
1214
|
S: this,
|
|
916
1215
|
C: (f, a) => f(...a)
|
|
917
1216
|
});
|
|
918
1217
|
continue;
|
|
919
1218
|
}
|
|
920
1219
|
const handle = this._repo.find(automergeUrl);
|
|
921
|
-
|
|
922
|
-
F:
|
|
923
|
-
L:
|
|
1220
|
+
log5.debug("document loading triggered", logMeta, {
|
|
1221
|
+
F: __dxlog_file6,
|
|
1222
|
+
L: 166,
|
|
924
1223
|
S: this,
|
|
925
1224
|
C: (f, a) => f(...a)
|
|
926
1225
|
});
|
|
@@ -938,12 +1237,12 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
938
1237
|
break;
|
|
939
1238
|
} catch (err) {
|
|
940
1239
|
if (`${err}`.includes("Timeout")) {
|
|
941
|
-
|
|
1240
|
+
log5.info("wraparound", {
|
|
942
1241
|
id: docHandle.documentId,
|
|
943
1242
|
state: docHandle.state
|
|
944
1243
|
}, {
|
|
945
|
-
F:
|
|
946
|
-
L:
|
|
1244
|
+
F: __dxlog_file6,
|
|
1245
|
+
L: 182,
|
|
947
1246
|
S: this,
|
|
948
1247
|
C: (f, a) => f(...a)
|
|
949
1248
|
});
|
|
@@ -983,9 +1282,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
983
1282
|
docUrl: handle.url
|
|
984
1283
|
};
|
|
985
1284
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
986
|
-
|
|
987
|
-
F:
|
|
988
|
-
L:
|
|
1285
|
+
log5.info("document loaded after all listeners were removed", logMeta, {
|
|
1286
|
+
F: __dxlog_file6,
|
|
1287
|
+
L: 218,
|
|
989
1288
|
S: this,
|
|
990
1289
|
C: (f, a) => f(...a)
|
|
991
1290
|
});
|
|
@@ -993,9 +1292,9 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
993
1292
|
}
|
|
994
1293
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
995
1294
|
if (objectDocHandle?.url !== handle.url) {
|
|
996
|
-
|
|
997
|
-
F:
|
|
998
|
-
L:
|
|
1295
|
+
log5.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1296
|
+
F: __dxlog_file6,
|
|
1297
|
+
L: 223,
|
|
999
1298
|
S: this,
|
|
1000
1299
|
C: (f, a) => f(...a)
|
|
1001
1300
|
});
|
|
@@ -1007,14 +1306,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1007
1306
|
});
|
|
1008
1307
|
} catch (err) {
|
|
1009
1308
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
1010
|
-
|
|
1309
|
+
log5.warn("failed to load a document", {
|
|
1011
1310
|
objectId,
|
|
1012
1311
|
automergeUrl: handle.url,
|
|
1013
1312
|
retryLoading: shouldRetryLoading,
|
|
1014
1313
|
err
|
|
1015
1314
|
}, {
|
|
1016
|
-
F:
|
|
1017
|
-
L:
|
|
1315
|
+
F: __dxlog_file6,
|
|
1316
|
+
L: 229,
|
|
1018
1317
|
S: this,
|
|
1019
1318
|
C: (f, a) => f(...a)
|
|
1020
1319
|
});
|
|
@@ -1024,27 +1323,14 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
1024
1323
|
}
|
|
1025
1324
|
}
|
|
1026
1325
|
};
|
|
1027
|
-
|
|
1326
|
+
_ts_decorate3([
|
|
1028
1327
|
trace2.span({
|
|
1029
1328
|
showInBrowserTimeline: true
|
|
1030
1329
|
})
|
|
1031
1330
|
], AutomergeDocumentLoaderImpl.prototype, "loadSpaceRootDocHandle", null);
|
|
1032
|
-
AutomergeDocumentLoaderImpl =
|
|
1331
|
+
AutomergeDocumentLoaderImpl = _ts_decorate3([
|
|
1033
1332
|
trace2.resource()
|
|
1034
1333
|
], AutomergeDocumentLoaderImpl);
|
|
1035
|
-
|
|
1036
|
-
// packages/core/echo/echo-pipeline/src/automerge/reference.ts
|
|
1037
|
-
import { Reference } from "@dxos/echo-schema";
|
|
1038
|
-
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
1039
|
-
var encodeReference = (reference) => ({
|
|
1040
|
-
"@type": REFERENCE_TYPE_TAG,
|
|
1041
|
-
// NOTE: Automerge do not support undefined values, so we need to use null instead.
|
|
1042
|
-
itemId: reference.itemId ?? null,
|
|
1043
|
-
protocol: reference.protocol ?? null,
|
|
1044
|
-
host: reference.host ?? null
|
|
1045
|
-
});
|
|
1046
|
-
var decodeReference = (value) => new Reference(value.itemId, value.protocol ?? void 0, value.host ?? void 0);
|
|
1047
|
-
var isEncodedReferenceObject = (value) => typeof value === "object" && value !== null && value["@type"] === REFERENCE_TYPE_TAG;
|
|
1048
1334
|
export {
|
|
1049
1335
|
AuthExtension,
|
|
1050
1336
|
AuthStatus,
|
|
@@ -1059,7 +1345,6 @@ export {
|
|
|
1059
1345
|
MeshNetworkAdapter,
|
|
1060
1346
|
MetadataStore,
|
|
1061
1347
|
Pipeline,
|
|
1062
|
-
REFERENCE_TYPE_TAG,
|
|
1063
1348
|
SnapshotManager,
|
|
1064
1349
|
SnapshotStore,
|
|
1065
1350
|
Space,
|
|
@@ -1069,12 +1354,9 @@ export {
|
|
|
1069
1354
|
TimeframeClock,
|
|
1070
1355
|
codec,
|
|
1071
1356
|
createMappedFeedWriter,
|
|
1072
|
-
decodeReference,
|
|
1073
|
-
encodeReference,
|
|
1074
1357
|
encodingOptions,
|
|
1075
1358
|
getSpaceKeyFromDoc,
|
|
1076
1359
|
hasInvitationExpired,
|
|
1077
|
-
isEncodedReferenceObject,
|
|
1078
1360
|
mapFeedIndexesToTimeframe,
|
|
1079
1361
|
mapTimeframeToFeedIndexes,
|
|
1080
1362
|
startAfter,
|