jazz-tools 0.13.31 → 0.14.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 (166) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/CHANGELOG.md +14 -3
  3. package/dist/auth/DemoAuth.d.ts.map +1 -1
  4. package/dist/auth/PassphraseAuth.d.ts +1 -3
  5. package/dist/auth/PassphraseAuth.d.ts.map +1 -1
  6. package/dist/{chunk-IJU4XPFS.js → chunk-2ASOGEYA.js} +3535 -3291
  7. package/dist/chunk-2ASOGEYA.js.map +1 -0
  8. package/dist/coValues/CoValueBase.d.ts +22 -0
  9. package/dist/coValues/CoValueBase.d.ts.map +1 -0
  10. package/dist/coValues/account.d.ts +12 -12
  11. package/dist/coValues/account.d.ts.map +1 -1
  12. package/dist/coValues/coFeed.d.ts +24 -25
  13. package/dist/coValues/coFeed.d.ts.map +1 -1
  14. package/dist/coValues/coList.d.ts +10 -13
  15. package/dist/coValues/coList.d.ts.map +1 -1
  16. package/dist/coValues/coMap.d.ts +32 -35
  17. package/dist/coValues/coMap.d.ts.map +1 -1
  18. package/dist/coValues/coPlainText.d.ts.map +1 -1
  19. package/dist/coValues/deepLoading.d.ts +17 -21
  20. package/dist/coValues/deepLoading.d.ts.map +1 -1
  21. package/dist/coValues/extensions/imageDef.d.ts +12 -11
  22. package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
  23. package/dist/coValues/group.d.ts +5 -9
  24. package/dist/coValues/group.d.ts.map +1 -1
  25. package/dist/coValues/inbox.d.ts +2 -3
  26. package/dist/coValues/inbox.d.ts.map +1 -1
  27. package/dist/coValues/interfaces.d.ts +8 -34
  28. package/dist/coValues/interfaces.d.ts.map +1 -1
  29. package/dist/coValues/profile.d.ts +4 -14
  30. package/dist/coValues/profile.d.ts.map +1 -1
  31. package/dist/coValues/registeredSchemas.d.ts +1 -3
  32. package/dist/coValues/registeredSchemas.d.ts.map +1 -1
  33. package/dist/coValues/schemaUnion.d.ts +6 -6
  34. package/dist/exports.d.ts +12 -16
  35. package/dist/exports.d.ts.map +1 -1
  36. package/dist/implementation/ContextManager.d.ts +1 -1
  37. package/dist/implementation/ContextManager.d.ts.map +1 -1
  38. package/dist/implementation/activeAccountContext.d.ts +1 -1
  39. package/dist/implementation/activeAccountContext.d.ts.map +1 -1
  40. package/dist/implementation/createContext.d.ts +10 -10
  41. package/dist/implementation/createContext.d.ts.map +1 -1
  42. package/dist/implementation/invites.d.ts +6 -6
  43. package/dist/implementation/invites.d.ts.map +1 -1
  44. package/dist/implementation/refs.d.ts +2 -2
  45. package/dist/implementation/refs.d.ts.map +1 -1
  46. package/dist/implementation/schema.d.ts +21 -28
  47. package/dist/implementation/schema.d.ts.map +1 -1
  48. package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +9 -0
  49. package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -0
  50. package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +28 -0
  51. package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -0
  52. package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +65 -0
  53. package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -0
  54. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +28 -0
  55. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -0
  56. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -0
  57. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -0
  58. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +41 -0
  59. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -0
  60. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +35 -0
  61. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -0
  62. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +9 -0
  63. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -0
  64. package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +20 -0
  65. package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -0
  66. package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +18 -0
  67. package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -0
  68. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +24 -0
  69. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -0
  70. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +21 -0
  71. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -0
  72. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +29 -0
  73. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -0
  74. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +29 -0
  75. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -0
  76. package/dist/implementation/zodSchema/unionUtils.d.ts +6 -0
  77. package/dist/implementation/zodSchema/unionUtils.d.ts.map +1 -0
  78. package/dist/implementation/zodSchema/zodCo.d.ts +35 -0
  79. package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -0
  80. package/dist/implementation/zodSchema/zodSchema.d.ts +38 -0
  81. package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -0
  82. package/dist/index.js +295 -10
  83. package/dist/index.js.map +1 -1
  84. package/dist/internal.d.ts +34 -0
  85. package/dist/internal.d.ts.map +1 -1
  86. package/dist/subscribe/SubscriptionScope.d.ts +1 -2
  87. package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
  88. package/dist/subscribe/utils.d.ts +2 -2
  89. package/dist/subscribe/utils.d.ts.map +1 -1
  90. package/dist/testing.d.ts +10 -8
  91. package/dist/testing.d.ts.map +1 -1
  92. package/dist/testing.js +1 -1
  93. package/dist/testing.js.map +1 -1
  94. package/dist/tests/utils.d.ts +6 -2
  95. package/dist/tests/utils.d.ts.map +1 -1
  96. package/dist/types.d.ts +1 -7
  97. package/dist/types.d.ts.map +1 -1
  98. package/package.json +3 -2
  99. package/src/auth/DemoAuth.ts +1 -2
  100. package/src/auth/PassphraseAuth.ts +1 -1
  101. package/src/coValues/CoValueBase.ts +83 -0
  102. package/src/coValues/account.ts +53 -43
  103. package/src/coValues/coFeed.ts +65 -83
  104. package/src/coValues/coList.ts +28 -21
  105. package/src/coValues/coMap.ts +54 -38
  106. package/src/coValues/coPlainText.ts +4 -1
  107. package/src/coValues/deepLoading.ts +35 -43
  108. package/src/coValues/extensions/imageDef.ts +21 -19
  109. package/src/coValues/group.ts +37 -38
  110. package/src/coValues/inbox.ts +24 -11
  111. package/src/coValues/interfaces.ts +29 -93
  112. package/src/coValues/profile.ts +12 -13
  113. package/src/coValues/registeredSchemas.ts +1 -3
  114. package/src/coValues/schemaUnion.ts +6 -6
  115. package/src/exports.ts +47 -25
  116. package/src/implementation/activeAccountContext.ts +1 -1
  117. package/src/implementation/createContext.ts +39 -24
  118. package/src/implementation/invites.ts +15 -12
  119. package/src/implementation/refs.ts +6 -4
  120. package/src/implementation/schema.ts +22 -34
  121. package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +101 -0
  122. package/src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +191 -0
  123. package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +102 -0
  124. package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +70 -0
  125. package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +59 -0
  126. package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +126 -0
  127. package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +98 -0
  128. package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +9 -0
  129. package/src/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +27 -0
  130. package/src/implementation/zodSchema/schemaTypes/RichTextSchema.ts +25 -0
  131. package/src/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +61 -0
  132. package/src/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +77 -0
  133. package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +90 -0
  134. package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +103 -0
  135. package/src/implementation/zodSchema/unionUtils.ts +139 -0
  136. package/src/implementation/zodSchema/zodCo.ts +409 -0
  137. package/src/implementation/zodSchema/zodSchema.ts +116 -0
  138. package/src/internal.ts +38 -0
  139. package/src/subscribe/SubscriptionScope.ts +3 -1
  140. package/src/subscribe/utils.ts +7 -2
  141. package/src/testing.ts +14 -16
  142. package/src/tests/ContextManager.test.ts +73 -47
  143. package/src/tests/DemoAuth.test.ts +1 -1
  144. package/src/tests/account.test.ts +6 -9
  145. package/src/tests/coFeed.test.ts +102 -63
  146. package/src/tests/coList.test.ts +82 -95
  147. package/src/tests/coMap.record.test.ts +53 -87
  148. package/src/tests/coMap.test.ts +297 -312
  149. package/src/tests/coPlainText.test.ts +19 -39
  150. package/src/tests/createContext.test.ts +33 -15
  151. package/src/tests/deepLoading.test.ts +196 -179
  152. package/src/tests/groupsAndAccounts.test.ts +81 -72
  153. package/src/tests/imageDef.test.ts +22 -13
  154. package/src/tests/inbox.test.ts +36 -29
  155. package/src/tests/load.test.ts +10 -10
  156. package/src/tests/patterns/requestToJoin.test.ts +31 -31
  157. package/src/tests/schema.test.ts +37 -38
  158. package/src/tests/schemaUnion.test.ts +54 -64
  159. package/src/tests/subscribe.test.ts +118 -116
  160. package/src/tests/testing.test.ts +33 -33
  161. package/src/tests/utils.ts +3 -2
  162. package/src/types.ts +1 -8
  163. package/dist/chunk-IJU4XPFS.js.map +0 -1
  164. package/dist/tests/deepLoading.test-d.d.ts +0 -2
  165. package/dist/tests/deepLoading.test-d.d.ts.map +0 -1
  166. package/src/tests/deepLoading.test-d.ts +0 -393
