@dxos/client-services 0.1.56-main.c19b7cd → 0.1.56-main.c277f68

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 (38) hide show
  1. package/dist/lib/browser/{chunk-ZOTHWLK5.mjs → chunk-E7EKG5QQ.mjs} +267 -280
  2. package/dist/lib/browser/chunk-E7EKG5QQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +8 -13
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +30 -45
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +2 -2
  8. package/dist/lib/node/index.cjs +287 -305
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +299 -323
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +5 -0
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  22. package/dist/types/src/version.d.ts +1 -1
  23. package/package.json +34 -34
  24. package/src/packlets/identity/identity-manager.test.ts +11 -0
  25. package/src/packlets/identity/identity-manager.ts +18 -1
  26. package/src/packlets/identity/identity-service.test.ts +15 -1
  27. package/src/packlets/identity/identity-service.ts +23 -14
  28. package/src/packlets/invitations/invitations-handler.ts +2 -0
  29. package/src/packlets/services/diagnostics.ts +2 -1
  30. package/src/packlets/services/service-context.ts +7 -4
  31. package/src/packlets/services/service-host.test.ts +1 -1
  32. package/src/packlets/services/service-host.ts +11 -7
  33. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  34. package/src/packlets/spaces/data-space-manager.ts +5 -1
  35. package/src/packlets/spaces/spaces-service.ts +1 -1
  36. package/src/packlets/vault/worker-runtime.ts +1 -1
  37. package/src/version.ts +1 -1
  38. package/dist/lib/browser/chunk-ZOTHWLK5.mjs.map +0 -7
@@ -64,13 +64,14 @@ var import_rpc = require("@dxos/rpc");
64
64
  var import_codec_protobuf2 = require("@dxos/codec-protobuf");
65
65
  var import_credentials2 = require("@dxos/credentials");
66
66
  var import_document_model = require("@dxos/document-model");
67
+ var import_echo_db = require("@dxos/echo-db");
67
68
  var import_invariant = require("@dxos/invariant");
68
69
  var import_log = require("@dxos/log");
69
70
  var import_protocols = require("@dxos/protocols");
70
71
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
71
72
 
72
73
  // packages/sdk/client-services/src/version.ts
73
- var DXOS_VERSION = "0.1.56-main.c19b7cd";
74
+ var DXOS_VERSION = "0.1.56-main.c277f68";
74
75
 
75
76
  // packages/sdk/client-services/src/packlets/services/platform.ts
76
77
  var getPlatform = () => {
@@ -104,9 +105,8 @@ var getPlatform = () => {
104
105
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
105
106
  var DEFAULT_TIMEOUT = 1e3;
106
107
  var createDiagnostics = async (clientServices, serviceContext, config) => {
107
- var _a, _b, _c;
108
108
  const diagnostics = {
109
- created: new Date().toISOString(),
109
+ created: (/* @__PURE__ */ new Date()).toISOString(),
110
110
  platform: getPlatform(),
111
111
  client: {
112
112
  version: DXOS_VERSION,
@@ -118,7 +118,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
118
118
  {
119
119
  (0, import_invariant.invariant)(clientServices.LoggingService, "SystemService is not available.", {
120
120
  F: __dxlog_file,
121
- L: 87,
121
+ L: 88,
122
122
  S: void 0,
123
123
  A: [
124
124
  "clientServices.LoggingService",
@@ -136,16 +136,16 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
136
136
  spaceKey: identity.space.key,
137
137
  profile: identity.profileDocument
138
138
  };
139
- const { devices } = (_a = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
139
+ const { devices } = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
140
140
  timeout: DEFAULT_TIMEOUT
141
- }).catch(() => void 0)) != null ? _a : {};
141
+ }).catch(() => void 0) ?? {};
142
142
  diagnostics.devices = devices;
143
143
  if (serviceContext.dataSpaceManager) {
144
- diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
144
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
145
145
  }
146
- const { feeds = [] } = (_c = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
146
+ const { feeds = [] } = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
147
147
  timeout: DEFAULT_TIMEOUT
148
- }).catch(() => void 0)) != null ? _c : {};
148
+ }).catch(() => void 0) ?? {};
149
149
  diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
150
150
  feedKey,
151
151
  bytes,
@@ -158,16 +158,13 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
158
158
  var getProperties = (space) => {
159
159
  let properties = {};
160
160
  try {
161
- const propertiesItem = space.dataPipeline.itemManager.items.find((item) => {
162
- var _a, _b;
163
- return ((_a = item.modelMeta) == null ? void 0 : _a.type) === import_document_model.DocumentModel.meta.type && ((_b = item.state) == null ? void 0 : _b.type) === "dxos.sdk.client.Properties";
164
- });
165
- const state = propertiesItem == null ? void 0 : propertiesItem.state;
166
- properties = state == null ? void 0 : state.data;
161
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === import_document_model.DocumentModel.meta.type && item.state?.type === import_echo_db.TYPE_PROPERTIES);
162
+ const state = propertiesItem?.state;
163
+ properties = state?.data;
167
164
  } catch (err) {
168
165
  import_log.log.warn(err.message, void 0, {
169
166
  F: __dxlog_file,
170
- L: 144,
167
+ L: 145,
171
168
  S: void 0,
172
169
  C: (f, a) => f(...a)
173
170
  });
@@ -175,7 +172,6 @@ var getProperties = (space) => {
175
172
  return properties;
176
173
  };
177
174
  var getSpaceStats = async (space) => {
178
- var _a, _b, _c, _d, _e, _f;
179
175
  const stats = {
180
176
  key: space.key,
181
177
  metrics: space.metrics,
@@ -183,18 +179,15 @@ var getSpaceStats = async (space) => {
183
179
  ...credential.subject.assertion,
184
180
  id: credential.id
185
181
  })),
186
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
187
- var _a2;
188
- return {
189
- identity: {
190
- identityKey: member.key,
191
- profile: {
192
- displayName: (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName
193
- }
194
- },
195
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services.SpaceMember.PresenceState.ONLINE : import_services.SpaceMember.PresenceState.OFFLINE
196
- };
197
- }),
182
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
183
+ identity: {
184
+ identityKey: member.key,
185
+ profile: {
186
+ displayName: member.assertion.profile?.displayName
187
+ }
188
+ },
189
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services.SpaceMember.PresenceState.ONLINE : import_services.SpaceMember.PresenceState.OFFLINE
190
+ })),
198
191
  pipeline: {
199
192
  // TODO(burdon): Pick properties from credentials if needed.
200
193
  // currentEpoch: space.dataPipeline.currentEpoch,
@@ -204,11 +197,11 @@ var getSpaceStats = async (space) => {
204
197
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
205
198
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
206
199
  // TODO(burdon): Empty?
207
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
208
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
209
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
210
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
211
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
200
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
201
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
202
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
203
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
204
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
212
205
  }
213
206
  };
