Skip to content

Commit

Permalink
fix: ts and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Jun 29, 2021
1 parent 78f6e72 commit 3fd26fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/operations/is_capped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class IsCappedOperation extends AbstractOperation<boolean> {
coll.s.db
.listCollections(
{ name: coll.collectionName },
{ ...this.options, readPreference: this.readPreference, session }
{ ...this.options, nameOnly: false, readPreference: this.readPreference, session }
)
.toArray((err, collections) => {
if (err || !collections) return callback(err);
Expand Down
2 changes: 1 addition & 1 deletion src/operations/options_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class OptionsOperation extends AbstractOperation<Document> {
coll.s.db
.listCollections(
{ name: coll.collectionName },
{ ...this.options, readPreference: this.readPreference, session }
{ ...this.options, nameOnly: false, readPreference: this.readPreference, session }
)
.toArray((err, collections) => {
if (err || !collections) return callback(err);
Expand Down
6 changes: 4 additions & 2 deletions test/types/list_collections.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { CollectionInfo, ListCollectionsCursor } from '../../src/operations

const db = new MongoClient('').db();

type EitherCollectionInfoResult = CollectionInfo | Pick<CollectionInfo, 'name' | 'type'>;

// We default to the CollectionInfo result type
expectType<ListCollectionsCursor<Pick<CollectionInfo, 'name' | 'type'> | CollectionInfo>>(
db.listCollections()
Expand All @@ -19,7 +21,7 @@ db.listCollections({ a: 2 });
db.listCollections({ a: 2 }, { batchSize: 2 });

const collections = await db.listCollections().toArray();
expectType<(CollectionInfo | string)[]>(collections);
expectType<EitherCollectionInfoResult[]>(collections);

const nameOnly = await db.listCollections({}, { nameOnly: true }).toArray();
expectType<Pick<CollectionInfo, 'name' | 'type'>[]>(nameOnly);
Expand All @@ -28,7 +30,7 @@ const fullInfo = await db.listCollections({}, { nameOnly: false }).toArray();
expectType<CollectionInfo[]>(fullInfo);

const couldBeEither = await db.listCollections({}, { nameOnly: Math.random() > 0.5 }).toArray();
expectType<(CollectionInfo | string)[]>(couldBeEither);
expectType<EitherCollectionInfoResult[]>(couldBeEither);

// Showing here that:
// regardless of the option the generic parameter can be used to coerce the result if need be
Expand Down

0 comments on commit 3fd26fe

Please sign in to comment.