jazz-tools 0.17.14 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.js +1 -1
  2. package/.svelte-kit/__package__/media/image.svelte +3 -9
  3. package/.svelte-kit/__package__/media/image.svelte.d.ts +1 -6
  4. package/.svelte-kit/__package__/media/image.svelte.d.ts.map +1 -1
  5. package/.svelte-kit/__package__/media/image.types.d.ts +7 -0
  6. package/.svelte-kit/__package__/media/image.types.d.ts.map +1 -0
  7. package/.svelte-kit/__package__/media/image.types.js +1 -0
  8. package/.svelte-kit/__package__/tests/media/image.svelte.test.js +31 -31
  9. package/.turbo/turbo-build.log +50 -50
  10. package/CHANGELOG.md +31 -0
  11. package/dist/browser/index.js +2 -2
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/{chunk-LZOF6WP5.js → chunk-HJ3GTGY7.js} +1320 -1018
  14. package/dist/chunk-HJ3GTGY7.js.map +1 -0
  15. package/dist/index.js +18 -18
  16. package/dist/index.js.map +1 -1
  17. package/dist/inspector/{custom-element-ZSNTCECD.js → custom-element-WCY6D3QJ.js} +3 -3
  18. package/dist/inspector/{custom-element-ZSNTCECD.js.map → custom-element-WCY6D3QJ.js.map} +1 -1
  19. package/dist/inspector/index.js +1 -1
  20. package/dist/inspector/index.js.map +1 -1
  21. package/dist/inspector/register-custom-element.js +1 -1
  22. package/dist/media/{chunk-E5J3WLQW.js → chunk-KR2V6X2N.js} +14 -9
  23. package/dist/media/chunk-KR2V6X2N.js.map +1 -0
  24. package/dist/media/create-image.d.ts +6 -6
  25. package/dist/media/index.browser.d.ts +6 -6
  26. package/dist/media/index.browser.js +1 -1
  27. package/dist/media/index.d.ts +1 -1
  28. package/dist/media/index.js +1 -1
  29. package/dist/media/index.native.d.ts +6 -6
  30. package/dist/media/index.native.js +1 -1
  31. package/dist/media/utils.d.ts.map +1 -1
  32. package/dist/prosemirror/index.js +2 -2
  33. package/dist/prosemirror/index.js.map +1 -1
  34. package/dist/react/index.js +7 -5
  35. package/dist/react/index.js.map +1 -1
  36. package/dist/react-core/hooks.d.ts.map +1 -1
  37. package/dist/react-core/index.js +4658 -23
  38. package/dist/react-core/index.js.map +1 -1
  39. package/dist/react-native-core/index.js +1 -1
  40. package/dist/react-native-core/index.js.map +1 -1
  41. package/dist/svelte/jazz.class.svelte.js +1 -1
  42. package/dist/svelte/media/image.svelte +3 -9
  43. package/dist/svelte/media/image.svelte.d.ts +1 -6
  44. package/dist/svelte/media/image.svelte.d.ts.map +1 -1
  45. package/dist/svelte/media/image.types.d.ts +7 -0
  46. package/dist/svelte/media/image.types.d.ts.map +1 -0
  47. package/dist/svelte/media/image.types.js +1 -0
  48. package/dist/svelte/tests/media/image.svelte.test.js +31 -31
  49. package/dist/testing.js +18 -14
  50. package/dist/testing.js.map +1 -1
  51. package/dist/tools/coValues/CoFieldInit.d.ts +13 -0
  52. package/dist/tools/coValues/CoFieldInit.d.ts.map +1 -0
  53. package/dist/tools/coValues/CoValueBase.d.ts +18 -15
  54. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  55. package/dist/tools/coValues/account.d.ts +100 -46
  56. package/dist/tools/coValues/account.d.ts.map +1 -1
  57. package/dist/tools/coValues/coFeed.d.ts +78 -62
  58. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  59. package/dist/tools/coValues/coList.d.ts +212 -99
  60. package/dist/tools/coValues/coList.d.ts.map +1 -1
  61. package/dist/tools/coValues/coMap.d.ts +200 -192
  62. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  63. package/dist/tools/coValues/coPlainText.d.ts +30 -22
  64. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  65. package/dist/tools/coValues/deepLoading.d.ts +13 -13
  66. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  67. package/dist/tools/coValues/extensions/imageDef.d.ts +1 -1
  68. package/dist/tools/coValues/group.d.ts +32 -32
  69. package/dist/tools/coValues/group.d.ts.map +1 -1
  70. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  71. package/dist/tools/coValues/interfaces.d.ts +18 -17
  72. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  73. package/dist/tools/coValues/profile.d.ts +6 -5
  74. package/dist/tools/coValues/profile.d.ts.map +1 -1
  75. package/dist/tools/coValues/schemaUnion.d.ts +3 -3
  76. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  77. package/dist/tools/exports.d.ts +1 -1
  78. package/dist/tools/exports.d.ts.map +1 -1
  79. package/dist/tools/implementation/anonymousJazzAgent.d.ts +2 -1
  80. package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
  81. package/dist/tools/implementation/schema.d.ts +5 -5
  82. package/dist/tools/implementation/schema.d.ts.map +1 -1
  83. package/dist/tools/implementation/symbols.d.ts +2 -0
  84. package/dist/tools/implementation/symbols.d.ts.map +1 -1
  85. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -2
  86. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  87. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +6 -2
  88. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  89. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +8 -3
  90. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  91. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +12 -7
  92. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  93. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +13 -7
  94. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +11 -2
  96. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +4 -0
  98. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +4 -0
  100. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/typeConverters/{CoFieldInit.d.ts → CoFieldSchemaInit.d.ts} +7 -7
  102. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -0
  103. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
  104. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  105. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +4 -4
  106. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  107. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -2
  108. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  109. package/dist/tools/internal.d.ts +2 -1
  110. package/dist/tools/internal.d.ts.map +1 -1
  111. package/dist/tools/lib/migration.d.ts +1 -1
  112. package/dist/tools/lib/migration.d.ts.map +1 -1
  113. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  114. package/dist/tools/subscribe/index.d.ts +1 -1
  115. package/dist/tools/subscribe/index.d.ts.map +1 -1
  116. package/dist/tools/subscribe/utils.d.ts +2 -2
  117. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  118. package/dist/tools/testing.d.ts.map +1 -1
  119. package/dist/tools/tests/utils.d.ts +2 -6
  120. package/dist/tools/tests/utils.d.ts.map +1 -1
  121. package/dist/worker/index.js +3 -3
  122. package/dist/worker/index.js.map +1 -1
  123. package/package.json +4 -4
  124. package/src/browser/auth/PasskeyAuth.ts +2 -2
  125. package/src/browser/createBrowserContext.ts +2 -2
  126. package/src/browser/tests/PasskeyAuth.test.ts +2 -2
  127. package/src/inspector/custom-element.tsx +2 -2
  128. package/src/inspector/viewer/new-app.tsx +1 -1
  129. package/src/media/create-image.test.ts +7 -7
  130. package/src/media/create-image.ts +5 -3
  131. package/src/media/index.ts +1 -1
  132. package/src/media/utils.test.ts +72 -66
  133. package/src/media/utils.ts +9 -6
  134. package/src/prosemirror/lib/plugin.ts +1 -1
  135. package/src/prosemirror/lib/sync.ts +1 -1
  136. package/src/prosemirror/tests/plugin.test.ts +4 -4
  137. package/src/react/media/image.tsx +2 -2
  138. package/src/react/tests/media/image.test.tsx +52 -32
  139. package/src/react-core/hooks.ts +11 -5
  140. package/src/react-core/tests/useAccount.test.ts +16 -22
  141. package/src/react-core/tests/useCoState.test.ts +19 -19
  142. package/src/react-core/tests/useInboxSender.test.ts +5 -2
  143. package/src/react-core/tests/usePassPhraseAuth.test.ts +6 -6
  144. package/src/react-native-core/media/image.tsx +1 -1
  145. package/src/svelte/jazz.class.svelte.ts +1 -1
  146. package/src/svelte/media/image.svelte +3 -9
  147. package/src/svelte/media/image.types.ts +7 -0
  148. package/src/svelte/tests/media/image.svelte.test.ts +34 -32
  149. package/src/tools/auth/DemoAuth.ts +2 -2
  150. package/src/tools/auth/PassphraseAuth.ts +2 -2
  151. package/src/tools/auth/clerk/index.ts +2 -2
  152. package/src/tools/auth/clerk/tests/JazzClerkAuth.test.ts +1 -1
  153. package/src/tools/coValues/CoFieldInit.ts +20 -0
  154. package/src/tools/coValues/CoValueBase.ts +40 -60
  155. package/src/tools/coValues/account.ts +306 -232
  156. package/src/tools/coValues/coFeed.ts +185 -153
  157. package/src/tools/coValues/coList.ts +507 -334
  158. package/src/tools/coValues/coMap.ts +420 -286
  159. package/src/tools/coValues/coPlainText.ts +94 -110
  160. package/src/tools/coValues/deepLoading.ts +13 -13
  161. package/src/tools/coValues/group.ts +100 -114
  162. package/src/tools/coValues/inbox.ts +16 -14
  163. package/src/tools/coValues/interfaces.ts +49 -31
  164. package/src/tools/coValues/profile.ts +8 -6
  165. package/src/tools/coValues/request.ts +9 -9
  166. package/src/tools/coValues/schemaUnion.ts +11 -5
  167. package/src/tools/exports.ts +1 -1
  168. package/src/tools/implementation/ContextManager.ts +4 -4
  169. package/src/tools/implementation/anonymousJazzAgent.ts +2 -1
  170. package/src/tools/implementation/createContext.ts +1 -1
  171. package/src/tools/implementation/devtoolsFormatters.ts +9 -9
  172. package/src/tools/implementation/invites.ts +2 -2
  173. package/src/tools/implementation/schema.ts +7 -7
  174. package/src/tools/implementation/symbols.ts +3 -0
  175. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -2
  176. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +11 -2
  177. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +18 -7
  178. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +17 -7
  179. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +20 -11
  180. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +19 -2
  181. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +6 -0
  182. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +6 -0
  183. package/src/tools/implementation/zodSchema/typeConverters/{CoFieldInit.ts → CoFieldSchemaInit.ts} +11 -11
  184. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +4 -4
  185. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +4 -4
  186. package/src/tools/implementation/zodSchema/zodCo.ts +2 -2
  187. package/src/tools/internal.ts +2 -1
  188. package/src/tools/lib/migration.ts +5 -5
  189. package/src/tools/subscribe/SubscriptionScope.ts +32 -24
  190. package/src/tools/subscribe/index.ts +4 -4
  191. package/src/tools/subscribe/utils.ts +11 -11
  192. package/src/tools/testing.ts +17 -13
  193. package/src/tools/tests/ContextManager.test.ts +68 -57
  194. package/src/tools/tests/PassphraseAuth.test.ts +2 -2
  195. package/src/tools/tests/account.test.ts +139 -69
  196. package/src/tools/tests/coDiscriminatedUnion.test-d.ts +12 -6
  197. package/src/tools/tests/coDiscriminatedUnion.test.ts +26 -17
  198. package/src/tools/tests/coFeed.test-d.ts +18 -17
  199. package/src/tools/tests/coFeed.test.ts +108 -97
  200. package/src/tools/tests/coList.test-d.ts +18 -23
  201. package/src/tools/tests/coList.test.ts +350 -165
  202. package/src/tools/tests/coMap.record.test-d.ts +9 -13
  203. package/src/tools/tests/coMap.record.test.ts +37 -23
  204. package/src/tools/tests/coMap.test-d.ts +43 -21
  205. package/src/tools/tests/coMap.test.ts +360 -182
  206. package/src/tools/tests/coOptional.test.ts +28 -13
  207. package/src/tools/tests/coPlainText.test.ts +15 -15
  208. package/src/tools/tests/createContext.test.ts +14 -14
  209. package/src/tools/tests/deepLoading.test.ts +95 -94
  210. package/src/tools/tests/exportImport.test.ts +61 -41
  211. package/src/tools/tests/groupsAndAccounts.test.ts +333 -116
  212. package/src/tools/tests/inbox.test.ts +22 -17
  213. package/src/tools/tests/interfaces.test.ts +12 -11
  214. package/src/tools/tests/invites.test.ts +6 -4
  215. package/src/tools/tests/load.test.ts +20 -18
  216. package/src/tools/tests/patterns/notifications.test.ts +6 -6
  217. package/src/tools/tests/patterns/quest.test.ts +3 -3
  218. package/src/tools/tests/patterns/requestToJoin.test.ts +22 -22
  219. package/src/tools/tests/request.test.ts +38 -39
  220. package/src/tools/tests/schemaUnion.test.ts +64 -10
  221. package/src/tools/tests/subscribe.test.ts +64 -64
  222. package/src/tools/tests/testing.test.ts +5 -9
  223. package/src/tools/tests/utils.ts +3 -3
  224. package/src/tools/tests/zod.test.ts +3 -3
  225. package/src/worker/index.ts +3 -3
  226. package/dist/chunk-LZOF6WP5.js.map +0 -1
  227. package/dist/media/chunk-E5J3WLQW.js.map +0 -1
  228. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +0 -1
