jazz-tools 0.17.14 → 0.18.1

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 (250) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.js +1 -1
  2. package/.svelte-kit/__package__/media/image.svelte +3 -9
  3. package/.svelte-kit/__package__/media/image.svelte.d.ts +1 -6
  4. package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
  5. package/.svelte-kit/__package__/media/image.types.d.ts +7 -0
  6. package/.svelte-kit/__package__/media/image.types.d.ts.map +1 -0
  7. package/.svelte-kit/__package__/media/image.types.js +1 -0
  8. package/.svelte-kit/__package__/tests/media/image.svelte.test.js +31 -31
  9. package/.turbo/turbo-build.log +60 -46
  10. package/CHANGELOG.md +41 -0
  11. package/dist/better-auth/auth/client.d.ts +29 -0
  12. package/dist/better-auth/auth/client.d.ts.map +1 -0
  13. package/dist/better-auth/auth/client.js +127 -0
  14. package/dist/better-auth/auth/client.js.map +1 -0
  15. package/dist/better-auth/auth/react.d.ts +2170 -0
  16. package/dist/better-auth/auth/react.d.ts.map +1 -0
  17. package/dist/better-auth/auth/react.js +40 -0
  18. package/dist/better-auth/auth/react.js.map +1 -0
  19. package/dist/better-auth/auth/server.d.ts +14 -0
  20. package/dist/better-auth/auth/server.d.ts.map +1 -0
  21. package/dist/better-auth/auth/server.js +198 -0
  22. package/dist/better-auth/auth/server.js.map +1 -0
  23. package/dist/better-auth/auth/tests/client.test.d.ts +2 -0
  24. package/dist/better-auth/auth/tests/client.test.d.ts.map +1 -0
  25. package/dist/better-auth/auth/tests/server.test.d.ts +2 -0
  26. package/dist/better-auth/auth/tests/server.test.d.ts.map +1 -0
  27. package/dist/browser/index.js +2 -2
  28. package/dist/browser/index.js.map +1 -1
  29. package/dist/{chunk-LZOF6WP5.js → chunk-IERUTUXB.js} +1336 -1017
  30. package/dist/chunk-IERUTUXB.js.map +1 -0
  31. package/dist/index.js +18 -18
  32. package/dist/index.js.map +1 -1
  33. package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
  34. package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
  35. package/dist/inspector/index.js +1 -1
  36. package/dist/inspector/index.js.map +1 -1
  37. package/dist/inspector/register-custom-element.js +1 -1
  38. package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
  39. package/dist/media/chunk-KR2V6X2N.js.map +1 -0
  40. package/dist/media/create-image.d.ts +6 -6
  41. package/dist/media/index.browser.d.ts +6 -6
  42. package/dist/media/index.browser.js +1 -1
  43. package/dist/media/index.d.ts +1 -1
  44. package/dist/media/index.js +1 -1
  45. package/dist/media/index.native.d.ts +6 -6
  46. package/dist/media/index.native.js +1 -1
  47. package/dist/media/utils.d.ts.map +1 -1
  48. package/dist/prosemirror/index.js +2 -2
  49. package/dist/prosemirror/index.js.map +1 -1
  50. package/dist/react/index.js +7 -5
  51. package/dist/react/index.js.map +1 -1
  52. package/dist/react-core/hooks.d.ts.map +1 -1
  53. package/dist/react-core/index.js +4675 -23
  54. package/dist/react-core/index.js.map +1 -1
  55. package/dist/react-native-core/index.js +1 -1
  56. package/dist/react-native-core/index.js.map +1 -1
  57. package/dist/svelte/jazz.class.svelte.js +1 -1
  58. package/dist/svelte/media/image.svelte +3 -9
  59. package/dist/svelte/media/image.svelte.d.ts +1 -6
  60. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  61. package/dist/svelte/media/image.types.d.ts +7 -0
  62. package/dist/svelte/media/image.types.d.ts.map +1 -0
  63. package/dist/svelte/media/image.types.js +1 -0
  64. package/dist/svelte/tests/media/image.svelte.test.js +31 -31
  65. package/dist/testing.js +18 -14
  66. package/dist/testing.js.map +1 -1
  67. package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
  68. package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
  69. package/dist/tools/coValues/CoValueBase.d.ts +18 -15
  70. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  71. package/dist/tools/coValues/account.d.ts +101 -46
  72. package/dist/tools/coValues/account.d.ts.map +1 -1
  73. package/dist/tools/coValues/coFeed.d.ts +78 -62
  74. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  75. package/dist/tools/coValues/coList.d.ts +212 -99
  76. package/dist/tools/coValues/coList.d.ts.map +1 -1
  77. package/dist/tools/coValues/coMap.d.ts +210 -192
  78. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  79. package/dist/tools/coValues/coPlainText.d.ts +30 -22
  80. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  81. package/dist/tools/coValues/deepLoading.d.ts +13 -13
  82. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  83. package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
  84. package/dist/tools/coValues/group.d.ts +32 -32
  85. package/dist/tools/coValues/group.d.ts.map +1 -1
  86. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  87. package/dist/tools/coValues/interfaces.d.ts +18 -17
  88. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  89. package/dist/tools/coValues/profile.d.ts +6 -5
  90. package/dist/tools/coValues/profile.d.ts.map +1 -1
  91. package/dist/tools/coValues/schemaUnion.d.ts +3 -3
  92. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  93. package/dist/tools/exports.d.ts +1 -1
  94. package/dist/tools/exports.d.ts.map +1 -1
  95. package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
  96. package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
  97. package/dist/tools/implementation/schema.d.ts +5 -5
  98. package/dist/tools/implementation/schema.d.ts.map +1 -1
  99. package/dist/tools/implementation/symbols.d.ts +2 -0
  100. package/dist/tools/implementation/symbols.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
  102. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  103. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
  104. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  105. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
  106. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  107. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
  108. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  109. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
  110. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  111. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
  112. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  113. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
  114. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  115. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
  116. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  117. package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
  118. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
  119. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
  120. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  121. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
  122. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  123. package/dist/tools/implementation/zodSchema/zodCo.d.ts +3 -3
  124. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  125. package/dist/tools/internal.d.ts +2 -1
  126. package/dist/tools/internal.d.ts.map +1 -1
  127. package/dist/tools/lib/migration.d.ts +1 -1
  128. package/dist/tools/lib/migration.d.ts.map +1 -1
  129. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  130. package/dist/tools/subscribe/index.d.ts +1 -1
  131. package/dist/tools/subscribe/index.d.ts.map +1 -1
  132. package/dist/tools/subscribe/utils.d.ts +2 -2
  133. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  134. package/dist/tools/testing.d.ts.map +1 -1
  135. package/dist/tools/tests/utils.d.ts +2 -6
  136. package/dist/tools/tests/utils.d.ts.map +1 -1
  137. package/dist/worker/index.js +3 -3
  138. package/dist/worker/index.js.map +1 -1
  139. package/package.json +23 -4
  140. package/src/better-auth/auth/client.ts +169 -0
  141. package/src/better-auth/auth/react.tsx +105 -0
  142. package/src/better-auth/auth/server.ts +250 -0
  143. package/src/better-auth/auth/tests/client.test.ts +249 -0
  144. package/src/better-auth/auth/tests/server.test.ts +226 -0
  145. package/src/browser/auth/PasskeyAuth.ts +2 -2
  146. package/src/browser/createBrowserContext.ts +2 -2
  147. package/src/browser/tests/PasskeyAuth.test.ts +2 -2
  148. package/src/inspector/custom-element.tsx +2 -2
  149. package/src/inspector/viewer/new-app.tsx +1 -1
  150. package/src/media/create-image.test.ts +7 -7
  151. package/src/media/create-image.ts +5 -3
  152. package/src/media/index.ts +1 -1
  153. package/src/media/utils.test.ts +72 -66
  154. package/src/media/utils.ts +9 -6
  155. package/src/prosemirror/lib/plugin.ts +1 -1
  156. package/src/prosemirror/lib/sync.ts +1 -1
  157. package/src/prosemirror/tests/plugin.test.ts +4 -4
  158. package/src/react/media/image.tsx +2 -2
  159. package/src/react/tests/media/image.test.tsx +52 -32
  160. package/src/react-core/hooks.ts +11 -5
  161. package/src/react-core/tests/useAccount.test.ts +16 -22
  162. package/src/react-core/tests/useCoState.test.ts +19 -19
  163. package/src/react-core/tests/useInboxSender.test.ts +5 -2
  164. package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
  165. package/src/react-native-core/media/image.tsx +1 -1
  166. package/src/svelte/jazz.class.svelte.ts +1 -1
  167. package/src/svelte/media/image.svelte +3 -9
  168. package/src/svelte/media/image.types.ts +7 -0
  169. package/src/svelte/tests/media/image.svelte.test.ts +34 -32
  170. package/src/tools/auth/DemoAuth.ts +2 -2
  171. package/src/tools/auth/PassphraseAuth.ts +2 -2
  172. package/src/tools/auth/clerk/index.ts +2 -2
  173. package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
  174. package/src/tools/coValues/CoFieldInit.ts +20 -0
  175. package/src/tools/coValues/CoValueBase.ts +40 -60
  176. package/src/tools/coValues/account.ts +311 -232
  177. package/src/tools/coValues/coFeed.ts +185 -153
  178. package/src/tools/coValues/coList.ts +507 -334
  179. package/src/tools/coValues/coMap.ts +434 -286
  180. package/src/tools/coValues/coPlainText.ts +94 -110
  181. package/src/tools/coValues/deepLoading.ts +13 -13
  182. package/src/tools/coValues/group.ts +100 -114
  183. package/src/tools/coValues/inbox.ts +16 -14
  184. package/src/tools/coValues/interfaces.ts +49 -31
  185. package/src/tools/coValues/profile.ts +8 -6
  186. package/src/tools/coValues/request.ts +9 -9
  187. package/src/tools/coValues/schemaUnion.ts +11 -5
  188. package/src/tools/exports.ts +1 -1
  189. package/src/tools/implementation/ContextManager.ts +4 -4
  190. package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
  191. package/src/tools/implementation/createContext.ts +1 -1
  192. package/src/tools/implementation/devtoolsFormatters.ts +9 -9
  193. package/src/tools/implementation/invites.ts +2 -2
  194. package/src/tools/implementation/schema.ts +7 -7
  195. package/src/tools/implementation/symbols.ts +3 -0
  196. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
  197. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
  198. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
  199. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
  200. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
  201. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
  202. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
  203. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
  204. package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
  205. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
  206. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
  207. package/src/tools/implementation/zodSchema/zodCo.ts +3 -3
  208. package/src/tools/internal.ts +2 -1
  209. package/src/tools/lib/migration.ts +5 -5
  210. package/src/tools/subscribe/SubscriptionScope.ts +32 -24
  211. package/src/tools/subscribe/index.ts +4 -4
  212. package/src/tools/subscribe/utils.ts +11 -11
  213. package/src/tools/testing.ts +17 -13
  214. package/src/tools/tests/ContextManager.test.ts +70 -59
  215. package/src/tools/tests/PassphraseAuth.test.ts +2 -2
  216. package/src/tools/tests/account.test.ts +188 -67
  217. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
  218. package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
  219. package/src/tools/tests/coFeed.test-d.ts +18 -17
  220. package/src/tools/tests/coFeed.test.ts +108 -97
  221. package/src/tools/tests/coList.test-d.ts +18 -23
  222. package/src/tools/tests/coList.test.ts +350 -165
  223. package/src/tools/tests/coMap.record.test-d.ts +9 -13
  224. package/src/tools/tests/coMap.record.test.ts +37 -23
  225. package/src/tools/tests/coMap.test-d.ts +43 -21
  226. package/src/tools/tests/coMap.test.ts +459 -182
  227. package/src/tools/tests/coOptional.test.ts +28 -13
  228. package/src/tools/tests/coPlainText.test.ts +15 -15
  229. package/src/tools/tests/createContext.test.ts +14 -14
  230. package/src/tools/tests/deepLoading.test.ts +95 -94
  231. package/src/tools/tests/exportImport.test.ts +61 -41
  232. package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
  233. package/src/tools/tests/inbox.test.ts +22 -17
  234. package/src/tools/tests/interfaces.test.ts +12 -11
  235. package/src/tools/tests/invites.test.ts +6 -4
  236. package/src/tools/tests/load.test.ts +20 -18
  237. package/src/tools/tests/patterns/notifications.test.ts +7 -7
  238. package/src/tools/tests/patterns/quest.test.ts +3 -3
  239. package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
  240. package/src/tools/tests/request.test.ts +38 -39
  241. package/src/tools/tests/schemaUnion.test.ts +64 -10
  242. package/src/tools/tests/subscribe.test.ts +64 -64
  243. package/src/tools/tests/testing.test.ts +7 -11
  244. package/src/tools/tests/utils.ts +3 -3
  245. package/src/tools/tests/zod.test.ts +3 -3
  246. package/src/worker/index.ts +3 -3
  247. package/tsup.config.ts +9 -0
  248. package/dist/chunk-LZOF6WP5.js.map +0 -1
  249. package/dist/media/chunk-E5J3WLQW.js.map +0 -1
  250. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +0 -1
