Skip to content

Commit 0c994ce

Browse files
feat: visually identify FLE2 collections MONGOSH-1204 (#1270)
1 parent e1b993b commit 0c994ce

File tree

6 files changed

+47
-14
lines changed

6 files changed

+47
-14
lines changed

packages/browser-repl/package-lock.json

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

packages/browser-repl/src/components/types/show-collections-output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ShowCollectionsOutput extends Component<ShowCollectionsOutputProps>
2525
let maxCollectionNameLength = 0;
2626
value.forEach(coll => {
2727
maxCollectionNameLength = Math.max(maxCollectionNameLength, coll.name.length);
28-
if (coll.name.startsWith('system.')) {
28+
if (coll.name.startsWith('system.') || coll.name.startsWith('enxcol_.')) {
2929
systemCollections.push(coll);
3030
} else {
3131
otherCollections.push(coll);

packages/cli-repl/src/format-output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function formatCollections(output: CollectionNamesWithTypes[], options: FormatOp
128128
const otherCollections: CollectionNamesWithTypes[] = [];
129129

130130
output.forEach(coll => {
131-
if (coll.name.startsWith('system.')) {
131+
if (coll.name.startsWith('system.') || coll.name.startsWith('enxcol_.')) {
132132
systemCollections.push(coll);
133133
} else {
134134
otherCollections.push(coll);

packages/shell-api/src/database.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,26 @@ describe('Database', () => {
164164
{ name: 'coll3', type: 'view' },
165165
{ name: 'coll1', type: 'collection' },
166166
{ name: 'coll2', type: 'newtype' },
167+
{ name: 'coll4', type: 'collection' },
168+
{ name: 'enxcol_.coll4.esc', type: 'collection' },
169+
{ name: 'enxcol_.coll4.ecc', type: 'collection' },
170+
{ name: 'enxcol_.coll4.ecoc', type: 'collection' },
171+
{ name: 'enxcol_.coll5.esc', type: 'collection' },
172+
{ name: 'coll6', type: 'timeseries' }
167173
];
168174

169175
serviceProvider.listCollections.resolves(result);
170176

171177
expect(await database._getCollectionNamesWithTypes()).to.deep.equal([
172178
{ name: 'coll1', badge: '' },
173179
{ name: 'coll2', badge: '' },
174-
{ name: 'coll3', badge: '[view]' }
180+
{ name: 'coll3', badge: '[view]' },
181+
{ name: 'coll4', badge: '[queryable-encryption]' },
182+
{ name: 'coll6', badge: '[time-series]' },
183+
{ name: 'enxcol_.coll4.ecc', badge: '' },
184+
{ name: 'enxcol_.coll4.ecoc', badge: '' },
185+
{ name: 'enxcol_.coll4.esc', badge: '' },
186+
{ name: 'enxcol_.coll5.esc', badge: '' }
175187
]);
176188

177189
expect(serviceProvider.listCollections).to.have.been.calledOnceWith(

packages/shell-api/src/database.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
isValidCollectionName,
2424
getConfigDB,
2525
shouldRunAggregationImmediately,
26-
adjustRunCommand
26+
adjustRunCommand,
27+
getBadge
2728
} from './helpers';
2829

2930
import type {
@@ -169,16 +170,11 @@ export default class Database extends ShellApiWithMongoClass {
169170
let collections = await this._listCollections({}, { ...options, nameOnly: true });
170171
collections = collections.sort((c1, c2) => (c1.name).localeCompare(c2.name));
171172

172-
const typesToBages: any = {
173-
timeseries: '[time-series]',
174-
view: '[view]'
175-
};
173+
this._cachedCollectionNames = collections.map((collection: Document) => collection.name);
176174

177-
this._cachedCollectionNames = collections.map((collection: any) => collection.name);
178-
179-
return collections.map((collection: any) => ({
175+
return collections.map((collection: Document, index: number) => ({
180176
name: collection.name,
181-
badge: typesToBages[collection.type] ?? ''
177+
badge: getBadge(collections, index)
182178
}));
183179
}
184180

packages/shell-api/src/helpers.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,28 @@ export function adjustRunCommand(cmd: Document, shellBson: ShellBson): Document
769769
}
770770
return cmd;
771771
}
772+
773+
const isFLE2Collection = (collections: Document[], index: number): boolean => {
774+
return (
775+
!collections[index].name.startsWith('enxcol_.') &&
776+
collections.some(coll => coll.name === `enxcol_.${collections[index].name}.esc`) &&
777+
collections.some(coll => coll.name === `enxcol_.${collections[index].name}.ecc`) &&
778+
collections.some(coll => coll.name === `enxcol_.${collections[index].name}.ecoc`)
779+
);
780+
};
781+
782+
export function getBadge(collections: Document[], index: number): string {
783+
if (collections[index].type === 'timeseries') {
784+
return '[time-series]';
785+
}
786+
787+
if (collections[index].type === 'view') {
788+
return '[view]';
789+
}
790+
791+
if (isFLE2Collection(collections, index)) {
792+
return '[queryable-encryption]';
793+
}
794+
795+
return '';
796+
}

0 commit comments

Comments
 (0)