@dxos/echo-pipeline 0.1.57-main.e87098f → 0.1.57
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-GELWTWOW.mjs → chunk-V6J3XM4Y.mjs} +371 -145
- package/dist/lib/browser/chunk-V6J3XM4Y.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +5 -4
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +385 -159
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +397 -170
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/db-host/data-service-host.d.ts +3 -1
- package/dist/types/src/db-host/data-service-host.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts +2 -1
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-host.d.ts +4 -2
- package/dist/types/src/db-host/database-host.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts +12 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts +1 -0
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/space/auth.d.ts +1 -0
- package/dist/types/src/space/auth.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts +4 -0
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/data-pipeline.d.ts +1 -0
- package/dist/types/src/space/data-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts +3 -2
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/database-test-rig.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/package.json +32 -32
- package/src/db-host/data-service-host.ts +5 -0
- package/src/db-host/data-service.ts +8 -0
- package/src/db-host/database-host.ts +7 -3
- package/src/metadata/metadata-store.ts +125 -28
- package/src/pipeline/pipeline.ts +11 -0
- package/src/space/auth.ts +5 -0
- package/src/space/control-pipeline.ts +63 -10
- package/src/space/data-pipeline.ts +29 -4
- package/src/space/space-protocol.ts +7 -2
- package/src/space/space.ts +4 -2
- package/src/testing/database-test-rig.ts +26 -21
- package/src/testing/test-agent-builder.ts +2 -2
- package/src/testing/util.ts +3 -1
- package/src/tests/database-unit.test.ts +26 -1
- package/src/tests/database.test.ts +3 -1
- package/dist/lib/browser/chunk-GELWTWOW.mjs.map +0 -7
|
@@ -45,7 +45,7 @@ module.exports = __toCommonJS(testing_exports);
|
|
|
45
45
|
var import_context7 = require("@dxos/context");
|
|
46
46
|
var import_credentials5 = require("@dxos/credentials");
|
|
47
47
|
var import_document_model = require("@dxos/document-model");
|
|
48
|
-
var
|
|
48
|
+
var import_keys8 = require("@dxos/keys");
|
|
49
49
|
var import_messaging = require("@dxos/messaging");
|
|
50
50
|
var import_model_factory = require("@dxos/model-factory");
|
|
51
51
|
var import_network_manager2 = require("@dxos/network-manager");
|
|
@@ -63,11 +63,12 @@ var import_invariant = require("@dxos/invariant");
|
|
|
63
63
|
var import_log = require("@dxos/log");
|
|
64
64
|
var import_service = require("@dxos/protocols/proto/dxos/echo/service");
|
|
65
65
|
var import_util = require("@dxos/util");
|
|
66
|
-
var __dxlog_file = "/
|
|
66
|
+
var __dxlog_file = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
|
|
67
67
|
var DataServiceHost = class {
|
|
68
|
-
constructor(_itemManager, _itemDemuxer, _writeStream) {
|
|
68
|
+
constructor(_itemManager, _itemDemuxer, _flush, _writeStream) {
|
|
69
69
|
this._itemManager = _itemManager;
|
|
70
70
|
this._itemDemuxer = _itemDemuxer;
|
|
71
|
+
this._flush = _flush;
|
|
71
72
|
this._writeStream = _writeStream;
|
|
72
73
|
this._ctx = new import_context.Context();
|
|
73
74
|
this._clientTagMap = new import_util.ComplexMap(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
|
|
@@ -101,7 +102,7 @@ var DataServiceHost = class {
|
|
|
101
102
|
const { batch, meta } = message;
|
|
102
103
|
(0, import_invariant.invariant)(!meta.clientTag, "Unexpected client tag in mutation message", {
|
|
103
104
|
F: __dxlog_file,
|
|
104
|
-
L:
|
|
105
|
+
L: 69,
|
|
105
106
|
S: this,
|
|
106
107
|
A: [
|
|
107
108
|
"!(meta as any).clientTag",
|
|
@@ -113,7 +114,7 @@ var DataServiceHost = class {
|
|
|
113
114
|
meta
|
|
114
115
|
}, {
|
|
115
116
|
F: __dxlog_file,
|
|
116
|
-
L:
|
|
117
|
+
L: 70,
|
|
117
118
|
S: this,
|
|
118
119
|
C: (f, a) => f(...a)
|
|
119
120
|
});
|
|
@@ -141,7 +142,7 @@ var DataServiceHost = class {
|
|
|
141
142
|
async write(request) {
|
|
142
143
|
(0, import_invariant.invariant)(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
|
|
143
144
|
F: __dxlog_file,
|
|
144
|
-
L:
|
|
145
|
+
L: 96,
|
|
145
146
|
S: this,
|
|
146
147
|
A: [
|
|
147
148
|
"!this._ctx.disposed",
|
|
@@ -150,7 +151,7 @@ var DataServiceHost = class {
|
|
|
150
151
|
});
|
|
151
152
|
(0, import_invariant.invariant)(this._writeStream, "Cannot write mutations in readonly mode", {
|
|
152
153
|
F: __dxlog_file,
|
|
153
|
-
L:
|
|
154
|
+
L: 97,
|
|
154
155
|
S: this,
|
|
155
156
|
A: [
|
|
156
157
|
"this._writeStream",
|
|
@@ -162,7 +163,7 @@ var DataServiceHost = class {
|
|
|
162
163
|
objectCount: request.batch.objects?.length ?? 0
|
|
163
164
|
}, {
|
|
164
165
|
F: __dxlog_file,
|
|
165
|
-
L:
|
|
166
|
+
L: 99,
|
|
166
167
|
S: this,
|
|
167
168
|
C: (f, a) => f(...a)
|
|
168
169
|
});
|
|
@@ -176,7 +177,7 @@ var DataServiceHost = class {
|
|
|
176
177
|
seq: receipt2.seq
|
|
177
178
|
}, {
|
|
178
179
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
180
|
+
L: 108,
|
|
180
181
|
S: this,
|
|
181
182
|
C: (f, a) => f(...a)
|
|
182
183
|
});
|
|
@@ -189,6 +190,9 @@ var DataServiceHost = class {
|
|
|
189
190
|
});
|
|
190
191
|
return receipt;
|
|
191
192
|
}
|
|
193
|
+
async flush() {
|
|
194
|
+
await this._flush();
|
|
195
|
+
}
|
|
192
196
|
};
|
|
193
197
|
var createDataMessage = (batch) => ({
|
|
194
198
|
batch: {
|
|
@@ -206,8 +210,9 @@ var createDataMessage = (batch) => ({
|
|
|
206
210
|
// packages/core/echo/echo-pipeline/src/db-host/database-host.ts
|
|
207
211
|
var import_echo_db2 = require("@dxos/echo-db");
|
|
208
212
|
var DatabaseHost = class {
|
|
209
|
-
constructor(_outboundStream) {
|
|
213
|
+
constructor(_outboundStream, _flush) {
|
|
210
214
|
this._outboundStream = _outboundStream;
|
|
215
|
+
this._flush = _flush;
|
|
211
216
|
}
|
|
212
217
|
get isReadOnly() {
|
|
213
218
|
return !!this._outboundStream;
|
|
@@ -230,7 +235,7 @@ var DatabaseHost = class {
|
|
|
230
235
|
return this._itemDemuxer.createSnapshot();
|
|
231
236
|
}
|
|
232
237
|
createDataServiceHost() {
|
|
233
|
-
return new DataServiceHost(this._itemManager, this._itemDemuxer, this._outboundStream ?? void 0);
|
|
238
|
+
return new DataServiceHost(this._itemManager, this._itemDemuxer, this._flush, this._outboundStream ?? void 0);
|
|
234
239
|
}
|
|
235
240
|
};
|
|
236
241
|
|
|
@@ -337,7 +342,7 @@ var import_invariant2 = require("@dxos/invariant");
|
|
|
337
342
|
var import_keys2 = require("@dxos/keys");
|
|
338
343
|
var import_log2 = require("@dxos/log");
|
|
339
344
|
var import_util2 = require("@dxos/util");
|
|
340
|
-
var __dxlog_file2 = "/
|
|
345
|
+
var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/db-host/data-service.ts";
|
|
341
346
|
var DataServiceSubscriptions = class {
|
|
342
347
|
constructor() {
|
|
343
348
|
this._spaces = new import_util2.ComplexMap(import_keys2.PublicKey.hash);
|
|
@@ -350,13 +355,13 @@ var DataServiceSubscriptions = class {
|
|
|
350
355
|
spaceKey
|
|
351
356
|
}, {
|
|
352
357
|
F: __dxlog_file2,
|
|
353
|
-
L:
|
|
358
|
+
L: 31,
|
|
354
359
|
S: this,
|
|
355
360
|
C: (f, a) => f(...a)
|
|
356
361
|
});
|
|
357
362
|
(0, import_invariant2.invariant)(!this._spaces.has(spaceKey), void 0, {
|
|
358
363
|
F: __dxlog_file2,
|
|
359
|
-
L:
|
|
364
|
+
L: 32,
|
|
360
365
|
S: this,
|
|
361
366
|
A: [
|
|
362
367
|
"!this._spaces.has(spaceKey)",
|
|
@@ -371,7 +376,7 @@ var DataServiceSubscriptions = class {
|
|
|
371
376
|
spaceKey
|
|
372
377
|
}, {
|
|
373
378
|
F: __dxlog_file2,
|
|
374
|
-
L:
|
|
379
|
+
L: 38,
|
|
375
380
|
S: this,
|
|
376
381
|
C: (f, a) => f(...a)
|
|
377
382
|
});
|
|
@@ -390,7 +395,7 @@ var DataServiceImpl = class {
|
|
|
390
395
|
subscribe(request) {
|
|
391
396
|
(0, import_invariant2.invariant)(request.spaceKey, void 0, {
|
|
392
397
|
F: __dxlog_file2,
|
|
393
|
-
L:
|
|
398
|
+
L: 57,
|
|
394
399
|
S: this,
|
|
395
400
|
A: [
|
|
396
401
|
"request.spaceKey",
|
|
@@ -403,7 +408,7 @@ var DataServiceImpl = class {
|
|
|
403
408
|
write(request) {
|
|
404
409
|
(0, import_invariant2.invariant)(request.spaceKey, void 0, {
|
|
405
410
|
F: __dxlog_file2,
|
|
406
|
-
L:
|
|
411
|
+
L: 64,
|
|
407
412
|
S: this,
|
|
408
413
|
A: [
|
|
409
414
|
"request.spaceKey",
|
|
@@ -412,7 +417,7 @@ var DataServiceImpl = class {
|
|
|
412
417
|
});
|
|
413
418
|
(0, import_invariant2.invariant)(request.batch, void 0, {
|
|
414
419
|
F: __dxlog_file2,
|
|
415
|
-
L:
|
|
420
|
+
L: 65,
|
|
416
421
|
S: this,
|
|
417
422
|
A: [
|
|
418
423
|
"request.batch",
|
|
@@ -422,6 +427,19 @@ var DataServiceImpl = class {
|
|
|
422
427
|
const host = this._subscriptions.getDataService(request.spaceKey) ?? (0, import_debug.raise)(new Error(`space not found: ${request.spaceKey}`));
|
|
423
428
|
return host.write(request);
|
|
424
429
|
}
|
|
430
|
+
flush(request) {
|
|
431
|
+
(0, import_invariant2.invariant)(request.spaceKey, void 0, {
|
|
432
|
+
F: __dxlog_file2,
|
|
433
|
+
L: 72,
|
|
434
|
+
S: this,
|
|
435
|
+
A: [
|
|
436
|
+
"request.spaceKey",
|
|
437
|
+
""
|
|
438
|
+
]
|
|
439
|
+
});
|
|
440
|
+
const host = this._subscriptions.getDataService(request.spaceKey) ?? (0, import_debug.raise)(new Error(`space not found: ${request.spaceKey}`));
|
|
441
|
+
return host.flush();
|
|
442
|
+
}
|
|
425
443
|
};
|
|
426
444
|
|
|
427
445
|
// packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
|
|
@@ -429,6 +447,7 @@ var import_crc_32 = __toESM(require("crc-32"));
|
|
|
429
447
|
var import_async2 = require("@dxos/async");
|
|
430
448
|
var import_errors = require("@dxos/errors");
|
|
431
449
|
var import_invariant3 = require("@dxos/invariant");
|
|
450
|
+
var import_keys3 = require("@dxos/keys");
|
|
432
451
|
var import_log3 = require("@dxos/log");
|
|
433
452
|
var import_protocols3 = require("@dxos/protocols");
|
|
434
453
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
@@ -443,19 +462,23 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
443
462
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
444
463
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
445
464
|
}
|
|
446
|
-
var __dxlog_file3 = "/
|
|
465
|
+
var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts";
|
|
447
466
|
var emptyEchoMetadata = () => ({
|
|
448
467
|
version: import_protocols3.STORAGE_VERSION,
|
|
449
468
|
spaces: [],
|
|
450
469
|
created: /* @__PURE__ */ new Date(),
|
|
451
470
|
updated: /* @__PURE__ */ new Date()
|
|
452
471
|
});
|
|
472
|
+
var emptyLargeSpaceMetadata = () => ({});
|
|
453
473
|
var EchoMetadata = import_protocols3.schema.getCodecForType("dxos.echo.metadata.EchoMetadata");
|
|
474
|
+
var LargeSpaceMetadata = import_protocols3.schema.getCodecForType("dxos.echo.metadata.LargeSpaceMetadata");
|
|
454
475
|
var MetadataStore = class {
|
|
455
476
|
// prettier-ignore
|
|
456
477
|
constructor(_directory) {
|
|
457
478
|
this._directory = _directory;
|
|
458
479
|
this._metadata = emptyEchoMetadata();
|
|
480
|
+
this._spaceLargeMetadata = new import_util3.ComplexMap(import_keys3.PublicKey.hash);
|
|
481
|
+
this._metadataFile = void 0;
|
|
459
482
|
this.update = new import_async2.Event();
|
|
460
483
|
}
|
|
461
484
|
get metadata() {
|
|
@@ -471,11 +494,7 @@ var MetadataStore = class {
|
|
|
471
494
|
get spaces() {
|
|
472
495
|
return this._metadata.spaces ?? [];
|
|
473
496
|
}
|
|
474
|
-
|
|
475
|
-
* Loads metadata from persistent storage.
|
|
476
|
-
*/
|
|
477
|
-
async load() {
|
|
478
|
-
const file = this._directory.getOrCreateFile("EchoMetadata");
|
|
497
|
+
async _readFile(file, codec2) {
|
|
479
498
|
try {
|
|
480
499
|
const { size: fileLength } = await file.stat();
|
|
481
500
|
if (fileLength < 8) {
|
|
@@ -485,10 +504,11 @@ var MetadataStore = class {
|
|
|
485
504
|
const checksum = fromBytesInt32(await file.read(4, 4));
|
|
486
505
|
(0, import_log3.log)("loaded", {
|
|
487
506
|
size: dataSize,
|
|
488
|
-
checksum
|
|
507
|
+
checksum,
|
|
508
|
+
name: file.filename
|
|
489
509
|
}, {
|
|
490
510
|
F: __dxlog_file3,
|
|
491
|
-
L:
|
|
511
|
+
L: 82,
|
|
492
512
|
S: this,
|
|
493
513
|
C: (f, a) => f(...a)
|
|
494
514
|
});
|
|
@@ -503,7 +523,48 @@ var MetadataStore = class {
|
|
|
503
523
|
if (calculatedChecksum !== checksum) {
|
|
504
524
|
throw new import_errors.DataCorruptionError("Metadata checksum is invalid.");
|
|
505
525
|
}
|
|
506
|
-
|
|
526
|
+
return codec2.decode(data);
|
|
527
|
+
} finally {
|
|
528
|
+
await file.close();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
async _writeFile(file, codec2, data) {
|
|
532
|
+
const encoded = (0, import_util3.arrayToBuffer)(codec2.encode(data));
|
|
533
|
+
const checksum = import_crc_32.default.buf(encoded);
|
|
534
|
+
const result = Buffer.alloc(8 + encoded.length);
|
|
535
|
+
result.writeInt32LE(encoded.length, 0);
|
|
536
|
+
result.writeInt32LE(checksum, 4);
|
|
537
|
+
encoded.copy(result, 8);
|
|
538
|
+
await file.write(0, result);
|
|
539
|
+
(0, import_log3.log)("saved", {
|
|
540
|
+
size: encoded.length,
|
|
541
|
+
checksum
|
|
542
|
+
}, {
|
|
543
|
+
F: __dxlog_file3,
|
|
544
|
+
L: 114,
|
|
545
|
+
S: this,
|
|
546
|
+
C: (f, a) => f(...a)
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
async close() {
|
|
550
|
+
await this.flush();
|
|
551
|
+
await this._metadataFile?.close();
|
|
552
|
+
this._metadataFile = void 0;
|
|
553
|
+
this._metadata = emptyEchoMetadata();
|
|
554
|
+
this._spaceLargeMetadata.clear();
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Loads metadata from persistent storage.
|
|
558
|
+
*/
|
|
559
|
+
async load() {
|
|
560
|
+
if (!this._metadataFile || this._metadataFile.closed) {
|
|
561
|
+
this._metadataFile = this._directory.getOrCreateFile("EchoMetadata");
|
|
562
|
+
}
|
|
563
|
+
try {
|
|
564
|
+
const metadata = await this._readFile(this._metadataFile, EchoMetadata);
|
|
565
|
+
if (metadata) {
|
|
566
|
+
this._metadata = metadata;
|
|
567
|
+
}
|
|
507
568
|
this._metadata.spaces?.forEach((space) => {
|
|
508
569
|
space.state ??= import_services.SpaceState.ACTIVE;
|
|
509
570
|
});
|
|
@@ -512,14 +573,29 @@ var MetadataStore = class {
|
|
|
512
573
|
err
|
|
513
574
|
}, {
|
|
514
575
|
F: __dxlog_file3,
|
|
515
|
-
L:
|
|
576
|
+
L: 145,
|
|
516
577
|
S: this,
|
|
517
578
|
C: (f, a) => f(...a)
|
|
518
579
|
});
|
|
519
580
|
this._metadata = emptyEchoMetadata();
|
|
520
|
-
} finally {
|
|
521
|
-
await file.close();
|
|
522
581
|
}
|
|
582
|
+
await (0, import_util3.forEachAsync)([
|
|
583
|
+
this._metadata.identity?.haloSpace.key,
|
|
584
|
+
...this._metadata.spaces?.map((space) => space.key) ?? []
|
|
585
|
+
].filter(import_util3.isNotNullOrUndefined), async (key) => {
|
|
586
|
+
try {
|
|
587
|
+
await this._loadSpaceLargeMetadata(key);
|
|
588
|
+
} catch (err) {
|
|
589
|
+
import_log3.log.error("failed to load space large metadata", {
|
|
590
|
+
err
|
|
591
|
+
}, {
|
|
592
|
+
F: __dxlog_file3,
|
|
593
|
+
L: 157,
|
|
594
|
+
S: this,
|
|
595
|
+
C: (f, a) => f(...a)
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
});
|
|
523
599
|
}
|
|
524
600
|
async _save() {
|
|
525
601
|
const data = {
|
|
@@ -530,27 +606,34 @@ var MetadataStore = class {
|
|
|
530
606
|
};
|
|
531
607
|
this.update.emit(data);
|
|
532
608
|
const file = this._directory.getOrCreateFile("EchoMetadata");
|
|
609
|
+
await this._writeFile(file, EchoMetadata, data);
|
|
610
|
+
}
|
|
611
|
+
async _loadSpaceLargeMetadata(key) {
|
|
612
|
+
const file = this._directory.getOrCreateFile(`space_${key.toHex()}_large`);
|
|
533
613
|
try {
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
(0, import_log3.log)("saved", {
|
|
542
|
-
size: encoded.length,
|
|
543
|
-
checksum
|
|
614
|
+
const metadata = await this._readFile(file, LargeSpaceMetadata);
|
|
615
|
+
if (metadata) {
|
|
616
|
+
this._spaceLargeMetadata.set(key, metadata);
|
|
617
|
+
}
|
|
618
|
+
} catch (err) {
|
|
619
|
+
import_log3.log.error("failed to load space large metadata", {
|
|
620
|
+
err
|
|
544
621
|
}, {
|
|
545
622
|
F: __dxlog_file3,
|
|
546
|
-
L:
|
|
623
|
+
L: 186,
|
|
547
624
|
S: this,
|
|
548
625
|
C: (f, a) => f(...a)
|
|
549
626
|
});
|
|
550
|
-
} finally {
|
|
551
|
-
await file.close();
|
|
552
627
|
}
|
|
553
628
|
}
|
|
629
|
+
async _saveSpaceLargeMetadata(key) {
|
|
630
|
+
const data = this._getLargeSpaceMetadata(key);
|
|
631
|
+
const file = this._directory.getOrCreateFile(`space_${key.toHex()}_large`);
|
|
632
|
+
await this._writeFile(file, LargeSpaceMetadata, data);
|
|
633
|
+
}
|
|
634
|
+
async flush() {
|
|
635
|
+
await this._directory.flush();
|
|
636
|
+
}
|
|
554
637
|
_getSpace(spaceKey) {
|
|
555
638
|
if (this._metadata.identity?.haloSpace.key.equals(spaceKey)) {
|
|
556
639
|
return this._metadata.identity.haloSpace;
|
|
@@ -558,7 +641,7 @@ var MetadataStore = class {
|
|
|
558
641
|
const space = this.spaces.find((space2) => space2.key === spaceKey);
|
|
559
642
|
(0, import_invariant3.invariant)(space, "Space not found", {
|
|
560
643
|
F: __dxlog_file3,
|
|
561
|
-
L:
|
|
644
|
+
L: 208,
|
|
562
645
|
S: this,
|
|
563
646
|
A: [
|
|
564
647
|
"space",
|
|
@@ -567,13 +650,22 @@ var MetadataStore = class {
|
|
|
567
650
|
});
|
|
568
651
|
return space;
|
|
569
652
|
}
|
|
653
|
+
_getLargeSpaceMetadata(key) {
|
|
654
|
+
let entry = this._spaceLargeMetadata.get(key);
|
|
655
|
+
if (entry) {
|
|
656
|
+
return entry;
|
|
657
|
+
}
|
|
658
|
+
entry = emptyLargeSpaceMetadata();
|
|
659
|
+
this._spaceLargeMetadata.set(key, entry);
|
|
660
|
+
return entry;
|
|
661
|
+
}
|
|
570
662
|
/**
|
|
571
663
|
* Clears storage - doesn't work for now.
|
|
572
664
|
*/
|
|
573
665
|
async clear() {
|
|
574
666
|
(0, import_log3.log)("clearing all metadata", void 0, {
|
|
575
667
|
F: __dxlog_file3,
|
|
576
|
-
L:
|
|
668
|
+
L: 227,
|
|
577
669
|
S: this,
|
|
578
670
|
C: (f, a) => f(...a)
|
|
579
671
|
});
|
|
@@ -586,7 +678,7 @@ var MetadataStore = class {
|
|
|
586
678
|
async setIdentityRecord(record) {
|
|
587
679
|
(0, import_invariant3.invariant)(!this._metadata.identity, "Cannot overwrite existing identity in metadata", {
|
|
588
680
|
F: __dxlog_file3,
|
|
589
|
-
L:
|
|
681
|
+
L: 237,
|
|
590
682
|
S: this,
|
|
591
683
|
A: [
|
|
592
684
|
"!this._metadata.identity",
|
|
@@ -595,11 +687,12 @@ var MetadataStore = class {
|
|
|
595
687
|
});
|
|
596
688
|
this._metadata.identity = record;
|
|
597
689
|
await this._save();
|
|
690
|
+
await this.flush();
|
|
598
691
|
}
|
|
599
692
|
async addSpace(record) {
|
|
600
693
|
(0, import_invariant3.invariant)(!(this._metadata.spaces ?? []).find((space) => space.key === record.key), "Cannot overwrite existing space in metadata", {
|
|
601
694
|
F: __dxlog_file3,
|
|
602
|
-
L:
|
|
695
|
+
L: 245,
|
|
603
696
|
S: this,
|
|
604
697
|
A: [
|
|
605
698
|
"!(this._metadata.spaces ?? []).find((space) => space.key === record.key)",
|
|
@@ -608,6 +701,7 @@ var MetadataStore = class {
|
|
|
608
701
|
});
|
|
609
702
|
(this._metadata.spaces ??= []).push(record);
|
|
610
703
|
await this._save();
|
|
704
|
+
await this.flush();
|
|
611
705
|
}
|
|
612
706
|
async setSpaceDataLatestTimeframe(spaceKey, timeframe) {
|
|
613
707
|
this._getSpace(spaceKey).dataTimeframe = timeframe;
|
|
@@ -616,6 +710,7 @@ var MetadataStore = class {
|
|
|
616
710
|
async setSpaceControlLatestTimeframe(spaceKey, timeframe) {
|
|
617
711
|
this._getSpace(spaceKey).controlTimeframe = timeframe;
|
|
618
712
|
await this._save();
|
|
713
|
+
await this.flush();
|
|
619
714
|
}
|
|
620
715
|
async setCache(spaceKey, cache) {
|
|
621
716
|
this._getSpace(spaceKey).cache = cache;
|
|
@@ -626,10 +721,20 @@ var MetadataStore = class {
|
|
|
626
721
|
space.controlFeedKey = controlFeedKey;
|
|
627
722
|
space.dataFeedKey = dataFeedKey;
|
|
628
723
|
await this._save();
|
|
724
|
+
await this.flush();
|
|
629
725
|
}
|
|
630
726
|
async setSpaceState(spaceKey, state) {
|
|
631
727
|
this._getSpace(spaceKey).state = state;
|
|
632
728
|
await this._save();
|
|
729
|
+
await this.flush();
|
|
730
|
+
}
|
|
731
|
+
getSpaceControlPipelineSnapshot(spaceKey) {
|
|
732
|
+
return this._getLargeSpaceMetadata(spaceKey).controlPipelineSnapshot;
|
|
733
|
+
}
|
|
734
|
+
async setSpaceControlPipelineSnapshot(spaceKey, snapshot) {
|
|
735
|
+
this._getLargeSpaceMetadata(spaceKey).controlPipelineSnapshot = snapshot;
|
|
736
|
+
await this._saveSpaceLargeMetadata(spaceKey);
|
|
737
|
+
await this.flush();
|
|
633
738
|
}
|
|
634
739
|
};
|
|
635
740
|
_ts_decorate2([
|
|
@@ -638,6 +743,9 @@ _ts_decorate2([
|
|
|
638
743
|
_ts_decorate2([
|
|
639
744
|
import_async2.synchronized
|
|
640
745
|
], MetadataStore.prototype, "_save", null);
|
|
746
|
+
_ts_decorate2([
|
|
747
|
+
import_async2.synchronized
|
|
748
|
+
], MetadataStore.prototype, "_saveSpaceLargeMetadata", null);
|
|
641
749
|
var fromBytesInt32 = (buf) => buf.readInt32LE(0);
|
|
642
750
|
|
|
643
751
|
// packages/core/echo/echo-pipeline/src/space/auth.ts
|
|
@@ -648,7 +756,7 @@ var import_invariant4 = require("@dxos/invariant");
|
|
|
648
756
|
var import_log4 = require("@dxos/log");
|
|
649
757
|
var import_protocols4 = require("@dxos/protocols");
|
|
650
758
|
var import_teleport = require("@dxos/teleport");
|
|
651
|
-
var __dxlog_file4 = "/
|
|
759
|
+
var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/auth.ts";
|
|
652
760
|
var AuthExtension = class extends import_teleport.RpcExtension {
|
|
653
761
|
constructor(_authParams) {
|
|
654
762
|
super({
|
|
@@ -741,10 +849,14 @@ var AuthExtension = class extends import_teleport.RpcExtension {
|
|
|
741
849
|
await this._ctx.dispose();
|
|
742
850
|
await super.onClose();
|
|
743
851
|
}
|
|
852
|
+
async onAbort() {
|
|
853
|
+
await this._ctx.dispose();
|
|
854
|
+
await super.onAbort();
|
|
855
|
+
}
|
|
744
856
|
};
|
|
745
857
|
|
|
746
858
|
// packages/core/echo/echo-pipeline/src/space/space.ts
|
|
747
|
-
var
|
|
859
|
+
var import_async8 = require("@dxos/async");
|
|
748
860
|
var import_invariant9 = require("@dxos/invariant");
|
|
749
861
|
var import_log10 = require("@dxos/log");
|
|
750
862
|
var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
@@ -752,9 +864,10 @@ var import_tracing3 = require("@dxos/tracing");
|
|
|
752
864
|
var import_util7 = require("@dxos/util");
|
|
753
865
|
|
|
754
866
|
// packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
|
|
867
|
+
var import_async6 = require("@dxos/async");
|
|
755
868
|
var import_context5 = require("@dxos/context");
|
|
756
869
|
var import_credentials = require("@dxos/credentials");
|
|
757
|
-
var
|
|
870
|
+
var import_keys5 = require("@dxos/keys");
|
|
758
871
|
var import_log8 = require("@dxos/log");
|
|
759
872
|
var import_credentials2 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
760
873
|
var import_timeframe3 = require("@dxos/timeframe");
|
|
@@ -767,7 +880,7 @@ var import_context4 = require("@dxos/context");
|
|
|
767
880
|
var import_debug3 = require("@dxos/debug");
|
|
768
881
|
var import_feed_store = require("@dxos/feed-store");
|
|
769
882
|
var import_invariant7 = require("@dxos/invariant");
|
|
770
|
-
var
|
|
883
|
+
var import_keys4 = require("@dxos/keys");
|
|
771
884
|
var import_log7 = require("@dxos/log");
|
|
772
885
|
var import_timeframe2 = require("@dxos/timeframe");
|
|
773
886
|
var import_util4 = require("@dxos/util");
|
|
@@ -780,7 +893,7 @@ var valueEncoding = (0, import_hypercore.createCodecEncoding)(codec);
|
|
|
780
893
|
|
|
781
894
|
// packages/core/echo/echo-pipeline/src/common/feeds.ts
|
|
782
895
|
var import_invariant5 = require("@dxos/invariant");
|
|
783
|
-
var __dxlog_file5 = "/
|
|
896
|
+
var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/common/feeds.ts";
|
|
784
897
|
var createMappedFeedWriter = (mapper, writer) => {
|
|
785
898
|
(0, import_invariant5.invariant)(mapper, void 0, {
|
|
786
899
|
F: __dxlog_file5,
|
|
@@ -808,7 +921,7 @@ var createMappedFeedWriter = (mapper, writer) => {
|
|
|
808
921
|
// packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts
|
|
809
922
|
var import_invariant6 = require("@dxos/invariant");
|
|
810
923
|
var import_log5 = require("@dxos/log");
|
|
811
|
-
var __dxlog_file6 = "/
|
|
924
|
+
var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/pipeline/message-selector.ts";
|
|
812
925
|
var createMessageSelector = (timeframeClock) => {
|
|
813
926
|
return (messages) => {
|
|
814
927
|
for (let i = 0; i < messages.length; i++) {
|
|
@@ -850,7 +963,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
850
963
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
851
964
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
852
965
|
}
|
|
853
|
-
var __dxlog_file7 = "/
|
|
966
|
+
var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts";
|
|
854
967
|
var mapFeedIndexesToTimeframe = (indexes) => new import_timeframe.Timeframe(indexes.map(({ feedKey, index }) => [
|
|
855
968
|
feedKey,
|
|
856
969
|
index
|
|
@@ -940,7 +1053,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
940
1053
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
941
1054
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
942
1055
|
}
|
|
943
|
-
var __dxlog_file8 = "/
|
|
1056
|
+
var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts";
|
|
944
1057
|
var PipelineState = class {
|
|
945
1058
|
// prettier-ignore
|
|
946
1059
|
constructor(_feeds, _timeframeClock) {
|
|
@@ -950,6 +1063,7 @@ var PipelineState = class {
|
|
|
950
1063
|
this.timeframeUpdate = this._timeframeClock.update;
|
|
951
1064
|
this.stalled = new import_async5.Event();
|
|
952
1065
|
this._startTimeframe = new import_timeframe2.Timeframe();
|
|
1066
|
+
this._reachedTarget = false;
|
|
953
1067
|
}
|
|
954
1068
|
/**
|
|
955
1069
|
* Latest theoretical timeframe based on the last mutation in each feed.
|
|
@@ -974,6 +1088,9 @@ var PipelineState = class {
|
|
|
974
1088
|
get targetTimeframe() {
|
|
975
1089
|
return this._targetTimeframe ? this._targetTimeframe : new import_timeframe2.Timeframe();
|
|
976
1090
|
}
|
|
1091
|
+
get reachedTarget() {
|
|
1092
|
+
return this._reachedTarget;
|
|
1093
|
+
}
|
|
977
1094
|
get feeds() {
|
|
978
1095
|
return Array.from(this._feeds.values());
|
|
979
1096
|
}
|
|
@@ -997,7 +1114,7 @@ var PipelineState = class {
|
|
|
997
1114
|
target: this.targetTimeframe
|
|
998
1115
|
}, {
|
|
999
1116
|
F: __dxlog_file8,
|
|
1000
|
-
L:
|
|
1117
|
+
L: 134,
|
|
1001
1118
|
S: this,
|
|
1002
1119
|
C: (f, a) => f(...a)
|
|
1003
1120
|
});
|
|
@@ -1016,6 +1133,7 @@ var PipelineState = class {
|
|
|
1016
1133
|
(0, import_context4.rejectOnDispose)(this._ctx),
|
|
1017
1134
|
this._reachedTargetPromise.then(() => {
|
|
1018
1135
|
done = true;
|
|
1136
|
+
this._reachedTarget = true;
|
|
1019
1137
|
}),
|
|
1020
1138
|
(0, import_async5.sleep)(timeout).then(() => {
|
|
1021
1139
|
if (done) {
|
|
@@ -1028,7 +1146,7 @@ var PipelineState = class {
|
|
|
1028
1146
|
dependencies: import_timeframe2.Timeframe.dependencies(this.targetTimeframe, this.timeframe)
|
|
1029
1147
|
}, {
|
|
1030
1148
|
F: __dxlog_file8,
|
|
1031
|
-
L:
|
|
1149
|
+
L: 162,
|
|
1032
1150
|
S: this,
|
|
1033
1151
|
C: (f, a) => f(...a)
|
|
1034
1152
|
});
|
|
@@ -1042,14 +1160,14 @@ var PipelineState = class {
|
|
|
1042
1160
|
var Pipeline = class {
|
|
1043
1161
|
constructor() {
|
|
1044
1162
|
this._timeframeClock = new TimeframeClock(new import_timeframe2.Timeframe());
|
|
1045
|
-
this._feeds = new import_util4.ComplexMap(
|
|
1163
|
+
this._feeds = new import_util4.ComplexMap(import_keys4.PublicKey.hash);
|
|
1046
1164
|
// External state accessor.
|
|
1047
1165
|
this._state = new PipelineState(this._feeds, this._timeframeClock);
|
|
1048
1166
|
// Waits for the message consumer to process the message and yield control back to the pipeline.
|
|
1049
1167
|
this._processingTrigger = new import_async5.Trigger().wake();
|
|
1050
1168
|
this._pauseTrigger = new import_async5.Trigger().wake();
|
|
1051
1169
|
// Pending downloads.
|
|
1052
|
-
this._downloads = new import_util4.ComplexMap((value) =>
|
|
1170
|
+
this._downloads = new import_util4.ComplexMap((value) => import_keys4.PublicKey.hash(value.key));
|
|
1053
1171
|
this._isStopping = false;
|
|
1054
1172
|
this._isStarted = false;
|
|
1055
1173
|
this._isBeingConsumed = false;
|
|
@@ -1061,7 +1179,7 @@ var Pipeline = class {
|
|
|
1061
1179
|
get writer() {
|
|
1062
1180
|
(0, import_invariant7.invariant)(this._writer, "Writer not set.", {
|
|
1063
1181
|
F: __dxlog_file8,
|
|
1064
|
-
L:
|
|
1182
|
+
L: 243,
|
|
1065
1183
|
S: this,
|
|
1066
1184
|
A: [
|
|
1067
1185
|
"this._writer",
|
|
@@ -1090,7 +1208,7 @@ var Pipeline = class {
|
|
|
1090
1208
|
setWriteFeed(feed) {
|
|
1091
1209
|
(0, import_invariant7.invariant)(!this._writer, "Writer already set.", {
|
|
1092
1210
|
F: __dxlog_file8,
|
|
1093
|
-
L:
|
|
1211
|
+
L: 270,
|
|
1094
1212
|
S: this,
|
|
1095
1213
|
A: [
|
|
1096
1214
|
"!this._writer",
|
|
@@ -1099,7 +1217,7 @@ var Pipeline = class {
|
|
|
1099
1217
|
});
|
|
1100
1218
|
(0, import_invariant7.invariant)(feed.properties.writable, "Feed must be writable.", {
|
|
1101
1219
|
F: __dxlog_file8,
|
|
1102
|
-
L:
|
|
1220
|
+
L: 271,
|
|
1103
1221
|
S: this,
|
|
1104
1222
|
A: [
|
|
1105
1223
|
"feed.properties.writable",
|
|
@@ -1114,7 +1232,7 @@ var Pipeline = class {
|
|
|
1114
1232
|
async start() {
|
|
1115
1233
|
(0, import_invariant7.invariant)(!this._isStarted, "Pipeline is already started.", {
|
|
1116
1234
|
F: __dxlog_file8,
|
|
1117
|
-
L:
|
|
1235
|
+
L: 284,
|
|
1118
1236
|
S: this,
|
|
1119
1237
|
A: [
|
|
1120
1238
|
"!this._isStarted",
|
|
@@ -1123,7 +1241,7 @@ var Pipeline = class {
|
|
|
1123
1241
|
});
|
|
1124
1242
|
(0, import_log7.log)("starting...", void 0, {
|
|
1125
1243
|
F: __dxlog_file8,
|
|
1126
|
-
L:
|
|
1244
|
+
L: 285,
|
|
1127
1245
|
S: this,
|
|
1128
1246
|
C: (f, a) => f(...a)
|
|
1129
1247
|
});
|
|
@@ -1132,7 +1250,7 @@ var Pipeline = class {
|
|
|
1132
1250
|
this._isStarted = true;
|
|
1133
1251
|
(0, import_log7.log)("started", void 0, {
|
|
1134
1252
|
F: __dxlog_file8,
|
|
1135
|
-
L:
|
|
1253
|
+
L: 289,
|
|
1136
1254
|
S: this,
|
|
1137
1255
|
C: (f, a) => f(...a)
|
|
1138
1256
|
});
|
|
@@ -1145,7 +1263,7 @@ var Pipeline = class {
|
|
|
1145
1263
|
async stop() {
|
|
1146
1264
|
(0, import_log7.log)("stopping...", void 0, {
|
|
1147
1265
|
F: __dxlog_file8,
|
|
1148
|
-
L:
|
|
1266
|
+
L: 300,
|
|
1149
1267
|
S: this,
|
|
1150
1268
|
C: (f, a) => f(...a)
|
|
1151
1269
|
});
|
|
@@ -1159,10 +1277,11 @@ var Pipeline = class {
|
|
|
1159
1277
|
await this._state._ctx.dispose();
|
|
1160
1278
|
this._state._ctx = new import_context4.Context();
|
|
1161
1279
|
this._state._reachedTargetPromise = void 0;
|
|
1280
|
+
this._state._reachedTarget = false;
|
|
1162
1281
|
this._isStarted = false;
|
|
1163
1282
|
(0, import_log7.log)("stopped", void 0, {
|
|
1164
1283
|
F: __dxlog_file8,
|
|
1165
|
-
L:
|
|
1284
|
+
L: 313,
|
|
1166
1285
|
S: this,
|
|
1167
1286
|
C: (f, a) => f(...a)
|
|
1168
1287
|
});
|
|
@@ -1174,7 +1293,7 @@ var Pipeline = class {
|
|
|
1174
1293
|
async setCursor(timeframe) {
|
|
1175
1294
|
(0, import_invariant7.invariant)(!this._isStarted || this._isPaused, "Invalid state.", {
|
|
1176
1295
|
F: __dxlog_file8,
|
|
1177
|
-
L:
|
|
1296
|
+
L: 322,
|
|
1178
1297
|
S: this,
|
|
1179
1298
|
A: [
|
|
1180
1299
|
"!this._isStarted || this._isPaused",
|
|
@@ -1203,7 +1322,7 @@ var Pipeline = class {
|
|
|
1203
1322
|
async unpause() {
|
|
1204
1323
|
(0, import_invariant7.invariant)(this._isPaused, "Pipeline is not paused.", {
|
|
1205
1324
|
F: __dxlog_file8,
|
|
1206
|
-
L:
|
|
1325
|
+
L: 351,
|
|
1207
1326
|
S: this,
|
|
1208
1327
|
A: [
|
|
1209
1328
|
"this._isPaused",
|
|
@@ -1223,7 +1342,7 @@ var Pipeline = class {
|
|
|
1223
1342
|
async *consume() {
|
|
1224
1343
|
(0, import_invariant7.invariant)(!this._isBeingConsumed, "Pipeline is already being consumed.", {
|
|
1225
1344
|
F: __dxlog_file8,
|
|
1226
|
-
L:
|
|
1345
|
+
L: 366,
|
|
1227
1346
|
S: this,
|
|
1228
1347
|
A: [
|
|
1229
1348
|
"!this._isBeingConsumed",
|
|
@@ -1233,7 +1352,7 @@ var Pipeline = class {
|
|
|
1233
1352
|
this._isBeingConsumed = true;
|
|
1234
1353
|
(0, import_invariant7.invariant)(this._feedSetIterator, "Iterator not initialized.", {
|
|
1235
1354
|
F: __dxlog_file8,
|
|
1236
|
-
L:
|
|
1355
|
+
L: 369,
|
|
1237
1356
|
S: this,
|
|
1238
1357
|
A: [
|
|
1239
1358
|
"this._feedSetIterator",
|
|
@@ -1247,7 +1366,7 @@ var Pipeline = class {
|
|
|
1247
1366
|
if (lastFeedSetIterator !== this._feedSetIterator) {
|
|
1248
1367
|
(0, import_invariant7.invariant)(this._feedSetIterator, "Iterator not initialized.", {
|
|
1249
1368
|
F: __dxlog_file8,
|
|
1250
|
-
L:
|
|
1369
|
+
L: 378,
|
|
1251
1370
|
S: this,
|
|
1252
1371
|
A: [
|
|
1253
1372
|
"this._feedSetIterator",
|
|
@@ -1261,7 +1380,7 @@ var Pipeline = class {
|
|
|
1261
1380
|
if (!done) {
|
|
1262
1381
|
const block = value ?? (0, import_debug3.failUndefined)();
|
|
1263
1382
|
this._processingTrigger.reset();
|
|
1264
|
-
this._timeframeClock.updatePendingTimeframe(
|
|
1383
|
+
this._timeframeClock.updatePendingTimeframe(import_keys4.PublicKey.from(block.feedKey), block.seq);
|
|
1265
1384
|
yield block;
|
|
1266
1385
|
this._processingTrigger.wake();
|
|
1267
1386
|
this._timeframeClock.updateTimeframe();
|
|
@@ -1282,7 +1401,7 @@ var Pipeline = class {
|
|
|
1282
1401
|
length: feed.length
|
|
1283
1402
|
}, {
|
|
1284
1403
|
F: __dxlog_file8,
|
|
1285
|
-
L:
|
|
1404
|
+
L: 407,
|
|
1286
1405
|
S: this,
|
|
1287
1406
|
C: (f, a) => f(...a)
|
|
1288
1407
|
});
|
|
@@ -1296,7 +1415,7 @@ var Pipeline = class {
|
|
|
1296
1415
|
data
|
|
1297
1416
|
}, {
|
|
1298
1417
|
F: __dxlog_file8,
|
|
1299
|
-
L:
|
|
1418
|
+
L: 412,
|
|
1300
1419
|
S: this,
|
|
1301
1420
|
C: (f, a) => f(...a)
|
|
1302
1421
|
});
|
|
@@ -1312,7 +1431,7 @@ var Pipeline = class {
|
|
|
1312
1431
|
this._feedSetIterator.stalled.on((iterator) => {
|
|
1313
1432
|
import_log7.log.warn(`Stalled after ${iterator.options.stallTimeout}ms with ${iterator.size} feeds.`, void 0, {
|
|
1314
1433
|
F: __dxlog_file8,
|
|
1315
|
-
L:
|
|
1434
|
+
L: 426,
|
|
1316
1435
|
S: this,
|
|
1317
1436
|
C: (f, a) => f(...a)
|
|
1318
1437
|
});
|
|
@@ -1350,14 +1469,21 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
1350
1469
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1351
1470
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1352
1471
|
}
|
|
1353
|
-
var __dxlog_file9 = "/
|
|
1472
|
+
var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/control-pipeline.ts";
|
|
1354
1473
|
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL = 500;
|
|
1474
|
+
var CONTROL_PIPELINE_SNAPSHOT_DELAY = 1e4;
|
|
1475
|
+
var USE_SNAPSHOTS = true;
|
|
1355
1476
|
var ControlPipeline = class ControlPipeline2 {
|
|
1356
1477
|
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }) {
|
|
1478
|
+
this._ctx = new import_context5.Context();
|
|
1357
1479
|
this._lastTimeframeSaveTime = Date.now();
|
|
1358
1480
|
this.onFeedAdmitted = new import_util5.Callback();
|
|
1359
1481
|
this._usage = new import_tracing.TimeUsageCounter();
|
|
1360
1482
|
this._mutations = new import_tracing.TimeSeriesCounter();
|
|
1483
|
+
this._snapshotTask = new import_async6.DeferredTask(this._ctx, async () => {
|
|
1484
|
+
await (0, import_async6.sleep)(CONTROL_PIPELINE_SNAPSHOT_DELAY);
|
|
1485
|
+
await this._saveSnapshot();
|
|
1486
|
+
});
|
|
1361
1487
|
this._spaceKey = spaceKey;
|
|
1362
1488
|
this._metadata = metadataStore;
|
|
1363
1489
|
this._pipeline = new Pipeline();
|
|
@@ -1368,22 +1494,24 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1368
1494
|
key: info.key
|
|
1369
1495
|
}, {
|
|
1370
1496
|
F: __dxlog_file9,
|
|
1371
|
-
L:
|
|
1497
|
+
L: 73,
|
|
1372
1498
|
S: this,
|
|
1373
1499
|
C: (f, a) => f(...a)
|
|
1374
1500
|
});
|
|
1375
1501
|
if (info.assertion.designation === import_credentials2.AdmittedFeed.Designation.CONTROL && !info.key.equals(genesisFeed.key)) {
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1502
|
+
queueMicrotask(async () => {
|
|
1503
|
+
try {
|
|
1504
|
+
const feed = await feedProvider(info.key);
|
|
1505
|
+
await this._pipeline.addFeed(feed);
|
|
1506
|
+
} catch (err) {
|
|
1507
|
+
import_log8.log.catch(err, void 0, {
|
|
1508
|
+
F: __dxlog_file9,
|
|
1509
|
+
L: 82,
|
|
1510
|
+
S: this,
|
|
1511
|
+
C: (f, a) => f(...a)
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1387
1515
|
}
|
|
1388
1516
|
await this.onFeedAdmitted.callIfSet(info);
|
|
1389
1517
|
});
|
|
@@ -1400,9 +1528,23 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1400
1528
|
this._pipeline.setWriteFeed(feed);
|
|
1401
1529
|
}
|
|
1402
1530
|
async start() {
|
|
1531
|
+
const snapshot = this._metadata.getSpaceControlPipelineSnapshot(this._spaceKey);
|
|
1532
|
+
(0, import_log8.log)("load snapshot", {
|
|
1533
|
+
key: this._spaceKey,
|
|
1534
|
+
present: !!snapshot,
|
|
1535
|
+
tf: snapshot?.timeframe
|
|
1536
|
+
}, {
|
|
1537
|
+
F: __dxlog_file9,
|
|
1538
|
+
L: 109,
|
|
1539
|
+
S: this,
|
|
1540
|
+
C: (f, a) => f(...a)
|
|
1541
|
+
});
|
|
1542
|
+
if (USE_SNAPSHOTS && snapshot) {
|
|
1543
|
+
await this._processSnapshot(snapshot);
|
|
1544
|
+
}
|
|
1403
1545
|
(0, import_log8.log)("starting...", void 0, {
|
|
1404
1546
|
F: __dxlog_file9,
|
|
1405
|
-
L:
|
|
1547
|
+
L: 114,
|
|
1406
1548
|
S: this,
|
|
1407
1549
|
C: (f, a) => f(...a)
|
|
1408
1550
|
});
|
|
@@ -1412,11 +1554,51 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1412
1554
|
await this._pipeline.start();
|
|
1413
1555
|
(0, import_log8.log)("started", void 0, {
|
|
1414
1556
|
F: __dxlog_file9,
|
|
1415
|
-
L:
|
|
1557
|
+
L: 120,
|
|
1416
1558
|
S: this,
|
|
1417
1559
|
C: (f, a) => f(...a)
|
|
1418
1560
|
});
|
|
1419
1561
|
}
|
|
1562
|
+
async _processSnapshot(snapshot) {
|
|
1563
|
+
await this._pipeline.setCursor(snapshot.timeframe);
|
|
1564
|
+
for (const message of snapshot.messages ?? []) {
|
|
1565
|
+
const result = await this._spaceStateMachine.process(message.credential, {
|
|
1566
|
+
sourceFeed: message.feedKey,
|
|
1567
|
+
skipVerification: true
|
|
1568
|
+
});
|
|
1569
|
+
if (!result) {
|
|
1570
|
+
import_log8.log.warn("credential processing failed from snapshot", {
|
|
1571
|
+
message
|
|
1572
|
+
}, {
|
|
1573
|
+
F: __dxlog_file9,
|
|
1574
|
+
L: 133,
|
|
1575
|
+
S: this,
|
|
1576
|
+
C: (f, a) => f(...a)
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
async _saveSnapshot() {
|
|
1582
|
+
await this._pipeline.pause();
|
|
1583
|
+
const snapshot = {
|
|
1584
|
+
timeframe: this._pipeline.state.timeframe,
|
|
1585
|
+
messages: this._spaceStateMachine.credentialEntries.map((entry) => ({
|
|
1586
|
+
feedKey: entry.sourceFeed,
|
|
1587
|
+
credential: entry.credential
|
|
1588
|
+
}))
|
|
1589
|
+
};
|
|
1590
|
+
await this._pipeline.unpause();
|
|
1591
|
+
(0, import_log8.log)("save snapshot", {
|
|
1592
|
+
key: this._spaceKey,
|
|
1593
|
+
snapshot
|
|
1594
|
+
}, {
|
|
1595
|
+
F: __dxlog_file9,
|
|
1596
|
+
L: 149,
|
|
1597
|
+
S: this,
|
|
1598
|
+
C: (f, a) => f(...a)
|
|
1599
|
+
});
|
|
1600
|
+
await this._metadata.setSpaceControlPipelineSnapshot(this._spaceKey, snapshot);
|
|
1601
|
+
}
|
|
1420
1602
|
async _consumePipeline(ctx) {
|
|
1421
1603
|
for await (const msg of this._pipeline.consume()) {
|
|
1422
1604
|
const span = this._usage.beginRecording();
|
|
@@ -1426,7 +1608,7 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1426
1608
|
} catch (err) {
|
|
1427
1609
|
import_log8.log.catch(err, void 0, {
|
|
1428
1610
|
F: __dxlog_file9,
|
|
1429
|
-
L:
|
|
1611
|
+
L: 162,
|
|
1430
1612
|
S: this,
|
|
1431
1613
|
C: (f, a) => f(...a)
|
|
1432
1614
|
});
|
|
@@ -1440,26 +1622,29 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1440
1622
|
seq: msg.seq
|
|
1441
1623
|
}, {
|
|
1442
1624
|
F: __dxlog_file9,
|
|
1443
|
-
L:
|
|
1625
|
+
L: 172,
|
|
1444
1626
|
S: this,
|
|
1445
1627
|
C: (f, a) => f(...a)
|
|
1446
1628
|
});
|
|
1447
1629
|
if (msg.data.payload.credential) {
|
|
1448
1630
|
const timer = import_util5.tracer.mark("dxos.echo.pipeline.control");
|
|
1449
|
-
const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential,
|
|
1631
|
+
const result = await this._spaceStateMachine.process(msg.data.payload.credential.credential, {
|
|
1632
|
+
sourceFeed: import_keys5.PublicKey.from(msg.feedKey)
|
|
1633
|
+
});
|
|
1450
1634
|
timer.end();
|
|
1451
1635
|
if (!result) {
|
|
1452
1636
|
import_log8.log.warn("processing failed", {
|
|
1453
1637
|
msg
|
|
1454
1638
|
}, {
|
|
1455
1639
|
F: __dxlog_file9,
|
|
1456
|
-
L:
|
|
1640
|
+
L: 181,
|
|
1457
1641
|
S: this,
|
|
1458
1642
|
C: (f, a) => f(...a)
|
|
1459
1643
|
});
|
|
1460
1644
|
} else {
|
|
1461
1645
|
await this._noteTargetStateIfNeeded(this._pipeline.state.pendingTimeframe);
|
|
1462
1646
|
}
|
|
1647
|
+
this._snapshotTask.schedule();
|
|
1463
1648
|
}
|
|
1464
1649
|
}
|
|
1465
1650
|
async _noteTargetStateIfNeeded(timeframe) {
|
|
@@ -1471,15 +1656,16 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1471
1656
|
async stop() {
|
|
1472
1657
|
(0, import_log8.log)("stopping...", void 0, {
|
|
1473
1658
|
F: __dxlog_file9,
|
|
1474
|
-
L:
|
|
1659
|
+
L: 201,
|
|
1475
1660
|
S: this,
|
|
1476
1661
|
C: (f, a) => f(...a)
|
|
1477
1662
|
});
|
|
1663
|
+
await this._ctx.dispose();
|
|
1478
1664
|
await this._pipeline.stop();
|
|
1479
1665
|
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
1480
1666
|
(0, import_log8.log)("stopped", void 0, {
|
|
1481
1667
|
F: __dxlog_file9,
|
|
1482
|
-
L:
|
|
1668
|
+
L: 205,
|
|
1483
1669
|
S: this,
|
|
1484
1670
|
C: (f, a) => f(...a)
|
|
1485
1671
|
});
|
|
@@ -1492,7 +1678,7 @@ var ControlPipeline = class ControlPipeline2 {
|
|
|
1492
1678
|
} catch (err) {
|
|
1493
1679
|
(0, import_log8.log)(err, void 0, {
|
|
1494
1680
|
F: __dxlog_file9,
|
|
1495
|
-
L:
|
|
1681
|
+
L: 214,
|
|
1496
1682
|
S: this,
|
|
1497
1683
|
C: (f, a) => f(...a)
|
|
1498
1684
|
});
|
|
@@ -1505,6 +1691,11 @@ _ts_decorate5([
|
|
|
1505
1691
|
_ts_decorate5([
|
|
1506
1692
|
import_tracing.trace.metricsCounter()
|
|
1507
1693
|
], ControlPipeline.prototype, "_mutations", void 0);
|
|
1694
|
+
_ts_decorate5([
|
|
1695
|
+
import_tracing.trace.span({
|
|
1696
|
+
showInBrowserTimeline: true
|
|
1697
|
+
})
|
|
1698
|
+
], ControlPipeline.prototype, "start", null);
|
|
1508
1699
|
_ts_decorate5([
|
|
1509
1700
|
import_tracing.trace.span()
|
|
1510
1701
|
], ControlPipeline.prototype, "_consumePipeline", null);
|
|
@@ -1516,7 +1707,7 @@ ControlPipeline = _ts_decorate5([
|
|
|
1516
1707
|
], ControlPipeline);
|
|
1517
1708
|
|
|
1518
1709
|
// packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
|
|
1519
|
-
var
|
|
1710
|
+
var import_async7 = require("@dxos/async");
|
|
1520
1711
|
var import_context6 = require("@dxos/context");
|
|
1521
1712
|
var import_credentials3 = require("@dxos/credentials");
|
|
1522
1713
|
var import_echo_db3 = require("@dxos/echo-db");
|
|
@@ -1536,10 +1727,10 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
1536
1727
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1537
1728
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1538
1729
|
}
|
|
1539
|
-
var __dxlog_file10 = "/
|
|
1730
|
+
var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/data-pipeline.ts";
|
|
1540
1731
|
var MESSAGES_PER_SNAPSHOT = 10;
|
|
1541
1732
|
var AUTOMATIC_SNAPSHOT_DEBOUNCE_INTERVAL = 5e3;
|
|
1542
|
-
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 =
|
|
1733
|
+
var TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2 = 5e3;
|
|
1543
1734
|
var DataPipeline = class DataPipeline2 {
|
|
1544
1735
|
constructor(_params) {
|
|
1545
1736
|
this._params = _params;
|
|
@@ -1555,7 +1746,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1555
1746
|
this._mutations = new import_tracing2.TimeSeriesCounter();
|
|
1556
1747
|
this.currentEpoch = void 0;
|
|
1557
1748
|
this.appliedEpoch = void 0;
|
|
1558
|
-
this.onNewEpoch = new
|
|
1749
|
+
this.onNewEpoch = new import_async7.Event();
|
|
1559
1750
|
}
|
|
1560
1751
|
get isOpen() {
|
|
1561
1752
|
return this._isOpen;
|
|
@@ -1615,10 +1806,10 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1615
1806
|
}, options);
|
|
1616
1807
|
}
|
|
1617
1808
|
};
|
|
1618
|
-
this.databaseHost = new DatabaseHost(feedWriter);
|
|
1809
|
+
this.databaseHost = new DatabaseHost(feedWriter, () => this._flush());
|
|
1619
1810
|
this.itemManager = new import_echo_db3.ItemManager(this._params.modelFactory);
|
|
1620
1811
|
await this.databaseHost.open(this.itemManager, this._params.modelFactory);
|
|
1621
|
-
(0,
|
|
1812
|
+
(0, import_async7.scheduleTask)(this._ctx, async () => {
|
|
1622
1813
|
await this._consumePipeline();
|
|
1623
1814
|
});
|
|
1624
1815
|
this._isOpen = true;
|
|
@@ -1666,9 +1857,10 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1666
1857
|
await this._processEpochInSeparateTask(this.currentEpoch);
|
|
1667
1858
|
await waitForOneEpoch;
|
|
1668
1859
|
}
|
|
1860
|
+
let messageCounter = 0;
|
|
1669
1861
|
(0, import_invariant8.invariant)(this._pipeline, "Pipeline is not initialized.", {
|
|
1670
1862
|
F: __dxlog_file10,
|
|
1671
|
-
L:
|
|
1863
|
+
L: 217,
|
|
1672
1864
|
S: this,
|
|
1673
1865
|
A: [
|
|
1674
1866
|
"this._pipeline",
|
|
@@ -1684,7 +1876,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1684
1876
|
seq
|
|
1685
1877
|
}, {
|
|
1686
1878
|
F: __dxlog_file10,
|
|
1687
|
-
L:
|
|
1879
|
+
L: 223,
|
|
1688
1880
|
S: this,
|
|
1689
1881
|
C: (f, a) => f(...a)
|
|
1690
1882
|
});
|
|
@@ -1696,7 +1888,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1696
1888
|
feedKey
|
|
1697
1889
|
}, {
|
|
1698
1890
|
F: __dxlog_file10,
|
|
1699
|
-
L:
|
|
1891
|
+
L: 229,
|
|
1700
1892
|
S: this,
|
|
1701
1893
|
C: (f, a) => f(...a)
|
|
1702
1894
|
});
|
|
@@ -1719,7 +1911,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1719
1911
|
spaceKey: this._params.spaceKey.toHex()
|
|
1720
1912
|
}, {
|
|
1721
1913
|
F: __dxlog_file10,
|
|
1722
|
-
L:
|
|
1914
|
+
L: 246,
|
|
1723
1915
|
S: this,
|
|
1724
1916
|
C: (f, a) => f(...a)
|
|
1725
1917
|
});
|
|
@@ -1728,18 +1920,22 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1728
1920
|
} catch (err) {
|
|
1729
1921
|
import_log9.log.catch(err, void 0, {
|
|
1730
1922
|
F: __dxlog_file10,
|
|
1731
|
-
L:
|
|
1923
|
+
L: 256,
|
|
1732
1924
|
S: this,
|
|
1733
1925
|
C: (f, a) => f(...a)
|
|
1734
1926
|
});
|
|
1735
1927
|
}
|
|
1736
1928
|
span.end();
|
|
1929
|
+
if (++messageCounter > 1e3) {
|
|
1930
|
+
messageCounter = 0;
|
|
1931
|
+
await (0, import_async7.sleep)(1);
|
|
1932
|
+
}
|
|
1737
1933
|
}
|
|
1738
1934
|
}
|
|
1739
1935
|
_createSnapshot() {
|
|
1740
1936
|
(0, import_invariant8.invariant)(this.databaseHost, "Database backend is not initialized.", {
|
|
1741
1937
|
F: __dxlog_file10,
|
|
1742
|
-
L:
|
|
1938
|
+
L: 270,
|
|
1743
1939
|
S: this,
|
|
1744
1940
|
A: [
|
|
1745
1941
|
"this.databaseHost",
|
|
@@ -1768,7 +1964,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1768
1964
|
} catch (err) {
|
|
1769
1965
|
import_log9.log.warn("Failed to cache properties", err, {
|
|
1770
1966
|
F: __dxlog_file10,
|
|
1771
|
-
L:
|
|
1967
|
+
L: 299,
|
|
1772
1968
|
S: this,
|
|
1773
1969
|
C: (f, a) => f(...a)
|
|
1774
1970
|
});
|
|
@@ -1776,6 +1972,9 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1776
1972
|
await this._params.metadataStore.setCache(this._params.spaceKey, cache);
|
|
1777
1973
|
}
|
|
1778
1974
|
async _noteTargetStateIfNeeded(timeframe) {
|
|
1975
|
+
if (!this._pipeline?.state.reachedTarget) {
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1779
1978
|
if (Date.now() - this._lastTimeframeSaveTime > TIMEFRAME_SAVE_DEBOUNCE_INTERVAL2) {
|
|
1780
1979
|
this._lastTimeframeSaveTime = Date.now();
|
|
1781
1980
|
await this._saveTargetTimeframe(timeframe);
|
|
@@ -1794,14 +1993,14 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1794
1993
|
if (err instanceof import_errors2.CancelledError) {
|
|
1795
1994
|
(0, import_log9.log)("Epoch processing cancelled.", void 0, {
|
|
1796
1995
|
F: __dxlog_file10,
|
|
1797
|
-
L:
|
|
1996
|
+
L: 335,
|
|
1798
1997
|
S: this,
|
|
1799
1998
|
C: (f, a) => f(...a)
|
|
1800
1999
|
});
|
|
1801
2000
|
} else {
|
|
1802
2001
|
import_log9.log.catch(err, void 0, {
|
|
1803
2002
|
F: __dxlog_file10,
|
|
1804
|
-
L:
|
|
2003
|
+
L: 337,
|
|
1805
2004
|
S: this,
|
|
1806
2005
|
C: (f, a) => f(...a)
|
|
1807
2006
|
});
|
|
@@ -1809,7 +2008,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1809
2008
|
}
|
|
1810
2009
|
});
|
|
1811
2010
|
this._epochCtx = ctx;
|
|
1812
|
-
(0,
|
|
2011
|
+
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
1813
2012
|
if (!this._isOpen) {
|
|
1814
2013
|
return;
|
|
1815
2014
|
}
|
|
@@ -1821,7 +2020,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1821
2020
|
async _processEpoch(ctx, epoch) {
|
|
1822
2021
|
(0, import_invariant8.invariant)(this._isOpen, "Space is closed.", {
|
|
1823
2022
|
F: __dxlog_file10,
|
|
1824
|
-
L:
|
|
2023
|
+
L: 356,
|
|
1825
2024
|
S: this,
|
|
1826
2025
|
A: [
|
|
1827
2026
|
"this._isOpen",
|
|
@@ -1830,7 +2029,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1830
2029
|
});
|
|
1831
2030
|
(0, import_invariant8.invariant)(this._pipeline, void 0, {
|
|
1832
2031
|
F: __dxlog_file10,
|
|
1833
|
-
L:
|
|
2032
|
+
L: 357,
|
|
1834
2033
|
S: this,
|
|
1835
2034
|
A: [
|
|
1836
2035
|
"this._pipeline",
|
|
@@ -1842,7 +2041,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1842
2041
|
epoch: (0, import_log9.omit)(epoch, "proof")
|
|
1843
2042
|
}, {
|
|
1844
2043
|
F: __dxlog_file10,
|
|
1845
|
-
L:
|
|
2044
|
+
L: 360,
|
|
1846
2045
|
S: this,
|
|
1847
2046
|
C: (f, a) => f(...a)
|
|
1848
2047
|
});
|
|
@@ -1852,7 +2051,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1852
2051
|
}
|
|
1853
2052
|
(0, import_log9.log)("restarting pipeline from epoch", void 0, {
|
|
1854
2053
|
F: __dxlog_file10,
|
|
1855
|
-
L:
|
|
2054
|
+
L: 366,
|
|
1856
2055
|
S: this,
|
|
1857
2056
|
C: (f, a) => f(...a)
|
|
1858
2057
|
});
|
|
@@ -1863,7 +2062,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1863
2062
|
async waitUntilTimeframe(timeframe) {
|
|
1864
2063
|
(0, import_invariant8.invariant)(this._pipeline, "Pipeline is not initialized.", {
|
|
1865
2064
|
F: __dxlog_file10,
|
|
1866
|
-
L:
|
|
2065
|
+
L: 373,
|
|
1867
2066
|
S: this,
|
|
1868
2067
|
A: [
|
|
1869
2068
|
"this._pipeline",
|
|
@@ -1875,7 +2074,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1875
2074
|
async createEpoch() {
|
|
1876
2075
|
(0, import_invariant8.invariant)(this._pipeline, void 0, {
|
|
1877
2076
|
F: __dxlog_file10,
|
|
1878
|
-
L:
|
|
2077
|
+
L: 379,
|
|
1879
2078
|
S: this,
|
|
1880
2079
|
A: [
|
|
1881
2080
|
"this._pipeline",
|
|
@@ -1884,7 +2083,7 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1884
2083
|
});
|
|
1885
2084
|
(0, import_invariant8.invariant)(this.currentEpoch, void 0, {
|
|
1886
2085
|
F: __dxlog_file10,
|
|
1887
|
-
L:
|
|
2086
|
+
L: 380,
|
|
1888
2087
|
S: this,
|
|
1889
2088
|
A: [
|
|
1890
2089
|
"this.currentEpoch",
|
|
@@ -1906,6 +2105,22 @@ var DataPipeline = class DataPipeline2 {
|
|
|
1906
2105
|
async ensureEpochInitialized() {
|
|
1907
2106
|
await this.onNewEpoch.waitForCondition(() => !!this.currentEpoch);
|
|
1908
2107
|
}
|
|
2108
|
+
async _flush() {
|
|
2109
|
+
try {
|
|
2110
|
+
await this._saveCache();
|
|
2111
|
+
if (this._pipeline) {
|
|
2112
|
+
await this._saveTargetTimeframe(this._pipeline.state.timeframe);
|
|
2113
|
+
}
|
|
2114
|
+
} catch (err) {
|
|
2115
|
+
import_log9.log.catch(err, void 0, {
|
|
2116
|
+
F: __dxlog_file10,
|
|
2117
|
+
L: 410,
|
|
2118
|
+
S: this,
|
|
2119
|
+
C: (f, a) => f(...a)
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
await this._params.metadataStore.flush();
|
|
2123
|
+
}
|
|
1909
2124
|
};
|
|
1910
2125
|
_ts_decorate6([
|
|
1911
2126
|
import_tracing2.trace.metricsCounter()
|
|
@@ -1914,19 +2129,19 @@ _ts_decorate6([
|
|
|
1914
2129
|
import_tracing2.trace.metricsCounter()
|
|
1915
2130
|
], DataPipeline.prototype, "_mutations", void 0);
|
|
1916
2131
|
_ts_decorate6([
|
|
1917
|
-
|
|
2132
|
+
import_async7.synchronized
|
|
1918
2133
|
], DataPipeline.prototype, "open", null);
|
|
1919
2134
|
_ts_decorate6([
|
|
1920
|
-
|
|
2135
|
+
import_async7.synchronized
|
|
1921
2136
|
], DataPipeline.prototype, "close", null);
|
|
1922
2137
|
_ts_decorate6([
|
|
1923
|
-
|
|
2138
|
+
import_async7.synchronized
|
|
1924
2139
|
], DataPipeline.prototype, "_processEpoch", null);
|
|
1925
2140
|
_ts_decorate6([
|
|
1926
|
-
|
|
2141
|
+
import_async7.synchronized
|
|
1927
2142
|
], DataPipeline.prototype, "createEpoch", null);
|
|
1928
2143
|
DataPipeline = _ts_decorate6([
|
|
1929
|
-
(0,
|
|
2144
|
+
(0, import_async7.trackLeaks)("open", "close"),
|
|
1930
2145
|
import_tracing2.trace.resource()
|
|
1931
2146
|
], DataPipeline);
|
|
1932
2147
|
|
|
@@ -1941,12 +2156,12 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
1941
2156
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1942
2157
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1943
2158
|
}
|
|
1944
|
-
var __dxlog_file11 = "/
|
|
2159
|
+
var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/space.ts";
|
|
1945
2160
|
var Space = class Space2 {
|
|
1946
2161
|
constructor(params) {
|
|
1947
|
-
this._addFeedLock = new
|
|
2162
|
+
this._addFeedLock = new import_async8.Lock();
|
|
1948
2163
|
this.onCredentialProcessed = new import_util7.Callback();
|
|
1949
|
-
this.stateUpdate = new
|
|
2164
|
+
this.stateUpdate = new import_async8.Event();
|
|
1950
2165
|
this._isOpen = false;
|
|
1951
2166
|
(0, import_invariant9.invariant)(params.spaceKey && params.feedProvider, void 0, {
|
|
1952
2167
|
F: __dxlog_file11,
|
|
@@ -1970,7 +2185,7 @@ var Space = class Space2 {
|
|
|
1970
2185
|
this._controlPipeline.onFeedAdmitted.set(async (info) => {
|
|
1971
2186
|
const sparse = info.assertion.designation === import_credentials4.AdmittedFeed.Designation.DATA;
|
|
1972
2187
|
if (info.assertion.designation === import_credentials4.AdmittedFeed.Designation.DATA) {
|
|
1973
|
-
|
|
2188
|
+
queueMicrotask(async () => {
|
|
1974
2189
|
if (this._dataPipeline.pipeline) {
|
|
1975
2190
|
if (!this._dataPipeline.pipeline.hasFeed(info.key)) {
|
|
1976
2191
|
return this._dataPipeline.pipeline.addFeed(await this._feedProvider(info.key, {
|
|
@@ -1981,9 +2196,11 @@ var Space = class Space2 {
|
|
|
1981
2196
|
});
|
|
1982
2197
|
}
|
|
1983
2198
|
if (!info.key.equals(params.genesisFeed.key)) {
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2199
|
+
queueMicrotask(async () => {
|
|
2200
|
+
this.protocol.addFeed(await params.feedProvider(info.key, {
|
|
2201
|
+
sparse
|
|
2202
|
+
}));
|
|
2203
|
+
});
|
|
1987
2204
|
}
|
|
1988
2205
|
});
|
|
1989
2206
|
this._controlPipeline.onCredentialProcessed.set(async (credential) => {
|
|
@@ -1992,7 +2209,7 @@ var Space = class Space2 {
|
|
|
1992
2209
|
credential
|
|
1993
2210
|
}, {
|
|
1994
2211
|
F: __dxlog_file11,
|
|
1995
|
-
L:
|
|
2212
|
+
L: 111,
|
|
1996
2213
|
S: this,
|
|
1997
2214
|
C: (f, a) => f(...a)
|
|
1998
2215
|
});
|
|
@@ -2057,7 +2274,7 @@ var Space = class Space2 {
|
|
|
2057
2274
|
setControlFeed(feed) {
|
|
2058
2275
|
(0, import_invariant9.invariant)(!this._controlFeed, "Control feed already set.", {
|
|
2059
2276
|
F: __dxlog_file11,
|
|
2060
|
-
L:
|
|
2277
|
+
L: 186,
|
|
2061
2278
|
S: this,
|
|
2062
2279
|
A: [
|
|
2063
2280
|
"!this._controlFeed",
|
|
@@ -2071,7 +2288,7 @@ var Space = class Space2 {
|
|
|
2071
2288
|
setDataFeed(feed) {
|
|
2072
2289
|
(0, import_invariant9.invariant)(!this._dataFeed, "Data feed already set.", {
|
|
2073
2290
|
F: __dxlog_file11,
|
|
2074
|
-
L:
|
|
2291
|
+
L: 193,
|
|
2075
2292
|
S: this,
|
|
2076
2293
|
A: [
|
|
2077
2294
|
"!this._dataFeed",
|
|
@@ -2097,7 +2314,7 @@ var Space = class Space2 {
|
|
|
2097
2314
|
async open(ctx) {
|
|
2098
2315
|
(0, import_log10.log)("opening...", void 0, {
|
|
2099
2316
|
F: __dxlog_file11,
|
|
2100
|
-
L:
|
|
2317
|
+
L: 215,
|
|
2101
2318
|
S: this,
|
|
2102
2319
|
C: (f, a) => f(...a)
|
|
2103
2320
|
});
|
|
@@ -2110,7 +2327,7 @@ var Space = class Space2 {
|
|
|
2110
2327
|
this._isOpen = true;
|
|
2111
2328
|
(0, import_log10.log)("opened", void 0, {
|
|
2112
2329
|
F: __dxlog_file11,
|
|
2113
|
-
L:
|
|
2330
|
+
L: 226,
|
|
2114
2331
|
S: this,
|
|
2115
2332
|
C: (f, a) => f(...a)
|
|
2116
2333
|
});
|
|
@@ -2120,7 +2337,7 @@ var Space = class Space2 {
|
|
|
2120
2337
|
key: this._key
|
|
2121
2338
|
}, {
|
|
2122
2339
|
F: __dxlog_file11,
|
|
2123
|
-
L:
|
|
2340
|
+
L: 231,
|
|
2124
2341
|
S: this,
|
|
2125
2342
|
C: (f, a) => f(...a)
|
|
2126
2343
|
});
|
|
@@ -2134,7 +2351,7 @@ var Space = class Space2 {
|
|
|
2134
2351
|
this._isOpen = false;
|
|
2135
2352
|
(0, import_log10.log)("closed", void 0, {
|
|
2136
2353
|
F: __dxlog_file11,
|
|
2137
|
-
L:
|
|
2354
|
+
L: 244,
|
|
2138
2355
|
S: this,
|
|
2139
2356
|
C: (f, a) => f(...a)
|
|
2140
2357
|
});
|
|
@@ -2142,13 +2359,13 @@ var Space = class Space2 {
|
|
|
2142
2359
|
async initializeDataPipeline() {
|
|
2143
2360
|
(0, import_log10.log)("initializeDataPipeline", void 0, {
|
|
2144
2361
|
F: __dxlog_file11,
|
|
2145
|
-
L:
|
|
2362
|
+
L: 249,
|
|
2146
2363
|
S: this,
|
|
2147
2364
|
C: (f, a) => f(...a)
|
|
2148
2365
|
});
|
|
2149
2366
|
(0, import_invariant9.invariant)(this._isOpen, "Space must be open to initialize data pipeline.", {
|
|
2150
2367
|
F: __dxlog_file11,
|
|
2151
|
-
L:
|
|
2368
|
+
L: 250,
|
|
2152
2369
|
S: this,
|
|
2153
2370
|
A: [
|
|
2154
2371
|
"this._isOpen",
|
|
@@ -2163,31 +2380,31 @@ _ts_decorate7([
|
|
|
2163
2380
|
import_tracing3.trace.info()
|
|
2164
2381
|
], Space.prototype, "key", null);
|
|
2165
2382
|
_ts_decorate7([
|
|
2166
|
-
|
|
2383
|
+
import_async8.synchronized,
|
|
2167
2384
|
import_tracing3.trace.span()
|
|
2168
2385
|
], Space.prototype, "open", null);
|
|
2169
2386
|
_ts_decorate7([
|
|
2170
|
-
|
|
2387
|
+
import_async8.synchronized
|
|
2171
2388
|
], Space.prototype, "close", null);
|
|
2172
2389
|
_ts_decorate7([
|
|
2173
|
-
|
|
2390
|
+
import_async8.synchronized
|
|
2174
2391
|
], Space.prototype, "initializeDataPipeline", null);
|
|
2175
2392
|
Space = _ts_decorate7([
|
|
2176
|
-
(0,
|
|
2393
|
+
(0, import_async8.trackLeaks)("open", "close"),
|
|
2177
2394
|
import_tracing3.trace.resource()
|
|
2178
2395
|
], Space);
|
|
2179
2396
|
|
|
2180
2397
|
// packages/core/echo/echo-pipeline/src/space/space-manager.ts
|
|
2181
|
-
var
|
|
2398
|
+
var import_async9 = require("@dxos/async");
|
|
2182
2399
|
var import_debug4 = require("@dxos/debug");
|
|
2183
|
-
var
|
|
2400
|
+
var import_keys7 = require("@dxos/keys");
|
|
2184
2401
|
var import_log12 = require("@dxos/log");
|
|
2185
2402
|
var import_protocols6 = require("@dxos/protocols");
|
|
2186
2403
|
var import_util9 = require("@dxos/util");
|
|
2187
2404
|
|
|
2188
2405
|
// packages/core/echo/echo-pipeline/src/space/space-protocol.ts
|
|
2189
2406
|
var import_crypto3 = require("@dxos/crypto");
|
|
2190
|
-
var
|
|
2407
|
+
var import_keys6 = require("@dxos/keys");
|
|
2191
2408
|
var import_log11 = require("@dxos/log");
|
|
2192
2409
|
var import_network_manager = require("@dxos/network-manager");
|
|
2193
2410
|
var import_teleport2 = require("@dxos/teleport");
|
|
@@ -2204,13 +2421,13 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
2204
2421
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2205
2422
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2206
2423
|
}
|
|
2207
|
-
var __dxlog_file12 = "/
|
|
2424
|
+
var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/space-protocol.ts";
|
|
2208
2425
|
var MOCK_AUTH_PROVIDER = async (nonce) => Buffer.from("mock");
|
|
2209
2426
|
var MOCK_AUTH_VERIFIER = async (nonce, credential) => true;
|
|
2210
2427
|
var SpaceProtocol = class {
|
|
2211
2428
|
constructor({ topic, swarmIdentity, networkManager, onSessionAuth, onAuthFailure, blobStore }) {
|
|
2212
2429
|
this._feeds = /* @__PURE__ */ new Set();
|
|
2213
|
-
this._sessions = new import_util8.ComplexMap(
|
|
2430
|
+
this._sessions = new import_util8.ComplexMap(import_keys6.PublicKey.hash);
|
|
2214
2431
|
this._networkManager = networkManager;
|
|
2215
2432
|
this._swarmIdentity = swarmIdentity;
|
|
2216
2433
|
this._onSessionAuth = onSessionAuth;
|
|
@@ -2218,7 +2435,7 @@ var SpaceProtocol = class {
|
|
|
2218
2435
|
this.blobSync = new import_teleport_extension_object_sync.BlobSync({
|
|
2219
2436
|
blobStore
|
|
2220
2437
|
});
|
|
2221
|
-
this._topic = import_crypto3.subtleCrypto.digest("SHA-256", topic.asBuffer()).then(import_crypto3.discoveryKey).then(
|
|
2438
|
+
this._topic = import_crypto3.subtleCrypto.digest("SHA-256", topic.asBuffer()).then(import_crypto3.discoveryKey).then(import_keys6.PublicKey.from);
|
|
2222
2439
|
}
|
|
2223
2440
|
get sessions() {
|
|
2224
2441
|
return this._sessions;
|
|
@@ -2348,7 +2565,7 @@ var SpaceProtocolSession = class {
|
|
|
2348
2565
|
get stream() {
|
|
2349
2566
|
return this._teleport.stream;
|
|
2350
2567
|
}
|
|
2351
|
-
async
|
|
2568
|
+
async open() {
|
|
2352
2569
|
await this._teleport.open();
|
|
2353
2570
|
this._teleport.addExtension("dxos.mesh.teleport.auth", new AuthExtension({
|
|
2354
2571
|
provider: this._swarmIdentity.credentialProvider,
|
|
@@ -2371,9 +2588,18 @@ var SpaceProtocolSession = class {
|
|
|
2371
2588
|
this._teleport.addExtension("dxos.mesh.teleport.replicator", this.replicator);
|
|
2372
2589
|
this._teleport.addExtension("dxos.mesh.teleport.blobsync", this._blobSync.createExtension());
|
|
2373
2590
|
}
|
|
2374
|
-
async
|
|
2591
|
+
async close() {
|
|
2592
|
+
import_log11.log.info("close", void 0, {
|
|
2593
|
+
F: __dxlog_file12,
|
|
2594
|
+
L: 254,
|
|
2595
|
+
S: this,
|
|
2596
|
+
C: (f, a) => f(...a)
|
|
2597
|
+
});
|
|
2375
2598
|
await this._teleport.close();
|
|
2376
2599
|
}
|
|
2600
|
+
async abort() {
|
|
2601
|
+
await this._teleport.abort();
|
|
2602
|
+
}
|
|
2377
2603
|
};
|
|
2378
2604
|
_ts_decorate8([
|
|
2379
2605
|
import_log11.logInfo
|
|
@@ -2393,11 +2619,11 @@ function _ts_decorate9(decorators, target, key, desc) {
|
|
|
2393
2619
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2394
2620
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2395
2621
|
}
|
|
2396
|
-
var __dxlog_file13 = "/
|
|
2622
|
+
var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/echo/echo-pipeline/src/space/space-manager.ts";
|
|
2397
2623
|
var SpaceManager = class SpaceManager2 {
|
|
2398
2624
|
constructor({ feedStore, networkManager, modelFactory, metadataStore, snapshotStore, blobStore }) {
|
|
2399
|
-
this._spaces = new import_util9.ComplexMap(
|
|
2400
|
-
this._instanceId =
|
|
2625
|
+
this._spaces = new import_util9.ComplexMap(import_keys7.PublicKey.hash);
|
|
2626
|
+
this._instanceId = import_keys7.PublicKey.random().toHex();
|
|
2401
2627
|
this._feedStore = feedStore;
|
|
2402
2628
|
this._networkManager = networkManager;
|
|
2403
2629
|
this._modelFactory = modelFactory;
|
|
@@ -2467,13 +2693,13 @@ var SpaceManager = class SpaceManager2 {
|
|
|
2467
2693
|
}
|
|
2468
2694
|
};
|
|
2469
2695
|
_ts_decorate9([
|
|
2470
|
-
|
|
2696
|
+
import_async9.synchronized
|
|
2471
2697
|
], SpaceManager.prototype, "open", null);
|
|
2472
2698
|
_ts_decorate9([
|
|
2473
|
-
|
|
2699
|
+
import_async9.synchronized
|
|
2474
2700
|
], SpaceManager.prototype, "close", null);
|
|
2475
2701
|
SpaceManager = _ts_decorate9([
|
|
2476
|
-
(0,
|
|
2702
|
+
(0, import_async9.trackLeaks)("open", "close")
|
|
2477
2703
|
], SpaceManager);
|
|
2478
2704
|
|
|
2479
2705
|
// packages/core/echo/echo-pipeline/src/testing/test-feed-builder.ts
|
|
@@ -2497,11 +2723,11 @@ var WebsocketNetworkManagerProvider = (signalUrl) => () => new import_network_ma
|
|
|
2497
2723
|
server: signalUrl
|
|
2498
2724
|
}
|
|
2499
2725
|
]),
|
|
2500
|
-
transportFactory: (0, import_network_manager2.
|
|
2726
|
+
transportFactory: (0, import_network_manager2.createSimplePeerTransportFactory)()
|
|
2501
2727
|
});
|
|
2502
2728
|
var TestAgentBuilder = class {
|
|
2503
2729
|
constructor({ storage, networkManagerProvider } = {}) {
|
|
2504
|
-
this._agents = new import_util10.ComplexMap(
|
|
2730
|
+
this._agents = new import_util10.ComplexMap(import_keys8.PublicKey.hash);
|
|
2505
2731
|
this._storage = storage ?? (0, import_random_access_storage.createStorage)({
|
|
2506
2732
|
type: import_random_access_storage.StorageType.RAM
|
|
2507
2733
|
});
|
|
@@ -2540,7 +2766,7 @@ var TestAgent = class {
|
|
|
2540
2766
|
this._feedBuilder = _feedBuilder;
|
|
2541
2767
|
this.identityKey = identityKey;
|
|
2542
2768
|
this.deviceKey = deviceKey;
|
|
2543
|
-
this._spaces = new import_util10.ComplexMap(
|
|
2769
|
+
this._spaces = new import_util10.ComplexMap(import_keys8.PublicKey.hash);
|
|
2544
2770
|
this.modelFactory = new import_model_factory.ModelFactory().registerModel(import_document_model.DocumentModel);
|
|
2545
2771
|
this.storage = this._feedBuilder.storage;
|
|
2546
2772
|
this.keyring = this._feedBuilder.keyring;
|
|
@@ -2660,21 +2886,22 @@ var TestAgent = class {
|
|
|
2660
2886
|
};
|
|
2661
2887
|
|
|
2662
2888
|
// packages/core/echo/echo-pipeline/src/testing/util.ts
|
|
2663
|
-
var
|
|
2889
|
+
var import_async10 = require("@dxos/async");
|
|
2664
2890
|
var import_document_model2 = require("@dxos/document-model");
|
|
2665
2891
|
var import_echo_db4 = require("@dxos/echo-db");
|
|
2666
2892
|
var import_testing2 = require("@dxos/feed-store/testing");
|
|
2667
|
-
var
|
|
2893
|
+
var import_keys9 = require("@dxos/keys");
|
|
2668
2894
|
var import_model_factory2 = require("@dxos/model-factory");
|
|
2669
2895
|
var import_timeframe5 = require("@dxos/timeframe");
|
|
2670
2896
|
var createMemoryDatabase = async (modelFactory) => {
|
|
2671
2897
|
const feed = new import_testing2.MockFeedWriter();
|
|
2672
|
-
const backend = new DatabaseHost(feed)
|
|
2898
|
+
const backend = new DatabaseHost(feed, async () => {
|
|
2899
|
+
});
|
|
2673
2900
|
feed.written.on(([data, meta]) => backend.echoProcessor({
|
|
2674
2901
|
batch: data.batch,
|
|
2675
2902
|
meta: {
|
|
2676
2903
|
...meta,
|
|
2677
|
-
memberKey:
|
|
2904
|
+
memberKey: import_keys9.PublicKey.random(),
|
|
2678
2905
|
timeframe: new import_timeframe5.Timeframe([
|
|
2679
2906
|
[
|
|
2680
2907
|
meta.feedKey,
|
|
@@ -2693,7 +2920,7 @@ var createMemoryDatabase = async (modelFactory) => {
|
|
|
2693
2920
|
var createRemoteDatabaseFromDataServiceHost = async (modelFactory, dataServiceHost) => {
|
|
2694
2921
|
const dataServiceSubscriptions = new DataServiceSubscriptions();
|
|
2695
2922
|
const dataService = new DataServiceImpl(dataServiceSubscriptions);
|
|
2696
|
-
const spaceKey =
|
|
2923
|
+
const spaceKey = import_keys9.PublicKey.random();
|
|
2697
2924
|
await dataServiceSubscriptions.registerSpace(spaceKey, dataServiceHost);
|
|
2698
2925
|
const itemManager = new import_echo_db4.ItemManager(modelFactory);
|
|
2699
2926
|
const backend = new import_echo_db4.DatabaseProxy(dataService, itemManager, spaceKey);
|
|
@@ -2704,7 +2931,7 @@ var createRemoteDatabaseFromDataServiceHost = async (modelFactory, dataServiceHo
|
|
|
2704
2931
|
};
|
|
2705
2932
|
};
|
|
2706
2933
|
var testLocalDatabase = async (create, check = create) => {
|
|
2707
|
-
const objectId =
|
|
2934
|
+
const objectId = import_keys9.PublicKey.random().toHex();
|
|
2708
2935
|
await create.databaseHost.getWriteStream()?.write({
|
|
2709
2936
|
batch: {
|
|
2710
2937
|
objects: [
|
|
@@ -2717,7 +2944,7 @@ var testLocalDatabase = async (create, check = create) => {
|
|
|
2717
2944
|
]
|
|
2718
2945
|
}
|
|
2719
2946
|
});
|
|
2720
|
-
await (0,
|
|
2947
|
+
await (0, import_async10.asyncTimeout)(check.databaseHost._itemDemuxer.mutation.waitForCondition(() => check.itemManager.entities.has(objectId)), 2e3);
|
|
2721
2948
|
};
|
|
2722
2949
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2723
2950
|
0 && (module.exports = {
|