Skip to content

Commit dab4c7c

Browse files
feat(NODE-6584)!: improve typing for filepaths in AutoEncryptionOptions (#4341)
Co-authored-by: Bailey Pearson <[email protected]>
1 parent 28f0152 commit dab4c7c

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/client-side-encryption/auto_encrypter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface AutoEncryptionOptions {
6969
/** If true, autoEncryption will not attempt to spawn a mongocryptd before connecting */
7070
mongocryptdBypassSpawn?: boolean;
7171
/** The path to the mongocryptd executable on the system */
72-
mongocryptdSpawnPath?: string;
72+
mongocryptdSpawnPath?: `${string}mongocryptd${'.exe' | ''}`;
7373
/** Command line arguments to use when auto-spawning a mongocryptd */
7474
mongocryptdSpawnArgs?: string[];
7575
/**
@@ -95,7 +95,7 @@ export interface AutoEncryptionOptions {
9595
*
9696
* Requires the MongoDB Crypt shared library, available in MongoDB 6.0 or higher.
9797
*/
98-
cryptSharedLibPath?: string;
98+
cryptSharedLibPath?: `${string}mongo_crypt_v${number}.${'so' | 'dll' | 'dylib'}`;
9999
/**
100100
* If specified, never use mongocryptd and instead fail when the MongoDB Crypt
101101
* shared library could not be loaded.

test/types/client-side-encryption.test-d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expectAssignable, expectError, expectNotAssignable, expectType } from 'tsd';
22

33
import type {
4+
AutoEncryptionOptions,
45
AWSEncryptionKeyOptions,
56
AzureEncryptionKeyOptions,
67
ClientEncryption,
@@ -107,3 +108,52 @@ expectAssignable<RequiredCreateEncryptedCollectionSettings>({
107108

108109
expectNotAssignable<ClientEncryptionDataKeyProvider>('arbitrary string');
109110
}
111+
112+
{
113+
expectAssignable<AutoEncryptionOptions>({
114+
extraOptions: {
115+
mongocryptdSpawnPath: 'mongocryptd'
116+
}
117+
});
118+
expectAssignable<AutoEncryptionOptions>({
119+
extraOptions: {
120+
mongocryptdSpawnPath: 'mongocryptd.exe'
121+
}
122+
});
123+
expectAssignable<AutoEncryptionOptions>({
124+
extraOptions: {
125+
mongocryptdSpawnPath: '/usr/bin/mongocryptd'
126+
}
127+
});
128+
expectNotAssignable<AutoEncryptionOptions>({
129+
extraOptions: {
130+
mongocryptdSpawnPath: 'mongo_crypt_v1.so'
131+
}
132+
});
133+
134+
expectAssignable<AutoEncryptionOptions>({
135+
extraOptions: {
136+
cryptSharedLibPath: 'mongo_crypt_v1.so'
137+
}
138+
});
139+
expectAssignable<AutoEncryptionOptions>({
140+
extraOptions: {
141+
cryptSharedLibPath: 'mongo_crypt_v1.dll'
142+
}
143+
});
144+
expectAssignable<AutoEncryptionOptions>({
145+
extraOptions: {
146+
cryptSharedLibPath: 'mongo_crypt_v1.dylib'
147+
}
148+
});
149+
expectAssignable<AutoEncryptionOptions>({
150+
extraOptions: {
151+
cryptSharedLibPath: '/usr/lib/mongo_crypt_v1.dylib'
152+
}
153+
});
154+
expectNotAssignable<AutoEncryptionOptions>({
155+
extraOptions: {
156+
cryptSharedLibPath: 'libmongocrypt.so'
157+
}
158+
});
159+
}

0 commit comments

Comments
 (0)