@graffy/common 0.15.25-alpha.1 → 0.15.25-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/index.cjs CHANGED
@@ -1,46 +1,12 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source)
24
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
- target[prop] = source[prop];
26
- if (source != null && __getOwnPropSymbols)
27
- for (var prop of __getOwnPropSymbols(source)) {
28
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
- target[prop] = source[prop];
30
- }
31
- return target;
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports[Symbol.toStringTag] = "Module";
35
- var nonSecure = require("nanoid/non-secure");
36
- var mergeIterators = require("merge-async-iterators");
37
- var stream = require("@graffy/stream");
38
- var isEqual = require("lodash/isEqual.js");
39
- function _interopDefaultLegacy(e) {
40
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
41
- }
42
- var mergeIterators__default = /* @__PURE__ */ _interopDefaultLegacy(mergeIterators);
43
- var isEqual__default = /* @__PURE__ */ _interopDefaultLegacy(isEqual);
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const nonSecure = require("nanoid/non-secure");
4
+ const mergeIterators = require("merge-async-iterators");
5
+ const stream = require("@graffy/stream");
6
+ const isEqual = require("lodash/isEqual.js");
7
+ const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
8
+ const mergeIterators__default = /* @__PURE__ */ _interopDefaultLegacy(mergeIterators);
9
+ const isEqual__default = /* @__PURE__ */ _interopDefaultLegacy(isEqual);
44
10
  function encode$7(query) {
45
11
  return encodeURIComponent(JSON.stringify(query));
46
12
  }
@@ -79,7 +45,7 @@ function decode$5(u8Arr) {
79
45
  }
80
46
  return view.getFloat64(0);
81
47
  }
82
- var alpha = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
48
+ const alpha = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
83
49
  function getByte(view, offset) {
84
50
  return offset < view.byteLength ? view.getUint8(offset) : 0;
85
51
  }
