jazz-tools 0.15.16 → 0.16.1

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 (203) 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 +44 -44
  7. package/CHANGELOG.md +34 -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-CL3ROOZM.js} +598 -598
  15. package/dist/chunk-CL3ROOZM.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 +8 -23
  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 +3 -3
  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 +17 -14
  74. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  75. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -17
  76. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  77. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +31 -34
  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 +19 -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/CoFieldInit.d.ts +10 -0
  92. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +1 -0
  93. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +15 -13
  94. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +12 -15
  96. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +17 -20
  98. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +17 -20
  100. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/unionUtils.d.ts +3 -5
  102. package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
  103. package/dist/tools/implementation/zodSchema/zodCo.d.ts +10 -8
  104. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  105. package/dist/tools/implementation/zodSchema/zodReExport.d.ts +4 -8
  106. package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
  107. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +21 -30
  108. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  109. package/dist/tools/internal.d.ts +3 -2
  110. package/dist/tools/internal.d.ts.map +1 -1
  111. package/dist/tools/lib/utilityTypes.d.ts +18 -0
  112. package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
  113. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  114. package/dist/tools/testing.d.ts +2 -2
  115. package/dist/tools/testing.d.ts.map +1 -1
  116. package/dist/worker/index.d.ts.map +1 -1
  117. package/dist/worker/index.js +2 -2
  118. package/dist/worker/index.js.map +1 -1
  119. package/package.json +5 -5
  120. package/src/browser/index.ts +2 -4
  121. package/src/browser-media-images/index.ts +1 -1
  122. package/src/react/hooks.tsx +2 -2
  123. package/src/react-core/hooks.ts +6 -6
  124. package/src/react-core/tests/useAccount.test.ts +2 -2
  125. package/src/react-core/tests/useCoState.test.ts +3 -2
  126. package/src/react-native-core/hooks.tsx +2 -2
  127. package/src/svelte/jazz.class.svelte.ts +10 -7
  128. package/src/svelte/jazz.svelte.ts +2 -2
  129. package/src/tools/coValues/CoValueBase.ts +8 -20
  130. package/src/tools/coValues/account.ts +18 -14
  131. package/src/tools/coValues/coFeed.ts +0 -4
  132. package/src/tools/coValues/coList.ts +7 -9
  133. package/src/tools/coValues/coMap.ts +5 -13
  134. package/src/tools/coValues/coPlainText.ts +4 -4
  135. package/src/tools/coValues/deepLoading.ts +4 -1
  136. package/src/tools/coValues/extensions/imageDef.ts +3 -3
  137. package/src/tools/coValues/inbox.ts +4 -4
  138. package/src/tools/coValues/interfaces.ts +4 -71
  139. package/src/tools/coValues/request.ts +17 -15
  140. package/src/tools/coValues/schemaUnion.ts +8 -4
  141. package/src/tools/exports.ts +3 -14
  142. package/src/tools/implementation/createContext.ts +9 -9
  143. package/src/tools/implementation/invites.ts +2 -2
  144. package/src/tools/implementation/schemaUtils.ts +18 -0
  145. package/src/tools/implementation/zodSchema/coExport.ts +14 -0
  146. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +156 -0
  147. package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +149 -0
  148. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +36 -17
  149. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +101 -52
  150. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +54 -50
  151. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +54 -46
  152. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +190 -161
  153. package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +29 -27
  154. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +28 -18
  155. package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +18 -0
  156. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +45 -36
  157. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +47 -35
  158. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +43 -30
  159. package/src/tools/implementation/zodSchema/typeConverters/CoFieldInit.ts +13 -0
  160. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +30 -26
  161. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +31 -28
  162. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +89 -80
  163. package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +95 -84
  164. package/src/tools/implementation/zodSchema/unionUtils.ts +47 -51
  165. package/src/tools/implementation/zodSchema/zodCo.ts +43 -76
  166. package/src/tools/implementation/zodSchema/zodReExport.ts +44 -24
  167. package/src/tools/implementation/zodSchema/zodSchema.ts +65 -103
  168. package/src/tools/internal.ts +3 -2
  169. package/src/tools/lib/utilityTypes.ts +16 -0
  170. package/src/tools/subscribe/utils.ts +4 -2
  171. package/src/tools/testing.ts +4 -4
  172. package/src/tools/tests/ContextManager.test.ts +8 -9
  173. package/src/tools/tests/account.test.ts +65 -3
  174. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +38 -0
  175. package/src/tools/tests/coDiscriminatedUnion.test.ts +219 -1
  176. package/src/tools/tests/coFeed.test-d.ts +4 -3
  177. package/src/tools/tests/coFeed.test.ts +8 -6
  178. package/src/tools/tests/coList.test-d.ts +32 -3
  179. package/src/tools/tests/coList.test.ts +30 -2
  180. package/src/tools/tests/coMap.record.test-d.ts +31 -3
  181. package/src/tools/tests/coMap.record.test.ts +18 -9
  182. package/src/tools/tests/coMap.test-d.ts +36 -8
  183. package/src/tools/tests/coMap.test.ts +87 -6
  184. package/src/tools/tests/coOptional.test.ts +63 -1
  185. package/src/tools/tests/createContext.test.ts +7 -9
  186. package/src/tools/tests/deepLoading.test.ts +4 -10
  187. package/src/tools/tests/exportImport.test.ts +2 -2
  188. package/src/tools/tests/groupsAndAccounts.test.ts +5 -4
  189. package/src/tools/tests/inbox.test.ts +3 -2
  190. package/src/tools/tests/load.test.ts +3 -29
  191. package/src/tools/tests/schemaUnion.test.ts +2 -2
  192. package/src/tools/tests/subscribe.test.ts +22 -114
  193. package/src/tools/tests/testing.test.ts +6 -6
  194. package/src/tools/tests/zod.test-d.ts +27 -0
  195. package/src/tools/tests/zod.test.ts +88 -45
  196. package/src/worker/index.ts +0 -1
  197. package/dist/chunk-OSVAAVWQ.js.map +0 -1
  198. package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +0 -12
  199. package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +0 -1
  200. package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +0 -9
  201. package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +0 -1
  202. package/src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +0 -172
  203. package/src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +0 -218
