Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions configs/eslint-config-compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"dependencies": {
"@babel/core": "^7.24.3",
"@babel/eslint-parser": "^7.14.3",
"@mongodb-js/eslint-config-devtools": "^0.9.9",
"@mongodb-js/eslint-config-devtools": "^0.11.2",
"@mongodb-js/eslint-plugin-compass": "^1.2.18",
"@typescript-eslint/eslint-plugin": "^8.49.0",
"@typescript-eslint/parser": "^8.49.0",
"@mongodb-js/eslint-plugin-devtools": "^0.3.2",
"@typescript-eslint/eslint-plugin": "^8.50.0",
"@typescript-eslint/parser": "^8.50.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^1.1.0",
Expand Down
758 changes: 559 additions & 199 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
"cheerio": "1.0.0-rc.10"
},
"@mongodb-js/eslint-config-devtools": {
"@typescript-eslint/eslint-plugin": "^8.49.0",
"@typescript-eslint/parser": "^8.49.0",
"@typescript-eslint/eslint-plugin": "^8.50.0",
"@typescript-eslint/parser": "^8.50.0",
"eslint": "^8.57.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.37.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('side-panel module', function () {
beforeEach(async function () {
store = (await configureStore()).plugin.store;

const localStorageValues: Record<string, string> = {};
const localStorageValues: Record<string, string> = Object.create(null);

fakeLocalStorage = sinon.stub(global, 'localStorage').value({
getItem: sinon.fake((key: string) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/compass-assistant/src/prompts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ describe('prompts', function () {
];

for (const testCase of testCases) {
const summary: Record<string, string | boolean> = {
const summary: {
type: string;
isTimeSeries?: boolean;
isView?: boolean;
subTab?: string;
} = {
type: testCase.context.activeWorkspace?.type || 'No active tab',
};
if (testCase.context.activeCollectionMetadata?.isTimeSeries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export type CollectionBadgeType =
| 'fle'
| 'clustered';

const badges: Record<
CollectionBadgeType,
{ label: React.ReactNode; variant?: BadgeVariant }
const badges: Readonly<
Record<
CollectionBadgeType,
{ label: React.ReactNode; variant?: BadgeVariant }
>
> = {
readonly: {
label: 'READ-ONLY',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export const StepButtonLabelMap = {

// Map of the current mock data generator step to the next step or 'finish' if the user is on the last step.
// For the purposes of telemetry tracking the step progression in the modal.
export const MOCK_DATA_GENERATOR_STEP_TO_NEXT_STEP_MAP: Record<
MockDataGeneratorStep,
MockDataGeneratorStep | 'finish'
export const MOCK_DATA_GENERATOR_STEP_TO_NEXT_STEP_MAP: Readonly<
Record<MockDataGeneratorStep, MockDataGeneratorStep | 'finish'>
> = {
[MockDataGeneratorSteps.SCHEMA_CONFIRMATION]:
MockDataGeneratorSteps.SCHEMA_EDITOR,
Expand Down Expand Up @@ -51,9 +50,8 @@ export const MongoDBFieldTypeValues: MongoDBFieldType[] = [
* Not all Faker methods are included here.
* More can be found in the Faker.js API: https://v9.fakerjs.dev/api/
*/
export const MONGO_TYPE_TO_FAKER_METHODS: Record<
MongoDBFieldType,
Array<{ method: string; description?: string }>
export const MONGO_TYPE_TO_FAKER_METHODS: Readonly<
Record<MongoDBFieldType, Array<{ method: string; description?: string }>>
> = {
String: [
{ method: 'lorem.word', description: 'Single word' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function isPrimitiveSchemaType(type: SchemaType): type is PrimitiveSchemaType {
* The result is used for the Mock Data Generator LLM call and script generation.
*/
export function processSchema(schema: Schema): ProcessSchemaResult {
const fieldInfo: Record<string, FieldInfo> = {};
const fieldInfo: Record<string, FieldInfo> = Object.create(null);
const arrayLengthMap: ArrayLengthMap = {};

if (!schema.fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const buttonSizeStyle: Record<ItemActionButtonSize, string | undefined> = {
width: `${20}px !important`,
height: `${20}px !important`,
}),
};
} as const;

export type SmallIconButtonProps = {
glyph: React.ReactChild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const VALUE_COLOR_BY_THEME_AND_TYPE: Record<
String: variantColors.light[7],
ObjectId: variantColors.light[5],
},
};
} as const;

const bsonValue = css({
whiteSpace: 'nowrap',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const StatusMessages: Record<Status, string> = {
['DeleteStart']: 'Removing document…',
['DeleteError']: '',
['DeleteSuccess']: 'Document deleted.',
};
} as const;

function useHadronDocumentStatus(
doc: HadronDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ export const DrawerAnchor: React.FunctionComponent = ({ children }) => {
if (!drawerEl) {
return;
}
const nodes: Record<string, HTMLButtonElement | undefined> = {};
const nodes: Record<string, HTMLButtonElement | undefined> =
Object.create(null);
for (const item of toolbarData) {
if (!item.guideCue) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-context-menu/src/use-context-menu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ describe('useContextMenu', function () {
expect(screen.getByTestId('menu-item-Parent Item 2')).to.exist;

// Should not show child items
expect(() => screen.getByTestId('menu-item-Child Item 1')).to.throw;
expect(() => screen.getByTestId('menu-item-Child Item 2')).to.throw;
expect(screen.queryByTestId('menu-item-Child Item 1')).to.not.exist;
expect(screen.queryByTestId('menu-item-Child Item 2')).to.not.exist;
});

it('shows both parent and child items when right clicking child area', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const featureDescription: Record<
title: 'Interactive Diagram Analysis',
subtitle: 'Explore and annotate interactive diagrams',
},
};
} as const;

const FeaturesList: React.FunctionComponent<{ features: Feature[] }> = ({
features,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getHighlightedFields = (
return NO_HIGHLIGHTED_FIELDS;
const { id } = selectedItems;
const { relationship } = relationships?.find((rel) => rel.id === id) ?? {};
const selection: Record<string, string[][] | undefined> = {};
const selection: Record<string, string[][] | undefined> = Object.create(null);
if (relationship?.[0].ns && relationship?.[0].fields) {
selection[relationship[0].ns] = [relationship[0].fields];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ const colorMap: Record<string, string> = {
color7: 'Pink',
color8: 'Orange',
color9: 'Yellow',
};
} as const;

function colorValueToName(color: string): string {
if (colorMap[color]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const indexTypeToIndexSelectOption: Record<IndexType, string> = {
'-1': '-1 (desc)',
'2dsphere': '2dsphere',
text: 'text (full text search)',
};
} as const;

export async function createIndex(
browser: CompassBrowser,
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ export async function startBrowser(
},
},
},
};
} as const;

// webdriverio removed RemoteOptions. It is now
// Capabilities.WebdriverIOConfig, but Capabilities is not exported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Collection ai query (with mocked backend)', function () {
expect(queryRequest.req.headers).to.have.property('x-client-request-id');
expect(queryRequest.req.headers).to.have.property('entrypoint');
expect(queryRequest.content.model).to.equal('mongodb-slim-latest');
expect(queryRequest.content.instructions).to.be.string;
expect(queryRequest.content.instructions).to.be.a('string');
expect(queryRequest.content.metadata).to.have.property('userId');
expect(queryRequest.content.metadata.store).to.have.equal('true');
expect(queryRequest.content.metadata.sensitiveStorage).to.have.equal(
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-e2e-tests/tests/my-queries-tab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ async function openMenuForQueryItem(
await browser.$(Selectors.SavedItemMenu).waitForDisplayed();
}

const knownQueryNames: Record<string, true> = {};
const knownQueryFilters: Record<string, true> = {};
const knownQueryNames: Record<string, true> = Object.create(null);
const knownQueryFilters: Record<string, true> = Object.create(null);

async function saveQuery(
browser: CompassBrowser,
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-editor/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ export const languages: Record<EditorLanguage, () => LanguageSupport> = {
'javascript-expression': () => {
return new LanguageSupport(javascriptExpression);
},
};
} as const;

export const languageName = Facet.define<EditorLanguage>({});

Expand Down
2 changes: 1 addition & 1 deletion packages/compass-generative-ai/src/atlas-ai-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export class AtlasAiService {
const newSchema: Record<
string,
Omit<MockDataSchemaRawField, 'sampleValues'>
> = {};
> = Object.create(null);
for (const [k, v] of Object.entries(schema)) {
newSchema[k] = { type: v.type };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const disabledButtonStyles: Record<Theme, string> = {
},
},
}),
};
} as const;

const CloudAIOptInBannerContent: React.FunctionComponent<{
isProjectAIEnabled: boolean;
Expand Down
52 changes: 24 additions & 28 deletions packages/compass-generative-ai/src/utils/parse-xml-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,33 @@ export function parseXmlToJsonResponse(
);

// Currently the prompt forces LLM to return xml-styled data
const result: Record<(typeof expectedTags)[number], string | null> = {
filter: null,
project: null,
sort: null,
skip: null,
limit: null,
aggregation: null,
};
const result: Record<(typeof expectedTags)[number], string | null> =
Object.create(null);

for (const tag of expectedTags) {
result[tag] = null;

Comment on lines +46 to +50
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initialization of result[tag] = null should occur after creating the object and before the loop, not inside the loop. Consider initializing all tags to null immediately after creating the object to avoid redundant assignments in each iteration.

Suggested change
Object.create(null);
for (const tag of expectedTags) {
result[tag] = null;
Object.fromEntries(
expectedTags.map((tag) => [tag, null as string | null])
) as Record<(typeof expectedTags)[number], string | null>;
for (const tag of expectedTags) {

Copilot uses AI. Check for mistakes.
const value = xmlDoc.querySelector(tag)?.textContent?.trim();
if (value) {
try {
const tagValue = parse(value);
if (
!tagValue ||
(typeof tagValue === 'object' && Object.keys(tagValue).length === 0)
) {
result[tag] = null;
} else {
// No indentation
result[tag] = toJSString(tagValue, 0) ?? null;
}
} catch (e) {
logger.log.warn(
logger.mongoLogId(1_001_000_384),
'AtlasAiService',
`Failed to parse value for tag <${tag}>: ${value}`,
{ error: e }
);
result[tag] = null;
if (!value) {
continue;
}

try {
const tagValue = parse(value);
if (
tagValue &&
!(typeof tagValue === 'object' && Object.keys(tagValue).length === 0)
) {
// No indentation
result[tag] = toJSString(tagValue, 0) ?? null;
}
} catch (e) {
logger.log.warn(
logger.mongoLogId(1_001_000_384),
'AtlasAiService',
`Failed to parse value for tag <${tag}>: ${value}`,
{ error: e }
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a bit of a refactor here to simplify things.

}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/compass-import-export/src/csv/csv-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export const parsableFieldTypes = [
] as const;
export type CSVParsableFieldType = (typeof parsableFieldTypes)[number];

export const CSVFieldTypeLabels: Record<CSVParsableFieldType, string> = {
export const CSVFieldTypeLabels: Readonly<
Record<CSVParsableFieldType, string>
> = {
int: 'Int32',
long: 'Long',
double: 'Double',
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-import-export/src/csv/csv-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ describe('placeValue', function () {
});

function parseHeader(header: string[]): Record<string, PathPart[]> {
const parsed: Record<string, PathPart[]> = {};
const parsed: Record<string, PathPart[]> = Object.create(null);
for (const name of header) {
parsed[name] = parseCSVHeaderName(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function listCSVFields({
// ie. the whole array counts as one field
const flattened = headerFields.map(csvHeaderNameToFieldName);

const fieldMap: Record<string, true> = {};
const fieldMap: Record<string, true> = Object.create(null);

// make sure that each array field is only included once
for (const name of flattened) {
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-import-export/src/modules/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const startImport = (): ImportThunkAction<Promise<void>> => {

const ignoreBlanks = ignoreBlanks_ && fileType === FILE_TYPES.CSV;
const fileSize = fileStats?.size || 0;
const fields: Record<string, CSVParsableFieldType> = {};
const fields: Record<string, CSVParsableFieldType> = Object.create(null);
for (const [name, type] of transform) {
if (exclude.includes(name)) {
continue;
Expand Down Expand Up @@ -662,7 +662,7 @@ const loadCSVPreviewDocs = (): ImportThunkAction<Promise<void>> => {
try {
const result = await listCSVFields({ input, delimiter, newline });

const fieldMap: Record<string, number[]> = {};
const fieldMap: Record<string, number[]> = Object.create(null);
const fields: FieldFromCSV[] = [];

// group the array fields' cells together so that large arrays don't kill
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-import-export/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import debug from 'debug';
const PREFIX = 'mongodb-compass-import-export';

const _LOGGERS: Record<string, debug.Debugger> = {};
const _LOGGERS: Record<string, debug.Debugger> = Object.create(null);

export const createDebug = function (name: string) {
if (!_LOGGERS[name]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ describe('RegularIndexesTable Component', function () {
expect(within(indexRow).getByTestId(indexCell)).to.exist;
}

expect(() => within(indexRow).getByTestId('index-actions-hide-action')).to
.throw;
expect(within(indexRow).queryByTestId('index-actions-hide-action')).to.not
.exist;
if (index.status === 'creating') {
expect(() =>
within(indexRow).getByTestId('index-actions-delete-action')
Expand All @@ -283,8 +283,8 @@ describe('RegularIndexesTable Component', function () {
expect(within(indexRow).getByTestId(indexCell)).to.exist;
}

expect(() => within(indexRow).getByTestId('index-actions-hide-action')).to
.throw;
expect(within(indexRow).queryByTestId('index-actions-hide-action')).to.not
.exist;
expect(() =>
within(indexRow).getByTestId('index-actions-delete-action')
).to.throw();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const statusBadgeVariants: Record<SearchIndexStatus, BadgeVariant> = {
READY: BadgeVariant.Green,
STALE: BadgeVariant.LightGray,
DELETING: BadgeVariant.Red,
};
} as const;

function IndexStatus({
status,
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-indexes/src/modules/create-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export const createIndexFormSubmitted = (): IndexesThunkAction<

const formIndexOptions = getState().createIndex.options;

let spec: Record<string, IndexDirection> = {};
let spec: Record<string, IndexDirection> = Object.create(null);

try {
// Gather from the index input fields
Expand Down
Loading
Loading