@graffy/common 0.19.1-alpha.1 → 0.19.1-alpha.3
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/coding/args.d.ts +4 -2
- package/coding/args.js +0 -1
- package/coding/decodeTree.js +7 -6
- package/coding/decorate.js +2 -2
- package/coding/encodeTree.js +4 -1
- package/coding/pack.d.ts +2 -2
- package/coding/path.d.ts +1 -1
- package/coding/struct.d.ts +0 -8
- package/coding/struct.js +8 -9
- package/node/find.d.ts +2 -2
- package/node/find.js +2 -2
- package/ops/finalize.d.ts +1 -1
- package/ops/merge.d.ts +0 -2
- package/ops/merge.js +2 -2
- package/ops/sieve.d.ts +0 -2
- package/ops/sieve.js +2 -2
- package/ops/slice.d.ts +6 -3
- package/ops/slice.js +1 -1
- package/package.json +6 -15
- package/stream/makeWatcher.d.ts +1 -1
- package/util.d.ts +1 -1
package/coding/args.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export declare function splitArgs(arg: any):
|
|
1
|
+
export declare function splitArgs(arg: any): [Record<string, any> | undefined, Record<string, any> | undefined];
|
|
2
2
|
export declare function encode(arg: any): {
|
|
3
|
-
key
|
|
3
|
+
key?: Uint8Array<ArrayBuffer>;
|
|
4
|
+
end?: Uint8Array<ArrayBuffer>;
|
|
5
|
+
limit?: number;
|
|
4
6
|
};
|
|
5
7
|
export declare function decode(node: any): any;
|
package/coding/args.js
CHANGED
|
@@ -36,7 +36,6 @@ export function encode(arg) {
|
|
|
36
36
|
if (!page)
|
|
37
37
|
return { key: encodeValue(filter || {}) };
|
|
38
38
|
const { $cursor, ...range } = page;
|
|
39
|
-
// @ts-expect-error
|
|
40
39
|
const { $first, $all, $last, $after, $before, $since, $until } = range;
|
|
41
40
|
const hasRange = !isEmpty(range);
|
|
42
41
|
errIf('first_and_last', isDef($first) && isDef($last), arg);
|
package/coding/decodeTree.js
CHANGED
|
@@ -150,17 +150,18 @@ function decode(nodes = [], { isGraph } = {}) {
|
|
|
150
150
|
}
|
|
151
151
|
child.$key = { ...args, ...child.$key };
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const ch = children;
|
|
154
|
+
if (ch.$put === true) {
|
|
155
|
+
ch[PRE_CHI_PUT] = [{ ...args, $all: true }];
|
|
155
156
|
}
|
|
156
|
-
else if (Array.isArray(
|
|
157
|
-
|
|
157
|
+
else if (Array.isArray(ch.$put)) {
|
|
158
|
+
ch[PRE_CHI_PUT] = ch.$put.map((rarg) => ({
|
|
158
159
|
...args,
|
|
159
160
|
...rarg,
|
|
160
161
|
}));
|
|
161
162
|
}
|
|
162
|
-
else if (isDef(
|
|
163
|
-
|
|
163
|
+
else if (isDef(ch.$put)) {
|
|
164
|
+
ch[PRE_CHI_PUT] = [{ ...args, ...ch.$put }];
|
|
164
165
|
}
|
|
165
166
|
return children;
|
|
166
167
|
}
|
package/coding/decorate.js
CHANGED
|
@@ -182,9 +182,9 @@ function addPageMeta(graph, args) {
|
|
|
182
182
|
Object.assign(graph, { $page: args, $prev: null, $next: null });
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
|
-
const [
|
|
185
|
+
const [page, filter] = splitArgs(args);
|
|
186
|
+
const { $first, $last, ...bounds } = page;
|
|
186
187
|
const count = $first || $last;
|
|
187
|
-
/** @type {any} */
|
|
188
188
|
const $page = { ...filter, ...bounds, $all: true };
|
|
189
189
|
if (graph.length === count) {
|
|
190
190
|
// This result was limited by the count; update the "outer" bound.
|
package/coding/encodeTree.js
CHANGED
|
@@ -93,7 +93,10 @@ function encode(value, { version, isGraph } = {}) {
|
|
|
93
93
|
if ((!isDef(key) || Number.isInteger(key)) &&
|
|
94
94
|
(filter || isDef(page.$cursor))) {
|
|
95
95
|
object.$key = isDef(page.$cursor) ? page.$cursor : page;
|
|
96
|
-
const wrapper = {
|
|
96
|
+
const wrapper = {
|
|
97
|
+
$key: filter || {},
|
|
98
|
+
$chi: [object],
|
|
99
|
+
};
|
|
97
100
|
if (isGraph)
|
|
98
101
|
wrapper.$put = foundPuts;
|
|
99
102
|
const node = makeNode(wrapper, key, ver);
|
package/coding/pack.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function pack(children: any, parentVersion
|
|
2
|
-
export declare function unpack(children: any, parentVersion
|
|
1
|
+
export declare function pack(children: any, parentVersion?: any): any;
|
|
2
|
+
export declare function unpack(children: any, parentVersion?: any): any;
|
package/coding/path.d.ts
CHANGED
package/coding/struct.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export declare const END = 0;
|
|
2
|
-
export declare const NULL = 1;
|
|
3
|
-
export declare const FALSE = 2;
|
|
4
|
-
export declare const TRUE = 3;
|
|
5
|
-
export declare const NUM = 4;
|
|
6
1
|
export declare const STR = 5;
|
|
7
|
-
export declare const ARR = 6;
|
|
8
|
-
export declare const OBJ = 7;
|
|
9
|
-
export declare const EOK = 127;
|
|
10
2
|
export declare function encode(value: any): Uint8Array<any>;
|
|
11
3
|
export declare function decode(buffer: any): any;
|
package/coding/struct.js
CHANGED
|
@@ -7,15 +7,15 @@ import { decode as decodeString, encode as encodeString } from "./string.js";
|
|
|
7
7
|
The constraints are:
|
|
8
8
|
- Sorting a byte stream should
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const END = 0;
|
|
11
|
+
const NULL = 1;
|
|
12
|
+
const FALSE = 2;
|
|
13
|
+
const TRUE = 3;
|
|
14
|
+
const NUM = 4;
|
|
15
15
|
export const STR = 5;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const ARR = 6;
|
|
17
|
+
const OBJ = 7;
|
|
18
|
+
const EOK = 127; // end-of-key
|
|
19
19
|
function encodeArray(array) {
|
|
20
20
|
return [ARR, ...array.flatMap((value) => encodeParts(value)), END];
|
|
21
21
|
}
|
|
@@ -92,7 +92,6 @@ export function encode(value) {
|
|
|
92
92
|
const nextKey = new WeakMap();
|
|
93
93
|
export function decode(buffer) {
|
|
94
94
|
let i = 0;
|
|
95
|
-
/** @type {Array<{ [prop: string]: any }|Array>} */
|
|
96
95
|
const stack = [[]];
|
|
97
96
|
function readString() {
|
|
98
97
|
const start = i;
|
package/node/find.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function findFirst(children: any, target: any, first
|
|
2
|
-
export declare function findLast(children: any, end: any, first
|
|
1
|
+
export declare function findFirst(children: any, target: any, first?: number, last?: any): number;
|
|
2
|
+
export declare function findLast(children: any, end: any, first?: number, last?: any): number;
|
package/node/find.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cmp, find } from "../util.js";
|
|
2
|
-
export function findFirst(children, target, first, last) {
|
|
2
|
+
export function findFirst(children, target, first = 0, last = children.length) {
|
|
3
3
|
return find(children, ({ key, end }) => {
|
|
4
4
|
const keyCmp = cmp(key, target);
|
|
5
5
|
const endCmp = end && cmp(end, target);
|
|
@@ -8,7 +8,7 @@ export function findFirst(children, target, first, last) {
|
|
|
8
8
|
return keyCmp;
|
|
9
9
|
}, first, last);
|
|
10
10
|
}
|
|
11
|
-
export function findLast(children, end, first, last) {
|
|
11
|
+
export function findLast(children, end, first = 0, last = children.length) {
|
|
12
12
|
const ix = findFirst(children, end, first, last);
|
|
13
13
|
return children[ix] && cmp(children[ix].key, end) <= 0 ? ix + 1 : ix;
|
|
14
14
|
}
|
package/ops/finalize.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {number | false} version
|
|
6
6
|
* @returns any
|
|
7
7
|
*/
|
|
8
|
-
export default function finalize(graph: any, query: any, version?: number): {
|
|
8
|
+
export default function finalize(graph: any, query: any, version?: number | false): {
|
|
9
9
|
key: Uint8Array<ArrayBuffer>;
|
|
10
10
|
end: Uint8Array<ArrayBuffer>;
|
|
11
11
|
version: number;
|
package/ops/merge.d.ts
CHANGED
package/ops/merge.js
CHANGED
|
@@ -12,7 +12,7 @@ export default function merge(current, changes) {
|
|
|
12
12
|
}
|
|
13
13
|
return current;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
function insertRange(current, change, start = 0) {
|
|
16
16
|
const { key, end } = change;
|
|
17
17
|
const keyIx = findFirst(current, key, start);
|
|
18
18
|
const endIx = findLast(current, end, keyIx);
|
|
@@ -41,7 +41,7 @@ function mergeRanges(base, node) {
|
|
|
41
41
|
cmp(base.end, node.end) > 0 && { ...base, key: keyAfter(node.end) },
|
|
42
42
|
].filter(Boolean);
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
function insertNode(current, change, start = 0) {
|
|
45
45
|
if (!current)
|
|
46
46
|
throw new Error(`merge.insertNode: ${current}`);
|
|
47
47
|
const key = change.key;
|
package/ops/sieve.d.ts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
1
|
export default function sieve(current: any, changes: any, result?: any[]): any[];
|
|
2
|
-
export declare function insertRange(current: any, change: any, result: any, start?: number): number;
|
|
3
|
-
export declare function insertNode(current: any, change: any, result: any, start?: number): any;
|
package/ops/sieve.js
CHANGED
|
@@ -10,7 +10,7 @@ export default function sieve(current, changes, result = []) {
|
|
|
10
10
|
}
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
function insertRange(current, change, result, start = 0) {
|
|
14
14
|
const { key, end } = change;
|
|
15
15
|
const keyIx = findFirst(current, key, start);
|
|
16
16
|
const endIx = findLast(current, end, keyIx);
|
|
@@ -89,7 +89,7 @@ function mergeRanges(base, node) {
|
|
|
89
89
|
cmp(base.end, node.end) > 0 && { ...base, key: keyAfter(node.end) },
|
|
90
90
|
].filter(Boolean);
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
function insertNode(current, change, result, start = 0) {
|
|
93
93
|
const key = change.key;
|
|
94
94
|
const index = findFirst(current, key, start);
|
|
95
95
|
const node = current[index];
|
package/ops/slice.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
declare class Result {
|
|
2
|
-
|
|
2
|
+
root: Result;
|
|
3
|
+
known?: any[];
|
|
4
|
+
unknown?: any[];
|
|
5
|
+
linked?: any[];
|
|
6
|
+
constructor(root?: any);
|
|
3
7
|
addKnown(node: any): void;
|
|
4
8
|
addUnknown(node: any): void;
|
|
5
9
|
addLinked(children: any): any;
|
|
6
10
|
}
|
|
7
|
-
export default function slice(graph: any, query: any, root
|
|
8
|
-
export declare function sliceRange(graph: any, query: any, result: any): void;
|
|
11
|
+
export default function slice(graph: any, query: any, root?: any): Result;
|
|
9
12
|
export {};
|
package/ops/slice.js
CHANGED
|
@@ -93,7 +93,7 @@ function sliceNode(graph, query, result) {
|
|
|
93
93
|
result.addKnown(graph);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
function sliceRange(graph, query, result) {
|
|
97
97
|
let { key, end, limit = Number.POSITIVE_INFINITY, version } = query;
|
|
98
98
|
const step = cmp(key, end) < 0 ? 1 : -1;
|
|
99
99
|
// Prefixes are used to combine filtering and pagination. In schemas where
|
package/package.json
CHANGED
|
@@ -2,18 +2,9 @@
|
|
|
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.19.1-alpha.
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
".": {
|
|
9
|
-
"import": "./index.js",
|
|
10
|
-
"types": "./index.d.ts"
|
|
11
|
-
},
|
|
12
|
-
"./*": {
|
|
13
|
-
"import": "./*.js",
|
|
14
|
-
"types": "./*.d.ts"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
5
|
+
"version": "0.19.1-alpha.3",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./index.js",
|
|
17
8
|
"types": "./index.d.ts",
|
|
18
9
|
"repository": {
|
|
19
10
|
"type": "git",
|
|
@@ -22,9 +13,9 @@
|
|
|
22
13
|
"license": "Apache-2.0",
|
|
23
14
|
"dependencies": {
|
|
24
15
|
"debug": "^4.4.3",
|
|
25
|
-
"lodash": "^4.
|
|
26
|
-
"nanoid": "^5.1.
|
|
27
|
-
"@graffy/stream": "0.19.1-alpha.
|
|
16
|
+
"lodash": "^4.18.1",
|
|
17
|
+
"nanoid": "^5.1.11",
|
|
18
|
+
"@graffy/stream": "0.19.1-alpha.3",
|
|
28
19
|
"merge-async-iterators": "^0.2.1"
|
|
29
20
|
}
|
|
30
21
|
}
|
package/stream/makeWatcher.d.ts
CHANGED
package/util.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare function isMaxKey(key: any): boolean;
|
|
|
5
5
|
export declare function err(message: any, { cause, ...args }?: {
|
|
6
6
|
cause?: any;
|
|
7
7
|
}): void;
|
|
8
|
-
export declare function errIf(message: any, condition: any, args
|
|
8
|
+
export declare function errIf(message: any, condition: any, args?: any): void;
|
|
9
9
|
export declare function isEmpty(object: any): boolean;
|
|
10
10
|
export declare function isDef(value: any): boolean;
|
|
11
11
|
export declare function isPlainObject(arg: any): boolean;
|