From 619495143d4cc29585626429c71e802b9f5e80e7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 26 Nov 2024 16:32:58 +0100 Subject: [PATCH] fix(NODE-6584): improve typing for files in AutoEncryptionOptions --- src/client-side-encryption/auto_encrypter.ts | 4 +- test/types/client-side-encryption.test-d.ts | 50 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/client-side-encryption/auto_encrypter.ts b/src/client-side-encryption/auto_encrypter.ts index edf731b92ac..8c9e0adf509 100644 --- a/src/client-side-encryption/auto_encrypter.ts +++ b/src/client-side-encryption/auto_encrypter.ts @@ -57,7 +57,7 @@ export interface AutoEncryptionOptions { /** If true, autoEncryption will not attempt to spawn a mongocryptd before connecting */ mongocryptdBypassSpawn?: boolean; /** The path to the mongocryptd executable on the system */ - mongocryptdSpawnPath?: string; + mongocryptdSpawnPath?: `${string}mongocryptd${'.exe' | ''}`; /** Command line arguments to use when auto-spawning a mongocryptd */ mongocryptdSpawnArgs?: string[]; /** @@ -83,7 +83,7 @@ export interface AutoEncryptionOptions { * * Requires the MongoDB Crypt shared library, available in MongoDB 6.0 or higher. */ - cryptSharedLibPath?: string; + cryptSharedLibPath?: `${string}mongo_crypt_v${number}.${'so' | 'dll' | 'dylib'}`; /** * If specified, never use mongocryptd and instead fail when the MongoDB Crypt * shared library could not be loaded. diff --git a/test/types/client-side-encryption.test-d.ts b/test/types/client-side-encryption.test-d.ts index 87c9d46a347..8257302be33 100644 --- a/test/types/client-side-encryption.test-d.ts +++ b/test/types/client-side-encryption.test-d.ts @@ -2,6 +2,7 @@ import { expectAssignable, expectError, expectNotAssignable, expectType } from ' import type { AWSEncryptionKeyOptions, + AutoEncryptionOptions, AzureEncryptionKeyOptions, ClientEncryption, ClientEncryptionEncryptOptions, @@ -107,3 +108,52 @@ expectAssignable({ expectNotAssignable('arbitrary string'); } + +{ + expectAssignable({ + extraOptions: { + mongocryptdSpawnPath: 'mongocryptd' + } + }); + expectAssignable({ + extraOptions: { + mongocryptdSpawnPath: 'mongocryptd.exe' + } + }); + expectAssignable({ + extraOptions: { + mongocryptdSpawnPath: '/usr/bin/mongocryptd' + } + }); + expectNotAssignable({ + extraOptions: { + mongocryptdSpawnPath: 'mongo_crypt_v1.so' + } + }); + + expectAssignable({ + extraOptions: { + cryptSharedLibPath: 'mongo_crypt_v1.so' + } + }); + expectAssignable({ + extraOptions: { + cryptSharedLibPath: 'mongo_crypt_v1.dll' + } + }); + expectAssignable({ + extraOptions: { + cryptSharedLibPath: 'mongo_crypt_v1.dylib' + } + }); + expectAssignable({ + extraOptions: { + cryptSharedLibPath: '/usr/lib/mongo_crypt_v1.dylib' + } + }); + expectNotAssignable({ + extraOptions: { + cryptSharedLibPath: 'libmongocrypt.so' + } + }); +}