@dxos/echo-pipeline 0.3.3-main.44bdbf7 → 0.3.3-main.619fab4

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.
@@ -91,7 +91,6 @@ var createMappedFeedWriter = (mapper, writer) => {
91
91
  };
92
92
 
93
93
  // packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts
94
- var import_async = require("@dxos/async");
95
94
  var import_codec_protobuf = require("@dxos/codec-protobuf");
96
95
  var import_context = require("@dxos/context");
97
96
  var import_echo_db = require("@dxos/echo-db");
@@ -100,14 +99,12 @@ var import_log = require("@dxos/log");
100
99
  var import_service = require("@dxos/protocols/proto/dxos/echo/service");
101
100
  var import_util = require("@dxos/util");
102
101
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/db-host/data-service-host.ts";
103
- var MUTATION_LIMIT_PER_OBJECT = 10;
104
102
  var DataServiceHost = class {
105
- constructor(_itemManager, _itemDemuxer, _flush, _writeStream, _opts = {}) {
103
+ constructor(_itemManager, _itemDemuxer, _flush, _writeStream) {
106
104
  this._itemManager = _itemManager;
107
105
  this._itemDemuxer = _itemDemuxer;
108
106
  this._flush = _flush;
109
107
  this._writeStream = _writeStream;
110
- this._opts = _opts;
111
108
  this._ctx = new import_context.Context();
112
109
  this._clientTagMap = new import_util.ComplexMap(([feedKey, seq]) => `${feedKey.toHex()}:${seq}`);
113
110
  }
@@ -116,9 +113,6 @@ var DataServiceHost = class {
116
113
  async close() {
117
114
  await this._ctx.dispose();
118
115
  }
119
- get _deferEvents() {
120
- return this._opts.deferEvents ?? true;
121
- }
122
116
  /**
123
117
  * Real-time subscription to data objects in a space.
124
118
  */
@@ -131,43 +125,7 @@ var DataServiceHost = class {
131
125
  objects
132
126
  }
133
127
  });
134
- const updateScheduler = new import_async.UpdateScheduler(ctx, async () => {
135
- flushPendingUpdate();
136
- }, {
137
- maxFrequency: 10
138
- });
139
- const pendingUpdates = [];
140
- const mutationsPerObject = /* @__PURE__ */ new Map();
141
- const clearPendingUpdates = () => {
142
- pendingUpdates.length = 0;
143
- mutationsPerObject.clear();
144
- };
145
- const flushPendingUpdate = () => {
146
- const stagedEvents = [];
147
- const objectsWithSnapshots = /* @__PURE__ */ new Set();
148
- for (const [id, count] of mutationsPerObject) {
149
- if (count >= MUTATION_LIMIT_PER_OBJECT) {
150
- objectsWithSnapshots.add(id);
151
- const entity = this._itemManager.entities.get(id);
152
- if (entity) {
153
- stagedEvents.push(entity.createSnapshot());
154
- }
155
- }
156
- }
157
- for (const obj of pendingUpdates) {
158
- if (!objectsWithSnapshots.has(obj.objectId)) {
159
- stagedEvents.push(obj);
160
- }
161
- }
162
- next({
163
- batch: {
164
- objects: stagedEvents
165
- }
166
- });
167
- clearPendingUpdates();
168
- };
169
128
  this._itemDemuxer.snapshot.on(ctx, (snapshot) => {
170
- clearPendingUpdates();
171
129
  next({
172
130
  action: import_service.EchoEvent.DatabaseAction.RESET,
173
131
  batch: {
@@ -179,7 +137,7 @@ var DataServiceHost = class {
179
137
  const { batch, meta } = message;
180
138
  (0, import_invariant2.invariant)(!meta.clientTag, "Unexpected client tag in mutation message", {
181
139
  F: __dxlog_file2,
182
- L: 131,
140
+ L: 69,
183
141
  S: this,
184
142
  A: [
185
143
  "!(meta as any).clientTag",
@@ -191,7 +149,7 @@ var DataServiceHost = class {
191
149
  meta
192
150
  }, {
193
151
  F: __dxlog_file2,
194
- L: 132,
152
+ L: 70,
195
153
  S: this,
196
154
  C: (f, a) => f(...a)
197
155
  });
@@ -205,37 +163,21 @@ var DataServiceHost = class {
205
163
  });
206
164
  });
207
165
  if (clientTag) {
208
- flushPendingUpdate();
209
166
  (0, import_echo_db.tagMutationsInBatch)(batch, clientTag, 0);
210
- next({
211
- clientTag,
212
- feedKey: message.meta.feedKey,
213
- seq: message.meta.seq,
214
- batch
215
- });
216
- } else {
217
- for (const obj of batch.objects ?? []) {
218
- const newCount = (mutationsPerObject.get(obj.objectId) ?? 0) + 1;
219
- mutationsPerObject.set(obj.objectId, newCount);
220
- }
221
- for (const obj of batch.objects ?? []) {
222
- if ((mutationsPerObject.get(obj.objectId) ?? 0) < MUTATION_LIMIT_PER_OBJECT) {
223
- pendingUpdates.push(obj);
224
- }
225
- }
226
- if (this._deferEvents) {
227
- updateScheduler.trigger();
228
- } else {
229
- flushPendingUpdate();
230
- }
231
167
  }
168
+ next({
169
+ clientTag,
170
+ feedKey: message.meta.feedKey,
171
+ seq: message.meta.seq,
172
+ batch
173
+ });
232
174
  });
233
175
  });
234
176
  }
235
177
  async write(request) {
236
178
  (0, import_invariant2.invariant)(!this._ctx.disposed, "Cannot write to closed DataServiceHost", {
237
179
  F: __dxlog_file2,
238
- L: 177,
180
+ L: 96,
239
181
  S: this,
240
182
  A: [
241
183
  "!this._ctx.disposed",
@@ -244,7 +186,7 @@ var DataServiceHost = class {
244
186
  });
245
187
  (0, import_invariant2.invariant)(this._writeStream, "Cannot write mutations in readonly mode", {
246
188
  F: __dxlog_file2,
247
- L: 178,
189
+ L: 97,
248
190
  S: this,
249
191
  A: [
250
192
  "this._writeStream",
@@ -256,7 +198,7 @@ var DataServiceHost = class {
256
198
  objectCount: request.batch.objects?.length ?? 0
257
199
  }, {
258
200
  F: __dxlog_file2,
259
- L: 180,
201
+ L: 99,
260
202
  S: this,
261
203
  C: (f, a) => f(...a)
262
204
  });
@@ -270,7 +212,7 @@ var DataServiceHost = class {
270
212
  seq: receipt2.seq
271
213
  }, {
272
214
  F: __dxlog_file2,
273
- L: 189,
215
+ L: 108,
274
216
  S: this,
275
217
  C: (f, a) => f(...a)
276
218
  });
@@ -327,8 +269,8 @@ var DatabaseHost = class {
327
269
  createSnapshot() {
328
270
  return this._itemDemuxer.createSnapshot();
329
271
  }
330
- createDataServiceHost(opts = {}) {
331
- return new DataServiceHost(this._itemManager, this._itemDemuxer, this._flush, this._outboundStream ?? void 0, opts);
272
+ createDataServiceHost() {
273
+ return new DataServiceHost(this._itemManager, this._itemDemuxer, this._flush, this._outboundStream ?? void 0);
332
274
  }
333
275
  };
334
276
 
@@ -521,7 +463,7 @@ var DataServiceImpl = class {
521
463
 
522
464
  // packages/core/echo/echo-pipeline/src/metadata/metadata-store.ts
523
465
  var import_crc_32 = __toESM(require("crc-32"));
524
- var import_async2 = require("@dxos/async");
466
+ var import_async = require("@dxos/async");
525
467
  var import_invariant4 = require("@dxos/invariant");
526
468
  var import_keys3 = require("@dxos/keys");
527
469
  var import_log3 = require("@dxos/log");
@@ -554,7 +496,7 @@ var MetadataStore = class {
554
496
  this._metadata = emptyEchoMetadata();
555
497
  this._spaceLargeMetadata = new import_util3.ComplexMap(import_keys3.PublicKey.hash);
556
498
  this._metadataFile = void 0;
557
- this.update = new import_async2.Event();
499
+ this.update = new import_async.Event();
558
500
  }
559
501
  get metadata() {
560
502
  return this._metadata;
@@ -813,18 +755,18 @@ var MetadataStore = class {
813
755
  }
814
756
  };
815
757
  _ts_decorate([
816
- import_async2.synchronized
758
+ import_async.synchronized
817
759
  ], MetadataStore.prototype, "load", null);
818
760
  _ts_decorate([
819
- import_async2.synchronized
761
+ import_async.synchronized
820
762
  ], MetadataStore.prototype, "_save", null);
821
763
  _ts_decorate([
822
- import_async2.synchronized
764
+ import_async.synchronized
823
765
  ], MetadataStore.prototype, "_saveSpaceLargeMetadata", null);
824
766
  var fromBytesInt32 = (buf) => buf.readInt32LE(0);
825
767
 
826
768
  // packages/core/echo/echo-pipeline/src/pipeline/pipeline.ts
827
- var import_async4 = require("@dxos/async");
769
+ var import_async3 = require("@dxos/async");
828
770
  var import_context3 = require("@dxos/context");
829
771
  var import_debug3 = require("@dxos/debug");
830
772
  var import_feed_store = require("@dxos/feed-store");
@@ -865,7 +807,7 @@ var createMessageSelector = (timeframeClock) => {
865
807
  };
866
808
 
867
809
  // packages/core/echo/echo-pipeline/src/pipeline/timeframe-clock.ts
868
- var import_async3 = require("@dxos/async");
810
+ var import_async2 = require("@dxos/async");
869
811
  var import_debug2 = require("@dxos/debug");
870
812
  var import_log5 = require("@dxos/log");
871
813
  var import_timeframe = require("@dxos/timeframe");
@@ -895,7 +837,7 @@ var startAfter = (timeframe) => timeframe.frames().map(([feedKey, index]) => ({
895
837
  var TimeframeClock = class {
896
838
  constructor(_timeframe = new import_timeframe.Timeframe()) {
897
839
  this._timeframe = _timeframe;
898
- this.update = new import_async3.Event();
840
+ this.update = new import_async2.Event();
899
841
  this._pendingTimeframe = _timeframe;
900
842
  }
901
843
  /**
@@ -979,7 +921,7 @@ var PipelineState = class {
979
921
  this._timeframeClock = _timeframeClock;
980
922
  this._ctx = new import_context3.Context();
981
923
  this.timeframeUpdate = this._timeframeClock.update;
982
- this.stalled = new import_async4.Event();
924
+ this.stalled = new import_async3.Event();
983
925
  this._startTimeframe = new import_timeframe2.Timeframe();
984
926
  this._reachedTarget = false;
985
927
  }
@@ -1053,7 +995,7 @@ var PipelineState = class {
1053
995
  done = true;
1054
996
  this._reachedTarget = true;
1055
997
  }),
1056
- (0, import_async4.sleepWithContext)(this._ctx, timeout).then(() => {
998
+ (0, import_async3.sleepWithContext)(this._ctx, timeout).then(() => {
1057
999
  if (done) {
1058
1000
  return;
1059
1001
  }
@@ -1082,8 +1024,8 @@ var Pipeline = class {
1082
1024
  // External state accessor.
1083
1025
  this._state = new PipelineState(this._feeds, this._timeframeClock);
1084
1026
  // Waits for the message consumer to process the message and yield control back to the pipeline.
1085
- this._processingTrigger = new import_async4.Trigger().wake();
1086
- this._pauseTrigger = new import_async4.Trigger().wake();
1027
+ this._processingTrigger = new import_async3.Trigger().wake();
1028
+ this._pauseTrigger = new import_async3.Trigger().wake();
1087
1029
  // Pending downloads.
1088
1030
  this._downloads = new import_util4.ComplexMap((value) => import_keys4.PublicKey.hash(value.key));
1089
1031
  this._isStopping = false;
@@ -1361,23 +1303,23 @@ var Pipeline = class {
1361
1303
  }
1362
1304
  };
1363
1305
  _ts_decorate3([
1364
- import_async4.synchronized
1306
+ import_async3.synchronized
1365
1307
  ], Pipeline.prototype, "start", null);
1366
1308
  _ts_decorate3([
1367
- import_async4.synchronized
1309
+ import_async3.synchronized
1368
1310
  ], Pipeline.prototype, "stop", null);
1369
1311
  _ts_decorate3([
1370
- import_async4.synchronized
1312
+ import_async3.synchronized
1371
1313
  ], Pipeline.prototype, "setCursor", null);
1372
1314
  _ts_decorate3([
1373
- import_async4.synchronized
1315
+ import_async3.synchronized
1374
1316
  ], Pipeline.prototype, "pause", null);
1375
1317
  _ts_decorate3([
1376
- import_async4.synchronized
1318
+ import_async3.synchronized
1377
1319
  ], Pipeline.prototype, "unpause", null);
1378
1320
 
1379
1321
  // packages/core/echo/echo-pipeline/src/space/auth.ts
1380
- var import_async5 = require("@dxos/async");
1322
+ var import_async4 = require("@dxos/async");
1381
1323
  var import_context4 = require("@dxos/context");
1382
1324
  var import_crypto2 = require("@dxos/crypto");
1383
1325
  var import_invariant7 = require("@dxos/invariant");
@@ -1435,7 +1377,7 @@ var AuthExtension = class extends import_teleport.RpcExtension {
1435
1377
  }
1436
1378
  async onOpen(context) {
1437
1379
  await super.onOpen(context);
1438
- (0, import_async5.scheduleTask)(this._ctx, async () => {
1380
+ (0, import_async4.scheduleTask)(this._ctx, async () => {
1439
1381
  try {
1440
1382
  const challenge = (0, import_crypto2.randomBytes)(32);
1441
1383
  const { credential } = await this.rpc.AuthService.authenticate({
@@ -1460,7 +1402,7 @@ var AuthExtension = class extends import_teleport.RpcExtension {
1460
1402
  "'credential not verified'"
1461
1403
  ]
1462
1404
  });
1463
- (0, import_async5.runInContext)(this._ctx, () => this._authParams.onAuthSuccess());
1405
+ (0, import_async4.runInContext)(this._ctx, () => this._authParams.onAuthSuccess());
1464
1406
  } catch (err) {
1465
1407
  (0, import_log7.log)("auth failed", err, {
1466
1408
  F: __dxlog_file8,
@@ -1484,7 +1426,7 @@ var AuthExtension = class extends import_teleport.RpcExtension {
1484
1426
  };
1485
1427
 
1486
1428
  // packages/core/echo/echo-pipeline/src/space/space.ts
1487
- var import_async8 = require("@dxos/async");
1429
+ var import_async7 = require("@dxos/async");
1488
1430
  var import_invariant9 = require("@dxos/invariant");
1489
1431
  var import_log10 = require("@dxos/log");
1490
1432
  var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
@@ -1492,7 +1434,7 @@ var import_tracing3 = require("@dxos/tracing");
1492
1434
  var import_util7 = require("@dxos/util");
1493
1435
 
1494
1436
  // packages/core/echo/echo-pipeline/src/space/control-pipeline.ts
1495
- var import_async6 = require("@dxos/async");
1437
+ var import_async5 = require("@dxos/async");
1496
1438
  var import_context5 = require("@dxos/context");
1497
1439
  var import_credentials = require("@dxos/credentials");
1498
1440
  var import_keys5 = require("@dxos/keys");
@@ -1522,8 +1464,8 @@ var ControlPipeline = class ControlPipeline2 {
1522
1464
  this.onFeedAdmitted = new import_util5.Callback();
1523
1465
  this._usage = new import_tracing.TimeUsageCounter();
1524
1466
  this._mutations = new import_tracing.TimeSeriesCounter();
1525
- this._snapshotTask = new import_async6.DeferredTask(this._ctx, async () => {
1526
- await (0, import_async6.sleepWithContext)(this._ctx, CONTROL_PIPELINE_SNAPSHOT_DELAY);
1467
+ this._snapshotTask = new import_async5.DeferredTask(this._ctx, async () => {
1468
+ await (0, import_async5.sleepWithContext)(this._ctx, CONTROL_PIPELINE_SNAPSHOT_DELAY);
1527
1469
  await this._saveSnapshot();
1528
1470
  });
1529
1471
  this._spaceKey = spaceKey;
@@ -1746,11 +1688,11 @@ _ts_decorate4([
1746
1688
  ], ControlPipeline.prototype, "_processMessage", null);
1747
1689
  ControlPipeline = _ts_decorate4([
1748
1690
  import_tracing.trace.resource(),
1749
- (0, import_async6.trackLeaks)("start", "stop")
1691
+ (0, import_async5.trackLeaks)("start", "stop")
1750
1692
  ], ControlPipeline);
1751
1693
 
1752
1694
  // packages/core/echo/echo-pipeline/src/space/data-pipeline.ts
1753
- var import_async7 = require("@dxos/async");
1695
+ var import_async6 = require("@dxos/async");
1754
1696
  var import_context6 = require("@dxos/context");
1755
1697
  var import_credentials3 = require("@dxos/credentials");
1756
1698
  var import_echo_db3 = require("@dxos/echo-db");
@@ -1789,7 +1731,7 @@ var DataPipeline = class DataPipeline2 {
1789
1731
  this._mutations = new import_tracing2.TimeSeriesCounter();
1790
1732
  this.currentEpoch = void 0;
1791
1733
  this.appliedEpoch = void 0;
1792
- this.onNewEpoch = new import_async7.Event();
1734
+ this.onNewEpoch = new import_async6.Event();
1793
1735
  }
1794
1736
  get isOpen() {
1795
1737
  return this._isOpen;
@@ -1852,7 +1794,7 @@ var DataPipeline = class DataPipeline2 {
1852
1794
  this.databaseHost = new DatabaseHost(feedWriter, () => this._flush());
1853
1795
  this.itemManager = new import_echo_db3.ItemManager(this._params.modelFactory);
1854
1796
  await this.databaseHost.open(this.itemManager, this._params.modelFactory);
1855
- (0, import_async7.scheduleTask)(this._ctx, async () => {
1797
+ (0, import_async6.scheduleTask)(this._ctx, async () => {
1856
1798
  await this._consumePipeline();
1857
1799
  });
1858
1800
  this._isOpen = true;
@@ -1971,7 +1913,7 @@ var DataPipeline = class DataPipeline2 {
1971
1913
  span.end();
1972
1914
  if (++messageCounter > 1e3) {
1973
1915
  messageCounter = 0;
1974
- await (0, import_async7.sleep)(1);
1916
+ await (0, import_async6.sleep)(1);
1975
1917
  }
1976
1918
  }
1977
1919
  }
@@ -2051,7 +1993,7 @@ var DataPipeline = class DataPipeline2 {
2051
1993
  }
2052
1994
  });
2053
1995
  this._epochCtx = ctx;
2054
- (0, import_async7.scheduleTask)(ctx, async () => {
1996
+ (0, import_async6.scheduleTask)(ctx, async () => {
2055
1997
  if (!this._isOpen) {
2056
1998
  return;
2057
1999
  }
@@ -2172,19 +2114,19 @@ _ts_decorate5([
2172
2114
  import_tracing2.trace.metricsCounter()
2173
2115
  ], DataPipeline.prototype, "_mutations", void 0);
2174
2116
  _ts_decorate5([
2175
- import_async7.synchronized
2117
+ import_async6.synchronized
2176
2118
  ], DataPipeline.prototype, "open", null);
2177
2119
  _ts_decorate5([
2178
- import_async7.synchronized
2120
+ import_async6.synchronized
2179
2121
  ], DataPipeline.prototype, "close", null);
2180
2122
  _ts_decorate5([
2181
- import_async7.synchronized
2123
+ import_async6.synchronized
2182
2124
  ], DataPipeline.prototype, "_processEpoch", null);
2183
2125
  _ts_decorate5([
2184
- import_async7.synchronized
2126
+ import_async6.synchronized
2185
2127
  ], DataPipeline.prototype, "createEpoch", null);
2186
2128
  DataPipeline = _ts_decorate5([
2187
- (0, import_async7.trackLeaks)("open", "close"),
2129
+ (0, import_async6.trackLeaks)("open", "close"),
2188
2130
  import_tracing2.trace.resource()
2189
2131
  ], DataPipeline);
2190
2132
 
@@ -2202,9 +2144,9 @@ function _ts_decorate6(decorators, target, key, desc) {
2202
2144
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/echo/echo-pipeline/src/space/space.ts";
2203
2145
  var Space = class Space2 {
2204
2146
  constructor(params) {
2205
- this._addFeedLock = new import_async8.Lock();
2147
+ this._addFeedLock = new import_async7.Lock();
2206
2148
  this.onCredentialProcessed = new import_util7.Callback();
2207
- this.stateUpdate = new import_async8.Event();
2149
+ this.stateUpdate = new import_async7.Event();
2208
2150
  this._isOpen = false;
2209
2151
  (0, import_invariant9.invariant)(params.spaceKey && params.feedProvider, void 0, {
2210
2152
  F: __dxlog_file11,
@@ -2423,22 +2365,22 @@ _ts_decorate6([
2423
2365
  import_tracing3.trace.info()
2424
2366
  ], Space.prototype, "key", null);
2425
2367
  _ts_decorate6([
2426
- import_async8.synchronized,
2368
+ import_async7.synchronized,
2427
2369
  import_tracing3.trace.span()
2428
2370
  ], Space.prototype, "open", null);
2429
2371
  _ts_decorate6([
2430
- import_async8.synchronized
2372
+ import_async7.synchronized
2431
2373
  ], Space.prototype, "close", null);
2432
2374
  _ts_decorate6([
2433
- import_async8.synchronized
2375
+ import_async7.synchronized
2434
2376
  ], Space.prototype, "initializeDataPipeline", null);
2435
2377
  Space = _ts_decorate6([
2436
- (0, import_async8.trackLeaks)("open", "close"),
2378
+ (0, import_async7.trackLeaks)("open", "close"),
2437
2379
  import_tracing3.trace.resource()
2438
2380
  ], Space);
2439
2381
 
2440
2382
  // packages/core/echo/echo-pipeline/src/space/space-manager.ts
2441
- var import_async9 = require("@dxos/async");
2383
+ var import_async8 = require("@dxos/async");
2442
2384
  var import_debug4 = require("@dxos/debug");
2443
2385
  var import_keys7 = require("@dxos/keys");
2444
2386
  var import_log12 = require("@dxos/log");
@@ -2736,13 +2678,13 @@ var SpaceManager = class SpaceManager2 {
2736
2678
  }
2737
2679
  };
2738
2680
  _ts_decorate8([
2739
- import_async9.synchronized
2681
+ import_async8.synchronized
2740
2682
  ], SpaceManager.prototype, "open", null);
2741
2683
  _ts_decorate8([
2742
- import_async9.synchronized
2684
+ import_async8.synchronized
2743
2685
  ], SpaceManager.prototype, "close", null);
2744
2686
  SpaceManager = _ts_decorate8([
2745
- (0, import_async9.trackLeaks)("open", "close")
2687
+ (0, import_async8.trackLeaks)("open", "close")
2746
2688
  ], SpaceManager);
2747
2689
  // Annotate the CommonJS export names for ESM import in node:
2748
2690
  0 && (module.exports = {