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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/lib/browser/{chunk-ZOTHWLK5.mjs → chunk-E7EKG5QQ.mjs} +267 -280
  2. package/dist/lib/browser/chunk-E7EKG5QQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +8 -13
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +30 -45
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +2 -2
  8. package/dist/lib/node/index.cjs +287 -305
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +299 -323
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +5 -0
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  22. package/dist/types/src/version.d.ts +1 -1
  23. package/package.json +34 -34
  24. package/src/packlets/identity/identity-manager.test.ts +11 -0
  25. package/src/packlets/identity/identity-manager.ts +18 -1
  26. package/src/packlets/identity/identity-service.test.ts +15 -1
  27. package/src/packlets/identity/identity-service.ts +23 -14
  28. package/src/packlets/invitations/invitations-handler.ts +2 -0
  29. package/src/packlets/services/diagnostics.ts +2 -1
  30. package/src/packlets/services/service-context.ts +7 -4
  31. package/src/packlets/services/service-host.test.ts +1 -1
  32. package/src/packlets/services/service-host.ts +11 -7
  33. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  34. package/src/packlets/spaces/data-space-manager.ts +5 -1
  35. package/src/packlets/spaces/spaces-service.ts +1 -1
  36. package/src/packlets/vault/worker-runtime.ts +1 -1
  37. package/src/version.ts +1 -1
  38. package/dist/lib/browser/chunk-ZOTHWLK5.mjs.map +0 -7
@@ -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,
@@ -1688,7 +1717,8 @@ var InvitationsHandler = class {
1688
1717
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
1689
1718
  teleport.addExtension("dxos.halo.invitations", createExtension());
1690
1719
  }),
1691
- topology: new StarTopology(topic)
1720
+ topology: new StarTopology(topic),
1721
+ label: "invitation host"
1692
1722
  });
1693
1723
  ctx.onDispose(() => swarmConnection.close());
1694
1724
  stream.next({
@@ -1713,7 +1743,7 @@ var InvitationsHandler = class {
1713
1743
  const { timeout = INVITATION_TIMEOUT } = invitation;
1714
1744
  invariant6(protocol, void 0, {
1715
1745
  F: __dxlog_file7,
1716
- L: 210,
1746
+ L: 211,
1717
1747
  S: this,
1718
1748
  A: [
1719
1749
  "protocol",
@@ -1727,7 +1757,7 @@ var InvitationsHandler = class {
1727
1757
  const setState = (newData) => {
1728
1758
  invariant6(newData.state !== void 0, void 0, {
1729
1759
  F: __dxlog_file7,
1730
- L: 221,
1760
+ L: 222,
1731
1761
  S: this,
1732
1762
  A: [
1733
1763
  "newData.state !== undefined",
@@ -1747,7 +1777,7 @@ var InvitationsHandler = class {
1747
1777
  ...protocol.toJSON()
1748
1778
  }, {
1749
1779
  F: __dxlog_file7,
1750
- L: 229,
1780
+ L: 230,
1751
1781
  S: this,
1752
1782
  C: (f, a) => f(...a)
1753
1783
  });
@@ -1757,7 +1787,7 @@ var InvitationsHandler = class {
1757
1787
  } else {
1758
1788
  log5.warn("auth failed", err, {
1759
1789
  F: __dxlog_file7,
1760
- L: 232,
1790
+ L: 233,
1761
1791
  S: this,
1762
1792
  C: (f, a) => f(...a)
1763
1793
  });
@@ -1771,7 +1801,7 @@ var InvitationsHandler = class {
1771
1801
  ...protocol.toJSON()
1772
1802
  }, {
1773
1803
  F: __dxlog_file7,
1774
- L: 240,
1804
+ L: 241,
1775
1805
  S: this,
1776
1806
  C: (f, a) => f(...a)
1777
1807
  });
@@ -1786,7 +1816,7 @@ var InvitationsHandler = class {
1786
1816
  currentState
1787
1817
  }, {
1788
1818
  F: __dxlog_file7,
1789
- L: 250,
1819
+ L: 251,
1790
1820
  S: this,
1791
1821
  C: (f, a) => f(...a)
1792
1822
  });
@@ -1801,7 +1831,7 @@ var InvitationsHandler = class {
1801
1831
  id: traceId
1802
1832
  }), {
1803
1833
  F: __dxlog_file7,
1804
- L: 259,
1834
+ L: 260,
1805
1835
  S: this,
1806
1836
  C: (f, a) => f(...a)
1807
1837
  });
@@ -1813,7 +1843,7 @@ var InvitationsHandler = class {
1813
1843
  ...protocol.toJSON()
1814
1844
  }, {
1815
1845
  F: __dxlog_file7,
1816
- L: 267,
1846
+ L: 268,
1817
1847
  S: this,
1818
1848
  C: (f, a) => f(...a)
1819
1849
  });
@@ -1824,7 +1854,7 @@ var InvitationsHandler = class {
1824
1854
  ...protocol.toJSON()
1825
1855
  }, {
1826
1856
  F: __dxlog_file7,
1827
- L: 271,
1857
+ L: 272,
1828
1858
  S: this,
1829
1859
  C: (f, a) => f(...a)
1830
1860
  });
@@ -1834,7 +1864,7 @@ var InvitationsHandler = class {
1834
1864
  response: introductionResponse
1835
1865
  }, {
1836
1866
  F: __dxlog_file7,
1837
- L: 275,
1867
+ L: 276,
1838
1868
  S: this,
1839
1869
  C: (f, a) => f(...a)
1840
1870
  });
@@ -1846,7 +1876,7 @@ var InvitationsHandler = class {
1846
1876
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1847
1877
  log5("guest waiting for authentication code...", void 0, {
1848
1878
  F: __dxlog_file7,
1849
- L: 284,
1879
+ L: 285,
1850
1880
  S: this,
1851
1881
  C: (f, a) => f(...a)
1852
1882
  });
@@ -1858,7 +1888,7 @@ var InvitationsHandler = class {
1858
1888
  });
1859
1889
  log5("sending authentication request", void 0, {
1860
1890
  F: __dxlog_file7,
1861
- L: 288,
1891
+ L: 289,
1862
1892
  S: this,
1863
1893
  C: (f, a) => f(...a)
1864
1894
  });
@@ -1879,7 +1909,7 @@ var InvitationsHandler = class {
1879
1909
  attempt
1880
1910
  }, {
1881
1911
  F: __dxlog_file7,
1882
- L: 299,
1912
+ L: 300,
1883
1913
  S: this,
1884
1914
  C: (f, a) => f(...a)
1885
1915
  });
@@ -1896,7 +1926,7 @@ var InvitationsHandler = class {
1896
1926
  ...protocol.toJSON()
1897
1927
  }, {
1898
1928
  F: __dxlog_file7,
1899
- L: 310,
1929
+ L: 311,
1900
1930
  S: this,
1901
1931
  C: (f, a) => f(...a)
1902
1932
  });
@@ -1908,7 +1938,7 @@ var InvitationsHandler = class {
1908
1938
  ...protocol.toJSON()
1909
1939
  }, {
1910
1940
  F: __dxlog_file7,
1911
- L: 321,
1941
+ L: 322,
1912
1942
  S: this,
1913
1943
  C: (f, a) => f(...a)
1914
1944
  });
@@ -1920,7 +1950,7 @@ var InvitationsHandler = class {
1920
1950
  id: traceId
1921
1951
  }), {
1922
1952
  F: __dxlog_file7,
1923
- L: 323,
1953
+ L: 324,
1924
1954
  S: this,
1925
1955
  C: (f, a) => f(...a)
1926
1956
  });
