jazz-tools 0.18.37 → 0.19.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 (309) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.d.ts +8 -8
  2. package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
  3. package/.svelte-kit/__package__/jazz.class.svelte.js +39 -14
  4. package/.svelte-kit/__package__/media/image.svelte +6 -5
  5. package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
  6. package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.d.ts +2 -0
  7. package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
  8. package/.svelte-kit/__package__/tests/AccountCoState.svelte.test-d.js +19 -0
  9. package/.svelte-kit/__package__/tests/CoState.svelte.test-d.d.ts +2 -0
  10. package/.svelte-kit/__package__/tests/CoState.svelte.test-d.d.ts.map +1 -0
  11. package/.svelte-kit/__package__/tests/CoState.svelte.test-d.js +16 -0
  12. package/.svelte-kit/__package__/tests/CoState.svelte.test.d.ts +2 -0
  13. package/.svelte-kit/__package__/tests/CoState.svelte.test.d.ts.map +1 -0
  14. package/.svelte-kit/__package__/tests/CoState.svelte.test.js +42 -0
  15. package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte +23 -0
  16. package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte.d.ts +12 -0
  17. package/.svelte-kit/__package__/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
  18. package/.turbo/turbo-build.log +53 -53
  19. package/CHANGELOG.md +33 -0
  20. package/dist/better-auth/database-adapter/index.js +14 -11
  21. package/dist/better-auth/database-adapter/index.js.map +1 -1
  22. package/dist/better-auth/database-adapter/repository/generic.d.ts +1 -1
  23. package/dist/better-auth/database-adapter/repository/generic.d.ts.map +1 -1
  24. package/dist/better-auth/database-adapter/repository/user.d.ts.map +1 -1
  25. package/dist/{chunk-OSQ7S47Q.js → chunk-P3YLNFN4.js} +504 -232
  26. package/dist/chunk-P3YLNFN4.js.map +1 -0
  27. package/dist/index.js +14 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/inspector/{custom-element-SUVJ7CPN.js → custom-element-QESCMFY7.js} +13 -3
  30. package/dist/inspector/{custom-element-SUVJ7CPN.js.map → custom-element-QESCMFY7.js.map} +1 -1
  31. package/dist/inspector/index.js +12 -2
  32. package/dist/inspector/index.js.map +1 -1
  33. package/dist/inspector/register-custom-element.js +1 -1
  34. package/dist/inspector/viewer/history-view.d.ts.map +1 -1
  35. package/dist/media/{chunk-K6GCHLQU.js → chunk-3LKBM3G3.js} +23 -15
  36. package/dist/media/chunk-3LKBM3G3.js.map +1 -0
  37. package/dist/media/create-image/browser.d.ts +2 -2
  38. package/dist/media/create-image/react-native.d.ts +2 -2
  39. package/dist/media/create-image/server.d.ts +2 -2
  40. package/dist/media/create-image-factory.d.ts +2 -2
  41. package/dist/media/index.browser.js +1 -1
  42. package/dist/media/index.js +1 -1
  43. package/dist/media/index.native.js +1 -1
  44. package/dist/media/index.server.js +1 -1
  45. package/dist/media/utils.d.ts.map +1 -1
  46. package/dist/react/hooks.d.ts +1 -1
  47. package/dist/react/hooks.d.ts.map +1 -1
  48. package/dist/react/index.d.ts +1 -1
  49. package/dist/react/index.d.ts.map +1 -1
  50. package/dist/react/index.js +31 -15
  51. package/dist/react/index.js.map +1 -1
  52. package/dist/react/media/image.d.ts.map +1 -1
  53. package/dist/react-core/hooks.d.ts +126 -224
  54. package/dist/react-core/hooks.d.ts.map +1 -1
  55. package/dist/react-core/index.js +65 -63
  56. package/dist/react-core/index.js.map +1 -1
  57. package/dist/react-core/subscription-provider.d.ts.map +1 -1
  58. package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts +2 -0
  59. package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts.map +1 -0
  60. package/dist/react-core/tests/useAccount.selector.test.d.ts +2 -0
  61. package/dist/react-core/tests/useAccount.selector.test.d.ts.map +1 -0
  62. package/dist/react-core/tests/useCoState.selector.test.d.ts +2 -0
  63. package/dist/react-core/tests/useCoState.selector.test.d.ts.map +1 -0
  64. package/dist/react-native-core/hooks.d.ts +1 -1
  65. package/dist/react-native-core/hooks.d.ts.map +1 -1
  66. package/dist/react-native-core/index.js +7 -5
  67. package/dist/react-native-core/index.js.map +1 -1
  68. package/dist/react-native-core/media/image.d.ts.map +1 -1
  69. package/dist/svelte/jazz.class.svelte.d.ts +8 -8
  70. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  71. package/dist/svelte/jazz.class.svelte.js +39 -14
  72. package/dist/svelte/media/image.svelte +6 -5
  73. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  74. package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts +2 -0
  75. package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
  76. package/dist/svelte/tests/AccountCoState.svelte.test-d.js +19 -0
  77. package/dist/svelte/tests/CoState.svelte.test-d.d.ts +2 -0
  78. package/dist/svelte/tests/CoState.svelte.test-d.d.ts.map +1 -0
  79. package/dist/svelte/tests/CoState.svelte.test-d.js +16 -0
  80. package/dist/svelte/tests/CoState.svelte.test.d.ts +2 -0
  81. package/dist/svelte/tests/CoState.svelte.test.d.ts.map +1 -0
  82. package/dist/svelte/tests/CoState.svelte.test.js +42 -0
  83. package/dist/svelte/tests/TestCoStateWrapper.svelte +23 -0
  84. package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts +12 -0
  85. package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
  86. package/dist/testing.js +3 -1
  87. package/dist/testing.js.map +1 -1
  88. package/dist/tools/coValues/CoValueBase.d.ts +4 -1
  89. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  90. package/dist/tools/coValues/account.d.ts +6 -6
  91. package/dist/tools/coValues/account.d.ts.map +1 -1
  92. package/dist/tools/coValues/coFeed.d.ts +5 -5
  93. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  94. package/dist/tools/coValues/coList.d.ts +9 -8
  95. package/dist/tools/coValues/coList.d.ts.map +1 -1
  96. package/dist/tools/coValues/coMap.d.ts +17 -17
  97. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  98. package/dist/tools/coValues/coPlainText.d.ts +3 -3
  99. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  100. package/dist/tools/coValues/coVector.d.ts +3 -3
  101. package/dist/tools/coValues/coVector.d.ts.map +1 -1
  102. package/dist/tools/coValues/deepLoading.d.ts +66 -36
  103. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  104. package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
  105. package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
  106. package/dist/tools/coValues/group.d.ts +2 -2
  107. package/dist/tools/coValues/group.d.ts.map +1 -1
  108. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  109. package/dist/tools/coValues/interfaces.d.ts +14 -6
  110. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  111. package/dist/tools/coValues/request.d.ts.map +1 -1
  112. package/dist/tools/coValues/schemaUnion.d.ts +2 -2
  113. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  114. package/dist/tools/exports.d.ts +3 -3
  115. package/dist/tools/exports.d.ts.map +1 -1
  116. package/dist/tools/implementation/refs.d.ts +3 -3
  117. package/dist/tools/implementation/refs.d.ts.map +1 -1
  118. package/dist/tools/implementation/schema.d.ts +2 -2
  119. package/dist/tools/implementation/schema.d.ts.map +1 -1
  120. package/dist/tools/implementation/schemaUtils.d.ts +8 -0
  121. package/dist/tools/implementation/schemaUtils.d.ts.map +1 -1
  122. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  123. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +33 -18
  124. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  125. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +5 -4
  126. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  127. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +23 -12
  128. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  129. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +29 -18
  130. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  131. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +39 -22
  132. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  133. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +1 -0
  134. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
  135. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +30 -19
  136. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  137. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +5 -0
  138. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -1
  139. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +6 -5
  140. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
  141. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -2
  142. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  143. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +3 -2
  144. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  145. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +3 -2
  146. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  147. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +3 -2
  148. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  149. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +3 -0
  150. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  151. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts +22 -0
  152. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
  153. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +4 -0
  154. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
  155. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts +9 -0
  156. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
  157. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  158. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +7 -6
  159. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  160. package/dist/tools/internal.d.ts +3 -3
  161. package/dist/tools/internal.d.ts.map +1 -1
  162. package/dist/tools/lib/utils.d.ts +14 -0
  163. package/dist/tools/lib/utils.d.ts.map +1 -0
  164. package/dist/tools/lib/utils.test.d.ts +2 -0
  165. package/dist/tools/lib/utils.test.d.ts.map +1 -0
  166. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +3 -2
  167. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  168. package/dist/tools/subscribe/JazzError.d.ts +4 -3
  169. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  170. package/dist/tools/subscribe/SubscriptionScope.d.ts +6 -5
  171. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  172. package/dist/tools/subscribe/index.d.ts.map +1 -1
  173. package/dist/tools/subscribe/types.d.ts +23 -3
  174. package/dist/tools/subscribe/types.d.ts.map +1 -1
  175. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  176. package/dist/tools/testing.d.ts +3 -2
  177. package/dist/tools/testing.d.ts.map +1 -1
  178. package/dist/tools/tests/schema.resolved.test.d.ts +2 -0
  179. package/dist/tools/tests/schema.resolved.test.d.ts.map +1 -0
  180. package/dist/tools/tests/utils.d.ts +2 -1
  181. package/dist/tools/tests/utils.d.ts.map +1 -1
  182. package/package.json +4 -4
  183. package/src/better-auth/database-adapter/index.ts +2 -2
  184. package/src/better-auth/database-adapter/repository/account.ts +3 -3
  185. package/src/better-auth/database-adapter/repository/generic.ts +9 -6
  186. package/src/better-auth/database-adapter/repository/user.ts +6 -2
  187. package/src/better-auth/database-adapter/schema.ts +1 -1
  188. package/src/better-auth/database-adapter/tests/index.test.ts +3 -4
  189. package/src/inspector/tests/viewer/history-view.test.tsx +74 -10
  190. package/src/inspector/viewer/history-view.tsx +14 -5
  191. package/src/media/utils.test.ts +5 -0
  192. package/src/media/utils.ts +25 -16
  193. package/src/react/hooks.tsx +2 -2
  194. package/src/react/index.ts +2 -2
  195. package/src/react/media/image.tsx +10 -2
  196. package/src/react/tests/useAcceptInvite.test.ts +3 -1
  197. package/src/react-core/hooks.ts +226 -304
  198. package/src/react-core/subscription-provider.tsx +14 -7
  199. package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +233 -0
  200. package/src/react-core/tests/subscription.bench.tsx +32 -15
  201. package/src/react-core/tests/{useAccountWithSelector.test.ts → useAccount.selector.test.ts} +72 -24
  202. package/src/react-core/tests/useAccount.test.ts +92 -106
  203. package/src/react-core/tests/{useCoStateWithSelector.test.ts → useCoState.selector.test.ts} +23 -8
  204. package/src/react-core/tests/useCoState.test.ts +173 -49
  205. package/src/react-core/tests/useInboxSender.test.ts +3 -1
  206. package/src/react-core/tests/usePassPhraseAuth.test.ts +11 -82
  207. package/src/react-core/tests/useSubscriptionSelector.test.ts +48 -14
  208. package/src/react-native-core/hooks.tsx +2 -2
  209. package/src/react-native-core/media/image.tsx +3 -1
  210. package/src/svelte/jazz.class.svelte.ts +103 -27
  211. package/src/svelte/media/image.svelte +6 -5
  212. package/src/svelte/tests/AccountCoState.svelte.test-d.ts +23 -0
  213. package/src/svelte/tests/CoState.svelte.test-d.ts +20 -0
  214. package/src/svelte/tests/CoState.svelte.test.ts +57 -0
  215. package/src/svelte/tests/TestCoStateWrapper.svelte +23 -0
  216. package/src/tools/coValues/CoValueBase.ts +12 -0
  217. package/src/tools/coValues/account.ts +17 -12
  218. package/src/tools/coValues/coFeed.ts +38 -15
  219. package/src/tools/coValues/coList.ts +16 -11
  220. package/src/tools/coValues/coMap.ts +15 -14
  221. package/src/tools/coValues/coPlainText.ts +6 -3
  222. package/src/tools/coValues/coVector.ts +6 -5
  223. package/src/tools/coValues/deepLoading.ts +98 -51
  224. package/src/tools/coValues/group.ts +3 -2
  225. package/src/tools/coValues/inbox.ts +11 -10
  226. package/src/tools/coValues/interfaces.ts +49 -27
  227. package/src/tools/coValues/request.ts +8 -6
  228. package/src/tools/coValues/schemaUnion.ts +2 -1
  229. package/src/tools/exports.ts +11 -1
  230. package/src/tools/implementation/refs.ts +19 -13
  231. package/src/tools/implementation/schema.ts +5 -4
  232. package/src/tools/implementation/schemaUtils.ts +15 -0
  233. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +4 -4
  234. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +131 -95
  235. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +19 -9
  236. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +73 -22
  237. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +86 -28
  238. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +204 -148
  239. package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +1 -0
  240. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +71 -27
  241. package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +7 -0
  242. package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +8 -6
  243. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +4 -1
  244. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +4 -1
  245. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +4 -1
  246. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +4 -1
  247. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +3 -0
  248. package/src/tools/implementation/zodSchema/typeConverters/{InstanceOfSchemaCoValuesNullable.ts → InstanceOfSchemaCoValuesMaybeLoaded.ts} +47 -39
  249. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +4 -0
  250. package/src/tools/implementation/zodSchema/typeConverters/{InstanceOrPrimitiveOfSchemaCoValuesNullable.ts → InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.ts} +7 -3
  251. package/src/tools/implementation/zodSchema/zodSchema.ts +15 -7
  252. package/src/tools/internal.ts +3 -3
  253. package/src/tools/lib/utils.test.ts +56 -0
  254. package/src/tools/lib/utils.ts +32 -0
  255. package/src/tools/subscribe/CoValueCoreSubscription.ts +13 -8
  256. package/src/tools/subscribe/JazzError.ts +8 -2
  257. package/src/tools/subscribe/SubscriptionScope.ts +55 -44
  258. package/src/tools/subscribe/index.ts +12 -4
  259. package/src/tools/subscribe/types.ts +36 -2
  260. package/src/tools/subscribe/utils.ts +2 -1
  261. package/src/tools/testing.ts +5 -0
  262. package/src/tools/tests/CoValueCoreSubscription.test.ts +10 -4
  263. package/src/tools/tests/ContextManager.test.ts +12 -5
  264. package/src/tools/tests/account.test.ts +22 -12
  265. package/src/tools/tests/coDiscriminatedUnion.test.ts +8 -4
  266. package/src/tools/tests/coFeed.branch.test.ts +48 -32
  267. package/src/tools/tests/coFeed.test-d.ts +17 -10
  268. package/src/tools/tests/coFeed.test.ts +52 -30
  269. package/src/tools/tests/coList.branch.test.ts +21 -21
  270. package/src/tools/tests/coList.test-d.ts +39 -23
  271. package/src/tools/tests/coList.test.ts +51 -25
  272. package/src/tools/tests/coList.unique.test.ts +34 -29
  273. package/src/tools/tests/coMap.branch.test.ts +20 -21
  274. package/src/tools/tests/coMap.record.test-d.ts +28 -26
  275. package/src/tools/tests/coMap.record.test.ts +30 -20
  276. package/src/tools/tests/coMap.test-d.ts +31 -29
  277. package/src/tools/tests/coMap.test.ts +67 -40
  278. package/src/tools/tests/coMap.unique.test.ts +25 -24
  279. package/src/tools/tests/coVector.test.ts +29 -15
  280. package/src/tools/tests/createContext.test.ts +5 -3
  281. package/src/tools/tests/deepLoading.test.ts +314 -117
  282. package/src/tools/tests/exportImport.test.ts +16 -15
  283. package/src/tools/tests/groupsAndAccounts.test.ts +39 -16
  284. package/src/tools/tests/inbox.test.ts +3 -1
  285. package/src/tools/tests/load.test.ts +29 -23
  286. package/src/tools/tests/patterns/quest.test.ts +3 -2
  287. package/src/tools/tests/patterns/requestToJoin.test.ts +17 -17
  288. package/src/tools/tests/request.test.ts +12 -2
  289. package/src/tools/tests/schema.resolved.test.ts +723 -0
  290. package/src/tools/tests/schemaUnion.test.ts +7 -3
  291. package/src/tools/tests/subscribe.test.ts +39 -21
  292. package/src/tools/tests/testing.test.ts +3 -2
  293. package/src/tools/tests/utils.ts +15 -2
  294. package/dist/chunk-OSQ7S47Q.js.map +0 -1
  295. package/dist/media/chunk-K6GCHLQU.js.map +0 -1
  296. package/dist/react-core/tests/useAccountWithSelector.test.d.ts +0 -2
  297. package/dist/react-core/tests/useAccountWithSelector.test.d.ts.map +0 -1
  298. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +0 -2
  299. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +0 -1
  300. package/dist/tools/implementation/errors.d.ts +0 -2
  301. package/dist/tools/implementation/errors.d.ts.map +0 -1
  302. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +0 -19
  303. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +0 -1
  304. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +0 -5
  305. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +0 -1
  306. package/dist/tools/lib/id.d.ts +0 -2
  307. package/dist/tools/lib/id.d.ts.map +0 -1
  308. package/src/tools/implementation/errors.ts +0 -1
  309. package/src/tools/lib/id.ts +0 -3
