@dxos/echo-pipeline 0.4.10-main.3aa8c1b → 0.4.10-main.3c620fb
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-REQJ6WI6.mjs} +2 -1
- package/dist/lib/browser/index.mjs +235 -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/index.cjs +218 -129
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +7 -2
- 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/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 +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/testing/index.ts +1 -0
- package/src/testing/level.ts +11 -0
- /package/dist/lib/browser/{chunk-RA6MLCZM.mjs.map → chunk-REQJ6WI6.mjs.map} +0 -0
|
@@ -1903,6 +1903,7 @@ SpaceManager = _ts_decorate7([
|
|
|
1903
1903
|
], SpaceManager);
|
|
1904
1904
|
|
|
1905
1905
|
export {
|
|
1906
|
+
Buffer,
|
|
1906
1907
|
codec,
|
|
1907
1908
|
valueEncoding,
|
|
1908
1909
|
createMappedFeedWriter,
|
|
@@ -1924,4 +1925,4 @@ export {
|
|
|
1924
1925
|
SpaceProtocolSession,
|
|
1925
1926
|
SpaceManager
|
|
1926
1927
|
};
|
|
1927
|
-
//# sourceMappingURL=chunk-
|
|
1928
|
+
//# sourceMappingURL=chunk-REQJ6WI6.mjs.map
|
|
@@ -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,
|
|
@@ -20,124 +21,100 @@ import {
|
|
|
20
21
|
mapTimeframeToFeedIndexes,
|
|
21
22
|
startAfter,
|
|
22
23
|
valueEncoding
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-REQJ6WI6.mjs";
|
|
24
25
|
|
|
25
26
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
26
27
|
import { next as automerge, getHeads } from "@dxos/automerge/automerge";
|
|
27
28
|
import { Repo } from "@dxos/automerge/automerge-repo";
|
|
28
|
-
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
29
29
|
import { Context } from "@dxos/context";
|
|
30
30
|
import { PublicKey } from "@dxos/keys";
|
|
31
|
-
import { log as
|
|
31
|
+
import { log as log4 } from "@dxos/log";
|
|
32
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this._directory = _directory;
|
|
36
|
+
// packages/core/echo/echo-pipeline/src/automerge/leveldb-storage-adapter.ts
|
|
37
|
+
var LevelDBStorageAdapter = class {
|
|
38
|
+
constructor(_params) {
|
|
39
|
+
this._params = _params;
|
|
42
40
|
this._state = "opened";
|
|
43
41
|
}
|
|
44
|
-
async load(
|
|
42
|
+
async load(keyArray) {
|
|
45
43
|
if (this._state !== "opened") {
|
|
46
44
|
return void 0;
|
|
47
45
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!size || size === 0) {
|
|
52
|
-
return void 0;
|
|
53
|
-
}
|
|
54
|
-
const buffer = await file.read(0, size);
|
|
55
|
-
return bufferToArray(buffer);
|
|
46
|
+
return this._params.db.get(keyArray, {
|
|
47
|
+
...encodingOptions
|
|
48
|
+
}).catch((err) => err.code === "LEVEL_NOT_FOUND" ? void 0 : Promise.reject(err));
|
|
56
49
|
}
|
|
57
|
-
async save(
|
|
50
|
+
async save(keyArray, binary) {
|
|
58
51
|
if (this._state !== "opened") {
|
|
59
52
|
return void 0;
|
|
60
53
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await
|
|
54
|
+
await this._params.callbacks?.beforeSave?.(keyArray);
|
|
55
|
+
await this._params.db.put(keyArray, Buffer.from(binary), {
|
|
56
|
+
...encodingOptions
|
|
57
|
+
});
|
|
58
|
+
await this._params.callbacks?.afterSave?.(keyArray);
|
|
66
59
|
}
|
|
67
|
-
async remove(
|
|
60
|
+
async remove(keyArray) {
|
|
68
61
|
if (this._state !== "opened") {
|
|
69
62
|
return void 0;
|
|
70
63
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
await this._params.db.del(keyArray, {
|
|
65
|
+
...encodingOptions
|
|
66
|
+
});
|
|
74
67
|
}
|
|
75
68
|
async loadRange(keyPrefix) {
|
|
76
69
|
if (this._state !== "opened") {
|
|
77
70
|
return [];
|
|
78
71
|
}
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
72
|
+
const result = [];
|
|
73
|
+
for await (const [key, value] of this._params.db.iterator({
|
|
74
|
+
gte: keyPrefix,
|
|
75
|
+
lte: [
|
|
76
|
+
...keyPrefix,
|
|
77
|
+
"\uFFFF"
|
|
78
|
+
],
|
|
79
|
+
...encodingOptions
|
|
80
|
+
})) {
|
|
81
|
+
result.push({
|
|
82
|
+
key,
|
|
83
|
+
data: value
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
90
87
|
}
|
|
91
88
|
async removeRange(keyPrefix) {
|
|
92
89
|
if (this._state !== "opened") {
|
|
93
90
|
return void 0;
|
|
94
91
|
}
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
const batch = this._params.db.batch();
|
|
93
|
+
for await (const [key] of this._params.db.iterator({
|
|
94
|
+
gte: keyPrefix,
|
|
95
|
+
lte: [
|
|
96
|
+
...keyPrefix,
|
|
97
|
+
"\uFFFF"
|
|
98
|
+
],
|
|
99
|
+
...encodingOptions
|
|
100
|
+
})) {
|
|
101
|
+
batch.del(key, {
|
|
102
|
+
...encodingOptions
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
await batch.write();
|
|
101
106
|
}
|
|
102
|
-
|
|
107
|
+
close() {
|
|
103
108
|
this._state = "closed";
|
|
104
109
|
}
|
|
105
|
-
_getFilename(key) {
|
|
106
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
107
|
-
}
|
|
108
|
-
_getKeyFromFilename(filename) {
|
|
109
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
110
|
-
}
|
|
111
110
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
111
|
+
var keyEncoder = {
|
|
112
|
+
encode: (key) => Buffer.from(key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-")),
|
|
113
|
+
decode: (key) => Buffer.from(key).toString().split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"))
|
|
114
|
+
};
|
|
115
|
+
var encodingOptions = {
|
|
116
|
+
keyEncoding: keyEncoder,
|
|
117
|
+
valueEncoding: "buffer"
|
|
141
118
|
};
|
|
142
119
|
|
|
143
120
|
// packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts
|
|
@@ -372,6 +349,118 @@ var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
|
372
349
|
}
|
|
373
350
|
};
|
|
374
351
|
|
|
352
|
+
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
353
|
+
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
354
|
+
import { log as log3 } from "@dxos/log";
|
|
355
|
+
import { StorageType } from "@dxos/random-access-storage";
|
|
356
|
+
|
|
357
|
+
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
358
|
+
import { arrayToBuffer, bufferToArray } from "@dxos/util";
|
|
359
|
+
var AutomergeStorageAdapter = class {
|
|
360
|
+
constructor(_directory) {
|
|
361
|
+
this._directory = _directory;
|
|
362
|
+
this._state = "opened";
|
|
363
|
+
}
|
|
364
|
+
async load(key) {
|
|
365
|
+
if (this._state !== "opened") {
|
|
366
|
+
return void 0;
|
|
367
|
+
}
|
|
368
|
+
const filename = this._getFilename(key);
|
|
369
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
370
|
+
const { size } = await file.stat();
|
|
371
|
+
if (!size || size === 0) {
|
|
372
|
+
return void 0;
|
|
373
|
+
}
|
|
374
|
+
const buffer = await file.read(0, size);
|
|
375
|
+
return bufferToArray(buffer);
|
|
376
|
+
}
|
|
377
|
+
async save(key, data) {
|
|
378
|
+
if (this._state !== "opened") {
|
|
379
|
+
return void 0;
|
|
380
|
+
}
|
|
381
|
+
const filename = this._getFilename(key);
|
|
382
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
383
|
+
await file.write(0, arrayToBuffer(data));
|
|
384
|
+
await file.truncate?.(data.length);
|
|
385
|
+
await file.flush?.();
|
|
386
|
+
}
|
|
387
|
+
async remove(key) {
|
|
388
|
+
if (this._state !== "opened") {
|
|
389
|
+
return void 0;
|
|
390
|
+
}
|
|
391
|
+
const filename = this._getFilename(key);
|
|
392
|
+
const file = this._directory.getOrCreateFile(filename);
|
|
393
|
+
await file.destroy();
|
|
394
|
+
}
|
|
395
|
+
async loadRange(keyPrefix) {
|
|
396
|
+
if (this._state !== "opened") {
|
|
397
|
+
return [];
|
|
398
|
+
}
|
|
399
|
+
const filename = this._getFilename(keyPrefix);
|
|
400
|
+
const entries = await this._directory.list();
|
|
401
|
+
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
402
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
403
|
+
const { size } = await file.stat();
|
|
404
|
+
const buffer = await file.read(0, size);
|
|
405
|
+
return {
|
|
406
|
+
key: this._getKeyFromFilename(entry),
|
|
407
|
+
data: bufferToArray(buffer)
|
|
408
|
+
};
|
|
409
|
+
}));
|
|
410
|
+
}
|
|
411
|
+
async removeRange(keyPrefix) {
|
|
412
|
+
if (this._state !== "opened") {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
const filename = this._getFilename(keyPrefix);
|
|
416
|
+
const entries = await this._directory.list();
|
|
417
|
+
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
418
|
+
const file = this._directory.getOrCreateFile(entry);
|
|
419
|
+
await file.destroy();
|
|
420
|
+
}));
|
|
421
|
+
}
|
|
422
|
+
async close() {
|
|
423
|
+
this._state = "closed";
|
|
424
|
+
}
|
|
425
|
+
_getFilename(key) {
|
|
426
|
+
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
427
|
+
}
|
|
428
|
+
_getKeyFromFilename(filename) {
|
|
429
|
+
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// packages/core/echo/echo-pipeline/src/automerge/migrations.ts
|
|
434
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/migrations.ts";
|
|
435
|
+
var levelMigration = async ({ db, directory }) => {
|
|
436
|
+
const isNewLevel = !await db.iterator({
|
|
437
|
+
...encodingOptions
|
|
438
|
+
}).next();
|
|
439
|
+
if (!isNewLevel) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const oldStorageAdapter = directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory);
|
|
443
|
+
const chunks = await oldStorageAdapter.loadRange([]);
|
|
444
|
+
if (chunks.length === 0) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const batch = db.batch();
|
|
448
|
+
log3.info("found chunks on old storage adapter", {
|
|
449
|
+
chunks: chunks.length
|
|
450
|
+
}, {
|
|
451
|
+
F: __dxlog_file3,
|
|
452
|
+
L: 36,
|
|
453
|
+
S: void 0,
|
|
454
|
+
C: (f, a) => f(...a)
|
|
455
|
+
});
|
|
456
|
+
for (const { key, data } of await oldStorageAdapter.loadRange([])) {
|
|
457
|
+
data && batch.put(key, data, {
|
|
458
|
+
...encodingOptions
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
await batch.write();
|
|
462
|
+
};
|
|
463
|
+
|
|
375
464
|
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
376
465
|
function _ts_decorate(decorators, target, key, desc) {
|
|
377
466
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -383,9 +472,9 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
383
472
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
384
473
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
385
474
|
}
|
|
386
|
-
var
|
|
475
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
387
476
|
var AutomergeHost = class {
|
|
388
|
-
constructor({ directory, metadata }) {
|
|
477
|
+
constructor({ directory, db, metadata }) {
|
|
389
478
|
this._ctx = new Context();
|
|
390
479
|
/**
|
|
391
480
|
* spaceKey -> deviceKey[]
|
|
@@ -393,19 +482,24 @@ var AutomergeHost = class {
|
|
|
393
482
|
this._authorizedDevices = new ComplexMap(PublicKey.hash);
|
|
394
483
|
this._updatingMetadata = /* @__PURE__ */ new Map();
|
|
395
484
|
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
485
|
+
this._directory = directory;
|
|
486
|
+
this._db = db;
|
|
396
487
|
this._metadata = metadata;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
this.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
488
|
+
}
|
|
489
|
+
async open() {
|
|
490
|
+
this._directory && await levelMigration({
|
|
491
|
+
db: await this._db,
|
|
492
|
+
directory: this._directory
|
|
493
|
+
});
|
|
494
|
+
this._storage = new LevelDBStorageAdapter({
|
|
495
|
+
db: await this._db,
|
|
404
496
|
callbacks: {
|
|
405
497
|
beforeSave: (params) => this._beforeSave(params)
|
|
406
498
|
}
|
|
407
499
|
});
|
|
408
500
|
this._peerId = `host-${PublicKey.random().toHex()}`;
|
|
501
|
+
this._meshNetwork = new MeshNetworkAdapter();
|
|
502
|
+
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
409
503
|
this._repo = new Repo({
|
|
410
504
|
peerId: this._peerId,
|
|
411
505
|
network: [
|
|
@@ -425,13 +519,13 @@ var AutomergeHost = class {
|
|
|
425
519
|
const doc = this._repo.handles[documentId]?.docSync();
|
|
426
520
|
if (!doc) {
|
|
427
521
|
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
428
|
-
|
|
522
|
+
log4("doc share policy check", {
|
|
429
523
|
peerId,
|
|
430
524
|
documentId,
|
|
431
525
|
isRequested
|
|
432
526
|
}, {
|
|
433
|
-
F:
|
|
434
|
-
L:
|
|
527
|
+
F: __dxlog_file4,
|
|
528
|
+
L: 111,
|
|
435
529
|
S: this,
|
|
436
530
|
C: (f, a) => f(...a)
|
|
437
531
|
});
|
|
@@ -440,12 +534,12 @@ var AutomergeHost = class {
|
|
|
440
534
|
try {
|
|
441
535
|
const spaceKey = getSpaceKeyFromDoc(doc);
|
|
442
536
|
if (!spaceKey) {
|
|
443
|
-
|
|
537
|
+
log4("space key not found for share policy check", {
|
|
444
538
|
peerId,
|
|
445
539
|
documentId
|
|
446
540
|
}, {
|
|
447
|
-
F:
|
|
448
|
-
L:
|
|
541
|
+
F: __dxlog_file4,
|
|
542
|
+
L: 118,
|
|
449
543
|
S: this,
|
|
450
544
|
C: (f, a) => f(...a)
|
|
451
545
|
});
|
|
@@ -454,12 +548,12 @@ var AutomergeHost = class {
|
|
|
454
548
|
const authorizedDevices = this._authorizedDevices.get(PublicKey.from(spaceKey));
|
|
455
549
|
const deviceKeyHex = this.repo.peerMetadataByPeerId[peerId]?.dxos_deviceKey;
|
|
456
550
|
if (!deviceKeyHex) {
|
|
457
|
-
|
|
551
|
+
log4("device key not found for share policy check", {
|
|
458
552
|
peerId,
|
|
459
553
|
documentId
|
|
460
554
|
}, {
|
|
461
|
-
F:
|
|
462
|
-
L:
|
|
555
|
+
F: __dxlog_file4,
|
|
556
|
+
L: 127,
|
|
463
557
|
S: this,
|
|
464
558
|
C: (f, a) => f(...a)
|
|
465
559
|
});
|
|
@@ -467,7 +561,7 @@ var AutomergeHost = class {
|
|
|
467
561
|
}
|
|
468
562
|
const deviceKey = PublicKey.from(deviceKeyHex);
|
|
469
563
|
const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
|
|
470
|
-
|
|
564
|
+
log4("share policy check", {
|
|
471
565
|
localPeer: this._peerId,
|
|
472
566
|
remotePeer: peerId,
|
|
473
567
|
documentId,
|
|
@@ -475,16 +569,16 @@ var AutomergeHost = class {
|
|
|
475
569
|
spaceKey,
|
|
476
570
|
isAuthorized
|
|
477
571
|
}, {
|
|
478
|
-
F:
|
|
479
|
-
L:
|
|
572
|
+
F: __dxlog_file4,
|
|
573
|
+
L: 133,
|
|
480
574
|
S: this,
|
|
481
575
|
C: (f, a) => f(...a)
|
|
482
576
|
});
|
|
483
577
|
return isAuthorized;
|
|
484
578
|
} catch (err) {
|
|
485
|
-
|
|
486
|
-
F:
|
|
487
|
-
L:
|
|
579
|
+
log4.catch(err, void 0, {
|
|
580
|
+
F: __dxlog_file4,
|
|
581
|
+
L: 143,
|
|
488
582
|
S: this,
|
|
489
583
|
C: (f, a) => f(...a)
|
|
490
584
|
});
|
|
@@ -503,6 +597,11 @@ var AutomergeHost = class {
|
|
|
503
597
|
});
|
|
504
598
|
}
|
|
505
599
|
}
|
|
600
|
+
async close() {
|
|
601
|
+
this._storage.close?.();
|
|
602
|
+
await this._clientNetwork.close();
|
|
603
|
+
await this._ctx.dispose();
|
|
604
|
+
}
|
|
506
605
|
get repo() {
|
|
507
606
|
return this._repo;
|
|
508
607
|
}
|
|
@@ -540,9 +639,9 @@ var AutomergeHost = class {
|
|
|
540
639
|
const markingDirtyPromise = this._metadata.markDirty(idToLastHash).then(() => {
|
|
541
640
|
this._updatingMetadata.delete(event.handle.documentId);
|
|
542
641
|
}).catch((err) => {
|
|
543
|
-
this._ctx.disposed &&
|
|
544
|
-
F:
|
|
545
|
-
L:
|
|
642
|
+
this._ctx.disposed && log4.catch(err, void 0, {
|
|
643
|
+
F: __dxlog_file4,
|
|
644
|
+
L: 207,
|
|
546
645
|
S: this,
|
|
547
646
|
C: (f, a) => f(...a)
|
|
548
647
|
});
|
|
@@ -574,11 +673,6 @@ var AutomergeHost = class {
|
|
|
574
673
|
_automergePeers() {
|
|
575
674
|
return this._repo.peers;
|
|
576
675
|
}
|
|
577
|
-
async close() {
|
|
578
|
-
await this._storage.close();
|
|
579
|
-
await this._clientNetwork.close();
|
|
580
|
-
await this._ctx.dispose();
|
|
581
|
-
}
|
|
582
676
|
//
|
|
583
677
|
// Methods for client-services.
|
|
584
678
|
//
|
|
@@ -602,12 +696,12 @@ var AutomergeHost = class {
|
|
|
602
696
|
return this._meshNetwork.createExtension();
|
|
603
697
|
}
|
|
604
698
|
authorizeDevice(spaceKey, deviceKey) {
|
|
605
|
-
|
|
699
|
+
log4("authorizeDevice", {
|
|
606
700
|
spaceKey,
|
|
607
701
|
deviceKey
|
|
608
702
|
}, {
|
|
609
|
-
F:
|
|
610
|
-
L:
|
|
703
|
+
F: __dxlog_file4,
|
|
704
|
+
L: 274,
|
|
611
705
|
S: this,
|
|
612
706
|
C: (f, a) => f(...a)
|
|
613
707
|
});
|
|
@@ -661,8 +755,8 @@ import { Event } from "@dxos/async";
|
|
|
661
755
|
import { cancelWithContext } from "@dxos/context";
|
|
662
756
|
import { warnAfterTimeout } from "@dxos/debug";
|
|
663
757
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
664
|
-
import { log as
|
|
665
|
-
var
|
|
758
|
+
import { log as log5 } from "@dxos/log";
|
|
759
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-doc-loader.ts";
|
|
666
760
|
var AutomergeDocumentLoaderImpl = class {
|
|
667
761
|
constructor(_spaceKey, _repo) {
|
|
668
762
|
this._spaceKey = _spaceKey;
|
|
@@ -682,10 +776,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
682
776
|
return;
|
|
683
777
|
}
|
|
684
778
|
if (!spaceState.rootUrl) {
|
|
685
|
-
|
|
779
|
+
log5.error("Database opened with no rootUrl", {
|
|
686
780
|
spaceKey: this._spaceKey
|
|
687
781
|
}, {
|
|
688
|
-
F:
|
|
782
|
+
F: __dxlog_file5,
|
|
689
783
|
L: 66,
|
|
690
784
|
S: this,
|
|
691
785
|
C: (f, a) => f(...a)
|
|
@@ -695,7 +789,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
695
789
|
const existingDocHandle = await this._initDocHandle(ctx, spaceState.rootUrl);
|
|
696
790
|
const doc = existingDocHandle.docSync();
|
|
697
791
|
invariant3(doc, void 0, {
|
|
698
|
-
F:
|
|
792
|
+
F: __dxlog_file5,
|
|
699
793
|
L: 71,
|
|
700
794
|
S: this,
|
|
701
795
|
A: [
|
|
@@ -711,7 +805,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
711
805
|
}
|
|
712
806
|
loadObjectDocument(objectId) {
|
|
713
807
|
invariant3(this._spaceRootDocHandle, void 0, {
|
|
714
|
-
F:
|
|
808
|
+
F: __dxlog_file5,
|
|
715
809
|
L: 80,
|
|
716
810
|
S: this,
|
|
717
811
|
A: [
|
|
@@ -724,7 +818,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
724
818
|
}
|
|
725
819
|
const spaceRootDoc = this._spaceRootDocHandle.docSync();
|
|
726
820
|
invariant3(spaceRootDoc, void 0, {
|
|
727
|
-
F:
|
|
821
|
+
F: __dxlog_file5,
|
|
728
822
|
L: 85,
|
|
729
823
|
S: this,
|
|
730
824
|
A: [
|
|
@@ -735,10 +829,10 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
735
829
|
const documentUrl = (spaceRootDoc.links ?? {})[objectId];
|
|
736
830
|
if (documentUrl == null) {
|
|
737
831
|
this._objectsPendingDocumentLoad.add(objectId);
|
|
738
|
-
|
|
832
|
+
log5.info("loading delayed until object links are initialized", {
|
|
739
833
|
objectId
|
|
740
834
|
}, {
|
|
741
|
-
F:
|
|
835
|
+
F: __dxlog_file5,
|
|
742
836
|
L: 89,
|
|
743
837
|
S: this,
|
|
744
838
|
C: (f, a) => f(...a)
|
|
@@ -759,7 +853,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
759
853
|
}
|
|
760
854
|
getSpaceRootDocHandle() {
|
|
761
855
|
invariant3(this._spaceRootDocHandle, void 0, {
|
|
762
|
-
F:
|
|
856
|
+
F: __dxlog_file5,
|
|
763
857
|
L: 107,
|
|
764
858
|
S: this,
|
|
765
859
|
A: [
|
|
@@ -771,7 +865,7 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
771
865
|
}
|
|
772
866
|
createDocumentForObject(objectId) {
|
|
773
867
|
invariant3(this._spaceRootDocHandle, void 0, {
|
|
774
|
-
F:
|
|
868
|
+
F: __dxlog_file5,
|
|
775
869
|
L: 112,
|
|
776
870
|
S: this,
|
|
777
871
|
A: [
|
|
@@ -810,11 +904,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
810
904
|
};
|
|
811
905
|
const objectDocumentHandle = this._objectDocumentHandles.get(objectId);
|
|
812
906
|
if (objectDocumentHandle != null && objectDocumentHandle.url !== automergeUrl) {
|
|
813
|
-
|
|
907
|
+
log5.warn("object already inlined in a different document, ignoring the link", {
|
|
814
908
|
...logMeta,
|
|
815
909
|
actualDocumentUrl: objectDocumentHandle.url
|
|
816
910
|
}, {
|
|
817
|
-
F:
|
|
911
|
+
F: __dxlog_file5,
|
|
818
912
|
L: 142,
|
|
819
913
|
S: this,
|
|
820
914
|
C: (f, a) => f(...a)
|
|
@@ -822,8 +916,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
822
916
|
continue;
|
|
823
917
|
}
|
|
824
918
|
if (objectDocumentHandle?.url === automergeUrl) {
|
|
825
|
-
|
|
826
|
-
F:
|
|
919
|
+
log5.warn("object document was already loaded", logMeta, {
|
|
920
|
+
F: __dxlog_file5,
|
|
827
921
|
L: 149,
|
|
828
922
|
S: this,
|
|
829
923
|
C: (f, a) => f(...a)
|
|
@@ -831,8 +925,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
831
925
|
continue;
|
|
832
926
|
}
|
|
833
927
|
const handle = this._repo.find(automergeUrl);
|
|
834
|
-
|
|
835
|
-
F:
|
|
928
|
+
log5.debug("document loading triggered", logMeta, {
|
|
929
|
+
F: __dxlog_file5,
|
|
836
930
|
L: 153,
|
|
837
931
|
S: this,
|
|
838
932
|
C: (f, a) => f(...a)
|
|
@@ -851,11 +945,11 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
851
945
|
break;
|
|
852
946
|
} catch (err) {
|
|
853
947
|
if (`${err}`.includes("Timeout")) {
|
|
854
|
-
|
|
948
|
+
log5.info("wraparound", {
|
|
855
949
|
id: docHandle.documentId,
|
|
856
950
|
state: docHandle.state
|
|
857
951
|
}, {
|
|
858
|
-
F:
|
|
952
|
+
F: __dxlog_file5,
|
|
859
953
|
L: 169,
|
|
860
954
|
S: this,
|
|
861
955
|
C: (f, a) => f(...a)
|
|
@@ -896,8 +990,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
896
990
|
docUrl: handle.url
|
|
897
991
|
};
|
|
898
992
|
if (this.onObjectDocumentLoaded.listenerCount() === 0) {
|
|
899
|
-
|
|
900
|
-
F:
|
|
993
|
+
log5.info("document loaded after all listeners were removed", logMeta, {
|
|
994
|
+
F: __dxlog_file5,
|
|
901
995
|
L: 205,
|
|
902
996
|
S: this,
|
|
903
997
|
C: (f, a) => f(...a)
|
|
@@ -906,8 +1000,8 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
906
1000
|
}
|
|
907
1001
|
const objectDocHandle = this._objectDocumentHandles.get(objectId);
|
|
908
1002
|
if (objectDocHandle?.url !== handle.url) {
|
|
909
|
-
|
|
910
|
-
F:
|
|
1003
|
+
log5.warn("object was rebound while a document was loading, discarding handle", logMeta, {
|
|
1004
|
+
F: __dxlog_file5,
|
|
911
1005
|
L: 210,
|
|
912
1006
|
S: this,
|
|
913
1007
|
C: (f, a) => f(...a)
|
|
@@ -920,13 +1014,13 @@ var AutomergeDocumentLoaderImpl = class {
|
|
|
920
1014
|
});
|
|
921
1015
|
} catch (err) {
|
|
922
1016
|
const shouldRetryLoading = this.onObjectDocumentLoaded.listenerCount() > 0;
|
|
923
|
-
|
|
1017
|
+
log5.warn("failed to load a document", {
|
|
924
1018
|
objectId,
|
|
925
1019
|
automergeUrl: handle.url,
|
|
926
1020
|
retryLoading: shouldRetryLoading,
|
|
927
1021
|
err
|
|
928
1022
|
}, {
|
|
929
|
-
F:
|
|
1023
|
+
F: __dxlog_file5,
|
|
930
1024
|
L: 216,
|
|
931
1025
|
S: this,
|
|
932
1026
|
C: (f, a) => f(...a)
|