@dxos/client-services 0.4.10-main.fa5a270 → 0.4.10-main.fd4f2a3

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.
Files changed (59) hide show
  1. package/dist/lib/browser/{chunk-7PYX6UUA.mjs → chunk-V2ALN47T.mjs} +202 -89
  2. package/dist/lib/browser/{chunk-7PYX6UUA.mjs.map → chunk-V2ALN47T.mjs.map} +4 -4
  3. package/dist/lib/browser/index.mjs +50 -20
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +6 -4
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-4TX623I7.cjs → chunk-7WXQVUAE.cjs} +200 -92
  9. package/dist/lib/node/chunk-7WXQVUAE.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +87 -57
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +10 -8
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/indexing/util.d.ts +2 -2
  16. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
  17. package/dist/types/src/packlets/services/service-context.d.ts +7 -5
  18. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-host.d.ts +1 -0
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  22. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  23. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  24. package/dist/types/src/packlets/storage/level.d.ts +4 -0
  25. package/dist/types/src/packlets/storage/level.d.ts.map +1 -0
  26. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  27. package/dist/types/src/packlets/storage/util.d.ts +4 -0
  28. package/dist/types/src/packlets/storage/util.d.ts.map +1 -0
  29. package/dist/types/src/packlets/testing/test-builder.d.ts +1 -1
  30. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  31. package/dist/types/src/packlets/vault/shared-worker-connection.d.ts +5 -5
  32. package/dist/types/src/packlets/vault/shared-worker-connection.d.ts.map +1 -1
  33. package/dist/types/src/packlets/vault/worker-runtime.d.ts +2 -0
  34. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  35. package/dist/types/src/packlets/vault/worker-session.d.ts +2 -0
  36. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  37. package/dist/types/src/version.d.ts +1 -1
  38. package/package.json +35 -34
  39. package/src/packlets/devices/devices-service.test.ts +1 -1
  40. package/src/packlets/identity/identity-service.test.ts +1 -1
  41. package/src/packlets/indexing/util.ts +4 -4
  42. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  43. package/src/packlets/network/network-service.test.ts +1 -1
  44. package/src/packlets/services/service-context.test.ts +5 -5
  45. package/src/packlets/services/service-context.ts +13 -8
  46. package/src/packlets/services/service-host.ts +32 -8
  47. package/src/packlets/services/service-registry.test.ts +1 -1
  48. package/src/packlets/spaces/data-space.ts +51 -2
  49. package/src/packlets/spaces/spaces-service.test.ts +1 -1
  50. package/src/packlets/storage/index.ts +1 -0
  51. package/src/packlets/storage/level.ts +19 -0
  52. package/src/packlets/storage/storage.ts +3 -9
  53. package/src/packlets/storage/util.ts +19 -0
  54. package/src/packlets/testing/test-builder.ts +5 -3
  55. package/src/packlets/vault/shared-worker-connection.ts +3 -8
  56. package/src/packlets/vault/worker-runtime.ts +27 -2
  57. package/src/packlets/vault/worker-session.ts +6 -0
  58. package/src/version.ts +1 -1
  59. package/dist/lib/node/chunk-4TX623I7.cjs.map +0 -7
@@ -2769,7 +2769,7 @@ var getPlatform = () => {
2769
2769
  };
2770
2770
 
2771
2771
  // packages/sdk/client-services/src/version.ts
2772
- var DXOS_VERSION = "0.4.10-main.fa5a270";
2772
+ var DXOS_VERSION = "0.4.10-main.fd4f2a3";
2773
2773
 
2774
2774
  // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2775
2775
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
@@ -2885,7 +2885,9 @@ import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as
2885
2885
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2886
2886
  import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
2887
2887
  import { timed, warnAfterTimeout } from "@dxos/debug";
2888
+ import { TYPE_PROPERTIES } from "@dxos/echo-db";
2888
2889
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2890
+ import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
2889
2891
  import { failedInvariant, invariant as invariant11 } from "@dxos/invariant";
2890
2892
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2891
2893
  import { log as log9 } from "@dxos/log";
@@ -2894,7 +2896,7 @@ import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/clien
2894
2896
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2895
2897
  import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2896
2898
  import { trace as trace6 } from "@dxos/tracing";
2897
- import { ComplexSet as ComplexSet3 } from "@dxos/util";
2899
+ import { ComplexSet as ComplexSet3, assignDeep } from "@dxos/util";
2898
2900
 
2899
2901
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
2900
2902
  import { Event as Event4 } from "@dxos/async";