@@ -1,52 +1,43 @@
1
1
  import {
2
2
  type AccountSchema,
3
- AnyAccountSchema,
4
- AnyCoFeedSchema,
5
- AnyCoListSchema,
6
- AnyCoSchema,
7
- AnyFileStreamSchema,
8
- AnyPlainTextSchema,
3
+ AnyZodOrCoValueSchema,
9
4
  BaseAccountShape,
10
- CoFeed,
11
5
  type CoFeedSchema,
12
6
  type CoListSchema,
13
7
  type CoMapSchema,
14
- CoPlainText,
15
8
  type CoProfileSchema,
16
9
  type CoRecordSchema,
17
- CoRichText,
18
10
  type DefaultProfileShape,
19
- FileStream,
20
11
  type FileStreamSchema,
21
12
  ImageDefinition,
22
13
  type PlainTextSchema,
23
14
  type Simplify,
24
- zodSchemaToCoSchema,
15
+ createCoreAccountSchema,
16
+ createCoreCoFeedSchema,
17
+ createCoreCoListSchema,
18
+ createCoreCoMapSchema,
19
+ createCoreCoPlainTextSchema,
20
+ createCoreFileStreamSchema,
21
+ hydrateCoreCoValueSchema,
25
22
  } from "../../internal.js";
26
23
  import {
27
- AnyDiscriminableCoSchema,
28
24
  CoDiscriminatedUnionSchema,
25
+ DiscriminableCoValueSchemas,
26
+ createCoreCoDiscriminatedUnionSchema,
29
27
  } from "./schemaTypes/CoDiscriminatedUnionSchema.js";
28
+ import { CoOptionalSchema } from "./schemaTypes/CoOptionalSchema.js";
29
+ import { CoreCoValueSchema } from "./schemaTypes/CoValueSchema.js";
30
30
  import {
31
- CoOptionalSchema,
32
- createCoOptionalSchema,
33
- } from "./schemaTypes/CoOptionalSchema.js";
34
- import {
35
- AnyRichTextSchema,
36
31
  RichTextSchema,
32
+ createCoreCoRichTextSchema,
37
33
  } from "./schemaTypes/RichTextSchema.js";
38
34
  import { z } from "./zodReExport.js";
39
35
 
40
36
  export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
41
37
  shape: Shape,
