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
@@ -3,16 +3,32 @@ import {
3
3
  AnonymousJazzAgent,
4
4
  FileStream,
5
5
  Group,
6
+ coOptionalDefiner,
6
7
  } from "../../../internal.js";
7
- import { z } from "../zodReExport.js";
8
+ import { CoOptionalSchema } from "./CoOptionalSchema.js";
9
+ import { CoreCoValueSchema } from "./CoValueSchema.js";
8
10
 
9
- export type AnyFileStreamSchema = z.core.$ZodCustom<FileStream, unknown> & {
10
- collaborative: true;
11
+ export interface CoreFileStreamSchema extends CoreCoValueSchema {
11
12
  builtin: "FileStream";
12
- };
13
+ }
14
+
15
+ export function createCoreFileStreamSchema(): CoreFileStreamSchema {
16
+ return {
17
+ collaborative: true as const,
18
+ builtin: "FileStream" as const,
19
+ };
20
+ }
21
+
22
+ export class FileStreamSchema implements CoreFileStreamSchema {
23
+ readonly collaborative = true as const;
24
+ readonly builtin = "FileStream" as const;
25
+
26
+ constructor(private coValueClass: typeof FileStream) {}
27
+
28
+ create(options?: { owner?: Account | Group } | Account | Group): FileStream {
29
+ return this.coValueClass.create(options);
30
+ }
13
31
 
14
- export type FileStreamSchema = AnyFileStreamSchema & {
15
- create(options?: { owner?: Account | Group } | Account | Group): FileStream;
16
32
  createFromBlob(
17
33
  blob: Blob | File,
18
34
  options?:
@@ -22,18 +38,27 @@ export type FileStreamSchema = AnyFileStreamSchema & {
22
38
  }
23
39
  | Account
24
40
  | Group,
25
- ): Promise<FileStream>;
41
+ ): Promise<FileStream> {
42
+ return this.coValueClass.createFromBlob(blob, options);
43
+ }
44
+
26
45
  loadAsBlob(
27
46
  id: string,
28
47
  options?: {
29
48
  allowUnfinished?: boolean;
30
49
  loadAs?: Account | AnonymousJazzAgent;
31
50
  },
32
- ): Promise<Blob | undefined>;
51
+ ): Promise<Blob | undefined> {
52
+ return this.coValueClass.loadAsBlob(id, options);
53
+ }
54
+
33
55
  load(
34
56
  id: string,
35
57
  options: { loadAs: Account | AnonymousJazzAgent },
36
- ): Promise<FileStream>;
58
+ ): Promise<FileStream | null> {
59
+ return this.coValueClass.load(id, options);
60
+ }
61
+
37
62
  subscribe(
38
63
  id: string,
39
64
  options: { loadAs: Account | AnonymousJazzAgent },
@@ -43,32 +68,16 @@ export type FileStreamSchema = AnyFileStreamSchema & {
43
68
  id: string,
44
69
  listener: (value: FileStream, unsubscribe: () => void) => void,
45
70
  ): () => void;
46
- getCoValueClass: () => typeof FileStream;
47
- };
71
+ subscribe(...args: [any, ...any[]]) {
72
+ // @ts-expect-error
73
+ return this.coValueClass.subscribe(...args);
74
+ }
48
75
 
49
- export function enrichFileStreamSchema(
50
- schema: AnyFileStreamSchema,
51
- coValueClass: typeof FileStream,
52
- ): FileStreamSchema {
53
- return Object.assign(schema, {
54
- create: (...args: any[]) => {
55
- return coValueClass.create(...args);
56
- },
57
- createFromBlob: (...args: [any, ...any[]]) => {
58
- return coValueClass.createFromBlob(...args);
59
- },
60
- load: (...args: [any, ...any[]]) => {
61
- return coValueClass.load(...args);
62
- },
63
- loadAsBlob: (...args: [any, ...any[]]) => {
64
- return coValueClass.loadAsBlob(...args);
65
- },
66
- subscribe: (...args: [any, ...any[]]) => {
67
- // @ts-expect-error
68
- return coValueClass.subscribe(...args);
69
- },
70
- getCoValueClass: () => {
71
- return coValueClass;
72
- },
73
- }) as unknown as FileStreamSchema;
76
+ getCoValueClass(): typeof FileStream {
77
+ return this.coValueClass;
78
+ }
79
+
80
+ optional(): CoOptionalSchema<this> {
81
+ return coOptionalDefiner(this);
82
+ }
74
83
  }
