bson
Advanced tools
Comparing version 4.2.2 to 4.2.3
@@ -25,3 +25,3 @@ { | ||
], | ||
"version": "4.2.2" | ||
"version": "4.2.3" | ||
} |
@@ -793,2 +793,3 @@ import { Buffer } from 'buffer'; | ||
_bsontype: 'MaxKey'; | ||
constructor(); | ||
/* Excluded from this release type: toExtendedJSON */ | ||
@@ -808,2 +809,3 @@ /* Excluded from this release type: fromExtendedJSON */ | ||
_bsontype: 'MinKey'; | ||
constructor(); | ||
/* Excluded from this release type: toExtendedJSON */ | ||
@@ -946,2 +948,3 @@ /* Excluded from this release type: fromExtendedJSON */ | ||
*/ | ||
constructor(low: Long); | ||
constructor(low: number, high: number); | ||
@@ -948,0 +951,0 @@ toJSON(): { |
@@ -5,2 +5,12 @@ # Changelog | ||
### [4.2.3](https://github.com/mongodb/js-bson/compare/v4.2.2...v4.2.3) (2021-03-02) | ||
### Bug Fixes | ||
* allow library to be loaded in web workeds ([#423](https://github.com/mongodb/js-bson/issues/423)) ([023f57e](https://github.com/mongodb/js-bson/commit/5ae057d3c6dd87e1407dcdc7b8d9da668023f57e)) | ||
* make inspection result of BSON types evaluable ([#416](https://github.com/mongodb/js-bson/issues/416)) ([616665f](https://github.com/mongodb/js-bson/commit/616665f5e6f7dd06a88de450aaccaa203fa6c652)) | ||
* permit BSON types to be created without new ([#424](https://github.com/mongodb/js-bson/issues/424)) ([d2bc284](https://github.com/mongodb/js-bson/commit/d2bc284943649ac27116701a4ed91ff731a4bdf7)) | ||
### [4.2.2](https://github.com/mongodb/js-bson/compare/v4.2.1...v4.2.2) (2020-12-01) | ||
@@ -7,0 +17,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Binary = void 0; | ||
const buffer_1 = require("buffer"); | ||
const ensure_buffer_1 = require("./ensure_buffer"); | ||
const uuid_1 = require("./uuid"); | ||
var buffer_1 = require("buffer"); | ||
var ensure_buffer_1 = require("./ensure_buffer"); | ||
var uuid_1 = require("./uuid"); | ||
/** | ||
@@ -11,3 +11,3 @@ * A class representation of the BSON Binary type. | ||
*/ | ||
class Binary { | ||
var Binary = /** @class */ (function () { | ||
/** | ||
@@ -17,3 +17,5 @@ * @param buffer - a buffer object containing the binary data. | ||
*/ | ||
constructor(buffer, subType) { | ||
function Binary(buffer, subType) { | ||
if (!(this instanceof Binary)) | ||
return new Binary(buffer, subType); | ||
if (!(buffer == null) && | ||
@@ -53,3 +55,3 @@ !(typeof buffer === 'string') && | ||
*/ | ||
put(byteValue) { | ||
Binary.prototype.put = function (byteValue) { | ||
// If it's a string and a has more than one character throw an error | ||
@@ -62,3 +64,3 @@ if (typeof byteValue === 'string' && byteValue.length !== 1) { | ||
// Decode the byte value once | ||
let decodedByte; | ||
var decodedByte; | ||
if (typeof byteValue === 'string') { | ||
@@ -80,3 +82,3 @@ decodedByte = byteValue.charCodeAt(0); | ||
else { | ||
const buffer = buffer_1.Buffer.alloc(Binary.BUFFER_SIZE + this.buffer.length); | ||
var buffer = buffer_1.Buffer.alloc(Binary.BUFFER_SIZE + this.buffer.length); | ||
// Combine the two buffers together | ||
@@ -87,3 +89,3 @@ this.buffer.copy(buffer, 0, 0, this.buffer.length); | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -95,7 +97,7 @@ * Writes a buffer or string to the binary. | ||
*/ | ||
write(sequence, offset) { | ||
Binary.prototype.write = function (sequence, offset) { | ||
offset = typeof offset === 'number' ? offset : this.position; | ||
// If the buffer is to small let's extend the buffer | ||
if (this.buffer.length < offset + sequence.length) { | ||
const buffer = buffer_1.Buffer.alloc(this.buffer.length + sequence.length); | ||
var buffer = buffer_1.Buffer.alloc(this.buffer.length + sequence.length); | ||
this.buffer.copy(buffer, 0, 0, this.buffer.length); | ||
@@ -115,3 +117,3 @@ // Assign the new buffer | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -123,7 +125,7 @@ * Reads **length** bytes starting at **position**. | ||
*/ | ||
read(position, length) { | ||
Binary.prototype.read = function (position, length) { | ||
length = length && length > 0 ? length : this.position; | ||
// Let's return the data based on the type we have | ||
return this.buffer.slice(position, position + length); | ||
} | ||
}; | ||
/** | ||
@@ -135,3 +137,3 @@ * Returns the value of this binary as a string. | ||
*/ | ||
value(asRaw) { | ||
Binary.prototype.value = function (asRaw) { | ||
asRaw = !!asRaw; | ||
@@ -147,20 +149,20 @@ // Optimize to serialize for the situation where the data == size of buffer | ||
return this.buffer.toString('binary', 0, this.position); | ||
} | ||
}; | ||
/** the length of the binary sequence */ | ||
length() { | ||
Binary.prototype.length = function () { | ||
return this.position; | ||
} | ||
}; | ||
/** @internal */ | ||
toJSON() { | ||
Binary.prototype.toJSON = function () { | ||
return this.buffer.toString('base64'); | ||
} | ||
}; | ||
/** @internal */ | ||
toString(format) { | ||
Binary.prototype.toString = function (format) { | ||
return this.buffer.toString(format); | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON(options) { | ||
Binary.prototype.toExtendedJSON = function (options) { | ||
options = options || {}; | ||
const base64String = this.buffer.toString('base64'); | ||
const subType = Number(this.sub_type).toString(16); | ||
var base64String = this.buffer.toString('base64'); | ||
var subType = Number(this.sub_type).toString(16); | ||
if (options.legacy) { | ||
@@ -178,8 +180,8 @@ return { | ||
}; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc, options) { | ||
Binary.fromExtendedJSON = function (doc, options) { | ||
options = options || {}; | ||
let data; | ||
let type; | ||
var data; | ||
var type; | ||
if ('$binary' in doc) { | ||
@@ -202,38 +204,39 @@ if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) { | ||
if (!data) { | ||
throw new TypeError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`); | ||
throw new TypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc)); | ||
} | ||
return new Binary(data, type); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Binary.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
const asBuffer = this.value(true); | ||
return `Binary("${asBuffer.toString('hex')}", ${this.sub_type})`; | ||
} | ||
} | ||
}; | ||
Binary.prototype.inspect = function () { | ||
var asBuffer = this.value(true); | ||
return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")"; | ||
}; | ||
/** | ||
* Binary default subtype | ||
* @internal | ||
*/ | ||
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0; | ||
/** Initial buffer default size */ | ||
Binary.BUFFER_SIZE = 256; | ||
/** Default BSON type */ | ||
Binary.SUBTYPE_DEFAULT = 0; | ||
/** Function BSON type */ | ||
Binary.SUBTYPE_FUNCTION = 1; | ||
/** Byte Array BSON type */ | ||
Binary.SUBTYPE_BYTE_ARRAY = 2; | ||
/** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */ | ||
Binary.SUBTYPE_UUID_OLD = 3; | ||
/** UUID BSON type */ | ||
Binary.SUBTYPE_UUID = 4; | ||
/** MD5 BSON type */ | ||
Binary.SUBTYPE_MD5 = 5; | ||
/** User BSON type */ | ||
Binary.SUBTYPE_USER_DEFINED = 128; | ||
return Binary; | ||
}()); | ||
exports.Binary = Binary; | ||
/** | ||
* Binary default subtype | ||
* @internal | ||
*/ | ||
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0; | ||
/** Initial buffer default size */ | ||
Binary.BUFFER_SIZE = 256; | ||
/** Default BSON type */ | ||
Binary.SUBTYPE_DEFAULT = 0; | ||
/** Function BSON type */ | ||
Binary.SUBTYPE_FUNCTION = 1; | ||
/** Byte Array BSON type */ | ||
Binary.SUBTYPE_BYTE_ARRAY = 2; | ||
/** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */ | ||
Binary.SUBTYPE_UUID_OLD = 3; | ||
/** UUID BSON type */ | ||
Binary.SUBTYPE_UUID = 4; | ||
/** MD5 BSON type */ | ||
Binary.SUBTYPE_MD5 = 5; | ||
/** User BSON type */ | ||
Binary.SUBTYPE_USER_DEFINED = 128; | ||
Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' }); | ||
//# sourceMappingURL=binary.js.map |
106
lib/bson.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deserializeStream = exports.calculateObjectSize = exports.deserialize = exports.serializeWithBufferAndIndex = exports.serialize = exports.setInternalBufferSize = exports.ObjectID = exports.Decimal128 = exports.BSONRegExp = exports.MaxKey = exports.MinKey = exports.Int32 = exports.Double = exports.Timestamp = exports.Long = exports.ObjectId = exports.Binary = exports.DBRef = exports.BSONSymbol = exports.Map = exports.Code = exports.LongWithoutOverridesClass = exports.EJSON = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_STRING = exports.BSON_DATA_REGEXP = exports.BSON_DATA_OID = exports.BSON_DATA_OBJECT = exports.BSON_DATA_NUMBER = exports.BSON_DATA_NULL = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_LONG = exports.BSON_DATA_INT = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_DATE = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_CODE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = void 0; | ||
const buffer_1 = require("buffer"); | ||
const binary_1 = require("./binary"); | ||
var buffer_1 = require("buffer"); | ||
var binary_1 = require("./binary"); | ||
Object.defineProperty(exports, "Binary", { enumerable: true, get: function () { return binary_1.Binary; } }); | ||
const code_1 = require("./code"); | ||
var code_1 = require("./code"); | ||
Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return code_1.Code; } }); | ||
const db_ref_1 = require("./db_ref"); | ||
var db_ref_1 = require("./db_ref"); | ||
Object.defineProperty(exports, "DBRef", { enumerable: true, get: function () { return db_ref_1.DBRef; } }); | ||
const decimal128_1 = require("./decimal128"); | ||
var decimal128_1 = require("./decimal128"); | ||
Object.defineProperty(exports, "Decimal128", { enumerable: true, get: function () { return decimal128_1.Decimal128; } }); | ||
const double_1 = require("./double"); | ||
var double_1 = require("./double"); | ||
Object.defineProperty(exports, "Double", { enumerable: true, get: function () { return double_1.Double; } }); | ||
const ensure_buffer_1 = require("./ensure_buffer"); | ||
const extended_json_1 = require("./extended_json"); | ||
const int_32_1 = require("./int_32"); | ||
var ensure_buffer_1 = require("./ensure_buffer"); | ||
var extended_json_1 = require("./extended_json"); | ||
var int_32_1 = require("./int_32"); | ||
Object.defineProperty(exports, "Int32", { enumerable: true, get: function () { return int_32_1.Int32; } }); | ||
const long_1 = require("./long"); | ||
var long_1 = require("./long"); | ||
Object.defineProperty(exports, "Long", { enumerable: true, get: function () { return long_1.Long; } }); | ||
const map_1 = require("./map"); | ||
var map_1 = require("./map"); | ||
Object.defineProperty(exports, "Map", { enumerable: true, get: function () { return map_1.Map; } }); | ||
const max_key_1 = require("./max_key"); | ||
var max_key_1 = require("./max_key"); | ||
Object.defineProperty(exports, "MaxKey", { enumerable: true, get: function () { return max_key_1.MaxKey; } }); | ||
const min_key_1 = require("./min_key"); | ||
var min_key_1 = require("./min_key"); | ||
Object.defineProperty(exports, "MinKey", { enumerable: true, get: function () { return min_key_1.MinKey; } }); | ||
const objectid_1 = require("./objectid"); | ||
var objectid_1 = require("./objectid"); | ||
Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return objectid_1.ObjectId; } }); | ||
Object.defineProperty(exports, "ObjectID", { enumerable: true, get: function () { return objectid_1.ObjectId; } }); | ||
const calculate_size_1 = require("./parser/calculate_size"); | ||
var calculate_size_1 = require("./parser/calculate_size"); | ||
// Parts of the parser | ||
const deserializer_1 = require("./parser/deserializer"); | ||
const serializer_1 = require("./parser/serializer"); | ||
const regexp_1 = require("./regexp"); | ||
var deserializer_1 = require("./parser/deserializer"); | ||
var serializer_1 = require("./parser/serializer"); | ||
var regexp_1 = require("./regexp"); | ||
Object.defineProperty(exports, "BSONRegExp", { enumerable: true, get: function () { return regexp_1.BSONRegExp; } }); | ||
const symbol_1 = require("./symbol"); | ||
var symbol_1 = require("./symbol"); | ||
Object.defineProperty(exports, "BSONSymbol", { enumerable: true, get: function () { return symbol_1.BSONSymbol; } }); | ||
const timestamp_1 = require("./timestamp"); | ||
var timestamp_1 = require("./timestamp"); | ||
Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return timestamp_1.Timestamp; } }); | ||
@@ -79,5 +79,5 @@ var constants_1 = require("./constants"); | ||
// Default Max Size | ||
const MAXSIZE = 1024 * 1024 * 17; | ||
var MAXSIZE = 1024 * 1024 * 17; | ||
// Current Internal Temporary Serialization Buffer | ||
let buffer = buffer_1.Buffer.alloc(MAXSIZE); | ||
var buffer = buffer_1.Buffer.alloc(MAXSIZE); | ||
/** | ||
@@ -103,8 +103,9 @@ * Sets the size of the internal serialization buffer. | ||
*/ | ||
function serialize(object, options = {}) { | ||
function serialize(object, options) { | ||
if (options === void 0) { options = {}; } | ||
// Unpack the options | ||
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; | ||
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; | ||
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; | ||
const minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE; | ||
var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; | ||
var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; | ||
var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; | ||
var minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE; | ||
// Resize the internal serialization buffer if needed | ||
@@ -115,5 +116,5 @@ if (buffer.length < minInternalBufferSize) { | ||
// Attempt to serialize | ||
const serializationIndex = serializer_1.serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []); | ||
var serializationIndex = serializer_1.serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []); | ||
// Create the final buffer | ||
const finishedBuffer = buffer_1.Buffer.alloc(serializationIndex); | ||
var finishedBuffer = buffer_1.Buffer.alloc(serializationIndex); | ||
// Copy into the finished buffer | ||
@@ -134,10 +135,11 @@ buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length); | ||
*/ | ||
function serializeWithBufferAndIndex(object, finalBuffer, options = {}) { | ||
function serializeWithBufferAndIndex(object, finalBuffer, options) { | ||
if (options === void 0) { options = {}; } | ||
// Unpack the options | ||
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; | ||
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; | ||
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; | ||
const startIndex = typeof options.index === 'number' ? options.index : 0; | ||
var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false; | ||
var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; | ||
var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; | ||
var startIndex = typeof options.index === 'number' ? options.index : 0; | ||
// Attempt to serialize | ||
const serializationIndex = serializer_1.serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined); | ||
var serializationIndex = serializer_1.serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined); | ||
buffer.copy(finalBuffer, startIndex, 0, serializationIndex); | ||
@@ -155,3 +157,4 @@ // Return the index | ||
*/ | ||
function deserialize(buffer, options = {}) { | ||
function deserialize(buffer, options) { | ||
if (options === void 0) { options = {}; } | ||
return deserializer_1.deserialize(ensure_buffer_1.ensureBuffer(buffer), options); | ||
@@ -167,6 +170,7 @@ } | ||
*/ | ||
function calculateObjectSize(object, options = {}) { | ||
function calculateObjectSize(object, options) { | ||
if (options === void 0) { options = {}; } | ||
options = options || {}; | ||
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; | ||
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; | ||
var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false; | ||
var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true; | ||
return calculate_size_1.calculateObjectSize(object, serializeFunctions, ignoreUndefined); | ||
@@ -188,9 +192,9 @@ } | ||
function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) { | ||
const internalOptions = Object.assign({ allowObjectSmallerThanBufferSize: true, index: 0 }, options); | ||
const bufferData = ensure_buffer_1.ensureBuffer(data); | ||
let index = startIndex; | ||
var internalOptions = Object.assign({ allowObjectSmallerThanBufferSize: true, index: 0 }, options); | ||
var bufferData = ensure_buffer_1.ensureBuffer(data); | ||
var index = startIndex; | ||
// Loop over all documents | ||
for (let i = 0; i < numberOfDocuments; i++) { | ||
for (var i = 0; i < numberOfDocuments; i++) { | ||
// Find size of the document | ||
const size = bufferData[index] | | ||
var size = bufferData[index] | | ||
(bufferData[index + 1] << 8) | | ||
@@ -218,3 +222,3 @@ (bufferData[index + 2] << 16) | | ||
*/ | ||
const BSON = { | ||
var BSON = { | ||
Binary: binary_1.Binary, | ||
@@ -236,10 +240,10 @@ Code: code_1.Code, | ||
EJSON: extended_json_1.EJSON, | ||
setInternalBufferSize, | ||
serialize, | ||
serializeWithBufferAndIndex, | ||
deserialize, | ||
calculateObjectSize, | ||
deserializeStream | ||
setInternalBufferSize: setInternalBufferSize, | ||
serialize: serialize, | ||
serializeWithBufferAndIndex: serializeWithBufferAndIndex, | ||
deserialize: deserialize, | ||
calculateObjectSize: calculateObjectSize, | ||
deserializeStream: deserializeStream | ||
}; | ||
exports.default = BSON; | ||
//# sourceMappingURL=bson.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
*/ | ||
class Code { | ||
var Code = /** @class */ (function () { | ||
/** | ||
@@ -14,3 +14,5 @@ * @param code - a string or function. | ||
*/ | ||
constructor(code, scope) { | ||
function Code(code, scope) { | ||
if (!(this instanceof Code)) | ||
return new Code(code, scope); | ||
this.code = code; | ||
@@ -20,7 +22,7 @@ this.scope = scope; | ||
/** @internal */ | ||
toJSON() { | ||
Code.prototype.toJSON = function () { | ||
return { code: this.code, scope: this.scope }; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON() { | ||
Code.prototype.toExtendedJSON = function () { | ||
if (this.scope) { | ||
@@ -30,18 +32,19 @@ return { $code: this.code, $scope: this.scope }; | ||
return { $code: this.code }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
Code.fromExtendedJSON = function (doc) { | ||
return new Code(doc.$code, doc.$scope); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Code.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
const codeJson = this.toJSON(); | ||
return `Code("${codeJson.code}"${codeJson.scope ? `, ${JSON.stringify(codeJson.scope)}` : ''})`; | ||
} | ||
} | ||
}; | ||
Code.prototype.inspect = function () { | ||
var codeJson = this.toJSON(); | ||
return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")"; | ||
}; | ||
return Code; | ||
}()); | ||
exports.Code = Code; | ||
Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' }); | ||
//# sourceMappingURL=code.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DBRef = exports.isDBRefLike = void 0; | ||
const utils_1 = require("./parser/utils"); | ||
var utils_1 = require("./parser/utils"); | ||
/** @internal */ | ||
@@ -14,3 +14,3 @@ function isDBRefLike(value) { | ||
*/ | ||
class DBRef { | ||
var DBRef = /** @class */ (function () { | ||
/** | ||
@@ -21,5 +21,7 @@ * @param collection - the collection name. | ||
*/ | ||
constructor(collection, oid, db, fields) { | ||
function DBRef(collection, oid, db, fields) { | ||
if (!(this instanceof DBRef)) | ||
return new DBRef(collection, oid, db, fields); | ||
// check if namespace has been provided | ||
const parts = collection.split('.'); | ||
var parts = collection.split('.'); | ||
if (parts.length === 2) { | ||
@@ -35,14 +37,18 @@ db = parts.shift(); | ||
} | ||
// Property provided for compatibility with the 1.x parser | ||
// the 1.x parser used a "namespace" property, while 4.x uses "collection" | ||
Object.defineProperty(DBRef.prototype, "namespace", { | ||
// Property provided for compatibility with the 1.x parser | ||
// the 1.x parser used a "namespace" property, while 4.x uses "collection" | ||
/** @internal */ | ||
get: function () { | ||
return this.collection; | ||
}, | ||
set: function (value) { | ||
this.collection = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** @internal */ | ||
get namespace() { | ||
return this.collection; | ||
} | ||
set namespace(value) { | ||
this.collection = value; | ||
} | ||
/** @internal */ | ||
toJSON() { | ||
const o = Object.assign({ | ||
DBRef.prototype.toJSON = function () { | ||
var o = Object.assign({ | ||
$ref: this.collection, | ||
@@ -54,7 +60,7 @@ $id: this.oid | ||
return o; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON(options) { | ||
DBRef.prototype.toExtendedJSON = function (options) { | ||
options = options || {}; | ||
let o = { | ||
var o = { | ||
$ref: this.collection, | ||
@@ -70,6 +76,6 @@ $id: this.oid | ||
return o; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
const copy = Object.assign({}, doc); | ||
DBRef.fromExtendedJSON = function (doc) { | ||
var copy = Object.assign({}, doc); | ||
delete copy.$ref; | ||
@@ -79,15 +85,16 @@ delete copy.$id; | ||
return new DBRef(doc.$ref, doc.$id, doc.$db, copy); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
DBRef.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
}; | ||
DBRef.prototype.inspect = function () { | ||
// NOTE: if OID is an ObjectId class it will just print the oid string. | ||
const oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString(); | ||
return `DBRef("${this.namespace}", "${oid}"${this.db ? `, "${this.db}"` : ''})`; | ||
} | ||
} | ||
var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString(); | ||
return "new DBRef(\"" + this.namespace + "\", new ObjectId(\"" + oid + "\")" + (this.db ? ", \"" + this.db + "\"" : '') + ")"; | ||
}; | ||
return DBRef; | ||
}()); | ||
exports.DBRef = DBRef; | ||
Object.defineProperty(DBRef.prototype, '_bsontype', { value: 'DBRef' }); | ||
//# sourceMappingURL=db_ref.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Decimal128 = void 0; | ||
const buffer_1 = require("buffer"); | ||
const long_1 = require("./long"); | ||
const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/; | ||
const PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i; | ||
const PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i; | ||
const EXPONENT_MAX = 6111; | ||
const EXPONENT_MIN = -6176; | ||
const EXPONENT_BIAS = 6176; | ||
const MAX_DIGITS = 34; | ||
var buffer_1 = require("buffer"); | ||
var long_1 = require("./long"); | ||
var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/; | ||
var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i; | ||
var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i; | ||
var EXPONENT_MAX = 6111; | ||
var EXPONENT_MIN = -6176; | ||
var EXPONENT_BIAS = 6176; | ||
var MAX_DIGITS = 34; | ||
// Nan value bits as 32 bit values (due to lack of longs) | ||
const NAN_BUFFER = [ | ||
var NAN_BUFFER = [ | ||
0x7c, | ||
@@ -33,3 +33,3 @@ 0x00, | ||
// Infinity value bits 32 bit values (due to lack of longs) | ||
const INF_NEGATIVE_BUFFER = [ | ||
var INF_NEGATIVE_BUFFER = [ | ||
0xf8, | ||
@@ -52,3 +52,3 @@ 0x00, | ||
].reverse(); | ||
const INF_POSITIVE_BUFFER = [ | ||
var INF_POSITIVE_BUFFER = [ | ||
0x78, | ||
@@ -71,11 +71,11 @@ 0x00, | ||
].reverse(); | ||
const EXPONENT_REGEX = /^([-+])?(\d+)?$/; | ||
var EXPONENT_REGEX = /^([-+])?(\d+)?$/; | ||
// Extract least significant 5 bits | ||
const COMBINATION_MASK = 0x1f; | ||
var COMBINATION_MASK = 0x1f; | ||
// Extract least significant 14 bits | ||
const EXPONENT_MASK = 0x3fff; | ||
var EXPONENT_MASK = 0x3fff; | ||
// Value of combination field for Inf | ||
const COMBINATION_INFINITY = 30; | ||
var COMBINATION_INFINITY = 30; | ||
// Value of combination field for NaN | ||
const COMBINATION_NAN = 31; | ||
var COMBINATION_NAN = 31; | ||
// Detect if the value is a digit | ||
@@ -87,8 +87,8 @@ function isDigit(value) { | ||
function divideu128(value) { | ||
const DIVISOR = long_1.Long.fromNumber(1000 * 1000 * 1000); | ||
let _rem = long_1.Long.fromNumber(0); | ||
var DIVISOR = long_1.Long.fromNumber(1000 * 1000 * 1000); | ||
var _rem = long_1.Long.fromNumber(0); | ||
if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) { | ||
return { quotient: value, rem: _rem }; | ||
} | ||
for (let i = 0; i <= 3; i++) { | ||
for (var i = 0; i <= 3; i++) { | ||
// Adjust remainder to match value of next dividend | ||
@@ -108,10 +108,10 @@ _rem = _rem.shiftLeft(32); | ||
} | ||
const leftHigh = left.shiftRightUnsigned(32); | ||
const leftLow = new long_1.Long(left.getLowBits(), 0); | ||
const rightHigh = right.shiftRightUnsigned(32); | ||
const rightLow = new long_1.Long(right.getLowBits(), 0); | ||
let productHigh = leftHigh.multiply(rightHigh); | ||
let productMid = leftHigh.multiply(rightLow); | ||
const productMid2 = leftLow.multiply(rightHigh); | ||
let productLow = leftLow.multiply(rightLow); | ||
var leftHigh = left.shiftRightUnsigned(32); | ||
var leftLow = new long_1.Long(left.getLowBits(), 0); | ||
var rightHigh = right.shiftRightUnsigned(32); | ||
var rightLow = new long_1.Long(right.getLowBits(), 0); | ||
var productHigh = leftHigh.multiply(rightHigh); | ||
var productMid = leftHigh.multiply(rightLow); | ||
var productMid2 = leftLow.multiply(rightHigh); | ||
var productLow = leftLow.multiply(rightLow); | ||
productHigh = productHigh.add(productMid.shiftRightUnsigned(32)); | ||
@@ -128,4 +128,4 @@ productMid = new long_1.Long(productMid.getLowBits(), 0) | ||
// Make values unsigned | ||
const uhleft = left.high >>> 0; | ||
const uhright = right.high >>> 0; | ||
var uhleft = left.high >>> 0; | ||
var uhright = right.high >>> 0; | ||
// Compare high bits first | ||
@@ -136,4 +136,4 @@ if (uhleft < uhright) { | ||
else if (uhleft === uhright) { | ||
const ulleft = left.low >>> 0; | ||
const ulright = right.low >>> 0; | ||
var ulleft = left.low >>> 0; | ||
var ulright = right.low >>> 0; | ||
if (ulleft < ulright) | ||
@@ -145,3 +145,3 @@ return true; | ||
function invalidErr(string, message) { | ||
throw new TypeError(`"${string}" is not a valid Decimal128 string - ${message}`); | ||
throw new TypeError("\"" + string + "\" is not a valid Decimal128 string - " + message); | ||
} | ||
@@ -152,5 +152,7 @@ /** | ||
*/ | ||
class Decimal128 { | ||
var Decimal128 = /** @class */ (function () { | ||
/** @param bytes - a buffer containing the raw Decimal128 bytes in little endian order */ | ||
constructor(bytes) { | ||
function Decimal128(bytes) { | ||
if (!(this instanceof Decimal128)) | ||
return new Decimal128(bytes); | ||
this.bytes = bytes; | ||
@@ -163,39 +165,39 @@ } | ||
*/ | ||
static fromString(representation) { | ||
Decimal128.fromString = function (representation) { | ||
// Parse state tracking | ||
let isNegative = false; | ||
let sawRadix = false; | ||
let foundNonZero = false; | ||
var isNegative = false; | ||
var sawRadix = false; | ||
var foundNonZero = false; | ||
// Total number of significant digits (no leading or trailing zero) | ||
let significantDigits = 0; | ||
var significantDigits = 0; | ||
// Total number of significand digits read | ||
let nDigitsRead = 0; | ||
var nDigitsRead = 0; | ||
// Total number of digits (no leading zeros) | ||
let nDigits = 0; | ||
var nDigits = 0; | ||
// The number of the digits after radix | ||
let radixPosition = 0; | ||
var radixPosition = 0; | ||
// The index of the first non-zero in *str* | ||
let firstNonZero = 0; | ||
var firstNonZero = 0; | ||
// Digits Array | ||
const digits = [0]; | ||
var digits = [0]; | ||
// The number of digits in digits | ||
let nDigitsStored = 0; | ||
var nDigitsStored = 0; | ||
// Insertion pointer for digits | ||
let digitsInsert = 0; | ||
var digitsInsert = 0; | ||
// The index of the first non-zero digit | ||
let firstDigit = 0; | ||
var firstDigit = 0; | ||
// The index of the last digit | ||
let lastDigit = 0; | ||
var lastDigit = 0; | ||
// Exponent | ||
let exponent = 0; | ||
var exponent = 0; | ||
// loop index over array | ||
let i = 0; | ||
var i = 0; | ||
// The high 17 digits of the significand | ||
let significandHigh = new long_1.Long(0, 0); | ||
var significandHigh = new long_1.Long(0, 0); | ||
// The low 17 digits of the significand | ||
let significandLow = new long_1.Long(0, 0); | ||
var significandLow = new long_1.Long(0, 0); | ||
// The biased exponent | ||
let biasedExponent = 0; | ||
var biasedExponent = 0; | ||
// Read index | ||
let index = 0; | ||
var index = 0; | ||
// Naively prevent against REDOS attacks. | ||
@@ -208,5 +210,5 @@ // TODO: implementing a custom parsing for this, or refactoring the regex would yield | ||
// Results | ||
const stringMatch = representation.match(PARSE_STRING_REGEXP); | ||
const infMatch = representation.match(PARSE_INF_REGEXP); | ||
const nanMatch = representation.match(PARSE_NAN_REGEXP); | ||
var stringMatch = representation.match(PARSE_STRING_REGEXP); | ||
var infMatch = representation.match(PARSE_INF_REGEXP); | ||
var nanMatch = representation.match(PARSE_NAN_REGEXP); | ||
// Validate the string | ||
@@ -219,8 +221,8 @@ if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) { | ||
// sign = stringMatch[1] | ||
const unsignedNumber = stringMatch[2]; | ||
var unsignedNumber = stringMatch[2]; | ||
// stringMatch[3] is undefined if a whole number (ex "1", 12") | ||
// but defined if a number w/ decimal in it (ex "1.0, 12.2") | ||
const e = stringMatch[4]; | ||
const expSign = stringMatch[5]; | ||
const expNumber = stringMatch[6]; | ||
var e = stringMatch[4]; | ||
var expSign = stringMatch[5]; | ||
var expNumber = stringMatch[6]; | ||
// they provided e, but didn't give an exponent number. for ex "1e" | ||
@@ -281,3 +283,3 @@ if (e && expNumber === undefined) | ||
// Read exponent digits | ||
const match = representation.substr(++index).match(EXPONENT_REGEX); | ||
var match = representation.substr(++index).match(EXPONENT_REGEX); | ||
// No digits read | ||
@@ -330,3 +332,3 @@ if (!match || !match[2]) | ||
// Check if we have a zero then just hard clamp, otherwise fail | ||
const digitsString = digits.join(''); | ||
var digitsString = digits.join(''); | ||
if (digitsString.match(/^0+$/)) { | ||
@@ -360,3 +362,3 @@ exponent = EXPONENT_MAX; | ||
// Check if we have a zero then just hard clamp, otherwise fail | ||
const digitsString = digits.join(''); | ||
var digitsString = digits.join(''); | ||
if (digitsString.match(/^0+$/)) { | ||
@@ -372,3 +374,3 @@ exponent = EXPONENT_MAX; | ||
if (lastDigit - firstDigit + 1 < significantDigits) { | ||
let endOfString = nDigitsRead; | ||
var endOfString = nDigitsRead; | ||
// If we have seen a radix point, 'string' is 1 longer than we have | ||
@@ -386,4 +388,4 @@ // documented with ndigits_read, so inc the position of the first nonzero | ||
} | ||
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10); | ||
let roundBit = 0; | ||
var roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10); | ||
var roundBit = 0; | ||
if (roundDigit >= 5) { | ||
@@ -402,3 +404,3 @@ roundBit = 1; | ||
if (roundBit) { | ||
let dIdx = lastDigit; | ||
var dIdx = lastDigit; | ||
for (; dIdx >= 0; dIdx--) { | ||
@@ -432,3 +434,3 @@ if (++digits[dIdx] > 9) { | ||
else if (lastDigit - firstDigit < 17) { | ||
let dIdx = firstDigit; | ||
var dIdx = firstDigit; | ||
significandLow = long_1.Long.fromNumber(digits[dIdx++]); | ||
@@ -442,3 +444,3 @@ significandHigh = new long_1.Long(0, 0); | ||
else { | ||
let dIdx = firstDigit; | ||
var dIdx = firstDigit; | ||
significandHigh = long_1.Long.fromNumber(digits[dIdx++]); | ||
@@ -455,3 +457,3 @@ for (; dIdx <= lastDigit - 17; dIdx++) { | ||
} | ||
const significand = multiply64x2(significandHigh, long_1.Long.fromString('100000000000000000')); | ||
var significand = multiply64x2(significandHigh, long_1.Long.fromString('100000000000000000')); | ||
significand.low = significand.low.add(significandLow); | ||
@@ -463,3 +465,3 @@ if (lessThan(significand.low, significandLow)) { | ||
biasedExponent = exponent + EXPONENT_BIAS; | ||
const dec = { low: long_1.Long.fromNumber(0), high: long_1.Long.fromNumber(0) }; | ||
var dec = { low: long_1.Long.fromNumber(0), high: long_1.Long.fromNumber(0) }; | ||
// Encode combination, exponent, and significand. | ||
@@ -482,3 +484,3 @@ if (significand.high.shiftRightUnsigned(49).and(long_1.Long.fromNumber(1)).equals(long_1.Long.fromNumber(1))) { | ||
// Encode into a buffer | ||
const buffer = buffer_1.Buffer.alloc(16); | ||
var buffer = buffer_1.Buffer.alloc(16); | ||
index = 0; | ||
@@ -509,45 +511,45 @@ // Encode the low 64 bits of the decimal | ||
return new Decimal128(buffer); | ||
} | ||
}; | ||
/** Create a string representation of the raw Decimal128 value */ | ||
toString() { | ||
Decimal128.prototype.toString = function () { | ||
// Note: bits in this routine are referred to starting at 0, | ||
// from the sign bit, towards the coefficient. | ||
// decoded biased exponent (14 bits) | ||
let biased_exponent; | ||
var biased_exponent; | ||
// the number of significand digits | ||
let significand_digits = 0; | ||
var significand_digits = 0; | ||
// the base-10 digits in the significand | ||
const significand = new Array(36); | ||
for (let i = 0; i < significand.length; i++) | ||
var significand = new Array(36); | ||
for (var i = 0; i < significand.length; i++) | ||
significand[i] = 0; | ||
// read pointer into significand | ||
let index = 0; | ||
var index = 0; | ||
// true if the number is zero | ||
let is_zero = false; | ||
var is_zero = false; | ||
// the most significant significand bits (50-46) | ||
let significand_msb; | ||
var significand_msb; | ||
// temporary storage for significand decoding | ||
let significand128 = { parts: [0, 0, 0, 0] }; | ||
var significand128 = { parts: [0, 0, 0, 0] }; | ||
// indexing variables | ||
let j, k; | ||
var j, k; | ||
// Output string | ||
const string = []; | ||
var string = []; | ||
// Unpack index | ||
index = 0; | ||
// Buffer reference | ||
const buffer = this.bytes; | ||
var buffer = this.bytes; | ||
// Unpack the low 64bits into a long | ||
// bits 96 - 127 | ||
const low = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
var low = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
// bits 64 - 95 | ||
const midl = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
var midl = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
// Unpack the high 64bits into a long | ||
// bits 32 - 63 | ||
const midh = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
var midh = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
// bits 0 - 31 | ||
const high = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
var high = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
// Unpack index | ||
index = 0; | ||
// Create the state of the decimal | ||
const dec = { | ||
var dec = { | ||
low: new long_1.Long(low, midl), | ||
@@ -561,3 +563,3 @@ high: new long_1.Long(midh, high) | ||
// bits 1 - 5 | ||
const combination = (high >> 26) & COMBINATION_MASK; | ||
var combination = (high >> 26) & COMBINATION_MASK; | ||
if (combination >> 3 === 3) { | ||
@@ -581,3 +583,3 @@ // Check for 'special' values | ||
// unbiased exponent | ||
const exponent = biased_exponent - EXPONENT_BIAS; | ||
var exponent = biased_exponent - EXPONENT_BIAS; | ||
// Create string of significand digits | ||
@@ -599,5 +601,5 @@ // Convert the 114-bit binary number represented by | ||
for (k = 3; k >= 0; k--) { | ||
let least_digits = 0; | ||
var least_digits = 0; | ||
// Perform the divide | ||
const result = divideu128(significand128); | ||
var result = divideu128(significand128); | ||
significand128 = result.quotient; | ||
@@ -632,3 +634,3 @@ least_digits = result.rem.low; | ||
// the exponent if scientific notation is used | ||
const scientific_exponent = significand_digits - 1 + exponent; | ||
var scientific_exponent = significand_digits - 1 + exponent; | ||
// The scientific exponent checks are dictated by the string conversion | ||
@@ -647,3 +649,3 @@ // specification and are somewhat arbitrary cutoffs. | ||
if (significand_digits > 34) { | ||
string.push(`${0}`); | ||
string.push("" + 0); | ||
if (exponent > 0) | ||
@@ -655,3 +657,3 @@ string.push('E+' + exponent); | ||
} | ||
string.push(`${significand[index++]}`); | ||
string.push("" + significand[index++]); | ||
significand_digits = significand_digits - 1; | ||
@@ -661,4 +663,4 @@ if (significand_digits) { | ||
} | ||
for (let i = 0; i < significand_digits; i++) { | ||
string.push(`${significand[index++]}`); | ||
for (var i = 0; i < significand_digits; i++) { | ||
string.push("" + significand[index++]); | ||
} | ||
@@ -671,3 +673,3 @@ // Exponent | ||
else { | ||
string.push(`${scientific_exponent}`); | ||
string.push("" + scientific_exponent); | ||
} | ||
@@ -678,12 +680,12 @@ } | ||
if (exponent >= 0) { | ||
for (let i = 0; i < significand_digits; i++) { | ||
string.push(`${significand[index++]}`); | ||
for (var i = 0; i < significand_digits; i++) { | ||
string.push("" + significand[index++]); | ||
} | ||
} | ||
else { | ||
let radix_position = significand_digits + exponent; | ||
var radix_position = significand_digits + exponent; | ||
// non-zero digits before radix | ||
if (radix_position > 0) { | ||
for (let i = 0; i < radix_position; i++) { | ||
string.push(`${significand[index++]}`); | ||
for (var i = 0; i < radix_position; i++) { | ||
string.push("" + significand[index++]); | ||
} | ||
@@ -699,4 +701,4 @@ } | ||
} | ||
for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) { | ||
string.push(`${significand[index++]}`); | ||
for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) { | ||
string.push("" + significand[index++]); | ||
} | ||
@@ -706,24 +708,25 @@ } | ||
return string.join(''); | ||
} | ||
toJSON() { | ||
}; | ||
Decimal128.prototype.toJSON = function () { | ||
return { $numberDecimal: this.toString() }; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON() { | ||
Decimal128.prototype.toExtendedJSON = function () { | ||
return { $numberDecimal: this.toString() }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
Decimal128.fromExtendedJSON = function (doc) { | ||
return Decimal128.fromString(doc.$numberDecimal); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Decimal128.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return `Decimal128("${this.toString()}")`; | ||
} | ||
} | ||
}; | ||
Decimal128.prototype.inspect = function () { | ||
return "Decimal128.fromString(\"" + this.toString() + "\")"; | ||
}; | ||
return Decimal128; | ||
}()); | ||
exports.Decimal128 = Decimal128; | ||
Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' }); | ||
//# sourceMappingURL=decimal128.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
*/ | ||
class Double { | ||
var Double = /** @class */ (function () { | ||
/** | ||
@@ -15,3 +15,5 @@ * Create a Double type | ||
*/ | ||
constructor(value) { | ||
function Double(value) { | ||
if (!(this instanceof Double)) | ||
return new Double(value); | ||
if (value instanceof Number) { | ||
@@ -27,11 +29,11 @@ value = value.valueOf(); | ||
*/ | ||
valueOf() { | ||
Double.prototype.valueOf = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
toJSON() { | ||
Double.prototype.toJSON = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON(options) { | ||
Double.prototype.toExtendedJSON = function (options) { | ||
if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) { | ||
@@ -43,5 +45,5 @@ return this.value; | ||
if (Object.is(Math.sign(this.value), -0)) { | ||
return { $numberDouble: `-${this.value.toFixed(1)}` }; | ||
return { $numberDouble: "-" + this.value.toFixed(1) }; | ||
} | ||
let $numberDouble; | ||
var $numberDouble; | ||
if (Number.isInteger(this.value)) { | ||
@@ -56,20 +58,21 @@ $numberDouble = this.value.toFixed(1); | ||
} | ||
return { $numberDouble }; | ||
} | ||
return { $numberDouble: $numberDouble }; | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc, options) { | ||
const doubleValue = parseFloat(doc.$numberDouble); | ||
Double.fromExtendedJSON = function (doc, options) { | ||
var doubleValue = parseFloat(doc.$numberDouble); | ||
return options && options.relaxed ? doubleValue : new Double(doubleValue); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Double.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
const eJSON = this.toExtendedJSON(); | ||
return `Double(${eJSON.$numberDouble})`; | ||
} | ||
} | ||
}; | ||
Double.prototype.inspect = function () { | ||
var eJSON = this.toExtendedJSON(); | ||
return "new Double(" + eJSON.$numberDouble + ")"; | ||
}; | ||
return Double; | ||
}()); | ||
exports.Double = Double; | ||
Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' }); | ||
//# sourceMappingURL=double.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ensureBuffer = void 0; | ||
const buffer_1 = require("buffer"); | ||
const utils_1 = require("./parser/utils"); | ||
var buffer_1 = require("buffer"); | ||
var utils_1 = require("./parser/utils"); | ||
/** | ||
@@ -7,0 +7,0 @@ * Makes sure that, if a Uint8Array is passed in, it is wrapped in a Buffer. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EJSON = exports.isBSONType = void 0; | ||
const binary_1 = require("./binary"); | ||
const code_1 = require("./code"); | ||
const db_ref_1 = require("./db_ref"); | ||
const decimal128_1 = require("./decimal128"); | ||
const double_1 = require("./double"); | ||
const int_32_1 = require("./int_32"); | ||
const long_1 = require("./long"); | ||
const max_key_1 = require("./max_key"); | ||
const min_key_1 = require("./min_key"); | ||
const objectid_1 = require("./objectid"); | ||
const utils_1 = require("./parser/utils"); | ||
const regexp_1 = require("./regexp"); | ||
const symbol_1 = require("./symbol"); | ||
const timestamp_1 = require("./timestamp"); | ||
var binary_1 = require("./binary"); | ||
var code_1 = require("./code"); | ||
var db_ref_1 = require("./db_ref"); | ||
var decimal128_1 = require("./decimal128"); | ||
var double_1 = require("./double"); | ||
var int_32_1 = require("./int_32"); | ||
var long_1 = require("./long"); | ||
var max_key_1 = require("./max_key"); | ||
var min_key_1 = require("./min_key"); | ||
var objectid_1 = require("./objectid"); | ||
var utils_1 = require("./parser/utils"); | ||
var regexp_1 = require("./regexp"); | ||
var symbol_1 = require("./symbol"); | ||
var timestamp_1 = require("./timestamp"); | ||
function isBSONType(value) { | ||
@@ -23,10 +23,10 @@ return (utils_1.isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string'); | ||
// INT32 boundaries | ||
const BSON_INT32_MAX = 0x7fffffff; | ||
const BSON_INT32_MIN = -0x80000000; | ||
var BSON_INT32_MAX = 0x7fffffff; | ||
var BSON_INT32_MIN = -0x80000000; | ||
// INT64 boundaries | ||
const BSON_INT64_MAX = 0x7fffffffffffffff; | ||
const BSON_INT64_MIN = -0x8000000000000000; | ||
var BSON_INT64_MAX = 0x7fffffffffffffff; | ||
var BSON_INT64_MIN = -0x8000000000000000; | ||
// all the types where we don't need to do any special processing and can just pass the EJSON | ||
//straight to type.fromExtendedJSON | ||
const keysToCodecs = { | ||
var keysToCodecs = { | ||
$oid: objectid_1.ObjectId, | ||
@@ -47,3 +47,4 @@ $binary: binary_1.Binary, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function deserializeValue(value, options = {}) { | ||
function deserializeValue(value, options) { | ||
if (options === void 0) { options = {}; } | ||
if (typeof value === 'number') { | ||
@@ -70,5 +71,5 @@ if (options.relaxed || options.legacy) { | ||
return null; | ||
const keys = Object.keys(value).filter(k => k.startsWith('$') && value[k] != null); | ||
for (let i = 0; i < keys.length; i++) { | ||
const c = keysToCodecs[keys[i]]; | ||
var keys = Object.keys(value).filter(function (k) { return k.startsWith('$') && value[k] != null; }); | ||
for (var i = 0; i < keys.length; i++) { | ||
var c = keysToCodecs[keys[i]]; | ||
if (c) | ||
@@ -78,4 +79,4 @@ return c.fromExtendedJSON(value, options); | ||
if (value.$date != null) { | ||
const d = value.$date; | ||
const date = new Date(); | ||
var d = value.$date; | ||
var date = new Date(); | ||
if (options.legacy) { | ||
@@ -98,3 +99,3 @@ if (typeof d === 'number') | ||
if (value.$code != null) { | ||
const copy = Object.assign({}, value); | ||
var copy = Object.assign({}, value); | ||
if (value.$scope) { | ||
@@ -106,3 +107,3 @@ copy.$scope = deserializeValue(value.$scope); | ||
if (value.$ref != null || value.$dbPointer != null) { | ||
const v = value.$ref ? value : value.$dbPointer; | ||
var v = value.$ref ? value : value.$dbPointer; | ||
// we run into this in a "degenerate EJSON" case (with $id and $ref order flipped) | ||
@@ -112,10 +113,10 @@ // because of the order JSON.parse goes through the document | ||
return v; | ||
const dollarKeys = Object.keys(v).filter(k => k.startsWith('$')); | ||
let valid = true; | ||
dollarKeys.forEach(k => { | ||
var dollarKeys = Object.keys(v).filter(function (k) { return k.startsWith('$'); }); | ||
var valid_1 = true; | ||
dollarKeys.forEach(function (k) { | ||
if (['$ref', '$id', '$db'].indexOf(k) === -1) | ||
valid = false; | ||
valid_1 = false; | ||
}); | ||
// only make DBRef if $ keys are all valid | ||
if (valid) | ||
if (valid_1) | ||
return db_ref_1.DBRef.fromExtendedJSON(v); | ||
@@ -127,6 +128,6 @@ } | ||
function serializeArray(array, options) { | ||
return array.map((v) => serializeValue(v, options)); | ||
return array.map(function (v) { return serializeValue(v, options); }); | ||
} | ||
function getISOString(date) { | ||
const isoStr = date.toISOString(); | ||
var isoStr = date.toISOString(); | ||
// we should only show milliseconds in timestamp if they're non-zero | ||
@@ -142,3 +143,3 @@ return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z'; | ||
if (value instanceof Date) { | ||
const dateNum = value.getTime(), | ||
var dateNum = value.getTime(), | ||
// is it in year range 1970-9999? | ||
@@ -158,3 +159,3 @@ inRange = dateNum > -1 && dateNum < 253402318800000; | ||
if (Math.floor(value) === value) { | ||
const int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX; | ||
var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX; | ||
// interpret as being of the smallest BSON integer type that can represent the number exactly | ||
@@ -169,5 +170,5 @@ if (int32Range) | ||
if (value instanceof RegExp) { | ||
let flags = value.flags; | ||
var flags = value.flags; | ||
if (flags === undefined) { | ||
const match = value.toString().match(/[gimuy]*$/); | ||
var match = value.toString().match(/[gimuy]*$/); | ||
if (match) { | ||
@@ -177,3 +178,3 @@ flags = match[0]; | ||
} | ||
const rx = new regexp_1.BSONRegExp(value.source, flags); | ||
var rx = new regexp_1.BSONRegExp(value.source, flags); | ||
return rx.toExtendedJSON(options); | ||
@@ -185,19 +186,21 @@ } | ||
} | ||
const BSON_TYPE_MAPPINGS = { | ||
Binary: (o) => new binary_1.Binary(o.value(), o.sub_type), | ||
Code: (o) => new code_1.Code(o.code, o.scope), | ||
DBRef: (o) => new db_ref_1.DBRef(o.collection || o.namespace, o.oid, o.db, o.fields), | ||
Decimal128: (o) => new decimal128_1.Decimal128(o.bytes), | ||
Double: (o) => new double_1.Double(o.value), | ||
Int32: (o) => new int_32_1.Int32(o.value), | ||
Long: (o) => long_1.Long.fromBits( | ||
// underscore variants for 1.x backwards compatibility | ||
o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_), | ||
MaxKey: () => new max_key_1.MaxKey(), | ||
MinKey: () => new min_key_1.MinKey(), | ||
ObjectID: (o) => new objectid_1.ObjectId(o), | ||
ObjectId: (o) => new objectid_1.ObjectId(o), | ||
BSONRegExp: (o) => new regexp_1.BSONRegExp(o.pattern, o.options), | ||
Symbol: (o) => new symbol_1.BSONSymbol(o.value), | ||
Timestamp: (o) => timestamp_1.Timestamp.fromBits(o.low, o.high) | ||
var BSON_TYPE_MAPPINGS = { | ||
Binary: function (o) { return new binary_1.Binary(o.value(), o.sub_type); }, | ||
Code: function (o) { return new code_1.Code(o.code, o.scope); }, | ||
DBRef: function (o) { return new db_ref_1.DBRef(o.collection || o.namespace, o.oid, o.db, o.fields); }, | ||
Decimal128: function (o) { return new decimal128_1.Decimal128(o.bytes); }, | ||
Double: function (o) { return new double_1.Double(o.value); }, | ||
Int32: function (o) { return new int_32_1.Int32(o.value); }, | ||
Long: function (o) { | ||
return long_1.Long.fromBits( | ||
// underscore variants for 1.x backwards compatibility | ||
o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_); | ||
}, | ||
MaxKey: function () { return new max_key_1.MaxKey(); }, | ||
MinKey: function () { return new min_key_1.MinKey(); }, | ||
ObjectID: function (o) { return new objectid_1.ObjectId(o); }, | ||
ObjectId: function (o) { return new objectid_1.ObjectId(o); }, | ||
BSONRegExp: function (o) { return new regexp_1.BSONRegExp(o.pattern, o.options); }, | ||
Symbol: function (o) { return new symbol_1.BSONSymbol(o.value); }, | ||
Timestamp: function (o) { return timestamp_1.Timestamp.fromBits(o.low, o.high); } | ||
}; | ||
@@ -208,7 +211,7 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
throw new Error('not an object instance'); | ||
const bsontype = doc._bsontype; | ||
var bsontype = doc._bsontype; | ||
if (typeof bsontype === 'undefined') { | ||
// It's a regular object. Recursively serialize its property values. | ||
const _doc = {}; | ||
for (const name in doc) { | ||
var _doc = {}; | ||
for (var name in doc) { | ||
_doc[name] = serializeValue(doc[name], options); | ||
@@ -221,3 +224,3 @@ } | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let outDoc = doc; | ||
var outDoc = doc; | ||
if (typeof outDoc.toExtendedJSON !== 'function') { | ||
@@ -228,3 +231,3 @@ // There's no EJSON serialization function on the object. It's probably an | ||
// Copy the object into this library's version of that type. | ||
const mapper = BSON_TYPE_MAPPINGS[doc._bsontype]; | ||
var mapper = BSON_TYPE_MAPPINGS[doc._bsontype]; | ||
if (!mapper) { | ||
@@ -274,3 +277,3 @@ throw new TypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype); | ||
function parse(text, options) { | ||
const finalOptions = Object.assign({}, { relaxed: true, legacy: false }, options); | ||
var finalOptions = Object.assign({}, { relaxed: true, legacy: false }, options); | ||
// relaxed implies not strict | ||
@@ -281,3 +284,3 @@ if (typeof finalOptions.relaxed === 'boolean') | ||
finalOptions.relaxed = !finalOptions.strict; | ||
return JSON.parse(text, (_key, value) => deserializeValue(value, finalOptions)); | ||
return JSON.parse(text, function (_key, value) { return deserializeValue(value, finalOptions); }); | ||
} | ||
@@ -321,3 +324,3 @@ EJSON.parse = parse; | ||
options = Object.assign({}, { relaxed: true, legacy: false }, options); | ||
const doc = serializeValue(value, options); | ||
var doc = serializeValue(value, options); | ||
return JSON.stringify(doc, replacer, space); | ||
@@ -324,0 +327,0 @@ } |
@@ -36,12 +36,12 @@ "use strict"; | ||
function readIEEE754(buffer, offset, endian, mLen, nBytes) { | ||
let e; | ||
let m; | ||
const bBE = endian === 'big'; | ||
const eLen = nBytes * 8 - mLen - 1; | ||
const eMax = (1 << eLen) - 1; | ||
const eBias = eMax >> 1; | ||
let nBits = -7; | ||
let i = bBE ? 0 : nBytes - 1; | ||
const d = bBE ? 1 : -1; | ||
let s = buffer[offset + i]; | ||
var e; | ||
var m; | ||
var bBE = endian === 'big'; | ||
var eLen = nBytes * 8 - mLen - 1; | ||
var eMax = (1 << eLen) - 1; | ||
var eBias = eMax >> 1; | ||
var nBits = -7; | ||
var i = bBE ? 0 : nBytes - 1; | ||
var d = bBE ? 1 : -1; | ||
var s = buffer[offset + i]; | ||
i += d; | ||
@@ -72,13 +72,13 @@ e = s & ((1 << -nBits) - 1); | ||
function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) { | ||
let e; | ||
let m; | ||
let c; | ||
const bBE = endian === 'big'; | ||
let eLen = nBytes * 8 - mLen - 1; | ||
const eMax = (1 << eLen) - 1; | ||
const eBias = eMax >> 1; | ||
const rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; | ||
let i = bBE ? nBytes - 1 : 0; | ||
const d = bBE ? -1 : 1; | ||
const s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; | ||
var e; | ||
var m; | ||
var c; | ||
var bBE = endian === 'big'; | ||
var eLen = nBytes * 8 - mLen - 1; | ||
var eMax = (1 << eLen) - 1; | ||
var eBias = eMax >> 1; | ||
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; | ||
var i = bBE ? nBytes - 1 : 0; | ||
var d = bBE ? -1 : 1; | ||
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; | ||
value = Math.abs(value); | ||
@@ -85,0 +85,0 @@ if (isNaN(value) || value === Infinity) { |
@@ -8,3 +8,3 @@ "use strict"; | ||
*/ | ||
class Int32 { | ||
var Int32 = /** @class */ (function () { | ||
/** | ||
@@ -15,3 +15,5 @@ * Create an Int32 type | ||
*/ | ||
constructor(value) { | ||
function Int32(value) { | ||
if (!(this instanceof Int32)) | ||
return new Int32(value); | ||
if (value instanceof Number) { | ||
@@ -27,29 +29,30 @@ value = value.valueOf(); | ||
*/ | ||
valueOf() { | ||
Int32.prototype.valueOf = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
toJSON() { | ||
Int32.prototype.toJSON = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON(options) { | ||
Int32.prototype.toExtendedJSON = function (options) { | ||
if (options && (options.relaxed || options.legacy)) | ||
return this.value; | ||
return { $numberInt: this.value.toString() }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc, options) { | ||
Int32.fromExtendedJSON = function (doc, options) { | ||
return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Int32.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return `Int32(${this.valueOf()})`; | ||
} | ||
} | ||
}; | ||
Int32.prototype.inspect = function () { | ||
return "new Int32(" + this.valueOf() + ")"; | ||
}; | ||
return Int32; | ||
}()); | ||
exports.Int32 = Int32; | ||
Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' }); | ||
//# sourceMappingURL=int_32.js.map |
459
lib/long.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Long = void 0; | ||
const utils_1 = require("./parser/utils"); | ||
var utils_1 = require("./parser/utils"); | ||
/** | ||
* wasm optimizations, to do native i64 multiplication and divide | ||
*/ | ||
let wasm = undefined; | ||
var wasm = undefined; | ||
try { | ||
@@ -17,11 +17,11 @@ wasm = new WebAssembly.Instance(new WebAssembly.Module( | ||
} | ||
const TWO_PWR_16_DBL = 1 << 16; | ||
const TWO_PWR_24_DBL = 1 << 24; | ||
const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; | ||
const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; | ||
const TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; | ||
var TWO_PWR_16_DBL = 1 << 16; | ||
var TWO_PWR_24_DBL = 1 << 24; | ||
var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; | ||
var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; | ||
var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; | ||
/** A cache of the Long representations of small integer values. */ | ||
const INT_CACHE = {}; | ||
var INT_CACHE = {}; | ||
/** A cache of the Long representations of small unsigned integer values. */ | ||
const UINT_CACHE = {}; | ||
var UINT_CACHE = {}; | ||
/** | ||
@@ -45,3 +45,3 @@ * A class representing a 64-bit integer | ||
*/ | ||
class Long { | ||
var Long = /** @class */ (function () { | ||
/** | ||
@@ -54,3 +54,7 @@ * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. | ||
*/ | ||
constructor(low = 0, high = 0, unsigned) { | ||
function Long(low, high, unsigned) { | ||
if (low === void 0) { low = 0; } | ||
if (high === void 0) { high = 0; } | ||
if (!(this instanceof Long)) | ||
return new Long(low, high, unsigned); | ||
this.low = low | 0; | ||
@@ -74,5 +78,5 @@ this.high = high | 0; | ||
*/ | ||
static fromBits(lowBits, highBits, unsigned) { | ||
Long.fromBits = function (lowBits, highBits, unsigned) { | ||
return new Long(lowBits, highBits, unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -84,4 +88,4 @@ * Returns a Long representing the given 32 bit integer value. | ||
*/ | ||
static fromInt(value, unsigned) { | ||
let obj, cachedObj, cache; | ||
Long.fromInt = function (value, unsigned) { | ||
var obj, cachedObj, cache; | ||
if (unsigned) { | ||
@@ -111,3 +115,3 @@ value >>>= 0; | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -119,3 +123,3 @@ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. | ||
*/ | ||
static fromNumber(value, unsigned) { | ||
Long.fromNumber = function (value, unsigned) { | ||
if (isNaN(value)) | ||
@@ -138,3 +142,3 @@ return unsigned ? Long.UZERO : Long.ZERO; | ||
return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -146,5 +150,5 @@ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. | ||
*/ | ||
static fromBigInt(value, unsigned) { | ||
Long.fromBigInt = function (value, unsigned) { | ||
return Long.fromString(value.toString(), unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -157,3 +161,3 @@ * Returns a Long representation of the given string, written using the specified radix. | ||
*/ | ||
static fromString(str, unsigned, radix) { | ||
Long.fromString = function (str, unsigned, radix) { | ||
if (str.length === 0) | ||
@@ -173,3 +177,3 @@ throw Error('empty string'); | ||
throw RangeError('radix'); | ||
let p; | ||
var p; | ||
if ((p = str.indexOf('-')) > 0) | ||
@@ -182,8 +186,8 @@ throw Error('interior hyphen'); | ||
// minimize the calls to the very expensive emulated div. | ||
const radixToPower = Long.fromNumber(Math.pow(radix, 8)); | ||
let result = Long.ZERO; | ||
for (let i = 0; i < str.length; i += 8) { | ||
const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix); | ||
var radixToPower = Long.fromNumber(Math.pow(radix, 8)); | ||
var result = Long.ZERO; | ||
for (var i = 0; i < str.length; i += 8) { | ||
var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix); | ||
if (size < 8) { | ||
const power = Long.fromNumber(Math.pow(radix, size)); | ||
var power = Long.fromNumber(Math.pow(radix, size)); | ||
result = result.mul(power).add(Long.fromNumber(value)); | ||
@@ -198,3 +202,3 @@ } | ||
return result; | ||
} | ||
}; | ||
/** | ||
@@ -207,5 +211,5 @@ * Creates a Long from its byte representation. | ||
*/ | ||
static fromBytes(bytes, unsigned, le) { | ||
Long.fromBytes = function (bytes, unsigned, le) { | ||
return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -217,5 +221,5 @@ * Creates a Long from its little endian byte representation. | ||
*/ | ||
static fromBytesLE(bytes, unsigned) { | ||
Long.fromBytesLE = function (bytes, unsigned) { | ||
return new Long(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24), bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24), unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -227,5 +231,5 @@ * Creates a Long from its big endian byte representation. | ||
*/ | ||
static fromBytesBE(bytes, unsigned) { | ||
Long.fromBytesBE = function (bytes, unsigned) { | ||
return new Long((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7], (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3], unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -235,5 +239,5 @@ * Tests if the specified object is a Long. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
static isLong(value) { | ||
Long.isLong = function (value) { | ||
return utils_1.isObjectLike(value) && value['__isLong__'] === true; | ||
} | ||
}; | ||
/** | ||
@@ -243,3 +247,3 @@ * Converts the specified value to a Long. | ||
*/ | ||
static fromValue(val, unsigned) { | ||
Long.fromValue = function (val, unsigned) { | ||
if (typeof val === 'number') | ||
@@ -251,17 +255,17 @@ return Long.fromNumber(val, unsigned); | ||
return Long.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned); | ||
} | ||
}; | ||
/** Returns the sum of this and the specified Long. */ | ||
add(addend) { | ||
Long.prototype.add = function (addend) { | ||
if (!Long.isLong(addend)) | ||
addend = Long.fromValue(addend); | ||
// Divide each number into 4 chunks of 16 bits, and then sum the chunks. | ||
const a48 = this.high >>> 16; | ||
const a32 = this.high & 0xffff; | ||
const a16 = this.low >>> 16; | ||
const a00 = this.low & 0xffff; | ||
const b48 = addend.high >>> 16; | ||
const b32 = addend.high & 0xffff; | ||
const b16 = addend.low >>> 16; | ||
const b00 = addend.low & 0xffff; | ||
let c48 = 0, c32 = 0, c16 = 0, c00 = 0; | ||
var a48 = this.high >>> 16; | ||
var a32 = this.high & 0xffff; | ||
var a16 = this.low >>> 16; | ||
var a00 = this.low & 0xffff; | ||
var b48 = addend.high >>> 16; | ||
var b32 = addend.high & 0xffff; | ||
var b16 = addend.low >>> 16; | ||
var b00 = addend.low & 0xffff; | ||
var c48 = 0, c32 = 0, c16 = 0, c00 = 0; | ||
c00 += a00 + b00; | ||
@@ -279,3 +283,3 @@ c16 += c00 >>> 16; | ||
return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -285,7 +289,7 @@ * Returns the sum of this and the specified Long. | ||
*/ | ||
and(other) { | ||
Long.prototype.and = function (other) { | ||
if (!Long.isLong(other)) | ||
other = Long.fromValue(other); | ||
return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -295,3 +299,3 @@ * Compares this Long's value with the specified's. | ||
*/ | ||
compare(other) { | ||
Long.prototype.compare = function (other) { | ||
if (!Long.isLong(other)) | ||
@@ -301,3 +305,3 @@ other = Long.fromValue(other); | ||
return 0; | ||
const thisNeg = this.isNegative(), otherNeg = other.isNegative(); | ||
var thisNeg = this.isNegative(), otherNeg = other.isNegative(); | ||
if (thisNeg && !otherNeg) | ||
@@ -315,7 +319,7 @@ return -1; | ||
: 1; | ||
} | ||
}; | ||
/** This is an alias of {@link Long.compare} */ | ||
comp(other) { | ||
Long.prototype.comp = function (other) { | ||
return this.compare(other); | ||
} | ||
}; | ||
/** | ||
@@ -325,3 +329,3 @@ * Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned. | ||
*/ | ||
divide(divisor) { | ||
Long.prototype.divide = function (divisor) { | ||
if (!Long.isLong(divisor)) | ||
@@ -343,3 +347,3 @@ divisor = Long.fromValue(divisor); | ||
} | ||
const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high); | ||
var low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high); | ||
return Long.fromBits(low, wasm.get_high(), this.unsigned); | ||
@@ -349,3 +353,3 @@ } | ||
return this.unsigned ? Long.UZERO : Long.ZERO; | ||
let approx, rem, res; | ||
var approx, rem, res; | ||
if (!this.unsigned) { | ||
@@ -362,3 +366,3 @@ // This section is only relevant for signed longs and is derived from the | ||
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. | ||
const halfThis = this.shr(1); | ||
var halfThis = this.shr(1); | ||
approx = halfThis.div(divisor).shl(1); | ||
@@ -410,8 +414,8 @@ if (approx.eq(Long.ZERO)) { | ||
// the smallest non-fractional digit, whichever is larger. | ||
const log2 = Math.ceil(Math.log(approx) / Math.LN2); | ||
const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); | ||
var log2 = Math.ceil(Math.log(approx) / Math.LN2); | ||
var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); | ||
// Decrease the approximation until it is smaller than the remainder. Note | ||
// that if it is too large, the product overflows and is negative. | ||
let approxRes = Long.fromNumber(approx); | ||
let approxRem = approxRes.mul(divisor); | ||
var approxRes = Long.fromNumber(approx); | ||
var approxRem = approxRes.mul(divisor); | ||
while (approxRem.isNegative() || approxRem.gt(rem)) { | ||
@@ -430,7 +434,7 @@ approx -= delta; | ||
return res; | ||
} | ||
}; | ||
/**This is an alias of {@link Long.divide} */ | ||
div(divisor) { | ||
Long.prototype.div = function (divisor) { | ||
return this.divide(divisor); | ||
} | ||
}; | ||
/** | ||
@@ -440,3 +444,3 @@ * Tests if this Long's value equals the specified's. | ||
*/ | ||
equals(other) { | ||
Long.prototype.equals = function (other) { | ||
if (!Long.isLong(other)) | ||
@@ -447,25 +451,25 @@ other = Long.fromValue(other); | ||
return this.high === other.high && this.low === other.low; | ||
} | ||
}; | ||
/** This is an alias of {@link Long.equals} */ | ||
eq(other) { | ||
Long.prototype.eq = function (other) { | ||
return this.equals(other); | ||
} | ||
}; | ||
/** Gets the high 32 bits as a signed integer. */ | ||
getHighBits() { | ||
Long.prototype.getHighBits = function () { | ||
return this.high; | ||
} | ||
}; | ||
/** Gets the high 32 bits as an unsigned integer. */ | ||
getHighBitsUnsigned() { | ||
Long.prototype.getHighBitsUnsigned = function () { | ||
return this.high >>> 0; | ||
} | ||
}; | ||
/** Gets the low 32 bits as a signed integer. */ | ||
getLowBits() { | ||
Long.prototype.getLowBits = function () { | ||
return this.low; | ||
} | ||
}; | ||
/** Gets the low 32 bits as an unsigned integer. */ | ||
getLowBitsUnsigned() { | ||
Long.prototype.getLowBitsUnsigned = function () { | ||
return this.low >>> 0; | ||
} | ||
}; | ||
/** Gets the number of bits needed to represent the absolute value of this Long. */ | ||
getNumBitsAbs() { | ||
Long.prototype.getNumBitsAbs = function () { | ||
if (this.isNegative()) { | ||
@@ -475,4 +479,4 @@ // Unsigned Longs are never negative | ||
} | ||
const val = this.high !== 0 ? this.high : this.low; | ||
let bit; | ||
var val = this.high !== 0 ? this.high : this.low; | ||
var bit; | ||
for (bit = 31; bit > 0; bit--) | ||
@@ -482,61 +486,61 @@ if ((val & (1 << bit)) !== 0) | ||
return this.high !== 0 ? bit + 33 : bit + 1; | ||
} | ||
}; | ||
/** Tests if this Long's value is greater than the specified's. */ | ||
greaterThan(other) { | ||
Long.prototype.greaterThan = function (other) { | ||
return this.comp(other) > 0; | ||
} | ||
}; | ||
/** This is an alias of {@link Long.greaterThan} */ | ||
gt(other) { | ||
Long.prototype.gt = function (other) { | ||
return this.greaterThan(other); | ||
} | ||
}; | ||
/** Tests if this Long's value is greater than or equal the specified's. */ | ||
greaterThanOrEqual(other) { | ||
Long.prototype.greaterThanOrEqual = function (other) { | ||
return this.comp(other) >= 0; | ||
} | ||
}; | ||
/** This is an alias of {@link Long.greaterThanOrEqual} */ | ||
gte(other) { | ||
Long.prototype.gte = function (other) { | ||
return this.greaterThanOrEqual(other); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.greaterThanOrEqual} */ | ||
ge(other) { | ||
Long.prototype.ge = function (other) { | ||
return this.greaterThanOrEqual(other); | ||
} | ||
}; | ||
/** Tests if this Long's value is even. */ | ||
isEven() { | ||
Long.prototype.isEven = function () { | ||
return (this.low & 1) === 0; | ||
} | ||
}; | ||
/** Tests if this Long's value is negative. */ | ||
isNegative() { | ||
Long.prototype.isNegative = function () { | ||
return !this.unsigned && this.high < 0; | ||
} | ||
}; | ||
/** Tests if this Long's value is odd. */ | ||
isOdd() { | ||
Long.prototype.isOdd = function () { | ||
return (this.low & 1) === 1; | ||
} | ||
}; | ||
/** Tests if this Long's value is positive. */ | ||
isPositive() { | ||
Long.prototype.isPositive = function () { | ||
return this.unsigned || this.high >= 0; | ||
} | ||
}; | ||
/** Tests if this Long's value equals zero. */ | ||
isZero() { | ||
Long.prototype.isZero = function () { | ||
return this.high === 0 && this.low === 0; | ||
} | ||
}; | ||
/** Tests if this Long's value is less than the specified's. */ | ||
lessThan(other) { | ||
Long.prototype.lessThan = function (other) { | ||
return this.comp(other) < 0; | ||
} | ||
}; | ||
/** This is an alias of {@link Long#lessThan}. */ | ||
lt(other) { | ||
Long.prototype.lt = function (other) { | ||
return this.lessThan(other); | ||
} | ||
}; | ||
/** Tests if this Long's value is less than or equal the specified's. */ | ||
lessThanOrEqual(other) { | ||
Long.prototype.lessThanOrEqual = function (other) { | ||
return this.comp(other) <= 0; | ||
} | ||
}; | ||
/** This is an alias of {@link Long.lessThanOrEqual} */ | ||
lte(other) { | ||
Long.prototype.lte = function (other) { | ||
return this.lessThanOrEqual(other); | ||
} | ||
}; | ||
/** Returns this Long modulo the specified. */ | ||
modulo(divisor) { | ||
Long.prototype.modulo = function (divisor) { | ||
if (!Long.isLong(divisor)) | ||
@@ -546,15 +550,15 @@ divisor = Long.fromValue(divisor); | ||
if (wasm) { | ||
const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high); | ||
var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high); | ||
return Long.fromBits(low, wasm.get_high(), this.unsigned); | ||
} | ||
return this.sub(this.div(divisor).mul(divisor)); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.modulo} */ | ||
mod(divisor) { | ||
Long.prototype.mod = function (divisor) { | ||
return this.modulo(divisor); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.modulo} */ | ||
rem(divisor) { | ||
Long.prototype.rem = function (divisor) { | ||
return this.modulo(divisor); | ||
} | ||
}; | ||
/** | ||
@@ -565,3 +569,3 @@ * Returns the product of this and the specified Long. | ||
*/ | ||
multiply(multiplier) { | ||
Long.prototype.multiply = function (multiplier) { | ||
if (this.isZero()) | ||
@@ -573,3 +577,3 @@ return Long.ZERO; | ||
if (wasm) { | ||
const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high); | ||
var low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high); | ||
return Long.fromBits(low, wasm.get_high(), this.unsigned); | ||
@@ -596,11 +600,11 @@ } | ||
// We can skip products that would overflow. | ||
const a48 = this.high >>> 16; | ||
const a32 = this.high & 0xffff; | ||
const a16 = this.low >>> 16; | ||
const a00 = this.low & 0xffff; | ||
const b48 = multiplier.high >>> 16; | ||
const b32 = multiplier.high & 0xffff; | ||
const b16 = multiplier.low >>> 16; | ||
const b00 = multiplier.low & 0xffff; | ||
let c48 = 0, c32 = 0, c16 = 0, c00 = 0; | ||
var a48 = this.high >>> 16; | ||
var a32 = this.high & 0xffff; | ||
var a16 = this.low >>> 16; | ||
var a00 = this.low & 0xffff; | ||
var b48 = multiplier.high >>> 16; | ||
var b32 = multiplier.high & 0xffff; | ||
var b16 = multiplier.low >>> 16; | ||
var b00 = multiplier.low & 0xffff; | ||
var c48 = 0, c32 = 0, c16 = 0, c00 = 0; | ||
c00 += a00 * b00; | ||
@@ -627,41 +631,41 @@ c16 += c00 >>> 16; | ||
return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.multiply} */ | ||
mul(multiplier) { | ||
Long.prototype.mul = function (multiplier) { | ||
return this.multiply(multiplier); | ||
} | ||
}; | ||
/** Returns the Negation of this Long's value. */ | ||
negate() { | ||
Long.prototype.negate = function () { | ||
if (!this.unsigned && this.eq(Long.MIN_VALUE)) | ||
return Long.MIN_VALUE; | ||
return this.not().add(Long.ONE); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.negate} */ | ||
neg() { | ||
Long.prototype.neg = function () { | ||
return this.negate(); | ||
} | ||
}; | ||
/** Returns the bitwise NOT of this Long. */ | ||
not() { | ||
Long.prototype.not = function () { | ||
return Long.fromBits(~this.low, ~this.high, this.unsigned); | ||
} | ||
}; | ||
/** Tests if this Long's value differs from the specified's. */ | ||
notEquals(other) { | ||
Long.prototype.notEquals = function (other) { | ||
return !this.equals(other); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.notEquals} */ | ||
neq(other) { | ||
Long.prototype.neq = function (other) { | ||
return this.notEquals(other); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.notEquals} */ | ||
ne(other) { | ||
Long.prototype.ne = function (other) { | ||
return this.notEquals(other); | ||
} | ||
}; | ||
/** | ||
* Returns the bitwise OR of this Long and the specified. | ||
*/ | ||
or(other) { | ||
Long.prototype.or = function (other) { | ||
if (!Long.isLong(other)) | ||
other = Long.fromValue(other); | ||
return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned); | ||
} | ||
}; | ||
/** | ||
@@ -672,3 +676,3 @@ * Returns this Long with bits shifted to the left by the given amount. | ||
*/ | ||
shiftLeft(numBits) { | ||
Long.prototype.shiftLeft = function (numBits) { | ||
if (Long.isLong(numBits)) | ||
@@ -682,7 +686,7 @@ numBits = numBits.toInt(); | ||
return Long.fromBits(0, this.low << (numBits - 32), this.unsigned); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.shiftLeft} */ | ||
shl(numBits) { | ||
Long.prototype.shl = function (numBits) { | ||
return this.shiftLeft(numBits); | ||
} | ||
}; | ||
/** | ||
@@ -693,3 +697,3 @@ * Returns this Long with bits arithmetically shifted to the right by the given amount. | ||
*/ | ||
shiftRight(numBits) { | ||
Long.prototype.shiftRight = function (numBits) { | ||
if (Long.isLong(numBits)) | ||
@@ -703,7 +707,7 @@ numBits = numBits.toInt(); | ||
return Long.fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.shiftRight} */ | ||
shr(numBits) { | ||
Long.prototype.shr = function (numBits) { | ||
return this.shiftRight(numBits); | ||
} | ||
}; | ||
/** | ||
@@ -714,3 +718,3 @@ * Returns this Long with bits logically shifted to the right by the given amount. | ||
*/ | ||
shiftRightUnsigned(numBits) { | ||
Long.prototype.shiftRightUnsigned = function (numBits) { | ||
if (Long.isLong(numBits)) | ||
@@ -722,5 +726,5 @@ numBits = numBits.toInt(); | ||
else { | ||
const high = this.high; | ||
var high = this.high; | ||
if (numBits < 32) { | ||
const low = this.low; | ||
var low = this.low; | ||
return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); | ||
@@ -733,11 +737,11 @@ } | ||
} | ||
} | ||
}; | ||
/** This is an alias of {@link Long.shiftRightUnsigned} */ | ||
shr_u(numBits) { | ||
Long.prototype.shr_u = function (numBits) { | ||
return this.shiftRightUnsigned(numBits); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.shiftRightUnsigned} */ | ||
shru(numBits) { | ||
Long.prototype.shru = function (numBits) { | ||
return this.shiftRightUnsigned(numBits); | ||
} | ||
}; | ||
/** | ||
@@ -748,25 +752,25 @@ * Returns the difference of this and the specified Long. | ||
*/ | ||
subtract(subtrahend) { | ||
Long.prototype.subtract = function (subtrahend) { | ||
if (!Long.isLong(subtrahend)) | ||
subtrahend = Long.fromValue(subtrahend); | ||
return this.add(subtrahend.neg()); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.subtract} */ | ||
sub(subtrahend) { | ||
Long.prototype.sub = function (subtrahend) { | ||
return this.subtract(subtrahend); | ||
} | ||
}; | ||
/** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */ | ||
toInt() { | ||
Long.prototype.toInt = function () { | ||
return this.unsigned ? this.low >>> 0 : this.low; | ||
} | ||
}; | ||
/** Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). */ | ||
toNumber() { | ||
Long.prototype.toNumber = function () { | ||
if (this.unsigned) | ||
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0); | ||
return this.high * TWO_PWR_32_DBL + (this.low >>> 0); | ||
} | ||
}; | ||
/** Converts the Long to a BigInt (arbitrary precision). */ | ||
toBigInt() { | ||
Long.prototype.toBigInt = function () { | ||
return BigInt(this.toString()); | ||
} | ||
}; | ||
/** | ||
@@ -777,5 +781,5 @@ * Converts this Long to its byte representation. | ||
*/ | ||
toBytes(le) { | ||
Long.prototype.toBytes = function (le) { | ||
return le ? this.toBytesLE() : this.toBytesBE(); | ||
} | ||
}; | ||
/** | ||
@@ -785,4 +789,4 @@ * Converts this Long to its little endian byte representation. | ||
*/ | ||
toBytesLE() { | ||
const hi = this.high, lo = this.low; | ||
Long.prototype.toBytesLE = function () { | ||
var hi = this.high, lo = this.low; | ||
return [ | ||
@@ -798,3 +802,3 @@ lo & 0xff, | ||
]; | ||
} | ||
}; | ||
/** | ||
@@ -804,4 +808,4 @@ * Converts this Long to its big endian byte representation. | ||
*/ | ||
toBytesBE() { | ||
const hi = this.high, lo = this.low; | ||
Long.prototype.toBytesBE = function () { | ||
var hi = this.high, lo = this.low; | ||
return [ | ||
@@ -817,11 +821,11 @@ hi >>> 24, | ||
]; | ||
} | ||
}; | ||
/** | ||
* Converts this Long to signed. | ||
*/ | ||
toSigned() { | ||
Long.prototype.toSigned = function () { | ||
if (!this.unsigned) | ||
return this; | ||
return Long.fromBits(this.low, this.high, false); | ||
} | ||
}; | ||
/** | ||
@@ -832,3 +836,3 @@ * Converts the Long to a string written in the specified radix. | ||
*/ | ||
toString(radix) { | ||
Long.prototype.toString = function (radix) { | ||
radix = radix || 10; | ||
@@ -844,3 +848,3 @@ if (radix < 2 || 36 < radix) | ||
// the bottom-most digit in this base and then recurse to do the rest. | ||
const radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this); | ||
var radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this); | ||
return div.toString(radix) + rem1.toInt().toString(radix); | ||
@@ -853,11 +857,11 @@ } | ||
// minimize the calls to the very expensive emulated div. | ||
const radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned); | ||
var radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned); | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
let rem = this; | ||
let result = ''; | ||
var rem = this; | ||
var result = ''; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const remDiv = rem.div(radixToPower); | ||
const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0; | ||
let digits = intval.toString(radix); | ||
var remDiv = rem.div(radixToPower); | ||
var intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0; | ||
var digits = intval.toString(radix); | ||
rem = remDiv; | ||
@@ -873,23 +877,23 @@ if (rem.isZero()) { | ||
} | ||
} | ||
}; | ||
/** Converts this Long to unsigned. */ | ||
toUnsigned() { | ||
Long.prototype.toUnsigned = function () { | ||
if (this.unsigned) | ||
return this; | ||
return Long.fromBits(this.low, this.high, true); | ||
} | ||
}; | ||
/** Returns the bitwise XOR of this Long and the given one. */ | ||
xor(other) { | ||
Long.prototype.xor = function (other) { | ||
if (!Long.isLong(other)) | ||
other = Long.fromValue(other); | ||
return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.isZero} */ | ||
eqz() { | ||
Long.prototype.eqz = function () { | ||
return this.isZero(); | ||
} | ||
}; | ||
/** This is an alias of {@link Long.lessThanOrEqual} */ | ||
le(other) { | ||
Long.prototype.le = function (other) { | ||
return this.lessThanOrEqual(other); | ||
} | ||
}; | ||
/* | ||
@@ -900,39 +904,40 @@ **************************************************************** | ||
*/ | ||
toExtendedJSON(options) { | ||
Long.prototype.toExtendedJSON = function (options) { | ||
if (options && options.relaxed) | ||
return this.toNumber(); | ||
return { $numberLong: this.toString() }; | ||
} | ||
static fromExtendedJSON(doc, options) { | ||
const result = Long.fromString(doc.$numberLong); | ||
}; | ||
Long.fromExtendedJSON = function (doc, options) { | ||
var result = Long.fromString(doc.$numberLong); | ||
return options && options.relaxed ? result.toNumber() : result; | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Long.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return `Long("${this.toString()}")`; | ||
} | ||
} | ||
}; | ||
Long.prototype.inspect = function () { | ||
return "new Long(\"" + this.toString() + "\")"; | ||
}; | ||
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL); | ||
/** Maximum unsigned value. */ | ||
Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true); | ||
/** Signed zero */ | ||
Long.ZERO = Long.fromInt(0); | ||
/** Unsigned zero. */ | ||
Long.UZERO = Long.fromInt(0, true); | ||
/** Signed one. */ | ||
Long.ONE = Long.fromInt(1); | ||
/** Unsigned one. */ | ||
Long.UONE = Long.fromInt(1, true); | ||
/** Signed negative one. */ | ||
Long.NEG_ONE = Long.fromInt(-1); | ||
/** Maximum signed value. */ | ||
Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false); | ||
/** Minimum signed value. */ | ||
Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false); | ||
return Long; | ||
}()); | ||
exports.Long = Long; | ||
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL); | ||
/** Maximum unsigned value. */ | ||
Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true); | ||
/** Signed zero */ | ||
Long.ZERO = Long.fromInt(0); | ||
/** Unsigned zero. */ | ||
Long.UZERO = Long.fromInt(0, true); | ||
/** Signed one. */ | ||
Long.ONE = Long.fromInt(1); | ||
/** Unsigned one. */ | ||
Long.UONE = Long.fromInt(1, true); | ||
/** Signed negative one. */ | ||
Long.NEG_ONE = Long.fromInt(-1); | ||
/** Maximum signed value. */ | ||
Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false); | ||
/** Minimum signed value. */ | ||
Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false); | ||
Object.defineProperty(Long.prototype, '__isLong__', { value: true }); | ||
Object.defineProperty(Long.prototype, '_bsontype', { value: 'Long' }); | ||
//# sourceMappingURL=long.js.map |
@@ -7,5 +7,5 @@ "use strict"; | ||
/** @public */ | ||
let bsonMap; | ||
var bsonMap; | ||
exports.Map = bsonMap; | ||
const check = function (potentialGlobal) { | ||
var check = function (potentialGlobal) { | ||
// eslint-disable-next-line eqeqeq | ||
@@ -23,3 +23,3 @@ return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal; | ||
} | ||
const bsonGlobal = getGlobal(); | ||
var bsonGlobal = getGlobal(); | ||
if (Object.prototype.hasOwnProperty.call(bsonGlobal, 'Map')) { | ||
@@ -30,12 +30,13 @@ exports.Map = bsonMap = bsonGlobal.Map; | ||
// We will return a polyfill | ||
exports.Map = bsonMap = class Map { | ||
constructor(array = []) { | ||
exports.Map = bsonMap = /** @class */ (function () { | ||
function Map(array) { | ||
if (array === void 0) { array = []; } | ||
this._keys = []; | ||
this._values = {}; | ||
for (let i = 0; i < array.length; i++) { | ||
for (var i = 0; i < array.length; i++) { | ||
if (array[i] == null) | ||
continue; // skip null and undefined | ||
const entry = array[i]; | ||
const key = entry[0]; | ||
const value = entry[1]; | ||
var entry = array[i]; | ||
var key = entry[0]; | ||
var value = entry[1]; | ||
// Add the key to the list of keys in order | ||
@@ -48,8 +49,8 @@ this._keys.push(key); | ||
} | ||
clear() { | ||
Map.prototype.clear = function () { | ||
this._keys = []; | ||
this._values = {}; | ||
} | ||
delete(key) { | ||
const value = this._values[key]; | ||
}; | ||
Map.prototype.delete = function (key) { | ||
var value = this._values[key]; | ||
if (value == null) | ||
@@ -62,10 +63,11 @@ return false; | ||
return true; | ||
} | ||
entries() { | ||
let index = 0; | ||
}; | ||
Map.prototype.entries = function () { | ||
var _this = this; | ||
var index = 0; | ||
return { | ||
next: () => { | ||
const key = this._keys[index++]; | ||
next: function () { | ||
var key = _this._keys[index++]; | ||
return { | ||
value: key !== undefined ? [key, this._values[key].v] : undefined, | ||
value: key !== undefined ? [key, _this._values[key].v] : undefined, | ||
done: key !== undefined ? false : true | ||
@@ -75,22 +77,23 @@ }; | ||
}; | ||
} | ||
forEach(callback, self) { | ||
}; | ||
Map.prototype.forEach = function (callback, self) { | ||
self = self || this; | ||
for (let i = 0; i < this._keys.length; i++) { | ||
const key = this._keys[i]; | ||
for (var i = 0; i < this._keys.length; i++) { | ||
var key = this._keys[i]; | ||
// Call the forEach callback | ||
callback.call(self, this._values[key].v, key, self); | ||
} | ||
} | ||
get(key) { | ||
}; | ||
Map.prototype.get = function (key) { | ||
return this._values[key] ? this._values[key].v : undefined; | ||
} | ||
has(key) { | ||
}; | ||
Map.prototype.has = function (key) { | ||
return this._values[key] != null; | ||
} | ||
keys() { | ||
let index = 0; | ||
}; | ||
Map.prototype.keys = function () { | ||
var _this = this; | ||
var index = 0; | ||
return { | ||
next: () => { | ||
const key = this._keys[index++]; | ||
next: function () { | ||
var key = _this._keys[index++]; | ||
return { | ||
@@ -102,4 +105,4 @@ value: key !== undefined ? key : undefined, | ||
}; | ||
} | ||
set(key, value) { | ||
}; | ||
Map.prototype.set = function (key, value) { | ||
if (this._values[key]) { | ||
@@ -115,10 +118,11 @@ this._values[key].v = value; | ||
return this; | ||
} | ||
values() { | ||
let index = 0; | ||
}; | ||
Map.prototype.values = function () { | ||
var _this = this; | ||
var index = 0; | ||
return { | ||
next: () => { | ||
const key = this._keys[index++]; | ||
next: function () { | ||
var key = _this._keys[index++]; | ||
return { | ||
value: key !== undefined ? this._values[key].v : undefined, | ||
value: key !== undefined ? _this._values[key].v : undefined, | ||
done: key !== undefined ? false : true | ||
@@ -128,8 +132,13 @@ }; | ||
}; | ||
} | ||
get size() { | ||
return this._keys.length; | ||
} | ||
}; | ||
}; | ||
Object.defineProperty(Map.prototype, "size", { | ||
get: function () { | ||
return this._keys.length; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Map; | ||
}()); | ||
} | ||
//# sourceMappingURL=map.js.map |
@@ -8,21 +8,26 @@ "use strict"; | ||
*/ | ||
class MaxKey { | ||
var MaxKey = /** @class */ (function () { | ||
function MaxKey() { | ||
if (!(this instanceof MaxKey)) | ||
return new MaxKey(); | ||
} | ||
/** @internal */ | ||
toExtendedJSON() { | ||
MaxKey.prototype.toExtendedJSON = function () { | ||
return { $maxKey: 1 }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON() { | ||
MaxKey.fromExtendedJSON = function () { | ||
return new MaxKey(); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
MaxKey.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return 'MaxKey()'; | ||
} | ||
} | ||
}; | ||
MaxKey.prototype.inspect = function () { | ||
return 'new MaxKey()'; | ||
}; | ||
return MaxKey; | ||
}()); | ||
exports.MaxKey = MaxKey; | ||
Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' }); | ||
//# sourceMappingURL=max_key.js.map |
@@ -8,21 +8,26 @@ "use strict"; | ||
*/ | ||
class MinKey { | ||
var MinKey = /** @class */ (function () { | ||
function MinKey() { | ||
if (!(this instanceof MinKey)) | ||
return new MinKey(); | ||
} | ||
/** @internal */ | ||
toExtendedJSON() { | ||
MinKey.prototype.toExtendedJSON = function () { | ||
return { $minKey: 1 }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON() { | ||
MinKey.fromExtendedJSON = function () { | ||
return new MinKey(); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
MinKey.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return 'MinKey()'; | ||
} | ||
} | ||
}; | ||
MinKey.prototype.inspect = function () { | ||
return 'new MinKey()'; | ||
}; | ||
return MinKey; | ||
}()); | ||
exports.MinKey = MinKey; | ||
Object.defineProperty(MinKey.prototype, '_bsontype', { value: 'MinKey' }); | ||
//# sourceMappingURL=min_key.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ObjectId = void 0; | ||
const buffer_1 = require("buffer"); | ||
const ensure_buffer_1 = require("./ensure_buffer"); | ||
const utils_1 = require("./parser/utils"); | ||
var buffer_1 = require("buffer"); | ||
var ensure_buffer_1 = require("./ensure_buffer"); | ||
var utils_1 = require("./parser/utils"); | ||
// constants | ||
const PROCESS_UNIQUE = utils_1.randomBytes(5); | ||
var PROCESS_UNIQUE = utils_1.randomBytes(5); | ||
// Regular expression that checks for hex value | ||
const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$'); | ||
var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$'); | ||
// Precomputed hex table enables speedy hex string conversion | ||
const hexTable = []; | ||
for (let i = 0; i < 256; i++) { | ||
hexTable[i] = (i <= 15 ? '0' : '') + i.toString(16); | ||
var hexTable = []; | ||
for (var i_1 = 0; i_1 < 256; i_1++) { | ||
hexTable[i_1] = (i_1 <= 15 ? '0' : '') + i_1.toString(16); | ||
} | ||
// Lookup tables | ||
const decodeLookup = []; | ||
let i = 0; | ||
var decodeLookup = []; | ||
var i = 0; | ||
while (i < 10) | ||
@@ -23,3 +23,3 @@ decodeLookup[0x30 + i] = i++; | ||
decodeLookup[0x41 - 10 + i] = decodeLookup[0x61 - 10 + i] = i++; | ||
const kId = Symbol('id'); | ||
var kId = Symbol('id'); | ||
/** | ||
@@ -29,3 +29,3 @@ * A class representation of the BSON ObjectId type. | ||
*/ | ||
class ObjectId { | ||
var ObjectId = /** @class */ (function () { | ||
/** | ||
@@ -36,3 +36,5 @@ * Create an ObjectId type | ||
*/ | ||
constructor(id) { | ||
function ObjectId(id) { | ||
if (!(this instanceof ObjectId)) | ||
return new ObjectId(id); | ||
// Duck-typing to support ObjectId from different npm packages | ||
@@ -65,3 +67,3 @@ if (id instanceof ObjectId) { | ||
if (id.length === 12) { | ||
const bytes = buffer_1.Buffer.from(id); | ||
var bytes = buffer_1.Buffer.from(id); | ||
if (bytes.byteLength === 12) { | ||
@@ -82,32 +84,40 @@ this[kId] = bytes; | ||
} | ||
/** | ||
* The ObjectId bytes | ||
* @readonly | ||
*/ | ||
get id() { | ||
return this[kId]; | ||
} | ||
set id(value) { | ||
this[kId] = value; | ||
if (ObjectId.cacheHexString) { | ||
this.__id = value.toString('hex'); | ||
} | ||
} | ||
/** | ||
* The generation time of this ObjectId instance | ||
* @deprecated Please use getTimestamp / createFromTime which returns an int32 epoch | ||
*/ | ||
get generationTime() { | ||
return this.id.readInt32BE(0); | ||
} | ||
set generationTime(value) { | ||
// Encode time into first 4 bytes | ||
this.id.writeUInt32BE(value, 0); | ||
} | ||
Object.defineProperty(ObjectId.prototype, "id", { | ||
/** | ||
* The ObjectId bytes | ||
* @readonly | ||
*/ | ||
get: function () { | ||
return this[kId]; | ||
}, | ||
set: function (value) { | ||
this[kId] = value; | ||
if (ObjectId.cacheHexString) { | ||
this.__id = value.toString('hex'); | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ObjectId.prototype, "generationTime", { | ||
/** | ||
* The generation time of this ObjectId instance | ||
* @deprecated Please use getTimestamp / createFromTime which returns an int32 epoch | ||
*/ | ||
get: function () { | ||
return this.id.readInt32BE(0); | ||
}, | ||
set: function (value) { | ||
// Encode time into first 4 bytes | ||
this.id.writeUInt32BE(value, 0); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** Returns the ObjectId id as a 24 character hex string representation */ | ||
toHexString() { | ||
ObjectId.prototype.toHexString = function () { | ||
if (ObjectId.cacheHexString && this.__id) { | ||
return this.__id; | ||
} | ||
const hexString = this.id.toString('hex'); | ||
var hexString = this.id.toString('hex'); | ||
if (ObjectId.cacheHexString && !this.__id) { | ||
@@ -117,3 +127,3 @@ this.__id = hexString; | ||
return hexString; | ||
} | ||
}; | ||
/** | ||
@@ -125,5 +135,5 @@ * Update the ObjectId index | ||
*/ | ||
static getInc() { | ||
ObjectId.getInc = function () { | ||
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff); | ||
} | ||
}; | ||
/** | ||
@@ -134,8 +144,8 @@ * Generate a 12 byte id buffer used in ObjectId's | ||
*/ | ||
static generate(time) { | ||
ObjectId.generate = function (time) { | ||
if ('number' !== typeof time) { | ||
time = ~~(Date.now() / 1000); | ||
} | ||
const inc = ObjectId.getInc(); | ||
const buffer = buffer_1.Buffer.alloc(12); | ||
var inc = ObjectId.getInc(); | ||
var buffer = buffer_1.Buffer.alloc(12); | ||
// 4-byte timestamp | ||
@@ -154,3 +164,3 @@ buffer.writeUInt32BE(time, 0); | ||
return buffer; | ||
} | ||
}; | ||
/** | ||
@@ -162,3 +172,3 @@ * Converts the id into a 24 character hex string for printing | ||
*/ | ||
toString(format) { | ||
ObjectId.prototype.toString = function (format) { | ||
// Is the id a buffer then use the buffer toString method to return the format | ||
@@ -168,3 +178,3 @@ if (format) | ||
return this.toHexString(); | ||
} | ||
}; | ||
/** | ||
@@ -174,5 +184,5 @@ * Converts to its JSON the 24 character hex string representation. | ||
*/ | ||
toJSON() { | ||
ObjectId.prototype.toJSON = function () { | ||
return this.toHexString(); | ||
} | ||
}; | ||
/** | ||
@@ -183,3 +193,3 @@ * Compares the equality of this ObjectId with `otherID`. | ||
*/ | ||
equals(otherId) { | ||
ObjectId.prototype.equals = function (otherId) { | ||
if (otherId === undefined || otherId === null) { | ||
@@ -209,14 +219,14 @@ return false; | ||
return false; | ||
} | ||
}; | ||
/** Returns the generation date (accurate up to the second) that this ID was generated. */ | ||
getTimestamp() { | ||
const timestamp = new Date(); | ||
const time = this.id.readUInt32BE(0); | ||
ObjectId.prototype.getTimestamp = function () { | ||
var timestamp = new Date(); | ||
var time = this.id.readUInt32BE(0); | ||
timestamp.setTime(Math.floor(time) * 1000); | ||
return timestamp; | ||
} | ||
}; | ||
/** @internal */ | ||
static createPk() { | ||
ObjectId.createPk = function () { | ||
return new ObjectId(); | ||
} | ||
}; | ||
/** | ||
@@ -227,4 +237,4 @@ * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId. | ||
*/ | ||
static createFromTime(time) { | ||
const buffer = buffer_1.Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | ||
ObjectId.createFromTime = function (time) { | ||
var buffer = buffer_1.Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | ||
// Encode time into first 4 bytes | ||
@@ -234,3 +244,3 @@ buffer.writeUInt32BE(time, 0); | ||
return new ObjectId(buffer); | ||
} | ||
}; | ||
/** | ||
@@ -241,3 +251,3 @@ * Creates an ObjectId from a hex string representation of an ObjectId. | ||
*/ | ||
static createFromHexString(hexString) { | ||
ObjectId.createFromHexString = function (hexString) { | ||
// Throw an error if it's not a valid setup | ||
@@ -248,3 +258,3 @@ if (typeof hexString === 'undefined' || (hexString != null && hexString.length !== 24)) { | ||
return new ObjectId(buffer_1.Buffer.from(hexString, 'hex')); | ||
} | ||
}; | ||
/** | ||
@@ -255,3 +265,3 @@ * Checks if a value is a valid bson ObjectId | ||
*/ | ||
static isValid(id) { | ||
ObjectId.isValid = function (id) { | ||
if (id == null) | ||
@@ -279,13 +289,13 @@ return false; | ||
return false; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON() { | ||
ObjectId.prototype.toExtendedJSON = function () { | ||
if (this.toHexString) | ||
return { $oid: this.toHexString() }; | ||
return { $oid: this.toString('hex') }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
ObjectId.fromExtendedJSON = function (doc) { | ||
return new ObjectId(doc.$oid); | ||
} | ||
}; | ||
/** | ||
@@ -297,26 +307,27 @@ * Converts to a string representation of this Id. | ||
*/ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
ObjectId.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return `ObjectId("${this.toHexString()}")`; | ||
} | ||
} | ||
}; | ||
ObjectId.prototype.inspect = function () { | ||
return "new ObjectId(\"" + this.toHexString() + "\")"; | ||
}; | ||
/** @internal */ | ||
ObjectId.index = ~~(Math.random() * 0xffffff); | ||
return ObjectId; | ||
}()); | ||
exports.ObjectId = ObjectId; | ||
/** @internal */ | ||
ObjectId.index = ~~(Math.random() * 0xffffff); | ||
// Deprecated methods | ||
Object.defineProperty(ObjectId.prototype, 'generate', { | ||
value: utils_1.deprecate((time) => ObjectId.generate(time), 'Please use the static `ObjectId.generate(time)` instead') | ||
value: utils_1.deprecate(function (time) { return ObjectId.generate(time); }, 'Please use the static `ObjectId.generate(time)` instead') | ||
}); | ||
Object.defineProperty(ObjectId.prototype, 'getInc', { | ||
value: utils_1.deprecate(() => ObjectId.getInc(), 'Please use the static `ObjectId.getInc()` instead') | ||
value: utils_1.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead') | ||
}); | ||
Object.defineProperty(ObjectId.prototype, 'get_inc', { | ||
value: utils_1.deprecate(() => ObjectId.getInc(), 'Please use the static `ObjectId.getInc()` instead') | ||
value: utils_1.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead') | ||
}); | ||
Object.defineProperty(ObjectId, 'get_inc', { | ||
value: utils_1.deprecate(() => ObjectId.getInc(), 'Please use the static `ObjectId.getInc()` instead') | ||
value: utils_1.deprecate(function () { return ObjectId.getInc(); }, 'Please use the static `ObjectId.getInc()` instead') | ||
}); | ||
Object.defineProperty(ObjectId.prototype, '_bsontype', { value: 'ObjectID' }); | ||
//# sourceMappingURL=objectid.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculateObjectSize = void 0; | ||
const buffer_1 = require("buffer"); | ||
const binary_1 = require("../binary"); | ||
const constants = require("../constants"); | ||
const utils_1 = require("./utils"); | ||
var buffer_1 = require("buffer"); | ||
var binary_1 = require("../binary"); | ||
var constants = require("../constants"); | ||
var utils_1 = require("./utils"); | ||
function calculateObjectSize(object, serializeFunctions, ignoreUndefined) { | ||
let totalLength = 4 + 1; | ||
var totalLength = 4 + 1; | ||
if (Array.isArray(object)) { | ||
for (let i = 0; i < object.length; i++) { | ||
for (var i = 0; i < object.length; i++) { | ||
totalLength += calculateElement(i.toString(), object[i], serializeFunctions, true, ignoreUndefined); | ||
@@ -21,3 +21,3 @@ } | ||
// Calculate size | ||
for (const key in object) { | ||
for (var key in object) { | ||
totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined); | ||
@@ -32,3 +32,6 @@ } | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
value, serializeFunctions = false, isArray = false, ignoreUndefined = false) { | ||
value, serializeFunctions, isArray, ignoreUndefined) { | ||
if (serializeFunctions === void 0) { serializeFunctions = false; } | ||
if (isArray === void 0) { isArray = false; } | ||
if (ignoreUndefined === void 0) { ignoreUndefined = false; } | ||
// If we have toBSON defined, override the current object | ||
@@ -122,3 +125,3 @@ if (value && value.toBSON) { | ||
// Set up correct object for serialization | ||
const ordered_values = Object.assign({ | ||
var ordered_values = Object.assign({ | ||
$ref: value.collection, | ||
@@ -125,0 +128,0 @@ $id: value.oid |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deserialize = void 0; | ||
const buffer_1 = require("buffer"); | ||
const binary_1 = require("../binary"); | ||
const code_1 = require("../code"); | ||
const constants = require("../constants"); | ||
const db_ref_1 = require("../db_ref"); | ||
const decimal128_1 = require("../decimal128"); | ||
const double_1 = require("../double"); | ||
const int_32_1 = require("../int_32"); | ||
const long_1 = require("../long"); | ||
const max_key_1 = require("../max_key"); | ||
const min_key_1 = require("../min_key"); | ||
const objectid_1 = require("../objectid"); | ||
const regexp_1 = require("../regexp"); | ||
const symbol_1 = require("../symbol"); | ||
const timestamp_1 = require("../timestamp"); | ||
const validate_utf8_1 = require("../validate_utf8"); | ||
var buffer_1 = require("buffer"); | ||
var binary_1 = require("../binary"); | ||
var code_1 = require("../code"); | ||
var constants = require("../constants"); | ||
var db_ref_1 = require("../db_ref"); | ||
var decimal128_1 = require("../decimal128"); | ||
var double_1 = require("../double"); | ||
var int_32_1 = require("../int_32"); | ||
var long_1 = require("../long"); | ||
var max_key_1 = require("../max_key"); | ||
var min_key_1 = require("../min_key"); | ||
var objectid_1 = require("../objectid"); | ||
var regexp_1 = require("../regexp"); | ||
var symbol_1 = require("../symbol"); | ||
var timestamp_1 = require("../timestamp"); | ||
var validate_utf8_1 = require("../validate_utf8"); | ||
// Internal long versions | ||
const JS_INT_MAX_LONG = long_1.Long.fromNumber(constants.JS_INT_MAX); | ||
const JS_INT_MIN_LONG = long_1.Long.fromNumber(constants.JS_INT_MIN); | ||
const functionCache = {}; | ||
var JS_INT_MAX_LONG = long_1.Long.fromNumber(constants.JS_INT_MAX); | ||
var JS_INT_MIN_LONG = long_1.Long.fromNumber(constants.JS_INT_MIN); | ||
var functionCache = {}; | ||
function deserialize(buffer, options, isArray) { | ||
options = options == null ? {} : options; | ||
const index = options && options.index ? options.index : 0; | ||
var index = options && options.index ? options.index : 0; | ||
// Read the document size | ||
const size = buffer[index] | | ||
var size = buffer[index] | | ||
(buffer[index + 1] << 8) | | ||
@@ -33,12 +33,12 @@ (buffer[index + 2] << 16) | | ||
if (size < 5) { | ||
throw new Error(`bson size must be >= 5, is ${size}`); | ||
throw new Error("bson size must be >= 5, is " + size); | ||
} | ||
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) { | ||
throw new Error(`buffer length ${buffer.length} must be >= bson size ${size}`); | ||
throw new Error("buffer length " + buffer.length + " must be >= bson size " + size); | ||
} | ||
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) { | ||
throw new Error(`buffer length ${buffer.length} must === bson size ${size}`); | ||
throw new Error("buffer length " + buffer.length + " must === bson size " + size); | ||
} | ||
if (size + index > buffer.byteLength) { | ||
throw new Error(`(bson size ${size} + options.index ${index} must be <= buffer length ${buffer.byteLength})`); | ||
throw new Error("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")"); | ||
} | ||
@@ -53,16 +53,17 @@ // Illegal end value | ||
exports.deserialize = deserialize; | ||
function deserializeObject(buffer, index, options, isArray = false) { | ||
const evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions']; | ||
const cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions']; | ||
const fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw']; | ||
function deserializeObject(buffer, index, options, isArray) { | ||
if (isArray === void 0) { isArray = false; } | ||
var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions']; | ||
var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions']; | ||
var fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw']; | ||
// Return raw bson buffer instead of parsing it | ||
const raw = options['raw'] == null ? false : options['raw']; | ||
var raw = options['raw'] == null ? false : options['raw']; | ||
// Return BSONRegExp objects instead of native regular expressions | ||
const bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false; | ||
var bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false; | ||
// Controls the promotion of values vs wrapper classes | ||
const promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers']; | ||
const promoteLongs = options['promoteLongs'] == null ? true : options['promoteLongs']; | ||
const promoteValues = options['promoteValues'] == null ? true : options['promoteValues']; | ||
var promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers']; | ||
var promoteLongs = options['promoteLongs'] == null ? true : options['promoteLongs']; | ||
var promoteValues = options['promoteValues'] == null ? true : options['promoteValues']; | ||
// Set the start index | ||
const startIndex = index; | ||
var startIndex = index; | ||
// Validate that we have at least 4 bytes of buffer | ||
@@ -72,3 +73,3 @@ if (buffer.length < 5) | ||
// Read the document size | ||
const size = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
var size = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24); | ||
// Ensure buffer is valid size | ||
@@ -78,10 +79,10 @@ if (size < 5 || size > buffer.length) | ||
// Create holding object | ||
const object = isArray ? [] : {}; | ||
var object = isArray ? [] : {}; | ||
// Used for arrays to skip having to perform utf8 decoding | ||
let arrayIndex = 0; | ||
const done = false; | ||
var arrayIndex = 0; | ||
var done = false; | ||
// While we have more left data left keep parsing | ||
while (!done) { | ||
// Read the type | ||
const elementType = buffer[index++]; | ||
var elementType = buffer[index++]; | ||
// If we get a zero it's the last byte, exit | ||
@@ -91,3 +92,3 @@ if (elementType === 0) | ||
// Get the start search index | ||
let i = index; | ||
var i = index; | ||
// Locate the end of the c string | ||
@@ -100,6 +101,6 @@ while (buffer[i] !== 0x00 && i < buffer.length) { | ||
throw new Error('Bad BSON Document: illegal CString'); | ||
const name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); | ||
var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); | ||
index = i + 1; | ||
if (elementType === constants.BSON_DATA_STRING) { | ||
const stringSize = buffer[index++] | | ||
var stringSize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -115,3 +116,3 @@ (buffer[index++] << 16) | | ||
} | ||
const s = buffer.toString('utf8', index, index + stringSize - 1); | ||
var s = buffer.toString('utf8', index, index + stringSize - 1); | ||
object[name] = s; | ||
@@ -121,3 +122,3 @@ index = index + stringSize; | ||
else if (elementType === constants.BSON_DATA_OID) { | ||
const oid = buffer_1.Buffer.alloc(12); | ||
var oid = buffer_1.Buffer.alloc(12); | ||
buffer.copy(oid, 0, index, index + 12); | ||
@@ -146,7 +147,7 @@ object[name] = new objectid_1.ObjectId(oid); | ||
else if (elementType === constants.BSON_DATA_DATE) { | ||
const lowBits = buffer[index++] | | ||
var lowBits = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
(buffer[index++] << 16) | | ||
(buffer[index++] << 24); | ||
const highBits = buffer[index++] | | ||
var highBits = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -163,4 +164,4 @@ (buffer[index++] << 16) | | ||
else if (elementType === constants.BSON_DATA_OBJECT) { | ||
const _index = index; | ||
const objectSize = buffer[index] | | ||
var _index = index; | ||
var objectSize = buffer[index] | | ||
(buffer[index + 1] << 8) | | ||
@@ -181,14 +182,14 @@ (buffer[index + 2] << 16) | | ||
else if (elementType === constants.BSON_DATA_ARRAY) { | ||
const _index = index; | ||
const objectSize = buffer[index] | | ||
var _index = index; | ||
var objectSize = buffer[index] | | ||
(buffer[index + 1] << 8) | | ||
(buffer[index + 2] << 16) | | ||
(buffer[index + 3] << 24); | ||
let arrayOptions = options; | ||
var arrayOptions = options; | ||
// Stop index | ||
const stopIndex = index + objectSize; | ||
var stopIndex = index + objectSize; | ||
// All elements of array to be returned as raw bson | ||
if (fieldsAsRaw && fieldsAsRaw[name]) { | ||
arrayOptions = {}; | ||
for (const n in options) { | ||
for (var n in options) { | ||
arrayOptions[n] = options[n]; | ||
@@ -213,11 +214,11 @@ } | ||
// Unpack the low and high bits | ||
const lowBits = buffer[index++] | | ||
var lowBits = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
(buffer[index++] << 16) | | ||
(buffer[index++] << 24); | ||
const highBits = buffer[index++] | | ||
var highBits = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
(buffer[index++] << 16) | | ||
(buffer[index++] << 24); | ||
const long = new long_1.Long(lowBits, highBits); | ||
var long = new long_1.Long(lowBits, highBits); | ||
// Promote the long if possible | ||
@@ -236,3 +237,3 @@ if (promoteLongs && promoteValues === true) { | ||
// Buffer to contain the decimal bytes | ||
const bytes = buffer_1.Buffer.alloc(16); | ||
var bytes = buffer_1.Buffer.alloc(16); | ||
// Copy the next 16 bytes into the bytes buffer | ||
@@ -243,3 +244,3 @@ buffer.copy(bytes, 0, index, index + 16); | ||
// Assign the new Decimal128 value | ||
const decimal128 = new decimal128_1.Decimal128(bytes); | ||
var decimal128 = new decimal128_1.Decimal128(bytes); | ||
// If we have an alternative mapper use that | ||
@@ -254,8 +255,8 @@ if ('toObject' in decimal128 && typeof decimal128.toObject === 'function') { | ||
else if (elementType === constants.BSON_DATA_BINARY) { | ||
let binarySize = buffer[index++] | | ||
var binarySize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
(buffer[index++] << 16) | | ||
(buffer[index++] << 24); | ||
const totalBinarySize = binarySize; | ||
const subType = buffer[index++]; | ||
var totalBinarySize = binarySize; | ||
var subType = buffer[index++]; | ||
// Did we have a negative binary size, throw | ||
@@ -291,3 +292,3 @@ if (binarySize < 0) | ||
else { | ||
const _buffer = buffer_1.Buffer.alloc(binarySize); | ||
var _buffer = buffer_1.Buffer.alloc(binarySize); | ||
// If we have subtype 2 skip the 4 bytes for the size | ||
@@ -332,3 +333,3 @@ if (subType === binary_1.Binary.SUBTYPE_BYTE_ARRAY) { | ||
// Return the C string | ||
const source = buffer.toString('utf8', index, i); | ||
var source = buffer.toString('utf8', index, i); | ||
// Create the regexp | ||
@@ -346,6 +347,6 @@ index = i + 1; | ||
// Return the C string | ||
const regExpOptions = buffer.toString('utf8', index, i); | ||
var regExpOptions = buffer.toString('utf8', index, i); | ||
index = i + 1; | ||
// For each option add the corresponding one for javascript | ||
const optionsArray = new Array(regExpOptions.length); | ||
var optionsArray = new Array(regExpOptions.length); | ||
// Parse options | ||
@@ -378,3 +379,3 @@ for (i = 0; i < regExpOptions.length; i++) { | ||
// Return the C string | ||
const source = buffer.toString('utf8', index, i); | ||
var source = buffer.toString('utf8', index, i); | ||
index = i + 1; | ||
@@ -391,3 +392,3 @@ // Get the start search index | ||
// Return the C string | ||
const regExpOptions = buffer.toString('utf8', index, i); | ||
var regExpOptions = buffer.toString('utf8', index, i); | ||
index = i + 1; | ||
@@ -398,3 +399,3 @@ // Set the object | ||
else if (elementType === constants.BSON_DATA_SYMBOL) { | ||
const stringSize = buffer[index++] | | ||
var stringSize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -407,3 +408,3 @@ (buffer[index++] << 16) | | ||
throw new Error('bad string length in bson'); | ||
const symbol = buffer.toString('utf8', index, index + stringSize - 1); | ||
var symbol = buffer.toString('utf8', index, index + stringSize - 1); | ||
object[name] = promoteValues ? symbol : new symbol_1.BSONSymbol(symbol); | ||
@@ -413,7 +414,7 @@ index = index + stringSize; | ||
else if (elementType === constants.BSON_DATA_TIMESTAMP) { | ||
const lowBits = buffer[index++] | | ||
var lowBits = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
(buffer[index++] << 16) | | ||
(buffer[index++] << 24); | ||
const highBits = buffer[index++] | | ||
var highBits = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -431,3 +432,3 @@ (buffer[index++] << 16) | | ||
else if (elementType === constants.BSON_DATA_CODE) { | ||
const stringSize = buffer[index++] | | ||
var stringSize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -440,3 +441,3 @@ (buffer[index++] << 16) | | ||
throw new Error('bad string length in bson'); | ||
const functionString = buffer.toString('utf8', index, index + stringSize - 1); | ||
var functionString = buffer.toString('utf8', index, index + stringSize - 1); | ||
// If we are evaluating the functions | ||
@@ -460,3 +461,3 @@ if (evalFunctions) { | ||
else if (elementType === constants.BSON_DATA_CODE_W_SCOPE) { | ||
const totalSize = buffer[index++] | | ||
var totalSize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -470,3 +471,3 @@ (buffer[index++] << 16) | | ||
// Get the code string size | ||
const stringSize = buffer[index++] | | ||
var stringSize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -481,9 +482,9 @@ (buffer[index++] << 16) | | ||
// Javascript function | ||
const functionString = buffer.toString('utf8', index, index + stringSize - 1); | ||
var functionString = buffer.toString('utf8', index, index + stringSize - 1); | ||
// Update parse index position | ||
index = index + stringSize; | ||
// Parse the element | ||
const _index = index; | ||
var _index = index; | ||
// Decode the size of the object document | ||
const objectSize = buffer[index] | | ||
var objectSize = buffer[index] | | ||
(buffer[index + 1] << 8) | | ||
@@ -493,3 +494,3 @@ (buffer[index + 2] << 16) | | ||
// Decode the scope object | ||
const scopeObject = deserializeObject(buffer, _index, options, false); | ||
var scopeObject = deserializeObject(buffer, _index, options, false); | ||
// Adjust the index | ||
@@ -523,3 +524,3 @@ index = index + objectSize; | ||
// Get the code string size | ||
const stringSize = buffer[index++] | | ||
var stringSize = buffer[index++] | | ||
(buffer[index++] << 8) | | ||
@@ -537,9 +538,9 @@ (buffer[index++] << 16) | | ||
} | ||
const namespace = buffer.toString('utf8', index, index + stringSize - 1); | ||
var namespace = buffer.toString('utf8', index, index + stringSize - 1); | ||
// Update parse index position | ||
index = index + stringSize; | ||
// Read the oid | ||
const oidBuffer = buffer_1.Buffer.alloc(12); | ||
var oidBuffer = buffer_1.Buffer.alloc(12); | ||
buffer.copy(oidBuffer, 0, index, index + 12); | ||
const oid = new objectid_1.ObjectId(oidBuffer); | ||
var oid = new objectid_1.ObjectId(oidBuffer); | ||
// Update the index | ||
@@ -561,5 +562,5 @@ index = index + 12; | ||
// check if object's $ keys are those of a DBRef | ||
const dollarKeys = Object.keys(object).filter(k => k.startsWith('$')); | ||
let valid = true; | ||
dollarKeys.forEach(k => { | ||
var dollarKeys = Object.keys(object).filter(function (k) { return k.startsWith('$'); }); | ||
var valid = true; | ||
dollarKeys.forEach(function (k) { | ||
if (['$ref', '$id', '$db'].indexOf(k) === -1) | ||
@@ -572,3 +573,3 @@ valid = false; | ||
if (db_ref_1.isDBRefLike(object)) { | ||
const copy = Object.assign({}, object); | ||
var copy = Object.assign({}, object); | ||
delete copy.$ref; | ||
@@ -575,0 +576,0 @@ delete copy.$id; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeInto = void 0; | ||
const binary_1 = require("../binary"); | ||
const constants = require("../constants"); | ||
const ensure_buffer_1 = require("../ensure_buffer"); | ||
const extended_json_1 = require("../extended_json"); | ||
const float_parser_1 = require("../float_parser"); | ||
const long_1 = require("../long"); | ||
const map_1 = require("../map"); | ||
const utils_1 = require("./utils"); | ||
const regexp = /\x00/; // eslint-disable-line no-control-regex | ||
const ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']); | ||
var binary_1 = require("../binary"); | ||
var constants = require("../constants"); | ||
var ensure_buffer_1 = require("../ensure_buffer"); | ||
var extended_json_1 = require("../extended_json"); | ||
var float_parser_1 = require("../float_parser"); | ||
var long_1 = require("../long"); | ||
var map_1 = require("../map"); | ||
var utils_1 = require("./utils"); | ||
var regexp = /\x00/; // eslint-disable-line no-control-regex | ||
var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']); | ||
function isRegExp(d) { | ||
@@ -26,3 +26,3 @@ return Object.prototype.toString.call(d) === '[object RegExp]'; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -34,3 +34,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Write the string | ||
const size = buffer.write(value, index + 4, undefined, 'utf8'); | ||
var size = buffer.write(value, index + 4, undefined, 'utf8'); | ||
// Write the size of the string to buffer | ||
@@ -57,3 +57,3 @@ buffer[index + 3] = ((size + 1) >> 24) & 0xff; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -74,3 +74,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -92,3 +92,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -105,3 +105,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -120,3 +120,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -128,5 +128,5 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Write the date | ||
const dateInMilis = long_1.Long.fromNumber(value.getTime()); | ||
const lowBits = dateInMilis.getLowBits(); | ||
const highBits = dateInMilis.getHighBits(); | ||
var dateInMilis = long_1.Long.fromNumber(value.getTime()); | ||
var lowBits = dateInMilis.getLowBits(); | ||
var highBits = dateInMilis.getHighBits(); | ||
// Encode low bits | ||
@@ -148,3 +148,3 @@ buffer[index++] = lowBits & 0xff; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -177,3 +177,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -212,3 +212,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -225,3 +225,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -249,3 +249,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -257,3 +257,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Get size of the buffer (current write point) | ||
const size = value.length; | ||
var size = value.length; | ||
// Write the size of the string to buffer | ||
@@ -272,4 +272,10 @@ buffer[index++] = size & 0xff; | ||
} | ||
function serializeObject(buffer, key, value, index, checkKeys = false, depth = 0, serializeFunctions = false, ignoreUndefined = true, isArray = false, path = []) { | ||
for (let i = 0; i < path.length; i++) { | ||
function serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, isArray, path) { | ||
if (checkKeys === void 0) { checkKeys = false; } | ||
if (depth === void 0) { depth = 0; } | ||
if (serializeFunctions === void 0) { serializeFunctions = false; } | ||
if (ignoreUndefined === void 0) { ignoreUndefined = true; } | ||
if (isArray === void 0) { isArray = false; } | ||
if (path === void 0) { path = []; } | ||
for (var i = 0; i < path.length; i++) { | ||
if (path[i] === value) | ||
@@ -283,3 +289,3 @@ throw new Error('cyclic dependency detected'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -290,3 +296,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
buffer[index++] = 0; | ||
const endIndex = serializeInto(buffer, value, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path); | ||
var endIndex = serializeInto(buffer, value, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path); | ||
// Pop stack | ||
@@ -299,3 +305,3 @@ path.pop(); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -315,3 +321,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -323,4 +329,4 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Write the date | ||
const lowBits = value.getLowBits(); | ||
const highBits = value.getHighBits(); | ||
var lowBits = value.getLowBits(); | ||
var highBits = value.getHighBits(); | ||
// Encode low bits | ||
@@ -343,3 +349,3 @@ buffer[index++] = lowBits & 0xff; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -361,3 +367,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -374,6 +380,8 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
} | ||
function serializeFunction(buffer, key, value, index, _checkKeys = false, _depth = 0, isArray) { | ||
function serializeFunction(buffer, key, value, index, _checkKeys, _depth, isArray) { | ||
if (_checkKeys === void 0) { _checkKeys = false; } | ||
if (_depth === void 0) { _depth = 0; } | ||
buffer[index++] = constants.BSON_DATA_CODE; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -385,5 +393,5 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Function string | ||
const functionString = utils_1.normalizedFunctionString(value); | ||
var functionString = utils_1.normalizedFunctionString(value); | ||
// Write the string | ||
const size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; | ||
var size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; | ||
// Write the size of the string to buffer | ||
@@ -400,3 +408,8 @@ buffer[index] = size & 0xff; | ||
} | ||
function serializeCode(buffer, key, value, index, checkKeys = false, depth = 0, serializeFunctions = false, ignoreUndefined = true, isArray = false) { | ||
function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, isArray) { | ||
if (checkKeys === void 0) { checkKeys = false; } | ||
if (depth === void 0) { depth = 0; } | ||
if (serializeFunctions === void 0) { serializeFunctions = false; } | ||
if (ignoreUndefined === void 0) { ignoreUndefined = true; } | ||
if (isArray === void 0) { isArray = false; } | ||
if (value.scope && typeof value.scope === 'object') { | ||
@@ -406,3 +419,3 @@ // Write the type | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -414,10 +427,10 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Starting index | ||
let startIndex = index; | ||
var startIndex = index; | ||
// Serialize the function | ||
// Get the function string | ||
const functionString = typeof value.code === 'string' ? value.code : value.code.toString(); | ||
var functionString = typeof value.code === 'string' ? value.code : value.code.toString(); | ||
// Index adjustment | ||
index = index + 4; | ||
// Write string into buffer | ||
const codeSize = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; | ||
var codeSize = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; | ||
// Write the size of the string to buffer | ||
@@ -434,6 +447,6 @@ buffer[index] = codeSize & 0xff; | ||
// Serialize the scope value | ||
const endIndex = serializeInto(buffer, value.scope, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined); | ||
var endIndex = serializeInto(buffer, value.scope, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined); | ||
index = endIndex - 1; | ||
// Writ the total | ||
const totalSize = endIndex - startIndex; | ||
var totalSize = endIndex - startIndex; | ||
// Write the total size of the object | ||
@@ -450,3 +463,3 @@ buffer[startIndex++] = totalSize & 0xff; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -458,5 +471,5 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Function string | ||
const functionString = value.code.toString(); | ||
var functionString = value.code.toString(); | ||
// Write the string | ||
const size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; | ||
var size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; | ||
// Write the size of the string to buffer | ||
@@ -478,3 +491,3 @@ buffer[index] = size & 0xff; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -486,5 +499,5 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Extract the buffer | ||
const data = value.value(true); | ||
var data = value.value(true); | ||
// Calculate size | ||
let size = value.position; | ||
var size = value.position; | ||
// Add the deprecated 02 type 4 bytes of size to total | ||
@@ -518,3 +531,3 @@ if (value.sub_type === binary_1.Binary.SUBTYPE_BYTE_ARRAY) | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -526,3 +539,3 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
// Write the string | ||
const size = buffer.write(value.value, index + 4, undefined, 'utf8') + 1; | ||
var size = buffer.write(value.value, index + 4, undefined, 'utf8') + 1; | ||
// Write the size of the string to buffer | ||
@@ -543,3 +556,3 @@ buffer[index] = size & 0xff; | ||
// Number of written bytes | ||
const numberOfWrittenBytes = !isArray | ||
var numberOfWrittenBytes = !isArray | ||
? buffer.write(key, index, undefined, 'utf8') | ||
@@ -550,4 +563,4 @@ : buffer.write(key, index, undefined, 'ascii'); | ||
buffer[index++] = 0; | ||
let startIndex = index; | ||
let output = { | ||
var startIndex = index; | ||
var output = { | ||
$ref: value.collection || value.namespace, | ||
@@ -560,5 +573,5 @@ $id: value.oid | ||
output = Object.assign(output, value.fields); | ||
const endIndex = serializeInto(buffer, output, false, index, depth + 1, serializeFunctions); | ||
var endIndex = serializeInto(buffer, output, false, index, depth + 1, serializeFunctions); | ||
// Calculate object size | ||
const size = endIndex - startIndex; | ||
var size = endIndex - startIndex; | ||
// Write the size | ||
@@ -572,3 +585,9 @@ buffer[startIndex++] = size & 0xff; | ||
} | ||
function serializeInto(buffer, object, checkKeys = false, startingIndex = 0, depth = 0, serializeFunctions = false, ignoreUndefined = true, path = []) { | ||
function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializeFunctions, ignoreUndefined, path) { | ||
if (checkKeys === void 0) { checkKeys = false; } | ||
if (startingIndex === void 0) { startingIndex = 0; } | ||
if (depth === void 0) { depth = 0; } | ||
if (serializeFunctions === void 0) { serializeFunctions = false; } | ||
if (ignoreUndefined === void 0) { ignoreUndefined = true; } | ||
if (path === void 0) { path = []; } | ||
startingIndex = startingIndex || 0; | ||
@@ -579,9 +598,9 @@ path = path || []; | ||
// Start place to serialize into | ||
let index = startingIndex + 4; | ||
var index = startingIndex + 4; | ||
// Special case isArray | ||
if (Array.isArray(object)) { | ||
// Get object keys | ||
for (let i = 0; i < object.length; i++) { | ||
const key = '' + i; | ||
let value = object[i]; | ||
for (var i = 0; i < object.length; i++) { | ||
var key = '' + i; | ||
var value = object[i]; | ||
// Is there an override value | ||
@@ -667,7 +686,7 @@ if (value && value.toBSON) { | ||
else if (object instanceof map_1.Map) { | ||
const iterator = object.entries(); | ||
let done = false; | ||
var iterator = object.entries(); | ||
var done = false; | ||
while (!done) { | ||
// Unpack the next entry | ||
const entry = iterator.next(); | ||
var entry = iterator.next(); | ||
done = !!entry.done; | ||
@@ -678,6 +697,6 @@ // Are we done, then skip and terminate | ||
// Get the entry values | ||
const key = entry.value[0]; | ||
const value = entry.value[1]; | ||
var key = entry.value[0]; | ||
var value = entry.value[1]; | ||
// Check the type of the value | ||
const type = typeof value; | ||
var type = typeof value; | ||
// Check the key and throw error if it's illegal | ||
@@ -777,4 +796,4 @@ if (typeof key === 'string' && !ignoreKeys.has(key)) { | ||
// Iterate over all the keys | ||
for (const key in object) { | ||
let value = object[key]; | ||
for (var key in object) { | ||
var value = object[key]; | ||
// Is there an override value | ||
@@ -787,3 +806,3 @@ if (value && value.toBSON) { | ||
// Check the type of the value | ||
const type = typeof value; | ||
var type = typeof value; | ||
// Check the key and throw error if it's illegal | ||
@@ -882,3 +901,3 @@ if (typeof key === 'string' && !ignoreKeys.has(key)) { | ||
// Final size | ||
const size = index - startingIndex; | ||
var size = index - startingIndex; | ||
// Write the size of the object | ||
@@ -885,0 +904,0 @@ buffer[startingIndex++] = size & 0xff; |
"use strict"; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deprecate = exports.isObjectLike = exports.isDate = exports.isBuffer = exports.haveBuffer = exports.isBigUInt64Array = exports.isBigInt64Array = exports.isUint8Array = exports.randomBytes = exports.normalizedFunctionString = void 0; | ||
const buffer_1 = require("buffer"); | ||
var buffer_1 = require("buffer"); | ||
/** | ||
@@ -14,4 +21,4 @@ * Normalizes our expected stringified form of a function across versions of node | ||
function insecureRandomBytes(size) { | ||
const result = buffer_1.Buffer.alloc(size); | ||
for (let i = 0; i < size; ++i) | ||
var result = buffer_1.Buffer.alloc(size); | ||
for (var i = 0; i < size; ++i) | ||
result[i] = Math.floor(Math.random() * 256); | ||
@@ -22,3 +29,3 @@ return result; | ||
if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) { | ||
exports.randomBytes = size => window.crypto.getRandomValues(buffer_1.Buffer.alloc(size)); | ||
exports.randomBytes = function (size) { return window.crypto.getRandomValues(buffer_1.Buffer.alloc(size)); }; | ||
} | ||
@@ -76,8 +83,12 @@ else { | ||
function deprecate(fn, message) { | ||
if (typeof window === 'undefined' || typeof self === 'undefined') { | ||
if (typeof window === 'undefined' && typeof self === 'undefined') { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
return require('util').deprecate(fn, message); | ||
} | ||
let warned = false; | ||
function deprecated(...args) { | ||
var warned = false; | ||
function deprecated() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
if (!warned) { | ||
@@ -87,3 +98,3 @@ console.warn(message); | ||
} | ||
return fn.apply(this, ...args); | ||
return fn.apply.apply(fn, __spreadArrays([this], args)); | ||
} | ||
@@ -90,0 +101,0 @@ return deprecated; |
@@ -11,3 +11,3 @@ "use strict"; | ||
*/ | ||
class BSONRegExp { | ||
var BSONRegExp = /** @class */ (function () { | ||
/** | ||
@@ -17,3 +17,5 @@ * @param pattern - The regular expression pattern to match | ||
*/ | ||
constructor(pattern, options) { | ||
function BSONRegExp(pattern, options) { | ||
if (!(this instanceof BSONRegExp)) | ||
return new BSONRegExp(pattern, options); | ||
this.pattern = pattern; | ||
@@ -24,3 +26,3 @@ this.options = options !== null && options !== void 0 ? options : ''; | ||
// Validate options | ||
for (let i = 0; i < this.options.length; i++) { | ||
for (var i = 0; i < this.options.length; i++) { | ||
if (!(this.options[i] === 'i' || | ||
@@ -32,11 +34,11 @@ this.options[i] === 'm' || | ||
this.options[i] === 'u')) { | ||
throw new Error(`The regular expression option [${this.options[i]}] is not supported`); | ||
throw new Error("The regular expression option [" + this.options[i] + "] is not supported"); | ||
} | ||
} | ||
} | ||
static parseOptions(options) { | ||
BSONRegExp.parseOptions = function (options) { | ||
return options ? options.split('').sort().join('') : ''; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON(options) { | ||
BSONRegExp.prototype.toExtendedJSON = function (options) { | ||
options = options || {}; | ||
@@ -47,5 +49,5 @@ if (options.legacy) { | ||
return { $regularExpression: { pattern: this.pattern, options: this.options } }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
BSONRegExp.fromExtendedJSON = function (doc) { | ||
if ('$regex' in doc) { | ||
@@ -65,7 +67,8 @@ if (typeof doc.$regex !== 'string') { | ||
} | ||
throw new TypeError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`); | ||
} | ||
} | ||
throw new TypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc)); | ||
}; | ||
return BSONRegExp; | ||
}()); | ||
exports.BSONRegExp = BSONRegExp; | ||
Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' }); | ||
//# sourceMappingURL=regexp.js.map |
@@ -8,40 +8,43 @@ "use strict"; | ||
*/ | ||
class BSONSymbol { | ||
var BSONSymbol = /** @class */ (function () { | ||
/** | ||
* @param value - the string representing the symbol. | ||
*/ | ||
constructor(value) { | ||
function BSONSymbol(value) { | ||
if (!(this instanceof BSONSymbol)) | ||
return new BSONSymbol(value); | ||
this.value = value; | ||
} | ||
/** Access the wrapped string value. */ | ||
valueOf() { | ||
BSONSymbol.prototype.valueOf = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
toString() { | ||
BSONSymbol.prototype.toString = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
inspect() { | ||
return `BSONSymbol("${this.value}")`; | ||
} | ||
BSONSymbol.prototype.inspect = function () { | ||
return "new BSONSymbol(\"" + this.value + "\")"; | ||
}; | ||
/** @internal */ | ||
toJSON() { | ||
BSONSymbol.prototype.toJSON = function () { | ||
return this.value; | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON() { | ||
BSONSymbol.prototype.toExtendedJSON = function () { | ||
return { $symbol: this.value }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
BSONSymbol.fromExtendedJSON = function (doc) { | ||
return new BSONSymbol(doc.$symbol); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
BSONSymbol.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
} | ||
}; | ||
return BSONSymbol; | ||
}()); | ||
exports.BSONSymbol = BSONSymbol; | ||
Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' }); | ||
//# sourceMappingURL=symbol.js.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Timestamp = exports.LongWithoutOverridesClass = void 0; | ||
const long_1 = require("./long"); | ||
var long_1 = require("./long"); | ||
/** @public */ | ||
exports.LongWithoutOverridesClass = long_1.Long; | ||
/** @public */ | ||
class Timestamp extends exports.LongWithoutOverridesClass { | ||
constructor(low, high) { | ||
var Timestamp = /** @class */ (function (_super) { | ||
__extends(Timestamp, _super); | ||
function Timestamp(low, high) { | ||
var _this = this; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
///@ts-expect-error | ||
if (!(_this instanceof Timestamp)) | ||
return new Timestamp(low, high); | ||
if (long_1.Long.isLong(low)) { | ||
super(low.low, low.high, true); | ||
_this = _super.call(this, low.low, low.high, true) || this; | ||
} | ||
else { | ||
super(low, high, true); | ||
_this = _super.call(this, low, high, true) || this; | ||
} | ||
Object.defineProperty(this, '_bsontype', { | ||
Object.defineProperty(_this, '_bsontype', { | ||
value: 'Timestamp', | ||
@@ -22,16 +41,17 @@ writable: false, | ||
}); | ||
return _this; | ||
} | ||
toJSON() { | ||
Timestamp.prototype.toJSON = function () { | ||
return { | ||
$timestamp: this.toString() | ||
}; | ||
} | ||
}; | ||
/** Returns a Timestamp represented by the given (32-bit) integer value. */ | ||
static fromInt(value) { | ||
Timestamp.fromInt = function (value) { | ||
return new Timestamp(long_1.Long.fromInt(value, true)); | ||
} | ||
}; | ||
/** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */ | ||
static fromNumber(value) { | ||
Timestamp.fromNumber = function (value) { | ||
return new Timestamp(long_1.Long.fromNumber(value, true)); | ||
} | ||
}; | ||
/** | ||
@@ -43,5 +63,5 @@ * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits. | ||
*/ | ||
static fromBits(lowBits, highBits) { | ||
Timestamp.fromBits = function (lowBits, highBits) { | ||
return new Timestamp(lowBits, highBits); | ||
} | ||
}; | ||
/** | ||
@@ -53,23 +73,24 @@ * Returns a Timestamp from the given string, optionally using the given radix. | ||
*/ | ||
static fromString(str, optRadix) { | ||
Timestamp.fromString = function (str, optRadix) { | ||
return new Timestamp(long_1.Long.fromString(str, true, optRadix)); | ||
} | ||
}; | ||
/** @internal */ | ||
toExtendedJSON() { | ||
Timestamp.prototype.toExtendedJSON = function () { | ||
return { $timestamp: { t: this.high >>> 0, i: this.low >>> 0 } }; | ||
} | ||
}; | ||
/** @internal */ | ||
static fromExtendedJSON(doc) { | ||
Timestamp.fromExtendedJSON = function (doc) { | ||
return new Timestamp(doc.$timestamp.i, doc.$timestamp.t); | ||
} | ||
}; | ||
/** @internal */ | ||
[Symbol.for('nodejs.util.inspect.custom')]() { | ||
Timestamp.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () { | ||
return this.inspect(); | ||
} | ||
inspect() { | ||
return `Timestamp(${this.getLowBits().toString()}, ${this.getHighBits().toString()})`; | ||
} | ||
} | ||
}; | ||
Timestamp.prototype.inspect = function () { | ||
return "new Timestamp(" + this.getLowBits().toString() + ", " + this.getHighBits().toString() + ")"; | ||
}; | ||
Timestamp.MAX_VALUE = long_1.Long.MAX_UNSIGNED_VALUE; | ||
return Timestamp; | ||
}(exports.LongWithoutOverridesClass)); | ||
exports.Timestamp = Timestamp; | ||
Timestamp.MAX_VALUE = long_1.Long.MAX_UNSIGNED_VALUE; | ||
//# sourceMappingURL=timestamp.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
*/ | ||
const UUID_RX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; | ||
var UUID_RX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; | ||
/** | ||
@@ -22,4 +22,4 @@ * Parser function copied from `uuid` npm module. | ||
} | ||
let v; | ||
const arr = new Uint8Array(16); | ||
var v; | ||
var arr = new Uint8Array(16); | ||
// Parse ########-....-....-....-............ | ||
@@ -26,0 +26,0 @@ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateUtf8 = void 0; | ||
const FIRST_BIT = 0x80; | ||
const FIRST_TWO_BITS = 0xc0; | ||
const FIRST_THREE_BITS = 0xe0; | ||
const FIRST_FOUR_BITS = 0xf0; | ||
const FIRST_FIVE_BITS = 0xf8; | ||
const TWO_BIT_CHAR = 0xc0; | ||
const THREE_BIT_CHAR = 0xe0; | ||
const FOUR_BIT_CHAR = 0xf0; | ||
const CONTINUING_CHAR = 0x80; | ||
var FIRST_BIT = 0x80; | ||
var FIRST_TWO_BITS = 0xc0; | ||
var FIRST_THREE_BITS = 0xe0; | ||
var FIRST_FOUR_BITS = 0xf0; | ||
var FIRST_FIVE_BITS = 0xf8; | ||
var TWO_BIT_CHAR = 0xc0; | ||
var THREE_BIT_CHAR = 0xe0; | ||
var FOUR_BIT_CHAR = 0xf0; | ||
var CONTINUING_CHAR = 0x80; | ||
/** | ||
@@ -20,5 +20,5 @@ * Determines if the passed in bytes are valid utf8 | ||
function validateUtf8(bytes, start, end) { | ||
let continuation = 0; | ||
for (let i = start; i < end; i += 1) { | ||
const byte = bytes[i]; | ||
var continuation = 0; | ||
for (var i = start; i < end; i += 1) { | ||
var byte = bytes[i]; | ||
if (continuation) { | ||
@@ -25,0 +25,0 @@ if ((byte & FIRST_TWO_BITS) !== CONTINUING_CHAR) { |
@@ -18,3 +18,3 @@ { | ||
"types": "bson.d.ts", | ||
"version": "4.2.2", | ||
"version": "4.2.3", | ||
"author": "Christian Amor Kvalheim <christkv@gmail.com>", | ||
@@ -21,0 +21,0 @@ "license": "Apache-2.0", |
@@ -53,5 +53,5 @@ import { Buffer } from 'buffer'; | ||
buffer: Buffer; | ||
sub_type: number; | ||
position: number; | ||
buffer!: Buffer; | ||
sub_type!: number; | ||
position!: number; | ||
@@ -63,2 +63,4 @@ /** | ||
constructor(buffer?: string | BinarySequence, subType?: number) { | ||
if (!(this instanceof Binary)) return new Binary(buffer, subType); | ||
if ( | ||
@@ -268,3 +270,3 @@ !(buffer == null) && | ||
const asBuffer = this.value(true); | ||
return `Binary("${asBuffer.toString('hex')}", ${this.sub_type})`; | ||
return `new Binary(Buffer.from("${asBuffer.toString('hex')}", "hex"), ${this.sub_type})`; | ||
} | ||
@@ -271,0 +273,0 @@ } |
@@ -16,3 +16,3 @@ import type { Document } from './bson'; | ||
code: string | Function; | ||
code!: string | Function; | ||
scope?: Document; | ||
@@ -24,2 +24,4 @@ /** | ||
constructor(code: string | Function, scope?: Document) { | ||
if (!(this instanceof Code)) return new Code(code, scope); | ||
this.code = code; | ||
@@ -55,3 +57,5 @@ this.scope = scope; | ||
const codeJson = this.toJSON(); | ||
return `Code("${codeJson.code}"${codeJson.scope ? `, ${JSON.stringify(codeJson.scope)}` : ''})`; | ||
return `new Code("${codeJson.code}"${ | ||
codeJson.scope ? `, ${JSON.stringify(codeJson.scope)}` : '' | ||
})`; | ||
} | ||
@@ -58,0 +62,0 @@ } |
@@ -25,6 +25,6 @@ import type { Document } from './bson'; | ||
collection: string; | ||
oid: ObjectId; | ||
collection!: string; | ||
oid!: ObjectId; | ||
db?: string; | ||
fields: Document; | ||
fields!: Document; | ||
@@ -37,2 +37,4 @@ /** | ||
constructor(collection: string, oid: ObjectId, db?: string, fields?: Document) { | ||
if (!(this instanceof DBRef)) return new DBRef(collection, oid, db, fields); | ||
// check if namespace has been provided | ||
@@ -113,3 +115,5 @@ const parts = collection.split('.'); | ||
this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString(); | ||
return `DBRef("${this.namespace}", "${oid}"${this.db ? `, "${this.db}"` : ''})`; | ||
return `new DBRef("${this.namespace}", new ObjectId("${oid}")${ | ||
this.db ? `, "${this.db}"` : '' | ||
})`; | ||
} | ||
@@ -116,0 +120,0 @@ } |
@@ -168,6 +168,8 @@ import { Buffer } from 'buffer'; | ||
readonly bytes: Buffer; | ||
readonly bytes!: Buffer; | ||
/** @param bytes - a buffer containing the raw Decimal128 bytes in little endian order */ | ||
constructor(bytes: Buffer) { | ||
if (!(this instanceof Decimal128)) return new Decimal128(bytes); | ||
this.bytes = bytes; | ||
@@ -798,3 +800,3 @@ } | ||
inspect(): string { | ||
return `Decimal128("${this.toString()}")`; | ||
return `Decimal128.fromString("${this.toString()}")`; | ||
} | ||
@@ -801,0 +803,0 @@ } |
@@ -15,3 +15,3 @@ import type { EJSONOptions } from './extended_json'; | ||
value: number; | ||
value!: number; | ||
/** | ||
@@ -23,2 +23,4 @@ * Create a Double type | ||
constructor(value: number) { | ||
if (!(this instanceof Double)) return new Double(value); | ||
if ((value as unknown) instanceof Number) { | ||
@@ -83,3 +85,3 @@ value = value.valueOf(); | ||
const eJSON = this.toExtendedJSON() as DoubleExtended; | ||
return `Double(${eJSON.$numberDouble})`; | ||
return `new Double(${eJSON.$numberDouble})`; | ||
} | ||
@@ -86,0 +88,0 @@ } |
@@ -15,3 +15,3 @@ import type { EJSONOptions } from './extended_json'; | ||
value: number; | ||
value!: number; | ||
/** | ||
@@ -23,2 +23,4 @@ * Create an Int32 type | ||
constructor(value: number | string) { | ||
if (!(this instanceof Int32)) return new Int32(value); | ||
if ((value as unknown) instanceof Number) { | ||
@@ -62,3 +64,3 @@ value = value.valueOf(); | ||
inspect(): string { | ||
return `Int32(${this.valueOf()})`; | ||
return `new Int32(${this.valueOf()})`; | ||
} | ||
@@ -65,0 +67,0 @@ } |
@@ -85,3 +85,3 @@ import type { EJSONOptions } from './extended_json'; | ||
*/ | ||
high: number; | ||
high!: number; | ||
@@ -91,3 +91,3 @@ /** | ||
*/ | ||
low: number; | ||
low!: number; | ||
@@ -97,3 +97,3 @@ /** | ||
*/ | ||
unsigned: boolean; | ||
unsigned!: boolean; | ||
@@ -108,2 +108,4 @@ /** | ||
constructor(low = 0, high = 0, unsigned?: boolean) { | ||
if (!(this instanceof Long)) return new Long(low, high, unsigned); | ||
this.low = low | 0; | ||
@@ -999,3 +1001,3 @@ this.high = high | 0; | ||
inspect(): string { | ||
return `Long("${this.toString()}")`; | ||
return `new Long("${this.toString()}")`; | ||
} | ||
@@ -1002,0 +1004,0 @@ } |
@@ -13,2 +13,6 @@ /** @public */ | ||
constructor() { | ||
if (!(this instanceof MaxKey)) return new MaxKey(); | ||
} | ||
/** @internal */ | ||
@@ -30,3 +34,3 @@ toExtendedJSON(): MaxKeyExtended { | ||
inspect(): string { | ||
return 'MaxKey()'; | ||
return 'new MaxKey()'; | ||
} | ||
@@ -33,0 +37,0 @@ } |
@@ -13,2 +13,6 @@ /** @public */ | ||
constructor() { | ||
if (!(this instanceof MinKey)) return new MinKey(); | ||
} | ||
/** @internal */ | ||
@@ -30,3 +34,3 @@ toExtendedJSON(): MinKeyExtended { | ||
inspect(): string { | ||
return 'MinKey()'; | ||
return 'new MinKey()'; | ||
} | ||
@@ -33,0 +37,0 @@ } |
@@ -60,2 +60,4 @@ import { Buffer } from 'buffer'; | ||
constructor(id?: string | Buffer | number | ObjectIdLike | ObjectId) { | ||
if (!(this instanceof ObjectId)) return new ObjectId(id); | ||
// Duck-typing to support ObjectId from different npm packages | ||
@@ -354,3 +356,3 @@ if (id instanceof ObjectId) { | ||
inspect(): string { | ||
return `ObjectId("${this.toHexString()}")`; | ||
return `new ObjectId("${this.toHexString()}")`; | ||
} | ||
@@ -357,0 +359,0 @@ } |
@@ -80,3 +80,3 @@ import { Buffer } from 'buffer'; | ||
export function deprecate<T extends Function>(fn: T, message: string): T { | ||
if (typeof window === 'undefined' || typeof self === 'undefined') { | ||
if (typeof window === 'undefined' && typeof self === 'undefined') { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -83,0 +83,0 @@ return require('util').deprecate(fn, message); |
@@ -28,4 +28,4 @@ import type { EJSONOptions } from './extended_json'; | ||
pattern: string; | ||
options: string; | ||
pattern!: string; | ||
options!: string; | ||
/** | ||
@@ -36,2 +36,4 @@ * @param pattern - The regular expression pattern to match | ||
constructor(pattern: string, options?: string) { | ||
if (!(this instanceof BSONRegExp)) return new BSONRegExp(pattern, options); | ||
this.pattern = pattern; | ||
@@ -38,0 +40,0 @@ this.options = options ?? ''; |
@@ -13,3 +13,3 @@ /** @public */ | ||
value: string; | ||
value!: string; | ||
/** | ||
@@ -19,2 +19,4 @@ * @param value - the string representing the symbol. | ||
constructor(value: string) { | ||
if (!(this instanceof BSONSymbol)) return new BSONSymbol(value); | ||
this.value = value; | ||
@@ -35,3 +37,3 @@ } | ||
inspect(): string { | ||
return `BSONSymbol("${this.value}")`; | ||
return `new BSONSymbol("${this.value}")`; | ||
} | ||
@@ -38,0 +40,0 @@ |
@@ -34,4 +34,9 @@ import { Long } from './long'; | ||
*/ | ||
constructor(low: Long); | ||
constructor(low: number, high: number); | ||
constructor(low: number | Long, high?: number) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
///@ts-expect-error | ||
if (!(this instanceof Timestamp)) return new Timestamp(low, high); | ||
if (Long.isLong(low)) { | ||
@@ -102,4 +107,4 @@ super(low.low, low.high, true); | ||
inspect(): string { | ||
return `Timestamp(${this.getLowBits().toString()}, ${this.getHighBits().toString()})`; | ||
return `new Timestamp(${this.getLowBits().toString()}, ${this.getHighBits().toString()})`; | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3192726
42468
7