@dxos/echo-pipeline 0.4.10-main.c42bfdb → 0.4.10-main.cb83c78
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-RA6MLCZM.mjs → chunk-SYE4EK33.mjs} +17 -9
- package/dist/lib/browser/chunk-SYE4EK33.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +290 -229
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +8 -2
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-KGIYLJBT.cjs → chunk-WCTX6RNS.cjs} +19 -11
- package/dist/lib/node/chunk-WCTX6RNS.cjs.map +7 -0
- package/dist/lib/node/index.cjs +305 -247
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -13
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/automerge/automerge-host.d.ts +19 -17
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +1 -0
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/level.test.d.ts +2 -0
- package/dist/types/src/automerge/level.test.d.ts.map +1 -0
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +30 -0
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -0
- package/dist/types/src/automerge/local-host-network-adapter.d.ts +8 -1
- package/dist/types/src/automerge/local-host-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/migrations.d.ts +7 -0
- package/dist/types/src/automerge/migrations.d.ts.map +1 -0
- package/dist/types/src/automerge/storage-adapter.test.d.ts +2 -0
- package/dist/types/src/automerge/storage-adapter.test.d.ts.map +1 -0
- package/dist/types/src/automerge/types.d.ts +6 -0
- package/dist/types/src/automerge/types.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts +2 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/level.d.ts +3 -0
- package/dist/types/src/testing/level.d.ts.map +1 -0
- package/package.json +33 -30
- package/src/automerge/automerge-host.test.ts +22 -8
- package/src/automerge/automerge-host.ts +44 -113
- package/src/automerge/index.ts +1 -0
- package/src/automerge/level.test.ts +64 -0
- package/src/automerge/leveldb-storage-adapter.ts +117 -0
- package/src/automerge/local-host-network-adapter.ts +19 -13
- package/src/automerge/migrations.ts +41 -0
- package/src/automerge/storage-adapter.test.ts +90 -0
- package/src/automerge/types.ts +6 -3
- package/src/metadata/metadata-store.ts +17 -8
- package/src/testing/index.ts +1 -0
- package/src/testing/level.ts +11 -0
- package/dist/lib/browser/chunk-RA6MLCZM.mjs.map +0 -7
- package/dist/lib/node/chunk-KGIYLJBT.cjs.map +0 -7
|
@@ -2,6 +2,7 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
import {
|
|
3
3
|
AuthExtension,
|
|
4
4
|
AuthStatus,
|
|
5
|
+
Buffer,
|
|
5
6
|
DataServiceImpl,
|
|
6
7
|
MOCK_AUTH_PROVIDER,
|
|
7
8
|
MOCK_AUTH_VERIFIER,
|
|
@@ -16,142 +17,129 @@ import {
|
|
|
16
17
|
TimeframeClock,
|
|
17
18
|
codec,
|
|
18
19
|
createMappedFeedWriter,
|
|
20
|
+
hasInvitationExpired,
|
|
19
21
|
mapFeedIndexesToTimeframe,
|
|
20
22
|
mapTimeframeToFeedIndexes,
|
|
21
23
|
startAfter,
|
|
22
24
|
valueEncoding
|
|
23
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-SYE4EK33.mjs";
|
|
24
26
|
|
|
25
27
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
26
|
-
import { next as automerge
|
|
28
|
+
import { next as automerge } from "@dxos/automerge/automerge";
|
|
27
29
|
import { Repo } from "@dxos/automerge/automerge-repo";
|
|
28
|
-
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
29
30
|
import { Context } from "@dxos/context";
|
|
30
31
|
import { PublicKey } from "@dxos/keys";
|
|
31
32
|
import { log as log3 } from "@dxos/log";
|
|
32
|
-
import { idCodec } from "@dxos/protocols";
|
|
33
|
-
import { StorageType } from "@dxos/random-access-storage";
|
|
34
33
|
import { trace } from "@dxos/tracing";
|
|
35
34
|
import { ComplexMap, ComplexSet, defaultMap, mapValues } from "@dxos/util";
|
|
36
35
|
|
|
37
|
-
// packages/core/echo/echo-pipeline/src/automerge/
|
|
38
|
-
import {
|
|
39
|
-
var
|
|
40
|
-
constructor(
|
|
41
|
-
|
|
42
|
-
this.
|
|
36
|
+
// packages/core/echo/echo-pipeline/src/automerge/leveldb-storage-adapter.ts
|
|
37
|
+
import { LifecycleState, Resource } from "@dxos/context";
|
|
38
|
+
var LevelDBStorageAdapter = class extends Resource {
|
|
39
|
+
constructor(_params) {
|
|
40
|
+
super();
|
|
41
|
+
this._params = _params;
|
|
43
42
|
}
|
|
44
|
-
async load(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
async load(keyArray) {
|
|
44
|
+
try {
|
|
45
|
+
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
return await this._params.db.get(keyArray, {
|
|
49
|
+
...encodingOptions
|
|
50
|
+
});
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (isLevelDbNotFoundError(err)) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
throw err;
|
|
53
56
|
}
|
|
54
|
-
const buffer = await file.read(0, size);
|
|
55
|
-
return bufferToArray(buffer);
|
|
56
57
|
}
|
|
57
|
-
async save(
|
|
58
|
-
if (this.
|
|
58
|
+
async save(keyArray, binary) {
|
|
59
|
+
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
59
60
|
return void 0;
|
|
60
61
|
}
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const batch = this._params.db.batch();
|
|
63
|
+
await this._params.callbacks?.beforeSave?.({
|
|
64
|
+
path: keyArray,
|
|
65
|
+
batch
|
|
66
|
+
});
|
|
67
|
+
batch.put(keyArray, Buffer.from(binary), {
|
|
68
|
+
...encodingOptions
|
|
69
|
+
});
|
|
70
|
+
await batch.write();
|
|
71
|
+
await this._params.callbacks?.afterSave?.(keyArray);
|
|
66
72
|
}
|
|
67
|
-
async remove(
|
|
68
|
-
if (this.
|
|
73
|
+
async remove(keyArray) {
|
|
74
|
+
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
69
75
|
return void 0;
|
|
70
76
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
await this._params.db.del(keyArray, {
|
|
78
|
+
...encodingOptions
|
|
79
|
+
});
|
|
74
80
|
}
|
|
75
81
|
async loadRange(keyPrefix) {
|
|
76
|
-
if (this.
|
|
82
|
+
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
77
83
|
return [];
|
|
78
84
|
}
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
const result = [];
|
|
86
|
+
for await (const [key, value] of this._params.db.iterator({
|
|
87
|
+
gte: keyPrefix,
|
|
88
|
+
lte: [
|
|
89
|
+
...keyPrefix,
|
|
90
|
+
"\uFFFF"
|
|
91
|
+
],
|
|
92
|
+
...encodingOptions
|
|
93
|
+
})) {
|
|
94
|
+
result.push({
|
|
95
|
+
key,
|
|
96
|
+
data: value
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
90
100
|
}
|
|
91
101
|
async removeRange(keyPrefix) {
|
|
92
|
-
if (this.
|
|
102
|
+
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
93
103
|
return void 0;
|
|
94
104
|
}
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
_getKeyFromFilename(filename) {
|
|
109
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage–wrapper.ts
|
|
114
|
-
var AutomergeStorageWrapper = class {
|
|
115
|
-
constructor({ storage, callbacks }) {
|
|
116
|
-
this._storage = storage;
|
|
117
|
-
this._callbacks = callbacks;
|
|
118
|
-
}
|
|
119
|
-
async load(key) {
|
|
120
|
-
return this._storage.load(key);
|
|
121
|
-
}
|
|
122
|
-
async save(key, value) {
|
|
123
|
-
await this._callbacks.beforeSave?.(key);
|
|
124
|
-
await this._storage.save(key, value);
|
|
125
|
-
await this._callbacks.afterSave?.(key);
|
|
126
|
-
}
|
|
127
|
-
async remove(key) {
|
|
128
|
-
return this._storage.remove(key);
|
|
129
|
-
}
|
|
130
|
-
async loadRange(keyPrefix) {
|
|
131
|
-
return this._storage.loadRange(keyPrefix);
|
|
132
|
-
}
|
|
133
|
-
async removeRange(keyPrefix) {
|
|
134
|
-
return this._storage.removeRange(keyPrefix);
|
|
135
|
-
}
|
|
136
|
-
async close() {
|
|
137
|
-
if (this._storage instanceof AutomergeStorageAdapter) {
|
|
138
|
-
return this._storage.close();
|
|
105
|
+
const batch = this._params.db.batch();
|
|
106
|
+
for await (const [key] of this._params.db.iterator({
|
|
107
|
+
gte: keyPrefix,
|
|
108
|
+
lte: [
|
|
109
|
+
...keyPrefix,
|
|
110
|
+
"\uFFFF"
|
|
111
|
+
],
|
|
112
|
+
...encodingOptions
|
|
113
|
+
})) {
|
|
114
|
+
batch.del(key, {
|
|
115
|
+
...encodingOptions
|
|
116
|
+
});
|
|
139
117
|
}
|
|
118
|
+
await batch.write();
|
|
140
119
|
}
|
|
141
120
|
};
|
|
121
|
+
var keyEncoder = {
|
|
122
|
+
encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
|
|
123
|
+
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
|
|
124
|
+
};
|
|
125
|
+
var encodingOptions = {
|
|
126
|
+
keyEncoding: keyEncoder,
|
|
127
|
+
valueEncoding: "buffer"
|
|
128
|
+
};
|
|
129
|
+
var isLevelDbNotFoundError = (err) => err.code === "LEVEL_NOT_FOUND";
|
|
142
130
|
|
|
143
131
|
// packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts
|
|
144
132
|
import { Trigger } from "@dxos/async";
|
|
145
133
|
import { NetworkAdapter, cbor } from "@dxos/automerge/automerge-repo";
|
|
146
134
|
import { Stream } from "@dxos/codec-protobuf";
|
|
147
135
|
import { invariant } from "@dxos/invariant";
|
|
148
|
-
import { log } from "@dxos/log";
|
|
149
136
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
|
|
150
137
|
var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
151
138
|
constructor() {
|
|
152
139
|
super(...arguments);
|
|
153
140
|
this._peers = /* @__PURE__ */ new Map();
|
|
154
141
|
this._connected = new Trigger();
|
|
142
|
+
this._isConnected = false;
|
|
155
143
|
}
|
|
156
144
|
/**
|
|
157
145
|
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
@@ -161,15 +149,21 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
161
149
|
network: this
|
|
162
150
|
});
|
|
163
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Called by `Repo` to connect to the network.
|
|
154
|
+
*
|
|
155
|
+
* @param peerId Our peer Id.
|
|
156
|
+
*/
|
|
164
157
|
connect(peerId) {
|
|
165
158
|
this.peerId = peerId;
|
|
159
|
+
this._isConnected = true;
|
|
166
160
|
this._connected.wake();
|
|
167
161
|
}
|
|
168
162
|
send(message) {
|
|
169
163
|
const peer = this._peers.get(message.targetId);
|
|
170
164
|
invariant(peer, "Peer not found.", {
|
|
171
165
|
F: __dxlog_file,
|
|
172
|
-
L:
|
|
166
|
+
L: 51,
|
|
173
167
|
S: this,
|
|
174
168
|
A: [
|
|
175
169
|
"peer",
|
|
@@ -184,12 +178,17 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
184
178
|
}
|
|
185
179
|
disconnect() {
|
|
186
180
|
}
|
|
181
|
+
async whenConnected() {
|
|
182
|
+
await this._connected.wait({
|
|
183
|
+
timeout: 1e4
|
|
184
|
+
});
|
|
185
|
+
}
|
|
187
186
|
syncRepo({ id, syncMessage }) {
|
|
188
187
|
const peerId = this._getPeerId(id);
|
|
189
188
|
return new Stream(({ next, close }) => {
|
|
190
189
|
invariant(!this._peers.has(peerId), "Peer already connected.", {
|
|
191
190
|
F: __dxlog_file,
|
|
192
|
-
L:
|
|
191
|
+
L: 73,
|
|
193
192
|
S: this,
|
|
194
193
|
A: [
|
|
195
194
|
"!this._peers.has(peerId)",
|
|
@@ -211,35 +210,47 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
211
210
|
});
|
|
212
211
|
}
|
|
213
212
|
});
|
|
214
|
-
this.
|
|
215
|
-
timeout: 1e3
|
|
216
|
-
}).then(() => {
|
|
217
|
-
this.emit("peer-candidate", {
|
|
218
|
-
peerMetadata: {},
|
|
219
|
-
peerId
|
|
220
|
-
});
|
|
221
|
-
}).catch((err) => log.catch(err, void 0, {
|
|
213
|
+
invariant(this._isConnected, void 0, {
|
|
222
214
|
F: __dxlog_file,
|
|
223
|
-
L:
|
|
215
|
+
L: 90,
|
|
224
216
|
S: this,
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
A: [
|
|
218
|
+
"this._isConnected",
|
|
219
|
+
""
|
|
220
|
+
]
|
|
221
|
+
});
|
|
222
|
+
this.emit("peer-candidate", {
|
|
223
|
+
peerMetadata: {},
|
|
224
|
+
peerId
|
|
225
|
+
});
|
|
227
226
|
});
|
|
228
227
|
}
|
|
229
228
|
async sendSyncMessage({ id, syncMessage }) {
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
invariant(this._isConnected, void 0, {
|
|
230
|
+
F: __dxlog_file,
|
|
231
|
+
L: 99,
|
|
232
|
+
S: this,
|
|
233
|
+
A: [
|
|
234
|
+
"this._isConnected",
|
|
235
|
+
""
|
|
236
|
+
]
|
|
232
237
|
});
|
|
233
238
|
const message = cbor.decode(syncMessage);
|
|
234
239
|
this.emit("message", message);
|
|
235
240
|
}
|
|
236
241
|
async getHostInfo() {
|
|
237
|
-
|
|
238
|
-
|
|
242
|
+
invariant(this._isConnected, void 0, {
|
|
243
|
+
F: __dxlog_file,
|
|
244
|
+
L: 105,
|
|
245
|
+
S: this,
|
|
246
|
+
A: [
|
|
247
|
+
"this._isConnected",
|
|
248
|
+
""
|
|
249
|
+
]
|
|
239
250
|
});
|
|
240
251
|
invariant(this.peerId, "Peer id not set.", {
|
|
241
252
|
F: __dxlog_file,
|
|
242
|
-
L:
|
|
253
|
+
L: 106,
|
|
243
254
|
S: this,
|
|
244
255
|
A: [
|
|
245
256
|
"this.peerId",
|
|
@@ -259,7 +270,7 @@ var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
|
259
270
|
import { Trigger as Trigger2 } from "@dxos/async";
|
|
260
271
|
import { NetworkAdapter as NetworkAdapter2, cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
261
272
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
262
|
-
import { log
|
|
273
|
+
import { log } from "@dxos/log";
|
|
263
274
|
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
264
275
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
|
|
265
276
|
var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
@@ -294,7 +305,7 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
294
305
|
});
|
|
295
306
|
extension.sendSyncMessage({
|
|
296
307
|
payload: cbor2.encode(message)
|
|
297
|
-
}).catch((err) =>
|
|
308
|
+
}).catch((err) => log.catch(err, void 0, {
|
|
298
309
|
F: __dxlog_file2,
|
|
299
310
|
L: 39,
|
|
300
311
|
S: this,
|
|
@@ -319,7 +330,7 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
319
330
|
}, {
|
|
320
331
|
onStartReplication: async (info, remotePeerId) => {
|
|
321
332
|
await this._connected.wait();
|
|
322
|
-
|
|
333
|
+
log("onStartReplication", {
|
|
323
334
|
id: info.id,
|
|
324
335
|
thisPeerId: this.peerId,
|
|
325
336
|
remotePeerId: remotePeerId.toHex()
|
|
@@ -332,7 +343,7 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
332
343
|
if (!this._extensions.has(info.id)) {
|
|
333
344
|
peerInfo = info;
|
|
334
345
|
this._extensions.set(info.id, extension);
|
|
335
|
-
|
|
346
|
+
log("peer-candidate", {
|
|
336
347
|
id: info.id,
|
|
337
348
|
thisPeerId: this.peerId,
|
|
338
349
|
remotePeerId: remotePeerId.toHex()
|
|
@@ -372,6 +383,118 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
372
383
|
}
|
|
373
384
|
};
|
|
374
385
|
|
|
386
|
+
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
387
|
+
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
388
|
+
import { log as log2 } from "@dxos/log";
|
|
389
|
+
import { StorageType } from "@dxos/random-access-storage";
|
|
390
|
+
|
|
391
|
+
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
392
|
+
import { arrayToBuffer, bufferToArray } from "@dxos/util";
|
|
393
|
+
var AutomergeStorageAdapter = class {
|
|
394
|
+
constructor(_directory) {
|
|
395
|
+
this._directory = _directory;
|
|
396
|
+
this._state = "opened";
|
|
397
|
+
}
|
|
398
|
+
async load(key) {
|
|
399
|
+
if (this._state !== "opened") {
|
|
400
|
+
return void 0;
|
|
401
|
+
}
|
|
402
|
+
const filename = this._getFilename(key);
|
|
403
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
404
|
+
const { size } = await file.stat();
|
|
405
|
+
if (!size || size === 0) {
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
const buffer = await file.read(0, size);
|
|
409
|
+
return bufferToArray(buffer);
|
|
410
|
+
}
|
|
411
|
+
async save(key, data) {
|
|
412
|
+
if (this._state !== "opened") {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
const filename = this._getFilename(key);
|
|
416
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
417
|
+
await file.write(0, arrayToBuffer(data));
|
|
418
|
+
await file.truncate?.(data.length);
|
|
419
|
+
await file.flush?.();
|
|
420
|
+
}
|
|
421
|
+
async remove(key) {
|
|
422
|
+
if (this._state !== "opened") {
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
const filename = this._getFilename(key);
|
|
426
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
427
|
+
await file.destroy();
|
|
428
|
+
}
|
|
429
|
+
async loadRange(keyPrefix) {
|
|
430
|
+
if (this._state !== "opened") {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
const filename = this._getFilename(keyPrefix);
|
|
434
|
+
const entries = await this._directory.list();
|
|
435
|
+
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
436
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
437
|
+
const { size } = await file.stat();
|
|
438
|
+
const buffer = await file.read(0, size);
|
|
439
|
+
return {
|
|
440
|
+
key: this._getKeyFromFilename(entry),
|
|
441
|
+
data: bufferToArray(buffer)
|
|
442
|
+
};
|
|
443
|
+
}));
|
|
444
|
+
}
|
|
445
|
+
async removeRange(keyPrefix) {
|
|
446
|
+
if (this._state !== "opened") {
|
|
447
|
+
return void 0;
|
|
448
|
+
}
|
|
449
|
+
const filename = this._getFilename(keyPrefix);
|
|
450
|
+
const entries = await this._directory.list();
|
|
451
|
+
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
452
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
453
|
+
await file.destroy();
|
|
454
|
+
}));
|
|
455
|
+
}
|
|
456
|
+
async close() {
|
|
457
|
+
this._state = "closed";
|
|
458
|
+
}
|
|
459
|
+
_getFilename(key) {
|
|
460
|
+
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
461
|
+
}
|
|
462
|
+
_getKeyFromFilename(filename) {
|
|
463
|
+
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
468
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
469
|
+
var levelMigration = async ({ db, directory }) => {
|
|
470
|
+
const isNewLevel = !await db.iterator({
|
|
471
|
+
...encodingOptions
|
|
472
|
+
}).next();
|
|
473
|
+
if (!isNewLevel) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const oldStorageAdapter = directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
477
|
+
const chunks = await oldStorageAdapter.loadRange([]);
|
|
478
|
+
if (chunks.length === 0) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const batch = db.batch();
|
|
482
|
+
log2.info("found chunks on old storage adapter", {
|
|
483
|
+
chunks: chunks.length
|
|
484
|
+
}, {
|
|
485
|
+
F: __dxlog_file3,
|
|
486
|
+
L: 36,
|
|
487
|
+
S: void 0,
|
|
488
|
+
C: (f, a) => f(...a)
|
|
489
|
+
});
|
|
490
|
+
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
491
|
+
data && batch.put(key, data, {
|
|
492
|
+
...encodingOptions
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
await batch.write();
|
|
496
|
+
};
|
|
497
|
+
|
|
375
498
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
376
499
|
function _ts_decorate(decorators, target, key, desc) {
|
|
377
500
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -383,29 +506,32 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
383
506
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
384
507
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
385
508
|
}
|
|
386
|
-
var
|
|
509
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
387
510
|
var AutomergeHost = class {
|
|
388
|
-
constructor({ directory,
|
|
511
|
+
constructor({ directory, db, storageCallbacks }) {
|
|
389
512
|
this._ctx = new Context();
|
|
390
513
|
/**
|
|
391
514
|
* spaceKey -> deviceKey[]
|
|
392
515
|
*/
|
|
393
516
|
this._authorizedDevices = new ComplexMap(PublicKey.hash);
|
|
394
|
-
this._updatingMetadata = /* @__PURE__ */ new Map();
|
|
395
517
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
396
|
-
this.
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
518
|
+
this._directory = directory;
|
|
519
|
+
this._db = db;
|
|
520
|
+
this._storageCallbacks = storageCallbacks;
|
|
521
|
+
}
|
|
522
|
+
async open() {
|
|
523
|
+
this._directory && await levelMigration({
|
|
524
|
+
db: this._db,
|
|
525
|
+
directory: this._directory
|
|
526
|
+
});
|
|
527
|
+
this._storage = new LevelDBStorageAdapter({
|
|
528
|
+
db: this._db,
|
|
529
|
+
callbacks: this._storageCallbacks
|
|
407
530
|
});
|
|
531
|
+
await this._storage.open?.();
|
|
408
532
|
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
533
|
+
this._meshNetwork = new MeshNetworkAdapter();
|
|
534
|
+
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
409
535
|
this._repo = new Repo({
|
|
410
536
|
peerId: this._peerId,
|
|
411
537
|
network: [
|
|
@@ -430,8 +556,8 @@ var AutomergeHost = class {
|
|
|
430
556
|
documentId,
|
|
431
557
|
isRequested
|
|
432
558
|
}, {
|
|
433
|
-
F:
|
|
434
|
-
L:
|
|
559
|
+
F: __dxlog_file4,
|
|
560
|
+
L: 98,
|
|
435
561
|
S: this,
|
|
436
562
|
C: (f, a) => f(...a)
|
|
437
563
|
});
|
|
@@ -444,8 +570,8 @@ var AutomergeHost = class {
|
|
|
444
570
|
peerId,
|
|
445
571
|
documentId
|
|
446
572
|
}, {
|
|
447
|
-
F:
|
|
448
|
-
L:
|
|
573
|
+
F: __dxlog_file4,
|
|
574
|
+
L: 105,
|
|
449
575
|
S: this,
|
|
450
576
|
C: (f, a) => f(...a)
|
|
451
577
|
});
|
|
@@ -458,8 +584,8 @@ var AutomergeHost = class {
|
|
|
458
584
|
peerId,
|
|
459
585
|
documentId
|
|
460
586
|
}, {
|
|
461
|
-
F:
|
|
462
|
-
L:
|
|
587
|
+
F: __dxlog_file4,
|
|
588
|
+
L: 114,
|
|
463
589
|
S: this,
|
|
464
590
|
C: (f, a) => f(...a)
|
|
465
591
|
});
|
|
@@ -475,16 +601,16 @@ var AutomergeHost = class {
|
|
|
475
601
|
spaceKey,
|
|
476
602
|
isAuthorized
|
|
477
603
|
}, {
|
|
478
|
-
F:
|
|
479
|
-
L:
|
|
604
|
+
F: __dxlog_file4,
|
|
605
|
+
L: 120,
|
|
480
606
|
S: this,
|
|
481
607
|
C: (f, a) => f(...a)
|
|
482
608
|
});
|
|
483
609
|
return isAuthorized;
|
|
484
610
|
} catch (err) {
|
|
485
611
|
log3.catch(err, void 0, {
|
|
486
|
-
F:
|
|
487
|
-
L:
|
|
612
|
+
F: __dxlog_file4,
|
|
613
|
+
L: 130,
|
|
488
614
|
S: this,
|
|
489
615
|
C: (f, a) => f(...a)
|
|
490
616
|
});
|
|
@@ -494,61 +620,16 @@ var AutomergeHost = class {
|
|
|
494
620
|
});
|
|
495
621
|
this._clientNetwork.ready();
|
|
496
622
|
this._meshNetwork.ready();
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
});
|
|
504
|
-
}
|
|
623
|
+
await this._clientNetwork.whenConnected();
|
|
624
|
+
}
|
|
625
|
+
async close() {
|
|
626
|
+
await this._storage.close?.();
|
|
627
|
+
await this._clientNetwork.close();
|
|
628
|
+
await this._ctx.dispose();
|
|
505
629
|
}
|
|
506
630
|
get repo() {
|
|
507
631
|
return this._repo;
|
|
508
632
|
}
|
|
509
|
-
async _beforeSave(path) {
|
|
510
|
-
const id = path[0];
|
|
511
|
-
if (this._updatingMetadata.has(id)) {
|
|
512
|
-
return this._updatingMetadata.get(id);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
_onDocument(handle) {
|
|
516
|
-
const listener = (event) => this._onUpdate(event);
|
|
517
|
-
handle.on("change", listener);
|
|
518
|
-
}
|
|
519
|
-
_onUpdate(event) {
|
|
520
|
-
if (this._metadata == null) {
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
const objectIds = getInlineChanges(event);
|
|
524
|
-
if (objectIds.length === 0) {
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
const heads = getHeads(event.doc);
|
|
528
|
-
const lastAvailableHash = heads.join("");
|
|
529
|
-
if (!lastAvailableHash) {
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
const encodedIds = objectIds.map((objectId) => idCodec.encode({
|
|
533
|
-
documentId: event.handle.documentId,
|
|
534
|
-
objectId
|
|
535
|
-
}));
|
|
536
|
-
const idToLastHash = new Map(encodedIds.map((id) => [
|
|
537
|
-
id,
|
|
538
|
-
lastAvailableHash
|
|
539
|
-
]));
|
|
540
|
-
const markingDirtyPromise = this._metadata.markDirty(idToLastHash).then(() => {
|
|
541
|
-
this._updatingMetadata.delete(event.handle.documentId);
|
|
542
|
-
}).catch((err) => {
|
|
543
|
-
this._ctx.disposed && log3.catch(err, void 0, {
|
|
544
|
-
F: __dxlog_file3,
|
|
545
|
-
L: 191,
|
|
546
|
-
S: this,
|
|
547
|
-
C: (f, a) => f(...a)
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
this._updatingMetadata.set(event.handle.documentId, markingDirtyPromise);
|
|
551
|
-
}
|
|
552
633
|
_automergeDocs() {
|
|
553
634
|
return mapValues(this._repo.handles, (handle) => ({
|
|
554
635
|
state: handle.state,
|
|
@@ -574,11 +655,6 @@ var AutomergeHost = class {
|
|
|
574
655
|
_automergePeers() {
|
|
575
656
|
return this._repo.peers;
|
|
576
657
|
}
|
|
577
|
-
async close() {
|
|
578
|
-
await this._storage.close();
|
|
579
|
-
await this._clientNetwork.close();
|
|
580
|
-
await this._ctx.dispose();
|
|
581
|
-
}
|
|
582
658
|
//
|
|
583
659
|
// Methods for client-services.
|
|
584
660
|
//
|
|
@@ -606,8 +682,8 @@ var AutomergeHost = class {
|
|
|
606
682
|
spaceKey,
|
|
607
683
|
deviceKey
|
|
608
684
|
}, {
|
|
609
|
-
F:
|
|
610
|
-
L:
|
|
685
|
+
F: __dxlog_file4,
|
|
686
|
+
L: 213,
|
|
611
687
|
S: this,
|
|
612
688
|
C: (f, a) => f(...a)
|
|
613
689
|
});
|
|
@@ -630,24 +706,6 @@ _ts_decorate([
|
|
|
630
706
|
AutomergeHost = _ts_decorate([
|
|
631
707
|
trace.resource()
|
|
632
708
|
], AutomergeHost);
|
|
633
|
-
var getInlineChanges = (event) => {
|
|
634
|
-
const inlineChangedObjectIds = /* @__PURE__ */ new Set();
|
|
635
|
-
for (const { path } of event.patches) {
|
|
636
|
-
if (path.length < 2) {
|
|
637
|
-
continue;
|
|
638
|
-
}
|
|
639
|
-
switch (path[0]) {
|
|
640
|
-
case "objects":
|
|
641
|
-
if (path.length >= 2) {
|
|
642
|
-
inlineChangedObjectIds.add(path[1]);
|
|
643
|
-
}
|
|
644
|
-
break;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
return [
|
|
648
|
-
...inlineChangedObjectIds
|
|
649
|
-
];
|
|
650
|
-
};
|
|
651
709
|
var getSpaceKeyFromDoc = (doc) => {
|
|
652
710
|
const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
|
|
653
711
|
if (rawSpaceKey == null) {
|
|
@@ -662,7 +720,7 @@ import { cancelWithContext } from "@dxos/context";
|
|
|
662
720
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
663
721
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
664
722
|
import { log as log4 } from "@dxos/log";
|
|
665
|
-
var
|
|
723
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
666
724
|
var AutomergeDocumentLoaderImpl = class {
|
|
667
725
|
constructor(_spaceKey, _repo) {
|
|
668
726
|
this._spaceKey = _spaceKey;
|
|
@@ -685,7 +743,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
685
743
|
log4.error("Database opened with no rootUrl", {
|
|
686
744
|
spaceKey: this._spaceKey
|
|
687
745
|
}, {
|
|
688
|
-
F:
|
|
746
|
+
F: __dxlog_file5,
|
|
689
747
|
L: 66,
|
|
690
748
|
S: this,
|
|
691
749
|
C: (f, a) => f(...a)
|
|
@@ -695,7 +753,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
695
753
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
696
754
|
const doc = existingDocHandle.docSync();
|
|
697
755
|
invariant3(doc, void 0, {
|
|
698
|
-
F:
|
|
756
|
+
F: __dxlog_file5,
|
|
699
757
|
L: 71,
|
|
700
758
|
S: this,
|
|
701
759
|
A: [
|
|
@@ -711,7 +769,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
711
769
|
}
|
|
712
770
|
loadObjectDocument(objectId) {
|
|
713
771
|
invariant3(this._spaceRootDocHandle, void 0, {
|
|
714
|
-
F:
|
|
772
|
+
F: __dxlog_file5,
|
|
715
773
|
L: 80,
|
|
716
774
|
S: this,
|
|
717
775
|
A: [
|
|
@@ -724,7 +782,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
724
782
|
}
|
|
725
783
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
726
784
|
invariant3(spaceRootDoc, void 0, {
|
|
727
|
-
F:
|
|
785
|
+
F: __dxlog_file5,
|
|
728
786
|
L: 85,
|
|
729
787
|
S: this,
|
|
730
788
|
A: [
|
|
@@ -738,7 +796,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
738
796
|
log4.info("loading delayed until object links are initialized", {
|
|
739
797
|
objectId
|
|
740
798
|
}, {
|
|
741
|
-
F:
|
|
799
|
+
F: __dxlog_file5,
|
|
742
800
|
L: 89,
|
|
743
801
|
S: this,
|
|
744
802
|
C: (f, a) => f(...a)
|
|
@@ -759,7 +817,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
759
817
|
}
|
|
760
818
|
getSpaceRootDocHandle() {
|
|
761
819
|
invariant3(this._spaceRootDocHandle, void 0, {
|
|
762
|
-
F:
|
|
820
|
+
F: __dxlog_file5,
|
|
763
821
|
L: 107,
|
|
764
822
|
S: this,
|
|
765
823
|
A: [
|
|
@@ -771,7 +829,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
771
829
|
}
|
|
772
830
|
createDocumentForObject(objectId) {
|
|
773
831
|
invariant3(this._spaceRootDocHandle, void 0, {
|
|
774
|
-
F:
|
|
832
|
+
F: __dxlog_file5,
|
|
775
833
|
L: 112,
|
|
776
834
|
S: this,
|
|
777
835
|
A: [
|
|
@@ -814,7 +872,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
814
872
|
...logMeta,
|
|
815
873
|
actualDocumentUrl: objectDocumentHandle.url
|
|
816
874
|
}, {
|
|
817
|
-
F:
|
|
875
|
+
F: __dxlog_file5,
|
|
818
876
|
L: 142,
|
|
819
877
|
S: this,
|
|
820
878
|
C: (f, a) => f(...a)
|
|
@@ -823,7 +881,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
823
881
|
}
|
|
824
882
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
825
883
|
log4.warn("object document was already loaded", logMeta, {
|
|
826
|
-
F:
|
|
884
|
+
F: __dxlog_file5,
|
|
827
885
|
L: 149,
|
|
828
886
|
S: this,
|
|
829
887
|
C: (f, a) => f(...a)
|
|
@@ -832,7 +890,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
832
890
|
}
|
|
833
891
|
const handle = this._repo.find(automergeUrl);
|
|
834
892
|
log4.debug("document loading triggered", logMeta, {
|
|
835
|
-
F:
|
|
893
|
+
F: __dxlog_file5,
|
|
836
894
|
L: 153,
|
|
837
895
|
S: this,
|
|
838
896
|
C: (f, a) => f(...a)
|
|
@@ -855,7 +913,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
855
913
|
id: docHandle.documentId,
|
|
856
914
|
state: docHandle.state
|
|
857
915
|
}, {
|
|
858
|
-
F:
|
|
916
|
+
F: __dxlog_file5,
|
|
859
917
|
L: 169,
|
|
860
918
|
S: this,
|
|
861
919
|
C: (f, a) => f(...a)
|
|
@@ -897,7 +955,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
897
955
|
};
|
|
898
956
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
899
957
|
log4.info("document loaded after all listeners were removed", logMeta, {
|
|
900
|
-
F:
|
|
958
|
+
F: __dxlog_file5,
|
|
901
959
|
L: 205,
|
|
902
960
|
S: this,
|
|
903
961
|
C: (f, a) => f(...a)
|
|
@@ -907,7 +965,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
907
965
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
908
966
|
if (objectDocHandle?.url !== handle.url) {
|
|
909
967
|
log4.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
910
|
-
F:
|
|
968
|
+
F: __dxlog_file5,
|
|
911
969
|
L: 210,
|
|
912
970
|
S: this,
|
|
913
971
|
C: (f, a) => f(...a)
|
|
@@ -926,7 +984,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
926
984
|
retryLoading: shouldRetryLoading,
|
|
927
985
|
err
|
|
928
986
|
}, {
|
|
929
|
-
F:
|
|
987
|
+
F: __dxlog_file5,
|
|
930
988
|
L: 216,
|
|
931
989
|
S: this,
|
|
932
990
|
C: (f, a) => f(...a)
|
|
@@ -957,6 +1015,7 @@ export {
|
|
|
957
1015
|
AutomergeHost,
|
|
958
1016
|
AutomergeStorageAdapter,
|
|
959
1017
|
DataServiceImpl,
|
|
1018
|
+
LevelDBStorageAdapter,
|
|
960
1019
|
LocalHostNetworkAdapter,
|
|
961
1020
|
MOCK_AUTH_PROVIDER,
|
|
962
1021
|
MOCK_AUTH_VERIFIER,
|
|
@@ -975,7 +1034,9 @@ export {
|
|
|
975
1034
|
createMappedFeedWriter,
|
|
976
1035
|
decodeReference,
|
|
977
1036
|
encodeReference,
|
|
1037
|
+
encodingOptions,
|
|
978
1038
|
getSpaceKeyFromDoc,
|
|
1039
|
+
hasInvitationExpired,
|
|
979
1040
|
isEncodedReferenceObject,
|
|
980
1041
|
mapFeedIndexesToTimeframe,
|
|
981
1042
|
mapTimeframeToFeedIndexes,
|