@@ -125,15 +125,15 @@ describe("ContextManager", () => {
125
125
  await manager.createContext({});
126
126
 
127
127
  const credentials = {
128
- accountID: account.id,
129
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
128
+ accountID: account.$jazz.id,
129
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
130
130
  provider: "test",
131
131
  };
132
132
 
133
133
  // Authenticate with those credentials
134
134
  await manager.authenticate(credentials);
135
135
 
136
- expect(getCurrentValue().me.id).toBe(credentials.accountID);
136
+ expect(getCurrentValue().me.$jazz.id).toBe(credentials.accountID);
137
137
  });
138
138
 
139
139
  test("handles race conditions on the context creation", async () => {
@@ -142,15 +142,15 @@ describe("ContextManager", () => {
142
142
  manager.createContext({});
143
143
 
144
144
  const credentials = {
145
- accountID: account.id,
146
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
145
+ accountID: account.$jazz.id,
146
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
147
147
  provider: "test",
148
148
  };
149
149
 
150
150
  // Authenticate without waiting for the previous context to be created
151
151
  await manager.authenticate(credentials);
152
152
 
153
- expect(getCurrentValue().me.id).toBe(credentials.accountID);
153
+ expect(getCurrentValue().me.$jazz.id).toBe(credentials.accountID);
154
154
  });
155
155
 
156
156
  test("calls onLogOut callback when logging out", async () => {
@@ -205,8 +205,8 @@ describe("ContextManager", () => {
205
205
 
206
206
  // Authenticate with credentials
207
207
  await manager.authenticate({
208
- accountID: account.id,
209
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
208
+ accountID: account.$jazz.id,
209
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
210
210
  provider: "test",
211
211
  });
212
212
 
@@ -219,8 +219,8 @@ describe("ContextManager", () => {
219
219
  const account = await createJazzTestAccount();
220
220
 
221
221
  await manager.getAuthSecretStorage().set({
222
- accountID: account.id,
223
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
222
+ accountID: account.$jazz.id,
223
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
224
224
  provider: "test",
225
225
  });
226
226
 
@@ -229,8 +229,8 @@ describe("ContextManager", () => {
229
229
 
230
230
  // Authenticate with same credentials
231
231
  await manager.authenticate({
232
- accountID: account.id,
233
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
232
+ accountID: account.$jazz.id,
233
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
234
234
  provider: "test",
235
235
  });
236
236
 
@@ -256,11 +256,14 @@ describe("ContextManager", () => {
256
256
  profile: co.profile(),
257
257
  })
258
258
  .withMigration(async (account) => {
259
- account.root = AccountRoot.create(
260
- {
261
- value: "Hello",
262
- },
263
- Group.create(this).makePublic(),
259
+ account.$jazz.set(
260
+ "root",
261
+ AccountRoot.create(
262
+ {
263
+ value: "Hello",
264
+ },
265
+ Group.create(this).makePublic(),
266
+ ),
264
267
  );
265
268
  });
266
269
 
@@ -272,15 +275,16 @@ describe("ContextManager", () => {
272
275
  AccountSchema: coValueClassFromCoValueClassOrSchema(CustomAccount),
273
276
  storage: dbFilename,
274
277
  onAnonymousAccountDiscarded: async (anonymousAccount) => {
275
- const anonymousAccountWithRoot = await anonymousAccount.ensureLoaded({
276
- resolve: { root: true },
277
- });
278
+ const anonymousAccountWithRoot =
279
+ await anonymousAccount.$jazz.ensureLoaded({
280
+ resolve: { root: true },
281
+ });
278
282
 
279
- const me = await CustomAccount.getMe().ensureLoaded({
283
+ const me = await CustomAccount.getMe().$jazz.ensureLoaded({
280
284
  resolve: { root: true },
281
285
  });
282
286
 
283
- me.root.transferredRoot = anonymousAccountWithRoot.root;
287
+ me.root.$jazz.set("transferredRoot", anonymousAccountWithRoot.root);
284
288
  },
285
289
  });
286
290
 
@@ -295,15 +299,15 @@ describe("ContextManager", () => {
295
299
  ).me;
296
300
 
297
301
  await customManager.authenticate({
298
- accountID: account.id,
299
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
302
+ accountID: account.$jazz.id,
303
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
300
304
  provider: "test",
301
305
  });
302
306
 
303
307
  // The storage should be closed and set to undefined
304
308
  expect(prevContextNode.storage).toBeUndefined();
305
309
 
306
- const me = await CustomAccount.getMe().ensureLoaded({
310
+ const me = await CustomAccount.getMe().$jazz.ensureLoaded({
307
311
  resolve: { root: { transferredRoot: true } },
308
312
  });
309
313
 
@@ -322,11 +326,11 @@ describe("ContextManager", () => {
322
326
  root: AccountRoot,
323
327
  profile: co.profile(),
324
328
  })
325
- .withMigration(async (account) => {
326
- account.root = AccountRoot.create({
329
+ .withMigration(async (account: Account) => {
330
+ account.$jazz.set("root", {
327
331
  value: "Hello",
328
332
  });
329
- lastRootId = account.root.id;
333
+ lastRootId = account.root!.$jazz.id;
330
334
  });
331
335
 
332
336
  const customManager = new TestJazzContextManager<
@@ -345,16 +349,16 @@ describe("ContextManager", () => {
345
349
  ).me;
346
350
 
347
351
  await customManager.authenticate({
348
- accountID: account.id,
349
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
352
+ accountID: account.$jazz.id,
353
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
350
354
  provider: "test",
351
355
  });
352
356
 
353
- const me = await CustomAccount.getMe().ensureLoaded({
357
+ const me = await CustomAccount.getMe().$jazz.ensureLoaded({
354
358
  resolve: { root: true },
355
359
  });
356
360
 
357
- expect(me.root.id).toBe(lastRootId);
361
+ expect(me.root.$jazz.id).toBe(lastRootId);
358
362
  });
359
363
 
360
364
  test("the migration should be applied correctly on existing accounts (2)", async () => {
@@ -368,16 +372,19 @@ describe("ContextManager", () => {
368
372
  profile: co.profile(),
369
373
  })
370
374
  .withMigration(async (account) => {
371
- if (account.root === undefined) {
372
- account.root = AccountRoot.create({
373
- value: 1,
374
- });
375
+ if (!account.$jazz.has("root")) {
376
+ account.$jazz.set(
377
+ "root",
378
+ AccountRoot.create({
379
+ value: 1,
380
+ }),
381
+ );
375
382
  } else {
376
- const { root } = await account.ensureLoaded({
383
+ const { root } = await account.$jazz.ensureLoaded({
377
384
  resolve: { root: true },
378
385
  });
379
386
 
380
- root.value = 2;
387
+ root.$jazz.set("value", 2);
381
388
  }
382
389
  });
383
390
  const customManager = new TestJazzContextManager<
@@ -396,12 +403,12 @@ describe("ContextManager", () => {
396
403
  ).me;
397
404
 
398
405
  await customManager.authenticate({
399
- accountID: account.id,
400
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
406
+ accountID: account.$jazz.id,
407
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
401
408
  provider: "test",
402
409
  });
403
410
 
404
- const me = await CustomAccount.getMe().ensureLoaded({
411
+ const me = await CustomAccount.getMe().$jazz.ensureLoaded({
405
412
  resolve: { root: true },
406
413
  });
407
414
 
@@ -422,23 +429,27 @@ describe("ContextManager", () => {
422
429
  profile: co.profile(),
423
430
  })
424
431
  .withMigration(async (account) => {
425
- if (account.root === undefined) {
426
- account.root = AccountRoot.create({
427
- value: "Hello",
428
- });
432
+ if (!account.$jazz.has("root")) {
433
+ account.$jazz.set(
434
+ "root",
435
+ AccountRoot.create({
436
+ value: "Hello",
437
+ }),
438
+ );
429
439
  }
430
440
  });
431
441
 
432
442
  const onAnonymousAccountDiscarded = async (
433
443
  anonymousAccount: Loaded<typeof CustomAccount, { root: true }>,
434
444
  ) => {
435
- const anonymousAccountWithRoot = await anonymousAccount.ensureLoaded({
436
- resolve: {
437
- root: true,
438
- },
439
- });
445
+ const anonymousAccountWithRoot =
446
+ await anonymousAccount.$jazz.ensureLoaded({
447
+ resolve: {
448
+ root: true,
449
+ },
450
+ });
440
451
 
441
- const meWithRoot = await CustomAccount.getMe().ensureLoaded({
452
+ const meWithRoot = await CustomAccount.getMe().$jazz.ensureLoaded({
442
453
  resolve: {
443
454
  root: true,
444
455
  },
@@ -446,9 +457,9 @@ describe("ContextManager", () => {
446
457
 
447
458
  const rootToTransfer = anonymousAccountWithRoot.root;
448
459
 
449
- await rootToTransfer._owner.castAs(Group).addMember(meWithRoot, "admin");
460
+ await rootToTransfer.$jazz.owner.addMember(meWithRoot, "admin");
450
461
 
451
- meWithRoot.root.transferredRoot = rootToTransfer;
462
+ meWithRoot.root.$jazz.set("transferredRoot", rootToTransfer);
452
463
  };
453
464
 
454
465
  const customManager = new TestJazzContextManager<
@@ -467,12 +478,12 @@ describe("ContextManager", () => {
467
478
  });
468
479
 
469
480
  await customManager.authenticate({
470
- accountID: account.id,
471
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
481
+ accountID: account.$jazz.id,
482
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
472
483
  provider: "test",
473
484
  });
474
485
 
475
- const me = await CustomAccount.getMe().ensureLoaded({
486
+ const me = await CustomAccount.getMe().$jazz.ensureLoaded({
476
487
  resolve: {
477
488
  root: true,
478
489
  },
@@ -491,7 +502,7 @@ describe("ContextManager", () => {
491
502
  expect(accountId).toBeDefined();
492
503
  const context = getCurrentValue();
493
504
  expect(context.me.profile?.name).toBe("Test User");
494
- expect(context.me.id).toBe(accountId);
505
+ expect(context.me.$jazz.id).toBe(accountId);
495
506
  });
496
507
 
497
508
  test("calls onAnonymousAccountDiscarded when registering from anonymous user", async () => {
@@ -510,8 +521,8 @@ describe("ContextManager", () => {
510
521
  const account = await createJazzTestAccount();
511
522
 
512
523
  await manager.getAuthSecretStorage().set({
513
- accountID: account.id,
514
- accountSecret: account._raw.core.node.getCurrentAgent().agentSecret,
524
+ accountID: account.$jazz.id,
525
+ accountSecret: account.$jazz.localNode.getCurrentAgent().agentSecret,
515
526
  provider: "test",
516
527
  });
517
528
 
@@ -151,7 +151,7 @@ describe("PassphraseAuth", () => {
151
151
  await passphraseAuth.signUp(testName);
152
152
 
153
153
  // Verify the account name was set
154
- const { profile } = await account.ensureLoaded({
154
+ const { profile } = await account.$jazz.ensureLoaded({
155
155
  resolve: {
156
156
  profile: true,
157
157
  },
@@ -315,7 +315,7 @@ describe("PassphraseAuth with TestJazzContextManager", () => {
315
315
  const context = contextManager.getCurrentValue();
316
316
 
317
317
  assert(context && "me" in context);
318
- expect(context.me.id).toBe(accountId);
318
+ expect(context.me.$jazz.id).toBe(accountId);
319
319
  expect(context.me.profile?.name).toBe("Test User");
320
320
 
321
321
  expect(authSecretStorage.isAuthenticated).toBe(true);
@@ -23,7 +23,7 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
23
23
  TestMap.create({ name: "Alice" }, { owner: clientAccount }),
24
24
  );
25
25
 
26
- await clientAccount.waitForAllCoValuesSync({
26
+ await clientAccount.$jazz.waitForAllCoValuesSync({
27
27
  timeout: 1000,
28
28
  });
29
29
 
@@ -31,7 +31,7 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
31
31
  clientNode.gracefulShutdown();
32
32
 
33
33
  for (const map of maps) {
34
- const loadedMap = await serverNode.load(map._raw.id);
34
+ const loadedMap = await serverNode.load(map.$jazz.raw.id);
35
35
  expect(loadedMap).not.toBe("unavailable");
36
36
  }
37
37
  });
@@ -39,12 +39,12 @@ test("waitForAllCoValuesSync should resolve when all the values are synced", asy
39
39
  test("waitForSync should resolve when the value is uploaded", async () => {
40
40
  const { clientNode, serverNode, clientAccount } = await setupTwoNodes();
41
41
 
42
- await clientAccount.waitForSync({ timeout: 1000 });
42
+ await clientAccount.$jazz.waitForSync({ timeout: 1000 });
43
43
 
44
44
  // Killing the client node so the serverNode can't load the map from it
45
45
  clientNode.gracefulShutdown();
46
46
 
47
- const loadedAccount = await serverNode.load(clientAccount._raw.id);
47
+ const loadedAccount = await serverNode.load(clientAccount.$jazz.raw.id);
48
48
 
49
49
  expect(loadedAccount).not.toBe("unavailable");
50
50
  });
@@ -86,11 +86,11 @@ test("Me gets updated correctly when creating a new account as active", async ()
86
86
 
87
87
  test("accounts should sync correctly", async () => {
88
88
  const account = await createJazzTestAccount({ isCurrentActiveAccount: true });
89
- account.profile!.name = "test 1";
89
+ account.profile!.$jazz.set("name", "test 1");
90
90
  const otherAccount = await createJazzTestAccount({
91
91
  isCurrentActiveAccount: true,
92
92
  });
93
- otherAccount.profile!.name = "test 2";
93
+ otherAccount.profile!.$jazz.set("name", "test 2");
94
94
 
95
95
  await linkAccounts(account, otherAccount);
96
96
 
@@ -111,7 +111,7 @@ test("loading accounts should work", async () => {
111
111
 
112
112
  const otherAccount = await createJazzTestAccount();
113
113
 
114
- const loadedAccount = await Account.load(account.id, {
114
+ const loadedAccount = await Account.load(account.$jazz.id, {
115
115
  loadAs: otherAccount,
116
116
  resolve: {
117
117
  profile: true,
@@ -129,7 +129,7 @@ test("loading raw accounts should work", async () => {
129
129
  },
130
130
  });
131
131
 
132
- const loadedAccount = await Account.load(account.id, {
132
+ const loadedAccount = await Account.load(account.$jazz.id, {
133
133
  loadAs: account,
134
134
  });
135
135
 
@@ -180,21 +180,24 @@ test("should support recursive props on co.profile", async () => {
180
180
  if (me.profile === undefined) {
181
181
  const group = Group.create({ owner: me });
182
182
  group.addMember("everyone", "reader");
183
- me.profile = User.create(
184
- {
185
- name: "test 1",
186
- created: new Date(),
187
- updated: new Date(),
188
- anonymous: false,
189
- following: co.list(User).create([], group),
190
- followers: co.list(User).create([], group),
191
- },
192
- group,
183
+ me.$jazz.set(
184
+ "profile",
185
+ User.create(
186
+ {
187
+ name: "test 1",
188
+ created: new Date(),
189
+ updated: new Date(),
190
+ anonymous: false,
191
+ following: co.list(User).create([], group),
192
+ followers: co.list(User).create([], group),
193
+ },
194
+ group,
195
+ ),
193
196
  );
194
197
  }
195
198
 
196
199
  if (me.root === undefined) {
197
- me.root = co.map({}).create({});
200
+ me.$jazz.set("root", {});
198
201
  }
199
202
  });
200
203
 
@@ -211,64 +214,182 @@ test("should support recursive props on co.profile", async () => {
211
214
  expect(account.profile.followers.length).toBe(0);
212
215
  });
213
216
 
214
- test("root and profile should be trusting by default", async () => {
215
- const AccountSchema = co
216
- .account({
217
- profile: co.profile(),
218
- root: co.map({
219
- name: z.string(),
220
- }),
221
- })
222
- .withMigration((me, creationProps) => {
223
- const group = Group.create({ owner: me }).makePublic();
217
+ test("cannot update account profile properties directly", async () => {
218
+ const account = await createJazzTestAccount({
219
+ creationProps: {
220
+ name: "test 1",
221
+ },
222
+ });
224
223
 
225
- if (me.profile === undefined) {
226
- me.profile = co.profile().create(
227
- {
228
- name: creationProps?.name ?? "Anonymous",
229
- },
230
- group,
231
- );
232
- }
224
+ assert(account.profile);
233
225
 
234
- if (me.root === undefined) {
235
- me.root = co
236
- .map({
237
- name: z.string(),
238
- })
239
- .create(
240
- {
241
- name: creationProps?.name ?? "Anonymous",
242
- },
243
- group,
226
+ // @ts-expect-error - cannot update profile properties directly
227
+ expect(() => (account.profile.name = "test 2")).toThrow(
228
+ "Cannot update a CoMap directly. Use `$jazz.set` instead.",
229
+ );
230
+ account.profile.$jazz.set("name", "test 3");
231
+ expect(account.profile.name).toBe("test 3");
232
+ });
233
+
234
+ describe("root and profile", () => {
235
+ test("root and profile should be trusting by default", async () => {
236
+ const AccountSchema = co
237
+ .account({
238
+ profile: co.profile(),
239
+ root: co.map({
240
+ name: z.string(),
241
+ }),
242
+ })
243
+ .withMigration((me, creationProps) => {
244
+ const group = Group.create({ owner: me }).makePublic();
245
+
246
+ if (me.profile === undefined) {
247
+ me.$jazz.set(
248
+ "profile",
249
+ co.profile().create(
250
+ {
251
+ name: creationProps?.name ?? "Anonymous",
252
+ },
253
+ group,
254
+ ),
244
255
  );
245
- }
256
+ }
257
+
258
+ if (me.root === undefined) {
259
+ me.$jazz.set(
260
+ "root",
261
+ co
262
+ .map({
263
+ name: z.string(),
264
+ })
265
+ .create(
266
+ {
267
+ name: creationProps?.name ?? "Anonymous",
268
+ },
269
+ group,
270
+ ),
271
+ );
272
+ }
273
+ });
274
+
275
+ const bob = await createJazzTestAccount({
276
+ AccountSchema,
277
+ creationProps: {
278
+ name: "Bob",
279
+ },
246
280
  });
247
281
 
248
- const bob = await createJazzTestAccount({
249
- AccountSchema,
250
- creationProps: {
251
- name: "Bob",
252
- },
282
+ const alice = await createJazzTestAccount({
283
+ AccountSchema,
284
+ creationProps: {
285
+ name: "Alice",
286
+ },
287
+ });
288
+
289
+ const bobAccountLoadedFromAlice = await AccountSchema.load(bob.$jazz.id, {
290
+ loadAs: alice,
291
+ resolve: {
292
+ profile: true,
293
+ root: true,
294
+ },
295
+ });
296
+
297
+ assert(bobAccountLoadedFromAlice);
298
+
299
+ expect(bobAccountLoadedFromAlice.profile.name).toBe("Bob");
300
+ expect(bobAccountLoadedFromAlice.root.name).toBe("Bob");
253
301
  });
254
302
 
255
- const alice = await createJazzTestAccount({
256
- AccountSchema,
257
- creationProps: {
258
- name: "Alice",
259
- },
303
+ test("can be initialized using JSON objects", async () => {
304
+ const Avatar = co.map({
305
+ url: z.string(),
306
+ });
307
+ const CustomProfile = co.profile({
308
+ avatar: Avatar,
309
+ });
310
+ const CustomRoot = co.map({
311
+ name: z.string(),
312
+ });
313
+ const AccountSchema = co
314
+ .account({
315
+ profile: CustomProfile,
316
+ root: CustomRoot,
317
+ })
318
+ .withMigration((me, creationProps) => {
319
+ if (me.profile === undefined) {
320
+ me.$jazz.set("profile", {
321
+ name: creationProps?.name ?? "Anonymous",
322
+ avatar: {
323
+ url: "https://example.com/avatar.png",
324
+ },
325
+ });
326
+ }
327
+
328
+ if (me.root === undefined) {
329
+ me.$jazz.set("root", { name: creationProps?.name ?? "Anonymous" });
330
+ }
331
+ });
332
+
333
+ const account = await createJazzTestAccount({
334
+ AccountSchema,
335
+ creationProps: {
336
+ name: "test 1",
337
+ },
338
+ });
339
+
340
+ expect(account.profile.name).toBe("test 1");
341
+ expect(account.profile.avatar.url).toBe("https://example.com/avatar.png");
342
+ expect(account.root.name).toBe("test 1");
260
343
  });
344
+ });
261
345
 
262
- const bobAccountLoadedFromAlice = await AccountSchema.load(bob.id, {
263
- loadAs: alice,
264
- resolve: {
265
- profile: true,
266
- root: true,
267
- },
346
+ describe("account.$jazz.has", () => {
347
+ test("should return true if the key is defined", async () => {
348
+ const account = await createJazzTestAccount({
349
+ creationProps: { name: "John" },
350
+ });
351
+
352
+ expect(account.$jazz.has("profile")).toBe(true);
353
+ expect(account.$jazz.has("root")).toBe(false);
268
354
  });
269
355
 
270
- assert(bobAccountLoadedFromAlice);
356
+ test("should work as migration check", async () => {
357
+ const CustomProfile = co.profile({
358
+ name: z.string(),
359
+ email: z.string().optional(),
360
+ });
271
361
 
272
- expect(bobAccountLoadedFromAlice.profile.name).toBe("Bob");
273
- expect(bobAccountLoadedFromAlice.root.name).toBe("Bob");
362
+ const CustomRoot = co.map({
363
+ settings: z.string(),
364
+ });
365
+
366
+ const CustomAccount = co
367
+ .account({
368
+ profile: CustomProfile,
369
+ root: CustomRoot,
370
+ })
371
+ .withMigration((me, creationProps) => {
372
+ if (!me.$jazz.has("profile")) {
373
+ me.$jazz.set("profile", {
374
+ name: creationProps?.name ?? "Anonymous",
375
+ email: "test@example.com",
376
+ });
377
+ }
378
+
379
+ if (!me.$jazz.has("root")) {
380
+ me.$jazz.set("root", { settings: "default" });
381
+ }
382
+ });
383
+
384
+ const account = await createJazzTestAccount({
385
+ AccountSchema: CustomAccount,
386
+ creationProps: { name: "Custom User" },
387
+ });
388
+
389
+ expect(account.$jazz.has("profile")).toBe(true);
390
+ expect(account.$jazz.has("root")).toBe(true);
391
+
392
+ expect(account.profile.email).toBe("test@example.com");
393
+ expect(account.root.settings).toBe("default");
394
+ });
274
395
  });
@@ -29,9 +29,12 @@ describe("co.discriminatedUnion", () => {
29
29
  }),
30
30
  });
31
31
 
32
- person.pet = Cat.create({
33
- type: "cat",
34
- });
32
+ person.$jazz.set(
33
+ "pet",
34
+ Cat.create({
35
+ type: "cat",
36
+ }),
37
+ );
35
38
 
36
39
  type ExpectedType = {
37
40
  pet: Loaded<typeof Dog> | Loaded<typeof Cat>;
@@ -67,9 +70,12 @@ describe("co.discriminatedUnion", () => {
67
70
  }),
68
71
  });
69
72
 
70
- pallino.friend = Cat.create({
71
- type: "cat",
72
- });
73
+ pallino.$jazz.set(
74
+ "friend",
75
+ Cat.create({
76
+ type: "cat",
77
+ }),
78
+ );
73
79
 
74
80
  type ExpectedType = {
75
81
  friend: Loaded<typeof Dog> | Loaded<typeof Cat> | undefined;