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
2,429 changes: 854 additions & 1,575 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@microsoft/api-extractor": "^7.15.2",
"@microsoft/api-extractor": "^7.16.1",
"@microsoft/tsdoc-config": "^0.15.2",
"@types/aws4": "^1.5.1",
"@types/chai": "^4.2.14",
Expand Down Expand Up @@ -68,12 +68,12 @@
"sinon-chai": "^3.2.0",
"snappy": "^6.3.0",
"source-map-support": "^0.5.19",
"standard-version": "^9.1.1",
"standard-version": "^9.3.0",
"through2": "^3.0.1",
"ts-node": "^9.1.1",
"tsd": "^0.15.1",
"typedoc": "^0.20.36",
"typescript": "^4.2.4",
"ts-node": "^10.0.0",
"tsd": "^0.17.0",
"typedoc": "^0.21.0",
"typescript": "^4.3.4",
"typescript-cached-transpile": "^0.0.6",
"worker-farm": "^1.5.0",
"wtfnode": "^0.8.2",
Expand All @@ -100,7 +100,7 @@
"check:coverage": "nyc npm run check:test",
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint",
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
"check:dts": "tsc --noEmit mongodb.d.ts",
"check:dts": "tsc --noEmit mongodb.d.ts && tsd",
"check:test": "mocha --recursive test/functional test/unit",
"check:ts": "tsc -v && tsc --noEmit",
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
Expand Down
6 changes: 3 additions & 3 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Collection } from '../collection';
import type { Topology } from '../sdam/topology';
import type { CommandOperationOptions, CollationOptions } from '../operations/command';
import type { Hint } from '../operations/operation';
import type { Filter, OptionalId, UpdateQuery } from '../mongo_types';
import type { Filter, OptionalId, UpdateFilter } from '../mongo_types';

