From c3b0741cb3c7b7221e73597642daa9323fdb98c8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 15 Feb 2022 15:01:47 -0500 Subject: [PATCH 1/3] test: ensure our enums are types and values --- test/types/enum.test-d.ts | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/types/enum.test-d.ts diff --git a/test/types/enum.test-d.ts b/test/types/enum.test-d.ts new file mode 100644 index 0000000000..6db4f6bb09 --- /dev/null +++ b/test/types/enum.test-d.ts @@ -0,0 +1,43 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { expectType } from 'tsd'; + +import { + AuthMechanism, + AutoEncryptionLoggerLevel, + BatchType, + BSONType, + Compressor, + CURSOR_FLAGS, + CursorFlag, + ExplainVerbosity, + // GSSAPICanonicalizationValues, + LoggerLevel, + ProfilingLevel, + ReadConcernLevel, + ReadPreferenceMode, + ReturnDocument, + ServerApiVersion, + ServerType, + TopologyType +} from '../../src/index'; + +// In our index.ts we clump CURSOR_FLAGS with the enums but its an array +expectType(CURSOR_FLAGS[0]); + +// Note both the Enum name and a property on the enum are the same type +// Object.values(x)[0] gets a union of the all the value types +expectType(Object.values(AuthMechanism)[0]); +expectType(Object.values(AutoEncryptionLoggerLevel)[0]); +expectType(Object.values(BatchType)[0]); +expectType(Object.values(BSONType)[0]); +expectType(Object.values(Compressor)[0]); +expectType(Object.values(ExplainVerbosity)[0]); +// expectType(Object.values(GSSAPICanonicalizationValues)[0]); +expectType(Object.values(LoggerLevel)[0]); +expectType(Object.values(ProfilingLevel)[0]); +expectType(Object.values(ReadConcernLevel)[0]); +expectType(Object.values(ReadPreferenceMode)[0]); +expectType(Object.values(ReturnDocument)[0]); +expectType(Object.values(ServerApiVersion)[0]); +expectType(Object.values(ServerType)[0]); +expectType(Object.values(TopologyType)[0]); From db652e3c3e7c547318fd4e8ab23f5437563a8c84 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 18 Feb 2022 11:36:04 -0500 Subject: [PATCH 2/3] add gssapi enum --- test/types/enum.test-d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/types/enum.test-d.ts b/test/types/enum.test-d.ts index 6db4f6bb09..39fc2f9f0d 100644 --- a/test/types/enum.test-d.ts +++ b/test/types/enum.test-d.ts @@ -10,7 +10,7 @@ import { CURSOR_FLAGS, CursorFlag, ExplainVerbosity, - // GSSAPICanonicalizationValues, + GSSAPICanonicalizationValue, LoggerLevel, ProfilingLevel, ReadConcernLevel, @@ -32,7 +32,7 @@ expectType(Object.values(BatchType)[0]); expectType(Object.values(BSONType)[0]); expectType(Object.values(Compressor)[0]); expectType(Object.values(ExplainVerbosity)[0]); -// expectType(Object.values(GSSAPICanonicalizationValues)[0]); +expectType(Object.values(GSSAPICanonicalizationValue)[0]); expectType(Object.values(LoggerLevel)[0]); expectType(Object.values(ProfilingLevel)[0]); expectType(Object.values(ReadConcernLevel)[0]); From 154a287f35363d70eb518e142628be1f0bb78215 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 18 Feb 2022 11:53:07 -0500 Subject: [PATCH 3/3] fix: lint! --- test/types/enum.test-d.ts | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/types/enum.test-d.ts b/test/types/enum.test-d.ts index 39fc2f9f0d..225282f618 100644 --- a/test/types/enum.test-d.ts +++ b/test/types/enum.test-d.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { expectType } from 'tsd'; +import { expectAssignable, expectType } from 'tsd'; import { AuthMechanism, @@ -21,23 +21,27 @@ import { TopologyType } from '../../src/index'; +const num: number = Math.random(); + // In our index.ts we clump CURSOR_FLAGS with the enums but its an array -expectType(CURSOR_FLAGS[0]); +expectType(CURSOR_FLAGS[num]); + +// Explain is kept as type string so we can automatically allow any new level to be passed through +expectAssignable(Object.values(ExplainVerbosity)[num]); // Note both the Enum name and a property on the enum are the same type -// Object.values(x)[0] gets a union of the all the value types -expectType(Object.values(AuthMechanism)[0]); -expectType(Object.values(AutoEncryptionLoggerLevel)[0]); -expectType(Object.values(BatchType)[0]); -expectType(Object.values(BSONType)[0]); -expectType(Object.values(Compressor)[0]); -expectType(Object.values(ExplainVerbosity)[0]); -expectType(Object.values(GSSAPICanonicalizationValue)[0]); -expectType(Object.values(LoggerLevel)[0]); -expectType(Object.values(ProfilingLevel)[0]); -expectType(Object.values(ReadConcernLevel)[0]); -expectType(Object.values(ReadPreferenceMode)[0]); -expectType(Object.values(ReturnDocument)[0]); -expectType(Object.values(ServerApiVersion)[0]); -expectType(Object.values(ServerType)[0]); -expectType(Object.values(TopologyType)[0]); +// Object.values(x)[num] gets a union of the all the value types +expectType(Object.values(AuthMechanism)[num]); +expectType(Object.values(AutoEncryptionLoggerLevel)[num]); +expectType(Object.values(BatchType)[num]); +expectType(Object.values(BSONType)[num]); +expectType(Object.values(Compressor)[num]); +expectType(Object.values(GSSAPICanonicalizationValue)[num]); +expectType(Object.values(LoggerLevel)[num]); +expectType(Object.values(ProfilingLevel)[num]); +expectType(Object.values(ReadConcernLevel)[num]); +expectType(Object.values(ReadPreferenceMode)[num]); +expectType(Object.values(ReturnDocument)[num]); +expectType(Object.values(ServerApiVersion)[num]); +expectType(Object.values(ServerType)[num]); +expectType(Object.values(TopologyType)[num]);