@dxos/react-client 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264 → 0.14.0

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 (103) hide show
  1. package/CHANGELOG.md +197 -14
  2. package/dist/lib/chunk-ClientProvider.mjs +23 -20
  3. package/dist/lib/chunk-ClientProvider.mjs.map +1 -1
  4. package/dist/lib/chunk-useClient.mjs.map +1 -1
  5. package/dist/lib/devtools.mjs.map +1 -1
  6. package/dist/lib/echo.mjs +23 -8
  7. package/dist/lib/echo.mjs.map +1 -1
  8. package/dist/lib/halo.mjs +11 -2
  9. package/dist/lib/halo.mjs.map +1 -1
  10. package/dist/lib/index.mjs +10 -2
  11. package/dist/lib/index.mjs.map +1 -1
  12. package/dist/lib/invitations.mjs +22 -21
  13. package/dist/lib/invitations.mjs.map +1 -1
  14. package/dist/lib/mesh.mjs.map +1 -1
  15. package/dist/lib/testing.mjs +13 -10
  16. package/dist/lib/testing.mjs.map +1 -1
  17. package/dist/types/src/client/ClientProvider.d.ts +1 -1
  18. package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
  19. package/dist/types/src/client/index.d.ts +9 -9
  20. package/dist/types/src/client/index.d.ts.map +1 -1
  21. package/dist/types/src/client/useEdgeServiceEndpoint.d.ts +6 -1
  22. package/dist/types/src/client/useEdgeServiceEndpoint.d.ts.map +1 -1
  23. package/dist/types/src/devtools/index.d.ts +2 -2
  24. package/dist/types/src/devtools/index.d.ts.map +1 -1
  25. package/dist/types/src/echo/ECHO.stories.d.ts +15 -0
  26. package/dist/types/src/echo/ECHO.stories.d.ts.map +1 -0
  27. package/dist/types/src/echo/index.d.ts +9 -9
  28. package/dist/types/src/echo/index.d.ts.map +1 -1
  29. package/dist/types/src/echo/useFeedSyncState.d.ts +1 -1
  30. package/dist/types/src/echo/useFeedSyncState.d.ts.map +1 -1
  31. package/dist/types/src/echo/useFeedSyncState.test.d.ts +2 -0
  32. package/dist/types/src/echo/useFeedSyncState.test.d.ts.map +1 -0
  33. package/dist/types/src/echo/useMembers.d.ts.map +1 -1
  34. package/dist/types/src/echo/useSpaceInvitations.d.ts +2 -2
  35. package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
  36. package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
  37. package/dist/types/src/halo/index.d.ts +8 -7
  38. package/dist/types/src/halo/index.d.ts.map +1 -1
  39. package/dist/types/src/halo/useHaloInvitations.d.ts +2 -2
  40. package/dist/types/src/halo/useHaloInvitations.d.ts.map +1 -1
  41. package/dist/types/src/halo/useInboxMessages.d.ts +6 -0
  42. package/dist/types/src/halo/useInboxMessages.d.ts.map +1 -0
  43. package/dist/types/src/index.d.ts +1 -1
  44. package/dist/types/src/index.d.ts.map +1 -1
  45. package/dist/types/src/invitations/index.d.ts +2 -2
  46. package/dist/types/src/invitations/index.d.ts.map +1 -1
  47. package/dist/types/src/invitations/useInvitationStatus.d.ts +13 -13
  48. package/dist/types/src/invitations/useInvitationStatus.d.ts.map +1 -1
  49. package/dist/types/src/mesh/index.d.ts +1 -1
  50. package/dist/types/src/mesh/index.d.ts.map +1 -1
  51. package/dist/types/src/testing/ClientRepeater.d.ts +1 -1
  52. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  53. package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -1
  54. package/dist/types/src/testing/index.d.ts +3 -3
  55. package/dist/types/src/testing/index.d.ts.map +1 -1
  56. package/dist/types/src/testing/withClientProvider.d.ts +14 -2
  57. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
  58. package/dist/types/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +26 -23
  60. package/src/client/AgentHostingProvider.tsx +2 -2
  61. package/src/client/ClientProvider.test.tsx +108 -11
  62. package/src/client/ClientProvider.tsx +73 -64
  63. package/src/client/index.ts +9 -9
  64. package/src/client/useClient.ts +1 -1
  65. package/src/client/useConfig.test.tsx +5 -7
  66. package/src/client/useConfig.ts +1 -1
  67. package/src/client/useEdgeServiceEndpoint.ts +13 -4
  68. package/src/client/useShell.ts +1 -1
  69. package/src/client/useStatus.ts +1 -1
  70. package/src/devtools/index.ts +2 -2
  71. package/src/devtools/useDevtools.ts +1 -1
  72. package/src/echo/ECHO.stories.tsx +134 -0
  73. package/src/echo/index.ts +9 -9
  74. package/src/echo/useFeedSyncState.test.tsx +54 -0
  75. package/src/echo/useFeedSyncState.ts +38 -7
  76. package/src/echo/useMembers.ts +3 -3
  77. package/src/echo/useRegistry.ts +1 -1
  78. package/src/echo/useSpaceInvitations.ts +2 -2
  79. package/src/echo/useSpaceProperties.ts +1 -1
  80. package/src/echo/useSpaces.test.tsx +2 -2
  81. package/src/echo/useSpaces.ts +1 -1
  82. package/src/echo/useSyncState.ts +1 -1
  83. package/src/halo/Passkey.stories.tsx +33 -23
  84. package/src/halo/index.ts +9 -7
  85. package/src/halo/useContacts.ts +1 -1
  86. package/src/halo/useCredentials.ts +1 -1
  87. package/src/halo/useDevices.test.tsx +2 -2
  88. package/src/halo/useDevices.ts +1 -1
  89. package/src/halo/useHaloInvitations.ts +2 -2
  90. package/src/halo/useIdentity.ts +1 -1
  91. package/src/halo/useInboxMessages.ts +16 -0
  92. package/src/index.ts +1 -1
  93. package/src/invitations/index.ts +7 -2
  94. package/src/invitations/useInvitationStatus.ts +42 -39
  95. package/src/mesh/index.ts +1 -1
  96. package/src/mesh/useNetworkStatus.ts +1 -1
  97. package/src/testing/ClientRepeater.stories.tsx +9 -8
  98. package/src/testing/ClientRepeater.tsx +2 -2
  99. package/src/testing/index.ts +3 -3
  100. package/src/testing/util.tsx +1 -1
  101. package/src/testing/withClientProvider.stories.tsx +4 -4
  102. package/src/testing/withClientProvider.tsx +31 -12
  103. package/tsconfig.json +6 -0
package/CHANGELOG.md CHANGED
@@ -1,82 +1,265 @@
1
1
  # @dxos/react-client
2
2
 
3
- ## 0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
3
+ ## 0.14.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - Updated dependencies [1eed6b1]
8
+ - Updated dependencies [6847fe2]
9
+ - Updated dependencies [eb5d14d]
10
+ - @dxos/echo@0.14.0
11
+ - @dxos/client@0.14.0
12
+ - @dxos/echo-react@0.14.0
13
+ - @dxos/echo-protocol@0.14.0
14
+ - @dxos/config@0.14.0
15
+ - @dxos/async@0.14.0
16
+ - @dxos/context@0.14.0
17
+ - @dxos/debug@0.14.0
18
+ - @dxos/keys@0.14.0
19
+ - @dxos/log@0.14.0
20
+ - @dxos/node-std@0.14.0
21
+ - @dxos/util@0.14.0
22
+ - @dxos/react-hooks@0.14.0
23
+
24
+ ## 0.13.0
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [162fd6d]
29
+ - Updated dependencies [aad3e41]
30
+ - Updated dependencies [bb2b672]
31
+ - Updated dependencies [cb1e218]
32
+ - Updated dependencies [1ef899b]
33
+ - Updated dependencies [32f32a0]
34
+ - Updated dependencies [469e7f7]
35
+ - Updated dependencies [665261a]
36
+ - Updated dependencies [2e96a73]
37
+ - Updated dependencies [945092e]
38
+ - Updated dependencies [c531b05]
39
+ - Updated dependencies [3672aff]
40
+ - Updated dependencies [2f95d25]
41
+ - Updated dependencies [c7cc480]
42
+ - Updated dependencies [8980a93]
43
+ - Updated dependencies [e99ee70]
44
+ - Updated dependencies [161f994]
45
+ - Updated dependencies [1894fc1]
46
+ - Updated dependencies [246ee3c]
47
+ - Updated dependencies [8ebe8d6]
48
+ - Updated dependencies [7715216]
49
+ - Updated dependencies [1737cad]
50
+ - Updated dependencies [6a7bed4]
51
+ - Updated dependencies [3022878]
52
+ - Updated dependencies [c2a300a]
53
+ - Updated dependencies [17008f0]
54
+ - Updated dependencies [4f8e566]
55
+ - Updated dependencies [a449958]
56
+ - @dxos/echo@0.13.0
57
+ - @dxos/util@0.13.0
58
+ - @dxos/client@0.13.0
59
+ - @dxos/echo-react@0.13.0
60
+ - @dxos/async@0.13.0
61
+ - @dxos/context@0.13.0
62
+ - @dxos/log@0.13.0
63
+ - @dxos/echo-protocol@0.13.0
64
+ - @dxos/config@0.13.0
65
+ - @dxos/react-hooks@0.13.0
66
+ - @dxos/debug@0.13.0
67
+ - @dxos/keys@0.13.0
68
+ - @dxos/node-std@0.13.0
69
+
70
+ ## 0.12.0
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [a92ea18]
75
+ - Updated dependencies [0c6c186]
7
76
  - Updated dependencies [86d1482]
