jazz-tools 0.11.8 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +22 -0
  3. package/dist/auth/DemoAuth.d.ts.map +1 -1
  4. package/dist/auth/PassphraseAuth.d.ts.map +1 -1
  5. package/dist/{chunk-HH3Z4JSB.js → chunk-QJNU65NK.js} +414 -275
  6. package/dist/chunk-QJNU65NK.js.map +1 -0
  7. package/dist/coValues/account.d.ts +15 -17
  8. package/dist/coValues/account.d.ts.map +1 -1
  9. package/dist/coValues/coFeed.d.ts +23 -18
  10. package/dist/coValues/coFeed.d.ts.map +1 -1
  11. package/dist/coValues/coList.d.ts +14 -7
  12. package/dist/coValues/coList.d.ts.map +1 -1
  13. package/dist/coValues/coMap.d.ts +36 -33
  14. package/dist/coValues/coMap.d.ts.map +1 -1
  15. package/dist/coValues/coPlainText.d.ts +7 -5
  16. package/dist/coValues/coPlainText.d.ts.map +1 -1
  17. package/dist/coValues/deepLoading.d.ts +36 -19
  18. package/dist/coValues/deepLoading.d.ts.map +1 -1
  19. package/dist/coValues/group.d.ts +14 -7
  20. package/dist/coValues/group.d.ts.map +1 -1
  21. package/dist/coValues/inbox.d.ts.map +1 -1
  22. package/dist/coValues/interfaces.d.ts +45 -11
  23. package/dist/coValues/interfaces.d.ts.map +1 -1
  24. package/dist/exports.d.ts +1 -1
  25. package/dist/exports.d.ts.map +1 -1
  26. package/dist/implementation/refs.d.ts +3 -0
  27. package/dist/implementation/refs.d.ts.map +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/testing.d.ts +1 -1
  30. package/dist/testing.d.ts.map +1 -1
  31. package/dist/testing.js +4 -2
  32. package/dist/testing.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/auth/DemoAuth.ts +3 -1
  35. package/src/auth/PassphraseAuth.ts +3 -1
  36. package/src/coValues/account.ts +43 -49
  37. package/src/coValues/coFeed.ts +74 -146
  38. package/src/coValues/coList.ts +47 -54
  39. package/src/coValues/coMap.ts +47 -54
  40. package/src/coValues/coPlainText.ts +23 -40
  41. package/src/coValues/deepLoading.ts +233 -102
  42. package/src/coValues/group.ts +44 -54
  43. package/src/coValues/inbox.ts +3 -6
  44. package/src/coValues/interfaces.ts +216 -105
  45. package/src/exports.ts +7 -1
  46. package/src/implementation/refs.ts +45 -7
  47. package/src/testing.ts +4 -1
  48. package/src/tests/ContextManager.test.ts +20 -6
  49. package/src/tests/PassphraseAuth.test.ts +3 -1
  50. package/src/tests/account.test.ts +26 -2
  51. package/src/tests/coFeed.test.ts +26 -19
  52. package/src/tests/coList.test.ts +18 -18
  53. package/src/tests/coMap.test.ts +67 -19
  54. package/src/tests/coPlainText.test.ts +8 -4
  55. package/src/tests/coRichText.test.ts +10 -8
  56. package/src/tests/deepLoading.test.ts +321 -80
  57. package/src/tests/groupsAndAccounts.test.ts +10 -12
  58. package/src/tests/inbox.test.ts +1 -1
  59. package/src/tests/schemaUnion.test.ts +8 -18
  60. package/src/tests/subscribe.test.ts +52 -33
  61. package/src/tests/testing.test.ts +1 -1
  62. package/dist/chunk-HH3Z4JSB.js.map +0 -1
