@graffy/common 0.16.19 → 0.16.20-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.
Files changed (3) hide show
  1. package/index.cjs +155 -309
  2. package/index.mjs +155 -309
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -19,12 +19,10 @@ function err(message, { cause = null, ...args } = {}) {
19
19
  throw e;
20
20
  }
21
21
  function errIf(message, condition, args) {
22
- if (condition)
23
- err(message, args);
22
+ if (condition) err(message, args);
24
23
  }
25
24
  function isEmpty(object) {
26
- for (const _ in object)
27
- return false;
25
+ for (const _ in object) return false;
28
26
  return true;
29
27
  }
30
28
  function isDef(value) {
@@ -42,15 +40,11 @@ function clone$1(obj) {
42
40
  function cmp(a, b) {
43
41
  const l = a.length < b.length ? a.length : b.length;
44
42
  for (let i = 0; i < l; i++) {
45
- if (a[i] < b[i])
46
- return -1;
47
- if (a[i] > b[i])
48
- return 1;
49
- }
50
- if (a.length < b.length)
51
- return -1;
52
- if (a.length > b.length)
53
- return 1;
43
+ if (a[i] < b[i]) return -1;
44
+ if (a[i] > b[i]) return 1;
45
+ }
46
+ if (a.length < b.length) return -1;
47
+ if (a.length > b.length) return 1;
54
48
  return 0;
55
49
  }
56
50
  function find(items, compare2, first = 0, last = items.length) {
@@ -71,8 +65,7 @@ function find(items, compare2, first = 0, last = items.length) {
71
65
  }
72
66
  function stringify() {
73
67
  var _a;
74
- if ((this == null ? void 0 : this.length) === 0)
75
- return "·";
68
+ if ((this == null ? void 0 : this.length) === 0) return "·";
76
69
  let str = "";
77
70
  let bull = false;
78
71
  (_a = this == null ? void 0 : this.forEach) == null ? void 0 : _a.call(this, (value, i) => {
@@ -88,10 +81,8 @@ function stringify() {
88
81
  }
89
82
  const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
90
83
  function addStringify(buffer) {
91
- if (!isDebugMode)
92
- return buffer;
93
- if ("toJSON" in buffer || inspectSymbol in buffer)
94
- return buffer;
84
+ if (!isDebugMode) return buffer;
85
+ if ("toJSON" in buffer || inspectSymbol in buffer) return buffer;
95
86
  buffer.toJSON = stringify;
96
87
  buffer.toString = stringify;
97
88
  buffer[inspectSymbol] = stringify;
@@ -164,31 +155,22 @@ function encodeObject(object) {
164
155
  ];
165
156
  }
166
157
  function encodeParts(value) {
167
- if (value === null)
168
- return [NULL];
169
- if (value === false)
170
- return [FALSE];
171
- if (value === true)
172
- return [TRUE];
173
- if (typeof value === "number")
174
- return [NUM, encode$6(value)];
175
- if (typeof value === "string")
176
- return [STR, encode$5(value), END];
177
- if (Array.isArray(value))
178
- return encodeArray(value);
179
- if (typeof value === "object")
180
- return encodeObject(value);
158
+ if (value === null) return [NULL];
159
+ if (value === false) return [FALSE];
160
+ if (value === true) return [TRUE];
161
+ if (typeof value === "number") return [NUM, encode$6(value)];
162
+ if (typeof value === "string") return [STR, encode$5(value), END];
163
+ if (Array.isArray(value)) return encodeArray(value);
164
+ if (typeof value === "object") return encodeObject(value);
181
165
  return [NULL];
182
166
  }
183
167
  function encode$4(value) {
184
168
  const parts = encodeParts(value);
185
- while (parts[parts.length - 1] === END)
186
- parts.pop();
169
+ while (parts[parts.length - 1] === END) parts.pop();
187
170
  const lastPart = parts[parts.length - 1];
188
171
  if (typeof lastPart !== "number") {
189
172
  let end = lastPart.length - 1;
190
- while (end >= 0 && !lastPart[end])
191
- end--;
173
+ while (end >= 0 && !lastPart[end]) end--;
192
174
  if (lastPart[end] !== 255) {
193
175
  parts[parts.length - 1] = lastPart.slice(0, end + 1);
194
176
  } else {
@@ -219,18 +201,15 @@ function decode$4(buffer) {
219
201
  const stack = [[]];
220
202
  function readString() {
221
203
  const start = i;
222
- while (i < buffer.length && buffer[i] !== END)
223
- i++;
204
+ while (i < buffer.length && buffer[i] !== END) i++;
224
205
  const str = decode$5(buffer.subarray(start, i));
225
206
  i++;
226
207
  return str;
227
208
  }
228
209
  function pushToken(type, value) {
229
210
  const current = stack[stack.length - 1];
230
- if (type === ARR || type === OBJ)
231
- stack.push(value);
232
- if (!current)
233
- return;
211
+ if (type === ARR || type === OBJ) stack.push(value);
212
+ if (!current) return;
234
213
  if (Array.isArray(current)) {
235
214
  current.push(value);
236
215
  } else {
@@ -283,10 +262,8 @@ function decode$4(buffer) {
283
262
  return stack[0][0];
284
263
  }
285
264
  function keyStep(key) {
286
- if (isMinKey(key))
287
- return { key, step: 1 };
288
- if (isMaxKey(key))
289
- return { key, step: -1 };
265
+ if (isMinKey(key)) return { key, step: 1 };
266
+ if (isMaxKey(key)) return { key, step: -1 };
290
267
  const l = key.length - 1;
291
268
  let newKey;
292
269
  let step;
@@ -309,8 +286,7 @@ function keyStep(key) {
309
286
  return { key: newKey, step };
310
287
  }
311
288
  function keyBefore(key) {
312
- if (isMinKey(key) || isMaxKey(key))
313
- return key;
289
+ if (isMinKey(key) || isMaxKey(key)) return key;
314
290
  const l = key.length - 1;
315
291
  let newKey;
316
292
  if (key[l] === 0) {
@@ -325,8 +301,7 @@ function keyBefore(key) {
325
301
  return newKey;
326
302
  }
327
303
  function keyAfter(key) {
328
- if (isMaxKey(key))
329
- return key;
304
+ if (isMaxKey(key)) return key;
330
305
  const l = key.length - 1;
331
306
  let newKey;
332
307
  if (key[l] === 255) {
@@ -342,8 +317,7 @@ function keyAfter(key) {
342
317
  }
343
318
  function decodeBound(bound) {
344
319
  const { key, step } = keyStep(bound);
345
- if (isMinKey(key) || isMaxKey(key))
346
- return { step };
320
+ if (isMinKey(key) || isMaxKey(key)) return { step };
347
321
  const value = decode$4(key);
348
322
  return { key: value, step };
349
323
  }
@@ -360,20 +334,17 @@ const pageProps = {
360
334
  function splitArgs(arg) {
361
335
  const page = {};
362
336
  const filter = {};
363
- for (const p in arg)
364
- (p in pageProps ? page : filter)[p] = arg[p];
337
+ for (const p in arg) (p in pageProps ? page : filter)[p] = arg[p];
365
338
  return [
366
339
  isEmpty(page) ? void 0 : page,
367
340
  isEmpty(filter) ? void 0 : filter
368
341
  ];
369
342
  }
370
343
  function encode$3(arg) {
371
- if (!isPlainObject(arg))
372
- return { key: encode$4(arg) };
344
+ if (!isPlainObject(arg)) return { key: encode$4(arg) };
373
345
  const [page, filter] = splitArgs(arg);
374
346
  errIf("page_and_filter", page && filter, arg);
375
- if (!page)
376
- return { key: encode$4(filter || {}) };
347
+ if (!page) return { key: encode$4(filter || {}) };
377
348
  const { $cursor, ...range } = page;
378
349
  const { $first, $all, $last, $after, $before, $since, $until } = range;
379
350
  const hasRange = !isEmpty(range);
@@ -384,23 +355,15 @@ function encode$3(arg) {
384
355
  errIf("before_and_until", isDef($before) && isDef($until), arg);
385
356
  errIf("cursor_and_range_arg", isDef($cursor) && hasRange, arg);
386
357
  let [key, end] = hasRange ? [MIN_KEY, MAX_KEY] : [];
387
- if (isDef($cursor))
388
- key = encode$4($cursor);
389
- if (isDef($after))
390
- key = keyAfter(encode$4($after));
391
- if (isDef($before))
392
- end = keyBefore(encode$4($before));
393
- if (isDef($since))
394
- key = encode$4($since);
395
- if (isDef($until))
396
- end = encode$4($until);
397
- if (isDef($last))
398
- [key, end] = [end, key];
358
+ if (isDef($cursor)) key = encode$4($cursor);
359
+ if (isDef($after)) key = keyAfter(encode$4($after));
360
+ if (isDef($before)) end = keyBefore(encode$4($before));
361
+ if (isDef($since)) key = encode$4($since);
362
+ if (isDef($until)) end = encode$4($until);
363
+ if (isDef($last)) [key, end] = [end, key];
399
364
  const node = { key };
400
- if (isDef(end))
401
- node.end = end;
402
- if ($first || $last)
403
- node.limit = $first || $last;
365
+ if (isDef(end)) node.end = end;
366
+ if ($first || $last) node.limit = $first || $last;
404
367
  return node;
405
368
  }
406
369
  function decode$3(node) {
@@ -408,8 +371,7 @@ function decode$3(node) {
408
371
  errIf("no_key", !isDef(key));
409
372
  errIf("limit_without_end", isDef(limit) && !isDef(end));
410
373
  const kParts = decodeBound(key);
411
- if (!isDef(end) || cmp(key, end) === 0)
412
- return kParts.key;
374
+ if (!isDef(end) || cmp(key, end) === 0) return kParts.key;
413
375
  const eParts = decodeBound(end);
414
376
  const reverse = cmp(key, end) > 0;
415
377
  const [lower, upper] = reverse ? [eParts, kParts] : [kParts, eParts];
@@ -430,25 +392,21 @@ function decode$3(node) {
430
392
  const PATH_SEPARATOR = ".";
431
393
  function encode$2(path) {
432
394
  if (typeof path === "string") {
433
- if (!path.length || path === PATH_SEPARATOR)
434
- return [];
395
+ if (!path.length || path === PATH_SEPARATOR) return [];
435
396
  path = path.split(PATH_SEPARATOR);
436
397
  }
437
398
  if (!Array.isArray(path)) {
438
399
  throw Error(`encodePath.invalid:${JSON.stringify(path)}`);
439
400
  }
440
401
  function encodeSegment(seg) {
441
- if (ArrayBuffer.isView(seg))
442
- return seg;
402
+ if (ArrayBuffer.isView(seg)) return seg;
443
403
  const node = encode$3(seg);
444
- if (node.end)
445
- return node;
404
+ if (node.end) return node;
446
405
  return node.key;
447
406
  }
448
407
  if (isPlainObject(path[path.length - 1])) {
449
408
  const [page, filter] = splitArgs(path[path.length - 1]);
450
- if (page)
451
- path = path.slice(0, -1).concat([filter || MIN_KEY]);
409
+ if (page) path = path.slice(0, -1).concat([filter || MIN_KEY]);
452
410
  }
453
411
  return path.map(encodeSegment);
454
412
  }
@@ -459,11 +417,9 @@ function decode$2(path) {
459
417
  return path.map((key) => decode$3({ key }));
460
418
  }
461
419
  function splitRef($ref) {
462
- if (!Array.isArray($ref))
463
- return [];
420
+ if (!Array.isArray($ref)) return [];
464
421
  const tail = $ref[$ref.length - 1];
465
- if (!isPlainObject(tail))
466
- return [];
422
+ if (!isPlainObject(tail)) return [];
467
423
  return splitArgs(tail);
468
424
  }
469
425
  let customAlphabet = (alphabet, defaultSize = 21) => {
@@ -484,8 +440,7 @@ function findFirst(children, target, first, last) {
484
440
  ({ key, end }) => {
485
441
  const keyCmp = cmp(key, target);
486
442
  const endCmp = end && cmp(end, target);
487
- if (end && keyCmp < 0 && endCmp >= 0)
488
- return 0;
443
+ if (end && keyCmp < 0 && endCmp >= 0) return 0;
489
444
  return keyCmp;
490
445
  },
491
446
  first,
@@ -553,20 +508,17 @@ function compare(node) {
553
508
  };
554
509
  }
555
510
  function compareValue(a, b) {
556
- if (a === b)
557
- return 0;
511
+ if (a === b) return 0;
558
512
  return a < b ? -1 : 1;
559
513
  }
560
514
  function clone(node) {
561
515
  const copy = { ...node };
562
- if (node.children)
563
- copy.children = node.children.map((child) => clone(child));
516
+ if (node.children) copy.children = node.children.map((child) => clone(child));
564
517
  return copy;
565
518
  }
566
519
  function merge(current, changes) {
567
520
  let index = 0;
568
- if (typeof changes === "undefined")
569
- return current;
521
+ if (typeof changes === "undefined") return current;
570
522
  for (const change of changes) {
571
523
  index = isRange(change) ? insertRange$1(current, change, index) : insertNode$1(current, change, index);
572
524
  }
@@ -589,8 +541,7 @@ function insertRange$1(current, change, start = 0) {
589
541
  return keyIx + insertions.length - 1;
590
542
  }
591
543
  function mergeRanges$1(base, node) {
592
- if (node.version < base.version)
593
- [node, base] = [base, node];
544
+ if (node.version < base.version) [node, base] = [base, node];
594
545
  return [
595
546
  cmp(base.key, node.key) < 0 && { ...base, end: keyBefore(node.key) },
596
547
  node,
@@ -598,8 +549,7 @@ function mergeRanges$1(base, node) {
598
549
  ].filter(Boolean);
599
550
  }
600
551
  function insertNode$1(current, change, start = 0) {
601
- if (!current)
602
- throw new Error(`merge.insertNode: ${current}`);
552
+ if (!current) throw new Error(`merge.insertNode: ${current}`);
603
553
  const key = change.key;
604
554
  const index = findFirst(current, key, start);
605
555
  const node = current[index];
@@ -613,8 +563,7 @@ function insertNodeIntoRange$1(current, index, change) {
613
563
  const key = change.key;
614
564
  const range = current[index];
615
565
  const newChange = getNewer(change, range);
616
- if (!newChange)
617
- return;
566
+ if (!newChange) return;
618
567
  const insertions = [
619
568
  cmp(range.key, key) < 0 && { ...range, end: keyBefore(key) },
620
569
  newChange,
@@ -632,11 +581,9 @@ function updateNode$1(current, index, change) {
632
581
  current[index] = newNode || change;
633
582
  } else {
634
583
  const newChange = getNewer(change, node);
635
- if (newChange)
636
- current[index] = newChange;
584
+ if (newChange) current[index] = newChange;
637
585
  }
638
- if (change.prefix)
639
- current[index].prefix = true;
586
+ if (change.prefix) current[index].prefix = true;
640
587
  return index + 1;
641
588
  }
642
589
  function getNewer(node, base) {
@@ -650,8 +597,7 @@ function getNewer(node, base) {
650
597
  }
651
598
  const IS_VAL = Symbol("IS_VAL");
652
599
  function makeNode(seg, props2) {
653
- if (ArrayBuffer.isView(seg))
654
- return { key: seg, ...props2 };
600
+ if (ArrayBuffer.isView(seg)) return { key: seg, ...props2 };
655
601
  return { ...seg, ...props2 };
656
602
  }
657
603
  function wrapValue(value, path, version = 0) {
@@ -659,74 +605,56 @@ function wrapValue(value, path, version = 0) {
659
605
  return wrap([node], path.slice(0, -1), version);
660
606
  }
661
607
  function wrap(children, path, version = 0, prefix = false) {
662
- if (!Array.isArray(path))
663
- throw Error(`wrap.path_not_array ${path}`);
664
- if (!path.length)
665
- return children;
608
+ if (!Array.isArray(path)) throw Error(`wrap.path_not_array ${path}`);
609
+ if (!path.length) return children;
666
610
  let i = path.length - 1;
667
611
  if (!Array.isArray(children)) {
668
612
  children = [makeNode(path[i--], { value: children, version })];
669
613
  } else {
670
- if (!children.length)
671
- return;
614
+ if (!children.length) return;
672
615
  children = [makeNode(path[i--], { children, version })];
673
616
  }
674
- if (prefix)
675
- children[0].prefix = true;
676
- while (i >= 0)
677
- children = [makeNode(path[i--], { children, version })];
617
+ if (prefix) children[0].prefix = true;
618
+ while (i >= 0) children = [makeNode(path[i--], { children, version })];
678
619
  return children;
679
620
  }
680
621
  function unwrap(tree, path) {
681
- if (!Array.isArray(path))
682
- throw Error(`unwrap.path_not_array ${path}`);
622
+ if (!Array.isArray(path)) throw Error(`unwrap.path_not_array ${path}`);
683
623
  let children = tree;
684
624
  let node = { children };
685
625
  for (let i = 0; i < path.length; i++) {
686
626
  const key = path[i];
687
- if (!ArrayBuffer.isView(key))
688
- throw Error("unwrap.ranges_unsupported");
627
+ if (!ArrayBuffer.isView(key)) throw Error("unwrap.ranges_unsupported");
689
628
  children = node.children;
690
- if (!children)
691
- return null;
629
+ if (!children) return null;
692
630
  node = children[findFirst(children, key)];
693
- if (!node || cmp(node.key, key) > 0)
694
- return void 0;
695
- if (isRange(node))
696
- return null;
697
- if (node.path)
698
- return unwrap(tree, node.path.concat(path.slice(i + 1)));
631
+ if (!node || cmp(node.key, key) > 0) return void 0;
632
+ if (isRange(node)) return null;
633
+ if (node.path) return unwrap(tree, node.path.concat(path.slice(i + 1)));
699
634
  }
700
635
  return getNodeValue(node);
701
636
  }
702
637
  function getNodeValue(node) {
703
- if (node.children)
704
- return node.children;
638
+ if (node.children) return node.children;
705
639
  if (node.value && typeof node.value === "object") {
706
640
  node.value[IS_VAL] = true;
707
641
  }
708
642
  return node.value;
709
643
  }
710
644
  function remove(children, path) {
711
- if (!Array.isArray(path))
712
- throw Error(`del.path_not_array ${path}`);
713
- if (!children)
714
- return null;
715
- if (!path.length)
716
- return [];
645
+ if (!Array.isArray(path)) throw Error(`del.path_not_array ${path}`);
646
+ if (!children) return null;
647
+ if (!path.length) return [];
717
648
  const key = path[0];
718
649
  const ix = findFirst(children, key);
719
650
  const node = children[ix];
720
- if (!node || cmp(node.key, key) > 0 || isRange(node))
721
- return children;
651
+ if (!node || cmp(node.key, key) > 0 || isRange(node)) return children;
722
652
  if (path.length === 1) {
723
653
  return children.slice(0, ix).concat(children.slice(ix + 1));
724
654
  }
725
- if (!isBranch(node))
726
- return children;
655
+ if (!isBranch(node)) return children;
727
656
  const filteredChildren = remove(node.children, path.slice(1));
728
- if (filteredChildren === children)
729
- return children;
657
+ if (filteredChildren === children) return children;
730
658
  const filteredNode = filteredChildren.length ? { ...node, children: filteredChildren } : [];
731
659
  return children.slice(0, ix).concat(filteredNode, children.slice(ix + 1));
732
660
  }
@@ -743,8 +671,7 @@ class Result {
743
671
  this.unknown.push(node);
744
672
  }
745
673
  addLinked(children) {
746
- if (this.root !== this)
747
- return this.root.addLinked(children);
674
+ if (this.root !== this) return this.root.addLinked(children);
748
675
  this.linked = this.linked || [];
749
676
  add(this.linked, children);
750
677
  }
@@ -786,10 +713,8 @@ function sliceNode(graph, query, result) {
786
713
  }
787
714
  } else if (isBranch(graph) && isBranch(query)) {
788
715
  const { known, unknown } = slice(graph.children, query.children, root);
789
- if (known)
790
- result.addKnown({ ...graph, children: known });
791
- if (unknown)
792
- result.addUnknown({ ...query, children: unknown });
716
+ if (known) result.addKnown({ ...graph, children: known });
717
+ if (unknown) result.addUnknown({ ...query, children: unknown });
793
718
  } else if (isLink(graph)) {
794
719
  result.addKnown(graph);
795
720
  if (graph.prefix && isRange(query)) {
@@ -821,17 +746,14 @@ function sliceRange(graph, query, result) {
821
746
  const step = cmp(key, end) < 0 ? 1 : -1;
822
747
  if (isMinKey(graph[0].key) && graph[0].prefix && graph[0].children) {
823
748
  const { known, unknown } = slice(graph[0].children, [query], result.root);
824
- if (known)
825
- result.addKnown({ ...graph[0], children: known });
826
- if (unknown)
827
- result.addUnknown({ ...query[0], children: unknown });
749
+ if (known) result.addKnown({ ...graph[0], children: known });
750
+ if (unknown) result.addUnknown({ ...query[0], children: unknown });
828
751
  return;
829
752
  }
830
753
  if (cmp(key, end) < 0) {
831
754
  for (let i = findFirst(graph, key); cmp(key, end) <= 0 && limit > 0; i++) {
832
755
  const node = graph[i];
833
- if (!node || cmp(key, node.key) < 0 || isOlder(node, version))
834
- break;
756
+ if (!node || cmp(key, node.key) < 0 || isOlder(node, version)) break;
835
757
  if (isRange(node)) {
836
758
  result.addKnown(getOverlap(node, key, end));
837
759
  } else {
@@ -860,8 +782,7 @@ function sliceRange(graph, query, result) {
860
782
  }
861
783
  }
862
784
  function getOverlap(node, key, end) {
863
- if (cmp(node.key, key) >= 0 && cmp(node.end, end) <= 0)
864
- return node;
785
+ if (cmp(node.key, key) >= 0 && cmp(node.end, end) <= 0) return node;
865
786
  return {
866
787
  ...node,
867
788
  key: cmp(node.key, key) > 0 ? node.key : key,
@@ -916,8 +837,7 @@ function insertRange(current, change, result, start = 0) {
916
837
  version: change.version
917
838
  });
918
839
  }
919
- if (appliedChange.length)
920
- result.push(...appliedChange);
840
+ if (appliedChange.length) result.push(...appliedChange);
921
841
  const insertions = [change];
922
842
  for (let i = keyIx; i < endIx; i++) {
923
843
  const node = current[i];
@@ -931,8 +851,7 @@ function insertRange(current, change, result, start = 0) {
931
851
  return keyIx + insertions.length - 1;
932
852
  }
933
853
  function mergeRanges(base, node) {
934
- if (node.version < base.version)
935
- [node, base] = [base, node];
854
+ if (node.version < base.version) [node, base] = [base, node];
936
855
  return [
937
856
  cmp(base.key, node.key) < 0 && { ...base, end: keyBefore(node.key) },
938
857
  node,
@@ -953,8 +872,7 @@ function insertNodeIntoRange(current, index, change, result) {
953
872
  const range = current[index];
954
873
  const newChange = getNewerChange(change, range);
955
874
  const newNode = getNewerNode(change, range);
956
- if (!newChange)
957
- return;
875
+ if (!newChange) return;
958
876
  result.push(newChange);
959
877
  const insertions = [
960
878
  cmp(range.key, key) < 0 && { ...range, end: keyBefore(key) },
@@ -970,18 +888,15 @@ function updateNode(current, index, change, result) {
970
888
  const nextResult = [];
971
889
  node.version = change.version;
972
890
  sieve(node.children, change.children, nextResult);
973
- if (nextResult.length)
974
- result.push({ ...change, children: nextResult });
891
+ if (nextResult.length) result.push({ ...change, children: nextResult });
975
892
  } else if (isBranch(node)) {
976
893
  const newNode = getNewerNode(node, change);
977
894
  current[index] = newNode || change;
978
- if (!newNode)
979
- result.push(change);
895
+ if (!newNode) result.push(change);
980
896
  } else {
981
897
  const newChange = getNewerChange(change, node);
982
898
  const newNode = getNewerNode(change, node);
983
- if (newNode)
984
- current[index] = newNode;
899
+ if (newNode) current[index] = newNode;
985
900
  if (newChange && (change.value !== node.value || !isPathEqual(change.path, node.path))) {
986
901
  result.push(newChange);
987
902
  }
@@ -989,15 +904,11 @@ function updateNode(current, index, change, result) {
989
904
  return index + 1;
990
905
  }
991
906
  function isPathEqual(first, second) {
992
- if (!(first || second))
993
- return true;
994
- if (!(first && second))
995
- return false;
996
- if (first.length !== second.length)
997
- return false;
907
+ if (!(first || second)) return true;
908
+ if (!(first && second)) return false;
909
+ if (first.length !== second.length) return false;
998
910
  for (let i = 0; i < first.length; i++) {
999
- if (first[i] !== second[i])
1000
- return false;
911
+ if (first[i] !== second[i]) return false;
1001
912
  }
1002
913
  return true;
1003
914
  }
@@ -1021,10 +932,8 @@ function getNewerChange(node, base) {
1021
932
  }
1022
933
  function setVersion(graph, version, onlyIfZero = false) {
1023
934
  for (const node of graph) {
1024
- if (!(onlyIfZero && node.version))
1025
- node.version = version;
1026
- if (node.children)
1027
- setVersion(node.children, version, onlyIfZero);
935
+ if (!(onlyIfZero && node.version)) node.version = version;
936
+ if (node.children) setVersion(node.children, version, onlyIfZero);
1028
937
  }
1029
938
  return graph;
1030
939
  }
@@ -1033,8 +942,7 @@ function getKnown(graph, version = 0) {
1033
942
  for (const { key, end, children } of graph) {
1034
943
  const node = { key, version };
1035
944
  if (end) {
1036
- if (cmp(end, key) !== 0)
1037
- node.end = end;
945
+ if (cmp(end, key) !== 0) node.end = end;
1038
946
  node.value = 1;
1039
947
  }
1040
948
  if (children) {
@@ -1049,10 +957,8 @@ function getKnown(graph, version = 0) {
1049
957
  function finalize(graph, query, version = Date.now()) {
1050
958
  let result = [{ key: MIN_KEY, end: MAX_KEY, version: 0 }];
1051
959
  merge(result, graph);
1052
- if (query)
1053
- result = slice(result, query).known || [];
1054
- if (version !== false)
1055
- result = setVersion(result, version, true);
960
+ if (query) result = slice(result, query).known || [];
961
+ if (version !== false) result = setVersion(result, version, true);
1056
962
  return result;
1057
963
  }
1058
964
  const PRE_CHI_PUT = Symbol("PREFIX_CHILDREN_$PUT");
@@ -1063,10 +969,8 @@ function decode$1(nodes = [], { isGraph } = {}) {
1063
969
  let allNums = true;
1064
970
  function pushResult(...objects) {
1065
971
  for (const object of objects) {
1066
- if (isDef(object) && !Number.isInteger(object.$key))
1067
- allNums = false;
1068
- if (isDef(object) && typeof object.$key !== "string")
1069
- allStrs = false;
972
+ if (isDef(object) && !Number.isInteger(object.$key)) allNums = false;
973
+ if (isDef(object) && typeof object.$key !== "string") allStrs = false;
1070
974
  }
1071
975
  result.push(...objects);
1072
976
  }
@@ -1095,22 +999,17 @@ function decode$1(nodes = [], { isGraph } = {}) {
1095
999
  return false;
1096
1000
  }
1097
1001
  for (const node of nodes2) {
1098
- if (isGraph && addPutRange(node))
1099
- continue;
1002
+ if (isGraph && addPutRange(node)) continue;
1100
1003
  if (isPrefix(node)) {
1101
1004
  const decodedChildren = decodePrefixNode(node);
1102
1005
  if (PRE_CHI_PUT in decodedChildren) {
1103
1006
  prefixChildPuts.push(...decodedChildren[PRE_CHI_PUT]);
1104
1007
  }
1105
1008
  pushResult(...decodedChildren);
1106
- } else if (isGraph && isRange(node))
1107
- pushResult(decodeRangeNode(node));
1108
- else if (isBranch(node))
1109
- pushResult(decodeBranchNode(node));
1110
- else if (isLink(node))
1111
- pushResult(decodeLinkNode(node));
1112
- else
1113
- pushResult(decodeLeafNode(node));
1009
+ } else if (isGraph && isRange(node)) pushResult(decodeRangeNode(node));
1010
+ else if (isBranch(node)) pushResult(decodeBranchNode(node));
1011
+ else if (isLink(node)) pushResult(decodeLinkNode(node));
1012
+ else pushResult(decodeLeafNode(node));
1114
1013
  }
1115
1014
  if (allStrs || allNums && putRanges.length === 1 && cmp(putRanges[0].key, 0) === 0 && cmp(putRanges[0].end, Number.POSITIVE_INFINITY) === 0) {
1116
1015
  result = result.reduce(
@@ -1150,8 +1049,7 @@ function decode$1(nodes = [], { isGraph } = {}) {
1150
1049
  }
1151
1050
  function decodePrefixNode(node) {
1152
1051
  let args = decode$3(node);
1153
- if (!args)
1154
- args = {};
1052
+ if (!args) args = {};
1155
1053
  if (typeof args === "string") {
1156
1054
  throw Error(`decode.unencoded_prefix: ${args}`);
1157
1055
  }
@@ -1224,12 +1122,9 @@ const REF = Symbol();
1224
1122
  const PRE = Symbol();
1225
1123
  function decorate(rootGraph, rootQuery) {
1226
1124
  function construct(plumGraph, query) {
1227
- if (plumGraph === null)
1228
- return null;
1229
- if (!isDef(plumGraph))
1230
- plumGraph = [];
1231
- if (query.$key)
1232
- query = [query];
1125
+ if (plumGraph === null) return null;
1126
+ if (!isDef(plumGraph)) plumGraph = [];
1127
+ if (query.$key) query = [query];
1233
1128
  let graph;
1234
1129
  if (query.$ref) {
1235
1130
  const { $ref, ...props2 } = query;
@@ -1237,8 +1132,7 @@ function decorate(rootGraph, rootQuery) {
1237
1132
  const path = encode$2($ref);
1238
1133
  const targetPlumGraph = unwrap(rootGraph, path);
1239
1134
  if (targetPlumGraph) {
1240
- if (range)
1241
- targetPlumGraph[PRE] = filter;
1135
+ if (range) targetPlumGraph[PRE] = filter;
1242
1136
  graph = construct(
1243
1137
  targetPlumGraph,
1244
1138
  range ? { $key: range, ...props2 } : props2
@@ -1272,8 +1166,7 @@ function decorate(rootGraph, rootQuery) {
1272
1166
  return subResult;
1273
1167
  });
1274
1168
  });
1275
- if (pageKey)
1276
- addPageMeta(graph, pageKey);
1169
+ if (pageKey) addPageMeta(graph, pageKey);
1277
1170
  } else if (typeof query === "object") {
1278
1171
  graph = {};
1279
1172
  for (const prop in query) {
@@ -1302,27 +1195,21 @@ function decorate(rootGraph, rootQuery) {
1302
1195
  }
1303
1196
  function descend(children, $key) {
1304
1197
  const key = ArrayBuffer.isView($key) ? $key : encode$3($key).key;
1305
- if (!Array.isArray(children))
1306
- return null;
1198
+ if (!Array.isArray(children)) return null;
1307
1199
  const ix = findFirst(children, key);
1308
1200
  const node = children[ix];
1309
- if (!node)
1310
- return;
1311
- if (isRange(node) && node.end >= key)
1312
- return null;
1313
- if (cmp(node.key, key) !== 0)
1314
- return;
1201
+ if (!node) return;
1202
+ if (isRange(node) && node.end >= key) return null;
1203
+ if (cmp(node.key, key) !== 0) return;
1315
1204
  const result2 = getValue(node);
1316
- if (node.prefix)
1317
- result2[PRE] = $key;
1205
+ if (node.prefix) result2[PRE] = $key;
1318
1206
  return result2;
1319
1207
  }
1320
1208
  function getValue(node) {
1321
1209
  let result2;
1322
1210
  if (node.path) {
1323
1211
  result2 = unwrap(rootGraph, node.path);
1324
- if (typeof result2 === "object" && result2)
1325
- result2[REF] = node.path;
1212
+ if (typeof result2 === "object" && result2) result2[REF] = node.path;
1326
1213
  } else {
1327
1214
  result2 = getNodeValue(node);
1328
1215
  }
@@ -1341,33 +1228,26 @@ function decorate(rootGraph, rootQuery) {
1341
1228
  let result2;
1342
1229
  if (cmp(key, end) < 0) {
1343
1230
  for (let n = 0; i < children.length && n < limit; i++) {
1344
- if (!isRange(children[i]))
1345
- n++;
1231
+ if (!isRange(children[i])) n++;
1346
1232
  }
1347
1233
  result2 = children.slice(ix, i);
1348
1234
  } else {
1349
1235
  for (let n = 0; i >= 0 && n < limit; i--) {
1350
- if (!isRange(children[i]))
1351
- n++;
1236
+ if (!isRange(children[i])) n++;
1352
1237
  }
1353
1238
  result2 = children.slice(i + 1, ix + 1);
1354
1239
  }
1355
- if (children[REF])
1356
- result2[REF] = children[REF];
1357
- if (children[PRE])
1358
- result2[PRE] = children[PRE];
1240
+ if (children[REF]) result2[REF] = children[REF];
1241
+ if (children[PRE]) result2[PRE] = children[PRE];
1359
1242
  return result2;
1360
1243
  }
1361
1244
  const result = construct(rootGraph, rootQuery);
1362
1245
  return result;
1363
1246
  }
1364
1247
  function deValNull(graph) {
1365
- if (typeof graph !== "object" || !graph)
1366
- return graph;
1367
- if ("$val" in graph && graph.$val !== true)
1368
- return graph.$val;
1369
- for (const prop in graph)
1370
- graph[prop] = deValNull(graph[prop]);
1248
+ if (typeof graph !== "object" || !graph) return graph;
1249
+ if ("$val" in graph && graph.$val !== true) return graph.$val;
1250
+ for (const prop in graph) graph[prop] = deValNull(graph[prop]);
1371
1251
  return graph;
1372
1252
  }
1373
1253
  function addPageMeta(graph, args) {
@@ -1420,8 +1300,7 @@ function decode(string, start = 0) {
1420
1300
  for (let i = start; i < string.length; i += 4) {
1421
1301
  let value = (getChar(string, i) << 18) + (getChar(string, i + 1) << 12) + (getChar(string, i + 2) << 6) + getChar(string, i + 3);
1422
1302
  for (let j = i * 3 / 4 + 2; j >= i * 3 / 4; j--) {
1423
- if (j < view.byteLength)
1424
- view.setUint8(j, value & 255);
1303
+ if (j < view.byteLength) view.setUint8(j, value & 255);
1425
1304
  value = value >> 8 | 0;
1426
1305
  }
1427
1306
  }
@@ -1446,27 +1325,20 @@ function serializeKey(key) {
1446
1325
  return `\0${encode$1(key)}`;
1447
1326
  }
1448
1327
  function deserializeKey(key) {
1449
- if (key[0] === "\0")
1450
- return decode(key.slice(1));
1328
+ if (key[0] === "\0") return decode(key.slice(1));
1451
1329
  return encode$4(key);
1452
1330
  }
1453
1331
  function pack(children, parentVersion) {
1454
- if (!Array.isArray(children))
1455
- return children;
1332
+ if (!Array.isArray(children)) return children;
1456
1333
  const array = children.map(
1457
1334
  (node) => props.reduce(
1458
1335
  (array2, prop, i) => {
1459
- if (!(prop in node))
1460
- return array2;
1336
+ if (!(prop in node)) return array2;
1461
1337
  let value = node[prop];
1462
- if (prop === "version" && value === parentVersion)
1463
- return array2;
1464
- if (prop === "children")
1465
- value = pack(value, node.version);
1466
- if (prop === "end")
1467
- value = serializeKey(value);
1468
- if (prop === "path")
1469
- value = value.map(serializeKey);
1338
+ if (prop === "version" && value === parentVersion) return array2;
1339
+ if (prop === "children") value = pack(value, node.version);
1340
+ if (prop === "end") value = serializeKey(value);
1341
+ if (prop === "path") value = value.map(serializeKey);
1470
1342
  array2[1] |= 1 << i;
1471
1343
  array2.push(value);
1472
1344
  return array2;
@@ -1477,20 +1349,15 @@ function pack(children, parentVersion) {
1477
1349
  return array;
1478
1350
  }
1479
1351
  function unpack(children, parentVersion) {
1480
- if (!Array.isArray(children))
1481
- return children;
1352
+ if (!Array.isArray(children)) return children;
1482
1353
  const node = children.map(
1483
1354
  ([key, type, ...values]) => props.reduce(
1484
1355
  (node2, prop, i) => {
1485
- if (!(type & 1 << i))
1486
- return node2;
1356
+ if (!(type & 1 << i)) return node2;
1487
1357
  let value = values.shift();
1488
- if (prop === "children")
1489
- value = unpack(value, node2.version);
1490
- if (prop === "end")
1491
- value = deserializeKey(value);
1492
- if (prop === "path")
1493
- value = value.map(deserializeKey);
1358
+ if (prop === "children") value = unpack(value, node2.version);
1359
+ if (prop === "end") value = deserializeKey(value);
1360
+ if (prop === "path") value = value.map(deserializeKey);
1494
1361
  node2[prop] = value;
1495
1362
  return node2;
1496
1363
  },
@@ -1514,8 +1381,7 @@ function encode(value, { version, isGraph } = {}) {
1514
1381
  const combine = isGraph ? merge : add;
1515
1382
  function makeNode2(object, key, ver, parentPuts = []) {
1516
1383
  var _a2;
1517
- if (!isDef(object))
1518
- return;
1384
+ if (!isDef(object)) return;
1519
1385
  const { $key, $ver, $ref, $val, $chi, $put, ...props2 } = object || {};
1520
1386
  if (typeof object === "object" && object && !Array.isArray(object)) {
1521
1387
  object = {
@@ -1532,10 +1398,8 @@ function encode(value, { version, isGraph } = {}) {
1532
1398
  ...props2
1533
1399
  };
1534
1400
  }
1535
- if (typeof object === "object" && object && isEmpty(object))
1536
- return;
1537
- if (isDef($ver))
1538
- ver = $ver;
1401
+ if (typeof object === "object" && object && isEmpty(object)) return;
1402
+ if (isDef($ver)) ver = $ver;
1539
1403
  if (isPlainObject($key)) {
1540
1404
  const [page, filter] = splitArgs($key);
1541
1405
  if (page) {
@@ -1544,19 +1408,16 @@ function encode(value, { version, isGraph } = {}) {
1544
1408
  object.$key = filter || {};
1545
1409
  object.$put = foundPuts;
1546
1410
  const node2 = makeNode2(object, key, ver);
1547
- if (!filter)
1548
- node2.key = MIN_KEY;
1411
+ if (!filter) node2.key = MIN_KEY;
1549
1412
  node2.prefix = true;
1550
1413
  return node2;
1551
1414
  }
1552
1415
  if ((!isDef(key) || Number.isInteger(key)) && (filter || isDef(page.$cursor))) {
1553
1416
  object.$key = isDef(page.$cursor) ? page.$cursor : page;
1554
1417
  const wrapper = { $key: filter || {}, $chi: [object] };
1555
- if (isGraph)
1556
- wrapper.$put = foundPuts;
1418
+ if (isGraph) wrapper.$put = foundPuts;
1557
1419
  const node2 = makeNode2(wrapper, key, ver);
1558
- if (!filter)
1559
- node2.key = MIN_KEY;
1420
+ if (!filter) node2.key = MIN_KEY;
1560
1421
  node2.prefix = true;
1561
1422
  return node2;
1562
1423
  }
@@ -1582,8 +1443,7 @@ function encode(value, { version, isGraph } = {}) {
1582
1443
  } else if (isDef($put)) {
1583
1444
  classifyPut($put);
1584
1445
  }
1585
- if (isDef($key) && (Number.isInteger(key) || !isDef(key)))
1586
- key = $key;
1446
+ if (isDef($key) && (Number.isInteger(key) || !isDef(key))) key = $key;
1587
1447
  const node = key === ROOT_KEY || !isDef(key) ? {} : encode$3(key);
1588
1448
  node.version = ver;
1589
1449
  if (object === null) {
@@ -1595,8 +1455,7 @@ function encode(value, { version, isGraph } = {}) {
1595
1455
  return node;
1596
1456
  } else if ($ref) {
1597
1457
  pushLink($ref, node.version, props2, $val, $chi);
1598
- if (!isGraph)
1599
- return;
1458
+ if (!isGraph) return;
1600
1459
  node.path = encode$2($ref);
1601
1460
  } else if ($val === true) {
1602
1461
  node.value = Array.isArray(object) ? clone$1(object) : props2;
@@ -1621,16 +1480,12 @@ function encode(value, { version, isGraph } = {}) {
1621
1480
  const children = Object.keys(props2).sort().map((key2) => makeNode2(object[key2], key2, ver)).filter(Boolean);
1622
1481
  if (children.length) {
1623
1482
  node.children = children;
1624
- } else if (putRange.length)
1625
- ;
1483
+ } else if (putRange.length) ;
1626
1484
  else if (isGraph) {
1627
- if (!(isDef($key) || isDef($put)))
1628
- return;
1629
- if (node.key && !node.end)
1630
- node.end = node.key;
1485
+ if (!(isDef($key) || isDef($put))) return;
1486
+ if (node.key && !node.end) node.end = node.key;
1631
1487
  } else {
1632
- if (!isDef($key))
1633
- return;
1488
+ if (!isDef($key)) return;
1634
1489
  node.value = 1;
1635
1490
  }
1636
1491
  }
@@ -1649,8 +1504,7 @@ function encode(value, { version, isGraph } = {}) {
1649
1504
  return node;
1650
1505
  }
1651
1506
  }
1652
- if (value == null ? void 0 : value.$key)
1653
- value = [value];
1507
+ if (value == null ? void 0 : value.$key) value = [value];
1654
1508
  const result = ((_a = makeNode2(value, ROOT_KEY, version)) == null ? void 0 : _a.children) || [];
1655
1509
  while (links.length) {
1656
1510
  combine(result, [links.pop()]);
@@ -1670,13 +1524,11 @@ async function* mergeStreams(...streams) {
1670
1524
  if (firstValues.some((value) => typeof value === "undefined")) {
1671
1525
  yield void 0;
1672
1526
  for (const value of firstValues) {
1673
- if (typeof value !== "undefined")
1674
- yield value;
1527
+ if (typeof value !== "undefined") yield value;
1675
1528
  }
1676
1529
  } else {
1677
1530
  const merged = [];
1678
- for (const value of firstValues)
1679
- merge(merged, value);
1531
+ for (const value of firstValues) merge(merged, value);
1680
1532
  yield merged;
1681
1533
  }
1682
1534
  yield* mergeIterators(streams);
@@ -1684,14 +1536,12 @@ async function* mergeStreams(...streams) {
1684
1536
  function makeWatcher() {
1685
1537
  const listeners = /* @__PURE__ */ new Set();
1686
1538
  function write(change) {
1687
- for (const push of listeners)
1688
- push(change);
1539
+ for (const push of listeners) push(change);
1689
1540
  }
1690
1541
  function watch(...args) {
1691
1542
  return stream.makeStream((push, _end) => {
1692
1543
  listeners.add(push);
1693
- if (args.length)
1694
- Promise.resolve(args[0]).then(push);
1544
+ if (args.length) Promise.resolve(args[0]).then(push);
1695
1545
  return () => listeners.delete(push);
1696
1546
  });
1697
1547
  }
@@ -1722,15 +1572,13 @@ function cloneObject(object) {
1722
1572
  const clone2 = {};
1723
1573
  for (const prop in object) {
1724
1574
  const value = cloneObject(object[prop]);
1725
- if (value === null)
1726
- continue;
1575
+ if (value === null) continue;
1727
1576
  clone2[prop] = value;
1728
1577
  }
1729
1578
  return isEmpty(clone2) ? null : clone2;
1730
1579
  }
1731
1580
  function wrapObject(object, path) {
1732
- if (!Array.isArray(path))
1733
- throw Error(`wrapObject.path_not_array ${path}`);
1581
+ if (!Array.isArray(path)) throw Error(`wrapObject.path_not_array ${path}`);
1734
1582
  for (let i = path.length - 1; i >= 0; i--) {
1735
1583
  const $key = path[i];
1736
1584
  if (typeof $key === "string") {
@@ -1744,11 +1592,9 @@ function wrapObject(object, path) {
1744
1592
  return object;
1745
1593
  }
1746
1594
  function unwrapObject(object, path) {
1747
- if (!Array.isArray(path))
1748
- throw Error(`unwrapObject.path_not_array ${path}`);
1595
+ if (!Array.isArray(path)) throw Error(`unwrapObject.path_not_array ${path}`);
1749
1596
  for (let i = 0; i < path.length; i++) {
1750
- if (!object || typeof object !== "object")
1751
- return;
1597
+ if (!object || typeof object !== "object") return;
1752
1598
  const $key = path[i];
1753
1599
  if (typeof $key === "string") {
1754
1600
  if (Array.isArray(object)) {