@dxos/client-services 0.1.56-main.01afb72 → 0.1.56-main.0e9f69e

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 (33) hide show
  1. package/dist/lib/browser/{chunk-53BV3Q7V.mjs → chunk-II6TDINB.mjs} +243 -256
  2. package/dist/lib/browser/chunk-II6TDINB.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 +263 -281
  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 +275 -299
  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/services/service-context.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  20. package/dist/types/src/version.d.ts +1 -1
  21. package/package.json +34 -34
  22. package/src/packlets/identity/identity-manager.test.ts +11 -0
  23. package/src/packlets/identity/identity-manager.ts +18 -1
  24. package/src/packlets/identity/identity-service.test.ts +15 -1
  25. package/src/packlets/identity/identity-service.ts +23 -14
  26. package/src/packlets/services/service-context.test.ts +59 -0
  27. package/src/packlets/services/service-context.ts +3 -0
  28. package/src/packlets/services/service-host.ts +11 -7
  29. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  30. package/src/packlets/spaces/data-space.ts +16 -4
  31. package/src/packlets/vault/worker-runtime.ts +1 -1
  32. package/src/version.ts +1 -1
  33. package/dist/lib/browser/chunk-53BV3Q7V.mjs.map +0 -7
@@ -12,7 +12,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
12
12
  const feedMap = new ComplexMap(PublicKey.hash);
13
13
  const update = () => {
14
14
  const { feeds } = feedStore;
15
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
15
+ feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
16
16
  if (!feedMap.has(feed.key)) {
17
17
  feedMap.set(feed.key, feed);
18
18
  feed.on("close", update);
@@ -20,15 +20,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
20
20
  }
21
21
  });
22
22
  next({
23
- feeds: Array.from(feedMap.values()).map((feed) => {
24
- var _a, _b;
25
- return {
26
- feedKey: feed.key,
27
- length: feed.properties.length,
28
- bytes: feed.core.byteLength,
29
- downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
30
- };
31
- })
23
+ feeds: Array.from(feedMap.values()).map((feed) => ({
24
+ feedKey: feed.key,
25
+ length: feed.properties.length,
26
+ bytes: feed.core.byteLength,
27
+ downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
28
+ }))
32
29
  });
33
30
  };
34
31
  subscriptions.add(feedStore.feedOpened.on(update));
@@ -104,13 +101,13 @@ var subscribeToSignal = ({ signalManager }) => new Stream2(({ next }) => {
104
101
  recipient: message.recipient.asUint8Array(),
105
102
  payload: message.payload
106
103
  },
107
- receivedAt: new Date()
104
+ receivedAt: /* @__PURE__ */ new Date()
108
105
  });
109
106
  });
110
107
  signalManager.swarmEvent.on(ctx, (swarmEvent) => {
111
108
  next({
112
109
  swarmEvent: swarmEvent.swarmEvent,
113
- receivedAt: new Date()
110
+ receivedAt: /* @__PURE__ */ new Date()
114
111
  });
115
112
  });
