From 02281bd64d7b7a76bd08879f7031e923054aeef7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 1 Dec 2025 11:45:22 +0100 Subject: [PATCH 1/4] chore(typescript): enable erasableSyntaxOnly for the whole repo Inspired by https://github.com/mongodb-js/compass/pull/7613 --- configs/tsconfig-mongosh/tsconfig.common.json | 1 + packages/async-rewriter2/src/error-codes.ts | 10 +++--- packages/autocomplete/src/index.spec.ts | 18 +++++----- .../shell-api-autocompleter.spec.ts | 3 +- packages/build/src/barque.ts | 10 ++---- packages/build/src/config/config.ts | 2 +- packages/build/src/config/platform.ts | 6 +--- packages/build/src/evergreen/rest-api.ts | 19 ++++++++--- .../build/src/homebrew/publish-to-homebrew.ts | 4 ++- packages/build/src/publish-mongosh.ts | 25 ++++++++++---- packages/cli-repl/src/error-codes.ts | 8 ++--- packages/errors/src/common-errors.ts | 18 +++++----- packages/logging/src/analytics-helpers.ts | 5 ++- .../node-runtime-worker-thread/src/rpc.ts | 17 +++------- .../src/serializer.ts | 19 +++++------ packages/shell-api/src/collection.ts | 23 +++++-------- packages/shell-api/src/database.ts | 12 +++---- packages/shell-api/src/enums.ts | 33 ++++++++----------- packages/shell-api/src/error-codes.ts | 18 +++++----- packages/shell-api/src/integration.spec.ts | 2 +- packages/shell-api/src/mongo.ts | 4 +-- .../shell-api/src/shell-instance-state.ts | 12 +++---- 22 files changed, 130 insertions(+), 139 deletions(-) diff --git a/configs/tsconfig-mongosh/tsconfig.common.json b/configs/tsconfig-mongosh/tsconfig.common.json index b1e364d62e..8579e03cfa 100644 --- a/configs/tsconfig-mongosh/tsconfig.common.json +++ b/configs/tsconfig-mongosh/tsconfig.common.json @@ -9,6 +9,7 @@ "noUnusedLocals": false, "noUnusedParameters": false, "noImplicitReturns": true, + "erasableSyntaxOnly": true, "declaration": true, "removeComments": true, diff --git a/packages/async-rewriter2/src/error-codes.ts b/packages/async-rewriter2/src/error-codes.ts index c3abd67140..612cee40b3 100644 --- a/packages/async-rewriter2/src/error-codes.ts +++ b/packages/async-rewriter2/src/error-codes.ts @@ -3,7 +3,7 @@ /** * @mongoshErrors */ -enum AsyncRewriterErrors { +export const AsyncRewriterErrors = { /** * Signals the use of a Mongosh API call in a place where it is not supported. * This occurs inside of constructors and (non-async) generator functions. @@ -23,7 +23,7 @@ enum AsyncRewriterErrors { * * **Solution: Do not use calls directly in such functions. If necessary, place these calls in an inner 'async' function.** */ - SyntheticPromiseInAlwaysSyncContext = 'ASYNC-10012', + SyntheticPromiseInAlwaysSyncContext: 'ASYNC-10012', /** * Signals the iteration of a Mongosh API object in a place where it is not supported. * This occurs inside of constructors and (non-async) generator functions. @@ -44,7 +44,5 @@ enum AsyncRewriterErrors { * * **Solution: Do not use calls directly in such functions. If necessary, place these calls in an inner 'async' function.** */ - SyntheticAsyncIterableInAlwaysSyncContext = 'ASYNC-10013', -} - -export { AsyncRewriterErrors }; + SyntheticAsyncIterableInAlwaysSyncContext: 'ASYNC-10013', +} as const; diff --git a/packages/autocomplete/src/index.spec.ts b/packages/autocomplete/src/index.spec.ts index 570643055e..8708265bb7 100644 --- a/packages/autocomplete/src/index.spec.ts +++ b/packages/autocomplete/src/index.spec.ts @@ -1,12 +1,12 @@ import { completer, BASE_COMPLETIONS } from './'; -import { signatures as shellSignatures, Topologies } from '@mongosh/shell-api'; +import { signatures as shellSignatures } from '@mongosh/shell-api'; import { expect } from 'chai'; let collections: string[]; let databases: string[]; const standalone600 = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: false, @@ -18,7 +18,7 @@ const standalone600 = { getDatabaseCompletions: () => databases, }; const standalone440 = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: false, @@ -30,7 +30,7 @@ const standalone440 = { getDatabaseCompletions: () => databases, }; const apiStrictParams = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone' as const, apiVersionInfo: () => ({ version: '1', strict: true, @@ -41,7 +41,7 @@ const apiStrictParams = { getDatabaseCompletions: () => databases, }; const sharded440 = { - topology: () => Topologies.Sharded, + topology: () => 'Sharded' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: false, @@ -54,7 +54,7 @@ const sharded440 = { }; const standalone300 = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: false, @@ -66,7 +66,7 @@ const standalone300 = { getDatabaseCompletions: () => databases, }; const datalake440 = { - topology: () => Topologies.Sharded, + topology: () => 'Sharded' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: true, @@ -79,7 +79,7 @@ const datalake440 = { }; const localAtlas600 = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: false, @@ -100,7 +100,7 @@ const noParams = { }; const emptyConnectionInfoParams = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone' as const, apiVersionInfo: () => undefined, connectionInfo: () => ({}), getCollectionCompletionsForCurrentDb: () => collections, diff --git a/packages/browser-runtime-core/src/autocompleter/shell-api-autocompleter.spec.ts b/packages/browser-runtime-core/src/autocompleter/shell-api-autocompleter.spec.ts index dee94dd162..40b223e2a1 100644 --- a/packages/browser-runtime-core/src/autocompleter/shell-api-autocompleter.spec.ts +++ b/packages/browser-runtime-core/src/autocompleter/shell-api-autocompleter.spec.ts @@ -1,11 +1,10 @@ import { ShellApiAutocompleter } from './shell-api-autocompleter'; import { expect } from 'chai'; -import { Topologies } from '@mongosh/shell-api'; import type { AutocompleteParameters } from '@mongosh/autocomplete'; import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete'; const standalone440Parameters: AutocompleteParameters = { - topology: () => Topologies.Standalone, + topology: () => 'Standalone', apiVersionInfo: () => undefined, connectionInfo: () => ({ is_atlas: false, diff --git a/packages/build/src/barque.ts b/packages/build/src/barque.ts index c55d62114e..51c32f2596 100644 --- a/packages/build/src/barque.ts +++ b/packages/build/src/barque.ts @@ -11,13 +11,7 @@ import tmp from 'tmp-promise'; import util, { promisify } from 'util'; import type { PackageVariant, Config } from './config'; import semver from 'semver'; -import { - getArch, - getDistro, - getDebArchName, - getRPMArchName, - Platform, -} from './config'; +import { getArch, getDistro, getDebArchName, getRPMArchName } from './config'; import { withRetries } from './helpers'; import type { PPARepository, @@ -120,7 +114,7 @@ export class Barque { private downloadedCuratorPromise: Promise | undefined; constructor(config: Config) { - if (config.platform !== Platform.Linux) { + if (config.platform !== 'linux') { throw new Error('Barque publishing is only supported on linux platforms'); } diff --git a/packages/build/src/config/config.ts b/packages/build/src/config/config.ts index 9db78071ac..6573a71270 100644 --- a/packages/build/src/config/config.ts +++ b/packages/build/src/config/config.ts @@ -50,7 +50,7 @@ export interface Config { notarySigningKeyName?: string; notaryAuthToken?: string; isCi?: boolean; - platform?: string; + platform?: NodeJS.Platform; execNodeVersion: string; packageVariant?: PackageVariant; repo: { diff --git a/packages/build/src/config/platform.ts b/packages/build/src/config/platform.ts index a142eba94c..79c692d9bf 100644 --- a/packages/build/src/config/platform.ts +++ b/packages/build/src/config/platform.ts @@ -4,8 +4,4 @@ * Different from 'BuildVariant': platform is extracted from os.platform() and * build variant is the host evergreen is building on. */ -export enum Platform { - Windows = 'win32', - MacOs = 'darwin', - Linux = 'linux', -} +export type Platform = 'win32' | 'darwin' | 'linux'; diff --git a/packages/build/src/evergreen/rest-api.ts b/packages/build/src/evergreen/rest-api.ts index 803526218a..faf78407ec 100644 --- a/packages/build/src/evergreen/rest-api.ts +++ b/packages/build/src/evergreen/rest-api.ts @@ -22,12 +22,21 @@ export interface EvergreenTask { } export class EvergreenApi { + public readonly apiBasepath: string; + public readonly apiUser: string; + public readonly apiKey: string; + private readonly fetch: typeof fetchFn; constructor( - public readonly apiBasepath: string, - public readonly apiUser: string, - public readonly apiKey: string, - private readonly fetch: typeof fetchFn = fetchFn - ) {} + apiBasepath: string, + apiUser: string, + apiKey: string, + fetch: typeof fetchFn = fetchFn + ) { + this.apiBasepath = apiBasepath; + this.apiUser = apiUser; + this.apiKey = apiKey; + this.fetch = fetch; + } public static async fromUserConfiguration( pathToConfiguration = path.join(os.homedir(), '.evergreen.yml') diff --git a/packages/build/src/homebrew/publish-to-homebrew.ts b/packages/build/src/homebrew/publish-to-homebrew.ts index 40b38e769b..12bce742cf 100644 --- a/packages/build/src/homebrew/publish-to-homebrew.ts +++ b/packages/build/src/homebrew/publish-to-homebrew.ts @@ -12,18 +12,20 @@ export type HomebrewPublisherConfig = { }; export class HomebrewPublisher { + public config: HomebrewPublisherConfig; readonly npmPackageSha256: typeof npmPackageSha256Fn; readonly generateFormula: typeof generateUpdatedFormulaFn; readonly updateHomebrewFork: typeof updateHomebrewForkFn; constructor( - public config: HomebrewPublisherConfig, + config: HomebrewPublisherConfig, { npmPackageSha256 = npmPackageSha256Fn, generateFormula = generateUpdatedFormulaFn, updateHomebrewFork = updateHomebrewForkFn, } = {} ) { + this.config = config; this.npmPackageSha256 = npmPackageSha256; this.generateFormula = generateFormula; this.updateHomebrewFork = updateHomebrewFork; diff --git a/packages/build/src/publish-mongosh.ts b/packages/build/src/publish-mongosh.ts index dfe07399c4..e81eecc35d 100644 --- a/packages/build/src/publish-mongosh.ts +++ b/packages/build/src/publish-mongosh.ts @@ -48,18 +48,25 @@ export async function publishMongosh(config: Config, octokit: Octokit) { } export class MongoshPublisher { + public config: Config; + public barque: Barque; + public mongoshGithubRepo: GithubRepo; + public packagePublisher: PackagePublisher; + public packageBumper: PackageBumper; + public homebrewPublisher: HomebrewPublisher; + private readonly getEvergreenArtifactUrl: typeof getArtifactUrlFn; private readonly writeBuildInfo: typeof writeBuildInfoFn; private readonly createAndPublishDownloadCenterConfig: typeof createAndPublishDownloadCenterConfigFn; private readonly shouldDoPublicRelease: typeof shouldDoPublicReleaseFn; constructor( - public config: Config, - public barque: Barque, - public mongoshGithubRepo: GithubRepo, - public packagePublisher: PackagePublisher, - public packageBumper: PackageBumper, - public homebrewPublisher: HomebrewPublisher, + config: Config, + barque: Barque, + mongoshGithubRepo: GithubRepo, + packagePublisher: PackagePublisher, + packageBumper: PackageBumper, + homebrewPublisher: HomebrewPublisher, { getEvergreenArtifactUrl = getArtifactUrlFn, writeBuildInfo = writeBuildInfoFn, @@ -67,6 +74,12 @@ export class MongoshPublisher { shouldDoPublicRelease = shouldDoPublicReleaseFn, } = {} ) { + this.config = config; + this.barque = barque; + this.mongoshGithubRepo = mongoshGithubRepo; + this.packagePublisher = packagePublisher; + this.packageBumper = packageBumper; + this.homebrewPublisher = homebrewPublisher; this.getEvergreenArtifactUrl = getEvergreenArtifactUrl; this.writeBuildInfo = writeBuildInfo; this.createAndPublishDownloadCenterConfig = diff --git a/packages/cli-repl/src/error-codes.ts b/packages/cli-repl/src/error-codes.ts index d6cf778e3a..6bd644ce3c 100644 --- a/packages/cli-repl/src/error-codes.ts +++ b/packages/cli-repl/src/error-codes.ts @@ -1,13 +1,11 @@ /** * @mongoshErrors */ -enum CliReplErrors { +export const CliReplErrors = { /** * Signals that the currently installed Node version does not match the one expected by mongosh. * * See the output for further details on the required Node version. */ - NodeVersionMismatch = 'CLIREPL-10001', -} - -export { CliReplErrors }; + NodeVersionMismatch: 'CLIREPL-10001', +} as const; diff --git a/packages/errors/src/common-errors.ts b/packages/errors/src/common-errors.ts index 29584f8fed..4626902862 100644 --- a/packages/errors/src/common-errors.ts +++ b/packages/errors/src/common-errors.ts @@ -1,20 +1,20 @@ /** * @mongoshErrors */ -enum CommonErrors { +export const CommonErrors = { /** * Signals calling an API method with an invalid argument. * * **Solution: See the error output for details on allowed argument values.** */ - InvalidArgument = 'COMMON-10001', + InvalidArgument: 'COMMON-10001', /** * Signals calling an API method that is not allowed in the current state. * * **Solution: See the error output for details.** */ - InvalidOperation = 'COMMON-10002', + InvalidOperation: 'COMMON-10002', /** * Signals calling an API method that has been deprecated or using an argument or option of an API method that has been deprecated @@ -22,28 +22,26 @@ enum CommonErrors { * * **Solution: See the error output for details on alternatives or consult the official documentation.** */ - Deprecated = 'COMMON-10003', + Deprecated: 'COMMON-10003', /** * Signals an error while running a specific command against the database. * * **Solution: Check the error output for more details and ensure the database is healthy and available.** */ - CommandFailed = 'COMMON-10004', + CommandFailed: 'COMMON-10004', /** * Signals an unexpected internal error of mongosh. * * **Please file a bug report for the `MONGOSH` project here: https://jira.mongodb.org.** */ - UnexpectedInternalError = 'COMMON-90001', + UnexpectedInternalError: 'COMMON-90001', /** * Signals usage of a method that is not implemented yet. * * **See the error output for details.** */ - NotImplemented = 'COMMON-90002', -} - -export { CommonErrors }; + NotImplemented: 'COMMON-90002', +} as const; diff --git a/packages/logging/src/analytics-helpers.ts b/packages/logging/src/analytics-helpers.ts index 93d9354859..38f61d6ce8 100644 --- a/packages/logging/src/analytics-helpers.ts +++ b/packages/logging/src/analytics-helpers.ts @@ -39,9 +39,12 @@ export interface MongoshAnalytics { } class Queue { + private applyFn: (val: T) => void; private queue: T[] = []; private state: 'paused' | 'enabled' | 'disabled' = 'paused'; - constructor(private applyFn: (val: T) => void) {} + constructor(applyFn: (val: T) => void) { + this.applyFn = applyFn; + } push(val: T) { switch (this.state) { case 'paused': diff --git a/packages/node-runtime-worker-thread/src/rpc.ts b/packages/node-runtime-worker-thread/src/rpc.ts index 3672c9fd8a..bbca9163f3 100644 --- a/packages/node-runtime-worker-thread/src/rpc.ts +++ b/packages/node-runtime-worker-thread/src/rpc.ts @@ -8,25 +8,18 @@ export type RPCMessageBus = { removeEventListener: Function; }; -enum RPCMessageTypes { - Message, - Error, -} - type RPCMessage = { - type: RPCMessageTypes.Message; + type: 'Message'; payload: string; }; type RPCError = { - type: RPCMessageTypes.Error; + type: 'Error'; payload: Error; }; function isRPCError(data: any): data is RPCError { - return ( - data && typeof data === 'object' && data.type === RPCMessageTypes.Error - ); + return data && typeof data === 'object' && data.type === 'Error'; } function getRPCOptions(messageBus: RPCMessageBus): PostmsgRpcOptions { @@ -59,13 +52,13 @@ export function exposeAll( key, async (...args: unknown[]) => { try { - return { type: RPCMessageTypes.Message, payload: await val(...args) }; + return { type: 'Message', payload: await val(...args) }; } catch (e: any) { // If server (whatever is executing the exposed method) throws during // the execution, we want to propagate error to the client (whatever // issued the call) and re-throw there. We will do this with a special // return type. - return { type: RPCMessageTypes.Error, payload: serializeError(e) }; + return { type: 'Error', payload: serializeError(e) }; } }, getRPCOptions(messageBus) diff --git a/packages/node-runtime-worker-thread/src/serializer.ts b/packages/node-runtime-worker-thread/src/serializer.ts index 3453fb6d6c..31efae423d 100644 --- a/packages/node-runtime-worker-thread/src/serializer.ts +++ b/packages/node-runtime-worker-thread/src/serializer.ts @@ -44,11 +44,10 @@ export function deserializeError(err: any): Error { return Object.assign(new Error(), err); } -export enum SerializedResultTypes { - SerializedErrorResult = 'SerializedErrorResult', - InspectResult = 'InspectResult', - SerializedShellApiResult = 'SerializedShellApiResult', -} +export type SerializedResultTypes = + | 'SerializedErrorResult' + | 'InspectResult' + | 'SerializedShellApiResult'; export function serializeEvaluationResult({ type, @@ -63,7 +62,7 @@ export function serializeEvaluationResult({ // Errors are serialized as some error metadata can be lost without this if (isError(printable)) { return { - type: SerializedResultTypes.SerializedErrorResult, + type: 'SerializedErrorResult', printable: serializeError(printable), source, }; @@ -77,7 +76,7 @@ export function serializeEvaluationResult({ // before passing to the main thread if (type === null) { return { - type: SerializedResultTypes.InspectResult, + type: 'InspectResult', printable: inspect(printable), source, }; @@ -87,7 +86,7 @@ export function serializeEvaluationResult({ // to preserve as much information as possible, including serializing the // printable value to EJSON as its a common thing to be returned by shell-api return { - type: SerializedResultTypes.SerializedShellApiResult, + type: 'SerializedShellApiResult', printable: { origType: type, serializedValue: EJSON.serialize(printable), @@ -100,11 +99,11 @@ export function deserializeEvaluationResult({ printable, source, }: RuntimeEvaluationResult): RuntimeEvaluationResult { - if (type === SerializedResultTypes.SerializedErrorResult) { + if (type === 'SerializedErrorResult') { return { type, printable: deserializeError(printable), source }; } - if (type === SerializedResultTypes.SerializedShellApiResult) { + if (type === 'SerializedShellApiResult') { return { type: printable.origType, printable: EJSON.deserialize(printable.serializedValue), diff --git a/packages/shell-api/src/collection.ts b/packages/shell-api/src/collection.ts index a0825ff36c..65fe16a8b0 100644 --- a/packages/shell-api/src/collection.ts +++ b/packages/shell-api/src/collection.ts @@ -11,12 +11,7 @@ import { deprecated, ShellApiWithMongoClass, } from './decorators'; -import { - asPrintable, - namespaceInfo, - ServerVersions, - Topologies, -} from './enums'; +import { asPrintable, namespaceInfo, ServerVersions } from './enums'; import type { FindAndModifyShellOptions, FindAndModifyMethodShellOptions, @@ -1439,7 +1434,7 @@ export class Collection< */ @returnsPromise @deprecated - @topologies([Topologies.Standalone]) + @topologies(['Standalone']) @apiVersions([]) async reIndex(): Promise { this._emitCollectionApiCall('reIndex'); @@ -2095,7 +2090,7 @@ export class Collection< } @returnsPromise - @topologies([Topologies.Sharded]) + @topologies(['Sharded']) @apiVersions([]) async getShardVersion(): Promise { this._emitCollectionApiCall('getShardVersion', {}); @@ -2161,7 +2156,7 @@ export class Collection< } @returnsPromise - @topologies([Topologies.Sharded]) + @topologies(['Sharded']) @apiVersions([]) async getShardDistribution(): Promise< CommandResult @@ -2289,7 +2284,7 @@ export class Collection< } @returnsPromise - @topologies([Topologies.Sharded]) + @topologies(['Sharded']) @apiVersions([]) @serverVersions(['8.0.10', ServerVersions.latest]) async getShardLocation(): Promise<{ @@ -2334,7 +2329,7 @@ export class Collection< } @serverVersions(['3.1.0', ServerVersions.latest]) - @topologies([Topologies.ReplSet, Topologies.Sharded]) + @topologies(['ReplSet', 'Sharded']) @apiVersions([1]) @returnsPromise async watch( @@ -2405,7 +2400,7 @@ export class Collection< @serverVersions(['7.0.0', ServerVersions.latest]) @returnsPromise - @topologies([Topologies.ReplSet, Topologies.Sharded]) + @topologies(['ReplSet', 'Sharded']) @apiVersions([]) async analyzeShardKey( key: Document, @@ -2422,7 +2417,7 @@ export class Collection< @serverVersions(['7.0.0', ServerVersions.latest]) @returnsPromise - @topologies([Topologies.ReplSet, Topologies.Sharded]) + @topologies(['ReplSet', 'Sharded']) @apiVersions([]) async configureQueryAnalyzer(options: Document): Promise { this._emitCollectionApiCall('configureQueryAnalyzer', options); @@ -2433,7 +2428,7 @@ export class Collection< } @serverVersions(['7.0.0', ServerVersions.latest]) - @topologies([Topologies.Sharded]) + @topologies(['Sharded']) @returnsPromise async checkMetadataConsistency( options: CheckMetadataConsistencyOptions = {} diff --git a/packages/shell-api/src/database.ts b/packages/shell-api/src/database.ts index 2841fbf5fd..e67dfcb068 100644 --- a/packages/shell-api/src/database.ts +++ b/packages/shell-api/src/database.ts @@ -1535,7 +1535,7 @@ export class Database< } @returnsPromise - @topologies([Topologies.Sharded]) + @topologies(['Sharded']) @apiVersions([1]) async printShardingStatus(verbose = false): Promise { this._emitDatabaseApiCall('printShardingStatus', { verbose }); @@ -1547,7 +1547,7 @@ export class Database< } @returnsPromise - @topologies([Topologies.ReplSet]) + @topologies(['ReplSet']) @apiVersions([]) async printSecondaryReplicationInfo(): Promise { let startOptimeDate = null; @@ -1628,7 +1628,7 @@ export class Database< } @returnsPromise - @topologies([Topologies.ReplSet]) + @topologies(['ReplSet']) @apiVersions([]) async getReplicationInfo(): Promise { const localdb = this.getSiblingDB('local'); @@ -1694,7 +1694,7 @@ export class Database< @returnsPromise @apiVersions([]) - @topologies([Topologies.ReplSet]) + @topologies(['ReplSet']) async printReplicationInfo(): Promise { const result = {} as any; let replInfo; @@ -1740,7 +1740,7 @@ export class Database< } @serverVersions(['3.1.0', ServerVersions.latest]) - @topologies([Topologies.ReplSet, Topologies.Sharded]) + @topologies(['ReplSet', 'Sharded']) @apiVersions([1]) @returnsPromise async watch( @@ -1820,7 +1820,7 @@ export class Database< } @serverVersions(['7.0.0', ServerVersions.latest]) - @topologies([Topologies.Sharded]) + @topologies(['Sharded']) @returnsPromise async checkMetadataConsistency( options: CheckMetadataConsistencyOptions = {} diff --git a/packages/shell-api/src/enums.ts b/packages/shell-api/src/enums.ts index 7d5b7d36e0..1ff7bfb538 100644 --- a/packages/shell-api/src/enums.ts +++ b/packages/shell-api/src/enums.ts @@ -1,27 +1,22 @@ -export enum ServerVersions { - latest = '999.999.999', // set a really high max value - earliest = '0.0.0', -} - -export enum Topologies { - ReplSet = 'ReplSet', - Standalone = 'Standalone', - Sharded = 'Sharded', - LoadBalanced = 'LoadBalanced', -} - -import type { ReplPlatform } from '@mongosh/service-provider-core'; - +export const ServerVersions = { + latest: '999.999.999', // set a really high max value + earliest: '0.0.0', +} as const; export const ALL_SERVER_VERSIONS = [ ServerVersions.earliest, ServerVersions.latest, ]; + export const ALL_TOPOLOGIES = [ - Topologies.ReplSet, - Topologies.Sharded, - Topologies.LoadBalanced, - Topologies.Standalone, -]; + 'ReplSet', + 'Standalone', + 'Sharded', + 'LoadBalanced', +] as const; +export type Topologies = (typeof ALL_TOPOLOGIES)[number]; + +import type { ReplPlatform } from '@mongosh/service-provider-core'; + export const ALL_PLATFORMS: ReplPlatform[] = ['Compass', 'Browser', 'CLI']; export const ALL_API_VERSIONS = [0, Infinity]; diff --git a/packages/shell-api/src/error-codes.ts b/packages/shell-api/src/error-codes.ts index b77f5e75ea..8e8fd9dd62 100644 --- a/packages/shell-api/src/error-codes.ts +++ b/packages/shell-api/src/error-codes.ts @@ -3,7 +3,7 @@ * * @param apiDetails Additional details on the blocked API */ -function blockedByDriverMetadata(apiDetails: string) { +export function blockedByDriverMetadata(apiDetails: string) { return { driverCaused: true, api: apiDetails, @@ -13,35 +13,35 @@ function blockedByDriverMetadata(apiDetails: string) { /** * @mongoshErrors */ -enum ShellApiErrors { +export const ShellApiErrors = { /** * Signals calling a method that requires sharding for a collection that is not sharded * or a database that does not have sharding enabled. * * **Solution: Be sure to enable sharding on the database or that the collection is sharded.** */ - NotConnectedToShardedCluster = 'SHAPI-10001', + NotConnectedToShardedCluster: 'SHAPI-10001', /** * Signals calling a method requiring a replica set without being connected to a replica set. * * **Solution: Make sure you are connected to a replica set.** */ - NotConnectedToReplicaSet = 'SHAPI-10002', + NotConnectedToReplicaSet: 'SHAPI-10002', /** * Signals calling a method that requires to be connected to a `mongos` instead of just a `mongod`. * * **Solution: Ensure you are connected to a `mongos` instances.** */ - NotConnectedToMongos = 'SHAPI-10003', + NotConnectedToMongos: 'SHAPI-10003', /** * Signals calling an operation that requires an active database connection without being connected. * * **Solution: Connect to a database before executing the operation.** */ - NotConnected = 'SHAPI-10004', + NotConnected: 'SHAPI-10004', /** * Signals calling a method that requires a Mongo object with field-level encryption options @@ -49,7 +49,5 @@ enum ShellApiErrors { * * **Solution: Create a new Mongo object with the correct field-level encryption options first.** */ - NotUsingFLE = 'SHAPI-10005', -} - -export { blockedByDriverMetadata, ShellApiErrors }; + NotUsingFLE: 'SHAPI-10005', +} as const; diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index 2b6e50a1bf..1469711467 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -2893,7 +2893,7 @@ describe('Shell API (integration)', function () { it('returns information that is meaningful for autocompletion', async function () { const params = instanceState.getAutocompleteParameters(); - expect(params.topology()).to.equal(Topologies.Standalone); + expect(params.topology()).to.equal('Standalone'); expect(params.connectionInfo()?.uri).to.equal(connectionString); expect(params.connectionInfo()?.is_atlas).to.equal(false); expect(params.connectionInfo()?.is_localhost).to.equal(true); diff --git a/packages/shell-api/src/mongo.ts b/packages/shell-api/src/mongo.ts index df45366d2f..1b7193628d 100644 --- a/packages/shell-api/src/mongo.ts +++ b/packages/shell-api/src/mongo.ts @@ -748,7 +748,7 @@ export default class Mongo< await this._serviceProvider.resetConnectionOptions(options); } - @topologies([Topologies.ReplSet]) + @topologies(['ReplSet']) startSession(options: Document = {}): Session { const allTransactionOptions = [ 'readConcern', @@ -845,7 +845,7 @@ export default class Mongo< } @serverVersions(['3.1.0', ServerVersions.latest]) - @topologies([Topologies.ReplSet, Topologies.Sharded]) + @topologies(['ReplSet', 'Sharded']) @apiVersions([1]) @returnsPromise async watch( diff --git a/packages/shell-api/src/shell-instance-state.ts b/packages/shell-api/src/shell-instance-state.ts index 03d98613d3..9e948a46df 100644 --- a/packages/shell-api/src/shell-instance-state.ts +++ b/packages/shell-api/src/shell-instance-state.ts @@ -569,16 +569,16 @@ export class ShellInstanceState { switch (topologyType) { case 'ReplicaSetNoPrimary': case 'ReplicaSetWithPrimary': - topology = Topologies.ReplSet; + topology = 'ReplSet'; break; case 'Sharded': - topology = Topologies.Sharded; + topology = 'Sharded'; break; case 'LoadBalanced': - topology = Topologies.LoadBalanced; + topology = 'LoadBalanced'; break; default: - topology = Topologies.Standalone; + topology = 'Standalone'; // We're connected to a single server, but that doesn't necessarily // mean that that server isn't part of a replset or sharding setup // if we're using directConnection=true (which we do by default). @@ -586,7 +586,7 @@ export class ShellInstanceState { const [server] = topologyDescription?.servers.values(); switch (server.type) { case 'Mongos': - topology = Topologies.Sharded; + topology = 'Sharded'; break; case 'PossiblePrimary': case 'RSPrimary': @@ -594,7 +594,7 @@ export class ShellInstanceState { case 'RSArbiter': case 'RSOther': case 'RSGhost': - topology = Topologies.ReplSet; + topology = 'ReplSet'; break; default: // Either Standalone, Unknown, or something so unknown that From ee303c503b31b135901480e1849c3ce851da54b2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 1 Dec 2025 15:28:00 +0100 Subject: [PATCH 2/4] fixup: types in files not covered by `npm run check` --- packages/build/src/barque.spec.ts | 2 +- .../src/serializer.spec.ts | 20 +++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/build/src/barque.spec.ts b/packages/build/src/barque.spec.ts index 8c1e36a950..55217f2397 100644 --- a/packages/build/src/barque.spec.ts +++ b/packages/build/src/barque.spec.ts @@ -333,7 +333,7 @@ describe('Barque', function () { }); it('platform is not linux', function () { - config.platform = 'macos'; + config.platform = 'darwin'; try { barque = new Barque(config); } catch (e: any) { diff --git a/packages/node-runtime-worker-thread/src/serializer.spec.ts b/packages/node-runtime-worker-thread/src/serializer.spec.ts index e0a5f763c4..85a77087b2 100644 --- a/packages/node-runtime-worker-thread/src/serializer.spec.ts +++ b/packages/node-runtime-worker-thread/src/serializer.spec.ts @@ -6,7 +6,6 @@ import { deserializeError, serializeEvaluationResult, deserializeEvaluationResult, - SerializedResultTypes, serializeConnectOptions, deserializeConnectOptions, } from './serializer'; @@ -50,10 +49,7 @@ describe('serializer', function () { printable: new SyntaxError('Ooops!'), }); - expect(serialized).to.have.property( - 'type', - SerializedResultTypes.SerializedErrorResult - ); + expect(serialized).to.have.property('type', 'SerializedErrorResult'); expect(serialized).to.have.property('printable').not.instanceof(Error); expect(serialized).to.have.nested.property( 'printable.name', @@ -68,10 +64,7 @@ describe('serializer', function () { printable: function abc() {}, }); - expect(serialized).to.have.property( - 'type', - SerializedResultTypes.InspectResult - ); + expect(serialized).to.have.property('type', 'InspectResult'); expect(serialized).to.have.property('printable', '[Function: abc]'); }); @@ -81,10 +74,7 @@ describe('serializer', function () { printable: { foo: 'bar' }, }); - expect(serialized).to.have.property( - 'type', - SerializedResultTypes.SerializedShellApiResult - ); + expect(serialized).to.have.property('type', 'SerializedShellApiResult'); expect(serialized).to.have.nested.property( 'printable.origType', 'TotallyRealShellApiType' @@ -100,7 +90,7 @@ describe('serializer', function () { describe('deserializeEvaluationResult', function () { it('should deserialize SerializedErrorResult', function () { const deserialized = deserializeEvaluationResult({ - type: SerializedResultTypes.SerializedErrorResult, + type: 'SerializedErrorResult', printable: { name: 'TypeError', message: 'Uh-oh' }, }); @@ -117,7 +107,7 @@ describe('serializer', function () { it('should deserialize SerializedShellApiResult', function () { const deserialized = deserializeEvaluationResult({ - type: SerializedResultTypes.SerializedShellApiResult, + type: 'SerializedShellApiResult', printable: { origType: 'ShellApiResult', serializedValue: { foo: 'bar' }, From eb2d60f04086ae282b600cd92a46540d85256193 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 1 Dec 2025 15:45:44 +0100 Subject: [PATCH 3/4] fixup: unused import --- packages/shell-api/src/mongo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shell-api/src/mongo.ts b/packages/shell-api/src/mongo.ts index 1b7193628d..0b5ccc1b36 100644 --- a/packages/shell-api/src/mongo.ts +++ b/packages/shell-api/src/mongo.ts @@ -50,7 +50,7 @@ import type ShellInstanceState from './shell-instance-state'; import { ClientBulkWriteResult } from './result'; import { CommandResult } from './result'; import { redactConnectionString } from 'mongodb-redact'; -import { asPrintable, ServerVersions, Topologies } from './enums'; +import { asPrintable, ServerVersions } from './enums'; import Session from './session'; import type { GenericServerSideSchema, StringKey } from './helpers'; import { From 9c241c163fe158579321d72f19699aad34395ba7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 1 Dec 2025 16:10:47 +0100 Subject: [PATCH 4/4] fixup: more unused/type-only imports --- packages/shell-api/src/database.ts | 2 +- packages/shell-api/src/integration.spec.ts | 2 +- packages/shell-api/src/shell-instance-state.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/shell-api/src/database.ts b/packages/shell-api/src/database.ts index e67dfcb068..fc2d0d3201 100644 --- a/packages/shell-api/src/database.ts +++ b/packages/shell-api/src/database.ts @@ -11,7 +11,7 @@ import { deprecated, ShellApiWithMongoClass, } from './decorators'; -import { asPrintable, ServerVersions, Topologies } from './enums'; +import { asPrintable, ServerVersions } from './enums'; import type { GenericDatabaseSchema, GenericServerSideSchema, diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index 1469711467..644c43e172 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -11,7 +11,7 @@ import { startSharedTestServer, } from '../../../testing/integration-testing-hooks'; import type { ShellApi, Mongo } from './index'; -import { toShellResult, Topologies } from './index'; +import { toShellResult } from './index'; import type { AnyBulkWriteOperation, Document, diff --git a/packages/shell-api/src/shell-instance-state.ts b/packages/shell-api/src/shell-instance-state.ts index 9e948a46df..4aae05f865 100644 --- a/packages/shell-api/src/shell-instance-state.ts +++ b/packages/shell-api/src/shell-instance-state.ts @@ -24,7 +24,7 @@ import { ALL_SERVER_VERSIONS, ALL_TOPOLOGIES, ServerVersions, - Topologies, + type Topologies, } from './enums'; import { ShellApiErrors } from './error-codes'; import type { ShellResult, DatabaseWithSchema } from './index';