@@ -1,22 +1,45 @@
1
1
  import { RawCoPlainText } from "cojson";
2
- import { Account, CoPlainText, Group } from "../../../internal.js";
2
+ import {
3
+ Account,
4
+ CoPlainText,
5
+ Group,
6
+ coOptionalDefiner,
7
+ } from "../../../internal.js";
3
8
  import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
4
- import { z } from "../zodReExport.js";
9
+ import { CoOptionalSchema } from "./CoOptionalSchema.js";
10
+ import { CoreCoValueSchema } from "./CoValueSchema.js";
5
11
 
6
- export type AnyPlainTextSchema = z.core.$ZodCustom<CoPlainText, unknown> & {
7
- collaborative: true;
12
+ export interface CorePlainTextSchema extends CoreCoValueSchema {
8
13
  builtin: "CoPlainText";
9
- };
14
+ }
15
+
16
+ export function createCoreCoPlainTextSchema(): CorePlainTextSchema {
17
+ return {
18
+ collaborative: true as const,
19
+ builtin: "CoPlainText" as const,
20
+ };
21
+ }
22
+
23
+ export class PlainTextSchema implements CorePlainTextSchema {
24
+ readonly collaborative = true as const;
25
+ readonly builtin = "CoPlainText" as const;
26
+
27
+ constructor(private coValueClass: typeof CoPlainText) {}
10
28
 
11
- export type PlainTextSchema = AnyPlainTextSchema & {
12
29
  create(
13
30
  text: string,
14
31
  options?: { owner: Account | Group } | Account | Group,
15
- ): CoPlainText;
32
+ ): CoPlainText {
33
+ return this.coValueClass.create(text, options);
34
+ }
35
+
16
36
  load(
17
37
  id: string,
18
38
  options: { loadAs: Account | AnonymousJazzAgent },
19
- ): Promise<CoPlainText>;
39
+ ): Promise<CoPlainText | null> {
40
+ return this.coValueClass.load(id, options);
41
+ }
42
+
20
43
  subscribe(
21
44
  id: string,
22
45
  options: { loadAs: Account | AnonymousJazzAgent },
@@ -26,31 +49,20 @@ export type PlainTextSchema = AnyPlainTextSchema & {
26
49
  id: string,
27
50
  listener: (value: CoPlainText, unsubscribe: () => void) => void,
28
51
  ): () => void;
29
- fromRaw(raw: RawCoPlainText): CoPlainText;
30
- getCoValueClass: () => typeof CoPlainText;
31
- };
32
-
33
- export function enrichPlainTextSchema(
34
- schema: AnyPlainTextSchema,
35
- coValueClass: typeof CoPlainText,
36
- ): PlainTextSchema {
37
- return Object.assign(schema, {
38
- create: (...args: [any, ...any[]]) => {
39
- return coValueClass.create(...args);
40
- },
41
- load: (...args: [any, ...any[]]) => {
42
- return coValueClass.load(...args);
43
- },
44
- subscribe: (...args: [any, ...any[]]) => {
45
- // @ts-expect-error
46
- return coValueClass.subscribe(...args);
47
- },
48
- fromRaw: (...args: [any, ...any[]]) => {
49
- // @ts-expect-error
50
- return coValueClass.fromRaw(...args);
51
- },
52
- getCoValueClass: () => {
53
- return coValueClass;
54
- },
55
- }) as unknown as PlainTextSchema;
52
+ subscribe(...args: [any, ...any[]]) {
53
+ // @ts-expect-error
54
+ return this.coValueClass.subscribe(...args);
55
+ }
56
+
57
+ fromRaw(raw: RawCoPlainText): CoPlainText {
58
+ return this.coValueClass.fromRaw(raw);
59
+ }
60
+
61
+ getCoValueClass(): typeof CoPlainText {
62
+ return this.coValueClass;
63
+ }
64
+
65
+ optional(): CoOptionalSchema<this> {
66
+ return coOptionalDefiner(this);
67
+ }
56
68
  }