@@ -1,15 +1,10 @@
1
1
  import { SessionID } from "cojson";
2
- import { ItemsSym, TypeSym } from "../internal.js";
2
+ import { CoValueLoadingState, ItemsSym, TypeSym } from "../internal.js";
3
3
  import { type Account } from "./account.js";
4
4
  import { CoFeedEntry } from "./coFeed.js";
5
5
  import { type CoKeys } from "./coMap.js";
6
6
  import { type CoValue, type ID } from "./interfaces.js";
7
7
 
8
- /**
9
- * Similar to {@link NonNullable}, but removes only `null` and preserves `undefined`.
10
- */
11
- export type NotNull<T> = Exclude<T, null>;
12
-
13
8
  /**
14
9
  * Used to check if T is a union type.
15
10
  *
@@ -22,6 +17,47 @@ type IsUnion<T, U = T> = (T extends any ? (x: T) => void : never) extends (
22
17
  ? false
23
18
  : true;
24
19
 
20
+ /**
21
+ * A CoValue that may or may not be loaded.
22
+ */
23
+ // T should extend CoValue. We can't enforce this because it would introduce circularity
24
+ // into the definition of CoValues.
25
+ export type MaybeLoaded<T> = T | NotLoaded<T>;
26
+
27
+ /**
28
+ * A CoValue that is not loaded.
29
+ */
30
+ export type NotLoaded<T> = {
31
+ $jazz: {
32
+ id: ID<T>;
33
+ loadingState:
34
+ | typeof CoValueLoadingState.LOADING
35
+ | typeof CoValueLoadingState.UNAVAILABLE
36
+ | typeof CoValueLoadingState.UNAUTHORIZED;
37
+ };
38
+ $isLoaded: false;
39
+ };
40
+
41
+ /**
42
+ * Narrows a maybe-loaded, optional CoValue to a loaded and required CoValue.
43
+ */
44
+ export type LoadedAndRequired<T> = Exclude<T, NotLoaded<T> | undefined>;
45
+
46
+ /**
47
+ * Narrows a maybe-loaded, optional CoValue to a loaded and optional CoValue
48
+ */
49
+ export type AsLoaded<T> = Exclude<T, NotLoaded<T>>;
50
+
51
+ /**
52
+ * By default, if a nested CoValue is not loaded, the parent CoValue will not be loaded either.
53
+ * When `$onError: "catch"` is used, the parent CoValue will always be loaded, and an {@link NotLoaded}
54
+ * value will be returned for the nested CoValue if it cannot be loaded.
55
+ *
56
+ * Use `$onError` to handle cases where some data you have requested is inaccessible,
57
+ * similar to a `try...catch` block in your query.
58
+ */
59
+ type OnError = { $onError?: "catch" };
60
+
25
61
  export type RefsToResolve<
