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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/lib/browser/{chunk-P6TNW4K5.mjs → chunk-CXJ3H4F5.mjs} +278 -287
  2. package/dist/lib/browser/chunk-CXJ3H4F5.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +8 -13
  4. package/dist/lib/browser/index.mjs.map +2 -2
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +30 -45
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +2 -2
  8. package/dist/lib/node/index.cjs +298 -312
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +310 -330
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/identity-manager.d.ts +5 -0
  14. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  15. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
  16. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/version.d.ts +1 -1
  24. package/package.json +34 -34
  25. package/src/packlets/identity/identity-manager.test.ts +11 -0
  26. package/src/packlets/identity/identity-manager.ts +18 -1
  27. package/src/packlets/identity/identity-service.test.ts +15 -1
  28. package/src/packlets/identity/identity-service.ts +23 -14
  29. package/src/packlets/invitations/invitations-handler.ts +2 -0
  30. package/src/packlets/services/diagnostics.ts +2 -1
  31. package/src/packlets/services/service-context.test.ts +59 -0
  32. package/src/packlets/services/service-context.ts +7 -4
  33. package/src/packlets/services/service-host.test.ts +1 -1
  34. package/src/packlets/services/service-host.ts +11 -7
  35. package/src/packlets/spaces/data-space-manager.test.ts +80 -22
  36. package/src/packlets/spaces/data-space-manager.ts +5 -1
  37. package/src/packlets/spaces/data-space.ts +16 -4
  38. package/src/packlets/vault/worker-runtime.ts +1 -1
  39. package/src/version.ts +1 -1
  40. package/dist/lib/browser/chunk-P6TNW4K5.mjs.map +0 -7
@@ -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.d9d1c3e";
2466
+ var DXOS_VERSION = "0.1.56-main.da2eab1";
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,
@@ -2885,6 +2905,7 @@ function _ts_decorate3(decorators, target, key, desc) {
2885
2905
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2886
2906
  }