@@ -1,21 +1,44 @@
1
- import { Account, CoRichText, Group } from "../../../internal.js";
1
+ import {
2
+ Account,
3
+ CoRichText,
4
+ Group,
5
+ coOptionalDefiner,
6
+ } from "../../../internal.js";
2
7
  import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
3
- import { z } from "../zodReExport.js";
8
+ import { CoOptionalSchema } from "./CoOptionalSchema.js";
9
+ import { CoreCoValueSchema } from "./CoValueSchema.js";
4
10
 
5
- export type AnyRichTextSchema = z.core.$ZodCustom<CoRichText, unknown> & {
6
- collaborative: true;
11
+ export interface CoreRichTextSchema extends CoreCoValueSchema {
7
12
  builtin: "CoRichText";
8
- };
13
+ }
14
+
15
+ export function createCoreCoRichTextSchema(): CoreRichTextSchema {
16
+ return {
17
+ collaborative: true as const,
18
+ builtin: "CoRichText" as const,
19
+ };
20
+ }
21
+
22
+ export class RichTextSchema implements CoreRichTextSchema {
23
+ readonly collaborative = true as const;
24
+ readonly builtin = "CoRichText" as const;
25
+
26
+ constructor(private coValueClass: typeof CoRichText) {}
9
27
 
10
- export type RichTextSchema = AnyRichTextSchema & {
11
28
  create(
12
29
  text: string,
13
30
  options?: { owner: Account | Group } | Account | Group,
14
- ): CoRichText;
31
+ ): CoRichText {
32
+ return this.coValueClass.create(text, options);
33
+ }
34
+
15
35
  load(
16
36
  id: string,
17
37
  options: { loadAs: Account | AnonymousJazzAgent },
18
- ): Promise<CoRichText>;
38
+ ): Promise<CoRichText | null> {
39
+ return this.coValueClass.load(id, options);
40
+ }
41
+
19
42
  subscribe(
20
43
  id: string,
21
44
  options: { loadAs: Account | AnonymousJazzAgent },
@@ -25,26 +48,16 @@ export type RichTextSchema = AnyRichTextSchema & {
25
48
  id: string,
26
49
  listener: (value: CoRichText, unsubscribe: () => void) => void,
27
50
  ): () => void;
28
- getCoValueClass: () => typeof CoRichText;
29
- };
30
-
31
- export function enrichRichTextSchema(
32
- schema: AnyRichTextSchema,
33
- coValueClass: typeof CoRichText,
34
- ): RichTextSchema {
35
- return Object.assign(schema, {
36
- create: (...args: [any, ...any[]]) => {
37
- return coValueClass.create(...args);
38
- },
39
- load: (...args: [any, ...any[]]) => {
40
- return coValueClass.load(...args);
41
- },
42
- subscribe: (...args: [any, ...any[]]) => {
43
- // @ts-expect-error
44
- return coValueClass.subscribe(...args);
45
- },
46
- getCoValueClass: () => {
47
- return coValueClass;
48
- },
49
- }) as unknown as RichTextSchema;
51
+ subscribe(...args: [any, ...any[]]) {
52
+ // @ts-expect-error
53
+ return this.coValueClass.subscribe(...args);
54
+ }
55
+
56
+ getCoValueClass(): typeof CoRichText {
57
+ return this.coValueClass;
58
+ }
59
+
60
+ optional(): CoOptionalSchema<this> {
61
+ return coOptionalDefiner(this);
62
+ }
50
63
  }
