jazz-tools 0.18.38 → 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 (302) 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 +57 -57
  19. package/CHANGELOG.md +22 -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/media/{chunk-K6GCHLQU.js → chunk-3LKBM3G3.js} +23 -15
  30. package/dist/media/chunk-3LKBM3G3.js.map +1 -0
  31. package/dist/media/create-image/browser.d.ts +2 -2
  32. package/dist/media/create-image/react-native.d.ts +2 -2
  33. package/dist/media/create-image/server.d.ts +2 -2
  34. package/dist/media/create-image-factory.d.ts +2 -2
  35. package/dist/media/index.browser.js +1 -1
  36. package/dist/media/index.js +1 -1
  37. package/dist/media/index.native.js +1 -1
  38. package/dist/media/index.server.js +1 -1
  39. package/dist/media/utils.d.ts.map +1 -1
  40. package/dist/react/hooks.d.ts +1 -1
  41. package/dist/react/hooks.d.ts.map +1 -1
  42. package/dist/react/index.d.ts +1 -1
  43. package/dist/react/index.d.ts.map +1 -1
  44. package/dist/react/index.js +31 -15
  45. package/dist/react/index.js.map +1 -1
  46. package/dist/react/media/image.d.ts.map +1 -1
  47. package/dist/react-core/hooks.d.ts +126 -224
  48. package/dist/react-core/hooks.d.ts.map +1 -1
  49. package/dist/react-core/index.js +65 -63
  50. package/dist/react-core/index.js.map +1 -1
  51. package/dist/react-core/subscription-provider.d.ts.map +1 -1
  52. package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts +2 -0
  53. package/dist/react-core/tests/createCoValueSubscriptionContext.test.d.ts.map +1 -0
  54. package/dist/react-core/tests/useAccount.selector.test.d.ts +2 -0
  55. package/dist/react-core/tests/useAccount.selector.test.d.ts.map +1 -0
  56. package/dist/react-core/tests/useCoState.selector.test.d.ts +2 -0
  57. package/dist/react-core/tests/useCoState.selector.test.d.ts.map +1 -0
  58. package/dist/react-native-core/hooks.d.ts +1 -1
  59. package/dist/react-native-core/hooks.d.ts.map +1 -1
  60. package/dist/react-native-core/index.js +7 -5
  61. package/dist/react-native-core/index.js.map +1 -1
  62. package/dist/react-native-core/media/image.d.ts.map +1 -1
  63. package/dist/svelte/jazz.class.svelte.d.ts +8 -8
  64. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  65. package/dist/svelte/jazz.class.svelte.js +39 -14
  66. package/dist/svelte/media/image.svelte +6 -5
  67. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  68. package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts +2 -0
  69. package/dist/svelte/tests/AccountCoState.svelte.test-d.d.ts.map +1 -0
  70. package/dist/svelte/tests/AccountCoState.svelte.test-d.js +19 -0
  71. package/dist/svelte/tests/CoState.svelte.test-d.d.ts +2 -0
  72. package/dist/svelte/tests/CoState.svelte.test-d.d.ts.map +1 -0
  73. package/dist/svelte/tests/CoState.svelte.test-d.js +16 -0
  74. package/dist/svelte/tests/CoState.svelte.test.d.ts +2 -0
  75. package/dist/svelte/tests/CoState.svelte.test.d.ts.map +1 -0
  76. package/dist/svelte/tests/CoState.svelte.test.js +42 -0
  77. package/dist/svelte/tests/TestCoStateWrapper.svelte +23 -0
  78. package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts +12 -0
  79. package/dist/svelte/tests/TestCoStateWrapper.svelte.d.ts.map +1 -0
  80. package/dist/testing.js +3 -1
  81. package/dist/testing.js.map +1 -1
  82. package/dist/tools/coValues/CoValueBase.d.ts +4 -1
  83. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  84. package/dist/tools/coValues/account.d.ts +6 -6
  85. package/dist/tools/coValues/account.d.ts.map +1 -1
  86. package/dist/tools/coValues/coFeed.d.ts +5 -5
  87. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  88. package/dist/tools/coValues/coList.d.ts +9 -8
  89. package/dist/tools/coValues/coList.d.ts.map +1 -1
  90. package/dist/tools/coValues/coMap.d.ts +17 -17
  91. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  92. package/dist/tools/coValues/coPlainText.d.ts +3 -3
  93. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  94. package/dist/tools/coValues/coVector.d.ts +3 -3
  95. package/dist/tools/coValues/coVector.d.ts.map +1 -1
  96. package/dist/tools/coValues/deepLoading.d.ts +66 -36
  97. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  98. package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
  99. package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
  100. package/dist/tools/coValues/group.d.ts +2 -2
  101. package/dist/tools/coValues/group.d.ts.map +1 -1
  102. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  103. package/dist/tools/coValues/interfaces.d.ts +14 -6
  104. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  105. package/dist/tools/coValues/request.d.ts.map +1 -1
  106. package/dist/tools/coValues/schemaUnion.d.ts +2 -2
  107. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  108. package/dist/tools/exports.d.ts +3 -3
  109. package/dist/tools/exports.d.ts.map +1 -1
  110. package/dist/tools/implementation/refs.d.ts +3 -3
  111. package/dist/tools/implementation/refs.d.ts.map +1 -1
  112. package/dist/tools/implementation/schema.d.ts +2 -2
  113. package/dist/tools/implementation/schema.d.ts.map +1 -1
  114. package/dist/tools/implementation/schemaUtils.d.ts +8 -0
  115. package/dist/tools/implementation/schemaUtils.d.ts.map +1 -1
  116. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  117. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +33 -18
  118. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  119. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +5 -4
  120. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  121. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +23 -12
  122. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  123. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +29 -18
  124. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  125. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +39 -22
  126. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  127. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +1 -0
  128. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
  129. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +30 -19
  130. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  131. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +5 -0
  132. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -1
  133. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +6 -5
  134. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
  135. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -2
  136. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  137. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +3 -2
  138. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  139. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +3 -2
  140. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  141. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +3 -2
  142. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  143. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +3 -0
  144. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  145. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts +22 -0
  146. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
  147. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +4 -0
  148. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
  149. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts +9 -0
  150. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -0
  151. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  152. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +7 -6
  153. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  154. package/dist/tools/internal.d.ts +3 -3
  155. package/dist/tools/internal.d.ts.map +1 -1
  156. package/dist/tools/lib/utils.d.ts +14 -0
  157. package/dist/tools/lib/utils.d.ts.map +1 -0
  158. package/dist/tools/lib/utils.test.d.ts +2 -0
  159. package/dist/tools/lib/utils.test.d.ts.map +1 -0
  160. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +3 -2
  161. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  162. package/dist/tools/subscribe/JazzError.d.ts +4 -3
  163. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  164. package/dist/tools/subscribe/SubscriptionScope.d.ts +6 -5
  165. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  166. package/dist/tools/subscribe/index.d.ts.map +1 -1
  167. package/dist/tools/subscribe/types.d.ts +23 -3
  168. package/dist/tools/subscribe/types.d.ts.map +1 -1
  169. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  170. package/dist/tools/testing.d.ts +3 -2
  171. package/dist/tools/testing.d.ts.map +1 -1
  172. package/dist/tools/tests/schema.resolved.test.d.ts +2 -0
  173. package/dist/tools/tests/schema.resolved.test.d.ts.map +1 -0
  174. package/dist/tools/tests/utils.d.ts +2 -1
  175. package/dist/tools/tests/utils.d.ts.map +1 -1
  176. package/package.json +4 -4
  177. package/src/better-auth/database-adapter/index.ts +2 -2
  178. package/src/better-auth/database-adapter/repository/account.ts +3 -3
  179. package/src/better-auth/database-adapter/repository/generic.ts +9 -6
  180. package/src/better-auth/database-adapter/repository/user.ts +6 -2
  181. package/src/better-auth/database-adapter/schema.ts +1 -1
  182. package/src/better-auth/database-adapter/tests/index.test.ts +3 -4
  183. package/src/inspector/tests/viewer/history-view.test.tsx +6 -2
  184. package/src/media/utils.test.ts +5 -0
  185. package/src/media/utils.ts +25 -16
  186. package/src/react/hooks.tsx +2 -2
  187. package/src/react/index.ts +2 -2
  188. package/src/react/media/image.tsx +10 -2
  189. package/src/react/tests/useAcceptInvite.test.ts +3 -1
  190. package/src/react-core/hooks.ts +226 -304
  191. package/src/react-core/subscription-provider.tsx +14 -7
  192. package/src/react-core/tests/createCoValueSubscriptionContext.test.tsx +233 -0
  193. package/src/react-core/tests/subscription.bench.tsx +32 -15
  194. package/src/react-core/tests/{useAccountWithSelector.test.ts → useAccount.selector.test.ts} +72 -24
  195. package/src/react-core/tests/useAccount.test.ts +92 -106
  196. package/src/react-core/tests/{useCoStateWithSelector.test.ts → useCoState.selector.test.ts} +23 -8
  197. package/src/react-core/tests/useCoState.test.ts +173 -49
  198. package/src/react-core/tests/useInboxSender.test.ts +3 -1
  199. package/src/react-core/tests/usePassPhraseAuth.test.ts +11 -82
  200. package/src/react-core/tests/useSubscriptionSelector.test.ts +48 -14
  201. package/src/react-native-core/hooks.tsx +2 -2
  202. package/src/react-native-core/media/image.tsx +3 -1
  203. package/src/svelte/jazz.class.svelte.ts +103 -27
  204. package/src/svelte/media/image.svelte +6 -5
  205. package/src/svelte/tests/AccountCoState.svelte.test-d.ts +23 -0
  206. package/src/svelte/tests/CoState.svelte.test-d.ts +20 -0
  207. package/src/svelte/tests/CoState.svelte.test.ts +57 -0
  208. package/src/svelte/tests/TestCoStateWrapper.svelte +23 -0
  209. package/src/tools/coValues/CoValueBase.ts +12 -0
  210. package/src/tools/coValues/account.ts +17 -12
  211. package/src/tools/coValues/coFeed.ts +38 -15
  212. package/src/tools/coValues/coList.ts +16 -11
  213. package/src/tools/coValues/coMap.ts +15 -14
  214. package/src/tools/coValues/coPlainText.ts +6 -3
  215. package/src/tools/coValues/coVector.ts +6 -5
  216. package/src/tools/coValues/deepLoading.ts +98 -51
  217. package/src/tools/coValues/group.ts +3 -2
  218. package/src/tools/coValues/inbox.ts +11 -10
  219. package/src/tools/coValues/interfaces.ts +49 -27
  220. package/src/tools/coValues/request.ts +8 -6
  221. package/src/tools/coValues/schemaUnion.ts +2 -1
  222. package/src/tools/exports.ts +11 -1
  223. package/src/tools/implementation/refs.ts +19 -13
  224. package/src/tools/implementation/schema.ts +5 -4
  225. package/src/tools/implementation/schemaUtils.ts +15 -0
  226. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +4 -4
  227. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +131 -95
  228. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +19 -9
  229. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +73 -22
  230. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +86 -28
  231. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +204 -148
  232. package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +1 -0
  233. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +71 -27
  234. package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +7 -0
  235. package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +8 -6
  236. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +4 -1
  237. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +4 -1
  238. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +4 -1
  239. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +4 -1
  240. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +3 -0
  241. package/src/tools/implementation/zodSchema/typeConverters/{InstanceOfSchemaCoValuesNullable.ts → InstanceOfSchemaCoValuesMaybeLoaded.ts} +47 -39
  242. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +4 -0
  243. package/src/tools/implementation/zodSchema/typeConverters/{InstanceOrPrimitiveOfSchemaCoValuesNullable.ts → InstanceOrPrimitiveOfSchemaCoValuesMaybeLoaded.ts} +7 -3
  244. package/src/tools/implementation/zodSchema/zodSchema.ts +15 -7
  245. package/src/tools/internal.ts +3 -3
  246. package/src/tools/lib/utils.test.ts +56 -0
  247. package/src/tools/lib/utils.ts +32 -0
  248. package/src/tools/subscribe/CoValueCoreSubscription.ts +13 -8
  249. package/src/tools/subscribe/JazzError.ts +8 -2
  250. package/src/tools/subscribe/SubscriptionScope.ts +55 -44
  251. package/src/tools/subscribe/index.ts +12 -4
  252. package/src/tools/subscribe/types.ts +36 -2
  253. package/src/tools/subscribe/utils.ts +2 -1
  254. package/src/tools/testing.ts +5 -0
  255. package/src/tools/tests/CoValueCoreSubscription.test.ts +10 -4
  256. package/src/tools/tests/ContextManager.test.ts +12 -5
  257. package/src/tools/tests/account.test.ts +22 -12
  258. package/src/tools/tests/coDiscriminatedUnion.test.ts +8 -4
  259. package/src/tools/tests/coFeed.branch.test.ts +48 -32
  260. package/src/tools/tests/coFeed.test-d.ts +17 -10
  261. package/src/tools/tests/coFeed.test.ts +52 -30
  262. package/src/tools/tests/coList.branch.test.ts +21 -21
  263. package/src/tools/tests/coList.test-d.ts +39 -23
  264. package/src/tools/tests/coList.test.ts +51 -25
  265. package/src/tools/tests/coList.unique.test.ts +34 -29
  266. package/src/tools/tests/coMap.branch.test.ts +20 -21
  267. package/src/tools/tests/coMap.record.test-d.ts +28 -26
  268. package/src/tools/tests/coMap.record.test.ts +30 -20
  269. package/src/tools/tests/coMap.test-d.ts +31 -29
  270. package/src/tools/tests/coMap.test.ts +67 -40
  271. package/src/tools/tests/coMap.unique.test.ts +25 -24
  272. package/src/tools/tests/coVector.test.ts +29 -15
  273. package/src/tools/tests/createContext.test.ts +5 -3
  274. package/src/tools/tests/deepLoading.test.ts +314 -117
  275. package/src/tools/tests/exportImport.test.ts +16 -15
  276. package/src/tools/tests/groupsAndAccounts.test.ts +39 -16
  277. package/src/tools/tests/inbox.test.ts +3 -1
  278. package/src/tools/tests/load.test.ts +29 -23
  279. package/src/tools/tests/patterns/quest.test.ts +3 -2
  280. package/src/tools/tests/patterns/requestToJoin.test.ts +17 -17
  281. package/src/tools/tests/request.test.ts +12 -2
  282. package/src/tools/tests/schema.resolved.test.ts +723 -0
  283. package/src/tools/tests/schemaUnion.test.ts +7 -3
  284. package/src/tools/tests/subscribe.test.ts +39 -21
  285. package/src/tools/tests/testing.test.ts +3 -2
  286. package/src/tools/tests/utils.ts +15 -2
  287. package/dist/chunk-OSQ7S47Q.js.map +0 -1
  288. package/dist/media/chunk-K6GCHLQU.js.map +0 -1
  289. package/dist/react-core/tests/useAccountWithSelector.test.d.ts +0 -2
  290. package/dist/react-core/tests/useAccountWithSelector.test.d.ts.map +0 -1
  291. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts +0 -2
  292. package/dist/react-core/tests/useCoStateWithSelector.test.d.ts.map +0 -1
  293. package/dist/tools/implementation/errors.d.ts +0 -2
  294. package/dist/tools/implementation/errors.d.ts.map +0 -1
  295. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +0 -19
  296. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +0 -1
  297. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +0 -5
  298. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +0 -1
  299. package/dist/tools/lib/id.d.ts +0 -2
  300. package/dist/tools/lib/id.d.ts.map +0 -1
  301. package/src/tools/implementation/errors.ts +0 -1
  302. package/src/tools/lib/id.ts +0 -3
