jazz-tools 0.15.15 → 0.16.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 (217) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.d.ts +2 -2
  2. package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
  3. package/.svelte-kit/__package__/jazz.class.svelte.js +5 -5
  4. package/.svelte-kit/__package__/jazz.svelte.d.ts +2 -2
  5. package/.svelte-kit/__package__/jazz.svelte.d.ts.map +1 -1
  6. package/.turbo/turbo-build.log +46 -50
  7. package/CHANGELOG.md +35 -0
  8. package/dist/browser/index.d.ts +2 -2
  9. package/dist/browser/index.d.ts.map +1 -1
  10. package/dist/browser/index.js.map +1 -1
  11. package/dist/browser-media-images/index.d.ts +3 -1
  12. package/dist/browser-media-images/index.d.ts.map +1 -1
  13. package/dist/browser-media-images/index.js.map +1 -1
  14. package/dist/{chunk-4CFNXQE7.js → chunk-MLCNE3TL.js} +791 -698
  15. package/dist/chunk-MLCNE3TL.js.map +1 -0
  16. package/dist/index.js +363 -11
  17. package/dist/index.js.map +1 -1
  18. package/dist/react/hooks.d.ts +2 -2
  19. package/dist/react/hooks.d.ts.map +1 -1
  20. package/dist/react/index.js +2 -0
  21. package/dist/react/index.js.map +1 -1
  22. package/dist/react/testing.js +3 -1
  23. package/dist/react/testing.js.map +1 -1
  24. package/dist/react-core/hooks.d.ts +2 -2
  25. package/dist/react-core/hooks.d.ts.map +1 -1
  26. package/dist/react-core/index.js +3 -3
  27. package/dist/react-core/index.js.map +1 -1
  28. package/dist/react-native-core/hooks.d.ts +2 -2
  29. package/dist/react-native-core/hooks.d.ts.map +1 -1
  30. package/dist/react-native-core/index.js.map +1 -1
  31. package/dist/svelte/jazz.class.svelte.d.ts +2 -2
  32. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  33. package/dist/svelte/jazz.class.svelte.js +5 -5
  34. package/dist/svelte/jazz.svelte.d.ts +2 -2
  35. package/dist/svelte/jazz.svelte.d.ts.map +1 -1
  36. package/dist/testing.js +3 -3
  37. package/dist/testing.js.map +1 -1
  38. package/dist/tools/coValues/CoValueBase.d.ts +3 -13
  39. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  40. package/dist/tools/coValues/account.d.ts +2 -2
  41. package/dist/tools/coValues/account.d.ts.map +1 -1
  42. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  43. package/dist/tools/coValues/coList.d.ts.map +1 -1
  44. package/dist/tools/coValues/coMap.d.ts +5 -18
  45. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  46. package/dist/tools/coValues/deepLoading.d.ts +4 -1
  47. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  48. package/dist/tools/coValues/extensions/imageDef.d.ts +4 -7
  49. package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
  50. package/dist/tools/coValues/group.d.ts +1 -0
  51. package/dist/tools/coValues/group.d.ts.map +1 -1
  52. package/dist/tools/coValues/inbox.d.ts +2 -2
  53. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  54. package/dist/tools/coValues/interfaces.d.ts +58 -17
  55. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  56. package/dist/tools/coValues/request.d.ts +82 -0
  57. package/dist/tools/coValues/request.d.ts.map +1 -0
  58. package/dist/tools/coValues/schemaUnion.d.ts +5 -1
  59. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  60. package/dist/tools/exports.d.ts +4 -3
  61. package/dist/tools/exports.d.ts.map +1 -1
  62. package/dist/tools/implementation/createContext.d.ts +4 -4
  63. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  64. package/dist/tools/implementation/invites.d.ts +2 -2
  65. package/dist/tools/implementation/invites.d.ts.map +1 -1
  66. package/dist/tools/implementation/schemaUtils.d.ts +8 -0
  67. package/dist/tools/implementation/schemaUtils.d.ts.map +1 -0
  68. package/dist/tools/implementation/zodSchema/coExport.d.ts +11 -1
  69. package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
  70. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts +22 -0
  71. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -0
  72. package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts +10 -0
  73. package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -0
  74. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +11 -11
  75. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  76. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +34 -24
  77. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  78. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +16 -14
  79. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  80. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +23 -17
  81. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  82. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +24 -16
  83. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  84. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +20 -9
  85. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
  86. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +18 -12
  87. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  88. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +18 -0
  89. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -0
  90. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +14 -9
  91. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  92. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +14 -9
  93. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  94. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +14 -9
  95. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  96. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +15 -13
  97. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  98. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +12 -15
  99. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  100. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +17 -20
  101. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
  102. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +17 -20
  103. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
  104. package/dist/tools/implementation/zodSchema/unionUtils.d.ts +3 -5
  105. package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
  106. package/dist/tools/implementation/zodSchema/zodCo.d.ts +10 -8
  107. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  108. package/dist/tools/implementation/zodSchema/zodReExport.d.ts +4 -8
  109. package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
  110. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +21 -30
  111. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  112. package/dist/tools/internal.d.ts +3 -2
  113. package/dist/tools/internal.d.ts.map +1 -1
  114. package/dist/tools/lib/id.d.ts +2 -0
  115. package/dist/tools/lib/id.d.ts.map +1 -0
  116. package/dist/tools/lib/utilityTypes.d.ts +10 -0
  117. package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
  118. package/dist/tools/subscribe/SubscriptionScope.d.ts +3 -2
  119. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  120. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  121. package/dist/tools/testing.d.ts +2 -2
  122. package/dist/tools/testing.d.ts.map +1 -1
  123. package/dist/tools/tests/exportImport.test.d.ts +2 -0
  124. package/dist/tools/tests/exportImport.test.d.ts.map +1 -0
  125. package/dist/tools/tests/request.test.d.ts +2 -0
  126. package/dist/tools/tests/request.test.d.ts.map +1 -0
  127. package/dist/worker/index.d.ts.map +1 -1
  128. package/dist/worker/index.js +2 -2
  129. package/dist/worker/index.js.map +1 -1
  130. package/package.json +7 -6
  131. package/src/browser/index.ts +2 -4
  132. package/src/browser-media-images/index.ts +1 -1
  133. package/src/react/hooks.tsx +2 -2
  134. package/src/react-core/hooks.ts +6 -6
  135. package/src/react-core/tests/useAccount.test.ts +2 -2
  136. package/src/react-core/tests/useCoState.test.ts +3 -2
  137. package/src/react-native-core/hooks.tsx +2 -2
  138. package/src/svelte/jazz.class.svelte.ts +10 -7
  139. package/src/svelte/jazz.svelte.ts +2 -2
  140. package/src/tools/coValues/CoValueBase.ts +8 -20
  141. package/src/tools/coValues/account.ts +18 -14
  142. package/src/tools/coValues/coFeed.ts +0 -4
  143. package/src/tools/coValues/coList.ts +7 -9
  144. package/src/tools/coValues/coMap.ts +1 -6
  145. package/src/tools/coValues/coPlainText.ts +4 -4
  146. package/src/tools/coValues/deepLoading.ts +4 -1
  147. package/src/tools/coValues/extensions/imageDef.ts +3 -3
  148. package/src/tools/coValues/group.ts +1 -0
  149. package/src/tools/coValues/inbox.ts +8 -7
  150. package/src/tools/coValues/interfaces.ts +177 -69
  151. package/src/tools/coValues/request.ts +633 -0
  152. package/src/tools/coValues/schemaUnion.ts +8 -4
  153. package/src/tools/exports.ts +11 -14
  154. package/src/tools/implementation/createContext.ts +9 -9
  155. package/src/tools/implementation/invites.ts +2 -2
  156. package/src/tools/implementation/schemaUtils.ts +18 -0
  157. package/src/tools/implementation/zodSchema/coExport.ts +14 -0
  158. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +156 -0
  159. package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +133 -0
  160. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +36 -17
  161. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +101 -52
  162. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +54 -50
  163. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +54 -46
  164. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +187 -137
  165. package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +29 -27
  166. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +28 -18
  167. package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +18 -0
  168. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +45 -36
  169. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +47 -35
  170. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +43 -30
  171. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +28 -23
  172. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +28 -25
  173. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +86 -78
  174. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +91 -82
  175. package/src/tools/implementation/zodSchema/unionUtils.ts +47 -51
  176. package/src/tools/implementation/zodSchema/zodCo.ts +42 -75
  177. package/src/tools/implementation/zodSchema/zodReExport.ts +44 -24
  178. package/src/tools/implementation/zodSchema/zodSchema.ts +64 -102
  179. package/src/tools/internal.ts +3 -2
  180. package/src/tools/lib/id.ts +3 -0
  181. package/src/tools/lib/utilityTypes.ts +7 -0
  182. package/src/tools/subscribe/SubscriptionScope.ts +10 -1
  183. package/src/tools/subscribe/utils.ts +4 -2
  184. package/src/tools/testing.ts +4 -4
  185. package/src/tools/tests/ContextManager.test.ts +8 -9
  186. package/src/tools/tests/account.test.ts +65 -3
  187. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +38 -0
  188. package/src/tools/tests/coDiscriminatedUnion.test.ts +219 -1
  189. package/src/tools/tests/coFeed.test-d.ts +4 -3
  190. package/src/tools/tests/coList.test-d.ts +32 -3
  191. package/src/tools/tests/coList.test.ts +20 -2
  192. package/src/tools/tests/coMap.record.test-d.ts +31 -3
  193. package/src/tools/tests/coMap.record.test.ts +9 -9
  194. package/src/tools/tests/coMap.test-d.ts +8 -8
  195. package/src/tools/tests/coMap.test.ts +19 -5
  196. package/src/tools/tests/coOptional.test.ts +63 -1
  197. package/src/tools/tests/createContext.test.ts +7 -9
  198. package/src/tools/tests/deepLoading.test.ts +4 -10
  199. package/src/tools/tests/exportImport.test.ts +526 -0
  200. package/src/tools/tests/groupsAndAccounts.test.ts +5 -4
  201. package/src/tools/tests/inbox.test.ts +3 -2
  202. package/src/tools/tests/load.test.ts +3 -29
  203. package/src/tools/tests/request.test.ts +951 -0
  204. package/src/tools/tests/schemaUnion.test.ts +2 -2
  205. package/src/tools/tests/subscribe.test.ts +22 -114
  206. package/src/tools/tests/testing.test.ts +6 -6
  207. package/src/tools/tests/zod.test-d.ts +27 -0
  208. package/src/tools/tests/zod.test.ts +50 -45
  209. package/src/worker/index.ts +0 -1
  210. package/tsup.config.ts +0 -2
  211. package/dist/chunk-4CFNXQE7.js.map +0 -1
  212. package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +0 -12
  213. package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +0 -1
  214. package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +0 -9
  215. package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +0 -1
  216. package/src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +0 -172
  217. package/src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +0 -218
