@dxos/client-services 0.4.7-main.aa6dc1f → 0.4.7-main.b51ad3a

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.
@@ -2671,7 +2671,7 @@ var getPlatform = () => {
2671
2671
  };
2672
2672
 
2673
2673
  // packages/sdk/client-services/src/version.ts
2674
- var DXOS_VERSION = "0.4.7-main.aa6dc1f";
2674
+ var DXOS_VERSION = "0.4.7-main.b51ad3a";
2675
2675
 
2676
2676
  // packages/sdk/client-services/src/packlets/services/diagnostics.ts
2677
2677
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
@@ -2813,12 +2813,12 @@ var getSpaceStats = async (space) => {
2813
2813
  };
2814
2814
 
2815
2815
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2816
- import { Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2816
+ import { Event as Event5, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2817
2817
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2818
2818
  import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
2819
2819
  import { timed, warnAfterTimeout } from "@dxos/debug";
2820
2820
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
2821
- import { failedInvariant } from "@dxos/invariant";
2821
+ import { failedInvariant, invariant as invariant11 } from "@dxos/invariant";
2822
2822
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2823
2823
  import { log as log10 } from "@dxos/log";
2824
2824
  import { CancelledError, SystemError } from "@dxos/protocols";
@@ -2835,6 +2835,7 @@ var AutomergeSpaceState = class {
2835
2835
  this._onNewRoot = _onNewRoot;
2836
2836
  this.rootUrl = void 0;
2837
2837
  this.lastEpoch = void 0;
2838
+ this._isProcessingRootDocs = false;
2838
2839
  }
2839
2840
  async processCredential(credential) {
2840
2841
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
@@ -2843,8 +2844,19 @@ var AutomergeSpaceState = class {
2843
2844
  this.lastEpoch = credential;
2844
2845
  if (credential.subject.assertion.automergeRoot) {
2845
2846
  this.rootUrl = credential.subject.assertion.automergeRoot;
2847
+ if (this._isProcessingRootDocs) {
2848
+ this._onNewRoot(this.rootUrl);
2849
+ }
2850
+ }
2851
+ }
2852
+ startProcessingRootDocs() {
2853
+ if (this._isProcessingRootDocs) {
2854
+ return;
2855
+ }
2856
+ if (this.rootUrl) {
2846
2857
  this._onNewRoot(this.rootUrl);
2847
2858
  }
2859
+ this._isProcessingRootDocs = true;
2848
2860
  }
2849
2861
  };
2850
2862
 
@@ -3310,12 +3322,13 @@ var DataSpace = class {
3310
3322
  });
3311
3323
  await this._initializeAndReadControlPipeline();
3312
3324
  await sleep2(1);
3325
+ this._automergeSpaceState.startProcessingRootDocs();
3313
3326
  await this._inner.initializeDataPipeline();
3314
3327
  this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3315
3328
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3316
3329
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3317
3330
  F: __dxlog_file12,
3318
- L: 286,
3331
+ L: 288,
3319
3332
  S: this,
3320
3333
  C: (f, a) => f(...a)
3321
3334
  });
@@ -3326,7 +3339,7 @@ var DataSpace = class {
3326
3339
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3327
3340
  log10("data pipeline ready", void 0, {
3328
3341
  F: __dxlog_file12,
3329
- L: 294,
3342
+ L: 296,
3330
3343
  S: this,
3331
3344
  C: (f, a) => f(...a)
3332
3345
  });
@@ -3336,7 +3349,7 @@ var DataSpace = class {
3336
3349
  state: SpaceState[this._state]
3337
3350
  }, {
3338
3351
  F: __dxlog_file12,
3339
- L: 298,
3352
+ L: 300,
3340
3353
  S: this,
3341
3354
  C: (f, a) => f(...a)
3342
3355
  });
@@ -3352,7 +3365,7 @@ var DataSpace = class {
3352
3365
  await this._createWritableFeeds();
3353
3366
  log10("writable feeds created", void 0, {
3354
3367
  F: __dxlog_file12,
3355
- L: 314,
3368
+ L: 316,
3356
3369
  S: this,
3357
3370
  C: (f, a) => f(...a)
3358
3371
  });
@@ -3415,7 +3428,7 @@ var DataSpace = class {
3415
3428
  rootUrl
3416
3429
  }, {
3417
3430
  F: __dxlog_file12,
3418
- L: 380,
3431
+ L: 382,
3419
3432
  S: this,
3420
3433
  C: (f, a) => f(...a)
3421
3434
  });
