@dxos/client-services 0.1.56-main.d9d1c3e → 0.1.56-main.da2eab1

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 (40) hide show
  1. package/dist/lib/browser/{chunk-P6TNW4K5.mjs → chunk-CXJ3H4F5.mjs} +278 -287
  2. package/dist/lib/browser/chunk-CXJ3H4F5.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 +298 -312
  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 +310 -330
  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/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/version.d.ts +1 -1
  24. package/package.json +34 -34
  25. package/src/packlets/identity/identity-manager.test.ts +11 -0
  26. package/src/packlets/identity/identity-manager.ts +18 -1
  27. package/src/packlets/identity/identity-service.test.ts +15 -1
  28. package/src/packlets/identity/identity-service.ts +23 -14
  29. package/src/packlets/invitations/invitations-handler.ts +2 -0
  30. package/src/packlets/services/diagnostics.ts +2 -1
  31. package/src/packlets/services/service-context.test.ts +59 -0
  32. package/src/packlets/services/service-context.ts +7 -4
  33. package/src/packlets/services/service-host.test.ts +1 -1
  34. package/src/packlets/services/service-host.ts +11 -7
  35. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  36. package/src/packlets/spaces/data-space-manager.ts +5 -1
  37. package/src/packlets/spaces/data-space.ts +16 -4
  38. package/src/packlets/vault/worker-runtime.ts +1 -1
  39. package/src/version.ts +1 -1
  40. package/dist/lib/browser/chunk-P6TNW4K5.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.d9d1c3e";
74
+ var DXOS_VERSION = "0.1.56-main.da2eab1";
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,
@@ -2574,6 +2605,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2574
2605
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2575
2606
  }
