Skip to content

Commit 17b6e19

Browse files
committed
Merge remote-tracking branch 'origin/main' into 1.32-releases
2 parents 7d66d66 + 0794aae commit 17b6e19

File tree

16 files changed

+1057
-178
lines changed

16 files changed

+1057
-178
lines changed

.github/workflows/authors-and-third-party-notices.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jobs:
5656
- Update `AUTHORS` and `THIRD-PARTY-NOTICES`
5757
5858
- name: Merge PR
59-
if: ${{steps.cpr.outputs.pull-request-operation == 'created'}}
6059
env:
6160
PULL_REQUEST_NUMBER: ${{steps.cpr.outputs.pull-request-number}}
6261
# NOTE: we don't use a PAT so to not trigger further automation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MongoDB Compass Monorepo
22

3-
This repository contains the source code and build tooling used in [MongoDB Compass](https://compass.mongodb.com).
3+
This repository contains the source code and build tooling used in [MongoDB Compass](https://www.mongodb.com/products/compass).
44

55
![Aggregation Pipeline Builder Tab in Compass](packages/compass/compass-screenshot.png)
66

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **compass**.
2-
This document was automatically generated on Thu Jun 09 2022.
2+
This document was automatically generated on Sun Jun 19 2022.
33

44
## List of dependencies
55

package-lock.json

Lines changed: 841 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mongodb-compass-monorepo",
33
"description": "Monorepo that includes Compass and all its dependencies",
4-
"homepage": "https://compass.mongodb.com",
4+
"homepage": "https://www.mongodb.com/products/compass",
55
"author": {
66
"name": "MongoDB Inc",
77
"email": "[email protected]"

packages/compass-aggregations/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"hadron-react-buttons": "^5.9.0",
8484
"hadron-react-components": "^5.15.0",
8585
"mocha": "^8.4.0",
86-
"mongodb-ace-autocompleter": "^1.0.0",
86+
"mongodb-ace-autocompleter": "^1.1.1",
8787
"mongodb-connection-model": "^21.17.0",
8888
"mongodb-data-service": "^21.21.0",
8989
"mongodb-query-parser": "^2.4.6",

packages/compass-components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"@leafygreen-ui/banner": "^3.0.9",
3636
"@leafygreen-ui/button": "^12.0.5",
3737
"@leafygreen-ui/card": "^5.1.4",
38-
"@leafygreen-ui/code": "^9.4.0",
3938
"@leafygreen-ui/checkbox": "^6.0.6",
39+
"@leafygreen-ui/code": "^9.4.0",
4040
"@leafygreen-ui/confirmation-modal": "^2.2.3",
4141
"@leafygreen-ui/emotion": "^4.0.0",
4242
"@leafygreen-ui/icon": "^11.7.0",
@@ -96,7 +96,7 @@
9696
"chai": "^4.3.4",
9797
"eslint": "^7.25.0",
9898
"mocha": "^8.4.0",
99-
"mongodb-ace-autocompleter": "*",
99+
"mongodb-ace-autocompleter": "^1.1.1",
100100
"mongodb-ace-mode": "^1.7.0",
101101
"nyc": "^15.0.0",
102102
"prettier": "2.3.2",

packages/compass-import-export/src/utils/dotnotation.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

packages/compass-import-export/src/utils/dotnotation.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,34 @@ describe('dotnotation', function () {
6060
locations: ['berlin', 'nyc', 'philadelphia'],
6161
});
6262
});
63+
64+
it('should pre-generate objects when includeObjects is specified', function () {
65+
expect(
66+
dotnotation.serialize(
67+
{
68+
foo: {
69+
1: 'a',
70+
two: 'b',
71+
},
72+
},
73+
{ includeObjects: true }
74+
)
75+
).to.deep.equal({
76+
foo: {},
77+
'foo.1': 'a',
78+
'foo.two': 'b',
79+
});
80+
81+
// leaves arrays alone - already handled by flatten() with { safe: true }
82+
expect(
83+
dotnotation.serialize(
84+
{
85+
foo: ['a', 'b'],
86+
},
87+
{ includeObjects: true }
88+
)
89+
).to.deep.equal({
90+
foo: ['a', 'b'],
91+
});
92+
});
6393
});
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import _ from 'lodash';
2+
// @ts-expect-error no types exist for this library
3+
import { flatten, unflatten } from 'flat';
4+
import { getTypeDescriptorForValue } from './bson-csv';
5+
/**
6+
* TODO: lucas: Some overlap w/ bson-csv but they do
7+
* have difference! Can't quite name it yet, but something
8+
* to sort in the future.
9+
*/
10+
11+
/**
12+
* Converts any nested objects into a single depth object with `dotnotation` keys.
13+
* @example
14+
* ```javascript
15+
* dotnotation.serialize({_id: 'arlo', collar: {size: 14}});
16+
* >> {_id: 'arlo', 'collar.size': 14}
17+
18+
* dotnotation.serialize({ foo: { 1: 'one', two: 'two' } });
19+
* >> { 'foo.1': 'one', 'foo.two': 'two' }
20+
21+
* dotnotation.serialize({ foo: { 1: 'one', two: 'two' } }, { includeObjects: true });
22+
* >> { foo: {}, 'foo.1': 'one', 'foo.two': 'two' }
23+
* ```
24+
* @param {Object} obj
25+
* @returns {Object}
26+
*/
27+
export function serialize(
28+
obj: Record<string, unknown>,
29+
{ includeObjects = false } = {}
30+
): Record<string, unknown> {
31+
const flattened = flatten(obj, {
32+
safe: true, // preserve arrays and their contents
33+
/**
34+
* @param {any} value
35+
* @returns {Boolean}
36+
* NOTE: lucas: Trying an existing fork that supports this new option:
37+
* https://github.com/hughsk/flat/pull/93
38+
*/
39+
ignoreValue: function (value: unknown): boolean {
40+
const t = getTypeDescriptorForValue(value);
41+
if (t.isBSON) {
42+
return true;
43+
}
44+
return false;
45+
},
46+
});
47+
48+
if (includeObjects) {
49+
/*
50+
Make sure that paths to objects exist in the returned value before the paths
51+
to properties inside those objects.
52+
ie. for { foo: { 1: 'one', two: 'two' } } we will return
53+
{ foo: {}, 'foo.1': 'one', 'foo.two': 'two' } rather than
54+
{ 'foo.1': 'one', 'foo.two': 'two'}.
55+
56+
This way when we walk the return value later by the time we encounter
57+
'foo.1' we already created foo, initialised to {}. Then _.set(result,
58+
'foo.1', 'one') will not create foo as an array because 1 looks like an
59+
index. This is because at that point result will already contain { foo: {} }
60+
61+
The use-case for this came about because paths that end with numbers are
62+
ambiguous and _.set() will assume it is an array index by default. By
63+
ensuring that there is already an object at the target the ambiguity is
64+
removed.
65+
*/
66+
const withObjects: Record<string, unknown> = {};
67+
const knownParents: Record<string, true> = {};
68+
for (const [path, value] of Object.entries(flattened)) {
69+
const parentPath = path.includes('.')
70+
? path.slice(0, path.lastIndexOf('.'))
71+
: null;
72+
if (parentPath && !knownParents[parentPath]) {
73+
knownParents[parentPath] = true;
74+
// Leave arrays alone because they already got handled by safe: true above.
75+
if (!Array.isArray(_.get(obj, parentPath))) {
76+
withObjects[parentPath] = {};
77+
}
78+
}
79+
withObjects[path] = value;
80+
}
81+
return withObjects;
82+
}
83+
84+
return flattened;
85+
}
86+
87+
/**
88+
* Converts an object using dotnotation to a full, nested object.
89+
* @example
90+
* ```javascript
91+
* dotnotation.deserialize({_id: 'arlo', 'collar.size': 14});
92+
* >> {_id: 'arlo', collar: {size: 14}}
93+
* ```
94+
* @param {Object} obj
95+
* @returns {Object}
96+
*/
97+
export function deserialize(obj: any): any {
98+
/**
99+
* TODO: lucas: bson type support. For now, drop.
100+
*/
101+
return unflatten(obj);
102+
}
103+
104+
export default { serialize, deserialize };

0 commit comments

Comments
 (0)