@graffy/common 0.15.15-alpha.3 → 0.15.18

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 +26 -17
  2. package/index.mjs +26 -17
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -1060,18 +1060,23 @@ function decode(nodes = [], { isGraph } = {}) {
1060
1060
  delete item.$key;
1061
1061
  return collection;
1062
1062
  }
1063
- const _a = item, { $key, $val } = _a, rest = __objRest(_a, ["$key", "$val"]);
1064
- if (typeof $val === "object")
1065
- $val.$val = true;
1066
- collection[$key] = isDef($val) ? $val : !isEmpty(rest) ? rest : isGraph ? null : true;
1063
+ const { $key, $val } = item;
1064
+ delete item.$key;
1065
+ delete item.$val;
1066
+ if (typeof $val === "object") {
1067
+ Object.defineProperty($val, "$val", { value: true });
1068
+ }
1069
+ collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
1067
1070
  return collection;
1068
1071
  }, allStrs ? {} : []);
1069
1072
  }
1070
1073
  if (isGraph && putRanges.length) {
1071
1074
  if (putRanges[0].key === "" && putRanges[0].end === "\uFFFF") {
1072
- result.$put = true;
1075
+ Object.defineProperty(result, "$put", { value: true });
1073
1076
  } else {
1074
- result.$put = putRanges.map((rNode) => decode$2(rNode));
1077
+ Object.defineProperty(result, "$put", {
1078
+ value: putRanges.map((rNode) => decode$2(rNode))
1079
+ });
1075
1080
  }
1076
1081
  }
1077
1082
  return result;
@@ -1091,7 +1096,9 @@ function decode(nodes = [], { isGraph } = {}) {
1091
1096
  throw Error("decode.unencoded_prefix_ref: " + node.path);
1092
1097
  }
1093
1098
  lastKey.$all = true;
1094
- return [{ $key: args, $ref }];
1099
+ const linkObject = { $key: args };
1100
+ Object.defineProperty(linkObject, "$ref", { value: $ref });
1101
+ return [linkObject];
1095
1102
  }
1096
1103
  const children = decodeChildren(node.children);
1097
1104
  if (!Array.isArray(children)) {
@@ -1123,7 +1130,9 @@ function decode(nodes = [], { isGraph } = {}) {
1123
1130
  return { $key: decode$2({ key: node.key }) };
1124
1131
  }
1125
1132
  function decodeLinkNode(node) {
1126
- return { $key: decode$2(node), $ref: decode$1(node.path) };
1133
+ const linkObject = { $key: decode$2(node) };
1134
+ Object.defineProperty(linkObject, "$ref", { value: decode$1(node.path) });
1135
+ return linkObject;
1127
1136
  }
1128
1137
  return decodeChildren(nodes);
1129
1138
  }
