@graffy/common 0.16.0-alpha.5 → 0.16.0-alpha.6

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
@@ -869,7 +869,7 @@ function insertRange(current, change, result, start = 0) {
869
869
  const { key, end } = change;
870
870
  const keyIx = findFirst(current, key, start);
871
871
  const endIx = findLast(current, end, keyIx);
872
- if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, key) <= 0 && cmp(current[keyIx].end, end) >= 0)) {
872
+ if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, end) <= 0 && cmp(current[keyIx].end || current[keyIx].key, key) >= 0)) {
873
873
  return keyIx;
874
874
  }
875
875
  const appliedChange = [];
@@ -1411,7 +1411,9 @@ function deserializeKey(key) {
1411
1411
  return decode(key.slice(1));
1412
1412
  return encode$4(key);
1413
1413
  }
1414
- function serializeNodes(children, parentVersion) {
1414
+ function pack(children, parentVersion) {
1415
+ if (!Array.isArray(children))
1416
+ return children;
1415
1417
  const array = children.map(
1416
1418
  (node) => props.reduce(
1417
1419
  (array2, prop, i) => {
@@ -1421,7 +1423,7 @@ function serializeNodes(children, parentVersion) {
1421
1423
  if (prop === "version" && value === parentVersion)
1422
1424
  return array2;
1423
1425
  if (prop === "children")
1424
- value = serializeNodes(value, node.version);
1426
+ value = pack(value, node.version);
1425
1427
  if (prop === "end")
1426
1428
  value = serializeKey(value);
1427
1429
  if (prop === "path")
@@ -1435,7 +1437,9 @@ function serializeNodes(children, parentVersion) {
1435
1437
  );
1436
1438
  return array;
1437
1439
  }
1438
- function deserializeNodes(children, parentVersion) {
1440
+ function unpack(children, parentVersion) {
1441
+ if (!Array.isArray(children))
1442
+ return children;
1439
1443
  const node = children.map(
1440
1444
  ([key, type, ...values]) => props.reduce(
1441
1445
  (node2, prop, i) => {
@@ -1443,7 +1447,7 @@ function deserializeNodes(children, parentVersion) {
1443
1447
  return node2;
1444
1448
  let value = values.shift();
1445
1449
  if (prop === "children")
1446
- value = deserializeNodes(value, node2.version);
1450
+ value = unpack(value, node2.version);
1447
1451
  if (prop === "end")
1448
1452
  value = deserializeKey(value);
1449
1453
  if (prop === "path")
@@ -1456,12 +1460,6 @@ function deserializeNodes(children, parentVersion) {
1456
1460
  );
1457
1461
  return node;
1458
1462
  }
1459
- function serialize(payload) {
1460
- return JSON.stringify(serializeNodes(payload));
1461
- }
1462
- function deserialize(str) {
1463
- return deserializeNodes(JSON.parse(str));
1464
- }
1465
1463
  const ROOT_KEY = Symbol();
1466
1464
  function encode(value, { version, isGraph } = {}) {
1467
1465
  var _a;
@@ -1715,7 +1713,6 @@ exports.decodePath = decode$2;
1715
1713
  exports.decodeQuery = decodeQuery;
1716
1714
  exports.decodeValue = decode$4;
1717
1715
  exports.decorate = decorate;
1718
- exports.deserialize = deserialize;
1719
1716
  exports.encodeArgs = encode$3;
1720
1717
  exports.encodeGraph = encodeGraph;
1721
1718
  exports.encodePath = encode$2;
@@ -1748,13 +1745,14 @@ exports.makeWatcher = makeWatcher;
1748
1745
  exports.merge = merge;
1749
1746
  exports.mergeObject = mergeObject;
1750
1747
  exports.mergeStreams = mergeStreams;
1748
+ exports.pack = pack;
1751
1749
  exports.remove = remove;
1752
- exports.serialize = serialize;
1753
1750
  exports.setVersion = setVersion;
1754
1751
  exports.sieve = sieve;
1755
1752
  exports.slice = slice;
1756
1753
  exports.splitArgs = splitArgs;
1757
1754
  exports.splitRef = splitRef;
1755
+ exports.unpack = unpack;
1758
1756
  exports.unwrap = unwrap;
1759
1757
  exports.unwrapObject = unwrapObject;
1760
1758
  exports.wrap = wrap;
package/index.mjs CHANGED
@@ -864,7 +864,7 @@ function insertRange(current, change, result, start = 0) {
864
864
  const { key, end } = change;
865
865
  const keyIx = findFirst(current, key, start);
866
866
  const endIx = findLast(current, end, keyIx);
867
- if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, key) <= 0 && cmp(current[keyIx].end, end) >= 0)) {
867
+ if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, end) <= 0 && cmp(current[keyIx].end || current[keyIx].key, key) >= 0)) {
868
868
  return keyIx;
869
869
  }
870
870
  const appliedChange = [];
@@ -1406,7 +1406,9 @@ function deserializeKey(key) {
1406
1406
  return decode(key.slice(1));
1407
1407
  return encode$4(key);
1408
1408
  }
1409
- function serializeNodes(children, parentVersion) {
1409
+ function pack(children, parentVersion) {
1410
+ if (!Array.isArray(children))
1411
+ return children;
1410
1412
  const array = children.map(
1411
1413
  (node) => props.reduce(
1412
1414
  (array2, prop, i) => {
@@ -1416,7 +1418,7 @@ function serializeNodes(children, parentVersion) {
1416
1418
  if (prop === "version" && value === parentVersion)
1417
1419
  return array2;
1418
1420
  if (prop === "children")
1419
- value = serializeNodes(value, node.version);
1421
+ value = pack(value, node.version);
1420
1422
  if (prop === "end")
1421
1423
  value = serializeKey(value);
1422
1424
  if (prop === "path")
@@ -1430,7 +1432,9 @@ function serializeNodes(children, parentVersion) {
1430
1432
  );
1431
1433
  return array;
1432
1434
  }
1433
- function deserializeNodes(children, parentVersion) {
1435
+ function unpack(children, parentVersion) {
1436
+ if (!Array.isArray(children))
1437
+ return children;
1434
1438
  const node = children.map(
1435
1439
  ([key, type, ...values]) => props.reduce(
1436
1440
  (node2, prop, i) => {
@@ -1438,7 +1442,7 @@ function deserializeNodes(children, parentVersion) {
1438
1442
  return node2;
1439
1443
  let value = values.shift();
1440
1444
  if (prop === "children")
1441
- value = deserializeNodes(value, node2.version);
1445
+ value = unpack(value, node2.version);
1442
1446
  if (prop === "end")
1443
1447
  value = deserializeKey(value);
1444
1448
  if (prop === "path")
@@ -1451,12 +1455,6 @@ function deserializeNodes(children, parentVersion) {
1451
1455
  );
1452
1456
  return node;
1453
1457
  }
1454
- function serialize(payload) {
1455
- return JSON.stringify(serializeNodes(payload));
1456
- }
1457
- function deserialize(str) {
1458
- return deserializeNodes(JSON.parse(str));
1459
- }
1460
1458
  const ROOT_KEY = Symbol();
1461
1459
  function encode(value, { version, isGraph } = {}) {
1462
1460
  var _a;
@@ -1711,7 +1709,6 @@ export {
1711
1709
  decodeQuery,
1712
1710
  decode$4 as decodeValue,
1713
1711
  decorate,
1714
- deserialize,
1715
1712
  encode$3 as encodeArgs,
1716
1713
  encodeGraph,
1717
1714
  encode$2 as encodePath,
@@ -1744,13 +1741,14 @@ export {
1744
1741
  merge,
1745
1742
  mergeObject,
1746
1743
  mergeStreams,
1744
+ pack,
1747
1745
  remove,
1748
- serialize,
1749
1746
  setVersion,
1750
1747
  sieve,
1751
1748
  slice,
1752
1749
  splitArgs,
1753
1750
  splitRef,
1751
+ unpack,
1754
1752
  unwrap,
1755
1753
  unwrapObject,
1756
1754
  wrap,
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.16.0-alpha.5",
5
+ "version": "0.16.0-alpha.6",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -18,6 +18,6 @@
18
18
  "dependencies": {
19
19
  "lodash": "^4.17.19",
20
20
  "merge-async-iterators": "^0.2.1",
21
- "@graffy/stream": "0.16.0-alpha.5"
21
+ "@graffy/stream": "0.16.0-alpha.6"
22
22
  }
23
23
  }
@@ -1,6 +1,6 @@
1
1
  export { default as makeId } from "./id.js";
2
2
  export { default as decorate } from "./decorate.js";
3
- export * from "./serialize.js";
3
+ export * from "./pack.js";
4
4
  export * from "./encodeTree.js";
5
5
  export * from "./decodeTree.js";
6
6
  export { encode as encodeValue, decode as decodeValue } from "./struct.js";
@@ -0,0 +1,2 @@
1
+ export function pack(children: any, parentVersion: any): any;
2
+ export function unpack(children: any, parentVersion: any): any;
@@ -1,2 +0,0 @@
1
- export function serialize(payload: any): string;
2
- export function deserialize(str: any): any;