jazz-tools 0.19.21 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/.svelte-kit/__package__/react.d.ts.map +1 -1
  2. package/.svelte-kit/__package__/react.tsx +5 -2
  3. package/.turbo/turbo-build.log +77 -89
  4. package/CHANGELOG.md +84 -0
  5. package/dist/better-auth/auth/react.d.ts.map +1 -1
  6. package/dist/better-auth/auth/react.js +5 -2
  7. package/dist/better-auth/auth/react.js.map +1 -1
  8. package/dist/browser/createBrowserContext.d.ts +1 -2
  9. package/dist/browser/createBrowserContext.d.ts.map +1 -1
  10. package/dist/browser/index.js +1 -8
  11. package/dist/browser/index.js.map +1 -1
  12. package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts +1 -1
  13. package/dist/{chunk-QCTQH5RS.js → chunk-3CAPPS2F.js} +234 -101
  14. package/dist/chunk-3CAPPS2F.js.map +1 -0
  15. package/dist/{chunk-M2HGBOXS.js → chunk-K4D7IMFM.js} +3 -3
  16. package/dist/chunk-K4D7IMFM.js.map +1 -0
  17. package/dist/expo/auth/clerk/index.d.ts.map +1 -1
  18. package/dist/expo/index.js +5 -2
  19. package/dist/expo/index.js.map +1 -1
  20. package/dist/index.js +39 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/inspector/{chunk-YQNK5Y7B.js → chunk-MCTB5ZJC.js} +1 -1
  23. package/dist/inspector/chunk-MCTB5ZJC.js.map +1 -0
  24. package/dist/inspector/contexts/node.d.ts.map +1 -1
  25. package/dist/inspector/{custom-element-KYV64IOC.js → custom-element-5YWVZBWA.js} +1 -1
  26. package/dist/inspector/{custom-element-KYV64IOC.js.map → custom-element-5YWVZBWA.js.map} +1 -1
  27. package/dist/inspector/index.js +3 -3
  28. package/dist/inspector/index.js.map +1 -1
  29. package/dist/inspector/register-custom-element.js +1 -1
  30. package/dist/inspector/standalone.js +1 -1
  31. package/dist/media/{chunk-3LKBM3G3.js → chunk-IRL3KNPO.js} +2 -2
  32. package/dist/media/{chunk-3LKBM3G3.js.map → chunk-IRL3KNPO.js.map} +1 -1
  33. package/dist/media/create-image/react-native.d.ts +1 -1
  34. package/dist/media/create-image/react-native.d.ts.map +1 -1
  35. package/dist/media/index.browser.js +1 -1
  36. package/dist/media/index.js +1 -1
  37. package/dist/media/index.native.js +5 -5
  38. package/dist/media/index.native.js.map +1 -1
  39. package/dist/media/index.server.js +1 -1
  40. package/dist/react/auth/Clerk.d.ts.map +1 -1
  41. package/dist/react/hooks.d.ts +1 -1
  42. package/dist/react/hooks.d.ts.map +1 -1
  43. package/dist/react/index.js +61 -47
  44. package/dist/react/index.js.map +1 -1
  45. package/dist/react/provider.d.ts.map +1 -1
  46. package/dist/react/ssr.js +2 -2
  47. package/dist/react/ssr.js.map +1 -1
  48. package/dist/react-core/chunk-UOYH6JFJ.js +10 -0
  49. package/dist/react-core/chunk-UOYH6JFJ.js.map +1 -0
  50. package/dist/react-core/hooks.d.ts +3 -3
  51. package/dist/react-core/hooks.d.ts.map +1 -1
  52. package/dist/react-core/index.js +27 -25
  53. package/dist/react-core/index.js.map +1 -1
  54. package/dist/react-core/provider.d.ts +2 -3
  55. package/dist/react-core/provider.d.ts.map +1 -1
  56. package/dist/react-core/testing.d.ts.map +1 -1
  57. package/dist/react-core/testing.js +4 -10
  58. package/dist/react-core/testing.js.map +1 -1
  59. package/dist/react-native/index.js +61 -53
  60. package/dist/react-native/index.js.map +1 -1
  61. package/dist/react-native-core/ReactNativeContextManager.d.ts +0 -1
  62. package/dist/react-native-core/ReactNativeContextManager.d.ts.map +1 -1
  63. package/dist/react-native-core/hooks.d.ts +1 -1
  64. package/dist/react-native-core/hooks.d.ts.map +1 -1
  65. package/dist/react-native-core/index.js +58 -50
  66. package/dist/react-native-core/index.js.map +1 -1
  67. package/dist/react-native-core/platform.d.ts +0 -4
  68. package/dist/react-native-core/platform.d.ts.map +1 -1
  69. package/dist/react-native-core/provider.d.ts +2 -1
  70. package/dist/react-native-core/provider.d.ts.map +1 -1
  71. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  72. package/dist/svelte/jazz.class.svelte.js +2 -8
  73. package/dist/svelte/tests/AccountCoState.svelte.test.d.ts +2 -0
  74. package/dist/svelte/tests/AccountCoState.svelte.test.d.ts.map +1 -0
  75. package/dist/svelte/tests/AccountCoState.svelte.test.js +59 -0
  76. package/dist/svelte/tests/CoState.svelte.test.js +23 -0
  77. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
  78. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts +11 -0
  79. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts.map +1 -0
  80. package/dist/testing.js +6 -6
  81. package/dist/testing.js.map +1 -1
  82. package/dist/tools/coValues/coList.d.ts +2 -2
  83. package/dist/tools/coValues/coList.d.ts.map +1 -1
  84. package/dist/tools/coValues/coMap.d.ts +2 -2
  85. package/dist/tools/coValues/deepLoading.d.ts +2 -2
  86. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  87. package/dist/tools/coValues/interfaces.d.ts +32 -0
  88. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  89. package/dist/tools/exports.d.ts +2 -1
  90. package/dist/tools/exports.d.ts.map +1 -1
  91. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  92. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  93. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -2
  94. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +3 -2
  96. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +3 -3
  98. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +3 -2
  100. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +5 -2
  102. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  103. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  104. package/dist/tools/ssr.js +1 -1
  105. package/dist/tools/subscribe/JazzError.d.ts +3 -3
  106. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  107. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  108. package/dist/tools/subscribe/types.d.ts +5 -1
  109. package/dist/tools/subscribe/types.d.ts.map +1 -1
  110. package/dist/tools/testing.d.ts +3 -3
  111. package/dist/tools/testing.d.ts.map +1 -1
  112. package/dist/tools/tests/deleteCoValues.test.d.ts +2 -0
  113. package/dist/tools/tests/deleteCoValues.test.d.ts.map +1 -0
  114. package/dist/tools/tests/deletedState.test.d.ts +2 -0
  115. package/dist/tools/tests/deletedState.test.d.ts.map +1 -0
  116. package/dist/worker/JazzMessageChannel.d.ts +36 -0
  117. package/dist/worker/JazzMessageChannel.d.ts.map +1 -0
  118. package/dist/worker/edge-wasm.js +2 -1
  119. package/dist/worker/edge-wasm.js.map +1 -1
  120. package/dist/worker/index.d.ts +7 -1
  121. package/dist/worker/index.d.ts.map +1 -1
  122. package/dist/worker/index.js +28 -17
  123. package/dist/worker/index.js.map +1 -1
  124. package/dist/worker/wasm.d.ts +2 -0
  125. package/dist/worker/wasm.d.ts.map +1 -0
  126. package/package.json +9 -28
  127. package/src/better-auth/auth/react.tsx +5 -2
  128. package/src/browser/createBrowserContext.ts +2 -5
  129. package/src/expo/auth/clerk/index.tsx +5 -2
  130. package/src/inspector/contexts/node.tsx +1 -2
  131. package/src/inspector/index.tsx +2 -2
  132. package/src/media/create-image/react-native.ts +9 -7
  133. package/src/media/create-image-factory.test.ts +1 -1
  134. package/src/media/create-image-factory.ts +1 -1
  135. package/src/react/auth/Clerk.tsx +5 -2
  136. package/src/react/auth/PasskeyAuth.tsx +2 -2
  137. package/src/react/hooks.tsx +3 -2
  138. package/src/react/provider.tsx +45 -41
  139. package/src/react-core/auth/DemoAuth.tsx +2 -2
  140. package/src/react-core/auth/PassphraseAuth.tsx +2 -2
  141. package/src/react-core/hooks.ts +26 -27
  142. package/src/react-core/provider.tsx +1 -5
  143. package/src/react-core/testing.tsx +3 -11
  144. package/src/react-core/tests/testUtils.tsx +2 -2
  145. package/src/react-core/tests/useAccount.selector.test.ts +2 -3
  146. package/src/react-core/tests/useAccount.test.ts +57 -7
  147. package/src/react-core/tests/useCoState.test.ts +37 -0
  148. package/src/react-core/tests/useInboxSender.test.ts +2 -5
  149. package/src/react-core/tests/useSuspenseAccount.test.tsx +68 -0
  150. package/src/react-core/tests/useSuspenseCoState.test.tsx +44 -0
  151. package/src/react-native-core/ReactNativeContextManager.ts +0 -3
  152. package/src/react-native-core/auth/usePasskeyAuth.tsx +2 -2
  153. package/src/react-native-core/hooks.tsx +3 -3
  154. package/src/react-native-core/platform.ts +2 -6
  155. package/src/react-native-core/provider.tsx +47 -43
  156. package/src/svelte/jazz.class.svelte.ts +2 -8
  157. package/src/svelte/tests/AccountCoState.svelte.test.ts +79 -0
  158. package/src/svelte/tests/CoState.svelte.test.ts +36 -0
  159. package/src/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
  160. package/src/tools/coValues/deepLoading.ts +2 -0
  161. package/src/tools/coValues/interfaces.ts +170 -32
  162. package/src/tools/exports.ts +6 -0
  163. package/src/tools/implementation/ContextManager.ts +2 -2
  164. package/src/tools/implementation/createContext.ts +4 -0
  165. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +30 -6
  166. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +55 -7
  167. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +33 -14
  168. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +35 -6
  169. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +35 -14
  170. package/src/tools/ssr/ssr.ts +2 -2
  171. package/src/tools/subscribe/CoValueCoreSubscription.ts +1 -0
  172. package/src/tools/subscribe/JazzError.ts +4 -1
  173. package/src/tools/subscribe/SubscriptionScope.ts +23 -0
  174. package/src/tools/subscribe/types.ts +5 -0
  175. package/src/tools/testing.ts +5 -5
  176. package/src/tools/tests/PassphraseAuth.test.ts +5 -5
  177. package/src/tools/tests/deleteCoValues.test.ts +231 -0
  178. package/src/tools/tests/deletedState.test.ts +110 -0
  179. package/src/tools/tests/request.test.ts +15 -2
  180. package/src/tools/tests/testStorage.ts +2 -2
  181. package/src/worker/JazzMessageChannel.ts +73 -0
  182. package/src/worker/edge-wasm.ts +2 -1
  183. package/src/worker/index.ts +36 -17
  184. package/src/worker/wasm.ts +1 -0
  185. package/tsup.config.ts +0 -4
  186. package/dist/browser/storageOptions.d.ts +0 -8
  187. package/dist/browser/storageOptions.d.ts.map +0 -1
  188. package/dist/browser/tests/storageOptions.test.d.ts +0 -2
  189. package/dist/browser/tests/storageOptions.test.d.ts.map +0 -1
  190. package/dist/chunk-M2HGBOXS.js.map +0 -1
  191. package/dist/chunk-QCTQH5RS.js.map +0 -1
  192. package/dist/expo/crypto.d.ts +0 -2
  193. package/dist/expo/crypto.d.ts.map +0 -1
  194. package/dist/expo/crypto.js +0 -6
  195. package/dist/expo/crypto.js.map +0 -1
  196. package/dist/inspector/chunk-YQNK5Y7B.js.map +0 -1
  197. package/dist/react-core/chunk-7DYMJ74I.js +0 -12
  198. package/dist/react-core/chunk-7DYMJ74I.js.map +0 -1
  199. package/dist/react-native/chunk-DGUM43GV.js +0 -11
  200. package/dist/react-native/chunk-DGUM43GV.js.map +0 -1
  201. package/dist/react-native/crypto.d.ts +0 -2
  202. package/dist/react-native/crypto.d.ts.map +0 -1
  203. package/dist/react-native/crypto.js +0 -8
  204. package/dist/react-native/crypto.js.map +0 -1
  205. package/dist/react-native-core/chunk-DGUM43GV.js +0 -11
  206. package/dist/react-native-core/chunk-DGUM43GV.js.map +0 -1
  207. package/dist/react-native-core/crypto/RNCrypto.d.ts +0 -2
  208. package/dist/react-native-core/crypto/RNCrypto.d.ts.map +0 -1
  209. package/dist/react-native-core/crypto/RNCrypto.js +0 -3
  210. package/dist/react-native-core/crypto/RNCrypto.js.map +0 -1
  211. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts +0 -17
  212. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts.map +0 -1
  213. package/dist/react-native-core/crypto/index.d.ts +0 -2
  214. package/dist/react-native-core/crypto/index.d.ts.map +0 -1
  215. package/dist/react-native-core/crypto.js +0 -89
  216. package/dist/react-native-core/crypto.js.map +0 -1
  217. package/src/browser/storageOptions.ts +0 -17
  218. package/src/browser/tests/storageOptions.test.ts +0 -33
  219. package/src/expo/crypto.ts +0 -1
  220. package/src/react-native/crypto.ts +0 -1
  221. package/src/react-native-core/crypto/RNCrypto.ts +0 -1
  222. package/src/react-native-core/crypto/RNQuickCrypto.ts +0 -122
  223. package/src/react-native-core/crypto/index.ts +0 -1
