jazz-tools 0.17.13 → 0.18.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 (228) 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 +49 -49
  10. package/CHANGELOG.md +42 -0
  11. package/dist/browser/index.js +2 -2
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/{chunk-SFP5PBPX.js → chunk-HJ3GTGY7.js} +1325 -1001
  14. package/dist/chunk-HJ3GTGY7.js.map +1 -0
  15. package/dist/index.js +18 -18
  16. package/dist/index.js.map +1 -1
  17. package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
  18. package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
  19. package/dist/inspector/index.js +1 -1
  20. package/dist/inspector/index.js.map +1 -1
  21. package/dist/inspector/register-custom-element.js +1 -1
  22. package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
  23. package/dist/media/chunk-KR2V6X2N.js.map +1 -0
  24. package/dist/media/create-image.d.ts +6 -6
  25. package/dist/media/index.browser.d.ts +6 -6
  26. package/dist/media/index.browser.js +1 -1
  27. package/dist/media/index.d.ts +1 -1
  28. package/dist/media/index.js +1 -1
  29. package/dist/media/index.native.d.ts +6 -6
  30. package/dist/media/index.native.js +1 -1
  31. package/dist/media/utils.d.ts.map +1 -1
  32. package/dist/prosemirror/index.js +2 -2
  33. package/dist/prosemirror/index.js.map +1 -1
  34. package/dist/react/index.js +7 -5
  35. package/dist/react/index.js.map +1 -1
  36. package/dist/react-core/hooks.d.ts.map +1 -1
  37. package/dist/react-core/index.js +4658 -23
  38. package/dist/react-core/index.js.map +1 -1
  39. package/dist/react-native-core/index.js +1 -1
  40. package/dist/react-native-core/index.js.map +1 -1
  41. package/dist/svelte/jazz.class.svelte.js +1 -1
  42. package/dist/svelte/media/image.svelte +3 -9
  43. package/dist/svelte/media/image.svelte.d.ts +1 -6
  44. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  45. package/dist/svelte/media/image.types.d.ts +7 -0
  46. package/dist/svelte/media/image.types.d.ts.map +1 -0
  47. package/dist/svelte/media/image.types.js +1 -0
  48. package/dist/svelte/tests/media/image.svelte.test.js +31 -31
  49. package/dist/testing.js +18 -14
  50. package/dist/testing.js.map +1 -1
  51. package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
  52. package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
  53. package/dist/tools/coValues/CoValueBase.d.ts +18 -15
  54. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  55. package/dist/tools/coValues/account.d.ts +100 -46
  56. package/dist/tools/coValues/account.d.ts.map +1 -1
  57. package/dist/tools/coValues/coFeed.d.ts +78 -62
  58. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  59. package/dist/tools/coValues/coList.d.ts +212 -99
  60. package/dist/tools/coValues/coList.d.ts.map +1 -1
  61. package/dist/tools/coValues/coMap.d.ts +200 -192
  62. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  63. package/dist/tools/coValues/coPlainText.d.ts +30 -22
  64. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  65. package/dist/tools/coValues/deepLoading.d.ts +13 -13
  66. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  67. package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
  68. package/dist/tools/coValues/group.d.ts +32 -32
  69. package/dist/tools/coValues/group.d.ts.map +1 -1
  70. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  71. package/dist/tools/coValues/interfaces.d.ts +18 -17
  72. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  73. package/dist/tools/coValues/profile.d.ts +6 -5
  74. package/dist/tools/coValues/profile.d.ts.map +1 -1
  75. package/dist/tools/coValues/schemaUnion.d.ts +3 -3
  76. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  77. package/dist/tools/exports.d.ts +1 -1
  78. package/dist/tools/exports.d.ts.map +1 -1
  79. package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
  80. package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
  81. package/dist/tools/implementation/schema.d.ts +5 -5
  82. package/dist/tools/implementation/schema.d.ts.map +1 -1
  83. package/dist/tools/implementation/symbols.d.ts +2 -0
  84. package/dist/tools/implementation/symbols.d.ts.map +1 -1
  85. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
  86. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  87. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
  88. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  89. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
  90. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  91. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
  92. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  93. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
  94. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
  96. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
  98. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
  100. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
  102. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
  103. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
  104. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  105. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
  106. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  107. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -2
  108. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  109. package/dist/tools/internal.d.ts +2 -1
  110. package/dist/tools/internal.d.ts.map +1 -1
  111. package/dist/tools/lib/migration.d.ts +1 -1
  112. package/dist/tools/lib/migration.d.ts.map +1 -1
  113. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  114. package/dist/tools/subscribe/index.d.ts +1 -1
  115. package/dist/tools/subscribe/index.d.ts.map +1 -1
  116. package/dist/tools/subscribe/utils.d.ts +2 -2
  117. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  118. package/dist/tools/testing.d.ts.map +1 -1
  119. package/dist/tools/tests/utils.d.ts +2 -6
  120. package/dist/tools/tests/utils.d.ts.map +1 -1
  121. package/dist/worker/index.js +3 -3
  122. package/dist/worker/index.js.map +1 -1
  123. package/package.json +4 -4
  124. package/src/browser/auth/PasskeyAuth.ts +2 -2
  125. package/src/browser/createBrowserContext.ts +2 -2
  126. package/src/browser/tests/PasskeyAuth.test.ts +2 -2
  127. package/src/inspector/custom-element.tsx +2 -2
  128. package/src/inspector/viewer/new-app.tsx +1 -1
  129. package/src/media/create-image.test.ts +7 -7
  130. package/src/media/create-image.ts +5 -3
  131. package/src/media/index.ts +1 -1
  132. package/src/media/utils.test.ts +72 -66
  133. package/src/media/utils.ts +9 -6
  134. package/src/prosemirror/lib/plugin.ts +1 -1
  135. package/src/prosemirror/lib/sync.ts +1 -1
  136. package/src/prosemirror/tests/plugin.test.ts +4 -4
  137. package/src/react/media/image.tsx +2 -2
  138. package/src/react/tests/media/image.test.tsx +52 -32
  139. package/src/react-core/hooks.ts +11 -5
  140. package/src/react-core/tests/useAccount.test.ts +16 -22
  141. package/src/react-core/tests/useCoState.test.ts +19 -19
  142. package/src/react-core/tests/useInboxSender.test.ts +5 -2
  143. package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
  144. package/src/react-native-core/media/image.tsx +1 -1
  145. package/src/svelte/jazz.class.svelte.ts +1 -1
  146. package/src/svelte/media/image.svelte +3 -9
  147. package/src/svelte/media/image.types.ts +7 -0
  148. package/src/svelte/tests/media/image.svelte.test.ts +34 -32
  149. package/src/tools/auth/DemoAuth.ts +2 -2
  150. package/src/tools/auth/PassphraseAuth.ts +2 -2
  151. package/src/tools/auth/clerk/index.ts +2 -2
  152. package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
  153. package/src/tools/coValues/CoFieldInit.ts +20 -0
  154. package/src/tools/coValues/CoValueBase.ts +40 -60
  155. package/src/tools/coValues/account.ts +306 -232
  156. package/src/tools/coValues/coFeed.ts +185 -153
  157. package/src/tools/coValues/coList.ts +507 -334
  158. package/src/tools/coValues/coMap.ts +420 -286
  159. package/src/tools/coValues/coPlainText.ts +94 -110
  160. package/src/tools/coValues/deepLoading.ts +13 -13
  161. package/src/tools/coValues/group.ts +100 -114
  162. package/src/tools/coValues/inbox.ts +16 -14
  163. package/src/tools/coValues/interfaces.ts +49 -31
  164. package/src/tools/coValues/profile.ts +8 -6
  165. package/src/tools/coValues/request.ts +9 -9
  166. package/src/tools/coValues/schemaUnion.ts +11 -5
  167. package/src/tools/exports.ts +1 -1
  168. package/src/tools/implementation/ContextManager.ts +4 -4
  169. package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
  170. package/src/tools/implementation/createContext.ts +1 -1
  171. package/src/tools/implementation/devtoolsFormatters.ts +9 -9
  172. package/src/tools/implementation/invites.ts +2 -2
  173. package/src/tools/implementation/schema.ts +7 -7
  174. package/src/tools/implementation/symbols.ts +3 -0
  175. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
  176. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
  177. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
  178. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
  179. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
  180. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
  181. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
  182. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
  183. package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
  184. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
  185. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
  186. package/src/tools/implementation/zodSchema/zodCo.ts +47 -10
  187. package/src/tools/internal.ts +2 -1
  188. package/src/tools/lib/migration.ts +5 -5
  189. package/src/tools/subscribe/SubscriptionScope.ts +32 -24
  190. package/src/tools/subscribe/index.ts +4 -4
  191. package/src/tools/subscribe/utils.ts +11 -11
  192. package/src/tools/testing.ts +17 -13
  193. package/src/tools/tests/ContextManager.test.ts +68 -57
  194. package/src/tools/tests/PassphraseAuth.test.ts +2 -2
  195. package/src/tools/tests/account.test.ts +154 -74
  196. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
  197. package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
  198. package/src/tools/tests/coFeed.test-d.ts +18 -17
  199. package/src/tools/tests/coFeed.test.ts +108 -97
  200. package/src/tools/tests/coList.test-d.ts +18 -23
  201. package/src/tools/tests/coList.test.ts +350 -165
  202. package/src/tools/tests/coMap.record.test-d.ts +9 -13
  203. package/src/tools/tests/coMap.record.test.ts +37 -23
  204. package/src/tools/tests/coMap.test-d.ts +43 -21
  205. package/src/tools/tests/coMap.test.ts +368 -182
  206. package/src/tools/tests/coOptional.test.ts +28 -13
  207. package/src/tools/tests/coPlainText.test.ts +15 -15
  208. package/src/tools/tests/createContext.test.ts +14 -14
  209. package/src/tools/tests/deepLoading.test.ts +95 -94
  210. package/src/tools/tests/exportImport.test.ts +61 -41
  211. package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
  212. package/src/tools/tests/inbox.test.ts +22 -17
  213. package/src/tools/tests/interfaces.test.ts +12 -11
  214. package/src/tools/tests/invites.test.ts +6 -4
  215. package/src/tools/tests/load.test.ts +20 -18
  216. package/src/tools/tests/patterns/notifications.test.ts +6 -6
  217. package/src/tools/tests/patterns/quest.test.ts +3 -3
  218. package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
  219. package/src/tools/tests/request.test.ts +38 -39
  220. package/src/tools/tests/schemaUnion.test.ts +64 -10
  221. package/src/tools/tests/subscribe.test.ts +64 -64
  222. package/src/tools/tests/testing.test.ts +5 -9
  223. package/src/tools/tests/utils.ts +3 -3
  224. package/src/tools/tests/zod.test.ts +3 -3
  225. package/src/worker/index.ts +3 -3
  226. package/dist/chunk-SFP5PBPX.js.map +0 -1
  227. package/dist/media/chunk-E5J3WLQW.js.map +0 -1
  228. 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 () => {
@@ -369,15 +373,18 @@ describe("ContextManager", () => {
369
373
  })
370
374
  .withMigration(async (account) => {
371
375
  if (account.root === undefined) {
372
- account.root = AccountRoot.create({
373
- value: 1,
374
- });
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
 
@@ -423,22 +430,26 @@ describe("ContextManager", () => {
423
430
  })
424
431
  .withMigration(async (account) => {
425
432
  if (account.root === undefined) {
426
- account.root = AccountRoot.create({
427
- value: "Hello",
428
- });
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);
@@ -1,4 +1,4 @@
1
- import { assert, beforeEach, expect, test } from "vitest";
1
+ import { assert, beforeEach, describe, expect, test } from "vitest";
2
2
  import { Account, Group, co, z } from "../exports.js";
3
3
  import {
4
4
  createJazzTestAccount,
@@ -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
 
@@ -137,10 +137,20 @@ test("loading raw accounts should work", async () => {
137
137
  expect(loadedAccount.profile!.name).toBe("test 1");
138
138
  });
139
139
 
140
- test("co.profile() should throw an error if passed a CoValue schema", async () => {
141
- expect(() => co.profile(co.map({}))).toThrow(
142
- "co.profile() expects an object as its argument, not a CoValue schema",
143
- );
140
+ describe("co.profile() schema", () => {
141
+ test("co.profile() should throw an error if passed a CoValue schema", async () => {
142
+ expect(() => co.profile(co.map({}))).toThrow(
143
+ "co.profile() expects an object as its argument, not a CoValue schema",
144
+ );
145
+ });
146
+
147
+ test("co.profile() should throw an error if its shape does not contain valid schemas", () => {
148
+ expect(() =>
149
+ co.profile({
150
+ field: "a string is not a valid schema",
151
+ }),
152
+ ).toThrow("co.profile() supports only Zod v4 schemas and CoValue schemas");
153
+ });
144
154
  });
145
155
 
146
156
  test("should support recursive props on co.profile", async () => {
@@ -170,21 +180,24 @@ test("should support recursive props on co.profile", async () => {
170
180
  if (me.profile === undefined) {
171
181
  const group = Group.create({ owner: me });
172
182
  group.addMember("everyone", "reader");
173
- me.profile = User.create(
174
- {
175
- name: "test 1",
176
- created: new Date(),
177
- updated: new Date(),
178
- anonymous: false,
179
- following: co.list(User).create([], group),
180
- followers: co.list(User).create([], group),
181
- },
182
- 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
+ ),
183
196
  );
184
197
  }
185
198
 
186
199
  if (me.root === undefined) {
187
- me.root = co.map({}).create({});
200
+ me.$jazz.set("root", {});
188
201
  }
189
202
  });
190
203
 
@@ -201,64 +214,131 @@ test("should support recursive props on co.profile", async () => {
201
214
  expect(account.profile.followers.length).toBe(0);
202
215
  });
203
216
 
204
- test("root and profile should be trusting by default", async () => {
205
- const AccountSchema = co
206
- .account({
207
- profile: co.profile(),
208
- root: co.map({
209
- name: z.string(),
210
- }),
211
- })
212
- .withMigration((me, creationProps) => {
213
- 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
+ });
214
223
 
215
- if (me.profile === undefined) {
216
- me.profile = co.profile().create(
217
- {
218
- name: creationProps?.name ?? "Anonymous",
219
- },
220
- group,
221
- );
222
- }
224
+ assert(account.profile);
223
225
 
224
- if (me.root === undefined) {
225
- me.root = co
226
- .map({
227
- name: z.string(),
228
- })
229
- .create(
230
- {
231
- name: creationProps?.name ?? "Anonymous",
232
- },
233
- 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
+ ),
234
255
  );
235
- }
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
+ },
236
280
  });
237
281
 
238
- const bob = await createJazzTestAccount({
239
- AccountSchema,
240
- creationProps: {
241
- name: "Bob",
242
- },
243
- });
282
+ const alice = await createJazzTestAccount({
283
+ AccountSchema,
284
+ creationProps: {
285
+ name: "Alice",
286
+ },
287
+ });
244
288
 
245
- const alice = await createJazzTestAccount({
246
- AccountSchema,
247
- creationProps: {
248
- name: "Alice",
249
- },
250
- });
289
+ const bobAccountLoadedFromAlice = await AccountSchema.load(bob.$jazz.id, {
290
+ loadAs: alice,
291
+ resolve: {
292
+ profile: true,
293
+ root: true,
294
+ },
295
+ });
251
296
 
252
- const bobAccountLoadedFromAlice = await AccountSchema.load(bob.id, {
253
- loadAs: alice,
254
- resolve: {
255
- profile: true,
256
- root: true,
257
- },
297
+ assert(bobAccountLoadedFromAlice);
298
+
299
+ expect(bobAccountLoadedFromAlice.profile.name).toBe("Bob");
300
+ expect(bobAccountLoadedFromAlice.root.name).toBe("Bob");
258
301
  });
259
302
 
260
- assert(bobAccountLoadedFromAlice);
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
+ });
261
339
 
262
- expect(bobAccountLoadedFromAlice.profile.name).toBe("Bob");
263
- expect(bobAccountLoadedFromAlice.root.name).toBe("Bob");
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");
343
+ });
264
344
  });
@@ -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;