MCPcopy
hub / github.com/mongodb/node-mongodb-native / getMongoDBClientEncryption

Function getMongoDBClientEncryption

src/deps.ts:207–227  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205
206/** A utility function to get the instance of mongodb-client-encryption, if it exists. */
207export 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}

Callers 4

checkForMongoCryptMethod · 0.90
getMongoCryptMethod · 0.90
getMongoCryptMethod · 0.90
createClientEncryptionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected