diff --git a/.evergreen/config.yml b/.evergreen/config.yml index a53a9d702c..9bbb7c014c 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -3493,9 +3493,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 @@ -3504,7 +3504,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 b92cbbcc5f..54f4366f6f 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 { @@ -122,34 +122,31 @@ export interface KMSProviders { * Configuration options for using 'aws' as your KMS provider */ aws?: AWSKMSProviderConfiguration | Record; + [key: `aws:${string}`]: AWSKMSProviderConfiguration; /** * 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; /** * Configuration options for using 'gcp' as your KMS provider */ gcp?: GCPKMSProviderConfiguration | Record; - - [key: string]: - | AWSKMSProviderConfiguration - | LocalKMSProviderConfiguration - | KMIPKMSProviderConfiguration - | AzureKMSProviderConfiguration - | GCPKMSProviderConfiguration - | undefined; + [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 6f403668e8..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,13 +9,14 @@ import type { KMSProviders, RangeOptions } from '../..'; +import type { ClientEncryptionDataKeyProvider } from '../mongodb'; type RequiredCreateEncryptedCollectionSettings = Parameters< ClientEncryption['createEncryptedCollection'] >[2]; expectError({}); -expectAssignable({ +expectError({ provider: 'blah!', createCollectionOptions: { encryptedFields: {} } }); @@ -32,6 +33,10 @@ expectAssignable({ provider: 'aws', createCollectionOptions: { encryptedFields: {} } }); +expectAssignable({ + provider: 'aws:namedprovider', + createCollectionOptions: { encryptedFields: {} } +}); expectAssignable({ provider: 'aws', createCollectionOptions: { encryptedFields: {} }, @@ -83,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'); +}