@graffy/common 0.16.3-alpha.5 → 0.16.3-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 +23 -8
- package/index.mjs +23 -8
- package/package.json +2 -2
- package/types/util.d.ts +1 -0
package/index.cjs
CHANGED
|
@@ -70,6 +70,13 @@ function isDef(value) {
|
|
|
70
70
|
function isPlainObject(arg) {
|
|
71
71
|
return typeof arg === "object" && arg && !Array.isArray(arg) && !ArrayBuffer.isView(arg);
|
|
72
72
|
}
|
|
73
|
+
function clone$1(obj) {
|
|
74
|
+
if (Array.isArray(obj)) {
|
|
75
|
+
return obj.slice(0);
|
|
76
|
+
} else {
|
|
77
|
+
return { ...obj };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
73
80
|
function cmp(a, b) {
|
|
74
81
|
const l = a.length < b.length ? a.length : b.length;
|
|
75
82
|
for (let i = 0; i < l; i++) {
|
|
@@ -413,10 +420,10 @@ function decode$3(node) {
|
|
|
413
420
|
} else if (isMinKey(key) && isMaxKey(end) || isMinKey(end) && isMaxKey(key)) {
|
|
414
421
|
args.$all = true;
|
|
415
422
|
}
|
|
416
|
-
if (lower.key && !isMinKey(lower.key)) {
|
|
423
|
+
if (isDef(lower.key) && !isMinKey(lower.key)) {
|
|
417
424
|
args[lower.step === 1 ? "$after" : "$since"] = lower.key;
|
|
418
425
|
}
|
|
419
|
-
if (upper.key && !isMaxKey(upper.key)) {
|
|
426
|
+
if (isDef(upper.key) && !isMaxKey(upper.key)) {
|
|
420
427
|
args[upper.step === -1 ? "$before" : "$until"] = upper.key;
|
|
421
428
|
}
|
|
422
429
|
return args;
|
|
@@ -1119,10 +1126,11 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1119
1126
|
delete item.$key;
|
|
1120
1127
|
return collection;
|
|
1121
1128
|
}
|
|
1122
|
-
|
|
1129
|
+
let { $key, $val } = item;
|
|
1123
1130
|
delete item.$key;
|
|
1124
1131
|
delete item.$val;
|
|
1125
1132
|
if (typeof $val === "object") {
|
|
1133
|
+
$val = clone$1($val);
|
|
1126
1134
|
Object.defineProperty($val, "$val", { value: true });
|
|
1127
1135
|
}
|
|
1128
1136
|
collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
|
|
@@ -1551,7 +1559,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1551
1559
|
}
|
|
1552
1560
|
let putRange = [];
|
|
1553
1561
|
let prefixPuts = [];
|
|
1554
|
-
if (Array.isArray(object) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1562
|
+
if (Array.isArray(object) && !isDef($put) && !isDef($val) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1555
1563
|
putRange = [encode$3({ $since: 0, $until: Infinity })];
|
|
1556
1564
|
}
|
|
1557
1565
|
function classifyPut(put) {
|
|
@@ -1586,7 +1594,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1586
1594
|
return;
|
|
1587
1595
|
node.path = encode$2($ref);
|
|
1588
1596
|
} else if ($val === true) {
|
|
1589
|
-
node.value = props2;
|
|
1597
|
+
node.value = Array.isArray(object) ? clone$1(object) : props2;
|
|
1590
1598
|
} else if (isDef($val)) {
|
|
1591
1599
|
node.value = $val;
|
|
1592
1600
|
} else if (typeof object !== "object") {
|
|
@@ -1608,7 +1616,9 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1608
1616
|
const children = Object.keys(props2).sort().map((key2) => makeNode2(object[key2], key2, ver)).filter(Boolean);
|
|
1609
1617
|
if (children.length) {
|
|
1610
1618
|
node.children = children;
|
|
1611
|
-
} else if (
|
|
1619
|
+
} else if (putRange.length)
|
|
1620
|
+
;
|
|
1621
|
+
else if (isGraph) {
|
|
1612
1622
|
if (!(isDef($key) || isDef($put)))
|
|
1613
1623
|
return;
|
|
1614
1624
|
if (node.key && !node.end)
|
|
@@ -1619,8 +1629,12 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1619
1629
|
node.value = 1;
|
|
1620
1630
|
}
|
|
1621
1631
|
}
|
|
1622
|
-
if (isGraph && putRange.length) {
|
|
1623
|
-
const putRangeClone = putRange.map(({ key: key2, end }) => ({
|
|
1632
|
+
if (isGraph && putRange.length && !isDef(node.path) && !isDef(node.value)) {
|
|
1633
|
+
const putRangeClone = putRange.map(({ key: key2, end }) => ({
|
|
1634
|
+
key: key2,
|
|
1635
|
+
end,
|
|
1636
|
+
version: 0
|
|
1637
|
+
}));
|
|
1624
1638
|
node.children = merge(putRangeClone, node.children || []);
|
|
1625
1639
|
}
|
|
1626
1640
|
if (((_a2 = node.children) == null ? void 0 : _a2.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
|
|
@@ -1753,6 +1767,7 @@ exports.MAX_KEY = MAX_KEY;
|
|
|
1753
1767
|
exports.MIN_KEY = MIN_KEY;
|
|
1754
1768
|
exports.add = add;
|
|
1755
1769
|
exports.addStringify = addStringify;
|
|
1770
|
+
exports.clone = clone$1;
|
|
1756
1771
|
exports.cloneObject = cloneObject;
|
|
1757
1772
|
exports.cmp = cmp;
|
|
1758
1773
|
exports.decodeArgs = decode$3;
|
package/index.mjs
CHANGED
|
@@ -68,6 +68,13 @@ function isDef(value) {
|
|
|
68
68
|
function isPlainObject(arg) {
|
|
69
69
|
return typeof arg === "object" && arg && !Array.isArray(arg) && !ArrayBuffer.isView(arg);
|
|
70
70
|
}
|
|
71
|
+
function clone$1(obj) {
|
|
72
|
+
if (Array.isArray(obj)) {
|
|
73
|
+
return obj.slice(0);
|
|
74
|
+
} else {
|
|
75
|
+
return { ...obj };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
71
78
|
function cmp(a, b) {
|
|
72
79
|
const l = a.length < b.length ? a.length : b.length;
|
|
73
80
|
for (let i = 0; i < l; i++) {
|
|
@@ -411,10 +418,10 @@ function decode$3(node) {
|
|
|
411
418
|
} else if (isMinKey(key) && isMaxKey(end) || isMinKey(end) && isMaxKey(key)) {
|
|
412
419
|
args.$all = true;
|
|
413
420
|
}
|
|
414
|
-
if (lower.key && !isMinKey(lower.key)) {
|
|
421
|
+
if (isDef(lower.key) && !isMinKey(lower.key)) {
|
|
415
422
|
args[lower.step === 1 ? "$after" : "$since"] = lower.key;
|
|
416
423
|
}
|
|
417
|
-
if (upper.key && !isMaxKey(upper.key)) {
|
|
424
|
+
if (isDef(upper.key) && !isMaxKey(upper.key)) {
|
|
418
425
|
args[upper.step === -1 ? "$before" : "$until"] = upper.key;
|
|
419
426
|
}
|
|
420
427
|
return args;
|
|
@@ -1117,10 +1124,11 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1117
1124
|
delete item.$key;
|
|
1118
1125
|
return collection;
|
|
1119
1126
|
}
|
|
1120
|
-
|
|
1127
|
+
let { $key, $val } = item;
|
|
1121
1128
|
delete item.$key;
|
|
1122
1129
|
delete item.$val;
|
|
1123
1130
|
if (typeof $val === "object") {
|
|
1131
|
+
$val = clone$1($val);
|
|
1124
1132
|
Object.defineProperty($val, "$val", { value: true });
|
|
1125
1133
|
}
|
|
1126
1134
|
collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
|
|
@@ -1549,7 +1557,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1549
1557
|
}
|
|
1550
1558
|
let putRange = [];
|
|
1551
1559
|
let prefixPuts = [];
|
|
1552
|
-
if (Array.isArray(object) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1560
|
+
if (Array.isArray(object) && !isDef($put) && !isDef($val) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1553
1561
|
putRange = [encode$3({ $since: 0, $until: Infinity })];
|
|
1554
1562
|
}
|
|
1555
1563
|
function classifyPut(put) {
|
|
@@ -1584,7 +1592,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1584
1592
|
return;
|
|
1585
1593
|
node.path = encode$2($ref);
|
|
1586
1594
|
} else if ($val === true) {
|
|
1587
|
-
node.value = props2;
|
|
1595
|
+
node.value = Array.isArray(object) ? clone$1(object) : props2;
|
|
1588
1596
|
} else if (isDef($val)) {
|
|
1589
1597
|
node.value = $val;
|
|
1590
1598
|
} else if (typeof object !== "object") {
|
|
@@ -1606,7 +1614,9 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1606
1614
|
const children = Object.keys(props2).sort().map((key2) => makeNode2(object[key2], key2, ver)).filter(Boolean);
|
|
1607
1615
|
if (children.length) {
|
|
1608
1616
|
node.children = children;
|
|
1609
|
-
} else if (
|
|
1617
|
+
} else if (putRange.length)
|
|
1618
|
+
;
|
|
1619
|
+
else if (isGraph) {
|
|
1610
1620
|
if (!(isDef($key) || isDef($put)))
|
|
1611
1621
|
return;
|
|
1612
1622
|
if (node.key && !node.end)
|
|
@@ -1617,8 +1627,12 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1617
1627
|
node.value = 1;
|
|
1618
1628
|
}
|
|
1619
1629
|
}
|
|
1620
|
-
if (isGraph && putRange.length) {
|
|
1621
|
-
const putRangeClone = putRange.map(({ key: key2, end }) => ({
|
|
1630
|
+
if (isGraph && putRange.length && !isDef(node.path) && !isDef(node.value)) {
|
|
1631
|
+
const putRangeClone = putRange.map(({ key: key2, end }) => ({
|
|
1632
|
+
key: key2,
|
|
1633
|
+
end,
|
|
1634
|
+
version: 0
|
|
1635
|
+
}));
|
|
1622
1636
|
node.children = merge(putRangeClone, node.children || []);
|
|
1623
1637
|
}
|
|
1624
1638
|
if (((_a2 = node.children) == null ? void 0 : _a2.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
|
|
@@ -1752,6 +1766,7 @@ export {
|
|
|
1752
1766
|
MIN_KEY,
|
|
1753
1767
|
add,
|
|
1754
1768
|
addStringify,
|
|
1769
|
+
clone$1 as clone,
|
|
1755
1770
|
cloneObject,
|
|
1756
1771
|
cmp,
|
|
1757
1772
|
decode$3 as decodeArgs,
|
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.3-alpha.
|
|
5
|
+
"version": "0.16.3-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.3-alpha.
|
|
21
|
+
"@graffy/stream": "0.16.3-alpha.6"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/types/util.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export function errIf(message: any, condition: any, args: any): void;
|
|
|
7
7
|
export function isEmpty(object: any): boolean;
|
|
8
8
|
export function isDef(value: any): boolean;
|
|
9
9
|
export function isPlainObject(arg: any): boolean;
|
|
10
|
+
export function clone(obj: any): any;
|
|
10
11
|
export function cmp(a: any, b: any): 0 | 1 | -1;
|
|
11
12
|
export function find(items: any, compare: any, first?: number, last?: any): number;
|
|
12
13
|
export function addStringify(buffer: any): any;
|