26
62
  V,
27
63
  DepthLimit extends number = 10,
@@ -31,41 +67,43 @@ export type RefsToResolve<
31
67
  | (DepthLimit extends CurrentDepth["length"]
32
68
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
69
  any
34
- : IsUnion<NonNullable<V>> extends true
70
+ : IsUnion<LoadedAndRequired<V>> extends true
35
71
  ? true
36
72
  : // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
37
73
  V extends ReadonlyArray<infer Item>
38
- ?
39
- | {
40
- $each?: RefsToResolve<
41
- NotNull<Item>,
42
- DepthLimit,
43
- [0, ...CurrentDepth]
44
- >;
45
- $onError?: null;
46
- }
47
- | boolean
74
+ ? LoadedAndRequired<Item> extends CoValue
75
+ ?
76
+ | ({
77
+ $each?: RefsToResolve<
78
+ AsLoaded<Item>,
79
+ DepthLimit,
80
+ [0, ...CurrentDepth]
81
+ >;
82
+ } & OnError)
83
+ | boolean
84
+ : OnError | boolean
48
85
  : // Basically V extends CoMap | Group | Account - but if we used that we'd introduce circularity into the definition of CoMap itself
49
86
  V extends { [TypeSym]: "CoMap" | "Group" | "Account" }
50
87
  ?
51
88
  | ({
52
- [Key in CoKeys<V> as NonNullable<V[Key]> extends CoValue
89
+ [Key in CoKeys<V> as LoadedAndRequired<
90
+ V[Key]
91
+ > extends CoValue
53
92
  ? Key
54
93
  : never]?: RefsToResolve<
55
- NonNullable<V[Key]>,
94
+ LoadedAndRequired<V[Key]>,
56
95
  DepthLimit,
57
96
  [0, ...CurrentDepth]
58
97
  >;
59
- } & { $onError?: null })
98
+ } & OnError)
60
99
  | (ItemsSym extends keyof V
61
100
  ? {
62
101
  $each: RefsToResolve<
63
- NonNullable<V[ItemsSym]>,
102
+ LoadedAndRequired<V[ItemsSym]>,
64
103
  DepthLimit,
65
104
  [0, ...CurrentDepth]
66
105
  >;
67
- $onError?: null;
68
- }
106
+ } & OnError
69
107
  : never)
