@graffy/common 0.16.0-alpha.1 → 0.16.0-alpha.10
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 +167 -59
- package/index.mjs +166 -58
- package/package.json +2 -2
- package/types/coding/index.d.ts +1 -1
- package/types/coding/pack.d.ts +2 -0
- package/types/ops/finalize.d.ts +1 -1
- package/types/ops/setVersion.d.ts +1 -1
- package/types/coding/serialize.d.ts +0 -2
package/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const isEqual = require("lodash/isEqual.js");
|
|
3
4
|
const mergeIterators = require("merge-async-iterators");
|
|
4
5
|
const stream = require("@graffy/stream");
|
|
5
|
-
const isEqual = require("lodash/isEqual.js");
|
|
6
6
|
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
7
|
-
const mergeIterators__default = /* @__PURE__ */ _interopDefaultLegacy(mergeIterators);
|
|
8
7
|
const isEqual__default = /* @__PURE__ */ _interopDefaultLegacy(isEqual);
|
|
8
|
+
const mergeIterators__default = /* @__PURE__ */ _interopDefaultLegacy(mergeIterators);
|
|
9
9
|
const textEncoder = new TextEncoder();
|
|
10
10
|
const textDecoder = new TextDecoder("utf-8");
|
|
11
11
|
function encode$6(string) {
|
|
@@ -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
|
});
|
|
@@ -390,8 +391,6 @@ function encode$3(arg) {
|
|
|
390
391
|
return node;
|
|
391
392
|
}
|
|
392
393
|
function decode$3(node) {
|
|
393
|
-
if (typeof node === "string")
|
|
394
|
-
throw Error("why?");
|
|
395
394
|
const { key, end, limit } = node;
|
|
396
395
|
errIf("no_key", !isDef(key));
|
|
397
396
|
errIf("limit_without_end", isDef(limit) && !isDef(end));
|
|
@@ -639,10 +638,10 @@ function getNewer(node, base) {
|
|
|
639
638
|
}
|
|
640
639
|
}
|
|
641
640
|
const IS_VAL = Symbol("IS_VAL");
|
|
642
|
-
function makeNode(seg,
|
|
641
|
+
function makeNode(seg, props2) {
|
|
643
642
|
if (ArrayBuffer.isView(seg))
|
|
644
|
-
return { key: seg, ...
|
|
645
|
-
return { ...seg, ...
|
|
643
|
+
return { key: seg, ...props2 };
|
|
644
|
+
return { ...seg, ...props2 };
|
|
646
645
|
}
|
|
647
646
|
function wrapValue(value, path, version = 0) {
|
|
648
647
|
const node = makeNode(path[path.length - 1], { value, version });
|
|
@@ -869,7 +868,7 @@ function insertRange(current, change, result, start = 0) {
|
|
|
869
868
|
const { key, end } = change;
|
|
870
869
|
const keyIx = findFirst(current, key, start);
|
|
871
870
|
const endIx = findLast(current, end, keyIx);
|
|
872
|
-
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key,
|
|
871
|
+
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, end) <= 0 && cmp(current[keyIx].end || current[keyIx].key, key) >= 0)) {
|
|
873
872
|
return keyIx;
|
|
874
873
|
}
|
|
875
874
|
const appliedChange = [];
|
|
@@ -1012,9 +1011,10 @@ function getNewerChange(node, base) {
|
|
|
1012
1011
|
return node.version >= base.version ? node : null;
|
|
1013
1012
|
}
|
|
1014
1013
|
}
|
|
1015
|
-
function setVersion(graph, version) {
|
|
1014
|
+
function setVersion(graph, version, onlyIfZero = false) {
|
|
1016
1015
|
for (const node of graph) {
|
|
1017
|
-
node.version
|
|
1016
|
+
if (!onlyIfZero || !node.version)
|
|
1017
|
+
node.version = version;
|
|
1018
1018
|
if (node.children)
|
|
1019
1019
|
setVersion(node.children, version);
|
|
1020
1020
|
}
|
|
@@ -1038,14 +1038,16 @@ function getKnown(graph, version = 0) {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
return query;
|
|
1040
1040
|
}
|
|
1041
|
-
function finalize(graph, query, version = Date.now()) {
|
|
1041
|
+
function finalize(graph, query, version = Date.now(), suppressSetVersion = false) {
|
|
1042
1042
|
let result = [{ key: MIN_KEY, end: MAX_KEY, version: 0 }];
|
|
1043
1043
|
merge(result, graph);
|
|
1044
1044
|
if (query)
|
|
1045
1045
|
result = slice(result, query).known || [];
|
|
1046
|
-
|
|
1046
|
+
if (!suppressSetVersion)
|
|
1047
|
+
result = setVersion(result, version);
|
|
1047
1048
|
return result;
|
|
1048
1049
|
}
|
|
1050
|
+
const PRE_CHI_PUT = Symbol("PREFIX_CHILDREN_$PUT");
|
|
1049
1051
|
function decode$1(nodes = [], { isGraph } = {}) {
|
|
1050
1052
|
function decodeChildren(nodes2) {
|
|
1051
1053
|
let result = [];
|
|
@@ -1061,6 +1063,7 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1061
1063
|
result.push(...objects);
|
|
1062
1064
|
}
|
|
1063
1065
|
const putRanges = [];
|
|
1066
|
+
const prefixChildPuts = [];
|
|
1064
1067
|
let lastNode = null;
|
|
1065
1068
|
function addPutRange({ key, end }) {
|
|
1066
1069
|
if (lastNode) {
|
|
@@ -1086,9 +1089,13 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1086
1089
|
for (const node of nodes2) {
|
|
1087
1090
|
if (isGraph && addPutRange(node))
|
|
1088
1091
|
continue;
|
|
1089
|
-
if (isPrefix(node))
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
+
if (isPrefix(node)) {
|
|
1093
|
+
const decodedChildren = decodePrefixNode(node);
|
|
1094
|
+
if (PRE_CHI_PUT in decodedChildren) {
|
|
1095
|
+
prefixChildPuts.push(...decodedChildren[PRE_CHI_PUT]);
|
|
1096
|
+
}
|
|
1097
|
+
pushResult(...decodedChildren);
|
|
1098
|
+
} else if (isGraph && isRange(node))
|
|
1092
1099
|
pushResult(decodeRangeNode(node));
|
|
1093
1100
|
else if (isBranch(node))
|
|
1094
1101
|
pushResult(decodeBranchNode(node));
|
|
@@ -1122,15 +1129,17 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1122
1129
|
Object.defineProperty(result, "$put", { value: true });
|
|
1123
1130
|
} else {
|
|
1124
1131
|
Object.defineProperty(result, "$put", {
|
|
1125
|
-
value: putRanges.map((rNode) => decode$3(rNode))
|
|
1132
|
+
value: putRanges.map((rNode) => decode$3(rNode)).concat(prefixChildPuts)
|
|
1126
1133
|
});
|
|
1127
1134
|
}
|
|
1135
|
+
} else if (prefixChildPuts.length) {
|
|
1136
|
+
Object.defineProperty(result, "$put", { value: prefixChildPuts });
|
|
1128
1137
|
}
|
|
1129
1138
|
return result;
|
|
1130
1139
|
}
|
|
1131
1140
|
function decodePrefixNode(node) {
|
|
1132
1141
|
let args = decode$3(node);
|
|
1133
|
-
if (args
|
|
1142
|
+
if (!args)
|
|
1134
1143
|
args = {};
|
|
1135
1144
|
if (typeof args === "string") {
|
|
1136
1145
|
throw Error("decode.unencoded_prefix: " + args);
|
|
@@ -1160,6 +1169,16 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1160
1169
|
}
|
|
1161
1170
|
child.$key = { ...args, ...child.$key };
|
|
1162
1171
|
}
|
|
1172
|
+
if (children.$put === true) {
|
|
1173
|
+
children[PRE_CHI_PUT] = [{ ...args, $all: true }];
|
|
1174
|
+
} else if (Array.isArray(children.$put)) {
|
|
1175
|
+
children[PRE_CHI_PUT] = children.$put.map((rarg) => ({
|
|
1176
|
+
...args,
|
|
1177
|
+
...rarg
|
|
1178
|
+
}));
|
|
1179
|
+
} else if (isDef(children.$put)) {
|
|
1180
|
+
children[PRE_CHI_PUT] = [{ ...args, ...children.$put }];
|
|
1181
|
+
}
|
|
1163
1182
|
return children;
|
|
1164
1183
|
}
|
|
1165
1184
|
function decodeBranchNode(node) {
|
|
@@ -1202,7 +1221,7 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1202
1221
|
query = [query];
|
|
1203
1222
|
let graph;
|
|
1204
1223
|
if (query.$ref) {
|
|
1205
|
-
const { $ref, ...
|
|
1224
|
+
const { $ref, ...props2 } = query;
|
|
1206
1225
|
const [range, filter] = splitRef($ref);
|
|
1207
1226
|
const path = encode$2($ref);
|
|
1208
1227
|
const targetPlumGraph = unwrap(rootGraph, path);
|
|
@@ -1211,7 +1230,7 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1211
1230
|
targetPlumGraph[PRE] = filter;
|
|
1212
1231
|
graph = construct(
|
|
1213
1232
|
targetPlumGraph,
|
|
1214
|
-
range ? { $key: range, ...
|
|
1233
|
+
range ? { $key: range, ...props2 } : props2
|
|
1215
1234
|
);
|
|
1216
1235
|
Object.defineProperty(graph, "$ref", { value: $ref });
|
|
1217
1236
|
}
|
|
@@ -1221,8 +1240,8 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1221
1240
|
if (!(item == null ? void 0 : item.$key)) {
|
|
1222
1241
|
return construct(descend(plumGraph, i), item);
|
|
1223
1242
|
}
|
|
1224
|
-
const { $key, $chi, ...
|
|
1225
|
-
const subQuery = $chi || (isEmpty(
|
|
1243
|
+
const { $key, $chi, ...props2 } = item;
|
|
1244
|
+
const subQuery = $chi || (isEmpty(props2) ? 1 : props2);
|
|
1226
1245
|
if (!isPlainObject($key) || !splitArgs($key)[0]) {
|
|
1227
1246
|
return construct(descend(plumGraph, $key), subQuery);
|
|
1228
1247
|
}
|
|
@@ -1388,25 +1407,86 @@ function decode(string, start = 0) {
|
|
|
1388
1407
|
}
|
|
1389
1408
|
return addStringify(new Uint8Array(buffer));
|
|
1390
1409
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1410
|
+
const props = [
|
|
1411
|
+
"end",
|
|
1412
|
+
"version",
|
|
1413
|
+
"limit",
|
|
1414
|
+
"value",
|
|
1415
|
+
"path",
|
|
1416
|
+
"prefix",
|
|
1417
|
+
"children"
|
|
1418
|
+
];
|
|
1419
|
+
function serializeKey(key) {
|
|
1420
|
+
if (key[0] === STR) {
|
|
1421
|
+
const last = key[key.length - 1];
|
|
1422
|
+
if (last !== 0 && last !== 255) {
|
|
1423
|
+
return decode$4(key);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
return "\0" + encode$1(key);
|
|
1427
|
+
}
|
|
1428
|
+
function deserializeKey(key) {
|
|
1429
|
+
if (key[0] === "\0")
|
|
1430
|
+
return decode(key.slice(1));
|
|
1431
|
+
return encode$4(key);
|
|
1432
|
+
}
|
|
1433
|
+
function pack(children, parentVersion) {
|
|
1434
|
+
if (!Array.isArray(children))
|
|
1435
|
+
return children;
|
|
1436
|
+
const array = children.map(
|
|
1437
|
+
(node) => props.reduce(
|
|
1438
|
+
(array2, prop, i) => {
|
|
1439
|
+
if (!(prop in node))
|
|
1440
|
+
return array2;
|
|
1441
|
+
let value = node[prop];
|
|
1442
|
+
if (prop === "version" && value === parentVersion)
|
|
1443
|
+
return array2;
|
|
1444
|
+
if (prop === "children")
|
|
1445
|
+
value = pack(value, node.version);
|
|
1446
|
+
if (prop === "end")
|
|
1447
|
+
value = serializeKey(value);
|
|
1448
|
+
if (prop === "path")
|
|
1449
|
+
value = value.map(serializeKey);
|
|
1450
|
+
array2[1] |= 1 << i;
|
|
1451
|
+
array2.push(value);
|
|
1452
|
+
return array2;
|
|
1453
|
+
},
|
|
1454
|
+
[serializeKey(node.key), 0]
|
|
1455
|
+
)
|
|
1456
|
+
);
|
|
1457
|
+
return array;
|
|
1395
1458
|
}
|
|
1396
|
-
function
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1459
|
+
function unpack(children, parentVersion) {
|
|
1460
|
+
if (!Array.isArray(children))
|
|
1461
|
+
return children;
|
|
1462
|
+
const node = children.map(
|
|
1463
|
+
([key, type, ...values]) => props.reduce(
|
|
1464
|
+
(node2, prop, i) => {
|
|
1465
|
+
if (!(type & 1 << i))
|
|
1466
|
+
return node2;
|
|
1467
|
+
let value = values.shift();
|
|
1468
|
+
if (prop === "children")
|
|
1469
|
+
value = unpack(value, node2.version);
|
|
1470
|
+
if (prop === "end")
|
|
1471
|
+
value = deserializeKey(value);
|
|
1472
|
+
if (prop === "path")
|
|
1473
|
+
value = value.map(deserializeKey);
|
|
1474
|
+
node2[prop] = value;
|
|
1475
|
+
return node2;
|
|
1476
|
+
},
|
|
1477
|
+
{ key: deserializeKey(key), version: parentVersion }
|
|
1478
|
+
)
|
|
1400
1479
|
);
|
|
1480
|
+
return node;
|
|
1401
1481
|
}
|
|
1402
1482
|
const ROOT_KEY = Symbol();
|
|
1403
1483
|
function encode(value, { version, isGraph } = {}) {
|
|
1404
1484
|
var _a;
|
|
1405
1485
|
const links = [];
|
|
1406
|
-
function pushLink($ref, $ver,
|
|
1486
|
+
function pushLink($ref, $ver, props2, $val, $chi) {
|
|
1407
1487
|
const [range, _] = splitRef($ref);
|
|
1408
|
-
let children = !isEmpty(
|
|
1409
|
-
range ? [{ $key: range, ...
|
|
1488
|
+
let children = !isEmpty(props2) ? makeNode2(
|
|
1489
|
+
range ? [{ $key: range, ...props2 }] : props2,
|
|
1410
1490
|
void 0,
|
|
1411
1491
|
$ver
|
|
1412
1492
|
).children : isDef($chi) ? makeNode2(
|
|
@@ -1419,19 +1499,31 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1419
1499
|
}
|
|
1420
1500
|
}
|
|
1421
1501
|
const combine = isGraph ? merge : add;
|
|
1422
|
-
function makeNode2(object, key, ver) {
|
|
1502
|
+
function makeNode2(object, key, ver, parentPuts = []) {
|
|
1423
1503
|
var _a2;
|
|
1424
1504
|
if (!isDef(object))
|
|
1425
1505
|
return;
|
|
1426
1506
|
if (typeof object === "object" && object && isEmpty(object))
|
|
1427
1507
|
return;
|
|
1428
|
-
const { $key, $ver, $ref, $val, $chi, $put, ...
|
|
1508
|
+
const { $key, $ver, $ref, $val, $chi, $put, ...props2 } = object || {};
|
|
1509
|
+
if (typeof object === "object" && object && !Array.isArray(object)) {
|
|
1510
|
+
object = Object.fromEntries(
|
|
1511
|
+
Object.entries({ $key, $ver, $ref, $val, $chi, $put, ...props2 }).filter(
|
|
1512
|
+
([_, val]) => isDef(val)
|
|
1513
|
+
)
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1429
1516
|
if (isDef($ver))
|
|
1430
1517
|
ver = $ver;
|
|
1431
1518
|
if (isPlainObject($key)) {
|
|
1432
1519
|
const [page, filter] = splitArgs($key);
|
|
1433
|
-
|
|
1434
|
-
|
|
1520
|
+
const foundPuts = parentPuts.filter(([_, putFilter]) => isEqual__default.default(filter, putFilter)).map(([range]) => range);
|
|
1521
|
+
if (isGraph && page && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props2))) {
|
|
1522
|
+
const node2 = makeNode2(
|
|
1523
|
+
{ ...object, $key: filter || {}, $put: foundPuts },
|
|
1524
|
+
key,
|
|
1525
|
+
ver
|
|
1526
|
+
);
|
|
1435
1527
|
if (!filter)
|
|
1436
1528
|
node2.key = MIN_KEY;
|
|
1437
1529
|
node2.prefix = true;
|
|
@@ -1443,7 +1535,8 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1443
1535
|
$key: filter || {},
|
|
1444
1536
|
$chi: [
|
|
1445
1537
|
{ ...object, $key: isDef(page.$cursor) ? page.$cursor : page }
|
|
1446
|
-
]
|
|
1538
|
+
],
|
|
1539
|
+
...isGraph ? { $put: foundPuts } : {}
|
|
1447
1540
|
},
|
|
1448
1541
|
key,
|
|
1449
1542
|
ver
|
|
@@ -1454,6 +1547,25 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1454
1547
|
return node2;
|
|
1455
1548
|
}
|
|
1456
1549
|
}
|
|
1550
|
+
let putQuery = [], prefixPuts = [];
|
|
1551
|
+
if (Array.isArray(object) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1552
|
+
putQuery = [encode$3({ $since: 0, $until: Infinity })];
|
|
1553
|
+
}
|
|
1554
|
+
function classifyPut(put) {
|
|
1555
|
+
const [range, filter] = splitArgs(put);
|
|
1556
|
+
if (filter) {
|
|
1557
|
+
prefixPuts.push([range, filter]);
|
|
1558
|
+
} else {
|
|
1559
|
+
putQuery.push(encode$3(put));
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
if ($put === true) {
|
|
1563
|
+
putQuery = null;
|
|
1564
|
+
} else if (Array.isArray($put)) {
|
|
1565
|
+
$put.forEach(classifyPut);
|
|
1566
|
+
} else if (isDef($put)) {
|
|
1567
|
+
classifyPut($put);
|
|
1568
|
+
}
|
|
1457
1569
|
if (isDef($key) && (Number.isInteger(key) || !isDef(key)))
|
|
1458
1570
|
key = $key;
|
|
1459
1571
|
const node = key === ROOT_KEY || !isDef(key) ? {} : encode$3(key);
|
|
@@ -1461,26 +1573,28 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1461
1573
|
if (object === null) {
|
|
1462
1574
|
node.end = node.key;
|
|
1463
1575
|
} else if (isDef($key) && isDef(key) && key !== $key) {
|
|
1464
|
-
node.children = [makeNode2(object, void 0, ver)].filter(
|
|
1576
|
+
node.children = [makeNode2(object, void 0, ver, prefixPuts)].filter(
|
|
1577
|
+
Boolean
|
|
1578
|
+
);
|
|
1465
1579
|
return node;
|
|
1466
1580
|
} else if ($ref) {
|
|
1467
|
-
pushLink($ref, node.version,
|
|
1581
|
+
pushLink($ref, node.version, props2, $val, $chi);
|
|
1468
1582
|
if (!isGraph)
|
|
1469
1583
|
return;
|
|
1470
1584
|
node.path = encode$2($ref);
|
|
1471
1585
|
} else if ($val === true) {
|
|
1472
|
-
node.value =
|
|
1586
|
+
node.value = props2;
|
|
1473
1587
|
} else if (isDef($val)) {
|
|
1474
1588
|
node.value = $val;
|
|
1475
1589
|
} else if (typeof object !== "object") {
|
|
1476
1590
|
node.value = isGraph || typeof object === "number" ? object : 1;
|
|
1477
1591
|
} else if (isDef($chi)) {
|
|
1478
|
-
const children = $chi.map((obj) => makeNode2(obj, void 0, ver)).filter(Boolean).sort((a, b) => cmp(a.key, b.key));
|
|
1592
|
+
const children = $chi.map((obj) => makeNode2(obj, void 0, ver, prefixPuts)).filter(Boolean).sort((a, b) => cmp(a.key, b.key));
|
|
1479
1593
|
if (children.length) {
|
|
1480
1594
|
node.children = children;
|
|
1481
1595
|
}
|
|
1482
1596
|
} else if (Array.isArray(object)) {
|
|
1483
|
-
const children = object.map((obj, i) => makeNode2(obj, i, ver)).filter(Boolean).reduce((acc, it) => {
|
|
1597
|
+
const children = object.map((obj, i) => makeNode2(obj, i, ver, prefixPuts)).filter(Boolean).reduce((acc, it) => {
|
|
1484
1598
|
combine(acc, [it]);
|
|
1485
1599
|
return acc;
|
|
1486
1600
|
}, []);
|
|
@@ -1488,7 +1602,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1488
1602
|
node.children = children;
|
|
1489
1603
|
}
|
|
1490
1604
|
} else {
|
|
1491
|
-
const children = Object.keys(
|
|
1605
|
+
const children = Object.keys(props2).sort().map((key2) => makeNode2(object[key2], key2, ver)).filter(Boolean);
|
|
1492
1606
|
if (children.length) {
|
|
1493
1607
|
node.children = children;
|
|
1494
1608
|
} else if (isGraph) {
|
|
@@ -1502,19 +1616,13 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1502
1616
|
node.value = 1;
|
|
1503
1617
|
}
|
|
1504
1618
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
putQuery = $put.map((arg) => encode$3(arg));
|
|
1513
|
-
} else if (isDef($put)) {
|
|
1514
|
-
putQuery = [encode$3($put)];
|
|
1515
|
-
}
|
|
1516
|
-
if (isGraph && isDef(putQuery)) {
|
|
1517
|
-
node.children = finalize(node.children || [], putQuery, node.version);
|
|
1619
|
+
if (isGraph && (putQuery === null || putQuery.length)) {
|
|
1620
|
+
node.children = finalize(
|
|
1621
|
+
node.children || [],
|
|
1622
|
+
putQuery,
|
|
1623
|
+
node.version,
|
|
1624
|
+
true
|
|
1625
|
+
);
|
|
1518
1626
|
}
|
|
1519
1627
|
if (((_a2 = node.children) == null ? void 0 : _a2.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
|
|
1520
1628
|
return node;
|
|
@@ -1529,7 +1637,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1529
1637
|
return result;
|
|
1530
1638
|
}
|
|
1531
1639
|
function encodeGraph(obj, version = Date.now()) {
|
|
1532
|
-
return encode(obj, { version, isGraph: true });
|
|
1640
|
+
return setVersion(encode(obj, { version, isGraph: true }), version, true);
|
|
1533
1641
|
}
|
|
1534
1642
|
function encodeQuery(obj, version = 0) {
|
|
1535
1643
|
return encode(obj, { version, isGraph: false });
|
|
@@ -1652,7 +1760,6 @@ exports.decodePath = decode$2;
|
|
|
1652
1760
|
exports.decodeQuery = decodeQuery;
|
|
1653
1761
|
exports.decodeValue = decode$4;
|
|
1654
1762
|
exports.decorate = decorate;
|
|
1655
|
-
exports.deserialize = deserialize;
|
|
1656
1763
|
exports.encodeArgs = encode$3;
|
|
1657
1764
|
exports.encodeGraph = encodeGraph;
|
|
1658
1765
|
exports.encodePath = encode$2;
|
|
@@ -1685,13 +1792,14 @@ exports.makeWatcher = makeWatcher;
|
|
|
1685
1792
|
exports.merge = merge;
|
|
1686
1793
|
exports.mergeObject = mergeObject;
|
|
1687
1794
|
exports.mergeStreams = mergeStreams;
|
|
1795
|
+
exports.pack = pack;
|
|
1688
1796
|
exports.remove = remove;
|
|
1689
|
-
exports.serialize = serialize;
|
|
1690
1797
|
exports.setVersion = setVersion;
|
|
1691
1798
|
exports.sieve = sieve;
|
|
1692
1799
|
exports.slice = slice;
|
|
1693
1800
|
exports.splitArgs = splitArgs;
|
|
1694
1801
|
exports.splitRef = splitRef;
|
|
1802
|
+
exports.unpack = unpack;
|
|
1695
1803
|
exports.unwrap = unwrap;
|
|
1696
1804
|
exports.unwrapObject = unwrapObject;
|
|
1697
1805
|
exports.wrap = wrap;
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import isEqual from "lodash/isEqual.js";
|
|
1
2
|
import mergeIterators from "merge-async-iterators";
|
|
2
3
|
import { makeStream } from "@graffy/stream";
|
|
3
|
-
import isEqual from "lodash/isEqual.js";
|
|
4
4
|
const textEncoder = new TextEncoder();
|
|
5
5
|
const textDecoder = new TextDecoder("utf-8");
|
|
6
6
|
function encode$6(string) {
|
|
@@ -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
|
});
|
|
@@ -385,8 +386,6 @@ function encode$3(arg) {
|
|
|
385
386
|
return node;
|
|
386
387
|
}
|
|
387
388
|
function decode$3(node) {
|
|
388
|
-
if (typeof node === "string")
|
|
389
|
-
throw Error("why?");
|
|
390
389
|
const { key, end, limit } = node;
|
|
391
390
|
errIf("no_key", !isDef(key));
|
|
392
391
|
errIf("limit_without_end", isDef(limit) && !isDef(end));
|
|
@@ -634,10 +633,10 @@ function getNewer(node, base) {
|
|
|
634
633
|
}
|
|
635
634
|
}
|
|
636
635
|
const IS_VAL = Symbol("IS_VAL");
|
|
637
|
-
function makeNode(seg,
|
|
636
|
+
function makeNode(seg, props2) {
|
|
638
637
|
if (ArrayBuffer.isView(seg))
|
|
639
|
-
return { key: seg, ...
|
|
640
|
-
return { ...seg, ...
|
|
638
|
+
return { key: seg, ...props2 };
|
|
639
|
+
return { ...seg, ...props2 };
|
|
641
640
|
}
|
|
642
641
|
function wrapValue(value, path, version = 0) {
|
|
643
642
|
const node = makeNode(path[path.length - 1], { value, version });
|
|
@@ -864,7 +863,7 @@ function insertRange(current, change, result, start = 0) {
|
|
|
864
863
|
const { key, end } = change;
|
|
865
864
|
const keyIx = findFirst(current, key, start);
|
|
866
865
|
const endIx = findLast(current, end, keyIx);
|
|
867
|
-
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key,
|
|
866
|
+
if (keyIx === endIx && !(current[keyIx] && cmp(current[keyIx].key, end) <= 0 && cmp(current[keyIx].end || current[keyIx].key, key) >= 0)) {
|
|
868
867
|
return keyIx;
|
|
869
868
|
}
|
|
870
869
|
const appliedChange = [];
|
|
@@ -1007,9 +1006,10 @@ function getNewerChange(node, base) {
|
|
|
1007
1006
|
return node.version >= base.version ? node : null;
|
|
1008
1007
|
}
|
|
1009
1008
|
}
|
|
1010
|
-
function setVersion(graph, version) {
|
|
1009
|
+
function setVersion(graph, version, onlyIfZero = false) {
|
|
1011
1010
|
for (const node of graph) {
|
|
1012
|
-
node.version
|
|
1011
|
+
if (!onlyIfZero || !node.version)
|
|
1012
|
+
node.version = version;
|
|
1013
1013
|
if (node.children)
|
|
1014
1014
|
setVersion(node.children, version);
|
|
1015
1015
|
}
|
|
@@ -1033,14 +1033,16 @@ function getKnown(graph, version = 0) {
|
|
|
1033
1033
|
}
|
|
1034
1034
|
return query;
|
|
1035
1035
|
}
|
|
1036
|
-
function finalize(graph, query, version = Date.now()) {
|
|
1036
|
+
function finalize(graph, query, version = Date.now(), suppressSetVersion = false) {
|
|
1037
1037
|
let result = [{ key: MIN_KEY, end: MAX_KEY, version: 0 }];
|
|
1038
1038
|
merge(result, graph);
|
|
1039
1039
|
if (query)
|
|
1040
1040
|
result = slice(result, query).known || [];
|
|
1041
|
-
|
|
1041
|
+
if (!suppressSetVersion)
|
|
1042
|
+
result = setVersion(result, version);
|
|
1042
1043
|
return result;
|
|
1043
1044
|
}
|
|
1045
|
+
const PRE_CHI_PUT = Symbol("PREFIX_CHILDREN_$PUT");
|
|
1044
1046
|
function decode$1(nodes = [], { isGraph } = {}) {
|
|
1045
1047
|
function decodeChildren(nodes2) {
|
|
1046
1048
|
let result = [];
|
|
@@ -1056,6 +1058,7 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1056
1058
|
result.push(...objects);
|
|
1057
1059
|
}
|
|
1058
1060
|
const putRanges = [];
|
|
1061
|
+
const prefixChildPuts = [];
|
|
1059
1062
|
let lastNode = null;
|
|
1060
1063
|
function addPutRange({ key, end }) {
|
|
1061
1064
|
if (lastNode) {
|
|
@@ -1081,9 +1084,13 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1081
1084
|
for (const node of nodes2) {
|
|
1082
1085
|
if (isGraph && addPutRange(node))
|
|
1083
1086
|
continue;
|
|
1084
|
-
if (isPrefix(node))
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
+
if (isPrefix(node)) {
|
|
1088
|
+
const decodedChildren = decodePrefixNode(node);
|
|
1089
|
+
if (PRE_CHI_PUT in decodedChildren) {
|
|
1090
|
+
prefixChildPuts.push(...decodedChildren[PRE_CHI_PUT]);
|
|
1091
|
+
}
|
|
1092
|
+
pushResult(...decodedChildren);
|
|
1093
|
+
} else if (isGraph && isRange(node))
|
|
1087
1094
|
pushResult(decodeRangeNode(node));
|
|
1088
1095
|
else if (isBranch(node))
|
|
1089
1096
|
pushResult(decodeBranchNode(node));
|
|
@@ -1117,15 +1124,17 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1117
1124
|
Object.defineProperty(result, "$put", { value: true });
|
|
1118
1125
|
} else {
|
|
1119
1126
|
Object.defineProperty(result, "$put", {
|
|
1120
|
-
value: putRanges.map((rNode) => decode$3(rNode))
|
|
1127
|
+
value: putRanges.map((rNode) => decode$3(rNode)).concat(prefixChildPuts)
|
|
1121
1128
|
});
|
|
1122
1129
|
}
|
|
1130
|
+
} else if (prefixChildPuts.length) {
|
|
1131
|
+
Object.defineProperty(result, "$put", { value: prefixChildPuts });
|
|
1123
1132
|
}
|
|
1124
1133
|
return result;
|
|
1125
1134
|
}
|
|
1126
1135
|
function decodePrefixNode(node) {
|
|
1127
1136
|
let args = decode$3(node);
|
|
1128
|
-
if (args
|
|
1137
|
+
if (!args)
|
|
1129
1138
|
args = {};
|
|
1130
1139
|
if (typeof args === "string") {
|
|
1131
1140
|
throw Error("decode.unencoded_prefix: " + args);
|
|
@@ -1155,6 +1164,16 @@ function decode$1(nodes = [], { isGraph } = {}) {
|
|
|
1155
1164
|
}
|
|
1156
1165
|
child.$key = { ...args, ...child.$key };
|
|
1157
1166
|
}
|
|
1167
|
+
if (children.$put === true) {
|
|
1168
|
+
children[PRE_CHI_PUT] = [{ ...args, $all: true }];
|
|
1169
|
+
} else if (Array.isArray(children.$put)) {
|
|
1170
|
+
children[PRE_CHI_PUT] = children.$put.map((rarg) => ({
|
|
1171
|
+
...args,
|
|
1172
|
+
...rarg
|
|
1173
|
+
}));
|
|
1174
|
+
} else if (isDef(children.$put)) {
|
|
1175
|
+
children[PRE_CHI_PUT] = [{ ...args, ...children.$put }];
|
|
1176
|
+
}
|
|
1158
1177
|
return children;
|
|
1159
1178
|
}
|
|
1160
1179
|
function decodeBranchNode(node) {
|
|
@@ -1197,7 +1216,7 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1197
1216
|
query = [query];
|
|
1198
1217
|
let graph;
|
|
1199
1218
|
if (query.$ref) {
|
|
1200
|
-
const { $ref, ...
|
|
1219
|
+
const { $ref, ...props2 } = query;
|
|
1201
1220
|
const [range, filter] = splitRef($ref);
|
|
1202
1221
|
const path = encode$2($ref);
|
|
1203
1222
|
const targetPlumGraph = unwrap(rootGraph, path);
|
|
@@ -1206,7 +1225,7 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1206
1225
|
targetPlumGraph[PRE] = filter;
|
|
1207
1226
|
graph = construct(
|
|
1208
1227
|
targetPlumGraph,
|
|
1209
|
-
range ? { $key: range, ...
|
|
1228
|
+
range ? { $key: range, ...props2 } : props2
|
|
1210
1229
|
);
|
|
1211
1230
|
Object.defineProperty(graph, "$ref", { value: $ref });
|
|
1212
1231
|
}
|
|
@@ -1216,8 +1235,8 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1216
1235
|
if (!(item == null ? void 0 : item.$key)) {
|
|
1217
1236
|
return construct(descend(plumGraph, i), item);
|
|
1218
1237
|
}
|
|
1219
|
-
const { $key, $chi, ...
|
|
1220
|
-
const subQuery = $chi || (isEmpty(
|
|
1238
|
+
const { $key, $chi, ...props2 } = item;
|
|
1239
|
+
const subQuery = $chi || (isEmpty(props2) ? 1 : props2);
|
|
1221
1240
|
if (!isPlainObject($key) || !splitArgs($key)[0]) {
|
|
1222
1241
|
return construct(descend(plumGraph, $key), subQuery);
|
|
1223
1242
|
}
|
|
@@ -1383,25 +1402,86 @@ function decode(string, start = 0) {
|
|
|
1383
1402
|
}
|
|
1384
1403
|
return addStringify(new Uint8Array(buffer));
|
|
1385
1404
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1405
|
+
const props = [
|
|
1406
|
+
"end",
|
|
1407
|
+
"version",
|
|
1408
|
+
"limit",
|
|
1409
|
+
"value",
|
|
1410
|
+
"path",
|
|
1411
|
+
"prefix",
|
|
1412
|
+
"children"
|
|
1413
|
+
];
|
|
1414
|
+
function serializeKey(key) {
|
|
1415
|
+
if (key[0] === STR) {
|
|
1416
|
+
const last = key[key.length - 1];
|
|
1417
|
+
if (last !== 0 && last !== 255) {
|
|
1418
|
+
return decode$4(key);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
return "\0" + encode$1(key);
|
|
1422
|
+
}
|
|
1423
|
+
function deserializeKey(key) {
|
|
1424
|
+
if (key[0] === "\0")
|
|
1425
|
+
return decode(key.slice(1));
|
|
1426
|
+
return encode$4(key);
|
|
1390
1427
|
}
|
|
1391
|
-
function
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1428
|
+
function pack(children, parentVersion) {
|
|
1429
|
+
if (!Array.isArray(children))
|
|
1430
|
+
return children;
|
|
1431
|
+
const array = children.map(
|
|
1432
|
+
(node) => props.reduce(
|
|
1433
|
+
(array2, prop, i) => {
|
|
1434
|
+
if (!(prop in node))
|
|
1435
|
+
return array2;
|
|
1436
|
+
let value = node[prop];
|
|
1437
|
+
if (prop === "version" && value === parentVersion)
|
|
1438
|
+
return array2;
|
|
1439
|
+
if (prop === "children")
|
|
1440
|
+
value = pack(value, node.version);
|
|
1441
|
+
if (prop === "end")
|
|
1442
|
+
value = serializeKey(value);
|
|
1443
|
+
if (prop === "path")
|
|
1444
|
+
value = value.map(serializeKey);
|
|
1445
|
+
array2[1] |= 1 << i;
|
|
1446
|
+
array2.push(value);
|
|
1447
|
+
return array2;
|
|
1448
|
+
},
|
|
1449
|
+
[serializeKey(node.key), 0]
|
|
1450
|
+
)
|
|
1395
1451
|
);
|
|
1452
|
+
return array;
|
|
1453
|
+
}
|
|
1454
|
+
function unpack(children, parentVersion) {
|
|
1455
|
+
if (!Array.isArray(children))
|
|
1456
|
+
return children;
|
|
1457
|
+
const node = children.map(
|
|
1458
|
+
([key, type, ...values]) => props.reduce(
|
|
1459
|
+
(node2, prop, i) => {
|
|
1460
|
+
if (!(type & 1 << i))
|
|
1461
|
+
return node2;
|
|
1462
|
+
let value = values.shift();
|
|
1463
|
+
if (prop === "children")
|
|
1464
|
+
value = unpack(value, node2.version);
|
|
1465
|
+
if (prop === "end")
|
|
1466
|
+
value = deserializeKey(value);
|
|
1467
|
+
if (prop === "path")
|
|
1468
|
+
value = value.map(deserializeKey);
|
|
1469
|
+
node2[prop] = value;
|
|
1470
|
+
return node2;
|
|
1471
|
+
},
|
|
1472
|
+
{ key: deserializeKey(key), version: parentVersion }
|
|
1473
|
+
)
|
|
1474
|
+
);
|
|
1475
|
+
return node;
|
|
1396
1476
|
}
|
|
1397
1477
|
const ROOT_KEY = Symbol();
|
|
1398
1478
|
function encode(value, { version, isGraph } = {}) {
|
|
1399
1479
|
var _a;
|
|
1400
1480
|
const links = [];
|
|
1401
|
-
function pushLink($ref, $ver,
|
|
1481
|
+
function pushLink($ref, $ver, props2, $val, $chi) {
|
|
1402
1482
|
const [range, _] = splitRef($ref);
|
|
1403
|
-
let children = !isEmpty(
|
|
1404
|
-
range ? [{ $key: range, ...
|
|
1483
|
+
let children = !isEmpty(props2) ? makeNode2(
|
|
1484
|
+
range ? [{ $key: range, ...props2 }] : props2,
|
|
1405
1485
|
void 0,
|
|
1406
1486
|
$ver
|
|
1407
1487
|
).children : isDef($chi) ? makeNode2(
|
|
@@ -1414,19 +1494,31 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1414
1494
|
}
|
|
1415
1495
|
}
|
|
1416
1496
|
const combine = isGraph ? merge : add;
|
|
1417
|
-
function makeNode2(object, key, ver) {
|
|
1497
|
+
function makeNode2(object, key, ver, parentPuts = []) {
|
|
1418
1498
|
var _a2;
|
|
1419
1499
|
if (!isDef(object))
|
|
1420
1500
|
return;
|
|
1421
1501
|
if (typeof object === "object" && object && isEmpty(object))
|
|
1422
1502
|
return;
|
|
1423
|
-
const { $key, $ver, $ref, $val, $chi, $put, ...
|
|
1503
|
+
const { $key, $ver, $ref, $val, $chi, $put, ...props2 } = object || {};
|
|
1504
|
+
if (typeof object === "object" && object && !Array.isArray(object)) {
|
|
1505
|
+
object = Object.fromEntries(
|
|
1506
|
+
Object.entries({ $key, $ver, $ref, $val, $chi, $put, ...props2 }).filter(
|
|
1507
|
+
([_, val]) => isDef(val)
|
|
1508
|
+
)
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1424
1511
|
if (isDef($ver))
|
|
1425
1512
|
ver = $ver;
|
|
1426
1513
|
if (isPlainObject($key)) {
|
|
1427
1514
|
const [page, filter] = splitArgs($key);
|
|
1428
|
-
|
|
1429
|
-
|
|
1515
|
+
const foundPuts = parentPuts.filter(([_, putFilter]) => isEqual(filter, putFilter)).map(([range]) => range);
|
|
1516
|
+
if (isGraph && page && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props2))) {
|
|
1517
|
+
const node2 = makeNode2(
|
|
1518
|
+
{ ...object, $key: filter || {}, $put: foundPuts },
|
|
1519
|
+
key,
|
|
1520
|
+
ver
|
|
1521
|
+
);
|
|
1430
1522
|
if (!filter)
|
|
1431
1523
|
node2.key = MIN_KEY;
|
|
1432
1524
|
node2.prefix = true;
|
|
@@ -1438,7 +1530,8 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1438
1530
|
$key: filter || {},
|
|
1439
1531
|
$chi: [
|
|
1440
1532
|
{ ...object, $key: isDef(page.$cursor) ? page.$cursor : page }
|
|
1441
|
-
]
|
|
1533
|
+
],
|
|
1534
|
+
...isGraph ? { $put: foundPuts } : {}
|
|
1442
1535
|
},
|
|
1443
1536
|
key,
|
|
1444
1537
|
ver
|
|
@@ -1449,6 +1542,25 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1449
1542
|
return node2;
|
|
1450
1543
|
}
|
|
1451
1544
|
}
|
|
1545
|
+
let putQuery = [], prefixPuts = [];
|
|
1546
|
+
if (Array.isArray(object) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1547
|
+
putQuery = [encode$3({ $since: 0, $until: Infinity })];
|
|
1548
|
+
}
|
|
1549
|
+
function classifyPut(put) {
|
|
1550
|
+
const [range, filter] = splitArgs(put);
|
|
1551
|
+
if (filter) {
|
|
1552
|
+
prefixPuts.push([range, filter]);
|
|
1553
|
+
} else {
|
|
1554
|
+
putQuery.push(encode$3(put));
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
if ($put === true) {
|
|
1558
|
+
putQuery = null;
|
|
1559
|
+
} else if (Array.isArray($put)) {
|
|
1560
|
+
$put.forEach(classifyPut);
|
|
1561
|
+
} else if (isDef($put)) {
|
|
1562
|
+
classifyPut($put);
|
|
1563
|
+
}
|
|
1452
1564
|
if (isDef($key) && (Number.isInteger(key) || !isDef(key)))
|
|
1453
1565
|
key = $key;
|
|
1454
1566
|
const node = key === ROOT_KEY || !isDef(key) ? {} : encode$3(key);
|
|
@@ -1456,26 +1568,28 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1456
1568
|
if (object === null) {
|
|
1457
1569
|
node.end = node.key;
|
|
1458
1570
|
} else if (isDef($key) && isDef(key) && key !== $key) {
|
|
1459
|
-
node.children = [makeNode2(object, void 0, ver)].filter(
|
|
1571
|
+
node.children = [makeNode2(object, void 0, ver, prefixPuts)].filter(
|
|
1572
|
+
Boolean
|
|
1573
|
+
);
|
|
1460
1574
|
return node;
|
|
1461
1575
|
} else if ($ref) {
|
|
1462
|
-
pushLink($ref, node.version,
|
|
1576
|
+
pushLink($ref, node.version, props2, $val, $chi);
|
|
1463
1577
|
if (!isGraph)
|
|
1464
1578
|
return;
|
|
1465
1579
|
node.path = encode$2($ref);
|
|
1466
1580
|
} else if ($val === true) {
|
|
1467
|
-
node.value =
|
|
1581
|
+
node.value = props2;
|
|
1468
1582
|
} else if (isDef($val)) {
|
|
1469
1583
|
node.value = $val;
|
|
1470
1584
|
} else if (typeof object !== "object") {
|
|
1471
1585
|
node.value = isGraph || typeof object === "number" ? object : 1;
|
|
1472
1586
|
} else if (isDef($chi)) {
|
|
1473
|
-
const children = $chi.map((obj) => makeNode2(obj, void 0, ver)).filter(Boolean).sort((a, b) => cmp(a.key, b.key));
|
|
1587
|
+
const children = $chi.map((obj) => makeNode2(obj, void 0, ver, prefixPuts)).filter(Boolean).sort((a, b) => cmp(a.key, b.key));
|
|
1474
1588
|
if (children.length) {
|
|
1475
1589
|
node.children = children;
|
|
1476
1590
|
}
|
|
1477
1591
|
} else if (Array.isArray(object)) {
|
|
1478
|
-
const children = object.map((obj, i) => makeNode2(obj, i, ver)).filter(Boolean).reduce((acc, it) => {
|
|
1592
|
+
const children = object.map((obj, i) => makeNode2(obj, i, ver, prefixPuts)).filter(Boolean).reduce((acc, it) => {
|
|
1479
1593
|
combine(acc, [it]);
|
|
1480
1594
|
return acc;
|
|
1481
1595
|
}, []);
|
|
@@ -1483,7 +1597,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1483
1597
|
node.children = children;
|
|
1484
1598
|
}
|
|
1485
1599
|
} else {
|
|
1486
|
-
const children = Object.keys(
|
|
1600
|
+
const children = Object.keys(props2).sort().map((key2) => makeNode2(object[key2], key2, ver)).filter(Boolean);
|
|
1487
1601
|
if (children.length) {
|
|
1488
1602
|
node.children = children;
|
|
1489
1603
|
} else if (isGraph) {
|
|
@@ -1497,19 +1611,13 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1497
1611
|
node.value = 1;
|
|
1498
1612
|
}
|
|
1499
1613
|
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
putQuery = $put.map((arg) => encode$3(arg));
|
|
1508
|
-
} else if (isDef($put)) {
|
|
1509
|
-
putQuery = [encode$3($put)];
|
|
1510
|
-
}
|
|
1511
|
-
if (isGraph && isDef(putQuery)) {
|
|
1512
|
-
node.children = finalize(node.children || [], putQuery, node.version);
|
|
1614
|
+
if (isGraph && (putQuery === null || putQuery.length)) {
|
|
1615
|
+
node.children = finalize(
|
|
1616
|
+
node.children || [],
|
|
1617
|
+
putQuery,
|
|
1618
|
+
node.version,
|
|
1619
|
+
true
|
|
1620
|
+
);
|
|
1513
1621
|
}
|
|
1514
1622
|
if (((_a2 = node.children) == null ? void 0 : _a2.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
|
|
1515
1623
|
return node;
|
|
@@ -1524,7 +1632,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1524
1632
|
return result;
|
|
1525
1633
|
}
|
|
1526
1634
|
function encodeGraph(obj, version = Date.now()) {
|
|
1527
|
-
return encode(obj, { version, isGraph: true });
|
|
1635
|
+
return setVersion(encode(obj, { version, isGraph: true }), version, true);
|
|
1528
1636
|
}
|
|
1529
1637
|
function encodeQuery(obj, version = 0) {
|
|
1530
1638
|
return encode(obj, { version, isGraph: false });
|
|
@@ -1648,7 +1756,6 @@ export {
|
|
|
1648
1756
|
decodeQuery,
|
|
1649
1757
|
decode$4 as decodeValue,
|
|
1650
1758
|
decorate,
|
|
1651
|
-
deserialize,
|
|
1652
1759
|
encode$3 as encodeArgs,
|
|
1653
1760
|
encodeGraph,
|
|
1654
1761
|
encode$2 as encodePath,
|
|
@@ -1681,13 +1788,14 @@ export {
|
|
|
1681
1788
|
merge,
|
|
1682
1789
|
mergeObject,
|
|
1683
1790
|
mergeStreams,
|
|
1791
|
+
pack,
|
|
1684
1792
|
remove,
|
|
1685
|
-
serialize,
|
|
1686
1793
|
setVersion,
|
|
1687
1794
|
sieve,
|
|
1688
1795
|
slice,
|
|
1689
1796
|
splitArgs,
|
|
1690
1797
|
splitRef,
|
|
1798
|
+
unpack,
|
|
1691
1799
|
unwrap,
|
|
1692
1800
|
unwrapObject,
|
|
1693
1801
|
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.10",
|
|
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.10"
|
|
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";
|
package/types/ops/finalize.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function setVersion(graph: any, version: any): any;
|
|
1
|
+
export default function setVersion(graph: any, version: any, onlyIfZero?: boolean): any;
|