package/package.json CHANGED
@@ -52,11 +52,6 @@
52
52
  "types": "./dist/expo/index.d.ts",
53
53
  "default": "./dist/expo/index.js"
54
54
  },
55
- "./expo/crypto": {
56
- "@jazz-tools/source": "./src/expo/crypto.ts",
57
- "types": "./dist/expo/crypto.d.ts",
58
- "default": "./dist/expo/crypto.js"
59
- },
60
55
  "./expo/testing": {
61
56
  "@jazz-tools/source": "./src/expo/testing.tsx",
62
57
  "types": "./dist/expo/testing.d.ts",
@@ -116,11 +111,6 @@
116
111
  "types": "./dist/react-native/index.d.ts",
117
112
  "default": "./dist/react-native/index.js"
118
113
  },
119
- "./react-native/crypto": {
120
- "@jazz-tools/source": "./src/react-native/crypto.ts",
121
- "types": "./dist/react-native/crypto.d.ts",
122
- "default": "./dist/react-native/crypto.js"
123
- },
124
114
  "./react-native/testing": {
125
115
  "@jazz-tools/source": "./src/react-native/testing.tsx",
126
116
  "types": "./dist/react-native/testing.d.ts",
@@ -135,11 +125,6 @@
135
125
  "types": "./dist/react-native-core/index.d.ts",
136
126
  "default": "./dist/react-native-core/index.js"
137
127
  },
