@graffy/common 0.15.14 → 0.15.15

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.
package/index.cjs CHANGED
@@ -271,7 +271,7 @@ function keyBefore(key) {
271
271
  return key.charCodeAt(l) === 0 ? key.substr(0, l) : key.substr(0, l) + String.fromCharCode(key.charCodeAt(l) - 1) + "\uFFFF";
272
272
  }
273
273
  function keyAfter(key) {
274
- if (key === "" || key === "\uFFFF" || key === "\0" || key === "\0\uFFFF") {
274
+ if (key === "\uFFFF" || key === "\0" || key === "\0\uFFFF") {
275
275
  return key;
276
276
  }
277
277
  const l = key.length - 1;
@@ -502,8 +502,11 @@ function add(base, diff) {
502
502
  }
503
503
  if (nodeIsBranch && itemIsBranch) {
504
504
  changed = add(item.children, node.children) || changed;
505
- } else if (nodeIsBranch || itemIsBranch) {
506
- throw new Error("add.branch_leaf_mismatch");
505
+ } else if (nodeIsBranch) {
506
+ continue;
507
+ } else if (itemIsBranch) {
508
+ item.value = node.value;
509
+ changed = true;
507
510
  } else {
508
511
  item.value += node.value;
509
512
  }
@@ -643,9 +646,10 @@ function wrap(children, path, version = 0, prefix = false) {
643
646
  children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { version, children })];
644
647
  return children;
645
648
  }
646
- function unwrap(children, path) {
649
+ function unwrap(tree, path) {
647
650
  if (!Array.isArray(path))
648
651
  throw Error("unwrap.path_not_array " + path);
652
+ let children = tree;
649
653
  let node = { children };
650
654
  for (let i = 0; i < path.length; i++) {
651
655
  const { key } = encode$2(path[i]);
@@ -657,6 +661,8 @@ function unwrap(children, path) {
657
661
  return void 0;
658
662
  if (isRange(node))
659
663
  return null;
664
+ if (node.path)
665
+ return unwrap(tree, node.path.concat(path.slice(i + 1)));
660
666
  }
661
667
  return getNodeValue(node);
662
668
  }
package/index.mjs CHANGED
@@ -263,7 +263,7 @@ function keyBefore(key) {
263
263
  return key.charCodeAt(l) === 0 ? key.substr(0, l) : key.substr(0, l) + String.fromCharCode(key.charCodeAt(l) - 1) + "\uFFFF";
264
264
  }
265
265
  function keyAfter(key) {
266
- if (key === "" || key === "\uFFFF" || key === "\0" || key === "\0\uFFFF") {
266
+ if (key === "\uFFFF" || key === "\0" || key === "\0\uFFFF") {
267
267
  return key;
268
268
  }
269
269
  const l = key.length - 1;
@@ -494,8 +494,11 @@ function add(base, diff) {
494
494
  }
495
495
  if (nodeIsBranch && itemIsBranch) {
496
496
  changed = add(item.children, node.children) || changed;
497
- } else if (nodeIsBranch || itemIsBranch) {
498
- throw new Error("add.branch_leaf_mismatch");
497
+ } else if (nodeIsBranch) {
498
+ continue;
499
+ } else if (itemIsBranch) {
500
+ item.value = node.value;
501
+ changed = true;
499
502
  } else {
500
503
  item.value += node.value;
501
504
  }
@@ -635,9 +638,10 @@ function wrap(children, path, version = 0, prefix = false) {
635
638
  children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { version, children })];
636
639
  return children;
637
640
  }
638
- function unwrap(children, path) {
641
+ function unwrap(tree, path) {
639
642
  if (!Array.isArray(path))
640
643
  throw Error("unwrap.path_not_array " + path);
644
+ let children = tree;
641
645
  let node = { children };
642
646
  for (let i = 0; i < path.length; i++) {
643
647
  const { key } = encode$2(path[i]);
@@ -649,6 +653,8 @@ function unwrap(children, path) {
649
653
  return void 0;
650
654
  if (isRange(node))
651
655
  return null;
656
+ if (node.path)
657
+ return unwrap(tree, node.path.concat(path.slice(i + 1)));
652
658
  }
653
659
  return getNodeValue(node);
654
660
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/common",
3
3
  "description": "Common libraries that used by various Graffy modules.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.15.14",
5
+ "version": "0.15.15",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -17,8 +17,8 @@
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
19
  "lodash": "^4.17.19",
20
- "nanoid": "^3.1.25",
21
- "@graffy/stream": "0.15.14",
20
+ "nanoid": "^3.1.31",
21
+ "@graffy/stream": "0.15.15",
22
22
  "merge-async-iterators": "^0.2.1"
23
23
  }
24
24
  }
@@ -1,6 +1,6 @@
1
1
  export function wrapValue(value: any, path: any, version?: number): any;
2
2
  export function wrap(children: any, path: any, version?: number, prefix?: boolean): any;
3
- export function unwrap(children: any, path: any): any;
3
+ export function unwrap(tree: any, path: any): any;
4
4
  export function getNodeValue(node: any): any;
5
5
  export function remove(children: any, path: any): any;
6
6
  export const IS_VAL: unique symbol;