jazz-tools 0.11.2 → 0.11.4

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.2 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.11.4 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"}
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.js 1.50 KB
13
- ESM dist/chunk-MVDJNBLV.js 119.45 KB
14
13
  ESM dist/testing.js 6.18 KB
14
+ ESM dist/chunk-IOK4K3XC.js 120.99 KB
15
15
  ESM dist/index.js.map 259.00 B
16
- ESM dist/chunk-MVDJNBLV.js.map 284.49 KB
17
16
  ESM dist/testing.js.map 12.24 KB
18
- ESM ⚡️ Build success in 43ms
17
+ ESM dist/chunk-IOK4K3XC.js.map 287.57 KB
18
+ ESM ⚡️ Build success in 52ms
19
19
 
20
- > jazz-tools@0.11.2 types /home/runner/_work/jazz/jazz/packages/jazz-tools
20
+ > jazz-tools@0.11.4 types /home/runner/_work/jazz/jazz/packages/jazz-tools
21
21
  > tsc --outDir dist
22
22
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.11.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 57a3dbe: Throw when assigning invalid values to ref fields
8
+ - a717754: Use RegisteredAccount types for `by` props
9
+ - a91f343: Fixes coList.splice to handle insertions at start of list
10
+ - Updated dependencies [7f036c1]
11
+ - cojson@0.11.4
12
+
13
+ ## 0.11.3
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [68b0242]
18
+ - cojson@0.11.3
19
+
3
20
  ## 0.11.2
4
21
 
5
22
  ### Patch Changes
@@ -1511,9 +1511,13 @@ var CoMapProxyHandler = {
1511
1511
  } else {
1512
1512
  throw new Error(`Cannot set required reference ${key} to null`);
1513
1513
  }
1514
- } else {
1514
+ } else if (value?.id) {
1515
1515
  target._raw.set(key, value.id);
1516
1516
  subscriptionsScopes.get(target)?.onRefAccessedOrSet(target.id, value.id);
1517
+ } else {
1518
+ throw new Error(
1519
+ `Cannot set reference ${key} to a non-CoValue. Got ${value}`
1520
+ );
1517
1521
  }
1518
1522
  }
1519
1523
  return true;
@@ -2581,24 +2585,60 @@ var _CoList = class _CoList extends Array {
2581
2585
  this._raw.delete(0);
2582
2586
  return first;
2583
2587
  }
2588
+ /**
2589
+ * Splice the `CoList` at a given index.
2590
+ *
2591
+ * @param start - The index to start the splice.
2592
+ * @param deleteCount - The number of items to delete.
2593
+ * @param items - The items to insert.
2594
+ */
2584
2595
  splice(start, deleteCount, ...items) {
2585
2596
  const deleted = this.slice(start, start + deleteCount);
2586
2597
  for (let idxToDelete = start + deleteCount - 1; idxToDelete >= start; idxToDelete--) {
2587
2598
  this._raw.delete(idxToDelete);
2588
2599
  }
2589
- let appendAfter = Math.max(start - 1, 0);
2590
- for (const item of toRawItems(items, this._schema[ItemsSym])) {
2591
- this._raw.append(item, appendAfter);
2592
- appendAfter++;
2600
+ const rawItems = toRawItems(items, this._schema[ItemsSym]);
2601
+ if (rawItems.length === 0) {
2602
+ return deleted;
2603
+ }
2604
+ if (rawItems.length === 1) {
2605
+ const item = rawItems[0];
2606
+ if (item === void 0) return deleted;
2607
+ if (start === 0) {
2608
+ this._raw.prepend(item);
2609
+ } else {
2610
+ this._raw.append(item, Math.max(start - 1, 0));
2611
+ }
2612
+ return deleted;
2613
+ }
2614
+ if (start === 0) {
2615
+ for (let i = rawItems.length - 1; i >= 0; i--) {
2616
+ const item = rawItems[i];
2617
+ if (item === void 0) continue;
2618
+ this._raw.prepend(item);
2619
+ }
2620
+ } else {
2621
+ let appendAfter = Math.max(start - 1, 0);
2622
+ for (const item of rawItems) {
2623
+ if (item === void 0) continue;
2624
+ this._raw.append(item, appendAfter);
2625
+ appendAfter++;
2626
+ }
2593
2627
  }
2594
2628
  return deleted;
2595
2629
  }
2596
- applyDiff(other) {
2630
+ /**
2631
+ * Modify the `CoList` to match another list, where the changes are managed internally.
2632
+ *
2633
+ * @param result - The resolved list of items.
2634
+ */
2635
+ applyDiff(result) {
2597
2636
  const current = this._raw.asArray();
2598
- const cmp = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => current[aIdx].id === other[bIdx].id : void 0;
2599
- for (const [from, to, insert] of [
2600
- ...calcPatch(current, other, cmp)
2601
- ].reverse()) {
2637
+ const comparator = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => {
2638
+ return current[aIdx]?.id === result[bIdx]?.id;
2639
+ } : void 0;
2640
+ const patches = [...calcPatch(current, result, comparator)];
2641
+ for (const [from, to, insert] of patches.reverse()) {
2602
2642
  this.splice(from, to - from, ...insert);
2603
2643
  }
2604
2644
  }
@@ -2728,7 +2768,19 @@ var CoListProxyHandler = {
2728
2768
  } else if ("encoded" in itemDescriptor) {
2729
2769
  rawValue = itemDescriptor.encoded.encode(value);
2730
2770
  } else if (isRefEncoded(itemDescriptor)) {
2731
- rawValue = value.id;
2771
+ if (value === null) {
2772
+ if (itemDescriptor.optional) {
2773
+ rawValue = null;
2774
+ } else {
2775
+ throw new Error(`Cannot set required reference ${key} to null`);
2776
+ }
2777
+ } else if (value?.id) {
2778
+ rawValue = value.id;
2779
+ } else {
2780
+ throw new Error(
2781
+ `Cannot set reference ${key} to a non-CoValue. Got ${value}`
2782
+ );
2783
+ }
2732
2784
  }
2733
2785
  target._raw.replace(Number(key), rawValue);
2734
2786
  return true;
@@ -4166,4 +4218,4 @@ export {
4166
4218
  consumeInviteLink
4167
4219
  };
4168
4220
  /* istanbul ignore file -- @preserve */
4169
- //# sourceMappingURL=chunk-MVDJNBLV.js.map
4221
+ //# sourceMappingURL=chunk-IOK4K3XC.js.map