@@ -1930,7 +1960,7 @@ var InvitationsHandler = class {
1930
1960
  ...protocol.toJSON()
1931
1961
  }, {
1932
1962
  F: __dxlog_file7,
1933
- L: 326,
1963
+ L: 327,
1934
1964
  S: this,
1935
1965
  C: (f, a) => f(...a)
1936
1966
  });
@@ -1940,7 +1970,7 @@ var InvitationsHandler = class {
1940
1970
  } else {
1941
1971
  log5("auth failed", err, {
1942
1972
  F: __dxlog_file7,
1943
- L: 329,
1973
+ L: 330,
1944
1974
  S: this,
1945
1975
  C: (f, a) => f(...a)
1946
1976
  });
@@ -1951,7 +1981,7 @@ var InvitationsHandler = class {
1951
1981
  error: err
1952
1982
  }), {
1953
1983
  F: __dxlog_file7,
1954
- L: 332,
1984
+ L: 333,
1955
1985
  S: this,
1956
1986
  C: (f, a) => f(...a)
1957
1987
  });
@@ -1969,7 +1999,7 @@ var InvitationsHandler = class {
1969
1999
  ...protocol.toJSON()
1970
2000
  }, {
1971
2001
  F: __dxlog_file7,
1972
- L: 343,
2002
+ L: 344,
1973
2003
  S: this,
1974
2004
  C: (f, a) => f(...a)
1975
2005
  });
