Skip to content

Commit 36bbc33

Browse files
make method
1 parent d782f4c commit 36bbc33

File tree

12 files changed

+58
-15
lines changed

12 files changed

+58
-15
lines changed

lib/schema.js

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

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

lib/schema/array.js

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

134132
/**
@@ -720,6 +718,10 @@ SchemaArray.prototype.toJSONSchema = function toJSONSchema(options) {
720718
};
721719
};
722720

721+
SchemaArray.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
722+
return 'array';
723+
};
724+
723725
/*!
724726
* Module exports.
725727
*/

lib/schema/bigint.js

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

2121
function SchemaBigInt(path, options) {
2222
SchemaType.call(this, path, options, 'BigInt');
23-
24-
this.supportsAutoEncryption = true;
2523
}
2624

2725
/**
@@ -256,6 +254,10 @@ SchemaBigInt.prototype.toJSONSchema = function toJSONSchema(options) {
256254
return createJSONSchemaTypeDefinition('string', 'long', options?.useBsonType, isRequired);
257255
};
258256

257+
SchemaBigInt.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
258+
return 'int64';
259+
};
260+
259261
/*!
260262
* Module exports.
261263
*/

lib/schema/boolean.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeD
2121
function SchemaBoolean(path, options) {
2222
SchemaType.call(this, path, options, 'Boolean');
2323

24-
this.supportsAutoEncryption = true;
24+
2525
}
2626

2727
/**
@@ -306,6 +306,10 @@ SchemaBoolean.prototype.toJSONSchema = function toJSONSchema(options) {
306306
return createJSONSchemaTypeDefinition('boolean', 'bool', options?.useBsonType, isRequired);
307307
};
308308

309+
SchemaBoolean.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
310+
return 'boolean';
311+
};
312+
309313
/*!
310314
* Module exports.
311315
*/

lib/schema/buffer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CastError = SchemaType.CastError;
2626
function SchemaBuffer(key, options) {
2727
SchemaType.call(this, key, options, 'Buffer');
2828

29-
this.supportsAutoEncryption = true;
29+
3030
}
3131

3232
/**
@@ -316,6 +316,10 @@ SchemaBuffer.prototype.toJSONSchema = function toJSONSchema(options) {
316316
return createJSONSchemaTypeDefinition('string', 'binData', options?.useBsonType, isRequired);
317317
};
318318

319+
SchemaBuffer.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
320+
return 'binary';
321+
};
322+
319323
/*!
320324
* Module exports.
321325
*/

lib/schema/date.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CastError = SchemaType.CastError;
2626
function SchemaDate(key, options) {
2727
SchemaType.call(this, key, options, 'Date');
2828

29-
this.supportsAutoEncryption = true;
29+
3030
}
3131

3232
/**
@@ -442,6 +442,10 @@ SchemaDate.prototype.toJSONSchema = function toJSONSchema(options) {
442442
return createJSONSchemaTypeDefinition('string', 'date', options?.useBsonType, isRequired);
443443
};
444444

445+
SchemaDate.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
446+
return 'date';
447+
};
448+
445449
/*!
446450
* Module exports.
447451
*/

lib/schema/decimal128.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const isBsonType = require('../helpers/isBsonType');
2222
function SchemaDecimal128(key, options) {
2323
SchemaType.call(this, key, options, 'Decimal128');
2424

25-
this.supportsAutoEncryption = true;
25+
2626
}
2727

2828
/**
@@ -237,6 +237,10 @@ SchemaDecimal128.prototype.toJSONSchema = function toJSONSchema(options) {
237237
return createJSONSchemaTypeDefinition('string', 'decimal', options?.useBsonType, isRequired);
238238
};
239239

240+
SchemaDecimal128.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
241+
return 'decimal128';
242+
};
243+
240244
/*!
241245
* Module exports.
242246
*/

lib/schema/double.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const createJSONSchemaTypeDefinition = require('../helpers/createJSONSchemaTypeD
2121
function SchemaDouble(path, options) {
2222
SchemaType.call(this, path, options, 'Double');
2323

24-
this.supportsAutoEncryption = true;
24+
2525
}
2626

2727
/**
@@ -220,6 +220,10 @@ SchemaDouble.prototype.toJSONSchema = function toJSONSchema(options) {
220220
return createJSONSchemaTypeDefinition('number', 'double', options?.useBsonType, isRequired);
221221
};
222222

223+
SchemaDouble.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
224+
return 'double';
225+
};
226+
223227
/*!
224228
* Module exports.
225229
*/

lib/schema/int32.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const handleBitwiseOperator = require('./operators/bitwise');
2222
function SchemaInt32(path, options) {
2323
SchemaType.call(this, path, options, 'Int32');
2424

25-
this.supportsAutoEncryption = true;
25+
2626
}
2727

2828
/**
@@ -262,6 +262,10 @@ SchemaInt32.prototype.toJSONSchema = function toJSONSchema(options) {
262262
return createJSONSchemaTypeDefinition('number', 'int', options?.useBsonType, isRequired);
263263
};
264264

265+
SchemaInt32.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
266+
return 'int32';
267+
};
268+
265269

266270
/*!
267271
* Module exports.

lib/schema/objectId.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function SchemaObjectId(key, options) {
3636
}
3737
SchemaType.call(this, key, options, 'ObjectId');
3838

39-
this.supportsAutoEncryption = true;
39+
4040
}
4141

4242
/**
@@ -306,6 +306,10 @@ SchemaObjectId.prototype.toJSONSchema = function toJSONSchema(options) {
306306
return createJSONSchemaTypeDefinition('string', 'objectId', options?.useBsonType, isRequired);
307307
};
308308

309+
SchemaObjectId.prototype.autoEncryptionBSONType = function autoEncryptionBSONType() {
310+
return 'objectid';
311+
};
312+
309313
/*!
310314
* Module exports.
311315
*/

0 commit comments

Comments
 (0)