2576
2607
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2608
+ var ENABLE_FEED_PURGE = false;
2577
2609
  var DataSpace = class DataSpace2 {
2578
2610
  constructor(params) {
2579
2611
  this._ctx = new import_context6.Context();
@@ -2585,7 +2617,6 @@ var DataSpace = class DataSpace2 {
2585
2617
  this.error = void 0;
2586
2618
  this.stateUpdate = new import_async8.Event();
2587
2619
  this.metrics = {};
2588
- var _a;
2589
2620
  this._inner = params.inner;
2590
2621
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2591
2622
  this._gossip = params.gossip;
@@ -2594,7 +2625,7 @@ var DataSpace = class DataSpace2 {
2594
2625
  this._feedStore = params.feedStore;
2595
2626
  this._metadataStore = params.metadataStore;
2596
2627
  this._signingContext = params.signingContext;
2597
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2628
+ this._callbacks = params.callbacks ?? {};
2598
2629
  this.authVerifier = new TrustedKeySetAuthVerifier({
2599
2630
  trustedKeysProvider: () => new import_util3.ComplexSet(import_keys6.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2600
2631
  update: this._inner.stateUpdate,
@@ -2638,14 +2669,13 @@ var DataSpace = class DataSpace2 {
2638
2669
  this._state = import_services7.SpaceState.CONTROL_ONLY;
2639
2670
  this.stateUpdate.emit();
2640
2671
  this.metrics = {};
2641
- this.metrics.open = new Date();
2672
+ this.metrics.open = /* @__PURE__ */ new Date();
2642
2673
  }
2643
2674
  async close() {
2644
2675
  await this._close();
2645
2676
  }
2646
2677
  async _close() {
2647
- var _a, _b;
2648
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2678
+ await this._callbacks.beforeClose?.();
2649
2679
  this._state = import_services7.SpaceState.CLOSED;
2650
2680
  await this._ctx.dispose();
2651
2681
  this._ctx = new import_context6.Context();
@@ -2667,13 +2697,13 @@ var DataSpace = class DataSpace2 {
2667
2697
  initializeDataPipelineAsync() {
2668
2698
  (0, import_async8.scheduleTask)(this._ctx, async () => {
2669
2699
  try {
2670
- this.metrics.pipelineInitBegin = new Date();
2700
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2671
2701
  await this.initializeDataPipeline();
2672
2702
  } catch (err) {
2673
2703
  if (err instanceof import_errors3.CancelledError) {
2674
2704
  (0, import_log10.log)("data pipeline initialization cancelled", err, {
2675
2705
  F: __dxlog_file12,
2676
- L: 193,
2706
+ L: 199,
2677
2707
  S: this,
2678
2708
  C: (f, a) => f(...a)
2679
2709
  });
@@ -2681,7 +2711,7 @@ var DataSpace = class DataSpace2 {
2681
2711
  }
2682
2712
  import_log10.log.error("Error initializing data pipeline", err, {
2683
2713
  F: __dxlog_file12,
2684
- L: 197,
2714
+ L: 203,
2685
2715
  S: this,
2686
2716
  C: (f, a) => f(...a)
2687
2717
  });
@@ -2689,12 +2719,11 @@ var DataSpace = class DataSpace2 {
2689
2719
  this.error = err;
2690
2720
  this.stateUpdate.emit();
2691
2721
  } finally {
2692
- this.metrics.ready = new Date();
2722
+ this.metrics.ready = /* @__PURE__ */ new Date();
2693
2723
  }
2694
2724
  });
2695
2725
  }
2696
2726
  async initializeDataPipeline() {
2697
- var _a, _b, _c, _d;
2698
2727
  if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
2699
2728
  throw new import_errors3.SystemError("Invalid operation");
2700
2729
  }
@@ -2703,11 +2732,11 @@ var DataSpace = class DataSpace2 {
2703
2732
  ctx: this._ctx,
2704
2733
  breakOnStall: false
2705
2734
  });
2706
- this.metrics.controlPipelineReady = new Date();
2735
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
2707
2736
  await this._createWritableFeeds();
2708
2737
  (0, import_log10.log)("writable feeds created", void 0, {
2709
2738
  F: __dxlog_file12,
2710
- L: 221,
2739
+ L: 227,
2711
2740
  S: this,
2712
2741
  C: (f, a) => f(...a)
2713
2742
  });
@@ -2720,11 +2749,11 @@ var DataSpace = class DataSpace2 {
2720
2749
  }), this._inner.controlPipeline.writer));
2721
2750
  }
2722
2751
  await this._inner.initializeDataPipeline();
2723
- this.metrics.dataPipelineOpen = new Date();
2752
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
2724
2753
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2725
2754
  (0, import_log10.log)("waiting for data pipeline to reach target timeframe", void 0, {
2726
2755
  F: __dxlog_file12,
2727
- L: 242,
2756
+ L: 248,
2728
2757
  S: this,
2729
2758
  C: (f, a) => f(...a)
2730
2759
  });
@@ -2732,17 +2761,17 @@ var DataSpace = class DataSpace2 {
2732
2761
  ctx: this._ctx,
2733
2762
  breakOnStall: false
2734
2763
  });
2735
- this.metrics.dataPipelineReady = new Date();
2764
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
2736
2765
  (0, import_log10.log)("data pipeline ready", void 0, {
2737
2766
  F: __dxlog_file12,
2738
- L: 251,
2767
+ L: 257,
2739
2768
  S: this,
2740
2769
  C: (f, a) => f(...a)
2741
2770
  });
2742
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
2771
+ await this._callbacks.beforeReady?.();
2743
2772
  this._state = import_services7.SpaceState.READY;
2744
2773
  this.stateUpdate.emit();
2745
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
2774
+ await this._callbacks.afterReady?.();
2746
2775
  }
2747
2776
  async _createWritableFeeds() {
2748
2777
  const credentials = [];
@@ -2789,7 +2818,6 @@ var DataSpace = class DataSpace2 {
2789
2818
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2790
2819
  }
2791
2820
  async createEpoch() {
2792
- var _a, _b;
2793
2821
  const epoch = await this.dataPipeline.createEpoch();
2794
2822
  const receipt = await this.inner.controlPipeline.writer.write({
2795
2823
  credential: {
@@ -2802,16 +2830,19 @@ var DataSpace = class DataSpace2 {
2802
2830
  })
2803
2831
  }
2804
2832
  });
2805
- await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
2833
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe2.Timeframe([
2806
2834
  [
2807
2835
  receipt.feedKey,
2808
2836
  receipt.seq
2809
2837
  ]
2810
2838
  ]));
2811
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
2812
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2813
- if (indexBeforeEpoch) {
2814
- await feed.clear(0, indexBeforeEpoch + 1);
2839
+ if (ENABLE_FEED_PURGE) {
2840
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
2841
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
2842
+ if (indexBeforeEpoch === void 0) {
2843
+ continue;
2844
+ }
2845
+ await feed.safeClear(0, indexBeforeEpoch + 1);
2815
2846
  }
2816
2847
  }
2817
2848
  }
@@ -2856,9 +2887,8 @@ DataSpace = _ts_decorate3([
2856
2887
  var import_credentials12 = require("@dxos/credentials");
2857
2888
  var import_debug5 = require("@dxos/debug");
2858
2889
  var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
2859
- var import_timeframe2 = require("@dxos/timeframe");
2890
+ var import_timeframe3 = require("@dxos/timeframe");
2860
2891
  var spaceGenesis = async (keyring, signingContext, space) => {
2861
- var _a, _b, _c, _d;
2862
2892
  const credentials = [
2863
2893
  await (0, import_credentials12.createCredential)({
2864
2894
  signer: keyring,
@@ -2878,11 +2908,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2878
2908
  spaceKey: space.key,
2879
2909
  role: import_credentials13.SpaceMember.Role.ADMIN,
2880
2910
  profile: signingContext.profile,
2881
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : (0, import_debug5.failUndefined)()
2911
+ genesisFeedKey: space.controlFeedKey ?? (0, import_debug5.failUndefined)()
2882
2912
  }
2883
2913
  }),
2884
2914
  await signingContext.credentialSigner.createCredential({
2885
- subject: (_b = space.controlFeedKey) != null ? _b : (0, import_debug5.failUndefined)(),
2915
+ subject: space.controlFeedKey ?? (0, import_debug5.failUndefined)(),
2886
2916
  assertion: {
2887
2917
  "@type": "dxos.halo.credentials.AdmittedFeed",
2888
2918
  spaceKey: space.key,
@@ -2892,7 +2922,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2892
2922
  }
2893
2923
  }),
2894
2924
  await signingContext.credentialSigner.createCredential({
2895
- subject: (_c = space.dataFeedKey) != null ? _c : (0, import_debug5.failUndefined)(),
2925
+ subject: space.dataFeedKey ?? (0, import_debug5.failUndefined)(),
2896
2926
  assertion: {
2897
2927
  "@type": "dxos.halo.credentials.AdmittedFeed",
2898
2928
  spaceKey: space.key,
@@ -2902,12 +2932,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
2902
2932
  }
2903
2933
  }),
2904
2934
  await signingContext.credentialSigner.createCredential({
2905
- subject: (_d = space.key) != null ? _d : (0, import_debug5.failUndefined)(),
2935
+ subject: space.key ?? (0, import_debug5.failUndefined)(),
2906
2936
  assertion: {
2907
2937
  "@type": "dxos.halo.credentials.Epoch",
2908
2938
  number: 0,
2909
2939
  previousId: void 0,
2910
- timeframe: new import_timeframe2.Timeframe(),
2940
+ timeframe: new import_timeframe3.Timeframe(),
2911
2941
  snapshotCid: void 0
2912
2942
  }
2913
2943
  })
@@ -3167,7 +3197,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3167
3197
  onAuthFailure: () => {
3168
3198
  import_log11.log.warn("auth failure", void 0, {
3169
3199
  F: __dxlog_file13,
3170
- L: 213,
3200
+ L: 217,
3171
3201
  S: this,
3172
3202
  C: (f, a) => f(...a)
3173
3203
  });
@@ -3191,7 +3221,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3191
3221
  space: space.key
3192
3222
  }, {
3193
3223
  F: __dxlog_file13,
3194
- L: 231,
3224
+ L: 235,
3195
3225
  S: this,
3196
3226
  C: (f, a) => f(...a)
3197
3227
  });
@@ -3203,7 +3233,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3203
3233
  open: this._isOpen
3204
3234
  }, {
3205
3235
  F: __dxlog_file13,
3206
- L: 238,
3236
+ L: 242,
3207
3237
  S: this,
3208
3238
  C: (f, a) => f(...a)
3209
3239
  });
@@ -3216,7 +3246,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3216
3246
  space: space.key
3217
3247
  }, {
3218
3248
  F: __dxlog_file13,
3219
- L: 244,
3249
+ L: 248,
3220
3250
  S: this,
3221
3251
  C: (f, a) => f(...a)
3222
3252
  });
@@ -3281,9 +3311,8 @@ var SpacesServiceImpl = class {
3281
3311
  return this._serializeSpace(space);
3282
3312
  }
3283
3313
  async updateSpace({ spaceKey, state }) {
3284
- var _a;
3285
3314
  const dataSpaceManager = await this._getDataSpaceManager();
3286
- 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));
3287
3316
  if (state) {
3288
3317
  switch (state) {
3289
3318
  case import_services9.SpaceState.ACTIVE:
@@ -3347,17 +3376,15 @@ var SpacesServiceImpl = class {
3347
3376
  });
3348
3377
  }
