@graffy/common 0.16.0 → 0.16.2-alpha.1
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 +34 -43
- package/index.mjs +30 -36
- package/package.json +2 -2
- package/types/util.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const isEqual = require("lodash/isEqual.js");
|
|
4
4
|
const mergeIterators = require("merge-async-iterators");
|
|
5
5
|
const stream = require("@graffy/stream");
|
|
6
|
-
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
7
|
-
const isEqual__default = /* @__PURE__ */ _interopDefaultLegacy(isEqual);
|
|
8
|
-
const mergeIterators__default = /* @__PURE__ */ _interopDefaultLegacy(mergeIterators);
|
|
9
6
|
const textEncoder = new TextEncoder();
|
|
10
7
|
const textDecoder = new TextDecoder("utf-8");
|
|
11
8
|
function encode$6(string) {
|
|
@@ -54,7 +51,7 @@ function isMaxKey(key) {
|
|
|
54
51
|
return key.length === 1 && key[0] === 255;
|
|
55
52
|
}
|
|
56
53
|
function err(message, { cause = null, ...args } = {}) {
|
|
57
|
-
const e = new Error(message + (args ?
|
|
54
|
+
const e = new Error(message + (args ? ` ${JSON.stringify(args)}` : ""));
|
|
58
55
|
e.cause = cause;
|
|
59
56
|
throw e;
|
|
60
57
|
}
|
|
@@ -107,7 +104,7 @@ const stringifyDescriptor = {
|
|
|
107
104
|
value: function() {
|
|
108
105
|
var _a;
|
|
109
106
|
if ((this == null ? void 0 : this.length) === 0)
|
|
110
|
-
return "
|
|
107
|
+
return "·";
|
|
111
108
|
let str = "";
|
|
112
109
|
let bull = false;
|
|
113
110
|
(_a = this == null ? void 0 : this.forEach) == null ? void 0 : _a.call(this, (value, i) => {
|
|
@@ -115,7 +112,7 @@ const stringifyDescriptor = {
|
|
|
115
112
|
str += String.fromCharCode(value);
|
|
116
113
|
bull = true;
|
|
117
114
|
} else {
|
|
118
|
-
str += (bull ? "
|
|
115
|
+
str += (bull ? "·" : "") + `0${value.toString(16)}`.slice(-2) + (i < this.length - 1 ? "·" : "");
|
|
119
116
|
bull = false;
|
|
120
117
|
}
|
|
121
118
|
});
|
|
@@ -274,7 +271,7 @@ function decode$4(buffer) {
|
|
|
274
271
|
pushToken(type, {});
|
|
275
272
|
break;
|
|
276
273
|
default:
|
|
277
|
-
throw new Error(
|
|
274
|
+
throw new Error(`Invalid byte ${type} at ${start}`);
|
|
278
275
|
}
|
|
279
276
|
}
|
|
280
277
|
return stack[0][0];
|
|
@@ -432,7 +429,7 @@ function encode$2(path) {
|
|
|
432
429
|
path = path.split(PATH_SEPARATOR);
|
|
433
430
|
}
|
|
434
431
|
if (!Array.isArray(path)) {
|
|
435
|
-
throw Error(
|
|
432
|
+
throw Error(`encodePath.invalid:${JSON.stringify(path)}`);
|
|
436
433
|
}
|
|
437
434
|
function encodeSegment(seg) {
|
|
438
435
|
if (ArrayBuffer.isView(seg))
|
|
@@ -451,7 +448,7 @@ function encode$2(path) {
|
|
|
451
448
|
}
|
|
452
449
|
function decode$2(path) {
|
|
453
450
|
if (!Array.isArray(path)) {
|
|
454
|
-
throw Error(
|
|
451
|
+
throw Error(`decodePath.invalid:${JSON.stringify(path)}`);
|
|
455
452
|
}
|
|
456
453
|
return path.map((key) => decode$3({ key }));
|
|
457
454
|
}
|
|
@@ -500,7 +497,7 @@ function isBranch(node) {
|
|
|
500
497
|
return node && typeof node.children !== "undefined";
|
|
501
498
|
}
|
|
502
499
|
function isPrefix(node) {
|
|
503
|
-
return node
|
|
500
|
+
return node == null ? void 0 : node.prefix;
|
|
504
501
|
}
|
|
505
502
|
function isLink(node) {
|
|
506
503
|
return node && typeof node.path !== "undefined";
|
|
@@ -596,7 +593,7 @@ function mergeRanges$1(base, node) {
|
|
|
596
593
|
}
|
|
597
594
|
function insertNode$1(current, change, start = 0) {
|
|
598
595
|
if (!current)
|
|
599
|
-
throw new Error(
|
|
596
|
+
throw new Error(`merge.insertNode: ${current}`);
|
|
600
597
|
const key = change.key;
|
|
601
598
|
const index = findFirst(current, key, start);
|
|
602
599
|
const node = current[index];
|
|
@@ -659,7 +656,7 @@ function wrapValue(value, path, version = 0) {
|
|
|
659
656
|
}
|
|
660
657
|
function wrap(children, path, version = 0, prefix = false) {
|
|
661
658
|
if (!Array.isArray(path))
|
|
662
|
-
throw Error(
|
|
659
|
+
throw Error(`wrap.path_not_array ${path}`);
|
|
663
660
|
if (!path.length)
|
|
664
661
|
return children;
|
|
665
662
|
let i = path.length - 1;
|
|
@@ -678,7 +675,7 @@ function wrap(children, path, version = 0, prefix = false) {
|
|
|
678
675
|
}
|
|
679
676
|
function unwrap(tree, path) {
|
|
680
677
|
if (!Array.isArray(path))
|
|
681
|
-
throw Error(
|
|
678
|
+
throw Error(`unwrap.path_not_array ${path}`);
|
|
682
679
|
let children = tree;
|
|
683
680
|
let node = { children };
|
|
684
681
|
for (let i = 0; i < path.length; i++) {
|
|
@@ -708,7 +705,7 @@ function getNodeValue(node) {
|
|
|
708
705
|
}
|
|
709
706
|
function remove(children, path) {
|
|
710
707
|
if (!Array.isArray(path))
|
|
711
|
-
throw Error(
|
|
708
|
+
throw Error(`del.path_not_array ${path}`);
|
|
712
709
|
if (!children)
|
|
713
710
|
return null;
|
|
714
711
|
if (!path.length)
|
|
@@ -989,9 +986,9 @@ function updateNode(current, index, change, result) {
|
|
|
989
986
|
return index + 1;
|
|
990
987
|
}
|
|
991
988
|
function isPathEqual(first, second) {
|
|
992
|
-
if (!first
|
|
989
|
+
if (!(first || second))
|
|
993
990
|
return true;
|
|
994
|
-
if (!first
|
|
991
|
+
if (!(first && second))
|
|
995
992
|
return false;
|
|
996
993
|
if (first.length !== second.length)
|
|
997
994
|
return false;
|
|
@@ -1023,7 +1020,7 @@ function getNewerChange(node, base) {
|
|
|
1023
1020
|
}
|
|
1024
1021
|
function setVersion(graph, version, onlyIfZero = false) {
|
|
1025
1022
|
for (const node of graph) {
|
|
1026
|
-
if (!onlyIfZero
|
|
1023
|
+
if (!(onlyIfZero && node.version))
|
|
1027
1024
|
node.version = version;
|
|
1028
1025
|
if (node.children)
|
|
1029
1026
|
setVersion(node.children, version, onlyIfZero);
|
|
@@ -1152,14 +1149,14 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1152
1149
|
if (!args)
|
|
1153
1150
|
args = {};
|
|
1154
1151
|
if (typeof args === "string") {
|
|
1155
|
-
throw Error(
|
|
1152
|
+
throw Error(`decode.unencoded_prefix: ${args}`);
|
|
1156
1153
|
}
|
|
1157
1154
|
if (isLink(node)) {
|
|
1158
1155
|
args.$all = true;
|
|
1159
1156
|
const $ref = decode$2(node.path);
|
|
1160
1157
|
const lastKey = $ref[$ref.length - 1];
|
|
1161
1158
|
if (typeof lastKey === "string") {
|
|
1162
|
-
throw Error(
|
|
1159
|
+
throw Error(`decode.unencoded_prefix_ref: ${node.path}`);
|
|
1163
1160
|
}
|
|
1164
1161
|
lastKey.$all = true;
|
|
1165
1162
|
const linkObject = { $key: args };
|
|
@@ -1168,11 +1165,11 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1168
1165
|
}
|
|
1169
1166
|
const children = decodeChildren(node.children);
|
|
1170
1167
|
if (!Array.isArray(children)) {
|
|
1171
|
-
throw Error(
|
|
1168
|
+
throw Error(`decode.prefix_without_encoded_child_keys:${node.key}`);
|
|
1172
1169
|
}
|
|
1173
1170
|
for (const child of children) {
|
|
1174
1171
|
if (typeof child.$key === "string") {
|
|
1175
|
-
throw Error(
|
|
1172
|
+
throw Error(`decode.prefix_with_unencoded_child_key:${child.$key}`);
|
|
1176
1173
|
}
|
|
1177
1174
|
if (!splitArgs(child.$key)[0]) {
|
|
1178
1175
|
child.$key = { $cursor: child.$key };
|
|
@@ -1252,12 +1249,12 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1252
1249
|
}
|
|
1253
1250
|
const { $key, $chi, ...props2 } = item;
|
|
1254
1251
|
const subQuery = $chi || (isEmpty(props2) ? 1 : props2);
|
|
1255
|
-
if (!isPlainObject($key)
|
|
1252
|
+
if (!(isPlainObject($key) && splitArgs($key)[0])) {
|
|
1256
1253
|
return construct(descend(plumGraph, $key), subQuery);
|
|
1257
1254
|
}
|
|
1258
1255
|
if (pageKey) {
|
|
1259
1256
|
throw Error(
|
|
1260
|
-
|
|
1257
|
+
`decorate.multi_range_query:${JSON.stringify({ $key, pageKey })}`
|
|
1261
1258
|
);
|
|
1262
1259
|
}
|
|
1263
1260
|
pageKey = $key;
|
|
@@ -1433,7 +1430,7 @@ function serializeKey(key) {
|
|
|
1433
1430
|
return decode$4(key);
|
|
1434
1431
|
}
|
|
1435
1432
|
}
|
|
1436
|
-
return
|
|
1433
|
+
return `\0${encode$1(key)}`;
|
|
1437
1434
|
}
|
|
1438
1435
|
function deserializeKey(key) {
|
|
1439
1436
|
if (key[0] === "\0")
|
|
@@ -1495,15 +1492,8 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1495
1492
|
const links = [];
|
|
1496
1493
|
function pushLink($ref, $ver, props2, $val, $chi) {
|
|
1497
1494
|
const [range, _] = splitRef($ref);
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
void 0,
|
|
1501
|
-
$ver
|
|
1502
|
-
).children : isDef($chi) ? makeNode2(
|
|
1503
|
-
range ? [{ $key: range, $chi }] : $chi,
|
|
1504
|
-
void 0,
|
|
1505
|
-
$ver
|
|
1506
|
-
).children : isDef($val) ? $val : isGraph ? void 0 : 1;
|
|
1495
|
+
const node = !isEmpty(props2) ? makeNode2(range ? [{ $key: range, ...props2 }] : props2, void 0, $ver) : isDef($chi) ? makeNode2(range ? [{ $key: range, $chi }] : $chi, void 0, $ver) : null;
|
|
1496
|
+
const children = node ? node.children : isDef($val) ? $val : isGraph ? void 0 : 1;
|
|
1507
1497
|
if (children) {
|
|
1508
1498
|
links.push(wrap(children, encode$2($ref), $ver, !!range)[0]);
|
|
1509
1499
|
}
|
|
@@ -1536,7 +1526,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1536
1526
|
if (isPlainObject($key)) {
|
|
1537
1527
|
const [page, filter] = splitArgs($key);
|
|
1538
1528
|
if (page) {
|
|
1539
|
-
const foundPuts = parentPuts.filter(([_, putFilter]) =>
|
|
1529
|
+
const foundPuts = parentPuts.filter(([_, putFilter]) => isEqual(filter, putFilter)).map(([range]) => range);
|
|
1540
1530
|
if (isGraph && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props2))) {
|
|
1541
1531
|
object.$key = filter || {};
|
|
1542
1532
|
object.$put = foundPuts;
|
|
@@ -1559,7 +1549,8 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1559
1549
|
}
|
|
1560
1550
|
}
|
|
1561
1551
|
}
|
|
1562
|
-
let putQuery = []
|
|
1552
|
+
let putQuery = [];
|
|
1553
|
+
let prefixPuts = [];
|
|
1563
1554
|
if (Array.isArray(object) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1564
1555
|
putQuery = [encode$3({ $since: 0, $until: Infinity })];
|
|
1565
1556
|
}
|
|
@@ -1618,7 +1609,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1618
1609
|
if (children.length) {
|
|
1619
1610
|
node.children = children;
|
|
1620
1611
|
} else if (isGraph) {
|
|
1621
|
-
if (!isDef($key)
|
|
1612
|
+
if (!(isDef($key) || isDef($put)))
|
|
1622
1613
|
return;
|
|
1623
1614
|
if (node.key && !node.end)
|
|
1624
1615
|
node.end = node.key;
|
|
@@ -1665,7 +1656,7 @@ async function* mergeStreams(...streams) {
|
|
|
1665
1656
|
merge(merged, value);
|
|
1666
1657
|
yield merged;
|
|
1667
1658
|
}
|
|
1668
|
-
yield*
|
|
1659
|
+
yield* mergeIterators(streams);
|
|
1669
1660
|
}
|
|
1670
1661
|
function makeWatcher() {
|
|
1671
1662
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -1716,7 +1707,7 @@ function cloneObject(object) {
|
|
|
1716
1707
|
}
|
|
1717
1708
|
function wrapObject(object, path) {
|
|
1718
1709
|
if (!Array.isArray(path))
|
|
1719
|
-
throw Error(
|
|
1710
|
+
throw Error(`wrapObject.path_not_array ${path}`);
|
|
1720
1711
|
for (let i = path.length - 1; i >= 0; i--) {
|
|
1721
1712
|
const $key = path[i];
|
|
1722
1713
|
if (typeof $key === "string") {
|
|
@@ -1731,26 +1722,26 @@ function wrapObject(object, path) {
|
|
|
1731
1722
|
}
|
|
1732
1723
|
function unwrapObject(object, path) {
|
|
1733
1724
|
if (!Array.isArray(path))
|
|
1734
|
-
throw Error(
|
|
1725
|
+
throw Error(`unwrapObject.path_not_array ${path}`);
|
|
1735
1726
|
for (let i = 0; i < path.length; i++) {
|
|
1736
1727
|
if (!object || typeof object !== "object")
|
|
1737
1728
|
return;
|
|
1738
1729
|
const $key = path[i];
|
|
1739
1730
|
if (typeof $key === "string") {
|
|
1740
1731
|
if (Array.isArray(object)) {
|
|
1741
|
-
throw Error(
|
|
1732
|
+
throw Error(`unwrapObject.string_key_array:${$key}`);
|
|
1742
1733
|
}
|
|
1743
1734
|
object = object[$key];
|
|
1744
1735
|
} else {
|
|
1745
1736
|
if (!Array.isArray(object)) {
|
|
1746
|
-
throw Error(
|
|
1737
|
+
throw Error(`unwrapObject.arg_key_object:${JSON.stringify($key)}`);
|
|
1747
1738
|
}
|
|
1748
1739
|
const [page, filter] = splitArgs($key);
|
|
1749
1740
|
if (page && !page.$cursor) {
|
|
1750
1741
|
return object;
|
|
1751
1742
|
} else {
|
|
1752
1743
|
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1753
|
-
object = object.find(({ $key: $key2 }) =>
|
|
1744
|
+
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1754
1745
|
}
|
|
1755
1746
|
}
|
|
1756
1747
|
}
|
package/index.mjs
CHANGED
|
@@ -49,7 +49,7 @@ function isMaxKey(key) {
|
|
|
49
49
|
return key.length === 1 && key[0] === 255;
|
|
50
50
|
}
|
|
51
51
|
function err(message, { cause = null, ...args } = {}) {
|
|
52
|
-
const e = new Error(message + (args ?
|
|
52
|
+
const e = new Error(message + (args ? ` ${JSON.stringify(args)}` : ""));
|
|
53
53
|
e.cause = cause;
|
|
54
54
|
throw e;
|
|
55
55
|
}
|
|
@@ -102,7 +102,7 @@ const stringifyDescriptor = {
|
|
|
102
102
|
value: function() {
|
|
103
103
|
var _a;
|
|
104
104
|
if ((this == null ? void 0 : this.length) === 0)
|
|
105
|
-
return "
|
|
105
|
+
return "·";
|
|
106
106
|
let str = "";
|
|
107
107
|
let bull = false;
|
|
108
108
|
(_a = this == null ? void 0 : this.forEach) == null ? void 0 : _a.call(this, (value, i) => {
|
|
@@ -110,7 +110,7 @@ const stringifyDescriptor = {
|
|
|
110
110
|
str += String.fromCharCode(value);
|
|
111
111
|
bull = true;
|
|
112
112
|
} else {
|
|
113
|
-
str += (bull ? "
|
|
113
|
+
str += (bull ? "·" : "") + `0${value.toString(16)}`.slice(-2) + (i < this.length - 1 ? "·" : "");
|
|
114
114
|
bull = false;
|
|
115
115
|
}
|
|
116
116
|
});
|
|
@@ -269,7 +269,7 @@ function decode$4(buffer) {
|
|
|
269
269
|
pushToken(type, {});
|
|
270
270
|
break;
|
|
271
271
|
default:
|
|
272
|
-
throw new Error(
|
|
272
|
+
throw new Error(`Invalid byte ${type} at ${start}`);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
return stack[0][0];
|
|
@@ -427,7 +427,7 @@ function encode$2(path) {
|
|
|
427
427
|
path = path.split(PATH_SEPARATOR);
|
|
428
428
|
}
|
|
429
429
|
if (!Array.isArray(path)) {
|
|
430
|
-
throw Error(
|
|
430
|
+
throw Error(`encodePath.invalid:${JSON.stringify(path)}`);
|
|
431
431
|
}
|
|
432
432
|
function encodeSegment(seg) {
|
|
433
433
|
if (ArrayBuffer.isView(seg))
|
|
@@ -446,7 +446,7 @@ function encode$2(path) {
|
|
|
446
446
|
}
|
|
447
447
|
function decode$2(path) {
|
|
448
448
|
if (!Array.isArray(path)) {
|
|
449
|
-
throw Error(
|
|
449
|
+
throw Error(`decodePath.invalid:${JSON.stringify(path)}`);
|
|
450
450
|
}
|
|
451
451
|
return path.map((key) => decode$3({ key }));
|
|
452
452
|
}
|
|
@@ -495,7 +495,7 @@ function isBranch(node) {
|
|
|
495
495
|
return node && typeof node.children !== "undefined";
|
|
496
496
|
}
|
|
497
497
|
function isPrefix(node) {
|
|
498
|
-
return node
|
|
498
|
+
return node == null ? void 0 : node.prefix;
|
|
499
499
|
}
|
|
500
500
|
function isLink(node) {
|
|
501
501
|
return node && typeof node.path !== "undefined";
|
|
@@ -591,7 +591,7 @@ function mergeRanges$1(base, node) {
|
|
|
591
591
|
}
|
|
592
592
|
function insertNode$1(current, change, start = 0) {
|
|
593
593
|
if (!current)
|
|
594
|
-
throw new Error(
|
|
594
|
+
throw new Error(`merge.insertNode: ${current}`);
|
|
595
595
|
const key = change.key;
|
|
596
596
|
const index = findFirst(current, key, start);
|
|
597
597
|
const node = current[index];
|
|
@@ -654,7 +654,7 @@ function wrapValue(value, path, version = 0) {
|
|
|
654
654
|
}
|
|
655
655
|
function wrap(children, path, version = 0, prefix = false) {
|
|
656
656
|
if (!Array.isArray(path))
|
|
657
|
-
throw Error(
|
|
657
|
+
throw Error(`wrap.path_not_array ${path}`);
|
|
658
658
|
if (!path.length)
|
|
659
659
|
return children;
|
|
660
660
|
let i = path.length - 1;
|
|
@@ -673,7 +673,7 @@ function wrap(children, path, version = 0, prefix = false) {
|
|
|
673
673
|
}
|
|
674
674
|
function unwrap(tree, path) {
|
|
675
675
|
if (!Array.isArray(path))
|
|
676
|
-
throw Error(
|
|
676
|
+
throw Error(`unwrap.path_not_array ${path}`);
|
|
677
677
|
let children = tree;
|
|
678
678
|
let node = { children };
|
|
679
679
|
for (let i = 0; i < path.length; i++) {
|
|
@@ -703,7 +703,7 @@ function getNodeValue(node) {
|
|
|
703
703
|
}
|
|
704
704
|
function remove(children, path) {
|
|
705
705
|
if (!Array.isArray(path))
|
|
706
|
-
throw Error(
|
|
706
|
+
throw Error(`del.path_not_array ${path}`);
|
|
707
707
|
if (!children)
|
|
708
708
|
return null;
|
|
709
709
|
if (!path.length)
|
|
@@ -984,9 +984,9 @@ function updateNode(current, index, change, result) {
|
|
|
984
984
|
return index + 1;
|
|
985
985
|
}
|
|
986
986
|
function isPathEqual(first, second) {
|
|
987
|
-
if (!first
|
|
987
|
+
if (!(first || second))
|
|
988
988
|
return true;
|
|
989
|
-
if (!first
|
|
989
|
+
if (!(first && second))
|
|
990
990
|
return false;
|
|
991
991
|
if (first.length !== second.length)
|
|
992
992
|
return false;
|
|
@@ -1018,7 +1018,7 @@ function getNewerChange(node, base) {
|
|
|
1018
1018
|
}
|
|
1019
1019
|
function setVersion(graph, version, onlyIfZero = false) {
|
|
1020
1020
|
for (const node of graph) {
|
|
1021
|
-
if (!onlyIfZero
|
|
1021
|
+
if (!(onlyIfZero && node.version))
|
|
1022
1022
|
node.version = version;
|
|
1023
1023
|
if (node.children)
|
|
1024
1024
|
setVersion(node.children, version, onlyIfZero);
|
|
@@ -1147,14 +1147,14 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1147
1147
|
if (!args)
|
|
1148
1148
|
args = {};
|
|
1149
1149
|
if (typeof args === "string") {
|
|
1150
|
-
throw Error(
|
|
1150
|
+
throw Error(`decode.unencoded_prefix: ${args}`);
|
|
1151
1151
|
}
|
|
1152
1152
|
if (isLink(node)) {
|
|
1153
1153
|
args.$all = true;
|
|
1154
1154
|
const $ref = decode$2(node.path);
|
|
1155
1155
|
const lastKey = $ref[$ref.length - 1];
|
|
1156
1156
|
if (typeof lastKey === "string") {
|
|
1157
|
-
throw Error(
|
|
1157
|
+
throw Error(`decode.unencoded_prefix_ref: ${node.path}`);
|
|
1158
1158
|
}
|
|
1159
1159
|
lastKey.$all = true;
|
|
1160
1160
|
const linkObject = { $key: args };
|
|
@@ -1163,11 +1163,11 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1163
1163
|
}
|
|
1164
1164
|
const children = decodeChildren(node.children);
|
|
1165
1165
|
if (!Array.isArray(children)) {
|
|
1166
|
-
throw Error(
|
|
1166
|
+
throw Error(`decode.prefix_without_encoded_child_keys:${node.key}`);
|
|
1167
1167
|
}
|
|
1168
1168
|
for (const child of children) {
|
|
1169
1169
|
if (typeof child.$key === "string") {
|
|
1170
|
-
throw Error(
|
|
1170
|
+
throw Error(`decode.prefix_with_unencoded_child_key:${child.$key}`);
|
|
1171
1171
|
}
|
|
1172
1172
|
if (!splitArgs(child.$key)[0]) {
|
|
1173
1173
|
child.$key = { $cursor: child.$key };
|
|
@@ -1247,12 +1247,12 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1247
1247
|
}
|
|
1248
1248
|
const { $key, $chi, ...props2 } = item;
|
|
1249
1249
|
const subQuery = $chi || (isEmpty(props2) ? 1 : props2);
|
|
1250
|
-
if (!isPlainObject($key)
|
|
1250
|
+
if (!(isPlainObject($key) && splitArgs($key)[0])) {
|
|
1251
1251
|
return construct(descend(plumGraph, $key), subQuery);
|
|
1252
1252
|
}
|
|
1253
1253
|
if (pageKey) {
|
|
1254
1254
|
throw Error(
|
|
1255
|
-
|
|
1255
|
+
`decorate.multi_range_query:${JSON.stringify({ $key, pageKey })}`
|
|
1256
1256
|
);
|
|
1257
1257
|
}
|
|
1258
1258
|
pageKey = $key;
|
|
@@ -1428,7 +1428,7 @@ function serializeKey(key) {
|
|
|
1428
1428
|
return decode$4(key);
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
|
-
return
|
|
1431
|
+
return `\0${encode$1(key)}`;
|
|
1432
1432
|
}
|
|
1433
1433
|
function deserializeKey(key) {
|
|
1434
1434
|
if (key[0] === "\0")
|
|
@@ -1490,15 +1490,8 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1490
1490
|
const links = [];
|
|
1491
1491
|
function pushLink($ref, $ver, props2, $val, $chi) {
|
|
1492
1492
|
const [range, _] = splitRef($ref);
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
void 0,
|
|
1496
|
-
$ver
|
|
1497
|
-
).children : isDef($chi) ? makeNode2(
|
|
1498
|
-
range ? [{ $key: range, $chi }] : $chi,
|
|
1499
|
-
void 0,
|
|
1500
|
-
$ver
|
|
1501
|
-
).children : isDef($val) ? $val : isGraph ? void 0 : 1;
|
|
1493
|
+
const node = !isEmpty(props2) ? makeNode2(range ? [{ $key: range, ...props2 }] : props2, void 0, $ver) : isDef($chi) ? makeNode2(range ? [{ $key: range, $chi }] : $chi, void 0, $ver) : null;
|
|
1494
|
+
const children = node ? node.children : isDef($val) ? $val : isGraph ? void 0 : 1;
|
|
1502
1495
|
if (children) {
|
|
1503
1496
|
links.push(wrap(children, encode$2($ref), $ver, !!range)[0]);
|
|
1504
1497
|
}
|
|
@@ -1554,7 +1547,8 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1554
1547
|
}
|
|
1555
1548
|
}
|
|
1556
1549
|
}
|
|
1557
|
-
let putQuery = []
|
|
1550
|
+
let putQuery = [];
|
|
1551
|
+
let prefixPuts = [];
|
|
1558
1552
|
if (Array.isArray(object) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1559
1553
|
putQuery = [encode$3({ $since: 0, $until: Infinity })];
|
|
1560
1554
|
}
|
|
@@ -1613,7 +1607,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1613
1607
|
if (children.length) {
|
|
1614
1608
|
node.children = children;
|
|
1615
1609
|
} else if (isGraph) {
|
|
1616
|
-
if (!isDef($key)
|
|
1610
|
+
if (!(isDef($key) || isDef($put)))
|
|
1617
1611
|
return;
|
|
1618
1612
|
if (node.key && !node.end)
|
|
1619
1613
|
node.end = node.key;
|
|
@@ -1711,7 +1705,7 @@ function cloneObject(object) {
|
|
|
1711
1705
|
}
|
|
1712
1706
|
function wrapObject(object, path) {
|
|
1713
1707
|
if (!Array.isArray(path))
|
|
1714
|
-
throw Error(
|
|
1708
|
+
throw Error(`wrapObject.path_not_array ${path}`);
|
|
1715
1709
|
for (let i = path.length - 1; i >= 0; i--) {
|
|
1716
1710
|
const $key = path[i];
|
|
1717
1711
|
if (typeof $key === "string") {
|
|
@@ -1726,19 +1720,19 @@ function wrapObject(object, path) {
|
|
|
1726
1720
|
}
|
|
1727
1721
|
function unwrapObject(object, path) {
|
|
1728
1722
|
if (!Array.isArray(path))
|
|
1729
|
-
throw Error(
|
|
1723
|
+
throw Error(`unwrapObject.path_not_array ${path}`);
|
|
1730
1724
|
for (let i = 0; i < path.length; i++) {
|
|
1731
1725
|
if (!object || typeof object !== "object")
|
|
1732
1726
|
return;
|
|
1733
1727
|
const $key = path[i];
|
|
1734
1728
|
if (typeof $key === "string") {
|
|
1735
1729
|
if (Array.isArray(object)) {
|
|
1736
|
-
throw Error(
|
|
1730
|
+
throw Error(`unwrapObject.string_key_array:${$key}`);
|
|
1737
1731
|
}
|
|
1738
1732
|
object = object[$key];
|
|
1739
1733
|
} else {
|
|
1740
1734
|
if (!Array.isArray(object)) {
|
|
1741
|
-
throw Error(
|
|
1735
|
+
throw Error(`unwrapObject.arg_key_object:${JSON.stringify($key)}`);
|
|
1742
1736
|
}
|
|
1743
1737
|
const [page, filter] = splitArgs($key);
|
|
1744
1738
|
if (page && !page.$cursor) {
|
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.
|
|
5
|
+
"version": "0.16.2-alpha.1",
|
|
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.
|
|
21
|
+
"@graffy/stream": "0.16.2-alpha.1"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/types/util.d.ts
CHANGED
|
@@ -7,7 +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 cmp(a: any, b: any):
|
|
10
|
+
export function cmp(a: any, b: any): 0 | 1 | -1;
|
|
11
11
|
export function find(items: any, compare: any, first?: number, last?: any): number;
|
|
12
12
|
export function addStringify(buffer: any): any;
|
|
13
13
|
export const MIN_KEY: Uint8Array;
|