@@ -20,18 +20,22 @@ import {
20
20
  type CoValue,
21
21
  CoValueBase,
22
22
  CoValueClass,
23
- DeeplyLoaded,
24
- DepthsIn,
25
23
  ID,
26
24
  Ref,
27
25
  type RefEncoded,
28
26
  RefIfCoValue,
27
+ RefsToResolve,
28
+ RefsToResolveStrict,
29
+ Resolved,
29
30
  type Schema,
30
31
  SchemaInit,
32
+ SubscribeListenerOptions,
33
+ SubscribeRestArgs,
31
34
  ensureCoValueLoaded,
32
35
  inspect,
33
36
  loadCoValue,
34
37
  loadCoValueWithoutMe,
38
+ parseSubscribeRestArgs,
35
39
  subscribeToCoValueWithoutMe,
36
40
  subscribeToExistingCoValue,
37
41
  subscriptionsScopes,
@@ -225,7 +229,7 @@ export class Account extends CoValueBase implements CoValue {
225
229
  valueID: ID<V>,
226
230
  inviteSecret: InviteSecret,
227
231
  coValueClass: CoValueClass<V>,
228
- ) {
232
+ ): Promise<Resolved<V, true> | null> {
229
233
  if (!this.isLocalNodeOwner) {
230
234
  throw new Error("Only a controlled account can accept invites");
231
235
  }
@@ -235,8 +239,9 @@ export class Account extends CoValueBase implements CoValue {
235
239
  inviteSecret,
236
240
  );
237
241
 
238
- return loadCoValue(coValueClass, valueID, this as Account, []);
239
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
+ return loadCoValue(coValueClass, valueID, {
243
+ loadAs: this,
244
+ });
240
245
  }
241
246
 
242
247
  /** @private */
@@ -346,73 +351,62 @@ export class Account extends CoValueBase implements CoValue {
346
351
  }
347
352
 
348
353
  /** @category Subscription & Loading */
349
- static load<A extends Account, Depth>(
350
- this: CoValueClass<A>,
351
- id: ID<A>,
352
- depth: Depth & DepthsIn<A>,
353
- ): Promise<DeeplyLoaded<A, Depth> | undefined>;
354
- static load<A extends Account, Depth>(
355
- this: CoValueClass<A>,
356
- id: ID<A>,
357
- as: Account,
358
- depth: Depth & DepthsIn<A>,
359
- ): Promise<DeeplyLoaded<A, Depth> | undefined>;
360
- static load<A extends Account, Depth>(
354
+ static load<A extends Account, const R extends RefsToResolve<A> = true>(
361
355
  this: CoValueClass<A>,
362
356
  id: ID<A>,
363
- asOrDepth: Account | (Depth & DepthsIn<A>),
364
- depth?: Depth & DepthsIn<A>,
365
- ): Promise<DeeplyLoaded<A, Depth> | undefined> {
366
- return loadCoValueWithoutMe(this, id, asOrDepth, depth);
357
+ options?: {
358
+ resolve?: RefsToResolveStrict<A, R>;
359
+ loadAs?: Account | AnonymousJazzAgent;
360
+ },
361
+ ): Promise<Resolved<A, R> | null> {
362
+ return loadCoValueWithoutMe(this, id, options);
367
363
  }
368
364
 
369
365
  /** @category Subscription & Loading */
370
- static subscribe<A extends Account, Depth>(
366
+ static subscribe<A extends Account, const R extends RefsToResolve<A> = true>(
371
367
  this: CoValueClass<A>,
372
368
  id: ID<A>,
373
- depth: Depth & DepthsIn<A>,
374
- listener: (value: DeeplyLoaded<A, Depth>) => void,
369
+ listener: (value: Resolved<A, R>, unsubscribe: () => void) => void,
375
370
  ): () => void;
376
- static subscribe<A extends Account, Depth>(
371
+ static subscribe<A extends Account, const R extends RefsToResolve<A> = true>(
377
372
  this: CoValueClass<A>,
378
373
  id: ID<A>,
379
- as: Account,
380
- depth: Depth & DepthsIn<A>,
381
- listener: (value: DeeplyLoaded<A, Depth>) => void,
374
+ options: SubscribeListenerOptions<A, R>,
375
+ listener: (value: Resolved<A, R>, unsubscribe: () => void) => void,
382
376
  ): () => void;
383
- static subscribe<A extends Account, Depth>(
377
+ static subscribe<A extends Account, const R extends RefsToResolve<A>>(
384
378
  this: CoValueClass<A>,
385
379
  id: ID<A>,
386
- asOrDepth: Account | (Depth & DepthsIn<A>),
387
- depthOrListener:
388
- | (Depth & DepthsIn<A>)
389
- | ((value: DeeplyLoaded<A, Depth>) => void),
390
- listener?: (value: DeeplyLoaded<A, Depth>) => void,
380
+ ...args: SubscribeRestArgs<A, R>
391
381
  ): () => void {
392
- return subscribeToCoValueWithoutMe<A, Depth>(
393
- this,
394
- id,
395
- asOrDepth,
396
- depthOrListener,
397
- listener!,
398
- );
382
+ const { options, listener } = parseSubscribeRestArgs(args);
383
+ return subscribeToCoValueWithoutMe<A, R>(this, id, options, listener);
399
384
  }
400
385
 
401
386
  /** @category Subscription & Loading */
402
- ensureLoaded<A extends Account, Depth>(
387
+ ensureLoaded<A extends Account, const R extends RefsToResolve<A>>(
403
388
  this: A,
404
- depth: Depth & DepthsIn<A>,
405
- ): Promise<DeeplyLoaded<A, Depth>> {
406
- return ensureCoValueLoaded(this, depth);
389
+ options: { resolve: RefsToResolveStrict<A, R> },
390
+ ): Promise<Resolved<A, R>> {
391
+ return ensureCoValueLoaded(this, options);
407
392
  }
408
393
 
409
394
  /** @category Subscription & Loading */
410
- subscribe<A extends Account, Depth>(
395
+ subscribe<A extends Account, const R extends RefsToResolve<A>>(
396
+ this: A,
397
+ listener: (value: Resolved<A, R>, unsubscribe: () => void) => void,
398
+ ): () => void;
399
+ subscribe<A extends Account, const R extends RefsToResolve<A>>(
400
+ this: A,
401
+ options: { resolve?: RefsToResolveStrict<A, R> },
402
+ listener: (value: Resolved<A, R>, unsubscribe: () => void) => void,
403
+ ): () => void;
404
+ subscribe<A extends Account, const R extends RefsToResolve<A>>(
411
405
  this: A,
412
- depth: Depth & DepthsIn<A>,
413
- listener: (value: DeeplyLoaded<A, Depth>) => void,
406
+ ...args: SubscribeRestArgs<A, R>
414
407
  ): () => void {
415
- return subscribeToExistingCoValue(this, depth, listener);
408
+ const { options, listener } = parseSubscribeRestArgs(args);
409
+ return subscribeToExistingCoValue(this, options, listener);
416
410
  }
417
411
 
418
412
  /**
@@ -10,17 +10,19 @@ 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";
14
13
  import type {
15
14
  AnonymousJazzAgent,
16
15
  CoValue,
17
16
  CoValueClass,
18
- DeeplyLoaded,
19
- DepthsIn,
20
17
  ID,
21
18
  IfCo,
19
+ RefsToResolve,
20
+ RefsToResolveStrict,
21
+ Resolved,
22
22
  Schema,
23
23
  SchemaFor,
24
+ SubscribeListenerOptions,
25
+ SubscribeRestArgs,
24
26
  UnCo,
25
27
  } from "../internal.js";
26
28
  import {
@@ -31,11 +33,10 @@ import {
31
33
  co,
32
34
  ensureCoValueLoaded,
33
35
  inspect,
34
- isAccountInstance,
35
36
  isRefEncoded,
36
37
  loadCoValueWithoutMe,
37
38
  parseCoValueCreateOptions,
38
- subscribeToCoValue,
39
+ parseSubscribeRestArgs,
39
40
  subscribeToCoValueWithoutMe,
40
41
  subscribeToExistingCoValue,
41
42
  } from "../internal.js";
@@ -327,73 +328,52 @@ export class CoFeed<Item = any> extends CoValueBase implements CoValue {
327
328
  * Load a `CoFeed`
328
329
  * @category Subscription & Loading
329
330
  */
330
- static load<S extends CoFeed, Depth>(
331
- this: CoValueClass<S>,
332
- id: ID<S>,
333
- depth: Depth & DepthsIn<S>,
334
- ): Promise<DeeplyLoaded<S, Depth> | undefined>;
335
- static load<S extends CoFeed, Depth>(
336
- this: CoValueClass<S>,
337
- id: ID<S>,
338
- as: Account,
339
- depth: Depth & DepthsIn<S>,
340
- ): Promise<DeeplyLoaded<S, Depth> | undefined>;
341
- static load<S extends CoFeed, Depth>(
342
- this: CoValueClass<S>,
343
- id: ID<S>,
344
- asOrDepth: Account | (Depth & DepthsIn<S>),
345
- depth?: Depth & DepthsIn<S>,
346
- ): Promise<DeeplyLoaded<S, Depth> | undefined> {
347
- return loadCoValueWithoutMe(this, id, asOrDepth, depth);
331
+ static load<F extends CoFeed, const R extends RefsToResolve<F> = true>(
332
+ this: CoValueClass<F>,
333
+ id: ID<F>,
334
+ options: {
335
+ resolve?: RefsToResolveStrict<F, R>;
336
+ loadAs?: Account | AnonymousJazzAgent;
337
+ },
338
+ ): Promise<Resolved<F, R> | null> {
339
+ return loadCoValueWithoutMe(this, id, options);
348
340
  }
349
341
 
350
342
  /**
351
343
  * Subscribe to a `CoFeed`, when you have an ID but don't have a `CoFeed` instance yet
352
344
  * @category Subscription & Loading
353
345
  */
354
- static subscribe<S extends CoFeed, Depth>(
355
- this: CoValueClass<S>,
356
- id: ID<S>,
357
- depth: Depth & DepthsIn<S>,
358
- listener: (value: DeeplyLoaded<S, Depth>) => void,
346
+ static subscribe<F extends CoFeed, const R extends RefsToResolve<F> = true>(
347
+ this: CoValueClass<F>,
348
+ id: ID<F>,
349
+ listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
359
350
  ): () => void;
360
- static subscribe<S extends CoFeed, Depth>(
361
- this: CoValueClass<S>,
362
- id: ID<S>,
363
- as: Account,
364
- depth: Depth & DepthsIn<S>,
365
- listener: (value: DeeplyLoaded<S, Depth>) => void,
351
+ static subscribe<F extends CoFeed, const R extends RefsToResolve<F> = true>(
352
+ this: CoValueClass<F>,
353
+ id: ID<F>,
354
+ options: SubscribeListenerOptions<F, R>,
355
+ listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
366
356
  ): () => void;
367
- static subscribe<S extends CoFeed, Depth>(
368
- this: CoValueClass<S>,
369
- id: ID<S>,
370
- asOrDepth: Account | (Depth & DepthsIn<S>),
371
- depthOrListener:
372
- | (Depth & DepthsIn<S>)
373
- | ((value: DeeplyLoaded<S, Depth>) => void),
374
- listener?: (value: DeeplyLoaded<S, Depth>) => void,
357
+ static subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
358
+ this: CoValueClass<F>,
359
+ id: ID<F>,
360
+ ...args: SubscribeRestArgs<F, R>
375
361
  ): () => void {
376
- return subscribeToCoValueWithoutMe<S, Depth>(
377
- this,
378
- id,
379
- asOrDepth,
380
- depthOrListener,
381
- listener,
382
- );
362
+ const { options, listener } = parseSubscribeRestArgs(args);
363
+ return subscribeToCoValueWithoutMe<F, R>(this, id, options, listener);
383
364
  }
384
365
 
385
366
  /**
386
367
  * Ensure a `CoFeed` is loaded to the specified depth
387
368
  *
388
- * @returns A new instance of the same CoFeed that's loaded to the specified depth,
389
- * or undefined if it cannot be loaded that deeply
369
+ * @returns A new instance of the same CoFeed that's loaded to the specified depth
390
370
  * @category Subscription & Loading
391
371
  */
392
- ensureLoaded<S extends CoFeed, Depth>(
393
- this: S,
394
- depth: Depth & DepthsIn<S>,
395
- ): Promise<DeeplyLoaded<S, Depth>> {
396
- return ensureCoValueLoaded(this, depth);
372
+ ensureLoaded<F extends CoFeed, const R extends RefsToResolve<F>>(
373
+ this: F,
374
+ options?: { resolve?: RefsToResolveStrict<F, R> },
375
+ ): Promise<Resolved<F, R>> {
376
+ return ensureCoValueLoaded(this, options);
397
377
  }
398
378
 
399
379
  /**
@@ -402,12 +382,21 @@ export class CoFeed<Item = any> extends CoValueBase implements CoValue {
402
382
  * No need to provide an ID or Account since they're already part of the instance.
403
383
  * @category Subscription & Loading
404
384
  */
405
- subscribe<S extends CoFeed, Depth>(
406
- this: S,
407
- depth: Depth & DepthsIn<S>,
408
- listener: (value: DeeplyLoaded<S, Depth>) => void,
385
+ subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
386
+ this: F,
387
+ listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
388
+ ): () => void;
389
+ subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
390
+ this: F,
391
+ options: { resolve?: RefsToResolveStrict<F, R> },
392
+ listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
393
+ ): () => void;
394
+ subscribe<F extends CoFeed, const R extends RefsToResolve<F>>(
395
+ this: F,
396
+ ...args: SubscribeRestArgs<F, R>
409
397
  ): () => void {
410
- return subscribeToExistingCoValue(this, depth, listener);
398
+ const { options, listener } = parseSubscribeRestArgs(args);
399
+ return subscribeToExistingCoValue(this, options, listener);
411
400
  }
412
401
 
413
402
  /**
@@ -785,34 +774,10 @@ export class FileStream extends CoValueBase implements CoValue {
785
774
  id: ID<FileStream>,
786
775
  options?: {
787
776
  allowUnfinished?: boolean;
788
- },
789
- ): Promise<Blob | undefined>;
790
- static async loadAsBlob(
791
- id: ID<FileStream>,
792
- as: Account,
793
- options?: {
794
- allowUnfinished?: boolean;
795
- },
796
- ): Promise<Blob | undefined>;
797
- static async loadAsBlob(
798
- id: ID<FileStream>,
799
- asOrOptions?:
800
- | Account
801
- | {
802
- allowUnfinished?: boolean;
803
- },
804
- optionsOrUndefined?: {
805
- allowUnfinished?: boolean;
777
+ loadAs?: Account | AnonymousJazzAgent;
806
778
  },
807
779
  ): Promise<Blob | undefined> {
808
- const as = isAccountInstance(asOrOptions)
809
- ? asOrOptions
810
- : activeAccountContext.get();
811
- const options = isAccountInstance(asOrOptions)
812
- ? optionsOrUndefined
813
- : asOrOptions;
814
-
815
- let stream = await this.load(id, as, []);
780
+ let stream = await this.load(id, options);
816
781
 
817
782
  /**
818
783
  * If the user hasn't requested an incomplete blob and the
@@ -820,12 +785,17 @@ export class FileStream extends CoValueBase implements CoValue {
820
785
  */
821
786
  if (!options?.allowUnfinished && !stream?.isBinaryStreamEnded()) {
822
787
  stream = await new Promise<FileStream>((resolve) => {
823
- subscribeToCoValue(this, id, as, [], (value, unsubscribe) => {
824
- if (value.isBinaryStreamEnded()) {
825
- unsubscribe();
826
- resolve(value);
827
- }
828
- });
788
+ subscribeToCoValueWithoutMe(
789
+ this,
790
+ id,
791
+ options || {},
792
+ (value, unsubscribe) => {
793
+ if (value.isBinaryStreamEnded()) {
794
+ unsubscribe();
795
+ resolve(value);
796
+ }
797
+ },
798
+ );
829
799
  });
830
800
  }
831
801
 
@@ -924,78 +894,36 @@ export class FileStream extends CoValueBase implements CoValue {
924
894
  * Load a `FileStream`
925
895
  * @category Subscription & Loading
926
896
  */
927
- static load<C extends FileStream, Depth>(
897
+ static load<C extends FileStream>(
928
898
  this: CoValueClass<C>,
929
899
  id: ID<C>,
930
- depth: Depth & DepthsIn<C>,
931
- ): Promise<DeeplyLoaded<C, Depth> | undefined>;
932
- static load<C extends FileStream, Depth>(
933
- this: CoValueClass<C>,
934
- id: ID<C>,
935
- as: Account,
936
- depth: Depth & DepthsIn<C>,
937
- ): Promise<DeeplyLoaded<C, Depth> | undefined>;
938
- static load<C extends FileStream, Depth>(
939
- this: CoValueClass<C>,
940
- id: ID<C>,
941
- asOrDepth: Account | (Depth & DepthsIn<C>),
942
- depth?: Depth & DepthsIn<C>,
943
- ): Promise<DeeplyLoaded<C, Depth> | undefined> {
944
- return loadCoValueWithoutMe(this, id, asOrDepth, depth);
900
+ options?: { loadAs?: Account | AnonymousJazzAgent },
901
+ ): Promise<Resolved<C, true> | null> {
902
+ return loadCoValueWithoutMe(this, id, options);
945
903
  }
946
904
 
947
905
  /**
948
906
  * Subscribe to a `FileStream`, when you have an ID but don't have a `FileStream` instance yet
949
907
  * @category Subscription & Loading
950
908
  */
951
- static subscribe<C extends FileStream, Depth>(
909
+ static subscribe<C extends FileStream>(
952
910
  this: CoValueClass<C>,
953
911
  id: ID<C>,
954
- depth: Depth & DepthsIn<C>,
955
- listener: (value: DeeplyLoaded<C, Depth>) => void,
956
- ): () => void;
957
- static subscribe<C extends FileStream, Depth>(
958
- this: CoValueClass<C>,
959
- id: ID<C>,
960
- as: Account,
961
- depth: Depth & DepthsIn<C>,
962
- listener: (value: DeeplyLoaded<C, Depth>) => void,
963
- ): () => void;
964
- static subscribe<C extends FileStream, Depth>(
965
- this: CoValueClass<C>,
966
- id: ID<C>,
967
- asOrDepth: Account | (Depth & DepthsIn<C>),
968
- depthOrListener:
969
- | (Depth & DepthsIn<C>)
970
- | ((value: DeeplyLoaded<C, Depth>) => void),
971
- listener?: (value: DeeplyLoaded<C, Depth>) => void,
912
+ options: { loadAs?: Account | AnonymousJazzAgent },
913
+ listener: (value: Resolved<C, true>) => void,
972
914
  ): () => void {
973
- return subscribeToCoValueWithoutMe<C, Depth>(
974
- this,
975
- id,
976
- asOrDepth,
977
- depthOrListener,
978
- listener,
979
- );
980
- }
981
-
982
- ensureLoaded<B extends FileStream, Depth>(
983
- this: B,
984
- depth: Depth & DepthsIn<B>,
985
- ): Promise<DeeplyLoaded<B, Depth> | undefined> {
986
- return ensureCoValueLoaded(this, depth);
915
+ return subscribeToCoValueWithoutMe<C, true>(this, id, options, listener);
987
916
  }
988
917
 
989
918
  /**
990
919
  * An instance method to subscribe to an existing `FileStream`
991
920
  * @category Subscription & Loading
992
921
  */
993
- subscribe<B extends FileStream, Depth>(
922
+ subscribe<B extends FileStream>(
994
923
  this: B,
995
- depth: Depth & DepthsIn<B>,
996
- listener: (value: DeeplyLoaded<B, Depth>) => void,
924
+ listener: (value: Resolved<B, true>) => void,
997
925
  ): () => void {
998
- return subscribeToExistingCoValue(this, depth, listener);
926
+ return subscribeToExistingCoValue(this, {}, listener);
999
927
  }
1000
928
 
1001
929
  /**
@@ -5,12 +5,15 @@ import type {
5
5
  CoValue,
6
6
  CoValueClass,
7
7
  CoValueFromRaw,
8
- DeeplyLoaded,
9
- DepthsIn,
10
8
  ID,
11
9
  RefEncoded,
10
+ RefsToResolve,
11
+ RefsToResolveStrict,
12
+ Resolved,
12
13
  Schema,
13
14
  SchemaFor,
15
+ SubscribeListenerOptions,
16
+ SubscribeRestArgs,
14
17
  UnCo,
15
18
  } from "../internal.js";
16
19
  import {
@@ -25,6 +28,7 @@ import {
25
28
  loadCoValueWithoutMe,
26
29
  makeRefs,
27
30
  parseCoValueCreateOptions,
31
+ parseSubscribeRestArgs,
28
32
  subscribeToCoValueWithoutMe,
29
33
  subscribeToExistingCoValue,
30
34
  subscriptionsScopes,
@@ -419,24 +423,15 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
419
423
  *
420
424
  * @category Subscription & Loading
421
425
  */
422
- static load<C extends CoList, Depth>(
423
- this: CoValueClass<C>,
424
- id: ID<C>,
425
- depth: Depth & DepthsIn<C>,
426
- ): Promise<DeeplyLoaded<C, Depth> | undefined>;
427
- static load<C extends CoList, Depth>(
428
- this: CoValueClass<C>,
429
- id: ID<C>,
430
- as: Account,
431
- depth: Depth & DepthsIn<C>,
432
- ): Promise<DeeplyLoaded<C, Depth> | undefined>;
433
- static load<C extends CoList, Depth>(
434
- this: CoValueClass<C>,
435
- id: ID<C>,
436
- asOrDepth: Account | (Depth & DepthsIn<C>),
437
- depth?: Depth & DepthsIn<C>,
438
- ): Promise<DeeplyLoaded<C, Depth> | undefined> {
439
- return loadCoValueWithoutMe(this, id, asOrDepth, depth);
426
+ static load<L extends CoList, const R extends RefsToResolve<L> = true>(
427
+ this: CoValueClass<L>,
428
+ id: ID<L>,
429
+ options?: {
430
+ resolve?: RefsToResolveStrict<L, R>;
431
+ loadAs?: Account | AnonymousJazzAgent;
432
+ },
433
+ ): Promise<Resolved<L, R> | null> {
434
+ return loadCoValueWithoutMe(this, id, options);
440
435
  }
441
436
 
442
437
  /**
@@ -467,35 +462,24 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
467
462
  *
468
463
  * @category Subscription & Loading
469
464
  */
470
- static subscribe<C extends CoList, Depth>(
471
- this: CoValueClass<C>,
472
- id: ID<C>,
473
- depth: Depth & DepthsIn<C>,
474
- listener: (value: DeeplyLoaded<C, Depth>) => void,
465
+ static subscribe<L extends CoList, const R extends RefsToResolve<L> = true>(
466
+ this: CoValueClass<L>,
467
+ id: ID<L>,
468
+ listener: (value: Resolved<L, R>, unsubscribe: () => void) => void,
475
469
  ): () => void;
476
- static subscribe<C extends CoList, Depth>(
477
- this: CoValueClass<C>,
478
- id: ID<C>,
479
- as: Account,
480
- depth: Depth & DepthsIn<C>,
481
- listener: (value: DeeplyLoaded<C, Depth>) => void,
470
+ static subscribe<L extends CoList, const R extends RefsToResolve<L> = true>(
471
+ this: CoValueClass<L>,
472
+ id: ID<L>,
473
+ options: SubscribeListenerOptions<L, R>,
474
+ listener: (value: Resolved<L, R>, unsubscribe: () => void) => void,
482
475
  ): () => void;
483
- static subscribe<C extends CoList, Depth>(
484
- this: CoValueClass<C>,
485
- id: ID<C>,
486
- asOrDepth: Account | (Depth & DepthsIn<C>),
487
- depthOrListener:
488
- | (Depth & DepthsIn<C>)
489
- | ((value: DeeplyLoaded<C, Depth>) => void),
490
- listener?: (value: DeeplyLoaded<C, Depth>) => void,
476
+ static subscribe<L extends CoList, const R extends RefsToResolve<L>>(
477
+ this: CoValueClass<L>,
478
+ id: ID<L>,
479
+ ...args: SubscribeRestArgs<L, R>
491
480
  ): () => void {
492
- return subscribeToCoValueWithoutMe<C, Depth>(
493
- this,
494
- id,
495
- asOrDepth,
496
- depthOrListener,
497
- listener,
498
- );
481
+ const { options, listener } = parseSubscribeRestArgs(args);
482
+ return subscribeToCoValueWithoutMe<L, R>(this, id, options, listener);
499
483
  }
500
484
 
501
485
  /**
@@ -505,11 +489,11 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
505
489
  *
506
490
  * @category Subscription & Loading
507
491
  */
508
- ensureLoaded<L extends CoList, Depth>(
492
+ ensureLoaded<L extends CoList, const R extends RefsToResolve<L>>(
509
493
  this: L,
510
- depth: Depth & DepthsIn<L>,
511
- ): Promise<DeeplyLoaded<L, Depth>> {
512
- return ensureCoValueLoaded(this, depth);
494
+ options: { resolve: RefsToResolveStrict<L, R> },
495
+ ): Promise<Resolved<L, R>> {
496
+ return ensureCoValueLoaded(this, options);
513
497
  }
514
498
 
515
499
  /**
@@ -521,12 +505,21 @@ export class CoList<Item = any> extends Array<Item> implements CoValue {
521
505
  *
522
506
  * @category Subscription & Loading
523
507
  **/
524
- subscribe<L extends CoList, Depth>(
508
+ subscribe<L extends CoList, const R extends RefsToResolve<L> = true>(
509
+ this: L,
510
+ listener: (value: Resolved<L, R>, unsubscribe: () => void) => void,
511
+ ): () => void;
512
+ subscribe<L extends CoList, const R extends RefsToResolve<L> = true>(
513
+ this: L,
514
+ options: { resolve?: RefsToResolveStrict<L, R> },
515
+ listener: (value: Resolved<L, R>, unsubscribe: () => void) => void,
516
+ ): () => void;
517
+ subscribe<L extends CoList, const R extends RefsToResolve<L>>(
525
518
  this: L,
526
- depth: Depth & DepthsIn<L>,
527
- listener: (value: DeeplyLoaded<L, Depth>) => void,
519
+ ...args: SubscribeRestArgs<L, R>
528
520
  ): () => void {
529
- return subscribeToExistingCoValue(this, depth, listener);
521
+ const { options, listener } = parseSubscribeRestArgs(args);
522
+ return subscribeToExistingCoValue(this, options, listener);
530
523
  }
531
524
 
532
525
  /** @category Type Helpers */