3349
3378
  async postMessage({ spaceKey, channel, message }) {
3350
- var _a;
3351
3379
  const dataSpaceManager = await this._getDataSpaceManager();
3352
- 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));
3353
3381
  await space.postMessage(getChannelId(channel), message);
3354
3382
  }
3355
3383
  subscribeMessages({ spaceKey, channel }) {
3356
3384
  return new import_codec_protobuf5.Stream(({ ctx, next }) => {
3357
3385
  (0, import_async10.scheduleTask)(ctx, async () => {
3358
- var _a;
3359
3386
  const dataSpaceManager = await this._getDataSpaceManager();
3360
- 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));
3361
3388
  const handle = space.listen(getChannelId(channel), (message) => {
3362
3389
  next(message);
3363
3390
  });
@@ -3367,8 +3394,7 @@ var SpacesServiceImpl = class {
3367
3394
  }
3368
3395
  queryCredentials({ spaceKey }) {
3369
3396
  return new import_codec_protobuf5.Stream(({ ctx, next }) => {
3370
- var _a;
3371
- 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));
3372
3398
  const processor = {
3373
3399
  processCredential: async (credential) => {
3374
3400
  next(credential);
@@ -3379,9 +3405,8 @@ var SpacesServiceImpl = class {
3379
3405
  });
3380
3406
  }
3381
3407
  async writeCredentials({ spaceKey, credentials }) {
3382
- var _a;
3383
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3384
- 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 ?? []) {
3385
3410
  await space.controlPipeline.writer.write({
3386
3411
  credential: {
3387
3412
  credential
@@ -3390,13 +3415,11 @@ var SpacesServiceImpl = class {
3390
3415
  }
3391
3416
  }
3392
3417
  async createEpoch({ spaceKey }) {
3393
- var _a;
3394
3418
  const dataSpaceManager = await this._getDataSpaceManager();
3395
- 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));
3396
3420
  await space.createEpoch();
3397
3421
  }
3398
3422
  _serializeSpace(space) {
3399
- var _a, _b, _c, _d, _e, _f, _g;
3400
3423
  return {
3401
3424
  spaceKey: space.key,
3402
3425
  state: space.state,
@@ -3408,16 +3431,15 @@ var SpacesServiceImpl = class {
3408
3431
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3409
3432
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3410
3433
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3411
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3412
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3413
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3414
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3415
- 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
3416
3439
  },
3417
3440
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3418
- var _a2, _b2, _c2;
3419
3441
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3420
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3442
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3421
3443
  if (isMe) {
3422
3444
  peers.push(space.presence.getLocalState());
3423
3445
  }
@@ -3425,14 +3447,14 @@ var SpacesServiceImpl = class {
3425
3447
  identity: {
3426
3448
  identityKey: member.key,
3427
3449
  profile: {
3428
- 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)
3429
3451
  }
3430
3452
  },
3431
3453
  presence: isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
3432
3454
  peerStates: peers
3433
3455
  };
3434
3456
  }),
3435
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3457
+ creator: space.inner.spaceState.creator?.key,
3436
3458
  cache: space.cache,
3437
3459
  metrics: space.metrics
3438
3460
  };
@@ -3472,7 +3494,8 @@ var ServiceContext = class ServiceContext2 {
3472
3494
  root: storage.createDirectory("feeds"),
3473
3495
  signer: this.keyring,
3474
3496
  hypercore: {
3475
- valueEncoding: import_echo_pipeline3.valueEncoding
3497
+ valueEncoding: import_echo_pipeline3.valueEncoding,
3498
+ stats: true
3476
3499
  }
3477
3500
  })
3478
3501
  });
@@ -3486,16 +3509,13 @@ var ServiceContext = class ServiceContext2 {
3486
3509
  });
3487
3510
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3488
3511
  this.invitations = new InvitationsHandler(this.networkManager);
3489
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3490
- var _a;
3491
- return (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3492
- }, 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)));
3493
3513
  }
3494
3514
  async open(ctx) {
3495
3515
  await this._checkStorageVersion();
3496
3516
  (0, import_log13.log)("opening...", void 0, {
3497
3517
  F: __dxlog_file15,
3498
- L: 131,
3518
+ L: 135,
3499
3519
  S: this,
3500
3520
  C: (f, a) => f(...a)
3501
3521
  });
@@ -3503,7 +3523,7 @@ var ServiceContext = class ServiceContext2 {
3503
3523
  id: this._instanceId
3504
3524
  }), {
3505
3525
  F: __dxlog_file15,
3506
- L: 132,
3526
+ L: 136,
3507
3527
  S: this,
3508
3528
  C: (f, a) => f(...a)
3509
3529
  });
@@ -3518,29 +3538,28 @@ var ServiceContext = class ServiceContext2 {
3518
3538
  id: this._instanceId
3519
3539
  }), {
3520
3540
  F: __dxlog_file15,
3521
- L: 140,
3541
+ L: 144,
3522
3542
  S: this,
3523
3543
  C: (f, a) => f(...a)
3524
3544
  });
3525
3545
  (0, import_log13.log)("opened", void 0, {
3526
3546
  F: __dxlog_file15,
3527
- L: 141,
3547
+ L: 145,
3528
3548
  S: this,
3529
3549
  C: (f, a) => f(...a)
3530
3550
  });
3531
3551
  }
