Skip to content
Merged
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
8 changes: 2 additions & 6 deletions packages/atlas-service/src/atlas-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import type { Logger } from '@mongodb-js/compass-logging';
import type { PreferencesAccess } from 'compass-preferences-model';
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
import { type UserDataType } from '@mongodb-js/compass-user-data';

export type AtlasServiceOptions = {
defaultHeaders?: Record<string, string>;
Expand Down Expand Up @@ -81,12 +82,7 @@ export class AtlasService {
userDataEndpoint(
orgId: string,
groupId: string,
type:
| 'favoriteQueries'
| 'recentQueries'
| 'favoriteAggregations'
| 'savedWorkspaces'
| 'dataModelDescriptions',
type: UserDataType,
id?: string
): string {
const encodedOrgId = encodeURIComponent(orgId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DataModelStorageAtlas implements DataModelStorage {
constructor(orgId: string, projectId: string, atlasService: AtlasService) {
this.userData = new AtlasUserData(
MongoDBDataModelDescriptionSchema,
'dataModelDescriptions',
'DataModelDescriptions',
{
orgId,
projectId,
Expand All @@ -37,7 +37,7 @@ class DataModelStorageAtlas implements DataModelStorage {
!type ||
!pathOrgId ||
!pathProjectId ||
type !== 'dataModelDescriptions'
type !== 'DataModelDescriptions'
) {
throw new Error(
'DataModelStorageAtlas is used outside of Atlas Cloud context'
Expand Down
2 changes: 0 additions & 2 deletions packages/compass-e2e-tests/tests/collection-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ describe('Collection import', function () {
// Find the log file
const logFilePath = path.resolve(
compass.userDataPath || '',
compass.appName || '',
'ImportErrorLogs',
`import-${filename}.log`
);
Expand Down Expand Up @@ -1293,7 +1292,6 @@ describe('Collection import', function () {

const logFilePath = path.resolve(
compass.userDataPath || '',
compass.appName || '',
'ImportErrorLogs',
`import-${fileName}.log`
);
Expand Down
10 changes: 9 additions & 1 deletion packages/compass-import-export/src/modules/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { analyzeCSVFields } from '../import/analyze-csv-fields';
import type { AnalyzeCSVFieldsResult } from '../import/analyze-csv-fields';
import { importCSV } from '../import/import-csv';
import { importJSON } from '../import/import-json';
import { getUserDataFolderPath } from '../utils/get-user-data-file-path';
import { getStoragePath } from '@mongodb-js/compass-utils';
import {
showBloatedDocumentSignalToast,
showUnboundArraySignalToast,
Expand Down Expand Up @@ -177,6 +177,14 @@ const onFileSelectError = (error: Error) => ({
error,
});

export function getUserDataFolderPath() {
const basepath = getStoragePath();
if (basepath === undefined) {
throw new Error('cannot access user data folder path');
}
return basepath;
}

async function getErrorLogPath(fileName: string) {
// Create the error log output file.
const userDataPath = getUserDataFolderPath();
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions packages/compass-shell/src/modules/history-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import fs from 'fs/promises';
import { HistoryStorage } from './history-storage';

describe('HistoryStorage', function () {
let tmpDir;
let historyFilePath;
let tmpDir: string;
let historyFilePath: string;

let historyStorage;
let historyStorage: HistoryStorage;

beforeEach(async function () {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'compass-shell-test'));
historyFilePath = path.join(tmpDir, 'shell-history.json');
historyFilePath = path.join(tmpDir, 'ShellHistory', 'shell-history.json');

historyStorage = new HistoryStorage(tmpDir);
});
Expand Down
24 changes: 21 additions & 3 deletions packages/compass-shell/src/modules/history-storage.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import { getAppName } from '@mongodb-js/compass-utils';
import { FileUserData, z } from '@mongodb-js/compass-user-data';
import { getAppName } from '@mongodb-js/compass-utils';

export class HistoryStorage {
fileName = 'shell-history';
userData;
private migrationChecked = false;

constructor(basePath?: string) {
// TODO: https://jira.mongodb.org/browse/COMPASS-7080
this.userData = new FileUserData(z.string().array(), getAppName() ?? '', {
this.userData = new FileUserData(z.string().array(), 'ShellHistory', {
basePath,
});
}

/**
* Migrates history from old app-name-based folder to new ShellHistory folder.
* Only runs once per instance and only if old folder exists.
*/
private async migrateIfNeeded(): Promise<void> {
if (this.migrationChecked) {
return;
}
this.migrationChecked = true;

const oldAppName = getAppName();
if (oldAppName) {
await this.userData.migrateFromOldFolder(oldAppName);
}
}

/**
* Saves the history to disk, it creates the directory and the file if
* not existing and replaces the file content.
Expand All @@ -20,6 +36,7 @@ export class HistoryStorage {
* newest to oldest.
*/
async save(history: string[]) {
await this.migrateIfNeeded();
await this.userData.write(this.fileName, history);
}

Expand All @@ -31,6 +48,7 @@ export class HistoryStorage {
* newest to oldest.
*/
async load(): Promise<string[]> {
await this.migrateIfNeeded();
try {
return (await this.userData.readOne(this.fileName)) ?? [];
} catch {
Expand Down
9 changes: 7 additions & 2 deletions packages/compass-user-data/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type { ReadAllResult } from './user-data';
export { IUserData, FileUserData, AtlasUserData } from './user-data';
export type { ReadAllResult, UserDataType } from './user-data';
export {
IUserData,
FileUserData,
AtlasUserData,
assertsUserDataType,
} from './user-data';
export { z } from 'zod';
Loading
Loading