2887
2907
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
2908
+ var ENABLE_FEED_PURGE = false;
2888
2909
  var DataSpace = class DataSpace2 {
2889
2910
  constructor(params) {
2890
2911
  this._ctx = new Context7();
@@ -2896,7 +2917,6 @@ var DataSpace = class DataSpace2 {
2896
2917
  this.error = void 0;
2897
2918
  this.stateUpdate = new Event5();
2898
2919
  this.metrics = {};
2899
- var _a;
2900
2920
  this._inner = params.inner;
2901
2921
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
2902
2922
  this._gossip = params.gossip;
@@ -2905,7 +2925,7 @@ var DataSpace = class DataSpace2 {
2905
2925
  this._feedStore = params.feedStore;
2906
2926
  this._metadataStore = params.metadataStore;
2907
2927
  this._signingContext = params.signingContext;
2908
- this._callbacks = (_a = params.callbacks) != null ? _a : {};
2928
+ this._callbacks = params.callbacks ?? {};
2909
2929
  this.authVerifier = new TrustedKeySetAuthVerifier({
2910
2930
  trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
2911
2931
  update: this._inner.stateUpdate,
@@ -2949,14 +2969,13 @@ var DataSpace = class DataSpace2 {
2949
2969
  this._state = SpaceState.CONTROL_ONLY;
2950
2970
  this.stateUpdate.emit();
2951
2971
  this.metrics = {};
2952
- this.metrics.open = new Date();
2972
+ this.metrics.open = /* @__PURE__ */ new Date();
2953
2973
  }
2954
2974
  async close() {
2955
2975
  await this._close();
2956
2976
  }
2957
2977
  async _close() {
2958
- var _a, _b;
2959
- await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2978
+ await this._callbacks.beforeClose?.();
2960
2979
  this._state = SpaceState.CLOSED;
2961
2980
  await this._ctx.dispose();
2962
2981
  this._ctx = new Context7();
@@ -2978,13 +2997,13 @@ var DataSpace = class DataSpace2 {
2978
2997
  initializeDataPipelineAsync() {
2979
2998
  scheduleTask4(this._ctx, async () => {
2980
2999
  try {
2981
- this.metrics.pipelineInitBegin = new Date();
3000
+ this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
2982
3001
  await this.initializeDataPipeline();
2983
3002
  } catch (err) {
2984
3003
  if (err instanceof CancelledError) {
2985
3004
  log10("data pipeline initialization cancelled", err, {
2986
3005
  F: __dxlog_file12,
2987
- L: 193,
3006
+ L: 199,
2988
3007
  S: this,
2989
3008
  C: (f, a) => f(...a)
2990
3009
  });
@@ -2992,7 +3011,7 @@ var DataSpace = class DataSpace2 {
2992
3011
  }
2993
3012
  log10.error("Error initializing data pipeline", err, {
2994
3013
  F: __dxlog_file12,
2995
- L: 197,
3014
+ L: 203,
2996
3015
  S: this,
2997
3016
  C: (f, a) => f(...a)
2998
3017
  });
@@ -3000,12 +3019,11 @@ var DataSpace = class DataSpace2 {
3000
3019
  this.error = err;
3001
3020
  this.stateUpdate.emit();
3002
3021
  } finally {
3003
- this.metrics.ready = new Date();
3022
+ this.metrics.ready = /* @__PURE__ */ new Date();
3004
3023
  }
3005
3024
  });
3006
3025
  }
3007
3026
  async initializeDataPipeline() {
3008
- var _a, _b, _c, _d;
3009
3027
  if (this._state !== SpaceState.CONTROL_ONLY) {
3010
3028
  throw new SystemError("Invalid operation");
3011
3029
  }
@@ -3014,11 +3032,11 @@ var DataSpace = class DataSpace2 {
3014
3032
  ctx: this._ctx,
3015
3033
  breakOnStall: false
3016
3034
  });
3017
- this.metrics.controlPipelineReady = new Date();
3035
+ this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3018
3036
  await this._createWritableFeeds();
3019
3037
  log10("writable feeds created", void 0, {
3020
3038
  F: __dxlog_file12,
3021
- L: 221,
3039
+ L: 227,
3022
3040
  S: this,
3023
3041
  C: (f, a) => f(...a)
3024
3042
  });
@@ -3031,11 +3049,11 @@ var DataSpace = class DataSpace2 {
3031
3049
  }), this._inner.controlPipeline.writer));
3032
3050
  }
3033
3051
  await this._inner.initializeDataPipeline();
3034
- this.metrics.dataPipelineOpen = new Date();
3052
+ this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3035
3053
  await cancelWithContext2(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3036
3054
  log10("waiting for data pipeline to reach target timeframe", void 0, {
3037
3055
  F: __dxlog_file12,
3038
- L: 242,
3056
+ L: 248,
3039
3057
  S: this,
3040
3058
  C: (f, a) => f(...a)
3041
3059
  });
@@ -3043,17 +3061,17 @@ var DataSpace = class DataSpace2 {
3043
3061
  ctx: this._ctx,
3044
3062
  breakOnStall: false
3045
3063
  });
3046
- this.metrics.dataPipelineReady = new Date();
3064
+ this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3047
3065
  log10("data pipeline ready", void 0, {
3048
3066
  F: __dxlog_file12,
3049
- L: 251,
3067
+ L: 257,
3050
3068
  S: this,
3051
3069
  C: (f, a) => f(...a)
3052
3070
  });
3053
- await ((_b = (_a = this._callbacks).beforeReady) == null ? void 0 : _b.call(_a));
3071
+ await this._callbacks.beforeReady?.();
3054
3072
  this._state = SpaceState.READY;
3055
3073
  this.stateUpdate.emit();
3056
- await ((_d = (_c = this._callbacks).afterReady) == null ? void 0 : _d.call(_c));
3074
+ await this._callbacks.afterReady?.();
3057
3075
  }
3058
3076
  async _createWritableFeeds() {
3059
3077
  const credentials = [];
@@ -3100,7 +3118,6 @@ var DataSpace = class DataSpace2 {
3100
3118
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
3101
3119
  }
3102
3120
  async createEpoch() {
3103
- var _a, _b;
3104
3121
  const epoch = await this.dataPipeline.createEpoch();
3105
3122
  const receipt = await this.inner.controlPipeline.writer.write({
3106
3123
  credential: {
@@ -3113,16 +3130,19 @@ var DataSpace = class DataSpace2 {
3113
3130
  })
3114
3131
  }
3115
3132
  });
3116
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([
3133
+ await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe2([
3117
3134
  [
3118
3135
  receipt.feedKey,
3119
3136
  receipt.seq
3120
3137
  ]
3121
3138
  ]));
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);
3139
+ if (ENABLE_FEED_PURGE) {
3140
+ for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
3141
+ const indexBeforeEpoch = epoch.timeframe.get(feed.key);
3142
+ if (indexBeforeEpoch === void 0) {
3143
+ continue;
3144
+ }
3145
+ await feed.safeClear(0, indexBeforeEpoch + 1);
3126
3146
  }
3127
3147
  }
3128
3148
  }
@@ -3179,9 +3199,8 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxo
3179
3199
  import { createCredential } from "@dxos/credentials";
3180
3200
  import { failUndefined as failUndefined2 } from "@dxos/debug";
3181
3201
  import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
3182
- import { Timeframe as Timeframe2 } from "@dxos/timeframe";
3202
+ import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3183
3203
  var spaceGenesis = async (keyring, signingContext, space) => {
3184
- var _a, _b, _c, _d;
3185
3204
  const credentials = [
3186
3205
  await createCredential({
3187
3206
  signer: keyring,
@@ -3201,11 +3220,11 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3201
3220
  spaceKey: space.key,
3202
3221
  role: SpaceMember2.Role.ADMIN,
3203
3222
  profile: signingContext.profile,
3204
- genesisFeedKey: (_a = space.controlFeedKey) != null ? _a : failUndefined2()
3223
+ genesisFeedKey: space.controlFeedKey ?? failUndefined2()
3205
3224
  }
3206
3225
  }),
3207
3226
  await signingContext.credentialSigner.createCredential({
3208
- subject: (_b = space.controlFeedKey) != null ? _b : failUndefined2(),
3227
+ subject: space.controlFeedKey ?? failUndefined2(),
3209
3228
  assertion: {
3210
3229
  "@type": "dxos.halo.credentials.AdmittedFeed",
3211
3230
  spaceKey: space.key,
@@ -3215,7 +3234,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3215
3234
  }
3216
3235
  }),
3217
3236
  await signingContext.credentialSigner.createCredential({
3218
- subject: (_c = space.dataFeedKey) != null ? _c : failUndefined2(),
3237
+ subject: space.dataFeedKey ?? failUndefined2(),
3219
3238
  assertion: {
3220
3239
  "@type": "dxos.halo.credentials.AdmittedFeed",
3221
3240
  spaceKey: space.key,
@@ -3225,12 +3244,12 @@ var spaceGenesis = async (keyring, signingContext, space) => {
3225
3244
  }
3226
3245
  }),
3227
3246
  await signingContext.credentialSigner.createCredential({
3228
- subject: (_d = space.key) != null ? _d : failUndefined2(),
3247
+ subject: space.key ?? failUndefined2(),
3229
3248
  assertion: {
3230
3249
  "@type": "dxos.halo.credentials.Epoch",
3231
3250
  number: 0,
3232
3251
  previousId: void 0,
3233
- timeframe: new Timeframe2(),
3252
+ timeframe: new Timeframe3(),
3234
3253
  snapshotCid: void 0
3235
3254
  }
3236
3255
  })
@@ -3490,7 +3509,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3490
3509
  onAuthFailure: () => {
3491
3510
  log11.warn("auth failure", void 0, {
3492
3511
  F: __dxlog_file13,
3493
- L: 213,
3512
+ L: 217,
3494
3513
  S: this,
3495
3514
  C: (f, a) => f(...a)
3496
3515
  });
@@ -3514,7 +3533,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3514
3533
  space: space.key
3515
3534
  }, {
3516
3535
  F: __dxlog_file13,
3517
- L: 231,
3536
+ L: 235,
3518
3537
  S: this,
3519
3538
  C: (f, a) => f(...a)
3520
3539
  });
@@ -3526,7 +3545,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3526
3545
  open: this._isOpen
3527
3546
  }, {
3528
3547
  F: __dxlog_file13,
3529
- L: 238,
3548
+ L: 242,
3530
3549
  S: this,
3531
3550
  C: (f, a) => f(...a)
3532
3551
  });
@@ -3539,7 +3558,7 @@ var DataSpaceManager = class DataSpaceManager2 {
3539
3558
  space: space.key
3540
3559
  }, {
3541
3560
  F: __dxlog_file13,
3542
- L: 244,
3561
+ L: 248,
3543
3562
  S: this,
3544
3563
  C: (f, a) => f(...a)
3545
3564
  });
@@ -3604,9 +3623,8 @@ var SpacesServiceImpl = class {
3604
3623
  return this._serializeSpace(space);
3605
3624
  }
3606
3625
  async updateSpace({ spaceKey, state }) {
3607
- var _a;
3608
3626
  const dataSpaceManager = await this._getDataSpaceManager();
3609
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3627
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3610
3628
  if (state) {
3611
3629
  switch (state) {
3612
3630
  case SpaceState3.ACTIVE:
@@ -3670,17 +3688,15 @@ var SpacesServiceImpl = class {
3670
3688
  });
3671
3689
  }
3672
3690
  async postMessage({ spaceKey, channel, message }) {
3673
- var _a;
3674
3691
  const dataSpaceManager = await this._getDataSpaceManager();
3675
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3692
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3676
3693
  await space.postMessage(getChannelId(channel), message);
3677
3694
  }
3678
3695
  subscribeMessages({ spaceKey, channel }) {
3679
3696
  return new Stream10(({ ctx, next }) => {
3680
3697
  scheduleTask5(ctx, async () => {
3681
- var _a;
3682
3698
  const dataSpaceManager = await this._getDataSpaceManager();
3683
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3699
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3684
3700
  const handle = space.listen(getChannelId(channel), (message) => {
3685
3701
  next(message);
3686
3702
  });
@@ -3690,8 +3706,7 @@ var SpacesServiceImpl = class {
3690
3706
  }
3691
3707
  queryCredentials({ spaceKey }) {
3692
3708
  return new Stream10(({ ctx, next }) => {
3693
- var _a;
3694
- 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));
3695
3710
  const processor = {
3696
3711
  processCredential: async (credential) => {
3697
3712
  next(credential);
@@ -3702,9 +3717,8 @@ var SpacesServiceImpl = class {
3702
3717
  });
3703
3718
  }
3704
3719
  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 : []) {
3720
+ const space = this._spaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3721
+ for (const credential of credentials ?? []) {
3708
3722
  await space.controlPipeline.writer.write({
3709
3723
  credential: {
3710
3724
  credential
@@ -3713,13 +3727,11 @@ var SpacesServiceImpl = class {
3713
3727
  }
3714
3728
  }
3715
3729
  async createEpoch({ spaceKey }) {
3716
- var _a;
3717
3730
  const dataSpaceManager = await this._getDataSpaceManager();
3718
- const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : raise2(new SpaceNotFoundError(spaceKey));
3731
+ const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
3719
3732
  await space.createEpoch();
3720
3733
  }
3721
3734
  _serializeSpace(space) {
3722
- var _a, _b, _c, _d, _e, _f, _g;
3723
3735
  return {
3724
3736
  spaceKey: space.key,
3725
3737
  state: space.state,
@@ -3731,16 +3743,15 @@ var SpacesServiceImpl = class {
3731
3743
  currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
3732
3744
  targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
3733
3745
  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
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
3739
3751
  },
3740
3752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3741
- var _a2, _b2, _c2;
3742
3753
  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);
3754
+ const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3744
3755
  if (isMe) {
3745
3756
  peers.push(space.presence.getLocalState());
3746
3757
  }
@@ -3748,14 +3759,14 @@ var SpacesServiceImpl = class {
3748
3759
  identity: {
3749
3760
  identityKey: member.key,
3750
3761
  profile: {
3751
- 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)
3752
3763
  }
3753
3764
  },
3754
3765
  presence: isMe || peers.length > 0 ? SpaceMember3.PresenceState.ONLINE : SpaceMember3.PresenceState.OFFLINE,
3755
3766
  peerStates: peers
3756
3767
  };
3757
3768
  }),
3758
- creator: (_g = space.inner.spaceState.creator) == null ? void 0 : _g.key,
3769
+ creator: space.inner.spaceState.creator?.key,
3759
3770
  cache: space.cache,
3760
3771
  metrics: space.metrics
3761
3772
  };
@@ -3778,6 +3789,7 @@ import { STORAGE_VERSION as STORAGE_VERSION2, trace as trace6 } from "@dxos/prot
3778
3789
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3779
3790
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
3780
3791
  import { trace as Trace2 } from "@dxos/tracing";
3792
+ import { safeInstanceof } from "@dxos/util";
3781
3793
  function _ts_decorate5(decorators, target, key, desc) {
3782
3794
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3783
3795
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3809,7 +3821,8 @@ var ServiceContext = class ServiceContext2 {
3809
3821
  root: storage.createDirectory("feeds"),
3810
3822
  signer: this.keyring,
3811
3823
  hypercore: {
3812
- valueEncoding
3824
+ valueEncoding,
3825
+ stats: true
3813
3826
  }
3814
3827
  })
3815
3828
  });
@@ -3823,16 +3836,13 @@ var ServiceContext = class ServiceContext2 {
3823
3836
  });
3824
3837
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3825
3838
  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)));
3839
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined3(), this._acceptIdentity.bind(this)));
3830
3840
  }