3532
3552
  async close() {
3533
- var _a;
3534
3553
  (0, import_log13.log)("closing...", void 0, {
3535
3554
  F: __dxlog_file15,
3536
- L: 145,
3555
+ L: 149,
3537
3556
  S: this,
3538
3557
  C: (f, a) => f(...a)
3539
3558
  });
3540
3559
  if (this._deviceSpaceSync && this.identityManager.identity) {
3541
3560
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3542
3561
  }
3543
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3562
+ await this.dataSpaceManager?.close();
3544
3563
  await this.identityManager.close();
3545
3564
  await this.spaceManager.close();
3546
3565
  await this.feedStore.close();
@@ -3549,7 +3568,7 @@ var ServiceContext = class ServiceContext2 {
3549
3568
  this.dataServiceSubscriptions.clear();
3550
3569
  (0, import_log13.log)("closed", void 0, {
3551
3570
  F: __dxlog_file15,
3552
- L: 156,
3571
+ L: 160,
3553
3572
  S: this,
3554
3573
  C: (f, a) => f(...a)
3555
3574
  });
@@ -3563,7 +3582,7 @@ var ServiceContext = class ServiceContext2 {
3563
3582
  const factory = this._handlerFactories.get(invitation.kind);
3564
3583
  (0, import_invariant12.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
3565
3584
  F: __dxlog_file15,
3566
- L: 168,
3585
+ L: 171,
3567
3586
  S: this,
3568
3587
  A: [
3569
3588
  "factory",
@@ -3585,14 +3604,13 @@ var ServiceContext = class ServiceContext2 {
3585
3604
  }
3586
3605
  // Called when identity is created.
3587
3606
  async _initialize(ctx) {
3588
- var _a;
3589
3607
  (0, import_log13.log)("initializing spaces...", void 0, {
3590
3608
  F: __dxlog_file15,
3591
- L: 190,
3609
+ L: 192,
3592
3610
  S: this,
3593
3611
  C: (f, a) => f(...a)
3594
3612
  });
3595
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
3613
+ const identity = this.identityManager.identity ?? (0, import_debug7.failUndefined)();
3596
3614
  const signingContext = {
3597
3615
  credentialSigner: identity.getIdentityCredentialSigner(),
3598
3616
  identityKey: identity.identityKey,
@@ -3611,7 +3629,7 @@ var ServiceContext = class ServiceContext2 {
3611
3629
  this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
3612
3630
  (0, import_invariant12.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3613
3631
  F: __dxlog_file15,
3614
- L: 213,
3632
+ L: 215,
3615
3633
  S: this,
3616
3634
  A: [
3617
3635
  "this.dataSpaceManager",
@@ -3635,7 +3653,7 @@ var ServiceContext = class ServiceContext2 {
3635
3653
  details: assertion
3636
3654
  }, {
3637
3655
  F: __dxlog_file15,
3638
- L: 229,
3656
+ L: 231,
3639
3657
  S: this,
3640
3658
  C: (f, a) => f(...a)
3641
3659
  });
@@ -3646,7 +3664,7 @@ var ServiceContext = class ServiceContext2 {
3646
3664
  details: assertion
3647
3665
  }, {
3648
3666
  F: __dxlog_file15,
3649
- L: 233,
3667
+ L: 235,
3650
3668
  S: this,
3651
3669
  C: (f, a) => f(...a)
3652
3670
  });
@@ -3657,7 +3675,7 @@ var ServiceContext = class ServiceContext2 {
3657
3675
  details: assertion
3658
3676
  }, {
3659
3677
  F: __dxlog_file15,
3660
- L: 238,
3678
+ L: 240,
3661
3679
  S: this,
3662
3680
  C: (f, a) => f(...a)
3663
3681
  });
@@ -3668,7 +3686,7 @@ var ServiceContext = class ServiceContext2 {
3668
3686
  } catch (err) {
3669
3687
  import_log13.log.catch(err, void 0, {
3670
3688
  F: __dxlog_file15,
3671
- L: 244,
3689
+ L: 246,
3672
3690
  S: this,
3673
3691
  C: (f, a) => f(...a)
3674
3692
  });
@@ -3685,6 +3703,7 @@ _ts_decorate5([
3685
3703
  import_tracing3.trace.span()
3686
3704
  ], ServiceContext.prototype, "_initialize", null);
3687
3705
  ServiceContext = _ts_decorate5([
3706
+ (0, import_util6.safeInstanceof)("dxos.client-services.ServiceContext"),
3688
3707
  import_tracing3.trace.resource()
3689
3708
  ], ServiceContext);
3690
3709
 
@@ -3719,21 +3738,17 @@ var DevicesServiceImpl = class {
3719
3738
  queryDevices() {
3720
3739
  return new import_codec_protobuf6.Stream(({ next }) => {
3721
3740
  const update = () => {
3722
- var _a;
3723
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
3741
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
3724
3742
  if (!deviceKeys) {
3725
3743
  next({
3726
3744
  devices: []
3727
3745
  });
3728
3746
  } else {
3729
3747
  next({
3730
- devices: Array.from(deviceKeys.values()).map((key) => {
3731
- var _a2;
3732
- return {
3733
- deviceKey: key,
3734
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
3735
- };
3736
- })
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
+ }))
3737
3752
  });
3738
3753
  }
3739
3754
  };
@@ -3761,14 +3776,14 @@ var import_async13 = require("@dxos/async");
3761
3776
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
3762
3777
  var import_feed_store4 = require("@dxos/feed-store");
3763
3778
  var import_keys9 = require("@dxos/keys");
3764
- var import_util6 = require("@dxos/util");
3779
+ var import_util7 = require("@dxos/util");
3765
3780
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
3766
3781
  return new import_codec_protobuf7.Stream(({ next }) => {
3767
3782
  const subscriptions = new import_async13.EventSubscriptions();
3768
- const feedMap = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3783
+ const feedMap = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
3769
3784
  const update = () => {
3770
3785
  const { feeds } = feedStore;
3771
- 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) => {
3772
3787
  if (!feedMap.has(feed.key)) {
3773
3788
  feedMap.set(feed.key, feed);
3774
3789
  feed.on("close", update);
@@ -3776,15 +3791,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
3776
3791
  }
3777
3792
  });
3778
3793
  next({
3779
- feeds: Array.from(feedMap.values()).map((feed) => {
3780
- var _a, _b;
3781
- return {
3782
- feedKey: feed.key,
3783
- length: feed.properties.length,
3784
- bytes: feed.core.byteLength,
3785
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
3786
- };
3787
- })
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
+ }))
3788
3800
  });
3789
3801
  };
3790
3802
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -3884,13 +3896,13 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf10.Strea
3884
3896
  recipient: message.recipient.asUint8Array(),
3885
3897
  payload: message.payload
3886
3898
  },
3887
- receivedAt: new Date()
3899
+ receivedAt: /* @__PURE__ */ new Date()
3888
3900
  });
3889
3901
  });
3890
3902
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
3891
3903
  next({
3892
3904
  swarmEvent: swarmEvent.swarmEvent,
3893
- receivedAt: new Date()
3905
+ receivedAt: /* @__PURE__ */ new Date()
3894
3906
  });
3895
3907
  });
