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
@@ -10,10 +10,12 @@ import type {
10
10
  SessionID,
11
11
  } from "cojson";
12
12
  import { cojsonInternals } from "cojson";
13
- import type {
13
+ import {
14
14
  AnonymousJazzAgent,
15
+ CoFieldInit,
15
16
  CoValue,
16
17
  CoValueClass,
18
+ getCoValueOwner,
17
19
  Group,
18
20
  ID,
19
21
  RefsToResolve,
@@ -23,10 +25,12 @@ import type {
23
25
  SchemaFor,
24
26
  SubscribeListenerOptions,
25
27
  SubscribeRestArgs,
28
+ TypeSym,
26
29
  } from "../internal.js";
27
30
  import {
28
31
  Account,
29
32
  CoValueBase,
33
+ CoValueJazzApi,
30
34
  ItemsSym,
31
35
  Ref,
32
36
  SchemaInit,
@@ -81,6 +85,8 @@ export { CoFeed as CoStream };
81
85
  * @category CoValues
82
86
  */
83
87
  export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
88
+ declare $jazz: CoFeedJazzApi<this>;
89
+
84
90
  /**
85
91
  * Declare a `CoFeed` by subclassing `CoFeed.Of(...)` and passing the item schema using a `co` primitive or a `coField.ref`.
86
92
  *
@@ -103,36 +109,25 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
103
109
  return cls;
104
110
  }
105
111
 
106
- /**
107
- * The ID of this `CoFeed`
108
- * @category Content */
109
- declare id: ID<this>;
110
112
  /** @category Type Helpers */
111
- declare _type: "CoStream";
113
+ declare [TypeSym]: "CoStream";
112
114
  static {
113
- this.prototype._type = "CoStream";
115
+ this.prototype[TypeSym] = "CoStream";
114
116
  }
115
- /** @category Internals */
116
- declare _raw: RawCoStream;
117
117
 
118
118
  /** @internal This is only a marker type and doesn't exist at runtime */
119
119
  [ItemsSym]!: Item;
120
120
  /** @internal */
121
121
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
122
  static _schema: any;
123
- /** @internal */
124
- get _schema(): {
125
- [ItemsSym]: SchemaFor<Item> | any;
126
- } {
127
- return (this.constructor as typeof CoFeed)._schema;
128
- }
123
+
129
124
  /**
130
125
  * The current account's view of this `CoFeed`
131
126
  * @category Content
132
127
  */
133
128
  get byMe(): CoFeedEntry<Item> | undefined {
134
- if (this._loadedAs._type === "Account") {
135
- return this.perAccount[this._loadedAs.id];
129
+ if (this.$jazz.loadedAs[TypeSym] === "Account") {
130
+ return this.perAccount[this.$jazz.loadedAs.$jazz.id];
136
131
  } else {
137
132
  return undefined;
138
133
  }
@@ -187,29 +182,23 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
187
182
  * @category Content
188
183
  */
189
184
  get inCurrentSession(): CoFeedEntry<Item> | undefined {
190
- if (this._loadedAs._type === "Account") {
191
- return this.perSession[this._loadedAs.sessionID!];
185
+ if (this.$jazz.loadedAs[TypeSym] === "Account") {
186
+ return this.perSession[this.$jazz.loadedAs.$jazz.sessionID!];
192
187
  } else {
193
188
  return undefined;
194
189
  }
195
190
  }
196
191
 
197
- constructor(
198
- options:
199
- | { init: Item[]; owner: Account | Group }
200
- | { fromRaw: RawCoStream },
201
- ) {
192
+ /** @internal */
193
+ constructor(options: { fromRaw: RawCoStream }) {
202
194
  super();
203
195
 
204
- if (options && "fromRaw" in options) {
205
- Object.defineProperties(this, {
206
- id: {
207
- value: options.fromRaw.id,
208
- enumerable: false,
209
- },
210
- _raw: { value: options.fromRaw, enumerable: false },
211
- });
212
- }
196
+ Object.defineProperties(this, {
197
+ $jazz: {
198
+ value: new CoFeedJazzApi(this, options.fromRaw),
199
+ enumerable: false,
200
+ },
201
+ });
213
202
 
214
203
  return this;
215
204
  }
@@ -217,6 +206,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
217
206
  /**
218
207
  * Create a new `CoFeed`
219
208
  * @category Creation
209
+ * @deprecated Use `co.feed(...).create` instead.
220
210
  */
221
211
  static create<S extends CoFeed>(
222
212
  this: CoValueClass<S>,
@@ -224,95 +214,32 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
224
214
  options?: { owner: Account | Group } | Account | Group,
225
215
  ) {
226
216
  const { owner } = parseCoValueCreateOptions(options);
227
- const instance = new this({ init, owner });
228
- const raw = owner._raw.createStream();
229
-
230
- Object.defineProperties(instance, {
231
- id: {
232
- value: raw.id,
233
- enumerable: false,
234
- },
235
- _raw: { value: raw, enumerable: false },
236
- });
217
+ const raw = owner.$jazz.raw.createStream();
218
+ const instance = new this({ fromRaw: raw });
237
219
 
238
220
  if (init) {
239
- instance.push(...init);
221
+ instance.$jazz.push(...init);
240
222
  }
241
223
  return instance;
242
224
  }
243
225
 
244
- getItemsDescriptor() {
245
- return this._schema?.[ItemsSym];
246
- }
247
-
248
- /**
249
- * Push items to this `CoFeed`
250
- *
251
- * Items are appended to the current session's log. Each session (tab, device, app instance)
252
- * maintains its own append-only log, which is then aggregated into the per-account view.
253
- *
254
- * @example
255
- * ```ts
256
- * // Adds items to current session's log
257
- * feed.push("item1", "item2");
258
- *
259
- * // View items from current session
260
- * console.log(feed.inCurrentSession);
261
- *
262
- * // View aggregated items from all sessions for current account
263
- * console.log(feed.byMe);
264
- * ```
265
- *
266
- * @category Content
267
- */
268
- push(...items: Item[]) {
269
- for (const item of items) {
270
- this.pushItem(item);
271
- }
272
- }
273
-
274
- private pushItem(item: Item) {
275
- const itemDescriptor = this._schema[ItemsSym] as Schema;
276
-
277
- if (itemDescriptor === "json") {
278
- this._raw.push(item as JsonValue);
279
- } else if ("encoded" in itemDescriptor) {
280
- this._raw.push(itemDescriptor.encoded.encode(item));
281
- } else if (isRefEncoded(itemDescriptor)) {
282
- let refId = (item as unknown as CoValue).id;
283
- if (!refId) {
284
- const coValue = instantiateRefEncodedWithInit(
285
- itemDescriptor,
286
- item,
287
- this._owner,
288
- );
289
- refId = coValue.id;
290
- }
291
- this._raw.push(refId);
292
- }
293
- }
294
-
295
226
  /**
296
227
  * Get a JSON representation of the `CoFeed`
297
228
  * @category
298
229
  */
299
230
  toJSON(): {
300
- id: string;
301
- _type: "CoStream";
302
231
  [key: string]: unknown;
303
232
  in: { [key: string]: unknown };
304
233
  } {
305
- const itemDescriptor = this._schema[ItemsSym] as Schema;
234
+ const itemDescriptor = this.$jazz.schema[ItemsSym] as Schema;
306
235
  const mapper =
307
236
  itemDescriptor === "json"
308
237
  ? (v: unknown) => v
309
238
  : "encoded" in itemDescriptor
310
239
  ? itemDescriptor.encoded.encode
311
- : (v: unknown) => v && (v as CoValue).id;
240
+ : (v: unknown) => v && (v as CoValue).$jazz.id;
312
241
 
313
242
  return {
314
- id: this.id,
315
- _type: this._type,
316
243
  ...Object.fromEntries(
317
244
  Object.entries(this).map(([account, entry]) => [
318
245
  account,
@@ -330,8 +257,6 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
330
257
 
331
258
  /** @internal */
332
259
  [inspect](): {
333
- id: string;
334
- _type: "CoStream";
335
260
  [key: string]: unknown;
336
261
  in: { [key: string]: unknown };
337
262
  } {
@@ -342,7 +267,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
342
267
  static schema<V extends CoFeed>(
343
268
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
344
269
  this: { new (...args: any): V } & typeof CoFeed,
345
- def: { [ItemsSym]: V["_schema"][ItemsSym] },
270
+ def: { [ItemsSym]: V["$jazz"]["schema"][ItemsSym] },
346
271
  ) {
347
272
  this._schema ||= {};
348
273
  Object.assign(this._schema, def);
@@ -351,6 +276,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
351
276
  /**
352
277
  * Load a `CoFeed`
353
278
  * @category Subscription & Loading
279
+ * @deprecated Use `co.feed(...).load` instead.
354
280
  */
355
281
  static load<F extends CoFeed, const R extends RefsToResolve<F> = true>(
356
282
  this: CoValueClass<F>,
@@ -366,6 +292,7 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
366
292
  /**
367
293
  * Subscribe to a `CoFeed`, when you have an ID but don't have a `CoFeed` instance yet
368
294
  * @category Subscription & Loading
295
+ * @deprecated Use `co.feed(...).subscribe` instead.
369
296
  */
370
297
  static subscribe<F extends CoFeed, const R extends RefsToResolve<F> = true>(
371
298
  this: CoValueClass<F>,
@@ -386,6 +313,77 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
386
313
  const { options, listener } = parseSubscribeRestArgs(args);
387
314
  return subscribeToCoValueWithoutMe<F, R>(this, id, options, listener);
388
315
  }
316
+ }
317
+
318
+ /** @internal */
319
+ type CoFeedItem<L> = L extends CoFeed<infer Item> ? Item : never;
320
+
321
+ export class CoFeedJazzApi<F extends CoFeed> extends CoValueJazzApi<F> {
322
+ constructor(
323
+ private coFeed: F,
324
+ public raw: RawCoStream,
325
+ ) {
326
+ super(coFeed);
327
+ }
328
+
329
+ /**
330
+ * The ID of this `CoFeed`
331
+ * @category Content
332
+ */
333
+ get id(): ID<F> {
334
+ return this.raw.id;
335
+ }
336
+
337
+ get owner(): Group {
338
+ return getCoValueOwner(this.coFeed);
339
+ }
340
+
341
+ /**
342
+ * Push items to this `CoFeed`
343
+ *
344
+ * Items are appended to the current session's log. Each session (tab, device, app instance)
345
+ * maintains its own append-only log, which is then aggregated into the per-account view.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * // Adds items to current session's log
350
+ * feed.$jazz.push("item1", "item2");
351
+ *
352
+ * // View items from current session
353
+ * console.log(feed.inCurrentSession);
354
+ *
355
+ * // View aggregated items from all sessions for current account
356
+ * console.log(feed.byMe);
357
+ * ```
358
+ *
359
+ * @category Content
360
+ */
361
+ push(...items: CoFieldInit<CoFeedItem<F>>[]): void {
362
+ for (const item of items) {
363
+ this.pushItem(item);
364
+ }
365
+ }
366
+
367
+ private pushItem(item: CoFieldInit<CoFeedItem<F>>) {
368
+ const itemDescriptor = this.schema[ItemsSym] as Schema;
369
+
370
+ if (itemDescriptor === "json") {
371
+ this.raw.push(item as JsonValue);
372
+ } else if ("encoded" in itemDescriptor) {
373
+ this.raw.push(itemDescriptor.encoded.encode(item));
374
+ } else if (isRefEncoded(itemDescriptor)) {
375
+ let refId = (item as unknown as CoValue).$jazz?.id;
376
+ if (!refId) {
377
+ const coValue = instantiateRefEncodedWithInit(
378
+ itemDescriptor,
379
+ item,
380
+ this.owner,
381
+ );
382
+ refId = coValue.$jazz.id;
383
+ }
384
+ this.raw.push(refId);
385
+ }
386
+ }
389
387
 
390
388
  /**
391
389
  * Ensure a `CoFeed` is loaded to the specified depth
@@ -394,10 +392,10 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
394
392
  * @category Subscription & Loading
395
393
  */
396
394
  ensureLoaded<F extends CoFeed, const R extends RefsToResolve<F>>(
397
- this: F,
395
+ this: CoFeedJazzApi<F>,
398
396
  options?: { resolve?: RefsToResolveStrict<F, R> },
399
397
  ): Promise<Resolved<F, R>> {
400
- return ensureCoValueLoaded(this, options);
398
+ return ensureCoValueLoaded(this.coFeed, options);
401
399
  }
402
400
 
403
401
  /**
@@ -407,20 +405,20 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
407
405
  * @category Subscription & Loading
408
406
  */
409
407
  subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
410
- this: F,
408
+ this: CoFeedJazzApi<F>,
411
409
  listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
412
410
  ): () => void;
413
411
  subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
414
- this: F,
412
+ this: CoFeedJazzApi<F>,
415
413
  options: { resolve?: RefsToResolveStrict<F, R> },
416
414
  listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
417
415
  ): () => void;
418
416
  subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
419
- this: F,
417
+ this: CoFeedJazzApi<F>,
420
418
  ...args: SubscribeRestArgs<F, R>
421
419
  ): () => void {
422
420
  const { options, listener } = parseSubscribeRestArgs(args);
423
- return subscribeToExistingCoValue(this, options, listener);
421
+ return subscribeToExistingCoValue(this.coFeed, options, listener);
424
422
  }
425
423
 
426
424
  /**
@@ -429,7 +427,22 @@ export class CoFeed<out Item = any> extends CoValueBase implements CoValue {
429
427
  * @category Subscription & Loading
430
428
  */
431
429
  waitForSync(options?: { timeout?: number }) {
432
- return this._raw.core.waitForSync(options);
430
+ return this.raw.core.waitForSync(options);
431
+ }
432
+
433
+ /**
434
+ * Get the descriptor for the items in the `CoFeed`
435
+ * @internal
436
+ */
437
+ getItemsDescriptor(): Schema | undefined {
438
+ return this.schema[ItemsSym];
439
+ }
440
+
441
+ /** @internal */
442
+ get schema(): {
443
+ [ItemsSym]: SchemaFor<CoFeedItem<F>> | any;
444
+ } {
445
+ return (this.coFeed.constructor as typeof CoFeed)._schema;
433
446
  }
434
447
  }
435
448
 
@@ -507,20 +520,22 @@ export const CoStreamPerAccountProxyHandler = (
507
520
  ): ProxyHandler<{}> => ({
508
521
  get(_target, key, receiver) {
509
522
  if (typeof key === "string" && key.startsWith("co_")) {
510
- const rawEntry = innerTarget._raw.lastItemBy(key as RawAccountID);
523
+ const rawEntry = innerTarget.$jazz.raw.lastItemBy(key as RawAccountID);
511
524
 
512
525
  if (!rawEntry) return;
513
526
  const entry = entryFromRawEntry(
514
527
  receiver,
515
528
  rawEntry,
516
- innerTarget._loadedAs,
529
+ innerTarget.$jazz.loadedAs,
517
530
  key as unknown as ID<Account>,
518
- innerTarget._schema[ItemsSym],
531
+ innerTarget.$jazz.schema[ItemsSym],
519
532
  );
520
533
 
521
534
  Object.defineProperty(entry, "all", {
522
535
  get: () => {
523
- const allRawEntries = innerTarget._raw.itemsBy(key as RawAccountID);
536
+ const allRawEntries = innerTarget.$jazz.raw.itemsBy(
537
+ key as RawAccountID,
538
+ );
524
539
  return (function* () {
525
540
  while (true) {
526
541
  const rawEntry = allRawEntries.next();
@@ -528,9 +543,9 @@ export const CoStreamPerAccountProxyHandler = (
528
543
  yield entryFromRawEntry(
529
544
  receiver,
530
545
  rawEntry.value,
531
- innerTarget._loadedAs,
546
+ innerTarget.$jazz.loadedAs,
532
547
  key as unknown as ID<Account>,
533
- innerTarget._schema[ItemsSym],
548
+ innerTarget.$jazz.schema[ItemsSym],
534
549
  );
535
550
  }
536
551
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -544,7 +559,7 @@ export const CoStreamPerAccountProxyHandler = (
544
559
  }
545
560
  },
546
561
  ownKeys(_target) {
547
- return Array.from(innerTarget._raw.accounts());
562
+ return Array.from(innerTarget.$jazz.raw.accounts());
548
563
  },
549
564
  getOwnPropertyDescriptor(_target, key) {
550
565
  if (typeof key === "string" && key.startsWith("co_")) {
@@ -570,7 +585,7 @@ const CoStreamPerSessionProxyHandler = (
570
585
  get(_target, key, receiver) {
571
586
  if (typeof key === "string" && key.includes("session")) {
572
587
  const sessionID = key as SessionID;
573
- const rawEntry = innerTarget._raw.lastItemIn(sessionID);
588
+ const rawEntry = innerTarget.$jazz.raw.lastItemIn(sessionID);
574
589
 
575
590
  if (!rawEntry) return;
576
591
  const by = cojsonInternals.accountOrAgentIDfromSessionID(sessionID);
@@ -578,16 +593,16 @@ const CoStreamPerSessionProxyHandler = (
578
593
  const entry = entryFromRawEntry(
579
594
  accessFrom,
580
595
  rawEntry,
581
- innerTarget._loadedAs,
596
+ innerTarget.$jazz.loadedAs,
582
597
  cojsonInternals.isAccountID(by)
583
598
  ? (by as unknown as ID<Account>)
584
599
  : undefined,
585
- innerTarget._schema[ItemsSym],
600
+ innerTarget.$jazz.schema[ItemsSym],
586
601
  );
587
602
 
588
603
  Object.defineProperty(entry, "all", {
589
604
  get: () => {
590
- const allRawEntries = innerTarget._raw.itemsIn(sessionID);
605
+ const allRawEntries = innerTarget.$jazz.raw.itemsIn(sessionID);
591
606
  return (function* () {
592
607
  while (true) {
593
608
  const rawEntry = allRawEntries.next();
@@ -595,11 +610,11 @@ const CoStreamPerSessionProxyHandler = (
595
610
  yield entryFromRawEntry(
596
611
  accessFrom,
597
612
  rawEntry.value,
598
- innerTarget._loadedAs,
613
+ innerTarget.$jazz.loadedAs,
599
614
  cojsonInternals.isAccountID(by)
600
615
  ? (by as unknown as ID<Account>)
601
616
  : undefined,
602
- innerTarget._schema[ItemsSym],
617
+ innerTarget.$jazz.schema[ItemsSym],
603
618
  );
604
619
  }
605
620
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -613,7 +628,7 @@ const CoStreamPerSessionProxyHandler = (
613
628
  }
614
629
  },
615
630
  ownKeys() {
616
- return innerTarget._raw.sessions();
631
+ return innerTarget.$jazz.raw.sessions();
617
632
  },
618
633
  getOwnPropertyDescriptor(target, key) {
619
634
  if (typeof key === "string" && key.startsWith("co_")) {
@@ -648,15 +663,10 @@ export { FileStream as BinaryCoStream };
648
663
  * @category CoValues
649
664
  */
650
665
  export class FileStream extends CoValueBase implements CoValue {
651
- /**
652
- * The ID of this `FileStream`
653
- * @category Content
654
- */
655
- declare id: ID<this>;
666
+ declare $jazz: FileStreamJazzApi<this>;
667
+
656
668
  /** @category Type Helpers */
657
- declare _type: "BinaryCoStream";
658
- /** @internal */
659
- declare _raw: RawBinaryCoStream;
669
+ declare [TypeSym]: "BinaryCoStream";
660
670
 
661
671
  constructor(
662
672
  options:
@@ -674,17 +684,16 @@ export class FileStream extends CoValueBase implements CoValue {
674
684
  if ("fromRaw" in options) {
675
685
  raw = options.fromRaw;
676
686
  } else {
677
- const rawOwner = options.owner._raw;
687
+ const rawOwner = options.owner.$jazz.raw;
678
688
  raw = rawOwner.createBinaryStream();
679
689
  }
680
690
 
681
691
  Object.defineProperties(this, {
682
- id: {
683
- value: raw.id,
692
+ [TypeSym]: { value: "BinaryCoStream", enumerable: false },
693
+ $jazz: {
694
+ value: new FileStreamJazzApi(this, raw),
684
695
  enumerable: false,
685
696
  },
686
- _type: { value: "BinaryCoStream", enumerable: false },
687
- _raw: { value: raw, enumerable: false },
688
697
  });
689
698
  }
690
699
 
@@ -710,6 +719,7 @@ export class FileStream extends CoValueBase implements CoValue {
710
719
  * For uploading an existing file or blob, use {@link FileStream.createFromBlob} instead.
711
720
  *
712
721
  * @category Creation
722
+ * @deprecated Use `co.fileStream(...).create` instead.
713
723
  */
714
724
  static create<S extends FileStream>(
715
725
  this: CoValueClass<S>,
@@ -719,7 +729,7 @@ export class FileStream extends CoValueBase implements CoValue {
719
729
  }
720
730
 
721
731
  getMetadata(): BinaryStreamInfo | undefined {
722
- return this._raw.getBinaryStreamInfo();
732
+ return this.$jazz.raw.getBinaryStreamInfo();
723
733
  }
724
734
 
725
735
  getChunks(options?: {
@@ -727,23 +737,23 @@ export class FileStream extends CoValueBase implements CoValue {
727
737
  }):
728
738
  | (BinaryStreamInfo & { chunks: Uint8Array[]; finished: boolean })
729
739
  | undefined {
730
- return this._raw.getBinaryChunks(options?.allowUnfinished);
740
+ return this.$jazz.raw.getBinaryChunks(options?.allowUnfinished);
731
741
  }
732
742
 
733
743
  isBinaryStreamEnded(): boolean {
734
- return this._raw.isBinaryStreamEnded();
744
+ return this.$jazz.raw.isBinaryStreamEnded();
735
745
  }
736
746
 
737
747
  start(options: BinaryStreamInfo): void {
738
- this._raw.startBinaryStream(options);
748
+ this.$jazz.raw.startBinaryStream(options);
739
749
  }
740
750
 
741
751
  push(data: Uint8Array): void {
742
- this._raw.pushBinaryStreamChunk(data);
752
+ this.$jazz.raw.pushBinaryStreamChunk(data);
743
753
  }
744
754
 
745
755
  end(): void {
746
- this._raw.endBinaryStream();
756
+ this.$jazz.raw.endBinaryStream();
747
757
  }
748
758
 
749
759
  toBlob(options?: { allowUnfinished?: boolean }): Blob | undefined {
@@ -763,6 +773,7 @@ export class FileStream extends CoValueBase implements CoValue {
763
773
  * Load a `FileStream` as a `Blob`
764
774
  *
765
775
  * @category Content
776
+ * @deprecated Use `co.fileStream(...).loadAsBlob` instead.
766
777
  */
767
778
  static async loadAsBlob(
768
779
  id: ID<FileStream>,
@@ -826,12 +837,13 @@ export class FileStream extends CoValueBase implements CoValue {
826
837
  * const fileStream = await FileStream.createFromBlob(file, {owner: group})
827
838
  * ```
828
839
  * @category Content
840
+ * @deprecated Use `co.fileStream(...).createFromBlob` instead.
829
841
  */
830
842
  static async createFromBlob(
831
843
  blob: Blob | File,
832
844
  options?:
833
845
  | {
834
- owner?: Group | Account;
846
+ owner?: Account | Group;
835
847
  onProgress?: (progress: number) => void;
836
848
  }
837
849
  | Account
@@ -856,6 +868,7 @@ export class FileStream extends CoValueBase implements CoValue {
856
868
  * const fileStream = await FileStream.createFromBlob(file, {owner: group})
857
869
  * ```
858
870
  * @category Content
871
+ * @deprecated Use `co.fileStream(...).createFromArrayBuffer` instead.
859
872
  */
860
873
  static async createFromArrayBuffer(
861
874
  arrayBuffer: ArrayBuffer,
@@ -863,7 +876,7 @@ export class FileStream extends CoValueBase implements CoValue {
863
876
  fileName: string | undefined,
864
877
  options?:
865
878
  | {
866
- owner?: Group | Account;
879
+ owner?: Account | Group;
867
880
  onProgress?: (progress: number) => void;
868
881
  }
869
882
  | Account
@@ -915,8 +928,6 @@ export class FileStream extends CoValueBase implements CoValue {
915
928
  * @category Content
916
929
  */
917
930
  toJSON(): {
918
- id: string;
919
- _type: "BinaryCoStream";
920
931
  mimeType?: string;
921
932
  totalSizeBytes?: number;
922
933
  fileName?: string;
@@ -924,8 +935,6 @@ export class FileStream extends CoValueBase implements CoValue {
924
935
  finished?: boolean;
925
936
  } {
926
937
  return {
927
- id: this.id,
928
- _type: this._type,
929
938
  ...this.getChunks(),
930
939
  };
931
940
  }
@@ -938,6 +947,7 @@ export class FileStream extends CoValueBase implements CoValue {
938
947
  /**
939
948
  * Load a `FileStream`
940
949
  * @category Subscription & Loading
950
+ * @deprecated Use `co.fileStream(...).load` instead.
941
951
  */
942
952
  static async load<C extends FileStream>(
943
953
  this: CoValueClass<C>,
@@ -975,6 +985,7 @@ export class FileStream extends CoValueBase implements CoValue {
975
985
  /**
976
986
  * Subscribe to a `FileStream`, when you have an ID but don't have a `FileStream` instance yet
977
987
  * @category Subscription & Loading
988
+ * @deprecated Use `co.fileStream(...).subscribe` instead.
978
989
  */
979
990
  static subscribe<F extends FileStream, const R extends RefsToResolve<F>>(
980
991
  this: CoValueClass<F>,
@@ -995,16 +1006,37 @@ export class FileStream extends CoValueBase implements CoValue {
995
1006
  const { options, listener } = parseSubscribeRestArgs(args);
996
1007
  return subscribeToCoValueWithoutMe<F, R>(this, id, options, listener);
997
1008
  }
1009
+ }
1010
+
1011
+ export class FileStreamJazzApi<F extends FileStream> extends CoValueJazzApi<F> {
1012
+ constructor(
1013
+ private fileStream: F,
1014
+ public raw: RawBinaryCoStream,
1015
+ ) {
1016
+ super(fileStream);
1017
+ }
1018
+
1019
+ /**
1020
+ * The ID of this `FileStream`
1021
+ * @category Content
1022
+ */
1023
+ get id(): ID<F> {
1024
+ return this.raw.id;
1025
+ }
1026
+
1027
+ get owner(): Group {
1028
+ return getCoValueOwner(this.fileStream);
1029
+ }
998
1030
 
999
1031
  /**
1000
1032
  * An instance method to subscribe to an existing `FileStream`
1001
1033
  * @category Subscription & Loading
1002
1034
  */
1003
1035
  subscribe<B extends FileStream>(
1004
- this: B,
1036
+ this: FileStreamJazzApi<B>,
1005
1037
  listener: (value: Resolved<B, true>) => void,
1006
1038
  ): () => void {
1007
- return subscribeToExistingCoValue(this, {}, listener);
1039
+ return subscribeToExistingCoValue(this.fileStream, {}, listener);
1008
1040
  }
1009
1041
 
1010
1042
  /**
@@ -1013,6 +1045,6 @@ export class FileStream extends CoValueBase implements CoValue {
1013
1045
  * @category Subscription & Loading
1014
1046
  */
1015
1047
  waitForSync(options?: { timeout?: number }) {
1016
- return this._raw.core.waitForSync(options);
1048
+ return this.raw.core.waitForSync(options);
1017
1049
  }
1018
1050
  }