@dxos/client-services 0.4.8-main.ac78619 → 0.4.8-main.beadd4b

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.
@@ -2772,7 +2772,7 @@ var getPlatform = () => {
2772
2772
  };
2773
2773
 
2774
2774
  // packages/sdk/client-services/src/version.ts
2775
- var DXOS_VERSION = "0.4.8-main.ac78619";
2775
+ var DXOS_VERSION = "0.4.8-main.beadd4b";
2776
2776
 
2777
2777
  // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2778
2778
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
@@ -4386,8 +4386,8 @@ import { Context as Context10 } from "@dxos/context";
4386
4386
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4387
4387
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4388
4388
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore, AutomergeHost } from "@dxos/echo-pipeline";
4389
- import { IndexMetadataStore } from "@dxos/echo-schema";
4390
4389
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4390
+ import { IndexMetadataStore, IndexStore, Indexer } from "@dxos/indexing";
4391
4391
  import { invariant as invariant14 } from "@dxos/invariant";
4392
4392
  import { Keyring } from "@dxos/keyring";
4393
4393
  import { PublicKey as PublicKey10 } from "@dxos/keys";
@@ -4397,6 +4397,87 @@ import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/ser
4397
4397
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4398
4398
  import { trace as Trace2 } from "@dxos/tracing";
4399
4399
  import { safeInstanceof } from "@dxos/util";
