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
@@ -1,113 +1,121 @@
1
1
  import { JsonValue } from "cojson";
2
2
  import {
3
3
  Account,
4
+ AnyZodOrCoValueSchema,
5
+ CoDiscriminatedUnionSchema,
4
6
  CoFeed,
5
7
  CoList,
6
8
  CoMap,
7
9
  CoPlainText,
8
10
  CoRichText,
9
11
  CoValueClass,
12
+ CoreAccountSchema,
13
+ CoreCoRecordSchema,
10
14
  FileStream,
11
15
  Profile,
12
16
  } from "../../../internal.js";
13
- import { AnyCoFeedSchema } from "../schemaTypes/CoFeedSchema.js";
14
- import { AnyCoListSchema } from "../schemaTypes/CoListSchema.js";
15
- import { AnyCoMapSchema } from "../schemaTypes/CoMapSchema.js";
16
- import { FileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
17
- import { PlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
18
- import { RichTextSchema } from "../schemaTypes/RichTextSchema.js";
17
+ import { CoreCoFeedSchema } from "../schemaTypes/CoFeedSchema.js";
18
+ import { CoreCoListSchema } from "../schemaTypes/CoListSchema.js";
19
+ import { CoreCoMapSchema } from "../schemaTypes/CoMapSchema.js";
20
+ import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
21
+ import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js";
22
+ import { CoreFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
23
+ import { CorePlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
24
+ import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js";
19
25
  import { z } from "../zodReExport.js";
20
26
 
21
27
  export type InstanceOrPrimitiveOfSchema<
22
- S extends CoValueClass | z.core.$ZodType,
23
- > = S extends z.core.$ZodType
24
- ? S extends z.core.$ZodObject<infer Shape> & {
25
- collaborative: true;
26
- builtin: "Account";
27
- }
28
+ S extends CoValueClass | AnyZodOrCoValueSchema,
29
+ > = S extends CoreCoValueSchema
30
+ ? S extends CoreAccountSchema<infer Shape>
28
31
  ? {
29
32
  -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
30
33
  } & { profile: Profile } & Account
31
- : S extends z.core.$ZodRecord<infer K, infer V> & {
32
- collaborative: true;
33
- }
34
+ : S extends CoreCoRecordSchema<infer K, infer V>
34
35
  ? {
35
36
  -readonly [key in z.output<K> &
36
37
  string]: InstanceOrPrimitiveOfSchema<V>;
37
38
  } & CoMap
38
- : S extends AnyCoMapSchema<infer Shape, infer Config>
39
+ : S extends CoreCoMapSchema<infer Shape, infer CatchAll>
39
40
  ? {
40
41
  -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<
41
42
  Shape[key]
42
43
  >;
43
- } & (unknown extends Config["out"][string]
44
+ } & (unknown extends CatchAll
44
45
  ? {}
45
46
  : {
46
- [key: string]: Config["out"][string];
47
+ // @ts-expect-error
48
+ [key: string]: InstanceOrPrimitiveOfSchema<CatchAll>;
47
49
  }) &
48
50
  CoMap
49
- : S extends AnyCoListSchema<infer T>
51
+ : S extends CoreCoListSchema<infer T>
50
52
  ? CoList<InstanceOrPrimitiveOfSchema<T>>
51
- : S extends AnyCoFeedSchema<infer T>
53
+ : S extends CoreCoFeedSchema<infer T>
52
54
  ? CoFeed<InstanceOrPrimitiveOfSchema<T>>
53
- : S extends PlainTextSchema
55
+ : S extends CorePlainTextSchema
54
56
  ? CoPlainText
55
- : S extends RichTextSchema
57
+ : S extends CoreRichTextSchema
56
58
  ? CoRichText
57
- : S extends FileStreamSchema
59
+ : S extends CoreFileStreamSchema
58
60
  ? FileStream
59
- : S extends z.core.$ZodOptional<infer Inner>
60
- ? InstanceOrPrimitiveOfSchema<Inner> | undefined
61
- : S extends z.ZodJSONSchema
62
- ? JsonValue
63
- : S extends z.core.$ZodUnion<infer Members>
64
- ? InstanceOrPrimitiveOfSchema<Members[number]>
65
- : // primitives below here - we manually traverse to ensure we only allow what we can handle
66
- S extends z.core.$ZodObject<infer Shape>
67
- ? {
68
- -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<
69
- Shape[key]
70
- >;
71
- }
72
- : S extends z.core.$ZodArray<infer Item>
73
- ? InstanceOrPrimitiveOfSchema<Item>[]
74
- : S extends z.core.$ZodTuple<infer Items>
75
- ? {
76
- [key in keyof Items]: InstanceOrPrimitiveOfSchema<
77
- Items[key]
78
- >;
79
- }
80
- : S extends z.core.$ZodString
81
- ? string
82
- : S extends z.core.$ZodNumber
83
- ? number
84
- : S extends z.core.$ZodBoolean
85
- ? boolean
86
- : S extends z.core.$ZodLiteral<
87
- infer Literal
88
- >
89
- ? Literal
90
- : S extends z.core.$ZodDate
91
- ? Date
92
- : S extends z.core.$ZodEnum<infer Enum>
93
- ? Enum[keyof Enum]
94
- : S extends z.core.$ZodTemplateLiteral<
95
- infer pattern
96
- >
97
- ? pattern
98
- : S extends z.core.$ZodReadonly<
99
- infer Inner
100
- >
101
- ? InstanceOrPrimitiveOfSchema<Inner>
102
- : S extends z.core.$ZodDefault<
103
- infer Default
104
- >
105
- ? InstanceOrPrimitiveOfSchema<Default>
106
- : S extends z.core.$ZodCatch<
107
- infer Catch
108
- >
109
- ? InstanceOrPrimitiveOfSchema<Catch>
110
- : never
111
- : S extends CoValueClass
112
- ? InstanceType<S>
113
- : never;
61
+ : S extends CoreCoOptionalSchema<infer T>
62
+ ? InstanceOrPrimitiveOfSchema<T> | undefined
63
+ : S extends CoDiscriminatedUnionSchema<infer Members>
64
+ ? InstanceOrPrimitiveOfSchema<Members[number]>
65
+ : never
66
+ : S extends z.core.$ZodType
67
+ ? S extends z.core.$ZodOptional<infer Inner extends z.core.$ZodType>
68
+ ? InstanceOrPrimitiveOfSchema<Inner> | undefined
69
+ : S extends z.ZodJSONSchema
70
+ ? JsonValue
71
+ : S extends z.core.$ZodUnion<infer Members extends z.core.$ZodType[]>
72
+ ? InstanceOrPrimitiveOfSchema<Members[number]>
73
+ : // primitives below here - we manually traverse to ensure we only allow what we can handle
74
+ S extends z.core.$ZodObject<infer Shape>
75
+ ? {
76
+ -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<
77
+ Shape[key]
78
+ >;
79
+ }
80
+ : S extends z.core.$ZodArray<infer Item extends z.core.$ZodType>
81
+ ? InstanceOrPrimitiveOfSchema<Item>[]
82
+ : S extends z.core.$ZodTuple<
83
+ infer Items extends readonly z.core.$ZodType[]
84
+ >
85
+ ? {
86
+ [key in keyof Items]: InstanceOrPrimitiveOfSchema<
87
+ Items[key]
88
+ >;
89
+ }
90
+ : S extends z.core.$ZodString
91
+ ? string
92
+ : S extends z.core.$ZodNumber
93
+ ? number
94
+ : S extends z.core.$ZodBoolean
95
+ ? boolean
96
+ : S extends z.core.$ZodLiteral<infer Literal>
97
+ ? Literal
98
+ : S extends z.core.$ZodDate
99
+ ? Date
100
+ : S extends z.core.$ZodEnum<infer Enum>
101
+ ? Enum[keyof Enum]
102
+ : S extends z.core.$ZodTemplateLiteral<
103
+ infer pattern
104
+ >
105
+ ? pattern
106
+ : S extends z.core.$ZodReadonly<
107
+ infer Inner extends z.core.$ZodType
108
+ >
109
+ ? InstanceOrPrimitiveOfSchema<Inner>
110
+ : S extends z.core.$ZodDefault<
111
+ infer Default extends z.core.$ZodType
112
+ >
113
+ ? InstanceOrPrimitiveOfSchema<Default>
114
+ : S extends z.core.$ZodCatch<
115
+ infer Catch extends z.core.$ZodType
116
+ >
117
+ ? InstanceOrPrimitiveOfSchema<Catch>
118
+ : never
119
+ : S extends CoValueClass
120
+ ? InstanceType<S>
121
+ : never;
@@ -1,31 +1,34 @@
1
1
  import { JsonValue } from "cojson";
2
2
  import {
3
3
  Account,
4
+ AnyZodOrCoValueSchema,
5
+ CoDiscriminatedUnionSchema,
4
6
  CoFeed,
5
7
  CoList,
6
8
  CoMap,
7
9
  CoPlainText,
8
10
  CoRichText,
9
11
  CoValueClass,
12
+ CoreAccountSchema,
13
+ CoreCoRecordSchema,
10
14
  FileStream,
11
15
  InstanceOrPrimitiveOfSchema,
12
16
  Profile,
13
17
  } from "../../../internal.js";
14
- import { AnyCoFeedSchema } from "../schemaTypes/CoFeedSchema.js";
15
- import { AnyCoListSchema } from "../schemaTypes/CoListSchema.js";
16
- import { AnyCoMapSchema } from "../schemaTypes/CoMapSchema.js";
17
- import { FileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
18
- import { PlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
19
- import { RichTextSchema } from "../schemaTypes/RichTextSchema.js";
18
+ import { CoreCoFeedSchema } from "../schemaTypes/CoFeedSchema.js";
19
+ import { CoreCoListSchema } from "../schemaTypes/CoListSchema.js";
20
+ import { CoreCoMapSchema } from "../schemaTypes/CoMapSchema.js";
21
+ import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
22
+ import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js";
23
+ import { CoreFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
24
+ import { CorePlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
25
+ import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js";
20
26
  import { z } from "../zodReExport.js";
21
27
 
22
28
  export type InstanceOrPrimitiveOfSchemaCoValuesNullable<
23
- S extends CoValueClass | z.core.$ZodType,
24
- > = S extends z.core.$ZodType
25
- ? S extends z.core.$ZodObject<infer Shape> & {
26
- collaborative: true;
27
- builtin: "Account";
28
- }
29
+ S extends CoValueClass | AnyZodOrCoValueSchema,
30
+ > = S extends CoreCoValueSchema
31
+ ? S extends CoreAccountSchema<infer Shape>
29
32
  ?
30
33
  | ({
31
34
  -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
@@ -33,94 +36,100 @@ export type InstanceOrPrimitiveOfSchemaCoValuesNullable<
33
36
  >;
34
37
  } & { profile: Profile | null } & Account)
35
38
  | null
36
- : S extends z.core.$ZodRecord<infer K, infer V> & {
37
- collaborative: true;
38
- }
39
+ : S extends CoreCoRecordSchema<infer K, infer V>
39
40
  ?
40
41
  | ({
41
42
  -readonly [key in z.output<K> &
42
43
  string]: InstanceOrPrimitiveOfSchemaCoValuesNullable<V>;
43
44
  } & CoMap)
44
45
  | null
45
- : S extends AnyCoMapSchema<infer Shape, infer Config>
46
+ : S extends CoreCoMapSchema<infer Shape, infer CatchAll>
46
47
  ?
47
48
  | ({
48
49
  -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
49
50
  Shape[key]
50
51
  >;
51
- } & (unknown extends Config["out"][string]
52
+ } & (unknown extends CatchAll
52
53
  ? {}
53
54
  : {
54
- [key: string]: Config["out"][string];
55
+ [
56
+ key: string // @ts-expect-error
57
+ ]: InstanceOrPrimitiveOfSchemaCoValuesNullable<CatchAll>;
55
58
  }) &
56
59
  CoMap)
57
60
  | null
58
- : S extends AnyCoListSchema<infer T>
61
+ : S extends CoreCoListSchema<infer T>
59
62
  ? CoList<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>> | null
60
- : S extends AnyCoFeedSchema<infer T>
63
+ : S extends CoreCoFeedSchema<infer T>
61
64
  ? CoFeed<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>> | null
62
- : S extends PlainTextSchema
65
+ : S extends CorePlainTextSchema
63
66
  ? CoPlainText | null
64
- : S extends RichTextSchema
67
+ : S extends CoreRichTextSchema
65
68
  ? CoRichText | null
66
- : S extends FileStreamSchema
69
+ : S extends CoreFileStreamSchema
67
70
  ? FileStream | null
68
- : S extends z.core.$ZodOptional<infer Inner>
69
- ?
70
- | InstanceOrPrimitiveOfSchemaCoValuesNullable<Inner>
71
- | undefined
72
- : S extends z.ZodJSONSchema
73
- ? JsonValue
74
- : S extends z.core.$ZodUnion<infer Members>
75
- ? InstanceOrPrimitiveOfSchemaCoValuesNullable<
76
- Members[number]
77
- >
78
- : // primitives below here - we manually traverse to ensure we only allow what we can handle
79
- S extends z.core.$ZodObject<infer Shape>
80
- ? {
81
- -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<
82
- Shape[key]
83
- >;
84
- }
85
- : S extends z.core.$ZodArray<infer Item>
86
- ? InstanceOrPrimitiveOfSchema<Item>[]
87
- : S extends z.core.$ZodTuple<infer Items>
88
- ? {
89
- [key in keyof Items]: InstanceOrPrimitiveOfSchema<
90
- Items[key]
91
- >;
92
- }
93
- : S extends z.core.$ZodString
94
- ? string
95
- : S extends z.core.$ZodNumber
96
- ? number
97
- : S extends z.core.$ZodBoolean
98
- ? boolean
99
- : S extends z.core.$ZodLiteral<
100
- infer Literal
101
- >
102
- ? Literal
103
- : S extends z.core.$ZodDate
104
- ? Date
105
- : S extends z.core.$ZodEnum<infer Enum>
106
- ? Enum[keyof Enum]
107
- : S extends z.core.$ZodTemplateLiteral<
108
- infer pattern
109
- >
110
- ? pattern
111
- : S extends z.core.$ZodReadonly<
112
- infer Inner
113
- >
114
- ? InstanceOrPrimitiveOfSchema<Inner>
115
- : S extends z.core.$ZodDefault<
116
- infer Default
117
- >
118
- ? InstanceOrPrimitiveOfSchema<Default>
119
- : S extends z.core.$ZodCatch<
120
- infer Catch
121
- >
122
- ? InstanceOrPrimitiveOfSchema<Catch>
123
- : never
124
- : S extends CoValueClass
125
- ? InstanceType<S> | null
126
- : never;
71
+ : S extends CoreCoOptionalSchema<infer T>
72
+ ? InstanceOrPrimitiveOfSchemaCoValuesNullable<T> | undefined
73
+ : S extends CoDiscriminatedUnionSchema<infer Members>
74
+ ? InstanceOrPrimitiveOfSchemaCoValuesNullable<
75
+ Members[number]
76
+ >
77
+ : never
78
+ : S extends z.core.$ZodType
79
+ ? S extends z.core.$ZodOptional<infer Inner extends z.core.$ZodType>
80
+ ? InstanceOrPrimitiveOfSchemaCoValuesNullable<Inner> | undefined
81
+ : S extends z.ZodJSONSchema
82
+ ? JsonValue
83
+ : S extends z.core.$ZodUnion<
84
+ infer Members extends readonly z.core.$ZodType[]
85
+ >
86
+ ? InstanceOrPrimitiveOfSchemaCoValuesNullable<Members[number]>
87
+ : // primitives below here - we manually traverse to ensure we only allow what we can handle
88
+ S extends z.core.$ZodObject<infer Shape>
89
+ ? {
90
+ -readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<
91
+ Shape[key]
92
+ >;
93
+ }
94
+ : S extends z.core.$ZodArray<infer Item extends z.core.$ZodType>
95
+ ? InstanceOrPrimitiveOfSchema<Item>[]
96
+ : S extends z.core.$ZodTuple<
97
+ infer Items extends z.core.$ZodType[]
98
+ >
99
+ ? {
100
+ [key in keyof Items]: InstanceOrPrimitiveOfSchema<
101
+ Items[key]
102
+ >;
103
+ }
104
+ : S extends z.core.$ZodString
105
+ ? string
106
+ : S extends z.core.$ZodNumber
107
+ ? number
108
+ : S extends z.core.$ZodBoolean
109
+ ? boolean
110
+ : S extends z.core.$ZodLiteral<infer Literal>
111
+ ? Literal
112
+ : S extends z.core.$ZodDate
113
+ ? Date
114
+ : S extends z.core.$ZodEnum<infer Enum>
115
+ ? Enum[keyof Enum]
116
+ : S extends z.core.$ZodTemplateLiteral<
117
+ infer pattern
118
+ >
119
+ ? pattern
120
+ : S extends z.core.$ZodReadonly<
121
+ infer Inner extends z.core.$ZodType
122
+ >
123
+ ? InstanceOrPrimitiveOfSchema<Inner>
124
+ : S extends z.core.$ZodDefault<
125
+ infer Default extends z.core.$ZodType
126
+ >
127
+ ? InstanceOrPrimitiveOfSchema<Default>
128
+ : S extends z.core.$ZodCatch<
129
+ infer Catch extends z.core.$ZodType
130
+ >
131
+ ? InstanceOrPrimitiveOfSchema<Catch>
132
+ : never
133
+ : S extends CoValueClass
134
+ ? InstanceType<S> | null
135
+ : never;
@@ -1,34 +1,34 @@
1
1
  import { RawAccount, RawCoList, RawCoMap } from "cojson";
2
- import { CoValueClass, CoValueFromRaw } from "../../internal.js";
3
2
  import {
3
+ AnyZodOrCoValueSchema,
4
+ CoDiscriminatedUnionSchema,
5
+ CoMap,
6
+ CoreCoDiscriminatedUnionSchema,
7
+ CoreCoMapSchema,
8
+ DiscriminableCoValueSchemas,
9
+ DiscriminableCoreCoValueSchema,
10
+ } from "../../internal.js";
11
+ import {
12
+ hydrateCoreCoValueSchema,
4
13
  isAnyCoValueSchema,
5
- zodSchemaToCoSchema,
6
- } from "./runtimeConverters/zodSchemaToCoSchema.js";
7
- import { AccountSchema } from "./schemaTypes/AccountSchema.js";
8
- import { CoListSchema } from "./schemaTypes/CoListSchema.js";
9
- import { CoMapSchema } from "./schemaTypes/CoMapSchema.js";
14
+ } from "./runtimeConverters/coValueSchemaTransformation.js";
10
15
  import { z } from "./zodReExport.js";
11
16
 
12
17
  export function schemaUnionDiscriminatorFor(
13
- schema: z.core.$ZodDiscriminatedUnion,
18
+ schema: CoreCoDiscriminatedUnionSchema<DiscriminableCoValueSchemas>,
14
19
  ) {
15
20
  if (isUnionOfCoMapsDeeply(schema)) {
16
- if (!schema._zod.disc || schema._zod.disc.size == 0) {
17
- throw new Error(
18
- "z.union() of collaborative types is not supported, use co.discriminatedUnion() instead",
19
- );
20
- }
21
-
22
- const discriminator = schema._zod.def.discriminator;
23
- const field = schema._zod.disc.get(discriminator);
21
+ const definition = schema.getDefinition();
22
+ const { discriminatorMap, discriminator, options } = definition;
24
23
 
24
+ const field = discriminatorMap[discriminator];
25
25
  if (!field) {
26
26
  throw new Error(
27
27
  "co.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported",
28
28
  );
29
29
  }
30
30
 
31
- for (const value of field.values) {
31
+ for (const value of field) {
32
32
  if (typeof value !== "string" && typeof value !== "number") {
33
33
  throw new Error(
34
34
  "co.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported",
@@ -36,15 +36,17 @@ export function schemaUnionDiscriminatorFor(
36
36
  }
37
37
  }
38
38
 
39
- const availableOptions: z.core.$ZodObject[] = [];
40
-
41
- for (const option of schema._zod.def.options) {
42
- if (option._zod.def.type === "object") {
43
- availableOptions.push(option as z.core.$ZodObject);
44
- } else if (option._zod.def.type === "union") {
45
- for (const subOption of (option as z.core.$ZodUnion)._zod.def.options) {
46
- if (subOption._zod.def.type === "object") {
47
- availableOptions.push(subOption as z.core.$ZodObject);
39
+ const availableOptions: DiscriminableCoreCoValueSchema[] = [];
40
+
41
+ for (const option of options) {
42
+ if (option.builtin === "CoMap") {
43
+ availableOptions.push(option);
44
+ } else if (option.builtin === "CoDiscriminatedUnion") {
45
+ for (const subOption of (
46
+ option as CoDiscriminatedUnionSchema<any>
47
+ ).getDefinition().options) {
48
+ if (!options.includes(subOption)) {
49
+ options.push(subOption);
48
50
  }
49
51
  }
50
52
  } else {
@@ -64,10 +66,9 @@ export function schemaUnionDiscriminatorFor(
64
66
  for (const option of availableOptions) {
65
67
  let match = true;
66
68
 
67
- for (const key of schema._zod.disc.keys()) {
68
- const discriminatorDef = (option as z.core.$ZodObject)._zod.def.shape[
69
- key as string
70
- ];
69
+ for (const key of Object.keys(discriminatorMap)) {
70
+ const discriminatorDef = (option as CoreCoMapSchema).getDefinition()
71
+ .shape[key as string];
71
72
 
72
73
  const discriminatorValue = (_raw as RawCoMap).get(key as string);
73
74
 
@@ -88,7 +89,8 @@ export function schemaUnionDiscriminatorFor(
88
89
  break;
89
90
  }
90
91
 
91
- const literalDef = discriminatorDef._zod.def as z.core.$ZodLiteralDef;
92
+ const literalDef = discriminatorDef._zod
93
+ .def as z.core.$ZodLiteralDef<any>;
92
94
 
93
95
  if (!Array.from(literalDef.values).includes(discriminatorValue)) {
94
96
  match = false;
@@ -97,12 +99,8 @@ export function schemaUnionDiscriminatorFor(
97
99
  }
98
100
 
99
101
  if (match) {
100
- const coValueSchema = zodSchemaToCoSchema(option) as
101
- | CoMapSchema<any>
102
- | AccountSchema
103
- | CoListSchema<any>;
104
- return coValueSchema.getCoValueClass() as CoValueClass<any> &
105
- CoValueFromRaw<any>;
102
+ const coValueSchema = hydrateCoreCoValueSchema(option as any);
103
+ return coValueSchema.getCoValueClass() as typeof CoMap;
106
104
  }
107
105
  }
108
106
 
@@ -114,34 +112,32 @@ export function schemaUnionDiscriminatorFor(
114
112
  return determineSchema;
115
113
  } else {
116
114
  throw new Error(
117
- "z.discriminatedUnion() of non-collaborative types is not supported",
115
+ "co.discriminatedUnion() of non-collaborative types is not supported",
118
116
  );
119
117
  }
120
118
  }
121
119
 
122
- export function isUnionOfCoMapsDeeply(
123
- schema: z.core.$ZodType,
124
- ): schema is z.core.$ZodDiscriminatedUnion {
125
- if (schema instanceof z.core.$ZodUnion) {
126
- return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
127
- } else {
128
- return false;
129
- }
120
+ function isUnionOfCoMapsDeeply(
121
+ schema: CoreCoDiscriminatedUnionSchema<DiscriminableCoValueSchemas>,
122
+ ): boolean {
123
+ return schema.getDefinition().options.every(isCoMapOrUnionOfCoMapsDeeply);
130
124
  }
131
125
 
132
126
  function isCoMapOrUnionOfCoMapsDeeply(
133
- schema: z.core.$ZodType,
134
- ): schema is z.core.$ZodDiscriminatedUnion {
135
- if (schema instanceof z.core.$ZodObject && isAnyCoValueSchema(schema)) {
127
+ schema: DiscriminableCoreCoValueSchema,
128
+ ): boolean {
129
+ if (schema.builtin === "CoMap") {
136
130
  return true;
137
- } else if (schema instanceof z.core.$ZodUnion) {
138
- return schema._zod.def.options.every(isCoMapOrUnionOfCoMapsDeeply);
131
+ } else if (schema.builtin === "CoDiscriminatedUnion") {
132
+ return (schema as CoDiscriminatedUnionSchema<any>)
133
+ .getDefinition()
134
+ .options.every(isCoMapOrUnionOfCoMapsDeeply);
139
135
  } else {
140
136
  return false;
141
137
  }
142
138
  }
143
139
 
144
- export function isUnionOfPrimitivesDeeply(schema: z.core.$ZodType) {
140
+ export function isUnionOfPrimitivesDeeply(schema: AnyZodOrCoValueSchema) {
145
141
  if (schema instanceof z.core.$ZodUnion) {
146
142
  return schema._zod.def.options.every(isUnionOfPrimitivesDeeply);
147
143
  } else {