@@ -3447,7 +3460,7 @@ var DataSpace = class {
3447
3460
  err
3448
3461
  }, {
3449
3462
  F: __dxlog_file12,
3450
- L: 403,
3463
+ L: 405,
3451
3464
  S: this,
3452
3465
  C: (f, a) => f(...a)
3453
3466
  });
@@ -3478,15 +3491,40 @@ var DataSpace = class {
3478
3491
  epoch = await this.dataPipeline.createEpoch();
3479
3492
  }
3480
3493
  break;
3481
- case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3482
- const document = this._automergeHost.repo.create();
3483
- epoch = {
3484
- previousId: this._automergeSpaceState.lastEpoch?.id,
3485
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3486
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3487
- automergeRoot: document.url
3488
- };
3489
- }
3494
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE:
3495
+ {
3496
+ const document = this._automergeHost.repo.create();
3497
+ epoch = {
3498
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3499
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3500
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3501
+ automergeRoot: document.url
3502
+ };
3503
+ }
3504
+ break;
3505
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3506
+ {
3507
+ const currentRootUrl = this._automergeSpaceState.rootUrl;
3508
+ const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3509
+ await cancelWithContext2(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
3510
+ const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3511
+ invariant11(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3512
+ F: __dxlog_file12,
3513
+ L: 450,
3514
+ S: this,
3515
+ A: [
3516
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3517
+ ""
3518
+ ]
3519
+ });
3520
+ epoch = {
3521
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3522
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3523
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
3524
+ automergeRoot: newRoot.url
3525
+ };
3526
+ }
3527
+ break;
3490
3528
  }
3491
3529
  if (!epoch) {
3492
3530
  return;
@@ -3537,7 +3575,7 @@ var DataSpace = class {
3537
3575
  state: SpaceState[this._state]
3538
3576
  }, {
3539
3577
  F: __dxlog_file12,
3540
- L: 492,
3578
+ L: 514,
3541
3579
  S: this,
3542
3580
  C: (f, a) => f(...a)
3543
3581
  });