138
- "./react-native-core/crypto": {
139
- "@jazz-tools/source": "./src/react-native-core/crypto/index.ts",
140
- "types": "./dist/react-native-core/crypto.d.ts",
141
- "default": "./dist/react-native-core/crypto.js"
142
- },
143
128
  "./react-native-core/testing": {
144
129
  "@jazz-tools/source": "./src/react-native-core/testing.tsx",
145
130
  "types": "./dist/react-native-core/testing.d.ts",
@@ -198,20 +183,20 @@
198
183
  "types": "./dist/worker/edge-wasm.d.ts",
199
184
  "default": "./dist/worker/edge-wasm.js"
200
185
  },
186
+ "./wasm": {
187
+ "@jazz-tools/source": "./src/worker/wasm.ts",
188
+ "types": "./dist/worker/wasm.d.ts",
189
+ "default": "./dist/worker/wasm.js"
190
+ },
201
191
  "./napi": {
202
192
  "@jazz-tools/source": "./src/worker/napi-crypto.ts",
203
193
  "types": "./dist/worker/napi-crypto.d.ts",
204
194
  "default": "./dist/worker/napi-crypto.js"
205
- },
206
- "./react-native-core/crypto/RNCrypto": {
207
- "@jazz-tools/source": "./src/react-native-core/crypto/RNCrypto.ts",
208
- "types": "./dist/react-native-core/crypto/RNCrypto.d.ts",
209
- "default": "./dist/react-native-core/crypto/RNCrypto.js"
210
195
  }