@@ -6,8 +6,7 @@ import type {
6
6
  RawGroup,
7
7
  Role,
8
8
  } from "cojson";
9
- import type {
10
- CoMap,
9
+ import {
11
10
  CoValue,
12
11
  CoValueClass,
13
12
  ID,
@@ -15,15 +14,15 @@ import type {
15
14
  RefsToResolve,
16
15
  RefsToResolveStrict,
17
16
  Resolved,
18
- Schema,
19
17
  SubscribeListenerOptions,
20
18
  SubscribeRestArgs,
19
+ TypeSym,
21
20
  } from "../internal.js";
22
21
  import {
23
22
  Account,
24
23
  AccountAndGroupProxyHandler,
25
24
  CoValueBase,
26
- Profile,
25
+ CoValueJazzApi,
27
26
  Ref,
28
27
  RegisteredSchemas,
29
28
  accessChildById,
@@ -37,73 +36,23 @@ import {
37
36
  subscribeToExistingCoValue,
38
37
  } from "../internal.js";
39
38
 
39
+ type GroupMember = {
40
+ id: string;
41
+ role: AccountRole;
42
+ ref: Ref<Account>;
43
+ account: Account;
44
+ };
45
+
40
46
  /** @category Identity & Permissions */
41
47
  export class Group extends CoValueBase implements CoValue {
42
- declare id: ID<this>;
43
- declare _type: "Group";
44
- static {
45
- this.prototype._type = "Group";
46
- }
47
- declare _raw: RawGroup;
48
-
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- static _schema: any;
51
- get _schema(): {
52
- profile: Schema;
53
- root: Schema;
54
- } {
55
- return (this.constructor as typeof Group)._schema;
56
- }
48
+ declare [TypeSym]: "Group";
57
49
  static {
58
- this._schema = {
59
- profile: "json" satisfies Schema,
60
- root: "json" satisfies Schema,
61
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
- } as any;
63
- Object.defineProperty(this.prototype, "_schema", {
64
- get: () => this._schema,
65
- });
66
- }
67
-
68
- declare profile: Profile | null;
69
- declare root: CoMap | null;
70
-
71
- get _refs(): {
72
- profile: Ref<Profile> | undefined;
73
- root: Ref<CoMap> | undefined;
74
- } {
75
- const profileID = this._raw.get("profile") as unknown as
76
- | ID<NonNullable<this["profile"]>>
77
- | undefined;
78
- const rootID = this._raw.get("root") as unknown as
79
- | ID<NonNullable<this["root"]>>
80
- | undefined;
81
- return {
82
- profile: profileID
83
- ? (new Ref(
84
- profileID,
85
- this._loadedAs,
86
- this._schema.profile as RefEncoded<NonNullable<this["profile"]>>,
87
- this,
88
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
- ) as any as this["profile"] extends Profile
90
- ? Ref<this["profile"]>
91
- : never)
92
- : undefined,
93
- root: rootID
94
- ? (new Ref(
95
- rootID,
96
- this._loadedAs,
97
- this._schema.root as RefEncoded<NonNullable<this["root"]>>,
98
- this,
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
- ) as any as this["root"] extends CoMap ? Ref<this["root"]> : never)
101
- : undefined,
102
- };
50
+ this.prototype[TypeSym] = "Group";
103
51
  }
52
+ declare $jazz: GroupJazzApi<this>;
104
53
 
105
54
  /** @deprecated Don't use constructor directly, use .create */
106
- constructor(options: { fromRaw: RawGroup } | { owner: Account | Group }) {
55
+ constructor(options: { fromRaw: RawGroup } | { owner: Account }) {
107
56
  super();
108
57
  let raw: RawGroup;
109
58
 
@@ -112,23 +61,27 @@ export class Group extends CoValueBase implements CoValue {
112
61
  } else {
113
62
  const initOwner = options.owner;
114
63
  if (!initOwner) throw new Error("No owner provided");
115
- if (initOwner._type === "Account" && isControlledAccount(initOwner)) {
116
- const rawOwner = initOwner._raw;
64
+ if (initOwner[TypeSym] === "Account" && isControlledAccount(initOwner)) {
65
+ const rawOwner = initOwner.$jazz.raw;
117
66
  raw = rawOwner.core.node.createGroup();
118
67
  } else {
119
68
  throw new Error("Can only construct group as a controlled account");
120
69
  }
121
70
  }
122
71
 
72
+ const proxy = new Proxy(
73
+ this,
74
+ AccountAndGroupProxyHandler as ProxyHandler<this>,
75
+ );
76
+
123
77
  Object.defineProperties(this, {
124
- id: {
125
- value: raw.id,
78
+ $jazz: {
79
+ value: new GroupJazzApi(proxy, raw),
126
80
  enumerable: false,
127
81
  },
128
- _raw: { value: raw, enumerable: false },
129
82
  });
130
83
 
131
- return new Proxy(this, AccountAndGroupProxyHandler as ProxyHandler<this>);
84
+ return proxy;
132
85
  }
133
86
 
134
87
  static create<G extends Group>(
@@ -139,7 +92,7 @@ export class Group extends CoValueBase implements CoValue {
139
92
  }
140
93
 
141
94
  myRole(): Role | undefined {
142
- return this._raw.myRole();
95
+ return this.$jazz.raw.myRole();
143
96
  }
144
97
 
145
98
  addMember(member: Everyone, role: "writer" | "reader" | "writeOnly"): void;
@@ -158,12 +111,15 @@ export class Group extends CoValueBase implements CoValue {
158
111
  member: Group | Everyone | Account,
159
112
  role?: AccountRole | "inherit",
160
113
  ) {
161
- if (member !== "everyone" && member._type === "Group") {
114
+ if (member !== "everyone" && member[TypeSym] === "Group") {
162
115
  if (role === "writeOnly")
163
116
  throw new Error("Cannot add group as member with write-only role");
164
- this._raw.extend(member._raw, role);
117
+ this.$jazz.raw.extend(member.$jazz.raw, role);
165
118
  } else if (role !== undefined && role !== "inherit") {
166
- this._raw.addMember(member === "everyone" ? member : member._raw, role);
119
+ this.$jazz.raw.addMember(
120
+ member === "everyone" ? member : member.$jazz.raw,
121
+ role,
122
+ );
167
123
  }
168
124
  }
169
125
 
@@ -174,23 +130,18 @@ export class Group extends CoValueBase implements CoValue {
174
130
  */
175
131
  removeMember(member: Group): void;
176
132
  removeMember(member: Group | Everyone | Account) {
177
- if (member !== "everyone" && member._type === "Group") {
178
- this._raw.revokeExtend(member._raw);
133
+ if (member !== "everyone" && member[TypeSym] === "Group") {
134
+ this.$jazz.raw.revokeExtend(member.$jazz.raw);
179
135
  } else {
180
- return this._raw.removeMember(
181
- member === "everyone" ? member : member._raw,
136
+ return this.$jazz.raw.removeMember(
137
+ member === "everyone" ? member : member.$jazz.raw,
182
138
  );
183
139
  }
184
140
  }
185
141
 
186
142
  private getMembersFromKeys(
187
143
  accountIDs: Iterable<RawAccountID | AgentID>,
188
- ): Array<{
189
- id: string;
190
- role: AccountRole;
191
- ref: Ref<Account>;
192
- account: Account;
193
- }> {
144
+ ): GroupMember[] {
194
145
  const members = [];
195
146
 
196
147
  const refEncodedAccountSchema = {
@@ -201,7 +152,7 @@ export class Group extends CoValueBase implements CoValue {
201
152
  for (const accountID of accountIDs) {
202
153
  if (!isAccountID(accountID)) continue;
203
154
 
204
- const role = this._raw.roleOf(accountID);
155
+ const role = this.$jazz.raw.roleOf(accountID);
205
156
 
206
157
  if (
207
158
  role === "admin" ||
@@ -211,7 +162,7 @@ export class Group extends CoValueBase implements CoValue {
211
162
  ) {
212
163
  const ref = new Ref<Account>(
213
164
  accountID,
214
- this._loadedAs,
165
+ this.$jazz.loadedAs,
215
166
  refEncodedAccountSchema,
216
167
  this,
217
168
  );
@@ -242,8 +193,8 @@ export class Group extends CoValueBase implements CoValue {
242
193
  *
243
194
  * @returns The members of the group.
244
195
  */
245
- get members() {
246
- return this.getMembersFromKeys(this._raw.getAllMemberKeysSet());
196
+ get members(): GroupMember[] {
197
+ return this.getMembersFromKeys(this.$jazz.raw.getAllMemberKeysSet());
247
198
  }
248
199
 
249
200
  /**
@@ -253,20 +204,18 @@ export class Group extends CoValueBase implements CoValue {
253
204
  * parent groups, use {@link Group.members|members} instead.
254
205
  * @returns The direct members of the group.
255
206
  */
256
- getDirectMembers() {
257
- return this.getMembersFromKeys(this._raw.getMemberKeys());
207
+ getDirectMembers(): GroupMember[] {
208
+ return this.getMembersFromKeys(this.$jazz.raw.getMemberKeys());
258
209
  }
259
210
 
260
- getRoleOf(member: Everyone | ID<Account> | "me") {
261
- if (member === "me") {
262
- return this._raw.roleOf(
263
- activeAccountContext.get().id as unknown as RawAccountID,
264
- );
265
- }
266
-
267
- return this._raw.roleOf(
268
- member === "everyone" ? member : (member as unknown as RawAccountID),
269
- );
211
+ getRoleOf(member: Everyone | ID<Account> | "me"): Role | undefined {
212
+ const accountId =
213
+ member === "me"
214
+ ? (activeAccountContext.get().$jazz.id as RawAccountID)
215
+ : member === "everyone"
216
+ ? member
217
+ : (member as RawAccountID);
218
+ return this.$jazz.raw.roleOf(accountId);
270
219
  }
271
220
 
272
221
  /**
@@ -276,13 +225,15 @@ export class Group extends CoValueBase implements CoValue {
276
225
  * @param role - Optional: the role to grant to everyone. Defaults to "reader".
277
226
  * @returns The group itself.
278
227
  */
279
- makePublic(role: "reader" | "writer" = "reader") {
228
+ makePublic(role: "reader" | "writer" = "reader"): this {
280
229
  this.addMember("everyone", role);
281
230
  return this;
282
231
  }
283
232
 
284
233
  getParentGroups(): Array<Group> {
285
- return this._raw.getParentGroups().map((group) => Group.fromRaw(group));
234
+ return this.$jazz.raw
235
+ .getParentGroups()
236
+ .map((group) => Group.fromRaw(group));
286
237
  }
287
238
 
288
239
  /** @category Identity & Permissions
@@ -295,8 +246,8 @@ export class Group extends CoValueBase implements CoValue {
295
246
  extend(
296
247
  parent: Group,
297
248
  roleMapping?: "reader" | "writer" | "admin" | "inherit",
298
- ) {
299
- this._raw.extend(parent._raw, roleMapping);
249
+ ): this {
250
+ this.$jazz.raw.extend(parent.$jazz.raw, roleMapping);
300
251
  return this;
301
252
  }
302
253
 
@@ -306,8 +257,8 @@ export class Group extends CoValueBase implements CoValue {
306
257
  * @param parent The group that will lose access to this group.
307
258
  * @returns This group.
308
259
  */
309
- async revokeExtend(parent: Group) {
310
- await this._raw.revokeExtend(parent._raw);
260
+ async revokeExtend(parent: Group): Promise<this> {
261
+ await this.$jazz.raw.revokeExtend(parent.$jazz.raw);
311
262
  return this;
312
263
  }
313
264
 
@@ -340,31 +291,55 @@ export class Group extends CoValueBase implements CoValue {
340
291
  const { options, listener } = parseSubscribeRestArgs(args);
341
292
  return subscribeToCoValueWithoutMe<G, R>(this, id, options, listener);
342
293
  }
294
+ }
295
+
296
+ export class GroupJazzApi<G extends Group> extends CoValueJazzApi<G> {
297
+ constructor(
298
+ private group: G,
299
+ public raw: RawGroup,
300
+ ) {
301
+ super(group);
302
+ }
303
+
304
+ /**
305
+ * The ID of this `Group`
306
+ * @category Content
307
+ */
308
+ get id(): ID<G> {
309
+ return this.raw.id;
310
+ }
311
+
312
+ /**
313
+ * Groups have no owner. They can be accessed by everyone.
314
+ */
315
+ get owner(): undefined {
316
+ return undefined;
317
+ }
343
318
 
344
319
  /** @category Subscription & Loading */
345
320
  ensureLoaded<G extends Group, const R extends RefsToResolve<G>>(
346
- this: G,
321
+ this: GroupJazzApi<G>,
347
322
  options?: { resolve?: RefsToResolveStrict<G, R> },
348
323
  ): Promise<Resolved<G, R>> {
349
- return ensureCoValueLoaded(this, options);
324
+ return ensureCoValueLoaded(this.group, options);
350
325
  }
351
326
 
352
327
  /** @category Subscription & Loading */
353
328
  subscribe<G extends Group, const R extends RefsToResolve<G>>(
354
- this: G,
329
+ this: GroupJazzApi<G>,
355
330
  listener: (value: Resolved<G, R>, unsubscribe: () => void) => void,
356
331
  ): () => void;
357
332
  subscribe<G extends Group, const R extends RefsToResolve<G>>(
358
- this: G,
333
+ this: GroupJazzApi<G>,
359
334
  options: { resolve?: RefsToResolveStrict<G, R> },
360
335
  listener: (value: Resolved<G, R>, unsubscribe: () => void) => void,
361
336
  ): () => void;
362
337
  subscribe<G extends Group, const R extends RefsToResolve<G>>(
363
- this: G,
338
+ this: GroupJazzApi<G>,
364
339
  ...args: SubscribeRestArgs<G, R>
365
340
  ): () => void {
366
341
  const { options, listener } = parseSubscribeRestArgs(args);
367
- return subscribeToExistingCoValue(this, options, listener);
342
+ return subscribeToExistingCoValue(this.group, options, listener);
368
343
  }
369
344
 
370
345
  /**
@@ -373,7 +348,7 @@ export class Group extends CoValueBase implements CoValue {
373
348
  * @category Subscription & Loading
374
349
  */
375
350
  waitForSync(options?: { timeout?: number }) {
376
- return this._raw.core.waitForSync(options);
351
+ return this.raw.core.waitForSync(options);
377
352
  }
378
353
  }
379
354
 
@@ -382,3 +357,14 @@ RegisteredSchemas["Group"] = Group;
382
357
  export function isAccountID(id: RawAccountID | AgentID): id is RawAccountID {
383
358
  return id.startsWith("co_");
384
359
  }
360
+
361
+ export function getCoValueOwner(coValue: CoValue): Group {
362
+ const group = accessChildById(coValue, coValue.$jazz.raw.group.id, {
363
+ ref: RegisteredSchemas["Group"],
364
+ optional: false,
365
+ });
366
+ if (!group) {
367
+ throw new Error("CoValue has no owner");
368
+ }
369
+ return group;
370
+ }
@@ -29,11 +29,11 @@ export type InboxRoot = RawCoMap<{
29
29
  }>;
30
30
 
31
31
  export function createInboxRoot(account: Account) {
32
- if (!account.isLocalNodeOwner) {
32
+ if (!account.$jazz.isLocalNodeOwner) {
33
33
  throw new Error("Account is not controlled");
34
34
  }
35
35
 
36
- const rawAccount = account._raw;
36
+ const rawAccount = account.$jazz.raw;
37
37
 
38
38
  const group = rawAccount.core.node.createGroup();
39
39
  const messagesFeed = group.createStream<MessagesStream>();
@@ -66,7 +66,7 @@ async function createInboxMessage<
66
66
  I extends CoValue,
67
67
  O extends CoValue | undefined,
68
68
  >(payload: I, inboxOwner: RawAccount) {
69
- const group = payload._raw.group;
69
+ const group = payload.$jazz.raw.group;
70
70
 
71
71
  if (group instanceof RawAccount) {
72
72
  throw new Error("Inbox messages should be owned by a group");
@@ -75,13 +75,13 @@ async function createInboxMessage<
75
75
  group.addMember(inboxOwner, "writer");
76
76
 
77
77
  const message = group.createMap<InboxMessage<I, O>>({
78
- payload: payload.id,
78
+ payload: payload.$jazz.id,
79
79
  result: undefined,
80
80
  processed: false,
81
81
  error: undefined,
82
82
  });
83
83
 
84
- await payload._raw.core.waitForSync();
84
+ await payload.$jazz.raw.core.waitForSync();
85
85
  await message.core.waitForSync();
86
86
 
87
87
  return message;
@@ -119,7 +119,7 @@ export class Inbox {
119
119
  ) {
120
120
  const processed = new Set<`${SessionID}/${number}`>();
121
121
  const failed = new Map<`${SessionID}/${number}`, string[]>();
122
- const node = this.account._raw.core.node;
122
+ const node = this.account.$jazz.localNode;
123
123
 
124
124
  this.processed.subscribe((stream) => {
125
125
  for (const items of Object.values(stream.items)) {
@@ -194,7 +194,7 @@ export class Inbox {
194
194
  .getCurrentContent() as RawCoMap;
195
195
 
196
196
  if (result) {
197
- inboxMessage.set("result", result.id);
197
+ inboxMessage.set("result", result.$jazz.id);
198
198
  }
199
199
 
200
200
  inboxMessage.set("processed", true);
@@ -258,7 +258,7 @@ export class Inbox {
258
258
  throw new Error("The account has not set up their inbox");
259
259
  }
260
260
 
261
- const node = account._raw.core.node;
261
+ const node = account.$jazz.localNode;
262
262
 
263
263
  const root = await node.load(profile.inbox as CoID<InboxRoot>);
264
264
 
@@ -332,7 +332,7 @@ export class InboxSender<I extends CoValue, O extends CoValue | undefined> {
332
332
  >(inboxOwnerID: ID<Account>, currentAccount?: Account) {
333
333
  currentAccount ||= activeAccountContext.get();
334
334
 
335
- const node = currentAccount._raw.core.node;
335
+ const node = currentAccount.$jazz.localNode;
336
336
 
337
337
  const inboxOwnerRaw = await node.load(
338
338
  inboxOwnerID as unknown as CoID<RawAccount>,
@@ -349,9 +349,11 @@ export class InboxSender<I extends CoValue, O extends CoValue | undefined> {
349
349
  }
350
350
 
351
351
  if (
352
- inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "reader" &&
353
- inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "writer" &&
354
- inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "admin"
352
+ inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !==
353
+ "reader" &&
354
+ inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !==
355
+ "writer" &&
356
+ inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "admin"
355
357
  ) {
356
358
  throw new Error(
357
359
  "Insufficient permissions to access the inbox, make sure its user profile is publicly readable.",
@@ -387,11 +389,11 @@ async function acceptInvite(invite: string, account?: Account) {
387
389
  throw new Error("Invalid inbox ticket");
388
390
  }
389
391
 
390
- if (!account.isLocalNodeOwner) {
392
+ if (!account.$jazz.isLocalNodeOwner) {
391
393
  throw new Error("Account is not controlled");
392
394
  }
393
395
 
394
- await account._raw.core.node.acceptInvite(id, inviteSecret);
396
+ await account.$jazz.localNode.acceptInvite(id, inviteSecret);
395
397
 
396
398
  return id;
397
399
  }
@@ -18,6 +18,7 @@ import {
18
18
  Resolved,
19
19
  SubscriptionScope,
20
20
  type SubscriptionValue,
21
+ TypeSym,
21
22
  activeAccountContext,
22
23
  coValueClassFromCoValueClassOrSchema,
23
24
  inspect,
@@ -32,26 +33,28 @@ export interface CoValueClass<Value extends CoValue = CoValue> {
32
33
  }
33
34
 
34
35
  export interface CoValueFromRaw<V extends CoValue> {
35
- fromRaw(raw: V["_raw"]): V;
36
+ fromRaw(raw: V["$jazz"]["raw"]): V;
36
37
  }
37
38
 
38
39
  /** @category Abstract interfaces */
39
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
41
  export interface CoValue {
41
- /** @category Content */
42
- readonly id: ID<this>;
43
42
  /** @category Type Helpers */
44
- _type: string;
45
- /** @category Collaboration */
46
- _owner: Account | Group;
47
- /** @category Internals */
48
- _raw: RawCoValue;
49
-
50
- /** @internal */
51
- _subscriptionScope?: SubscriptionScope<this>;
43
+ [TypeSym]: string;
44
+
45
+ $jazz: {
46
+ /** @category Content */
47
+ readonly id: ID<CoValue>;
48
+ /** @category Collaboration */
49
+ owner?: Group;
50
+ /** @internal */
51
+ readonly loadedAs: Account | AnonymousJazzAgent;
52
+ /** @category Internals */
53
+ raw: RawCoValue;
54
+ /** @internal */
55
+ _subscriptionScope?: SubscriptionScope<CoValue>;
56
+ };
52
57
 
53
- /** @internal */
54
- readonly _loadedAs: Account | AnonymousJazzAgent;
55
58
  /** @category Stringifying & Inspection */
56
59
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
60
  toJSON(key?: string, seenAbove?: ID<CoValue>[]): any[] | object | string;
@@ -62,7 +65,7 @@ export interface CoValue {
62
65
 
63
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
67
  export function isCoValue(value: any): value is CoValue {
65
- return value && value._type !== undefined;
68
+ return value && value[TypeSym] !== undefined;
66
69
  }
67
70
 
68
71
  export function isCoValueClass<V extends CoValue>(
@@ -149,15 +152,15 @@ export async function ensureCoValueLoaded<
149
152
  ): Promise<Resolved<V, R>> {
150
153
  const response = await loadCoValue(
151
154
  existing.constructor as CoValueClass<V>,
152
- existing.id,
155
+ existing.$jazz.id,
153
156
  {
154
- loadAs: existing._loadedAs,
157
+ loadAs: existing.$jazz.loadedAs,
155
158
  resolve: options?.resolve,
156
159
  },
157
160
  );
158
161
 
159
162
  if (!response) {
160
- throw new Error("Failed to deeply load CoValue " + existing.id);
163
+ throw new Error("Failed to deeply load CoValue " + existing.$jazz.id);
161
164
  }
162
165
 
163
166
  return response;
@@ -255,7 +258,7 @@ export function subscribeToCoValue<
255
258
  listener: SubscribeListener<V, R>,
256
259
  ): () => void {
257
260
  const loadAs = options.loadAs ?? activeAccountContext.get();
258
- const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
261
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
259
262
 
260
263
  const resolve = options.resolve ?? true;
261
264
 
@@ -325,9 +328,9 @@ export function subscribeToExistingCoValue<
325
328
  ): () => void {
326
329
  return subscribeToCoValue(
327
330
  existing.constructor as CoValueClass<V>,
328
- existing.id,
331
+ existing.$jazz.id,
329
332
  {
330
- loadAs: existing._loadedAs,
333
+ loadAs: existing.$jazz.loadedAs,
331
334
  resolve: options?.resolve,
332
335
  onUnavailable: options?.onUnavailable,
333
336
  onUnauthorized: options?.onUnauthorized,
@@ -341,7 +344,7 @@ export function isAccountInstance(instance: unknown): instance is Account {
341
344
  return false;
342
345
  }
343
346
 
344
- return "_type" in instance && instance._type === "Account";
347
+ return TypeSym in instance && instance[TypeSym] === "Account";
345
348
  }
346
349
 
347
350
  export function isAnonymousAgentInstance(
@@ -351,7 +354,7 @@ export function isAnonymousAgentInstance(
351
354
  return false;
352
355
  }
353
356
 
354
- return "_type" in instance && instance._type === "Anonymous";
357
+ return TypeSym in instance && instance[TypeSym] === "Anonymous";
355
358
  }
356
359
 
357
360
  export function parseCoValueCreateOptions(
@@ -363,15 +366,20 @@ export function parseCoValueCreateOptions(
363
366
  | Account
364
367
  | Group
365
368
  | undefined,
366
- ) {
369
+ ): {
370
+ owner: Group;
371
+ uniqueness?: CoValueUniqueness;
372
+ } {
367
373
  const Group = RegisteredSchemas["Group"];
368
374
 
369
375
  if (!options) {
370
376
  return { owner: Group.create(), uniqueness: undefined };
371
377
  }
372
378
 
373
- if ("_type" in options) {
374
- if (options._type === "Account" || options._type === "Group") {
379
+ if (TypeSym in options) {
380
+ if (options[TypeSym] === "Account") {
381
+ return { owner: accountOrGroupToGroup(options), uniqueness: undefined };
382
+ } else if (options[TypeSym] === "Group") {
375
383
  return { owner: options, uniqueness: undefined };
376
384
  }
377
385
  }
@@ -380,10 +388,20 @@ export function parseCoValueCreateOptions(
380
388
  ? { uniqueness: options.unique }
381
389
  : undefined;
382
390
 
383
- return {
384
- owner: options.owner ?? Group.create(),
391
+ const opts = {
392
+ owner: options.owner
393
+ ? accountOrGroupToGroup(options.owner)
394
+ : Group.create(),
385
395
  uniqueness,
386
396
  };
397
+ return opts;
398
+ }
399
+
400
+ export function accountOrGroupToGroup(accountOrGroup: Account | Group): Group {
401
+ if (accountOrGroup[TypeSym] === "Group") {
402
+ return accountOrGroup;
403
+ }
404
+ return RegisteredSchemas["Group"].fromRaw(accountOrGroup.$jazz.raw);
387
405
  }
388
406
 
389
407
  export function parseGroupCreateOptions(
@@ -398,7 +416,7 @@ export function parseGroupCreateOptions(
398
416
  return { owner: activeAccountContext.get() };
399
417
  }
400
418
 
401
- return "_type" in options && isAccountInstance(options)
419
+ return TypeSym in options && isAccountInstance(options)
402
420
  ? { owner: options }
403
421
  : { owner: options.owner ?? activeAccountContext.get() };
404
422
  }
@@ -460,7 +478,7 @@ export async function exportCoValue<
460
478
  },
461
479
  ) {
462
480
  const loadAs = options.loadAs ?? activeAccountContext.get();
463
- const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
481
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
464
482
 
465
483
  const resolve = options.resolve ?? true;
466
484
 
@@ -515,7 +533,7 @@ function loadContentPiecesFromSubscription(
515
533
 
516
534
  valuesExported.add(subscription.id);
517
535
 
518
- const core = subscription.getCurrentValue()?._raw
536
+ const core = subscription.getCurrentValue()?.$jazz.raw
519
537
  .core as AvailableCoValueCore;
520
538
 
521
539
  if (core) {
@@ -563,7 +581,7 @@ export function importContentPieces(
563
581
  loadAs?: Account | AnonymousJazzAgent,
564
582
  ) {
565
583
  const account = loadAs ?? Account.getMe();
566
- const node = "node" in account ? account.node : account._raw.core.node;
584
+ const node = "node" in account ? account.node : account.$jazz.localNode;
567
585
 
568
586
  for (const piece of contentPieces) {
569
587
  node.syncManager.handleNewContent(piece, "import");