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,12 +0,0 @@
1
- import { CoMap, CoValueClass } from "../../../internal.js";
2
- import { z } from "../zodReExport.js";
3
- import { AnyCoSchema, ZodPrimitiveSchema } from "../zodSchema.js";
4
- /**
5
- * Types of objects that can be nested inside CoValue schema containers
6
- */
7
- type SchemaField = AnyCoSchema | CoValueClass | ZodPrimitiveSchema | z.core.$ZodOptional<z.core.$ZodType> | z.core.$ZodUnion<z.core.$ZodType[]> | z.core.$ZodObject<z.core.$ZodLooseShape> | z.core.$ZodArray<z.core.$ZodType> | z.core.$ZodTuple<z.core.$ZodType[]> | z.core.$ZodReadonly<z.core.$ZodType> | z.core.$ZodLazy<z.core.$ZodType> | z.core.$ZodTemplateLiteral<any> | z.core.$ZodLiteral<any> | z.core.$ZodCatch<z.core.$ZodType> | z.core.$ZodEnum<any> | z.core.$ZodDefault<z.core.$ZodType> | z.core.$ZodCatch<z.core.$ZodType> | (z.core.$ZodCustom<any, any> & {
8
- builtin: any;
9
- });
10
- export declare function schemaFieldToCoFieldDef(schema: SchemaField, isOptional?: boolean): string | number | boolean | Date | import("../../../internal.js").CoValue | CoMap | import("../../../internal.js").CoPlainText | import("../../../internal.js").BinaryCoStream | import("../../../internal.js").CoStream<unknown> | import("../../../internal.js").CoList<unknown> | null | undefined;
11
- export {};
12
- //# sourceMappingURL=zodFieldToCoFieldDef.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zodFieldToCoFieldDef.d.ts","sourceRoot":"","sources":["../../../../../src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAkB,MAAM,sBAAsB,CAAC;AAQ3E,OAAO,EAKL,CAAC,EACF,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAMlE;;GAEG;AACH,KAAK,WAAW,GAEZ,WAAW,GAEX,YAAY,GACZ,kBAAkB,GAClB,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GACpC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GACnC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,GACxC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GACjC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,GACnC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GACpC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAChC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAC/B,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GACjC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GACpB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GACnC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GACjC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC,CAAC;AAErD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,WAAW,EACnB,UAAU,UAAQ,ySA4HnB"}
@@ -1,9 +0,0 @@
1
- import { CoValueClass } from "../../../internal.js";
2
- import { z } from "../zodReExport.js";
3
- import { AnyCoSchema, CoValueClassFromAnySchema, CoValueOrZodSchema, CoValueSchemaFromZodSchema, ZodPrimitiveSchema } from "../zodSchema.js";
4
- export declare function isAnyCoValueSchema(schema: z.core.$ZodType | CoValueClass): schema is AnyCoSchema;
5
- export declare function isCoValueSchema(schema: z.core.$ZodType | CoValueClass): schema is CoValueSchemaFromZodSchema<AnyCoSchema>;
6
- export declare function zodSchemaToCoSchema<S extends z.core.$ZodType | AnyCoSchema>(schema: S): CoValueSchemaFromZodSchema<S>;
7
- export declare function anySchemaToCoSchema<S extends CoValueOrZodSchema>(schema: S): CoValueClassFromAnySchema<S>;
8
- export declare function zodSchemaToCoSchemaOrKeepPrimitive<S extends z.core.$ZodType>(schema: S): CoValueSchemaFromZodSchema<S> | ZodPrimitiveSchema;
9
- //# sourceMappingURL=zodSchemaToCoSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zodSchemaToCoSchema.d.ts","sourceRoot":"","sources":["../../../../../src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,YAAY,EAWb,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EACL,WAAW,EACX,yBAAyB,EACzB,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EAKnB,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,YAAY,GACrC,MAAM,IAAI,WAAW,CAEvB;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,YAAY,GACrC,MAAM,IAAI,0BAA0B,CAAC,WAAW,CAAC,CAEnD;AAyHD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,WAAW,EACzE,MAAM,EAAE,CAAC,GACR,0BAA0B,CAAC,CAAC,CAAC,CAQ/B;AAGD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,kBAAkB,EAC9D,MAAM,EAAE,CAAC,GACR,yBAAyB,CAAC,CAAC,CAAC,CAkB9B;AAED,wBAAgB,kCAAkC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAC1E,MAAM,EAAE,CAAC,GACR,0BAA0B,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAMpD"}
@@ -1,172 +0,0 @@
1
- import { CoMap, CoValueClass, isCoValueClass } from "../../../internal.js";
2
- import { coField } from "../../schema.js";
3
- import { isAnyCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
4
- import {
5
- isUnionOfCoMapsDeeply,
6
- isUnionOfPrimitivesDeeply,
7
- schemaUnionDiscriminatorFor,
8
- } from "../unionUtils.js";
9
- import {
10
- ZodCatch,
11
- ZodDefault,
12
- ZodLazy,
13
- ZodReadonly,
14
- z,
15
- } from "../zodReExport.js";
16
- import { AnyCoSchema, ZodPrimitiveSchema } from "../zodSchema.js";
17
- import {
18
- isCoValueSchema,
19
- zodSchemaToCoSchemaOrKeepPrimitive,
20
- } from "./zodSchemaToCoSchema.js";
21
-
22
- /**
23
- * Types of objects that can be nested inside CoValue schema containers
24
- */
25
- type SchemaField =
26
- // Schemas created with co.map(), co.record(), co.list(), etc.
27
- | AnyCoSchema
28
- // CoValue classes created with class syntax, or framework-provided classes like Group
29
- | CoValueClass
30
- | ZodPrimitiveSchema
31
- | z.core.$ZodOptional<z.core.$ZodType>
32
- | z.core.$ZodUnion<z.core.$ZodType[]>
33
- | z.core.$ZodObject<z.core.$ZodLooseShape>
34
- | z.core.$ZodArray<z.core.$ZodType>
35
- | z.core.$ZodTuple<z.core.$ZodType[]>
36
- | z.core.$ZodReadonly<z.core.$ZodType>
37
- | z.core.$ZodLazy<z.core.$ZodType>
38
- | z.core.$ZodTemplateLiteral<any>
39
- | z.core.$ZodLiteral<any>
40
- | z.core.$ZodCatch<z.core.$ZodType>
41
- | z.core.$ZodEnum<any>
42
- | z.core.$ZodDefault<z.core.$ZodType>
43
- | z.core.$ZodCatch<z.core.$ZodType>
44
- | (z.core.$ZodCustom<any, any> & { builtin: any });
45
-
46
- export function schemaFieldToCoFieldDef(
47
- schema: SchemaField,
48
- isOptional = false,
49
- ) {
50
- if (isCoValueClass(schema)) {
51
- if (isOptional) {
52
- return coField.ref(schema, { optional: true });
53
- } else {
54
- return coField.ref(schema);
55
- }
56
- } else if (isCoValueSchema(schema)) {
57
- if (isAnyCoOptionalSchema(schema)) {
58
- return coField.ref(schema.getCoValueClass(), {
59
- optional: true,
60
- });
61
- }
62
-
63
- if (isOptional) {
64
- return coField.ref(schema.getCoValueClass(), { optional: true });
65
- } else {
66
- return coField.ref(schema.getCoValueClass());
67
- }
68
- } else {
69
- if ("_zod" in schema) {
70
- if (schema._zod.def.type === "optional") {
71
- const inner = zodSchemaToCoSchemaOrKeepPrimitive(
72
- schema._zod.def.innerType,
73
- );
74
- return schemaFieldToCoFieldDef(inner, true);
75
- } else if (schema._zod.def.type === "string") {
76
- return coField.string;
77
- } else if (schema._zod.def.type === "number") {
78
- return coField.number;
79
- } else if (schema._zod.def.type === "boolean") {
80
- return coField.boolean;
81
- } else if (schema._zod.def.type === "null") {
82
- return coField.null;
83
- } else if (schema._zod.def.type === "enum") {
84
- return coField.string;
85
- } else if (schema._zod.def.type === "readonly") {
86
- return schemaFieldToCoFieldDef(
87
- (schema as unknown as ZodReadonly).def.innerType as SchemaField,
88
- isOptional,
89
- );
90
- } else if (schema._zod.def.type === "date") {
91
- return coField.optional.Date;
92
- } else if (schema._zod.def.type === "template_literal") {
93
- return coField.string;
94
- } else if (schema._zod.def.type === "lazy") {
95
- // Mostly to support z.json()
96
- return schemaFieldToCoFieldDef(
97
- (schema as unknown as ZodLazy).unwrap() as SchemaField,
98
- isOptional,
99
- );
100
- } else if (
101
- schema._zod.def.type === "default" ||
102
- schema._zod.def.type === "catch"
103
- ) {
104
- console.warn(
105
- "z.default()/z.catch() are not supported in collaborative schemas. They will be ignored.",
106
- );
107
-
108
- return schemaFieldToCoFieldDef(
109
- (schema as unknown as ZodDefault | ZodCatch).def
110
- .innerType as SchemaField,
111
- isOptional,
112
- );
113
- } else if (schema._zod.def.type === "literal") {
114
- if (
115
- schema._zod.def.values.some(
116
- (literal) => typeof literal === "undefined",
117
- )
118
- ) {
119
- throw new Error("z.literal() with undefined is not supported");
120
- }
121
- if (schema._zod.def.values.some((literal) => literal === null)) {
122
- throw new Error("z.literal() with null is not supported");
123
- }
124
- if (
125
- schema._zod.def.values.some((literal) => typeof literal === "bigint")
126
- ) {
127
- throw new Error("z.literal() with bigint is not supported");
128
- }
129
- return coField.literal(
130
- ...(schema._zod.def.values as Exclude<
131
- (typeof schema._zod.def.values)[number],
132
- undefined | null | bigint
133
- >[]),
134
- );
135
- } else if (
136
- schema._zod.def.type === "object" ||
137
- schema._zod.def.type === "array" ||
138
- schema._zod.def.type === "tuple"
139
- ) {
140
- return coField.json();
141
- } else if (schema._zod.def.type === "custom") {
142
- if ("builtin" in schema) {
143
- return schemaFieldToCoFieldDef(schema.builtin, isOptional);
144
- } else {
145
- throw new Error(`Unsupported custom zod type`);
146
- }
147
- } else if (schema._zod.def.type === "union") {
148
- if (isUnionOfPrimitivesDeeply(schema)) {
149
- return coField.json();
150
- } else if (isUnionOfCoMapsDeeply(schema)) {
151
- const result = schemaUnionDiscriminatorFor(schema);
152
-
153
- if (isOptional) {
154
- return coField.ref<CoValueClass<CoMap>>(result, { optional: true });
155
- } else {
156
- return coField.ref<CoValueClass<CoMap>>(result);
157
- }
158
- } else {
159
- throw new Error(
160
- "z.union()/z.discriminatedUnion() of mixed collaborative and non-collaborative types is not supported",
161
- );
162
- }
163
- } else {
164
- throw new Error(
165
- `Unsupported zod type: ${(schema._zod?.def as any)?.type || JSON.stringify(schema)}`,
166
- );
167
- }
168
- } else {
169
- throw new Error(`Unsupported zod type: ${schema}`);
170
- }
171
- }
172
- }
@@ -1,218 +0,0 @@
1
- import { RawCoList, RawCoMap } from "cojson";
2
- import {
3
- Account,
4
- CoFeed,
5
- CoList,
6
- CoMap,
7
- CoPlainText,
8
- CoRichText,
9
- CoValueClass,
10
- FileStream,
11
- SchemaUnion,
12
- enrichAccountSchema,
13
- enrichCoDiscriminatedUnionSchema,
14
- enrichCoFeedSchema,
15
- enrichCoListSchema,
16
- enrichCoMapSchema,
17
- enrichFileStreamSchema,
18
- enrichPlainTextSchema,
19
- isCoValueClass,
20
- } from "../../../internal.js";
21
- import { coField } from "../../schema.js";
22
- import { isAnyCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
23
- import { enrichRichTextSchema } from "../schemaTypes/RichTextSchema.js";
24
- import {
25
- isUnionOfCoMapsDeeply,
26
- schemaUnionDiscriminatorFor,
27
- } from "../unionUtils.js";
28
- import { z } from "../zodReExport.js";
29
- import {
30
- AnyCoSchema,
31
- CoValueClassFromAnySchema,
32
- CoValueOrZodSchema,
33
- CoValueSchemaFromZodSchema,
34
- ZodPrimitiveSchema,
35
- getDef,
36
- isZodArray,
37
- isZodCustom,
38
- isZodObject,
39
- } from "../zodSchema.js";
40
- import { schemaFieldToCoFieldDef } from "./zodFieldToCoFieldDef.js";
41
-
42
- let coSchemasForZodSchemas = new Map<z.core.$ZodType, AnyCoSchema>();
43
-
44
- export function isAnyCoValueSchema(
45
- schema: z.core.$ZodType | CoValueClass,
46
- ): schema is AnyCoSchema {
47
- return "collaborative" in schema && schema.collaborative === true;
48
- }
49
-
50
- export function isCoValueSchema(
51
- schema: z.core.$ZodType | CoValueClass,
52
- ): schema is CoValueSchemaFromZodSchema<AnyCoSchema> {
53
- return isAnyCoValueSchema(schema) && "getCoValueClass" in schema;
54
- }
55
-
56
- /**
57
- * Convert a Zod schema into a CoValue schema.
58
- *
59
- * @param schema A Zod schema that may represent a CoValue schema
60
- * @returns The CoValue schema matching the provided ProtoCoSchema, or `null` if the Zod schema
61
- * does not match a CoValue schema.
62
- */
63
- function tryZodSchemaToCoSchema<S extends z.core.$ZodType>(
64
- schema: S,
65
- ): CoValueSchemaFromZodSchema<S> | null {
66
- if (isAnyCoValueSchema(schema)) {
67
- if (coSchemasForZodSchemas.has(schema)) {
68
- return coSchemasForZodSchemas.get(
69
- schema,
70
- ) as CoValueSchemaFromZodSchema<S>;
71
- }
72
-
73
- if (isAnyCoOptionalSchema(schema)) {
74
- // Optional schemas are not supported as top-level schemas
75
- return null;
76
- } else if (isZodObject(schema)) {
77
- const def = getDef(schema);
78
-
79
- const ClassToExtend =
80
- "builtin" in schema && schema.builtin === "Account" ? Account : CoMap;
81
-
82
- const coValueClass = class ZCoMap extends ClassToExtend {
83
- constructor(options: { fromRaw: RawCoMap } | undefined) {
84
- super(options);
85
- for (const [field, fieldType] of Object.entries(
86
- def.shape as z.core.$ZodShape,
87
- )) {
88
- (this as any)[field] = schemaFieldToCoFieldDef(
89
- zodSchemaToCoSchemaOrKeepPrimitive(fieldType),
90
- );
91
- }
92
- if (def.catchall) {
93
- (this as any)[coField.items] = schemaFieldToCoFieldDef(
94
- zodSchemaToCoSchemaOrKeepPrimitive(def.catchall),
95
- );
96
- }
97
- }
98
- };
99
-
100
- const coValueSchema =
101
- ClassToExtend === Account
102
- ? enrichAccountSchema(schema as any, coValueClass as any)
103
- : enrichCoMapSchema(schema as any, coValueClass as any);
104
-
105
- coSchemasForZodSchemas.set(schema, coValueSchema);
106
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
107
- } else if (isZodArray(schema)) {
108
- const def = getDef(schema);
109
- const coValueClass = class ZCoList extends CoList {
110
- constructor(options: { fromRaw: RawCoList } | undefined) {
111
- super(options);
112
- (this as any)[coField.items] = schemaFieldToCoFieldDef(
113
- zodSchemaToCoSchemaOrKeepPrimitive(def.element),
114
- );
115
- }
116
- };
117
-
118
- const coValueSchema = enrichCoListSchema(schema, coValueClass as any);
119
-
120
- coSchemasForZodSchemas.set(schema, coValueSchema);
121
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
122
- } else if (isZodCustom(schema)) {
123
- if ("builtin" in schema) {
124
- if (schema.builtin === "CoFeed" && "element" in schema) {
125
- const coValueClass = CoFeed.Of(
126
- schemaFieldToCoFieldDef(
127
- zodSchemaToCoSchemaOrKeepPrimitive(
128
- schema.element as z.core.$ZodType,
129
- ),
130
- ),
131
- );
132
- const coValueSchema = enrichCoFeedSchema(schema, coValueClass as any);
133
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
134
- } else if (schema.builtin === "FileStream") {
135
- const coValueClass = FileStream;
136
- const coValueSchema = enrichFileStreamSchema(schema, coValueClass);
137
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
138
- } else if (schema.builtin === "CoPlainText") {
139
- const coValueClass = CoPlainText;
140
- const coValueSchema = enrichPlainTextSchema(schema, coValueClass);
141
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
142
- } else if (schema.builtin === "CoRichText") {
143
- const coValueClass = CoRichText;
144
- const coValueSchema = enrichRichTextSchema(schema, coValueClass);
145
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
146
- } else {
147
- throw new Error(`Unsupported builtin type: ${schema.builtin}`);
148
- }
149
- } else {
150
- throw new Error(`Unsupported custom zod type`);
151
- }
152
- } else {
153
- throw new Error(
154
- `Unsupported zod CoValue type for top-level schema: ${schema._zod?.def?.type || JSON.stringify(schema, undefined, 2)}`,
155
- );
156
- }
157
- } else if (schema instanceof z.core.$ZodDiscriminatedUnion) {
158
- if (isUnionOfCoMapsDeeply(schema)) {
159
- const coValueClass = SchemaUnion.Of(schemaUnionDiscriminatorFor(schema));
160
- const coValueSchema = enrichCoDiscriminatedUnionSchema(
161
- schema as any,
162
- coValueClass as any,
163
- );
164
- return coValueSchema as unknown as CoValueSchemaFromZodSchema<S>;
165
- } else {
166
- throw new Error(
167
- "z.discriminatedUnion() of non-collaborative types is not supported as a top-level schema",
168
- );
169
- }
170
- } else {
171
- return null;
172
- }
173
- }
174
-
175
- export function zodSchemaToCoSchema<S extends z.core.$ZodType | AnyCoSchema>(
176
- schema: S,
177
- ): CoValueSchemaFromZodSchema<S> {
178
- const coSchema = tryZodSchemaToCoSchema(schema);
179
- if (!coSchema) {
180
- throw new Error(
181
- `Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`,
182
- );
183
- }
184
- return coSchema;
185
- }
186
-
187
- // TODO this should be coValueClassOrAnySchemaToCoValueClass
188
- export function anySchemaToCoSchema<S extends CoValueOrZodSchema>(
189
- schema: S,
190
- ): CoValueClassFromAnySchema<S> {
191
- if (isCoValueClass(schema)) {
192
- return schema as any;
193
- } else if (isCoValueSchema(schema)) {
194
- return schema.getCoValueClass() as any;
195
- } else if ("def" in schema) {
196
- const coSchema = tryZodSchemaToCoSchema(
197
- schema as z.core.$ZodType | AnyCoSchema,
198
- );
199
- if (!coSchema) {
200
- throw new Error(
201
- `Unsupported zod type: ${(schema.def as any)?.type || JSON.stringify(schema)}`,
202
- );
203
- }
204
- return coSchema.getCoValueClass() as any;
205
- }
206
-
207
- throw new Error(`Unsupported schema: ${JSON.stringify(schema)}`);
208
- }
209
-
210
- export function zodSchemaToCoSchemaOrKeepPrimitive<S extends z.core.$ZodType>(
211
- schema: S,
212
- ): CoValueSchemaFromZodSchema<S> | ZodPrimitiveSchema {
213
- const coSchema = tryZodSchemaToCoSchema(schema);
214
- if (!coSchema) {
215
- return schema as any;
216
- }
217
- return coSchema;
218
- }