jazz-tools 0.18.23 → 0.18.25
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/.svelte-kit/__package__/Provider.svelte +2 -0
- package/.svelte-kit/__package__/Provider.svelte.d.ts.map +1 -1
- package/.turbo/turbo-build.log +65 -65
- package/CHANGELOG.md +25 -0
- package/dist/browser/index.js +9 -9
- package/dist/browser/index.js.map +1 -1
- package/dist/{chunk-D5L6ES2M.js → chunk-DOCEAUVD.js} +72 -35
- package/dist/chunk-DOCEAUVD.js.map +1 -0
- package/dist/{chunk-BOMSRY5H.js → chunk-M2HGBOXS.js} +2 -2
- package/dist/chunk-M2HGBOXS.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/inspector/{custom-element-XDJT5T57.js → custom-element-A7UAELEG.js} +3 -1
- package/dist/inspector/{custom-element-XDJT5T57.js.map → custom-element-A7UAELEG.js.map} +1 -1
- package/dist/inspector/index.js +2 -0
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/register-custom-element.js +1 -1
- package/dist/inspector/viewer/use-open-inspector.d.ts.map +1 -1
- package/dist/inspector/viewer/use-page-path.d.ts.map +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 +2 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +17 -3
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +2 -1
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/ssr.js +1 -1
- package/dist/react/ssr.js.map +1 -1
- package/dist/react-core/hooks.d.ts +13 -0
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.d.ts +2 -0
- package/dist/react-core/index.d.ts.map +1 -1
- package/dist/react-core/index.js +104 -0
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/subscription-provider.d.ts +27 -0
- package/dist/react-core/subscription-provider.d.ts.map +1 -0
- package/dist/react-core/tests/subscription.bench.d.ts +2 -0
- package/dist/react-core/tests/subscription.bench.d.ts.map +1 -0
- package/dist/react-core/tests/useSubscriptionSelector.test.d.ts +2 -0
- package/dist/react-core/tests/useSubscriptionSelector.test.d.ts.map +1 -0
- package/dist/react-core/types.d.ts +10 -0
- package/dist/react-core/types.d.ts.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.d.ts +1 -0
- package/dist/react-native-core/index.d.ts.map +1 -1
- package/dist/react-native-core/index.js +25 -12
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/provider.d.ts +2 -1
- package/dist/react-native-core/provider.d.ts.map +1 -1
- package/dist/svelte/Provider.svelte +2 -0
- package/dist/svelte/Provider.svelte.d.ts.map +1 -1
- package/dist/testing.js +4 -4
- package/dist/testing.js.map +1 -1
- package/dist/tools/auth/AuthSecretStorage.d.ts +3 -1
- package/dist/tools/auth/AuthSecretStorage.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +3 -3
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/group.d.ts +20 -1
- package/dist/tools/coValues/group.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/implementation/ContextManager.d.ts +1 -0
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts +7 -7
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -8
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +5 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/ssr.js +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/worker/index.js +3 -3
- package/dist/worker/index.js.map +1 -1
- package/package.json +5 -4
- package/src/better-auth/database-adapter/tests/sync-utils.ts +1 -1
- package/src/browser/createBrowserContext.ts +9 -9
- package/src/browser/tests/utils.ts +2 -2
- package/src/inspector/viewer/use-open-inspector.ts +1 -0
- package/src/inspector/viewer/use-page-path.ts +1 -0
- package/src/react/hooks.tsx +3 -0
- package/src/react/index.ts +9 -0
- package/src/react/provider.tsx +3 -0
- package/src/react-core/hooks.ts +37 -5
- package/src/react-core/index.ts +2 -0
- package/src/react-core/subscription-provider.tsx +144 -0
- package/src/react-core/tests/subscription.bench.tsx +319 -0
- package/src/react-core/tests/useSubscriptionSelector.test.ts +250 -0
- package/src/react-core/types.ts +19 -0
- package/src/react-native-core/hooks.tsx +3 -0
- package/src/react-native-core/index.ts +6 -0
- package/src/react-native-core/platform.ts +9 -9
- package/src/react-native-core/provider.tsx +3 -1
- package/src/svelte/Provider.svelte +2 -0
- package/src/tools/auth/AuthSecretStorage.ts +16 -9
- package/src/tools/coValues/account.ts +5 -5
- package/src/tools/coValues/group.ts +33 -0
- package/src/tools/coValues/interfaces.ts +4 -1
- package/src/tools/implementation/ContextManager.ts +7 -3
- package/src/tools/implementation/createContext.ts +12 -12
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +5 -5
- package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +7 -1
- package/src/tools/ssr/ssr.ts +1 -1
- package/src/tools/testing.ts +3 -3
- package/src/tools/tests/AuthSecretStorage.test.ts +59 -1
- package/src/tools/tests/ContextManager.test.ts +11 -1
- package/src/tools/tests/account.test.ts +16 -0
- package/src/tools/tests/coPlainText.test.ts +2 -2
- package/src/tools/tests/createContext.test.ts +19 -19
- package/src/tools/tests/deepLoading.test.ts +2 -2
- package/src/tools/tests/group.test.ts +59 -0
- package/src/tools/tests/inbox.test.ts +2 -2
- package/src/tools/tests/utils.ts +3 -3
- package/src/worker/index.ts +3 -3
- package/dist/chunk-BOMSRY5H.js.map +0 -1
- package/dist/chunk-D5L6ES2M.js.map +0 -1
package/dist/react-core/index.js
CHANGED
@@ -162,6 +162,24 @@ function useCoStateWithSelector(Schema, id, options) {
|
|
162
162
|
options.equalityFn ?? Object.is
|
163
163
|
);
|
164
164
|
}
|
165
|
+
function useSubscriptionSelector(subscription, options) {
|
166
|
+
return useSyncExternalStoreWithSelector(
|
167
|
+
React.useCallback(
|
168
|
+
(callback) => {
|
169
|
+
if (!subscription) {
|
170
|
+
return () => {
|
171
|
+
};
|
172
|
+
}
|
173
|
+
return subscription.subscribe(callback);
|
174
|
+
},
|
175
|
+
[subscription]
|
176
|
+
),
|
177
|
+
() => subscription ? subscription.getCurrentValue() : null,
|
178
|
+
() => subscription ? subscription.getCurrentValue() : null,
|
179
|
+
options?.select ?? ((value) => value),
|
180
|
+
options?.equalityFn ?? Object.is
|
181
|
+
);
|
182
|
+
}
|
165
183
|
function useAccountSubscription(Schema, options) {
|
166
184
|
const contextManager = useJazzContextManager();
|
167
185
|
const createSubscription = () => {
|
@@ -296,6 +314,87 @@ function useSyncConnectionStatus() {
|
|
296
314
|
return connected;
|
297
315
|
}
|
298
316
|
|
317
|
+
// src/react-core/subscription-provider.tsx
|
318
|
+
import React2 from "react";
|
319
|
+
import { jsx } from "react/jsx-runtime";
|
320
|
+
function createCoValueSubscriptionContext(schema, resolve) {
|
321
|
+
const Context = React2.createContext(null);
|
322
|
+
return {
|
323
|
+
Provider: ({
|
324
|
+
id,
|
325
|
+
options,
|
326
|
+
loadingFallback,
|
327
|
+
unavailableFallback,
|
328
|
+
children
|
329
|
+
}) => {
|
330
|
+
const subscription = useCoValueSubscription(schema, id, {
|
331
|
+
...options,
|
332
|
+
resolve
|
333
|
+
});
|
334
|
+
const loadState = useSubscriptionSelector(subscription, {
|
335
|
+
select: (value) => !value ? value : true
|
336
|
+
});
|
337
|
+
if (loadState === void 0) {
|
338
|
+
return loadingFallback ?? null;
|
339
|
+
}
|
340
|
+
if (loadState === null) {
|
341
|
+
return unavailableFallback ?? null;
|
342
|
+
}
|
343
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: subscription, children });
|
344
|
+
},
|
345
|
+
useSelector: (options) => {
|
346
|
+
const subscription = React2.useContext(Context);
|
347
|
+
if (!subscription) {
|
348
|
+
throw new Error(
|
349
|
+
"useSelector must be used within a coValue subscription provider"
|
350
|
+
);
|
351
|
+
}
|
352
|
+
return useSubscriptionSelector(
|
353
|
+
subscription,
|
354
|
+
options
|
355
|
+
);
|
356
|
+
}
|
357
|
+
};
|
358
|
+
}
|
359
|
+
function createAccountSubscriptionContext(schema, resolve) {
|
360
|
+
const Context = React2.createContext(null);
|
361
|
+
return {
|
362
|
+
Provider: ({
|
363
|
+
options,
|
364
|
+
loadingFallback,
|
365
|
+
unavailableFallback,
|
366
|
+
children
|
367
|
+
}) => {
|
368
|
+
const subscription = useAccountSubscription(schema, {
|
369
|
+
...options,
|
370
|
+
resolve
|
371
|
+
});
|
372
|
+
const loadState = useSubscriptionSelector(subscription, {
|
373
|
+
select: (value) => !value ? value : true
|
374
|
+
});
|
375
|
+
if (loadState === void 0) {
|
376
|
+
return loadingFallback ?? null;
|
377
|
+
}
|
378
|
+
if (loadState === null) {
|
379
|
+
return unavailableFallback ?? null;
|
380
|
+
}
|
381
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: subscription, children });
|
382
|
+
},
|
383
|
+
useSelector: (options) => {
|
384
|
+
const subscription = React2.useContext(Context);
|
385
|
+
if (!subscription) {
|
386
|
+
throw new Error(
|
387
|
+
"useSelector must be used within an account subscription provider"
|
388
|
+
);
|
389
|
+
}
|
390
|
+
return useSubscriptionSelector(
|
391
|
+
subscription,
|
392
|
+
options
|
393
|
+
);
|
394
|
+
}
|
395
|
+
};
|
396
|
+
}
|
397
|
+
|
299
398
|
// src/react-core/auth/DemoAuth.tsx
|
300
399
|
import { DemoAuth } from "jazz-tools";
|
301
400
|
import { useEffect, useMemo, useState } from "react";
|
@@ -367,17 +466,22 @@ function usePassphraseAuth({ wordlist }) {
|
|
367
466
|
export {
|
368
467
|
JazzContext,
|
369
468
|
JazzContextManagerContext,
|
469
|
+
createAccountSubscriptionContext,
|
470
|
+
createCoValueSubscriptionContext,
|
370
471
|
experimental_useInboxSender,
|
371
472
|
useAccount,
|
473
|
+
useAccountSubscription,
|
372
474
|
useAccountWithSelector,
|
373
475
|
useAuthSecretStorage,
|
374
476
|
useCoState,
|
375
477
|
useCoStateWithSelector,
|
478
|
+
useCoValueSubscription,
|
376
479
|
useDemoAuth,
|
377
480
|
useIsAuthenticated,
|
378
481
|
useJazzContext,
|
379
482
|
useJazzContextManager,
|
380
483
|
usePassphraseAuth,
|
484
|
+
useSubscriptionSelector,
|
381
485
|
useSyncConnectionStatus
|
382
486
|
};
|
383
487
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/react-core/hooks.ts","../../src/react-core/utils.ts","../../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 useRef,\n useSyncExternalStore,\n} from \"react\";\n\nimport {\n Account,\n AccountClass,\n AnonymousJazzAgent,\n AnyAccountSchema,\n CoValue,\n CoValueClassOrSchema,\n Group,\n InboxSender,\n InstanceOfSchema,\n JazzContextManager,\n JazzContextType,\n Loaded,\n ResolveQuery,\n ResolveQueryStrict,\n SubscriptionScope,\n coValueClassFromCoValueClassOrSchema,\n type BranchDefinition,\n} from \"jazz-tools\";\nimport { JazzContext, JazzContextManagerContext } from \"./provider.js\";\nimport { getCurrentAccountFromContextManager } from \"./utils.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\nfunction useCoValueSubscription<\n S extends CoValueClassOrSchema,\n const R extends ResolveQuery<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\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 node = contextManager.getCurrentValue()!.node;\n const subscription = new SubscriptionScope<any>(\n node,\n options?.resolve ?? true,\n id,\n {\n ref: coValueClassFromCoValueClassOrSchema(Schema),\n optional: true,\n },\n false,\n false,\n options?.unstable_branch,\n );\n\n return {\n subscription,\n contextManager,\n id,\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.id !== id ||\n subscription.Schema !== Schema ||\n subscription.branchName !== branchName ||\n subscription.branchOwnerId !== branchOwnerId\n ) {\n subscription.subscription?.destroy();\n setSubscription(createSubscription());\n }\n\n return contextManager.subscribe(() => {\n subscription.subscription?.destroy();\n setSubscription(createSubscription());\n });\n }, [Schema, id, contextManager, branchName, branchOwnerId]);\n\n return subscription.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 * @returns The loaded CoValue, or `undefined` if loading, or `null` if not found/not accessible\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) {\n * return project === null\n * ? \"Project not found or not accessible\"\n * : \"Loading project...\";\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: null } },\n * },\n * });\n *\n * if (!task) {\n * return task === null\n * ? \"Task not found or not accessible\"\n * : \"Loading task...\";\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 ? <li key={subtask.id}>{subtask.title}</li> : <li key={index}>Inaccessible subtask</li>\n * ))}\n * </ul>\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 const R extends ResolveQuery<S> = true,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to. If `undefined`, returns `null` */\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 /**\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): Loaded<S, R> | undefined | null {\n const subscription = useCoValueSubscription(Schema, id, options);\n\n const value = React.useSyncExternalStore<Loaded<S, R> | undefined | null>(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n );\n\n return value;\n}\n\n/**\n * React hook for subscribing to CoValues with selective data extraction and custom equality checking.\n *\n * This hook extends `useCoState` by allowing you to select only specific parts of the CoValue data\n * through a selector function, which helps reduce unnecessary re-renders by narrowing down the\n * returned data. Additionally, you can provide a custom equality function to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * The hook automatically handles the subscription lifecycle and supports deep loading of nested\n * CoValues through resolve queries, just like `useCoState`.\n *\n * @returns The result of the selector function applied to the loaded CoValue data\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 = useCoStateWithSelector(\n * Project,\n * projectId,\n * {\n * select: (project) => project?.name ?? \"Loading...\",\n * }\n * );\n *\n * return <h1>{projectName}</h1>;\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 = useCoStateWithSelector(\n * TaskList,\n * listId,\n * {\n * resolve: { $each: true },\n * select: (tasks) => {\n * if (!tasks) 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 * @example\n * ```tsx\n * // Combine with deep loading and complex selectors\n * const Team = co.map({\n * name: z.string(),\n * members: co.list(TeamMember),\n * projects: co.list(Project),\n * });\n *\n * function TeamSummary({ teamId }: { teamId: string }) {\n * const summary = useCoStateWithSelector(\n * Team,\n * teamId,\n * {\n * resolve: {\n * members: { $each: true },\n * projects: { $each: { tasks: { $each: true } } },\n * },\n * select: (team) => {\n * if (!team) return null;\n *\n * const totalTasks = team.projects.reduce(\n * (sum, project) => sum + project.tasks.length,\n * 0\n * );\n *\n * return {\n * teamName: team.name,\n * memberCount: team.members.length,\n * projectCount: team.projects.length,\n * totalTasks,\n * };\n * },\n * }\n * );\n *\n * if (!summary) return <div>Loading team summary...</div>;\n *\n * return (\n * <div>\n * <h2>{summary.teamName}</h2>\n * <p>{summary.memberCount} members</p>\n * <p>{summary.projectCount} projects</p>\n * <p>{summary.totalTasks} total tasks</p>\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 useCoStateWithSelector<\n S extends CoValueClassOrSchema,\n TSelectorReturn,\n const R extends ResolveQuery<S> = true,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to. If `undefined`, returns the result of selector called with `null` */\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: Loaded<S, R> | undefined | null) => 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 = useCoValueSubscription(Schema, id, options);\n\n return useSyncExternalStoreWithSelector<\n Loaded<S, R> | undefined | null,\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 () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n options.select,\n options.equalityFn ?? Object.is,\n );\n}\n\nfunction useAccountSubscription<\n S extends AccountClass<Account> | AnyAccountSchema,\n const R extends ResolveQuery<S>,\n>(\n Schema: S,\n options?: {\n resolve?: ResolveQueryStrict<S, R>;\n unstable_branch?: BranchDefinition;\n },\n) {\n const contextManager = useJazzContextManager();\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 // We don't need type validation here, since it's mostly to help users on public API\n const resolve: any = options?.resolve ?? true;\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 );\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;\n}\n\n/**\n * React hook for accessing the current user's account and authentication state.\n * \n * This hook provides access to the current user's account profile and root data,\n * along with authentication utilities. It automatically handles subscription to\n * the user's account data and provides a logout function.\n * \n * @returns An object containing:\n * - `me`: The loaded account data, or `undefined` if loading, or `null` if not authenticated\n * - `agent`: The current agent (anonymous or authenticated user). Can be used as `loadAs` parameter for load and subscribe methods.\n * - `logOut`: Function to log out the current user\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) {\n * return me === null\n * ? <div>Failed to load your projects</div>\n * : <div>Loading...</div>;\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 R extends ResolveQuery<A> = true,\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 /**\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): {\n me: Loaded<A, R> | undefined | null;\n agent: AnonymousJazzAgent | Loaded<A, true>;\n logOut: () => void;\n} {\n const contextManager = useJazzContextManager<InstanceOfSchema<A>>();\n const subscription = useAccountSubscription(AccountSchema, options);\n\n const agent = getCurrentAccountFromContextManager(contextManager);\n\n const value = React.useSyncExternalStore<Loaded<A, R> | undefined | null>(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n );\n\n return {\n me: value,\n agent,\n logOut: contextManager.logOut,\n };\n}\n\n/**\n * React hook for accessing the current user's account with selective data extraction and custom equality checking.\n *\n * This hook extends `useAccount` by allowing you to select only specific parts of the account data\n * through a selector function, which helps reduce unnecessary re-renders by narrowing down the\n * returned data. Additionally, you can provide a custom equality function to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * The hook automatically handles the subscription lifecycle and supports deep loading of nested\n * CoValues through resolve queries, just like `useAccount`.\n *\n * @returns The result of the selector function applied to the loaded account data\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 = useAccountWithSelector(\n * MyAppAccount,\n * {\n * resolve: {\n * profile: true,\n * root: true,\n * },\n * select: (account) => account?.profile?.name ?? \"Loading...\",\n * }\n * );\n *\n * return <h1>{profileName}</h1>;\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 useAccountWithSelector<\n A extends AccountClass<Account> | AnyAccountSchema,\n TSelectorReturn,\n R extends ResolveQuery<A> = true,\n>(\n /** The account schema to use. Defaults to the base Account schema */\n AccountSchema: A = Account as unknown as A,\n /** Configuration for the subscription and selection */\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> | undefined | null) => 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 return useSyncExternalStoreWithSelector<\n Loaded<A, R> | undefined | null,\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 () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n options.select,\n options.equalityFn ?? Object.is,\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","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 { 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,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EAOA;AAAA,EAOA;AAAA,EACA;AAAA,OAEK;;;ACxBA,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;;;ADkBO,SAAS,iBAAsC;AACpD,QAAM,QAAQ,WAAW,WAAW;AAEpC,MAAI,CAAC,OAAO;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B,0BAA0B,WAAW;AAAA,IACrC;AAAA,EACF;AACF;","names":["subscription","inbox","useCallback","useMemo","useSyncExternalStore","useMemo","useSyncExternalStore","useCallback"]}
|
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 useRef,\n useSyncExternalStore,\n} from \"react\";\n\nimport {\n Account,\n AccountClass,\n AnonymousJazzAgent,\n AnyAccountSchema,\n CoValue,\n CoValueClassOrSchema,\n InboxSender,\n InstanceOfSchema,\n JazzContextManager,\n JazzContextType,\n Loaded,\n ResolveQuery,\n ResolveQueryStrict,\n SubscriptionScope,\n coValueClassFromCoValueClassOrSchema,\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 const R extends ResolveQuery<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\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 node = contextManager.getCurrentValue()!.node;\n const subscription = new SubscriptionScope<any>(\n node,\n options?.resolve ?? true,\n id,\n {\n ref: coValueClassFromCoValueClassOrSchema(Schema),\n optional: true,\n },\n false,\n false,\n options?.unstable_branch,\n );\n\n return {\n subscription,\n contextManager,\n id,\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.id !== id ||\n subscription.Schema !== Schema ||\n subscription.branchName !== branchName ||\n subscription.branchOwnerId !== branchOwnerId\n ) {\n subscription.subscription?.destroy();\n setSubscription(createSubscription());\n }\n\n return contextManager.subscribe(() => {\n subscription.subscription?.destroy();\n setSubscription(createSubscription());\n });\n }, [Schema, id, contextManager, branchName, branchOwnerId]);\n\n return subscription.subscription as CoValueSubscription<S, R>;\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 * @returns The loaded CoValue, or `undefined` if loading, or `null` if not found/not accessible\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) {\n * return project === null\n * ? \"Project not found or not accessible\"\n * : \"Loading project...\";\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: null } },\n * },\n * });\n *\n * if (!task) {\n * return task === null\n * ? \"Task not found or not accessible\"\n * : \"Loading task...\";\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 ? <li key={subtask.id}>{subtask.title}</li> : <li key={index}>Inaccessible subtask</li>\n * ))}\n * </ul>\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 const R extends ResolveQuery<S> = true,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to. If `undefined`, returns `null` */\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 /**\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): Loaded<S, R> | undefined | null {\n const subscription = useCoValueSubscription(Schema, id, options);\n\n const value = React.useSyncExternalStore<Loaded<S, R> | undefined | null>(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n );\n\n return value;\n}\n\n/**\n * React hook for subscribing to CoValues with selective data extraction and custom equality checking.\n *\n * This hook extends `useCoState` by allowing you to select only specific parts of the CoValue data\n * through a selector function, which helps reduce unnecessary re-renders by narrowing down the\n * returned data. Additionally, you can provide a custom equality function to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * The hook automatically handles the subscription lifecycle and supports deep loading of nested\n * CoValues through resolve queries, just like `useCoState`.\n *\n * @returns The result of the selector function applied to the loaded CoValue data\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 = useCoStateWithSelector(\n * Project,\n * projectId,\n * {\n * select: (project) => project?.name ?? \"Loading...\",\n * }\n * );\n *\n * return <h1>{projectName}</h1>;\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 = useCoStateWithSelector(\n * TaskList,\n * listId,\n * {\n * resolve: { $each: true },\n * select: (tasks) => {\n * if (!tasks) 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 * @example\n * ```tsx\n * // Combine with deep loading and complex selectors\n * const Team = co.map({\n * name: z.string(),\n * members: co.list(TeamMember),\n * projects: co.list(Project),\n * });\n *\n * function TeamSummary({ teamId }: { teamId: string }) {\n * const summary = useCoStateWithSelector(\n * Team,\n * teamId,\n * {\n * resolve: {\n * members: { $each: true },\n * projects: { $each: { tasks: { $each: true } } },\n * },\n * select: (team) => {\n * if (!team) return null;\n *\n * const totalTasks = team.projects.reduce(\n * (sum, project) => sum + project.tasks.length,\n * 0\n * );\n *\n * return {\n * teamName: team.name,\n * memberCount: team.members.length,\n * projectCount: team.projects.length,\n * totalTasks,\n * };\n * },\n * }\n * );\n *\n * if (!summary) return <div>Loading team summary...</div>;\n *\n * return (\n * <div>\n * <h2>{summary.teamName}</h2>\n * <p>{summary.memberCount} members</p>\n * <p>{summary.projectCount} projects</p>\n * <p>{summary.totalTasks} total tasks</p>\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 useCoStateWithSelector<\n S extends CoValueClassOrSchema,\n TSelectorReturn,\n const R extends ResolveQuery<S> = true,\n>(\n /** The CoValue schema or class constructor */\n Schema: S,\n /** The ID of the CoValue to subscribe to. If `undefined`, returns the result of selector called with `null` */\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: Loaded<S, R> | undefined | null) => 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 = useCoValueSubscription(Schema, id, options);\n\n return useSyncExternalStoreWithSelector<\n Loaded<S, R> | undefined | null,\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 () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n options.select,\n options.equalityFn ?? Object.is,\n );\n}\n\nexport function useSubscriptionSelector<\n S extends CoValueClassOrSchema,\n R extends ResolveQuery<S>,\n TSelectorReturn = Loaded<S, R> | undefined | null,\n>(\n subscription: CoValueSubscription<S, R>,\n options?: {\n select?: (value: Loaded<S, R> | undefined | null) => TSelectorReturn;\n equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;\n },\n) {\n return useSyncExternalStoreWithSelector<\n Loaded<S, R> | undefined | null,\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 () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\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 const R extends ResolveQuery<S>,\n>(\n Schema: S,\n options?: {\n resolve?: ResolveQueryStrict<S, R>;\n unstable_branch?: BranchDefinition;\n },\n) {\n const contextManager = useJazzContextManager();\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 // We don't need type validation here, since it's mostly to help users on public API\n const resolve: any = options?.resolve ?? true;\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 );\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 and authentication state.\n * \n * This hook provides access to the current user's account profile and root data,\n * along with authentication utilities. It automatically handles subscription to\n * the user's account data and provides a logout function.\n * \n * @returns An object containing:\n * - `me`: The loaded account data, or `undefined` if loading, or `null` if not authenticated\n * - `agent`: The current agent (anonymous or authenticated user). Can be used as `loadAs` parameter for load and subscribe methods.\n * - `logOut`: Function to log out the current user\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) {\n * return me === null\n * ? <div>Failed to load your projects</div>\n * : <div>Loading...</div>;\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 R extends ResolveQuery<A> = true,\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 /**\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): {\n me: Loaded<A, R> | undefined | null;\n agent: AnonymousJazzAgent | Loaded<A, true>;\n logOut: () => void;\n} {\n const contextManager = useJazzContextManager<InstanceOfSchema<A>>();\n const subscription = useAccountSubscription(AccountSchema, options);\n\n const agent = getCurrentAccountFromContextManager(contextManager);\n\n const value = React.useSyncExternalStore<Loaded<A, R> | undefined | null>(\n React.useCallback(\n (callback) => {\n if (!subscription) {\n return () => {};\n }\n\n return subscription.subscribe(callback);\n },\n [subscription],\n ),\n () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n );\n\n return {\n me: value,\n agent,\n logOut: contextManager.logOut,\n };\n}\n\n/**\n * React hook for accessing the current user's account with selective data extraction and custom equality checking.\n *\n * This hook extends `useAccount` by allowing you to select only specific parts of the account data\n * through a selector function, which helps reduce unnecessary re-renders by narrowing down the\n * returned data. Additionally, you can provide a custom equality function to further optimize\n * performance by controlling when the component should re-render based on the selected data.\n *\n * The hook automatically handles the subscription lifecycle and supports deep loading of nested\n * CoValues through resolve queries, just like `useAccount`.\n *\n * @returns The result of the selector function applied to the loaded account data\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 = useAccountWithSelector(\n * MyAppAccount,\n * {\n * resolve: {\n * profile: true,\n * root: true,\n * },\n * select: (account) => account?.profile?.name ?? \"Loading...\",\n * }\n * );\n *\n * return <h1>{profileName}</h1>;\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 useAccountWithSelector<\n A extends AccountClass<Account> | AnyAccountSchema,\n TSelectorReturn,\n R extends ResolveQuery<A> = true,\n>(\n /** The account schema to use. Defaults to the base Account schema */\n AccountSchema: A = Account as unknown as A,\n /** Configuration for the subscription and selection */\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> | undefined | null) => 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 return useSyncExternalStoreWithSelector<\n Loaded<A, R> | undefined | null,\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 () => (subscription ? subscription.getCurrentValue() : null),\n () => (subscription ? subscription.getCurrentValue() : null),\n options.select,\n options.equalityFn ?? Object.is,\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","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 Loaded,\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 ? value : true),\n });\n\n if (loadState === undefined) {\n return loadingFallback ?? null;\n }\n\n if (loadState === null) {\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 ? value : true),\n });\n\n if (loadState === undefined) {\n return loadingFallback ?? null;\n }\n\n if (loadState === null) {\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,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EAMA;AAAA,EAOA;AAAA,EACA;AAAA,OAEK;;;ACvBA,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;;;ADkBO,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;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aC;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","inbox","React","React","useCallback","useMemo","useSyncExternalStore","useMemo","useSyncExternalStore","useCallback"]}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { Account, AccountClass, AnyAccountSchema, CoValueClassOrSchema, Loaded, ResolveQuery, ResolveQueryStrict } from "jazz-tools";
|
3
|
+
import { useAccountSubscription, useCoValueSubscription } from "./hooks.js";
|
4
|
+
export declare function createCoValueSubscriptionContext<S extends CoValueClassOrSchema, const R extends ResolveQuery<S> = true>(schema: S, resolve?: ResolveQueryStrict<S, R>): {
|
5
|
+
Provider: ({ id, options, loadingFallback, unavailableFallback, children, }: React.PropsWithChildren<{
|
6
|
+
id: string | undefined | null;
|
7
|
+
options?: Omit<Parameters<typeof useCoValueSubscription<S, R>>[2], "resolve">;
|
8
|
+
loadingFallback?: React.ReactNode;
|
9
|
+
unavailableFallback?: React.ReactNode;
|
10
|
+
}>) => string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
|
11
|
+
useSelector: <TSelectorReturn = Loaded<S, R>>(options?: {
|
12
|
+
select?: (value: Loaded<S, R>) => TSelectorReturn;
|
13
|
+
equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;
|
14
|
+
}) => TSelectorReturn;
|
15
|
+
};
|
16
|
+
export declare function createAccountSubscriptionContext<A extends AccountClass<Account> | AnyAccountSchema, const R extends ResolveQuery<A> = true>(schema: A, resolve?: ResolveQueryStrict<A, R>): {
|
17
|
+
Provider: ({ options, loadingFallback, unavailableFallback, children, }: React.PropsWithChildren<{
|
18
|
+
options?: Omit<Parameters<typeof useAccountSubscription<A, R>>[1], "resolve">;
|
19
|
+
loadingFallback?: React.ReactNode;
|
20
|
+
unavailableFallback?: React.ReactNode;
|
21
|
+
}>) => string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null;
|
22
|
+
useSelector: <TSelectorReturn = Loaded<A, R>>(options?: {
|
23
|
+
select?: (value: Loaded<A, R>) => TSelectorReturn;
|
24
|
+
equalityFn?: (a: TSelectorReturn, b: TSelectorReturn) => boolean;
|
25
|
+
}) => TSelectorReturn;
|
26
|
+
};
|
27
|
+
//# sourceMappingURL=subscription-provider.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"subscription-provider.d.ts","sourceRoot":"","sources":["../../src/react-core/subscription-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,MAAM,EACN,YAAY,EACZ,kBAAkB,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AAGpB,wBAAgB,gCAAgC,CAC9C,CAAC,SAAS,oBAAoB,EAC9B,KAAK,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,EACtC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,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,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC;KAClE;EAiBJ"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"subscription.bench.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/subscription.bench.tsx"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useSubscriptionSelector.test.d.ts","sourceRoot":"","sources":["../../../src/react-core/tests/useSubscriptionSelector.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { CoValueClassOrSchema, ResolveQuery, SubscriptionScope } from "jazz-tools";
|
2
|
+
declare const subscriptionTag: unique symbol;
|
3
|
+
export type CoValueSubscription<S extends CoValueClassOrSchema, R extends ResolveQuery<S>> = (SubscriptionScope<any> & {
|
4
|
+
[subscriptionTag]: {
|
5
|
+
schema: S;
|
6
|
+
resolve: R;
|
7
|
+
};
|
8
|
+
}) | null;
|
9
|
+
export {};
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/react-core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,CAAC,MAAM,eAAe,EAAE,OAAO,MAAM,CAAC;AAE7C,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,IAEvB,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG;IACxB,CAAC,eAAe,CAAC,EAAE;QACjB,MAAM,EAAE,CAAC,CAAC;QACV,OAAO,EAAE,CAAC,CAAC;KACZ,CAAC;CACH,CAAC,GACF,IAAI,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { CoValueClassOrSchema } from "jazz-tools";
|
2
|
-
export { useCoState, experimental_useInboxSender, useDemoAuth, usePassphraseAuth, useJazzContext, useAuthSecretStorage, useIsAuthenticated, useAccount, useCoStateWithSelector, useAccountWithSelector, useSyncConnectionStatus, } from "jazz-tools/react-core";
|
2
|
+
export { useCoState, experimental_useInboxSender, useDemoAuth, usePassphraseAuth, useJazzContext, useAuthSecretStorage, useIsAuthenticated, useAccount, useCoStateWithSelector, useAccountWithSelector, useSyncConnectionStatus, useCoValueSubscription, useAccountSubscription, useSubscriptionSelector, } from "jazz-tools/react-core";
|
3
3
|
export declare function useAcceptInviteNative<S extends CoValueClassOrSchema>({ invitedObjectSchema, onAccept, forValueHint, }: {
|
4
4
|
invitedObjectSchema: S;
|
5
5
|
onAccept: (projectID: string) => void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react-native-core/hooks.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAmB,MAAM,YAAY,CAAC;AAInE,OAAO,EACL,UAAU,EACV,2BAA2B,EAC3B,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,oBAAoB,EAAE,EACpE,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACb,EAAE;IACD,mBAAmB,EAAE,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAsCP"}
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react-native-core/hooks.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAmB,MAAM,YAAY,CAAC;AAInE,OAAO,EACL,UAAU,EACV,2BAA2B,EAC3B,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,oBAAoB,EAAE,EACpE,mBAAmB,EACnB,QAAQ,EACR,YAAY,GACb,EAAE;IACD,mBAAmB,EAAE,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAsCP"}
|
@@ -3,6 +3,7 @@ export * from "./hooks.js";
|
|
3
3
|
export * from "./provider.js";
|
4
4
|
export * from "./storage/kv-store-context.js";
|
5
5
|
export * from "./media/image.js";
|
6
|
+
export { createCoValueSubscriptionContext, createAccountSubscriptionContext, type CoValueSubscription, } from "jazz-tools/react-core";
|
6
7
|
export { SQLiteDatabaseDriverAsync } from "cojson";
|
7
8
|
export { parseInviteLink } from "jazz-tools";
|
8
9
|
export { createInviteLink, setupKvStore } from "./platform.js";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-native-core/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,yBAAyB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,gCAAgC,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-native-core/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EACL,gCAAgC,EAChC,gCAAgC,EAChC,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,yBAAyB,EACzB,KAAK,uBAAuB,GAC7B,MAAM,gCAAgC,CAAC"}
|
@@ -248,7 +248,10 @@ import {
|
|
248
248
|
useAccount,
|
249
249
|
useCoStateWithSelector,
|
250
250
|
useAccountWithSelector,
|
251
|
-
useSyncConnectionStatus
|
251
|
+
useSyncConnectionStatus,
|
252
|
+
useCoValueSubscription,
|
253
|
+
useAccountSubscription,
|
254
|
+
useSubscriptionSelector
|
252
255
|
} from "jazz-tools/react-core";
|
253
256
|
function useAcceptInviteNative({
|
254
257
|
invitedObjectSchema,
|
@@ -316,7 +319,7 @@ async function setupPeers(options) {
|
|
316
319
|
const CryptoProvider2 = options.CryptoProvider || PureJSCrypto;
|
317
320
|
const crypto = await CryptoProvider2.create();
|
318
321
|
let node = void 0;
|
319
|
-
const
|
322
|
+
const peers = [];
|
320
323
|
const storage = options.storage && options.storage !== "disabled" ? await getSqliteStorageAsync(options.storage) : void 0;
|
321
324
|
if (options.sync.when === "never") {
|
322
325
|
return {
|
@@ -325,7 +328,7 @@ async function setupPeers(options) {
|
|
325
328
|
addConnectionListener: () => () => {
|
326
329
|
},
|
327
330
|
connected: () => false,
|
328
|
-
|
331
|
+
peers,
|
329
332
|
setNode: () => {
|
330
333
|
},
|
331
334
|
crypto,
|
@@ -339,11 +342,11 @@ async function setupPeers(options) {
|
|
339
342
|
if (node) {
|
340
343
|
node.syncManager.addPeer(peer);
|
341
344
|
} else {
|
342
|
-
|
345
|
+
peers.push(peer);
|
343
346
|
}
|
344
347
|
},
|
345
348
|
removePeer: (peer) => {
|
346
|
-
|
349
|
+
peers.splice(peers.indexOf(peer), 1);
|
347
350
|
}
|
348
351
|
});
|
349
352
|
function toggleNetwork(enabled) {
|
@@ -368,7 +371,7 @@ async function setupPeers(options) {
|
|
368
371
|
};
|
369
372
|
},
|
370
373
|
connected: () => wsPeer.connected,
|
371
|
-
|
374
|
+
peers,
|
372
375
|
setNode,
|
373
376
|
crypto,
|
374
377
|
storage
|
@@ -377,7 +380,7 @@ async function setupPeers(options) {
|
|
377
380
|
async function createJazzReactNativeGuestContext(options) {
|
378
381
|
const {
|
379
382
|
toggleNetwork,
|
380
|
-
|
383
|
+
peers,
|
381
384
|
setNode,
|
382
385
|
crypto,
|
383
386
|
storage,
|
@@ -386,7 +389,7 @@ async function createJazzReactNativeGuestContext(options) {
|
|
386
389
|
} = await setupPeers(options);
|
387
390
|
const context = createAnonymousJazzContext({
|
388
391
|
crypto,
|
389
|
-
|
392
|
+
peers,
|
390
393
|
storage
|
391
394
|
});
|
392
395
|
setNode(context.agent.node);
|
@@ -408,7 +411,7 @@ async function createJazzReactNativeGuestContext(options) {
|
|
408
411
|
async function createJazzReactNativeContext(options) {
|
409
412
|
const {
|
410
413
|
toggleNetwork,
|
411
|
-
|
414
|
+
peers,
|
412
415
|
setNode,
|
413
416
|
crypto,
|
414
417
|
storage,
|
@@ -435,7 +438,7 @@ async function createJazzReactNativeContext(options) {
|
|
435
438
|
const context = await createJazzContext({
|
436
439
|
credentials: options.credentials,
|
437
440
|
newAccountProps: options.newAccountProps,
|
438
|
-
|
441
|
+
peers,
|
439
442
|
crypto,
|
440
443
|
defaultProfileName: options.defaultProfileName,
|
441
444
|
AccountSchema: options.AccountSchema,
|
@@ -530,11 +533,12 @@ function JazzProviderCore({
|
|
530
533
|
logOutReplacement,
|
531
534
|
onAnonymousAccountDiscarded,
|
532
535
|
kvStore,
|
533
|
-
CryptoProvider: CryptoProvider2
|
536
|
+
CryptoProvider: CryptoProvider2,
|
537
|
+
authSecretStorageKey
|
534
538
|
}) {
|
535
539
|
setupKvStore(kvStore);
|
536
540
|
const [contextManager] = React2.useState(
|
537
|
-
() => new ReactNativeContextManager()
|
541
|
+
() => new ReactNativeContextManager({ authSecretStorageKey })
|
538
542
|
);
|
539
543
|
const onLogOutRefCallback = useRefCallback(onLogOut);
|
540
544
|
const logOutReplacementRefCallback = useRefCallback(logOutReplacement);
|
@@ -665,6 +669,10 @@ var Image = forwardRef(function Image2({ imageId, width, height, ...props }, ref
|
|
665
669
|
});
|
666
670
|
|
667
671
|
// src/react-native-core/index.ts
|
672
|
+
import {
|
673
|
+
createCoValueSubscriptionContext,
|
674
|
+
createAccountSubscriptionContext
|
675
|
+
} from "jazz-tools/react-core";
|
668
676
|
import { SQLiteDatabaseDriverAsync } from "cojson";
|
669
677
|
import { parseInviteLink as parseInviteLink2 } from "jazz-tools";
|
670
678
|
export {
|
@@ -675,20 +683,25 @@ export {
|
|
675
683
|
ReactNativeContextManager,
|
676
684
|
SQLiteDatabaseDriverAsync,
|
677
685
|
clearUserCredentials,
|
686
|
+
createAccountSubscriptionContext,
|
687
|
+
createCoValueSubscriptionContext,
|
678
688
|
createInviteLink,
|
679
689
|
experimental_useInboxSender,
|
680
690
|
parseInviteLink2 as parseInviteLink,
|
681
691
|
setupKvStore,
|
682
692
|
useAcceptInviteNative,
|
683
693
|
useAccount,
|
694
|
+
useAccountSubscription,
|
684
695
|
useAccountWithSelector,
|
685
696
|
useAuthSecretStorage,
|
686
697
|
useCoState,
|
687
698
|
useCoStateWithSelector,
|
699
|
+
useCoValueSubscription,
|
688
700
|
useDemoAuth,
|
689
701
|
useIsAuthenticated,
|
690
702
|
useJazzContext2 as useJazzContext,
|
691
703
|
usePassphraseAuth,
|
704
|
+
useSubscriptionSelector,
|
692
705
|
useSyncConnectionStatus
|
693
706
|
};
|
694
707
|
//# sourceMappingURL=index.js.map
|