Skip to content

Commit 05035eb

Browse files
authored
feat(NODE-3274): add type hinting for UpdateFilter (#2842)
1 parent e376632 commit 05035eb

16 files changed

+1469
-1803
lines changed

package-lock.json

+854-1,575
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@istanbuljs/nyc-config-typescript": "^1.0.1",
35-
"@microsoft/api-extractor": "^7.15.2",
35+
"@microsoft/api-extractor": "^7.16.1",
3636
"@microsoft/tsdoc-config": "^0.15.2",
3737
"@types/aws4": "^1.5.1",
3838
"@types/chai": "^4.2.14",
@@ -69,12 +69,12 @@
6969
"sinon-chai": "^3.2.0",
7070
"snappy": "^6.3.0",
7171
"source-map-support": "^0.5.19",
72-
"standard-version": "^9.1.1",
72+
"standard-version": "^9.3.0",
7373
"through2": "^3.0.1",
74-
"ts-node": "^9.1.1",
75-
"tsd": "^0.15.1",
76-
"typedoc": "^0.20.36",
77-
"typescript": "^4.2.4",
74+
"ts-node": "^10.0.0",
75+
"tsd": "^0.17.0",
76+
"typedoc": "^0.21.0",
77+
"typescript": "^4.3.4",
7878
"typescript-cached-transpile": "^0.0.6",
7979
"worker-farm": "^1.5.0",
8080
"wtfnode": "^0.8.2",
@@ -101,7 +101,7 @@
101101
"check:coverage": "nyc npm run check:test",
102102
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint",
103103
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
104-
"check:dts": "tsc --noEmit mongodb.d.ts",
104+
"check:dts": "tsc --noEmit mongodb.d.ts && tsd",
105105
"check:test": "mocha --recursive test/functional test/unit",
106106
"check:ts": "tsc -v && tsc --noEmit",
107107
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",

src/bulk/common.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type { Collection } from '../collection';
2525
import type { Topology } from '../sdam/topology';
2626
import type { CommandOperationOptions, CollationOptions } from '../operations/command';
2727
import type { Hint } from '../operations/operation';
28-
import type { Filter, OptionalId, UpdateQuery } from '../mongo_types';
28+
import type { Filter, OptionalId, UpdateFilter } from '../mongo_types';
2929

3030
/** @public */
3131
export const BatchType = Object.freeze({
@@ -82,7 +82,7 @@ export interface UpdateOneModel<TSchema extends Document = Document> {
8282
/** The filter to limit the updated documents. */
8383
filter: Filter<TSchema>;
8484
/** A document or pipeline containing update operators. */
85-
update: UpdateQuery<TSchema> | UpdateQuery<TSchema>[];
85+
update: UpdateFilter<TSchema> | UpdateFilter<TSchema>[];
8686
/** A set of filters specifying to which array elements an update should apply. */
8787
arrayFilters?: Document[];
8888
/** Specifies a collation. */
@@ -98,7 +98,7 @@ export interface UpdateManyModel<TSchema extends Document = Document> {
9898
/** The filter to limit the updated documents. */
9999
filter: Filter<TSchema>;
100100
/** A document or pipeline containing update operators. */
101-
update: UpdateQuery<TSchema> | UpdateQuery<TSchema>[];
101+
update: UpdateFilter<TSchema> | UpdateFilter<TSchema>[];
102102
/** A set of filters specifying to which array elements an update should apply. */
103103
arrayFilters?: Document[];
104104
/** Specifies a collation. */

src/cmap/auth/gssapi.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
7272
if ('kModuleError' in Kerberos) {
7373
return callback(Kerberos['kModuleError']);
7474
}
75+
const { initializeClient } = Kerberos;
7576

7677
const { username, password } = credentials;
7778
const mechanismProperties = credentials.mechanismProperties as MechanismProperties;
@@ -89,7 +90,7 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
8990
Object.assign(initOptions, { user: username, password: password });
9091
}
9192

92-
Kerberos.initializeClient(
93+
initializeClient(
9394
`${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`,
9495
initOptions,
9596
(err: string, client: KerberosClient): void => {

src/cmap/auth/mongodb_aws.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class MongoDBAWS extends AuthProvider {
3838
if ('kModuleError' in aws4) {
3939
return callback(aws4['kModuleError']);
4040
}
41+
const { sign } = aws4;
4142

4243
if (maxWireVersion(connection) < 9) {
4344
callback(
@@ -98,7 +99,7 @@ export class MongoDBAWS extends AuthProvider {
9899
}
99100

100101
const body = 'Action=GetCallerIdentity&Version=2011-06-15';
101-
const options = aws4.sign(
102+
const options = sign(
102103
{
103104
method: 'POST',
104105
host,

src/collection.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ import type { CountOptions } from './operations/count';
9292
import type {
9393
Filter,
9494
TODO_NODE_3286,
95-
UpdateQuery,
95+
UpdateFilter,
9696
WithId,
9797
OptionalId,
98-
FlattenIfArray
98+
Flatten
9999
} from './mongo_types';
100100

101101
/** @public */
@@ -414,27 +414,27 @@ export class Collection<TSchema extends Document = Document> {
414414
*/
415415
updateOne(
416416
filter: Filter<TSchema>,
417-
update: UpdateQuery<TSchema> | Partial<TSchema>
417+
update: UpdateFilter<TSchema> | Partial<TSchema>
418418
): Promise<UpdateResult | Document>;
419419
updateOne(
420420
filter: Filter<TSchema>,
421-
update: UpdateQuery<TSchema> | Partial<TSchema>,
421+
update: UpdateFilter<TSchema> | Partial<TSchema>,
422422
callback: Callback<UpdateResult | Document>
423423
): void;
424424
updateOne(
425425
filter: Filter<TSchema>,
426-
update: UpdateQuery<TSchema> | Partial<TSchema>,
426+
update: UpdateFilter<TSchema> | Partial<TSchema>,
427427
options: UpdateOptions
428428
): Promise<UpdateResult | Document>;
429429
updateOne(
430430
filter: Filter<TSchema>,
431-
update: UpdateQuery<TSchema> | Partial<TSchema>,
431+
update: UpdateFilter<TSchema> | Partial<TSchema>,
432432
options: UpdateOptions,
433433
callback: Callback<UpdateResult | Document>
434434
): void;
435435
updateOne(
436436
filter: Filter<TSchema>,
437-
update: UpdateQuery<TSchema> | Partial<TSchema>,
437+
update: UpdateFilter<TSchema> | Partial<TSchema>,
438438
options?: UpdateOptions | Callback<UpdateResult | Document>,
439439
callback?: Callback<UpdateResult | Document>
440440
): Promise<UpdateResult | Document> | void {
@@ -502,27 +502,27 @@ export class Collection<TSchema extends Document = Document> {
502502
*/
503503
updateMany(
504504
filter: Filter<TSchema>,
505-
update: UpdateQuery<TSchema>
505+
update: UpdateFilter<TSchema>
506506
): Promise<UpdateResult | Document>;
507507
updateMany(
508508
filter: Filter<TSchema>,
509-
update: UpdateQuery<TSchema>,
509+
update: UpdateFilter<TSchema>,
510510
callback: Callback<UpdateResult | Document>
511511
): void;
512512
updateMany(
513513
filter: Filter<TSchema>,
514-
update: UpdateQuery<TSchema>,
514+
update: UpdateFilter<TSchema>,
515515
options: UpdateOptions
516516
): Promise<UpdateResult | Document>;
517517
updateMany(
518518
filter: Filter<TSchema>,
519-
update: UpdateQuery<TSchema>,
519+
update: UpdateFilter<TSchema>,
520520
options: UpdateOptions,
521521
callback: Callback<UpdateResult | Document>
522522
): void;
523523
updateMany(
524524
filter: Filter<TSchema>,
525-
update: UpdateQuery<TSchema>,
525+
update: UpdateFilter<TSchema>,
526526
options?: UpdateOptions | Callback<UpdateResult | Document>,
527527
callback?: Callback<UpdateResult | Document>
528528
): Promise<UpdateResult | Document> | void {
@@ -1116,30 +1116,30 @@ export class Collection<TSchema extends Document = Document> {
11161116
*/
11171117
distinct<Key extends keyof WithId<TSchema>>(
11181118
key: Key
1119-
): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
1119+
): Promise<Array<Flatten<WithId<TSchema>[Key]>>>;
11201120
distinct<Key extends keyof WithId<TSchema>>(
11211121
key: Key,
1122-
callback: Callback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>
1122+
callback: Callback<Array<Flatten<WithId<TSchema>[Key]>>>
11231123
): void;
11241124
distinct<Key extends keyof WithId<TSchema>>(
11251125
key: Key,
11261126
filter: Filter<TSchema>
1127-
): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
1127+
): Promise<Array<Flatten<WithId<TSchema>[Key]>>>;
11281128
distinct<Key extends keyof WithId<TSchema>>(
11291129
key: Key,
11301130
filter: Filter<TSchema>,
1131-
callback: Callback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>
1131+
callback: Callback<Array<Flatten<WithId<TSchema>[Key]>>>
11321132
): void;
11331133
distinct<Key extends keyof WithId<TSchema>>(
11341134
key: Key,
11351135
filter: Filter<TSchema>,
11361136
options: DistinctOptions
1137-
): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
1137+
): Promise<Array<Flatten<WithId<TSchema>[Key]>>>;
11381138
distinct<Key extends keyof WithId<TSchema>>(
11391139
key: Key,
11401140
filter: Filter<TSchema>,
11411141
options: DistinctOptions,
1142-
callback: Callback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>
1142+
callback: Callback<Array<Flatten<WithId<TSchema>[Key]>>>
11431143
): void;
11441144

11451145
// Embedded documents overload
@@ -1320,27 +1320,27 @@ export class Collection<TSchema extends Document = Document> {
13201320
*/
13211321
findOneAndUpdate(
13221322
filter: Filter<TSchema>,
1323-
update: UpdateQuery<TSchema>
1323+
update: UpdateFilter<TSchema>
13241324
): Promise<ModifyResult<TSchema>>;
13251325
findOneAndUpdate(
13261326
filter: Filter<TSchema>,
1327-
update: UpdateQuery<TSchema>,
1327+
update: UpdateFilter<TSchema>,
13281328
callback: Callback<ModifyResult<TSchema>>
13291329
): void;
13301330
findOneAndUpdate(
13311331
filter: Filter<TSchema>,
1332-
update: UpdateQuery<TSchema>,
1332+
update: UpdateFilter<TSchema>,
13331333
options: FindOneAndUpdateOptions
13341334
): Promise<ModifyResult<TSchema>>;
13351335
findOneAndUpdate(
13361336
filter: Filter<TSchema>,
1337-
update: UpdateQuery<TSchema>,
1337+
update: UpdateFilter<TSchema>,
13381338
options: FindOneAndUpdateOptions,
13391339
callback: Callback<ModifyResult<TSchema>>
13401340
): void;
13411341
findOneAndUpdate(
13421342
filter: Filter<TSchema>,
1343-
update: UpdateQuery<TSchema>,
1343+
update: UpdateFilter<TSchema>,
13441344
options?: FindOneAndUpdateOptions | Callback<ModifyResult<TSchema>>,
13451345
callback?: Callback<ModifyResult<TSchema>>
13461346
): Promise<ModifyResult<TSchema>> | void {
@@ -1536,7 +1536,7 @@ export class Collection<TSchema extends Document = Document> {
15361536
*/
15371537
update(
15381538
selector: Filter<TSchema>,
1539-
update: UpdateQuery<TSchema>,
1539+
update: UpdateFilter<TSchema>,
15401540
options: UpdateOptions,
15411541
callback: Callback<Document>
15421542
): Promise<UpdateResult> | void {

src/deps.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ function makeErrorModule(error: any) {
1818
});
1919
}
2020

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

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

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

62-
export let aws4: typeof import('aws4') = makeErrorModule(
66+
export let aws4: typeof import('aws4') | { kModuleError: MongoDriverError } = makeErrorModule(
6367
new MongoDriverError(
6468
'Optional module `aws4` not found. Please install it to enable AWS authentication'
6569
)

src/index.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -363,19 +363,35 @@ export type {
363363
WithId,
364364
OptionalId,
365365
WithoutId,
366-
UpdateQuery,
366+
UpdateFilter,
367367
Filter,
368368
Projection,
369369
InferIdType,
370370
ProjectionOperators,
371-
FlattenIfArray,
371+
Flatten,
372372
SchemaMember,
373373
Condition,
374374
RootFilterOperators,
375375
AlternativeType,
376376
FilterOperators,
377377
BSONTypeAlias,
378378
BitwiseFilter,
379-
RegExpOrString
379+
RegExpOrString,
380+
OnlyFieldsOfType,
381+
NumericType,
382+
IntegerType,
383+
MatchKeysAndValues,
384+
SetFields,
385+
PullOperator,
386+
PushOperator,
387+
PullAllOperator,
388+
AcceptedFields,
389+
NotAcceptedFields,
390+
AddToSetOperators,
391+
ArrayOperator,
392+
FilterOperations,
393+
KeysOfAType,
394+
KeysOfOtherType,
395+
IsAny
380396
} from './mongo_types';
381397
export type { serialize, deserialize } from './bson';

0 commit comments

Comments
 (0)