Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum committed Jul 20, 2021
1 parent 3e45d6c commit 454d67e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/operations/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const VALID_INDEX_OPTIONS = new Set([
'expireAfterSeconds',
'storageEngine',
'collation',
'version',

// text indexes
'weights',
Expand Down Expand Up @@ -90,9 +91,12 @@ export interface CreateIndexesOptions extends CommandOperationOptions {
sparse?: boolean;
/** Allows you to expire data on indexes applied to a data (MongoDB 2.2 or higher) */
expireAfterSeconds?: number;
/** Allows users to configure the storage engine on a per-index basis when creating an index. (MongoDB 3.0 or higher) */
storageEngine?: Document;
/** (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes. */
commitQuorum?: number | string;
/** Specifies the index version number, either 0 or 1. */
version: number;
// text indexes
weights?: Document;
default_language?: string;
Expand All @@ -110,6 +114,8 @@ export interface CreateIndexesOptions extends CommandOperationOptions {
bucketSize?: number;
// wildcard indexes
wildcardProjection?: Document;
/** Specifies that the index should exist on the target collection but should not be used by the query planner when executing operations. (MongoDB 4.4 or higher) */
hidden: boolean;
}

function makeIndexSpec(indexSpec: IndexSpecification, options: any): IndexDescription {
Expand Down
28 changes: 28 additions & 0 deletions test/types/index_options.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expectType, expectNotType } from 'tsd';
import { IndexDescription } from '../../src';

// test that all valid index options are allowed in IndexDefinitions
expectType<IndexDescription>({
key: {},
background: true,
expireAfterSeconds: 2400,
name: 'index_1',
sparse: true,
storageEngine: {},
unique: true,
version: 1,
default_language: 'english',
language_override: 'english',
textIndexVersion: 2,
weights: {},
'2dsphereIndexVersion': 2,
bits: 1,
max: 1.1,
min: 9.9,
bucketSize: 100,
partialFilterExpression: {},
collation: { locale: 'en' },
wildcardProjection: {},
hidden: true
});
expectNotType<IndexDescription>({ key: {}, invalidOption: 2400 });
8 changes: 1 addition & 7 deletions test/types/mongodb.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expectType, expectDeprecated, expectError } from 'tsd';

import { expectType, expectDeprecated } from 'tsd';
import { MongoClient } from '../../src/mongo_client';
import { Collection } from '../../src/collection';
import { AggregationCursor } from '../../src/cursor/aggregation_cursor';
Expand Down Expand Up @@ -32,8 +31,3 @@ const composedMap = mappedAgg.map<string>(x => x.toString());
expectType<AggregationCursor<string>>(composedMap);
expectType<string | null>(await composedMap.next());
expectType<string[]>(await composedMap.toArray());

// test that VALID_INDEX_OPTIONS like expireAfterSeconds are allowed in IndexDefinitions
coll.createIndexes([{ key: { event: 1 }, name: 'event', expireAfterSeconds: 2400 }]);
// test that invalid options are not allowed
expectError(coll.createIndexes([{ key: { event: 1 }, name: 'event', invalidOption: 2400 }]));

0 comments on commit 454d67e

Please sign in to comment.