UNPKG

truffle

Version:

Truffle - Simple development framework for Ethereum

1,392 lines (1,305 loc) 151 kB
#!/usr/bin/env node exports.id = 5498; exports.ids = [5498,794]; exports.modules = { /***/ 92936: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ getAddress: () => (/* binding */ getAddress), /* harmony export */ getContractAddress: () => (/* binding */ getContractAddress), /* harmony export */ getCreate2Address: () => (/* binding */ getCreate2Address), /* harmony export */ getIcapAddress: () => (/* binding */ getIcapAddress), /* harmony export */ isAddress: () => (/* binding */ isAddress) /* harmony export */ }); /* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(46366); /* harmony import */ var _ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2593); /* harmony import */ var _ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(38197); /* harmony import */ var _ethersproject_rlp__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(50284); /* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167); /* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6915); const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i); function getChecksumAddress(address) { if (!(0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .isHexString */ .A7)(address, 20)) { logger.throwArgumentError("invalid address", "address", address); } address = address.toLowerCase(); const chars = address.substring(2).split(""); const expanded = new Uint8Array(40); for (let i = 0; i < 40; i++) { expanded[i] = chars[i].charCodeAt(0); } const hashed = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .arrayify */ .lE)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)(expanded)); for (let i = 0; i < 40; i += 2) { if ((hashed[i >> 1] >> 4) >= 8) { chars[i] = chars[i].toUpperCase(); } if ((hashed[i >> 1] & 0x0f) >= 8) { chars[i + 1] = chars[i + 1].toUpperCase(); } } return "0x" + chars.join(""); } // Shims for environments that are missing some required constants and functions const MAX_SAFE_INTEGER = 0x1fffffffffffff; function log10(x) { if (Math.log10) { return Math.log10(x); } return Math.log(x) / Math.LN10; } // See: https://en.wikipedia.org/wiki/International_Bank_Account_Number // Create lookup table const ibanLookup = {}; for (let i = 0; i < 10; i++) { ibanLookup[String(i)] = String(i); } for (let i = 0; i < 26; i++) { ibanLookup[String.fromCharCode(65 + i)] = String(10 + i); } // How many decimal digits can we process? (for 64-bit float, this is 15) const safeDigits = Math.floor(log10(MAX_SAFE_INTEGER)); function ibanChecksum(address) { address = address.toUpperCase(); address = address.substring(4) + address.substring(0, 2) + "00"; let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join(""); // Javascript can handle integers safely up to 15 (decimal) digits while (expanded.length >= safeDigits) { let block = expanded.substring(0, safeDigits); expanded = parseInt(block, 10) % 97 + expanded.substring(block.length); } let checksum = String(98 - (parseInt(expanded, 10) % 97)); while (checksum.length < 2) { checksum = "0" + checksum; } return checksum; } ; function getAddress(address) { let result = null; if (typeof (address) !== "string") { logger.throwArgumentError("invalid address", "address", address); } if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) { // Missing the 0x prefix if (address.substring(0, 2) !== "0x") { address = "0x" + address; } result = getChecksumAddress(address); // It is a checksummed address with a bad checksum if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) { logger.throwArgumentError("bad address checksum", "address", address); } // Maybe ICAP? (we only support direct mode) } else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) { // It is an ICAP address with a bad checksum if (address.substring(2, 4) !== ibanChecksum(address)) { logger.throwArgumentError("bad icap checksum", "address", address); } result = (0,_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* ._base36To16 */ .g$)(address.substring(4)); while (result.length < 40) { result = "0" + result; } result = getChecksumAddress("0x" + result); } else { logger.throwArgumentError("invalid address", "address", address); } return result; } function isAddress(address) { try { getAddress(address); return true; } catch (error) { } return false; } function getIcapAddress(address) { let base36 = (0,_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* ._base16To36 */ .t2)(getAddress(address).substring(2)).toUpperCase(); while (base36.length < 30) { base36 = "0" + base36; } return "XE" + ibanChecksum("XE00" + base36) + base36; } // http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed function getContractAddress(transaction) { let from = null; try { from = getAddress(transaction.from); } catch (error) { logger.throwArgumentError("missing from address", "transaction", transaction); } const nonce = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .stripZeros */ .G1)((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .arrayify */ .lE)(_ethersproject_bignumber__WEBPACK_IMPORTED_MODULE_4__/* .BigNumber */ .O$.from(transaction.nonce).toHexString())); return getAddress((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataSlice */ .p3)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)((0,_ethersproject_rlp__WEBPACK_IMPORTED_MODULE_5__.encode)([from, nonce])), 12)); } function getCreate2Address(from, salt, initCodeHash) { if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataLength */ .E1)(salt) !== 32) { logger.throwArgumentError("salt must be 32 bytes", "salt", salt); } if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataLength */ .E1)(initCodeHash) !== 32) { logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", initCodeHash); } return getAddress((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .hexDataSlice */ .p3)((0,_ethersproject_keccak256__WEBPACK_IMPORTED_MODULE_3__/* .keccak256 */ .w)((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_2__/* .concat */ .zo)(["0xff", getAddress(from), salt, initCodeHash])), 12)); } //# sourceMappingURL=index.js.map /***/ }), /***/ 20335: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Ox: () => (/* binding */ parseFixed), /* harmony export */ S5: () => (/* binding */ formatFixed), /* harmony export */ xO: () => (/* binding */ FixedFormat), /* harmony export */ xs: () => (/* binding */ FixedNumber) /* harmony export */ }); /* harmony import */ var _ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(46366); /* harmony import */ var _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66167); /* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48794); /* harmony import */ var _bignumber__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2593); const logger = new _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd(_version__WEBPACK_IMPORTED_MODULE_1__/* .version */ .i); const _constructorGuard = {}; const Zero = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(0); const NegativeOne = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(-1); function throwFault(message, fault, operation, value) { const params = { fault: fault, operation: operation }; if (value !== undefined) { params.value = value; } return logger.throwError(message, _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.NUMERIC_FAULT, params); } // Constant to pull zeros from for multipliers let zeros = "0"; while (zeros.length < 256) { zeros += zeros; } // Returns a string "1" followed by decimal "0"s function getMultiplier(decimals) { if (typeof (decimals) !== "number") { try { decimals = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(decimals).toNumber(); } catch (e) { } } if (typeof (decimals) === "number" && decimals >= 0 && decimals <= 256 && !(decimals % 1)) { return ("1" + zeros.substring(0, decimals)); } return logger.throwArgumentError("invalid decimal size", "decimals", decimals); } function formatFixed(value, decimals) { if (decimals == null) { decimals = 0; } const multiplier = getMultiplier(decimals); // Make sure wei is a big number (convert as necessary) value = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(value); const negative = value.lt(Zero); if (negative) { value = value.mul(NegativeOne); } let fraction = value.mod(multiplier).toString(); while (fraction.length < multiplier.length - 1) { fraction = "0" + fraction; } // Strip training 0 fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1]; const whole = value.div(multiplier).toString(); if (multiplier.length === 1) { value = whole; } else { value = whole + "." + fraction; } if (negative) { value = "-" + value; } return value; } function parseFixed(value, decimals) { if (decimals == null) { decimals = 0; } const multiplier = getMultiplier(decimals); if (typeof (value) !== "string" || !value.match(/^-?[0-9.]+$/)) { logger.throwArgumentError("invalid decimal value", "value", value); } // Is it negative? const negative = (value.substring(0, 1) === "-"); if (negative) { value = value.substring(1); } if (value === ".") { logger.throwArgumentError("missing value", "value", value); } // Split it into a whole and fractional part const comps = value.split("."); if (comps.length > 2) { logger.throwArgumentError("too many decimal points", "value", value); } let whole = comps[0], fraction = comps[1]; if (!whole) { whole = "0"; } if (!fraction) { fraction = "0"; } // Trim trailing zeros while (fraction[fraction.length - 1] === "0") { fraction = fraction.substring(0, fraction.length - 1); } // Check the fraction doesn't exceed our decimals size if (fraction.length > multiplier.length - 1) { throwFault("fractional component exceeds decimals", "underflow", "parseFixed"); } // If decimals is 0, we have an empty string for fraction if (fraction === "") { fraction = "0"; } // Fully pad the string with zeros to get to wei while (fraction.length < multiplier.length - 1) { fraction += "0"; } const wholeValue = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(whole); const fractionValue = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(fraction); let wei = (wholeValue.mul(multiplier)).add(fractionValue); if (negative) { wei = wei.mul(NegativeOne); } return wei; } class FixedFormat { constructor(constructorGuard, signed, width, decimals) { if (constructorGuard !== _constructorGuard) { logger.throwError("cannot use FixedFormat constructor; use FixedFormat.from", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.UNSUPPORTED_OPERATION, { operation: "new FixedFormat" }); } this.signed = signed; this.width = width; this.decimals = decimals; this.name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals); this._multiplier = getMultiplier(decimals); Object.freeze(this); } static from(value) { if (value instanceof FixedFormat) { return value; } if (typeof (value) === "number") { value = `fixed128x${value}`; } let signed = true; let width = 128; let decimals = 18; if (typeof (value) === "string") { if (value === "fixed") { // defaults... } else if (value === "ufixed") { signed = false; } else { const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/); if (!match) { logger.throwArgumentError("invalid fixed format", "format", value); } signed = (match[1] !== "u"); width = parseInt(match[2]); decimals = parseInt(match[3]); } } else if (value) { const check = (key, type, defaultValue) => { if (value[key] == null) { return defaultValue; } if (typeof (value[key]) !== type) { logger.throwArgumentError("invalid fixed format (" + key + " not " + type + ")", "format." + key, value[key]); } return value[key]; }; signed = check("signed", "boolean", signed); width = check("width", "number", width); decimals = check("decimals", "number", decimals); } if (width % 8) { logger.throwArgumentError("invalid fixed format width (not byte aligned)", "format.width", width); } if (decimals > 80) { logger.throwArgumentError("invalid fixed format (decimals too large)", "format.decimals", decimals); } return new FixedFormat(_constructorGuard, signed, width, decimals); } } class FixedNumber { constructor(constructorGuard, hex, value, format) { if (constructorGuard !== _constructorGuard) { logger.throwError("cannot use FixedNumber constructor; use FixedNumber.from", _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.UNSUPPORTED_OPERATION, { operation: "new FixedFormat" }); } this.format = format; this._hex = hex; this._value = value; this._isFixedNumber = true; Object.freeze(this); } _checkFormat(other) { if (this.format.name !== other.format.name) { logger.throwArgumentError("incompatible format; use fixedNumber.toFormat", "other", other); } } addUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.add(b), this.format.decimals, this.format); } subUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.sub(b), this.format.decimals, this.format); } mulUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.mul(b).div(this.format._multiplier), this.format.decimals, this.format); } divUnsafe(other) { this._checkFormat(other); const a = parseFixed(this._value, this.format.decimals); const b = parseFixed(other._value, other.format.decimals); return FixedNumber.fromValue(a.mul(this.format._multiplier).div(b), this.format.decimals, this.format); } floor() { const comps = this.toString().split("."); if (comps.length === 1) { comps.push("0"); } let result = FixedNumber.from(comps[0], this.format); const hasFraction = !comps[1].match(/^(0*)$/); if (this.isNegative() && hasFraction) { result = result.subUnsafe(ONE.toFormat(result.format)); } return result; } ceiling() { const comps = this.toString().split("."); if (comps.length === 1) { comps.push("0"); } let result = FixedNumber.from(comps[0], this.format); const hasFraction = !comps[1].match(/^(0*)$/); if (!this.isNegative() && hasFraction) { result = result.addUnsafe(ONE.toFormat(result.format)); } return result; } // @TODO: Support other rounding algorithms round(decimals) { if (decimals == null) { decimals = 0; } // If we are already in range, we're done const comps = this.toString().split("."); if (comps.length === 1) { comps.push("0"); } if (decimals < 0 || decimals > 80 || (decimals % 1)) { logger.throwArgumentError("invalid decimal count", "decimals", decimals); } if (comps[1].length <= decimals) { return this; } const factor = FixedNumber.from("1" + zeros.substring(0, decimals), this.format); const bump = BUMP.toFormat(this.format); return this.mulUnsafe(factor).addUnsafe(bump).floor().divUnsafe(factor); } isZero() { return (this._value === "0.0" || this._value === "0"); } isNegative() { return (this._value[0] === "-"); } toString() { return this._value; } toHexString(width) { if (width == null) { return this._hex; } if (width % 8) { logger.throwArgumentError("invalid byte width", "width", width); } const hex = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(this._hex).fromTwos(this.format.width).toTwos(width).toHexString(); return (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexZeroPad */ .$m)(hex, width / 8); } toUnsafeFloat() { return parseFloat(this.toString()); } toFormat(format) { return FixedNumber.fromString(this._value, format); } static fromValue(value, decimals, format) { // If decimals looks more like a format, and there is no format, shift the parameters if (format == null && decimals != null && !(0,_bignumber__WEBPACK_IMPORTED_MODULE_2__/* .isBigNumberish */ .Zm)(decimals)) { format = decimals; decimals = null; } if (decimals == null) { decimals = 0; } if (format == null) { format = "fixed"; } return FixedNumber.fromString(formatFixed(value, decimals), FixedFormat.from(format)); } static fromString(value, format) { if (format == null) { format = "fixed"; } const fixedFormat = FixedFormat.from(format); const numeric = parseFixed(value, fixedFormat.decimals); if (!fixedFormat.signed && numeric.lt(Zero)) { throwFault("unsigned value cannot be negative", "overflow", "value", value); } let hex = null; if (fixedFormat.signed) { hex = numeric.toTwos(fixedFormat.width).toHexString(); } else { hex = numeric.toHexString(); hex = (0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .hexZeroPad */ .$m)(hex, fixedFormat.width / 8); } const decimal = formatFixed(numeric, fixedFormat.decimals); return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat); } static fromBytes(value, format) { if (format == null) { format = "fixed"; } const fixedFormat = FixedFormat.from(format); if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .arrayify */ .lE)(value).length > fixedFormat.width / 8) { throw new Error("overflow"); } let numeric = _bignumber__WEBPACK_IMPORTED_MODULE_2__/* .BigNumber */ .O$.from(value); if (fixedFormat.signed) { numeric = numeric.fromTwos(fixedFormat.width); } const hex = numeric.toTwos((fixedFormat.signed ? 0 : 1) + fixedFormat.width).toHexString(); const decimal = formatFixed(numeric, fixedFormat.decimals); return new FixedNumber(_constructorGuard, hex, decimal, fixedFormat); } static from(value, format) { if (typeof (value) === "string") { return FixedNumber.fromString(value, format); } if ((0,_ethersproject_bytes__WEBPACK_IMPORTED_MODULE_3__/* .isBytes */ ._t)(value)) { return FixedNumber.fromBytes(value, format); } try { return FixedNumber.fromValue(value, 0, format); } catch (error) { // Allow NUMERIC_FAULT to bubble up if (error.code !== _ethersproject_logger__WEBPACK_IMPORTED_MODULE_0__/* .Logger */ .Yd.errors.INVALID_ARGUMENT) { throw error; } } return logger.throwArgumentError("invalid FixedNumber value", "value", value); } static isFixedNumber(value) { return !!(value && value._isFixedNumber); } } const ONE = FixedNumber.from(1); const BUMP = FixedNumber.from("0.5"); //# sourceMappingURL=fixednumber.js.map /***/ }), /***/ 833: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ BigNumber: () => (/* reexport safe */ _bignumber__WEBPACK_IMPORTED_MODULE_0__.O$), /* harmony export */ FixedFormat: () => (/* reexport safe */ _fixednumber__WEBPACK_IMPORTED_MODULE_1__.xO), /* harmony export */ FixedNumber: () => (/* reexport safe */ _fixednumber__WEBPACK_IMPORTED_MODULE_1__.xs), /* harmony export */ _base16To36: () => (/* reexport safe */ _bignumber__WEBPACK_IMPORTED_MODULE_0__.t2), /* harmony export */ _base36To16: () => (/* reexport safe */ _bignumber__WEBPACK_IMPORTED_MODULE_0__.g$), /* harmony export */ formatFixed: () => (/* reexport safe */ _fixednumber__WEBPACK_IMPORTED_MODULE_1__.S5), /* harmony export */ parseFixed: () => (/* reexport safe */ _fixednumber__WEBPACK_IMPORTED_MODULE_1__.Ox) /* harmony export */ }); /* harmony import */ var _bignumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2593); /* harmony import */ var _fixednumber__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20335); // Internal methods used by address //# sourceMappingURL=index.js.map /***/ }), /***/ 72047: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { // Packages var retrier = __webpack_require__(99353); function retry(fn, opts) { function run(resolve, reject) { var options = opts || {}; var op; // Default `randomize` to true if (!('randomize' in options)) { options.randomize = true; } op = retrier.operation(options); // We allow the user to abort retrying // this makes sense in the cases where // knowledge is obtained that retrying // would be futile (e.g.: auth errors) function bail(err) { reject(err || new Error('Aborted')); } function onError(err, num) { if (err.bail) { bail(err); return; } if (!op.retry(err)) { reject(op.mainError()); } else if (options.onRetry) { options.onRetry(err, num); } } function runAttempt(num) { var val; try { val = fn(bail, num); } catch (err) { onError(err, num); return; } Promise.resolve(val) .then(resolve) .catch(function catchIt(err) { onError(err, num); }); } op.attempt(runAttempt); } return new Promise(run); } module.exports = retry; /***/ }), /***/ 49804: /***/ ((module) => { var hasOwn = Object.prototype.hasOwnProperty; var toString = Object.prototype.toString; module.exports = function forEach (obj, fn, ctx) { if (toString.call(fn) !== '[object Function]') { throw new TypeError('iterator must be a function'); } var l = obj.length; if (l === +l) { for (var i = 0; i < l; i++) { fn.call(ctx, obj[i], i, obj); } } else { for (var k in obj) { if (hasOwn.call(obj, k)) { fn.call(ctx, obj[k], k, obj); } } } }; /***/ }), /***/ 83573: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; var each = __webpack_require__(49804); module.exports = api; /** * Convenience wrapper around the api. * Calls `.get` when called with an `object` and a `pointer`. * Calls `.set` when also called with `value`. * If only supplied `object`, returns a partially applied function, mapped to the object. * * @param {Object} obj * @param {String|Array} pointer * @param value * @returns {*} */ function api (obj, pointer, value) { // .set() if (arguments.length === 3) { return api.set(obj, pointer, value); } // .get() if (arguments.length === 2) { return api.get(obj, pointer); } // Return a partially applied function on `obj`. var wrapped = api.bind(api, obj); // Support for oo style for (var name in api) { if (api.hasOwnProperty(name)) { wrapped[name] = api[name].bind(wrapped, obj); } } return wrapped; } /** * Lookup a json pointer in an object * * @param {Object} obj * @param {String|Array} pointer * @returns {*} */ api.get = function get (obj, pointer) { var refTokens = Array.isArray(pointer) ? pointer : api.parse(pointer); for (var i = 0; i < refTokens.length; ++i) { var tok = refTokens[i]; if (!(typeof obj == 'object' && tok in obj)) { throw new Error('Invalid reference token: ' + tok); } obj = obj[tok]; } return obj; }; /** * Sets a value on an object * * @param {Object} obj * @param {String|Array} pointer * @param value */ api.set = function set (obj, pointer, value) { var refTokens = Array.isArray(pointer) ? pointer : api.parse(pointer), nextTok = refTokens[0]; if (refTokens.length === 0) { throw Error('Can not set the root object'); } for (var i = 0; i < refTokens.length - 1; ++i) { var tok = refTokens[i]; if (typeof tok !== 'string' && typeof tok !== 'number') { tok = String(tok) } if (tok === "__proto__" || tok === "constructor" || tok === "prototype") { continue } if (tok === '-' && Array.isArray(obj)) { tok = obj.length; } nextTok = refTokens[i + 1]; if (!(tok in obj)) { if (nextTok.match(/^(\d+|-)$/)) { obj[tok] = []; } else { obj[tok] = {}; } } obj = obj[tok]; } if (nextTok === '-' && Array.isArray(obj)) { nextTok = obj.length; } obj[nextTok] = value; return this; }; /** * Removes an attribute * * @param {Object} obj * @param {String|Array} pointer */ api.remove = function (obj, pointer) { var refTokens = Array.isArray(pointer) ? pointer : api.parse(pointer); var finalToken = refTokens[refTokens.length -1]; if (finalToken === undefined) { throw new Error('Invalid JSON pointer for remove: "' + pointer + '"'); } var parent = api.get(obj, refTokens.slice(0, -1)); if (Array.isArray(parent)) { var index = +finalToken; if (finalToken === '' && isNaN(index)) { throw new Error('Invalid array index: "' + finalToken + '"'); } Array.prototype.splice.call(parent, index, 1); } else { delete parent[finalToken]; } }; /** * Returns a (pointer -> value) dictionary for an object * * @param obj * @param {function} descend * @returns {} */ api.dict = function dict (obj, descend) { var results = {}; api.walk(obj, function (value, pointer) { results[pointer] = value; }, descend); return results; }; /** * Iterates over an object * Iterator: function (value, pointer) {} * * @param obj * @param {function} iterator * @param {function} descend */ api.walk = function walk (obj, iterator, descend) { var refTokens = []; descend = descend || function (value) { var type = Object.prototype.toString.call(value); return type === '[object Object]' || type === '[object Array]'; }; (function next (cur) { each(cur, function (value, key) { refTokens.push(String(key)); if (descend(value)) { next(value); } else { iterator(value, api.compile(refTokens)); } refTokens.pop(); }); }(obj)); }; /** * Tests if an object has a value for a json pointer * * @param obj * @param pointer * @returns {boolean} */ api.has = function has (obj, pointer) { try { api.get(obj, pointer); } catch (e) { return false; } return true; }; /** * Escapes a reference token * * @param str * @returns {string} */ api.escape = function escape (str) { return str.toString().replace(/~/g, '~0').replace(/\//g, '~1'); }; /** * Unescapes a reference token * * @param str * @returns {string} */ api.unescape = function unescape (str) { return str.replace(/~1/g, '/').replace(/~0/g, '~'); }; /** * Converts a json pointer into a array of reference tokens * * @param pointer * @returns {Array} */ api.parse = function parse (pointer) { if (pointer === '') { return []; } if (pointer.charAt(0) !== '/') { throw new Error('Invalid JSON pointer: ' + pointer); } return pointer.substring(1).split(/\//).map(api.unescape); }; /** * Builds a json pointer from a array of reference tokens * * @param refTokens * @returns {string} */ api.compile = function compile (refTokens) { if (refTokens.length === 0) { return ''; } return '/' + refTokens.map(api.escape).join('/'); }; /***/ }), /***/ 91501: /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; var __webpack_unused_export__; // An augmented AVL Tree where each node maintains a list of records and their search intervals. // Record is composed of an interval and its underlying data, sent by a client. This allows the // interval tree to have the same interval inserted multiple times, as long its data is different. // Both insertion and deletion require O(log n) time. Searching requires O(k*logn) time, where `k` // is the number of intervals in the output list. __webpack_unused_export__ = ({ value: true }); var isSame = __webpack_require__(96774); function height(node) { if (node === undefined) { return -1; } else { return node.height; } } var Node = /** @class */ (function () { function Node(intervalTree, record) { this.intervalTree = intervalTree; this.records = []; this.height = 0; this.key = record.low; this.max = record.high; // Save the array of all records with the same key for this node this.records.push(record); } // Gets the highest record.high value for this node Node.prototype.getNodeHigh = function () { var high = this.records[0].high; for (var i = 1; i < this.records.length; i++) { if (this.records[i].high > high) { high = this.records[i].high; } } return high; }; // Updates height value of the node. Called during insertion, rebalance, removal Node.prototype.updateHeight = function () { this.height = Math.max(height(this.left), height(this.right)) + 1; }; // Updates the max value of all the parents after inserting into already existing node, as well as // removing the node completely or removing the record of an already existing node. Starts with // the parent of an affected node and bubbles up to root Node.prototype.updateMaxOfParents = function () { if (this === undefined) { return; } var thisHigh = this.getNodeHigh(); if (this.left !== undefined && this.right !== undefined) { this.max = Math.max(Math.max(this.left.max, this.right.max), thisHigh); } else if (this.left !== undefined && this.right === undefined) { this.max = Math.max(this.left.max, thisHigh); } else if (this.left === undefined && this.right !== undefined) { this.max = Math.max(this.right.max, thisHigh); } else { this.max = thisHigh; } if (this.parent) { this.parent.updateMaxOfParents(); } }; /* Left-Left case: z y / \ / \ y T4 Right Rotate (z) x z / \ - - - - - - - - -> / \ / \ x T3 T1 T2 T3 T4 / \ T1 T2 Left-Right case: z z x / \ / \ / \ y T4 Left Rotate (y) x T4 Right Rotate(z) y z / \ - - - - - - - - -> / \ - - - - - - - -> / \ / \ T1 x y T3 T1 T2 T3 T4 / \ / \ T2 T3 T1 T2 */ // Handles Left-Left case and Left-Right case after rebalancing AVL tree Node.prototype._updateMaxAfterRightRotate = function () { var parent = this.parent; var left = parent.left; // Update max of left sibling (x in first case, y in second) var thisParentLeftHigh = left.getNodeHigh(); if (left.left === undefined && left.right !== undefined) { left.max = Math.max(thisParentLeftHigh, left.right.max); } else if (left.left !== undefined && left.right === undefined) { left.max = Math.max(thisParentLeftHigh, left.left.max); } else if (left.left === undefined && left.right === undefined) { left.max = thisParentLeftHigh; } else { left.max = Math.max(Math.max(left.left.max, left.right.max), thisParentLeftHigh); } // Update max of itself (z) var thisHigh = this.getNodeHigh(); if (this.left === undefined && this.right !== undefined) { this.max = Math.max(thisHigh, this.right.max); } else if (this.left !== undefined && this.right === undefined) { this.max = Math.max(thisHigh, this.left.max); } else if (this.left === undefined && this.right === undefined) { this.max = thisHigh; } else { this.max = Math.max(Math.max(this.left.max, this.right.max), thisHigh); } // Update max of parent (y in first case, x in second) parent.max = Math.max(Math.max(parent.left.max, parent.right.max), parent.getNodeHigh()); }; /* Right-Right case: z y / \ / \ T1 y Left Rotate(z) z x / \ - - - - - - - -> / \ / \ T2 x T1 T2 T3 T4 / \ T3 T4 Right-Left case: z z x / \ / \ / \ T1 y Right Rotate (y) T1 x Left Rotate(z) z y / \ - - - - - - - - -> / \ - - - - - - - -> / \ / \ x T4 T2 y T1 T2 T3 T4 / \ / \ T2 T3 T3 T4 */ // Handles Right-Right case and Right-Left case in rebalancing AVL tree Node.prototype._updateMaxAfterLeftRotate = function () { var parent = this.parent; var right = parent.right; // Update max of right sibling (x in first case, y in second) var thisParentRightHigh = right.getNodeHigh(); if (right.left === undefined && right.right !== undefined) { right.max = Math.max(thisParentRightHigh, right.right.max); } else if (right.left !== undefined && right.right === undefined) { right.max = Math.max(thisParentRightHigh, right.left.max); } else if (right.left === undefined && right.right === undefined) { right.max = thisParentRightHigh; } else { right.max = Math.max(Math.max(right.left.max, right.right.max), thisParentRightHigh); } // Update max of itself (z) var thisHigh = this.getNodeHigh(); if (this.left === undefined && this.right !== undefined) { this.max = Math.max(thisHigh, this.right.max); } else if (this.left !== undefined && this.right === undefined) { this.max = Math.max(thisHigh, this.left.max); } else if (this.left === undefined && this.right === undefined) { this.max = thisHigh; } else { this.max = Math.max(Math.max(this.left.max, this.right.max), thisHigh); } // Update max of parent (y in first case, x in second) parent.max = Math.max(Math.max(parent.left.max, right.max), parent.getNodeHigh()); }; Node.prototype._leftRotate = function () { var rightChild = this.right; rightChild.parent = this.parent; if (rightChild.parent === undefined) { this.intervalTree.root = rightChild; } else { if (rightChild.parent.left === this) { rightChild.parent.left = rightChild; } else if (rightChild.parent.right === this) { rightChild.parent.right = rightChild; } } this.right = rightChild.left; if (this.right !== undefined) { this.right.parent = this; } rightChild.left = this; this.parent = rightChild; this.updateHeight(); rightChild.updateHeight(); }; Node.prototype._rightRotate = function () { var leftChild = this.left; leftChild.parent = this.parent; if (leftChild.parent === undefined) { this.intervalTree.root = leftChild; } else { if (leftChild.parent.left === this) { leftChild.parent.left = leftChild; } else if (leftChild.parent.right === this) { leftChild.parent.right = leftChild; } } this.left = leftChild.right; if (this.left !== undefined) { this.left.parent = this; } leftChild.right = this; this.parent = leftChild; this.updateHeight(); leftChild.updateHeight(); }; // Rebalances the tree if the height value between two nodes of the same parent is greater than // two. There are 4 cases that can happen which are outlined in the graphics above Node.prototype._rebalance = function () { if (height(this.left) >= 2 + height(this.right)) { var left = this.left; if (height(left.left) >= height(left.right)) { // Left-Left case this._rightRotate(); this._updateMaxAfterRightRotate(); } else { // Left-Right case left._leftRotate(); this._rightRotate(); this._updateMaxAfterRightRotate(); } } else if (height(this.right) >= 2 + height(this.left)) { var right = this.right; if (height(right.right) >= height(right.left)) { // Right-Right case this._leftRotate(); this._updateMaxAfterLeftRotate(); } else { // Right-Left case right._rightRotate(); this._leftRotate(); this._updateMaxAfterLeftRotate(); } } }; Node.prototype.insert = function (record) { if (record.low < this.key) { // Insert into left subtree if (this.left === undefined) { this.left = new Node(this.intervalTree, record); this.left.parent = this; } else { this.left.insert(record); } } else { // Insert into right subtree if (this.right === undefined) { this.right = new Node(this.intervalTree, record); this.right.parent = this; } else { this.right.insert(record); } } // Update the max value of this ancestor if needed if (this.max < record.high) { this.max = record.high; } // Update height of each node this.updateHeight(); // Rebalance the tree to ensure all operations are executed in O(logn) time. This is especially // important in searching, as the tree has a high chance of degenerating without the rebalancing this._rebalance(); }; Node.prototype._getOverlappingRecords = function (currentNode, low, high) { if (currentNode.key <= high && low <= currentNode.getNodeHigh()) { // Nodes are overlapping, check if individual records in the node are overlapping var tempResults = []; for (var i = 0; i < currentNode.records.length; i++) { if (currentNode.records[i].high >= low) { tempResults.push(currentNode.records[i]); } } return tempResults; } return []; }; Node.prototype.search = function (low, high) { // Don't search nodes that don't exist if (this === undefined) { return []; } var leftSearch = []; var ownSearch = []; var rightSearch = []; // If interval is to the right of the rightmost point of any interval in this node and all its // children, there won't be any matches if (low > this.max) { return []; } // Search left children if (this.left !== undefined && this.left.max >= low) { leftSearch = this.left.search(low, high); } // Check this node ownSearch = this._getOverlappingRecords(this, low, high); // If interval is to the left of the start of this interval, then it can't be in any child to // the right if (high < this.key) { return leftSearch.concat(ownSearch); } // Otherwise, search right children if (this.right !== undefined) { rightSearch = this.right.search(low, high); } // Return accumulated results, if any return leftSearch.concat(ownSearch, rightSearch); }; // Searches for a node by a `key` value Node.prototype.searchExisting = function (low) { if (this === undefined) { return undefined; } if (this.key === low) { return this; } else if (low < this.key) { if (this.left !== undefined) { return this.left.searchExisting(low); } } else { if (this.right !== undefined) { return this.right.searchExisting(low); } } return undefined; }; // Returns the smallest node of the subtree Node.prototype._minValue = function () { if (this.left === undefined) { return this; } else { return this.left._minValue(); } }; Node.prototype.remove = function (node) { var parent = this.parent; if (node.key < this.key) { // Node to be removed is on the left side if (this.left !== undefined) { return this.left.remove(node); } else { return undefined; } } else if (node.key > this.key) { // Node to be removed is on the right side if (this.right !== undefined) { return this.right.remove(node); } else { return undefined; } } else { if (this.left !== undefined && this.right !== undefined) { // Node has two children var minValue = this.right._minValue(); this.key = minValue.key; this.records = minValue.records; return this.right.remove(this); } else if (parent.left === this) { // One child or no child case on left side if (this.right !== undefined) { parent.left = this.right; this.right.parent = parent; } else { parent.left = this.left; if (this.left !== undefined) { this.left.parent = parent; } } parent.updateMaxOfParents(); parent.updateHeight(); parent._rebalance(); return this; } else if (parent.right === this) { // One child or no child case on right side if (this.right !== undefined) { parent.right = this.right; this.right.parent = parent; } else { parent.right = this.left; if (this.left !== undefined) { this.left.parent = parent; } } parent.updateMaxOfParents(); parent.updateHeight(); parent._rebalance(); return this; } } }; return Node; }()); __webpack_unused_export__ = Node; var IntervalTree = /** @class */ (function () { function IntervalTree() { this.count = 0; } IntervalTree.prototype.insert = function (record) { if (record.low > record.high) { throw new Error('`low` value must be lower or equal to `high` value'); } if (this.root === undefined) { // Base case: Tree is empty, new node becomes root this.root = new Node(this, record); this.count++; return true; } else { // Otherwise, check if node already exists with the same key var node = this.root.searchExisting(record.low); if (node !== undefined) { // Check the records in this node if there already is the one with same low, high, data for (var i = 0; i < node.records.length; i++) { if (isSame(node.records[i], record)) { // This record is same as the one we're trying to insert; return false to indicate // nothing has been inserted return false; } } // Add the record to the node node.records.push(record); // Update max of the node and its parents if necessary if (record.high > node.max) { node.max = record.high; if (node.parent) { node.parent.updateMaxOfParents(); } } this.count++; return true; } else { // Node with this key doesn't already exist. Call insert function on root's node this.root.insert(record); this.count++; return true; } } }; IntervalTree.prototype.search = function (low, high) { if (this.root === undefined) { // Tree is empty; return empty array return []; } else { return this.root.search(low, high); } }; IntervalTree.prototype.remove = function (record) { if (this.root === undefined) { // Tree is empty; nothing to remove return false; } else { var node = this.root.searchExisting(r