@@ -14,14 +14,20 @@ import {
14
14
  CoMap,
15
15
  FileStream,
16
16
  Group,
17
- co,
17
+ coField,
18
18
  cojsonInternals,
19
+ z,
19
20
  } from "../index.js";
20
21
  import {
22
+ CoMapInstance,
21
23
  ID,
24
+ InstanceOrPrimitiveOfSchema,
25
+ Loaded,
22
26
  Resolved,
27
+ co,
23
28
  createCoValueObservable,
24
29
  subscribeToCoValue,
30
+ zodSchemaToCoSchema,
25
31
  } from "../internal.js";
26
32
  import {
27
33
  createJazzTestAccount,
@@ -32,30 +38,29 @@ import { setupAccount, waitFor } from "./utils.js";
32
38
 
33
39
  cojsonInternals.setCoValueLoadingRetryDelay(300);
34
40
 
35
- class ChatRoom extends CoMap {
36
- messages = co.ref(MessagesList);
37
- name = co.string;
38
- }
41
+ const ReactionsFeed = co.feed(z.string());
39
42
 
40
- class Message extends CoMap {
41
- text = co.string;
42
- reactions = co.ref(ReactionsStream);
43
- attachment = co.optional.ref(FileStream);
44
- }
43
+ const Message = co.map({
44
+ text: z.string(),
45
+ reactions: ReactionsFeed,
46
+ attachment: z.optional(co.fileStream()),
47
+ });
45
48
 
46
- class MessagesList extends CoList.Of(co.ref(Message)) {}
47
- class ReactionsStream extends CoFeed.Of(co.string) {}
49
+ const ChatRoom = co.map({
50
+ messages: co.list(Message),
51
+ name: z.string(),
52
+ });
48
53
 
49
54
  function createChatRoom(me: Account | Group, name: string) {
50
55
  return ChatRoom.create(
51
- { messages: MessagesList.create([], { owner: me }), name },
56
+ { messages: co.list(Message).create([], { owner: me }), name },
52
57
  { owner: me },
53
58
  );
54
59
  }
55
60
 
56
61
  function createMessage(me: Account | Group, text: string) {
57
62
  return Message.create(
58
- { text, reactions: ReactionsStream.create([], { owner: me }) },
63
+ { text, reactions: ReactionsFeed.create([], { owner: me }) },
59
64
  { owner: me },
60
65
  );
61
66
  }
@@ -76,10 +81,10 @@ describe("subscribeToCoValue", () => {
76
81
  const chatRoom = createChatRoom(me, "General");
77
82
  const updateFn = vi.fn();
78
83
 
79
- let result = null as Resolved<ChatRoom, {}> | null;
84
+ let result = null as Loaded<typeof ChatRoom, true> | null;
80
85
 
81
86
  const unsubscribe = subscribeToCoValue(
82
- ChatRoom,
87
+ zodSchemaToCoSchema(ChatRoom),
83
88
  chatRoom.id,
84
89
  { loadAs: meOnSecondPeer },
85
90
  (value) => {
@@ -123,10 +128,10 @@ describe("subscribeToCoValue", () => {
123
128
  const chatRoom = createChatRoom(me, "General");
124
129
  const updateFn = vi.fn();
125
130
 
126
- let result = null as Resolved<ChatRoom, {}> | null;
131
+ let result = null as Loaded<typeof ChatRoom, {}> | null;
127
132
 
128
133
  const unsubscribe = subscribeToCoValue(
129
- ChatRoom,
134
+ zodSchemaToCoSchema(ChatRoom),
130
135
  chatRoom.id,
131
136
  {
132
137
  loadAs: meOnSecondPeer,
@@ -167,7 +172,7 @@ describe("subscribeToCoValue", () => {
167
172
  messages.push(createMessage(me, "Hello"));
168
173
 
169
174
  const unsubscribe = subscribeToCoValue(
170
- ChatRoom,
175
+ zodSchemaToCoSchema(ChatRoom),
171
176
  chatRoom.id,
172
177
  {
173
178
  loadAs: meOnSecondPeer,
@@ -210,7 +215,7 @@ describe("subscribeToCoValue", () => {
210
215
  const updateFn = vi.fn();
211
216
 
212
217
  const unsubscribe = subscribeToCoValue(
213
- ChatRoom,
218
+ zodSchemaToCoSchema(ChatRoom),
214
219
  chatRoom.id,
215
220
  {
216
221
  loadAs: meOnSecondPeer,
@@ -258,8 +263,8 @@ describe("subscribeToCoValue", () => {
258
263
 
259
264
  const updateFn = vi.fn();
260
265
 
261
- const updates = [] as Resolved<
262
- ChatRoom,
266
+ const updates = [] as Loaded<
267
+ typeof ChatRoom,
263
268
  {
264
269
  messages: {
265
270
  $each: {
@@ -270,7 +275,7 @@ describe("subscribeToCoValue", () => {
270
275
  >[];
271
276
 
272
277
  const unsubscribe = subscribeToCoValue(
273
- ChatRoom,
278
+ zodSchemaToCoSchema(ChatRoom),
274
279
  chatRoom.id,
275
280
  {
276
281
  loadAs: meOnSecondPeer,
@@ -341,7 +346,7 @@ describe("subscribeToCoValue", () => {
341
346
  const updateFn = vi.fn();
342
347
 
343
348
  const unsubscribe = subscribeToCoValue(
344
- ChatRoom,
349
+ zodSchemaToCoSchema(ChatRoom),
345
350
  chatRoom.id,
346
351
  {
347
352
  loadAs: meOnSecondPeer,
@@ -384,11 +389,11 @@ describe("subscribeToCoValue", () => {
384
389
  });
385
390
 
386
391
  it("should emit only once when loading a list of values", async () => {
387
- class TestMap extends CoMap {
388
- value = co.string;
389
- }
392
+ const TestMap = co.map({
393
+ value: z.string(),
394
+ });
390
395
 
391
- class TestList extends CoList.Of(co.ref(TestMap)) {}
396
+ const TestList = co.list(TestMap);
392
397
 
393
398
  const account = await createJazzTestAccount({
394
399
  isCurrentActiveAccount: true,
@@ -405,7 +410,7 @@ describe("subscribeToCoValue", () => {
405
410
  const updateFn = vi.fn();
406
411
 
407
412
  const unsubscribe = subscribeToCoValue(
408
- TestList,
413
+ zodSchemaToCoSchema(TestList),
409
414
  list.id,
410
415
  {
411
416
  loadAs: account,
@@ -428,11 +433,11 @@ describe("subscribeToCoValue", () => {
428
433
  });
429
434
 
430
435
  it("should emit when all the items become accessible", async () => {
431
- class TestMap extends CoMap {
432
- value = co.string;
433
- }
436
+ const TestMap = co.map({
437
+ value: z.string(),
438
+ });
434
439
 
435
- class TestList extends CoList.Of(co.ref(TestMap)) {}
440
+ const TestList = co.list(TestMap);
436
441
 
437
442
  const reader = await createJazzTestAccount({
438
443
  isCurrentActiveAccount: true,
@@ -458,7 +463,7 @@ describe("subscribeToCoValue", () => {
458
463
  everyone,
459
464
  );
460
465
 
461
- let result = null as Resolved<TestList, { $each: true }> | null;
466
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
462
467
 
463
468
  const updateFn = vi.fn().mockImplementation((value) => {
464
469
  result = value;
@@ -466,7 +471,7 @@ describe("subscribeToCoValue", () => {
466
471
  const onUnauthorized = vi.fn();
467
472
 
468
473
  const unsubscribe = subscribeToCoValue(
469
- TestList,
474
+ zodSchemaToCoSchema(TestList),
470
475
  list.id,
471
476
  {
472
477
  loadAs: reader,
@@ -498,11 +503,11 @@ describe("subscribeToCoValue", () => {
498
503
  });
499
504
 
500
505
  it("should emit when all the items become available", async () => {
501
- class TestMap extends CoMap {
502
- value = co.string;
503
- }
506
+ const TestMap = co.map({
507
+ value: z.string(),
508
+ });
504
509
 
505
- class TestList extends CoList.Of(co.ref(TestMap)) {}
510
+ const TestList = co.list(TestMap);
506
511
 
507
512
  const reader = await createJazzTestAccount({
508
513
  isCurrentActiveAccount: true,
@@ -528,7 +533,7 @@ describe("subscribeToCoValue", () => {
528
533
  everyone,
529
534
  );
530
535
 
531
- let result = null as Resolved<TestList, { $each: true }> | null;
536
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
532
537
 
533
538
  const updateFn = vi.fn().mockImplementation((value) => {
534
539
  result = value;
@@ -537,7 +542,7 @@ describe("subscribeToCoValue", () => {
537
542
  const onUnavailable = vi.fn();
538
543
 
539
544
  const unsubscribe = subscribeToCoValue(
540
- TestList,
545
+ zodSchemaToCoSchema(TestList),
541
546
  list.id,
542
547
  {
543
548
  loadAs: reader,
@@ -573,12 +578,12 @@ describe("subscribeToCoValue", () => {
573
578
  expect(updateFn).toHaveBeenCalledTimes(2);
574
579
  });
575
580
 
576
- it("should handle null values in lists with required refs", async () => {
577
- class TestMap extends CoMap {
578
- value = co.string;
579
- }
581
+ it("should handle undefined values in lists with required refs", async () => {
582
+ const TestMap = co.map({
583
+ value: z.string(),
584
+ });
580
585
 
581
- class TestList extends CoList.Of(co.ref(TestMap)) {}
586
+ const TestList = co.list(TestMap);
582
587
 
583
588
  const reader = await createJazzTestAccount({
584
589
  isCurrentActiveAccount: true,
@@ -593,8 +598,8 @@ describe("subscribeToCoValue", () => {
593
598
 
594
599
  const list = TestList.create(
595
600
  [
596
- // TODO: This should be flagged as an error by typescript
597
- null,
601
+ // @ts-expect-error
602
+ undefined,
598
603
  TestMap.create({ value: "2" }, everyone),
599
604
  TestMap.create({ value: "3" }, everyone),
600
605
  TestMap.create({ value: "4" }, everyone),
@@ -603,7 +608,7 @@ describe("subscribeToCoValue", () => {
603
608
  everyone,
604
609
  );
605
610
 
606
- let result = null as Resolved<TestList, { $each: true }> | null;
611
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
607
612
 
608
613
  const updateFn = vi.fn().mockImplementation((value) => {
609
614
  result = value;
@@ -612,7 +617,7 @@ describe("subscribeToCoValue", () => {
612
617
  const onUnavailable = vi.fn();
613
618
 
614
619
  const unsubscribe = subscribeToCoValue(
615
- TestList,
620
+ zodSchemaToCoSchema(TestList),
616
621
  list.id,
617
622
  {
618
623
  loadAs: reader,
@@ -644,12 +649,12 @@ describe("subscribeToCoValue", () => {
644
649
  expect(updateFn).toHaveBeenCalledTimes(1);
645
650
  });
646
651
 
647
- it("should handle null values in lists with optional refs", async () => {
648
- class TestMap extends CoMap {
649
- value = co.string;
650
- }
652
+ it("should handle undefined values in lists with optional refs", async () => {
653
+ const TestMap = co.map({
654
+ value: z.string(),
655
+ });
651
656
 
652
- class TestList extends CoList.Of(co.optional.ref(TestMap)) {}
657
+ const TestList = co.list(z.optional(TestMap));
653
658
 
654
659
  const reader = await createJazzTestAccount({
655
660
  isCurrentActiveAccount: true,
@@ -664,7 +669,7 @@ describe("subscribeToCoValue", () => {
664
669
 
665
670
  const list = TestList.create(
666
671
  [
667
- null,
672
+ undefined,
668
673
  TestMap.create({ value: "2" }, everyone),
669
674
  TestMap.create({ value: "3" }, everyone),
670
675
  TestMap.create({ value: "4" }, everyone),
@@ -673,7 +678,7 @@ describe("subscribeToCoValue", () => {
673
678
  everyone,
674
679
  );
675
680
 
676
- let result = null as Resolved<TestList, { $each: true }> | null;
681
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
677
682
 
678
683
  const updateFn = vi.fn().mockImplementation((value) => {
679
684
  result = value;
@@ -682,7 +687,7 @@ describe("subscribeToCoValue", () => {
682
687
  const onUnavailable = vi.fn();
683
688
 
684
689
  const unsubscribe = subscribeToCoValue(
685
- TestList,
690
+ zodSchemaToCoSchema(TestList),
686
691
  list.id,
687
692
  {
688
693
  loadAs: reader,
@@ -703,17 +708,17 @@ describe("subscribeToCoValue", () => {
703
708
 
704
709
  assert(result);
705
710
 
706
- expect(result[0]).toBeNull();
711
+ expect(result[0]).toBeUndefined();
707
712
 
708
713
  expect(updateFn).toHaveBeenCalledTimes(1);
709
714
  });
710
715
 
711
- it("should unsubscribe from a nested ref when the value is set to null", async () => {
712
- class TestMap extends CoMap {
713
- value = co.string;
714
- }
716
+ it("should unsubscribe from a nested ref when the value is set to undefined", async () => {
717
+ const TestMap = co.map({
718
+ value: z.string(),
719
+ });
715
720
 
716
- class TestList extends CoList.Of(co.optional.ref(TestMap)) {}
721
+ const TestList = co.list(z.optional(TestMap));
717
722
 
718
723
  const creator = await createJazzTestAccount({
719
724
  isCurrentActiveAccount: true,
@@ -727,14 +732,14 @@ describe("subscribeToCoValue", () => {
727
732
  creator,
728
733
  );
729
734
 
730
- let result = null as Resolved<TestList, { $each: true }> | null;
735
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
731
736
 
732
737
  const updateFn = vi.fn().mockImplementation((value) => {
733
738
  result = value;
734
739
  });
735
740
 
736
741
  const unsubscribe = subscribeToCoValue(
737
- TestList,
742
+ zodSchemaToCoSchema(TestList),
738
743
  list.id,
739
744
  {
740
745
  loadAs: creator,
@@ -759,14 +764,14 @@ describe("subscribeToCoValue", () => {
759
764
 
760
765
  updateFn.mockClear();
761
766
 
762
- list[0] = null;
767
+ list[0] = undefined;
763
768
 
764
769
  await waitFor(() => {
765
770
  expect(updateFn).toHaveBeenCalled();
766
771
  });
767
772
 
768
773
  assert(result);
769
- expect(result[0]).toBeNull();
774
+ expect(result[0]).toBeUndefined();
770
775
 
771
776
  updateFn.mockClear();
772
777
 
@@ -776,11 +781,11 @@ describe("subscribeToCoValue", () => {
776
781
  });
777
782
 
778
783
  it("should unsubscribe from a nested ref when the value is changed to a different ref", async () => {
779
- class TestMap extends CoMap {
780
- value = co.string;
781
- }
784
+ const TestMap = co.map({
785
+ value: z.string(),
786
+ });
782
787
 
783
- class TestList extends CoList.Of(co.ref(TestMap)) {}
788
+ const TestList = co.list(TestMap);
784
789
 
785
790
  const creator = await createJazzTestAccount({
786
791
  isCurrentActiveAccount: true,
@@ -794,14 +799,14 @@ describe("subscribeToCoValue", () => {
794
799
  creator,
795
800
  );
796
801
 
797
- let result = null as Resolved<TestList, { $each: true }> | null;
802
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
798
803
 
799
804
  const updateFn = vi.fn().mockImplementation((value) => {
800
805
  result = value;
801
806
  });
802
807
 
803
808
  const unsubscribe = subscribeToCoValue(
804
- TestList,
809
+ zodSchemaToCoSchema(TestList),
805
810
  list.id,
806
811
  {
807
812
  loadAs: creator,
@@ -850,9 +855,9 @@ describe("subscribeToCoValue", () => {
850
855
  });
851
856
 
852
857
  it("should emit on group changes, even when the amount of totalValidTransactions doesn't change but the content does", async () => {
853
- class Person extends CoMap {
854
- name = co.string;
855
- }
858
+ const Person = co.map({
859
+ name: z.string(),
860
+ });
856
861
 
857
862
  const creator = await createJazzTestAccount();
858
863
 
@@ -884,16 +889,13 @@ describe("subscribeToCoValue", () => {
884
889
  group.removeMember(writer1);
885
890
  group.addMember(writer2, "writer");
886
891
 
887
- let value: Resolved<Person, {}> | null = null as Resolved<
888
- Person,
889
- {}
890
- > | null;
892
+ let value = null as Loaded<typeof Person, {}> | null;
891
893
  const spy = vi.fn((update) => {
892
894
  value = update;
893
895
  });
894
896
 
895
897
  const unsubscribe = subscribeToCoValue(
896
- Person,
898
+ zodSchemaToCoSchema(Person),
897
899
  person.id,
898
900
  {
899
901
  loadAs: reader,
@@ -941,11 +943,11 @@ describe("subscribeToCoValue", () => {
941
943
  });
942
944
 
943
945
  it("errors on autoloaded values shouldn't block updates", async () => {
944
- class TestMap extends CoMap {
945
- value = co.string;
946
- }
946
+ const TestMap = co.map({
947
+ value: z.string(),
948
+ });
947
949
 
948
- class TestList extends CoList.Of(co.ref(TestMap)) {}
950
+ const TestList = co.list(TestMap);
949
951
 
950
952
  const reader = await createJazzTestAccount({
951
953
  isCurrentActiveAccount: true,
@@ -971,7 +973,7 @@ describe("subscribeToCoValue", () => {
971
973
  everyone,
972
974
  );
973
975
 
974
- let result = null as Resolved<TestList, { $each: true }> | null;
976
+ let result = null as Loaded<typeof TestList, { $each: true }> | null;
975
977
 
976
978
  const updateFn = vi.fn().mockImplementation((value) => {
977
979
  result = value;
@@ -980,7 +982,7 @@ describe("subscribeToCoValue", () => {
980
982
  const onUnavailable = vi.fn();
981
983
 
982
984
  const unsubscribe = subscribeToCoValue(
983
- TestList,
985
+ zodSchemaToCoSchema(TestList),
984
986
  list.id,
985
987
  {
986
988
  loadAs: reader,
@@ -1018,16 +1020,16 @@ describe("subscribeToCoValue", () => {
1018
1020
  });
1019
1021
 
1020
1022
  it("errors on autoloaded values shouldn't block updates, even when the error comes from a new ref", async () => {
1021
- class Dog extends CoMap {
1022
- name = co.string;
1023
- }
1023
+ const Dog = co.map({
1024
+ name: z.string(),
1025
+ });
1024
1026
 
1025
- class Person extends CoMap {
1026
- name = co.string;
1027
- dog = co.ref(Dog);
1028
- }
1027
+ const Person = co.map({
1028
+ name: z.string(),
1029
+ dog: Dog,
1030
+ });
1029
1031
 
1030
- class PersonList extends CoList.Of(co.ref(Person)) {}
1032
+ const PersonList = co.list(Person);
1031
1033
 
1032
1034
  const reader = await createJazzTestAccount({
1033
1035
  isCurrentActiveAccount: true,
@@ -1058,7 +1060,7 @@ describe("subscribeToCoValue", () => {
1058
1060
  everyone,
1059
1061
  );
1060
1062
 
1061
- let result = null as Resolved<PersonList, { $each: true }> | null;
1063
+ let result = null as Loaded<typeof PersonList, { $each: true }> | null;
1062
1064
 
1063
1065
  const updateFn = vi.fn().mockImplementation((value) => {
1064
1066
  result = value;
@@ -1067,7 +1069,7 @@ describe("subscribeToCoValue", () => {
1067
1069
  const onUnavailable = vi.fn();
1068
1070
 
1069
1071
  const unsubscribe = subscribeToCoValue(
1070
- PersonList,
1072
+ zodSchemaToCoSchema(PersonList),
1071
1073
  list.id,
1072
1074
  {
1073
1075
  loadAs: reader,
@@ -1114,16 +1116,16 @@ describe("subscribeToCoValue", () => {
1114
1116
  });
1115
1117
 
1116
1118
  it("autoload on $each resolve should work on all items", async () => {
1117
- class Dog extends CoMap {
1118
- name = co.string;
1119
- }
1119
+ const Dog = co.map({
1120
+ name: z.string(),
1121
+ });
1120
1122
 
1121
- class Person extends CoMap {
1122
- name = co.string;
1123
- dog = co.ref(Dog);
1124
- }
1123
+ const Person = co.map({
1124
+ name: z.string(),
1125
+ dog: Dog,
1126
+ });
1125
1127
 
1126
- class PersonList extends CoList.Of(co.ref(Person)) {}
1128
+ const PersonList = co.list(Person);
1127
1129
 
1128
1130
  const reader = await createJazzTestAccount({
1129
1131
  isCurrentActiveAccount: true,
@@ -1154,7 +1156,7 @@ describe("subscribeToCoValue", () => {
1154
1156
  everyone,
1155
1157
  );
1156
1158
 
1157
- let result = null as Resolved<PersonList, { $each: true }> | null;
1159
+ let result = null as Loaded<typeof PersonList, { $each: true }> | null;
1158
1160
 
1159
1161
  const updateFn = vi.fn().mockImplementation((value) => {
1160
1162
  result = value;
@@ -1163,7 +1165,7 @@ describe("subscribeToCoValue", () => {
1163
1165
  const onUnavailable = vi.fn();
1164
1166
 
1165
1167
  const unsubscribe = subscribeToCoValue(
1166
- PersonList,
1168
+ zodSchemaToCoSchema(PersonList),
1167
1169
  list.id,
1168
1170
  {
1169
1171
  loadAs: reader,
@@ -1199,9 +1201,9 @@ describe("subscribeToCoValue", () => {
1199
1201
  });
1200
1202
 
1201
1203
  describe("createCoValueObservable", () => {
1202
- class TestMap extends CoMap {
1203
- color = co.string;
1204
- }
1204
+ const TestMap = co.map({
1205
+ color: z.string(),
1206
+ });
1205
1207
 
1206
1208
  function createTestMap(me: Account | Group) {
1207
1209
  return TestMap.create({ color: "red" }, { owner: me });
@@ -1220,7 +1222,7 @@ describe("createCoValueObservable", () => {
1220
1222
  const mockListener = vi.fn();
1221
1223
 
1222
1224
  const unsubscribe = observable.subscribe(
1223
- TestMap,
1225
+ zodSchemaToCoSchema(TestMap),
1224
1226
  testMap.id,
1225
1227
  {
1226
1228
  loadAs: meOnSecondPeer,
@@ -1249,7 +1251,7 @@ describe("createCoValueObservable", () => {
1249
1251
  const mockListener = vi.fn();
1250
1252
 
1251
1253
  const unsubscribe = observable.subscribe(
1252
- TestMap,
1254
+ zodSchemaToCoSchema(TestMap),
1253
1255
  testMap.id,
1254
1256
  {
1255
1257
  loadAs: meOnSecondPeer,
@@ -1269,13 +1271,13 @@ describe("createCoValueObservable", () => {
1269
1271
  it("should return null if the coValue is not found", async () => {
1270
1272
  const { meOnSecondPeer } = await setupAccount();
1271
1273
  const observable = createCoValueObservable<
1272
- TestMap,
1273
- Resolved<TestMap, {}>
1274
+ typeof TestMap,
1275
+ Loaded<typeof TestMap, {}>
1274
1276
  >();
1275
1277
 
1276
1278
  const unsubscribe = observable.subscribe(
1277
1279
  TestMap,
1278
- "co_z123" as ID<TestMap>,
1280
+ "co_z123",
1279
1281
  { loadAs: meOnSecondPeer },
1280
1282
  () => {},
1281
1283
  );