3831
3841
  async open(ctx) {
3832
3842
  await this._checkStorageVersion();
3833
3843
  log13("opening...", void 0, {
3834
3844
  F: __dxlog_file15,
3835
- L: 131,
3845
+ L: 135,
3836
3846
  S: this,
3837
3847
  C: (f, a) => f(...a)
3838
3848
  });
@@ -3840,7 +3850,7 @@ var ServiceContext = class ServiceContext2 {
3840
3850
  id: this._instanceId
3841
3851
  }), {
3842
3852
  F: __dxlog_file15,
3843
- L: 132,
3853
+ L: 136,
3844
3854
  S: this,
3845
3855
  C: (f, a) => f(...a)
3846
3856
  });
@@ -3855,29 +3865,28 @@ var ServiceContext = class ServiceContext2 {
3855
3865
  id: this._instanceId
3856
3866
  }), {
3857
3867
  F: __dxlog_file15,
3858
- L: 140,
3868
+ L: 144,
3859
3869
  S: this,
3860
3870
  C: (f, a) => f(...a)
3861
3871
  });
3862
3872
  log13("opened", void 0, {
3863
3873
  F: __dxlog_file15,
3864
- L: 141,
3874
+ L: 145,
3865
3875
  S: this,
3866
3876
  C: (f, a) => f(...a)
3867
3877
  });
