summary refs log tree commit diff
path: root/dist/util/MongoBigInt.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dist/util/MongoBigInt.js70
-rw-r--r--dist/util/MongoBigInt.js.map1
2 files changed, 71 insertions, 0 deletions
diff --git a/dist/util/MongoBigInt.js b/dist/util/MongoBigInt.js
new file mode 100644

index 00000000..7dae718e --- /dev/null +++ b/dist/util/MongoBigInt.js
@@ -0,0 +1,70 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +class LongSchema extends mongoose_1.default.SchemaType { + constructor() { + super(...arguments); + this.$conditionalHandlers = { + $lt: this.handleSingle, + $lte: this.handleSingle, + $gt: this.handleSingle, + $gte: this.handleSingle, + $ne: this.handleSingle, + $in: this.handleArray, + $nin: this.handleArray, + $mod: this.handleArray, + $all: this.handleArray, + $bitsAnySet: this.handleArray, + $bitsAllSet: this.handleArray, + }; + } + handleSingle(val) { + return this.cast(val); + } + handleArray(val) { + var self = this; + return val.map(function (m) { + return self.cast(m); + }); + } + checkRequired(val) { + return null != val; + } + cast(val, scope, init) { + if (null === val) + return val; + if ("" === val) + return null; + if (val instanceof mongoose_1.default.mongo.Long) + return BigInt(val.toString()); + if (val instanceof Number || "number" == typeof val) + return BigInt(val); + if (!Array.isArray(val) && val.toString) + return BigInt(val.toString()); + // @ts-ignore + throw new SchemaType.CastError("Long", val); + } + castForQuery($conditional, value) { + var handler; + if (2 === arguments.length) { + // @ts-ignore + handler = this.$conditionalHandlers[$conditional]; + if (!handler) { + throw new Error("Can't use " + $conditional + " with Long."); + } + return handler.call(this, value); + } + else { + return this.cast($conditional); + } + } +} +LongSchema.cast = mongoose_1.default.SchemaType.cast; +LongSchema.set = mongoose_1.default.SchemaType.set; +LongSchema.get = mongoose_1.default.SchemaType.get; +mongoose_1.default.Schema.Types.Long = LongSchema; +mongoose_1.default.Types.Long = mongoose_1.default.mongo.Long; +//# sourceMappingURL=MongoBigInt.js.map \ No newline at end of file diff --git a/dist/util/MongoBigInt.js.map b/dist/util/MongoBigInt.js.map new file mode 100644
index 00000000..5b0c8caa --- /dev/null +++ b/dist/util/MongoBigInt.js.map
@@ -0,0 +1 @@ +{"version":3,"file":"MongoBigInt.js","sourceRoot":"","sources":["../../src/util/MongoBigInt.ts"],"names":[],"mappings":";;;;;AAAA,wDAAgC;AAEhC,MAAM,UAAW,SAAQ,kBAAQ,CAAC,UAAU;IAA5C;;QACQ,yBAAoB,GAAG;YAC7B,GAAG,EAAE,IAAI,CAAC,YAAY;YACtB,IAAI,EAAE,IAAI,CAAC,YAAY;YACvB,GAAG,EAAE,IAAI,CAAC,YAAY;YACtB,IAAI,EAAE,IAAI,CAAC,YAAY;YACvB,GAAG,EAAE,IAAI,CAAC,YAAY;YACtB,GAAG,EAAE,IAAI,CAAC,WAAW;YACrB,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;SAC7B,CAAC;IA0CH,CAAC;IAxCA,YAAY,CAAC,GAAQ;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAED,WAAW,CAAC,GAAQ;QACnB,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,OAAO,GAAG,CAAC,GAAG,CAAC,UAAU,CAAM;YAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,GAAQ;QACrB,OAAO,IAAI,IAAI,GAAG,CAAC;IACpB,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,KAAW,EAAE,IAAU;QACrC,IAAI,IAAI,KAAK,GAA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