@@ -3249,7 +3251,7 @@ var DataSpace = class {
3249
3251
  state: SpaceState[this._state]
3250
3252
  }, {
3251
3253
  F: __dxlog_file12,
3252
- L: 132,
3254
+ L: 140,
3253
3255
  S: this,
3254
3256
  C: (f, a) => f(...a)
3255
3257
  });
@@ -3299,7 +3301,7 @@ var DataSpace = class {
3299
3301
  state: SpaceState[this._state]
3300
3302
  }, {
3301
3303
  F: __dxlog_file12,
3302
- L: 190,
3304
+ L: 198,
3303
3305
  S: this,
3304
3306
  C: (f, a) => f(...a)
3305
3307
  });
@@ -3317,7 +3319,7 @@ var DataSpace = class {
3317
3319
  state: SpaceState[this._state]
3318
3320
  }, {
3319
3321
  F: __dxlog_file12,
3320
- L: 204,
3322
+ L: 212,
3321
3323
  S: this,
3322
3324
  C: (f, a) => f(...a)
3323
3325
  });
@@ -3349,7 +3351,7 @@ var DataSpace = class {
3349
3351
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3350
3352
  log9("data pipeline initialization cancelled", err, {
3351
3353
  F: __dxlog_file12,
3352
- L: 237,
3354
+ L: 245,
3353
3355
  S: this,
3354
3356
  C: (f, a) => f(...a)
3355
3357
  });
@@ -3357,7 +3359,7 @@ var DataSpace = class {
3357
3359
  }
3358
3360
  log9.error("Error initializing data pipeline", err, {
3359
3361
  F: __dxlog_file12,
3360
- L: 241,
3362
+ L: 249,
3361
3363
  S: this,
3362
3364
  C: (f, a) => f(...a)
3363
3365
  });
@@ -3366,7 +3368,7 @@ var DataSpace = class {
3366
3368
  state: SpaceState[this._state]
3367
3369
  }, {
3368
3370
  F: __dxlog_file12,
3369
- L: 243,
3371
+ L: 251,
3370
3372
  S: this,
3371
3373
  C: (f, a) => f(...a)
3372
3374
  });
@@ -3386,7 +3388,7 @@ var DataSpace = class {
3386
3388
  state: SpaceState[this._state]
3387
3389
  }, {
3388
3390
  F: __dxlog_file12,
3389
- L: 259,
3391
+ L: 267,
3390
3392
  S: this,
3391
3393
  C: (f, a) => f(...a)
3392
3394
  });
@@ -3396,7 +3398,7 @@ var DataSpace = class {
3396
3398
  await cancelWithContext2(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3397
3399
  log9("data pipeline ready", void 0, {
3398
3400
  F: __dxlog_file12,
3399
- L: 271,
3401
+ L: 279,
3400
3402
  S: this,
3401
3403
  C: (f, a) => f(...a)
3402
3404
  });
@@ -3406,7 +3408,7 @@ var DataSpace = class {
3406
3408
  state: SpaceState[this._state]
3407
3409
  }, {
3408
3410
  F: __dxlog_file12,
3409
- L: 275,
3411
+ L: 283,
3410
3412
  S: this,
3411
3413
  C: (f, a) => f(...a)
3412
3414
  });
@@ -3422,7 +3424,7 @@ var DataSpace = class {
3422
3424
  await this._createWritableFeeds();
3423
3425
  log9("writable feeds created", void 0, {
3424
3426
  F: __dxlog_file12,
3425
- L: 291,
3427
+ L: 299,
3426
3428
  S: this,
3427
3429
  C: (f, a) => f(...a)
3428
3430
  });
@@ -3485,7 +3487,7 @@ var DataSpace = class {
3485
3487
  rootUrl
3486
3488
  }, {
3487
3489
  F: __dxlog_file12,
3488
- L: 357,
3490
+ L: 365,
3489
3491
  S: this,
3490
3492
  C: (f, a) => f(...a)
3491
3493
  });
@@ -3517,7 +3519,7 @@ var DataSpace = class {
3517
3519
  err
3518
3520
  }, {
3519
3521
  F: __dxlog_file12,
3520
- L: 380,
3522
+ L: 388,
3521
3523
  S: this,
3522
3524
  C: (f, a) => f(...a)
3523
3525
  });