@@ -1979,7 +2009,7 @@ var InvitationsHandler = class {
1979
2009
  } else {
1980
2010
  log5("auth failed", err, {
1981
2011
  F: __dxlog_file7,
1982
- L: 346,
2012
+ L: 347,
1983
2013
  S: this,
1984
2014
  C: (f, a) => f(...a)
1985
2015
  });
@@ -1992,7 +2022,7 @@ var InvitationsHandler = class {
1992
2022
  scheduleTask2(ctx, async () => {
1993
2023
  invariant6(invitation.swarmKey, void 0, {
1994
2024
  F: __dxlog_file7,
1995
- L: 356,
2025
+ L: 357,
1996
2026
  S: this,
1997
2027
  A: [
1998
2028
  "invitation.swarmKey",
@@ -2006,7 +2036,8 @@ var InvitationsHandler = class {
2006
2036
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
2007
2037
  teleport.addExtension("dxos.halo.invitations", createExtension());
2008
2038
  }),
2009
- topology: new StarTopology(topic)
2039
+ topology: new StarTopology(topic),
2040
+ label: "invitation guest"
2010
2041
  });
2011
2042
  ctx.onDispose(() => swarmConnection.close());
2012
2043
  setState({
@@ -2242,7 +2273,6 @@ var SpaceInvitationProtocol = class {
2242
2273
  };
2243
2274
  }
2244
2275
  async admit(request, guestProfile) {
2245
- var _a;
2246
2276
  invariant8(this._spaceKey, void 0, {
2247
2277
  F: __dxlog_file9,
2248
2278
  L: 42,
@@ -2306,7 +2336,7 @@ var SpaceInvitationProtocol = class {
2306
2336
  space: {
2307
2337
  credential: spaceMemberCredential,
2308
2338
  controlTimeframe: space.inner.controlPipeline.state.timeframe,
2309
- dataTimeframe: (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.timeframe
2339
+ dataTimeframe: space.dataPipeline.pipelineState?.timeframe
2310
2340
  }
2311
2341
  };
2312
2342
  }
@@ -2410,9 +2440,8 @@ var ClientRpcServer = class {
2410
2440
  await this._rpcPeer.close();
2411
2441
  }
2412
2442
  _getServiceHandler(serviceName) {
2413
- var _a;
2414
2443
  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}`));
2444
+ const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
2416
2445
  const service = this._serviceRegistry.services[key];
2417
2446
  if (!service) {
2418
2447
  throw new Error(`Service not available: ${serviceName}`);
@@ -2427,13 +2456,14 @@ var ClientRpcServer = class {
2427
2456
  import { getFirstStreamValue } from "@dxos/codec-protobuf";
2428
2457
  import { credentialTypeFilter } from "@dxos/credentials";
2429
2458
  import { DocumentModel } from "@dxos/document-model";
2459
+ import { TYPE_PROPERTIES } from "@dxos/echo-db";
2430
2460
  import { invariant as invariant9 } from "@dxos/invariant";
2431
2461
  import { log as log8 } from "@dxos/log";
2432
2462
  import { STORAGE_VERSION } from "@dxos/protocols";
2433
2463
  import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
2434
2464
 
2435
2465
  // packages/sdk/client-services/src/version.ts
2436
- var DXOS_VERSION = "0.1.56-main.c19b7cd";
2466
+ var DXOS_VERSION = "0.1.56-main.c277f68";
2437
2467
 
2438
2468
  // packages/sdk/client-services/src/packlets/services/platform.ts
2439
2469
  var getPlatform = () => {
@@ -2467,9 +2497,8 @@ var getPlatform = () => {
2467
2497
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2468
2498
  var DEFAULT_TIMEOUT = 1e3;
2469
2499
  var createDiagnostics = async (clientServices, serviceContext, config) => {
2470
- var _a, _b, _c;
2471
2500
  const diagnostics = {
2472
- created: new Date().toISOString(),
2501
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2473
2502
  platform: getPlatform(),
2474
2503
  client: {
2475
2504
  version: DXOS_VERSION,
@@ -2481,7 +2510,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2481
2510
  {
2482
2511
  invariant9(clientServices.LoggingService, "SystemService is not available.", {
2483
2512
  F: __dxlog_file10,
2484
- L: 87,
2513
+ L: 88,
2485
2514
  S: void 0,
2486
2515
  A: [
2487
2516
  "clientServices.LoggingService",
@@ -2499,16 +2528,16 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2499
2528
  spaceKey: identity.space.key,
2500
2529
  profile: identity.profileDocument
2501
2530
  };
2502
- const { devices } = (_a = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2531
+ const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
2503
2532
  timeout: DEFAULT_TIMEOUT
2504
- }).catch(() => void 0)) != null ? _a : {};
2533
+ }).catch(() => void 0) ?? {};
2505
2534
  diagnostics.devices = devices;
2506
2535
  if (serviceContext.dataSpaceManager) {
2507
- diagnostics.spaces = await Promise.all((_b = Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space))) != null ? _b : []);
2536
+ diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
2508
2537
  }
2509
- const { feeds = [] } = (_c = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2538
+ const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
2510
2539
  timeout: DEFAULT_TIMEOUT
2511
- }).catch(() => void 0)) != null ? _c : {};
2540
+ }).catch(() => void 0) ?? {};
2512
2541
  diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
2513
2542
  feedKey,
2514
2543
  bytes,
@@ -2521,16 +2550,13 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
2521
2550
  var getProperties = (space) => {
2522
2551
  let properties = {};
2523
2552
  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;
2553
+ const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === DocumentModel.meta.type && item.state?.type === TYPE_PROPERTIES);
2554
+ const state = propertiesItem?.state;
2555
+ properties = state?.data;
2530
2556
  } catch (err) {
2531
2557
  log8.warn(err.message, void 0, {
2532
2558
  F: __dxlog_file10,
2533
- L: 144,
2559
+ L: 145,
2534
2560
  S: void 0,
2535
2561
  C: (f, a) => f(...a)
2536
2562
  });
@@ -2538,7 +2564,6 @@ var getProperties = (space) => {
2538
2564
  return properties;
2539
2565
  };
2540
2566
  var getSpaceStats = async (space) => {
2541
- var _a, _b, _c, _d, _e, _f;
2542
2567
  const stats = {
2543
2568
  key: space.key,
2544
2569
  metrics: space.metrics,
@@ -2546,18 +2571,15 @@ var getSpaceStats = async (space) => {
2546
2571
  ...credential.subject.assertion,
2547
2572
  id: credential.id
2548
2573
  })),
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
- }),
2574
+ members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
2575
+ identity: {
2576
+ identityKey: member.key,
2577
+ profile: {
2578
+ displayName: member.assertion.profile?.displayName
2579
+ }
2580
+ },
2581
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
2582
+ })),
2561
2583
  pipeline: {
2562
2584
  // TODO(burdon): Pick properties from credentials if needed.
2563
2585
  // currentEpoch: space.dataPipeline.currentEpoch,
@@ -2567,11 +2589,11 @@ var getSpaceStats = async (space) => {
2567
2589
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
2568
2590
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
2569
2591
  // 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
2592
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
2593
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
2594
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
2595
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
2596
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
2575
2597
  }
2576
2598
  };
2577
2599
  if (space.dataPipeline.itemManager) {
@@ -2600,7 +2622,7 @@ import { PublicKey as PublicKey7 } from "@dxos/keys";
2600
2622
  import { log as log10 } from "@dxos/log";
2601
2623
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2602
2624
  import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
2603
- import { Timeframe } from "@dxos/timeframe";
2625
+ import { Timeframe as Timeframe2 } from "@dxos/timeframe";
2604
2626
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2605
2627
 
2606
2628
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
@@ -2669,7 +2691,7 @@ var NotarizationPlugin = class {
2669
2691
  errors.throw(err);
2670
2692
  }
2671
2693
  });
2672
- opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2694
+ opCtx?.onDispose(() => ctx.dispose());
2673
2695
  if (timeout !== 0) {
2674
2696
  scheduleTask3(ctx, () => {
2675
2697
  log9.warn("Notarization timeout", {
@@ -2762,11 +2784,10 @@ var NotarizationPlugin = class {
2762
2784
  * Called with credentials arriving from the control pipeline.
2763
2785
  */
2764
2786
  async processCredential(credential) {
2765
- var _a;
2766
2787
  if (!credential.id) {
2767
2788
  return;
2768
2789
  }
2769
- (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2790
+ this._processCredentialsTriggers.get(credential.id)?.wake();
2770
2791
  this._processedCredentials.add(credential.id);
2771
2792
  this._processCredentialsTriggers.delete(credential.id);
2772
2793
  }
@@ -2792,11 +2813,10 @@ var NotarizationPlugin = class {
2792
2813
  * Requests from other peers to notarize credentials.
2793
2814
  */
2794
2815
  async _onNotarize(request) {
2795
- var _a;
2796
2816
  if (!this._writer) {
2797
2817
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
2798
2818
  }
2799
- for (const credential of (_a = request.credentials) != null ? _a : []) {
2819
+ for (const credential of request.credentials ?? []) {
2800
2820
  invariant10(credential.id, "Credential must have an id", {
2801
2821
  F: __dxlog_file11,
2802
2822
  L: 200,
@@ -2897,7 +2917,6 @@ var DataSpace = class DataSpace2 {
2897
2917
  this.error = void 0;
2898
2918
  this.stateUpdate = new Event5();
2899
2919
  this.metrics = {};
2900
- var _a;
2901
2920
  this._inner = params.inner;
2902
2921
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2903
2922
  this._gossip = params.gossip;
@@ -2906,7 +2925,7 @@ var DataSpace = class DataSpace2 {
2906
2925
  this._feedStore = params.feedStore;
2907
2926
  this._metadataStore = params.metadataStore;
2908
2927
  this._signingContext = params.signingContext;
2909
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2928
+ this._callbacks = params.callbacks ?? {};
2910
2929
  this.authVerifier = new TrustedKeySetAuthVerifier({
2911
2930
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2912
2931
  update: this._inner.stateUpdate,
@@ -2950,14 +2969,13 @@ var DataSpace = class DataSpace2 {
2950
2969
  this._state = SpaceState.CONTROL_ONLY;
2951
2970
  this.stateUpdate.emit();
2952
2971
  this.metrics = {};
2953
- this.metrics.open = new Date();
2972
+ this.metrics.open = /* @__PURE__ */ new Date();
2954
2973
  }
2955
2974
  async close() {
2956
2975
  await this._close();
2957
2976
  }
2958
2977
  async _close() {
2959
- var _a, _b;
2960
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2978
+ await this._callbacks.beforeClose?.();
2961
2979
  this._state = SpaceState.CLOSED;
2962
2980
  await this._ctx.dispose();
2963
2981
  this._ctx = new Context7();
@@ -2979,7 +2997,7 @@ var DataSpace = class DataSpace2 {
2979
2997
  initializeDataPipelineAsync() {
2980
2998
  scheduleTask4(this._ctx, async () => {
2981
2999
  try {
2982
- this.metrics.pipelineInitBegin = new Date();
3000
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2983
3001
  await this.initializeDataPipeline();
2984
3002
  } catch (err) {
2985
3003
  if (err instanceof CancelledError) {
@@ -3001,12 +3019,11 @@ var DataSpace = class DataSpace2 {
3001
3019
  this.error = err;
3002
3020
  this.stateUpdate.emit();
3003
3021
  } finally {
3004
- this.metrics.ready = new Date();
3022
+ this.metrics.ready = /* @__PURE__ */ new Date();
3005
3023
  }
3006
3024
  });
3007
3025
  }
3008
3026
  async initializeDataPipeline() {
3009
- var _a, _b, _c, _d;
3010
3027
  if (this._state !== SpaceState.CONTROL_ONLY) {
3011
3028
  throw new SystemError("Invalid operation");
3012
3029
  }
@@ -3015,7 +3032,7 @@ var DataSpace = class DataSpace2 {
3015
3032
  ctx: this._ctx,
3016
3033
  breakOnStall: false
3017
3034
  });
3018
- this.metrics.controlPipelineReady = new Date();
3035
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3019
3036
  await this._createWritableFeeds();
3020
3037
  log10("writable feeds created", void 0, {
3021
3038
  F: __dxlog_file12,
@@ -3032,7 +3049,7 @@ var DataSpace = class DataSpace2 {
3032
3049
  }), this._inner.controlPipeline.writer));
3033
3050
  }
3034
3051
  await this._inner.initializeDataPipeline();
3035
- this.metrics.dataPipelineOpen = new Date();
3052
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3036
3053
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3037
3054
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3038
3055
  F: __dxlog_file12,
@@ -3044,17 +3061,17 @@ var DataSpace = class DataSpace2 {
3044
3061
  ctx: this._ctx,
3045
3062
  breakOnStall: false
3046
3063
  });
3047
- this.metrics.dataPipelineReady = new Date();
3064
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3048
3065
  log10("data pipeline ready", void 0, {
3049
3066
  F: __dxlog_file12,
3050
3067
  L: 257,
3051
3068
  S: this,
3052
3069
  C: (f, a) => f(...a)
3053
3070
  });
3054
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3071
+ await this._callbacks.beforeReady?.();
3055
3072
  this._state = SpaceState.READY;
3056
3073
  this.stateUpdate.emit();
3057
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3074
+ await this._callbacks.afterReady?.();
3058
3075
  }
3059
3076
  async _createWritableFeeds() {
3060
3077
  const credentials = [];
@@ -3101,7 +3118,6 @@ var DataSpace = class DataSpace2 {
3101
3118
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3102
3119
  }
3103
3120
  async createEpoch() {
3104
- var _a, _b;
3105
3121
  const epoch = await this.dataPipeline.createEpoch();
3106
3122
  const receipt = await this.inner.controlPipeline.writer.write({
3107
3123
  credential: {
@@ -3114,14 +3130,14 @@ var DataSpace = class DataSpace2 {
3114
3130
  })
3115
3131
  }
3116
3132
  });
3117
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3133
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
3118
3134
  [
3119
3135
  receipt.feedKey,
3120
3136
  receipt.seq
3121
3137
  ]
3122
3138
  ]));
3123
3139
  if (ENABLE_FEED_PURGE) {
3124
- for (const feed of (_b = (_a = this.inner.dataPipeline.pipelineState) == null ? void 0 : _a.feeds) != null ? _b : []) {
3140
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3125
3141
  const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3126
3142
  if (indexBeforeEpoch === void 0) {
3127
3143
  continue;
@@ -3183,9 +3199,8 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
3183
3199
  import { createCredential } from "@dxos/credentials";
3184
3200
  import { failUndefined as failUndefined2 } from "@dxos/debug";
3185
3201
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3186
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3202
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3187
3203
  var spaceGenesis = async (keyring, signingContext, space) => {
3188
- var _a, _b, _c, _d;
3189
3204
  const credentials = [
3190
3205
  await createCredential({
3191
3206
  signer: keyring,
@@ -3205,11 +3220,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3205
3220
  spaceKey: space.key,
3206
3221
  role: SpaceMember2.Role.ADMIN,
3207
3222
  profile: signingContext.profile,
3208
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3223
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
3209
3224
  }
3210
3225
  }),
3211
3226
  await signingContext.credentialSigner.createCredential({
3212
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3227
+ subject: space.controlFeedKey ?? failUndefined2(),
3213
3228
  assertion: {
3214
3229
  "@type": "dxos.halo.credentials.AdmittedFeed",
3215
3230
  spaceKey: space.key,
@@ -3219,7 +3234,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3219
3234
  }
3220
3235
  }),
3221
3236
  await signingContext.credentialSigner.createCredential({
3222
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3237
+ subject: space.dataFeedKey ?? failUndefined2(),
3223
3238
  assertion: {
3224
3239
  "@type": "dxos.halo.credentials.AdmittedFeed",
3225
3240
  spaceKey: space.key,
@@ -3229,12 +3244,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3229
3244
  }
3230
3245
  }),
3231
3246
  await signingContext.credentialSigner.createCredential({
3232
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3247
+ subject: space.key ?? failUndefined2(),
3233
3248
  assertion: {
3234
3249
  "@type": "dxos.halo.credentials.Epoch",
3235
3250
  number: 0,
3236
3251
  previousId: void 0,
3237
- timeframe: new Timeframe2(),
3252
+ timeframe: new Timeframe3(),
3238
3253
  snapshotCid: void 0
3239
3254
  }
3240
3255
  })
@@ -3494,7 +3509,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3494
3509
  onAuthFailure: () => {
3495
3510
  log11.warn("auth failure", void 0, {
3496
3511
  F: __dxlog_file13,
3497
- L: 213,
3512
+ L: 217,
3498
3513
  S: this,
3499
3514
  C: (f, a) => f(...a)
3500
3515
  });
@@ -3518,7 +3533,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3518
3533
  space: space.key
3519
3534
  }, {
3520
3535
  F: __dxlog_file13,
3521
- L: 231,
3536
+ L: 235,
3522
3537
  S: this,
3523
3538
  C: (f, a) => f(...a)
3524
3539
  });
@@ -3530,7 +3545,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3530
3545
  open: this._isOpen
3531
3546
  }, {
3532
3547
  F: __dxlog_file13,
3533
- L: 238,
3548
+ L: 242,
3534
3549
  S: this,
3535
3550
  C: (f, a) => f(...a)
3536
3551
  });
@@ -3543,7 +3558,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3543
3558
  space: space.key
3544
3559
  }, {
3545
3560
  F: __dxlog_file13,
3546
- L: 244,
3561
+ L: 248,
3547
3562
  S: this,
3548
3563
  C: (f, a) => f(...a)
3549
3564
  });
@@ -3608,9 +3623,8 @@ var SpacesServiceImpl = class {
3608
3623
  return this._serializeSpace(space);
3609
3624
  }
3610
3625
  async updateSpace({ spaceKey, state }) {
3611
- var _a;
3612
3626
  const dataSpaceManager = await this._getDataSpaceManager();
3613
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3627
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3614
3628
  if (state) {
3615
3629
  switch (state) {
3616
3630
  case SpaceState3.ACTIVE:
@@ -3641,7 +3655,7 @@ var SpacesServiceImpl = class {
3641
3655
  spaces
3642
3656
  });
3643
3657
  }, {
3644
- maxFrequency: 2
3658
+ maxFrequency: false ? void 0 : 2
3645
3659
  });
3646
3660
  scheduleTask5(ctx, async () => {
3647
3661
  const dataSpaceManager = await this._getDataSpaceManager();
@@ -3674,17 +3688,15 @@ var SpacesServiceImpl = class {
3674
3688
  });
3675
3689
  }
3676
3690
  async postMessage({ spaceKey, channel, message }) {
3677
- var _a;
3678
3691
  const dataSpaceManager = await this._getDataSpaceManager();
3679
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3692
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3680
3693
  await space.postMessage(getChannelId(channel), message);
3681
3694
  }
3682
3695
  subscribeMessages({ spaceKey, channel }) {
3683
3696
  return new Stream10(({ ctx, next }) => {
3684
3697
  scheduleTask5(ctx, async () => {
3685
- var _a;
3686
3698
  const dataSpaceManager = await this._getDataSpaceManager();
3687
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3699
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3688
3700
  const handle = space.listen(getChannelId(channel), (message) => {
3689
3701
  next(message);
3690
3702
  });
@@ -3694,8 +3706,7 @@ var SpacesServiceImpl = class {
3694
3706
  }
3695
3707
  queryCredentials({ spaceKey }) {
3696
3708
  return new Stream10(({ ctx, next }) => {
3697
- var _a;
3698
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3709
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3699
3710
  const processor = {
3700
3711
  processCredential: async (credential) => {
3701
3712
  next(credential);
@@ -3706,9 +3717,8 @@ var SpacesServiceImpl = class {
3706
3717
  });
3707
3718
  }
3708
3719
  async writeCredentials({ spaceKey, credentials }) {
3709
- var _a;
3710
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3711
- for (const credential of credentials != null ? credentials : []) {
3720
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3721
+ for (const credential of credentials ?? []) {
3712
3722
  await space.controlPipeline.writer.write({
3713
3723
  credential: {
3714
3724
  credential
@@ -3717,13 +3727,11 @@ var SpacesServiceImpl = class {
3717
3727
  }
3718
3728
  }
3719
3729
  async createEpoch({ spaceKey }) {
3720
- var _a;
3721
3730
  const dataSpaceManager = await this._getDataSpaceManager();
3722
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3731
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3723
3732
  await space.createEpoch();
3724
3733
  }
3725
3734
  _serializeSpace(space) {
3726
- var _a, _b, _c, _d, _e, _f, _g;
3727
3735
  return {
3728
3736
  spaceKey: space.key,
3729
3737
  state: space.state,
@@ -3735,16 +3743,15 @@ var SpacesServiceImpl = class {
3735
3743
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3736
3744
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3737
3745
  totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
3738
- dataFeeds: (_b = (_a = space.dataPipeline.pipelineState) == null ? void 0 : _a.feeds.map((feed) => feed.key)) != null ? _b : [],
3739
- startDataTimeframe: (_c = space.dataPipeline.pipelineState) == null ? void 0 : _c.startTimeframe,
3740
- currentDataTimeframe: (_d = space.dataPipeline.pipelineState) == null ? void 0 : _d.timeframe,
3741
- targetDataTimeframe: (_e = space.dataPipeline.pipelineState) == null ? void 0 : _e.targetTimeframe,
3742
- totalDataTimeframe: (_f = space.dataPipeline.pipelineState) == null ? void 0 : _f.endTimeframe
3746
+ dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
3747
+ startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
3748
+ currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
3749
+ targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
3750
+ totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
3743
3751
  },
3744
3752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3745
- var _a2, _b2, _c2;
3746
3753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3747
- const isMe = (_a2 = this._identityManager.identity) == null ? void 0 : _a2.identityKey.equals(member.key);
3754
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3748
3755
  if (isMe) {
3749
3756
  peers.push(space.presence.getLocalState());
3750
3757
  }
@@ -3752,14 +3759,14 @@ var SpacesServiceImpl = class {
3752
3759
  identity: {
3753
3760
  identityKey: member.key,
3754
3761
  profile: {
3755
- displayName: (_c2 = (_b2 = member.assertion.profile) == null ? void 0 : _b2.displayName) != null ? _c2 : humanize(member.key)
3762
+ displayName: member.assertion.profile?.displayName ?? humanize(member.key)
3756
3763
  }
3757
3764
  },
3758
3765
  presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3759
3766
  peerStates: peers
3760
3767
  };
3761
3768
  }),
3762
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3769
+ creator: space.inner.spaceState.creator?.key,
3763
3770
  cache: space.cache,
3764
3771
  metrics: space.metrics
3765
3772
  };
@@ -3782,6 +3789,7 @@ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/prot
3782
3789
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3783
3790
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3784
3791
  import { trace as Trace2 } from "@dxos/tracing";
3792
+ import { safeInstanceof } from "@dxos/util";
3785
3793
  function _ts_decorate5(decorators, target, key, desc) {
3786
3794
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3787
3795
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3813,7 +3821,8 @@ var ServiceContext = class ServiceContext2 {
3813
3821
  root: storage.createDirectory("feeds"),
3814
3822
  signer: this.keyring,
3815
3823
  hypercore: {
3816
- valueEncoding
3824
+ valueEncoding,
3825
+ stats: true
3817
3826
  }
3818
3827
  })
3819
3828
  });
@@ -3827,16 +3836,13 @@ var ServiceContext = class ServiceContext2 {
3827
3836
  });
3828
3837
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3829
3838
  this.invitations = new InvitationsHandler(this.networkManager);
3830
- this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3831
- var _a;
3832
- return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3833
- }, this._acceptIdentity.bind(this)));
3839
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3834
3840
  }
3835
3841
  async open(ctx) {
3836
3842
  await this._checkStorageVersion();
3837
3843
  log13("opening...", void 0, {
3838
3844
  F: __dxlog_file15,
3839
- L: 131,
3845
+ L: 135,
3840
3846
  S: this,
3841
3847
  C: (f, a) => f(...a)
3842
3848
  });
@@ -3844,7 +3850,7 @@ var ServiceContext = class ServiceContext2 {
3844
3850
  id: this._instanceId
3845
3851
  }), {
3846
3852
  F: __dxlog_file15,
3847
- L: 132,
3853
+ L: 136,
3848
3854
  S: this,
3849
3855
  C: (f, a) => f(...a)
3850
3856
  });
@@ -3859,29 +3865,28 @@ var ServiceContext = class ServiceContext2 {
3859
3865
  id: this._instanceId
3860
3866
  }), {
3861
3867
  F: __dxlog_file15,
3862
- L: 140,
3868
+ L: 144,
3863
3869
  S: this,
3864
3870
  C: (f, a) => f(...a)
3865
3871
  });
3866
3872
  log13("opened", void 0, {
3867
3873
  F: __dxlog_file15,
3868
- L: 141,
3874
+ L: 145,
3869
3875
  S: this,
3870
3876
  C: (f, a) => f(...a)
3871
3877
  });
3872
3878
  }
3873
3879
  async close() {
3874
- var _a;
3875
3880
  log13("closing...", void 0, {
3876
3881
  F: __dxlog_file15,
3877
- L: 145,
3882
+ L: 149,
3878
3883
  S: this,
3879
3884
  C: (f, a) => f(...a)
3880
3885
  });
3881
3886
  if (this._deviceSpaceSync && this.identityManager.identity) {
3882
3887
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3883
3888
  }
3884
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3889
+ await this.dataSpaceManager?.close();
3885
3890
  await this.identityManager.close();
3886
3891
  await this.spaceManager.close();
3887
3892
  await this.feedStore.close();
@@ -3890,7 +3895,7 @@ var ServiceContext = class ServiceContext2 {
3890
3895
  this.dataServiceSubscriptions.clear();
3891
3896
  log13("closed", void 0, {
3892
3897
  F: __dxlog_file15,
3893
- L: 156,
3898
+ L: 160,
3894
3899
  S: this,
3895
3900
  C: (f, a) => f(...a)
3896
3901
  });
@@ -3904,7 +3909,7 @@ var ServiceContext = class ServiceContext2 {
3904
3909
  const factory = this._handlerFactories.get(invitation.kind);
3905
3910
  invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3906
3911
  F: __dxlog_file15,
3907
- L: 168,
3912
+ L: 171,
3908
3913
  S: this,
3909
3914
  A: [
3910
3915
  "factory",
@@ -3926,14 +3931,13 @@ var ServiceContext = class ServiceContext2 {
3926
3931
  }
3927
3932
  // Called when identity is created.
3928
3933
  async _initialize(ctx) {
3929
- var _a;
3930
3934
  log13("initializing spaces...", void 0, {
3931
3935
  F: __dxlog_file15,
3932
- L: 190,
3936
+ L: 192,
3933
3937
  S: this,
3934
3938
  C: (f, a) => f(...a)
3935
3939
  });
3936
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3940
+ const identity = this.identityManager.identity ?? failUndefined3();
3937
3941
  const signingContext = {
3938
3942
  credentialSigner: identity.getIdentityCredentialSigner(),
3939
3943
  identityKey: identity.identityKey,
@@ -3952,7 +3956,7 @@ var ServiceContext = class ServiceContext2 {
3952
3956
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3953
3957
  invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3954
3958
  F: __dxlog_file15,
3955
- L: 213,
3959
+ L: 215,
3956
3960
  S: this,
3957
3961
  A: [
3958
3962
  "this.dataSpaceManager",
@@ -3976,7 +3980,7 @@ var ServiceContext = class ServiceContext2 {
3976
3980
  details: assertion
3977
3981
  }, {
3978
3982
  F: __dxlog_file15,
3979
- L: 229,
3983
+ L: 231,
3980
3984
  S: this,
3981
3985
  C: (f, a) => f(...a)
3982
3986
  });
@@ -3987,7 +3991,7 @@ var ServiceContext = class ServiceContext2 {
3987
3991
  details: assertion
3988
3992
  }, {
3989
3993
  F: __dxlog_file15,
3990
- L: 233,
3994
+ L: 235,
3991
3995
  S: this,
3992
3996
  C: (f, a) => f(...a)
3993
3997
  });
@@ -3998,7 +4002,7 @@ var ServiceContext = class ServiceContext2 {
3998
4002
  details: assertion
3999
4003
  }, {
4000
4004
  F: __dxlog_file15,
4001
- L: 238,
4005
+ L: 240,
4002
4006
  S: this,
4003
4007
  C: (f, a) => f(...a)
4004
4008
  });
@@ -4009,7 +4013,7 @@ var ServiceContext = class ServiceContext2 {
4009
4013
  } catch (err) {
4010
4014
  log13.catch(err, void 0, {
4011
4015
  F: __dxlog_file15,
4012
- L: 244,
4016
+ L: 246,
4013
4017
  S: this,
4014
4018
  C: (f, a) => f(...a)
4015
4019
  });
@@ -4026,6 +4030,7 @@ _ts_decorate5([
4026
4030
  Trace2.span()
4027
4031
  ], ServiceContext.prototype, "_initialize", null);
4028
4032
  ServiceContext = _ts_decorate5([
4033
+ safeInstanceof("dxos.client-services.ServiceContext"),
4029
4034
  Trace2.resource()
4030
4035
  ], ServiceContext);
4031
4036
 
@@ -4078,7 +4083,7 @@ var Lock = class {
4078
4083
  S: this,
4079
4084
  C: (f, a) => f(...a)
4080
4085
  });
4081
- } catch (e) {
4086
+ } catch {
4082
4087
  log14("stealing lock...", void 0, {
4083
4088
  F: __dxlog_file16,
4084
4089
  L: 46,
@@ -4115,8 +4120,7 @@ var Lock = class {
4115
4120
  void navigator.locks.request(this._lockKey, {
4116
4121
  steal
4117
4122
  }, async () => {
4118
- var _a, _b;
4119
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4123
+ await this._onAcquire?.();
4120
4124
  acquired.wake();
4121
4125
  this._releaseTrigger = new Trigger6();
4122
4126
  await this._releaseTrigger.wait();
@@ -4126,7 +4130,7 @@ var Lock = class {
4126
4130
  S: this,
4127
4131
  C: (f, a) => f(...a)
4128
4132
  });
4129
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
4133
+ await this._onRelease?.();
4130
4134
  log14("released lock", void 0, {
4131
4135
  F: __dxlog_file16,
4132
4136
  L: 74,
@@ -4134,8 +4138,7 @@ var Lock = class {
4134
4138
  C: (f, a) => f(...a)
4135
4139
  });
4136
4140
  }).catch(async () => {
4137
- var _a;
4138
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4141
+ await this._onRelease?.();
4139
4142
  });
4140
4143
  await acquired.wait();
4141
4144
  log14("recieved lock", {
@@ -4163,7 +4166,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
4163
4166
  import { isNode } from "@dxos/util";
4164
4167
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
4165
4168
  var createStorageObjects = (config) => {
4166
- const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
4169
+ const { path = isNode() ? DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
4167
4170
  if (persistent && storageType === StorageDriver.RAM) {
4168
4171
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4169
4172
  }
@@ -4259,21 +4262,17 @@ var DevicesServiceImpl = class {
4259
4262
  queryDevices() {
4260
4263
  return new Stream11(({ next }) => {
4261
4264
  const update = () => {
4262
- var _a;
4263
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4265
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4264
4266
  if (!deviceKeys) {
4265
4267
  next({
4266
4268
  devices: []
4267
4269
  });
4268
4270
  } else {
4269
4271
  next({
4270
- devices: Array.from(deviceKeys.values()).map((key) => {
4271
- var _a2;
4272
- return {
4273
- deviceKey: key,
4274
- kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
- };
4276
- })
4272
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4273
+ deviceKey: key,
4274
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
+ }))
4277
4276
  });
4278
4277
  }
4279
4278
  };
@@ -4301,7 +4300,7 @@ import { jsonify, numericalValues, tracer } from "@dxos/util";
4301
4300
  var LoggingServiceImpl = class {
4302
4301
  constructor() {
4303
4302
  this._logs = new Event7();
4304
- this._started = new Date();
4303
+ this._started = /* @__PURE__ */ new Date();
4305
4304
  this._logProcessor = (_config, entry2) => {
4306
4305
  this._logs.emit(entry2);
4307
4306
  };
@@ -4331,8 +4330,7 @@ var LoggingServiceImpl = class {
4331
4330
  */
4332
4331
  queryMetrics({ interval = 5e3 }) {
4333
4332
  const getNumericalValues = (key) => {
4334
- var _a;
4335
- const events = (_a = tracer.get(key)) != null ? _a : [];
4333
+ const events = tracer.get(key) ?? [];
4336
4334
  return {
4337
4335
  key,
4338
4336
  stats: numericalValues(events, "duration")
@@ -4341,14 +4339,14 @@ var LoggingServiceImpl = class {
4341
4339
  return new Stream12(({ next }) => {
4342
4340
  const update = () => {
4343
4341
  const metrics = {
4344
- timestamp: new Date(),
4342
+ timestamp: /* @__PURE__ */ new Date(),
4345
4343
  values: [
4346
4344
  getNumericalValues("dxos.echo.pipeline.control"),
4347
4345
  getNumericalValues("dxos.echo.pipeline.data")
4348
4346
  ].filter(Boolean)
4349
4347
  };
4350
4348
  next({
4351
- timestamp: new Date(),
4349
+ timestamp: /* @__PURE__ */ new Date(),
4352
4350
  metrics
4353
4351
  });
4354
4352
  };
@@ -4362,11 +4360,10 @@ var LoggingServiceImpl = class {
4362
4360
  queryLogs(request) {
4363
4361
  return new Stream12(({ ctx, next }) => {
4364
4362
  const handler = (entry2) => {
4365
- var _a, _b, _c, _d, _e;
4366
4363
  if (LOG_PROCESSING > 0) {
4367
4364
  return;
4368
4365
  }
4369
- 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"))) {
4366
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4370
4367
  return;
4371
4368
  }
4372
4369
  if (!shouldLog(entry2, request)) {
@@ -4375,11 +4372,11 @@ var LoggingServiceImpl = class {
4375
4372
  const record = {
4376
4373
  ...entry2,
4377
4374
  context: jsonify(getContextFromEntry(entry2)),
4378
- timestamp: new Date(),
4375
+ timestamp: /* @__PURE__ */ new Date(),
4379
4376
  meta: {
4380
4377
  // TODO(dmaretskyi): Fix proto.
4381
- file: (_c = (_b = entry2.meta) == null ? void 0 : _b.F) != null ? _c : "",
4382
- line: (_e = (_d = entry2.meta) == null ? void 0 : _d.L) != null ? _e : 0
4378
+ file: entry2.meta?.F ?? "",
4379
+ line: entry2.meta?.L ?? 0
4383
4380
  }
4384
4381
  };
4385
4382
  try {
@@ -4402,15 +4399,11 @@ var matchFilter = (filter, level, path, options) => {
4402
4399
  }
4403
4400
  };
4404
4401
  var shouldLog = (entry2, request) => {
4405
- var _a;
4406
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4402
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
4407
4403
  if (request.filters === void 0) {
4408
4404
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
4409
4405
  } else {
4410
- return request.filters.some((filter) => {
4411
- var _a2, _b;
4412
- return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
4413
- });
4406
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4414
4407
  }
4415
4408
  };
4416
4409
  var LOG_PROCESSING = 0;
@@ -4461,8 +4454,7 @@ var SystemServiceImpl = class {
4461
4454
  this._onReset = onReset;
4462
4455
  }
4463
4456
  async getConfig() {
4464
- var _a, _b;
4465
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4457
+ return this._config?.values ?? {};
4466
4458
  }
4467
4459
  /**
4468
4460
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4470,7 +4462,7 @@ var SystemServiceImpl = class {
4470
4462
  async getDiagnostics({ keys } = {}) {
4471
4463
  const diagnostics = await this._getDiagnostics();
4472
4464
  return {
4473
- timestamp: new Date(),
4465
+ timestamp: /* @__PURE__ */ new Date(),
4474
4466
  diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4475
4467
  truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4476
4468
  humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
@@ -4561,11 +4553,10 @@ var ClientServicesHost = class ClientServicesHost2 {
4561
4553
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4562
4554
  },
4563
4555
  onUpdateStatus: async (status) => {
4564
- var _a, _b;
4565
4556
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
4566
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4557
+ await this._resourceLock?.acquire();
4567
4558
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
4568
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4559
+ await this._resourceLock?.release();
4569
4560
  }
4570
4561
  },
4571
4562
  onReset: async () => {
@@ -4602,7 +4593,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4602
4593
  * Can only be called once.
4603
4594
  */
4604
4595
  initialize({ config, ...options }) {
4605
- var _a, _b, _c;
4606
4596
  invariant13(!this._open, "service host is open", {
4607
4597
  F: __dxlog_file17,
4608
4598
  L: 181,
@@ -4612,7 +4602,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4612
4602
  "'service host is open'"
4613
4603
  ]
4614
4604
  });
4615
- log16.info("initializing...", void 0, {
4605
+ log16("initializing...", void 0, {
4616
4606
  F: __dxlog_file17,
4617
4607
  L: 182,
4618
4608
  S: this,
@@ -4634,8 +4624,8 @@ var ClientServicesHost = class ClientServicesHost2 {
4634
4624
  }
4635
4625
  }
4636
4626
  const { connectionLog = true, transportFactory = createWebRTCTransportFactory({
4637
- iceServers: (_a = this._config) == null ? void 0 : _a.get("runtime.services.ice")
4638
- }), signalManager = new WebsocketSignalManager((_c = (_b = this._config) == null ? void 0 : _b.get("runtime.services.signaling")) != null ? _c : []) } = options;
4627
+ iceServers: this._config?.get("runtime.services.ice")
4628
+ }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4639
4629
  this._signalManager = signalManager;
4640
4630
  invariant13(!this._networkManager, "network manager already set", {
4641
4631
  F: __dxlog_file17,
@@ -4651,7 +4641,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4651
4641
  transportFactory,
4652
4642
  signalManager
4653
4643
  });
4654
- log16.info("initialized", void 0, {
4644
+ log16("initialized", void 0, {
4655
4645
  F: __dxlog_file17,
4656
4646
  L: 208,
4657
4647
  S: this,
@@ -4659,7 +4649,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4659
4649
  });
4660
4650
  }
4661
4651
  async open(ctx) {
4662
- var _a, _b, _c;
4663
4652
  if (this._open) {
4664
4653
  return;
4665
4654
  }
@@ -4709,20 +4698,20 @@ var ClientServicesHost = class ClientServicesHost2 {
4709
4698
  ]
4710
4699
  });
4711
4700
  this._opening = true;
4712
- log16.info("opening...", {
4713
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4701
+ log16("opening...", {
4702
+ lockKey: this._resourceLock?.lockKey
4714
4703
  }, {
4715
4704
  F: __dxlog_file17,
4716
4705
  L: 227,
4717
4706
  S: this,
4718
4707
  C: (f, a) => f(...a)
4719
4708
  });
4720
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4709
+ await this._resourceLock?.acquire();
4721
4710
  await this._loggingService.open();
4722
4711
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4723
4712
  this._serviceRegistry.setServices({
4724
4713
  SystemService: this._systemService,
4725
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4714
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4726
4715
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4727
4716
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4728
4717
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4744,12 +4733,12 @@ var ClientServicesHost = class ClientServicesHost2 {
4744
4733
  this._opening = false;
4745
4734
  this._open = true;
4746
4735
  this._statusUpdate.emit();
4747
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4748
- log16.info("opened", {
4736
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4737
+ log16("opened", {
4749
4738
  deviceKey
4750
4739
  }, {
4751
4740
  F: __dxlog_file17,
4752
- L: 280,
4741
+ L: 284,
4753
4742
  S: this,
4754
4743
  C: (f, a) => f(...a)
4755
4744
  });
@@ -4757,22 +4746,21 @@ var ClientServicesHost = class ClientServicesHost2 {
4757
4746
  id: traceId
4758
4747
  }), {
4759
4748
  F: __dxlog_file17,
4760
- L: 281,
4749
+ L: 285,
4761
4750
  S: this,
4762
4751
  C: (f, a) => f(...a)
4763
4752
  });
4764
4753
  }
4765
4754
  async close() {
4766
- var _a;
4767
4755
  if (!this._open) {
4768
4756
  return;
4769
4757
  }
4770
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4771
- log16.info("closing...", {
4758
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4759
+ log16("closing...", {
4772
4760
  deviceKey
4773
4761
  }, {
4774
4762
  F: __dxlog_file17,
4775
- L: 292,
4763
+ L: 296,
4776
4764
  S: this,
4777
4765
  C: (f, a) => f(...a)
4778
4766
  });
@@ -4783,37 +4771,36 @@ var ClientServicesHost = class ClientServicesHost2 {
4783
4771
  await this._serviceContext.close();
4784
4772
  this._open = false;
4785
4773
  this._statusUpdate.emit();
4786
- log16.info("closed", {
4774
+ log16("closed", {
4787
4775
  deviceKey
4788
4776
  }, {
4789
4777
  F: __dxlog_file17,
4790
- L: 298,
4778
+ L: 302,
4791
4779
  S: this,
4792
4780
  C: (f, a) => f(...a)
4793
4781
  });
4794
4782
  }
4795
4783
  async reset() {
4796
- var _a, _b, _c;
4797
4784
  const traceId = PublicKey10.random().toHex();
4798
4785
  log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4799
4786
  id: traceId
4800
4787
  }), {
4801
4788
  F: __dxlog_file17,
4802
- L: 303,
4789
+ L: 307,
4803
4790
  S: this,
4804
4791
  C: (f, a) => f(...a)
4805
4792
  });
4806
4793
  log16("resetting...", void 0, {
4807
4794
  F: __dxlog_file17,
4808
- L: 305,
4795
+ L: 309,
4809
4796
  S: this,
4810
4797
  C: (f, a) => f(...a)
4811
4798
  });
4812
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4799
+ await this._serviceContext?.close();
4813
4800
  await this._storage.reset();
4814
4801
  log16("reset", void 0, {
4815
4802
  F: __dxlog_file17,
4816
- L: 308,
4803
+ L: 312,
4817
4804
  S: this,
4818
4805
  C: (f, a) => f(...a)
4819
4806
  });
@@ -4821,11 +4808,11 @@ var ClientServicesHost = class ClientServicesHost2 {
4821
4808
  id: traceId
4822
4809
  }), {
4823
4810
  F: __dxlog_file17,
4824
- L: 309,
4811
+ L: 313,
4825
4812
  S: this,
4826
4813
  C: (f, a) => f(...a)
4827
4814
  });
4828
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4815
+ await this._callbacks?.onReset?.();
4829
4816
  }
4830
4817
  };
4831
4818
  _ts_decorate7([
@@ -4879,4 +4866,4 @@ export {
4879
4866
  createDefaultModelFactory,
4880
4867
  ClientServicesHost
4881
4868
  };
4882
- //# sourceMappingURL=chunk-ZOTHWLK5.mjs.map
4869
+ //# sourceMappingURL=chunk-E7EKG5QQ.mjs.map