From 6f7b942473d99ff39795cf5783b5bca864fd54f6 Mon Sep 17 00:00:00 2001 From: Cheng Tak Kin Date: Wed, 5 Oct 2022 00:11:56 +0800 Subject: [PATCH] feat(NODE-3651): add hashed index type (#3432) --- src/operations/indexes.ts | 11 ++++++++++- test/types/community/createIndex.test-d.ts | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/operations/indexes.ts b/src/operations/indexes.ts index f1dfceeaa7..3a3b72dc30 100644 --- a/src/operations/indexes.ts +++ b/src/operations/indexes.ts @@ -50,7 +50,16 @@ const VALID_INDEX_OPTIONS = new Set([ ]); /** @public */ -export type IndexDirection = -1 | 1 | '2d' | '2dsphere' | 'text' | 'geoHaystack' | number; +export type IndexDirection = + | -1 + | 1 + | '2d' + | '2dsphere' + | 'text' + | 'geoHaystack' + | 'hashed' + | number; + function isIndexDirection(x: unknown): x is IndexDirection { return ( typeof x === 'number' || x === '2d' || x === '2dsphere' || x === 'text' || x === 'geoHaystack' diff --git a/test/types/community/createIndex.test-d.ts b/test/types/community/createIndex.test-d.ts index f1802cb762..2ddc32acd2 100644 --- a/test/types/community/createIndex.test-d.ts +++ b/test/types/community/createIndex.test-d.ts @@ -18,6 +18,7 @@ collection.createIndex(['someKey', 1]); collection.createIndex(new Map([['someKey', 1]])); collection.createIndex({ a: 1, b: -1 }); collection.createIndex({ a: '2dsphere', b: -1 }); +collection.createIndex({ a: 'hashed' }); // OrMore collection.createIndex(['someKey']); collection.createIndex([['someKey', 1]]); @@ -28,6 +29,7 @@ collection.createIndex([ { a: 'geoHaystack', b: 1 } ]); collection.createIndex(['a', ['b', 1], { a: 'geoHaystack', b: 1 }, new Map([['someKey', 1]])]); +collection.createIndex([{ a: 'hashed' }]); // @ts-expect-error: CreateIndexes now asserts the object value types as of NODE-3517 collection.createIndexes([{ key: { a: 34n } }]);