@@ -163,7 +129,10 @@ function encode$3(value) {
163
129
  const parts = encodeParts(value);
164
130
  while (parts[parts.length - 1] === END)
165
131
  parts.pop();
166
- const length = parts.reduce((sum, part) => sum + (typeof part === "number" ? 1 : part.length), 0);
132
+ const length = parts.reduce(
133
+ (sum, part) => sum + (typeof part === "number" ? 1 : part.length),
134
+ 0
135
+ );
167
136
  const buffer = new Uint8Array(length);
168
137
  let i = 0;
169
138
  for (const part of parts) {
@@ -177,7 +146,7 @@ function encode$3(value) {
177
146
  }
178
147
  return encode$4(buffer);
179
148
  }
180
- const nextKey = new WeakMap();
149
+ const nextKey = /* @__PURE__ */ new WeakMap();
181
150
  function decode$3(key) {
182
151
  let i = 0;
183
152
  const buffer = decode$4(key, 0);
@@ -277,8 +246,7 @@ function keyAfter(key) {
277
246
  const l = key.length - 1;
278
247
  return key.charCodeAt(l) === 65535 ? key.substr(0, l - 1) + String.fromCharCode(key.charCodeAt(l - 1) + 1) : key + "\0";
279
248
  }
280
- function err(message, _a = {}) {
281
- var _b = _a, { cause } = _b, args = __objRest(_b, ["cause"]);
249
+ function err(message, { cause, ...args } = {}) {
282
250
  const e = new Error(message + (args ? " " + JSON.stringify(args) : ""));
283
251
  e.cause = cause;
284
252
  throw e;
@@ -356,7 +324,7 @@ function encode$2(arg) {
356
324
  errIf("page_and_filter", page && filter, arg);
357
325
  if (!page)
358
326
  return { key: maybeEncode(filter || {}) };
359
- const _a = page, { $cursor } = _a, range = __objRest(_a, ["$cursor"]);
327
+ const { $cursor, ...range } = page;
360
328
  const { $first, $all, $last, $after, $before, $since, $until } = range;
361
329
  const hasRange = !isEmpty(range);
362
330
  errIf("first_and_last", isDef($first) && isDef($last), arg);
@@ -451,15 +419,20 @@ function splitRef($ref) {
451
419
  return [];
452
420
  return splitArgs(tail);
453
421
  }
454
- var id = nonSecure.customAlphabet(alpha, 20);
422
+ const id = nonSecure.customAlphabet(alpha, 20);
455
423
  function findFirst(children, target, first, last) {
456
- return find(children, ({ key, end }) => {
457
- if (key === target || end && key < target && end >= target)
458
- return 0;
459
- if (key < target)
460
- return -1;
461
- return 1;
462
- }, first, last);
424
+ return find(
425
+ children,
426
+ ({ key, end }) => {
427
+ if (key === target || end && key < target && end >= target)
428
+ return 0;
429
+ if (key < target)
430
+ return -1;
431
+ return 1;
432
+ },
433
+ first,
434
+ last
435
+ );
463
436
  }
464
437
  function findLast(children, end, first, last) {
465
438
  const ix = findFirst(children, end, first, last);
@@ -530,7 +503,7 @@ function compareValue(a, b) {
530
503
  return a < b ? -1 : 1;
531
504
  }
532
505
  function clone(node) {
533
- const copy = __spreadValues({}, node);
506
+ const copy = { ...node };
534
507
  if (node.children)
535
508
  copy.children = node.children.map((child) => clone(child));
536
509
  return copy;
@@ -564,9 +537,9 @@ function mergeRanges$1(base, node) {
564
537
  if (node.version < base.version)
565
538
  [node, base] = [base, node];
566
539
  return [
567
- base.key < node.key && __spreadProps(__spreadValues({}, base), { end: keyBefore(node.key) }),
540
+ base.key < node.key && { ...base, end: keyBefore(node.key) },
568
541
  node,
569
- base.end > node.end && __spreadProps(__spreadValues({}, base), { key: keyAfter(node.end) })
542
+ base.end > node.end && { ...base, key: keyAfter(node.end) }
570
543
  ].filter(Boolean);
571
544
  }
572
545
  function insertNode$1(current, change, start = 0) {
@@ -589,9 +562,9 @@ function insertNodeIntoRange$1(current, index, change) {
589
562
  if (!newChange)
590
563
  return;
591
564
  const insertions = [
592
- range.key < key && __spreadProps(__spreadValues({}, range), { end: keyBefore(key) }),
565
+ range.key < key && { ...range, end: keyBefore(key) },
593
566
  newChange,
594
- range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
567
+ range.end > key && { ...range, key: keyAfter(key) }
595
568
  ].filter(Boolean);
596
569
  current.splice(index, 1, ...insertions);
597
570
  return index + insertions.length - 1;
@@ -617,14 +590,14 @@ function getNewer(node, base) {
617
590
  if (isBranch(node)) {
618
591
  const children = [{ key: "", end: "\uFFFF", version }];
619
592
  merge(children, node.children);
620
- return children.length === 1 ? null : __spreadProps(__spreadValues({}, node), { children });
593
+ return children.length === 1 ? null : { ...node, children };
621
594
  } else {
622
595
  return node.version >= version ? node : null;
623
596
  }
624
597
  }
625
598
  const IS_VAL = Symbol("IS_VAL");
626
599
  function wrapValue(value, path, version = 0) {
627
- const node = __spreadProps(__spreadValues({}, encode$2(path[path.length - 1])), { value, version });
600
+ const node = { ...encode$2(path[path.length - 1]), value, version };
628
601
  return wrap([node], path.slice(0, -1), version);
629
602
  }
630
603
  function wrap(children, path, version = 0, prefix = false) {
@@ -634,16 +607,16 @@ function wrap(children, path, version = 0, prefix = false) {
634
607
  return children;
635
608
  let i = path.length - 1;
636
609
  if (!Array.isArray(children)) {
637
- children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { value: children, version })];
610
+ children = [{ ...encode$2(path[i--]), value: children, version }];
638
611
  } else {
639
612
  if (!children.length)
640
613
  return;
641
- children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { version, children })];
614
+ children = [{ ...encode$2(path[i--]), version, children }];
642
615
  }
643
616
  if (prefix)
644
617
  children[0].prefix = true;
645
618
  while (i >= 0)
646
- children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { version, children })];
619
+ children = [{ ...encode$2(path[i--]), version, children }];
647
620
  return children;
648
621
  }
649
622
  function unwrap(tree, path) {
@@ -694,7 +667,7 @@ function remove(children, path) {
694
667
  const filteredChildren = remove(node.children, path.slice(1));
695
668
  if (filteredChildren === children)
696
669
  return children;
697
- const filteredNode = filteredChildren.length ? __spreadProps(__spreadValues({}, node), { children: filteredChildren }) : [];
670
+ const filteredNode = filteredChildren.length ? { ...node, children: filteredChildren } : [];
698
671
  return children.slice(0, ix).concat(filteredNode, children.slice(ix + 1));
699
672
  }
700
673
  class Result {
@@ -743,7 +716,10 @@ function sliceNode(graph, query, result) {
743
716
  result.addUnknown(query);
744
717
  } else if (isRange(graph)) {
745
718
  if (isBranch(query)) {
746
- const { known } = slice([{ key: "", end: "\uFFFF", version: graph.version }], query.children);
719
+ const { known } = slice(
720
+ [{ key: "", end: "\uFFFF", version: graph.version }],
721
+ query.children
722
+ );
747
723
  result.addKnown({ key, version: graph.version, children: known });
748
724
  } else {
749
725
  result.addKnown({ key, end: key, version: graph.version });
@@ -751,20 +727,30 @@ function sliceNode(graph, query, result) {
751
727
  } else if (isBranch(graph) && isBranch(query)) {
752
728
  const { known, unknown } = slice(graph.children, query.children, root);
753
729
  if (known)
754
- result.addKnown(__spreadProps(__spreadValues({}, graph), { children: known }));
730
+ result.addKnown({ ...graph, children: known });
755
731
  if (unknown)
756
- result.addUnknown(__spreadProps(__spreadValues({}, query), { children: unknown }));
732
+ result.addUnknown({ ...query, children: unknown });
757
733
  } else if (isLink(graph)) {
758
734
  result.addKnown(graph);
759
735
  if (graph.prefix && isRange(query)) {
760
736
  result.addLinked(wrap([query], graph.path, version, true));
761
737
  } else {
762
- result.addLinked(wrap(query.children || query.value, graph.path, version, graph.prefix || query.prefix));
738
+ result.addLinked(
739
+ wrap(
740
+ query.children || query.value,
741
+ graph.path,
742
+ version,
743
+ graph.prefix || query.prefix
744
+ )
745
+ );
763
746
  }
764
747
  } else if (isBranch(graph)) {
765
748
  result.addKnown(graph);
766
749
  } else if (isBranch(query)) {
767
- const { known } = slice([{ key: "", end: "\uFFFF", version: graph.version }], query.children);
750
+ const { known } = slice(
751
+ [{ key: "", end: "\uFFFF", version: graph.version }],
752
+ query.children
753
+ );
768
754
  result.addKnown({ key, version: graph.version, children: known });
769
755
  } else {
770
756
  result.addKnown(graph);
@@ -776,9 +762,9 @@ function sliceRange(graph, query, result) {
776
762
  if (graph[0].key === "" && graph[0].prefix && graph[0].children) {
777
763
  const { known, unknown } = slice(graph[0].children, [query], result.root);
778
764
  if (known)
779
- result.addKnown(__spreadProps(__spreadValues({}, graph[0]), { children: known }));
765
+ result.addKnown({ ...graph[0], children: known });
780
766
  if (unknown)
781
- result.addUnknown(__spreadProps(__spreadValues({}, query[0]), { children: unknown }));
767
+ result.addUnknown({ ...query[0], children: unknown });
782
768
  return;
783
769
  }
784
770
  if (key < end) {
@@ -789,7 +775,7 @@ function sliceRange(graph, query, result) {
789
775
  if (isRange(node)) {
790
776
  result.addKnown(getOverlap(node, key, end));
791
777
  } else {
792
- sliceNode(node, __spreadProps(__spreadValues({}, query), { key }), result);
778
+ sliceNode(node, { ...query, key }, result);
793
779
  limit--;
794
780
  }
795
781
  key = keyAfter(node.end || node.key);
@@ -802,24 +788,25 @@ function sliceRange(graph, query, result) {
802
788
  if (isRange(node)) {
803
789
  result.addKnown(getOverlap(node, end, key));
804
790
  } else {
805
- sliceNode(node, __spreadProps(__spreadValues({}, query), { key }), result);
791
+ sliceNode(node, { ...query, key }, result);
806
792
  limit--;
807
793
  }
808
794
  key = keyBefore(node.key);
809
795
  }
810
796
  }
811
797
  if (limit && (step < 0 ? key > end : key < end)) {
812
- const unknown = __spreadProps(__spreadValues({}, query), { key, end, limit });
798
+ const unknown = { ...query, key, end, limit };
813
799
  result.addUnknown(unknown);
814
800
  }
815
801
  }
816
802
  function getOverlap(node, key, end) {
817
803
  if (node.key >= key && node.end <= end)
818
804
  return node;
819
- return __spreadProps(__spreadValues({}, node), {
805
+ return {
806
+ ...node,
820
807
  key: node.key > key ? node.key : key,
821
808
  end: node.end < end ? node.end : end
822
- });
809
+ };
823
810
  }
824
811
  function sieve(current, changes, result = []) {
825
812
  let index = 0;
@@ -887,9 +874,9 @@ function mergeRanges(base, node) {
887
874
  if (node.version < base.version)
888
875
  [node, base] = [base, node];
889
876
  return [
890
- base.key < node.key && __spreadProps(__spreadValues({}, base), { end: keyBefore(node.key) }),
877
+ base.key < node.key && { ...base, end: keyBefore(node.key) },
891
878
  node,
892
- base.end > node.end && __spreadProps(__spreadValues({}, base), { key: keyAfter(node.end) })
879
+ base.end > node.end && { ...base, key: keyAfter(node.end) }
893
880
  ].filter(Boolean);
894
881
  }
895
882
  function insertNode(current, change, result, start = 0) {
@@ -911,9 +898,9 @@ function insertNodeIntoRange(current, index, change, result) {
911
898
  return;
912
899
  result.push(newChange);
913
900
  const insertions = [
914
- range.key < key && __spreadProps(__spreadValues({}, range), { end: keyBefore(key) }),
901
+ range.key < key && { ...range, end: keyBefore(key) },
915
902
  newNode,
916
- range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
903
+ range.end > key && { ...range, key: keyAfter(key) }
917
904
  ].filter(Boolean);
918
905
  current.splice(index, 1, ...insertions);
919
906
  return index + insertions.length - 1;
@@ -925,7 +912,7 @@ function updateNode(current, index, change, result) {
925
912
  node.version = change.version;
926
913
  sieve(node.children, change.children, nextResult);
927
914
  if (nextResult.length)
928
- result.push(__spreadProps(__spreadValues({}, change), { children: nextResult }));
915
+ result.push({ ...change, children: nextResult });
929
916
  } else if (isBranch(node)) {
930
917
  const newNode = getNewerNode(node, change);
931
918
  current[index] = newNode || change;
@@ -960,15 +947,17 @@ function getNewerNode(node, base) {
960
947
  const emptyNode = { key: "", end: "\uFFFF", version: base.version };
961
948
  const children = [emptyNode];
962
949
  sieve(children, node.children);
963
- return children.length === 1 && children[0] === emptyNode ? null : __spreadProps(__spreadValues({}, node), { children });
950
+ return children.length === 1 && children[0] === emptyNode ? null : { ...node, children };
964
951
  } else {
965
952
  return node.version >= base.version ? node : null;
966
953
  }
967
954
  }
968
955
  function getNewerChange(node, base) {
969
956
  if (isBranch(node)) {
970
- const children = node.children.filter((child) => getNewerChange(child, base));
971
- return children.length && __spreadProps(__spreadValues({}, node), { children });
957
+ const children = node.children.filter(
958
+ (child) => getNewerChange(child, base)
959
+ );
960
+ return children.length && { ...node, children };
972
961
  } else {
973
962
  return node.version >= base.version ? node : null;
974
963
  }
@@ -1058,21 +1047,24 @@ function decode(nodes = [], { isGraph } = {}) {
1058
1047
  pushResult(decodeLeafNode(node));
1059
1048
  }
1060
1049
  if (allNums || allStrs) {
1061
- result = result.reduce((collection, item) => {
1062
- if (Array.isArray(item)) {
1063
- collection[item.$key] = item;
1050
+ result = result.reduce(
1051
+ (collection, item) => {
1052
+ if (Array.isArray(item)) {
1053
+ collection[item.$key] = item;
1054
+ delete item.$key;
1055
+ return collection;
1056
+ }
1057
+ const { $key, $val } = item;
1064
1058
  delete item.$key;
1059
+ delete item.$val;
1060
+ if (typeof $val === "object") {
1061
+ Object.defineProperty($val, "$val", { value: true });
1062
+ }
1063
+ collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
1065
1064
  return collection;
1066
- }
1067
- const { $key, $val } = item;
1068
- delete item.$key;
1069
- delete item.$val;
1070
- if (typeof $val === "object") {
1071
- Object.defineProperty($val, "$val", { value: true });
1072
- }
1073
- collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
1074
- return collection;
1075
- }, allStrs ? {} : []);
1065
+ },
1066
+ allStrs ? {} : []
1067
+ );
1076
1068
  }
1077
1069
  if (isGraph && putRanges.length) {
1078
1070
  if (putRanges[0].key === "" && putRanges[0].end === "\uFFFF") {
@@ -1115,7 +1107,7 @@ function decode(nodes = [], { isGraph } = {}) {
1115
1107
  if (!splitArgs(child.$key)[0]) {
1116
1108
  child.$key = { $cursor: child.$key };
1117
1109
  }
1118
- child.$key = __spreadValues(__spreadValues({}, args), child.$key);
1110
+ child.$key = { ...args, ...child.$key };
1119
1111
  }
1120
1112
  return children;
1121
1113
  }
@@ -1158,13 +1150,16 @@ function decorate(rootGraph, rootQuery) {
1158
1150
  query = [query];
1159
1151
  let graph;
1160
1152
  if (query.$ref) {
1161
- const _a = query, { $ref } = _a, props = __objRest(_a, ["$ref"]);
1153
+ const { $ref, ...props } = query;
1162
1154
  const [range, filter] = splitRef($ref);
1163
1155
  const path = encode$1($ref);
1164
1156
  const targetPlumGraph = unwrap(rootGraph, path);
1165
1157
  if (range)
1166
1158
  targetPlumGraph[PRE] = filter;
1167
- graph = construct(targetPlumGraph, range ? __spreadValues({ $key: range }, props) : props);
1159
+ graph = construct(
1160
+ targetPlumGraph,
1161
+ range ? { $key: range, ...props } : props
1162
+ );
1168
1163
  Object.defineProperty(graph, "$ref", { value: $ref });
1169
1164
  } else if (Array.isArray(query)) {
1170
1165
  let pageKey;
@@ -1172,13 +1167,15 @@ function decorate(rootGraph, rootQuery) {
1172
1167
  if (!(item == null ? void 0 : item.$key)) {
1173
1168
  return construct(descend(plumGraph, i), item);
1174
1169
  }
1175
- const _a2 = item, { $key, $chi } = _a2, props = __objRest(_a2, ["$key", "$chi"]);
1170
+ const { $key, $chi, ...props } = item;
1176
1171
  const subQuery = $chi || (isEmpty(props) ? 1 : props);
1177
1172
  if (!isPlainObject($key) || !splitArgs($key)[0]) {
1178
1173
  return construct(descend(plumGraph, $key), subQuery);
1179
1174
  }
1180
1175
  if (pageKey) {
1181
- throw Error("decorate.multi_range_query:" + JSON.stringify({ $key, pageKey }));
1176
+ throw Error(
1177
+ "decorate.multi_range_query:" + JSON.stringify({ $key, pageKey })
1178
+ );
1182
1179
  }
1183
1180
  pageKey = $key;
1184
1181
  const children = slice2(plumGraph, $key);
@@ -1186,7 +1183,7 @@ function decorate(rootGraph, rootQuery) {
1186
1183
  const $key2 = decode$2(node);
1187
1184
  const subResult = construct(getValue(node), subQuery);
1188
1185
  if (typeof subResult === "object") {
1189
- subResult.$key = children[PRE] ? __spreadProps(__spreadValues({}, children[PRE]), { $cursor: $key2 }) : $key2;
1186
+ subResult.$key = children[PRE] ? { ...children[PRE], $cursor: $key2 } : $key2;
1190
1187
  }
1191
1188
  return subResult;
1192
1189
  });
@@ -1204,7 +1201,7 @@ function decorate(rootGraph, rootQuery) {
1204
1201
  } else if (typeof plumGraph !== "object" || !plumGraph) {
1205
1202
  graph = plumGraph;
1206
1203
  } else if (plumGraph[IS_VAL]) {
1207
- graph = Array.isArray(plumGraph) ? plumGraph.slice(0) : __spreadValues({}, plumGraph);
1204
+ graph = Array.isArray(plumGraph) ? plumGraph.slice(0) : { ...plumGraph };
1208
1205
  graph.$val = true;
1209
1206
  } else if (Array.isArray(plumGraph)) {
1210
1207
  graph = decodeGraph(plumGraph);
@@ -1285,9 +1282,9 @@ function addPageMeta(graph, args) {
1285
1282
  Object.assign(graph, { $page: args, $prev: null, $next: null });
1286
1283
  return;
1287
1284
  }
1288
- const [_a, ..._b] = splitArgs(args), _c = _a, { $first, $last } = _c, bounds = __objRest(_c, ["$first", "$last"]), [filter] = _b;
1285
+ const [{ $first, $last, ...bounds }, filter] = splitArgs(args);
1289
1286
  const count = $first || $last;
1290
- const $page = __spreadProps(__spreadValues(__spreadValues({}, filter), bounds), { $all: true });
1287
+ const $page = { ...filter, ...bounds, $all: true };
1291
1288
  if (graph.length === count) {
1292
1289
  if ($first) {
1293
1290
  const boundKey = graph[graph.length - 1].$key;
@@ -1299,8 +1296,8 @@ function addPageMeta(graph, args) {
1299
1296
  delete $page.$after;
1300
1297
  }
1301
1298
  }
1302
- const $prev = isDef($page.$after) ? __spreadProps(__spreadValues({}, filter), { $last: count, $until: $page.$after }) : isDef($page.$since) ? __spreadProps(__spreadValues({}, filter), { $last: count, $before: $page.$since }) : null;
1303
- let $next = isDef($page.$before) ? __spreadProps(__spreadValues({}, filter), { $first: count, $since: $page.$before }) : isDef($page.$until) ? __spreadProps(__spreadValues({}, filter), { $first: count, $after: $page.$until }) : null;
1299
+ const $prev = isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } : isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } : null;
1300
+ let $next = isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } : isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } : null;
1304
1301
  Object.assign(graph, { $page, $next, $prev });
1305
1302
  }
1306
1303
  function serialize(obj) {
@@ -1315,35 +1312,47 @@ function encode(value, { version, isGraph } = {}) {
1315
1312
  const links = [];
1316
1313
  function pushLink($ref, $ver, props, $val, $chi) {
1317
1314
  const [range, _] = splitRef($ref);
1318
- let children = !isEmpty(props) ? makeNode(range ? [__spreadValues({ $key: range }, props)] : props, void 0, $ver).children : isDef($chi) ? makeNode(range ? [{ $key: range, $chi }] : $chi, void 0, $ver).children : isDef($val) ? $val : isGraph ? void 0 : 1;
1315
+ let children = !isEmpty(props) ? makeNode(
1316
+ range ? [{ $key: range, ...props }] : props,
1317
+ void 0,
1318
+ $ver
1319
+ ).children : isDef($chi) ? makeNode(
1320
+ range ? [{ $key: range, $chi }] : $chi,
1321
+ void 0,
1322
+ $ver
1323
+ ).children : isDef($val) ? $val : isGraph ? void 0 : 1;
1319
1324
  if (children) {
1320
1325
  links.push(wrap(children, encode$1($ref), $ver, !!range)[0]);
1321
1326
  }
1322
1327
  }
1323
1328
  const combine = isGraph ? merge : add;
1324
1329
  function makeNode(object, key, ver) {
1325
- var _b;
1330
+ var _a2;
1326
1331
  if (!isDef(object))
1327
1332
  return;
1328
1333
  if (typeof object === "object" && object && isEmpty(object))
1329
1334
  return;
1330
- const _a2 = object || {}, { $key, $ver, $ref, $val, $chi, $put } = _a2, props = __objRest(_a2, ["$key", "$ver", "$ref", "$val", "$chi", "$put"]);
1335
+ const { $key, $ver, $ref, $val, $chi, $put, ...props } = object || {};
1331
1336
  if (isDef($ver))
1332
1337
  ver = $ver;
1333
1338
  if (isPlainObject($key)) {
1334
1339
  const [page, filter] = splitArgs($key);
1335
1340
  if (isGraph && page && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props))) {
1336
- const node2 = makeNode(__spreadProps(__spreadValues({}, object), { $key: filter || "" }), key, ver);
1341
+ const node2 = makeNode({ ...object, $key: filter || "" }, key, ver);
1337
1342
  node2.prefix = true;
1338
1343
  return node2;
1339
1344
  }
1340
1345
  if ((!isDef(key) || Number.isInteger(key)) && page && (filter || isDef(page.$cursor))) {
1341
- const node2 = makeNode({
1342
- $key: filter || "",
1343
- $chi: [
1344
- __spreadProps(__spreadValues({}, object), { $key: isDef(page.$cursor) ? page.$cursor : page })
1345
- ]
1346
- }, key, ver);
1346
+ const node2 = makeNode(
1347
+ {
1348
+ $key: filter || "",
1349
+ $chi: [
1350
+ { ...object, $key: isDef(page.$cursor) ? page.$cursor : page }
1351
+ ]
1352
+ },
1353
+ key,
1354
+ ver
1355
+ );
1347
1356
  node2.prefix = true;
1348
1357
  return node2;
1349
1358
  }
@@ -1410,7 +1419,7 @@ function encode(value, { version, isGraph } = {}) {
1410
1419
  if (isGraph && isDef(putQuery)) {
1411
1420
  node.children = finalize(node.children || [], putQuery, node.version);
1412
1421
  }
1413
- if (((_b = node.children) == null ? void 0 : _b.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1422
+ if (((_a2 = node.children) == null ? void 0 : _a2.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1414
1423
  return node;
1415
1424
  }
1416
1425
  }
@@ -1442,10 +1451,10 @@ async function* mergeStreams(...streams) {
1442
1451
  merge(merged, value);
1443
1452
  yield merged;
1444
1453
  }
1445
- yield* mergeIterators__default["default"](streams);
1454
+ yield* mergeIterators__default.default(streams);
1446
1455
  }
1447
1456
  function makeWatcher() {
1448
- const listeners = new Set();
1457
+ const listeners = /* @__PURE__ */ new Set();
1449
1458
  function write(change) {
1450
1459
  for (const push of listeners)
1451
1460
  push(change);
@@ -1501,7 +1510,7 @@ function wrapObject(object, path) {
1501
1510
  } else if (Array.isArray(object)) {
1502
1511
  object = [{ $key, $chi: object }];
1503
1512
  } else {
1504
- object = [__spreadValues({ $key }, object)];
1513
+ object = [{ $key, ...object }];
1505
1514
  }
1506
1515
  }
1507
1516
  return object;
@@ -1526,8 +1535,8 @@ function unwrapObject(object, path) {
1526
1535
  if (page && !page.$cursor) {
1527
1536
  return object;
1528
1537
  } else {
1529
- const target = (page == null ? void 0 : page.$cursor) ? __spreadProps(__spreadValues({}, filter), { $cursor: page.$cursor }) : filter;
1530
- object = object.find(({ $key: $key2 }) => isEqual__default["default"]($key2, target));
1538
+ const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
1539
+ object = object.find(({ $key: $key2 }) => isEqual__default.default($key2, target));
1531
1540
  }
1532
1541
  }
1533
1542
  }
package/index.mjs CHANGED
@@ -1,34 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
1
  import { customAlphabet } from "nanoid/non-secure";
33
2
  import mergeIterators from "merge-async-iterators";
34
3
  import { makeStream } from "@graffy/stream";
@@ -71,7 +40,7 @@ function decode$5(u8Arr) {
71
40
  }
72
41
  return view.getFloat64(0);
73
42
  }
74
- var alpha = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
43
+ const alpha = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
75
44
  function getByte(view, offset) {
76
45
  return offset < view.byteLength ? view.getUint8(offset) : 0;
77
46
  }
@@ -155,7 +124,10 @@ function encode$3(value) {
155
124
  const parts = encodeParts(value);
156
125
  while (parts[parts.length - 1] === END)
157
126
  parts.pop();
158
- const length = parts.reduce((sum, part) => sum + (typeof part === "number" ? 1 : part.length), 0);
127
+ const length = parts.reduce(
128
+ (sum, part) => sum + (typeof part === "number" ? 1 : part.length),
129
+ 0
130
+ );
159
131
  const buffer = new Uint8Array(length);
160
132
  let i = 0;
161
133
  for (const part of parts) {
@@ -169,7 +141,7 @@ function encode$3(value) {
169
141
  }
170
142
  return encode$4(buffer);
171
143
  }
172
- const nextKey = new WeakMap();
144
+ const nextKey = /* @__PURE__ */ new WeakMap();
173
145
  function decode$3(key) {
174
146
  let i = 0;
175
147
  const buffer = decode$4(key, 0);
@@ -269,8 +241,7 @@ function keyAfter(key) {
269
241
  const l = key.length - 1;
270
242
  return key.charCodeAt(l) === 65535 ? key.substr(0, l - 1) + String.fromCharCode(key.charCodeAt(l - 1) + 1) : key + "\0";
271
243
  }
272
- function err(message, _a = {}) {
273
- var _b = _a, { cause } = _b, args = __objRest(_b, ["cause"]);
244
+ function err(message, { cause, ...args } = {}) {
274
245
  const e = new Error(message + (args ? " " + JSON.stringify(args) : ""));
275
246
  e.cause = cause;
276
247
  throw e;
@@ -348,7 +319,7 @@ function encode$2(arg) {
348
319
  errIf("page_and_filter", page && filter, arg);
349
320
  if (!page)
350
321
  return { key: maybeEncode(filter || {}) };
351
- const _a = page, { $cursor } = _a, range = __objRest(_a, ["$cursor"]);
322
+ const { $cursor, ...range } = page;
352
323
  const { $first, $all, $last, $after, $before, $since, $until } = range;
353
324
  const hasRange = !isEmpty(range);
354
325
  errIf("first_and_last", isDef($first) && isDef($last), arg);
@@ -443,15 +414,20 @@ function splitRef($ref) {
443
414
  return [];
444
415
  return splitArgs(tail);
445
416
  }
446
- var id = customAlphabet(alpha, 20);
417
+ const id = customAlphabet(alpha, 20);
447
418
  function findFirst(children, target, first, last) {
448
- return find(children, ({ key, end }) => {
449
- if (key === target || end && key < target && end >= target)
450
- return 0;
451
- if (key < target)
452
- return -1;
453
- return 1;
454
- }, first, last);
419
+ return find(
420
+ children,
421
+ ({ key, end }) => {
422
+ if (key === target || end && key < target && end >= target)
423
+ return 0;
424
+ if (key < target)
425
+ return -1;
426
+ return 1;
427
+ },
428
+ first,
429
+ last
430
+ );
455
431
  }
456
432
  function findLast(children, end, first, last) {
457
433
  const ix = findFirst(children, end, first, last);
@@ -522,7 +498,7 @@ function compareValue(a, b) {
522
498
  return a < b ? -1 : 1;
523
499
  }
524
500
  function clone(node) {
525
- const copy = __spreadValues({}, node);
501
+ const copy = { ...node };
526
502
  if (node.children)
527
503
  copy.children = node.children.map((child) => clone(child));
528
504
  return copy;
@@ -556,9 +532,9 @@ function mergeRanges$1(base, node) {
556
532
  if (node.version < base.version)
557
533
  [node, base] = [base, node];
558
534
  return [
559
- base.key < node.key && __spreadProps(__spreadValues({}, base), { end: keyBefore(node.key) }),
535
+ base.key < node.key && { ...base, end: keyBefore(node.key) },
560
536
  node,
561
- base.end > node.end && __spreadProps(__spreadValues({}, base), { key: keyAfter(node.end) })
537
+ base.end > node.end && { ...base, key: keyAfter(node.end) }
562
538
  ].filter(Boolean);
563
539
  }
564
540
  function insertNode$1(current, change, start = 0) {
@@ -581,9 +557,9 @@ function insertNodeIntoRange$1(current, index, change) {
581
557
  if (!newChange)
582
558
  return;
583
559
  const insertions = [
584
- range.key < key && __spreadProps(__spreadValues({}, range), { end: keyBefore(key) }),
560
+ range.key < key && { ...range, end: keyBefore(key) },
585
561
  newChange,
586
- range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
562
+ range.end > key && { ...range, key: keyAfter(key) }
587
563
  ].filter(Boolean);
588
564
  current.splice(index, 1, ...insertions);
589
565
  return index + insertions.length - 1;
@@ -609,14 +585,14 @@ function getNewer(node, base) {
609
585
  if (isBranch(node)) {
610
586
  const children = [{ key: "", end: "\uFFFF", version }];
611
587
  merge(children, node.children);
612
- return children.length === 1 ? null : __spreadProps(__spreadValues({}, node), { children });
588
+ return children.length === 1 ? null : { ...node, children };
613
589
  } else {
614
590
  return node.version >= version ? node : null;
615
591
  }
616
592
  }
617
593
  const IS_VAL = Symbol("IS_VAL");
618
594
  function wrapValue(value, path, version = 0) {
619
- const node = __spreadProps(__spreadValues({}, encode$2(path[path.length - 1])), { value, version });
595
+ const node = { ...encode$2(path[path.length - 1]), value, version };
620
596
  return wrap([node], path.slice(0, -1), version);
621
597
  }
622
598
  function wrap(children, path, version = 0, prefix = false) {
@@ -626,16 +602,16 @@ function wrap(children, path, version = 0, prefix = false) {
626
602
  return children;
627
603
  let i = path.length - 1;
628
604
  if (!Array.isArray(children)) {
629
- children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { value: children, version })];
605
+ children = [{ ...encode$2(path[i--]), value: children, version }];
630
606
  } else {
631
607
  if (!children.length)
632
608
  return;
633
- children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { version, children })];
609
+ children = [{ ...encode$2(path[i--]), version, children }];
634
610
  }
635
611
  if (prefix)
636
612
  children[0].prefix = true;
637
613
  while (i >= 0)
638
- children = [__spreadProps(__spreadValues({}, encode$2(path[i--])), { version, children })];
614
+ children = [{ ...encode$2(path[i--]), version, children }];
639
615
  return children;
640
616
  }
641
617
  function unwrap(tree, path) {
@@ -686,7 +662,7 @@ function remove(children, path) {
686
662
  const filteredChildren = remove(node.children, path.slice(1));
687
663
  if (filteredChildren === children)
688
664
  return children;
689
- const filteredNode = filteredChildren.length ? __spreadProps(__spreadValues({}, node), { children: filteredChildren }) : [];
665
+ const filteredNode = filteredChildren.length ? { ...node, children: filteredChildren } : [];
690
666
  return children.slice(0, ix).concat(filteredNode, children.slice(ix + 1));
691
667
  }
692
668
  class Result {
@@ -735,7 +711,10 @@ function sliceNode(graph, query, result) {
735
711
  result.addUnknown(query);
736
712
  } else if (isRange(graph)) {
737
713
  if (isBranch(query)) {
738
- const { known } = slice([{ key: "", end: "\uFFFF", version: graph.version }], query.children);
714
+ const { known } = slice(
715
+ [{ key: "", end: "\uFFFF", version: graph.version }],
716
+ query.children
717
+ );
739
718
  result.addKnown({ key, version: graph.version, children: known });
740
719
  } else {
741
720
  result.addKnown({ key, end: key, version: graph.version });
@@ -743,20 +722,30 @@ function sliceNode(graph, query, result) {
743
722
  } else if (isBranch(graph) && isBranch(query)) {
744
723
  const { known, unknown } = slice(graph.children, query.children, root);
745
724
  if (known)
746
- result.addKnown(__spreadProps(__spreadValues({}, graph), { children: known }));
725
+ result.addKnown({ ...graph, children: known });
747
726
  if (unknown)
748
- result.addUnknown(__spreadProps(__spreadValues({}, query), { children: unknown }));
727
+ result.addUnknown({ ...query, children: unknown });
749
728
  } else if (isLink(graph)) {
750
729
  result.addKnown(graph);
751
730
  if (graph.prefix && isRange(query)) {
752
731
  result.addLinked(wrap([query], graph.path, version, true));
753
732
  } else {
754
- result.addLinked(wrap(query.children || query.value, graph.path, version, graph.prefix || query.prefix));
733
+ result.addLinked(
734
+ wrap(
735
+ query.children || query.value,
736
+ graph.path,
737
+ version,
738
+ graph.prefix || query.prefix
739
+ )
740
+ );
755
741
  }
756
742
  } else if (isBranch(graph)) {
757
743
  result.addKnown(graph);
758
744
  } else if (isBranch(query)) {
759
- const { known } = slice([{ key: "", end: "\uFFFF", version: graph.version }], query.children);
745
+ const { known } = slice(
746
+ [{ key: "", end: "\uFFFF", version: graph.version }],
747
+ query.children
748
+ );
760
749
  result.addKnown({ key, version: graph.version, children: known });
761
750
  } else {
762
751
  result.addKnown(graph);
@@ -768,9 +757,9 @@ function sliceRange(graph, query, result) {
768
757
  if (graph[0].key === "" && graph[0].prefix && graph[0].children) {
769
758
  const { known, unknown } = slice(graph[0].children, [query], result.root);
770
759
  if (known)
771
- result.addKnown(__spreadProps(__spreadValues({}, graph[0]), { children: known }));
760
+ result.addKnown({ ...graph[0], children: known });
772
761
  if (unknown)
773
- result.addUnknown(__spreadProps(__spreadValues({}, query[0]), { children: unknown }));
762
+ result.addUnknown({ ...query[0], children: unknown });
774
763
  return;
775
764
  }
776
765
  if (key < end) {
@@ -781,7 +770,7 @@ function sliceRange(graph, query, result) {
781
770
  if (isRange(node)) {
782
771
  result.addKnown(getOverlap(node, key, end));
783
772
  } else {
784
- sliceNode(node, __spreadProps(__spreadValues({}, query), { key }), result);
773
+ sliceNode(node, { ...query, key }, result);
785
774
  limit--;
786
775
  }
787
776
  key = keyAfter(node.end || node.key);
@@ -794,24 +783,25 @@ function sliceRange(graph, query, result) {
794
783
  if (isRange(node)) {
795
784
  result.addKnown(getOverlap(node, end, key));
796
785
  } else {
797
- sliceNode(node, __spreadProps(__spreadValues({}, query), { key }), result);
786
+ sliceNode(node, { ...query, key }, result);
798
787
  limit--;
799
788
  }
800
789
  key = keyBefore(node.key);
801
790
  }
802
791
  }
803
792
  if (limit && (step < 0 ? key > end : key < end)) {
804
- const unknown = __spreadProps(__spreadValues({}, query), { key, end, limit });
793
+ const unknown = { ...query, key, end, limit };
805
794
  result.addUnknown(unknown);
806
795
  }
807
796
  }
808
797
  function getOverlap(node, key, end) {
809
798
  if (node.key >= key && node.end <= end)
810
799
  return node;
811
- return __spreadProps(__spreadValues({}, node), {
800
+ return {
801
+ ...node,
812
802
  key: node.key > key ? node.key : key,
813
803
  end: node.end < end ? node.end : end
814
- });
804
+ };
815
805
  }
816
806
  function sieve(current, changes, result = []) {
817
807
  let index = 0;
@@ -879,9 +869,9 @@ function mergeRanges(base, node) {
879
869
  if (node.version < base.version)
880
870
  [node, base] = [base, node];
881
871
  return [
882
- base.key < node.key && __spreadProps(__spreadValues({}, base), { end: keyBefore(node.key) }),
872
+ base.key < node.key && { ...base, end: keyBefore(node.key) },
883
873
  node,
884
- base.end > node.end && __spreadProps(__spreadValues({}, base), { key: keyAfter(node.end) })
874
+ base.end > node.end && { ...base, key: keyAfter(node.end) }
885
875
  ].filter(Boolean);
886
876
  }
887
877
  function insertNode(current, change, result, start = 0) {
@@ -903,9 +893,9 @@ function insertNodeIntoRange(current, index, change, result) {
903
893
  return;
904
894
  result.push(newChange);
905
895
  const insertions = [
906
- range.key < key && __spreadProps(__spreadValues({}, range), { end: keyBefore(key) }),
896
+ range.key < key && { ...range, end: keyBefore(key) },
907
897
  newNode,
908
- range.end > key && __spreadProps(__spreadValues({}, range), { key: keyAfter(key) })
898
+ range.end > key && { ...range, key: keyAfter(key) }
909
899
  ].filter(Boolean);
910
900
  current.splice(index, 1, ...insertions);
911
901
  return index + insertions.length - 1;
@@ -917,7 +907,7 @@ function updateNode(current, index, change, result) {
917
907
  node.version = change.version;
918
908
  sieve(node.children, change.children, nextResult);
919
909
  if (nextResult.length)
920
- result.push(__spreadProps(__spreadValues({}, change), { children: nextResult }));
910
+ result.push({ ...change, children: nextResult });
921
911
  } else if (isBranch(node)) {
922
912
  const newNode = getNewerNode(node, change);
923
913
  current[index] = newNode || change;
@@ -952,15 +942,17 @@ function getNewerNode(node, base) {
952
942
  const emptyNode = { key: "", end: "\uFFFF", version: base.version };
953
943
  const children = [emptyNode];
954
944
  sieve(children, node.children);
955
- return children.length === 1 && children[0] === emptyNode ? null : __spreadProps(__spreadValues({}, node), { children });
945
+ return children.length === 1 && children[0] === emptyNode ? null : { ...node, children };
956
946
  } else {
957
947
  return node.version >= base.version ? node : null;
958
948
  }
959
949
  }
960
950
  function getNewerChange(node, base) {
961
951
  if (isBranch(node)) {
962
- const children = node.children.filter((child) => getNewerChange(child, base));
963
- return children.length && __spreadProps(__spreadValues({}, node), { children });
952
+ const children = node.children.filter(
953
+ (child) => getNewerChange(child, base)
954
+ );
955
+ return children.length && { ...node, children };
964
956
  } else {
965
957
  return node.version >= base.version ? node : null;
966
958
  }
@@ -1050,21 +1042,24 @@ function decode(nodes = [], { isGraph } = {}) {
1050
1042
  pushResult(decodeLeafNode(node));
1051
1043
  }
1052
1044
  if (allNums || allStrs) {
1053
- result = result.reduce((collection, item) => {
1054
- if (Array.isArray(item)) {
1055
- collection[item.$key] = item;
1045
+ result = result.reduce(
1046
+ (collection, item) => {
1047
+ if (Array.isArray(item)) {
1048
+ collection[item.$key] = item;
1049
+ delete item.$key;
1050
+ return collection;
1051
+ }
1052
+ const { $key, $val } = item;
1056
1053
  delete item.$key;
1054
+ delete item.$val;
1055
+ if (typeof $val === "object") {
1056
+ Object.defineProperty($val, "$val", { value: true });
1057
+ }
1058
+ collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
1057
1059
  return collection;
1058
- }
1059
- const { $key, $val } = item;
1060
- delete item.$key;
1061
- delete item.$val;
1062
- if (typeof $val === "object") {
1063
- Object.defineProperty($val, "$val", { value: true });
1064
- }
1065
- collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
1066
- return collection;
1067
- }, allStrs ? {} : []);
1060
+ },
1061
+ allStrs ? {} : []
1062
+ );
1068
1063
  }
1069
1064
  if (isGraph && putRanges.length) {
1070
1065
  if (putRanges[0].key === "" && putRanges[0].end === "\uFFFF") {
@@ -1107,7 +1102,7 @@ function decode(nodes = [], { isGraph } = {}) {
1107
1102
  if (!splitArgs(child.$key)[0]) {
1108
1103
  child.$key = { $cursor: child.$key };
1109
1104
  }
1110
- child.$key = __spreadValues(__spreadValues({}, args), child.$key);
1105
+ child.$key = { ...args, ...child.$key };
1111
1106
  }
1112
1107
  return children;
1113
1108
  }
@@ -1150,13 +1145,16 @@ function decorate(rootGraph, rootQuery) {
1150
1145
  query = [query];
1151
1146
  let graph;
1152
1147
  if (query.$ref) {
1153
- const _a = query, { $ref } = _a, props = __objRest(_a, ["$ref"]);
1148
+ const { $ref, ...props } = query;
1154
1149
  const [range, filter] = splitRef($ref);
1155
1150
  const path = encode$1($ref);
1156
1151
  const targetPlumGraph = unwrap(rootGraph, path);
1157
1152
  if (range)
1158
1153
  targetPlumGraph[PRE] = filter;
1159
- graph = construct(targetPlumGraph, range ? __spreadValues({ $key: range }, props) : props);
1154
+ graph = construct(
1155
+ targetPlumGraph,
1156
+ range ? { $key: range, ...props } : props
1157
+ );
1160
1158
  Object.defineProperty(graph, "$ref", { value: $ref });
1161
1159
  } else if (Array.isArray(query)) {
1162
1160
  let pageKey;
@@ -1164,13 +1162,15 @@ function decorate(rootGraph, rootQuery) {
1164
1162
  if (!(item == null ? void 0 : item.$key)) {
1165
1163
  return construct(descend(plumGraph, i), item);
1166
1164
  }
1167
- const _a2 = item, { $key, $chi } = _a2, props = __objRest(_a2, ["$key", "$chi"]);
1165
+ const { $key, $chi, ...props } = item;
1168
1166
  const subQuery = $chi || (isEmpty(props) ? 1 : props);
1169
1167
  if (!isPlainObject($key) || !splitArgs($key)[0]) {
1170
1168
  return construct(descend(plumGraph, $key), subQuery);
1171
1169
  }
1172
1170
  if (pageKey) {
1173
- throw Error("decorate.multi_range_query:" + JSON.stringify({ $key, pageKey }));
1171
+ throw Error(
1172
+ "decorate.multi_range_query:" + JSON.stringify({ $key, pageKey })
1173
+ );
1174
1174
  }
1175
1175
  pageKey = $key;
1176
1176
  const children = slice2(plumGraph, $key);
@@ -1178,7 +1178,7 @@ function decorate(rootGraph, rootQuery) {
1178
1178
  const $key2 = decode$2(node);
1179
1179
  const subResult = construct(getValue(node), subQuery);
1180
1180
  if (typeof subResult === "object") {
1181
- subResult.$key = children[PRE] ? __spreadProps(__spreadValues({}, children[PRE]), { $cursor: $key2 }) : $key2;
1181
+ subResult.$key = children[PRE] ? { ...children[PRE], $cursor: $key2 } : $key2;
1182
1182
  }
1183
1183
  return subResult;
1184
1184
  });
@@ -1196,7 +1196,7 @@ function decorate(rootGraph, rootQuery) {
1196
1196
  } else if (typeof plumGraph !== "object" || !plumGraph) {
1197
1197
  graph = plumGraph;
1198
1198
  } else if (plumGraph[IS_VAL]) {
1199
- graph = Array.isArray(plumGraph) ? plumGraph.slice(0) : __spreadValues({}, plumGraph);
1199
+ graph = Array.isArray(plumGraph) ? plumGraph.slice(0) : { ...plumGraph };
1200
1200
  graph.$val = true;
1201
1201
  } else if (Array.isArray(plumGraph)) {
1202
1202
  graph = decodeGraph(plumGraph);
@@ -1277,9 +1277,9 @@ function addPageMeta(graph, args) {
1277
1277
  Object.assign(graph, { $page: args, $prev: null, $next: null });
1278
1278
  return;
1279
1279
  }
1280
- const [_a, ..._b] = splitArgs(args), _c = _a, { $first, $last } = _c, bounds = __objRest(_c, ["$first", "$last"]), [filter] = _b;
1280
+ const [{ $first, $last, ...bounds }, filter] = splitArgs(args);
1281
1281
  const count = $first || $last;
1282
- const $page = __spreadProps(__spreadValues(__spreadValues({}, filter), bounds), { $all: true });
1282
+ const $page = { ...filter, ...bounds, $all: true };
1283
1283
  if (graph.length === count) {
1284
1284
  if ($first) {
1285
1285
  const boundKey = graph[graph.length - 1].$key;
@@ -1291,8 +1291,8 @@ function addPageMeta(graph, args) {
1291
1291
  delete $page.$after;
1292
1292
  }
1293
1293
  }
1294
- const $prev = isDef($page.$after) ? __spreadProps(__spreadValues({}, filter), { $last: count, $until: $page.$after }) : isDef($page.$since) ? __spreadProps(__spreadValues({}, filter), { $last: count, $before: $page.$since }) : null;
1295
- let $next = isDef($page.$before) ? __spreadProps(__spreadValues({}, filter), { $first: count, $since: $page.$before }) : isDef($page.$until) ? __spreadProps(__spreadValues({}, filter), { $first: count, $after: $page.$until }) : null;
1294
+ const $prev = isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } : isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } : null;
1295
+ let $next = isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } : isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } : null;
1296
1296
  Object.assign(graph, { $page, $next, $prev });
1297
1297
  }
1298
1298
  function serialize(obj) {
@@ -1307,35 +1307,47 @@ function encode(value, { version, isGraph } = {}) {
1307
1307
  const links = [];
1308
1308
  function pushLink($ref, $ver, props, $val, $chi) {
1309
1309
  const [range, _] = splitRef($ref);
1310
- let children = !isEmpty(props) ? makeNode(range ? [__spreadValues({ $key: range }, props)] : props, void 0, $ver).children : isDef($chi) ? makeNode(range ? [{ $key: range, $chi }] : $chi, void 0, $ver).children : isDef($val) ? $val : isGraph ? void 0 : 1;
1310
+ let children = !isEmpty(props) ? makeNode(
1311
+ range ? [{ $key: range, ...props }] : props,
1312
+ void 0,
1313
+ $ver
1314
+ ).children : isDef($chi) ? makeNode(
1315
+ range ? [{ $key: range, $chi }] : $chi,
1316
+ void 0,
1317
+ $ver
1318
+ ).children : isDef($val) ? $val : isGraph ? void 0 : 1;
1311
1319
  if (children) {
1312
1320
  links.push(wrap(children, encode$1($ref), $ver, !!range)[0]);
1313
1321
  }
1314
1322
  }
1315
1323
  const combine = isGraph ? merge : add;
1316
1324
  function makeNode(object, key, ver) {
1317
- var _b;
1325
+ var _a2;
1318
1326
  if (!isDef(object))
1319
1327
  return;
1320
1328
  if (typeof object === "object" && object && isEmpty(object))
1321
1329
  return;
1322
- const _a2 = object || {}, { $key, $ver, $ref, $val, $chi, $put } = _a2, props = __objRest(_a2, ["$key", "$ver", "$ref", "$val", "$chi", "$put"]);
1330
+ const { $key, $ver, $ref, $val, $chi, $put, ...props } = object || {};
1323
1331
  if (isDef($ver))
1324
1332
  ver = $ver;
1325
1333
  if (isPlainObject($key)) {
1326
1334
  const [page, filter] = splitArgs($key);
1327
1335
  if (isGraph && page && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props))) {
1328
- const node2 = makeNode(__spreadProps(__spreadValues({}, object), { $key: filter || "" }), key, ver);
1336
+ const node2 = makeNode({ ...object, $key: filter || "" }, key, ver);
1329
1337
  node2.prefix = true;
1330
1338
  return node2;
1331
1339
  }
1332
1340
  if ((!isDef(key) || Number.isInteger(key)) && page && (filter || isDef(page.$cursor))) {
1333
- const node2 = makeNode({
1334
- $key: filter || "",
1335
- $chi: [
1336
- __spreadProps(__spreadValues({}, object), { $key: isDef(page.$cursor) ? page.$cursor : page })
1337
- ]
1338
- }, key, ver);
1341
+ const node2 = makeNode(
1342
+ {
1343
+ $key: filter || "",
1344
+ $chi: [
1345
+ { ...object, $key: isDef(page.$cursor) ? page.$cursor : page }
1346
+ ]
1347
+ },
1348
+ key,
1349
+ ver
1350
+ );
1339
1351
  node2.prefix = true;
1340
1352
  return node2;
1341
1353
  }
@@ -1402,7 +1414,7 @@ function encode(value, { version, isGraph } = {}) {
1402
1414
  if (isGraph && isDef(putQuery)) {
1403
1415
  node.children = finalize(node.children || [], putQuery, node.version);
1404
1416
  }
1405
- if (((_b = node.children) == null ? void 0 : _b.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1417
+ if (((_a2 = node.children) == null ? void 0 : _a2.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1406
1418
  return node;
1407
1419
  }
1408
1420
  }
@@ -1437,7 +1449,7 @@ async function* mergeStreams(...streams) {
1437
1449
  yield* mergeIterators(streams);
1438
1450
  }
1439
1451
  function makeWatcher() {
1440
- const listeners = new Set();
1452
+ const listeners = /* @__PURE__ */ new Set();
1441
1453
  function write(change) {
1442
1454
  for (const push of listeners)
1443
1455
  push(change);
@@ -1493,7 +1505,7 @@ function wrapObject(object, path) {
1493
1505
  } else if (Array.isArray(object)) {
1494
1506
  object = [{ $key, $chi: object }];
1495
1507
  } else {
1496
- object = [__spreadValues({ $key }, object)];
1508
+ object = [{ $key, ...object }];
1497
1509
  }
1498
1510
  }
1499
1511
  return object;
@@ -1518,11 +1530,68 @@ function unwrapObject(object, path) {
1518
1530
  if (page && !page.$cursor) {
1519
1531
  return object;
1520
1532
  } else {
1521
- const target = (page == null ? void 0 : page.$cursor) ? __spreadProps(__spreadValues({}, filter), { $cursor: page.$cursor }) : filter;
1533
+ const target = (page == null ? void 0 : page.$cursor) ? { ...filter, $cursor: page.$cursor } : filter;
1522
1534
  object = object.find(({ $key: $key2 }) => isEqual($key2, target));
1523
1535
  }
1524
1536
  }
1525
1537
  }
1526
1538
  return object;
1527
1539
  }
1528
- export { IS_VAL, add, cloneObject, decode$2 as decodeArgs, decodeGraph, decode$1 as decodePath, decodeQuery, decode$7 as decodeUrl, decode$3 as decodeValue, decorate, deserialize, encode$2 as encodeArgs, encodeGraph, encode$1 as encodePath, encodeQuery, encode$7 as encodeUrl, encode$3 as encodeValue, err, errIf, finalize, find, findFirst, findLast, getKnown, getNodeValue, isBranch, isDef, isEmpty, isEncoded, isEncodedKey, isLink, isNewer, isOlder, isPlainObject, isPrefix, isRange, keyAfter, keyBefore, keyStep, id as makeId, makeWatcher, merge, mergeObject, mergeStreams, remove, serialize, setVersion, sieve, slice, splitArgs, splitRef, unwrap, unwrapObject, wrap, wrapObject, wrapValue };
1540
+ export {
1541
+ IS_VAL,
1542
+ add,
1543
+ cloneObject,
1544
+ decode$2 as decodeArgs,
1545
+ decodeGraph,
1546
+ decode$1 as decodePath,
1547
+ decodeQuery,
1548
+ decode$7 as decodeUrl,
1549
+ decode$3 as decodeValue,
1550
+ decorate,
1551
+ deserialize,
1552
+ encode$2 as encodeArgs,
1553
+ encodeGraph,
1554
+ encode$1 as encodePath,
1555
+ encodeQuery,
1556
+ encode$7 as encodeUrl,
1557
+ encode$3 as encodeValue,
1558
+ err,
1559
+ errIf,
1560
+ finalize,
1561
+ find,
1562
+ findFirst,
1563
+ findLast,
1564
+ getKnown,
1565
+ getNodeValue,
1566
+ isBranch,
1567
+ isDef,
1568
+ isEmpty,
1569
+ isEncoded,
1570
+ isEncodedKey,
1571
+ isLink,
1572
+ isNewer,
1573
+ isOlder,
1574
+ isPlainObject,
1575
+ isPrefix,
1576
+ isRange,
1577
+ keyAfter,
1578
+ keyBefore,
1579
+ keyStep,
1580
+ id as makeId,
1581
+ makeWatcher,
1582
+ merge,
1583
+ mergeObject,
1584
+ mergeStreams,
1585
+ remove,
1586
+ serialize,
1587
+ setVersion,
1588
+ sieve,
1589
+ slice,
1590
+ splitArgs,
1591
+ splitRef,
1592
+ unwrap,
1593
+ unwrapObject,
1594
+ wrap,
1595
+ wrapObject,
1596
+ wrapValue
1597
+ };
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.15.25-alpha.1",
5
+ "version": "0.15.25-alpha.2",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -17,8 +17,8 @@
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
19
  "lodash": "^4.17.19",
20
- "nanoid": "^3.2.0",
21
- "@graffy/stream": "0.15.25-alpha.1",
20
+ "nanoid": "^4.0.0",
21
+ "@graffy/stream": "0.15.25-alpha.2",
22
22
  "merge-async-iterators": "^0.2.1"
23
23
  }
24
24
  }
@@ -1,2 +1,2 @@
1
- declare var _default: "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
1
+ declare const _default: "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare var _default: () => string;
1
+ declare const _default: (size?: number) => string;
2
2
  export default _default;