diff --git a/types/bson/index.d.ts b/types/bson/index.d.ts index b1f622ad47..67df319bf6 100644 --- a/types/bson/index.d.ts +++ b/types/bson/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for bson 1.0 +// Type definitions for bson 1.0.4 // Project: https://github.com/mongodb/js-bson // Definitions by: Hiroki Horiuchi // Federico Caselli @@ -107,6 +107,14 @@ export class Long { toString(radix?: number): string; xor(other: Long): Long; } +export class Decimal128 { + static fromString(s: string): Decimal128; + + constructor(bytes: Buffer); + + toJSON(): string; + toString(): string; +} export class MaxKey { constructor(); } @@ -135,7 +143,7 @@ export class ObjectID { static createFromTime(time: number): ObjectID; /** * Checks if a value is a valid bson ObjectID - * + * * @return {boolean} return true if the value is a valid bson ObjectID, return false otherwise. */ static isValid(id: string | number | ObjectID): boolean; diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index e1837c04ed..6f4f5624e1 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -12,7 +12,7 @@ import { ObjectID } from 'bson'; import { EventEmitter } from 'events'; import { Readable, Writable } from "stream"; -export { Binary, Double, Long, MaxKey, MinKey, ObjectID, Timestamp } from 'bson'; +export { Binary, Double, Long, Decimal128, MaxKey, MinKey, ObjectID, Timestamp } from 'bson'; // Class documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html export class MongoClient { diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 70771c4398..2c58b764d3 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -1307,6 +1307,8 @@ declare module "mongoose" { // the ObjectIdConstructor, so we add the interface below interface ObjectId extends mongodb.ObjectID {} + class Decimal128 extends mongodb.Decimal128 {} + /* * section types/embedded.js * http://mongoosejs.com/docs/api.html#types-embedded-js @@ -2019,6 +2021,20 @@ declare module "mongoose" { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: string; } + /* + * section schema/decimal128.js + * http://mongoosejs.com/docs/api.html#schema-decimal128-js + */ + class Decimal128 extends SchemaType { + /** Decimal128 SchemaType constructor. */ + constructor(key: string, options?: Object); + + /** Check if the given value satisfies a required validator. */ + checkRequired(value: any, doc: MongooseDocument): boolean; + + /** This schema type's name, to defend against minifiers that mangle function names. */ + static schemaName: string; + } /* * section schema/mixed.js diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index dc170dccd9..4fb41ef3b2 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -61,7 +61,10 @@ mongoose.STATES.hasOwnProperty(''); mongoose.connection.on('error', cb); new mongoose.mongo.MongoError('error').stack; mongoose.SchemaTypes.String; +mongoose.SchemaTypes.ObjectId; +mongoose.SchemaTypes.Decimal128; mongoose.Types.ObjectId; +mongoose.Types.Decimal128; mongoose.version.toLowerCase(); /* @@ -228,6 +231,7 @@ var schema: mongoose.Schema = new mongoose.Schema({ age: { type: Number, min: 18, max: 65 }, mixed: mongoose.Schema.Types.Mixed, _someId: mongoose.Schema.Types.ObjectId, + someDecimal:mongoose.Schema.Types.Decimal128, array: [], ofString: [String], ofNumber: [Number], @@ -585,6 +589,23 @@ mongooseBuffer.compare(mongooseBuffer); /* inherited static properties */ mongoose.Types.Buffer.from([1, 2, 3]); +/* + * section types/decimal128.js + * http://mongoosejs.com/docs/api.html#types-decimal128-js + */ +var decimal128: mongoose.Types.Decimal128 = mongoose.Types.Decimal128.fromString('123.45678901234567'); +decimal128 = new mongoose.Types.Decimal128(new Buffer('12345')); +/* practical examples */ +export interface ILargeValuesSchema extends mongoose.MongooseDocument { + sum: mongoose.Schema.Types.Decimal128; +} +export var LargeValuesSchema = new mongoose.Schema({ + sum: { + type: mongoose.Schema.Types.Decimal128, + required: true + } +}); + /* * section types/objectid.js * http://mongoosejs.com/docs/api.html#types-objectid-js @@ -1050,7 +1071,7 @@ aggregate.unwind( includeArrayIndex: "idx", preserveNullAndEmptyArrays: true }); - + /* * section schematype.js * http://mongoosejs.com/docs/api.html#schematype-js