@dxos/echo-pipeline 0.4.10-main.697c7a4 → 0.4.10-main.6f3f81d
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-Y5YOH4CA.mjs → chunk-SYE4EK33.mjs} +29 -35
- package/dist/lib/browser/chunk-SYE4EK33.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +237 -141
- 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-ONMB6ZZF.cjs → chunk-WCTX6RNS.cjs} +34 -40
- package/dist/lib/node/chunk-WCTX6RNS.cjs.map +7 -0
- package/dist/lib/node/index.cjs +241 -150
- 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 +18 -9
- package/dist/types/src/automerge/automerge-host.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 +27 -0
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -0
- 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 +5 -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/space/space.d.ts +4 -8
- package/dist/types/src/space/space.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/dist/types/src/testing/test-agent-builder.d.ts +2 -2
- package/package.json +33 -30
- package/src/automerge/automerge-host.test.ts +19 -5
- package/src/automerge/automerge-host.ts +37 -27
- package/src/automerge/level.test.ts +43 -0
- package/src/automerge/leveldb-storage-adapter.ts +105 -0
- package/src/automerge/migrations.ts +41 -0
- package/src/automerge/storage-adapter.test.ts +90 -0
- package/src/automerge/types.ts +5 -3
- package/src/metadata/metadata-store.ts +17 -8
- package/src/space/space.test.ts +7 -7
- package/src/space/space.ts +6 -21
- package/src/testing/index.ts +1 -0
- package/src/testing/level.ts +11 -0
- package/dist/lib/browser/chunk-Y5YOH4CA.mjs.map +0 -7
- package/dist/lib/node/chunk-ONMB6ZZF.cjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,50 +18,48 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
AuthExtension: () =>
|
|
22
|
-
AuthStatus: () =>
|
|
21
|
+
AuthExtension: () => import_chunk_WCTX6RNS.AuthExtension,
|
|
22
|
+
AuthStatus: () => import_chunk_WCTX6RNS.AuthStatus,
|
|
23
23
|
AutomergeDocumentLoaderImpl: () => AutomergeDocumentLoaderImpl,
|
|
24
24
|
AutomergeHost: () => AutomergeHost,
|
|
25
25
|
AutomergeStorageAdapter: () => AutomergeStorageAdapter,
|
|
26
|
-
DataServiceImpl: () =>
|
|
26
|
+
DataServiceImpl: () => import_chunk_WCTX6RNS.DataServiceImpl,
|
|
27
27
|
LocalHostNetworkAdapter: () => LocalHostNetworkAdapter,
|
|
28
|
-
MOCK_AUTH_PROVIDER: () =>
|
|
29
|
-
MOCK_AUTH_VERIFIER: () =>
|
|
28
|
+
MOCK_AUTH_PROVIDER: () => import_chunk_WCTX6RNS.MOCK_AUTH_PROVIDER,
|
|
29
|
+
MOCK_AUTH_VERIFIER: () => import_chunk_WCTX6RNS.MOCK_AUTH_VERIFIER,
|
|
30
30
|
MeshNetworkAdapter: () => MeshNetworkAdapter,
|
|
31
|
-
MetadataStore: () =>
|
|
32
|
-
Pipeline: () =>
|
|
31
|
+
MetadataStore: () => import_chunk_WCTX6RNS.MetadataStore,
|
|
32
|
+
Pipeline: () => import_chunk_WCTX6RNS.Pipeline,
|
|
33
33
|
REFERENCE_TYPE_TAG: () => REFERENCE_TYPE_TAG,
|
|
34
|
-
SnapshotManager: () =>
|
|
35
|
-
SnapshotStore: () =>
|
|
36
|
-
Space: () =>
|
|
37
|
-
SpaceManager: () =>
|
|
38
|
-
SpaceProtocol: () =>
|
|
39
|
-
SpaceProtocolSession: () =>
|
|
40
|
-
TimeframeClock: () =>
|
|
41
|
-
codec: () =>
|
|
42
|
-
createMappedFeedWriter: () =>
|
|
34
|
+
SnapshotManager: () => import_chunk_WCTX6RNS.SnapshotManager,
|
|
35
|
+
SnapshotStore: () => import_chunk_WCTX6RNS.SnapshotStore,
|
|
36
|
+
Space: () => import_chunk_WCTX6RNS.Space,
|
|
37
|
+
SpaceManager: () => import_chunk_WCTX6RNS.SpaceManager,
|
|
38
|
+
SpaceProtocol: () => import_chunk_WCTX6RNS.SpaceProtocol,
|
|
39
|
+
SpaceProtocolSession: () => import_chunk_WCTX6RNS.SpaceProtocolSession,
|
|
40
|
+
TimeframeClock: () => import_chunk_WCTX6RNS.TimeframeClock,
|
|
41
|
+
codec: () => import_chunk_WCTX6RNS.codec,
|
|
42
|
+
createMappedFeedWriter: () => import_chunk_WCTX6RNS.createMappedFeedWriter,
|
|
43
43
|
decodeReference: () => decodeReference,
|
|
44
44
|
encodeReference: () => encodeReference,
|
|
45
45
|
getSpaceKeyFromDoc: () => getSpaceKeyFromDoc,
|
|
46
|
+
hasInvitationExpired: () => import_chunk_WCTX6RNS.hasInvitationExpired,
|
|
46
47
|
isEncodedReferenceObject: () => isEncodedReferenceObject,
|
|
47
|
-
mapFeedIndexesToTimeframe: () =>
|
|
48
|
-
mapTimeframeToFeedIndexes: () =>
|
|
49
|
-
startAfter: () =>
|
|
50
|
-
valueEncoding: () =>
|
|
48
|
+
mapFeedIndexesToTimeframe: () => import_chunk_WCTX6RNS.mapFeedIndexesToTimeframe,
|
|
49
|
+
mapTimeframeToFeedIndexes: () => import_chunk_WCTX6RNS.mapTimeframeToFeedIndexes,
|
|
50
|
+
startAfter: () => import_chunk_WCTX6RNS.startAfter,
|
|
51
|
+
valueEncoding: () => import_chunk_WCTX6RNS.valueEncoding
|
|
51
52
|
});
|
|
52
53
|
module.exports = __toCommonJS(node_exports);
|
|
53
|
-
var
|
|
54
|
+
var import_chunk_WCTX6RNS = require("./chunk-WCTX6RNS.cjs");
|
|
54
55
|
var import_automerge = require("@dxos/automerge/automerge");
|
|
55
56
|
var import_automerge_repo = require("@dxos/automerge/automerge-repo");
|
|
56
|
-
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
57
57
|
var import_context = require("@dxos/context");
|
|
58
58
|
var import_keys = require("@dxos/keys");
|
|
59
59
|
var import_log = require("@dxos/log");
|
|
60
60
|
var import_protocols = require("@dxos/protocols");
|
|
61
|
-
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
62
61
|
var import_tracing = require("@dxos/tracing");
|
|
63
62
|
var import_util = require("@dxos/util");
|
|
64
|
-
var import_util2 = require("@dxos/util");
|
|
65
63
|
var import_async = require("@dxos/async");
|
|
66
64
|
var import_automerge_repo2 = require("@dxos/automerge/automerge-repo");
|
|
67
65
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
@@ -72,112 +70,97 @@ var import_automerge_repo3 = require("@dxos/automerge/automerge-repo");
|
|
|
72
70
|
var import_invariant2 = require("@dxos/invariant");
|
|
73
71
|
var import_log3 = require("@dxos/log");
|
|
74
72
|
var import_teleport_extension_automerge_replicator = require("@dxos/teleport-extension-automerge-replicator");
|
|
73
|
+
var import_automerge_repo_storage_indexeddb = require("@dxos/automerge/automerge-repo-storage-indexeddb");
|
|
74
|
+
var import_log4 = require("@dxos/log");
|
|
75
|
+
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
76
|
+
var import_util2 = require("@dxos/util");
|
|
75
77
|
var import_async3 = require("@dxos/async");
|
|
76
78
|
var import_context2 = require("@dxos/context");
|
|
77
79
|
var import_debug = require("@dxos/debug");
|
|
78
80
|
var import_invariant3 = require("@dxos/invariant");
|
|
79
|
-
var
|
|
81
|
+
var import_log5 = require("@dxos/log");
|
|
80
82
|
var import_echo_db = require("@dxos/echo-db");
|
|
81
|
-
var
|
|
82
|
-
constructor(
|
|
83
|
-
this.
|
|
83
|
+
var LevelDBStorageAdapter = class {
|
|
84
|
+
constructor(_params) {
|
|
85
|
+
this._params = _params;
|
|
84
86
|
this._state = "opened";
|
|
85
87
|
}
|
|
86
|
-
async load(
|
|
88
|
+
async load(keyArray) {
|
|
87
89
|
if (this._state !== "opened") {
|
|
88
90
|
return void 0;
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!size || size === 0) {
|
|
94
|
-
return void 0;
|
|
95
|
-
}
|
|
96
|
-
const buffer = await file.read(0, size);
|
|
97
|
-
return (0, import_util2.bufferToArray)(buffer);
|
|
92
|
+
return this._params.db.get(keyArray, {
|
|
93
|
+
...encodingOptions
|
|
94
|
+
}).catch((err) => err.code === "LEVEL_NOT_FOUND" ? void 0 : Promise.reject(err));
|
|
98
95
|
}
|
|
99
|
-
async save(
|
|
96
|
+
async save(keyArray, binary) {
|
|
100
97
|
if (this._state !== "opened") {
|
|
101
98
|
return void 0;
|
|
102
99
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
await
|
|
100
|
+
await this._params.callbacks?.beforeSave?.(keyArray);
|
|
101
|
+
await this._params.db.put(keyArray, Buffer.from(binary), {
|
|
102
|
+
...encodingOptions
|
|
103
|
+
});
|
|
104
|
+
await this._params.callbacks?.afterSave?.(keyArray);
|
|
108
105
|
}
|
|
109
|
-
async remove(
|
|
106
|
+
async remove(keyArray) {
|
|
110
107
|
if (this._state !== "opened") {
|
|
111
108
|
return void 0;
|
|
112
109
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
await this._params.db.del(keyArray, {
|
|
111
|
+
...encodingOptions
|
|
112
|
+
});
|
|
116
113
|
}
|
|
117
114
|
async loadRange(keyPrefix) {
|
|
118
115
|
if (this._state !== "opened") {
|
|
119
116
|
return [];
|
|
120
117
|
}
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
118
|
+
const result = [];
|
|
119
|
+
for await (const [key, value] of this._params.db.iterator({
|
|
120
|
+
gte: keyPrefix,
|
|
121
|
+
lte: [
|
|
122
|
+
...keyPrefix,
|
|
123
|
+
"\uFFFF"
|
|
124
|
+
],
|
|
125
|
+
...encodingOptions
|
|
126
|
+
})) {
|
|
127
|
+
result.push({
|
|
128
|
+
key,
|
|
129
|
+
data: value
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
132
133
|
}
|
|
133
134
|
async removeRange(keyPrefix) {
|
|
134
135
|
if (this._state !== "opened") {
|
|
135
136
|
return void 0;
|
|
136
137
|
}
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
const batch = this._params.db.batch();
|
|
139
|
+
for await (const [key] of this._params.db.iterator({
|
|
140
|
+
gte: keyPrefix,
|
|
141
|
+
lte: [
|
|
142
|
+
...keyPrefix,
|
|
143
|
+
"\uFFFF"
|
|
144
|
+
],
|
|
145
|
+
...encodingOptions
|
|
146
|
+
})) {
|
|
147
|
+
batch.del(key, {
|
|
148
|
+
...encodingOptions
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
await batch.write();
|
|
143
152
|
}
|
|
144
|
-
|
|
153
|
+
close() {
|
|
145
154
|
this._state = "closed";
|
|
146
155
|
}
|
|
147
|
-
_getFilename(key) {
|
|
148
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
149
|
-
}
|
|
150
|
-
_getKeyFromFilename(filename) {
|
|
151
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
152
|
-
}
|
|
153
156
|
};
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
async save(key, value) {
|
|
163
|
-
await this._callbacks.beforeSave?.(key);
|
|
164
|
-
await this._storage.save(key, value);
|
|
165
|
-
await this._callbacks.afterSave?.(key);
|
|
166
|
-
}
|
|
167
|
-
async remove(key) {
|
|
168
|
-
return this._storage.remove(key);
|
|
169
|
-
}
|
|
170
|
-
async loadRange(keyPrefix) {
|
|
171
|
-
return this._storage.loadRange(keyPrefix);
|
|
172
|
-
}
|
|
173
|
-
async removeRange(keyPrefix) {
|
|
174
|
-
return this._storage.removeRange(keyPrefix);
|
|
175
|
-
}
|
|
176
|
-
async close() {
|
|
177
|
-
if (this._storage instanceof AutomergeStorageAdapter) {
|
|
178
|
-
return this._storage.close();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
157
|
+
var keyEncoder = {
|
|
158
|
+
encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
|
|
159
|
+
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
|
|
160
|
+
};
|
|
161
|
+
var encodingOptions = {
|
|
162
|
+
keyEncoding: keyEncoder,
|
|
163
|
+
valueEncoding: "buffer"
|
|
181
164
|
};
|
|
182
165
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
|
|
183
166
|
var LocalHostNetworkAdapter = class extends import_automerge_repo2.NetworkAdapter {
|
|
@@ -397,6 +380,108 @@ var MeshNetworkAdapter = class extends import_automerge_repo3.NetworkAdapter {
|
|
|
397
380
|
return extension;
|
|
398
381
|
}
|
|
399
382
|
};
|
|
383
|
+
var AutomergeStorageAdapter = class {
|
|
384
|
+
constructor(_directory) {
|
|
385
|
+
this._directory = _directory;
|
|
386
|
+
this._state = "opened";
|
|
387
|
+
}
|
|
388
|
+
async load(key) {
|
|
389
|
+
if (this._state !== "opened") {
|
|
390
|
+
return void 0;
|
|
391
|
+
}
|
|
392
|
+
const filename = this._getFilename(key);
|
|
393
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
394
|
+
const { size } = await file.stat();
|
|
395
|
+
if (!size || size === 0) {
|
|
396
|
+
return void 0;
|
|
397
|
+
}
|
|
398
|
+
const buffer = await file.read(0, size);
|
|
399
|
+
return (0, import_util2.bufferToArray)(buffer);
|
|
400
|
+
}
|
|
401
|
+
async save(key, data) {
|
|
402
|
+
if (this._state !== "opened") {
|
|
403
|
+
return void 0;
|
|
404
|
+
}
|
|
405
|
+
const filename = this._getFilename(key);
|
|
406
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
407
|
+
await file.write(0, (0, import_util2.arrayToBuffer)(data));
|
|
408
|
+
await file.truncate?.(data.length);
|
|
409
|
+
await file.flush?.();
|
|
410
|
+
}
|
|
411
|
+
async remove(key) {
|
|
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.destroy();
|
|
418
|
+
}
|
|
419
|
+
async loadRange(keyPrefix) {
|
|
420
|
+
if (this._state !== "opened") {
|
|
421
|
+
return [];
|
|
422
|
+
}
|
|
423
|
+
const filename = this._getFilename(keyPrefix);
|
|
424
|
+
const entries = await this._directory.list();
|
|
425
|
+
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
426
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
427
|
+
const { size } = await file.stat();
|
|
428
|
+
const buffer = await file.read(0, size);
|
|
429
|
+
return {
|
|
430
|
+
key: this._getKeyFromFilename(entry),
|
|
431
|
+
data: (0, import_util2.bufferToArray)(buffer)
|
|
432
|
+
};
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
async removeRange(keyPrefix) {
|
|
436
|
+
if (this._state !== "opened") {
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
const filename = this._getFilename(keyPrefix);
|
|
440
|
+
const entries = await this._directory.list();
|
|
441
|
+
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
442
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
443
|
+
await file.destroy();
|
|
444
|
+
}));
|
|
445
|
+
}
|
|
446
|
+
async close() {
|
|
447
|
+
this._state = "closed";
|
|
448
|
+
}
|
|
449
|
+
_getFilename(key) {
|
|
450
|
+
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
451
|
+
}
|
|
452
|
+
_getKeyFromFilename(filename) {
|
|
453
|
+
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
457
|
+
var levelMigration = async ({ db, directory }) => {
|
|
458
|
+
const isNewLevel = !await db.iterator({
|
|
459
|
+
...encodingOptions
|
|
460
|
+
}).next();
|
|
461
|
+
if (!isNewLevel) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const oldStorageAdapter = directory.type === import_random_access_storage.StorageType.IDB ? new import_automerge_repo_storage_indexeddb.IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
465
|
+
const chunks = await oldStorageAdapter.loadRange([]);
|
|
466
|
+
if (chunks.length === 0) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const batch = db.batch();
|
|
470
|
+
import_log4.log.info("found chunks on old storage adapter", {
|
|
471
|
+
chunks: chunks.length
|
|
472
|
+
}, {
|
|
473
|
+
F: __dxlog_file3,
|
|
474
|
+
L: 36,
|
|
475
|
+
S: void 0,
|
|
476
|
+
C: (f, a) => f(...a)
|
|
477
|
+
});
|
|
478
|
+
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
479
|
+
data && batch.put(key, data, {
|
|
480
|
+
...encodingOptions
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
await batch.write();
|
|
484
|
+
};
|
|
400
485
|
function _ts_decorate(decorators, target, key, desc) {
|
|
401
486
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
402
487
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -407,26 +492,31 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
407
492
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
408
493
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
409
494
|
}
|
|
410
|
-
var
|
|
495
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
411
496
|
var AutomergeHost = class {
|
|
412
|
-
constructor({ directory, metadata }) {
|
|
497
|
+
constructor({ directory, db, metadata }) {
|
|
413
498
|
this._ctx = new import_context.Context();
|
|
414
499
|
this._authorizedDevices = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
415
500
|
this._updatingMetadata = /* @__PURE__ */ new Map();
|
|
416
501
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
502
|
+
this._directory = directory;
|
|
503
|
+
this._db = db;
|
|
417
504
|
this._metadata = metadata;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
this.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
505
|
+
}
|
|
506
|
+
async open() {
|
|
507
|
+
this._directory && await levelMigration({
|
|
508
|
+
db: await this._db,
|
|
509
|
+
directory: this._directory
|
|
510
|
+
});
|
|
511
|
+
this._storage = new LevelDBStorageAdapter({
|
|
512
|
+
db: await this._db,
|
|
425
513
|
callbacks: {
|
|
426
514
|
beforeSave: (params) => this._beforeSave(params)
|
|
427
515
|
}
|
|
428
516
|
});
|
|
429
517
|
this._peerId = `host-${import_keys.PublicKey.random().toHex()}`;
|
|
518
|
+
this._meshNetwork = new MeshNetworkAdapter();
|
|
519
|
+
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
430
520
|
this._repo = new import_automerge_repo.Repo({
|
|
431
521
|
peerId: this._peerId,
|
|
432
522
|
network: [
|
|
@@ -451,8 +541,8 @@ var AutomergeHost = class {
|
|
|
451
541
|
documentId,
|
|
452
542
|
isRequested
|
|
453
543
|
}, {
|
|
454
|
-
F:
|
|
455
|
-
L:
|
|
544
|
+
F: __dxlog_file4,
|
|
545
|
+
L: 111,
|
|
456
546
|
S: this,
|
|
457
547
|
C: (f, a) => f(...a)
|
|
458
548
|
});
|
|
@@ -465,8 +555,8 @@ var AutomergeHost = class {
|
|
|
465
555
|
peerId,
|
|
466
556
|
documentId
|
|
467
557
|
}, {
|
|
468
|
-
F:
|
|
469
|
-
L:
|
|
558
|
+
F: __dxlog_file4,
|
|
559
|
+
L: 118,
|
|
470
560
|
S: this,
|
|
471
561
|
C: (f, a) => f(...a)
|
|
472
562
|
});
|
|
@@ -479,8 +569,8 @@ var AutomergeHost = class {
|
|
|
479
569
|
peerId,
|
|
480
570
|
documentId
|
|
481
571
|
}, {
|
|
482
|
-
F:
|
|
483
|
-
L:
|
|
572
|
+
F: __dxlog_file4,
|
|
573
|
+
L: 127,
|
|
484
574
|
S: this,
|
|
485
575
|
C: (f, a) => f(...a)
|
|
486
576
|
});
|
|
@@ -496,16 +586,16 @@ var AutomergeHost = class {
|
|
|
496
586
|
spaceKey,
|
|
497
587
|
isAuthorized
|
|
498
588
|
}, {
|
|
499
|
-
F:
|
|
500
|
-
L:
|
|
589
|
+
F: __dxlog_file4,
|
|
590
|
+
L: 133,
|
|
501
591
|
S: this,
|
|
502
592
|
C: (f, a) => f(...a)
|
|
503
593
|
});
|
|
504
594
|
return isAuthorized;
|
|
505
595
|
} catch (err) {
|
|
506
596
|
import_log.log.catch(err, void 0, {
|
|
507
|
-
F:
|
|
508
|
-
L:
|
|
597
|
+
F: __dxlog_file4,
|
|
598
|
+
L: 143,
|
|
509
599
|
S: this,
|
|
510
600
|
C: (f, a) => f(...a)
|
|
511
601
|
});
|
|
@@ -524,6 +614,11 @@ var AutomergeHost = class {
|
|
|
524
614
|
});
|
|
525
615
|
}
|
|
526
616
|
}
|
|
617
|
+
async close() {
|
|
618
|
+
this._storage.close?.();
|
|
619
|
+
await this._clientNetwork.close();
|
|
620
|
+
await this._ctx.dispose();
|
|
621
|
+
}
|
|
527
622
|
get repo() {
|
|
528
623
|
return this._repo;
|
|
529
624
|
}
|
|
@@ -562,8 +657,8 @@ var AutomergeHost = class {
|
|
|
562
657
|
this._updatingMetadata.delete(event.handle.documentId);
|
|
563
658
|
}).catch((err) => {
|
|
564
659
|
this._ctx.disposed && import_log.log.catch(err, void 0, {
|
|
565
|
-
F:
|
|
566
|
-
L:
|
|
660
|
+
F: __dxlog_file4,
|
|
661
|
+
L: 207,
|
|
567
662
|
S: this,
|
|
568
663
|
C: (f, a) => f(...a)
|
|
569
664
|
});
|
|
@@ -595,11 +690,6 @@ var AutomergeHost = class {
|
|
|
595
690
|
_automergePeers() {
|
|
596
691
|
return this._repo.peers;
|
|
597
692
|
}
|
|
598
|
-
async close() {
|
|
599
|
-
await this._storage.close();
|
|
600
|
-
await this._clientNetwork.close();
|
|
601
|
-
await this._ctx.dispose();
|
|
602
|
-
}
|
|
603
693
|
//
|
|
604
694
|
// Methods for client-services.
|
|
605
695
|
//
|
|
@@ -627,8 +717,8 @@ var AutomergeHost = class {
|
|
|
627
717
|
spaceKey,
|
|
628
718
|
deviceKey
|
|
629
719
|
}, {
|
|
630
|
-
F:
|
|
631
|
-
L:
|
|
720
|
+
F: __dxlog_file4,
|
|
721
|
+
L: 274,
|
|
632
722
|
S: this,
|
|
633
723
|
C: (f, a) => f(...a)
|
|
634
724
|
});
|
|
@@ -676,7 +766,7 @@ var getSpaceKeyFromDoc = (doc) => {
|
|
|
676
766
|
}
|
|
677
767
|
return String(rawSpaceKey);
|
|
678
768
|
};
|
|
679
|
-
var
|
|
769
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
680
770
|
var AutomergeDocumentLoaderImpl = class {
|
|
681
771
|
constructor(_spaceKey, _repo) {
|
|
682
772
|
this._spaceKey = _spaceKey;
|
|
@@ -696,10 +786,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
696
786
|
return;
|
|
697
787
|
}
|
|
698
788
|
if (!spaceState.rootUrl) {
|
|
699
|
-
|
|
789
|
+
import_log5.log.error("Database opened with no rootUrl", {
|
|
700
790
|
spaceKey: this._spaceKey
|
|
701
791
|
}, {
|
|
702
|
-
F:
|
|
792
|
+
F: __dxlog_file5,
|
|
703
793
|
L: 66,
|
|
704
794
|
S: this,
|
|
705
795
|
C: (f, a) => f(...a)
|
|
@@ -709,7 +799,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
709
799
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
710
800
|
const doc = existingDocHandle.docSync();
|
|
711
801
|
(0, import_invariant3.invariant)(doc, void 0, {
|
|
712
|
-
F:
|
|
802
|
+
F: __dxlog_file5,
|
|
713
803
|
L: 71,
|
|
714
804
|
S: this,
|
|
715
805
|
A: [
|
|
@@ -725,7 +815,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
725
815
|
}
|
|
726
816
|
loadObjectDocument(objectId) {
|
|
727
817
|
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
728
|
-
F:
|
|
818
|
+
F: __dxlog_file5,
|
|
729
819
|
L: 80,
|
|
730
820
|
S: this,
|
|
731
821
|
A: [
|
|
@@ -738,7 +828,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
738
828
|
}
|
|
739
829
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
740
830
|
(0, import_invariant3.invariant)(spaceRootDoc, void 0, {
|
|
741
|
-
F:
|
|
831
|
+
F: __dxlog_file5,
|
|
742
832
|
L: 85,
|
|
743
833
|
S: this,
|
|
744
834
|
A: [
|
|
@@ -749,10 +839,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
749
839
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
750
840
|
if (documentUrl == null) {
|
|
751
841
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
752
|
-
|
|
842
|
+
import_log5.log.info("loading delayed until object links are initialized", {
|
|
753
843
|
objectId
|
|
754
844
|
}, {
|
|
755
|
-
F:
|
|
845
|
+
F: __dxlog_file5,
|
|
756
846
|
L: 89,
|
|
757
847
|
S: this,
|
|
758
848
|
C: (f, a) => f(...a)
|
|
@@ -773,7 +863,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
773
863
|
}
|
|
774
864
|
getSpaceRootDocHandle() {
|
|
775
865
|
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
776
|
-
F:
|
|
866
|
+
F: __dxlog_file5,
|
|
777
867
|
L: 107,
|
|
778
868
|
S: this,
|
|
779
869
|
A: [
|
|
@@ -785,7 +875,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
785
875
|
}
|
|
786
876
|
createDocumentForObject(objectId) {
|
|
787
877
|
(0, import_invariant3.invariant)(this._spaceRootDocHandle, void 0, {
|
|
788
|
-
F:
|
|
878
|
+
F: __dxlog_file5,
|
|
789
879
|
L: 112,
|
|
790
880
|
S: this,
|
|
791
881
|
A: [
|
|
@@ -824,11 +914,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
824
914
|
};
|
|
825
915
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
826
916
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
827
|
-
|
|
917
|
+
import_log5.log.warn("object already inlined in a different document, ignoring the link", {
|
|
828
918
|
...logMeta,
|
|
829
919
|
actualDocumentUrl: objectDocumentHandle.url
|
|
830
920
|
}, {
|
|
831
|
-
F:
|
|
921
|
+
F: __dxlog_file5,
|
|
832
922
|
L: 142,
|
|
833
923
|
S: this,
|
|
834
924
|
C: (f, a) => f(...a)
|
|
@@ -836,8 +926,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
836
926
|
continue;
|
|
837
927
|
}
|
|
838
928
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
839
|
-
|
|
840
|
-
F:
|
|
929
|
+
import_log5.log.warn("object document was already loaded", logMeta, {
|
|
930
|
+
F: __dxlog_file5,
|
|
841
931
|
L: 149,
|
|
842
932
|
S: this,
|
|
843
933
|
C: (f, a) => f(...a)
|
|
@@ -845,8 +935,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
845
935
|
continue;
|
|
846
936
|
}
|
|
847
937
|
const handle = this._repo.find(automergeUrl);
|
|
848
|
-
|
|
849
|
-
F:
|
|
938
|
+
import_log5.log.debug("document loading triggered", logMeta, {
|
|
939
|
+
F: __dxlog_file5,
|
|
850
940
|
L: 153,
|
|
851
941
|
S: this,
|
|
852
942
|
C: (f, a) => f(...a)
|
|
@@ -865,11 +955,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
865
955
|
break;
|
|
866
956
|
} catch (err) {
|
|
867
957
|
if (`${err}`.includes("Timeout")) {
|
|
868
|
-
|
|
958
|
+
import_log5.log.info("wraparound", {
|
|
869
959
|
id: docHandle.documentId,
|
|
870
960
|
state: docHandle.state
|
|
871
961
|
}, {
|
|
872
|
-
F:
|
|
962
|
+
F: __dxlog_file5,
|
|
873
963
|
L: 169,
|
|
874
964
|
S: this,
|
|
875
965
|
C: (f, a) => f(...a)
|
|
@@ -910,8 +1000,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
910
1000
|
docUrl: handle.url
|
|
911
1001
|
};
|
|
912
1002
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
913
|
-
|
|
914
|
-
F:
|
|
1003
|
+
import_log5.log.info("document loaded after all listeners were removed", logMeta, {
|
|
1004
|
+
F: __dxlog_file5,
|
|
915
1005
|
L: 205,
|
|
916
1006
|
S: this,
|
|
917
1007
|
C: (f, a) => f(...a)
|
|
@@ -920,8 +1010,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
920
1010
|
}
|
|
921
1011
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
922
1012
|
if (objectDocHandle?.url !== handle.url) {
|
|
923
|
-
|
|
924
|
-
F:
|
|
1013
|
+
import_log5.log.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1014
|
+
F: __dxlog_file5,
|
|
925
1015
|
L: 210,
|
|
926
1016
|
S: this,
|
|
927
1017
|
C: (f, a) => f(...a)
|
|
@@ -934,13 +1024,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
934
1024
|
});
|
|
935
1025
|
} catch (err) {
|
|
936
1026
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
937
|
-
|
|
1027
|
+
import_log5.log.warn("failed to load a document", {
|
|
938
1028
|
objectId,
|
|
939
1029
|
automergeUrl: handle.url,
|
|
940
1030
|
retryLoading: shouldRetryLoading,
|
|
941
1031
|
err
|
|
942
1032
|
}, {
|
|
943
|
-
F:
|
|
1033
|
+
F: __dxlog_file5,
|
|
944
1034
|
L: 216,
|
|
945
1035
|
S: this,
|
|
946
1036
|
C: (f, a) => f(...a)
|
|
@@ -988,6 +1078,7 @@ var isEncodedReferenceObject = (value) => typeof value === "object" && value !==
|
|
|
988
1078
|
decodeReference,
|
|
989
1079
|
encodeReference,
|
|
990
1080
|
getSpaceKeyFromDoc,
|
|
1081
|
+
hasInvitationExpired,
|
|
991
1082
|
isEncodedReferenceObject,
|
|
992
1083
|
mapFeedIndexesToTimeframe,
|
|
993
1084
|
mapTimeframeToFeedIndexes,
|