jazz-tools 0.15.16 → 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 (199) 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 -46
  7. package/CHANGELOG.md +25 -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-OSVAAVWQ.js → chunk-MLCNE3TL.js} +594 -598
  15. package/dist/chunk-MLCNE3TL.js.map +1 -0
  16. package/dist/index.js +8 -10
  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.map +1 -1
  21. package/dist/react-core/hooks.d.ts +2 -2
  22. package/dist/react-core/hooks.d.ts.map +1 -1
  23. package/dist/react-core/index.js +3 -3
  24. package/dist/react-core/index.js.map +1 -1
  25. package/dist/react-native-core/hooks.d.ts +2 -2
  26. package/dist/react-native-core/hooks.d.ts.map +1 -1
  27. package/dist/react-native-core/index.js.map +1 -1
  28. package/dist/svelte/jazz.class.svelte.d.ts +2 -2
  29. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  30. package/dist/svelte/jazz.class.svelte.js +5 -5
  31. package/dist/svelte/jazz.svelte.d.ts +2 -2
  32. package/dist/svelte/jazz.svelte.d.ts.map +1 -1
  33. package/dist/testing.js +3 -3
  34. package/dist/testing.js.map +1 -1
  35. package/dist/tools/coValues/CoValueBase.d.ts +3 -13
  36. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  37. package/dist/tools/coValues/account.d.ts +2 -2
  38. package/dist/tools/coValues/account.d.ts.map +1 -1
  39. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  40. package/dist/tools/coValues/coList.d.ts.map +1 -1
  41. package/dist/tools/coValues/coMap.d.ts +5 -18
  42. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  43. package/dist/tools/coValues/deepLoading.d.ts +4 -1
  44. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  45. package/dist/tools/coValues/extensions/imageDef.d.ts +4 -7
  46. package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
  47. package/dist/tools/coValues/inbox.d.ts +2 -2
  48. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  49. package/dist/tools/coValues/interfaces.d.ts +2 -17
  50. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  51. package/dist/tools/coValues/request.d.ts +2 -2
  52. package/dist/tools/coValues/request.d.ts.map +1 -1
  53. package/dist/tools/coValues/schemaUnion.d.ts +5 -1
  54. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  55. package/dist/tools/exports.d.ts +3 -3
  56. package/dist/tools/exports.d.ts.map +1 -1
  57. package/dist/tools/implementation/createContext.d.ts +4 -4
  58. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  59. package/dist/tools/implementation/invites.d.ts +2 -2
  60. package/dist/tools/implementation/invites.d.ts.map +1 -1
  61. package/dist/tools/implementation/schemaUtils.d.ts +8 -0
  62. package/dist/tools/implementation/schemaUtils.d.ts.map +1 -0
  63. package/dist/tools/implementation/zodSchema/coExport.d.ts +11 -1
  64. package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
  65. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts +22 -0
  66. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -0
  67. package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts +10 -0
  68. package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -0
  69. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +11 -11
  70. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  71. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +34 -24
  72. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  73. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +16 -14
  74. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  75. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +23 -17
  76. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  77. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +24 -16
  78. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  79. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +20 -9
  80. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
  81. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +18 -12
  82. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  83. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +18 -0
  84. package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -0
  85. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +14 -9
  86. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  87. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +14 -9
  88. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  89. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +14 -9
  90. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  91. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +15 -13
  92. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  93. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +12 -15
  94. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +17 -20
  96. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +17 -20
  98. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/unionUtils.d.ts +3 -5
  100. package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/zodCo.d.ts +10 -8
  102. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  103. package/dist/tools/implementation/zodSchema/zodReExport.d.ts +4 -8
  104. package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
  105. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +21 -30
  106. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  107. package/dist/tools/internal.d.ts +3 -2
  108. package/dist/tools/internal.d.ts.map +1 -1
  109. package/dist/tools/lib/utilityTypes.d.ts +10 -0
  110. package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
  111. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  112. package/dist/tools/testing.d.ts +2 -2
  113. package/dist/tools/testing.d.ts.map +1 -1
  114. package/dist/worker/index.d.ts.map +1 -1
  115. package/dist/worker/index.js +2 -2
  116. package/dist/worker/index.js.map +1 -1
  117. package/package.json +5 -5
  118. package/src/browser/index.ts +2 -4
  119. package/src/browser-media-images/index.ts +1 -1
  120. package/src/react/hooks.tsx +2 -2
  121. package/src/react-core/hooks.ts +6 -6
  122. package/src/react-core/tests/useAccount.test.ts +2 -2
  123. package/src/react-core/tests/useCoState.test.ts +3 -2
  124. package/src/react-native-core/hooks.tsx +2 -2
  125. package/src/svelte/jazz.class.svelte.ts +10 -7
  126. package/src/svelte/jazz.svelte.ts +2 -2
  127. package/src/tools/coValues/CoValueBase.ts +8 -20
  128. package/src/tools/coValues/account.ts +18 -14
  129. package/src/tools/coValues/coFeed.ts +0 -4
  130. package/src/tools/coValues/coList.ts +7 -9
  131. package/src/tools/coValues/coMap.ts +1 -6
  132. package/src/tools/coValues/coPlainText.ts +4 -4
  133. package/src/tools/coValues/deepLoading.ts +4 -1
  134. package/src/tools/coValues/extensions/imageDef.ts +3 -3
  135. package/src/tools/coValues/inbox.ts +4 -4
  136. package/src/tools/coValues/interfaces.ts +4 -71
  137. package/src/tools/coValues/request.ts +15 -13
  138. package/src/tools/coValues/schemaUnion.ts +8 -4
  139. package/src/tools/exports.ts +3 -14
  140. package/src/tools/implementation/createContext.ts +9 -9
  141. package/src/tools/implementation/invites.ts +2 -2
  142. package/src/tools/implementation/schemaUtils.ts +18 -0
  143. package/src/tools/implementation/zodSchema/coExport.ts +14 -0
  144. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +156 -0
  145. package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +133 -0
  146. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +36 -17
  147. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +101 -52
  148. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +54 -50
  149. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +54 -46
  150. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +187 -137
  151. package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +29 -27
  152. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +28 -18
  153. package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +18 -0
  154. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +45 -36
  155. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +47 -35
  156. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +43 -30
  157. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +28 -23
  158. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +28 -25
  159. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +86 -78
  160. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +91 -82
  161. package/src/tools/implementation/zodSchema/unionUtils.ts +47 -51
  162. package/src/tools/implementation/zodSchema/zodCo.ts +42 -75
  163. package/src/tools/implementation/zodSchema/zodReExport.ts +44 -24
  164. package/src/tools/implementation/zodSchema/zodSchema.ts +64 -102
  165. package/src/tools/internal.ts +3 -2
  166. package/src/tools/lib/utilityTypes.ts +7 -0
  167. package/src/tools/subscribe/utils.ts +4 -2
  168. package/src/tools/testing.ts +4 -4
  169. package/src/tools/tests/ContextManager.test.ts +8 -9
  170. package/src/tools/tests/account.test.ts +65 -3
  171. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +38 -0
  172. package/src/tools/tests/coDiscriminatedUnion.test.ts +219 -1
  173. package/src/tools/tests/coFeed.test-d.ts +4 -3
  174. package/src/tools/tests/coList.test-d.ts +32 -3
  175. package/src/tools/tests/coList.test.ts +20 -2
  176. package/src/tools/tests/coMap.record.test-d.ts +31 -3
  177. package/src/tools/tests/coMap.record.test.ts +9 -9
  178. package/src/tools/tests/coMap.test-d.ts +8 -8
  179. package/src/tools/tests/coMap.test.ts +19 -5
  180. package/src/tools/tests/coOptional.test.ts +63 -1
  181. package/src/tools/tests/createContext.test.ts +7 -9
  182. package/src/tools/tests/deepLoading.test.ts +4 -10
  183. package/src/tools/tests/exportImport.test.ts +2 -2
  184. package/src/tools/tests/groupsAndAccounts.test.ts +5 -4
  185. package/src/tools/tests/inbox.test.ts +3 -2
  186. package/src/tools/tests/load.test.ts +3 -29
  187. package/src/tools/tests/schemaUnion.test.ts +2 -2
  188. package/src/tools/tests/subscribe.test.ts +22 -114
  189. package/src/tools/tests/testing.test.ts +6 -6
  190. package/src/tools/tests/zod.test-d.ts +27 -0
  191. package/src/tools/tests/zod.test.ts +50 -45
  192. package/src/worker/index.ts +0 -1
  193. package/dist/chunk-OSVAAVWQ.js.map +0 -1
  194. package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +0 -12
  195. package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +0 -1
  196. package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +0 -9
  197. package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +0 -1
  198. package/src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +0 -172
  199. package/src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +0 -218
