jazz-tools 0.11.5 → 0.11.7

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.5 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.11.7 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-IOK4K3XC.js 120.99 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-IOK4K3XC.js.map 287.57 KB
18
- ESM ⚡️ Build success in 51ms
17
+ ESM dist/chunk-HH3Z4JSB.js.map 289.35 KB
18
+ ESM ⚡️ Build success in 38ms
19
19
 
20
- > jazz-tools@0.11.5 types /home/runner/_work/jazz/jazz/packages/jazz-tools
20
+ > jazz-tools@0.11.7 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.7
4
+
5
+ ### Patch Changes
6
+
7
+ - a140f55: Bugfix: Trigger a single update when loading a locally available list of items
8
+ - 2b0d1b0: Export CoFeedEntry type
9
+ - Updated dependencies [2b94bc8]
10
+ - Updated dependencies [2957362]
11
+ - cojson@0.11.7
12
+
13
+ ## 0.11.6
14
+
15
+ ### Patch Changes
16
+
17
+ - e7c85b7: Add targetWidth to highestResAvailable to add a way to fetch the next size up
18
+ - Updated dependencies [8ed144e]
19
+ - cojson@0.11.6
20
+
3
21
  ## 0.11.5
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)) {
@@ -3489,22 +3507,26 @@ var ImageDefinition = class extends (_b = CoMap, _a = co.items, _b) {
3489
3507
  );
3490
3508
  }
3491
3509
  const resolutions = Object.keys(this).filter(
3492
- (key) => key.match(/^\d+x\d+$/) && (options?.maxWidth === void 0 || Number(key.split("x")[0]) <= options.maxWidth)
3510
+ (key) => key.match(/^\d+x\d+$/)
3511
+ );
3512
+ let maxWidth = options?.maxWidth;
3513
+ if (options?.targetWidth) {
3514
+ const targetWidth = options.targetWidth;
3515
+ const widths = resolutions.map((res) => Number(res.split("x")[0]));
3516
+ maxWidth = Math.min(...widths.filter((w) => w >= targetWidth));
3517
+ }
3518
+ const validResolutions = resolutions.filter(
3519
+ (key) => maxWidth === void 0 || Number(key.split("x")[0]) <= maxWidth
3493
3520
  );
3494
- resolutions.sort((a, b) => {
3521
+ validResolutions.sort((a, b) => {
3495
3522
  const aWidth = Number(a.split("x")[0]);
3496
3523
  const bWidth = Number(b.split("x")[0]);
3497
3524
  return aWidth - bWidth;
3498
3525
  });
3499
3526
  let highestAvailableResolution;
3500
- for (const resolution of resolutions) {
3527
+ for (const resolution of validResolutions) {
3501
3528
  if (this[resolution] && this[resolution]?.getChunks()) {
3502
3529
  highestAvailableResolution = resolution;
3503
- } else {
3504
- return highestAvailableResolution && {
3505
- res: highestAvailableResolution,
3506
- stream: this[highestAvailableResolution]
3507
- };
3508
3530
  }
3509
3531
  }
3510
3532
  return highestAvailableResolution && {
@@ -4182,7 +4204,7 @@ export {
4182
4204
  activeAccountContext,
4183
4205
  AnonymousJazzAgent,
4184
4206
  CoValueBase,
4185
- loadCoValue,
4207
+ loadCoValue2 as loadCoValue,
4186
4208
  subscribeToCoValue,
4187
4209
  createCoValueObservable,
4188
4210
  Encoders,
@@ -4218,4 +4240,4 @@ export {
4218
4240
  consumeInviteLink
4219
4241
  };
4220
4242
  /* istanbul ignore file -- @preserve */
4221
- //# sourceMappingURL=chunk-IOK4K3XC.js.map
4243
+ //# sourceMappingURL=chunk-HH3Z4JSB.js.map