4400
+
4401
+ // packages/sdk/client-services/src/packlets/indexing/util.ts
4402
+ import { getHeads } from "@dxos/automerge/automerge";
4403
+ import { warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
4404
+ import { idCodec } from "@dxos/protocols";
4405
+ var createLoadDocuments = (automergeHost) => (
4406
+ /**
4407
+ * Get object data blobs from Automerge Repo by ids.
4408
+ * @param ids
4409
+ */
4410
+ // TODO(mykola): Unload automerge handles after usage.
4411
+ async function* loadDocuments(ids) {
4412
+ for (const id of ids) {
4413
+ const { documentId, objectId } = idCodec.decode(id);
4414
+ const handle = automergeHost.repo.find(documentId);
4415
+ await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
4416
+ const doc = handle.docSync();
4417
+ const heads = getHeads(doc);
4418
+ yield [
4419
+ {
4420
+ id,
4421
+ object: doc.objects[objectId],
4422
+ currentHash: heads.at(-1)
4423
+ }
4424
+ ];
4425
+ }
4426
+ }
4427
+ );
4428
+ var createGetAllDocuments = (automergeHost) => (
4429
+ /**
4430
+ * Recursively get all object data blobs from Automerge Repo.
4431
+ * @param ids
4432
+ */
4433
+ // TODO(mykola): Unload automerge handles after usage.
4434
+ async function* getAllDocuments() {
4435
+ const visited = /* @__PURE__ */ new Set();
4436
+ async function* getObjectsFromHandle(handle) {
4437
+ if (visited.has(handle.documentId)) {
4438
+ return;
4439
+ }
4440
+ await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
4441
+ const doc = handle.docSync();
4442
+ const heads = getHeads(doc);
4443
+ if (doc.objects) {
4444
+ yield Object.entries(doc.objects).map(([objectId, object]) => {
4445
+ return {
4446
+ id: idCodec.encode({
4447
+ documentId: handle.documentId,
4448
+ objectId
4449
+ }),
4450
+ object,
4451
+ currentHash: heads.at(-1)
4452
+ };
4453
+ });
4454
+ }
4455
+ if (doc.links) {
4456
+ for (const id of Object.values(doc.links)) {
4457
+ if (visited.has(id)) {
4458
+ continue;
4459
+ }
4460
+ const linkHandle = automergeHost.repo.find(id);
4461
+ for await (const result of getObjectsFromHandle(linkHandle)) {
4462
+ yield result;
4463
+ }
4464
+ }
4465
+ }
4466
+ visited.add(handle.documentId);
4467
+ }
4468
+ for (const handle of Object.values(automergeHost.repo.handles)) {
4469
+ if (visited.has(handle.documentId)) {
4470
+ continue;
4471
+ }
4472
+ for await (const result of getObjectsFromHandle(handle)) {
4473
+ yield result;
4474
+ }
4475
+ visited.add(handle.documentId);
4476
+ }
4477
+ }
4478
+ );
4479
+
4480
+ // packages/sdk/client-services/src/packlets/services/service-context.ts
4400
4481
  function _ts_decorate6(decorators, target, key, desc) {
4401
4482
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4402
4483
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4420,9 +4501,6 @@ var ServiceContext = class {
4420
4501
  this._handlerFactories = /* @__PURE__ */ new Map();
4421
4502
  this._instanceId = PublicKey10.random().toHex();
4422
4503
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
4423
- this.indexMetadata = new IndexMetadataStore({
4424
- directory: storage.createDirectory("index-metadata")
4425
- });
4426
4504
  this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
4427
4505
  this.blobStore = new BlobStore(storage.createDirectory("blobs"));
4428
4506
  this.keyring = new Keyring(storage.createDirectory("keyring"));
@@ -4445,10 +4523,21 @@ var ServiceContext = class {
4445
4523
  snapshotStore: this.snapshotStore
4446
4524
  });
4447
4525
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4526
+ this.indexMetadata = new IndexMetadataStore({
4527
+ directory: storage.createDirectory("index-metadata")
4528
+ });
4448
4529
  this.automergeHost = new AutomergeHost({
4449
4530
  directory: storage.createDirectory("automerge"),
4450
4531
  metadata: this.indexMetadata
4451
4532
  });
4533
+ this.indexer = new Indexer({
4534
+ indexStore: new IndexStore({
4535
+ directory: storage.createDirectory("index-store")
4536
+ }),
4537
+ metadataStore: this.indexMetadata,
4538
+ loadDocuments: createLoadDocuments(this.automergeHost),
4539
+ getAllDocuments: createGetAllDocuments(this.automergeHost)
4540
+ });
4452
4541
  this.invitations = new InvitationsHandler(this.networkManager);
4453
4542
  this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4454
4543
  }
@@ -4456,7 +4545,7 @@ var ServiceContext = class {
4456
4545
  await this._checkStorageVersion();
4457
4546
  log13("opening...", void 0, {
4458
4547
  F: __dxlog_file15,
4459
- L: 152,
4548
+ L: 162,
4460
4549
  S: this,
4461
4550
  C: (f, a) => f(...a)
4462
4551
  });
@@ -4464,7 +4553,7 @@ var ServiceContext = class {
4464
4553
  id: this._instanceId
4465
4554
  }), {
4466
4555
  F: __dxlog_file15,
4467
- L: 153,
4556
+ L: 163,
4468
4557
  S: this,
4469
4558
  C: (f, a) => f(...a)
4470
4559
  });
@@ -4480,13 +4569,13 @@ var ServiceContext = class {
4480
4569
  id: this._instanceId
4481
4570
  }), {
4482
4571
  F: __dxlog_file15,
4483
- L: 163,
4572
+ L: 173,
4484
4573
  S: this,
4485
4574
  C: (f, a) => f(...a)
4486
4575
  });
4487
4576
  log13("opened", void 0, {
4488
4577
  F: __dxlog_file15,
4489
- L: 164,
4578
+ L: 174,
4490
4579
  S: this,
4491
4580
  C: (f, a) => f(...a)
4492
4581
  });