@@ -12,7 +12,7 @@ import {
12
12
  } from "vitest";
13
13
  import { Group, co, subscribeToCoValue, z } from "../exports.js";
14
14
  import { Account } from "../index.js";
15
- import { Loaded, anySchemaToCoSchema } from "../internal.js";
15
+ import { Loaded, coValueClassFromCoValueClassOrSchema } from "../internal.js";
16
16
  import {
17
17
  createJazzTestAccount,
18
18
  getPeerConnectedToTestSyncServer,
@@ -144,7 +144,7 @@ describe("CoMap", async () => {
144
144
  name: z.string(),
145
145
  age: z.number(),
146
146
  // TODO: would be nice if this didn't need a type annotation
147
- get friend(): z.ZodOptional<typeof Person> {
147
+ get friend(): co.Optional<typeof Person> {
148
148
  return co.optional(Person);
149
149
  },
150
150
  });
@@ -181,7 +181,7 @@ describe("CoMap", async () => {
181
181
  const Person = co.map({
182
182
  name: z.string(),
183
183
  age: z.number(),
184
- get friend(): z.ZodOptional<typeof Person> {
184
+ get friend(): co.Optional<typeof Person> {
185
185
  return co.optional(Person);
186
186
  },
187
187
  });
@@ -210,7 +210,7 @@ describe("CoMap", async () => {
210
210
  const Person = co.map({
211
211
  name: z.string(),
212
212
  age: z.number(),
213
- get friend(): z.ZodOptional<typeof Person> {
213
+ get friend(): co.Optional<typeof Person> {
214
214
  return co.optional(Person);
215
215
  },
216
216
  });
@@ -801,7 +801,7 @@ describe("CoMap resolution", async () => {
801
801
  const spy = vi.fn((person) => updates.push(person));
802
802
 
803
803
  subscribeToCoValue(
804
- anySchemaToCoSchema(Person), // TODO: we should get rid of the conversion in the future
804
+ coValueClassFromCoValueClassOrSchema(Person), // TODO: we should get rid of the conversion in the future
805
805
  person.id,
806
806
  {
807
807
  syncResolution: true,
@@ -2104,6 +2104,20 @@ describe("CoMap migration", () => {
2104
2104
  });
2105
2105
  });
2106
2106
 
2107
+ describe("co.map schema", () => {
2108
+ test("can access the inner schemas of a co.map", () => {
2109
+ const Person = co.map({
2110
+ name: co.plainText(),
2111
+ });
2112
+
2113
+ const person = Person.create({
2114
+ name: Person.shape["name"].create("John"),
2115
+ });
2116
+
2117
+ expect(person.name.toString()).toEqual("John");
2118
+ });
2119
+ });
2120
+
2107
2121
  describe("Updating a nested reference", () => {
2108
2122
  test("should assign a resolved optional reference and expect value is not null", async () => {
2109
2123
  // Define the schema similar to the server-worker-http example
@@ -1,4 +1,4 @@
1
- import { beforeEach, describe, test } from "vitest";
1
+ import { beforeEach, describe, expect, test } from "vitest";
2
2
  import { CoPlainText, co, z } from "../exports.js";
3
3
  import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
4
4
 
@@ -36,4 +36,66 @@ describe("co.optional", () => {
36
36
  preferredName: co.optional(z.string()),
37
37
  });
38
38
  });
39
+
40
+ test("can use schem.optional() on all CoValue schemas but co.optional()", () => {
41
+ const Option1 = co.map({ type: z.literal("1") });
42
+ const Option2 = co.map({ type: z.literal("2") });
43
+ const Schema = co.map({
44
+ plainText: co.plainText().optional(),
45
+ richText: co.richText().optional(),
46
+ fileStream: co.fileStream().optional(),
47
+ image: co.image().optional(),
48
+ record: co.record(z.string(), z.string()).optional(),
49
+ map: co.map({ field: z.string() }).optional(),
50
+ list: co.list(z.string()).optional(),
51
+ feed: co.feed(z.string()).optional(),
52
+ union: co.discriminatedUnion("type", [Option1, Option2]).optional(),
53
+ });
54
+
55
+ const schema = Schema.create({});
56
+
57
+ expect(schema.plainText).toBeUndefined();
58
+ expect(schema.richText).toBeUndefined();
59
+ expect(schema.fileStream).toBeUndefined();
60
+ expect(schema.image).toBeUndefined();
61
+ expect(schema.record).toBeUndefined();
62
+ expect(schema.map).toBeUndefined();
63
+ expect(schema.list).toBeUndefined();
64
+ expect(schema.feed).toBeUndefined();
65
+ expect(schema.union).toBeUndefined();
66
+
67
+ schema.plainText = Schema.shape.plainText.innerType.create("Hello");
68
+ schema.richText = Schema.shape.richText.innerType.create("Hello");
69
+ schema.fileStream = Schema.shape.fileStream.innerType.create();
70
+ schema.image = Schema.shape.image.innerType.create({
71
+ originalSize: [1920, 1080],
72
+ });
73
+ schema.record = Schema.shape.record.innerType.create({ field: "hello" });
74
+ schema.map = Schema.shape.map.innerType.create({ field: "hello" });
75
+ schema.list = Schema.shape.list.innerType.create([]);
76
+ schema.feed = Schema.shape.feed.innerType.create([]);
77
+ schema.union = Option1.create({ type: "1" });
78
+
79
+ expect(schema.plainText?.toString()).toEqual("Hello");
80
+ expect(schema.richText?.toString()).toEqual("Hello");
81
+ expect(schema.fileStream).not.toBeUndefined();
82
+ expect(schema.image?.originalSize).toEqual([1920, 1080]);
83
+ expect(schema.record?.field).toEqual("hello");
84
+ expect(schema.map?.field).toEqual("hello");
85
+ expect(schema.list).toEqual([]);
86
+ expect(schema.feed).not.toBeUndefined();
87
+ expect(schema.union?.type).toEqual("1");
88
+ });
89
+
90
+ test("can access the inner schema of a co.optional", () => {
91
+ const Person = co.map({
92
+ preferredName: co.optional(co.plainText()),
93
+ });
94
+
95
+ const person = Person.create({
96
+ preferredName: Person.shape["preferredName"].innerType.create("John"),
97
+ });
98
+
99
+ expect(person?.preferredName?.toString()).toEqual("John");
100
+ });
39
101
  });
@@ -9,15 +9,13 @@ import {
9
9
  ID,
10
10
  InMemoryKVStore,
11
11
  KvStoreContext,
12
- anySchemaToCoSchema,
13
12
  co,
13
+ coValueClassFromCoValueClassOrSchema,
14
14
  createAnonymousJazzContext,
15
15
  createJazzContext,
16
16
  createJazzContextForNewAccount,
17
17
  createJazzContextFromExistingCredentials,
18
18
  randomSessionProvider,
19
- z,
20
- zodSchemaToCoSchema,
21
19
  } from "../exports";
22
20
  import { activeAccountContext } from "../implementation/activeAccountContext";
23
21
  import {
@@ -86,12 +84,12 @@ describe("createContext methods", () => {
86
84
  credentials,
87
85
  peersToLoadFrom: [getPeerConnectedToTestSyncServer()],
88
86
  crypto: Crypto,
89
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
87
+ AccountSchema: CustomAccount,
90
88
  sessionProvider: randomSessionProvider,
91
89
  });
92
90
 
93
91
  expect(context.account).toBeInstanceOf(
94
- anySchemaToCoSchema(CustomAccount),
92
+ coValueClassFromCoValueClassOrSchema(CustomAccount),
95
93
  );
96
94
  });
97
95
 
@@ -196,11 +194,11 @@ describe("createContext methods", () => {
196
194
  creationProps: { name: "New User" },
197
195
  peersToLoadFrom: [],
198
196
  crypto: Crypto,
199
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
197
+ AccountSchema: CustomAccount,
200
198
  });
201
199
 
202
200
  expect(context.account).toBeInstanceOf(
203
- anySchemaToCoSchema(CustomAccount),
201
+ coValueClassFromCoValueClassOrSchema(CustomAccount),
204
202
  );
205
203
  });
206
204
 
@@ -347,11 +345,11 @@ describe("createContext methods", () => {
347
345
  crypto: Crypto,
348
346
  authSecretStorage,
349
347
  sessionProvider: randomSessionProvider,
350
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
348
+ AccountSchema: CustomAccount,
351
349
  });
352
350
 
353
351
  expect(context.account).toBeInstanceOf(
354
- anySchemaToCoSchema(CustomAccount),
352
+ coValueClassFromCoValueClassOrSchema(CustomAccount),
355
353
  );
356
354
  });
357
355
  });
@@ -1,4 +1,4 @@
1
- import { Profile, cojsonInternals } from "cojson";
1
+ import { cojsonInternals } from "cojson";
2
2
  import { WasmCrypto } from "cojson/crypto/WasmCrypto";
3
3
  import { assert, describe, expect, expectTypeOf, test, vi } from "vitest";
4
4
  import {
@@ -9,13 +9,7 @@ import {
9
9
  isControlledAccount,
10
10
  z,
11
11
  } from "../index.js";
12
- import {
13
- Account,
14
- CoListSchema,
15
- Loaded,
16
- co,
17
- randomSessionProvider,
18
- } from "../internal.js";
12
+ import { Account, Loaded, co, randomSessionProvider } from "../internal.js";
19
13
  import { createJazzTestAccount, linkAccounts } from "../testing.js";
20
14
  import { waitFor } from "./utils.js";
21
15
 
@@ -794,11 +788,11 @@ describe("Deep loading with unauthorized account", async () => {
794
788
  test("unaccessible list element with $onError and $each with depth", async () => {
795
789
  const Person = co.map({
796
790
  name: z.string(),
797
- get friends(): z.ZodOptional<typeof Friends> {
791
+ get friends(): co.Optional<typeof Friends> {
798
792
  return co.optional(Friends);
799
793
  },
800
794
  });
801
- const Friends: CoListSchema<typeof Person> = co.list(Person); // TODO: annoying that we have to annotate
795
+ const Friends: co.List<typeof Person> = co.list(Person); // TODO: annoying that we have to annotate
802
796
 
803
797
  const list = Friends.create(
804
798
  [
@@ -464,13 +464,13 @@ describe("importContentPieces", () => {
464
464
  {
465
465
  title: "My First Post",
466
466
  content: "Hello World",
467
- comments: Post.def.shape.comments.create([comment1, comment2], group),
467
+ comments: Post.shape.comments.create([comment1, comment2], group),
468
468
  },
469
469
  group,
470
470
  );
471
471
 
472
472
  const blog = Blog.create(
473
- { name: "My Blog", posts: Blog.def.shape.posts.create([post], group) },
473
+ { name: "My Blog", posts: Blog.shape.posts.create([post], group) },
474
474
  group,
475
475
  );
476
476
 
@@ -1,7 +1,7 @@
1
1
  import { WasmCrypto } from "cojson/crypto/WasmCrypto";
2
2
  import { assert, beforeEach, describe, expect, test } from "vitest";
3
3
  import { CoMap, Group, z } from "../exports.js";
4
- import { Loaded, Ref, co, zodSchemaToCoSchema } from "../internal.js";
4
+ import { Loaded, Ref, co } from "../internal.js";
5
5
  import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
6
6
  import { setupTwoNodes, waitFor } from "./utils.js";
7
7
 
@@ -22,15 +22,16 @@ describe("Custom accounts and groups", async () => {
22
22
  color: z.string(),
23
23
  });
24
24
 
25
+ const Root = co.map({});
25
26
  const CustomAccount = co
26
27
  .account({
27
28
  profile: CustomProfile,
28
- root: co.map({}),
29
+ root: Root,
29
30
  })
30
31
  .withMigration((account, creationProps?: { name: string }) => {
31
32
  // making sure that the inferred type of account.root & account.profile considers the root/profile not being loaded
32
33
  type R = typeof account.root;
33
- const _r: R = {} as Loaded<typeof CustomAccount.def.shape.root> | null;
34
+ const _r: R = {} as Loaded<typeof Root> | null;
34
35
  type P = typeof account.profile;
35
36
  const _p: P = {} as Loaded<typeof CustomProfile> | null;
36
37
  if (creationProps) {
@@ -47,7 +48,7 @@ describe("Custom accounts and groups", async () => {
47
48
  const me = await createJazzTestAccount({
48
49
  creationProps: { name: "Hermes Puggington" },
49
50
  isCurrentActiveAccount: true,
50
- AccountSchema: zodSchemaToCoSchema(CustomAccount),
51
+ AccountSchema: CustomAccount,
51
52
  });
52
53
 
53
54
  expect(me.profile).toBeDefined();
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import { Group, Inbox, InboxSender, z } from "../exports";
3
- import { Loaded, anySchemaToCoSchema, co } from "../internal";
3
+ import { Loaded, co, coValueClassFromCoValueClassOrSchema } from "../internal";
4
4
  import { setupTwoNodes, waitFor } from "./utils";
5
5
 
6
6
  const Message = co.map({
@@ -18,7 +18,8 @@ describe("Inbox", () => {
18
18
 
19
19
  const { clientAccount: sender, serverAccount: receiver } =
20
20
  await setupTwoNodes({
21
- ServerAccountSchema: anySchemaToCoSchema(WorkerAccount),
21
+ ServerAccountSchema:
22
+ coValueClassFromCoValueClassOrSchema(WorkerAccount),
22
23
  });
23
24
 
24
25
  await expect(() => InboxSender.load(receiver.id, sender)).rejects.toThrow(
@@ -69,33 +69,6 @@ test("load a missing optional value (co.optional)", async () => {
69
69
  expect(john.dog).toBeUndefined();
70
70
  });
71
71
 
72
- test("load a missing optional value (z.optional)", async () => {
73
- const Dog = co.map({
74
- name: z.string(),
75
- });
76
-
77
- const Person = co.map({
78
- name: z.string(),
79
- dog: z.optional(Dog),
80
- });
81
-
82
- const group = Group.create();
83
- const map = Person.create({ name: "John" }, group);
84
- group.addMember("everyone", "reader");
85
-
86
- const alice = await createJazzTestAccount();
87
-
88
- const john = await Person.load(map.id, {
89
- loadAs: alice,
90
- resolve: { dog: true },
91
- });
92
-
93
- assert(john);
94
-
95
- expect(john.name).toBe("John");
96
- expect(john.dog).toBeUndefined();
97
- });
98
-
99
72
  test("load a missing optional value (Schema.optional)", async () => {
100
73
  const Dog = co.map({
101
74
  name: z.string(),
@@ -214,13 +187,14 @@ test("returns null if the value is unavailable after retries", async () => {
214
187
  test("load a large coValue", async () => {
215
188
  const syncServer = await setupJazzTestSync({ asyncPeers: true });
216
189
 
190
+ const Data = co.list(z.string());
217
191
  const LargeDataset = co.map({
218
192
  metadata: z.object({
219
193
  name: z.string(),
220
194
  description: z.string(),
221
195
  createdAt: z.number(),
222
196
  }),
223
- data: co.list(z.string()),
197
+ data: Data,
224
198
  });
225
199
 
226
200
  const group = Group.create(syncServer);
@@ -232,7 +206,7 @@ test("load a large coValue", async () => {
232
206
  "A dataset with many entries for testing large coValue loading",
233
207
  createdAt: Date.now(),
234
208
  },
235
- data: LargeDataset.def.shape.data.create([], group),
209
+ data: Data.create([], group),
236
210
  },
237
211
  group,
238
212
  );
@@ -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
- });