@@ -58,6 +58,11 @@ function removeGetters(obj) {
58
58
  }
59
59
  return result;
60
60
  }
61
+ function withSchemaResolveQuery(loadOptions, schemaResolveQuery) {
62
+ const newOptions = loadOptions ? { ...loadOptions } : {};
63
+ newOptions.resolve ||= schemaResolveQuery;
64
+ return newOptions;
65
+ }
61
66
 
62
67
  // src/tools/implementation/zodSchema/zodReExport.ts
63
68
  import {
@@ -130,6 +135,11 @@ import {
130
135
  // src/tools/coValues/CoValueBase.ts
131
136
  import { ControlledAccount } from "cojson";
132
137
  var CoValueBase = class {
138
+ constructor() {
139
+ Object.defineProperties(this, {
140
+ $isLoaded: { value: true, enumerable: false }
141
+ });
142
+ }
133
143
  /** @category Internals */
134
144
  static fromRaw(raw) {
135
145
  return new this({ fromRaw: raw });
@@ -161,6 +171,9 @@ var CoValueJazzApi = class {
161
171
  }
162
172
  return this.raw.id;
163
173
  }
174
+ get loadingState() {
175
+ return CoValueLoadingState.LOADED;
176
+ }
164
177
  /** @internal */
165
178
  get localNode() {
166
179
  return this.raw.core.node;
@@ -453,7 +466,7 @@ var _CoMap = class _CoMap extends CoValueBase {
453
466
  /**
454
467
  * Given some data, updates an existing CoMap or initialises a new one if none exists.
455
468
  *
456
- * Note: This method respects resolve options, and thus can return `null` if the references cannot be resolved.
469
+ * Note: This method respects resolve options, and thus can return a not-loaded value if the references cannot be resolved.
457
470
  *
458
471
  * @example
459
472
  * ```ts
@@ -500,7 +513,7 @@ var _CoMap = class _CoMap extends CoValueBase {
500
513
  * @param unique The unique identifier of the CoMap to load.
501
514
  * @param ownerID The ID of the owner of the CoMap.
502
515
  * @param options Additional options for loading the CoMap.
503
- * @returns The loaded CoMap, or null if unavailable.
516
+ * @returns The loaded CoMap, or an not-loaded value if unavailable.
504
517
  *
505
518
  * @deprecated Use `co.map(...).loadUnique` instead.
506
519
  */
@@ -509,7 +522,7 @@ var _CoMap = class _CoMap extends CoValueBase {
509
522
  const owner = await Group2.load(ownerID, {
510
523
  loadAs: options?.loadAs
511
524
  });
512
- if (!owner) return owner;
525
+ if (!owner.$isLoaded) return owner;
513
526
  return internalLoadUnique(this, {
514
527
  header,
515
528
  owner,
@@ -888,7 +901,8 @@ var _CoList = class _CoList extends Array {
888
901
  $jazz: {
889
902
  value: new CoListJazzApi(proxy, () => options.fromRaw),
890
903
  enumerable: false
891
- }
904
+ },
905
+ $isLoaded: { value: true, enumerable: false }
892
906
  });
893
907
  }
894
908
  return proxy;
@@ -922,7 +936,8 @@ var _CoList = class _CoList extends Array {
922
936
  $jazz: {
923
937
  value: new CoListJazzApi(instance, () => raw),
924
938
  enumerable: false
925
- }
939
+ },
940
+ $isLoaded: { value: true, enumerable: false }
926
941
  });
927
942
  const raw = owner.$jazz.raw.createList(
928
943
  toRawItems(items, instance.$jazz.schema[ItemsSym], owner),
@@ -1012,7 +1027,7 @@ var _CoList = class _CoList extends Array {
1012
1027
  /**
1013
1028
  * Given some data, updates an existing CoList or initialises a new one if none exists.
1014
1029
  *
1015
- * Note: This method respects resolve options, and thus can return `null` if the references cannot be resolved.
1030
+ * Note: This method respects resolve options, and thus can return a not-loaded value if the references cannot be resolved.
1016
1031
  *
1017
1032
  * @example
1018
1033
  * ```ts
@@ -1054,14 +1069,14 @@ var _CoList = class _CoList extends Array {
1054
1069
  * @param unique The unique identifier of the CoList to load.
1055
1070
  * @param ownerID The ID of the owner of the CoList.
1056
1071
  * @param options Additional options for loading the CoList.
1057
- * @returns The loaded CoList, or null if unavailable.
1072
+ * @returns The loaded CoList, or an not-loaded value if unavailable.
1058
1073
  */
1059
1074
  static async loadUnique(unique, ownerID, options) {
1060
1075
  const header = _CoList._getUniqueHeader(unique, ownerID);
1061
1076
  const owner = await Group2.load(ownerID, {
1062
1077
  loadAs: options?.loadAs
1063
1078
  });
1064
- if (!owner) return owner;
1079
+ if (!owner.$isLoaded) return owner;
1065
1080
  return internalLoadUnique(this, {
1066
1081
  header,
1067
1082
  owner,
@@ -1970,13 +1985,19 @@ var FileStream = class extends CoValueBase {
1970
1985
  */
1971
1986
  static async loadAsBlob(id, options) {
1972
1987
  let stream = await this.load(id, options);
1973
- return stream?.toBlob({
1988
+ if (!stream.$isLoaded) {
1989
+ return void 0;
1990
+ }
1991
+ return stream.toBlob({
1974
1992
  allowUnfinished: options?.allowUnfinished
1975
1993
  });
1976
1994
  }
1977
1995
  static async loadAsBase64(id, options) {
1978
1996
  const stream = await this.load(id, options);
1979
- return stream?.asBase64(options);
1997
+ if (!stream.$isLoaded) {
1998
+ return void 0;
1999
+ }
2000
+ return stream.asBase64(options);
1980
2001
  }
1981
2002
  asBase64(options) {
1982
2003
  const chunks = this.getChunks(options);
@@ -2078,7 +2099,7 @@ var FileStream = class extends CoValueBase {
2078
2099
  */
2079
2100
  static async load(id, options) {
2080
2101
  const stream = await loadCoValueWithoutMe(this, id, options);
2081
- if (!options?.allowUnfinished && !stream?.isBinaryStreamEnded()) {
2102
+ if (!options?.allowUnfinished && stream.$isLoaded && !stream.isBinaryStreamEnded()) {
2082
2103
  return new Promise((resolve) => {
2083
2104
  subscribeToCoValueWithoutMe(
2084
2105
  this,
@@ -2676,7 +2697,7 @@ var _Group = class _Group extends CoValueBase {
2676
2697
  const group = await loadCoValueWithoutMe(this, id, {
2677
2698
  loadAs: options?.loadAs
2678
2699
  });
2679
- if (!group) {
2700
+ if (!group.$isLoaded) {
2680
2701
  throw new Error(`Group with id ${id} not found`);
2681
2702
  }
2682
2703
  return group.$jazz.createInvite(options?.role ?? "reader");
@@ -2776,10 +2797,21 @@ import {
2776
2797
  RawAccount as RawAccount3
2777
2798
  } from "cojson";
2778
2799
 
2779
- // src/tools/lib/id.ts
2800
+ // src/tools/lib/utils.ts
2780
2801
  function isCoValueId(id) {
2781
2802
  return typeof id === "string" && id.startsWith("co_z");
2782
2803
  }
2804
+ function assertLoaded(coValue) {
2805
+ if (!coValue.$isLoaded) {
2806
+ throw new Error("CoValue is not loaded");
2807
+ }
2808
+ }
2809
+ function getLoadedOrUndefined(coValue) {
2810
+ if (!coValue?.$isLoaded) {
2811
+ return void 0;
2812
+ }
2813
+ return coValue;
2814
+ }
2783
2815
 
2784
2816
  // src/tools/coValues/inbox.ts
2785
2817
  function createInboxRoot(account) {
@@ -2888,7 +2920,7 @@ var Inbox = class _Inbox {
2888
2920
  const messagesFeed = new IncrementalFeed(this.messages.core);
2889
2921
  const processMessage = async (txKey, messageId) => {
2890
2922
  const message = await node.load(messageId);
2891
- if (message === "unavailable") {
2923
+ if (message === CoValueLoadingState.UNAVAILABLE) {
2892
2924
  throw new Error(`Inbox: message ${messageId} is unavailable`);
2893
2925
  }
2894
2926
  const value = await loadCoValue(
@@ -2962,7 +2994,7 @@ var Inbox = class _Inbox {
2962
2994
  }
2963
2995
  static async load(account) {
2964
2996
  const profile = account.profile;
2965
- if (!profile) {
2997
+ if (!profile.$isLoaded) {
2966
2998
  throw new Error("Account profile should already be loaded");
2967
2999
  }
2968
3000
  if (!profile.inbox) {
@@ -2970,7 +3002,7 @@ var Inbox = class _Inbox {
2970
3002
  }
2971
3003
  const node = account.$jazz.localNode;
2972
3004
  const root = await node.load(profile.inbox);
2973
- if (root === "unavailable") {
3005
+ if (root === CoValueLoadingState.UNAVAILABLE) {
2974
3006
  throw new Error("Inbox not found");
2975
3007
  }
2976
3008
  const [messages, processed, failed] = await Promise.all([
@@ -2978,7 +3010,7 @@ var Inbox = class _Inbox {
2978
3010
  node.load(root.get("processed")),
2979
3011
  node.load(root.get("failed"))
2980
3012
  ]);
2981
- if (messages === "unavailable" || processed === "unavailable" || failed === "unavailable") {
3013
+ if (messages === CoValueLoadingState.UNAVAILABLE || processed === CoValueLoadingState.UNAVAILABLE || failed === CoValueLoadingState.UNAVAILABLE) {
2982
3014
  throw new Error("Inbox not found");
2983
3015
  }
2984
3016
  await processed.core.waitForFullStreaming();
@@ -3018,11 +3050,11 @@ var InboxSender = class _InboxSender {
3018
3050
  const inboxOwnerRaw = await node.load(
3019
3051
  inboxOwnerID
3020
3052
  );
3021
- if (inboxOwnerRaw === "unavailable") {
3053
+ if (inboxOwnerRaw === CoValueLoadingState.UNAVAILABLE) {
3022
3054
  throw new Error("Failed to load the inbox owner");
3023
3055
  }
3024
3056
  const inboxOwnerProfileRaw = await node.load(inboxOwnerRaw.get("profile"));
3025
- if (inboxOwnerProfileRaw === "unavailable") {
3057
+ if (inboxOwnerProfileRaw === CoValueLoadingState.UNAVAILABLE) {
3026
3058
  throw new Error("Failed to load the inbox owner profile");
3027
3059
  }
3028
3060
  const inboxOwnerRole = inboxOwnerProfileRaw.group.roleOf(
@@ -3039,7 +3071,7 @@ var InboxSender = class _InboxSender {
3039
3071
  }
3040
3072
  const id = await acceptInvite(inboxInvite, currentAccount);
3041
3073
  const messages = await node.load(id);
3042
- if (messages === "unavailable") {
3074
+ if (messages === CoValueLoadingState.UNAVAILABLE) {
3043
3075
  throw new Error("Inbox not found");
3044
3076
  }
3045
3077
  return new _InboxSender(currentAccount, inboxOwnerRaw, messages);
@@ -3085,7 +3117,8 @@ var CoPlainText = class extends String {
3085
3117
  $jazz: {
3086
3118
  value: new CoTextJazzApi(this, raw),
3087
3119
  enumerable: false
3088
- }
3120
+ },
3121
+ $isLoaded: { value: true, enumerable: false }
3089
3122
  });
3090
3123
  return;
3091
3124
  }
@@ -3097,7 +3130,8 @@ var CoPlainText = class extends String {
3097
3130
  $jazz: {
3098
3131
  value: new CoTextJazzApi(this, raw),
3099
3132
  enumerable: false
3100
- }
3133
+ },
3134
+ $isLoaded: { value: true, enumerable: false }
3101
3135
  });
3102
3136
  return;
3103
3137
  }
@@ -3341,6 +3375,7 @@ var _CoVector = class _CoVector extends Float32Array {
3341
3375
  value: new CoVectorJazzApi(this, raw),
3342
3376
  enumerable: false
3343
3377
  },
3378
+ $isLoaded: { value: true, enumerable: false },
3344
3379
  _isVectorLoaded: { value: false, enumerable: false, writable: true },
3345
3380
  _requiredDimensionsCount: {
3346
3381
  value: dimensionsCount,
@@ -3441,7 +3476,7 @@ var _CoVector = class _CoVector extends Float32Array {
3441
3476
  */
3442
3477
  static async load(id, options) {
3443
3478
  const coVector = await loadCoValueWithoutMe(this, id, options);
3444
- if (!coVector?.$jazz.raw.isBinaryStreamEnded()) {
3479
+ if (!coVector.$isLoaded || !coVector.$jazz.raw.isBinaryStreamEnded()) {
3445
3480
  return new Promise((resolve) => {
3446
3481
  subscribeToCoValueWithoutMe(
3447
3482
  this,
@@ -3662,23 +3697,27 @@ var Ref = class {
3662
3697
  node = subscriptionScope.childNodes.get(this.id);
3663
3698
  }
3664
3699
  if (!node) {
3665
- return null;
3700
+ return createUnloadedCoValue(this.id, CoValueLoadingState.LOADING);
3666
3701
  }
3667
3702
  const value = node.value;
3668
- if (value?.type === "loaded") {
3703
+ if (value?.type === CoValueLoadingState.LOADED) {
3669
3704
  return value.value;
3670
3705
  } else {
3671
3706
  return new Promise((resolve) => {
3672
3707
  const unsubscribe = node.subscribe((value2) => {
3673
- if (value2?.type === "loaded") {
3708
+ if (value2?.type === CoValueLoadingState.LOADED) {
3674
3709
  unsubscribe();
3675
3710
  resolve(value2.value);
3676
- } else if (value2?.type === "unavailable") {
3711
+ } else if (value2?.type === CoValueLoadingState.UNAVAILABLE) {
3677
3712
  unsubscribe();
3678
- resolve(null);
3679
- } else if (value2?.type === "unauthorized") {
3713
+ resolve(
3714
+ createUnloadedCoValue(this.id, CoValueLoadingState.UNAVAILABLE)
3715
+ );
3716
+ } else if (value2?.type === CoValueLoadingState.UNAUTHORIZED) {
3680
3717
  unsubscribe();
3681
- resolve(null);
3718
+ resolve(
3719
+ createUnloadedCoValue(this.id, CoValueLoadingState.UNAUTHORIZED)
3720
+ );
3682
3721
  }
3683
3722
  if (subscriptionScope.closed) {
3684
3723
  node.destroy();
@@ -3855,6 +3894,28 @@ function applyCoValueMigrations(instance) {
3855
3894
  import {
3856
3895
  cojsonInternals as cojsonInternals4
3857
3896
  } from "cojson";
3897
+
3898
+ // src/tools/subscribe/types.ts
3899
+ var CoValueLoadingState = {
3900
+ /**
3901
+ * The coValue is loaded.
3902
+ */
3903
+ LOADED: "loaded",
3904
+ /**
3905
+ * The coValue is being loaded.
3906
+ */
3907
+ LOADING: "loading",
3908
+ /**
3909
+ * The coValue was loaded but the account is not authorized to access it.
3910
+ */
3911
+ UNAUTHORIZED: "unauthorized",
3912
+ /**
3913
+ * Tried to load the coValue but failed.
3914
+ */
3915
+ UNAVAILABLE: "unavailable"
3916
+ };
3917
+
3918
+ // src/tools/subscribe/CoValueCoreSubscription.ts
3858
3919
  var CoValueCoreSubscription = class {
3859
3920
  constructor(localNode, id, listener, skipRetry, branch) {
3860
3921
  this._unsubscribe = () => {
@@ -3922,14 +3983,14 @@ var CoValueCoreSubscription = class {
3922
3983
  handleBranchCheckout() {
3923
3984
  this.localNode.checkoutBranch(this.source.id, this.branchName, this.branchOwnerId).then((value) => {
3924
3985
  if (this.unsubscribed) return;
3925
- if (value !== "unavailable") {
3986
+ if (value !== CoValueLoadingState.UNAVAILABLE) {
3926
3987
  this.subscribe(value);
3927
3988
  } else {
3928
3989
  this.handleUnavailableBranch();
3929
3990
  }
3930
3991
  }).catch((error) => {
3931
3992
  console.error(error);
3932
- this.emit("unavailable");
3993
+ this.emit(CoValueLoadingState.UNAVAILABLE);
3933
3994
  });
3934
3995
  }
3935
3996
  /**
@@ -3942,7 +4003,7 @@ var CoValueCoreSubscription = class {
3942
4003
  throw new Error("Branch is unavailable");
3943
4004
  }
3944
4005
  this.subscribeToUnavailableSource();
3945
- this.emit("unavailable");
4006
+ this.emit(CoValueLoadingState.UNAVAILABLE);
3946
4007
  }
3947
4008
  /**
3948
4009
  * Loads the CoValue core from the network/storage.
@@ -3955,11 +4016,11 @@ var CoValueCoreSubscription = class {
3955
4016
  this.subscribe(value.getCurrentContent());
3956
4017
  } else {
3957
4018
  this.subscribeToUnavailableSource();
3958
- this.emit("unavailable");
4019
+ this.emit(CoValueLoadingState.UNAVAILABLE);
3959
4020
  }
3960
4021
  }).catch((error) => {
3961
4022
  console.error(error);
3962
- this.emit("unavailable");
4023
+ this.emit(CoValueLoadingState.UNAVAILABLE);
3963
4024
  });
3964
4025
  }
3965
4026
  /**
@@ -4083,7 +4144,7 @@ function createCoValue(ref2, raw, subscriptionScope) {
4083
4144
  configurable: false
4084
4145
  });
4085
4146
  return {
4086
- type: "loaded",
4147
+ type: CoValueLoadingState.LOADED,
4087
4148
  value: freshValueInstance,
4088
4149
  id: subscriptionScope.id
4089
4150
  };
@@ -4121,13 +4182,13 @@ var SubscriptionScope = class _SubscriptionScope {
4121
4182
  this.closed = false;
4122
4183
  this.silenceUpdates = false;
4123
4184
  this.handleChildUpdate = (id, value, key) => {
4124
- if (value.type === "unloaded") {
4185
+ if (value.type === CoValueLoadingState.LOADING) {
4125
4186
  return;
4126
4187
  }
4127
4188
  this.pendingLoadedChildren.delete(id);
4128
4189
  this.pendingAutoloadedChildren.delete(id);
4129
4190
  this.childValues.set(id, value);
4130
- if (value.type === "unavailable" || value.type === "unauthorized") {
4191
+ if (value.type === CoValueLoadingState.UNAVAILABLE || value.type === CoValueLoadingState.UNAUTHORIZED) {
4131
4192
  this.childErrors.set(id, value.prependPath(key ?? id));
4132
4193
  this.errorFromChildren = this.computeChildErrors();
4133
4194
  } else if (this.errorFromChildren && this.childErrors.has(id)) {
@@ -4135,7 +4196,7 @@ var SubscriptionScope = class _SubscriptionScope {
4135
4196
  this.errorFromChildren = this.computeChildErrors();
4136
4197
  }
4137
4198
  if (this.shouldSendUpdates()) {
4138
- if (this.value.type === "loaded") {
4199
+ if (this.value.type === CoValueLoadingState.LOADED) {
4139
4200
  this.updateValue(
4140
4201
  createCoValue(this.schema, this.value.value.$jazz.raw, this)
4141
4202
  );
@@ -4145,18 +4206,18 @@ var SubscriptionScope = class _SubscriptionScope {
4145
4206
  };
4146
4207
  this.subscribers = /* @__PURE__ */ new Set();
4147
4208
  this.resolve = resolve;
4148
- this.value = { type: "unloaded", id };
4209
+ this.value = { type: CoValueLoadingState.LOADING, id };
4149
4210
  let lastUpdate;
4150
4211
  this.subscription = new CoValueCoreSubscription(
4151
4212
  node,
4152
4213
  id,
4153
4214
  (value) => {
4154
4215
  lastUpdate = value;
4155
- if (skipRetry && value === "unavailable") {
4216
+ if (skipRetry && value === CoValueLoadingState.UNAVAILABLE) {
4156
4217
  this.handleUpdate(value);
4157
4218
  return;
4158
4219
  }
4159
- if (!this.migrated && value !== "unavailable") {
4220
+ if (!this.migrated && value !== CoValueLoadingState.UNAVAILABLE) {
4160
4221
  if (this.migrating) {
4161
4222
  return;
4162
4223
  }
@@ -4179,12 +4240,12 @@ var SubscriptionScope = class _SubscriptionScope {
4179
4240
  this.dirty = true;
4180
4241
  }
4181
4242
  handleUpdate(update) {
4182
- if (update === "unavailable") {
4183
- if (this.value.type === "unloaded") {
4243
+ if (update === CoValueLoadingState.UNAVAILABLE) {
4244
+ if (this.value.type === CoValueLoadingState.LOADING) {
4184
4245
  this.updateValue(
4185
- new JazzError(this.id, "unavailable", [
4246
+ new JazzError(this.id, CoValueLoadingState.UNAVAILABLE, [
4186
4247
  {
4187
- code: "unavailable",
4248
+ code: CoValueLoadingState.UNAVAILABLE,
4188
4249
  message: "The value is unavailable",
4189
4250
  params: {
4190
4251
  id: this.id
@@ -4200,11 +4261,11 @@ var SubscriptionScope = class _SubscriptionScope {
4200
4261
  const ruleset = update.core.verified.header.ruleset;
4201
4262
  const hasAccess = ruleset.type !== "ownedByGroup" || myRoleForRawValue(update) !== void 0;
4202
4263
  if (!hasAccess) {
4203
- if (this.value.type !== "unauthorized") {
4264
+ if (this.value.type !== CoValueLoadingState.UNAUTHORIZED) {
4204
4265
  this.updateValue(
4205
- new JazzError(this.id, "unauthorized", [
4266
+ new JazzError(this.id, CoValueLoadingState.UNAUTHORIZED, [
4206
4267
  {
4207
- code: "unauthorized",
4268
+ code: CoValueLoadingState.UNAUTHORIZED,
4208
4269
  message: `The current user (${this.node.getCurrentAgent().id}) is not authorized to access this value`,
4209
4270
  params: {
4210
4271
  id: this.id
@@ -4218,7 +4279,7 @@ var SubscriptionScope = class _SubscriptionScope {
4218
4279
  return;
4219
4280
  }
4220
4281
  this.silenceUpdates = true;
4221
- if (this.value.type !== "loaded") {
4282
+ if (this.value.type !== CoValueLoadingState.LOADED) {
4222
4283
  this.updateValue(createCoValue(this.schema, update, this));
4223
4284
  this.loadChildren();
4224
4285
  } else {
@@ -4237,7 +4298,7 @@ var SubscriptionScope = class _SubscriptionScope {
4237
4298
  }
4238
4299
  computeChildErrors() {
4239
4300
  let issues = [];
4240
- let errorType = "unavailable";
4301
+ let errorType = CoValueLoadingState.UNAVAILABLE;
4241
4302
  if (this.childErrors.size === 0 && this.validationErrors.size === 0) {
4242
4303
  return void 0;
4243
4304
  }
@@ -4271,26 +4332,26 @@ var SubscriptionScope = class _SubscriptionScope {
4271
4332
  return void 0;
4272
4333
  }
4273
4334
  shouldSendUpdates() {
4274
- if (this.value.type === "unloaded") return false;
4275
- if (this.value.type !== "loaded") return true;
4335
+ if (this.value.type === CoValueLoadingState.LOADING) return false;
4336
+ if (this.value.type !== CoValueLoadingState.LOADED) return true;
4276
4337
  return this.pendingLoadedChildren.size === 0;
4277
4338
  }
4278
4339
  getCurrentValue() {
4279
- if (this.value.type === "unauthorized" || this.value.type === "unavailable") {
4340
+ if (this.value.type === CoValueLoadingState.UNAUTHORIZED || this.value.type === CoValueLoadingState.UNAVAILABLE) {
4280
4341
  console.error(this.value.toString());
4281
- return null;
4342
+ return this.value.type;
4282
4343
  }
4283
4344
  if (!this.shouldSendUpdates()) {
4284
- return void 0;
4345
+ return CoValueLoadingState.LOADING;
4285
4346
  }
4286
4347
  if (this.errorFromChildren) {
4287
4348
  console.error(this.errorFromChildren.toString());
4288
- return null;
4349
+ return this.errorFromChildren.type;
4289
4350
  }
4290
- if (this.value.type === "loaded") {
4351
+ if (this.value.type === CoValueLoadingState.LOADED) {
4291
4352
  return this.value.value;
4292
4353
  }
4293
- return void 0;
4354
+ return CoValueLoadingState.LOADING;
4294
4355
  }
4295
4356
  triggerUpdate() {
4296
4357
  if (!this.shouldSendUpdates()) return;
@@ -4301,7 +4362,7 @@ var SubscriptionScope = class _SubscriptionScope {
4301
4362
  const value = this.value;
4302
4363
  if (error) {
4303
4364
  this.subscribers.forEach((listener) => listener(error));
4304
- } else if (value.type !== "unloaded") {
4365
+ } else if (value.type !== CoValueLoadingState.LOADING) {
4305
4366
  this.subscribers.forEach((listener) => listener(value));
4306
4367
  }
4307
4368
  this.dirty = false;
@@ -4320,12 +4381,12 @@ var SubscriptionScope = class _SubscriptionScope {
4320
4381
  if (this.resolve === true || !this.resolve) {
4321
4382
  this.resolve = {};
4322
4383
  }
4323
- if (!this.resolve.$each && !(key in this.resolve)) {
4324
- const resolve = this.resolve;
4384
+ const resolve = this.resolve;
4385
+ if (!resolve.$each && !(key in resolve)) {
4325
4386
  resolve[key] = true;
4326
4387
  this.autoloadedKeys.add(key);
4327
4388
  }
4328
- if (this.value.type !== "loaded") {
4389
+ if (this.value.type !== CoValueLoadingState.LOADED) {
4329
4390
  return;
4330
4391
  }
4331
4392
  const value = this.value.value;
@@ -4351,14 +4412,14 @@ var SubscriptionScope = class _SubscriptionScope {
4351
4412
  if (!this.closed) {
4352
4413
  throw new Error("Cannot pull a non-closed subscription scope");
4353
4414
  }
4354
- if (this.value.type === "loaded") {
4415
+ if (this.value.type === CoValueLoadingState.LOADED) {
4355
4416
  return;
4356
4417
  }
4357
4418
  this.subscription.pullValue();
4358
4419
  const value = this.getCurrentValue();
4359
- if (value) {
4420
+ if (typeof value !== "string") {
4360
4421
  listener({
4361
- type: "loaded",
4422
+ type: CoValueLoadingState.LOADED,
4362
4423
  value,
4363
4424
  id: this.id
4364
4425
  });
@@ -4397,7 +4458,7 @@ var SubscriptionScope = class _SubscriptionScope {
4397
4458
  }
4398
4459
  loadChildren() {
4399
4460
  const { resolve } = this;
4400
- if (this.value.type !== "loaded") {
4461
+ if (this.value.type !== CoValueLoadingState.LOADED) {
4401
4462
  return false;
4402
4463
  }
4403
4464
  const value = this.value.value;
@@ -4448,7 +4509,7 @@ var SubscriptionScope = class _SubscriptionScope {
4448
4509
  } else if (!descriptor.optional) {
4449
4510
  this.validationErrors.set(
4450
4511
  key,
4451
- new JazzError(void 0, "unavailable", [
4512
+ new JazzError(void 0, CoValueLoadingState.UNAVAILABLE, [
4452
4513
  {
4453
4514
  code: "validationError",
4454
4515
  message: `The ref on position ${key} requested on ${stream.constructor.name} is missing`,
@@ -4488,7 +4549,7 @@ var SubscriptionScope = class _SubscriptionScope {
4488
4549
  if (!descriptor) {
4489
4550
  this.childErrors.set(
4490
4551
  key,
4491
- new JazzError(void 0, "unavailable", [
4552
+ new JazzError(void 0, CoValueLoadingState.UNAVAILABLE, [
4492
4553
  {
4493
4554
  code: "validationError",
4494
4555
  message: `The ref ${key} requested on ${map.constructor.name} is not defined in the schema`,
@@ -4507,7 +4568,7 @@ var SubscriptionScope = class _SubscriptionScope {
4507
4568
  } else if (!descriptor.optional) {
4508
4569
  this.validationErrors.set(
4509
4570
  key,
4510
- new JazzError(void 0, "unavailable", [
4571
+ new JazzError(void 0, CoValueLoadingState.UNAVAILABLE, [
4511
4572
  {
4512
4573
  code: "validationError",
4513
4574
  message: `The ref ${key} requested on ${map.constructor.name} is missing`,
@@ -4538,7 +4599,7 @@ var SubscriptionScope = class _SubscriptionScope {
4538
4599
  } else if (!descriptor.optional) {
4539
4600
  this.validationErrors.set(
4540
4601
  key,
4541
- new JazzError(void 0, "unavailable", [
4602
+ new JazzError(void 0, CoValueLoadingState.UNAVAILABLE, [
4542
4603
  {
4543
4604
  code: "validationError",
4544
4605
  message: `The ref on position ${key} requested on ${list.constructor.name} is missing`,
@@ -4558,7 +4619,7 @@ var SubscriptionScope = class _SubscriptionScope {
4558
4619
  if (isAutoloaded) {
4559
4620
  this.autoloaded.add(id);
4560
4621
  }
4561
- const skipInvalid = typeof query === "object" && query.$onError === null;
4622
+ const skipInvalid = typeof query === "object" && query.$onError === "catch";
4562
4623
  if (skipInvalid) {
4563
4624
  if (key) {
4564
4625
  this.skipInvalidKeys.add(key);
@@ -4627,20 +4688,26 @@ function accessChildByKey(parent, childId, key) {
4627
4688
  );
4628
4689
  }
4629
4690
  const value = subscriptionScope.childValues.get(childId);
4630
- if (value?.type === "loaded") {
4691
+ if (value?.type === CoValueLoadingState.LOADED) {
4631
4692
  return value.value;
4632
4693
  } else {
4633
- return null;
4694
+ return createUnloadedCoValue(
4695
+ childId,
4696
+ value?.type ?? CoValueLoadingState.LOADING
4697
+ );
4634
4698
  }
4635
4699
  }
4636
4700
  function accessChildById(parent, childId, schema) {
4637
4701
  const subscriptionScope = getSubscriptionScope(parent);
4638
4702
  subscriptionScope.subscribeToId(childId, schema);
4639
4703
  const value = subscriptionScope.childValues.get(childId);
4640
- if (value?.type === "loaded") {
4704
+ if (value?.type === CoValueLoadingState.LOADED) {
4641
4705
  return value.value;
4642
4706
  } else {
4643
- return null;
4707
+ return createUnloadedCoValue(
4708
+ childId,
4709
+ value?.type ?? CoValueLoadingState.LOADING
4710
+ );
4644
4711
  }
4645
4712
  }
4646
4713
 
@@ -4827,6 +4894,7 @@ var CoDiscriminatedUnionSchema = class {
4827
4894
  this.coValueClass = coValueClass;
4828
4895
  this.collaborative = true;
4829
4896
  this.builtin = "CoDiscriminatedUnion";
4897
+ this.resolveQuery = true;
4830
4898
  this.getDefinition = coreSchema.getDefinition;
4831
4899
  }
4832
4900
  load(id, options) {
@@ -4868,7 +4936,8 @@ function createCoreCoDiscriminatedUnionSchema(discriminator, schemas) {
4868
4936
  get options() {
4869
4937
  return schemas;
4870
4938
  }
4871
- })
4939
+ }),
4940
+ resolveQuery: true
4872
4941
  };
4873
4942
  }
4874
4943
 
@@ -4881,6 +4950,7 @@ var CoOptionalSchema = class {
4881
4950
  this.getDefinition = () => ({
4882
4951
  innerType: this.innerType
4883
4952
  });
4953
+ this.resolveQuery = true;
4884
4954
  }
4885
4955
  getCoValueClass() {
4886
4956
  return this.innerType.getCoValueClass();
@@ -4891,7 +4961,8 @@ var CoOptionalSchema = class {
4891
4961
  function createCoreCoRichTextSchema() {
4892
4962
  return {
4893
4963
  collaborative: true,
4894
- builtin: "CoRichText"
4964
+ builtin: "CoRichText",
4965
+ resolveQuery: true
4895
4966
  };
4896
4967
  }
4897
4968
  var RichTextSchema = class {
@@ -4899,6 +4970,7 @@ var RichTextSchema = class {
4899
4970
  this.coValueClass = coValueClass;
4900
4971
  this.collaborative = true;
4901
4972
  this.builtin = "CoRichText";
4973
+ this.resolveQuery = true;
4902
4974
  }
4903
4975
  create(text, options) {
4904
4976
  return this.coValueClass.create(text, options);
@@ -4910,7 +4982,7 @@ var RichTextSchema = class {
4910
4982
  return this.coValueClass.subscribe(...args);
4911
4983
  }
4912
4984
  unstable_merge(id, options) {
4913
- return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
4985
+ return unstable_mergeBranchWithResolve(this.coValueClass, id, options);
4914
4986
  }
4915
4987
  getCoValueClass() {
4916
4988
  return this.coValueClass;
@@ -4924,13 +4996,15 @@ var RichTextSchema = class {
4924
4996
  function createCoreGroupSchema() {
4925
4997
  return {
4926
4998
  collaborative: true,
4927
- builtin: "Group"
4999
+ builtin: "Group",
5000
+ resolveQuery: true
4928
5001
  };
4929
5002
  }
4930
5003
  var GroupSchema = class {
4931
5004
  constructor() {
4932
5005
  this.collaborative = true;
4933
5006
  this.builtin = "Group";
5007
+ this.resolveQuery = true;
4934
5008
  }
4935
5009
  getCoValueClass() {
4936
5010
  return Group2;
@@ -5062,11 +5136,13 @@ var coDiscriminatedUnionDefiner = (discriminator, schemas) => {
5062
5136
  // src/tools/implementation/zodSchema/coExport.ts
5063
5137
  var coExport_exports = {};
5064
5138
  __export(coExport_exports, {
5139
+ Account: () => AccountSchema,
5065
5140
  DiscriminatedUnion: () => CoDiscriminatedUnionSchema,
5066
5141
  Feed: () => CoFeedSchema,
5067
5142
  FileStream: () => FileStreamSchema,
5068
5143
  Group: () => GroupSchema,
5069
5144
  List: () => CoListSchema,
5145
+ Map: () => CoMapSchema,
5070
5146
  Optional: () => CoOptionalSchema,
5071
5147
  PlainText: () => PlainTextSchema,
5072
5148
  RichText: () => RichTextSchema,
@@ -5088,6 +5164,156 @@ __export(coExport_exports, {
5088
5164
  });
5089
5165
 
5090
5166
  // src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
5167
+ var CoMapSchema = class _CoMapSchema {
5168
+ constructor(coreSchema, coValueClass) {
5169
+ this.coValueClass = coValueClass;
5170
+ this.collaborative = true;
5171
+ this.builtin = "CoMap";
5172
+ /**
5173
+ * Default resolve query to be used when loading instances of this schema.
5174
+ * This resolve query will be used when no resolve query is provided to the load method.
5175
+ * @default true
5176
+ */
5177
+ this.resolveQuery = true;
5178
+ this.shape = coreSchema.shape;
5179
+ this.catchAll = coreSchema.catchAll;
5180
+ this.getDefinition = coreSchema.getDefinition;
5181
+ }
5182
+ create(...args) {
5183
+ return this.coValueClass.create(...args);
5184
+ }
5185
+ load(id, options) {
5186
+ return this.coValueClass.load(
5187
+ id,
5188
+ // @ts-expect-error
5189
+ withSchemaResolveQuery(options, this.resolveQuery)
5190
+ );
5191
+ }
5192
+ unstable_merge(id, options) {
5193
+ return unstable_mergeBranchWithResolve(
5194
+ this.coValueClass,
5195
+ id,
5196
+ // @ts-expect-error
5197
+ withSchemaResolveQuery(options, this.resolveQuery)
5198
+ );
5199
+ }
5200
+ subscribe(id, options, listener) {
5201
+ return this.coValueClass.subscribe(
5202
+ id,
5203
+ withSchemaResolveQuery(options, this.resolveQuery),
5204
+ listener
5205
+ );
5206
+ }
5207
+ /** @deprecated Use `CoMap.upsertUnique` and `CoMap.loadUnique` instead. */
5208
+ findUnique(unique, ownerID, as) {
5209
+ return this.coValueClass.findUnique(unique, ownerID, as);
5210
+ }
5211
+ upsertUnique(options) {
5212
+ return this.coValueClass.upsertUnique(
5213
+ // @ts-expect-error
5214
+ withSchemaResolveQuery(options, this.resolveQuery)
5215
+ );
5216
+ }
5217
+ loadUnique(unique, ownerID, options) {
5218
+ return this.coValueClass.loadUnique(
5219
+ unique,
5220
+ ownerID,
5221
+ // @ts-expect-error
5222
+ withSchemaResolveQuery(options, this.resolveQuery)
5223
+ );
5224
+ }
5225
+ /**
5226
+ * @deprecated `co.map().catchall` will be removed in an upcoming version.
5227
+ *
5228
+ * Use a `co.record` nested inside a `co.map` if you need to store key-value properties.
5229
+ *
5230
+ * @example
5231
+ * ```ts
5232
+ * // Instead of:
5233
+ * const Image = co.map({
5234
+ * original: co.fileStream(),
5235
+ * }).catchall(co.fileStream());
5236
+ *
5237
+ * // Use:
5238
+ * const Image = co.map({
5239
+ * original: co.fileStream(),
5240
+ * resolutions: co.record(z.string(), co.fileStream()),
5241
+ * });
5242
+ * ```
5243
+ */
5244
+ catchall(schema) {
5245
+ const schemaWithCatchAll = createCoreCoMapSchema(this.shape, schema);
5246
+ return hydrateCoreCoValueSchema(schemaWithCatchAll);
5247
+ }
5248
+ withMigration(migration) {
5249
+ this.coValueClass.prototype.migrate = migration;
5250
+ return this;
5251
+ }
5252
+ getCoValueClass() {
5253
+ return this.coValueClass;
5254
+ }
5255
+ optional() {
5256
+ return coOptionalDefiner(this);
5257
+ }
5258
+ /**
5259
+ * Creates a new CoMap schema by picking the specified keys from the original schema.
5260
+ *
5261
+ * @param keys - The keys to pick from the original schema.
5262
+ * @returns A new CoMap schema with the picked keys.
5263
+ */
5264
+ pick(keys) {
5265
+ const keysSet = new Set(Object.keys(keys));
5266
+ const pickedShape = {};
5267
+ for (const [key, value] of Object.entries(this.shape)) {
5268
+ if (keysSet.has(key)) {
5269
+ pickedShape[key] = value;
5270
+ }
5271
+ }
5272
+ return coMapDefiner(pickedShape);
5273
+ }
5274
+ /**
5275
+ * Creates a new CoMap schema by making all fields optional.
5276
+ *
5277
+ * @returns A new CoMap schema with all fields optional.
5278
+ */
5279
+ partial(keys) {
5280
+ const partialShape = {};
5281
+ for (const [key, value] of Object.entries(this.shape)) {
5282
+ if (keys && !keys[key]) {
5283
+ partialShape[key] = value;
5284
+ continue;
5285
+ }
5286
+ if (isAnyCoValueSchema2(value)) {
5287
+ partialShape[key] = coOptionalDefiner(value);
5288
+ } else {
5289
+ partialShape[key] = z.optional(this.shape[key]);
5290
+ }
5291
+ }
5292
+ const partialCoMapSchema = coMapDefiner(partialShape);
5293
+ if (this.catchAll) {
5294
+ return partialCoMapSchema.catchall(
5295
+ this.catchAll
5296
+ );
5297
+ }
5298
+ return partialCoMapSchema;
5299
+ }
5300
+ /**
5301
+ * Adds a default resolve query to be used when loading instances of this schema.
5302
+ * This resolve query will be used when no resolve query is provided to the load method.
5303
+ */
5304
+ resolved(resolveQuery) {
5305
+ const coreSchema = createCoreCoMapSchema(
5306
+ this.shape,
5307
+ this.catchAll
5308
+ );
5309
+ const copy = new _CoMapSchema(
5310
+ coreSchema,
5311
+ this.coValueClass
5312
+ );
5313
+ copy.resolveQuery = resolveQuery;
5314
+ return copy;
5315
+ }
5316
+ };
5091
5317
  function createCoreCoMapSchema(shape, catchAll) {
5092
5318
  return {
5093
5319
  collaborative: true,
@@ -5115,103 +5341,49 @@ function createCoreCoMapSchema(shape, catchAll) {
5115
5341
  }
5116
5342
  return propValues;
5117
5343
  }
5118
- })
5344
+ }),
5345
+ resolveQuery: true
5119
5346
  };
5120
5347
  }
5121
- function enrichCoMapSchema(schema, coValueClass) {
5122
- const coValueSchema = Object.assign(schema, {
5123
- create: (...args) => {
5124
- return coValueClass.create(...args);
5125
- },
5126
- load: (...args) => {
5127
- return coValueClass.load(...args);
5128
- },
5129
- subscribe: (...args) => {
5130
- return coValueClass.subscribe(...args);
5131
- },
5132
- findUnique: (...args) => {
5133
- return coValueClass.findUnique(...args);
5134
- },
5135
- upsertUnique: (...args) => {
5136
- return coValueClass.upsertUnique(...args);
5137
- },
5138
- loadUnique: (...args) => {
5139
- return coValueClass.loadUnique(...args);
5140
- },
5141
- unstable_merge: (...args) => {
5142
- return unstable_mergeBranchWithResolve2(coValueClass, ...args);
5143
- },
5144
- catchall: (catchAll) => {
5145
- const schemaWithCatchAll = createCoreCoMapSchema(
5146
- coValueSchema.getDefinition().shape,
5147
- catchAll
5148
- );
5149
- return hydrateCoreCoValueSchema(schemaWithCatchAll);
5150
- },
5151
- withMigration: (migration) => {
5152
- coValueClass.prototype.migrate = migration;
5153
- return coValueSchema;
5154
- },
5155
- getCoValueClass: () => {
5156
- return coValueClass;
5157
- },
5158
- optional: () => {
5159
- return coOptionalDefiner(coValueSchema);
5160
- },
5161
- pick: (keys) => {
5162
- const keysSet = new Set(Object.keys(keys));
5163
- const pickedShape = {};
5164
- for (const [key, value] of Object.entries(coValueSchema.shape)) {
5165
- if (keysSet.has(key)) {
5166
- pickedShape[key] = value;
5167
- }
5168
- }
5169
- return coMapDefiner(pickedShape);
5170
- },
5171
- partial: (keys) => {
5172
- const partialShape = {};
5173
- for (const [key, value] of Object.entries(coValueSchema.shape)) {
5174
- if (keys && !keys[key]) {
5175
- partialShape[key] = value;
5176
- continue;
5177
- }
5178
- if (isAnyCoValueSchema2(value)) {
5179
- partialShape[key] = coOptionalDefiner(value);
5180
- } else {
5181
- partialShape[key] = z.optional(coValueSchema.shape[key]);
5182
- }
5183
- }
5184
- const partialCoMapSchema = coMapDefiner(partialShape);
5185
- if (coValueSchema.catchAll) {
5186
- return partialCoMapSchema.catchall(
5187
- coValueSchema.catchAll
5188
- );
5189
- }
5190
- return partialCoMapSchema;
5191
- }
5192
- });
5193
- return coValueSchema;
5194
- }
5195
5348
 
5196
5349
  // src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts
5197
- var CoListSchema = class {
5350
+ var CoListSchema = class _CoListSchema {
5198
5351
  constructor(element, coValueClass) {
5199
5352
  this.element = element;
5200
5353
  this.coValueClass = coValueClass;
5201
5354
  this.collaborative = true;
5202
5355
  this.builtin = "CoList";
5356
+ /**
5357
+ * Default resolve query to be used when loading instances of this schema.
5358
+ * This resolve query will be used when no resolve query is provided to the load method.
5359
+ * @default true
5360
+ */
5361
+ this.resolveQuery = true;
5203
5362
  }
5204
5363
  create(items, options) {
5205
5364
  return this.coValueClass.create(items, options);
5206
5365
  }
5207
5366
  load(id, options) {
5208
- return this.coValueClass.load(id, options);
5367
+ return this.coValueClass.load(
5368
+ id,
5369
+ // @ts-expect-error
5370
+ withSchemaResolveQuery(options, this.resolveQuery)
5371
+ );
5209
5372
  }
5210
5373
  unstable_merge(id, options) {
5211
- return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
5374
+ return unstable_mergeBranchWithResolve(
5375
+ this.coValueClass,
5376
+ id,
5377
+ // @ts-expect-error
5378
+ withSchemaResolveQuery(options, this.resolveQuery)
5379
+ );
5212
5380
  }
5213
5381
  subscribe(id, options, listener) {
5214
- return this.coValueClass.subscribe(id, options, listener);
5382
+ return this.coValueClass.subscribe(
5383
+ id,
5384
+ withSchemaResolveQuery(options, this.resolveQuery),
5385
+ listener
5386
+ );
5215
5387
  }
5216
5388
  getCoValueClass() {
5217
5389
  return this.coValueClass;
@@ -5221,42 +5393,81 @@ var CoListSchema = class {
5221
5393
  return this.coValueClass.findUnique(unique, ownerID, as);
5222
5394
  }
5223
5395
  upsertUnique(options) {
5224
- return this.coValueClass.upsertUnique(options);
5396
+ return this.coValueClass.upsertUnique(
5397
+ // @ts-expect-error
5398
+ withSchemaResolveQuery(options, this.resolveQuery)
5399
+ );
5225
5400
  }
5226
5401
  loadUnique(unique, ownerID, options) {
5227
- return this.coValueClass.loadUnique(unique, ownerID, options);
5402
+ return this.coValueClass.loadUnique(
5403
+ unique,
5404
+ ownerID,
5405
+ // @ts-expect-error
5406
+ withSchemaResolveQuery(options, this.resolveQuery)
5407
+ );
5228
5408
  }
5229
5409
  optional() {
5230
5410
  return coOptionalDefiner(this);
5231
5411
  }
5412
+ /**
5413
+ * Adds a default resolve query to be used when loading instances of this schema.
5414
+ * This resolve query will be used when no resolve query is provided to the load method.
5415
+ */
5416
+ resolved(resolveQuery) {
5417
+ const copy = new _CoListSchema(this.element, this.coValueClass);
5418
+ copy.resolveQuery = resolveQuery;
5419
+ return copy;
5420
+ }
5232
5421
  };
5233
5422
  function createCoreCoListSchema(element) {
5234
5423
  return {
5235
5424
  collaborative: true,
5236
5425
  builtin: "CoList",
5237
- element
5426
+ element,
5427
+ resolveQuery: true
5238
5428
  };
5239
5429
  }
5240
5430
 
5241
5431
  // src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts
5242
- var CoFeedSchema = class {
5432
+ var CoFeedSchema = class _CoFeedSchema {
5243
5433
  constructor(element, coValueClass) {
5244
5434
  this.element = element;
5245
5435
  this.coValueClass = coValueClass;
5246
5436
  this.collaborative = true;
5247
5437
  this.builtin = "CoFeed";
5438
+ /**
5439
+ * Default resolve query to be used when loading instances of this schema.
5440
+ * This resolve query will be used when no resolve query is provided to the load method.
5441
+ * @default true
5442
+ */
5443
+ this.resolveQuery = true;
5248
5444
  }
5249
5445
  create(init, options) {
5250
5446
  return this.coValueClass.create(init, options);
5251
5447
  }
5252
5448
  load(id, options) {
5253
- return this.coValueClass.load(id, options);
5449
+ return this.coValueClass.load(
5450
+ id,
5451
+ // @ts-expect-error
5452
+ withSchemaResolveQuery(options, this.resolveQuery)
5453
+ );
5254
5454
  }
5255
5455
  unstable_merge(id, options) {
5256
- return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
5456
+ return unstable_mergeBranchWithResolve(
5457
+ this.coValueClass,
5458
+ id,
5459
+ // @ts-expect-error
5460
+ withSchemaResolveQuery(options, this.resolveQuery)
5461
+ );
5257
5462
  }
5258
- subscribe(...args) {
5259
- return this.coValueClass.subscribe(...args);
5463
+ subscribe(id, ...args) {
5464
+ const { options, listener } = parseSubscribeRestArgs(args);
5465
+ return this.coValueClass.subscribe(
5466
+ id,
5467
+ // @ts-expect-error
5468
+ withSchemaResolveQuery(options, this.resolveQuery),
5469
+ listener
5470
+ );
5260
5471
  }
5261
5472
  getCoValueClass() {
5262
5473
  return this.coValueClass;
@@ -5264,12 +5475,22 @@ var CoFeedSchema = class {
5264
5475
  optional() {
5265
5476
  return coOptionalDefiner(this);
5266
5477
  }
5478
+ /**
5479
+ * Adds a default resolve query to be used when loading instances of this schema.
5480
+ * This resolve query will be used when no resolve query is provided to the load method.
5481
+ */
5482
+ resolved(resolveQuery) {
5483
+ const copy = new _CoFeedSchema(this.element, this.coValueClass);
5484
+ copy.resolveQuery = resolveQuery;
5485
+ return copy;
5486
+ }
5267
5487
  };
5268
5488
  function createCoreCoFeedSchema(element) {
5269
5489
  return {
5270
5490
  collaborative: true,
5271
5491
  builtin: "CoFeed",
5272
- element
5492
+ element,
5493
+ resolveQuery: true
5273
5494
  };
5274
5495
  }
5275
5496
 
@@ -5277,7 +5498,8 @@ function createCoreCoFeedSchema(element) {
5277
5498
  function createCoreCoPlainTextSchema() {
5278
5499
  return {
5279
5500
  collaborative: true,
5280
- builtin: "CoPlainText"
5501
+ builtin: "CoPlainText",
5502
+ resolveQuery: true
5281
5503
  };
5282
5504
  }
5283
5505
  var PlainTextSchema = class {
@@ -5285,6 +5507,7 @@ var PlainTextSchema = class {
5285
5507
  this.coValueClass = coValueClass;
5286
5508
  this.collaborative = true;
5287
5509
  this.builtin = "CoPlainText";
5510
+ this.resolveQuery = true;
5288
5511
  }
5289
5512
  create(text, options) {
5290
5513
  return this.coValueClass.create(text, options);
@@ -5296,7 +5519,7 @@ var PlainTextSchema = class {
5296
5519
  return this.coValueClass.subscribe(...args);
5297
5520
  }
5298
5521
  unstable_merge(id, options) {
5299
- return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
5522
+ return unstable_mergeBranchWithResolve(this.coValueClass, id, options);
5300
5523
  }
5301
5524
  fromRaw(raw) {
5302
5525
  return this.coValueClass.fromRaw(raw);
@@ -5313,7 +5536,8 @@ var PlainTextSchema = class {
5313
5536
  function createCoreFileStreamSchema() {
5314
5537
  return {
5315
5538
  collaborative: true,
5316
- builtin: "FileStream"
5539
+ builtin: "FileStream",
5540
+ resolveQuery: true
5317
5541
  };
5318
5542
  }
5319
5543
  var FileStreamSchema = class {
@@ -5321,6 +5545,7 @@ var FileStreamSchema = class {
5321
5545
  this.coValueClass = coValueClass;
5322
5546
  this.collaborative = true;
5323
5547
  this.builtin = "FileStream";
5548
+ this.resolveQuery = true;
5324
5549
  }
5325
5550
  create(options) {
5326
5551
  return this.coValueClass.create(options);
@@ -5338,7 +5563,7 @@ var FileStreamSchema = class {
5338
5563
  return this.coValueClass.load(id, options);
5339
5564
  }
5340
5565
  unstable_merge(id, options) {
5341
- return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
5566
+ return unstable_mergeBranchWithResolve(this.coValueClass, id, options);
5342
5567
  }
5343
5568
  subscribe(...args) {
5344
5569
  return this.coValueClass.subscribe(...args);
@@ -5356,7 +5581,8 @@ function createCoreCoVectorSchema(dimensions) {
5356
5581
  return {
5357
5582
  collaborative: true,
5358
5583
  builtin: "CoVector",
5359
- dimensions
5584
+ dimensions,
5585
+ resolveQuery: true
5360
5586
  };
5361
5587
  }
5362
5588
  var CoVectorSchema = class {
@@ -5365,6 +5591,7 @@ var CoVectorSchema = class {
5365
5591
  this.coValueClass = coValueClass;
5366
5592
  this.collaborative = true;
5367
5593
  this.builtin = "CoVector";
5594
+ this.resolveQuery = true;
5368
5595
  }
5369
5596
  create(vector, options) {
5370
5597
  return this.coValueClass.create(vector, options);
@@ -5387,48 +5614,84 @@ var CoVectorSchema = class {
5387
5614
  };
5388
5615
 
5389
5616
  // src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
5617
+ var AccountSchema = class _AccountSchema {
5618
+ constructor(coreSchema, coValueClass) {
5619
+ this.coValueClass = coValueClass;
5620
+ this.collaborative = true;
5621
+ this.builtin = "Account";
5622
+ /**
5623
+ * Default resolve query to be used when loading instances of this schema.
5624
+ * This resolve query will be used when no resolve query is provided to the load method.
5625
+ * @default true
5626
+ */
5627
+ this.resolveQuery = true;
5628
+ this.shape = coreSchema.shape;
5629
+ this.getDefinition = coreSchema.getDefinition;
5630
+ }
5631
+ create(options) {
5632
+ return this.coValueClass.create(options);
5633
+ }
5634
+ load(id, options) {
5635
+ return this.coValueClass.load(
5636
+ id,
5637
+ // @ts-expect-error
5638
+ withSchemaResolveQuery(options, this.resolveQuery)
5639
+ );
5640
+ }
5641
+ /** @internal */
5642
+ createAs(as, options) {
5643
+ return this.coValueClass.createAs(as, options);
5644
+ }
5645
+ unstable_merge(id, options) {
5646
+ return unstable_mergeBranchWithResolve(
5647
+ this.coValueClass,
5648
+ id,
5649
+ // @ts-expect-error
5650
+ withSchemaResolveQuery(options, this.resolveQuery)
5651
+ );
5652
+ }
5653
+ subscribe(id, options, listener) {
5654
+ return this.coValueClass.subscribe(
5655
+ id,
5656
+ // @ts-expect-error
5657
+ withSchemaResolveQuery(options, this.resolveQuery),
5658
+ listener
5659
+ );
5660
+ }
5661
+ getMe() {
5662
+ return this.coValueClass.getMe();
5663
+ }
5664
+ withMigration(migration) {
5665
+ this.coValueClass.prototype.migrate = async function(creationProps) {
5666
+ await migration(this, creationProps);
5667
+ };
5668
+ return this;
5669
+ }
5670
+ getCoValueClass() {
5671
+ return this.coValueClass;
5672
+ }
5673
+ optional() {
5674
+ return coOptionalDefiner(this);
5675
+ }
5676
+ /**
5677
+ * Adds a default resolve query to be used when loading instances of this schema.
5678
+ * This resolve query will be used when no resolve query is provided to the load method.
5679
+ */
5680
+ resolved(resolveQuery) {
5681
+ const coreSchema = createCoreAccountSchema(
5682
+ this.shape
5683
+ );
5684
+ const copy = new _AccountSchema(coreSchema, this.coValueClass);
5685
+ copy.resolveQuery = resolveQuery;
5686
+ return copy;
5687
+ }
5688
+ };
5390
5689
  function createCoreAccountSchema(shape) {
5391
5690
  return {
5392
5691
  ...createCoreCoMapSchema(shape),
5393
5692
  builtin: "Account"
5394
5693
  };
5395
5694
  }
5396
- function enrichAccountSchema(schema, coValueClass) {
5397
- const enrichedSchema = Object.assign(schema, {
5398
- create: (...args) => {
5399
- return coValueClass.create(...args);
5400
- },
5401
- createAs: (...args) => {
5402
- return coValueClass.createAs(...args);
5403
- },
5404
- getMe: (...args) => {
5405
- return coValueClass.getMe(...args);
5406
- },
5407
- load: (...args) => {
5408
- return coValueClass.load(...args);
5409
- },
5410
- subscribe: (...args) => {
5411
- return coValueClass.subscribe(...args);
5412
- },
5413
- fromRaw: (...args) => {
5414
- return coValueClass.fromRaw(...args);
5415
- },
5416
- unstable_merge: (...args) => {
5417
- return unstable_mergeBranchWithResolve(coValueClass, ...args);
5418
- },
5419
- withMigration: (migration) => {
5420
- coValueClass.prototype.migrate = async function(creationProps) {
5421
- await migration(this, creationProps);
5422
- };
5423
- return enrichedSchema;
5424
- },
5425
- getCoValueClass: () => {
5426
- return coValueClass;
5427
- },
5428
- optional: () => coOptionalDefiner(enrichedSchema)
5429
- });
5430
- return enrichedSchema;
5431
- }
5432
5695
 
5433
5696
  // src/tools/implementation/zodSchema/unionUtils.ts
5434
5697
  function schemaUnionDiscriminatorFor(schema) {
@@ -5679,7 +5942,7 @@ function hydrateCoreCoValueSchema(schema) {
5679
5942
  }
5680
5943
  }
5681
5944
  };
5682
- const coValueSchema = ClassToExtend === Account ? enrichAccountSchema(schema, coValueClass) : enrichCoMapSchema(schema, coValueClass);
5945
+ const coValueSchema = ClassToExtend === Account ? new AccountSchema(schema, coValueClass) : new CoMapSchema(schema, coValueClass);
5683
5946
  return coValueSchema;
5684
5947
  } else if (schema.builtin === "CoList") {
5685
5948
  const element = schema.element;
@@ -6236,6 +6499,12 @@ globalThis.devtoolsFormatters = [
6236
6499
  function isCoValueClass(value) {
6237
6500
  return typeof value === "function" && value.fromRaw !== void 0;
6238
6501
  }
6502
+ function createUnloadedCoValue(id, loadingState) {
6503
+ return {
6504
+ $jazz: { id, loadingState },
6505
+ $isLoaded: false
6506
+ };
6507
+ }
6239
6508
  function loadCoValueWithoutMe(cls, id, options) {
6240
6509
  return loadCoValue(cls, id, {
6241
6510
  ...options,
@@ -6254,10 +6523,10 @@ function loadCoValue(cls, id, options) {
6254
6523
  syncResolution: true,
6255
6524
  skipRetry: options.skipRetry,
6256
6525
  onUnavailable: () => {
6257
- resolve(null);
6526
+ resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAVAILABLE));
6258
6527
  },
6259
6528
  onUnauthorized: () => {
6260
- resolve(null);
6529
+ resolve(createUnloadedCoValue(id, CoValueLoadingState.UNAUTHORIZED));
6261
6530
  },
6262
6531
  unstable_branch: options.unstable_branch
6263
6532
  },
@@ -6278,7 +6547,7 @@ async function ensureCoValueLoaded(existing, options) {
6278
6547
  unstable_branch: options?.unstable_branch
6279
6548
  }
6280
6549
  );
6281
- if (!response) {
6550
+ if (!response.$isLoaded) {
6282
6551
  throw new Error("Failed to deeply load CoValue " + existing.$jazz.id);
6283
6552
  }
6284
6553
  return response;
@@ -6337,15 +6606,15 @@ function subscribeToCoValue(cls, id, options, listener) {
6337
6606
  );
6338
6607
  const handleUpdate = (value) => {
6339
6608
  if (unsubscribed) return;
6340
- if (value.type === "unavailable") {
6609
+ if (value.type === CoValueLoadingState.UNAVAILABLE) {
6341
6610
  options.onUnavailable?.();
6342
6611
  if (!options.skipRetry) {
6343
6612
  console.error(value.toString());
6344
6613
  }
6345
- } else if (value.type === "unauthorized") {
6614
+ } else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
6346
6615
  options.onUnauthorized?.();
6347
6616
  console.error(value.toString());
6348
- } else if (value.type === "loaded") {
6617
+ } else if (value.type === CoValueLoadingState.LOADED) {
6349
6618
  listener(value.value, unsubscribe);
6350
6619
  }
6351
6620
  };
@@ -6431,10 +6700,8 @@ async function unstable_loadUnique(schema, options) {
6431
6700
  return internalLoadUnique(cls, {
6432
6701
  header,
6433
6702
  onCreateWhenMissing: options.onCreateWhenMissing,
6434
- // @ts-expect-error loaded is not compatible with Resolved at type level, but they are the same thing
6435
6703
  onUpdateWhenFound: options.onUpdateWhenFound,
6436
6704
  owner: options.owner,
6437
- // @ts-expect-error loaded is not compatible with Resolved at type level, but they are the same thing
6438
6705
  resolve: options.resolve
6439
6706
  });
6440
6707
  }
@@ -6442,7 +6709,7 @@ async function internalLoadUnique(cls, options) {
6442
6709
  const loadAs = options.owner.$jazz.loadedAs;
6443
6710
  const node = loadAs[TypeSym] === "Anonymous" ? loadAs.node : loadAs.$jazz.localNode;
6444
6711
  const id = cojsonInternals6.idforHeader(options.header, node.crypto);
6445
- await loadCoValueWithoutMe(cls, id, {
6712
+ const maybeLoadedCoValue = await loadCoValueWithoutMe(cls, id, {
6446
6713
  skipRetry: true,
6447
6714
  loadAs
6448
6715
  });
@@ -6455,14 +6722,14 @@ async function internalLoadUnique(cls, options) {
6455
6722
  });
6456
6723
  }
6457
6724
  if (!isAvailable) {
6458
- return null;
6725
+ return maybeLoadedCoValue;
6459
6726
  }
6460
6727
  if (options.onUpdateWhenFound) {
6461
6728
  const loaded = await loadCoValueWithoutMe(cls, id, {
6462
6729
  loadAs,
6463
6730
  resolve: options.resolve
6464
6731
  });
6465
- if (loaded) {
6732
+ if (loaded.$isLoaded) {
6466
6733
  options.onUpdateWhenFound(loaded);
6467
6734
  } else {
6468
6735
  return loaded;
@@ -6491,13 +6758,13 @@ async function exportCoValue(cls, id, options) {
6491
6758
  );
6492
6759
  const value = await new Promise((resolve2) => {
6493
6760
  rootNode.setListener((value2) => {
6494
- if (value2.type === "unavailable") {
6761
+ if (value2.type === CoValueLoadingState.UNAVAILABLE) {
6495
6762
  resolve2(null);
6496
6763
  console.error(value2.toString());
6497
- } else if (value2.type === "unauthorized") {
6764
+ } else if (value2.type === CoValueLoadingState.UNAUTHORIZED) {
6498
6765
  resolve2(null);
6499
6766
  console.error(value2.toString());
6500
- } else if (value2.type === "loaded") {
6767
+ } else if (value2.type === CoValueLoadingState.LOADED) {
6501
6768
  resolve2(value2.value);
6502
6769
  }
6503
6770
  rootNode.destroy();
@@ -6516,8 +6783,9 @@ function loadContentPiecesFromSubscription(subscription, valuesExported, content
6516
6783
  return;
6517
6784
  }
6518
6785
  valuesExported.add(subscription.id);
6519
- const core2 = subscription.getCurrentValue()?.$jazz.raw.core;
6520
- if (core2) {
6786
+ const currentValue = subscription.getCurrentValue();
6787
+ if (typeof currentValue !== "string") {
6788
+ const core2 = currentValue.$jazz.raw.core;
6521
6789
  loadContentPiecesFromCoValue(core2, valuesExported, contentPieces);
6522
6790
  }
6523
6791
  for (const child of subscription.childNodes.values()) {
@@ -6552,7 +6820,7 @@ function unstable_mergeBranch(subscriptionScope) {
6552
6820
  return;
6553
6821
  }
6554
6822
  function handleMerge(subscriptionNode) {
6555
- if (subscriptionNode.value.type === "loaded") {
6823
+ if (subscriptionNode.value.type === CoValueLoadingState.LOADED) {
6556
6824
  subscriptionNode.value.value.$jazz.raw.core.mergeBranch();
6557
6825
  }
6558
6826
  for (const childNode of subscriptionNode.childNodes.values()) {
@@ -6561,7 +6829,7 @@ function unstable_mergeBranch(subscriptionScope) {
6561
6829
  }
6562
6830
  handleMerge(subscriptionScope);
6563
6831
  }
6564
- async function unstable_mergeBranchWithResolve2(cls, id, options) {
6832
+ async function unstable_mergeBranchWithResolve(cls, id, options) {
6565
6833
  const loadAs = options.loadAs ?? activeAccountContext3.get();
6566
6834
  const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
6567
6835
  const resolve = options.resolve ?? true;
@@ -6579,11 +6847,11 @@ async function unstable_mergeBranchWithResolve2(cls, id, options) {
6579
6847
  );
6580
6848
  await new Promise((resolve2, reject) => {
6581
6849
  rootNode.setListener((value) => {
6582
- if (value.type === "unavailable") {
6850
+ if (value.type === CoValueLoadingState.UNAVAILABLE) {
6583
6851
  reject(new Error("Unable to load the branch. " + value.toString()));
6584
- } else if (value.type === "unauthorized") {
6852
+ } else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
6585
6853
  reject(new Error("Unable to load the branch. " + value.toString()));
6586
- } else if (value.type === "loaded") {
6854
+ } else if (value.type === CoValueLoadingState.LOADED) {
6587
6855
  resolve2();
6588
6856
  }
6589
6857
  rootNode.destroy();
@@ -6594,6 +6862,7 @@ async function unstable_mergeBranchWithResolve2(cls, id, options) {
6594
6862
 
6595
6863
  export {
6596
6864
  zodReExport_exports,
6865
+ createUnloadedCoValue,
6597
6866
  loadCoValue,
6598
6867
  subscribeToCoValue,
6599
6868
  unstable_loadUnique,
@@ -6609,6 +6878,8 @@ export {
6609
6878
  Group2 as Group,
6610
6879
  Profile,
6611
6880
  isCoValueId,
6881
+ assertLoaded,
6882
+ getLoadedOrUndefined,
6612
6883
  Inbox,
6613
6884
  InboxSender,
6614
6885
  CoPlainText,
@@ -6619,6 +6890,7 @@ export {
6619
6890
  Ref,
6620
6891
  Encoders,
6621
6892
  coField,
6893
+ CoValueLoadingState,
6622
6894
  SubscriptionScope,
6623
6895
  randomSessionProvider,
6624
6896
  createJazzContextFromExistingCredentials,
@@ -6635,4 +6907,4 @@ export {
6635
6907
  JazzContextManager
6636
6908
  };
6637
6909
  /* istanbul ignore file -- @preserve */
6638
- //# sourceMappingURL=chunk-OSQ7S47Q.js.map
6910
+ //# sourceMappingURL=chunk-P3YLNFN4.js.map