@graffy/common 0.19.1-alpha.1 → 0.19.1-alpha.2

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 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: Uint8Array<any>;
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);
@@ -150,17 +150,18 @@ function decode(nodes = [], { isGraph } = {}) {
150
150
  }
151
151
  child.$key = { ...args, ...child.$key };
152
152
  }
153
- if (children.$put === true) {
154
- children[PRE_CHI_PUT] = [{ ...args, $all: true }];
153
+ const ch = children;
154
+ if (ch.$put === true) {
155
+ ch[PRE_CHI_PUT] = [{ ...args, $all: true }];
155
156
  }
156
- else if (Array.isArray(children.$put)) {
157
- children[PRE_CHI_PUT] = children.$put.map((rarg) => ({
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(children.$put)) {
163
- children[PRE_CHI_PUT] = [{ ...args, ...children.$put }];
163
+ else if (isDef(ch.$put)) {
164
+ ch[PRE_CHI_PUT] = [{ ...args, ...ch.$put }];
164
165
  }
165
166
  return children;
166
167
  }
@@ -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 [{ $first, $last, ...bounds }, filter] = splitArgs(args);
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.
@@ -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 = { $key: filter || {}, $chi: [object] };
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: any): any;
2
- export declare function unpack(children: any, parentVersion: any): any;
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
@@ -1,3 +1,3 @@
1
1
  export declare function encode(path: any): any;
2
2
  export declare function decode(path: any): any[];
3
- export declare function splitRef($ref: any): {}[];
3
+ export declare function splitRef($ref: any): any[] | [Record<string, any>, Record<string, any>];
package/coding/struct.js CHANGED
@@ -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: any, last: any): number;
2
- export declare function findLast(children: any, end: any, first: any, last: any): number;
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/slice.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  declare class Result {
2
- constructor(root: any);
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: any): Result;
11
+ export default function slice(graph: any, query: any, root?: any): Result;
8
12
  export declare function sliceRange(graph: any, query: any, result: any): void;
9
13
  export {};
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.19.1-alpha.1",
5
+ "version": "0.19.1-alpha.2",
6
6
  "main": "./cjs/index.js",
7
7
  "exports": {
8
8
  ".": {
@@ -22,9 +22,9 @@
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
24
  "debug": "^4.4.3",
25
- "lodash": "^4.17.23",
26
- "nanoid": "^5.1.6",
27
- "@graffy/stream": "0.19.1-alpha.1",
25
+ "lodash": "^4.18.1",
26
+ "nanoid": "^5.1.11",
27
+ "@graffy/stream": "0.19.1-alpha.2",
28
28
  "merge-async-iterators": "^0.2.1"
29
29
  }
30
30
  }
@@ -1,7 +1,7 @@
1
1
  export default function makeWatcher(): {
2
2
  write: (change: any) => void;
3
3
  watch: (...args: any[]) => {
4
- debugId: any;
4
+ debugId: string;
5
5
  next: () => any;
6
6
  return(value: any): any;
7
7
  throw(error: any): any;
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: any): void;
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;