@graffy/common 0.15.9 → 0.15.11-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 +21 -17
- package/index.mjs +21 -17
- package/package.json +2 -2
- package/types/node/find.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -452,17 +452,17 @@ function splitRef($ref) {
|
|
|
452
452
|
return splitArgs(tail);
|
|
453
453
|
}
|
|
454
454
|
var id = nonSecure.customAlphabet(alpha, 20);
|
|
455
|
-
function findFirst(children, target) {
|
|
455
|
+
function findFirst(children, target, first, last) {
|
|
456
456
|
return find(children, ({ key, end }) => {
|
|
457
457
|
if (key === target || end && key < target && end >= target)
|
|
458
458
|
return 0;
|
|
459
459
|
if (key < target)
|
|
460
460
|
return -1;
|
|
461
461
|
return 1;
|
|
462
|
-
});
|
|
462
|
+
}, first, last);
|
|
463
463
|
}
|
|
464
464
|
function findLast(children, end, first, last) {
|
|
465
|
-
const ix = findFirst(children, end);
|
|
465
|
+
const ix = findFirst(children, end, first, last);
|
|
466
466
|
return children[ix] && children[ix].key <= end ? ix + 1 : ix;
|
|
467
467
|
}
|
|
468
468
|
function isRange(node) {
|
|
@@ -534,6 +534,8 @@ function clone(node) {
|
|
|
534
534
|
}
|
|
535
535
|
function merge(current, changes) {
|
|
536
536
|
let index = 0;
|
|
537
|
+
if (typeof changes === "undefined")
|
|
538
|
+
return current;
|
|
537
539
|
for (const change of changes) {
|
|
538
540
|
index = isRange(change) ? insertRange$1(current, change, index) : insertNode$1(current, change, index);
|
|
539
541
|
}
|
|
@@ -541,8 +543,8 @@ function merge(current, changes) {
|
|
|
541
543
|
}
|
|
542
544
|
function insertRange$1(current, change, start = 0) {
|
|
543
545
|
const { key, end } = change;
|
|
544
|
-
const keyIx = findFirst(current, key);
|
|
545
|
-
const endIx = findLast(current, end);
|
|
546
|
+
const keyIx = findFirst(current, key, start);
|
|
547
|
+
const endIx = findLast(current, end, keyIx);
|
|
546
548
|
const insertions = [change];
|
|
547
549
|
for (let i = keyIx; i < endIx; i++) {
|
|
548
550
|
const node = current[i];
|
|
@@ -553,7 +555,7 @@ function insertRange$1(current, change, start = 0) {
|
|
|
553
555
|
}
|
|
554
556
|
}
|
|
555
557
|
current.splice(keyIx, endIx - keyIx, ...insertions);
|
|
556
|
-
return keyIx + insertions.length;
|
|
558
|
+
return keyIx + insertions.length - 1;
|
|
557
559
|
}
|
|
558
560
|
function mergeRanges$1(base, node) {
|
|
559
561
|
if (node.version < base.version)
|
|
@@ -568,7 +570,7 @@ function insertNode$1(current, change, start = 0) {
|
|
|
568
570
|
if (!current)
|
|
569
571
|
throw new Error("merge.insertNode: " + current);
|
|
570
572
|
const key = change.key;
|
|
571
|
-
const index = findFirst(current, key);
|
|
573
|
+
const index = findFirst(current, key, start);
|
|
572
574
|
const node = current[index];
|
|
573
575
|
if (node && node.key <= key) {
|
|
574
576
|
return isRange(node) ? insertNodeIntoRange$1(current, index, change) : updateNode$1(current, index, change);
|
|
@@ -589,7 +591,7 @@ function insertNodeIntoRange$1(current, index, change) {
|
|
|
589
591
|
range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
|
|
590
592
|
].filter(Boolean);
|
|
591
593
|
current.splice(index, 1, ...insertions);
|
|
592
|
-
return index + insertions.length;
|
|
594
|
+
return index + insertions.length - 1;
|
|
593
595
|
}
|
|
594
596
|
function updateNode$1(current, index, change) {
|
|
595
597
|
const node = current[index];
|
|
@@ -684,7 +686,7 @@ function remove(children, path) {
|
|
|
684
686
|
if (!isBranch(node))
|
|
685
687
|
return children;
|
|
686
688
|
const filteredChildren = remove(node.children, path.slice(1));
|
|
687
|
-
if (filteredChildren ===
|
|
689
|
+
if (filteredChildren === children)
|
|
688
690
|
return children;
|
|
689
691
|
const filteredNode = filteredChildren.length ? __spreadProps(__spreadValues({}, node), { children: filteredChildren }) : [];
|
|
690
692
|
return children.slice(0, ix).concat(filteredNode, children.slice(ix + 1));
|
|
@@ -818,8 +820,8 @@ function sieve(current, changes, result = []) {
|
|
|
818
820
|
}
|
|
819
821
|
function insertRange(current, change, result, start = 0) {
|
|
820
822
|
const { key, end } = change;
|
|
821
|
-
const keyIx = findFirst(current, key);
|
|
822
|
-
const endIx = findLast(current, end);
|
|
823
|
+
const keyIx = findFirst(current, key, start);
|
|
824
|
+
const endIx = findLast(current, end, keyIx);
|
|
823
825
|
if (keyIx === endIx && !(current[keyIx] && current[keyIx].key <= key && current[keyIx].end >= end)) {
|
|
824
826
|
return keyIx;
|
|
825
827
|
}
|
|
@@ -869,7 +871,7 @@ function insertRange(current, change, result, start = 0) {
|
|
|
869
871
|
}
|
|
870
872
|
}
|
|
871
873
|
current.splice(keyIx, endIx - keyIx, ...insertions);
|
|
872
|
-
return keyIx + insertions.length;
|
|
874
|
+
return keyIx + insertions.length - 1;
|
|
873
875
|
}
|
|
874
876
|
function mergeRanges(base, node) {
|
|
875
877
|
if (node.version < base.version)
|
|
@@ -882,7 +884,7 @@ function mergeRanges(base, node) {
|
|
|
882
884
|
}
|
|
883
885
|
function insertNode(current, change, result, start = 0) {
|
|
884
886
|
const key = change.key;
|
|
885
|
-
const index = findFirst(current, key);
|
|
887
|
+
const index = findFirst(current, key, start);
|
|
886
888
|
const node = current[index];
|
|
887
889
|
if (node && node.key <= key) {
|
|
888
890
|
return isRange(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result);
|
|
@@ -904,7 +906,7 @@ function insertNodeIntoRange(current, index, change, result) {
|
|
|
904
906
|
range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
|
|
905
907
|
].filter(Boolean);
|
|
906
908
|
current.splice(index, 1, ...insertions);
|
|
907
|
-
return index + insertions.length;
|
|
909
|
+
return index + insertions.length - 1;
|
|
908
910
|
}
|
|
909
911
|
function updateNode(current, index, change, result) {
|
|
910
912
|
const node = current[index];
|
|
@@ -989,9 +991,10 @@ function getKnown(graph, version = 0) {
|
|
|
989
991
|
}
|
|
990
992
|
function finalize(graph, query, version = Date.now()) {
|
|
991
993
|
let result = [{ key: "", end: "\uFFFF", version: 0 }];
|
|
994
|
+
merge(result, graph);
|
|
992
995
|
if (query)
|
|
993
996
|
result = slice(result, query).known || [];
|
|
994
|
-
result = setVersion(
|
|
997
|
+
result = setVersion(result, version);
|
|
995
998
|
return result;
|
|
996
999
|
}
|
|
997
1000
|
function decode(nodes = [], { isGraph } = {}) {
|
|
@@ -1059,7 +1062,7 @@ function decode(nodes = [], { isGraph } = {}) {
|
|
|
1059
1062
|
}, allStrs ? {} : []);
|
|
1060
1063
|
}
|
|
1061
1064
|
if (isGraph && putRanges.length) {
|
|
1062
|
-
if (putRanges
|
|
1065
|
+
if (putRanges[0].key === "" && putRanges[0].end === "\uFFFF") {
|
|
1063
1066
|
result.$put = true;
|
|
1064
1067
|
} else {
|
|
1065
1068
|
result.$put = putRanges.map((rNode) => decode$2(rNode));
|
|
@@ -1169,7 +1172,8 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1169
1172
|
return subResult;
|
|
1170
1173
|
});
|
|
1171
1174
|
});
|
|
1172
|
-
|
|
1175
|
+
if (pageKey)
|
|
1176
|
+
addPageMeta(graph, pageKey);
|
|
1173
1177
|
} else if (typeof query === "object") {
|
|
1174
1178
|
graph = {};
|
|
1175
1179
|
for (const prop in query) {
|
package/index.mjs
CHANGED
|
@@ -444,17 +444,17 @@ function splitRef($ref) {
|
|
|
444
444
|
return splitArgs(tail);
|
|
445
445
|
}
|
|
446
446
|
var id = customAlphabet(alpha, 20);
|
|
447
|
-
function findFirst(children, target) {
|
|
447
|
+
function findFirst(children, target, first, last) {
|
|
448
448
|
return find(children, ({ key, end }) => {
|
|
449
449
|
if (key === target || end && key < target && end >= target)
|
|
450
450
|
return 0;
|
|
451
451
|
if (key < target)
|
|
452
452
|
return -1;
|
|
453
453
|
return 1;
|
|
454
|
-
});
|
|
454
|
+
}, first, last);
|
|
455
455
|
}
|
|
456
456
|
function findLast(children, end, first, last) {
|
|
457
|
-
const ix = findFirst(children, end);
|
|
457
|
+
const ix = findFirst(children, end, first, last);
|
|
458
458
|
return children[ix] && children[ix].key <= end ? ix + 1 : ix;
|
|
459
459
|
}
|
|
460
460
|
function isRange(node) {
|
|
@@ -526,6 +526,8 @@ function clone(node) {
|
|
|
526
526
|
}
|
|
527
527
|
function merge(current, changes) {
|
|
528
528
|
let index = 0;
|
|
529
|
+
if (typeof changes === "undefined")
|
|
530
|
+
return current;
|
|
529
531
|
for (const change of changes) {
|
|
530
532
|
index = isRange(change) ? insertRange$1(current, change, index) : insertNode$1(current, change, index);
|
|
531
533
|
}
|
|
@@ -533,8 +535,8 @@ function merge(current, changes) {
|
|
|
533
535
|
}
|
|
534
536
|
function insertRange$1(current, change, start = 0) {
|
|
535
537
|
const { key, end } = change;
|
|
536
|
-
const keyIx = findFirst(current, key);
|
|
537
|
-
const endIx = findLast(current, end);
|
|
538
|
+
const keyIx = findFirst(current, key, start);
|
|
539
|
+
const endIx = findLast(current, end, keyIx);
|
|
538
540
|
const insertions = [change];
|
|
539
541
|
for (let i = keyIx; i < endIx; i++) {
|
|
540
542
|
const node = current[i];
|
|
@@ -545,7 +547,7 @@ function insertRange$1(current, change, start = 0) {
|
|
|
545
547
|
}
|
|
546
548
|
}
|
|
547
549
|
current.splice(keyIx, endIx - keyIx, ...insertions);
|
|
548
|
-
return keyIx + insertions.length;
|
|
550
|
+
return keyIx + insertions.length - 1;
|
|
549
551
|
}
|
|
550
552
|
function mergeRanges$1(base, node) {
|
|
551
553
|
if (node.version < base.version)
|
|
@@ -560,7 +562,7 @@ function insertNode$1(current, change, start = 0) {
|
|
|
560
562
|
if (!current)
|
|
561
563
|
throw new Error("merge.insertNode: " + current);
|
|
562
564
|
const key = change.key;
|
|
563
|
-
const index = findFirst(current, key);
|
|
565
|
+
const index = findFirst(current, key, start);
|
|
564
566
|
const node = current[index];
|
|
565
567
|
if (node && node.key <= key) {
|
|
566
568
|
return isRange(node) ? insertNodeIntoRange$1(current, index, change) : updateNode$1(current, index, change);
|
|
@@ -581,7 +583,7 @@ function insertNodeIntoRange$1(current, index, change) {
|
|
|
581
583
|
range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
|
|
582
584
|
].filter(Boolean);
|
|
583
585
|
current.splice(index, 1, ...insertions);
|
|
584
|
-
return index + insertions.length;
|
|
586
|
+
return index + insertions.length - 1;
|
|
585
587
|
}
|
|
586
588
|
function updateNode$1(current, index, change) {
|
|
587
589
|
const node = current[index];
|
|
@@ -676,7 +678,7 @@ function remove(children, path) {
|
|
|
676
678
|
if (!isBranch(node))
|
|
677
679
|
return children;
|
|
678
680
|
const filteredChildren = remove(node.children, path.slice(1));
|
|
679
|
-
if (filteredChildren ===
|
|
681
|
+
if (filteredChildren === children)
|
|
680
682
|
return children;
|
|
681
683
|
const filteredNode = filteredChildren.length ? __spreadProps(__spreadValues({}, node), { children: filteredChildren }) : [];
|
|
682
684
|
return children.slice(0, ix).concat(filteredNode, children.slice(ix + 1));
|
|
@@ -810,8 +812,8 @@ function sieve(current, changes, result = []) {
|
|
|
810
812
|
}
|
|
811
813
|
function insertRange(current, change, result, start = 0) {
|
|
812
814
|
const { key, end } = change;
|
|
813
|
-
const keyIx = findFirst(current, key);
|
|
814
|
-
const endIx = findLast(current, end);
|
|
815
|
+
const keyIx = findFirst(current, key, start);
|
|
816
|
+
const endIx = findLast(current, end, keyIx);
|
|
815
817
|
if (keyIx === endIx && !(current[keyIx] && current[keyIx].key <= key && current[keyIx].end >= end)) {
|
|
816
818
|
return keyIx;
|
|
817
819
|
}
|
|
@@ -861,7 +863,7 @@ function insertRange(current, change, result, start = 0) {
|
|
|
861
863
|
}
|
|
862
864
|
}
|
|
863
865
|
current.splice(keyIx, endIx - keyIx, ...insertions);
|
|
864
|
-
return keyIx + insertions.length;
|
|
866
|
+
return keyIx + insertions.length - 1;
|
|
865
867
|
}
|
|
866
868
|
function mergeRanges(base, node) {
|
|
867
869
|
if (node.version < base.version)
|
|
@@ -874,7 +876,7 @@ function mergeRanges(base, node) {
|
|
|
874
876
|
}
|
|
875
877
|
function insertNode(current, change, result, start = 0) {
|
|
876
878
|
const key = change.key;
|
|
877
|
-
const index = findFirst(current, key);
|
|
879
|
+
const index = findFirst(current, key, start);
|
|
878
880
|
const node = current[index];
|
|
879
881
|
if (node && node.key <= key) {
|
|
880
882
|
return isRange(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result);
|
|
@@ -896,7 +898,7 @@ function insertNodeIntoRange(current, index, change, result) {
|
|
|
896
898
|
range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
|
|
897
899
|
].filter(Boolean);
|
|
898
900
|
current.splice(index, 1, ...insertions);
|
|
899
|
-
return index + insertions.length;
|
|
901
|
+
return index + insertions.length - 1;
|
|
900
902
|
}
|
|
901
903
|
function updateNode(current, index, change, result) {
|
|
902
904
|
const node = current[index];
|
|
@@ -981,9 +983,10 @@ function getKnown(graph, version = 0) {
|
|
|
981
983
|
}
|
|
982
984
|
function finalize(graph, query, version = Date.now()) {
|
|
983
985
|
let result = [{ key: "", end: "\uFFFF", version: 0 }];
|
|
986
|
+
merge(result, graph);
|
|
984
987
|
if (query)
|
|
985
988
|
result = slice(result, query).known || [];
|
|
986
|
-
result = setVersion(
|
|
989
|
+
result = setVersion(result, version);
|
|
987
990
|
return result;
|
|
988
991
|
}
|
|
989
992
|
function decode(nodes = [], { isGraph } = {}) {
|
|
@@ -1051,7 +1054,7 @@ function decode(nodes = [], { isGraph } = {}) {
|
|
|
1051
1054
|
}, allStrs ? {} : []);
|
|
1052
1055
|
}
|
|
1053
1056
|
if (isGraph && putRanges.length) {
|
|
1054
|
-
if (putRanges
|
|
1057
|
+
if (putRanges[0].key === "" && putRanges[0].end === "\uFFFF") {
|
|
1055
1058
|
result.$put = true;
|
|
1056
1059
|
} else {
|
|
1057
1060
|
result.$put = putRanges.map((rNode) => decode$2(rNode));
|
|
@@ -1161,7 +1164,8 @@ function decorate(rootGraph, rootQuery) {
|
|
|
1161
1164
|
return subResult;
|
|
1162
1165
|
});
|
|
1163
1166
|
});
|
|
1164
|
-
|
|
1167
|
+
if (pageKey)
|
|
1168
|
+
addPageMeta(graph, pageKey);
|
|
1165
1169
|
} else if (typeof query === "object") {
|
|
1166
1170
|
graph = {};
|
|
1167
1171
|
for (const prop in query) {
|
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.15.
|
|
5
|
+
"version": "0.15.11-alpha.1",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"lodash": "^4.17.19",
|
|
20
20
|
"nanoid": "^3.1.25",
|
|
21
21
|
"merge-async-iterators": "^0.2.1",
|
|
22
|
-
"@graffy/stream": "0.15.
|
|
22
|
+
"@graffy/stream": "0.15.11-alpha.1"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/types/node/find.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function findFirst(children: any, target: any): number;
|
|
1
|
+
export function findFirst(children: any, target: any, first: any, last: any): number;
|
|
2
2
|
export function findLast(children: any, end: any, first: any, last: any): number;
|