77
+ - Updated dependencies [af1c007]
78
+ - Updated dependencies [12461e1]
79
+ - Updated dependencies [4862c8e]
80
+ - Updated dependencies [106d38a]
81
+ - Updated dependencies [9049c30]
82
+ - Updated dependencies [6186edc]
83
+ - Updated dependencies [e3ceced]
8
84
  - Updated dependencies [e2eecf2]
9
85
  - Updated dependencies [2800d03]
86
+ - Updated dependencies [4ececc6]
87
+ - Updated dependencies [c95def4]
88
+ - Updated dependencies [3c7b013]
89
+ - Updated dependencies [b1dc20c]
90
+ - Updated dependencies [ac71815]
91
+ - Updated dependencies [7c87626]
92
+ - Updated dependencies [f82c78f]
93
+ - Updated dependencies [3b78bb6]
10
94
  - Updated dependencies [22bea85]
95
+ - Updated dependencies [a069511]
96
+ - Updated dependencies [5df602e]
97
+ - Updated dependencies [63fc847]
98
+ - Updated dependencies [0fe00c5]
11
99
  - Updated dependencies [069e8ed]
12
100
  - Updated dependencies [75971ad]
13
101
  - Updated dependencies [3958355]
14
102
  - Updated dependencies [b4c7782]
103
+ - Updated dependencies [fd23a8b]
104
+ - Updated dependencies [577b434]
105
+ - Updated dependencies [7d04444]
106
+ - Updated dependencies [6ef35a6]
107
+ - Updated dependencies [d17d75a]
15
108
  - Updated dependencies [ea11703]
109
+ - Updated dependencies [c01fef6]
110
+ - Updated dependencies [b2caee6]
111
+ - Updated dependencies [9baf25f]
112
+ - Updated dependencies [34f7d92]
113
+ - Updated dependencies [dcf911b]
16
114
  - Updated dependencies [881f900]
17
115
  - Updated dependencies [da37a13]
18
116
  - Updated dependencies [0a01ff7]
19
117
  - Updated dependencies [1c995c4]
118
+ - Updated dependencies [6f4a887]
119
+ - Updated dependencies [1aabb03]
120
+ - Updated dependencies [d0beedc]
121
+ - Updated dependencies [731b264]
20
122
  - Updated dependencies [a69d861]
21
123
  - Updated dependencies [ba08e65]
124
+ - Updated dependencies [07565c8]
22
125
  - Updated dependencies [5fcd238]
23
126
  - Updated dependencies [5e8878c]
127
+ - Updated dependencies [6409948]
128
+ - Updated dependencies [792c756]
129
+ - Updated dependencies [497caab]
130
+ - Updated dependencies [35d6e86]
131
+ - Updated dependencies [1cf6347]
132
+ - Updated dependencies [0cde959]
24
133
  - Updated dependencies [e094f74]
134
+ - Updated dependencies [9ab38fa]
135
+ - Updated dependencies [b3673ee]
136
+ - Updated dependencies [915db6a]
25
137
  - Updated dependencies [6c6987e]
26
138
  - Updated dependencies [3e02201]
139
+ - Updated dependencies [ed43a8d]
140
+ - Updated dependencies [6c25ed3]
27
141
  - Updated dependencies [a3b6ef0]
142
+ - Updated dependencies [4c55b5d]
28
143
  - Updated dependencies [b02fe16]
144
+ - Updated dependencies [252ca39]
145
+ - Updated dependencies [8fb29b3]
29
146
  - Updated dependencies [c439ba0]
30
147
  - Updated dependencies [6af130f]
148
+ - Updated dependencies [2c442f9]
149
+ - Updated dependencies [0264069]
150
+ - Updated dependencies [2922d36]
31
151
  - Updated dependencies [d62a947]
152
+ - Updated dependencies [872f391]
153
+ - Updated dependencies [51820a1]
154
+ - Updated dependencies [9ae0e5f]
32
155
  - Updated dependencies [7d000b9]
156
+ - Updated dependencies [66e9264]
157
+ - Updated dependencies [84362af]
158
+ - Updated dependencies [76d6fca]
33
159
  - Updated dependencies [4c107a2]
34
160
  - Updated dependencies [b9d72bb]
161
+ - Updated dependencies [eeff74c]
162
+ - Updated dependencies [967b130]
163
+ - Updated dependencies [75d9c7c]
35
164
  - Updated dependencies [3e9a10f]
36
165
  - Updated dependencies [8ea2bf9]
37
166
  - Updated dependencies [48ea128]
38
167
  - Updated dependencies [8ca2ac7]
168
+ - Updated dependencies [72f7584]
169
+ - Updated dependencies [e94ed89]
170
+ - Updated dependencies [0132aab]
171
+ - Updated dependencies [a74e9b0]
39
172
  - Updated dependencies [47c8d7e]
40
173
  - Updated dependencies [10b1239]
174
+ - Updated dependencies [851791f]
175
+ - Updated dependencies [608a172]
41
176
  - Updated dependencies [b600f72]
42
177
  - Updated dependencies [99e323d]
43
178
  - Updated dependencies [ea11703]
44
179
  - Updated dependencies [bcfe4c5]
180
+ - Updated dependencies [ce194c0]
181
+ - Updated dependencies [4aa6a33]
182
+ - Updated dependencies [9636ce1]
183
+ - Updated dependencies [0ac2e5f]
184
+ - Updated dependencies [9426389]
185
+ - Updated dependencies [2e5e188]
186
+ - Updated dependencies [ebb8f4a]
187
+ - Updated dependencies [9d2466a]
45
188
  - Updated dependencies [ca34a80]
189
+ - Updated dependencies [df22dec]
190
+ - Updated dependencies [a283607]
46
191
  - Updated dependencies [24fcadc]
192
+ - Updated dependencies [b00ee72]
47
193
  - Updated dependencies [4804da0]
48
194
  - Updated dependencies [63e500b]
195
+ - Updated dependencies [19f19a2]
196
+ - Updated dependencies [5959b41]
197
+ - Updated dependencies [2a41efd]
198
+ - Updated dependencies [139a3b0]
199
+ - Updated dependencies [142ba02]
200
+ - Updated dependencies [e1ee9dd]
201
+ - Updated dependencies [a5dfa5e]
202
+ - Updated dependencies [f3c02b3]
49
203
  - Updated dependencies [256f286]
204
+ - Updated dependencies [61becad]
205
+ - Updated dependencies [690dcaa]
206
+ - Updated dependencies [c4188a6]
50
207
  - Updated dependencies [5b504b4]
51
208
  - Updated dependencies [d7b0a3b]
209
+ - Updated dependencies [1482a3f]
210
+ - Updated dependencies [2513a52]
211
+ - Updated dependencies [17ed864]
212
+ - Updated dependencies [b125655]
213
+ - Updated dependencies [9996125]
52
214
  - Updated dependencies [f4c2702]
