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
@@ -119,35 +119,8 @@ function isAnyCoValueSchema(schema) {
119
119
  }
120
120
 
121
121
  // src/tools/coValues/CoValueBase.ts
122
- import { ControlledAccount, RawAccount } from "cojson";
122
+ import { ControlledAccount } from "cojson";
123
123
  var CoValueBase = class {
124
- get _owner() {
125
- const schema = this._raw.group instanceof RawAccount ? RegisteredSchemas["Account"] : RegisteredSchemas["Group"];
126
- return accessChildById(this, this._raw.group.id, {
127
- ref: schema,
128
- optional: false
129
- });
130
- }
131
- /** @private */
132
- get _loadedAs() {
133
- const agent = this._raw.core.node.getCurrentAgent();
134
- if (agent instanceof ControlledAccount) {
135
- return coValuesCache.get(
136
- agent.account,
137
- () => coValueClassFromCoValueClassOrSchema(
138
- RegisteredSchemas["Account"]
139
- ).fromRaw(agent.account)
140
- );
141
- }
142
- return new AnonymousJazzAgent(this._raw.core.node);
143
- }
144
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- constructor(..._args) {
146
- Object.defineProperty(this, "_instanceID", {
147
- value: `instance-${Math.random().toString(36).slice(2)}`,
148
- enumerable: false
149
- });
150
- }
151
124
  /** @category Internals */
152
125
  static fromRaw(raw) {
153
126
  return new this({ fromRaw: raw });
@@ -155,21 +128,39 @@ var CoValueBase = class {
155
128
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
156
129
  toJSON() {
157
130
  return {
158
- id: this.id,
159
- type: this._type,
131
+ id: this.$jazz.id,
132
+ type: this[TypeSym],
160
133
  error: "unknown CoValue class"
161
134
  };
162
135
  }
163
136
  [inspect]() {
164
137
  return this.toJSON();
165
138
  }
166
- /** @category Type Helpers */
167
- castAs(schema) {
168
- const cl = isCoValueSchema(schema) ? schema.getCoValueClass() : schema;
169
- if (this.constructor === cl) {
170
- return this;
139
+ };
140
+ var CoValueJazzApi = class {
141
+ constructor(coValue) {
142
+ this.coValue = coValue;
143
+ Object.defineProperty(this, "_instanceID", {
144
+ value: `instance-${Math.random().toString(36).slice(2)}`,
145
+ enumerable: false
146
+ });
147
+ }
148
+ /** @internal */
149
+ get localNode() {
150
+ return this.raw.core.node;
151
+ }
152
+ /** @private */
153
+ get loadedAs() {
154
+ const agent = this.localNode.getCurrentAgent();
155
+ if (agent instanceof ControlledAccount) {
156
+ return coValuesCache.get(
157
+ agent.account,
158
+ () => coValueClassFromCoValueClassOrSchema(
159
+ RegisteredSchemas["Account"]
160
+ ).fromRaw(agent.account)
161
+ );
171
162
  }
172
- return cl.fromRaw(this._raw);
163
+ return new AnonymousJazzAgent(this.localNode);
173
164
  }
174
165
  };
175
166
 
@@ -179,6 +170,7 @@ var inspect = Symbol.for("nodejs.util.inspect.custom");
179
170
  // src/tools/implementation/symbols.ts
180
171
  var SchemaInit = "$SchemaInit$";
181
172
  var ItemsSym = "$items$";
173
+ var TypeSym = "$type$";
182
174
 
183
175
  // src/tools/coValues/registeredSchemas.ts
184
176
  var RegisteredSchemas = {};
@@ -188,125 +180,23 @@ import {
188
180
  cojsonInternals
189
181
  } from "cojson";
190
182
  var _CoMap = class _CoMap extends CoValueBase {
191
- /** @internal */
192
- get _schema() {
193
- return this.constructor._schema;
194
- }
195
- /**
196
- * The timestamp of the creation time of the CoMap
197
- */
198
- get _createdAt() {
199
- return this._raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
200
- }
201
- /**
202
- * The timestamp of the last updated time of the CoMap
203
- */
204
- get _lastUpdatedAt() {
205
- return this._raw.latestTxMadeAt;
206
- }
207
- /**
208
- * If property `prop` is a `coField.ref(...)`, you can use `coMaps._refs.prop` to access
209
- * the `Ref` instead of the potentially loaded/null value.
210
- *
211
- * This allows you to always get the ID or load the value manually.
212
- *
213
- * @example
214
- * ```ts
215
- * person._refs.pet.id; // => ID<Animal>
216
- * person._refs.pet.value;
217
- * // => Animal | null
218
- * const pet = await person._refs.pet.load();
219
- * ```
220
- *
221
- * @category Content
222
- **/
223
- get _refs() {
224
- return makeRefs(
225
- this,
226
- (key) => this._raw.get(key),
227
- () => {
228
- const keys = this._raw.keys().filter((key) => {
229
- const descriptor = this.getDescriptor(key);
230
- return descriptor && descriptor !== "json" && isRefEncoded(descriptor);
231
- });
232
- return keys;
233
- },
234
- this._loadedAs,
235
- (key) => this.getDescriptor(key)
236
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
- );
238
- }
239
- /** @internal */
240
- getEditFromRaw(target, rawEdit, descriptor, key) {
241
- return {
242
- value: descriptor === "json" ? rawEdit.value : "encoded" in descriptor ? rawEdit.value === null || rawEdit.value === void 0 ? rawEdit.value : descriptor.encoded.decode(rawEdit.value) : accessChildById(target, rawEdit.value, descriptor),
243
- ref: descriptor !== "json" && isRefEncoded(descriptor) ? new Ref(
244
- rawEdit.value,
245
- target._loadedAs,
246
- descriptor,
247
- target
248
- ) : void 0,
249
- get by() {
250
- return rawEdit.by && accessChildById(target, rawEdit.by, {
251
- ref: Account,
252
- optional: false
253
- });
254
- },
255
- madeAt: rawEdit.at,
256
- key
257
- };
258
- }
259
- /** @category Collaboration */
260
- get _edits() {
261
- const map = this;
262
- return new Proxy(
263
- {},
264
- {
265
- get(_target, key) {
266
- const rawEdit = map._raw.lastEditAt(key);
267
- if (!rawEdit) return void 0;
268
- const descriptor = map.getDescriptor(key);
269
- if (!descriptor) return void 0;
270
- return {
271
- ...map.getEditFromRaw(map, rawEdit, descriptor, key),
272
- get all() {
273
- return [...map._raw.editsAt(key)].map(
274
- (rawEdit2) => map.getEditFromRaw(map, rawEdit2, descriptor, key)
275
- );
276
- }
277
- };
278
- },
279
- ownKeys(_target) {
280
- return map._raw.keys();
281
- },
282
- getOwnPropertyDescriptor(target, key) {
283
- return {
284
- value: Reflect.get(target, key),
285
- writable: false,
286
- enumerable: true,
287
- configurable: true
288
- };
289
- }
290
- }
291
- );
292
- }
293
183
  /** @internal */
294
184
  constructor(options) {
295
185
  super();
186
+ const proxy = new Proxy(this, CoMapProxyHandler);
296
187
  if (options) {
297
188
  if ("fromRaw" in options) {
298
189
  Object.defineProperties(this, {
299
- id: {
300
- value: options.fromRaw.id,
190
+ $jazz: {
191
+ value: new CoMapJazzApi(proxy, () => options.fromRaw),
301
192
  enumerable: false
302
- },
303
- _raw: { value: options.fromRaw, enumerable: false }
193
+ }
304
194
  });
305
195
  } else {
306
196
  throw new Error("Invalid CoMap constructor arguments");
307
197
  }
308
198
  }
309
- return new Proxy(this, CoMapProxyHandler);
199
+ return proxy;
310
200
  }
311
201
  /**
312
202
  * Create a new CoMap with the given initial values and owner.
@@ -325,10 +215,12 @@ var _CoMap = class _CoMap extends CoValueBase {
325
215
  * ```
326
216
  *
327
217
  * @category Creation
218
+ *
219
+ * @deprecated Use `co.map(...).create`.
328
220
  **/
329
221
  static create(init, options) {
330
222
  const instance = new this();
331
- return instance._createCoMap(init, options);
223
+ return _CoMap._createCoMap(instance, init, options);
332
224
  }
333
225
  /**
334
226
  * Return a JSON representation of the `CoMap`
@@ -336,21 +228,18 @@ var _CoMap = class _CoMap extends CoValueBase {
336
228
  */
337
229
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
338
230
  toJSON(_key, processedValues) {
339
- const result = {
340
- id: this.id,
341
- _type: this._type
342
- };
343
- for (const key of this._raw.keys()) {
231
+ const result = {};
232
+ for (const key of this.$jazz.raw.keys()) {
344
233
  const tKey = key;
345
- const descriptor = this.getDescriptor(tKey);
234
+ const descriptor = this.$jazz.getDescriptor(tKey);
346
235
  if (!descriptor) {
347
236
  continue;
348
237
  }
349
238
  if (descriptor == "json" || "encoded" in descriptor) {
350
- result[key] = this._raw.get(key);
239
+ result[key] = this.$jazz.raw.get(key);
351
240
  } else if (isRefEncoded(descriptor)) {
352
- const id = this._raw.get(key);
353
- if (processedValues?.includes(id) || id === this.id) {
241
+ const id = this.$jazz.raw.get(key);
242
+ if (processedValues?.includes(id) || id === this.$jazz.id) {
354
243
  result[key] = { _circular: id };
355
244
  continue;
356
245
  }
@@ -358,7 +247,7 @@ var _CoMap = class _CoMap extends CoValueBase {
358
247
  if (ref2 && typeof ref2 === "object" && "toJSON" in ref2 && typeof ref2.toJSON === "function") {
359
248
  const jsonedRef = ref2.toJSON(tKey, [
360
249
  ...processedValues || [],
361
- this.id
250
+ this.$jazz.id
362
251
  ]);
363
252
  result[key] = jsonedRef;
364
253
  }
@@ -371,30 +260,31 @@ var _CoMap = class _CoMap extends CoValueBase {
371
260
  [inspect]() {
372
261
  return this.toJSON();
373
262
  }
374
- _createCoMap(init, options) {
263
+ /**
264
+ * @internal
265
+ */
266
+ static _createCoMap(instance, init, options) {
375
267
  const { owner, uniqueness } = parseCoValueCreateOptions(options);
376
- const raw = this.rawFromInit(init, owner, uniqueness);
377
- Object.defineProperties(this, {
378
- id: {
379
- value: raw.id,
268
+ Object.defineProperties(instance, {
269
+ $jazz: {
270
+ value: new CoMapJazzApi(instance, () => raw),
380
271
  enumerable: false
381
- },
382
- _raw: { value: raw, enumerable: false }
272
+ }
383
273
  });
384
- return this;
274
+ const raw = _CoMap.rawFromInit(instance, init, owner, uniqueness);
275
+ return instance;
385
276
  }
386
277
  /**
387
278
  * Create a new `RawCoMap` from an initialization object
388
279
  * @internal
389
280
  */
390
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
391
- rawFromInit(init, owner, uniqueness) {
392
- const rawOwner = owner._raw;
281
+ static rawFromInit(instance, init, owner, uniqueness) {
282
+ const rawOwner = owner.$jazz.raw;
393
283
  const rawInit = {};
394
284
  if (init)
395
285
  for (const key of Object.keys(init)) {
396
286
  const initValue = init[key];
397
- const descriptor = this.getDescriptor(key);
287
+ const descriptor = instance.$jazz.getDescriptor(key);
398
288
  if (!descriptor) {
399
289
  continue;
400
290
  }
@@ -402,14 +292,14 @@ var _CoMap = class _CoMap extends CoValueBase {
402
292
  rawInit[key] = initValue;
403
293
  } else if (isRefEncoded(descriptor)) {
404
294
  if (initValue != null) {
405
- let refId = initValue.id;
295
+ let refId = initValue.$jazz?.id;
406
296
  if (!refId) {
407
297
  const coValue = instantiateRefEncodedWithInit(
408
298
  descriptor,
409
299
  initValue,
410
300
  owner
411
301
  );
412
- refId = coValue.id;
302
+ refId = coValue.$jazz.id;
413
303
  }
414
304
  rawInit[key] = refId;
415
305
  }
@@ -422,9 +312,6 @@ var _CoMap = class _CoMap extends CoValueBase {
422
312
  }
423
313
  return rawOwner.createMap(rawInit, null, "private", uniqueness);
424
314
  }
425
- getDescriptor(key) {
426
- return this._schema?.[key] || this._schema?.[ItemsSym];
427
- }
428
315
  /**
429
316
  * Declare a Record-like CoMap schema, by extending `CoMap.Record(...)` and passing the value schema using `co`. Keys are always `string`.
430
317
  *
@@ -444,11 +331,11 @@ var _CoMap = class _CoMap extends CoValueBase {
444
331
  * @category Declaration
445
332
  */
446
333
  static Record(value) {
447
- var _a, _b;
448
- class RecordLikeCoMap extends (_b = _CoMap, _a = ItemsSym, _b) {
334
+ var _a2, _b;
335
+ class RecordLikeCoMap extends (_b = _CoMap, _a2 = ItemsSym, _b) {
449
336
  constructor() {
450
337
  super(...arguments);
451
- this[_a] = value;
338
+ this[_a2] = value;
452
339
  }
453
340
  }
454
341
  return RecordLikeCoMap;
@@ -472,6 +359,8 @@ var _CoMap = class _CoMap extends CoValueBase {
472
359
  * ```
473
360
  *
474
361
  * @category Subscription & Loading
362
+ *
363
+ * @deprecated Use `co.map(...).load` instead.
475
364
  */
476
365
  static load(id, options) {
477
366
  return loadCoValueWithoutMe(this, id, options);
@@ -496,7 +385,7 @@ var _CoMap = class _CoMap extends CoValueBase {
496
385
  meta: null,
497
386
  uniqueness: unique
498
387
  };
499
- const crypto = as._type === "Anonymous" ? as.node.crypto : as._raw.core.node.crypto;
388
+ const crypto = as[TypeSym] === "Anonymous" ? as.node.crypto : as.$jazz.localNode.crypto;
500
389
  return cojsonInternals.idforHeader(header, crypto);
501
390
  }
502
391
  /**
@@ -521,30 +410,34 @@ var _CoMap = class _CoMap extends CoValueBase {
521
410
  * @param options The options for creating or loading the CoMap. This includes the intended state of the CoMap, its unique identifier, its owner, and the references to resolve.
522
411
  * @returns Either an existing & modified CoMap, or a new initialised CoMap if none exists.
523
412
  * @category Subscription & Loading
413
+ *
414
+ * @deprecated Use `co.map(...).upsertUnique` instead.
524
415
  */
525
416
  static async upsertUnique(options) {
526
417
  const mapId = _CoMap._findUnique(
527
418
  options.unique,
528
- options.owner.id,
529
- options.owner._loadedAs
419
+ options.owner.$jazz.id,
420
+ options.owner.$jazz.loadedAs
530
421
  );
531
422
  let map = await loadCoValueWithoutMe(this, mapId, {
532
423
  ...options,
533
- loadAs: options.owner._loadedAs,
424
+ loadAs: options.owner.$jazz.loadedAs,
534
425
  skipRetry: true
535
426
  });
536
427
  if (!map) {
537
428
  const instance = new this();
538
- map = instance._createCoMap(options.value, {
429
+ map = _CoMap._createCoMap(instance, options.value, {
539
430
  owner: options.owner,
540
431
  unique: options.unique
541
432
  });
542
433
  } else {
543
- map.applyDiff(options.value);
434
+ map.$jazz.applyDiff(
435
+ options.value
436
+ );
544
437
  }
545
438
  return await loadCoValueWithoutMe(this, mapId, {
546
439
  ...options,
547
- loadAs: options.owner._loadedAs,
440
+ loadAs: options.owner.$jazz.loadedAs,
548
441
  skipRetry: true
549
442
  });
550
443
  }
@@ -554,6 +447,8 @@ var _CoMap = class _CoMap extends CoValueBase {
554
447
  * @param ownerID The ID of the owner of the CoMap.
555
448
  * @param options Additional options for loading the CoMap.
556
449
  * @returns The loaded CoMap, or null if unavailable.
450
+ *
451
+ * @deprecated Use `co.map(...).loadUnique` instead.
557
452
  */
558
453
  static loadUnique(unique, ownerID, options) {
559
454
  return loadCoValueWithoutMe(
@@ -562,20 +457,87 @@ var _CoMap = class _CoMap extends CoValueBase {
562
457
  { ...options, skipRetry: true }
563
458
  );
564
459
  }
460
+ };
461
+ _CoMap.prototype[TypeSym] = "CoMap";
462
+ var CoMap = _CoMap;
463
+ var CoMapJazzApi = class extends CoValueJazzApi {
464
+ constructor(coMap, getRaw) {
465
+ super(coMap);
466
+ this.coMap = coMap;
467
+ this.getRaw = getRaw;
468
+ }
565
469
  /**
566
- * Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
470
+ * The ID of this `CoMap`
471
+ * @category Content
472
+ */
473
+ get id() {
474
+ return this.raw.id;
475
+ }
476
+ get owner() {
477
+ return getCoValueOwner(this.coMap);
478
+ }
479
+ /**
480
+ * Set a value on the CoMap
567
481
  *
568
- * Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.
482
+ * @param key The key to set
483
+ * @param value The value to set
569
484
  *
570
- * @category Subscription & Loading
485
+ * @category Content
571
486
  */
572
- ensureLoaded(options) {
573
- return ensureCoValueLoaded(this, options);
487
+ set(key, value) {
488
+ const descriptor = this.getDescriptor(key);
489
+ if (!descriptor) {
490
+ throw Error(`Cannot set unknown key ${key}`);
491
+ }
492
+ let refId = value?.$jazz?.id;
493
+ if (descriptor === "json") {
494
+ this.raw.set(key, value);
495
+ } else if ("encoded" in descriptor) {
496
+ this.raw.set(key, descriptor.encoded.encode(value));
497
+ } else if (isRefEncoded(descriptor)) {
498
+ if (value === void 0) {
499
+ if (!descriptor.optional) {
500
+ throw Error(`Cannot set required reference ${key} to undefined`);
501
+ }
502
+ this.raw.set(key, null);
503
+ } else {
504
+ if (!refId) {
505
+ const coValue = instantiateRefEncodedWithInit(
506
+ descriptor,
507
+ value,
508
+ this.owner
509
+ );
510
+ refId = coValue.$jazz.id;
511
+ }
512
+ this.raw.set(key, refId);
513
+ }
514
+ }
574
515
  }
575
- subscribe(...args) {
576
- const { options, listener } = parseSubscribeRestArgs(args);
577
- return subscribeToExistingCoValue(this, options, listener);
516
+ /**
517
+ * Delete a value from a CoMap.
518
+ *
519
+ * For record-like CoMaps (created with `co.record`), any string key can be deleted.
520
+ * For struct-like CoMaps (created with `co.map`), only optional properties can be deleted.
521
+ *
522
+ * @param key The key to delete
523
+ *
524
+ * @category Content
525
+ */
526
+ delete(key) {
527
+ this.raw.delete(key);
578
528
  }
529
+ /**
530
+ * Modify the `CoMap` to match another map.
531
+ *
532
+ * The new values are assigned to the CoMap, overwriting existing values
533
+ * when the property already exists.
534
+ *
535
+ * @param newValues - The new values to apply to the CoMap. For collaborative values,
536
+ * both CoValues and JSON values are supported.
537
+ * @returns The modified CoMap.
538
+ *
539
+ * @category Content
540
+ */
579
541
  applyDiff(newValues) {
580
542
  for (const key in newValues) {
581
543
  if (Object.prototype.hasOwnProperty.call(newValues, key)) {
@@ -583,33 +545,146 @@ var _CoMap = class _CoMap extends CoValueBase {
583
545
  const descriptor = this.getDescriptor(key);
584
546
  if (!descriptor) continue;
585
547
  const newValue = newValues[tKey];
586
- const currentValue = this[tKey];
548
+ const currentValue = this.coMap[tKey];
587
549
  if (descriptor === "json" || "encoded" in descriptor) {
588
550
  if (currentValue !== newValue) {
589
- this[tKey] = newValue;
551
+ this.set(tKey, newValue);
590
552
  }
591
553
  } else if (isRefEncoded(descriptor)) {
592
- const currentId = currentValue?.id;
593
- const newId = newValue?.id;
554
+ const currentId = currentValue?.$jazz.id;
555
+ let newId = newValue?.$jazz?.id;
594
556
  if (currentId !== newId) {
595
- this[tKey] = newValue;
557
+ this.set(tKey, newValue);
596
558
  }
597
559
  }
598
560
  }
599
561
  }
600
- return this;
562
+ return this.coMap;
563
+ }
564
+ /**
565
+ * Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
566
+ *
567
+ * Works like `CoMap.load()`, but you don't need to pass the ID or the account to load as again.
568
+ *
569
+ * @category Subscription & Loading
570
+ */
571
+ ensureLoaded(options) {
572
+ return ensureCoValueLoaded(this.coMap, options);
573
+ }
574
+ subscribe(...args) {
575
+ const { options, listener } = parseSubscribeRestArgs(args);
576
+ return subscribeToExistingCoValue(this.coMap, options, listener);
601
577
  }
602
578
  /**
603
579
  * Wait for the `CoMap` to be uploaded to the other peers.
604
580
  *
605
581
  * @category Subscription & Loading
606
582
  */
607
- waitForSync(options) {
608
- return this._raw.core.waitForSync(options);
583
+ async waitForSync(options) {
584
+ await this.raw.core.waitForSync(options);
585
+ }
586
+ /**
587
+ * Get the descriptor for a given key
588
+ * @internal
589
+ */
590
+ getDescriptor(key) {
591
+ return this.schema?.[key] || this.schema?.[ItemsSym];
592
+ }
593
+ /**
594
+ * If property `prop` is a `coField.ref(...)`, you can use `coMap.$jazz.refs.prop` to access
595
+ * the `Ref` instead of the potentially loaded/null value.
596
+ *
597
+ * This allows you to always get the ID or load the value manually.
598
+ *
599
+ * @example
600
+ * ```ts
601
+ * person.$jazz.refs.pet.id; // => ID<Animal>
602
+ * person.$jazz.refs.pet.value;
603
+ * // => Animal | null
604
+ * const pet = await person.$jazz.refs.pet.load();
605
+ * ```
606
+ *
607
+ * @category Content
608
+ **/
609
+ get refs() {
610
+ return makeRefs(
611
+ this.coMap,
612
+ (key) => this.raw.get(key),
613
+ () => {
614
+ const keys = this.raw.keys().filter((key) => {
615
+ const descriptor = this.getDescriptor(key);
616
+ return descriptor && descriptor !== "json" && isRefEncoded(descriptor);
617
+ });
618
+ return keys;
619
+ },
620
+ this.loadedAs,
621
+ (key) => this.getDescriptor(key)
622
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
623
+ );
624
+ }
625
+ /**
626
+ * Get the edits made to the CoMap.
627
+ *
628
+ * @category Collaboration
629
+ */
630
+ getEdits() {
631
+ const map = this.coMap;
632
+ return new Proxy(
633
+ {},
634
+ {
635
+ get(_target, key) {
636
+ const rawEdit = map.$jazz.raw.lastEditAt(key);
637
+ if (!rawEdit) return void 0;
638
+ const descriptor = map.$jazz.getDescriptor(key);
639
+ if (!descriptor) return void 0;
640
+ return {
641
+ ...getEditFromRaw(map, rawEdit, descriptor, key),
642
+ get all() {
643
+ return [...map.$jazz.raw.editsAt(key)].map(
644
+ (rawEdit2) => getEditFromRaw(map, rawEdit2, descriptor, key)
645
+ );
646
+ }
647
+ };
648
+ },
649
+ ownKeys(_target) {
650
+ return map.$jazz.raw.keys();
651
+ },
652
+ getOwnPropertyDescriptor(target, key) {
653
+ return {
654
+ value: Reflect.get(target, key),
655
+ writable: false,
656
+ enumerable: true,
657
+ configurable: true
658
+ };
659
+ }
660
+ }
661
+ );
662
+ }
663
+ /** @internal */
664
+ get raw() {
665
+ return this.getRaw();
666
+ }
667
+ /**
668
+ * The timestamp of the creation time of the CoMap
669
+ *
670
+ * @category Content
671
+ */
672
+ get createdAt() {
673
+ return this.raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
674
+ }
675
+ /**
676
+ * The timestamp of the last updated time of the CoMap
677
+ *
678
+ * @category Content
679
+ */
680
+ get lastUpdatedAt() {
681
+ return this.raw.latestTxMadeAt;
682
+ }
683
+ /** @internal */
684
+ get schema() {
685
+ return this.coMap.constructor._schema;
609
686
  }
610
687
  };
611
- _CoMap.prototype._type = "CoMap";
612
- var CoMap = _CoMap;
613
688
  var CoMapProxyHandler = {
614
689
  get(target, key, receiver) {
615
690
  if (key === "_schema") {
@@ -620,11 +695,11 @@ var CoMapProxyHandler = {
620
695
  if (typeof key !== "string") {
621
696
  return void 0;
622
697
  }
623
- const descriptor = target.getDescriptor(key);
698
+ const descriptor = target.$jazz.getDescriptor(key);
624
699
  if (!descriptor) {
625
700
  return void 0;
626
701
  }
627
- const raw = target._raw.get(key);
702
+ const raw = target.$jazz.raw.get(key);
628
703
  if (descriptor === "json") {
629
704
  return raw;
630
705
  } else if ("encoded" in descriptor) {
@@ -635,36 +710,15 @@ var CoMapProxyHandler = {
635
710
  }
636
711
  },
637
712
  set(target, key, value, receiver) {
638
- if ((typeof key === "string" || ItemsSym) && typeof value === "object" && value !== null && SchemaInit in value) {
713
+ if (typeof key === "string" && typeof value === "object" && value !== null && SchemaInit in value) {
639
714
  target.constructor._schema ||= {};
640
715
  target.constructor._schema[key] = value[SchemaInit];
641
716
  return true;
642
717
  }
643
- const descriptor = target.getDescriptor(key);
718
+ const descriptor = target.$jazz.getDescriptor(key);
644
719
  if (!descriptor) return false;
645
720
  if (typeof key === "string") {
646
- if (descriptor === "json") {
647
- target._raw.set(key, value);
648
- } else if ("encoded" in descriptor) {
649
- target._raw.set(key, descriptor.encoded.encode(value));
650
- } else if (isRefEncoded(descriptor)) {
651
- if (value === void 0) {
652
- if (descriptor.optional) {
653
- target._raw.set(key, null);
654
- } else {
655
- throw new Error(
656
- `Cannot set required reference ${key} to undefined`
657
- );
658
- }
659
- } else if (value?.id) {
660
- target._raw.set(key, value.id);
661
- } else {
662
- throw new Error(
663
- `Cannot set reference ${key} to a non-CoValue. Got ${value}`
664
- );
665
- }
666
- }
667
- return true;
721
+ throw Error("Cannot update a CoMap directly. Use `$jazz.set` instead.");
668
722
  } else {
669
723
  return Reflect.set(target, key, value, receiver);
670
724
  }
@@ -680,7 +734,7 @@ var CoMapProxyHandler = {
680
734
  },
681
735
  ownKeys(target) {
682
736
  const keys = Reflect.ownKeys(target).filter((k) => k !== ItemsSym);
683
- for (const key of target._raw.keys()) {
737
+ for (const key of target.$jazz.raw.keys()) {
684
738
  if (!keys.includes(key)) {
685
739
  keys.push(key);
686
740
  }
@@ -691,8 +745,8 @@ var CoMapProxyHandler = {
691
745
  if (key in target) {
692
746
  return Reflect.getOwnPropertyDescriptor(target, key);
693
747
  } else {
694
- const descriptor = target.getDescriptor(key);
695
- if (descriptor || key in target._raw.latest) {
748
+ const descriptor = target.$jazz.getDescriptor(key);
749
+ if (descriptor || key in target.$jazz.raw.latest) {
696
750
  return {
697
751
  enumerable: true,
698
752
  configurable: true,
@@ -702,27 +756,47 @@ var CoMapProxyHandler = {
702
756
  }
703
757
  },
704
758
  has(target, key) {
705
- const descriptor = target.getDescriptor(key);
706
- if (target._raw && typeof key === "string" && descriptor) {
707
- return target._raw.get(key) !== void 0;
759
+ const descriptor = target.$jazz?.getDescriptor(key);
760
+ if (target.$jazz?.raw && typeof key === "string" && descriptor) {
761
+ return target.$jazz.raw.get(key) !== void 0;
708
762
  } else {
709
763
  return Reflect.has(target, key);
710
764
  }
711
765
  },
712
766
  deleteProperty(target, key) {
713
- const descriptor = target.getDescriptor(key);
767
+ const descriptor = target.$jazz.getDescriptor(key);
714
768
  if (typeof key === "string" && descriptor) {
715
- target._raw.delete(key);
716
- return true;
769
+ throw Error(
770
+ "Cannot delete a CoMap property directly. Use `$jazz.delete` instead."
771
+ );
717
772
  } else {
718
773
  return Reflect.deleteProperty(target, key);
719
774
  }
720
775
  }
721
776
  };
722
777
  RegisteredSchemas["CoMap"] = CoMap;
778
+ function getEditFromRaw(target, rawEdit, descriptor, key) {
779
+ return {
780
+ value: descriptor === "json" ? rawEdit.value : "encoded" in descriptor ? rawEdit.value === null || rawEdit.value === void 0 ? rawEdit.value : descriptor.encoded.decode(rawEdit.value) : accessChildById(target, rawEdit.value, descriptor),
781
+ ref: descriptor !== "json" && isRefEncoded(descriptor) ? new Ref(
782
+ rawEdit.value,
783
+ target.$jazz.loadedAs,
784
+ descriptor,
785
+ target
786
+ ) : void 0,
787
+ get by() {
788
+ return rawEdit.by && accessChildById(target, rawEdit.by, {
789
+ ref: Account,
790
+ optional: false
791
+ });
792
+ },
793
+ madeAt: rawEdit.at,
794
+ key
795
+ };
796
+ }
723
797
 
724
798
  // src/tools/coValues/coList.ts
725
- import { ControlledAccount as ControlledAccount2, RawAccount as RawAccount2, cojsonInternals as cojsonInternals2 } from "cojson";
799
+ import { cojsonInternals as cojsonInternals2 } from "cojson";
726
800
  import { calcPatch } from "fast-myers-diff";
727
801
  var _CoList = class _CoList extends Array {
728
802
  /**
@@ -741,11 +815,11 @@ var _CoList = class _CoList extends Array {
741
815
  * @category Declaration
742
816
  */
743
817
  static Of(item) {
744
- var _a, _b;
745
- return class CoListOf extends (_b = _CoList, _a = coField.items, _b) {
818
+ var _a2, _b;
819
+ return class CoListOf extends (_b = _CoList, _a2 = coField.items, _b) {
746
820
  constructor() {
747
821
  super(...arguments);
748
- this[_a] = item;
822
+ this[_a2] = item;
749
823
  }
750
824
  };
751
825
  }
@@ -755,79 +829,21 @@ var _CoList = class _CoList extends Array {
755
829
  static of(..._args) {
756
830
  throw new Error("Can't use Array.of with CoLists");
757
831
  }
758
- /** @internal */
759
- get _schema() {
760
- return this.constructor._schema;
761
- }
762
- /** @category Collaboration */
763
- get _owner() {
764
- return this._raw.group instanceof RawAccount2 ? coValueClassFromCoValueClassOrSchema(
765
- RegisteredSchemas["Account"]
766
- ).fromRaw(this._raw.group) : RegisteredSchemas["Group"].fromRaw(this._raw.group);
767
- }
768
- /**
769
- * If a `CoList`'s items are a `coField.ref(...)`, you can use `coList._refs[i]` to access
770
- * the `Ref` instead of the potentially loaded/null value.
771
- *
772
- * This allows you to always get the ID or load the value manually.
773
- *
774
- * @example
775
- * ```ts
776
- * animals._refs[0].id; // => ID<Animal>
777
- * animals._refs[0].value;
778
- * // => Animal | null
779
- * const animal = await animals._refs[0].load();
780
- * ```
781
- *
782
- * @category Content
783
- **/
784
- get _refs() {
785
- return makeRefs(
786
- this,
787
- (idx) => this._raw.get(idx),
788
- () => Array.from({ length: this._raw.entries().length }, (_, idx) => idx),
789
- this._loadedAs,
790
- (_idx) => this._schema[ItemsSym]
791
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
792
- );
793
- }
794
- get _edits() {
795
- throw new Error("Not implemented");
796
- }
797
- get _loadedAs() {
798
- const agent = this._raw.core.node.getCurrentAgent();
799
- if (agent instanceof ControlledAccount2) {
800
- return coValuesCache.get(
801
- agent.account,
802
- () => coValueClassFromCoValueClassOrSchema(
803
- RegisteredSchemas["Account"]
804
- ).fromRaw(agent.account)
805
- );
806
- }
807
- return new AnonymousJazzAgent(this._raw.core.node);
808
- }
809
832
  static get [(ItemsSym, Symbol.species)]() {
810
833
  return Array;
811
834
  }
812
- getItemsDescriptor() {
813
- return this._schema?.[ItemsSym];
814
- }
815
835
  constructor(options) {
816
836
  super();
817
- Object.defineProperty(this, "_instanceID", {
818
- value: `instance-${Math.random().toString(36).slice(2)}`,
819
- enumerable: false
820
- });
837
+ const proxy = new Proxy(this, CoListProxyHandler);
821
838
  if (options && "fromRaw" in options) {
822
839
  Object.defineProperties(this, {
823
- id: {
824
- value: options.fromRaw.id,
840
+ $jazz: {
841
+ value: new CoListJazzApi(proxy, () => options.fromRaw),
825
842
  enumerable: false
826
- },
827
- _raw: { value: options.fromRaw, enumerable: false }
843
+ }
828
844
  });
829
845
  }
830
- return new Proxy(this, CoListProxyHandler);
846
+ return proxy;
831
847
  }
832
848
  /**
833
849
  * Create a new CoList with the given initial values and owner.
@@ -849,126 +865,37 @@ var _CoList = class _CoList extends Array {
849
865
  * ```
850
866
  *
851
867
  * @category Creation
868
+ * @deprecated Use `co.list(...).create` instead.
852
869
  **/
853
870
  static create(items, options) {
854
871
  const { owner, uniqueness } = parseCoValueCreateOptions(options);
855
- const instance = new this({ init: items, owner });
856
- const raw = owner._raw.createList(
857
- toRawItems(items, instance._schema[ItemsSym], owner),
872
+ const instance = new this();
873
+ Object.defineProperties(instance, {
874
+ $jazz: {
875
+ value: new CoListJazzApi(instance, () => raw),
876
+ enumerable: false
877
+ }
878
+ });
879
+ const raw = owner.$jazz.raw.createList(
880
+ toRawItems(items, instance.$jazz.schema[ItemsSym], owner),
858
881
  null,
859
882
  "private",
860
883
  uniqueness
861
884
  );
862
- Object.defineProperties(instance, {
863
- id: {
864
- value: raw.id,
865
- enumerable: false
866
- },
867
- _raw: { value: raw, enumerable: false }
868
- });
869
885
  return instance;
870
886
  }
871
- push(...items) {
872
- this._raw.appendItems(
873
- toRawItems(items, this._schema[ItemsSym], this._owner),
874
- void 0,
875
- "private"
876
- );
877
- return this._raw.entries().length;
878
- }
879
- unshift(...items) {
880
- for (const item of toRawItems(
881
- items,
882
- this._schema[ItemsSym],
883
- this._owner
884
- )) {
885
- this._raw.prepend(item);
886
- }
887
- return this._raw.entries().length;
888
- }
889
- pop() {
890
- const last = this[this.length - 1];
891
- this._raw.delete(this.length - 1);
892
- return last;
893
- }
894
- shift() {
895
- const first = this[0];
896
- this._raw.delete(0);
897
- return first;
898
- }
899
- /**
900
- * Splice the `CoList` at a given index.
901
- *
902
- * @param start - The index to start the splice.
903
- * @param deleteCount - The number of items to delete.
904
- * @param items - The items to insert.
905
- */
906
- splice(start, deleteCount, ...items) {
907
- const deleted = this.slice(start, start + deleteCount);
908
- for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
909
- this._raw.delete(idxToDelete);
910
- }
911
- const rawItems = toRawItems(
912
- items,
913
- this._schema[ItemsSym],
914
- this._owner
915
- );
916
- if (rawItems.length === 0) {
917
- return deleted;
918
- }
919
- if (rawItems.length === 1) {
920
- const item = rawItems[0];
921
- if (item === void 0) return deleted;
922
- if (start === 0) {
923
- this._raw.prepend(item);
924
- } else {
925
- this._raw.append(item, Math.max(start - 1, 0));
926
- }
927
- return deleted;
928
- }
929
- if (start === 0) {
930
- for (let i = rawItems.length - 1; i >= 0; i--) {
931
- const item = rawItems[i];
932
- if (item === void 0) continue;
933
- this._raw.prepend(item);
934
- }
935
- } else {
936
- let appendAfter = Math.max(start - 1, 0);
937
- for (const item of rawItems) {
938
- if (item === void 0) continue;
939
- this._raw.append(item, appendAfter);
940
- appendAfter++;
941
- }
942
- }
943
- return deleted;
944
- }
945
- /**
946
- * Modify the `CoList` to match another list, where the changes are managed internally.
947
- *
948
- * @param result - The resolved list of items.
949
- */
950
- applyDiff(result) {
951
- const current = this._raw.asArray();
952
- const comparator = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => {
953
- return current[aIdx]?.id === result[bIdx]?.id;
954
- } : void 0;
955
- const patches = [...calcPatch(current, result, comparator)];
956
- for (const [from, to, insert] of patches.reverse()) {
957
- this.splice(from, to - from, ...insert);
958
- }
959
- }
960
887
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
961
888
  toJSON(_key, seenAbove) {
962
- const itemDescriptor = this._schema[ItemsSym];
889
+ const itemDescriptor = this.$jazz.schema[ItemsSym];
963
890
  if (itemDescriptor === "json") {
964
- return this._raw.asArray();
891
+ return this.$jazz.raw.asArray();
965
892
  } else if ("encoded" in itemDescriptor) {
966
- return this._raw.asArray().map((e) => itemDescriptor.encoded.encode(e));
893
+ return this.$jazz.raw.asArray().map((e) => itemDescriptor.encoded.encode(e));
967
894
  } else if (isRefEncoded(itemDescriptor)) {
968
895
  return this.map(
969
- (item, idx) => seenAbove?.includes(item?.id) ? { _circular: item.id } : item?.toJSON(idx + "", [
896
+ (item, idx) => seenAbove?.includes(item?.$jazz.id) ? { _circular: item.$jazz.id } : item?.toJSON(idx + "", [
970
897
  ...seenAbove || [],
971
- this.id
898
+ this.$jazz.id
972
899
  ])
973
900
  );
974
901
  } else {
@@ -1008,6 +935,7 @@ var _CoList = class _CoList extends Array {
1008
935
  * ```
1009
936
  *
1010
937
  * @category Subscription & Loading
938
+ * @deprecated Use `co.list(...).load` instead.
1011
939
  */
1012
940
  static load(id, options) {
1013
941
  return loadCoValueWithoutMe(this, id, options);
@@ -1016,24 +944,6 @@ var _CoList = class _CoList extends Array {
1016
944
  const { options, listener } = parseSubscribeRestArgs(args);
1017
945
  return subscribeToCoValueWithoutMe(this, id, options, listener);
1018
946
  }
1019
- /**
1020
- * Given an already loaded `CoList`, ensure that items are loaded to the specified depth.
1021
- *
1022
- * Works like `CoList.load()`, but you don't need to pass the ID or the account to load as again.
1023
- *
1024
- * @category Subscription & Loading
1025
- */
1026
- ensureLoaded(options) {
1027
- return ensureCoValueLoaded(this, options);
1028
- }
1029
- subscribe(...args) {
1030
- const { options, listener } = parseSubscribeRestArgs(args);
1031
- return subscribeToExistingCoValue(this, options, listener);
1032
- }
1033
- /** @category Type Helpers */
1034
- castAs(cl) {
1035
- return cl.fromRaw(this._raw);
1036
- }
1037
947
  /** @deprecated Use `CoList.upsertUnique` and `CoList.loadUnique` instead. */
1038
948
  static findUnique(unique, ownerID, as) {
1039
949
  return _CoList._findUnique(unique, ownerID, as);
@@ -1050,7 +960,7 @@ var _CoList = class _CoList extends Array {
1050
960
  meta: null,
1051
961
  uniqueness: unique
1052
962
  };
1053
- const crypto = as._type === "Anonymous" ? as.node.crypto : as._raw.core.node.crypto;
963
+ const crypto = as[TypeSym] === "Anonymous" ? as.node.crypto : as.$jazz.localNode.crypto;
1054
964
  return cojsonInternals2.idforHeader(header, crypto);
1055
965
  }
1056
966
  /**
@@ -1069,60 +979,377 @@ var _CoList = class _CoList extends Array {
1069
979
  * );
1070
980
  * ```
1071
981
  *
1072
- * @param options The options for creating or loading the CoList. This includes the intended state of the CoList, its unique identifier, its owner, and the references to resolve.
1073
- * @returns Either an existing & modified CoList, or a new initialised CoList if none exists.
982
+ * @param options The options for creating or loading the CoList. This includes the intended state of the CoList, its unique identifier, its owner, and the references to resolve.
983
+ * @returns Either an existing & modified CoList, or a new initialised CoList if none exists.
984
+ * @category Subscription & Loading
985
+ */
986
+ static async upsertUnique(options) {
987
+ const listId = _CoList._findUnique(
988
+ options.unique,
989
+ options.owner.$jazz.id,
990
+ options.owner.$jazz.loadedAs
991
+ );
992
+ let list = await loadCoValueWithoutMe(this, listId, {
993
+ ...options,
994
+ loadAs: options.owner.$jazz.loadedAs,
995
+ skipRetry: true
996
+ });
997
+ if (!list) {
998
+ list = this.create(options.value, {
999
+ owner: options.owner,
1000
+ unique: options.unique
1001
+ });
1002
+ } else {
1003
+ list.$jazz.applyDiff(options.value);
1004
+ }
1005
+ return await loadCoValueWithoutMe(this, listId, {
1006
+ ...options,
1007
+ loadAs: options.owner.$jazz.loadedAs,
1008
+ skipRetry: true
1009
+ });
1010
+ }
1011
+ /**
1012
+ * Loads a CoList by its unique identifier and owner's ID.
1013
+ * @param unique The unique identifier of the CoList to load.
1014
+ * @param ownerID The ID of the owner of the CoList.
1015
+ * @param options Additional options for loading the CoList.
1016
+ * @returns The loaded CoList, or null if unavailable.
1017
+ */
1018
+ static loadUnique(unique, ownerID, options) {
1019
+ return loadCoValueWithoutMe(
1020
+ this,
1021
+ _CoList._findUnique(unique, ownerID, options?.loadAs),
1022
+ { ...options, skipRetry: true }
1023
+ );
1024
+ }
1025
+ // Override mutation methods defined on Array, as CoLists aren't meant to be mutated directly
1026
+ /**
1027
+ * @deprecated Use `.$jazz.push` instead.
1028
+ */
1029
+ push(...items) {
1030
+ throw new Error(
1031
+ "Cannot mutate a CoList directly. Use `.$jazz.push` instead."
1032
+ );
1033
+ }
1034
+ /**
1035
+ * @deprecated Use `.$jazz.unshift` instead.
1036
+ */
1037
+ unshift(...items) {
1038
+ throw new Error(
1039
+ "Cannot mutate a CoList directly. Use `.$jazz.unshift` instead."
1040
+ );
1041
+ }
1042
+ /**
1043
+ * @deprecated Use `.$jazz.pop` instead.
1044
+ */
1045
+ // @ts-expect-error
1046
+ pop(value) {
1047
+ throw new Error(
1048
+ "Cannot mutate a CoList directly. Use `.$jazz.pop` instead."
1049
+ );
1050
+ }
1051
+ /**
1052
+ * @deprecated Use `.$jazz.shift` instead.
1053
+ */
1054
+ // @ts-expect-error
1055
+ shift(value) {
1056
+ throw new Error(
1057
+ "Cannot mutate a CoList directly. Use `.$jazz.shift` instead."
1058
+ );
1059
+ }
1060
+ /**
1061
+ * @deprecated Use `.$jazz.splice` instead.
1062
+ */
1063
+ splice(start, deleteCount, ...items) {
1064
+ throw new Error(
1065
+ "Cannot mutate a CoList directly. Use `.$jazz.splice` instead."
1066
+ );
1067
+ }
1068
+ /**
1069
+ * @deprecated Use `.$jazz.set` instead.
1070
+ */
1071
+ copyWithin(target, start, end) {
1072
+ throw new Error(
1073
+ "Cannot mutate a CoList directly. Use `.$jazz.set` instead."
1074
+ );
1075
+ }
1076
+ /**
1077
+ * @deprecated Use `.$jazz.set` instead.
1078
+ */
1079
+ fill(value, start, end) {
1080
+ throw new Error(
1081
+ "Cannot mutate a CoList directly. Use `.$jazz.set` instead."
1082
+ );
1083
+ }
1084
+ /**
1085
+ * @deprecated Use `.toReversed` if you want a reversed copy, or `.$jazz.set` to mutate the CoList.
1086
+ */
1087
+ // @ts-expect-error
1088
+ reverse(value) {
1089
+ throw new Error(
1090
+ "Cannot mutate a CoList directly. Use `.toReversed` if you want a reversed copy, or `.$jazz.set` to mutate the CoList."
1091
+ );
1092
+ }
1093
+ /**
1094
+ * @deprecated Use `.toSorted()` if you want a sorted copy, or `.$jazz.set` to mutate the CoList.
1095
+ */
1096
+ sort(compareFn) {
1097
+ throw new Error(
1098
+ "Cannot mutate a CoList directly. Use `.toSorted` if you want a sorted copy, or `.$jazz.set` to mutate the CoList."
1099
+ );
1100
+ }
1101
+ };
1102
+ _CoList.prototype[TypeSym] = "CoList";
1103
+ var CoList = _CoList;
1104
+ var CoListJazzApi = class extends CoValueJazzApi {
1105
+ constructor(coList, getRaw) {
1106
+ super(coList);
1107
+ this.coList = coList;
1108
+ this.getRaw = getRaw;
1109
+ }
1110
+ /**
1111
+ * The ID of this `CoList`
1112
+ * @category Content
1113
+ */
1114
+ get id() {
1115
+ return this.raw.id;
1116
+ }
1117
+ /** @category Collaboration */
1118
+ get owner() {
1119
+ return getCoValueOwner(this.coList);
1120
+ }
1121
+ set(index, value) {
1122
+ const itemDescriptor = this.schema[ItemsSym];
1123
+ const rawValue = toRawItems([value], itemDescriptor, this.owner)[0];
1124
+ if (rawValue === null && !itemDescriptor.optional) {
1125
+ throw new Error(`Cannot set required reference ${index} to undefined`);
1126
+ }
1127
+ this.raw.replace(index, rawValue);
1128
+ }
1129
+ /**
1130
+ * Appends new elements to the end of an array, and returns the new length of the array.
1131
+ * @param items New elements to add to the array.
1132
+ *
1133
+ * @category Content
1134
+ */
1135
+ push(...items) {
1136
+ this.raw.appendItems(
1137
+ toRawItems(items, this.schema[ItemsSym], this.owner),
1138
+ void 0,
1139
+ "private"
1140
+ );
1141
+ return this.raw.entries().length;
1142
+ }
1143
+ /**
1144
+ * Inserts new elements at the start of an array, and returns the new length of the array.
1145
+ * @param items Elements to insert at the start of the array.
1146
+ *
1147
+ * @category Content
1148
+ */
1149
+ unshift(...items) {
1150
+ for (const item of toRawItems(
1151
+ items,
1152
+ this.schema[ItemsSym],
1153
+ this.owner
1154
+ )) {
1155
+ this.raw.prepend(item);
1156
+ }
1157
+ return this.raw.entries().length;
1158
+ }
1159
+ /**
1160
+ * Removes the last element from an array and returns it.
1161
+ * If the array is empty, undefined is returned and the array is not modified.
1162
+ *
1163
+ * @category Content
1164
+ */
1165
+ pop() {
1166
+ const last = this.coList[this.coList.length - 1];
1167
+ this.raw.delete(this.coList.length - 1);
1168
+ return last;
1169
+ }
1170
+ /**
1171
+ * Removes the first element from an array and returns it.
1172
+ * If the array is empty, undefined is returned and the array is not modified.
1173
+ *
1174
+ * @category Content
1175
+ */
1176
+ shift() {
1177
+ const first = this.coList[0];
1178
+ this.raw.delete(0);
1179
+ return first;
1180
+ }
1181
+ /**
1182
+ * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
1183
+ * @param start The zero-based location in the array from which to start removing elements.
1184
+ * @param deleteCount The number of elements to remove.
1185
+ * @param items Elements to insert into the array in place of the deleted elements.
1186
+ * @returns An array containing the elements that were deleted.
1187
+ *
1188
+ * @category Content
1189
+ */
1190
+ splice(start, deleteCount, ...items) {
1191
+ const deleted = this.coList.slice(start, start + deleteCount);
1192
+ for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
1193
+ this.raw.delete(idxToDelete);
1194
+ }
1195
+ const rawItems = toRawItems(
1196
+ items,
1197
+ this.schema[ItemsSym],
1198
+ this.owner
1199
+ );
1200
+ if (rawItems.length === 0) {
1201
+ return deleted;
1202
+ }
1203
+ if (rawItems.length === 1) {
1204
+ const item = rawItems[0];
1205
+ if (item === void 0) return deleted;
1206
+ if (start === 0) {
1207
+ this.raw.prepend(item);
1208
+ } else {
1209
+ this.raw.append(item, Math.max(start - 1, 0));
1210
+ }
1211
+ return deleted;
1212
+ }
1213
+ if (start === 0) {
1214
+ for (let i = rawItems.length - 1; i >= 0; i--) {
1215
+ const item = rawItems[i];
1216
+ if (item === void 0) continue;
1217
+ this.raw.prepend(item);
1218
+ }
1219
+ } else {
1220
+ let appendAfter = Math.max(start - 1, 0);
1221
+ for (const item of rawItems) {
1222
+ if (item === void 0) continue;
1223
+ this.raw.append(item, appendAfter);
1224
+ appendAfter++;
1225
+ }
1226
+ }
1227
+ return deleted;
1228
+ }
1229
+ remove(...args) {
1230
+ const predicate = args[0] instanceof Function ? args[0] : void 0;
1231
+ let indices = [];
1232
+ if (predicate) {
1233
+ for (let i = 0; i < this.coList.length; i++) {
1234
+ if (predicate(this.coList[i], i, this.coList)) {
1235
+ indices.push(i);
1236
+ }
1237
+ }
1238
+ } else {
1239
+ indices = args.filter((index) => index >= 0 && index < this.coList.length).sort((a, b) => a - b);
1240
+ }
1241
+ const deletedItems = indices.map((index) => this.coList[index]);
1242
+ for (const index of indices.reverse()) {
1243
+ this.raw.delete(index);
1244
+ }
1245
+ return deletedItems;
1246
+ }
1247
+ /**
1248
+ * Retains only the elements matching the predicate from the array.
1249
+ * @param predicate The predicate to match the elements to retain.
1250
+ * @returns The removed elements.
1251
+ *
1252
+ * @category Content
1253
+ */
1254
+ retain(predicate) {
1255
+ return this.remove((...args) => !predicate(...args));
1256
+ }
1257
+ /**
1258
+ * Modify the `CoList` to match another list, where the changes are managed internally.
1259
+ *
1260
+ * Changes are detected using `Object.is` for non-collaborative values and `$jazz.id` for collaborative values.
1261
+ *
1262
+ * @param result - The resolved list of items. For collaborative values, both CoValues and JSON values are supported.
1263
+ * @returns The modified CoList.
1264
+ *
1265
+ * @category Content
1266
+ */
1267
+ applyDiff(result) {
1268
+ const current = this.raw.asArray();
1269
+ const comparator = isRefEncoded(this.schema[ItemsSym]) ? (aIdx, bIdx) => {
1270
+ const oldCoValueId = current[aIdx]?.$jazz?.id;
1271
+ const newCoValueId = result[bIdx]?.$jazz?.id;
1272
+ const isSame = !!oldCoValueId && !!newCoValueId && oldCoValueId === newCoValueId;
1273
+ return isSame;
1274
+ } : void 0;
1275
+ const patches = [...calcPatch(current, result, comparator)];
1276
+ for (const [from, to, insert] of patches.reverse()) {
1277
+ this.splice(from, to - from, ...insert);
1278
+ }
1279
+ return this.coList;
1280
+ }
1281
+ /**
1282
+ * Given an already loaded `CoList`, ensure that items are loaded to the specified depth.
1283
+ *
1284
+ * Works like `CoList.load()`, but you don't need to pass the ID or the account to load as again.
1285
+ *
1286
+ * @category Subscription & Loading
1287
+ */
1288
+ ensureLoaded(options) {
1289
+ return ensureCoValueLoaded(this.coList, options);
1290
+ }
1291
+ subscribe(...args) {
1292
+ const { options, listener } = parseSubscribeRestArgs(args);
1293
+ return subscribeToExistingCoValue(this.coList, options, listener);
1294
+ }
1295
+ /**
1296
+ * Wait for the `CoList` to be uploaded to the other peers.
1297
+ *
1074
1298
  * @category Subscription & Loading
1075
1299
  */
1076
- static async upsertUnique(options) {
1077
- const listId = _CoList._findUnique(
1078
- options.unique,
1079
- options.owner.id,
1080
- options.owner._loadedAs
1081
- );
1082
- let list = await loadCoValueWithoutMe(this, listId, {
1083
- ...options,
1084
- loadAs: options.owner._loadedAs,
1085
- skipRetry: true
1086
- });
1087
- if (!list) {
1088
- list = this.create(options.value, {
1089
- owner: options.owner,
1090
- unique: options.unique
1091
- });
1092
- } else {
1093
- list.applyDiff(options.value);
1094
- }
1095
- return await loadCoValueWithoutMe(this, listId, {
1096
- ...options,
1097
- loadAs: options.owner._loadedAs,
1098
- skipRetry: true
1099
- });
1300
+ async waitForSync(options) {
1301
+ await this.raw.core.waitForSync(options);
1100
1302
  }
1101
1303
  /**
1102
- * Loads a CoList by its unique identifier and owner's ID.
1103
- * @param unique The unique identifier of the CoList to load.
1104
- * @param ownerID The ID of the owner of the CoList.
1105
- * @param options Additional options for loading the CoList.
1106
- * @returns The loaded CoList, or null if unavailable.
1304
+ * Get the descriptor for the items in the `CoList`
1305
+ * @internal
1107
1306
  */
1108
- static loadUnique(unique, ownerID, options) {
1109
- return loadCoValueWithoutMe(
1110
- this,
1111
- _CoList._findUnique(unique, ownerID, options?.loadAs),
1112
- { ...options, skipRetry: true }
1307
+ getItemsDescriptor() {
1308
+ return this.schema[ItemsSym];
1309
+ }
1310
+ /**
1311
+ * If a `CoList`'s items are a `coField.ref(...)`, you can use `coList.$jazz.refs[i]` to access
1312
+ * the `Ref` instead of the potentially loaded/null value.
1313
+ *
1314
+ * This allows you to always get the ID or load the value manually.
1315
+ *
1316
+ * @example
1317
+ * ```ts
1318
+ * animals.$jazz.refs[0].id; // => ID<Animal>
1319
+ * animals.$jazz.refs[0].value;
1320
+ * // => Animal | null
1321
+ * const animal = await animals.$jazz.refs[0].load();
1322
+ * ```
1323
+ *
1324
+ * @category Content
1325
+ **/
1326
+ get refs() {
1327
+ return makeRefs(
1328
+ this.coList,
1329
+ (idx) => this.raw.get(idx),
1330
+ () => Array.from({ length: this.raw.entries().length }, (_, idx) => idx),
1331
+ this.loadedAs,
1332
+ (_idx) => this.schema[ItemsSym]
1333
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1113
1334
  );
1114
1335
  }
1115
1336
  /**
1116
- * Wait for the `CoList` to be uploaded to the other peers.
1337
+ * Get the edits made to the CoList.
1117
1338
  *
1118
- * @category Subscription & Loading
1339
+ * @category Collaboration
1119
1340
  */
1120
- waitForSync(options) {
1121
- return this._raw.core.waitForSync(options);
1341
+ getEdits() {
1342
+ throw new Error("Not implemented");
1343
+ }
1344
+ /** @internal */
1345
+ get raw() {
1346
+ return this.getRaw();
1347
+ }
1348
+ /** @internal */
1349
+ get schema() {
1350
+ return this.coList.constructor._schema;
1122
1351
  }
1123
1352
  };
1124
- _CoList.prototype._type = "CoList";
1125
- var CoList = _CoList;
1126
1353
  function toRawItems(items, itemDescriptor, owner) {
1127
1354
  let rawItems = [];
1128
1355
  if (itemDescriptor === "json") {
@@ -1131,15 +1358,17 @@ function toRawItems(items, itemDescriptor, owner) {
1131
1358
  rawItems = items?.map((e) => itemDescriptor.encoded.encode(e));
1132
1359
  } else if (isRefEncoded(itemDescriptor)) {
1133
1360
  rawItems = items?.map((value) => {
1134
- if (value == null) return null;
1135
- let refId = value.id;
1361
+ if (value == null) {
1362
+ return null;
1363
+ }
1364
+ let refId = value.$jazz?.id;
1136
1365
  if (!refId) {
1137
1366
  const coValue = instantiateRefEncodedWithInit(
1138
1367
  itemDescriptor,
1139
1368
  value,
1140
1369
  owner
1141
1370
  );
1142
- refId = coValue.id;
1371
+ refId = coValue.$jazz.id;
1143
1372
  }
1144
1373
  return refId;
1145
1374
  });
@@ -1151,8 +1380,8 @@ function toRawItems(items, itemDescriptor, owner) {
1151
1380
  var CoListProxyHandler = {
1152
1381
  get(target, key, receiver) {
1153
1382
  if (typeof key === "string" && !isNaN(+key)) {
1154
- const itemDescriptor = target._schema[ItemsSym];
1155
- const rawValue = target._raw.get(Number(key));
1383
+ const itemDescriptor = target.$jazz.schema[ItemsSym];
1384
+ const rawValue = target.$jazz.raw.get(Number(key));
1156
1385
  if (itemDescriptor === "json") {
1157
1386
  return rawValue;
1158
1387
  } else if ("encoded" in itemDescriptor) {
@@ -1161,7 +1390,7 @@ var CoListProxyHandler = {
1161
1390
  return rawValue === void 0 || rawValue === null ? void 0 : accessChildByKey(target, rawValue, key);
1162
1391
  }
1163
1392
  } else if (key === "length") {
1164
- return target._raw.entries().length;
1393
+ return target.$jazz.raw.entries().length;
1165
1394
  } else {
1166
1395
  return Reflect.get(target, key, receiver);
1167
1396
  }
@@ -1173,31 +1402,7 @@ var CoListProxyHandler = {
1173
1402
  return true;
1174
1403
  }
1175
1404
  if (typeof key === "string" && !isNaN(+key)) {
1176
- const itemDescriptor = target._schema[ItemsSym];
1177
- let rawValue;
1178
- if (itemDescriptor === "json") {
1179
- rawValue = value;
1180
- } else if ("encoded" in itemDescriptor) {
1181
- rawValue = itemDescriptor.encoded.encode(value);
1182
- } else if (isRefEncoded(itemDescriptor)) {
1183
- if (value === void 0) {
1184
- if (itemDescriptor.optional) {
1185
- rawValue = null;
1186
- } else {
1187
- throw new Error(
1188
- `Cannot set required reference ${key} to undefined`
1189
- );
1190
- }
1191
- } else if (value?.id) {
1192
- rawValue = value.id;
1193
- } else {
1194
- throw new Error(
1195
- `Cannot set reference ${key} to a non-CoValue. Got ${value}`
1196
- );
1197
- }
1198
- }
1199
- target._raw.replace(Number(key), rawValue);
1200
- return true;
1405
+ throw Error("Cannot update a CoList directly. Use `$jazz.set` instead.");
1201
1406
  } else {
1202
1407
  return Reflect.set(target, key, value, receiver);
1203
1408
  }
@@ -1213,7 +1418,7 @@ var CoListProxyHandler = {
1213
1418
  },
1214
1419
  has(target, key) {
1215
1420
  if (typeof key === "string" && !isNaN(+key)) {
1216
- return Number(key) < target._raw.entries().length;
1421
+ return Number(key) < target.$jazz.raw.entries().length;
1217
1422
  } else {
1218
1423
  return Reflect.has(target, key);
1219
1424
  }
@@ -1235,28 +1440,24 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1235
1440
  * @category Declaration
1236
1441
  */
1237
1442
  static Of(item) {
1238
- var _a, _b;
1239
- const cls = class CoFeedOf extends (_b = _CoFeed, _a = coField.items, _b) {
1443
+ var _a2, _b;
1444
+ const cls = class CoFeedOf extends (_b = _CoFeed, _a2 = coField.items, _b) {
1240
1445
  constructor() {
1241
1446
  super(...arguments);
1242
- this[_a] = item;
1447
+ this[_a2] = item;
1243
1448
  }
1244
1449
  };
1245
1450
  cls._schema ||= {};
1246
1451
  cls._schema[ItemsSym] = item[SchemaInit];
1247
1452
  return cls;
1248
1453
  }
1249
- /** @internal */
1250
- get _schema() {
1251
- return this.constructor._schema;
1252
- }
1253
1454
  /**
1254
1455
  * The current account's view of this `CoFeed`
1255
1456
  * @category Content
1256
1457
  */
1257
1458
  get byMe() {
1258
- if (this._loadedAs._type === "Account") {
1259
- return this.perAccount[this._loadedAs.id];
1459
+ if (this.$jazz.loadedAs[TypeSym] === "Account") {
1460
+ return this.perAccount[this.$jazz.loadedAs.$jazz.id];
1260
1461
  } else {
1261
1462
  return void 0;
1262
1463
  }
@@ -1304,102 +1505,45 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1304
1505
  * @category Content
1305
1506
  */
1306
1507
  get inCurrentSession() {
1307
- if (this._loadedAs._type === "Account") {
1308
- return this.perSession[this._loadedAs.sessionID];
1508
+ if (this.$jazz.loadedAs[TypeSym] === "Account") {
1509
+ return this.perSession[this.$jazz.loadedAs.$jazz.sessionID];
1309
1510
  } else {
1310
1511
  return void 0;
1311
1512
  }
1312
1513
  }
1514
+ /** @internal */
1313
1515
  constructor(options) {
1314
1516
  super();
1315
- if (options && "fromRaw" in options) {
1316
- Object.defineProperties(this, {
1317
- id: {
1318
- value: options.fromRaw.id,
1319
- enumerable: false
1320
- },
1321
- _raw: { value: options.fromRaw, enumerable: false }
1322
- });
1323
- }
1517
+ Object.defineProperties(this, {
1518
+ $jazz: {
1519
+ value: new CoFeedJazzApi(this, options.fromRaw),
1520
+ enumerable: false
1521
+ }
1522
+ });
1324
1523
  return this;
1325
1524
  }
1326
1525
  /**
1327
1526
  * Create a new `CoFeed`
1328
1527
  * @category Creation
1528
+ * @deprecated Use `co.feed(...).create` instead.
1329
1529
  */
1330
1530
  static create(init, options) {
1331
1531
  const { owner } = parseCoValueCreateOptions(options);
1332
- const instance = new this({ init, owner });
1333
- const raw = owner._raw.createStream();
1334
- Object.defineProperties(instance, {
1335
- id: {
1336
- value: raw.id,
1337
- enumerable: false
1338
- },
1339
- _raw: { value: raw, enumerable: false }
1340
- });
1532
+ const raw = owner.$jazz.raw.createStream();
1533
+ const instance = new this({ fromRaw: raw });
1341
1534
  if (init) {
1342
- instance.push(...init);
1535
+ instance.$jazz.push(...init);
1343
1536
  }
1344
1537
  return instance;
1345
1538
  }
1346
- getItemsDescriptor() {
1347
- return this._schema?.[ItemsSym];
1348
- }
1349
- /**
1350
- * Push items to this `CoFeed`
1351
- *
1352
- * Items are appended to the current session's log. Each session (tab, device, app instance)
1353
- * maintains its own append-only log, which is then aggregated into the per-account view.
1354
- *
1355
- * @example
1356
- * ```ts
1357
- * // Adds items to current session's log
1358
- * feed.push("item1", "item2");
1359
- *
1360
- * // View items from current session
1361
- * console.log(feed.inCurrentSession);
1362
- *
1363
- * // View aggregated items from all sessions for current account
1364
- * console.log(feed.byMe);
1365
- * ```
1366
- *
1367
- * @category Content
1368
- */
1369
- push(...items) {
1370
- for (const item of items) {
1371
- this.pushItem(item);
1372
- }
1373
- }
1374
- pushItem(item) {
1375
- const itemDescriptor = this._schema[ItemsSym];
1376
- if (itemDescriptor === "json") {
1377
- this._raw.push(item);
1378
- } else if ("encoded" in itemDescriptor) {
1379
- this._raw.push(itemDescriptor.encoded.encode(item));
1380
- } else if (isRefEncoded(itemDescriptor)) {
1381
- let refId = item.id;
1382
- if (!refId) {
1383
- const coValue = instantiateRefEncodedWithInit(
1384
- itemDescriptor,
1385
- item,
1386
- this._owner
1387
- );
1388
- refId = coValue.id;
1389
- }
1390
- this._raw.push(refId);
1391
- }
1392
- }
1393
1539
  /**
1394
1540
  * Get a JSON representation of the `CoFeed`
1395
1541
  * @category
1396
1542
  */
1397
1543
  toJSON() {
1398
- const itemDescriptor = this._schema[ItemsSym];
1399
- const mapper = itemDescriptor === "json" ? (v) => v : "encoded" in itemDescriptor ? itemDescriptor.encoded.encode : (v) => v && v.id;
1544
+ const itemDescriptor = this.$jazz.schema[ItemsSym];
1545
+ const mapper = itemDescriptor === "json" ? (v) => v : "encoded" in itemDescriptor ? itemDescriptor.encoded.encode : (v) => v && v.$jazz.id;
1400
1546
  return {
1401
- id: this.id,
1402
- _type: this._type,
1403
1547
  ...Object.fromEntries(
1404
1548
  Object.entries(this).map(([account, entry]) => [
1405
1549
  account,
@@ -1426,6 +1570,7 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1426
1570
  /**
1427
1571
  * Load a `CoFeed`
1428
1572
  * @category Subscription & Loading
1573
+ * @deprecated Use `co.feed(...).load` instead.
1429
1574
  */
1430
1575
  static load(id, options) {
1431
1576
  return loadCoValueWithoutMe(this, id, options);
@@ -1434,6 +1579,69 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1434
1579
  const { options, listener } = parseSubscribeRestArgs(args);
1435
1580
  return subscribeToCoValueWithoutMe(this, id, options, listener);
1436
1581
  }
1582
+ };
1583
+ _CoFeed.prototype[TypeSym] = "CoStream";
1584
+ var CoFeed = _CoFeed;
1585
+ var CoFeedJazzApi = class extends CoValueJazzApi {
1586
+ constructor(coFeed, raw) {
1587
+ super(coFeed);
1588
+ this.coFeed = coFeed;
1589
+ this.raw = raw;
1590
+ }
1591
+ /**
1592
+ * The ID of this `CoFeed`
1593
+ * @category Content
1594
+ */
1595
+ get id() {
1596
+ return this.raw.id;
1597
+ }
1598
+ get owner() {
1599
+ return getCoValueOwner(this.coFeed);
1600
+ }
1601
+ /**
1602
+ * Push items to this `CoFeed`
1603
+ *
1604
+ * Items are appended to the current session's log. Each session (tab, device, app instance)
1605
+ * maintains its own append-only log, which is then aggregated into the per-account view.
1606
+ *
1607
+ * @example
1608
+ * ```ts
1609
+ * // Adds items to current session's log
1610
+ * feed.$jazz.push("item1", "item2");
1611
+ *
1612
+ * // View items from current session
1613
+ * console.log(feed.inCurrentSession);
1614
+ *
1615
+ * // View aggregated items from all sessions for current account
1616
+ * console.log(feed.byMe);
1617
+ * ```
1618
+ *
1619
+ * @category Content
1620
+ */
1621
+ push(...items) {
1622
+ for (const item of items) {
1623
+ this.pushItem(item);
1624
+ }
1625
+ }
1626
+ pushItem(item) {
1627
+ const itemDescriptor = this.schema[ItemsSym];
1628
+ if (itemDescriptor === "json") {
1629
+ this.raw.push(item);
1630
+ } else if ("encoded" in itemDescriptor) {
1631
+ this.raw.push(itemDescriptor.encoded.encode(item));
1632
+ } else if (isRefEncoded(itemDescriptor)) {
1633
+ let refId = item.$jazz?.id;
1634
+ if (!refId) {
1635
+ const coValue = instantiateRefEncodedWithInit(
1636
+ itemDescriptor,
1637
+ item,
1638
+ this.owner
1639
+ );
1640
+ refId = coValue.$jazz.id;
1641
+ }
1642
+ this.raw.push(refId);
1643
+ }
1644
+ }
1437
1645
  /**
1438
1646
  * Ensure a `CoFeed` is loaded to the specified depth
1439
1647
  *
@@ -1441,11 +1649,11 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1441
1649
  * @category Subscription & Loading
1442
1650
  */
1443
1651
  ensureLoaded(options) {
1444
- return ensureCoValueLoaded(this, options);
1652
+ return ensureCoValueLoaded(this.coFeed, options);
1445
1653
  }
1446
1654
  subscribe(...args) {
1447
1655
  const { options, listener } = parseSubscribeRestArgs(args);
1448
- return subscribeToExistingCoValue(this, options, listener);
1656
+ return subscribeToExistingCoValue(this.coFeed, options, listener);
1449
1657
  }
1450
1658
  /**
1451
1659
  * Wait for the `CoFeed` to be uploaded to the other peers.
@@ -1453,11 +1661,20 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1453
1661
  * @category Subscription & Loading
1454
1662
  */
1455
1663
  waitForSync(options) {
1456
- return this._raw.core.waitForSync(options);
1664
+ return this.raw.core.waitForSync(options);
1665
+ }
1666
+ /**
1667
+ * Get the descriptor for the items in the `CoFeed`
1668
+ * @internal
1669
+ */
1670
+ getItemsDescriptor() {
1671
+ return this.schema[ItemsSym];
1672
+ }
1673
+ /** @internal */
1674
+ get schema() {
1675
+ return this.coFeed.constructor._schema;
1457
1676
  }
1458
1677
  };
1459
- _CoFeed.prototype._type = "CoStream";
1460
- var CoFeed = _CoFeed;
1461
1678
  function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField) {
1462
1679
  return {
1463
1680
  get value() {
@@ -1501,18 +1718,20 @@ function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField)
1501
1718
  var CoStreamPerAccountProxyHandler = (innerTarget) => ({
1502
1719
  get(_target, key, receiver) {
1503
1720
  if (typeof key === "string" && key.startsWith("co_")) {
1504
- const rawEntry = innerTarget._raw.lastItemBy(key);
1721
+ const rawEntry = innerTarget.$jazz.raw.lastItemBy(key);
1505
1722
  if (!rawEntry) return;
1506
1723
  const entry = entryFromRawEntry(
1507
1724
  receiver,
1508
1725
  rawEntry,
1509
- innerTarget._loadedAs,
1726
+ innerTarget.$jazz.loadedAs,
1510
1727
  key,
1511
- innerTarget._schema[ItemsSym]
1728
+ innerTarget.$jazz.schema[ItemsSym]
1512
1729
  );
1513
1730
  Object.defineProperty(entry, "all", {
1514
1731
  get: () => {
1515
- const allRawEntries = innerTarget._raw.itemsBy(key);
1732
+ const allRawEntries = innerTarget.$jazz.raw.itemsBy(
1733
+ key
1734
+ );
1516
1735
  return function* () {
1517
1736
  while (true) {
1518
1737
  const rawEntry2 = allRawEntries.next();
@@ -1520,9 +1739,9 @@ var CoStreamPerAccountProxyHandler = (innerTarget) => ({
1520
1739
  yield entryFromRawEntry(
1521
1740
  receiver,
1522
1741
  rawEntry2.value,
1523
- innerTarget._loadedAs,
1742
+ innerTarget.$jazz.loadedAs,
1524
1743
  key,
1525
- innerTarget._schema[ItemsSym]
1744
+ innerTarget.$jazz.schema[ItemsSym]
1526
1745
  );
1527
1746
  }
1528
1747
  }();
@@ -1534,7 +1753,7 @@ var CoStreamPerAccountProxyHandler = (innerTarget) => ({
1534
1753
  }
1535
1754
  },
1536
1755
  ownKeys(_target) {
1537
- return Array.from(innerTarget._raw.accounts());
1756
+ return Array.from(innerTarget.$jazz.raw.accounts());
1538
1757
  },
1539
1758
  getOwnPropertyDescriptor(_target, key) {
1540
1759
  if (typeof key === "string" && key.startsWith("co_")) {
@@ -1552,19 +1771,19 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
1552
1771
  get(_target, key, receiver) {
1553
1772
  if (typeof key === "string" && key.includes("session")) {
1554
1773
  const sessionID = key;
1555
- const rawEntry = innerTarget._raw.lastItemIn(sessionID);
1774
+ const rawEntry = innerTarget.$jazz.raw.lastItemIn(sessionID);
1556
1775
  if (!rawEntry) return;
1557
1776
  const by = cojsonInternals3.accountOrAgentIDfromSessionID(sessionID);
1558
1777
  const entry = entryFromRawEntry(
1559
1778
  accessFrom,
1560
1779
  rawEntry,
1561
- innerTarget._loadedAs,
1780
+ innerTarget.$jazz.loadedAs,
1562
1781
  cojsonInternals3.isAccountID(by) ? by : void 0,
1563
- innerTarget._schema[ItemsSym]
1782
+ innerTarget.$jazz.schema[ItemsSym]
1564
1783
  );
1565
1784
  Object.defineProperty(entry, "all", {
1566
1785
  get: () => {
1567
- const allRawEntries = innerTarget._raw.itemsIn(sessionID);
1786
+ const allRawEntries = innerTarget.$jazz.raw.itemsIn(sessionID);
1568
1787
  return function* () {
1569
1788
  while (true) {
1570
1789
  const rawEntry2 = allRawEntries.next();
@@ -1572,9 +1791,9 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
1572
1791
  yield entryFromRawEntry(
1573
1792
  accessFrom,
1574
1793
  rawEntry2.value,
1575
- innerTarget._loadedAs,
1794
+ innerTarget.$jazz.loadedAs,
1576
1795
  cojsonInternals3.isAccountID(by) ? by : void 0,
1577
- innerTarget._schema[ItemsSym]
1796
+ innerTarget.$jazz.schema[ItemsSym]
1578
1797
  );
1579
1798
  }
1580
1799
  }();
@@ -1586,7 +1805,7 @@ var CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
1586
1805
  }
1587
1806
  },
1588
1807
  ownKeys() {
1589
- return innerTarget._raw.sessions();
1808
+ return innerTarget.$jazz.raw.sessions();
1590
1809
  },
1591
1810
  getOwnPropertyDescriptor(target, key) {
1592
1811
  if (typeof key === "string" && key.startsWith("co_")) {
@@ -1607,16 +1826,15 @@ var FileStream = class extends CoValueBase {
1607
1826
  if ("fromRaw" in options) {
1608
1827
  raw = options.fromRaw;
1609
1828
  } else {
1610
- const rawOwner = options.owner._raw;
1829
+ const rawOwner = options.owner.$jazz.raw;
1611
1830
  raw = rawOwner.createBinaryStream();
1612
1831
  }
1613
1832
  Object.defineProperties(this, {
1614
- id: {
1615
- value: raw.id,
1833
+ [TypeSym]: { value: "BinaryCoStream", enumerable: false },
1834
+ $jazz: {
1835
+ value: new FileStreamJazzApi(this, raw),
1616
1836
  enumerable: false
1617
- },
1618
- _type: { value: "BinaryCoStream", enumerable: false },
1619
- _raw: { value: raw, enumerable: false }
1837
+ }
1620
1838
  });
1621
1839
  }
1622
1840
  /**
@@ -1641,27 +1859,28 @@ var FileStream = class extends CoValueBase {
1641
1859
  * For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead.
1642
1860
  *
1643
1861
  * @category Creation
1862
+ * @deprecated Use `co.fileStream(...).create` instead.
1644
1863
  */
1645
1864
  static create(options) {
1646
1865
  return new this(parseCoValueCreateOptions(options));
1647
1866
  }
1648
1867
  getMetadata() {
1649
- return this._raw.getBinaryStreamInfo();
1868
+ return this.$jazz.raw.getBinaryStreamInfo();
1650
1869
  }
1651
1870
  getChunks(options) {
1652
- return this._raw.getBinaryChunks(options?.allowUnfinished);
1871
+ return this.$jazz.raw.getBinaryChunks(options?.allowUnfinished);
1653
1872
  }
1654
1873
  isBinaryStreamEnded() {
1655
- return this._raw.isBinaryStreamEnded();
1874
+ return this.$jazz.raw.isBinaryStreamEnded();
1656
1875
  }
1657
1876
  start(options) {
1658
- this._raw.startBinaryStream(options);
1877
+ this.$jazz.raw.startBinaryStream(options);
1659
1878
  }
1660
1879
  push(data) {
1661
- this._raw.pushBinaryStreamChunk(data);
1880
+ this.$jazz.raw.pushBinaryStreamChunk(data);
1662
1881
  }
1663
1882
  end() {
1664
- this._raw.endBinaryStream();
1883
+ this.$jazz.raw.endBinaryStream();
1665
1884
  }
1666
1885
  toBlob(options) {
1667
1886
  const chunks = this.getChunks({
@@ -1676,6 +1895,7 @@ var FileStream = class extends CoValueBase {
1676
1895
  * Load a `FileStream` as a `Blob`
1677
1896
  *
1678
1897
  * @category Content
1898
+ * @deprecated Use `co.fileStream(...).loadAsBlob` instead.
1679
1899
  */
1680
1900
  static async loadAsBlob(id, options) {
1681
1901
  let stream = await this.load(id, options);
@@ -1712,6 +1932,7 @@ var FileStream = class extends CoValueBase {
1712
1932
  * const fileStream = await FileStream.createFromBlob(file, {owner: group})
1713
1933
  * ```
1714
1934
  * @category Content
1935
+ * @deprecated Use `co.fileStream(...).createFromBlob` instead.
1715
1936
  */
1716
1937
  static async createFromBlob(blob, options) {
1717
1938
  const arrayBuffer = await blob.arrayBuffer();
@@ -1732,6 +1953,7 @@ var FileStream = class extends CoValueBase {
1732
1953
  * const fileStream = await FileStream.createFromBlob(file, {owner: group})
1733
1954
  * ```
1734
1955
  * @category Content
1956
+ * @deprecated Use `co.fileStream(...).createFromArrayBuffer` instead.
1735
1957
  */
1736
1958
  static async createFromArrayBuffer(arrayBuffer, mimeType, fileName, options) {
1737
1959
  const stream = this.create(options);
@@ -1770,8 +1992,6 @@ var FileStream = class extends CoValueBase {
1770
1992
  */
1771
1993
  toJSON() {
1772
1994
  return {
1773
- id: this.id,
1774
- _type: this._type,
1775
1995
  ...this.getChunks()
1776
1996
  };
1777
1997
  }
@@ -1782,6 +2002,7 @@ var FileStream = class extends CoValueBase {
1782
2002
  /**
1783
2003
  * Load a `FileStream`
1784
2004
  * @category Subscription & Loading
2005
+ * @deprecated Use `co.fileStream(...).load` instead.
1785
2006
  */
1786
2007
  static async load(id, options) {
1787
2008
  const stream = await loadCoValueWithoutMe(this, id, options);
@@ -1806,12 +2027,29 @@ var FileStream = class extends CoValueBase {
1806
2027
  const { options, listener } = parseSubscribeRestArgs(args);
1807
2028
  return subscribeToCoValueWithoutMe(this, id, options, listener);
1808
2029
  }
2030
+ };
2031
+ var FileStreamJazzApi = class extends CoValueJazzApi {
2032
+ constructor(fileStream, raw) {
2033
+ super(fileStream);
2034
+ this.fileStream = fileStream;
2035
+ this.raw = raw;
2036
+ }
2037
+ /**
2038
+ * The ID of this `FileStream`
2039
+ * @category Content
2040
+ */
2041
+ get id() {
2042
+ return this.raw.id;
2043
+ }
2044
+ get owner() {
2045
+ return getCoValueOwner(this.fileStream);
2046
+ }
1809
2047
  /**
1810
2048
  * An instance method to subscribe to an existing `FileStream`
1811
2049
  * @category Subscription & Loading
1812
2050
  */
1813
2051
  subscribe(listener) {
1814
- return subscribeToExistingCoValue(this, {}, listener);
2052
+ return subscribeToExistingCoValue(this.fileStream, {}, listener);
1815
2053
  }
1816
2054
  /**
1817
2055
  * Wait for the `FileStream` to be uploaded to the other peers.
@@ -1819,146 +2057,114 @@ var FileStream = class extends CoValueBase {
1819
2057
  * @category Subscription & Loading
1820
2058
  */
1821
2059
  waitForSync(options) {
1822
- return this._raw.core.waitForSync(options);
2060
+ return this.raw.core.waitForSync(options);
1823
2061
  }
1824
2062
  };
1825
2063
 
1826
2064
  // src/tools/coValues/account.ts
1827
2065
  import {
1828
- ControlledAccount as ControlledAccount3,
1829
- LocalNode,
2066
+ ControlledAccount as RawControlledAccount,
2067
+ LocalNode as LocalNode2,
1830
2068
  cojsonInternals as cojsonInternals4
1831
2069
  } from "cojson";
1832
- var _Account = class _Account extends CoValueBase {
1833
- get _schema() {
1834
- return this.constructor._schema;
1835
- }
1836
- get _owner() {
1837
- return this;
1838
- }
1839
- get _loadedAs() {
1840
- if (this.isLocalNodeOwner) return this;
1841
- const agent = this._raw.core.node.getCurrentAgent();
1842
- if (agent instanceof ControlledAccount3) {
1843
- return coValuesCache.get(
1844
- agent.account,
1845
- () => _Account.fromRaw(agent.account)
1846
- );
1847
- }
1848
- return new AnonymousJazzAgent(this._raw.core.node);
1849
- }
1850
- getDescriptor(key) {
1851
- if (key === "profile") {
1852
- return this._schema.profile;
1853
- } else if (key === "root") {
1854
- return this._schema.root;
1855
- }
1856
- return void 0;
1857
- }
1858
- get _refs() {
1859
- const profileID = this._raw.get("profile");
1860
- const rootID = this._raw.get("root");
1861
- return {
1862
- profile: profileID ? new Ref(
1863
- profileID,
1864
- this._loadedAs,
1865
- this._schema.profile,
1866
- this
1867
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1868
- ) : void 0,
1869
- root: rootID ? new Ref(
1870
- rootID,
1871
- this._loadedAs,
1872
- this._schema.root,
1873
- this
1874
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1875
- ) : void 0
1876
- };
1877
- }
1878
- /**
1879
- * Whether this account is the currently active account.
1880
- */
1881
- get isMe() {
1882
- return activeAccountContext.get().id === this.id;
1883
- }
2070
+ var Account = class extends CoValueBase {
1884
2071
  constructor(options) {
1885
2072
  super();
1886
2073
  if (!("fromRaw" in options)) {
1887
2074
  throw new Error("Can only construct account from raw or with .create()");
1888
2075
  }
1889
- this.isLocalNodeOwner = options.fromRaw.id == options.fromRaw.core.node.getCurrentAgent().id;
2076
+ const proxy = new Proxy(
2077
+ this,
2078
+ AccountAndGroupProxyHandler
2079
+ );
1890
2080
  Object.defineProperties(this, {
1891
- id: {
1892
- value: options.fromRaw.id,
2081
+ [TypeSym]: { value: "Account", enumerable: false },
2082
+ $jazz: {
2083
+ value: new AccountJazzApi(proxy, options.fromRaw),
1893
2084
  enumerable: false
1894
- },
1895
- _raw: { value: options.fromRaw, enumerable: false },
1896
- _type: { value: "Account", enumerable: false }
2085
+ }
1897
2086
  });
1898
- if (this.isLocalNodeOwner) {
1899
- this.sessionID = options.fromRaw.core.node.currentSessionID;
1900
- }
1901
- return new Proxy(this, AccountAndGroupProxyHandler);
2087
+ return proxy;
1902
2088
  }
1903
- myRole() {
1904
- if (this.isLocalNodeOwner) {
1905
- return "admin";
2089
+ /**
2090
+ * Whether this account is the currently active account.
2091
+ */
2092
+ get isMe() {
2093
+ return activeAccountContext.get().$jazz.id === this.$jazz.id;
2094
+ }
2095
+ /**
2096
+ * Accept an invite to a `CoValue` or `Group`.
2097
+ *
2098
+ * @param valueID The ID of the `CoValue` or `Group` to accept the invite to.
2099
+ * @param inviteSecret The secret of the invite to accept.
2100
+ * @param coValueClass The class of the `CoValue` or `Group` to accept the invite to.
2101
+ * @returns The loaded `CoValue` or `Group`.
2102
+ */
2103
+ async acceptInvite(valueID, inviteSecret, coValueClass) {
2104
+ if (!this.$jazz.isLocalNodeOwner) {
2105
+ throw new Error("Only a controlled account can accept invites");
1906
2106
  }
2107
+ await this.$jazz.localNode.acceptInvite(
2108
+ valueID,
2109
+ inviteSecret
2110
+ );
2111
+ return loadCoValue(
2112
+ coValueClassFromCoValueClassOrSchema(coValueClass),
2113
+ valueID,
2114
+ {
2115
+ loadAs: this
2116
+ }
2117
+ );
1907
2118
  }
1908
2119
  getRoleOf(member) {
1909
2120
  if (member === "me") {
1910
2121
  return this.isMe ? "admin" : void 0;
1911
2122
  }
1912
- if (member === this.id) {
2123
+ if (member === this.$jazz.id) {
1913
2124
  return "admin";
1914
2125
  }
1915
- return void 0;
1916
- }
1917
- getParentGroups() {
1918
- return [];
1919
- }
1920
- get members() {
1921
- const ref2 = new Ref(
1922
- this.id,
1923
- this._loadedAs,
1924
- {
1925
- ref: () => this.constructor,
1926
- optional: false
1927
- },
1928
- this
1929
- );
1930
- return [{ id: this.id, role: "admin", ref: ref2, account: this }];
2126
+ return void 0;
1931
2127
  }
1932
2128
  canRead(value) {
1933
- const role = value._owner.getRoleOf(this.id);
2129
+ const valueOwner = value.$jazz.owner;
2130
+ if (!valueOwner) {
2131
+ return true;
2132
+ }
2133
+ const role = valueOwner.getRoleOf(this.$jazz.id);
1934
2134
  return role === "admin" || role === "writer" || role === "reader" || role === "writeOnly";
1935
2135
  }
1936
2136
  canWrite(value) {
1937
- const role = value._owner.getRoleOf(this.id);
2137
+ const valueOwner = value.$jazz.owner;
2138
+ if (!valueOwner) {
2139
+ if (value[TypeSym] === "Group") {
2140
+ const roleInGroup = value.getRoleOf(this.$jazz.id);
2141
+ return roleInGroup === "admin" || roleInGroup === "writer";
2142
+ }
2143
+ if (value[TypeSym] === "Account") {
2144
+ return value.$jazz.id === this.$jazz.id;
2145
+ }
2146
+ return false;
2147
+ }
2148
+ const role = valueOwner.getRoleOf(this.$jazz.id);
1938
2149
  return role === "admin" || role === "writer" || role === "writeOnly";
1939
2150
  }
1940
2151
  canAdmin(value) {
1941
- return value._owner.getRoleOf(this.id) === "admin";
1942
- }
1943
- async acceptInvite(valueID, inviteSecret, coValueClass) {
1944
- if (!this.isLocalNodeOwner) {
1945
- throw new Error("Only a controlled account can accept invites");
1946
- }
1947
- await this._raw.core.node.acceptInvite(
1948
- valueID,
1949
- inviteSecret
1950
- );
1951
- return loadCoValue(
1952
- coValueClassFromCoValueClassOrSchema(coValueClass),
1953
- valueID,
1954
- {
1955
- loadAs: this
2152
+ const valueOwner = value.$jazz.owner;
2153
+ if (!valueOwner) {
2154
+ if (value[TypeSym] === "Group") {
2155
+ const roleInGroup = value.getRoleOf(this.$jazz.id);
2156
+ return roleInGroup === "admin";
1956
2157
  }
1957
- );
2158
+ if (value[TypeSym] === "Account") {
2159
+ return value.$jazz.id === this.$jazz.id;
2160
+ }
2161
+ return false;
2162
+ }
2163
+ return valueOwner.getRoleOf(this.$jazz.id) === "admin";
1958
2164
  }
1959
2165
  /** @private */
1960
2166
  static async create(options) {
1961
- const { node } = await LocalNode.withNewlyCreatedAccount({
2167
+ const { node } = await LocalNode2.withNewlyCreatedAccount({
1962
2168
  ...options,
1963
2169
  migration: async (rawAccount, _node, creationProps) => {
1964
2170
  const account = new this({
@@ -1972,19 +2178,22 @@ var _Account = class _Account extends CoValueBase {
1972
2178
  static getMe() {
1973
2179
  return activeAccountContext.get();
1974
2180
  }
2181
+ /**
2182
+ * @deprecated Use `co.account(...).createAs` instead.
2183
+ */
1975
2184
  static async createAs(as, options) {
1976
2185
  const connectedPeers = cojsonInternals4.connectedPeers(
1977
2186
  "creatingAccount",
1978
2187
  "createdAccount",
1979
2188
  { peer1role: "server", peer2role: "client" }
1980
2189
  );
1981
- as._raw.core.node.syncManager.addPeer(connectedPeers[1]);
2190
+ as.$jazz.localNode.syncManager.addPeer(connectedPeers[1]);
1982
2191
  const account = await this.create({
1983
2192
  creationProps: options.creationProps,
1984
- crypto: as._raw.core.node.crypto,
2193
+ crypto: as.$jazz.localNode.crypto,
1985
2194
  peersToLoadFrom: [connectedPeers[0]]
1986
2195
  });
1987
- await account.waitForAllCoValuesSync();
2196
+ await account.$jazz.waitForAllCoValuesSync();
1988
2197
  return account;
1989
2198
  }
1990
2199
  static fromNode(node) {
@@ -1994,10 +2203,7 @@ var _Account = class _Account extends CoValueBase {
1994
2203
  }
1995
2204
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1996
2205
  toJSON() {
1997
- return {
1998
- id: this.id,
1999
- _type: this._type
2000
- };
2206
+ return {};
2001
2207
  }
2002
2208
  [inspect]() {
2003
2209
  return this.toJSON();
@@ -2006,17 +2212,13 @@ var _Account = class _Account extends CoValueBase {
2006
2212
  await this.migrate(creationProps);
2007
2213
  if (this.profile === void 0 && creationProps) {
2008
2214
  const profileGroup = RegisteredSchemas["Group"].create({ owner: this });
2009
- this.profile = Profile.create({ name: creationProps.name }, profileGroup);
2215
+ this.$jazz.set(
2216
+ "profile",
2217
+ Profile.create({ name: creationProps.name }, profileGroup)
2218
+ );
2010
2219
  profileGroup.addMember("everyone", "reader");
2011
- } else if (this.profile && creationProps) {
2012
- if (this.profile._owner._type !== "Group") {
2013
- throw new Error("Profile must be owned by a Group", {
2014
- cause: `The profile of the account "${this.id}" was created with an Account as owner, which is not allowed.`
2015
- });
2016
- }
2017
2220
  }
2018
- const node = this._raw.core.node;
2019
- const profile = node.expectCoValueLoaded(this._raw.get("profile")).getCurrentContent();
2221
+ const profile = this.$jazz.localNode.expectCoValueLoaded(this.$jazz.raw.get("profile")).getCurrentContent();
2020
2222
  if (!profile.get("inbox")) {
2021
2223
  const inboxRoot = createInboxRoot(this);
2022
2224
  profile.set("inbox", inboxRoot.id);
@@ -2027,7 +2229,11 @@ var _Account = class _Account extends CoValueBase {
2027
2229
  migrate(creationProps) {
2028
2230
  creationProps;
2029
2231
  }
2030
- /** @category Subscription & Loading */
2232
+ /**
2233
+ * Load an `Account`
2234
+ * @category Subscription & Loading
2235
+ * @deprecated Use `co.account(...).load` instead.
2236
+ */
2031
2237
  static load(id, options) {
2032
2238
  return loadCoValueWithoutMe(this, id, options);
2033
2239
  }
@@ -2035,13 +2241,109 @@ var _Account = class _Account extends CoValueBase {
2035
2241
  const { options, listener } = parseSubscribeRestArgs(args);
2036
2242
  return subscribeToCoValueWithoutMe(this, id, options, listener);
2037
2243
  }
2244
+ };
2245
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2246
+ Account._schema = {
2247
+ profile: {
2248
+ ref: () => Profile,
2249
+ optional: false
2250
+ },
2251
+ root: {
2252
+ ref: () => RegisteredSchemas["CoMap"],
2253
+ optional: true
2254
+ }
2255
+ };
2256
+ var AccountJazzApi = class extends CoValueJazzApi {
2257
+ constructor(account, raw) {
2258
+ super(account);
2259
+ this.account = account;
2260
+ this.raw = raw;
2261
+ this.isLocalNodeOwner = this.raw.id === this.localNode.getCurrentAgent().id;
2262
+ if (this.isLocalNodeOwner) {
2263
+ this.sessionID = this.localNode.currentSessionID;
2264
+ }
2265
+ }
2266
+ /**
2267
+ * The ID of this `Account`
2268
+ * @category Content
2269
+ */
2270
+ get id() {
2271
+ return this.raw.id;
2272
+ }
2273
+ /**
2274
+ * Accounts have no owner. They can be accessed by everyone.
2275
+ */
2276
+ get owner() {
2277
+ return void 0;
2278
+ }
2279
+ /**
2280
+ * Set the value of a key in the account.
2281
+ *
2282
+ * @param key The key to set.
2283
+ * @param value The value to set.
2284
+ *
2285
+ * @category Content
2286
+ */
2287
+ set(key, value) {
2288
+ if (value) {
2289
+ let refId = value.$jazz?.id;
2290
+ if (!refId) {
2291
+ const descriptor = this.schema[key];
2292
+ const coValue = instantiateRefEncodedWithInit(
2293
+ descriptor,
2294
+ value,
2295
+ accountOrGroupToGroup(this.account)
2296
+ );
2297
+ refId = coValue.$jazz.id;
2298
+ }
2299
+ this.raw.set(key, refId, "trusting");
2300
+ }
2301
+ }
2302
+ /**
2303
+ * Get the descriptor for a given key
2304
+ * @internal
2305
+ */
2306
+ getDescriptor(key) {
2307
+ if (key === "profile") {
2308
+ return this.schema.profile;
2309
+ } else if (key === "root") {
2310
+ return this.schema.root;
2311
+ }
2312
+ return void 0;
2313
+ }
2314
+ /**
2315
+ * If property `prop` is a `coField.ref(...)`, you can use `account.$jazz.refs.prop` to access
2316
+ * the `Ref` instead of the potentially loaded/null value.
2317
+ *
2318
+ * This allows you to always get the ID or load the value manually.
2319
+ *
2320
+ * @category Content
2321
+ */
2322
+ get refs() {
2323
+ const profileID = this.raw.get("profile");
2324
+ const rootID = this.raw.get("root");
2325
+ return {
2326
+ profile: profileID ? new Ref(
2327
+ profileID,
2328
+ this.loadedAs,
2329
+ this.schema.profile,
2330
+ this.account
2331
+ ) : void 0,
2332
+ root: rootID ? new Ref(
2333
+ rootID,
2334
+ this.loadedAs,
2335
+ this.schema.root,
2336
+ this.account
2337
+ ) : void 0
2338
+ };
2339
+ }
2038
2340
  /** @category Subscription & Loading */
2039
2341
  ensureLoaded(options) {
2040
- return ensureCoValueLoaded(this, options);
2342
+ return ensureCoValueLoaded(this.account, options);
2041
2343
  }
2042
2344
  subscribe(...args) {
2043
2345
  const { options, listener } = parseSubscribeRestArgs(args);
2044
- return subscribeToExistingCoValue(this, options, listener);
2346
+ return subscribeToExistingCoValue(this.account, options, listener);
2045
2347
  }
2046
2348
  /**
2047
2349
  * Wait for the `Account` to be uploaded to the other peers.
@@ -2049,7 +2351,7 @@ var _Account = class _Account extends CoValueBase {
2049
2351
  * @category Subscription & Loading
2050
2352
  */
2051
2353
  waitForSync(options) {
2052
- return this._raw.core.waitForSync(options);
2354
+ return this.raw.core.waitForSync(options);
2053
2355
  }
2054
2356
  /**
2055
2357
  * Wait for all the available `CoValues` to be uploaded to the other peers.
@@ -2057,26 +2359,28 @@ var _Account = class _Account extends CoValueBase {
2057
2359
  * @category Subscription & Loading
2058
2360
  */
2059
2361
  waitForAllCoValuesSync(options) {
2060
- return this._raw.core.node.syncManager.waitForAllCoValuesSync(
2061
- options?.timeout
2062
- );
2362
+ return this.localNode.syncManager.waitForAllCoValuesSync(options?.timeout);
2063
2363
  }
2064
- };
2065
- _Account._schema = {
2066
- profile: {
2067
- ref: () => Profile,
2068
- optional: false
2069
- },
2070
- root: {
2071
- ref: () => RegisteredSchemas["CoMap"],
2072
- optional: true
2364
+ /** @internal */
2365
+ get schema() {
2366
+ return this.account.constructor._schema;
2367
+ }
2368
+ get loadedAs() {
2369
+ if (this.isLocalNodeOwner) return this.account;
2370
+ const agent = this.localNode.getCurrentAgent();
2371
+ if (agent instanceof RawControlledAccount) {
2372
+ return coValuesCache.get(
2373
+ agent.account,
2374
+ () => Account.fromRaw(agent.account)
2375
+ );
2376
+ }
2377
+ return new AnonymousJazzAgent(this.localNode);
2073
2378
  }
2074
2379
  };
2075
- var Account = _Account;
2076
2380
  var AccountAndGroupProxyHandler = {
2077
2381
  get(target, key, receiver) {
2078
2382
  if (key === "profile" || key === "root") {
2079
- const id = target._raw.get(key);
2383
+ const id = target.$jazz.raw.get(key);
2080
2384
  if (id) {
2081
2385
  return accessChildByKey(target, id, key);
2082
2386
  } else {
@@ -2087,26 +2391,13 @@ var AccountAndGroupProxyHandler = {
2087
2391
  }
2088
2392
  },
2089
2393
  set(target, key, value, receiver) {
2090
- if ((key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
2394
+ if (target instanceof Account && (key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
2091
2395
  target.constructor._schema ||= {};
2092
2396
  target.constructor._schema[key] = value[SchemaInit];
2093
2397
  return true;
2094
- } else if (key === "profile") {
2095
- if (value) {
2096
- target._raw.set(
2097
- "profile",
2098
- value.id,
2099
- "trusting"
2100
- );
2101
- }
2102
- return true;
2103
- } else if (key === "root") {
2398
+ } else if (target instanceof Account && (key === "profile" || key === "root")) {
2104
2399
  if (value) {
2105
- target._raw.set(
2106
- "root",
2107
- value.id,
2108
- "trusting"
2109
- );
2400
+ target.$jazz.set(key, value);
2110
2401
  }
2111
2402
  return true;
2112
2403
  } else {
@@ -2124,35 +2415,12 @@ var AccountAndGroupProxyHandler = {
2124
2415
  }
2125
2416
  };
2126
2417
  function isControlledAccount(account) {
2127
- return account.isLocalNodeOwner;
2418
+ return account.$jazz.isLocalNodeOwner;
2128
2419
  }
2129
2420
  RegisteredSchemas["Account"] = Account;
2130
2421
 
2131
2422
  // src/tools/coValues/group.ts
2132
2423
  var _Group = class _Group extends CoValueBase {
2133
- get _schema() {
2134
- return this.constructor._schema;
2135
- }
2136
- get _refs() {
2137
- const profileID = this._raw.get("profile");
2138
- const rootID = this._raw.get("root");
2139
- return {
2140
- profile: profileID ? new Ref(
2141
- profileID,
2142
- this._loadedAs,
2143
- this._schema.profile,
2144
- this
2145
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2146
- ) : void 0,
2147
- root: rootID ? new Ref(
2148
- rootID,
2149
- this._loadedAs,
2150
- this._schema.root,
2151
- this
2152
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2153
- ) : void 0
2154
- };
2155
- }
2156
2424
  /** @deprecated Don't use constructor directly, use .create */
2157
2425
  constructor(options) {
2158
2426
  super();
@@ -2162,43 +2430,49 @@ var _Group = class _Group extends CoValueBase {
2162
2430
  } else {
2163
2431
  const initOwner = options.owner;
2164
2432
  if (!initOwner) throw new Error("No owner provided");
2165
- if (initOwner._type === "Account" && isControlledAccount(initOwner)) {
2166
- const rawOwner = initOwner._raw;
2433
+ if (initOwner[TypeSym] === "Account" && isControlledAccount(initOwner)) {
2434
+ const rawOwner = initOwner.$jazz.raw;
2167
2435
  raw = rawOwner.core.node.createGroup();
2168
2436
  } else {
2169
2437
  throw new Error("Can only construct group as a controlled account");
2170
2438
  }
2171
2439
  }
2440
+ const proxy = new Proxy(
2441
+ this,
2442
+ AccountAndGroupProxyHandler
2443
+ );
2172
2444
  Object.defineProperties(this, {
2173
- id: {
2174
- value: raw.id,
2445
+ $jazz: {
2446
+ value: new GroupJazzApi(proxy, raw),
2175
2447
  enumerable: false
2176
- },
2177
- _raw: { value: raw, enumerable: false }
2448
+ }
2178
2449
  });
2179
- return new Proxy(this, AccountAndGroupProxyHandler);
2450
+ return proxy;
2180
2451
  }
2181
2452
  static create(options) {
2182
2453
  return new this(parseGroupCreateOptions(options));
2183
2454
  }
2184
2455
  myRole() {
2185
- return this._raw.myRole();
2456
+ return this.$jazz.raw.myRole();
2186
2457
  }
2187
2458
  addMember(member, role) {
2188
- if (member !== "everyone" && member._type === "Group") {
2459
+ if (member !== "everyone" && member[TypeSym] === "Group") {
2189
2460
  if (role === "writeOnly")
2190
2461
  throw new Error("Cannot add group as member with write-only role");
2191
- this._raw.extend(member._raw, role);
2462
+ this.$jazz.raw.extend(member.$jazz.raw, role);
2192
2463
  } else if (role !== void 0 && role !== "inherit") {
2193
- this._raw.addMember(member === "everyone" ? member : member._raw, role);
2464
+ this.$jazz.raw.addMember(
2465
+ member === "everyone" ? member : member.$jazz.raw,
2466
+ role
2467
+ );
2194
2468
  }
2195
2469
  }
2196
2470
  removeMember(member) {
2197
- if (member !== "everyone" && member._type === "Group") {
2198
- this._raw.revokeExtend(member._raw);
2471
+ if (member !== "everyone" && member[TypeSym] === "Group") {
2472
+ this.$jazz.raw.revokeExtend(member.$jazz.raw);
2199
2473
  } else {
2200
- return this._raw.removeMember(
2201
- member === "everyone" ? member : member._raw
2474
+ return this.$jazz.raw.removeMember(
2475
+ member === "everyone" ? member : member.$jazz.raw
2202
2476
  );
2203
2477
  }
2204
2478
  }
@@ -2210,11 +2484,11 @@ var _Group = class _Group extends CoValueBase {
2210
2484
  };
2211
2485
  for (const accountID of accountIDs) {
2212
2486
  if (!isAccountID(accountID)) continue;
2213
- const role = this._raw.roleOf(accountID);
2487
+ const role = this.$jazz.raw.roleOf(accountID);
2214
2488
  if (role === "admin" || role === "writer" || role === "reader" || role === "writeOnly") {
2215
2489
  const ref2 = new Ref(
2216
2490
  accountID,
2217
- this._loadedAs,
2491
+ this.$jazz.loadedAs,
2218
2492
  refEncodedAccountSchema,
2219
2493
  this
2220
2494
  );
@@ -2241,7 +2515,7 @@ var _Group = class _Group extends CoValueBase {
2241
2515
  * @returns The members of the group.
2242
2516
  */
2243
2517
  get members() {
2244
- return this.getMembersFromKeys(this._raw.getAllMemberKeysSet());
2518
+ return this.getMembersFromKeys(this.$jazz.raw.getAllMemberKeysSet());
2245
2519
  }
2246
2520
  /**
2247
2521
  * Returns the direct members of the group.
@@ -2251,17 +2525,11 @@ var _Group = class _Group extends CoValueBase {
2251
2525
  * @returns The direct members of the group.
2252
2526
  */
2253
2527
  getDirectMembers() {
2254
- return this.getMembersFromKeys(this._raw.getMemberKeys());
2528
+ return this.getMembersFromKeys(this.$jazz.raw.getMemberKeys());
2255
2529
  }
2256
2530
  getRoleOf(member) {
2257
- if (member === "me") {
2258
- return this._raw.roleOf(
2259
- activeAccountContext.get().id
2260
- );
2261
- }
2262
- return this._raw.roleOf(
2263
- member === "everyone" ? member : member
2264
- );
2531
+ const accountId = member === "me" ? activeAccountContext.get().$jazz.id : member === "everyone" ? member : member;
2532
+ return this.$jazz.raw.roleOf(accountId);
2265
2533
  }
2266
2534
  /**
2267
2535
  * Make the group public, so that everyone can read it.
@@ -2275,7 +2543,7 @@ var _Group = class _Group extends CoValueBase {
2275
2543
  return this;
2276
2544
  }
2277
2545
  getParentGroups() {
2278
- return this._raw.getParentGroups().map((group) => _Group.fromRaw(group));
2546
+ return this.$jazz.raw.getParentGroups().map((group) => _Group.fromRaw(group));
2279
2547
  }
2280
2548
  /** @category Identity & Permissions
2281
2549
  * Gives members of a parent group membership in this group.
@@ -2285,7 +2553,7 @@ var _Group = class _Group extends CoValueBase {
2285
2553
  * @returns This group.
2286
2554
  */
2287
2555
  extend(parent, roleMapping) {
2288
- this._raw.extend(parent._raw, roleMapping);
2556
+ this.$jazz.raw.extend(parent.$jazz.raw, roleMapping);
2289
2557
  return this;
2290
2558
  }
2291
2559
  /** @category Identity & Permissions
@@ -2295,7 +2563,7 @@ var _Group = class _Group extends CoValueBase {
2295
2563
  * @returns This group.
2296
2564
  */
2297
2565
  async revokeExtend(parent) {
2298
- await this._raw.revokeExtend(parent._raw);
2566
+ await this.$jazz.raw.revokeExtend(parent.$jazz.raw);
2299
2567
  return this;
2300
2568
  }
2301
2569
  /** @category Subscription & Loading */
@@ -2306,13 +2574,35 @@ var _Group = class _Group extends CoValueBase {
2306
2574
  const { options, listener } = parseSubscribeRestArgs(args);
2307
2575
  return subscribeToCoValueWithoutMe(this, id, options, listener);
2308
2576
  }
2577
+ };
2578
+ _Group.prototype[TypeSym] = "Group";
2579
+ var Group6 = _Group;
2580
+ var GroupJazzApi = class extends CoValueJazzApi {
2581
+ constructor(group, raw) {
2582
+ super(group);
2583
+ this.group = group;
2584
+ this.raw = raw;
2585
+ }
2586
+ /**
2587
+ * The ID of this `Group`
2588
+ * @category Content
2589
+ */
2590
+ get id() {
2591
+ return this.raw.id;
2592
+ }
2593
+ /**
2594
+ * Groups have no owner. They can be accessed by everyone.
2595
+ */
2596
+ get owner() {
2597
+ return void 0;
2598
+ }
2309
2599
  /** @category Subscription & Loading */
2310
2600
  ensureLoaded(options) {
2311
- return ensureCoValueLoaded(this, options);
2601
+ return ensureCoValueLoaded(this.group, options);
2312
2602
  }
2313
2603
  subscribe(...args) {
2314
2604
  const { options, listener } = parseSubscribeRestArgs(args);
2315
- return subscribeToExistingCoValue(this, options, listener);
2605
+ return subscribeToExistingCoValue(this.group, options, listener);
2316
2606
  }
2317
2607
  /**
2318
2608
  * Wait for the `Group` to be uploaded to the other peers.
@@ -2320,23 +2610,23 @@ var _Group = class _Group extends CoValueBase {
2320
2610
  * @category Subscription & Loading
2321
2611
  */
2322
2612
  waitForSync(options) {
2323
- return this._raw.core.waitForSync(options);
2613
+ return this.raw.core.waitForSync(options);
2324
2614
  }
2325
2615
  };
2326
- _Group.prototype._type = "Group";
2327
- _Group._schema = {
2328
- profile: "json",
2329
- root: "json"
2330
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2331
- };
2332
- Object.defineProperty(_Group.prototype, "_schema", {
2333
- get: () => _Group._schema
2334
- });
2335
- var Group = _Group;
2336
- RegisteredSchemas["Group"] = Group;
2616
+ RegisteredSchemas["Group"] = Group6;
2337
2617
  function isAccountID(id) {
2338
2618
  return id.startsWith("co_");
2339
2619
  }
2620
+ function getCoValueOwner(coValue) {
2621
+ const group = accessChildById(coValue, coValue.$jazz.raw.group.id, {
2622
+ ref: RegisteredSchemas["Group"],
2623
+ optional: false
2624
+ });
2625
+ if (!group) {
2626
+ throw new Error("CoValue has no owner");
2627
+ }
2628
+ return group;
2629
+ }
2340
2630
 
2341
2631
  // src/tools/coValues/profile.ts
2342
2632
  var Profile = class extends CoMap {
@@ -2352,10 +2642,11 @@ var Profile = class extends CoMap {
2352
2642
  * The owner (a Group) determines access rights to the Profile.
2353
2643
  *
2354
2644
  * @category Creation
2645
+ * @deprecated Use `co.profile(...).create` instead.
2355
2646
  */
2356
2647
  static create(init, options) {
2357
2648
  const owner = options !== void 0 && "owner" in options ? options.owner : options;
2358
- if (owner?._type === "Account") {
2649
+ if (owner?.[TypeSym] === "Account") {
2359
2650
  throw new Error("Profiles should be owned by a group");
2360
2651
  }
2361
2652
  return super.create(init, options);
@@ -2363,7 +2654,7 @@ var Profile = class extends CoMap {
2363
2654
  };
2364
2655
 
2365
2656
  // src/tools/coValues/inbox.ts
2366
- import { RawAccount as RawAccount4 } from "cojson";
2657
+ import { RawAccount as RawAccount2 } from "cojson";
2367
2658
 
2368
2659
  // src/tools/lib/id.ts
2369
2660
  function isCoValueId(id) {
@@ -2372,10 +2663,10 @@ function isCoValueId(id) {
2372
2663
 
2373
2664
  // src/tools/coValues/inbox.ts
2374
2665
  function createInboxRoot(account) {
2375
- if (!account.isLocalNodeOwner) {
2666
+ if (!account.$jazz.isLocalNodeOwner) {
2376
2667
  throw new Error("Account is not controlled");
2377
2668
  }
2378
- const rawAccount = account._raw;
2669
+ const rawAccount = account.$jazz.raw;
2379
2670
  const group = rawAccount.core.node.createGroup();
2380
2671
  const messagesFeed = group.createStream();
2381
2672
  const inboxRoot = rawAccount.createMap();
@@ -2391,18 +2682,18 @@ function createInboxRoot(account) {
2391
2682
  };
2392
2683
  }
2393
2684
  async function createInboxMessage(payload, inboxOwner) {
2394
- const group = payload._raw.group;
2395
- if (group instanceof RawAccount4) {
2685
+ const group = payload.$jazz.raw.group;
2686
+ if (group instanceof RawAccount2) {
2396
2687
  throw new Error("Inbox messages should be owned by a group");
2397
2688
  }
2398
2689
  group.addMember(inboxOwner, "writer");
2399
2690
  const message = group.createMap({
2400
- payload: payload.id,
2691
+ payload: payload.$jazz.id,
2401
2692
  result: void 0,
2402
2693
  processed: false,
2403
2694
  error: void 0
2404
2695
  });
2405
- await payload._raw.core.waitForSync();
2696
+ await payload.$jazz.raw.core.waitForSync();
2406
2697
  await message.core.waitForSync();
2407
2698
  return message;
2408
2699
  }
@@ -2415,10 +2706,10 @@ var Inbox = class _Inbox {
2415
2706
  this.processed = processed;
2416
2707
  this.failed = failed;
2417
2708
  }
2418
- subscribe(Schema, callback, options = {}) {
2709
+ subscribe(Schema4, callback, options = {}) {
2419
2710
  const processed = /* @__PURE__ */ new Set();
2420
2711
  const failed = /* @__PURE__ */ new Map();
2421
- const node = this.account._raw.core.node;
2712
+ const node = this.account.$jazz.localNode;
2422
2713
  this.processed.subscribe((stream) => {
2423
2714
  for (const items of Object.values(stream.items)) {
2424
2715
  for (const item of items) {
@@ -2453,7 +2744,7 @@ var Inbox = class _Inbox {
2453
2744
  );
2454
2745
  }
2455
2746
  return loadCoValue(
2456
- coValueClassFromCoValueClassOrSchema(Schema),
2747
+ coValueClassFromCoValueClassOrSchema(Schema4),
2457
2748
  message.get("payload"),
2458
2749
  {
2459
2750
  loadAs: account
@@ -2469,7 +2760,7 @@ var Inbox = class _Inbox {
2469
2760
  }).then((result) => {
2470
2761
  const inboxMessage = node.expectCoValueLoaded(item.value).getCurrentContent();
2471
2762
  if (result) {
2472
- inboxMessage.set("result", result.id);
2763
+ inboxMessage.set("result", result.$jazz.id);
2473
2764
  }
2474
2765
  inboxMessage.set("processed", true);
2475
2766
  this.processed.push(txKey);
@@ -2518,7 +2809,7 @@ var Inbox = class _Inbox {
2518
2809
  if (!profile.inbox) {
2519
2810
  throw new Error("The account has not set up their inbox");
2520
2811
  }
2521
- const node = account._raw.core.node;
2812
+ const node = account.$jazz.localNode;
2522
2813
  const root = await node.load(profile.inbox);
2523
2814
  if (root === "unavailable") {
2524
2815
  throw new Error("Inbox not found");
@@ -2563,7 +2854,7 @@ var InboxSender = class _InboxSender {
2563
2854
  }
2564
2855
  static async load(inboxOwnerID, currentAccount) {
2565
2856
  currentAccount ||= activeAccountContext.get();
2566
- const node = currentAccount._raw.core.node;
2857
+ const node = currentAccount.$jazz.localNode;
2567
2858
  const inboxOwnerRaw = await node.load(
2568
2859
  inboxOwnerID
2569
2860
  );
@@ -2574,7 +2865,7 @@ var InboxSender = class _InboxSender {
2574
2865
  if (inboxOwnerProfileRaw === "unavailable") {
2575
2866
  throw new Error("Failed to load the inbox owner profile");
2576
2867
  }
2577
- if (inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "reader" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "writer" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "admin") {
2868
+ if (inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "reader" && inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "writer" && inboxOwnerProfileRaw.group.roleOf(currentAccount.$jazz.raw.id) !== "admin") {
2578
2869
  throw new Error(
2579
2870
  "Insufficient permissions to access the inbox, make sure its user profile is publicly readable."
2580
2871
  );
@@ -2598,10 +2889,10 @@ async function acceptInvite(invite, account) {
2598
2889
  if (!isCoValueId(id) || !inviteSecret.startsWith("inviteSecret_")) {
2599
2890
  throw new Error("Invalid inbox ticket");
2600
2891
  }
2601
- if (!account.isLocalNodeOwner) {
2892
+ if (!account.$jazz.isLocalNodeOwner) {
2602
2893
  throw new Error("Account is not controlled");
2603
2894
  }
2604
- await account._raw.core.node.acceptInvite(id, inviteSecret);
2895
+ await account.$jazz.localNode.acceptInvite(id, inviteSecret);
2605
2896
  return id;
2606
2897
  }
2607
2898
  function getAccountIDfromSessionID(sessionID) {
@@ -2614,44 +2905,9 @@ function getAccountIDfromSessionID(sessionID) {
2614
2905
  }
2615
2906
 
2616
2907
  // src/tools/coValues/coPlainText.ts
2617
- import {
2618
- ControlledAccount as ControlledAccount4,
2619
- RawAccount as RawAccount5,
2620
- stringifyOpID
2621
- } from "cojson";
2908
+ import { stringifyOpID } from "cojson";
2622
2909
  import { calcPatch as calcPatch2 } from "fast-myers-diff";
2623
-
2624
- // src/tools/lib/cache.ts
2625
- var weakMap = /* @__PURE__ */ new WeakMap();
2626
- var coValuesCache = {
2627
- get: (raw, compute) => {
2628
- const cached = weakMap.get(raw);
2629
- if (cached) {
2630
- return cached;
2631
- }
2632
- const computed = compute();
2633
- weakMap.set(raw, computed);
2634
- return computed;
2635
- }
2636
- };
2637
-
2638
- // src/tools/coValues/coPlainText.ts
2639
2910
  var CoPlainText = class extends String {
2640
- get _owner() {
2641
- return this._raw.group instanceof RawAccount5 ? Account.fromRaw(this._raw.group) : Group.fromRaw(this._raw.group);
2642
- }
2643
- get _loadedAs() {
2644
- const agent = this._raw.core.node.getCurrentAgent();
2645
- if (agent instanceof ControlledAccount4) {
2646
- return coValuesCache.get(
2647
- agent.account,
2648
- () => coValueClassFromCoValueClassOrSchema(
2649
- RegisteredSchemas["Account"]
2650
- ).fromRaw(agent.account)
2651
- );
2652
- }
2653
- return new AnonymousJazzAgent(this._raw.core.node);
2654
- }
2655
2911
  /** @internal */
2656
2912
  constructor(options) {
2657
2913
  if (!options) {
@@ -2662,19 +2918,23 @@ var CoPlainText = class extends String {
2662
2918
  super(options.fromRaw.toString());
2663
2919
  const raw = options.fromRaw;
2664
2920
  Object.defineProperties(this, {
2665
- id: { value: raw.id, enumerable: false },
2666
- _type: { value: "CoPlainText", enumerable: false },
2667
- _raw: { value: raw, enumerable: false }
2921
+ [TypeSym]: { value: "CoPlainText", enumerable: false },
2922
+ $jazz: {
2923
+ value: new CoTextJazzApi(this, raw),
2924
+ enumerable: false
2925
+ }
2668
2926
  });
2669
2927
  return;
2670
2928
  }
2671
2929
  if ("text" in options && "owner" in options) {
2672
2930
  super(options.text);
2673
- const raw = options.owner._raw.createPlainText(options.text);
2931
+ const raw = options.owner.$jazz.raw.createPlainText(options.text);
2674
2932
  Object.defineProperties(this, {
2675
- id: { value: raw.id, enumerable: false },
2676
- _type: { value: "CoPlainText", enumerable: false },
2677
- _raw: { value: raw, enumerable: false }
2933
+ [TypeSym]: { value: "CoPlainText", enumerable: false },
2934
+ $jazz: {
2935
+ value: new CoTextJazzApi(this, raw),
2936
+ enumerable: false
2937
+ }
2678
2938
  });
2679
2939
  return;
2680
2940
  }
@@ -2693,73 +2953,57 @@ var CoPlainText = class extends String {
2693
2953
  * ```
2694
2954
  *
2695
2955
  * @category Creation
2956
+ * @deprecated Use `co.plainText(...).create` instead.
2696
2957
  */
2697
2958
  static create(text, options) {
2698
2959
  const { owner } = parseCoValueCreateOptions(options);
2699
2960
  return new this({ text, owner });
2700
2961
  }
2701
2962
  get length() {
2702
- return this._raw.toString().length;
2963
+ return this.$jazz.raw.toString().length;
2703
2964
  }
2704
2965
  toString() {
2705
- return this._raw.toString();
2966
+ return this.$jazz.raw.toString();
2706
2967
  }
2707
2968
  valueOf() {
2708
- return this._raw.toString();
2969
+ return this.$jazz.raw.toString();
2709
2970
  }
2710
2971
  toJSON() {
2711
- return this._raw.toString();
2972
+ return this.$jazz.raw.toString();
2712
2973
  }
2713
2974
  [inspect]() {
2714
2975
  return this.toJSON();
2715
2976
  }
2716
2977
  insertBefore(idx, text) {
2717
- this._raw.insertBefore(idx, text);
2978
+ this.$jazz.raw.insertBefore(idx, text);
2718
2979
  }
2719
2980
  insertAfter(idx, text) {
2720
- this._raw.insertAfter(idx, text);
2981
+ this.$jazz.raw.insertAfter(idx, text);
2721
2982
  }
2722
2983
  deleteRange(range) {
2723
- this._raw.deleteRange(range);
2984
+ this.$jazz.raw.deleteRange(range);
2724
2985
  }
2725
2986
  posBefore(idx) {
2726
- return this._raw.mapping.opIDbeforeIdx[idx];
2987
+ return this.$jazz.raw.mapping.opIDbeforeIdx[idx];
2727
2988
  }
2728
2989
  posAfter(idx) {
2729
- return this._raw.mapping.opIDafterIdx[idx];
2990
+ return this.$jazz.raw.mapping.opIDafterIdx[idx];
2730
2991
  }
2731
2992
  idxBefore(pos) {
2732
- return this._raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
2993
+ return this.$jazz.raw.mapping.idxBeforeOpID[stringifyOpID(pos)];
2733
2994
  }
2734
2995
  idxAfter(pos) {
2735
- return this._raw.mapping.idxAfterOpID[stringifyOpID(pos)];
2996
+ return this.$jazz.raw.mapping.idxAfterOpID[stringifyOpID(pos)];
2736
2997
  }
2998
+ /** @category Internals */
2737
2999
  static fromRaw(raw) {
2738
3000
  return new this({ fromRaw: raw });
2739
3001
  }
2740
- /**
2741
- * Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
2742
- *
2743
- * @category Mutation
2744
- */
2745
- applyDiff(other) {
2746
- const current = this._raw.toString();
2747
- const currentGraphemes = this._raw.toGraphemes(current);
2748
- const otherGraphemes = this._raw.toGraphemes(other);
2749
- const patches = [...calcPatch2(currentGraphemes, otherGraphemes)];
2750
- for (const [from, to, insert] of patches.reverse()) {
2751
- if (to > from) {
2752
- this.deleteRange({ from, to });
2753
- }
2754
- if (insert.length > 0) {
2755
- this.insertBefore(from, this._raw.fromGraphemes(insert));
2756
- }
2757
- }
2758
- }
2759
3002
  /**
2760
3003
  * Load a `CoPlainText` with a given ID, as a given account.
2761
3004
  *
2762
3005
  * @category Subscription & Loading
3006
+ * @deprecated Use `co.plainText(...).load` instead.
2763
3007
  */
2764
3008
  static load(id, options) {
2765
3009
  return loadCoValueWithoutMe(this, id, options);
@@ -2768,18 +3012,6 @@ var CoPlainText = class extends String {
2768
3012
  const { options, listener } = parseSubscribeRestArgs(args);
2769
3013
  return subscribeToCoValueWithoutMe(this, id, options, listener);
2770
3014
  }
2771
- /**
2772
- * Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
2773
- *
2774
- * Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
2775
- *
2776
- * Returns an unsubscribe function that you should call when you no longer need updates.
2777
- *
2778
- * @category Subscription & Loading
2779
- **/
2780
- subscribe(listener) {
2781
- return subscribeToExistingCoValue(this, {}, listener);
2782
- }
2783
3015
  /**
2784
3016
  * Allow CoPlainText to behave like a primitive string in most contexts (e.g.,
2785
3017
  * string concatenation, template literals, React rendering, etc.) by implementing
@@ -2792,9 +3024,53 @@ var CoPlainText = class extends String {
2792
3024
  */
2793
3025
  [Symbol.toPrimitive](hint) {
2794
3026
  if (hint === "number") {
2795
- return Number(this._raw.toString());
3027
+ return Number(this.$jazz.raw.toString());
3028
+ }
3029
+ return this.$jazz.raw.toString();
3030
+ }
3031
+ };
3032
+ var CoTextJazzApi = class extends CoValueJazzApi {
3033
+ constructor(coText, raw) {
3034
+ super(coText);
3035
+ this.coText = coText;
3036
+ this.raw = raw;
3037
+ }
3038
+ get id() {
3039
+ return this.raw.id;
3040
+ }
3041
+ get owner() {
3042
+ return getCoValueOwner(this.coText);
3043
+ }
3044
+ /**
3045
+ * Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
3046
+ *
3047
+ * @category Mutation
3048
+ */
3049
+ applyDiff(other) {
3050
+ const current = this.raw.toString();
3051
+ const currentGraphemes = this.raw.toGraphemes(current);
3052
+ const otherGraphemes = this.raw.toGraphemes(other);
3053
+ const patches = [...calcPatch2(currentGraphemes, otherGraphemes)];
3054
+ for (const [from, to, insert] of patches.reverse()) {
3055
+ if (to > from) {
3056
+ this.coText.deleteRange({ from, to });
3057
+ }
3058
+ if (insert.length > 0) {
3059
+ this.coText.insertBefore(from, this.raw.fromGraphemes(insert));
3060
+ }
2796
3061
  }
2797
- return this._raw.toString();
3062
+ }
3063
+ /**
3064
+ * Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
3065
+ *
3066
+ * Works like `CoPlainText.subscribe()`, but you don't need to pass the ID or the account to load as again.
3067
+ *
3068
+ * Returns an unsubscribe function that you should call when you no longer need updates.
3069
+ *
3070
+ * @category Subscription & Loading
3071
+ **/
3072
+ subscribe(listener) {
3073
+ return subscribeToExistingCoValue(this.coText, {}, listener);
2798
3074
  }
2799
3075
  };
2800
3076
 
@@ -2879,10 +3155,12 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
2879
3155
  };
2880
3156
 
2881
3157
  // src/tools/implementation/anonymousJazzAgent.ts
3158
+ var _a;
3159
+ _a = TypeSym;
2882
3160
  var AnonymousJazzAgent = class {
2883
3161
  constructor(node) {
2884
3162
  this.node = node;
2885
- this._type = "Anonymous";
3163
+ this[_a] = "Anonymous";
2886
3164
  }
2887
3165
  };
2888
3166
 
@@ -3099,19 +3377,19 @@ function instantiateRefEncodedWithInit(schema, init, parentOwner) {
3099
3377
  `Cannot automatically create CoValue from value: ${JSON.stringify(init)}. Use the CoValue schema's create() method instead.`
3100
3378
  );
3101
3379
  }
3102
- const node = parentOwner._raw.core.node;
3380
+ const node = parentOwner.$jazz.localNode;
3103
3381
  const rawGroup = node.createGroup();
3104
- const owner = new Group({ fromRaw: rawGroup });
3105
- owner.addMember(parentOwner.castAs(Group));
3382
+ const owner = new Group6({ fromRaw: rawGroup });
3383
+ owner.addMember(parentOwner);
3106
3384
  return schema.ref.create(init, owner);
3107
3385
  }
3108
3386
 
3109
3387
  // src/tools/lib/migration.ts
3110
3388
  function applyCoValueMigrations(instance) {
3111
- const node = instance._raw.core.node;
3389
+ const node = instance.$jazz.raw.core.node;
3112
3390
  const migratedCoValues = node._migratedCoValues ??= /* @__PURE__ */ new Set();
3113
- if ("migrate" in instance && typeof instance.migrate === "function" && instance._type !== "Account" && !migratedCoValues.has(instance.id)) {
3114
- migratedCoValues.add(instance.id);
3391
+ if ("migrate" in instance && typeof instance.migrate === "function" && instance[TypeSym] !== "Account" && !migratedCoValues.has(instance.$jazz.id)) {
3392
+ migratedCoValues.add(instance.$jazz.id);
3115
3393
  const result = instance.migrate?.(instance);
3116
3394
  if (result && "then" in result) {
3117
3395
  throw new Error("Migration function cannot be async");
@@ -3212,19 +3490,34 @@ var JazzError = class _JazzError {
3212
3490
  };
3213
3491
 
3214
3492
  // src/tools/subscribe/utils.ts
3215
- import { RawAccount as RawAccount6 } from "cojson";
3216
- function getOwnerFromRawValue(raw) {
3217
- const owner = raw.group;
3218
- return coValuesCache.get(
3219
- owner,
3220
- () => owner instanceof RawAccount6 ? coValueClassFromCoValueClassOrSchema(
3221
- RegisteredSchemas["Account"]
3222
- ).fromRaw(owner) : RegisteredSchemas["Group"].fromRaw(owner)
3493
+ import { RawAccount as RawAccount3 } from "cojson";
3494
+
3495
+ // src/tools/lib/cache.ts
3496
+ var weakMap = /* @__PURE__ */ new WeakMap();
3497
+ var coValuesCache = {
3498
+ get: (raw, compute) => {
3499
+ const cached = weakMap.get(raw);
3500
+ if (cached) {
3501
+ return cached;
3502
+ }
3503
+ const computed = compute();
3504
+ weakMap.set(raw, computed);
3505
+ return computed;
3506
+ }
3507
+ };
3508
+
3509
+ // src/tools/subscribe/utils.ts
3510
+ function myRoleForRawValue(raw) {
3511
+ const rawOwner = raw.group;
3512
+ const owner = coValuesCache.get(
3513
+ rawOwner,
3514
+ () => rawOwner instanceof RawAccount3 ? RegisteredSchemas["Account"].fromRaw(rawOwner) : RegisteredSchemas["Group"].fromRaw(rawOwner)
3223
3515
  );
3516
+ return accountOrGroupToGroup(owner).myRole();
3224
3517
  }
3225
3518
  function createCoValue(ref2, raw, subscriptionScope) {
3226
3519
  const freshValueInstance = instantiateRefEncodedFromRaw(ref2, raw);
3227
- Object.defineProperty(freshValueInstance, "_subscriptionScope", {
3520
+ Object.defineProperty(freshValueInstance.$jazz, "_subscriptionScope", {
3228
3521
  value: subscriptionScope,
3229
3522
  writable: false,
3230
3523
  enumerable: false,
@@ -3273,7 +3566,7 @@ var SubscriptionScope = class _SubscriptionScope {
3273
3566
  if (this.shouldSendUpdates()) {
3274
3567
  if (this.value.type === "loaded") {
3275
3568
  this.updateValue(
3276
- createCoValue(this.schema, this.value.value._raw, this)
3569
+ createCoValue(this.schema, this.value.value.$jazz.raw, this)
3277
3570
  );
3278
3571
  }
3279
3572
  }
@@ -3334,7 +3627,7 @@ var SubscriptionScope = class _SubscriptionScope {
3334
3627
  return;
3335
3628
  }
3336
3629
  const ruleset = update.core.verified.header.ruleset;
3337
- const hasAccess = ruleset.type !== "ownedByGroup" || getOwnerFromRawValue(update).myRole() !== void 0;
3630
+ const hasAccess = ruleset.type !== "ownedByGroup" || myRoleForRawValue(update) !== void 0;
3338
3631
  if (!hasAccess) {
3339
3632
  if (this.value.type !== "unauthorized") {
3340
3633
  this.updateValue(
@@ -3358,9 +3651,9 @@ var SubscriptionScope = class _SubscriptionScope {
3358
3651
  this.updateValue(createCoValue(this.schema, update, this));
3359
3652
  this.loadChildren();
3360
3653
  } else {
3361
- const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || // Checking the identity of the _raw value makes us cover the cases where the group
3654
+ const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || // Checking the identity of the raw value makes us cover the cases where the group
3362
3655
  // has been updated and the coValues that don't update the totalValidTransactions value (e.g. FileStream)
3363
- this.value.value._raw !== update;
3656
+ this.value.value.$jazz.raw !== update;
3364
3657
  if (this.loadChildren()) {
3365
3658
  this.updateValue(createCoValue(this.schema, update, this));
3366
3659
  } else if (hasChanged) {
@@ -3440,13 +3733,13 @@ var SubscriptionScope = class _SubscriptionScope {
3440
3733
  if (this.value.type !== "loaded") {
3441
3734
  return false;
3442
3735
  }
3443
- return this.value.value._raw.core.verified.isStreaming();
3736
+ return this.value.value.$jazz.raw.core.verified.isStreaming();
3444
3737
  }
3445
3738
  isFileStream() {
3446
3739
  if (this.value.type !== "loaded") {
3447
3740
  return false;
3448
3741
  }
3449
- return this.value.value._raw.core.verified.header.meta?.type === "binary";
3742
+ return this.value.value.$jazz.raw.core.verified.header.meta?.type === "binary";
3450
3743
  }
3451
3744
  triggerUpdate() {
3452
3745
  if (!this.shouldSendUpdates()) return;
@@ -3486,10 +3779,10 @@ var SubscriptionScope = class _SubscriptionScope {
3486
3779
  }
3487
3780
  const value = this.value.value;
3488
3781
  this.silenceUpdates = true;
3489
- if (value._type === "CoMap" || value._type === "Account") {
3782
+ if (value[TypeSym] === "CoMap" || value[TypeSym] === "Account") {
3490
3783
  const map = value;
3491
3784
  this.loadCoMapKey(map, key, true);
3492
- } else if (value._type === "CoList") {
3785
+ } else if (value[TypeSym] === "CoList") {
3493
3786
  const list = value;
3494
3787
  this.loadCoListKey(list, key, true);
3495
3788
  }
@@ -3524,23 +3817,23 @@ var SubscriptionScope = class _SubscriptionScope {
3524
3817
  const depth = typeof resolve !== "object" || resolve === null ? {} : resolve;
3525
3818
  let hasChanged = false;
3526
3819
  const idsToLoad = new Set(this.idsSubscribed);
3527
- const coValueType = value._type;
3820
+ const coValueType = value[TypeSym];
3528
3821
  if (Object.keys(depth).length > 0) {
3529
- if (coValueType === "CoMap" || coValueType === "Account") {
3822
+ if (coValueType === "CoMap" || coValueType === "Account" || coValueType === "Group") {
3530
3823
  const map = value;
3531
- const keys = "$each" in depth ? map._raw.keys() : Object.keys(depth);
3824
+ const keys = "$each" in depth ? map.$jazz.raw.keys() : Object.keys(depth);
3532
3825
  for (const key of keys) {
3533
3826
  const id = this.loadCoMapKey(map, key, depth[key] ?? depth.$each);
3534
3827
  if (id) {
3535
3828
  idsToLoad.add(id);
3536
3829
  }
3537
3830
  }
3538
- } else if (value._type === "CoList") {
3831
+ } else if (value[TypeSym] === "CoList") {
3539
3832
  const list = value;
3540
- const descriptor = list.getItemsDescriptor();
3833
+ const descriptor = list.$jazz.getItemsDescriptor();
3541
3834
  if (descriptor && isRefEncoded(descriptor)) {
3542
- list._raw.processNewTransactions();
3543
- const entries = list._raw.entries();
3835
+ list.$jazz.raw.processNewTransactions();
3836
+ const entries = list.$jazz.raw.entries();
3544
3837
  const keys = "$each" in depth ? Object.keys(entries) : Object.keys(depth);
3545
3838
  for (const key of keys) {
3546
3839
  const id = this.loadCoListKey(list, key, depth[key] ?? depth.$each);
@@ -3549,12 +3842,12 @@ var SubscriptionScope = class _SubscriptionScope {
3549
3842
  }
3550
3843
  }
3551
3844
  }
3552
- } else if (value._type === "CoStream") {
3845
+ } else if (value[TypeSym] === "CoStream") {
3553
3846
  const stream = value;
3554
- const descriptor = stream.getItemsDescriptor();
3847
+ const descriptor = stream.$jazz.getItemsDescriptor();
3555
3848
  if (descriptor && isRefEncoded(descriptor)) {
3556
- for (const session of stream._raw.sessions()) {
3557
- const values = stream._raw.items[session] ?? [];
3849
+ for (const session of stream.$jazz.raw.sessions()) {
3850
+ const values = stream.$jazz.raw.items[session] ?? [];
3558
3851
  for (const [i, item] of values.entries()) {
3559
3852
  const key = `${session}/${i}`;
3560
3853
  if (!depth.$each && !depth[key]) {
@@ -3601,8 +3894,8 @@ var SubscriptionScope = class _SubscriptionScope {
3601
3894
  if (key === "$onError") {
3602
3895
  return void 0;
3603
3896
  }
3604
- const id = map._raw.get(key);
3605
- const descriptor = map.getDescriptor(key);
3897
+ const id = map.$jazz.raw.get(key);
3898
+ const descriptor = map.$jazz.getDescriptor(key);
3606
3899
  if (!descriptor) {
3607
3900
  this.childErrors.set(
3608
3901
  key,
@@ -3639,11 +3932,11 @@ var SubscriptionScope = class _SubscriptionScope {
3639
3932
  return void 0;
3640
3933
  }
3641
3934
  loadCoListKey(list, key, depth) {
3642
- const descriptor = list.getItemsDescriptor();
3935
+ const descriptor = list.$jazz.getItemsDescriptor();
3643
3936
  if (!descriptor || !isRefEncoded(descriptor)) {
3644
3937
  return void 0;
3645
3938
  }
3646
- const entries = list._raw.entries();
3939
+ const entries = list.$jazz.raw.entries();
3647
3940
  const entry = entries[Number(key)];
3648
3941
  if (!entry) {
3649
3942
  return void 0;
@@ -3704,18 +3997,18 @@ var SubscriptionScope = class _SubscriptionScope {
3704
3997
 
3705
3998
  // src/tools/subscribe/index.ts
3706
3999
  function getSubscriptionScope(value) {
3707
- const subscriptionScope = value._subscriptionScope;
4000
+ const subscriptionScope = value.$jazz._subscriptionScope;
3708
4001
  if (subscriptionScope) {
3709
4002
  return subscriptionScope;
3710
4003
  }
3711
- const node = value._raw.core.node;
4004
+ const node = value.$jazz.raw.core.node;
3712
4005
  const resolve = true;
3713
- const id = value.id;
4006
+ const id = value.$jazz.id;
3714
4007
  const newSubscriptionScope = new SubscriptionScope(node, resolve, id, {
3715
4008
  ref: value.constructor,
3716
4009
  optional: false
3717
4010
  });
3718
- Object.defineProperty(value, "_subscriptionScope", {
4011
+ Object.defineProperty(value.$jazz, "_subscriptionScope", {
3719
4012
  value: subscriptionScope,
3720
4013
  writable: false,
3721
4014
  enumerable: false,
@@ -3748,7 +4041,7 @@ function accessChildById(parent, childId, schema) {
3748
4041
 
3749
4042
  // src/tools/implementation/createContext.ts
3750
4043
  import {
3751
- LocalNode as LocalNode2
4044
+ LocalNode as LocalNode3
3752
4045
  } from "cojson";
3753
4046
  async function randomSessionProvider(accountID, crypto) {
3754
4047
  return {
@@ -3772,7 +4065,7 @@ async function createJazzContextFromExistingCredentials({
3772
4065
  );
3773
4066
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
3774
4067
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
3775
- const node = await LocalNode2.withLoadedAccount({
4068
+ const node = await LocalNode3.withLoadedAccount({
3776
4069
  accountID: credentials.accountID,
3777
4070
  accountSecret: credentials.secret,
3778
4071
  sessionID,
@@ -3812,7 +4105,7 @@ async function createJazzContextForNewAccount({
3812
4105
  }) {
3813
4106
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
3814
4107
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
3815
- const { node } = await LocalNode2.withNewlyCreatedAccount({
4108
+ const { node } = await LocalNode3.withNewlyCreatedAccount({
3816
4109
  creationProps,
3817
4110
  peersToLoadFrom,
3818
4111
  crypto,
@@ -3878,7 +4171,7 @@ async function createJazzContext(options) {
3878
4171
  });
3879
4172
  if (!options.newAccountProps) {
3880
4173
  await authSecretStorage.setWithoutNotify({
3881
- accountID: context.account.id,
4174
+ accountID: context.account.$jazz.id,
3882
4175
  secretSeed,
3883
4176
  accountSecret: context.node.getCurrentAgent().agentSecret,
3884
4177
  provider: "anonymous"
@@ -3896,7 +4189,7 @@ function createAnonymousJazzContext({
3896
4189
  storage
3897
4190
  }) {
3898
4191
  const agentSecret = crypto.newRandomAgentSecret();
3899
- const node = new LocalNode2(
4192
+ const node = new LocalNode3(
3900
4193
  agentSecret,
3901
4194
  crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
3902
4195
  crypto
@@ -4938,7 +5231,7 @@ var JazzContextManager = class {
4938
5231
  await this.handleAnonymousAccountMigration(prevContext);
4939
5232
  }
4940
5233
  if (this.context && "me" in this.context) {
4941
- return this.context.me.id;
5234
+ return this.context.me.$jazz.id;
4942
5235
  }
4943
5236
  throw new Error("The registration hasn't created a new account");
4944
5237
  };
@@ -5017,8 +5310,8 @@ var JazzContextManager = class {
5017
5310
  const currentContext = this.context;
5018
5311
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
5019
5312
  const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals5.connectedPeers(
5020
- prevContext.me.id,
5021
- currentContext.me.id,
5313
+ prevContext.me.$jazz.id,
5314
+ currentContext.me.$jazz.id,
5022
5315
  {
5023
5316
  peer1role: "client",
5024
5317
  peer2role: "server"
@@ -5029,7 +5322,7 @@ var JazzContextManager = class {
5029
5322
  prevContext.node.syncManager.addPeer(currentAccountAsPeer);
5030
5323
  try {
5031
5324
  await this.props.onAnonymousAccountDiscarded?.(prevContext.me);
5032
- await prevContext.me.waitForAllCoValuesSync();
5325
+ await prevContext.me.$jazz.waitForAllCoValuesSync();
5033
5326
  } catch (error) {
5034
5327
  console.error("Error onAnonymousAccountDiscarded", error);
5035
5328
  }
@@ -5056,22 +5349,22 @@ function createResolvablePromise() {
5056
5349
  globalThis.devtoolsFormatters = [
5057
5350
  {
5058
5351
  header: (object2) => {
5059
- if (object2._type === "CoMap") {
5352
+ if (object2[TypeSym] === "CoMap") {
5060
5353
  return ["div", {}, ["span", {}, object2.constructor.name]];
5061
- } else if (object2._type === "CoList") {
5354
+ } else if (object2[TypeSym] === "CoList") {
5062
5355
  return [
5063
5356
  "div",
5064
5357
  {},
5065
5358
  ["span", {}, object2.constructor.name + "(" + object2.length + ") "]
5066
5359
  ];
5067
- } else if (object2._type === "Account") {
5360
+ } else if (object2[TypeSym] === "Account") {
5068
5361
  return [
5069
5362
  "div",
5070
5363
  {},
5071
5364
  [
5072
5365
  "span",
5073
5366
  {},
5074
- object2.constructor.name + "(" + object2._refs.profile.value?.name + (object2.isMe ? " ME" : "") + ")"
5367
+ object2.constructor.name + "(" + object2.$jazz.refs.profile.value?.name + (object2.isMe ? " ME" : "") + ")"
5075
5368
  ]
5076
5369
  ];
5077
5370
  } else {
@@ -5082,7 +5375,7 @@ globalThis.devtoolsFormatters = [
5082
5375
  return true;
5083
5376
  },
5084
5377
  body: function(object2) {
5085
- if (object2._type === "CoMap" || object2._type === "Account") {
5378
+ if (object2[TypeSym] === "CoMap" || object2[TypeSym] === "Account") {
5086
5379
  return [
5087
5380
  "div",
5088
5381
  { style: "margin-left: 15px" },
@@ -5097,13 +5390,13 @@ globalThis.devtoolsFormatters = [
5097
5390
  "span",
5098
5391
  { style: "opacity: 0.5" },
5099
5392
  ` (pending ${object2._schema[k].name} `,
5100
- ["object", { object: object2._refs[k] }],
5393
+ ["object", { object: object2.$jazz.refs[k] }],
5101
5394
  ")"
5102
5395
  ]
5103
5396
  ] : [] : []
5104
5397
  ])
5105
5398
  ];
5106
- } else if (object2._type === "CoList") {
5399
+ } else if (object2[TypeSym] === "CoList") {
5107
5400
  return [
5108
5401
  "div",
5109
5402
  { style: "margin-left: 15px" },
@@ -5118,7 +5411,7 @@ globalThis.devtoolsFormatters = [
5118
5411
  "span",
5119
5412
  { style: "opacity: 0.5" },
5120
5413
  ` (pending ${object2._schema[ItemsSym].name} `,
5121
- ["object", { object: object2._refs[i] }],
5414
+ ["object", { object: object2.$jazz.refs[i] }],
5122
5415
  ")"
5123
5416
  ]
5124
5417
  ] : [] : []
@@ -5166,14 +5459,14 @@ function loadCoValue(cls, id, options) {
5166
5459
  async function ensureCoValueLoaded(existing, options) {
5167
5460
  const response = await loadCoValue(
5168
5461
  existing.constructor,
5169
- existing.id,
5462
+ existing.$jazz.id,
5170
5463
  {
5171
- loadAs: existing._loadedAs,
5464
+ loadAs: existing.$jazz.loadedAs,
5172
5465
  resolve: options?.resolve
5173
5466
  }
5174
5467
  );
5175
5468
  if (!response) {
5176
- throw new Error("Failed to deeply load CoValue " + existing.id);
5469
+ throw new Error("Failed to deeply load CoValue " + existing.$jazz.id);
5177
5470
  }
5178
5471
  return response;
5179
5472
  }
@@ -5213,7 +5506,7 @@ function subscribeToCoValueWithoutMe(cls, id, options, listener) {
5213
5506
  }
5214
5507
  function subscribeToCoValue(cls, id, options, listener) {
5215
5508
  const loadAs = options.loadAs ?? activeAccountContext.get();
5216
- const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
5509
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
5217
5510
  const resolve = options.resolve ?? true;
5218
5511
  let unsubscribed = false;
5219
5512
  const rootNode = new SubscriptionScope(
@@ -5258,9 +5551,9 @@ function subscribeToCoValue(cls, id, options, listener) {
5258
5551
  function subscribeToExistingCoValue(existing, options, listener) {
5259
5552
  return subscribeToCoValue(
5260
5553
  existing.constructor,
5261
- existing.id,
5554
+ existing.$jazz.id,
5262
5555
  {
5263
- loadAs: existing._loadedAs,
5556
+ loadAs: existing.$jazz.loadedAs,
5264
5557
  resolve: options?.resolve,
5265
5558
  onUnavailable: options?.onUnavailable,
5266
5559
  onUnauthorized: options?.onUnauthorized
@@ -5272,33 +5565,42 @@ function isAccountInstance(instance) {
5272
5565
  if (typeof instance !== "object" || instance === null) {
5273
5566
  return false;
5274
5567
  }
5275
- return "_type" in instance && instance._type === "Account";
5568
+ return TypeSym in instance && instance[TypeSym] === "Account";
5276
5569
  }
5277
5570
  function parseCoValueCreateOptions(options) {
5278
- const Group10 = RegisteredSchemas["Group"];
5571
+ const Group16 = RegisteredSchemas["Group"];
5279
5572
  if (!options) {
5280
- return { owner: Group10.create(), uniqueness: void 0 };
5573
+ return { owner: Group16.create(), uniqueness: void 0 };
5281
5574
  }
5282
- if ("_type" in options) {
5283
- if (options._type === "Account" || options._type === "Group") {
5575
+ if (TypeSym in options) {
5576
+ if (options[TypeSym] === "Account") {
5577
+ return { owner: accountOrGroupToGroup(options), uniqueness: void 0 };
5578
+ } else if (options[TypeSym] === "Group") {
5284
5579
  return { owner: options, uniqueness: void 0 };
5285
5580
  }
5286
5581
  }
5287
5582
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
5288
- return {
5289
- owner: options.owner ?? Group10.create(),
5583
+ const opts = {
5584
+ owner: options.owner ? accountOrGroupToGroup(options.owner) : Group16.create(),
5290
5585
  uniqueness
5291
5586
  };
5587
+ return opts;
5588
+ }
5589
+ function accountOrGroupToGroup(accountOrGroup) {
5590
+ if (accountOrGroup[TypeSym] === "Group") {
5591
+ return accountOrGroup;
5592
+ }
5593
+ return RegisteredSchemas["Group"].fromRaw(accountOrGroup.$jazz.raw);
5292
5594
  }
5293
5595
  function parseGroupCreateOptions(options) {
5294
5596
  if (!options) {
5295
5597
  return { owner: activeAccountContext.get() };
5296
5598
  }
5297
- return "_type" in options && isAccountInstance(options) ? { owner: options } : { owner: options.owner ?? activeAccountContext.get() };
5599
+ return TypeSym in options && isAccountInstance(options) ? { owner: options } : { owner: options.owner ?? activeAccountContext.get() };
5298
5600
  }
5299
5601
  async function exportCoValue(cls, id, options) {
5300
5602
  const loadAs = options.loadAs ?? activeAccountContext.get();
5301
- const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
5603
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
5302
5604
  const resolve = options.resolve ?? true;
5303
5605
  const rootNode = new SubscriptionScope(
5304
5606
  node,
@@ -5338,7 +5640,7 @@ function loadContentPiecesFromSubscription(subscription, valuesExported, content
5338
5640
  return;
5339
5641
  }
5340
5642
  valuesExported.add(subscription.id);
5341
- const core2 = subscription.getCurrentValue()?._raw.core;
5643
+ const core2 = subscription.getCurrentValue()?.$jazz.raw.core;
5342
5644
  if (core2) {
5343
5645
  loadContentPiecesFromCoValue(core2, valuesExported, contentPieces);
5344
5646
  }
@@ -5364,7 +5666,7 @@ function loadContentPiecesFromCoValue(core2, valuesExported, contentPieces) {
5364
5666
  }
5365
5667
  function importContentPieces(contentPieces, loadAs) {
5366
5668
  const account = loadAs ?? Account.getMe();
5367
- const node = "node" in account ? account.node : account._raw.core.node;
5669
+ const node = "node" in account ? account.node : account.$jazz.localNode;
5368
5670
  for (const piece of contentPieces) {
5369
5671
  node.syncManager.handleNewContent(piece, "import");
5370
5672
  }
@@ -5383,7 +5685,7 @@ export {
5383
5685
  FileStream,
5384
5686
  Account,
5385
5687
  isControlledAccount,
5386
- Group,
5688
+ Group6 as Group,
5387
5689
  Profile,
5388
5690
  isCoValueId,
5389
5691
  Inbox,
@@ -5412,4 +5714,4 @@ export {
5412
5714
  JazzContextManager
5413
5715
  };
5414
5716
  /* istanbul ignore file -- @preserve */
5415
- //# sourceMappingURL=chunk-LZOF6WP5.js.map
5717
+ //# sourceMappingURL=chunk-HJ3GTGY7.js.map