211
196
  },
212
197
  "type": "module",
213
198
  "license": "MIT",
214
- "version": "0.19.21",
199
+ "version": "0.20.0",
215
200
  "dependencies": {
216
201
  "@manuscripts/prosemirror-recreate-steps": "^0.1.4",
217
202
  "@scure/base": "1.2.1",
@@ -228,9 +213,9 @@
228
213
  "prosemirror-transform": "^1.9.0",
229
214
  "use-sync-external-store": "^1.5.0",
230
215
  "zod": "4.1.11",
231
- "cojson": "0.19.21",
232
- "cojson-storage-indexeddb": "0.19.21",
233
- "cojson-transport-ws": "0.19.21"
216
+ "cojson": "0.20.0",
217
+ "cojson-storage-indexeddb": "0.20.0",
218
+ "cojson-transport-ws": "0.20.0"
234
219
  },
235
220
  "devDependencies": {
236
221
  "@scure/bip39": "^1.3.0",
@@ -270,7 +255,6 @@
270
255
  "react-native-mmkv": "^3.3.0",
271
256
  "react-native-nitro-modules": "^0.26.4",
272
257
  "react-native-passkey": "^3.0.0",
273
- "react-native-quick-crypto": "^1.0.0-beta.21",
274
258
  "sharp": "^0.33.5",
275
259
  "svelte": "^5.0.0"
276
260
  },
@@ -320,9 +304,6 @@
320
304
  "react-native-passkey": {
321
305
  "optional": true
322
306
  },
323
- "react-native-quick-crypto": {
324
- "optional": true
325
- },
326
307
  "sharp": {
327
308
  "optional": true
328
309
  },
@@ -1,7 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  import { createAuthClient } from "better-auth/client";
4
- import { useAuthSecretStorage, useJazzContext } from "jazz-tools/react-core";
4
+ import {
5
+ useAuthSecretStorage,
6
+ useJazzContextValue,
7
+ } from "jazz-tools/react-core";
5
8
  import { useEffect } from "react";
6
9
  import { type PropsWithChildren } from "react";
7
10
  import { jazzPluginClient } from "./client.js";