@@ -3594,7 +3632,7 @@ DataSpace = _ts_decorate4([
3594
3632
  import { Event as Event6, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3595
3633
  import { cancelWithContext as cancelWithContext3, Context as Context8 } from "@dxos/context";
3596
3634
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3597
- import { invariant as invariant11 } from "@dxos/invariant";
3635
+ import { invariant as invariant12 } from "@dxos/invariant";
3598
3636
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3599
3637
  import { log as log11 } from "@dxos/log";
3600
3638
  import { trace as trace7 } from "@dxos/protocols";
@@ -3787,7 +3825,7 @@ var DataSpaceManager = class {
3787
3825
  * Creates a new space writing the genesis credentials to the control feed.
3788
3826
  */
3789
3827
  async createSpace() {
3790
- invariant11(this._isOpen, "Not open.", {
3828
+ invariant12(this._isOpen, "Not open.", {
3791
3829
  F: __dxlog_file13,
3792
3830
  L: 145,
3793
3831
  S: this,
@@ -3824,7 +3862,7 @@ var DataSpaceManager = class {
3824
3862
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3825
3863
  await this._metadataStore.addSpace(metadata);
3826
3864
  const memberCredential = credentials[1];
3827
- invariant11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3865
+ invariant12(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3828
3866
  F: __dxlog_file13,
3829
3867
  L: 170,
3830
3868
  S: this,
@@ -3848,7 +3886,7 @@ var DataSpaceManager = class {
3848
3886
  S: this,
3849
3887
  C: (f, a) => f(...a)
3850
3888
  });
3851
- invariant11(this._isOpen, "Not open.", {
3889
+ invariant12(this._isOpen, "Not open.", {
3852
3890
  F: __dxlog_file13,
3853
3891
  L: 183,
3854
3892
  S: this,
@@ -3857,7 +3895,7 @@ var DataSpaceManager = class {
3857
3895
  "'Not open.'"
3858
3896
  ]
3859
3897
  });
3860
- invariant11(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3898
+ invariant12(!this._spaces.has(opts.spaceKey), "Space already exists.", {
3861
3899
  F: __dxlog_file13,
3862
3900
  L: 184,
3863
3901
  S: this,
@@ -4024,7 +4062,7 @@ DataSpaceManager = _ts_decorate5([
4024
4062
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
4025
4063
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4026
4064
  import { raise as raise2 } from "@dxos/debug";
4027
- import { invariant as invariant12 } from "@dxos/invariant";
4065
+ import { invariant as invariant13 } from "@dxos/invariant";
4028
4066
  import { log as log12 } from "@dxos/log";
4029
4067
  import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
4030
4068
  import { SpaceMember as SpaceMember3, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
@@ -4153,7 +4191,7 @@ var SpacesServiceImpl = class {
4153
4191
  }
4154
4192
  });
4155
4193
  } else {
4156
- invariant12(!credential.id, "Id on unsigned credentials is not allowed", {
4194
+ invariant13(!credential.id, "Id on unsigned credentials is not allowed", {
4157
4195
  F: __dxlog_file14,
4158
4196
  L: 168,
4159
4197
  S: this,
@@ -4162,7 +4200,7 @@ var SpacesServiceImpl = class {
4162
4200
  "'Id on unsigned credentials is not allowed'"
4163
4201
  ]
4164
4202
  });
4165
- invariant12(this._identityManager.identity, "Identity is not available", {
4203
+ invariant13(this._identityManager.identity, "Identity is not available", {
4166
4204
  F: __dxlog_file14,
4167
4205
  L: 169,
4168
4206
  S: this,
@@ -4172,7 +4210,7 @@ var SpacesServiceImpl = class {
4172
4210
  ]
4173
4211
  });
4174
4212
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
4175
- invariant12(credential.issuer.equals(signer.getIssuer()), void 0, {
4213
+ invariant13(credential.issuer.equals(signer.getIssuer()), void 0, {
4176
4214
  F: __dxlog_file14,
4177
4215
  L: 171,
4178
4216
  S: this,
@@ -4193,10 +4231,12 @@ var SpacesServiceImpl = class {
4193
4231
  }
4194
4232
  }
4195
4233
  }
4196
- async createEpoch({ spaceKey }) {
4234
+ async createEpoch({ spaceKey, migration }) {
4197
4235
  const dataSpaceManager = await this._getDataSpaceManager();
4198
4236
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4199
- await space.createEpoch();
4237
+ await space.createEpoch({
4238
+ migration
4239
+ });
4200
4240
  }
4201
4241
  _serializeSpace(space) {
4202
4242
  return {
@@ -4247,7 +4287,7 @@ import { failUndefined as failUndefined2 } from "@dxos/debug";
4247
4287
  import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore, AutomergeHost } from "@dxos/echo-pipeline";
4248
4288
  import { IndexMetadataStore } from "@dxos/echo-schema";
4249
4289
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
4250
- import { invariant as invariant13 } from "@dxos/invariant";
4290
+ import { invariant as invariant14 } from "@dxos/invariant";
4251
4291
  import { Keyring } from "@dxos/keyring";
4252
4292
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4253
4293
  import { log as log13 } from "@dxos/log";
@@ -4383,7 +4423,7 @@ var ServiceContext = class {
4383
4423
  }
4384
4424
  getInvitationHandler(invitation) {
4385
4425
  const factory = this._handlerFactories.get(invitation.kind);
4386
- invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4426
+ invariant14(factory, `Unknown invitation kind: ${invitation.kind}`, {
4387
4427
  F: __dxlog_file15,
4388
4428
  L: 192,
4389
4429
  S: this,
@@ -4438,7 +4478,7 @@ var ServiceContext = class {
4438
4478
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4439
4479
  await this.dataSpaceManager.open();
4440
4480
  this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4441
- invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4481
+ invariant14(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4442
4482
  F: __dxlog_file15,
4443
4483
  L: 248,
4444
4484
  S: this,
@@ -4543,7 +4583,7 @@ var ServiceRegistry = class {
4543
4583
  };
4544
4584
 
4545
4585
  // packages/sdk/client-services/src/packlets/locks/browser.ts
4546
- import { asyncTimeout, Trigger as Trigger6 } from "@dxos/async";
4586
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
4547
4587
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
4548
4588
  import { log as log14, logInfo } from "@dxos/log";
4549
4589
  function _ts_decorate7(decorators, target, key, desc) {
@@ -4584,7 +4624,7 @@ var Lock = class {
4584
4624
  S: this,
4585
4625
  C: (f, a) => f(...a)
4586
4626
  });
4587
- await asyncTimeout(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4627
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
4588
4628
  log14("acquired lock", void 0, {
4589
4629
  F: __dxlog_file16,
4590
4630
  L: 44,
@@ -4722,7 +4762,7 @@ import { Context as Context10 } from "@dxos/context";
4722
4762
  import { DocumentModel as DocumentModel2 } from "@dxos/document-model";
4723
4763
  import { DataServiceImpl } from "@dxos/echo-pipeline";
4724
4764
  import { getRawDoc, getAutomergeObjectCore } from "@dxos/echo-schema";
4725
- import { invariant as invariant15 } from "@dxos/invariant";
4765
+ import { invariant as invariant16 } from "@dxos/invariant";
4726
4766
  import { PublicKey as PublicKey12 } from "@dxos/keys";
4727
4767
  import { log as log16 } from "@dxos/log";
4728
4768
  import { WebsocketSignalManager } from "@dxos/messaging";
@@ -4738,7 +4778,7 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
4738
4778
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
4739
4779
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
4740
4780
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
4741
- import { invariant as invariant14 } from "@dxos/invariant";
4781
+ import { invariant as invariant15 } from "@dxos/invariant";
4742
4782
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
4743
4783
  var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
4744
4784
  var DevicesServiceImpl = class {
@@ -4757,7 +4797,7 @@ var DevicesServiceImpl = class {
4757
4797
  devices: []
4758
4798
  });
4759
4799
  } else {
4760
- invariant14(this._identityManager.identity?.presence, "presence not present", {
4800
+ invariant15(this._identityManager.identity?.presence, "presence not present", {
4761
4801
  F: __dxlog_file17,
4762
4802
  L: 32,
4763
4803
  S: this,
@@ -5132,7 +5172,7 @@ var ClientServicesHost = class {
5132
5172
  * Can only be called once.
5133
5173
  */
5134
5174
  initialize({ config, ...options }) {
5135
- invariant15(!this._open, "service host is open", {
5175
+ invariant16(!this._open, "service host is open", {
5136
5176
  F: __dxlog_file18,
5137
5177
  L: 190,
5138
5178
  S: this,
@@ -5148,7 +5188,7 @@ var ClientServicesHost = class {
5148
5188
  C: (f, a) => f(...a)
5149
5189
  });
5150
5190
  if (config) {
5151
- invariant15(!this._config, "config already set", {
5191
+ invariant16(!this._config, "config already set", {
5152
5192
  F: __dxlog_file18,
5153
5193
  L: 194,
5154
5194
  S: this,
@@ -5166,7 +5206,7 @@ var ClientServicesHost = class {
5166
5206
  iceServers: this._config?.get("runtime.services.ice")
5167
5207
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
5168
5208
  this._signalManager = signalManager;
5169
- invariant15(!this._networkManager, "network manager already set", {
5209
+ invariant16(!this._networkManager, "network manager already set", {
5170
5210
  F: __dxlog_file18,
5171
5211
  L: 210,
5172
5212
  S: this,
@@ -5200,7 +5240,7 @@ var ClientServicesHost = class {
5200
5240
  S: this,
5201
5241
  C: (f, a) => f(...a)
5202
5242
  });
5203
- invariant15(this._config, "config not set", {
5243
+ invariant16(this._config, "config not set", {
5204
5244
  F: __dxlog_file18,
5205
5245
  L: 230,
5206
5246
  S: this,
@@ -5209,7 +5249,7 @@ var ClientServicesHost = class {
5209
5249
  "'config not set'"
5210
5250
  ]
5211
5251
  });
5212
- invariant15(this._storage, "storage not set", {
5252
+ invariant16(this._storage, "storage not set", {
5213
5253
  F: __dxlog_file18,
5214
5254
  L: 231,
5215
5255
  S: this,
@@ -5218,7 +5258,7 @@ var ClientServicesHost = class {
5218
5258
  "'storage not set'"
5219
5259
  ]
5220
5260
  });
5221
- invariant15(this._signalManager, "signal manager not set", {
5261
+ invariant16(this._signalManager, "signal manager not set", {
5222
5262
  F: __dxlog_file18,
5223
5263
  L: 232,
5224
5264
  S: this,
@@ -5227,7 +5267,7 @@ var ClientServicesHost = class {
5227
5267
  "'signal manager not set'"
5228
5268
  ]
5229
5269
  });
5230
- invariant15(this._networkManager, "network manager not set", {
5270
+ invariant16(this._networkManager, "network manager not set", {
5231
5271
  F: __dxlog_file18,
5232
5272
  L: 233,
5233
5273
  S: this,
@@ -5371,7 +5411,7 @@ var ClientServicesHost = class {
5371
5411
  const obj = new Properties(void 0);
5372
5412
  obj[defaultKey] = identity.identityKey.toHex();
5373
5413
  const automergeIndex = space.automergeSpaceState.rootUrl;
5374
- invariant15(automergeIndex, void 0, {
5414
+ invariant16(automergeIndex, void 0, {
5375
5415
  F: __dxlog_file18,
5376
5416
  L: 355,
5377
5417
  S: this,
@@ -5443,4 +5483,4 @@ export {
5443
5483
  createDefaultModelFactory,
5444
5484
  ClientServicesHost
5445
5485
  };
5446
- //# sourceMappingURL=chunk-HVCUCBHI.mjs.map
5486
+ //# sourceMappingURL=chunk-W4YHONPO.mjs.map