From bb219589e56386d7b8e42723c57cd084c8510717 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 13 Jun 2024 16:49:09 +0200 Subject: [PATCH 1/3] fix(NODE-5801): use more specific key typing for multiple KMS provider support --- src/client-side-encryption/providers/index.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/client-side-encryption/providers/index.ts b/src/client-side-encryption/providers/index.ts index b92cbbcc5f..27e2552fdb 100644 --- a/src/client-side-encryption/providers/index.ts +++ b/src/client-side-encryption/providers/index.ts @@ -122,34 +122,31 @@ export interface KMSProviders { * Configuration options for using 'aws' as your KMS provider */ aws?: AWSKMSProviderConfiguration | Record; + [key: `aws:${string}`]: AWSKMSProviderConfiguration | Record; /** * Configuration options for using 'local' as your KMS provider */ local?: LocalKMSProviderConfiguration; + [key: `local:${string}`]: LocalKMSProviderConfiguration; /** * Configuration options for using 'kmip' as your KMS provider */ kmip?: KMIPKMSProviderConfiguration; + [key: `kmip:${string}`]: KMIPKMSProviderConfiguration; /** * Configuration options for using 'azure' as your KMS provider */ azure?: AzureKMSProviderConfiguration | Record; + [key: `azure:${string}`]: AzureKMSProviderConfiguration | Record; /** * Configuration options for using 'gcp' as your KMS provider */ gcp?: GCPKMSProviderConfiguration | Record; - - [key: string]: - | AWSKMSProviderConfiguration - | LocalKMSProviderConfiguration - | KMIPKMSProviderConfiguration - | AzureKMSProviderConfiguration - | GCPKMSProviderConfiguration - | undefined; + [key: `gcp:${string}`]: GCPKMSProviderConfiguration | Record; } /** From 1c63e68371aeedcd0c64c4cb493048c4c8cd2a06 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 13 Jun 2024 16:51:20 +0200 Subject: [PATCH 2/3] fixup --- src/client-side-encryption/providers/index.ts | 2 +- test/types/client-side-encryption.test-d.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client-side-encryption/providers/index.ts b/src/client-side-encryption/providers/index.ts index 27e2552fdb..c6010e1e89 100644 --- a/src/client-side-encryption/providers/index.ts +++ b/src/client-side-encryption/providers/index.ts @@ -12,7 +12,7 @@ import { loadGCPCredentials } from './gcp'; * `aws:`, `gcp:`, `local:`, `kmip:`, `azure:` * where `name` is an alphanumeric string, underscores allowed. */ -export type ClientEncryptionDataKeyProvider = string; +export type ClientEncryptionDataKeyProvider = keyof KMSProviders; /** @public */ export interface AWSKMSProviderConfiguration { diff --git a/test/types/client-side-encryption.test-d.ts b/test/types/client-side-encryption.test-d.ts index 6f403668e8..5db153c46a 100644 --- a/test/types/client-side-encryption.test-d.ts +++ b/test/types/client-side-encryption.test-d.ts @@ -15,7 +15,7 @@ type RequiredCreateEncryptedCollectionSettings = Parameters< >[2]; expectError({}); -expectAssignable({ +expectError({ provider: 'blah!', createCollectionOptions: { encryptedFields: {} } }); @@ -32,6 +32,10 @@ expectAssignable({ provider: 'aws', createCollectionOptions: { encryptedFields: {} } }); +expectAssignable({ + provider: 'aws:namedprovider', + createCollectionOptions: { encryptedFields: {} } +}); expectAssignable({ provider: 'aws', createCollectionOptions: { encryptedFields: {} }, From 3a8ccf7c2015eee2897547a24418fbe2b24b209e Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 13 Jun 2024 13:13:39 -0600 Subject: [PATCH 3/3] fix lint tasks in CI --- .evergreen/config.yml | 6 +++--- .evergreen/generate_evergreen_tasks.js | 7 ++++--- .evergreen/run-typescript.sh | 2 +- README.md | 6 +++--- src/client-side-encryption/providers/index.ts | 6 +++--- test/types/client-side-encryption.test-d.ts | 18 +++++++++++++++++- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index d80f3d3f4c..67dcba0e44 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -3500,9 +3500,9 @@ tasks: - {key: TS_VERSION, value: current} - func: install dependencies - func: check types - - name: check-types-typescript-4.1.6 + - name: check-types-typescript-4.4 tags: - - check-types-typescript-4.1.6 + - check-types-typescript-4.4 - typescript-compilation commands: - command: expansions.update @@ -3511,7 +3511,7 @@ tasks: updates: - {key: NODE_LTS_VERSION, value: '16'} - {key: NPM_VERSION, value: '9'} - - {key: TS_VERSION, value: 4.1.6} + - {key: TS_VERSION, value: '4.4'} - func: install dependencies - func: check types - name: download-and-merge-coverage diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 31dfbc84de..a9d2584631 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -497,9 +497,10 @@ SINGLETON_TASKS.push( ); function* makeTypescriptTasks() { - for (const TS_VERSION of ['next', 'current', '4.1.6']) { - // 4.1.6 can consume the public API but not compile the driver - if (TS_VERSION !== '4.1.6' && TS_VERSION !== 'next') { + for (const TS_VERSION of ['next', 'current', '4.4']) { + // We don't compile on next, because compilation errors are likely. We do expect + // that the drivers types continue to work with next though. + if (TS_VERSION !== '4.4' && TS_VERSION !== 'next') { yield { name: `compile-driver-typescript-${TS_VERSION}`, tags: [`compile-driver-typescript-${TS_VERSION}`, 'typescript-compilation'], diff --git a/.evergreen/run-typescript.sh b/.evergreen/run-typescript.sh index a468569920..87d47a559b 100644 --- a/.evergreen/run-typescript.sh +++ b/.evergreen/run-typescript.sh @@ -32,7 +32,7 @@ export TSC="./node_modules/typescript/bin/tsc" export TS_VERSION=$(get_ts_version) # On old versions of TS we need to put the node types back to 18.11.19 -npm install --no-save --force typescript@"$TS_VERSION" "$(if [[ $TS_VERSION == '4.1.6' ]]; then echo "@types/node@18.11.19"; else echo ""; fi)" +npm install --no-save --force typescript@"$TS_VERSION" "$(if [[ $TS_VERSION == '4.4' ]]; then echo "@types/node@18.11.19"; else echo ""; fi)" echo "Typescript $($TSC -v)" diff --git a/README.md b/README.md index e6cf529b61..ecde8bfcc4 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ The official [MongoDB](https://www.mongodb.com/) driver for Node.js. The GitHub release contains a detached signature file for the NPM package (named `mongodb-X.Y.Z.tgz.sig`). -The following command returns the link npm package. +The following command returns the link npm package. ```shell -npm view mongodb@vX.Y.Z dist.tarball +npm view mongodb@vX.Y.Z dist.tarball ``` Using the result of the above command, a `curl` command can return the official npm package for the release. @@ -81,7 +81,7 @@ The following table describes add-on component version compatibility for the Nod #### Typescript Version -We recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `typescript@4.1.6`. +We recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `typescript@4.4.0`. This is the lowest typescript version guaranteed to work with our driver: older versions may or may not work - use at your own risk. Since typescript [does not restrict breaking changes to major versions](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes), we consider this support best effort. If you run into any unexpected compiler failures against our supported TypeScript versions, please let us know by filing an issue on our [JIRA](https://jira.mongodb.org/browse/NODE). diff --git a/src/client-side-encryption/providers/index.ts b/src/client-side-encryption/providers/index.ts index c6010e1e89..54f4366f6f 100644 --- a/src/client-side-encryption/providers/index.ts +++ b/src/client-side-encryption/providers/index.ts @@ -122,7 +122,7 @@ export interface KMSProviders { * Configuration options for using 'aws' as your KMS provider */ aws?: AWSKMSProviderConfiguration | Record; - [key: `aws:${string}`]: AWSKMSProviderConfiguration | Record; + [key: `aws:${string}`]: AWSKMSProviderConfiguration; /** * Configuration options for using 'local' as your KMS provider @@ -140,13 +140,13 @@ export interface KMSProviders { * Configuration options for using 'azure' as your KMS provider */ azure?: AzureKMSProviderConfiguration | Record; - [key: `azure:${string}`]: AzureKMSProviderConfiguration | Record; + [key: `azure:${string}`]: AzureKMSProviderConfiguration; /** * Configuration options for using 'gcp' as your KMS provider */ gcp?: GCPKMSProviderConfiguration | Record; - [key: `gcp:${string}`]: GCPKMSProviderConfiguration | Record; + [key: `gcp:${string}`]: GCPKMSProviderConfiguration; } /** diff --git a/test/types/client-side-encryption.test-d.ts b/test/types/client-side-encryption.test-d.ts index 5db153c46a..53e4060aa2 100644 --- a/test/types/client-side-encryption.test-d.ts +++ b/test/types/client-side-encryption.test-d.ts @@ -1,4 +1,4 @@ -import { expectAssignable, expectError, expectType } from 'tsd'; +import { expectAssignable, expectError, expectNotAssignable, expectType } from 'tsd'; import type { AWSEncryptionKeyOptions, @@ -9,6 +9,7 @@ import type { KMSProviders, RangeOptions } from '../..'; +import type { ClientEncryptionDataKeyProvider } from '../mongodb'; type RequiredCreateEncryptedCollectionSettings = Parameters< ClientEncryption['createEncryptedCollection'] @@ -87,3 +88,18 @@ expectAssignable({ // automatic expectAssignable({}); } + +{ + expectAssignable('aws'); + expectAssignable('gcp'); + expectAssignable('azure'); + expectAssignable('local'); + expectAssignable('kmip'); + expectAssignable('aws:named'); + expectAssignable('gcp:named'); + expectAssignable('azure:named'); + expectAssignable('local:named'); + expectAssignable('kmip:named'); + + expectNotAssignable('arbitrary string'); +}