@@ -21,16 +21,16 @@ import { Filter } from './filter';
21
21
*/
22
22
23
23
export class ClientSideEncryptionFilter extends Filter {
24
- enabled : boolean ;
25
- static version = null ;
26
- static libmongocrypt : string | null = null ;
24
+ enabled : boolean = false ;
25
+ version : string | null = null ;
26
+ libmongocrypt : string | null = null ;
27
27
28
28
override async initializeFilter ( client : MongoClient , context : Record < string , any > ) {
29
29
let mongodbClientEncryption : typeof import ( 'mongodb-client-encryption' ) ;
30
30
try {
31
31
// eslint-disable-next-line @typescript-eslint/no-require-imports
32
32
mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
33
- ClientSideEncryptionFilter . libmongocrypt = (
33
+ this . libmongocrypt = (
34
34
mongodbClientEncryption as typeof import ( 'mongodb-client-encryption' )
35
35
) . MongoCrypt . libmongocryptVersion ;
36
36
} catch ( failedToGetFLELib ) {
@@ -39,21 +39,23 @@ export class ClientSideEncryptionFilter extends Filter {
39
39
}
40
40
}
41
41
42
- ClientSideEncryptionFilter . version ??= JSON . parse (
43
- await readFile (
44
- resolve ( dirname ( require . resolve ( 'mongodb-client-encryption' ) ) , '..' , 'package.json' ) ,
45
- 'utf8'
46
- )
47
- ) . version ;
42
+ if ( ! this . version ) {
43
+ this . version = JSON . parse (
44
+ await readFile (
45
+ resolve ( dirname ( require . resolve ( 'mongodb-client-encryption' ) ) , '..' , 'package.json' ) ,
46
+ 'utf8'
47
+ )
48
+ ) . version ;
49
+ }
48
50
49
51
this . enabled = ! ! ( kmsCredentialsPresent && mongodbClientEncryption ) ;
50
52
51
53
// Adds these fields onto the context so that they can be reused by tests
52
54
context . clientSideEncryption = {
53
55
enabled : this . enabled ,
54
56
mongodbClientEncryption,
55
- version : ClientSideEncryptionFilter . version ,
56
- libmongocrypt : ClientSideEncryptionFilter . libmongocrypt
57
+ version : this . version ,
58
+ libmongocrypt : this . libmongocrypt
57
59
} ;
58
60
}
59
61
@@ -73,18 +75,17 @@ export class ClientSideEncryptionFilter extends Filter {
73
75
74
76
// TODO(NODE-3401): unskip csfle tests on windows
75
77
if ( process . env . TEST_CSFLE && process . platform !== 'win32' ) {
76
- if ( ClientSideEncryptionFilter . version == null ) {
78
+ if ( this . version == null ) {
77
79
throw new Error ( 'FLE tests must run, but mongodb client encryption was not installed.' ) ;
78
80
}
79
81
}
80
82
81
83
if ( ! kmsCredentialsPresent ) return 'Test requires FLE kms credentials' ;
82
- if ( ClientSideEncryptionFilter . version == null )
83
- return 'Test requires mongodb-client-encryption to be installed.' ;
84
+ if ( this . version == null ) return 'Test requires mongodb-client-encryption to be installed.' ;
84
85
85
86
const validRange = typeof clientSideEncryption === 'string' ? clientSideEncryption : '>=0.0.0' ;
86
- return satisfies ( ClientSideEncryptionFilter . version , validRange , { includePrerelease : true } )
87
+ return satisfies ( this . version , validRange , { includePrerelease : true } )
87
88
? true
88
- : `requires mongodb-client-encryption ${ validRange } , received ${ ClientSideEncryptionFilter . version } ` ;
89
+ : `requires mongodb-client-encryption ${ validRange } , received ${ this . version } ` ;
89
90
}
90
91
}
0 commit comments