3868
3878
  }
3869
3879
  async close() {
3870
- var _a;
3871
3880
  log13("closing...", void 0, {
3872
3881
  F: __dxlog_file15,
3873
- L: 145,
3882
+ L: 149,
3874
3883
  S: this,
3875
3884
  C: (f, a) => f(...a)
3876
3885
  });
3877
3886
  if (this._deviceSpaceSync && this.identityManager.identity) {
3878
3887
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3879
3888
  }
3880
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3889
+ await this.dataSpaceManager?.close();
3881
3890
  await this.identityManager.close();
3882
3891
  await this.spaceManager.close();
3883
3892
  await this.feedStore.close();
@@ -3886,7 +3895,7 @@ var ServiceContext = class ServiceContext2 {
3886
3895
  this.dataServiceSubscriptions.clear();
3887
3896
  log13("closed", void 0, {
3888
3897
  F: __dxlog_file15,
3889
- L: 156,
3898
+ L: 160,
3890
3899
  S: this,
3891
3900
  C: (f, a) => f(...a)
3892
3901
  });
@@ -3900,7 +3909,7 @@ var ServiceContext = class ServiceContext2 {
3900
3909
  const factory = this._handlerFactories.get(invitation.kind);
3901
3910
  invariant12(factory, `Unknown invitation kind: ${invitation.kind}`, {
3902
3911
  F: __dxlog_file15,
3903
- L: 168,
3912
+ L: 171,
3904
3913
  S: this,
3905
3914
  A: [
3906
3915
  "factory",
@@ -3922,14 +3931,13 @@ var ServiceContext = class ServiceContext2 {
3922
3931
  }
3923
3932
  // Called when identity is created.
3924
3933
  async _initialize(ctx) {
3925
- var _a;
3926
3934
  log13("initializing spaces...", void 0, {
3927
3935
  F: __dxlog_file15,
3928
- L: 190,
3936
+ L: 192,
3929
3937
  S: this,
3930
3938
  C: (f, a) => f(...a)
3931
3939
  });
3932
- const identity = (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3940
+ const identity = this.identityManager.identity ?? failUndefined3();
3933
3941
  const signingContext = {
3934
3942
  credentialSigner: identity.getIdentityCredentialSigner(),
3935
3943
  identityKey: identity.identityKey,
@@ -3948,7 +3956,7 @@ var ServiceContext = class ServiceContext2 {
3948
3956
  this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
3949
3957
  invariant12(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
3950
3958
  F: __dxlog_file15,
3951
- L: 213,
3959
+ L: 215,
3952
3960
  S: this,
3953
3961
  A: [
3954
3962
  "this.dataSpaceManager",
@@ -3972,7 +3980,7 @@ var ServiceContext = class ServiceContext2 {
3972
3980
  details: assertion
3973
3981
  }, {
3974
3982
  F: __dxlog_file15,
3975
- L: 229,
3983
+ L: 231,
3976
3984
  S: this,
3977
3985
  C: (f, a) => f(...a)
3978
3986
  });
@@ -3983,7 +3991,7 @@ var ServiceContext = class ServiceContext2 {
3983
3991
  details: assertion
3984
3992
  }, {
3985
3993
  F: __dxlog_file15,
3986
- L: 233,
3994
+ L: 235,
3987
3995
  S: this,
3988
3996
  C: (f, a) => f(...a)
3989
3997
  });
@@ -3994,7 +4002,7 @@ var ServiceContext = class ServiceContext2 {
3994
4002
  details: assertion
3995
4003
  }, {
3996
4004
  F: __dxlog_file15,
3997
- L: 238,
4005
+ L: 240,
3998
4006
  S: this,
3999
4007
  C: (f, a) => f(...a)
4000
4008
  });
@@ -4005,7 +4013,7 @@ var ServiceContext = class ServiceContext2 {
4005
4013
  } catch (err) {
4006
4014
  log13.catch(err, void 0, {
4007
4015
  F: __dxlog_file15,
4008
- L: 244,
4016
+ L: 246,
4009
4017
  S: this,
4010
4018
  C: (f, a) => f(...a)
4011
4019
  });
@@ -4022,6 +4030,7 @@ _ts_decorate5([
4022
4030
  Trace2.span()
4023
4031
  ], ServiceContext.prototype, "_initialize", null);
4024
4032
  ServiceContext = _ts_decorate5([
4033
+ safeInstanceof("dxos.client-services.ServiceContext"),
4025
4034
  Trace2.resource()
4026
4035
  ], ServiceContext);
4027
4036
 
@@ -4074,7 +4083,7 @@ var Lock = class {
4074
4083
  S: this,
4075
4084
  C: (f, a) => f(...a)
4076
4085
  });
4077
- } catch (e) {
4086
+ } catch {
4078
4087
  log14("stealing lock...", void 0, {
4079
4088
  F: __dxlog_file16,
4080
4089
  L: 46,
@@ -4111,8 +4120,7 @@ var Lock = class {
4111
4120
  void navigator.locks.request(this._lockKey, {
4112
4121
  steal
4113
4122
  }, async () => {
4114
- var _a, _b;
4115
- await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
4123
+ await this._onAcquire?.();
4116
4124
  acquired.wake();
4117
4125
  this._releaseTrigger = new Trigger6();
4118
4126
  await this._releaseTrigger.wait();
@@ -4122,7 +4130,7 @@ var Lock = class {
4122
4130
  S: this,
4123
4131
  C: (f, a) => f(...a)
4124
4132
  });
4125
- await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
4133
+ await this._onRelease?.();
4126
4134
  log14("released lock", void 0, {
4127
4135
  F: __dxlog_file16,
4128
4136
  L: 74,
@@ -4130,8 +4138,7 @@ var Lock = class {
4130
4138
  C: (f, a) => f(...a)
4131
4139
  });
4132
4140
  }).catch(async () => {
4133
- var _a;
4134
- await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
4141
+ await this._onRelease?.();
4135
4142
  });
4136
4143
  await acquired.wait();
4137
4144
  log14("recieved lock", {
@@ -4159,7 +4166,7 @@ import { createStorage, StorageType } from "@dxos/random-access-storage";
4159
4166
  import { isNode } from "@dxos/util";
4160
4167
  var StorageDriver = Runtime.Client.Storage.StorageDriver;
4161
4168
  var createStorageObjects = (config) => {
4162
- 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 ?? {};
4163
4170
  if (persistent && storageType === StorageDriver.RAM) {
4164
4171
  throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
4165
4172
  }
@@ -4255,21 +4262,17 @@ var DevicesServiceImpl = class {
4255
4262
  queryDevices() {
4256
4263
  return new Stream11(({ next }) => {
4257
4264
  const update = () => {
4258
- var _a;
4259
- const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
4265
+ const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
4260
4266
  if (!deviceKeys) {
4261
4267
  next({
4262
4268
  devices: []
4263
4269
  });
4264
4270
  } else {
4265
4271
  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
- })
4272
+ devices: Array.from(deviceKeys.values()).map((key) => ({
4273
+ deviceKey: key,
4274
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? DeviceKind.CURRENT : DeviceKind.TRUSTED
4275
+ }))
4273
4276
  });
4274
4277
  }
4275
4278
  };
@@ -4297,7 +4300,7 @@ import { jsonify, numericalValues, tracer } from "@dxos/util";
4297
4300
  var LoggingServiceImpl = class {
4298
4301
  constructor() {
4299
4302
  this._logs = new Event7();
4300
- this._started = new Date();
4303
+ this._started = /* @__PURE__ */ new Date();
4301
4304
  this._logProcessor = (_config, entry2) => {
4302
4305
  this._logs.emit(entry2);
4303
4306
  };
@@ -4327,8 +4330,7 @@ var LoggingServiceImpl = class {
4327
4330
  */
4328
4331
  queryMetrics({ interval = 5e3 }) {
4329
4332
  const getNumericalValues = (key) => {
4330
- var _a;
4331
- const events = (_a = tracer.get(key)) != null ? _a : [];
4333
+ const events = tracer.get(key) ?? [];
4332
4334
  return {
4333
4335
  key,
4334
4336
  stats: numericalValues(events, "duration")
@@ -4337,14 +4339,14 @@ var LoggingServiceImpl = class {
4337
4339
  return new Stream12(({ next }) => {
4338
4340
  const update = () => {
4339
4341
  const metrics = {
4340
- timestamp: new Date(),
4342
+ timestamp: /* @__PURE__ */ new Date(),
4341
4343
  values: [
4342
4344
  getNumericalValues("dxos.echo.pipeline.control"),
4343
4345
  getNumericalValues("dxos.echo.pipeline.data")
4344
4346
  ].filter(Boolean)
4345
4347
  };
4346
4348
  next({
4347
- timestamp: new Date(),
4349
+ timestamp: /* @__PURE__ */ new Date(),
4348
4350
  metrics
4349
4351
  });
4350
4352
  };
@@ -4358,11 +4360,10 @@ var LoggingServiceImpl = class {
4358
4360
  queryLogs(request) {
4359
4361
  return new Stream12(({ ctx, next }) => {
4360
4362
  const handler = (entry2) => {
4361
- var _a, _b, _c, _d, _e;
4362
4363
  if (LOG_PROCESSING > 0) {
4363
4364
  return;
4364
4365
  }
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"))) {
4366
+ if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
4366
4367
  return;
4367
4368
  }
4368
4369
  if (!shouldLog(entry2, request)) {
@@ -4371,11 +4372,11 @@ var LoggingServiceImpl = class {
4371
4372
  const record = {
4372
4373
  ...entry2,
4373
4374
  context: jsonify(getContextFromEntry(entry2)),
4374
- timestamp: new Date(),
4375
+ timestamp: /* @__PURE__ */ new Date(),
4375
4376
  meta: {
4376
4377
  // 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
4378
+ file: entry2.meta?.F ?? "",
4379
+ line: entry2.meta?.L ?? 0
4379
4380
  }
4380
4381
  };
4381
4382
  try {
@@ -4398,15 +4399,11 @@ var matchFilter = (filter, level, path, options) => {
4398
4399
  }
4399
4400
  };
4400
4401
  var shouldLog = (entry2, request) => {
4401
- var _a;
4402
- const options = (_a = request.options) != null ? _a : QueryLogsRequest.MatchingOptions.INCLUSIVE;
4402
+ const options = request.options ?? QueryLogsRequest.MatchingOptions.INCLUSIVE;
4403
4403
  if (request.filters === void 0) {
4404
4404
  return options === QueryLogsRequest.MatchingOptions.INCLUSIVE;
4405
4405
  } 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
- });
4406
+ return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
4410
4407
  }
4411
4408
  };
4412
4409
  var LOG_PROCESSING = 0;
@@ -4457,8 +4454,7 @@ var SystemServiceImpl = class {
4457
4454
  this._onReset = onReset;
4458
4455
  }
4459
4456
  async getConfig() {
4460
- var _a, _b;
4461
- return (_b = (_a = this._config) == null ? void 0 : _a.values) != null ? _b : {};
4457
+ return this._config?.values ?? {};
4462
4458
  }
4463
4459
  /**
4464
4460
  * NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
@@ -4466,7 +4462,7 @@ var SystemServiceImpl = class {
4466
4462
  async getDiagnostics({ keys } = {}) {
4467
4463
  const diagnostics = await this._getDiagnostics();
4468
4464
  return {
4469
- timestamp: new Date(),
4465
+ timestamp: /* @__PURE__ */ new Date(),
4470
4466
  diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer({
4471
4467
  truncate: keys === GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
4472
4468
  humanize: keys === GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
@@ -4557,11 +4553,10 @@ var ClientServicesHost = class ClientServicesHost2 {
4557
4553
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
4558
4554
  },
4559
4555
  onUpdateStatus: async (status) => {
4560
- var _a, _b;
4561
4556
  if (!this.isOpen && status === SystemStatus.ACTIVE) {
4562
- await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
4557
+ await this._resourceLock?.acquire();
4563
4558
  } else if (this.isOpen && status === SystemStatus.INACTIVE) {
4564
- await ((_b = this._resourceLock) == null ? void 0 : _b.release());
4559
+ await this._resourceLock?.release();
4565
4560
  }
4566
4561
  },
4567
4562
  onReset: async () => {
@@ -4598,7 +4593,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4598
4593
  * Can only be called once.
4599
4594
  */
4600
4595
  initialize({ config, ...options }) {
4601
- var _a, _b, _c;
4602
4596
  invariant13(!this._open, "service host is open", {
4603
4597
  F: __dxlog_file17,
4604
4598
  L: 181,
@@ -4608,7 +4602,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4608
4602
  "'service host is open'"
4609
4603
  ]
4610
4604
  });
4611
- log16.info("initializing...", void 0, {
4605
+ log16("initializing...", void 0, {
4612
4606
  F: __dxlog_file17,
4613
4607
  L: 182,
4614
4608
  S: this,
@@ -4630,8 +4624,8 @@ var ClientServicesHost = class ClientServicesHost2 {
4630
4624
  }
4631
4625
  }
4632
4626
  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;
4627
+ iceServers: this._config?.get("runtime.services.ice")
4628
+ }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
4635
4629
  this._signalManager = signalManager;
4636
4630
  invariant13(!this._networkManager, "network manager already set", {
4637
4631
  F: __dxlog_file17,
@@ -4647,7 +4641,7 @@ var ClientServicesHost = class ClientServicesHost2 {
4647
4641
  transportFactory,
4648
4642
  signalManager
4649
4643
  });
4650
- log16.info("initialized", void 0, {
4644
+ log16("initialized", void 0, {
4651
4645
  F: __dxlog_file17,
4652
4646
  L: 208,
4653
4647
  S: this,
@@ -4655,7 +4649,6 @@ var ClientServicesHost = class ClientServicesHost2 {
4655
4649
  });
4656
4650
  }
4657
4651
  async open(ctx) {
4658
- var _a, _b, _c;
4659
4652
  if (this._open) {
4660
4653
  return;
4661
4654
  }
@@ -4705,20 +4698,20 @@ var ClientServicesHost = class ClientServicesHost2 {
4705
4698
  ]
4706
4699
  });
4707
4700
  this._opening = true;
4708
- log16.info("opening...", {
4709
- lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
4701
+ log16("opening...", {
4702
+ lockKey: this._resourceLock?.lockKey
4710
4703
  }, {
4711
4704
  F: __dxlog_file17,
4712
4705
  L: 227,
4713
4706
  S: this,
4714
4707
  C: (f, a) => f(...a)
4715
4708
  });
4716
- await ((_b = this._resourceLock) == null ? void 0 : _b.acquire());
4709
+ await this._resourceLock?.acquire();
4717
4710
  await this._loggingService.open();
4718
4711
  this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
4719
4712
  this._serviceRegistry.setServices({
4720
4713
  SystemService: this._systemService,
4721
- IdentityService: new IdentityServiceImpl(this._serviceContext),
4714
+ IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
4722
4715
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
4723
4716
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4724
4717
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
@@ -4740,12 +4733,12 @@ var ClientServicesHost = class ClientServicesHost2 {
4740
4733
  this._opening = false;
4741
4734
  this._open = true;
4742
4735
  this._statusUpdate.emit();
4743
- const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
4744
- log16.info("opened", {
4736
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4737
+ log16("opened", {
4745
4738
  deviceKey
4746
4739
  }, {
4747
4740
  F: __dxlog_file17,
4748
- L: 280,
4741
+ L: 284,
4749
4742
  S: this,
4750
4743
  C: (f, a) => f(...a)
4751
4744
  });
@@ -4753,22 +4746,21 @@ var ClientServicesHost = class ClientServicesHost2 {
4753
4746
  id: traceId
4754
4747
  }), {
4755
4748
  F: __dxlog_file17,
4756
- L: 281,
4749
+ L: 285,
4757
4750
  S: this,
4758
4751
  C: (f, a) => f(...a)
4759
4752
  });
4760
4753
  }
4761
4754
  async close() {
4762
- var _a;
4763
4755
  if (!this._open) {
4764
4756
  return;
4765
4757
  }
4766
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4767
- log16.info("closing...", {
4758
+ const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
4759
+ log16("closing...", {
4768
4760
  deviceKey
4769
4761
  }, {
4770
4762
  F: __dxlog_file17,
4771
- L: 292,
4763
+ L: 296,
4772
4764
  S: this,
4773
4765
  C: (f, a) => f(...a)
4774
4766
  });
@@ -4779,37 +4771,36 @@ var ClientServicesHost = class ClientServicesHost2 {
4779
4771
  await this._serviceContext.close();
4780
4772
  this._open = false;
4781
4773
  this._statusUpdate.emit();
4782
- log16.info("closed", {
4774
+ log16("closed", {
4783
4775
  deviceKey
4784
4776
  }, {
4785
4777
  F: __dxlog_file17,
4786
- L: 298,
4778
+ L: 302,
4787
4779
  S: this,
4788
4780
  C: (f, a) => f(...a)
4789
4781
  });
4790
4782
  }
4791
4783
  async reset() {
4792
- var _a, _b, _c;
4793
4784
  const traceId = PublicKey10.random().toHex();
4794
4785
  log16.trace("dxos.sdk.client-services-host.reset", trace7.begin({
4795
4786
  id: traceId
4796
4787
  }), {
4797
4788
  F: __dxlog_file17,
4798
- L: 303,
4789
+ L: 307,
4799
4790
  S: this,
4800
4791
  C: (f, a) => f(...a)
4801
4792
  });
4802
4793
  log16("resetting...", void 0, {
4803
4794
  F: __dxlog_file17,
4804
- L: 305,
4795
+ L: 309,
4805
4796
  S: this,
4806
4797
  C: (f, a) => f(...a)
4807
4798
  });
4808
- await ((_a = this._serviceContext) == null ? void 0 : _a.close());
4799
+ await this._serviceContext?.close();
4809
4800
  await this._storage.reset();
4810
4801
  log16("reset", void 0, {
4811
4802
  F: __dxlog_file17,
4812
- L: 308,
4803
+ L: 312,
4813
4804
  S: this,
4814
4805
  C: (f, a) => f(...a)
4815
4806
  });
@@ -4817,11 +4808,11 @@ var ClientServicesHost = class ClientServicesHost2 {
4817
4808
  id: traceId
4818
4809
  }), {
4819
4810
  F: __dxlog_file17,
4820
- L: 309,
4811
+ L: 313,
4821
4812
  S: this,
4822
4813
  C: (f, a) => f(...a)
4823
4814
  });
4824
- await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
4815
+ await this._callbacks?.onReset?.();
4825
4816
  }
4826
4817
  };
4827
4818
  _ts_decorate7([
@@ -4875,4 +4866,4 @@ export {
4875
4866
  createDefaultModelFactory,
4876
4867
  ClientServicesHost
4877
4868
  };
4878
- //# sourceMappingURL=chunk-P6TNW4K5.mjs.map
4869
+ //# sourceMappingURL=chunk-CXJ3H4F5.mjs.map