42
38
  ): CoMapSchema<Shape> => {
43
- const objectSchema = z.object(shape).meta({
44
- collaborative: true,
45
- });
46
- const enrichedSchema = Object.assign(objectSchema, {
47
- collaborative: true,
48
- });
49
- return zodSchemaToCoSchema(enrichedSchema);
39
+ const coreSchema = createCoreCoMapSchema(shape);
40
+ return hydrateCoreCoValueSchema(coreSchema);
50
41
  };
51
42
 
52
43
  /**
@@ -96,19 +87,13 @@ export const coAccountDefiner = <Shape extends BaseAccountShape>(
96
87
  root: coMapDefiner({}),
97
88
  } as unknown as Shape,
98
89
  ): AccountSchema<Shape> => {
99
- const schema = z.object(shape).meta({
100
- collaborative: true,
101
- });
102
- const enrichedSchema = Object.assign(schema, {
103
- collaborative: true,
104
- builtin: "Account",
105
- }) as AnyAccountSchema<Shape>;
106
- return zodSchemaToCoSchema(enrichedSchema);
90
+ const coreSchema = createCoreAccountSchema(shape);
91
+ return hydrateCoreCoValueSchema(coreSchema);
107
92
  };
108
93
 
109
94
  export const coRecordDefiner = <
110
95
  K extends z.core.$ZodString<string>,
111
- V extends z.core.$ZodType,
96
+ V extends AnyZodOrCoValueSchema,
112
97
  >(
113
98
  _keyType: K,
114
99
  valueType: V,
@@ -119,16 +104,11 @@ export const coRecordDefiner = <
119
104
  >;
120
105
  };
121
106
 
122
- export const coListDefiner = <T extends z.core.$ZodType>(
107
+ export const coListDefiner = <T extends AnyZodOrCoValueSchema>(
123
108
  element: T,
124
109
  ): CoListSchema<T> => {
125
- const schema = z.array(element).meta({
126
- collaborative: true,
127
- });
128
- const enrichedSchema = Object.assign(schema, {
129
- collaborative: true,
130
- }) as AnyCoListSchema<T>;
131
- return zodSchemaToCoSchema(enrichedSchema) as unknown as CoListSchema<T>;
110
+ const coreSchema = createCoreCoListSchema(element);
111
+ return hydrateCoreCoValueSchema(coreSchema);
132
112
  };
133
113
 
134
114
  export const coProfileDefiner = <
@@ -141,64 +121,51 @@ export const coProfileDefiner = <
141
121
  inbox: z.optional(z.string()),
142
122
  inboxInvite: z.optional(z.string()),
143
123
  });
144
- return coMapDefiner(ehnancedShape) as CoProfileSchema<Shape>;
124
+ return coMapDefiner(ehnancedShape) as unknown as CoProfileSchema<Shape>;
145
125
  };
146
126
 
147
- export const coFeedDefiner = <T extends z.core.$ZodType>(
127
+ export const coFeedDefiner = <T extends AnyZodOrCoValueSchema>(
148
128
  element: T,
149
129
  ): CoFeedSchema<T> => {
150
- const schema = z.instanceof(CoFeed);
151
- const enrichedSchema = Object.assign(schema, {
152
- collaborative: true,
153
- builtin: "CoFeed",
154
- element,
155
- }) as AnyCoFeedSchema<T>;
156
- return zodSchemaToCoSchema(enrichedSchema);
130
+ const coreSchema = createCoreCoFeedSchema(element);
131
+ return hydrateCoreCoValueSchema(coreSchema);
157
132
  };
158
133
 
159
134
  export const coFileStreamDefiner = (): FileStreamSchema => {
160
- const schema = z.instanceof(FileStream);
161
- const enrichedSchema = Object.assign(schema, {
162
- collaborative: true,
163
- builtin: "FileStream",
164
- }) as AnyFileStreamSchema;
165
- return zodSchemaToCoSchema(enrichedSchema);
135
+ const coreSchema = createCoreFileStreamSchema();
136
+ return hydrateCoreCoValueSchema(coreSchema);
166
137
  };
167
138
 
168
139
  export const coPlainTextDefiner = (): PlainTextSchema => {
169
- const schema = z.instanceof(CoPlainText);
170
- const enrichedSchema = Object.assign(schema, {
171
- collaborative: true,
172
- builtin: "CoPlainText",
173
- }) as AnyPlainTextSchema;
174
- return zodSchemaToCoSchema(enrichedSchema);
140
+ const coreSchema = createCoreCoPlainTextSchema();
141
+ return hydrateCoreCoValueSchema(coreSchema);
175
142
  };
176
143
 
177
144
  export const coRichTextDefiner = (): RichTextSchema => {
178
- const schema = z.instanceof(CoRichText);
179
- const enrichedSchema = Object.assign(schema, {
180
- collaborative: true,
181
- builtin: "CoRichText",
182
- }) as AnyRichTextSchema;
183
- return zodSchemaToCoSchema(enrichedSchema);
145
+ const coreSchema = createCoreCoRichTextSchema();
146
+ return hydrateCoreCoValueSchema(coreSchema);
184
147
  };
185
148
 
186
- export const coImageDefiner = (): typeof ImageDefinition => {
149
+ export type ImageDefinitionSchema = typeof ImageDefinition;
150
+ export const coImageDefiner = (): ImageDefinitionSchema => {
187
151
  return ImageDefinition;
188
152
  };
189
153
 
190
- export const coOptionalDefiner = <T extends AnyCoSchema>(
154
+ export const coOptionalDefiner = <T extends CoreCoValueSchema>(
191
155
  schema: T,
192
156
  ): CoOptionalSchema<T> => {
193
- return createCoOptionalSchema(schema);
157
+ return new CoOptionalSchema(schema);
194
158
  };
195
159
 
196
160
  export const coDiscriminatedUnionDefiner = <
197
- T extends readonly [AnyDiscriminableCoSchema, ...AnyDiscriminableCoSchema[]],
161
+ Options extends DiscriminableCoValueSchemas,
198
162
  >(
199
163
  discriminator: string,
200
- schemas: T,
201
- ): CoDiscriminatedUnionSchema<T> => {
202
- const schema = z.discriminatedUnion(discriminator, schemas as any);
203
- return zodSchemaToCoSchema(schema);
164
+ schemas: Options,
165
+ ): CoDiscriminatedUnionSchema<Options> => {
166
+ const coreSchema = createCoreCoDiscriminatedUnionSchema(
167
+ discriminator,
168
+ schemas,
169
+ );
170
+ return hydrateCoreCoValueSchema(coreSchema);
204
171
  };
@@ -1,17 +1,14 @@
1
1
  import {
2
- ZodArray,
3
- ZodTuple,
4
- ZodUnion,
2
+ ZodObject,
5
3
  core,
6
- array as zodArray,
7
- tuple as zodTuple,
8
- union as zodUnion,
4
+ object as zodObject,
5
+ strictObject as zodStrictObject,
9
6
  } from "zod/v4";
7
+ import { removeGetters } from "../schemaUtils.js";
10
8
  export {
11
9
  string,
12
10
  number,
13
11
  boolean,
14
- object,
15
12
  templateLiteral,
16
13
  json,
17
14
  date,
@@ -33,12 +30,14 @@ export {
33
30
  cidrv6,
34
31
  iso,
35
32
  int32,
36
- strictObject,
33
+ union,
37
34
  discriminatedUnion,
38
35
  // record,
39
36
  // intersection,
40
37
  int,
41
38
  optional,
39
+ array,
40
+ tuple,
42
41
  type ZodOptional,
43
42
  type ZodReadonly,
44
43
  type ZodLazy,
@@ -49,25 +48,46 @@ export {
49
48
  z,
50
49
  } from "zod/v4";
51
50
 
52
- type NonCoZodType = core.$ZodType & { collaborative?: false };
51
+ export function object<
52
+ T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>,
53
+ >(
54
+ shape?: T,
55
+ params?: string | core.$ZodObjectParams,
56
+ ): ZodObject<T, core.$strip> {
57
+ rejectCoValueSchemas(
58
+ shape,
59
+ "z.object() does not support collaborative types as values. Use co.map() instead",
60
+ );
61
+ return zodObject(shape, params);
62
+ }
63
+
64
+ export function strictObject<T extends core.$ZodLooseShape>(
65
+ shape: T,
66
+ params?: string | core.$ZodObjectParams,
67
+ ): ZodObject<T, core.$strict> {
68
+ rejectCoValueSchemas(
69
+ shape,
70
+ "z.strictObject() does not support collaborative types as values. Use co.map() instead",
71
+ );
72
+ return zodStrictObject(shape, params);
73
+ }
53
74
 
54
- export function union<const T extends readonly NonCoZodType[]>(
55
- options: T,
56
- params?: string | core.$ZodUnionParams,
57
- ): ZodUnion<T> {
58
- return zodUnion(options, params);
75
+ function rejectCoValueSchemas(
76
+ shape: core.$ZodLooseShape | undefined,
77
+ errorMessage: string,
78
+ ) {
79
+ if (containsCoValueSchema(shape)) {
80
+ throw Error(errorMessage);
81
+ }
59
82
  }
60
83
 
61
- export function array<T extends NonCoZodType>(
62
- element: T,
63
- params?: string | core.$ZodArrayParams,
64
- ): ZodArray<T> {
65
- return zodArray(element, params);
84
+ function containsCoValueSchema(shape?: core.$ZodLooseShape): boolean {
85
+ // Remove getters to avoid circularity issues accessing schemas that may not be defined yet
86
+ return Object.values(removeGetters(shape ?? {})).some(isAnyCoValueSchema);
66
87
  }
67
88
 
68
- export function tuple<T extends readonly [NonCoZodType, ...NonCoZodType[]]>(
69
- options: T,
70
- params?: string | core.$ZodTupleParams,
71
- ): ZodTuple<T> {
72
- return zodTuple(options, params);
89
+ // Note: if you're editing this function, edit the `isAnyCoValueSchema`
90
+ // function in `zodSchemaToCoSchema.ts` as well
91
+ function isAnyCoValueSchema(schema: any): boolean {
92
+ return "collaborative" in schema && schema.collaborative === true;
73
93
  }
@@ -2,8 +2,10 @@ import { LocalNode, RawAccount } from "cojson";
2
2
  import {
3
3
  Account,
4
4
  AccountClass,
5
+ CoRecordSchema,
5
6
  CoValueClass,
6
7
  CoValueFromRaw,
8
+ CoreCoRecordSchema,
7
9
  InstanceOfSchema,
8
10
  RefsToResolve,
9
11
  RefsToResolveStrict,
@@ -12,47 +14,40 @@ import {
12
14
  } from "../../internal.js";
13
15
  import {
14
16
  AccountSchema,
15
- AnyAccountSchema,
16
17
  BaseAccountShape,
18
+ CoreAccountSchema,
17
19
  } from "./schemaTypes/AccountSchema.js";
18
20
  import {
19
- AnyDiscriminableCoSchema,
20
21
  CoDiscriminatedUnionSchema,
22
+ CoreCoDiscriminatedUnionSchema,
21
23
  } from "./schemaTypes/CoDiscriminatedUnionSchema.js";
22
- import { AnyCoFeedSchema, CoFeedSchema } from "./schemaTypes/CoFeedSchema.js";
23
- import { AnyCoListSchema, CoListSchema } from "./schemaTypes/CoListSchema.js";
24
+ import { CoFeedSchema, CoreCoFeedSchema } from "./schemaTypes/CoFeedSchema.js";
25
+ import { CoListSchema, CoreCoListSchema } from "./schemaTypes/CoListSchema.js";
24
26
  import {
25
- AnyCoMapSchema,
26
- CoMapInitZod,
27
27
  CoMapSchema,
28
+ CoMapSchemaInit,
29
+ CoreCoMapSchema,
28
30
  } from "./schemaTypes/CoMapSchema.js";
29
- import { AnyCoOptionalSchema } from "./schemaTypes/CoOptionalSchema.js";
30
31
  import {
31
- AnyCoRecordSchema,
32
- CoRecordSchema,
33
- } from "./schemaTypes/CoRecordSchema.js";
32
+ CoOptionalSchema,
33
+ CoreCoOptionalSchema,
34
+ } from "./schemaTypes/CoOptionalSchema.js";
35
+ import { CoreCoValueSchema } from "./schemaTypes/CoValueSchema.js";
34
36
  import {
35
- AnyFileStreamSchema,
37
+ CoreFileStreamSchema,
36
38
  FileStreamSchema,
37
39
  } from "./schemaTypes/FileStreamSchema.js";
38
40
  import {
39
- AnyPlainTextSchema,
41
+ CorePlainTextSchema,
40
42
  PlainTextSchema,
41
43
  } from "./schemaTypes/PlainTextSchema.js";
42
44
  import {
43
- AnyRichTextSchema,
45
+ CoreRichTextSchema,
44
46
  RichTextSchema,
45
47
  } from "./schemaTypes/RichTextSchema.js";
46
48
  import { InstanceOfSchemaCoValuesNullable } from "./typeConverters/InstanceOfSchemaCoValuesNullable.js";
47
49
  import { z } from "./zodReExport.js";
48
50
 
49
- // defining an extra type for this, otherwise BaseSchema & {...} often
50
- // gets expanded into a n inferred type that's too long for typescript to print
51
- export type WithHelpers<
52
- Base extends z.core.$ZodType,
53
- Helpers extends object,
54
- > = Base & Helpers;
55
-
56
51
  export type ZodPrimitiveSchema =
57
52
  | z.core.$ZodString
58
53
  | z.core.$ZodNumber
@@ -61,108 +56,75 @@ export type ZodPrimitiveSchema =
61
56
  | z.core.$ZodDate
62
57
  | z.core.$ZodLiteral;
63
58
 
64
- export type AnyCoUnionSchema = z.core.$ZodDiscriminatedUnion<
65
- (
66
- | (z.core.$ZodType & { collaborative: true })
67
- | z.core.$ZodDiscriminatedUnion
68
- )[]
69
- >;
70
-
71
- // this is a series of hacks to work around z4 removing _zod at runtime from z.core.$ZodType
72
- export function isZodObject(
73
- schema: z.core.$ZodType,
74
- ): schema is z.ZodObject<any, any> {
75
- return (schema as any).def?.type === "object";
76
- }
77
-
78
- export function isZodArray(
79
- schema: z.core.$ZodType,
80
- ): schema is z.core.$ZodArray<any> {
81
- return (schema as any).def?.type === "array";
82
- }
83
-
84
- export function isZodCustom(
85
- schema: z.core.$ZodType,
86
- ): schema is z.core.$ZodCustom<any, any> {
87
- return (schema as any).def?.type === "custom";
88
- }
89
-
90
- export function getDef<S extends z.core.$ZodType>(schema: S): S["_zod"]["def"] {
91
- return (schema as any).def;
92
- }
93
-
94
- // TODO rename. This represents a CoValue class or a CoValue schema
95
- export type CoValueOrZodSchema = CoValueClass | AnyCoSchema;
96
-
97
- // TODO rename to CoValueSchemaFromCoProtoSchema
98
- export type CoValueSchemaFromZodSchema<S extends z.core.$ZodType> =
99
- S extends z.core.$ZodType
100
- ? S extends AnyAccountSchema<infer Shape extends BaseAccountShape>
101
- ? AccountSchema<Shape>
102
- : S extends AnyCoRecordSchema<infer K, infer V>
103
- ? CoRecordSchema<K, V>
104
- : S extends AnyCoMapSchema<infer Shape, infer Config>
105
- ? CoMapSchema<Shape, Config>
106
- : S extends AnyCoListSchema<infer T>
107
- ? CoListSchema<T>
108
- : S extends AnyCoFeedSchema<infer T>
109
- ? CoFeedSchema<T>
110
- : S extends AnyPlainTextSchema
111
- ? PlainTextSchema
112
- : S extends AnyRichTextSchema
113
- ? RichTextSchema
114
- : S extends AnyFileStreamSchema
115
- ? FileStreamSchema
116
- : S extends z.core.$ZodOptional<infer Inner>
117
- ? CoValueSchemaFromZodSchema<Inner>
118
- : S extends z.core.$ZodUnion<
119
- infer Members extends readonly [
120
- AnyDiscriminableCoSchema,
121
- ...AnyDiscriminableCoSchema[],
122
- ]
123
- >
124
- ? CoDiscriminatedUnionSchema<Members>
125
- : never
126
- : never;
127
-
128
- export type CoValueClassFromAnySchema<S extends CoValueOrZodSchema> =
59
+ export type CoValueClassOrSchema = CoValueClass | CoreCoValueSchema;
60
+
61
+ export type CoValueSchemaFromCoreSchema<S extends CoreCoValueSchema> =
62
+ S extends CoreAccountSchema<infer Shape extends BaseAccountShape>
63
+ ? AccountSchema<Shape>
64
+ : S extends CoreCoRecordSchema<infer K, infer V>
65
+ ? CoRecordSchema<K, V>
66
+ : S extends CoreCoMapSchema<infer Shape, infer Config>
67
+ ? CoMapSchema<Shape, Config>
68
+ : S extends CoreCoListSchema<infer T>
69
+ ? CoListSchema<T>
70
+ : S extends CoreCoFeedSchema<infer T>
71
+ ? CoFeedSchema<T>
72
+ : S extends CorePlainTextSchema
73
+ ? PlainTextSchema
74
+ : S extends CoreRichTextSchema
75
+ ? RichTextSchema
76
+ : S extends CoreFileStreamSchema
77
+ ? FileStreamSchema
78
+ : S extends CoreCoOptionalSchema<infer Inner>
79
+ ? CoOptionalSchema<Inner>
80
+ : S extends CoreCoDiscriminatedUnionSchema<infer Members>
81
+ ? CoDiscriminatedUnionSchema<Members>
82
+ : never;
83
+
84
+ export type CoValueClassFromAnySchema<S extends CoValueClassOrSchema> =
129
85
  S extends CoValueClass<any>
130
86
  ? S
131
87
  : CoValueClass<InstanceOfSchema<S>> &
132
88
  CoValueFromRaw<InstanceOfSchema<S>> &
133
- (S extends AnyAccountSchema ? AccountClassEssentials : {});
89
+ (S extends CoreAccountSchema ? AccountClassEssentials : {});
134
90
 
135
91
  type AccountClassEssentials = {
136
92
  fromRaw: <A extends Account>(this: AccountClass<A>, raw: RawAccount) => A;
137
93
  fromNode: <A extends Account>(this: AccountClass<A>, node: LocalNode) => A;
138
94
  };
139
95
 
140
- // TODO rename to ProtoCoSchema?
141
- export type AnyCoSchema =
142
- | AnyCoMapSchema
143
- | AnyAccountSchema
144
- | AnyCoRecordSchema
145
- | AnyCoListSchema
146
- | AnyCoFeedSchema
147
- | AnyCoUnionSchema
148
- | AnyCoOptionalSchema
149
- | AnyPlainTextSchema
150
- | AnyRichTextSchema
151
- | AnyFileStreamSchema;
96
+ export type AnyCoreCoValueSchema =
97
+ | CoreCoMapSchema
98
+ | CoreAccountSchema
99
+ | CoreCoRecordSchema
100
+ | CoreCoListSchema
101
+ | CoreCoFeedSchema
102
+ | CoreCoDiscriminatedUnionSchema<any>
103
+ | CoreCoOptionalSchema
104
+ | CorePlainTextSchema
105
+ | CoreRichTextSchema
106
+ | CoreFileStreamSchema;
107
+
108
+ type AnyZodSchema = z.core.$ZodType;
109
+
110
+ export type AnyZodOrCoValueSchema = AnyZodSchema | CoreCoValueSchema;
152
111
 
153
112
  export type Loaded<
154
- T extends CoValueClass | AnyCoSchema,
113
+ T extends CoValueClassOrSchema,
155
114
  R extends ResolveQuery<T> = true,
156
115
  > = Resolved<NonNullable<InstanceOfSchemaCoValuesNullable<T>>, R>;
157
116
 
158
- export type ResolveQuery<T extends CoValueClass | AnyCoSchema> = RefsToResolve<
117
+ export type ResolveQuery<T extends CoValueClassOrSchema> = RefsToResolve<
159
118
  NonNullable<InstanceOfSchemaCoValuesNullable<T>>
160
119
  >;
161
120
 
162
121
  export type ResolveQueryStrict<
163
- T extends CoValueClass | AnyCoSchema,
122
+ T extends CoValueClassOrSchema,
164
123
  R extends ResolveQuery<T>,
165
124
  > = RefsToResolveStrict<NonNullable<InstanceOfSchemaCoValuesNullable<T>>, R>;
166
125
 
167
- export type InitFor<T extends CoValueClass | AnyCoSchema> =
168
- T extends AnyCoMapSchema<infer Shape> ? Simplify<CoMapInitZod<Shape>> : never;
126
+ export type InitFor<T extends CoValueClassOrSchema> = T extends CoreCoMapSchema<
127
+ infer Shape
128
+ >
129
+ ? Simplify<CoMapSchemaInit<Shape>>
130
+ : never;
@@ -26,6 +26,7 @@ export * from "./subscribe/SubscriptionScope.js";
26
26
  export * from "./subscribe/types.js";
27
27
  export * from "./subscribe/index.js";
28
28
  export * from "./lib/cache.js";
29
+ export * from "./lib/utilityTypes.js";
29
30
  export * from "./implementation/createContext.js";
30
31
 
31
32
  export * from "./types.js";
@@ -44,8 +45,8 @@ export * from "./implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSc
44
45
  export * from "./implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
45
46
  export * from "./implementation/zodSchema/typeConverters/InstanceOfSchema.js";
46
47
  export * from "./implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.js";
47
- export * from "./implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.js";
48
- export * from "./implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.js";
48
+ export * from "./implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.js";
49
+ export * from "./implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.js";
49
50
  export * from "./coValues/extensions/imageDef.js";
50
51
 
51
52
  export * from "./implementation/ContextManager.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Make any property optional if its type includes `undefined`, preserving the type as-is
3
+ */
4
+ export type PartialOnUndefined<T> = {
5
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
6
+ } & {
7
+ [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
8
+ };
9
+
10
+ /**
11
+ * Useful to flatten the type output to improve type hints shown in editors.
12
+ * And also to transform an interface into a type to aide with assignability.
13
+ *
14
+ * Taken from https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
15
+ */
16
+ export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
@@ -3,7 +3,7 @@ import { RegisteredSchemas } from "../coValues/registeredSchemas.js";
3
3
  import {
4
4
  CoValue,
5
5
  RefEncoded,
6
- anySchemaToCoSchema,
6
+ coValueClassFromCoValueClassOrSchema,
7
7
  instantiateRefEncoded,
8
8
  } from "../internal.js";
9
9
  import { coValuesCache } from "../lib/cache.js";
@@ -14,7 +14,9 @@ export function getOwnerFromRawValue(raw: RawCoValue) {
14
14
 
15
15
  return coValuesCache.get(owner, () =>
16
16
  owner instanceof RawAccount
17
- ? anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(owner)
17
+ ? coValueClassFromCoValueClassOrSchema(
18
+ RegisteredSchemas["Account"],
19
+ ).fromRaw(owner)
18
20
  : RegisteredSchemas["Group"].fromRaw(owner as any),
19
21
  );
20
22
  }
@@ -5,15 +5,15 @@ import {
5
5
  Account,
6
6
  AccountClass,
7
7
  type AnonymousJazzAgent,
8
- AnyAccountSchema,
9
8
  AuthCredentials,
10
9
  CoValueFromRaw,
10
+ CoreAccountSchema,
11
11
  InstanceOfSchema,
12
12
  JazzContextManager,
13
13
  JazzContextManagerAuthProps,
14
14
  JazzContextManagerBaseProps,
15
15
  activeAccountContext,
16
- anySchemaToCoSchema,
16
+ coValueClassFromCoValueClassOrSchema,
17
17
  createAnonymousJazzContext,
18
18
  createJazzContext,
19
19
  randomSessionProvider,
@@ -88,14 +88,14 @@ let isMigrationActive = false;
88
88
  export async function createJazzTestAccount<
89
89
  S extends
90
90
  | (AccountClass<Account> & CoValueFromRaw<Account>)
91
- | AnyAccountSchema,
91
+ | CoreAccountSchema,
92
92
  >(options?: {
93
93
  isCurrentActiveAccount?: boolean;
94
94
  AccountSchema?: S;
95
95
  creationProps?: Record<string, unknown>;
96
96
  }): Promise<InstanceOfSchema<S>> {
97
97
  const AccountClass = options?.AccountSchema
98
- ? anySchemaToCoSchema(options.AccountSchema)
98
+ ? coValueClassFromCoValueClassOrSchema(options.AccountSchema)
99
99
  : Account;
100
100
  const peers = [];
101
101
  if (syncServer.current) {