@dxos/echo-pipeline 0.4.8-next.fff1521 → 0.4.9-main.1057b49
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-3FVT6KX6.mjs → chunk-RTEEJ723.mjs} +289 -1807
- package/dist/lib/browser/chunk-RTEEJ723.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +633 -14
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +4 -332
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/chunk-7VZVCCNF.cjs +1948 -0
- package/dist/lib/node/chunk-7VZVCCNF.cjs.map +7 -0
- package/dist/lib/node/index.cjs +643 -34
- 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 -338
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/db-host/data-service.d.ts +3 -13
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/index.d.ts +0 -2
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/index.d.ts +0 -1
- package/dist/types/src/space/index.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +1 -4
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +1 -7
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +1 -3
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/package.json +30 -33
- package/src/automerge/automerge-host.ts +1 -1
- package/src/db-host/data-service.ts +10 -56
- package/src/db-host/index.ts +0 -2
- package/src/space/control-pipeline.ts +3 -1
- package/src/space/index.ts +0 -1
- package/src/space/space-manager.ts +1 -13
- package/src/space/space.test.ts +2 -112
- package/src/space/space.ts +2 -60
- package/src/testing/index.ts +0 -2
- package/src/testing/test-agent-builder.ts +3 -8
- package/dist/lib/browser/chunk-3FVT6KX6.mjs.map +0 -7
- package/dist/lib/node/chunk-WZ4WTAN6.cjs +0 -3454
- package/dist/lib/node/chunk-WZ4WTAN6.cjs.map +0 -7
- package/dist/types/src/db-host/data-service-host.d.ts +0 -38
- package/dist/types/src/db-host/data-service-host.d.ts.map +0 -1
- package/dist/types/src/db-host/database-host.d.ts +0 -27
- package/dist/types/src/db-host/database-host.d.ts.map +0 -1
- package/dist/types/src/space/data-pipeline.d.ts +0 -80
- package/dist/types/src/space/data-pipeline.d.ts.map +0 -1
- package/dist/types/src/space/data-pipeline.test.d.ts +0 -1
- package/dist/types/src/space/data-pipeline.test.d.ts.map +0 -1
- package/dist/types/src/testing/database-test-rig.d.ts +0 -67
- package/dist/types/src/testing/database-test-rig.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -14
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/tests/database.test.d.ts +0 -2
- package/dist/types/src/tests/database.test.d.ts.map +0 -1
- package/src/db-host/data-service-host.ts +0 -233
- package/src/db-host/database-host.ts +0 -63
- package/src/space/data-pipeline.test.ts +0 -3
- package/src/space/data-pipeline.ts +0 -468
- package/src/testing/database-test-rig.ts +0 -289
- package/src/testing/util.ts +0 -85
- package/src/tests/database.test.ts +0 -100
|
@@ -40,257 +40,6 @@ var createMappedFeedWriter = (mapper, writer) => {
|
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
// packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts
|
|
44
|
-
import { UpdateScheduler } from "@dxos/async";
|
|
45
|
-
import { Stream } from "@dxos/codec-protobuf";
|
|
46
|
-
import { Context } from "@dxos/context";
|
|
47
|
-
import { tagMutationsInBatch, setMetadataOnObject } from "@dxos/echo-db";
|
|
48
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
49
|
-
import { log } from "@dxos/log";
|
|
50
|
-
import { EchoEvent } from "@dxos/protocols/proto/dxos/echo/service";
|
|
51
|
-
import { ComplexMap } from "@dxos/util";
|
|
52
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
|
|
53
|
-
var MUTATION_LIMIT_PER_OBJECT = 10;
|
|
54
|
-
var DataServiceHost = class {
|
|
55
|
-
constructor(_itemManager, _itemDemuxer, _flush, _writeStream, _opts = {}) {
|
|
56
|
-
this._itemManager = _itemManager;
|
|
57
|
-
this._itemDemuxer = _itemDemuxer;
|
|
58
|
-
this._flush = _flush;
|
|
59
|
-
this._writeStream = _writeStream;
|
|
60
|
-
this._opts = _opts;
|
|
61
|
-
this._ctx = new Context();
|
|
62
|
-
this._clientTagMap = new ComplexMap(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
|
|
63
|
-
}
|
|
64
|
-
async open() {
|
|
65
|
-
}
|
|
66
|
-
async close() {
|
|
67
|
-
await this._ctx.dispose();
|
|
68
|
-
}
|
|
69
|
-
get _deferEvents() {
|
|
70
|
-
return this._opts.deferEvents ?? true;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Real-time subscription to data objects in a space.
|
|
74
|
-
*/
|
|
75
|
-
subscribe() {
|
|
76
|
-
return new Stream(({ next, close, ctx }) => {
|
|
77
|
-
ctx.onDispose(this._ctx.onDispose(close));
|
|
78
|
-
const objects = Array.from(this._itemManager.entities.values()).map((entity) => entity.createSnapshot());
|
|
79
|
-
next({
|
|
80
|
-
batch: {
|
|
81
|
-
objects
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
const updateScheduler = new UpdateScheduler(ctx, async () => {
|
|
85
|
-
flushPendingUpdate();
|
|
86
|
-
}, {
|
|
87
|
-
maxFrequency: 10
|
|
88
|
-
});
|
|
89
|
-
const pendingUpdates = [];
|
|
90
|
-
const mutationsPerObject = /* @__PURE__ */ new Map();
|
|
91
|
-
const clearPendingUpdates = () => {
|
|
92
|
-
pendingUpdates.length = 0;
|
|
93
|
-
mutationsPerObject.clear();
|
|
94
|
-
};
|
|
95
|
-
const flushPendingUpdate = () => {
|
|
96
|
-
const stagedEvents = [];
|
|
97
|
-
const objectsWithSnapshots = /* @__PURE__ */ new Set();
|
|
98
|
-
for (const [id, count] of mutationsPerObject) {
|
|
99
|
-
if (count >= MUTATION_LIMIT_PER_OBJECT) {
|
|
100
|
-
objectsWithSnapshots.add(id);
|
|
101
|
-
const entity = this._itemManager.entities.get(id);
|
|
102
|
-
if (entity) {
|
|
103
|
-
stagedEvents.push(entity.createSnapshot());
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
for (const obj of pendingUpdates) {
|
|
108
|
-
if (!objectsWithSnapshots.has(obj.objectId)) {
|
|
109
|
-
stagedEvents.push(obj);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
next({
|
|
113
|
-
batch: {
|
|
114
|
-
objects: stagedEvents
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
clearPendingUpdates();
|
|
118
|
-
};
|
|
119
|
-
this._itemDemuxer.snapshot.on(ctx, (snapshot) => {
|
|
120
|
-
clearPendingUpdates();
|
|
121
|
-
next({
|
|
122
|
-
action: EchoEvent.DatabaseAction.RESET,
|
|
123
|
-
batch: {
|
|
124
|
-
objects: snapshot.items
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
this._itemDemuxer.mutation.on(ctx, (message) => {
|
|
129
|
-
const { batch, meta } = message;
|
|
130
|
-
invariant2(!meta.clientTag, "Unexpected client tag in mutation message", {
|
|
131
|
-
F: __dxlog_file2,
|
|
132
|
-
L: 138,
|
|
133
|
-
S: this,
|
|
134
|
-
A: [
|
|
135
|
-
"!(meta as any).clientTag",
|
|
136
|
-
"'Unexpected client tag in mutation message'"
|
|
137
|
-
]
|
|
138
|
-
});
|
|
139
|
-
log("message", {
|
|
140
|
-
batch: batch.objects?.length,
|
|
141
|
-
meta
|
|
142
|
-
}, {
|
|
143
|
-
F: __dxlog_file2,
|
|
144
|
-
L: 139,
|
|
145
|
-
S: this,
|
|
146
|
-
C: (f, a) => f(...a)
|
|
147
|
-
});
|
|
148
|
-
const clientTag = this._clientTagMap.get([
|
|
149
|
-
message.meta.feedKey,
|
|
150
|
-
message.meta.seq
|
|
151
|
-
]);
|
|
152
|
-
batch.objects?.forEach((object) => {
|
|
153
|
-
setMetadataOnObject(object, {
|
|
154
|
-
...meta
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
if (clientTag) {
|
|
158
|
-
flushPendingUpdate();
|
|
159
|
-
tagMutationsInBatch(batch, clientTag, 0);
|
|
160
|
-
next({
|
|
161
|
-
clientTag,
|
|
162
|
-
feedKey: message.meta.feedKey,
|
|
163
|
-
seq: message.meta.seq,
|
|
164
|
-
batch
|
|
165
|
-
});
|
|
166
|
-
} else {
|
|
167
|
-
for (const obj of batch.objects ?? []) {
|
|
168
|
-
const newCount = (mutationsPerObject.get(obj.objectId) ?? 0) + 1;
|
|
169
|
-
mutationsPerObject.set(obj.objectId, newCount);
|
|
170
|
-
}
|
|
171
|
-
for (const obj of batch.objects ?? []) {
|
|
172
|
-
if ((mutationsPerObject.get(obj.objectId) ?? 0) < MUTATION_LIMIT_PER_OBJECT) {
|
|
173
|
-
pendingUpdates.push(obj);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (this._deferEvents) {
|
|
177
|
-
updateScheduler.trigger();
|
|
178
|
-
} else {
|
|
179
|
-
flushPendingUpdate();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
async write(request) {
|
|
186
|
-
invariant2(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
|
|
187
|
-
F: __dxlog_file2,
|
|
188
|
-
L: 184,
|
|
189
|
-
S: this,
|
|
190
|
-
A: [
|
|
191
|
-
"!this._ctx.disposed",
|
|
192
|
-
"'Cannot write to closed DataServiceHost'"
|
|
193
|
-
]
|
|
194
|
-
});
|
|
195
|
-
invariant2(this._writeStream, "Cannot write mutations in readonly mode", {
|
|
196
|
-
F: __dxlog_file2,
|
|
197
|
-
L: 185,
|
|
198
|
-
S: this,
|
|
199
|
-
A: [
|
|
200
|
-
"this._writeStream",
|
|
201
|
-
"'Cannot write mutations in readonly mode'"
|
|
202
|
-
]
|
|
203
|
-
});
|
|
204
|
-
log("write", {
|
|
205
|
-
clientTag: request.clientTag,
|
|
206
|
-
objectCount: request.batch.objects?.length ?? 0
|
|
207
|
-
}, {
|
|
208
|
-
F: __dxlog_file2,
|
|
209
|
-
L: 187,
|
|
210
|
-
S: this,
|
|
211
|
-
C: (f, a) => f(...a)
|
|
212
|
-
});
|
|
213
|
-
const message = createDataMessage(request.batch);
|
|
214
|
-
const receipt = await this._writeStream.write(message, {
|
|
215
|
-
afterWrite: async (receipt2) => {
|
|
216
|
-
if (request.clientTag) {
|
|
217
|
-
log("tag", {
|
|
218
|
-
clientTag: request.clientTag,
|
|
219
|
-
feedKey: receipt2.feedKey,
|
|
220
|
-
seq: receipt2.seq
|
|
221
|
-
}, {
|
|
222
|
-
F: __dxlog_file2,
|
|
223
|
-
L: 196,
|
|
224
|
-
S: this,
|
|
225
|
-
C: (f, a) => f(...a)
|
|
226
|
-
});
|
|
227
|
-
this._clientTagMap.set([
|
|
228
|
-
receipt2.feedKey,
|
|
229
|
-
receipt2.seq
|
|
230
|
-
], request.clientTag);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
return receipt;
|
|
235
|
-
}
|
|
236
|
-
async flush() {
|
|
237
|
-
await this._flush();
|
|
238
|
-
}
|
|
239
|
-
getHostInfo() {
|
|
240
|
-
throw new Error("Method not implemented.");
|
|
241
|
-
}
|
|
242
|
-
syncRepo(request) {
|
|
243
|
-
throw new Error("Method not implemented.");
|
|
244
|
-
}
|
|
245
|
-
sendSyncMessage(request) {
|
|
246
|
-
throw new Error("Method not implemented.");
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
var createDataMessage = (batch) => ({
|
|
250
|
-
batch: {
|
|
251
|
-
objects: batch.objects?.map((object) => ({
|
|
252
|
-
...object,
|
|
253
|
-
mutations: object.mutations?.map((mutation) => ({
|
|
254
|
-
...mutation,
|
|
255
|
-
meta: void 0
|
|
256
|
-
})),
|
|
257
|
-
meta: void 0
|
|
258
|
-
}))
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// packages/core/echo/echo-pipeline/src/db-host/database-host.ts
|
|
263
|
-
import { ItemDemuxer } from "@dxos/echo-db";
|
|
264
|
-
var DatabaseHost = class {
|
|
265
|
-
constructor(_outboundStream, _flush) {
|
|
266
|
-
this._outboundStream = _outboundStream;
|
|
267
|
-
this._flush = _flush;
|
|
268
|
-
}
|
|
269
|
-
get isReadOnly() {
|
|
270
|
-
return !!this._outboundStream;
|
|
271
|
-
}
|
|
272
|
-
get echoProcessor() {
|
|
273
|
-
return this._echoProcessor;
|
|
274
|
-
}
|
|
275
|
-
async open(itemManager, modelFactory) {
|
|
276
|
-
this._itemManager = itemManager;
|
|
277
|
-
this._itemManager._debugLabel = "host";
|
|
278
|
-
this._itemDemuxer = new ItemDemuxer(itemManager, modelFactory);
|
|
279
|
-
this._echoProcessor = this._itemDemuxer.open();
|
|
280
|
-
}
|
|
281
|
-
async close() {
|
|
282
|
-
}
|
|
283
|
-
getWriteStream() {
|
|
284
|
-
return this._outboundStream;
|
|
285
|
-
}
|
|
286
|
-
createSnapshot() {
|
|
287
|
-
return this._itemDemuxer.createSnapshot();
|
|
288
|
-
}
|
|
289
|
-
createDataServiceHost(opts = {}) {
|
|
290
|
-
return new DataServiceHost(this._itemManager, this._itemDemuxer, this._flush, this._outboundStream ?? void 0, opts);
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
|
|
294
43
|
// packages/core/echo/echo-pipeline/src/db-host/snapshot-manager.ts
|
|
295
44
|
import { cancelWithContext } from "@dxos/context";
|
|
296
45
|
import { PublicKey } from "@dxos/keys";
|
|
@@ -373,109 +122,17 @@ var SnapshotStore = class {
|
|
|
373
122
|
};
|
|
374
123
|
|
|
375
124
|
// packages/core/echo/echo-pipeline/src/db-host/data-service.ts
|
|
376
|
-
import { raise } from "@dxos/debug";
|
|
377
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
378
|
-
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
379
|
-
import { log as log2 } from "@dxos/log";
|
|
380
|
-
import { ComplexMap as ComplexMap2 } from "@dxos/util";
|
|
381
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service.ts";
|
|
382
|
-
var DataServiceSubscriptions = class {
|
|
383
|
-
constructor() {
|
|
384
|
-
this._spaces = new ComplexMap2(PublicKey2.hash);
|
|
385
|
-
}
|
|
386
|
-
clear() {
|
|
387
|
-
this._spaces.clear();
|
|
388
|
-
}
|
|
389
|
-
async registerSpace(spaceKey, host) {
|
|
390
|
-
log2("Registering space", {
|
|
391
|
-
spaceKey
|
|
392
|
-
}, {
|
|
393
|
-
F: __dxlog_file3,
|
|
394
|
-
L: 35,
|
|
395
|
-
S: this,
|
|
396
|
-
C: (f, a) => f(...a)
|
|
397
|
-
});
|
|
398
|
-
invariant3(!this._spaces.has(spaceKey), void 0, {
|
|
399
|
-
F: __dxlog_file3,
|
|
400
|
-
L: 36,
|
|
401
|
-
S: this,
|
|
402
|
-
A: [
|
|
403
|
-
"!this._spaces.has(spaceKey)",
|
|
404
|
-
""
|
|
405
|
-
]
|
|
406
|
-
});
|
|
407
|
-
await host.open();
|
|
408
|
-
this._spaces.set(spaceKey, host);
|
|
409
|
-
}
|
|
410
|
-
async unregisterSpace(spaceKey) {
|
|
411
|
-
log2("Unregistering space", {
|
|
412
|
-
spaceKey
|
|
413
|
-
}, {
|
|
414
|
-
F: __dxlog_file3,
|
|
415
|
-
L: 42,
|
|
416
|
-
S: this,
|
|
417
|
-
C: (f, a) => f(...a)
|
|
418
|
-
});
|
|
419
|
-
const host = this._spaces.get(spaceKey);
|
|
420
|
-
await host?.close();
|
|
421
|
-
this._spaces.delete(spaceKey);
|
|
422
|
-
}
|
|
423
|
-
getDataService(spaceKey) {
|
|
424
|
-
return this._spaces.get(spaceKey);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
125
|
var DataServiceImpl = class {
|
|
428
|
-
constructor(
|
|
429
|
-
this._subscriptions = _subscriptions;
|
|
126
|
+
constructor(_automergeHost) {
|
|
430
127
|
this._automergeHost = _automergeHost;
|
|
431
128
|
}
|
|
432
129
|
subscribe(request) {
|
|
433
|
-
|
|
434
|
-
F: __dxlog_file3,
|
|
435
|
-
L: 64,
|
|
436
|
-
S: this,
|
|
437
|
-
A: [
|
|
438
|
-
"request.spaceKey",
|
|
439
|
-
""
|
|
440
|
-
]
|
|
441
|
-
});
|
|
442
|
-
const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
|
|
443
|
-
return host.subscribe();
|
|
130
|
+
throw new Error("Deprecated.");
|
|
444
131
|
}
|
|
445
132
|
write(request) {
|
|
446
|
-
|
|
447
|
-
F: __dxlog_file3,
|
|
448
|
-
L: 71,
|
|
449
|
-
S: this,
|
|
450
|
-
A: [
|
|
451
|
-
"request.spaceKey",
|
|
452
|
-
""
|
|
453
|
-
]
|
|
454
|
-
});
|
|
455
|
-
invariant3(request.batch, void 0, {
|
|
456
|
-
F: __dxlog_file3,
|
|
457
|
-
L: 72,
|
|
458
|
-
S: this,
|
|
459
|
-
A: [
|
|
460
|
-
"request.batch",
|
|
461
|
-
""
|
|
462
|
-
]
|
|
463
|
-
});
|
|
464
|
-
const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
|
|
465
|
-
return host.write(request);
|
|
133
|
+
throw new Error("Deprecated.");
|
|
466
134
|
}
|
|
467
|
-
flush(request) {
|
|
468
|
-
invariant3(request.spaceKey, void 0, {
|
|
469
|
-
F: __dxlog_file3,
|
|
470
|
-
L: 79,
|
|
471
|
-
S: this,
|
|
472
|
-
A: [
|
|
473
|
-
"request.spaceKey",
|
|
474
|
-
""
|
|
475
|
-
]
|
|
476
|
-
});
|
|
477
|
-
const host = this._subscriptions.getDataService(request.spaceKey) ?? raise(new Error(`space not found: ${request.spaceKey}`));
|
|
478
|
-
return host.flush();
|
|
135
|
+
async flush(request) {
|
|
479
136
|
}
|
|
480
137
|
// Automerge specific.
|
|
481
138
|
async getHostInfo(request) {
|
|
@@ -492,13 +149,13 @@ var DataServiceImpl = class {
|
|
|
492
149
|
// packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
|
|
493
150
|
import CRC32 from "crc-32";
|
|
494
151
|
import { Event, scheduleTaskInterval, synchronized } from "@dxos/async";
|
|
495
|
-
import { Context
|
|
496
|
-
import { invariant as
|
|
497
|
-
import { PublicKey as
|
|
498
|
-
import { log
|
|
152
|
+
import { Context } from "@dxos/context";
|
|
153
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
154
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
155
|
+
import { log } from "@dxos/log";
|
|
499
156
|
import { DataCorruptionError, STORAGE_VERSION, schema as schema4 } from "@dxos/protocols";
|
|
500
157
|
import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
|
|
501
|
-
import { ComplexMap
|
|
158
|
+
import { ComplexMap, arrayToBuffer, forEachAsync, isNotNullOrUndefined } from "@dxos/util";
|
|
502
159
|
function _ts_decorate(decorators, target, key, desc) {
|
|
503
160
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
504
161
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -509,7 +166,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
509
166
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
510
167
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
511
168
|
}
|
|
512
|
-
var
|
|
169
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
|
|
513
170
|
var EXPIRED_INVITATION_CLEANUP_INTERVAL = 60 * 60 * 1e3;
|
|
514
171
|
var emptyEchoMetadata = () => ({
|
|
515
172
|
version: STORAGE_VERSION,
|
|
@@ -523,10 +180,10 @@ var LargeSpaceMetadata = schema4.getCodecForType("dxos.echo.metadata.LargeSpaceM
|
|
|
523
180
|
var MetadataStore = class {
|
|
524
181
|
constructor(directory) {
|
|
525
182
|
this._metadata = emptyEchoMetadata();
|
|
526
|
-
this._spaceLargeMetadata = new
|
|
183
|
+
this._spaceLargeMetadata = new ComplexMap(PublicKey2.hash);
|
|
527
184
|
this._metadataFile = void 0;
|
|
528
185
|
this.update = new Event();
|
|
529
|
-
this._invitationCleanupCtx = new
|
|
186
|
+
this._invitationCleanupCtx = new Context();
|
|
530
187
|
this._directory = directory;
|
|
531
188
|
}
|
|
532
189
|
get metadata() {
|
|
@@ -550,12 +207,12 @@ var MetadataStore = class {
|
|
|
550
207
|
}
|
|
551
208
|
const dataSize = fromBytesInt32(await file.read(0, 4));
|
|
552
209
|
const checksum = fromBytesInt32(await file.read(4, 4));
|
|
553
|
-
|
|
210
|
+
log("loaded", {
|
|
554
211
|
size: dataSize,
|
|
555
212
|
checksum,
|
|
556
213
|
name: file.filename
|
|
557
214
|
}, {
|
|
558
|
-
F:
|
|
215
|
+
F: __dxlog_file2,
|
|
559
216
|
L: 89,
|
|
560
217
|
S: this,
|
|
561
218
|
C: (f, a) => f(...a)
|
|
@@ -587,11 +244,11 @@ var MetadataStore = class {
|
|
|
587
244
|
result.writeInt32LE(checksum, 4);
|
|
588
245
|
encoded.copy(result, 8);
|
|
589
246
|
await file.write(0, result);
|
|
590
|
-
|
|
247
|
+
log("saved", {
|
|
591
248
|
size: encoded.length,
|
|
592
249
|
checksum
|
|
593
250
|
}, {
|
|
594
|
-
F:
|
|
251
|
+
F: __dxlog_file2,
|
|
595
252
|
L: 124,
|
|
596
253
|
S: this,
|
|
597
254
|
C: (f, a) => f(...a)
|
|
@@ -621,10 +278,10 @@ var MetadataStore = class {
|
|
|
621
278
|
space.state ??= SpaceState.ACTIVE;
|
|
622
279
|
});
|
|
623
280
|
} catch (err) {
|
|
624
|
-
|
|
281
|
+
log.error("failed to load metadata", {
|
|
625
282
|
err
|
|
626
283
|
}, {
|
|
627
|
-
F:
|
|
284
|
+
F: __dxlog_file2,
|
|
628
285
|
L: 156,
|
|
629
286
|
S: this,
|
|
630
287
|
C: (f, a) => f(...a)
|
|
@@ -638,10 +295,10 @@ var MetadataStore = class {
|
|
|
638
295
|
try {
|
|
639
296
|
await this._loadSpaceLargeMetadata(key);
|
|
640
297
|
} catch (err) {
|
|
641
|
-
|
|
298
|
+
log.error("failed to load space large metadata", {
|
|
642
299
|
err
|
|
643
300
|
}, {
|
|
644
|
-
F:
|
|
301
|
+
F: __dxlog_file2,
|
|
645
302
|
L: 168,
|
|
646
303
|
S: this,
|
|
647
304
|
C: (f, a) => f(...a)
|
|
@@ -675,10 +332,10 @@ var MetadataStore = class {
|
|
|
675
332
|
this._spaceLargeMetadata.set(key, metadata);
|
|
676
333
|
}
|
|
677
334
|
} catch (err) {
|
|
678
|
-
|
|
335
|
+
log.error("failed to load space large metadata", {
|
|
679
336
|
err
|
|
680
337
|
}, {
|
|
681
|
-
F:
|
|
338
|
+
F: __dxlog_file2,
|
|
682
339
|
L: 215,
|
|
683
340
|
S: this,
|
|
684
341
|
C: (f, a) => f(...a)
|
|
@@ -698,8 +355,8 @@ var MetadataStore = class {
|
|
|
698
355
|
return this._metadata.identity.haloSpace;
|
|
699
356
|
}
|
|
700
357
|
const space = this.spaces.find((space2) => space2.key === spaceKey);
|
|
701
|
-
|
|
702
|
-
F:
|
|
358
|
+
invariant2(space, "Space not found", {
|
|
359
|
+
F: __dxlog_file2,
|
|
703
360
|
L: 237,
|
|
704
361
|
S: this,
|
|
705
362
|
A: [
|
|
@@ -722,8 +379,8 @@ var MetadataStore = class {
|
|
|
722
379
|
* Clears storage - doesn't work for now.
|
|
723
380
|
*/
|
|
724
381
|
async clear() {
|
|
725
|
-
|
|
726
|
-
F:
|
|
382
|
+
log("clearing all metadata", void 0, {
|
|
383
|
+
F: __dxlog_file2,
|
|
727
384
|
L: 256,
|
|
728
385
|
S: this,
|
|
729
386
|
C: (f, a) => f(...a)
|
|
@@ -735,8 +392,8 @@ var MetadataStore = class {
|
|
|
735
392
|
return this._metadata.identity;
|
|
736
393
|
}
|
|
737
394
|
async setIdentityRecord(record) {
|
|
738
|
-
|
|
739
|
-
F:
|
|
395
|
+
invariant2(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
|
|
396
|
+
F: __dxlog_file2,
|
|
740
397
|
L: 266,
|
|
741
398
|
S: this,
|
|
742
399
|
A: [
|
|
@@ -765,8 +422,8 @@ var MetadataStore = class {
|
|
|
765
422
|
await this.flush();
|
|
766
423
|
}
|
|
767
424
|
async addSpace(record) {
|
|
768
|
-
|
|
769
|
-
F:
|
|
425
|
+
invariant2(!(this._metadata.spaces ?? []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata", {
|
|
426
|
+
F: __dxlog_file2,
|
|
770
427
|
L: 294,
|
|
771
428
|
S: this,
|
|
772
429
|
A: [
|
|
@@ -826,7 +483,7 @@ var fromBytesInt32 = (buf) => buf.readInt32LE(0);
|
|
|
826
483
|
// packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts
|
|
827
484
|
import { Event as Event2 } from "@dxos/async";
|
|
828
485
|
import { timed } from "@dxos/debug";
|
|
829
|
-
import { log as
|
|
486
|
+
import { log as log2 } from "@dxos/log";
|
|
830
487
|
import { Timeframe } from "@dxos/timeframe";
|
|
831
488
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
832
489
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -838,7 +495,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
838
495
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
839
496
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
840
497
|
}
|
|
841
|
-
var
|
|
498
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
|
|
842
499
|
var mapTimeframeToFeedIndexes = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
|
|
843
500
|
feedKey,
|
|
844
501
|
index
|
|
@@ -892,22 +549,22 @@ var TimeframeClock = class {
|
|
|
892
549
|
return !gaps.isEmpty();
|
|
893
550
|
}
|
|
894
551
|
async waitUntilReached(target) {
|
|
895
|
-
|
|
552
|
+
log2("waitUntilReached", {
|
|
896
553
|
target,
|
|
897
554
|
current: this._timeframe
|
|
898
555
|
}, {
|
|
899
|
-
F:
|
|
556
|
+
F: __dxlog_file3,
|
|
900
557
|
L: 70,
|
|
901
558
|
S: this,
|
|
902
559
|
C: (f, a) => f(...a)
|
|
903
560
|
});
|
|
904
561
|
await this.update.waitForCondition(() => {
|
|
905
|
-
|
|
562
|
+
log2("check if reached", {
|
|
906
563
|
target,
|
|
907
564
|
current: this._timeframe,
|
|
908
565
|
deps: Timeframe.dependencies(target, this._timeframe)
|
|
909
566
|
}, {
|
|
910
|
-
F:
|
|
567
|
+
F: __dxlog_file3,
|
|
911
568
|
L: 72,
|
|
912
569
|
S: this,
|
|
913
570
|
C: (f, a) => f(...a)
|
|
@@ -922,25 +579,25 @@ _ts_decorate2([
|
|
|
922
579
|
|
|
923
580
|
// packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
|
|
924
581
|
import { Event as Event3, sleepWithContext, synchronized as synchronized2, Trigger } from "@dxos/async";
|
|
925
|
-
import { Context as
|
|
582
|
+
import { Context as Context2, rejectOnDispose } from "@dxos/context";
|
|
926
583
|
import { failUndefined } from "@dxos/debug";
|
|
927
584
|
import { FeedSetIterator } from "@dxos/feed-store";
|
|
928
|
-
import { invariant as
|
|
929
|
-
import { PublicKey as
|
|
930
|
-
import { log as
|
|
585
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
586
|
+
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
587
|
+
import { log as log4 } from "@dxos/log";
|
|
931
588
|
import { Timeframe as Timeframe2 } from "@dxos/timeframe";
|
|
932
|
-
import { ComplexMap as
|
|
589
|
+
import { ComplexMap as ComplexMap2 } from "@dxos/util";
|
|
933
590
|
|
|
934
591
|
// packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
|
|
935
|
-
import { invariant as
|
|
936
|
-
import { log as
|
|
937
|
-
var
|
|
592
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
593
|
+
import { log as log3 } from "@dxos/log";
|
|
594
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts";
|
|
938
595
|
var createMessageSelector = (timeframeClock) => {
|
|
939
596
|
return (messages) => {
|
|
940
597
|
for (let i = 0; i < messages.length; i++) {
|
|
941
598
|
const { data: { timeframe } } = messages[i];
|
|
942
|
-
|
|
943
|
-
F:
|
|
599
|
+
invariant3(timeframe, void 0, {
|
|
600
|
+
F: __dxlog_file4,
|
|
944
601
|
L: 25,
|
|
945
602
|
S: void 0,
|
|
946
603
|
A: [
|
|
@@ -952,8 +609,8 @@ var createMessageSelector = (timeframeClock) => {
|
|
|
952
609
|
return i;
|
|
953
610
|
}
|
|
954
611
|
}
|
|
955
|
-
|
|
956
|
-
F:
|
|
612
|
+
log3("Skipping...", void 0, {
|
|
613
|
+
F: __dxlog_file4,
|
|
957
614
|
L: 33,
|
|
958
615
|
S: void 0,
|
|
959
616
|
C: (f, a) => f(...a)
|
|
@@ -972,12 +629,12 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
972
629
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
973
630
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
974
631
|
}
|
|
975
|
-
var
|
|
632
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
|
|
976
633
|
var PipelineState = class {
|
|
977
634
|
constructor(_feeds, _timeframeClock) {
|
|
978
635
|
this._feeds = _feeds;
|
|
979
636
|
this._timeframeClock = _timeframeClock;
|
|
980
|
-
this._ctx = new
|
|
637
|
+
this._ctx = new Context2();
|
|
981
638
|
this.timeframeUpdate = this._timeframeClock.update;
|
|
982
639
|
this.stalled = new Event3();
|
|
983
640
|
this._startTimeframe = new Timeframe2();
|
|
@@ -1025,13 +682,13 @@ var PipelineState = class {
|
|
|
1025
682
|
*
|
|
1026
683
|
* @param timeout Timeout in milliseconds to specify the maximum wait time.
|
|
1027
684
|
*/
|
|
1028
|
-
async waitUntilReachedTargetTimeframe({ ctx = new
|
|
1029
|
-
|
|
685
|
+
async waitUntilReachedTargetTimeframe({ ctx = new Context2(), timeout, breakOnStall = true } = {}) {
|
|
686
|
+
log4("waitUntilReachedTargetTimeframe", {
|
|
1030
687
|
timeout,
|
|
1031
688
|
current: this.timeframe,
|
|
1032
689
|
target: this.targetTimeframe
|
|
1033
690
|
}, {
|
|
1034
|
-
F:
|
|
691
|
+
F: __dxlog_file5,
|
|
1035
692
|
L: 133,
|
|
1036
693
|
S: this,
|
|
1037
694
|
C: (f, a) => f(...a)
|
|
@@ -1057,13 +714,13 @@ var PipelineState = class {
|
|
|
1057
714
|
if (done) {
|
|
1058
715
|
return;
|
|
1059
716
|
}
|
|
1060
|
-
|
|
717
|
+
log4.warn("waitUntilReachedTargetTimeframe timed out", {
|
|
1061
718
|
timeout,
|
|
1062
719
|
current: this.timeframe,
|
|
1063
720
|
target: this.targetTimeframe,
|
|
1064
721
|
dependencies: Timeframe2.dependencies(this.targetTimeframe, this.timeframe)
|
|
1065
722
|
}, {
|
|
1066
|
-
F:
|
|
723
|
+
F: __dxlog_file5,
|
|
1067
724
|
L: 161,
|
|
1068
725
|
S: this,
|
|
1069
726
|
C: (f, a) => f(...a)
|
|
@@ -1078,14 +735,14 @@ var PipelineState = class {
|
|
|
1078
735
|
var Pipeline = class {
|
|
1079
736
|
constructor() {
|
|
1080
737
|
this._timeframeClock = new TimeframeClock(new Timeframe2());
|
|
1081
|
-
this._feeds = new
|
|
738
|
+
this._feeds = new ComplexMap2(PublicKey3.hash);
|
|
1082
739
|
// External state accessor.
|
|
1083
740
|
this._state = new PipelineState(this._feeds, this._timeframeClock);
|
|
1084
741
|
// Waits for the message consumer to process the message and yield control back to the pipeline.
|
|
1085
742
|
this._processingTrigger = new Trigger().wake();
|
|
1086
743
|
this._pauseTrigger = new Trigger().wake();
|
|
1087
744
|
// Pending downloads.
|
|
1088
|
-
this._downloads = new
|
|
745
|
+
this._downloads = new ComplexMap2((value) => PublicKey3.hash(value.key));
|
|
1089
746
|
this._isStopping = false;
|
|
1090
747
|
this._isStarted = false;
|
|
1091
748
|
this._isBeingConsumed = false;
|
|
@@ -1095,8 +752,8 @@ var Pipeline = class {
|
|
|
1095
752
|
return this._state;
|
|
1096
753
|
}
|
|
1097
754
|
get writer() {
|
|
1098
|
-
|
|
1099
|
-
F:
|
|
755
|
+
invariant4(this._writer, "Writer not set.", {
|
|
756
|
+
F: __dxlog_file5,
|
|
1100
757
|
L: 242,
|
|
1101
758
|
S: this,
|
|
1102
759
|
A: [
|
|
@@ -1124,8 +781,8 @@ var Pipeline = class {
|
|
|
1124
781
|
}
|
|
1125
782
|
}
|
|
1126
783
|
setWriteFeed(feed) {
|
|
1127
|
-
|
|
1128
|
-
F:
|
|
784
|
+
invariant4(!this._writer, "Writer already set.", {
|
|
785
|
+
F: __dxlog_file5,
|
|
1129
786
|
L: 269,
|
|
1130
787
|
S: this,
|
|
1131
788
|
A: [
|
|
@@ -1133,8 +790,8 @@ var Pipeline = class {
|
|
|
1133
790
|
"'Writer already set.'"
|
|
1134
791
|
]
|
|
1135
792
|
});
|
|
1136
|
-
|
|
1137
|
-
F:
|
|
793
|
+
invariant4(feed.properties.writable, "Feed must be writable.", {
|
|
794
|
+
F: __dxlog_file5,
|
|
1138
795
|
L: 270,
|
|
1139
796
|
S: this,
|
|
1140
797
|
A: [
|
|
@@ -1148,8 +805,8 @@ var Pipeline = class {
|
|
|
1148
805
|
}), feed.createFeedWriter());
|
|
1149
806
|
}
|
|
1150
807
|
async start() {
|
|
1151
|
-
|
|
1152
|
-
F:
|
|
808
|
+
invariant4(!this._isStarted, "Pipeline is already started.", {
|
|
809
|
+
F: __dxlog_file5,
|
|
1153
810
|
L: 283,
|
|
1154
811
|
S: this,
|
|
1155
812
|
A: [
|
|
@@ -1157,8 +814,8 @@ var Pipeline = class {
|
|
|
1157
814
|
"'Pipeline is already started.'"
|
|
1158
815
|
]
|
|
1159
816
|
});
|
|
1160
|
-
|
|
1161
|
-
F:
|
|
817
|
+
log4("starting...", void 0, {
|
|
818
|
+
F: __dxlog_file5,
|
|
1162
819
|
L: 284,
|
|
1163
820
|
S: this,
|
|
1164
821
|
C: (f, a) => f(...a)
|
|
@@ -1166,8 +823,8 @@ var Pipeline = class {
|
|
|
1166
823
|
await this._initIterator();
|
|
1167
824
|
await this._feedSetIterator.open();
|
|
1168
825
|
this._isStarted = true;
|
|
1169
|
-
|
|
1170
|
-
F:
|
|
826
|
+
log4("started", void 0, {
|
|
827
|
+
F: __dxlog_file5,
|
|
1171
828
|
L: 288,
|
|
1172
829
|
S: this,
|
|
1173
830
|
C: (f, a) => f(...a)
|
|
@@ -1179,8 +836,8 @@ var Pipeline = class {
|
|
|
1179
836
|
}
|
|
1180
837
|
}
|
|
1181
838
|
async stop() {
|
|
1182
|
-
|
|
1183
|
-
F:
|
|
839
|
+
log4("stopping...", void 0, {
|
|
840
|
+
F: __dxlog_file5,
|
|
1184
841
|
L: 299,
|
|
1185
842
|
S: this,
|
|
1186
843
|
C: (f, a) => f(...a)
|
|
@@ -1193,12 +850,12 @@ var Pipeline = class {
|
|
|
1193
850
|
await this._feedSetIterator?.close();
|
|
1194
851
|
await this._processingTrigger.wait();
|
|
1195
852
|
await this._state._ctx.dispose();
|
|
1196
|
-
this._state._ctx = new
|
|
853
|
+
this._state._ctx = new Context2();
|
|
1197
854
|
this._state._reachedTargetPromise = void 0;
|
|
1198
855
|
this._state._reachedTarget = false;
|
|
1199
856
|
this._isStarted = false;
|
|
1200
|
-
|
|
1201
|
-
F:
|
|
857
|
+
log4("stopped", void 0, {
|
|
858
|
+
F: __dxlog_file5,
|
|
1202
859
|
L: 312,
|
|
1203
860
|
S: this,
|
|
1204
861
|
C: (f, a) => f(...a)
|
|
@@ -1209,8 +866,8 @@ var Pipeline = class {
|
|
|
1209
866
|
* The pipeline will start processing messages AFTER this timeframe.
|
|
1210
867
|
*/
|
|
1211
868
|
async setCursor(timeframe) {
|
|
1212
|
-
|
|
1213
|
-
F:
|
|
869
|
+
invariant4(!this._isStarted || this._isPaused, "Invalid state.", {
|
|
870
|
+
F: __dxlog_file5,
|
|
1214
871
|
L: 321,
|
|
1215
872
|
S: this,
|
|
1216
873
|
A: [
|
|
@@ -1238,8 +895,8 @@ var Pipeline = class {
|
|
|
1238
895
|
this._isPaused = true;
|
|
1239
896
|
}
|
|
1240
897
|
async unpause() {
|
|
1241
|
-
|
|
1242
|
-
F:
|
|
898
|
+
invariant4(this._isPaused, "Pipeline is not paused.", {
|
|
899
|
+
F: __dxlog_file5,
|
|
1243
900
|
L: 350,
|
|
1244
901
|
S: this,
|
|
1245
902
|
A: [
|
|
@@ -1258,8 +915,8 @@ var Pipeline = class {
|
|
|
1258
915
|
* Updates the timeframe clock after the message has bee processed.
|
|
1259
916
|
*/
|
|
1260
917
|
async *consume() {
|
|
1261
|
-
|
|
1262
|
-
F:
|
|
918
|
+
invariant4(!this._isBeingConsumed, "Pipeline is already being consumed.", {
|
|
919
|
+
F: __dxlog_file5,
|
|
1263
920
|
L: 365,
|
|
1264
921
|
S: this,
|
|
1265
922
|
A: [
|
|
@@ -1268,8 +925,8 @@ var Pipeline = class {
|
|
|
1268
925
|
]
|
|
1269
926
|
});
|
|
1270
927
|
this._isBeingConsumed = true;
|
|
1271
|
-
|
|
1272
|
-
F:
|
|
928
|
+
invariant4(this._feedSetIterator, "Iterator not initialized.", {
|
|
929
|
+
F: __dxlog_file5,
|
|
1273
930
|
L: 368,
|
|
1274
931
|
S: this,
|
|
1275
932
|
A: [
|
|
@@ -1282,8 +939,8 @@ var Pipeline = class {
|
|
|
1282
939
|
while (!this._isStopping) {
|
|
1283
940
|
await this._pauseTrigger.wait();
|
|
1284
941
|
if (lastFeedSetIterator !== this._feedSetIterator) {
|
|
1285
|
-
|
|
1286
|
-
F:
|
|
942
|
+
invariant4(this._feedSetIterator, "Iterator not initialized.", {
|
|
943
|
+
F: __dxlog_file5,
|
|
1287
944
|
L: 377,
|
|
1288
945
|
S: this,
|
|
1289
946
|
A: [
|
|
@@ -1298,7 +955,7 @@ var Pipeline = class {
|
|
|
1298
955
|
if (!done) {
|
|
1299
956
|
const block = value ?? failUndefined();
|
|
1300
957
|
this._processingTrigger.reset();
|
|
1301
|
-
this._timeframeClock.updatePendingTimeframe(
|
|
958
|
+
this._timeframeClock.updatePendingTimeframe(PublicKey3.from(block.feedKey), block.seq);
|
|
1302
959
|
yield block;
|
|
1303
960
|
this._processingTrigger.wake();
|
|
1304
961
|
this._timeframeClock.updateTimeframe();
|
|
@@ -1313,12 +970,12 @@ var Pipeline = class {
|
|
|
1313
970
|
}
|
|
1314
971
|
const timeframe = this._state._startTimeframe;
|
|
1315
972
|
const seq = timeframe.get(feed.key) ?? -1;
|
|
1316
|
-
|
|
973
|
+
log4("download", {
|
|
1317
974
|
feed: feed.key.truncate(),
|
|
1318
975
|
seq,
|
|
1319
976
|
length: feed.length
|
|
1320
977
|
}, {
|
|
1321
|
-
F:
|
|
978
|
+
F: __dxlog_file5,
|
|
1322
979
|
L: 406,
|
|
1323
980
|
S: this,
|
|
1324
981
|
C: (f, a) => f(...a)
|
|
@@ -1329,10 +986,10 @@ var Pipeline = class {
|
|
|
1329
986
|
}, (err, data) => {
|
|
1330
987
|
if (err) {
|
|
1331
988
|
} else {
|
|
1332
|
-
|
|
989
|
+
log4.info("downloaded", {
|
|
1333
990
|
data
|
|
1334
991
|
}, {
|
|
1335
|
-
F:
|
|
992
|
+
F: __dxlog_file5,
|
|
1336
993
|
L: 411,
|
|
1337
994
|
S: this,
|
|
1338
995
|
C: (f, a) => f(...a)
|
|
@@ -1347,8 +1004,8 @@ var Pipeline = class {
|
|
|
1347
1004
|
stallTimeout: 1e3
|
|
1348
1005
|
});
|
|
1349
1006
|
this._feedSetIterator.stalled.on((iterator) => {
|
|
1350
|
-
|
|
1351
|
-
F:
|
|
1007
|
+
log4.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
|
|
1008
|
+
F: __dxlog_file5,
|
|
1352
1009
|
L: 425,
|
|
1353
1010
|
S: this,
|
|
1354
1011
|
C: (f, a) => f(...a)
|
|
@@ -1378,13 +1035,13 @@ _ts_decorate3([
|
|
|
1378
1035
|
|
|
1379
1036
|
// packages/core/echo/echo-pipeline/src/space/auth.ts
|
|
1380
1037
|
import { runInContext, scheduleTask } from "@dxos/async";
|
|
1381
|
-
import { Context as
|
|
1038
|
+
import { Context as Context3 } from "@dxos/context";
|
|
1382
1039
|
import { randomBytes } from "@dxos/crypto";
|
|
1383
|
-
import { invariant as
|
|
1384
|
-
import { log as
|
|
1040
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1041
|
+
import { log as log5 } from "@dxos/log";
|
|
1385
1042
|
import { schema as schema5 } from "@dxos/protocols";
|
|
1386
1043
|
import { RpcExtension } from "@dxos/teleport";
|
|
1387
|
-
var
|
|
1044
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/auth.ts";
|
|
1388
1045
|
var AuthExtension = class extends RpcExtension {
|
|
1389
1046
|
constructor(_authParams) {
|
|
1390
1047
|
super({
|
|
@@ -1397,10 +1054,10 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1397
1054
|
timeout: 60 * 1e3
|
|
1398
1055
|
});
|
|
1399
1056
|
this._authParams = _authParams;
|
|
1400
|
-
this._ctx = new
|
|
1057
|
+
this._ctx = new Context3({
|
|
1401
1058
|
onError: (err) => {
|
|
1402
|
-
|
|
1403
|
-
F:
|
|
1059
|
+
log5.catch(err, void 0, {
|
|
1060
|
+
F: __dxlog_file6,
|
|
1404
1061
|
L: 28,
|
|
1405
1062
|
S: this,
|
|
1406
1063
|
C: (f, a) => f(...a)
|
|
@@ -1421,8 +1078,8 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1421
1078
|
credential
|
|
1422
1079
|
};
|
|
1423
1080
|
} catch (err) {
|
|
1424
|
-
|
|
1425
|
-
F:
|
|
1081
|
+
log5.error("failed to generate auth credentials", err, {
|
|
1082
|
+
F: __dxlog_file6,
|
|
1426
1083
|
L: 55,
|
|
1427
1084
|
S: this,
|
|
1428
1085
|
C: (f, a) => f(...a)
|
|
@@ -1441,8 +1098,8 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1441
1098
|
const { credential } = await this.rpc.AuthService.authenticate({
|
|
1442
1099
|
challenge
|
|
1443
1100
|
});
|
|
1444
|
-
|
|
1445
|
-
F:
|
|
1101
|
+
invariant5(credential?.length > 0, "invalid credential", {
|
|
1102
|
+
F: __dxlog_file6,
|
|
1446
1103
|
L: 69,
|
|
1447
1104
|
S: this,
|
|
1448
1105
|
A: [
|
|
@@ -1451,8 +1108,8 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1451
1108
|
]
|
|
1452
1109
|
});
|
|
1453
1110
|
const success = await this._authParams.verifier(challenge, credential);
|
|
1454
|
-
|
|
1455
|
-
F:
|
|
1111
|
+
invariant5(success, "credential not verified", {
|
|
1112
|
+
F: __dxlog_file6,
|
|
1456
1113
|
L: 71,
|
|
1457
1114
|
S: this,
|
|
1458
1115
|
A: [
|
|
@@ -1462,8 +1119,8 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1462
1119
|
});
|
|
1463
1120
|
runInContext(this._ctx, () => this._authParams.onAuthSuccess());
|
|
1464
1121
|
} catch (err) {
|
|
1465
|
-
|
|
1466
|
-
F:
|
|
1122
|
+
log5("auth failed", err, {
|
|
1123
|
+
F: __dxlog_file6,
|
|
1467
1124
|
L: 74,
|
|
1468
1125
|
S: this,
|
|
1469
1126
|
C: (f, a) => f(...a)
|
|
@@ -1483,17 +1140,24 @@ var AuthExtension = class extends RpcExtension {
|
|
|
1483
1140
|
}
|
|
1484
1141
|
};
|
|
1485
1142
|
|
|
1486
|
-
// packages/core/echo/echo-pipeline/src/space/
|
|
1487
|
-
import { Event as Event4,
|
|
1488
|
-
import {
|
|
1489
|
-
import {
|
|
1490
|
-
import {
|
|
1491
|
-
import {
|
|
1492
|
-
import {
|
|
1493
|
-
|
|
1143
|
+
// packages/core/echo/echo-pipeline/src/space/space.ts
|
|
1144
|
+
import { Event as Event4, Mutex, synchronized as synchronized3, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
1145
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1146
|
+
import { log as log7, logInfo } from "@dxos/log";
|
|
1147
|
+
import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
1148
|
+
import { trace as trace2 } from "@dxos/tracing";
|
|
1149
|
+
import { Callback as Callback2 } from "@dxos/util";
|
|
1150
|
+
|
|
1151
|
+
// packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
|
|
1152
|
+
import { DeferredTask, sleepWithContext as sleepWithContext2, trackLeaks } from "@dxos/async";
|
|
1153
|
+
import { Context as Context4 } from "@dxos/context";
|
|
1154
|
+
import { SpaceStateMachine } from "@dxos/credentials";
|
|
1155
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
1156
|
+
import { log as log6 } from "@dxos/log";
|
|
1157
|
+
import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
1494
1158
|
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
1495
1159
|
import { TimeSeriesCounter, TimeUsageCounter, trace } from "@dxos/tracing";
|
|
1496
|
-
import { tracer } from "@dxos/util";
|
|
1160
|
+
import { Callback, tracer } from "@dxos/util";
|
|
1497
1161
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
1498
1162
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1499
1163
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1504,492 +1168,17 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
1504
1168
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1505
1169
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1506
1170
|
}
|
|
1507
|
-
var
|
|
1508
|
-
var
|
|
1509
|
-
var
|
|
1510
|
-
var
|
|
1511
|
-
var
|
|
1512
|
-
constructor(
|
|
1513
|
-
this.
|
|
1514
|
-
this.
|
|
1515
|
-
this.
|
|
1516
|
-
this._targetTimeframe = void 0;
|
|
1517
|
-
this._lastAutomaticSnapshotTimeframe = new Timeframe3();
|
|
1518
|
-
this._isOpen = false;
|
|
1519
|
-
this._lastTimeframeSaveTime = 0;
|
|
1520
|
-
this._lastSnapshotSaveTime = 0;
|
|
1521
|
-
this._lastProcessedEpoch = -1;
|
|
1171
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
|
|
1172
|
+
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
|
|
1173
|
+
var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
|
|
1174
|
+
var USE_SNAPSHOTS = true;
|
|
1175
|
+
var ControlPipeline = class {
|
|
1176
|
+
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
|
|
1177
|
+
this._ctx = new Context4();
|
|
1178
|
+
this._lastTimeframeSaveTime = Date.now();
|
|
1179
|
+
this.onFeedAdmitted = new Callback();
|
|
1522
1180
|
this._usage = new TimeUsageCounter();
|
|
1523
1181
|
this._mutations = new TimeSeriesCounter();
|
|
1524
|
-
this.currentEpoch = void 0;
|
|
1525
|
-
this.appliedEpoch = void 0;
|
|
1526
|
-
this.onNewEpoch = new Event4();
|
|
1527
|
-
}
|
|
1528
|
-
get isOpen() {
|
|
1529
|
-
return this._isOpen;
|
|
1530
|
-
}
|
|
1531
|
-
get pipeline() {
|
|
1532
|
-
return this._pipeline;
|
|
1533
|
-
}
|
|
1534
|
-
get pipelineState() {
|
|
1535
|
-
return this._pipeline?.state;
|
|
1536
|
-
}
|
|
1537
|
-
setTargetTimeframe(timeframe) {
|
|
1538
|
-
this._targetTimeframe = timeframe;
|
|
1539
|
-
this._pipeline?.state.setTargetTimeframe(timeframe);
|
|
1540
|
-
}
|
|
1541
|
-
async processCredential(credential) {
|
|
1542
|
-
if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
|
|
1543
|
-
return;
|
|
1544
|
-
}
|
|
1545
|
-
this.currentEpoch = credential;
|
|
1546
|
-
if (this._isOpen) {
|
|
1547
|
-
await this._processEpochInSeparateTask(credential);
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
async open() {
|
|
1551
|
-
if (this._isOpen) {
|
|
1552
|
-
return;
|
|
1553
|
-
}
|
|
1554
|
-
this._pipeline = new Pipeline();
|
|
1555
|
-
await this._params.onPipelineCreated(this._pipeline);
|
|
1556
|
-
await this._pipeline.pause();
|
|
1557
|
-
await this._pipeline.start();
|
|
1558
|
-
if (this._targetTimeframe) {
|
|
1559
|
-
this._pipeline.state.setTargetTimeframe(this._targetTimeframe);
|
|
1560
|
-
}
|
|
1561
|
-
const feedWriter = {
|
|
1562
|
-
write: (data, options) => {
|
|
1563
|
-
invariant8(this._pipeline, "Pipeline is not initialized.", {
|
|
1564
|
-
F: __dxlog_file9,
|
|
1565
|
-
L: 164,
|
|
1566
|
-
S: this,
|
|
1567
|
-
A: [
|
|
1568
|
-
"this._pipeline",
|
|
1569
|
-
"'Pipeline is not initialized.'"
|
|
1570
|
-
]
|
|
1571
|
-
});
|
|
1572
|
-
invariant8(this.currentEpoch, "Epoch is not initialized.", {
|
|
1573
|
-
F: __dxlog_file9,
|
|
1574
|
-
L: 165,
|
|
1575
|
-
S: this,
|
|
1576
|
-
A: [
|
|
1577
|
-
"this.currentEpoch",
|
|
1578
|
-
"'Epoch is not initialized.'"
|
|
1579
|
-
]
|
|
1580
|
-
});
|
|
1581
|
-
return this._pipeline.writer.write({
|
|
1582
|
-
data
|
|
1583
|
-
}, options);
|
|
1584
|
-
}
|
|
1585
|
-
};
|
|
1586
|
-
this.databaseHost = new DatabaseHost(feedWriter, () => this._flush());
|
|
1587
|
-
this.itemManager = new ItemManager(this._params.modelFactory);
|
|
1588
|
-
await this.databaseHost.open(this.itemManager, this._params.modelFactory);
|
|
1589
|
-
scheduleTask2(this._ctx, async () => {
|
|
1590
|
-
await this._consumePipeline();
|
|
1591
|
-
});
|
|
1592
|
-
this._isOpen = true;
|
|
1593
|
-
}
|
|
1594
|
-
async close() {
|
|
1595
|
-
if (!this._isOpen) {
|
|
1596
|
-
return;
|
|
1597
|
-
}
|
|
1598
|
-
log8("close", void 0, {
|
|
1599
|
-
F: __dxlog_file9,
|
|
1600
|
-
L: 189,
|
|
1601
|
-
S: this,
|
|
1602
|
-
C: (f, a) => f(...a)
|
|
1603
|
-
});
|
|
1604
|
-
this._isOpen = false;
|
|
1605
|
-
await this._ctx.dispose();
|
|
1606
|
-
await this._pipeline?.stop();
|
|
1607
|
-
try {
|
|
1608
|
-
await this._saveCache();
|
|
1609
|
-
if (this._pipeline) {
|
|
1610
|
-
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
1611
|
-
}
|
|
1612
|
-
} catch (err) {
|
|
1613
|
-
log8.catch(err, void 0, {
|
|
1614
|
-
F: __dxlog_file9,
|
|
1615
|
-
L: 202,
|
|
1616
|
-
S: this,
|
|
1617
|
-
C: (f, a) => f(...a)
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
await this.databaseHost?.close();
|
|
1621
|
-
await this.itemManager?.destroy();
|
|
1622
|
-
this._ctx = new Context5();
|
|
1623
|
-
this._pipeline = void 0;
|
|
1624
|
-
this._targetTimeframe = void 0;
|
|
1625
|
-
this._lastAutomaticSnapshotTimeframe = new Timeframe3();
|
|
1626
|
-
this.currentEpoch = void 0;
|
|
1627
|
-
this.appliedEpoch = void 0;
|
|
1628
|
-
this._lastProcessedEpoch = -1;
|
|
1629
|
-
this._epochCtx = void 0;
|
|
1630
|
-
}
|
|
1631
|
-
async _consumePipeline() {
|
|
1632
|
-
const pipeline = this._pipeline;
|
|
1633
|
-
if (this.currentEpoch) {
|
|
1634
|
-
const waitForOneEpoch = this.onNewEpoch.waitForCount(1);
|
|
1635
|
-
await this._processEpochInSeparateTask(this.currentEpoch);
|
|
1636
|
-
await waitForOneEpoch;
|
|
1637
|
-
}
|
|
1638
|
-
let messageCounter = 0;
|
|
1639
|
-
invariant8(pipeline, "Pipeline is not initialized.", {
|
|
1640
|
-
F: __dxlog_file9,
|
|
1641
|
-
L: 229,
|
|
1642
|
-
S: this,
|
|
1643
|
-
A: [
|
|
1644
|
-
"pipeline",
|
|
1645
|
-
"'Pipeline is not initialized.'"
|
|
1646
|
-
]
|
|
1647
|
-
});
|
|
1648
|
-
for await (const msg of pipeline.consume()) {
|
|
1649
|
-
const span = this._usage.beginRecording();
|
|
1650
|
-
this._mutations.inc();
|
|
1651
|
-
const { feedKey, seq, data } = msg;
|
|
1652
|
-
log8("processing message", {
|
|
1653
|
-
feedKey,
|
|
1654
|
-
seq
|
|
1655
|
-
}, {
|
|
1656
|
-
F: __dxlog_file9,
|
|
1657
|
-
L: 235,
|
|
1658
|
-
S: this,
|
|
1659
|
-
C: (f, a) => f(...a)
|
|
1660
|
-
});
|
|
1661
|
-
try {
|
|
1662
|
-
if (data.payload.data) {
|
|
1663
|
-
const feedInfo = this._params.feedInfoProvider(feedKey);
|
|
1664
|
-
if (!feedInfo) {
|
|
1665
|
-
log8.warn("Could not find feed", {
|
|
1666
|
-
feedKey
|
|
1667
|
-
}, {
|
|
1668
|
-
F: __dxlog_file9,
|
|
1669
|
-
L: 241,
|
|
1670
|
-
S: this,
|
|
1671
|
-
C: (f, a) => f(...a)
|
|
1672
|
-
});
|
|
1673
|
-
continue;
|
|
1674
|
-
}
|
|
1675
|
-
const timer = tracer.mark("dxos.echo.pipeline.data");
|
|
1676
|
-
this.databaseHost.echoProcessor({
|
|
1677
|
-
batch: data.payload.data.batch,
|
|
1678
|
-
meta: {
|
|
1679
|
-
feedKey,
|
|
1680
|
-
seq,
|
|
1681
|
-
timeframe: data.timeframe,
|
|
1682
|
-
memberKey: feedInfo.assertion.identityKey
|
|
1683
|
-
}
|
|
1684
|
-
});
|
|
1685
|
-
timer.end();
|
|
1686
|
-
log8.trace("dxos.echo.data-pipeline.processed", {
|
|
1687
|
-
feedKey: feedKey.toHex(),
|
|
1688
|
-
seq,
|
|
1689
|
-
spaceKey: this._params.spaceKey.toHex()
|
|
1690
|
-
}, {
|
|
1691
|
-
F: __dxlog_file9,
|
|
1692
|
-
L: 258,
|
|
1693
|
-
S: this,
|
|
1694
|
-
C: (f, a) => f(...a)
|
|
1695
|
-
});
|
|
1696
|
-
await this._noteTargetStateIfNeeded(pipeline.state.pendingTimeframe);
|
|
1697
|
-
}
|
|
1698
|
-
} catch (err) {
|
|
1699
|
-
log8.catch(err, void 0, {
|
|
1700
|
-
F: __dxlog_file9,
|
|
1701
|
-
L: 268,
|
|
1702
|
-
S: this,
|
|
1703
|
-
C: (f, a) => f(...a)
|
|
1704
|
-
});
|
|
1705
|
-
}
|
|
1706
|
-
span.end();
|
|
1707
|
-
if (++messageCounter > 100) {
|
|
1708
|
-
messageCounter = 0;
|
|
1709
|
-
await idle(1e3);
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
_createSnapshot() {
|
|
1714
|
-
invariant8(this.databaseHost, "Database backend is not initialized.", {
|
|
1715
|
-
F: __dxlog_file9,
|
|
1716
|
-
L: 282,
|
|
1717
|
-
S: this,
|
|
1718
|
-
A: [
|
|
1719
|
-
"this.databaseHost",
|
|
1720
|
-
"'Database backend is not initialized.'"
|
|
1721
|
-
]
|
|
1722
|
-
});
|
|
1723
|
-
return {
|
|
1724
|
-
spaceKey: this._params.spaceKey.asUint8Array(),
|
|
1725
|
-
timeframe: this._pipeline.state.timeframe,
|
|
1726
|
-
database: this.databaseHost.createSnapshot()
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
async _saveTargetTimeframe(timeframe) {
|
|
1730
|
-
const newTimeframe = Timeframe3.merge(this._targetTimeframe ?? new Timeframe3(), timeframe);
|
|
1731
|
-
await this._params.metadataStore.setSpaceDataLatestTimeframe(this._params.spaceKey, newTimeframe);
|
|
1732
|
-
this._targetTimeframe = newTimeframe;
|
|
1733
|
-
}
|
|
1734
|
-
async _saveCache() {
|
|
1735
|
-
const cache = {};
|
|
1736
|
-
try {
|
|
1737
|
-
const propertiesItem = this.itemManager.items.find((item) => item.modelMeta?.type === "dxos.org/model/document" && // TODO(burdon): Document?
|
|
1738
|
-
(getStateMachineFromItem(item)?.snapshot()).type === TYPE_PROPERTIES);
|
|
1739
|
-
if (propertiesItem) {
|
|
1740
|
-
cache.properties = getStateMachineFromItem(propertiesItem)?.snapshot();
|
|
1741
|
-
}
|
|
1742
|
-
} catch (err) {
|
|
1743
|
-
log8.warn("Failed to cache properties", err, {
|
|
1744
|
-
F: __dxlog_file9,
|
|
1745
|
-
L: 311,
|
|
1746
|
-
S: this,
|
|
1747
|
-
C: (f, a) => f(...a)
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
await this._params.metadataStore.setCache(this._params.spaceKey, cache);
|
|
1751
|
-
}
|
|
1752
|
-
async _noteTargetStateIfNeeded(timeframe) {
|
|
1753
|
-
if (!this._pipeline?.state.reachedTarget) {
|
|
1754
|
-
return;
|
|
1755
|
-
}
|
|
1756
|
-
if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL) {
|
|
1757
|
-
this._lastTimeframeSaveTime = Date.now();
|
|
1758
|
-
await this._saveTargetTimeframe(timeframe);
|
|
1759
|
-
}
|
|
1760
|
-
if (Date.now() - this._lastSnapshotSaveTime > AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL && timeframe.totalMessages() - this._lastAutomaticSnapshotTimeframe.totalMessages() > MESSAGES_PER_SNAPSHOT) {
|
|
1761
|
-
await this._saveCache();
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
async _processEpochInSeparateTask(epoch) {
|
|
1765
|
-
if (epoch.subject.assertion.number <= this._lastProcessedEpoch) {
|
|
1766
|
-
return;
|
|
1767
|
-
}
|
|
1768
|
-
await this._epochCtx?.dispose();
|
|
1769
|
-
const ctx = new Context5({
|
|
1770
|
-
onError: (err) => {
|
|
1771
|
-
if (err instanceof CancelledError) {
|
|
1772
|
-
log8("Epoch processing cancelled.", void 0, {
|
|
1773
|
-
F: __dxlog_file9,
|
|
1774
|
-
L: 347,
|
|
1775
|
-
S: this,
|
|
1776
|
-
C: (f, a) => f(...a)
|
|
1777
|
-
});
|
|
1778
|
-
} else {
|
|
1779
|
-
log8.catch(err, void 0, {
|
|
1780
|
-
F: __dxlog_file9,
|
|
1781
|
-
L: 349,
|
|
1782
|
-
S: this,
|
|
1783
|
-
C: (f, a) => f(...a)
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
});
|
|
1788
|
-
this._epochCtx = ctx;
|
|
1789
|
-
scheduleTask2(ctx, async () => {
|
|
1790
|
-
if (!this._isOpen) {
|
|
1791
|
-
return;
|
|
1792
|
-
}
|
|
1793
|
-
await this._processEpoch(ctx, epoch.subject.assertion);
|
|
1794
|
-
if (epoch.subject.assertion.snapshotCid === void 0) {
|
|
1795
|
-
epoch.subject.assertion.snapshotCid = this.appliedEpoch?.subject.assertion.snapshotCid;
|
|
1796
|
-
}
|
|
1797
|
-
this.appliedEpoch = epoch;
|
|
1798
|
-
this.onNewEpoch.emit(epoch);
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
1801
|
-
async _processEpoch(ctx, epoch) {
|
|
1802
|
-
invariant8(this._isOpen, "Space is closed.", {
|
|
1803
|
-
F: __dxlog_file9,
|
|
1804
|
-
L: 373,
|
|
1805
|
-
S: this,
|
|
1806
|
-
A: [
|
|
1807
|
-
"this._isOpen",
|
|
1808
|
-
"'Space is closed.'"
|
|
1809
|
-
]
|
|
1810
|
-
});
|
|
1811
|
-
invariant8(this._pipeline, void 0, {
|
|
1812
|
-
F: __dxlog_file9,
|
|
1813
|
-
L: 374,
|
|
1814
|
-
S: this,
|
|
1815
|
-
A: [
|
|
1816
|
-
"this._pipeline",
|
|
1817
|
-
""
|
|
1818
|
-
]
|
|
1819
|
-
});
|
|
1820
|
-
this._lastProcessedEpoch = epoch.number;
|
|
1821
|
-
log8("processing", {
|
|
1822
|
-
epoch: omit(epoch, "proof")
|
|
1823
|
-
}, {
|
|
1824
|
-
F: __dxlog_file9,
|
|
1825
|
-
L: 377,
|
|
1826
|
-
S: this,
|
|
1827
|
-
C: (f, a) => f(...a)
|
|
1828
|
-
});
|
|
1829
|
-
if (epoch.snapshotCid) {
|
|
1830
|
-
const snapshot = await this._params.snapshotManager.load(ctx, epoch.snapshotCid);
|
|
1831
|
-
this.databaseHost._itemDemuxer.restoreFromSnapshot(snapshot.database);
|
|
1832
|
-
}
|
|
1833
|
-
log8("restarting pipeline from epoch", void 0, {
|
|
1834
|
-
F: __dxlog_file9,
|
|
1835
|
-
L: 383,
|
|
1836
|
-
S: this,
|
|
1837
|
-
C: (f, a) => f(...a)
|
|
1838
|
-
});
|
|
1839
|
-
await this._pipeline.pause();
|
|
1840
|
-
await this._pipeline.setCursor(epoch.timeframe);
|
|
1841
|
-
await this._pipeline.unpause();
|
|
1842
|
-
}
|
|
1843
|
-
async waitUntilTimeframe(timeframe) {
|
|
1844
|
-
invariant8(this._pipeline, "Pipeline is not initialized.", {
|
|
1845
|
-
F: __dxlog_file9,
|
|
1846
|
-
L: 390,
|
|
1847
|
-
S: this,
|
|
1848
|
-
A: [
|
|
1849
|
-
"this._pipeline",
|
|
1850
|
-
"'Pipeline is not initialized.'"
|
|
1851
|
-
]
|
|
1852
|
-
});
|
|
1853
|
-
await this._pipeline.state.waitUntilTimeframe(timeframe);
|
|
1854
|
-
}
|
|
1855
|
-
async createEpoch() {
|
|
1856
|
-
invariant8(this._pipeline, void 0, {
|
|
1857
|
-
F: __dxlog_file9,
|
|
1858
|
-
L: 396,
|
|
1859
|
-
S: this,
|
|
1860
|
-
A: [
|
|
1861
|
-
"this._pipeline",
|
|
1862
|
-
""
|
|
1863
|
-
]
|
|
1864
|
-
});
|
|
1865
|
-
invariant8(this.currentEpoch, void 0, {
|
|
1866
|
-
F: __dxlog_file9,
|
|
1867
|
-
L: 397,
|
|
1868
|
-
S: this,
|
|
1869
|
-
A: [
|
|
1870
|
-
"this.currentEpoch",
|
|
1871
|
-
""
|
|
1872
|
-
]
|
|
1873
|
-
});
|
|
1874
|
-
await this._pipeline.pause();
|
|
1875
|
-
const snapshot = await this._createSnapshot();
|
|
1876
|
-
const snapshotCid = await this._params.snapshotManager.store(snapshot);
|
|
1877
|
-
const epoch = {
|
|
1878
|
-
previousId: this.currentEpoch.id,
|
|
1879
|
-
timeframe: this._pipeline.state.timeframe,
|
|
1880
|
-
number: this.currentEpoch.subject.assertion.number + 1,
|
|
1881
|
-
snapshotCid
|
|
1882
|
-
};
|
|
1883
|
-
await this._pipeline.unpause();
|
|
1884
|
-
return epoch;
|
|
1885
|
-
}
|
|
1886
|
-
async ensureEpochInitialized() {
|
|
1887
|
-
await this.onNewEpoch.waitForCondition(() => !!this.currentEpoch);
|
|
1888
|
-
}
|
|
1889
|
-
async _flush() {
|
|
1890
|
-
try {
|
|
1891
|
-
await this._saveCache();
|
|
1892
|
-
if (this._pipeline) {
|
|
1893
|
-
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
1894
|
-
}
|
|
1895
|
-
} catch (err) {
|
|
1896
|
-
log8.catch(err, void 0, {
|
|
1897
|
-
F: __dxlog_file9,
|
|
1898
|
-
L: 427,
|
|
1899
|
-
S: this,
|
|
1900
|
-
C: (f, a) => f(...a)
|
|
1901
|
-
});
|
|
1902
|
-
}
|
|
1903
|
-
await this._params.metadataStore.flush();
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
_ts_decorate4([
|
|
1907
|
-
trace.metricsCounter()
|
|
1908
|
-
], DataPipeline.prototype, "_usage", void 0);
|
|
1909
|
-
_ts_decorate4([
|
|
1910
|
-
trace.metricsCounter()
|
|
1911
|
-
], DataPipeline.prototype, "_mutations", void 0);
|
|
1912
|
-
_ts_decorate4([
|
|
1913
|
-
synchronized3
|
|
1914
|
-
], DataPipeline.prototype, "open", null);
|
|
1915
|
-
_ts_decorate4([
|
|
1916
|
-
synchronized3
|
|
1917
|
-
], DataPipeline.prototype, "close", null);
|
|
1918
|
-
_ts_decorate4([
|
|
1919
|
-
synchronized3
|
|
1920
|
-
], DataPipeline.prototype, "_processEpoch", null);
|
|
1921
|
-
_ts_decorate4([
|
|
1922
|
-
synchronized3
|
|
1923
|
-
], DataPipeline.prototype, "createEpoch", null);
|
|
1924
|
-
DataPipeline = _ts_decorate4([
|
|
1925
|
-
trackLeaks("open", "close"),
|
|
1926
|
-
trace.resource()
|
|
1927
|
-
], DataPipeline);
|
|
1928
|
-
var idle = async (timeout) => {
|
|
1929
|
-
if (!("scheduler" in globalThis && typeof globalThis.scheduler.postTask === "function")) {
|
|
1930
|
-
await sleep(1);
|
|
1931
|
-
return;
|
|
1932
|
-
}
|
|
1933
|
-
await new Promise((resolve) => {
|
|
1934
|
-
const cleanup = () => {
|
|
1935
|
-
clearTimeout(timer);
|
|
1936
|
-
controller.abort();
|
|
1937
|
-
};
|
|
1938
|
-
const controller = new AbortController();
|
|
1939
|
-
void globalThis.scheduler.postTask(() => {
|
|
1940
|
-
cleanup();
|
|
1941
|
-
resolve();
|
|
1942
|
-
}, {
|
|
1943
|
-
priority: "background",
|
|
1944
|
-
signal: controller.signal
|
|
1945
|
-
}).catch(() => {
|
|
1946
|
-
});
|
|
1947
|
-
const timer = setTimeout(() => {
|
|
1948
|
-
cleanup();
|
|
1949
|
-
resolve();
|
|
1950
|
-
}, timeout);
|
|
1951
|
-
});
|
|
1952
|
-
};
|
|
1953
|
-
|
|
1954
|
-
// packages/core/echo/echo-pipeline/src/space/space.ts
|
|
1955
|
-
import { Event as Event5, synchronized as synchronized4, trackLeaks as trackLeaks3, Mutex } from "@dxos/async";
|
|
1956
|
-
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1957
|
-
import { log as log10, logInfo } from "@dxos/log";
|
|
1958
|
-
import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
1959
|
-
import { trace as trace3 } from "@dxos/tracing";
|
|
1960
|
-
import { Callback as Callback2 } from "@dxos/util";
|
|
1961
|
-
|
|
1962
|
-
// packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
|
|
1963
|
-
import { DeferredTask, sleepWithContext as sleepWithContext2, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
1964
|
-
import { Context as Context6 } from "@dxos/context";
|
|
1965
|
-
import { SpaceStateMachine } from "@dxos/credentials";
|
|
1966
|
-
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1967
|
-
import { log as log9 } from "@dxos/log";
|
|
1968
|
-
import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
1969
|
-
import { Timeframe as Timeframe4 } from "@dxos/timeframe";
|
|
1970
|
-
import { TimeSeriesCounter as TimeSeriesCounter2, TimeUsageCounter as TimeUsageCounter2, trace as trace2 } from "@dxos/tracing";
|
|
1971
|
-
import { Callback, tracer as tracer2 } from "@dxos/util";
|
|
1972
|
-
function _ts_decorate5(decorators, target, key, desc) {
|
|
1973
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1974
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1975
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
1976
|
-
else
|
|
1977
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1978
|
-
if (d = decorators[i])
|
|
1979
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1980
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1981
|
-
}
|
|
1982
|
-
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
|
|
1983
|
-
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 500;
|
|
1984
|
-
var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
|
|
1985
|
-
var USE_SNAPSHOTS = true;
|
|
1986
|
-
var ControlPipeline = class {
|
|
1987
|
-
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
|
|
1988
|
-
this._ctx = new Context6();
|
|
1989
|
-
this._lastTimeframeSaveTime = Date.now();
|
|
1990
|
-
this.onFeedAdmitted = new Callback();
|
|
1991
|
-
this._usage = new TimeUsageCounter2();
|
|
1992
|
-
this._mutations = new TimeSeriesCounter2();
|
|
1993
1182
|
this._snapshotTask = new DeferredTask(this._ctx, async () => {
|
|
1994
1183
|
await sleepWithContext2(this._ctx, CONTROL_PIPELINE_SNAPSHOT_DELAY);
|
|
1995
1184
|
await this._saveSnapshot();
|
|
@@ -2000,10 +1189,10 @@ var ControlPipeline = class {
|
|
|
2000
1189
|
void this._pipeline.addFeed(genesisFeed);
|
|
2001
1190
|
this._spaceStateMachine = new SpaceStateMachine(spaceKey);
|
|
2002
1191
|
this._spaceStateMachine.onFeedAdmitted.set(async (info) => {
|
|
2003
|
-
|
|
1192
|
+
log6("feed admitted", {
|
|
2004
1193
|
key: info.key
|
|
2005
1194
|
}, {
|
|
2006
|
-
F:
|
|
1195
|
+
F: __dxlog_file7,
|
|
2007
1196
|
L: 74,
|
|
2008
1197
|
S: this,
|
|
2009
1198
|
C: (f, a) => f(...a)
|
|
@@ -2012,11 +1201,13 @@ var ControlPipeline = class {
|
|
|
2012
1201
|
queueMicrotask(async () => {
|
|
2013
1202
|
try {
|
|
2014
1203
|
const feed = await feedProvider(info.key);
|
|
2015
|
-
|
|
1204
|
+
if (!this._pipeline.hasFeed(feed.key)) {
|
|
1205
|
+
await this._pipeline.addFeed(feed);
|
|
1206
|
+
}
|
|
2016
1207
|
} catch (err) {
|
|
2017
|
-
|
|
2018
|
-
F:
|
|
2019
|
-
L:
|
|
1208
|
+
log6.catch(err, void 0, {
|
|
1209
|
+
F: __dxlog_file7,
|
|
1210
|
+
L: 85,
|
|
2020
1211
|
S: this,
|
|
2021
1212
|
C: (f, a) => f(...a)
|
|
2022
1213
|
});
|
|
@@ -2040,32 +1231,32 @@ var ControlPipeline = class {
|
|
|
2040
1231
|
}
|
|
2041
1232
|
async start() {
|
|
2042
1233
|
const snapshot = this._metadata.getSpaceControlPipelineSnapshot(this._spaceKey);
|
|
2043
|
-
|
|
1234
|
+
log6("load snapshot", {
|
|
2044
1235
|
key: this._spaceKey,
|
|
2045
1236
|
present: !!snapshot,
|
|
2046
1237
|
tf: snapshot?.timeframe
|
|
2047
1238
|
}, {
|
|
2048
|
-
F:
|
|
2049
|
-
L:
|
|
1239
|
+
F: __dxlog_file7,
|
|
1240
|
+
L: 113,
|
|
2050
1241
|
S: this,
|
|
2051
1242
|
C: (f, a) => f(...a)
|
|
2052
1243
|
});
|
|
2053
1244
|
if (USE_SNAPSHOTS && snapshot) {
|
|
2054
1245
|
await this._processSnapshot(snapshot);
|
|
2055
1246
|
}
|
|
2056
|
-
|
|
2057
|
-
F:
|
|
2058
|
-
L:
|
|
1247
|
+
log6("starting...", void 0, {
|
|
1248
|
+
F: __dxlog_file7,
|
|
1249
|
+
L: 118,
|
|
2059
1250
|
S: this,
|
|
2060
1251
|
C: (f, a) => f(...a)
|
|
2061
1252
|
});
|
|
2062
1253
|
setTimeout(async () => {
|
|
2063
|
-
void this._consumePipeline(new
|
|
1254
|
+
void this._consumePipeline(new Context4());
|
|
2064
1255
|
});
|
|
2065
1256
|
await this._pipeline.start();
|
|
2066
|
-
|
|
2067
|
-
F:
|
|
2068
|
-
L:
|
|
1257
|
+
log6("started", void 0, {
|
|
1258
|
+
F: __dxlog_file7,
|
|
1259
|
+
L: 124,
|
|
2069
1260
|
S: this,
|
|
2070
1261
|
C: (f, a) => f(...a)
|
|
2071
1262
|
});
|
|
@@ -2078,11 +1269,11 @@ var ControlPipeline = class {
|
|
|
2078
1269
|
skipVerification: true
|
|
2079
1270
|
});
|
|
2080
1271
|
if (!result) {
|
|
2081
|
-
|
|
1272
|
+
log6.warn("credential processing failed from snapshot", {
|
|
2082
1273
|
message
|
|
2083
1274
|
}, {
|
|
2084
|
-
F:
|
|
2085
|
-
L:
|
|
1275
|
+
F: __dxlog_file7,
|
|
1276
|
+
L: 137,
|
|
2086
1277
|
S: this,
|
|
2087
1278
|
C: (f, a) => f(...a)
|
|
2088
1279
|
});
|
|
@@ -2099,12 +1290,12 @@ var ControlPipeline = class {
|
|
|
2099
1290
|
}))
|
|
2100
1291
|
};
|
|
2101
1292
|
await this._pipeline.unpause();
|
|
2102
|
-
|
|
1293
|
+
log6("save snapshot", {
|
|
2103
1294
|
key: this._spaceKey,
|
|
2104
1295
|
snapshot
|
|
2105
1296
|
}, {
|
|
2106
|
-
F:
|
|
2107
|
-
L:
|
|
1297
|
+
F: __dxlog_file7,
|
|
1298
|
+
L: 153,
|
|
2108
1299
|
S: this,
|
|
2109
1300
|
C: (f, a) => f(...a)
|
|
2110
1301
|
});
|
|
@@ -2117,9 +1308,9 @@ var ControlPipeline = class {
|
|
|
2117
1308
|
try {
|
|
2118
1309
|
await this._processMessage(ctx, msg);
|
|
2119
1310
|
} catch (err) {
|
|
2120
|
-
|
|
2121
|
-
F:
|
|
2122
|
-
L:
|
|
1311
|
+
log6.catch(err, void 0, {
|
|
1312
|
+
F: __dxlog_file7,
|
|
1313
|
+
L: 166,
|
|
2123
1314
|
S: this,
|
|
2124
1315
|
C: (f, a) => f(...a)
|
|
2125
1316
|
});
|
|
@@ -2128,27 +1319,27 @@ var ControlPipeline = class {
|
|
|
2128
1319
|
}
|
|
2129
1320
|
}
|
|
2130
1321
|
async _processMessage(ctx, msg) {
|
|
2131
|
-
|
|
1322
|
+
log6("processing", {
|
|
2132
1323
|
key: msg.feedKey,
|
|
2133
1324
|
seq: msg.seq
|
|
2134
1325
|
}, {
|
|
2135
|
-
F:
|
|
2136
|
-
L:
|
|
1326
|
+
F: __dxlog_file7,
|
|
1327
|
+
L: 176,
|
|
2137
1328
|
S: this,
|
|
2138
1329
|
C: (f, a) => f(...a)
|
|
2139
1330
|
});
|
|
2140
1331
|
if (msg.data.payload.credential) {
|
|
2141
|
-
const timer =
|
|
1332
|
+
const timer = tracer.mark("dxos.echo.pipeline.control");
|
|
2142
1333
|
const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, {
|
|
2143
|
-
sourceFeed:
|
|
1334
|
+
sourceFeed: PublicKey4.from(msg.feedKey)
|
|
2144
1335
|
});
|
|
2145
1336
|
timer.end();
|
|
2146
1337
|
if (!result) {
|
|
2147
|
-
|
|
1338
|
+
log6.warn("processing failed", {
|
|
2148
1339
|
msg
|
|
2149
1340
|
}, {
|
|
2150
|
-
F:
|
|
2151
|
-
L:
|
|
1341
|
+
F: __dxlog_file7,
|
|
1342
|
+
L: 185,
|
|
2152
1343
|
S: this,
|
|
2153
1344
|
C: (f, a) => f(...a)
|
|
2154
1345
|
});
|
|
@@ -2159,67 +1350,67 @@ var ControlPipeline = class {
|
|
|
2159
1350
|
}
|
|
2160
1351
|
}
|
|
2161
1352
|
async _noteTargetStateIfNeeded(timeframe) {
|
|
2162
|
-
if (Date.now() - this._lastTimeframeSaveTime >
|
|
1353
|
+
if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL) {
|
|
2163
1354
|
this._lastTimeframeSaveTime = Date.now();
|
|
2164
1355
|
await this._saveTargetTimeframe(timeframe);
|
|
2165
1356
|
}
|
|
2166
1357
|
}
|
|
2167
1358
|
async stop() {
|
|
2168
|
-
|
|
2169
|
-
F:
|
|
2170
|
-
L:
|
|
1359
|
+
log6("stopping...", void 0, {
|
|
1360
|
+
F: __dxlog_file7,
|
|
1361
|
+
L: 205,
|
|
2171
1362
|
S: this,
|
|
2172
1363
|
C: (f, a) => f(...a)
|
|
2173
1364
|
});
|
|
2174
1365
|
await this._ctx.dispose();
|
|
2175
1366
|
await this._pipeline.stop();
|
|
2176
1367
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
2177
|
-
|
|
2178
|
-
F:
|
|
2179
|
-
L:
|
|
1368
|
+
log6("stopped", void 0, {
|
|
1369
|
+
F: __dxlog_file7,
|
|
1370
|
+
L: 209,
|
|
2180
1371
|
S: this,
|
|
2181
1372
|
C: (f, a) => f(...a)
|
|
2182
1373
|
});
|
|
2183
1374
|
}
|
|
2184
1375
|
async _saveTargetTimeframe(timeframe) {
|
|
2185
1376
|
try {
|
|
2186
|
-
const newTimeframe =
|
|
1377
|
+
const newTimeframe = Timeframe3.merge(this._targetTimeframe ?? new Timeframe3(), timeframe);
|
|
2187
1378
|
await this._metadata.setSpaceControlLatestTimeframe(this._spaceKey, newTimeframe);
|
|
2188
1379
|
this._targetTimeframe = newTimeframe;
|
|
2189
1380
|
} catch (err) {
|
|
2190
|
-
|
|
2191
|
-
F:
|
|
2192
|
-
L:
|
|
1381
|
+
log6(err, void 0, {
|
|
1382
|
+
F: __dxlog_file7,
|
|
1383
|
+
L: 218,
|
|
2193
1384
|
S: this,
|
|
2194
1385
|
C: (f, a) => f(...a)
|
|
2195
1386
|
});
|
|
2196
1387
|
}
|
|
2197
1388
|
}
|
|
2198
1389
|
};
|
|
2199
|
-
|
|
2200
|
-
|
|
1390
|
+
_ts_decorate4([
|
|
1391
|
+
trace.metricsCounter()
|
|
2201
1392
|
], ControlPipeline.prototype, "_usage", void 0);
|
|
2202
|
-
|
|
2203
|
-
|
|
1393
|
+
_ts_decorate4([
|
|
1394
|
+
trace.metricsCounter()
|
|
2204
1395
|
], ControlPipeline.prototype, "_mutations", void 0);
|
|
2205
|
-
|
|
2206
|
-
|
|
1396
|
+
_ts_decorate4([
|
|
1397
|
+
trace.span({
|
|
2207
1398
|
showInBrowserTimeline: true
|
|
2208
1399
|
})
|
|
2209
1400
|
], ControlPipeline.prototype, "start", null);
|
|
2210
|
-
|
|
2211
|
-
|
|
1401
|
+
_ts_decorate4([
|
|
1402
|
+
trace.span()
|
|
2212
1403
|
], ControlPipeline.prototype, "_consumePipeline", null);
|
|
2213
|
-
|
|
2214
|
-
|
|
1404
|
+
_ts_decorate4([
|
|
1405
|
+
trace.span()
|
|
2215
1406
|
], ControlPipeline.prototype, "_processMessage", null);
|
|
2216
|
-
ControlPipeline =
|
|
2217
|
-
|
|
2218
|
-
|
|
1407
|
+
ControlPipeline = _ts_decorate4([
|
|
1408
|
+
trace.resource(),
|
|
1409
|
+
trackLeaks("start", "stop")
|
|
2219
1410
|
], ControlPipeline);
|
|
2220
1411
|
|
|
2221
1412
|
// packages/core/echo/echo-pipeline/src/space/space.ts
|
|
2222
|
-
function
|
|
1413
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
2223
1414
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2224
1415
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2225
1416
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2229,16 +1420,16 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
2229
1420
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2230
1421
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2231
1422
|
}
|
|
2232
|
-
var
|
|
1423
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
|
|
2233
1424
|
var Space = class {
|
|
2234
1425
|
constructor(params) {
|
|
2235
1426
|
this._addFeedMutex = new Mutex();
|
|
2236
1427
|
this.onCredentialProcessed = new Callback2();
|
|
2237
|
-
this.stateUpdate = new
|
|
1428
|
+
this.stateUpdate = new Event4();
|
|
2238
1429
|
this._isOpen = false;
|
|
2239
|
-
|
|
2240
|
-
F:
|
|
2241
|
-
L:
|
|
1430
|
+
invariant6(params.spaceKey && params.feedProvider, void 0, {
|
|
1431
|
+
F: __dxlog_file8,
|
|
1432
|
+
L: 72,
|
|
2242
1433
|
S: this,
|
|
2243
1434
|
A: [
|
|
2244
1435
|
"params.spaceKey && params.feedProvider",
|
|
@@ -2257,17 +1448,6 @@ var Space = class {
|
|
|
2257
1448
|
});
|
|
2258
1449
|
this._controlPipeline.onFeedAdmitted.set(async (info) => {
|
|
2259
1450
|
const sparse = info.assertion.designation === AdmittedFeed2.Designation.DATA;
|
|
2260
|
-
if (info.assertion.designation === AdmittedFeed2.Designation.DATA) {
|
|
2261
|
-
queueMicrotask(async () => {
|
|
2262
|
-
if (this._dataPipeline.pipeline) {
|
|
2263
|
-
if (!this._dataPipeline.pipeline.hasFeed(info.key)) {
|
|
2264
|
-
return this._dataPipeline.pipeline.addFeed(await this._feedProvider(info.key, {
|
|
2265
|
-
sparse
|
|
2266
|
-
}));
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
});
|
|
2270
|
-
}
|
|
2271
1451
|
if (!info.key.equals(params.genesisFeed.key)) {
|
|
2272
1452
|
queueMicrotask(async () => {
|
|
2273
1453
|
this.protocol.addFeed(await params.feedProvider(info.key, {
|
|
@@ -2278,11 +1458,11 @@ var Space = class {
|
|
|
2278
1458
|
});
|
|
2279
1459
|
this._controlPipeline.onCredentialProcessed.set(async (credential) => {
|
|
2280
1460
|
await this.onCredentialProcessed.callIfSet(credential);
|
|
2281
|
-
|
|
1461
|
+
log7("onCredentialProcessed", {
|
|
2282
1462
|
credential
|
|
2283
1463
|
}, {
|
|
2284
|
-
F:
|
|
2285
|
-
L:
|
|
1464
|
+
F: __dxlog_file8,
|
|
1465
|
+
L: 99,
|
|
2286
1466
|
S: this,
|
|
2287
1467
|
C: (f, a) => f(...a)
|
|
2288
1468
|
});
|
|
@@ -2290,29 +1470,6 @@ var Space = class {
|
|
|
2290
1470
|
});
|
|
2291
1471
|
this.protocol = params.protocol;
|
|
2292
1472
|
this.protocol.addFeed(params.genesisFeed);
|
|
2293
|
-
this._dataPipeline = new DataPipeline({
|
|
2294
|
-
modelFactory: params.modelFactory,
|
|
2295
|
-
metadataStore: params.metadataStore,
|
|
2296
|
-
snapshotManager: params.snapshotManager,
|
|
2297
|
-
memberKey: params.memberKey,
|
|
2298
|
-
spaceKey: this._key,
|
|
2299
|
-
feedInfoProvider: (feedKey) => this._controlPipeline.spaceState.feeds.get(feedKey),
|
|
2300
|
-
snapshotId: params.snapshotId,
|
|
2301
|
-
onPipelineCreated: async (pipeline) => {
|
|
2302
|
-
if (this._dataFeed) {
|
|
2303
|
-
pipeline.setWriteFeed(this._dataFeed);
|
|
2304
|
-
}
|
|
2305
|
-
await this._addFeedMutex.executeSynchronized(async () => {
|
|
2306
|
-
for (const feed of this._controlPipeline.spaceState.feeds.values()) {
|
|
2307
|
-
if (feed.assertion.designation === AdmittedFeed2.Designation.DATA && !pipeline.hasFeed(feed.key)) {
|
|
2308
|
-
await pipeline.addFeed(await this._feedProvider(feed.key, {
|
|
2309
|
-
sparse: true
|
|
2310
|
-
}));
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
});
|
|
2314
|
-
}
|
|
2315
|
-
});
|
|
2316
1473
|
}
|
|
2317
1474
|
get key() {
|
|
2318
1475
|
return this._key;
|
|
@@ -2338,16 +1495,13 @@ var Space = class {
|
|
|
2338
1495
|
get controlPipeline() {
|
|
2339
1496
|
return this._controlPipeline.pipeline;
|
|
2340
1497
|
}
|
|
2341
|
-
get dataPipeline() {
|
|
2342
|
-
return this._dataPipeline;
|
|
2343
|
-
}
|
|
2344
1498
|
get snapshotManager() {
|
|
2345
1499
|
return this._snapshotManager;
|
|
2346
1500
|
}
|
|
2347
1501
|
async setControlFeed(feed) {
|
|
2348
|
-
|
|
2349
|
-
F:
|
|
2350
|
-
L:
|
|
1502
|
+
invariant6(!this._controlFeed, "Control feed already set.", {
|
|
1503
|
+
F: __dxlog_file8,
|
|
1504
|
+
L: 146,
|
|
2351
1505
|
S: this,
|
|
2352
1506
|
A: [
|
|
2353
1507
|
"!this._controlFeed",
|
|
@@ -2359,9 +1513,9 @@ var Space = class {
|
|
|
2359
1513
|
return this;
|
|
2360
1514
|
}
|
|
2361
1515
|
async setDataFeed(feed) {
|
|
2362
|
-
|
|
2363
|
-
F:
|
|
2364
|
-
L:
|
|
1516
|
+
invariant6(!this._dataFeed, "Data feed already set.", {
|
|
1517
|
+
F: __dxlog_file8,
|
|
1518
|
+
L: 153,
|
|
2365
1519
|
S: this,
|
|
2366
1520
|
A: [
|
|
2367
1521
|
"!this._dataFeed",
|
|
@@ -2369,8 +1523,6 @@ var Space = class {
|
|
|
2369
1523
|
]
|
|
2370
1524
|
});
|
|
2371
1525
|
this._dataFeed = feed;
|
|
2372
|
-
await this._dataPipeline.pipeline?.addFeed(feed);
|
|
2373
|
-
this._dataPipeline.pipeline?.setWriteFeed(feed);
|
|
2374
1526
|
return this;
|
|
2375
1527
|
}
|
|
2376
1528
|
/**
|
|
@@ -2386,9 +1538,9 @@ var Space = class {
|
|
|
2386
1538
|
// return this._dataPipeline?.getFeeds();
|
|
2387
1539
|
// }
|
|
2388
1540
|
async open(ctx) {
|
|
2389
|
-
|
|
2390
|
-
F:
|
|
2391
|
-
L:
|
|
1541
|
+
log7("opening...", void 0, {
|
|
1542
|
+
F: __dxlog_file8,
|
|
1543
|
+
L: 174,
|
|
2392
1544
|
S: this,
|
|
2393
1545
|
C: (f, a) => f(...a)
|
|
2394
1546
|
});
|
|
@@ -2397,97 +1549,70 @@ var Space = class {
|
|
|
2397
1549
|
}
|
|
2398
1550
|
await this._controlPipeline.start();
|
|
2399
1551
|
await this.protocol.start();
|
|
2400
|
-
await this._controlPipeline.spaceState.addCredentialProcessor(this._dataPipeline);
|
|
2401
1552
|
this._isOpen = true;
|
|
2402
|
-
|
|
2403
|
-
F:
|
|
2404
|
-
L:
|
|
1553
|
+
log7("opened", void 0, {
|
|
1554
|
+
F: __dxlog_file8,
|
|
1555
|
+
L: 184,
|
|
2405
1556
|
S: this,
|
|
2406
1557
|
C: (f, a) => f(...a)
|
|
2407
1558
|
});
|
|
2408
1559
|
}
|
|
2409
1560
|
async close() {
|
|
2410
|
-
|
|
1561
|
+
log7("closing...", {
|
|
2411
1562
|
key: this._key
|
|
2412
1563
|
}, {
|
|
2413
|
-
F:
|
|
2414
|
-
L:
|
|
1564
|
+
F: __dxlog_file8,
|
|
1565
|
+
L: 189,
|
|
2415
1566
|
S: this,
|
|
2416
1567
|
C: (f, a) => f(...a)
|
|
2417
1568
|
});
|
|
2418
1569
|
if (!this._isOpen) {
|
|
2419
1570
|
return;
|
|
2420
1571
|
}
|
|
2421
|
-
await this._controlPipeline.spaceState.removeCredentialProcessor(this._dataPipeline);
|
|
2422
|
-
await this._dataPipeline.close();
|
|
2423
1572
|
await this.protocol.stop();
|
|
2424
1573
|
await this._controlPipeline.stop();
|
|
2425
1574
|
this._isOpen = false;
|
|
2426
|
-
|
|
2427
|
-
F:
|
|
2428
|
-
L:
|
|
2429
|
-
S: this,
|
|
2430
|
-
C: (f, a) => f(...a)
|
|
2431
|
-
});
|
|
2432
|
-
}
|
|
2433
|
-
async initializeDataPipeline() {
|
|
2434
|
-
log10("initializeDataPipeline", void 0, {
|
|
2435
|
-
F: __dxlog_file11,
|
|
2436
|
-
L: 255,
|
|
1575
|
+
log7("closed", void 0, {
|
|
1576
|
+
F: __dxlog_file8,
|
|
1577
|
+
L: 199,
|
|
2437
1578
|
S: this,
|
|
2438
1579
|
C: (f, a) => f(...a)
|
|
2439
1580
|
});
|
|
2440
|
-
invariant9(this._isOpen, "Space must be open to initialize data pipeline.", {
|
|
2441
|
-
F: __dxlog_file11,
|
|
2442
|
-
L: 256,
|
|
2443
|
-
S: this,
|
|
2444
|
-
A: [
|
|
2445
|
-
"this._isOpen",
|
|
2446
|
-
"'Space must be open to initialize data pipeline.'"
|
|
2447
|
-
]
|
|
2448
|
-
});
|
|
2449
|
-
await this._dataPipeline.open();
|
|
2450
1581
|
}
|
|
2451
1582
|
};
|
|
2452
|
-
|
|
2453
|
-
|
|
1583
|
+
_ts_decorate5([
|
|
1584
|
+
trace2.info()
|
|
2454
1585
|
], Space.prototype, "protocol", void 0);
|
|
2455
|
-
|
|
2456
|
-
|
|
1586
|
+
_ts_decorate5([
|
|
1587
|
+
trace2.info()
|
|
2457
1588
|
], Space.prototype, "_controlPipeline", void 0);
|
|
2458
|
-
|
|
2459
|
-
trace3.info()
|
|
2460
|
-
], Space.prototype, "_dataPipeline", void 0);
|
|
2461
|
-
_ts_decorate6([
|
|
1589
|
+
_ts_decorate5([
|
|
2462
1590
|
logInfo,
|
|
2463
|
-
|
|
1591
|
+
trace2.info()
|
|
2464
1592
|
], Space.prototype, "key", null);
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
1593
|
+
_ts_decorate5([
|
|
1594
|
+
synchronized3,
|
|
1595
|
+
trace2.span()
|
|
2468
1596
|
], Space.prototype, "open", null);
|
|
2469
|
-
|
|
2470
|
-
|
|
1597
|
+
_ts_decorate5([
|
|
1598
|
+
synchronized3
|
|
2471
1599
|
], Space.prototype, "close", null);
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
Space = _ts_decorate6([
|
|
2476
|
-
trackLeaks3("open", "close"),
|
|
2477
|
-
trace3.resource()
|
|
1600
|
+
Space = _ts_decorate5([
|
|
1601
|
+
trackLeaks2("open", "close"),
|
|
1602
|
+
trace2.resource()
|
|
2478
1603
|
], Space);
|
|
2479
1604
|
|
|
2480
1605
|
// packages/core/echo/echo-pipeline/src/space/space-protocol.ts
|
|
2481
1606
|
import { discoveryKey, subtleCrypto as subtleCrypto2 } from "@dxos/crypto";
|
|
2482
|
-
import { PublicKey as
|
|
2483
|
-
import { log as
|
|
1607
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1608
|
+
import { log as log8, logInfo as logInfo2 } from "@dxos/log";
|
|
2484
1609
|
import { MMSTTopology } from "@dxos/network-manager";
|
|
2485
1610
|
import { Teleport } from "@dxos/teleport";
|
|
2486
1611
|
import { BlobSync } from "@dxos/teleport-extension-object-sync";
|
|
2487
1612
|
import { ReplicatorExtension } from "@dxos/teleport-extension-replicator";
|
|
2488
|
-
import { trace as
|
|
2489
|
-
import { ComplexMap as
|
|
2490
|
-
function
|
|
1613
|
+
import { trace as trace3 } from "@dxos/tracing";
|
|
1614
|
+
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
1615
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
2491
1616
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2492
1617
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2493
1618
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2497,13 +1622,13 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
2497
1622
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2498
1623
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2499
1624
|
}
|
|
2500
|
-
var
|
|
1625
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
|
|
2501
1626
|
var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
|
|
2502
1627
|
var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
|
|
2503
1628
|
var SpaceProtocol = class {
|
|
2504
1629
|
constructor({ topic, swarmIdentity, networkManager, onSessionAuth, onAuthFailure, blobStore }) {
|
|
2505
1630
|
this._feeds = /* @__PURE__ */ new Set();
|
|
2506
|
-
this._sessions = new
|
|
1631
|
+
this._sessions = new ComplexMap3(PublicKey5.hash);
|
|
2507
1632
|
this._spaceKey = topic;
|
|
2508
1633
|
this._networkManager = networkManager;
|
|
2509
1634
|
this._swarmIdentity = swarmIdentity;
|
|
@@ -2512,7 +1637,7 @@ var SpaceProtocol = class {
|
|
|
2512
1637
|
this.blobSync = new BlobSync({
|
|
2513
1638
|
blobStore
|
|
2514
1639
|
});
|
|
2515
|
-
this._topic = subtleCrypto2.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(
|
|
1640
|
+
this._topic = subtleCrypto2.digest("SHA-256", topic.asBuffer()).then(discoveryKey).then(PublicKey5.from);
|
|
2516
1641
|
}
|
|
2517
1642
|
get sessions() {
|
|
2518
1643
|
return this._sessions;
|
|
@@ -2525,10 +1650,10 @@ var SpaceProtocol = class {
|
|
|
2525
1650
|
}
|
|
2526
1651
|
// TODO(burdon): Create abstraction for Space (e.g., add keys and have provider).
|
|
2527
1652
|
addFeed(feed) {
|
|
2528
|
-
|
|
1653
|
+
log8("addFeed", {
|
|
2529
1654
|
key: feed.key
|
|
2530
1655
|
}, {
|
|
2531
|
-
F:
|
|
1656
|
+
F: __dxlog_file9,
|
|
2532
1657
|
L: 103,
|
|
2533
1658
|
S: this,
|
|
2534
1659
|
C: (f, a) => f(...a)
|
|
@@ -2550,8 +1675,8 @@ var SpaceProtocol = class {
|
|
|
2550
1675
|
sampleSize: 20
|
|
2551
1676
|
};
|
|
2552
1677
|
await this.blobSync.open();
|
|
2553
|
-
|
|
2554
|
-
F:
|
|
1678
|
+
log8("starting...", void 0, {
|
|
1679
|
+
F: __dxlog_file9,
|
|
2555
1680
|
L: 129,
|
|
2556
1681
|
S: this,
|
|
2557
1682
|
C: (f, a) => f(...a)
|
|
@@ -2564,8 +1689,8 @@ var SpaceProtocol = class {
|
|
|
2564
1689
|
topology: new MMSTTopology(topologyConfig),
|
|
2565
1690
|
label: `swarm ${topic.truncate()} for space ${this._spaceKey.truncate()}`
|
|
2566
1691
|
});
|
|
2567
|
-
|
|
2568
|
-
F:
|
|
1692
|
+
log8("started", void 0, {
|
|
1693
|
+
F: __dxlog_file9,
|
|
2569
1694
|
L: 139,
|
|
2570
1695
|
S: this,
|
|
2571
1696
|
C: (f, a) => f(...a)
|
|
@@ -2574,15 +1699,15 @@ var SpaceProtocol = class {
|
|
|
2574
1699
|
async stop() {
|
|
2575
1700
|
await this.blobSync.close();
|
|
2576
1701
|
if (this._connection) {
|
|
2577
|
-
|
|
2578
|
-
F:
|
|
1702
|
+
log8("stopping...", void 0, {
|
|
1703
|
+
F: __dxlog_file9,
|
|
2579
1704
|
L: 146,
|
|
2580
1705
|
S: this,
|
|
2581
1706
|
C: (f, a) => f(...a)
|
|
2582
1707
|
});
|
|
2583
1708
|
await this._connection.close();
|
|
2584
|
-
|
|
2585
|
-
F:
|
|
1709
|
+
log8("stopped", void 0, {
|
|
1710
|
+
F: __dxlog_file9,
|
|
2586
1711
|
L: 148,
|
|
2587
1712
|
S: this,
|
|
2588
1713
|
C: (f, a) => f(...a)
|
|
@@ -2606,18 +1731,18 @@ var SpaceProtocol = class {
|
|
|
2606
1731
|
};
|
|
2607
1732
|
}
|
|
2608
1733
|
};
|
|
2609
|
-
|
|
1734
|
+
_ts_decorate6([
|
|
2610
1735
|
logInfo2,
|
|
2611
|
-
|
|
1736
|
+
trace3.info()
|
|
2612
1737
|
], SpaceProtocol.prototype, "_topic", void 0);
|
|
2613
|
-
|
|
2614
|
-
|
|
1738
|
+
_ts_decorate6([
|
|
1739
|
+
trace3.info()
|
|
2615
1740
|
], SpaceProtocol.prototype, "_spaceKey", void 0);
|
|
2616
|
-
|
|
1741
|
+
_ts_decorate6([
|
|
2617
1742
|
logInfo2
|
|
2618
1743
|
], SpaceProtocol.prototype, "_ownPeerKey", null);
|
|
2619
|
-
SpaceProtocol =
|
|
2620
|
-
|
|
1744
|
+
SpaceProtocol = _ts_decorate6([
|
|
1745
|
+
trace3.resource()
|
|
2621
1746
|
], SpaceProtocol);
|
|
2622
1747
|
var AuthStatus;
|
|
2623
1748
|
(function(AuthStatus2) {
|
|
@@ -2655,8 +1780,8 @@ var SpaceProtocolSession = class {
|
|
|
2655
1780
|
provider: this._swarmIdentity.credentialProvider,
|
|
2656
1781
|
verifier: this._swarmIdentity.credentialAuthenticator,
|
|
2657
1782
|
onAuthSuccess: () => {
|
|
2658
|
-
|
|
2659
|
-
F:
|
|
1783
|
+
log8("Peer authenticated", void 0, {
|
|
1784
|
+
F: __dxlog_file9,
|
|
2660
1785
|
L: 245,
|
|
2661
1786
|
S: this,
|
|
2662
1787
|
C: (f, a) => f(...a)
|
|
@@ -2673,8 +1798,8 @@ var SpaceProtocolSession = class {
|
|
|
2673
1798
|
this._teleport.addExtension("dxos.mesh.teleport.blobsync", this._blobSync.createExtension());
|
|
2674
1799
|
}
|
|
2675
1800
|
async close() {
|
|
2676
|
-
|
|
2677
|
-
F:
|
|
1801
|
+
log8("close", void 0, {
|
|
1802
|
+
F: __dxlog_file9,
|
|
2678
1803
|
L: 261,
|
|
2679
1804
|
S: this,
|
|
2680
1805
|
C: (f, a) => f(...a)
|
|
@@ -2685,21 +1810,21 @@ var SpaceProtocolSession = class {
|
|
|
2685
1810
|
await this._teleport.abort();
|
|
2686
1811
|
}
|
|
2687
1812
|
};
|
|
2688
|
-
|
|
1813
|
+
_ts_decorate6([
|
|
2689
1814
|
logInfo2
|
|
2690
1815
|
], SpaceProtocolSession.prototype, "_wireParams", void 0);
|
|
2691
|
-
|
|
1816
|
+
_ts_decorate6([
|
|
2692
1817
|
logInfo2
|
|
2693
1818
|
], SpaceProtocolSession.prototype, "authStatus", null);
|
|
2694
1819
|
|
|
2695
1820
|
// packages/core/echo/echo-pipeline/src/space/space-manager.ts
|
|
2696
|
-
import { synchronized as
|
|
1821
|
+
import { synchronized as synchronized4, trackLeaks as trackLeaks3 } from "@dxos/async";
|
|
2697
1822
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
2698
|
-
import { PublicKey as
|
|
2699
|
-
import { log as
|
|
2700
|
-
import { trace as
|
|
2701
|
-
import { ComplexMap as
|
|
2702
|
-
function
|
|
1823
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1824
|
+
import { log as log9 } from "@dxos/log";
|
|
1825
|
+
import { trace as trace4 } from "@dxos/protocols";
|
|
1826
|
+
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1827
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
2703
1828
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2704
1829
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2705
1830
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2709,14 +1834,13 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
2709
1834
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2710
1835
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2711
1836
|
}
|
|
2712
|
-
var
|
|
1837
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
|
|
2713
1838
|
var SpaceManager = class {
|
|
2714
|
-
constructor({ feedStore, networkManager,
|
|
2715
|
-
this._spaces = new
|
|
2716
|
-
this._instanceId =
|
|
1839
|
+
constructor({ feedStore, networkManager, metadataStore, snapshotStore, blobStore }) {
|
|
1840
|
+
this._spaces = new ComplexMap4(PublicKey6.hash);
|
|
1841
|
+
this._instanceId = PublicKey6.random().toHex();
|
|
2717
1842
|
this._feedStore = feedStore;
|
|
2718
1843
|
this._networkManager = networkManager;
|
|
2719
|
-
this._modelFactory = modelFactory;
|
|
2720
1844
|
this._metadataStore = metadataStore;
|
|
2721
1845
|
this._snapshotStore = snapshotStore;
|
|
2722
1846
|
this._blobStore = blobStore;
|
|
@@ -2733,19 +1857,19 @@ var SpaceManager = class {
|
|
|
2733
1857
|
].map((space) => space.close()));
|
|
2734
1858
|
}
|
|
2735
1859
|
async constructSpace({ metadata, swarmIdentity, onAuthorizedConnection, onAuthFailure, memberKey }) {
|
|
2736
|
-
|
|
1860
|
+
log9.trace("dxos.echo.space-manager.construct-space", trace4.begin({
|
|
2737
1861
|
id: this._instanceId
|
|
2738
1862
|
}), {
|
|
2739
|
-
F:
|
|
2740
|
-
L:
|
|
1863
|
+
F: __dxlog_file10,
|
|
1864
|
+
L: 89,
|
|
2741
1865
|
S: this,
|
|
2742
1866
|
C: (f, a) => f(...a)
|
|
2743
1867
|
});
|
|
2744
|
-
|
|
1868
|
+
log9("constructing space...", {
|
|
2745
1869
|
spaceKey: metadata.genesisFeedKey
|
|
2746
1870
|
}, {
|
|
2747
|
-
F:
|
|
2748
|
-
L:
|
|
1871
|
+
F: __dxlog_file10,
|
|
1872
|
+
L: 90,
|
|
2749
1873
|
S: this,
|
|
2750
1874
|
C: (f, a) => f(...a)
|
|
2751
1875
|
});
|
|
@@ -2765,674 +1889,38 @@ var SpaceManager = class {
|
|
|
2765
1889
|
protocol,
|
|
2766
1890
|
genesisFeed,
|
|
2767
1891
|
feedProvider: (feedKey, opts) => this._feedStore.openFeed(feedKey, opts),
|
|
2768
|
-
modelFactory: this._modelFactory,
|
|
2769
1892
|
metadataStore: this._metadataStore,
|
|
2770
1893
|
snapshotManager,
|
|
2771
1894
|
memberKey
|
|
2772
1895
|
});
|
|
2773
1896
|
this._spaces.set(space.key, space);
|
|
2774
|
-
|
|
1897
|
+
log9.trace("dxos.echo.space-manager.construct-space", trace4.end({
|
|
2775
1898
|
id: this._instanceId
|
|
2776
1899
|
}), {
|
|
2777
|
-
F:
|
|
2778
|
-
L:
|
|
1900
|
+
F: __dxlog_file10,
|
|
1901
|
+
L: 117,
|
|
2779
1902
|
S: this,
|
|
2780
1903
|
C: (f, a) => f(...a)
|
|
2781
1904
|
});
|
|
2782
1905
|
return space;
|
|
2783
1906
|
}
|
|
2784
1907
|
};
|
|
2785
|
-
|
|
2786
|
-
|
|
1908
|
+
_ts_decorate7([
|
|
1909
|
+
synchronized4
|
|
2787
1910
|
], SpaceManager.prototype, "open", null);
|
|
2788
|
-
|
|
2789
|
-
|
|
1911
|
+
_ts_decorate7([
|
|
1912
|
+
synchronized4
|
|
2790
1913
|
], SpaceManager.prototype, "close", null);
|
|
2791
|
-
SpaceManager =
|
|
2792
|
-
|
|
1914
|
+
SpaceManager = _ts_decorate7([
|
|
1915
|
+
trackLeaks3("open", "close")
|
|
2793
1916
|
], SpaceManager);
|
|
2794
1917
|
|
|
2795
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage-adapter.ts
|
|
2796
|
-
import { arrayToBuffer as arrayToBuffer2, bufferToArray } from "@dxos/util";
|
|
2797
|
-
var AutomergeStorageAdapter = class {
|
|
2798
|
-
constructor(_directory) {
|
|
2799
|
-
this._directory = _directory;
|
|
2800
|
-
this._state = "opened";
|
|
2801
|
-
}
|
|
2802
|
-
async load(key) {
|
|
2803
|
-
if (this._state !== "opened") {
|
|
2804
|
-
return void 0;
|
|
2805
|
-
}
|
|
2806
|
-
const filename = this._getFilename(key);
|
|
2807
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
2808
|
-
const { size } = await file.stat();
|
|
2809
|
-
if (!size || size === 0) {
|
|
2810
|
-
return void 0;
|
|
2811
|
-
}
|
|
2812
|
-
const buffer = await file.read(0, size);
|
|
2813
|
-
return bufferToArray(buffer);
|
|
2814
|
-
}
|
|
2815
|
-
async save(key, data) {
|
|
2816
|
-
if (this._state !== "opened") {
|
|
2817
|
-
return void 0;
|
|
2818
|
-
}
|
|
2819
|
-
const filename = this._getFilename(key);
|
|
2820
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
2821
|
-
await file.write(0, arrayToBuffer2(data));
|
|
2822
|
-
await file.truncate?.(data.length);
|
|
2823
|
-
await file.flush?.();
|
|
2824
|
-
}
|
|
2825
|
-
async remove(key) {
|
|
2826
|
-
if (this._state !== "opened") {
|
|
2827
|
-
return void 0;
|
|
2828
|
-
}
|
|
2829
|
-
const filename = this._getFilename(key);
|
|
2830
|
-
const file = this._directory.getOrCreateFile(filename);
|
|
2831
|
-
await file.destroy();
|
|
2832
|
-
}
|
|
2833
|
-
async loadRange(keyPrefix) {
|
|
2834
|
-
if (this._state !== "opened") {
|
|
2835
|
-
return [];
|
|
2836
|
-
}
|
|
2837
|
-
const filename = this._getFilename(keyPrefix);
|
|
2838
|
-
const entries = await this._directory.list();
|
|
2839
|
-
return Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
2840
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
2841
|
-
const { size } = await file.stat();
|
|
2842
|
-
const buffer = await file.read(0, size);
|
|
2843
|
-
return {
|
|
2844
|
-
key: this._getKeyFromFilename(entry),
|
|
2845
|
-
data: bufferToArray(buffer)
|
|
2846
|
-
};
|
|
2847
|
-
}));
|
|
2848
|
-
}
|
|
2849
|
-
async removeRange(keyPrefix) {
|
|
2850
|
-
if (this._state !== "opened") {
|
|
2851
|
-
return void 0;
|
|
2852
|
-
}
|
|
2853
|
-
const filename = this._getFilename(keyPrefix);
|
|
2854
|
-
const entries = await this._directory.list();
|
|
2855
|
-
await Promise.all(entries.filter((entry) => entry.startsWith(filename)).map(async (entry) => {
|
|
2856
|
-
const file = this._directory.getOrCreateFile(entry);
|
|
2857
|
-
await file.destroy();
|
|
2858
|
-
}));
|
|
2859
|
-
}
|
|
2860
|
-
async close() {
|
|
2861
|
-
this._state = "closed";
|
|
2862
|
-
}
|
|
2863
|
-
_getFilename(key) {
|
|
2864
|
-
return key.map((k) => k.replaceAll("%", "%25").replaceAll("-", "%2D")).join("-");
|
|
2865
|
-
}
|
|
2866
|
-
_getKeyFromFilename(filename) {
|
|
2867
|
-
return filename.split("-").map((k) => k.replaceAll("%2D", "-").replaceAll("%25", "%"));
|
|
2868
|
-
}
|
|
2869
|
-
};
|
|
2870
|
-
|
|
2871
|
-
// packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts
|
|
2872
|
-
import { Trigger as Trigger2 } from "@dxos/async";
|
|
2873
|
-
import { NetworkAdapter, cbor } from "@dxos/automerge/automerge-repo";
|
|
2874
|
-
import { Stream as Stream2 } from "@dxos/codec-protobuf";
|
|
2875
|
-
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2876
|
-
import { log as log13 } from "@dxos/log";
|
|
2877
|
-
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/local-host-network-adapter.ts";
|
|
2878
|
-
var LocalHostNetworkAdapter = class extends NetworkAdapter {
|
|
2879
|
-
constructor() {
|
|
2880
|
-
super(...arguments);
|
|
2881
|
-
this._peers = /* @__PURE__ */ new Map();
|
|
2882
|
-
this._connected = new Trigger2();
|
|
2883
|
-
}
|
|
2884
|
-
/**
|
|
2885
|
-
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
2886
|
-
*/
|
|
2887
|
-
ready() {
|
|
2888
|
-
this.emit("ready", {
|
|
2889
|
-
network: this
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
connect(peerId) {
|
|
2893
|
-
this.peerId = peerId;
|
|
2894
|
-
this._connected.wake();
|
|
2895
|
-
}
|
|
2896
|
-
send(message) {
|
|
2897
|
-
const peer = this._peers.get(message.targetId);
|
|
2898
|
-
invariant10(peer, "Peer not found.", {
|
|
2899
|
-
F: __dxlog_file14,
|
|
2900
|
-
L: 45,
|
|
2901
|
-
S: this,
|
|
2902
|
-
A: [
|
|
2903
|
-
"peer",
|
|
2904
|
-
"'Peer not found.'"
|
|
2905
|
-
]
|
|
2906
|
-
});
|
|
2907
|
-
peer.send(message);
|
|
2908
|
-
}
|
|
2909
|
-
async close() {
|
|
2910
|
-
this._peers.forEach((peer) => peer.disconnect());
|
|
2911
|
-
this.emit("close");
|
|
2912
|
-
}
|
|
2913
|
-
disconnect() {
|
|
2914
|
-
}
|
|
2915
|
-
syncRepo({ id, syncMessage }) {
|
|
2916
|
-
const peerId = this._getPeerId(id);
|
|
2917
|
-
return new Stream2(({ next, close }) => {
|
|
2918
|
-
invariant10(!this._peers.has(peerId), "Peer already connected.", {
|
|
2919
|
-
F: __dxlog_file14,
|
|
2920
|
-
L: 63,
|
|
2921
|
-
S: this,
|
|
2922
|
-
A: [
|
|
2923
|
-
"!this._peers.has(peerId)",
|
|
2924
|
-
"'Peer already connected.'"
|
|
2925
|
-
]
|
|
2926
|
-
});
|
|
2927
|
-
this._peers.set(peerId, {
|
|
2928
|
-
connected: true,
|
|
2929
|
-
send: (message) => {
|
|
2930
|
-
next({
|
|
2931
|
-
syncMessage: cbor.encode(message)
|
|
2932
|
-
});
|
|
2933
|
-
},
|
|
2934
|
-
disconnect: () => {
|
|
2935
|
-
this._peers.delete(peerId);
|
|
2936
|
-
close();
|
|
2937
|
-
this.emit("peer-disconnected", {
|
|
2938
|
-
peerId
|
|
2939
|
-
});
|
|
2940
|
-
}
|
|
2941
|
-
});
|
|
2942
|
-
this._connected.wait({
|
|
2943
|
-
timeout: 1e3
|
|
2944
|
-
}).then(() => {
|
|
2945
|
-
this.emit("peer-candidate", {
|
|
2946
|
-
peerMetadata: {},
|
|
2947
|
-
peerId
|
|
2948
|
-
});
|
|
2949
|
-
}).catch((err) => log13.catch(err, void 0, {
|
|
2950
|
-
F: __dxlog_file14,
|
|
2951
|
-
L: 88,
|
|
2952
|
-
S: this,
|
|
2953
|
-
C: (f, a) => f(...a)
|
|
2954
|
-
}));
|
|
2955
|
-
});
|
|
2956
|
-
}
|
|
2957
|
-
async sendSyncMessage({ id, syncMessage }) {
|
|
2958
|
-
await this._connected.wait({
|
|
2959
|
-
timeout: 1e3
|
|
2960
|
-
});
|
|
2961
|
-
const message = cbor.decode(syncMessage);
|
|
2962
|
-
this.emit("message", message);
|
|
2963
|
-
}
|
|
2964
|
-
async getHostInfo() {
|
|
2965
|
-
await this._connected.wait({
|
|
2966
|
-
timeout: 1e3
|
|
2967
|
-
});
|
|
2968
|
-
invariant10(this.peerId, "Peer id not set.", {
|
|
2969
|
-
F: __dxlog_file14,
|
|
2970
|
-
L: 100,
|
|
2971
|
-
S: this,
|
|
2972
|
-
A: [
|
|
2973
|
-
"this.peerId",
|
|
2974
|
-
"'Peer id not set.'"
|
|
2975
|
-
]
|
|
2976
|
-
});
|
|
2977
|
-
return {
|
|
2978
|
-
peerId: this.peerId
|
|
2979
|
-
};
|
|
2980
|
-
}
|
|
2981
|
-
_getPeerId(id) {
|
|
2982
|
-
return id;
|
|
2983
|
-
}
|
|
2984
|
-
};
|
|
2985
|
-
|
|
2986
|
-
// packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts
|
|
2987
|
-
import { Trigger as Trigger3 } from "@dxos/async";
|
|
2988
|
-
import { NetworkAdapter as NetworkAdapter2, cbor as cbor2 } from "@dxos/automerge/automerge-repo";
|
|
2989
|
-
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2990
|
-
import { log as log14 } from "@dxos/log";
|
|
2991
|
-
import { AutomergeReplicator } from "@dxos/teleport-extension-automerge-replicator";
|
|
2992
|
-
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/mesh-network-adapter.ts";
|
|
2993
|
-
var MeshNetworkAdapter = class extends NetworkAdapter2 {
|
|
2994
|
-
constructor() {
|
|
2995
|
-
super(...arguments);
|
|
2996
|
-
this._extensions = /* @__PURE__ */ new Map();
|
|
2997
|
-
this._connected = new Trigger3();
|
|
2998
|
-
}
|
|
2999
|
-
/**
|
|
3000
|
-
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
3001
|
-
*/
|
|
3002
|
-
ready() {
|
|
3003
|
-
this.emit("ready", {
|
|
3004
|
-
network: this
|
|
3005
|
-
});
|
|
3006
|
-
}
|
|
3007
|
-
connect(peerId) {
|
|
3008
|
-
this.peerId = peerId;
|
|
3009
|
-
this._connected.wake();
|
|
3010
|
-
}
|
|
3011
|
-
send(message) {
|
|
3012
|
-
const receiverId = message.targetId;
|
|
3013
|
-
const extension = this._extensions.get(receiverId);
|
|
3014
|
-
invariant11(extension, "Extension not found.", {
|
|
3015
|
-
F: __dxlog_file15,
|
|
3016
|
-
L: 38,
|
|
3017
|
-
S: this,
|
|
3018
|
-
A: [
|
|
3019
|
-
"extension",
|
|
3020
|
-
"'Extension not found.'"
|
|
3021
|
-
]
|
|
3022
|
-
});
|
|
3023
|
-
extension.sendSyncMessage({
|
|
3024
|
-
payload: cbor2.encode(message)
|
|
3025
|
-
}).catch((err) => log14.catch(err, void 0, {
|
|
3026
|
-
F: __dxlog_file15,
|
|
3027
|
-
L: 39,
|
|
3028
|
-
S: this,
|
|
3029
|
-
C: (f, a) => f(...a)
|
|
3030
|
-
}));
|
|
3031
|
-
}
|
|
3032
|
-
disconnect() {
|
|
3033
|
-
}
|
|
3034
|
-
createExtension() {
|
|
3035
|
-
invariant11(this.peerId, "Peer id not set.", {
|
|
3036
|
-
F: __dxlog_file15,
|
|
3037
|
-
L: 47,
|
|
3038
|
-
S: this,
|
|
3039
|
-
A: [
|
|
3040
|
-
"this.peerId",
|
|
3041
|
-
"'Peer id not set.'"
|
|
3042
|
-
]
|
|
3043
|
-
});
|
|
3044
|
-
let peerInfo;
|
|
3045
|
-
const extension = new AutomergeReplicator({
|
|
3046
|
-
peerId: this.peerId
|
|
3047
|
-
}, {
|
|
3048
|
-
onStartReplication: async (info, remotePeerId) => {
|
|
3049
|
-
await this._connected.wait();
|
|
3050
|
-
log14("onStartReplication", {
|
|
3051
|
-
id: info.id,
|
|
3052
|
-
thisPeerId: this.peerId,
|
|
3053
|
-
remotePeerId: remotePeerId.toHex()
|
|
3054
|
-
}, {
|
|
3055
|
-
F: __dxlog_file15,
|
|
3056
|
-
L: 70,
|
|
3057
|
-
S: this,
|
|
3058
|
-
C: (f, a) => f(...a)
|
|
3059
|
-
});
|
|
3060
|
-
if (!this._extensions.has(info.id)) {
|
|
3061
|
-
peerInfo = info;
|
|
3062
|
-
this._extensions.set(info.id, extension);
|
|
3063
|
-
log14("peer-candidate", {
|
|
3064
|
-
id: info.id,
|
|
3065
|
-
thisPeerId: this.peerId,
|
|
3066
|
-
remotePeerId: remotePeerId.toHex()
|
|
3067
|
-
}, {
|
|
3068
|
-
F: __dxlog_file15,
|
|
3069
|
-
L: 76,
|
|
3070
|
-
S: this,
|
|
3071
|
-
C: (f, a) => f(...a)
|
|
3072
|
-
});
|
|
3073
|
-
this.emit("peer-candidate", {
|
|
3074
|
-
// TODO(mykola): Hack, stop abusing `peerMetadata` field.
|
|
3075
|
-
peerMetadata: {
|
|
3076
|
-
dxos_deviceKey: remotePeerId.toHex()
|
|
3077
|
-
},
|
|
3078
|
-
peerId: info.id
|
|
3079
|
-
});
|
|
3080
|
-
}
|
|
3081
|
-
},
|
|
3082
|
-
onSyncMessage: async ({ payload }) => {
|
|
3083
|
-
if (!peerInfo) {
|
|
3084
|
-
return;
|
|
3085
|
-
}
|
|
3086
|
-
const message = cbor2.decode(payload);
|
|
3087
|
-
this.emit("message", message);
|
|
3088
|
-
},
|
|
3089
|
-
onClose: async () => {
|
|
3090
|
-
if (!peerInfo) {
|
|
3091
|
-
return;
|
|
3092
|
-
}
|
|
3093
|
-
this.emit("peer-disconnected", {
|
|
3094
|
-
peerId: peerInfo.id
|
|
3095
|
-
});
|
|
3096
|
-
this._extensions.delete(peerInfo.id);
|
|
3097
|
-
}
|
|
3098
|
-
});
|
|
3099
|
-
return extension;
|
|
3100
|
-
}
|
|
3101
|
-
};
|
|
3102
|
-
|
|
3103
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
3104
|
-
import { next as automerge, getHeads } from "@dxos/automerge/automerge";
|
|
3105
|
-
import { Repo } from "@dxos/automerge/automerge-repo";
|
|
3106
|
-
import { IndexedDBStorageAdapter } from "@dxos/automerge/automerge-repo-storage-indexeddb";
|
|
3107
|
-
import { Context as Context7 } from "@dxos/context";
|
|
3108
|
-
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
3109
|
-
import { log as log15 } from "@dxos/log";
|
|
3110
|
-
import { idCodec } from "@dxos/protocols";
|
|
3111
|
-
import { StorageType } from "@dxos/random-access-storage";
|
|
3112
|
-
import { trace as trace6 } from "@dxos/tracing";
|
|
3113
|
-
import { ComplexMap as ComplexMap7, ComplexSet, defaultMap, mapValues } from "@dxos/util";
|
|
3114
|
-
|
|
3115
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-storage–wrapper.ts
|
|
3116
|
-
var AutomergeStorageWrapper = class {
|
|
3117
|
-
constructor({ storage, callbacks }) {
|
|
3118
|
-
this._storage = storage;
|
|
3119
|
-
this._callbacks = callbacks;
|
|
3120
|
-
}
|
|
3121
|
-
async load(key) {
|
|
3122
|
-
return this._storage.load(key);
|
|
3123
|
-
}
|
|
3124
|
-
async save(key, value) {
|
|
3125
|
-
await this._callbacks.beforeSave?.(key);
|
|
3126
|
-
await this._storage.save(key, value);
|
|
3127
|
-
await this._callbacks.afterSave?.(key);
|
|
3128
|
-
}
|
|
3129
|
-
async remove(key) {
|
|
3130
|
-
return this._storage.remove(key);
|
|
3131
|
-
}
|
|
3132
|
-
async loadRange(keyPrefix) {
|
|
3133
|
-
return this._storage.loadRange(keyPrefix);
|
|
3134
|
-
}
|
|
3135
|
-
async removeRange(keyPrefix) {
|
|
3136
|
-
return this._storage.removeRange(keyPrefix);
|
|
3137
|
-
}
|
|
3138
|
-
async close() {
|
|
3139
|
-
if (this._storage instanceof AutomergeStorageAdapter) {
|
|
3140
|
-
return this._storage.close();
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
};
|
|
3144
|
-
|
|
3145
|
-
// packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts
|
|
3146
|
-
function _ts_decorate9(decorators, target, key, desc) {
|
|
3147
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3148
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3149
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
3150
|
-
else
|
|
3151
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
3152
|
-
if (d = decorators[i])
|
|
3153
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3154
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3155
|
-
}
|
|
3156
|
-
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/automerge/automerge-host.ts";
|
|
3157
|
-
var AutomergeHost = class {
|
|
3158
|
-
constructor({ directory, metadata }) {
|
|
3159
|
-
this._ctx = new Context7();
|
|
3160
|
-
/**
|
|
3161
|
-
* spaceKey -> deviceKey[]
|
|
3162
|
-
*/
|
|
3163
|
-
this._authorizedDevices = new ComplexMap7(PublicKey8.hash);
|
|
3164
|
-
this._updatingMetadata = /* @__PURE__ */ new Map();
|
|
3165
|
-
this._requestedDocs = /* @__PURE__ */ new Set();
|
|
3166
|
-
this._metadata = metadata;
|
|
3167
|
-
this._meshNetwork = new MeshNetworkAdapter();
|
|
3168
|
-
this._clientNetwork = new LocalHostNetworkAdapter();
|
|
3169
|
-
this._storage = new AutomergeStorageWrapper({
|
|
3170
|
-
storage: (
|
|
3171
|
-
// TODO(mykola): Delete specific handling of IDB storage.
|
|
3172
|
-
directory.type === StorageType.IDB ? new IndexedDBStorageAdapter(directory.path, "data") : new AutomergeStorageAdapter(directory)
|
|
3173
|
-
),
|
|
3174
|
-
callbacks: {
|
|
3175
|
-
beforeSave: (params) => this._beforeSave(params)
|
|
3176
|
-
}
|
|
3177
|
-
});
|
|
3178
|
-
this._peerId = `host-${PublicKey8.random().toHex()}`;
|
|
3179
|
-
this._repo = new Repo({
|
|
3180
|
-
peerId: this._peerId,
|
|
3181
|
-
network: [
|
|
3182
|
-
this._clientNetwork,
|
|
3183
|
-
this._meshNetwork
|
|
3184
|
-
],
|
|
3185
|
-
storage: this._storage,
|
|
3186
|
-
// TODO(dmaretskyi): Share based on HALO permissions and space affinity.
|
|
3187
|
-
// Hosts, running in the worker, don't share documents unless requested by other peers.
|
|
3188
|
-
sharePolicy: async (peerId, documentId) => {
|
|
3189
|
-
if (peerId.startsWith("client-")) {
|
|
3190
|
-
return false;
|
|
3191
|
-
}
|
|
3192
|
-
if (!documentId) {
|
|
3193
|
-
return false;
|
|
3194
|
-
}
|
|
3195
|
-
const doc = this._repo.handles[documentId]?.docSync();
|
|
3196
|
-
if (!doc) {
|
|
3197
|
-
const isRequested = this._requestedDocs.has(`automerge:${documentId}`);
|
|
3198
|
-
log15("doc share policy check", {
|
|
3199
|
-
peerId,
|
|
3200
|
-
documentId,
|
|
3201
|
-
isRequested
|
|
3202
|
-
}, {
|
|
3203
|
-
F: __dxlog_file16,
|
|
3204
|
-
L: 96,
|
|
3205
|
-
S: this,
|
|
3206
|
-
C: (f, a) => f(...a)
|
|
3207
|
-
});
|
|
3208
|
-
return isRequested;
|
|
3209
|
-
}
|
|
3210
|
-
try {
|
|
3211
|
-
const spaceKey = getSpaceKeyFromDoc(doc);
|
|
3212
|
-
if (!spaceKey) {
|
|
3213
|
-
log15("space key not found for share policy check", {
|
|
3214
|
-
peerId,
|
|
3215
|
-
documentId
|
|
3216
|
-
}, {
|
|
3217
|
-
F: __dxlog_file16,
|
|
3218
|
-
L: 103,
|
|
3219
|
-
S: this,
|
|
3220
|
-
C: (f, a) => f(...a)
|
|
3221
|
-
});
|
|
3222
|
-
return false;
|
|
3223
|
-
}
|
|
3224
|
-
const authorizedDevices = this._authorizedDevices.get(PublicKey8.from(spaceKey));
|
|
3225
|
-
const deviceKeyHex = this.repo.peerMetadataByPeerId[peerId]?.dxos_deviceKey;
|
|
3226
|
-
if (!deviceKeyHex) {
|
|
3227
|
-
log15("device key not found for share policy check", {
|
|
3228
|
-
peerId,
|
|
3229
|
-
documentId
|
|
3230
|
-
}, {
|
|
3231
|
-
F: __dxlog_file16,
|
|
3232
|
-
L: 112,
|
|
3233
|
-
S: this,
|
|
3234
|
-
C: (f, a) => f(...a)
|
|
3235
|
-
});
|
|
3236
|
-
return false;
|
|
3237
|
-
}
|
|
3238
|
-
const deviceKey = PublicKey8.from(deviceKeyHex);
|
|
3239
|
-
const isAuthorized = authorizedDevices?.has(deviceKey) ?? false;
|
|
3240
|
-
log15("share policy check", {
|
|
3241
|
-
localPeer: this._peerId,
|
|
3242
|
-
remotePeer: peerId,
|
|
3243
|
-
documentId,
|
|
3244
|
-
deviceKey,
|
|
3245
|
-
spaceKey,
|
|
3246
|
-
isAuthorized
|
|
3247
|
-
}, {
|
|
3248
|
-
F: __dxlog_file16,
|
|
3249
|
-
L: 118,
|
|
3250
|
-
S: this,
|
|
3251
|
-
C: (f, a) => f(...a)
|
|
3252
|
-
});
|
|
3253
|
-
return isAuthorized;
|
|
3254
|
-
} catch (err) {
|
|
3255
|
-
log15.catch(err, void 0, {
|
|
3256
|
-
F: __dxlog_file16,
|
|
3257
|
-
L: 128,
|
|
3258
|
-
S: this,
|
|
3259
|
-
C: (f, a) => f(...a)
|
|
3260
|
-
});
|
|
3261
|
-
return false;
|
|
3262
|
-
}
|
|
3263
|
-
}
|
|
3264
|
-
});
|
|
3265
|
-
this._clientNetwork.ready();
|
|
3266
|
-
this._meshNetwork.ready();
|
|
3267
|
-
{
|
|
3268
|
-
const listener = ({ handle }) => this._onDocument(handle);
|
|
3269
|
-
this._repo.on("document", listener);
|
|
3270
|
-
this._ctx.onDispose(() => {
|
|
3271
|
-
this._repo.off("document", listener);
|
|
3272
|
-
});
|
|
3273
|
-
}
|
|
3274
|
-
}
|
|
3275
|
-
get repo() {
|
|
3276
|
-
return this._repo;
|
|
3277
|
-
}
|
|
3278
|
-
async _beforeSave(path) {
|
|
3279
|
-
const id = path[0];
|
|
3280
|
-
if (this._updatingMetadata.has(id)) {
|
|
3281
|
-
return this._updatingMetadata.get(id);
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
_onDocument(handle) {
|
|
3285
|
-
const listener = (event) => this._onUpdate(event);
|
|
3286
|
-
handle.on("change", listener);
|
|
3287
|
-
this._ctx.onDispose(() => {
|
|
3288
|
-
handle.off("change", listener);
|
|
3289
|
-
});
|
|
3290
|
-
}
|
|
3291
|
-
_onUpdate(event) {
|
|
3292
|
-
if (this._metadata == null) {
|
|
3293
|
-
return;
|
|
3294
|
-
}
|
|
3295
|
-
const objectIds = getInlineChanges(event);
|
|
3296
|
-
if (objectIds.length === 0) {
|
|
3297
|
-
return;
|
|
3298
|
-
}
|
|
3299
|
-
const heads = getHeads(event.doc);
|
|
3300
|
-
const lastAvailableHash = heads.at(-1);
|
|
3301
|
-
if (!lastAvailableHash) {
|
|
3302
|
-
return;
|
|
3303
|
-
}
|
|
3304
|
-
const encodedIds = objectIds.map((objectId) => idCodec.encode({
|
|
3305
|
-
documentId: event.handle.documentId,
|
|
3306
|
-
objectId
|
|
3307
|
-
}));
|
|
3308
|
-
const idToLastHash = new Map(encodedIds.map((id) => [
|
|
3309
|
-
id,
|
|
3310
|
-
lastAvailableHash
|
|
3311
|
-
]));
|
|
3312
|
-
const markingDirtyPromise = this._metadata.markDirty(idToLastHash).then(() => {
|
|
3313
|
-
this._updatingMetadata.delete(event.handle.documentId);
|
|
3314
|
-
}).catch((err) => {
|
|
3315
|
-
this._ctx.disposed && log15.catch(err, void 0, {
|
|
3316
|
-
F: __dxlog_file16,
|
|
3317
|
-
L: 188,
|
|
3318
|
-
S: this,
|
|
3319
|
-
C: (f, a) => f(...a)
|
|
3320
|
-
});
|
|
3321
|
-
});
|
|
3322
|
-
this._updatingMetadata.set(event.handle.documentId, markingDirtyPromise);
|
|
3323
|
-
}
|
|
3324
|
-
_automergeDocs() {
|
|
3325
|
-
return mapValues(this._repo.handles, (handle) => ({
|
|
3326
|
-
state: handle.state,
|
|
3327
|
-
hasDoc: !!handle.docSync(),
|
|
3328
|
-
heads: handle.docSync() ? automerge.getHeads(handle.docSync()) : null,
|
|
3329
|
-
data: handle.docSync()?.doc && mapValues(handle.docSync()?.doc, (value, key) => {
|
|
3330
|
-
try {
|
|
3331
|
-
switch (key) {
|
|
3332
|
-
case "access":
|
|
3333
|
-
case "links":
|
|
3334
|
-
return value;
|
|
3335
|
-
case "objects":
|
|
3336
|
-
return Object.keys(value);
|
|
3337
|
-
default:
|
|
3338
|
-
return `${value}`;
|
|
3339
|
-
}
|
|
3340
|
-
} catch (err) {
|
|
3341
|
-
return `${err}`;
|
|
3342
|
-
}
|
|
3343
|
-
})
|
|
3344
|
-
}));
|
|
3345
|
-
}
|
|
3346
|
-
_automergePeers() {
|
|
3347
|
-
return this._repo.peers;
|
|
3348
|
-
}
|
|
3349
|
-
async close() {
|
|
3350
|
-
await this._storage.close();
|
|
3351
|
-
await this._clientNetwork.close();
|
|
3352
|
-
await this._ctx.dispose();
|
|
3353
|
-
}
|
|
3354
|
-
//
|
|
3355
|
-
// Methods for client-services.
|
|
3356
|
-
//
|
|
3357
|
-
syncRepo(request) {
|
|
3358
|
-
return this._clientNetwork.syncRepo(request);
|
|
3359
|
-
}
|
|
3360
|
-
sendSyncMessage(request) {
|
|
3361
|
-
return this._clientNetwork.sendSyncMessage(request);
|
|
3362
|
-
}
|
|
3363
|
-
async getHostInfo() {
|
|
3364
|
-
return this._clientNetwork.getHostInfo();
|
|
3365
|
-
}
|
|
3366
|
-
//
|
|
3367
|
-
// Mesh replication.
|
|
3368
|
-
//
|
|
3369
|
-
createExtension() {
|
|
3370
|
-
return this._meshNetwork.createExtension();
|
|
3371
|
-
}
|
|
3372
|
-
authorizeDevice(spaceKey, deviceKey) {
|
|
3373
|
-
log15("authorizeDevice", {
|
|
3374
|
-
spaceKey,
|
|
3375
|
-
deviceKey
|
|
3376
|
-
}, {
|
|
3377
|
-
F: __dxlog_file16,
|
|
3378
|
-
L: 255,
|
|
3379
|
-
S: this,
|
|
3380
|
-
C: (f, a) => f(...a)
|
|
3381
|
-
});
|
|
3382
|
-
defaultMap(this._authorizedDevices, spaceKey, () => new ComplexSet(PublicKey8.hash)).add(deviceKey);
|
|
3383
|
-
}
|
|
3384
|
-
};
|
|
3385
|
-
_ts_decorate9([
|
|
3386
|
-
trace6.info()
|
|
3387
|
-
], AutomergeHost.prototype, "_peerId", void 0);
|
|
3388
|
-
_ts_decorate9([
|
|
3389
|
-
trace6.info({
|
|
3390
|
-
depth: null
|
|
3391
|
-
})
|
|
3392
|
-
], AutomergeHost.prototype, "_automergeDocs", null);
|
|
3393
|
-
_ts_decorate9([
|
|
3394
|
-
trace6.info({
|
|
3395
|
-
depth: null
|
|
3396
|
-
})
|
|
3397
|
-
], AutomergeHost.prototype, "_automergePeers", null);
|
|
3398
|
-
AutomergeHost = _ts_decorate9([
|
|
3399
|
-
trace6.resource()
|
|
3400
|
-
], AutomergeHost);
|
|
3401
|
-
var getInlineChanges = (event) => {
|
|
3402
|
-
const inlineChangedObjectIds = /* @__PURE__ */ new Set();
|
|
3403
|
-
for (const { path } of event.patches) {
|
|
3404
|
-
if (path.length < 2) {
|
|
3405
|
-
continue;
|
|
3406
|
-
}
|
|
3407
|
-
switch (path[0]) {
|
|
3408
|
-
case "objects":
|
|
3409
|
-
if (path.length >= 2) {
|
|
3410
|
-
inlineChangedObjectIds.add(path[1]);
|
|
3411
|
-
}
|
|
3412
|
-
break;
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
|
-
return [
|
|
3416
|
-
...inlineChangedObjectIds
|
|
3417
|
-
];
|
|
3418
|
-
};
|
|
3419
|
-
var getSpaceKeyFromDoc = (doc) => {
|
|
3420
|
-
const rawSpaceKey = doc.access?.spaceKey ?? doc.experimental_spaceKey;
|
|
3421
|
-
if (rawSpaceKey == null) {
|
|
3422
|
-
return null;
|
|
3423
|
-
}
|
|
3424
|
-
return String(rawSpaceKey);
|
|
3425
|
-
};
|
|
3426
|
-
|
|
3427
1918
|
export {
|
|
3428
1919
|
codec,
|
|
3429
1920
|
valueEncoding,
|
|
3430
1921
|
createMappedFeedWriter,
|
|
3431
|
-
DataServiceHost,
|
|
3432
|
-
DatabaseHost,
|
|
3433
1922
|
SnapshotManager,
|
|
3434
1923
|
SnapshotStore,
|
|
3435
|
-
DataServiceSubscriptions,
|
|
3436
1924
|
DataServiceImpl,
|
|
3437
1925
|
MetadataStore,
|
|
3438
1926
|
mapTimeframeToFeedIndexes,
|
|
@@ -3441,18 +1929,12 @@ export {
|
|
|
3441
1929
|
TimeframeClock,
|
|
3442
1930
|
Pipeline,
|
|
3443
1931
|
AuthExtension,
|
|
3444
|
-
DataPipeline,
|
|
3445
1932
|
Space,
|
|
3446
1933
|
MOCK_AUTH_PROVIDER,
|
|
3447
1934
|
MOCK_AUTH_VERIFIER,
|
|
3448
1935
|
SpaceProtocol,
|
|
3449
1936
|
AuthStatus,
|
|
3450
1937
|
SpaceProtocolSession,
|
|
3451
|
-
SpaceManager
|
|
3452
|
-
AutomergeStorageAdapter,
|
|
3453
|
-
LocalHostNetworkAdapter,
|
|
3454
|
-
MeshNetworkAdapter,
|
|
3455
|
-
AutomergeHost,
|
|
3456
|
-
getSpaceKeyFromDoc
|
|
1938
|
+
SpaceManager
|
|
3457
1939
|
};
|
|
3458
|
-
//# sourceMappingURL=chunk-
|
|
1940
|
+
//# sourceMappingURL=chunk-RTEEJ723.mjs.map
|