Skip to content

Commit 6e1d094

Browse files
committed
fix: remove Enum suffix
1 parent 86a3282 commit 6e1d094

File tree

10 files changed

+83
-83
lines changed

10 files changed

+83
-83
lines changed

src/cmap/auth/defaultAuthProviders.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MongoDBAWS } from './mongodb_aws';
77
import type { AuthProvider } from './auth_provider';
88

99
/** @public */
10-
export const AuthMechanismEnum = {
10+
export const AuthMechanism = {
1111
MONGODB_AWS: 'MONGODB-AWS',
1212
MONGODB_CR: 'MONGODB-CR',
1313
MONGODB_DEFAULT: 'DEFAULT',
@@ -19,16 +19,16 @@ export const AuthMechanismEnum = {
1919
} as const;
2020

2121
/** @public */
22-
export type AuthMechanism = typeof AuthMechanismEnum[keyof typeof AuthMechanismEnum];
22+
export type AuthMechanismId = typeof AuthMechanism[keyof typeof AuthMechanism];
2323

2424
export const AUTH_PROVIDERS = {
25-
[AuthMechanismEnum.MONGODB_AWS]: new MongoDBAWS(),
26-
[AuthMechanismEnum.MONGODB_CR]: new MongoCR(),
27-
[AuthMechanismEnum.MONGODB_GSSAPI]: new GSSAPI(),
28-
[AuthMechanismEnum.MONGODB_PLAIN]: new Plain(),
29-
[AuthMechanismEnum.MONGODB_SCRAM_SHA1]: new ScramSHA1(),
30-
[AuthMechanismEnum.MONGODB_SCRAM_SHA256]: new ScramSHA256(),
31-
[AuthMechanismEnum.MONGODB_X509]: new X509()
25+
[AuthMechanism.MONGODB_AWS]: new MongoDBAWS(),
26+
[AuthMechanism.MONGODB_CR]: new MongoCR(),
27+
[AuthMechanism.MONGODB_GSSAPI]: new GSSAPI(),
28+
[AuthMechanism.MONGODB_PLAIN]: new Plain(),
29+
[AuthMechanism.MONGODB_SCRAM_SHA1]: new ScramSHA1(),
30+
[AuthMechanism.MONGODB_SCRAM_SHA256]: new ScramSHA256(),
31+
[AuthMechanism.MONGODB_X509]: new X509()
3232
};
3333

3434
// TODO: We can make auth mechanism more functional since we pass around a context object

src/cmap/auth/mongo_credentials.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
import type { Document } from '../../bson';
44
import { MongoParseError } from '../../error';
5-
import { AuthMechanism, AuthMechanismEnum } from './defaultAuthProviders';
5+
import { AuthMechanismId, AuthMechanism } from './defaultAuthProviders';
66

77
// https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst
8-
function getDefaultAuthMechanism(ismaster?: Document): AuthMechanism {
8+
function getDefaultAuthMechanism(ismaster?: Document): AuthMechanismId {
99
if (ismaster) {
1010
// If ismaster contains saslSupportedMechs, use scram-sha-256
1111
// if it is available, else scram-sha-1
1212
if (Array.isArray(ismaster.saslSupportedMechs)) {
1313
return ismaster.saslSupportedMechs.indexOf('SCRAM-SHA-256') >= 0
14-
? AuthMechanismEnum.MONGODB_SCRAM_SHA256
15-
: AuthMechanismEnum.MONGODB_SCRAM_SHA1;
14+
? AuthMechanism.MONGODB_SCRAM_SHA256
15+
: AuthMechanism.MONGODB_SCRAM_SHA1;
1616
}
1717

1818
// Fallback to legacy selection method. If wire version >= 3, use scram-sha-1
1919
if (ismaster.maxWireVersion >= 3) {
20-
return AuthMechanismEnum.MONGODB_SCRAM_SHA1;
20+
return AuthMechanism.MONGODB_SCRAM_SHA1;
2121
}
2222
}
2323

2424
// Default for wireprotocol < 3
25-
return AuthMechanismEnum.MONGODB_CR;
25+
return AuthMechanism.MONGODB_CR;
2626
}
2727

2828
/** @public */
@@ -31,7 +31,7 @@ export interface MongoCredentialsOptions {
3131
password: string;
3232
source: string;
3333
db?: string;
34-
mechanism?: AuthMechanism;
34+
mechanism?: AuthMechanismId;
3535
mechanismProperties: Document;
3636
}
3737

@@ -47,7 +47,7 @@ export class MongoCredentials {
4747
/** The database that the user should authenticate against */
4848
readonly source: string;
4949
/** The method used to authenticate */
50-
readonly mechanism: AuthMechanism;
50+
readonly mechanism: AuthMechanismId;
5151
/** Special properties used by some types of auth mechanisms */
5252
readonly mechanismProperties: Document;
5353

@@ -58,7 +58,7 @@ export class MongoCredentials {
5858
if (!this.source && options.db) {
5959
this.source = options.db;
6060
}
61-
this.mechanism = options.mechanism || AuthMechanismEnum.MONGODB_DEFAULT;
61+
this.mechanism = options.mechanism || AuthMechanism.MONGODB_DEFAULT;
6262
this.mechanismProperties = options.mechanismProperties || {};
6363

6464
if (this.mechanism.match(/MONGODB-AWS/i)) {

src/cmap/auth/mongodb_aws.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { maxWireVersion, Callback } from '../../utils';
99
import type { BSONSerializeOptions } from '../../bson';
1010

1111
import { aws4 } from '../../deps';
12-
import { AuthMechanismEnum } from './defaultAuthProviders';
12+
import { AuthMechanism } from './defaultAuthProviders';
1313

1414
const ASCII_N = 110;
1515
const AWS_RELATIVE_URI = 'http://169.254.170.2';
@@ -155,7 +155,7 @@ function makeTempCredentials(credentials: MongoCredentials, callback: Callback<M
155155
username: creds.AccessKeyId,
156156
password: creds.SecretAccessKey,
157157
source: credentials.source,
158-
mechanism: AuthMechanismEnum.MONGODB_AWS,
158+
mechanism: AuthMechanism.MONGODB_AWS,
159159
mechanismProperties: {
160160
AWS_SESSION_TOKEN: creds.Token
161161
}

src/cmap/connect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as net from 'net';
22
import * as tls from 'tls';
33
import { Connection, ConnectionOptions } from './connection';
44
import { MongoError, MongoNetworkError, MongoNetworkTimeoutError, AnyError } from '../error';
5-
import { defaultAuthProviders, AuthMechanismEnum } from './auth/defaultAuthProviders';
5+
import { defaultAuthProviders, AuthMechanism } from './auth/defaultAuthProviders';
66
import { AuthContext } from './auth/auth_provider';
77
import { makeClientMetadata, ClientMetadata, Callback, CallbackWithType } from '../utils';
88
import {
@@ -179,7 +179,7 @@ function prepareHandshakeDocument(authContext: AuthContext, callback: Callback<H
179179
});
180180

181181
let provider;
182-
if ((provider = AUTH_PROVIDERS[AuthMechanismEnum.MONGODB_SCRAM_SHA256])) {
182+
if ((provider = AUTH_PROVIDERS[AuthMechanism.MONGODB_SCRAM_SHA256])) {
183183
// This auth mechanism is always present.
184184
provider.prepare(handshakeDoc, authContext, callback);
185185
return;

src/connection_string.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as url from 'url';
22
import * as qs from 'querystring';
33
import * as dns from 'dns';
44
import { URL } from 'url';
5-
import { AuthMechanismEnum } from './cmap/auth/defaultAuthProviders';
6-
import { ReadPreference, ReadPreferenceMode } from './read_preference';
7-
import { ReadConcern, ReadConcernLevel } from './read_concern';
5+
import { AuthMechanism } from './cmap/auth/defaultAuthProviders';
6+
import { ReadPreference, ReadPreferenceModeId } from './read_preference';
7+
import { ReadConcern, ReadConcernLevelId } from './read_concern';
88
import { W, WriteConcern } from './write_concern';
99
import { MongoParseError } from './error';
1010
import type { AnyOptions, Callback } from './utils';
@@ -1100,7 +1100,7 @@ export const OPTIONS: Record<keyof MongoClientOptions, OptionDescriptor> = {
11001100
authMechanism: {
11011101
rename: 'credentials',
11021102
transform({ options, values: [value] }): MongoCredentials {
1103-
const mechanisms = Object.values(AuthMechanismEnum);
1103+
const mechanisms = Object.values(AuthMechanism);
11041104
const [mechanism] = mechanisms.filter(m => m.match(RegExp(String.raw`\b${value}\b`, 'i')));
11051105
if (!mechanism) {
11061106
throw new TypeError(`authMechanism one of ${mechanisms}, got ${value}`);
@@ -1403,7 +1403,7 @@ export const OPTIONS: Record<keyof MongoClientOptions, OptionDescriptor> = {
14031403
transform({ values: [level], options }) {
14041404
return ReadConcern.fromOptions({
14051405
...options.readConcern,
1406-
level: level as ReadConcernLevel
1406+
level: level as ReadConcernLevelId
14071407
});
14081408
}
14091409
},
@@ -1423,7 +1423,7 @@ export const OPTIONS: Record<keyof MongoClientOptions, OptionDescriptor> = {
14231423
maxStalenessSeconds: options.readPreference?.maxStalenessSeconds
14241424
};
14251425
return new ReadPreference(
1426-
value as ReadPreferenceMode,
1426+
value as ReadPreferenceModeId,
14271427
options.readPreference?.tags,
14281428
rpOpts
14291429
);

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type {
104104
OperationTime,
105105
ResumeOptions
106106
} from './change_stream';
107-
export type { AuthMechanism, AuthMechanismEnum } from './cmap/auth/defaultAuthProviders';
107+
export type { AuthMechanism, AuthMechanismId } from './cmap/auth/defaultAuthProviders';
108108
export type { MongoCredentials, MongoCredentialsOptions } from './cmap/auth/mongo_credentials';
109109
export type {
110110
WriteProtocolMessageType,
@@ -176,7 +176,7 @@ export type {
176176
PkFactory,
177177
MongoURIOptions,
178178
LogLevel,
179-
LogLevelEnum,
179+
LogLevelId,
180180
Auth,
181181
DriverInfo
182182
} from './mongo_client';
@@ -234,13 +234,13 @@ export type { ValidateCollectionOptions } from './operations/validate_collection
234234
export type {
235235
ReadConcern,
236236
ReadConcernLike,
237-
ReadConcernLevelEnum,
238-
ReadConcernLevel
237+
ReadConcernLevel,
238+
ReadConcernLevelId
239239
} from './read_concern';
240240
export type {
241241
ReadPreferenceLike,
242+
ReadPreferenceModeId,
242243
ReadPreferenceMode,
243-
ReadPreferenceModeEnum,
244244
ReadPreferenceOptions,
245245
ReadPreferenceLikeOptions,
246246
ReadPreferenceFromOptions,

src/mongo_client.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Db, DbOptions } from './db';
22
import { EventEmitter } from 'events';
33
import { ChangeStream, ChangeStreamOptions } from './change_stream';
4-
import { ReadPreference, ReadPreferenceMode } from './read_preference';
4+
import { ReadPreference, ReadPreferenceModeId } from './read_preference';
55
import { MongoError, AnyError } from './error';
66
import { WriteConcern, WriteConcernOptions } from './write_concern';
77
import { maybePromise, MongoDBNamespace, Callback } from './utils';
88
import { deprecate } from 'util';
99
import { connect, validOptions } from './operations/connect';
1010
import { PromiseProvider } from './promise_provider';
1111
import { Logger } from './logger';
12-
import { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
12+
import { ReadConcern, ReadConcernLevelId, ReadConcernLike } from './read_concern';
1313
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
1414
import type { AutoEncryptionOptions } from './deps';
1515
import type { CompressorName } from './cmap/wire_protocol/compression';
16-
import type { AuthMechanism } from './cmap/auth/defaultAuthProviders';
16+
import type { AuthMechanismId } from './cmap/auth/defaultAuthProviders';
1717
import type { Topology } from './sdam/topology';
1818
import type { ClientSession, ClientSessionOptions } from './sessions';
1919
import type { OperationParent } from './operations/command';
@@ -24,15 +24,15 @@ import type { MongoCredentials } from './cmap/auth/mongo_credentials';
2424
import { parseOptions } from './connection_string';
2525

2626
/** @public */
27-
export const LogLevelEnum = {
27+
export const LogLevel = {
2828
error: 'error',
2929
warn: 'warn',
3030
info: 'info',
3131
debug: 'debug'
3232
} as const;
3333

3434
/** @public */
35-
export type LogLevel = typeof LogLevelEnum[keyof typeof LogLevelEnum];
35+
export type LogLevelId = typeof LogLevel[keyof typeof LogLevel];
3636

3737
/** @public */
3838
export interface DriverInfo {
@@ -99,17 +99,17 @@ export interface MongoURIOptions extends Pick<WriteConcernOptions, 'journal' | '
9999
/** The maximum time in milliseconds that a thread can wait for a connection to become available. */
100100
waitQueueTimeoutMS?: number;
101101
/** The level of isolation */
102-
readConcernLevel?: ReadConcernLevel;
102+
readConcernLevel?: ReadConcernLevelId;
103103
/** Specifies the read preferences for this connection */
104-
readPreference?: ReadPreferenceMode | ReadPreference;
104+
readPreference?: ReadPreferenceModeId | ReadPreference;
105105
/** Specifies, in seconds, how stale a secondary can be before the client stops using it for read operations. */
106106
maxStalenessSeconds?: number;
107107
/** Specifies the tags document as a comma-separated list of colon-separated key-value pairs. */
108108
readPreferenceTags?: TagSet[];
109109
/** Specify the database name associated with the user’s credentials. */
110110
authSource?: string;
111111
/** Specify the authentication mechanism that MongoDB will use to authenticate the connection. */
112-
authMechanism?: AuthMechanism;
112+
authMechanism?: AuthMechanismId;
113113
/** Specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs. */
114114
authMechanismProperties?: {
115115
SERVICE_NAME?: string;
@@ -181,7 +181,7 @@ export interface MongoClientOptions
181181
/** Specify a read concern for the collection (only MongoDB 3.2 or higher supported) */
182182
readConcern?: ReadConcernLike;
183183
/** The logging level */
184-
loggerLevel?: LogLevel;
184+
loggerLevel?: LogLevelId;
185185
/** Custom logger object */
186186
logger?: Logger;
187187
/** The auth settings for when connection to server. */

src/operations/connect.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as BSON from '../bson';
1212
import type { Document } from '../bson';
1313
import type { MongoClient } from '../mongo_client';
1414
import { ConnectionOptions, Connection } from '../cmap/connection';
15-
import type { AuthMechanism } from '../cmap/auth/defaultAuthProviders';
15+
import type { AuthMechanismId } from '../cmap/auth/defaultAuthProviders';
1616
import { Server } from '../sdam/server';
1717

1818
const VALID_AUTH_MECHANISMS = new Set([
@@ -444,7 +444,7 @@ export interface GenerateCredentialsOptions {
444444
authSource: string;
445445
authdb: string;
446446
dbName: string;
447-
authMechanism: AuthMechanism;
447+
authMechanism: AuthMechanismId;
448448
authMechanismProperties: Document;
449449
}
450450

@@ -462,15 +462,15 @@ function generateCredentials(
462462

463463
// authMechanism
464464
const authMechanismRaw = options.authMechanism || 'DEFAULT';
465-
const authMechanism = authMechanismRaw.toUpperCase();
465+
const mechanism = authMechanismRaw.toUpperCase() as AuthMechanismId;
466466
const mechanismProperties = options.authMechanismProperties;
467467

468-
if (!VALID_AUTH_MECHANISMS.has(authMechanism)) {
469-
throw new MongoError(`authentication mechanism ${authMechanism} not supported`);
468+
if (!VALID_AUTH_MECHANISMS.has(mechanism)) {
469+
throw new MongoError(`authentication mechanism ${mechanism} not supported`);
470470
}
471471

472472
return new MongoCredentials({
473-
mechanism: authMechanism as AuthMechanism,
473+
mechanism,
474474
mechanismProperties,
475475
source,
476476
username,

src/read_concern.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @public */
2-
export const ReadConcernLevelEnum = {
2+
export const ReadConcernLevel = {
33
local: 'local',
44
majority: 'majority',
55
linearizable: 'linearizable',
@@ -8,10 +8,10 @@ export const ReadConcernLevelEnum = {
88
} as const;
99

1010
/** @public */
11-
export type ReadConcernLevel = keyof typeof ReadConcernLevelEnum;
11+
export type ReadConcernLevelId = keyof typeof ReadConcernLevel;
1212

1313
/** @public */
14-
export type ReadConcernLike = ReadConcern | { level: ReadConcernLevel } | ReadConcernLevel;
14+
export type ReadConcernLike = ReadConcern | { level: ReadConcernLevelId } | ReadConcernLevelId;
1515

1616
/**
1717
* The MongoDB ReadConcern, which allows for control of the consistency and isolation properties
@@ -21,17 +21,17 @@ export type ReadConcernLike = ReadConcern | { level: ReadConcernLevel } | ReadCo
2121
* @see https://docs.mongodb.com/manual/reference/read-concern/index.html
2222
*/
2323
export class ReadConcern {
24-
level: ReadConcernLevel | string;
24+
level: ReadConcernLevelId | string;
2525

2626
/** Constructs a ReadConcern from the read concern level.*/
27-
constructor(level: ReadConcernLevel) {
27+
constructor(level: ReadConcernLevelId) {
2828
/**
2929
* A spec test exists that allows level to be any string.
3030
* "invalid readConcern with out stage"
3131
* @see ./test/spec/crud/v2/aggregate-out-readConcern.json
3232
* @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#unknown-levels-and-additional-options-for-string-based-readconcerns
3333
*/
34-
this.level = ReadConcernLevelEnum[level] || level;
34+
this.level = ReadConcernLevel[level] ?? level;
3535
}
3636

3737
/**
@@ -41,7 +41,7 @@ export class ReadConcern {
4141
*/
4242
static fromOptions(options?: {
4343
readConcern?: ReadConcernLike;
44-
level?: ReadConcernLevel;
44+
level?: ReadConcernLevelId;
4545
}): ReadConcern | undefined {
4646
if (options == null) {
4747
return;
@@ -64,18 +64,18 @@ export class ReadConcern {
6464
}
6565

6666
static get MAJORITY(): 'majority' {
67-
return ReadConcernLevelEnum.majority;
67+
return ReadConcernLevel.majority;
6868
}
6969

7070
static get AVAILABLE(): 'available' {
71-
return ReadConcernLevelEnum.available;
71+
return ReadConcernLevel.available;
7272
}
7373

7474
static get LINEARIZABLE(): 'linearizable' {
75-
return ReadConcernLevelEnum.linearizable;
75+
return ReadConcernLevel.linearizable;
7676
}
7777

7878
static get SNAPSHOT(): 'snapshot' {
79-
return ReadConcernLevelEnum.snapshot;
79+
return ReadConcernLevel.snapshot;
8080
}
8181
}

0 commit comments

Comments
 (0)