jazz-tools 0.11.6 → 0.11.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.11.6 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.11.8 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -11,12 +11,12 @@
11
11
  ESM Build start
12
12
  ESM dist/index.js 1.50 KB
13
13
  ESM dist/testing.js 6.18 KB
14
- ESM dist/chunk-2LO7CLFD.js 121.15 KB
14
+ ESM dist/chunk-HH3Z4JSB.js 121.60 KB
15
15
  ESM dist/index.js.map 259.00 B
16
16
  ESM dist/testing.js.map 12.24 KB
17
- ESM dist/chunk-2LO7CLFD.js.map 288.04 KB
18
- ESM ⚡️ Build success in 79ms
17
+ ESM dist/chunk-HH3Z4JSB.js.map 289.35 KB
18
+ ESM ⚡️ Build success in 40ms
19
19
 
20
- > jazz-tools@0.11.6 types /home/runner/_work/jazz/jazz/packages/jazz-tools
20
+ > jazz-tools@0.11.8 types /home/runner/_work/jazz/jazz/packages/jazz-tools
21
21
  > tsc --outDir dist
22
22
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.11.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6c86c4f]
8
+ - Updated dependencies [9d0c9dc]
9
+ - cojson@0.11.8
10
+
11
+ ## 0.11.7
12
+
13
+ ### Patch Changes
14
+
15
+ - a140f55: Bugfix: Trigger a single update when loading a locally available list of items
16
+ - 2b0d1b0: Export CoFeedEntry type
17
+ - Updated dependencies [2b94bc8]
18
+ - Updated dependencies [2957362]
19
+ - cojson@0.11.7
20
+
3
21
  ## 0.11.6
4
22
 
5
23
  ### Patch Changes
