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
@@ -12,13 +12,16 @@ import type {
12
12
  AnonymousJazzAgent,
13
13
  CoValue,
14
14
  CoValueClass,
15
- DeeplyLoaded,
16
- DepthsIn,
17
15
  ID,
18
16
  IfCo,
19
17
  RefEncoded,
20
18
  RefIfCoValue,
19
+ RefsToResolve,
20
+ RefsToResolveStrict,
21
+ Resolved,
21
22
  Schema,
23
+ SubscribeListenerOptions,
24
+ SubscribeRestArgs,
22
25
  co,
23
26
  } from "../internal.js";
24
27
  import {
@@ -32,6 +35,7 @@ import {
32
35
  loadCoValueWithoutMe,
33
36
  makeRefs,
34
37
  parseCoValueCreateOptions,
38
+ parseSubscribeRestArgs,
35
39
  subscribeToCoValueWithoutMe,
36
40
  subscribeToExistingCoValue,
37
41
  subscriptionsScopes,
@@ -433,24 +437,15 @@ export class CoMap extends CoValueBase implements CoValue {
433
437
  *
434
438
  * @category Subscription & Loading
435
439
  */
436
- static load<C extends CoMap, Depth>(
437
- this: CoValueClass<C>,
438
- id: ID<C>,
439
- depth: Depth & DepthsIn<C>,
440
- ): Promise<DeeplyLoaded<C, Depth> | undefined>;
441
- static load<C extends CoMap, Depth>(
442
- this: CoValueClass<C>,
443
- id: ID<C>,
444
- as: Account,
445
- depth: Depth & DepthsIn<C>,
446
- ): Promise<DeeplyLoaded<C, Depth> | undefined>;
447
- static load<C extends CoMap, Depth>(
448
- this: CoValueClass<C>,
449
- id: ID<C>,
450
- asOrDepth: Account | (Depth & DepthsIn<C>),
451
- depth?: Depth & DepthsIn<C>,
452
- ): Promise<DeeplyLoaded<C, Depth> | undefined> {
453
- return loadCoValueWithoutMe(this, id, asOrDepth, depth);
440
+ static load<M extends CoMap, const R extends RefsToResolve<M> = true>(
441
+ this: CoValueClass<M>,
442
+ id: ID<M>,
443
+ options?: {
444
+ resolve?: RefsToResolveStrict<M, R>;
445
+ loadAs?: Account | AnonymousJazzAgent;
446
+ },
447
+ ): Promise<Resolved<M, R> | null> {
448
+ return loadCoValueWithoutMe(this, id, options);
454
449
  }
455
450
 
456
451
  /**
@@ -480,35 +475,24 @@ export class CoMap extends CoValueBase implements CoValue {
480
475
  *
481
476
  * @category Subscription & Loading
482
477
  */
483
- static subscribe<C extends CoMap, Depth>(
484
- this: CoValueClass<C>,
485
- id: ID<C>,
486
- depth: Depth & DepthsIn<C>,
487
- listener: (value: DeeplyLoaded<C, Depth>) => void,
478
+ static subscribe<M extends CoMap, const R extends RefsToResolve<M> = true>(
479
+ this: CoValueClass<M>,
480
+ id: ID<M>,
481
+ listener: (value: Resolved<M, R>, unsubscribe: () => void) => void,
488
482
  ): () => void;
489
- static subscribe<C extends CoMap, Depth>(
490
- this: CoValueClass<C>,
491
- id: ID<C>,
492
- as: Account,
493
- depth: Depth & DepthsIn<C>,
494
- listener: (value: DeeplyLoaded<C, Depth>) => void,
483
+ static subscribe<M extends CoMap, const R extends RefsToResolve<M> = true>(
484
+ this: CoValueClass<M>,
485
+ id: ID<M>,
486
+ options: SubscribeListenerOptions<M, R>,
487
+ listener: (value: Resolved<M, R>, unsubscribe: () => void) => void,
495
488
  ): () => void;
496
- static subscribe<C extends CoMap, Depth>(
497
- this: CoValueClass<C>,
498
- id: ID<C>,
499
- asOrDepth: Account | (Depth & DepthsIn<C>),
500
- depthOrListener:
501
- | (Depth & DepthsIn<C>)
502
- | ((value: DeeplyLoaded<C, Depth>) => void),
503
- listener?: (value: DeeplyLoaded<C, Depth>) => void,
489
+ static subscribe<M extends CoMap, const R extends RefsToResolve<M>>(
490
+ this: CoValueClass<M>,
491
+ id: ID<M>,
492
+ ...args: SubscribeRestArgs<M, R>
504
493
  ): () => void {
505
- return subscribeToCoValueWithoutMe<C, Depth>(
506
- this,
507
- id,
508
- asOrDepth,
509
- depthOrListener,
510
- listener,
511
- );
494
+ const { options, listener } = parseSubscribeRestArgs(args);
495
+ return subscribeToCoValueWithoutMe<M, R>(this, id, options, listener);
512
496
  }
513
497
 
514
498
  static findUnique<M extends CoMap>(
@@ -540,11 +524,11 @@ export class CoMap extends CoValueBase implements CoValue {
540
524
  *
541
525
  * @category Subscription & Loading
542
526
  */
543
- ensureLoaded<M extends CoMap, Depth>(
527
+ ensureLoaded<M extends CoMap, const R extends RefsToResolve<M>>(
544
528
  this: M,
545
- depth: Depth & DepthsIn<M>,
546
- ): Promise<DeeplyLoaded<M, Depth>> {
547
- return ensureCoValueLoaded(this, depth);
529
+ options: { resolve: RefsToResolveStrict<M, R> },
530
+ ): Promise<Resolved<M, R>> {
531
+ return ensureCoValueLoaded(this, options);
548
532
  }
549
533
 
550
534
  /**
@@ -556,12 +540,21 @@ export class CoMap extends CoValueBase implements CoValue {
556
540
  *
557
541
  * @category Subscription & Loading
558
542
  **/
559
- subscribe<M extends CoMap, Depth>(
543
+ subscribe<M extends CoMap, const R extends RefsToResolve<M> = true>(
544
+ this: M,
545
+ listener: (value: Resolved<M, R>, unsubscribe: () => void) => void,
546
+ ): () => void;
547
+ subscribe<M extends CoMap, const R extends RefsToResolve<M> = true>(
548
+ this: M,
549
+ options: { resolve?: RefsToResolveStrict<M, R> },
550
+ listener: (value: Resolved<M, R>, unsubscribe: () => void) => void,
551
+ ): () => void;
552
+ subscribe<M extends CoMap, const R extends RefsToResolve<M>>(
560
553
  this: M,
561
- depth: Depth & DepthsIn<M>,
562
- listener: (value: DeeplyLoaded<M, Depth>) => void,
554
+ ...args: SubscribeRestArgs<M, R>
563
555
  ): () => void {
564
- return subscribeToExistingCoValue(this, depth, listener);
556
+ const { options, listener } = parseSubscribeRestArgs(args);
557
+ return subscribeToExistingCoValue<M, R>(this, options, listener);
565
558
  }
566
559
 
567
560
  applyDiff<N extends Partial<CoMapInit<this>>>(newValues: N) {
@@ -4,13 +4,20 @@ import {
4
4
  type RawCoPlainText,
5
5
  stringifyOpID,
6
6
  } from "cojson";
7
- import { activeAccountContext } from "../implementation/activeAccountContext.js";
8
- import type { CoValue, CoValueClass, ID } from "../internal.js";
7
+ import type {
8
+ AnonymousJazzAgent,
9
+ CoValue,
10
+ CoValueClass,
11
+ ID,
12
+ Resolved,
13
+ SubscribeListenerOptions,
14
+ SubscribeRestArgs,
15
+ } from "../internal.js";
9
16
  import {
10
17
  inspect,
11
- isAccountInstance,
12
- loadCoValue,
13
- subscribeToCoValue,
18
+ loadCoValueWithoutMe,
19
+ parseSubscribeRestArgs,
20
+ subscribeToCoValueWithoutMe,
14
21
  subscribeToExistingCoValue,
15
22
  } from "../internal.js";
16
23
  import { Account } from "./account.js";
@@ -122,9 +129,9 @@ export class CoPlainText extends String implements CoValue {
122
129
  static load<T extends CoPlainText>(
123
130
  this: CoValueClass<T>,
124
131
  id: ID<T>,
125
- as?: Account,
126
- ): Promise<T | undefined> {
127
- return loadCoValue(this, id, as ?? activeAccountContext.get(), []);
132
+ options?: { loadAs?: Account | AnonymousJazzAgent },
133
+ ): Promise<T | null> {
134
+ return loadCoValueWithoutMe(this, id, options);
128
135
  }
129
136
 
130
137
  // /**
@@ -157,47 +164,23 @@ export class CoPlainText extends String implements CoValue {
157
164
  static subscribe<T extends CoPlainText>(
158
165
  this: CoValueClass<T>,
159
166
  id: ID<T>,
160
- listener: (value: T) => void,
167
+ listener: (value: Resolved<T, true>, unsubscribe: () => void) => void,
161
168
  ): () => void;
162
169
  static subscribe<T extends CoPlainText>(
163
170
  this: CoValueClass<T>,
164
171
  id: ID<T>,
165
- as: Account,
166
- listener: (value: T) => void,
172
+ options: Omit<SubscribeListenerOptions<T, true>, "resolve">,
173
+ listener: (value: Resolved<T, true>, unsubscribe: () => void) => void,
167
174
  ): () => void;
168
175
  static subscribe<T extends CoPlainText>(
169
176
  this: CoValueClass<T>,
170
177
  id: ID<T>,
171
- asOrListener: Account | ((value: T) => void),
172
- listener?: (value: T) => void,
178
+ ...args: SubscribeRestArgs<T, true>
173
179
  ): () => void {
174
- if (isAccountInstance(asOrListener)) {
175
- return subscribeToCoValue(this, id, asOrListener, [], listener!);
176
- }
177
-
178
- return subscribeToCoValue(
179
- this,
180
- id,
181
- activeAccountContext.get(),
182
- [],
183
- listener!,
184
- );
180
+ const { options, listener } = parseSubscribeRestArgs(args);
181
+ return subscribeToCoValueWithoutMe<T, true>(this, id, options, listener);
185
182
  }
186
183
 
187
- // /**
188
- // * Effectful version of `CoMap.subscribe()` that returns a stream of updates.
189
- // *
190
- // * Needs to be run inside an `AccountCtx` context.
191
- // *
192
- // * @category Subscription & Loading
193
- // */
194
- // static subscribeEf<T extends CoPlainText>(
195
- // this: CoValueClass<T>,
196
- // id: ID<T>,
197
- // ): Stream.Stream<T, UnavailableError, AccountCtx> {
198
- // return subscribeToCoValueEf(this, id, []);
199
- // }
200
-
201
184
  /**
202
185
  * Given an already loaded `CoPlainText`, subscribe to updates to the `CoPlainText` and ensure that the specified fields are loaded to the specified depth.
203
186
  *
@@ -209,8 +192,8 @@ export class CoPlainText extends String implements CoValue {
209
192
  **/
210
193
  subscribe<T extends CoPlainText>(
211
194
  this: T,
212
- listener: (value: T) => void,
195
+ listener: (value: Resolved<T, true>, unsubscribe: () => void) => void,
213
196
  ): () => void {
214
- return subscribeToExistingCoValue(this, [], listener);
197
+ return subscribeToExistingCoValue(this, {}, listener);
215
198
  }
216
199
  }