215
+ - Updated dependencies [2df0297]
216
+ - Updated dependencies [3e08678]
217
+ - Updated dependencies [7407d65]
53
218
  - Updated dependencies [318bbad]
219
+ - Updated dependencies [9a3f01e]
220
+ - Updated dependencies [dd039d2]
221
+ - Updated dependencies [adcad97]
54
222
  - Updated dependencies [f8bfba0]
55
223
  - Updated dependencies [ea11703]
224
+ - Updated dependencies [fa82aef]
225
+ - Updated dependencies [178a283]
226
+ - Updated dependencies [56276cd]
56
227
  - Updated dependencies [0280a6a]
57
228
  - Updated dependencies [18597fc]
229
+ - Updated dependencies [9205bd3]
230
+ - Updated dependencies [fce2060]
231
+ - Updated dependencies [bda45ac]
232
+ - Updated dependencies [5885380]
58
233
  - Updated dependencies [881f900]
234
+ - Updated dependencies [72b2984]
235
+ - Updated dependencies [693d1b4]
59
236
  - Updated dependencies [32353e6]
60
237
  - Updated dependencies [559acfa]
61
238
  - Updated dependencies [e8088ea]
239
+ - Updated dependencies [1a3de22]
62
240
  - Updated dependencies [5d816a6]
63
241
  - Updated dependencies [40b50c2]
64
242
  - Updated dependencies [85bdad2]
65
243
  - Updated dependencies [77d0026]
244
+ - Updated dependencies [4a10672]
245
+ - Updated dependencies [c209b42]
246
+ - Updated dependencies [4da1052]
247
+ - Updated dependencies [eda8b55]
66
248
  - Updated dependencies [cc11297]
67
- - @dxos/client@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
68
- - @dxos/echo@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
69
- - @dxos/config@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
70
- - @dxos/echo-protocol@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
71
- - @dxos/util@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
72
- - @dxos/react-hooks@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
73
- - @dxos/echo-react@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
74
- - @dxos/async@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
75
- - @dxos/context@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
76
- - @dxos/log@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
77
- - @dxos/debug@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
78
- - @dxos/keys@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
79
- - @dxos/node-std@0.12.0-next-73daef452f1464b62efdbca75fb0067c1066f264
249
+ - Updated dependencies [ff37699]
250
+ - @dxos/echo@0.12.0
251
+ - @dxos/client@0.12.0
252
+ - @dxos/echo-protocol@0.12.0
253
+ - @dxos/config@0.12.0
254
+ - @dxos/util@0.12.0
255
+ - @dxos/async@0.12.0
256
+ - @dxos/log@0.12.0
257
+ - @dxos/debug@0.12.0
258
+ - @dxos/context@0.12.0
259
+ - @dxos/react-hooks@0.12.0
260
+ - @dxos/node-std@0.12.0
261
+ - @dxos/echo-react@0.12.0
262
+ - @dxos/keys@0.12.0
80
263
 
81
264
  ## 0.11.1
82
265
 
@@ -31,34 +31,37 @@ var __dxlog_file = "/__w/dxos/dxos/packages/sdk/react-client/src/client/ClientPr
31
31
  * To be used with the `useClient` hook.
32
32
  */
