@graffy/common 0.16.0-alpha.5 → 0.16.0-alpha.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.
- package/index.cjs +13 -14
- package/index.mjs +13 -14
- 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
|
@@ -119,6 +119,7 @@ const stringifyDescriptor = {
|
|
|
119
119
|
};
|
|
120
120
|
function addStringify(buffer) {
|
|
121
121
|
Object.defineProperties(buffer, {
|
|
122
|
+
toJSON: stringifyDescriptor,
|
|
122
123
|
toString: stringifyDescriptor,
|
|
123
124
|
[Symbol.for("nodejs.util.inspect.custom")]: stringifyDescriptor
|
|
124
125
|
});
|
|
@@ -869,7 +870,7 @@ function insertRange(current, change, result, start = 0) {
|
|
|
869
870
|
const { key, end } = change;
|
|
870
871
|
const keyIx = findFirst(current, key, start);
|
|
871
872
|
const endIx = findLast(current, end, keyIx);
|
|
872
|
-
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key,
|
|
873
|
+
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, end) <= 0 && cmp(current[keyIx].end || current[keyIx].key, key) >= 0)) {
|
|
873
874
|
return keyIx;
|
|
874
875
|
}
|
|
875
876
|
const appliedChange = [];
|
|
@@ -1400,7 +1401,7 @@ const props = [
|
|
|
1400
1401
|
function serializeKey(key) {
|
|
1401
1402
|
if (key[0] === STR) {
|
|
1402
1403
|
const last = key[key.length - 1];
|
|
1403
|
-
if (
|
|
1404
|
+
if (last !== 0 && last !== 255) {
|
|
1404
1405
|
return decode$4(key);
|
|
1405
1406
|
}
|
|
1406
1407
|
}
|
|
@@ -1411,7 +1412,9 @@ function deserializeKey(key) {
|
|
|
1411
1412
|
return decode(key.slice(1));
|
|
1412
1413
|
return encode$4(key);
|
|
1413
1414
|
}
|
|
1414
|
-
function
|
|
1415
|
+
function pack(children, parentVersion) {
|
|
1416
|
+
if (!Array.isArray(children))
|
|
1417
|
+
return children;
|
|
1415
1418
|
const array = children.map(
|
|
1416
1419
|
(node) => props.reduce(
|
|
1417
1420
|
(array2, prop, i) => {
|
|
@@ -1421,7 +1424,7 @@ function serializeNodes(children, parentVersion) {
|
|
|
1421
1424
|
if (prop === "version" && value === parentVersion)
|
|
1422
1425
|
return array2;
|
|
1423
1426
|
if (prop === "children")
|
|
1424
|
-
value =
|
|
1427
|
+
value = pack(value, node.version);
|
|
1425
1428
|
if (prop === "end")
|
|
1426
1429
|
value = serializeKey(value);
|
|
1427
1430
|
if (prop === "path")
|
|
@@ -1435,7 +1438,9 @@ function serializeNodes(children, parentVersion) {
|
|
|
1435
1438
|
);
|
|
1436
1439
|
return array;
|
|
1437
1440
|
}
|
|
1438
|
-
function
|
|
1441
|
+
function unpack(children, parentVersion) {
|
|
1442
|
+
if (!Array.isArray(children))
|
|
1443
|
+
return children;
|
|
1439
1444
|
const node = children.map(
|
|
1440
1445
|
([key, type, ...values]) => props.reduce(
|
|
1441
1446
|
(node2, prop, i) => {
|
|
@@ -1443,7 +1448,7 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1443
1448
|
return node2;
|
|
1444
1449
|
let value = values.shift();
|
|
1445
1450
|
if (prop === "children")
|
|
1446
|
-
value =
|
|
1451
|
+
value = unpack(value, node2.version);
|
|
1447
1452
|
if (prop === "end")
|
|
1448
1453
|
value = deserializeKey(value);
|
|
1449
1454
|
if (prop === "path")
|
|
@@ -1456,12 +1461,6 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1456
1461
|
);
|
|
1457
1462
|
return node;
|
|
1458
1463
|
}
|
|
1459
|
-
function serialize(payload) {
|
|
1460
|
-
return JSON.stringify(serializeNodes(payload));
|
|
1461
|
-
}
|
|
1462
|
-
function deserialize(str) {
|
|
1463
|
-
return deserializeNodes(JSON.parse(str));
|
|
1464
|
-
}
|
|
1465
1464
|
const ROOT_KEY = Symbol();
|
|
1466
1465
|
function encode(value, { version, isGraph } = {}) {
|
|
1467
1466
|
var _a;
|
|
@@ -1715,7 +1714,6 @@ exports.decodePath = decode$2;
|
|
|
1715
1714
|
exports.decodeQuery = decodeQuery;
|
|
1716
1715
|
exports.decodeValue = decode$4;
|
|
1717
1716
|
exports.decorate = decorate;
|
|
1718
|
-
exports.deserialize = deserialize;
|
|
1719
1717
|
exports.encodeArgs = encode$3;
|
|
1720
1718
|
exports.encodeGraph = encodeGraph;
|
|
1721
1719
|
exports.encodePath = encode$2;
|
|
@@ -1748,13 +1746,14 @@ exports.makeWatcher = makeWatcher;
|
|
|
1748
1746
|
exports.merge = merge;
|
|
1749
1747
|
exports.mergeObject = mergeObject;
|
|
1750
1748
|
exports.mergeStreams = mergeStreams;
|
|
1749
|
+
exports.pack = pack;
|
|
1751
1750
|
exports.remove = remove;
|
|
1752
|
-
exports.serialize = serialize;
|
|
1753
1751
|
exports.setVersion = setVersion;
|
|
1754
1752
|
exports.sieve = sieve;
|
|
1755
1753
|
exports.slice = slice;
|
|
1756
1754
|
exports.splitArgs = splitArgs;
|
|
1757
1755
|
exports.splitRef = splitRef;
|
|
1756
|
+
exports.unpack = unpack;
|
|
1758
1757
|
exports.unwrap = unwrap;
|
|
1759
1758
|
exports.unwrapObject = unwrapObject;
|
|
1760
1759
|
exports.wrap = wrap;
|
package/index.mjs
CHANGED
|
@@ -114,6 +114,7 @@ const stringifyDescriptor = {
|
|
|
114
114
|
};
|
|
115
115
|
function addStringify(buffer) {
|
|
116
116
|
Object.defineProperties(buffer, {
|
|
117
|
+
toJSON: stringifyDescriptor,
|
|
117
118
|
toString: stringifyDescriptor,
|
|
118
119
|
[Symbol.for("nodejs.util.inspect.custom")]: stringifyDescriptor
|
|
119
120
|
});
|
|
@@ -864,7 +865,7 @@ function insertRange(current, change, result, start = 0) {
|
|
|
864
865
|
const { key, end } = change;
|
|
865
866
|
const keyIx = findFirst(current, key, start);
|
|
866
867
|
const endIx = findLast(current, end, keyIx);
|
|
867
|
-
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key,
|
|
868
|
+
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, end) <= 0 && cmp(current[keyIx].end || current[keyIx].key, key) >= 0)) {
|
|
868
869
|
return keyIx;
|
|
869
870
|
}
|
|
870
871
|
const appliedChange = [];
|
|
@@ -1395,7 +1396,7 @@ const props = [
|
|
|
1395
1396
|
function serializeKey(key) {
|
|
1396
1397
|
if (key[0] === STR) {
|
|
1397
1398
|
const last = key[key.length - 1];
|
|
1398
|
-
if (
|
|
1399
|
+
if (last !== 0 && last !== 255) {
|
|
1399
1400
|
return decode$4(key);
|
|
1400
1401
|
}
|
|
1401
1402
|
}
|
|
@@ -1406,7 +1407,9 @@ function deserializeKey(key) {
|
|
|
1406
1407
|
return decode(key.slice(1));
|
|
1407
1408
|
return encode$4(key);
|
|
1408
1409
|
}
|
|
1409
|
-
function
|
|
1410
|
+
function pack(children, parentVersion) {
|
|
1411
|
+
if (!Array.isArray(children))
|
|
1412
|
+
return children;
|
|
1410
1413
|
const array = children.map(
|
|
1411
1414
|
(node) => props.reduce(
|
|
1412
1415
|
(array2, prop, i) => {
|
|
@@ -1416,7 +1419,7 @@ function serializeNodes(children, parentVersion) {
|
|
|
1416
1419
|
if (prop === "version" && value === parentVersion)
|
|
1417
1420
|
return array2;
|
|
1418
1421
|
if (prop === "children")
|
|
1419
|
-
value =
|
|
1422
|
+
value = pack(value, node.version);
|
|
1420
1423
|
if (prop === "end")
|
|
1421
1424
|
value = serializeKey(value);
|
|
1422
1425
|
if (prop === "path")
|
|
@@ -1430,7 +1433,9 @@ function serializeNodes(children, parentVersion) {
|
|
|
1430
1433
|
);
|
|
1431
1434
|
return array;
|
|
1432
1435
|
}
|
|
1433
|
-
function
|
|
1436
|
+
function unpack(children, parentVersion) {
|
|
1437
|
+
if (!Array.isArray(children))
|
|
1438
|
+
return children;
|
|
1434
1439
|
const node = children.map(
|
|
1435
1440
|
([key, type, ...values]) => props.reduce(
|
|
1436
1441
|
(node2, prop, i) => {
|
|
@@ -1438,7 +1443,7 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1438
1443
|
return node2;
|
|
1439
1444
|
let value = values.shift();
|
|
1440
1445
|
if (prop === "children")
|
|
1441
|
-
value =
|
|
1446
|
+
value = unpack(value, node2.version);
|
|
1442
1447
|
if (prop === "end")
|
|
1443
1448
|
value = deserializeKey(value);
|
|
1444
1449
|
if (prop === "path")
|
|
@@ -1451,12 +1456,6 @@ function deserializeNodes(children, parentVersion) {
|
|
|
1451
1456
|
);
|
|
1452
1457
|
return node;
|
|
1453
1458
|
}
|
|
1454
|
-
function serialize(payload) {
|
|
1455
|
-
return JSON.stringify(serializeNodes(payload));
|
|
1456
|
-
}
|
|
1457
|
-
function deserialize(str) {
|
|
1458
|
-
return deserializeNodes(JSON.parse(str));
|
|
1459
|
-
}
|
|
1460
1459
|
const ROOT_KEY = Symbol();
|
|
1461
1460
|
function encode(value, { version, isGraph } = {}) {
|
|
1462
1461
|
var _a;
|
|
@@ -1711,7 +1710,6 @@ export {
|
|
|
1711
1710
|
decodeQuery,
|
|
1712
1711
|
decode$4 as decodeValue,
|
|
1713
1712
|
decorate,
|
|
1714
|
-
deserialize,
|
|
1715
1713
|
encode$3 as encodeArgs,
|
|
1716
1714
|
encodeGraph,
|
|
1717
1715
|
encode$2 as encodePath,
|
|
@@ -1744,13 +1742,14 @@ export {
|
|
|
1744
1742
|
merge,
|
|
1745
1743
|
mergeObject,
|
|
1746
1744
|
mergeStreams,
|
|
1745
|
+
pack,
|
|
1747
1746
|
remove,
|
|
1748
|
-
serialize,
|
|
1749
1747
|
setVersion,
|
|
1750
1748
|
sieve,
|
|
1751
1749
|
slice,
|
|
1752
1750
|
splitArgs,
|
|
1753
1751
|
splitRef,
|
|
1752
|
+
unpack,
|
|
1754
1753
|
unwrap,
|
|
1755
1754
|
unwrapObject,
|
|
1756
1755
|
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.7",
|
|
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.7"
|
|
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";
|