@@ -1152,7 +1161,7 @@ function decorate(rootGraph, rootQuery) {
1152
1161
  if (range)
1153
1162
  targetPlumGraph[PRE] = filter;
1154
1163
  graph = construct(targetPlumGraph, range ? __spreadValues({ $key: range }, props) : props);
1155
- graph.$ref = $ref;
1164
+ Object.defineProperty(graph, "$ref", { value: $ref });
1156
1165
  } else if (Array.isArray(query)) {
1157
1166
  let pageKey;
1158
1167
  graph = query.flatMap((item, i) => {
@@ -1196,11 +1205,12 @@ function decorate(rootGraph, rootQuery) {
1196
1205
  } else if (Array.isArray(plumGraph)) {
1197
1206
  graph = decodeGraph(plumGraph);
1198
1207
  } else {
1199
- throw Error("decorate.unexpected_graph", plumGraph);
1208
+ throw Error("decorate.unexpected_graph");
1200
1209
  }
1201
1210
  }
1202
- if (plumGraph[REF])
1203
- graph.$ref = decode$1(plumGraph[REF]);
1211
+ if (plumGraph[REF]) {
1212
+ Object.defineProperty(graph, "$ref", decode$1(plumGraph[REF]));
1213
+ }
1204
1214
  return graph;
1205
1215
  }
1206
1216
  function descend(children, $key) {
@@ -1306,18 +1316,17 @@ function encode(value, { version, isGraph } = {}) {
1306
1316
  }
1307
1317
  const combine = isGraph ? merge : add;
1308
1318
  function makeNode(object, key, ver) {
1309
- var _c;
1319
+ var _b;
1310
1320
  if (!isDef(object))
1311
1321
  return;
1312
1322
  if (typeof object === "object" && object && isEmpty(object))
1313
1323
  return;
1314
- const _a2 = object || {}, { $key, $ver } = _a2, data = __objRest(_a2, ["$key", "$ver"]);
1315
- const _b = data, { $ref, $val, $chi, $put } = _b, props = __objRest(_b, ["$ref", "$val", "$chi", "$put"]);
1324
+ const _a2 = object || {}, { $key, $ver, $ref, $val, $chi, $put } = _a2, props = __objRest(_a2, ["$key", "$ver", "$ref", "$val", "$chi", "$put"]);
1316
1325
  if (isDef($ver))
1317
1326
  ver = $ver;
1318
1327
  if (isPlainObject($key)) {
1319
1328
  const [page, filter] = splitArgs($key);
1320
- if (isGraph && page && !isDef(page.$cursor) && !isEmpty(data)) {
1329
+ if (isGraph && page && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props))) {
1321
1330
  const node2 = makeNode(__spreadProps(__spreadValues({}, object), { $key: filter || "" }), key, ver);
1322
1331
  node2.prefix = true;
1323
1332
  return node2;
@@ -1395,7 +1404,7 @@ function encode(value, { version, isGraph } = {}) {
1395
1404
  if (isGraph && isDef(putQuery)) {
1396
1405
  node.children = finalize(node.children || [], putQuery, node.version);
1397
1406
  }
1398
- if (((_c = node.children) == null ? void 0 : _c.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1407
+ if (((_b = node.children) == null ? void 0 : _b.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1399
1408
  return node;
1400
1409
  }
1401
1410
  }
package/index.mjs CHANGED
@@ -1052,18 +1052,23 @@ function decode(nodes = [], { isGraph } = {}) {
1052
1052
  delete item.$key;
1053
1053
  return collection;
1054
1054
  }
1055
- const _a = item, { $key, $val } = _a, rest = __objRest(_a, ["$key", "$val"]);
1056
- if (typeof $val === "object")
1057
- $val.$val = true;
1058
- collection[$key] = isDef($val) ? $val : !isEmpty(rest) ? rest : isGraph ? null : true;
1055
+ const { $key, $val } = item;
1056
+ delete item.$key;
1057
+ delete item.$val;
1058
+ if (typeof $val === "object") {
1059
+ Object.defineProperty($val, "$val", { value: true });
1060
+ }
1061
+ collection[$key] = isDef($val) ? $val : !isEmpty(item) || item.$ref || item.$put ? item : isGraph ? null : true;
1059
1062
  return collection;
1060
1063
  }, allStrs ? {} : []);
1061
1064
  }
1062
1065
  if (isGraph && putRanges.length) {
1063
1066
  if (putRanges[0].key === "" && putRanges[0].end === "\uFFFF") {
1064
- result.$put = true;
1067
+ Object.defineProperty(result, "$put", { value: true });
1065
1068
  } else {
1066
- result.$put = putRanges.map((rNode) => decode$2(rNode));
1069
+ Object.defineProperty(result, "$put", {
1070
+ value: putRanges.map((rNode) => decode$2(rNode))
1071
+ });
1067
1072
  }
1068
1073
  }
1069
1074
  return result;
@@ -1083,7 +1088,9 @@ function decode(nodes = [], { isGraph } = {}) {
1083
1088
  throw Error("decode.unencoded_prefix_ref: " + node.path);
1084
1089
  }
1085
1090
  lastKey.$all = true;
1086
- return [{ $key: args, $ref }];
1091
+ const linkObject = { $key: args };
1092
+ Object.defineProperty(linkObject, "$ref", { value: $ref });
1093
+ return [linkObject];
1087
1094
  }
1088
1095
  const children = decodeChildren(node.children);
1089
1096
  if (!Array.isArray(children)) {
@@ -1115,7 +1122,9 @@ function decode(nodes = [], { isGraph } = {}) {
1115
1122
  return { $key: decode$2({ key: node.key }) };
1116
1123
  }
1117
1124
  function decodeLinkNode(node) {
1118
- return { $key: decode$2(node), $ref: decode$1(node.path) };
1125
+ const linkObject = { $key: decode$2(node) };
1126
+ Object.defineProperty(linkObject, "$ref", { value: decode$1(node.path) });
1127
+ return linkObject;
1119
1128
  }
1120
1129
  return decodeChildren(nodes);
1121
1130
  }
@@ -1144,7 +1153,7 @@ function decorate(rootGraph, rootQuery) {
1144
1153
  if (range)
1145
1154
  targetPlumGraph[PRE] = filter;
1146
1155
  graph = construct(targetPlumGraph, range ? __spreadValues({ $key: range }, props) : props);
1147
- graph.$ref = $ref;
1156
+ Object.defineProperty(graph, "$ref", { value: $ref });
1148
1157
  } else if (Array.isArray(query)) {
1149
1158
  let pageKey;
1150
1159
  graph = query.flatMap((item, i) => {
@@ -1188,11 +1197,12 @@ function decorate(rootGraph, rootQuery) {
1188
1197
  } else if (Array.isArray(plumGraph)) {
1189
1198
  graph = decodeGraph(plumGraph);
1190
1199
  } else {
1191
- throw Error("decorate.unexpected_graph", plumGraph);
1200
+ throw Error("decorate.unexpected_graph");
1192
1201
  }
1193
1202
  }
1194
- if (plumGraph[REF])
1195
- graph.$ref = decode$1(plumGraph[REF]);
1203
+ if (plumGraph[REF]) {
1204
+ Object.defineProperty(graph, "$ref", decode$1(plumGraph[REF]));
1205
+ }
1196
1206
  return graph;
1197
1207
  }
1198
1208
  function descend(children, $key) {
@@ -1298,18 +1308,17 @@ function encode(value, { version, isGraph } = {}) {
1298
1308
  }
1299
1309
  const combine = isGraph ? merge : add;
1300
1310
  function makeNode(object, key, ver) {
1301
- var _c;
1311
+ var _b;
1302
1312
  if (!isDef(object))
1303
1313
  return;
1304
1314
  if (typeof object === "object" && object && isEmpty(object))
1305
1315
  return;
1306
- const _a2 = object || {}, { $key, $ver } = _a2, data = __objRest(_a2, ["$key", "$ver"]);
1307
- const _b = data, { $ref, $val, $chi, $put } = _b, props = __objRest(_b, ["$ref", "$val", "$chi", "$put"]);
1316
+ const _a2 = object || {}, { $key, $ver, $ref, $val, $chi, $put } = _a2, props = __objRest(_a2, ["$key", "$ver", "$ref", "$val", "$chi", "$put"]);
1308
1317
  if (isDef($ver))
1309
1318
  ver = $ver;
1310
1319
  if (isPlainObject($key)) {
1311
1320
  const [page, filter] = splitArgs($key);
1312
- if (isGraph && page && !isDef(page.$cursor) && !isEmpty(data)) {
1321
+ if (isGraph && page && !isDef(page.$cursor) && ($ref || $val || $chi || $put || !isEmpty(props))) {
1313
1322
  const node2 = makeNode(__spreadProps(__spreadValues({}, object), { $key: filter || "" }), key, ver);
1314
1323
  node2.prefix = true;
1315
1324
  return node2;
@@ -1387,7 +1396,7 @@ function encode(value, { version, isGraph } = {}) {
1387
1396
  if (isGraph && isDef(putQuery)) {
1388
1397
  node.children = finalize(node.children || [], putQuery, node.version);
1389
1398
  }
1390
- if (((_c = node.children) == null ? void 0 : _c.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1399
+ if (((_b = node.children) == null ? void 0 : _b.length) || isDef(node.end) || isDef(node.value) || isDef(node.path)) {
1391
1400
  return node;
1392
1401
  }
1393
1402
  }
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.15-alpha.3",
5
+ "version": "0.15.18",
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.1.25",
20
+ "nanoid": "^3.2.0",
21
21
  "merge-async-iterators": "^0.2.1",
22
- "@graffy/stream": "0.15.15-alpha.3"
22
+ "@graffy/stream": "0.15.18"
23
23
  }
24
24
  }