/** @public */
export const BatchType = Object.freeze({
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface UpdateOneModel<TSchema extends Document = Document> {
/** The filter to limit the updated documents. */
filter: Filter<TSchema>;
/** A document or pipeline containing update operators. */
update: UpdateQuery<TSchema> | UpdateQuery<TSchema>[];
update: UpdateFilter<TSchema> | UpdateFilter<TSchema>[];
/** A set of filters specifying to which array elements an update should apply. */
arrayFilters?: Document[];
/** Specifies a collation. */
Expand All @@ -98,7 +98,7 @@ export interface UpdateManyModel<TSchema extends Document = Document> {
/** The filter to limit the updated documents. */
filter: Filter<TSchema>;
/** A document or pipeline containing update operators. */
update: UpdateQuery<TSchema> | UpdateQuery<TSchema>[];
update: UpdateFilter<TSchema> | UpdateFilter<TSchema>[];
/** A set of filters specifying to which array elements an update should apply. */
arrayFilters?: Document[];
/** Specifies a collation. */
Expand Down
3 changes: 2 additions & 1 deletion src/cmap/auth/gssapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
if ('kModuleError' in Kerberos) {
return callback(Kerberos['kModuleError']);
}
const { initializeClient } = Kerberos;
Copy link
Contributor

Choose a reason for hiding this comment

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

What motivated pulling this out vs leaving it as Kerberos.initializeClient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cus Typescript! tsd has its own version of TS which was a version newer and these lines were throwing errors. You'll notice the deps.ts file needed changes to make the types more accurate. Pulling out the function here after you've narrowed the type makes it exist properly inside the callback below. Where as Kerberos.initializeClient has the error that the property potentially doesn't exist.

I can move the narrowing down into the callback too or just cast this problem away, open to diff solutions here

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine - slightly less readable, but not so bad as to necessitate a change.


const { username, password, mechanismProperties } = credentials;
const serviceName =
Expand All @@ -89,7 +90,7 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
Object.assign(initOptions, { user: username, password: password });
}

Kerberos.initializeClient(
initializeClient(
`${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`,
initOptions,
(err: string, client: KerberosClient): void => {
Expand Down
3 changes: 2 additions & 1 deletion src/cmap/auth/mongodb_aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MongoDBAWS extends AuthProvider {
if ('kModuleError' in aws4) {
return callback(aws4['kModuleError']);
}
const { sign } = aws4;

if (maxWireVersion(connection) < 9) {
callback(
Expand Down Expand Up @@ -97,7 +98,7 @@ export class MongoDBAWS extends AuthProvider {
}

const body = 'Action=GetCallerIdentity&Version=2011-06-15';
const options = aws4.sign(
const options = sign(
{
method: 'POST',
host,
Expand Down
48 changes: 24 additions & 24 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ import type { CountOptions } from './operations/count';
import type {
Filter,
TODO_NODE_3286,
UpdateQuery,
UpdateFilter,
WithId,
OptionalId,
FlattenIfArray
Flatten
} from './mongo_types';

/** @public */
Expand Down Expand Up @@ -414,27 +414,27 @@ export class Collection<TSchema extends Document = Document> {
*/
updateOne(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema> | Partial<TSchema>
update: UpdateFilter<TSchema> | Partial<TSchema>
): Promise<UpdateResult | Document>;
updateOne(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema> | Partial<TSchema>,
update: UpdateFilter<TSchema> | Partial<TSchema>,
callback: Callback<UpdateResult | Document>
): void;
updateOne(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema> | Partial<TSchema>,
update: UpdateFilter<TSchema> | Partial<TSchema>,
options: UpdateOptions
): Promise<UpdateResult | Document>;
updateOne(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema> | Partial<TSchema>,
update: UpdateFilter<TSchema> | Partial<TSchema>,
options: UpdateOptions,
callback: Callback<UpdateResult | Document>
): void;
updateOne(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema> | Partial<TSchema>,
update: UpdateFilter<TSchema> | Partial<TSchema>,
options?: UpdateOptions | Callback<UpdateResult | Document>,
callback?: Callback<UpdateResult | Document>
): Promise<UpdateResult | Document> | void {
Expand Down Expand Up @@ -502,27 +502,27 @@ export class Collection<TSchema extends Document = Document> {
*/
updateMany(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>
update: UpdateFilter<TSchema>
): Promise<UpdateResult | Document>;
updateMany(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
callback: Callback<UpdateResult | Document>
): void;
updateMany(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options: UpdateOptions
): Promise<UpdateResult | Document>;
updateMany(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options: UpdateOptions,
callback: Callback<UpdateResult | Document>
): void;
updateMany(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options?: UpdateOptions | Callback<UpdateResult | Document>,
callback?: Callback<UpdateResult | Document>
): Promise<UpdateResult | Document> | void {
Expand Down Expand Up @@ -1116,30 +1116,30 @@ export class Collection<TSchema extends Document = Document> {
*/
distinct<Key extends keyof WithId<TSchema>>(
key: Key
): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
): Promise<Array<Flatten<WithId<TSchema>[Key]>>>;
distinct<Key extends keyof WithId<TSchema>>(
key: Key,
callback: Callback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>
callback: Callback<Array<Flatten<WithId<TSchema>[Key]>>>
): void;
distinct<Key extends keyof WithId<TSchema>>(
key: Key,
filter: Filter<TSchema>
): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
): Promise<Array<Flatten<WithId<TSchema>[Key]>>>;
distinct<Key extends keyof WithId<TSchema>>(
key: Key,
filter: Filter<TSchema>,
callback: Callback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>
callback: Callback<Array<Flatten<WithId<TSchema>[Key]>>>
): void;
distinct<Key extends keyof WithId<TSchema>>(
key: Key,
filter: Filter<TSchema>,
options: DistinctOptions
): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
): Promise<Array<Flatten<WithId<TSchema>[Key]>>>;
distinct<Key extends keyof WithId<TSchema>>(
key: Key,
filter: Filter<TSchema>,
options: DistinctOptions,
callback: Callback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>
callback: Callback<Array<Flatten<WithId<TSchema>[Key]>>>
): void;

// Embedded documents overload
Expand Down Expand Up @@ -1320,27 +1320,27 @@ export class Collection<TSchema extends Document = Document> {
*/
findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>
update: UpdateFilter<TSchema>
): Promise<ModifyResult<TSchema>>;
findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
callback: Callback<ModifyResult<TSchema>>
): void;
findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options: FindOneAndUpdateOptions
): Promise<ModifyResult<TSchema>>;
findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options: FindOneAndUpdateOptions,
callback: Callback<ModifyResult<TSchema>>
): void;
findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options?: FindOneAndUpdateOptions | Callback<ModifyResult<TSchema>>,
callback?: Callback<ModifyResult<TSchema>>
): Promise<ModifyResult<TSchema>> | void {
Expand Down Expand Up @@ -1536,7 +1536,7 @@ export class Collection<TSchema extends Document = Document> {
*/
update(
selector: Filter<TSchema>,
update: UpdateQuery<TSchema>,
update: UpdateFilter<TSchema>,
options: UpdateOptions,
callback: Callback<Document>
): Promise<UpdateResult> | void {
Expand Down
12 changes: 8 additions & 4 deletions src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function makeErrorModule(error: any) {
});
}

export let Kerberos: typeof import('kerberos') = makeErrorModule(
export let Kerberos:
| typeof import('kerberos')
| { kModuleError: MongoDriverError } = makeErrorModule(
new MongoDriverError(
'Optional module `kerberos` not found. Please install it to enable kerberos authentication'
)
Expand All @@ -38,7 +40,7 @@ export interface KerberosClient {
unwrap: (challenge: string, callback?: Callback<string>) => Promise<string> | void;
}

export let Snappy: typeof import('snappy') = makeErrorModule(
export let Snappy: typeof import('snappy') | { kModuleError: MongoDriverError } = makeErrorModule(
new MongoDriverError(
'Optional module `snappy` not found. Please install it to enable snappy compression'
)
Expand All @@ -48,7 +50,9 @@ try {
Snappy = require('snappy');
} catch {} // eslint-disable-line

export let saslprep: typeof import('saslprep') = makeErrorModule(
export let saslprep:
| typeof import('saslprep')
| { kModuleError: MongoDriverError } = makeErrorModule(
new MongoDriverError(
'Optional module `saslprep` not found.' +
' Please install it to enable Stringprep Profile for User Names and Passwords'
Expand All @@ -59,7 +63,7 @@ try {
saslprep = require('saslprep');
} catch {} // eslint-disable-line

export let aws4: typeof import('aws4') = makeErrorModule(
export let aws4: typeof import('aws4') | { kModuleError: MongoDriverError } = makeErrorModule(
new MongoDriverError(
'Optional module `aws4` not found. Please install it to enable AWS authentication'
)
Expand Down
22 changes: 19 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,35 @@ export type {
WithId,
OptionalId,
WithoutId,
UpdateQuery,
UpdateFilter,
Filter,
Projection,
InferIdType,
ProjectionOperators,
FlattenIfArray,
Flatten,
SchemaMember,
Condition,
RootFilterOperators,
AlternativeType,
FilterOperators,
BSONTypeAlias,
BitwiseFilter,
RegExpOrString
RegExpOrString,
OnlyFieldsOfType,
NumericType,
IntegerType,
MatchKeysAndValues,
SetFields,
PullOperator,
PushOperator,
PullAllOperator,
AcceptedFields,
NotAcceptedFields,
AddToSetOperators,
ArrayOperator,
FilterOperations,
KeysOfAType,
KeysOfOtherType,
IsAny
} from './mongo_types';
export type { serialize, deserialize } from './bson';
Loading