@graffy/common 0.16.0-alpha.4 → 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 +17 -15
- package/index.mjs +17 -15
- package/package.json +2 -2
- package/types/coding/index.d.ts +1 -1
- package/types/coding/pack.d.ts +2 -0
- package/types/coding/serialize.d.ts +0 -2
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,
|
|
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 = [];
|
|
@@ -1398,8 +1398,12 @@ const props = [
|
|
|
1398
1398
|
"children"
|
|
1399
1399
|
];
|
|
1400
1400
|
function serializeKey(key) {
|
|
1401
|
-
if (key[0] === STR)
|
|
1402
|
-
|
|
1401
|
+
if (key[0] === STR) {
|
|
1402
|
+
const last = key[key.length - 1];
|
|
1403
|
+
if (cmp(last, MIN_KEY) !== 0 && cmp(last, MAX_KEY) !== 0) {
|
|
1404
|
+
return decode$4(key);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1403
1407
|
return "\0" + encode$1(key);
|
|
1404
1408
|
}
|
|
1405
1409
|
function deserializeKey(key) {
|
|
@@ -1407,7 +1411,9 @@ function deserializeKey(key) {
|
|
|
1407
1411
|
return decode(key.slice(1));
|
|
1408
1412
|
return encode$4(key);
|
|
1409
1413
|
}
|
|
1410
|
-
function
|
|
1414
|
+
function pack(children, parentVersion) {
|
|
1415
|
+
if (!Array.isArray(children))
|
|
1416
|
+
return children;
|
|
1411
1417
|
const array = children.map(
|
|
1412
1418
|
(node) => props.reduce(
|
|
1413
1419
|
(array2, prop, i) => {
|
|
@@ -1417,7 +1423,7 @@ function serializeNodes(children, parentVersion) {
|
|
|
1417
1423
|
if (prop === "version" && value === parentVersion)
|
|
1418
1424
|
return array2;
|
|
1419
1425
|
if (prop === "children")
|
|
1420
|
-
value =
|
|
1426
|
+
value = pack(value, node.version);
|
|
1421
1427
|
if (prop === "end")
|
|
1422
1428
|
value = serializeKey(value);
|
|
1423
1429
|
if (prop === "path")
|
|
@@ -1431,7 +1437,9 @@ function serializeNodes(children, parentVersion) {
|
|
|
1431
1437
|
);
|
|
1432
1438
|
return array;
|
|
1433
1439
|
}
|
|
1434
|
-
function
|
|
1440
|
+
function unpack(children, parentVersion) {
|
|
1441
|
+
if (!Array.isArray(children))
|
|
1442
|
+
return children;
|
|
1435
1443
|
const node = children.map(
|
|
1436
1444
|
([key, type, ...values]) => props.reduce(
|
|
1437
1445
|
(node2, prop, i) => {
|
|
@@ -1439,7 +1447,7 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1439
1447
|
return node2;
|
|
1440
1448
|
let value = values.shift();
|
|
1441
1449
|
if (prop === "children")
|
|
1442
|
-
value =
|
|
1450
|
+
value = unpack(value, node2.version);
|
|
1443
1451
|
if (prop === "end")
|
|
1444
1452
|
value = deserializeKey(value);
|
|
1445
1453
|
if (prop === "path")
|
|
@@ -1452,12 +1460,6 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1452
1460
|
);
|
|
1453
1461
|
return node;
|
|
1454
1462
|
}
|
|
1455
|
-
function serialize(payload) {
|
|
1456
|
-
return JSON.stringify(serializeNodes(payload));
|
|
1457
|
-
}
|
|
1458
|
-
function deserialize(str) {
|
|
1459
|
-
return deserializeNodes(JSON.parse(str));
|
|
1460
|
-
}
|
|
1461
1463
|
const ROOT_KEY = Symbol();
|
|
1462
1464
|
function encode(value, { version, isGraph } = {}) {
|
|
1463
1465
|
var _a;
|
|
@@ -1711,7 +1713,6 @@ exports.decodePath = decode$2;
|
|
|
1711
1713
|
exports.decodeQuery = decodeQuery;
|
|
1712
1714
|
exports.decodeValue = decode$4;
|
|
1713
1715
|
exports.decorate = decorate;
|
|
1714
|
-
exports.deserialize = deserialize;
|
|
1715
1716
|
exports.encodeArgs = encode$3;
|
|
1716
1717
|
exports.encodeGraph = encodeGraph;
|
|
1717
1718
|
exports.encodePath = encode$2;
|
|
@@ -1744,13 +1745,14 @@ exports.makeWatcher = makeWatcher;
|
|
|
1744
1745
|
exports.merge = merge;
|
|
1745
1746
|
exports.mergeObject = mergeObject;
|
|
1746
1747
|
exports.mergeStreams = mergeStreams;
|
|
1748
|
+
exports.pack = pack;
|
|
1747
1749
|
exports.remove = remove;
|
|
1748
|
-
exports.serialize = serialize;
|
|
1749
1750
|
exports.setVersion = setVersion;
|
|
1750
1751
|
exports.sieve = sieve;
|
|
1751
1752
|
exports.slice = slice;
|
|
1752
1753
|
exports.splitArgs = splitArgs;
|
|
1753
1754
|
exports.splitRef = splitRef;
|
|
1755
|
+
exports.unpack = unpack;
|
|
1754
1756
|
exports.unwrap = unwrap;
|
|
1755
1757
|
exports.unwrapObject = unwrapObject;
|
|
1756
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,
|
|
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 = [];
|
|
@@ -1393,8 +1393,12 @@ const props = [
|
|
|
1393
1393
|
"children"
|
|
1394
1394
|
];
|
|
1395
1395
|
function serializeKey(key) {
|
|
1396
|
-
if (key[0] === STR)
|
|
1397
|
-
|
|
1396
|
+
if (key[0] === STR) {
|
|
1397
|
+
const last = key[key.length - 1];
|
|
1398
|
+
if (cmp(last, MIN_KEY) !== 0 && cmp(last, MAX_KEY) !== 0) {
|
|
1399
|
+
return decode$4(key);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1398
1402
|
return "\0" + encode$1(key);
|
|
1399
1403
|
}
|
|
1400
1404
|
function deserializeKey(key) {
|
|
@@ -1402,7 +1406,9 @@ function deserializeKey(key) {
|
|
|
1402
1406
|
return decode(key.slice(1));
|
|
1403
1407
|
return encode$4(key);
|
|
1404
1408
|
}
|
|
1405
|
-
function
|
|
1409
|
+
function pack(children, parentVersion) {
|
|
1410
|
+
if (!Array.isArray(children))
|
|
1411
|
+
return children;
|
|
1406
1412
|
const array = children.map(
|
|
1407
1413
|
(node) => props.reduce(
|
|
1408
1414
|
(array2, prop, i) => {
|
|
@@ -1412,7 +1418,7 @@ function serializeNodes(children, parentVersion) {
|
|
|
1412
1418
|
if (prop === "version" && value === parentVersion)
|
|
1413
1419
|
return array2;
|
|
1414
1420
|
if (prop === "children")
|
|
1415
|
-
value =
|
|
1421
|
+
value = pack(value, node.version);
|
|
1416
1422
|
if (prop === "end")
|
|
1417
1423
|
value = serializeKey(value);
|
|
1418
1424
|
if (prop === "path")
|
|
@@ -1426,7 +1432,9 @@ function serializeNodes(children, parentVersion) {
|
|
|
1426
1432
|
);
|
|
1427
1433
|
return array;
|
|
1428
1434
|
}
|
|
1429
|
-
function
|
|
1435
|
+
function unpack(children, parentVersion) {
|
|
1436
|
+
if (!Array.isArray(children))
|
|
1437
|
+
return children;
|
|
1430
1438
|
const node = children.map(
|
|
1431
1439
|
([key, type, ...values]) => props.reduce(
|
|
1432
1440
|
(node2, prop, i) => {
|
|
@@ -1434,7 +1442,7 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1434
1442
|
return node2;
|
|
1435
1443
|
let value = values.shift();
|
|
1436
1444
|
if (prop === "children")
|
|
1437
|
-
value =
|
|
1445
|
+
value = unpack(value, node2.version);
|
|
1438
1446
|
if (prop === "end")
|
|
1439
1447
|
value = deserializeKey(value);
|
|
1440
1448
|
if (prop === "path")
|
|
@@ -1447,12 +1455,6 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1447
1455
|
);
|
|
1448
1456
|
return node;
|
|
1449
1457
|
}
|
|
1450
|
-
function serialize(payload) {
|
|
1451
|
-
return JSON.stringify(serializeNodes(payload));
|
|
1452
|
-
}
|
|
1453
|
-
function deserialize(str) {
|
|
1454
|
-
return deserializeNodes(JSON.parse(str));
|
|
1455
|
-
}
|
|
1456
1458
|
const ROOT_KEY = Symbol();
|
|
1457
1459
|
function encode(value, { version, isGraph } = {}) {
|
|
1458
1460
|
var _a;
|
|
@@ -1707,7 +1709,6 @@ export {
|
|
|
1707
1709
|
decodeQuery,
|
|
1708
1710
|
decode$4 as decodeValue,
|
|
1709
1711
|
decorate,
|
|
1710
|
-
deserialize,
|
|
1711
1712
|
encode$3 as encodeArgs,
|
|
1712
1713
|
encodeGraph,
|
|
1713
1714
|
encode$2 as encodePath,
|
|
@@ -1740,13 +1741,14 @@ export {
|
|
|
1740
1741
|
merge,
|
|
1741
1742
|
mergeObject,
|
|
1742
1743
|
mergeStreams,
|
|
1744
|
+
pack,
|
|
1743
1745
|
remove,
|
|
1744
|
-
serialize,
|
|
1745
1746
|
setVersion,
|
|
1746
1747
|
sieve,
|
|
1747
1748
|
slice,
|
|
1748
1749
|
splitArgs,
|
|
1749
1750
|
splitRef,
|
|
1751
|
+
unpack,
|
|
1750
1752
|
unwrap,
|
|
1751
1753
|
unwrapObject,
|
|
1752
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
|
+
"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.
|
|
21
|
+
"@graffy/stream": "0.16.0-alpha.6"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/types/coding/index.d.ts
CHANGED
|
@@ -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 "./
|
|
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";
|