@graffy/common 0.16.10-alpha.2 → 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 +93 -66
- package/index.mjs +93 -66
- 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,9 +69,75 @@ function find(items, compare2, first = 0, last = items.length) {
|
|
|
107
69
|
}
|
|
108
70
|
return currentFirst;
|
|
109
71
|
}
|
|
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");
|
|
110
90
|
function addStringify(buffer) {
|
|
91
|
+
if (!isDebugMode)
|
|
92
|
+
return buffer;
|
|
93
|
+
if ("toJSON" in buffer || inspectSymbol in buffer)
|
|
94
|
+
return buffer;
|
|
95
|
+
buffer.toJSON = stringify;
|
|
96
|
+
buffer.toString = stringify;
|
|
97
|
+
buffer[inspectSymbol] = stringify;
|
|
111
98
|
return buffer;
|
|
112
99
|
}
|
|
100
|
+
addStringify(MIN_KEY);
|
|
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
|
+
}
|
|
113
141
|
const END = 0;
|
|
114
142
|
const NULL = 1;
|
|
115
143
|
const FALSE = 2;
|
|
@@ -128,7 +156,7 @@ function encodeObject(object) {
|
|
|
128
156
|
OBJ,
|
|
129
157
|
...keys.flatMap((key) => [
|
|
130
158
|
STR,
|
|
131
|
-
encode$
|
|
159
|
+
encode$5(key),
|
|
132
160
|
END,
|
|
133
161
|
...encodeParts(object[key])
|
|
134
162
|
]),
|
|
@@ -143,9 +171,9 @@ function encodeParts(value) {
|
|
|
143
171
|
if (value === true)
|
|
144
172
|
return [TRUE];
|
|
145
173
|
if (typeof value === "number")
|
|
146
|
-
return [NUM, encode$
|
|
174
|
+
return [NUM, encode$6(value)];
|
|
147
175
|
if (typeof value === "string")
|
|
148
|
-
return [STR, encode$
|
|
176
|
+
return [STR, encode$5(value), END];
|
|
149
177
|
if (Array.isArray(value))
|
|
150
178
|
return encodeArray(value);
|
|
151
179
|
if (typeof value === "object")
|
|
@@ -182,6 +210,7 @@ function encode$4(value) {
|
|
|
182
210
|
i += part.length;
|
|
183
211
|
}
|
|
184
212
|
}
|
|
213
|
+
addStringify(buffer);
|
|
185
214
|
return buffer;
|
|
186
215
|
}
|
|
187
216
|
const nextKey = /* @__PURE__ */ new WeakMap();
|
|
@@ -189,10 +218,10 @@ function decode$4(buffer) {
|
|
|
189
218
|
let i = 0;
|
|
190
219
|
const stack = [[]];
|
|
191
220
|
function readString() {
|
|
192
|
-
|
|
221
|
+
const start = i;
|
|
193
222
|
while (i < buffer.length && buffer[i] !== END)
|
|
194
223
|
i++;
|
|
195
|
-
const str = decode$
|
|
224
|
+
const str = decode$5(buffer.subarray(start, i));
|
|
196
225
|
i++;
|
|
197
226
|
return str;
|
|
198
227
|
}
|
|
@@ -236,7 +265,7 @@ function decode$4(buffer) {
|
|
|
236
265
|
break;
|
|
237
266
|
case NUM:
|
|
238
267
|
i += 8;
|
|
239
|
-
pushToken(type, decode$
|
|
268
|
+
pushToken(type, decode$6(buffer.subarray(start, i)));
|
|
240
269
|
break;
|
|
241
270
|
case STR:
|
|
242
271
|
pushToken(type, readString());
|
|
@@ -264,10 +293,12 @@ function keyStep(key) {
|
|
|
264
293
|
switch (key[l]) {
|
|
265
294
|
case 0:
|
|
266
295
|
newKey = key.slice(0, l);
|
|
296
|
+
addStringify(newKey);
|
|
267
297
|
step = 1;
|
|
268
298
|
break;
|
|
269
299
|
case 255:
|
|
270
300
|
newKey = key.slice(0, l);
|
|
301
|
+
addStringify(newKey);
|
|
271
302
|
newKey[l - 1]++;
|
|
272
303
|
step = -1;
|
|
273
304
|
break;
|
|
@@ -290,6 +321,7 @@ function keyBefore(key) {
|
|
|
290
321
|
newKey[l]--;
|
|
291
322
|
newKey[l + 1] = 255;
|
|
292
323
|
}
|
|
324
|
+
addStringify(newKey);
|
|
293
325
|
return newKey;
|
|
294
326
|
}
|
|
295
327
|
function keyAfter(key) {
|
|
@@ -305,6 +337,7 @@ function keyAfter(key) {
|
|
|
305
337
|
newKey.set(key, 0);
|
|
306
338
|
newKey[l + 1] = 0;
|
|
307
339
|
}
|
|
340
|
+
addStringify(newKey);
|
|
308
341
|
return newKey;
|
|
309
342
|
}
|
|
310
343
|
function decodeBound(bound) {
|
|
@@ -572,10 +605,9 @@ function insertNode$1(current, change, start = 0) {
|
|
|
572
605
|
const node = current[index];
|
|
573
606
|
if (node && cmp(node.key, key) <= 0) {
|
|
574
607
|
return isRange(node) ? insertNodeIntoRange$1(current, index, change) : updateNode$1(current, index, change);
|
|
575
|
-
} else {
|
|
576
|
-
current.splice(index, 0, change);
|
|
577
|
-
return index + 1;
|
|
578
608
|
}
|
|
609
|
+
current.splice(index, 0, change);
|
|
610
|
+
return index + 1;
|
|
579
611
|
}
|
|
580
612
|
function insertNodeIntoRange$1(current, index, change) {
|
|
581
613
|
const key = change.key;
|
|
@@ -613,9 +645,8 @@ function getNewer(node, base) {
|
|
|
613
645
|
const children = [{ key: MIN_KEY, end: MAX_KEY, version }];
|
|
614
646
|
merge(children, node.children);
|
|
615
647
|
return children.length === 1 ? null : { ...node, children };
|
|
616
|
-
} else {
|
|
617
|
-
return node.version >= version ? node : null;
|
|
618
648
|
}
|
|
649
|
+
return node.version >= version ? node : null;
|
|
619
650
|
}
|
|
620
651
|
const IS_VAL = Symbol("IS_VAL");
|
|
621
652
|
function makeNode(seg, props2) {
|
|
@@ -719,7 +750,7 @@ class Result {
|
|
|
719
750
|
}
|
|
720
751
|
}
|
|
721
752
|
function slice(graph, query, root) {
|
|
722
|
-
|
|
753
|
+
const result = new Result(root);
|
|
723
754
|
let currentQuery = query;
|
|
724
755
|
while (currentQuery) {
|
|
725
756
|
let index = 0;
|
|
@@ -914,9 +945,8 @@ function insertNode(current, change, result, start = 0) {
|
|
|
914
945
|
const node = current[index];
|
|
915
946
|
if (node && cmp(node.key, key) <= 0) {
|
|
916
947
|
return isRange(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result);
|
|
917
|
-
} else {
|
|
918
|
-
return index;
|
|
919
948
|
}
|
|
949
|
+
return index;
|
|
920
950
|
}
|
|
921
951
|
function insertNodeIntoRange(current, index, change, result) {
|
|
922
952
|
const key = change.key;
|
|
@@ -977,9 +1007,8 @@ function getNewerNode(node, base) {
|
|
|
977
1007
|
const children = [emptyNode];
|
|
978
1008
|
sieve(children, node.children);
|
|
979
1009
|
return children.length === 1 && children[0] === emptyNode ? null : { ...node, children };
|
|
980
|
-
} else {
|
|
981
|
-
return node.version >= base.version ? node : null;
|
|
982
1010
|
}
|
|
1011
|
+
return node.version >= base.version ? node : null;
|
|
983
1012
|
}
|
|
984
1013
|
function getNewerChange(node, base) {
|
|
985
1014
|
if (isBranch(node)) {
|
|
@@ -987,9 +1016,8 @@ function getNewerChange(node, base) {
|
|
|
987
1016
|
(child) => getNewerChange(child, base)
|
|
988
1017
|
);
|
|
989
1018
|
return children.length && { ...node, children };
|
|
990
|
-
} else {
|
|
991
|
-
return node.version >= base.version ? node : null;
|
|
992
1019
|
}
|
|
1020
|
+
return node.version >= base.version ? node : null;
|
|
993
1021
|
}
|
|
994
1022
|
function setVersion(graph, version, onlyIfZero = false) {
|
|
995
1023
|
for (const node of graph) {
|
|
@@ -1351,7 +1379,7 @@ function addPageMeta(graph, args) {
|
|
|
1351
1379
|
}
|
|
1352
1380
|
}
|
|
1353
1381
|
const $prev = isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } : isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } : null;
|
|
1354
|
-
|
|
1382
|
+
const $next = isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } : isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } : null;
|
|
1355
1383
|
Object.assign(graph, { $page, $next, $prev });
|
|
1356
1384
|
}
|
|
1357
1385
|
function getByte(view, offset) {
|
|
@@ -1524,7 +1552,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1524
1552
|
}
|
|
1525
1553
|
}
|
|
1526
1554
|
let putRange = [];
|
|
1527
|
-
|
|
1555
|
+
const prefixPuts = [];
|
|
1528
1556
|
if (Array.isArray(object) && !isDef($put) && !isDef($val) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1529
1557
|
putRange = [encode$3({ $since: 0, $until: Infinity })];
|
|
1530
1558
|
}
|
|
@@ -1609,7 +1637,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1609
1637
|
}
|
|
1610
1638
|
if (value == null ? void 0 : value.$key)
|
|
1611
1639
|
value = [value];
|
|
1612
|
-
|
|
1640
|
+
const result = ((_a = makeNode2(value, ROOT_KEY, version)) == null ? void 0 : _a.children) || [];
|
|
1613
1641
|
while (links.length) {
|
|
1614
1642
|
combine(result, [links.pop()]);
|
|
1615
1643
|
}
|
|
@@ -1632,7 +1660,7 @@ async function* mergeStreams(...streams) {
|
|
|
1632
1660
|
yield value;
|
|
1633
1661
|
}
|
|
1634
1662
|
} else {
|
|
1635
|
-
|
|
1663
|
+
const merged = [];
|
|
1636
1664
|
for (const value of firstValues)
|
|
1637
1665
|
merge(merged, value);
|
|
1638
1666
|
yield merged;
|
|
@@ -1720,10 +1748,9 @@ function unwrapObject(object, path) {
|
|
|
1720
1748
|
const [page, filter] = splitArgs($key);
|
|
1721
1749
|
if (page && !page.$cursor) {
|
|
1722
1750
|
return object;
|
|
1723
|
-
} else {
|
|
1724
|
-
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1725
|
-
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1726
1751
|
}
|
|
1752
|
+
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1753
|
+
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1727
1754
|
}
|
|
1728
1755
|
}
|
|
1729
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,9 +67,75 @@ function find(items, compare2, first = 0, last = items.length) {
|
|
|
105
67
|
}
|
|
106
68
|
return currentFirst;
|
|
107
69
|
}
|
|
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");
|
|
108
88
|
function addStringify(buffer) {
|
|
89
|
+
if (!isDebugMode)
|
|
90
|
+
return buffer;
|
|
91
|
+
if ("toJSON" in buffer || inspectSymbol in buffer)
|
|
92
|
+
return buffer;
|
|
93
|
+
buffer.toJSON = stringify;
|
|
94
|
+
buffer.toString = stringify;
|
|
95
|
+
buffer[inspectSymbol] = stringify;
|
|
109
96
|
return buffer;
|
|
110
97
|
}
|
|
98
|
+
addStringify(MIN_KEY);
|
|
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
|
+
}
|
|
111
139
|
const END = 0;
|
|
112
140
|
const NULL = 1;
|
|
113
141
|
const FALSE = 2;
|
|
@@ -126,7 +154,7 @@ function encodeObject(object) {
|
|
|
126
154
|
OBJ,
|
|
127
155
|
...keys.flatMap((key) => [
|
|
128
156
|
STR,
|
|
129
|
-
encode$
|
|
157
|
+
encode$5(key),
|
|
130
158
|
END,
|
|
131
159
|
...encodeParts(object[key])
|
|
132
160
|
]),
|
|
@@ -141,9 +169,9 @@ function encodeParts(value) {
|
|
|
141
169
|
if (value === true)
|
|
142
170
|
return [TRUE];
|
|
143
171
|
if (typeof value === "number")
|
|
144
|
-
return [NUM, encode$
|
|
172
|
+
return [NUM, encode$6(value)];
|
|
145
173
|
if (typeof value === "string")
|
|
146
|
-
return [STR, encode$
|
|
174
|
+
return [STR, encode$5(value), END];
|
|
147
175
|
if (Array.isArray(value))
|
|
148
176
|
return encodeArray(value);
|
|
149
177
|
if (typeof value === "object")
|
|
@@ -180,6 +208,7 @@ function encode$4(value) {
|
|
|
180
208
|
i += part.length;
|
|
181
209
|
}
|
|
182
210
|
}
|
|
211
|
+
addStringify(buffer);
|
|
183
212
|
return buffer;
|
|
184
213
|
}
|
|
185
214
|
const nextKey = /* @__PURE__ */ new WeakMap();
|
|
@@ -187,10 +216,10 @@ function decode$4(buffer) {
|
|
|
187
216
|
let i = 0;
|
|
188
217
|
const stack = [[]];
|
|
189
218
|
function readString() {
|
|
190
|
-
|
|
219
|
+
const start = i;
|
|
191
220
|
while (i < buffer.length && buffer[i] !== END)
|
|
192
221
|
i++;
|
|
193
|
-
const str = decode$
|
|
222
|
+
const str = decode$5(buffer.subarray(start, i));
|
|
194
223
|
i++;
|
|
195
224
|
return str;
|
|
196
225
|
}
|
|
@@ -234,7 +263,7 @@ function decode$4(buffer) {
|
|
|
234
263
|
break;
|
|
235
264
|
case NUM:
|
|
236
265
|
i += 8;
|
|
237
|
-
pushToken(type, decode$
|
|
266
|
+
pushToken(type, decode$6(buffer.subarray(start, i)));
|
|
238
267
|
break;
|
|
239
268
|
case STR:
|
|
240
269
|
pushToken(type, readString());
|
|
@@ -262,10 +291,12 @@ function keyStep(key) {
|
|
|
262
291
|
switch (key[l]) {
|
|
263
292
|
case 0:
|
|
264
293
|
newKey = key.slice(0, l);
|
|
294
|
+
addStringify(newKey);
|
|
265
295
|
step = 1;
|
|
266
296
|
break;
|
|
267
297
|
case 255:
|
|
268
298
|
newKey = key.slice(0, l);
|
|
299
|
+
addStringify(newKey);
|
|
269
300
|
newKey[l - 1]++;
|
|
270
301
|
step = -1;
|
|
271
302
|
break;
|
|
@@ -288,6 +319,7 @@ function keyBefore(key) {
|
|
|
288
319
|
newKey[l]--;
|
|
289
320
|
newKey[l + 1] = 255;
|
|
290
321
|
}
|
|
322
|
+
addStringify(newKey);
|
|
291
323
|
return newKey;
|
|
292
324
|
}
|
|
293
325
|
function keyAfter(key) {
|
|
@@ -303,6 +335,7 @@ function keyAfter(key) {
|
|
|
303
335
|
newKey.set(key, 0);
|
|
304
336
|
newKey[l + 1] = 0;
|
|
305
337
|
}
|
|
338
|
+
addStringify(newKey);
|
|
306
339
|
return newKey;
|
|
307
340
|
}
|
|
308
341
|
function decodeBound(bound) {
|
|
@@ -570,10 +603,9 @@ function insertNode$1(current, change, start = 0) {
|
|
|
570
603
|
const node = current[index];
|
|
571
604
|
if (node && cmp(node.key, key) <= 0) {
|
|
572
605
|
return isRange(node) ? insertNodeIntoRange$1(current, index, change) : updateNode$1(current, index, change);
|
|
573
|
-
} else {
|
|
574
|
-
current.splice(index, 0, change);
|
|
575
|
-
return index + 1;
|
|
576
606
|
}
|
|
607
|
+
current.splice(index, 0, change);
|
|
608
|
+
return index + 1;
|
|
577
609
|
}
|
|
578
610
|
function insertNodeIntoRange$1(current, index, change) {
|
|
579
611
|
const key = change.key;
|
|
@@ -611,9 +643,8 @@ function getNewer(node, base) {
|
|
|
611
643
|
const children = [{ key: MIN_KEY, end: MAX_KEY, version }];
|
|
612
644
|
merge(children, node.children);
|
|
613
645
|
return children.length === 1 ? null : { ...node, children };
|
|
614
|
-
} else {
|
|
615
|
-
return node.version >= version ? node : null;
|
|
616
646
|
}
|
|
647
|
+
return node.version >= version ? node : null;
|
|
617
648
|
}
|
|
618
649
|
const IS_VAL = Symbol("IS_VAL");
|
|
619
650
|
function makeNode(seg, props2) {
|
|
@@ -717,7 +748,7 @@ class Result {
|
|
|
717
748
|
}
|
|
718
749
|
}
|
|
719
750
|
function slice(graph, query, root) {
|
|
720
|
-
|
|
751
|
+
const result = new Result(root);
|
|
721
752
|
let currentQuery = query;
|
|
722
753
|
while (currentQuery) {
|
|
723
754
|
let index = 0;
|
|
@@ -912,9 +943,8 @@ function insertNode(current, change, result, start = 0) {
|
|
|
912
943
|
const node = current[index];
|
|
913
944
|
if (node && cmp(node.key, key) <= 0) {
|
|
914
945
|
return isRange(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result);
|
|
915
|
-
} else {
|
|
916
|
-
return index;
|
|
917
946
|
}
|
|
947
|
+
return index;
|
|
918
948
|
}
|
|
919
949
|
function insertNodeIntoRange(current, index, change, result) {
|
|
920
950
|
const key = change.key;
|
|
@@ -975,9 +1005,8 @@ function getNewerNode(node, base) {
|
|
|
975
1005
|
const children = [emptyNode];
|
|
976
1006
|
sieve(children, node.children);
|
|
977
1007
|
return children.length === 1 && children[0] === emptyNode ? null : { ...node, children };
|
|
978
|
-
} else {
|
|
979
|
-
return node.version >= base.version ? node : null;
|
|
980
1008
|
}
|
|
1009
|
+
return node.version >= base.version ? node : null;
|
|
981
1010
|
}
|
|
982
1011
|
function getNewerChange(node, base) {
|
|
983
1012
|
if (isBranch(node)) {
|
|
@@ -985,9 +1014,8 @@ function getNewerChange(node, base) {
|
|
|
985
1014
|
(child) => getNewerChange(child, base)
|
|
986
1015
|
);
|
|
987
1016
|
return children.length && { ...node, children };
|
|
988
|
-
} else {
|
|
989
|
-
return node.version >= base.version ? node : null;
|
|
990
1017
|
}
|
|
1018
|
+
return node.version >= base.version ? node : null;
|
|
991
1019
|
}
|
|
992
1020
|
function setVersion(graph, version, onlyIfZero = false) {
|
|
993
1021
|
for (const node of graph) {
|
|
@@ -1349,7 +1377,7 @@ function addPageMeta(graph, args) {
|
|
|
1349
1377
|
}
|
|
1350
1378
|
}
|
|
1351
1379
|
const $prev = isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } : isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } : null;
|
|
1352
|
-
|
|
1380
|
+
const $next = isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } : isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } : null;
|
|
1353
1381
|
Object.assign(graph, { $page, $next, $prev });
|
|
1354
1382
|
}
|
|
1355
1383
|
function getByte(view, offset) {
|
|
@@ -1522,7 +1550,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1522
1550
|
}
|
|
1523
1551
|
}
|
|
1524
1552
|
let putRange = [];
|
|
1525
|
-
|
|
1553
|
+
const prefixPuts = [];
|
|
1526
1554
|
if (Array.isArray(object) && !isDef($put) && !isDef($val) && !object.some((it) => isDef(it == null ? void 0 : it.$key))) {
|
|
1527
1555
|
putRange = [encode$3({ $since: 0, $until: Infinity })];
|
|
1528
1556
|
}
|
|
@@ -1607,7 +1635,7 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
1607
1635
|
}
|
|
1608
1636
|
if (value == null ? void 0 : value.$key)
|
|
1609
1637
|
value = [value];
|
|
1610
|
-
|
|
1638
|
+
const result = ((_a = makeNode2(value, ROOT_KEY, version)) == null ? void 0 : _a.children) || [];
|
|
1611
1639
|
while (links.length) {
|
|
1612
1640
|
combine(result, [links.pop()]);
|
|
1613
1641
|
}
|
|
@@ -1630,7 +1658,7 @@ async function* mergeStreams(...streams) {
|
|
|
1630
1658
|
yield value;
|
|
1631
1659
|
}
|
|
1632
1660
|
} else {
|
|
1633
|
-
|
|
1661
|
+
const merged = [];
|
|
1634
1662
|
for (const value of firstValues)
|
|
1635
1663
|
merge(merged, value);
|
|
1636
1664
|
yield merged;
|
|
@@ -1718,10 +1746,9 @@ function unwrapObject(object, path) {
|
|
|
1718
1746
|
const [page, filter] = splitArgs($key);
|
|
1719
1747
|
if (page && !page.$cursor) {
|
|
1720
1748
|
return object;
|
|
1721
|
-
} else {
|
|
1722
|
-
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1723
|
-
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1724
1749
|
}
|
|
1750
|
+
const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
|
|
1751
|
+
object = object.find(({ $key: $key2 }) => isEqual($key2, target));
|
|
1725
1752
|
}
|
|
1726
1753
|
}
|
|
1727
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
|
}
|