Skip to content

Commit 465ffd9

Browse files
addaleaxbaileympearsonnbbeeken
authored
fix(NODE-5801): use more specific key typing for multiple KMS provider support (#4146)
Co-authored-by: Bailey Pearson <bailey.pearson@mongodb.com> Co-authored-by: Neal Beeken <neal.beeken@mongodb.com>
1 parent 3ed6a2a commit 465ffd9

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

Diff for: .evergreen/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3493,9 +3493,9 @@ tasks:
34933493
- {key: TS_VERSION, value: current}
34943494
- func: install dependencies
34953495
- func: check types
3496-
- name: check-types-typescript-4.1.6
3496+
- name: check-types-typescript-4.4
34973497
tags:
3498-
- check-types-typescript-4.1.6
3498+
- check-types-typescript-4.4
34993499
- typescript-compilation
35003500
commands:
35013501
- command: expansions.update
@@ -3504,7 +3504,7 @@ tasks:
35043504
updates:
35053505
- {key: NODE_LTS_VERSION, value: '16'}
35063506
- {key: NPM_VERSION, value: '9'}
3507-
- {key: TS_VERSION, value: 4.1.6}
3507+
- {key: TS_VERSION, value: '4.4'}
35083508
- func: install dependencies
35093509
- func: check types
35103510
- name: download-and-merge-coverage

Diff for: .evergreen/generate_evergreen_tasks.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,10 @@ SINGLETON_TASKS.push(
497497
);
498498

499499
function* makeTypescriptTasks() {
500-
for (const TS_VERSION of ['next', 'current', '4.1.6']) {
501-
// 4.1.6 can consume the public API but not compile the driver
502-
if (TS_VERSION !== '4.1.6' && TS_VERSION !== 'next') {
500+
for (const TS_VERSION of ['next', 'current', '4.4']) {
501+
// We don't compile on next, because compilation errors are likely. We do expect
502+
// that the drivers types continue to work with next though.
503+
if (TS_VERSION !== '4.4' && TS_VERSION !== 'next') {
503504
yield {
504505
name: `compile-driver-typescript-${TS_VERSION}`,
505506
tags: [`compile-driver-typescript-${TS_VERSION}`, 'typescript-compilation'],

Diff for: .evergreen/run-typescript.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export TSC="./node_modules/typescript/bin/tsc"
3232
export TS_VERSION=$(get_ts_version)
3333

3434
# On old versions of TS we need to put the node types back to 18.11.19
35-
npm install --no-save --force typescript@"$TS_VERSION" "$(if [[ $TS_VERSION == '4.1.6' ]]; then echo "@types/node@18.11.19"; else echo ""; fi)"
35+
npm install --no-save --force typescript@"$TS_VERSION" "$(if [[ $TS_VERSION == '4.4' ]]; then echo "@types/node@18.11.19"; else echo ""; fi)"
3636

3737
echo "Typescript $($TSC -v)"
3838

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ The official [MongoDB](https://www.mongodb.com/) driver for Node.js.
2727
The GitHub release contains a detached signature file for the NPM package (named
2828
`mongodb-X.Y.Z.tgz.sig`).
2929

30-
The following command returns the link npm package.
30+
The following command returns the link npm package.
3131
```shell
32-
npm view mongodb@vX.Y.Z dist.tarball
32+
npm view mongodb@vX.Y.Z dist.tarball
3333
```
3434

3535
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
8181

8282
#### Typescript Version
8383

84-
We recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `typescript@4.1.6`.
84+
We recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `typescript@4.4.0`.
8585
This is the lowest typescript version guaranteed to work with our driver: older versions may or may not work - use at your own risk.
8686
Since typescript [does not restrict breaking changes to major versions](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes), we consider this support best effort.
8787
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 for: src/client-side-encryption/providers/index.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { loadGCPCredentials } from './gcp';
1212
* `aws:<name>`, `gcp:<name>`, `local:<name>`, `kmip:<name>`, `azure:<name>`
1313
* where `name` is an alphanumeric string, underscores allowed.
1414
*/
15-
export type ClientEncryptionDataKeyProvider = string;
15+
export type ClientEncryptionDataKeyProvider = keyof KMSProviders;
1616

1717
/** @public */
1818
export interface AWSKMSProviderConfiguration {
@@ -122,34 +122,31 @@ export interface KMSProviders {
122122
* Configuration options for using 'aws' as your KMS provider
123123
*/
124124
aws?: AWSKMSProviderConfiguration | Record<string, never>;
125+
[key: `aws:${string}`]: AWSKMSProviderConfiguration;
125126

126127
/**
127128
* Configuration options for using 'local' as your KMS provider
128129
*/
129130
local?: LocalKMSProviderConfiguration;
131+
[key: `local:${string}`]: LocalKMSProviderConfiguration;
130132

131133
/**
132134
* Configuration options for using 'kmip' as your KMS provider
133135
*/
134136
kmip?: KMIPKMSProviderConfiguration;
137+
[key: `kmip:${string}`]: KMIPKMSProviderConfiguration;
135138

136139
/**
137140
* Configuration options for using 'azure' as your KMS provider
138141
*/
139142
azure?: AzureKMSProviderConfiguration | Record<string, never>;
143+
[key: `azure:${string}`]: AzureKMSProviderConfiguration;
140144

141145
/**
142146
* Configuration options for using 'gcp' as your KMS provider
143147
*/
144148
gcp?: GCPKMSProviderConfiguration | Record<string, never>;
145-
146-
[key: string]:
147-
| AWSKMSProviderConfiguration
148-
| LocalKMSProviderConfiguration
149-
| KMIPKMSProviderConfiguration
150-
| AzureKMSProviderConfiguration
151-
| GCPKMSProviderConfiguration
152-
| undefined;
149+
[key: `gcp:${string}`]: GCPKMSProviderConfiguration;
153150
}
154151

155152
/**

Diff for: test/types/client-side-encryption.test-d.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectAssignable, expectError, expectType } from 'tsd';
1+
import { expectAssignable, expectError, expectNotAssignable, expectType } from 'tsd';
22

33
import type {
44
AWSEncryptionKeyOptions,
@@ -9,13 +9,14 @@ import type {
99
KMSProviders,
1010
RangeOptions
1111
} from '../..';
12+
import type { ClientEncryptionDataKeyProvider } from '../mongodb';
1213

1314
type RequiredCreateEncryptedCollectionSettings = Parameters<
1415
ClientEncryption['createEncryptedCollection']
1516
>[2];
1617

1718
expectError<RequiredCreateEncryptedCollectionSettings>({});
18-
expectAssignable<RequiredCreateEncryptedCollectionSettings>({
19+
expectError<RequiredCreateEncryptedCollectionSettings>({
1920
provider: 'blah!',
2021
createCollectionOptions: { encryptedFields: {} }
2122
});
@@ -32,6 +33,10 @@ expectAssignable<RequiredCreateEncryptedCollectionSettings>({
3233
provider: 'aws',
3334
createCollectionOptions: { encryptedFields: {} }
3435
});
36+
expectAssignable<RequiredCreateEncryptedCollectionSettings>({
37+
provider: 'aws:namedprovider',
38+
createCollectionOptions: { encryptedFields: {} }
39+
});
3540
expectAssignable<RequiredCreateEncryptedCollectionSettings>({
3641
provider: 'aws',
3742
createCollectionOptions: { encryptedFields: {} },
@@ -83,3 +88,18 @@ expectAssignable<RequiredCreateEncryptedCollectionSettings>({
8388
// automatic
8489
expectAssignable<KMSProviders['gcp']>({});
8590
}
91+
92+
{
93+
expectAssignable<ClientEncryptionDataKeyProvider>('aws');
94+
expectAssignable<ClientEncryptionDataKeyProvider>('gcp');
95+
expectAssignable<ClientEncryptionDataKeyProvider>('azure');
96+
expectAssignable<ClientEncryptionDataKeyProvider>('local');
97+
expectAssignable<ClientEncryptionDataKeyProvider>('kmip');
98+
expectAssignable<ClientEncryptionDataKeyProvider>('aws:named');
99+
expectAssignable<ClientEncryptionDataKeyProvider>('gcp:named');
100+
expectAssignable<ClientEncryptionDataKeyProvider>('azure:named');
101+
expectAssignable<ClientEncryptionDataKeyProvider>('local:named');
102+
expectAssignable<ClientEncryptionDataKeyProvider>('kmip:named');
103+
104+
expectNotAssignable<ClientEncryptionDataKeyProvider>('arbitrary string');
105+
}

0 commit comments

Comments
 (0)