functionInt8(key, options) {mongoose.SchemaType.call(this, key, options,'Int8'); }Int8.prototype=Object.create(mongoose.SchemaType.prototype);// `cast()` takes a parameter that can be anything. You need to// validate the provided `val` and throw a `CastError` if you// can't convert it.Int8.prototype.cast=function(val) {var _val =Number(val);if (isNaN(_val)) {thrownewError('Int8: '+ val +' is not a number'); } _val =Math.round(_val);if (_val <-0x80|| _val >0x7F) {thrownewError('Int8: '+ val +' is outside of the range of valid 8-bit ints'); }return _val; };// Don't forget to add `Int8` to the type registrymongoose.Schema.Types.Int8 = Int8;var testSchema =newSchema({ test: Int8 });var Test =mongoose.model('Test', testSchema);var t =newTest();t.test ='abc';assert.ok(t.validateSync());assert.equal(t.validateSync().errors['test'].name,'CastError');assert.equal(t.validateSync().errors['test'].message,'Cast to Int8 failed for value "abc" at path "test"');assert.equal(t.validateSync().errors['test'].reason.message,'Int8: abc is not a number');