33
33
  var ClientProvider = forwardRef(({ children, config: configProp, client: clientProp, services: servicesProp, status: statusProp, fallback: Fallback = () => null, suspend, noBanner, onInitialized, ...options }, forwardedRef) => {
34
- const [error, setError] = useState();
35
- if (error) throw error;
34
+ const [failure, setFailure] = useState();
35
+ if (failure) throw failure.error;
36
36
  const [client, setClient] = useState(clientProp instanceof Client ? clientProp : void 0);
37
37
  useImperativeHandle(forwardedRef, () => client, [client]);
38
38
  const [status, setStatus] = useControlledState(statusProp);
39
39
  useEffect(() => {
40
40
  if (!client) return;
41
- const subscription = client.status.subscribe((status) => setStatus(status));
42
- return () => subscription.unsubscribe();
41
+ const statusSubscription = client.status.subscribe((status) => setStatus(status));
42
+ const fatalErrorSubscription = client.fatalError.subscribe((error) => {
43
+ if (error) setFailure({ error });
44
+ });
45
+ return () => {
46
+ statusSubscription.unsubscribe();
47
+ fatalErrorSubscription.unsubscribe();
48
+ };
43
49
  }, [client]);
44
- useAsyncEffect(async () => {
45
- let disposed = false;
50
+ useAsyncEffect(async (controller) => {
46
51
  const initialize = async (client) => {
47
52
  if (!client.initialized && !(suspend && clientProp)) {
48
- await client.initialize().catch((err) => {
49
- if (!disposed) setError(err);
50
- });
53
+ await client.initialize();
51
54
  log("client ready", void 0, {
52
55
  "~LogMeta": "~LogMeta",
53
56
  F: __dxlog_file,
54
- L: 137,
57
+ L: 143,
55
58
  S: void 0
56
59
  });
57
60
  await onInitialized?.(client);
58
61
  log("initialization complete", void 0, {
59
62
  "~LogMeta": "~LogMeta",
60
63
  F: __dxlog_file,
61
- L: 139,
64
+ L: 145,
62
65
  S: void 0
63
66
  });
64
67
  }
@@ -75,14 +78,14 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
75
78
  log("resolved config", { config }, {
76
79
  "~LogMeta": "~LogMeta",
77
80
  F: __dxlog_file,
78
- L: 157,
81
+ L: 163,
79
82
  S: void 0
80
83
  });
81
84
  const services = await getAsyncProviderValue(servicesProp, config);
82
85
  log("created services", { services }, {
83
86
  "~LogMeta": "~LogMeta",
84
87
  F: __dxlog_file,
85
- L: 159,
88
+ L: 165,
86
89
  S: void 0
87
90
  });
88
91
  client = new Client({
@@ -93,38 +96,38 @@ var ClientProvider = forwardRef(({ children, config: configProp, client: clientP
93
96
  log("created client", void 0, {
94
97
  "~LogMeta": "~LogMeta",
95
98
  F: __dxlog_file,
96
- L: 161,
99
+ L: 167,
97
100
  S: void 0
98
101
  });
99
102
  await initialize(client);
100
103
  }
101
104
  } catch (err) {
102
- if (!disposed) log.catch(err, void 0, {
105
+ log.catch(err, void 0, {
103
106
  "~LogMeta": "~LogMeta",
104
107
  F: __dxlog_file,
105
- L: 166,
108
+ L: 172,
106
109
  S: void 0
107
110
  });
111
+ if (!controller.signal.aborted) setFailure({ error: err });
108
112
  }
109
113
  return () => {
110
114
  log("clean up", void 0, {
111
115
  "~LogMeta": "~LogMeta",
112
116
  F: __dxlog_file,
113
- L: 171,
117
+ L: 179,
114
118
  S: void 0
115
119
  });
116
- disposed = true;
117
120
  if (!clientProp) client?.destroy().then(() => {
118
121
  log("destroyed", void 0, {
119
122
  "~LogMeta": "~LogMeta",
120
123
  F: __dxlog_file,
121
- L: 178,
124
+ L: 185,
122
125
  S: void 0
123
126
  });
124
127
  }).catch((err) => log.catch(err, void 0, {
125
128
  "~LogMeta": "~LogMeta",
126
129
  F: __dxlog_file,
127
- L: 180,
130
+ L: 187,
128
131
  S: void 0
129
132
  }));
130
133
  };
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-ClientProvider.mjs","names":[],"sources":["../../src/banner.ts","../../src/client/ClientProvider.tsx"],"sourcesContent":["//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\n\n// http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS\nconst BANNER = (client: Client) => {\n const commitHash = client.config.get('runtime.app.build.commitHash');\n const hash = commitHash ? ` App Commit ${commitHash} \\n` : '';\n\n return (\n '\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\______/\\\\/\\\\/\\\\/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__/\\\\/\\\\_________\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\______/\\\\/\\\\______/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\___\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__________/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\/\\\\___\\n' +\n `\\n DXOS Client ${client.version} \\n${hash}`\n );\n};\n\nlet bannerPrinted = false;\n\nexport const printBanner = (client: Client) => {\n if (bannerPrinted || window.location.hostname === 'localhost') {\n return;\n }\n\n bannerPrinted = true;\n // eslint-disable-next-line no-console\n console.log(`%c${BANNER(client)}`, 'font-family: monospace;');\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport React, {\n type FunctionComponent,\n type PropsWithChildren,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useState,\n} from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner';\nimport { ClientContext, type ClientContextProps } from './context';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Provide the context immediately instead of rendering `fallback` until the client is\n * initialized and active. Client-dependent hooks then suspend at their own Suspense\n * boundaries, so the surrounding shell renders while initialization runs. Only valid with\n * a caller-supplied `client` whose initialization the caller owns (e.g. a forked\n * `initialize()`); the config/services paths keep the blocking behavior.\n */\n suspend?: boolean;\n\n /**\n * Skip the DXOS banner.\n */\n noBanner?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProp,\n client: clientProp,\n services: servicesProp,\n status: statusProp,\n fallback: Fallback = () => null,\n suspend,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n // The client is initialized asynchronously.\n // If an error occurs during initialization, it is caught and the state is set.\n // This allows the error to be thrown in the render method.\n // The assumption is that a client initialization error is fatal to the app.\n // This error will be caught by the nearest error boundary.\n const [error, setError] = useState();\n if (error) {\n throw error;\n }\n\n const [client, setClient] = useState(clientProp instanceof Client ? clientProp : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusProp);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useAsyncEffect(async () => {\n let disposed = false;\n const initialize = async (client: Client) => {\n // In suspend mode the caller owns initialization (typically a forked `initialize()` whose\n // failure raises the app's fatal error). A competing call here can succeed after that\n // failure and wake suspended consumers into an app whose initialization events never\n // fired — onboarding, app-graph, and migrations all gate on those.\n if (!client.initialized && !(suspend && clientProp)) {\n await client.initialize().catch((err) => {\n if (!disposed) {\n setError(err);\n }\n });\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n try {\n if (clientProp) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProp);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProp);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProp, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n } catch (err) {\n if (!disposed) {\n log.catch(err);\n }\n }\n\n return () => {\n log('clean up');\n disposed = true;\n // Only destroy if the client is not provided by the parent.\n if (!clientProp) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n }, [configProp, clientProp, servicesProp, noBanner, suspend]);\n\n // In suspend mode the (possibly uninitialized) client is provided immediately and hooks\n // suspend individually; the status gate is skipped because status only becomes ACTIVE\n // after the caller's forked initialization completes.\n if (!suspend && (!client?.initialized || status !== SystemStatus.ACTIVE)) {\n return <Fallback client={client} status={status} />;\n }\n if (!client) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n },\n);\n"],"mappings":";;;;;;;;AAOA,IAAM,UAAU,WAAmB;CACjC,MAAM,aAAa,OAAO,OAAO,IAAI,8BAA8B;CACnE,MAAM,OAAO,aAAa,eAAe,WAAW,OAAO;CAE3D,OACE;;;;;;iBAMkB,OAAO,QAAQ,KAAK;AAE1C;AAEA,IAAI,gBAAgB;AAEpB,IAAa,eAAe,WAAmB;CAC7C,IAAI,iBAAiB,OAAO,SAAS,aAAa,aAChD;CAGF,gBAAgB;CAEhB,QAAQ,IAAI,KAAK,OAAO,MAAM,KAAK,yBAAyB;AAC9D;;;;;;;;ACgDA,IAAa,iBAAiB,YAE1B,EACE,UACA,QAAQ,YACR,QAAQ,YACR,UAAU,cACV,QAAQ,YACR,UAAU,iBAAiB,MAC3B,SACA,UACA,eACA,GAAG,WAEL,iBACG;CAMH,MAAM,CAAC,OAAO,YAAY,SAAS;CACnC,IAAI,OACF,MAAM;CAGR,MAAM,CAAC,QAAQ,aAAa,SAAS,sBAAsB,SAAS,aAAa,KAAA,CAAS;CAG1F,oBAAoB,oBAAoB,QAAQ,CAAC,MAAM,CAAC;CAGx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AA,GAAA,KAAA;IAAA,CAAC;IACpB,MAAM,WAAW,MAAM;GACzB;EACF,SAAS,KAAK;GACZ,IAAI,CAAC,UACH,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;EAEjB;EAEA,aAAa;GACX,IAAI,YAAS,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;GACd,WAAW;GAEX,IAAI,CAAC,YACH,QACI,QAAQ,CAAA,CACT,WAAW;IACV,IAAI,aAAU,KAAA,GAAA;KAAA,YAAA;KAAA,GAAA;KAAA,GAAA;KAAA,GAAA,KAAA;IAAA,CAAC;GACjB,CAAC,CAAA,CACA,OAAO,QAAQ,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC,CAAC;EAEpC;CACF,GAAG;EAAC;EAAY;EAAY;EAAc;EAAU;CAAO,CAAC;CAK5D,IAAI,CAAC,YAAY,CAAC,QAAQ,eAAe,WAAW,aAAa,SAC/D,OAAO,oBAAC,UAAD;EAAkB;EAAgB;CAAS,CAAA;CAEpD,IAAI,CAAC,QACH,OAAO,oBAAC,UAAD;EAAkB;EAAgB;CAAS,CAAA;CAGpD,OAAO,oBAAC,cAAc,UAAf;EAAwB,OAAO;GAAE;GAAQ;EAAO;EAAI;CAAiC,CAAA;AAC9F,CACF"}
1
+ {"version":3,"file":"chunk-ClientProvider.mjs","names":[],"sources":["../../src/banner.ts","../../src/client/ClientProvider.tsx"],"sourcesContent":["//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\n\n// http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS\nconst BANNER = (client: Client) => {\n const commitHash = client.config.get('runtime.app.build.commitHash');\n const hash = commitHash ? ` App Commit ${commitHash} \\n` : '';\n\n return (\n '\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\______/\\\\/\\\\/\\\\/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__/\\\\/\\\\_________\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\______/\\\\/\\\\______/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\___\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__________/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\/\\\\___\\n' +\n `\\n DXOS Client ${client.version} \\n${hash}`\n );\n};\n\nlet bannerPrinted = false;\n\nexport const printBanner = (client: Client) => {\n if (bannerPrinted || window.location.hostname === 'localhost') {\n return;\n }\n\n bannerPrinted = true;\n // eslint-disable-next-line no-console\n console.log(`%c${BANNER(client)}`, 'font-family: monospace;');\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport React, {\n type FunctionComponent,\n type PropsWithChildren,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useState,\n} from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner.ts';\nimport { ClientContext, type ClientContextProps } from './context.ts';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Provide the context immediately instead of rendering `fallback` until the client is\n * initialized and active. Client-dependent hooks then suspend at their own Suspense\n * boundaries, so the surrounding shell renders while initialization runs. Only valid with\n * a caller-supplied `client` whose initialization the caller owns (e.g. a forked\n * `initialize()`); the config/services paths keep the blocking behavior.\n */\n suspend?: boolean;\n\n /**\n * Skip the DXOS banner.\n */\n noBanner?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProp,\n client: clientProp,\n services: servicesProp,\n status: statusProp,\n fallback: Fallback = () => null,\n suspend,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n // The client is initialized asynchronously.\n // If an error occurs during initialization, it is caught and the state is set.\n // This allows the error to be thrown in the render method.\n // The assumption is that a client initialization error is fatal to the app.\n // This error will be caught by the nearest error boundary.\n // Boxed so that any rejection value, including `undefined`, is thrown.\n const [failure, setFailure] = useState<{ error: unknown }>();\n if (failure) {\n throw failure.error;\n }\n\n const [client, setClient] = useState(clientProp instanceof Client ? clientProp : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusProp);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const statusSubscription = client.status.subscribe((status) => setStatus(status));\n // Losing services after initialization is as fatal as failing to initialize.\n const fatalErrorSubscription = client.fatalError.subscribe((error) => {\n if (error) {\n setFailure({ error });\n }\n });\n return () => {\n statusSubscription.unsubscribe();\n fatalErrorSubscription.unsubscribe();\n };\n }, [client]);\n\n // Create and/or initialize client.\n useAsyncEffect(\n async (controller) => {\n const initialize = async (client: Client) => {\n // In suspend mode the caller owns initialization (typically a forked `initialize()` whose\n // failure raises the app's fatal error). A competing call here can succeed after that\n // failure and wake suspended consumers into an app whose initialization events never\n // fired — onboarding, app-graph, and migrations all gate on those.\n if (!client.initialized && !(suspend && clientProp)) {\n await client.initialize();\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n try {\n if (clientProp) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProp);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProp);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProp, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n } catch (err) {\n // Any initialization failure, including onInitialized, is fatal and renders the nearest error boundary.\n log.catch(err);\n if (!controller.signal.aborted) {\n setFailure({ error: err });\n }\n }\n\n return () => {\n log('clean up');\n // Only destroy if the client is not provided by the parent.\n if (!clientProp) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n },\n [configProp, clientProp, servicesProp, noBanner, suspend],\n );\n\n // In suspend mode the (possibly uninitialized) client is provided immediately and hooks\n // suspend individually; the status gate is skipped because status only becomes ACTIVE\n // after the caller's forked initialization completes.\n if (!suspend && (!client?.initialized || status !== SystemStatus.ACTIVE)) {\n return <Fallback client={client} status={status} />;\n }\n if (!client) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n },\n);\n"],"mappings":";;;;;;;;AAOA,IAAM,UAAU,WAAmB;CACjC,MAAM,aAAa,OAAO,OAAO,IAAI,8BAA8B;CACnE,MAAM,OAAO,aAAa,eAAe,WAAW,OAAO;CAE3D,OACE;;;;;;iBAMkB,OAAO,QAAQ,KAAK;AAE1C;AAEA,IAAI,gBAAgB;AAEpB,IAAa,eAAe,WAAmB;CAC7C,IAAI,iBAAiB,OAAO,SAAS,aAAa,aAChD;CAGF,gBAAgB;CAEhB,QAAQ,IAAI,KAAK,OAAO,MAAM,KAAK,yBAAyB;AAC9D;;;;;;;;ACgDA,IAAa,iBAAiB,YAE1B,EACE,UACA,QAAQ,YACR,QAAQ,YACR,UAAU,cACV,QAAQ,YACR,UAAU,iBAAiB,MAC3B,SACA,UACA,eACA,GAAG,WAEL,iBACG;CAOH,MAAM,CAAC,SAAS,cAAc,SAA6B;CAC3D,IAAI,SACF,MAAM,QAAQ;CAGhB,MAAM,CAAC,QAAQ,aAAa,SAAS,sBAAsB,SAAS,aAAa,KAAA,CAAS;CAG1F,oBAAoB,oBAAoB,QAAQ,CAAC,MAAM,CAAC;CAGxD,MAAM,CAAC,QAAQ,aAAa,mBAAmB,UAAU;CACzD,gBAAgB;EACd,IAAI,CAAC,QACH;EAGF,MAAM,qBAAqB,OAAO,OAAO,WAAW,WAAW,UAAU,MAAM,CAAC;EAEhF,MAAM,yBAAyB,OAAO,WAAW,WAAW,UAAU;GACpE,IAAI,OACF,WAAW,EAAE,MAAM,CAAC;EAExB,CAAC;EACD,aAAa;GACX,mBAAmB,YAAY;GAC/B,uBAAuB,YAAY;EACrC;CACF,GAAG,CAAC,MAAM,CAAC;CAGX,eACE,OAAO,eAAe;EACpB,MAAM,aAAa,OAAO,WAAmB;GAK3C,IAAI,CAAC,OAAO,eAAe,EA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AI,CAAC,YACH,QACI,QAAQ,CAAA,CACT,WAAW;IACV,IAAI,aAAU,KAAA,GAAA;KAAA,YAAA;KAAA,GAAA;KAAA,GAAA;KAAA,GAAA,KAAA;IAAA,CAAC;GACjB,CAAC,CAAA,CACA,OAAO,QAAQ,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC,CAAC;EAEpC;CACF,GACA;EAAC;EAAY;EAAY;EAAc;EAAU;CAAO,CAC1D;CAKA,IAAI,CAAC,YAAY,CAAC,QAAQ,eAAe,WAAW,aAAa,SAC/D,OAAO,oBAAC,UAAD;EAAkB;EAAgB;CAAS,CAAA;CAEpD,IAAI,CAAC,QACH,OAAO,oBAAC,UAAD;EAAkB;EAAgB;CAAS,CAAA;CAGpD,OAAO,oBAAC,cAAc,UAAf;EAAwB,OAAO;GAAE;GAAQ;EAAO;EAAI;CAAiC,CAAA;AAC9F,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-useClient.mjs","names":[],"sources":["../../src/client/useClient.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n *\n * Under a `suspend` ClientProvider the context is available before `client.initialize()`\n * completes; this hook then suspends (throws the initialization promise) so any component\n * depending on the client parks at its nearest Suspense boundary instead of reading an\n * uninitialized client.\n *\n * Deliberately no timeout here: React retries a rejected thrown promise and the retry suspends\n * again, so a rejection loops rather than reaching an error boundary (measured: ~90 renders in\n * 500ms). A stalled initialization is bounded once, at the app entry point, which raises it as a\n * fatal error instead.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n if (!client.initialized) {\n throw client.waitUntilInitialized();\n }\n return client;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,IAAa,kBAAkB;CAC7B,MAAM,EAAE,WAAW,WAAW,aAAa,KAAK,sBAAM,IAAI,MAAM,wBAAwB,CAAC;CACzF,IAAI,CAAC,OAAO,aACV,MAAM,OAAO,qBAAqB;CAEpC,OAAO;AACT"}
1
+ {"version":3,"file":"chunk-useClient.mjs","names":[],"sources":["../../src/client/useClient.ts"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context.ts';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n *\n * Under a `suspend` ClientProvider the context is available before `client.initialize()`\n * completes; this hook then suspends (throws the initialization promise) so any component\n * depending on the client parks at its nearest Suspense boundary instead of reading an\n * uninitialized client.\n *\n * Deliberately no timeout here: React retries a rejected thrown promise and the retry suspends\n * again, so a rejection loops rather than reaching an error boundary (measured: ~90 renders in\n * 500ms). A stalled initialization is bounded once, at the app entry point, which raises it as a\n * fatal error instead.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n if (!client.initialized) {\n throw client.waitUntilInitialized();\n }\n return client;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,IAAa,kBAAkB;CAC7B,MAAM,EAAE,WAAW,WAAW,aAAa,KAAK,sBAAM,IAAI,MAAM,wBAAwB,CAAC;CACzF,IAAI,CAAC,OAAO,aACV,MAAM,OAAO,qBAAqB;CAEpC,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"devtools.mjs","names":[],"sources":["../../src/devtools/useDevtools.ts","../../src/devtools/useStream.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type DevtoolsHost } from '@dxos/client/devtools';\nimport { raise } from '@dxos/debug';\n\nimport { useClient } from '../client';\n\nexport const useDevtools = (): DevtoolsHost => {\n const client = useClient();\n return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));\n};\n","//\n// Copyright 2021 DXOS.org\n//\n\nimport { type DependencyList, useEffect, useState } from 'react';\n\nimport { type Stream } from '@dxos/async';\nimport { log } from '@dxos/log';\n\n/**\n * Subscribe to service API streams.\n */\nexport const useStream = <T>(streamFactory: () => Stream<T>, defaultValue: T, deps: DependencyList = []): T => {\n const [value, setValue] = useState<T | undefined>(defaultValue);\n useEffect(() => {\n const stream = streamFactory();\n stream.subscribe(\n (response: T) => setValue(response),\n (err) => {\n if (err) {\n log.catch(err);\n }\n },\n );\n\n return () => {\n void stream.close();\n };\n }, deps);\n\n return value ?? defaultValue;\n};\n"],"mappings":";;;;;;AASA,IAAa,oBAAkC;CAE7C,OADe,UACR,CAAA,CAAO,SAAS,SAAS,gBAAgB,sBAAM,IAAI,MAAM,6BAA6B,CAAC;AAChG;;;;;;;ACAA,IAAa,aAAgB,eAAgC,cAAiB,OAAuB,CAAC,MAAS;CAC7G,MAAM,CAAC,OAAO,YAAY,SAAwB,YAAY;CAC9D,gBAAgB;EACd,MAAM,SAAS,cAAc;EAC7B,OAAO,WACJ,aAAgB,SAAS,QAAQ,IACjC,QAAQ;GACP,IAAI,KACF,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;EAEjB,CACF;EAEA,aAAa;GACX,OAAY,MAAM;EACpB;CACF,GAAG,IAAI;CAEP,OAAO,SAAS;AAClB"}
1
+ {"version":3,"file":"devtools.mjs","names":[],"sources":["../../src/devtools/useDevtools.ts","../../src/devtools/useStream.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type DevtoolsHost } from '@dxos/client/devtools';\nimport { raise } from '@dxos/debug';\n\nimport { useClient } from '../client/index.ts';\n\nexport const useDevtools = (): DevtoolsHost => {\n const client = useClient();\n return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));\n};\n","//\n// Copyright 2021 DXOS.org\n//\n\nimport { type DependencyList, useEffect, useState } from 'react';\n\nimport { type Stream } from '@dxos/async';\nimport { log } from '@dxos/log';\n\n/**\n * Subscribe to service API streams.\n */\nexport const useStream = <T>(streamFactory: () => Stream<T>, defaultValue: T, deps: DependencyList = []): T => {\n const [value, setValue] = useState<T | undefined>(defaultValue);\n useEffect(() => {\n const stream = streamFactory();\n stream.subscribe(\n (response: T) => setValue(response),\n (err) => {\n if (err) {\n log.catch(err);\n }\n },\n );\n\n return () => {\n void stream.close();\n };\n }, deps);\n\n return value ?? defaultValue;\n};\n"],"mappings":";;;;;;AASA,IAAa,oBAAkC;CAE7C,OADe,UACR,CAAA,CAAO,SAAS,SAAS,gBAAgB,sBAAM,IAAI,MAAM,6BAA6B,CAAC;AAChG;;;;;;;ACAA,IAAa,aAAgB,eAAgC,cAAiB,OAAuB,CAAC,MAAS;CAC7G,MAAM,CAAC,OAAO,YAAY,SAAwB,YAAY;CAC9D,gBAAgB;EACd,MAAM,SAAS,cAAc;EAC7B,OAAO,WACJ,aAAgB,SAAS,QAAQ,IACjC,QAAQ;GACP,IAAI,KACF,IAAI,MAAM,KAAE,KAAA,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;EAEjB,CACF;EAEA,aAAa;GACX,OAAY,MAAM;EACpB;CACF,GAAG,IAAI;CAEP,OAAO,SAAS;AAClB"}
package/dist/lib/echo.mjs CHANGED
@@ -3,7 +3,7 @@ import { useInvitationStatus } from "./invitations.mjs";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { PublicKey } from "@dxos/client";
5
5
  import { useMulticastObservable } from "@dxos/react-hooks";
6
- import { HaloSpaceMember, SpaceState, createSubscription } from "@dxos/client/echo";
6
+ import { SpaceMember_Role, SpaceState, createSubscription } from "@dxos/client/echo";
7
7
  import { useObject } from "@dxos/echo-react";
8
8
  import { MulticastObservable } from "@dxos/async";
9
9
  import { Context } from "@dxos/context";
@@ -43,7 +43,7 @@ var useSpaces = ({ all = false } = {}) => {
43
43
  var useMembers = (spaceKey) => {
44
44
  const spaces = useSpaces({ all: true });
45
45
  const space = spaceKey ? spaces.find((space) => spaceKey instanceof PublicKey ? space.key.equals(spaceKey) : space.id === spaceKey) : void 0;
46
- return (useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? []).filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);
46
+ return (useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? []).filter((member) => member.role !== SpaceMember_Role.REMOVED);
47
47
  };
48
48
  //#endregion
49
49
  //#region src/echo/useSpaceInvitations.ts
@@ -176,9 +176,10 @@ var useSpaceSyncState = (space) => {
176
176
  };
177
177
  //#endregion
178
178
  //#region src/echo/useFeedSyncState.ts
179
- var DEFAULT_POLL_INTERVAL_MS = 5e3;
179
+ var DEFAULT_POLL_INTERVAL_MS = 15e3;
180
+ var isDocumentVisible = () => globalThis.document?.visibilityState !== "hidden";
180
181
  /**
181
- * Polls feed replication state per space.
182
+ * Polls feed replication state per space, while the document is visible.
182
183
  */
183
184
  var useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS) => {
184
185
  const client = useClient();
@@ -187,6 +188,7 @@ var useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS) => {
187
188
  const feedService = client.services.services.FeedService;
188
189
  if (!feedService) return;
189
190
  let cancelled = false;
191
+ let interval;
190
192
  const poll = async () => {
191
193
  const spaces = client.spaces.get();
192
194
  const entries = await Promise.all(spaces.map(async (space) => {
@@ -209,14 +211,27 @@ var useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS) => {
209
211
  }));
210
212
  if (!cancelled) setFeedSyncState(Object.fromEntries(entries));
211
213
  };
212
- poll();
213
- const interval = setInterval(() => void poll(), pollIntervalMs);
214
- const spacesSubscription = client.spaces.subscribe(() => {
214
+ const start = () => {
215
+ if (interval !== void 0) return;
215
216
  poll();
217
+ interval = setInterval(() => void poll(), pollIntervalMs);
218
+ };
219
+ const stop = () => {
220
+ if (interval === void 0) return;
221
+ clearInterval(interval);
222
+ interval = void 0;
223
+ };
224
+ const handleVisibilityChange = () => isDocumentVisible() ? start() : stop();
225
+ if (isDocumentVisible()) start();
226
+ const document = globalThis.document;
227
+ document?.addEventListener("visibilitychange", handleVisibilityChange);
228
+ const spacesSubscription = client.spaces.subscribe(() => {
229
+ if (isDocumentVisible()) poll();
216
230
  });
217
231
  return () => {
218
232
  cancelled = true;
219
- clearInterval(interval);
233
+ stop();
234
+ document?.removeEventListener("visibilitychange", handleVisibilityChange);
220
235
  spacesSubscription.unsubscribe();
221
236
  };
222
237
  }, [client, pollIntervalMs]);
@@ -1 +1 @@
1
- {"version":3,"file":"echo.mjs","names":[],"sources":["../../src/echo/useSpaces.ts","../../src/echo/useMembers.ts","../../src/echo/useSpaceInvitations.ts","../../src/echo/useSpaceProperties.ts","../../src/echo/useFlush.ts","../../src/echo/useSubscription.ts","../../src/echo/useSyncState.ts","../../src/echo/useFeedSyncState.ts","../../src/echo/useRegistry.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { type SpaceId } from '@dxos/keys';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its id.\n * The space is not guaranteed to be in the ready state.\n * Returns undefined if no id is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceId the id of the space to look for.\n */\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n if (!spaceId) {\n return undefined;\n }\n\n return spaces.find((space) => {\n if (spaceId instanceof PublicKey) {\n return space.key.equals(spaceId);\n }\n\n return space.id === spaceId;\n });\n};\n\nexport type UseSpacesProps = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces.\n */\nexport const useSpaces = ({ all = false }: UseSpacesProps = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { PublicKey, type PublicKeyLike } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKeyLike | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey\n ? spaces.find((space) => (spaceKey instanceof PublicKey ? space.key.equals(spaceKey) : space.id === spaceKey))\n : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { type SpaceId } from '@dxos/keys';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\nimport { useSpace } from './useSpaces';\n\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpaceInvitations = (spaceId?: SpaceId | PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceId);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpaceInvitation = (spaceId?: SpaceId | PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceId);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type SpaceProperties, SpaceState } from '@dxos/client/echo';\nimport { type Key, type Obj } from '@dxos/echo';\nimport { type ObjectUpdateCallback, useObject } from '@dxos/echo-react';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpace } from './useSpaces';\n\n/**\n * Subscribe to a space's properties with reactive updates.\n * Returns undefined if the space is undefined or not ready yet.\n * Automatically waits for the space to be ready before returning properties.\n *\n * @param spaceId - The space ID to get properties from (can be undefined).\n * @returns A tuple of [snapshot, updateCallback] or [undefined, no-op] if not ready.\n */\nexport const useSpaceProperties = (\n spaceId: Key.SpaceId | undefined,\n): [Obj.Snapshot<SpaceProperties> | undefined, ObjectUpdateCallback<SpaceProperties>] => {\n const space = useSpace(spaceId);\n const spaceState = useMulticastObservable(space?.state ?? MulticastObservable.empty());\n const properties = spaceState === SpaceState.SPACE_READY ? space?.properties : undefined;\n return useObject(properties);\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback, useRef, useState } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\n\n/**\n * Flushes a space's database to storage, exposing a transient `idle → flushing → flushed → idle`\n * state suitable for driving a toolbar affordance.\n */\nexport const useFlush = (space?: Space) => {\n const [state, setState] = useState<'idle' | 'flushing' | 'flushed'>('idle');\n const resetTimer = useRef<NodeJS.Timeout | null>(null);\n\n const handleFlush = useCallback(() => {\n if (!space) {\n return;\n }\n\n queueMicrotask(async () => {\n if (resetTimer.current) {\n clearTimeout(resetTimer.current);\n }\n\n setState('flushing');\n await space.db.flush();\n setState('flushed');\n\n resetTimer.current = setTimeout(() => {\n setState('idle');\n resetTimer.current = null;\n }, 1_000);\n });\n }, [space]);\n\n return { state, handleFlush };\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>(null);\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PeerSyncState, type Space, type SpaceSyncStateMap } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { isEdgePeerId } from '@dxos/echo-protocol';\n\nimport { useClient } from '../client';\n\n/**\n * Hook Subscribes to sync state for each space.\n */\nexport const useSyncState = (): SpaceSyncStateMap => {\n const client = useClient();\n const [spaceState, setSpaceState] = useState<SpaceSyncStateMap>({});\n\n useEffect(() => {\n const ctx = new Context();\n const createSubscriptions = (spaces: Space[]) => {\n for (const space of spaces) {\n if (spaceState[space.id]) {\n continue;\n }\n\n ctx.onDispose(\n space.internal.db.subscribeToAutomergeSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState((spaceState) => ({ ...spaceState, [space.id]: syncState }));\n }\n }),\n );\n }\n };\n\n createSubscriptions(client.spaces.get());\n client.spaces.subscribe((spaces) => {\n createSubscriptions(spaces);\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [client]);\n\n return spaceState;\n};\n\n/**\n * Hook Subscribes to sync state for a single space.\n */\n// TODO(wittjosiah): Reconcile w/ useSyncState.\nexport const useSpaceSyncState = (space: Space): PeerSyncState | undefined => {\n const [spaceState, setSpaceState] = useState<PeerSyncState>();\n\n useEffect(() => {\n const ctx = new Context();\n space.internal.db.subscribeToAutomergeSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState(syncState);\n }\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [space]);\n\n return spaceState;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type SpaceId } from '@dxos/keys';\n\nimport { useClient } from '../client';\n\nconst DEFAULT_POLL_INTERVAL_MS = 5_000;\n\nexport type FeedSyncState = {\n /** Combined blocks to pull + push across namespaces. */\n pending: number;\n /** Total blocks stored locally across namespaces. */\n total: number;\n};\n\nexport type FeedSyncStateMap = Record<SpaceId, FeedSyncState>;\n\n/**\n * Polls feed replication state per space.\n */\nexport const useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS): FeedSyncStateMap => {\n const client = useClient();\n const [feedSyncState, setFeedSyncState] = useState<FeedSyncStateMap>({});\n\n useEffect(() => {\n const feedService = client.services.services.FeedService;\n if (!feedService) {\n return;\n }\n\n let cancelled = false;\n\n const poll = async () => {\n const spaces = client.spaces.get();\n const entries = await Promise.all(\n spaces.map(async (space) => {\n try {\n const response = await feedService.getSyncState({ spaceId: space.id });\n const state = (response.namespaces ?? []).reduce<FeedSyncState>(\n (acc, entry) => {\n acc.pending += Number(entry.blocksToPull ?? 0) + Number(entry.blocksToPush ?? 0);\n acc.total += Number(entry.totalBlocks ?? 0);\n return acc;\n },\n { pending: 0, total: 0 },\n );\n return [space.id, state] as const;\n } catch {\n return [space.id, { pending: 0, total: 0 }] as const;\n }\n }),\n );\n\n if (!cancelled) {\n setFeedSyncState(Object.fromEntries(entries));\n }\n };\n\n void poll();\n const interval = setInterval(() => void poll(), pollIntervalMs);\n\n const spacesSubscription = client.spaces.subscribe(() => {\n void poll();\n });\n\n return () => {\n cancelled = true;\n clearInterval(interval);\n spacesSubscription.unsubscribe();\n };\n }, [client, pollIntervalMs]);\n\n return feedSyncState;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Registry } from '@dxos/echo';\n\nimport { useClient } from '../client';\n\n/**\n * Returns the hypergraph registry attached to the current client.\n */\nexport const useRegistry = (): Registry.Registry => {\n const client = useClient();\n return client.graph.registry;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,YAAY,YAAqD;CAC5E,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAgC,OAAO,MAAM;CAC5D,IAAI,CAAC,SACH;CAGF,OAAO,OAAO,MAAM,UAAU;EAC5B,IAAI,mBAAmB,WACrB,OAAO,MAAM,IAAI,OAAO,OAAO;EAGjC,OAAO,MAAM,OAAO;CACtB,CAAC;AACH;;;;;;;AAeA,IAAa,aAAa,EAAE,MAAM,UAA0B,CAAC,MAAe;CAC1E,MAAM,SAAS,UAAU;CAIzB,OAHe,uBAAgC,OAAO,MAG/C,CAAA,CAAO,QAAQ,UAAU,OAAO,MAAM,MAAM,IAAI,MAAM,WAAW,WAAW;AACrF;;;AC7CA,IAAa,cAAc,aAAuD;CAEhF,MAAM,SAAS,UAAU,EAAE,KAAK,KAAK,CAAC;CACtC,MAAM,QAAQ,WACV,OAAO,MAAM,UAAW,oBAAoB,YAAY,MAAM,IAAI,OAAO,QAAQ,IAAI,MAAM,OAAO,QAAS,IAC3G,KAAA;CAIJ,QADgB,uBAAuB,OAAO,WAAW,oBAAoB,MAAM,CAAC,KAAK,CAAC,EAAA,CAC3E,QAAQ,WAAW,OAAO,SAAS,gBA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"sources":["../../src/echo/useSpaces.ts","../../src/echo/useMembers.ts","../../src/echo/useSpaceInvitations.ts","../../src/echo/useSpaceProperties.ts","../../src/echo/useFlush.ts","../../src/echo/useSubscription.ts","../../src/echo/useSyncState.ts","../../src/echo/useFeedSyncState.ts","../../src/echo/useRegistry.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nimport { PublicKey } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { type SpaceId } from '@dxos/keys';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client/index.ts';\n\n/**\n * Get a specific Space using its id.\n * The space is not guaranteed to be in the ready state.\n * Returns undefined if no id is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceId the id of the space to look for.\n */\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpace = (spaceId?: SpaceId | PublicKey): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n if (!spaceId) {\n return undefined;\n }\n\n return spaces.find((space) => {\n if (spaceId instanceof PublicKey) {\n return space.key.equals(spaceId);\n }\n\n return space.id === spaceId;\n });\n};\n\nexport type UseSpacesProps = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces.\n */\nexport const useSpaces = ({ all = false }: UseSpacesProps = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { PublicKey, type PublicKeyLike } from '@dxos/client';\nimport { type SpaceMember, SpaceMember_Role } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces.ts';\n\nexport const useMembers = (spaceKey: PublicKeyLike | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey\n ? spaces.find((space) => (spaceKey instanceof PublicKey ? space.key.equals(spaceKey) : space.id === spaceKey))\n : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== SpaceMember_Role.REMOVED);\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { type SpaceId } from '@dxos/keys';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations/index.ts';\nimport { useSpace } from './useSpaces.ts';\n\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpaceInvitations = (spaceId?: SpaceId | PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceId);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\n// TODO(wittjosiah): Currently unable to remove `PublicKey` from this api.\n// When initially joining a space that is all that is returned.\nexport const useSpaceInvitation = (spaceId?: SpaceId | PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceId);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type SpaceProperties, SpaceState } from '@dxos/client/echo';\nimport { type Key, type Obj } from '@dxos/echo';\nimport { type ObjectUpdateCallback, useObject } from '@dxos/echo-react';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpace } from './useSpaces.ts';\n\n/**\n * Subscribe to a space's properties with reactive updates.\n * Returns undefined if the space is undefined or not ready yet.\n * Automatically waits for the space to be ready before returning properties.\n *\n * @param spaceId - The space ID to get properties from (can be undefined).\n * @returns A tuple of [snapshot, updateCallback] or [undefined, no-op] if not ready.\n */\nexport const useSpaceProperties = (\n spaceId: Key.SpaceId | undefined,\n): [Obj.Snapshot<SpaceProperties> | undefined, ObjectUpdateCallback<SpaceProperties>] => {\n const space = useSpace(spaceId);\n const spaceState = useMulticastObservable(space?.state ?? MulticastObservable.empty());\n const properties = spaceState === SpaceState.SPACE_READY ? space?.properties : undefined;\n return useObject(properties);\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback, useRef, useState } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\n\n/**\n * Flushes a space's database to storage, exposing a transient `idle → flushing → flushed → idle`\n * state suitable for driving a toolbar affordance.\n */\nexport const useFlush = (space?: Space) => {\n const [state, setState] = useState<'idle' | 'flushing' | 'flushed'>('idle');\n const resetTimer = useRef<NodeJS.Timeout | null>(null);\n\n const handleFlush = useCallback(() => {\n if (!space) {\n return;\n }\n\n queueMicrotask(async () => {\n if (resetTimer.current) {\n clearTimeout(resetTimer.current);\n }\n\n setState('flushing');\n await space.db.flush();\n setState('flushed');\n\n resetTimer.current = setTimeout(() => {\n setState('idle');\n resetTimer.current = null;\n }, 1_000);\n });\n }, [space]);\n\n return { state, handleFlush };\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>(null);\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PeerSyncState, type Space, type SpaceSyncStateMap } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { isEdgePeerId } from '@dxos/echo-protocol';\n\nimport { useClient } from '../client/index.ts';\n\n/**\n * Hook Subscribes to sync state for each space.\n */\nexport const useSyncState = (): SpaceSyncStateMap => {\n const client = useClient();\n const [spaceState, setSpaceState] = useState<SpaceSyncStateMap>({});\n\n useEffect(() => {\n const ctx = new Context();\n const createSubscriptions = (spaces: Space[]) => {\n for (const space of spaces) {\n if (spaceState[space.id]) {\n continue;\n }\n\n ctx.onDispose(\n space.internal.db.subscribeToAutomergeSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState((spaceState) => ({ ...spaceState, [space.id]: syncState }));\n }\n }),\n );\n }\n };\n\n createSubscriptions(client.spaces.get());\n client.spaces.subscribe((spaces) => {\n createSubscriptions(spaces);\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [client]);\n\n return spaceState;\n};\n\n/**\n * Hook Subscribes to sync state for a single space.\n */\n// TODO(wittjosiah): Reconcile w/ useSyncState.\nexport const useSpaceSyncState = (space: Space): PeerSyncState | undefined => {\n const [spaceState, setSpaceState] = useState<PeerSyncState>();\n\n useEffect(() => {\n const ctx = new Context();\n space.internal.db.subscribeToAutomergeSyncState(ctx, ({ peers = [] }) => {\n const syncState = peers.find((state) => isEdgePeerId(state.peerId, space.id));\n if (syncState) {\n setSpaceState(syncState);\n }\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [space]);\n\n return spaceState;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type SpaceId } from '@dxos/keys';\n\nimport { useClient } from '../client/index.ts';\n\n// Each poll issues a `peekPull` round-trip to edge per space per namespace, so a stats readout polls\n// an order of magnitude slower than the data path it observes.\nconst DEFAULT_POLL_INTERVAL_MS = 15_000;\n\nexport type FeedSyncState = {\n /** Combined blocks to pull + push across namespaces. */\n pending: number;\n /** Total blocks stored locally across namespaces. */\n total: number;\n};\n\nexport type FeedSyncStateMap = Record<SpaceId, FeedSyncState>;\n\nconst isDocumentVisible = (): boolean => globalThis.document?.visibilityState !== 'hidden';\n\n/**\n * Polls feed replication state per space, while the document is visible.\n */\nexport const useFeedSyncState = (pollIntervalMs = DEFAULT_POLL_INTERVAL_MS): FeedSyncStateMap => {\n const client = useClient();\n const [feedSyncState, setFeedSyncState] = useState<FeedSyncStateMap>({});\n\n useEffect(() => {\n const feedService = client.services.services.FeedService;\n if (!feedService) {\n return;\n }\n\n let cancelled = false;\n let interval: ReturnType<typeof setInterval> | undefined;\n\n const poll = async () => {\n const spaces = client.spaces.get();\n const entries = await Promise.all(\n spaces.map(async (space) => {\n try {\n const response = await feedService.getSyncState({ spaceId: space.id });\n const state = (response.namespaces ?? []).reduce<FeedSyncState>(\n (acc, entry) => {\n acc.pending += Number(entry.blocksToPull ?? 0) + Number(entry.blocksToPush ?? 0);\n acc.total += Number(entry.totalBlocks ?? 0);\n return acc;\n },\n { pending: 0, total: 0 },\n );\n return [space.id, state] as const;\n } catch {\n return [space.id, { pending: 0, total: 0 }] as const;\n }\n }),\n );\n\n if (!cancelled) {\n setFeedSyncState(Object.fromEntries(entries));\n }\n };\n\n // Polling resumes with an immediate poll so the readout is not stale for a whole interval.\n const start = () => {\n if (interval !== undefined) {\n return;\n }\n void poll();\n interval = setInterval(() => void poll(), pollIntervalMs);\n };\n\n const stop = () => {\n if (interval === undefined) {\n return;\n }\n clearInterval(interval);\n interval = undefined;\n };\n\n const handleVisibilityChange = () => (isDocumentVisible() ? start() : stop());\n\n if (isDocumentVisible()) {\n start();\n }\n\n const document = globalThis.document;\n document?.addEventListener('visibilitychange', handleVisibilityChange);\n\n const spacesSubscription = client.spaces.subscribe(() => {\n if (isDocumentVisible()) {\n void poll();\n }\n });\n\n return () => {\n cancelled = true;\n stop();\n document?.removeEventListener('visibilitychange', handleVisibilityChange);\n spacesSubscription.unsubscribe();\n };\n }, [client, pollIntervalMs]);\n\n return feedSyncState;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Registry } from '@dxos/echo';\n\nimport { useClient } from '../client/index.ts';\n\n/**\n * Returns the hypergraph registry attached to the current client.\n */\nexport const useRegistry = (): Registry.Registry => {\n const client = useClient();\n return client.graph.registry;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,YAAY,YAAqD;CAC5E,MAAM,SAAS,UAAU;CACzB,MAAM,SAAS,uBAAgC,OAAO,MAAM;CAC5D,IAAI,CAAC,SACH;CAGF,OAAO,OAAO,MAAM,UAAU;EAC5B,IAAI,mBAAmB,WACrB,OAAO,MAAM,IAAI,OAAO,OAAO;EAGjC,OAAO,MAAM,OAAO;CACtB,CAAC;AACH;;;;;;;AAeA,IAAa,aAAa,EAAE,MAAM,UAA0B,CAAC,MAAe;CAC1E,MAAM,SAAS,UAAU;CAIzB,OAHe,uBAAgC,OAAO,MAG/C,CAAA,CAAO,QAAQ,UAAU,OAAO,MAAM,MAAM,IAAI,MAAM,WAAW,WAAW;AACrF;;;AC7CA,IAAa,cAAc,aAAuD;CAEhF,MAAM,SAAS,UAAU,EAAE,KAAK,KAAK,CAAC;CACtC,MAAM,QAAQ,WACV,OAAO,MAAM,UAAW,oBAAoB,YAAY,MAAM,IAAI,OAAO,QAAQ,IAAI,MAAM,OAAO,QAAS,IAC3G,KAAA;CAIJ,QADgB,uBAAuB,OAAO,WAAW,oBAAoB,MAAM,CAAC,KAAK,CAAC,EAAA,CAC3E,QAAQ,WAA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