@@ -4494,7 +4583,7 @@ var ServiceContext = class {
4494
4583
  async close() {
4495
4584
  log13("closing...", void 0, {
4496
4585
  F: __dxlog_file15,
4497
- L: 168,
4586
+ L: 178,
4498
4587
  S: this,
4499
4588
  C: (f, a) => f(...a)
4500
4589
  });
@@ -4510,9 +4599,10 @@ var ServiceContext = class {
4510
4599
  await this.signalManager.close();
4511
4600
  this.dataServiceSubscriptions.clear();
4512
4601
  await this.metadataStore.close();
4602
+ await this.indexer.destroy();
4513
4603
  log13("closed", void 0, {
4514
4604
  F: __dxlog_file15,
4515
- L: 181,
4605
+ L: 192,
4516
4606
  S: this,
4517
4607
  C: (f, a) => f(...a)
4518
4608
  });
@@ -4526,7 +4616,7 @@ var ServiceContext = class {
4526
4616
  const factory = this._handlerFactories.get(invitation.kind);
4527
4617
  invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4528
4618
  F: __dxlog_file15,
4529
- L: 192,
4619
+ L: 203,
4530
4620
  S: this,
4531
4621
  A: [
4532
4622
  "factory",
@@ -4558,7 +4648,7 @@ var ServiceContext = class {
4558
4648
  async _initialize(ctx) {
4559
4649
  log13("initializing spaces...", void 0, {
4560
4650
  F: __dxlog_file15,
4561
- L: 223,
4651
+ L: 234,
4562
4652
  S: this,
4563
4653
  C: (f, a) => f(...a)
4564
4654
  });
@@ -4581,7 +4671,7 @@ var ServiceContext = class {
4581
4671
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4582
4672
  invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4583
4673
  F: __dxlog_file15,
4584
- L: 248,
4674
+ L: 259,
4585
4675
  S: this,
4586
4676
  A: [
4587
4677
  "this.dataSpaceManager",
@@ -4605,7 +4695,7 @@ var ServiceContext = class {
4605
4695
  details: assertion
4606
4696
  }, {
4607
4697
  F: __dxlog_file15,
4608
- L: 264,
4698
+ L: 275,
4609
4699
  S: this,
4610
4700
  C: (f, a) => f(...a)
4611
4701
  });
@@ -4616,7 +4706,7 @@ var ServiceContext = class {
4616
4706
  details: assertion
4617
4707
  }, {
4618
4708
  F: __dxlog_file15,
4619
- L: 268,
4709
+ L: 279,
4620
4710
  S: this,
4621
4711
  C: (f, a) => f(...a)
4622
4712
  });
@@ -4627,7 +4717,7 @@ var ServiceContext = class {
4627
4717
  details: assertion
4628
4718
  }, {
4629
4719
  F: __dxlog_file15,
4630
- L: 273,
4720
+ L: 284,
4631
4721
  S: this,
4632
4722
  C: (f, a) => f(...a)
4633
4723
  });
@@ -4638,7 +4728,7 @@ var ServiceContext = class {
4638
4728
  } catch (err) {
4639
4729
  log13.catch(err, void 0, {
4640
4730
  F: __dxlog_file15,
4641
- L: 279,
4731
+ L: 290,
4642
4732
  S: this,
4643
4733
  C: (f, a) => f(...a)
4644
4734
  });
@@ -4863,6 +4953,7 @@ import { Context as Context11 } from "@dxos/context";
4863
4953
  import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4864
4954
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4865
4955
  import { getRawDoc, getAutomergeObjectCore } from "@dxos/echo-schema";
4956
+ import { IndexServiceImpl } from "@dxos/indexing";
4866
4957
  import { invariant as invariant16 } from "@dxos/invariant";
4867
4958
  import { PublicKey as PublicKey12 } from "@dxos/keys";
4868
4959
  import { log as log16 } from "@dxos/log";
@@ -5275,7 +5366,7 @@ var ClientServicesHost = class {
5275
5366
  initialize({ config, ...options }) {
5276
5367
  invariant16(!this._open, "service host is open", {
5277
5368
  F: __dxlog_file18,
5278
- L: 190,
5369
+ L: 191,
5279
5370
  S: this,
5280
5371
  A: [
5281
5372
  "!this._open",
@@ -5284,14 +5375,14 @@ var ClientServicesHost = class {
5284
5375
  });
5285
5376
  log16("initializing...", void 0, {
5286
5377
  F: __dxlog_file18,
5287
- L: 191,
5378
+ L: 192,
5288
5379
  S: this,
5289
5380
  C: (f, a) => f(...a)
5290
5381
  });
5291
5382
  if (config) {
5292
5383
  invariant16(!this._config, "config already set", {
5293
5384
  F: __dxlog_file18,
5294
- L: 194,
5385
+ L: 195,
5295
5386
  S: this,
5296
5387
  A: [
5297
5388
  "!this._config",
@@ -5309,7 +5400,7 @@ var ClientServicesHost = class {
5309
5400
  this._signalManager = signalManager;
5310
5401
  invariant16(!this._networkManager, "network manager already set", {
5311
5402
  F: __dxlog_file18,
5312
- L: 210,
5403
+ L: 211,
5313
5404
  S: this,
5314
5405
  A: [
5315
5406
  "!this._networkManager",
@@ -5323,7 +5414,7 @@ var ClientServicesHost = class {
5323
5414
  });
5324
5415
  log16("initialized", void 0, {
5325
5416
  F: __dxlog_file18,
5326
- L: 217,
5417
+ L: 218,
5327
5418
  S: this,
5328
5419
  C: (f, a) => f(...a)
5329
5420
  });
@@ -5337,13 +5428,13 @@ var ClientServicesHost = class {
5337
5428
  id: traceId
5338
5429
  }), {
5339
5430
  F: __dxlog_file18,
5340
- L: 228,
5431
+ L: 229,
5341
5432
  S: this,
5342
5433
  C: (f, a) => f(...a)
5343
5434
  });
5344
5435
  invariant16(this._config, "config not set", {
5345
5436
  F: __dxlog_file18,
5346
- L: 230,
5437
+ L: 231,
5347
5438
  S: this,
5348
5439
  A: [
5349
5440
  "this._config",
@@ -5352,7 +5443,7 @@ var ClientServicesHost = class {
5352
5443
  });
5353
5444
  invariant16(this._storage, "storage not set", {
5354
5445
  F: __dxlog_file18,
5355
- L: 231,
5446
+ L: 232,
5356
5447
  S: this,
5357
5448
  A: [
5358
5449
  "this._storage",
@@ -5361,7 +5452,7 @@ var ClientServicesHost = class {
5361
5452
  });
5362
5453
  invariant16(this._signalManager, "signal manager not set", {
5363
5454
  F: __dxlog_file18,
5364
- L: 232,
5455
+ L: 233,
5365
5456
  S: this,
5366
5457
  A: [
5367
5458
  "this._signalManager",
@@ -5370,7 +5461,7 @@ var ClientServicesHost = class {
5370
5461
  });
5371
5462
  invariant16(this._networkManager, "network manager not set", {
5372
5463
  F: __dxlog_file18,
5373
- L: 233,
5464
+ L: 234,
5374
5465
  S: this,
5375
5466
  A: [
5376
5467
  "this._networkManager",
@@ -5382,7 +5473,7 @@ var ClientServicesHost = class {
5382
5473
  lockKey: this._resourceLock?.lockKey
5383
5474
  }, {
5384
5475
  F: __dxlog_file18,
5385
- L: 236,
5476
+ L: 237,
5386
5477
  S: this,
5387
5478
  C: (f, a) => f(...a)
5388
5479
  });
@@ -5399,6 +5490,10 @@ var ClientServicesHost = class {
5399
5490
  return this._serviceContext.dataSpaceManager;
5400
5491
  }),
5401
5492
  DataService: new DataServiceImpl(this._serviceContext.dataServiceSubscriptions, this._serviceContext.automergeHost),
5493
+ IndexService: new IndexServiceImpl({
5494
+ indexer: this._serviceContext.indexer,
5495
+ automergeHost: this._serviceContext.automergeHost
5496
+ }),
5402
5497
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5403
5498
  LoggingService: this._loggingService,
5404
5499
  TracingService: this._tracingService,
@@ -5412,7 +5507,7 @@ var ClientServicesHost = class {
5412
5507
  await this._serviceContext.open(ctx);
5413
5508
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5414
5509
  F: __dxlog_file18,
5415
- L: 297,
5510
+ L: 303,
5416
5511
  S: this,
5417
5512
  A: [
5418
5513
  "this.serviceRegistry.services.InvitationsService",
@@ -5424,7 +5519,7 @@ var ClientServicesHost = class {
5424
5519
  count: loadedInvitations.invitations?.length
5425
5520
  }, {
5426
5521
  F: __dxlog_file18,
5427
- L: 300,
5522
+ L: 306,
5428
5523
  S: this,
5429
5524
  C: (f, a) => f(...a)
5430
5525
  });
@@ -5446,7 +5541,7 @@ var ClientServicesHost = class {
5446
5541
  deviceKey
5447
5542
  }, {
5448
5543
  F: __dxlog_file18,
5449
- L: 317,
5544
+ L: 323,
5450
5545
  S: this,
5451
5546
  C: (f, a) => f(...a)
5452
5547
  });
@@ -5454,7 +5549,7 @@ var ClientServicesHost = class {
5454
5549
  id: traceId
5455
5550
  }), {
5456
5551
  F: __dxlog_file18,
5457
- L: 318,
5552
+ L: 324,
5458
5553
  S: this,
5459
5554
  C: (f, a) => f(...a)
5460
5555
  });
@@ -5468,7 +5563,7 @@ var ClientServicesHost = class {
5468
5563
  deviceKey
5469
5564
  }, {
5470
5565
  F: __dxlog_file18,
5471
- L: 329,
5566
+ L: 335,
5472
5567
  S: this,
5473
5568
  C: (f, a) => f(...a)
5474
5569
  });
@@ -5484,7 +5579,7 @@ var ClientServicesHost = class {
5484
5579
  deviceKey
5485
5580
  }, {
5486
5581
  F: __dxlog_file18,
5487
- L: 336,
5582
+ L: 342,
5488
5583
  S: this,
5489
5584
  C: (f, a) => f(...a)
5490
5585
  });
@@ -5495,13 +5590,13 @@ var ClientServicesHost = class {
5495
5590
  id: traceId
5496
5591
  }), {
5497
5592
  F: __dxlog_file18,
5498
- L: 341,
5593
+ L: 347,
5499
5594
  S: this,
5500
5595
  C: (f, a) => f(...a)
5501
5596
  });
5502
5597
  log16("resetting...", void 0, {
5503
5598
  F: __dxlog_file18,
5504
- L: 343,
5599
+ L: 349,
5505
5600
  S: this,
5506
5601
  C: (f, a) => f(...a)
5507
5602
  });
@@ -5509,7 +5604,7 @@ var ClientServicesHost = class {
5509
5604
  await this._storage.reset();
5510
5605
  log16("reset", void 0, {
5511
5606
  F: __dxlog_file18,
5512
- L: 346,
5607
+ L: 352,
5513
5608
  S: this,
5514
5609
  C: (f, a) => f(...a)
5515
5610
  });
@@ -5517,7 +5612,7 @@ var ClientServicesHost = class {
5517
5612
  id: traceId
5518
5613
  }), {
5519
5614
  F: __dxlog_file18,
5520
- L: 347,
5615
+ L: 353,
5521
5616
  S: this,
5522
5617
  C: (f, a) => f(...a)
5523
5618
  });
@@ -5532,7 +5627,7 @@ var ClientServicesHost = class {
5532
5627
  const automergeIndex = space.automergeSpaceState.rootUrl;
5533
5628
  invariant16(automergeIndex, void 0, {
5534
5629
  F: __dxlog_file18,
5535
- L: 362,
5630
+ L: 368,
5536
5631
  S: this,
5537
5632
  A: [
5538
5633
  "automergeIndex",
@@ -5603,4 +5698,4 @@ export {
5603
5698
  createDefaultModelFactory,
5604
5699
  ClientServicesHost
5605
5700
  };
5606
- //# sourceMappingURL=chunk-5DNT7O4B.mjs.map
5701
+ //# sourceMappingURL=chunk-C75D5PB3.mjs.map