70
108
  | boolean
71
109
  : V extends {
@@ -73,18 +111,19 @@ export type RefsToResolve<
73
111
  byMe: CoFeedEntry<infer Item> | undefined;
74
112
  }
75
113
  ?
76
- | {
114
+ | ({
77
115
  $each: RefsToResolve<
78
- NotNull<Item>,
116
+ AsLoaded<Item>,
79
117
  DepthLimit,
80
118
  [0, ...CurrentDepth]
81
119
  >;
82
- $onError?: null;
83
- }
120
+ } & OnError)
84
121
  | boolean
85
- : boolean);
122
+ : V extends { [TypeSym]: "CoPlainText" | "BinaryCoStream" }
123
+ ? boolean | OnError
124
+ : boolean);
86
125
 
87
- export type RefsToResolveStrict<T, V> = V extends RefsToResolve<T>
126
+ export type RefsToResolveStrict<T, V> = [V] extends [RefsToResolve<T>]
88
127
  ? RefsToResolve<T>
89
128
  : V;
90
129
 
@@ -93,8 +132,12 @@ export type Resolved<
93
132
  R extends RefsToResolve<T> | undefined = true,
94
133
  > = DeeplyLoaded<T, R, 10, []>;
95
134
 
96
- type onErrorNullEnabled<Depth> = Depth extends { $onError: null }
97
- ? null
135
+ /**
136
+ * If the resolve query contains `$onError: "catch"`, we return a not loaded value for this nested CoValue.
137
+ * Otherwise, the whole load operation returns a not-loaded value.
138
+ */
139
+ type OnErrorResolvedValue<V, Depth> = Depth extends { $onError: "catch" }
140
+ ? NotLoaded<V>
98
141
  : never;
