()
| 205 | |
| 206 | /** A utility function to get the instance of mongodb-client-encryption, if it exists. */ |
| 207 | export function getMongoDBClientEncryption(): |
| 208 | | typeof import('mongodb-client-encryption') |
| 209 | | { kModuleError: MongoMissingDependencyError } { |
| 210 | let mongodbClientEncryption = null; |
| 211 | |
| 212 | try { |
| 213 | // NOTE(NODE-3199): Ensure you always wrap an optional require literally in the try block |
| 214 | // Cannot be moved to helper utility function, bundlers search and replace the actual require call |
| 215 | // in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed |
| 216 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 217 | mongodbClientEncryption = require('mongodb-client-encryption'); |
| 218 | } catch (error) { |
| 219 | const kModuleError = new MongoMissingDependencyError( |
| 220 | 'Optional module `mongodb-client-encryption` not found. Please install it to use auto encryption or ClientEncryption.', |
| 221 | { cause: error, dependencyName: 'mongodb-client-encryption' } |
| 222 | ); |
| 223 | return { kModuleError }; |
| 224 | } |
| 225 | |
| 226 | return mongodbClientEncryption; |
| 227 | } |
no outgoing calls
no test coverage detected