Skip to content

Commit c3151f0

Browse files
Supports FLE
1 parent 85541f8 commit c3151f0

File tree

12 files changed

+561
-3
lines changed

12 files changed

+561
-3
lines changed

lib/schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,9 @@ Schema.prototype.add = function add(obj, prefix) {
894894
* @api private
895895
*/
896896
Schema.prototype._addEncryptedField = function _addEncryptedField(path, fieldConfig) {
897-
const type = inferBSONType(this, path);
898-
if (type == null) {
899-
throw new Error('unable to determine bson type for field `' + path + '`');
897+
const type = this.path(path).instance.toLowerCase();
898+
if (!this.path(path).supportsAutoEncryption) {
899+
throw new Error('Invalid BSON type for FLE: `' + type + '`');
900900
}
901901

902902
this.encryptedFields[path] = clone(fieldConfig);

lib/schema/array.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ function SchemaArray(key, cast, options, schemaOptions) {
127127
defaultFn.$runBeforeSetters = !fn;
128128
this.default(defaultFn);
129129
}
130+
131+
this.supportsAutoEncryption = true;
130132
}
131133

132134
/**

lib/schema/bigint.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeD
2020

2121
function SchemaBigInt(path, options) {
2222
SchemaType.call(this, path, options, 'BigInt');
23+
24+
this.supportsAutoEncryption = true;
2325
}
2426

2527
/**

lib/schema/boolean.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeD
2020

2121
function SchemaBoolean(path, options) {
2222
SchemaType.call(this, path, options, 'Boolean');
23+
24+
this.supportsAutoEncryption = true;
2325
}
2426

2527
/**

lib/schema/buffer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const CastError = SchemaType.CastError;
2525

2626
function SchemaBuffer(key, options) {
2727
SchemaType.call(this, key, options, 'Buffer');
28+
29+
this.supportsAutoEncryption = true;
2830
}
2931

3032
/**

lib/schema/date.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const CastError = SchemaType.CastError;
2525

2626
function SchemaDate(key, options) {
2727
SchemaType.call(this, key, options, 'Date');
28+
29+
this.supportsAutoEncryption = true;
2830
}
2931

3032
/**

lib/schema/decimal128.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const isBsonType = require('../helpers/isBsonType');
2121

2222
function SchemaDecimal128(key, options) {
2323
SchemaType.call(this, key, options, 'Decimal128');
24+
25+
this.supportsAutoEncryption = true;
2426
}
2527

2628
/**

lib/schema/double.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeD
2020

2121
function SchemaDouble(path, options) {
2222
SchemaType.call(this, path, options, 'Double');
23+
24+
this.supportsAutoEncryption = true;
2325
}
2426

2527
/**

lib/schema/int32.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const handleBitwiseOperator = require('./operators/bitwise');
2121

2222
function SchemaInt32(path, options) {
2323
SchemaType.call(this, path, options, 'Int32');
24+
25+
this.supportsAutoEncryption = true;
2426
}
2527

2628
/**

lib/schema/objectId.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function SchemaObjectId(key, options) {
3535
'you\'re trying to create a hex char path in your schema.');
3636
}
3737
SchemaType.call(this, key, options, 'ObjectId');
38+
39+
this.supportsAutoEncryption = true;
3840
}
3941

4042
/**

0 commit comments

Comments
 (0)