@@ -343,7 +343,6 @@ function instantiateRefEncoded(schema, raw) {
343
343
 
344
344
  // src/implementation/subscriptionScope.ts
345
345
  var subscriptionsScopes = /* @__PURE__ */ new WeakMap();
346
- var TRACE_INVALIDATIONS = false;
347
346
  var SubscriptionScope = class {
348
347
  constructor(root, rootSchema, onUpdate) {
349
348
  this.scopeID = `scope-${Math.random().toString(36).slice(2)}`;
@@ -351,6 +350,7 @@ var SubscriptionScope = class {
351
350
  this.scheduledUpdate = false;
352
351
  this.cachedValues = {};
353
352
  this.parents = {};
353
+ this.syncResolution = false;
354
354
  this.unsubscribeAll = () => {
355
355
  for (const entry of this.entries.values()) {
356
356
  if (entry.state === "loaded") {
@@ -397,38 +397,52 @@ var SubscriptionScope = class {
397
397
  };
398
398
  this.entries.set(accessedOrSetId, loadingEntry);
399
399
  const node = this.subscriber._type === "Account" ? this.subscriber._raw.core.node : this.subscriber.node;
400
- void node.loadCoValueCore(accessedOrSetId).then((core) => {
401
- if (loadingEntry.state === "loading" && loadingEntry.immediatelyUnsub) {
402
- return;
403
- }
404
- if (core !== "unavailable") {
405
- const entry = {
406
- state: "loaded",
407
- rawUnsub: () => {
408
- }
409
- // placeholder
410
- };
411
- this.entries.set(accessedOrSetId, entry);
412
- const rawUnsub = core.subscribe((rawUpdate) => {
413
- if (!rawUpdate) return;
414
- this.invalidate(accessedOrSetId);
415
- this.scheduleUpdate();
416
- });
417
- entry.rawUnsub = rawUnsub;
418
- }
419
- });
400
+ loadCoValue(
401
+ node,
402
+ accessedOrSetId,
403
+ (core) => {
404
+ if (loadingEntry.state === "loading" && loadingEntry.immediatelyUnsub) {
405
+ return;
406
+ }
407
+ if (core !== "unavailable") {
408
+ const entry = {
409
+ state: "loaded",
410
+ rawUnsub: () => {
411
+ }
412
+ // placeholder
413
+ };
414
+ this.entries.set(accessedOrSetId, entry);
415
+ const rawUnsub = core.subscribe((rawUpdate) => {
416
+ if (!rawUpdate) return;
417
+ this.invalidate(accessedOrSetId);
418
+ this.scheduleUpdate();
419
+ });
420
+ entry.rawUnsub = rawUnsub;
421
+ }
422
+ },
423
+ this.syncResolution
424
+ );
420
425
  }
421
426
  }
422
- invalidate(id, fromChild, seen = /* @__PURE__ */ new Set()) {
427
+ invalidate(id, seen = /* @__PURE__ */ new Set()) {
423
428
  if (seen.has(id)) return;
424
- TRACE_INVALIDATIONS && console.log("invalidating", fromChild, "->", id, this.cachedValues[id]);
425
429
  delete this.cachedValues[id];
426
430
  seen.add(id);
427
431
  for (const parent of this.parents[id] || []) {
428
- this.invalidate(parent, id, seen);
432
+ this.invalidate(parent, seen);
429
433
  }
430
434
  }
431
435
  };
436
+ function loadCoValue(node, id, callback, syncResolution) {
437
+ const entry = node.coValuesStore.get(id);
438
+ if (entry.state.type === "available" && syncResolution) {
439
+ callback(entry.state.coValue);
440
+ } else {
441
+ void node.loadCoValueCore(id).then((core) => {
442
+ callback(core);
443
+ });
444
+ }
445
+ }
432
446
 
433
447
  // src/implementation/createContext.ts
434
448
  import {
@@ -741,11 +755,11 @@ function loadCoValueWithoutMe(cls, id, asOrDepth, depth) {
741
755
  "Depth is required when loading a CoValue as an Account or AnonymousJazzAgent"
742
756
  );
743
757
  }
744
- return loadCoValue(cls, id, asOrDepth, depth);
758
+ return loadCoValue2(cls, id, asOrDepth, depth);
745
759
  }
746
- return loadCoValue(cls, id, activeAccountContext.get(), asOrDepth);
760
+ return loadCoValue2(cls, id, activeAccountContext.get(), asOrDepth);
747
761
  }
748
- function loadCoValue(cls, id, as, depth) {
762
+ function loadCoValue2(cls, id, as, depth) {
749
763
  return new Promise((resolve) => {
750
764
  subscribeToCoValue(
751
765
  cls,
@@ -763,7 +777,7 @@ function loadCoValue(cls, id, as, depth) {
763
777
  });
764
778
  }
765
779
  async function ensureCoValueLoaded(existing, depth) {
766
- const response = await loadCoValue(
780
+ const response = await loadCoValue2(
767
781
  existing.constructor,
768
782
  existing.id,
769
783
  existing._loadedAs,
@@ -812,7 +826,11 @@ function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable, syncRes
812
826
  value,
813
827
  cls,
814
828
  (update, subscription2) => {
815
- if (fulfillsDepth(depth, update)) {
829
+ if (subscription2.syncResolution) return false;
830
+ subscription2.syncResolution = true;
831
+ const isLoaded = fulfillsDepth(depth, update);
832
+ subscription2.syncResolution = false;
833
+ if (isLoaded) {
816
834
  listener(
817
835
  update,
818
836
  subscription2.unsubscribeAll
@@ -997,7 +1015,7 @@ var Inbox = class _Inbox {
997
1015
  new Error("Unable to load inbox message " + id)
998
1016
  );
999
1017
  }
1000
- return loadCoValue(
1018
+ return loadCoValue2(
1001
1019
  Schema,
1002
1020
  message.get("payload"),
1003
1021
  account,
@@ -1711,7 +1729,7 @@ var _Account = class _Account extends CoValueBase {
1711
1729
  valueID,
1712
1730
  inviteSecret
1713
1731
  );
1714
- return loadCoValue(coValueClass, valueID, this, []);
1732
+ return loadCoValue2(coValueClass, valueID, this, []);
1715
1733
  }
1716
1734
  /** @private */
1717
1735
  static async create(options) {
@@ -2909,7 +2927,7 @@ var _Group = class _Group extends CoValueBase {
2909
2927
  );
2910
2928
  }
2911
2929
  getParentGroups() {
2912
- return this._raw.getParentGroups().map(({ group }) => _Group.fromRaw(group));
2930
+ return this._raw.getParentGroups().map((group) => _Group.fromRaw(group));
2913
2931
  }
2914
2932
  extend(parent, roleMapping) {
2915
2933
  this._raw.extend(parent._raw, roleMapping);
@@ -3034,7 +3052,7 @@ var CoPlainText = class extends String {
3034
3052
  * @category Subscription & Loading
3035
3053
  */
3036
3054
  static load(id, as) {
3037
- return loadCoValue(this, id, as ?? activeAccountContext.get(), []);
3055
+ return loadCoValue2(this, id, as ?? activeAccountContext.get(), []);
3038
3056
  }
3039
3057
  static subscribe(id, asOrListener, listener) {
3040
3058
  if (isAccountInstance(asOrListener)) {
@@ -4186,7 +4204,7 @@ export {
4186
4204
  activeAccountContext,
4187
4205
  AnonymousJazzAgent,
4188
4206
  CoValueBase,
4189
- loadCoValue,
4207
+ loadCoValue2 as loadCoValue,
4190
4208
  subscribeToCoValue,
4191
4209
  createCoValueObservable,
4192
4210
  Encoders,
@@ -4222,4 +4240,4 @@ export {
4222
4240
  consumeInviteLink
4223
4241
  };
4224
4242
  /* istanbul ignore file -- @preserve */
4225
- //# sourceMappingURL=chunk-2LO7CLFD.js.map
4243
+ //# sourceMappingURL=chunk-HH3Z4JSB.js.map