@@ -3572,7 +3574,7 @@ var DataSpace = class {
3572
3574
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3573
3575
  invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3574
3576
  F: __dxlog_file12,
3575
- L: 430,
3577
+ L: 438,
3576
3578
  S: this,
3577
3579
  A: [
3578
3580
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3587,6 +3589,66 @@ var DataSpace = class {
3587
3589
  };
3588
3590
  }
3589
3591
  break;
3592
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3593
+ {
3594
+ log9.info("Fragmenting", void 0, {
3595
+ F: __dxlog_file12,
3596
+ L: 450,
3597
+ S: this,
3598
+ C: (f, a) => f(...a)
3599
+ });
3600
+ const currentRootUrl = this._automergeSpaceState.rootUrl;
3601
+ const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3602
+ await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3603
+ const objects = Object.entries(rootHandle.docSync().objects);
3604
+ const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
3605
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3606
+ invariant11(properties, "Properties not found", {
3607
+ F: __dxlog_file12,
3608
+ L: 460,
3609
+ S: this,
3610
+ A: [
3611
+ "properties",
3612
+ "'Properties not found'"
3613
+ ]
3614
+ });
3615
+ const newSpaceDoc = {
3616
+ ...rootHandle.docSync(),
3617
+ objects: Object.fromEntries([
3618
+ properties
3619
+ ])
3620
+ };
3621
+ const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3622
+ invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3623
+ F: __dxlog_file12,
3624
+ L: 465,
3625
+ S: this,
3626
+ A: [
3627
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3628
+ ""
3629
+ ]
3630
+ });
3631
+ const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3632
+ await docLoader.loadSpaceRootDocHandle(this._ctx, {
3633
+ rootUrl: newRoot.url
3634
+ });
3635
+ otherObjects.forEach(([key, value]) => {
3636
+ const handle = docLoader.createDocumentForObject(key);
3637
+ handle.change((doc) => {
3638
+ assignDeep(doc, [
3639
+ "objects",
3640
+ key
3641
+ ], value);
3642
+ });
3643
+ });
3644
+ epoch = {
3645
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3646
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3647
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3648
+ automergeRoot: newRoot.url
3649
+ };
3650
+ }
3651
+ break;
3590
3652
  }
3591
3653
  if (!epoch) {
3592
3654
  return;
@@ -3628,7 +3690,7 @@ var DataSpace = class {
3628
3690
  state: SpaceState[this._state]
3629
3691
  }, {
3630
3692
  F: __dxlog_file12,
3631
- L: 482,
3693
+ L: 531,
3632
3694
  S: this,
3633
3695
  C: (f, a) => f(...a)
3634
3696
  });
@@ -4324,7 +4386,7 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4324
4386
 
4325
4387
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4326
4388
  import { Trigger as Trigger5 } from "@dxos/async";
4327
- import { Context as Context10 } from "@dxos/context";
4389
+ import { Context as Context10, Resource } from "@dxos/context";
4328
4390
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4329
4391
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4330
4392
  import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -4344,7 +4406,7 @@ import { safeInstanceof } from "@dxos/util";
4344
4406
  import { getHeads } from "@dxos/automerge/automerge";