@@ -4,8 +4,8 @@ import {
4
4
  Account,
5
5
  CryptoProvider,
6
6
  Loaded,
7
- anySchemaToCoSchema,
8
7
  co,
8
+ coValueClassFromCoValueClassOrSchema,
9
9
  subscribeToCoValue,
10
10
  z,
11
11
  } from "../exports.js";
@@ -93,7 +93,7 @@ describe("SchemaUnion", () => {
93
93
  );
94
94
  let currentValue = "Submit";
95
95
  const unsubscribe = subscribeToCoValue(
96
- anySchemaToCoSchema(WidgetUnion),
96
+ coValueClassFromCoValueClassOrSchema(WidgetUnion),
97
97
  buttonWidget.id,
98
98
  { loadAs: me, syncResolution: true },
99
99
  (value: Loaded<typeof WidgetUnion>) => {
@@ -10,9 +10,8 @@ import {
10
10
  import { Account, Group, cojsonInternals, z } from "../index.js";
11
11
  import {
12
12
  Loaded,
13
- anySchemaToCoSchema,
14
13
  co,
15
- createCoValueObservable,
14
+ coValueClassFromCoValueClassOrSchema,
16
15
  subscribeToCoValue,
17
16
  } from "../internal.js";
18
17
  import {
@@ -70,7 +69,7 @@ describe("subscribeToCoValue", () => {
70
69
  let result = null as Loaded<typeof ChatRoom, true> | null;
71
70
 
72
71
  const unsubscribe = subscribeToCoValue(
73
- anySchemaToCoSchema(ChatRoom),
72
+ coValueClassFromCoValueClassOrSchema(ChatRoom),
74
73
  chatRoom.id,
75
74
  { loadAs: meOnSecondPeer },
76
75
  (value) => {
@@ -117,7 +116,7 @@ describe("subscribeToCoValue", () => {
117
116
  let result = null as Loaded<typeof ChatRoom, {}> | null;
118
117
 
119
118
  const unsubscribe = subscribeToCoValue(
120
- anySchemaToCoSchema(ChatRoom),
119
+ coValueClassFromCoValueClassOrSchema(ChatRoom),
121
120
  chatRoom.id,
122
121
  {
123
122
  loadAs: meOnSecondPeer,
@@ -158,7 +157,7 @@ describe("subscribeToCoValue", () => {
158
157
  messages.push(createMessage(me, "Hello"));
159
158
 
160
159
  const unsubscribe = subscribeToCoValue(
161
- anySchemaToCoSchema(ChatRoom),
160
+ coValueClassFromCoValueClassOrSchema(ChatRoom),
162
161
  chatRoom.id,
163
162
  {
164
163
  loadAs: meOnSecondPeer,
@@ -201,7 +200,7 @@ describe("subscribeToCoValue", () => {
201
200
  const updateFn = vi.fn();
202
201
 
203
202
  const unsubscribe = subscribeToCoValue(
204
- anySchemaToCoSchema(ChatRoom),
203
+ coValueClassFromCoValueClassOrSchema(ChatRoom),
205
204
  chatRoom.id,
206
205
  {
207
206
  loadAs: meOnSecondPeer,
@@ -261,7 +260,7 @@ describe("subscribeToCoValue", () => {
261
260
  >[];
262
261
 
263
262
  const unsubscribe = subscribeToCoValue(
264
- anySchemaToCoSchema(ChatRoom),
263
+ coValueClassFromCoValueClassOrSchema(ChatRoom),
265
264
  chatRoom.id,
266
265
  {
267
266
  loadAs: meOnSecondPeer,
@@ -332,7 +331,7 @@ describe("subscribeToCoValue", () => {
332
331
  const updateFn = vi.fn();
333
332
 
334
333
  const unsubscribe = subscribeToCoValue(
335
- anySchemaToCoSchema(ChatRoom),
334
+ coValueClassFromCoValueClassOrSchema(ChatRoom),
336
335
  chatRoom.id,
337
336
  {
338
337
  loadAs: meOnSecondPeer,
@@ -396,7 +395,7 @@ describe("subscribeToCoValue", () => {
396
395
  const updateFn = vi.fn();
397
396
 
398
397
  const unsubscribe = subscribeToCoValue(
399
- anySchemaToCoSchema(TestList),
398
+ coValueClassFromCoValueClassOrSchema(TestList),
400
399
  list.id,
401
400
  {
402
401
  loadAs: account,
@@ -457,7 +456,7 @@ describe("subscribeToCoValue", () => {
457
456
  const onUnauthorized = vi.fn();
458
457
 
459
458
  const unsubscribe = subscribeToCoValue(
460
- anySchemaToCoSchema(TestList),
459
+ coValueClassFromCoValueClassOrSchema(TestList),
461
460
  list.id,
462
461
  {
463
462
  loadAs: reader,
@@ -528,7 +527,7 @@ describe("subscribeToCoValue", () => {
528
527
  const onUnavailable = vi.fn();
529
528
 
530
529
  const unsubscribe = subscribeToCoValue(
531
- anySchemaToCoSchema(TestList),
530
+ coValueClassFromCoValueClassOrSchema(TestList),
532
531
  list.id,
533
532
  {
534
533
  loadAs: reader,
@@ -603,7 +602,7 @@ describe("subscribeToCoValue", () => {
603
602
  const onUnavailable = vi.fn();
604
603
 
605
604
  const unsubscribe = subscribeToCoValue(
606
- anySchemaToCoSchema(TestList),
605
+ coValueClassFromCoValueClassOrSchema(TestList),
607
606
  list.id,
608
607
  {
609
608
  loadAs: reader,
@@ -673,7 +672,7 @@ describe("subscribeToCoValue", () => {
673
672
  const onUnavailable = vi.fn();
674
673
 
675
674
  const unsubscribe = subscribeToCoValue(
676
- anySchemaToCoSchema(TestList),
675
+ coValueClassFromCoValueClassOrSchema(TestList),
677
676
  list.id,
678
677
  {
679
678
  loadAs: reader,
@@ -725,7 +724,7 @@ describe("subscribeToCoValue", () => {
725
724
  });
726
725
 
727
726
  const unsubscribe = subscribeToCoValue(
728
- anySchemaToCoSchema(TestList),
727
+ coValueClassFromCoValueClassOrSchema(TestList),
729
728
  list.id,
730
729
  {
731
730
  loadAs: creator,
@@ -792,7 +791,7 @@ describe("subscribeToCoValue", () => {
792
791
  });
793
792
 
794
793
  const unsubscribe = subscribeToCoValue(
795
- anySchemaToCoSchema(TestList),
794
+ coValueClassFromCoValueClassOrSchema(TestList),
796
795
  list.id,
797
796
  {
798
797
  loadAs: creator,
@@ -881,7 +880,7 @@ describe("subscribeToCoValue", () => {
881
880
  });
882
881
 
883
882
  const unsubscribe = subscribeToCoValue(
884
- anySchemaToCoSchema(Person),
883
+ coValueClassFromCoValueClassOrSchema(Person),
885
884
  person.id,
886
885
  {
887
886
  loadAs: reader,
@@ -968,7 +967,7 @@ describe("subscribeToCoValue", () => {
968
967
  const onUnavailable = vi.fn();
969
968
 
970
969
  const unsubscribe = subscribeToCoValue(
971
- anySchemaToCoSchema(TestList),
970
+ coValueClassFromCoValueClassOrSchema(TestList),
972
971
  list.id,
973
972
  {
974
973
  loadAs: reader,
@@ -1055,7 +1054,7 @@ describe("subscribeToCoValue", () => {
1055
1054
  const onUnavailable = vi.fn();
1056
1055
 
1057
1056
  const unsubscribe = subscribeToCoValue(
1058
- anySchemaToCoSchema(PersonList),
1057
+ coValueClassFromCoValueClassOrSchema(PersonList),
1059
1058
  list.id,
1060
1059
  {
1061
1060
  loadAs: reader,
@@ -1151,7 +1150,7 @@ describe("subscribeToCoValue", () => {
1151
1150
  const onUnavailable = vi.fn();
1152
1151
 
1153
1152
  const unsubscribe = subscribeToCoValue(
1154
- anySchemaToCoSchema(PersonList),
1153
+ coValueClassFromCoValueClassOrSchema(PersonList),
1155
1154
  list.id,
1156
1155
  {
1157
1156
  loadAs: reader,
@@ -1188,13 +1187,14 @@ describe("subscribeToCoValue", () => {
1188
1187
  it("should subscribe to a large coValue", async () => {
1189
1188
  const syncServer = await setupJazzTestSync({ asyncPeers: true });
1190
1189
 
1190
+ const Data = co.list(z.string());
1191
1191
  const LargeDataset = co.map({
1192
1192
  metadata: z.object({
1193
1193
  name: z.string(),
1194
1194
  description: z.string(),
1195
1195
  createdAt: z.number(),
1196
1196
  }),
1197
- data: co.list(z.string()),
1197
+ data: Data,
1198
1198
  });
1199
1199
 
1200
1200
  const group = Group.create(syncServer);
@@ -1206,7 +1206,7 @@ describe("subscribeToCoValue", () => {
1206
1206
  "A dataset with many entries for testing large coValue subscription",
1207
1207
  createdAt: Date.now(),
1208
1208
  },
1209
- data: LargeDataset.def.shape.data.create([], group),
1209
+ data: Data.create([], group),
1210
1210
  },
1211
1211
  group,
1212
1212
  );
@@ -1234,7 +1234,7 @@ describe("subscribeToCoValue", () => {
1234
1234
 
1235
1235
  // Test subscribing to the large coValue
1236
1236
  const unsubscribe = subscribeToCoValue(
1237
- anySchemaToCoSchema(LargeDataset),
1237
+ coValueClassFromCoValueClassOrSchema(LargeDataset),
1238
1238
  largeMap.id,
1239
1239
  {
1240
1240
  loadAs: alice,
@@ -1277,95 +1277,3 @@ describe("subscribeToCoValue", () => {
1277
1277
  expect(result.data[chunks]).toBe("new entry");
1278
1278
  });
1279
1279
  });
1280
-
1281
- describe("createCoValueObservable", () => {
1282
- const TestMap = co.map({
1283
- color: z.string(),
1284
- });
1285
-
1286
- function createTestMap(me: Account | Group) {
1287
- return TestMap.create({ color: "red" }, { owner: me });
1288
- }
1289
-
1290
- it("should return undefined when there are no subscribers", async () => {
1291
- const observable = createCoValueObservable();
1292
-
1293
- expect(observable.getCurrentValue()).toBeUndefined();
1294
- });
1295
-
1296
- it("should update currentValue when subscribed", async () => {
1297
- const { me, meOnSecondPeer } = await setupAccount();
1298
- const testMap = createTestMap(me);
1299
- const observable = createCoValueObservable();
1300
- const mockListener = vi.fn();
1301
-
1302
- const unsubscribe = observable.subscribe(
1303
- anySchemaToCoSchema(TestMap),
1304
- testMap.id,
1305
- {
1306
- loadAs: meOnSecondPeer,
1307
- },
1308
- () => {
1309
- mockListener();
1310
- },
1311
- );
1312
-
1313
- testMap.color = "blue";
1314
-
1315
- await waitFor(() => mockListener.mock.calls.length > 0);
1316
-
1317
- expect(observable.getCurrentValue()).toMatchObject({
1318
- id: testMap.id,
1319
- color: "blue",
1320
- });
1321
-
1322
- unsubscribe();
1323
- });
1324
-
1325
- it("should reset to undefined after unsubscribe", async () => {
1326
- const { me, meOnSecondPeer } = await setupAccount();
1327
- const testMap = createTestMap(me);
1328
- const observable = createCoValueObservable();
1329
- const mockListener = vi.fn();
1330
-
1331
- const unsubscribe = observable.subscribe(
1332
- anySchemaToCoSchema(TestMap),
1333
- testMap.id,
1334
- {
1335
- loadAs: meOnSecondPeer,
1336
- },
1337
- () => {
1338
- mockListener();
1339
- },
1340
- );
1341
-
1342
- await waitFor(() => mockListener.mock.calls.length > 0);
1343
- expect(observable.getCurrentValue()).toBeDefined();
1344
-
1345
- unsubscribe();
1346
- expect(observable.getCurrentValue()).toBeUndefined();
1347
- });
1348
-
1349
- it("should return null if the coValue is not found", async () => {
1350
- const { meOnSecondPeer } = await setupAccount();
1351
- const observable = createCoValueObservable<
1352
- typeof TestMap,
1353
- Loaded<typeof TestMap, {}>
1354
- >();
1355
-
1356
- const unsubscribe = observable.subscribe(
1357
- TestMap,
1358
- "co_z123",
1359
- { loadAs: meOnSecondPeer },
1360
- () => {},
1361
- );
1362
-
1363
- expect(observable.getCurrentValue()).toBeUndefined();
1364
-
1365
- await waitFor(() => {
1366
- expect(observable.getCurrentValue()).toBeNull();
1367
- });
1368
-
1369
- unsubscribe();
1370
- });
1371
- });
@@ -1,5 +1,5 @@
1
1
  import { beforeEach, describe, expect, test } from "vitest";
2
- import { Account, CoMap, Group, co, z, zodSchemaToCoSchema } from "../exports";
2
+ import { Account, CoMap, Group, co, z } from "../exports";
3
3
  import { createJazzTestAccount, setupJazzTestSync } from "../testing";
4
4
 
5
5
  describe("Jazz Test Sync", () => {
@@ -43,7 +43,7 @@ describe("Jazz Test Sync", () => {
43
43
  });
44
44
 
45
45
  const account1 = await createJazzTestAccount({
46
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
46
+ AccountSchema: CustomAccount,
47
47
  isCurrentActiveAccount: true,
48
48
  });
49
49
 
@@ -69,12 +69,12 @@ describe("Jazz Test Sync", () => {
69
69
  });
70
70
 
71
71
  const account1 = await createJazzTestAccount({
72
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
72
+ AccountSchema: CustomAccount,
73
73
  isCurrentActiveAccount: true,
74
74
  });
75
75
 
76
76
  const account2 = await createJazzTestAccount({
77
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
77
+ AccountSchema: CustomAccount,
78
78
  isCurrentActiveAccount: false,
79
79
  });
80
80
 
@@ -91,11 +91,11 @@ describe("Jazz Test Sync", () => {
91
91
 
92
92
  const promise = Promise.all([
93
93
  createJazzTestAccount({
94
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
94
+ AccountSchema: CustomAccount,
95
95
  isCurrentActiveAccount: true,
96
96
  }),
97
97
  createJazzTestAccount({
98
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
98
+ AccountSchema: CustomAccount,
99
99
  isCurrentActiveAccount: true,
100
100
  }),
101
101
  ]);
@@ -15,6 +15,33 @@ describe("CoValue and Zod schema compatibility", () => {
15
15
  });
16
16
  });
17
17
 
18
+ test("cannot use z.optional with CoValue schemas", () => {
19
+ const Dog = co.map({
20
+ name: z.string(),
21
+ breed: z.string(),
22
+ });
23
+
24
+ const Person = co.map({
25
+ // @ts-expect-error: cannot use z.optional with a CoValue schema
26
+ pet: z.optional(Dog),
27
+ });
28
+ });
29
+
30
+ test("cannot use z.discriminatedUnion with CoValue schemas as values", () => {
31
+ const Dog = co.map({
32
+ type: z.literal("dog"),
33
+ });
34
+
35
+ const Cat = co.map({
36
+ type: z.literal("cat"),
37
+ });
38
+
39
+ const Person = co.map({
40
+ // @ts-expect-error: cannot use z.discriminatedUnion with a CoValue schema
41
+ pets: z.discriminatedUnion("type", [Dog, Cat]),
42
+ });
43
+ });
44
+
18
45
  test("cannot use z.union with CoValue schemas as values", () => {
19
46
  const Dog = co.map({
20
47
  type: z.literal("dog"),
@@ -368,51 +368,6 @@ describe("co.map and Zod schema compatibility", () => {
368
368
  // expect(failedMap.result).toEqual({ status: "failed", error: "error" });
369
369
  // });
370
370
 
371
- it("should handle discriminated unions of CoValues", () => {
372
- const Dog = co.map({
373
- type: z.literal("dog"),
374
- breed: z.string(),
375
- });
376
-
377
- const Cat = co.map({
378
- type: z.literal("cat"),
379
- name: z.string(),
380
- });
381
-
382
- const Person = co.map({
383
- pet: z.discriminatedUnion("type", [Dog, Cat]),
384
- });
385
-
386
- const person = Person.create({
387
- pet: Dog.create({ type: "dog", breed: "Labrador" }),
388
- });
389
-
390
- expect(person.pet).toEqual({ type: "dog", breed: "Labrador" });
391
-
392
- person.pet = Cat.create({ type: "cat", name: "Whiskers" });
393
-
394
- expect(person.pet).toEqual({ type: "cat", name: "Whiskers" });
395
- });
396
-
397
- it("should handle optional CoValues", () => {
398
- const Dog = co.map({
399
- name: z.string(),
400
- breed: z.string(),
401
- });
402
-
403
- const Person = co.map({
404
- pet: z.optional(Dog),
405
- });
406
-
407
- const person = Person.create({});
408
-
409
- expect(person.pet).toBeUndefined();
410
-
411
- person.pet = Dog.create({ name: "Rex", breed: "Labrador" });
412
-
413
- expect(person.pet).toEqual({ name: "Rex", breed: "Labrador" });
414
- });
415
-
416
371
  // it("should handle intersections", async () => {
417
372
  // const schema = co.map({
418
373
  // value: z.intersection(
@@ -503,3 +458,53 @@ describe("co.map and Zod schema compatibility", () => {
503
458
  });
504
459
  });
505
460
  });
461
+
462
+ describe("z.object() and CoValue schema compatibility", () => {
463
+ it("z.object() should throw an error when used with CoValue schema values", () => {
464
+ const coValueSchema = co.map({});
465
+ expect(() => z.object({ value: coValueSchema })).toThrow(
466
+ "z.object() does not support collaborative types as values. Use co.map() instead",
467
+ );
468
+ });
469
+
470
+ it("z.strictObject() should throw an error when used with CoValue schema values", () => {
471
+ const coValueSchema = co.map({});
472
+ expect(() => z.strictObject({ value: coValueSchema })).toThrow(
473
+ "z.strictObject() does not support collaborative types as values. Use co.map() instead",
474
+ );
475
+ });
476
+
477
+ it("z.object() should continue to work with cyclic references", () => {
478
+ const NoteItem = z.object({
479
+ type: z.literal("note"),
480
+ content: z.string(),
481
+ });
482
+
483
+ const ReferenceItem = z.object({
484
+ type: z.literal("reference"),
485
+ content: z.string(),
486
+
487
+ get child(): z.ZodDiscriminatedUnion<
488
+ [typeof NoteItem, typeof ReferenceItem]
489
+ > {
490
+ return ProjectContextItem;
491
+ },
492
+ });
493
+
494
+ const ProjectContextItem = z.discriminatedUnion("type", [
495
+ NoteItem,
496
+ ReferenceItem,
497
+ ]);
498
+
499
+ const referenceItem = ReferenceItem.parse({
500
+ type: "reference",
501
+ content: "Hello",
502
+ child: {
503
+ type: "note",
504
+ content: "Hello",
505
+ },
506
+ });
507
+
508
+ expect(referenceItem.child.type).toEqual("note");
509
+ });
510
+ });
@@ -7,7 +7,6 @@ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
7
7
  import {
8
8
  Account,
9
9
  AccountClass,
10
- AccountSchema,
11
10
  AnyAccountSchema,
12
11
  CoValueFromRaw,
13
12
  Inbox,
package/tsup.config.ts CHANGED
@@ -73,8 +73,6 @@ export default defineConfig([
73
73
  {
74
74
  ...cfg,
75
75
  entry: {
76
- index: "src/react/index.ts",
77
- testing: "src/react/testing.tsx",
78
76
  ssr: "src/react/ssr.ts",
79
77
  },
80
78
  outDir: "dist/react",