214
207
  if (space.dataPipeline.itemManager) {
@@ -241,6 +234,7 @@ var import_protocols9 = require("@dxos/protocols");
241
234
  var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
242
235
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
243
236
  var import_tracing3 = require("@dxos/tracing");
237
+ var import_util6 = require("@dxos/util");
244
238
 
245
239
  // packages/sdk/client-services/src/packlets/identity/authenticator.ts
246
240
  var import_async = require("@dxos/async");
@@ -345,7 +339,7 @@ var TrustedKeySetAuthVerifier = class {
345
339
  return await trigger.wait({
346
340
  timeout: this._params.authTimeout
347
341
  });
348
- } catch (e) {
342
+ } catch {
349
343
  return false;
350
344
  } finally {
351
345
  clear();
@@ -441,11 +435,10 @@ var Identity = class Identity2 {
441
435
  return this._deviceStateMachine.deviceCredentialChain;
442
436
  }
443
437
  getAdmissionCredentials() {
444
- var _a, _b;
445
438
  return {
446
439
  deviceKey: this.deviceKey,
447
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : (0, import_debug2.failUndefined)(),
448
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : (0, import_debug2.failUndefined)()
440
+ controlFeedKey: this.space.controlFeedKey ?? (0, import_debug2.failUndefined)(),
441
+ dataFeedKey: this.space.dataFeedKey ?? (0, import_debug2.failUndefined)()
449
442
  };
450
443
  }
451
444
  /**
@@ -539,6 +532,7 @@ var import_keys2 = require("@dxos/keys");
539
532
  var import_log4 = require("@dxos/log");
540
533
  var import_protocols3 = require("@dxos/protocols");
541
534
  var import_credentials7 = require("@dxos/protocols/proto/dxos/halo/credentials");
535
+ var import_timeframe = require("@dxos/timeframe");
542
536
  var import_tracing2 = require("@dxos/tracing");
543
537
  var import_util = require("@dxos/util");
544
538
  function _ts_decorate2(decorators, target, key, desc) {
@@ -566,7 +560,6 @@ var IdentityManager = class IdentityManager2 {
566
560
  return this._identity;
567
561
  }
568
562
  async open(ctx) {
569
- var _a;
570
563
  const traceId = import_keys2.PublicKey.random().toHex();
571
564
  import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.begin({
572
565
  id: traceId
@@ -592,7 +585,7 @@ var IdentityManager = class IdentityManager2 {
592
585
  await this._identity.ready();
593
586
  import_log4.log.trace("dxos.halo.identity", {
594
587
  identityKey: identityRecord.identityKey,
595
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
588
+ displayName: this._identity.profileDocument?.displayName
596
589
  }, {
597
590
  F: __dxlog_file4,
598
591
  L: 82,
@@ -611,11 +604,9 @@ var IdentityManager = class IdentityManager2 {
611
604
  });
612
605
  }
613
606
  async close() {
614
- var _a;
615
- await ((_a = this._identity) == null ? void 0 : _a.close(new import_context2.Context()));
607
+ await this._identity?.close(new import_context2.Context());
616
608
  }
617
609
  async createIdentity({ displayName } = {}) {
618
- var _a;
619
610
  (0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
620
611
  F: __dxlog_file4,
621
612
  L: 96,
@@ -689,7 +680,7 @@ var IdentityManager = class IdentityManager2 {
689
680
  await this._identity.ready();
690
681
  import_log4.log.trace("dxos.halo.identity", {
691
682
  identityKey: identityRecord.identityKey,
692
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
683
+ displayName: this._identity.profileDocument?.displayName
693
684
  }, {
694
685
  F: __dxlog_file4,
695
686
  L: 152,
@@ -712,7 +703,6 @@ var IdentityManager = class IdentityManager2 {
712
703
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
713
704
  */
714
705
  async acceptIdentity(params) {
715
- var _a;
716
706
  (0, import_log4.log)("accepting identity", {
717
707
  params
718
708
  }, {
@@ -748,7 +738,7 @@ var IdentityManager = class IdentityManager2 {
748
738
  await this._identity.ready();
749
739
  import_log4.log.trace("dxos.halo.identity", {
750
740
  identityKey: identityRecord.identityKey,
751
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
741
+ displayName: this._identity.profileDocument?.displayName
752
742
  }, {
753
743
  F: __dxlog_file4,
754
744
  L: 186,
@@ -767,10 +757,42 @@ var IdentityManager = class IdentityManager2 {
767
757
  });
768
758
  return identity;
769
759
  }
760
+ /**
761
+ * Update the profile document of an existing identity.
762
+ */
763
+ async updateProfile(profile) {
764
+ (0, import_invariant3.invariant)(this._identity, "Identity not initialized.", {
765
+ F: __dxlog_file4,
766
+ L: 200,
767
+ S: this,
768
+ A: [
769
+ "this._identity",
770
+ "'Identity not initialized.'"
771
+ ]
772
+ });
773
+ const credential = await this._identity.getIdentityCredentialSigner().createCredential({
774
+ subject: this._identity.identityKey,
775
+ assertion: {
776
+ "@type": "dxos.halo.credentials.IdentityProfile",
777
+ profile
778
+ }
779
+ });
780
+ const receipt = await this._identity.controlPipeline.writer.write({
781
+ credential: {
782
+ credential
783
+ }
784
+ });
785
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
786
+ [
787
+ receipt.feedKey,
788
+ receipt.seq
789
+ ]
790
+ ]));
791
+ }
770
792
  async _constructIdentity(identityRecord) {
771
793
  (0, import_invariant3.invariant)(!this._identity, void 0, {
772
794
  F: __dxlog_file4,
773
- L: 197,
795
+ L: 214,
774
796
  S: this,
775
797
  A: [
776
798
  "!this._identity",
@@ -781,13 +803,13 @@ var IdentityManager = class IdentityManager2 {
781
803
  identityRecord
782
804
  }, {
783
805
  F: __dxlog_file4,
784
- L: 198,
806
+ L: 215,
785
807
  S: this,
786
808
  C: (f, a) => f(...a)
787
809
  });
788
810
  (0, import_invariant3.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
789
811
  F: __dxlog_file4,
790
- L: 201,
812
+ L: 218,
791
813
  S: this,
792
814
  A: [
793
815
  "identityRecord.haloSpace.controlFeedKey",
@@ -799,7 +821,7 @@ var IdentityManager = class IdentityManager2 {
799
821
  });
800
822
  (0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
801
823
  F: __dxlog_file4,
802
- L: 205,
824
+ L: 222,
803
825
  S: this,
804
826
  A: [
805
827
  "identityRecord.haloSpace.dataFeedKey",
@@ -831,7 +853,7 @@ var IdentityManager = class IdentityManager2 {
831
853
  identityKey: identityRecord.identityKey
832
854
  }, {
833
855
  F: __dxlog_file4,
834
- L: 229,
856
+ L: 246,
835
857
  S: this,
836
858
  C: (f, a) => f(...a)
837
859
  });
@@ -852,7 +874,7 @@ var IdentityManager = class IdentityManager2 {
852
874
  onAuthFailure: () => {
853
875
  import_log4.log.warn("auth failure", void 0, {
854
876
  F: __dxlog_file4,
855
- L: 248,
877
+ L: 265,
856
878
  S: this,
857
879
  C: (f, a) => f(...a)
858
880
  });
@@ -875,12 +897,13 @@ var import_debug3 = require("@dxos/debug");
875
897
  var import_invariant4 = require("@dxos/invariant");
876
898
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
877
899
  var IdentityServiceImpl = class {
878
- // TODO(wittjosiah): Remove dependency on service context.
879
- constructor(_serviceContext) {
880
- this._serviceContext = _serviceContext;
900
+ constructor(_createIdentity, _identityManager, _keyring) {
901
+ this._createIdentity = _createIdentity;
902
+ this._identityManager = _identityManager;
903
+ this._keyring = _keyring;
881
904
  }
882
905
  async createIdentity(request) {
883
- await this._serviceContext.createIdentity(request);
906
+ await this._createIdentity(request);
884
907
  return this._getIdentity();
885
908
  }
886
909
  async recoverIdentity(request) {
@@ -892,34 +915,47 @@ var IdentityServiceImpl = class {
892
915
  identity: this._getIdentity()
893
916
  });
894
917
  emitNext();
895
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
918
+ return this._identityManager.stateUpdate.on(emitNext);
896
919
  });
897
920
  }
898
921
  _getIdentity() {
899
- if (!this._serviceContext.identityManager.identity) {
922
+ if (!this._identityManager.identity) {
900
923
  return void 0;
901
924
  }
902
925
  return {
903
- identityKey: this._serviceContext.identityManager.identity.identityKey,
904
- spaceKey: this._serviceContext.identityManager.identity.space.key,
905
- profile: this._serviceContext.identityManager.identity.profileDocument
926
+ identityKey: this._identityManager.identity.identityKey,
927
+ spaceKey: this._identityManager.identity.space.key,
928
+ profile: this._identityManager.identity.profileDocument
906
929
  };
907
930
  }
931
+ async updateProfile(profile) {
932
+ (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
933
+ F: __dxlog_file5,
934
+ L: 59,
935
+ S: this,
936
+ A: [
937
+ "this._identityManager.identity",
938
+ "'Identity not initialized.'"
939
+ ]
940
+ });
941
+ await this._identityManager.updateProfile(profile);
942
+ return this._getIdentity();
943
+ }
908
944
  async signPresentation({ presentation, nonce }) {
909
- (0, import_invariant4.invariant)(this._serviceContext.identityManager.identity, "Identity not initialized.", {
945
+ (0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
910
946
  F: __dxlog_file5,
911
- L: 56,
947
+ L: 65,
912
948
  S: this,
913
949
  A: [
914
- "this._serviceContext.identityManager.identity",
950
+ "this._identityManager.identity",
915
951
  "'Identity not initialized.'"
916
952
  ]
917
953
  });
918
954
  return await (0, import_credentials8.signPresentation)({
919
955
  presentation,
920
- signer: this._serviceContext.keyring,
921
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
922
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
956
+ signer: this._keyring,
957
+ signerKey: this._identityManager.identity.deviceKey,
958
+ chain: this._identityManager.identity.deviceCredentialChain,
923
959
  nonce
924
960
  });
925
961
  }
@@ -1255,7 +1291,6 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1255
1291
  };
1256
1292
  }
1257
1293
  async onOpen(context) {
1258
- var _a;
1259
1294
  await super.onOpen(context);
1260
1295
  try {
1261
1296
  await this.rpc.InvitationHostService.options({
@@ -1264,7 +1299,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1264
1299
  await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1265
1300
  timeout: OPTIONS_TIMEOUT
1266
1301
  }));
1267
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
1302
+ if (this._remoteOptions?.role !== import_invitations.Options.Role.GUEST) {
1268
1303
  throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1269
1304
  expected: import_invitations.Options.Role.GUEST,
1270
1305
  remoteOptions: this._remoteOptions
@@ -1322,7 +1357,6 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1322
1357
  };
1323
1358
  }
1324
1359
  async onOpen(context) {
1325
- var _a;
1326
1360
  await super.onOpen(context);
1327
1361
  try {
1328
1362
  (0, import_log5.log)("begin options", void 0, {
@@ -1343,7 +1377,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1343
1377
  S: this,
1344
1378
  C: (f, a) => f(...a)
1345
1379
  });
1346
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.HOST) {
1380
+ if (this._remoteOptions?.role !== import_invitations.Options.Role.HOST) {
1347
1381
  throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1348
1382
  expected: import_invitations.Options.Role.HOST,
1349
1383
  remoteOptions: this._remoteOptions
@@ -1382,9 +1416,8 @@ var InvitationsHandler = class {
1382
1416
  this._networkManager = _networkManager;
1383
1417
  }
1384
1418
  createInvitation(protocol, options) {
1385
- var _a;
1386
- const { invitationId = import_keys4.PublicKey.random().toHex(), type = import_services4.Invitation.Type.INTERACTIVE, authMethod = import_services4.Invitation.AuthMethod.SHARED_SECRET, state = import_services4.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys4.PublicKey.random() } = options != null ? options : {};
1387
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services4.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0;
1419
+ const { invitationId = import_keys4.PublicKey.random().toHex(), type = import_services4.Invitation.Type.INTERACTIVE, authMethod = import_services4.Invitation.AuthMethod.SHARED_SECRET, state = import_services4.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys4.PublicKey.random() } = options ?? {};
1420
+ const authCode = options?.authCode ?? (authMethod === import_services4.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1388
1421
  (0, import_invariant7.invariant)(protocol, void 0, {
1389
1422
  F: __dxlog_file8,
1390
1423
  L: 76,
@@ -1437,9 +1470,8 @@ var InvitationsHandler = class {
1437
1470
  return invitation;
1438
1471
  },
1439
1472
  admit: async (admissionRequest) => {
1440
- var _a2, _b, _c;
1441
1473
  try {
1442
- const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1474
+ const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1443
1475
  (0, import_invariant7.invariant)(deviceKey, void 0, {
1444
1476
  F: __dxlog_file8,
1445
1477
  L: 119,
@@ -1584,7 +1616,8 @@ var InvitationsHandler = class {
1584
1616
  protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
1585
1617
  teleport.addExtension("dxos.halo.invitations", createExtension());
1586
1618
  }),
1587
- topology: new import_network_manager.StarTopology(topic)
1619
+ topology: new import_network_manager.StarTopology(topic),
1620
+ label: "invitation host"
1588
1621
  });
1589
1622
  ctx.onDispose(() => swarmConnection.close());
1590
1623
  stream.next({
@@ -1609,7 +1642,7 @@ var InvitationsHandler = class {
1609
1642
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
1610
1643
  (0, import_invariant7.invariant)(protocol, void 0, {
1611
1644
  F: __dxlog_file8,
1612
- L: 210,
1645
+ L: 211,
1613
1646
  S: this,
1614
1647
  A: [
1615
1648
  "protocol",
@@ -1623,7 +1656,7 @@ var InvitationsHandler = class {
1623
1656
  const setState = (newData) => {
1624
1657
  (0, import_invariant7.invariant)(newData.state !== void 0, void 0, {
1625
1658
  F: __dxlog_file8,
1626
- L: 221,
1659
+ L: 222,
1627
1660
  S: this,
1628
1661
  A: [
1629
1662
  "newData.state !== undefined",
@@ -1643,7 +1676,7 @@ var InvitationsHandler = class {
1643
1676
  ...protocol.toJSON()
1644
1677
  }, {
1645
1678
  F: __dxlog_file8,
1646
- L: 229,
1679
+ L: 230,
1647
1680
  S: this,
1648
1681
  C: (f, a) => f(...a)
1649
1682
  });
@@ -1653,7 +1686,7 @@ var InvitationsHandler = class {
1653
1686
  } else {
1654
1687
  import_log6.log.warn("auth failed", err, {
1655
1688
  F: __dxlog_file8,
1656
- L: 232,
1689
+ L: 233,
1657
1690
  S: this,
1658
1691
  C: (f, a) => f(...a)
1659
1692
  });
@@ -1667,7 +1700,7 @@ var InvitationsHandler = class {
1667
1700
  ...protocol.toJSON()
1668
1701
  }, {
1669
1702
  F: __dxlog_file8,
1670
- L: 240,
1703
+ L: 241,
1671
1704
  S: this,
1672
1705
  C: (f, a) => f(...a)
1673
1706
  });
@@ -1682,7 +1715,7 @@ var InvitationsHandler = class {
1682
1715
  currentState
1683
1716
  }, {
1684
1717
  F: __dxlog_file8,
1685
- L: 250,
1718
+ L: 251,
1686
1719
  S: this,
1687
1720
  C: (f, a) => f(...a)
1688
1721
  });
@@ -1697,7 +1730,7 @@ var InvitationsHandler = class {
1697
1730
  id: traceId
1698
1731
  }), {
1699
1732
  F: __dxlog_file8,
1700
- L: 259,
1733
+ L: 260,
1701
1734
  S: this,
1702
1735
  C: (f, a) => f(...a)
1703
1736
  });
@@ -1709,7 +1742,7 @@ var InvitationsHandler = class {
1709
1742
  ...protocol.toJSON()
1710
1743
  }, {
1711
1744
  F: __dxlog_file8,
1712
- L: 267,
1745
+ L: 268,
1713
1746
  S: this,
1714
1747
  C: (f, a) => f(...a)
1715
1748
  });
@@ -1720,7 +1753,7 @@ var InvitationsHandler = class {
1720
1753
  ...protocol.toJSON()
1721
1754
  }, {
1722
1755
  F: __dxlog_file8,
1723
- L: 271,
1756
+ L: 272,
1724
1757
  S: this,
1725
1758
  C: (f, a) => f(...a)
1726
1759
  });
@@ -1730,7 +1763,7 @@ var InvitationsHandler = class {
1730
1763
  response: introductionResponse
1731
1764
  }, {
1732
1765
  F: __dxlog_file8,
1733
- L: 275,
1766
+ L: 276,
1734
1767
  S: this,
1735
1768
  C: (f, a) => f(...a)
1736
1769
  });
@@ -1742,7 +1775,7 @@ var InvitationsHandler = class {
1742
1775
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1743
1776
  (0, import_log6.log)("guest waiting for authentication code...", void 0, {
1744
1777
  F: __dxlog_file8,
1745
- L: 284,
1778
+ L: 285,
1746
1779
  S: this,
1747
1780
  C: (f, a) => f(...a)
1748
1781
  });
@@ -1754,7 +1787,7 @@ var InvitationsHandler = class {
1754
1787
  });
1755
1788
  (0, import_log6.log)("sending authentication request", void 0, {
1756
1789
  F: __dxlog_file8,
1757
- L: 288,
1790
+ L: 289,
1758
1791
  S: this,
1759
1792
  C: (f, a) => f(...a)
1760
1793
  });
@@ -1775,7 +1808,7 @@ var InvitationsHandler = class {
1775
1808
  attempt
1776
1809
  }, {
1777
1810
  F: __dxlog_file8,
1778
- L: 299,
1811
+ L: 300,
1779
1812
  S: this,
1780
1813
  C: (f, a) => f(...a)
1781
1814
  });
@@ -1792,7 +1825,7 @@ var InvitationsHandler = class {
1792
1825
  ...protocol.toJSON()
1793
1826
  }, {
1794
1827
  F: __dxlog_file8,
1795
- L: 310,
1828
+ L: 311,
1796
1829
  S: this,
1797
1830
  C: (f, a) => f(...a)
1798
1831
  });
@@ -1804,7 +1837,7 @@ var InvitationsHandler = class {
1804
1837
  ...protocol.toJSON()
1805
1838
  }, {
1806
1839
  F: __dxlog_file8,
1807
- L: 321,
1840
+ L: 322,
1808
1841
  S: this,
1809
1842
  C: (f, a) => f(...a)
1810
1843
  });
@@ -1816,7 +1849,7 @@ var InvitationsHandler = class {
1816
1849
  id: traceId
1817
1850
  }), {
1818
1851
  F: __dxlog_file8,
1819
- L: 323,
1852
+ L: 324,
1820
1853
  S: this,
1821
1854
  C: (f, a) => f(...a)
1822
1855
  });
@@ -1826,7 +1859,7 @@ var InvitationsHandler = class {
1826
1859
  ...protocol.toJSON()
1827
1860
  }, {
1828
1861
  F: __dxlog_file8,
1829
- L: 326,
1862
+ L: 327,
1830
1863
  S: this,
1831
1864
  C: (f, a) => f(...a)
1832
1865
  });
@@ -1836,7 +1869,7 @@ var InvitationsHandler = class {
1836
1869
  } else {
1837
1870
  (0, import_log6.log)("auth failed", err, {
1838
1871
  F: __dxlog_file8,
1839
- L: 329,
1872
+ L: 330,
1840
1873
  S: this,
1841
1874
  C: (f, a) => f(...a)
1842
1875
  });
@@ -1847,7 +1880,7 @@ var InvitationsHandler = class {
1847
1880
  error: err
1848
1881
  }), {
1849
1882
  F: __dxlog_file8,
1850
- L: 332,
1883
+ L: 333,
1851
1884
  S: this,
1852
1885
  C: (f, a) => f(...a)
1853
1886
  });
@@ -1865,7 +1898,7 @@ var InvitationsHandler = class {
1865
1898
  ...protocol.toJSON()
1866
1899
  }, {
1867
1900
  F: __dxlog_file8,
1868
- L: 343,
1901
+ L: 344,
1869
1902
  S: this,
1870
1903
  C: (f, a) => f(...a)
1871
1904
  });
@@ -1875,7 +1908,7 @@ var InvitationsHandler = class {
1875
1908
  } else {
1876
1909
  (0, import_log6.log)("auth failed", err, {
1877
1910
  F: __dxlog_file8,
1878
- L: 346,
1911
+ L: 347,
1879
1912
  S: this,
1880
1913
  C: (f, a) => f(...a)
1881
1914
  });
@@ -1888,7 +1921,7 @@ var InvitationsHandler = class {
1888
1921
  (0, import_async5.scheduleTask)(ctx, async () => {
1889
1922
  (0, import_invariant7.invariant)(invitation.swarmKey, void 0, {
1890
1923
  F: __dxlog_file8,
1891
- L: 356,
1924
+ L: 357,
1892
1925
  S: this,
1893
1926
  A: [
1894
1927
  "invitation.swarmKey",
@@ -1902,7 +1935,8 @@ var InvitationsHandler = class {
1902
1935
  protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
1903
1936
  teleport.addExtension("dxos.halo.invitations", createExtension());
1904
1937
  }),
1905
- topology: new import_network_manager.StarTopology(topic)
1938
+ topology: new import_network_manager.StarTopology(topic),
1939
+ label: "invitation guest"
1906
1940
  });
1907
1941
  ctx.onDispose(() => swarmConnection.close());
1908
1942
  setState({
@@ -2138,7 +2172,6 @@ var SpaceInvitationProtocol = class {
2138
2172
  };
2139
2173
  }
2140
2174
  async admit(request, guestProfile) {
2141
- var _a;
2142
2175
  (0, import_invariant9.invariant)(this._spaceKey, void 0, {
2143
2176
  F: __dxlog_file10,
2144
2177
  L: 42,
@@ -2202,7 +2235,7 @@ var SpaceInvitationProtocol = class {
2202
2235
  space: {
2203
2236
  credential: spaceMemberCredential,
2204
2237
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2205
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2238
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2206
2239
  }
2207
2240
  };
2208
2241
  }
@@ -2289,7 +2322,7 @@ var import_keys6 = require("@dxos/keys");
2289
2322
  var import_log10 = require("@dxos/log");
2290
2323
  var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
2291
2324
  var import_credentials11 = require("@dxos/protocols/proto/dxos/halo/credentials");
2292
- var import_timeframe = require("@dxos/timeframe");
2325
+ var import_timeframe2 = require("@dxos/timeframe");
2293
2326
  var import_util3 = require("@dxos/util");
2294
2327
 
2295
2328
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
@@ -2358,7 +2391,7 @@ var NotarizationPlugin = class {
2358
2391
  errors.throw(err);
2359
2392
  }
2360
2393
  });
2361
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2394
+ opCtx?.onDispose(() => ctx.dispose());
2362
2395
  if (timeout !== 0) {
2363
2396
  (0, import_async7.scheduleTask)(ctx, () => {
2364
2397
  import_log9.log.warn("Notarization timeout", {
@@ -2451,11 +2484,10 @@ var NotarizationPlugin = class {
2451
2484
  * Called with credentials arriving from the control pipeline.
2452
2485
  */
2453
2486
  async processCredential(credential) {
2454
- var _a;
2455
2487
  if (!credential.id) {
2456
2488
  return;
2457
2489
  }
2458
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2490
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2459
2491
  this._processedCredentials.add(credential.id);
2460
2492
  this._processCredentialsTriggers.delete(credential.id);
2461
2493
  }
@@ -2481,11 +2513,10 @@ var NotarizationPlugin = class {
2481
2513
  * Requests from other peers to notarize credentials.
2482
2514
  */
2483
2515
  async _onNotarize(request) {
2484
- var _a;
2485
2516
  if (!this._writer) {
2486
2517
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2487
2518
  }
2488
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2519
+ for (const credential of request.credentials ?? []) {
2489
2520
  (0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
2490
2521
  F: __dxlog_file11,
2491
2522
  L: 200,
@@ -2586,7 +2617,6 @@ var DataSpace = class DataSpace2 {
2586
2617
  this.error = void 0;
2587
2618
  this.stateUpdate = new import_async8.Event();
2588
2619
  this.metrics = {};
2589
- var _a;
2590
2620
  this._inner = params.inner;
2591
2621
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2592
2622
  this._gossip = params.gossip;
@@ -2595,7 +2625,7 @@ var DataSpace = class DataSpace2 {
2595
2625
  this._feedStore = params.feedStore;
2596
2626
  this._metadataStore = params.metadataStore;
2597
2627
  this._signingContext = params.signingContext;
2598
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2628
+ this._callbacks = params.callbacks ?? {};
2599
2629
  this.authVerifier = new TrustedKeySetAuthVerifier({
2600
2630
  trustedKeysProvider: () => new import_util3.ComplexSet(import_keys6.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2601
2631
  update: this._inner.stateUpdate,
@@ -2639,14 +2669,13 @@ var DataSpace = class DataSpace2 {
2639
2669
  this._state = import_services7.SpaceState.CONTROL_ONLY;
2640
2670
  this.stateUpdate.emit();
2641
2671
  this.metrics = {};
2642
- this.metrics.open = new Date();
2672
+ this.metrics.open = /* @__PURE__ */ new Date();
2643
2673
  }
2644
2674
  async close() {
2645
2675
  await this._close();
2646
2676
  }
2647
2677
  async _close() {
2648
- var _a, _b;
2649
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2678
+ await this._callbacks.beforeClose?.();
2650
2679
  this._state = import_services7.SpaceState.CLOSED;
2651
2680
  await this._ctx.dispose();
2652
2681
  this._ctx = new import_context6.Context();
@@ -2668,7 +2697,7 @@ var DataSpace = class DataSpace2 {
2668
2697
  initializeDataPipelineAsync() {
2669
2698
  (0, import_async8.scheduleTask)(this._ctx, async () => {
2670
2699
  try {
2671
- this.metrics.pipelineInitBegin = new Date();
2700
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2672
2701
  await this.initializeDataPipeline();
2673
2702
  } catch (err) {
2674
2703
  if (err instanceof import_errors3.CancelledError) {
@@ -2690,12 +2719,11 @@ var DataSpace = class DataSpace2 {
2690
2719
  this.error = err;
2691
2720
  this.stateUpdate.emit();
2692
2721
  } finally {
2693
- this.metrics.ready = new Date();
2722
+ this.metrics.ready = /* @__PURE__ */ new Date();
2694
2723
  }
2695
2724
  });
2696
2725
  }
2697
2726
  async initializeDataPipeline() {
2698
- var _a, _b, _c, _d;
2699
2727
  if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
2700
2728
  throw new import_errors3.SystemError("Invalid operation");
2701
2729
  }
@@ -2704,7 +2732,7 @@ var DataSpace = class DataSpace2 {
2704
2732
  ctx: this._ctx,
2705
2733
  breakOnStall: false
2706
2734
  });
2707
- this.metrics.controlPipelineReady = new Date();
2735
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2708
2736
  await this._createWritableFeeds();
2709
2737
  (0, import_log10.log)("writable feeds created", void 0, {
2710
2738
  F: __dxlog_file12,
@@ -2721,7 +2749,7 @@ var DataSpace = class DataSpace2 {
2721
2749
  }), this._inner.controlPipeline.writer));
2722
2750
  }
2723
2751
  await this._inner.initializeDataPipeline();
2724
- this.metrics.dataPipelineOpen = new Date();
2752
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
2725
2753
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2726
2754
  (0, import_log10.log)("waiting for data pipeline to reach target timeframe", void 0, {
2727
2755
  F: __dxlog_file12,
@@ -2733,17 +2761,17 @@ var DataSpace = class DataSpace2 {
2733
2761
  ctx: this._ctx,
2734
2762
  breakOnStall: false
2735
2763
  });
2736
- this.metrics.dataPipelineReady = new Date();
2764
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
2737
2765
  (0, import_log10.log)("data pipeline ready", void 0, {
2738
2766
  F: __dxlog_file12,
2739
2767
  L: 257,
2740
2768
  S: this,
2741
2769
  C: (f, a) => f(...a)
2742
2770
  });
2743
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2771
+ await this._callbacks.beforeReady?.();
2744
2772
  this._state = import_services7.SpaceState.READY;
2745
2773
  this.stateUpdate.emit();
2746
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
2774
+ await this._callbacks.afterReady?.();
2747
2775
  }
2748
2776
  async _createWritableFeeds() {
2749
2777
  const credentials = [];
@@ -2790,7 +2818,6 @@ var DataSpace = class DataSpace2 {
2790
2818
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2791
2819
  }
2792
2820
  async createEpoch() {
2793
- var _a, _b;
2794
2821
  const epoch = await this.dataPipeline.createEpoch();
2795
2822
  const receipt = await this.inner.controlPipeline.writer.write({
2796
2823
  credential: {
@@ -2803,14 +2830,14 @@ var DataSpace = class DataSpace2 {
2803
2830
  })
2804
2831
  }
2805
2832
  });
2806
- await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
2833
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe2.Timeframe([
2807
2834
  [
2808
2835
  receipt.feedKey,
2809
2836
  receipt.seq
2810
2837
  ]
2811
2838
  ]));
2812
2839
  if (ENABLE_FEED_PURGE) {
2813
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2840
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
2814
2841
  const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2815
2842
  if (indexBeforeEpoch === void 0) {
2816
2843
  continue;
@@ -2860,9 +2887,8 @@ DataSpace = _ts_decorate3([
2860
2887
  var import_credentials12 = require("@dxos/credentials");
2861
2888
  var import_debug5 = require("@dxos/debug");
2862
2889
  var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
2863
- var import_timeframe2 = require("@dxos/timeframe");
2890
+ var import_timeframe3 = require("@dxos/timeframe");
2864
2891
  var spaceGenesis = async (keyring, signingContext, space) => {
2865
- var _a, _b, _c, _d;
2866
2892
  const credentials = [
2867
2893
  await (0, import_credentials12.createCredential)({
2868
2894
  signer: keyring,
@@ -2882,11 +2908,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2882
2908
  spaceKey: space.key,
2883
2909
  role: import_credentials13.SpaceMember.Role.ADMIN,
2884
2910
  profile: signingContext.profile,
2885
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : (0, import_debug5.failUndefined)()
2911
+ genesisFeedKey: space.controlFeedKey ?? (0, import_debug5.failUndefined)()
2886
2912
  }
2887
2913
  }),
2888
2914
  await signingContext.credentialSigner.createCredential({
2889
- subject: (_b = space.controlFeedKey) != null ? _b : (0, import_debug5.failUndefined)(),
2915
+ subject: space.controlFeedKey ?? (0, import_debug5.failUndefined)(),
2890
2916
  assertion: {
2891
2917
  "@type": "dxos.halo.credentials.AdmittedFeed",
2892
2918
  spaceKey: space.key,
@@ -2896,7 +2922,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2896
2922
  }
2897
2923
  }),
2898
2924
  await signingContext.credentialSigner.createCredential({
2899
- subject: (_c = space.dataFeedKey) != null ? _c : (0, import_debug5.failUndefined)(),
2925
+ subject: space.dataFeedKey ?? (0, import_debug5.failUndefined)(),
2900
2926
  assertion: {
2901
2927
  "@type": "dxos.halo.credentials.AdmittedFeed",
2902
2928
  spaceKey: space.key,
@@ -2906,12 +2932,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2906
2932
  }
2907
2933
  }),
2908
2934
  await signingContext.credentialSigner.createCredential({
2909
- subject: (_d = space.key) != null ? _d : (0, import_debug5.failUndefined)(),
2935
+ subject: space.key ?? (0, import_debug5.failUndefined)(),
2910
2936
  assertion: {
2911
2937
  "@type": "dxos.halo.credentials.Epoch",
2912
2938
  number: 0,
2913
2939
  previousId: void 0,
2914
- timeframe: new import_timeframe2.Timeframe(),
2940
+ timeframe: new import_timeframe3.Timeframe(),
2915
2941
  snapshotCid: void 0
2916
2942
  }
2917
2943
  })
@@ -3171,7 +3197,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3171
3197
  onAuthFailure: () => {
3172
3198
  import_log11.log.warn("auth failure", void 0, {
3173
3199
  F: __dxlog_file13,
3174
- L: 213,
3200
+ L: 217,
3175
3201
  S: this,
3176
3202
  C: (f, a) => f(...a)
3177
3203
  });
@@ -3195,7 +3221,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3195
3221
  space: space.key
3196
3222
  }, {
3197
3223
  F: __dxlog_file13,
3198
- L: 231,
3224
+ L: 235,
3199
3225
  S: this,
3200
3226
  C: (f, a) => f(...a)
3201
3227
  });
@@ -3207,7 +3233,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3207
3233
  open: this._isOpen
3208
3234
  }, {
3209
3235
  F: __dxlog_file13,
3210
- L: 238,
3236
+ L: 242,
3211
3237
  S: this,
3212
3238
  C: (f, a) => f(...a)
3213
3239
  });
@@ -3220,7 +3246,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3220
3246
  space: space.key
3221
3247
  }, {
3222
3248
  F: __dxlog_file13,
3223
- L: 244,
3249
+ L: 248,
3224
3250
  S: this,
3225
3251
  C: (f, a) => f(...a)
3226
3252
  });
@@ -3285,9 +3311,8 @@ var SpacesServiceImpl = class {
3285
3311
  return this._serializeSpace(space);
3286
3312
  }
3287
3313
  async updateSpace({ spaceKey, state }) {
3288
- var _a;
3289
3314
  const dataSpaceManager = await this._getDataSpaceManager();
3290
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3315
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3291
3316
  if (state) {
3292
3317
  switch (state) {
3293
3318
  case import_services9.SpaceState.ACTIVE:
@@ -3318,7 +3343,7 @@ var SpacesServiceImpl = class {
3318
3343
  spaces
3319
3344
  });
3320
3345
  }, {
3321
- maxFrequency: 2
3346
+ maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
3322
3347
  });
3323
3348
  (0, import_async10.scheduleTask)(ctx, async () => {
3324
3349
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -3351,17 +3376,15 @@ var SpacesServiceImpl = class {
3351
3376
  });
3352
3377
  }
3353
3378
  async postMessage({ spaceKey, channel, message }) {
3354
- var _a;
3355
3379
  const dataSpaceManager = await this._getDataSpaceManager();
3356
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3380
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3357
3381
  await space.postMessage(getChannelId(channel), message);
3358
3382
  }
3359
3383
  subscribeMessages({ spaceKey, channel }) {
3360
3384
  return new import_codec_protobuf5.Stream(({ ctx, next }) => {
3361
3385
  (0, import_async10.scheduleTask)(ctx, async () => {
3362
- var _a;
3363
3386
  const dataSpaceManager = await this._getDataSpaceManager();
3364
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3387
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3365
3388
  const handle = space.listen(getChannelId(channel), (message) => {
3366
3389
  next(message);
3367
3390
  });
@@ -3371,8 +3394,7 @@ var SpacesServiceImpl = class {
3371
3394
  }
3372
3395
  queryCredentials({ spaceKey }) {
3373
3396
  return new import_codec_protobuf5.Stream(({ ctx, next }) => {
3374
- var _a;
3375
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3397
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3376
3398
  const processor = {
3377
3399
  processCredential: async (credential) => {
3378
3400
  next(credential);
@@ -3383,9 +3405,8 @@ var SpacesServiceImpl = class {
3383
3405
  });
3384
3406
  }
3385
3407
  async writeCredentials({ spaceKey, credentials }) {
3386
- var _a;
3387
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3388
- for (const credential of credentials != null ? credentials : []) {
3408
+ const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3409
+ for (const credential of credentials ?? []) {
3389
3410
  await space.controlPipeline.writer.write({
3390
3411
  credential: {
3391
3412
  credential
@@ -3394,13 +3415,11 @@ var SpacesServiceImpl = class {
3394
3415
  }
3395
3416
  }
3396
3417
  async createEpoch({ spaceKey }) {
3397
- var _a;
3398
3418
  const dataSpaceManager = await this._getDataSpaceManager();
3399
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3419
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3400
3420
  await space.createEpoch();
3401
3421
  }
3402
3422
  _serializeSpace(space) {
3403
- var _a, _b, _c, _d, _e, _f, _g;
3404
3423
  return {
3405
3424
  spaceKey: space.key,
3406
3425
  state: space.state,
@@ -3412,16 +3431,15 @@ var SpacesServiceImpl = class {
3412
3431
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3413
3432
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3414
3433
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3415
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3416
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3417
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3418
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3419
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3434
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3435
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3436
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3437
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3438
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3420
3439
  },
3421
3440
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3422
- var _a2, _b2, _c2;
3423
3441
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3424
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3442
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3425
3443
  if (isMe) {
3426
3444
  peers.push(space.presence.getLocalState());
3427
3445
  }
@@ -3429,14 +3447,14 @@ var SpacesServiceImpl = class {
3429
3447
  identity: {
3430
3448
  identityKey: member.key,
3431
3449
  profile: {
3432
- displayName: (_c2 = (_b2 = member.assertion.profile) == null ? void 0 : _b2.displayName) != null ? _c2 : (0, import_util5.humanize)(member.key)
3450
+ displayName: member.assertion.profile?.displayName ?? (0, import_util5.humanize)(member.key)
3433
3451
  }
3434
3452
  },
3435
3453
  presence: isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
3436
3454
  peerStates: peers
3437
3455
  };
3438
3456
  }),
3439
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3457
+ creator: space.inner.spaceState.creator?.key,
3440
3458
  cache: space.cache,
3441
3459
  metrics: space.metrics
3442
3460
  };
@@ -3476,7 +3494,8 @@ var ServiceContext = class ServiceContext2 {
3476
3494
  root: storage.createDirectory("feeds"),
3477
3495
  signer: this.keyring,
3478
3496
  hypercore: {
3479
- valueEncoding: import_echo_pipeline3.valueEncoding
3497
+ valueEncoding: import_echo_pipeline3.valueEncoding,
3498
+ stats: true
3480
3499
  }
3481
3500
  })
3482
3501
  });
@@ -3490,16 +3509,13 @@ var ServiceContext = class ServiceContext2 {
3490
3509
  });
3491
3510
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3492
3511
  this.invitations = new InvitationsHandler(this.networkManager);
3493
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3494
- var _a;
3495
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3496
- }, this._acceptIdentity.bind(this)));
3512
+ this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
3497
3513
  }
3498
3514
  async open(ctx) {
3499
3515
  await this._checkStorageVersion();
3500
3516
  (0, import_log13.log)("opening...", void 0, {
3501
3517
  F: __dxlog_file15,
3502
- L: 131,
3518
+ L: 135,
3503
3519
  S: this,
3504
3520
  C: (f, a) => f(...a)
3505
3521
  });
@@ -3507,7 +3523,7 @@ var ServiceContext = class ServiceContext2 {
3507
3523
  id: this._instanceId
3508
3524
  }), {
3509
3525
  F: __dxlog_file15,
3510
- L: 132,
3526
+ L: 136,
3511
3527
  S: this,
3512
3528
  C: (f, a) => f(...a)
3513
3529
  });
@@ -3522,29 +3538,28 @@ var ServiceContext = class ServiceContext2 {
3522
3538
  id: this._instanceId
3523
3539
  }), {
3524
3540
  F: __dxlog_file15,
3525
- L: 140,
3541
+ L: 144,
3526
3542
  S: this,
3527
3543
  C: (f, a) => f(...a)
3528
3544
  });
3529
3545
  (0, import_log13.log)("opened", void 0, {
3530
3546
  F: __dxlog_file15,
3531
- L: 141,
3547
+ L: 145,
3532
3548
  S: this,
3533
3549
  C: (f, a) => f(...a)
3534
3550
  });
3535
3551
  }
3536
3552
  async close() {
3537
- var _a;
3538
3553
  (0, import_log13.log)("closing...", void 0, {
3539
3554
  F: __dxlog_file15,
3540
- L: 145,
3555
+ L: 149,
3541
3556
  S: this,
3542
3557
  C: (f, a) => f(...a)
3543
3558
  });
3544
3559
  if (this._deviceSpaceSync && this.identityManager.identity) {
3545
3560
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3546
3561
  }
3547
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3562
+ await this.dataSpaceManager?.close();
3548
3563
  await this.identityManager.close();
3549
3564
  await this.spaceManager.close();
3550
3565
  await this.feedStore.close();
@@ -3553,7 +3568,7 @@ var ServiceContext = class ServiceContext2 {
3553
3568
  this.dataServiceSubscriptions.clear();
3554
3569
  (0, import_log13.log)("closed", void 0, {
3555
3570
  F: __dxlog_file15,
3556
- L: 156,
3571
+ L: 160,
3557
3572
  S: this,
3558
3573
  C: (f, a) => f(...a)
3559
3574
  });
@@ -3567,7 +3582,7 @@ var ServiceContext = class ServiceContext2 {
3567
3582
  const factory = this._handlerFactories.get(invitation.kind);
3568
3583
  (0, import_invariant12.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
3569
3584
  F: __dxlog_file15,
3570
- L: 168,
3585
+ L: 171,
3571
3586
  S: this,
3572
3587
  A: [
3573
3588
  "factory",
@@ -3589,14 +3604,13 @@ var ServiceContext = class ServiceContext2 {
3589
3604
  }
3590
3605
  // Called when identity is created.
3591
3606
  async _initialize(ctx) {
3592
- var _a;
3593
3607
  (0, import_log13.log)("initializing spaces...", void 0, {
3594
3608
  F: __dxlog_file15,
3595
- L: 190,
3609
+ L: 192,
3596
3610
  S: this,
3597
3611
  C: (f, a) => f(...a)
3598
3612
  });
3599
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3613
+ const identity = this.identityManager.identity ?? (0, import_debug7.failUndefined)();
3600
3614
  const signingContext = {
3601
3615
  credentialSigner: identity.getIdentityCredentialSigner(),
3602
3616
  identityKey: identity.identityKey,
@@ -3615,7 +3629,7 @@ var ServiceContext = class ServiceContext2 {
3615
3629
  this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
3616
3630
  (0, import_invariant12.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3617
3631
  F: __dxlog_file15,
3618
- L: 213,
3632
+ L: 215,
3619
3633
  S: this,
3620
3634
  A: [
3621
3635
  "this.dataSpaceManager",
@@ -3639,7 +3653,7 @@ var ServiceContext = class ServiceContext2 {
3639
3653
  details: assertion
3640
3654
  }, {
3641
3655
  F: __dxlog_file15,
3642
- L: 229,
3656
+ L: 231,
3643
3657
  S: this,
3644
3658
  C: (f, a) => f(...a)
3645
3659
  });
@@ -3650,7 +3664,7 @@ var ServiceContext = class ServiceContext2 {
3650
3664
  details: assertion
3651
3665
  }, {
3652
3666
  F: __dxlog_file15,
3653
- L: 233,
3667
+ L: 235,
3654
3668
  S: this,
3655
3669
  C: (f, a) => f(...a)
3656
3670
  });
@@ -3661,7 +3675,7 @@ var ServiceContext = class ServiceContext2 {
3661
3675
  details: assertion
3662
3676
  }, {
3663
3677
  F: __dxlog_file15,
3664
- L: 238,
3678
+ L: 240,
3665
3679
  S: this,
3666
3680
  C: (f, a) => f(...a)
3667
3681
  });
@@ -3672,7 +3686,7 @@ var ServiceContext = class ServiceContext2 {
3672
3686
  } catch (err) {
3673
3687
  import_log13.log.catch(err, void 0, {
3674
3688
  F: __dxlog_file15,
3675
- L: 244,
3689
+ L: 246,
3676
3690
  S: this,
3677
3691
  C: (f, a) => f(...a)
3678
3692
  });
@@ -3689,6 +3703,7 @@ _ts_decorate5([
3689
3703
  import_tracing3.trace.span()
3690
3704
  ], ServiceContext.prototype, "_initialize", null);
3691
3705
  ServiceContext = _ts_decorate5([
3706
+ (0, import_util6.safeInstanceof)("dxos.client-services.ServiceContext"),
3692
3707
  import_tracing3.trace.resource()
3693
3708
  ], ServiceContext);
3694
3709
 
@@ -3723,21 +3738,17 @@ var DevicesServiceImpl = class {
3723
3738
  queryDevices() {
3724
3739
  return new import_codec_protobuf6.Stream(({ next }) => {
3725
3740
  const update = () => {
3726
- var _a;
3727
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
3741
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
3728
3742
  if (!deviceKeys) {
3729
3743
  next({
3730
3744
  devices: []
3731
3745
  });
3732
3746
  } else {
3733
3747
  next({
3734
- devices: Array.from(deviceKeys.values()).map((key) => {
3735
- var _a2;
3736
- return {
3737
- deviceKey: key,
3738
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
3739
- };
3740
- })
3748
+ devices: Array.from(deviceKeys.values()).map((key) => ({
3749
+ deviceKey: key,
3750
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
3751
+ }))
3741
3752
  });
3742
3753
  }
3743
3754
  };
@@ -3765,14 +3776,14 @@ var import_async13 = require("@dxos/async");
3765
3776
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
3766
3777
  var import_feed_store4 = require("@dxos/feed-store");
3767
3778
  var import_keys9 = require("@dxos/keys");
3768
- var import_util6 = require("@dxos/util");
3779
+ var import_util7 = require("@dxos/util");
3769
3780
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
3770
3781
  return new import_codec_protobuf7.Stream(({ next }) => {
3771
3782
  const subscriptions = new import_async13.EventSubscriptions();
3772
- const feedMap = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3783
+ const feedMap = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
3773
3784
  const update = () => {
3774
3785
  const { feeds } = feedStore;
3775
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
3786
+ feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
3776
3787
  if (!feedMap.has(feed.key)) {
3777
3788
  feedMap.set(feed.key, feed);
3778
3789
  feed.on("close", update);
@@ -3780,15 +3791,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
3780
3791
  }
3781
3792
  });
3782
3793
  next({
3783
- feeds: Array.from(feedMap.values()).map((feed) => {
3784
- var _a, _b;
3785
- return {
3786
- feedKey: feed.key,
3787
- length: feed.properties.length,
3788
- bytes: feed.core.byteLength,
3789
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
3790
- };
3791
- })
3794
+ feeds: Array.from(feedMap.values()).map((feed) => ({
3795
+ feedKey: feed.key,
3796
+ length: feed.properties.length,
3797
+ bytes: feed.core.byteLength,
3798
+ downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
3799
+ }))
3792
3800
  });
3793
3801
  };
3794
3802
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -3888,13 +3896,13 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf10.Strea
3888
3896
  recipient: message.recipient.asUint8Array(),
3889
3897
  payload: message.payload
3890
3898
  },
3891
- receivedAt: new Date()
3899
+ receivedAt: /* @__PURE__ */ new Date()
3892
3900
  });
3893
3901
  });
3894
3902
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
3895
3903
  next({
3896
3904
  swarmEvent: swarmEvent.swarmEvent,
3897
- receivedAt: new Date()
3905
+ receivedAt: /* @__PURE__ */ new Date()
3898
3906
  });
3899
3907
  });
3900
3908
  return () => {
@@ -3902,17 +3910,15 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf10.Strea
3902
3910
  };
3903
3911
  });
3904
3912
  var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf10.Stream(({ next }) => {
3905
- var _a;
3906
3913
  const update = () => {
3907
- var _a2;
3908
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
3914
+ const info = networkManager.connectionLog?.swarms;
3909
3915
  if (info) {
3910
3916
  next({
3911
3917
  data: info
3912
3918
  });
3913
3919
  }
3914
3920
  };
3915
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
3921
+ networkManager.connectionLog?.update.on(update);
3916
3922
  update();
3917
3923
  });
3918
3924
 
@@ -3925,14 +3931,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
3925
3931
  const spaces = [
3926
3932
  ...context.spaceManager.spaces.values()
3927
3933
  ];
3928
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
3934
+ const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
3929
3935
  next({
3930
3936
  spaces: filteredSpaces.map((space) => {
3931
3937
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
3932
3938
  return {
3933
3939
  key: space.key,
3934
3940
  isOpen: space.isOpen,
3935
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
3941
+ timeframe: spaceMetadata?.dataTimeframe,
3936
3942
  genesisFeed: space.genesisFeedKey,
3937
3943
  controlFeed: space.controlFeedKey,
3938
3944
  dataFeed: space.dataFeedKey
@@ -3946,7 +3952,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
3946
3952
  await update();
3947
3953
  });
3948
3954
  return () => {
3949
- unsubscribe == null ? void 0 : unsubscribe();
3955
+ unsubscribe?.();
3950
3956
  clearTimeout(timeout);
3951
3957
  };
3952
3958
  });
@@ -3977,16 +3983,15 @@ var DevtoolsServiceImpl = class {
3977
3983
  };
3978
3984
  }
3979
3985
  async getStorageInfo() {
3980
- var _a, _b, _c, _d, _e;
3981
- const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
3986
+ const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
3982
3987
  used: 0
3983
3988
  };
3984
3989
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
3985
3990
  return {
3986
3991
  type: this.params.context.storage.type,
3987
3992
  storageUsage: storageUsage.used,
3988
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
3989
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
3993
+ originUsage: navigatorInfo?.usage ?? 0,
3994
+ usageQuota: navigatorInfo?.quota ?? 0
3990
3995
  };
3991
3996
  }
3992
3997
  async getBlobs() {
@@ -4094,7 +4099,6 @@ var Lock = class {
4094
4099
  return this._lockPath;
4095
4100
  }
4096
4101
  async acquire() {
4097
- var _a;
4098
4102
  (0, import_log14.log)("acquiring lock...", void 0, {
4099
4103
  F: __dxlog_file16,
4100
4104
  L: 32,
@@ -4102,7 +4106,7 @@ var Lock = class {
4102
4106
  C: (f, a) => f(...a)
4103
4107
  });
4104
4108
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4105
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4109
+ await this._onAcquire?.();
4106
4110
  (0, import_log14.log)("acquired lock", void 0, {
4107
4111
  F: __dxlog_file16,
4108
4112
  L: 37,
@@ -4111,8 +4115,7 @@ var Lock = class {
4111
4115
  });
4112
4116
  }
4113
4117
  async release() {
4114
- var _a;
4115
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4118
+ await this._onRelease?.();
4116
4119
  (0, import_invariant13.invariant)(this._fileHandle, "Lock is not acquired", {
4117
4120
  F: __dxlog_file16,
4118
4121
  L: 42,
@@ -4134,11 +4137,11 @@ var import_async16 = require("@dxos/async");
4134
4137
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
4135
4138
  var import_log15 = require("@dxos/log");
4136
4139
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
4137
- var import_util7 = require("@dxos/util");
4140
+ var import_util8 = require("@dxos/util");
4138
4141
  var LoggingServiceImpl = class {
4139
4142
  constructor() {
4140
4143
  this._logs = new import_async16.Event();
4141
- this._started = new Date();
4144
+ this._started = /* @__PURE__ */ new Date();
4142
4145
  this._logProcessor = (_config, entry2) => {
4143
4146
  this._logs.emit(entry2);
4144
4147
  };
@@ -4152,15 +4155,15 @@ var LoggingServiceImpl = class {
4152
4155
  }
4153
4156
  async controlMetrics({ reset, record }) {
4154
4157
  if (reset) {
4155
- import_util7.tracer.clear();
4158
+ import_util8.tracer.clear();
4156
4159
  }
4157
4160
  if (record === true) {
4158
- import_util7.tracer.start();
4161
+ import_util8.tracer.start();
4159
4162
  } else if (record === false) {
4160
- import_util7.tracer.stop();
4163
+ import_util8.tracer.stop();
4161
4164
  }
4162
4165
  return {
4163
- recording: import_util7.tracer.recording
4166
+ recording: import_util8.tracer.recording
4164
4167
  };
4165
4168
  }
4166
4169
  /**
@@ -4168,24 +4171,23 @@ var LoggingServiceImpl = class {
4168
4171
  */
4169
4172
  queryMetrics({ interval = 5e3 }) {
4170
4173
  const getNumericalValues = (key) => {
4171
- var _a;
4172
- const events = (_a = import_util7.tracer.get(key)) != null ? _a : [];
4174
+ const events = import_util8.tracer.get(key) ?? [];
4173
4175
  return {
4174
4176
  key,
4175
- stats: (0, import_util7.numericalValues)(events, "duration")
4177
+ stats: (0, import_util8.numericalValues)(events, "duration")
4176
4178
  };
4177
4179
  };
4178
4180
  return new import_codec_protobuf13.Stream(({ next }) => {
4179
4181
  const update = () => {
4180
4182
  const metrics = {
4181
- timestamp: new Date(),
4183
+ timestamp: /* @__PURE__ */ new Date(),
4182
4184
  values: [
4183
4185
  getNumericalValues("dxos.echo.pipeline.control"),
4184
4186
  getNumericalValues("dxos.echo.pipeline.data")
4185
4187
  ].filter(Boolean)
4186
4188
  };
4187
4189
  next({
4188
- timestamp: new Date(),
4190
+ timestamp: /* @__PURE__ */ new Date(),
4189
4191
  metrics
4190
4192
  });
4191
4193
  };
@@ -4199,11 +4201,10 @@ var LoggingServiceImpl = class {
4199
4201
  queryLogs(request) {
4200
4202
  return new import_codec_protobuf13.Stream(({ ctx, next }) => {
4201
4203
  const handler = (entry2) => {
4202
- var _a, _b, _c, _d, _e;
4203
4204
  if (LOG_PROCESSING > 0) {
4204
4205
  return;
4205
4206
  }
4206
- if (((_a = entry2.meta) == null ? void 0 : _a.F.includes("logging-service")) || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4207
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4207
4208
  return;
4208
4209
  }
4209
4210
  if (!shouldLog(entry2, request)) {
@@ -4211,12 +4212,12 @@ var LoggingServiceImpl = class {
4211
4212
  }
4212
4213
  const record = {
4213
4214
  ...entry2,
4214
- context: (0, import_util7.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4215
- timestamp: new Date(),
4215
+ context: (0, import_util8.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4216
+ timestamp: /* @__PURE__ */ new Date(),
4216
4217
  meta: {
4217
4218
  // TODO(dmaretskyi): Fix proto.
4218
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4219
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4219
+ file: entry2.meta?.F ?? "",
4220
+ line: entry2.meta?.L ?? 0
4220
4221
  }
4221
4222
  };
4222
4223
  try {
@@ -4239,15 +4240,11 @@ var matchFilter = (filter, level, path, options) => {
4239
4240
  }
4240
4241
  };
4241
4242
  var shouldLog = (entry2, request) => {
4242
- var _a;
4243
- const options = (_a = request.options) != null ? _a : import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4243
+ const options = request.options ?? import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4244
4244
  if (request.filters === void 0) {
4245
4245
  return options === import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4246
4246
  } else {
4247
- return request.filters.some((filter) => {
4248
- var _a2, _b;
4249
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4250
- });
4247
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4251
4248
  }
4252
4249
  };
4253
4250
  var LOG_PROCESSING = 0;
@@ -4289,10 +4286,10 @@ var import_client_protocol4 = require("@dxos/client-protocol");
4289
4286
  var import_errors5 = require("@dxos/errors");
4290
4287
  var import_config = require("@dxos/protocols/proto/dxos/config");
4291
4288
  var import_random_access_storage = require("@dxos/random-access-storage");
4292
- var import_util8 = require("@dxos/util");
4289
+ var import_util9 = require("@dxos/util");
4293
4290
  var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4294
4291
  var createStorageObjects = (config) => {
4295
- const { path = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4292
+ const { path = (0, import_util9.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
4296
4293
  if (persistent && storageType === StorageDriver.RAM) {
4297
4294
  throw new import_errors5.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4298
4295
  }
@@ -4336,7 +4333,7 @@ var toStorageType = (type) => {
4336
4333
  // packages/sdk/client-services/src/packlets/system/system-service.ts
4337
4334
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
4338
4335
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
4339
- var import_util9 = require("@dxos/util");
4336
+ var import_util10 = require("@dxos/util");
4340
4337
  var SystemServiceImpl = class {
4341
4338
  constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
4342
4339
  this._config = config;
@@ -4347,8 +4344,7 @@ var SystemServiceImpl = class {
4347
4344
  this._onReset = onReset;
4348
4345
  }
4349
4346
  async getConfig() {
4350
- var _a, _b;
4351
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4347
+ return this._config?.values ?? {};
4352
4348
  }
4353
4349
  /**
4354
4350
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4356,8 +4352,8 @@ var SystemServiceImpl = class {
4356
4352
  async getDiagnostics({ keys } = {}) {
4357
4353
  const diagnostics = await this._getDiagnostics();
4358
4354
  return {
4359
- timestamp: new Date(),
4360
- diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util9.jsonKeyReplacer)({
4355
+ timestamp: /* @__PURE__ */ new Date(),
4356
+ diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)({
4361
4357
  truncate: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4362
4358
  humanize: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4363
4359
  })))
@@ -4471,11 +4467,10 @@ var ClientServicesHost = class ClientServicesHost2 {
4471
4467
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4472
4468
  },
4473
4469
  onUpdateStatus: async (status) => {
4474
- var _a, _b;
4475
4470
  if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
4476
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4471
+ await this._resourceLock?.acquire();
4477
4472
  } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
4478
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4473
+ await this._resourceLock?.release();
4479
4474
  }
4480
4475
  },
4481
4476
  onReset: async () => {
@@ -4512,7 +4507,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4512
4507
  * Can only be called once.
4513
4508
  */
4514
4509
  initialize({ config, ...options }) {
4515
- var _a, _b, _c;
4516
4510
  (0, import_invariant14.invariant)(!this._open, "service host is open", {
4517
4511
  F: __dxlog_file17,
4518
4512
  L: 181,
@@ -4522,7 +4516,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4522
4516
  "'service host is open'"
4523
4517
  ]
4524
4518
  });
4525
- import_log16.log.info("initializing...", void 0, {
4519
+ (0, import_log16.log)("initializing...", void 0, {
4526
4520
  F: __dxlog_file17,
4527
4521
  L: 182,
4528
4522
  S: this,
@@ -4544,8 +4538,8 @@ var ClientServicesHost = class ClientServicesHost2 {
4544
4538
  }
4545
4539
  }
4546
4540
  const { connectionLog = true, transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
4547
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4548
- }), signalManager = new import_messaging.WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4541
+ iceServers: this._config?.get("runtime.services.ice")
4542
+ }), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4549
4543
  this._signalManager = signalManager;
4550
4544
  (0, import_invariant14.invariant)(!this._networkManager, "network manager already set", {
4551
4545
  F: __dxlog_file17,
@@ -4561,7 +4555,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4561
4555
  transportFactory,
4562
4556
  signalManager
4563
4557
  });
4564
- import_log16.log.info("initialized", void 0, {
4558
+ (0, import_log16.log)("initialized", void 0, {
4565
4559
  F: __dxlog_file17,
4566
4560
  L: 208,
4567
4561
  S: this,
@@ -4569,7 +4563,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4569
4563
  });
4570
4564
  }
4571
4565
  async open(ctx) {
4572
- var _a, _b, _c;
4573
4566
  if (this._open) {
4574
4567
  return;
4575
4568
  }
@@ -4619,20 +4612,20 @@ var ClientServicesHost = class ClientServicesHost2 {
4619
4612
  ]
4620
4613
  });
4621
4614
  this._opening = true;
4622
- import_log16.log.info("opening...", {
4623
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4615
+ (0, import_log16.log)("opening...", {
4616
+ lockKey: this._resourceLock?.lockKey
4624
4617
  }, {
4625
4618
  F: __dxlog_file17,
4626
4619
  L: 227,
4627
4620
  S: this,
4628
4621
  C: (f, a) => f(...a)
4629
4622
  });
4630
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4623
+ await this._resourceLock?.acquire();
4631
4624
  await this._loggingService.open();
4632
4625
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4633
4626
  this._serviceRegistry.setServices({
4634
4627
  SystemService: this._systemService,
4635
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4628
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4636
4629
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4637
4630
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4638
4631
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4654,12 +4647,12 @@ var ClientServicesHost = class ClientServicesHost2 {
4654
4647
  this._opening = false;
4655
4648
  this._open = true;
4656
4649
  this._statusUpdate.emit();
4657
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4658
- import_log16.log.info("opened", {
4650
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4651
+ (0, import_log16.log)("opened", {
4659
4652
  deviceKey
4660
4653
  }, {
4661
4654
  F: __dxlog_file17,
4662
- L: 280,
4655
+ L: 284,
4663
4656
  S: this,
4664
4657
  C: (f, a) => f(...a)
4665
4658
  });
@@ -4667,22 +4660,21 @@ var ClientServicesHost = class ClientServicesHost2 {
4667
4660
  id: traceId
4668
4661
  }), {
4669
4662
  F: __dxlog_file17,
4670
- L: 281,
4663
+ L: 285,
4671
4664
  S: this,
4672
4665
  C: (f, a) => f(...a)
4673
4666
  });
4674
4667
  }
4675
4668
  async close() {
4676
- var _a;
4677
4669
  if (!this._open) {
4678
4670
  return;
4679
4671
  }
4680
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4681
- import_log16.log.info("closing...", {
4672
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4673
+ (0, import_log16.log)("closing...", {
4682
4674
  deviceKey
4683
4675
  }, {
4684
4676
  F: __dxlog_file17,
4685
- L: 292,
4677
+ L: 296,
4686
4678
  S: this,
4687
4679
  C: (f, a) => f(...a)
4688
4680
  });
@@ -4693,37 +4685,36 @@ var ClientServicesHost = class ClientServicesHost2 {
4693
4685
  await this._serviceContext.close();
4694
4686
  this._open = false;
4695
4687
  this._statusUpdate.emit();
4696
- import_log16.log.info("closed", {
4688
+ (0, import_log16.log)("closed", {
4697
4689
  deviceKey
4698
4690
  }, {
4699
4691
  F: __dxlog_file17,
4700
- L: 298,
4692
+ L: 302,
4701
4693
  S: this,
4702
4694
  C: (f, a) => f(...a)
4703
4695
  });
4704
4696
  }
4705
4697
  async reset() {
4706
- var _a, _b, _c;
4707
4698
  const traceId = import_keys12.PublicKey.random().toHex();
4708
4699
  import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.begin({
4709
4700
  id: traceId
4710
4701
  }), {
4711
4702
  F: __dxlog_file17,
4712
- L: 303,
4703
+ L: 307,
4713
4704
  S: this,
4714
4705
  C: (f, a) => f(...a)
4715
4706
  });
4716
4707
  (0, import_log16.log)("resetting...", void 0, {
4717
4708
  F: __dxlog_file17,
4718
- L: 305,
4709
+ L: 309,
4719
4710
  S: this,
4720
4711
  C: (f, a) => f(...a)
4721
4712
  });
4722
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4713
+ await this._serviceContext?.close();
4723
4714
  await this._storage.reset();
4724
4715
  (0, import_log16.log)("reset", void 0, {
4725
4716
  F: __dxlog_file17,
4726
- L: 308,
4717
+ L: 312,
4727
4718
  S: this,
4728
4719
  C: (f, a) => f(...a)
4729
4720
  });
@@ -4731,11 +4722,11 @@ var ClientServicesHost = class ClientServicesHost2 {
4731
4722
  id: traceId
4732
4723
  }), {
4733
4724
  F: __dxlog_file17,
4734
- L: 309,
4725
+ L: 313,
4735
4726
  S: this,
4736
4727
  C: (f, a) => f(...a)
4737
4728
  });
4738
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4729
+ await this._callbacks?.onReset?.();
4739
4730
  }
4740
4731
  };
4741
4732
  _ts_decorate7([
@@ -4775,18 +4766,16 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4775
4766
  const authCode = new import_async18.Trigger();
4776
4767
  const hostObservable = createInvitation(host, options);
4777
4768
  hostObservable.subscribe(async (hostInvitation) => {
4778
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4779
4769
  switch (hostInvitation.state) {
4780
4770
  case import_services15.Invitation.State.CONNECTING: {
4781
- if ((_b = (_a = hooks == null ? void 0 : hooks.host) == null ? void 0 : _a.onConnecting) == null ? void 0 : _b.call(_a, hostObservable)) {
4771
+ if (hooks?.host?.onConnecting?.(hostObservable)) {
4782
4772
  break;
4783
4773
  }
4784
4774
  const guestObservable = acceptInvitation(guest, hostInvitation);
4785
4775
  guestObservable.subscribe(async (guestInvitation) => {
4786
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
4787
4776
  switch (guestInvitation.state) {
4788
4777
  case import_services15.Invitation.State.CONNECTING: {
4789
- if ((_b2 = (_a2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _a2.onConnecting) == null ? void 0 : _b2.call(_a2, guestObservable)) {
4778
+ if (hooks?.guest?.onConnecting?.(guestObservable)) {
4790
4779
  break;
4791
4780
  }
4792
4781
  (0, import_invariant15.invariant)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey), void 0, {
@@ -4801,22 +4790,22 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4801
4790
  break;
4802
4791
  }
4803
4792
  case import_services15.Invitation.State.CONNECTED: {
4804
- (_d2 = (_c2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _c2.onConnected) == null ? void 0 : _d2.call(_c2, guestObservable);
4793
+ hooks?.guest?.onConnected?.(guestObservable);
4805
4794
  break;
4806
4795
  }
4807
4796
  case import_services15.Invitation.State.READY_FOR_AUTHENTICATION: {
4808
- if ((_f2 = (_e2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _e2.onReady) == null ? void 0 : _f2.call(_e2, guestObservable)) {
4797
+ if (hooks?.guest?.onReady?.(guestObservable)) {
4809
4798
  break;
4810
4799
  }
4811
4800
  await guestObservable.authenticate(await authCode.wait());
4812
4801
  break;
4813
4802
  }
4814
4803
  case import_services15.Invitation.State.AUTHENTICATING: {
4815
- (_h2 = (_g2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _g2.onAuthenticating) == null ? void 0 : _h2.call(_g2, guestObservable);
4804
+ hooks?.guest?.onAuthenticating?.(guestObservable);
4816
4805
  break;
4817
4806
  }
4818
4807
  case import_services15.Invitation.State.SUCCESS: {
4819
- if ((_j2 = (_i2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _i2.onSuccess) == null ? void 0 : _j2.call(_i2, guestObservable)) {
4808
+ if (hooks?.guest?.onSuccess?.(guestObservable)) {
4820
4809
  break;
4821
4810
  }
4822
4811
  guestComplete.wake({
@@ -4825,7 +4814,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4825
4814
  break;
4826
4815
  }
4827
4816
  case import_services15.Invitation.State.CANCELLED: {
4828
- if ((_l2 = (_k2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _k2.onCancelled) == null ? void 0 : _l2.call(_k2, guestObservable)) {
4817
+ if (hooks?.guest?.onCancelled?.(guestObservable)) {
4829
4818
  break;
4830
4819
  }
4831
4820
  guestComplete.wake({
@@ -4834,7 +4823,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4834
4823
  break;
4835
4824
  }
4836
4825
  case import_services15.Invitation.State.TIMEOUT: {
4837
- if ((_n2 = (_m2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _m2.onTimeout) == null ? void 0 : _n2.call(_m2, guestObservable)) {
4826
+ if (hooks?.guest?.onTimeout?.(guestObservable)) {
4838
4827
  return;
4839
4828
  }
4840
4829
  guestComplete.wake({
@@ -4843,8 +4832,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4843
4832
  }
4844
4833
  }
4845
4834
  }, (error) => {
4846
- var _a2, _b2;
4847
- if ((_b2 = (_a2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _a2.onError) == null ? void 0 : _b2.call(_a2, guestObservable)) {
4835
+ if (hooks?.guest?.onError?.(guestObservable)) {
4848
4836
  return;
4849
4837
  }
4850
4838
  guestComplete.wake({
@@ -4854,11 +4842,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4854
4842
  break;
4855
4843
  }
4856
4844
  case import_services15.Invitation.State.CONNECTED: {
4857
- (_d = (_c = hooks == null ? void 0 : hooks.host) == null ? void 0 : _c.onConnected) == null ? void 0 : _d.call(_c, hostObservable);
4845
+ hooks?.host?.onConnected?.(hostObservable);
4858
4846
  break;
4859
4847
  }
4860
4848
  case import_services15.Invitation.State.READY_FOR_AUTHENTICATION: {
4861
- if ((_f = (_e = hooks == null ? void 0 : hooks.host) == null ? void 0 : _e.onReady) == null ? void 0 : _f.call(_e, hostObservable)) {
4849
+ if (hooks?.host?.onReady?.(hostObservable)) {
4862
4850
  break;
4863
4851
  }
4864
4852
  if (hostInvitation.authCode) {
@@ -4867,11 +4855,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4867
4855
  break;
4868
4856
  }
4869
4857
  case import_services15.Invitation.State.AUTHENTICATING: {
4870
- (_h = (_g = hooks == null ? void 0 : hooks.host) == null ? void 0 : _g.onAuthenticating) == null ? void 0 : _h.call(_g, hostObservable);
4858
+ hooks?.host?.onAuthenticating?.(hostObservable);
4871
4859
  break;
4872
4860
  }
4873
4861
  case import_services15.Invitation.State.SUCCESS: {
4874
- if ((_j = (_i = hooks == null ? void 0 : hooks.host) == null ? void 0 : _i.onSuccess) == null ? void 0 : _j.call(_i, hostObservable)) {
4862
+ if (hooks?.host?.onSuccess?.(hostObservable)) {
4875
4863
  break;
4876
4864
  }
4877
4865
  hostComplete.wake({
@@ -4880,7 +4868,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4880
4868
  break;
4881
4869
  }
4882
4870
  case import_services15.Invitation.State.CANCELLED: {
4883
- if ((_l = (_k = hooks == null ? void 0 : hooks.host) == null ? void 0 : _k.onCancelled) == null ? void 0 : _l.call(_k, hostObservable)) {
4871
+ if (hooks?.host?.onCancelled?.(hostObservable)) {
4884
4872
  break;
4885
4873
  }
4886
4874
  hostComplete.wake({
@@ -4889,7 +4877,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4889
4877
  break;
4890
4878
  }
4891
4879
  case import_services15.Invitation.State.TIMEOUT: {
4892
- if ((_n = (_m = hooks == null ? void 0 : hooks.host) == null ? void 0 : _m.onTimeout) == null ? void 0 : _n.call(_m, hostObservable)) {
4880
+ if (hooks?.host?.onTimeout?.(hostObservable)) {
4893
4881
  break;
4894
4882
  }
4895
4883
  hostComplete.wake({
@@ -4899,8 +4887,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4899
4887
  }
4900
4888
  }
4901
4889
  }, (error) => {
4902
- var _a, _b;
4903
- if ((_b = (_a = hooks == null ? void 0 : hooks.host) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, hostObservable)) {
4890
+ if (hooks?.host?.onError?.(hostObservable)) {
4904
4891
  return;
4905
4892
  }
4906
4893
  hostComplete.wake({
@@ -4913,9 +4900,9 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4913
4900
  ];
4914
4901
  };
4915
4902
  var createInvitation = (host, options) => {
4916
- options != null ? options : options = {
4903
+ options ??= {
4917
4904
  authMethod: import_services15.Invitation.AuthMethod.NONE,
4918
- ...options != null ? options : {}
4905
+ ...options ?? {}
4919
4906
  };
4920
4907
  if (host instanceof ServiceContext) {
4921
4908
  const hostHandler = host.getInvitationHandler({
@@ -5011,18 +4998,15 @@ var TestPeer = class {
5011
4998
  return this._props;
5012
4999
  }
5013
5000
  get storage() {
5014
- var _a, _b;
5015
- return (_b = (_a = this._props).storage) != null ? _b : _a.storage = (0, import_random_access_storage2.createStorage)({
5001
+ return this._props.storage ??= (0, import_random_access_storage2.createStorage)({
5016
5002
  type: this.opts.storageType
5017
5003
  });
5018
5004
  }
5019
5005
  get keyring() {
5020
- var _a, _b;
5021
- return (_b = (_a = this._props).keyring) != null ? _b : _a.keyring = new import_keyring2.Keyring(this.storage.createDirectory("keyring"));
5006
+ return this._props.keyring ??= new import_keyring2.Keyring(this.storage.createDirectory("keyring"));
5022
5007
  }
5023
5008
  get feedStore() {
5024
- var _a, _b;
5025
- return (_b = (_a = this._props).feedStore) != null ? _b : _a.feedStore = new import_feed_store5.FeedStore({
5009
+ return this._props.feedStore ??= new import_feed_store5.FeedStore({
5026
5010
  factory: new import_feed_store5.FeedFactory({
5027
5011
  root: this.storage.createDirectory("feeds"),
5028
5012
  signer: this.keyring,
@@ -5033,27 +5017,22 @@ var TestPeer = class {
5033
5017
  });
5034
5018
  }
5035
5019
  get metadataStore() {
5036
- var _a, _b;
5037
- return (_b = (_a = this._props).metadataStore) != null ? _b : _a.metadataStore = new import_echo_pipeline5.MetadataStore(this.storage.createDirectory("metadata"));
5020
+ return this._props.metadataStore ??= new import_echo_pipeline5.MetadataStore(this.storage.createDirectory("metadata"));
5038
5021
  }
5039
5022
  get blobStore() {
5040
- var _a, _b;
5041
- return (_b = (_a = this._props).blobStore) != null ? _b : _a.blobStore = new import_teleport_extension_object_sync2.BlobStore(this.storage.createDirectory("blobs"));
5023
+ return this._props.blobStore ??= new import_teleport_extension_object_sync2.BlobStore(this.storage.createDirectory("blobs"));
5042
5024
  }
5043
5025
  get snapshotStore() {
5044
- var _a, _b;
5045
- return (_b = (_a = this._props).snapshotStore) != null ? _b : _a.snapshotStore = new import_echo_pipeline5.SnapshotStore(this.storage.createDirectory("snapshots"));
5026
+ return this._props.snapshotStore ??= new import_echo_pipeline5.SnapshotStore(this.storage.createDirectory("snapshots"));
5046
5027
  }
5047
5028
  get networkManager() {
5048
- var _a, _b;
5049
- return (_b = (_a = this._props).networkManager) != null ? _b : _a.networkManager = new import_network_manager3.NetworkManager({
5029
+ return this._props.networkManager ??= new import_network_manager3.NetworkManager({
5050
5030
  signalManager: new import_messaging2.MemorySignalManager(this.signalContext),
5051
5031
  transportFactory: import_network_manager3.MemoryTransportFactory
5052
5032
  });
5053
5033
  }
5054
5034
  get spaceManager() {
5055
- var _a, _b;
5056
- return (_b = (_a = this._props).spaceManager) != null ? _b : _a.spaceManager = new import_echo_pipeline5.SpaceManager({
5035
+ return this._props.spaceManager ??= new import_echo_pipeline5.SpaceManager({
5057
5036
  feedStore: this.feedStore,
5058
5037
  networkManager: this.networkManager,
5059
5038
  metadataStore: this.metadataStore,
@@ -5063,16 +5042,13 @@ var TestPeer = class {
5063
5042
  });
5064
5043
  }
5065
5044
  get identity() {
5066
- var _a;
5067
- return (_a = this._props.signingContext) != null ? _a : (0, import_debug8.failUndefined)();
5045
+ return this._props.signingContext ?? (0, import_debug8.failUndefined)();
5068
5046
  }
5069
5047
  get dataSpaceManager() {
5070
- var _a, _b;
5071
- return (_b = (_a = this._props).dataSpaceManager) != null ? _b : _a.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, new import_echo_pipeline5.DataServiceSubscriptions(), this.keyring, this.identity, this.feedStore);
5048
+ return this._props.dataSpaceManager ??= new DataSpaceManager(this.spaceManager, this.metadataStore, new import_echo_pipeline5.DataServiceSubscriptions(), this.keyring, this.identity, this.feedStore);
5072
5049
  }
5073
5050
  async createIdentity() {
5074
- var _a, _b;
5075
- (_b = (_a = this._props).signingContext) != null ? _b : _a.signingContext = await createSigningContext(this.keyring);
5051
+ this._props.signingContext ??= await createSigningContext(this.keyring);
5076
5052
  }
5077
5053
  async destroy() {
5078
5054
  await this.storage.reset();