jazz-tools 0.9.1 → 0.9.8

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.
@@ -4,6 +4,8 @@ import {
4
4
  CoFeed,
5
5
  CoList,
6
6
  CoMap,
7
+ CoPlainText,
8
+ CoRichText,
7
9
  CoValueBase,
8
10
  Encoders,
9
11
  FileStream,
@@ -11,6 +13,7 @@ import {
11
13
  ImageDefinition,
12
14
  Inbox,
13
15
  InboxSender,
16
+ Marks,
14
17
  Profile,
15
18
  SchemaUnion,
16
19
  co,
@@ -23,7 +26,7 @@ import {
23
26
  loadCoValue,
24
27
  randomSessionProvider,
25
28
  subscribeToCoValue
26
- } from "./chunk-7LENDMTN.js";
29
+ } from "./chunk-YD32FKHW.js";
27
30
 
28
31
  // src/index.native.ts
29
32
  import {
@@ -37,6 +40,8 @@ export {
37
40
  CoFeed,
38
41
  CoList,
39
42
  CoMap,
43
+ CoPlainText,
44
+ CoRichText,
40
45
  CoFeed as CoStream,
41
46
  CoValueBase,
42
47
  Encoders,
@@ -46,6 +51,7 @@ export {
46
51
  Inbox,
47
52
  InboxSender,
48
53
  MAX_RECOMMENDED_TX_SIZE,
54
+ Marks,
49
55
  Profile,
50
56
  SchemaUnion,
51
57
  co,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.native.ts"],"sourcesContent":["export * from \"./exports.js\";\n\nexport {\n MAX_RECOMMENDED_TX_SIZE,\n cojsonInternals,\n} from \"cojson/native\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OACK;","names":[]}
1
+ {"version":3,"sources":["../src/index.native.ts"],"sourcesContent":["export * from \"./exports.js\";\n\nexport {\n MAX_RECOMMENDED_TX_SIZE,\n cojsonInternals,\n} from \"cojson/native\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OACK;","names":[]}
package/dist/index.web.js CHANGED
@@ -4,6 +4,8 @@ import {
4
4
  CoFeed,
5
5
  CoList,
6
6
  CoMap,
7
+ CoPlainText,
8
+ CoRichText,
7
9
  CoValueBase,
8
10
  Encoders,
9
11
  FileStream,
@@ -11,6 +13,7 @@ import {
11
13
  ImageDefinition,
12
14
  Inbox,
13
15
  InboxSender,
16
+ Marks,
14
17
  Profile,
15
18
  SchemaUnion,
16
19
  co,
@@ -23,7 +26,7 @@ import {
23
26
  loadCoValue,
24
27
  randomSessionProvider,
25
28
  subscribeToCoValue
26
- } from "./chunk-7LENDMTN.js";
29
+ } from "./chunk-YD32FKHW.js";
27
30
 
28
31
  // src/index.web.ts
29
32
  import { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto } from "cojson";
@@ -34,6 +37,8 @@ export {
34
37
  CoFeed,
35
38
  CoList,
36
39
  CoMap,
40
+ CoPlainText,
41
+ CoRichText,
37
42
  CoFeed as CoStream,
38
43
  CoValueBase,
39
44
  Encoders,
@@ -43,6 +48,7 @@ export {
43
48
  Inbox,
44
49
  InboxSender,
45
50
  MAX_RECOMMENDED_TX_SIZE,
51
+ Marks,
46
52
  Profile,
47
53
  SchemaUnion,
48
54
  WasmCrypto,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.web.ts"],"sourcesContent":["export * from \"./exports.js\";\n\nexport { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto } from \"cojson\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,iBAAiB,yBAAyB,kBAAkB;","names":[]}
1
+ {"version":3,"sources":["../src/index.web.ts"],"sourcesContent":["export * from \"./exports.js\";\n\nexport { cojsonInternals, MAX_RECOMMENDED_TX_SIZE, WasmCrypto } from \"cojson\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,iBAAiB,yBAAyB,kBAAkB;","names":[]}
package/dist/testing.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  Account,
3
+ activeAccountContext,
3
4
  createAnonymousJazzContext
4
- } from "./chunk-7LENDMTN.js";
5
+ } from "./chunk-YD32FKHW.js";
5
6
 
6
7
  // src/testing.ts
7
8
  import { cojsonInternals } from "cojson";
@@ -27,8 +28,14 @@ async function createJazzTestAccount(options) {
27
28
  },
28
29
  crypto: await TestJSCrypto.create()
29
30
  });
31
+ if (options?.isCurrentActiveAccount) {
32
+ activeAccountContext.set(account);
33
+ }
30
34
  return account;
31
35
  }
36
+ function setActiveAccount(account) {
37
+ activeAccountContext.set(account);
38
+ }
32
39
  async function createJazzTestGuest() {
33
40
  const ctx = await createAnonymousJazzContext({
34
41
  crypto: await PureJSCrypto.create(),
@@ -66,6 +73,7 @@ export {
66
73
  createJazzTestAccount,
67
74
  createJazzTestGuest,
68
75
  getJazzContextShape,
69
- linkAccounts
76
+ linkAccounts,
77
+ setActiveAccount
70
78
  };
71
79
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import { AgentSecret, CryptoProvider, Peer } from \"cojson\";\nimport { cojsonInternals } from \"cojson\";\nimport { PureJSCrypto } from \"cojson/crypto\";\nimport { Account, type AccountClass } from \"./exports.js\";\nimport {\n type AnonymousJazzAgent,\n type CoValueClass,\n createAnonymousJazzContext,\n} from \"./internal.js\";\n\ntype TestAccountSchema<Acc extends Account> = CoValueClass<Acc> & {\n fromNode: (typeof Account)[\"fromNode\"];\n create: (options: {\n creationProps: { name: string };\n initialAgentSecret?: AgentSecret;\n peersToLoadFrom?: Peer[];\n crypto: CryptoProvider;\n }) => Promise<Acc>;\n};\n\nclass TestJSCrypto extends PureJSCrypto {\n static async create() {\n if (\"navigator\" in globalThis && navigator.userAgent.includes(\"jsdom\")) {\n // Mocking crypto seal & encrypt to make it work with JSDom. Getting \"Error: Uint8Array expected\" there\n const crypto = new PureJSCrypto();\n\n crypto.seal = (options) =>\n `sealed_U${cojsonInternals.stableStringify(options.message)}` as any;\n crypto.unseal = (sealed) =>\n JSON.parse(sealed.substring(\"sealed_U\".length));\n crypto.encrypt = (message) =>\n `encrypted_U${cojsonInternals.stableStringify(message)}` as any;\n crypto.decryptRaw = (encrypted) =>\n encrypted.substring(\"encrypted_U\".length) as any;\n\n return crypto;\n }\n\n // For non-jsdom environments, we use the real crypto\n return new PureJSCrypto();\n }\n}\n\nexport async function createJazzTestAccount<Acc extends Account>(options?: {\n AccountSchema?: CoValueClass<Acc>;\n}): Promise<Acc> {\n const AccountSchema = (options?.AccountSchema ??\n Account) as unknown as TestAccountSchema<Acc>;\n const account = await AccountSchema.create({\n creationProps: {\n name: \"Test Account\",\n },\n crypto: await TestJSCrypto.create(),\n });\n\n return account;\n}\n\nexport async function createJazzTestGuest() {\n const ctx = await createAnonymousJazzContext({\n crypto: await PureJSCrypto.create(),\n peersToLoadFrom: [],\n });\n\n return {\n guest: ctx.agent,\n };\n}\n\nexport function getJazzContextShape<Acc extends Account>(\n account: Acc | { guest: AnonymousJazzAgent },\n) {\n if (\"guest\" in account) {\n return {\n guest: account.guest,\n AccountSchema: Account,\n logOut: () => account.guest.node.gracefulShutdown(),\n done: () => account.guest.node.gracefulShutdown(),\n };\n }\n\n return {\n me: account,\n AccountSchema: account.constructor as AccountClass<Acc>,\n logOut: () => account._raw.core.node.gracefulShutdown(),\n done: () => account._raw.core.node.gracefulShutdown(),\n };\n}\n\nexport function linkAccounts(\n a: Account,\n b: Account,\n aRole: \"server\" | \"client\" = \"server\",\n bRole: \"server\" | \"client\" = \"server\",\n) {\n const [aPeer, bPeer] = cojsonInternals.connectedPeers(b.id, a.id, {\n peer1role: aRole,\n peer2role: bRole,\n });\n\n a._raw.core.node.syncManager.addPeer(aPeer);\n b._raw.core.node.syncManager.addPeer(bPeer);\n}\n"],"mappings":";;;;;;AACA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAkB7B,IAAM,eAAN,cAA2B,aAAa;AAAA,EACtC,aAAa,SAAS;A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,SAAS,aACd,GACA,GACA,QAA6B,UAC7B,QAA6B,UAC7B;AACA,QAAM,CAAC,OAAO,KAAK,IAAI,gBAAgB,eAAe,EAAE,IAAI,EAAE,IAAI;AAAA,IAChE,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AAED,IAAE,KAAK,KAAK,KAAK,YAAY,QAAQ,KAAK;AAC1C,IAAE,KAAK,KAAK,KAAK,YAAY,QAAQ,KAAK;AAC5C;","names":[]}
1
+ {"version":3,"sources":["../src/testing.ts"],"sourcesContent":["import { AgentSecret, CryptoProvider, Peer } from \"cojson\";\nimport { cojsonInternals } from \"cojson\";\nimport { PureJSCrypto } from \"cojson/crypto\";\nimport { Account, type AccountClass } from \"./exports.js\";\nimport { activeAccountContext } from \"./implementation/activeAccountContext.js\";\nimport {\n type AnonymousJazzAgent,\n type CoValueClass,\n createAnonymousJazzContext,\n} from \"./internal.js\";\n\ntype TestAccountSchema<Acc extends Account> = CoValueClass<Acc> & {\n fromNode: (typeof Account)[\"fromNode\"];\n create: (options: {\n creationProps: { name: string };\n initialAgentSecret?: AgentSecret;\n peersToLoadFrom?: Peer[];\n crypto: CryptoProvider;\n }) => Promise<Acc>;\n};\n\nclass TestJSCrypto extends PureJSCrypto {\n static async create() {\n if (\"navigator\" in globalThis && navigator.userAgent.includes(\"jsdom\")) {\n // Mocking crypto seal & encrypt to make it work with JSDom. Getting \"Error: Uint8Array expected\" there\n const crypto = new PureJSCrypto();\n\n crypto.seal = (options) =>\n `sealed_U${cojsonInternals.stableStringify(options.message)}` as any;\n crypto.unseal = (sealed) =>\n JSON.parse(sealed.substring(\"sealed_U\".length));\n crypto.encrypt = (message) =>\n `encrypted_U${cojsonInternals.stableStringify(message)}` as any;\n crypto.decryptRaw = (encrypted) =>\n encrypted.substring(\"encrypted_U\".length) as any;\n\n return crypto;\n }\n\n // For non-jsdom environments, we use the real crypto\n return new PureJSCrypto();\n }\n}\n\nexport async function createJazzTestAccount<Acc extends Account>(options?: {\n isCurrentActiveAccount?: boolean;\n AccountSchema?: CoValueClass<Acc>;\n}): Promise<Acc> {\n const AccountSchema = (options?.AccountSchema ??\n Account) as unknown as TestAccountSchema<Acc>;\n const account = await AccountSchema.create({\n creationProps: {\n name: \"Test Account\",\n },\n crypto: await TestJSCrypto.create(),\n });\n if (options?.isCurrentActiveAccount) {\n activeAccountContext.set(account);\n }\n\n return account;\n}\n\nexport function setActiveAccount(account: Account) {\n activeAccountContext.set(account);\n}\n\nexport async function createJazzTestGuest() {\n const ctx = await createAnonymousJazzContext({\n crypto: await PureJSCrypto.create(),\n peersToLoadFrom: [],\n });\n\n return {\n guest: ctx.agent,\n };\n}\n\nexport function getJazzContextShape<Acc extends Account>(\n account: Acc | { guest: AnonymousJazzAgent },\n) {\n if (\"guest\" in account) {\n return {\n guest: account.guest,\n AccountSchema: Account,\n logOut: () => account.guest.node.gracefulShutdown(),\n done: () => account.guest.node.gracefulShutdown(),\n };\n }\n\n return {\n me: account,\n AccountSchema: account.constructor as AccountClass<Acc>,\n logOut: () => account._raw.core.node.gracefulShutdown(),\n done: () => account._raw.core.node.gracefulShutdown(),\n };\n}\n\nexport function linkAccounts(\n a: Account,\n b: Account,\n aRole: \"server\" | \"client\" = \"server\",\n bRole: \"server\" | \"client\" = \"server\",\n) {\n const [aPeer, bPeer] = cojsonInternals.connectedPeers(b.id, a.id, {\n peer1role: aRole,\n peer2role: bRole,\n });\n\n a._raw.core.node.syncManager.addPeer(aPeer);\n b._raw.core.node.syncManager.addPeer(bPeer);\n}\n"],"mappings":";;;;;;;AACA,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAmB7B,IAAM,eAAN,cAA2B,aAAa;AAAA,EACtC,aAAa,SAAS;AACpB,QAAI,eAAe,cAAc,UAAU,UAAU,SAAS,OAAO,GAAG;AAEtE,YAAM,SAAS,IAAI,aAAa;AAEhC,aAAO,OAAO,CAAC,YACb,WAAW,gBAAgB,gBAAgB,QAAQ,OAAO,CAAC;AAC7D,aAAO,SAAS,C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ACA,QAAM,CAAC,OAAO,KAAK,IAAI,gBAAgB,eAAe,EAAE,IAAI,EAAE,IAAI;AAAA,IAChE,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AAED,IAAE,KAAK,KAAK,KAAK,YAAY,QAAQ,KAAK;AAC1C,IAAE,KAAK,KAAK,KAAK,YAAY,QAAQ,KAAK;AAC5C;","names":[]}
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "type": "module",
25
25
  "license": "MIT",
26
- "version": "0.9.1",
26
+ "version": "0.9.8",
27
27
  "dependencies": {
28
28
  "cojson": "0.9.0"
29
29
  },
@@ -12,6 +12,7 @@ import {
12
12
  SessionID,
13
13
  cojsonInternals,
14
14
  } from "cojson";
15
+ import { activeAccountContext } from "../implementation/activeAccountContext.js";
15
16
  import {
16
17
  AnonymousJazzAgent,
17
18
  type CoValue,
@@ -29,7 +30,8 @@ import {
29
30
  ensureCoValueLoaded,
30
31
  inspect,
31
32
  loadCoValue,
32
- subscribeToCoValue,
33
+ loadCoValueWithoutMe,
34
+ subscribeToCoValueWithoutMe,
33
35
  subscribeToExistingCoValue,
34
36
  subscriptionsScopes,
35
37
  } from "../internal.js";
@@ -192,6 +194,10 @@ export class Account extends CoValueBase implements CoValue {
192
194
  return this.fromNode(node) as A;
193
195
  }
194
196
 
197
+ static getMe<A extends Account>(this: CoValueClass<A> & typeof Account) {
198
+ return activeAccountContext.get() as A;
199
+ }
200
+
195
201
  static async createAs<A extends Account>(
196
202
  this: CoValueClass<A> & typeof Account,
197
203
  as: Account,
@@ -266,24 +272,56 @@ export class Account extends CoValueBase implements CoValue {
266
272
  }
267
273
 
268
274
  /** @category Subscription & Loading */
275
+ static load<A extends Account, Depth>(
276
+ this: CoValueClass<A>,
277
+ id: ID<A>,
278
+ depth: Depth & DepthsIn<A>,
279
+ ): Promise<DeeplyLoaded<A, Depth> | undefined>;
269
280
  static load<A extends Account, Depth>(
270
281
  this: CoValueClass<A>,
271
282
  id: ID<A>,
272
283
  as: Account,
273
284
  depth: Depth & DepthsIn<A>,
285
+ ): Promise<DeeplyLoaded<A, Depth> | undefined>;
286
+ static load<A extends Account, Depth>(
287
+ this: CoValueClass<A>,
288
+ id: ID<A>,
289
+ asOrDepth: Account | (Depth & DepthsIn<A>),
290
+ depth?: Depth & DepthsIn<A>,
274
291
  ): Promise<DeeplyLoaded<A, Depth> | undefined> {
275
- return loadCoValue(this, id, as, depth);
292
+ return loadCoValueWithoutMe(this, id, asOrDepth, depth);
276
293
  }
277
294
 
278
295
  /** @category Subscription & Loading */
296
+ static subscribe<A extends Account, Depth>(
297
+ this: CoValueClass<A>,
298
+ id: ID<A>,
299
+ depth: Depth & DepthsIn<A>,
300
+ listener: (value: DeeplyLoaded<A, Depth>) => void,
301
+ ): () => void;
279
302
  static subscribe<A extends Account, Depth>(
280
303
  this: CoValueClass<A>,
281
304
  id: ID<A>,
282
305
  as: Account,
283
306
  depth: Depth & DepthsIn<A>,
284
307
  listener: (value: DeeplyLoaded<A, Depth>) => void,
308
+ ): () => void;
309
+ static subscribe<A extends Account, Depth>(
310
+ this: CoValueClass<A>,
311
+ id: ID<A>,
312
+ asOrDepth: Account | (Depth & DepthsIn<A>),
313
+ depthOrListener:
314
+ | (Depth & DepthsIn<A>)
315
+ | ((value: DeeplyLoaded<A, Depth>) => void),
316
+ listener?: (value: DeeplyLoaded<A, Depth>) => void,
285
317
  ): () => void {
286
- return subscribeToCoValue<A, Depth>(this, id, as, depth, listener);
318
+ return subscribeToCoValueWithoutMe<A, Depth>(
319
+ this,
320
+ id,
321
+ asOrDepth,
322
+ depthOrListener,
323
+ listener!,
324
+ );
287
325
  }
288
326
 
289
327
  /** @category Subscription & Loading */
@@ -10,6 +10,7 @@ import type {
10
10
  SessionID,
11
11
  } from "cojson";
12
12
  import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals } from "cojson";
13
+ import { activeAccountContext } from "../implementation/activeAccountContext.js";
13
14
  import type {
14
15
  AnonymousJazzAgent,
15
16
  CoValue,
@@ -30,10 +31,12 @@ import {
30
31
  co,
31
32
  ensureCoValueLoaded,
32
33
  inspect,
34
+ isAccountInstance,
33
35
  isRefEncoded,
34
- loadCoValue,
36
+ loadCoValueWithoutMe,
35
37
  parseCoValueCreateOptions,
36
38
  subscribeToCoValue,
39
+ subscribeToCoValueWithoutMe,
37
40
  subscribeToExistingCoValue,
38
41
  } from "../internal.js";
39
42
  import { type Account } from "./account.js";
@@ -205,7 +208,7 @@ export class CoFeed<Item = any> extends CoValueBase implements CoValue {
205
208
  static create<S extends CoFeed>(
206
209
  this: CoValueClass<S>,
207
210
  init: S extends CoFeed<infer Item> ? UnCo<Item>[] : never,
208
- options: { owner: Account | Group } | Account | Group,
211
+ options?: { owner: Account | Group } | Account | Group,
209
212
  ) {
210
213
  const { owner } = parseCoValueCreateOptions(options);
211
214
  const instance = new this({ init, owner });
@@ -323,27 +326,59 @@ export class CoFeed<Item = any> extends CoValueBase implements CoValue {
323
326
  * Load a `CoFeed`
324
327
  * @category Subscription & Loading
325
328
  */
329
+ static load<S extends CoFeed, Depth>(
330
+ this: CoValueClass<S>,
331
+ id: ID<S>,
332
+ depth: Depth & DepthsIn<S>,
333
+ ): Promise<DeeplyLoaded<S, Depth> | undefined>;
326
334
  static load<S extends CoFeed, Depth>(
327
335
  this: CoValueClass<S>,
328
336
  id: ID<S>,
329
337
  as: Account,
330
338
  depth: Depth & DepthsIn<S>,
339
+ ): Promise<DeeplyLoaded<S, Depth> | undefined>;
340
+ static load<S extends CoFeed, Depth>(
341
+ this: CoValueClass<S>,
342
+ id: ID<S>,
343
+ asOrDepth: Account | (Depth & DepthsIn<S>),
344
+ depth?: Depth & DepthsIn<S>,
331
345
  ): Promise<DeeplyLoaded<S, Depth> | undefined> {
332
- return loadCoValue(this, id, as, depth);
346
+ return loadCoValueWithoutMe(this, id, asOrDepth, depth);
333
347
  }
334
348
 
335
349
  /**
336
350
  * Subscribe to a `CoFeed`, when you have an ID but don't have a `CoFeed` instance yet
337
351
  * @category Subscription & Loading
338
352
  */
353
+ static subscribe<S extends CoFeed, Depth>(
354
+ this: CoValueClass<S>,
355
+ id: ID<S>,
356
+ depth: Depth & DepthsIn<S>,
357
+ listener: (value: DeeplyLoaded<S, Depth>) => void,
358
+ ): () => void;
339
359
  static subscribe<S extends CoFeed, Depth>(
340
360
  this: CoValueClass<S>,
341
361
  id: ID<S>,
342
362
  as: Account,
343
363
  depth: Depth & DepthsIn<S>,
344
364
  listener: (value: DeeplyLoaded<S, Depth>) => void,
365
+ ): () => void;
366
+ static subscribe<S extends CoFeed, Depth>(
367
+ this: CoValueClass<S>,
368
+ id: ID<S>,
369
+ asOrDepth: Account | (Depth & DepthsIn<S>),
370
+ depthOrListener:
371
+ | (Depth & DepthsIn<S>)
372
+ | ((value: DeeplyLoaded<S, Depth>) => void),
373
+ listener?: (value: DeeplyLoaded<S, Depth>) => void,
345
374
  ): () => void {
346
- return subscribeToCoValue<S, Depth>(this, id, as, depth, listener);
375
+ return subscribeToCoValueWithoutMe<S, Depth>(
376
+ this,
377
+ id,
378
+ asOrDepth,
379
+ depthOrListener,
380
+ listener,
381
+ );
347
382
  }
348
383
 
349
384
  /**
@@ -675,7 +710,7 @@ export class FileStream extends CoValueBase implements CoValue {
675
710
 
676
711
  static create<S extends FileStream>(
677
712
  this: CoValueClass<S>,
678
- options: { owner: Account | Group } | Account | Group,
713
+ options?: { owner?: Account | Group } | Account | Group,
679
714
  ) {
680
715
  return new this(parseCoValueCreateOptions(options));
681
716
  }
@@ -722,13 +757,37 @@ export class FileStream extends CoValueBase implements CoValue {
722
757
  *
723
758
  * @category Content
724
759
  */
760
+ static async loadAsBlob(
761
+ id: ID<FileStream>,
762
+ options?: {
763
+ allowUnfinished?: boolean;
764
+ },
765
+ ): Promise<Blob | undefined>;
725
766
  static async loadAsBlob(
726
767
  id: ID<FileStream>,
727
768
  as: Account,
728
769
  options?: {
729
770
  allowUnfinished?: boolean;
730
771
  },
772
+ ): Promise<Blob | undefined>;
773
+ static async loadAsBlob(
774
+ id: ID<FileStream>,
775
+ asOrOptions?:
776
+ | Account
777
+ | {
778
+ allowUnfinished?: boolean;
779
+ },
780
+ optionsOrUndefined?: {
781
+ allowUnfinished?: boolean;
782
+ },
731
783
  ): Promise<Blob | undefined> {
784
+ const as = isAccountInstance(asOrOptions)
785
+ ? asOrOptions
786
+ : activeAccountContext.get();
787
+ const options = isAccountInstance(asOrOptions)
788
+ ? optionsOrUndefined
789
+ : asOrOptions;
790
+
732
791
  let stream = await this.load(id, as, []);
733
792
 
734
793
  /**
@@ -764,16 +823,17 @@ export class FileStream extends CoValueBase implements CoValue {
764
823
  */
765
824
  static async createFromBlob(
766
825
  blob: Blob | File,
767
- options:
826
+ options?:
768
827
  | {
769
- owner: Group | Account;
828
+ owner?: Group | Account;
770
829
  onProgress?: (progress: number) => void;
771
830
  }
772
831
  | Account
773
832
  | Group,
774
833
  ): Promise<FileStream> {
775
834
  const stream = this.create(options);
776
- const onProgress = "onProgress" in options ? options.onProgress : undefined;
835
+ const onProgress =
836
+ options && "onProgress" in options ? options.onProgress : undefined;
777
837
 
778
838
  const start = Date.now();
779
839
 
@@ -840,27 +900,59 @@ export class FileStream extends CoValueBase implements CoValue {
840
900
  * Load a `FileStream`
841
901
  * @category Subscription & Loading
842
902
  */
843
- static load<B extends FileStream, Depth>(
844
- this: CoValueClass<B>,
845
- id: ID<B>,
903
+ static load<C extends FileStream, Depth>(
904
+ this: CoValueClass<C>,
905
+ id: ID<C>,
906
+ depth: Depth & DepthsIn<C>,
907
+ ): Promise<DeeplyLoaded<C, Depth> | undefined>;
908
+ static load<C extends FileStream, Depth>(
909
+ this: CoValueClass<C>,
910
+ id: ID<C>,
846
911
  as: Account,
847
- depth: Depth & DepthsIn<B>,
848
- ): Promise<DeeplyLoaded<B, Depth> | undefined> {
849
- return loadCoValue(this, id, as, depth);
912
+ depth: Depth & DepthsIn<C>,
913
+ ): Promise<DeeplyLoaded<C, Depth> | undefined>;
914
+ static load<C extends FileStream, Depth>(
915
+ this: CoValueClass<C>,
916
+ id: ID<C>,
917
+ asOrDepth: Account | (Depth & DepthsIn<C>),
918
+ depth?: Depth & DepthsIn<C>,
919
+ ): Promise<DeeplyLoaded<C, Depth> | undefined> {
920
+ return loadCoValueWithoutMe(this, id, asOrDepth, depth);
850
921
  }
851
922
 
852
923
  /**
853
924
  * Subscribe to a `FileStream`, when you have an ID but don't have a `FileStream` instance yet
854
925
  * @category Subscription & Loading
855
926
  */
856
- static subscribe<B extends FileStream, Depth>(
857
- this: CoValueClass<B>,
858
- id: ID<B>,
927
+ static subscribe<C extends FileStream, Depth>(
928
+ this: CoValueClass<C>,
929
+ id: ID<C>,
930
+ depth: Depth & DepthsIn<C>,
931
+ listener: (value: DeeplyLoaded<C, Depth>) => void,
932
+ ): () => void;
933
+ static subscribe<C extends FileStream, Depth>(
934
+ this: CoValueClass<C>,
935
+ id: ID<C>,
859
936
  as: Account,
860
- depth: Depth & DepthsIn<B>,
861
- listener: (value: DeeplyLoaded<B, Depth>) => void,
937
+ depth: Depth & DepthsIn<C>,
938
+ listener: (value: DeeplyLoaded<C, Depth>) => void,
939
+ ): () => void;
940
+ static subscribe<C extends FileStream, Depth>(
941
+ this: CoValueClass<C>,
942
+ id: ID<C>,
943
+ asOrDepth: Account | (Depth & DepthsIn<C>),
944
+ depthOrListener:
945
+ | (Depth & DepthsIn<C>)
946
+ | ((value: DeeplyLoaded<C, Depth>) => void),
947
+ listener?: (value: DeeplyLoaded<C, Depth>) => void,
862
948
  ): () => void {
863
- return subscribeToCoValue<B, Depth>(this, id, as, depth, listener);
949
+ return subscribeToCoValueWithoutMe<C, Depth>(
950
+ this,
951
+ id,
952
+ asOrDepth,
953
+ depthOrListener,
954
+ listener,
955
+ );
864
956
  }
865
957
 
866
958
  ensureLoaded<B extends FileStream, Depth>(
@@ -21,10 +21,10 @@ import {
21
21
  ensureCoValueLoaded,
22
22
  inspect,
23
23
  isRefEncoded,
24
- loadCoValue,
24
+ loadCoValueWithoutMe,
25
25
  makeRefs,
26
26
  parseCoValueCreateOptions,
27
- subscribeToCoValue,
27
+ subscribeToCoValueWithoutMe,
28
28
  subscribeToExistingCoValue,
29
29
  subscriptionsScopes,
30
30
  } from "../internal.js";
@@ -221,7 +221,7 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
221
221
  static create<L extends CoList>(
222
222
  this: CoValueClass<L>,
223
223
  items: UnCo<L[number]>[],
224
- options: { owner: Account | Group } | Account | Group,
224
+ options?: { owner: Account | Group } | Account | Group,
225
225
  ) {
226
226
  const { owner } = parseCoValueCreateOptions(options);
227
227
  const instance = new this({ init: items, owner });
@@ -360,13 +360,24 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
360
360
  *
361
361
  * @category Subscription & Loading
362
362
  */
363
- static load<L extends CoList, Depth>(
364
- this: CoValueClass<L>,
365
- id: ID<L>,
363
+ static load<C extends CoList, Depth>(
364
+ this: CoValueClass<C>,
365
+ id: ID<C>,
366
+ depth: Depth & DepthsIn<C>,
367
+ ): Promise<DeeplyLoaded<C, Depth> | undefined>;
368
+ static load<C extends CoList, Depth>(
369
+ this: CoValueClass<C>,
370
+ id: ID<C>,
366
371
  as: Account,
367
- depth: Depth & DepthsIn<L>,
368
- ): Promise<DeeplyLoaded<L, Depth> | undefined> {
369
- return loadCoValue(this, id, as, depth);
372
+ depth: Depth & DepthsIn<C>,
373
+ ): Promise<DeeplyLoaded<C, Depth> | undefined>;
374
+ static load<C extends CoList, Depth>(
375
+ this: CoValueClass<C>,
376
+ id: ID<C>,
377
+ asOrDepth: Account | (Depth & DepthsIn<C>),
378
+ depth?: Depth & DepthsIn<C>,
379
+ ): Promise<DeeplyLoaded<C, Depth> | undefined> {
380
+ return loadCoValueWithoutMe(this, id, asOrDepth, depth);
370
381
  }
371
382
 
372
383
  /**
@@ -397,14 +408,35 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
397
408
  *
398
409
  * @category Subscription & Loading
399
410
  */
400
- static subscribe<L extends CoList, Depth>(
401
- this: CoValueClass<L>,
402
- id: ID<L>,
411
+ static subscribe<C extends CoList, Depth>(
412
+ this: CoValueClass<C>,
413
+ id: ID<C>,
414
+ depth: Depth & DepthsIn<C>,
415
+ listener: (value: DeeplyLoaded<C, Depth>) => void,
416
+ ): () => void;
417
+ static subscribe<C extends CoList, Depth>(
418
+ this: CoValueClass<C>,
419
+ id: ID<C>,
403
420
  as: Account,
404
- depth: Depth & DepthsIn<L>,
405
- listener: (value: DeeplyLoaded<L, Depth>) => void,
421
+ depth: Depth & DepthsIn<C>,
422
+ listener: (value: DeeplyLoaded<C, Depth>) => void,
423
+ ): () => void;
424
+ static subscribe<C extends CoList, Depth>(
425
+ this: CoValueClass<C>,
426
+ id: ID<C>,
427
+ asOrDepth: Account | (Depth & DepthsIn<C>),
428
+ depthOrListener:
429
+ | (Depth & DepthsIn<C>)
430
+ | ((value: DeeplyLoaded<C, Depth>) => void),
431
+ listener?: (value: DeeplyLoaded<C, Depth>) => void,
406
432
  ): () => void {
407
- return subscribeToCoValue<L, Depth>(this, id, as, depth, listener);
433
+ return subscribeToCoValueWithoutMe<C, Depth>(
434
+ this,
435
+ id,
436
+ asOrDepth,
437
+ depthOrListener,
438
+ listener,
439
+ );
408
440
  }
409
441
 
410
442
  /**