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
package/package.json CHANGED
@@ -139,7 +139,7 @@
139
139
  },
140
140
  "type": "module",
141
141
  "license": "MIT",
142
- "version": "0.15.15",
142
+ "version": "0.16.0",
143
143
  "dependencies": {
144
144
  "@manuscripts/prosemirror-recreate-steps": "^0.1.4",
145
145
  "@scure/base": "1.2.1",
@@ -157,10 +157,10 @@
157
157
  "prosemirror-schema-basic": "^1.2.2",
158
158
  "prosemirror-state": "^1.4.3",
159
159
  "prosemirror-transform": "^1.9.0",
160
- "zod": "3.25.28",
161
- "cojson": "0.15.15",
162
- "cojson-storage-indexeddb": "0.15.15",
163
- "cojson-transport-ws": "0.15.15"
160
+ "zod": "3.25.76",
161
+ "cojson": "0.16.0",
162
+ "cojson-storage-indexeddb": "0.16.0",
163
+ "cojson-transport-ws": "0.16.0"
164
164
  },
165
165
  "devDependencies": {
166
166
  "@scure/bip39": "^1.3.0",
@@ -171,8 +171,9 @@
171
171
  "@types/react": "19.1.0",
172
172
  "@types/react-dom": "19.1.0",
173
173
  "@vitest/browser": "^3.2.4",
174
- "queueueue": "^4.1.2",
174
+ "msw": "^2.10.3",
175
175
  "playwright": "^1.50.1",
176
+ "queueueue": "^4.1.2",
176
177
  "tsup": "8.5.0",
177
178
  "typescript": "5.6.2",
178
179
  "vitest": "3.2.4",
@@ -1,9 +1,7 @@
1
1
  import {
2
2
  Account,
3
3
  CoValue,
4
- CoValueClass,
5
- CoValueOrZodSchema,
6
- ID,
4
+ CoValueClassOrSchema,
7
5
  InviteSecret,
8
6
  createInviteLink as baseCreateInviteLink,
9
7
  consumeInviteLink,
@@ -36,7 +34,7 @@ export { parseInviteLink } from "jazz-tools";
36
34
 
37
35
  /** @category Invite Links */
38
36
  export async function consumeInviteLinkFromWindowLocation<
39
- S extends CoValueOrZodSchema,
37
+ S extends CoValueClassOrSchema,
40
38
  >({
41
39
  as,
42
40
  forValueHint,
@@ -17,7 +17,7 @@ export async function createImage(
17
17
  owner?: Group | Account;
18
18
  maxSize?: 256 | 1024 | 2048;
19
19
  },
20
- ): Promise<Loaded<typeof ImageDefinition>> {
20
+ ): Promise<Loaded<typeof ImageDefinition, { $each: true }>> {
21
21
  // Get the original size of the image
22
22
  const { width: originalWidth, height: originalHeight } =
23
23
  await getImageSize(imageBlobOrFile);
@@ -1,12 +1,12 @@
1
1
  import { consumeInviteLinkFromWindowLocation } from "jazz-tools/browser";
2
2
  import { useEffect } from "react";
3
3
 
4
- import { CoValueOrZodSchema } from "jazz-tools";
4
+ import { CoValueClassOrSchema } from "jazz-tools";
5
5
  import { useJazzContext } from "jazz-tools/react-core";
6
6
 
7
7
  export { useCoState, useAuthSecretStorage } from "jazz-tools/react-core";
8
8
 
9
- export function useAcceptInvite<S extends CoValueOrZodSchema>({
9
+ export function useAcceptInvite<S extends CoValueClassOrSchema>({
10
10
  invitedObjectSchema,
11
11
  onAccept,
12
12
  forValueHint,
@@ -11,7 +11,7 @@ import {
11
11
  AnonymousJazzAgent,
12
12
  AnyAccountSchema,
13
13
  CoValue,
14
- CoValueOrZodSchema,
14
+ CoValueClassOrSchema,
15
15
  InboxSender,
16
16
  InstanceOfSchema,
17
17
  JazzContextManager,
@@ -20,7 +20,7 @@ import {
20
20
  ResolveQuery,
21
21
  ResolveQueryStrict,
22
22
  SubscriptionScope,
23
- anySchemaToCoSchema,
23
+ coValueClassFromCoValueClassOrSchema,
24
24
  } from "jazz-tools";
25
25
  import { JazzContext, JazzContextManagerContext } from "./provider.js";
26
26
  import { getCurrentAccountFromContextManager } from "./utils.js";
@@ -80,7 +80,7 @@ export function useIsAuthenticated() {
80
80
  }
81
81
 
82
82
  function useCoValueSubscription<
83
- S extends CoValueOrZodSchema,
83
+ S extends CoValueClassOrSchema,
84
84
  const R extends ResolveQuery<S>,
85
85
  >(
86
86
  Schema: S,
@@ -107,7 +107,7 @@ function useCoValueSubscription<
107
107
  options?.resolve ?? true,
108
108
  id,
109
109
  {
110
- ref: anySchemaToCoSchema(Schema),
110
+ ref: coValueClassFromCoValueClassOrSchema(Schema),
111
111
  optional: true,
112
112
  },
113
113
  );
@@ -142,7 +142,7 @@ function useCoValueSubscription<
142
142
  }
143
143
 
144
144
  export function useCoState<
145
- S extends CoValueOrZodSchema,
145
+ S extends CoValueClassOrSchema,
146
146
  const R extends ResolveQuery<S> = true,
147
147
  >(
148
148
  Schema: S,
@@ -198,7 +198,7 @@ function useAccountSubscription<
198
198
 
199
199
  const node = contextManager.getCurrentValue()!.node;
200
200
  const subscription = new SubscriptionScope<any>(node, resolve, agent.id, {
201
- ref: anySchemaToCoSchema(Schema),
201
+ ref: coValueClassFromCoValueClassOrSchema(Schema),
202
202
  optional: true,
203
203
  });
204
204
 
@@ -1,6 +1,6 @@
1
1
  // @vitest-environment happy-dom
2
2
 
3
- import { RefsToResolve, co, z, zodSchemaToCoSchema } from "jazz-tools";
3
+ import { RefsToResolve, co, z } from "jazz-tools";
4
4
  import { beforeEach, describe, expect, it } from "vitest";
5
5
  import { useAccount, useJazzContextManager } from "../hooks.js";
6
6
  import { useIsAuthenticated } from "../index.js";
@@ -46,7 +46,7 @@ describe("useAccount", () => {
46
46
  });
47
47
 
48
48
  const account = await createJazzTestAccount({
49
- AccountSchema: zodSchemaToCoSchema(AccountSchema),
49
+ AccountSchema,
50
50
  });
51
51
 
52
52
  const { result } = renderHook(
@@ -520,12 +520,13 @@ describe("useCoState", () => {
520
520
  const Message = co.map({
521
521
  content: CoRichText,
522
522
  });
523
+ const Messages = co.list(Message);
523
524
  const Thread = co.map({
524
- messages: co.list(Message),
525
+ messages: Messages,
525
526
  });
526
527
 
527
528
  const thread = Thread.create({
528
- messages: Thread.def.shape.messages.create([
529
+ messages: Messages.create([
529
530
  Message.create({
530
531
  content: CoRichText.create("Hello man!"),
531
532
  }),
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from "react";
2
2
 
3
- import { CoValueOrZodSchema, parseInviteLink } from "jazz-tools";
3
+ import { CoValueClassOrSchema, parseInviteLink } from "jazz-tools";
4
4
  import { useJazzContext } from "jazz-tools/react-core";
5
5
  import { Linking } from "react-native";
6
6
 
@@ -15,7 +15,7 @@ export {
15
15
  useAccount,
16
16
  } from "jazz-tools/react-core";
17
17
 
18
- export function useAcceptInviteNative<S extends CoValueOrZodSchema>({
18
+ export function useAcceptInviteNative<S extends CoValueClassOrSchema>({
19
19
  invitedObjectSchema,
20
20
  onAccept,
21
21
  forValueHint,
@@ -2,21 +2,24 @@ import type {
2
2
  Account,
3
3
  AccountClass,
4
4
  AnyAccountSchema,
5
+ CoValueClassOrSchema,
5
6
  CoValueFromRaw,
6
- CoValueOrZodSchema,
7
7
  InstanceOfSchema,
8
8
  Loaded,
9
9
  ResolveQuery,
10
10
  ResolveQueryStrict,
11
11
  } from "jazz-tools";
12
- import { anySchemaToCoSchema, subscribeToCoValue } from "jazz-tools";
12
+ import {
13
+ coValueClassFromCoValueClassOrSchema,
14
+ subscribeToCoValue,
15
+ } from "jazz-tools";
13
16
  import { untrack } from "svelte";
14
17
  import { createSubscriber } from "svelte/reactivity";
15
18
  import { useIsAuthenticated } from "./auth/useIsAuthenticated.svelte.js";
16
19
  import { getJazzContext } from "./jazz.svelte";
17
20
 
18
21
  export class CoState<
19
- V extends CoValueOrZodSchema,
22
+ V extends CoValueClassOrSchema,
20
23
  R extends ResolveQuery<V> = true,
21
24
  > {
22
25
  #value: Loaded<V, R> | undefined | null = undefined;
@@ -47,10 +50,10 @@ export class CoState<
47
50
  const agent = "me" in ctx ? ctx.me : ctx.guest;
48
51
 
49
52
  const unsubscribe = subscribeToCoValue(
50
- anySchemaToCoSchema(Schema),
53
+ coValueClassFromCoValueClassOrSchema(Schema),
51
54
  id,
52
55
  {
53
- // @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
56
+ // @ts-expect-error The resolve query type isn't compatible with the coValueClassFromCoValueClassOrSchema conversion
54
57
  resolve: options?.resolve,
55
58
  loadAs: agent,
56
59
  onUnavailable: () => {
@@ -112,10 +115,10 @@ export class AccountCoState<
112
115
  const me = ctx.me;
113
116
 
114
117
  const unsubscribe = subscribeToCoValue(
115
- anySchemaToCoSchema(Schema),
118
+ coValueClassFromCoValueClassOrSchema(Schema),
116
119
  me.id,
117
120
  {
118
- // @ts-expect-error The resolve query type isn't compatible with the anySchemaToCoSchema conversion
121
+ // @ts-expect-error The resolve query type isn't compatible with the coValueClassFromCoValueClassOrSchema conversion
119
122
  resolve: options?.resolve,
120
123
  loadAs: me,
121
124
  onUnavailable: () => {
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  AccountClass,
3
3
  AuthSecretStorage,
4
- CoValueOrZodSchema,
4
+ CoValueClassOrSchema,
5
5
  ID,
6
6
  InstanceOfSchema,
7
7
  JazzContextType,
@@ -66,7 +66,7 @@ export function getAuthSecretStorage() {
66
66
  * @param forValueHint - Hint for the value.
67
67
  * @returns The accept invite hook.
68
68
  */
69
- export class InviteListener<V extends CoValueOrZodSchema> {
69
+ export class InviteListener<V extends CoValueClassOrSchema> {
70
70
  constructor({
71
71
  invitedObjectSchema,
72
72
  onAccept,
@@ -1,5 +1,5 @@
1
1
  import { ControlledAccount, RawAccount, type RawCoValue } from "cojson";
2
- import { z } from "../implementation/zodSchema/zodReExport.js";
2
+ import { CoreCoValueSchema } from "../implementation/zodSchema/schemaTypes/CoValueSchema.js";
3
3
  import {
4
4
  AnonymousJazzAgent,
5
5
  CoValue,
@@ -8,13 +8,14 @@ import {
8
8
  ID,
9
9
  RegisteredSchemas,
10
10
  accessChildById,
11
- anySchemaToCoSchema,
11
+ coValueClassFromCoValueClassOrSchema,
12
12
  coValuesCache,
13
13
  inspect,
14
14
  isCoValueSchema,
15
15
  } from "../internal.js";
16
16
  import type {
17
17
  Account,
18
+ CoValueClassOrSchema,
18
19
  Group,
19
20
  InstanceOfSchemaCoValuesNullable,
20
21
  } from "../internal.js";
@@ -46,9 +47,9 @@ export class CoValueBase implements CoValue {
46
47
 
47
48
  if (agent instanceof ControlledAccount) {
48
49
  return coValuesCache.get(agent.account, () =>
49
- anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
50
- agent.account,
51
- ),
50
+ coValueClassFromCoValueClassOrSchema(
51
+ RegisteredSchemas["Account"],
52
+ ).fromRaw(agent.account),
52
53
  );
53
54
  }
54
55
 
@@ -81,24 +82,11 @@ export class CoValueBase implements CoValue {
81
82
  }
82
83
 
83
84
  /** @category Type Helpers */
84
- castAs<
85
- S extends
86
- | CoValueClass
87
- | z.core.$ZodType
88
- | (z.core.$ZodObject<any, any> & {
89
- builtin: "Account";
90
- migration?: (account: any, creationProps?: { name: string }) => void;
91
- })
92
- | (z.core.$ZodCustom<any, any> & { builtin: "FileStream" })
93
- | (z.core.$ZodCustom<any, any> & {
94
- builtin: "CoFeed";
95
- element: z.core.$ZodType;
96
- }),
97
- >(
85
+ castAs<S extends CoValueClassOrSchema>(
98
86
  schema: S,
99
87
  ): S extends CoValueClass
100
88
  ? InstanceType<S>
101
- : S extends z.core.$ZodType
89
+ : S extends CoreCoValueSchema
102
90
  ? NonNullable<InstanceOfSchemaCoValuesNullable<S>>
103
91
  : never {
104
92
  const cl = isCoValueSchema(schema) ? schema.getCoValueClass() : schema;
@@ -16,12 +16,12 @@ import {
16
16
  } from "cojson";
17
17
  import {
18
18
  AnonymousJazzAgent,
19
- AnyAccountSchema,
20
19
  type CoMap,
21
20
  type CoValue,
22
21
  CoValueBase,
23
22
  CoValueClass,
24
- CoValueOrZodSchema,
23
+ CoValueClassOrSchema,
24
+ CoreAccountSchema,
25
25
  type Group,
26
26
  ID,
27
27
  InstanceOfSchema,
@@ -40,7 +40,7 @@ import {
40
40
  SubscribeRestArgs,
41
41
  accessChildByKey,
42
42
  activeAccountContext,
43
- anySchemaToCoSchema,
43
+ coValueClassFromCoValueClassOrSchema,
44
44
  coValuesCache,
45
45
  createInboxRoot,
46
46
  ensureCoValueLoaded,
@@ -254,7 +254,7 @@ export class Account extends CoValueBase implements CoValue {
254
254
  return value._owner.getRoleOf(this.id) === "admin";
255
255
  }
256
256
 
257
- async acceptInvite<S extends CoValueOrZodSchema>(
257
+ async acceptInvite<S extends CoValueClassOrSchema>(
258
258
  valueID: string,
259
259
  inviteSecret: InviteSecret,
260
260
  coValueClass: S,
@@ -268,9 +268,13 @@ export class Account extends CoValueBase implements CoValue {
268
268
  inviteSecret,
269
269
  );
270
270
 
271
- return loadCoValue(anySchemaToCoSchema(coValueClass), valueID, {
272
- loadAs: this,
273
- }) as Resolved<InstanceOrPrimitiveOfSchema<S>, true> | null;
271
+ return loadCoValue(
272
+ coValueClassFromCoValueClassOrSchema(coValueClass),
273
+ valueID,
274
+ {
275
+ loadAs: this,
276
+ },
277
+ ) as Resolved<InstanceOrPrimitiveOfSchema<S>, true> | null;
274
278
  }
275
279
 
276
280
  /** @private */
@@ -447,9 +451,7 @@ export class Account extends CoValueBase implements CoValue {
447
451
  *
448
452
  * @category Subscription & Loading
449
453
  */
450
- waitForSync(options?: {
451
- timeout?: number;
452
- }) {
454
+ waitForSync(options?: { timeout?: number }) {
453
455
  return this._raw.core.waitForSync(options);
454
456
  }
455
457
 
@@ -458,9 +460,7 @@ export class Account extends CoValueBase implements CoValue {
458
460
  *
459
461
  * @category Subscription & Loading
460
462
  */
461
- waitForAllCoValuesSync(options?: {
462
- timeout?: number;
463
- }) {
463
+ waitForAllCoValuesSync(options?: { timeout?: number }) {
464
464
  return this._raw.core.node.syncManager.waitForAllCoValuesSync(
465
465
  options?.timeout,
466
466
  );
@@ -502,7 +502,11 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
502
502
  return true;
503
503
  } else if (key === "root") {
504
504
  if (value) {
505
- target._raw.set("root", value.id as unknown as CoID<RawCoMap>);
505
+ target._raw.set(
506
+ "root",
507
+ value.id as unknown as CoID<RawCoMap>,
508
+ "trusting",
509
+ );
506
510
  }
507
511
  return true;
508
512
  } else {
@@ -12,12 +12,10 @@ import type {
12
12
  import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals } from "cojson";
13
13
  import type {
14
14
  AnonymousJazzAgent,
15
- AnyAccountSchema,
16
15
  CoValue,
17
16
  CoValueClass,
18
17
  Group,
19
18
  ID,
20
- InstanceOfSchema,
21
19
  RefsToResolve,
22
20
  RefsToResolveStrict,
23
21
  Resolved,
@@ -31,10 +29,8 @@ import {
31
29
  CoValueBase,
32
30
  ItemsSym,
33
31
  Ref,
34
- RegisteredSchemas,
35
32
  SchemaInit,
36
33
  accessChildById,
37
- anySchemaToCoSchema,
38
34
  coField,
39
35
  ensureCoValueLoaded,
40
36
  inspect,
@@ -3,13 +3,11 @@ import { ControlledAccount, RawAccount } from "cojson";
3
3
  import { calcPatch } from "fast-myers-diff";
4
4
  import type {
5
5
  Account,
6
- AnyAccountSchema,
7
6
  CoValue,
8
7
  CoValueClass,
9
8
  CoValueFromRaw,
10
9
  Group,
11
10
  ID,
12
- InstanceOfSchema,
13
11
  RefEncoded,
14
12
  RefsToResolve,
15
13
  RefsToResolveStrict,
@@ -26,8 +24,8 @@ import {
26
24
  RegisteredSchemas,
27
25
  SchemaInit,
28
26
  accessChildByKey,
29
- anySchemaToCoSchema,
30
27
  coField,
28
+ coValueClassFromCoValueClassOrSchema,
31
29
  coValuesCache,
32
30
  ensureCoValueLoaded,
33
31
  inspect,
@@ -117,9 +115,9 @@ export class CoList<out Item = any> extends Array<Item> implements CoValue {
117
115
  /** @category Collaboration */
118
116
  get _owner(): Account | Group {
119
117
  return this._raw.group instanceof RawAccount
120
- ? anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
121
- this._raw.group,
122
- )
118
+ ? coValueClassFromCoValueClassOrSchema(
119
+ RegisteredSchemas["Account"],
120
+ ).fromRaw(this._raw.group)
123
121
  : RegisteredSchemas["Group"].fromRaw(this._raw.group);
124
122
  }
125
123
 
@@ -175,9 +173,9 @@ export class CoList<out Item = any> extends Array<Item> implements CoValue {
175
173
 
176
174
  if (agent instanceof ControlledAccount) {
177
175
  return coValuesCache.get(agent.account, () =>
178
- anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
179
- agent.account,
180
- ),
176
+ coValueClassFromCoValueClassOrSchema(
177
+ RegisteredSchemas["Account"],
178
+ ).fromRaw(agent.account),
181
179
  );
182
180
  }
183
181
 
@@ -20,6 +20,7 @@ import type {
20
20
  RefsToResolveStrict,
21
21
  Resolved,
22
22
  Schema,
23
+ Simplify,
23
24
  SubscribeListenerOptions,
24
25
  SubscribeRestArgs,
25
26
  } from "../internal.js";
@@ -54,12 +55,6 @@ type CoMapEdit<V> = {
54
55
 
55
56
  type LastAndAllCoMapEdits<V> = CoMapEdit<V> & { all: CoMapEdit<V>[] };
56
57
 
57
- export type Simplify<A> = {
58
- [K in keyof A]: A[K];
59
- } extends infer B
60
- ? B
61
- : never;
62
-
63
58
  /**
64
59
  * CoMaps are collaborative versions of plain objects, mapping string-like keys to values.
65
60
  *
@@ -14,7 +14,7 @@ import {
14
14
  Resolved,
15
15
  SubscribeListenerOptions,
16
16
  SubscribeRestArgs,
17
- anySchemaToCoSchema,
17
+ coValueClassFromCoValueClassOrSchema,
18
18
  parseCoValueCreateOptions,
19
19
  } from "../internal.js";
20
20
  import {
@@ -47,9 +47,9 @@ export class CoPlainText extends String implements CoValue {
47
47
 
48
48
  if (agent instanceof ControlledAccount) {
49
49
  return coValuesCache.get(agent.account, () =>
50
- anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(
51
- agent.account,
52
- ),
50
+ coValueClassFromCoValueClassOrSchema(
51
+ RegisteredSchemas["Account"],
52
+ ).fromRaw(agent.account),
53
53
  );
54
54
  }
55
55
 
@@ -5,7 +5,10 @@ import { CoFeedEntry } from "./coFeed.js";
5
5
  import { type CoKeys } from "./coMap.js";
6
6
  import { type CoValue, type ID } from "./interfaces.js";
7
7
 
8
- type NotNull<T> = Exclude<T, null>;
8
+ /**
9
+ * Similar to {@link NonNullable}, but removes only `null` and preserves `undefined`.
10
+ */
11
+ export type NotNull<T> = Exclude<T, null>;
9
12
 
10
13
  /**
11
14
  * Used to check if T is a union type.
@@ -8,9 +8,9 @@ const ImageDefinitionBase = coMapDefiner({
8
8
  }).catchall(coFileStreamDefiner());
9
9
 
10
10
  /** @category Media */
11
- export const ImageDefinition = ImageDefinitionBase.withHelpers((Self) => ({
11
+ export const ImageDefinition = Object.assign({}, ImageDefinitionBase, {
12
12
  highestResAvailable(
13
- imageDef: Loaded<typeof Self>,
13
+ imageDef: ImageDefinition,
14
14
  options?: {
15
15
  maxWidth?: number;
16
16
  targetWidth?: number;
@@ -56,5 +56,5 @@ export const ImageDefinition = ImageDefinitionBase.withHelpers((Self) => ({
56
56
  }
57
57
  );
58
58
  },
59
- }));
59
+ });
60
60
  export type ImageDefinition = Loaded<typeof ImageDefinition>;
@@ -153,6 +153,7 @@ export class Group extends CoValueBase implements CoValue {
153
153
  member: Group,
154
154
  role?: "reader" | "writer" | "admin" | "inherit",
155
155
  ): void;
156
+ addMember(member: Group | Account, role: "reader" | "writer" | "admin"): void;
156
157
  addMember(
157
158
  member: Group | Everyone | Account,
158
159
  role?: AccountRole | "inherit",
@@ -3,13 +3,14 @@ import { CoStreamItem, RawCoStream } from "cojson";
3
3
  import {
4
4
  type Account,
5
5
  CoValue,
6
- CoValueOrZodSchema,
6
+ CoValueClassOrSchema,
7
7
  ID,
8
8
  InstanceOfSchema,
9
9
  activeAccountContext,
10
- anySchemaToCoSchema,
10
+ coValueClassFromCoValueClassOrSchema,
11
11
  loadCoValue,
12
12
  } from "../internal.js";
13
+ import { isCoValueId } from "../lib/id.js";
13
14
 
14
15
  export type InboxInvite = `${CoID<MessagesStream>}/${InviteSecret}`;
15
16
  type TxKey = `${SessionID}/${number}`;
@@ -108,7 +109,7 @@ export class Inbox {
108
109
  this.failed = failed;
109
110
  }
110
111
 
111
- subscribe<M extends CoValueOrZodSchema, O extends CoValue | undefined>(
112
+ subscribe<M extends CoValueClassOrSchema, O extends CoValue | undefined>(
112
113
  Schema: M,
113
114
  callback: (
114
115
  message: InstanceOfSchema<M>,
@@ -171,7 +172,7 @@ export class Inbox {
171
172
  }
172
173
 
173
174
  return loadCoValue(
174
- anySchemaToCoSchema(Schema),
175
+ coValueClassFromCoValueClassOrSchema(Schema),
175
176
  message.get("payload")!,
176
177
  {
177
178
  loadAs: account,
@@ -382,7 +383,7 @@ async function acceptInvite(invite: string, account?: Account) {
382
383
 
383
384
  const inviteSecret = invite.slice(invite.indexOf("/") + 1) as InviteSecret;
384
385
 
385
- if (!id?.startsWith("co_z") || !inviteSecret.startsWith("inviteSecret_")) {
386
+ if (!isCoValueId(id) || !inviteSecret.startsWith("inviteSecret_")) {
386
387
  throw new Error("Invalid inbox ticket");
387
388
  }
388
389
 
@@ -399,8 +400,8 @@ function getAccountIDfromSessionID(sessionID: SessionID) {
399
400
  const until = sessionID.indexOf("_session");
400
401
  const accountID = sessionID.slice(0, until);
401
402
 
402
- if (accountID.startsWith("co_z")) {
403
- return accountID as ID<Account>;
403
+ if (isCoValueId(accountID)) {
404
+ return accountID;
404
405
  }
405
406
 
406
407
  return;