3896
3908
  return () => {
@@ -3898,17 +3910,15 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf10.Strea
3898
3910
  };
3899
3911
  });
3900
3912
  var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf10.Stream(({ next }) => {
3901
- var _a;
3902
3913
  const update = () => {
3903
- var _a2;
3904
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
3914
+ const info = networkManager.connectionLog?.swarms;
3905
3915
  if (info) {
3906
3916
  next({
3907
3917
  data: info
3908
3918
  });
3909
3919
  }
3910
3920
  };
3911
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
3921
+ networkManager.connectionLog?.update.on(update);
3912
3922
  update();
3913
3923
  });
3914
3924
 
@@ -3921,14 +3931,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
3921
3931
  const spaces = [
3922
3932
  ...context.spaceManager.spaces.values()
3923
3933
  ];
3924
- 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)));
3925
3935
  next({
3926
3936
  spaces: filteredSpaces.map((space) => {
3927
3937
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
3928
3938
  return {
3929
3939
  key: space.key,
3930
3940
  isOpen: space.isOpen,
3931
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
3941
+ timeframe: spaceMetadata?.dataTimeframe,
3932
3942
  genesisFeed: space.genesisFeedKey,
3933
3943
  controlFeed: space.controlFeedKey,
3934
3944
  dataFeed: space.dataFeedKey
@@ -3942,7 +3952,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
3942
3952
  await update();
3943
3953
  });
3944
3954
  return () => {
3945
- unsubscribe == null ? void 0 : unsubscribe();
3955
+ unsubscribe?.();
3946
3956
  clearTimeout(timeout);
3947
3957
  };
3948
3958
  });
@@ -3973,16 +3983,15 @@ var DevtoolsServiceImpl = class {
3973
3983
  };
3974
3984
  }
3975
3985
  async getStorageInfo() {
3976
- var _a, _b, _c, _d, _e;
3977
- 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?.() ?? {
3978
3987
  used: 0
3979
3988
  };
3980
3989
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
3981
3990
  return {
3982
3991
  type: this.params.context.storage.type,
3983
3992
  storageUsage: storageUsage.used,
3984
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
3985
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
3993
+ originUsage: navigatorInfo?.usage ?? 0,
3994
+ usageQuota: navigatorInfo?.quota ?? 0
3986
3995
  };
3987
3996
  }