@@ -0,0 +1,13 @@
1
+ import { NotNull } from "../../../internal.js";
2
+ import { z } from "../zodReExport.js";
3
+ import { AnyZodOrCoValueSchema } from "../zodSchema.js";
4
+ import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "./InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
5
+
6
+ /**
7
+ * Returns the type of the value that should be used to initialize a coField
8
+ * of the given schema.
9
+ */
10
+ export type CoFieldInit<T extends AnyZodOrCoValueSchema> =
11
+ T extends z.core.$ZodNullable
12
+ ? InstanceOrPrimitiveOfSchemaCoValuesNullable<T>
13
+ : NotNull<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>>;
@@ -1,56 +1,60 @@
1
1
  import {
2
2
  Account,
3
- AnyAccountSchema,
4
- AnyCoRecordSchema,
3
+ AnyZodOrCoValueSchema,
4
+ CoDiscriminatedUnionSchema,
5
5
  CoFeed,
6
6
  CoList,
7
7
  CoMap,
8
8
  CoPlainText,
9
9
  CoRichText,
10
10
  CoValueClass,
11
+ CoreAccountSchema,
12
+ CoreCoRecordSchema,
11
13
  FileStream,
12
14
  } 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 { AnyFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
17
- import { AnyPlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
18
- import { AnyRichTextSchema } from "../schemaTypes/RichTextSchema.js";
15
+ import { CoreCoFeedSchema } from "../schemaTypes/CoFeedSchema.js";
16
+ import { CoreCoListSchema } from "../schemaTypes/CoListSchema.js";
17
+ import { CoreCoMapSchema } from "../schemaTypes/CoMapSchema.js";
18
+ import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
19
+ import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js";
20
+ import { CoreFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
21
+ import { CorePlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
22
+ import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js";
19
23
  import { z } from "../zodReExport.js";
20
24
  import { InstanceOrPrimitiveOfSchema } from "./InstanceOrPrimitiveOfSchema.js";
21
25
 
22
- export type InstanceOfSchema<S extends CoValueClass | z.core.$ZodType> =
23
- S extends z.core.$ZodType
24
- ? S extends AnyAccountSchema<infer Shape>
26
+ export type InstanceOfSchema<S extends CoValueClass | AnyZodOrCoValueSchema> =
27
+ S extends CoreCoValueSchema
28
+ ? S extends CoreAccountSchema<infer Shape>
25
29
  ? {
26
30
  [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
27
31
  } & Account
28
- : S extends AnyCoRecordSchema<infer K, infer V>
32
+ : S extends CoreCoRecordSchema<infer K, infer V>
29
33
  ? {
30
34
  [key in z.output<K> & string]: InstanceOrPrimitiveOfSchema<V>;
31
35
  } & CoMap
32
- : S extends AnyCoMapSchema<infer Shape, infer Config>
36
+ : S extends CoreCoMapSchema<infer Shape, infer CatchAll>
33
37
  ? {
34
38
  [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
35
- } & (unknown extends Config["out"][string]
36
- ? {}
37
- : {
38
- [key: string]: Config["out"][string];
39
- }) &
39
+ } & (CatchAll extends AnyZodOrCoValueSchema
40
+ ? {
41
+ [key: string]: InstanceOrPrimitiveOfSchema<CatchAll>;
42
+ }
43
+ : {}) &
40
44
  CoMap
41
- : S extends AnyCoListSchema<infer T>
45
+ : S extends CoreCoListSchema<infer T>
42
46
  ? CoList<InstanceOrPrimitiveOfSchema<T>>
43
- : S extends AnyCoFeedSchema<infer T>
47
+ : S extends CoreCoFeedSchema<infer T>
44
48
  ? CoFeed<InstanceOrPrimitiveOfSchema<T>>
45
- : S extends AnyPlainTextSchema
49
+ : S extends CorePlainTextSchema
46
50
  ? CoPlainText
47
- : S extends AnyRichTextSchema
51
+ : S extends CoreRichTextSchema
48
52
  ? CoRichText
49
- : S extends AnyFileStreamSchema
53
+ : S extends CoreFileStreamSchema
50
54
  ? FileStream
51
- : S extends z.core.$ZodOptional<infer Inner>
52
- ? InstanceOrPrimitiveOfSchema<Inner>
53
- : S extends z.core.$ZodUnion<infer Members>
55
+ : S extends CoreCoOptionalSchema<infer T>
56
+ ? InstanceOrPrimitiveOfSchema<T>
57
+ : S extends CoDiscriminatedUnionSchema<infer Members>
54
58
  ? InstanceOrPrimitiveOfSchema<Members[number]>
55
59
  : never
56
60
  : S extends CoValueClass
@@ -1,29 +1,32 @@
1
1
  import {
2
2
  Account,
3
- AnyCoFeedSchema,
4
- AnyCoListSchema,
5
- AnyCoMapSchema,
3
+ AnyZodOrCoValueSchema,
6
4
  CoFeed,
7
5
  CoList,
8
6
  CoMap,
9
7
  CoPlainText,
10
8
  CoRichText,
11
9
  CoValueClass,
10
+ CoreAccountSchema,
11
+ CoreCoDiscriminatedUnionSchema,
12
+ CoreCoFeedSchema,
13
+ CoreCoListSchema,
14
+ CoreCoMapSchema,
15
+ CoreCoRecordSchema,
12
16
  FileStream,
13
17
  } from "../../../internal.js";
14
- import { FileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
15
- import { PlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
16
- import { RichTextSchema } from "../schemaTypes/RichTextSchema.js";
18
+ import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
19
+ import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js";
20
+ import { CoreFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
21
+ import { CorePlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
22
+ import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js";
17
23
  import { z } from "../zodReExport.js";
18
24
  import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "./InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
19
25
 
20
26
  export type InstanceOfSchemaCoValuesNullable<
21
- S extends CoValueClass | z.core.$ZodType,
22
- > = S extends z.core.$ZodType
23
- ? S extends z.core.$ZodObject<infer Shape> & {
24
- collaborative: true;
25
- builtin: "Account";
26
- }
27
+ S extends CoValueClass | AnyZodOrCoValueSchema,
28
+ > = S extends CoreCoValueSchema
29
+ ? S extends CoreAccountSchema<infer Shape>
27
30
  ?
28
31
  | ({
29
32
  [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
@@ -31,43 +34,43 @@ export type InstanceOfSchemaCoValuesNullable<
31
34
  >;
32
35
  } & Account)
33
36
  | null
34
- : S extends z.core.$ZodRecord<infer K, infer V> & {
35
- collaborative: true;
36
- }
37
+ : S extends CoreCoRecordSchema<infer K, infer V>
37
38
  ?
38
39
  | ({
39
40
  [key in z.output<K> &
40
41
  string]: InstanceOrPrimitiveOfSchemaCoValuesNullable<V>;
41
42
  } & CoMap)
42
43
  | null
43
- : S extends AnyCoMapSchema<infer Shape, infer Config>
44
+ : S extends CoreCoMapSchema<infer Shape, infer CatchAll>
44
45
  ?
45
46
  | ({
46
47
  [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
47
48
  Shape[key]
48
49
  >;
49
- } & (unknown extends Config["out"][string]
50
- ? {}
51
- : {
52
- [key: string]: Config["out"][string];
53
- }) &
50
+ } & (CatchAll extends AnyZodOrCoValueSchema
51
+ ? {
52
+ [
53
+ key: string
54
+ ]: InstanceOrPrimitiveOfSchemaCoValuesNullable<CatchAll>;
55
+ }
56
+ : {}) &
54
57
  CoMap)
55
58
  | null
56
- : S extends AnyCoListSchema<infer T>
59
+ : S extends CoreCoListSchema<infer T>
57
60
  ? CoList<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>> | null
58
- : S extends AnyCoFeedSchema<infer T>
61
+ : S extends CoreCoFeedSchema<infer T>
59
62
  ? CoFeed<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>> | null
60
- : S extends PlainTextSchema
63
+ : S extends CorePlainTextSchema
61
64
  ? CoPlainText | null
62
- : S extends RichTextSchema
65
+ : S extends CoreRichTextSchema
63
66
  ? CoRichText | null
64
- : S extends FileStreamSchema
67
+ : S extends CoreFileStreamSchema
65
68
  ? FileStream | null
66
- : S extends z.core.$ZodOptional<infer Inner>
69
+ : S extends CoreCoOptionalSchema<infer Inner>
67
70
  ?
68
71
  | InstanceOrPrimitiveOfSchemaCoValuesNullable<Inner>
69
72
  | undefined
70
- : S extends z.core.$ZodUnion<infer Members>
73
+ : S extends CoreCoDiscriminatedUnionSchema<infer Members>
71
74
  ? InstanceOrPrimitiveOfSchemaCoValuesNullable<
72
75
  Members[number]
73
76
  >