116
113
  return () => {
@@ -121,13 +118,10 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
121
118
  const update = () => {
122
119
  try {
123
120
  const topics = networkManager.topics;
124
- const labeledTopics = topics.map((topic) => {
125
- var _a, _b;
126
- return {
127
- topic,
128
- label: (_b = (_a = networkManager.getSwarm(topic)) == null ? void 0 : _a.label) != null ? _b : topic.toHex()
129
- };
130
- });
121
+ const labeledTopics = topics.map((topic) => ({
122
+ topic,
123
+ label: networkManager.getSwarm(topic)?.label ?? topic.toHex()
124
+ }));
131
125
  next({
132
126
  topics: labeledTopics
133
127
  });
@@ -139,17 +133,15 @@ var subscribeToNetworkTopics = ({ networkManager }) => new Stream2(({ next, clos
139
133
  update();
140
134
  });
141
135
  var subscribeToSwarmInfo = ({ networkManager }) => new Stream2(({ next }) => {
142
- var _a;
143
136
  const update = () => {
144
- var _a2;
145
- const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
137
+ const info = networkManager.connectionLog?.swarms;
146
138
  if (info) {
147
139
  next({
148
140
  data: info
149
141
  });
150
142
  }
151
143
  };
152
- (_a = networkManager.connectionLog) == null ? void 0 : _a.update.on(update);
144
+ networkManager.connectionLog?.update.on(update);
153
145
  update();
154
146
  });
155
147
  var getNetworkPeers = ({ networkManager }, request) => {
@@ -158,7 +150,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
158
150
  }
159
151
  const map = networkManager.getSwarmMap(PublicKey2.from(request.topic));
160
152
  return {
161
- peers: map == null ? void 0 : map.peers.map((peer) => ({
153
+ peers: map?.peers.map((peer) => ({
162
154
  ...peer,
163
155
  connections: peer.connections.map((connection) => connection.asUint8Array())
164
156
  }))
@@ -174,14 +166,14 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
174
166
  const spaces = [
175
167
  ...context.spaceManager.spaces.values()
176
168
  ];
177
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
169
+ const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
178
170
  next({
179
171
  spaces: filteredSpaces.map((space) => {
180
172
  const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
181
173
  return {
182
174
  key: space.key,
183
175
  isOpen: space.isOpen,
184
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
176
+ timeframe: spaceMetadata?.dataTimeframe,
185
177
  genesisFeed: space.genesisFeedKey,
186
178
  controlFeed: space.controlFeedKey,
187
179
  dataFeed: space.dataFeedKey
@@ -195,7 +187,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
195
187
  await update();
196
188
  });
197
189
  return () => {
198
- unsubscribe == null ? void 0 : unsubscribe();
190
+ unsubscribe?.();
199
191
  clearTimeout(timeout);
200
192
  };
201
193
  });
@@ -254,16 +246,15 @@ var DevtoolsServiceImpl = class {
254
246
  };
255
247
  }
256
248
  async getStorageInfo() {
257
- var _a, _b, _c, _d, _e;
258
- const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
249
+ const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
259
250
  used: 0
260
251
  };
261
252
  const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
262
253
  return {
263
254
  type: this.params.context.storage.type,
264
255
  storageUsage: storageUsage.used,
265
- originUsage: (_d = navigatorInfo == null ? void 0 : navigatorInfo.usage) != null ? _d : 0,
266
- usageQuota: (_e = navigatorInfo == null ? void 0 : navigatorInfo.quota) != null ? _e : 0
256
+ originUsage: navigatorInfo?.usage ?? 0,
257
+ usageQuota: navigatorInfo?.quota ?? 0
267
258
  };
268
259
  }
269
260
  async getBlobs() {
@@ -449,7 +440,7 @@ var TrustedKeySetAuthVerifier = class {
449
440
  return await trigger.wait({
450
441
  timeout: this._params.authTimeout
451
442
  });
452
- } catch (e) {
443
+ } catch {
453
444
  return false;
454
445
  } finally {
455
446
  clear();
@@ -545,11 +536,10 @@ var Identity = class Identity2 {
545
536
  return this._deviceStateMachine.deviceCredentialChain;
546
537
  }
547
538
  getAdmissionCredentials() {
548
- var _a, _b;
549
539
  return {
550
540
  deviceKey: this.deviceKey,
551
- controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : failUndefined(),
552
- dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : failUndefined()
541
+ controlFeedKey: this.space.controlFeedKey ?? failUndefined(),
542
+ dataFeedKey: this.space.dataFeedKey ?? failUndefined()
553
543
  };
554
544
  }
555
545
  /**
@@ -643,6 +633,7 @@ import { PublicKey as PublicKey3 } from "@dxos/keys";
643
633
  import { log as log3 } from "@dxos/log";
644
634
  import { trace as trace2 } from "@dxos/protocols";
645
635
  import { AdmittedFeed as AdmittedFeed2 } from "@dxos/protocols/proto/dxos/halo/credentials";
636
+ import { Timeframe } from "@dxos/timeframe";
646
637
  import { trace as Trace } from "@dxos/tracing";
647
638
  import { deferFunction } from "@dxos/util";
648
639
  function _ts_decorate2(decorators, target, key, desc) {
@@ -670,7 +661,6 @@ var IdentityManager = class IdentityManager2 {
670
661
  return this._identity;
671
662
  }
672
663
  async open(ctx) {
673
- var _a;
674
664
  const traceId = PublicKey3.random().toHex();
675
665
  log3.trace("dxos.halo.identity-manager.open", trace2.begin({
676
666
  id: traceId
@@ -696,7 +686,7 @@ var IdentityManager = class IdentityManager2 {
696
686
  await this._identity.ready();
697
687
  log3.trace("dxos.halo.identity", {
698
688
  identityKey: identityRecord.identityKey,
699
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
689
+ displayName: this._identity.profileDocument?.displayName
700
690
  }, {
701
691
  F: __dxlog_file3,
702
692
  L: 82,
@@ -715,11 +705,9 @@ var IdentityManager = class IdentityManager2 {
715
705
  });
716
706
  }
717
707
  async close() {
718
- var _a;
719
- await ((_a = this._identity) == null ? void 0 : _a.close(new Context3()));
708
+ await this._identity?.close(new Context3());
720
709
  }
721
710
  async createIdentity({ displayName } = {}) {
722
- var _a;
723
711
  invariant2(!this._identity, "Identity already exists.", {
724
712
  F: __dxlog_file3,
725
713
  L: 96,
@@ -793,7 +781,7 @@ var IdentityManager = class IdentityManager2 {
793
781
  await this._identity.ready();
794
782
  log3.trace("dxos.halo.identity", {
795
783
  identityKey: identityRecord.identityKey,
796
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
784
+ displayName: this._identity.profileDocument?.displayName
797
785
  }, {
798
786
  F: __dxlog_file3,
799
787
  L: 152,
@@ -816,7 +804,6 @@ var IdentityManager = class IdentityManager2 {
816
804
  * Accept an existing identity. Expects it's device key to be authorized (now or later).
817
805
  */
818
806
  async acceptIdentity(params) {
819
- var _a;
820
807
  log3("accepting identity", {
821
808
  params
822
809
  }, {
@@ -852,7 +839,7 @@ var IdentityManager = class IdentityManager2 {
852
839
  await this._identity.ready();
853
840
  log3.trace("dxos.halo.identity", {
854
841
  identityKey: identityRecord.identityKey,
855
- displayName: (_a = this._identity.profileDocument) == null ? void 0 : _a.displayName
842
+ displayName: this._identity.profileDocument?.displayName
856
843
  }, {
857
844
  F: __dxlog_file3,
858
845
  L: 186,
@@ -871,10 +858,42 @@ var IdentityManager = class IdentityManager2 {
871
858
  });
872
859
  return identity;
873
860
  }
861
+ /**
862
+ * Update the profile document of an existing identity.
863
+ */
864
+ async updateProfile(profile) {
865
+ invariant2(this._identity, "Identity not initialized.", {
866
+ F: __dxlog_file3,
867
+ L: 200,
868
+ S: this,
869
+ A: [
870
+ "this._identity",
871
+ "'Identity not initialized.'"
872
+ ]
873
+ });
874
+ const credential = await this._identity.getIdentityCredentialSigner().createCredential({
875
+ subject: this._identity.identityKey,
876
+ assertion: {
877
+ "@type": "dxos.halo.credentials.IdentityProfile",
878
+ profile
879
+ }
880
+ });
881
+ const receipt = await this._identity.controlPipeline.writer.write({
882
+ credential: {
883
+ credential
884
+ }
885
+ });
886
+ await this._identity.controlPipeline.state.waitUntilTimeframe(new Timeframe([
887
+ [
888
+ receipt.feedKey,
889
+ receipt.seq
890
+ ]
891
+ ]));
892
+ }
874
893
  async _constructIdentity(identityRecord) {
875
894
  invariant2(!this._identity, void 0, {
876
895
  F: __dxlog_file3,
877
- L: 197,
896
+ L: 214,
878
897
  S: this,
879
898
  A: [
880
899
  "!this._identity",
@@ -885,13 +904,13 @@ var IdentityManager = class IdentityManager2 {
885
904
  identityRecord
886
905
  }, {
887
906
  F: __dxlog_file3,
888
- L: 198,
907
+ L: 215,
889
908
  S: this,
890
909
  C: (f, a) => f(...a)
891
910
  });
892
911
  invariant2(identityRecord.haloSpace.controlFeedKey, void 0, {
893
912
  F: __dxlog_file3,
894
- L: 201,
913
+ L: 218,
895
914
  S: this,
896
915
  A: [
897
916
  "identityRecord.haloSpace.controlFeedKey",
@@ -903,7 +922,7 @@ var IdentityManager = class IdentityManager2 {
903
922
  });
904
923
  invariant2(identityRecord.haloSpace.dataFeedKey, void 0, {
905
924
  F: __dxlog_file3,
906
- L: 205,
925
+ L: 222,
907
926
  S: this,
908
927
  A: [
909
928
  "identityRecord.haloSpace.dataFeedKey",
@@ -935,7 +954,7 @@ var IdentityManager = class IdentityManager2 {
935
954
  identityKey: identityRecord.identityKey
936
955
  }, {
937
956
  F: __dxlog_file3,
938
- L: 229,
957
+ L: 246,
939
958
  S: this,
940
959
  C: (f, a) => f(...a)
941
960
  });
@@ -956,7 +975,7 @@ var IdentityManager = class IdentityManager2 {
956
975
  onAuthFailure: () => {
957
976
  log3.warn("auth failure", void 0, {
958
977
  F: __dxlog_file3,
959
- L: 248,
978
+ L: 265,
960
979
  S: this,
961
980
  C: (f, a) => f(...a)
962
981
  });
@@ -979,12 +998,13 @@ import { todo } from "@dxos/debug";
979
998
  import { invariant as invariant3 } from "@dxos/invariant";
980
999
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
981
1000
  var IdentityServiceImpl = class {
982
- // TODO(wittjosiah): Remove dependency on service context.
983
- constructor(_serviceContext) {
984
- this._serviceContext = _serviceContext;
1001
+ constructor(_createIdentity, _identityManager, _keyring) {
1002
+ this._createIdentity = _createIdentity;
1003
+ this._identityManager = _identityManager;
1004
+ this._keyring = _keyring;
985
1005
  }
986
1006
  async createIdentity(request) {
987
- await this._serviceContext.createIdentity(request);
1007
+ await this._createIdentity(request);
988
1008
  return this._getIdentity();
989
1009
  }
990
1010
  async recoverIdentity(request) {
@@ -996,34 +1016,47 @@ var IdentityServiceImpl = class {
996
1016
  identity: this._getIdentity()
997
1017
  });
998
1018
  emitNext();
999
- return this._serviceContext.identityManager.stateUpdate.on(emitNext);
1019
+ return this._identityManager.stateUpdate.on(emitNext);
1000
1020
  });
1001
1021
  }
1002
1022
  _getIdentity() {
1003
- if (!this._serviceContext.identityManager.identity) {
1023
+ if (!this._identityManager.identity) {
1004
1024
  return void 0;
1005
1025
  }
1006
1026
  return {
1007
- identityKey: this._serviceContext.identityManager.identity.identityKey,
1008
- spaceKey: this._serviceContext.identityManager.identity.space.key,
1009
- profile: this._serviceContext.identityManager.identity.profileDocument
1027
+ identityKey: this._identityManager.identity.identityKey,
1028
+ spaceKey: this._identityManager.identity.space.key,
1029
+ profile: this._identityManager.identity.profileDocument
1010
1030
  };
1011
1031
  }
1032
+ async updateProfile(profile) {
1033
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
1034
+ F: __dxlog_file4,
1035
+ L: 59,
1036
+ S: this,
1037
+ A: [
1038
+ "this._identityManager.identity",
1039
+ "'Identity not initialized.'"
1040
+ ]
1041
+ });
1042
+ await this._identityManager.updateProfile(profile);
1043
+ return this._getIdentity();
1044
+ }
1012
1045
  async signPresentation({ presentation, nonce }) {
1013
- invariant3(this._serviceContext.identityManager.identity, "Identity not initialized.", {
1046
+ invariant3(this._identityManager.identity, "Identity not initialized.", {
1014
1047
  F: __dxlog_file4,
1015
- L: 56,
1048
+ L: 65,
1016
1049
  S: this,
1017
1050
  A: [
1018
- "this._serviceContext.identityManager.identity",
1051
+ "this._identityManager.identity",
1019
1052
  "'Identity not initialized.'"
1020
1053
  ]
1021
1054
  });
1022
1055
  return await signPresentation({
1023
1056
  presentation,
1024
- signer: this._serviceContext.keyring,
1025
- signerKey: this._serviceContext.identityManager.identity.deviceKey,
1026
- chain: this._serviceContext.identityManager.identity.deviceCredentialChain,
1057
+ signer: this._keyring,
1058
+ signerKey: this._identityManager.identity.deviceKey,
1059
+ chain: this._identityManager.identity.deviceCredentialChain,
1027
1060
  nonce
1028
1061
  });
1029
1062
  }
@@ -1359,7 +1392,6 @@ var InvitationHostExtension = class extends RpcExtension {
1359
1392
  };
1360
1393
  }
1361
1394
  async onOpen(context) {
1362
- var _a;
1363
1395
  await super.onOpen(context);
1364
1396
  try {
1365
1397
  await this.rpc.InvitationHostService.options({
@@ -1368,7 +1400,7 @@ var InvitationHostExtension = class extends RpcExtension {
1368
1400
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
1369
1401
  timeout: OPTIONS_TIMEOUT
1370
1402
  }));
1371
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.GUEST) {
1403
+ if (this._remoteOptions?.role !== Options.Role.GUEST) {
1372
1404
  throw new InvalidInvitationExtensionRoleError(void 0, {
1373
1405
  expected: Options.Role.GUEST,
1374
1406
  remoteOptions: this._remoteOptions
@@ -1426,7 +1458,6 @@ var InvitationGuestExtension = class extends RpcExtension {
1426
1458
  };
1427
1459
  }
1428
1460
  async onOpen(context) {
1429
- var _a;
1430
1461
  await super.onOpen(context);
1431
1462
  try {
1432
1463
  log4("begin options", void 0, {
@@ -1447,7 +1478,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1447
1478
  S: this,
1448
1479
  C: (f, a) => f(...a)
1449
1480
  });
1450
- if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.HOST) {
1481
+ if (this._remoteOptions?.role !== Options.Role.HOST) {
1451
1482
  throw new InvalidInvitationExtensionRoleError(void 0, {
1452
1483
  expected: Options.Role.HOST,
1453
1484
  remoteOptions: this._remoteOptions
@@ -1486,9 +1517,8 @@ var InvitationsHandler = class {
1486
1517
  this._networkManager = _networkManager;
1487
1518
  }
1488
1519
  createInvitation(protocol, options) {
1489
- var _a;
1490
- const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
1491
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
1520
+ const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options ?? {};
1521
+ const authCode = options?.authCode ?? (authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
1492
1522
  invariant6(protocol, void 0, {
1493
1523
  F: __dxlog_file7,
1494
1524
  L: 76,
@@ -1541,9 +1571,8 @@ var InvitationsHandler = class {
1541
1571
  return invitation;
1542
1572
  },
1543
1573
  admit: async (admissionRequest) => {
1544
- var _a2, _b, _c;
1545
1574
  try {
1546
- const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1575
+ const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1547
1576
  invariant6(deviceKey, void 0, {
1548
1577
  F: __dxlog_file7,
1549
1578
  L: 119,
@@ -2242,7 +2271,6 @@ var SpaceInvitationProtocol = class {
2242
2271
  };
2243
2272
  }
2244
2273
  async admit(request, guestProfile) {
2245
- var _a;
2246
2274
  invariant8(this._spaceKey, void 0, {
2247
2275
  F: __dxlog_file9,
2248
2276
  L: 42,
@@ -2306,7 +2334,7 @@ var SpaceInvitationProtocol = class {
2306
2334
  space: {
2307
2335
  credential: spaceMemberCredential,
2308
2336
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2309
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2337
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2310
2338
  }
2311
2339
  };
2312
2340
  }
@@ -2410,9 +2438,8 @@ var ClientRpcServer = class {
2410
2438
  await this._rpcPeer.close();
2411
2439
  }
2412
2440
  _getServiceHandler(serviceName) {
2413
- var _a;
2414
2441
  if (!this._handlerCache.has(serviceName)) {
2415
- const [key, descriptor] = (_a = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName)) != null ? _a : raise(new Error(`Service not available: ${serviceName}`));
2442
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
2416
2443
  const service = this._serviceRegistry.services[key];
2417
2444
  if (!service) {
2418
2445
  throw new Error(`Service not available: ${serviceName}`);
@@ -2433,7 +2460,7 @@ import { STORAGE_VERSION } from "@dxos/protocols";
2433
2460
  import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2434
2461
 
2435
2462
  // packages/sdk/client-services/src/version.ts
2436
- var DXOS_VERSION = "0.1.56-main.01afb72";
2463
+ var DXOS_VERSION = "0.1.56-main.0e9f69e";
2437
2464
 
2438
2465
  // packages/sdk/client-services/src/packlets/services/platform.ts
2439
2466
  var getPlatform = () => {
@@ -2467,9 +2494,8 @@ var getPlatform = () => {
2467
2494
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2468
2495
  var DEFAULT_TIMEOUT = 1e3;
2469
2496
  var createDiagnostics = async (clientServices, serviceContext, config) => {
2470
- var _a, _b, _c;
2471
2497
  const diagnostics = {
2472
- created: new Date().toISOString(),
2498
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2473
2499
  platform: getPlatform(),
2474
2500
  client: {
2475
2501
  version: DXOS_VERSION,
@@ -2499,16 +2525,16 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2499
2525
  spaceKey: identity.space.key,
2500
2526
  profile: identity.profileDocument
2501
2527
  };
2502
- const { devices } = (_a = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2528
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2503
2529
  timeout: DEFAULT_TIMEOUT
2504
- }).catch(() => void 0)) != null ? _a : {};
2530
+ }).catch(() => void 0) ?? {};
2505
2531
  diagnostics.devices = devices;
2506
2532
  if (serviceContext.dataSpaceManager) {
2507
- diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
2533
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2508
2534
  }
2509
- const { feeds = [] } = (_c = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2535
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2510
2536
  timeout: DEFAULT_TIMEOUT
2511
- }).catch(() => void 0)) != null ? _c : {};
2537
+ }).catch(() => void 0) ?? {};
2512
2538
  diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2513
2539
  feedKey,
2514
2540
  bytes,
@@ -2521,12 +2547,9 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2521
2547
  var getProperties = (space) => {
2522
2548
  let properties = {};
2523
2549
  try {
2524
- const propertiesItem = space.dataPipeline.itemManager.items.find((item) => {
2525
- var _a, _b;
2526
- return ((_a = item.modelMeta) == null ? void 0 : _a.type) === DocumentModel.meta.type && ((_b = item.state) == null ? void 0 : _b.type) === "dxos.sdk.client.Properties";
2527
- });
2528
- const state = propertiesItem == null ? void 0 : propertiesItem.state;
2529
- properties = state == null ? void 0 : state.data;
2550
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === DocumentModel.meta.type && item.state?.type === "dxos.sdk.client.Properties");
2551
+ const state = propertiesItem?.state;
2552
+ properties = state?.data;
2530
2553
  } catch (err) {
2531
2554
  log8.warn(err.message, void 0, {
2532
2555
  F: __dxlog_file10,
@@ -2538,7 +2561,6 @@ var getProperties = (space) => {
2538
2561
  return properties;
2539
2562
  };
2540
2563
  var getSpaceStats = async (space) => {
2541
- var _a, _b, _c, _d, _e, _f;
2542
2564
  const stats = {
2543
2565
  key: space.key,
2544
2566
  metrics: space.metrics,
@@ -2546,18 +2568,15 @@ var getSpaceStats = async (space) => {
2546
2568
  ...credential.subject.assertion,
2547
2569
  id: credential.id
2548
2570
  })),
2549
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2550
- var _a2;
2551
- return {
2552
- identity: {
2553
- identityKey: member.key,
2554
- profile: {
2555
- displayName: (_a2 = member.assertion.profile) == null ? void 0 : _a2.displayName
2556
- }
2557
- },
2558
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2559
- };
2560
- }),
2571
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2572
+ identity: {
2573
+ identityKey: member.key,
2574
+ profile: {
2575
+ displayName: member.assertion.profile?.displayName
2576
+ }
2577
+ },
2578
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2579
+ })),
2561
2580
  pipeline: {
2562
2581
  // TODO(burdon): Pick properties from credentials if needed.
2563
2582
  // currentEpoch: space.dataPipeline.currentEpoch,
@@ -2567,11 +2586,11 @@ var getSpaceStats = async (space) => {
2567
2586
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2568
2587
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2569
2588
  // TODO(burdon): Empty?
2570
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
2571
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
2572
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
2573
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
2574
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
2589
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2590
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2591
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2592
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2593
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2575
2594
  }
2576
2595
  };
2577
2596
  if (space.dataPipeline.itemManager) {
@@ -2600,7 +2619,7 @@ import { PublicKey as PublicKey7 } from "@dxos/keys";
2600
2619
  import { log as log10 } from "@dxos/log";
2601
2620
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2602
2621
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2603
- import { Timeframe } from "@dxos/timeframe";
2622
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2604
2623
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2605
2624
 
2606
2625
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
@@ -2669,7 +2688,7 @@ var NotarizationPlugin = class {
2669
2688
  errors.throw(err);
2670
2689
  }
2671
2690
  });
2672
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2691
+ opCtx?.onDispose(() => ctx.dispose());
2673
2692
  if (timeout !== 0) {
2674
2693
  scheduleTask3(ctx, () => {
2675
2694
  log9.warn("Notarization timeout", {
@@ -2762,11 +2781,10 @@ var NotarizationPlugin = class {
2762
2781
  * Called with credentials arriving from the control pipeline.
2763
2782
  */
2764
2783
  async processCredential(credential) {
2765
- var _a;
2766
2784
  if (!credential.id) {
2767
2785
  return;
2768
2786
  }
2769
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2787
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2770
2788
  this._processedCredentials.add(credential.id);
2771
2789
  this._processCredentialsTriggers.delete(credential.id);
2772
2790
  }
@@ -2792,11 +2810,10 @@ var NotarizationPlugin = class {
2792
2810
  * Requests from other peers to notarize credentials.
2793
2811
  */
2794
2812
  async _onNotarize(request) {
2795
- var _a;
2796
2813
  if (!this._writer) {
2797
2814
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2798
2815
  }
2799
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2816
+ for (const credential of request.credentials ?? []) {
2800
2817
  invariant10(credential.id, "Credential must have an id", {
2801
2818
  F: __dxlog_file11,
2802
2819
  L: 200,
@@ -2885,6 +2902,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2885
2902
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2886
2903
  }
2887
2904
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2905
+ var ENABLE_FEED_PURGE = false;
2888
2906
  var DataSpace = class DataSpace2 {
2889
2907
  constructor(params) {
2890
2908
  this._ctx = new Context7();
@@ -2896,7 +2914,6 @@ var DataSpace = class DataSpace2 {
2896
2914
  this.error = void 0;
2897
2915
  this.stateUpdate = new Event5();
2898
2916
  this.metrics = {};
2899
- var _a;
2900
2917
  this._inner = params.inner;
2901
2918
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2902
2919
  this._gossip = params.gossip;
@@ -2905,7 +2922,7 @@ var DataSpace = class DataSpace2 {
2905
2922
  this._feedStore = params.feedStore;
2906
2923
  this._metadataStore = params.metadataStore;
2907
2924
  this._signingContext = params.signingContext;
2908
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2925
+ this._callbacks = params.callbacks ?? {};
2909
2926
  this.authVerifier = new TrustedKeySetAuthVerifier({
2910
2927
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2911
2928
  update: this._inner.stateUpdate,
@@ -2949,14 +2966,13 @@ var DataSpace = class DataSpace2 {
2949
2966
  this._state = SpaceState.CONTROL_ONLY;
2950
2967
  this.stateUpdate.emit();
2951
2968
  this.metrics = {};
2952
- this.metrics.open = new Date();
2969
+ this.metrics.open = /* @__PURE__ */ new Date();
2953
2970
  }
2954
2971
  async close() {
2955
2972
  await this._close();
2956
2973
  }
2957
2974
  async _close() {
2958
- var _a, _b;
2959
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2975
+ await this._callbacks.beforeClose?.();
2960
2976
  this._state = SpaceState.CLOSED;
2961
2977
  await this._ctx.dispose();
2962
2978
  this._ctx = new Context7();
@@ -2978,13 +2994,13 @@ var DataSpace = class DataSpace2 {
2978
2994
  initializeDataPipelineAsync() {
2979
2995
  scheduleTask4(this._ctx, async () => {
2980
2996
  try {
2981
- this.metrics.pipelineInitBegin = new Date();
2997
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2982
2998
  await this.initializeDataPipeline();
2983
2999
  } catch (err) {
2984
3000
  if (err instanceof CancelledError) {
2985
3001
  log10("data pipeline initialization cancelled", err, {
2986
3002
  F: __dxlog_file12,
2987
- L: 193,
3003
+ L: 199,
2988
3004
  S: this,
2989
3005
  C: (f, a) => f(...a)
2990
3006
  });
@@ -2992,7 +3008,7 @@ var DataSpace = class DataSpace2 {
2992
3008
  }
2993
3009
  log10.error("Error initializing data pipeline", err, {
2994
3010
  F: __dxlog_file12,
2995
- L: 197,
3011
+ L: 203,
2996
3012
  S: this,
2997
3013
  C: (f, a) => f(...a)
2998
3014
  });
@@ -3000,12 +3016,11 @@ var DataSpace = class DataSpace2 {
3000
3016
  this.error = err;
3001
3017
  this.stateUpdate.emit();
3002
3018
  } finally {
3003
- this.metrics.ready = new Date();
3019
+ this.metrics.ready = /* @__PURE__ */ new Date();
3004
3020
  }
3005
3021
  });
3006
3022
  }
3007
3023
  async initializeDataPipeline() {
3008
- var _a, _b, _c, _d;
3009
3024
  if (this._state !== SpaceState.CONTROL_ONLY) {
3010
3025
  throw new SystemError("Invalid operation");
3011
3026
  }
@@ -3014,11 +3029,11 @@ var DataSpace = class DataSpace2 {
3014
3029
  ctx: this._ctx,
3015
3030
  breakOnStall: false
3016
3031
  });
3017
- this.metrics.controlPipelineReady = new Date();
3032
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3018
3033
  await this._createWritableFeeds();
3019
3034
  log10("writable feeds created", void 0, {
3020
3035
  F: __dxlog_file12,
3021
- L: 221,
3036
+ L: 227,
3022
3037
  S: this,
3023
3038
  C: (f, a) => f(...a)
3024
3039
  });
@@ -3031,11 +3046,11 @@ var DataSpace = class DataSpace2 {
3031
3046
  }), this._inner.controlPipeline.writer));
3032
3047
  }
3033
3048
  await this._inner.initializeDataPipeline();
3034
- this.metrics.dataPipelineOpen = new Date();
3049
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3035
3050
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3036
3051
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3037
3052
  F: __dxlog_file12,
3038
- L: 242,
3053
+ L: 248,
3039
3054
  S: this,
3040
3055
  C: (f, a) => f(...a)
3041
3056
  });
@@ -3043,17 +3058,17 @@ var DataSpace = class DataSpace2 {
3043
3058
  ctx: this._ctx,
3044
3059
  breakOnStall: false
3045
3060
  });
3046
- this.metrics.dataPipelineReady = new Date();
3061
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3047
3062
  log10("data pipeline ready", void 0, {
3048
3063
  F: __dxlog_file12,
3049
- L: 251,
3064
+ L: 257,
3050
3065
  S: this,
3051
3066
  C: (f, a) => f(...a)
3052
3067
  });
3053
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3068
+ await this._callbacks.beforeReady?.();
3054
3069
  this._state = SpaceState.READY;
3055
3070
  this.stateUpdate.emit();
3056
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3071
+ await this._callbacks.afterReady?.();
3057
3072
  }
3058
3073
  async _createWritableFeeds() {
3059
3074
  const credentials = [];
@@ -3100,7 +3115,6 @@ var DataSpace = class DataSpace2 {
3100
3115
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3101
3116
  }
3102
3117
  async createEpoch() {
3103
- var _a, _b;
3104
3118
  const epoch = await this.dataPipeline.createEpoch();
3105
3119
  const receipt = await this.inner.controlPipeline.writer.write({
3106
3120
  credential: {
@@ -3113,16 +3127,19 @@ var DataSpace = class DataSpace2 {
3113
3127
  })
3114
3128
  }
3115
3129
  });
3116
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3130
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
3117
3131
  [
3118
3132
  receipt.feedKey,
3119
3133
  receipt.seq
3120
3134
  ]
3121
3135
  ]));
3122
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
3123
- const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3124
- if (indexBeforeEpoch) {
3125
- await feed.clear(0, indexBeforeEpoch + 1);
3136
+ if (ENABLE_FEED_PURGE) {
3137
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3138
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3139
+ if (indexBeforeEpoch === void 0) {
3140
+ continue;
3141
+ }
3142
+ await feed.safeClear(0, indexBeforeEpoch + 1);
3126
3143
  }
3127
3144
  }
3128
3145
  }
@@ -3179,9 +3196,8 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
3179
3196
  import { createCredential } from "@dxos/credentials";
3180
3197
  import { failUndefined as failUndefined2 } from "@dxos/debug";
3181
3198
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3182
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3199
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3183
3200
  var spaceGenesis = async (keyring, signingContext, space) => {
3184
- var _a, _b, _c, _d;
3185
3201
  const credentials = [
3186
3202
  await createCredential({
3187
3203
  signer: keyring,
@@ -3201,11 +3217,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3201
3217
  spaceKey: space.key,
3202
3218
  role: SpaceMember2.Role.ADMIN,
3203
3219
  profile: signingContext.profile,
3204
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3220
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
3205
3221
  }
3206
3222
  }),
3207
3223
  await signingContext.credentialSigner.createCredential({
3208
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3224
+ subject: space.controlFeedKey ?? failUndefined2(),
3209
3225
  assertion: {
3210
3226
  "@type": "dxos.halo.credentials.AdmittedFeed",
3211
3227
  spaceKey: space.key,
@@ -3215,7 +3231,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3215
3231
  }
3216
3232
  }),
3217
3233
  await signingContext.credentialSigner.createCredential({
3218
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3234
+ subject: space.dataFeedKey ?? failUndefined2(),
3219
3235
  assertion: {
3220
3236
  "@type": "dxos.halo.credentials.AdmittedFeed",
3221
3237
  spaceKey: space.key,
@@ -3225,12 +3241,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3225
3241
  }
3226
3242
  }),
3227
3243
  await signingContext.credentialSigner.createCredential({
3228
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3244
+ subject: space.key ?? failUndefined2(),
3229
3245
  assertion: {
3230
3246
  "@type": "dxos.halo.credentials.Epoch",
3231
3247
  number: 0,
3232
3248
  previousId: void 0,
3233
- timeframe: new Timeframe2(),
3249
+ timeframe: new Timeframe3(),
3234
3250
  snapshotCid: void 0
3235
3251
  }
3236
3252
  })
@@ -3604,9 +3620,8 @@ var SpacesServiceImpl = class {
3604
3620
  return this._serializeSpace(space);
3605
3621
  }
3606
3622
  async updateSpace({ spaceKey, state }) {
3607
- var _a;
3608
3623
  const dataSpaceManager = await this._getDataSpaceManager();
3609
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3624
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3610
3625
  if (state) {
3611
3626
  switch (state) {
3612
3627
  case SpaceState3.ACTIVE:
@@ -3670,17 +3685,15 @@ var SpacesServiceImpl = class {
3670
3685
  });
3671
3686
  }
3672
3687
  async postMessage({ spaceKey, channel, message }) {
3673
- var _a;
3674
3688
  const dataSpaceManager = await this._getDataSpaceManager();
3675
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3689
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3676
3690
  await space.postMessage(getChannelId(channel), message);
3677
3691
  }
3678
3692
  subscribeMessages({ spaceKey, channel }) {
3679
3693
  return new Stream10(({ ctx, next }) => {
3680
3694
  scheduleTask5(ctx, async () => {
3681
- var _a;
3682
3695
  const dataSpaceManager = await this._getDataSpaceManager();
3683
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3696
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3684
3697
  const handle = space.listen(getChannelId(channel), (message) => {
3685
3698
  next(message);
3686
3699
  });
@@ -3690,8 +3703,7 @@ var SpacesServiceImpl = class {
3690
3703
  }
3691
3704
  queryCredentials({ spaceKey }) {
3692
3705
  return new Stream10(({ ctx, next }) => {
3693
- var _a;
3694
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3706
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3695
3707
  const processor = {
3696
3708
  processCredential: async (credential) => {
3697
3709
  next(credential);
@@ -3702,9 +3714,8 @@ var SpacesServiceImpl = class {
3702
3714
  });
3703
3715
  }
3704
3716
  async writeCredentials({ spaceKey, credentials }) {
3705
- var _a;
3706
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3707
- for (const credential of credentials != null ? credentials : []) {
3717
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3718
+ for (const credential of credentials ?? []) {
3708
3719
  await space.controlPipeline.writer.write({
3709
3720
  credential: {
3710
3721
  credential
@@ -3713,13 +3724,11 @@ var SpacesServiceImpl = class {
3713
3724
  }
3714
3725
  }
3715
3726
  async createEpoch({ spaceKey }) {
3716
- var _a;
3717
3727
  const dataSpaceManager = await this._getDataSpaceManager();
3718
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3728
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3719
3729
  await space.createEpoch();
3720
3730
  }
3721
3731
  _serializeSpace(space) {
3722
- var _a, _b, _c, _d, _e, _f, _g;
3723
3732
  return {
3724
3733
  spaceKey: space.key,
3725
3734
  state: space.state,
@@ -3731,16 +3740,15 @@ var SpacesServiceImpl = class {
3731
3740
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3732
3741
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3733
3742
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3734
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3735
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3736
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3737
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3738
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3743
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3744
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3745
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3746
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3747
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3739
3748
  },
3740
3749
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3741
- var _a2, _b2, _c2;
3742
3750
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3743
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3751
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3744
3752
  if (isMe) {
3745
3753
  peers.push(space.presence.getLocalState());
3746
3754
  }
@@ -3748,14 +3756,14 @@ var SpacesServiceImpl = class {
3748
3756
  identity: {
3749
3757
  identityKey: member.key,
3750
3758
  profile: {
3751
- displayName: (_c2 = (_b2 = member.assertion.profile) == null ? void 0 : _b2.displayName) != null ? _c2 : humanize(member.key)
3759
+ displayName: member.assertion.profile?.displayName ?? humanize(member.key)
3752
3760
  }
3753
3761
  },
3754
3762
  presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3755
3763
  peerStates: peers
3756
3764
  };
3757
3765
  }),
3758
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3766
+ creator: space.inner.spaceState.creator?.key,
3759
3767
  cache: space.cache,
3760
3768
  metrics: space.metrics
3761
3769
  };
@@ -3778,6 +3786,7 @@ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/prot
3778
3786
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3779
3787
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3780
3788
  import { trace as Trace2 } from "@dxos/tracing";
3789
+ import { safeInstanceof } from "@dxos/util";
3781
3790
  function _ts_decorate5(decorators, target, key, desc) {
3782
3791
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3783
3792
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3823,16 +3832,13 @@ var ServiceContext = class ServiceContext2 {
3823
3832
  });
3824
3833
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3825
3834
  this.invitations = new InvitationsHandler(this.networkManager);
3826
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3827
- var _a;
3828
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3829
- }, this._acceptIdentity.bind(this)));
3835
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3830
3836
  }
3831
3837
  async open(ctx) {
3832
3838
  await this._checkStorageVersion();
3833
3839
  log13("opening...", void 0, {
3834
3840
  F: __dxlog_file15,
3835
- L: 131,
3841
+ L: 134,
3836
3842
  S: this,
3837
3843
  C: (f, a) => f(...a)
3838
3844
  });
@@ -3840,7 +3846,7 @@ var ServiceContext = class ServiceContext2 {
3840
3846
  id: this._instanceId
3841
3847
  }), {
3842
3848
  F: __dxlog_file15,
3843
- L: 132,
3849
+ L: 135,
3844
3850
  S: this,
3845
3851
  C: (f, a) => f(...a)
3846
3852
  });
@@ -3855,29 +3861,28 @@ var ServiceContext = class ServiceContext2 {
3855
3861
  id: this._instanceId
3856
3862
  }), {
3857
3863
  F: __dxlog_file15,
3858
- L: 140,
3864
+ L: 143,
3859
3865
  S: this,
3860
3866
  C: (f, a) => f(...a)
3861
3867
  });
3862
3868
  log13("opened", void 0, {
3863
3869
  F: __dxlog_file15,
3864
- L: 141,
3870
+ L: 144,
3865
3871
  S: this,
3866
3872
  C: (f, a) => f(...a)
3867
3873
  });
3868
3874
  }
3869
3875
  async close() {
3870
- var _a;
3871
3876
  log13("closing...", void 0, {
3872
3877
  F: __dxlog_file15,
3873
- L: 145,
3878
+ L: 148,
3874
3879
  S: this,
3875
3880
  C: (f, a) => f(...a)
3876
3881
  });
3877
3882
  if (this._deviceSpaceSync && this.identityManager.identity) {
3878
3883
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3879
3884
  }
3880
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3885
+ await this.dataSpaceManager?.close();
3881
3886
  await this.identityManager.close();
3882
3887
  await this.spaceManager.close();
3883
3888
  await this.feedStore.close();
@@ -3886,7 +3891,7 @@ var ServiceContext = class ServiceContext2 {
3886
3891
  this.dataServiceSubscriptions.clear();
3887
3892
  log13("closed", void 0, {
3888
3893
  F: __dxlog_file15,
3889
- L: 156,
3894
+ L: 159,
3890
3895
  S: this,
3891
3896
  C: (f, a) => f(...a)
3892
3897
  });
@@ -3900,7 +3905,7 @@ var ServiceContext = class ServiceContext2 {
3900
3905
  const factory = this._handlerFactories.get(invitation.kind);
3901
3906
  invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3902
3907
  F: __dxlog_file15,
3903
- L: 168,
3908
+ L: 171,
3904
3909
  S: this,
3905
3910
  A: [
3906
3911
  "factory",
@@ -3922,14 +3927,13 @@ var ServiceContext = class ServiceContext2 {
3922
3927
  }
3923
3928
  // Called when identity is created.
3924
3929
  async _initialize(ctx) {
3925
- var _a;
3926
3930
  log13("initializing spaces...", void 0, {
3927
3931
  F: __dxlog_file15,
3928
- L: 190,
3932
+ L: 193,
3929
3933
  S: this,
3930
3934
  C: (f, a) => f(...a)
3931
3935
  });
3932
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3936
+ const identity = this.identityManager.identity ?? failUndefined3();
3933
3937
  const signingContext = {
3934
3938
  credentialSigner: identity.getIdentityCredentialSigner(),
3935
3939
  identityKey: identity.identityKey,
@@ -3948,7 +3952,7 @@ var ServiceContext = class ServiceContext2 {
3948
3952
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3949
3953
  invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3950
3954
  F: __dxlog_file15,
3951
- L: 213,
3955
+ L: 216,
3952
3956
  S: this,
3953
3957
  A: [
3954
3958
  "this.dataSpaceManager",
@@ -3972,7 +3976,7 @@ var ServiceContext = class ServiceContext2 {
3972
3976
  details: assertion
3973
3977
  }, {
3974
3978
  F: __dxlog_file15,
3975
- L: 229,
3979
+ L: 232,
3976
3980
  S: this,
3977
3981
  C: (f, a) => f(...a)
3978
3982
  });
@@ -3983,7 +3987,7 @@ var ServiceContext = class ServiceContext2 {
3983
3987
  details: assertion
3984
3988
  }, {
3985
3989
  F: __dxlog_file15,
3986
- L: 233,
3990
+ L: 236,
3987
3991
  S: this,
3988
3992
  C: (f, a) => f(...a)
3989
3993
  });
@@ -3994,7 +3998,7 @@ var ServiceContext = class ServiceContext2 {
3994
3998
  details: assertion
3995
3999
  }, {
3996
4000
  F: __dxlog_file15,
3997
- L: 238,
4001
+ L: 241,
3998
4002
  S: this,
3999
4003
  C: (f, a) => f(...a)
4000
4004
  });
@@ -4005,7 +4009,7 @@ var ServiceContext = class ServiceContext2 {
4005
4009
  } catch (err) {
4006
4010
  log13.catch(err, void 0, {
4007
4011
  F: __dxlog_file15,
4008
- L: 244,
4012
+ L: 247,
4009
4013
  S: this,
4010
4014
  C: (f, a) => f(...a)
4011
4015
  });
@@ -4022,6 +4026,7 @@ _ts_decorate5([
4022
4026
  Trace2.span()
4023
4027
  ], ServiceContext.prototype, "_initialize", null);
4024
4028
  ServiceContext = _ts_decorate5([
4029
+ safeInstanceof("dxos.client-services.ServiceContext"),
4025
4030
  Trace2.resource()
4026
4031
  ], ServiceContext);
4027
4032
 
@@ -4074,7 +4079,7 @@ var Lock = class {
4074
4079
  S: this,
4075
4080
  C: (f, a) => f(...a)
4076
4081
  });
4077
- } catch (e) {
4082
+ } catch {
4078
4083
  log14("stealing lock...", void 0, {
4079
4084
  F: __dxlog_file16,
4080
4085
  L: 46,
@@ -4111,8 +4116,7 @@ var Lock = class {
4111
4116
  void navigator.locks.request(this._lockKey, {
4112
4117
  steal
4113
4118
  }, async () => {
4114
- var _a, _b;
4115
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4119
+ await this._onAcquire?.();
4116
4120
  acquired.wake();
4117
4121
  this._releaseTrigger = new Trigger6();
4118
4122
  await this._releaseTrigger.wait();
@@ -4122,7 +4126,7 @@ var Lock = class {
4122
4126
  S: this,
4123
4127
  C: (f, a) => f(...a)
4124
4128
  });
4125
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
4129
+ await this._onRelease?.();
4126
4130
  log14("released lock", void 0, {
4127
4131
  F: __dxlog_file16,
4128
4132
  L: 74,
@@ -4130,8 +4134,7 @@ var Lock = class {
4130
4134
  C: (f, a) => f(...a)
4131
4135
  });
4132
4136
  }).catch(async () => {
4133
- var _a;
4134
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4137
+ await this._onRelease?.();
4135
4138
  });
4136
4139
  await acquired.wait();
4137
4140
  log14("recieved lock", {
@@ -4159,7 +4162,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
4159
4162
  import { isNode } from "@dxos/util";
4160
4163
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
4161
4164
  var createStorageObjects = (config) => {
4162
- const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4165
+ const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
4163
4166
  if (persistent && storageType === StorageDriver.RAM) {
4164
4167
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4165
4168
  }
@@ -4255,21 +4258,17 @@ var DevicesServiceImpl = class {
4255
4258
  queryDevices() {
4256
4259
  return new Stream11(({ next }) => {
4257
4260
  const update = () => {
4258
- var _a;
4259
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4261
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4260
4262
  if (!deviceKeys) {
4261
4263
  next({
4262
4264
  devices: []
4263
4265
  });
4264
4266
  } else {
4265
4267
  next({
4266
- devices: Array.from(deviceKeys.values()).map((key) => {
4267
- var _a2;
4268
- return {
4269
- deviceKey: key,
4270
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4271
- };
4272
- })
4268
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4269
+ deviceKey: key,
4270
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4271
+ }))
4273
4272
  });
4274
4273
  }
4275
4274
  };
@@ -4297,7 +4296,7 @@ import { jsonify, numericalValues, tracer } from "@dxos/util";
4297
4296
  var LoggingServiceImpl = class {
4298
4297
  constructor() {
4299
4298
  this._logs = new Event7();
4300
- this._started = new Date();
4299
+ this._started = /* @__PURE__ */ new Date();
4301
4300
  this._logProcessor = (_config, entry2) => {
4302
4301
  this._logs.emit(entry2);
4303
4302
  };
@@ -4327,8 +4326,7 @@ var LoggingServiceImpl = class {
4327
4326
  */
4328
4327
  queryMetrics({ interval = 5e3 }) {
4329
4328
  const getNumericalValues = (key) => {
4330
- var _a;
4331
- const events = (_a = tracer.get(key)) != null ? _a : [];
4329
+ const events = tracer.get(key) ?? [];
4332
4330
  return {
4333
4331
  key,
4334
4332
  stats: numericalValues(events, "duration")
@@ -4337,14 +4335,14 @@ var LoggingServiceImpl = class {
4337
4335
  return new Stream12(({ next }) => {
4338
4336
  const update = () => {
4339
4337
  const metrics = {
4340
- timestamp: new Date(),
4338
+ timestamp: /* @__PURE__ */ new Date(),
4341
4339
  values: [
4342
4340
  getNumericalValues("dxos.echo.pipeline.control"),
4343
4341
  getNumericalValues("dxos.echo.pipeline.data")
4344
4342
  ].filter(Boolean)
4345
4343
  };
4346
4344
  next({
4347
- timestamp: new Date(),
4345
+ timestamp: /* @__PURE__ */ new Date(),
4348
4346
  metrics
4349
4347
  });
4350
4348
  };
@@ -4358,11 +4356,10 @@ var LoggingServiceImpl = class {
4358
4356
  queryLogs(request) {
4359
4357
  return new Stream12(({ ctx, next }) => {
4360
4358
  const handler = (entry2) => {
4361
- var _a, _b, _c, _d, _e;
4362
4359
  if (LOG_PROCESSING > 0) {
4363
4360
  return;
4364
4361
  }
4365
- 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"))) {
4362
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4366
4363
  return;
4367
4364
  }
4368
4365
  if (!shouldLog(entry2, request)) {
@@ -4371,11 +4368,11 @@ var LoggingServiceImpl = class {
4371
4368
  const record = {
4372
4369
  ...entry2,
4373
4370
  context: jsonify(getContextFromEntry(entry2)),
4374
- timestamp: new Date(),
4371
+ timestamp: /* @__PURE__ */ new Date(),
4375
4372
  meta: {
4376
4373
  // TODO(dmaretskyi): Fix proto.
4377
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4378
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4374
+ file: entry2.meta?.F ?? "",
4375
+ line: entry2.meta?.L ?? 0
4379
4376
  }
4380
4377
  };
4381
4378
  try {
@@ -4398,15 +4395,11 @@ var matchFilter = (filter, level, path, options) => {
4398
4395
  }
4399
4396
  };
4400
4397
  var shouldLog = (entry2, request) => {
4401
- var _a;
4402
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4398
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
4403
4399
  if (request.filters === void 0) {
4404
4400
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
4405
4401
  } else {
4406
- return request.filters.some((filter) => {
4407
- var _a2, _b;
4408
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4409
- });
4402
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4410
4403
  }
4411
4404
  };
4412
4405
  var LOG_PROCESSING = 0;
@@ -4457,8 +4450,7 @@ var SystemServiceImpl = class {
4457
4450
  this._onReset = onReset;
4458
4451
  }
4459
4452
  async getConfig() {
4460
- var _a, _b;
4461
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4453
+ return this._config?.values ?? {};
4462
4454
  }
4463
4455
  /**
4464
4456
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4466,7 +4458,7 @@ var SystemServiceImpl = class {
4466
4458
  async getDiagnostics({ keys } = {}) {
4467
4459
  const diagnostics = await this._getDiagnostics();
4468
4460
  return {
4469
- timestamp: new Date(),
4461
+ timestamp: /* @__PURE__ */ new Date(),
4470
4462
  diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4471
4463
  truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4472
4464
  humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
@@ -4557,11 +4549,10 @@ var ClientServicesHost = class ClientServicesHost2 {
4557
4549
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4558
4550
  },
4559
4551
  onUpdateStatus: async (status) => {
4560
- var _a, _b;
4561
4552
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
4562
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4553
+ await this._resourceLock?.acquire();
4563
4554
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
4564
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4555
+ await this._resourceLock?.release();
4565
4556
  }
4566
4557
  },
4567
4558
  onReset: async () => {
@@ -4598,7 +4589,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4598
4589
  * Can only be called once.
4599
4590
  */
4600
4591
  initialize({ config, ...options }) {
4601
- var _a, _b, _c;
4602
4592
  invariant13(!this._open, "service host is open", {
4603
4593
  F: __dxlog_file17,
4604
4594
  L: 181,
@@ -4608,7 +4598,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4608
4598
  "'service host is open'"
4609
4599
  ]
4610
4600
  });
4611
- log16.info("initializing...", void 0, {
4601
+ log16("initializing...", void 0, {
4612
4602
  F: __dxlog_file17,
4613
4603
  L: 182,
4614
4604
  S: this,
@@ -4630,8 +4620,8 @@ var ClientServicesHost = class ClientServicesHost2 {
4630
4620
  }
4631
4621
  }
4632
4622
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4633
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4634
- }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4623
+ iceServers: this._config?.get("runtime.services.ice")
4624
+ }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4635
4625
  this._signalManager = signalManager;
4636
4626
  invariant13(!this._networkManager, "network manager already set", {
4637
4627
  F: __dxlog_file17,
@@ -4647,7 +4637,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4647
4637
  transportFactory,
4648
4638
  signalManager
4649
4639
  });
4650
- log16.info("initialized", void 0, {
4640
+ log16("initialized", void 0, {
4651
4641
  F: __dxlog_file17,
4652
4642
  L: 208,
4653
4643
  S: this,
@@ -4655,7 +4645,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4655
4645
  });
4656
4646
  }
4657
4647
  async open(ctx) {
4658
- var _a, _b, _c;
4659
4648
  if (this._open) {
4660
4649
  return;
4661
4650
  }
@@ -4705,20 +4694,20 @@ var ClientServicesHost = class ClientServicesHost2 {
4705
4694
  ]
4706
4695
  });
4707
4696
  this._opening = true;
4708
- log16.info("opening...", {
4709
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4697
+ log16("opening...", {
4698
+ lockKey: this._resourceLock?.lockKey
4710
4699
  }, {
4711
4700
  F: __dxlog_file17,
4712
4701
  L: 227,
4713
4702
  S: this,
4714
4703
  C: (f, a) => f(...a)
4715
4704
  });
4716
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4705
+ await this._resourceLock?.acquire();
4717
4706
  await this._loggingService.open();
4718
4707
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4719
4708
  this._serviceRegistry.setServices({
4720
4709
  SystemService: this._systemService,
4721
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4710
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4722
4711
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4723
4712
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4724
4713
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4740,12 +4729,12 @@ var ClientServicesHost = class ClientServicesHost2 {
4740
4729
  this._opening = false;
4741
4730
  this._open = true;
4742
4731
  this._statusUpdate.emit();
4743
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4744
- log16.info("opened", {
4732
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4733
+ log16("opened", {
4745
4734
  deviceKey
4746
4735
  }, {
4747
4736
  F: __dxlog_file17,
4748
- L: 280,
4737
+ L: 284,
4749
4738
  S: this,
4750
4739
  C: (f, a) => f(...a)
4751
4740
  });
@@ -4753,22 +4742,21 @@ var ClientServicesHost = class ClientServicesHost2 {
4753
4742
  id: traceId
4754
4743
  }), {
4755
4744
  F: __dxlog_file17,
4756
- L: 281,
4745
+ L: 285,
4757
4746
  S: this,
4758
4747
  C: (f, a) => f(...a)
4759
4748
  });
4760
4749
  }
4761
4750
  async close() {
4762
- var _a;
4763
4751
  if (!this._open) {
4764
4752
  return;
4765
4753
  }
4766
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4767
- log16.info("closing...", {
4754
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4755
+ log16("closing...", {
4768
4756
  deviceKey
4769
4757
  }, {
4770
4758
  F: __dxlog_file17,
4771
- L: 292,
4759
+ L: 296,
4772
4760
  S: this,
4773
4761
  C: (f, a) => f(...a)
4774
4762
  });
@@ -4779,37 +4767,36 @@ var ClientServicesHost = class ClientServicesHost2 {
4779
4767
  await this._serviceContext.close();
4780
4768
  this._open = false;
4781
4769
  this._statusUpdate.emit();
4782
- log16.info("closed", {
4770
+ log16("closed", {
4783
4771
  deviceKey
4784
4772
  }, {
4785
4773
  F: __dxlog_file17,
4786
- L: 298,
4774
+ L: 302,
4787
4775
  S: this,
4788
4776
  C: (f, a) => f(...a)
4789
4777
  });
4790
4778
  }
4791
4779
  async reset() {
4792
- var _a, _b, _c;
4793
4780
  const traceId = PublicKey10.random().toHex();
4794
4781
  log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4795
4782
  id: traceId
4796
4783
  }), {
4797
4784
  F: __dxlog_file17,
4798
- L: 303,
4785
+ L: 307,
4799
4786
  S: this,
4800
4787
  C: (f, a) => f(...a)
4801
4788
  });
4802
4789
  log16("resetting...", void 0, {
4803
4790
  F: __dxlog_file17,
4804
- L: 305,
4791
+ L: 309,
4805
4792
  S: this,
4806
4793
  C: (f, a) => f(...a)
4807
4794
  });
4808
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4795
+ await this._serviceContext?.close();
4809
4796
  await this._storage.reset();
4810
4797
  log16("reset", void 0, {
4811
4798
  F: __dxlog_file17,
4812
- L: 308,
4799
+ L: 312,
4813
4800
  S: this,
4814
4801
  C: (f, a) => f(...a)
4815
4802
  });
@@ -4817,11 +4804,11 @@ var ClientServicesHost = class ClientServicesHost2 {
4817
4804
  id: traceId
4818
4805
  }), {
4819
4806
  F: __dxlog_file17,
4820
- L: 309,
4807
+ L: 313,
4821
4808
  S: this,
4822
4809
  C: (f, a) => f(...a)
4823
4810
  });
4824
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4811
+ await this._callbacks?.onReset?.();
4825
4812
  }
4826
4813
  };
4827
4814
  _ts_decorate7([
@@ -4875,4 +4862,4 @@ export {
4875
4862
  createDefaultModelFactory,
4876
4863
  ClientServicesHost
4877
4864
  };
4878
- //# sourceMappingURL=chunk-53BV3Q7V.mjs.map
4865
+ //# sourceMappingURL=chunk-II6TDINB.mjs.map