@@ -35,7 +38,7 @@ export function AuthProvider({
35
38
  }: PropsWithChildren<{
36
39
  betterAuthClient: AuthClient;
37
40
  }>) {
38
- const context = useJazzContext();
41
+ const context = useJazzContextValue();
39
42
  const authSecretStorage = useAuthSecretStorage();
40
43
 
41
44
  if (betterAuthClient.jazz === undefined) {
@@ -21,7 +21,6 @@ import {
21
21
  createAnonymousJazzContext,
22
22
  } from "jazz-tools";
23
23
  import { createJazzContext } from "jazz-tools";
24
- import { StorageConfig, getStorageOptions } from "./storageOptions.js";
25
24
  import { setupInspector } from "./utils/export-account-inspector.js";
26
25
  import { getBrowserLockSessionProvider } from "./provideBrowserLockSession/index.js";
27
26
 
@@ -30,7 +29,7 @@ setupInspector();
30
29
  export type BaseBrowserContextOptions = {
31
30
  sync: SyncConfig;
32
31
  reconnectionTimeout?: number;
33
- storage?: StorageConfig;
32
+ storage?: "indexedDB";
34
33
  crypto?: CryptoProvider;
35
34
  authSecretStorage: AuthSecretStorage;
36
35
  };
@@ -52,11 +51,9 @@ async function setupPeers(options: BaseBrowserContextOptions) {
52
51
  const crypto = options.crypto || (await WasmCrypto.create());
53
52
  let node: LocalNode | undefined = undefined;
54
53
 
55
- const { useIndexedDB } = getStorageOptions(options.storage);
56
-
57
54
  const peers: Peer[] = [];
58
55
 
59
- const storage = useIndexedDB ? await getIndexedDBStorage() : undefined;
56
+ const storage = await getIndexedDBStorage();
60
57
 
61
58
  if (options.sync.when === "never") {
62
59
  return {
@@ -6,7 +6,10 @@ import {
6
6
  CoValueFromRaw,
7
7
  KvStoreContext,
8
8
  } from "jazz-tools";
9
- import { useAuthSecretStorage, useJazzContext } from "jazz-tools/react-core";
9
+ import {
10
+ useAuthSecretStorage,
11
+ useJazzContextValue,
12
+ } from "jazz-tools/react-core";
10
13
  import { JazzProviderProps } from "jazz-tools/react-native-core";
11
14
  import React from "react";
12
15
  import { useEffect, useMemo, useState } from "react";
@@ -14,7 +17,7 @@ import { JazzExpoProvider } from "../../provider.js";
14
17
  import { ExpoSecureStoreAdapter } from "../../storage/expo-secure-store-adapter.js";
15
18
 
16
19
  function useJazzClerkAuth(clerk: MinimalClerkClient) {
17
- const context = useJazzContext();
20
+ const context = useJazzContextValue();
18
21
  const authSecretStorage = useAuthSecretStorage();
19
22
 
20
23
  if ("guest" in context) {
@@ -7,7 +7,6 @@ import {
7
7
  } from "react";
8
8
  import { CoID, LocalNode, RawAccount } from "cojson";
9
9
  import { WasmCrypto } from "cojson/crypto/WasmCrypto";
10
- import type { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
11
10
  import { createWebSocketPeer } from "cojson-transport-ws";
12
11
 
13
12
  type NodeContextType = {
@@ -40,7 +39,7 @@ type NodeProviderProps = PropsWithChildren<{
40
39
  server?: string;
41
40
  }>;
42
41
 
43
- let crypto: WasmCrypto | PureJSCrypto | null = null;
42
+ let crypto: WasmCrypto | null = null;
44
43
 
45
44
  async function getCrypto() {
46
45
  if (crypto) return crypto;
@@ -1,12 +1,12 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
  import { setup } from "goober";
3
- import { useJazzContext } from "jazz-tools/react-core";
3
+ import { useJazzContextValue } from "jazz-tools/react-core";
4
4
  import { Account } from "jazz-tools";
5
5
  import { InspectorInApp } from "./in-app.js";
6
6
  import { Position } from "./viewer/inspector-button.js";
7
7
 
8
8
  export function JazzInspector({ position = "right" }: { position?: Position }) {
9
- const context = useJazzContext<Account>();
9
+ const context = useJazzContextValue<Account>();
10
10
  const localNode = context.node;
11
11
  const me = "me" in context ? context.me : undefined;
12
12
 
@@ -1,8 +1,7 @@
1
- import { NativeModules } from "react-native";
2
1
  import type ImageResizerType from "@bam.tech/react-native-image-resizer";
3
2
  import type ImageManipulatorType from "expo-image-manipulator";
4
3
  import type { Account, Group } from "jazz-tools";
5
- import { FileStream } from "jazz-tools";
4
+ import { co, type FileStream } from "jazz-tools";
6
5
  import { Image } from "react-native";
7
6
  import { createImageFactory } from "../create-image-factory";
8
7
 
@@ -108,7 +107,8 @@ async function getPlaceholderBase64(filePath: string): Promise<string> {
108
107
  );
109
108
  }
110
109
 
111
- return base64;
110
+ // Convert base64 to data URL
111
+ return "data:image/png;base64," + base64;
112
112
  }
113
113
  }
114
114
 
@@ -147,7 +147,7 @@ async function resize(
147
147
  }
148
148
  }
149
149
 
150
- function getMimeType(filePath: string): Promise<string> {
150
+ async function getMimeType(filePath: string): Promise<string> {
151
151
  return fetch(filePath)
152
152
  .then((res) => res.blob())
153
153
  .then((blob) => blob.type);
@@ -167,9 +167,11 @@ export async function createFileStreamFromSource(
167
167
  const blob = await fetch(filePath).then((res) => res.blob());
168
168
  const arrayBuffer = await toArrayBuffer(blob);
169
169
 
170
- return FileStream.createFromArrayBuffer(arrayBuffer, blob.type, undefined, {
171
- owner,
172
- });
170
+ return co
171
+ .fileStream()
172
+ .createFromArrayBuffer(arrayBuffer, blob.type, undefined, {
173
+ owner,
174
+ });
173
175
  }
174
176
 
175
177
  // TODO: look for more efficient way to do this as React Native hasn't blob.arrayBuffer()
@@ -162,8 +162,8 @@ describe("createImage", async () => {
162
162
  expect(image).toBeDefined();
163
163
  expect(image.originalSize).toEqual([1920, 400]);
164
164
  expect(image.placeholderDataURL).not.toBeDefined();
165
-
166
165
  expect(image[`256x53`]).toBeDefined();
166
+ expect(image[`512x107`]).toBeDefined();
167
167
  expect(image[`1024x213`]).toBeDefined();
168
168
  expect(image[`2048x427`]).not.toBeDefined();
169
169
 
@@ -154,7 +154,7 @@ async function createImage<TSourceType, TResizeOutput>(
154
154
  if (options?.progressive) {
155
155
  imageCoValue.$jazz.set("progressive", true);
156
156
 
157
- const resizes = ([256, 1024, 2048] as const).filter(
157
+ const resizes = ([256, 512, 1024, 2048] as const).filter(
158
158
  (s) =>
159
159
  s <
160
160
  Math.max(imageCoValue.originalSize[0], imageCoValue.originalSize[1]),
@@ -8,12 +8,15 @@ import {
8
8
  KvStoreContext,
9
9
  } from "jazz-tools";
10
10
  import { LocalStorageKVStore } from "jazz-tools/browser";
11
- import { useAuthSecretStorage, useJazzContext } from "jazz-tools/react-core";
11
+ import {
12
+ useAuthSecretStorage,
13
+ useJazzContextValue,
14
+ } from "jazz-tools/react-core";
12
15
  import { ReactNode, useEffect, useMemo, useState } from "react";
13
16
  import { JazzProviderProps, JazzReactProvider } from "../provider.js";
14
17
 
15
18
  function useJazzClerkAuth(clerk: MinimalClerkClient) {
16
- const context = useJazzContext();
19
+ const context = useJazzContextValue();
17
20
  const authSecretStorage = useAuthSecretStorage();
18
21
 
19
22
  if ("guest" in context) {
@@ -2,7 +2,7 @@ import { BrowserPasskeyAuth } from "jazz-tools/browser";
2
2
  import {
3
3
  useAuthSecretStorage,
4
4
  useIsAuthenticated,
5
- useJazzContext,
5
+ useJazzContextValue,
6
6
  } from "jazz-tools/react-core";
7
7
  import { useMemo, useState } from "react";
8
8
 
@@ -23,7 +23,7 @@ export function usePasskeyAuth({
23
23
  appName: string;
24
24
  appHostname?: string;
25
25
  }) {
26
- const context = useJazzContext();
26
+ const context = useJazzContextValue();
27
27
  const authSecretStorage = useAuthSecretStorage();
28
28
 
29
29
  if ("guest" in context) {
@@ -2,7 +2,7 @@ import { consumeInviteLinkFromWindowLocation } from "jazz-tools/browser";
2
2
  import { useEffect } from "react";
3
3
 
4
4
  import { CoValueClassOrSchema } from "jazz-tools";
5
- import { useJazzContext } from "jazz-tools/react-core";
5
+ import { useJazzContextValue } from "jazz-tools/react-core";
6
6
 
7
7
  export function useAcceptInvite<S extends CoValueClassOrSchema>({
8
8
  invitedObjectSchema,
@@ -13,7 +13,7 @@ export function useAcceptInvite<S extends CoValueClassOrSchema>({
13
13
  onAccept: (valueID: string) => void;
14
14
  forValueHint?: string;
15
15
  }): void {
16
- const context = useJazzContext();
16
+ const context = useJazzContextValue();
17
17
 
18
18
  if (!("me" in context)) {
19
19
  throw new Error(
@@ -46,6 +46,7 @@ export function useAcceptInvite<S extends CoValueClassOrSchema>({
46
46
 
47
47
  export {
48
48
  experimental_useInboxSender,
49
+ useJazzContextValue,
49
50
  useJazzContext,
50
51
  useAuthSecretStorage,
51
52
  useAccount,
@@ -3,15 +3,20 @@ import {
3
3
  AccountClass,
4
4
  AnyAccountSchema,
5
5
  CoValueFromRaw,
6
- InstanceOfSchema,
7
- JazzContextType,
8
6
  } from "jazz-tools";
9
7
  import {
10
8
  JazzBrowserContextManager,
11
9
  JazzContextManagerProps,
12
10
  } from "jazz-tools/browser";
13
- import { JazzContext, JazzContextManagerContext } from "jazz-tools/react-core";
14
- import React, { useEffect, useRef } from "react";
11
+ import { JazzContext } from "jazz-tools/react-core";
12
+ import React, {
13
+ useCallback,
14
+ useContext,
15
+ useEffect,
16
+ useMemo,
17
+ useRef,
18
+ useSyncExternalStore,
19
+ } from "react";
15
20
 
16
21
  export type JazzProviderProps<
17
22
  S extends
@@ -43,6 +48,12 @@ export function JazzReactProvider<
43
48
  fallback = null,
44
49
  authSecretStorageKey,
45
50
  }: JazzProviderProps<S>) {
51
+ if (useContext(JazzContext)) {
52
+ throw new Error(
53
+ "You can't nest a JazzProvider inside another JazzProvider.",
54
+ );
55
+ }
56
+
46
57
  const [contextManager] = React.useState(
47
58
  () =>
48
59
  new JazzBrowserContextManager<S>({
@@ -56,45 +67,40 @@ export function JazzReactProvider<
56
67
  const onAnonymousAccountDiscardedRefCallback = useRefCallback(
57
68
  onAnonymousAccountDiscarded,
58
69
  );
59
- const logoutReplacementActiveRef = useRef(false);
60
- logoutReplacementActiveRef.current = Boolean(logOutReplacement);
61
- const onAnonymousAccountDiscardedEnabled = Boolean(
62
- onAnonymousAccountDiscarded,
63
- );
64
70
 
65
- const value = React.useSyncExternalStore<
66
- JazzContextType<InstanceOfSchema<S>> | undefined
67
- >(
68
- React.useCallback(
69
- (callback) => {
70
- const props = {
71
- AccountSchema,
72
- guestMode,
73
- sync,
74
- storage,
75
- defaultProfileName,
76
- onLogOut: onLogOutRefCallback,
77
- logOutReplacement: logoutReplacementActiveRef.current
78
- ? logOutReplacementRefCallback
79
- : undefined,
80
- onAnonymousAccountDiscarded: onAnonymousAccountDiscardedEnabled
81
- ? onAnonymousAccountDiscardedRefCallback
82
- : undefined,
83
- } satisfies JazzContextManagerProps<S>;
71
+ const props = useMemo(() => {
72
+ return {
73
+ AccountSchema,
74
+ guestMode,
75
+ sync,
76
+ storage,
77
+ defaultProfileName,
78
+ onLogOut: onLogOutRefCallback,
79
+ logOutReplacement: logOutReplacement
80
+ ? logOutReplacementRefCallback
81
+ : undefined,
82
+ onAnonymousAccountDiscarded: onAnonymousAccountDiscarded
83
+ ? onAnonymousAccountDiscardedRefCallback
84
+ : undefined,
85
+ } satisfies JazzContextManagerProps<S>;
86
+ }, [guestMode, sync.peer, sync.when, storage]);
84
87
 
85
- if (contextManager.propsChanged(props)) {
86
- contextManager.createContext(props).catch((error) => {
87
- console.log(error.stack);
88
- console.error("Error creating Jazz browser context:", error);
89
- });
90
- }
88
+ if (contextManager.propsChanged(props) && typeof window !== "undefined") {
89
+ contextManager.createContext(props).catch((error) => {
90
+ console.log(error.stack);
91
+ console.error("Error creating Jazz browser context:", error);
92
+ });
93
+ }
91
94
 
95
+ const isReady = useSyncExternalStore(
96
+ useCallback(
97
+ (callback) => {
92
98
  return contextManager.subscribe(callback);
93
99
  },
94
- [sync, guestMode].concat(storage as any),
100
+ [contextManager],
95
101
  ),
96
- () => contextManager.getCurrentValue(),
97
- () => contextManager.getCurrentValue(),
102
+ () => Boolean(contextManager.getCurrentValue()),
103
+ () => Boolean(contextManager.getCurrentValue()),
98
104
  );
99
105
 
100
106
  useEffect(() => {
@@ -108,10 +114,8 @@ export function JazzReactProvider<
108
114
  }, []);
109
115
 
110
116
  return (
111
- <JazzContext.Provider value={value}>
112
- <JazzContextManagerContext.Provider value={contextManager}>
113
- {value ? children : fallback}
114
- </JazzContextManagerContext.Provider>
117
+ <JazzContext.Provider value={contextManager}>
118
+ {isReady ? children : fallback}
115
119
  </JazzContext.Provider>
116
120
  );
117
121
  }
@@ -1,6 +1,6 @@
1
1
  import { DemoAuth } from "jazz-tools";
2
2
  import { useEffect, useMemo, useState } from "react";
3
- import { useAuthSecretStorage, useJazzContext } from "../hooks.js";
3
+ import { useAuthSecretStorage, useJazzContextValue } from "../hooks.js";
4
4
  import { useIsAuthenticated } from "../hooks.js";
5
5
 
6
6
  /**
@@ -14,7 +14,7 @@ import { useIsAuthenticated } from "../hooks.js";
14
14
  * @category Auth Providers
15
15
  */
16
16
  export function useDemoAuth() {
17
- const context = useJazzContext();
17
+ const context = useJazzContextValue();
18
18
  const authSecretStorage = useAuthSecretStorage();
19
19
 
20
20
  if ("guest" in context) {
@@ -1,6 +1,6 @@
1
1
  import { PassphraseAuth } from "jazz-tools";
2
2
  import { useCallback, useMemo, useSyncExternalStore } from "react";
3
- import { useAuthSecretStorage, useJazzContext } from "../hooks.js";
3
+ import { useAuthSecretStorage, useJazzContextValue } from "../hooks.js";
4
4
  import { useIsAuthenticated } from "../hooks.js";
5
5
 
6
6
  /**
@@ -14,7 +14,7 @@ import { useIsAuthenticated } from "../hooks.js";
14
14
  * @category Auth Providers
15
15
  */
16
16
  export function usePassphraseAuth({ wordlist }: { wordlist: string[] }) {
17
- const context = useJazzContext();
17
+ const context = useJazzContextValue();
18
18
  const authSecretStorage = useAuthSecretStorage();
19
19
 
20
20
  if ("guest" in context) {
@@ -19,7 +19,6 @@ import {
19
19
  InboxSender,
20
20
  InstanceOfSchema,
21
21
  JazzContextManager,
22
- JazzContextType,
23
22
  Loaded,
24
23
  MaybeLoaded,
25
24
  NotLoaded,
@@ -32,13 +31,13 @@ import {
32
31
  getUnloadedCoValueWithoutId,
33
32
  type BranchDefinition,
34
33
  } from "jazz-tools";
35
- import { JazzContext, JazzContextManagerContext } from "./provider.js";
34
+ import { JazzContext } from "./provider.js";
36
35
  import { getCurrentAccountFromContextManager } from "./utils.js";
37
36
  import { CoValueSubscription } from "./types.js";
38
37
  import { use } from "./use.js";
39
38
 
40
39
  export function useJazzContext<Acc extends Account>() {
41
- const value = useContext(JazzContext) as JazzContextType<Acc>;
40
+ const value = useContext(JazzContext) as JazzContextManager<Acc, {}>;
42
41
 
43
42
  if (!value) {
44
43
  throw new Error(
@@ -49,31 +48,31 @@ export function useJazzContext<Acc extends Account>() {
49
48
  return value;
50
49
  }
51
50
 
52
- export function useJazzContextManager<Acc extends Account>() {
53
- const value = useContext(JazzContextManagerContext) as JazzContextManager<
54
- Acc,
55
- {}
56
- >;
51
+ export function useJazzContextValue<Acc extends Account>() {
52
+ const contextManager = useJazzContext<Acc>();
57
53
 
58
- if (!value) {
54
+ const context = useSyncExternalStore(
55
+ useCallback(
56
+ (callback) => {
57
+ return contextManager.subscribe(callback);
58
+ },
59
+ [contextManager],
60
+ ),
61
+ () => contextManager.getCurrentValue(),
62
+ () => contextManager.getCurrentValue(),
63
+ );
64
+
65
+ if (!context) {
59
66
  throw new Error(
60
- "You need to set up a JazzProvider on top of your app to use this hook.",
67
+ "The JazzProvider is not initialized yet. This looks like a bug, please report it.",
61
68
  );
62
69
  }
63
70
 
64
- return value;
71
+ return context;
65
72
  }
66
73
 
67
74
  export function useAuthSecretStorage() {
68
- const value = useContext(JazzContextManagerContext);
69
-
70
- if (!value) {
71
- throw new Error(
72
- "You need to set up a JazzProvider on top of your app to use this useAuthSecretStorage.",
73
- );
74
- }
75
-
76
- return value.getAuthSecretStorage();
75
+ return useJazzContext().getAuthSecretStorage();
77
76
  }
78
77
 
79
78
  export function useIsAuthenticated() {
@@ -122,7 +121,7 @@ interface SubscriptionsState {
122
121
  schema: CoValueClassOrSchema;
123
122
  ids: readonly (string | undefined | null)[];
124
123
  resolve: ResolveQuery<any>;
125
- contextManager: ReturnType<typeof useJazzContextManager>;
124
+ contextManager: ReturnType<typeof useJazzContext>;
126
125
  agent: AnonymousJazzAgent | Loaded<any, true>;
127
126
  branchName?: string;
128
127
  branchOwnerId?: string;
@@ -142,7 +141,7 @@ function useCoValueSubscriptions(
142
141
  resolve: ResolveQuery<any>,
143
142
  branch?: BranchDefinition,
144
143
  ): (SubscriptionScope<CoValue> | null)[] {
145
- const contextManager = useJazzContextManager();
144
+ const contextManager = useJazzContext();
146
145
  const agent = useAgent();
147
146
 
148
147
  const callerStack = useMemo(() => captureStack(), []);
@@ -536,7 +535,7 @@ export function useAccountSubscription<
536
535
  unstable_branch?: BranchDefinition;
537
536
  },
538
537
  ) {
539
- const contextManager = useJazzContextManager();
538
+ const contextManager = useJazzContext();
540
539
 
541
540
  // Capture stack trace at hook call time
542
541
  const callerStack = useMemo(() => captureStack(), []);
@@ -783,7 +782,7 @@ export function useSuspenseAccount<
783
782
  * Returns a function for logging out of the current account.
784
783
  */
785
784
  export function useLogOut(): () => void {
786
- const contextManager = useJazzContextManager();
785
+ const contextManager = useJazzContext();
787
786
  return contextManager.logOut;
788
787
  }
789
788
 
@@ -798,7 +797,7 @@ export function useLogOut(): () => void {
798
797
  export function useAgent<
799
798
  A extends AccountClass<Account> | AnyAccountSchema = typeof Account,
800
799
  >(): AnonymousJazzAgent | Loaded<A, true> {
801
- const contextManager = useJazzContextManager<InstanceOfSchema<A>>();
800
+ const contextManager = useJazzContext<InstanceOfSchema<A>>();
802
801
 
803
802
  const getCurrentValue = () =>
804
803
  getCurrentAccountFromContextManager(contextManager) as
@@ -821,7 +820,7 @@ export function experimental_useInboxSender<
821
820
  I extends CoValue,
822
821
  O extends CoValue | undefined,
823
822
  >(inboxOwnerID: string | undefined) {
824
- const context = useJazzContext();
823
+ const context = useJazzContextValue();
825
824
 
826
825
  if (!("me" in context)) {
827
826
  throw new Error(
@@ -868,7 +867,7 @@ export function experimental_useInboxSender<
868
867
  * after 5 seconds of not receiving a ping from the server.
869
868
  */
870
869
  export function useSyncConnectionStatus() {
871
- const context = useJazzContext();
870
+ const context = useJazzContextValue();
872
871
 
873
872
  const connected = useSyncExternalStore(
874
873
  useCallback(
@@ -1,11 +1,7 @@
1
1
  import React from "react";
2
2
 
3
- import { Account, JazzContextManager, JazzContextType } from "jazz-tools";
3
+ import { Account, JazzContextManager } from "jazz-tools";
4
4
 
5
5
  export const JazzContext = React.createContext<
6
- JazzContextType<Account> | undefined
7
- >(undefined);
8
-
9
- export const JazzContextManagerContext = React.createContext<
10
6
  JazzContextManager<Account, {}> | undefined
11
7
  >(undefined);
@@ -1,7 +1,7 @@
1
1
  import { Account, AnonymousJazzAgent } from "jazz-tools";
2
2
  import { TestJazzContextManager } from "jazz-tools/testing";
3
3
  import { useCallback, useState, useSyncExternalStore } from "react";
4
- import { JazzContext, JazzContextManagerContext } from "./provider.js";
4
+ import { JazzContext } from "./provider.js";
5
5
 
6
6
  export function JazzTestProvider<Acc extends Account>({
7
7
  children,
@@ -18,17 +18,9 @@ export function JazzTestProvider<Acc extends Account>({
18
18
  });
19
19
  });
20
20
 
21
- const value = useSyncExternalStore(
22
- useCallback((callback) => contextManager.subscribe(callback), []),
23
- () => contextManager.getCurrentValue(),
24
- () => contextManager.getCurrentValue(),
25
- );
26
-
27
21
  return (
28
- <JazzContext.Provider value={value}>
29
- <JazzContextManagerContext.Provider value={contextManager}>
30
- {children}
31
- </JazzContextManagerContext.Provider>
22
+ <JazzContext.Provider value={contextManager}>
23
+ {children}
32
24
  </JazzContext.Provider>
33
25
  );
34
26
  }