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
@@ -0,0 +1,723 @@
1
+ import { beforeAll, describe, expect, expectTypeOf, test } from "vitest";
2
+ import {
3
+ Account,
4
+ co,
5
+ CoPlainText,
6
+ CoValueLoadingState,
7
+ Group,
8
+ z,
9
+ } from "../exports";
10
+ import { createJazzTestAccount, setupJazzTestSync } from "../testing";
11
+ import { assertLoaded, setupTwoNodes, waitFor } from "./utils";
12
+
13
+ describe("Schema.resolved()", () => {
14
+ beforeAll(async () => {
15
+ await setupJazzTestSync();
16
+ await createJazzTestAccount({
17
+ isCurrentActiveAccount: true,
18
+ creationProps: { name: "Hermes Puggington" },
19
+ });
20
+ });
21
+
22
+ test("all CoValue schemas have a `true` resolve query by default", () => {
23
+ const AllSchemas = [
24
+ co.plainText(),
25
+ co.richText(),
26
+ co.fileStream(),
27
+ co.vector(1),
28
+ co.group(),
29
+ co.list(co.plainText()),
30
+ co.feed(co.plainText()),
31
+ co.map({ text: co.plainText() }),
32
+ co.record(z.string(), co.plainText()),
33
+ co.optional(co.plainText()),
34
+ co.discriminatedUnion("type", [
35
+ co.map({ type: z.literal("a") }),
36
+ co.map({ type: z.literal("b") }),
37
+ ]),
38
+ ];
39
+
40
+ for (const Schema of AllSchemas) {
41
+ expect(Schema.resolveQuery).toBe(true);
42
+ }
43
+ });
44
+
45
+ describe("allows adding a default resolve query", () => {
46
+ test("to a CoMap schema", () => {
47
+ const TestMap = co.map({
48
+ name: co.plainText(),
49
+ });
50
+
51
+ const TestMapWithName = TestMap.resolved({
52
+ name: true,
53
+ });
54
+
55
+ expect(TestMapWithName.resolveQuery).toEqual({
56
+ name: true,
57
+ });
58
+ });
59
+
60
+ test("to a CoRecord schema", () => {
61
+ const TestRecord = co.record(z.string(), co.plainText());
62
+
63
+ const TestRecordWithName = TestRecord.resolved({
64
+ name: true,
65
+ });
66
+
67
+ expect(TestRecordWithName.resolveQuery).toEqual({
68
+ name: true,
69
+ });
70
+ });
71
+
72
+ test("to a CoList schema", () => {
73
+ const TestList = co.list(co.plainText());
74
+
75
+ const TestListWithItems = TestList.resolved({
76
+ $each: true,
77
+ });
78
+
79
+ expect(TestListWithItems.resolveQuery).toEqual({
80
+ $each: true,
81
+ });
82
+ });
83
+
84
+ test("to a CoFeed schema", () => {
85
+ const TestFeed = co.feed(co.plainText());
86
+
87
+ const TestFeedWithItems = TestFeed.resolved({
88
+ $each: true,
89
+ });
90
+
91
+ expect(TestFeedWithItems.resolveQuery).toEqual({
92
+ $each: true,
93
+ });
94
+ });
95
+
96
+ test("to an Account schema", () => {
97
+ const TestAccount = co.account();
98
+
99
+ const TestAccountWithName = TestAccount.resolved({
100
+ profile: true,
101
+ });
102
+
103
+ expect(TestAccountWithName.resolveQuery).toEqual({
104
+ profile: true,
105
+ });
106
+ });
107
+ });
108
+
109
+ describe("the schema's resolve query is used when loading CoValues", () => {
110
+ let clientAccount: Account;
111
+ let serverAccount: Account;
112
+ let publicGroup: Group;
113
+
114
+ beforeAll(async () => {
115
+ ({ clientAccount, serverAccount } = await setupTwoNodes());
116
+ publicGroup = Group.create(serverAccount).makePublic("writer");
117
+ });
118
+
119
+ describe("on load()", () => {
120
+ test("for CoMap", async () => {
121
+ const TestMap = co.map({
122
+ name: co.plainText(),
123
+ });
124
+
125
+ const TestMapWithName = TestMap.resolved({
126
+ name: true,
127
+ });
128
+
129
+ const map = TestMapWithName.create(
130
+ {
131
+ name: "Test",
132
+ },
133
+ publicGroup,
134
+ );
135
+
136
+ const loadedMap = await TestMapWithName.load(map.$jazz.id, {
137
+ loadAs: clientAccount,
138
+ });
139
+
140
+ assertLoaded(loadedMap);
141
+ expect(loadedMap.name.$isLoaded).toBe(true);
142
+ expect(loadedMap.name.toUpperCase()).toBe("TEST");
143
+ });
144
+
145
+ test("for CoRecord", async () => {
146
+ const TestRecord = co.record(z.string(), co.plainText());
147
+
148
+ const TestRecordWithName = TestRecord.resolved({
149
+ name: true,
150
+ });
151
+
152
+ const record = TestRecordWithName.create(
153
+ {
154
+ name: "Test",
155
+ },
156
+ publicGroup,
157
+ );
158
+
159
+ const loadedRecord = await TestRecordWithName.load(record.$jazz.id, {
160
+ loadAs: clientAccount,
161
+ });
162
+
163
+ assertLoaded(loadedRecord);
164
+ expect(loadedRecord.name?.$isLoaded).toBe(true);
165
+ expect(loadedRecord.name?.toUpperCase()).toBe("TEST");
166
+ });
167
+
168
+ test("for CoList", async () => {
169
+ const TestList = co.list(co.plainText());
170
+
171
+ const TestListWithItems = TestList.resolved({
172
+ $each: true,
173
+ });
174
+
175
+ const list = TestListWithItems.create(["Test", "Test2"], publicGroup);
176
+
177
+ const loadedList = await TestListWithItems.load(list.$jazz.id, {
178
+ loadAs: clientAccount,
179
+ });
180
+
181
+ assertLoaded(loadedList);
182
+ expect(loadedList.length).toBe(2);
183
+ expect(loadedList[0]?.$isLoaded).toBe(true);
184
+ expect(loadedList[0]?.toUpperCase()).toBe("TEST");
185
+ });
186
+
187
+ // TODO fix - `$each` does not load nested CoValues when providing an explicit resolve query either:
188
+ // TestFeed.load(feed.$jazz.id, {
189
+ // loadAs: clientAccount,
190
+ // resolve: {
191
+ // $each: true,
192
+ // },
193
+ // })
194
+ test.skip("for CoFeed", async () => {
195
+ const TestFeed = co.feed(co.plainText());
196
+
197
+ const TestFeedWithItems = TestFeed.resolved({
198
+ $each: true,
199
+ });
200
+
201
+ const feed = TestFeedWithItems.create(["Test"], publicGroup);
202
+
203
+ const loadedFeed = await TestFeedWithItems.load(feed.$jazz.id, {
204
+ loadAs: clientAccount,
205
+ });
206
+
207
+ assertLoaded(loadedFeed);
208
+ expect(loadedFeed.inCurrentSession?.value.$jazz.loadingState).toBe(
209
+ CoValueLoadingState.LOADED,
210
+ );
211
+ expect(loadedFeed.inCurrentSession?.value.toUpperCase()).toEqual(
212
+ "HELLO",
213
+ );
214
+ });
215
+
216
+ test("for Account", async () => {
217
+ const AccountWithProfile = co.account().resolved({
218
+ profile: true,
219
+ });
220
+
221
+ const account = await AccountWithProfile.createAs(serverAccount, {
222
+ creationProps: { name: "Hermes Puggington" },
223
+ });
224
+ account.$jazz.set(
225
+ "profile",
226
+ co.profile().create({ name: "Hermes Puggington" }, publicGroup),
227
+ );
228
+
229
+ const loadedAccount = await AccountWithProfile.load(account.$jazz.id, {
230
+ loadAs: clientAccount,
231
+ });
232
+
233
+ assertLoaded(loadedAccount);
234
+ expect(loadedAccount.profile.$isLoaded).toBe(true);
235
+ expect(loadedAccount.profile.name).toBe("Hermes Puggington");
236
+ });
237
+ });
238
+
239
+ describe("on subscribe()", () => {
240
+ test("for CoMap", async () => {
241
+ const TestMap = co.map({ name: co.plainText() });
242
+
243
+ const TestMapWithName = TestMap.resolved({ name: true });
244
+
245
+ const map = TestMapWithName.create({ name: "Test" }, publicGroup);
246
+
247
+ const updates: co.loaded<typeof TestMapWithName>[] = [];
248
+ TestMapWithName.subscribe(
249
+ map.$jazz.id,
250
+ {
251
+ loadAs: clientAccount,
252
+ },
253
+ (map) => {
254
+ expectTypeOf<typeof map.name>().toEqualTypeOf<CoPlainText>();
255
+ updates.push(map);
256
+ },
257
+ );
258
+
259
+ await waitFor(() => expect(updates.length).toBe(1));
260
+ expect(updates[0]?.name.toUpperCase()).toEqual("TEST");
261
+ });
262
+
263
+ test("for CoRecord", async () => {
264
+ const TestRecord = co.record(z.string(), co.plainText());
265
+
266
+ const TestRecordWithName = TestRecord.resolved({ name: true });
267
+
268
+ const record = TestRecordWithName.create({ name: "Test" }, publicGroup);
269
+
270
+ const updates: co.loaded<typeof TestRecordWithName>[] = [];
271
+ TestRecordWithName.subscribe(
272
+ record.$jazz.id,
273
+ {
274
+ loadAs: clientAccount,
275
+ },
276
+ (record) => {
277
+ expectTypeOf<typeof record.name>().toEqualTypeOf<CoPlainText>();
278
+ updates.push(record);
279
+ },
280
+ );
281
+
282
+ await waitFor(() => expect(updates.length).toBe(1));
283
+ expect(updates[0]?.name.toUpperCase()).toEqual("TEST");
284
+ });
285
+
286
+ test("for CoList", async () => {
287
+ const TestList = co.list(co.plainText());
288
+
289
+ const TestListWithItems = TestList.resolved({ $each: true });
290
+
291
+ const list = TestListWithItems.create(["Test"], publicGroup);
292
+
293
+ const updates: co.loaded<typeof TestListWithItems>[] = [];
294
+ TestListWithItems.subscribe(
295
+ list.$jazz.id,
296
+ {
297
+ loadAs: clientAccount,
298
+ },
299
+ (list) => {
300
+ expectTypeOf<(typeof list)[0]>().toEqualTypeOf<CoPlainText>();
301
+ updates.push(list);
302
+ },
303
+ );
304
+
305
+ await waitFor(() => expect(updates.length).toBe(1));
306
+ expect(updates[0]?.[0]?.toUpperCase()).toEqual("TEST");
307
+ });
308
+
309
+ // TODO fix - `$each` does not load nested CoValues when providing an explicit resolve query either
310
+ test.skip("for CoFeed", async () => {
311
+ const TestFeed = co.feed(co.plainText());
312
+
313
+ const TestFeedWithItems = TestFeed.resolved({ $each: true });
314
+
315
+ const feed = TestFeedWithItems.create(["Test"], publicGroup);
316
+
317
+ const updates: co.loaded<typeof TestFeedWithItems>[] = [];
318
+ TestFeedWithItems.subscribe(
319
+ feed.$jazz.id,
320
+ {
321
+ loadAs: clientAccount,
322
+ },
323
+ (feed) => {
324
+ updates.push(feed);
325
+ },
326
+ );
327
+
328
+ await waitFor(() => expect(updates.length).toBe(1));
329
+ expect(updates[0]?.inCurrentSession?.value.toUpperCase()).toEqual(
330
+ "TEST",
331
+ );
332
+ });
333
+
334
+ test("for Account", async () => {
335
+ const AccountWithProfile = co.account().resolved({ profile: true });
336
+
337
+ const account = await AccountWithProfile.createAs(serverAccount, {
338
+ creationProps: { name: "Hermes Puggington" },
339
+ });
340
+ account.$jazz.set(
341
+ "profile",
342
+ co.profile().create({ name: "Hermes Puggington" }, publicGroup),
343
+ );
344
+
345
+ const updates: co.loaded<typeof AccountWithProfile>[] = [];
346
+ AccountWithProfile.subscribe(
347
+ account.$jazz.id,
348
+ {
349
+ loadAs: clientAccount,
350
+ },
351
+ (account) => {
352
+ updates.push(account);
353
+ },
354
+ );
355
+
356
+ await waitFor(() => expect(updates.length).toBe(1));
357
+ expect(updates[0]?.profile.name).toBe("Hermes Puggington");
358
+ });
359
+ });
360
+
361
+ describe("on merge()", () => {
362
+ test("for CoMap", async () => {
363
+ const TestMap = co.map({ name: co.plainText() });
364
+
365
+ const TestMapWithName = TestMap.resolved({ name: true });
366
+
367
+ const map = TestMap.create({ name: "Test" }, publicGroup);
368
+
369
+ const branchMap = await TestMapWithName.load(map.$jazz.id, {
370
+ unstable_branch: { name: "test-merge-coMap", owner: publicGroup },
371
+ loadAs: clientAccount,
372
+ });
373
+
374
+ assertLoaded(branchMap);
375
+ branchMap.name.insertAfter(branchMap.name.length, "!!");
376
+
377
+ await TestMapWithName.unstable_merge(map.$jazz.id, {
378
+ branch: { name: "test-merge-coMap", owner: publicGroup },
379
+ loadAs: clientAccount,
380
+ });
381
+
382
+ const mergedMap = await TestMapWithName.load(map.$jazz.id, {
383
+ loadAs: clientAccount,
384
+ });
385
+
386
+ assertLoaded(mergedMap);
387
+ expect(mergedMap.name.toUpperCase()).toEqual("TEST!!");
388
+ });
389
+
390
+ test("for CoRecord", async () => {
391
+ const TestRecord = co.record(z.string(), co.plainText());
392
+
393
+ const TestRecordWithName = TestRecord.resolved({ name: true });
394
+
395
+ const record = TestRecordWithName.create({ name: "Test" }, publicGroup);
396
+
397
+ const branchRecord = await TestRecordWithName.load(record.$jazz.id, {
398
+ unstable_branch: { name: "test-merge-coRecord", owner: publicGroup },
399
+ loadAs: clientAccount,
400
+ });
401
+
402
+ assertLoaded(branchRecord);
403
+ branchRecord.name.insertAfter(branchRecord.name.length, "!!");
404
+
405
+ await TestRecordWithName.unstable_merge(record.$jazz.id, {
406
+ branch: { name: "test-merge-coRecord", owner: publicGroup },
407
+ loadAs: clientAccount,
408
+ });
409
+
410
+ const mergedRecord = await TestRecordWithName.load(record.$jazz.id, {
411
+ loadAs: clientAccount,
412
+ });
413
+
414
+ assertLoaded(mergedRecord);
415
+ expect(mergedRecord.name.toUpperCase()).toEqual("TEST!!");
416
+ });
417
+
418
+ test("for CoList", async () => {
419
+ const TestList = co.list(co.plainText());
420
+
421
+ const TestListWithItems = TestList.resolved({ $each: true });
422
+
423
+ const list = TestListWithItems.create(["Test"], publicGroup);
424
+
425
+ const branchList = await TestListWithItems.load(list.$jazz.id, {
426
+ unstable_branch: { name: "test-merge-coList", owner: publicGroup },
427
+ loadAs: clientAccount,
428
+ });
429
+
430
+ assertLoaded(branchList);
431
+ branchList[0]?.insertAfter(branchList[0].length, "!!");
432
+
433
+ await TestListWithItems.unstable_merge(list.$jazz.id, {
434
+ branch: { name: "test-merge-coList", owner: publicGroup },
435
+ loadAs: clientAccount,
436
+ });
437
+
438
+ const mergedList = await TestListWithItems.load(list.$jazz.id, {
439
+ loadAs: clientAccount,
440
+ });
441
+
442
+ assertLoaded(mergedList);
443
+ expect(mergedList[0]?.toUpperCase()).toEqual("TEST!!");
444
+ });
445
+
446
+ // TODO fix - `$each` does not load nested CoValues when providing an explicit resolve query either
447
+ test.skip("for CoFeed", async () => {
448
+ const TestFeed = co.feed(co.plainText());
449
+
450
+ const TestFeedWithItems = TestFeed.resolved({ $each: true });
451
+
452
+ const feed = TestFeedWithItems.create(["Test"], publicGroup);
453
+
454
+ const branchFeed = await TestFeedWithItems.load(feed.$jazz.id, {
455
+ unstable_branch: { name: "test-merge-coFeed", owner: publicGroup },
456
+ loadAs: clientAccount,
457
+ });
458
+
459
+ assertLoaded(branchFeed);
460
+ branchFeed.inCurrentSession?.value.insertAfter(
461
+ branchFeed.inCurrentSession.value.length,
462
+ "!!",
463
+ );
464
+
465
+ await TestFeedWithItems.unstable_merge(feed.$jazz.id, {
466
+ branch: { name: "test-merge-coFeed", owner: publicGroup },
467
+ loadAs: clientAccount,
468
+ });
469
+
470
+ const mergedFeed = await TestFeedWithItems.load(feed.$jazz.id, {
471
+ loadAs: clientAccount,
472
+ });
473
+
474
+ assertLoaded(mergedFeed);
475
+ expect(mergedFeed.inCurrentSession?.value.toUpperCase()).toEqual(
476
+ "TEST!!",
477
+ );
478
+ });
479
+
480
+ test("for Account", async () => {
481
+ const TestAccount = co
482
+ .account({
483
+ profile: co.profile(),
484
+ root: co.map({ text: co.plainText() }),
485
+ })
486
+ .resolved({ profile: true, root: { text: true } });
487
+ const AccountList = co
488
+ .list(TestAccount)
489
+ .resolved({ $each: TestAccount.resolveQuery });
490
+
491
+ const account = await TestAccount.createAs(serverAccount, {
492
+ creationProps: { name: "Hermes Puggington" },
493
+ });
494
+ account.$jazz.set(
495
+ "profile",
496
+ TestAccount.shape.profile.create(
497
+ { name: "Hermes Puggington" },
498
+ publicGroup,
499
+ ),
500
+ );
501
+ account.$jazz.set(
502
+ "root",
503
+ TestAccount.shape.root.create({ text: "Test" }, publicGroup),
504
+ );
505
+ const accountList = AccountList.create([account], publicGroup);
506
+
507
+ const branchAccountList = await AccountList.load(accountList.$jazz.id, {
508
+ unstable_branch: {
509
+ name: "test-merge-account",
510
+ owner: publicGroup,
511
+ },
512
+ loadAs: clientAccount,
513
+ });
514
+
515
+ assertLoaded(branchAccountList);
516
+ branchAccountList[0]?.root.text.insertAfter(
517
+ branchAccountList[0].root.text.length,
518
+ "!!",
519
+ );
520
+
521
+ await TestAccount.unstable_merge(account.$jazz.id, {
522
+ branch: { name: "test-merge-account", owner: publicGroup },
523
+ loadAs: clientAccount,
524
+ });
525
+
526
+ const mergedAccount = await TestAccount.load(account.$jazz.id, {
527
+ loadAs: clientAccount,
528
+ });
529
+
530
+ assertLoaded(mergedAccount);
531
+ expect(mergedAccount.root.text.toUpperCase()).toEqual("TEST!!");
532
+ });
533
+ });
534
+
535
+ describe("on upsertUnique()", () => {
536
+ test("for CoMap", async () => {
537
+ const TestMap = co.map({ name: co.plainText() });
538
+
539
+ const TestMapWithName = TestMap.resolved({ name: true });
540
+
541
+ const map = await TestMapWithName.upsertUnique({
542
+ value: { name: "Test" },
543
+ unique: "test-upsertUnique-coList",
544
+ owner: publicGroup,
545
+ });
546
+
547
+ assertLoaded(map);
548
+ expect(map.name.toUpperCase()).toEqual("TEST");
549
+ });
550
+
551
+ test("for CoRecord", async () => {
552
+ const TestRecord = co.record(z.string(), co.plainText());
553
+
554
+ const TestRecordWithName = TestRecord.resolved({ name: true });
555
+
556
+ const record = await TestRecordWithName.upsertUnique({
557
+ value: { name: "Test" },
558
+ unique: "test-upsertUnique-coRecord",
559
+ owner: publicGroup,
560
+ });
561
+
562
+ assertLoaded(record);
563
+ expect(record.name?.toUpperCase()).toEqual("TEST");
564
+ });
565
+
566
+ test("for CoList", async () => {
567
+ const TestList = co.list(co.plainText());
568
+
569
+ const TestListWithItems = TestList.resolved({ $each: true });
570
+
571
+ const list = await TestListWithItems.upsertUnique({
572
+ value: ["Test"],
573
+ unique: "test-upsertUnique-coList",
574
+ owner: publicGroup,
575
+ });
576
+
577
+ assertLoaded(list);
578
+ expect(list[0]?.toUpperCase()).toEqual("TEST");
579
+ });
580
+ });
581
+
582
+ describe("on loadUnique()", () => {
583
+ let group: Group;
584
+ beforeAll(async () => {
585
+ group = Group.create();
586
+ });
587
+
588
+ test("for CoMap", async () => {
589
+ const TestMap = co.map({ name: co.plainText() });
590
+ const TestMapWithName = TestMap.resolved({ name: true });
591
+
592
+ const map = TestMapWithName.create(
593
+ { name: "Test" },
594
+ {
595
+ unique: "test-loadUnique-coMap",
596
+ owner: group,
597
+ },
598
+ );
599
+
600
+ const loadedMap = await TestMapWithName.loadUnique(
601
+ "test-loadUnique-coMap",
602
+ group.$jazz.id,
603
+ );
604
+
605
+ assertLoaded(loadedMap);
606
+ expect(loadedMap.name.toUpperCase()).toEqual("TEST");
607
+ });
608
+
609
+ test("for CoRecord", async () => {
610
+ const TestRecord = co.record(z.string(), co.plainText());
611
+ const TestRecordWithName = TestRecord.resolved({ name: true });
612
+
613
+ const record = TestRecordWithName.create(
614
+ { name: "Test" },
615
+ {
616
+ unique: "test-loadUnique-coRecord",
617
+ owner: group,
618
+ },
619
+ );
620
+
621
+ const loadedRecord = await TestRecordWithName.loadUnique(
622
+ "test-loadUnique-coRecord",
623
+ group.$jazz.id,
624
+ );
625
+
626
+ assertLoaded(loadedRecord);
627
+ expect(loadedRecord.name?.toUpperCase()).toEqual("TEST");
628
+ });
629
+
630
+ test("for CoList", async () => {
631
+ const TestList = co.list(co.plainText());
632
+ const TestListWithItems = TestList.resolved({ $each: true });
633
+
634
+ const list = TestListWithItems.create(["Test"], {
635
+ unique: "test-loadUnique-coList",
636
+ owner: group,
637
+ });
638
+
639
+ const loadedList = await TestListWithItems.loadUnique(
640
+ "test-loadUnique-coList",
641
+ group.$jazz.id,
642
+ );
643
+
644
+ assertLoaded(loadedList);
645
+ expect(loadedList[0]?.toUpperCase()).toEqual("TEST");
646
+ });
647
+ });
648
+
649
+ test("the default resolve query is overridden with provided resolve queries", async () => {
650
+ const TestMap = co.map({ name: co.plainText() });
651
+
652
+ const TestMapWithName = TestMap.resolved({ name: true });
653
+
654
+ const map = TestMapWithName.create({ name: "Test" }, publicGroup);
655
+
656
+ const loadedMap = await TestMapWithName.load(map.$jazz.id, {
657
+ loadAs: clientAccount,
658
+ resolve: true,
659
+ });
660
+
661
+ assertLoaded(loadedMap);
662
+ expect(loadedMap.name.$jazz.loadingState).toEqual(
663
+ CoValueLoadingState.LOADING,
664
+ );
665
+ });
666
+
667
+ test("nested schemas' resolve queries are ignored when loading the parent schema", async () => {
668
+ const TestMap = co.map({
669
+ name: co.plainText(),
670
+ });
671
+ const TestMapWithName = TestMap.resolved({ name: true });
672
+ const ParentMap = co.map({
673
+ child: TestMapWithName,
674
+ });
675
+ const ParentMapWithChild = ParentMap.resolved({ child: true });
676
+
677
+ const parentMap = ParentMapWithChild.create(
678
+ { child: { name: "Test" } },
679
+ publicGroup,
680
+ );
681
+
682
+ const loadedParentMap = await ParentMapWithChild.load(
683
+ parentMap.$jazz.id,
684
+ {
685
+ loadAs: clientAccount,
686
+ },
687
+ );
688
+
689
+ assertLoaded(loadedParentMap);
690
+ expect(loadedParentMap.child.$isLoaded).toEqual(true);
691
+ expect(loadedParentMap.child.name.$isLoaded).toEqual(false);
692
+ });
693
+
694
+ test("works with recursive schemas", async () => {
695
+ const Person = co.map({
696
+ get friends(): co.List<typeof Person, { $each: true }> {
697
+ return Friends;
698
+ },
699
+ });
700
+ const Friends = co.list(Person).resolved({ $each: true });
701
+
702
+ const PersonWithFriends = Person.resolved({
703
+ friends: { $each: true },
704
+ });
705
+
706
+ const person = Person.create(
707
+ {
708
+ friends: [{ friends: [] }],
709
+ },
710
+ publicGroup,
711
+ );
712
+
713
+ const loadedPerson = await PersonWithFriends.load(person.$jazz.id, {
714
+ loadAs: clientAccount,
715
+ });
716
+
717
+ assertLoaded(loadedPerson);
718
+ expect(loadedPerson.friends.$isLoaded).toBe(true);
719
+ expect(loadedPerson.friends.length).toBe(1);
720
+ expect(loadedPerson.friends[0]?.friends.$isLoaded).toBe(false);
721
+ });
722
+ });
723
+ });