4345
4407
  import { warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
4346
4408
  import { idCodec } from "@dxos/protocols";
4347
- var createLoadDocuments = (automergeHost) => (
4409
+ var createSelectedDocumentsIterator = (automergeHost) => (
4348
4410
  /**
4349
4411
  * Get object data blobs from Automerge Repo by ids.
4350
4412
  * @param ids
@@ -4357,17 +4419,17 @@ var createLoadDocuments = (automergeHost) => (
4357
4419
  await warnAfterTimeout2(5e3, "to long to load doc", () => handle.whenReady());
4358
4420
  const doc = handle.docSync();
4359
4421
  const hash = getHeads(doc).join("");
4360
- yield [
4422
+ yield doc.objects?.[objectId] ? [
4361
4423
  {
4362
4424
  id,
4363
4425
  object: doc.objects[objectId],
4364
4426
  currentHash: hash
4365
4427
  }
4366
- ];
4428
+ ] : [];
4367
4429
  }
4368
4430
  }
4369
4431
  );
4370
- var createGetAllDocuments = (automergeHost) => (
4432
+ var createDocumentsIterator = (automergeHost) => (
4371
4433
  /**
4372
4434
  * Recursively get all object data blobs from Automerge Repo.
4373
4435
  * @param ids
@@ -4390,7 +4452,7 @@ var createGetAllDocuments = (automergeHost) => (
4390
4452
  objectId
4391
4453
  }),
4392
4454
  object,
4393
- currentHash: heads.at(-1)
4455
+ currentHash: heads.join("")
4394
4456
  };
4395
4457
  });
4396
4458
  }
@@ -4431,9 +4493,11 @@ function _ts_decorate6(decorators, target, key, desc) {
4431
4493
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4432
4494
  }
4433
4495
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4434
- var ServiceContext = class {
4435
- constructor(storage, networkManager, signalManager, _runtimeParams) {
4496
+ var ServiceContext = class extends Resource {
4497
+ constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4498
+ super();
4436
4499
  this.storage = storage;
4500
+ this.level = level;
4437
4501
  this.networkManager = networkManager;
4438
4502
  this.signalManager = signalManager;
4439
4503
  this._runtimeParams = _runtimeParams;
@@ -4463,7 +4527,7 @@ var ServiceContext = class {
4463
4527
  });
4464
4528
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4465
4529
  this.indexMetadata = new IndexMetadataStore({
4466
- directory: storage.createDirectory("index-metadata")
4530
+ db: level.sublevel("index-metadata")
4467
4531
  });
4468
4532
  this.automergeHost = new AutomergeHost({
4469
4533
  directory: storage.createDirectory("automerge"),
@@ -4474,17 +4538,17 @@ var ServiceContext = class {
4474
4538
  directory: storage.createDirectory("index-store")
4475
4539
  }),
4476
4540
  metadataStore: this.indexMetadata,
4477
- loadDocuments: createLoadDocuments(this.automergeHost),
4478
- getAllDocuments: createGetAllDocuments(this.automergeHost)
4541
+ loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4542
+ getAllDocuments: createDocumentsIterator(this.automergeHost)
4479
4543
  });
4480
4544
  this.invitations = new InvitationsHandler(this.networkManager);
4481
4545
  this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4482
4546
  }
4483
- async open(ctx) {
4547
+ async _open(ctx) {
4484
4548
  await this._checkStorageVersion();
4485
4549
  log12("opening...", void 0, {
4486
4550
  F: __dxlog_file15,
4487
- L: 151,
4551
+ L: 156,
4488
4552
  S: this,
4489
4553
  C: (f, a) => f(...a)
4490
4554
  });
@@ -4492,7 +4556,7 @@ var ServiceContext = class {
4492
4556
  id: this._instanceId
4493
4557
  }), {
4494
4558
  F: __dxlog_file15,
4495
- L: 152,
4559
+ L: 157,
4496
4560
  S: this,
4497
4561
  C: (f, a) => f(...a)
4498
4562
  });
@@ -4508,21 +4572,21 @@ var ServiceContext = class {
4508
4572
  id: this._instanceId
4509
4573
  }), {
4510
4574
  F: __dxlog_file15,
4511
- L: 162,
4575
+ L: 167,
4512
4576
  S: this,
4513
4577
  C: (f, a) => f(...a)
4514
4578
  });
4515
4579
  log12("opened", void 0, {
4516
4580
  F: __dxlog_file15,
4517
- L: 163,
4581
+ L: 168,
4518
4582
  S: this,
4519
4583
  C: (f, a) => f(...a)
4520
4584
  });
4521
4585
  }
4522
- async close() {
4586
+ async _close() {
4523
4587
  log12("closing...", void 0, {
4524
4588
  F: __dxlog_file15,
4525
- L: 167,
4589
+ L: 172,
4526
4590
  S: this,
4527
4591
  C: (f, a) => f(...a)
4528
4592
  });
@@ -4540,7 +4604,7 @@ var ServiceContext = class {
4540
4604
  await this.indexer.destroy();
4541
4605
  log12("closed", void 0, {
4542
4606
  F: __dxlog_file15,
4543
- L: 180,
4607
+ L: 185,
4544
4608
  S: this,
4545
4609
  C: (f, a) => f(...a)
4546
4610
  });
@@ -4554,7 +4618,7 @@ var ServiceContext = class {
4554
4618
  const factory = this._handlerFactories.get(invitation.kind);
4555
4619
  invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4556
4620
  F: __dxlog_file15,
4557
- L: 191,
4621
+ L: 196,
4558
4622
  S: this,
4559
4623
  A: [
4560
4624
  "factory",
@@ -4586,7 +4650,7 @@ var ServiceContext = class {
4586
4650
  async _initialize(ctx) {
4587
4651
  log12("initializing spaces...", void 0, {
4588
4652
  F: __dxlog_file15,
4589
- L: 222,
4653
+ L: 227,
4590
4654
  S: this,
4591
4655
  C: (f, a) => f(...a)
4592
4656
  });
@@ -4609,7 +4673,7 @@ var ServiceContext = class {
4609
4673
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4610
4674
  invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4611
4675
  F: __dxlog_file15,
4612
- L: 246,
4676
+ L: 251,
4613
4677
  S: this,
4614
4678
  A: [
4615
4679
  "this.dataSpaceManager",
@@ -4633,7 +4697,7 @@ var ServiceContext = class {
4633
4697
  details: assertion
4634
4698
  }, {
4635
4699
  F: __dxlog_file15,
4636
- L: 262,
4700
+ L: 267,
4637
4701
  S: this,
4638
4702
  C: (f, a) => f(...a)
4639
4703
  });
@@ -4644,7 +4708,7 @@ var ServiceContext = class {
4644
4708
  details: assertion
4645
4709
  }, {
4646
4710
  F: __dxlog_file15,
4647
- L: 266,
4711
+ L: 271,
4648
4712
  S: this,
4649
4713
  C: (f, a) => f(...a)
4650
4714
  });
@@ -4655,7 +4719,7 @@ var ServiceContext = class {
4655
4719
  details: assertion
4656
4720
  }, {
4657
4721
  F: __dxlog_file15,
4658
- L: 271,
4722
+ L: 276,
4659
4723
  S: this,
4660
4724
  C: (f, a) => f(...a)
4661
4725
  });
@@ -4666,7 +4730,7 @@ var ServiceContext = class {
4666
4730
  } catch (err) {
4667
4731
  log12.catch(err, void 0, {
4668
4732
  F: __dxlog_file15,
4669
- L: 277,
4733
+ L: 282,
4670
4734
  S: this,
4671
4735
  C: (f, a) => f(...a)
4672
4736
  });
@@ -4678,7 +4742,7 @@ var ServiceContext = class {
4678
4742
  };
4679
4743
  _ts_decorate6([
4680
4744
  Trace2.span()
4681
- ], ServiceContext.prototype, "open", null);
4745
+ ], ServiceContext.prototype, "_open", null);
4682
4746
  _ts_decorate6([
4683
4747
  Trace2.span()
4684
4748
  ], ServiceContext.prototype, "_initialize", null);
@@ -4836,14 +4900,27 @@ var isLocked = (lockPath) => {
4836
4900
  };
4837
4901
 
4838
4902
  // packages/sdk/client-services/src/packlets/storage/storage.ts
4839
- import { DX_DATA } from "@dxos/client-protocol";
4840
4903
  import { InvalidConfigError } from "@dxos/protocols";
4841
- import { Runtime } from "@dxos/protocols/proto/dxos/config";
4904
+ import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
4842
4905
  import { createStorage, StorageType } from "@dxos/random-access-storage";
4906
+
4907
+ // packages/sdk/client-services/src/packlets/storage/util.ts
4908
+ import { DX_DATA } from "@dxos/client-protocol";
4909
+ import { Runtime } from "@dxos/protocols/proto/dxos/config";
4843
4910
  import { isNode as isNode2 } from "@dxos/util";
4844
- var StorageDriver = Runtime.Client.Storage.StorageDriver;
4911
+ var getRootPath = (config) => {
4912
+ const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4913
+ return `${dataRoot}/`;
4914
+ };
4915
+ var isPersistent = (config) => {
4916
+ const { persistent = false } = config ?? {};
4917
+ return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
4918
+ };
4919
+
4920
+ // packages/sdk/client-services/src/packlets/storage/storage.ts
4921
+ var StorageDriver = Runtime2.Client.Storage.StorageDriver;
4845
4922
  var createStorageObjects = (config) => {
4846
- const { persistent = false, keyStore, dataStore, dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
4923
+ const { persistent = false, keyStore, dataStore } = config ?? {};
4847
4924
  if (persistent && dataStore === StorageDriver.RAM) {
4848
4925
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4849
4926
  }
@@ -4859,7 +4936,7 @@ var createStorageObjects = (config) => {
4859
4936
  return {
4860
4937
  storage: createStorage({
4861
4938
  type: persistent ? toStorageType(dataStore) : StorageType.RAM,
4862
- root: `${dataRoot}/`
4939
+ root: getRootPath(config)
4863
4940
  })
4864
4941
  };
4865
4942
  };
@@ -4884,22 +4961,34 @@ var toStorageType = (type) => {
4884
4961
  }
4885
4962
  };
4886
4963
 
4964
+ // packages/sdk/client-services/src/packlets/storage/level.ts
4965
+ import { Level } from "level";
4966
+ import path from "@dxos/node-std/path";
4967
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
4968
+ var createLevel = async (config) => {
4969
+ const persistent = isPersistent(config);
4970
+ const storagePath = persistent ? getRootPath(config) : path.join("tmp", "level", PublicKey11.random().toHex());
4971
+ const level = new Level(storagePath);
4972
+ await level.open();
4973
+ return level;
4974
+ };
4975
+
4887
4976
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4888
4977
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4889
- import { Properties, clientServiceBundle, defaultKey } from "@dxos/client-protocol";
4978
+ import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4890
4979
  import { Context as Context11 } from "@dxos/context";
4891
- import { DataServiceImpl } from "@dxos/echo-pipeline";
4892
- import { getAutomergeObjectCore, getRawDoc } from "@dxos/echo-schema";
4980
+ import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
4981
+ import * as E from "@dxos/echo-schema";
4893
4982
  import { IndexServiceImpl } from "@dxos/indexing";
4894
4983
  import { invariant as invariant16 } from "@dxos/invariant";
4895
- import { PublicKey as PublicKey12 } from "@dxos/keys";
4984
+ import { PublicKey as PublicKey13 } from "@dxos/keys";
4896
4985
  import { log as log15 } from "@dxos/log";
4897
4986
  import { WebsocketSignalManager } from "@dxos/messaging";
4898
4987
  import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
4899
4988
  import { trace as trace9 } from "@dxos/protocols";
4900
4989
  import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
4901
4990
  import { TRACE_PROCESSOR as TRACE_PROCESSOR2, trace as Trace3 } from "@dxos/tracing";
4902
- import { assignDeep } from "@dxos/util";
4991
+ import { assignDeep as assignDeep2 } from "@dxos/util";
4903
4992
  import { WebsocketRpcClient } from "@dxos/websocket-rpc";
4904
4993
 
4905
4994
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
@@ -4987,7 +5076,7 @@ var DevicesServiceImpl = class {
4987
5076
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
4988
5077
  import { Event as Event8 } from "@dxos/async";
4989
5078
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
4990
- import { PublicKey as PublicKey11 } from "@dxos/keys";
5079
+ import { PublicKey as PublicKey12 } from "@dxos/keys";
4991
5080
  import { getContextFromEntry, log as log14 } from "@dxos/log";
4992
5081
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
4993
5082
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
@@ -4995,7 +5084,7 @@ var LoggingServiceImpl = class {
4995
5084
  constructor() {
4996
5085
  this._logs = new Event8();
4997
5086
  this._started = Date.now();
4998
- this._sessionId = PublicKey11.random().toHex();
5087
+ this._sessionId = PublicKey12.random().toHex();
4999
5088
  this._logProcessor = (_config, entry2) => {
5000
5089
  this._logs.emit(entry2);
5001
5090
  };
@@ -5090,12 +5179,12 @@ var LoggingServiceImpl = class {
5090
5179
  });
5091
5180
  }
5092
5181
  };
5093
- var matchFilter = (filter, level, path, options) => {
5182
+ var matchFilter = (filter, level, path2, options) => {
5094
5183
  switch (options) {
5095
5184
  case QueryLogsRequest.MatchingOptions.INCLUSIVE:
5096
- return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
5185
+ return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5097
5186
  case QueryLogsRequest.MatchingOptions.EXPLICIT:
5098
- return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
5187
+ return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5099
5188
  }
5100
5189
  };
5101
5190
  var shouldLog = (entry2, request) => {
@@ -5296,7 +5385,7 @@ var ClientServicesHost = class {
5296
5385
  initialize({ config, ...options }) {
5297
5386
  invariant16(!this._open, "service host is open", {
5298
5387
  F: __dxlog_file18,
5299
- L: 179,
5388
+ L: 182,
5300
5389
  S: this,
5301
5390
  A: [
5302
5391
  "!this._open",
@@ -5305,14 +5394,14 @@ var ClientServicesHost = class {
5305
5394
  });
5306
5395
  log15("initializing...", void 0, {
5307
5396
  F: __dxlog_file18,
5308
- L: 180,
5397
+ L: 183,
5309
5398
  S: this,
5310
5399
  C: (f, a) => f(...a)
5311
5400
  });
5312
5401
  if (config) {
5313
5402
  invariant16(!this._config, "config already set", {
5314
5403
  F: __dxlog_file18,
5315
- L: 183,
5404
+ L: 186,
5316
5405
  S: this,
5317
5406
  A: [
5318
5407
  "!this._config",
@@ -5324,13 +5413,21 @@ var ClientServicesHost = class {
5324
5413
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
5325
5414
  }
5326
5415
  }
5416
+ if (!options.signalManager) {
5417
+ log15.warn("running signaling without telemetry metadata.", void 0, {
5418
+ F: __dxlog_file18,
5419
+ L: 194,
5420
+ S: this,
5421
+ C: (f, a) => f(...a)
5422
+ });
5423
+ }
5327
5424
  const { connectionLog = true, transportFactory = createSimplePeerTransportFactory({
5328
5425
  iceServers: this._config?.get("runtime.services.ice")
5329
5426
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5330
5427
  this._signalManager = signalManager;
5331
5428
  invariant16(!this._networkManager, "network manager already set", {
5332
5429
  F: __dxlog_file18,
5333
- L: 199,
5430
+ L: 205,
5334
5431
  S: this,
5335
5432
  A: [
5336
5433
  "!this._networkManager",
@@ -5344,7 +5441,7 @@ var ClientServicesHost = class {
5344
5441
  });
5345
5442
  log15("initialized", void 0, {
5346
5443
  F: __dxlog_file18,
5347
- L: 206,
5444
+ L: 212,
5348
5445
  S: this,
5349
5446
  C: (f, a) => f(...a)
5350
5447
  });
@@ -5353,18 +5450,18 @@ var ClientServicesHost = class {
5353
5450
  if (this._open) {
5354
5451
  return;
5355
5452
  }
5356
- const traceId = PublicKey12.random().toHex();
5453
+ const traceId = PublicKey13.random().toHex();
5357
5454
  log15.trace("dxos.client-services.host.open", trace9.begin({
5358
5455
  id: traceId
5359
5456
  }), {
5360
5457
  F: __dxlog_file18,
5361
- L: 217,
5458
+ L: 223,
5362
5459
  S: this,
5363
5460
  C: (f, a) => f(...a)
5364
5461
  });
5365
5462
  invariant16(this._config, "config not set", {
5366
5463
  F: __dxlog_file18,
5367
- L: 219,
5464
+ L: 225,
5368
5465
  S: this,
5369
5466
  A: [
5370
5467
  "this._config",
@@ -5373,7 +5470,7 @@ var ClientServicesHost = class {
5373
5470
  });
5374
5471
  invariant16(this._storage, "storage not set", {
5375
5472
  F: __dxlog_file18,
5376
- L: 220,
5473
+ L: 226,
5377
5474
  S: this,
5378
5475
  A: [
5379
5476
  "this._storage",
@@ -5382,7 +5479,7 @@ var ClientServicesHost = class {
5382
5479
  });
5383
5480
  invariant16(this._signalManager, "signal manager not set", {
5384
5481
  F: __dxlog_file18,
5385
- L: 221,
5482
+ L: 227,
5386
5483
  S: this,
5387
5484
  A: [
5388
5485
  "this._signalManager",
@@ -5391,7 +5488,7 @@ var ClientServicesHost = class {
5391
5488
  });
5392
5489
  invariant16(this._networkManager, "network manager not set", {
5393
5490
  F: __dxlog_file18,
5394
- L: 222,
5491
+ L: 228,
5395
5492
  S: this,
5396
5493
  A: [
5397
5494
  "this._networkManager",
@@ -5403,13 +5500,16 @@ var ClientServicesHost = class {
5403
5500
  lockKey: this._resourceLock?.lockKey
5404
5501
  }, {
5405
5502
  F: __dxlog_file18,
5406
- L: 225,
5503
+ L: 231,
5407
5504
  S: this,
5408
5505
  C: (f, a) => f(...a)
5409
5506
  });
5507
+ if (!this._level) {
5508
+ this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5509
+ }
5410
5510
  await this._resourceLock?.acquire();
5411
5511
  await this._loggingService.open();
5412
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._runtimeParams);
5512
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5413
5513
  this._serviceRegistry.setServices({
5414
5514
  SystemService: this._systemService,
5415
5515
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
@@ -5437,7 +5537,7 @@ var ClientServicesHost = class {
5437
5537
  await this._serviceContext.open(ctx);
5438
5538
  invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5439
5539
  F: __dxlog_file18,
5440
- L: 286,
5540
+ L: 297,
5441
5541
  S: this,
5442
5542
  A: [
5443
5543
  "this.serviceRegistry.services.InvitationsService",
@@ -5449,7 +5549,7 @@ var ClientServicesHost = class {
5449
5549
  count: loadedInvitations.invitations?.length
5450
5550
  }, {
5451
5551
  F: __dxlog_file18,
5452
- L: 289,
5552
+ L: 300,
5453
5553
  S: this,
5454
5554
  C: (f, a) => f(...a)
5455
5555
  });
@@ -5471,7 +5571,7 @@ var ClientServicesHost = class {
5471
5571
  deviceKey
5472
5572
  }, {
5473
5573
  F: __dxlog_file18,
5474
- L: 306,
5574
+ L: 317,
5475
5575
  S: this,
5476
5576
  C: (f, a) => f(...a)
5477
5577
  });
@@ -5479,7 +5579,7 @@ var ClientServicesHost = class {
5479
5579
  id: traceId
5480
5580
  }), {
5481
5581
  F: __dxlog_file18,
5482
- L: 307,
5582
+ L: 318,
5483
5583
  S: this,
5484
5584
  C: (f, a) => f(...a)
5485
5585
  });
@@ -5493,7 +5593,7 @@ var ClientServicesHost = class {
5493
5593
  deviceKey
5494
5594
  }, {
5495
5595
  F: __dxlog_file18,
5496
- L: 318,
5596
+ L: 329,
5497
5597
  S: this,
5498
5598
  C: (f, a) => f(...a)
5499
5599
  });
@@ -5503,30 +5603,31 @@ var ClientServicesHost = class {
5503
5603
  });
5504
5604
  await this._loggingService.close();
5505
5605
  await this._serviceContext.close();
5606
+ await this._level?.close();
5506
5607
  this._open = false;
5507
5608
  this._statusUpdate.emit();
5508
5609
  log15("closed", {
5509
5610
  deviceKey
5510
5611
  }, {
5511
5612
  F: __dxlog_file18,
5512
- L: 325,
5613
+ L: 337,
5513
5614
  S: this,
5514
5615
  C: (f, a) => f(...a)
5515
5616
  });
5516
5617
  }
5517
5618
  async reset() {
5518
- const traceId = PublicKey12.random().toHex();
5619
+ const traceId = PublicKey13.random().toHex();
5519
5620
  log15.trace("dxos.sdk.client-services-host.reset", trace9.begin({
5520
5621
  id: traceId
5521
5622
  }), {
5522
5623
  F: __dxlog_file18,
5523
- L: 330,
5624
+ L: 342,
5524
5625
  S: this,
5525
5626
  C: (f, a) => f(...a)
5526
5627
  });
5527
5628
  log15("resetting...", void 0, {
5528
5629
  F: __dxlog_file18,
5529
- L: 332,
5630
+ L: 344,
5530
5631
  S: this,
5531
5632
  C: (f, a) => f(...a)
5532
5633
  });
@@ -5534,7 +5635,7 @@ var ClientServicesHost = class {
5534
5635
  await this._storage.reset();
5535
5636
  log15("reset", void 0, {
5536
5637
  F: __dxlog_file18,
5537
- L: 335,
5638
+ L: 347,
5538
5639
  S: this,
5539
5640
  C: (f, a) => f(...a)
5540
5641
  });
@@ -5542,7 +5643,7 @@ var ClientServicesHost = class {
5542
5643
  id: traceId
5543
5644
  }), {
5544
5645
  F: __dxlog_file18,
5545
- L: 336,
5646
+ L: 348,
5546
5647
  S: this,
5547
5648
  C: (f, a) => f(...a)
5548
5649
  });
@@ -5552,12 +5653,10 @@ var ClientServicesHost = class {
5552
5653
  const identity = await this._serviceContext.createIdentity(params);
5553
5654
  await this._serviceContext.initialized.wait();
5554
5655
  const space = await this._serviceContext.dataSpaceManager.createSpace();
5555
- const obj = new Properties(void 0);
5556
- obj[defaultKey] = identity.identityKey.toHex();
5557
5656
  const automergeIndex = space.automergeSpaceState.rootUrl;
5558
5657
  invariant16(automergeIndex, void 0, {
5559
5658
  F: __dxlog_file18,
5560
- L: 351,
5659
+ L: 360,
5561
5660
  S: this,
5562
5661
  A: [
5563
5662
  "automergeIndex",
@@ -5566,12 +5665,25 @@ var ClientServicesHost = class {
5566
5665
  });
5567
5666
  const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5568
5667
  await document.whenReady();
5668
+ const properties = {
5669
+ system: {
5670
+ type: encodeReference(E.getTypeReference(Properties))
5671
+ },
5672
+ data: {
5673
+ [defaultKey]: identity.identityKey.toHex()
5674
+ },
5675
+ meta: {
5676
+ keys: []
5677
+ }
5678
+ };
5679
+ const propertiesId = PublicKey13.random().toHex();
5569
5680
  document.change((doc) => {
5570
- assignDeep(doc, [
5681
+ assignDeep2(doc, [
5571
5682
  "objects",
5572
- getAutomergeObjectCore(obj).id
5573
- ], getRawDoc(obj).handle.docSync());
5683
+ propertiesId
5684
+ ], properties);
5574
5685
  });
5686
+ await this._serviceContext.automergeHost.repo.flush();
5575
5687
  return identity;
5576
5688
  }
5577
5689
  };
@@ -5625,6 +5737,7 @@ export {
5625
5737
  Lock,
5626
5738
  isLocked,
5627
5739
  createStorageObjects,
5740
+ createLevel,
5628
5741
  ClientServicesHost
5629
5742
  };
5630
- //# sourceMappingURL=chunk-7PYX6UUA.mjs.map
5743
+ //# sourceMappingURL=chunk-V2ALN47T.mjs.map