@graffy/common 0.16.10-alpha.1 → 0.16.11
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 +84 -93
- package/index.mjs +84 -93
- package/package.json +3 -2
package/index.cjs
CHANGED
|
@@ -1,47 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const debug = require("debug");
|
|
3
4
|
const isEqual = require("lodash/isEqual.js");
|
|
4
5
|
const mergeIterators = require("merge-async-iterators");
|
|
5
6
|
const stream = require("@graffy/stream");
|
|
6
|
-
const
|
|
7
|
-
const textDecoder = new TextDecoder("utf-8");
|
|
8
|
-
function encode$6(string) {
|
|
9
|
-
return textEncoder.encode(string);
|
|
10
|
-
}
|
|
11
|
-
function decode$6(u8Arr) {
|
|
12
|
-
return textDecoder.decode(u8Arr);
|
|
13
|
-
}
|
|
14
|
-
function TwosComplement(view) {
|
|
15
|
-
let lo = -view.getUint32(4) >>> 0;
|
|
16
|
-
const carry = lo ? 0 : -1;
|
|
17
|
-
let hi = ~view.getUint32(0) + carry >>> 0;
|
|
18
|
-
view.setUint32(0, hi);
|
|
19
|
-
view.setUint32(4, lo);
|
|
20
|
-
}
|
|
21
|
-
function encode$5(number) {
|
|
22
|
-
const buffer = new ArrayBuffer(8);
|
|
23
|
-
const view = new DataView(buffer);
|
|
24
|
-
view.setFloat64(0, number);
|
|
25
|
-
if (number < 0) {
|
|
26
|
-
TwosComplement(view);
|
|
27
|
-
} else {
|
|
28
|
-
view.setUint8(0, view.getUint8(0) | 128);
|
|
29
|
-
}
|
|
30
|
-
return new Uint8Array(buffer);
|
|
31
|
-
}
|
|
32
|
-
function decode$5(u8Arr) {
|
|
33
|
-
const copy = new Uint8Array(8);
|
|
34
|
-
copy.set(u8Arr, 0);
|
|
35
|
-
const { buffer, byteOffset, byteLength } = copy;
|
|
36
|
-
const view = new DataView(buffer, byteOffset, byteLength);
|
|
37
|
-
const high = view.getUint8(0);
|
|
38
|
-
if (high & 128) {
|
|
39
|
-
view.setUint8(0, high & 127);
|
|
40
|
-
} else {
|
|
41
|
-
TwosComplement(view);
|
|
42
|
-
}
|
|
43
|
-
return view.getFloat64(0);
|
|
44
|
-
}
|
|
7
|
+
const isDebugMode = debug("graffy*").enabled;
|
|
45
8
|
const MIN_KEY = new Uint8Array();
|
|
46
9
|
const MAX_KEY = new Uint8Array([255]);
|
|
47
10
|
function isMinKey(key) {
|
|
@@ -73,9 +36,8 @@ function isPlainObject(arg) {
|
|
|
73
36
|
function clone$1(obj) {
|
|
74
37
|
if (Array.isArray(obj)) {
|
|
75
38
|
return obj.slice(0);
|
|
76
|
-
} else {
|
|
77
|
-
return { ...obj };
|
|
78
39
|
}
|
|
40
|
+
return { ...obj };
|
|
79
41
|
}
|
|
80
42
|
function cmp(a, b) {
|
|
81
43
|
const l = a.length < b.length ? a.length : b.length;
|
|
@@ -107,40 +69,75 @@ function find(items, compare2, first = 0, last = items.length) {
|
|
|
107
69
|
}
|
|
108
70
|
return currentFirst;
|
|
109
71
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
72
|
+
function stringify() {
|
|
73
|
+
var _a;
|
|
74
|
+
if ((this == null ? void 0 : this.length) === 0)
|
|
75
|
+
return "·";
|
|
76
|
+
let str = "";
|
|
77
|
+
let bull = false;
|
|
78
|
+
(_a = this == null ? void 0 : this.forEach) == null ? void 0 : _a.call(this, (value, i) => {
|
|
79
|
+
if (value >= 32 && value <= 126) {
|
|
80
|
+
str += String.fromCharCode(value);
|
|
81
|
+
bull = true;
|
|
82
|
+
} else {
|
|
83
|
+
str += (bull ? "·" : "") + `0${value.toString(16)}`.slice(-2) + (i < this.length - 1 ? "·" : "");
|
|
84
|
+
bull = false;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return str;
|
|
88
|
+
}
|
|
89
|
+
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
129
90
|
function addStringify(buffer) {
|
|
130
|
-
if (
|
|
91
|
+
if (!isDebugMode)
|
|
131
92
|
return buffer;
|
|
132
|
-
if ("toJSON" in buffer ||
|
|
93
|
+
if ("toJSON" in buffer || inspectSymbol in buffer)
|
|
133
94
|
return buffer;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
toString: stringifyDescriptor,
|
|
138
|
-
[Symbol.for("nodejs.util.inspect.custom")]: stringifyDescriptor
|
|
139
|
-
});
|
|
95
|
+
buffer.toJSON = stringify;
|
|
96
|
+
buffer.toString = stringify;
|
|
97
|
+
buffer[inspectSymbol] = stringify;
|
|
140
98
|
return buffer;
|
|
141
99
|
}
|
|
142
100
|
addStringify(MIN_KEY);
|
|
143
101
|
addStringify(MAX_KEY);
|
|
102
|
+
function TwosComplement(view) {
|
|
103
|
+
const lo = -view.getUint32(4) >>> 0;
|
|
104
|
+
const carry = lo ? 0 : -1;
|
|
105
|
+
const hi = ~view.getUint32(0) + carry >>> 0;
|
|
106
|
+
view.setUint32(0, hi);
|
|
107
|
+
view.setUint32(4, lo);
|
|
108
|
+
}
|
|
109
|
+
function encode$6(number) {
|
|
110
|
+
const buffer = new ArrayBuffer(8);
|
|
111
|
+
const view = new DataView(buffer);
|
|
112
|
+
view.setFloat64(0, number);
|
|
113
|
+
if (number < 0) {
|
|
114
|
+
TwosComplement(view);
|
|
115
|
+
} else {
|
|
116
|
+
view.setUint8(0, view.getUint8(0) | 128);
|
|
117
|
+
}
|
|
118
|
+
return new Uint8Array(buffer);
|
|
119
|
+
}
|
|
120
|
+
function decode$6(u8Arr) {
|
|
121
|
+
const copy = new Uint8Array(8);
|
|
122
|
+
copy.set(u8Arr, 0);
|
|
123
|
+
const { buffer, byteOffset, byteLength } = copy;
|
|
124
|
+
const view = new DataView(buffer, byteOffset, byteLength);
|
|
125
|
+
const high = view.getUint8(0);
|
|
126
|
+
if (high & 128) {
|
|
127
|
+
view.setUint8(0, high & 127);
|
|
128
|
+
} else {
|
|
129
|
+
TwosComplement(view);
|
|
130
|
+
}
|
|
131
|
+
return view.getFloat64(0);
|
|
132
|
+
}
|
|
133
|
+
const textEncoder = new TextEncoder();
|
|
134
|
+
const textDecoder = new TextDecoder("utf-8");
|
|
135
|
+
function encode$5(string) {
|
|
136
|
+
return textEncoder.encode(string);
|
|
137
|
+
}
|
|
138
|
+
function decode$5(u8Arr) {
|
|
139
|
+
return textDecoder.decode(u8Arr);
|
|
140
|
+
}
|
|
144
141
|
const END = 0;
|
|
145
142
|
const NULL = 1;
|
|
146
143
|
const FALSE = 2;
|
|
@@ -159,7 +156,7 @@ function encodeObject(object) {
|
|
|
159
156
|
OBJ,
|
|
160
157
|
...keys.flatMap((key) => [
|
|
161
158
|
STR,
|
|
162
|
-
encode$
|
|
159
|
+
encode$5(key),
|
|
163
160
|
END,
|
|
164
161
|
...encodeParts(object[key])
|
|
165
162
|
]),
|
|
@@ -174,9 +171,9 @@ function encodeParts(value) {
|
|
|
174
171
|
if (value === true)
|
|
175
172
|
return [TRUE];
|
|
176
173
|
if (typeof value === "number")
|
|
177
|
-
return [NUM, encode$
|
|
174
|
+
return [NUM, encode$6(value)];
|
|
178
175
|
if (typeof value === "string")
|
|
179
|
-
return [STR, encode$
|
|
176
|
+
return [STR, encode$5(value), END];
|
|
180
177
|
if (Array.isArray(value))
|
|
181
178
|
return encodeArray(value);
|
|
182
179
|
if (typeof value === "object")
|
|
@@ -221,10 +218,10 @@ function decode$4(buffer) {
|
|
|
221
218
|
let i = 0;
|
|
222
219
|
const stack = [[]];
|
|
223
220
|
function readString() {
|
|
224
|
-
|
|
221
|
+
const start = i;
|
|
225
222
|
while (i < buffer.length && buffer[i] !== END)
|
|
226
223
|
i++;
|
|
227
|
-
const str = decode$
|
|
224
|
+
const str = decode$5(buffer.subarray(start, i));
|
|
228
225
|
i++;
|
|
229
226
|
return str;
|
|
230
227
|
}
|
|
@@ -268,7 +265,7 @@ function decode$4(buffer) {
|
|
|
268
265
|
break;
|
|
269
266
|
case NUM:
|
|
270
267
|
i += 8;
|
|
271
|
-
pushToken(type, decode$
|
|
268
|
+
pushToken(type, decode$6(buffer.subarray(start, i)));
|
|
272
269
|
break;
|
|
273
270
|
case STR:
|
|
274
271
|
pushToken(type, readString());
|
|
@@ -608,10 +605,9 @@ function insertNode$1(current, change, start = 0) {
|
|
|
608
605
|
const node = current[index];
|
|
609
606
|
if (node && cmp(node.key, key) <= 0) {
|
|
610
607
|
return isRange(node) ? insertNodeIntoRange$1(current, index, change) : updateNode$1(current, index, change);
|
|
611
|
-
} else {
|
|
612
|
-
current.splice(index, 0, change);
|
|
613
|
-
return index + 1;
|
|
614
608
|
}
|
|
609
|
+
current.splice(index, 0, change);
|
|
610
|
+
return index + 1;
|
|
615
611
|
}
|
|
616
612
|
function insertNodeIntoRange$1(current, index, change) {
|
|
617
613
|
const key = change.key;
|
|
@@ -649,9 +645,8 @@ function getNewer(node, base) {
|
|
|
649
645
|
const children = [{ key: MIN_KEY, end: MAX_KEY, version }];
|
|
650
646
|
merge(children, node.children);
|
|
651
647
|
return children.length === 1 ? null : { ...node, children };
|
|
652
|
-
} else {
|
|
653
|
-
return node.version >= version ? node : null;
|
|
654
648
|
}
|
|
649
|
+
return node.version >= version ? node : null;
|
|
655
650
|
}
|
|
656
651
|
const IS_VAL = Symbol("IS_VAL");
|
|
657
652
|
function makeNode(seg, props2) {
|
|
@@ -755,7 +750,7 @@ class Result {
|
|
|
755
750
|
}
|
|
756
751
|
}
|
|
757
752
|
function slice(graph, query, root) {
|
|
758
|
-
|
|
753
|
+
const result = new Result(root);
|
|
759
754
|
let currentQuery = query;
|
|
760
755
|
while (currentQuery) {
|
|
761
756
|
let index = 0;
|
|
@@ -950,9 +945,8 @@ function insertNode(current, change, result, start = 0) {
|
|
|
950
945
|
const node = current[index];
|
|
951
946
|
if (node && cmp(node.key, key) <= 0) {
|
|
952
947
|
return isRange(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result);
|
|
953
|
-
} else {
|
|
954
|
-
return index;
|
|
955
948
|
}
|
|
949
|
+
return index;
|
|
956
950
|
}
|
|
957
951
|
function insertNodeIntoRange(current, index, change, result) {
|
|
958
952
|
const key = change.key;
|
|
@@ -1013,9 +1007,8 @@ function getNewerNode(node, base) {
|
|
|
1013
1007
|
const children = [emptyNode];
|
|
1014
1008
|
sieve(children, node.children);
|
|
1015
1009
|
return children.length === 1 && children[0] === emptyNode ? null : { ...node, children };
|
|
1016
|
-
} else {
|
|
1017
|
-
return node.version >= base.version ? node : null;
|
|
1018
1010
|
}
|
|
1011
|
+
return node.version >= base.version ? node : null;
|
|
1019
1012
|
}
|
|
1020
1013
|
function getNewerChange(node, base) {
|
|
1021
1014
|
if (isBranch(node)) {
|
|
@@ -1023,9 +1016,8 @@ function getNewerChange(node, base) {
|
|
|
1023
1016
|
(child) => getNewerChange(child, base)
|
|
1024
1017
|
);
|
|
1025
1018
|
return children.length && { ...node, children };
|
|
1026
|
-
} else {
|
|
1027
|
-
return node.version >= base.version ? node : null;
|
|
1028
1019
|
}
|
|
1020
|
+
return node.version >= base.version ? node : null;
|
|
1029
1021
|
}
|
|
1030
1022
|
function setVersion(graph, version, onlyIfZero = false) {
|
|
1031
1023
|
for (const node of graph) {
|
|
@@ -1387,7 +1379,7 @@ function addPageMeta(graph, args) {
|
|
|
1387
1379
|
}
|
|
1388
1380
|
}
|
|
1389
1381
|
const $prev = isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } : isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } : null;
|
|
1390
|
-
|
|
1382
|
+
const $next = isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } : isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } : null;
|
|
1391
1383
|
Object.assign(graph, { $page, $next, $prev });
|
|
1392
1384
|
}
|
|
1393
1385
|
function getByte(view, offset) {
|
|
@@ -1560,7 +1552,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1560
1552
|
}
|
|
1561
1553
|
}
|
|
1562
1554
|
let putRange = [];
|
|
1563
|
-
|
|
1555
|
+
const prefixPuts = [];
|
|
1564
1556
|
if (Array.isArray(object) && !isDef($put) && !isDef($val) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1565
1557
|
putRange = [encode$3({ $since: 0, $until: Infinity })];
|
|
1566
1558
|
}
|
|
@@ -1645,7 +1637,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1645
1637
|
}
|
|
1646
1638
|
if (value == null ? void 0 : value.$key)
|
|
1647
1639
|
value = [value];
|
|
1648
|
-
|
|
1640
|
+
const result = ((_a = makeNode2(value, ROOT_KEY, version)) == null ? void 0 : _a.children) || [];
|
|
1649
1641
|
while (links.length) {
|
|
1650
1642
|
combine(result, [links.pop()]);
|
|
1651
1643
|
}
|
|
@@ -1668,7 +1660,7 @@ async function* mergeStreams(...streams) {
|
|
|
1668
1660
|
yield value;
|
|
1669
1661
|
}
|
|
1670
1662
|
} else {
|
|
1671
|
-
|
|
1663
|
+
const merged = [];
|
|
1672
1664
|
for (const value of firstValues)
|
|
1673
1665
|
merge(merged, value);
|
|
1674
1666
|
yield merged;
|
|
@@ -1756,10 +1748,9 @@ function unwrapObject(object, path) {
|
|
|
1756
1748
|
const [page, filter] = splitArgs($key);
|
|
1757
1749
|
if (page && !page.$cursor) {
|
|
1758
1750
|
return object;
|
|
1759
|
-
} else {
|
|
1760
|
-
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1761
|
-
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1762
1751
|
}
|
|
1752
|
+
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1753
|
+
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1763
1754
|
}
|
|
1764
1755
|
}
|
|
1765
1756
|
return object;
|
package/index.mjs
CHANGED
|
@@ -1,45 +1,8 @@
|
|
|
1
|
+
import debug from "debug";
|
|
1
2
|
import isEqual from "lodash/isEqual.js";
|
|
2
3
|
import mergeIterators from "merge-async-iterators";
|
|
3
4
|
import { makeStream } from "@graffy/stream";
|
|
4
|
-
const
|
|
5
|
-
const textDecoder = new TextDecoder("utf-8");
|
|
6
|
-
function encode$6(string) {
|
|
7
|
-
return textEncoder.encode(string);
|
|
8
|
-
}
|
|
9
|
-
function decode$6(u8Arr) {
|
|
10
|
-
return textDecoder.decode(u8Arr);
|
|
11
|
-
}
|
|
12
|
-
function TwosComplement(view) {
|
|
13
|
-
let lo = -view.getUint32(4) >>> 0;
|
|
14
|
-
const carry = lo ? 0 : -1;
|
|
15
|
-
let hi = ~view.getUint32(0) + carry >>> 0;
|
|
16
|
-
view.setUint32(0, hi);
|
|
17
|
-
view.setUint32(4, lo);
|
|
18
|
-
}
|
|
19
|
-
function encode$5(number) {
|
|
20
|
-
const buffer = new ArrayBuffer(8);
|
|
21
|
-
const view = new DataView(buffer);
|
|
22
|
-
view.setFloat64(0, number);
|
|
23
|
-
if (number < 0) {
|
|
24
|
-
TwosComplement(view);
|
|
25
|
-
} else {
|
|
26
|
-
view.setUint8(0, view.getUint8(0) | 128);
|
|
27
|
-
}
|
|
28
|
-
return new Uint8Array(buffer);
|
|
29
|
-
}
|
|
30
|
-
function decode$5(u8Arr) {
|
|
31
|
-
const copy = new Uint8Array(8);
|
|
32
|
-
copy.set(u8Arr, 0);
|
|
33
|
-
const { buffer, byteOffset, byteLength } = copy;
|
|
34
|
-
const view = new DataView(buffer, byteOffset, byteLength);
|
|
35
|
-
const high = view.getUint8(0);
|
|
36
|
-
if (high & 128) {
|
|
37
|
-
view.setUint8(0, high & 127);
|
|
38
|
-
} else {
|
|
39
|
-
TwosComplement(view);
|
|
40
|
-
}
|
|
41
|
-
return view.getFloat64(0);
|
|
42
|
-
}
|
|
5
|
+
const isDebugMode = debug("graffy*").enabled;
|
|
43
6
|
const MIN_KEY = new Uint8Array();
|
|
44
7
|
const MAX_KEY = new Uint8Array([255]);
|
|
45
8
|
function isMinKey(key) {
|
|
@@ -71,9 +34,8 @@ function isPlainObject(arg) {
|
|
|
71
34
|
function clone$1(obj) {
|
|
72
35
|
if (Array.isArray(obj)) {
|
|
73
36
|
return obj.slice(0);
|
|
74
|
-
} else {
|
|
75
|
-
return { ...obj };
|
|
76
37
|
}
|
|
38
|
+
return { ...obj };
|
|
77
39
|
}
|
|
78
40
|
function cmp(a, b) {
|
|
79
41
|
const l = a.length < b.length ? a.length : b.length;
|
|
@@ -105,40 +67,75 @@ function find(items, compare2, first = 0, last = items.length) {
|
|
|
105
67
|
}
|
|
106
68
|
return currentFirst;
|
|
107
69
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
70
|
+
function stringify() {
|
|
71
|
+
var _a;
|
|
72
|
+
if ((this == null ? void 0 : this.length) === 0)
|
|
73
|
+
return "·";
|
|
74
|
+
let str = "";
|
|
75
|
+
let bull = false;
|
|
76
|
+
(_a = this == null ? void 0 : this.forEach) == null ? void 0 : _a.call(this, (value, i) => {
|
|
77
|
+
if (value >= 32 && value <= 126) {
|
|
78
|
+
str += String.fromCharCode(value);
|
|
79
|
+
bull = true;
|
|
80
|
+
} else {
|
|
81
|
+
str += (bull ? "·" : "") + `0${value.toString(16)}`.slice(-2) + (i < this.length - 1 ? "·" : "");
|
|
82
|
+
bull = false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return str;
|
|
86
|
+
}
|
|
87
|
+
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
127
88
|
function addStringify(buffer) {
|
|
128
|
-
if (
|
|
89
|
+
if (!isDebugMode)
|
|
129
90
|
return buffer;
|
|
130
|
-
if ("toJSON" in buffer ||
|
|
91
|
+
if ("toJSON" in buffer || inspectSymbol in buffer)
|
|
131
92
|
return buffer;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
toString: stringifyDescriptor,
|
|
136
|
-
[Symbol.for("nodejs.util.inspect.custom")]: stringifyDescriptor
|
|
137
|
-
});
|
|
93
|
+
buffer.toJSON = stringify;
|
|
94
|
+
buffer.toString = stringify;
|
|
95
|
+
buffer[inspectSymbol] = stringify;
|
|
138
96
|
return buffer;
|
|
139
97
|
}
|
|
140
98
|
addStringify(MIN_KEY);
|
|
141
99
|
addStringify(MAX_KEY);
|
|
100
|
+
function TwosComplement(view) {
|
|
101
|
+
const lo = -view.getUint32(4) >>> 0;
|
|
102
|
+
const carry = lo ? 0 : -1;
|
|
103
|
+
const hi = ~view.getUint32(0) + carry >>> 0;
|
|
104
|
+
view.setUint32(0, hi);
|
|
105
|
+
view.setUint32(4, lo);
|
|
106
|
+
}
|
|
107
|
+
function encode$6(number) {
|
|
108
|
+
const buffer = new ArrayBuffer(8);
|
|
109
|
+
const view = new DataView(buffer);
|
|
110
|
+
view.setFloat64(0, number);
|
|
111
|
+
if (number < 0) {
|
|
112
|
+
TwosComplement(view);
|
|
113
|
+
} else {
|
|
114
|
+
view.setUint8(0, view.getUint8(0) | 128);
|
|
115
|
+
}
|
|
116
|
+
return new Uint8Array(buffer);
|
|
117
|
+
}
|
|
118
|
+
function decode$6(u8Arr) {
|
|
119
|
+
const copy = new Uint8Array(8);
|
|
120
|
+
copy.set(u8Arr, 0);
|
|
121
|
+
const { buffer, byteOffset, byteLength } = copy;
|
|
122
|
+
const view = new DataView(buffer, byteOffset, byteLength);
|
|
123
|
+
const high = view.getUint8(0);
|
|
124
|
+
if (high & 128) {
|
|
125
|
+
view.setUint8(0, high & 127);
|
|
126
|
+
} else {
|
|
127
|
+
TwosComplement(view);
|
|
128
|
+
}
|
|
129
|
+
return view.getFloat64(0);
|
|
130
|
+
}
|
|
131
|
+
const textEncoder = new TextEncoder();
|
|
132
|
+
const textDecoder = new TextDecoder("utf-8");
|
|
133
|
+
function encode$5(string) {
|
|
134
|
+
return textEncoder.encode(string);
|
|
135
|
+
}
|
|
136
|
+
function decode$5(u8Arr) {
|
|
137
|
+
return textDecoder.decode(u8Arr);
|
|
138
|
+
}
|
|
142
139
|
const END = 0;
|
|
143
140
|
const NULL = 1;
|
|
144
141
|
const FALSE = 2;
|
|
@@ -157,7 +154,7 @@ function encodeObject(object) {
|
|
|
157
154
|
OBJ,
|
|
158
155
|
...keys.flatMap((key) => [
|
|
159
156
|
STR,
|
|
160
|
-
encode$
|
|
157
|
+
encode$5(key),
|
|
161
158
|
END,
|
|
162
159
|
...encodeParts(object[key])
|
|
163
160
|
]),
|
|
@@ -172,9 +169,9 @@ function encodeParts(value) {
|
|
|
172
169
|
if (value === true)
|
|
173
170
|
return [TRUE];
|
|
174
171
|
if (typeof value === "number")
|
|
175
|
-
return [NUM, encode$
|
|
172
|
+
return [NUM, encode$6(value)];
|
|
176
173
|
if (typeof value === "string")
|
|
177
|
-
return [STR, encode$
|
|
174
|
+
return [STR, encode$5(value), END];
|
|
178
175
|
if (Array.isArray(value))
|
|
179
176
|
return encodeArray(value);
|
|
180
177
|
if (typeof value === "object")
|
|
@@ -219,10 +216,10 @@ function decode$4(buffer) {
|
|
|
219
216
|
let i = 0;
|
|
220
217
|
const stack = [[]];
|
|
221
218
|
function readString() {
|
|
222
|
-
|
|
219
|
+
const start = i;
|
|
223
220
|
while (i < buffer.length && buffer[i] !== END)
|
|
224
221
|
i++;
|
|
225
|
-
const str = decode$
|
|
222
|
+
const str = decode$5(buffer.subarray(start, i));
|
|
226
223
|
i++;
|
|
227
224
|
return str;
|
|
228
225
|
}
|
|
@@ -266,7 +263,7 @@ function decode$4(buffer) {
|
|
|
266
263
|
break;
|
|
267
264
|
case NUM:
|
|
268
265
|
i += 8;
|
|
269
|
-
pushToken(type, decode$
|
|
266
|
+
pushToken(type, decode$6(buffer.subarray(start, i)));
|
|
270
267
|
break;
|
|
271
268
|
case STR:
|
|
272
269
|
pushToken(type, readString());
|
|
@@ -606,10 +603,9 @@ function insertNode$1(current, change, start = 0) {
|
|
|
606
603
|
const node = current[index];
|
|
607
604
|
if (node && cmp(node.key, key) <= 0) {
|
|
608
605
|
return isRange(node) ? insertNodeIntoRange$1(current, index, change) : updateNode$1(current, index, change);
|
|
609
|
-
} else {
|
|
610
|
-
current.splice(index, 0, change);
|
|
611
|
-
return index + 1;
|
|
612
606
|
}
|
|
607
|
+
current.splice(index, 0, change);
|
|
608
|
+
return index + 1;
|
|
613
609
|
}
|
|
614
610
|
function insertNodeIntoRange$1(current, index, change) {
|
|
615
611
|
const key = change.key;
|
|
@@ -647,9 +643,8 @@ function getNewer(node, base) {
|
|
|
647
643
|
const children = [{ key: MIN_KEY, end: MAX_KEY, version }];
|
|
648
644
|
merge(children, node.children);
|
|
649
645
|
return children.length === 1 ? null : { ...node, children };
|
|
650
|
-
} else {
|
|
651
|
-
return node.version >= version ? node : null;
|
|
652
646
|
}
|
|
647
|
+
return node.version >= version ? node : null;
|
|
653
648
|
}
|
|
654
649
|
const IS_VAL = Symbol("IS_VAL");
|
|
655
650
|
function makeNode(seg, props2) {
|
|
@@ -753,7 +748,7 @@ class Result {
|
|
|
753
748
|
}
|
|
754
749
|
}
|
|
755
750
|
function slice(graph, query, root) {
|
|
756
|
-
|
|
751
|
+
const result = new Result(root);
|
|
757
752
|
let currentQuery = query;
|
|
758
753
|
while (currentQuery) {
|
|
759
754
|
let index = 0;
|
|
@@ -948,9 +943,8 @@ function insertNode(current, change, result, start = 0) {
|
|
|
948
943
|
const node = current[index];
|
|
949
944
|
if (node && cmp(node.key, key) <= 0) {
|
|
950
945
|
return isRange(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result);
|
|
951
|
-
} else {
|
|
952
|
-
return index;
|
|
953
946
|
}
|
|
947
|
+
return index;
|
|
954
948
|
}
|
|
955
949
|
function insertNodeIntoRange(current, index, change, result) {
|
|
956
950
|
const key = change.key;
|
|
@@ -1011,9 +1005,8 @@ function getNewerNode(node, base) {
|
|
|
1011
1005
|
const children = [emptyNode];
|
|
1012
1006
|
sieve(children, node.children);
|
|
1013
1007
|
return children.length === 1 && children[0] === emptyNode ? null : { ...node, children };
|
|
1014
|
-
} else {
|
|
1015
|
-
return node.version >= base.version ? node : null;
|
|
1016
1008
|
}
|
|
1009
|
+
return node.version >= base.version ? node : null;
|
|
1017
1010
|
}
|
|
1018
1011
|
function getNewerChange(node, base) {
|
|
1019
1012
|
if (isBranch(node)) {
|
|
@@ -1021,9 +1014,8 @@ function getNewerChange(node, base) {
|
|
|
1021
1014
|
(child) => getNewerChange(child, base)
|
|
1022
1015
|
);
|
|
1023
1016
|
return children.length && { ...node, children };
|
|
1024
|
-
} else {
|
|
1025
|
-
return node.version >= base.version ? node : null;
|
|
1026
1017
|
}
|
|
1018
|
+
return node.version >= base.version ? node : null;
|
|
1027
1019
|
}
|
|
1028
1020
|
function setVersion(graph, version, onlyIfZero = false) {
|
|
1029
1021
|
for (const node of graph) {
|
|
@@ -1385,7 +1377,7 @@ function addPageMeta(graph, args) {
|
|
|
1385
1377
|
}
|
|
1386
1378
|
}
|
|
1387
1379
|
const $prev = isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } : isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } : null;
|
|
1388
|
-
|
|
1380
|
+
const $next = isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } : isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } : null;
|
|
1389
1381
|
Object.assign(graph, { $page, $next, $prev });
|
|
1390
1382
|
}
|
|
1391
1383
|
function getByte(view, offset) {
|
|
@@ -1558,7 +1550,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1558
1550
|
}
|
|
1559
1551
|
}
|
|
1560
1552
|
let putRange = [];
|
|
1561
|
-
|
|
1553
|
+
const prefixPuts = [];
|
|
1562
1554
|
if (Array.isArray(object) && !isDef($put) && !isDef($val) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1563
1555
|
putRange = [encode$3({ $since: 0, $until: Infinity })];
|
|
1564
1556
|
}
|
|
@@ -1643,7 +1635,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1643
1635
|
}
|
|
1644
1636
|
if (value == null ? void 0 : value.$key)
|
|
1645
1637
|
value = [value];
|
|
1646
|
-
|
|
1638
|
+
const result = ((_a = makeNode2(value, ROOT_KEY, version)) == null ? void 0 : _a.children) || [];
|
|
1647
1639
|
while (links.length) {
|
|
1648
1640
|
combine(result, [links.pop()]);
|
|
1649
1641
|
}
|
|
@@ -1666,7 +1658,7 @@ async function* mergeStreams(...streams) {
|
|
|
1666
1658
|
yield value;
|
|
1667
1659
|
}
|
|
1668
1660
|
} else {
|
|
1669
|
-
|
|
1661
|
+
const merged = [];
|
|
1670
1662
|
for (const value of firstValues)
|
|
1671
1663
|
merge(merged, value);
|
|
1672
1664
|
yield merged;
|
|
@@ -1754,10 +1746,9 @@ function unwrapObject(object, path) {
|
|
|
1754
1746
|
const [page, filter] = splitArgs($key);
|
|
1755
1747
|
if (page && !page.$cursor) {
|
|
1756
1748
|
return object;
|
|
1757
|
-
} else {
|
|
1758
|
-
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1759
|
-
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1760
1749
|
}
|
|
1750
|
+
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1751
|
+
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1761
1752
|
}
|
|
1762
1753
|
}
|
|
1763
1754
|
return object;
|
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.11",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"lodash": "^4.17.19",
|
|
20
|
+
"debug": "^4.3.3",
|
|
20
21
|
"merge-async-iterators": "^0.2.1",
|
|
21
|
-
"@graffy/stream": "0.16.
|
|
22
|
+
"@graffy/stream": "0.16.11"
|
|
22
23
|
}
|
|
23
24
|
}
|