99
142
 
100
143
  type CoMapLikeLoaded<
@@ -104,16 +147,16 @@ type CoMapLikeLoaded<
104
147
  CurrentDepth extends number[],
105
148
  > = {
106
149
  readonly [Key in keyof Omit<Depth, "$onError">]-?: Key extends CoKeys<V>
107
- ? NonNullable<V[Key]> extends CoValue
150
+ ? LoadedAndRequired<V[Key]> extends CoValue
108
151
  ?
109
152
  | DeeplyLoaded<
110
- NonNullable<V[Key]>,
153
+ LoadedAndRequired<V[Key]>,
111
154
  Depth[Key],
112
155
  DepthLimit,
113
156
  [0, ...CurrentDepth]
114
157
  >
115
158
  | (undefined extends V[Key] ? undefined : never)
116
- | onErrorNullEnabled<Depth[Key]>
159
+ | OnErrorResolvedValue<V[Key], Depth[Key]>
117
160
  : never
118
161
  : never;
119
162
  } & V;
@@ -125,22 +168,23 @@ export type DeeplyLoaded<
125
168
  CurrentDepth extends number[] = [],
126
169
  > = DepthLimit extends CurrentDepth["length"]
127
170
  ? V
128
- : Depth extends boolean | undefined // Checking against boolean instead of true because the inference from RefsToResolveStrict transforms true into boolean
171
+ : Depth extends true | undefined
129
172
  ? V
130
173
  : // Basically V extends CoList - but if we used that we'd introduce circularity into the definition of CoList itself
131
174
  [V] extends [ReadonlyArray<infer Item>]
132
- ? NotNull<Item> extends CoValue
175
+ ? // `& {}` forces TypeScript to simplify the type before performing the `extends CoValue` check.
176
+ // Without it, the check would fail even when it should succeed.
177
+ AsLoaded<Item & {}> extends CoValue
133
178
  ? Depth extends { $each: infer ItemDepth }
134
179
  ? // Deeply loaded CoList
135
180
  ReadonlyArray<
136
- | (NotNull<Item> &
137
- DeeplyLoaded<
138
- NotNull<Item>,
139
- ItemDepth,
140
- DepthLimit,
141
- [0, ...CurrentDepth]
142
- >)
143
- | onErrorNullEnabled<Depth["$each"]>
181
+ | DeeplyLoaded<
182
+ AsLoaded<Item>,
183
+ ItemDepth,
184
+ DepthLimit,
185
+ [0, ...CurrentDepth]
186
+ >
187
+ | OnErrorResolvedValue<AsLoaded<Item>, Depth["$each"]>
144
188
  > &
145
189
  V // the CoList base type needs to be intersected after so that built-in methods return the correct narrowed array type
146
190
  : never
@@ -152,17 +196,20 @@ export type DeeplyLoaded<
152
196
  ? V
153
197
  : // 1. Record-like CoMap
154
198
  ItemsSym extends keyof V
155
- ? // 1.1. Deeply loaded Record-like CoMap with { $each: true | {$onError: null} }
199
+ ? // 1.1. Deeply loaded Record-like CoMap with { $each: true | { $onError: 'catch' } }
156
200
  Depth extends { $each: infer ItemDepth }
157
201
  ? {
158
202
  readonly [key: string]:
159
203
  | DeeplyLoaded<
160
- NonNullable<V[ItemsSym]>,
204
+ LoadedAndRequired<V[ItemsSym]>,
161
205
  ItemDepth,
162
206
  DepthLimit,
163
207
  [0, ...CurrentDepth]
164
208
  >
165
- | onErrorNullEnabled<Depth["$each"]>;
209
+ | OnErrorResolvedValue<
210
+ LoadedAndRequired<V[ItemsSym]>,
211
+ Depth["$each"]
212
+ >;
166
213
  } & V // same reason as in CoList
167
214
  : // 1.2. Deeply loaded Record-like CoMap with { [key: string]: true }
168
215
  string extends keyof Depth
@@ -180,12 +227,12 @@ export type DeeplyLoaded<
180
227
  ]
181
228
  ? // Deeply loaded CoStream
