@types/{bson,mongodb,mongoose}: added Decimal128 type

This commit is contained in:
Fábio Batista
2017-04-07 21:18:51 -03:00
parent d005e9bd51
commit 16be2fcb11
4 changed files with 49 additions and 4 deletions
+10 -2
View File
@@ -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 <https://github.com/horiuchi/>
// Federico Caselli <https://github.com/CaselIT>
@@ -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;
+1 -1
View File
@@ -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 {
+16
View File
@@ -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
+22 -1
View File
@@ -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