jazz-tools 0.19.8 → 0.19.10
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.
- package/.turbo/turbo-build.log +44 -42
- package/CHANGELOG.md +19 -3
- package/dist/{chunk-2S3Z2CN6.js → chunk-FFEEPZEG.js} +367 -102
- package/dist/chunk-FFEEPZEG.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +59 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +124 -36
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/testUtils.d.ts +1 -0
- package/dist/react-core/tests/testUtils.d.ts.map +1 -1
- package/dist/react-core/tests/useSuspenseAccount.test.d.ts +2 -0
- package/dist/react-core/tests/useSuspenseAccount.test.d.ts.map +1 -0
- package/dist/react-core/tests/useSuspenseCoState.test.d.ts +2 -0
- package/dist/react-core/tests/useSuspenseCoState.test.d.ts.map +1 -0
- package/dist/react-core/use.d.ts +3 -0
- package/dist/react-core/use.d.ts.map +1 -0
- package/dist/react-native/index.js +5 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native-core/crypto/RNCrypto.d.ts +2 -0
- package/dist/react-native-core/crypto/RNCrypto.d.ts.map +1 -0
- package/dist/react-native-core/crypto/RNCrypto.js +3 -0
- package/dist/react-native-core/crypto/RNCrypto.js.map +1 -0
- package/dist/react-native-core/hooks.d.ts +1 -1
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js +5 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +2 -1
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +1 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/implementation/ContextManager.d.ts +3 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +8 -22
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionCache.d.ts +51 -0
- package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -0
- package/dist/tools/subscribe/SubscriptionScope.d.ts +17 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +9 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +2 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/SubscriptionCache.test.d.ts +2 -0
- package/dist/tools/tests/SubscriptionCache.test.d.ts.map +1 -0
- package/package.json +13 -6
- package/src/react/hooks.tsx +2 -0
- package/src/react/index.ts +1 -14
- package/src/react-core/hooks.ts +167 -18
- package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +18 -8
- package/src/react-core/tests/testUtils.tsx +67 -5
- package/src/react-core/tests/useCoState.test.ts +3 -7
- package/src/react-core/tests/useSubscriptionSelector.test.ts +3 -7
- package/src/react-core/tests/useSuspenseAccount.test.tsx +343 -0
- package/src/react-core/tests/useSuspenseCoState.test.tsx +1182 -0
- package/src/react-core/use.ts +46 -0
- package/src/react-native-core/crypto/RNCrypto.ts +1 -0
- package/src/react-native-core/hooks.tsx +2 -0
- package/src/react-native-core/platform.ts +2 -1
- package/src/tools/coValues/interfaces.ts +2 -3
- package/src/tools/implementation/ContextManager.ts +13 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +71 -100
- package/src/tools/subscribe/SubscriptionCache.ts +272 -0
- package/src/tools/subscribe/SubscriptionScope.ts +113 -7
- package/src/tools/subscribe/utils.ts +77 -0
- package/src/tools/testing.ts +0 -3
- package/src/tools/tests/CoValueCoreSubscription.test.ts +46 -12
- package/src/tools/tests/ContextManager.test.ts +85 -0
- package/src/tools/tests/SubscriptionCache.test.ts +237 -0
- package/src/tools/tests/coMap.test.ts +5 -7
- package/tsup.config.ts +1 -0
- package/dist/chunk-2S3Z2CN6.js.map +0 -1
package/dist/react-core/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/react-core/hooks.ts
|
|
8
8
|
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
9
|
-
import
|
|
9
|
+
import React2, {
|
|
10
10
|
useCallback,
|
|
11
11
|
useContext,
|
|
12
12
|
useRef,
|
|
@@ -16,8 +16,6 @@ import {
|
|
|
16
16
|
Account,
|
|
17
17
|
CoValueLoadingState,
|
|
18
18
|
InboxSender,
|
|
19
|
-
SubscriptionScope,
|
|
20
|
-
coValueClassFromCoValueClassOrSchema,
|
|
21
19
|
importContentPieces,
|
|
22
20
|
captureStack,
|
|
23
21
|
getUnloadedCoValueWithoutId
|
|
@@ -32,6 +30,37 @@ function getCurrentAccountFromContextManager(contextManager) {
|
|
|
32
30
|
return "me" in context ? context.me : context.guest;
|
|
33
31
|
}
|
|
34
32
|
|
|
33
|
+
// src/react-core/use.ts
|
|
34
|
+
import React from "react";
|
|
35
|
+
var attachPromiseStatus = (promise) => {
|
|
36
|
+
if (!promise.status) {
|
|
37
|
+
promise.status = "pending";
|
|
38
|
+
promise.then(
|
|
39
|
+
(v) => {
|
|
40
|
+
promise.status = "fulfilled";
|
|
41
|
+
promise.value = v;
|
|
42
|
+
},
|
|
43
|
+
(e) => {
|
|
44
|
+
promise.status = "rejected";
|
|
45
|
+
promise.reason = e;
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var use = React.use || // A shim for older React versions
|
|
51
|
+
((promise) => {
|
|
52
|
+
if (promise.status === "pending") {
|
|
53
|
+
throw promise;
|
|
54
|
+
} else if (promise.status === "fulfilled") {
|
|
55
|
+
return promise.value;
|
|
56
|
+
} else if (promise.status === "rejected") {
|
|
57
|
+
throw promise.reason;
|
|
58
|
+
} else {
|
|
59
|
+
attachPromiseStatus(promise);
|
|
60
|
+
throw promise;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
35
64
|
// src/react-core/hooks.ts
|
|
36
65
|
function useJazzContext() {
|
|
37
66
|
const value = useContext(JazzContext);
|
|
@@ -76,7 +105,7 @@ function useIsAuthenticated() {
|
|
|
76
105
|
function useCoValueSubscription(Schema, id, options) {
|
|
77
106
|
const contextManager = useJazzContextManager();
|
|
78
107
|
const agent = useAgent();
|
|
79
|
-
const callerStack =
|
|
108
|
+
const callerStack = React2.useRef(void 0);
|
|
80
109
|
if (!callerStack.current) {
|
|
81
110
|
callerStack.current = captureStack();
|
|
82
111
|
}
|
|
@@ -99,19 +128,19 @@ function useCoValueSubscription(Schema, id, options) {
|
|
|
99
128
|
}
|
|
100
129
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
101
130
|
const node = contextManager.getCurrentValue().node;
|
|
102
|
-
const
|
|
131
|
+
const cache = contextManager.getSubscriptionScopeCache();
|
|
132
|
+
const subscription2 = cache.getOrCreate(
|
|
103
133
|
node,
|
|
104
|
-
|
|
134
|
+
Schema,
|
|
105
135
|
id,
|
|
106
|
-
|
|
107
|
-
ref: coValueClassFromCoValueClassOrSchema(Schema),
|
|
108
|
-
optional: true
|
|
109
|
-
},
|
|
136
|
+
resolve,
|
|
110
137
|
false,
|
|
111
138
|
false,
|
|
112
|
-
options?.unstable_branch
|
|
113
|
-
callerStack.current
|
|
139
|
+
options?.unstable_branch
|
|
114
140
|
);
|
|
141
|
+
if (callerStack.current) {
|
|
142
|
+
subscription2.callerStack = callerStack.current;
|
|
143
|
+
}
|
|
115
144
|
return {
|
|
116
145
|
value: subscription2,
|
|
117
146
|
contextManager,
|
|
@@ -122,7 +151,7 @@ function useCoValueSubscription(Schema, id, options) {
|
|
|
122
151
|
agent
|
|
123
152
|
};
|
|
124
153
|
};
|
|
125
|
-
const subscriptionRef =
|
|
154
|
+
const subscriptionRef = React2.useRef(null);
|
|
126
155
|
if (!subscriptionRef.current) {
|
|
127
156
|
subscriptionRef.current = createSubscription();
|
|
128
157
|
}
|
|
@@ -130,7 +159,6 @@ function useCoValueSubscription(Schema, id, options) {
|
|
|
130
159
|
const branchOwnerId = options?.unstable_branch?.owner?.$jazz.id;
|
|
131
160
|
let subscription = subscriptionRef.current;
|
|
132
161
|
if (subscription.contextManager !== contextManager || subscription.id !== id || subscription.Schema !== Schema || subscription.branchName !== branchName || subscription.branchOwnerId !== branchOwnerId || subscription.agent !== agent) {
|
|
133
|
-
subscription.value?.destroy();
|
|
134
162
|
subscriptionRef.current = createSubscription();
|
|
135
163
|
subscription = subscriptionRef.current;
|
|
136
164
|
}
|
|
@@ -161,7 +189,7 @@ function useCoState(Schema, id, options) {
|
|
|
161
189
|
const subscription = useCoValueSubscription(Schema, id, options);
|
|
162
190
|
const getCurrentValue = useGetCurrentValue(subscription);
|
|
163
191
|
const value = useSyncExternalStoreWithSelector(
|
|
164
|
-
|
|
192
|
+
React2.useCallback(
|
|
165
193
|
(callback) => {
|
|
166
194
|
if (!subscription) {
|
|
167
195
|
return () => {
|
|
@@ -178,10 +206,38 @@ function useCoState(Schema, id, options) {
|
|
|
178
206
|
);
|
|
179
207
|
return value;
|
|
180
208
|
}
|
|
209
|
+
function useSuspenseCoState(Schema, id, options) {
|
|
210
|
+
useImportCoValueContent(id, options?.preloaded);
|
|
211
|
+
const subscription = useCoValueSubscription(Schema, id, options);
|
|
212
|
+
if (!subscription) {
|
|
213
|
+
throw new Error("Subscription not found");
|
|
214
|
+
}
|
|
215
|
+
use(subscription.getPromise());
|
|
216
|
+
const getCurrentValue = () => {
|
|
217
|
+
const value2 = subscription.getCurrentValue();
|
|
218
|
+
if (!value2.$isLoaded) {
|
|
219
|
+
throw new Error("CoValue must be loaded in a suspense context");
|
|
220
|
+
}
|
|
221
|
+
return value2;
|
|
222
|
+
};
|
|
223
|
+
const value = useSyncExternalStoreWithSelector(
|
|
224
|
+
React2.useCallback(
|
|
225
|
+
(callback) => {
|
|
226
|
+
return subscription.subscribe(callback);
|
|
227
|
+
},
|
|
228
|
+
[subscription]
|
|
229
|
+
),
|
|
230
|
+
getCurrentValue,
|
|
231
|
+
getCurrentValue,
|
|
232
|
+
options?.select ?? ((value2) => value2),
|
|
233
|
+
options?.equalityFn ?? Object.is
|
|
234
|
+
);
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
181
237
|
function useSubscriptionSelector(subscription, options) {
|
|
182
238
|
const getCurrentValue = useGetCurrentValue(subscription);
|
|
183
239
|
return useSyncExternalStoreWithSelector(
|
|
184
|
-
|
|
240
|
+
React2.useCallback(
|
|
185
241
|
(callback) => {
|
|
186
242
|
if (!subscription) {
|
|
187
243
|
return () => {
|
|
@@ -199,7 +255,7 @@ function useSubscriptionSelector(subscription, options) {
|
|
|
199
255
|
}
|
|
200
256
|
function useAccountSubscription(Schema, options) {
|
|
201
257
|
const contextManager = useJazzContextManager();
|
|
202
|
-
const callerStack =
|
|
258
|
+
const callerStack = React2.useRef(void 0);
|
|
203
259
|
if (!callerStack.current) {
|
|
204
260
|
callerStack.current = captureStack();
|
|
205
261
|
}
|
|
@@ -214,19 +270,19 @@ function useAccountSubscription(Schema, options) {
|
|
|
214
270
|
}
|
|
215
271
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
216
272
|
const node = contextManager.getCurrentValue().node;
|
|
217
|
-
const
|
|
273
|
+
const cache = contextManager.getSubscriptionScopeCache();
|
|
274
|
+
const subscription2 = cache.getOrCreate(
|
|
218
275
|
node,
|
|
219
|
-
|
|
276
|
+
Schema,
|
|
220
277
|
agent.$jazz.id,
|
|
221
|
-
|
|
222
|
-
ref: coValueClassFromCoValueClassOrSchema(Schema),
|
|
223
|
-
optional: true
|
|
224
|
-
},
|
|
278
|
+
resolve,
|
|
225
279
|
false,
|
|
226
280
|
false,
|
|
227
|
-
options?.unstable_branch
|
|
228
|
-
callerStack.current
|
|
281
|
+
options?.unstable_branch
|
|
229
282
|
);
|
|
283
|
+
if (callerStack.current) {
|
|
284
|
+
subscription2.callerStack = callerStack.current;
|
|
285
|
+
}
|
|
230
286
|
return {
|
|
231
287
|
subscription: subscription2,
|
|
232
288
|
contextManager,
|
|
@@ -235,16 +291,14 @@ function useAccountSubscription(Schema, options) {
|
|
|
235
291
|
branchOwnerId: options?.unstable_branch?.owner?.$jazz.id
|
|
236
292
|
};
|
|
237
293
|
};
|
|
238
|
-
const [subscription, setSubscription] =
|
|
294
|
+
const [subscription, setSubscription] = React2.useState(createSubscription);
|
|
239
295
|
const branchName = options?.unstable_branch?.name;
|
|
240
296
|
const branchOwnerId = options?.unstable_branch?.owner?.$jazz.id;
|
|
241
|
-
|
|
297
|
+
React2.useLayoutEffect(() => {
|
|
242
298
|
if (subscription.contextManager !== contextManager || subscription.Schema !== Schema || subscription.branchName !== options?.unstable_branch?.name || subscription.branchOwnerId !== options?.unstable_branch?.owner?.$jazz.id) {
|
|
243
|
-
subscription.subscription?.destroy();
|
|
244
299
|
setSubscription(createSubscription());
|
|
245
300
|
}
|
|
246
301
|
return contextManager.subscribe(() => {
|
|
247
|
-
subscription.subscription?.destroy();
|
|
248
302
|
setSubscription(createSubscription());
|
|
249
303
|
});
|
|
250
304
|
}, [Schema, contextManager, branchName, branchOwnerId]);
|
|
@@ -254,7 +308,39 @@ function useAccount(AccountSchema = Account, options) {
|
|
|
254
308
|
const subscription = useAccountSubscription(AccountSchema, options);
|
|
255
309
|
const getCurrentValue = useGetCurrentValue(subscription);
|
|
256
310
|
return useSyncExternalStoreWithSelector(
|
|
257
|
-
|
|
311
|
+
React2.useCallback(
|
|
312
|
+
(callback) => {
|
|
313
|
+
if (!subscription) {
|
|
314
|
+
return () => {
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return subscription.subscribe(callback);
|
|
318
|
+
},
|
|
319
|
+
[subscription]
|
|
320
|
+
),
|
|
321
|
+
getCurrentValue,
|
|
322
|
+
getCurrentValue,
|
|
323
|
+
options?.select ?? ((value) => value),
|
|
324
|
+
options?.equalityFn ?? Object.is
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
function useSuspenseAccount(AccountSchema = Account, options) {
|
|
328
|
+
const subscription = useAccountSubscription(AccountSchema, options);
|
|
329
|
+
if (!subscription) {
|
|
330
|
+
throw new Error(
|
|
331
|
+
"Subscription not found, are you using useSuspenseAccount in guest mode?"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
use(subscription.getPromise());
|
|
335
|
+
const getCurrentValue = () => {
|
|
336
|
+
const value = subscription.getCurrentValue();
|
|
337
|
+
if (!value.$isLoaded) {
|
|
338
|
+
throw new Error("Account must be loaded in a suspense context");
|
|
339
|
+
}
|
|
340
|
+
return value;
|
|
341
|
+
};
|
|
342
|
+
return useSyncExternalStoreWithSelector(
|
|
343
|
+
React2.useCallback(
|
|
258
344
|
(callback) => {
|
|
259
345
|
if (!subscription) {
|
|
260
346
|
return () => {
|
|
@@ -277,7 +363,7 @@ function useLogOut() {
|
|
|
277
363
|
function useAgent() {
|
|
278
364
|
const contextManager = useJazzContextManager();
|
|
279
365
|
const getCurrentValue = () => getCurrentAccountFromContextManager(contextManager);
|
|
280
|
-
return
|
|
366
|
+
return React2.useSyncExternalStore(
|
|
281
367
|
useCallback(
|
|
282
368
|
(callback) => {
|
|
283
369
|
return contextManager.subscribe(callback);
|
|
@@ -341,13 +427,13 @@ function getResolveQuery(Schema, resolveQuery) {
|
|
|
341
427
|
}
|
|
342
428
|
|
|
343
429
|
// src/react-core/subscription-provider.tsx
|
|
344
|
-
import
|
|
430
|
+
import React3 from "react";
|
|
345
431
|
import {
|
|
346
432
|
CoValueLoadingState as CoValueLoadingState2
|
|
347
433
|
} from "jazz-tools";
|
|
348
434
|
import { jsx } from "react/jsx-runtime";
|
|
349
435
|
function createCoValueSubscriptionContext(schema, resolve) {
|
|
350
|
-
const Context =
|
|
436
|
+
const Context = React3.createContext(null);
|
|
351
437
|
return {
|
|
352
438
|
Provider: ({
|
|
353
439
|
id,
|
|
@@ -372,7 +458,7 @@ function createCoValueSubscriptionContext(schema, resolve) {
|
|
|
372
458
|
return /* @__PURE__ */ jsx(Context.Provider, { value: subscription, children });
|
|
373
459
|
},
|
|
374
460
|
useSelector: (options) => {
|
|
375
|
-
const subscription =
|
|
461
|
+
const subscription = React3.useContext(Context);
|
|
376
462
|
if (!subscription) {
|
|
377
463
|
throw new Error(
|
|
378
464
|
"useSelector must be used within a coValue subscription provider"
|
|
@@ -386,7 +472,7 @@ function createCoValueSubscriptionContext(schema, resolve) {
|
|
|
386
472
|
};
|
|
387
473
|
}
|
|
388
474
|
function createAccountSubscriptionContext(schema, resolve) {
|
|
389
|
-
const Context =
|
|
475
|
+
const Context = React3.createContext(null);
|
|
390
476
|
return {
|
|
391
477
|
Provider: ({
|
|
392
478
|
options,
|
|
@@ -410,7 +496,7 @@ function createAccountSubscriptionContext(schema, resolve) {
|
|
|
410
496
|
return /* @__PURE__ */ jsx(Context.Provider, { value: subscription, children });
|
|
411
497
|
},
|
|
412
498
|
useSelector: (options) => {
|
|
413
|
-
const subscription =
|
|
499
|
+
const subscription = React3.useContext(Context);
|
|
414
500
|
if (!subscription) {
|
|
415
501
|
throw new Error(
|
|
416
502
|
"useSelector must be used within an account subscription provider"
|
|
@@ -511,6 +597,8 @@ export {
|
|
|
511
597
|
useLogOut,
|
|
512
598
|
usePassphraseAuth,
|
|
513
599
|
useSubscriptionSelector,
|
|
600
|
+
useSuspenseAccount,
|
|
601
|
+
useSuspenseCoState,
|
|
514
602
|
useSyncConnectionStatus
|
|
515
603
|
};
|
|
516
604
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-core/hooks.ts","../../src/react-core/utils.ts","../../src/react-core/subscription-provider.tsx","../../src/react-core/auth/DemoAuth.tsx","../../src/react-core/auth/PassphraseAuth.tsx"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from \"use-sync-external-store/shim/with-selector\";\nimport React, {\n useCallback,\n useContext,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\n\nimport {\n Account,\n AccountClass,\n AnonymousJazzAgent,\n AnyAccountSchema,\n CoValue,\n CoValueClassOrSchema,\n CoValueLoadingState,\n ExportedCoValue,\n InboxSender,\n InstanceOfSchema,\n JazzContextManager,\n JazzContextType,\n Loaded,\n MaybeLoaded,\n NotLoaded,\n ResolveQuery,\n ResolveQueryStrict,\n SchemaResolveQuery,\n SubscriptionScope,\n coValueClassFromCoValueClassOrSchema,\n importContentPieces,\n captureStack,\n getUnloadedCoValueWithoutId,\n type BranchDefinition,\n} from \"jazz-tools\";\nimport { JazzContext, JazzContextManagerContext } from \"./provider.js\";\nimport { getCurrentAccountFromContextManager } from \"./utils.js\";\nimport { CoValueSubscription } from \"./types.js\";\n\nexport function useJazzContext<Acc extends Account>() {\n const value = useContext(JazzContext) as JazzContextType<Acc>;\n\n if (!value) {\n throw new Error(\n \"You need to set up a JazzProvider on top of your app to use this hook.\",\n );\n }\n\n return value;\n}\n\nexport function useJazzContextManager<Acc extends Account>() {\n const value = useContext(JazzContextManagerContext) as JazzContextManager<\n Acc,\n {}\n >;\n\n if (!value) {\n throw new Error(\n \"You need to set up a JazzProvider on top of your app to use this hook.\",\n );\n }\n\n return value;\n}\n\nexport function useAuthSecretStorage() {\n const value = useContext(JazzContextManagerContext);\n\n if (!value) {\n throw new Error(\n \"You need to set up a JazzProvider on top of your app to use this useAuthSecretStorage.\",\n );\n }\n\n return value.getAuthSecretStorage();\n}\n\nexport function useIsAuthenticated() {\n const authSecretStorage = useAuthSecretStorage();\n\n return useSyncExternalStore(\n useCallback(\n (callback) => {\n return authSecretStorage.onUpdate(callback);\n },\n [authSecretStorage],\n ),\n () => authSecretStorage.isAuthenticated,\n () => authSecretStorage.isAuthenticated,\n );\n}\n\nexport function useCoValueSubscription<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n>(\n Schema: S,\n id: string | undefined | null,\n options?: {\n resolve?: ResolveQueryStrict<S, R>;\n unstable_branch?: BranchDefinition;\n },\n) {\n const contextManager = useJazzContextManager();\n const agent = useAgent();\n\n const callerStack = React.useRef<Error | undefined>(undefined);\n\n if (!callerStack.current) {\n callerStack.current = captureStack();\n }\n\n const createSubscription = () => {\n if (!id) {\n return {\n subscription: null,\n contextManager,\n id,\n Schema,\n };\n }\n\n if (options?.unstable_branch?.owner === null) {\n return {\n subscription: null,\n contextManager,\n id,\n Schema,\n };\n }\n\n const resolve = getResolveQuery(Schema, options?.resolve);\n\n const node = contextManager.getCurrentValue()!.node;\n const subscription = new SubscriptionScope<any>(\n node,\n resolve,\n id,\n {\n ref: coValueClassFromCoValueClassOrSchema(Schema),\n optional: true,\n },\n false,\n false,\n options?.unstable_branch,\n callerStack.current,\n );\n\n return {\n value: subscription,\n contextManager,\n id,\n Schema,\n branchName: options?.unstable_branch?.name,\n branchOwnerId: options?.unstable_branch?.owner?.$jazz.id,\n agent,\n };\n };\n\n const subscriptionRef = React.useRef<null | ReturnType<\n typeof createSubscription\n >>(null);\n\n if (!subscriptionRef.current) {\n subscriptionRef.current = createSubscription();\n }\n\n const branchName = options?.unstable_branch?.name;\n const branchOwnerId = options?.unstable_branch?.owner?.$jazz.id;\n\n let subscription = subscriptionRef.current;\n\n // Check if the subscription needs to be updated\n // because one of the dependencies has changed\n if (\n subscription.contextManager !== contextManager ||\n subscription.id !== id ||\n subscription.Schema !== Schema ||\n subscription.branchName !== branchName ||\n subscription.branchOwnerId !== branchOwnerId ||\n subscription.agent !== agent\n ) {\n subscription.value?.destroy();\n subscriptionRef.current = createSubscription();\n subscription = subscriptionRef.current;\n }\n\n // Subscribe to the context manager to react to auth changes\n return subscription.value as CoValueSubscription<S, R>;\n}\n\nfunction useImportCoValueContent<V>(\n id: string | undefined | null,\n content?: ExportedCoValue<V>,\n) {\n const agent = useAgent();\n const preloadExecuted = useRef<typeof agent | null>(null);\n if (content && preloadExecuted.current !== agent && id) {\n if (content.id === id) {\n importContentPieces(content.contentPieces, agent);\n } else {\n console.warn(\"Preloaded value ID does not match the subscription ID\");\n }\n\n preloadExecuted.current = agent;\n }\n}\n\nfunction useGetCurrentValue<C extends CoValue>(\n subscription: SubscriptionScope<C> | null,\n) {\n return useCallback(() => {\n if (!subscription) {\n return getUnloadedCoValueWithoutId(CoValueLoadingState.UNAVAILABLE);\n }\n\n return subscription.getCurrentValue();\n }, [subscription]);\n}\n\n/**\n * React hook for subscribing to CoValues and handling loading states.\n *\n * This hook provides a convenient way to subscribe to CoValues and automatically\n * handles the subscription lifecycle (subscribe on mount, unsubscribe on unmount).\n * It also supports deep loading of nested CoValues through resolve queries.\n *\n * The {@param options.select} function allows returning only specific parts of the CoValue data,\n * which helps reduce unnecessary re-renders by narrowing down the returned data.\n * Additionally, you can provide a custom {@param options.equalityFn} to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * @returns The loaded CoValue, or an {@link NotLoaded} value. Use `$isLoaded` to check whether the\n * CoValue is loaded, or use {@link MaybeLoaded.$jazz.loadingState} to get the detailed loading state.\n * If a selector function is provided, returns the result of the selector function.\n *\n * @example\n * ```tsx\n * // Select only specific fields to reduce re-renders\n * const Project = co.map({\n * name: z.string(),\n * description: z.string(),\n * tasks: co.list(Task),\n * lastModified: z.date(),\n * });\n *\n * function ProjectTitle({ projectId }: { projectId: string }) {\n * // Only re-render when the project name changes, not other fields\n * const projectName = useCoState(\n * Project,\n * projectId,\n * {\n * select: (project) => !project.$isLoading ? project.name : \"Loading...\",\n * }\n * );\n *\n * return <h1>{projectName}</h1>;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Deep loading with resolve queries\n * const Project = co.map({\n * name: z.string(),\n * tasks: co.list(Task),\n * owner: TeamMember,\n * });\n *\n * function ProjectView({ projectId }: { projectId: string }) {\n * const project = useCoState(Project, projectId, {\n * resolve: {\n * tasks: { $each: true },\n * owner: true,\n * },\n * });\n *\n * if (!project.$isLoaded) {\n * switch (project.$jazz.loadingState) {\n * case \"unauthorized\":\n * return \"Project not accessible\";\n * case \"unavailable\":\n * return \"Project not found\";\n * case \"loading\":\n * return \"Loading project...\";\n * }\n * }\n *\n * return (\n * <div>\n * <h1>{project.name}</h1>\n * <p>Owner: {project.owner.name}</p>\n * <ul>\n * {project.tasks.map((task) => (\n * <li key={task.id}>{task.title}</li>\n * ))}\n * </ul>\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Using with optional references and error handling\n * const Task = co.map({\n * title: z.string(),\n * assignee: co.optional(TeamMember),\n * subtasks: co.list(Task),\n * });\n *\n * function TaskDetail({ taskId }: { taskId: string }) {\n * const task = useCoState(Task, taskId, {\n * resolve: {\n * assignee: true,\n * subtasks: { $each: { $onError: 'catch' } },\n * },\n * });\n *\n * if (!task.$isLoaded) {\n * switch (task.$jazz.loadingState) {\n * case \"unauthorized\":\n * return \"Task not accessible\";\n * case \"unavailable\":\n * return \"Task not found\";\n * case \"loading\":\n * return \"Loading task...\";\n * }\n * }\n *\n * return (\n * <div>\n * <h2>{task.title}</h2>\n * {task.assignee && <p>Assigned to: {task.assignee.name}</p>}\n * <ul>\n * {task.subtasks.map((subtask, index) => (\n * subtask.$isLoaded ? <li key={subtask.id}>{subtask.title}</li> : <li key={index}>Inaccessible subtask</li>\n * ))}\n * </ul>\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Use custom equality function for complex data structures\n * const TaskList = co.list(Task);\n *\n * function TaskCount({ listId }: { listId: string }) {\n * const taskStats = useCoState(\n * TaskList,\n * listId,\n * {\n * resolve: { $each: true },\n * select: (tasks) => {\n * if (!tasks.$isLoaded) return { total: 0, completed: 0 };\n * return {\n * total: tasks.length,\n * completed: tasks.filter(task => task.completed).length,\n * };\n * },\n * // Custom equality to prevent re-renders when stats haven't changed\n * equalityFn: (a, b) => a.total === b.total && a.completed === b.completed,\n * }\n * );\n *\n * return (\n * <div>\n * {taskStats.completed} of {taskStats.total} tasks completed\n * </div>\n * );\n * }\n * ```\n *\n * For more examples, see the [subscription and deep loading](https://jazz.tools/docs/react/using-covalues/subscription-and-loading) documentation.\n */\nexport function useCoState<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n TSelectorReturn = MaybeLoaded<Loaded<S, R>>,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to. If `undefined`, returns an `unavailable` value */\n id: string | undefined,\n /** Optional configuration for the subscription */\n options?: {\n /** Resolve query to specify which nested CoValues to load */\n resolve?: ResolveQueryStrict<S, R>;\n /** Select which value to return */\n select?: (value: MaybeLoaded<Loaded<S, R>>) => TSelectorReturn;\n /** Equality function to determine if the selected value has changed, defaults to `Object.is` */\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n /**\n * Create or load a branch for isolated editing.\n *\n * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version.\n * It's a fork of your data graph: the same schema, but with diverging values.\n *\n * The checkout of the branch is applied on all the resolved values.\n *\n * @param name - A unique name for the branch. This identifies the branch\n * and can be used to switch between different branches of the same CoValue.\n * @param owner - The owner of the branch. Determines who can access and modify\n * the branch. If not provided, the branch is owned by the current user.\n *\n * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.\n */\n unstable_branch?: BranchDefinition;\n preloaded?: ExportedCoValue<Loaded<S, R>>;\n },\n): TSelectorReturn {\n useImportCoValueContent(id, options?.preloaded);\n\n const subscription = useCoValueSubscription(Schema, id, options);\n const getCurrentValue = useGetCurrentValue(subscription);\n\n const value = useSyncExternalStoreWithSelector<\n MaybeLoaded<Loaded<S, R>>,\n TSelectorReturn\n >(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n\n return value;\n}\n\nexport function useSubscriptionSelector<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n TSelectorReturn = MaybeLoaded<Loaded<S, R>>,\n>(\n subscription: CoValueSubscription<S, R>,\n options?: {\n select?: (value: MaybeLoaded<Loaded<S, R>>) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n },\n) {\n const getCurrentValue = useGetCurrentValue(subscription);\n\n return useSyncExternalStoreWithSelector<\n MaybeLoaded<Loaded<S, R>>,\n TSelectorReturn\n >(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n}\n\nexport function useAccountSubscription<\n S extends AccountClass<Account> | AnyAccountSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n>(\n Schema: S,\n options?: {\n resolve?: ResolveQueryStrict<S, R>;\n unstable_branch?: BranchDefinition;\n },\n) {\n const contextManager = useJazzContextManager();\n\n // Capture stack trace at hook call time\n const callerStack = React.useRef<Error | undefined>(undefined);\n if (!callerStack.current) {\n callerStack.current = captureStack();\n }\n\n const createSubscription = () => {\n const agent = getCurrentAccountFromContextManager(contextManager);\n\n if (agent.$type$ === \"Anonymous\") {\n return {\n subscription: null,\n contextManager,\n agent,\n };\n }\n\n const resolve = getResolveQuery(Schema, options?.resolve);\n\n const node = contextManager.getCurrentValue()!.node;\n const subscription = new SubscriptionScope<any>(\n node,\n resolve,\n agent.$jazz.id,\n {\n ref: coValueClassFromCoValueClassOrSchema(Schema),\n optional: true,\n },\n false,\n false,\n options?.unstable_branch,\n callerStack.current,\n );\n\n return {\n subscription,\n contextManager,\n Schema,\n branchName: options?.unstable_branch?.name,\n branchOwnerId: options?.unstable_branch?.owner?.$jazz.id,\n };\n };\n\n const [subscription, setSubscription] = React.useState(createSubscription);\n\n const branchName = options?.unstable_branch?.name;\n const branchOwnerId = options?.unstable_branch?.owner?.$jazz.id;\n\n React.useLayoutEffect(() => {\n if (\n subscription.contextManager !== contextManager ||\n subscription.Schema !== Schema ||\n subscription.branchName !== options?.unstable_branch?.name ||\n subscription.branchOwnerId !== options?.unstable_branch?.owner?.$jazz.id\n ) {\n subscription.subscription?.destroy();\n setSubscription(createSubscription());\n }\n\n return contextManager.subscribe(() => {\n subscription.subscription?.destroy();\n setSubscription(createSubscription());\n });\n }, [Schema, contextManager, branchName, branchOwnerId]);\n\n return subscription.subscription as CoValueSubscription<S, R>;\n}\n\n/**\n * React hook for accessing the current user's account.\n *\n * This hook provides access to the current user's account profile and root data.\n * It automatically handles the subscription lifecycle and supports deep loading of nested\n * CoValues through resolve queries.\n *\n * The {@param options.select} function allows returning only specific parts of the account data,\n * which helps reduce unnecessary re-renders by narrowing down the returned data.\n * Additionally, you can provide a custom {@param options.equalityFn} to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * @returns The account data, or an {@link NotLoaded} value. Use `$isLoaded` to check whether the\n * CoValue is loaded, or use {@link MaybeLoaded.$jazz.loadingState} to get the detailed loading state.\n * If a selector function is provided, returns the result of the selector function.\n *\n * @example\n * ```tsx\n * // Select only specific fields to reduce re-renders\n * const MyAppAccount = co.account({\n * profile: co.profile(),\n * root: co.map({\n * name: z.string(),\n * email: z.string(),\n * lastLogin: z.date(),\n * }),\n * });\n *\n * function UserProfile({ accountId }: { accountId: string }) {\n * // Only re-render when the profile name changes, not other fields\n * const profileName = useAccount(\n * MyAppAccount,\n * {\n * resolve: {\n * profile: true,\n * root: true,\n * },\n * select: (account) => account.$isLoaded ? account.profile.name : \"Loading...\",\n * }\n * );\n *\n * return <h1>{profileName}</h1>;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Deep loading with resolve queries\n * function ProjectListWithDetails() {\n * const me = useAccount(MyAppAccount, {\n * resolve: {\n * profile: true,\n * root: {\n * myProjects: {\n * $each: {\n * tasks: true,\n * },\n * },\n * },\n * },\n * });\n *\n * if (!me.$isLoaded) {\n * switch (me.$jazz.loadingState) {\n * case \"unauthorized\":\n * return \"Account not accessible\";\n * case \"unavailable\":\n * return \"Account not found\";\n * case \"loading\":\n * return \"Loading account...\";\n * }\n * }\n *\n * return (\n * <div>\n * <h1>{me.profile.name}'s projects</h1>\n * <ul>\n * {me.root.myProjects.map((project) => (\n * <li key={project.id}>\n * {project.name} ({project.tasks.length} tasks)\n * </li>\n * ))}\n * </ul>\n * </div>\n * );\n * }\n * ```\n *\n */\nexport function useAccount<\n A extends AccountClass<Account> | AnyAccountSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<A> = SchemaResolveQuery<A>,\n TSelectorReturn = MaybeLoaded<Loaded<A, R>>,\n>(\n /** The account schema to use. Defaults to the base Account schema */\n AccountSchema: A = Account as unknown as A,\n /** Optional configuration for the subscription */\n options?: {\n /** Resolve query to specify which nested CoValues to load from the account */\n resolve?: ResolveQueryStrict<A, R>;\n /** Select which value to return from the account data */\n select?: (account: MaybeLoaded<Loaded<A, R>>) => TSelectorReturn;\n /** Equality function to determine if the selected value has changed, defaults to `Object.is` */\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n /**\n * Create or load a branch for isolated editing.\n *\n * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version.\n * It's a fork of your data graph: the same schema, but with diverging values.\n *\n * The checkout of the branch is applied on all the resolved values.\n *\n * @param name - A unique name for the branch. This identifies the branch\n * and can be used to switch between different branches of the same CoValue.\n * @param owner - The owner of the branch. Determines who can access and modify\n * the branch. If not provided, the branch is owned by the current user.\n *\n * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.\n */\n unstable_branch?: BranchDefinition;\n },\n): TSelectorReturn {\n const subscription = useAccountSubscription(AccountSchema, options);\n const getCurrentValue = useGetCurrentValue(subscription);\n\n return useSyncExternalStoreWithSelector<\n MaybeLoaded<Loaded<A, R>>,\n TSelectorReturn\n >(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n}\n\n/**\n * Returns a function for logging out of the current account.\n */\nexport function useLogOut(): () => void {\n const contextManager = useJazzContextManager();\n return contextManager.logOut;\n}\n\n/**\n * React hook for accessing the current agent. An agent can either be:\n * - an Authenticated Account, if the user is logged in\n * - an Anonymous Account, if the user didn't log in\n * - or an anonymous agent, if in guest mode\n *\n * The agent can be used as the `loadAs` parameter for load and subscribe methods.\n */\nexport function useAgent<\n A extends AccountClass<Account> | AnyAccountSchema = typeof Account,\n>(): AnonymousJazzAgent | Loaded<A, true> {\n const contextManager = useJazzContextManager<InstanceOfSchema<A>>();\n\n const getCurrentValue = () =>\n getCurrentAccountFromContextManager(contextManager) as\n | AnonymousJazzAgent\n | Loaded<A, true>;\n\n return React.useSyncExternalStore(\n useCallback(\n (callback) => {\n return contextManager.subscribe(callback);\n },\n [contextManager],\n ),\n getCurrentValue,\n getCurrentValue,\n );\n}\n\nexport function experimental_useInboxSender<\n I extends CoValue,\n O extends CoValue | undefined,\n>(inboxOwnerID: string | undefined) {\n const context = useJazzContext();\n\n if (!(\"me\" in context)) {\n throw new Error(\n \"useInboxSender can't be used in a JazzProvider with auth === 'guest'.\",\n );\n }\n\n const me = context.me;\n const inboxRef = useRef<Promise<InboxSender<I, O>> | undefined>(undefined);\n\n const sendMessage = useCallback(\n async (message: I) => {\n if (!inboxOwnerID) throw new Error(\"Inbox owner ID is required\");\n\n if (!inboxRef.current) {\n const inbox = InboxSender.load<I, O>(inboxOwnerID, me);\n inboxRef.current = inbox;\n }\n\n let inbox = await inboxRef.current;\n\n // Regenerate the InboxSender if the inbox owner or current account changes\n if (inbox.owner.id !== inboxOwnerID || inbox.currentAccount !== me) {\n const req = InboxSender.load<I, O>(inboxOwnerID, me);\n inboxRef.current = req;\n inbox = await req;\n }\n\n return inbox.sendMessage(message);\n },\n [inboxOwnerID, me.$jazz.id],\n );\n\n return sendMessage;\n}\n\n/**\n * Hook that returns the current connection status to the Jazz sync server.\n *\n * @returns `true` when connected to the server, `false` when disconnected\n *\n * @remarks\n * On connection drop, this hook will return `false` only when Jazz detects the disconnection\n * after 5 seconds of not receiving a ping from the server.\n */\nexport function useSyncConnectionStatus() {\n const context = useJazzContext();\n\n const connected = useSyncExternalStore(\n useCallback(\n (callback) => {\n return context.addConnectionListener(callback);\n },\n [context],\n ),\n () => context.connected(),\n () => context.connected(),\n );\n\n return connected;\n}\n\nfunction getResolveQuery(\n Schema: CoValueClassOrSchema,\n // We don't need type validation here, since this is an internal API\n resolveQuery?: ResolveQuery<any>,\n): ResolveQuery<any> {\n if (resolveQuery) {\n return resolveQuery;\n }\n // Check the schema is a CoValue schema (and not a CoValue class)\n if (\"resolveQuery\" in Schema) {\n return Schema.resolveQuery;\n }\n return true;\n}\n","import { Account, JazzContextManager } from \"jazz-tools\";\n\nexport function getCurrentAccountFromContextManager<Acc extends Account>(\n contextManager: JazzContextManager<Acc, any>,\n) {\n const context = contextManager.getCurrentValue();\n\n if (!context) {\n throw new Error(\"No context found\");\n }\n\n return \"me\" in context ? context.me : context.guest;\n}\n\nexport function subscribeToContextManager<Acc extends Account>(\n contextManager: JazzContextManager<Acc, any>,\n callback: () => () => void,\n) {\n let unsub = () => {};\n\n const handler = () => {\n unsub();\n unsub = callback();\n };\n\n handler();\n return contextManager.subscribe(handler);\n}\n","import React from \"react\";\nimport {\n Account,\n AccountClass,\n AnyAccountSchema,\n CoValueClassOrSchema,\n CoValueLoadingState,\n Loaded,\n MaybeLoaded,\n ResolveQuery,\n ResolveQueryStrict,\n} from \"jazz-tools\";\nimport {\n useAccountSubscription,\n useCoValueSubscription,\n useSubscriptionSelector,\n} from \"./hooks.js\";\nimport type { CoValueSubscription } from \"./types.js\";\n\nexport function createCoValueSubscriptionContext<\n S extends CoValueClassOrSchema,\n const R extends ResolveQuery<S> = true,\n>(schema: S, resolve?: ResolveQueryStrict<S, R>) {\n const Context = React.createContext<CoValueSubscription<S, R>>(null);\n\n return {\n Provider: ({\n id,\n options,\n loadingFallback,\n unavailableFallback,\n children,\n }: React.PropsWithChildren<{\n id: string | undefined | null;\n options?: Omit<\n Parameters<typeof useCoValueSubscription<S, R>>[2],\n \"resolve\"\n >;\n loadingFallback?: React.ReactNode;\n unavailableFallback?: React.ReactNode;\n }>) => {\n const subscription = useCoValueSubscription(schema, id, {\n ...options,\n resolve: resolve,\n });\n\n const loadState = useSubscriptionSelector(subscription, {\n select: (value) => value.$jazz.loadingState,\n });\n\n if (loadState === CoValueLoadingState.LOADING) {\n return loadingFallback ?? null;\n }\n if (\n loadState === CoValueLoadingState.UNAUTHORIZED ||\n loadState === CoValueLoadingState.UNAVAILABLE\n ) {\n return unavailableFallback ?? null;\n }\n\n return (\n <Context.Provider value={subscription}>{children}</Context.Provider>\n );\n },\n useSelector: <TSelectorReturn = Loaded<S, R>>(options?: {\n select?: (value: Loaded<S, R>) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n }) => {\n const subscription = React.useContext(Context);\n\n if (!subscription) {\n throw new Error(\n \"useSelector must be used within a coValue subscription provider\",\n );\n }\n\n return useSubscriptionSelector<S, R, TSelectorReturn>(\n subscription,\n options as Parameters<\n typeof useSubscriptionSelector<S, R, TSelectorReturn>\n >[1],\n );\n },\n };\n}\n\nexport function createAccountSubscriptionContext<\n A extends AccountClass<Account> | AnyAccountSchema,\n const R extends ResolveQuery<A> = true,\n>(schema: A, resolve?: ResolveQueryStrict<A, R>) {\n const Context = React.createContext<CoValueSubscription<A, R>>(null);\n\n return {\n Provider: ({\n options,\n loadingFallback,\n unavailableFallback,\n children,\n }: React.PropsWithChildren<{\n options?: Omit<\n Parameters<typeof useAccountSubscription<A, R>>[1],\n \"resolve\"\n >;\n loadingFallback?: React.ReactNode;\n unavailableFallback?: React.ReactNode;\n }>) => {\n const subscription = useAccountSubscription(schema, {\n ...options,\n resolve: resolve,\n });\n\n const loadState = useSubscriptionSelector(subscription, {\n select: (value) => value.$jazz.loadingState,\n });\n\n if (loadState === CoValueLoadingState.LOADING) {\n return loadingFallback ?? null;\n }\n\n if (\n loadState === CoValueLoadingState.UNAUTHORIZED ||\n loadState === CoValueLoadingState.UNAVAILABLE\n ) {\n return unavailableFallback ?? null;\n }\n\n return (\n <Context.Provider value={subscription}>{children}</Context.Provider>\n );\n },\n useSelector: <TSelectorReturn = Loaded<A, R>>(options?: {\n select?: (value: Loaded<A, R>) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n }) => {\n const subscription = React.useContext(Context);\n\n if (!subscription) {\n throw new Error(\n \"useSelector must be used within an account subscription provider\",\n );\n }\n\n return useSubscriptionSelector<A, R, TSelectorReturn>(\n subscription,\n options as Parameters<\n typeof useSubscriptionSelector<A, R, TSelectorReturn>\n >[1],\n );\n },\n };\n}\n","import { DemoAuth } from \"jazz-tools\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useAuthSecretStorage, useJazzContext } from \"../hooks.js\";\nimport { useIsAuthenticated } from \"../hooks.js\";\n\n/**\n * `useDemoAuth` is a hook that provides a `JazzAuth` object for demo authentication.\n *\n *\n * ```ts\n * const { state, logIn, signUp, existingUsers } = useDemoAuth();\n * ```\n *\n * @category Auth Providers\n */\nexport function useDemoAuth() {\n const context = useJazzContext();\n const authSecretStorage = useAuthSecretStorage();\n\n if (\"guest\" in context) {\n throw new Error(\"Demo auth is not supported in guest mode\");\n }\n\n const authMethod = useMemo(() => {\n return new DemoAuth(context.authenticate, authSecretStorage);\n }, []);\n\n const isAuthenticated = useIsAuthenticated();\n const [existingUsers, setExistingUsers] = useState<string[]>([]);\n\n useEffect(() => {\n authMethod.getExistingUsers().then(setExistingUsers);\n }, [authMethod]);\n\n function handleSignUp(username: string) {\n return authMethod.signUp(username).then(() => {\n setExistingUsers(existingUsers.concat([username]));\n });\n }\n\n return {\n state: isAuthenticated ? \"signedIn\" : \"anonymous\",\n logIn: authMethod.logIn,\n signUp: handleSignUp,\n existingUsers,\n } as const;\n}\n","import { PassphraseAuth } from \"jazz-tools\";\nimport { useCallback, useMemo, useSyncExternalStore } from \"react\";\nimport { useAuthSecretStorage, useJazzContext } from \"../hooks.js\";\nimport { useIsAuthenticated } from \"../hooks.js\";\n\n/**\n * `usePassphraseAuth` hook provides a `JazzAuth` object for passphrase authentication.\n *\n * @example\n * ```ts\n * const auth = usePassphraseAuth({ appName, appHostname, wordlist });\n * ```\n *\n * @category Auth Providers\n */\nexport function usePassphraseAuth({ wordlist }: { wordlist: string[] }) {\n const context = useJazzContext();\n const authSecretStorage = useAuthSecretStorage();\n\n if (\"guest\" in context) {\n throw new Error(\"Passphrase auth is not supported in guest mode\");\n }\n\n const authMethod = useMemo(() => {\n return new PassphraseAuth(\n context.node.crypto,\n context.authenticate,\n context.register,\n authSecretStorage,\n wordlist,\n );\n }, [wordlist]);\n\n const passphrase = useSyncExternalStore(\n useCallback(\n (callback) => {\n authMethod.loadCurrentAccountPassphrase();\n return authMethod.subscribe(callback);\n },\n [authMethod],\n ),\n () => authMethod.passphrase,\n );\n\n const isAuthenticated = useIsAuthenticated();\n return {\n state: isAuthenticated ? \"signedIn\" : \"anonymous\",\n logIn: authMethod.logIn,\n signUp: authMethod.signUp,\n registerNewAccount: authMethod.registerNewAccount,\n generateRandomPassphrase: authMethod.generateRandomPassphrase,\n passphrase,\n } as const;\n}\n"],"mappings":";;;;;;;AAAA,SAAS,wCAAwC;AACjD,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EAMA;AAAA,EAEA;AAAA,EAUA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;AChCA,SAAS,oCACd,gBACA;AACA,QAAM,UAAU,eAAe,gBAAgB;AAE/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AAEA,SAAO,QAAQ,UAAU,QAAQ,KAAK,QAAQ;AAChD;;;AD2BO,SAAS,iBAAsC;AACpD,QAAM,QAAQ,WAAW,WAAW;AAEpC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,wBAA6C;AAC3D,QAAM,QAAQ,WAAW,yBAAyB;AAKlD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,uBAAuB;AACrC,QAAM,QAAQ,WAAW,yBAAyB;AAElD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,qBAAqB;AACpC;AAEO,SAAS,qBAAqB;AACnC,QAAM,oBAAoB,qBAAqB;AAE/C,SAAO;AAAA,IACL;AAAA,MACE,CAAC,aAAa;AACZ,eAAO,kBAAkB,SAAS,QAAQ;AAAA,MAC5C;AAAA,MACA,CAAC,iBAAiB;AAAA,IACpB;AAAA,IACA,MAAM,kBAAkB;AAAA,IACxB,MAAM,kBAAkB;AAAA,EAC1B;AACF;AAEO,SAAS,uBAKd,QACA,IACA,SAIA;AACA,QAAM,iBAAiB,s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AAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,QAAM,aAAaC;AAAA,IACjBC;AAAA,MACE,CAAC,aAAa;AACZ,mBAAW,6BAA6B;AACxC,eAAO,WAAW,UAAU,QAAQ;AAAA,MACtC;AAAA,MACA,CAAC,UAAU;AAAA,IACb;AAAA,IACA,MAAM,WAAW;AAAA,EACnB;AAEA,QAAM,kBAAkB,mBAAmB;AAC3C,SAAO;AAAA,IACL,OAAO,kBAAkB,aAAa;AAAA,IACtC,OAAO,WAAW;AAAA,IAClB,QAAQ,WAAW;AAAA,IACnB,oBAAoB,WAAW;AAAA,IAC/B,0BAA0B,WAAW;AAAA,IACrC;AAAA,EACF;AACF;","names":["subscription","value","inbox","React","CoValueLoadingState","React","CoValueLoadingState","useMemo","useMemo","useCallback","useMemo","useSyncExternalStore","useMemo","useSyncExternalStore","useCallback"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react-core/hooks.ts","../../src/react-core/utils.ts","../../src/react-core/use.ts","../../src/react-core/subscription-provider.tsx","../../src/react-core/auth/DemoAuth.tsx","../../src/react-core/auth/PassphraseAuth.tsx"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from \"use-sync-external-store/shim/with-selector\";\nimport React, {\n useCallback,\n useContext,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from \"react\";\n\nimport {\n Account,\n AccountClass,\n AnonymousJazzAgent,\n AnyAccountSchema,\n CoValue,\n CoValueClassOrSchema,\n CoValueLoadingState,\n ExportedCoValue,\n InboxSender,\n InstanceOfSchema,\n JazzContextManager,\n JazzContextType,\n Loaded,\n MaybeLoaded,\n NotLoaded,\n RefsToResolve,\n ResolveQuery,\n ResolveQueryStrict,\n SchemaResolveQuery,\n SubscriptionScope,\n importContentPieces,\n captureStack,\n getUnloadedCoValueWithoutId,\n type BranchDefinition,\n} from \"jazz-tools\";\nimport { JazzContext, JazzContextManagerContext } from \"./provider.js\";\nimport { getCurrentAccountFromContextManager } from \"./utils.js\";\nimport { CoValueSubscription } from \"./types.js\";\nimport { use } from \"./use.js\";\n\nexport function useJazzContext<Acc extends Account>() {\n const value = useContext(JazzContext) as JazzContextType<Acc>;\n\n if (!value) {\n throw new Error(\n \"You need to set up a JazzProvider on top of your app to use this hook.\",\n );\n }\n\n return value;\n}\n\nexport function useJazzContextManager<Acc extends Account>() {\n const value = useContext(JazzContextManagerContext) as JazzContextManager<\n Acc,\n {}\n >;\n\n if (!value) {\n throw new Error(\n \"You need to set up a JazzProvider on top of your app to use this hook.\",\n );\n }\n\n return value;\n}\n\nexport function useAuthSecretStorage() {\n const value = useContext(JazzContextManagerContext);\n\n if (!value) {\n throw new Error(\n \"You need to set up a JazzProvider on top of your app to use this useAuthSecretStorage.\",\n );\n }\n\n return value.getAuthSecretStorage();\n}\n\nexport function useIsAuthenticated() {\n const authSecretStorage = useAuthSecretStorage();\n\n return useSyncExternalStore(\n useCallback(\n (callback) => {\n return authSecretStorage.onUpdate(callback);\n },\n [authSecretStorage],\n ),\n () => authSecretStorage.isAuthenticated,\n () => authSecretStorage.isAuthenticated,\n );\n}\n\nexport function useCoValueSubscription<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n>(\n Schema: S,\n id: string | undefined | null,\n options?: {\n resolve?: ResolveQueryStrict<S, R>;\n unstable_branch?: BranchDefinition;\n },\n) {\n const contextManager = useJazzContextManager();\n const agent = useAgent();\n\n const callerStack = React.useRef<Error | undefined>(undefined);\n\n if (!callerStack.current) {\n callerStack.current = captureStack();\n }\n\n const createSubscription = () => {\n if (!id) {\n return {\n subscription: null,\n contextManager,\n id,\n Schema,\n };\n }\n\n if (options?.unstable_branch?.owner === null) {\n return {\n subscription: null,\n contextManager,\n id,\n Schema,\n };\n }\n\n const resolve = getResolveQuery(Schema, options?.resolve);\n\n const node = contextManager.getCurrentValue()!.node;\n const cache = contextManager.getSubscriptionScopeCache();\n const subscription = cache.getOrCreate(\n node,\n Schema,\n id,\n resolve,\n false,\n false,\n options?.unstable_branch,\n );\n\n // Set callerStack on returned subscription after retrieval\n if (callerStack.current) {\n subscription.callerStack = callerStack.current;\n }\n\n return {\n value: subscription,\n contextManager,\n id,\n Schema,\n branchName: options?.unstable_branch?.name,\n branchOwnerId: options?.unstable_branch?.owner?.$jazz.id,\n agent,\n };\n };\n\n const subscriptionRef = React.useRef<null | ReturnType<\n typeof createSubscription\n >>(null);\n\n if (!subscriptionRef.current) {\n subscriptionRef.current = createSubscription();\n }\n\n const branchName = options?.unstable_branch?.name;\n const branchOwnerId = options?.unstable_branch?.owner?.$jazz.id;\n\n let subscription = subscriptionRef.current;\n\n // Check if the subscription needs to be updated\n // because one of the dependencies has changed\n if (\n subscription.contextManager !== contextManager ||\n subscription.id !== id ||\n subscription.Schema !== Schema ||\n subscription.branchName !== branchName ||\n subscription.branchOwnerId !== branchOwnerId ||\n subscription.agent !== agent\n ) {\n subscriptionRef.current = createSubscription();\n subscription = subscriptionRef.current;\n }\n\n // Subscribe to the context manager to react to auth changes\n return subscription.value as CoValueSubscription<S, R>;\n}\n\nfunction useImportCoValueContent<V>(\n id: string | undefined | null,\n content?: ExportedCoValue<V>,\n) {\n const agent = useAgent();\n const preloadExecuted = useRef<typeof agent | null>(null);\n if (content && preloadExecuted.current !== agent && id) {\n if (content.id === id) {\n importContentPieces(content.contentPieces, agent);\n } else {\n console.warn(\"Preloaded value ID does not match the subscription ID\");\n }\n\n preloadExecuted.current = agent;\n }\n}\n\nfunction useGetCurrentValue<C extends CoValue>(\n subscription: SubscriptionScope<C> | null,\n) {\n return useCallback(() => {\n if (!subscription) {\n return getUnloadedCoValueWithoutId(CoValueLoadingState.UNAVAILABLE);\n }\n\n return subscription.getCurrentValue();\n }, [subscription]);\n}\n\n/**\n * React hook for subscribing to CoValues and handling loading states.\n *\n * This hook provides a convenient way to subscribe to CoValues and automatically\n * handles the subscription lifecycle (subscribe on mount, unsubscribe on unmount).\n * It also supports deep loading of nested CoValues through resolve queries.\n *\n * The {@param options.select} function allows returning only specific parts of the CoValue data,\n * which helps reduce unnecessary re-renders by narrowing down the returned data.\n * Additionally, you can provide a custom {@param options.equalityFn} to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * @returns The loaded CoValue, or an {@link NotLoaded} value. Use `$isLoaded` to check whether the\n * CoValue is loaded, or use {@link MaybeLoaded.$jazz.loadingState} to get the detailed loading state.\n * If a selector function is provided, returns the result of the selector function.\n *\n * @example\n * ```tsx\n * // Select only specific fields to reduce re-renders\n * const Project = co.map({\n * name: z.string(),\n * description: z.string(),\n * tasks: co.list(Task),\n * lastModified: z.date(),\n * });\n *\n * function ProjectTitle({ projectId }: { projectId: string }) {\n * // Only re-render when the project name changes, not other fields\n * const projectName = useCoState(\n * Project,\n * projectId,\n * {\n * select: (project) => !project.$isLoading ? project.name : \"Loading...\",\n * }\n * );\n *\n * return <h1>{projectName}</h1>;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Deep loading with resolve queries\n * const Project = co.map({\n * name: z.string(),\n * tasks: co.list(Task),\n * owner: TeamMember,\n * });\n *\n * function ProjectView({ projectId }: { projectId: string }) {\n * const project = useCoState(Project, projectId, {\n * resolve: {\n * tasks: { $each: true },\n * owner: true,\n * },\n * });\n *\n * if (!project.$isLoaded) {\n * switch (project.$jazz.loadingState) {\n * case \"unauthorized\":\n * return \"Project not accessible\";\n * case \"unavailable\":\n * return \"Project not found\";\n * case \"loading\":\n * return \"Loading project...\";\n * }\n * }\n *\n * return (\n * <div>\n * <h1>{project.name}</h1>\n * <p>Owner: {project.owner.name}</p>\n * <ul>\n * {project.tasks.map((task) => (\n * <li key={task.id}>{task.title}</li>\n * ))}\n * </ul>\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Using with optional references and error handling\n * const Task = co.map({\n * title: z.string(),\n * assignee: co.optional(TeamMember),\n * subtasks: co.list(Task),\n * });\n *\n * function TaskDetail({ taskId }: { taskId: string }) {\n * const task = useCoState(Task, taskId, {\n * resolve: {\n * assignee: true,\n * subtasks: { $each: { $onError: 'catch' } },\n * },\n * });\n *\n * if (!task.$isLoaded) {\n * switch (task.$jazz.loadingState) {\n * case \"unauthorized\":\n * return \"Task not accessible\";\n * case \"unavailable\":\n * return \"Task not found\";\n * case \"loading\":\n * return \"Loading task...\";\n * }\n * }\n *\n * return (\n * <div>\n * <h2>{task.title}</h2>\n * {task.assignee && <p>Assigned to: {task.assignee.name}</p>}\n * <ul>\n * {task.subtasks.map((subtask, index) => (\n * subtask.$isLoaded ? <li key={subtask.id}>{subtask.title}</li> : <li key={index}>Inaccessible subtask</li>\n * ))}\n * </ul>\n * </div>\n * );\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Use custom equality function for complex data structures\n * const TaskList = co.list(Task);\n *\n * function TaskCount({ listId }: { listId: string }) {\n * const taskStats = useCoState(\n * TaskList,\n * listId,\n * {\n * resolve: { $each: true },\n * select: (tasks) => {\n * if (!tasks.$isLoaded) return { total: 0, completed: 0 };\n * return {\n * total: tasks.length,\n * completed: tasks.filter(task => task.completed).length,\n * };\n * },\n * // Custom equality to prevent re-renders when stats haven't changed\n * equalityFn: (a, b) => a.total === b.total && a.completed === b.completed,\n * }\n * );\n *\n * return (\n * <div>\n * {taskStats.completed} of {taskStats.total} tasks completed\n * </div>\n * );\n * }\n * ```\n *\n * For more examples, see the [subscription and deep loading](https://jazz.tools/docs/react/using-covalues/subscription-and-loading) documentation.\n */\nexport function useCoState<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n TSelectorReturn = MaybeLoaded<Loaded<S, R>>,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to. If `undefined`, returns an `unavailable` value */\n id: string | undefined,\n /** Optional configuration for the subscription */\n options?: {\n /** Resolve query to specify which nested CoValues to load */\n resolve?: ResolveQueryStrict<S, R>;\n /** Select which value to return */\n select?: (value: MaybeLoaded<Loaded<S, R>>) => TSelectorReturn;\n /** Equality function to determine if the selected value has changed, defaults to `Object.is` */\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n /**\n * Create or load a branch for isolated editing.\n *\n * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version.\n * It's a fork of your data graph: the same schema, but with diverging values.\n *\n * The checkout of the branch is applied on all the resolved values.\n *\n * @param name - A unique name for the branch. This identifies the branch\n * and can be used to switch between different branches of the same CoValue.\n * @param owner - The owner of the branch. Determines who can access and modify\n * the branch. If not provided, the branch is owned by the current user.\n *\n * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.\n */\n unstable_branch?: BranchDefinition;\n preloaded?: ExportedCoValue<Loaded<S, R>>;\n },\n): TSelectorReturn {\n useImportCoValueContent(id, options?.preloaded);\n\n const subscription = useCoValueSubscription(Schema, id, options);\n const getCurrentValue = useGetCurrentValue(subscription);\n\n const value = useSyncExternalStoreWithSelector<\n MaybeLoaded<Loaded<S, R>>,\n TSelectorReturn\n >(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n\n return value;\n}\n\nexport function useSuspenseCoState<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n TSelectorReturn = Loaded<S, R>,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to */\n id: string,\n /** Optional configuration for the subscription */\n options?: {\n /** Resolve query to specify which nested CoValues to load */\n resolve?: ResolveQueryStrict<S, R>;\n /** Select which value to return */\n select?: (value: Loaded<S, R>) => TSelectorReturn;\n /** Equality function to determine if the selected value has changed, defaults to `Object.is` */\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n /**\n * Create or load a branch for isolated editing.\n *\n * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version.\n * It's a fork of your data graph: the same schema, but with diverging values.\n *\n * The checkout of the branch is applied on all the resolved values.\n *\n * @param name - A unique name for the branch. This identifies the branch\n * and can be used to switch between different branches of the same CoValue.\n * @param owner - The owner of the branch. Determines who can access and modify\n * the branch. If not provided, the branch is owned by the current user.\n *\n * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.\n */\n unstable_branch?: BranchDefinition;\n preloaded?: ExportedCoValue<Loaded<S, R>>;\n },\n): TSelectorReturn {\n useImportCoValueContent(id, options?.preloaded);\n\n const subscription = useCoValueSubscription(Schema, id, options);\n\n if (!subscription) {\n throw new Error(\"Subscription not found\");\n }\n\n use(subscription.getPromise());\n\n const getCurrentValue = () => {\n const value = subscription.getCurrentValue();\n\n if (!value.$isLoaded) {\n throw new Error(\"CoValue must be loaded in a suspense context\");\n }\n\n return value;\n };\n\n const value = useSyncExternalStoreWithSelector<Loaded<S, R>, TSelectorReturn>(\n React.useCallback(\n (callback) => {\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n\n return value;\n}\n\nexport function useSubscriptionSelector<\n S extends CoValueClassOrSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n TSelectorReturn = MaybeLoaded<Loaded<S, R>>,\n>(\n subscription: CoValueSubscription<S, R>,\n options?: {\n select?: (value: MaybeLoaded<Loaded<S, R>>) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n },\n) {\n const getCurrentValue = useGetCurrentValue(subscription);\n\n return useSyncExternalStoreWithSelector<\n MaybeLoaded<Loaded<S, R>>,\n TSelectorReturn\n >(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n}\n\nexport function useAccountSubscription<\n S extends AccountClass<Account> | AnyAccountSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<S> = SchemaResolveQuery<S>,\n>(\n Schema: S,\n options?: {\n resolve?: ResolveQueryStrict<S, R>;\n unstable_branch?: BranchDefinition;\n },\n) {\n const contextManager = useJazzContextManager();\n\n // Capture stack trace at hook call time\n const callerStack = React.useRef<Error | undefined>(undefined);\n if (!callerStack.current) {\n callerStack.current = captureStack();\n }\n\n const createSubscription = () => {\n const agent = getCurrentAccountFromContextManager(contextManager);\n\n if (agent.$type$ === \"Anonymous\") {\n return {\n subscription: null,\n contextManager,\n agent,\n };\n }\n\n const resolve = getResolveQuery(Schema, options?.resolve);\n\n const node = contextManager.getCurrentValue()!.node;\n const cache = contextManager.getSubscriptionScopeCache();\n const subscription = cache.getOrCreate(\n node,\n Schema,\n agent.$jazz.id,\n resolve,\n false,\n false,\n options?.unstable_branch,\n );\n\n // Set callerStack on returned subscription after retrieval\n if (callerStack.current) {\n subscription.callerStack = callerStack.current;\n }\n\n return {\n subscription,\n contextManager,\n Schema,\n branchName: options?.unstable_branch?.name,\n branchOwnerId: options?.unstable_branch?.owner?.$jazz.id,\n };\n };\n\n const [subscription, setSubscription] = React.useState(createSubscription);\n\n const branchName = options?.unstable_branch?.name;\n const branchOwnerId = options?.unstable_branch?.owner?.$jazz.id;\n\n React.useLayoutEffect(() => {\n if (\n subscription.contextManager !== contextManager ||\n subscription.Schema !== Schema ||\n subscription.branchName !== options?.unstable_branch?.name ||\n subscription.branchOwnerId !== options?.unstable_branch?.owner?.$jazz.id\n ) {\n // No need to manually destroy - cache handles cleanup via SubscriptionScope lifecycle\n setSubscription(createSubscription());\n }\n\n return contextManager.subscribe(() => {\n // No need to manually destroy - cache handles cleanup via SubscriptionScope lifecycle\n setSubscription(createSubscription());\n });\n }, [Schema, contextManager, branchName, branchOwnerId]);\n\n return subscription.subscription as CoValueSubscription<S, R>;\n}\n\n/**\n * React hook for accessing the current user's account.\n *\n * This hook provides access to the current user's account profile and root data.\n * It automatically handles the subscription lifecycle and supports deep loading of nested\n * CoValues through resolve queries.\n *\n * The {@param options.select} function allows returning only specific parts of the account data,\n * which helps reduce unnecessary re-renders by narrowing down the returned data.\n * Additionally, you can provide a custom {@param options.equalityFn} to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * @returns The account data, or an {@link NotLoaded} value. Use `$isLoaded` to check whether the\n * CoValue is loaded, or use {@link MaybeLoaded.$jazz.loadingState} to get the detailed loading state.\n * If a selector function is provided, returns the result of the selector function.\n *\n * @example\n * ```tsx\n * // Select only specific fields to reduce re-renders\n * const MyAppAccount = co.account({\n * profile: co.profile(),\n * root: co.map({\n * name: z.string(),\n * email: z.string(),\n * lastLogin: z.date(),\n * }),\n * });\n *\n * function UserProfile({ accountId }: { accountId: string }) {\n * // Only re-render when the profile name changes, not other fields\n * const profileName = useAccount(\n * MyAppAccount,\n * {\n * resolve: {\n * profile: true,\n * root: true,\n * },\n * select: (account) => account.$isLoaded ? account.profile.name : \"Loading...\",\n * }\n * );\n *\n * return <h1>{profileName}</h1>;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Deep loading with resolve queries\n * function ProjectListWithDetails() {\n * const me = useAccount(MyAppAccount, {\n * resolve: {\n * profile: true,\n * root: {\n * myProjects: {\n * $each: {\n * tasks: true,\n * },\n * },\n * },\n * },\n * });\n *\n * if (!me.$isLoaded) {\n * switch (me.$jazz.loadingState) {\n * case \"unauthorized\":\n * return \"Account not accessible\";\n * case \"unavailable\":\n * return \"Account not found\";\n * case \"loading\":\n * return \"Loading account...\";\n * }\n * }\n *\n * return (\n * <div>\n * <h1>{me.profile.name}'s projects</h1>\n * <ul>\n * {me.root.myProjects.map((project) => (\n * <li key={project.id}>\n * {project.name} ({project.tasks.length} tasks)\n * </li>\n * ))}\n * </ul>\n * </div>\n * );\n * }\n * ```\n *\n */\nexport function useAccount<\n A extends AccountClass<Account> | AnyAccountSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<A> = SchemaResolveQuery<A>,\n TSelectorReturn = MaybeLoaded<Loaded<A, R>>,\n>(\n /** The account schema to use. Defaults to the base Account schema */\n AccountSchema: A = Account as unknown as A,\n /** Optional configuration for the subscription */\n options?: {\n /** Resolve query to specify which nested CoValues to load from the account */\n resolve?: ResolveQueryStrict<A, R>;\n /** Select which value to return from the account data */\n select?: (account: MaybeLoaded<Loaded<A, R>>) => TSelectorReturn;\n /** Equality function to determine if the selected value has changed, defaults to `Object.is` */\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n /**\n * Create or load a branch for isolated editing.\n *\n * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version.\n * It's a fork of your data graph: the same schema, but with diverging values.\n *\n * The checkout of the branch is applied on all the resolved values.\n *\n * @param name - A unique name for the branch. This identifies the branch\n * and can be used to switch between different branches of the same CoValue.\n * @param owner - The owner of the branch. Determines who can access and modify\n * the branch. If not provided, the branch is owned by the current user.\n *\n * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.\n */\n unstable_branch?: BranchDefinition;\n },\n): TSelectorReturn {\n const subscription = useAccountSubscription(AccountSchema, options);\n const getCurrentValue = useGetCurrentValue(subscription);\n\n return useSyncExternalStoreWithSelector<\n MaybeLoaded<Loaded<A, R>>,\n TSelectorReturn\n >(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n}\n\nexport function useSuspenseAccount<\n A extends AccountClass<Account> | AnyAccountSchema,\n // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is\n const R extends ResolveQuery<A> = SchemaResolveQuery<A>,\n TSelectorReturn = Loaded<A, R>,\n>(\n /** The account schema to use. Defaults to the base Account schema */\n AccountSchema: A = Account as unknown as A,\n /** Optional configuration for the subscription */\n options?: {\n /** Resolve query to specify which nested CoValues to load from the account */\n resolve?: ResolveQueryStrict<A, R>;\n /** Select which value to return from the account data */\n select?: (account: Loaded<A, R>) => TSelectorReturn;\n /** Equality function to determine if the selected value has changed, defaults to `Object.is` */\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n /**\n * Create or load a branch for isolated editing.\n *\n * Branching lets you take a snapshot of the current state and start modifying it without affecting the canonical/shared version.\n * It's a fork of your data graph: the same schema, but with diverging values.\n *\n * The checkout of the branch is applied on all the resolved values.\n *\n * @param name - A unique name for the branch. This identifies the branch\n * and can be used to switch between different branches of the same CoValue.\n * @param owner - The owner of the branch. Determines who can access and modify\n * the branch. If not provided, the branch is owned by the current user.\n *\n * For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.\n */\n unstable_branch?: BranchDefinition;\n },\n): TSelectorReturn {\n const subscription = useAccountSubscription(AccountSchema, options);\n\n if (!subscription) {\n throw new Error(\n \"Subscription not found, are you using useSuspenseAccount in guest mode?\",\n );\n }\n\n use(subscription.getPromise());\n\n const getCurrentValue = () => {\n const value = subscription.getCurrentValue();\n\n if (!value.$isLoaded) {\n throw new Error(\"Account must be loaded in a suspense context\");\n }\n\n return value;\n };\n\n return useSyncExternalStoreWithSelector<Loaded<A, R>, TSelectorReturn>(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n getCurrentValue,\n getCurrentValue,\n options?.select ?? ((value) => value as TSelectorReturn),\n options?.equalityFn ?? Object.is,\n );\n}\n\n/**\n * Returns a function for logging out of the current account.\n */\nexport function useLogOut(): () => void {\n const contextManager = useJazzContextManager();\n return contextManager.logOut;\n}\n\n/**\n * React hook for accessing the current agent. An agent can either be:\n * - an Authenticated Account, if the user is logged in\n * - an Anonymous Account, if the user didn't log in\n * - or an anonymous agent, if in guest mode\n *\n * The agent can be used as the `loadAs` parameter for load and subscribe methods.\n */\nexport function useAgent<\n A extends AccountClass<Account> | AnyAccountSchema = typeof Account,\n>(): AnonymousJazzAgent | Loaded<A, true> {\n const contextManager = useJazzContextManager<InstanceOfSchema<A>>();\n\n const getCurrentValue = () =>\n getCurrentAccountFromContextManager(contextManager) as\n | AnonymousJazzAgent\n | Loaded<A, true>;\n\n return React.useSyncExternalStore(\n useCallback(\n (callback) => {\n return contextManager.subscribe(callback);\n },\n [contextManager],\n ),\n getCurrentValue,\n getCurrentValue,\n );\n}\n\nexport function experimental_useInboxSender<\n I extends CoValue,\n O extends CoValue | undefined,\n>(inboxOwnerID: string | undefined) {\n const context = useJazzContext();\n\n if (!(\"me\" in context)) {\n throw new Error(\n \"useInboxSender can't be used in a JazzProvider with auth === 'guest'.\",\n );\n }\n\n const me = context.me;\n const inboxRef = useRef<Promise<InboxSender<I, O>> | undefined>(undefined);\n\n const sendMessage = useCallback(\n async (message: I) => {\n if (!inboxOwnerID) throw new Error(\"Inbox owner ID is required\");\n\n if (!inboxRef.current) {\n const inbox = InboxSender.load<I, O>(inboxOwnerID, me);\n inboxRef.current = inbox;\n }\n\n let inbox = await inboxRef.current;\n\n // Regenerate the InboxSender if the inbox owner or current account changes\n if (inbox.owner.id !== inboxOwnerID || inbox.currentAccount !== me) {\n const req = InboxSender.load<I, O>(inboxOwnerID, me);\n inboxRef.current = req;\n inbox = await req;\n }\n\n return inbox.sendMessage(message);\n },\n [inboxOwnerID, me.$jazz.id],\n );\n\n return sendMessage;\n}\n\n/**\n * Hook that returns the current connection status to the Jazz sync server.\n *\n * @returns `true` when connected to the server, `false` when disconnected\n *\n * @remarks\n * On connection drop, this hook will return `false` only when Jazz detects the disconnection\n * after 5 seconds of not receiving a ping from the server.\n */\nexport function useSyncConnectionStatus() {\n const context = useJazzContext();\n\n const connected = useSyncExternalStore(\n useCallback(\n (callback) => {\n return context.addConnectionListener(callback);\n },\n [context],\n ),\n () => context.connected(),\n () => context.connected(),\n );\n\n return connected;\n}\n\nfunction getResolveQuery(\n Schema: CoValueClassOrSchema,\n // We don't need type validation here, since this is an internal API\n resolveQuery?: ResolveQuery<any>,\n): ResolveQuery<any> {\n if (resolveQuery) {\n return resolveQuery;\n }\n // Check the schema is a CoValue schema (and not a CoValue class)\n if (\"resolveQuery\" in Schema) {\n return Schema.resolveQuery;\n }\n return true;\n}\n","import { Account, JazzContextManager } from \"jazz-tools\";\n\nexport function getCurrentAccountFromContextManager<Acc extends Account>(\n contextManager: JazzContextManager<Acc, any>,\n) {\n const context = contextManager.getCurrentValue();\n\n if (!context) {\n throw new Error(\"No context found\");\n }\n\n return \"me\" in context ? context.me : context.guest;\n}\n\nexport function subscribeToContextManager<Acc extends Account>(\n contextManager: JazzContextManager<Acc, any>,\n callback: () => () => void,\n) {\n let unsub = () => {};\n\n const handler = () => {\n unsub();\n unsub = callback();\n };\n\n handler();\n return contextManager.subscribe(handler);\n}\n","import React from \"react\";\n\n// shim from https://github.com/pmndrs/jotai/blob/f287c5d665a807e676bc731e83174c62c1fe1fc9/src/react/useAtomValue.ts#L13C1-L56C1\nconst attachPromiseStatus = <T>(\n promise: PromiseLike<T> & {\n status?: \"pending\" | \"fulfilled\" | \"rejected\";\n value?: T;\n reason?: unknown;\n },\n) => {\n if (!promise.status) {\n promise.status = \"pending\";\n promise.then(\n (v) => {\n promise.status = \"fulfilled\";\n promise.value = v;\n },\n (e) => {\n promise.status = \"rejected\";\n promise.reason = e;\n },\n );\n }\n};\n\nexport const use =\n React.use ||\n // A shim for older React versions\n (<T>(\n promise: PromiseLike<T> & {\n status?: \"pending\" | \"fulfilled\" | \"rejected\";\n value?: T;\n reason?: unknown;\n },\n ): T => {\n if (promise.status === \"pending\") {\n throw promise;\n } else if (promise.status === \"fulfilled\") {\n return promise.value as T;\n } else if (promise.status === \"rejected\") {\n throw promise.reason;\n } else {\n attachPromiseStatus(promise);\n throw promise;\n }\n });\n","import React from \"react\";\nimport {\n Account,\n AccountClass,\n AnyAccountSchema,\n CoValueClassOrSchema,\n CoValueLoadingState,\n Loaded,\n MaybeLoaded,\n ResolveQuery,\n ResolveQueryStrict,\n} from \"jazz-tools\";\nimport {\n useAccountSubscription,\n useCoValueSubscription,\n useSubscriptionSelector,\n} from \"./hooks.js\";\nimport type { CoValueSubscription } from \"./types.js\";\n\nexport function createCoValueSubscriptionContext<\n S extends CoValueClassOrSchema,\n const R extends ResolveQuery<S> = true,\n>(schema: S, resolve?: ResolveQueryStrict<S, R>) {\n const Context = React.createContext<CoValueSubscription<S, R>>(null);\n\n return {\n Provider: ({\n id,\n options,\n loadingFallback,\n unavailableFallback,\n children,\n }: React.PropsWithChildren<{\n id: string | undefined | null;\n options?: Omit<\n Parameters<typeof useCoValueSubscription<S, R>>[2],\n \"resolve\"\n >;\n loadingFallback?: React.ReactNode;\n unavailableFallback?: React.ReactNode;\n }>) => {\n const subscription = useCoValueSubscription(schema, id, {\n ...options,\n resolve: resolve,\n });\n\n const loadState = useSubscriptionSelector(subscription, {\n select: (value) => value.$jazz.loadingState,\n });\n\n if (loadState === CoValueLoadingState.LOADING) {\n return loadingFallback ?? null;\n }\n if (\n loadState === CoValueLoadingState.UNAUTHORIZED ||\n loadState === CoValueLoadingState.UNAVAILABLE\n ) {\n return unavailableFallback ?? null;\n }\n\n return (\n <Context.Provider value={subscription}>{children}</Context.Provider>\n );\n },\n useSelector: <TSelectorReturn = Loaded<S, R>>(options?: {\n select?: (value: Loaded<S, R>) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n }) => {\n const subscription = React.useContext(Context);\n\n if (!subscription) {\n throw new Error(\n \"useSelector must be used within a coValue subscription provider\",\n );\n }\n\n return useSubscriptionSelector<S, R, TSelectorReturn>(\n subscription,\n options as Parameters<\n typeof useSubscriptionSelector<S, R, TSelectorReturn>\n >[1],\n );\n },\n };\n}\n\nexport function createAccountSubscriptionContext<\n A extends AccountClass<Account> | AnyAccountSchema,\n const R extends ResolveQuery<A> = true,\n>(schema: A, resolve?: ResolveQueryStrict<A, R>) {\n const Context = React.createContext<CoValueSubscription<A, R>>(null);\n\n return {\n Provider: ({\n options,\n loadingFallback,\n unavailableFallback,\n children,\n }: React.PropsWithChildren<{\n options?: Omit<\n Parameters<typeof useAccountSubscription<A, R>>[1],\n \"resolve\"\n >;\n loadingFallback?: React.ReactNode;\n unavailableFallback?: React.ReactNode;\n }>) => {\n const subscription = useAccountSubscription(schema, {\n ...options,\n resolve: resolve,\n });\n\n const loadState = useSubscriptionSelector(subscription, {\n select: (value) => value.$jazz.loadingState,\n });\n\n if (loadState === CoValueLoadingState.LOADING) {\n return loadingFallback ?? null;\n }\n\n if (\n loadState === CoValueLoadingState.UNAUTHORIZED ||\n loadState === CoValueLoadingState.UNAVAILABLE\n ) {\n return unavailableFallback ?? null;\n }\n\n return (\n <Context.Provider value={subscription}>{children}</Context.Provider>\n );\n },\n useSelector: <TSelectorReturn = Loaded<A, R>>(options?: {\n select?: (value: Loaded<A, R>) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n }) => {\n const subscription = React.useContext(Context);\n\n if (!subscription) {\n throw new Error(\n \"useSelector must be used within an account subscription provider\",\n );\n }\n\n return useSubscriptionSelector<A, R, TSelectorReturn>(\n subscription,\n options as Parameters<\n typeof useSubscriptionSelector<A, R, TSelectorReturn>\n >[1],\n );\n },\n };\n}\n","import { DemoAuth } from \"jazz-tools\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useAuthSecretStorage, useJazzContext } from \"../hooks.js\";\nimport { useIsAuthenticated } from \"../hooks.js\";\n\n/**\n * `useDemoAuth` is a hook that provides a `JazzAuth` object for demo authentication.\n *\n *\n * ```ts\n * const { state, logIn, signUp, existingUsers } = useDemoAuth();\n * ```\n *\n * @category Auth Providers\n */\nexport function useDemoAuth() {\n const context = useJazzContext();\n const authSecretStorage = useAuthSecretStorage();\n\n if (\"guest\" in context) {\n throw new Error(\"Demo auth is not supported in guest mode\");\n }\n\n const authMethod = useMemo(() => {\n return new DemoAuth(context.authenticate, authSecretStorage);\n }, []);\n\n const isAuthenticated = useIsAuthenticated();\n const [existingUsers, setExistingUsers] = useState<string[]>([]);\n\n useEffect(() => {\n authMethod.getExistingUsers().then(setExistingUsers);\n }, [authMethod]);\n\n function handleSignUp(username: string) {\n return authMethod.signUp(username).then(() => {\n setExistingUsers(existingUsers.concat([username]));\n });\n }\n\n return {\n state: isAuthenticated ? \"signedIn\" : \"anonymous\",\n logIn: authMethod.logIn,\n signUp: handleSignUp,\n existingUsers,\n } as const;\n}\n","import { PassphraseAuth } from \"jazz-tools\";\nimport { useCallback, useMemo, useSyncExternalStore } from \"react\";\nimport { useAuthSecretStorage, useJazzContext } from \"../hooks.js\";\nimport { useIsAuthenticated } from \"../hooks.js\";\n\n/**\n * `usePassphraseAuth` hook provides a `JazzAuth` object for passphrase authentication.\n *\n * @example\n * ```ts\n * const auth = usePassphraseAuth({ appName, appHostname, wordlist });\n * ```\n *\n * @category Auth Providers\n */\nexport function usePassphraseAuth({ wordlist }: { wordlist: string[] }) {\n const context = useJazzContext();\n const authSecretStorage = useAuthSecretStorage();\n\n if (\"guest\" in context) {\n throw new Error(\"Passphrase auth is not supported in guest mode\");\n }\n\n const authMethod = useMemo(() => {\n return new PassphraseAuth(\n context.node.crypto,\n context.authenticate,\n context.register,\n authSecretStorage,\n wordlist,\n );\n }, [wordlist]);\n\n const passphrase = useSyncExternalStore(\n useCallback(\n (callback) => {\n authMethod.loadCurrentAccountPassphrase();\n return authMethod.subscribe(callback);\n },\n [authMethod],\n ),\n () => authMethod.passphrase,\n );\n\n const isAuthenticated = useIsAuthenticated();\n return {\n state: isAuthenticated ? \"signedIn\" : \"anonymous\",\n logIn: authMethod.logIn,\n signUp: authMethod.signUp,\n registerNewAccount: authMethod.registerNewAccount,\n generateRandomPassphrase: authMethod.generateRandomPassphrase,\n passphrase,\n } as const;\n}\n"],"mappings":";;;;;;;AAAA,SAAS,wCAAwC;AACjD,OAAOA;AAAA,EACL;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EAMA;AAAA,EAEA;AAAA,EAYA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;AChCA,SAAS,oCACd,gBACA;AACA,QAAM,UAAU,eAAe,gBAAgB;AAE/C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AAEA,SAAO,QAAQ,UAAU,QAAQ,KAAK,QAAQ;AAChD;;;ACZA,OAAO,WAAW;AAGlB,IAAM,sBAAsB,CAC1B,YAKG;AACH,MAAI,CAAC,QAAQ,QAAQ;AACnB,YAAQ,SAAS;AACjB,YAAQ;AAAA,MACN,CAAC,MAAM;AACL,gBAAQ,SAAS;AACjB,gBAAQ,QAAQ;AAAA,MAClB;AAAA,MACA,CAAC,MAAM;AACL,gBAAQ,SAAS;AACjB,gBAAQ,SAAS;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,MACX,MAAM;AAAA,CAEL,CACC,YAKM;AACN,MAAI,QAAQ,WAAW,WAAW;AAChC,UAAM;AAAA,EACR,WAAW,QAAQ,WAAW,aAAa;AACzC,WAAO,QAAQ;AAAA,EACjB,WAAW,QAAQ,WAAW,YAAY;AACxC,UAAM,QAAQ;AAAA,EAChB,OAAO;AACL,wBAAoB,OAAO;AAC3B,UAAM;AAAA,EACR;AACF;;;AFLK,SAAS,iBAAsC;AACpD,QAAM,QAAQ,WAAW,WAAW;AAEpC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR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AgB;AAAA,EACrD,GAAG,CAAC,UAAU,CAAC;AAEf,WAAS,aAAa,UAAkB;AACtC,WAAO,WAAW,OAAO,QAAQ,EAAE,KAAK,MAAM;AAC5C,uBAAiB,cAAc,OAAO,CAAC,QAAQ,CAAC,CAAC;AAAA,IACnD,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,OAAO,kBAAkB,aAAa;AAAA,IACtC,OAAO,WAAW;AAAA,IAClB,QAAQ;AAAA,IACR;AAAA,EACF;AACF;;;AC9CA,SAAS,sBAAsB;AAC/B,SAAS,eAAAC,cAAa,WAAAC,UAAS,wBAAAC,6BAA4B;AAcpD,SAAS,kBAAkB,EAAE,SAAS,GAA2B;AACtE,QAAM,UAAU,eAAe;AAC/B,QAAM,oBAAoB,qBAAqB;AAE/C,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AAEA,QAAM,aAAaC,SAAQ,MAAM;AAC/B,WAAO,IAAI;AAAA,MACT,QAAQ,KAAK;AAAA,MACb,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,QAAM,aAAaC;AAAA,IACjBC;AAAA,MACE,CAAC,aAAa;AACZ,mBAAW,6BAA6B;AACxC,eAAO,WAAW,UAAU,QAAQ;AAAA,MACtC;AAAA,MACA,CAAC,UAAU;AAAA,IACb;AAAA,IACA,MAAM,WAAW;AAAA,EACnB;AAEA,QAAM,kBAAkB,mBAAmB;AAC3C,SAAO;AAAA,IACL,OAAO,kBAAkB,aAAa;AAAA,IACtC,OAAO,WAAW;AAAA,IAClB,QAAQ,WAAW;AAAA,IACnB,oBAAoB,WAAW;AAAA,IAC/B,0BAA0B,WAAW;AAAA,IACrC;AAAA,EACF;AACF;","names":["React","React","subscription","value","inbox","React","CoValueLoadingState","React","CoValueLoadingState","useMemo","useMemo","useCallback","useMemo","useSyncExternalStore","useMemo","useSyncExternalStore","useCallback"]}
|
|
@@ -12,4 +12,5 @@ declare const customRenderHook: <TProps, TResult>(callback: (props: TProps) => T
|
|
|
12
12
|
export * from "@testing-library/react";
|
|
13
13
|
export { customRender as render };
|
|
14
14
|
export { customRenderHook as renderHook };
|
|
15
|
+
export declare function createAsyncStorage(): Promise<import("cojson").StorageApiAsync>;
|
|
15
16
|
//# sourceMappingURL=testUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/testUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,aAAa,EAGd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/testUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,aAAa,EAGd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,KAAK,mBAAmB,GAAG;IACzB,OAAO,CAAC,EAAE,OAAO,GAAG;QAAE,KAAK,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAClD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,YAAY,OACZ,KAAK,CAAC,SAAS,YACV,aAAa,GAAG,mBAAmB,oIAkB7C,CAAC;AAEF,QAAA,MAAM,gBAAgB,GAAI,MAAM,EAAE,OAAO,YAC7B,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,YAC3B,iBAAiB,CAAC,MAAM,CAAC,GAAG,mBAAmB,uEAkBzD,CAAC;AAGF,cAAc,wBAAwB,CAAC;AAGvC,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC;AAClC,OAAO,EAAE,gBAAgB,IAAI,UAAU,EAAE,CAAC;AAyC1C,wBAAsB,kBAAkB,8CAUvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSuspenseAccount.test.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/useSuspenseAccount.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSuspenseCoState.test.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/useSuspenseCoState.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../src/react-core/use.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAyB1B,eAAO,MAAM,GAAG,kBAoBZ,CAAC"}
|
|
@@ -251,7 +251,9 @@ import {
|
|
|
251
251
|
useSyncConnectionStatus,
|
|
252
252
|
useCoValueSubscription,
|
|
253
253
|
useAccountSubscription,
|
|
254
|
-
useSubscriptionSelector
|
|
254
|
+
useSubscriptionSelector,
|
|
255
|
+
useSuspenseCoState,
|
|
256
|
+
useSuspenseAccount
|
|
255
257
|
} from "jazz-tools/react-core";
|
|
256
258
|
function useAcceptInviteNative({
|
|
257
259
|
invitedObjectSchema,
|
|
@@ -802,6 +804,8 @@ export {
|
|
|
802
804
|
useLogOut,
|
|
803
805
|
usePassphraseAuth,
|
|
804
806
|
useSubscriptionSelector,
|
|
807
|
+
useSuspenseAccount,
|
|
808
|
+
useSuspenseCoState,
|
|
805
809
|
useSyncConnectionStatus
|
|
806
810
|
};
|
|
807
811
|
//# sourceMappingURL=index.js.map
|