182
229
  {
183
- byMe?: { value: NotNull<Item> };
184
- inCurrentSession?: { value: NotNull<Item> };
230
+ byMe?: { value: AsLoaded<Item> };
231
+ inCurrentSession?: { value: AsLoaded<Item> };
185
232
  perSession: {
186
- [key: SessionID]: { value: NotNull<Item> };
233
+ [key: SessionID]: { value: AsLoaded<Item> };
187
234
  };
188
- } & { [key: ID<Account>]: { value: NotNull<Item> } } & V // same reason as in CoList
235
+ } & { [key: ID<Account>]: { value: AsLoaded<Item> } } & V // same reason as in CoList
189
236
  : [V] extends [
190
237
  {
191
238
  [TypeSym]: "BinaryCoStream";
@@ -14,6 +14,7 @@ import {
14
14
  CoValue,
15
15
  CoValueClass,
16
16
  ID,
17
+ MaybeLoaded,
17
18
  RefEncoded,
18
19
  RefsToResolve,
19
20
  RefsToResolveStrict,
@@ -278,7 +279,7 @@ export class Group extends CoValueBase implements CoValue {
278
279
  resolve?: RefsToResolveStrict<G, R>;
279
280
  loadAs?: Account | AnonymousJazzAgent;
280
281
  },
281
- ): Promise<Resolved<G, R> | null> {
282
+ ): Promise<MaybeLoaded<Resolved<G, R>>> {
282
283
  return loadCoValueWithoutMe(this, id, options);
283
284
  }
284
285
 
@@ -323,7 +324,7 @@ export class Group extends CoValueBase implements CoValue {
323
324
  const group = await loadCoValueWithoutMe(this, id, {
324
325
  loadAs: options?.loadAs,
325
326
  });
326
- if (!group) {
327
+ if (!group.$isLoaded) {
327
328
  throw new Error(`Group with id ${id} not found`);
328
329
  }
329
330
  return group.$jazz.createInvite(options?.role ?? "reader");
@@ -11,13 +11,14 @@ import {
11
11
  type Account,
12
12
  CoValue,
13
13
  CoValueClassOrSchema,
14
+ CoValueLoadingState,
14
15
  ID,
15
16
  InstanceOfSchema,
16
17
  activeAccountContext,
17
18
  coValueClassFromCoValueClassOrSchema,
18
19
  loadCoValue,
19
20
  } from "../internal.js";
20
- import { isCoValueId } from "../lib/id.js";
21
+ import { isCoValueId } from "../lib/utils.js";
21
22
 
22
23
  export type InboxInvite = `${CoID<MessagesStream>}/${InviteSecret}`;
23
24
  type TxKey = `${SessionID}/${number}`;
@@ -224,7 +225,7 @@ export class Inbox {
224
225
  messageId: CoID<InboxMessage<CoValue, any>>,
225
226
  ) => {
226
227
  const message = await node.load(messageId);
227
- if (message === "unavailable") {
228
+ if (message === CoValueLoadingState.UNAVAILABLE) {
228
229
  throw new Error(`Inbox: message ${messageId} is unavailable`);
229
230
  }
230
231
 
@@ -331,7 +332,7 @@ export class Inbox {
331
332
  static async load(account: Account) {
332
333
  const profile = account.profile;
333
334
 
334
- if (!profile) {
335
+ if (!profile.$isLoaded) {
335
336
  throw new Error("Account profile should already be loaded");
336
337
  }
337
338
 
@@ -343,7 +344,7 @@ export class Inbox {
343
344
 
344
345
  const root = await node.load(profile.inbox as CoID<InboxRoot>);
345
346
 
346
- if (root === "unavailable") {
347
+ if (root === CoValueLoadingState.UNAVAILABLE) {
347
348
  throw new Error("Inbox not found");
348
349
  }
349
350
 
@@ -354,9 +355,9 @@ export class Inbox {
354
355
  ]);
355
356
 
356
357
  if (
357
- messages === "unavailable" ||
358
- processed === "unavailable" ||
359
- failed === "unavailable"
358
+ messages === CoValueLoadingState.UNAVAILABLE ||
359
+ processed === CoValueLoadingState.UNAVAILABLE ||
360
+ failed === CoValueLoadingState.UNAVAILABLE
360
361
  ) {
361
362
  throw new Error("Inbox not found");
362
363
  }
@@ -421,13 +422,13 @@ export class InboxSender<I extends CoValue, O extends CoValue | undefined> {
421
422
  inboxOwnerID as unknown as CoID<RawAccount>,
422
423
  );
423
424
 
424
- if (inboxOwnerRaw === "unavailable") {
425
+ if (inboxOwnerRaw === CoValueLoadingState.UNAVAILABLE) {
425
426
  throw new Error("Failed to load the inbox owner");
426
427
  }
427
428
 
428
429
  const inboxOwnerProfileRaw = await node.load(inboxOwnerRaw.get("profile")!);
429
430
 
430
- if (inboxOwnerProfileRaw === "unavailable") {
431
+ if (inboxOwnerProfileRaw === CoValueLoadingState.UNAVAILABLE) {
431
432
  throw new Error("Failed to load the inbox owner profile");
432
433
  }
433
434
 
@@ -453,7 +454,7 @@ export class InboxSender<I extends CoValue, O extends CoValue | undefined> {
453
454
 
454
455
  const messages = await node.load(id);
455
456
 
456
- if (messages === "unavailable") {
457
+ if (messages === CoValueLoadingState.UNAVAILABLE) {
457
458
  throw new Error("Inbox not found");
458
459
  }
459
460
 
@@ -9,8 +9,11 @@ import {
9
9
  Account,
10
10
  AnonymousJazzAgent,
11
11
  CoValueClassOrSchema,
12
+ CoValueLoadingState,
13
+ NotLoadedCoValueState,
12
14
  type Group,
13
15
  Loaded,
16
+ MaybeLoaded,
14
17
  RefsToResolve,
15
18
  RefsToResolveStrict,
16
19
  RegisteredSchemas,
@@ -20,6 +23,7 @@ import {
20
23
  SubscriptionScope,
21
24
  type SubscriptionValue,
22
25
  TypeSym,
26
+ NotLoaded,
23
27
  activeAccountContext,
24
28
  coValueClassFromCoValueClassOrSchema,
25
29
  getSubscriptionScope,
@@ -49,6 +53,8 @@ export interface CoValue {
49
53
  $jazz: {
50
54
  /** @category Content */
51
55
  readonly id: ID<CoValue>;
56
+ /** @category Content */
57
+ loadingState: typeof CoValueLoadingState.LOADED;
52
58
  /** @category Collaboration */
53
59
  owner?: Group;
54
60
  /** @internal */
@@ -61,6 +67,11 @@ export interface CoValue {
61
67
  branchName: string | undefined;
62
68
  unstable_merge: () => void;
63
69
  };
70
+ /**
71
+ * Whether the CoValue is loaded. Can be used to distinguish between loaded and {@link NotLoaded} CoValues.
72
+ * For more information about the CoValue's loading state, use {@link $jazz.loadingState}.
73
+ */
74
+ $isLoaded: true;
64
75
 
65
76
  /** @category Stringifying & Inspection */
66
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -96,6 +107,16 @@ export function isCoValueClass<V extends CoValue>(
96
107
  */
97
108
  export type ID<T> = string;
98
109
 
110
+ export function createUnloadedCoValue<T extends CoValue>(
111
+ id: ID<T>,
112
+ loadingState: NotLoadedCoValueState,
113
+ ): NotLoaded<T> {
114
+ return {
115
+ $jazz: { id, loadingState },
116
+ $isLoaded: false,
117
+ };
118
+ }
119
+
99
120
  export function loadCoValueWithoutMe<
100
121
  V extends CoValue,
101
122
  const R extends RefsToResolve<V>,
@@ -108,7 +129,7 @@ export function loadCoValueWithoutMe<
108
129
  skipRetry?: boolean;
109
130
  unstable_branch?: BranchDefinition;
110
131
  },
111
- ): Promise<Resolved<V, R> | null> {
132
+ ): Promise<MaybeLoaded<Resolved<V, R>>> {
112
133
  return loadCoValue(cls, id, {
113
134
  ...options,
114
135
  loadAs: options?.loadAs ?? activeAccountContext.get(),
@@ -128,7 +149,7 @@ export function loadCoValue<
128
149
  skipRetry?: boolean;
129
150
  unstable_branch?: BranchDefinition;
130
151
  },
131
- ): Promise<Resolved<V, R> | null> {
152
+ ): Promise<MaybeLoaded<Resolved<V, R>>> {
132
153
  return new Promise((resolve) => {
133
154
  subscribeToCoValue<V, R>(
134
155
  cls,
@@ -139,10 +160,10 @@ export function loadCoValue<
139
160
  syncResolution: true,
140
161
  skipRetry: options.skipRetry,
141
162
  onUnavailable: () => {
142
- resolve(null);
163
+ resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAVAILABLE));
143
164
  },
144
165
  onUnauthorized: () => {
145
- resolve(null);
166
+ resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAUTHORIZED));
146
167
  },
147
168
  unstable_branch: options.unstable_branch,
148
169
  },
@@ -176,7 +197,7 @@ export async function ensureCoValueLoaded<
176
197
  },
177
198
  );
178
199
 
179
- if (!response) {
200
+ if (!response.$isLoaded) {
180
201
  throw new Error("Failed to deeply load CoValue " + existing.$jazz.id);
181
202
  }
182
203
 
@@ -300,18 +321,18 @@ export function subscribeToCoValue<
300
321
  const handleUpdate = (value: SubscriptionValue<V, any>) => {
301
322
  if (unsubscribed) return;
302
323
 
303
- if (value.type === "unavailable") {
324
+ if (value.type === CoValueLoadingState.UNAVAILABLE) {
304
325
  options.onUnavailable?.();
305
326
 
306
327
  // Don't log unavailable errors when `loadUnique` or `upsertUnique` are used
307
328
  if (!options.skipRetry) {
308
329
  console.error(value.toString());
309
330
  }
310
- } else if (value.type === "unauthorized") {
331
+ } else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
311
332
  options.onUnauthorized?.();
312
333
 
313
334
  console.error(value.toString());
314
- } else if (value.type === "loaded") {
335
+ } else if (value.type === CoValueLoadingState.LOADED) {
315
336
  listener(value.value as Resolved<V, R>, unsubscribe);
316
337
  }
317
338
  };
@@ -472,7 +493,7 @@ export async function unstable_loadUnique<
472
493
  owner: Account | Group;
473
494
  resolve?: ResolveQueryStrict<S, R>;
474
495
  },
475
- ): Promise<Loaded<S, R> | null> {
496
+ ): Promise<MaybeLoaded<Loaded<S, R>>> {
476
497
  const cls = coValueClassFromCoValueClassOrSchema(schema);
477
498
 
478
499
  if (
@@ -484,15 +505,14 @@ export async function unstable_loadUnique<
484
505
 
485
506
  const header = cls._getUniqueHeader(options.unique, options.owner.$jazz.id);
486
507
 
508
+ // @ts-expect-error the CoValue class is too generic for TS to infer its instances are CoValues
487
509
  return internalLoadUnique(cls, {
488
510
  header,
489
511
  onCreateWhenMissing: options.onCreateWhenMissing,
490
- // @ts-expect-error loaded is not compatible with Resolved at type level, but they are the same thing
491
512
  onUpdateWhenFound: options.onUpdateWhenFound,
492
513
  owner: options.owner,
493
- // @ts-expect-error loaded is not compatible with Resolved at type level, but they are the same thing
494
514
  resolve: options.resolve,
495
- }) as unknown as Loaded<S, R> | null;
515
+ }) as unknown as MaybeLoaded<Loaded<S, R>>;
496
516
  }
497
517
 
498
518
  export async function internalLoadUnique<
@@ -507,7 +527,7 @@ export async function internalLoadUnique<
507
527
  owner: Account | Group;
508
528
  resolve?: RefsToResolveStrict<V, R>;
509
529
  },
510
- ): Promise<Resolved<V, R> | null> {
530
+ ): Promise<MaybeLoaded<Resolved<V, R>>> {
511
531
  const loadAs = options.owner.$jazz.loadedAs;
512
532
 
513
533
  const node =
@@ -519,7 +539,7 @@ export async function internalLoadUnique<
519
539
  // retrying failures
520
540
  // This way when we want to upsert we are sure that, if the load failed
521
541
  // it failed because the unique value was missing
522
- await loadCoValueWithoutMe(cls, id, {
542
+ const maybeLoadedCoValue = await loadCoValueWithoutMe(cls, id, {
523
543
  skipRetry: true,
524
544
  loadAs,
525
545
  });
@@ -539,7 +559,9 @@ export async function internalLoadUnique<
539
559
  }
540
560
 
541
561
  if (!isAvailable) {
542
- return null;
562
+ // @ts-expect-error the resolve query of the loaded values is not necessarily the same,
563
+ // but we're only returning not-loaded values
564
+ return maybeLoadedCoValue;
543
565
  }
544
566
 
545
567
  if (options.onUpdateWhenFound) {
@@ -549,7 +571,7 @@ export async function internalLoadUnique<
549
571
  resolve: options.resolve,
550
572
  });
551
573
 
552
- if (loaded) {
574
+ if (loaded.$isLoaded) {
553
575
  // we don't return the update result because
554
576
  // we want to run another load to backfill any possible partially loaded
555
577
  // values that have been set in the update
@@ -642,13 +664,13 @@ export async function exportCoValue<
642
664
 
643
665
  const value = await new Promise<Loaded<S, R> | null>((resolve) => {
644
666
  rootNode.setListener((value) => {
645
- if (value.type === "unavailable") {
667
+ if (value.type === CoValueLoadingState.UNAVAILABLE) {
646
668
  resolve(null);
647
669
  console.error(value.toString());
648
- } else if (value.type === "unauthorized") {
670
+ } else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
649
671
  resolve(null);
650
672
  console.error(value.toString());
651
- } else if (value.type === "loaded") {
673
+ } else if (value.type === CoValueLoadingState.LOADED) {
652
674
  resolve(value.value as Loaded<S, R>);
653
675
  }
654
676
 
@@ -679,10 +701,10 @@ function loadContentPiecesFromSubscription(
679
701
 
680
702
  valuesExported.add(subscription.id);
681
703
 
682
- const core = subscription.getCurrentValue()?.$jazz.raw
683
- .core as AvailableCoValueCore;
704
+ const currentValue = subscription.getCurrentValue();
684
705
 
685
- if (core) {
706
+ if (typeof currentValue !== "string") {
707
+ const core = currentValue.$jazz.raw.core as AvailableCoValueCore;
686
708
  loadContentPiecesFromCoValue(core, valuesExported, contentPieces);
687
709
  }
688
710
 
@@ -742,7 +764,7 @@ export function unstable_mergeBranch(
742
764
  }
743
765
 
744
766
  function handleMerge(subscriptionNode: SubscriptionScope<CoValue>) {
745
- if (subscriptionNode.value.type === "loaded") {
767
+ if (subscriptionNode.value.type === CoValueLoadingState.LOADED) {
746
768
  subscriptionNode.value.value.$jazz.raw.core.mergeBranch();
747
769
  }
748
770
 
@@ -762,7 +784,7 @@ export async function unstable_mergeBranchWithResolve<
762
784
  id: ID<CoValue>,
763
785
  options: {
764
786
  resolve?: ResolveQueryStrict<S, R>;
765
- loadAs: Account | AnonymousJazzAgent;
787
+ loadAs?: Account | AnonymousJazzAgent;
766
788
  branch: BranchDefinition;
767
789
  },
768
790
  ) {
@@ -786,11 +808,11 @@ export async function unstable_mergeBranchWithResolve<
786
808
 
787
809
  await new Promise<void>((resolve, reject) => {
788
810
  rootNode.setListener((value) => {
789
- if (value.type === "unavailable") {
811
+ if (value.type === CoValueLoadingState.UNAVAILABLE) {
790
812
  reject(new Error("Unable to load the branch. " + value.toString()));
791
- } else if (value.type === "unauthorized") {
813
+ } else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
792
814
  reject(new Error("Unable to load the branch. " + value.toString()));
793
- } else if (value.type === "loaded") {
815
+ } else if (value.type === CoValueLoadingState.LOADED) {
794
816
  resolve();
795
817
  }
796
818
 
@@ -14,6 +14,8 @@ import {
14
14
  CoMapSchemaInit,
15
15
  CoValueClass,
16
16
  CoreCoMapSchema,
17
+ CoValueLoadingState,
18
+ createUnloadedCoValue,
17
19
  Group,
18
20
  Loaded,
19
21
  ResolveQuery,
@@ -25,7 +27,7 @@ import {
25
27
  importContentPieces,
26
28
  loadCoValue,
27
29
  } from "../internal.js";
28
- import { isCoValueId } from "../lib/id.js";
30
+ import { isCoValueId } from "../lib/utils.js";
29
31
  import { Account } from "./account.js";
30
32
 
31
33
  type MessageShape = Record<string, AnyZodOrCoValueSchema>;
@@ -289,7 +291,7 @@ async function handleMessagePayload({
289
291
  loadAs,
290
292
  });
291
293
 
292
- if (!madeBy) {
294
+ if (!madeBy.$isLoaded) {
293
295
  throw new JazzRequestError("Creator account not found", 400);
294
296
  }
295
297
 
@@ -301,7 +303,7 @@ async function handleMessagePayload({
301
303
  loadAs,
302
304
  });
303
305
 
304
- if (!value) {
306
+ if (!value.$isLoaded) {
305
307
  throw new JazzRequestError("Value not found", 400);
306
308
  }
307
309
 
@@ -375,7 +377,7 @@ export class HttpRoute<
375
377
  const as = options?.owner ?? Account.getMe();
376
378
 
377
379
  const target = await loadWorkerAccountOrGroup(this.workerId, as);
378
- if (!target) {
380
+ if (!target.$isLoaded) {
379
381
  throw new JazzRequestError("Worker account not found", 400);
380
382
  }
381
383
 
@@ -619,7 +621,7 @@ async function loadWorkerAccountOrGroup(id: string, loadAs: Account) {
619
621
  const coValue = await node.loadCoValueCore(id as `co_z${string}`);
620
622
 
621
623
  if (!coValue.isAvailable()) {
622
- return null;
624
+ return createUnloadedCoValue(id, CoValueLoadingState.UNAVAILABLE);
623
625
  }
624
626
 
625
627
  const content = coValue.getCurrentContent();
@@ -782,7 +784,7 @@ export async function parseAuthToken(
782
784
 
783
785
  const account = await Account.load(id, { loadAs: options?.loadAs });
784
786
 
785
- if (!account) {
787
+ if (!account.$isLoaded) {
786
788
  return {
787
789
  error: {
788
790
  message: "Failed to load account",
@@ -10,6 +10,7 @@ import {
10
10
  CoValueJazzApi,
11
11
  Group,
12
12
  ID,
13
+ MaybeLoaded,
13
14
  Resolved,
14
15
  Simplify,
15
16
  SubscribeListenerOptions,
@@ -160,7 +161,7 @@ export abstract class SchemaUnion extends CoValueBase implements CoValue {
160
161
  loadAs?: Account | AnonymousJazzAgent;
161
162
  skipRetry?: boolean;
162
163
  },
163
- ): Promise<Resolved<M, true> | null> {
164
+ ): Promise<MaybeLoaded<Resolved<M, true>>> {
164
165
  return loadCoValueWithoutMe(this, id, options);
165
166
  }
166
167