@augment-vir/common 29.1.3 → 29.1.4

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.
@@ -6,6 +6,7 @@ const run_time_assertions_1 = require("run-time-assertions");
6
6
  const tuple_1 = require("../tuple");
7
7
  const filter_object_1 = require("./filter-object");
8
8
  const map_object_1 = require("./map-object");
9
+ const object_1 = require("./object");
9
10
  function shouldPreserve(input) {
10
11
  return (0, run_time_assertions_1.isPrimitive)(input) || input instanceof RegExp || input instanceof Promise;
11
12
  }
@@ -30,21 +31,21 @@ function selectFrom(originalObject, selectionSet) {
30
31
  }
31
32
  function selectCollapsedFrom(originalObject, selectionSet) {
32
33
  const selected = selectFrom(originalObject, selectionSet);
33
- return collapseObject(selected);
34
+ return collapseObject(selected, selectionSet);
34
35
  }
35
- function collapseObject(input) {
36
+ function collapseObject(input, selectionSet) {
36
37
  if (shouldPreserve(input)) {
37
38
  return input;
38
39
  }
39
40
  const keys = Object.keys(input);
40
41
  if (Array.isArray(input)) {
41
- return input.map((innerInput) => collapseObject(innerInput));
42
+ return input.map((innerInput) => collapseObject(innerInput, selectionSet));
42
43
  }
43
44
  else if ((0, tuple_1.isLengthAtLeast)(keys, 2)) {
44
45
  return input;
45
46
  }
46
- else if ((0, tuple_1.isLengthAtLeast)(keys, 1)) {
47
- return collapseObject(input[keys[0]]);
47
+ else if ((0, tuple_1.isLengthAtLeast)(keys, 1) && (0, object_1.isObject)(selectionSet)) {
48
+ return collapseObject(input[keys[0]], selectionSet[keys[0]]);
48
49
  }
49
50
  else {
50
51
  return input;
@@ -2,6 +2,7 @@ import { isPrimitive } from 'run-time-assertions';
2
2
  import { isLengthAtLeast } from '../tuple';
3
3
  import { omitObjectKeys } from './filter-object';
4
4
  import { mapObjectValues } from './map-object';
5
+ import { isObject } from './object';
5
6
  function shouldPreserve(input) {
6
7
  return isPrimitive(input) || input instanceof RegExp || input instanceof Promise;
7
8
  }
@@ -26,21 +27,21 @@ export function selectFrom(originalObject, selectionSet) {
26
27
  }
27
28
  export function selectCollapsedFrom(originalObject, selectionSet) {
28
29
  const selected = selectFrom(originalObject, selectionSet);
29
- return collapseObject(selected);
30
+ return collapseObject(selected, selectionSet);
30
31
  }
31
- function collapseObject(input) {
32
+ function collapseObject(input, selectionSet) {
32
33
  if (shouldPreserve(input)) {
33
34
  return input;
34
35
  }
35
36
  const keys = Object.keys(input);
36
37
  if (Array.isArray(input)) {
37
- return input.map((innerInput) => collapseObject(innerInput));
38
+ return input.map((innerInput) => collapseObject(innerInput, selectionSet));
38
39
  }
39
40
  else if (isLengthAtLeast(keys, 2)) {
40
41
  return input;
41
42
  }
42
- else if (isLengthAtLeast(keys, 1)) {
43
- return collapseObject(input[keys[0]]);
43
+ else if (isLengthAtLeast(keys, 1) && isObject(selectionSet)) {
44
+ return collapseObject(input[keys[0]], selectionSet[keys[0]]);
44
45
  }
45
46
  else {
46
47
  return input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "29.1.3",
3
+ "version": "29.1.4",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"