3988
3997
  async getBlobs() {
@@ -4090,7 +4099,6 @@ var Lock = class {
4090
4099
  return this._lockPath;
4091
4100
  }
4092
4101
  async acquire() {
4093
- var _a;
4094
4102
  (0, import_log14.log)("acquiring lock...", void 0, {
4095
4103
  F: __dxlog_file16,
4096
4104
  L: 32,
@@ -4098,7 +4106,7 @@ var Lock = class {
4098
4106
  C: (f, a) => f(...a)
4099
4107
  });
4100
4108
  this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
4101
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4109
+ await this._onAcquire?.();
4102
4110
  (0, import_log14.log)("acquired lock", void 0, {
4103
4111
  F: __dxlog_file16,
4104
4112
  L: 37,
@@ -4107,8 +4115,7 @@ var Lock = class {
4107
4115
  });
4108
4116
  }
4109
4117
  async release() {
4110
- var _a;
4111
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4118
+ await this._onRelease?.();
4112
4119
  (0, import_invariant13.invariant)(this._fileHandle, "Lock is not acquired", {
4113
4120
  F: __dxlog_file16,
4114
4121
  L: 42,
@@ -4130,11 +4137,11 @@ var import_async16 = require("@dxos/async");
4130
4137
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
4131
4138
  var import_log15 = require("@dxos/log");
4132
4139
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
4133
- var import_util7 = require("@dxos/util");
4140
+ var import_util8 = require("@dxos/util");
4134
4141
  var LoggingServiceImpl = class {
4135
4142
  constructor() {
4136
4143
  this._logs = new import_async16.Event();
4137
- this._started = new Date();
4144
+ this._started = /* @__PURE__ */ new Date();
4138
4145
  this._logProcessor = (_config, entry2) => {
4139
4146
  this._logs.emit(entry2);
4140
4147
  };
@@ -4148,15 +4155,15 @@ var LoggingServiceImpl = class {
4148
4155
  }
4149
4156
  async controlMetrics({ reset, record }) {
4150
4157
  if (reset) {
4151
- import_util7.tracer.clear();
4158
+ import_util8.tracer.clear();
4152
4159
  }
4153
4160
  if (record === true) {
4154
- import_util7.tracer.start();
4161
+ import_util8.tracer.start();
4155
4162
  } else if (record === false) {
4156
- import_util7.tracer.stop();
4163
+ import_util8.tracer.stop();
4157
4164
  }
4158
4165
  return {
4159
- recording: import_util7.tracer.recording
4166
+ recording: import_util8.tracer.recording
4160
4167
  };
4161
4168
  }
4162
4169
  /**
@@ -4164,24 +4171,23 @@ var LoggingServiceImpl = class {
4164
4171
  */
4165
4172
  queryMetrics({ interval = 5e3 }) {
4166
4173
  const getNumericalValues = (key) => {
4167
- var _a;
4168
- const events = (_a = import_util7.tracer.get(key)) != null ? _a : [];
4174
+ const events = import_util8.tracer.get(key) ?? [];
4169
4175
  return {
4170
4176
  key,
4171
- stats: (0, import_util7.numericalValues)(events, "duration")
4177
+ stats: (0, import_util8.numericalValues)(events, "duration")
4172
4178
  };
4173
4179
  };
4174
4180
  return new import_codec_protobuf13.Stream(({ next }) => {
4175
4181
  const update = () => {
4176
4182
  const metrics = {
4177
- timestamp: new Date(),
4183
+ timestamp: /* @__PURE__ */ new Date(),
4178
4184
  values: [
4179
4185
  getNumericalValues("dxos.echo.pipeline.control"),
4180
4186
  getNumericalValues("dxos.echo.pipeline.data")
4181
4187
  ].filter(Boolean)
4182
4188
  };
4183
4189
  next({
4184
- timestamp: new Date(),
4190
+ timestamp: /* @__PURE__ */ new Date(),
4185
4191
  metrics
4186
4192
  });
4187
4193
  };
@@ -4195,11 +4201,10 @@ var LoggingServiceImpl = class {
4195
4201
  queryLogs(request) {
4196
4202
  return new import_codec_protobuf13.Stream(({ ctx, next }) => {
4197
4203
  const handler = (entry2) => {
4198
- var _a, _b, _c, _d, _e;
4199
4204
  if (LOG_PROCESSING > 0) {
4200
4205
  return;
4201
4206
  }
4202
- 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"))) {
4203
4208
  return;
4204
4209
  }
4205
4210
  if (!shouldLog(entry2, request)) {
@@ -4207,12 +4212,12 @@ var LoggingServiceImpl = class {
4207
4212
  }
4208
4213
  const record = {
4209
4214
  ...entry2,
4210
- context: (0, import_util7.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4211
- timestamp: new Date(),
4215
+ context: (0, import_util8.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
4216
+ timestamp: /* @__PURE__ */ new Date(),
4212
4217
  meta: {
4213
4218
  // TODO(dmaretskyi): Fix proto.
4214
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4215
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4219
+ file: entry2.meta?.F ?? "",
4220
+ line: entry2.meta?.L ?? 0
4216
4221
  }
4217
4222
  };
4218
4223
  try {
@@ -4235,15 +4240,11 @@ var matchFilter = (filter, level, path, options) => {
4235
4240
  }
4236
4241
  };
4237
4242
  var shouldLog = (entry2, request) => {
4238
- var _a;
4239
- const options = (_a = request.options) != null ? _a : import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4243
+ const options = request.options ?? import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4240
4244
  if (request.filters === void 0) {
4241
4245
  return options === import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
4242
4246
  } else {
4243
- return request.filters.some((filter) => {
4244
- var _a2, _b;
4245
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4246
- });
4247
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4247
4248
  }
4248
4249
  };
4249
4250
  var LOG_PROCESSING = 0;
@@ -4285,10 +4286,10 @@ var import_client_protocol4 = require("@dxos/client-protocol");
4285
4286
  var import_errors5 = require("@dxos/errors");
4286
4287
  var import_config = require("@dxos/protocols/proto/dxos/config");
4287
4288
  var import_random_access_storage = require("@dxos/random-access-storage");
4288
- var import_util8 = require("@dxos/util");
4289
+ var import_util9 = require("@dxos/util");
4289
4290
  var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4290
4291
  var createStorageObjects = (config) => {
4291
- 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 ?? {};
4292
4293
  if (persistent && storageType === StorageDriver.RAM) {
4293
4294
  throw new import_errors5.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4294
4295
  }
@@ -4332,7 +4333,7 @@ var toStorageType = (type) => {
4332
4333
  // packages/sdk/client-services/src/packlets/system/system-service.ts
4333
4334
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
4334
4335
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
4335
- var import_util9 = require("@dxos/util");
4336
+ var import_util10 = require("@dxos/util");
4336
4337
  var SystemServiceImpl = class {
4337
4338
  constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
4338
4339
  this._config = config;
@@ -4343,8 +4344,7 @@ var SystemServiceImpl = class {
4343
4344
  this._onReset = onReset;
4344
4345
  }
4345
4346
  async getConfig() {
4346
- var _a, _b;
4347
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4347
+ return this._config?.values ?? {};
4348
4348
  }
4349
4349
  /**
4350
4350
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4352,8 +4352,8 @@ var SystemServiceImpl = class {
4352
4352
  async getDiagnostics({ keys } = {}) {
4353
4353
  const diagnostics = await this._getDiagnostics();
4354
4354
  return {
4355
- timestamp: new Date(),
4356
- 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)({
4357
4357
  truncate: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4358
4358
  humanize: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
4359
4359
  })))
@@ -4467,11 +4467,10 @@ var ClientServicesHost = class ClientServicesHost2 {
4467
4467
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4468
4468
  },
4469
4469
  onUpdateStatus: async (status) => {
4470
- var _a, _b;
4471
4470
  if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
4472
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4471
+ await this._resourceLock?.acquire();
4473
4472
  } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
4474
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4473
+ await this._resourceLock?.release();
4475
4474
  }
4476
4475
  },
4477
4476
  onReset: async () => {
@@ -4508,7 +4507,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4508
4507
  * Can only be called once.
4509
4508
  */
4510
4509
  initialize({ config, ...options }) {
4511
- var _a, _b, _c;
4512
4510
  (0, import_invariant14.invariant)(!this._open, "service host is open", {
4513
4511
  F: __dxlog_file17,
4514
4512
  L: 181,
@@ -4518,7 +4516,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4518
4516
  "'service host is open'"
4519
4517
  ]
4520
4518
  });
4521
- import_log16.log.info("initializing...", void 0, {
4519
+ (0, import_log16.log)("initializing...", void 0, {
4522
4520
  F: __dxlog_file17,
4523
4521
  L: 182,
4524
4522
  S: this,
@@ -4540,8 +4538,8 @@ var ClientServicesHost = class ClientServicesHost2 {
4540
4538
  }
4541
4539
  }
4542
4540
  const { connectionLog = true, transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
4543
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4544
- }), 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;
4545
4543
  this._signalManager = signalManager;
4546
4544
  (0, import_invariant14.invariant)(!this._networkManager, "network manager already set", {
4547
4545
  F: __dxlog_file17,
@@ -4557,7 +4555,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4557
4555
  transportFactory,
4558
4556
  signalManager
4559
4557
  });
4560
- import_log16.log.info("initialized", void 0, {
4558
+ (0, import_log16.log)("initialized", void 0, {
4561
4559
  F: __dxlog_file17,
4562
4560
  L: 208,
4563
4561
  S: this,
@@ -4565,7 +4563,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4565
4563
  });
4566
4564
  }
4567
4565
  async open(ctx) {
4568
- var _a, _b, _c;
4569
4566
  if (this._open) {
4570
4567
  return;
4571
4568
  }
@@ -4615,20 +4612,20 @@ var ClientServicesHost = class ClientServicesHost2 {
4615
4612
  ]
4616
4613
  });
4617
4614
  this._opening = true;
4618
- import_log16.log.info("opening...", {
4619
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4615
+ (0, import_log16.log)("opening...", {
4616
+ lockKey: this._resourceLock?.lockKey
4620
4617
  }, {
4621
4618
  F: __dxlog_file17,
4622
4619
  L: 227,
4623
4620
  S: this,
4624
4621
  C: (f, a) => f(...a)
4625
4622
  });
4626
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4623
+ await this._resourceLock?.acquire();
4627
4624
  await this._loggingService.open();
4628
4625
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4629
4626
  this._serviceRegistry.setServices({
4630
4627
  SystemService: this._systemService,
4631
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4628
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4632
4629
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4633
4630
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4634
4631
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4650,12 +4647,12 @@ var ClientServicesHost = class ClientServicesHost2 {
4650
4647
  this._opening = false;
4651
4648
  this._open = true;
4652
4649
  this._statusUpdate.emit();
4653
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4654
- import_log16.log.info("opened", {
4650
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4651
+ (0, import_log16.log)("opened", {
4655
4652
  deviceKey
4656
4653
  }, {
4657
4654
  F: __dxlog_file17,
4658
- L: 280,
4655
+ L: 284,
4659
4656
  S: this,
4660
4657
  C: (f, a) => f(...a)
4661
4658
  });
@@ -4663,22 +4660,21 @@ var ClientServicesHost = class ClientServicesHost2 {
4663
4660
  id: traceId
4664
4661
  }), {
4665
4662
  F: __dxlog_file17,
4666
- L: 281,
4663
+ L: 285,
4667
4664
  S: this,
4668
4665
  C: (f, a) => f(...a)
4669
4666
  });
4670
4667
  }
4671
4668
  async close() {
4672
- var _a;
4673
4669
  if (!this._open) {
4674
4670
  return;
4675
4671
  }
4676
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4677
- import_log16.log.info("closing...", {
4672
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4673
+ (0, import_log16.log)("closing...", {
4678
4674
  deviceKey
4679
4675
  }, {
4680
4676
  F: __dxlog_file17,
4681
- L: 292,
4677
+ L: 296,
4682
4678
  S: this,
4683
4679
  C: (f, a) => f(...a)
4684
4680
  });
@@ -4689,37 +4685,36 @@ var ClientServicesHost = class ClientServicesHost2 {
4689
4685
  await this._serviceContext.close();
4690
4686
  this._open = false;
4691
4687
  this._statusUpdate.emit();
4692
- import_log16.log.info("closed", {
4688
+ (0, import_log16.log)("closed", {
4693
4689
  deviceKey
4694
4690
  }, {
4695
4691
  F: __dxlog_file17,
4696
- L: 298,
4692
+ L: 302,
4697
4693
  S: this,
4698
4694
  C: (f, a) => f(...a)
4699
4695
  });
4700
4696
  }
4701
4697
  async reset() {
4702
- var _a, _b, _c;
4703
4698
  const traceId = import_keys12.PublicKey.random().toHex();
4704
4699
  import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.begin({
4705
4700
  id: traceId
4706
4701
  }), {
4707
4702
  F: __dxlog_file17,
4708
- L: 303,
4703
+ L: 307,
4709
4704
  S: this,
4710
4705
  C: (f, a) => f(...a)
4711
4706
  });
4712
4707
  (0, import_log16.log)("resetting...", void 0, {
4713
4708
  F: __dxlog_file17,
4714
- L: 305,
4709
+ L: 309,
4715
4710
  S: this,
4716
4711
  C: (f, a) => f(...a)
4717
4712
  });
4718
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4713
+ await this._serviceContext?.close();
4719
4714
  await this._storage.reset();
4720
4715
  (0, import_log16.log)("reset", void 0, {
4721
4716
  F: __dxlog_file17,
4722
- L: 308,
4717
+ L: 312,
4723
4718
  S: this,
4724
4719
  C: (f, a) => f(...a)
4725
4720
  });
@@ -4727,11 +4722,11 @@ var ClientServicesHost = class ClientServicesHost2 {
4727
4722
  id: traceId
4728
4723
  }), {
4729
4724
  F: __dxlog_file17,
4730
- L: 309,
4725
+ L: 313,
4731
4726
  S: this,
4732
4727
  C: (f, a) => f(...a)
4733
4728
  });
4734
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4729
+ await this._callbacks?.onReset?.();
4735
4730
  }
4736
4731
  };
4737
4732
  _ts_decorate7([
@@ -4771,18 +4766,16 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4771
4766
  const authCode = new import_async18.Trigger();
4772
4767
  const hostObservable = createInvitation(host, options);
4773
4768
  hostObservable.subscribe(async (hostInvitation) => {
4774
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
4775
4769
  switch (hostInvitation.state) {
4776
4770
  case import_services15.Invitation.State.CONNECTING: {
4777
- 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)) {
4778
4772
  break;
4779
4773
  }
4780
4774
  const guestObservable = acceptInvitation(guest, hostInvitation);
4781
4775
  guestObservable.subscribe(async (guestInvitation) => {
4782
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
4783
4776
  switch (guestInvitation.state) {
4784
4777
  case import_services15.Invitation.State.CONNECTING: {
4785
- 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)) {
4786
4779
  break;
4787
4780
  }
4788
4781
  (0, import_invariant15.invariant)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey), void 0, {
@@ -4797,22 +4790,22 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4797
4790
  break;
4798
4791
  }
4799
4792
  case import_services15.Invitation.State.CONNECTED: {
4800
- (_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);
4801
4794
  break;
4802
4795
  }
4803
4796
  case import_services15.Invitation.State.READY_FOR_AUTHENTICATION: {
4804
- 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)) {
4805
4798
  break;
4806
4799
  }
4807
4800
  await guestObservable.authenticate(await authCode.wait());
4808
4801
  break;
4809
4802
  }
4810
4803
  case import_services15.Invitation.State.AUTHENTICATING: {
4811
- (_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);
4812
4805
  break;
4813
4806
  }
4814
4807
  case import_services15.Invitation.State.SUCCESS: {
4815
- 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)) {
4816
4809
  break;
4817
4810
  }
4818
4811
  guestComplete.wake({
@@ -4821,7 +4814,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4821
4814
  break;
4822
4815
  }
4823
4816
  case import_services15.Invitation.State.CANCELLED: {
4824
- 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)) {
4825
4818
  break;
4826
4819
  }
4827
4820
  guestComplete.wake({
@@ -4830,7 +4823,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4830
4823
  break;
4831
4824
  }
4832
4825
  case import_services15.Invitation.State.TIMEOUT: {
4833
- 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)) {
4834
4827
  return;
4835
4828
  }
4836
4829
  guestComplete.wake({
@@ -4839,8 +4832,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4839
4832
  }
4840
4833
  }
4841
4834
  }, (error) => {
4842
- var _a2, _b2;
4843
- 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)) {
4844
4836
  return;
4845
4837
  }
4846
4838
  guestComplete.wake({
@@ -4850,11 +4842,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4850
4842
  break;
4851
4843
  }
4852
4844
  case import_services15.Invitation.State.CONNECTED: {
4853
- (_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);
4854
4846
  break;
4855
4847
  }
4856
4848
  case import_services15.Invitation.State.READY_FOR_AUTHENTICATION: {
4857
- 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)) {
4858
4850
  break;
4859
4851
  }
4860
4852
  if (hostInvitation.authCode) {
@@ -4863,11 +4855,11 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4863
4855
  break;
4864
4856
  }
4865
4857
  case import_services15.Invitation.State.AUTHENTICATING: {
4866
- (_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);
4867
4859
  break;
4868
4860
  }
4869
4861
  case import_services15.Invitation.State.SUCCESS: {
4870
- 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)) {
4871
4863
  break;
4872
4864
  }
4873
4865
  hostComplete.wake({
@@ -4876,7 +4868,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4876
4868
  break;
4877
4869
  }
4878
4870
  case import_services15.Invitation.State.CANCELLED: {
4879
- 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)) {
4880
4872
  break;
4881
4873
  }
4882
4874
  hostComplete.wake({
@@ -4885,7 +4877,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4885
4877
  break;
4886
4878
  }
4887
4879
  case import_services15.Invitation.State.TIMEOUT: {
4888
- 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)) {
4889
4881
  break;
4890
4882
  }
4891
4883
  hostComplete.wake({
@@ -4895,8 +4887,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4895
4887
  }
4896
4888
  }
4897
4889
  }, (error) => {
4898
- var _a, _b;
4899
- 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)) {
4900
4891
  return;
4901
4892
  }
4902
4893
  hostComplete.wake({
@@ -4909,9 +4900,9 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4909
4900
  ];
4910
4901
  };
4911
4902
  var createInvitation = (host, options) => {
4912
- options != null ? options : options = {
4903
+ options ??= {
4913
4904
  authMethod: import_services15.Invitation.AuthMethod.NONE,
4914
- ...options != null ? options : {}
4905
+ ...options ?? {}
4915
4906
  };
4916
4907
  if (host instanceof ServiceContext) {
4917
4908
  const hostHandler = host.getInvitationHandler({
@@ -5007,18 +4998,15 @@ var TestPeer = class {
5007
4998
  return this._props;
5008
4999
  }
5009
5000
  get storage() {
5010
- var _a, _b;
5011
- 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)({
5012
5002
  type: this.opts.storageType
5013
5003
  });
5014
5004
  }
5015
5005
  get keyring() {
5016
- var _a, _b;
5017
- 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"));
5018
5007
  }
5019
5008
  get feedStore() {
5020
- var _a, _b;
5021
- 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({
5022
5010
  factory: new import_feed_store5.FeedFactory({
5023
5011
  root: this.storage.createDirectory("feeds"),
5024
5012
  signer: this.keyring,
@@ -5029,27 +5017,22 @@ var TestPeer = class {
5029
5017
  });
5030
5018
  }
5031
5019
  get metadataStore() {
5032
- var _a, _b;
5033
- 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"));
5034
5021
  }
5035
5022
  get blobStore() {
5036
- var _a, _b;
5037
- 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"));
5038
5024
  }
5039
5025
  get snapshotStore() {
5040
- var _a, _b;
5041
- 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"));
5042
5027
  }
5043
5028
  get networkManager() {
5044
- var _a, _b;
5045
- 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({
5046
5030
  signalManager: new import_messaging2.MemorySignalManager(this.signalContext),
5047
5031
  transportFactory: import_network_manager3.MemoryTransportFactory
5048
5032
  });
5049
5033
  }
5050
5034
  get spaceManager() {
5051
- var _a, _b;
5052
- 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({
5053
5036
  feedStore: this.feedStore,
5054
5037
  networkManager: this.networkManager,
5055
5038
  metadataStore: this.metadataStore,
@@ -5059,16 +5042,13 @@ var TestPeer = class {
5059
5042
  });
5060
5043
  }
5061
5044
  get identity() {
5062
- var _a;
5063
- return (_a = this._props.signingContext) != null ? _a : (0, import_debug8.failUndefined)();
5045
+ return this._props.signingContext ?? (0, import_debug8.failUndefined)();
5064
5046
  }
5065
5047
  get dataSpaceManager() {
5066
- var _a, _b;
5067
- 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);
5068
5049
  }
5069
5050
  async createIdentity() {
5070
- var _a, _b;
5071
- (_b = (_a = this._props).signingContext) != null ? _b : _a.signingContext = await createSigningContext(this.keyring);
5051
+ this._props.signingContext ??= await createSigningContext(this.keyring);
5072
5052
  }
5073
5053
  async destroy() {
5074
5054
  await this.storage.reset();